@svgrid/grid 1.1.2 → 1.2.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 (141) hide show
  1. package/dist/SvGrid.svelte +3 -1
  2. package/dist/SvGridDropdown.svelte +7 -3
  3. package/dist/cdn/svgrid.js +13504 -0
  4. package/dist/cdn/svgrid.svelte-external.js +11188 -0
  5. package/package.json +12 -2
  6. package/src/SvGrid.svelte +3 -1
  7. package/src/SvGridDropdown.svelte +7 -3
  8. package/dist/SvGrid.helpers.test.d.ts +0 -1
  9. package/dist/SvGrid.helpers.test.js +0 -298
  10. package/dist/SvGridChart.test.d.ts +0 -1
  11. package/dist/SvGridChart.test.js +0 -62
  12. package/dist/a11y.contract.test.d.ts +0 -1
  13. package/dist/a11y.contract.test.js +0 -39
  14. package/dist/a11y.test.d.ts +0 -1
  15. package/dist/a11y.test.js +0 -44
  16. package/dist/aligned-grids.test.d.ts +0 -1
  17. package/dist/aligned-grids.test.js +0 -75
  18. package/dist/build-api.coverage.test.d.ts +0 -20
  19. package/dist/build-api.coverage.test.js +0 -505
  20. package/dist/cell-formatting.test.d.ts +0 -1
  21. package/dist/cell-formatting.test.js +0 -234
  22. package/dist/cell-render.test.d.ts +0 -1
  23. package/dist/cell-render.test.js +0 -338
  24. package/dist/chart-export.test.d.ts +0 -1
  25. package/dist/chart-export.test.js +0 -302
  26. package/dist/chart.coverage.test.d.ts +0 -1
  27. package/dist/chart.coverage.test.js +0 -748
  28. package/dist/chart.test.d.ts +0 -1
  29. package/dist/chart.test.js +0 -289
  30. package/dist/clipboard.test.d.ts +0 -1
  31. package/dist/clipboard.test.js +0 -700
  32. package/dist/collaboration.coverage.test.d.ts +0 -1
  33. package/dist/collaboration.coverage.test.js +0 -200
  34. package/dist/collaboration.test.d.ts +0 -1
  35. package/dist/collaboration.test.js +0 -65
  36. package/dist/column-groups.test.d.ts +0 -1
  37. package/dist/column-groups.test.js +0 -56
  38. package/dist/column-types.test.d.ts +0 -1
  39. package/dist/column-types.test.js +0 -62
  40. package/dist/columns.test.d.ts +0 -1
  41. package/dist/columns.test.js +0 -625
  42. package/dist/conditional-formatting.test.d.ts +0 -1
  43. package/dist/conditional-formatting.test.js +0 -87
  44. package/dist/core.coverage.test.d.ts +0 -1
  45. package/dist/core.coverage.test.js +0 -186
  46. package/dist/core.performance.test.d.ts +0 -1
  47. package/dist/core.performance.test.js +0 -29
  48. package/dist/createGrid.test.d.ts +0 -1
  49. package/dist/createGrid.test.js +0 -9
  50. package/dist/editing.test.d.ts +0 -1
  51. package/dist/editing.test.js +0 -732
  52. package/dist/editors/cell-editors.coverage.test.d.ts +0 -1
  53. package/dist/editors/cell-editors.coverage.test.js +0 -139
  54. package/dist/editors/cell-editors.test.d.ts +0 -1
  55. package/dist/editors/cell-editors.test.js +0 -75
  56. package/dist/facet-buckets.test.d.ts +0 -1
  57. package/dist/facet-buckets.test.js +0 -296
  58. package/dist/fill-patterns.test.d.ts +0 -1
  59. package/dist/fill-patterns.test.js +0 -81
  60. package/dist/filter-operators.test.d.ts +0 -1
  61. package/dist/filter-operators.test.js +0 -135
  62. package/dist/filtering/excel-filters.test.d.ts +0 -1
  63. package/dist/filtering/excel-filters.test.js +0 -116
  64. package/dist/filtering/locale-filter.test.d.ts +0 -13
  65. package/dist/filtering/locale-filter.test.js +0 -189
  66. package/dist/flex-render.test.d.ts +0 -1
  67. package/dist/flex-render.test.js +0 -142
  68. package/dist/group-aggregate.test.d.ts +0 -1
  69. package/dist/group-aggregate.test.js +0 -32
  70. package/dist/hyperformula-adapter.test.d.ts +0 -1
  71. package/dist/hyperformula-adapter.test.js +0 -205
  72. package/dist/keyboard-handlers.coverage.test.d.ts +0 -1
  73. package/dist/keyboard-handlers.coverage.test.js +0 -495
  74. package/dist/keyboard.test.d.ts +0 -1
  75. package/dist/keyboard.test.js +0 -27
  76. package/dist/menus.test.d.ts +0 -1
  77. package/dist/menus.test.js +0 -560
  78. package/dist/named-views.coverage.test.d.ts +0 -1
  79. package/dist/named-views.coverage.test.js +0 -180
  80. package/dist/named-views.test.d.ts +0 -1
  81. package/dist/named-views.test.js +0 -57
  82. package/dist/new-features.test.d.ts +0 -1
  83. package/dist/new-features.test.js +0 -183
  84. package/dist/render-component.test.d.ts +0 -1
  85. package/dist/render-component.test.js +0 -41
  86. package/dist/row-drag.test.d.ts +0 -1
  87. package/dist/row-drag.test.js +0 -142
  88. package/dist/row-resize.test.d.ts +0 -1
  89. package/dist/row-resize.test.js +0 -329
  90. package/dist/scroll-sync.test.d.ts +0 -1
  91. package/dist/scroll-sync.test.js +0 -290
  92. package/dist/selection.multi-range.test.d.ts +0 -1
  93. package/dist/selection.multi-range.test.js +0 -55
  94. package/dist/selection.test.d.ts +0 -1
  95. package/dist/selection.test.js +0 -647
  96. package/dist/server-data-source.coverage.test.d.ts +0 -1
  97. package/dist/server-data-source.coverage.test.js +0 -154
  98. package/dist/server-data-source.test.d.ts +0 -1
  99. package/dist/server-data-source.test.js +0 -81
  100. package/dist/sparkline.test.d.ts +0 -1
  101. package/dist/sparkline.test.js +0 -52
  102. package/dist/spreadsheet.test.d.ts +0 -1
  103. package/dist/spreadsheet.test.js +0 -446
  104. package/dist/subscribe.test.d.ts +0 -1
  105. package/dist/subscribe.test.js +0 -93
  106. package/dist/svgrid.api-extensions.test.d.ts +0 -14
  107. package/dist/svgrid.api-extensions.test.js +0 -334
  108. package/dist/svgrid.api.test.d.ts +0 -15
  109. package/dist/svgrid.api.test.js +0 -169
  110. package/dist/svgrid.behavior.test.d.ts +0 -15
  111. package/dist/svgrid.behavior.test.js +0 -625
  112. package/dist/svgrid.column-reorder.test.d.ts +0 -15
  113. package/dist/svgrid.column-reorder.test.js +0 -224
  114. package/dist/svgrid.comments-autocomplete.test.d.ts +0 -1
  115. package/dist/svgrid.comments-autocomplete.test.js +0 -96
  116. package/dist/svgrid.context-menu.test.d.ts +0 -1
  117. package/dist/svgrid.context-menu.test.js +0 -102
  118. package/dist/svgrid.features.test.d.ts +0 -1
  119. package/dist/svgrid.features.test.js +0 -129
  120. package/dist/svgrid.interaction.test.d.ts +0 -9
  121. package/dist/svgrid.interaction.test.js +0 -349
  122. package/dist/svgrid.locale-filtering.test.d.ts +0 -15
  123. package/dist/svgrid.locale-filtering.test.js +0 -261
  124. package/dist/svgrid.new-features.wrapper.test.d.ts +0 -1
  125. package/dist/svgrid.new-features.wrapper.test.js +0 -194
  126. package/dist/svgrid.row-pinning.test.d.ts +0 -14
  127. package/dist/svgrid.row-pinning.test.js +0 -250
  128. package/dist/svgrid.set-filter.test.d.ts +0 -17
  129. package/dist/svgrid.set-filter.test.js +0 -268
  130. package/dist/svgrid.wrapper.test.d.ts +0 -1
  131. package/dist/svgrid.wrapper.test.js +0 -59
  132. package/dist/test-setup.d.ts +0 -1
  133. package/dist/test-setup.js +0 -35
  134. package/dist/transaction.test.d.ts +0 -1
  135. package/dist/transaction.test.js +0 -89
  136. package/dist/virtualization/column-virtualizer.test.d.ts +0 -1
  137. package/dist/virtualization/column-virtualizer.test.js +0 -25
  138. package/dist/virtualization/scroll-scaling.test.d.ts +0 -1
  139. package/dist/virtualization/scroll-scaling.test.js +0 -127
  140. package/dist/virtualization/virtualizer.test.d.ts +0 -1
  141. package/dist/virtualization/virtualizer.test.js +0 -41
@@ -1,446 +0,0 @@
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
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,93 +0,0 @@
1
- /**
2
- * Unit tests for the grid-store subscribe helper.
3
- *
4
- * The function attaches a selector to grid.store and shallow-compares each
5
- * emitted state, updating the returned `current` getter only when the
6
- * selection actually changed.
7
- */
8
- import { describe, expect, it } from 'vitest';
9
- import { subscribeGrid, subscribeSvGrid } from './subscribe';
10
- /**
11
- * Minimal hand-rolled stand-in for `grid.store` that mimics the TanStack
12
- * Store shape `subscribeGrid` reads: `state` getter + `subscribe(listener)`
13
- * + `setState(updater)` that fires the listeners.
14
- */
15
- function makeFakeStore(initial) {
16
- let state = initial;
17
- const listeners = new Set();
18
- const store = {
19
- get state() {
20
- return state;
21
- },
22
- subscribe(listener) {
23
- listeners.add(listener);
24
- return () => listeners.delete(listener);
25
- },
26
- setState(updater) {
27
- state = updater(state);
28
- for (const l of listeners)
29
- l();
30
- },
31
- };
32
- return store;
33
- }
34
- describe('subscribeGrid', () => {
35
- it('starts with the current selected value', () => {
36
- const store = makeFakeStore({ sorting: ['name'], rowSelection: { '0': true } });
37
- const grid = { store };
38
- const sub = subscribeGrid(grid, (s) => s.sorting);
39
- expect(sub.current).toEqual(['name']);
40
- });
41
- it('updates the selected value when the store fires a change', () => {
42
- const store = makeFakeStore({ sorting: ['name'] });
43
- const grid = { store };
44
- const sub = subscribeGrid(grid, (s) => s.sorting);
45
- store.setState((prev) => ({ ...prev, sorting: ['age'] }));
46
- expect(sub.current).toEqual(['age']);
47
- });
48
- it('keeps the previous reference when shallow-compare reports equal', () => {
49
- const store = makeFakeStore({ sel: { a: true } });
50
- const grid = { store };
51
- const sub = subscribeGrid(grid, (s) => s.sel);
52
- const initial = sub.current;
53
- // A new object with the same key/value content - shallow-equal to the prev.
54
- store.setState(() => ({ sel: { a: true } }));
55
- expect(sub.current).toBe(initial);
56
- });
57
- it('replaces the reference when a key value changes', () => {
58
- const store = makeFakeStore({ sel: { a: true } });
59
- const grid = { store };
60
- const sub = subscribeGrid(grid, (s) => s.sel);
61
- const initial = sub.current;
62
- store.setState(() => ({ sel: { a: false } }));
63
- expect(sub.current).not.toBe(initial);
64
- expect(sub.current).toEqual({ a: false });
65
- });
66
- it('treats a different key set as a change', () => {
67
- const store = makeFakeStore({ sel: { a: true } });
68
- const grid = { store };
69
- const sub = subscribeGrid(grid, (s) => s.sel);
70
- store.setState(() => ({ sel: { a: true, b: true } }));
71
- expect(sub.current).toEqual({ a: true, b: true });
72
- });
73
- it('treats primitive selections (numbers, strings) correctly', () => {
74
- const store = makeFakeStore({ count: 1 });
75
- const grid = { store };
76
- const sub = subscribeGrid(grid, (s) => s.count);
77
- expect(sub.current).toBe(1);
78
- store.setState(() => ({ count: 1 }));
79
- expect(sub.current).toBe(1);
80
- store.setState(() => ({ count: 2 }));
81
- expect(sub.current).toBe(2);
82
- });
83
- it('treats null and undefined as inequal to objects (early-return shallowCompare branch)', () => {
84
- const store = makeFakeStore({ sel: { a: true } });
85
- const grid = { store };
86
- const sub = subscribeGrid(grid, (s) => s.sel);
87
- store.setState(() => ({ sel: null }));
88
- expect(sub.current).toBeNull();
89
- });
90
- it('exports the subscribeSvGrid alias as the same function', () => {
91
- expect(subscribeSvGrid).toBe(subscribeGrid);
92
- });
93
- });
@@ -1,14 +0,0 @@
1
- /**
2
- * Behavioral tests for the SvGridApi extensions inspired by the jqxGrid API:
3
- * - Row selection read/write (getSelectedRows / getSelectedRowIds /
4
- * selectRows / selectAllRows / toggleRowSelected)
5
- * - Pagination control (getPageInfo / setPage / next/prev/first/last /
6
- * setPageSize)
7
- * - Navigation (scrollToRow / getActiveCell / setActiveCell)
8
- * - View state (getState / setState / refresh)
9
- * - Click / double-click / scroll-bottom events
10
- *
11
- * They mount the real <SvGrid /> in jsdom and exercise the api object handed
12
- * back from onApiReady.
13
- */
14
- export {};