Integrate Sheetwrite with Svelte bindings, callbacks, and reset ownership.
@sheetwrite/svelte initializes WASM in the browser. Bind grid when the host needs imperative access and pass onGridChange or onReady callbacks using the adapter's camel-case props.
The binding is populated before onReady and cleared before reset or unmount. A reset publishes a new generation and reason; coordinators attached to the previous grid must be destroyed and recreated.
Svelte adapter
<scriptlang="ts">
import {
Sheetwriteconst Sheetwrite: Component<SheetwriteProps<Record<string, CellScalar>>, {}, "grid">constSheetwrite:Component<SheetwriteProps<Record<string, CellScalar>>,{},"grid">constSheetwrite:Component<SheetwriteProps<Record<string, CellScalar>>,{},"grid">Owns a sheet derived from columns and defaultRows. Bind grid for imperative access; it clears on reset or unmount.API reference →,
typeGridinterface GridinterfaceGridinterfaceGridImperative grid handle for document commands, events, rendering, and teardown.API reference →,
typeGridReadyEventinterface GridReadyEventinterfaceGridReadyEventinterfaceGridReadyEventGrid handle, generation, and reason published after adapter initialization.API reference →,
typeSimpleColumninterface SimpleColumn<Row extends Record<string, CellScalar>>interfaceSimpleColumn<RowextendsRecord<string, CellScalar>>interfaceSimpleColumn<RowextendsRecord<string, CellScalar>>Column definition accepted by the adapters’ simple row-object API.API reference →,
} from"@sheetwrite/svelte";
importtype { ChangeEventinterface ChangeEventinterfaceChangeEventinterfaceChangeEventPayload of the change event; flows OUT for API submission/reconcile.API reference →, Transactioninterface TransactioninterfaceTransactioninterfaceTransactionLow-level Store transaction. epoch provides optional optimistic concurrency at the storage boundary. Calling Store.applyTransaction bypasses Grid read-only checks and Grid undo/redo history. Host-driven edits should use Grid.applyTransaction.API reference → } from"@sheetwrite/core";
saveProps.save: (transaction: Transaction) => voidinterfaceProps {save: (transaction:Transaction) =>void;}interfaceProps {save: (transaction:Transaction,) =>void;}: (transactiontransaction: Transactionlet transaction:Transactionlet transaction:TransactionOperations that actually committed after policy and bounds filtering.API reference →:Transactioninterface TransactioninterfaceTransactioninterfaceTransactionLow-level Store transaction. epoch provides optional optimistic concurrency at the storage boundary. Calling Store.applyTransaction bypasses Grid read-only checks and Grid undo/redo history. Host-driven edits should use Grid.applyTransaction.API reference →) =>void;
onReadyProps.onReady: (event: GridReadyEvent) => voidinterfaceProps {onReady: (event:GridReadyEvent) =>void;}interfaceProps {onReady: (event:GridReadyEvent,) =>void;}Fires after the adapter publishes a ready Grid generation.API reference →: (event:GridReadyEventinterface GridReadyEventinterfaceGridReadyEventinterfaceGridReadyEventGrid handle, generation, and reason published after adapter initialization.API reference →) =>void;
}
let { columnslet columns: readonly SimpleColumn<Row>[]let columns:readonlySimpleColumn<Row>[]let columns:readonlySimpleColumn<Row>[]Restrict to these column indices (defaults to all columns).API reference →, rowslet rows: readonly Row[]let rows:readonlyRow[]let rows:readonlyRow[]end-exclusive row rangeAPI reference →, savelet save: (transaction: Transaction) => voidletsave: (transaction:Transaction) =>voidletsave: (transaction:Transaction,) =>void, onReadylet onReady: (event: GridReadyEvent) => voidletonReady: (event:GridReadyEvent) =>voidletonReady: (event:GridReadyEvent,) =>voidFires after the adapter publishes a ready Grid generation.API reference → }:Propsinterface PropsinterfacePropsinterfaceProps=$propsfunction $props(): Propsfunction$props():Propsfunction$props():PropsDeclares the props that a component accepts. Example: let { optionalProp = 42, requiredProp, bindableProp = $bindable() }: { optionalProp?: number; requiredProps: string; bindableProp: boolean } = $props();@see {@link svelte.dev/docs/svelte/$props Documentation}();
let grid:Gridinterface GridinterfaceGridinterfaceGridImperative grid handle for document commands, events, rendering, and teardown.API reference →|undefined;
consthandleGridChangeconst handleGridChange: (event: ChangeEvent) => voidconsthandleGridChange: (event:ChangeEvent) =>voidconsthandleGridChange: (event:ChangeEvent,) =>void= (event:ChangeEventinterface ChangeEventinterfaceChangeEventinterfaceChangeEventPayload of the change event; flows OUT for API submission/reconcile.API reference →) =>savelet save: (transaction: Transaction) => voidletsave: (transaction:Transaction) =>voidletsave: (transaction:Transaction,) =>void(event.transactionChangeEvent.transaction: TransactioninterfaceChangeEvent {transaction:Transaction;}interfaceChangeEvent {transaction:Transaction;}Operations that actually committed after policy and bounds filtering.API reference →);
</script>
<Sheetwriteconst Sheetwrite: Component<SheetwriteProps<Record<string, CellScalar>>, {}, "grid">constSheetwrite:Component<SheetwriteProps<Record<string, CellScalar>>,{},"grid">constSheetwrite:Component<SheetwriteProps<Record<string, CellScalar>>,{},"grid">Owns a sheet derived from columns and defaultRows. Bind grid for imperative access; it clears on reset or unmount.API reference →
{columnscolumns: readonly SimpleColumn<Record<string, CellScalar>>[]let columns:readonlySimpleColumn<Record<string, CellScalar>>[]let columns:readonlySimpleColumn<Record<string, CellScalar>>[]Restrict to these column indices (defaults to all columns).API reference →}