@svgrid/grid 2.2.35 → 2.5.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 (380) 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 +160 -160
  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.css +2814 -2814
  21. package/dist/SvGrid.svelte +3490 -3490
  22. package/dist/SvGridChart.svelte +1716 -1716
  23. package/dist/SvGridChartPanel.svelte +485 -485
  24. package/dist/SvGridChartView.svelte +70 -70
  25. package/dist/SvGridDropdown.svelte +728 -728
  26. package/dist/SvGridSelect.svelte +266 -266
  27. package/dist/SvGroupCell.svelte +116 -116
  28. package/dist/SvListBox.svelte +326 -326
  29. package/dist/SvMaskedInput.svelte +122 -122
  30. package/dist/SvMenu.svelte +124 -124
  31. package/dist/SvMenuList.svelte +146 -146
  32. package/dist/SvMultiSelect.svelte +289 -289
  33. package/dist/SvNumberInput.svelte +168 -168
  34. package/dist/SvOtpInput.svelte +158 -158
  35. package/dist/SvPasswordInput.svelte +151 -151
  36. package/dist/SvPhoneInput.svelte +133 -133
  37. package/dist/SvPopover.svelte +197 -197
  38. package/dist/SvProgress.svelte +116 -116
  39. package/dist/SvRadioGroup.svelte +107 -107
  40. package/dist/SvRating.svelte +112 -112
  41. package/dist/SvResult.svelte +73 -73
  42. package/dist/SvRichText.svelte +211 -211
  43. package/dist/SvRowGroupPanel.svelte +170 -170
  44. package/dist/SvScrollArea.svelte +61 -61
  45. package/dist/SvSlider.svelte +200 -200
  46. package/dist/SvSwitchButton.svelte +108 -108
  47. package/dist/SvTagsInput.svelte +112 -112
  48. package/dist/SvTextInput.svelte +147 -147
  49. package/dist/SvTimePicker.svelte +245 -245
  50. package/dist/SvToaster.svelte +159 -159
  51. package/dist/SvToggleButton.svelte +85 -85
  52. package/dist/SvTooltip.svelte +161 -161
  53. package/dist/SvTour.svelte +208 -208
  54. package/dist/SvTree.svelte +444 -444
  55. package/dist/SvTreeSelect.svelte +235 -235
  56. package/dist/cdn/{GridMenus-oQYElQll.js → GridMenus-BpVcKyUr.js} +2 -2
  57. package/dist/cdn/{GridMenus-T-bZNprc.js → GridMenus-CeXL5IW4.js} +2 -2
  58. package/dist/cdn/{SvDateTimePicker-CHnUkWcH.js → SvDateTimePicker-DSUhIta8.js} +2 -2
  59. package/dist/cdn/{SvDateTimePicker-CRQH_U7E.js → SvDateTimePicker-h9kPyszT.js} +2 -2
  60. package/dist/cdn/{SvGridChart-BwVos976.js → SvGridChart-Bs2GIR2Q.js} +1 -1
  61. package/dist/cdn/{SvGridChart-BEJmNNx9.js → SvGridChart-CwhFz7GV.js} +1 -1
  62. package/dist/cdn/{SvGridChartPanel-BOknOkrP.js → SvGridChartPanel-1WXuStzM.js} +1 -1
  63. package/dist/cdn/{SvGridChartPanel-D2PjII4O.js → SvGridChartPanel-e5_nqNP9.js} +1 -1
  64. package/dist/cdn/{SvGridChartView-00LPUHL1.js → SvGridChartView-SmPW10dI.js} +1 -1
  65. package/dist/cdn/{SvGridChartView-BhUEJ5ki.js → SvGridChartView-eSPuJE6g.js} +1 -1
  66. package/dist/cdn/{SvGridDropdown-D0VdjeR8.js → SvGridDropdown-B1ZcLpgs.js} +1 -1
  67. package/dist/cdn/{SvGridDropdown-D13MtJ2j.js → SvGridDropdown-CtdbHcIS.js} +1 -1
  68. package/dist/cdn/{src-Cm7C_WOZ.js → src-DbeN1ReZ.js} +24 -24
  69. package/dist/cdn/{src-72QTH8lh.js → src-DmEQFW5_.js} +23 -23
  70. package/dist/cdn/svgrid.js +5 -5
  71. package/dist/cdn/svgrid.svelte-external.js +5 -5
  72. package/dist/chart-export.js +8 -8
  73. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/_svelte_metadata.json +1 -0
  74. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/_metadata.json +178 -0
  75. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/attachments-qzRy9DX4.js +3843 -0
  76. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/attachments-qzRy9DX4.js.map +1 -0
  77. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/constants-RLNOXCpz.js +23 -0
  78. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/constants-RLNOXCpz.js.map +1 -0
  79. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/dev-DPd12uEU.js +1925 -0
  80. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/dev-DPd12uEU.js.map +1 -0
  81. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/events-CDC4DKuQ.js +206 -0
  82. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/events-CDC4DKuQ.js.map +1 -0
  83. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/flags-BD-lYX7s.js +20 -0
  84. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/flags-BD-lYX7s.js.map +1 -0
  85. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/hydration-D3UBU2t8.js +264 -0
  86. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/hydration-D3UBU2t8.js.map +1 -0
  87. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/legacy-client-B0ZUlbSQ.js +698 -0
  88. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/legacy-client-B0ZUlbSQ.js.map +1 -0
  89. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/package.json +3 -0
  90. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte.js +135 -0
  91. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte.js.map +1 -0
  92. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_animate.js +57 -0
  93. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_animate.js.map +1 -0
  94. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_attachments.js +2 -0
  95. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_compiler.js +46691 -0
  96. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_compiler.js.map +1 -0
  97. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_easing.js +239 -0
  98. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_easing.js.map +1 -0
  99. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_events.js +2 -0
  100. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal.js +6 -0
  101. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal.js.map +1 -0
  102. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_client.js +7 -0
  103. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_disclose-version.js +6 -0
  104. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_disclose-version.js.map +1 -0
  105. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_async.js +7 -0
  106. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_async.js.map +1 -0
  107. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_legacy.js +7 -0
  108. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_legacy.js.map +1 -0
  109. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_tracing.js +7 -0
  110. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_tracing.js.map +1 -0
  111. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_server.js +6 -0
  112. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_legacy.js +85 -0
  113. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_legacy.js.map +1 -0
  114. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_motion.js +561 -0
  115. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_motion.js.map +1 -0
  116. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity.js +26 -0
  117. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity.js.map +1 -0
  118. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity_window.js +124 -0
  119. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity_window.js.map +1 -0
  120. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_server.js +2 -0
  121. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_store.js +91 -0
  122. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_store.js.map +1 -0
  123. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_transition.js +242 -0
  124. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_transition.js.map +1 -0
  125. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-lObbumRX.js +497 -0
  126. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-lObbumRX.js.map +1 -0
  127. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-mR9mAWyK.js +4929 -0
  128. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-mR9mAWyK.js.map +1 -0
  129. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/validate-CezNmRkM.js +192 -0
  130. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/validate-CezNmRkM.js.map +1 -0
  131. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/version-BHHo0WE-.js +10 -0
  132. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/version-BHHo0WE-.js.map +1 -0
  133. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/warnings-yiExAB06.js +140 -0
  134. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/warnings-yiExAB06.js.map +1 -0
  135. package/dist/themes/index.js +28 -9
  136. package/package.json +11 -11
  137. package/src/FlexRender.svelte +96 -96
  138. package/src/GridFooter.svelte +178 -178
  139. package/src/GridMenus.svelte +705 -705
  140. package/src/SvAutoComplete.svelte +165 -165
  141. package/src/SvAvatar.svelte +75 -75
  142. package/src/SvCalendar.svelte +503 -503
  143. package/src/SvCalendar.test.ts +226 -226
  144. package/src/SvCarousel.svelte +141 -141
  145. package/src/SvCheckBox.svelte +102 -102
  146. package/src/SvCircularProgress.svelte +109 -109
  147. package/src/SvColorInput.svelte +181 -181
  148. package/src/SvComboBox.svelte +275 -275
  149. package/src/SvContextMenu.svelte +116 -116
  150. package/src/SvCountryInput.svelte +160 -160
  151. package/src/SvDrawer.svelte +254 -254
  152. package/src/SvDropDownList.svelte +374 -374
  153. package/src/SvDurationInput.svelte +126 -126
  154. package/src/SvField.svelte +293 -293
  155. package/src/SvForm.svelte +437 -437
  156. package/src/SvForm.test.ts +411 -411
  157. package/src/SvGrid.controller.svelte.ts +3680 -3680
  158. package/src/SvGrid.css +2814 -2814
  159. package/src/SvGrid.svelte +3490 -3490
  160. package/src/SvGrid.types.ts +1708 -1708
  161. package/src/SvGridChart.svelte +1716 -1716
  162. package/src/SvGridChartPanel.svelte +485 -485
  163. package/src/SvGridChartView.svelte +70 -70
  164. package/src/SvGridDropdown.svelte +728 -728
  165. package/src/SvGridSelect.svelte +266 -266
  166. package/src/SvGroupCell.svelte +116 -116
  167. package/src/SvListBox.svelte +326 -326
  168. package/src/SvMaskedInput.svelte +122 -122
  169. package/src/SvMenu.svelte +124 -124
  170. package/src/SvMenu.test.ts +97 -97
  171. package/src/SvMenuList.svelte +146 -146
  172. package/src/SvMultiSelect.svelte +289 -289
  173. package/src/SvNumberInput.svelte +168 -168
  174. package/src/SvOtpInput.svelte +158 -158
  175. package/src/SvPasswordInput.svelte +151 -151
  176. package/src/SvPhoneInput.svelte +133 -133
  177. package/src/SvPopover.svelte +197 -197
  178. package/src/SvProgress.svelte +116 -116
  179. package/src/SvRadioGroup.svelte +107 -107
  180. package/src/SvRating.svelte +112 -112
  181. package/src/SvResult.svelte +73 -73
  182. package/src/SvRichText.svelte +211 -211
  183. package/src/SvRowGroupPanel.svelte +170 -170
  184. package/src/SvScrollArea.svelte +61 -61
  185. package/src/SvSlider.svelte +200 -200
  186. package/src/SvSwitchButton.svelte +108 -108
  187. package/src/SvTagsInput.svelte +112 -112
  188. package/src/SvTextInput.svelte +147 -147
  189. package/src/SvTimePicker.svelte +245 -245
  190. package/src/SvToaster.svelte +159 -159
  191. package/src/SvToaster.test.ts +95 -95
  192. package/src/SvToggleButton.svelte +85 -85
  193. package/src/SvTooltip.svelte +161 -161
  194. package/src/SvTour.svelte +208 -208
  195. package/src/SvTree.svelte +444 -444
  196. package/src/SvTreeSelect.svelte +235 -235
  197. package/src/a11y/dismissable.test.ts +119 -119
  198. package/src/a11y/dismissable.ts +114 -114
  199. package/src/a11y.contract.test.ts +49 -49
  200. package/src/a11y.test.ts +59 -59
  201. package/src/a11y.ts +61 -61
  202. package/src/ai.test.ts +502 -502
  203. package/src/ai.ts +1391 -1391
  204. package/src/build-api.coverage.test.ts +633 -633
  205. package/src/build-api.ts +805 -805
  206. package/src/builtin-editors.grid.test.ts +85 -85
  207. package/src/cell-formatting.ts +169 -169
  208. package/src/cell-render.test.ts +513 -513
  209. package/src/cell-render.ts +496 -496
  210. package/src/cell-values.ts +118 -118
  211. package/src/chart-export.ts +201 -201
  212. package/src/chart-view.svelte.ts +36 -36
  213. package/src/chart.ts +2295 -2295
  214. package/src/collaboration.test.ts +104 -104
  215. package/src/collaboration.ts +167 -167
  216. package/src/core.performance.test.ts +30 -30
  217. package/src/core.ts +1261 -1261
  218. package/src/createAutocomplete.svelte.ts +132 -132
  219. package/src/createCombobox.svelte.ts +191 -191
  220. package/src/createCountryInput.svelte.ts +157 -157
  221. package/src/createDropdownList.svelte.ts +168 -168
  222. package/src/createForm.svelte.ts +386 -386
  223. package/src/createGrid.svelte.ts +42 -42
  224. package/src/createGrid.test.ts +10 -10
  225. package/src/createGridState.svelte.ts +17 -17
  226. package/src/createListbox.svelte.ts +250 -250
  227. package/src/createMenu.svelte.ts +224 -224
  228. package/src/createPopoverSelect.svelte.ts +213 -213
  229. package/src/createSlider.svelte.ts +191 -191
  230. package/src/createTooltip.svelte.ts +144 -144
  231. package/src/createTree.svelte.ts +319 -319
  232. package/src/editing.test.ts +949 -949
  233. package/src/editing.ts +606 -606
  234. package/src/editor-contract.ts +164 -164
  235. package/src/editor-registry.grid.test.ts +144 -144
  236. package/src/editor-registry.ts +122 -122
  237. package/src/export-data-api.test.ts +126 -126
  238. package/src/export-format.test.ts +107 -107
  239. package/src/export-format.ts +601 -601
  240. package/src/filter-operators.ts +157 -157
  241. package/src/flex-render.ts +3 -3
  242. package/src/form-field.ts +127 -127
  243. package/src/group-display.test.ts +167 -167
  244. package/src/group-display.ts +200 -200
  245. package/src/index.ts +724 -724
  246. package/src/js-scroller.svelte.ts +173 -173
  247. package/src/keyboard-handlers.ts +270 -270
  248. package/src/keyboard.test.ts +59 -59
  249. package/src/keyboard.ts +97 -97
  250. package/src/list-nav.test.ts +49 -49
  251. package/src/list-nav.ts +29 -29
  252. package/src/list-option.test.ts +56 -56
  253. package/src/list-option.ts +172 -172
  254. package/src/menus.ts +567 -567
  255. package/src/merge-objects.ts +48 -48
  256. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/_svelte_metadata.json +1 -0
  257. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/_metadata.json +178 -0
  258. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/attachments-qzRy9DX4.js +3843 -0
  259. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/attachments-qzRy9DX4.js.map +1 -0
  260. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/constants-RLNOXCpz.js +23 -0
  261. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/constants-RLNOXCpz.js.map +1 -0
  262. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/dev-DPd12uEU.js +1925 -0
  263. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/dev-DPd12uEU.js.map +1 -0
  264. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/events-CDC4DKuQ.js +206 -0
  265. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/events-CDC4DKuQ.js.map +1 -0
  266. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/flags-BD-lYX7s.js +20 -0
  267. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/flags-BD-lYX7s.js.map +1 -0
  268. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/hydration-D3UBU2t8.js +264 -0
  269. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/hydration-D3UBU2t8.js.map +1 -0
  270. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/legacy-client-B0ZUlbSQ.js +698 -0
  271. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/legacy-client-B0ZUlbSQ.js.map +1 -0
  272. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/package.json +3 -0
  273. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte.js +135 -0
  274. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte.js.map +1 -0
  275. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_animate.js +57 -0
  276. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_animate.js.map +1 -0
  277. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_attachments.js +2 -0
  278. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_compiler.js +46691 -0
  279. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_compiler.js.map +1 -0
  280. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_easing.js +239 -0
  281. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_easing.js.map +1 -0
  282. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_events.js +2 -0
  283. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal.js +6 -0
  284. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal.js.map +1 -0
  285. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_client.js +7 -0
  286. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_disclose-version.js +6 -0
  287. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_disclose-version.js.map +1 -0
  288. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_async.js +7 -0
  289. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_async.js.map +1 -0
  290. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_legacy.js +7 -0
  291. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_legacy.js.map +1 -0
  292. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_tracing.js +7 -0
  293. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_tracing.js.map +1 -0
  294. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_server.js +6 -0
  295. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_legacy.js +85 -0
  296. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_legacy.js.map +1 -0
  297. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_motion.js +561 -0
  298. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_motion.js.map +1 -0
  299. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity.js +26 -0
  300. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity.js.map +1 -0
  301. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity_window.js +124 -0
  302. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity_window.js.map +1 -0
  303. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_server.js +2 -0
  304. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_store.js +91 -0
  305. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_store.js.map +1 -0
  306. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_transition.js +242 -0
  307. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_transition.js.map +1 -0
  308. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-lObbumRX.js +497 -0
  309. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-lObbumRX.js.map +1 -0
  310. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-mR9mAWyK.js +4929 -0
  311. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-mR9mAWyK.js.map +1 -0
  312. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/validate-CezNmRkM.js +192 -0
  313. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/validate-CezNmRkM.js.map +1 -0
  314. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/version-BHHo0WE-.js +10 -0
  315. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/version-BHHo0WE-.js.map +1 -0
  316. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/warnings-yiExAB06.js +140 -0
  317. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/warnings-yiExAB06.js.map +1 -0
  318. package/src/overlays.test.ts +90 -90
  319. package/src/render-component.ts +28 -28
  320. package/src/row-resize.ts +210 -210
  321. package/src/scheduler-model.test.ts +562 -562
  322. package/src/scheduler-model.ts +872 -872
  323. package/src/selection.test.ts +754 -754
  324. package/src/selection.ts +491 -491
  325. package/src/server-data-source.test.ts +289 -289
  326. package/src/server-data-source.ts +413 -413
  327. package/src/sparkline.test.ts +68 -68
  328. package/src/sparkline.ts +169 -169
  329. package/src/spreadsheet.test.ts +488 -488
  330. package/src/spreadsheet.ts +312 -312
  331. package/src/static-functions.ts +11 -11
  332. package/src/subscribe.ts +38 -38
  333. package/src/svgrid-wrapper.types.ts +526 -526
  334. package/src/svgrid.async-editor-options.test.ts +271 -271
  335. package/src/svgrid.auto-row-height.test.ts +204 -204
  336. package/src/svgrid.behavior.test.ts +705 -705
  337. package/src/svgrid.charting.test.ts +534 -534
  338. package/src/svgrid.comments-autocomplete.test.ts +123 -123
  339. package/src/svgrid.context-menu.test.ts +147 -147
  340. package/src/svgrid.features.test.ts +157 -157
  341. package/src/svgrid.filter-depth.test.ts +163 -163
  342. package/src/svgrid.filter-menu-listbox.svelte.test.ts +331 -322
  343. package/src/svgrid.filter-menu-scroll.test.ts +112 -112
  344. package/src/svgrid.grand-total.test.ts +188 -188
  345. package/src/svgrid.group-display-mode.test.ts +171 -171
  346. package/src/svgrid.group-footers.test.ts +121 -121
  347. package/src/svgrid.group-pagination.test.ts +153 -153
  348. package/src/svgrid.new-features.wrapper.test.ts +251 -251
  349. package/src/svgrid.tree-data.test.ts +186 -186
  350. package/src/svgrid.wrapper.test.ts +40 -40
  351. package/src/svgriddropdown.async-panel.svelte.test.ts +195 -195
  352. package/src/test-setup.ts +62 -62
  353. package/src/themes/index.ts +278 -257
  354. package/src/toast-store.svelte.ts +246 -246
  355. package/src/toast-store.test.ts +147 -147
  356. package/src/tree-row-model.test.ts +168 -168
  357. package/src/ui-buttons.test.ts +144 -144
  358. package/src/ui-inputs.test.ts +118 -118
  359. package/src/ui-localization.test.ts +113 -113
  360. package/src/ui-range.test.ts +70 -70
  361. package/src/ui-selection.test.ts +155 -155
  362. package/src/ui-tier1.test.ts +142 -142
  363. package/src/virtual.test.ts +88 -88
  364. package/src/virtualization/column-virtualizer.test.ts +27 -27
  365. package/src/virtualization/column-virtualizer.ts +30 -30
  366. package/src/virtualization/svelte-virtualizer.svelte.ts +26 -26
  367. package/src/virtualization/types.ts +30 -30
  368. package/src/virtualization/virtualizer.test.ts +47 -47
  369. package/src/virtualization/virtualizer.ts +296 -296
  370. package/themes/ag-alpine.css +2 -2
  371. package/themes/antd.css +4 -4
  372. package/themes/atlassian.css +1 -1
  373. package/themes/ember.css +2 -2
  374. package/themes/fluent.css +1 -1
  375. package/themes/github.css +1 -1
  376. package/themes/nord.css +2 -2
  377. package/themes/notion.css +2 -2
  378. package/themes/salesforce.css +1 -1
  379. package/themes/tailwind.css +1 -1
  380. package/themes/vercel.css +1 -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
+ }