@svgrid/grid 1.1.1 → 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 (188) hide show
  1. package/dist/FlexRender.svelte +96 -96
  2. package/dist/SvGrid.controller.svelte.js +17 -6
  3. package/dist/SvGrid.css +2012 -2012
  4. package/dist/SvGrid.svelte +2571 -2346
  5. package/dist/SvGridDropdown.svelte +7 -3
  6. package/dist/build-api.js +2 -2
  7. package/dist/cdn/svgrid.js +13504 -0
  8. package/dist/cdn/svgrid.svelte-external.js +11188 -0
  9. package/dist/cell-values.d.ts +1 -1
  10. package/dist/cell-values.js +7 -7
  11. package/dist/column-types.js +1 -1
  12. package/dist/core.d.ts +1 -1
  13. package/dist/core.js +2 -2
  14. package/dist/summaries.js +4 -4
  15. package/package.json +12 -2
  16. package/src/FlexRender.svelte +96 -96
  17. package/src/SvGrid.controller.svelte.ts +2363 -2352
  18. package/src/SvGrid.css +2012 -2012
  19. package/src/SvGrid.svelte +2571 -2346
  20. package/src/SvGrid.types.ts +537 -537
  21. package/src/SvGridDropdown.svelte +7 -3
  22. package/src/a11y.contract.test.ts +49 -49
  23. package/src/a11y.test.ts +59 -59
  24. package/src/a11y.ts +59 -59
  25. package/src/build-api.ts +683 -683
  26. package/src/cell-formatting.ts +169 -169
  27. package/src/cell-values.ts +4 -4
  28. package/src/column-types.ts +1 -1
  29. package/src/core.performance.test.ts +30 -30
  30. package/src/core.ts +1077 -1077
  31. package/src/createGrid.svelte.ts +42 -42
  32. package/src/createGrid.test.ts +10 -10
  33. package/src/createGridState.svelte.ts +17 -17
  34. package/src/editing.ts +669 -669
  35. package/src/flex-render.ts +3 -3
  36. package/src/index.ts +208 -208
  37. package/src/keyboard.test.ts +59 -59
  38. package/src/keyboard.ts +97 -97
  39. package/src/merge-objects.ts +48 -48
  40. package/src/render-component.ts +28 -28
  41. package/src/spreadsheet.test.ts +489 -489
  42. package/src/spreadsheet.ts +304 -304
  43. package/src/static-functions.ts +11 -11
  44. package/src/subscribe.ts +38 -38
  45. package/src/summaries.ts +4 -4
  46. package/src/svgrid-wrapper.types.ts +412 -412
  47. package/src/svgrid.features.test.ts +157 -157
  48. package/src/svgrid.wrapper.test.ts +40 -40
  49. package/src/virtualization/column-virtualizer.test.ts +27 -27
  50. package/src/virtualization/column-virtualizer.ts +30 -30
  51. package/src/virtualization/svelte-virtualizer.svelte.ts +26 -26
  52. package/src/virtualization/types.ts +30 -30
  53. package/src/virtualization/virtualizer.test.ts +47 -47
  54. package/src/virtualization/virtualizer.ts +296 -296
  55. package/dist/SvGrid.helpers.test.d.ts +0 -1
  56. package/dist/SvGrid.helpers.test.js +0 -298
  57. package/dist/SvGridChart.test.d.ts +0 -1
  58. package/dist/SvGridChart.test.js +0 -62
  59. package/dist/a11y.contract.test.d.ts +0 -1
  60. package/dist/a11y.contract.test.js +0 -39
  61. package/dist/a11y.test.d.ts +0 -1
  62. package/dist/a11y.test.js +0 -44
  63. package/dist/aligned-grids.test.d.ts +0 -1
  64. package/dist/aligned-grids.test.js +0 -75
  65. package/dist/build-api.coverage.test.d.ts +0 -20
  66. package/dist/build-api.coverage.test.js +0 -505
  67. package/dist/cell-formatting.test.d.ts +0 -1
  68. package/dist/cell-formatting.test.js +0 -234
  69. package/dist/cell-render.test.d.ts +0 -1
  70. package/dist/cell-render.test.js +0 -338
  71. package/dist/chart-export.test.d.ts +0 -1
  72. package/dist/chart-export.test.js +0 -302
  73. package/dist/chart.coverage.test.d.ts +0 -1
  74. package/dist/chart.coverage.test.js +0 -748
  75. package/dist/chart.test.d.ts +0 -1
  76. package/dist/chart.test.js +0 -289
  77. package/dist/clipboard.test.d.ts +0 -1
  78. package/dist/clipboard.test.js +0 -700
  79. package/dist/collaboration.coverage.test.d.ts +0 -1
  80. package/dist/collaboration.coverage.test.js +0 -200
  81. package/dist/collaboration.test.d.ts +0 -1
  82. package/dist/collaboration.test.js +0 -65
  83. package/dist/column-groups.test.d.ts +0 -1
  84. package/dist/column-groups.test.js +0 -56
  85. package/dist/column-types.test.d.ts +0 -1
  86. package/dist/column-types.test.js +0 -62
  87. package/dist/columns.test.d.ts +0 -1
  88. package/dist/columns.test.js +0 -625
  89. package/dist/conditional-formatting.test.d.ts +0 -1
  90. package/dist/conditional-formatting.test.js +0 -87
  91. package/dist/core.coverage.test.d.ts +0 -1
  92. package/dist/core.coverage.test.js +0 -186
  93. package/dist/core.performance.test.d.ts +0 -1
  94. package/dist/core.performance.test.js +0 -29
  95. package/dist/createGrid.test.d.ts +0 -1
  96. package/dist/createGrid.test.js +0 -9
  97. package/dist/editing.test.d.ts +0 -1
  98. package/dist/editing.test.js +0 -732
  99. package/dist/editors/cell-editors.coverage.test.d.ts +0 -1
  100. package/dist/editors/cell-editors.coverage.test.js +0 -139
  101. package/dist/editors/cell-editors.test.d.ts +0 -1
  102. package/dist/editors/cell-editors.test.js +0 -75
  103. package/dist/facet-buckets.test.d.ts +0 -1
  104. package/dist/facet-buckets.test.js +0 -296
  105. package/dist/fill-patterns.test.d.ts +0 -1
  106. package/dist/fill-patterns.test.js +0 -81
  107. package/dist/filter-operators.test.d.ts +0 -1
  108. package/dist/filter-operators.test.js +0 -135
  109. package/dist/filtering/excel-filters.test.d.ts +0 -1
  110. package/dist/filtering/excel-filters.test.js +0 -116
  111. package/dist/filtering/locale-filter.test.d.ts +0 -13
  112. package/dist/filtering/locale-filter.test.js +0 -189
  113. package/dist/flex-render.test.d.ts +0 -1
  114. package/dist/flex-render.test.js +0 -142
  115. package/dist/group-aggregate.test.d.ts +0 -1
  116. package/dist/group-aggregate.test.js +0 -32
  117. package/dist/hyperformula-adapter.test.d.ts +0 -1
  118. package/dist/hyperformula-adapter.test.js +0 -205
  119. package/dist/keyboard-handlers.coverage.test.d.ts +0 -1
  120. package/dist/keyboard-handlers.coverage.test.js +0 -495
  121. package/dist/keyboard.test.d.ts +0 -1
  122. package/dist/keyboard.test.js +0 -27
  123. package/dist/menus.test.d.ts +0 -1
  124. package/dist/menus.test.js +0 -560
  125. package/dist/named-views.coverage.test.d.ts +0 -1
  126. package/dist/named-views.coverage.test.js +0 -180
  127. package/dist/named-views.test.d.ts +0 -1
  128. package/dist/named-views.test.js +0 -57
  129. package/dist/new-features.test.d.ts +0 -1
  130. package/dist/new-features.test.js +0 -183
  131. package/dist/render-component.test.d.ts +0 -1
  132. package/dist/render-component.test.js +0 -41
  133. package/dist/row-drag.test.d.ts +0 -1
  134. package/dist/row-drag.test.js +0 -142
  135. package/dist/row-resize.test.d.ts +0 -1
  136. package/dist/row-resize.test.js +0 -329
  137. package/dist/scroll-sync.test.d.ts +0 -1
  138. package/dist/scroll-sync.test.js +0 -290
  139. package/dist/selection.multi-range.test.d.ts +0 -1
  140. package/dist/selection.multi-range.test.js +0 -55
  141. package/dist/selection.test.d.ts +0 -1
  142. package/dist/selection.test.js +0 -647
  143. package/dist/server-data-source.coverage.test.d.ts +0 -1
  144. package/dist/server-data-source.coverage.test.js +0 -154
  145. package/dist/server-data-source.test.d.ts +0 -1
  146. package/dist/server-data-source.test.js +0 -81
  147. package/dist/sparkline.test.d.ts +0 -1
  148. package/dist/sparkline.test.js +0 -52
  149. package/dist/spreadsheet.test.d.ts +0 -1
  150. package/dist/spreadsheet.test.js +0 -446
  151. package/dist/subscribe.test.d.ts +0 -1
  152. package/dist/subscribe.test.js +0 -93
  153. package/dist/svgrid.api-extensions.test.d.ts +0 -14
  154. package/dist/svgrid.api-extensions.test.js +0 -334
  155. package/dist/svgrid.api.test.d.ts +0 -15
  156. package/dist/svgrid.api.test.js +0 -169
  157. package/dist/svgrid.behavior.test.d.ts +0 -15
  158. package/dist/svgrid.behavior.test.js +0 -625
  159. package/dist/svgrid.column-reorder.test.d.ts +0 -15
  160. package/dist/svgrid.column-reorder.test.js +0 -224
  161. package/dist/svgrid.comments-autocomplete.test.d.ts +0 -1
  162. package/dist/svgrid.comments-autocomplete.test.js +0 -96
  163. package/dist/svgrid.context-menu.test.d.ts +0 -1
  164. package/dist/svgrid.context-menu.test.js +0 -102
  165. package/dist/svgrid.features.test.d.ts +0 -1
  166. package/dist/svgrid.features.test.js +0 -129
  167. package/dist/svgrid.interaction.test.d.ts +0 -9
  168. package/dist/svgrid.interaction.test.js +0 -349
  169. package/dist/svgrid.locale-filtering.test.d.ts +0 -15
  170. package/dist/svgrid.locale-filtering.test.js +0 -261
  171. package/dist/svgrid.new-features.wrapper.test.d.ts +0 -1
  172. package/dist/svgrid.new-features.wrapper.test.js +0 -194
  173. package/dist/svgrid.row-pinning.test.d.ts +0 -14
  174. package/dist/svgrid.row-pinning.test.js +0 -250
  175. package/dist/svgrid.set-filter.test.d.ts +0 -17
  176. package/dist/svgrid.set-filter.test.js +0 -268
  177. package/dist/svgrid.wrapper.test.d.ts +0 -1
  178. package/dist/svgrid.wrapper.test.js +0 -59
  179. package/dist/test-setup.d.ts +0 -1
  180. package/dist/test-setup.js +0 -35
  181. package/dist/transaction.test.d.ts +0 -1
  182. package/dist/transaction.test.js +0 -89
  183. package/dist/virtualization/column-virtualizer.test.d.ts +0 -1
  184. package/dist/virtualization/column-virtualizer.test.js +0 -25
  185. package/dist/virtualization/scroll-scaling.test.d.ts +0 -1
  186. package/dist/virtualization/scroll-scaling.test.js +0 -127
  187. package/dist/virtualization/virtualizer.test.d.ts +0 -1
  188. package/dist/virtualization/virtualizer.test.js +0 -41
@@ -1,647 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest';
2
- import { createSelection } from './selection';
3
- // ---------------------------------------------------------------------------
4
- // Fake controller (`ctx`) helpers. The selection factory reads/writes plain
5
- // state on `ctx` and calls a small set of `ctx.grid.*` methods. We build the
6
- // minimal surface each tested path touches.
7
- // ---------------------------------------------------------------------------
8
- function makeGroupRow(id) {
9
- // isGroupRow() checks `typeof row.getCanExpand === 'function' && row.getCanExpand()`
10
- return { id, getCanExpand: () => true, toggleExpanded: vi.fn(), original: {} };
11
- }
12
- function makeDataRow(id, original = {}) {
13
- return {
14
- id,
15
- getCanExpand: () => false,
16
- original,
17
- getCellValueByColumnId: (colId) => original?.[colId],
18
- };
19
- }
20
- function makeColumn(id, columnDef = {}) {
21
- return { id, columnDef };
22
- }
23
- function makeCtx(overrides = {}) {
24
- let rowSelection = overrides.rowSelectionState ?? {};
25
- let activeCell = overrides.activeCell ?? null;
26
- const setRowSelection = vi.fn((updater) => {
27
- rowSelection =
28
- typeof updater === 'function' ? updater(rowSelection) : updater;
29
- ctx.rowSelectionState = rowSelection;
30
- });
31
- const setActiveCell = vi.fn((cell) => {
32
- activeCell = cell;
33
- });
34
- const ctx = {
35
- rowSelectionState: rowSelection,
36
- allRows: [],
37
- allColumns: [],
38
- headerSelectionState: 'none',
39
- userHasActivatedCell: false,
40
- enableCellSelectionEffective: true,
41
- selectionRange: { anchor: null, focus: null },
42
- isDraggingSelection: false,
43
- fillDrag: null,
44
- activeAtPointerDown: null,
45
- editingEnabled: false,
46
- editingCell: undefined,
47
- scrollContainer: null,
48
- rowVirtualizationEnabled: false,
49
- rowScrollScalingActive: false,
50
- renderedColumnItems: [],
51
- columnVirtualizer: null,
52
- theadEl: null,
53
- headerHeight: 0,
54
- props: {},
55
- gridRootEl: null,
56
- getCellDisplayValue: vi.fn((_r, _c, base) => base),
57
- toggleBooleanCell: vi.fn(),
58
- onCellDoubleClick: vi.fn(),
59
- onFillPointerUp: vi.fn(),
60
- onFillPointerMove: vi.fn(),
61
- grid: {
62
- setRowSelection,
63
- setActiveCell,
64
- getState: () => ({ activeCell }),
65
- },
66
- ...overrides,
67
- };
68
- ctx.rowSelectionState = rowSelection;
69
- return ctx;
70
- }
71
- describe('createSelection - row selection', () => {
72
- it('isRowSelected reflects rowSelectionState', () => {
73
- const ctx = makeCtx({ rowSelectionState: { r1: true, r2: false } });
74
- const sel = createSelection(ctx);
75
- expect(sel.isRowSelected('r1')).toBe(true);
76
- expect(sel.isRowSelected('r2')).toBe(false);
77
- expect(sel.isRowSelected('missing')).toBe(false);
78
- });
79
- it('toggleRowSelectionById flips the single row', () => {
80
- const ctx = makeCtx({ rowSelectionState: { r1: false } });
81
- const sel = createSelection(ctx);
82
- sel.toggleRowSelectionById('r1');
83
- expect(ctx.rowSelectionState.r1).toBe(true);
84
- sel.toggleRowSelectionById('r1');
85
- expect(ctx.rowSelectionState.r1).toBe(false);
86
- });
87
- it('toggleSelectAllRows selects every non-group row when not all selected', () => {
88
- const ctx = makeCtx({
89
- headerSelectionState: 'none',
90
- allRows: [makeDataRow('r1'), makeGroupRow('g1'), makeDataRow('r2')],
91
- });
92
- const sel = createSelection(ctx);
93
- sel.toggleSelectAllRows();
94
- expect(ctx.rowSelectionState.r1).toBe(true);
95
- expect(ctx.rowSelectionState.r2).toBe(true);
96
- // group row excluded
97
- expect(ctx.rowSelectionState.g1).toBeUndefined();
98
- });
99
- it('toggleSelectAllRows deselects all when header state is "all"', () => {
100
- const ctx = makeCtx({
101
- headerSelectionState: 'all',
102
- rowSelectionState: { r1: true, r2: true },
103
- allRows: [makeDataRow('r1'), makeDataRow('r2')],
104
- });
105
- const sel = createSelection(ctx);
106
- sel.toggleSelectAllRows();
107
- expect(ctx.rowSelectionState.r1).toBeUndefined();
108
- expect(ctx.rowSelectionState.r2).toBeUndefined();
109
- });
110
- });
111
- describe('createSelection - setActiveCell', () => {
112
- it('sets active cell and flags userHasActivatedCell', () => {
113
- const ctx = makeCtx({ allColumns: [makeColumn('a'), makeColumn('b')] });
114
- const sel = createSelection(ctx);
115
- sel.setActiveCell(2, 1);
116
- expect(ctx.userHasActivatedCell).toBe(true);
117
- expect(ctx.grid.setActiveCell).toHaveBeenCalledWith(expect.objectContaining({ rowIndex: 2, colIndex: 1 }));
118
- });
119
- it('fires onActiveCellChange with resolved columnId', () => {
120
- const onActiveCellChange = vi.fn();
121
- const ctx = makeCtx({
122
- allColumns: [makeColumn('a'), makeColumn('b')],
123
- props: { onActiveCellChange },
124
- });
125
- const sel = createSelection(ctx);
126
- sel.setActiveCell(0, 1);
127
- expect(onActiveCellChange).toHaveBeenCalledWith({
128
- rowIndex: 0,
129
- colIndex: 1,
130
- columnId: 'b',
131
- });
132
- });
133
- it('onActiveCellChange columnId falls back to "" when column missing', () => {
134
- const onActiveCellChange = vi.fn();
135
- const ctx = makeCtx({ allColumns: [], props: { onActiveCellChange } });
136
- const sel = createSelection(ctx);
137
- sel.setActiveCell(0, 5);
138
- expect(onActiveCellChange).toHaveBeenCalledWith(expect.objectContaining({ columnId: '' }));
139
- });
140
- });
141
- describe('createSelection - range math', () => {
142
- it('setSelection sets anchor and focus to the same point', () => {
143
- const ctx = makeCtx();
144
- const sel = createSelection(ctx);
145
- sel.setSelection(3, 4);
146
- expect(ctx.selectionRange).toEqual({
147
- anchor: { rowIndex: 3, colIndex: 4 },
148
- focus: { rowIndex: 3, colIndex: 4 },
149
- });
150
- });
151
- it('setSelection is a no-op when cell selection disabled', () => {
152
- const ctx = makeCtx({ enableCellSelectionEffective: false });
153
- const before = ctx.selectionRange;
154
- const sel = createSelection(ctx);
155
- sel.setSelection(1, 1);
156
- expect(ctx.selectionRange).toBe(before);
157
- });
158
- it('extendSelection keeps the existing anchor and moves focus', () => {
159
- const ctx = makeCtx({
160
- selectionRange: { anchor: { rowIndex: 1, colIndex: 1 }, focus: { rowIndex: 1, colIndex: 1 } },
161
- });
162
- const sel = createSelection(ctx);
163
- sel.extendSelection(4, 5);
164
- expect(ctx.selectionRange.anchor).toEqual({ rowIndex: 1, colIndex: 1 });
165
- expect(ctx.selectionRange.focus).toEqual({ rowIndex: 4, colIndex: 5 });
166
- });
167
- it('extendSelection uses the new point as anchor when none exists', () => {
168
- const ctx = makeCtx({ selectionRange: { anchor: null, focus: null } });
169
- const sel = createSelection(ctx);
170
- sel.extendSelection(2, 3);
171
- expect(ctx.selectionRange.anchor).toEqual({ rowIndex: 2, colIndex: 3 });
172
- expect(ctx.selectionRange.focus).toEqual({ rowIndex: 2, colIndex: 3 });
173
- });
174
- it('extendSelection is a no-op when cell selection disabled', () => {
175
- const ctx = makeCtx({ enableCellSelectionEffective: false });
176
- const before = ctx.selectionRange;
177
- const sel = createSelection(ctx);
178
- sel.extendSelection(1, 1);
179
- expect(ctx.selectionRange).toBe(before);
180
- });
181
- it('isCellInSelectedRange covers normalized ranges (anchor > focus)', () => {
182
- const ctx = makeCtx({
183
- selectionRange: { anchor: { rowIndex: 4, colIndex: 4 }, focus: { rowIndex: 1, colIndex: 1 } },
184
- });
185
- const sel = createSelection(ctx);
186
- expect(sel.isCellInSelectedRange(2, 3)).toBe(true);
187
- expect(sel.isCellInSelectedRange(1, 1)).toBe(true);
188
- expect(sel.isCellInSelectedRange(4, 4)).toBe(true);
189
- expect(sel.isCellInSelectedRange(0, 0)).toBe(false);
190
- expect(sel.isCellInSelectedRange(5, 5)).toBe(false);
191
- });
192
- it('isCellInSelectedRange returns false when no range', () => {
193
- const ctx = makeCtx({ selectionRange: { anchor: null, focus: null } });
194
- const sel = createSelection(ctx);
195
- expect(sel.isCellInSelectedRange(0, 0)).toBe(false);
196
- });
197
- });
198
- describe('createSelection - getCellRangeEdges', () => {
199
- it('returns null outside the range', () => {
200
- const ctx = makeCtx({
201
- selectionRange: { anchor: { rowIndex: 1, colIndex: 1 }, focus: { rowIndex: 3, colIndex: 3 } },
202
- });
203
- const sel = createSelection(ctx);
204
- expect(sel.getCellRangeEdges(0, 0)).toBeNull();
205
- expect(sel.getCellRangeEdges(5, 5)).toBeNull();
206
- });
207
- it('returns null when range unset', () => {
208
- const ctx = makeCtx();
209
- const sel = createSelection(ctx);
210
- expect(sel.getCellRangeEdges(0, 0)).toBeNull();
211
- });
212
- it('marks all four edges for a single-cell range', () => {
213
- const ctx = makeCtx({
214
- selectionRange: { anchor: { rowIndex: 2, colIndex: 2 }, focus: { rowIndex: 2, colIndex: 2 } },
215
- });
216
- const sel = createSelection(ctx);
217
- expect(sel.getCellRangeEdges(2, 2)).toEqual({ top: true, bottom: true, left: true, right: true });
218
- });
219
- it('flags only the corner edges for a corner cell of a wider range', () => {
220
- const ctx = makeCtx({
221
- selectionRange: { anchor: { rowIndex: 1, colIndex: 1 }, focus: { rowIndex: 3, colIndex: 3 } },
222
- });
223
- const sel = createSelection(ctx);
224
- expect(sel.getCellRangeEdges(1, 1)).toEqual({ top: true, bottom: false, left: true, right: false });
225
- expect(sel.getCellRangeEdges(2, 2)).toEqual({ top: false, bottom: false, left: false, right: false });
226
- expect(sel.getCellRangeEdges(3, 3)).toEqual({ top: false, bottom: true, left: false, right: true });
227
- });
228
- });
229
- describe('createSelection - isInFillPreview', () => {
230
- it('returns false when no fill drag active', () => {
231
- const ctx = makeCtx({ fillDrag: null });
232
- const sel = createSelection(ctx);
233
- expect(sel.isInFillPreview(0, 0)).toBe(false);
234
- });
235
- it('returns false for cells outside the preview rectangle', () => {
236
- const ctx = makeCtx({
237
- fillDrag: { sourceMinRow: 0, sourceMaxRow: 1, sourceMinCol: 0, sourceMaxCol: 0, targetRow: 3, targetCol: 0 },
238
- });
239
- const sel = createSelection(ctx);
240
- expect(sel.isInFillPreview(5, 0)).toBe(false);
241
- expect(sel.isInFillPreview(0, 5)).toBe(false);
242
- });
243
- it('returns true for cells in the preview but outside the source', () => {
244
- const ctx = makeCtx({
245
- fillDrag: { sourceMinRow: 0, sourceMaxRow: 1, sourceMinCol: 0, sourceMaxCol: 0, targetRow: 3, targetCol: 0 },
246
- });
247
- const sel = createSelection(ctx);
248
- expect(sel.isInFillPreview(2, 0)).toBe(true); // below source, within preview
249
- expect(sel.isInFillPreview(0, 0)).toBe(false); // inside the source range
250
- });
251
- });
252
- describe('createSelection - findColumnById', () => {
253
- it('finds a column by id or returns undefined', () => {
254
- const ctx = makeCtx({ allColumns: [makeColumn('a'), makeColumn('b')] });
255
- const sel = createSelection(ctx);
256
- expect(sel.findColumnById('b')?.id).toBe('b');
257
- expect(sel.findColumnById('zzz')).toBeUndefined();
258
- });
259
- });
260
- describe('createSelection - onCellPointerDown', () => {
261
- function baseCtx(over = {}) {
262
- return makeCtx({
263
- allRows: [makeDataRow('r0'), makeDataRow('r1')],
264
- allColumns: [makeColumn('c0', { editorType: 'text' }), makeColumn('c1', { editorType: 'text' })],
265
- ...over,
266
- });
267
- }
268
- it('ignores non-left button', () => {
269
- const ctx = baseCtx();
270
- const sel = createSelection(ctx);
271
- sel.onCellPointerDown(0, 0, { button: 2 });
272
- expect(ctx.grid.setActiveCell).not.toHaveBeenCalled();
273
- });
274
- it('ignores group rows', () => {
275
- const ctx = baseCtx({ allRows: [makeGroupRow('g0')] });
276
- const sel = createSelection(ctx);
277
- sel.onCellPointerDown(0, 0, { button: 0, shiftKey: false });
278
- expect(ctx.grid.setActiveCell).not.toHaveBeenCalled();
279
- });
280
- it('ignores checkbox columns (by editorType)', () => {
281
- const ctx = baseCtx({
282
- allColumns: [makeColumn('c0', { editorType: 'checkbox' })],
283
- });
284
- const sel = createSelection(ctx);
285
- sel.onCellPointerDown(0, 0, { button: 0, shiftKey: false });
286
- expect(ctx.grid.setActiveCell).not.toHaveBeenCalled();
287
- });
288
- it('ignores boolean-valued cells', () => {
289
- const ctx = baseCtx({
290
- getCellDisplayValue: vi.fn(() => true),
291
- });
292
- const sel = createSelection(ctx);
293
- sel.onCellPointerDown(0, 0, { button: 0, shiftKey: false });
294
- expect(ctx.grid.setActiveCell).not.toHaveBeenCalled();
295
- });
296
- it('plain click sets active + selection and starts a drag', () => {
297
- const ctx = baseCtx();
298
- const sel = createSelection(ctx);
299
- sel.onCellPointerDown(1, 1, { button: 0, shiftKey: false });
300
- expect(ctx.isDraggingSelection).toBe(true);
301
- expect(ctx.selectionRange.anchor).toEqual({ rowIndex: 1, colIndex: 1 });
302
- expect(ctx.grid.setActiveCell).toHaveBeenCalled();
303
- expect(ctx.activeAtPointerDown).toBeNull();
304
- });
305
- it('shift click extends the existing range without starting a drag', () => {
306
- const ctx = baseCtx({
307
- selectionRange: { anchor: { rowIndex: 0, colIndex: 0 }, focus: { rowIndex: 0, colIndex: 0 } },
308
- activeCell: { rowIndex: 0, colIndex: 0 },
309
- });
310
- const sel = createSelection(ctx);
311
- sel.onCellPointerDown(1, 1, { button: 0, shiftKey: true });
312
- expect(ctx.isDraggingSelection).toBe(false);
313
- expect(ctx.selectionRange.anchor).toEqual({ rowIndex: 0, colIndex: 0 });
314
- expect(ctx.selectionRange.focus).toEqual({ rowIndex: 1, colIndex: 1 });
315
- expect(ctx.activeAtPointerDown).toEqual({ rowIndex: 0, colIndex: 0 });
316
- });
317
- });
318
- describe('createSelection - onCellPointerEnter / drag', () => {
319
- it('does nothing when not dragging', () => {
320
- const ctx = makeCtx({ isDraggingSelection: false, allRows: [makeDataRow('r0')] });
321
- const sel = createSelection(ctx);
322
- sel.onCellPointerEnter(0, 0);
323
- expect(ctx.grid.setActiveCell).not.toHaveBeenCalled();
324
- });
325
- it('extends selection and moves active cell while dragging', () => {
326
- const ctx = makeCtx({
327
- isDraggingSelection: true,
328
- selectionRange: { anchor: { rowIndex: 0, colIndex: 0 }, focus: { rowIndex: 0, colIndex: 0 } },
329
- allRows: [makeDataRow('r0'), makeDataRow('r1')],
330
- allColumns: [makeColumn('c0'), makeColumn('c1')],
331
- });
332
- const sel = createSelection(ctx);
333
- sel.onCellPointerEnter(1, 1);
334
- expect(ctx.selectionRange.focus).toEqual({ rowIndex: 1, colIndex: 1 });
335
- expect(ctx.grid.setActiveCell).toHaveBeenCalled();
336
- });
337
- it('ignores group rows while dragging', () => {
338
- const ctx = makeCtx({ isDraggingSelection: true, allRows: [makeGroupRow('g0')] });
339
- const sel = createSelection(ctx);
340
- sel.onCellPointerEnter(0, 0);
341
- expect(ctx.grid.setActiveCell).not.toHaveBeenCalled();
342
- });
343
- });
344
- describe('createSelection - endDragSelection / window move', () => {
345
- it('endDragSelection clears the drag flag', () => {
346
- const ctx = makeCtx({ isDraggingSelection: true });
347
- const sel = createSelection(ctx);
348
- sel.endDragSelection();
349
- expect(ctx.isDraggingSelection).toBe(false);
350
- });
351
- it('endDragSelection commits a pending fill drag', () => {
352
- const ctx = makeCtx({ isDraggingSelection: true, fillDrag: { x: 1 } });
353
- const sel = createSelection(ctx);
354
- sel.endDragSelection();
355
- expect(ctx.onFillPointerUp).toHaveBeenCalled();
356
- });
357
- it('onWindowPointerMove delegates to fill move when fill active', () => {
358
- const ctx = makeCtx({ fillDrag: { x: 1 } });
359
- const sel = createSelection(ctx);
360
- const ev = { buttons: 1 };
361
- sel.onWindowPointerMove(ev);
362
- expect(ctx.onFillPointerMove).toHaveBeenCalledWith(ev);
363
- });
364
- it('onWindowPointerMove ignores when not dragging and no fill', () => {
365
- const ctx = makeCtx({ fillDrag: null, isDraggingSelection: false });
366
- const sel = createSelection(ctx);
367
- sel.onWindowPointerMove({ buttons: 0 });
368
- expect(ctx.onFillPointerUp).not.toHaveBeenCalled();
369
- });
370
- it('onWindowPointerMove ends the drag when no buttons held', () => {
371
- const ctx = makeCtx({ fillDrag: null, isDraggingSelection: true });
372
- const sel = createSelection(ctx);
373
- sel.onWindowPointerMove({ buttons: 0 });
374
- expect(ctx.isDraggingSelection).toBe(false);
375
- });
376
- it('onWindowPointerMove keeps the drag while a button is held', () => {
377
- const ctx = makeCtx({ fillDrag: null, isDraggingSelection: true });
378
- const sel = createSelection(ctx);
379
- sel.onWindowPointerMove({ buttons: 1 });
380
- expect(ctx.isDraggingSelection).toBe(true);
381
- });
382
- });
383
- describe('createSelection - onCellClick', () => {
384
- function clickCtx(over = {}) {
385
- return makeCtx({
386
- allRows: [makeDataRow('r0', { id: 0 }), makeDataRow('r1', { id: 1 })],
387
- allColumns: [makeColumn('c0', { editorType: 'text' }), makeColumn('c1', { editorType: 'text' })],
388
- gridRootEl: { focus: vi.fn() },
389
- ...over,
390
- });
391
- }
392
- it('returns early when row or column missing', () => {
393
- const ctx = clickCtx({ allRows: [] });
394
- const sel = createSelection(ctx);
395
- sel.onCellClick(0, 0);
396
- expect(ctx.gridRootEl.focus).not.toHaveBeenCalled();
397
- });
398
- it('toggles expansion for a group row', () => {
399
- const group = makeGroupRow('g0');
400
- const ctx = clickCtx({ allRows: [group] });
401
- const sel = createSelection(ctx);
402
- sel.onCellClick(0, 0);
403
- expect(group.toggleExpanded).toHaveBeenCalled();
404
- expect(ctx.grid.setActiveCell).toHaveBeenCalled();
405
- });
406
- it('emits onCellClick and onRowClick for data cells', () => {
407
- const onCellClick = vi.fn();
408
- const onRowClick = vi.fn();
409
- const ctx = clickCtx({ props: { onCellClick, onRowClick } });
410
- const sel = createSelection(ctx);
411
- sel.onCellClick(1, 0);
412
- expect(onCellClick).toHaveBeenCalledWith(expect.objectContaining({ rowIndex: 1, colIndex: 0, columnId: 'c0' }));
413
- expect(onRowClick).toHaveBeenCalledWith(expect.objectContaining({ rowIndex: 1, columnId: 'c0' }));
414
- });
415
- it('toggles a checkbox cell and clears editing', () => {
416
- const ctx = clickCtx({
417
- allColumns: [makeColumn('c0', { editorType: 'checkbox' })],
418
- editingCell: { rowIndex: 0, colIndex: 0 },
419
- });
420
- const sel = createSelection(ctx);
421
- sel.onCellClick(0, 0);
422
- expect(ctx.toggleBooleanCell).toHaveBeenCalledWith(0, 0);
423
- expect(ctx.editingCell).toBeNull();
424
- expect(ctx.selectionRange.anchor).toEqual({ rowIndex: 0, colIndex: 0 });
425
- });
426
- it('enters edit mode when clicking the previously-active editable cell', () => {
427
- const ctx = clickCtx({
428
- editingEnabled: true,
429
- activeAtPointerDown: { rowIndex: 0, colIndex: 0 },
430
- });
431
- const sel = createSelection(ctx);
432
- sel.onCellClick(0, 0);
433
- expect(ctx.onCellDoubleClick).toHaveBeenCalledWith(0, 0);
434
- });
435
- it('clears editing when not re-clicking the active cell', () => {
436
- const ctx = clickCtx({
437
- editingEnabled: true,
438
- activeAtPointerDown: { rowIndex: 1, colIndex: 1 },
439
- editingCell: { rowIndex: 0, colIndex: 0 },
440
- });
441
- const sel = createSelection(ctx);
442
- sel.onCellClick(0, 0);
443
- expect(ctx.onCellDoubleClick).not.toHaveBeenCalled();
444
- expect(ctx.editingCell).toBeNull();
445
- });
446
- });
447
- describe('createSelection - emitCellDoubleClick', () => {
448
- it('emits the public double-click events and runs edit entry', () => {
449
- const onCellDoubleClick = vi.fn();
450
- const onRowDoubleClick = vi.fn();
451
- const ctx = makeCtx({
452
- allRows: [makeDataRow('r0', { id: 0 })],
453
- allColumns: [makeColumn('c0', { editorType: 'text' })],
454
- props: { onCellDoubleClick, onRowDoubleClick },
455
- });
456
- const sel = createSelection(ctx);
457
- sel.emitCellDoubleClick(0, 0);
458
- expect(onCellDoubleClick).toHaveBeenCalledWith(expect.objectContaining({ rowIndex: 0, colIndex: 0, columnId: 'c0' }));
459
- expect(onRowDoubleClick).toHaveBeenCalled();
460
- expect(ctx.onCellDoubleClick).toHaveBeenCalledWith(0, 0);
461
- });
462
- it('skips the public events for group rows but still runs edit entry', () => {
463
- const onCellDoubleClick = vi.fn();
464
- const ctx = makeCtx({
465
- allRows: [makeGroupRow('g0')],
466
- allColumns: [makeColumn('c0')],
467
- props: { onCellDoubleClick },
468
- });
469
- const sel = createSelection(ctx);
470
- sel.emitCellDoubleClick(0, 0);
471
- expect(onCellDoubleClick).not.toHaveBeenCalled();
472
- expect(ctx.onCellDoubleClick).toHaveBeenCalledWith(0, 0);
473
- });
474
- });
475
- describe('createSelection - scrollActiveCellIntoView', () => {
476
- it('returns early without a scroll container', () => {
477
- const ctx = makeCtx({ scrollContainer: null });
478
- const sel = createSelection(ctx);
479
- expect(() => sel.scrollActiveCellIntoView(0, 0)).not.toThrow();
480
- });
481
- it('returns early for out-of-bounds indices', () => {
482
- const container = document.createElement('div');
483
- const ctx = makeCtx({
484
- scrollContainer: container,
485
- allRows: [makeDataRow('r0')],
486
- allColumns: [makeColumn('c0')],
487
- });
488
- const sel = createSelection(ctx);
489
- // rowIndex out of range -> early return, no throw
490
- expect(() => sel.scrollActiveCellIntoView(5, 0)).not.toThrow();
491
- expect(() => sel.scrollActiveCellIntoView(0, 5)).not.toThrow();
492
- });
493
- it('adjusts scrollLeft in non-virtualized mode using column virtualizer offsets', () => {
494
- const container = document.createElement('div');
495
- Object.defineProperty(container, 'clientWidth', { value: 100, configurable: true });
496
- Object.defineProperty(container, 'clientHeight', { value: 100, configurable: true });
497
- container.scrollLeft = 500;
498
- const ctx = makeCtx({
499
- scrollContainer: container,
500
- rowVirtualizationEnabled: false,
501
- allRows: [makeDataRow('r0'), makeDataRow('r1')],
502
- allColumns: [makeColumn('c0'), makeColumn('c1'), makeColumn('c2')],
503
- renderedColumnItems: [],
504
- columnVirtualizer: {
505
- getOffsetForIndex: (i) => i * 140,
506
- getSizeForIndex: () => 140,
507
- },
508
- theadEl: { offsetHeight: 0 },
509
- });
510
- const sel = createSelection(ctx);
511
- // target column 0 is left of the current scrollLeft -> scroll left to it
512
- sel.scrollActiveCellIntoView(0, 0);
513
- expect(container.scrollLeft).toBe(0);
514
- });
515
- it('virtualized: uses native scrollIntoView when the row is mounted', () => {
516
- const container = document.createElement('div');
517
- Object.defineProperty(container, 'clientWidth', { value: 100, configurable: true });
518
- Object.defineProperty(container, 'clientHeight', { value: 100, configurable: true });
519
- const tr = document.createElement('tr');
520
- tr.className = 'sv-grid-row';
521
- const cell = document.createElement('td');
522
- cell.setAttribute('data-svgrid-row', '0');
523
- tr.appendChild(cell);
524
- container.appendChild(tr);
525
- const scrollIntoView = vi.fn();
526
- tr.scrollIntoView = scrollIntoView;
527
- const ctx = makeCtx({
528
- scrollContainer: container,
529
- rowVirtualizationEnabled: true,
530
- allRows: [makeDataRow('r0')],
531
- allColumns: [makeColumn('c0')],
532
- renderedColumnItems: [{ index: 0, start: 0, size: 140 }],
533
- });
534
- const sel = createSelection(ctx);
535
- sel.scrollActiveCellIntoView(0, 0);
536
- expect(scrollIntoView).toHaveBeenCalledWith(expect.objectContaining({ block: 'nearest' }));
537
- });
538
- it('virtualized + scroll scaling: maps the logical offset into DOM space', () => {
539
- const container = document.createElement('div');
540
- Object.defineProperty(container, 'clientHeight', { value: 100, configurable: true });
541
- container.scrollTop = 0;
542
- const ctx = makeCtx({
543
- scrollContainer: container,
544
- rowVirtualizationEnabled: true,
545
- rowScrollScalingActive: true,
546
- allRows: [makeDataRow('r0')],
547
- allColumns: [makeColumn('c0')],
548
- theadEl: { offsetHeight: 10 },
549
- virtualizer: { getOffsetForIndex: () => 1000, getSizeForIndex: () => 20 },
550
- logicalToDomRowOffset: (n) => n / 2, // 1000 -> 500
551
- columnVirtualizer: { getOffsetForIndex: () => 0, getSizeForIndex: () => 140 },
552
- });
553
- const sel = createSelection(ctx);
554
- sel.scrollActiveCellIntoView(0, 0);
555
- // nextTop = max(500 - 10, 0) = 490
556
- expect(container.scrollTop).toBe(490);
557
- });
558
- it('virtualized: computes scrollTop manually when the row is offscreen', () => {
559
- const container = document.createElement('div');
560
- Object.defineProperty(container, 'clientHeight', { value: 100, configurable: true });
561
- container.scrollTop = 0;
562
- const ctx = makeCtx({
563
- scrollContainer: container,
564
- rowVirtualizationEnabled: true,
565
- rowScrollScalingActive: false,
566
- allRows: [makeDataRow('r0')],
567
- allColumns: [makeColumn('c0')],
568
- theadEl: { offsetHeight: 10 },
569
- virtualizer: { getOffsetForIndex: () => 500, getSizeForIndex: () => 30 },
570
- columnVirtualizer: { getOffsetForIndex: () => 0, getSizeForIndex: () => 140 },
571
- });
572
- const sel = createSelection(ctx);
573
- sel.scrollActiveCellIntoView(0, 0);
574
- // rowBottom = 10 + 500 + 30 = 540 > 0 + 100 -> nextTop = 540 - 100 = 440
575
- expect(container.scrollTop).toBe(440);
576
- });
577
- it('non-virtualized: scrolls up when the cell overlaps the sticky header', () => {
578
- const container = document.createElement('div');
579
- Object.defineProperty(container, 'clientHeight', { value: 200, configurable: true });
580
- Object.defineProperty(container, 'clientWidth', { value: 500, configurable: true });
581
- container.scrollTop = 100;
582
- container.scrollLeft = 0;
583
- container.getBoundingClientRect = () => ({ top: 0, left: 0, bottom: 200, right: 500 });
584
- const td = document.createElement('td');
585
- td.setAttribute('data-svgrid-row', '0');
586
- td.setAttribute('data-svgrid-col', '0');
587
- td.getBoundingClientRect = () => ({ top: 5, bottom: 35, left: 0, right: 140 });
588
- container.appendChild(td);
589
- const ctx = makeCtx({
590
- scrollContainer: container,
591
- rowVirtualizationEnabled: false,
592
- allRows: [makeDataRow('r0')],
593
- allColumns: [makeColumn('c0')],
594
- headerHeight: 30,
595
- theadEl: { offsetHeight: 30 },
596
- renderedColumnItems: [{ index: 0, start: 0, size: 140 }],
597
- });
598
- const sel = createSelection(ctx);
599
- sel.scrollActiveCellIntoView(0, 0);
600
- // cellTopInView (5) < headerHeight (30) -> nextTop = 100 + 5 - 30 = 75
601
- expect(container.scrollTop).toBe(75);
602
- });
603
- it('non-virtualized: scrolls down when the cell is past the bottom', () => {
604
- const container = document.createElement('div');
605
- Object.defineProperty(container, 'clientHeight', { value: 200, configurable: true });
606
- Object.defineProperty(container, 'clientWidth', { value: 500, configurable: true });
607
- container.scrollTop = 0;
608
- container.scrollLeft = 0;
609
- container.getBoundingClientRect = () => ({ top: 0, left: 0, bottom: 200, right: 500 });
610
- const td = document.createElement('td');
611
- td.setAttribute('data-svgrid-row', '0');
612
- td.setAttribute('data-svgrid-col', '0');
613
- td.getBoundingClientRect = () => ({ top: 250, bottom: 290, left: 0, right: 140 });
614
- container.appendChild(td);
615
- const ctx = makeCtx({
616
- scrollContainer: container,
617
- rowVirtualizationEnabled: false,
618
- allRows: [makeDataRow('r0')],
619
- allColumns: [makeColumn('c0')],
620
- headerHeight: 30,
621
- theadEl: { offsetHeight: 30 },
622
- renderedColumnItems: [{ index: 0, start: 0, size: 140 }],
623
- });
624
- const sel = createSelection(ctx);
625
- sel.scrollActiveCellIntoView(0, 0);
626
- // cellBotInView (290) > clientHeight (200) -> nextTop = 0 + 290 - 200 = 90
627
- expect(container.scrollTop).toBe(90);
628
- });
629
- it('scrolls right when the target column is past the viewport', () => {
630
- const container = document.createElement('div');
631
- Object.defineProperty(container, 'clientWidth', { value: 100, configurable: true });
632
- Object.defineProperty(container, 'clientHeight', { value: 100, configurable: true });
633
- container.scrollLeft = 0;
634
- const ctx = makeCtx({
635
- scrollContainer: container,
636
- rowVirtualizationEnabled: false,
637
- allRows: [makeDataRow('r0')],
638
- allColumns: [makeColumn('c0'), makeColumn('c1'), makeColumn('c2')],
639
- renderedColumnItems: [{ index: 2, start: 280, size: 140 }],
640
- theadEl: { offsetHeight: 0 },
641
- });
642
- const sel = createSelection(ctx);
643
- sel.scrollActiveCellIntoView(0, 2);
644
- // cellEnd (420) - clientWidth (100) = 320
645
- expect(container.scrollLeft).toBe(320);
646
- });
647
- });
@@ -1 +0,0 @@
1
- export {};