@svgrid/grid 1.1.0 → 1.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.
Files changed (148) hide show
  1. package/dist/FlexRender.svelte +96 -96
  2. package/dist/GridMenus.svelte +205 -127
  3. package/dist/SvGrid.controller.svelte.d.ts +44 -1
  4. package/dist/SvGrid.controller.svelte.js +240 -44
  5. package/dist/SvGrid.css +325 -22
  6. package/dist/SvGrid.helpers.test.d.ts +1 -0
  7. package/dist/SvGrid.helpers.test.js +298 -0
  8. package/dist/SvGrid.svelte +729 -203
  9. package/dist/SvGrid.types.d.ts +91 -4
  10. package/dist/aligned-grids.d.ts +6 -0
  11. package/dist/aligned-grids.js +84 -0
  12. package/dist/aligned-grids.test.d.ts +1 -0
  13. package/dist/aligned-grids.test.js +75 -0
  14. package/dist/build-api.coverage.test.d.ts +20 -0
  15. package/dist/build-api.coverage.test.js +505 -0
  16. package/dist/build-api.js +61 -31
  17. package/dist/cell-render.test.d.ts +1 -0
  18. package/dist/cell-render.test.js +338 -0
  19. package/dist/cell-values.d.ts +1 -1
  20. package/dist/cell-values.js +7 -7
  21. package/dist/chart-export.test.d.ts +1 -0
  22. package/dist/chart-export.test.js +302 -0
  23. package/dist/chart.coverage.test.d.ts +1 -0
  24. package/dist/chart.coverage.test.js +748 -0
  25. package/dist/clipboard.js +88 -24
  26. package/dist/clipboard.test.d.ts +1 -0
  27. package/dist/clipboard.test.js +700 -0
  28. package/dist/collaboration.coverage.test.d.ts +1 -0
  29. package/dist/collaboration.coverage.test.js +200 -0
  30. package/dist/column-groups.d.ts +19 -0
  31. package/dist/column-groups.js +62 -0
  32. package/dist/column-groups.test.d.ts +1 -0
  33. package/dist/column-groups.test.js +56 -0
  34. package/dist/column-types.d.ts +10 -0
  35. package/dist/column-types.js +63 -0
  36. package/dist/column-types.test.d.ts +1 -0
  37. package/dist/column-types.test.js +62 -0
  38. package/dist/columns.test.d.ts +1 -0
  39. package/dist/columns.test.js +625 -0
  40. package/dist/core.d.ts +86 -1
  41. package/dist/core.js +2 -2
  42. package/dist/editing.d.ts +7 -0
  43. package/dist/editing.js +191 -5
  44. package/dist/editing.test.d.ts +1 -0
  45. package/dist/editing.test.js +732 -0
  46. package/dist/editors/cell-editors.coverage.test.d.ts +1 -0
  47. package/dist/editors/cell-editors.coverage.test.js +139 -0
  48. package/dist/facet-buckets.test.d.ts +1 -0
  49. package/dist/facet-buckets.test.js +296 -0
  50. package/dist/filter-operators.test.d.ts +1 -0
  51. package/dist/filter-operators.test.js +135 -0
  52. package/dist/hyperformula-adapter.test.d.ts +1 -0
  53. package/dist/hyperformula-adapter.test.js +205 -0
  54. package/dist/index.d.ts +5 -2
  55. package/dist/index.js +4 -1
  56. package/dist/keyboard-handlers.coverage.test.d.ts +1 -0
  57. package/dist/keyboard-handlers.coverage.test.js +495 -0
  58. package/dist/keyboard-handlers.js +7 -2
  59. package/dist/menus.js +1 -0
  60. package/dist/menus.test.d.ts +1 -0
  61. package/dist/menus.test.js +560 -0
  62. package/dist/named-views.coverage.test.d.ts +1 -0
  63. package/dist/named-views.coverage.test.js +180 -0
  64. package/dist/row-drag.d.ts +49 -0
  65. package/dist/row-drag.js +221 -0
  66. package/dist/row-drag.test.d.ts +1 -0
  67. package/dist/row-drag.test.js +142 -0
  68. package/dist/row-resize.test.d.ts +1 -0
  69. package/dist/row-resize.test.js +329 -0
  70. package/dist/scroll-sync.js +3 -0
  71. package/dist/scroll-sync.test.d.ts +1 -0
  72. package/dist/scroll-sync.test.js +290 -0
  73. package/dist/selection.d.ts +7 -1
  74. package/dist/selection.js +76 -36
  75. package/dist/selection.multi-range.test.d.ts +1 -0
  76. package/dist/selection.multi-range.test.js +55 -0
  77. package/dist/selection.test.d.ts +1 -0
  78. package/dist/selection.test.js +647 -0
  79. package/dist/server-data-source.coverage.test.d.ts +1 -0
  80. package/dist/server-data-source.coverage.test.js +154 -0
  81. package/dist/spreadsheet.d.ts +30 -0
  82. package/dist/spreadsheet.js +48 -0
  83. package/dist/spreadsheet.test.d.ts +1 -0
  84. package/dist/spreadsheet.test.js +446 -0
  85. package/dist/summaries.js +4 -4
  86. package/dist/sv-grid-scrollbar.js +13 -1
  87. package/dist/svgrid-wrapper.types.d.ts +19 -0
  88. package/dist/svgrid.behavior.test.js +20 -0
  89. package/dist/svgrid.interaction.test.js +31 -0
  90. package/dist/svgrid.new-features.wrapper.test.js +34 -2
  91. package/dist/test-setup.js +9 -3
  92. package/dist/virtualization/scroll-scaling.d.ts +17 -0
  93. package/dist/virtualization/scroll-scaling.js +35 -0
  94. package/dist/virtualization/scroll-scaling.test.js +42 -1
  95. package/package.json +2 -1
  96. package/src/FlexRender.svelte +96 -96
  97. package/src/GridMenus.svelte +205 -127
  98. package/src/SvGrid.controller.svelte.ts +204 -36
  99. package/src/SvGrid.css +277 -12
  100. package/src/SvGrid.svelte +727 -205
  101. package/src/SvGrid.types.ts +85 -4
  102. package/src/a11y.contract.test.ts +49 -49
  103. package/src/a11y.test.ts +59 -59
  104. package/src/a11y.ts +59 -59
  105. package/src/aligned-grids.test.ts +80 -0
  106. package/src/aligned-grids.ts +87 -0
  107. package/src/build-api.ts +43 -23
  108. package/src/cell-formatting.ts +169 -169
  109. package/src/cell-values.ts +4 -4
  110. package/src/clipboard.test.ts +49 -0
  111. package/src/clipboard.ts +51 -23
  112. package/src/column-groups.test.ts +59 -0
  113. package/src/column-groups.ts +80 -0
  114. package/src/column-types.test.ts +68 -0
  115. package/src/column-types.ts +82 -0
  116. package/src/core.performance.test.ts +30 -30
  117. package/src/core.ts +1077 -999
  118. package/src/createGrid.svelte.ts +42 -42
  119. package/src/createGrid.test.ts +10 -10
  120. package/src/createGridState.svelte.ts +17 -17
  121. package/src/editing.ts +161 -5
  122. package/src/flex-render.ts +3 -3
  123. package/src/index.ts +208 -196
  124. package/src/keyboard.test.ts +59 -59
  125. package/src/keyboard.ts +97 -97
  126. package/src/menus.ts +1 -0
  127. package/src/merge-objects.ts +48 -48
  128. package/src/render-component.ts +28 -28
  129. package/src/row-drag.test.ts +168 -0
  130. package/src/row-drag.ts +255 -0
  131. package/src/scroll-sync.ts +2 -0
  132. package/src/selection.multi-range.test.ts +61 -0
  133. package/src/selection.ts +71 -37
  134. package/src/spreadsheet.test.ts +46 -2
  135. package/src/spreadsheet.ts +58 -0
  136. package/src/static-functions.ts +11 -11
  137. package/src/subscribe.ts +38 -38
  138. package/src/summaries.ts +4 -4
  139. package/src/svgrid-wrapper.types.ts +412 -393
  140. package/src/svgrid.features.test.ts +157 -157
  141. package/src/svgrid.new-features.wrapper.test.ts +2 -2
  142. package/src/svgrid.wrapper.test.ts +40 -40
  143. package/src/virtualization/column-virtualizer.test.ts +27 -27
  144. package/src/virtualization/column-virtualizer.ts +30 -30
  145. package/src/virtualization/svelte-virtualizer.svelte.ts +26 -26
  146. package/src/virtualization/types.ts +30 -30
  147. package/src/virtualization/virtualizer.test.ts +47 -47
  148. package/src/virtualization/virtualizer.ts +296 -296
@@ -1,393 +1,412 @@
1
- import type { ColumnDef, RowData, SvGridOptions, TableFeatures } from './core'
2
-
3
- export type SvGridFilterOperator =
4
- | 'contains'
5
- | 'equals'
6
- | 'startsWith'
7
- | 'greaterThan'
8
- | 'lessThan'
9
- | 'between'
10
- | 'isBlank'
11
-
12
- /**
13
- * A serializable snapshot of everything that makes up the current "view":
14
- * sort, grouping, pagination, column layout (width / pinning / order /
15
- * visibility), and all filter surfaces. Round-trippable through
16
- * `api.getState()` / `api.setState()` - persist it to a URL, localStorage, or
17
- * a server to implement "save view" / "named views".
18
- */
19
- export type SvGridViewState = {
20
- sorting: Array<{ id: string; desc: boolean }>
21
- grouping: string[]
22
- pagination: { pageIndex: number; pageSize: number }
23
- columnWidths: Record<string, number>
24
- columnPinning: { left: string[]; right: string[] }
25
- columnOrder: string[]
26
- /** Ids of columns currently hidden via setColumnVisible. */
27
- hiddenColumns: string[]
28
- globalFilter: string
29
- columnFilters: Record<
30
- string,
31
- { operator: SvGridFilterOperator; value: string; valueTo?: string }
32
- >
33
- /** Facet (Excel-style value checklist) selections, keyed by column id. */
34
- facetFilters: Record<string, string[]>
35
- }
36
-
37
- /**
38
- * A batch of row mutations for `api.applyTransaction`. `update` / `remove`
39
- * (by id) match on `getRowId`; `remove` also accepts row object references.
40
- */
41
- export type SvGridTransaction<TData> = {
42
- add?: ReadonlyArray<TData>
43
- update?: ReadonlyArray<TData>
44
- remove?: ReadonlyArray<TData | string>
45
- }
46
-
47
- export type SvGridTransactionResult = {
48
- added: number
49
- updated: number
50
- removed: number
51
- }
52
-
53
- /**
54
- * Imperative API exposed via the `<SvGrid onApiReady>` callback. Use it for
55
- * data, column, filter, sort, group, and visibility operations from outside
56
- * the component.
57
- */
58
- export type SvGridApi<
59
- TFeatures extends TableFeatures,
60
- TData extends RowData,
61
- > = {
62
- // ----- Cells -----
63
- /** Read a cell value from the underlying data at `rowIndex`. */
64
- getCellValue(rowIndex: number, columnId: string): unknown
65
- /** Write a cell value through the column's field. */
66
- setCellValue(rowIndex: number, columnId: string, value: unknown): void
67
-
68
- // ----- Cell selection -----
69
- /**
70
- * Programmatically select one or more rectangular cell ranges. Each
71
- * range is `[rowStart, colStart, rowEnd, colEnd]` in 0-indexed grid
72
- * coordinates. Pass an empty array to clear the selection.
73
- *
74
- * The grid currently honours the FIRST range only (single-range
75
- * engine); subsequent ranges are accepted for API forward compat
76
- * but ignored. The grid's active cell jumps to the range's start
77
- * corner.
78
- */
79
- selectCells(ranges: ReadonlyArray<readonly [number, number, number, number]>): void
80
- /**
81
- * Returns the current cell-selection rectangles in the same shape
82
- * `selectCells` accepts. Empty array when no range is active.
83
- */
84
- getSelected(): Array<[number, number, number, number]>
85
-
86
- // ----- Rows -----
87
- /** Add one row. `position` defaults to `'bottom'`. */
88
- addRow(row: TData, position?: 'top' | 'bottom' | number): void
89
- addRows(rows: ReadonlyArray<TData>, position?: 'top' | 'bottom' | number): void
90
- /** Remove a row at the given data-array index. */
91
- removeRow(rowIndex: number): void
92
- removeRows(rowIndices: ReadonlyArray<number>): void
93
- /**
94
- * Apply a batch of add / update / remove mutations in a SINGLE data update
95
- * (one re-render, not one per row) - the high-frequency / streaming path.
96
- * `update` and `remove`-by-id match rows via `getRowId`, so set that prop
97
- * for those to work; `remove` also accepts row object references. Returns
98
- * the counts actually applied.
99
- */
100
- applyTransaction(tx: SvGridTransaction<TData>): SvGridTransactionResult
101
-
102
- // ----- Columns -----
103
- /** Add one column. `position` defaults to `'right'`. */
104
- addColumn(
105
- column: ColumnDef<TFeatures, TData>,
106
- position?: 'left' | 'right' | number,
107
- ): void
108
- addColumns(
109
- columns: ReadonlyArray<ColumnDef<TFeatures, TData>>,
110
- position?: 'left' | 'right' | number,
111
- ): void
112
- /** Remove a column by id (or field when no id was provided). */
113
- removeColumn(columnId: string): void
114
-
115
- // ----- Visibility -----
116
- setColumnVisible(columnId: string, visible: boolean): void
117
- isColumnVisible(columnId: string): boolean
118
-
119
- // ----- Sort / group / filter -----
120
- /** Sort by one column (replaces any existing sort). Pass `null` to clear. */
121
- setSort(columnId: string, direction: 'asc' | 'desc' | null): void
122
- clearSort(): void
123
- setGroupBy(columnIds: ReadonlyArray<string>): void
124
- /** Set the operator filter for a column. Pass `null` to clear. */
125
- setFilter(
126
- columnId: string,
127
- filter:
128
- | {
129
- operator: SvGridFilterOperator
130
- value?: string
131
- /** Upper bound for the `between` operator. Required when `operator === 'between'`. */
132
- valueTo?: string
133
- }
134
- | null,
135
- ): void
136
- /**
137
- * Set the facet (set-list, Excel-style multi-select) filter for a column.
138
- * Pass an empty array or `null` to clear it. The values restore the
139
- * checked state of the column-menu's value list - the engine then filters
140
- * the data to rows whose cell value is in the set. Used to restore
141
- * snapshots captured via `onFiltersChange`'s `selectedValues`.
142
- */
143
- setFacetFilter(columnId: string, values: ReadonlyArray<string> | null): void
144
- clearFilter(columnId: string): void
145
- /**
146
- * Clear every active column filter (menu, filter-row, set-list, and global).
147
- * Resets the grid to "no filtering" in a single call.
148
- */
149
- clearAllFilters(): void
150
- /**
151
- * Read the active column-menu filters as a snapshot. Keyed by column id.
152
- * Returns an empty object when nothing is filtered. `valueTo` is only
153
- * present when `operator === 'between'`.
154
- */
155
- getFilters(): Record<
156
- string,
157
- { operator: SvGridFilterOperator; value: string; valueTo?: string }
158
- >
159
-
160
- /**
161
- * Snapshot of the rows the grid is actually displaying right now -
162
- * after filtering, sorting, grouping, and pagination have been applied.
163
- * Use this when you need to export the visible result set (e.g. CSV).
164
- */
165
- getDisplayedRows(): ReadonlyArray<TData>
166
-
167
- /** Snapshot of the current data array (pre-pipeline). */
168
- getData(): ReadonlyArray<TData>
169
-
170
- /**
171
- * Snapshot of every column the grid currently knows about, in visual
172
- * order, with the human-readable header label. Use this when exporting
173
- * or building a column-picker UI - the data is read once, no
174
- * subscription. Hidden columns are included; check `visible` to filter.
175
- */
176
- getColumns(): ReadonlyArray<{
177
- id: string
178
- field?: string
179
- header: string
180
- visible: boolean
181
- }>
182
-
183
- /** Clear every checked row. Emits `onRowSelectionChange({}, [])`. */
184
- clearRowSelection(): void
185
-
186
- // ----- Column layout (width + pinning) -----
187
- /**
188
- * Set the width of one column in pixels. Identical to dragging the
189
- * column's resize handle. Width is clamped to `MIN_COLUMN_WIDTH`.
190
- */
191
- setColumnWidth(columnId: string, width: number): void
192
- /**
193
- * Snapshot of every column's current width (in pixels), keyed by
194
- * column id. Columns the user has never resized AND that have no
195
- * explicit `width` on their ColumnDef are reported at the grid-wide
196
- * default. Useful for "save view" + URL persistence.
197
- */
198
- getColumnWidths(): Record<string, number>
199
- /**
200
- * Snap one column's width to its widest visible cell (header text +
201
- * any rendered body cell). Equivalent to double-clicking the column's
202
- * resize handle. The grid also exposes this through the column menu's
203
- * "Autosize" item.
204
- */
205
- autosizeColumn(columnId: string): void
206
- /** Run `autosizeColumn` on every column. */
207
- autosizeAllColumns(): void
208
- /**
209
- * Replace the column-pinning state in one call. Each entry is a
210
- * column id; the order in the array becomes the visible order along
211
- * the pinned edge.
212
- */
213
- setColumnPinning(pinning: {
214
- left?: ReadonlyArray<string>
215
- right?: ReadonlyArray<string>
216
- }): void
217
- /** Snapshot of the current column-pinning state. */
218
- getColumnPinning(): { left: string[]; right: string[] }
219
-
220
- // ----- Column reorder -----
221
- /**
222
- * Replace the column order. Pass an array of column ids in the
223
- * desired visual order. Unknown ids are skipped; columns not in the
224
- * array keep their existing relative position after the listed ones.
225
- * Fires `onColumnOrderChange` once the new order is applied. Pin
226
- * groups (`columnPinning.left` / `right`) are still applied on top.
227
- */
228
- setColumnOrder(order: ReadonlyArray<string>): void
229
- /**
230
- * Snapshot of the current visual column order - the same shape the
231
- * `onColumnOrderChange` callback receives. Useful for saving and
232
- * restoring a view layout.
233
- */
234
- getColumnOrder(): string[]
235
-
236
- // ----- Row expansion -----
237
- /**
238
- * Set whether a row (group node or expandable leaf) is expanded.
239
- * The `id` is the engine's row id - for grouped rows that's the
240
- * synthetic group key (e.g. `"department:Engineering"`).
241
- */
242
- setRowExpanded(id: string, expanded: boolean): void
243
- /** Expand every group node in the current grouped row model. */
244
- expandAllGroups(): void
245
- /** Collapse every expansion - resets expanded state to {}. */
246
- collapseAllGroups(): void
247
-
248
- // ----- Undo / redo -----
249
- /** Undo the most recent inline-edit. Returns false when the history is empty. */
250
- undo(): boolean
251
- /** Redo the most recently undone edit. Returns false when the redo stack is empty. */
252
- redo(): boolean
253
- /** True when there's at least one step on the undo stack. */
254
- canUndo(): boolean
255
- /** True when there's at least one step on the redo stack. */
256
- canRedo(): boolean
257
- /** Wipe both stacks (e.g. after a server save commits the buffer). */
258
- clearHistory(): void
259
-
260
- // ----- Find in grid -----
261
- /** Open the built-in find overlay (Ctrl+F also opens it). */
262
- openFind(): void
263
- /** Close the find overlay and clear the query. */
264
- closeFind(): void
265
- /** Update the find query programmatically (useful for app-wide command palettes). */
266
- setFindQuery(q: string): void
267
- /** Snapshot of the current find hits (rowIndex / colIndex / columnId). */
268
- getFindHits(): Array<{ rowIndex: number; colIndex: number; columnId: string }>
269
-
270
- // ----- Row selection (read + write) -----
271
- /**
272
- * The currently selected data rows (group-header rows excluded), in row-model
273
- * order. Read once - no subscription. The push-based equivalent is
274
- * `onRowSelectionChange`.
275
- */
276
- getSelectedRows(): TData[]
277
- /** The engine row ids of the selected rows. Keys into the selection record. */
278
- getSelectedRowIds(): string[]
279
- /**
280
- * Select rows by engine row id. By default this REPLACES the selection;
281
- * pass `additive: true` to add to the existing selection instead.
282
- */
283
- selectRows(ids: ReadonlyArray<string>, additive?: boolean): void
284
- /** Select every selectable (non-group) row in the current row model. */
285
- selectAllRows(): void
286
- /** Flip one row's selected state by id. */
287
- toggleRowSelected(id: string): void
288
-
289
- // ----- Pagination -----
290
- /**
291
- * Current pagination snapshot. `total` is the post-filter row count;
292
- * `pageCount` is derived from it and `pageSize` (always >= 1).
293
- */
294
- getPageInfo(): {
295
- pageIndex: number
296
- pageSize: number
297
- pageCount: number
298
- total: number
299
- }
300
- /** Jump to a 0-based page. Clamped to [0, pageCount - 1]. */
301
- setPage(pageIndex: number): void
302
- /** Advance one page (no-op past the last page). */
303
- nextPage(): void
304
- /** Go back one page (no-op before the first page). */
305
- prevPage(): void
306
- /** Jump to the first page. */
307
- firstPage(): void
308
- /** Jump to the last page. */
309
- lastPage(): void
310
- /** Change the page size, keeping the first visible row in view. */
311
- setPageSize(pageSize: number): void
312
-
313
- // ----- Navigation / scrolling -----
314
- /**
315
- * Scroll the body so the given row index is at the top of the viewport.
316
- * Works with virtualization on. Index is clamped to the row count.
317
- */
318
- scrollToRow(rowIndex: number): void
319
- /** The active (focused) cell, or null when nothing is focused. */
320
- getActiveCell(): { rowIndex: number; colIndex: number; columnId: string } | null
321
- /** Move the active cell. Both coordinates are clamped to the grid bounds. */
322
- setActiveCell(rowIndex: number, colIndex: number): void
323
-
324
- // ----- View state (save / restore) -----
325
- /**
326
- * Serializable snapshot of the whole view - sort, grouping, pagination,
327
- * column layout, and every filter surface. Pair with `setState` for
328
- * "save view" / URL persistence / named views.
329
- */
330
- getState(): SvGridViewState
331
- /**
332
- * Restore a view from a (partial) snapshot produced by `getState`. Only the
333
- * keys present are applied, so you can restore just the columns, just the
334
- * filters, etc.
335
- */
336
- setState(state: Partial<SvGridViewState>): void
337
- /** Force a recompute of the row pipeline + a re-render. */
338
- refresh(): void
339
- }
340
-
341
- export type SvGridWrapperProps<
342
- TFeatures extends TableFeatures,
343
- TData extends RowData,
344
- > = {
345
- data: ReadonlyArray<TData>
346
- columns: Array<ColumnDef<TFeatures, TData>>
347
- /**
348
- * Feature set from `tableFeatures({ ... })`. Optional - the `sortable` /
349
- * `filterable` / `groupable` shortcuts inject the matching feature, so a
350
- * grid can be configured from the boolean shortcuts alone.
351
- */
352
- features?: TFeatures
353
- /**
354
- * Capability shortcuts. Every capability is OFF by default (a bare grid is
355
- * a plain read-only table); set a shortcut `true` to opt in.
356
- *
357
- * `sortable` - column sorting (injects `rowSortingFeature`)
358
- * `filterable` - column filtering (injects `columnFilteringFeature`)
359
- * `editable` - inline editing (alias of `enableInlineEditing`)
360
- * `groupable` - grouping controls (alias of `showGroupingControls`)
361
- * `pageable` - pagination footer (alias of `showPagination`)
362
- */
363
- sortable?: boolean
364
- filterable?: boolean
365
- editable?: boolean
366
- groupable?: boolean
367
- pageable?: boolean
368
- options?: Partial<SvGridOptions<TFeatures, TData>>
369
- loading?: boolean
370
- error?: string | null
371
- emptyMessage?: string
372
- showGlobalFilter?: boolean
373
- showColumnFilters?: boolean
374
- showGroupingControls?: boolean
375
- showRowSelection?: boolean
376
- showPagination?: boolean
377
- virtualization?: boolean
378
- /** Row height in pixels. Pass a function `(rowIndex) => px` for per-row
379
- * variable heights (e.g. when wiring up an interactive row-resize). */
380
- rowHeight?: number | ((rowIndex: number) => number)
381
- overscan?: number
382
- containerHeight?: number
383
- columnVirtualization?: boolean
384
- columnOverscan?: number
385
- columnWidth?: number
386
- showFilterMenu?: boolean
387
- showFilterRow?: boolean
388
- enableCellSelection?: boolean
389
- enableInlineEditing?: boolean
390
- enableRowSummaries?: boolean
391
- /** Receives the imperative grid API when the component is ready. */
392
- onApiReady?: (api: SvGridApi<TFeatures, TData>) => void
393
- }
1
+ import type { ColumnDef, RowData, SvGridOptions, TableFeatures } from './core'
2
+
3
+ export type SvGridFilterOperator =
4
+ | 'contains'
5
+ | 'equals'
6
+ | 'startsWith'
7
+ | 'greaterThan'
8
+ | 'lessThan'
9
+ | 'between'
10
+ | 'isBlank'
11
+
12
+ /**
13
+ * A serializable snapshot of everything that makes up the current "view":
14
+ * sort, grouping, pagination, column layout (width / pinning / order /
15
+ * visibility), and all filter surfaces. Round-trippable through
16
+ * `api.getState()` / `api.setState()` - persist it to a URL, localStorage, or
17
+ * a server to implement "save view" / "named views".
18
+ */
19
+ export type SvGridViewState = {
20
+ sorting: Array<{ id: string; desc: boolean }>
21
+ grouping: string[]
22
+ pagination: { pageIndex: number; pageSize: number }
23
+ columnWidths: Record<string, number>
24
+ columnPinning: { left: string[]; right: string[] }
25
+ columnOrder: string[]
26
+ /** Ids of columns currently hidden via setColumnVisible. */
27
+ hiddenColumns: string[]
28
+ globalFilter: string
29
+ columnFilters: Record<
30
+ string,
31
+ { operator: SvGridFilterOperator; value: string; valueTo?: string }
32
+ >
33
+ /** Facet (Excel-style value checklist) selections, keyed by column id. */
34
+ facetFilters: Record<string, string[]>
35
+ }
36
+
37
+ /**
38
+ * A batch of row mutations for `api.applyTransaction`. `update` / `remove`
39
+ * (by id) match on `getRowId`; `remove` also accepts row object references.
40
+ */
41
+ export type SvGridTransaction<TData> = {
42
+ add?: ReadonlyArray<TData>
43
+ update?: ReadonlyArray<TData>
44
+ remove?: ReadonlyArray<TData | string>
45
+ }
46
+
47
+ export type SvGridTransactionResult = {
48
+ added: number
49
+ updated: number
50
+ removed: number
51
+ }
52
+
53
+ /**
54
+ * Imperative API exposed via the `<SvGrid onApiReady>` callback. Use it for
55
+ * data, column, filter, sort, group, and visibility operations from outside
56
+ * the component.
57
+ */
58
+ export type SvGridApi<
59
+ TFeatures extends TableFeatures,
60
+ TData extends RowData,
61
+ > = {
62
+ // ----- Cells -----
63
+ /** Read a cell value from the underlying data at `rowIndex`. */
64
+ getCellValue(rowIndex: number, columnId: string): unknown
65
+ /** Write a cell value through the column's field. */
66
+ setCellValue(rowIndex: number, columnId: string, value: unknown): void
67
+ /**
68
+ * Programmatically begin editing a cell (as a double-click would). Returns
69
+ * `true` if editing started (cell exists, editable, editing enabled).
70
+ */
71
+ startEditing(rowIndex: number, columnId: string): boolean
72
+ /**
73
+ * Commit (default) or, with `cancel: true`, discard the active edit.
74
+ * Returns `true` if there was an edit in progress.
75
+ */
76
+ stopEditing(cancel?: boolean): boolean
77
+
78
+ // ----- Cell selection -----
79
+ /**
80
+ * Programmatically select one or more rectangular cell ranges. Each
81
+ * range is `[rowStart, colStart, rowEnd, colEnd]` in 0-indexed grid
82
+ * coordinates. Pass an empty array to clear the selection.
83
+ *
84
+ * The grid currently honours the FIRST range only (single-range
85
+ * engine); subsequent ranges are accepted for API forward compat
86
+ * but ignored. The grid's active cell jumps to the range's start
87
+ * corner.
88
+ */
89
+ selectCells(ranges: ReadonlyArray<readonly [number, number, number, number]>): void
90
+ /**
91
+ * Returns the current cell-selection rectangles in the same shape
92
+ * `selectCells` accepts. Empty array when no range is active.
93
+ */
94
+ getSelected(): Array<[number, number, number, number]>
95
+
96
+ // ----- Rows -----
97
+ /** Add one row. `position` defaults to `'bottom'`. */
98
+ addRow(row: TData, position?: 'top' | 'bottom' | number): void
99
+ addRows(rows: ReadonlyArray<TData>, position?: 'top' | 'bottom' | number): void
100
+ /** Remove a row at the given data-array index. */
101
+ removeRow(rowIndex: number): void
102
+ removeRows(rowIndices: ReadonlyArray<number>): void
103
+ /**
104
+ * Apply a batch of add / update / remove mutations in a SINGLE data update
105
+ * (one re-render, not one per row) - the high-frequency / streaming path.
106
+ * `update` and `remove`-by-id match rows via `getRowId`, so set that prop
107
+ * for those to work; `remove` also accepts row object references. Returns
108
+ * the counts actually applied.
109
+ */
110
+ applyTransaction(tx: SvGridTransaction<TData>): SvGridTransactionResult
111
+
112
+ // ----- Columns -----
113
+ /** Add one column. `position` defaults to `'right'`. */
114
+ addColumn(
115
+ column: ColumnDef<TFeatures, TData>,
116
+ position?: 'left' | 'right' | number,
117
+ ): void
118
+ addColumns(
119
+ columns: ReadonlyArray<ColumnDef<TFeatures, TData>>,
120
+ position?: 'left' | 'right' | number,
121
+ ): void
122
+ /** Remove a column by id (or field when no id was provided). */
123
+ removeColumn(columnId: string): void
124
+
125
+ // ----- Visibility -----
126
+ setColumnVisible(columnId: string, visible: boolean): void
127
+ isColumnVisible(columnId: string): boolean
128
+
129
+ // ----- Sort / group / filter -----
130
+ /** Sort by one column (replaces any existing sort). Pass `null` to clear. */
131
+ setSort(columnId: string, direction: 'asc' | 'desc' | null): void
132
+ clearSort(): void
133
+ setGroupBy(columnIds: ReadonlyArray<string>): void
134
+ /** Set the operator filter for a column. Pass `null` to clear. */
135
+ setFilter(
136
+ columnId: string,
137
+ filter:
138
+ | {
139
+ operator: SvGridFilterOperator
140
+ value?: string
141
+ /** Upper bound for the `between` operator. Required when `operator === 'between'`. */
142
+ valueTo?: string
143
+ /**
144
+ * Optional SECOND condition on the same column, joined by `join`
145
+ * (multi-condition filtering, e.g. "> 100 AND < 500").
146
+ */
147
+ operator2?: SvGridFilterOperator
148
+ value2?: string
149
+ valueTo2?: string
150
+ /** How to combine the two conditions. Defaults to `'AND'`. */
151
+ join?: 'AND' | 'OR'
152
+ }
153
+ | null,
154
+ ): void
155
+ /**
156
+ * Set the facet (set-list, Excel-style multi-select) filter for a column.
157
+ * Pass an empty array or `null` to clear it. The values restore the
158
+ * checked state of the column-menu's value list - the engine then filters
159
+ * the data to rows whose cell value is in the set. Used to restore
160
+ * snapshots captured via `onFiltersChange`'s `selectedValues`.
161
+ */
162
+ setFacetFilter(columnId: string, values: ReadonlyArray<string> | null): void
163
+ clearFilter(columnId: string): void
164
+ /**
165
+ * Clear every active column filter (menu, filter-row, set-list, and global).
166
+ * Resets the grid to "no filtering" in a single call.
167
+ */
168
+ clearAllFilters(): void
169
+ /**
170
+ * Read the active column-menu filters as a snapshot. Keyed by column id.
171
+ * Returns an empty object when nothing is filtered. `valueTo` is only
172
+ * present when `operator === 'between'`.
173
+ */
174
+ getFilters(): Record<
175
+ string,
176
+ { operator: SvGridFilterOperator; value: string; valueTo?: string }
177
+ >
178
+
179
+ /**
180
+ * Snapshot of the rows the grid is actually displaying right now -
181
+ * after filtering, sorting, grouping, and pagination have been applied.
182
+ * Use this when you need to export the visible result set (e.g. CSV).
183
+ */
184
+ getDisplayedRows(): ReadonlyArray<TData>
185
+
186
+ /** Snapshot of the current data array (pre-pipeline). */
187
+ getData(): ReadonlyArray<TData>
188
+
189
+ /**
190
+ * Snapshot of every column the grid currently knows about, in visual
191
+ * order, with the human-readable header label. Use this when exporting
192
+ * or building a column-picker UI - the data is read once, no
193
+ * subscription. Hidden columns are included; check `visible` to filter.
194
+ */
195
+ getColumns(): ReadonlyArray<{
196
+ id: string
197
+ field?: string
198
+ header: string
199
+ visible: boolean
200
+ }>
201
+
202
+ /** Clear every checked row. Emits `onRowSelectionChange({}, [])`. */
203
+ clearRowSelection(): void
204
+
205
+ // ----- Column layout (width + pinning) -----
206
+ /**
207
+ * Set the width of one column in pixels. Identical to dragging the
208
+ * column's resize handle. Width is clamped to `MIN_COLUMN_WIDTH`.
209
+ */
210
+ setColumnWidth(columnId: string, width: number): void
211
+ /**
212
+ * Snapshot of every column's current width (in pixels), keyed by
213
+ * column id. Columns the user has never resized AND that have no
214
+ * explicit `width` on their ColumnDef are reported at the grid-wide
215
+ * default. Useful for "save view" + URL persistence.
216
+ */
217
+ getColumnWidths(): Record<string, number>
218
+ /**
219
+ * Snap one column's width to its widest visible cell (header text +
220
+ * any rendered body cell). Equivalent to double-clicking the column's
221
+ * resize handle. The grid also exposes this through the column menu's
222
+ * "Autosize" item.
223
+ */
224
+ autosizeColumn(columnId: string): void
225
+ /** Run `autosizeColumn` on every column. */
226
+ autosizeAllColumns(): void
227
+ /**
228
+ * Replace the column-pinning state in one call. Each entry is a
229
+ * column id; the order in the array becomes the visible order along
230
+ * the pinned edge.
231
+ */
232
+ setColumnPinning(pinning: {
233
+ left?: ReadonlyArray<string>
234
+ right?: ReadonlyArray<string>
235
+ }): void
236
+ /** Snapshot of the current column-pinning state. */
237
+ getColumnPinning(): { left: string[]; right: string[] }
238
+
239
+ // ----- Column reorder -----
240
+ /**
241
+ * Replace the column order. Pass an array of column ids in the
242
+ * desired visual order. Unknown ids are skipped; columns not in the
243
+ * array keep their existing relative position after the listed ones.
244
+ * Fires `onColumnOrderChange` once the new order is applied. Pin
245
+ * groups (`columnPinning.left` / `right`) are still applied on top.
246
+ */
247
+ setColumnOrder(order: ReadonlyArray<string>): void
248
+ /**
249
+ * Snapshot of the current visual column order - the same shape the
250
+ * `onColumnOrderChange` callback receives. Useful for saving and
251
+ * restoring a view layout.
252
+ */
253
+ getColumnOrder(): string[]
254
+
255
+ // ----- Row expansion -----
256
+ /**
257
+ * Set whether a row (group node or expandable leaf) is expanded.
258
+ * The `id` is the engine's row id - for grouped rows that's the
259
+ * synthetic group key (e.g. `"department:Engineering"`).
260
+ */
261
+ setRowExpanded(id: string, expanded: boolean): void
262
+ /** Expand every group node in the current grouped row model. */
263
+ expandAllGroups(): void
264
+ /** Collapse every expansion - resets expanded state to {}. */
265
+ collapseAllGroups(): void
266
+
267
+ // ----- Undo / redo -----
268
+ /** Undo the most recent inline-edit. Returns false when the history is empty. */
269
+ undo(): boolean
270
+ /** Redo the most recently undone edit. Returns false when the redo stack is empty. */
271
+ redo(): boolean
272
+ /** True when there's at least one step on the undo stack. */
273
+ canUndo(): boolean
274
+ /** True when there's at least one step on the redo stack. */
275
+ canRedo(): boolean
276
+ /** Wipe both stacks (e.g. after a server save commits the buffer). */
277
+ clearHistory(): void
278
+
279
+ // ----- Find in grid -----
280
+ /** Open the built-in find overlay (Ctrl+F also opens it). */
281
+ openFind(): void
282
+ /** Close the find overlay and clear the query. */
283
+ closeFind(): void
284
+ /** Update the find query programmatically (useful for app-wide command palettes). */
285
+ setFindQuery(q: string): void
286
+ /** Snapshot of the current find hits (rowIndex / colIndex / columnId). */
287
+ getFindHits(): Array<{ rowIndex: number; colIndex: number; columnId: string }>
288
+
289
+ // ----- Row selection (read + write) -----
290
+ /**
291
+ * The currently selected data rows (group-header rows excluded), in row-model
292
+ * order. Read once - no subscription. The push-based equivalent is
293
+ * `onRowSelectionChange`.
294
+ */
295
+ getSelectedRows(): TData[]
296
+ /** The engine row ids of the selected rows. Keys into the selection record. */
297
+ getSelectedRowIds(): string[]
298
+ /**
299
+ * Select rows by engine row id. By default this REPLACES the selection;
300
+ * pass `additive: true` to add to the existing selection instead.
301
+ */
302
+ selectRows(ids: ReadonlyArray<string>, additive?: boolean): void
303
+ /** Select every selectable (non-group) row in the current row model. */
304
+ selectAllRows(): void
305
+ /** Flip one row's selected state by id. */
306
+ toggleRowSelected(id: string): void
307
+
308
+ // ----- Pagination -----
309
+ /**
310
+ * Current pagination snapshot. `total` is the post-filter row count;
311
+ * `pageCount` is derived from it and `pageSize` (always >= 1).
312
+ */
313
+ getPageInfo(): {
314
+ pageIndex: number
315
+ pageSize: number
316
+ pageCount: number
317
+ total: number
318
+ }
319
+ /** Jump to a 0-based page. Clamped to [0, pageCount - 1]. */
320
+ setPage(pageIndex: number): void
321
+ /** Advance one page (no-op past the last page). */
322
+ nextPage(): void
323
+ /** Go back one page (no-op before the first page). */
324
+ prevPage(): void
325
+ /** Jump to the first page. */
326
+ firstPage(): void
327
+ /** Jump to the last page. */
328
+ lastPage(): void
329
+ /** Change the page size, keeping the first visible row in view. */
330
+ setPageSize(pageSize: number): void
331
+
332
+ // ----- Navigation / scrolling -----
333
+ /**
334
+ * Scroll the body so the given row index is at the top of the viewport.
335
+ * Works with virtualization on. Index is clamped to the row count.
336
+ */
337
+ scrollToRow(rowIndex: number): void
338
+ /** The active (focused) cell, or null when nothing is focused. */
339
+ getActiveCell(): { rowIndex: number; colIndex: number; columnId: string } | null
340
+ /** Move the active cell. Both coordinates are clamped to the grid bounds. */
341
+ setActiveCell(rowIndex: number, colIndex: number): void
342
+
343
+ // ----- View state (save / restore) -----
344
+ /**
345
+ * Serializable snapshot of the whole view - sort, grouping, pagination,
346
+ * column layout, and every filter surface. Pair with `setState` for
347
+ * "save view" / URL persistence / named views.
348
+ */
349
+ getState(): SvGridViewState
350
+ /**
351
+ * Restore a view from a (partial) snapshot produced by `getState`. Only the
352
+ * keys present are applied, so you can restore just the columns, just the
353
+ * filters, etc.
354
+ */
355
+ setState(state: Partial<SvGridViewState>): void
356
+ /** Force a recompute of the row pipeline + a re-render. */
357
+ refresh(): void
358
+ }
359
+
360
+ export type SvGridWrapperProps<
361
+ TFeatures extends TableFeatures,
362
+ TData extends RowData,
363
+ > = {
364
+ data: ReadonlyArray<TData>
365
+ columns: Array<ColumnDef<TFeatures, TData>>
366
+ /**
367
+ * Feature set from `tableFeatures({ ... })`. Optional - the `sortable` /
368
+ * `filterable` / `groupable` shortcuts inject the matching feature, so a
369
+ * grid can be configured from the boolean shortcuts alone.
370
+ */
371
+ features?: TFeatures
372
+ /**
373
+ * Capability shortcuts. Every capability is OFF by default (a bare grid is
374
+ * a plain read-only table); set a shortcut `true` to opt in.
375
+ *
376
+ * `sortable` - column sorting (injects `rowSortingFeature`)
377
+ * `filterable` - column filtering (injects `columnFilteringFeature`)
378
+ * `editable` - inline editing (alias of `enableInlineEditing`)
379
+ * `groupable` - grouping controls (alias of `showGroupingControls`)
380
+ * `pageable` - pagination footer (alias of `showPagination`)
381
+ */
382
+ sortable?: boolean
383
+ filterable?: boolean
384
+ editable?: boolean
385
+ groupable?: boolean
386
+ pageable?: boolean
387
+ options?: Partial<SvGridOptions<TFeatures, TData>>
388
+ loading?: boolean
389
+ error?: string | null
390
+ emptyMessage?: string
391
+ showGlobalFilter?: boolean
392
+ showColumnFilters?: boolean
393
+ showGroupingControls?: boolean
394
+ showRowSelection?: boolean
395
+ showPagination?: boolean
396
+ virtualization?: boolean
397
+ /** Row height in pixels. Pass a function `(rowIndex) => px` for per-row
398
+ * variable heights (e.g. when wiring up an interactive row-resize). */
399
+ rowHeight?: number | ((rowIndex: number) => number)
400
+ overscan?: number
401
+ containerHeight?: number
402
+ columnVirtualization?: boolean
403
+ columnOverscan?: number
404
+ columnWidth?: number
405
+ showFilterMenu?: boolean
406
+ showFilterRow?: boolean
407
+ enableCellSelection?: boolean
408
+ enableInlineEditing?: boolean
409
+ enableRowSummaries?: boolean
410
+ /** Receives the imperative grid API when the component is ready. */
411
+ onApiReady?: (api: SvGridApi<TFeatures, TData>) => void
412
+ }