@svgrid/grid 1.0.2 → 1.1.1

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 (216) 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 +648 -0
  6. package/dist/GridMenus.svelte.d.ts +31 -0
  7. package/dist/SvGrid.controller.svelte.d.ts +472 -0
  8. package/dist/SvGrid.controller.svelte.js +1917 -0
  9. package/dist/SvGrid.css +2012 -0
  10. package/dist/SvGrid.helpers.d.ts +35 -0
  11. package/dist/SvGrid.helpers.js +160 -0
  12. package/dist/SvGrid.helpers.test.d.ts +1 -0
  13. package/dist/SvGrid.helpers.test.js +298 -0
  14. package/dist/SvGrid.svelte +2346 -8742
  15. package/dist/SvGrid.svelte.d.ts +4 -357
  16. package/dist/SvGrid.types.d.ts +523 -0
  17. package/dist/SvGrid.types.js +1 -0
  18. package/dist/SvGridChart.svelte +1060 -23
  19. package/dist/SvGridChart.svelte.d.ts +17 -0
  20. package/dist/aligned-grids.d.ts +6 -0
  21. package/dist/aligned-grids.js +84 -0
  22. package/dist/aligned-grids.test.d.ts +1 -0
  23. package/dist/aligned-grids.test.js +75 -0
  24. package/dist/build-api.coverage.test.d.ts +20 -0
  25. package/dist/build-api.coverage.test.js +505 -0
  26. package/dist/build-api.d.ts +5 -0
  27. package/dist/build-api.js +557 -0
  28. package/dist/cell-render.d.ts +15 -0
  29. package/dist/cell-render.js +246 -0
  30. package/dist/cell-render.test.d.ts +1 -0
  31. package/dist/cell-render.test.js +338 -0
  32. package/dist/cell-values.d.ts +28 -0
  33. package/dist/cell-values.js +89 -0
  34. package/dist/chart-export.test.d.ts +1 -0
  35. package/dist/chart-export.test.js +302 -0
  36. package/dist/chart.coverage.test.d.ts +1 -0
  37. package/dist/chart.coverage.test.js +748 -0
  38. package/dist/chart.d.ts +370 -3
  39. package/dist/chart.js +1135 -42
  40. package/dist/clipboard.d.ts +15 -0
  41. package/dist/clipboard.js +420 -0
  42. package/dist/clipboard.test.d.ts +1 -0
  43. package/dist/clipboard.test.js +700 -0
  44. package/dist/collaboration.coverage.test.d.ts +1 -0
  45. package/dist/collaboration.coverage.test.js +200 -0
  46. package/dist/column-groups.d.ts +19 -0
  47. package/dist/column-groups.js +62 -0
  48. package/dist/column-groups.test.d.ts +1 -0
  49. package/dist/column-groups.test.js +56 -0
  50. package/dist/column-types.d.ts +10 -0
  51. package/dist/column-types.js +63 -0
  52. package/dist/column-types.test.d.ts +1 -0
  53. package/dist/column-types.test.js +62 -0
  54. package/dist/columns.d.ts +30 -0
  55. package/dist/columns.js +277 -0
  56. package/dist/columns.test.d.ts +1 -0
  57. package/dist/columns.test.js +625 -0
  58. package/dist/core.d.ts +86 -1
  59. package/dist/css.d.ts +3 -0
  60. package/dist/editing.d.ts +31 -0
  61. package/dist/editing.js +529 -0
  62. package/dist/editing.test.d.ts +1 -0
  63. package/dist/editing.test.js +732 -0
  64. package/dist/editors/cell-editors.coverage.test.d.ts +1 -0
  65. package/dist/editors/cell-editors.coverage.test.js +139 -0
  66. package/dist/editors/cell-editors.d.ts +1 -1
  67. package/dist/facet-buckets.d.ts +13 -0
  68. package/dist/facet-buckets.js +54 -0
  69. package/dist/facet-buckets.test.d.ts +1 -0
  70. package/dist/facet-buckets.test.js +296 -0
  71. package/dist/features.d.ts +5 -0
  72. package/dist/features.js +30 -0
  73. package/dist/filter-operators.d.ts +16 -0
  74. package/dist/filter-operators.js +69 -0
  75. package/dist/filter-operators.test.d.ts +1 -0
  76. package/dist/filter-operators.test.js +135 -0
  77. package/dist/hyperformula-adapter.d.ts +82 -0
  78. package/dist/hyperformula-adapter.js +73 -0
  79. package/dist/hyperformula-adapter.test.d.ts +1 -0
  80. package/dist/hyperformula-adapter.test.js +205 -0
  81. package/dist/index.d.ts +9 -3
  82. package/dist/index.js +8 -2
  83. package/dist/keyboard-handlers.coverage.test.d.ts +1 -0
  84. package/dist/keyboard-handlers.coverage.test.js +495 -0
  85. package/dist/keyboard-handlers.d.ts +7 -0
  86. package/dist/keyboard-handlers.js +202 -0
  87. package/dist/menus.d.ts +40 -0
  88. package/dist/menus.js +390 -0
  89. package/dist/menus.test.d.ts +1 -0
  90. package/dist/menus.test.js +560 -0
  91. package/dist/named-views.coverage.test.d.ts +1 -0
  92. package/dist/named-views.coverage.test.js +180 -0
  93. package/dist/named-views.d.ts +27 -0
  94. package/dist/named-views.js +39 -0
  95. package/dist/row-drag.d.ts +49 -0
  96. package/dist/row-drag.js +221 -0
  97. package/dist/row-drag.test.d.ts +1 -0
  98. package/dist/row-drag.test.js +142 -0
  99. package/dist/row-resize.d.ts +43 -0
  100. package/dist/row-resize.js +158 -0
  101. package/dist/row-resize.test.d.ts +1 -0
  102. package/dist/row-resize.test.js +329 -0
  103. package/dist/scroll-sync.d.ts +9 -0
  104. package/dist/scroll-sync.js +89 -0
  105. package/dist/scroll-sync.test.d.ts +1 -0
  106. package/dist/scroll-sync.test.js +290 -0
  107. package/dist/selection.d.ts +32 -0
  108. package/dist/selection.js +427 -0
  109. package/dist/selection.multi-range.test.d.ts +1 -0
  110. package/dist/selection.multi-range.test.js +55 -0
  111. package/dist/selection.test.d.ts +1 -0
  112. package/dist/selection.test.js +647 -0
  113. package/dist/server-data-source.coverage.test.d.ts +1 -0
  114. package/dist/server-data-source.coverage.test.js +154 -0
  115. package/dist/spreadsheet.d.ts +110 -0
  116. package/dist/spreadsheet.js +242 -0
  117. package/dist/spreadsheet.test.d.ts +1 -0
  118. package/dist/spreadsheet.test.js +446 -0
  119. package/dist/summaries.d.ts +12 -0
  120. package/dist/summaries.js +65 -0
  121. package/dist/sv-grid-scrollbar.js +13 -1
  122. package/dist/svgrid-wrapper.types.d.ts +31 -1
  123. package/dist/svgrid.behavior.test.js +20 -0
  124. package/dist/svgrid.comments-autocomplete.test.d.ts +1 -0
  125. package/dist/svgrid.comments-autocomplete.test.js +96 -0
  126. package/dist/svgrid.context-menu.test.d.ts +1 -0
  127. package/dist/svgrid.context-menu.test.js +102 -0
  128. package/dist/svgrid.interaction.test.js +31 -0
  129. package/dist/svgrid.new-features.wrapper.test.js +64 -6
  130. package/dist/svgrid.wrapper.test.js +27 -1
  131. package/dist/test-setup.js +9 -3
  132. package/dist/virtualization/column-virtualizer.d.ts +2 -0
  133. package/dist/virtualization/scroll-scaling.d.ts +45 -0
  134. package/dist/virtualization/scroll-scaling.js +99 -0
  135. package/dist/virtualization/scroll-scaling.test.d.ts +1 -0
  136. package/dist/virtualization/scroll-scaling.test.js +127 -0
  137. package/dist/virtualization/svelte-virtualizer.svelte.d.ts +2 -0
  138. package/dist/virtualization/svelte-virtualizer.svelte.js +2 -0
  139. package/dist/virtualization/virtualizer.d.ts +7 -0
  140. package/dist/virtualization/virtualizer.js +30 -0
  141. package/package.json +2 -1
  142. package/src/GridFooter.svelte +164 -0
  143. package/src/GridMenus.svelte +648 -0
  144. package/src/SvGrid.controller.svelte.ts +2352 -0
  145. package/src/SvGrid.css +2012 -0
  146. package/src/SvGrid.helpers.test.ts +415 -0
  147. package/src/SvGrid.helpers.ts +185 -0
  148. package/src/SvGrid.svelte +2346 -8742
  149. package/src/SvGrid.types.ts +537 -0
  150. package/src/SvGridChart.svelte +1060 -23
  151. package/src/aligned-grids.test.ts +80 -0
  152. package/src/aligned-grids.ts +87 -0
  153. package/src/build-api.coverage.test.ts +532 -0
  154. package/src/build-api.ts +683 -0
  155. package/src/cell-render.test.ts +451 -0
  156. package/src/cell-render.ts +426 -0
  157. package/src/cell-values.ts +114 -0
  158. package/src/chart-export.test.ts +370 -0
  159. package/src/chart.coverage.test.ts +814 -0
  160. package/src/chart.ts +1352 -47
  161. package/src/clipboard.test.ts +780 -0
  162. package/src/clipboard.ts +552 -0
  163. package/src/collaboration.coverage.test.ts +220 -0
  164. package/src/column-groups.test.ts +59 -0
  165. package/src/column-groups.ts +80 -0
  166. package/src/column-types.test.ts +68 -0
  167. package/src/column-types.ts +82 -0
  168. package/src/columns.test.ts +702 -0
  169. package/src/columns.ts +419 -0
  170. package/src/core.ts +86 -0
  171. package/src/css.d.ts +3 -0
  172. package/src/editing.test.ts +837 -0
  173. package/src/editing.ts +669 -0
  174. package/src/editors/cell-editors.coverage.test.ts +156 -0
  175. package/src/editors/cell-editors.ts +1 -0
  176. package/src/facet-buckets.test.ts +353 -0
  177. package/src/facet-buckets.ts +67 -0
  178. package/src/features.ts +128 -0
  179. package/src/filter-operators.test.ts +174 -0
  180. package/src/filter-operators.ts +87 -0
  181. package/src/hyperformula-adapter.test.ts +256 -0
  182. package/src/hyperformula-adapter.ts +124 -0
  183. package/src/index.ts +49 -0
  184. package/src/keyboard-handlers.coverage.test.ts +560 -0
  185. package/src/keyboard-handlers.ts +353 -0
  186. package/src/keyboard.ts +97 -97
  187. package/src/menus.test.ts +620 -0
  188. package/src/menus.ts +555 -0
  189. package/src/named-views.coverage.test.ts +210 -0
  190. package/src/named-views.ts +48 -0
  191. package/src/row-drag.test.ts +168 -0
  192. package/src/row-drag.ts +255 -0
  193. package/src/row-resize.test.ts +369 -0
  194. package/src/row-resize.ts +171 -0
  195. package/src/scroll-sync.test.ts +330 -0
  196. package/src/scroll-sync.ts +218 -0
  197. package/src/selection.multi-range.test.ts +61 -0
  198. package/src/selection.test.ts +722 -0
  199. package/src/selection.ts +579 -0
  200. package/src/server-data-source.coverage.test.ts +180 -0
  201. package/src/spreadsheet.test.ts +489 -0
  202. package/src/spreadsheet.ts +304 -0
  203. package/src/summaries.ts +204 -0
  204. package/src/sv-grid-scrollbar.ts +13 -1
  205. package/src/svgrid-wrapper.types.ts +31 -1
  206. package/src/svgrid.behavior.test.ts +22 -0
  207. package/src/svgrid.comments-autocomplete.test.ts +112 -0
  208. package/src/svgrid.context-menu.test.ts +126 -0
  209. package/src/svgrid.interaction.test.ts +30 -0
  210. package/src/svgrid.new-features.wrapper.test.ts +67 -6
  211. package/src/svgrid.wrapper.test.ts +27 -1
  212. package/src/test-setup.ts +9 -6
  213. package/src/virtualization/scroll-scaling.test.ts +148 -0
  214. package/src/virtualization/scroll-scaling.ts +121 -0
  215. package/src/virtualization/svelte-virtualizer.svelte.ts +2 -0
  216. package/src/virtualization/virtualizer.ts +26 -0
@@ -0,0 +1,446 @@
1
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2
+ import { spreadsheetLayout, spansToMerges } from './spreadsheet';
3
+ // jsdom does not implement the global `CSS` object, which `findCell` uses via
4
+ // `CSS.escape`. Provide a minimal polyfill so the action's selector queries
5
+ // run. (A real browser ships CSS.escape; this is purely an env gap.)
6
+ if (typeof globalThis.CSS === 'undefined') {
7
+ // @ts-expect-error - minimal shim for the test environment
8
+ globalThis.CSS = { escape: (s) => s.replace(/["\\]/g, '\\$&') };
9
+ }
10
+ else if (typeof globalThis.CSS.escape !== 'function') {
11
+ // @ts-expect-error - augment partial CSS object
12
+ globalThis.CSS.escape = (s) => s.replace(/["\\]/g, '\\$&');
13
+ }
14
+ // ---------------------------------------------------------------------------
15
+ // Helpers
16
+ // ---------------------------------------------------------------------------
17
+ /** Flush a queued requestAnimationFrame callback. The action batches its
18
+ * work into one rAF, so tests must advance a frame to observe the effect. */
19
+ function flushFrame() {
20
+ return new Promise((resolve) => {
21
+ // Two rAFs: the first lets any already-queued callback run, the second
22
+ // guarantees we resolve AFTER that callback has executed.
23
+ requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
24
+ });
25
+ }
26
+ /** Build a `<table>` with a header-less body of `rows` x `cols`. Each TD is
27
+ * tagged with `data-svgrid-row` (display index) + `data-col-id` exactly the
28
+ * way SvGrid emits them, which is what the layout helper queries on. */
29
+ function buildGrid(rows, columnOrder) {
30
+ const host = document.createElement('div');
31
+ const table = document.createElement('table');
32
+ const tbody = document.createElement('tbody');
33
+ for (let r = 0; r < rows; r += 1) {
34
+ const tr = document.createElement('tr');
35
+ for (const colId of columnOrder) {
36
+ const td = document.createElement('td');
37
+ td.setAttribute('data-svgrid-row', String(r));
38
+ td.setAttribute('data-col-id', colId);
39
+ td.textContent = `${colId}-${r}`;
40
+ tr.appendChild(td);
41
+ }
42
+ tbody.appendChild(tr);
43
+ }
44
+ table.appendChild(tbody);
45
+ host.appendChild(table);
46
+ document.body.appendChild(host);
47
+ const cellAt = (r, colId) => {
48
+ const el = host.querySelector(`td[data-svgrid-row="${r}"][data-col-id="${colId}"]`);
49
+ if (!el)
50
+ throw new Error(`no cell at row=${r} col=${colId}`);
51
+ return el;
52
+ };
53
+ return { host, cellAt };
54
+ }
55
+ let hosts = [];
56
+ function track(host) {
57
+ hosts.push(host);
58
+ return host;
59
+ }
60
+ beforeEach(() => {
61
+ hosts = [];
62
+ });
63
+ afterEach(() => {
64
+ for (const h of hosts)
65
+ h.remove();
66
+ document.body.innerHTML = '';
67
+ });
68
+ // ---------------------------------------------------------------------------
69
+ // Merges
70
+ // ---------------------------------------------------------------------------
71
+ describe('spreadsheetLayout - merges', () => {
72
+ it('applies colspan + hides covered cells horizontally', async () => {
73
+ const cols = ['a', 'b', 'c'];
74
+ const { host, cellAt } = buildGrid(2, cols);
75
+ track(host);
76
+ const action = spreadsheetLayout(host, {
77
+ columnOrder: cols,
78
+ merges: [{ rowIndex: 0, columnId: 'a', colspan: 2 }],
79
+ });
80
+ await flushFrame();
81
+ const origin = cellAt(0, 'a');
82
+ expect(origin.getAttribute('colspan')).toBe('2');
83
+ expect(origin.hasAttribute('rowspan')).toBe(false);
84
+ expect(origin.getAttribute('data-svgrid-sheet')).toBe('');
85
+ // Covered neighbour to the right is hidden + marked.
86
+ expect(cellAt(0, 'b').style.display).toBe('none');
87
+ expect(cellAt(0, 'b').getAttribute('data-svgrid-sheet')).toBe('');
88
+ // Untouched cells stay visible.
89
+ expect(cellAt(0, 'c').style.display).toBe('');
90
+ expect(cellAt(1, 'a').style.display).toBe('');
91
+ action.destroy();
92
+ });
93
+ it('applies rowspan + hides covered cells vertically', async () => {
94
+ const cols = ['a', 'b'];
95
+ const { host, cellAt } = buildGrid(3, cols);
96
+ track(host);
97
+ const action = spreadsheetLayout(host, {
98
+ columnOrder: cols,
99
+ merges: [{ rowIndex: 0, columnId: 'a', rowspan: 2 }],
100
+ });
101
+ await flushFrame();
102
+ const origin = cellAt(0, 'a');
103
+ expect(origin.getAttribute('rowspan')).toBe('2');
104
+ expect(origin.hasAttribute('colspan')).toBe(false);
105
+ expect(cellAt(1, 'a').style.display).toBe('none');
106
+ expect(cellAt(2, 'a').style.display).toBe(''); // outside the span
107
+ action.destroy();
108
+ });
109
+ it('handles a rectangular colspan + rowspan block', async () => {
110
+ const cols = ['a', 'b', 'c'];
111
+ const { host, cellAt } = buildGrid(3, cols);
112
+ track(host);
113
+ const action = spreadsheetLayout(host, {
114
+ columnOrder: cols,
115
+ merges: [{ rowIndex: 0, columnId: 'a', colspan: 2, rowspan: 2 }],
116
+ });
117
+ await flushFrame();
118
+ expect(cellAt(0, 'a').getAttribute('colspan')).toBe('2');
119
+ expect(cellAt(0, 'a').getAttribute('rowspan')).toBe('2');
120
+ // All covered cells except the origin are hidden.
121
+ expect(cellAt(0, 'b').style.display).toBe('none');
122
+ expect(cellAt(1, 'a').style.display).toBe('none');
123
+ expect(cellAt(1, 'b').style.display).toBe('none');
124
+ // c column + row 2 untouched.
125
+ expect(cellAt(0, 'c').style.display).toBe('');
126
+ expect(cellAt(2, 'a').style.display).toBe('');
127
+ action.destroy();
128
+ });
129
+ it('clamps zero/negative span to a minimum of 1 (no colspan/rowspan attr)', async () => {
130
+ const cols = ['a', 'b'];
131
+ const { host, cellAt } = buildGrid(2, cols);
132
+ track(host);
133
+ const action = spreadsheetLayout(host, {
134
+ columnOrder: cols,
135
+ merges: [{ rowIndex: 0, columnId: 'a', colspan: 0, rowspan: -5 }],
136
+ });
137
+ await flushFrame();
138
+ const origin = cellAt(0, 'a');
139
+ // Clamped to 1, so no span attributes are written, but it is still marked.
140
+ expect(origin.hasAttribute('colspan')).toBe(false);
141
+ expect(origin.hasAttribute('rowspan')).toBe(false);
142
+ expect(origin.getAttribute('data-svgrid-sheet')).toBe('');
143
+ expect(cellAt(0, 'b').style.display).toBe(''); // nothing covered
144
+ action.destroy();
145
+ });
146
+ it('skips a merge whose columnId is not in columnOrder', async () => {
147
+ const cols = ['a', 'b'];
148
+ const { host, cellAt } = buildGrid(1, cols);
149
+ track(host);
150
+ const action = spreadsheetLayout(host, {
151
+ columnOrder: cols,
152
+ merges: [{ rowIndex: 0, columnId: 'ghost', colspan: 2 }],
153
+ });
154
+ await flushFrame();
155
+ expect(cellAt(0, 'a').hasAttribute('data-svgrid-sheet')).toBe(false);
156
+ expect(cellAt(0, 'b').style.display).toBe('');
157
+ action.destroy();
158
+ });
159
+ it('skips a merge whose origin cell is not rendered', async () => {
160
+ const cols = ['a', 'b'];
161
+ const { host, cellAt } = buildGrid(1, cols);
162
+ track(host);
163
+ const action = spreadsheetLayout(host, {
164
+ columnOrder: cols,
165
+ merges: [{ rowIndex: 99, columnId: 'a', colspan: 2 }],
166
+ });
167
+ await flushFrame();
168
+ // Nothing marked anywhere.
169
+ expect(host.querySelectorAll('[data-svgrid-sheet]').length).toBe(0);
170
+ expect(cellAt(0, 'a').style.display).toBe('');
171
+ action.destroy();
172
+ });
173
+ it('ignores covered cells that fall outside the columnOrder or render window', async () => {
174
+ const cols = ['a', 'b'];
175
+ // Only 1 row rendered, but ask for a colspan that runs off the column
176
+ // list AND a rowspan that runs off the rendered rows.
177
+ const { host, cellAt } = buildGrid(1, cols);
178
+ track(host);
179
+ const action = spreadsheetLayout(host, {
180
+ columnOrder: cols,
181
+ merges: [{ rowIndex: 0, columnId: 'b', colspan: 3, rowspan: 3 }],
182
+ });
183
+ await flushFrame();
184
+ const origin = cellAt(0, 'b');
185
+ expect(origin.getAttribute('colspan')).toBe('3');
186
+ expect(origin.getAttribute('rowspan')).toBe('3');
187
+ // No sibling to the right of b, and rows 1/2 don't exist - so the only
188
+ // marked cell is the origin itself.
189
+ expect(host.querySelectorAll('[data-svgrid-sheet]').length).toBe(1);
190
+ action.destroy();
191
+ });
192
+ });
193
+ // ---------------------------------------------------------------------------
194
+ // Selection-edge inheritance
195
+ // ---------------------------------------------------------------------------
196
+ describe('spreadsheetLayout - selection edge inheritance', () => {
197
+ it('mirrors range-right / range-bottom / selected-range flags onto the origin', async () => {
198
+ const cols = ['a', 'b'];
199
+ const { host, cellAt } = buildGrid(2, cols);
200
+ track(host);
201
+ // Mark the far covered cell with range edge flags BEFORE applying.
202
+ cellAt(1, 'b').setAttribute('data-range-right', 'true');
203
+ cellAt(1, 'b').setAttribute('data-range-bottom', 'true');
204
+ cellAt(0, 'b').setAttribute('data-selected-range', 'true');
205
+ const action = spreadsheetLayout(host, {
206
+ columnOrder: cols,
207
+ merges: [{ rowIndex: 0, columnId: 'a', colspan: 2, rowspan: 2 }],
208
+ });
209
+ await flushFrame();
210
+ const origin = cellAt(0, 'a');
211
+ expect(origin.classList.contains('sv-merge-edge-right')).toBe(true);
212
+ expect(origin.classList.contains('sv-merge-edge-bottom')).toBe(true);
213
+ expect(origin.classList.contains('sv-merge-in-range')).toBe(true);
214
+ action.destroy();
215
+ });
216
+ it('leaves edge classes off when no range flags are present', async () => {
217
+ const cols = ['a', 'b'];
218
+ const { host, cellAt } = buildGrid(2, cols);
219
+ track(host);
220
+ const action = spreadsheetLayout(host, {
221
+ columnOrder: cols,
222
+ merges: [{ rowIndex: 0, columnId: 'a', colspan: 2, rowspan: 2 }],
223
+ });
224
+ await flushFrame();
225
+ const origin = cellAt(0, 'a');
226
+ expect(origin.classList.contains('sv-merge-edge-right')).toBe(false);
227
+ expect(origin.classList.contains('sv-merge-edge-bottom')).toBe(false);
228
+ expect(origin.classList.contains('sv-merge-in-range')).toBe(false);
229
+ action.destroy();
230
+ });
231
+ it('treats the origin own selected-range flag as in-range', async () => {
232
+ const cols = ['a'];
233
+ const { host, cellAt } = buildGrid(1, cols);
234
+ track(host);
235
+ cellAt(0, 'a').setAttribute('data-selected-range', 'true');
236
+ const action = spreadsheetLayout(host, {
237
+ columnOrder: cols,
238
+ merges: [{ rowIndex: 0, columnId: 'a' }],
239
+ });
240
+ await flushFrame();
241
+ expect(cellAt(0, 'a').classList.contains('sv-merge-in-range')).toBe(true);
242
+ action.destroy();
243
+ });
244
+ });
245
+ // ---------------------------------------------------------------------------
246
+ // Borders
247
+ // ---------------------------------------------------------------------------
248
+ describe('spreadsheetLayout - borders', () => {
249
+ it('injects an overlay with the requested edge styles', async () => {
250
+ const cols = ['a'];
251
+ const { host, cellAt } = buildGrid(1, cols);
252
+ track(host);
253
+ const action = spreadsheetLayout(host, {
254
+ columnOrder: cols,
255
+ borders: [
256
+ {
257
+ rowIndex: 0,
258
+ columnId: 'a',
259
+ top: { width: 3, style: 'dashed', color: 'red' },
260
+ bottom: {}, // defaults: 2px solid currentColor
261
+ },
262
+ ],
263
+ });
264
+ await flushFrame();
265
+ const td = cellAt(0, 'a');
266
+ const overlay = td.querySelector('.sv-cell-border-overlay');
267
+ expect(overlay).not.toBeNull();
268
+ expect(overlay.style.borderTop).toBe('3px dashed red');
269
+ // jsdom's CSSOM drops the `currentColor` keyword from the border
270
+ // shorthand, but the width + style survive, confirming the default
271
+ // (2px solid) edge was emitted.
272
+ expect(overlay.style.borderBottom).toContain('2px solid');
273
+ // No left/right set.
274
+ expect(overlay.style.borderLeft).toBe('');
275
+ expect(td.getAttribute('data-svgrid-sheet')).toBe('');
276
+ // The TD becomes a positioning context.
277
+ expect(td.style.position).toBe('relative');
278
+ action.destroy();
279
+ });
280
+ it('skips a border spec with no edges set (no overlay injected)', async () => {
281
+ const cols = ['a'];
282
+ const { host, cellAt } = buildGrid(1, cols);
283
+ track(host);
284
+ const action = spreadsheetLayout(host, {
285
+ columnOrder: cols,
286
+ borders: [{ rowIndex: 0, columnId: 'a' }],
287
+ });
288
+ await flushFrame();
289
+ expect(cellAt(0, 'a').querySelector('.sv-cell-border-overlay')).toBeNull();
290
+ expect(cellAt(0, 'a').hasAttribute('data-svgrid-sheet')).toBe(false);
291
+ action.destroy();
292
+ });
293
+ it('skips a border spec whose target cell is absent', async () => {
294
+ const cols = ['a'];
295
+ const { host } = buildGrid(1, cols);
296
+ track(host);
297
+ const action = spreadsheetLayout(host, {
298
+ columnOrder: cols,
299
+ borders: [{ rowIndex: 5, columnId: 'a', top: { width: 1 } }],
300
+ });
301
+ await flushFrame();
302
+ expect(host.querySelectorAll('.sv-cell-border-overlay').length).toBe(0);
303
+ action.destroy();
304
+ });
305
+ it('does not override an already-positioned TD', async () => {
306
+ const cols = ['a'];
307
+ const { host, cellAt } = buildGrid(1, cols);
308
+ track(host);
309
+ cellAt(0, 'a').style.position = 'absolute';
310
+ const action = spreadsheetLayout(host, {
311
+ columnOrder: cols,
312
+ borders: [{ rowIndex: 0, columnId: 'a', left: { color: 'blue' } }],
313
+ });
314
+ await flushFrame();
315
+ expect(cellAt(0, 'a').style.position).toBe('absolute');
316
+ action.destroy();
317
+ });
318
+ });
319
+ // ---------------------------------------------------------------------------
320
+ // Cleanup + update + destroy
321
+ // ---------------------------------------------------------------------------
322
+ describe('spreadsheetLayout - update + cleanup', () => {
323
+ it('clears prior decorations on the next apply (update path)', async () => {
324
+ const cols = ['a', 'b'];
325
+ const { host, cellAt } = buildGrid(2, cols);
326
+ track(host);
327
+ const action = spreadsheetLayout(host, {
328
+ columnOrder: cols,
329
+ merges: [{ rowIndex: 0, columnId: 'a', colspan: 2 }],
330
+ borders: [{ rowIndex: 1, columnId: 'a', top: { width: 1 } }],
331
+ });
332
+ await flushFrame();
333
+ expect(cellAt(0, 'a').getAttribute('colspan')).toBe('2');
334
+ expect(cellAt(1, 'a').querySelector('.sv-cell-border-overlay')).not.toBeNull();
335
+ // Update to an empty spec - everything from the previous run is removed.
336
+ action.update({ columnOrder: cols, merges: [], borders: [] });
337
+ await flushFrame();
338
+ expect(cellAt(0, 'a').hasAttribute('colspan')).toBe(false);
339
+ expect(cellAt(0, 'b').style.display).toBe('');
340
+ expect(cellAt(0, 'a').hasAttribute('data-svgrid-sheet')).toBe(false);
341
+ expect(cellAt(1, 'a').querySelector('.sv-cell-border-overlay')).toBeNull();
342
+ action.destroy();
343
+ });
344
+ it('re-applies decorations when the grid body mutates (MutationObserver)', async () => {
345
+ const cols = ['a', 'b'];
346
+ const { host, cellAt } = buildGrid(1, cols);
347
+ track(host);
348
+ const action = spreadsheetLayout(host, {
349
+ columnOrder: cols,
350
+ merges: [{ rowIndex: 1, columnId: 'a', colspan: 2 }],
351
+ });
352
+ await flushFrame();
353
+ // Row 1 does not exist yet - nothing applied.
354
+ expect(host.querySelectorAll('[data-svgrid-sheet]').length).toBe(0);
355
+ // Simulate the grid rendering a new row -> observer schedules apply.
356
+ const tbody = host.querySelector('tbody');
357
+ const tr = document.createElement('tr');
358
+ for (const colId of cols) {
359
+ const td = document.createElement('td');
360
+ td.setAttribute('data-svgrid-row', '1');
361
+ td.setAttribute('data-col-id', colId);
362
+ tr.appendChild(td);
363
+ }
364
+ tbody.appendChild(tr);
365
+ await flushFrame();
366
+ await flushFrame();
367
+ expect(cellAt(1, 'a').getAttribute('colspan')).toBe('2');
368
+ action.destroy();
369
+ });
370
+ it('destroy disconnects the observer and cancels a pending frame', async () => {
371
+ const cols = ['a', 'b'];
372
+ const { host, cellAt } = buildGrid(1, cols);
373
+ track(host);
374
+ // Destroy immediately - the first scheduled frame is pending.
375
+ const action = spreadsheetLayout(host, {
376
+ columnOrder: cols,
377
+ merges: [{ rowIndex: 0, columnId: 'a', colspan: 2 }],
378
+ });
379
+ action.destroy();
380
+ await flushFrame();
381
+ await flushFrame();
382
+ // Frame was cancelled before apply ran.
383
+ expect(cellAt(0, 'a').hasAttribute('colspan')).toBe(false);
384
+ // After destroy, mutations no longer trigger apply.
385
+ const tbody = host.querySelector('tbody');
386
+ tbody.appendChild(document.createElement('tr'));
387
+ await flushFrame();
388
+ await flushFrame();
389
+ expect(cellAt(0, 'a').hasAttribute('colspan')).toBe(false);
390
+ });
391
+ it('treats null merges / borders as empty (no throw)', async () => {
392
+ const cols = ['a'];
393
+ const { host } = buildGrid(1, cols);
394
+ track(host);
395
+ const opts = {
396
+ columnOrder: cols,
397
+ merges: null,
398
+ borders: null,
399
+ };
400
+ const action = spreadsheetLayout(host, opts);
401
+ await flushFrame();
402
+ expect(host.querySelectorAll('[data-svgrid-sheet]').length).toBe(0);
403
+ action.destroy();
404
+ });
405
+ });
406
+ describe('spansToMerges - declarative colSpan/rowSpan -> MergeSpec[]', () => {
407
+ const rows = [
408
+ { region: 'AMER', q: 'Q1', amt: 1 },
409
+ { region: 'AMER', q: 'Q2', amt: 2 },
410
+ { region: 'AMER', q: 'Q3', amt: 3 },
411
+ { region: 'EMEA', q: 'Q1', amt: 4 },
412
+ { region: 'EMEA', q: 'Q2', amt: 5 },
413
+ ];
414
+ // Merge each run of equal `region` values downward.
415
+ function regionRowSpan() {
416
+ return ({ data, rowIndex }) => {
417
+ if (rowIndex > 0 && rows[rowIndex - 1].region === data.region)
418
+ return 1; // covered
419
+ let n = 1;
420
+ while (rows[rowIndex + n]?.region === data.region)
421
+ n += 1;
422
+ return n;
423
+ };
424
+ }
425
+ it('emits a rowspan merge at each run origin and skips covered rows', () => {
426
+ const columns = [{ id: 'region', field: 'region', rowSpan: regionRowSpan() }];
427
+ const merges = spansToMerges(rows, columns);
428
+ // AMER spans rows 0..2 (rowspan 3), EMEA spans rows 3..4 (rowspan 2).
429
+ expect(merges).toEqual([
430
+ { rowIndex: 0, columnId: 'region', colspan: undefined, rowspan: 3 },
431
+ { rowIndex: 3, columnId: 'region', colspan: undefined, rowspan: 2 },
432
+ ]);
433
+ });
434
+ it('supports colSpan and marks covered columns', () => {
435
+ const columns = [
436
+ { id: 'a', field: 'region', colSpan: ({ rowIndex }) => (rowIndex === 0 ? 2 : 1) },
437
+ { id: 'b', field: 'q' },
438
+ { id: 'c', field: 'amt' },
439
+ ];
440
+ const merges = spansToMerges(rows.slice(0, 1), columns);
441
+ expect(merges).toEqual([{ rowIndex: 0, columnId: 'a', colspan: 2, rowspan: undefined }]);
442
+ });
443
+ it('returns no merges when no column defines spans', () => {
444
+ expect(spansToMerges(rows, [{ id: 'region', field: 'region' }])).toEqual([]);
445
+ });
446
+ });
@@ -0,0 +1,12 @@
1
+ import { type Column, type Row, type RowData, type TableFeatures } from "./index";
2
+ import "./sv-grid-scrollbar";
3
+ export declare function createSummaries<TFeatures extends TableFeatures = TableFeatures, TData extends RowData = RowData>(ctx: any): {
4
+ computeSummaries: (rows: ReadonlyArray<Row<TData>>, columns: ReadonlyArray<Column<TData>>) => Record<string, string>;
5
+ hasRenderedColumn: (entry: {
6
+ item: (typeof ctx.renderedColumnItems)[number];
7
+ column: (typeof ctx.allColumns)[number] | undefined;
8
+ }) => entry is {
9
+ item: (typeof ctx.renderedColumnItems)[number];
10
+ column: (typeof ctx.allColumns)[number];
11
+ };
12
+ };
@@ -0,0 +1,65 @@
1
+ import "./sv-grid-scrollbar";
2
+ import { getCellKey, } from "./SvGrid.helpers";
3
+ import { formatSummaryNumeric, } from "./cell-values";
4
+ export function createSummaries(ctx) {
5
+ /**
6
+ * Aggregate every row into a per-column footer summary (sum for numeric
7
+ * columns, `Count: N` otherwise). This loop is the hottest path on a
8
+ * large grid - it is rows x columns iterations - so two things keep the
9
+ * constant factor down:
10
+ *
11
+ * 1. The edited-cell overlay is only consulted when an edit actually
12
+ * exists. `key in editedCellValues` hits a reactive-proxy `has`
13
+ * trap for every cell otherwise - 5M no-op trap calls on a
14
+ * 100k x 50 grid. Skipping it when the map is empty is the single
15
+ * biggest win here.
16
+ * 2. The column's accessor (`accessorFn` / `field`) is resolved once
17
+ * per column, not re-read off `columnDef` for every cell.
18
+ */
19
+ function computeSummaries(rows, columns) {
20
+ const summary = {};
21
+ const rowCount = rows.length;
22
+ const hasEdits = Object.keys(ctx.editedCellValues).length > 0;
23
+ for (const column of columns) {
24
+ const def = column.columnDef;
25
+ const accessorFn = def.accessorFn;
26
+ const field = def.field;
27
+ const columnId = column.id;
28
+ let numericSum = 0;
29
+ let numericCount = 0;
30
+ for (let i = 0; i < rowCount; i += 1) {
31
+ const row = rows[i];
32
+ let value;
33
+ const base = accessorFn
34
+ ? accessorFn(row.original)
35
+ : field
36
+ ? row.original[field]
37
+ : row.getCellValueByColumnId(columnId);
38
+ if (hasEdits) {
39
+ const key = getCellKey(row.id, columnId);
40
+ value = key in ctx.editedCellValues ? ctx.editedCellValues[key] : base;
41
+ }
42
+ else {
43
+ value = base;
44
+ }
45
+ const asNumber = Number(value);
46
+ if (Number.isFinite(asNumber)) {
47
+ numericSum += asNumber;
48
+ numericCount += 1;
49
+ }
50
+ }
51
+ summary[columnId] =
52
+ numericCount > 0
53
+ ? formatSummaryNumeric(column, numericSum)
54
+ : `Count: ${rowCount}`;
55
+ }
56
+ return summary;
57
+ }
58
+ function hasRenderedColumn(entry) {
59
+ return entry.column !== undefined;
60
+ }
61
+ return {
62
+ computeSummaries,
63
+ hasRenderedColumn,
64
+ };
65
+ }
@@ -30,7 +30,11 @@ const STYLE_TEMPLATE = `
30
30
  display: flex;
31
31
  user-select: none;
32
32
  background: var(--sg-scrollbar-bg, #eef2f8);
33
- box-shadow: inset 0 0 0 1px var(--sg-scrollbar-border, rgba(15, 23, 42, 0.04));
33
+ /* The 1px separator is drawn on the INNER edge only (the edge facing
34
+ the grid body) via the orientation rules below. A full inset box
35
+ here doubled up with the grid's own frame border on the outer edge,
36
+ reading as a 2px border - most visible in dense-gridline themes
37
+ like Excel, which should show a single 1px line. */
34
38
  /* Start hidden + non-interactive - viewport/content sizes are 0 until
35
39
  after the first layout pass, so without this default the scrollbar
36
40
  paints visible for one frame and then JS hides it on mount. That
@@ -44,10 +48,18 @@ const STYLE_TEMPLATE = `
44
48
  :host([orientation="vertical"]) {
45
49
  flex-direction: column;
46
50
  width: ${ARROW_SIZE}px;
51
+ /* LTR: vertical scrollbar sits at the right, inner edge is the left. */
52
+ box-shadow: inset 1px 0 0 0 var(--sg-scrollbar-border, rgba(15, 23, 42, 0.04));
53
+ }
54
+ :host([orientation="vertical"]:dir(rtl)) {
55
+ /* RTL flips the scrollbar to the left, so the inner edge is the right. */
56
+ box-shadow: inset -1px 0 0 0 var(--sg-scrollbar-border, rgba(15, 23, 42, 0.04));
47
57
  }
48
58
  :host([orientation="horizontal"]) {
49
59
  flex-direction: row;
50
60
  height: ${ARROW_SIZE}px;
61
+ /* Horizontal scrollbar sits at the bottom, inner edge is the top. */
62
+ box-shadow: inset 0 1px 0 0 var(--sg-scrollbar-border, rgba(15, 23, 42, 0.04));
51
63
  }
52
64
  .arrow {
53
65
  flex: none;
@@ -58,6 +58,16 @@ export type SvGridApi<TFeatures extends TableFeatures, TData extends RowData> =
58
58
  getCellValue(rowIndex: number, columnId: string): unknown;
59
59
  /** Write a cell value through the column's field. */
60
60
  setCellValue(rowIndex: number, columnId: string, value: unknown): void;
61
+ /**
62
+ * Programmatically begin editing a cell (as a double-click would). Returns
63
+ * `true` if editing started (cell exists, editable, editing enabled).
64
+ */
65
+ startEditing(rowIndex: number, columnId: string): boolean;
66
+ /**
67
+ * Commit (default) or, with `cancel: true`, discard the active edit.
68
+ * Returns `true` if there was an edit in progress.
69
+ */
70
+ stopEditing(cancel?: boolean): boolean;
61
71
  /**
62
72
  * Programmatically select one or more rectangular cell ranges. Each
63
73
  * range is `[rowStart, colStart, rowEnd, colEnd]` in 0-indexed grid
@@ -105,6 +115,15 @@ export type SvGridApi<TFeatures extends TableFeatures, TData extends RowData> =
105
115
  value?: string;
106
116
  /** Upper bound for the `between` operator. Required when `operator === 'between'`. */
107
117
  valueTo?: string;
118
+ /**
119
+ * Optional SECOND condition on the same column, joined by `join`
120
+ * (multi-condition filtering, e.g. "> 100 AND < 500").
121
+ */
122
+ operator2?: SvGridFilterOperator;
123
+ value2?: string;
124
+ valueTo2?: string;
125
+ /** How to combine the two conditions. Defaults to `'AND'`. */
126
+ join?: 'AND' | 'OR';
108
127
  } | null): void;
109
128
  /**
110
129
  * Set the facet (set-list, Excel-style multi-select) filter for a column.
@@ -164,6 +183,15 @@ export type SvGridApi<TFeatures extends TableFeatures, TData extends RowData> =
164
183
  * default. Useful for "save view" + URL persistence.
165
184
  */
166
185
  getColumnWidths(): Record<string, number>;
186
+ /**
187
+ * Snap one column's width to its widest visible cell (header text +
188
+ * any rendered body cell). Equivalent to double-clicking the column's
189
+ * resize handle. The grid also exposes this through the column menu's
190
+ * "Autosize" item.
191
+ */
192
+ autosizeColumn(columnId: string): void;
193
+ /** Run `autosizeColumn` on every column. */
194
+ autosizeAllColumns(): void;
167
195
  /**
168
196
  * Replace the column-pinning state in one call. Each entry is a
169
197
  * column id; the order in the array becomes the visible order along
@@ -325,7 +353,9 @@ export type SvGridWrapperProps<TFeatures extends TableFeatures, TData extends Ro
325
353
  showRowSelection?: boolean;
326
354
  showPagination?: boolean;
327
355
  virtualization?: boolean;
328
- rowHeight?: number;
356
+ /** Row height in pixels. Pass a function `(rowIndex) => px` for per-row
357
+ * variable heights (e.g. when wiring up an interactive row-resize). */
358
+ rowHeight?: number | ((rowIndex: number) => number);
329
359
  overscan?: number;
330
360
  containerHeight?: number;
331
361
  columnVirtualization?: boolean;
@@ -389,6 +389,26 @@ describe('SvGrid - column add / remove / visibility', () => {
389
389
  destroy();
390
390
  }
391
391
  });
392
+ it('columns marked `visible: false` start hidden but stay listed', async () => {
393
+ const columns = personColumns.map((c) => (c.field === 'team' ? { ...c, visible: false } : c));
394
+ const { api, destroy } = await mountGrid({ columns });
395
+ try {
396
+ // Starts hidden...
397
+ expect(api.isColumnVisible('team')).toBe(false);
398
+ // ...but is still listed in getColumns() (so a Choose Columns UI
399
+ // can offer it), just with visible=false.
400
+ const team = api.getColumns().find((c) => c.id === 'team');
401
+ expect(team).toBeDefined();
402
+ expect(team?.visible).toBe(false);
403
+ // A later user toggle wins over the initial flag.
404
+ api.setColumnVisible('team', true);
405
+ await tick();
406
+ expect(api.isColumnVisible('team')).toBe(true);
407
+ }
408
+ finally {
409
+ destroy();
410
+ }
411
+ });
392
412
  });
393
413
  describe('SvGrid - row add / remove', () => {
394
414
  it('addRow at top / bottom / specific index', async () => {
@@ -0,0 +1 @@
1
+ export {};