@gridstorm/svelte 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # @gridstorm/svelte
2
+
3
+ Svelte 5 wrapper component for GridStorm.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @gridstorm/svelte
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ <script>
15
+ import { GridStorm } from '@gridstorm/svelte';
16
+ </script>
17
+
18
+ <GridStorm columnDefs={columns} rowData={data} plugins={plugins} />
19
+ ```
20
+
21
+ ## Features
22
+
23
+ - **Svelte 5 runes compatible**
24
+ - **Reactive props**
25
+ - **Auto-cleanup on destroy**
26
+ - **Full TypeScript support**
27
+
28
+ ## Documentation
29
+
30
+ [Full Documentation](https://grid-data-analytics-explorer.vercel.app/) | [GitHub](https://github.com/007krcs/grid-data)
31
+
32
+ ## License
33
+
34
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,247 @@
1
+ 'use strict';
2
+
3
+ var core = require('@gridstorm/core');
4
+ var domRenderer = require('@gridstorm/dom-renderer');
5
+
6
+ // src/gridstorm-action.ts
7
+ function gridstormAction(container, params) {
8
+ let engine = null;
9
+ let renderer = null;
10
+ const unsubs = [];
11
+ function init() {
12
+ const { props, events, onReady } = params;
13
+ const config = {
14
+ columns: props.columns,
15
+ rowData: props.rowData,
16
+ plugins: props.plugins || [],
17
+ getRowId: props.getRowId ? (p) => props.getRowId(p.data) : void 0,
18
+ rowHeight: props.rowHeight,
19
+ headerHeight: props.headerHeight,
20
+ theme: props.theme
21
+ };
22
+ engine = core.createGrid(config);
23
+ renderer = new domRenderer.DomRenderer({
24
+ container,
25
+ engine,
26
+ enableCellEditing: props.enableCellEditing,
27
+ enableGrouping: props.enableGrouping,
28
+ floatingFilter: props.floatingFilter,
29
+ enablePagination: props.enablePagination,
30
+ pageSizeOptions: props.paginationPageSize ? [props.paginationPageSize] : void 0
31
+ });
32
+ renderer.mount();
33
+ if (props.density) {
34
+ container.setAttribute("data-density", props.density);
35
+ }
36
+ if (events?.onSelectionChanged) {
37
+ unsubs.push(
38
+ engine.eventBus.on("selection:changed", () => {
39
+ events.onSelectionChanged(engine.api.getSelectedNodes());
40
+ })
41
+ );
42
+ }
43
+ if (events?.onSortChanged) {
44
+ unsubs.push(
45
+ engine.eventBus.on("column:sort:changed", (e) => {
46
+ events.onSortChanged(e.sortModel || []);
47
+ })
48
+ );
49
+ }
50
+ if (events?.onFilterChanged) {
51
+ unsubs.push(
52
+ engine.eventBus.on("filter:changed", (e) => {
53
+ events.onFilterChanged(e.filterModel || {});
54
+ })
55
+ );
56
+ }
57
+ if (events?.onCellValueChanged) {
58
+ unsubs.push(
59
+ engine.eventBus.on("cell:valueChanged", (e) => {
60
+ events.onCellValueChanged(e);
61
+ })
62
+ );
63
+ }
64
+ if (events?.onRowClicked) {
65
+ unsubs.push(
66
+ engine.eventBus.on("row:clicked", (e) => {
67
+ events.onRowClicked(e.node);
68
+ })
69
+ );
70
+ }
71
+ if (events?.onPaginationChanged) {
72
+ unsubs.push(
73
+ engine.eventBus.on("pagination:changed", (e) => {
74
+ events.onPaginationChanged(e);
75
+ })
76
+ );
77
+ }
78
+ if (events?.onColumnResized) {
79
+ unsubs.push(
80
+ engine.eventBus.on("column:resized", (e) => {
81
+ events.onColumnResized(e);
82
+ })
83
+ );
84
+ }
85
+ requestAnimationFrame(() => {
86
+ if (engine) {
87
+ engine.eventBus.emit("grid:ready", { api: engine.api });
88
+ events?.onGridReady?.(engine.api);
89
+ onReady?.(engine.api, engine);
90
+ }
91
+ });
92
+ }
93
+ function destroy() {
94
+ unsubs.forEach((fn) => fn());
95
+ unsubs.length = 0;
96
+ renderer?.destroy();
97
+ engine?.destroy();
98
+ renderer = null;
99
+ engine = null;
100
+ }
101
+ init();
102
+ return {
103
+ /**
104
+ * Called by Svelte when the action parameters change.
105
+ * Performs incremental updates for rowData and columns changes.
106
+ */
107
+ update(newParams) {
108
+ if (engine && newParams.props.rowData !== params.props.rowData) {
109
+ engine.api.setRowData(newParams.props.rowData);
110
+ }
111
+ if (engine && newParams.props.columns !== params.props.columns) {
112
+ engine.api.setColumnDefs(newParams.props.columns);
113
+ }
114
+ params = newParams;
115
+ },
116
+ /**
117
+ * Called by Svelte when the element is removed from the DOM.
118
+ * Cleans up the engine, renderer, and all event subscriptions.
119
+ */
120
+ destroy
121
+ };
122
+ }
123
+
124
+ // src/composables/useGridApi.ts
125
+ var currentApi = null;
126
+ var listeners = /* @__PURE__ */ new Set();
127
+ function setGridApi(api) {
128
+ currentApi = api;
129
+ listeners.forEach((fn) => fn(api));
130
+ }
131
+ function getGridApi() {
132
+ return currentApi;
133
+ }
134
+ function onGridApiChange(listener) {
135
+ listeners.add(listener);
136
+ return () => listeners.delete(listener);
137
+ }
138
+
139
+ // src/composables/useGridState.ts
140
+ function getGridState(selector) {
141
+ const api = getGridApi();
142
+ if (!api) return void 0;
143
+ const state = api.getState();
144
+ if (!state) return void 0;
145
+ return selector(state);
146
+ }
147
+
148
+ // src/composables/useGridEvent.ts
149
+ function subscribeToGridEvent(event, callback) {
150
+ const api = getGridApi();
151
+ if (!api) return () => {
152
+ };
153
+ api.addEventListener(event, callback);
154
+ return () => {
155
+ api.removeEventListener(event, callback);
156
+ };
157
+ }
158
+
159
+ // src/composables/useGridSelection.ts
160
+ function getSelectedRows() {
161
+ const api = getGridApi();
162
+ if (!api) return [];
163
+ return api.getSelectedNodes();
164
+ }
165
+ function selectAll() {
166
+ const api = getGridApi();
167
+ if (!api) return;
168
+ api.selectAll();
169
+ }
170
+ function deselectAll() {
171
+ const api = getGridApi();
172
+ if (!api) return;
173
+ api.deselectAll();
174
+ }
175
+
176
+ // src/composables/useGridSort.ts
177
+ function getSortModel() {
178
+ const api = getGridApi();
179
+ if (!api) return [];
180
+ return api.getSortModel();
181
+ }
182
+ function setSortModel(model) {
183
+ const api = getGridApi();
184
+ if (!api) return;
185
+ api.setSortModel(model);
186
+ }
187
+
188
+ // src/composables/useGridFilter.ts
189
+ function getFilterModel() {
190
+ const api = getGridApi();
191
+ if (!api) return {};
192
+ return api.getFilterModel();
193
+ }
194
+ function setFilterModel(model) {
195
+ const api = getGridApi();
196
+ if (!api) return;
197
+ api.setFilterModel(model);
198
+ }
199
+ function setQuickFilter(text) {
200
+ const api = getGridApi();
201
+ if (!api) return;
202
+ api.setQuickFilter(text);
203
+ }
204
+
205
+ // src/composables/useGridPagination.ts
206
+ function getPaginationState() {
207
+ const api = getGridApi();
208
+ if (!api) {
209
+ return { currentPage: 0, pageSize: 10, totalPages: 0, totalRows: 0 };
210
+ }
211
+ const state = api.getState();
212
+ const pagination = state.pagination;
213
+ const totalPages = Math.max(
214
+ 1,
215
+ Math.ceil(pagination.totalRows / pagination.pageSize)
216
+ );
217
+ return {
218
+ currentPage: pagination.currentPage,
219
+ pageSize: pagination.pageSize,
220
+ totalPages,
221
+ totalRows: pagination.totalRows
222
+ };
223
+ }
224
+ function goToPage(page) {
225
+ const api = getGridApi();
226
+ if (!api) return;
227
+ api.paginationGoToPage(page);
228
+ }
229
+
230
+ exports.deselectAll = deselectAll;
231
+ exports.getFilterModel = getFilterModel;
232
+ exports.getGridApi = getGridApi;
233
+ exports.getGridState = getGridState;
234
+ exports.getPaginationState = getPaginationState;
235
+ exports.getSelectedRows = getSelectedRows;
236
+ exports.getSortModel = getSortModel;
237
+ exports.goToPage = goToPage;
238
+ exports.gridstormAction = gridstormAction;
239
+ exports.onGridApiChange = onGridApiChange;
240
+ exports.selectAll = selectAll;
241
+ exports.setFilterModel = setFilterModel;
242
+ exports.setGridApi = setGridApi;
243
+ exports.setQuickFilter = setQuickFilter;
244
+ exports.setSortModel = setSortModel;
245
+ exports.subscribeToGridEvent = subscribeToGridEvent;
246
+ //# sourceMappingURL=index.cjs.map
247
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/gridstorm-action.ts","../src/composables/useGridApi.ts","../src/composables/useGridState.ts","../src/composables/useGridEvent.ts","../src/composables/useGridSelection.ts","../src/composables/useGridSort.ts","../src/composables/useGridFilter.ts","../src/composables/useGridPagination.ts"],"names":["createGrid","DomRenderer"],"mappings":";;;;;;AAuEO,SAAS,eAAA,CACd,WACA,MAAA,EACA;AACA,EAAA,IAAI,MAAA,GAAmC,IAAA;AACvC,EAAA,IAAI,QAAA,GAA+B,IAAA;AACnC,EAAA,MAAM,SAA4B,EAAC;AAEnC,EAAA,SAAS,IAAA,GAAO;AACd,IAAA,MAAM,EAAE,KAAA,EAAO,MAAA,EAAQ,OAAA,EAAQ,GAAI,MAAA;AAGnC,IAAA,MAAM,MAAA,GAA4B;AAAA,MAChC,SAAS,KAAA,CAAM,OAAA;AAAA,MACf,SAAS,KAAA,CAAM,OAAA;AAAA,MACf,OAAA,EAAS,KAAA,CAAM,OAAA,IAAW,EAAC;AAAA,MAC3B,QAAA,EAAU,MAAM,QAAA,GACZ,CAAC,MAAM,KAAA,CAAM,QAAA,CAAU,CAAA,CAAE,IAAI,CAAA,GAC7B,MAAA;AAAA,MACJ,WAAW,KAAA,CAAM,SAAA;AAAA,MACjB,cAAc,KAAA,CAAM,YAAA;AAAA,MACpB,OAAO,KAAA,CAAM;AAAA,KACf;AAGA,IAAA,MAAA,GAASA,gBAAW,MAAM,CAAA;AAG1B,IAAA,QAAA,GAAW,IAAIC,uBAAA,CAAY;AAAA,MACzB,SAAA;AAAA,MACA,MAAA;AAAA,MACA,mBAAmB,KAAA,CAAM,iBAAA;AAAA,MACzB,gBAAgB,KAAA,CAAM,cAAA;AAAA,MACtB,gBAAgB,KAAA,CAAM,cAAA;AAAA,MACtB,kBAAkB,KAAA,CAAM,gBAAA;AAAA,MACxB,iBAAiB,KAAA,CAAM,kBAAA,GACnB,CAAC,KAAA,CAAM,kBAAkB,CAAA,GACzB;AAAA,KACL,CAAA;AACD,IAAA,QAAA,CAAS,KAAA,EAAM;AAGf,IAAA,IAAI,MAA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AACvE,EAAA,MAAM,MAAM,UAAA,EAAW;AACvB,EAAA,IAAI,CAAC,GAAA,EAAK;AACV,EAAA,GAAA,CAAI,eAAe,KAAK,CAAA;AAC1B;AAOO,SAAS,eAAe,IAAA,EAAoB;AACjD,EAAA,MAAM,MAAM,UAAA,EAAW;AACvB,EAAA,IAAI,CAAC,GAAA,EAAK;AACV,EAAA,GAAA,CAAI,eAAe,IAAI,CAAA;AACzB;;;ACdO,SAAS,kBAAA,GAAsC;AACpD,EAAA,MAAM,MAAM,UAAA,EAAW;AACvB,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,OAAO,EAAE,aAAa,CAAA,EAAG,QAAA,EAAU,IAAI,UAAA,EAAY,CAAA,EAAG,WAAW,CAAA,EAAE;AAAA,EACrE;AAEA,EAAA,MAAM,KAAA,GAAQ,IAAI,QAAA,EAAS;AAC3B,EAAA,MAAM,aAAa,KAAA,CAAM,UAAA;AACzB,EAAA,MAAM,aAAa,IAAA,CAAK,GAAA;AAAA,IACtB,CAAA;AAAA,IACA,IAAA,CAAK,IAAA,CAAK,UAAA,CAAW,SAAA,GAAY,WAAW,QAAQ;AAAA,GACtD;AAEA,EAAA,OAAO;AAAA,IACL,aAAa,UAAA,CAAW,WAAA;AAAA,IACxB,UAAU,UAAA,CAAW,QAAA;AAAA,IACrB,UAAA;AAAA,IACA,WAAW,UAAA,CAAW;AAAA,GACxB;AACF;AAOO,SAAS,SAAS,IAAA,EAAoB;AAC3C,EAAA,MAAM,MAAM,UAAA,EAAW;AACvB,EAAA,IAAI,CAAC,GAAA,EAAK;AACV,EAAA,GAAA,CAAI,mBAAmB,IAAI,CAAA;AAC7B","file":"index.cjs","sourcesContent":["// ─── GridStorm Svelte Action ───\n// The core of the Svelte 5 adapter. Implements a Svelte \"action\" — a function\n// that takes a DOM element and manages the GridStorm lifecycle (create, update, destroy).\n//\n// Usage in a Svelte 5 component:\n//\n// <script lang=\"ts\">\n// import { gridstormAction } from '@gridstorm/svelte';\n//\n// const columns = [{ field: 'name' }, { field: 'age' }];\n// const rowData = [{ name: 'Alice', age: 30 }];\n// </script>\n//\n// <div use:gridstormAction={{ props: { columns, rowData } }} style=\"height: 400px\" />\n\nimport { createGrid } from '@gridstorm/core';\nimport type { GridEngine, GridApi, GridConfig } from '@gridstorm/core';\nimport { DomRenderer } from '@gridstorm/dom-renderer';\nimport type { GridStormProps, GridStormEventHandlers } from './types';\n\n/**\n * Parameters for the gridstormAction Svelte action.\n *\n * @typeParam TData - The type of each row data object.\n */\nexport interface GridStormActionParams<TData = any> {\n /** Grid configuration props. */\n props: GridStormProps<TData>;\n /** Event handler callbacks. */\n events?: GridStormEventHandlers<TData>;\n /** Callback fired when the engine and API are ready. */\n onReady?: (api: GridApi<TData>, engine: GridEngine<TData>) => void;\n}\n\n/**\n * Svelte action that creates and manages a GridStorm instance on a DOM element.\n *\n * This is the primary integration point for using GridStorm in Svelte 5.\n * It handles engine creation, DOM renderer mounting, event bridging,\n * reactive updates (rowData, columns), and cleanup on destroy.\n *\n * @param container - The DOM element to mount the grid into.\n * @param params - Configuration including props, event handlers, and ready callback.\n * @returns A Svelte action interface with `update` and `destroy` methods.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { gridstormAction } from '@gridstorm/svelte';\n * import { sortingPlugin } from '@gridstorm/plugin-sorting';\n *\n * let api = $state(null);\n * const columns = [\n * { field: 'name', headerName: 'Name', sortable: true },\n * { field: 'age', headerName: 'Age', width: 100 },\n * ];\n * const rowData = [\n * { name: 'Alice', age: 30 },\n * { name: 'Bob', age: 25 },\n * ];\n * </script>\n *\n * <div\n * use:gridstormAction={{\n * props: { columns, rowData, plugins: [sortingPlugin()] },\n * onReady: (gridApi) => { api = gridApi; },\n * }}\n * style=\"height: 400px\"\n * />\n * ```\n */\nexport function gridstormAction<TData = any>(\n container: HTMLElement,\n params: GridStormActionParams<TData>,\n) {\n let engine: GridEngine<TData> | null = null;\n let renderer: DomRenderer | null = null;\n const unsubs: Array<() => void> = [];\n\n function init() {\n const { props, events, onReady } = params;\n\n // Build grid config from props\n const config: GridConfig<TData> = {\n columns: props.columns,\n rowData: props.rowData,\n plugins: props.plugins || [],\n getRowId: props.getRowId\n ? (p) => props.getRowId!(p.data)\n : undefined,\n rowHeight: props.rowHeight,\n headerHeight: props.headerHeight,\n theme: props.theme,\n };\n\n // Create the headless grid engine\n engine = createGrid(config);\n\n // Create and mount the DOM renderer\n renderer = new DomRenderer({\n container,\n engine,\n enableCellEditing: props.enableCellEditing,\n enableGrouping: props.enableGrouping,\n floatingFilter: props.floatingFilter,\n enablePagination: props.enablePagination,\n pageSizeOptions: props.paginationPageSize\n ? [props.paginationPageSize]\n : undefined,\n });\n renderer.mount();\n\n // Apply density as a data attribute on the container\n if (props.density) {\n container.setAttribute('data-density', props.density);\n }\n\n // ── Event bridge: core events -> Svelte callbacks ──\n\n if (events?.onSelectionChanged) {\n unsubs.push(\n engine.eventBus.on('selection:changed', () => {\n events.onSelectionChanged!(engine!.api.getSelectedNodes());\n }),\n );\n }\n\n if (events?.onSortChanged) {\n unsubs.push(\n engine.eventBus.on('column:sort:changed', (e: any) => {\n events.onSortChanged!(e.sortModel || []);\n }),\n );\n }\n\n if (events?.onFilterChanged) {\n unsubs.push(\n engine.eventBus.on('filter:changed', (e: any) => {\n events.onFilterChanged!(e.filterModel || {});\n }),\n );\n }\n\n if (events?.onCellValueChanged) {\n unsubs.push(\n engine.eventBus.on('cell:valueChanged', (e: any) => {\n events.onCellValueChanged!(e);\n }),\n );\n }\n\n if (events?.onRowClicked) {\n unsubs.push(\n engine.eventBus.on('row:clicked', (e: any) => {\n events.onRowClicked!(e.node);\n }),\n );\n }\n\n if (events?.onPaginationChanged) {\n unsubs.push(\n engine.eventBus.on('pagination:changed', (e: any) => {\n events.onPaginationChanged!(e);\n }),\n );\n }\n\n if (events?.onColumnResized) {\n unsubs.push(\n engine.eventBus.on('column:resized', (e: any) => {\n events.onColumnResized!(e);\n }),\n );\n }\n\n // Fire grid:ready after the renderer has mounted and DOM is populated.\n // Plugins like column-resize and context-menu use rAF on grid:ready to\n // inject DOM elements, so we re-emit after the renderer is in the DOM.\n requestAnimationFrame(() => {\n if (engine) {\n engine.eventBus.emit('grid:ready', { api: engine.api });\n events?.onGridReady?.(engine.api);\n onReady?.(engine.api, engine);\n }\n });\n }\n\n function destroy() {\n unsubs.forEach((fn) => fn());\n unsubs.length = 0;\n renderer?.destroy();\n engine?.destroy();\n renderer = null;\n engine = null;\n }\n\n // Initialize the grid\n init();\n\n // Return the Svelte action interface\n return {\n /**\n * Called by Svelte when the action parameters change.\n * Performs incremental updates for rowData and columns changes.\n */\n update(newParams: GridStormActionParams<TData>) {\n if (engine && newParams.props.rowData !== params.props.rowData) {\n engine.api.setRowData(newParams.props.rowData);\n }\n if (engine && newParams.props.columns !== params.props.columns) {\n engine.api.setColumnDefs(newParams.props.columns);\n }\n params = newParams;\n },\n\n /**\n * Called by Svelte when the element is removed from the DOM.\n * Cleans up the engine, renderer, and all event subscriptions.\n */\n destroy,\n };\n}\n","// ─── Grid API Store ───\n// Lightweight store for the current GridApi reference.\n// In Svelte 5, there is no provide/inject like Vue or React context.\n// Instead, this module-level store allows any component to access the\n// grid API after initialization. Call setGridApi from the onReady callback\n// and getGridApi from anywhere in your component tree.\n\nimport type { GridApi } from '@gridstorm/core';\n\n/** Module-level reference to the current grid API. */\nlet currentApi: GridApi | null = null;\n\n/** Set of listeners notified when the API changes. */\nconst listeners = new Set<(api: GridApi | null) => void>();\n\n/**\n * Set the current grid API reference.\n *\n * Call this from the `onReady` callback of `gridstormAction` to make\n * the API available to composable helper functions.\n *\n * @param api - The grid API instance, or `null` to clear it.\n */\nexport function setGridApi(api: GridApi | null): void {\n currentApi = api;\n listeners.forEach((fn) => fn(api));\n}\n\n/**\n * Get the current grid API reference.\n *\n * Returns `null` if the grid has not been initialized yet or has been destroyed.\n *\n * @typeParam TData - The type of each row data object.\n * @returns The current GridApi instance, or `null`.\n */\nexport function getGridApi<TData = any>(): GridApi<TData> | null {\n return currentApi as GridApi<TData> | null;\n}\n\n/**\n * Register a listener that is called whenever the grid API changes.\n *\n * @param listener - Callback invoked with the new API (or `null` on destroy).\n * @returns An unsubscribe function.\n */\nexport function onGridApiChange(\n listener: (api: GridApi | null) => void,\n): () => void {\n listeners.add(listener);\n return () => listeners.delete(listener);\n}\n","// ─── Grid State Accessor ───\n// Provides direct access to the grid store state via a selector function.\n\nimport type { GridState } from '@gridstorm/core';\nimport { getGridApi } from './useGridApi';\n\n/**\n * Read a slice of the grid store state using a selector function.\n *\n * Returns `undefined` if the grid has not been initialized yet.\n * This function reads state synchronously (snapshot) and does not\n * set up a reactive subscription. For reactive state in Svelte 5,\n * subscribe to grid events or use `$effect` with periodic polling.\n *\n * @typeParam T - The type of the selected state slice.\n * @param selector - A function that extracts a value from the grid state.\n * @returns The selected state value, or `undefined` if not available.\n *\n * @example\n * ```ts\n * import { getGridState } from '@gridstorm/svelte';\n *\n * const sortModel = getGridState((state) => state.sortModel);\n * ```\n */\nexport function getGridState<T>(selector: (state: GridState) => T): T | undefined {\n const api = getGridApi();\n if (!api) return undefined;\n const state = api.getState();\n if (!state) return undefined;\n return selector(state);\n}\n","// ─── Grid Event Subscription ───\n// Provides a helper to subscribe to grid events from Svelte components.\n\nimport type { GridEventMap } from '@gridstorm/core';\nimport { getGridApi } from './useGridApi';\n\n/**\n * Subscribe to a grid event by name.\n *\n * Returns an unsubscribe function. If the grid has not been initialized yet,\n * returns a no-op unsubscribe function.\n *\n * In Svelte 5, call this inside `$effect` or `onMount` and clean up\n * the subscription in the effect's cleanup or `onDestroy`.\n *\n * @typeParam K - The event key from GridEventMap.\n * @param event - The event name to listen for.\n * @param callback - Callback invoked when the event fires.\n * @returns An unsubscribe function.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { onMount, onDestroy } from 'svelte';\n * import { subscribeToGridEvent } from '@gridstorm/svelte';\n *\n * let unsub: () => void;\n * onMount(() => {\n * unsub = subscribeToGridEvent('selection:changed', (e) => {\n * console.log('Selection changed:', e);\n * });\n * });\n * onDestroy(() => unsub?.());\n * </script>\n * ```\n */\nexport function subscribeToGridEvent<K extends string & keyof GridEventMap>(\n event: K,\n callback: (payload: GridEventMap[K]) => void,\n): () => void {\n const api = getGridApi();\n if (!api) return () => {};\n\n // Access the engine's event bus through the API's addEventListener\n api.addEventListener(event as any, callback as any);\n\n return () => {\n api.removeEventListener(event as any, callback as any);\n };\n}\n","// ─── Grid Selection Helpers ───\n// Convenience functions for managing row selection in Svelte components.\n\nimport type { RowNode } from '@gridstorm/core';\nimport { getGridApi } from './useGridApi';\n\n/**\n * Get the currently selected row nodes.\n *\n * Returns an empty array if the grid has not been initialized yet.\n *\n * @typeParam TData - The type of each row data object.\n * @returns Array of selected RowNode objects.\n */\nexport function getSelectedRows<TData = any>(): RowNode<TData>[] {\n const api = getGridApi<TData>();\n if (!api) return [];\n return api.getSelectedNodes();\n}\n\n/**\n * Select all rows that pass the current filter.\n */\nexport function selectAll(): void {\n const api = getGridApi();\n if (!api) return;\n api.selectAll();\n}\n\n/**\n * Deselect all currently selected rows.\n */\nexport function deselectAll(): void {\n const api = getGridApi();\n if (!api) return;\n api.deselectAll();\n}\n","// ─── Grid Sort Helpers ───\n// Convenience functions for managing sort state in Svelte components.\n\nimport type { SortModelItem } from '@gridstorm/core';\nimport { getGridApi } from './useGridApi';\n\n/**\n * Get the current sort model.\n *\n * @returns Array of active sort items, or an empty array if not available.\n */\nexport function getSortModel(): SortModelItem[] {\n const api = getGridApi();\n if (!api) return [];\n return api.getSortModel();\n}\n\n/**\n * Set the sort model, replacing any existing sort configuration.\n *\n * @param model - Array of sort items specifying column and direction.\n */\nexport function setSortModel(model: SortModelItem[]): void {\n const api = getGridApi();\n if (!api) return;\n api.setSortModel(model);\n}\n","// ─── Grid Filter Helpers ───\n// Convenience functions for managing filter state in Svelte components.\n\nimport type { FilterModel } from '@gridstorm/core';\nimport { getGridApi } from './useGridApi';\n\n/**\n * Get the current filter model for all columns.\n *\n * @returns Object keyed by column ID with active filter models,\n * or an empty object if not available.\n */\nexport function getFilterModel(): Record<string, FilterModel> {\n const api = getGridApi();\n if (!api) return {};\n return api.getFilterModel();\n}\n\n/**\n * Set the filter model, replacing all active filters.\n *\n * @param model - Object keyed by column ID with filter models.\n */\nexport function setFilterModel(model: Record<string, FilterModel>): void {\n const api = getGridApi();\n if (!api) return;\n api.setFilterModel(model);\n}\n\n/**\n * Apply a quick filter across all columns.\n *\n * @param text - The filter text. Pass an empty string to clear.\n */\nexport function setQuickFilter(text: string): void {\n const api = getGridApi();\n if (!api) return;\n api.setQuickFilter(text);\n}\n","// ─── Grid Pagination Helpers ───\n// Convenience functions for managing pagination in Svelte components.\n\nimport { getGridApi } from './useGridApi';\n\n/**\n * Pagination state snapshot.\n */\nexport interface PaginationState {\n /** Current page (zero-based). */\n currentPage: number;\n /** Rows per page. */\n pageSize: number;\n /** Total number of pages. */\n totalPages: number;\n /** Total row count. */\n totalRows: number;\n}\n\n/**\n * Get the current pagination state.\n *\n * @returns A snapshot of pagination state, or defaults if not available.\n */\nexport function getPaginationState(): PaginationState {\n const api = getGridApi();\n if (!api) {\n return { currentPage: 0, pageSize: 10, totalPages: 0, totalRows: 0 };\n }\n\n const state = api.getState();\n const pagination = state.pagination;\n const totalPages = Math.max(\n 1,\n Math.ceil(pagination.totalRows / pagination.pageSize),\n );\n\n return {\n currentPage: pagination.currentPage,\n pageSize: pagination.pageSize,\n totalPages,\n totalRows: pagination.totalRows,\n };\n}\n\n/**\n * Navigate to a specific page (zero-based index).\n *\n * @param page - The zero-based page number to navigate to.\n */\nexport function goToPage(page: number): void {\n const api = getGridApi();\n if (!api) return;\n api.paginationGoToPage(page);\n}\n"]}
@@ -0,0 +1,312 @@
1
+ import { ColumnDef, GridPlugin, GridApi, RowNode, GridEngine, GridState, GridEventMap, SortModelItem, FilterModel } from '@gridstorm/core';
2
+ export { CellEditorDef, CellPosition, ColumnDef, ColumnState, EditingState, FilterModel, GridApi, GridConfig, GridEventMap, GridPlugin, GridState, PinnedPosition, RowNode, SelectionState, SortDirection, SortModelItem } from '@gridstorm/core';
3
+
4
+ /**
5
+ * Props for the GridStorm Svelte action.
6
+ *
7
+ * Defines column structure, row data, plugins, and behavioral options
8
+ * for configuring a GridStorm instance within a Svelte component.
9
+ *
10
+ * @typeParam TData - The type of each row data object.
11
+ */
12
+ interface GridStormProps<TData = any> {
13
+ /** Column definitions. */
14
+ columns: ColumnDef<TData>[];
15
+ /** Row data array. */
16
+ rowData: TData[];
17
+ /** Plugins to install. */
18
+ plugins?: GridPlugin<TData>[];
19
+ /** Row ID getter function. */
20
+ getRowId?: (data: TData) => string;
21
+ /** Row height in pixels. */
22
+ rowHeight?: number;
23
+ /** Header height in pixels. */
24
+ headerHeight?: number;
25
+ /** Theme identifier (e.g., 'light', 'dark'). */
26
+ theme?: string;
27
+ /** Density mode. */
28
+ density?: 'compact' | 'normal' | 'comfortable';
29
+ /** Container height. */
30
+ height?: string | number;
31
+ /** Container width. */
32
+ width?: string | number;
33
+ /** Additional CSS class for the container. */
34
+ containerClass?: string;
35
+ /** Enable inline cell editing overlay. */
36
+ enableCellEditing?: boolean;
37
+ /** Enable row grouping visual (chevron, indent, group label). */
38
+ enableGrouping?: boolean;
39
+ /** Show floating filter inputs below the header. */
40
+ floatingFilter?: boolean;
41
+ /** Show pagination bar below the grid. */
42
+ enablePagination?: boolean;
43
+ /** Number of rows per page when pagination is enabled. */
44
+ paginationPageSize?: number;
45
+ }
46
+ /**
47
+ * Context value exposing the grid engine and API.
48
+ *
49
+ * @typeParam TData - The type of each row data object.
50
+ */
51
+ interface GridStormContext<TData = any> {
52
+ /** Get the GridApi instance, or null if not yet initialized. */
53
+ getApi(): GridApi<TData> | null;
54
+ /** Get the GridEngine instance, or null if not yet initialized. */
55
+ getEngine(): GridEngine<TData> | null;
56
+ }
57
+ /**
58
+ * Event handler callbacks for the GridStorm Svelte action.
59
+ *
60
+ * @typeParam TData - The type of each row data object.
61
+ */
62
+ interface GridStormEventHandlers<TData = any> {
63
+ /** Fired when the grid engine is ready and the API is available. */
64
+ onGridReady?: (api: GridApi<TData>) => void;
65
+ /** Fired when the selection changes. */
66
+ onSelectionChanged?: (selectedNodes: RowNode<TData>[]) => void;
67
+ /** Fired when the sort model changes. */
68
+ onSortChanged?: (sortModel: any[]) => void;
69
+ /** Fired when the filter model changes. */
70
+ onFilterChanged?: (filterModel: Record<string, any>) => void;
71
+ /** Fired when a cell value is changed via editing. */
72
+ onCellValueChanged?: (params: {
73
+ rowId: string;
74
+ field: string;
75
+ oldValue: any;
76
+ newValue: any;
77
+ }) => void;
78
+ /** Fired when a row is clicked. */
79
+ onRowClicked?: (node: RowNode<TData>) => void;
80
+ /** Fired when pagination state changes. */
81
+ onPaginationChanged?: (params: {
82
+ currentPage: number;
83
+ pageSize: number;
84
+ totalRows: number;
85
+ }) => void;
86
+ /** Fired when a column is resized. */
87
+ onColumnResized?: (params: {
88
+ colId: string;
89
+ width: number;
90
+ }) => void;
91
+ }
92
+
93
+ /**
94
+ * Parameters for the gridstormAction Svelte action.
95
+ *
96
+ * @typeParam TData - The type of each row data object.
97
+ */
98
+ interface GridStormActionParams<TData = any> {
99
+ /** Grid configuration props. */
100
+ props: GridStormProps<TData>;
101
+ /** Event handler callbacks. */
102
+ events?: GridStormEventHandlers<TData>;
103
+ /** Callback fired when the engine and API are ready. */
104
+ onReady?: (api: GridApi<TData>, engine: GridEngine<TData>) => void;
105
+ }
106
+ /**
107
+ * Svelte action that creates and manages a GridStorm instance on a DOM element.
108
+ *
109
+ * This is the primary integration point for using GridStorm in Svelte 5.
110
+ * It handles engine creation, DOM renderer mounting, event bridging,
111
+ * reactive updates (rowData, columns), and cleanup on destroy.
112
+ *
113
+ * @param container - The DOM element to mount the grid into.
114
+ * @param params - Configuration including props, event handlers, and ready callback.
115
+ * @returns A Svelte action interface with `update` and `destroy` methods.
116
+ *
117
+ * @example
118
+ * ```svelte
119
+ * <script lang="ts">
120
+ * import { gridstormAction } from '@gridstorm/svelte';
121
+ * import { sortingPlugin } from '@gridstorm/plugin-sorting';
122
+ *
123
+ * let api = $state(null);
124
+ * const columns = [
125
+ * { field: 'name', headerName: 'Name', sortable: true },
126
+ * { field: 'age', headerName: 'Age', width: 100 },
127
+ * ];
128
+ * const rowData = [
129
+ * { name: 'Alice', age: 30 },
130
+ * { name: 'Bob', age: 25 },
131
+ * ];
132
+ * </script>
133
+ *
134
+ * <div
135
+ * use:gridstormAction={{
136
+ * props: { columns, rowData, plugins: [sortingPlugin()] },
137
+ * onReady: (gridApi) => { api = gridApi; },
138
+ * }}
139
+ * style="height: 400px"
140
+ * />
141
+ * ```
142
+ */
143
+ declare function gridstormAction<TData = any>(container: HTMLElement, params: GridStormActionParams<TData>): {
144
+ /**
145
+ * Called by Svelte when the action parameters change.
146
+ * Performs incremental updates for rowData and columns changes.
147
+ */
148
+ update(newParams: GridStormActionParams<TData>): void;
149
+ /**
150
+ * Called by Svelte when the element is removed from the DOM.
151
+ * Cleans up the engine, renderer, and all event subscriptions.
152
+ */
153
+ destroy: () => void;
154
+ };
155
+
156
+ /**
157
+ * Set the current grid API reference.
158
+ *
159
+ * Call this from the `onReady` callback of `gridstormAction` to make
160
+ * the API available to composable helper functions.
161
+ *
162
+ * @param api - The grid API instance, or `null` to clear it.
163
+ */
164
+ declare function setGridApi(api: GridApi | null): void;
165
+ /**
166
+ * Get the current grid API reference.
167
+ *
168
+ * Returns `null` if the grid has not been initialized yet or has been destroyed.
169
+ *
170
+ * @typeParam TData - The type of each row data object.
171
+ * @returns The current GridApi instance, or `null`.
172
+ */
173
+ declare function getGridApi<TData = any>(): GridApi<TData> | null;
174
+ /**
175
+ * Register a listener that is called whenever the grid API changes.
176
+ *
177
+ * @param listener - Callback invoked with the new API (or `null` on destroy).
178
+ * @returns An unsubscribe function.
179
+ */
180
+ declare function onGridApiChange(listener: (api: GridApi | null) => void): () => void;
181
+
182
+ /**
183
+ * Read a slice of the grid store state using a selector function.
184
+ *
185
+ * Returns `undefined` if the grid has not been initialized yet.
186
+ * This function reads state synchronously (snapshot) and does not
187
+ * set up a reactive subscription. For reactive state in Svelte 5,
188
+ * subscribe to grid events or use `$effect` with periodic polling.
189
+ *
190
+ * @typeParam T - The type of the selected state slice.
191
+ * @param selector - A function that extracts a value from the grid state.
192
+ * @returns The selected state value, or `undefined` if not available.
193
+ *
194
+ * @example
195
+ * ```ts
196
+ * import { getGridState } from '@gridstorm/svelte';
197
+ *
198
+ * const sortModel = getGridState((state) => state.sortModel);
199
+ * ```
200
+ */
201
+ declare function getGridState<T>(selector: (state: GridState) => T): T | undefined;
202
+
203
+ /**
204
+ * Subscribe to a grid event by name.
205
+ *
206
+ * Returns an unsubscribe function. If the grid has not been initialized yet,
207
+ * returns a no-op unsubscribe function.
208
+ *
209
+ * In Svelte 5, call this inside `$effect` or `onMount` and clean up
210
+ * the subscription in the effect's cleanup or `onDestroy`.
211
+ *
212
+ * @typeParam K - The event key from GridEventMap.
213
+ * @param event - The event name to listen for.
214
+ * @param callback - Callback invoked when the event fires.
215
+ * @returns An unsubscribe function.
216
+ *
217
+ * @example
218
+ * ```svelte
219
+ * <script lang="ts">
220
+ * import { onMount, onDestroy } from 'svelte';
221
+ * import { subscribeToGridEvent } from '@gridstorm/svelte';
222
+ *
223
+ * let unsub: () => void;
224
+ * onMount(() => {
225
+ * unsub = subscribeToGridEvent('selection:changed', (e) => {
226
+ * console.log('Selection changed:', e);
227
+ * });
228
+ * });
229
+ * onDestroy(() => unsub?.());
230
+ * </script>
231
+ * ```
232
+ */
233
+ declare function subscribeToGridEvent<K extends string & keyof GridEventMap>(event: K, callback: (payload: GridEventMap[K]) => void): () => void;
234
+
235
+ /**
236
+ * Get the currently selected row nodes.
237
+ *
238
+ * Returns an empty array if the grid has not been initialized yet.
239
+ *
240
+ * @typeParam TData - The type of each row data object.
241
+ * @returns Array of selected RowNode objects.
242
+ */
243
+ declare function getSelectedRows<TData = any>(): RowNode<TData>[];
244
+ /**
245
+ * Select all rows that pass the current filter.
246
+ */
247
+ declare function selectAll(): void;
248
+ /**
249
+ * Deselect all currently selected rows.
250
+ */
251
+ declare function deselectAll(): void;
252
+
253
+ /**
254
+ * Get the current sort model.
255
+ *
256
+ * @returns Array of active sort items, or an empty array if not available.
257
+ */
258
+ declare function getSortModel(): SortModelItem[];
259
+ /**
260
+ * Set the sort model, replacing any existing sort configuration.
261
+ *
262
+ * @param model - Array of sort items specifying column and direction.
263
+ */
264
+ declare function setSortModel(model: SortModelItem[]): void;
265
+
266
+ /**
267
+ * Get the current filter model for all columns.
268
+ *
269
+ * @returns Object keyed by column ID with active filter models,
270
+ * or an empty object if not available.
271
+ */
272
+ declare function getFilterModel(): Record<string, FilterModel>;
273
+ /**
274
+ * Set the filter model, replacing all active filters.
275
+ *
276
+ * @param model - Object keyed by column ID with filter models.
277
+ */
278
+ declare function setFilterModel(model: Record<string, FilterModel>): void;
279
+ /**
280
+ * Apply a quick filter across all columns.
281
+ *
282
+ * @param text - The filter text. Pass an empty string to clear.
283
+ */
284
+ declare function setQuickFilter(text: string): void;
285
+
286
+ /**
287
+ * Pagination state snapshot.
288
+ */
289
+ interface PaginationState {
290
+ /** Current page (zero-based). */
291
+ currentPage: number;
292
+ /** Rows per page. */
293
+ pageSize: number;
294
+ /** Total number of pages. */
295
+ totalPages: number;
296
+ /** Total row count. */
297
+ totalRows: number;
298
+ }
299
+ /**
300
+ * Get the current pagination state.
301
+ *
302
+ * @returns A snapshot of pagination state, or defaults if not available.
303
+ */
304
+ declare function getPaginationState(): PaginationState;
305
+ /**
306
+ * Navigate to a specific page (zero-based index).
307
+ *
308
+ * @param page - The zero-based page number to navigate to.
309
+ */
310
+ declare function goToPage(page: number): void;
311
+
312
+ export { type GridStormActionParams, type GridStormContext, type GridStormEventHandlers, type GridStormProps, type PaginationState, deselectAll, getFilterModel, getGridApi, getGridState, getPaginationState, getSelectedRows, getSortModel, goToPage, gridstormAction, onGridApiChange, selectAll, setFilterModel, setGridApi, setQuickFilter, setSortModel, subscribeToGridEvent };
@@ -0,0 +1,312 @@
1
+ import { ColumnDef, GridPlugin, GridApi, RowNode, GridEngine, GridState, GridEventMap, SortModelItem, FilterModel } from '@gridstorm/core';
2
+ export { CellEditorDef, CellPosition, ColumnDef, ColumnState, EditingState, FilterModel, GridApi, GridConfig, GridEventMap, GridPlugin, GridState, PinnedPosition, RowNode, SelectionState, SortDirection, SortModelItem } from '@gridstorm/core';
3
+
4
+ /**
5
+ * Props for the GridStorm Svelte action.
6
+ *
7
+ * Defines column structure, row data, plugins, and behavioral options
8
+ * for configuring a GridStorm instance within a Svelte component.
9
+ *
10
+ * @typeParam TData - The type of each row data object.
11
+ */
12
+ interface GridStormProps<TData = any> {
13
+ /** Column definitions. */
14
+ columns: ColumnDef<TData>[];
15
+ /** Row data array. */
16
+ rowData: TData[];
17
+ /** Plugins to install. */
18
+ plugins?: GridPlugin<TData>[];
19
+ /** Row ID getter function. */
20
+ getRowId?: (data: TData) => string;
21
+ /** Row height in pixels. */
22
+ rowHeight?: number;
23
+ /** Header height in pixels. */
24
+ headerHeight?: number;
25
+ /** Theme identifier (e.g., 'light', 'dark'). */
26
+ theme?: string;
27
+ /** Density mode. */
28
+ density?: 'compact' | 'normal' | 'comfortable';
29
+ /** Container height. */
30
+ height?: string | number;
31
+ /** Container width. */
32
+ width?: string | number;
33
+ /** Additional CSS class for the container. */
34
+ containerClass?: string;
35
+ /** Enable inline cell editing overlay. */
36
+ enableCellEditing?: boolean;
37
+ /** Enable row grouping visual (chevron, indent, group label). */
38
+ enableGrouping?: boolean;
39
+ /** Show floating filter inputs below the header. */
40
+ floatingFilter?: boolean;
41
+ /** Show pagination bar below the grid. */
42
+ enablePagination?: boolean;
43
+ /** Number of rows per page when pagination is enabled. */
44
+ paginationPageSize?: number;
45
+ }
46
+ /**
47
+ * Context value exposing the grid engine and API.
48
+ *
49
+ * @typeParam TData - The type of each row data object.
50
+ */
51
+ interface GridStormContext<TData = any> {
52
+ /** Get the GridApi instance, or null if not yet initialized. */
53
+ getApi(): GridApi<TData> | null;
54
+ /** Get the GridEngine instance, or null if not yet initialized. */
55
+ getEngine(): GridEngine<TData> | null;
56
+ }
57
+ /**
58
+ * Event handler callbacks for the GridStorm Svelte action.
59
+ *
60
+ * @typeParam TData - The type of each row data object.
61
+ */
62
+ interface GridStormEventHandlers<TData = any> {
63
+ /** Fired when the grid engine is ready and the API is available. */
64
+ onGridReady?: (api: GridApi<TData>) => void;
65
+ /** Fired when the selection changes. */
66
+ onSelectionChanged?: (selectedNodes: RowNode<TData>[]) => void;
67
+ /** Fired when the sort model changes. */
68
+ onSortChanged?: (sortModel: any[]) => void;
69
+ /** Fired when the filter model changes. */
70
+ onFilterChanged?: (filterModel: Record<string, any>) => void;
71
+ /** Fired when a cell value is changed via editing. */
72
+ onCellValueChanged?: (params: {
73
+ rowId: string;
74
+ field: string;
75
+ oldValue: any;
76
+ newValue: any;
77
+ }) => void;
78
+ /** Fired when a row is clicked. */
79
+ onRowClicked?: (node: RowNode<TData>) => void;
80
+ /** Fired when pagination state changes. */
81
+ onPaginationChanged?: (params: {
82
+ currentPage: number;
83
+ pageSize: number;
84
+ totalRows: number;
85
+ }) => void;
86
+ /** Fired when a column is resized. */
87
+ onColumnResized?: (params: {
88
+ colId: string;
89
+ width: number;
90
+ }) => void;
91
+ }
92
+
93
+ /**
94
+ * Parameters for the gridstormAction Svelte action.
95
+ *
96
+ * @typeParam TData - The type of each row data object.
97
+ */
98
+ interface GridStormActionParams<TData = any> {
99
+ /** Grid configuration props. */
100
+ props: GridStormProps<TData>;
101
+ /** Event handler callbacks. */
102
+ events?: GridStormEventHandlers<TData>;
103
+ /** Callback fired when the engine and API are ready. */
104
+ onReady?: (api: GridApi<TData>, engine: GridEngine<TData>) => void;
105
+ }
106
+ /**
107
+ * Svelte action that creates and manages a GridStorm instance on a DOM element.
108
+ *
109
+ * This is the primary integration point for using GridStorm in Svelte 5.
110
+ * It handles engine creation, DOM renderer mounting, event bridging,
111
+ * reactive updates (rowData, columns), and cleanup on destroy.
112
+ *
113
+ * @param container - The DOM element to mount the grid into.
114
+ * @param params - Configuration including props, event handlers, and ready callback.
115
+ * @returns A Svelte action interface with `update` and `destroy` methods.
116
+ *
117
+ * @example
118
+ * ```svelte
119
+ * <script lang="ts">
120
+ * import { gridstormAction } from '@gridstorm/svelte';
121
+ * import { sortingPlugin } from '@gridstorm/plugin-sorting';
122
+ *
123
+ * let api = $state(null);
124
+ * const columns = [
125
+ * { field: 'name', headerName: 'Name', sortable: true },
126
+ * { field: 'age', headerName: 'Age', width: 100 },
127
+ * ];
128
+ * const rowData = [
129
+ * { name: 'Alice', age: 30 },
130
+ * { name: 'Bob', age: 25 },
131
+ * ];
132
+ * </script>
133
+ *
134
+ * <div
135
+ * use:gridstormAction={{
136
+ * props: { columns, rowData, plugins: [sortingPlugin()] },
137
+ * onReady: (gridApi) => { api = gridApi; },
138
+ * }}
139
+ * style="height: 400px"
140
+ * />
141
+ * ```
142
+ */
143
+ declare function gridstormAction<TData = any>(container: HTMLElement, params: GridStormActionParams<TData>): {
144
+ /**
145
+ * Called by Svelte when the action parameters change.
146
+ * Performs incremental updates for rowData and columns changes.
147
+ */
148
+ update(newParams: GridStormActionParams<TData>): void;
149
+ /**
150
+ * Called by Svelte when the element is removed from the DOM.
151
+ * Cleans up the engine, renderer, and all event subscriptions.
152
+ */
153
+ destroy: () => void;
154
+ };
155
+
156
+ /**
157
+ * Set the current grid API reference.
158
+ *
159
+ * Call this from the `onReady` callback of `gridstormAction` to make
160
+ * the API available to composable helper functions.
161
+ *
162
+ * @param api - The grid API instance, or `null` to clear it.
163
+ */
164
+ declare function setGridApi(api: GridApi | null): void;
165
+ /**
166
+ * Get the current grid API reference.
167
+ *
168
+ * Returns `null` if the grid has not been initialized yet or has been destroyed.
169
+ *
170
+ * @typeParam TData - The type of each row data object.
171
+ * @returns The current GridApi instance, or `null`.
172
+ */
173
+ declare function getGridApi<TData = any>(): GridApi<TData> | null;
174
+ /**
175
+ * Register a listener that is called whenever the grid API changes.
176
+ *
177
+ * @param listener - Callback invoked with the new API (or `null` on destroy).
178
+ * @returns An unsubscribe function.
179
+ */
180
+ declare function onGridApiChange(listener: (api: GridApi | null) => void): () => void;
181
+
182
+ /**
183
+ * Read a slice of the grid store state using a selector function.
184
+ *
185
+ * Returns `undefined` if the grid has not been initialized yet.
186
+ * This function reads state synchronously (snapshot) and does not
187
+ * set up a reactive subscription. For reactive state in Svelte 5,
188
+ * subscribe to grid events or use `$effect` with periodic polling.
189
+ *
190
+ * @typeParam T - The type of the selected state slice.
191
+ * @param selector - A function that extracts a value from the grid state.
192
+ * @returns The selected state value, or `undefined` if not available.
193
+ *
194
+ * @example
195
+ * ```ts
196
+ * import { getGridState } from '@gridstorm/svelte';
197
+ *
198
+ * const sortModel = getGridState((state) => state.sortModel);
199
+ * ```
200
+ */
201
+ declare function getGridState<T>(selector: (state: GridState) => T): T | undefined;
202
+
203
+ /**
204
+ * Subscribe to a grid event by name.
205
+ *
206
+ * Returns an unsubscribe function. If the grid has not been initialized yet,
207
+ * returns a no-op unsubscribe function.
208
+ *
209
+ * In Svelte 5, call this inside `$effect` or `onMount` and clean up
210
+ * the subscription in the effect's cleanup or `onDestroy`.
211
+ *
212
+ * @typeParam K - The event key from GridEventMap.
213
+ * @param event - The event name to listen for.
214
+ * @param callback - Callback invoked when the event fires.
215
+ * @returns An unsubscribe function.
216
+ *
217
+ * @example
218
+ * ```svelte
219
+ * <script lang="ts">
220
+ * import { onMount, onDestroy } from 'svelte';
221
+ * import { subscribeToGridEvent } from '@gridstorm/svelte';
222
+ *
223
+ * let unsub: () => void;
224
+ * onMount(() => {
225
+ * unsub = subscribeToGridEvent('selection:changed', (e) => {
226
+ * console.log('Selection changed:', e);
227
+ * });
228
+ * });
229
+ * onDestroy(() => unsub?.());
230
+ * </script>
231
+ * ```
232
+ */
233
+ declare function subscribeToGridEvent<K extends string & keyof GridEventMap>(event: K, callback: (payload: GridEventMap[K]) => void): () => void;
234
+
235
+ /**
236
+ * Get the currently selected row nodes.
237
+ *
238
+ * Returns an empty array if the grid has not been initialized yet.
239
+ *
240
+ * @typeParam TData - The type of each row data object.
241
+ * @returns Array of selected RowNode objects.
242
+ */
243
+ declare function getSelectedRows<TData = any>(): RowNode<TData>[];
244
+ /**
245
+ * Select all rows that pass the current filter.
246
+ */
247
+ declare function selectAll(): void;
248
+ /**
249
+ * Deselect all currently selected rows.
250
+ */
251
+ declare function deselectAll(): void;
252
+
253
+ /**
254
+ * Get the current sort model.
255
+ *
256
+ * @returns Array of active sort items, or an empty array if not available.
257
+ */
258
+ declare function getSortModel(): SortModelItem[];
259
+ /**
260
+ * Set the sort model, replacing any existing sort configuration.
261
+ *
262
+ * @param model - Array of sort items specifying column and direction.
263
+ */
264
+ declare function setSortModel(model: SortModelItem[]): void;
265
+
266
+ /**
267
+ * Get the current filter model for all columns.
268
+ *
269
+ * @returns Object keyed by column ID with active filter models,
270
+ * or an empty object if not available.
271
+ */
272
+ declare function getFilterModel(): Record<string, FilterModel>;
273
+ /**
274
+ * Set the filter model, replacing all active filters.
275
+ *
276
+ * @param model - Object keyed by column ID with filter models.
277
+ */
278
+ declare function setFilterModel(model: Record<string, FilterModel>): void;
279
+ /**
280
+ * Apply a quick filter across all columns.
281
+ *
282
+ * @param text - The filter text. Pass an empty string to clear.
283
+ */
284
+ declare function setQuickFilter(text: string): void;
285
+
286
+ /**
287
+ * Pagination state snapshot.
288
+ */
289
+ interface PaginationState {
290
+ /** Current page (zero-based). */
291
+ currentPage: number;
292
+ /** Rows per page. */
293
+ pageSize: number;
294
+ /** Total number of pages. */
295
+ totalPages: number;
296
+ /** Total row count. */
297
+ totalRows: number;
298
+ }
299
+ /**
300
+ * Get the current pagination state.
301
+ *
302
+ * @returns A snapshot of pagination state, or defaults if not available.
303
+ */
304
+ declare function getPaginationState(): PaginationState;
305
+ /**
306
+ * Navigate to a specific page (zero-based index).
307
+ *
308
+ * @param page - The zero-based page number to navigate to.
309
+ */
310
+ declare function goToPage(page: number): void;
311
+
312
+ export { type GridStormActionParams, type GridStormContext, type GridStormEventHandlers, type GridStormProps, type PaginationState, deselectAll, getFilterModel, getGridApi, getGridState, getPaginationState, getSelectedRows, getSortModel, goToPage, gridstormAction, onGridApiChange, selectAll, setFilterModel, setGridApi, setQuickFilter, setSortModel, subscribeToGridEvent };
package/dist/index.js ADDED
@@ -0,0 +1,230 @@
1
+ import { createGrid } from '@gridstorm/core';
2
+ import { DomRenderer } from '@gridstorm/dom-renderer';
3
+
4
+ // src/gridstorm-action.ts
5
+ function gridstormAction(container, params) {
6
+ let engine = null;
7
+ let renderer = null;
8
+ const unsubs = [];
9
+ function init() {
10
+ const { props, events, onReady } = params;
11
+ const config = {
12
+ columns: props.columns,
13
+ rowData: props.rowData,
14
+ plugins: props.plugins || [],
15
+ getRowId: props.getRowId ? (p) => props.getRowId(p.data) : void 0,
16
+ rowHeight: props.rowHeight,
17
+ headerHeight: props.headerHeight,
18
+ theme: props.theme
19
+ };
20
+ engine = createGrid(config);
21
+ renderer = new DomRenderer({
22
+ container,
23
+ engine,
24
+ enableCellEditing: props.enableCellEditing,
25
+ enableGrouping: props.enableGrouping,
26
+ floatingFilter: props.floatingFilter,
27
+ enablePagination: props.enablePagination,
28
+ pageSizeOptions: props.paginationPageSize ? [props.paginationPageSize] : void 0
29
+ });
30
+ renderer.mount();
31
+ if (props.density) {
32
+ container.setAttribute("data-density", props.density);
33
+ }
34
+ if (events?.onSelectionChanged) {
35
+ unsubs.push(
36
+ engine.eventBus.on("selection:changed", () => {
37
+ events.onSelectionChanged(engine.api.getSelectedNodes());
38
+ })
39
+ );
40
+ }
41
+ if (events?.onSortChanged) {
42
+ unsubs.push(
43
+ engine.eventBus.on("column:sort:changed", (e) => {
44
+ events.onSortChanged(e.sortModel || []);
45
+ })
46
+ );
47
+ }
48
+ if (events?.onFilterChanged) {
49
+ unsubs.push(
50
+ engine.eventBus.on("filter:changed", (e) => {
51
+ events.onFilterChanged(e.filterModel || {});
52
+ })
53
+ );
54
+ }
55
+ if (events?.onCellValueChanged) {
56
+ unsubs.push(
57
+ engine.eventBus.on("cell:valueChanged", (e) => {
58
+ events.onCellValueChanged(e);
59
+ })
60
+ );
61
+ }
62
+ if (events?.onRowClicked) {
63
+ unsubs.push(
64
+ engine.eventBus.on("row:clicked", (e) => {
65
+ events.onRowClicked(e.node);
66
+ })
67
+ );
68
+ }
69
+ if (events?.onPaginationChanged) {
70
+ unsubs.push(
71
+ engine.eventBus.on("pagination:changed", (e) => {
72
+ events.onPaginationChanged(e);
73
+ })
74
+ );
75
+ }
76
+ if (events?.onColumnResized) {
77
+ unsubs.push(
78
+ engine.eventBus.on("column:resized", (e) => {
79
+ events.onColumnResized(e);
80
+ })
81
+ );
82
+ }
83
+ requestAnimationFrame(() => {
84
+ if (engine) {
85
+ engine.eventBus.emit("grid:ready", { api: engine.api });
86
+ events?.onGridReady?.(engine.api);
87
+ onReady?.(engine.api, engine);
88
+ }
89
+ });
90
+ }
91
+ function destroy() {
92
+ unsubs.forEach((fn) => fn());
93
+ unsubs.length = 0;
94
+ renderer?.destroy();
95
+ engine?.destroy();
96
+ renderer = null;
97
+ engine = null;
98
+ }
99
+ init();
100
+ return {
101
+ /**
102
+ * Called by Svelte when the action parameters change.
103
+ * Performs incremental updates for rowData and columns changes.
104
+ */
105
+ update(newParams) {
106
+ if (engine && newParams.props.rowData !== params.props.rowData) {
107
+ engine.api.setRowData(newParams.props.rowData);
108
+ }
109
+ if (engine && newParams.props.columns !== params.props.columns) {
110
+ engine.api.setColumnDefs(newParams.props.columns);
111
+ }
112
+ params = newParams;
113
+ },
114
+ /**
115
+ * Called by Svelte when the element is removed from the DOM.
116
+ * Cleans up the engine, renderer, and all event subscriptions.
117
+ */
118
+ destroy
119
+ };
120
+ }
121
+
122
+ // src/composables/useGridApi.ts
123
+ var currentApi = null;
124
+ var listeners = /* @__PURE__ */ new Set();
125
+ function setGridApi(api) {
126
+ currentApi = api;
127
+ listeners.forEach((fn) => fn(api));
128
+ }
129
+ function getGridApi() {
130
+ return currentApi;
131
+ }
132
+ function onGridApiChange(listener) {
133
+ listeners.add(listener);
134
+ return () => listeners.delete(listener);
135
+ }
136
+
137
+ // src/composables/useGridState.ts
138
+ function getGridState(selector) {
139
+ const api = getGridApi();
140
+ if (!api) return void 0;
141
+ const state = api.getState();
142
+ if (!state) return void 0;
143
+ return selector(state);
144
+ }
145
+
146
+ // src/composables/useGridEvent.ts
147
+ function subscribeToGridEvent(event, callback) {
148
+ const api = getGridApi();
149
+ if (!api) return () => {
150
+ };
151
+ api.addEventListener(event, callback);
152
+ return () => {
153
+ api.removeEventListener(event, callback);
154
+ };
155
+ }
156
+
157
+ // src/composables/useGridSelection.ts
158
+ function getSelectedRows() {
159
+ const api = getGridApi();
160
+ if (!api) return [];
161
+ return api.getSelectedNodes();
162
+ }
163
+ function selectAll() {
164
+ const api = getGridApi();
165
+ if (!api) return;
166
+ api.selectAll();
167
+ }
168
+ function deselectAll() {
169
+ const api = getGridApi();
170
+ if (!api) return;
171
+ api.deselectAll();
172
+ }
173
+
174
+ // src/composables/useGridSort.ts
175
+ function getSortModel() {
176
+ const api = getGridApi();
177
+ if (!api) return [];
178
+ return api.getSortModel();
179
+ }
180
+ function setSortModel(model) {
181
+ const api = getGridApi();
182
+ if (!api) return;
183
+ api.setSortModel(model);
184
+ }
185
+
186
+ // src/composables/useGridFilter.ts
187
+ function getFilterModel() {
188
+ const api = getGridApi();
189
+ if (!api) return {};
190
+ return api.getFilterModel();
191
+ }
192
+ function setFilterModel(model) {
193
+ const api = getGridApi();
194
+ if (!api) return;
195
+ api.setFilterModel(model);
196
+ }
197
+ function setQuickFilter(text) {
198
+ const api = getGridApi();
199
+ if (!api) return;
200
+ api.setQuickFilter(text);
201
+ }
202
+
203
+ // src/composables/useGridPagination.ts
204
+ function getPaginationState() {
205
+ const api = getGridApi();
206
+ if (!api) {
207
+ return { currentPage: 0, pageSize: 10, totalPages: 0, totalRows: 0 };
208
+ }
209
+ const state = api.getState();
210
+ const pagination = state.pagination;
211
+ const totalPages = Math.max(
212
+ 1,
213
+ Math.ceil(pagination.totalRows / pagination.pageSize)
214
+ );
215
+ return {
216
+ currentPage: pagination.currentPage,
217
+ pageSize: pagination.pageSize,
218
+ totalPages,
219
+ totalRows: pagination.totalRows
220
+ };
221
+ }
222
+ function goToPage(page) {
223
+ const api = getGridApi();
224
+ if (!api) return;
225
+ api.paginationGoToPage(page);
226
+ }
227
+
228
+ export { deselectAll, getFilterModel, getGridApi, getGridState, getPaginationState, getSelectedRows, getSortModel, goToPage, gridstormAction, onGridApiChange, selectAll, setFilterModel, setGridApi, setQuickFilter, setSortModel, subscribeToGridEvent };
229
+ //# sourceMappingURL=index.js.map
230
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/gridstorm-action.ts","../src/composables/useGridApi.ts","../src/composables/useGridState.ts","../src/composables/useGridEvent.ts","../src/composables/useGridSelection.ts","../src/composables/useGridSort.ts","../src/composables/useGridFilter.ts","../src/composables/useGridPagination.ts"],"names":[],"mappings":";;;;AAuEO,SAAS,eAAA,CACd,WACA,MAAA,EACA;AACA,EAAA,IAAI,MAAA,GAAmC,IAAA;AACvC,EAAA,IAAI,QAAA,GAA+B,IAAA;AACnC,EAAA,MAAM,SAA4B,EAAC;AAEnC,EAAA,SAAS,IAAA,GAAO;AACd,IAAA,MAAM,EAAE,KAAA,EAAO,MAAA,EAAQ,OAAA,EAAQ,GAAI,MAAA;AAGnC,IAAA,MAAM,MAAA,GAA4B;AAAA,MAChC,SAAS,KAAA,CAAM,OAAA;AAAA,MACf,SAAS,KAAA,CAAM,OAAA;AAAA,MACf,OAAA,EAAS,KAAA,CAAM,OAAA,IAAW,EAAC;AAAA,MAC3B,QAAA,EAAU,MAAM,QAAA,GACZ,CAAC,MAAM,KAAA,CAAM,QAAA,CAAU,CAAA,CAAE,IAAI,CAAA,GAC7B,MAAA;AAAA,MACJ,WAAW,KAAA,CAAM,SAAA;AAAA,MACjB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,OAAO;AAAA,IACL,aAAa,UAAA,CAAW,WAAA;AAAA,IACxB,UAAU,UAAA,CAAW,QAAA;AAAA,IACrB,UAAA;AAAA,IACA,WAAW,UAAA,CAAW;AAAA,GACxB;AACF;AAOO,SAAS,SAAS,IAAA,EAAoB;AAC3C,EAAA,MAAM,MAAM,UAAA,EAAW;AACvB,EAAA,IAAI,CAAC,GAAA,EAAK;AACV,EAAA,GAAA,CAAI,mBAAmB,IAAI,CAAA;AAC7B","file":"index.js","sourcesContent":["// ─── GridStorm Svelte Action ───\n// The core of the Svelte 5 adapter. Implements a Svelte \"action\" — a function\n// that takes a DOM element and manages the GridStorm lifecycle (create, update, destroy).\n//\n// Usage in a Svelte 5 component:\n//\n// <script lang=\"ts\">\n// import { gridstormAction } from '@gridstorm/svelte';\n//\n// const columns = [{ field: 'name' }, { field: 'age' }];\n// const rowData = [{ name: 'Alice', age: 30 }];\n// </script>\n//\n// <div use:gridstormAction={{ props: { columns, rowData } }} style=\"height: 400px\" />\n\nimport { createGrid } from '@gridstorm/core';\nimport type { GridEngine, GridApi, GridConfig } from '@gridstorm/core';\nimport { DomRenderer } from '@gridstorm/dom-renderer';\nimport type { GridStormProps, GridStormEventHandlers } from './types';\n\n/**\n * Parameters for the gridstormAction Svelte action.\n *\n * @typeParam TData - The type of each row data object.\n */\nexport interface GridStormActionParams<TData = any> {\n /** Grid configuration props. */\n props: GridStormProps<TData>;\n /** Event handler callbacks. */\n events?: GridStormEventHandlers<TData>;\n /** Callback fired when the engine and API are ready. */\n onReady?: (api: GridApi<TData>, engine: GridEngine<TData>) => void;\n}\n\n/**\n * Svelte action that creates and manages a GridStorm instance on a DOM element.\n *\n * This is the primary integration point for using GridStorm in Svelte 5.\n * It handles engine creation, DOM renderer mounting, event bridging,\n * reactive updates (rowData, columns), and cleanup on destroy.\n *\n * @param container - The DOM element to mount the grid into.\n * @param params - Configuration including props, event handlers, and ready callback.\n * @returns A Svelte action interface with `update` and `destroy` methods.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { gridstormAction } from '@gridstorm/svelte';\n * import { sortingPlugin } from '@gridstorm/plugin-sorting';\n *\n * let api = $state(null);\n * const columns = [\n * { field: 'name', headerName: 'Name', sortable: true },\n * { field: 'age', headerName: 'Age', width: 100 },\n * ];\n * const rowData = [\n * { name: 'Alice', age: 30 },\n * { name: 'Bob', age: 25 },\n * ];\n * </script>\n *\n * <div\n * use:gridstormAction={{\n * props: { columns, rowData, plugins: [sortingPlugin()] },\n * onReady: (gridApi) => { api = gridApi; },\n * }}\n * style=\"height: 400px\"\n * />\n * ```\n */\nexport function gridstormAction<TData = any>(\n container: HTMLElement,\n params: GridStormActionParams<TData>,\n) {\n let engine: GridEngine<TData> | null = null;\n let renderer: DomRenderer | null = null;\n const unsubs: Array<() => void> = [];\n\n function init() {\n const { props, events, onReady } = params;\n\n // Build grid config from props\n const config: GridConfig<TData> = {\n columns: props.columns,\n rowData: props.rowData,\n plugins: props.plugins || [],\n getRowId: props.getRowId\n ? (p) => props.getRowId!(p.data)\n : undefined,\n rowHeight: props.rowHeight,\n headerHeight: props.headerHeight,\n theme: props.theme,\n };\n\n // Create the headless grid engine\n engine = createGrid(config);\n\n // Create and mount the DOM renderer\n renderer = new DomRenderer({\n container,\n engine,\n enableCellEditing: props.enableCellEditing,\n enableGrouping: props.enableGrouping,\n floatingFilter: props.floatingFilter,\n enablePagination: props.enablePagination,\n pageSizeOptions: props.paginationPageSize\n ? [props.paginationPageSize]\n : undefined,\n });\n renderer.mount();\n\n // Apply density as a data attribute on the container\n if (props.density) {\n container.setAttribute('data-density', props.density);\n }\n\n // ── Event bridge: core events -> Svelte callbacks ──\n\n if (events?.onSelectionChanged) {\n unsubs.push(\n engine.eventBus.on('selection:changed', () => {\n events.onSelectionChanged!(engine!.api.getSelectedNodes());\n }),\n );\n }\n\n if (events?.onSortChanged) {\n unsubs.push(\n engine.eventBus.on('column:sort:changed', (e: any) => {\n events.onSortChanged!(e.sortModel || []);\n }),\n );\n }\n\n if (events?.onFilterChanged) {\n unsubs.push(\n engine.eventBus.on('filter:changed', (e: any) => {\n events.onFilterChanged!(e.filterModel || {});\n }),\n );\n }\n\n if (events?.onCellValueChanged) {\n unsubs.push(\n engine.eventBus.on('cell:valueChanged', (e: any) => {\n events.onCellValueChanged!(e);\n }),\n );\n }\n\n if (events?.onRowClicked) {\n unsubs.push(\n engine.eventBus.on('row:clicked', (e: any) => {\n events.onRowClicked!(e.node);\n }),\n );\n }\n\n if (events?.onPaginationChanged) {\n unsubs.push(\n engine.eventBus.on('pagination:changed', (e: any) => {\n events.onPaginationChanged!(e);\n }),\n );\n }\n\n if (events?.onColumnResized) {\n unsubs.push(\n engine.eventBus.on('column:resized', (e: any) => {\n events.onColumnResized!(e);\n }),\n );\n }\n\n // Fire grid:ready after the renderer has mounted and DOM is populated.\n // Plugins like column-resize and context-menu use rAF on grid:ready to\n // inject DOM elements, so we re-emit after the renderer is in the DOM.\n requestAnimationFrame(() => {\n if (engine) {\n engine.eventBus.emit('grid:ready', { api: engine.api });\n events?.onGridReady?.(engine.api);\n onReady?.(engine.api, engine);\n }\n });\n }\n\n function destroy() {\n unsubs.forEach((fn) => fn());\n unsubs.length = 0;\n renderer?.destroy();\n engine?.destroy();\n renderer = null;\n engine = null;\n }\n\n // Initialize the grid\n init();\n\n // Return the Svelte action interface\n return {\n /**\n * Called by Svelte when the action parameters change.\n * Performs incremental updates for rowData and columns changes.\n */\n update(newParams: GridStormActionParams<TData>) {\n if (engine && newParams.props.rowData !== params.props.rowData) {\n engine.api.setRowData(newParams.props.rowData);\n }\n if (engine && newParams.props.columns !== params.props.columns) {\n engine.api.setColumnDefs(newParams.props.columns);\n }\n params = newParams;\n },\n\n /**\n * Called by Svelte when the element is removed from the DOM.\n * Cleans up the engine, renderer, and all event subscriptions.\n */\n destroy,\n };\n}\n","// ─── Grid API Store ───\n// Lightweight store for the current GridApi reference.\n// In Svelte 5, there is no provide/inject like Vue or React context.\n// Instead, this module-level store allows any component to access the\n// grid API after initialization. Call setGridApi from the onReady callback\n// and getGridApi from anywhere in your component tree.\n\nimport type { GridApi } from '@gridstorm/core';\n\n/** Module-level reference to the current grid API. */\nlet currentApi: GridApi | null = null;\n\n/** Set of listeners notified when the API changes. */\nconst listeners = new Set<(api: GridApi | null) => void>();\n\n/**\n * Set the current grid API reference.\n *\n * Call this from the `onReady` callback of `gridstormAction` to make\n * the API available to composable helper functions.\n *\n * @param api - The grid API instance, or `null` to clear it.\n */\nexport function setGridApi(api: GridApi | null): void {\n currentApi = api;\n listeners.forEach((fn) => fn(api));\n}\n\n/**\n * Get the current grid API reference.\n *\n * Returns `null` if the grid has not been initialized yet or has been destroyed.\n *\n * @typeParam TData - The type of each row data object.\n * @returns The current GridApi instance, or `null`.\n */\nexport function getGridApi<TData = any>(): GridApi<TData> | null {\n return currentApi as GridApi<TData> | null;\n}\n\n/**\n * Register a listener that is called whenever the grid API changes.\n *\n * @param listener - Callback invoked with the new API (or `null` on destroy).\n * @returns An unsubscribe function.\n */\nexport function onGridApiChange(\n listener: (api: GridApi | null) => void,\n): () => void {\n listeners.add(listener);\n return () => listeners.delete(listener);\n}\n","// ─── Grid State Accessor ───\n// Provides direct access to the grid store state via a selector function.\n\nimport type { GridState } from '@gridstorm/core';\nimport { getGridApi } from './useGridApi';\n\n/**\n * Read a slice of the grid store state using a selector function.\n *\n * Returns `undefined` if the grid has not been initialized yet.\n * This function reads state synchronously (snapshot) and does not\n * set up a reactive subscription. For reactive state in Svelte 5,\n * subscribe to grid events or use `$effect` with periodic polling.\n *\n * @typeParam T - The type of the selected state slice.\n * @param selector - A function that extracts a value from the grid state.\n * @returns The selected state value, or `undefined` if not available.\n *\n * @example\n * ```ts\n * import { getGridState } from '@gridstorm/svelte';\n *\n * const sortModel = getGridState((state) => state.sortModel);\n * ```\n */\nexport function getGridState<T>(selector: (state: GridState) => T): T | undefined {\n const api = getGridApi();\n if (!api) return undefined;\n const state = api.getState();\n if (!state) return undefined;\n return selector(state);\n}\n","// ─── Grid Event Subscription ───\n// Provides a helper to subscribe to grid events from Svelte components.\n\nimport type { GridEventMap } from '@gridstorm/core';\nimport { getGridApi } from './useGridApi';\n\n/**\n * Subscribe to a grid event by name.\n *\n * Returns an unsubscribe function. If the grid has not been initialized yet,\n * returns a no-op unsubscribe function.\n *\n * In Svelte 5, call this inside `$effect` or `onMount` and clean up\n * the subscription in the effect's cleanup or `onDestroy`.\n *\n * @typeParam K - The event key from GridEventMap.\n * @param event - The event name to listen for.\n * @param callback - Callback invoked when the event fires.\n * @returns An unsubscribe function.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { onMount, onDestroy } from 'svelte';\n * import { subscribeToGridEvent } from '@gridstorm/svelte';\n *\n * let unsub: () => void;\n * onMount(() => {\n * unsub = subscribeToGridEvent('selection:changed', (e) => {\n * console.log('Selection changed:', e);\n * });\n * });\n * onDestroy(() => unsub?.());\n * </script>\n * ```\n */\nexport function subscribeToGridEvent<K extends string & keyof GridEventMap>(\n event: K,\n callback: (payload: GridEventMap[K]) => void,\n): () => void {\n const api = getGridApi();\n if (!api) return () => {};\n\n // Access the engine's event bus through the API's addEventListener\n api.addEventListener(event as any, callback as any);\n\n return () => {\n api.removeEventListener(event as any, callback as any);\n };\n}\n","// ─── Grid Selection Helpers ───\n// Convenience functions for managing row selection in Svelte components.\n\nimport type { RowNode } from '@gridstorm/core';\nimport { getGridApi } from './useGridApi';\n\n/**\n * Get the currently selected row nodes.\n *\n * Returns an empty array if the grid has not been initialized yet.\n *\n * @typeParam TData - The type of each row data object.\n * @returns Array of selected RowNode objects.\n */\nexport function getSelectedRows<TData = any>(): RowNode<TData>[] {\n const api = getGridApi<TData>();\n if (!api) return [];\n return api.getSelectedNodes();\n}\n\n/**\n * Select all rows that pass the current filter.\n */\nexport function selectAll(): void {\n const api = getGridApi();\n if (!api) return;\n api.selectAll();\n}\n\n/**\n * Deselect all currently selected rows.\n */\nexport function deselectAll(): void {\n const api = getGridApi();\n if (!api) return;\n api.deselectAll();\n}\n","// ─── Grid Sort Helpers ───\n// Convenience functions for managing sort state in Svelte components.\n\nimport type { SortModelItem } from '@gridstorm/core';\nimport { getGridApi } from './useGridApi';\n\n/**\n * Get the current sort model.\n *\n * @returns Array of active sort items, or an empty array if not available.\n */\nexport function getSortModel(): SortModelItem[] {\n const api = getGridApi();\n if (!api) return [];\n return api.getSortModel();\n}\n\n/**\n * Set the sort model, replacing any existing sort configuration.\n *\n * @param model - Array of sort items specifying column and direction.\n */\nexport function setSortModel(model: SortModelItem[]): void {\n const api = getGridApi();\n if (!api) return;\n api.setSortModel(model);\n}\n","// ─── Grid Filter Helpers ───\n// Convenience functions for managing filter state in Svelte components.\n\nimport type { FilterModel } from '@gridstorm/core';\nimport { getGridApi } from './useGridApi';\n\n/**\n * Get the current filter model for all columns.\n *\n * @returns Object keyed by column ID with active filter models,\n * or an empty object if not available.\n */\nexport function getFilterModel(): Record<string, FilterModel> {\n const api = getGridApi();\n if (!api) return {};\n return api.getFilterModel();\n}\n\n/**\n * Set the filter model, replacing all active filters.\n *\n * @param model - Object keyed by column ID with filter models.\n */\nexport function setFilterModel(model: Record<string, FilterModel>): void {\n const api = getGridApi();\n if (!api) return;\n api.setFilterModel(model);\n}\n\n/**\n * Apply a quick filter across all columns.\n *\n * @param text - The filter text. Pass an empty string to clear.\n */\nexport function setQuickFilter(text: string): void {\n const api = getGridApi();\n if (!api) return;\n api.setQuickFilter(text);\n}\n","// ─── Grid Pagination Helpers ───\n// Convenience functions for managing pagination in Svelte components.\n\nimport { getGridApi } from './useGridApi';\n\n/**\n * Pagination state snapshot.\n */\nexport interface PaginationState {\n /** Current page (zero-based). */\n currentPage: number;\n /** Rows per page. */\n pageSize: number;\n /** Total number of pages. */\n totalPages: number;\n /** Total row count. */\n totalRows: number;\n}\n\n/**\n * Get the current pagination state.\n *\n * @returns A snapshot of pagination state, or defaults if not available.\n */\nexport function getPaginationState(): PaginationState {\n const api = getGridApi();\n if (!api) {\n return { currentPage: 0, pageSize: 10, totalPages: 0, totalRows: 0 };\n }\n\n const state = api.getState();\n const pagination = state.pagination;\n const totalPages = Math.max(\n 1,\n Math.ceil(pagination.totalRows / pagination.pageSize),\n );\n\n return {\n currentPage: pagination.currentPage,\n pageSize: pagination.pageSize,\n totalPages,\n totalRows: pagination.totalRows,\n };\n}\n\n/**\n * Navigate to a specific page (zero-based index).\n *\n * @param page - The zero-based page number to navigate to.\n */\nexport function goToPage(page: number): void {\n const api = getGridApi();\n if (!api) return;\n api.paginationGoToPage(page);\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@gridstorm/svelte",
3
+ "version": "0.1.2",
4
+ "description": "GridStorm Svelte 5 adapter — reactive data grid component for Svelte",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "source": "./src/index.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "require": {
17
+ "types": "./dist/index.d.cts",
18
+ "default": "./dist/index.cjs"
19
+ }
20
+ }
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "scripts": {
26
+ "build": "tsup",
27
+ "dev": "tsup --watch",
28
+ "typecheck": "tsc --noEmit",
29
+ "clean": "rm -rf dist"
30
+ },
31
+ "dependencies": {
32
+ "@gridstorm/core": "workspace:*",
33
+ "@gridstorm/dom-renderer": "workspace:*"
34
+ },
35
+ "peerDependencies": {
36
+ "svelte": "^5.0.0"
37
+ },
38
+ "devDependencies": {
39
+ "tsup": "^8.2.0",
40
+ "typescript": "^5.5.0"
41
+ },
42
+ "sideEffects": false,
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "license": "MIT",
47
+ "keywords": [
48
+ "datagrid",
49
+ "svelte",
50
+ "svelte5",
51
+ "svelte-grid",
52
+ "svelte-table",
53
+ "gridstorm",
54
+ "action"
55
+ ],
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "https://github.com/007krcs/grid-data.git",
59
+ "directory": "packages/svelte-adapter"
60
+ },
61
+ "bugs": {
62
+ "url": "https://github.com/007krcs/grid-data/issues"
63
+ },
64
+ "homepage": "https://grid-data-analytics-explorer.vercel.app/",
65
+ "author": {
66
+ "name": "GridStorm",
67
+ "url": "https://grid-data-analytics-explorer.vercel.app/"
68
+ },
69
+ "funding": {
70
+ "type": "github",
71
+ "url": "https://github.com/sponsors/gridstorm"
72
+ },
73
+ "engines": {
74
+ "node": ">=18.0.0"
75
+ }
76
+ }