@svgrid/grid 2.0.1 → 2.1.0

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