@svgrid/grid 1.0.0

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 (213) hide show
  1. package/LICENSE +33 -0
  2. package/README.md +39 -0
  3. package/dist/FlexRender.svelte +96 -0
  4. package/dist/FlexRender.svelte.d.ts +49 -0
  5. package/dist/SvGrid.svelte +8742 -0
  6. package/dist/SvGrid.svelte.d.ts +381 -0
  7. package/dist/SvGridChart.svelte +653 -0
  8. package/dist/SvGridChart.svelte.d.ts +25 -0
  9. package/dist/SvGridChart.test.d.ts +1 -0
  10. package/dist/SvGridChart.test.js +62 -0
  11. package/dist/SvGridDropdown.svelte +675 -0
  12. package/dist/SvGridDropdown.svelte.d.ts +40 -0
  13. package/dist/a11y.contract.test.d.ts +1 -0
  14. package/dist/a11y.contract.test.js +39 -0
  15. package/dist/a11y.d.ts +38 -0
  16. package/dist/a11y.js +37 -0
  17. package/dist/a11y.test.d.ts +1 -0
  18. package/dist/a11y.test.js +44 -0
  19. package/dist/cell-formatting.d.ts +17 -0
  20. package/dist/cell-formatting.js +141 -0
  21. package/dist/cell-formatting.test.d.ts +1 -0
  22. package/dist/cell-formatting.test.js +234 -0
  23. package/dist/chart-export.d.ts +14 -0
  24. package/dist/chart-export.js +112 -0
  25. package/dist/chart.d.ts +226 -0
  26. package/dist/chart.js +732 -0
  27. package/dist/chart.test.d.ts +1 -0
  28. package/dist/chart.test.js +289 -0
  29. package/dist/collaboration.d.ts +74 -0
  30. package/dist/collaboration.js +98 -0
  31. package/dist/collaboration.test.d.ts +1 -0
  32. package/dist/collaboration.test.js +65 -0
  33. package/dist/conditional-formatting.d.ts +91 -0
  34. package/dist/conditional-formatting.js +170 -0
  35. package/dist/conditional-formatting.test.d.ts +1 -0
  36. package/dist/conditional-formatting.test.js +87 -0
  37. package/dist/core.coverage.test.d.ts +1 -0
  38. package/dist/core.coverage.test.js +186 -0
  39. package/dist/core.d.ts +370 -0
  40. package/dist/core.js +568 -0
  41. package/dist/core.performance.test.d.ts +1 -0
  42. package/dist/core.performance.test.js +29 -0
  43. package/dist/createGrid.svelte.d.ts +6 -0
  44. package/dist/createGrid.svelte.js +17 -0
  45. package/dist/createGrid.test.d.ts +1 -0
  46. package/dist/createGrid.test.js +9 -0
  47. package/dist/createGridState.svelte.d.ts +3 -0
  48. package/dist/createGridState.svelte.js +13 -0
  49. package/dist/editors/cell-editors.d.ts +23 -0
  50. package/dist/editors/cell-editors.js +97 -0
  51. package/dist/editors/cell-editors.test.d.ts +1 -0
  52. package/dist/editors/cell-editors.test.js +75 -0
  53. package/dist/fill-patterns.d.ts +30 -0
  54. package/dist/fill-patterns.js +207 -0
  55. package/dist/fill-patterns.test.d.ts +1 -0
  56. package/dist/fill-patterns.test.js +81 -0
  57. package/dist/filtering/excel-filters.d.ts +26 -0
  58. package/dist/filtering/excel-filters.js +64 -0
  59. package/dist/filtering/excel-filters.test.d.ts +1 -0
  60. package/dist/filtering/excel-filters.test.js +116 -0
  61. package/dist/filtering/locale-filter.test.d.ts +13 -0
  62. package/dist/filtering/locale-filter.test.js +189 -0
  63. package/dist/flex-render.d.ts +1 -0
  64. package/dist/flex-render.js +2 -0
  65. package/dist/flex-render.test.d.ts +1 -0
  66. package/dist/flex-render.test.js +142 -0
  67. package/dist/group-aggregate.test.d.ts +1 -0
  68. package/dist/group-aggregate.test.js +32 -0
  69. package/dist/index.d.ts +29 -0
  70. package/dist/index.js +27 -0
  71. package/dist/keyboard.d.ts +8 -0
  72. package/dist/keyboard.js +91 -0
  73. package/dist/keyboard.test.d.ts +1 -0
  74. package/dist/keyboard.test.js +27 -0
  75. package/dist/merge-objects.d.ts +9 -0
  76. package/dist/merge-objects.js +28 -0
  77. package/dist/named-views.d.ts +42 -0
  78. package/dist/named-views.js +80 -0
  79. package/dist/named-views.test.d.ts +1 -0
  80. package/dist/named-views.test.js +57 -0
  81. package/dist/new-features.test.d.ts +1 -0
  82. package/dist/new-features.test.js +183 -0
  83. package/dist/render-component.d.ts +13 -0
  84. package/dist/render-component.js +14 -0
  85. package/dist/render-component.test.d.ts +1 -0
  86. package/dist/render-component.test.js +41 -0
  87. package/dist/server-data-source.d.ts +76 -0
  88. package/dist/server-data-source.js +83 -0
  89. package/dist/server-data-source.test.d.ts +1 -0
  90. package/dist/server-data-source.test.js +81 -0
  91. package/dist/sparkline.d.ts +56 -0
  92. package/dist/sparkline.js +97 -0
  93. package/dist/sparkline.test.d.ts +1 -0
  94. package/dist/sparkline.test.js +52 -0
  95. package/dist/static-functions.d.ts +1 -0
  96. package/dist/static-functions.js +1 -0
  97. package/dist/subscribe.d.ts +9 -0
  98. package/dist/subscribe.js +31 -0
  99. package/dist/subscribe.test.d.ts +1 -0
  100. package/dist/subscribe.test.js +93 -0
  101. package/dist/sv-grid-scrollbar.d.ts +1 -0
  102. package/dist/sv-grid-scrollbar.js +310 -0
  103. package/dist/svgrid-wrapper.types.d.ts +341 -0
  104. package/dist/svgrid-wrapper.types.js +1 -0
  105. package/dist/svgrid.api-extensions.test.d.ts +14 -0
  106. package/dist/svgrid.api-extensions.test.js +334 -0
  107. package/dist/svgrid.api.test.d.ts +15 -0
  108. package/dist/svgrid.api.test.js +169 -0
  109. package/dist/svgrid.behavior.test.d.ts +15 -0
  110. package/dist/svgrid.behavior.test.js +605 -0
  111. package/dist/svgrid.column-reorder.test.d.ts +15 -0
  112. package/dist/svgrid.column-reorder.test.js +224 -0
  113. package/dist/svgrid.features.test.d.ts +1 -0
  114. package/dist/svgrid.features.test.js +129 -0
  115. package/dist/svgrid.interaction.test.d.ts +9 -0
  116. package/dist/svgrid.interaction.test.js +318 -0
  117. package/dist/svgrid.locale-filtering.test.d.ts +15 -0
  118. package/dist/svgrid.locale-filtering.test.js +261 -0
  119. package/dist/svgrid.new-features.wrapper.test.d.ts +1 -0
  120. package/dist/svgrid.new-features.wrapper.test.js +136 -0
  121. package/dist/svgrid.row-pinning.test.d.ts +14 -0
  122. package/dist/svgrid.row-pinning.test.js +250 -0
  123. package/dist/svgrid.set-filter.test.d.ts +17 -0
  124. package/dist/svgrid.set-filter.test.js +268 -0
  125. package/dist/svgrid.wrapper.test.d.ts +1 -0
  126. package/dist/svgrid.wrapper.test.js +33 -0
  127. package/dist/test-setup.d.ts +1 -0
  128. package/dist/test-setup.js +29 -0
  129. package/dist/transaction.test.d.ts +1 -0
  130. package/dist/transaction.test.js +89 -0
  131. package/dist/virtualization/column-virtualizer.d.ts +20 -0
  132. package/dist/virtualization/column-virtualizer.js +19 -0
  133. package/dist/virtualization/column-virtualizer.test.d.ts +1 -0
  134. package/dist/virtualization/column-virtualizer.test.js +25 -0
  135. package/dist/virtualization/svelte-virtualizer.svelte.d.ts +11 -0
  136. package/dist/virtualization/svelte-virtualizer.svelte.js +20 -0
  137. package/dist/virtualization/types.d.ts +28 -0
  138. package/dist/virtualization/types.js +1 -0
  139. package/dist/virtualization/virtualizer.d.ts +13 -0
  140. package/dist/virtualization/virtualizer.js +232 -0
  141. package/dist/virtualization/virtualizer.test.d.ts +1 -0
  142. package/dist/virtualization/virtualizer.test.js +41 -0
  143. package/package.json +69 -0
  144. package/src/FlexRender.svelte +96 -0
  145. package/src/SvGrid.svelte +8742 -0
  146. package/src/SvGridChart.svelte +653 -0
  147. package/src/SvGridChart.test.ts +69 -0
  148. package/src/SvGridDropdown.svelte +675 -0
  149. package/src/a11y.contract.test.ts +49 -0
  150. package/src/a11y.test.ts +59 -0
  151. package/src/a11y.ts +59 -0
  152. package/src/cell-formatting.test.ts +273 -0
  153. package/src/cell-formatting.ts +169 -0
  154. package/src/chart-export.ts +144 -0
  155. package/src/chart.test.ts +311 -0
  156. package/src/chart.ts +934 -0
  157. package/src/collaboration.test.ts +74 -0
  158. package/src/collaboration.ts +161 -0
  159. package/src/conditional-formatting.test.ts +107 -0
  160. package/src/conditional-formatting.ts +239 -0
  161. package/src/core.coverage.test.ts +230 -0
  162. package/src/core.performance.test.ts +30 -0
  163. package/src/core.ts +991 -0
  164. package/src/createGrid.svelte.ts +42 -0
  165. package/src/createGrid.test.ts +10 -0
  166. package/src/createGridState.svelte.ts +17 -0
  167. package/src/editors/cell-editors.test.ts +80 -0
  168. package/src/editors/cell-editors.ts +127 -0
  169. package/src/fill-patterns.test.ts +93 -0
  170. package/src/fill-patterns.ts +229 -0
  171. package/src/filtering/excel-filters.test.ts +131 -0
  172. package/src/filtering/excel-filters.ts +101 -0
  173. package/src/filtering/locale-filter.test.ts +220 -0
  174. package/src/flex-render.test.ts +143 -0
  175. package/src/flex-render.ts +3 -0
  176. package/src/group-aggregate.test.ts +48 -0
  177. package/src/index.ts +159 -0
  178. package/src/keyboard.test.ts +59 -0
  179. package/src/keyboard.ts +97 -0
  180. package/src/merge-objects.ts +48 -0
  181. package/src/named-views.test.ts +66 -0
  182. package/src/named-views.ts +120 -0
  183. package/src/new-features.test.ts +217 -0
  184. package/src/render-component.test.ts +51 -0
  185. package/src/render-component.ts +28 -0
  186. package/src/server-data-source.test.ts +88 -0
  187. package/src/server-data-source.ts +163 -0
  188. package/src/sparkline.test.ts +59 -0
  189. package/src/sparkline.ts +164 -0
  190. package/src/static-functions.ts +11 -0
  191. package/src/subscribe.test.ts +103 -0
  192. package/src/subscribe.ts +38 -0
  193. package/src/sv-grid-scrollbar.ts +347 -0
  194. package/src/svgrid-wrapper.types.ts +382 -0
  195. package/src/svgrid.api-extensions.test.ts +362 -0
  196. package/src/svgrid.api.test.ts +192 -0
  197. package/src/svgrid.behavior.test.ts +657 -0
  198. package/src/svgrid.column-reorder.test.ts +234 -0
  199. package/src/svgrid.features.test.ts +157 -0
  200. package/src/svgrid.interaction.test.ts +355 -0
  201. package/src/svgrid.locale-filtering.test.ts +259 -0
  202. package/src/svgrid.new-features.wrapper.test.ts +164 -0
  203. package/src/svgrid.row-pinning.test.ts +266 -0
  204. package/src/svgrid.set-filter.test.ts +270 -0
  205. package/src/svgrid.wrapper.test.ts +35 -0
  206. package/src/test-setup.ts +37 -0
  207. package/src/transaction.test.ts +100 -0
  208. package/src/virtualization/column-virtualizer.test.ts +27 -0
  209. package/src/virtualization/column-virtualizer.ts +30 -0
  210. package/src/virtualization/svelte-virtualizer.svelte.ts +24 -0
  211. package/src/virtualization/types.ts +30 -0
  212. package/src/virtualization/virtualizer.test.ts +47 -0
  213. package/src/virtualization/virtualizer.ts +270 -0
@@ -0,0 +1,164 @@
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
+
19
+ const sourcePath = resolve(__dirname, './SvGrid.svelte')
20
+ const source = readFileSync(sourcePath, 'utf-8')
21
+ const typesPath = resolve(__dirname, './svgrid-wrapper.types.ts')
22
+ const types = readFileSync(typesPath, 'utf-8')
23
+
24
+ describe('SvGrid wrapper - getRowId prop', () => {
25
+ it('declares the getRowId prop on the Props type', () => {
26
+ expect(source).toMatch(/getRowId\?:\s*\(row:\s*TData,\s*index:\s*number\)\s*=>\s*string/)
27
+ })
28
+
29
+ it('forwards the prop into createSvGrid options', () => {
30
+ expect(source).toMatch(/get getRowId\(\)[\s\S]*?return props\.getRowId/)
31
+ })
32
+ })
33
+
34
+ describe('SvGrid wrapper - cellClass + rowClass', () => {
35
+ it('declares the rowClass prop on the Props type', () => {
36
+ expect(source).toMatch(/rowClass\?:\s*\(ctx:\s*\{/)
37
+ })
38
+
39
+ it('exposes a resolveClassList helper that normalises array / record / string forms', () => {
40
+ expect(source).toMatch(/function resolveClassList\(/)
41
+ expect(source).toMatch(/Array\.isArray\(value\)/)
42
+ })
43
+
44
+ it('computes the row-level class once per render row and threads it onto the <tr>', () => {
45
+ expect(source).toMatch(/function computeRowClass/)
46
+ expect(source).toMatch(/userRowClass = computeRowClass\(row, rowIndex\)/)
47
+ expect(source).toMatch(/class=\{`sv-grid-row \$\{userRowClass\}`\}/)
48
+ })
49
+
50
+ it('computes the cell-level class per column and threads it onto the <td>', () => {
51
+ expect(source).toMatch(/function computeCellClass/)
52
+ expect(source).toMatch(/userCellClass = computeCellClass\(row, rendered\.column\)/)
53
+ expect(source).toMatch(/class=\{`sv-grid-cell \$\{userCellClass\}`\}/)
54
+ })
55
+ })
56
+
57
+ describe('SvGrid wrapper - column-layout API', () => {
58
+ it('declares setColumnWidth + getColumnWidths in the public type', () => {
59
+ expect(types).toContain('setColumnWidth(columnId: string, width: number): void')
60
+ expect(types).toContain('getColumnWidths(): Record<string, number>')
61
+ })
62
+
63
+ it('declares setColumnPinning + getColumnPinning in the public type', () => {
64
+ expect(types).toMatch(/setColumnPinning\(pinning:\s*\{/)
65
+ expect(types).toContain('getColumnPinning(): { left: string[]; right: string[] }')
66
+ })
67
+
68
+ it('implements all four methods in the api object', () => {
69
+ expect(source).toMatch(/setColumnWidth\(columnId: string, width: number\)/)
70
+ expect(source).toMatch(/getColumnWidths\(\)/)
71
+ expect(source).toMatch(/setColumnPinning\(pinning\)/)
72
+ expect(source).toMatch(/getColumnPinning\(\)/)
73
+ })
74
+
75
+ it('clamps setColumnWidth to MIN_COLUMN_WIDTH', () => {
76
+ // Confirm the clamp is in the code path so a caller can't drop a
77
+ // column below the minimum by passing 0 or a negative number.
78
+ expect(source).toMatch(/Math\.max\(MIN_COLUMN_WIDTH/)
79
+ })
80
+
81
+ it('defensive-copies setColumnPinning inputs so callers cannot mutate state', () => {
82
+ expect(source).toMatch(/Array\.from\(new Set\(pinning\.left/)
83
+ expect(source).toMatch(/Array\.from\(new Set\(pinning\.right/)
84
+ })
85
+ })
86
+
87
+ describe('SvGrid wrapper - between filter operator', () => {
88
+ it("includes 'between' in the FilterOperator type", () => {
89
+ expect(source).toMatch(/"between"/)
90
+ })
91
+
92
+ it("includes 'between' in NUMBER_OPERATORS + DATE_OPERATORS but NOT in TEXT_OPERATORS", () => {
93
+ // The list literals appear in order, so we slice each block out
94
+ // separately and check membership.
95
+ const numOps = source.match(/const NUMBER_OPERATORS[^]*?\];/)?.[0] ?? ''
96
+ expect(numOps).toContain('"between"')
97
+ const dateOps = source.match(/const DATE_OPERATORS[^]*?\];/)?.[0] ?? ''
98
+ expect(dateOps).toContain('"between"')
99
+ const textOps = source.match(/const TEXT_OPERATORS[^]*?\];/)?.[0] ?? ''
100
+ expect(textOps).not.toContain('"between"')
101
+ })
102
+
103
+ it('renders a second input ("To") when the operator is between', () => {
104
+ expect(source).toMatch(/menuActiveOperator === "between"/)
105
+ expect(source).toMatch(/placeholder="To"/)
106
+ })
107
+
108
+ it('treats the filter as inactive until BOTH endpoints are non-empty', () => {
109
+ // The active-filters filter() should require value AND valueTo.
110
+ expect(source).toMatch(/if \(f\.operator === "between"\) \{[^}]*f\.value\.trim\(\)\.length > 0[^}]*f\.valueTo[^}]*\.trim\(\)\.length > 0/)
111
+ })
112
+
113
+ it('forwards valueTo through applyExcelFilter', () => {
114
+ expect(source).toMatch(/valueTo: filter\.operator === "between" \? filter\.valueTo : undefined/)
115
+ })
116
+
117
+ it('publishes valueTo in the onFiltersChange payload only for between clauses', () => {
118
+ expect(source).toMatch(/f\.operator === "between" && f\.valueTo\s*\?\s*\{ valueTo: f\.valueTo \}/)
119
+ })
120
+
121
+ it('exposes valueTo on the imperative setFilter input + getFilters output', () => {
122
+ expect(types).toMatch(/setFilter\(\s*columnId: string,[\s\S]*?valueTo\?: string/)
123
+ expect(types).toMatch(/getFilters\(\)[\s\S]*?valueTo\?: string/)
124
+ })
125
+ })
126
+
127
+ describe('SvGrid wrapper - multi-cell paste + cut + delete', () => {
128
+ it('fills the selection range when the clipboard payload is 1x1', () => {
129
+ expect(source).toMatch(/clipboardIsSingleCell\s*=\s*\n?\s*lines\.length === 1 && \(lines\[0\]\?\.split\("\\t"\)\.length \?\? 0\) === 1/)
130
+ expect(source).toMatch(/selectionIsRange = startRow !== endRow \|\| startCol !== endCol/)
131
+ expect(source).toMatch(/fillRange = clipboardIsSingleCell && selectionIsRange/)
132
+ })
133
+
134
+ it('walks the entire selection rect when filling', () => {
135
+ expect(source).toMatch(/const rowSpan = fillRange \? endRow - startRow \+ 1 : lines\.length/)
136
+ expect(source).toMatch(/const colSpan = fillRange/)
137
+ })
138
+
139
+ it('implements clearSelectedCells() that touches every editable cell in the range', () => {
140
+ expect(source).toMatch(/function clearSelectedCells\(\): boolean/)
141
+ expect(source).toMatch(/parseEditorValue\(editorType, ""\)/)
142
+ })
143
+
144
+ it('wires Ctrl/Cmd+X to cutSelectionToClipboard', () => {
145
+ expect(source).toMatch(/lower === "x"/)
146
+ expect(source).toMatch(/void cutSelectionToClipboard\(\)/)
147
+ expect(source).toMatch(/async function cutSelectionToClipboard/)
148
+ // Confirm both calls live inside the cutSelectionToClipboard body
149
+ // (copy first, then clear). A comment between them is fine.
150
+ const body = source.match(
151
+ /async function cutSelectionToClipboard\(\)[^{]*\{([\s\S]*?)^\s\s\}/m,
152
+ )?.[1] ?? ''
153
+ expect(body).toContain('copySelectionToClipboard();')
154
+ expect(body).toContain('clearSelectedCells();')
155
+ expect(body.indexOf('copySelectionToClipboard()')).toBeLessThan(
156
+ body.indexOf('clearSelectedCells()'),
157
+ )
158
+ })
159
+
160
+ it('wires Delete + Backspace to clearSelectedCells (without clipboard interaction)', () => {
161
+ expect(source).toMatch(/event\.key === "Delete" \|\| event\.key === "Backspace"/)
162
+ expect(source).toMatch(/if \(clearSelectedCells\(\)\)\s*\{/)
163
+ })
164
+ })
@@ -0,0 +1,266 @@
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
+
15
+ import { describe, expect, it } from 'vitest'
16
+ import { mount, unmount, flushSync } from 'svelte'
17
+ import SvGrid from './SvGrid.svelte'
18
+ import {
19
+ columnFilteringFeature,
20
+ createCoreRowModel,
21
+ createFilteredRowModel,
22
+ createSortedRowModel,
23
+ rowSortingFeature,
24
+ sortFns,
25
+ tableFeatures,
26
+ } from './index'
27
+ import type { ColumnDef, SvGridApi } from './index'
28
+
29
+ type Row = { id: string; account: string; arr: number; seats: number }
30
+
31
+ const features = tableFeatures({ columnFilteringFeature, rowSortingFeature })
32
+
33
+ const rows: Row[] = [
34
+ { id: 'ACC-1', account: 'Helios', arr: 120_000, seats: 40 },
35
+ { id: 'ACC-2', account: 'Vertex', arr: 85_000, seats: 22 },
36
+ { id: 'ACC-3', account: 'Atlas', arr: 250_000, seats: 80 },
37
+ { id: 'ACC-4', account: 'Quantum', arr: 60_000, seats: 15 },
38
+ ]
39
+
40
+ const cols: ColumnDef<typeof features, Row>[] = [
41
+ { field: 'id', header: 'ID', width: 100, editable: false },
42
+ { field: 'account', header: 'Account', width: 200, editable: false },
43
+ { field: 'arr', header: 'ARR', width: 130, editable: false, align: 'right',
44
+ format: { type: 'number', options: { style: 'currency', currency: 'USD', maximumFractionDigits: 0 } } },
45
+ { field: 'seats', header: 'Seats', width: 90, editable: false, align: 'right' },
46
+ ]
47
+
48
+ type MountOpts = {
49
+ pinnedTopRows?: ReadonlyArray<Row>
50
+ pinnedBottomRows?: ReadonlyArray<Row>
51
+ }
52
+
53
+ function mountGrid(opts: MountOpts = {}) {
54
+ return new Promise<{
55
+ target: HTMLElement
56
+ api: SvGridApi<typeof features, Row>
57
+ destroy: () => void
58
+ setProps: (next: MountOpts) => void
59
+ }>((res, rej) => {
60
+ const target = document.createElement('div')
61
+ document.body.appendChild(target)
62
+ const propsState: MountOpts = { ...opts }
63
+ let api: SvGridApi<typeof features, Row> | null = null
64
+ const app = mount(SvGrid, {
65
+ target,
66
+ props: {
67
+ data: rows,
68
+ columns: cols,
69
+ features,
70
+ _rowModels: {
71
+ coreRowModel: createCoreRowModel(),
72
+ filteredRowModel: createFilteredRowModel(),
73
+ sortedRowModel: createSortedRowModel(sortFns),
74
+ },
75
+ containerHeight: 480,
76
+ virtualization: false,
77
+ columnVirtualization: false,
78
+ enableInlineEditing: false,
79
+ showPagination: false,
80
+ showColumnFilters: false,
81
+ showGlobalFilter: false,
82
+ showRowSelection: false,
83
+ pinnedTopRows: propsState.pinnedTopRows,
84
+ pinnedBottomRows: propsState.pinnedBottomRows,
85
+ onApiReady(received: SvGridApi<typeof features, Row>) {
86
+ api = received
87
+ res({
88
+ target,
89
+ api,
90
+ destroy: () => {
91
+ unmount(app)
92
+ target.remove()
93
+ },
94
+ setProps(next) {
95
+ propsState.pinnedTopRows = next.pinnedTopRows
96
+ propsState.pinnedBottomRows = next.pinnedBottomRows
97
+ // Svelte 5: re-mount-with-new-props isn't ideal, but here
98
+ // we use the `$state` props passthrough via the parent
99
+ // closure. The easiest mechanism is to imperatively
100
+ // update via Svelte's prop machinery, which $props()
101
+ // reads from this same object reference.
102
+ ;(app as unknown as { pinnedTopRows: unknown; pinnedBottomRows: unknown })
103
+ .pinnedTopRows = next.pinnedTopRows
104
+ ;(app as unknown as { pinnedTopRows: unknown; pinnedBottomRows: unknown })
105
+ .pinnedBottomRows = next.pinnedBottomRows
106
+ flushSync()
107
+ },
108
+ })
109
+ },
110
+ } as any,
111
+ })
112
+ queueMicrotask(() => { if (!api) rej(new Error('onApiReady never fired')) })
113
+ })
114
+ }
115
+
116
+ const tick = () => new Promise<void>((r) => queueMicrotask(r))
117
+
118
+ const TOTALS: Row = {
119
+ id: '⌃ TOTALS', account: 'All accounts',
120
+ arr: rows.reduce((s, r) => s + r.arr, 0),
121
+ seats: rows.reduce((s, r) => s + r.seats, 0),
122
+ }
123
+ const BENCHMARK: Row = {
124
+ id: '⌃ BENCH', account: 'Industry benchmark',
125
+ arr: 180_000, seats: 95,
126
+ }
127
+ const PAGE: Row = {
128
+ id: '⌄ PAGE', account: 'Visible page',
129
+ arr: rows.reduce((s, r) => s + r.arr, 0),
130
+ seats: rows.reduce((s, r) => s + r.seats, 0),
131
+ }
132
+
133
+ describe('SvGrid - pinnedTopRows render', () => {
134
+ it('renders a pinned-top tbody when prop is provided', async () => {
135
+ const { target, destroy } = await mountGrid({ pinnedTopRows: [TOTALS] })
136
+ try {
137
+ await tick()
138
+ const topBody = target.querySelector('tbody.sv-grid-pinned-top-body')
139
+ expect(topBody, 'pinned-top tbody should exist').not.toBeNull()
140
+ const trs = topBody!.querySelectorAll('tr.sv-grid-pinned-row-top')
141
+ expect(trs.length).toBe(1)
142
+ } finally { destroy() }
143
+ })
144
+
145
+ it('does NOT render the tbody when prop is empty / undefined', async () => {
146
+ const { target, destroy } = await mountGrid({ pinnedTopRows: [] })
147
+ try {
148
+ await tick()
149
+ const topBody = target.querySelector('tbody.sv-grid-pinned-top-body')
150
+ expect(topBody).toBeNull()
151
+ } finally { destroy() }
152
+ })
153
+
154
+ it('renders the row values using the column schema (format applied)', async () => {
155
+ const { target, destroy } = await mountGrid({ pinnedTopRows: [TOTALS] })
156
+ try {
157
+ await tick()
158
+ const tds = target
159
+ .querySelectorAll('tr.sv-grid-pinned-row-top td')
160
+ expect(tds.length).toBe(cols.length)
161
+ // ARR cell should be currency-formatted ($515,000) - currency
162
+ // symbol exact form may vary by ICU build; assert a "$" plus the
163
+ // raw number with grouping is present.
164
+ const arrCellText = (tds[2]?.textContent ?? '').trim()
165
+ expect(arrCellText).toMatch(/\$/)
166
+ expect(arrCellText).toContain('515')
167
+ } finally { destroy() }
168
+ })
169
+
170
+ it('stacks multiple pinned-top rows with data-pinned-index', async () => {
171
+ const { target, destroy } = await mountGrid({
172
+ pinnedTopRows: [TOTALS, BENCHMARK],
173
+ })
174
+ try {
175
+ await tick()
176
+ const trs = target.querySelectorAll('tr.sv-grid-pinned-row-top')
177
+ expect(trs.length).toBe(2)
178
+ expect(trs[0]!.getAttribute('data-pinned-row')).toBe('top')
179
+ expect(trs[0]!.getAttribute('data-pinned-index')).toBe('0')
180
+ expect(trs[1]!.getAttribute('data-pinned-index')).toBe('1')
181
+ } finally { destroy() }
182
+ })
183
+
184
+ it('marks pinned cells with the data-pinned-row attribute', async () => {
185
+ const { target, destroy } = await mountGrid({ pinnedTopRows: [TOTALS] })
186
+ try {
187
+ await tick()
188
+ const tr = target.querySelector('tr.sv-grid-pinned-row-top')
189
+ expect(tr!.getAttribute('data-pinned-row')).toBe('top')
190
+ } finally { destroy() }
191
+ })
192
+ })
193
+
194
+ describe('SvGrid - pinnedBottomRows render', () => {
195
+ it('renders a pinned-bottom tbody when prop is provided', async () => {
196
+ const { target, destroy } = await mountGrid({ pinnedBottomRows: [PAGE] })
197
+ try {
198
+ await tick()
199
+ const bottomBody = target.querySelector('tbody.sv-grid-pinned-bottom-body')
200
+ expect(bottomBody).not.toBeNull()
201
+ const trs = bottomBody!.querySelectorAll('tr.sv-grid-pinned-row-bottom')
202
+ expect(trs.length).toBe(1)
203
+ expect(trs[0]!.getAttribute('data-pinned-row')).toBe('bottom')
204
+ } finally { destroy() }
205
+ })
206
+
207
+ it('renders bottom rows AFTER the regular tbody', async () => {
208
+ const { target, destroy } = await mountGrid({ pinnedBottomRows: [PAGE] })
209
+ try {
210
+ await tick()
211
+ const bodies = target.querySelectorAll('tbody')
212
+ // [regular .sv-grid-body, .sv-grid-pinned-bottom-body]
213
+ // In the DOM order, the bottom tbody must come after the main body.
214
+ const classes = Array.from(bodies).map((b) => b.className)
215
+ const mainIdx = classes.findIndex((c) => c.includes('sv-grid-body') && !c.includes('pinned'))
216
+ const botIdx = classes.findIndex((c) => c.includes('sv-grid-pinned-bottom-body'))
217
+ expect(mainIdx).toBeGreaterThanOrEqual(0)
218
+ expect(botIdx).toBeGreaterThan(mainIdx)
219
+ } finally { destroy() }
220
+ })
221
+ })
222
+
223
+ describe('SvGrid - pinned rows are read-only', () => {
224
+ it('pinned-row cells do not carry the editing class even with inline editing enabled', async () => {
225
+ const { target, destroy } = await mountGrid({ pinnedTopRows: [TOTALS] })
226
+ try {
227
+ await tick()
228
+ const editingCells = target.querySelectorAll(
229
+ 'tr.sv-grid-pinned-row-top td.sv-grid-cell-editing',
230
+ )
231
+ expect(editingCells.length).toBe(0)
232
+ } finally { destroy() }
233
+ })
234
+
235
+ it('pinned rows do not carry the selection checkbox cell', async () => {
236
+ const { target, destroy } = await mountGrid({ pinnedTopRows: [TOTALS] })
237
+ try {
238
+ await tick()
239
+ // The selection cell class is `.sv-grid-selection-cell`. It may
240
+ // appear in the regular row when row-selection is on, but never
241
+ // with a working <button role="checkbox"> inside it on a pinned
242
+ // row (the snippet renders an empty <td>).
243
+ const checkboxes = target.querySelectorAll(
244
+ 'tr.sv-grid-pinned-row-top button[role="checkbox"]',
245
+ )
246
+ expect(checkboxes.length).toBe(0)
247
+ } finally { destroy() }
248
+ })
249
+ })
250
+
251
+ describe('SvGrid - pinned rows + CSS variables', () => {
252
+ it('sets --sg-thead-h and --sg-pinned-row-h CSS variables on the shell', async () => {
253
+ const { target, destroy } = await mountGrid({
254
+ pinnedTopRows: [TOTALS],
255
+ pinnedBottomRows: [PAGE],
256
+ })
257
+ try {
258
+ await tick()
259
+ const shell = target.querySelector('.sv-grid-shell') as HTMLElement | null
260
+ expect(shell, 'shell should exist').not.toBeNull()
261
+ const style = shell!.getAttribute('style') ?? ''
262
+ expect(style).toContain('--sg-thead-h')
263
+ expect(style).toContain('--sg-pinned-row-h')
264
+ } finally { destroy() }
265
+ })
266
+ })