@svgrid/grid 1.0.2 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +137 -39
  3. package/dist/GridFooter.svelte +164 -0
  4. package/dist/GridFooter.svelte.d.ts +29 -0
  5. package/dist/GridMenus.svelte +648 -0
  6. package/dist/GridMenus.svelte.d.ts +31 -0
  7. package/dist/SvGrid.controller.svelte.d.ts +472 -0
  8. package/dist/SvGrid.controller.svelte.js +1917 -0
  9. package/dist/SvGrid.css +2012 -0
  10. package/dist/SvGrid.helpers.d.ts +35 -0
  11. package/dist/SvGrid.helpers.js +160 -0
  12. package/dist/SvGrid.helpers.test.d.ts +1 -0
  13. package/dist/SvGrid.helpers.test.js +298 -0
  14. package/dist/SvGrid.svelte +2346 -8742
  15. package/dist/SvGrid.svelte.d.ts +4 -357
  16. package/dist/SvGrid.types.d.ts +523 -0
  17. package/dist/SvGrid.types.js +1 -0
  18. package/dist/SvGridChart.svelte +1060 -23
  19. package/dist/SvGridChart.svelte.d.ts +17 -0
  20. package/dist/aligned-grids.d.ts +6 -0
  21. package/dist/aligned-grids.js +84 -0
  22. package/dist/aligned-grids.test.d.ts +1 -0
  23. package/dist/aligned-grids.test.js +75 -0
  24. package/dist/build-api.coverage.test.d.ts +20 -0
  25. package/dist/build-api.coverage.test.js +505 -0
  26. package/dist/build-api.d.ts +5 -0
  27. package/dist/build-api.js +557 -0
  28. package/dist/cell-render.d.ts +15 -0
  29. package/dist/cell-render.js +246 -0
  30. package/dist/cell-render.test.d.ts +1 -0
  31. package/dist/cell-render.test.js +338 -0
  32. package/dist/cell-values.d.ts +28 -0
  33. package/dist/cell-values.js +89 -0
  34. package/dist/chart-export.test.d.ts +1 -0
  35. package/dist/chart-export.test.js +302 -0
  36. package/dist/chart.coverage.test.d.ts +1 -0
  37. package/dist/chart.coverage.test.js +748 -0
  38. package/dist/chart.d.ts +370 -3
  39. package/dist/chart.js +1135 -42
  40. package/dist/clipboard.d.ts +15 -0
  41. package/dist/clipboard.js +420 -0
  42. package/dist/clipboard.test.d.ts +1 -0
  43. package/dist/clipboard.test.js +700 -0
  44. package/dist/collaboration.coverage.test.d.ts +1 -0
  45. package/dist/collaboration.coverage.test.js +200 -0
  46. package/dist/column-groups.d.ts +19 -0
  47. package/dist/column-groups.js +62 -0
  48. package/dist/column-groups.test.d.ts +1 -0
  49. package/dist/column-groups.test.js +56 -0
  50. package/dist/column-types.d.ts +10 -0
  51. package/dist/column-types.js +63 -0
  52. package/dist/column-types.test.d.ts +1 -0
  53. package/dist/column-types.test.js +62 -0
  54. package/dist/columns.d.ts +30 -0
  55. package/dist/columns.js +277 -0
  56. package/dist/columns.test.d.ts +1 -0
  57. package/dist/columns.test.js +625 -0
  58. package/dist/core.d.ts +86 -1
  59. package/dist/css.d.ts +3 -0
  60. package/dist/editing.d.ts +31 -0
  61. package/dist/editing.js +529 -0
  62. package/dist/editing.test.d.ts +1 -0
  63. package/dist/editing.test.js +732 -0
  64. package/dist/editors/cell-editors.coverage.test.d.ts +1 -0
  65. package/dist/editors/cell-editors.coverage.test.js +139 -0
  66. package/dist/editors/cell-editors.d.ts +1 -1
  67. package/dist/facet-buckets.d.ts +13 -0
  68. package/dist/facet-buckets.js +54 -0
  69. package/dist/facet-buckets.test.d.ts +1 -0
  70. package/dist/facet-buckets.test.js +296 -0
  71. package/dist/features.d.ts +5 -0
  72. package/dist/features.js +30 -0
  73. package/dist/filter-operators.d.ts +16 -0
  74. package/dist/filter-operators.js +69 -0
  75. package/dist/filter-operators.test.d.ts +1 -0
  76. package/dist/filter-operators.test.js +135 -0
  77. package/dist/hyperformula-adapter.d.ts +82 -0
  78. package/dist/hyperformula-adapter.js +73 -0
  79. package/dist/hyperformula-adapter.test.d.ts +1 -0
  80. package/dist/hyperformula-adapter.test.js +205 -0
  81. package/dist/index.d.ts +9 -3
  82. package/dist/index.js +8 -2
  83. package/dist/keyboard-handlers.coverage.test.d.ts +1 -0
  84. package/dist/keyboard-handlers.coverage.test.js +495 -0
  85. package/dist/keyboard-handlers.d.ts +7 -0
  86. package/dist/keyboard-handlers.js +202 -0
  87. package/dist/menus.d.ts +40 -0
  88. package/dist/menus.js +390 -0
  89. package/dist/menus.test.d.ts +1 -0
  90. package/dist/menus.test.js +560 -0
  91. package/dist/named-views.coverage.test.d.ts +1 -0
  92. package/dist/named-views.coverage.test.js +180 -0
  93. package/dist/named-views.d.ts +27 -0
  94. package/dist/named-views.js +39 -0
  95. package/dist/row-drag.d.ts +49 -0
  96. package/dist/row-drag.js +221 -0
  97. package/dist/row-drag.test.d.ts +1 -0
  98. package/dist/row-drag.test.js +142 -0
  99. package/dist/row-resize.d.ts +43 -0
  100. package/dist/row-resize.js +158 -0
  101. package/dist/row-resize.test.d.ts +1 -0
  102. package/dist/row-resize.test.js +329 -0
  103. package/dist/scroll-sync.d.ts +9 -0
  104. package/dist/scroll-sync.js +89 -0
  105. package/dist/scroll-sync.test.d.ts +1 -0
  106. package/dist/scroll-sync.test.js +290 -0
  107. package/dist/selection.d.ts +32 -0
  108. package/dist/selection.js +427 -0
  109. package/dist/selection.multi-range.test.d.ts +1 -0
  110. package/dist/selection.multi-range.test.js +55 -0
  111. package/dist/selection.test.d.ts +1 -0
  112. package/dist/selection.test.js +647 -0
  113. package/dist/server-data-source.coverage.test.d.ts +1 -0
  114. package/dist/server-data-source.coverage.test.js +154 -0
  115. package/dist/spreadsheet.d.ts +110 -0
  116. package/dist/spreadsheet.js +242 -0
  117. package/dist/spreadsheet.test.d.ts +1 -0
  118. package/dist/spreadsheet.test.js +446 -0
  119. package/dist/summaries.d.ts +12 -0
  120. package/dist/summaries.js +65 -0
  121. package/dist/sv-grid-scrollbar.js +13 -1
  122. package/dist/svgrid-wrapper.types.d.ts +31 -1
  123. package/dist/svgrid.behavior.test.js +20 -0
  124. package/dist/svgrid.comments-autocomplete.test.d.ts +1 -0
  125. package/dist/svgrid.comments-autocomplete.test.js +96 -0
  126. package/dist/svgrid.context-menu.test.d.ts +1 -0
  127. package/dist/svgrid.context-menu.test.js +102 -0
  128. package/dist/svgrid.interaction.test.js +31 -0
  129. package/dist/svgrid.new-features.wrapper.test.js +64 -6
  130. package/dist/svgrid.wrapper.test.js +27 -1
  131. package/dist/test-setup.js +9 -3
  132. package/dist/virtualization/column-virtualizer.d.ts +2 -0
  133. package/dist/virtualization/scroll-scaling.d.ts +45 -0
  134. package/dist/virtualization/scroll-scaling.js +99 -0
  135. package/dist/virtualization/scroll-scaling.test.d.ts +1 -0
  136. package/dist/virtualization/scroll-scaling.test.js +127 -0
  137. package/dist/virtualization/svelte-virtualizer.svelte.d.ts +2 -0
  138. package/dist/virtualization/svelte-virtualizer.svelte.js +2 -0
  139. package/dist/virtualization/virtualizer.d.ts +7 -0
  140. package/dist/virtualization/virtualizer.js +30 -0
  141. package/package.json +2 -1
  142. package/src/GridFooter.svelte +164 -0
  143. package/src/GridMenus.svelte +648 -0
  144. package/src/SvGrid.controller.svelte.ts +2352 -0
  145. package/src/SvGrid.css +2012 -0
  146. package/src/SvGrid.helpers.test.ts +415 -0
  147. package/src/SvGrid.helpers.ts +185 -0
  148. package/src/SvGrid.svelte +2346 -8742
  149. package/src/SvGrid.types.ts +537 -0
  150. package/src/SvGridChart.svelte +1060 -23
  151. package/src/aligned-grids.test.ts +80 -0
  152. package/src/aligned-grids.ts +87 -0
  153. package/src/build-api.coverage.test.ts +532 -0
  154. package/src/build-api.ts +683 -0
  155. package/src/cell-render.test.ts +451 -0
  156. package/src/cell-render.ts +426 -0
  157. package/src/cell-values.ts +114 -0
  158. package/src/chart-export.test.ts +370 -0
  159. package/src/chart.coverage.test.ts +814 -0
  160. package/src/chart.ts +1352 -47
  161. package/src/clipboard.test.ts +780 -0
  162. package/src/clipboard.ts +552 -0
  163. package/src/collaboration.coverage.test.ts +220 -0
  164. package/src/column-groups.test.ts +59 -0
  165. package/src/column-groups.ts +80 -0
  166. package/src/column-types.test.ts +68 -0
  167. package/src/column-types.ts +82 -0
  168. package/src/columns.test.ts +702 -0
  169. package/src/columns.ts +419 -0
  170. package/src/core.ts +86 -0
  171. package/src/css.d.ts +3 -0
  172. package/src/editing.test.ts +837 -0
  173. package/src/editing.ts +669 -0
  174. package/src/editors/cell-editors.coverage.test.ts +156 -0
  175. package/src/editors/cell-editors.ts +1 -0
  176. package/src/facet-buckets.test.ts +353 -0
  177. package/src/facet-buckets.ts +67 -0
  178. package/src/features.ts +128 -0
  179. package/src/filter-operators.test.ts +174 -0
  180. package/src/filter-operators.ts +87 -0
  181. package/src/hyperformula-adapter.test.ts +256 -0
  182. package/src/hyperformula-adapter.ts +124 -0
  183. package/src/index.ts +49 -0
  184. package/src/keyboard-handlers.coverage.test.ts +560 -0
  185. package/src/keyboard-handlers.ts +353 -0
  186. package/src/keyboard.ts +97 -97
  187. package/src/menus.test.ts +620 -0
  188. package/src/menus.ts +555 -0
  189. package/src/named-views.coverage.test.ts +210 -0
  190. package/src/named-views.ts +48 -0
  191. package/src/row-drag.test.ts +168 -0
  192. package/src/row-drag.ts +255 -0
  193. package/src/row-resize.test.ts +369 -0
  194. package/src/row-resize.ts +171 -0
  195. package/src/scroll-sync.test.ts +330 -0
  196. package/src/scroll-sync.ts +218 -0
  197. package/src/selection.multi-range.test.ts +61 -0
  198. package/src/selection.test.ts +722 -0
  199. package/src/selection.ts +579 -0
  200. package/src/server-data-source.coverage.test.ts +180 -0
  201. package/src/spreadsheet.test.ts +489 -0
  202. package/src/spreadsheet.ts +304 -0
  203. package/src/summaries.ts +204 -0
  204. package/src/sv-grid-scrollbar.ts +13 -1
  205. package/src/svgrid-wrapper.types.ts +31 -1
  206. package/src/svgrid.behavior.test.ts +22 -0
  207. package/src/svgrid.comments-autocomplete.test.ts +112 -0
  208. package/src/svgrid.context-menu.test.ts +126 -0
  209. package/src/svgrid.interaction.test.ts +30 -0
  210. package/src/svgrid.new-features.wrapper.test.ts +67 -6
  211. package/src/svgrid.wrapper.test.ts +27 -1
  212. package/src/test-setup.ts +9 -6
  213. package/src/virtualization/scroll-scaling.test.ts +148 -0
  214. package/src/virtualization/scroll-scaling.ts +121 -0
  215. package/src/virtualization/svelte-virtualizer.svelte.ts +2 -0
  216. package/src/virtualization/virtualizer.ts +26 -0
@@ -0,0 +1,290 @@
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
+ });
@@ -0,0 +1,32 @@
1
+ import { type RowData, type TableFeatures } from "./index";
2
+ import "./sv-grid-scrollbar";
3
+ export declare function createSelection<TFeatures extends TableFeatures = TableFeatures, TData extends RowData = RowData>(ctx: any): {
4
+ isRowSelected: (rowId: string) => boolean;
5
+ toggleRowSelectionById: (rowId: string) => void;
6
+ toggleSelectAllRows: () => void;
7
+ setActiveCell: (rowIndex: number, colIndex: number) => void;
8
+ scrollActiveCellIntoView: (rowIndex: number, colIndex: number) => void;
9
+ setSelection: (rowIndex: number, colIndex: number, additive?: boolean) => void;
10
+ extendSelection: (rowIndex: number, colIndex: number) => void;
11
+ isCellInSelectedRange: (rowIndex: number, colIndex: number) => boolean;
12
+ getCellRangeEdges: (rowIndex: number, colIndex: number) => {
13
+ top: boolean;
14
+ bottom: boolean;
15
+ left: boolean;
16
+ right: boolean;
17
+ } | null;
18
+ getSelectionRects: () => {
19
+ minRow: number;
20
+ maxRow: number;
21
+ minCol: number;
22
+ maxCol: number;
23
+ }[];
24
+ isInFillPreview: (rowIndex: number, colIndex: number) => boolean;
25
+ findColumnById: (columnId: string) => any;
26
+ onCellPointerDown: (rowIndex: number, colIndex: number, event: PointerEvent) => void;
27
+ onCellPointerEnter: (rowIndex: number, colIndex: number) => void;
28
+ endDragSelection: () => void;
29
+ onWindowPointerMove: (event: PointerEvent) => void;
30
+ onCellClick: (rowIndex: number, colIndex: number) => void;
31
+ emitCellDoubleClick: (rowIndex: number, colIndex: number) => void;
32
+ };