@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,194 +0,0 @@
1
- /**
2
- * Source-level smoke tests for the wrapper additions: `getRowId` prop,
3
- * `cellClass` / `rowClass` rendering, the column-layout API surface
4
- * (`setColumnWidth` / `getColumnWidths` / `setColumnPinning` /
5
- * `getColumnPinning`), the `between` operator UI, and the multi-cell
6
- * paste / cut keyboard plumbing.
7
- *
8
- * These are deliberately source-string assertions, not jsdom mounts -
9
- * Svelte 5 mount inside vitest is brittle (the existing
10
- * `svgrid.wrapper.test.ts` follows the same pattern). The behaviour
11
- * itself is covered by integration probes in the gallery (see the
12
- * pivot expansion + paste/cut probes that were run during build) and
13
- * the upstream unit tests of the headless engine + Pro pivot.
14
- */
15
- import { readFileSync } from 'node:fs';
16
- import { resolve } from 'node:path';
17
- import { describe, expect, it } from 'vitest';
18
- // The wrapper implementation spans SvGrid.svelte plus its extracted
19
- // sibling modules (types + pure helpers). Concatenate them so these
20
- // "the wrapper declares/exposes X" assertions hold wherever the code
21
- // physically lives.
22
- const source = [
23
- './SvGrid.svelte',
24
- './SvGrid.controller.svelte.ts',
25
- './GridMenus.svelte',
26
- './GridFooter.svelte',
27
- './SvGrid.types.ts',
28
- './SvGrid.helpers.ts',
29
- './filter-operators.ts',
30
- './facet-buckets.ts',
31
- './cell-values.ts',
32
- './clipboard.ts',
33
- './build-api.ts',
34
- './columns.ts',
35
- './selection.ts',
36
- './editing.ts',
37
- './cell-render.ts',
38
- './menus.ts',
39
- './summaries.ts',
40
- './keyboard-handlers.ts',
41
- './scroll-sync.ts',
42
- './features.ts',
43
- ]
44
- .map((p) => readFileSync(resolve(__dirname, p), 'utf-8'))
45
- .join('\n');
46
- const typesPath = resolve(__dirname, './svgrid-wrapper.types.ts');
47
- const types = readFileSync(typesPath, 'utf-8');
48
- describe('SvGrid wrapper - getRowId prop', () => {
49
- it('declares the getRowId prop on the Props type', () => {
50
- expect(source).toMatch(/getRowId\?:\s*\(row:\s*TData,\s*index:\s*number\)\s*=>\s*string/);
51
- });
52
- it('forwards the prop into createSvGrid options', () => {
53
- expect(source).toMatch(/get getRowId\(\)[\s\S]*?return props\.getRowId/);
54
- });
55
- });
56
- describe('SvGrid wrapper - cellClass + rowClass', () => {
57
- it('declares the rowClass prop on the Props type', () => {
58
- expect(source).toMatch(/rowClass\?:\s*\(ctx:\s*\{/);
59
- });
60
- it('exposes a resolveClassList helper that normalises array / record / string forms', () => {
61
- expect(source).toMatch(/function resolveClassList\(/);
62
- expect(source).toMatch(/Array\.isArray\(value\)/);
63
- });
64
- it('computes the row-level class once per render row and threads it onto the <tr>', () => {
65
- expect(source).toMatch(/function computeRowClass/);
66
- expect(source).toMatch(/userRowClass = computeRowClass\(row, rowIndex\)/);
67
- expect(source).toMatch(/class=\{`sv-grid-row \$\{userRowClass\}/);
68
- });
69
- it('computes the cell-level class per column and threads it onto the <td>', () => {
70
- expect(source).toMatch(/function computeCellClass/);
71
- expect(source).toMatch(/userCellClass = computeCellClass\(row, rendered\.column\)/);
72
- expect(source).toMatch(/class=\{`sv-grid-cell \$\{userCellClass\}`\}/);
73
- });
74
- });
75
- describe('SvGrid wrapper - column-layout API', () => {
76
- it('declares setColumnWidth + getColumnWidths in the public type', () => {
77
- expect(types).toContain('setColumnWidth(columnId: string, width: number): void');
78
- expect(types).toContain('getColumnWidths(): Record<string, number>');
79
- });
80
- it('declares setColumnPinning + getColumnPinning in the public type', () => {
81
- expect(types).toMatch(/setColumnPinning\(pinning:\s*\{/);
82
- expect(types).toContain('getColumnPinning(): { left: string[]; right: string[] }');
83
- });
84
- it('implements all four methods in the api object', () => {
85
- expect(source).toMatch(/setColumnWidth\(columnId: string, width: number\)/);
86
- expect(source).toMatch(/getColumnWidths\(\)/);
87
- expect(source).toMatch(/setColumnPinning\(pinning\)/);
88
- expect(source).toMatch(/getColumnPinning\(\)/);
89
- });
90
- it('clamps setColumnWidth to MIN_COLUMN_WIDTH', () => {
91
- // Confirm the clamp is in the code path so a caller can't drop a
92
- // column below the minimum by passing 0 or a negative number.
93
- expect(source).toMatch(/Math\.max\(MIN_COLUMN_WIDTH/);
94
- });
95
- it('defensive-copies setColumnPinning inputs so callers cannot mutate state', () => {
96
- expect(source).toMatch(/Array\.from\(new Set\(pinning\.left/);
97
- expect(source).toMatch(/Array\.from\(new Set\(pinning\.right/);
98
- });
99
- });
100
- describe('SvGrid wrapper - between filter operator', () => {
101
- it("includes 'between' in the FilterOperator type", () => {
102
- expect(source).toMatch(/"between"/);
103
- });
104
- it("includes 'between' in NUMBER_OPERATORS + DATE_OPERATORS but NOT in TEXT_OPERATORS", () => {
105
- // The list literals appear in order, so we slice each block out
106
- // separately and check membership.
107
- const numOps = source.match(/const NUMBER_OPERATORS[^]*?\];/)?.[0] ?? '';
108
- expect(numOps).toContain('"between"');
109
- const dateOps = source.match(/const DATE_OPERATORS[^]*?\];/)?.[0] ?? '';
110
- expect(dateOps).toContain('"between"');
111
- const textOps = source.match(/const TEXT_OPERATORS[^]*?\];/)?.[0] ?? '';
112
- expect(textOps).not.toContain('"between"');
113
- });
114
- it('renders a second input ("To") when the operator is between', () => {
115
- expect(source).toMatch(/menuActiveOperator === "between"/);
116
- expect(source).toMatch(/placeholder="To"/);
117
- });
118
- it('treats the filter as inactive until BOTH endpoints are non-empty', () => {
119
- // The active-filters filter() should require value AND valueTo.
120
- expect(source).toMatch(/if \(f\.operator === "between"\) \{[^}]*f\.value\.trim\(\)\.length > 0[^}]*f\.valueTo[^}]*\.trim\(\)\.length > 0/);
121
- });
122
- it('forwards valueTo through applyExcelFilter', () => {
123
- expect(source).toMatch(/valueTo:\s*(filter\.operator|op) === "between" \? (filter\.valueTo|valueTo) : undefined/);
124
- });
125
- it('publishes valueTo in the onFiltersChange payload only for between clauses', () => {
126
- expect(source).toMatch(/f\.operator === "between" && f\.valueTo\s*\?\s*\{ valueTo: f\.valueTo \}/);
127
- });
128
- it('exposes valueTo on the imperative setFilter input + getFilters output', () => {
129
- expect(types).toMatch(/setFilter\(\s*columnId: string,[\s\S]*?valueTo\?: string/);
130
- expect(types).toMatch(/getFilters\(\)[\s\S]*?valueTo\?: string/);
131
- });
132
- });
133
- describe('SvGrid wrapper - multi-cell paste + cut + delete', () => {
134
- it('fills the selection range when the clipboard payload is 1x1', () => {
135
- expect(source).toMatch(/clipboardIsSingleCell\s*=\s*\n?\s*lines\.length === 1 && \(lines\[0\]\?\.split\("\\t"\)\.length \?\? 0\) === 1/);
136
- expect(source).toMatch(/selectionIsRange = startRow !== endRow \|\| startCol !== endCol/);
137
- expect(source).toMatch(/fillRange = clipboardIsSingleCell && selectionIsRange/);
138
- });
139
- it('walks the entire selection rect when filling', () => {
140
- expect(source).toMatch(/const rowSpan = fillRange \? endRow - startRow \+ 1 : lines\.length/);
141
- expect(source).toMatch(/const colSpan = fillRange/);
142
- });
143
- it('implements clearSelectedCells() that touches every editable cell in the range', () => {
144
- expect(source).toMatch(/function clearSelectedCells\(\): boolean/);
145
- expect(source).toMatch(/parseEditorValue\(editorType, ""\)/);
146
- });
147
- it('wires Ctrl/Cmd+X to cutSelectionToClipboard', () => {
148
- expect(source).toMatch(/lower === "x"/);
149
- expect(source).toMatch(/void (?:ctx\.)?cutSelectionToClipboard\(\)/);
150
- expect(source).toMatch(/async function cutSelectionToClipboard/);
151
- // Confirm both calls live inside the cutSelectionToClipboard body
152
- // (copy first, then clear). A comment between them is fine.
153
- const body = source.match(/async function cutSelectionToClipboard\(\)[^{]*\{([\s\S]*?)^\s\s\}/m)?.[1] ?? '';
154
- expect(body).toContain('copySelectionToClipboard();');
155
- expect(body).toContain('clearSelectedCells();');
156
- expect(body.indexOf('copySelectionToClipboard()')).toBeLessThan(body.indexOf('clearSelectedCells()'));
157
- });
158
- it('wires Delete + Backspace to clearSelectedCells (without clipboard interaction)', () => {
159
- expect(source).toMatch(/event\.key === "Delete" \|\| event\.key === "Backspace"/);
160
- expect(source).toMatch(/if \((?:ctx\.)?clearSelectedCells\(\)\)\s*\{/);
161
- });
162
- // Regression: the controller's ctx is an object literal of getters, and the
163
- // copy/cut/paste handlers in keyboard-handlers + menus reach the functions
164
- // via `ctx.<name>()`. A refactor once shipped the `ctx.cutSelectionToClipboard`
165
- // / `ctx.pasteFromClipboard` CALLS but dropped their getters, so those threw
166
- // "is not a function" at runtime - copy worked, cut + paste were dead. Assert
167
- // every clipboard function called through ctx has a matching getter.
168
- it('exposes a ctx getter for every clipboard command it calls through ctx', () => {
169
- for (const fn of [
170
- 'copySelectionToClipboard',
171
- 'cutSelectionToClipboard',
172
- 'pasteFromClipboard',
173
- 'onGridPaste',
174
- 'clearSelectedCells',
175
- ]) {
176
- expect(source).toMatch(new RegExp(`get ${fn}\\(\\)\\s*\\{\\s*return ${fn};?\\s*\\}`));
177
- }
178
- });
179
- it('copy/cut fall back to execCommand when navigator.clipboard is absent (insecure context)', () => {
180
- expect(source).toMatch(/function writeClipboardText\(/);
181
- expect(source).toMatch(/document\.execCommand\("copy"\)/);
182
- });
183
- it('paste falls back to a native paste event when the async API is unavailable', () => {
184
- // keydown only preventDefaults (and uses the async API) in a secure context;
185
- // otherwise it lets the browser deliver a native paste event to onGridPaste.
186
- // Accept either the positive branch or the inverted early-return guard
187
- // (`if (!navigator.clipboard?.readText) return`) - both gate on the async API.
188
- expect(source).toMatch(/if \(!?navigator\.clipboard\?\.readText\)/);
189
- expect(source).toMatch(/function onGridPaste\(event: ClipboardEvent\)/);
190
- expect(source).toMatch(/clipboardData\?\.getData\("text\/plain"\)/);
191
- // The grid root wires the handler.
192
- expect(source).toMatch(/onpaste=\{onGridPaste\}/);
193
- });
194
- });
@@ -1,14 +0,0 @@
1
- /**
2
- * Component tests for the engine-level row pinning props
3
- * (`pinnedTopRows` / `pinnedBottomRows`). Mount a real <SvGrid>,
4
- * pass the props, then assert on the rendered DOM:
5
- *
6
- * - pinned-top / pinned-bottom <tbody>s are rendered
7
- * - each pinned row carries the expected class + data attributes
8
- * - column widths + cell values match the schema
9
- * - read-only invariants hold (no editor cell, no checkbox cell)
10
- * - reactive prop changes re-render
11
- * - stacking attributes (data-pinned-index) are present
12
- * - CSS variables for sticky offsets are set on the shell
13
- */
14
- export {};
@@ -1,250 +0,0 @@
1
- /**
2
- * Component tests for the engine-level row pinning props
3
- * (`pinnedTopRows` / `pinnedBottomRows`). Mount a real <SvGrid>,
4
- * pass the props, then assert on the rendered DOM:
5
- *
6
- * - pinned-top / pinned-bottom <tbody>s are rendered
7
- * - each pinned row carries the expected class + data attributes
8
- * - column widths + cell values match the schema
9
- * - read-only invariants hold (no editor cell, no checkbox cell)
10
- * - reactive prop changes re-render
11
- * - stacking attributes (data-pinned-index) are present
12
- * - CSS variables for sticky offsets are set on the shell
13
- */
14
- import { describe, expect, it } from 'vitest';
15
- import { mount, unmount, flushSync } from 'svelte';
16
- import SvGrid from './SvGrid.svelte';
17
- import { columnFilteringFeature, createCoreRowModel, createFilteredRowModel, createSortedRowModel, rowSortingFeature, sortFns, tableFeatures, } from './index';
18
- const features = tableFeatures({ columnFilteringFeature, rowSortingFeature });
19
- const rows = [
20
- { id: 'ACC-1', account: 'Helios', arr: 120000, seats: 40 },
21
- { id: 'ACC-2', account: 'Vertex', arr: 85000, seats: 22 },
22
- { id: 'ACC-3', account: 'Atlas', arr: 250000, seats: 80 },
23
- { id: 'ACC-4', account: 'Quantum', arr: 60000, seats: 15 },
24
- ];
25
- const cols = [
26
- { field: 'id', header: 'ID', width: 100, editable: false },
27
- { field: 'account', header: 'Account', width: 200, editable: false },
28
- { field: 'arr', header: 'ARR', width: 130, editable: false, align: 'right',
29
- format: { type: 'number', options: { style: 'currency', currency: 'USD', maximumFractionDigits: 0 } } },
30
- { field: 'seats', header: 'Seats', width: 90, editable: false, align: 'right' },
31
- ];
32
- function mountGrid(opts = {}) {
33
- return new Promise((res, rej) => {
34
- const target = document.createElement('div');
35
- document.body.appendChild(target);
36
- const propsState = { ...opts };
37
- let api = null;
38
- const app = mount(SvGrid, {
39
- target,
40
- props: {
41
- data: rows,
42
- columns: cols,
43
- features,
44
- _rowModels: {
45
- coreRowModel: createCoreRowModel(),
46
- filteredRowModel: createFilteredRowModel(),
47
- sortedRowModel: createSortedRowModel(sortFns),
48
- },
49
- containerHeight: 480,
50
- virtualization: false,
51
- columnVirtualization: false,
52
- enableInlineEditing: false,
53
- showPagination: false,
54
- showColumnFilters: false,
55
- showGlobalFilter: false,
56
- showRowSelection: false,
57
- pinnedTopRows: propsState.pinnedTopRows,
58
- pinnedBottomRows: propsState.pinnedBottomRows,
59
- onApiReady(received) {
60
- api = received;
61
- res({
62
- target,
63
- api,
64
- destroy: () => {
65
- unmount(app);
66
- target.remove();
67
- },
68
- setProps(next) {
69
- propsState.pinnedTopRows = next.pinnedTopRows;
70
- propsState.pinnedBottomRows = next.pinnedBottomRows;
71
- app
72
- .pinnedTopRows = next.pinnedTopRows;
73
- app
74
- .pinnedBottomRows = next.pinnedBottomRows;
75
- flushSync();
76
- },
77
- });
78
- },
79
- },
80
- });
81
- queueMicrotask(() => { if (!api)
82
- rej(new Error('onApiReady never fired')); });
83
- });
84
- }
85
- const tick = () => new Promise((r) => queueMicrotask(r));
86
- const TOTALS = {
87
- id: '⌃ TOTALS', account: 'All accounts',
88
- arr: rows.reduce((s, r) => s + r.arr, 0),
89
- seats: rows.reduce((s, r) => s + r.seats, 0),
90
- };
91
- const BENCHMARK = {
92
- id: '⌃ BENCH', account: 'Industry benchmark',
93
- arr: 180000, seats: 95,
94
- };
95
- const PAGE = {
96
- id: '⌄ PAGE', account: 'Visible page',
97
- arr: rows.reduce((s, r) => s + r.arr, 0),
98
- seats: rows.reduce((s, r) => s + r.seats, 0),
99
- };
100
- describe('SvGrid - pinnedTopRows render', () => {
101
- it('renders a pinned-top tbody when prop is provided', async () => {
102
- const { target, destroy } = await mountGrid({ pinnedTopRows: [TOTALS] });
103
- try {
104
- await tick();
105
- const topBody = target.querySelector('tbody.sv-grid-pinned-top-body');
106
- expect(topBody, 'pinned-top tbody should exist').not.toBeNull();
107
- const trs = topBody.querySelectorAll('tr.sv-grid-pinned-row-top');
108
- expect(trs.length).toBe(1);
109
- }
110
- finally {
111
- destroy();
112
- }
113
- });
114
- it('does NOT render the tbody when prop is empty / undefined', async () => {
115
- const { target, destroy } = await mountGrid({ pinnedTopRows: [] });
116
- try {
117
- await tick();
118
- const topBody = target.querySelector('tbody.sv-grid-pinned-top-body');
119
- expect(topBody).toBeNull();
120
- }
121
- finally {
122
- destroy();
123
- }
124
- });
125
- it('renders the row values using the column schema (format applied)', async () => {
126
- const { target, destroy } = await mountGrid({ pinnedTopRows: [TOTALS] });
127
- try {
128
- await tick();
129
- const tds = target
130
- .querySelectorAll('tr.sv-grid-pinned-row-top td');
131
- expect(tds.length).toBe(cols.length);
132
- // ARR cell should be currency-formatted ($515,000) - currency
133
- // symbol exact form may vary by ICU build; assert a "$" plus the
134
- // raw number with grouping is present.
135
- const arrCellText = (tds[2]?.textContent ?? '').trim();
136
- expect(arrCellText).toMatch(/\$/);
137
- expect(arrCellText).toContain('515');
138
- }
139
- finally {
140
- destroy();
141
- }
142
- });
143
- it('stacks multiple pinned-top rows with data-pinned-index', async () => {
144
- const { target, destroy } = await mountGrid({
145
- pinnedTopRows: [TOTALS, BENCHMARK],
146
- });
147
- try {
148
- await tick();
149
- const trs = target.querySelectorAll('tr.sv-grid-pinned-row-top');
150
- expect(trs.length).toBe(2);
151
- expect(trs[0].getAttribute('data-pinned-row')).toBe('top');
152
- expect(trs[0].getAttribute('data-pinned-index')).toBe('0');
153
- expect(trs[1].getAttribute('data-pinned-index')).toBe('1');
154
- }
155
- finally {
156
- destroy();
157
- }
158
- });
159
- it('marks pinned cells with the data-pinned-row attribute', async () => {
160
- const { target, destroy } = await mountGrid({ pinnedTopRows: [TOTALS] });
161
- try {
162
- await tick();
163
- const tr = target.querySelector('tr.sv-grid-pinned-row-top');
164
- expect(tr.getAttribute('data-pinned-row')).toBe('top');
165
- }
166
- finally {
167
- destroy();
168
- }
169
- });
170
- });
171
- describe('SvGrid - pinnedBottomRows render', () => {
172
- it('renders a pinned-bottom tbody when prop is provided', async () => {
173
- const { target, destroy } = await mountGrid({ pinnedBottomRows: [PAGE] });
174
- try {
175
- await tick();
176
- const bottomBody = target.querySelector('tbody.sv-grid-pinned-bottom-body');
177
- expect(bottomBody).not.toBeNull();
178
- const trs = bottomBody.querySelectorAll('tr.sv-grid-pinned-row-bottom');
179
- expect(trs.length).toBe(1);
180
- expect(trs[0].getAttribute('data-pinned-row')).toBe('bottom');
181
- }
182
- finally {
183
- destroy();
184
- }
185
- });
186
- it('renders bottom rows AFTER the regular tbody', async () => {
187
- const { target, destroy } = await mountGrid({ pinnedBottomRows: [PAGE] });
188
- try {
189
- await tick();
190
- const bodies = target.querySelectorAll('tbody');
191
- // [regular .sv-grid-body, .sv-grid-pinned-bottom-body]
192
- // In the DOM order, the bottom tbody must come after the main body.
193
- const classes = Array.from(bodies).map((b) => b.className);
194
- const mainIdx = classes.findIndex((c) => c.includes('sv-grid-body') && !c.includes('pinned'));
195
- const botIdx = classes.findIndex((c) => c.includes('sv-grid-pinned-bottom-body'));
196
- expect(mainIdx).toBeGreaterThanOrEqual(0);
197
- expect(botIdx).toBeGreaterThan(mainIdx);
198
- }
199
- finally {
200
- destroy();
201
- }
202
- });
203
- });
204
- describe('SvGrid - pinned rows are read-only', () => {
205
- it('pinned-row cells do not carry the editing class even with inline editing enabled', async () => {
206
- const { target, destroy } = await mountGrid({ pinnedTopRows: [TOTALS] });
207
- try {
208
- await tick();
209
- const editingCells = target.querySelectorAll('tr.sv-grid-pinned-row-top td.sv-grid-cell-editing');
210
- expect(editingCells.length).toBe(0);
211
- }
212
- finally {
213
- destroy();
214
- }
215
- });
216
- it('pinned rows do not carry the selection checkbox cell', async () => {
217
- const { target, destroy } = await mountGrid({ pinnedTopRows: [TOTALS] });
218
- try {
219
- await tick();
220
- // The selection cell class is `.sv-grid-selection-cell`. It may
221
- // appear in the regular row when row-selection is on, but never
222
- // with a working <button role="checkbox"> inside it on a pinned
223
- // row (the snippet renders an empty <td>).
224
- const checkboxes = target.querySelectorAll('tr.sv-grid-pinned-row-top button[role="checkbox"]');
225
- expect(checkboxes.length).toBe(0);
226
- }
227
- finally {
228
- destroy();
229
- }
230
- });
231
- });
232
- describe('SvGrid - pinned rows + CSS variables', () => {
233
- it('sets --sg-thead-h and --sg-pinned-row-h CSS variables on the shell', async () => {
234
- const { target, destroy } = await mountGrid({
235
- pinnedTopRows: [TOTALS],
236
- pinnedBottomRows: [PAGE],
237
- });
238
- try {
239
- await tick();
240
- const shell = target.querySelector('.sv-grid-shell');
241
- expect(shell, 'shell should exist').not.toBeNull();
242
- const style = shell.getAttribute('style') ?? '';
243
- expect(style).toContain('--sg-thead-h');
244
- expect(style).toContain('--sg-pinned-row-h');
245
- }
246
- finally {
247
- destroy();
248
- }
249
- });
250
- });
@@ -1,17 +0,0 @@
1
- /**
2
- * Component tests for `api.setFacetFilter()` - the imperative entry
3
- * point that powers the three set-filter UX patterns (Excel-style
4
- * column-menu, async value loaders, and tree-list cascades). The grid
5
- * is filter-source-agnostic; this test exercises the API directly so
6
- * coverage is independent of any specific UI implementation.
7
- *
8
- * Covers:
9
- * - Single column facet filter narrows the displayed rows
10
- * - Multi-value filter (OR within column) accepts every listed value
11
- * - Passing null / empty clears the filter
12
- * - Two columns AND across (different columns)
13
- * - Combines with operator filter from setFilter()
14
- * - Survives unknown values (no crash, just no matches)
15
- * - Unicode / non-ASCII values match exactly (no normalization)
16
- */
17
- export {};