@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,329 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
- import { rowResize } from './row-resize';
3
- const STRIP_CLASS = 'sv-grid-row-resize-handle';
4
- // ---------------------------------------------------------------------------
5
- // Helpers
6
- // ---------------------------------------------------------------------------
7
- /** Build a host `<table>` with `rows` body rows. Each row carries the
8
- * `tr.sv-grid-row` class + a `.sv-row-gutter` cell holding a
9
- * `data-svgrid-row` marker, matching what SvGrid renders. Extra classes
10
- * let individual tests opt rows out (header / spacer / no-gutter). */
11
- function buildGrid(specs) {
12
- const host = document.createElement('div');
13
- const table = document.createElement('table');
14
- const tbody = document.createElement('tbody');
15
- const rows = [];
16
- specs.forEach((spec, i) => {
17
- const tr = document.createElement('tr');
18
- tr.className = ['sv-grid-row', ...(spec.rowClasses ?? [])].join(' ');
19
- const cell = document.createElement('td');
20
- cell.className = 'sv-grid-cell';
21
- if (spec.gutter !== false)
22
- cell.classList.add('sv-row-gutter');
23
- const marker = document.createElement('span');
24
- marker.setAttribute('data-svgrid-row', String(spec.rowIndex ?? i));
25
- cell.appendChild(marker);
26
- tr.appendChild(cell);
27
- tbody.appendChild(tr);
28
- rows.push(tr);
29
- });
30
- table.appendChild(tbody);
31
- host.appendChild(table);
32
- document.body.appendChild(host);
33
- return { host, rows };
34
- }
35
- function gutterOf(tr) {
36
- return tr.querySelector('.sv-row-gutter');
37
- }
38
- function stripOf(tr) {
39
- return tr.querySelector(`.${STRIP_CLASS}`);
40
- }
41
- /** Mock getBoundingClientRect so a TR reports a real height in jsdom
42
- * (which otherwise returns all-zero rects). */
43
- function mockRowHeight(tr, height) {
44
- tr.getBoundingClientRect = () => ({ height, width: 100, top: 0, left: 0, right: 100, bottom: height, x: 0, y: 0, toJSON() { } });
45
- }
46
- function pointer(type, init = {}) {
47
- return new PointerEvent(type, { bubbles: true, cancelable: true, pointerId: 1, ...init });
48
- }
49
- const hosts = [];
50
- function track(host) {
51
- hosts.push(host);
52
- return host;
53
- }
54
- beforeEach(() => {
55
- // jsdom lacks pointer-capture methods on elements; stub them so the action's
56
- // try/catch wrapped calls have something to invoke.
57
- if (!HTMLElement.prototype.setPointerCapture) {
58
- HTMLElement.prototype.setPointerCapture = function () { };
59
- }
60
- if (!HTMLElement.prototype.releasePointerCapture) {
61
- HTMLElement.prototype.releasePointerCapture = function () { };
62
- }
63
- });
64
- afterEach(() => {
65
- while (hosts.length)
66
- hosts.pop().remove();
67
- document.body.innerHTML = '';
68
- document.body.style.cursor = '';
69
- });
70
- // ---------------------------------------------------------------------------
71
- // decorate()
72
- // ---------------------------------------------------------------------------
73
- describe('rowResize - strip injection', () => {
74
- it('injects a resize strip into every gutter cell', () => {
75
- const { host, rows } = buildGrid([{}, {}, {}]);
76
- track(host);
77
- const action = rowResize(host, { onResize: vi.fn() });
78
- for (const tr of rows) {
79
- const strip = stripOf(tr);
80
- expect(strip).not.toBeNull();
81
- expect(strip.getAttribute('role')).toBe('separator');
82
- expect(strip.getAttribute('aria-orientation')).toBe('horizontal');
83
- expect(strip.getAttribute('aria-label')).toBe('Resize row');
84
- expect(strip.style.cursor).toBe('row-resize');
85
- }
86
- // Gutter cells become a positioning context with visible overflow.
87
- expect(gutterOf(rows[0]).style.position).toBe('relative');
88
- expect(gutterOf(rows[0]).style.overflow).toBe('visible');
89
- action.destroy();
90
- });
91
- it('does not double-inject a strip on re-decorate', async () => {
92
- const { host, rows } = buildGrid([{}]);
93
- track(host);
94
- const action = rowResize(host, { onResize: vi.fn() });
95
- expect(rows[0].querySelectorAll(`.${STRIP_CLASS}`).length).toBe(1);
96
- // Trigger the MutationObserver by appending an unrelated node.
97
- gutterOf(rows[0]).appendChild(document.createElement('span'));
98
- await Promise.resolve();
99
- await new Promise((r) => setTimeout(r, 0));
100
- expect(rows[0].querySelectorAll(`.${STRIP_CLASS}`).length).toBe(1);
101
- action.destroy();
102
- });
103
- it('skips header rows, spacer rows, and rows without a gutter cell', () => {
104
- const { host, rows } = buildGrid([
105
- { rowClasses: ['sv-grid-header-row'] },
106
- { rowClasses: ['sv-grid-row-spacer'] },
107
- { gutter: false },
108
- {}, // normal row gets a strip
109
- ]);
110
- track(host);
111
- const action = rowResize(host, { onResize: vi.fn() });
112
- expect(stripOf(rows[0])).toBeNull();
113
- expect(stripOf(rows[1])).toBeNull();
114
- expect(stripOf(rows[2])).toBeNull();
115
- expect(stripOf(rows[3])).not.toBeNull();
116
- action.destroy();
117
- });
118
- it('does not override an already-positioned gutter cell', () => {
119
- const { host, rows } = buildGrid([{}]);
120
- track(host);
121
- gutterOf(rows[0]).style.position = 'sticky';
122
- const action = rowResize(host, { onResize: vi.fn() });
123
- expect(gutterOf(rows[0]).style.position).toBe('sticky');
124
- action.destroy();
125
- });
126
- it('injects no strips when created disabled', () => {
127
- const { host, rows } = buildGrid([{}, {}]);
128
- track(host);
129
- const action = rowResize(host, { onResize: vi.fn(), disabled: true });
130
- expect(stripOf(rows[0])).toBeNull();
131
- expect(stripOf(rows[1])).toBeNull();
132
- action.destroy();
133
- });
134
- });
135
- // ---------------------------------------------------------------------------
136
- // Drag lifecycle
137
- // ---------------------------------------------------------------------------
138
- describe('rowResize - drag', () => {
139
- it('reports the new height on pointerup and fires move callbacks', () => {
140
- const { host, rows } = buildGrid([{ rowIndex: 0 }]);
141
- track(host);
142
- mockRowHeight(rows[0], 32);
143
- const onResize = vi.fn();
144
- const onResizeMove = vi.fn();
145
- const action = rowResize(host, { onResize, onResizeMove });
146
- const strip = stripOf(rows[0]);
147
- strip.dispatchEvent(pointer('pointerdown', { clientY: 100 }));
148
- expect(strip.classList.contains('is-resizing')).toBe(true);
149
- expect(document.body.style.cursor).toBe('row-resize');
150
- // Drag down 20px -> 52.
151
- window.dispatchEvent(pointer('pointermove', { clientY: 120 }));
152
- expect(onResizeMove).toHaveBeenLastCalledWith(0, 52);
153
- expect(rows[0].style.height).toBe('52px');
154
- window.dispatchEvent(pointer('pointerup', { clientY: 120 }));
155
- expect(onResize).toHaveBeenCalledWith(0, 52);
156
- expect(strip.classList.contains('is-resizing')).toBe(false);
157
- expect(document.body.style.cursor).toBe('');
158
- action.destroy();
159
- });
160
- it('clamps the height to the min bound', () => {
161
- const { host, rows } = buildGrid([{ rowIndex: 0 }]);
162
- track(host);
163
- mockRowHeight(rows[0], 32);
164
- const onResize = vi.fn();
165
- const action = rowResize(host, { onResize, min: 24 });
166
- const strip = stripOf(rows[0]);
167
- strip.dispatchEvent(pointer('pointerdown', { clientY: 100 }));
168
- // Drag far up -> would be negative, clamps to 24.
169
- window.dispatchEvent(pointer('pointerup', { clientY: 0 }));
170
- expect(onResize).toHaveBeenCalledWith(0, 24);
171
- action.destroy();
172
- });
173
- it('clamps the height to the max bound', () => {
174
- const { host, rows } = buildGrid([{ rowIndex: 0 }]);
175
- track(host);
176
- mockRowHeight(rows[0], 32);
177
- const onResize = vi.fn();
178
- const action = rowResize(host, { onResize, max: 50 });
179
- const strip = stripOf(rows[0]);
180
- strip.dispatchEvent(pointer('pointerdown', { clientY: 100 }));
181
- window.dispatchEvent(pointer('pointerup', { clientY: 1000 }));
182
- expect(onResize).toHaveBeenCalledWith(0, 50);
183
- action.destroy();
184
- });
185
- it('works without an onResizeMove callback (optional)', () => {
186
- const { host, rows } = buildGrid([{ rowIndex: 0 }]);
187
- track(host);
188
- mockRowHeight(rows[0], 30);
189
- const onResize = vi.fn();
190
- const action = rowResize(host, { onResize });
191
- const strip = stripOf(rows[0]);
192
- strip.dispatchEvent(pointer('pointerdown', { clientY: 50 }));
193
- expect(() => window.dispatchEvent(pointer('pointermove', { clientY: 60 }))).not.toThrow();
194
- window.dispatchEvent(pointer('pointerup', { clientY: 60 }));
195
- expect(onResize).toHaveBeenCalledWith(0, 40);
196
- action.destroy();
197
- });
198
- it('ignores pointermove / pointerup when no drag is active', () => {
199
- const { host, rows } = buildGrid([{ rowIndex: 0 }]);
200
- track(host);
201
- const onResize = vi.fn();
202
- const onResizeMove = vi.fn();
203
- const action = rowResize(host, { onResize, onResizeMove });
204
- // No pointerdown first - listeners were only attached on down, so these
205
- // shouldn't do anything even if dispatched.
206
- window.dispatchEvent(pointer('pointermove', { clientY: 10 }));
207
- window.dispatchEvent(pointer('pointerup', { clientY: 10 }));
208
- expect(onResize).not.toHaveBeenCalled();
209
- expect(onResizeMove).not.toHaveBeenCalled();
210
- action.destroy();
211
- });
212
- });
213
- // ---------------------------------------------------------------------------
214
- // pointerdown guards
215
- // ---------------------------------------------------------------------------
216
- describe('rowResize - pointerdown guards', () => {
217
- it('ignores pointerdown when disabled', () => {
218
- const { host, rows } = buildGrid([{ rowIndex: 0 }]);
219
- track(host);
220
- mockRowHeight(rows[0], 32);
221
- const onResize = vi.fn();
222
- // Start enabled so a strip exists, then disable via update.
223
- const action = rowResize(host, { onResize });
224
- const strip = stripOf(rows[0]);
225
- action.update({ onResize, disabled: true });
226
- // update removes strips, but dispatch on the (now-detached) strip anyway:
227
- // even if it were still in the DOM, current.disabled short-circuits.
228
- strip.dispatchEvent(pointer('pointerdown', { clientY: 10 }));
229
- window.dispatchEvent(pointer('pointerup', { clientY: 50 }));
230
- expect(onResize).not.toHaveBeenCalled();
231
- action.destroy();
232
- });
233
- it('ignores pointerdown on a non-strip target', () => {
234
- const { host, rows } = buildGrid([{ rowIndex: 0 }]);
235
- track(host);
236
- const onResize = vi.fn();
237
- const action = rowResize(host, { onResize });
238
- gutterOf(rows[0]).dispatchEvent(pointer('pointerdown', { clientY: 10 }));
239
- expect(document.body.style.cursor).toBe('');
240
- action.destroy();
241
- });
242
- it('ignores a strip whose row has a non-finite row index', () => {
243
- const { host, rows } = buildGrid([{}]);
244
- track(host);
245
- // Remove the data-svgrid-row marker so rowIndexOf returns NaN.
246
- rows[0].querySelector('[data-svgrid-row]').removeAttribute('data-svgrid-row');
247
- const onResize = vi.fn();
248
- const action = rowResize(host, { onResize });
249
- const strip = stripOf(rows[0]);
250
- strip.dispatchEvent(pointer('pointerdown', { clientY: 10 }));
251
- expect(document.body.style.cursor).toBe('');
252
- expect(strip.classList.contains('is-resizing')).toBe(false);
253
- action.destroy();
254
- });
255
- it('ignores a strip not inside a tr.sv-grid-row', () => {
256
- const host = track(document.createElement('div'));
257
- document.body.appendChild(host);
258
- // A loose strip with no matching ancestor row.
259
- const strip = document.createElement('div');
260
- strip.className = STRIP_CLASS;
261
- host.appendChild(strip);
262
- const onResize = vi.fn();
263
- const action = rowResize(host, { onResize });
264
- strip.dispatchEvent(pointer('pointerdown', { clientY: 10 }));
265
- expect(document.body.style.cursor).toBe('');
266
- action.destroy();
267
- });
268
- });
269
- // ---------------------------------------------------------------------------
270
- // update() + destroy()
271
- // ---------------------------------------------------------------------------
272
- describe('rowResize - update + destroy', () => {
273
- it('removes strips when toggled to disabled and restores when re-enabled', () => {
274
- const { host, rows } = buildGrid([{}, {}]);
275
- track(host);
276
- const onResize = vi.fn();
277
- const action = rowResize(host, { onResize, disabled: false });
278
- expect(stripOf(rows[0])).not.toBeNull();
279
- action.update({ onResize, disabled: true });
280
- expect(stripOf(rows[0])).toBeNull();
281
- expect(stripOf(rows[1])).toBeNull();
282
- action.update({ onResize, disabled: false });
283
- expect(stripOf(rows[0])).not.toBeNull();
284
- action.destroy();
285
- });
286
- it('does not repaint when disabled flag is unchanged on update', () => {
287
- const { host, rows } = buildGrid([{}]);
288
- track(host);
289
- const action = rowResize(host, { onResize: vi.fn() });
290
- const firstStrip = stripOf(rows[0]);
291
- // Same disabled value -> decorate is NOT called, strip stays the same node.
292
- action.update({ onResize: vi.fn() });
293
- expect(stripOf(rows[0])).toBe(firstStrip);
294
- action.destroy();
295
- });
296
- it('destroy removes all strips and detaches listeners', () => {
297
- const { host, rows } = buildGrid([{ rowIndex: 0 }]);
298
- track(host);
299
- mockRowHeight(rows[0], 32);
300
- const onResize = vi.fn();
301
- const action = rowResize(host, { onResize });
302
- expect(stripOf(rows[0])).not.toBeNull();
303
- action.destroy();
304
- expect(stripOf(rows[0])).toBeNull();
305
- // After destroy the pointerdown listener is gone; re-create a strip
306
- // manually and confirm no drag starts.
307
- const strip = document.createElement('div');
308
- strip.className = STRIP_CLASS;
309
- gutterOf(rows[0]).appendChild(strip);
310
- strip.dispatchEvent(pointer('pointerdown', { clientY: 10 }));
311
- expect(document.body.style.cursor).toBe('');
312
- });
313
- it('uses default min=20 / max=320 when bounds are omitted', () => {
314
- const { host, rows } = buildGrid([{ rowIndex: 0 }]);
315
- track(host);
316
- mockRowHeight(rows[0], 100);
317
- const onResize = vi.fn();
318
- const action = rowResize(host, { onResize });
319
- const strip = stripOf(rows[0]);
320
- strip.dispatchEvent(pointer('pointerdown', { clientY: 0 }));
321
- // Drag way past max -> clamps to 320.
322
- window.dispatchEvent(pointer('pointermove', { clientY: 10000 }));
323
- expect(rows[0].style.height).toBe('320px');
324
- // Drag way below min -> clamps to 20.
325
- window.dispatchEvent(pointer('pointerup', { clientY: -10000 }));
326
- expect(onResize).toHaveBeenCalledWith(0, 20);
327
- action.destroy();
328
- });
329
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,290 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
- import { createScrollSync } from './scroll-sync';
3
- // ---------------------------------------------------------------------------
4
- // Fake controller `ctx` for the scroll-sync handlers. As with the other
5
- // controller-slice tests, the handlers read/write everything through `ctx`,
6
- // so a hand-rolled stub drives every branch. Where the handler reads real DOM
7
- // geometry (tooltip placement, scroll offsets) we build genuine elements and
8
- // stub getBoundingClientRect / scroll metrics.
9
- // ---------------------------------------------------------------------------
10
- function makeCtx(overrides = {}) {
11
- const ctx = {
12
- tooltip: null,
13
- tooltipTimer: null,
14
- scrollSyncRaf: null,
15
- scrollVersion: 0,
16
- pendingScrollTop: 0,
17
- pendingScrollLeft: 0,
18
- rowVirtualizationEnabled: false,
19
- columnVirtualizationEnabled: false,
20
- scrollBottomArmed: true,
21
- columnMenuFor: null,
22
- operatorMenuFor: null,
23
- closeMenus: vi.fn(),
24
- domToLogicalRowOffset: (n) => n,
25
- virtualizer: { setScrollOffset: vi.fn() },
26
- columnVirtualizer: { setHorizontalOffset: vi.fn() },
27
- props: {},
28
- ...overrides,
29
- };
30
- return ctx;
31
- }
32
- const syncFor = (overrides) => {
33
- const ctx = makeCtx(overrides);
34
- return { ctx, ss: createScrollSync(ctx) };
35
- };
36
- describe('showTooltipFor / hideTooltip', () => {
37
- beforeEach(() => {
38
- vi.useFakeTimers();
39
- });
40
- afterEach(() => {
41
- vi.useRealTimers();
42
- });
43
- function anchorEl(rect) {
44
- const el = document.createElement('div');
45
- el.getBoundingClientRect = () => ({ left: 0, right: 0, top: 0, bottom: 0, width: 0, height: 0, x: 0, y: 0, ...rect });
46
- return el;
47
- }
48
- it('does nothing when there is no text', () => {
49
- const { ctx, ss } = syncFor();
50
- ss.showTooltipFor(anchorEl({}), '');
51
- expect(ctx.tooltipTimer).toBeNull();
52
- vi.runAllTimers();
53
- expect(ctx.tooltip).toBeNull();
54
- });
55
- it('schedules a tooltip after the debounce, positioned below the anchor', () => {
56
- const { ctx, ss } = syncFor();
57
- // Anchor near the top of a tall viewport -> tooltip appears below.
58
- vi.stubGlobal('innerWidth', 1000);
59
- vi.stubGlobal('innerHeight', 800);
60
- const el = anchorEl({ left: 100, right: 140, top: 50, bottom: 70 });
61
- ss.showTooltipFor(el, 'hello');
62
- expect(ctx.tooltipTimer).not.toBeNull();
63
- expect(ctx.tooltip).toBeNull(); // not yet flushed
64
- vi.advanceTimersByTime(250);
65
- expect(ctx.tooltip).toEqual({
66
- text: 'hello',
67
- x: 106, // left + 6, within clamp range
68
- y: 76, // bottom + 6 since "below"
69
- below: true,
70
- });
71
- });
72
- it('flips above the anchor when there is no room below', () => {
73
- const { ctx, ss } = syncFor();
74
- vi.stubGlobal('innerWidth', 1000);
75
- vi.stubGlobal('innerHeight', 200);
76
- // bottom + 64 is NOT < 200, so the tooltip renders above.
77
- const el = anchorEl({ left: 100, right: 140, top: 150, bottom: 170 });
78
- ss.showTooltipFor(el, 'world');
79
- vi.advanceTimersByTime(250);
80
- expect(ctx.tooltip.below).toBe(false);
81
- expect(ctx.tooltip.y).toBe(144); // top - 6
82
- });
83
- it('clamps x so a wide tooltip stays inside the viewport', () => {
84
- const { ctx, ss } = syncFor();
85
- vi.stubGlobal('innerWidth', 300);
86
- vi.stubGlobal('innerHeight', 800);
87
- const el = anchorEl({ left: 280, right: 300, top: 10, bottom: 30 });
88
- ss.showTooltipFor(el, 'edge');
89
- vi.advanceTimersByTime(250);
90
- // x clamped to vw - 290 = 10.
91
- expect(ctx.tooltip.x).toBe(10);
92
- });
93
- it('clears a pending timer before scheduling a new tooltip', () => {
94
- const { ctx, ss } = syncFor();
95
- const clearSpy = vi.spyOn(window, 'clearTimeout');
96
- const el = anchorEl({ left: 10, right: 30, top: 10, bottom: 30 });
97
- ss.showTooltipFor(el, 'first');
98
- ss.showTooltipFor(el, 'second');
99
- expect(clearSpy).toHaveBeenCalled();
100
- clearSpy.mockRestore();
101
- });
102
- it('hideTooltip clears the pending timer and the tooltip', () => {
103
- const { ctx, ss } = syncFor();
104
- const el = anchorEl({ left: 10, right: 30, top: 10, bottom: 30 });
105
- ss.showTooltipFor(el, 'gone');
106
- ctx.tooltip = { text: 'x', x: 0, y: 0, below: true };
107
- ss.hideTooltip();
108
- expect(ctx.tooltipTimer).toBeNull();
109
- expect(ctx.tooltip).toBeNull();
110
- });
111
- it('hideTooltip is safe when no timer is pending', () => {
112
- const { ctx, ss } = syncFor();
113
- ctx.tooltip = { text: 'x', x: 0, y: 0, below: true };
114
- ss.hideTooltip();
115
- expect(ctx.tooltip).toBeNull();
116
- });
117
- });
118
- describe('scheduleScrollSync / flushScheduledScrollSync', () => {
119
- let rafCb = null;
120
- let rafCalls = 0;
121
- beforeEach(() => {
122
- rafCb = null;
123
- rafCalls = 0;
124
- vi.stubGlobal('requestAnimationFrame', (cb) => {
125
- rafCb = cb;
126
- rafCalls += 1;
127
- return 42;
128
- });
129
- });
130
- afterEach(() => {
131
- vi.unstubAllGlobals();
132
- });
133
- it('records the pending offsets and schedules a single rAF', () => {
134
- const { ctx, ss } = syncFor();
135
- ss.scheduleScrollSync(120, 45);
136
- expect(ctx.pendingScrollTop).toBe(120);
137
- expect(ctx.pendingScrollLeft).toBe(45);
138
- expect(ctx.scrollSyncRaf).toBe(42);
139
- expect(rafCalls).toBe(1);
140
- });
141
- it('coalesces back-to-back calls into one frame (latest position wins)', () => {
142
- const { ctx, ss } = syncFor();
143
- ss.scheduleScrollSync(10, 0);
144
- ss.scheduleScrollSync(200, 5); // raf already pending, must not re-schedule
145
- expect(rafCalls).toBe(1);
146
- expect(ctx.pendingScrollTop).toBe(200);
147
- expect(ctx.pendingScrollLeft).toBe(5);
148
- });
149
- it('flush bumps scrollVersion and clears the raf handle', () => {
150
- const { ctx, ss } = syncFor();
151
- ss.scheduleScrollSync(50, 50);
152
- rafCb?.(0);
153
- expect(ctx.scrollVersion).toBe(1);
154
- expect(ctx.scrollSyncRaf).toBeNull();
155
- });
156
- it('flush pushes the row offset through domToLogicalRowOffset when row virtualization is on', () => {
157
- const setScrollOffset = vi.fn();
158
- const { ss } = syncFor({
159
- rowVirtualizationEnabled: true,
160
- domToLogicalRowOffset: (n) => n * 2,
161
- virtualizer: { setScrollOffset },
162
- });
163
- ss.scheduleScrollSync(30, 0);
164
- rafCb?.(0);
165
- expect(setScrollOffset).toHaveBeenCalledWith(60);
166
- });
167
- it('flush pushes the horizontal offset when column virtualization is on', () => {
168
- const setHorizontalOffset = vi.fn();
169
- const { ss } = syncFor({
170
- columnVirtualizationEnabled: true,
171
- columnVirtualizer: { setHorizontalOffset },
172
- });
173
- ss.scheduleScrollSync(0, 88);
174
- rafCb?.(0);
175
- expect(setHorizontalOffset).toHaveBeenCalledWith(88);
176
- });
177
- it('flush skips both virtualizers when neither is enabled', () => {
178
- const { ctx, ss } = syncFor();
179
- ss.scheduleScrollSync(5, 5);
180
- rafCb?.(0);
181
- expect(ctx.virtualizer.setScrollOffset).not.toHaveBeenCalled();
182
- expect(ctx.columnVirtualizer.setHorizontalOffset).not.toHaveBeenCalled();
183
- });
184
- });
185
- describe('onBodyScroll', () => {
186
- let rafCb = null;
187
- beforeEach(() => {
188
- rafCb = null;
189
- vi.stubGlobal('requestAnimationFrame', (cb) => {
190
- rafCb = cb;
191
- return 7;
192
- });
193
- });
194
- afterEach(() => {
195
- vi.unstubAllGlobals();
196
- });
197
- function scrollEvent(container) {
198
- return { currentTarget: container };
199
- }
200
- function scroller(props) {
201
- const el = document.createElement('div');
202
- Object.defineProperty(el, 'scrollTop', { value: props.scrollTop ?? 0, configurable: true });
203
- Object.defineProperty(el, 'scrollLeft', { value: props.scrollLeft ?? 0, configurable: true });
204
- Object.defineProperty(el, 'scrollHeight', { value: props.scrollHeight ?? 0, configurable: true });
205
- Object.defineProperty(el, 'clientHeight', { value: props.clientHeight ?? 0, configurable: true });
206
- return el;
207
- }
208
- it('does nothing when there is no current target', () => {
209
- const { ctx, ss } = syncFor();
210
- ss.onBodyScroll(scrollEvent(null));
211
- expect(ctx.pendingScrollTop).toBe(0);
212
- });
213
- it('records the container scroll offsets via scheduleScrollSync', () => {
214
- const { ctx, ss } = syncFor();
215
- const el = scroller({ scrollTop: 90, scrollLeft: 12 });
216
- ss.onBodyScroll(scrollEvent(el));
217
- expect(ctx.pendingScrollTop).toBe(90);
218
- expect(ctx.pendingScrollLeft).toBe(12);
219
- expect(ctx.scrollSyncRaf).toBe(7);
220
- });
221
- it('closes open column/operator menus on scroll', () => {
222
- const closeMenus = vi.fn();
223
- const { ss } = syncFor({ columnMenuFor: 'x', closeMenus });
224
- ss.onBodyScroll(scrollEvent(scroller({})));
225
- expect(closeMenus).toHaveBeenCalled();
226
- });
227
- it('closes menus when an operator menu is open', () => {
228
- const closeMenus = vi.fn();
229
- const { ss } = syncFor({ operatorMenuFor: 'op', closeMenus });
230
- ss.onBodyScroll(scrollEvent(scroller({})));
231
- expect(closeMenus).toHaveBeenCalled();
232
- });
233
- it('does not close menus when none are open', () => {
234
- const closeMenus = vi.fn();
235
- const { ss } = syncFor({ closeMenus });
236
- ss.onBodyScroll(scrollEvent(scroller({})));
237
- expect(closeMenus).not.toHaveBeenCalled();
238
- });
239
- it('fires onScrollBottomReached once when the scroll reaches the bottom', () => {
240
- const onScrollBottomReached = vi.fn();
241
- const { ctx, ss } = syncFor({
242
- props: { onScrollBottomReached },
243
- scrollBottomArmed: true,
244
- });
245
- // scrollTop + clientHeight >= scrollHeight - 32 -> at bottom.
246
- const el = scroller({ scrollTop: 600, clientHeight: 400, scrollHeight: 1000 });
247
- ss.onBodyScroll(scrollEvent(el));
248
- expect(onScrollBottomReached).toHaveBeenCalledWith({
249
- scrollTop: 600,
250
- scrollHeight: 1000,
251
- clientHeight: 400,
252
- });
253
- expect(ctx.scrollBottomArmed).toBe(false); // disarmed so it won't refire
254
- });
255
- it('does not refire onScrollBottomReached while still at the bottom (disarmed)', () => {
256
- const onScrollBottomReached = vi.fn();
257
- const { ss } = syncFor({
258
- props: { onScrollBottomReached },
259
- scrollBottomArmed: false,
260
- });
261
- const el = scroller({ scrollTop: 600, clientHeight: 400, scrollHeight: 1000 });
262
- ss.onBodyScroll(scrollEvent(el));
263
- expect(onScrollBottomReached).not.toHaveBeenCalled();
264
- });
265
- it('re-arms the trigger after scrolling away from the bottom', () => {
266
- const onScrollBottomReached = vi.fn();
267
- const { ctx, ss } = syncFor({
268
- props: { onScrollBottomReached },
269
- scrollBottomArmed: false,
270
- });
271
- // Not at bottom: scrollTop + clientHeight < scrollHeight - 32.
272
- const el = scroller({ scrollTop: 100, clientHeight: 400, scrollHeight: 1000 });
273
- ss.onBodyScroll(scrollEvent(el));
274
- expect(ctx.scrollBottomArmed).toBe(true);
275
- expect(onScrollBottomReached).not.toHaveBeenCalled();
276
- });
277
- it('skips the bottom-reached logic entirely when no callback is registered', () => {
278
- const { ctx, ss } = syncFor({ scrollBottomArmed: true });
279
- const el = scroller({ scrollTop: 600, clientHeight: 400, scrollHeight: 1000 });
280
- ss.onBodyScroll(scrollEvent(el));
281
- // Armed flag is untouched when there is no callback.
282
- expect(ctx.scrollBottomArmed).toBe(true);
283
- });
284
- });
285
- describe('createScrollSync wiring', () => {
286
- it('exposes the documented handler surface', () => {
287
- const { ss } = syncFor();
288
- expect(Object.keys(ss).sort()).toEqual(['flushScheduledScrollSync', 'hideTooltip', 'onBodyScroll', 'scheduleScrollSync', 'showTooltipFor']);
289
- });
290
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,55 +0,0 @@
1
- /**
2
- * Unit tests for multiple-range (Ctrl+drag) cell selection, driven through the
3
- * pure range helpers of createSelection(ctx) with a minimal fake ctx.
4
- */
5
- import { describe, expect, it } from 'vitest';
6
- import { createSelection } from './selection';
7
- function makeCtx() {
8
- return {
9
- enableCellSelectionEffective: true,
10
- selectionRange: { anchor: null, focus: null },
11
- selectionRanges: [],
12
- };
13
- }
14
- describe('multiple range selection', () => {
15
- it('a plain selection replaces any committed ranges', () => {
16
- const ctx = makeCtx();
17
- const s = createSelection(ctx);
18
- s.setSelection(0, 0);
19
- s.extendSelection(1, 1); // active range 0,0..1,1
20
- s.setSelection(5, 5, true); // additive: commit prior, start new
21
- expect(ctx.selectionRanges.length).toBe(1);
22
- s.setSelection(9, 9, false); // plain: clears committed
23
- expect(ctx.selectionRanges.length).toBe(0);
24
- });
25
- it('Ctrl+drag commits the prior range and keeps both highlighted', () => {
26
- const ctx = makeCtx();
27
- const s = createSelection(ctx);
28
- s.setSelection(0, 0);
29
- s.extendSelection(1, 1); // range A: rows 0-1, cols 0-1
30
- s.setSelection(3, 3, true); // start range B additively
31
- s.extendSelection(4, 4); // range B: rows 3-4, cols 3-4
32
- const rects = s.getSelectionRects();
33
- expect(rects.length).toBe(2);
34
- // both ranges report cells as selected
35
- expect(s.isCellInSelectedRange(0, 0)).toBe(true);
36
- expect(s.isCellInSelectedRange(1, 1)).toBe(true);
37
- expect(s.isCellInSelectedRange(4, 4)).toBe(true);
38
- // a cell in neither is not selected
39
- expect(s.isCellInSelectedRange(2, 2)).toBe(false);
40
- });
41
- it('getCellRangeEdges outlines each range independently', () => {
42
- const ctx = makeCtx();
43
- const s = createSelection(ctx);
44
- s.setSelection(0, 0);
45
- s.extendSelection(1, 1);
46
- s.setSelection(3, 3, true);
47
- s.extendSelection(4, 4);
48
- // top-left corner of range A
49
- expect(s.getCellRangeEdges(0, 0)).toEqual({ top: true, bottom: false, left: true, right: false });
50
- // bottom-right corner of range B
51
- expect(s.getCellRangeEdges(4, 4)).toEqual({ top: false, bottom: true, left: false, right: true });
52
- // outside every range
53
- expect(s.getCellRangeEdges(2, 2)).toBeNull();
54
- });
55
- });
@@ -1 +0,0 @@
1
- export {};