@svgrid/grid 1.0.2 → 1.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 (143) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +137 -39
  3. package/dist/GridFooter.svelte +164 -0
  4. package/dist/GridFooter.svelte.d.ts +29 -0
  5. package/dist/GridMenus.svelte +570 -0
  6. package/dist/GridMenus.svelte.d.ts +31 -0
  7. package/dist/SvGrid.controller.svelte.d.ts +429 -0
  8. package/dist/SvGrid.controller.svelte.js +1732 -0
  9. package/dist/SvGrid.css +1709 -0
  10. package/dist/SvGrid.helpers.d.ts +35 -0
  11. package/dist/SvGrid.helpers.js +160 -0
  12. package/dist/SvGrid.svelte +344 -7043
  13. package/dist/SvGrid.svelte.d.ts +4 -357
  14. package/dist/SvGrid.types.d.ts +436 -0
  15. package/dist/SvGrid.types.js +1 -0
  16. package/dist/SvGridChart.svelte +1060 -23
  17. package/dist/SvGridChart.svelte.d.ts +17 -0
  18. package/dist/build-api.d.ts +5 -0
  19. package/dist/build-api.js +527 -0
  20. package/dist/cell-render.d.ts +15 -0
  21. package/dist/cell-render.js +246 -0
  22. package/dist/cell-values.d.ts +28 -0
  23. package/dist/cell-values.js +89 -0
  24. package/dist/chart.d.ts +370 -3
  25. package/dist/chart.js +1135 -42
  26. package/dist/clipboard.d.ts +15 -0
  27. package/dist/clipboard.js +356 -0
  28. package/dist/columns.d.ts +30 -0
  29. package/dist/columns.js +277 -0
  30. package/dist/core.d.ts +1 -1
  31. package/dist/css.d.ts +3 -0
  32. package/dist/editing.d.ts +24 -0
  33. package/dist/editing.js +343 -0
  34. package/dist/editors/cell-editors.d.ts +1 -1
  35. package/dist/facet-buckets.d.ts +13 -0
  36. package/dist/facet-buckets.js +54 -0
  37. package/dist/features.d.ts +5 -0
  38. package/dist/features.js +30 -0
  39. package/dist/filter-operators.d.ts +16 -0
  40. package/dist/filter-operators.js +69 -0
  41. package/dist/hyperformula-adapter.d.ts +82 -0
  42. package/dist/hyperformula-adapter.js +73 -0
  43. package/dist/index.d.ts +5 -2
  44. package/dist/index.js +5 -2
  45. package/dist/keyboard-handlers.d.ts +7 -0
  46. package/dist/keyboard-handlers.js +197 -0
  47. package/dist/menus.d.ts +40 -0
  48. package/dist/menus.js +389 -0
  49. package/dist/named-views.d.ts +27 -0
  50. package/dist/named-views.js +39 -0
  51. package/dist/row-resize.d.ts +43 -0
  52. package/dist/row-resize.js +158 -0
  53. package/dist/scroll-sync.d.ts +9 -0
  54. package/dist/scroll-sync.js +86 -0
  55. package/dist/selection.d.ts +26 -0
  56. package/dist/selection.js +387 -0
  57. package/dist/spreadsheet.d.ts +80 -0
  58. package/dist/spreadsheet.js +194 -0
  59. package/dist/summaries.d.ts +12 -0
  60. package/dist/summaries.js +65 -0
  61. package/dist/svgrid-wrapper.types.d.ts +12 -1
  62. package/dist/svgrid.comments-autocomplete.test.d.ts +1 -0
  63. package/dist/svgrid.comments-autocomplete.test.js +96 -0
  64. package/dist/svgrid.context-menu.test.d.ts +1 -0
  65. package/dist/svgrid.context-menu.test.js +102 -0
  66. package/dist/svgrid.new-features.wrapper.test.js +30 -4
  67. package/dist/svgrid.wrapper.test.js +27 -1
  68. package/dist/virtualization/column-virtualizer.d.ts +2 -0
  69. package/dist/virtualization/scroll-scaling.d.ts +28 -0
  70. package/dist/virtualization/scroll-scaling.js +64 -0
  71. package/dist/virtualization/scroll-scaling.test.d.ts +1 -0
  72. package/dist/virtualization/scroll-scaling.test.js +86 -0
  73. package/dist/virtualization/svelte-virtualizer.svelte.d.ts +2 -0
  74. package/dist/virtualization/svelte-virtualizer.svelte.js +2 -0
  75. package/dist/virtualization/virtualizer.d.ts +7 -0
  76. package/dist/virtualization/virtualizer.js +30 -0
  77. package/package.json +1 -1
  78. package/src/GridFooter.svelte +164 -0
  79. package/src/GridMenus.svelte +570 -0
  80. package/src/SvGrid.controller.svelte.ts +2195 -0
  81. package/src/SvGrid.css +1747 -0
  82. package/src/SvGrid.helpers.test.ts +415 -0
  83. package/src/SvGrid.helpers.ts +185 -0
  84. package/src/SvGrid.svelte +348 -7043
  85. package/src/SvGrid.types.ts +456 -0
  86. package/src/SvGridChart.svelte +1060 -23
  87. package/src/build-api.coverage.test.ts +532 -0
  88. package/src/build-api.ts +663 -0
  89. package/src/cell-render.test.ts +451 -0
  90. package/src/cell-render.ts +426 -0
  91. package/src/cell-values.ts +114 -0
  92. package/src/chart-export.test.ts +370 -0
  93. package/src/chart.coverage.test.ts +814 -0
  94. package/src/chart.ts +1352 -47
  95. package/src/clipboard.test.ts +731 -0
  96. package/src/clipboard.ts +524 -0
  97. package/src/collaboration.coverage.test.ts +220 -0
  98. package/src/columns.test.ts +702 -0
  99. package/src/columns.ts +419 -0
  100. package/src/core.ts +8 -0
  101. package/src/css.d.ts +3 -0
  102. package/src/editing.test.ts +837 -0
  103. package/src/editing.ts +513 -0
  104. package/src/editors/cell-editors.coverage.test.ts +156 -0
  105. package/src/editors/cell-editors.ts +1 -0
  106. package/src/facet-buckets.test.ts +353 -0
  107. package/src/facet-buckets.ts +67 -0
  108. package/src/features.ts +128 -0
  109. package/src/filter-operators.test.ts +174 -0
  110. package/src/filter-operators.ts +87 -0
  111. package/src/hyperformula-adapter.test.ts +256 -0
  112. package/src/hyperformula-adapter.ts +124 -0
  113. package/src/index.ts +37 -0
  114. package/src/keyboard-handlers.coverage.test.ts +560 -0
  115. package/src/keyboard-handlers.ts +353 -0
  116. package/src/keyboard.ts +97 -97
  117. package/src/menus.test.ts +620 -0
  118. package/src/menus.ts +554 -0
  119. package/src/named-views.coverage.test.ts +210 -0
  120. package/src/named-views.ts +48 -0
  121. package/src/row-resize.test.ts +369 -0
  122. package/src/row-resize.ts +171 -0
  123. package/src/scroll-sync.test.ts +330 -0
  124. package/src/scroll-sync.ts +216 -0
  125. package/src/selection.test.ts +722 -0
  126. package/src/selection.ts +545 -0
  127. package/src/server-data-source.coverage.test.ts +180 -0
  128. package/src/spreadsheet.test.ts +445 -0
  129. package/src/spreadsheet.ts +246 -0
  130. package/src/summaries.ts +204 -0
  131. package/src/sv-grid-scrollbar.ts +13 -1
  132. package/src/svgrid-wrapper.types.ts +12 -1
  133. package/src/svgrid.behavior.test.ts +22 -0
  134. package/src/svgrid.comments-autocomplete.test.ts +112 -0
  135. package/src/svgrid.context-menu.test.ts +126 -0
  136. package/src/svgrid.interaction.test.ts +30 -0
  137. package/src/svgrid.new-features.wrapper.test.ts +65 -4
  138. package/src/svgrid.wrapper.test.ts +27 -1
  139. package/src/test-setup.ts +9 -6
  140. package/src/virtualization/scroll-scaling.test.ts +148 -0
  141. package/src/virtualization/scroll-scaling.ts +121 -0
  142. package/src/virtualization/svelte-virtualizer.svelte.ts +2 -0
  143. package/src/virtualization/virtualizer.ts +26 -0
package/dist/menus.js ADDED
@@ -0,0 +1,389 @@
1
+ import "./sv-grid-scrollbar";
2
+ import { clampMenuX, cssEscape, } from "./SvGrid.helpers";
3
+ export function createMenus(ctx) {
4
+ function updateFilterRow(columnId, value) {
5
+ ctx.filterRowValues = { ...ctx.filterRowValues, [columnId]: value };
6
+ const current = ctx.filterMenuValues[columnId] ?? {
7
+ operator: "contains",
8
+ value: "",
9
+ };
10
+ ctx.filterMenuValues = {
11
+ ...ctx.filterMenuValues,
12
+ [columnId]: { ...current, value },
13
+ };
14
+ }
15
+ function updateFilterOperator(columnId, operator) {
16
+ const current = ctx.filterMenuValues[columnId] ?? {
17
+ operator: "contains",
18
+ value: "",
19
+ };
20
+ ctx.filterMenuValues = {
21
+ ...ctx.filterMenuValues,
22
+ [columnId]: { ...current, operator },
23
+ };
24
+ }
25
+ function updateFilterMenuValue(columnId, value) {
26
+ const current = ctx.filterMenuValues[columnId] ?? {
27
+ operator: "contains",
28
+ value: "",
29
+ };
30
+ ctx.filterMenuValues = {
31
+ ...ctx.filterMenuValues,
32
+ [columnId]: { ...current, value },
33
+ };
34
+ ctx.filterRowValues = { ...ctx.filterRowValues, [columnId]: value };
35
+ }
36
+ /** Upper-bound input for the `between` operator. Only relevant when
37
+ * the column's current operator is `between`; harmless to call
38
+ * otherwise. */
39
+ function updateFilterMenuValueTo(columnId, valueTo) {
40
+ const current = ctx.filterMenuValues[columnId] ?? {
41
+ operator: "between",
42
+ value: "",
43
+ };
44
+ ctx.filterMenuValues = {
45
+ ...ctx.filterMenuValues,
46
+ [columnId]: { ...current, valueTo },
47
+ };
48
+ }
49
+ function toggleCheckboxWithKeyboard(event, toggle) {
50
+ if (event.key !== "Enter" && event.key !== " ")
51
+ return;
52
+ event.preventDefault();
53
+ toggle();
54
+ }
55
+ function isColumnFiltered(columnId) {
56
+ if (ctx.valueFilters[columnId])
57
+ return true;
58
+ const menuFilter = ctx.filterMenuValues[columnId];
59
+ return Boolean(menuFilter &&
60
+ (menuFilter.operator === "isBlank" || menuFilter.value.trim()));
61
+ }
62
+ function closeMenus() {
63
+ ctx.columnMenuFor = null;
64
+ ctx.filterMenuFor = null;
65
+ ctx.operatorMenuFor = null;
66
+ ctx.chooseColumnsPos = null;
67
+ }
68
+ function openChooseColumns(event) {
69
+ event.stopPropagation();
70
+ // Submenu behavior: keep the parent operations menu open and float the
71
+ // Choose Columns panel out to the right of it (AG-Grid style). Falls
72
+ // back to below the item if the popover would clip the viewport.
73
+ const trigger = event.currentTarget;
74
+ const menuEl = trigger.closest(".sv-grid-menu");
75
+ const anchor = (menuEl ?? trigger).getBoundingClientRect();
76
+ const panelWidth = 240;
77
+ const wantRight = anchor.right + 4;
78
+ const x = wantRight + panelWidth + 8 > window.innerWidth
79
+ ? clampMenuX(anchor.left - panelWidth - 4, panelWidth)
80
+ : clampMenuX(wantRight, panelWidth);
81
+ ctx.chooseColumnsPos = { x, y: anchor.top };
82
+ }
83
+ function openColumnMenu(event, columnId) {
84
+ event.stopPropagation();
85
+ const wasOpen = ctx.columnMenuFor === columnId;
86
+ closeMenus();
87
+ if (wasOpen)
88
+ return;
89
+ const rect = event.currentTarget.getBoundingClientRect();
90
+ ctx.columnMenuPos = {
91
+ x: clampMenuX(rect.right - 240, 240),
92
+ y: rect.bottom + 4,
93
+ };
94
+ ctx.columnMenuFor = columnId;
95
+ }
96
+ function openFilterMenu(event, columnId) {
97
+ event.stopPropagation();
98
+ const wasOpen = ctx.filterMenuFor === columnId;
99
+ closeMenus();
100
+ if (wasOpen)
101
+ return;
102
+ // If the consumer is running in row-mode (or any mode where the
103
+ // funnel popover wouldn't render), redirect the click to the
104
+ // inline filter input for this column. Without this the funnel
105
+ // would be a dead button - it visibly clicks but nothing happens
106
+ // because the menu is gated behind `showColumnFiltersEffective`.
107
+ if (!ctx.showColumnFiltersEffective && ctx.showFilterRowEffective) {
108
+ // Find the row-mode filter input and focus it. The input is
109
+ // tagged with `data-svgrid-filter-col` so we can target by id
110
+ // without depending on column position.
111
+ const input = ctx.scrollContainer?.querySelector(`[data-svgrid-filter-col="${cssEscape(columnId)}"]`);
112
+ if (input) {
113
+ input.focus();
114
+ input.select();
115
+ // Brief pulse so the user sees where focus landed.
116
+ input.classList.add("sv-grid-filter-value-pulse");
117
+ setTimeout(() => input.classList.remove("sv-grid-filter-value-pulse"), 700);
118
+ }
119
+ return;
120
+ }
121
+ const rect = event.currentTarget.getBoundingClientRect();
122
+ ctx.filterMenuPos = {
123
+ x: clampMenuX(rect.right - 260, 260),
124
+ y: rect.bottom + 4,
125
+ };
126
+ ctx.columnMenuSearch = "";
127
+ ctx.filterMenuFor = columnId;
128
+ }
129
+ function openOperatorMenu(event, columnId) {
130
+ event.stopPropagation();
131
+ const wasOpen = ctx.operatorMenuFor === columnId;
132
+ closeMenus();
133
+ if (wasOpen)
134
+ return;
135
+ const rect = event.currentTarget.getBoundingClientRect();
136
+ ctx.operatorMenuPos = { x: clampMenuX(rect.left, 184), y: rect.bottom + 4 };
137
+ ctx.operatorMenuFor = columnId;
138
+ }
139
+ function sortColumnFromMenu(columnId, desc) {
140
+ ctx.grid.store.setState((prev) => ({
141
+ ...prev,
142
+ sorting: [{ id: columnId, desc }],
143
+ }));
144
+ closeMenus();
145
+ }
146
+ function clearColumnSort(columnId) {
147
+ ctx.grid.store.setState((prev) => ({
148
+ ...prev,
149
+ sorting: (prev.sorting ?? []).filter((entry) => entry.id !== columnId),
150
+ }));
151
+ closeMenus();
152
+ }
153
+ function groupByColumnFromMenu(columnId) {
154
+ const current = ctx.grid.getState().grouping ?? [];
155
+ if (current.includes(columnId)) {
156
+ closeMenus();
157
+ return;
158
+ }
159
+ ctx.grid.setGrouping([...current, columnId]);
160
+ closeMenus();
161
+ }
162
+ function clearGroupingFromMenu(columnId) {
163
+ const current = ctx.grid.getState().grouping ?? [];
164
+ ctx.grid.setGrouping(current.filter((id) => id !== columnId));
165
+ closeMenus();
166
+ }
167
+ function isFacetChecked(columnId, value) {
168
+ const selected = ctx.valueFilters[columnId];
169
+ return selected ? selected.has(value) : true;
170
+ }
171
+ function toggleFacetValue(columnId, value) {
172
+ const allValues = ctx.columnMenuFacetValues;
173
+ const next = new Set(ctx.valueFilters[columnId] ?? allValues);
174
+ if (next.has(value))
175
+ next.delete(value);
176
+ else
177
+ next.add(value);
178
+ if (next.size === allValues.length) {
179
+ const copy = { ...ctx.valueFilters };
180
+ delete copy[columnId];
181
+ ctx.valueFilters = copy;
182
+ }
183
+ else {
184
+ ctx.valueFilters = { ...ctx.valueFilters, [columnId]: next };
185
+ }
186
+ }
187
+ function isAllFacetsChecked(columnId) {
188
+ const selected = ctx.valueFilters[columnId];
189
+ return !selected || selected.size >= ctx.columnMenuFacetValues.length;
190
+ }
191
+ function toggleAllFacets(columnId) {
192
+ if (isAllFacetsChecked(columnId)) {
193
+ ctx.valueFilters = { ...ctx.valueFilters, [columnId]: new Set() };
194
+ }
195
+ else {
196
+ const copy = { ...ctx.valueFilters };
197
+ delete copy[columnId];
198
+ ctx.valueFilters = copy;
199
+ }
200
+ }
201
+ function clearColumnFilter(columnId) {
202
+ if (ctx.valueFilters[columnId]) {
203
+ const next = { ...ctx.valueFilters };
204
+ delete next[columnId];
205
+ ctx.valueFilters = next;
206
+ }
207
+ if (ctx.filterMenuValues[columnId]) {
208
+ const next = { ...ctx.filterMenuValues };
209
+ delete next[columnId];
210
+ ctx.filterMenuValues = next;
211
+ }
212
+ if (ctx.filterRowValues[columnId]) {
213
+ const next = { ...ctx.filterRowValues };
214
+ delete next[columnId];
215
+ ctx.filterRowValues = next;
216
+ }
217
+ }
218
+ function changePage(delta) {
219
+ ctx.grid.setPagination((prev) => ({
220
+ ...prev,
221
+ pageIndex: Math.max((prev?.pageIndex ?? 0) + delta, 0),
222
+ }));
223
+ }
224
+ function goToPage(pageIndex) {
225
+ ctx.grid.setPagination((prev) => ({
226
+ ...prev,
227
+ pageIndex: Math.max(0, pageIndex),
228
+ }));
229
+ }
230
+ function setPageSize(pageSize) {
231
+ ctx.grid.setPagination((prev) => {
232
+ const oldSize = prev?.pageSize ?? 10;
233
+ const oldIndex = prev?.pageIndex ?? 0;
234
+ // Keep the first visible row in view when the page size changes.
235
+ const firstVisibleRow = oldIndex * oldSize;
236
+ return {
237
+ ...prev,
238
+ pageSize,
239
+ pageIndex: Math.max(0, Math.floor(firstVisibleRow / pageSize)),
240
+ };
241
+ });
242
+ }
243
+ function insertRowAt(t, offset) {
244
+ const data = ctx.internalData.slice();
245
+ const idx = t.row ? data.indexOf(t.row) : -1;
246
+ const at = idx < 0 ? data.length : idx + offset;
247
+ data.splice(at, 0, {});
248
+ ctx.internalData = data;
249
+ }
250
+ function removeRowAt(t) {
251
+ if (!t.row)
252
+ return;
253
+ ctx.internalData = ctx.internalData.filter((r) => r !== t.row);
254
+ }
255
+ function removeColAt(t) {
256
+ ctx.internalColumns = ctx.internalColumns.filter((d) => (d.id ?? d.field) !== t.columnId);
257
+ }
258
+ // Built-in items, keyed. `run` reads the live target passed at click time.
259
+ const builtins = {
260
+ copy: { label: "Copy", run: () => ctx.copySelectionToClipboard() },
261
+ cut: { label: "Cut", run: () => ctx.cutSelectionToClipboard() },
262
+ paste: { label: "Paste", run: () => void ctx.pasteFromClipboard() },
263
+ clear: { label: "Clear", run: () => ctx.clearSelectedCells() },
264
+ row_above: { label: "Insert row above", run: (t) => insertRowAt(t, 0) },
265
+ row_below: { label: "Insert row below", run: (t) => insertRowAt(t, 1) },
266
+ remove_row: { label: "Remove row", run: removeRowAt },
267
+ remove_col: { label: "Remove column", run: removeColAt },
268
+ comment: { label: "Edit comment", run: (t) => openCommentEditor(t) },
269
+ };
270
+ const DEFAULT_ITEMS = [
271
+ "copy", "cut", "paste", "clear", "separator",
272
+ "row_above", "row_below", "remove_row", "separator", "remove_col",
273
+ ];
274
+ function openContextMenu(event, rowIndex, colIndex, columnId) {
275
+ if (!ctx.props.contextMenu)
276
+ return;
277
+ event.preventDefault();
278
+ closeMenus();
279
+ ctx.contextMenuFor = null;
280
+ const rowModel = ctx.allRows[rowIndex];
281
+ const row = rowModel?.original ?? null;
282
+ const rowId = rowModel?.id ?? String(rowIndex);
283
+ ctx.contextMenuPos = {
284
+ x: clampMenuX(event.clientX, 220),
285
+ y: Math.max(8, Math.min(event.clientY, window.innerHeight - 16)),
286
+ };
287
+ ctx.contextMenuFor = { rowIndex, colIndex, columnId, rowId, row };
288
+ }
289
+ function closeContextMenu() {
290
+ ctx.contextMenuFor = null;
291
+ }
292
+ // ---- Editable comments ---------------------------------------------
293
+ function openCommentEditor(t) {
294
+ const cur = ctx.noteOverrides?.[t.rowId]?.[t.columnId] ??
295
+ ctx.props.notes?.[t.rowId]?.[t.columnId] ??
296
+ "";
297
+ ctx.commentDraft = cur;
298
+ ctx.commentEditFor = { rowId: t.rowId, columnId: t.columnId, x: ctx.contextMenuPos.x, y: ctx.contextMenuPos.y };
299
+ ctx.contextMenuFor = null;
300
+ }
301
+ function writeNote(rowId, columnId, note) {
302
+ const next = { ...ctx.noteOverrides };
303
+ next[rowId] = { ...(next[rowId] ?? {}), [columnId]: note };
304
+ ctx.noteOverrides = next;
305
+ ctx.props.onNoteChange?.({ rowId, columnId, note });
306
+ }
307
+ function saveComment() {
308
+ const e = ctx.commentEditFor;
309
+ if (!e)
310
+ return;
311
+ writeNote(e.rowId, e.columnId, ctx.commentDraft);
312
+ ctx.commentEditFor = null;
313
+ }
314
+ function removeComment() {
315
+ const e = ctx.commentEditFor;
316
+ if (!e)
317
+ return;
318
+ writeNote(e.rowId, e.columnId, "");
319
+ ctx.commentEditFor = null;
320
+ }
321
+ function closeCommentEditor() {
322
+ ctx.commentEditFor = null;
323
+ }
324
+ /** Resolve the configured items against the current target for rendering. */
325
+ function contextMenuItems() {
326
+ const target = ctx.contextMenuFor;
327
+ if (!target)
328
+ return [];
329
+ const cfg = ctx.props.contextMenu;
330
+ const entries = Array.isArray(cfg)
331
+ ? cfg
332
+ : [...DEFAULT_ITEMS, ...(ctx.props.editableComments ? ["separator", "comment"] : [])];
333
+ const out = [];
334
+ for (const entry of entries) {
335
+ if (entry === "separator") {
336
+ out.push({ key: "sep" + out.length, label: "", separator: true });
337
+ continue;
338
+ }
339
+ if (typeof entry === "string") {
340
+ const b = builtins[entry];
341
+ if (!b)
342
+ continue;
343
+ out.push({ key: entry, label: b.label, run: () => b.run(target) });
344
+ continue;
345
+ }
346
+ if (entry.hidden?.(target))
347
+ continue;
348
+ out.push({
349
+ key: entry.key,
350
+ label: entry.label,
351
+ disabled: entry.disabled?.(target) ?? false,
352
+ run: () => entry.action(target),
353
+ });
354
+ }
355
+ // Drop leading/trailing/double separators.
356
+ return out.filter((it, i, a) => !it.separator || (i > 0 && i < a.length - 1 && !a[i - 1]?.separator));
357
+ }
358
+ return {
359
+ updateFilterRow,
360
+ updateFilterOperator,
361
+ updateFilterMenuValue,
362
+ updateFilterMenuValueTo,
363
+ toggleCheckboxWithKeyboard,
364
+ isColumnFiltered,
365
+ closeMenus,
366
+ openChooseColumns,
367
+ openColumnMenu,
368
+ openFilterMenu,
369
+ openOperatorMenu,
370
+ sortColumnFromMenu,
371
+ clearColumnSort,
372
+ groupByColumnFromMenu,
373
+ clearGroupingFromMenu,
374
+ isFacetChecked,
375
+ toggleFacetValue,
376
+ isAllFacetsChecked,
377
+ toggleAllFacets,
378
+ clearColumnFilter,
379
+ changePage,
380
+ goToPage,
381
+ setPageSize,
382
+ openContextMenu,
383
+ closeContextMenu,
384
+ contextMenuItems,
385
+ saveComment,
386
+ removeComment,
387
+ closeCommentEditor,
388
+ };
389
+ }
@@ -40,3 +40,30 @@ export declare function localStorageViews(key: string): ViewStorage;
40
40
  export declare function createNamedViews(host: ViewStateHost, options?: {
41
41
  storage?: ViewStorage;
42
42
  }): NamedViews;
43
+ export type AutoSavedViewOptions = {
44
+ /** Slot name inside the NamedViews store. Default `'__autosave'`. */
45
+ name?: string;
46
+ /** Sample interval in ms. Default 800. */
47
+ intervalMs?: number;
48
+ /** Skip restore-on-mount (e.g. you already loaded a URL view first). */
49
+ skipRestore?: boolean;
50
+ };
51
+ /**
52
+ * Attach an "always-save-current-layout" slot to a `NamedViews` manager.
53
+ * Restores once on attach (if a saved view exists under `name`) and
54
+ * polls `host.getState()` thereafter, saving when the JSON snapshot
55
+ * changes.
56
+ *
57
+ * Returns a `detach()` that stops polling - call it from `onDestroy`.
58
+ *
59
+ * ```ts
60
+ * const views = createNamedViews(api, { storage: localStorageViews('myapp:views') })
61
+ * const off = attachAutoSavedView(api, views)
62
+ * onDestroy(off)
63
+ * ```
64
+ *
65
+ * Distinct from a user-saved named view: the slot is a single, fixed
66
+ * name reserved for "what the user left the page looking at." The user
67
+ * can still call `views.save('Q3 review')` etc. through the same store.
68
+ */
69
+ export declare function attachAutoSavedView(host: ViewStateHost, views: NamedViews, opts?: AutoSavedViewOptions): () => void;
@@ -78,3 +78,42 @@ export function createNamedViews(host, options = {}) {
78
78
  },
79
79
  };
80
80
  }
81
+ /**
82
+ * Attach an "always-save-current-layout" slot to a `NamedViews` manager.
83
+ * Restores once on attach (if a saved view exists under `name`) and
84
+ * polls `host.getState()` thereafter, saving when the JSON snapshot
85
+ * changes.
86
+ *
87
+ * Returns a `detach()` that stops polling - call it from `onDestroy`.
88
+ *
89
+ * ```ts
90
+ * const views = createNamedViews(api, { storage: localStorageViews('myapp:views') })
91
+ * const off = attachAutoSavedView(api, views)
92
+ * onDestroy(off)
93
+ * ```
94
+ *
95
+ * Distinct from a user-saved named view: the slot is a single, fixed
96
+ * name reserved for "what the user left the page looking at." The user
97
+ * can still call `views.save('Q3 review')` etc. through the same store.
98
+ */
99
+ export function attachAutoSavedView(host, views, opts = {}) {
100
+ const name = opts.name ?? '__autosave';
101
+ if (!opts.skipRestore && views.has(name))
102
+ views.load(name);
103
+ const interval = Math.max(100, opts.intervalMs ?? 800);
104
+ let last = JSON.stringify(host.getState());
105
+ const handle = setInterval(() => {
106
+ let next;
107
+ try {
108
+ next = JSON.stringify(host.getState());
109
+ }
110
+ catch {
111
+ return;
112
+ }
113
+ if (next === last)
114
+ return;
115
+ last = next;
116
+ views.save(name);
117
+ }, interval);
118
+ return () => clearInterval(handle);
119
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Row-resize Svelte action - drag the bottom edge of a row to grow /
3
+ * shrink it. Pair with a function-valued `rowHeight` prop so the grid
4
+ * reads per-row heights from a reactive store.
5
+ *
6
+ * The action is OFF until a consumer attaches it AND a row-header
7
+ * gutter cell exists in each row. A row-header cell is any TD with
8
+ * the `sv-row-gutter` class (typically the one rendering the row
9
+ * number 1, 2, 3, ...). Demos opt in by setting
10
+ * `cellClass: 'sv-row-gutter'` on the gutter column.
11
+ *
12
+ * <script>
13
+ * let heights = $state<Record<number, number>>({})
14
+ * let resizeOn = $state(false)
15
+ * const rowHeight = (i: number) => heights[i] ?? 32
16
+ * function onResize(i: number, h: number) { heights = { ...heights, [i]: h } }
17
+ * </script>
18
+ *
19
+ * <div use:rowResize={{ onResize, disabled: !resizeOn }}>
20
+ * <SvGrid columns={[{ field:'rn', cellClass:'sv-row-gutter', ... }, ...]}
21
+ * rowHeight={rowHeight} ... />
22
+ * </div>
23
+ *
24
+ * Visual: the strip sits along the bottom edge of the row-header
25
+ * cell, 5px tall, transparent by default, accent-tinted on hover -
26
+ * matching the column resize handle's look. Cursor is `row-resize`.
27
+ */
28
+ export type RowResizeOptions = {
29
+ /** Called when the user releases the drag with the final height. */
30
+ onResize: (rowIndex: number, height: number) => void;
31
+ /** Optional callback fired during the drag (every pointermove). */
32
+ onResizeMove?: (rowIndex: number, height: number) => void;
33
+ /** Min row height in px. Default 20. */
34
+ min?: number;
35
+ /** Max row height in px. Default 320. */
36
+ max?: number;
37
+ /** When true, the action removes its strips and ignores events. */
38
+ disabled?: boolean;
39
+ };
40
+ export declare function rowResize(node: HTMLElement, opts: RowResizeOptions): {
41
+ update(next: RowResizeOptions): void;
42
+ destroy(): void;
43
+ };
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Row-resize Svelte action - drag the bottom edge of a row to grow /
3
+ * shrink it. Pair with a function-valued `rowHeight` prop so the grid
4
+ * reads per-row heights from a reactive store.
5
+ *
6
+ * The action is OFF until a consumer attaches it AND a row-header
7
+ * gutter cell exists in each row. A row-header cell is any TD with
8
+ * the `sv-row-gutter` class (typically the one rendering the row
9
+ * number 1, 2, 3, ...). Demos opt in by setting
10
+ * `cellClass: 'sv-row-gutter'` on the gutter column.
11
+ *
12
+ * <script>
13
+ * let heights = $state<Record<number, number>>({})
14
+ * let resizeOn = $state(false)
15
+ * const rowHeight = (i: number) => heights[i] ?? 32
16
+ * function onResize(i: number, h: number) { heights = { ...heights, [i]: h } }
17
+ * </script>
18
+ *
19
+ * <div use:rowResize={{ onResize, disabled: !resizeOn }}>
20
+ * <SvGrid columns={[{ field:'rn', cellClass:'sv-row-gutter', ... }, ...]}
21
+ * rowHeight={rowHeight} ... />
22
+ * </div>
23
+ *
24
+ * Visual: the strip sits along the bottom edge of the row-header
25
+ * cell, 5px tall, transparent by default, accent-tinted on hover -
26
+ * matching the column resize handle's look. Cursor is `row-resize`.
27
+ */
28
+ const STRIP_CLASS = 'sv-grid-row-resize-handle';
29
+ export function rowResize(node, opts) {
30
+ let current = opts;
31
+ let drag = null;
32
+ function rowIndexOf(tr) {
33
+ const dataRow = tr.querySelector('[data-svgrid-row]');
34
+ const val = dataRow?.dataset.svgridRow;
35
+ return val != null ? Number(val) : NaN;
36
+ }
37
+ function onPointerMove(e) {
38
+ if (!drag)
39
+ return;
40
+ const min = current.min ?? 20;
41
+ const max = current.max ?? 320;
42
+ const next = Math.max(min, Math.min(max, drag.startHeight + (e.clientY - drag.startY)));
43
+ drag.trEl.style.height = `${Math.round(next)}px`;
44
+ current.onResizeMove?.(drag.rowIndex, Math.round(next));
45
+ }
46
+ function onPointerUp(e) {
47
+ if (!drag)
48
+ return;
49
+ const min = current.min ?? 20;
50
+ const max = current.max ?? 320;
51
+ const next = Math.max(min, Math.min(max, drag.startHeight + (e.clientY - drag.startY)));
52
+ current.onResize(drag.rowIndex, Math.round(next));
53
+ drag.strip.classList.remove('is-resizing');
54
+ try {
55
+ drag.trEl.releasePointerCapture(e.pointerId);
56
+ }
57
+ catch { /* ignore */ }
58
+ drag = null;
59
+ window.removeEventListener('pointermove', onPointerMove);
60
+ window.removeEventListener('pointerup', onPointerUp);
61
+ document.body.style.cursor = '';
62
+ }
63
+ function onPointerDown(e) {
64
+ if (current.disabled)
65
+ return;
66
+ const t = e.target;
67
+ if (!t?.classList.contains(STRIP_CLASS))
68
+ return;
69
+ const tr = t.closest('tr.sv-grid-row');
70
+ if (!tr)
71
+ return;
72
+ const rowIndex = rowIndexOf(tr);
73
+ if (!Number.isFinite(rowIndex))
74
+ return;
75
+ e.preventDefault();
76
+ e.stopPropagation();
77
+ t.classList.add('is-resizing');
78
+ drag = {
79
+ rowIndex,
80
+ startY: e.clientY,
81
+ startHeight: tr.getBoundingClientRect().height,
82
+ trEl: tr,
83
+ strip: t,
84
+ };
85
+ try {
86
+ tr.setPointerCapture(e.pointerId);
87
+ }
88
+ catch { /* ignore */ }
89
+ document.body.style.cursor = 'row-resize';
90
+ window.addEventListener('pointermove', onPointerMove);
91
+ window.addEventListener('pointerup', onPointerUp);
92
+ }
93
+ /** Inject one strip into every row's gutter cell. When disabled or
94
+ * when a row lacks a `.sv-row-gutter` cell, no strip is added. */
95
+ function decorate() {
96
+ if (current.disabled) {
97
+ removeAllStrips();
98
+ return;
99
+ }
100
+ const rows = node.querySelectorAll('tr.sv-grid-row');
101
+ for (const tr of rows) {
102
+ if (tr.classList.contains('sv-grid-header-row'))
103
+ continue;
104
+ if (tr.classList.contains('sv-grid-row-spacer'))
105
+ continue;
106
+ const gutter = tr.querySelector('.sv-grid-cell.sv-row-gutter');
107
+ if (!gutter)
108
+ continue;
109
+ if (gutter.querySelector(`:scope > .${STRIP_CLASS}`))
110
+ continue;
111
+ // Anchor the strip to the gutter cell + allow it to overflow
112
+ // downward into the row gap so the hit-area straddles the
113
+ // row boundary the way Excel does.
114
+ if (getComputedStyle(gutter).position === 'static')
115
+ gutter.style.position = 'relative';
116
+ gutter.style.overflow = 'visible';
117
+ const strip = document.createElement('div');
118
+ strip.className = STRIP_CLASS;
119
+ strip.setAttribute('role', 'separator');
120
+ strip.setAttribute('aria-orientation', 'horizontal');
121
+ strip.setAttribute('aria-label', 'Resize row');
122
+ // Inline the geometry + pointer-events so the strip works even
123
+ // before SvGrid.css is parsed; the hover tint still comes from
124
+ // the stylesheet. We keep the strip fully inside the gutter
125
+ // cell (no negative offset) to avoid stacking-context surprises
126
+ // with pinned / virtualised neighbour cells.
127
+ // 5px tall + sitting flush with the row bottom matches the
128
+ // column resize handle's 5px width.
129
+ strip.style.cssText =
130
+ 'position:absolute;left:0;right:0;bottom:0;height:5px;' +
131
+ 'cursor:row-resize;user-select:none;z-index:60;pointer-events:auto;';
132
+ gutter.appendChild(strip);
133
+ }
134
+ }
135
+ function removeAllStrips() {
136
+ node.querySelectorAll(`.${STRIP_CLASS}`).forEach((el) => el.remove());
137
+ }
138
+ node.addEventListener('pointerdown', onPointerDown, { capture: true });
139
+ const observer = new MutationObserver(() => decorate());
140
+ observer.observe(node, { childList: true, subtree: true });
141
+ decorate();
142
+ return {
143
+ update(next) {
144
+ const wasDisabled = current.disabled;
145
+ current = next;
146
+ // Toggle: when going from enabled <-> disabled, repaint immediately.
147
+ if (wasDisabled !== current.disabled)
148
+ decorate();
149
+ },
150
+ destroy() {
151
+ node.removeEventListener('pointerdown', onPointerDown, { capture: true });
152
+ window.removeEventListener('pointermove', onPointerMove);
153
+ window.removeEventListener('pointerup', onPointerUp);
154
+ observer.disconnect();
155
+ removeAllStrips();
156
+ },
157
+ };
158
+ }
@@ -0,0 +1,9 @@
1
+ import { type RowData, type TableFeatures } from "./index";
2
+ import "./sv-grid-scrollbar";
3
+ export declare function createScrollSync<TFeatures extends TableFeatures = TableFeatures, TData extends RowData = RowData>(ctx: any): {
4
+ showTooltipFor: (el: HTMLElement, text: string) => void;
5
+ hideTooltip: () => void;
6
+ flushScheduledScrollSync: () => void;
7
+ scheduleScrollSync: (scrollTop: number, scrollLeft: number) => void;
8
+ onBodyScroll: (event: Event) => void;
9
+ };