@svgrid/grid 3.0.3 → 4.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 (318) hide show
  1. package/README.md +5 -4
  2. package/dist/GridMenus.svelte +44 -2
  3. package/dist/SvChartMenu.svelte +69 -0
  4. package/dist/SvChartMenu.svelte.d.ts +11 -0
  5. package/dist/SvChartPanes.svelte +113 -0
  6. package/dist/SvChartPanes.svelte.d.ts +20 -0
  7. package/dist/SvGrid.controller.svelte.d.ts +122 -41
  8. package/dist/SvGrid.controller.svelte.js +845 -207
  9. package/dist/SvGrid.css +178 -2
  10. package/dist/SvGrid.svelte +467 -516
  11. package/dist/SvGrid.types.d.ts +315 -12
  12. package/dist/SvGridCellEditor.svelte +17 -0
  13. package/dist/SvGridChart.svelte +2257 -329
  14. package/dist/SvGridChart.svelte.d.ts +6 -106
  15. package/dist/SvGridChart.types.d.ts +338 -0
  16. package/dist/SvGridChart.types.js +1 -0
  17. package/dist/SvGridChartBuilder.svelte +323 -0
  18. package/dist/SvGridChartBuilder.svelte.d.ts +34 -0
  19. package/dist/SvGridChartPanel.svelte +221 -275
  20. package/dist/SvGridChartPickers.svelte +417 -0
  21. package/dist/SvGridChartPickers.svelte.d.ts +70 -0
  22. package/dist/SvGridChartView.svelte +13 -14
  23. package/dist/SvModal.svelte +7 -1
  24. package/dist/SvModal.svelte.d.ts +5 -0
  25. package/dist/ai.d.ts +40 -8
  26. package/dist/ai.js +135 -24
  27. package/dist/aria.d.ts +11 -0
  28. package/dist/build-api.js +119 -28
  29. package/dist/cdn/GridMenus-CLI93jke.js +635 -0
  30. package/dist/cdn/{GridMenus-DhdPF700.js → GridMenus-CwooL3QA.js} +240 -207
  31. package/dist/cdn/SvChartMenu-Bl6PBbkT.js +58 -0
  32. package/dist/cdn/SvChartMenu-FBSMINA6.js +59 -0
  33. package/dist/cdn/{SvDateRangeInput-DMLKmGEc.js → SvDateRangeInput-BeU_TkbQ.js} +15 -14
  34. package/dist/cdn/{SvDateRangeInput-CaOuMs8O.js → SvDateRangeInput-yX8vzleW.js} +38 -37
  35. package/dist/cdn/{SvDateTimePicker-sonaH0oh.js → SvDateTimePicker-DQwt4UAs.js} +139 -180
  36. package/dist/cdn/SvDateTimePicker-vNU6bZ-q.js +775 -0
  37. package/dist/cdn/{SvGridCellEditor-CjEJMJKc.js → SvGridCellEditor-B1p-vCK5.js} +188 -178
  38. package/dist/cdn/{SvGridCellEditor-BWnTi2N7.js → SvGridCellEditor-D_0q4xAu.js} +98 -88
  39. package/dist/cdn/SvGridChart-C3EWAZaM.js +3574 -0
  40. package/dist/cdn/SvGridChart-DzLkSwCH.js +3572 -0
  41. package/dist/cdn/SvGridChartBuilder-BE2T1ykB.js +783 -0
  42. package/dist/cdn/SvGridChartBuilder-CfII62sZ.js +784 -0
  43. package/dist/cdn/SvGridChartPanel-CCX5_Wgd.js +675 -0
  44. package/dist/cdn/SvGridChartPanel-xf4sWVTo.js +699 -0
  45. package/dist/cdn/SvGridChartView-CfuXmY5I.js +48 -0
  46. package/dist/cdn/SvGridChartView-DYwabQWj.js +47 -0
  47. package/dist/cdn/SvMenuList-CLN8OuIK.js +452 -0
  48. package/dist/cdn/SvMenuList-DkGhNKjf.js +451 -0
  49. package/dist/cdn/SvModal-BAE-pjZX.js +396 -0
  50. package/dist/cdn/SvModal-CIZWCcad.js +397 -0
  51. package/dist/cdn/chart-Dz7SqMXH.js +4341 -0
  52. package/dist/cdn/chart-export-BXqueeWJ.js +135 -0
  53. package/dist/cdn/chart-export-pdf-DONFUnNY.js +110 -0
  54. package/dist/cdn/chart-panel-messages-CUbf2R4i.js +1052 -0
  55. package/dist/cdn/chart-panel-messages-CmNrMdsr.js +1053 -0
  56. package/dist/cdn/chart-summary-BJW_tg_X.js +138 -0
  57. package/dist/cdn/chart-trend-CaN9mDEV.js +50 -0
  58. package/dist/cdn/chart-validate-HcOVFAfJ.js +188 -0
  59. package/dist/cdn/{column-resize-DsfNXMom.js → column-resize-DpmOLfRp.js} +3 -3
  60. package/dist/cdn/{date-format-BnnHlqGw.js → date-format-CtquV-p3.js} +583 -603
  61. package/dist/cdn/{date-format-BNii4zeD.js → date-format-D6KFzU_W.js} +347 -367
  62. package/dist/cdn/dismissable-DAHetSNk.js +44 -0
  63. package/dist/cdn/editor-contract-LXgQJAgd.js +22 -0
  64. package/dist/cdn/focus-trap-BBOQYBma.js +65 -0
  65. package/dist/cdn/{row-resize-BRcimkUT.js → row-resize-niQCp040.js} +44 -36
  66. package/dist/cdn/server-block-cache-CGoWz-87.js +237 -0
  67. package/dist/cdn/{src-D6XvA1Ij.js → src-B6HXdfHY.js} +10448 -10049
  68. package/dist/cdn/{src-Bugf5XlI.js → src-C6Iowdvs.js} +6908 -6509
  69. package/dist/cdn/svgrid.js +27 -15
  70. package/dist/cdn/svgrid.svelte-external.js +27 -15
  71. package/dist/cdn/validate-CchXzyrX.js +76 -0
  72. package/dist/chart-axes.d.ts +53 -0
  73. package/dist/chart-axes.js +351 -0
  74. package/dist/chart-cartesian.d.ts +88 -0
  75. package/dist/chart-cartesian.js +1862 -0
  76. package/dist/chart-decimate.d.ts +51 -0
  77. package/dist/chart-decimate.js +199 -0
  78. package/dist/chart-export-pdf.d.ts +47 -0
  79. package/dist/chart-export-pdf.js +187 -0
  80. package/dist/chart-export.d.ts +2 -1
  81. package/dist/chart-export.js +18 -3
  82. package/dist/chart-financial.d.ts +91 -0
  83. package/dist/chart-financial.js +175 -0
  84. package/dist/chart-flow.d.ts +10 -0
  85. package/dist/chart-flow.js +298 -0
  86. package/dist/chart-format.d.ts +18 -0
  87. package/dist/chart-format.js +65 -0
  88. package/dist/chart-grid.d.ts +8 -0
  89. package/dist/chart-grid.js +190 -0
  90. package/dist/chart-hierarchy.d.ts +17 -0
  91. package/dist/chart-hierarchy.js +146 -0
  92. package/dist/chart-indicators.d.ts +115 -0
  93. package/dist/chart-indicators.js +389 -0
  94. package/dist/chart-messages.d.ts +95 -0
  95. package/dist/chart-messages.js +92 -0
  96. package/dist/chart-motion.d.ts +16 -0
  97. package/dist/chart-motion.js +141 -0
  98. package/dist/chart-panel-messages.d.ts +265 -0
  99. package/dist/chart-panel-messages.js +285 -0
  100. package/dist/chart-pivot.d.ts +87 -0
  101. package/dist/chart-pivot.js +156 -0
  102. package/dist/chart-polar.d.ts +25 -0
  103. package/dist/chart-polar.js +700 -0
  104. package/dist/chart-samples.d.ts +16 -0
  105. package/dist/chart-samples.js +153 -0
  106. package/dist/chart-scale.d.ts +113 -0
  107. package/dist/chart-scale.js +405 -0
  108. package/dist/chart-stats.d.ts +111 -0
  109. package/dist/chart-stats.js +419 -0
  110. package/dist/chart-stream.d.ts +45 -0
  111. package/dist/chart-stream.js +91 -0
  112. package/dist/chart-summary.d.ts +27 -0
  113. package/dist/chart-summary.js +205 -0
  114. package/dist/chart-sync.svelte.d.ts +32 -0
  115. package/dist/chart-sync.svelte.js +23 -0
  116. package/dist/chart-table.d.ts +35 -0
  117. package/dist/chart-table.js +165 -0
  118. package/dist/chart-trend.d.ts +19 -0
  119. package/dist/chart-trend.js +61 -0
  120. package/dist/chart-types.d.ts +1456 -0
  121. package/dist/chart-types.js +6 -0
  122. package/dist/chart-validate.d.ts +43 -0
  123. package/dist/chart-validate.js +272 -0
  124. package/dist/chart-zoom.d.ts +40 -0
  125. package/dist/chart-zoom.js +145 -0
  126. package/dist/chart.d.ts +186 -865
  127. package/dist/chart.js +460 -2204
  128. package/dist/clipboard.d.ts +1 -0
  129. package/dist/clipboard.js +137 -18
  130. package/dist/column-resize.d.ts +3 -0
  131. package/dist/column-resize.js +4 -1
  132. package/dist/columns.js +3 -0
  133. package/dist/command-context.d.ts +19 -0
  134. package/dist/command-context.js +116 -0
  135. package/dist/core.d.ts +7 -0
  136. package/dist/core.js +36 -13
  137. package/dist/createPopoverSelect.svelte.d.ts +2 -2
  138. package/dist/editing.d.ts +2 -8
  139. package/dist/editing.js +272 -33
  140. package/dist/fill-patterns.d.ts +0 -5
  141. package/dist/fill-patterns.js +56 -2
  142. package/dist/grid-icons.d.ts +2 -2
  143. package/dist/grid-icons.js +2 -2
  144. package/dist/grid-messages.d.ts +12 -3
  145. package/dist/grid-messages.js +7 -0
  146. package/dist/history.d.ts +83 -0
  147. package/dist/history.js +133 -0
  148. package/dist/index.d.ts +27 -10
  149. package/dist/index.js +22 -5
  150. package/dist/keyboard-handlers.js +88 -31
  151. package/dist/keyboard.d.ts +55 -0
  152. package/dist/keyboard.js +132 -0
  153. package/dist/menus.d.ts +3 -1
  154. package/dist/menus.js +7 -2
  155. package/dist/merges.d.ts +97 -0
  156. package/dist/merges.js +147 -0
  157. package/dist/row-model.d.ts +133 -0
  158. package/dist/row-model.js +16 -0
  159. package/dist/row-resize.d.ts +3 -0
  160. package/dist/row-resize.js +14 -0
  161. package/dist/scroll-sync.d.ts +1 -0
  162. package/dist/scroll-sync.js +24 -0
  163. package/dist/selection.d.ts +18 -1
  164. package/dist/selection.js +138 -18
  165. package/dist/server-block-cache.d.ts +214 -0
  166. package/dist/server-block-cache.js +531 -0
  167. package/dist/server-data-source.d.ts +240 -6
  168. package/dist/server-data-source.js +220 -20
  169. package/dist/server.d.ts +13 -0
  170. package/dist/server.js +13 -0
  171. package/dist/shortcut-registry.d.ts +145 -0
  172. package/dist/shortcut-registry.js +44 -0
  173. package/dist/svgrid-wrapper.types.d.ts +213 -22
  174. package/dist/validate.d.ts +2 -0
  175. package/dist/validate.js +8 -3
  176. package/dist/virtualization/virtualizer.js +38 -17
  177. package/package.json +11 -1
  178. package/src/GridMenus.svelte +44 -2
  179. package/src/SvChartMenu.svelte +69 -0
  180. package/src/SvChartPanes.svelte +113 -0
  181. package/src/SvChartPanes.test.ts +66 -0
  182. package/src/SvGrid.controller.svelte.ts +818 -179
  183. package/src/SvGrid.css +178 -2
  184. package/src/SvGrid.svelte +467 -516
  185. package/src/SvGrid.types.ts +293 -11
  186. package/src/SvGridCellEditor.svelte +17 -0
  187. package/src/SvGridChart.svelte +2257 -329
  188. package/src/SvGridChart.test.ts +1419 -1
  189. package/src/SvGridChart.types.ts +336 -0
  190. package/src/SvGridChartBuilder.svelte +323 -0
  191. package/src/SvGridChartPanel.svelte +221 -275
  192. package/src/SvGridChartPickers.svelte +417 -0
  193. package/src/SvGridChartView.svelte +13 -14
  194. package/src/SvModal.svelte +7 -1
  195. package/src/SvModal.test.ts +9 -0
  196. package/src/ai.test.ts +57 -2
  197. package/src/ai.ts +166 -22
  198. package/src/aria.d.ts +11 -0
  199. package/src/build-api.coverage.test.ts +184 -0
  200. package/src/build-api.ts +118 -22
  201. package/src/chart-axes.test.ts +573 -0
  202. package/src/chart-axes.ts +342 -0
  203. package/src/chart-cartesian.ts +1863 -0
  204. package/src/chart-decimate.test.ts +249 -0
  205. package/src/chart-decimate.ts +186 -0
  206. package/src/chart-export-pdf.test.ts +91 -0
  207. package/src/chart-export-pdf.ts +207 -0
  208. package/src/chart-export.test.ts +14 -0
  209. package/src/chart-export.ts +13 -3
  210. package/src/chart-financial.ts +208 -0
  211. package/src/chart-flow.ts +286 -0
  212. package/src/chart-format.ts +67 -0
  213. package/src/chart-grid.ts +179 -0
  214. package/src/chart-hierarchy.ts +135 -0
  215. package/src/chart-indicators.test.ts +443 -0
  216. package/src/chart-indicators.ts +384 -0
  217. package/src/chart-messages.test.ts +21 -0
  218. package/src/chart-messages.ts +184 -0
  219. package/src/chart-motion.test.ts +71 -0
  220. package/src/chart-motion.ts +148 -0
  221. package/src/chart-panel-messages.test.ts +29 -0
  222. package/src/chart-panel-messages.ts +550 -0
  223. package/src/chart-pivot.test.ts +54 -0
  224. package/src/chart-pivot.ts +225 -0
  225. package/src/chart-polar.ts +674 -0
  226. package/src/chart-samples.ts +106 -0
  227. package/src/chart-scale.ts +394 -0
  228. package/src/chart-series-types.test.ts +714 -0
  229. package/src/chart-stats.ts +409 -0
  230. package/src/chart-stream.test.ts +75 -0
  231. package/src/chart-stream.ts +114 -0
  232. package/src/chart-summary.test.ts +90 -0
  233. package/src/chart-summary.ts +197 -0
  234. package/src/chart-sync.svelte.ts +41 -0
  235. package/src/chart-table.test.ts +76 -0
  236. package/src/chart-table.ts +178 -0
  237. package/src/chart-trend.ts +47 -0
  238. package/src/chart-types.ts +1309 -0
  239. package/src/chart-validate.test.ts +100 -0
  240. package/src/chart-validate.ts +247 -0
  241. package/src/chart-zoom.test.ts +137 -0
  242. package/src/chart-zoom.ts +124 -0
  243. package/src/chart.coverage.test.ts +81 -0
  244. package/src/chart.test.ts +56 -3
  245. package/src/chart.ts +557 -2784
  246. package/src/clipboard.test.ts +151 -0
  247. package/src/clipboard.ts +145 -16
  248. package/src/column-resize.ts +7 -1
  249. package/src/columns.ts +2 -0
  250. package/src/command-context.test.ts +200 -0
  251. package/src/command-context.ts +137 -0
  252. package/src/core.rowmodel-cache.test.ts +51 -0
  253. package/src/core.ts +40 -12
  254. package/src/editing.test.ts +281 -3
  255. package/src/editing.ts +264 -38
  256. package/src/fill-patterns.test.ts +35 -0
  257. package/src/fill-patterns.ts +56 -2
  258. package/src/grid-icons.ts +2 -2
  259. package/src/grid-messages.ts +21 -3
  260. package/src/history.test.ts +196 -0
  261. package/src/history.ts +162 -0
  262. package/src/icon-seam.test.ts +5 -6
  263. package/src/index.ts +169 -12
  264. package/src/keyboard-handlers.coverage.test.ts +126 -6
  265. package/src/keyboard-handlers.ts +91 -30
  266. package/src/keyboard-shortcuts.seam.test.ts +200 -0
  267. package/src/keyboard.test.ts +124 -1
  268. package/src/keyboard.ts +142 -0
  269. package/src/menus.test.ts +26 -0
  270. package/src/menus.ts +10 -3
  271. package/src/merges.test.ts +112 -0
  272. package/src/merges.ts +168 -0
  273. package/src/pivot.grid.test.ts +40 -5
  274. package/src/row-model.ts +146 -0
  275. package/src/row-resize.test.ts +44 -0
  276. package/src/row-resize.ts +17 -0
  277. package/src/scroll-sync.test.ts +42 -1
  278. package/src/scroll-sync.ts +25 -0
  279. package/src/selection.multi-range.test.ts +34 -0
  280. package/src/selection.test.ts +33 -2
  281. package/src/selection.ts +143 -21
  282. package/src/server-block-cache.test.ts +645 -0
  283. package/src/server-block-cache.ts +677 -0
  284. package/src/server-data-source.infinite.test.ts +343 -0
  285. package/src/server-data-source.ts +450 -27
  286. package/src/server.ts +47 -0
  287. package/src/shortcut-registry.test.ts +97 -0
  288. package/src/shortcut-registry.ts +181 -0
  289. package/src/svgrid-wrapper.types.ts +184 -13
  290. package/src/svgrid.behavior.test.ts +135 -0
  291. package/src/svgrid.charting.test.ts +513 -3
  292. package/src/svgrid.context-menu.test.ts +31 -0
  293. package/src/svgrid.new-features.wrapper.test.ts +10 -3
  294. package/src/svgrid.row-model-prop.svelte.test.ts +352 -0
  295. package/src/svgrid.row-model-seam.svelte.test.ts +289 -0
  296. package/src/validate.test.ts +10 -0
  297. package/src/validate.ts +10 -3
  298. package/src/virtualization/virtualizer.ts +39 -17
  299. package/dist/SvGroupCell.svelte +0 -141
  300. package/dist/SvGroupCell.svelte.d.ts +0 -49
  301. package/dist/SvRowGroupPanel.svelte +0 -186
  302. package/dist/SvRowGroupPanel.svelte.d.ts +0 -25
  303. package/dist/cdn/GridMenus-CHOMnW-c.js +0 -602
  304. package/dist/cdn/SvDateTimePicker-CCbDZNZB.js +0 -816
  305. package/dist/cdn/SvGridChart-1PMSp2LZ.js +0 -1481
  306. package/dist/cdn/SvGridChart-D02avhyr.js +0 -1480
  307. package/dist/cdn/SvGridChartPanel-DJnViOv4.js +0 -834
  308. package/dist/cdn/SvGridChartPanel-vPTNerFZ.js +0 -810
  309. package/dist/cdn/SvGridChartView-C--HhdUo.js +0 -56
  310. package/dist/cdn/SvGridChartView-KyyFG-wY.js +0 -55
  311. package/dist/cdn/chart-DLg3_zTQ.js +0 -1652
  312. package/dist/cdn/validate-_CDJzgIo.js +0 -75
  313. package/dist/server-group-model.d.ts +0 -98
  314. package/dist/server-group-model.js +0 -263
  315. package/src/SvGroupCell.svelte +0 -141
  316. package/src/SvRowGroupPanel.svelte +0 -186
  317. package/src/server-group-model.test.ts +0 -294
  318. package/src/server-group-model.ts +0 -370
@@ -33,29 +33,46 @@ function sameState(a: VirtualizerState, b: VirtualizerState) {
33
33
  for (let i = 0; i < a.items.length; i += 1) {
34
34
  const ai = a.items[i]!
35
35
  const bi = b.items[i]!
36
- if (ai.index !== bi.index || ai.start !== bi.start || ai.size !== bi.size) return false
36
+ if (ai.index !== bi.index || ai.start !== bi.start || ai.size !== bi.size || ai.key !== bi.key) return false
37
37
  }
38
38
  return true
39
39
  }
40
40
 
41
- // Slot-based keying: the key is the POSITION of the item inside the
42
- // visible window (slot 0 = topmost rendered row, slot 1 = next, etc.)
43
- // - NOT the data index. As the user scrolls, the window's startIndex
44
- // changes but the slot keys stay the same (0..N-1), so Svelte recycles
45
- // the existing <tr> DOM nodes and only updates their data + position.
41
+ // Slot-based keying: the key is a SLOT number, not the data index, so the
42
+ // same N <tr> nodes stay alive for the lifetime of the grid and scrolling
43
+ // never mounts or unmounts a row. With data-index keys, scrolling down one
44
+ // row meant the old topmost key disappeared and a new bottommost key
45
+ // appeared, so Svelte unmounted the top <tr> and mounted a fresh one at the
46
+ // bottom on every scroll tick.
46
47
  //
47
- // This avoids the mount/unmount churn that previously fired on every
48
- // scroll tick: with data-index keys, scrolling down 1 row meant the old
49
- // topmost key disappeared and a new bottommost key appeared, forcing
50
- // Svelte to unmount the top <tr> and mount a fresh one at the bottom.
51
- // Slot-based keys keep the same N <tr> nodes alive for the lifetime of
52
- // the grid; scroll just translates them via the top spacer.
48
+ // The slot for data index i is `i mod N`, N being the window length. That
49
+ // matters for what a one-row scroll costs: while N holds, a row that stays
50
+ // inside the window keeps its slot, so Svelte keeps its <tr> and touches
51
+ // nothing in it, and only the row that entered gets new content - the keyed
52
+ // each moves that one <tr> to the other end with a single `insertBefore`.
53
+ // The earlier `i - startIndex` slot scheme handed EVERY rendered row a new
54
+ // index on every one-row scroll, so an arrow key re-rendered all ~30 rows x
55
+ // every rendered column to shift the data up by one.
56
+ //
57
+ // The modulus has to be EXACTLY N, not merely >= N: under a larger modulus
58
+ // the window's residues are a proper subset, so each one-row scroll drops
59
+ // one residue and picks up another, and Svelte unmounts a <tr> and mounts a
60
+ // fresh one instead of moving it (measured: mount + unmount per arrow key,
61
+ // zero moves). When N changes - the top and bottom overscan clamping on the
62
+ // first and last rows, a resize, variable row heights - every slot remaps
63
+ // and the whole window re-renders once, which is what the old scheme did on
64
+ // every tick.
65
+ function slotKey(index: number, windowLength: number): string {
66
+ return `virtual_slot_${index % windowLength}`
67
+ }
68
+
53
69
  function buildUniformItems(
54
70
  startIndex: number,
55
71
  endIndex: number,
56
72
  estimateSize: number,
57
73
  ): Array<VirtualItem> {
58
74
  const items: Array<VirtualItem> = []
75
+ const windowLength = endIndex - startIndex + 1
59
76
  for (let index = startIndex; index <= endIndex; index += 1) {
60
77
  const start = index * estimateSize
61
78
  items.push({
@@ -63,7 +80,7 @@ function buildUniformItems(
63
80
  start,
64
81
  size: estimateSize,
65
82
  end: start + estimateSize,
66
- key: `virtual_slot_${index - startIndex}`,
83
+ key: slotKey(index, windowLength),
67
84
  })
68
85
  }
69
86
  return items
@@ -91,8 +108,8 @@ export function buildPreMeasureItems(
91
108
  if (count <= 0) return []
92
109
  const size = Math.max(estimateSize, 1)
93
110
  const visible = Math.ceil(Math.max(viewportHeight, 0) / size)
94
- const endIndex = Math.min(visible + Math.max(overscan, 0), count - 1)
95
- return buildUniformItems(0, Math.max(endIndex, 0), size)
111
+ const endIndex = Math.max(Math.min(visible + Math.max(overscan, 0), count - 1), 0)
112
+ return buildUniformItems(0, endIndex, size)
96
113
  }
97
114
 
98
115
  function buildVariableItems(
@@ -101,6 +118,7 @@ function buildVariableItems(
101
118
  offsets: Array<number>,
102
119
  ): Array<VirtualItem> {
103
120
  const items: Array<VirtualItem> = []
121
+ const windowLength = endIndex - startIndex + 1
104
122
  for (let index = startIndex; index <= endIndex; index += 1) {
105
123
  const start = offsets[index] ?? 0
106
124
  const end = offsets[index + 1] ?? start
@@ -109,7 +127,7 @@ function buildVariableItems(
109
127
  start,
110
128
  size: end - start,
111
129
  end,
112
- key: `virtual_slot_${index - startIndex}`,
130
+ key: slotKey(index, windowLength),
113
131
  })
114
132
  }
115
133
  return items
@@ -215,8 +233,12 @@ export function createVirtualizer(initial: VirtualizerOptions) {
215
233
  const sizeFn = options.estimateSize
216
234
  const offsets = new Array<number>(count + 1)
217
235
  offsets[0] = 0
236
+ // A size of 0 is a real size: a collapsed row or column takes no room
237
+ // and both searches below stay monotonic over equal offsets. Only a
238
+ // negative size is nonsense. The floor used to be 1, which left every
239
+ // hidden column a one-pixel sliver.
218
240
  for (let i = 0; i < count; i += 1) {
219
- offsets[i + 1] = offsets[i]! + Math.max(sizeFn(i), 1)
241
+ offsets[i + 1] = offsets[i]! + Math.max(sizeFn(i), 0)
220
242
  }
221
243
  offsetCache = { fn: sizeFn, count, offsets }
222
244
  return offsets
@@ -1,141 +0,0 @@
1
- <!--
2
- Built-in group cell for the server-side group/tree model. Drop it into the
3
- grouping column and it draws the expander + indentation for group rows (and an
4
- indented leaf value) - no hand-written cell recipe. Pair with `serverGroupRows`
5
- to feed `<SvGrid data>`, and wire `onToggle` to the controller's `toggleGroup`.
6
-
7
- cell: (ctx) => renderComponent(SvGroupCell, {
8
- row: ctx.row.original, onToggle: ctl.toggleGroup, leafField: 'name',
9
- })
10
- -->
11
- <script lang="ts" generics="TData">
12
- import type { ServerDisplayRow } from './server-data-source'
13
- import type { GridIcons } from './grid-icons'
14
-
15
- type GroupGridRow = { __group?: ServerDisplayRow<TData> } & Record<string, unknown>
16
- type Props = {
17
- /** The grid row from `serverGroupRows` (carries the `__group` marker). */
18
- row: GroupGridRow
19
- /**
20
- * Expand / collapse a group, or load more children. Receives the grid row;
21
- * wire to `serverGroupNav(ctl).onToggle` (which drives clicks and keyboard).
22
- */
23
- onToggle: (row: GroupGridRow) => void
24
- /** Field to show for leaf rows in the group column (blank if omitted). */
25
- leafField?: string
26
- /** Pixels of indentation per level. Default 18. */
27
- indent?: number
28
- /**
29
- * Icon overrides, the same map `<SvGrid icons>` takes. Only
30
- * `chevron-right` is drawn here. You mount this component yourself, so it
31
- * cannot inherit the grid's icons - pass the same object to both to keep
32
- * the expander consistent with the rest of the chrome.
33
- */
34
- icons?: GridIcons
35
- }
36
-
37
- let { row, onToggle, leafField, indent = 18, icons }: Props = $props()
38
- const chevron = $derived(icons?.['chevron-right'])
39
- const meta = $derived(row.__group)
40
- </script>
41
-
42
- {#if meta && meta.kind === 'group'}
43
- <button
44
- type="button"
45
- class="sv-group-cell"
46
- style={`padding-inline-start: ${meta.level * indent}px`}
47
- aria-expanded={meta.expanded}
48
- aria-label={meta.expanded ? 'Collapse group' : 'Expand group'}
49
- onclick={() => onToggle(row)}
50
- >
51
- <!-- Same chevron the grid's own expanders and SvTree draw, so every
52
- expander in the library looks identical. -->
53
- <span class="sv-group-chev" class:open={meta.expanded} aria-hidden="true">
54
- {#if chevron}
55
- {@render chevron()}
56
- {:else}
57
- <svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor"
58
- stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="m9 18 6-6-6-6" /></svg>
59
- {/if}
60
- </span>
61
- <span class="sv-group-key">{meta.key}</span>
62
- {#if meta.loading}<span class="sv-group-load" aria-hidden="true">…</span>{/if}
63
- </button>
64
- {:else if meta && meta.kind === 'more'}
65
- <button
66
- type="button"
67
- class="sv-group-more"
68
- style={`padding-inline-start: ${meta.level * indent}px`}
69
- disabled={meta.loading}
70
- onclick={() => onToggle(row)}
71
- >
72
- {meta.loading ? 'Loading...' : `Load ${meta.remaining} more`}
73
- </button>
74
- {:else if meta && meta.kind === 'footer'}
75
- <span class="sv-group-footer" style={`padding-inline-start: ${meta.level * indent}px`}>Total</span>
76
- {:else if meta && meta.kind === 'skeleton'}
77
- <span class="sv-group-skeleton" style={`margin-inline-start: ${meta.level * indent}px`} aria-hidden="true"></span>
78
- {:else if meta}
79
- <span class="sv-group-leaf" style={`padding-inline-start: ${(meta.level + 1) * indent}px`}>
80
- {leafField ? (row[leafField] ?? '') : ''}
81
- </span>
82
- {/if}
83
-
84
- <style>
85
- .sv-group-cell {
86
- display: inline-flex;
87
- align-items: center;
88
- gap: 6px;
89
- background: none;
90
- border: 0;
91
- padding: 0;
92
- font: inherit;
93
- color: inherit;
94
- cursor: pointer;
95
- }
96
- .sv-group-chev {
97
- display: inline-flex;
98
- align-items: center;
99
- justify-content: center;
100
- width: 12px;
101
- height: 12px;
102
- transition: transform 0.15s;
103
- color: var(--sg-muted, #64748b);
104
- }
105
- /* An `icons` override renders inside this wrapper, and this style block is
106
- scoped, so its markup needs :global() to be reached. Sizing it here means
107
- a custom chevron lands in the same box as the built-in and rotates with
108
- the wrapper rather than needing to know the rule exists. */
109
- .sv-group-chev :global(svg),
110
- .sv-group-chev :global(img) {
111
- width: 100%;
112
- height: 100%;
113
- display: block;
114
- }
115
- .sv-group-chev.open { transform: rotate(90deg); }
116
- .sv-group-key { font-weight: 600; }
117
- .sv-group-load { color: var(--sg-muted, #64748b); font-size: 12px; }
118
- .sv-group-leaf { color: var(--sg-muted, #475569); }
119
- .sv-group-more {
120
- background: none;
121
- border: 0;
122
- padding: 0;
123
- font: inherit;
124
- font-size: 13px;
125
- color: var(--sg-accent, #2563eb);
126
- cursor: pointer;
127
- }
128
- .sv-group-more:disabled { color: var(--sg-muted, #64748b); cursor: default; }
129
- .sv-group-footer { font-weight: 600; color: var(--sg-muted, #64748b); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
130
- .sv-group-skeleton {
131
- display: inline-block;
132
- width: 60%;
133
- height: 10px;
134
- border-radius: 5px;
135
- background: linear-gradient(90deg, var(--sg-border, #e2e8f0) 25%, var(--sg-header-bg, #f1f5f9) 50%, var(--sg-border, #e2e8f0) 75%);
136
- background-size: 200% 100%;
137
- animation: sv-group-shimmer 1.2s infinite;
138
- }
139
- @keyframes sv-group-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
140
- @media (prefers-reduced-motion: reduce) { .sv-group-skeleton { animation: none; } }
141
- </style>
@@ -1,49 +0,0 @@
1
- import type { ServerDisplayRow } from './server-data-source.js';
2
- import type { GridIcons } from './grid-icons.js';
3
- declare function $$render<TData>(): {
4
- props: {
5
- /** The grid row from `serverGroupRows` (carries the `__group` marker). */
6
- row: {
7
- __group?: ServerDisplayRow<TData>;
8
- } & Record<string, unknown>;
9
- /**
10
- * Expand / collapse a group, or load more children. Receives the grid row;
11
- * wire to `serverGroupNav(ctl).onToggle` (which drives clicks and keyboard).
12
- */
13
- onToggle: (row: {
14
- __group?: ServerDisplayRow<TData>;
15
- } & Record<string, unknown>) => void;
16
- /** Field to show for leaf rows in the group column (blank if omitted). */
17
- leafField?: string;
18
- /** Pixels of indentation per level. Default 18. */
19
- indent?: number;
20
- /**
21
- * Icon overrides, the same map `<SvGrid icons>` takes. Only
22
- * `chevron-right` is drawn here. You mount this component yourself, so it
23
- * cannot inherit the grid's icons - pass the same object to both to keep
24
- * the expander consistent with the rest of the chrome.
25
- */
26
- icons?: GridIcons;
27
- };
28
- exports: {};
29
- bindings: "";
30
- slots: {};
31
- events: {};
32
- };
33
- declare class __sveltets_Render<TData> {
34
- props(): ReturnType<typeof $$render<TData>>['props'];
35
- events(): ReturnType<typeof $$render<TData>>['events'];
36
- slots(): ReturnType<typeof $$render<TData>>['slots'];
37
- bindings(): "";
38
- exports(): {};
39
- }
40
- interface $$IsomorphicComponent {
41
- new <TData>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TData>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TData>['props']>, ReturnType<__sveltets_Render<TData>['events']>, ReturnType<__sveltets_Render<TData>['slots']>> & {
42
- $$bindings?: ReturnType<__sveltets_Render<TData>['bindings']>;
43
- } & ReturnType<__sveltets_Render<TData>['exports']>;
44
- <TData>(internal: unknown, props: ReturnType<__sveltets_Render<TData>['props']> & {}): ReturnType<__sveltets_Render<TData>['exports']>;
45
- z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
46
- }
47
- declare const SvGroupCell: $$IsomorphicComponent;
48
- type SvGroupCell<TData> = InstanceType<typeof SvGroupCell<TData>>;
49
- export default SvGroupCell;
@@ -1,186 +0,0 @@
1
- <!--
2
- A row-group panel (like the "drag columns to group" bar in enterprise grids).
3
- Shows the current group-by columns as chips you can remove or drag to reorder,
4
- plus a "+ Group by" menu to add one. It is also a drop target: a column drag
5
- that carries `text/sv-column` (its column id) adds that column. Wire `onChange`
6
- to a server group model's `setGroupBy`, or to client grouping.
7
-
8
- <SvRowGroupPanel
9
- columns={[{ id: 'region', label: 'Region' }, { id: 'country', label: 'Country' }]}
10
- groupBy={view.groupBy}
11
- onChange={(g) => ctl.setGroupBy(g)}
12
- />
13
- -->
14
- <script lang="ts">
15
- import { GRID_ICON_GLYPHS, type GridIconName, type GridIcons } from './grid-icons'
16
-
17
- type Col = { id: string; label: string }
18
- type Props = {
19
- /** Columns that can be grouped on. */
20
- columns: Col[]
21
- /** Current group-by column ids, outer to inner. */
22
- groupBy: string[]
23
- /** Called with the new group-by order. */
24
- onChange: (groupBy: string[]) => void
25
- /** Text shown when nothing is grouped. */
26
- placeholder?: string
27
- /**
28
- * Icon overrides, the same map `<SvGrid icons>` takes. This panel draws
29
- * `drag-handle`, `remove` and `breadcrumb-separator`. You mount it
30
- * yourself, so pass the same object you gave the grid to keep them
31
- * consistent.
32
- */
33
- icons?: GridIcons
34
- }
35
- let { columns, groupBy, onChange, placeholder = 'Drag a column here to group by it', icons }: Props = $props()
36
-
37
- const labelOf = (id: string) => columns.find((c) => c.id === id)?.label ?? id
38
- const available = $derived(columns.filter((c) => !groupBy.includes(c.id)))
39
-
40
- let dragIndex = $state<number | null>(null)
41
-
42
- function remove(id: string) {
43
- onChange(groupBy.filter((g) => g !== id))
44
- }
45
- function add(id: string) {
46
- if (id && !groupBy.includes(id)) onChange([...groupBy, id])
47
- }
48
- function reorder(to: number) {
49
- if (dragIndex === null || dragIndex === to) return
50
- const next = [...groupBy]
51
- const [moved] = next.splice(dragIndex, 1)
52
- next.splice(to, 0, moved!)
53
- dragIndex = null
54
- onChange(next)
55
- }
56
- function onPanelDrop(e: DragEvent) {
57
- const id = e.dataTransfer?.getData('text/sv-column')
58
- if (id) add(id)
59
- }
60
- /** Keyboard equivalent of dragging a chip: moves the chip at `i` one slot earlier/later,
61
- * reusing `reorder()` (via `dragIndex`) so there is a single source of truth for the move. */
62
- function moveByKeyboard(i: number, delta: number) {
63
- const to = i + delta
64
- if (to < 0 || to >= groupBy.length) return
65
- dragIndex = i
66
- reorder(to)
67
- }
68
- function onChipKeydown(e: KeyboardEvent, i: number) {
69
- if (!e.altKey) return
70
- if (e.key === 'ArrowLeft') {
71
- e.preventDefault()
72
- moveByKeyboard(i, -1)
73
- } else if (e.key === 'ArrowRight') {
74
- e.preventDefault()
75
- moveByKeyboard(i, 1)
76
- }
77
- }
78
- </script>
79
-
80
- <!-- Same override-or-default resolution SvGrid uses, kept local because this
81
- component is mounted by the consumer and never sees the grid's snippet. -->
82
- {#snippet ic(name: GridIconName)}
83
- {@const override = icons?.[name]}
84
- {#if override}{@render override()}{:else}{GRID_ICON_GLYPHS[name]}{/if}
85
- {/snippet}
86
-
87
- <div
88
- class="sv-rowgroup-panel"
89
- role="group"
90
- aria-label="Row groups"
91
- ondragover={(e) => e.preventDefault()}
92
- ondrop={onPanelDrop}
93
- >
94
- <span class="sv-rgp-label" aria-hidden="true">Group by:</span>
95
- {#if groupBy.length === 0}
96
- <span class="sv-rgp-empty">{placeholder}</span>
97
- {:else}
98
- {#each groupBy as id, i (id)}
99
- {#if i > 0}<span class="sv-rgp-sep" aria-hidden="true">{@render ic('breadcrumb-separator')}</span>{/if}
100
- <!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
101
- <span
102
- class="sv-rgp-chip"
103
- class:sv-rgp-chip-drag={dragIndex === i}
104
- role="group"
105
- tabindex="0"
106
- aria-label={`Grouped by ${labelOf(id)}, position ${i + 1} of ${groupBy.length}. Press Alt+Arrow keys to reorder.`}
107
- draggable="true"
108
- ondragstart={() => (dragIndex = i)}
109
- ondragend={() => (dragIndex = null)}
110
- ondragover={(e) => e.preventDefault()}
111
- ondrop={() => reorder(i)}
112
- onkeydown={(e) => onChipKeydown(e, i)}
113
- >
114
- <span class="sv-rgp-grip" aria-hidden="true">{@render ic('drag-handle')}</span>
115
- {labelOf(id)}
116
- <button type="button" class="sv-rgp-x" onclick={() => remove(id)} aria-label={`Stop grouping by ${labelOf(id)}`}>{@render ic('remove')}</button>
117
- </span>
118
- {/each}
119
- {/if}
120
- {#if available.length}
121
- <select
122
- class="sv-rgp-add"
123
- aria-label="Add a group column"
124
- onchange={(e) => { add(e.currentTarget.value); e.currentTarget.value = '' }}
125
- >
126
- <option value="">+ Group by</option>
127
- {#each available as c (c.id)}<option value={c.id}>{c.label}</option>{/each}
128
- </select>
129
- {/if}
130
- </div>
131
-
132
- <style>
133
- .sv-rowgroup-panel {
134
- display: flex;
135
- align-items: center;
136
- flex-wrap: wrap;
137
- gap: 6px;
138
- padding: 8px 10px;
139
- border: 1px dashed var(--sg-border, #cbd5e1);
140
- border-radius: 10px;
141
- background: var(--sg-header-bg, #f8fafc);
142
- font-size: 13px;
143
- }
144
- .sv-rgp-label { color: var(--sg-muted, #64748b); font-weight: 600; }
145
- .sv-rgp-empty { color: var(--sg-muted, #94a3b8); font-style: italic; }
146
- .sv-rgp-sep { color: var(--sg-muted, #94a3b8); }
147
- .sv-rgp-chip {
148
- display: inline-flex;
149
- align-items: center;
150
- gap: 6px;
151
- padding: 3px 6px 3px 8px;
152
- border-radius: 999px;
153
- background: var(--sg-bg, #fff);
154
- border: 1px solid var(--sg-border, #e2e8f0);
155
- cursor: grab;
156
- user-select: none;
157
- font-weight: 600;
158
- }
159
- .sv-rgp-chip-drag { opacity: 0.5; }
160
- .sv-rgp-grip { color: var(--sg-muted, #94a3b8); cursor: grab; }
161
- .sv-rgp-x {
162
- display: inline-flex;
163
- align-items: center;
164
- justify-content: center;
165
- width: 16px;
166
- height: 16px;
167
- border: 0;
168
- border-radius: 50%;
169
- background: none;
170
- color: var(--sg-muted, #64748b);
171
- cursor: pointer;
172
- font-size: 14px;
173
- line-height: 1;
174
- }
175
- .sv-rgp-x:hover { background: var(--sg-header-bg, #f1f5f9); color: var(--sg-fg, #0f172a); }
176
- .sv-rgp-add {
177
- font: inherit;
178
- font-size: 13px;
179
- padding: 4px 8px;
180
- border-radius: 8px;
181
- border: 1px solid var(--sg-border, #e2e8f0);
182
- background: var(--sg-bg, #fff);
183
- color: var(--sg-accent, #2563eb);
184
- cursor: pointer;
185
- }
186
- </style>
@@ -1,25 +0,0 @@
1
- import { type GridIcons } from './grid-icons.js';
2
- type Col = {
3
- id: string;
4
- label: string;
5
- };
6
- type Props = {
7
- /** Columns that can be grouped on. */
8
- columns: Col[];
9
- /** Current group-by column ids, outer to inner. */
10
- groupBy: string[];
11
- /** Called with the new group-by order. */
12
- onChange: (groupBy: string[]) => void;
13
- /** Text shown when nothing is grouped. */
14
- placeholder?: string;
15
- /**
16
- * Icon overrides, the same map `<SvGrid icons>` takes. This panel draws
17
- * `drag-handle`, `remove` and `breadcrumb-separator`. You mount it
18
- * yourself, so pass the same object you gave the grid to keep them
19
- * consistent.
20
- */
21
- icons?: GridIcons;
22
- };
23
- declare const SvRowGroupPanel: import("svelte").Component<Props, {}, "">;
24
- type SvRowGroupPanel = ReturnType<typeof SvRowGroupPanel>;
25
- export default SvRowGroupPanel;