@svgrid/grid 2.6.1 → 2.6.2

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 (374) hide show
  1. package/README.md +199 -199
  2. package/dist/FlexRender.svelte +96 -96
  3. package/dist/GridFooter.svelte +178 -178
  4. package/dist/GridMenus.svelte +705 -705
  5. package/dist/SvAutoComplete.svelte +165 -165
  6. package/dist/SvAvatar.svelte +75 -75
  7. package/dist/SvCalendar.svelte +503 -503
  8. package/dist/SvCarousel.svelte +141 -141
  9. package/dist/SvCheckBox.svelte +102 -102
  10. package/dist/SvCircularProgress.svelte +109 -109
  11. package/dist/SvColorInput.svelte +181 -181
  12. package/dist/SvComboBox.svelte +275 -275
  13. package/dist/SvContextMenu.svelte +116 -116
  14. package/dist/SvCountryInput.svelte +162 -162
  15. package/dist/SvDrawer.svelte +254 -254
  16. package/dist/SvDropDownList.svelte +374 -374
  17. package/dist/SvDurationInput.svelte +126 -126
  18. package/dist/SvField.svelte +293 -293
  19. package/dist/SvForm.svelte +437 -437
  20. package/dist/SvGrid.controller.svelte.js +22 -10
  21. package/dist/SvGrid.css +2814 -2814
  22. package/dist/SvGrid.svelte +3490 -3490
  23. package/dist/SvGridChart.svelte +1716 -1716
  24. package/dist/SvGridChartPanel.svelte +485 -485
  25. package/dist/SvGridChartView.svelte +70 -70
  26. package/dist/SvGridDropdown.svelte +728 -728
  27. package/dist/SvGridSelect.svelte +266 -266
  28. package/dist/SvGroupCell.svelte +116 -116
  29. package/dist/SvListBox.svelte +326 -326
  30. package/dist/SvMaskedInput.svelte +122 -122
  31. package/dist/SvMenu.svelte +124 -124
  32. package/dist/SvMenuList.svelte +146 -146
  33. package/dist/SvMultiSelect.svelte +289 -289
  34. package/dist/SvNumberInput.svelte +168 -168
  35. package/dist/SvOtpInput.svelte +158 -158
  36. package/dist/SvPasswordInput.svelte +151 -151
  37. package/dist/SvPhoneInput.svelte +133 -133
  38. package/dist/SvPopover.svelte +197 -197
  39. package/dist/SvProgress.svelte +116 -116
  40. package/dist/SvRadioGroup.svelte +107 -107
  41. package/dist/SvRating.svelte +112 -112
  42. package/dist/SvResult.svelte +73 -73
  43. package/dist/SvRichText.svelte +211 -211
  44. package/dist/SvRowGroupPanel.svelte +170 -170
  45. package/dist/SvScrollArea.svelte +61 -61
  46. package/dist/SvSlider.svelte +202 -202
  47. package/dist/SvSwitchButton.svelte +108 -108
  48. package/dist/SvTagsInput.svelte +114 -114
  49. package/dist/SvTextInput.svelte +147 -147
  50. package/dist/SvTimePicker.svelte +245 -245
  51. package/dist/SvToaster.svelte +159 -159
  52. package/dist/SvToggleButton.svelte +85 -85
  53. package/dist/SvTooltip.svelte +161 -161
  54. package/dist/SvTour.svelte +208 -208
  55. package/dist/SvTree.svelte +444 -444
  56. package/dist/SvTreeSelect.svelte +235 -235
  57. package/dist/cdn/{GridMenus-DfmxE2Tb.js → GridMenus-BoVKgAv8.js} +9 -9
  58. package/dist/cdn/{GridMenus-CaaYtSpU.js → GridMenus-DL1zrDwf.js} +9 -9
  59. package/dist/cdn/{SvDateTimePicker-DSUhIta8.js → SvDateTimePicker-CHnUkWcH.js} +2 -2
  60. package/dist/cdn/{SvDateTimePicker-h9kPyszT.js → SvDateTimePicker-CRQH_U7E.js} +2 -2
  61. package/dist/cdn/{SvGridChart-CwhFz7GV.js → SvGridChart-BEJmNNx9.js} +1 -1
  62. package/dist/cdn/{SvGridChart-Bs2GIR2Q.js → SvGridChart-BwVos976.js} +1 -1
  63. package/dist/cdn/{SvGridChartPanel-1WXuStzM.js → SvGridChartPanel-BOknOkrP.js} +1 -1
  64. package/dist/cdn/{SvGridChartPanel-e5_nqNP9.js → SvGridChartPanel-D2PjII4O.js} +1 -1
  65. package/dist/cdn/{SvGridChartView-SmPW10dI.js → SvGridChartView-00LPUHL1.js} +1 -1
  66. package/dist/cdn/{SvGridChartView-eSPuJE6g.js → SvGridChartView-BhUEJ5ki.js} +1 -1
  67. package/dist/cdn/{SvGridDropdown-B1ZcLpgs.js → SvGridDropdown-D0VdjeR8.js} +1 -1
  68. package/dist/cdn/{SvGridDropdown-CtdbHcIS.js → SvGridDropdown-D13MtJ2j.js} +1 -1
  69. package/dist/cdn/{src-BIIhU1uh.js → src-CEpw6Ato.js} +2885 -2863
  70. package/dist/cdn/{src-DisUdSk9.js → src-M2NfKnjX.js} +2106 -2084
  71. package/dist/cdn/svgrid.js +8 -8
  72. package/dist/cdn/svgrid.svelte-external.js +8 -8
  73. package/dist/chart-export.js +8 -8
  74. package/dist/filtering/excel-filters.d.ts +14 -0
  75. package/dist/filtering/excel-filters.js +67 -32
  76. package/dist/index.d.ts +1 -1
  77. package/dist/index.js +1 -1
  78. package/package.json +11 -11
  79. package/src/FlexRender.svelte +96 -96
  80. package/src/GridFooter.svelte +178 -178
  81. package/src/GridMenus.svelte +705 -705
  82. package/src/SvAutoComplete.svelte +165 -165
  83. package/src/SvAvatar.svelte +75 -75
  84. package/src/SvCalendar.svelte +503 -503
  85. package/src/SvCalendar.test.ts +226 -226
  86. package/src/SvCarousel.svelte +141 -141
  87. package/src/SvCheckBox.svelte +102 -102
  88. package/src/SvCircularProgress.svelte +109 -109
  89. package/src/SvColorInput.svelte +181 -181
  90. package/src/SvComboBox.svelte +275 -275
  91. package/src/SvContextMenu.svelte +116 -116
  92. package/src/SvCountryInput.svelte +162 -162
  93. package/src/SvDrawer.svelte +254 -254
  94. package/src/SvDropDownList.svelte +374 -374
  95. package/src/SvDurationInput.svelte +126 -126
  96. package/src/SvField.svelte +293 -293
  97. package/src/SvForm.svelte +437 -437
  98. package/src/SvForm.test.ts +411 -411
  99. package/src/SvGrid.controller.svelte.ts +3691 -3680
  100. package/src/SvGrid.css +2814 -2814
  101. package/src/SvGrid.svelte +3490 -3490
  102. package/src/SvGrid.types.ts +1708 -1708
  103. package/src/SvGridChart.svelte +1716 -1716
  104. package/src/SvGridChartPanel.svelte +485 -485
  105. package/src/SvGridChartView.svelte +70 -70
  106. package/src/SvGridDropdown.svelte +728 -728
  107. package/src/SvGridSelect.svelte +266 -266
  108. package/src/SvGroupCell.svelte +116 -116
  109. package/src/SvListBox.svelte +326 -326
  110. package/src/SvMaskedInput.svelte +122 -122
  111. package/src/SvMenu.svelte +124 -124
  112. package/src/SvMenu.test.ts +97 -97
  113. package/src/SvMenuList.svelte +146 -146
  114. package/src/SvMultiSelect.svelte +289 -289
  115. package/src/SvNumberInput.svelte +168 -168
  116. package/src/SvOtpInput.svelte +158 -158
  117. package/src/SvPasswordInput.svelte +151 -151
  118. package/src/SvPhoneInput.svelte +133 -133
  119. package/src/SvPopover.svelte +197 -197
  120. package/src/SvProgress.svelte +116 -116
  121. package/src/SvRadioGroup.svelte +107 -107
  122. package/src/SvRating.svelte +112 -112
  123. package/src/SvResult.svelte +73 -73
  124. package/src/SvRichText.svelte +211 -211
  125. package/src/SvRowGroupPanel.svelte +170 -170
  126. package/src/SvScrollArea.svelte +61 -61
  127. package/src/SvSlider.svelte +202 -202
  128. package/src/SvSwitchButton.svelte +108 -108
  129. package/src/SvTagsInput.svelte +114 -114
  130. package/src/SvTextInput.svelte +147 -147
  131. package/src/SvTimePicker.svelte +245 -245
  132. package/src/SvToaster.svelte +159 -159
  133. package/src/SvToaster.test.ts +95 -95
  134. package/src/SvToggleButton.svelte +85 -85
  135. package/src/SvTooltip.svelte +161 -161
  136. package/src/SvTour.svelte +208 -208
  137. package/src/SvTree.svelte +444 -444
  138. package/src/SvTreeSelect.svelte +235 -235
  139. package/src/a11y/dismissable.test.ts +119 -119
  140. package/src/a11y/dismissable.ts +114 -114
  141. package/src/a11y.contract.test.ts +49 -49
  142. package/src/a11y.test.ts +59 -59
  143. package/src/a11y.ts +61 -61
  144. package/src/ai.test.ts +502 -502
  145. package/src/ai.ts +1391 -1391
  146. package/src/build-api.coverage.test.ts +633 -633
  147. package/src/build-api.ts +805 -805
  148. package/src/builtin-editors.grid.test.ts +85 -85
  149. package/src/cell-formatting.ts +169 -169
  150. package/src/cell-render.test.ts +513 -513
  151. package/src/cell-render.ts +496 -496
  152. package/src/cell-values.ts +118 -118
  153. package/src/chart-export.ts +201 -201
  154. package/src/chart-view.svelte.ts +36 -36
  155. package/src/chart.ts +2295 -2295
  156. package/src/collaboration.test.ts +104 -104
  157. package/src/collaboration.ts +167 -167
  158. package/src/core.performance.test.ts +30 -30
  159. package/src/core.ts +1261 -1261
  160. package/src/createAutocomplete.svelte.ts +132 -132
  161. package/src/createCombobox.svelte.ts +191 -191
  162. package/src/createCountryInput.svelte.ts +157 -157
  163. package/src/createDropdownList.svelte.ts +168 -168
  164. package/src/createForm.svelte.ts +386 -386
  165. package/src/createGrid.svelte.ts +42 -42
  166. package/src/createGrid.test.ts +10 -10
  167. package/src/createGridState.svelte.ts +17 -17
  168. package/src/createListbox.svelte.ts +250 -250
  169. package/src/createMenu.svelte.ts +224 -224
  170. package/src/createPopoverSelect.svelte.ts +213 -213
  171. package/src/createSlider.svelte.ts +191 -191
  172. package/src/createTooltip.svelte.ts +144 -144
  173. package/src/createTree.svelte.ts +319 -319
  174. package/src/editing.test.ts +949 -949
  175. package/src/editing.ts +606 -606
  176. package/src/editor-contract.ts +170 -170
  177. package/src/editor-registry.grid.test.ts +144 -144
  178. package/src/editor-registry.ts +122 -122
  179. package/src/export-data-api.test.ts +126 -126
  180. package/src/export-format.test.ts +107 -107
  181. package/src/export-format.ts +601 -601
  182. package/src/filter-operators.ts +157 -157
  183. package/src/filtering/excel-filters.ts +71 -34
  184. package/src/flex-render.ts +3 -3
  185. package/src/form-field.ts +127 -127
  186. package/src/group-display.test.ts +167 -167
  187. package/src/group-display.ts +200 -200
  188. package/src/index.ts +726 -724
  189. package/src/js-scroller.svelte.ts +173 -173
  190. package/src/keyboard-handlers.ts +270 -270
  191. package/src/keyboard.test.ts +59 -59
  192. package/src/keyboard.ts +97 -97
  193. package/src/list-nav.test.ts +49 -49
  194. package/src/list-nav.ts +29 -29
  195. package/src/list-option.test.ts +56 -56
  196. package/src/list-option.ts +172 -172
  197. package/src/menus.ts +567 -567
  198. package/src/merge-objects.ts +48 -48
  199. package/src/overlays.test.ts +90 -90
  200. package/src/render-component.ts +28 -28
  201. package/src/row-resize.ts +210 -210
  202. package/src/scheduler-model.test.ts +562 -562
  203. package/src/scheduler-model.ts +872 -872
  204. package/src/selection.test.ts +754 -754
  205. package/src/selection.ts +491 -491
  206. package/src/server-data-source.test.ts +289 -289
  207. package/src/server-data-source.ts +413 -413
  208. package/src/sparkline.test.ts +68 -68
  209. package/src/sparkline.ts +169 -169
  210. package/src/spreadsheet.test.ts +488 -488
  211. package/src/spreadsheet.ts +312 -312
  212. package/src/static-functions.ts +11 -11
  213. package/src/subscribe.ts +38 -38
  214. package/src/svgrid-wrapper.types.ts +526 -526
  215. package/src/svgrid.async-editor-options.test.ts +271 -271
  216. package/src/svgrid.auto-row-height.test.ts +204 -204
  217. package/src/svgrid.behavior.test.ts +705 -705
  218. package/src/svgrid.charting.test.ts +534 -534
  219. package/src/svgrid.comments-autocomplete.test.ts +123 -123
  220. package/src/svgrid.context-menu.test.ts +147 -147
  221. package/src/svgrid.features.test.ts +157 -157
  222. package/src/svgrid.filter-depth.test.ts +163 -163
  223. package/src/svgrid.filter-menu-listbox.svelte.test.ts +331 -331
  224. package/src/svgrid.filter-menu-scroll.test.ts +112 -112
  225. package/src/svgrid.grand-total.test.ts +188 -188
  226. package/src/svgrid.group-display-mode.test.ts +171 -171
  227. package/src/svgrid.group-footers.test.ts +121 -121
  228. package/src/svgrid.group-pagination.test.ts +153 -153
  229. package/src/svgrid.new-features.wrapper.test.ts +251 -251
  230. package/src/svgrid.tree-data.test.ts +186 -186
  231. package/src/svgrid.wrapper.test.ts +42 -40
  232. package/src/svgriddropdown.async-panel.svelte.test.ts +195 -195
  233. package/src/test-setup.ts +62 -62
  234. package/src/themes/index.ts +278 -278
  235. package/src/toast-store.svelte.ts +246 -246
  236. package/src/toast-store.test.ts +147 -147
  237. package/src/tree-row-model.test.ts +168 -168
  238. package/src/ui-buttons.test.ts +144 -144
  239. package/src/ui-inputs.test.ts +118 -118
  240. package/src/ui-localization.test.ts +113 -113
  241. package/src/ui-range.test.ts +70 -70
  242. package/src/ui-selection.test.ts +155 -155
  243. package/src/ui-tier1.test.ts +142 -142
  244. package/src/virtual.test.ts +88 -88
  245. package/src/virtualization/column-virtualizer.test.ts +27 -27
  246. package/src/virtualization/column-virtualizer.ts +30 -30
  247. package/src/virtualization/svelte-virtualizer.svelte.ts +26 -26
  248. package/src/virtualization/types.ts +30 -30
  249. package/src/virtualization/virtualizer.test.ts +47 -47
  250. package/src/virtualization/virtualizer.ts +296 -296
  251. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/_svelte_metadata.json +0 -1
  252. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/_metadata.json +0 -178
  253. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/attachments-qzRy9DX4.js +0 -3843
  254. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/attachments-qzRy9DX4.js.map +0 -1
  255. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/constants-RLNOXCpz.js +0 -23
  256. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/constants-RLNOXCpz.js.map +0 -1
  257. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/dev-DPd12uEU.js +0 -1925
  258. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/dev-DPd12uEU.js.map +0 -1
  259. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/events-CDC4DKuQ.js +0 -206
  260. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/events-CDC4DKuQ.js.map +0 -1
  261. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/flags-BD-lYX7s.js +0 -20
  262. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/flags-BD-lYX7s.js.map +0 -1
  263. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/hydration-D3UBU2t8.js +0 -264
  264. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/hydration-D3UBU2t8.js.map +0 -1
  265. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/legacy-client-B0ZUlbSQ.js +0 -698
  266. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/legacy-client-B0ZUlbSQ.js.map +0 -1
  267. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/package.json +0 -3
  268. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte.js +0 -135
  269. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte.js.map +0 -1
  270. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_animate.js +0 -57
  271. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_animate.js.map +0 -1
  272. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_attachments.js +0 -2
  273. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_compiler.js +0 -46691
  274. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_compiler.js.map +0 -1
  275. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_easing.js +0 -239
  276. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_easing.js.map +0 -1
  277. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_events.js +0 -2
  278. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal.js +0 -6
  279. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal.js.map +0 -1
  280. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_client.js +0 -7
  281. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_disclose-version.js +0 -6
  282. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_disclose-version.js.map +0 -1
  283. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_async.js +0 -7
  284. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_async.js.map +0 -1
  285. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_legacy.js +0 -7
  286. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_legacy.js.map +0 -1
  287. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_tracing.js +0 -7
  288. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_tracing.js.map +0 -1
  289. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_server.js +0 -6
  290. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_legacy.js +0 -85
  291. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_legacy.js.map +0 -1
  292. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_motion.js +0 -561
  293. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_motion.js.map +0 -1
  294. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity.js +0 -26
  295. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity.js.map +0 -1
  296. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity_window.js +0 -124
  297. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity_window.js.map +0 -1
  298. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_server.js +0 -2
  299. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_store.js +0 -91
  300. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_store.js.map +0 -1
  301. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_transition.js +0 -242
  302. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_transition.js.map +0 -1
  303. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-lObbumRX.js +0 -497
  304. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-lObbumRX.js.map +0 -1
  305. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-mR9mAWyK.js +0 -4929
  306. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-mR9mAWyK.js.map +0 -1
  307. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/validate-CezNmRkM.js +0 -192
  308. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/validate-CezNmRkM.js.map +0 -1
  309. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/version-BHHo0WE-.js +0 -10
  310. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/version-BHHo0WE-.js.map +0 -1
  311. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/warnings-yiExAB06.js +0 -140
  312. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/warnings-yiExAB06.js.map +0 -1
  313. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/_svelte_metadata.json +0 -1
  314. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/_metadata.json +0 -178
  315. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/attachments-qzRy9DX4.js +0 -3843
  316. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/attachments-qzRy9DX4.js.map +0 -1
  317. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/constants-RLNOXCpz.js +0 -23
  318. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/constants-RLNOXCpz.js.map +0 -1
  319. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/dev-DPd12uEU.js +0 -1925
  320. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/dev-DPd12uEU.js.map +0 -1
  321. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/events-CDC4DKuQ.js +0 -206
  322. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/events-CDC4DKuQ.js.map +0 -1
  323. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/flags-BD-lYX7s.js +0 -20
  324. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/flags-BD-lYX7s.js.map +0 -1
  325. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/hydration-D3UBU2t8.js +0 -264
  326. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/hydration-D3UBU2t8.js.map +0 -1
  327. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/legacy-client-B0ZUlbSQ.js +0 -698
  328. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/legacy-client-B0ZUlbSQ.js.map +0 -1
  329. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/package.json +0 -3
  330. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte.js +0 -135
  331. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte.js.map +0 -1
  332. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_animate.js +0 -57
  333. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_animate.js.map +0 -1
  334. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_attachments.js +0 -2
  335. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_compiler.js +0 -46691
  336. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_compiler.js.map +0 -1
  337. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_easing.js +0 -239
  338. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_easing.js.map +0 -1
  339. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_events.js +0 -2
  340. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal.js +0 -6
  341. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal.js.map +0 -1
  342. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_client.js +0 -7
  343. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_disclose-version.js +0 -6
  344. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_disclose-version.js.map +0 -1
  345. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_async.js +0 -7
  346. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_async.js.map +0 -1
  347. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_legacy.js +0 -7
  348. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_legacy.js.map +0 -1
  349. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_tracing.js +0 -7
  350. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_tracing.js.map +0 -1
  351. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_server.js +0 -6
  352. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_legacy.js +0 -85
  353. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_legacy.js.map +0 -1
  354. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_motion.js +0 -561
  355. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_motion.js.map +0 -1
  356. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity.js +0 -26
  357. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity.js.map +0 -1
  358. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity_window.js +0 -124
  359. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity_window.js.map +0 -1
  360. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_server.js +0 -2
  361. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_store.js +0 -91
  362. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_store.js.map +0 -1
  363. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_transition.js +0 -242
  364. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_transition.js.map +0 -1
  365. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-lObbumRX.js +0 -497
  366. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-lObbumRX.js.map +0 -1
  367. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-mR9mAWyK.js +0 -4929
  368. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-mR9mAWyK.js.map +0 -1
  369. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/validate-CezNmRkM.js +0 -192
  370. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/validate-CezNmRkM.js.map +0 -1
  371. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/version-BHHo0WE-.js +0 -10
  372. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/version-BHHo0WE-.js.map +0 -1
  373. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/warnings-yiExAB06.js +0 -140
  374. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/warnings-yiExAB06.js.map +0 -1
package/src/build-api.ts CHANGED
@@ -1,805 +1,805 @@
1
- // build-api handlers extracted from the controller. Imperative event handlers
2
- // reading/writing controller state via the `ctx` handle; the reactive core
3
- // ($state/$derived/$effect) stays in the controller.
4
- import {
5
- type RowData,
6
- type SvGridApi,
7
- type TableFeatures,
8
- } from "./index";
9
- import "./sv-grid-scrollbar";
10
- import { untrack } from "svelte";
11
- // The export serializers load lazily (their own chunk) so export-format.ts stays
12
- // out of the base bundle - it is fetched only when an export/copy method is
13
- // actually invoked (an explicit, already-async user action).
14
- import type {
15
- GridExportColumn,
16
- GridExportScope,
17
- GridExportOptions,
18
- GridClipboardOptions,
19
- } from "./export-format";
20
- import type {
21
- FilterOperator,
22
- } from "./SvGrid.types";
23
- import {
24
- isGroupRow,
25
- getColumnAlign,
26
- columnDefMatchesId,
27
- } from "./cell-values";
28
-
29
- export function createGridApi<
30
- TFeatures extends TableFeatures = TableFeatures,
31
- TData extends RowData = RowData,
32
- >(ctx: any) {
33
- function buildApi(): SvGridApi<TFeatures, TData> {
34
- const findColumn = (columnId: string) =>
35
- ctx.grid.getAllColumns().find((column: any) => column.id === columnId);
36
-
37
- // --- Free data export (CSV / TSV / JSON + clipboard) helpers ----------
38
- // Snapshot the VISIBLE columns (field + label + format + align) so the
39
- // exporter reproduces on-screen values. Mirrors getColumns()'s visible set.
40
- const exportColumns = (): GridExportColumn[] =>
41
- ctx.allColumns
42
- .map((c: any) => ({
43
- field: (c.columnDef as { field?: string }).field as string,
44
- header:
45
- typeof c.columnDef.header === "string" ? c.columnDef.header : c.id,
46
- format: c.columnDef.format,
47
- align: getColumnAlign(c),
48
- }))
49
- .filter((c: GridExportColumn) => !!c.field);
50
- // Rows for the requested scope: current view / checked / full dataset.
51
- const exportScopeRows = (scope: GridExportScope): TData[] => {
52
- if (scope === "all") return ctx.internalData as TData[];
53
- const out: TData[] = [];
54
- for (const row of ctx.allRows) {
55
- if (isGroupRow(row)) continue;
56
- if (scope === "selected" && !ctx.rowSelectionState[row.id]) continue;
57
- out.push(row.original as TData);
58
- }
59
- return out;
60
- };
61
- const projectForExport = async (
62
- scope: GridExportScope,
63
- columns: ReadonlyArray<string> | undefined,
64
- rawValues: boolean | undefined,
65
- ) => {
66
- const { projectGridRows } = await import("./export-format");
67
- return projectGridRows(
68
- exportScopeRows(scope) as ReadonlyArray<Record<string, unknown>>,
69
- exportColumns(),
70
- { columns, rawValues },
71
- );
72
- };
73
-
74
- return {
75
- getCellValue(rowIndex, columnId) {
76
- const row = ctx.internalData[rowIndex];
77
- const column = findColumn(columnId);
78
- if (!row || !column) return undefined;
79
- if (column.columnDef.fieldFn)
80
- return column.columnDef.fieldFn(row);
81
- if (column.columnDef.field)
82
- return (row as Record<string, unknown>)[column.columnDef.field];
83
- return undefined;
84
- },
85
- setCellValue(rowIndex, columnId, value) {
86
- const row = ctx.internalData[rowIndex];
87
- const column = findColumn(columnId);
88
- if (!row || !column?.columnDef.field) return;
89
- const next = ctx.internalData.slice() as Array<TData>;
90
- next[rowIndex] = { ...row, [column.columnDef.field]: value } as TData;
91
- ctx.internalData = next;
92
- },
93
- startEditing(rowIndex, columnId) {
94
- return ctx.startEditing(rowIndex, columnId);
95
- },
96
- stopEditing(cancel) {
97
- return ctx.stopEditing(cancel ?? false);
98
- },
99
- selectCells(ranges) {
100
- // Multiple rectangles are supported. Empty array clears everything.
101
- if (!ranges || ranges.length === 0) {
102
- ctx.selectionRange = { anchor: null, focus: null };
103
- ctx.selectionRanges = [];
104
- return;
105
- }
106
- const rowCount = ctx.internalData.length;
107
- const colCount = ctx.allColumns.length;
108
- if (rowCount === 0 || colCount === 0) return;
109
- // Clamp to the visible grid bounds so callers can pass open-ended
110
- // values like `[0, 0, Infinity, Infinity]` to mean "select all".
111
- const toRange = ([r1, c1, r2, c2]: readonly [number, number, number, number]) => ({
112
- anchor: {
113
- rowIndex: Math.max(0, Math.min(rowCount - 1, Math.min(r1, r2))),
114
- colIndex: Math.max(0, Math.min(colCount - 1, Math.min(c1, c2))),
115
- },
116
- focus: {
117
- rowIndex: Math.max(0, Math.min(rowCount - 1, Math.max(r1, r2))),
118
- colIndex: Math.max(0, Math.min(colCount - 1, Math.max(c1, c2))),
119
- },
120
- });
121
- const built = ranges.map(toRange);
122
- // Last range is the active one; the rest are committed extras.
123
- ctx.selectionRanges = built.slice(0, -1);
124
- const active = built[built.length - 1]!;
125
- ctx.selectionRange = active;
126
- // Move the active cell to the last range's top-left so keyboard
127
- // navigation continues from there.
128
- ctx.setActiveCell(active.anchor.rowIndex, active.anchor.colIndex);
129
- },
130
- getSelected() {
131
- return ctx
132
- .getSelectionRects()
133
- .map((r: { minRow: number; minCol: number; maxRow: number; maxCol: number }) =>
134
- [r.minRow, r.minCol, r.maxRow, r.maxCol] as [number, number, number, number],
135
- );
136
- },
137
- openChart() {
138
- ctx.chartPanelOpen = true;
139
- },
140
- closeChart() {
141
- ctx.chartPanelOpen = false;
142
- },
143
- getChartSpec() {
144
- return ctx.chartSpec;
145
- },
146
- chartRange(ranges) {
147
- if (ranges && ranges.length) this.selectCells(ranges);
148
- ctx.chartPanelOpen = true;
149
- },
150
- configureChart(config) {
151
- if (ctx.chartingEnabled) ctx.applyChartConfig(config);
152
- },
153
- setChartAiHandler(handler) {
154
- ctx.chartAiHandler = handler ?? null;
155
- },
156
- addRow(row, position = "bottom") {
157
- this.addRows([row], position);
158
- },
159
- addRows(rows, position = "bottom") {
160
- const next = ctx.internalData.slice() as Array<TData>;
161
- if (position === "top") next.unshift(...rows);
162
- else if (position === "bottom") next.push(...rows);
163
- else if (typeof position === "number")
164
- next.splice(Math.max(0, Math.min(position, next.length)), 0, ...rows);
165
- ctx.internalData = next;
166
- },
167
- removeRow(rowIndex) {
168
- this.removeRows([rowIndex]);
169
- },
170
- removeRows(rowIndices) {
171
- const drop = new Set(rowIndices);
172
- ctx.internalData = ctx.internalData.filter((_: any, i: any) => !drop.has(i));
173
- },
174
- applyTransaction(tx) {
175
- const getId = ctx.props.getRowId;
176
- let next = ctx.internalData.slice() as Array<TData>;
177
- let added = 0;
178
- let updated = 0;
179
- let removed = 0;
180
-
181
- if (tx.remove?.length) {
182
- const removeIds = new Set<string>();
183
- const removeRefs = new Set<TData>();
184
- for (const r of tx.remove) {
185
- if (typeof r === "string") removeIds.add(r);
186
- else removeRefs.add(r as TData);
187
- }
188
- next = next.filter((row, i) => {
189
- const hit =
190
- removeRefs.has(row) ||
191
- (getId ? removeIds.has(getId(row, i)) : false);
192
- if (hit) removed += 1;
193
- return !hit;
194
- });
195
- }
196
-
197
- if (tx.update?.length && getId) {
198
- const byId = new Map<string, TData>();
199
- for (const u of tx.update) byId.set(getId(u, 0), u);
200
- next = next.map((row, i) => {
201
- const u = byId.get(getId(row, i));
202
- if (u) {
203
- updated += 1;
204
- return u;
205
- }
206
- return row;
207
- });
208
- }
209
-
210
- if (tx.add?.length) {
211
- next.push(...(tx.add as Array<TData>));
212
- added += tx.add.length;
213
- }
214
-
215
- ctx.internalData = next;
216
- return { added, updated, removed };
217
- },
218
- addColumn(column, position = "right") {
219
- this.addColumns([column], position);
220
- },
221
- addColumns(columns, position = "right") {
222
- const next = ctx.internalColumns.slice();
223
- if (position === "left") next.unshift(...columns);
224
- else if (position === "right") next.push(...columns);
225
- else if (typeof position === "number")
226
- next.splice(
227
- Math.max(0, Math.min(position, next.length)),
228
- 0,
229
- ...columns,
230
- );
231
- ctx.internalColumns = next;
232
- },
233
- removeColumn(columnId) {
234
- ctx.internalColumns = ctx.internalColumns.filter(
235
- (def: any) => !columnDefMatchesId(def, columnId),
236
- );
237
- },
238
- setColumnVisible(columnId, visible) {
239
- if (visible) {
240
- const next = { ...ctx.hiddenColumns };
241
- delete next[columnId];
242
- ctx.hiddenColumns = next;
243
- } else {
244
- ctx.hiddenColumns = { ...ctx.hiddenColumns, [columnId]: true };
245
- }
246
- },
247
- isColumnVisible(columnId) {
248
- return !ctx.hiddenColumns[columnId];
249
- },
250
- setSort(columnId, direction) {
251
- // Honour the column's `sortable` opt-out. Asking the engine
252
- // whether the column can sort folds in both the feature toggle
253
- // AND the per-column flag.
254
- const col = ctx.allColumns.find((c: any) => c.id === columnId);
255
- if (col && !col.getCanSort?.()) return;
256
- const clauses = direction
257
- ? [{ id: columnId, desc: direction === "desc" }]
258
- : (ctx.grid.getState().sorting ?? []).filter(
259
- (entry: { id: string }) => entry.id !== columnId,
260
- );
261
- ctx.grid.store.setState((prev: any) => ({ ...prev, sorting: clauses }));
262
- },
263
- clearSort() {
264
- ctx.grid.store.setState((prev: any) => ({ ...prev, sorting: [] }));
265
- },
266
- setGroupBy(columnIds) {
267
- ctx.grid.setGrouping([...columnIds]);
268
- },
269
- setOption(key, value) {
270
- // Runtime prop override. Writes into the controller's `optionOverrides`
271
- // store, which the effective-props proxy merges over the incoming prop, so
272
- // the grid re-renders exactly as if the parent had changed that prop.
273
- // `undefined` clears the override (falls back to the prop). Reassign the
274
- // whole object for reliable reactivity; `untrack` per the `setFilter` note.
275
- untrack(() => {
276
- const next: Record<string, unknown> = { ...ctx.optionOverrides };
277
- if (value === undefined) delete next[key as string];
278
- else next[key as string] = value;
279
- ctx.optionOverrides = next;
280
- });
281
- },
282
- getOption(key) {
283
- // The effective value: the override if set, otherwise the incoming prop.
284
- return (ctx.props as Record<string, unknown>)[key as string] as never;
285
- },
286
- resetOptions() {
287
- untrack(() => {
288
- ctx.optionOverrides = {};
289
- });
290
- },
291
- setFilter(columnId, filter) {
292
- // `untrack`: these imperative mutators read the same filter state they
293
- // write (read-modify-write on `filterMenuValues`). When a consumer
294
- // calls them from inside a reactive `$effect`, that internal read would
295
- // otherwise be captured as a dependency of the caller's effect, and the
296
- // write would re-dirty it - an infinite update loop. Untracking the
297
- // body keeps the API safe to drive from an effect.
298
- untrack(() => {
299
- // Honour the column's `filterable` opt-out. Same approach as
300
- // `setSort` - `getCanFilter()` already combines the feature flag
301
- // and the per-column field.
302
- const col = ctx.allColumns.find((c: any) => c.id === columnId);
303
- if (col && !col.getCanFilter?.()) return;
304
- if (!filter) {
305
- this.clearFilter(columnId);
306
- return;
307
- }
308
- ctx.filterMenuValues = {
309
- ...ctx.filterMenuValues,
310
- [columnId]: {
311
- operator: filter.operator,
312
- value: filter.value ?? "",
313
- ...(filter.operator === "between"
314
- ? { valueTo: filter.valueTo ?? "" }
315
- : {}),
316
- // Optional second condition + join (multi-condition filtering).
317
- ...(filter.operator2
318
- ? {
319
- operator2: filter.operator2,
320
- value2: filter.value2 ?? "",
321
- join: filter.join ?? "AND",
322
- ...(filter.operator2 === "between"
323
- ? { valueTo2: filter.valueTo2 ?? "" }
324
- : {}),
325
- }
326
- : {}),
327
- },
328
- };
329
- });
330
- },
331
- setFacetFilter(columnId, values) {
332
- // See `setFilter` for why the read-modify-write is untracked.
333
- untrack(() => {
334
- // Empty array OR null both mean "clear this column's facet" -
335
- // mirrors how the column menu treats unchecking the last value.
336
- if (!values || values.length === 0) {
337
- if (ctx.valueFilters[columnId]) {
338
- const next = { ...ctx.valueFilters };
339
- delete next[columnId];
340
- ctx.valueFilters = next;
341
- }
342
- return;
343
- }
344
- ctx.valueFilters = {
345
- ...ctx.valueFilters,
346
- [columnId]: new Set(values),
347
- };
348
- });
349
- },
350
- clearFilter(columnId) {
351
- ctx.clearColumnFilter(columnId);
352
- },
353
- refreshEditorOptions(columnId) {
354
- // Async `editorOptions` are cached per column (or per column+row for a
355
- // per-row source) so opening an editor twice does not refetch. This
356
- // drops those entries, so the next render re-runs the source - use it
357
- // when the underlying list changed server-side.
358
- if (columnId == null) {
359
- ctx.asyncEditorOptions = {};
360
- return;
361
- }
362
- const next = { ...ctx.asyncEditorOptions };
363
- for (const key of Object.keys(next)) {
364
- if (key === columnId || key.startsWith(`${columnId}::`)) delete next[key];
365
- }
366
- ctx.asyncEditorOptions = next;
367
- },
368
- clearAllFilters() {
369
- // See `setFilter` for why the read-modify-write is untracked.
370
- untrack(() => {
371
- // Wipe every filter surface in one go: column-menu, filter-row, set
372
- // filters, and the global search box.
373
- ctx.filterMenuValues = {};
374
- ctx.filterRowValues = {};
375
- ctx.valueFilters = {};
376
- if (ctx.globalFilter !== "") ctx.globalFilter = "";
377
- });
378
- },
379
- getFilters() {
380
- // Return a defensive copy so callers can't mutate internal state.
381
- const out: Record<
382
- string,
383
- { operator: FilterOperator; value: string; valueTo?: string }
384
- > = {};
385
- for (const [columnId, filter] of Object.entries(ctx.filterMenuValues as Record<string, { operator: FilterOperator; value: string; valueTo?: string }>)) {
386
- out[columnId] = {
387
- operator: filter.operator,
388
- value: filter.value,
389
- ...(filter.operator === "between" && filter.valueTo
390
- ? { valueTo: filter.valueTo }
391
- : {}),
392
- };
393
- }
394
- return out;
395
- },
396
- getDisplayedRows() {
397
- // `allRows` is the final, post-filter, post-sort, post-group,
398
- // post-pagination list - exactly what the body renders. Skip group
399
- // header rows (they wrap an aggregate, not a TData row).
400
- const out: TData[] = [];
401
- for (const row of ctx.allRows) {
402
- if (row.subRows && row.subRows.length > 0) continue;
403
- out.push(row.original as TData);
404
- }
405
- return out;
406
- },
407
- getData() {
408
- return ctx.internalData;
409
- },
410
- getColumns() {
411
- // Snapshot every column with its human-readable label and
412
- // visibility flag. Used by external code (exporters, column
413
- // pickers) so they don't have to re-walk the columnDef tree.
414
- // Hidden columns ARE included (with `visible: false`) so a column
415
- // picker can re-enable them - callers that only want what's
416
- // rendered filter by `.visible` (e.g. the exporter does).
417
- const describe = (c: any, visible: boolean) => ({
418
- id: c.id,
419
- field: (c.columnDef as { field?: string }).field,
420
- header:
421
- typeof c.columnDef.header === "string"
422
- ? c.columnDef.header
423
- : c.id,
424
- visible,
425
- // Surface the format + alignment so exporters can reproduce the
426
- // on-screen display value (currency symbol, date pattern, etc.)
427
- // instead of dumping raw values. `getColumnAlign` applies the same
428
- // editorType-based default the body uses.
429
- format: c.columnDef.format,
430
- align: getColumnAlign(c),
431
- });
432
- // Visible columns first, in their current visual order...
433
- const out = ctx.allColumns.map((c: any) => describe(c, true));
434
- // ...then any column hidden via `visible: false` / setColumnVisible.
435
- // Those aren't in `allColumns` (that list is visible-only), so pull
436
- // them straight from the engine's leaf set.
437
- const visibleIds = new Set(out.map((c: { id: string }) => c.id));
438
- for (const c of ctx.grid.getAllColumns() as any[]) {
439
- if (!visibleIds.has(c.id)) out.push(describe(c, false));
440
- }
441
- return out;
442
- },
443
- // ---- Free data export (CSV / TSV / JSON + clipboard) -----------------
444
- async exportCsv(options: GridExportOptions = {}) {
445
- const { serializeDelimited, downloadTextFile } = await import("./export-format");
446
- const { records, fields } = await projectForExport(
447
- options.rows ?? "displayed",
448
- options.columns,
449
- options.rawValues,
450
- );
451
- const text = await serializeDelimited(records, fields, {
452
- csv: { delimiter: ",", bom: options.bom ?? true },
453
- signal: options.signal,
454
- onProgress: options.onProgress,
455
- });
456
- if (options.download !== false)
457
- downloadTextFile(text, `${options.filename ?? "grid"}.csv`, "text/csv;charset=utf-8");
458
- return text;
459
- },
460
- async exportTsv(options: GridExportOptions = {}) {
461
- const { serializeDelimited, downloadTextFile } = await import("./export-format");
462
- const { records, fields } = await projectForExport(
463
- options.rows ?? "displayed",
464
- options.columns,
465
- options.rawValues,
466
- );
467
- const text = await serializeDelimited(records, fields, {
468
- csv: { delimiter: "\t", bom: options.bom ?? true },
469
- signal: options.signal,
470
- onProgress: options.onProgress,
471
- });
472
- if (options.download !== false)
473
- downloadTextFile(text, `${options.filename ?? "grid"}.tsv`, "text/tab-separated-values;charset=utf-8");
474
- return text;
475
- },
476
- async exportJson(options: GridExportOptions = {}) {
477
- const { serializeJson, downloadTextFile } = await import("./export-format");
478
- const { records, fields } = await projectForExport(
479
- options.rows ?? "displayed",
480
- options.columns,
481
- options.rawValues,
482
- );
483
- const text = await serializeJson(records, fields, {
484
- signal: options.signal,
485
- onProgress: options.onProgress,
486
- });
487
- if (options.download !== false)
488
- downloadTextFile(text, `${options.filename ?? "grid"}.json`, "application/json");
489
- return text;
490
- },
491
- async copyToClipboard(options: GridClipboardOptions = {}) {
492
- const { serializeDelimited, serializeMarkdown, copyTextToClipboard } = await import("./export-format");
493
- const { records, fields, align } = await projectForExport(
494
- options.rows ?? "displayed",
495
- options.columns,
496
- options.rawValues,
497
- );
498
- const format = options.format ?? "tsv";
499
- const text =
500
- format === "markdown"
501
- ? await serializeMarkdown(records, fields, { align })
502
- : await serializeDelimited(records, fields, {
503
- csv: { delimiter: format === "csv" ? "," : "\t", bom: false },
504
- });
505
- await copyTextToClipboard(text);
506
- return text;
507
- },
508
- clearRowSelection() {
509
- // Wipe the internal selection map AND emit the change so any
510
- // consumer holding a derived `selectedRows` resets too.
511
- ctx.grid.setRowSelection(() => ({}));
512
- ctx.props.onRowSelectionChange?.({}, []);
513
- },
514
- setColumnWidth(columnId: string, width: number) {
515
- const clamped = Math.max(ctx.MIN_COLUMN_WIDTH, Math.floor(width));
516
- ctx.columnWidths = { ...ctx.columnWidths, [columnId]: clamped };
517
- },
518
- getColumnWidths() {
519
- // Resolve every column's effective width by consulting both the
520
- // resize overrides (`columnWidths`) AND the columnDef defaults,
521
- // so the snapshot is round-trippable through setColumnWidth.
522
- const out: Record<string, number> = {};
523
- for (const c of ctx.allColumns) out[c.id] = ctx.getColumnWidth(c.id);
524
- return out;
525
- },
526
- autosizeColumn(columnId: string) {
527
- ctx.autosizeColumn(columnId);
528
- },
529
- autosizeAllColumns() {
530
- ctx.autosizeAllColumns();
531
- },
532
- setColumnPinning(pinning) {
533
- // Defensive copy + dedupe so callers can't mutate our state.
534
- const left = Array.from(new Set(pinning.left ?? []));
535
- const right = Array.from(new Set(pinning.right ?? []));
536
- ctx.columnPinning = { left, right };
537
- },
538
- getColumnPinning() {
539
- return {
540
- left: ctx.columnPinning.left.slice(),
541
- right: ctx.columnPinning.right.slice(),
542
- };
543
- },
544
- // ---- Column reorder
545
- setColumnOrder(order) {
546
- ctx.setColumnOrderInternal(order);
547
- },
548
- getColumnOrder() {
549
- return ctx.getCurrentColumnOrder();
550
- },
551
- setRowExpanded(id, expanded) {
552
- ctx.grid.setExpanded((prev: any) => ({ ...prev, [id]: !!expanded }));
553
- },
554
- expandAllGroups() {
555
- // Walk the current grouped row model and flip every group node on.
556
- const next: Record<string, boolean> = {};
557
- const walk = (rows: ReadonlyArray<{ id: string; getCanExpand?: () => boolean; subRows?: ReadonlyArray<unknown> }>) => {
558
- for (const row of rows) {
559
- if (row.getCanExpand?.()) next[row.id] = true;
560
- const sub = row.subRows as ReadonlyArray<{ id: string; getCanExpand?: () => boolean; subRows?: ReadonlyArray<unknown> }> | undefined;
561
- if (sub && sub.length > 0) walk(sub);
562
- }
563
- };
564
- walk(ctx.grid.getRowModel().rows as unknown as ReadonlyArray<{ id: string; getCanExpand?: () => boolean; subRows?: ReadonlyArray<unknown> }>);
565
- ctx.grid.setExpanded(() => next);
566
- },
567
- collapseAllGroups() {
568
- ctx.grid.setExpanded(() => ({}));
569
- },
570
- // ---- Undo / redo (history + pointer)
571
- undo() {
572
- if (ctx.historyPtr < 0) return false
573
- const step = ctx.history[ctx.historyPtr]
574
- if (!step) return false
575
- ctx.applyHistoryStep(step, 'undo')
576
- ctx.historyPtr -= 1
577
- ctx.historyVersion += 1
578
- return true
579
- },
580
- redo() {
581
- if (ctx.historyPtr >= ctx.history.length - 1) return false
582
- const step = ctx.history[ctx.historyPtr + 1]
583
- if (!step) return false
584
- ctx.applyHistoryStep(step, 'redo')
585
- ctx.historyPtr += 1
586
- ctx.historyVersion += 1
587
- return true
588
- },
589
- canUndo() { void ctx.historyVersion; return ctx.historyPtr >= 0 },
590
- canRedo() { void ctx.historyVersion; return ctx.historyPtr < ctx.history.length - 1 },
591
- clearHistory() { ctx.history = []; ctx.historyPtr = -1; ctx.historyVersion += 1 },
592
- // ---- Find
593
- openFind() { ctx.findOpen = true },
594
- closeFind() { ctx.findOpen = false; ctx.findQuery = '' },
595
- setFindQuery(q: string) { ctx.findQuery = q; ctx.findHitIndex = 0 },
596
- getFindHits() { return ctx.findHits.slice() },
597
- // ---- Row selection (read + write)
598
- getSelectedRows() {
599
- const out: TData[] = [];
600
- for (const row of ctx.allRows) {
601
- if (isGroupRow(row)) continue;
602
- if (ctx.rowSelectionState[row.id]) out.push(row.original as TData);
603
- }
604
- return out;
605
- },
606
- getSelectedRowIds() {
607
- const out: string[] = [];
608
- for (const row of ctx.allRows) {
609
- if (!isGroupRow(row) && ctx.rowSelectionState[row.id]) out.push(row.id);
610
- }
611
- return out;
612
- },
613
- selectRows(ids, additive = false) {
614
- const set = new Set(ids);
615
- ctx.grid.setRowSelection((prev: any) => {
616
- const next: Record<string, boolean> = additive ? { ...prev } : {};
617
- for (const id of set) next[id] = true;
618
- return next;
619
- });
620
- },
621
- selectAllRows() {
622
- const next: Record<string, boolean> = {};
623
- for (const row of ctx.allRows) if (!isGroupRow(row)) next[row.id] = true;
624
- ctx.grid.setRowSelection(() => next);
625
- },
626
- toggleRowSelected(id) {
627
- ctx.toggleRowSelectionById(id);
628
- },
629
- // ---- Pagination
630
- getPageInfo() {
631
- const { pageIndex, pageSize } = ctx.paginationState;
632
- const total = ctx.allRowsBeforePagination.length;
633
- const pageCount = Math.max(1, Math.ceil(total / Math.max(1, pageSize)));
634
- return { pageIndex, pageSize, pageCount, total };
635
- },
636
- setPage(pageIndex) {
637
- const total = ctx.allRowsBeforePagination.length;
638
- const pageCount = Math.max(
639
- 1,
640
- Math.ceil(total / Math.max(1, ctx.paginationState.pageSize)),
641
- );
642
- ctx.goToPage(Math.max(0, Math.min(pageIndex, pageCount - 1)));
643
- },
644
- nextPage() {
645
- this.setPage(ctx.paginationState.pageIndex + 1);
646
- },
647
- prevPage() {
648
- this.setPage(ctx.paginationState.pageIndex - 1);
649
- },
650
- firstPage() {
651
- this.setPage(0);
652
- },
653
- lastPage() {
654
- const total = ctx.allRowsBeforePagination.length;
655
- const pageCount = Math.max(
656
- 1,
657
- Math.ceil(total / Math.max(1, ctx.paginationState.pageSize)),
658
- );
659
- this.setPage(pageCount - 1);
660
- },
661
- setPageSize(size) {
662
- // Calls the component-level helper (lexical scope), not this method.
663
- ctx.setPageSize(Math.max(1, Math.floor(size)));
664
- },
665
- // ---- Navigation / scrolling
666
- scrollToRow(rowIndex) {
667
- if (!ctx.scrollContainer) return;
668
- const maxIndex = Math.max(0, ctx.allRows.length - 1);
669
- const clamped = Math.max(0, Math.min(rowIndex, maxIndex));
670
- // Logical offset from the virtualizer (honors uniform OR per-row
671
- // sizing), then mapped into the capped DOM scroll space so it lands
672
- // correctly on huge grids where the DOM height is scaled down.
673
- const logical = ctx.virtualizer.getOffsetForIndex(clamped);
674
- ctx.scrollContainer.scrollTop = ctx.logicalToDomRowOffset(logical);
675
- ctx.scheduleScrollSync(
676
- ctx.scrollContainer.scrollTop,
677
- ctx.scrollContainer.scrollLeft,
678
- );
679
- },
680
- getActiveCell() {
681
- const a = ctx.activeCell;
682
- if (!a || a.rowIndex < 0 || a.colIndex < 0) return null;
683
- const col = ctx.allColumns[a.colIndex];
684
- return {
685
- rowIndex: a.rowIndex,
686
- colIndex: a.colIndex,
687
- columnId: col?.id ?? "",
688
- };
689
- },
690
- setActiveCell(rowIndex, colIndex) {
691
- const r = Math.max(0, Math.min(rowIndex, Math.max(0, ctx.allRows.length - 1)));
692
- const c = Math.max(
693
- 0,
694
- Math.min(colIndex, Math.max(0, ctx.allColumns.length - 1)),
695
- );
696
- // Calls the component-level helper (lexical scope), not this method.
697
- ctx.setActiveCell(r, c);
698
- },
699
- // ---- View state (save / restore)
700
- getState() {
701
- return {
702
- sorting: (ctx.grid.getState().sorting ?? []).map(
703
- (s: { id: string; desc: boolean }) => ({ id: s.id, desc: s.desc }),
704
- ),
705
- grouping: [...(ctx.grid.getState().grouping ?? [])],
706
- pagination: {
707
- pageIndex: ctx.paginationState.pageIndex,
708
- pageSize: ctx.paginationState.pageSize,
709
- },
710
- columnWidths: this.getColumnWidths(),
711
- columnPinning: this.getColumnPinning(),
712
- columnOrder: ctx.getCurrentColumnOrder(),
713
- hiddenColumns: Object.keys(ctx.hiddenColumns).filter(
714
- (k) => ctx.hiddenColumns[k],
715
- ),
716
- globalFilter: ctx.globalFilter,
717
- columnFilters: this.getFilters(),
718
- facetFilters: Object.fromEntries(
719
- Object.entries(ctx.valueFilters).map(([k, set]: [string, any]) => [
720
- k,
721
- Array.from(set),
722
- ]),
723
- ),
724
- ...(ctx.chartingEnabled
725
- ? {
726
- chart: {
727
- open: ctx.chartPanelOpen,
728
- type: ctx.chartType,
729
- dimension: ctx.chartDimensionId,
730
- series: ctx.chartSeriesId,
731
- measure: ctx.chartMeasureId,
732
- reduce: ctx.chartReduce,
733
- stacked: ctx.chartStacked,
734
- },
735
- charts: ctx.getChartsState(),
736
- chartActive: ctx.activeChartIndex,
737
- }
738
- : {}),
739
- };
740
- },
741
- setState(state) {
742
- if (state.sorting) {
743
- const sorting = state.sorting.map((s) => ({ id: s.id, desc: s.desc }));
744
- ctx.grid.store.setState((prev: any) => ({ ...prev, sorting }));
745
- }
746
- if (state.grouping) {
747
- // Drop grouping by columns that no longer exist (#53) - otherwise a
748
- // saved view collapses every row into a group named 'undefined'.
749
- const existing = new Set((ctx.grid.getAllColumns() as any[]).map((c) => c.id));
750
- ctx.grid.setGrouping(state.grouping.filter((id: string) => existing.has(id)));
751
- }
752
- if (state.pagination) {
753
- const p = state.pagination;
754
- ctx.grid.setPagination((prev: any) => ({ ...prev, ...p }));
755
- }
756
- if (state.columnWidths) ctx.columnWidths = { ...state.columnWidths };
757
- if (state.columnPinning)
758
- ctx.columnPinning = {
759
- left: [...(state.columnPinning.left ?? [])],
760
- right: [...(state.columnPinning.right ?? [])],
761
- };
762
- if (state.columnOrder) ctx.setColumnOrderInternal(state.columnOrder);
763
- if (state.hiddenColumns) {
764
- // Seed from columns declared `visible: false` so a partial/empty saved
765
- // state never un-hides an app-declared-hidden column (#54); then layer
766
- // the saved user-driven hides on top.
767
- const next: Record<string, boolean> = { ...ctx.declaredHiddenColumns };
768
- for (const id of state.hiddenColumns) next[id] = true;
769
- ctx.hiddenColumns = next;
770
- }
771
- if (state.globalFilter !== undefined) ctx.globalFilter = state.globalFilter;
772
- if (state.columnFilters)
773
- ctx.filterMenuValues = { ...state.columnFilters };
774
- if (state.facetFilters) {
775
- const next: Record<string, Set<string>> = {};
776
- for (const [k, arr] of Object.entries(state.facetFilters))
777
- next[k] = new Set(arr);
778
- ctx.valueFilters = next;
779
- }
780
- if ((state.chart || state.charts) && ctx.chartingEnabled) {
781
- if (Array.isArray(state.charts) && state.charts.length) {
782
- ctx.applyChartsState(state.charts, state.chartActive);
783
- }
784
- if (state.chart) {
785
- const c = state.chart;
786
- ctx.chartPanelOpen = c.open;
787
- ctx.chartType = c.type;
788
- ctx.chartDimensionId = c.dimension;
789
- ctx.chartSeriesId = c.series;
790
- ctx.chartMeasureId = c.measure;
791
- ctx.chartReduce = c.reduce;
792
- ctx.chartStacked = c.stacked;
793
- }
794
- }
795
- },
796
- refresh() {
797
- ctx.grid.store.setState((prev: any) => ({ ...prev }));
798
- },
799
- };
800
- }
801
-
802
- return {
803
- buildApi,
804
- };
805
- }
1
+ // build-api handlers extracted from the controller. Imperative event handlers
2
+ // reading/writing controller state via the `ctx` handle; the reactive core
3
+ // ($state/$derived/$effect) stays in the controller.
4
+ import {
5
+ type RowData,
6
+ type SvGridApi,
7
+ type TableFeatures,
8
+ } from "./index";
9
+ import "./sv-grid-scrollbar";
10
+ import { untrack } from "svelte";
11
+ // The export serializers load lazily (their own chunk) so export-format.ts stays
12
+ // out of the base bundle - it is fetched only when an export/copy method is
13
+ // actually invoked (an explicit, already-async user action).
14
+ import type {
15
+ GridExportColumn,
16
+ GridExportScope,
17
+ GridExportOptions,
18
+ GridClipboardOptions,
19
+ } from "./export-format";
20
+ import type {
21
+ FilterOperator,
22
+ } from "./SvGrid.types";
23
+ import {
24
+ isGroupRow,
25
+ getColumnAlign,
26
+ columnDefMatchesId,
27
+ } from "./cell-values";
28
+
29
+ export function createGridApi<
30
+ TFeatures extends TableFeatures = TableFeatures,
31
+ TData extends RowData = RowData,
32
+ >(ctx: any) {
33
+ function buildApi(): SvGridApi<TFeatures, TData> {
34
+ const findColumn = (columnId: string) =>
35
+ ctx.grid.getAllColumns().find((column: any) => column.id === columnId);
36
+
37
+ // --- Free data export (CSV / TSV / JSON + clipboard) helpers ----------
38
+ // Snapshot the VISIBLE columns (field + label + format + align) so the
39
+ // exporter reproduces on-screen values. Mirrors getColumns()'s visible set.
40
+ const exportColumns = (): GridExportColumn[] =>
41
+ ctx.allColumns
42
+ .map((c: any) => ({
43
+ field: (c.columnDef as { field?: string }).field as string,
44
+ header:
45
+ typeof c.columnDef.header === "string" ? c.columnDef.header : c.id,
46
+ format: c.columnDef.format,
47
+ align: getColumnAlign(c),
48
+ }))
49
+ .filter((c: GridExportColumn) => !!c.field);
50
+ // Rows for the requested scope: current view / checked / full dataset.
51
+ const exportScopeRows = (scope: GridExportScope): TData[] => {
52
+ if (scope === "all") return ctx.internalData as TData[];
53
+ const out: TData[] = [];
54
+ for (const row of ctx.allRows) {
55
+ if (isGroupRow(row)) continue;
56
+ if (scope === "selected" && !ctx.rowSelectionState[row.id]) continue;
57
+ out.push(row.original as TData);
58
+ }
59
+ return out;
60
+ };
61
+ const projectForExport = async (
62
+ scope: GridExportScope,
63
+ columns: ReadonlyArray<string> | undefined,
64
+ rawValues: boolean | undefined,
65
+ ) => {
66
+ const { projectGridRows } = await import("./export-format");
67
+ return projectGridRows(
68
+ exportScopeRows(scope) as ReadonlyArray<Record<string, unknown>>,
69
+ exportColumns(),
70
+ { columns, rawValues },
71
+ );
72
+ };
73
+
74
+ return {
75
+ getCellValue(rowIndex, columnId) {
76
+ const row = ctx.internalData[rowIndex];
77
+ const column = findColumn(columnId);
78
+ if (!row || !column) return undefined;
79
+ if (column.columnDef.fieldFn)
80
+ return column.columnDef.fieldFn(row);
81
+ if (column.columnDef.field)
82
+ return (row as Record<string, unknown>)[column.columnDef.field];
83
+ return undefined;
84
+ },
85
+ setCellValue(rowIndex, columnId, value) {
86
+ const row = ctx.internalData[rowIndex];
87
+ const column = findColumn(columnId);
88
+ if (!row || !column?.columnDef.field) return;
89
+ const next = ctx.internalData.slice() as Array<TData>;
90
+ next[rowIndex] = { ...row, [column.columnDef.field]: value } as TData;
91
+ ctx.internalData = next;
92
+ },
93
+ startEditing(rowIndex, columnId) {
94
+ return ctx.startEditing(rowIndex, columnId);
95
+ },
96
+ stopEditing(cancel) {
97
+ return ctx.stopEditing(cancel ?? false);
98
+ },
99
+ selectCells(ranges) {
100
+ // Multiple rectangles are supported. Empty array clears everything.
101
+ if (!ranges || ranges.length === 0) {
102
+ ctx.selectionRange = { anchor: null, focus: null };
103
+ ctx.selectionRanges = [];
104
+ return;
105
+ }
106
+ const rowCount = ctx.internalData.length;
107
+ const colCount = ctx.allColumns.length;
108
+ if (rowCount === 0 || colCount === 0) return;
109
+ // Clamp to the visible grid bounds so callers can pass open-ended
110
+ // values like `[0, 0, Infinity, Infinity]` to mean "select all".
111
+ const toRange = ([r1, c1, r2, c2]: readonly [number, number, number, number]) => ({
112
+ anchor: {
113
+ rowIndex: Math.max(0, Math.min(rowCount - 1, Math.min(r1, r2))),
114
+ colIndex: Math.max(0, Math.min(colCount - 1, Math.min(c1, c2))),
115
+ },
116
+ focus: {
117
+ rowIndex: Math.max(0, Math.min(rowCount - 1, Math.max(r1, r2))),
118
+ colIndex: Math.max(0, Math.min(colCount - 1, Math.max(c1, c2))),
119
+ },
120
+ });
121
+ const built = ranges.map(toRange);
122
+ // Last range is the active one; the rest are committed extras.
123
+ ctx.selectionRanges = built.slice(0, -1);
124
+ const active = built[built.length - 1]!;
125
+ ctx.selectionRange = active;
126
+ // Move the active cell to the last range's top-left so keyboard
127
+ // navigation continues from there.
128
+ ctx.setActiveCell(active.anchor.rowIndex, active.anchor.colIndex);
129
+ },
130
+ getSelected() {
131
+ return ctx
132
+ .getSelectionRects()
133
+ .map((r: { minRow: number; minCol: number; maxRow: number; maxCol: number }) =>
134
+ [r.minRow, r.minCol, r.maxRow, r.maxCol] as [number, number, number, number],
135
+ );
136
+ },
137
+ openChart() {
138
+ ctx.chartPanelOpen = true;
139
+ },
140
+ closeChart() {
141
+ ctx.chartPanelOpen = false;
142
+ },
143
+ getChartSpec() {
144
+ return ctx.chartSpec;
145
+ },
146
+ chartRange(ranges) {
147
+ if (ranges && ranges.length) this.selectCells(ranges);
148
+ ctx.chartPanelOpen = true;
149
+ },
150
+ configureChart(config) {
151
+ if (ctx.chartingEnabled) ctx.applyChartConfig(config);
152
+ },
153
+ setChartAiHandler(handler) {
154
+ ctx.chartAiHandler = handler ?? null;
155
+ },
156
+ addRow(row, position = "bottom") {
157
+ this.addRows([row], position);
158
+ },
159
+ addRows(rows, position = "bottom") {
160
+ const next = ctx.internalData.slice() as Array<TData>;
161
+ if (position === "top") next.unshift(...rows);
162
+ else if (position === "bottom") next.push(...rows);
163
+ else if (typeof position === "number")
164
+ next.splice(Math.max(0, Math.min(position, next.length)), 0, ...rows);
165
+ ctx.internalData = next;
166
+ },
167
+ removeRow(rowIndex) {
168
+ this.removeRows([rowIndex]);
169
+ },
170
+ removeRows(rowIndices) {
171
+ const drop = new Set(rowIndices);
172
+ ctx.internalData = ctx.internalData.filter((_: any, i: any) => !drop.has(i));
173
+ },
174
+ applyTransaction(tx) {
175
+ const getId = ctx.props.getRowId;
176
+ let next = ctx.internalData.slice() as Array<TData>;
177
+ let added = 0;
178
+ let updated = 0;
179
+ let removed = 0;
180
+
181
+ if (tx.remove?.length) {
182
+ const removeIds = new Set<string>();
183
+ const removeRefs = new Set<TData>();
184
+ for (const r of tx.remove) {
185
+ if (typeof r === "string") removeIds.add(r);
186
+ else removeRefs.add(r as TData);
187
+ }
188
+ next = next.filter((row, i) => {
189
+ const hit =
190
+ removeRefs.has(row) ||
191
+ (getId ? removeIds.has(getId(row, i)) : false);
192
+ if (hit) removed += 1;
193
+ return !hit;
194
+ });
195
+ }
196
+
197
+ if (tx.update?.length && getId) {
198
+ const byId = new Map<string, TData>();
199
+ for (const u of tx.update) byId.set(getId(u, 0), u);
200
+ next = next.map((row, i) => {
201
+ const u = byId.get(getId(row, i));
202
+ if (u) {
203
+ updated += 1;
204
+ return u;
205
+ }
206
+ return row;
207
+ });
208
+ }
209
+
210
+ if (tx.add?.length) {
211
+ next.push(...(tx.add as Array<TData>));
212
+ added += tx.add.length;
213
+ }
214
+
215
+ ctx.internalData = next;
216
+ return { added, updated, removed };
217
+ },
218
+ addColumn(column, position = "right") {
219
+ this.addColumns([column], position);
220
+ },
221
+ addColumns(columns, position = "right") {
222
+ const next = ctx.internalColumns.slice();
223
+ if (position === "left") next.unshift(...columns);
224
+ else if (position === "right") next.push(...columns);
225
+ else if (typeof position === "number")
226
+ next.splice(
227
+ Math.max(0, Math.min(position, next.length)),
228
+ 0,
229
+ ...columns,
230
+ );
231
+ ctx.internalColumns = next;
232
+ },
233
+ removeColumn(columnId) {
234
+ ctx.internalColumns = ctx.internalColumns.filter(
235
+ (def: any) => !columnDefMatchesId(def, columnId),
236
+ );
237
+ },
238
+ setColumnVisible(columnId, visible) {
239
+ if (visible) {
240
+ const next = { ...ctx.hiddenColumns };
241
+ delete next[columnId];
242
+ ctx.hiddenColumns = next;
243
+ } else {
244
+ ctx.hiddenColumns = { ...ctx.hiddenColumns, [columnId]: true };
245
+ }
246
+ },
247
+ isColumnVisible(columnId) {
248
+ return !ctx.hiddenColumns[columnId];
249
+ },
250
+ setSort(columnId, direction) {
251
+ // Honour the column's `sortable` opt-out. Asking the engine
252
+ // whether the column can sort folds in both the feature toggle
253
+ // AND the per-column flag.
254
+ const col = ctx.allColumns.find((c: any) => c.id === columnId);
255
+ if (col && !col.getCanSort?.()) return;
256
+ const clauses = direction
257
+ ? [{ id: columnId, desc: direction === "desc" }]
258
+ : (ctx.grid.getState().sorting ?? []).filter(
259
+ (entry: { id: string }) => entry.id !== columnId,
260
+ );
261
+ ctx.grid.store.setState((prev: any) => ({ ...prev, sorting: clauses }));
262
+ },
263
+ clearSort() {
264
+ ctx.grid.store.setState((prev: any) => ({ ...prev, sorting: [] }));
265
+ },
266
+ setGroupBy(columnIds) {
267
+ ctx.grid.setGrouping([...columnIds]);
268
+ },
269
+ setOption(key, value) {
270
+ // Runtime prop override. Writes into the controller's `optionOverrides`
271
+ // store, which the effective-props proxy merges over the incoming prop, so
272
+ // the grid re-renders exactly as if the parent had changed that prop.
273
+ // `undefined` clears the override (falls back to the prop). Reassign the
274
+ // whole object for reliable reactivity; `untrack` per the `setFilter` note.
275
+ untrack(() => {
276
+ const next: Record<string, unknown> = { ...ctx.optionOverrides };
277
+ if (value === undefined) delete next[key as string];
278
+ else next[key as string] = value;
279
+ ctx.optionOverrides = next;
280
+ });
281
+ },
282
+ getOption(key) {
283
+ // The effective value: the override if set, otherwise the incoming prop.
284
+ return (ctx.props as Record<string, unknown>)[key as string] as never;
285
+ },
286
+ resetOptions() {
287
+ untrack(() => {
288
+ ctx.optionOverrides = {};
289
+ });
290
+ },
291
+ setFilter(columnId, filter) {
292
+ // `untrack`: these imperative mutators read the same filter state they
293
+ // write (read-modify-write on `filterMenuValues`). When a consumer
294
+ // calls them from inside a reactive `$effect`, that internal read would
295
+ // otherwise be captured as a dependency of the caller's effect, and the
296
+ // write would re-dirty it - an infinite update loop. Untracking the
297
+ // body keeps the API safe to drive from an effect.
298
+ untrack(() => {
299
+ // Honour the column's `filterable` opt-out. Same approach as
300
+ // `setSort` - `getCanFilter()` already combines the feature flag
301
+ // and the per-column field.
302
+ const col = ctx.allColumns.find((c: any) => c.id === columnId);
303
+ if (col && !col.getCanFilter?.()) return;
304
+ if (!filter) {
305
+ this.clearFilter(columnId);
306
+ return;
307
+ }
308
+ ctx.filterMenuValues = {
309
+ ...ctx.filterMenuValues,
310
+ [columnId]: {
311
+ operator: filter.operator,
312
+ value: filter.value ?? "",
313
+ ...(filter.operator === "between"
314
+ ? { valueTo: filter.valueTo ?? "" }
315
+ : {}),
316
+ // Optional second condition + join (multi-condition filtering).
317
+ ...(filter.operator2
318
+ ? {
319
+ operator2: filter.operator2,
320
+ value2: filter.value2 ?? "",
321
+ join: filter.join ?? "AND",
322
+ ...(filter.operator2 === "between"
323
+ ? { valueTo2: filter.valueTo2 ?? "" }
324
+ : {}),
325
+ }
326
+ : {}),
327
+ },
328
+ };
329
+ });
330
+ },
331
+ setFacetFilter(columnId, values) {
332
+ // See `setFilter` for why the read-modify-write is untracked.
333
+ untrack(() => {
334
+ // Empty array OR null both mean "clear this column's facet" -
335
+ // mirrors how the column menu treats unchecking the last value.
336
+ if (!values || values.length === 0) {
337
+ if (ctx.valueFilters[columnId]) {
338
+ const next = { ...ctx.valueFilters };
339
+ delete next[columnId];
340
+ ctx.valueFilters = next;
341
+ }
342
+ return;
343
+ }
344
+ ctx.valueFilters = {
345
+ ...ctx.valueFilters,
346
+ [columnId]: new Set(values),
347
+ };
348
+ });
349
+ },
350
+ clearFilter(columnId) {
351
+ ctx.clearColumnFilter(columnId);
352
+ },
353
+ refreshEditorOptions(columnId) {
354
+ // Async `editorOptions` are cached per column (or per column+row for a
355
+ // per-row source) so opening an editor twice does not refetch. This
356
+ // drops those entries, so the next render re-runs the source - use it
357
+ // when the underlying list changed server-side.
358
+ if (columnId == null) {
359
+ ctx.asyncEditorOptions = {};
360
+ return;
361
+ }
362
+ const next = { ...ctx.asyncEditorOptions };
363
+ for (const key of Object.keys(next)) {
364
+ if (key === columnId || key.startsWith(`${columnId}::`)) delete next[key];
365
+ }
366
+ ctx.asyncEditorOptions = next;
367
+ },
368
+ clearAllFilters() {
369
+ // See `setFilter` for why the read-modify-write is untracked.
370
+ untrack(() => {
371
+ // Wipe every filter surface in one go: column-menu, filter-row, set
372
+ // filters, and the global search box.
373
+ ctx.filterMenuValues = {};
374
+ ctx.filterRowValues = {};
375
+ ctx.valueFilters = {};
376
+ if (ctx.globalFilter !== "") ctx.globalFilter = "";
377
+ });
378
+ },
379
+ getFilters() {
380
+ // Return a defensive copy so callers can't mutate internal state.
381
+ const out: Record<
382
+ string,
383
+ { operator: FilterOperator; value: string; valueTo?: string }
384
+ > = {};
385
+ for (const [columnId, filter] of Object.entries(ctx.filterMenuValues as Record<string, { operator: FilterOperator; value: string; valueTo?: string }>)) {
386
+ out[columnId] = {
387
+ operator: filter.operator,
388
+ value: filter.value,
389
+ ...(filter.operator === "between" && filter.valueTo
390
+ ? { valueTo: filter.valueTo }
391
+ : {}),
392
+ };
393
+ }
394
+ return out;
395
+ },
396
+ getDisplayedRows() {
397
+ // `allRows` is the final, post-filter, post-sort, post-group,
398
+ // post-pagination list - exactly what the body renders. Skip group
399
+ // header rows (they wrap an aggregate, not a TData row).
400
+ const out: TData[] = [];
401
+ for (const row of ctx.allRows) {
402
+ if (row.subRows && row.subRows.length > 0) continue;
403
+ out.push(row.original as TData);
404
+ }
405
+ return out;
406
+ },
407
+ getData() {
408
+ return ctx.internalData;
409
+ },
410
+ getColumns() {
411
+ // Snapshot every column with its human-readable label and
412
+ // visibility flag. Used by external code (exporters, column
413
+ // pickers) so they don't have to re-walk the columnDef tree.
414
+ // Hidden columns ARE included (with `visible: false`) so a column
415
+ // picker can re-enable them - callers that only want what's
416
+ // rendered filter by `.visible` (e.g. the exporter does).
417
+ const describe = (c: any, visible: boolean) => ({
418
+ id: c.id,
419
+ field: (c.columnDef as { field?: string }).field,
420
+ header:
421
+ typeof c.columnDef.header === "string"
422
+ ? c.columnDef.header
423
+ : c.id,
424
+ visible,
425
+ // Surface the format + alignment so exporters can reproduce the
426
+ // on-screen display value (currency symbol, date pattern, etc.)
427
+ // instead of dumping raw values. `getColumnAlign` applies the same
428
+ // editorType-based default the body uses.
429
+ format: c.columnDef.format,
430
+ align: getColumnAlign(c),
431
+ });
432
+ // Visible columns first, in their current visual order...
433
+ const out = ctx.allColumns.map((c: any) => describe(c, true));
434
+ // ...then any column hidden via `visible: false` / setColumnVisible.
435
+ // Those aren't in `allColumns` (that list is visible-only), so pull
436
+ // them straight from the engine's leaf set.
437
+ const visibleIds = new Set(out.map((c: { id: string }) => c.id));
438
+ for (const c of ctx.grid.getAllColumns() as any[]) {
439
+ if (!visibleIds.has(c.id)) out.push(describe(c, false));
440
+ }
441
+ return out;
442
+ },
443
+ // ---- Free data export (CSV / TSV / JSON + clipboard) -----------------
444
+ async exportCsv(options: GridExportOptions = {}) {
445
+ const { serializeDelimited, downloadTextFile } = await import("./export-format");
446
+ const { records, fields } = await projectForExport(
447
+ options.rows ?? "displayed",
448
+ options.columns,
449
+ options.rawValues,
450
+ );
451
+ const text = await serializeDelimited(records, fields, {
452
+ csv: { delimiter: ",", bom: options.bom ?? true },
453
+ signal: options.signal,
454
+ onProgress: options.onProgress,
455
+ });
456
+ if (options.download !== false)
457
+ downloadTextFile(text, `${options.filename ?? "grid"}.csv`, "text/csv;charset=utf-8");
458
+ return text;
459
+ },
460
+ async exportTsv(options: GridExportOptions = {}) {
461
+ const { serializeDelimited, downloadTextFile } = await import("./export-format");
462
+ const { records, fields } = await projectForExport(
463
+ options.rows ?? "displayed",
464
+ options.columns,
465
+ options.rawValues,
466
+ );
467
+ const text = await serializeDelimited(records, fields, {
468
+ csv: { delimiter: "\t", bom: options.bom ?? true },
469
+ signal: options.signal,
470
+ onProgress: options.onProgress,
471
+ });
472
+ if (options.download !== false)
473
+ downloadTextFile(text, `${options.filename ?? "grid"}.tsv`, "text/tab-separated-values;charset=utf-8");
474
+ return text;
475
+ },
476
+ async exportJson(options: GridExportOptions = {}) {
477
+ const { serializeJson, downloadTextFile } = await import("./export-format");
478
+ const { records, fields } = await projectForExport(
479
+ options.rows ?? "displayed",
480
+ options.columns,
481
+ options.rawValues,
482
+ );
483
+ const text = await serializeJson(records, fields, {
484
+ signal: options.signal,
485
+ onProgress: options.onProgress,
486
+ });
487
+ if (options.download !== false)
488
+ downloadTextFile(text, `${options.filename ?? "grid"}.json`, "application/json");
489
+ return text;
490
+ },
491
+ async copyToClipboard(options: GridClipboardOptions = {}) {
492
+ const { serializeDelimited, serializeMarkdown, copyTextToClipboard } = await import("./export-format");
493
+ const { records, fields, align } = await projectForExport(
494
+ options.rows ?? "displayed",
495
+ options.columns,
496
+ options.rawValues,
497
+ );
498
+ const format = options.format ?? "tsv";
499
+ const text =
500
+ format === "markdown"
501
+ ? await serializeMarkdown(records, fields, { align })
502
+ : await serializeDelimited(records, fields, {
503
+ csv: { delimiter: format === "csv" ? "," : "\t", bom: false },
504
+ });
505
+ await copyTextToClipboard(text);
506
+ return text;
507
+ },
508
+ clearRowSelection() {
509
+ // Wipe the internal selection map AND emit the change so any
510
+ // consumer holding a derived `selectedRows` resets too.
511
+ ctx.grid.setRowSelection(() => ({}));
512
+ ctx.props.onRowSelectionChange?.({}, []);
513
+ },
514
+ setColumnWidth(columnId: string, width: number) {
515
+ const clamped = Math.max(ctx.MIN_COLUMN_WIDTH, Math.floor(width));
516
+ ctx.columnWidths = { ...ctx.columnWidths, [columnId]: clamped };
517
+ },
518
+ getColumnWidths() {
519
+ // Resolve every column's effective width by consulting both the
520
+ // resize overrides (`columnWidths`) AND the columnDef defaults,
521
+ // so the snapshot is round-trippable through setColumnWidth.
522
+ const out: Record<string, number> = {};
523
+ for (const c of ctx.allColumns) out[c.id] = ctx.getColumnWidth(c.id);
524
+ return out;
525
+ },
526
+ autosizeColumn(columnId: string) {
527
+ ctx.autosizeColumn(columnId);
528
+ },
529
+ autosizeAllColumns() {
530
+ ctx.autosizeAllColumns();
531
+ },
532
+ setColumnPinning(pinning) {
533
+ // Defensive copy + dedupe so callers can't mutate our state.
534
+ const left = Array.from(new Set(pinning.left ?? []));
535
+ const right = Array.from(new Set(pinning.right ?? []));
536
+ ctx.columnPinning = { left, right };
537
+ },
538
+ getColumnPinning() {
539
+ return {
540
+ left: ctx.columnPinning.left.slice(),
541
+ right: ctx.columnPinning.right.slice(),
542
+ };
543
+ },
544
+ // ---- Column reorder
545
+ setColumnOrder(order) {
546
+ ctx.setColumnOrderInternal(order);
547
+ },
548
+ getColumnOrder() {
549
+ return ctx.getCurrentColumnOrder();
550
+ },
551
+ setRowExpanded(id, expanded) {
552
+ ctx.grid.setExpanded((prev: any) => ({ ...prev, [id]: !!expanded }));
553
+ },
554
+ expandAllGroups() {
555
+ // Walk the current grouped row model and flip every group node on.
556
+ const next: Record<string, boolean> = {};
557
+ const walk = (rows: ReadonlyArray<{ id: string; getCanExpand?: () => boolean; subRows?: ReadonlyArray<unknown> }>) => {
558
+ for (const row of rows) {
559
+ if (row.getCanExpand?.()) next[row.id] = true;
560
+ const sub = row.subRows as ReadonlyArray<{ id: string; getCanExpand?: () => boolean; subRows?: ReadonlyArray<unknown> }> | undefined;
561
+ if (sub && sub.length > 0) walk(sub);
562
+ }
563
+ };
564
+ walk(ctx.grid.getRowModel().rows as unknown as ReadonlyArray<{ id: string; getCanExpand?: () => boolean; subRows?: ReadonlyArray<unknown> }>);
565
+ ctx.grid.setExpanded(() => next);
566
+ },
567
+ collapseAllGroups() {
568
+ ctx.grid.setExpanded(() => ({}));
569
+ },
570
+ // ---- Undo / redo (history + pointer)
571
+ undo() {
572
+ if (ctx.historyPtr < 0) return false
573
+ const step = ctx.history[ctx.historyPtr]
574
+ if (!step) return false
575
+ ctx.applyHistoryStep(step, 'undo')
576
+ ctx.historyPtr -= 1
577
+ ctx.historyVersion += 1
578
+ return true
579
+ },
580
+ redo() {
581
+ if (ctx.historyPtr >= ctx.history.length - 1) return false
582
+ const step = ctx.history[ctx.historyPtr + 1]
583
+ if (!step) return false
584
+ ctx.applyHistoryStep(step, 'redo')
585
+ ctx.historyPtr += 1
586
+ ctx.historyVersion += 1
587
+ return true
588
+ },
589
+ canUndo() { void ctx.historyVersion; return ctx.historyPtr >= 0 },
590
+ canRedo() { void ctx.historyVersion; return ctx.historyPtr < ctx.history.length - 1 },
591
+ clearHistory() { ctx.history = []; ctx.historyPtr = -1; ctx.historyVersion += 1 },
592
+ // ---- Find
593
+ openFind() { ctx.findOpen = true },
594
+ closeFind() { ctx.findOpen = false; ctx.findQuery = '' },
595
+ setFindQuery(q: string) { ctx.findQuery = q; ctx.findHitIndex = 0 },
596
+ getFindHits() { return ctx.findHits.slice() },
597
+ // ---- Row selection (read + write)
598
+ getSelectedRows() {
599
+ const out: TData[] = [];
600
+ for (const row of ctx.allRows) {
601
+ if (isGroupRow(row)) continue;
602
+ if (ctx.rowSelectionState[row.id]) out.push(row.original as TData);
603
+ }
604
+ return out;
605
+ },
606
+ getSelectedRowIds() {
607
+ const out: string[] = [];
608
+ for (const row of ctx.allRows) {
609
+ if (!isGroupRow(row) && ctx.rowSelectionState[row.id]) out.push(row.id);
610
+ }
611
+ return out;
612
+ },
613
+ selectRows(ids, additive = false) {
614
+ const set = new Set(ids);
615
+ ctx.grid.setRowSelection((prev: any) => {
616
+ const next: Record<string, boolean> = additive ? { ...prev } : {};
617
+ for (const id of set) next[id] = true;
618
+ return next;
619
+ });
620
+ },
621
+ selectAllRows() {
622
+ const next: Record<string, boolean> = {};
623
+ for (const row of ctx.allRows) if (!isGroupRow(row)) next[row.id] = true;
624
+ ctx.grid.setRowSelection(() => next);
625
+ },
626
+ toggleRowSelected(id) {
627
+ ctx.toggleRowSelectionById(id);
628
+ },
629
+ // ---- Pagination
630
+ getPageInfo() {
631
+ const { pageIndex, pageSize } = ctx.paginationState;
632
+ const total = ctx.allRowsBeforePagination.length;
633
+ const pageCount = Math.max(1, Math.ceil(total / Math.max(1, pageSize)));
634
+ return { pageIndex, pageSize, pageCount, total };
635
+ },
636
+ setPage(pageIndex) {
637
+ const total = ctx.allRowsBeforePagination.length;
638
+ const pageCount = Math.max(
639
+ 1,
640
+ Math.ceil(total / Math.max(1, ctx.paginationState.pageSize)),
641
+ );
642
+ ctx.goToPage(Math.max(0, Math.min(pageIndex, pageCount - 1)));
643
+ },
644
+ nextPage() {
645
+ this.setPage(ctx.paginationState.pageIndex + 1);
646
+ },
647
+ prevPage() {
648
+ this.setPage(ctx.paginationState.pageIndex - 1);
649
+ },
650
+ firstPage() {
651
+ this.setPage(0);
652
+ },
653
+ lastPage() {
654
+ const total = ctx.allRowsBeforePagination.length;
655
+ const pageCount = Math.max(
656
+ 1,
657
+ Math.ceil(total / Math.max(1, ctx.paginationState.pageSize)),
658
+ );
659
+ this.setPage(pageCount - 1);
660
+ },
661
+ setPageSize(size) {
662
+ // Calls the component-level helper (lexical scope), not this method.
663
+ ctx.setPageSize(Math.max(1, Math.floor(size)));
664
+ },
665
+ // ---- Navigation / scrolling
666
+ scrollToRow(rowIndex) {
667
+ if (!ctx.scrollContainer) return;
668
+ const maxIndex = Math.max(0, ctx.allRows.length - 1);
669
+ const clamped = Math.max(0, Math.min(rowIndex, maxIndex));
670
+ // Logical offset from the virtualizer (honors uniform OR per-row
671
+ // sizing), then mapped into the capped DOM scroll space so it lands
672
+ // correctly on huge grids where the DOM height is scaled down.
673
+ const logical = ctx.virtualizer.getOffsetForIndex(clamped);
674
+ ctx.scrollContainer.scrollTop = ctx.logicalToDomRowOffset(logical);
675
+ ctx.scheduleScrollSync(
676
+ ctx.scrollContainer.scrollTop,
677
+ ctx.scrollContainer.scrollLeft,
678
+ );
679
+ },
680
+ getActiveCell() {
681
+ const a = ctx.activeCell;
682
+ if (!a || a.rowIndex < 0 || a.colIndex < 0) return null;
683
+ const col = ctx.allColumns[a.colIndex];
684
+ return {
685
+ rowIndex: a.rowIndex,
686
+ colIndex: a.colIndex,
687
+ columnId: col?.id ?? "",
688
+ };
689
+ },
690
+ setActiveCell(rowIndex, colIndex) {
691
+ const r = Math.max(0, Math.min(rowIndex, Math.max(0, ctx.allRows.length - 1)));
692
+ const c = Math.max(
693
+ 0,
694
+ Math.min(colIndex, Math.max(0, ctx.allColumns.length - 1)),
695
+ );
696
+ // Calls the component-level helper (lexical scope), not this method.
697
+ ctx.setActiveCell(r, c);
698
+ },
699
+ // ---- View state (save / restore)
700
+ getState() {
701
+ return {
702
+ sorting: (ctx.grid.getState().sorting ?? []).map(
703
+ (s: { id: string; desc: boolean }) => ({ id: s.id, desc: s.desc }),
704
+ ),
705
+ grouping: [...(ctx.grid.getState().grouping ?? [])],
706
+ pagination: {
707
+ pageIndex: ctx.paginationState.pageIndex,
708
+ pageSize: ctx.paginationState.pageSize,
709
+ },
710
+ columnWidths: this.getColumnWidths(),
711
+ columnPinning: this.getColumnPinning(),
712
+ columnOrder: ctx.getCurrentColumnOrder(),
713
+ hiddenColumns: Object.keys(ctx.hiddenColumns).filter(
714
+ (k) => ctx.hiddenColumns[k],
715
+ ),
716
+ globalFilter: ctx.globalFilter,
717
+ columnFilters: this.getFilters(),
718
+ facetFilters: Object.fromEntries(
719
+ Object.entries(ctx.valueFilters).map(([k, set]: [string, any]) => [
720
+ k,
721
+ Array.from(set),
722
+ ]),
723
+ ),
724
+ ...(ctx.chartingEnabled
725
+ ? {
726
+ chart: {
727
+ open: ctx.chartPanelOpen,
728
+ type: ctx.chartType,
729
+ dimension: ctx.chartDimensionId,
730
+ series: ctx.chartSeriesId,
731
+ measure: ctx.chartMeasureId,
732
+ reduce: ctx.chartReduce,
733
+ stacked: ctx.chartStacked,
734
+ },
735
+ charts: ctx.getChartsState(),
736
+ chartActive: ctx.activeChartIndex,
737
+ }
738
+ : {}),
739
+ };
740
+ },
741
+ setState(state) {
742
+ if (state.sorting) {
743
+ const sorting = state.sorting.map((s) => ({ id: s.id, desc: s.desc }));
744
+ ctx.grid.store.setState((prev: any) => ({ ...prev, sorting }));
745
+ }
746
+ if (state.grouping) {
747
+ // Drop grouping by columns that no longer exist (#53) - otherwise a
748
+ // saved view collapses every row into a group named 'undefined'.
749
+ const existing = new Set((ctx.grid.getAllColumns() as any[]).map((c) => c.id));
750
+ ctx.grid.setGrouping(state.grouping.filter((id: string) => existing.has(id)));
751
+ }
752
+ if (state.pagination) {
753
+ const p = state.pagination;
754
+ ctx.grid.setPagination((prev: any) => ({ ...prev, ...p }));
755
+ }
756
+ if (state.columnWidths) ctx.columnWidths = { ...state.columnWidths };
757
+ if (state.columnPinning)
758
+ ctx.columnPinning = {
759
+ left: [...(state.columnPinning.left ?? [])],
760
+ right: [...(state.columnPinning.right ?? [])],
761
+ };
762
+ if (state.columnOrder) ctx.setColumnOrderInternal(state.columnOrder);
763
+ if (state.hiddenColumns) {
764
+ // Seed from columns declared `visible: false` so a partial/empty saved
765
+ // state never un-hides an app-declared-hidden column (#54); then layer
766
+ // the saved user-driven hides on top.
767
+ const next: Record<string, boolean> = { ...ctx.declaredHiddenColumns };
768
+ for (const id of state.hiddenColumns) next[id] = true;
769
+ ctx.hiddenColumns = next;
770
+ }
771
+ if (state.globalFilter !== undefined) ctx.globalFilter = state.globalFilter;
772
+ if (state.columnFilters)
773
+ ctx.filterMenuValues = { ...state.columnFilters };
774
+ if (state.facetFilters) {
775
+ const next: Record<string, Set<string>> = {};
776
+ for (const [k, arr] of Object.entries(state.facetFilters))
777
+ next[k] = new Set(arr);
778
+ ctx.valueFilters = next;
779
+ }
780
+ if ((state.chart || state.charts) && ctx.chartingEnabled) {
781
+ if (Array.isArray(state.charts) && state.charts.length) {
782
+ ctx.applyChartsState(state.charts, state.chartActive);
783
+ }
784
+ if (state.chart) {
785
+ const c = state.chart;
786
+ ctx.chartPanelOpen = c.open;
787
+ ctx.chartType = c.type;
788
+ ctx.chartDimensionId = c.dimension;
789
+ ctx.chartSeriesId = c.series;
790
+ ctx.chartMeasureId = c.measure;
791
+ ctx.chartReduce = c.reduce;
792
+ ctx.chartStacked = c.stacked;
793
+ }
794
+ }
795
+ },
796
+ refresh() {
797
+ ctx.grid.store.setState((prev: any) => ({ ...prev }));
798
+ },
799
+ };
800
+ }
801
+
802
+ return {
803
+ buildApi,
804
+ };
805
+ }