@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,43 @@
1
+ /**
2
+ * Row-resize Svelte action - drag the bottom edge of a row to grow /
3
+ * shrink it. Pair with a function-valued `rowHeight` prop so the grid
4
+ * reads per-row heights from a reactive store.
5
+ *
6
+ * The action is OFF until a consumer attaches it AND a row-header
7
+ * gutter cell exists in each row. A row-header cell is any TD with
8
+ * the `sv-row-gutter` class (typically the one rendering the row
9
+ * number 1, 2, 3, ...). Demos opt in by setting
10
+ * `cellClass: 'sv-row-gutter'` on the gutter column.
11
+ *
12
+ * <script>
13
+ * let heights = $state<Record<number, number>>({})
14
+ * let resizeOn = $state(false)
15
+ * const rowHeight = (i: number) => heights[i] ?? 32
16
+ * function onResize(i: number, h: number) { heights = { ...heights, [i]: h } }
17
+ * </script>
18
+ *
19
+ * <div use:rowResize={{ onResize, disabled: !resizeOn }}>
20
+ * <SvGrid columns={[{ field:'rn', cellClass:'sv-row-gutter', ... }, ...]}
21
+ * rowHeight={rowHeight} ... />
22
+ * </div>
23
+ *
24
+ * Visual: the strip sits along the bottom edge of the row-header
25
+ * cell, 5px tall, transparent by default, accent-tinted on hover -
26
+ * matching the column resize handle's look. Cursor is `row-resize`.
27
+ */
28
+ export type RowResizeOptions = {
29
+ /** Called when the user releases the drag with the final height. */
30
+ onResize: (rowIndex: number, height: number) => void;
31
+ /** Optional callback fired during the drag (every pointermove). */
32
+ onResizeMove?: (rowIndex: number, height: number) => void;
33
+ /** Min row height in px. Default 20. */
34
+ min?: number;
35
+ /** Max row height in px. Default 320. */
36
+ max?: number;
37
+ /** When true, the action removes its strips and ignores events. */
38
+ disabled?: boolean;
39
+ };
40
+ export declare function rowResize(node: HTMLElement, opts: RowResizeOptions): {
41
+ update(next: RowResizeOptions): void;
42
+ destroy(): void;
43
+ };
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Row-resize Svelte action - drag the bottom edge of a row to grow /
3
+ * shrink it. Pair with a function-valued `rowHeight` prop so the grid
4
+ * reads per-row heights from a reactive store.
5
+ *
6
+ * The action is OFF until a consumer attaches it AND a row-header
7
+ * gutter cell exists in each row. A row-header cell is any TD with
8
+ * the `sv-row-gutter` class (typically the one rendering the row
9
+ * number 1, 2, 3, ...). Demos opt in by setting
10
+ * `cellClass: 'sv-row-gutter'` on the gutter column.
11
+ *
12
+ * <script>
13
+ * let heights = $state<Record<number, number>>({})
14
+ * let resizeOn = $state(false)
15
+ * const rowHeight = (i: number) => heights[i] ?? 32
16
+ * function onResize(i: number, h: number) { heights = { ...heights, [i]: h } }
17
+ * </script>
18
+ *
19
+ * <div use:rowResize={{ onResize, disabled: !resizeOn }}>
20
+ * <SvGrid columns={[{ field:'rn', cellClass:'sv-row-gutter', ... }, ...]}
21
+ * rowHeight={rowHeight} ... />
22
+ * </div>
23
+ *
24
+ * Visual: the strip sits along the bottom edge of the row-header
25
+ * cell, 5px tall, transparent by default, accent-tinted on hover -
26
+ * matching the column resize handle's look. Cursor is `row-resize`.
27
+ */
28
+ const STRIP_CLASS = 'sv-grid-row-resize-handle';
29
+ export function rowResize(node, opts) {
30
+ let current = opts;
31
+ let drag = null;
32
+ function rowIndexOf(tr) {
33
+ const dataRow = tr.querySelector('[data-svgrid-row]');
34
+ const val = dataRow?.dataset.svgridRow;
35
+ return val != null ? Number(val) : NaN;
36
+ }
37
+ function onPointerMove(e) {
38
+ if (!drag)
39
+ return;
40
+ const min = current.min ?? 20;
41
+ const max = current.max ?? 320;
42
+ const next = Math.max(min, Math.min(max, drag.startHeight + (e.clientY - drag.startY)));
43
+ drag.trEl.style.height = `${Math.round(next)}px`;
44
+ current.onResizeMove?.(drag.rowIndex, Math.round(next));
45
+ }
46
+ function onPointerUp(e) {
47
+ if (!drag)
48
+ return;
49
+ const min = current.min ?? 20;
50
+ const max = current.max ?? 320;
51
+ const next = Math.max(min, Math.min(max, drag.startHeight + (e.clientY - drag.startY)));
52
+ current.onResize(drag.rowIndex, Math.round(next));
53
+ drag.strip.classList.remove('is-resizing');
54
+ try {
55
+ drag.trEl.releasePointerCapture(e.pointerId);
56
+ }
57
+ catch { /* ignore */ }
58
+ drag = null;
59
+ window.removeEventListener('pointermove', onPointerMove);
60
+ window.removeEventListener('pointerup', onPointerUp);
61
+ document.body.style.cursor = '';
62
+ }
63
+ function onPointerDown(e) {
64
+ if (current.disabled)
65
+ return;
66
+ const t = e.target;
67
+ if (!t?.classList.contains(STRIP_CLASS))
68
+ return;
69
+ const tr = t.closest('tr.sv-grid-row');
70
+ if (!tr)
71
+ return;
72
+ const rowIndex = rowIndexOf(tr);
73
+ if (!Number.isFinite(rowIndex))
74
+ return;
75
+ e.preventDefault();
76
+ e.stopPropagation();
77
+ t.classList.add('is-resizing');
78
+ drag = {
79
+ rowIndex,
80
+ startY: e.clientY,
81
+ startHeight: tr.getBoundingClientRect().height,
82
+ trEl: tr,
83
+ strip: t,
84
+ };
85
+ try {
86
+ tr.setPointerCapture(e.pointerId);
87
+ }
88
+ catch { /* ignore */ }
89
+ document.body.style.cursor = 'row-resize';
90
+ window.addEventListener('pointermove', onPointerMove);
91
+ window.addEventListener('pointerup', onPointerUp);
92
+ }
93
+ /** Inject one strip into every row's gutter cell. When disabled or
94
+ * when a row lacks a `.sv-row-gutter` cell, no strip is added. */
95
+ function decorate() {
96
+ if (current.disabled) {
97
+ removeAllStrips();
98
+ return;
99
+ }
100
+ const rows = node.querySelectorAll('tr.sv-grid-row');
101
+ for (const tr of rows) {
102
+ if (tr.classList.contains('sv-grid-header-row'))
103
+ continue;
104
+ if (tr.classList.contains('sv-grid-row-spacer'))
105
+ continue;
106
+ const gutter = tr.querySelector('.sv-grid-cell.sv-row-gutter');
107
+ if (!gutter)
108
+ continue;
109
+ if (gutter.querySelector(`:scope > .${STRIP_CLASS}`))
110
+ continue;
111
+ // Anchor the strip to the gutter cell + allow it to overflow
112
+ // downward into the row gap so the hit-area straddles the
113
+ // row boundary the way Excel does.
114
+ if (getComputedStyle(gutter).position === 'static')
115
+ gutter.style.position = 'relative';
116
+ gutter.style.overflow = 'visible';
117
+ const strip = document.createElement('div');
118
+ strip.className = STRIP_CLASS;
119
+ strip.setAttribute('role', 'separator');
120
+ strip.setAttribute('aria-orientation', 'horizontal');
121
+ strip.setAttribute('aria-label', 'Resize row');
122
+ // Inline the geometry + pointer-events so the strip works even
123
+ // before SvGrid.css is parsed; the hover tint still comes from
124
+ // the stylesheet. We keep the strip fully inside the gutter
125
+ // cell (no negative offset) to avoid stacking-context surprises
126
+ // with pinned / virtualised neighbour cells.
127
+ // 5px tall + sitting flush with the row bottom matches the
128
+ // column resize handle's 5px width.
129
+ strip.style.cssText =
130
+ 'position:absolute;left:0;right:0;bottom:0;height:5px;' +
131
+ 'cursor:row-resize;user-select:none;z-index:60;pointer-events:auto;';
132
+ gutter.appendChild(strip);
133
+ }
134
+ }
135
+ function removeAllStrips() {
136
+ node.querySelectorAll(`.${STRIP_CLASS}`).forEach((el) => el.remove());
137
+ }
138
+ node.addEventListener('pointerdown', onPointerDown, { capture: true });
139
+ const observer = new MutationObserver(() => decorate());
140
+ observer.observe(node, { childList: true, subtree: true });
141
+ decorate();
142
+ return {
143
+ update(next) {
144
+ const wasDisabled = current.disabled;
145
+ current = next;
146
+ // Toggle: when going from enabled <-> disabled, repaint immediately.
147
+ if (wasDisabled !== current.disabled)
148
+ decorate();
149
+ },
150
+ destroy() {
151
+ node.removeEventListener('pointerdown', onPointerDown, { capture: true });
152
+ window.removeEventListener('pointermove', onPointerMove);
153
+ window.removeEventListener('pointerup', onPointerUp);
154
+ observer.disconnect();
155
+ removeAllStrips();
156
+ },
157
+ };
158
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,329 @@
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
+ });
@@ -0,0 +1,9 @@
1
+ import { type RowData, type TableFeatures } from "./index";
2
+ import "./sv-grid-scrollbar";
3
+ export declare function createScrollSync<TFeatures extends TableFeatures = TableFeatures, TData extends RowData = RowData>(ctx: any): {
4
+ showTooltipFor: (el: HTMLElement, text: string) => void;
5
+ hideTooltip: () => void;
6
+ flushScheduledScrollSync: () => void;
7
+ scheduleScrollSync: (scrollTop: number, scrollLeft: number) => void;
8
+ onBodyScroll: (event: Event) => void;
9
+ };
@@ -0,0 +1,89 @@
1
+ import "./sv-grid-scrollbar";
2
+ export function createScrollSync(ctx) {
3
+ function showTooltipFor(el, text) {
4
+ if (!text)
5
+ return;
6
+ if (ctx.tooltipTimer)
7
+ window.clearTimeout(ctx.tooltipTimer);
8
+ ctx.tooltipTimer = window.setTimeout(() => {
9
+ const rect = el.getBoundingClientRect();
10
+ const vw = window.innerWidth;
11
+ const vh = window.innerHeight;
12
+ const below = rect.bottom + 64 < vh;
13
+ // Clamp x so the 280px-wide tooltip doesn't fall off the viewport.
14
+ const x = Math.min(Math.max(rect.left + 6, 10), vw - 290);
15
+ const y = below ? rect.bottom + 6 : rect.top - 6;
16
+ ctx.tooltip = { text, x, y, below };
17
+ }, 250);
18
+ }
19
+ function hideTooltip() {
20
+ if (ctx.tooltipTimer) {
21
+ window.clearTimeout(ctx.tooltipTimer);
22
+ ctx.tooltipTimer = null;
23
+ }
24
+ ctx.tooltip = null;
25
+ }
26
+ function flushScheduledScrollSync() {
27
+ ctx.scrollSyncRaf = null;
28
+ ctx.scrollVersion += 1;
29
+ if (ctx.rowVirtualizationEnabled)
30
+ ctx.virtualizer.setScrollOffset(ctx.domToLogicalRowOffset(ctx.pendingScrollTop));
31
+ if (ctx.columnVirtualizationEnabled)
32
+ ctx.columnVirtualizer.setHorizontalOffset(ctx.pendingScrollLeft);
33
+ }
34
+ /**
35
+ * Sync the virtualizer to the user's scroll position once per frame.
36
+ *
37
+ * The browser's smooth-scroll animation fires a `scroll` event on
38
+ * every frame of the ~250 ms ramp after each wheel notch - so a
39
+ * single wheel notch produces ~16 calls to `onBodyScroll`. Without
40
+ * batching, each one ran a full virtualizer recalc + Svelte re-render
41
+ * synchronously, which (a) made the work pile up on heavy demos and
42
+ * (b) read on screen as "the grid keeps scrolling after the wheel
43
+ * stopped" because each scroll event ticked the rendered window one
44
+ * row at a time over a quarter-second.
45
+ *
46
+ * Batching to a single rAF flush per frame means each animation
47
+ * frame produces ONE virtualizer update at the latest known scroll
48
+ * position. Smooth-scroll still feels smooth (the browser is still
49
+ * animating `scrollTop`), but the grid's per-frame cost is bounded
50
+ * and the visible rows match the current `scrollTop` exactly when
51
+ * the wheel stops - no trailing updates.
52
+ */
53
+ function scheduleScrollSync(scrollTop, scrollLeft) {
54
+ ctx.pendingScrollTop = scrollTop;
55
+ ctx.pendingScrollLeft = scrollLeft;
56
+ if (ctx.scrollSyncRaf !== null)
57
+ return;
58
+ ctx.scrollSyncRaf = requestAnimationFrame(flushScheduledScrollSync);
59
+ }
60
+ function onBodyScroll(event) {
61
+ const container = event.currentTarget;
62
+ if (!container)
63
+ return;
64
+ if (ctx.columnMenuFor || ctx.operatorMenuFor)
65
+ ctx.closeMenus();
66
+ scheduleScrollSync(container.scrollTop, container.scrollLeft);
67
+ // Mirror horizontal scroll to any aligned grids in the same group.
68
+ if (ctx.props.alignedGridGroup != null)
69
+ ctx.broadcastAlignedScroll(container.scrollLeft);
70
+ if (ctx.props.onScrollBottomReached) {
71
+ const { scrollTop, scrollHeight, clientHeight } = container;
72
+ const atBottom = scrollTop + clientHeight >= scrollHeight - 32;
73
+ if (atBottom && ctx.scrollBottomArmed) {
74
+ ctx.scrollBottomArmed = false;
75
+ ctx.props.onScrollBottomReached({ scrollTop, scrollHeight, clientHeight });
76
+ }
77
+ else if (!atBottom && !ctx.scrollBottomArmed) {
78
+ ctx.scrollBottomArmed = true;
79
+ }
80
+ }
81
+ }
82
+ return {
83
+ showTooltipFor,
84
+ hideTooltip,
85
+ flushScheduledScrollSync,
86
+ scheduleScrollSync,
87
+ onBodyScroll,
88
+ };
89
+ }
@@ -0,0 +1 @@
1
+ export {};