@svgrid/grid 2.2.32 → 2.4.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 (405) hide show
  1. package/README.md +199 -199
  2. package/dist/DockNodeView.svelte +1 -1
  3. package/dist/FlexRender.svelte +96 -96
  4. package/dist/GridFooter.svelte +178 -179
  5. package/dist/GridMenus.svelte +705 -782
  6. package/dist/SvAutoComplete.svelte +165 -165
  7. package/dist/SvAvatar.svelte +75 -75
  8. package/dist/SvCalendar.svelte +503 -503
  9. package/dist/SvCarousel.svelte +141 -141
  10. package/dist/SvCheckBox.svelte +102 -102
  11. package/dist/SvCircularProgress.svelte +109 -109
  12. package/dist/SvColorInput.svelte +181 -181
  13. package/dist/SvComboBox.svelte +275 -275
  14. package/dist/SvContextMenu.svelte +116 -116
  15. package/dist/SvCountryInput.svelte +160 -160
  16. package/dist/SvDateRangeInput.svelte +1 -1
  17. package/dist/SvDrawer.svelte +254 -254
  18. package/dist/SvDropDownList.svelte +374 -374
  19. package/dist/SvDurationInput.svelte +126 -126
  20. package/dist/SvField.svelte +293 -293
  21. package/dist/SvForm.svelte +437 -437
  22. package/dist/SvGrid.css +2814 -2804
  23. package/dist/SvGrid.svelte +3490 -3513
  24. package/dist/SvGridChart.svelte +1716 -1724
  25. package/dist/SvGridChartPanel.svelte +485 -485
  26. package/dist/SvGridChartView.svelte +70 -70
  27. package/dist/SvGridDropdown.svelte +728 -728
  28. package/dist/SvGridSelect.svelte +266 -268
  29. package/dist/SvGroupCell.svelte +116 -116
  30. package/dist/SvKbd.svelte +1 -1
  31. package/dist/SvList.svelte +1 -1
  32. package/dist/SvListBox.svelte +326 -326
  33. package/dist/SvMaskedInput.svelte +122 -122
  34. package/dist/SvMenu.svelte +124 -124
  35. package/dist/SvMenuList.svelte +146 -146
  36. package/dist/SvMenubar.svelte +1 -1
  37. package/dist/SvMultiSelect.svelte +289 -290
  38. package/dist/SvNumberInput.svelte +168 -168
  39. package/dist/SvOtpInput.svelte +158 -158
  40. package/dist/SvPasswordInput.svelte +151 -151
  41. package/dist/SvPhoneInput.svelte +133 -133
  42. package/dist/SvPopover.svelte +197 -197
  43. package/dist/SvProgress.svelte +116 -116
  44. package/dist/SvRadioGroup.svelte +107 -107
  45. package/dist/SvRating.svelte +112 -112
  46. package/dist/SvResult.svelte +73 -73
  47. package/dist/SvRichText.svelte +211 -207
  48. package/dist/SvRowGroupPanel.svelte +170 -170
  49. package/dist/SvScrollArea.svelte +61 -61
  50. package/dist/SvSlider.svelte +200 -200
  51. package/dist/SvSwitchButton.svelte +108 -108
  52. package/dist/SvTagsInput.svelte +112 -112
  53. package/dist/SvTextInput.svelte +147 -147
  54. package/dist/SvTimePicker.svelte +245 -245
  55. package/dist/SvToaster.svelte +159 -159
  56. package/dist/SvToggleButton.svelte +85 -85
  57. package/dist/SvTooltip.svelte +161 -161
  58. package/dist/SvTour.svelte +208 -204
  59. package/dist/SvTree.svelte +444 -444
  60. package/dist/SvTreeSelect.svelte +235 -237
  61. package/dist/cdn/{GridMenus-C6ixSGWW.js → GridMenus-BpVcKyUr.js} +5 -7
  62. package/dist/cdn/{GridMenus-Cyk3qpJ7.js → GridMenus-CeXL5IW4.js} +153 -152
  63. package/dist/cdn/{SvDateTimePicker-ClqtVIj3.js → SvDateTimePicker-DSUhIta8.js} +165 -165
  64. package/dist/cdn/{SvDateTimePicker-CdqaP61H.js → SvDateTimePicker-h9kPyszT.js} +572 -555
  65. package/dist/cdn/{SvGridChart-BcLCYvw9.js → SvGridChart-Bs2GIR2Q.js} +28 -21
  66. package/dist/cdn/{SvGridChart-BhnFdLd0.js → SvGridChart-CwhFz7GV.js} +2 -2
  67. package/dist/cdn/{SvGridChartPanel-Cmx9DHAS.js → SvGridChartPanel-1WXuStzM.js} +2 -2
  68. package/dist/cdn/{SvGridChartPanel-DvjwxLvK.js → SvGridChartPanel-e5_nqNP9.js} +22 -14
  69. package/dist/cdn/{SvGridChartView-PwqI4s02.js → SvGridChartView-SmPW10dI.js} +3 -3
  70. package/dist/cdn/{SvGridChartView-B40DTJSX.js → SvGridChartView-eSPuJE6g.js} +2 -2
  71. package/dist/cdn/{SvGridDropdown-D0VdjeR8.js → SvGridDropdown-B1ZcLpgs.js} +1 -1
  72. package/dist/cdn/{SvGridDropdown-Dh-2ej8j.js → SvGridDropdown-CtdbHcIS.js} +6 -5
  73. package/dist/cdn/{chart-T1usDN0o.js → chart-i4XcXyHJ.js} +12 -10
  74. package/dist/cdn/disclose-version-Dr7rEVv-.js +2866 -0
  75. package/dist/cdn/{export-format-JT5pWVT8.js → export-format-Cv1Dll6k.js} +66 -245
  76. package/dist/cdn/{src-CgD-wiuS.js → src-DbeN1ReZ.js} +9223 -8944
  77. package/dist/cdn/{src-BgHjWF0Q.js → src-DmEQFW5_.js} +9023 -8828
  78. package/dist/cdn/svgrid.js +9 -9
  79. package/dist/cdn/svgrid.svelte-external.js +9 -9
  80. package/dist/chart-export.js +8 -8
  81. package/dist/chart.d.ts +2 -0
  82. package/dist/chart.js +1 -4
  83. package/dist/columns.js +9 -2
  84. package/dist/createMenu.svelte.js +0 -1
  85. package/dist/createPopoverSelect.svelte.d.ts +2 -2
  86. package/dist/editing.js +1 -1
  87. package/dist/export-format.js +3 -0
  88. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/_svelte_metadata.json +1 -0
  89. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/_metadata.json +178 -0
  90. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/attachments-qzRy9DX4.js +3843 -0
  91. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/attachments-qzRy9DX4.js.map +1 -0
  92. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/constants-RLNOXCpz.js +23 -0
  93. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/constants-RLNOXCpz.js.map +1 -0
  94. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/dev-DPd12uEU.js +1925 -0
  95. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/dev-DPd12uEU.js.map +1 -0
  96. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/events-CDC4DKuQ.js +206 -0
  97. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/events-CDC4DKuQ.js.map +1 -0
  98. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/flags-BD-lYX7s.js +20 -0
  99. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/flags-BD-lYX7s.js.map +1 -0
  100. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/hydration-D3UBU2t8.js +264 -0
  101. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/hydration-D3UBU2t8.js.map +1 -0
  102. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/legacy-client-B0ZUlbSQ.js +698 -0
  103. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/legacy-client-B0ZUlbSQ.js.map +1 -0
  104. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/package.json +3 -0
  105. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte.js +135 -0
  106. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte.js.map +1 -0
  107. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_animate.js +57 -0
  108. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_animate.js.map +1 -0
  109. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_attachments.js +2 -0
  110. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_compiler.js +46691 -0
  111. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_compiler.js.map +1 -0
  112. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_easing.js +239 -0
  113. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_easing.js.map +1 -0
  114. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_events.js +2 -0
  115. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal.js +6 -0
  116. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal.js.map +1 -0
  117. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_client.js +7 -0
  118. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_disclose-version.js +6 -0
  119. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_disclose-version.js.map +1 -0
  120. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_async.js +7 -0
  121. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_async.js.map +1 -0
  122. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_legacy.js +7 -0
  123. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_legacy.js.map +1 -0
  124. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_tracing.js +7 -0
  125. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_tracing.js.map +1 -0
  126. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_server.js +6 -0
  127. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_legacy.js +85 -0
  128. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_legacy.js.map +1 -0
  129. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_motion.js +561 -0
  130. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_motion.js.map +1 -0
  131. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity.js +26 -0
  132. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity.js.map +1 -0
  133. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity_window.js +124 -0
  134. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity_window.js.map +1 -0
  135. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_server.js +2 -0
  136. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_store.js +91 -0
  137. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_store.js.map +1 -0
  138. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_transition.js +242 -0
  139. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_transition.js.map +1 -0
  140. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-lObbumRX.js +497 -0
  141. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-lObbumRX.js.map +1 -0
  142. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-mR9mAWyK.js +4929 -0
  143. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-mR9mAWyK.js.map +1 -0
  144. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/validate-CezNmRkM.js +192 -0
  145. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/validate-CezNmRkM.js.map +1 -0
  146. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/version-BHHo0WE-.js +10 -0
  147. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/version-BHHo0WE-.js.map +1 -0
  148. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/warnings-yiExAB06.js +140 -0
  149. package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/warnings-yiExAB06.js.map +1 -0
  150. package/dist/selection.js +0 -1
  151. package/package.json +11 -10
  152. package/src/DockNodeView.svelte +1 -1
  153. package/src/FlexRender.svelte +96 -96
  154. package/src/GridFooter.svelte +178 -179
  155. package/src/GridMenus.svelte +705 -782
  156. package/src/SvAutoComplete.svelte +165 -165
  157. package/src/SvAvatar.svelte +75 -75
  158. package/src/SvCalendar.svelte +503 -503
  159. package/src/SvCalendar.test.ts +226 -226
  160. package/src/SvCarousel.svelte +141 -141
  161. package/src/SvCheckBox.svelte +102 -102
  162. package/src/SvCircularProgress.svelte +109 -109
  163. package/src/SvColorInput.svelte +181 -181
  164. package/src/SvComboBox.svelte +275 -275
  165. package/src/SvContextMenu.svelte +116 -116
  166. package/src/SvCountryInput.svelte +160 -160
  167. package/src/SvDateRangeInput.svelte +1 -1
  168. package/src/SvDrawer.svelte +254 -254
  169. package/src/SvDropDownList.svelte +374 -374
  170. package/src/SvDurationInput.svelte +126 -126
  171. package/src/SvField.svelte +293 -293
  172. package/src/SvForm.svelte +437 -437
  173. package/src/SvForm.test.ts +411 -411
  174. package/src/SvGrid.controller.svelte.ts +3680 -3685
  175. package/src/SvGrid.css +2814 -2804
  176. package/src/SvGrid.svelte +3490 -3513
  177. package/src/SvGrid.types.ts +1708 -1709
  178. package/src/SvGridChart.svelte +1716 -1724
  179. package/src/SvGridChartPanel.svelte +485 -485
  180. package/src/SvGridChartView.svelte +70 -70
  181. package/src/SvGridDropdown.svelte +728 -728
  182. package/src/SvGridSelect.svelte +266 -268
  183. package/src/SvGroupCell.svelte +116 -116
  184. package/src/SvKbd.svelte +1 -1
  185. package/src/SvList.svelte +1 -1
  186. package/src/SvListBox.svelte +326 -326
  187. package/src/SvMaskedInput.svelte +122 -122
  188. package/src/SvMenu.svelte +124 -124
  189. package/src/SvMenu.test.ts +97 -97
  190. package/src/SvMenuList.svelte +146 -146
  191. package/src/SvMenubar.svelte +1 -1
  192. package/src/SvMultiSelect.svelte +289 -290
  193. package/src/SvNumberInput.svelte +168 -168
  194. package/src/SvOtpInput.svelte +158 -158
  195. package/src/SvPasswordInput.svelte +151 -151
  196. package/src/SvPhoneInput.svelte +133 -133
  197. package/src/SvPopover.svelte +197 -197
  198. package/src/SvProgress.svelte +116 -116
  199. package/src/SvRadioGroup.svelte +107 -107
  200. package/src/SvRating.svelte +112 -112
  201. package/src/SvResult.svelte +73 -73
  202. package/src/SvRichText.svelte +211 -207
  203. package/src/SvRowGroupPanel.svelte +170 -170
  204. package/src/SvScrollArea.svelte +61 -61
  205. package/src/SvSlider.svelte +200 -200
  206. package/src/SvSwitchButton.svelte +108 -108
  207. package/src/SvTagsInput.svelte +112 -112
  208. package/src/SvTextInput.svelte +147 -147
  209. package/src/SvTimePicker.svelte +245 -245
  210. package/src/SvToaster.svelte +159 -159
  211. package/src/SvToaster.test.ts +95 -95
  212. package/src/SvToggleButton.svelte +85 -85
  213. package/src/SvTooltip.svelte +161 -161
  214. package/src/SvTour.svelte +208 -204
  215. package/src/SvTree.svelte +444 -444
  216. package/src/SvTreeSelect.svelte +235 -237
  217. package/src/a11y/dismissable.test.ts +119 -119
  218. package/src/a11y/dismissable.ts +114 -114
  219. package/src/a11y.contract.test.ts +49 -49
  220. package/src/a11y.test.ts +59 -59
  221. package/src/a11y.ts +61 -61
  222. package/src/ai.test.ts +502 -502
  223. package/src/ai.ts +1391 -1391
  224. package/src/build-api.coverage.test.ts +633 -633
  225. package/src/build-api.ts +805 -910
  226. package/src/builtin-editors.grid.test.ts +85 -85
  227. package/src/cell-formatting.test.ts +1 -1
  228. package/src/cell-formatting.ts +169 -169
  229. package/src/cell-render.test.ts +513 -513
  230. package/src/cell-render.ts +496 -590
  231. package/src/cell-values.ts +118 -118
  232. package/src/chart-export.ts +201 -201
  233. package/src/chart-view.svelte.ts +36 -36
  234. package/src/chart.ts +2295 -2296
  235. package/src/clipboard.ts +0 -102
  236. package/src/collaboration.test.ts +104 -104
  237. package/src/collaboration.ts +167 -167
  238. package/src/columns.ts +7 -117
  239. package/src/core.performance.test.ts +30 -30
  240. package/src/core.ts +1261 -1261
  241. package/src/createAutocomplete.svelte.ts +132 -132
  242. package/src/createCombobox.svelte.ts +191 -191
  243. package/src/createCountryInput.svelte.ts +157 -157
  244. package/src/createDropdownList.svelte.ts +168 -168
  245. package/src/createForm.svelte.ts +386 -386
  246. package/src/createGrid.svelte.ts +42 -42
  247. package/src/createGrid.test.ts +10 -10
  248. package/src/createGridState.svelte.ts +17 -17
  249. package/src/createListbox.svelte.ts +250 -250
  250. package/src/createMenu.svelte.ts +224 -225
  251. package/src/createPopoverSelect.svelte.ts +213 -213
  252. package/src/createSlider.svelte.ts +191 -191
  253. package/src/createTooltip.svelte.ts +144 -144
  254. package/src/createTree.svelte.ts +319 -319
  255. package/src/editing.test.ts +949 -949
  256. package/src/editing.ts +606 -709
  257. package/src/editor-contract.ts +164 -164
  258. package/src/editor-registry.grid.test.ts +144 -146
  259. package/src/editor-registry.ts +122 -122
  260. package/src/export-data-api.test.ts +126 -126
  261. package/src/export-format.test.ts +107 -107
  262. package/src/export-format.ts +601 -598
  263. package/src/features.ts +0 -90
  264. package/src/filter-operators.ts +157 -157
  265. package/src/flex-render.ts +3 -3
  266. package/src/form-field.ts +127 -127
  267. package/src/group-display.test.ts +167 -167
  268. package/src/group-display.ts +200 -200
  269. package/src/index.ts +724 -724
  270. package/src/js-scroller.svelte.ts +173 -173
  271. package/src/keyboard-handlers.coverage.test.ts +1 -1
  272. package/src/keyboard-handlers.ts +270 -390
  273. package/src/keyboard.test.ts +59 -59
  274. package/src/keyboard.ts +97 -97
  275. package/src/list-nav.test.ts +49 -49
  276. package/src/list-nav.ts +29 -29
  277. package/src/list-option.test.ts +56 -56
  278. package/src/list-option.ts +172 -172
  279. package/src/menus.test.ts +0 -1
  280. package/src/menus.ts +567 -679
  281. package/src/merge-objects.ts +48 -48
  282. package/src/new-features.test.ts +3 -1
  283. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/_svelte_metadata.json +1 -0
  284. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/_metadata.json +178 -0
  285. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/attachments-qzRy9DX4.js +3843 -0
  286. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/attachments-qzRy9DX4.js.map +1 -0
  287. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/constants-RLNOXCpz.js +23 -0
  288. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/constants-RLNOXCpz.js.map +1 -0
  289. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/dev-DPd12uEU.js +1925 -0
  290. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/dev-DPd12uEU.js.map +1 -0
  291. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/events-CDC4DKuQ.js +206 -0
  292. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/events-CDC4DKuQ.js.map +1 -0
  293. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/flags-BD-lYX7s.js +20 -0
  294. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/flags-BD-lYX7s.js.map +1 -0
  295. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/hydration-D3UBU2t8.js +264 -0
  296. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/hydration-D3UBU2t8.js.map +1 -0
  297. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/legacy-client-B0ZUlbSQ.js +698 -0
  298. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/legacy-client-B0ZUlbSQ.js.map +1 -0
  299. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/package.json +3 -0
  300. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte.js +135 -0
  301. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte.js.map +1 -0
  302. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_animate.js +57 -0
  303. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_animate.js.map +1 -0
  304. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_attachments.js +2 -0
  305. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_compiler.js +46691 -0
  306. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_compiler.js.map +1 -0
  307. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_easing.js +239 -0
  308. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_easing.js.map +1 -0
  309. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_events.js +2 -0
  310. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal.js +6 -0
  311. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal.js.map +1 -0
  312. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_client.js +7 -0
  313. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_disclose-version.js +6 -0
  314. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_disclose-version.js.map +1 -0
  315. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_async.js +7 -0
  316. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_async.js.map +1 -0
  317. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_legacy.js +7 -0
  318. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_legacy.js.map +1 -0
  319. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_tracing.js +7 -0
  320. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_tracing.js.map +1 -0
  321. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_server.js +6 -0
  322. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_legacy.js +85 -0
  323. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_legacy.js.map +1 -0
  324. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_motion.js +561 -0
  325. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_motion.js.map +1 -0
  326. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity.js +26 -0
  327. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity.js.map +1 -0
  328. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity_window.js +124 -0
  329. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity_window.js.map +1 -0
  330. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_server.js +2 -0
  331. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_store.js +91 -0
  332. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_store.js.map +1 -0
  333. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_transition.js +242 -0
  334. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_transition.js.map +1 -0
  335. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-lObbumRX.js +497 -0
  336. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-lObbumRX.js.map +1 -0
  337. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-mR9mAWyK.js +4929 -0
  338. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-mR9mAWyK.js.map +1 -0
  339. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/validate-CezNmRkM.js +192 -0
  340. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/validate-CezNmRkM.js.map +1 -0
  341. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/version-BHHo0WE-.js +10 -0
  342. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/version-BHHo0WE-.js.map +1 -0
  343. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/warnings-yiExAB06.js +140 -0
  344. package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/warnings-yiExAB06.js.map +1 -0
  345. package/src/overlays.test.ts +90 -90
  346. package/src/render-component.ts +28 -28
  347. package/src/row-drag.test.ts +1 -1
  348. package/src/row-resize.test.ts +1 -2
  349. package/src/row-resize.ts +210 -210
  350. package/src/scheduler-model.test.ts +562 -562
  351. package/src/scheduler-model.ts +872 -872
  352. package/src/scroll-sync.test.ts +4 -7
  353. package/src/scroll-sync.ts +0 -122
  354. package/src/selection.test.ts +754 -754
  355. package/src/selection.ts +491 -600
  356. package/src/server-data-source.test.ts +289 -289
  357. package/src/server-data-source.ts +413 -413
  358. package/src/server-group-model.test.ts +2 -2
  359. package/src/sparkline.test.ts +68 -68
  360. package/src/sparkline.ts +169 -169
  361. package/src/spreadsheet.test.ts +488 -488
  362. package/src/spreadsheet.ts +312 -312
  363. package/src/static-functions.ts +11 -11
  364. package/src/subscribe.ts +38 -38
  365. package/src/summaries.ts +0 -112
  366. package/src/svgrid-wrapper.types.ts +526 -526
  367. package/src/svgrid.async-editor-options.test.ts +271 -271
  368. package/src/svgrid.auto-row-height.test.ts +204 -204
  369. package/src/svgrid.behavior.test.ts +705 -706
  370. package/src/svgrid.charting.test.ts +534 -534
  371. package/src/svgrid.column-reorder.test.ts +0 -8
  372. package/src/svgrid.comments-autocomplete.test.ts +123 -123
  373. package/src/svgrid.context-menu.test.ts +147 -147
  374. package/src/svgrid.features.test.ts +157 -157
  375. package/src/svgrid.filter-depth.test.ts +163 -163
  376. package/src/svgrid.filter-menu-listbox.svelte.test.ts +322 -322
  377. package/src/svgrid.filter-menu-scroll.test.ts +112 -112
  378. package/src/svgrid.footer-pagesize.svelte.test.ts +86 -0
  379. package/src/svgrid.grand-total.test.ts +188 -188
  380. package/src/svgrid.group-display-mode.test.ts +171 -171
  381. package/src/svgrid.group-footers.test.ts +121 -121
  382. package/src/svgrid.group-pagination.test.ts +153 -153
  383. package/src/svgrid.new-features.wrapper.test.ts +251 -251
  384. package/src/svgrid.tree-data.test.ts +186 -186
  385. package/src/svgrid.wrapper.test.ts +40 -40
  386. package/src/svgriddropdown.async-panel.svelte.test.ts +195 -195
  387. package/src/test-setup.ts +62 -62
  388. package/src/themes/index.ts +257 -257
  389. package/src/toast-store.svelte.ts +246 -246
  390. package/src/toast-store.test.ts +147 -147
  391. package/src/tree-row-model.test.ts +168 -169
  392. package/src/ui-buttons.test.ts +144 -144
  393. package/src/ui-inputs.test.ts +118 -118
  394. package/src/ui-localization.test.ts +113 -113
  395. package/src/ui-range.test.ts +70 -70
  396. package/src/ui-selection.test.ts +155 -155
  397. package/src/ui-tier1.test.ts +142 -142
  398. package/src/virtual.test.ts +88 -88
  399. package/src/virtualization/column-virtualizer.test.ts +27 -27
  400. package/src/virtualization/column-virtualizer.ts +30 -30
  401. package/src/virtualization/svelte-virtualizer.svelte.ts +26 -26
  402. package/src/virtualization/types.ts +30 -30
  403. package/src/virtualization/virtualizer.test.ts +47 -47
  404. package/src/virtualization/virtualizer.ts +296 -296
  405. package/dist/cdn/disclose-version-DoD9AFD_.js +0 -2958
package/src/editing.ts CHANGED
@@ -1,709 +1,606 @@
1
- // editing 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
- applyExcelFilter,
6
- normalizeForFilter,
7
- createColumnVirtualizer,
8
- createCoreRowModel,
9
- createExpandedRowModel,
10
- createFilteredRowModel,
11
- createGroupedRowModel,
12
- createPaginatedRowModel,
13
- createSvelteVirtualizer,
14
- createSortedRowModel,
15
- createSvGrid,
16
- filterFns,
17
- getGridCellA11yProps,
18
- getGridCellDomId,
19
- getGridHeaderA11yProps,
20
- getGridRootA11yProps,
21
- getGridRowA11yProps,
22
- parseEditorValue,
23
- normalizeEditorOptions,
24
- sortFns,
25
- tableFeatures,
26
- rowSortingFeature,
27
- columnFilteringFeature,
28
- columnGroupingFeature,
29
- type CellContext,
30
- type EditorContext,
31
- type CellEditorOption,
32
- type CellEditorType,
33
- type CellFormatter,
34
- type CellFormatConfig,
35
- type Column,
36
- type ColumnDef,
37
- type Row,
38
- type RowData,
39
- type SvGridApi,
40
- type TableFeatures,
41
- } from "./index";
42
- import "./sv-grid-scrollbar";
43
- import type { Snippet } from "svelte";
44
- import { getKeyboardIntent, getNextActiveCell } from "./keyboard";
45
- import {
46
- formatNumericWithConfig,
47
- getDateFormatter,
48
- resolveDatePattern,
49
- } from "./cell-formatting";
50
- import {
51
- RenderSnippetConfig,
52
- RenderComponentConfig,
53
- } from "./render-component";
54
- import { buildFillPattern } from "./fill-patterns";
55
- import { buildSparkline, toSparklineValues } from "./sparkline";
56
- import {
57
- resolveCellFormat,
58
- computeColumnStat,
59
- formatsNeedingStats,
60
- type ColumnStat,
61
- type ResolvedCellFormat,
62
- } from "./conditional-formatting";
63
- import SvGridDropdown from "./SvGridDropdown.svelte";
64
- import type {
65
- Props,
66
- SelectionPoint,
67
- SelectionRange,
68
- CellEditState,
69
- FilterOperator,
70
- FilterOption,
71
- MenuPosition,
72
- } from "./SvGrid.types";
73
- import {
74
- cfTextStyle,
75
- fmtStat,
76
- getCellKey,
77
- resolveClassList,
78
- toDateInputValue,
79
- toDateTimeLocalInputValue,
80
- getEditableInputValue,
81
- getEditorInputType,
82
- toValueArray,
83
- getOptionLabel,
84
- getOptionColor,
85
- colorfulChipStyle,
86
- getEditorClass,
87
- asDate,
88
- clampMenuX,
89
- cssEscape,
90
- rawToNumber,
91
- formatFacetNumber,
92
- formatFacetDate,
93
- } from "./SvGrid.helpers";
94
- import { createSelection } from "./selection";
95
- import { createColumns } from "./columns";
96
- import { createGridApi } from "./build-api";
97
- import { createClipboard } from "./clipboard";
98
- import {
99
- filterOperatorOptions,
100
- fallbackOperatorOption,
101
- TEXT_OPERATORS,
102
- NUMBER_OPERATORS,
103
- DATE_OPERATORS,
104
- CHECKBOX_OPERATORS,
105
- operatorOption,
106
- operatorsForColumn,
107
- defaultOperatorFor,
108
- operatorLabelFor,
109
- } from "./filter-operators";
110
- import {
111
- type FacetBucket,
112
- isBucketableColumn,
113
- buildBuckets,
114
- isInBucket,
115
- } from "./facet-buckets";
116
- import {
117
- getColumnBaseValue,
118
- isGroupRow,
119
- toolPanelHeaderLabel,
120
- formatSummaryNumeric,
121
- getColumnAlign,
122
- getPinnedCellValue,
123
- getColumnAccessorValue,
124
- columnDefMatchesId,
125
- } from "./cell-values";
126
-
127
- type HistoryStep = {
128
- rowId: string;
129
- columnId: string;
130
- field: string;
131
- before: unknown;
132
- after: unknown;
133
- };
134
-
135
- export function createEditing<
136
- TFeatures extends TableFeatures = TableFeatures,
137
- TData extends RowData = RowData,
138
- >(ctx: any) {
139
- /**
140
- * Resolve `columnDef.editable` for one row × column pair.
141
- *
142
- * - `undefined` / `true` editable
143
- * - `false` not editable (column-level lockdown, fastest path)
144
- * - function call it with the cell's context and honour the
145
- * boolean it returns (cell-level lockdown - used for things like
146
- * "this field is owned by the server, this one isn't, by row")
147
- *
148
- * Called from every editing entry point: double-click, type-to-edit,
149
- * fill-handle drag, Delete-clear, clipboard paste. A central helper
150
- * keeps the cell-level callback signature consistent and saves a
151
- * lookup of CellContext at each site.
152
- */
153
- function isCellEditable(column: Column<TData>, row?: Row<TData>): boolean {
154
- const editable = column.columnDef.editable;
155
- if (editable === false) return false;
156
- if (typeof editable !== "function") return true;
157
- if (!row) return true;
158
- const cellCtx: CellContext<TData> = {
159
- cell: {
160
- id: `${row.id}_${column.id}`,
161
- row,
162
- column,
163
- getValue: () => getColumnBaseValue(row, column),
164
- getContext: () => cellCtx,
165
- },
166
- row,
167
- column,
168
- table: ctx.grid,
169
- getValue: () => getColumnBaseValue(row, column),
170
- };
171
- try {
172
- return editable(cellCtx) !== false;
173
- } catch {
174
- // A throwing predicate shouldn't crash the grid - log and treat
175
- // as not-editable so any error biases toward safety.
176
- return false;
177
- }
178
- }
179
-
180
- /** Variant that takes raw row + column indices for the rare callers
181
- * (fill-handle, paste, Delete) that already work in index-space. */
182
- function isCellEditableAt(rowIndex: number, colIndex: number): boolean {
183
- const row = ctx.allRows[rowIndex];
184
- const column = ctx.allColumns[colIndex];
185
- if (!column) return false;
186
- return isCellEditable(column, row);
187
- }
188
-
189
- function getRowColumnValue(row: Row<TData>, columnId: string) {
190
- const column = ctx.allColumns.find((entry: any) => entry.id === columnId);
191
- return column
192
- ? getColumnBaseValue(row, column)
193
- : row.getCellValueByColumnId(columnId);
194
- }
195
-
196
- function getCellDisplayValue(
197
- rowId: string,
198
- columnId: string,
199
- baseValue: unknown,
200
- ) {
201
- const key = getCellKey(rowId, columnId);
202
- return key in ctx.editedCellValues ? ctx.editedCellValues[key] : baseValue;
203
- }
204
-
205
- /** Start editing seeded with a typed character (Excel-style type-to-edit). */
206
- function startEditingWithChar(
207
- rowIndex: number,
208
- colIndex: number,
209
- char: string,
210
- ): boolean {
211
- if (!ctx.editingEnabled) return false;
212
- const row = ctx.allRows[rowIndex];
213
- const column = ctx.allColumns[colIndex];
214
- if (!row || !column || isGroupRow(row)) return false;
215
- if (!isCellEditable(column, row)) return false;
216
- const editorType = (column.columnDef.editorType ??
217
- "text") as CellEditorType;
218
- if (
219
- editorType === "checkbox" ||
220
- editorType === "date" ||
221
- editorType === "datetime" ||
222
- editorType === "list" ||
223
- editorType === "chips"
224
- ) {
225
- return false;
226
- }
227
- if (editorType === "number" && !/[0-9.+\-]/.test(char)) return false;
228
- ctx.editorSelectAll = false;
229
- ctx.editingCell = {
230
- rowId: row.id,
231
- columnId: column.id,
232
- editorType,
233
- value: char,
234
- rowRef: row.original,
235
- };
236
- ctx.setActiveCell(rowIndex, colIndex);
237
- ctx.setSelection(rowIndex, colIndex);
238
- return true;
239
- }
240
-
241
- function saveEditingCell() {
242
- if (!ctx.editingCell) return;
243
- const editing = ctx.editingCell;
244
- // Resolve the row this edit belongs to. `allRows` is only the current page,
245
- // so fall back to the full filtered model, then to the data object captured
246
- // when the edit started. Without that last hop an edit is silently dropped
247
- // when a filter typed mid-edit hides the row from both models (#49).
248
- const row =
249
- ctx.allRows.find((entry: any) => entry.id === editing.rowId) ??
250
- ctx.allRowsBeforePagination.find((entry: any) => entry.id === editing.rowId);
251
- const rowData = (row?.original ?? editing.rowRef) as
252
- | Record<string, unknown>
253
- | undefined;
254
- const column = ctx.allColumns.find(
255
- (entry: any) => entry.id === ctx.editingCell?.columnId,
256
- );
257
- const parsedValue = parseEditorValue(
258
- ctx.editingCell.editorType,
259
- ctx.editingCell.value,
260
- {
261
- multiple: column?.columnDef.editorMultiple === true,
262
- },
263
- );
264
- let oldValue: unknown = undefined;
265
- let finalValue: unknown = parsedValue;
266
- if (rowData && column?.columnDef.field) {
267
- oldValue = rowData[column.columnDef.field];
268
- // Per-column valueParser refines the type-coerced value before storing.
269
- const parser = (
270
- column.columnDef as { valueParser?: (p: unknown) => unknown }
271
- ).valueParser;
272
- if (parser) {
273
- finalValue = parser({
274
- newValue: parsedValue,
275
- oldValue,
276
- rawInput: ctx.editingCell.value,
277
- data: rowData,
278
- columnId: ctx.editingCell.columnId,
279
- });
280
- }
281
- rowData[column.columnDef.field] = finalValue;
282
- }
283
- const key = getCellKey(ctx.editingCell.rowId, ctx.editingCell.columnId);
284
- ctx.editedCellValues = {
285
- ...ctx.editedCellValues,
286
- [key]: finalValue,
287
- };
288
- ctx.grid.store.setState((prev: any) => ({ ...prev }));
289
- // Record into the history at the current pointer. Any forward
290
- // history (steps the user could have redone) is truncated - this
291
- // is the standard "edit invalidates redo" rule.
292
- if (oldValue !== finalValue && rowData && column?.columnDef.field) {
293
- const step: HistoryStep = {
294
- rowId: ctx.editingCell.rowId,
295
- columnId: ctx.editingCell.columnId,
296
- field: column.columnDef.field as string,
297
- before: oldValue,
298
- after: finalValue,
299
- }
300
- const truncated = ctx.history.slice(0, ctx.historyPtr + 1)
301
- truncated.push(step)
302
- // Cap the buffer at UNDO_LIMIT; drop the OLDEST entries so the
303
- // pointer stays valid relative to the newest steps.
304
- if (truncated.length > ctx.UNDO_LIMIT) {
305
- const drop = truncated.length - ctx.UNDO_LIMIT
306
- ctx.history = truncated.slice(drop)
307
- ctx.historyPtr = ctx.history.length - 1
308
- } else {
309
- ctx.history = truncated
310
- ctx.historyPtr = ctx.history.length - 1
311
- }
312
- ctx.historyVersion += 1
313
- }
314
- // Notify the consumer AFTER the row has been updated so any callback-
315
- // driven recompute (cascade totals, server save, undo stack) sees the
316
- // post-write state. `rowIndex` matches the position in `props.data`.
317
- if (ctx.props.onCellValueChange && rowData && column) {
318
- const rowIndex = ctx.internalData.indexOf(rowData as TData);
319
- ctx.props.onCellValueChange({
320
- rowIndex,
321
- columnId: column.id,
322
- oldValue,
323
- newValue: finalValue,
324
- row: rowData as TData,
325
- });
326
- }
327
- ctx.editingCell = null;
328
- }
329
-
330
- /** Apply an undo / redo step directly to the underlying row, bypassing
331
- * the editor pipeline so we don't accidentally re-push to the stack. */
332
- function applyHistoryStep(step: HistoryStep, direction: 'undo' | 'redo') {
333
- const row = ctx.allRows.find((r: any) => r.id === step.rowId)
334
- const col = ctx.allColumns.find((c: any) => c.id === step.columnId)
335
- if (!row?.original || !col) return
336
- const value = direction === 'undo' ? step.before : step.after
337
- ;(row.original as Record<string, unknown>)[step.field] = value
338
- const key = getCellKey(step.rowId, step.columnId)
339
- ctx.editedCellValues = { ...ctx.editedCellValues, [key]: value }
340
- ctx.grid.store.setState((prev: any) => ({ ...prev }))
341
- if (ctx.props.onCellValueChange) {
342
- const rowIndex = ctx.internalData.indexOf(row.original as TData)
343
- ctx.props.onCellValueChange({
344
- rowIndex,
345
- columnId: step.columnId,
346
- oldValue: direction === 'undo' ? step.after : step.before,
347
- newValue: value,
348
- row: row.original as TData,
349
- })
350
- }
351
- }
352
-
353
- function updateEditingCellValue(value: unknown) {
354
- ctx.editingCell = ctx.editingCell ? { ...ctx.editingCell, value } : ctx.editingCell;
355
- }
356
-
357
- /**
358
- * Commit the open editor and move the active cell one column along, wrapping
359
- * at row boundaries the way Excel does. Editors `stopPropagation()` every key
360
- * so the grid's own Tab handler never sees this one - without the explicit
361
- * move, Tab committed the edit and then let the browser walk focus out of the
362
- * grid entirely (#48). Shared by every editor type, including the textarea.
363
- */
364
- function commitAndMoveByTab(shiftKey: boolean) {
365
- const active = ctx.activeCell;
366
- saveEditingCell();
367
- ctx.gridRootEl?.focus({ preventScroll: true });
368
- if (!active) return;
369
- const next = getNextActiveCell(active, shiftKey ? "tabPrev" : "tabNext", {
370
- maxRow: ctx.allRows.length - 1,
371
- maxCol: ctx.allColumns.length - 1,
372
- });
373
- ctx.setActiveCell(next.rowIndex, next.colIndex);
374
- ctx.setSelection(next.rowIndex, next.colIndex);
375
- ctx.scrollActiveCellIntoView(next.rowIndex, next.colIndex);
376
- }
377
-
378
- function onEditorKeyDown(event: KeyboardEvent) {
379
- event.stopPropagation();
380
- if (event.key === "Enter") {
381
- event.preventDefault();
382
- saveEditingCell();
383
- ctx.gridRootEl?.focus({ preventScroll: true });
384
- } else if (event.key === "Tab") {
385
- event.preventDefault();
386
- commitAndMoveByTab(event.shiftKey);
387
- } else if (event.key === "Escape") {
388
- event.preventDefault();
389
- ctx.editingCell = null;
390
- ctx.gridRootEl?.focus({ preventScroll: true });
391
- }
392
- }
393
-
394
- function focusOnMount(node: HTMLInputElement | HTMLTextAreaElement) {
395
- const selectAll = ctx.editorSelectAll;
396
- requestAnimationFrame(() => {
397
- node.focus({ preventScroll: true });
398
- try {
399
- if (selectAll) {
400
- node.select();
401
- } else {
402
- const end = node.value.length;
403
- node.setSelectionRange(end, end);
404
- }
405
- } catch {
406
- /* date/number inputs may not support text selection */
407
- }
408
- });
409
- }
410
-
411
- function onCellDoubleClick(rowIndex: number, colIndex: number) {
412
- if (!ctx.editingEnabled) return;
413
- const row = ctx.allRows[rowIndex];
414
- const column = ctx.allColumns[colIndex];
415
- if (!row || !column) return;
416
- if (isGroupRow(row)) return;
417
- // Full-row editing: put the whole row into edit instead of one cell.
418
- if (ctx.props.fullRowEditing) {
419
- if (ctx.fullRowEdit?.rowId === row.id) return;
420
- startFullRowEdit(rowIndex);
421
- return;
422
- }
423
- if (!isCellEditable(column, row)) return;
424
- if (ctx.editingCell?.rowId === row.id && ctx.editingCell?.columnId === column.id)
425
- return;
426
- const editorType = (column.columnDef.editorType ??
427
- "text") as CellEditorType;
428
- ctx.editorSelectAll = true;
429
- let initialValue = getCellDisplayValue(
430
- row.id,
431
- column.id,
432
- row.getCellValueByColumnId(column.id),
433
- );
434
- if (editorType === "list" || editorType === "chips") {
435
- if (column.columnDef.editorMultiple) {
436
- // Seed with an array so the editor can mutate slot-by-slot.
437
- initialValue = toValueArray(initialValue);
438
- } else if (Array.isArray(initialValue)) {
439
- initialValue = initialValue[0] ?? "";
440
- }
441
- }
442
- ctx.editingCell = {
443
- rowId: row.id,
444
- columnId: column.id,
445
- editorType,
446
- value: initialValue,
447
- rowRef: row.original,
448
- };
449
- ctx.setActiveCell(rowIndex, colIndex);
450
- ctx.setSelection(rowIndex, colIndex);
451
- }
452
-
453
- async function pasteFromClipboard() {
454
- // Preferred path: the async Clipboard API. Requires a secure context
455
- // (HTTPS or localhost) AND read permission; it also works on Firefox,
456
- // where the native `paste` event does NOT fire on a non-editable element.
457
- // On plain HTTP (a XAMPP/Apache LAN host) `navigator.clipboard` is
458
- // undefined - there the Ctrl+V keydown handler skips preventDefault and
459
- // lets the browser deliver a native `paste` event to `onGridPaste`.
460
- if (!navigator.clipboard?.readText) return;
461
- let text: string;
462
- try {
463
- text = await navigator.clipboard.readText();
464
- } catch {
465
- return;
466
- }
467
- applyPastedText(text);
468
- }
469
-
470
- /**
471
- * Native `paste` ClipboardEvent fallback (insecure-context path). A real
472
- * Ctrl/Cmd+V on the focused grid root fires this with `clipboardData`
473
- * readable even over plain HTTP and with no permission prompt. Wired on the
474
- * grid root in SvGrid.svelte; the keydown handler lets the gesture through
475
- * (no preventDefault) whenever the async API is unavailable.
476
- */
477
- function onGridPaste(event: ClipboardEvent) {
478
- // A cell is being edited: the focused editor input handles its own paste
479
- // natively. Never hijack it for a range paste - doing so (on Firefox /
480
- // insecure contexts, where the async Clipboard API is unavailable) would
481
- // preventDefault the editor's paste and write to the data cell instead,
482
- // so the edit "wouldn't update".
483
- if (ctx.editingCell) return;
484
- // When the async API is available the keydown handler already pasted via
485
- // pasteFromClipboard(); ignore the (suppressed) native event so we don't
486
- // paste twice.
487
- if (typeof navigator.clipboard?.readText === "function") return;
488
- const text = event.clipboardData?.getData("text/plain") ?? "";
489
- if (!text) return;
490
- event.preventDefault();
491
- applyPastedText(text);
492
- }
493
-
494
- function applyPastedText(text: string) {
495
- const anchor = ctx.selectionRange.anchor ?? ctx.grid.getState().activeCell;
496
- if (!anchor) return;
497
- const focus = ctx.selectionRange.focus ?? anchor;
498
- const startRow = Math.min(anchor.rowIndex, focus.rowIndex);
499
- const startCol = Math.min(anchor.colIndex, focus.colIndex);
500
- const endRow = Math.max(anchor.rowIndex, focus.rowIndex);
501
- const endCol = Math.max(anchor.colIndex, focus.colIndex);
502
- const lines = text.replace(/\r\n/g, "\n").split("\n");
503
- if (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
504
- if (!lines.length) return;
505
-
506
- // Excel/Sheets behaviour: when the clipboard holds a single cell and
507
- // the selection is a range, fill the entire range with that value.
508
- // For larger clipboards (multi-row/col TSV), paste at the top-left
509
- // corner and let the clipboard determine the span (the original
510
- // behaviour).
511
- const clipboardIsSingleCell =
512
- lines.length === 1 && (lines[0]?.split("\t").length ?? 0) === 1;
513
- const selectionIsRange = startRow !== endRow || startCol !== endCol;
514
- const fillRange = clipboardIsSingleCell && selectionIsRange;
515
-
516
- const rowSpan = fillRange ? endRow - startRow + 1 : lines.length;
517
- const colSpan = fillRange
518
- ? endCol - startCol + 1
519
- : Math.max(...lines.map((l) => l.split("\t").length));
520
-
521
- const next = ctx.internalData.slice() as Array<TData>;
522
- for (let i = 0; i < rowSpan; i += 1) {
523
- const targetRowIndex = startRow + i;
524
- const row = ctx.allRows[targetRowIndex];
525
- if (!row || isGroupRow(row)) continue;
526
- // Map the visible row back to its index in the data array via row.id (default = String(index)).
527
- const dataIndex = Number(row.id);
528
- if (
529
- !Number.isInteger(dataIndex) ||
530
- dataIndex < 0 ||
531
- dataIndex >= next.length
532
- )
533
- continue;
534
- const originalRow = next[dataIndex];
535
- if (!originalRow) continue;
536
- const sourceCells = fillRange
537
- ? null
538
- : lines[i]?.split("\t") ?? [];
539
- const updated: Record<string, unknown> = {
540
- ...(originalRow as Record<string, unknown>),
541
- };
542
- for (let j = 0; j < colSpan; j += 1) {
543
- const column = ctx.allColumns[startCol + j];
544
- if (!column?.columnDef.field) continue;
545
- if (!isCellEditableAt(targetRowIndex, startCol + j)) continue;
546
- const editorType = (column.columnDef.editorType ??
547
- "text") as CellEditorType;
548
- const raw = fillRange ? lines[0]! : sourceCells?.[j] ?? "";
549
- updated[column.columnDef.field] = parseEditorValue(editorType, raw);
550
- }
551
- next[dataIndex] = updated as TData;
552
- }
553
- ctx.internalData = next;
554
- ctx.grid.store.setState((prev: any) => ({ ...prev }));
555
- }
556
-
557
- /** Programmatically begin editing a cell (mirrors a double-click). */
558
- function startEditing(rowIndex: number, columnId: string): boolean {
559
- if (!ctx.editingEnabled) return false;
560
- const row = ctx.allRows[rowIndex];
561
- if (!row || isGroupRow(row)) return false;
562
- const colIndex = ctx.allColumns.findIndex((c: any) => c.id === columnId);
563
- if (colIndex < 0) return false;
564
- const column = ctx.allColumns[colIndex];
565
- if (!isCellEditable(column, row)) return false;
566
- if (
567
- ctx.editingCell?.rowId === row.id &&
568
- ctx.editingCell?.columnId === columnId
569
- )
570
- return true;
571
- onCellDoubleClick(rowIndex, colIndex);
572
- return (
573
- ctx.editingCell?.rowId === row.id &&
574
- ctx.editingCell?.columnId === columnId
575
- );
576
- }
577
-
578
- /** Commit (default) or cancel the active edit, if any. */
579
- function stopEditing(cancel = false): boolean {
580
- if (!ctx.editingCell) return false;
581
- if (cancel) {
582
- ctx.editingCell = null;
583
- } else {
584
- saveEditingCell();
585
- }
586
- return true;
587
- }
588
-
589
- // ---- Full-row editing -------------------------------------------------
590
- /** Put the whole row into edit mode, seeding a draft per editable column. */
591
- function startFullRowEdit(rowIndex: number): boolean {
592
- if (!ctx.editingEnabled || !ctx.props.fullRowEditing) return false;
593
- const row = ctx.allRows[rowIndex];
594
- if (!row || isGroupRow(row)) return false;
595
- if (ctx.fullRowEdit && ctx.fullRowEdit.rowId !== row.id) commitFullRowEdit();
596
- ctx.editingCell = null; // never both at once
597
- const draft: Record<string, unknown> = {};
598
- for (const column of ctx.allColumns) {
599
- if (!column.columnDef.field) continue;
600
- if (!isCellEditable(column, row)) continue;
601
- draft[column.id] = getCellDisplayValue(
602
- row.id,
603
- column.id,
604
- row.getCellValueByColumnId(column.id),
605
- );
606
- }
607
- ctx.fullRowEdit = { rowId: row.id, draft };
608
- ctx.setActiveCell(rowIndex, Math.max(0, ctx.allColumns.findIndex((c: any) => c.id in draft)));
609
- return true;
610
- }
611
-
612
- /** Stage one column's draft value during full-row editing. */
613
- function setFullRowDraft(columnId: string, value: unknown): void {
614
- const fr = ctx.fullRowEdit;
615
- if (!fr) return;
616
- ctx.fullRowEdit = { rowId: fr.rowId, draft: { ...fr.draft, [columnId]: value } };
617
- }
618
-
619
- /** Commit every drafted column of the full-row edit in one data update. */
620
- function commitFullRowEdit(): void {
621
- const fr = ctx.fullRowEdit;
622
- if (!fr) return;
623
- const row = ctx.allRows.find((r: any) => r.id === fr.rowId);
624
- if (!row?.original) {
625
- ctx.fullRowEdit = null;
626
- return;
627
- }
628
- const changed: Array<{ columnId: string; field: string; before: unknown; after: unknown }> = [];
629
- for (const column of ctx.allColumns) {
630
- if (!(column.id in fr.draft)) continue;
631
- const field = column.columnDef.field as string | undefined;
632
- if (!field) continue;
633
- const editorType = (column.columnDef.editorType ?? "text") as CellEditorType;
634
- const parsed = parseEditorValue(editorType, fr.draft[column.id], {
635
- multiple: column.columnDef.editorMultiple === true,
636
- });
637
- const oldValue = (row.original as Record<string, unknown>)[field];
638
- const parser = (column.columnDef as { valueParser?: (p: unknown) => unknown }).valueParser;
639
- const finalValue = parser
640
- ? parser({
641
- newValue: parsed,
642
- oldValue,
643
- rawInput: String(fr.draft[column.id] ?? ""),
644
- data: row.original,
645
- columnId: column.id,
646
- })
647
- : parsed;
648
- if (oldValue !== finalValue) {
649
- (row.original as Record<string, unknown>)[field] = finalValue;
650
- const key = getCellKey(fr.rowId, column.id);
651
- ctx.editedCellValues = { ...ctx.editedCellValues, [key]: finalValue };
652
- changed.push({ columnId: column.id, field, before: oldValue, after: finalValue });
653
- }
654
- }
655
- // Record the whole-row change as consecutive history steps.
656
- if (changed.length) {
657
- let hist = ctx.history.slice(0, ctx.historyPtr + 1);
658
- for (const c of changed) {
659
- hist.push({ rowId: fr.rowId, columnId: c.columnId, field: c.field, before: c.before, after: c.after });
660
- }
661
- if (hist.length > ctx.UNDO_LIMIT) hist = hist.slice(hist.length - ctx.UNDO_LIMIT);
662
- ctx.history = hist;
663
- ctx.historyPtr = ctx.history.length - 1;
664
- ctx.historyVersion += 1;
665
- }
666
- ctx.grid.store.setState((prev: any) => ({ ...prev }));
667
- if (ctx.props.onCellValueChange && changed.length) {
668
- const rowIndex = ctx.internalData.indexOf(row.original as TData);
669
- for (const c of changed) {
670
- ctx.props.onCellValueChange({
671
- rowIndex,
672
- columnId: c.columnId,
673
- oldValue: c.before,
674
- newValue: c.after,
675
- row: row.original as TData,
676
- });
677
- }
678
- }
679
- ctx.fullRowEdit = null;
680
- }
681
-
682
- /** Discard the full-row edit. */
683
- function cancelFullRowEdit(): void {
684
- ctx.fullRowEdit = null;
685
- }
686
-
687
- return {
688
- isCellEditable,
689
- isCellEditableAt,
690
- getRowColumnValue,
691
- getCellDisplayValue,
692
- startEditingWithChar,
693
- startEditing,
694
- stopEditing,
695
- startFullRowEdit,
696
- setFullRowDraft,
697
- commitFullRowEdit,
698
- cancelFullRowEdit,
699
- saveEditingCell,
700
- applyHistoryStep,
701
- updateEditingCellValue,
702
- onEditorKeyDown,
703
- commitAndMoveByTab,
704
- focusOnMount,
705
- onCellDoubleClick,
706
- pasteFromClipboard,
707
- onGridPaste,
708
- };
709
- }
1
+ // editing 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
+ parseEditorValue,
6
+ type CellContext,
7
+ type CellEditorType,
8
+ type Column,
9
+ type Row,
10
+ type RowData,
11
+ type TableFeatures,
12
+ } from "./index";
13
+ import "./sv-grid-scrollbar";
14
+ import { getNextActiveCell } from "./keyboard";
15
+ import {
16
+ getCellKey,
17
+ toValueArray,
18
+ } from "./SvGrid.helpers";
19
+ import {
20
+ getColumnBaseValue,
21
+ isGroupRow,
22
+ } from "./cell-values";
23
+
24
+ type HistoryStep = {
25
+ rowId: string;
26
+ columnId: string;
27
+ field: string;
28
+ before: unknown;
29
+ after: unknown;
30
+ };
31
+
32
+ export function createEditing<
33
+ TFeatures extends TableFeatures = TableFeatures,
34
+ TData extends RowData = RowData,
35
+ >(ctx: any) {
36
+ /**
37
+ * Resolve `columnDef.editable` for one row × column pair.
38
+ *
39
+ * - `undefined` / `true` → editable
40
+ * - `false` → not editable (column-level lockdown, fastest path)
41
+ * - function → call it with the cell's context and honour the
42
+ * boolean it returns (cell-level lockdown - used for things like
43
+ * "this field is owned by the server, this one isn't, by row")
44
+ *
45
+ * Called from every editing entry point: double-click, type-to-edit,
46
+ * fill-handle drag, Delete-clear, clipboard paste. A central helper
47
+ * keeps the cell-level callback signature consistent and saves a
48
+ * lookup of CellContext at each site.
49
+ */
50
+ function isCellEditable(column: Column<TData>, row?: Row<TData>): boolean {
51
+ const editable = column.columnDef.editable;
52
+ if (editable === false) return false;
53
+ if (typeof editable !== "function") return true;
54
+ if (!row) return true;
55
+ const cellCtx: CellContext<TData> = {
56
+ cell: {
57
+ id: `${row.id}_${column.id}`,
58
+ row,
59
+ column,
60
+ getValue: () => getColumnBaseValue(row, column),
61
+ getContext: () => cellCtx,
62
+ },
63
+ row,
64
+ column,
65
+ table: ctx.grid,
66
+ getValue: () => getColumnBaseValue(row, column),
67
+ };
68
+ try {
69
+ return editable(cellCtx) !== false;
70
+ } catch {
71
+ // A throwing predicate shouldn't crash the grid - log and treat
72
+ // as not-editable so any error biases toward safety.
73
+ return false;
74
+ }
75
+ }
76
+
77
+ /** Variant that takes raw row + column indices for the rare callers
78
+ * (fill-handle, paste, Delete) that already work in index-space. */
79
+ function isCellEditableAt(rowIndex: number, colIndex: number): boolean {
80
+ const row = ctx.allRows[rowIndex];
81
+ const column = ctx.allColumns[colIndex];
82
+ if (!column) return false;
83
+ return isCellEditable(column, row);
84
+ }
85
+
86
+ function getRowColumnValue(row: Row<TData>, columnId: string) {
87
+ const column = ctx.allColumns.find((entry: any) => entry.id === columnId);
88
+ return column
89
+ ? getColumnBaseValue(row, column)
90
+ : row.getCellValueByColumnId(columnId);
91
+ }
92
+
93
+ function getCellDisplayValue(
94
+ rowId: string,
95
+ columnId: string,
96
+ baseValue: unknown,
97
+ ) {
98
+ const key = getCellKey(rowId, columnId);
99
+ return key in ctx.editedCellValues ? ctx.editedCellValues[key] : baseValue;
100
+ }
101
+
102
+ /** Start editing seeded with a typed character (Excel-style type-to-edit). */
103
+ function startEditingWithChar(
104
+ rowIndex: number,
105
+ colIndex: number,
106
+ char: string,
107
+ ): boolean {
108
+ if (!ctx.editingEnabled) return false;
109
+ const row = ctx.allRows[rowIndex];
110
+ const column = ctx.allColumns[colIndex];
111
+ if (!row || !column || isGroupRow(row)) return false;
112
+ if (!isCellEditable(column, row)) return false;
113
+ const editorType = (column.columnDef.editorType ??
114
+ "text") as CellEditorType;
115
+ if (
116
+ editorType === "checkbox" ||
117
+ editorType === "date" ||
118
+ editorType === "datetime" ||
119
+ editorType === "list" ||
120
+ editorType === "chips"
121
+ ) {
122
+ return false;
123
+ }
124
+ if (editorType === "number" && !/[0-9.+-]/.test(char)) return false;
125
+ ctx.editorSelectAll = false;
126
+ ctx.editingCell = {
127
+ rowId: row.id,
128
+ columnId: column.id,
129
+ editorType,
130
+ value: char,
131
+ rowRef: row.original,
132
+ };
133
+ ctx.setActiveCell(rowIndex, colIndex);
134
+ ctx.setSelection(rowIndex, colIndex);
135
+ return true;
136
+ }
137
+
138
+ function saveEditingCell() {
139
+ if (!ctx.editingCell) return;
140
+ const editing = ctx.editingCell;
141
+ // Resolve the row this edit belongs to. `allRows` is only the current page,
142
+ // so fall back to the full filtered model, then to the data object captured
143
+ // when the edit started. Without that last hop an edit is silently dropped
144
+ // when a filter typed mid-edit hides the row from both models (#49).
145
+ const row =
146
+ ctx.allRows.find((entry: any) => entry.id === editing.rowId) ??
147
+ ctx.allRowsBeforePagination.find((entry: any) => entry.id === editing.rowId);
148
+ const rowData = (row?.original ?? editing.rowRef) as
149
+ | Record<string, unknown>
150
+ | undefined;
151
+ const column = ctx.allColumns.find(
152
+ (entry: any) => entry.id === ctx.editingCell?.columnId,
153
+ );
154
+ const parsedValue = parseEditorValue(
155
+ ctx.editingCell.editorType,
156
+ ctx.editingCell.value,
157
+ {
158
+ multiple: column?.columnDef.editorMultiple === true,
159
+ },
160
+ );
161
+ let oldValue: unknown = undefined;
162
+ let finalValue: unknown = parsedValue;
163
+ if (rowData && column?.columnDef.field) {
164
+ oldValue = rowData[column.columnDef.field];
165
+ // Per-column valueParser refines the type-coerced value before storing.
166
+ const parser = (
167
+ column.columnDef as { valueParser?: (p: unknown) => unknown }
168
+ ).valueParser;
169
+ if (parser) {
170
+ finalValue = parser({
171
+ newValue: parsedValue,
172
+ oldValue,
173
+ rawInput: ctx.editingCell.value,
174
+ data: rowData,
175
+ columnId: ctx.editingCell.columnId,
176
+ });
177
+ }
178
+ rowData[column.columnDef.field] = finalValue;
179
+ }
180
+ const key = getCellKey(ctx.editingCell.rowId, ctx.editingCell.columnId);
181
+ ctx.editedCellValues = {
182
+ ...ctx.editedCellValues,
183
+ [key]: finalValue,
184
+ };
185
+ ctx.grid.store.setState((prev: any) => ({ ...prev }));
186
+ // Record into the history at the current pointer. Any forward
187
+ // history (steps the user could have redone) is truncated - this
188
+ // is the standard "edit invalidates redo" rule.
189
+ if (oldValue !== finalValue && rowData && column?.columnDef.field) {
190
+ const step: HistoryStep = {
191
+ rowId: ctx.editingCell.rowId,
192
+ columnId: ctx.editingCell.columnId,
193
+ field: column.columnDef.field as string,
194
+ before: oldValue,
195
+ after: finalValue,
196
+ }
197
+ const truncated = ctx.history.slice(0, ctx.historyPtr + 1)
198
+ truncated.push(step)
199
+ // Cap the buffer at UNDO_LIMIT; drop the OLDEST entries so the
200
+ // pointer stays valid relative to the newest steps.
201
+ if (truncated.length > ctx.UNDO_LIMIT) {
202
+ const drop = truncated.length - ctx.UNDO_LIMIT
203
+ ctx.history = truncated.slice(drop)
204
+ ctx.historyPtr = ctx.history.length - 1
205
+ } else {
206
+ ctx.history = truncated
207
+ ctx.historyPtr = ctx.history.length - 1
208
+ }
209
+ ctx.historyVersion += 1
210
+ }
211
+ // Notify the consumer AFTER the row has been updated so any callback-
212
+ // driven recompute (cascade totals, server save, undo stack) sees the
213
+ // post-write state. `rowIndex` matches the position in `props.data`.
214
+ if (ctx.props.onCellValueChange && rowData && column) {
215
+ const rowIndex = ctx.internalData.indexOf(rowData as TData);
216
+ ctx.props.onCellValueChange({
217
+ rowIndex,
218
+ columnId: column.id,
219
+ oldValue,
220
+ newValue: finalValue,
221
+ row: rowData as TData,
222
+ });
223
+ }
224
+ ctx.editingCell = null;
225
+ }
226
+
227
+ /** Apply an undo / redo step directly to the underlying row, bypassing
228
+ * the editor pipeline so we don't accidentally re-push to the stack. */
229
+ function applyHistoryStep(step: HistoryStep, direction: 'undo' | 'redo') {
230
+ const row = ctx.allRows.find((r: any) => r.id === step.rowId)
231
+ const col = ctx.allColumns.find((c: any) => c.id === step.columnId)
232
+ if (!row?.original || !col) return
233
+ const value = direction === 'undo' ? step.before : step.after
234
+ ;(row.original as Record<string, unknown>)[step.field] = value
235
+ const key = getCellKey(step.rowId, step.columnId)
236
+ ctx.editedCellValues = { ...ctx.editedCellValues, [key]: value }
237
+ ctx.grid.store.setState((prev: any) => ({ ...prev }))
238
+ if (ctx.props.onCellValueChange) {
239
+ const rowIndex = ctx.internalData.indexOf(row.original as TData)
240
+ ctx.props.onCellValueChange({
241
+ rowIndex,
242
+ columnId: step.columnId,
243
+ oldValue: direction === 'undo' ? step.after : step.before,
244
+ newValue: value,
245
+ row: row.original as TData,
246
+ })
247
+ }
248
+ }
249
+
250
+ function updateEditingCellValue(value: unknown) {
251
+ ctx.editingCell = ctx.editingCell ? { ...ctx.editingCell, value } : ctx.editingCell;
252
+ }
253
+
254
+ /**
255
+ * Commit the open editor and move the active cell one column along, wrapping
256
+ * at row boundaries the way Excel does. Editors `stopPropagation()` every key
257
+ * so the grid's own Tab handler never sees this one - without the explicit
258
+ * move, Tab committed the edit and then let the browser walk focus out of the
259
+ * grid entirely (#48). Shared by every editor type, including the textarea.
260
+ */
261
+ function commitAndMoveByTab(shiftKey: boolean) {
262
+ const active = ctx.activeCell;
263
+ saveEditingCell();
264
+ ctx.gridRootEl?.focus({ preventScroll: true });
265
+ if (!active) return;
266
+ const next = getNextActiveCell(active, shiftKey ? "tabPrev" : "tabNext", {
267
+ maxRow: ctx.allRows.length - 1,
268
+ maxCol: ctx.allColumns.length - 1,
269
+ });
270
+ ctx.setActiveCell(next.rowIndex, next.colIndex);
271
+ ctx.setSelection(next.rowIndex, next.colIndex);
272
+ ctx.scrollActiveCellIntoView(next.rowIndex, next.colIndex);
273
+ }
274
+
275
+ function onEditorKeyDown(event: KeyboardEvent) {
276
+ event.stopPropagation();
277
+ if (event.key === "Enter") {
278
+ event.preventDefault();
279
+ saveEditingCell();
280
+ ctx.gridRootEl?.focus({ preventScroll: true });
281
+ } else if (event.key === "Tab") {
282
+ event.preventDefault();
283
+ commitAndMoveByTab(event.shiftKey);
284
+ } else if (event.key === "Escape") {
285
+ event.preventDefault();
286
+ ctx.editingCell = null;
287
+ ctx.gridRootEl?.focus({ preventScroll: true });
288
+ }
289
+ }
290
+
291
+ function focusOnMount(node: HTMLInputElement | HTMLTextAreaElement) {
292
+ const selectAll = ctx.editorSelectAll;
293
+ requestAnimationFrame(() => {
294
+ node.focus({ preventScroll: true });
295
+ try {
296
+ if (selectAll) {
297
+ node.select();
298
+ } else {
299
+ const end = node.value.length;
300
+ node.setSelectionRange(end, end);
301
+ }
302
+ } catch {
303
+ /* date/number inputs may not support text selection */
304
+ }
305
+ });
306
+ }
307
+
308
+ function onCellDoubleClick(rowIndex: number, colIndex: number) {
309
+ if (!ctx.editingEnabled) return;
310
+ const row = ctx.allRows[rowIndex];
311
+ const column = ctx.allColumns[colIndex];
312
+ if (!row || !column) return;
313
+ if (isGroupRow(row)) return;
314
+ // Full-row editing: put the whole row into edit instead of one cell.
315
+ if (ctx.props.fullRowEditing) {
316
+ if (ctx.fullRowEdit?.rowId === row.id) return;
317
+ startFullRowEdit(rowIndex);
318
+ return;
319
+ }
320
+ if (!isCellEditable(column, row)) return;
321
+ if (ctx.editingCell?.rowId === row.id && ctx.editingCell?.columnId === column.id)
322
+ return;
323
+ const editorType = (column.columnDef.editorType ??
324
+ "text") as CellEditorType;
325
+ ctx.editorSelectAll = true;
326
+ let initialValue = getCellDisplayValue(
327
+ row.id,
328
+ column.id,
329
+ row.getCellValueByColumnId(column.id),
330
+ );
331
+ if (editorType === "list" || editorType === "chips") {
332
+ if (column.columnDef.editorMultiple) {
333
+ // Seed with an array so the editor can mutate slot-by-slot.
334
+ initialValue = toValueArray(initialValue);
335
+ } else if (Array.isArray(initialValue)) {
336
+ initialValue = initialValue[0] ?? "";
337
+ }
338
+ }
339
+ ctx.editingCell = {
340
+ rowId: row.id,
341
+ columnId: column.id,
342
+ editorType,
343
+ value: initialValue,
344
+ rowRef: row.original,
345
+ };
346
+ ctx.setActiveCell(rowIndex, colIndex);
347
+ ctx.setSelection(rowIndex, colIndex);
348
+ }
349
+
350
+ async function pasteFromClipboard() {
351
+ // Preferred path: the async Clipboard API. Requires a secure context
352
+ // (HTTPS or localhost) AND read permission; it also works on Firefox,
353
+ // where the native `paste` event does NOT fire on a non-editable element.
354
+ // On plain HTTP (a XAMPP/Apache LAN host) `navigator.clipboard` is
355
+ // undefined - there the Ctrl+V keydown handler skips preventDefault and
356
+ // lets the browser deliver a native `paste` event to `onGridPaste`.
357
+ if (!navigator.clipboard?.readText) return;
358
+ let text: string;
359
+ try {
360
+ text = await navigator.clipboard.readText();
361
+ } catch {
362
+ return;
363
+ }
364
+ applyPastedText(text);
365
+ }
366
+
367
+ /**
368
+ * Native `paste` ClipboardEvent fallback (insecure-context path). A real
369
+ * Ctrl/Cmd+V on the focused grid root fires this with `clipboardData`
370
+ * readable even over plain HTTP and with no permission prompt. Wired on the
371
+ * grid root in SvGrid.svelte; the keydown handler lets the gesture through
372
+ * (no preventDefault) whenever the async API is unavailable.
373
+ */
374
+ function onGridPaste(event: ClipboardEvent) {
375
+ // A cell is being edited: the focused editor input handles its own paste
376
+ // natively. Never hijack it for a range paste - doing so (on Firefox /
377
+ // insecure contexts, where the async Clipboard API is unavailable) would
378
+ // preventDefault the editor's paste and write to the data cell instead,
379
+ // so the edit "wouldn't update".
380
+ if (ctx.editingCell) return;
381
+ // When the async API is available the keydown handler already pasted via
382
+ // pasteFromClipboard(); ignore the (suppressed) native event so we don't
383
+ // paste twice.
384
+ if (typeof navigator.clipboard?.readText === "function") return;
385
+ const text = event.clipboardData?.getData("text/plain") ?? "";
386
+ if (!text) return;
387
+ event.preventDefault();
388
+ applyPastedText(text);
389
+ }
390
+
391
+ function applyPastedText(text: string) {
392
+ const anchor = ctx.selectionRange.anchor ?? ctx.grid.getState().activeCell;
393
+ if (!anchor) return;
394
+ const focus = ctx.selectionRange.focus ?? anchor;
395
+ const startRow = Math.min(anchor.rowIndex, focus.rowIndex);
396
+ const startCol = Math.min(anchor.colIndex, focus.colIndex);
397
+ const endRow = Math.max(anchor.rowIndex, focus.rowIndex);
398
+ const endCol = Math.max(anchor.colIndex, focus.colIndex);
399
+ const lines = text.replace(/\r\n/g, "\n").split("\n");
400
+ if (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
401
+ if (!lines.length) return;
402
+
403
+ // Excel/Sheets behaviour: when the clipboard holds a single cell and
404
+ // the selection is a range, fill the entire range with that value.
405
+ // For larger clipboards (multi-row/col TSV), paste at the top-left
406
+ // corner and let the clipboard determine the span (the original
407
+ // behaviour).
408
+ const clipboardIsSingleCell =
409
+ lines.length === 1 && (lines[0]?.split("\t").length ?? 0) === 1;
410
+ const selectionIsRange = startRow !== endRow || startCol !== endCol;
411
+ const fillRange = clipboardIsSingleCell && selectionIsRange;
412
+
413
+ const rowSpan = fillRange ? endRow - startRow + 1 : lines.length;
414
+ const colSpan = fillRange
415
+ ? endCol - startCol + 1
416
+ : Math.max(...lines.map((l) => l.split("\t").length));
417
+
418
+ const next = ctx.internalData.slice() as Array<TData>;
419
+ for (let i = 0; i < rowSpan; i += 1) {
420
+ const targetRowIndex = startRow + i;
421
+ const row = ctx.allRows[targetRowIndex];
422
+ if (!row || isGroupRow(row)) continue;
423
+ // Map the visible row back to its index in the data array via row.id (default = String(index)).
424
+ const dataIndex = Number(row.id);
425
+ if (
426
+ !Number.isInteger(dataIndex) ||
427
+ dataIndex < 0 ||
428
+ dataIndex >= next.length
429
+ )
430
+ continue;
431
+ const originalRow = next[dataIndex];
432
+ if (!originalRow) continue;
433
+ const sourceCells = fillRange
434
+ ? null
435
+ : lines[i]?.split("\t") ?? [];
436
+ const updated: Record<string, unknown> = {
437
+ ...(originalRow as Record<string, unknown>),
438
+ };
439
+ for (let j = 0; j < colSpan; j += 1) {
440
+ const column = ctx.allColumns[startCol + j];
441
+ if (!column?.columnDef.field) continue;
442
+ if (!isCellEditableAt(targetRowIndex, startCol + j)) continue;
443
+ const editorType = (column.columnDef.editorType ??
444
+ "text") as CellEditorType;
445
+ const raw = fillRange ? lines[0]! : sourceCells?.[j] ?? "";
446
+ updated[column.columnDef.field] = parseEditorValue(editorType, raw);
447
+ }
448
+ next[dataIndex] = updated as TData;
449
+ }
450
+ ctx.internalData = next;
451
+ ctx.grid.store.setState((prev: any) => ({ ...prev }));
452
+ }
453
+
454
+ /** Programmatically begin editing a cell (mirrors a double-click). */
455
+ function startEditing(rowIndex: number, columnId: string): boolean {
456
+ if (!ctx.editingEnabled) return false;
457
+ const row = ctx.allRows[rowIndex];
458
+ if (!row || isGroupRow(row)) return false;
459
+ const colIndex = ctx.allColumns.findIndex((c: any) => c.id === columnId);
460
+ if (colIndex < 0) return false;
461
+ const column = ctx.allColumns[colIndex];
462
+ if (!isCellEditable(column, row)) return false;
463
+ if (
464
+ ctx.editingCell?.rowId === row.id &&
465
+ ctx.editingCell?.columnId === columnId
466
+ )
467
+ return true;
468
+ onCellDoubleClick(rowIndex, colIndex);
469
+ return (
470
+ ctx.editingCell?.rowId === row.id &&
471
+ ctx.editingCell?.columnId === columnId
472
+ );
473
+ }
474
+
475
+ /** Commit (default) or cancel the active edit, if any. */
476
+ function stopEditing(cancel = false): boolean {
477
+ if (!ctx.editingCell) return false;
478
+ if (cancel) {
479
+ ctx.editingCell = null;
480
+ } else {
481
+ saveEditingCell();
482
+ }
483
+ return true;
484
+ }
485
+
486
+ // ---- Full-row editing -------------------------------------------------
487
+ /** Put the whole row into edit mode, seeding a draft per editable column. */
488
+ function startFullRowEdit(rowIndex: number): boolean {
489
+ if (!ctx.editingEnabled || !ctx.props.fullRowEditing) return false;
490
+ const row = ctx.allRows[rowIndex];
491
+ if (!row || isGroupRow(row)) return false;
492
+ if (ctx.fullRowEdit && ctx.fullRowEdit.rowId !== row.id) commitFullRowEdit();
493
+ ctx.editingCell = null; // never both at once
494
+ const draft: Record<string, unknown> = {};
495
+ for (const column of ctx.allColumns) {
496
+ if (!column.columnDef.field) continue;
497
+ if (!isCellEditable(column, row)) continue;
498
+ draft[column.id] = getCellDisplayValue(
499
+ row.id,
500
+ column.id,
501
+ row.getCellValueByColumnId(column.id),
502
+ );
503
+ }
504
+ ctx.fullRowEdit = { rowId: row.id, draft };
505
+ ctx.setActiveCell(rowIndex, Math.max(0, ctx.allColumns.findIndex((c: any) => c.id in draft)));
506
+ return true;
507
+ }
508
+
509
+ /** Stage one column's draft value during full-row editing. */
510
+ function setFullRowDraft(columnId: string, value: unknown): void {
511
+ const fr = ctx.fullRowEdit;
512
+ if (!fr) return;
513
+ ctx.fullRowEdit = { rowId: fr.rowId, draft: { ...fr.draft, [columnId]: value } };
514
+ }
515
+
516
+ /** Commit every drafted column of the full-row edit in one data update. */
517
+ function commitFullRowEdit(): void {
518
+ const fr = ctx.fullRowEdit;
519
+ if (!fr) return;
520
+ const row = ctx.allRows.find((r: any) => r.id === fr.rowId);
521
+ if (!row?.original) {
522
+ ctx.fullRowEdit = null;
523
+ return;
524
+ }
525
+ const changed: Array<{ columnId: string; field: string; before: unknown; after: unknown }> = [];
526
+ for (const column of ctx.allColumns) {
527
+ if (!(column.id in fr.draft)) continue;
528
+ const field = column.columnDef.field as string | undefined;
529
+ if (!field) continue;
530
+ const editorType = (column.columnDef.editorType ?? "text") as CellEditorType;
531
+ const parsed = parseEditorValue(editorType, fr.draft[column.id], {
532
+ multiple: column.columnDef.editorMultiple === true,
533
+ });
534
+ const oldValue = (row.original as Record<string, unknown>)[field];
535
+ const parser = (column.columnDef as { valueParser?: (p: unknown) => unknown }).valueParser;
536
+ const finalValue = parser
537
+ ? parser({
538
+ newValue: parsed,
539
+ oldValue,
540
+ rawInput: String(fr.draft[column.id] ?? ""),
541
+ data: row.original,
542
+ columnId: column.id,
543
+ })
544
+ : parsed;
545
+ if (oldValue !== finalValue) {
546
+ (row.original as Record<string, unknown>)[field] = finalValue;
547
+ const key = getCellKey(fr.rowId, column.id);
548
+ ctx.editedCellValues = { ...ctx.editedCellValues, [key]: finalValue };
549
+ changed.push({ columnId: column.id, field, before: oldValue, after: finalValue });
550
+ }
551
+ }
552
+ // Record the whole-row change as consecutive history steps.
553
+ if (changed.length) {
554
+ let hist = ctx.history.slice(0, ctx.historyPtr + 1);
555
+ for (const c of changed) {
556
+ hist.push({ rowId: fr.rowId, columnId: c.columnId, field: c.field, before: c.before, after: c.after });
557
+ }
558
+ if (hist.length > ctx.UNDO_LIMIT) hist = hist.slice(hist.length - ctx.UNDO_LIMIT);
559
+ ctx.history = hist;
560
+ ctx.historyPtr = ctx.history.length - 1;
561
+ ctx.historyVersion += 1;
562
+ }
563
+ ctx.grid.store.setState((prev: any) => ({ ...prev }));
564
+ if (ctx.props.onCellValueChange && changed.length) {
565
+ const rowIndex = ctx.internalData.indexOf(row.original as TData);
566
+ for (const c of changed) {
567
+ ctx.props.onCellValueChange({
568
+ rowIndex,
569
+ columnId: c.columnId,
570
+ oldValue: c.before,
571
+ newValue: c.after,
572
+ row: row.original as TData,
573
+ });
574
+ }
575
+ }
576
+ ctx.fullRowEdit = null;
577
+ }
578
+
579
+ /** Discard the full-row edit. */
580
+ function cancelFullRowEdit(): void {
581
+ ctx.fullRowEdit = null;
582
+ }
583
+
584
+ return {
585
+ isCellEditable,
586
+ isCellEditableAt,
587
+ getRowColumnValue,
588
+ getCellDisplayValue,
589
+ startEditingWithChar,
590
+ startEditing,
591
+ stopEditing,
592
+ startFullRowEdit,
593
+ setFullRowDraft,
594
+ commitFullRowEdit,
595
+ cancelFullRowEdit,
596
+ saveEditingCell,
597
+ applyHistoryStep,
598
+ updateEditingCellValue,
599
+ onEditorKeyDown,
600
+ commitAndMoveByTab,
601
+ focusOnMount,
602
+ onCellDoubleClick,
603
+ pasteFromClipboard,
604
+ onGridPaste,
605
+ };
606
+ }