@svgrid/grid 2.6.21 → 2.7.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 (358) hide show
  1. package/CHANGELOG.md +150 -88
  2. package/README.md +221 -199
  3. package/dist/FlexRender.svelte +96 -96
  4. package/dist/GridFooter.svelte +181 -181
  5. package/dist/GridMenus.svelte +201 -18
  6. package/dist/SvAutoComplete.svelte +169 -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 +279 -275
  14. package/dist/SvContextMenu.svelte +116 -116
  15. package/dist/SvCountryInput.svelte +163 -163
  16. package/dist/SvDateRangeInput.svelte +25 -3
  17. package/dist/SvDrawer.svelte +254 -254
  18. package/dist/SvDropDownList.svelte +378 -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.controller.svelte.d.ts +61 -9
  23. package/dist/SvGrid.controller.svelte.js +363 -123
  24. package/dist/SvGrid.css +222 -1
  25. package/dist/SvGrid.helpers.d.ts +55 -0
  26. package/dist/SvGrid.helpers.js +83 -0
  27. package/dist/SvGrid.svelte +255 -56
  28. package/dist/SvGrid.types.d.ts +146 -1
  29. package/dist/SvGridCellEditor.svelte +744 -662
  30. package/dist/SvGridChart.svelte +1716 -1716
  31. package/dist/SvGridChartPanel.svelte +485 -485
  32. package/dist/SvGridChartView.svelte +70 -70
  33. package/dist/SvGridDropdown.svelte +728 -728
  34. package/dist/SvGridSelect.svelte +270 -266
  35. package/dist/SvGridSelect.svelte.d.ts +1 -1
  36. package/dist/SvGroupCell.svelte +116 -116
  37. package/dist/SvListBox.svelte +334 -326
  38. package/dist/SvMaskedInput.svelte +122 -122
  39. package/dist/SvMenu.svelte +124 -124
  40. package/dist/SvMenuList.svelte +146 -146
  41. package/dist/SvMultiSelect.svelte +293 -289
  42. package/dist/SvMultiSelect.svelte.d.ts +1 -1
  43. package/dist/SvNumberInput.svelte +172 -168
  44. package/dist/SvOtpInput.svelte +158 -158
  45. package/dist/SvPasswordInput.svelte +151 -151
  46. package/dist/SvPhoneInput.svelte +133 -133
  47. package/dist/SvPopover.svelte +197 -197
  48. package/dist/SvProgress.svelte +116 -116
  49. package/dist/SvRadioGroup.svelte +107 -107
  50. package/dist/SvRating.svelte +112 -112
  51. package/dist/SvResult.svelte +73 -73
  52. package/dist/SvRichCell.svelte +125 -0
  53. package/dist/SvRichCell.svelte.d.ts +15 -0
  54. package/dist/SvRichText.svelte +211 -211
  55. package/dist/SvRowGroupPanel.svelte +170 -170
  56. package/dist/SvScrollArea.svelte +61 -61
  57. package/dist/SvSlider.svelte +203 -203
  58. package/dist/SvSwitchButton.svelte +108 -108
  59. package/dist/SvTagsInput.svelte +115 -115
  60. package/dist/SvTextArea.svelte +5 -1
  61. package/dist/SvTextInput.svelte +147 -147
  62. package/dist/SvTimePicker.svelte +245 -245
  63. package/dist/SvToaster.svelte +159 -159
  64. package/dist/SvToggleButton.svelte +85 -85
  65. package/dist/SvTooltip.svelte +161 -161
  66. package/dist/SvTour.svelte +208 -208
  67. package/dist/SvTree.svelte +444 -444
  68. package/dist/SvTreeSelect.svelte +239 -235
  69. package/dist/SvTreeSelect.svelte.d.ts +1 -1
  70. package/dist/builtin-editors.d.ts +2 -2
  71. package/dist/builtin-editors.js +19 -3
  72. package/dist/cdn/GridMenus-C4oLsJyj.js +600 -0
  73. package/dist/cdn/GridMenus-yEivjNwl.js +601 -0
  74. package/dist/cdn/SvDateRangeInput-Bh0A0JkF.js +199 -0
  75. package/dist/cdn/SvDateRangeInput-DflbiP7N.js +198 -0
  76. package/dist/cdn/SvDateTimePicker-BWwpfB_o.js +812 -0
  77. package/dist/cdn/SvDateTimePicker-Bivn8dAP.js +816 -0
  78. package/dist/cdn/SvGridCellEditor-AXL8cHGO.js +550 -0
  79. package/dist/cdn/SvGridCellEditor-Ba7rY3eu.js +549 -0
  80. package/dist/cdn/{SvGridChart-BwVos976.js → SvGridChart-Bs2GIR2Q.js} +1 -1
  81. package/dist/cdn/{SvGridChart-BEJmNNx9.js → SvGridChart-CwhFz7GV.js} +1 -1
  82. package/dist/cdn/{SvGridChartPanel-BOknOkrP.js → SvGridChartPanel-1WXuStzM.js} +1 -1
  83. package/dist/cdn/{SvGridChartPanel-D2PjII4O.js → SvGridChartPanel-e5_nqNP9.js} +1 -1
  84. package/dist/cdn/{SvGridChartView-00LPUHL1.js → SvGridChartView-SmPW10dI.js} +1 -1
  85. package/dist/cdn/{SvGridChartView-BhUEJ5ki.js → SvGridChartView-eSPuJE6g.js} +1 -1
  86. package/dist/cdn/{SvGridDropdown-D0VdjeR8.js → SvGridDropdown-B1ZcLpgs.js} +1 -1
  87. package/dist/cdn/{SvGridDropdown-D13MtJ2j.js → SvGridDropdown-CtdbHcIS.js} +1 -1
  88. package/dist/cdn/column-resize-DsfNXMom.js +102 -0
  89. package/dist/cdn/date-format-CcP1tafP.js +1395 -0
  90. package/dist/cdn/date-format-DZT7T1wf.js +1393 -0
  91. package/dist/cdn/{editor-registry-CiI0xlKg.js → editor-registry-BhgE3S84.js} +51 -25
  92. package/dist/cdn/row-resize-BRcimkUT.js +95 -0
  93. package/dist/cdn/{src-BYq-qyrp.js → src-COC0vnpg.js} +7846 -7317
  94. package/dist/cdn/{src-DBel9wRZ.js → src-pYGV2rMR.js} +10033 -9504
  95. package/dist/cdn/svgrid.js +15 -11
  96. package/dist/cdn/svgrid.svelte-external.js +15 -11
  97. package/dist/cell-values.d.ts +16 -0
  98. package/dist/cell-values.js +28 -0
  99. package/dist/chart-export.js +8 -8
  100. package/dist/clipboard.d.ts +22 -0
  101. package/dist/clipboard.js +405 -27
  102. package/dist/column-groups.js +1 -1
  103. package/dist/column-resize.d.ts +46 -0
  104. package/dist/column-resize.js +205 -0
  105. package/dist/columns.d.ts +0 -3
  106. package/dist/columns.js +0 -57
  107. package/dist/core.d.ts +19 -4
  108. package/dist/core.js +460 -119
  109. package/dist/editing.js +12 -7
  110. package/dist/editors/cell-editors.d.ts +11 -0
  111. package/dist/editors/cell-editors.js +18 -1
  112. package/dist/filtering/excel-filters.js +28 -0
  113. package/dist/grid-messages.d.ts +15 -0
  114. package/dist/grid-messages.js +15 -0
  115. package/dist/group-display.d.ts +1 -1
  116. package/dist/index.d.ts +6 -1
  117. package/dist/index.js +10 -0
  118. package/dist/list-option.d.ts +6 -0
  119. package/dist/menus.js +41 -8
  120. package/dist/row-resize.d.ts +11 -0
  121. package/dist/row-resize.js +7 -1
  122. package/dist/sanitize-html.d.ts +37 -0
  123. package/dist/sanitize-html.js +234 -0
  124. package/dist/selection-bar-view.svelte.d.ts +25 -0
  125. package/dist/selection-bar-view.svelte.js +13 -0
  126. package/dist/selection.d.ts +2 -1
  127. package/dist/selection.js +133 -8
  128. package/dist/spreadsheet.d.ts +1 -1
  129. package/dist/spreadsheet.js +1 -1
  130. package/package.json +11 -11
  131. package/src/FlexRender.svelte +96 -96
  132. package/src/GridFooter.svelte +181 -181
  133. package/src/GridMenus.svelte +201 -18
  134. package/src/SvAutoComplete.svelte +169 -165
  135. package/src/SvAvatar.svelte +75 -75
  136. package/src/SvCalendar.svelte +503 -503
  137. package/src/SvCalendar.test.ts +226 -226
  138. package/src/SvCarousel.svelte +141 -141
  139. package/src/SvCheckBox.svelte +102 -102
  140. package/src/SvCircularProgress.svelte +109 -109
  141. package/src/SvColorInput.svelte +181 -181
  142. package/src/SvComboBox.svelte +279 -275
  143. package/src/SvContextMenu.svelte +116 -116
  144. package/src/SvCountryInput.svelte +163 -163
  145. package/src/SvDateRangeInput.svelte +25 -3
  146. package/src/SvDrawer.svelte +254 -254
  147. package/src/SvDropDownList.svelte +378 -374
  148. package/src/SvDurationInput.svelte +126 -126
  149. package/src/SvField.svelte +293 -293
  150. package/src/SvForm.svelte +437 -437
  151. package/src/SvForm.test.ts +411 -411
  152. package/src/SvGrid.controller.svelte.ts +404 -133
  153. package/src/SvGrid.css +222 -1
  154. package/src/SvGrid.helpers.ts +87 -0
  155. package/src/SvGrid.svelte +255 -56
  156. package/src/SvGrid.types.ts +2092 -1940
  157. package/src/SvGridCellEditor.svelte +744 -662
  158. package/src/SvGridChart.svelte +1716 -1716
  159. package/src/SvGridChartPanel.svelte +485 -485
  160. package/src/SvGridChartView.svelte +70 -70
  161. package/src/SvGridDropdown.svelte +728 -728
  162. package/src/SvGridSelect.svelte +270 -266
  163. package/src/SvGroupCell.svelte +116 -116
  164. package/src/SvListBox.svelte +334 -326
  165. package/src/SvMaskedInput.svelte +122 -122
  166. package/src/SvMenu.svelte +124 -124
  167. package/src/SvMenu.test.ts +97 -97
  168. package/src/SvMenuList.svelte +146 -146
  169. package/src/SvMultiSelect.svelte +293 -289
  170. package/src/SvNumberInput.svelte +172 -168
  171. package/src/SvOtpInput.svelte +158 -158
  172. package/src/SvPasswordInput.svelte +151 -151
  173. package/src/SvPhoneInput.svelte +133 -133
  174. package/src/SvPopover.svelte +197 -197
  175. package/src/SvProgress.svelte +116 -116
  176. package/src/SvRadioGroup.svelte +107 -107
  177. package/src/SvRating.svelte +112 -112
  178. package/src/SvResult.svelte +73 -73
  179. package/src/SvRichCell.svelte +125 -0
  180. package/src/SvRichText.svelte +211 -211
  181. package/src/SvRowGroupPanel.svelte +170 -170
  182. package/src/SvScrollArea.svelte +61 -61
  183. package/src/SvSlider.svelte +203 -203
  184. package/src/SvSwitchButton.svelte +108 -108
  185. package/src/SvTagsInput.svelte +115 -115
  186. package/src/SvTextArea.svelte +5 -1
  187. package/src/SvTextInput.svelte +147 -147
  188. package/src/SvTimePicker.svelte +245 -245
  189. package/src/SvToaster.svelte +159 -159
  190. package/src/SvToaster.test.ts +95 -95
  191. package/src/SvToggleButton.svelte +85 -85
  192. package/src/SvTooltip.svelte +161 -161
  193. package/src/SvTour.svelte +208 -208
  194. package/src/SvTree.svelte +444 -444
  195. package/src/SvTreeSelect.svelte +239 -235
  196. package/src/a11y/dismissable.test.ts +119 -119
  197. package/src/a11y/dismissable.ts +114 -114
  198. package/src/a11y.contract.test.ts +49 -49
  199. package/src/a11y.test.ts +59 -59
  200. package/src/a11y.ts +61 -61
  201. package/src/ai.test.ts +502 -502
  202. package/src/ai.ts +1419 -1419
  203. package/src/build-api.coverage.test.ts +633 -633
  204. package/src/build-api.ts +846 -846
  205. package/src/builtin-editors.grid.test.ts +83 -83
  206. package/src/builtin-editors.test.ts +18 -1
  207. package/src/builtin-editors.ts +19 -3
  208. package/src/cell-formatting.ts +171 -171
  209. package/src/cell-render.test.ts +513 -513
  210. package/src/cell-render.ts +496 -496
  211. package/src/cell-values.ts +148 -118
  212. package/src/chart-export.ts +202 -202
  213. package/src/chart-view.svelte.ts +36 -36
  214. package/src/chart.ts +2321 -2321
  215. package/src/clipboard.test.ts +93 -20
  216. package/src/clipboard.ts +433 -33
  217. package/src/collaboration.test.ts +104 -104
  218. package/src/collaboration.ts +167 -167
  219. package/src/column-groups.ts +78 -78
  220. package/src/column-resize.test.ts +381 -0
  221. package/src/column-resize.ts +227 -0
  222. package/src/columns.test.ts +0 -103
  223. package/src/columns.ts +0 -58
  224. package/src/core.aggregate.test.ts +134 -0
  225. package/src/core.filter.test.ts +156 -0
  226. package/src/core.grouping.test.ts +146 -0
  227. package/src/core.performance.test.ts +30 -30
  228. package/src/core.row-shape.test.ts +119 -0
  229. package/src/core.rowmodel-cache.test.ts +121 -0
  230. package/src/core.sort.test.ts +293 -0
  231. package/src/core.ts +1865 -1468
  232. package/src/createAutocomplete.svelte.ts +132 -132
  233. package/src/createCombobox.svelte.ts +191 -191
  234. package/src/createCountryInput.svelte.ts +157 -157
  235. package/src/createDropdownList.svelte.ts +168 -168
  236. package/src/createForm.svelte.ts +386 -386
  237. package/src/createGrid.svelte.ts +42 -42
  238. package/src/createGrid.test.ts +10 -10
  239. package/src/createGridState.svelte.ts +17 -17
  240. package/src/createListbox.svelte.ts +250 -250
  241. package/src/createMenu.svelte.ts +224 -224
  242. package/src/createPopoverSelect.svelte.ts +213 -213
  243. package/src/createSlider.svelte.ts +191 -191
  244. package/src/createTooltip.svelte.ts +144 -144
  245. package/src/createTree.svelte.ts +322 -322
  246. package/src/date-string-column.test.ts +87 -0
  247. package/src/datetime/date-core.ts +206 -206
  248. package/src/datetime/date-restrict.ts +61 -61
  249. package/src/datetime/timezone.ts +135 -135
  250. package/src/dock-manager-model.ts +596 -596
  251. package/src/dock-model.ts +374 -374
  252. package/src/editing.test.ts +974 -949
  253. package/src/editing.ts +609 -606
  254. package/src/editor-block-prop.test.ts +132 -0
  255. package/src/editor-contract.ts +171 -171
  256. package/src/editor-registry.grid.test.ts +144 -144
  257. package/src/editor-registry.ts +122 -122
  258. package/src/editors/cell-editors.ts +27 -1
  259. package/src/export-data-api.test.ts +126 -126
  260. package/src/export-format.test.ts +107 -107
  261. package/src/export-format.ts +601 -601
  262. package/src/filter-operators.ts +160 -160
  263. package/src/filtering/excel-filters.ts +325 -295
  264. package/src/filtering/normalize-fast-path.test.ts +104 -0
  265. package/src/flex-render.ts +3 -3
  266. package/src/form-field.ts +127 -127
  267. package/src/grid-messages.ts +34 -0
  268. package/src/group-display.test.ts +167 -167
  269. package/src/group-display.ts +200 -200
  270. package/src/headless.ts +87 -87
  271. package/src/index.ts +25 -1
  272. package/src/js-scroller.svelte.ts +173 -173
  273. package/src/keyboard-handlers.ts +270 -270
  274. package/src/keyboard.test.ts +59 -59
  275. package/src/keyboard.ts +97 -97
  276. package/src/list-nav.test.ts +49 -49
  277. package/src/list-nav.ts +29 -29
  278. package/src/list-option.test.ts +56 -56
  279. package/src/list-option.ts +179 -173
  280. package/src/menus.test.ts +43 -0
  281. package/src/menus.ts +597 -567
  282. package/src/merge-objects.ts +48 -48
  283. package/src/move-cells.test.ts +850 -0
  284. package/src/number-editor-literal.test.ts +84 -0
  285. package/src/number-editor.grid.test.ts +160 -0
  286. package/src/overlays.test.ts +90 -90
  287. package/src/positioning.ts +268 -268
  288. package/src/render-component.ts +28 -28
  289. package/src/resize-props.test.ts +361 -0
  290. package/src/row-drag-touch.ts +211 -211
  291. package/src/row-drag.test.ts +353 -353
  292. package/src/row-drag.ts +415 -415
  293. package/src/row-resize.test.ts +524 -493
  294. package/src/row-resize.ts +228 -210
  295. package/src/sanitize-html.test.ts +182 -0
  296. package/src/sanitize-html.ts +235 -0
  297. package/src/scheduler-ical.ts +181 -181
  298. package/src/scheduler-model.test.ts +562 -562
  299. package/src/scheduler-model.ts +873 -873
  300. package/src/selection-bar-view.svelte.ts +36 -0
  301. package/src/selection.test.ts +900 -743
  302. package/src/selection.ts +135 -8
  303. package/src/server-data-source.test.ts +383 -383
  304. package/src/server-data-source.ts +469 -469
  305. package/src/sparkline.test.ts +68 -68
  306. package/src/sparkline.ts +169 -169
  307. package/src/spreadsheet.test.ts +488 -488
  308. package/src/spreadsheet.ts +312 -312
  309. package/src/static-functions.ts +11 -11
  310. package/src/subscribe.ts +38 -38
  311. package/src/summaries.ts +113 -113
  312. package/src/svgrid-wrapper.types.ts +563 -563
  313. package/src/svgrid.async-editor-options.test.ts +273 -273
  314. package/src/svgrid.auto-row-height.test.ts +204 -204
  315. package/src/svgrid.behavior.test.ts +910 -910
  316. package/src/svgrid.charting.test.ts +534 -534
  317. package/src/svgrid.comments-autocomplete.test.ts +127 -127
  318. package/src/svgrid.context-menu.test.ts +147 -147
  319. package/src/svgrid.features.test.ts +157 -157
  320. package/src/svgrid.filter-depth.test.ts +163 -163
  321. package/src/svgrid.filter-menu-listbox.svelte.test.ts +377 -331
  322. package/src/svgrid.filter-menu-scroll.test.ts +112 -112
  323. package/src/svgrid.grand-total.test.ts +188 -188
  324. package/src/svgrid.group-display-mode.test.ts +171 -171
  325. package/src/svgrid.group-footers.test.ts +121 -121
  326. package/src/svgrid.group-pagination.test.ts +153 -153
  327. package/src/svgrid.in-suggest-snapshot.svelte.test.ts +91 -0
  328. package/src/svgrid.menu-scroll-close.test.ts +204 -0
  329. package/src/svgrid.new-features.wrapper.test.ts +251 -251
  330. package/src/svgrid.selection-bar-seam.test.ts +185 -0
  331. package/src/svgrid.tree-data.test.ts +186 -186
  332. package/src/svgrid.upsell-license.test.ts +117 -0
  333. package/src/svgrid.wrapper.test.ts +63 -63
  334. package/src/svgriddropdown.async-panel.svelte.test.ts +195 -195
  335. package/src/test-setup.ts +62 -62
  336. package/src/themes/index.ts +288 -288
  337. package/src/toast-store.svelte.ts +250 -250
  338. package/src/toast-store.test.ts +147 -147
  339. package/src/tree-row-model.test.ts +168 -168
  340. package/src/ui-buttons.test.ts +144 -144
  341. package/src/ui-inputs.test.ts +118 -118
  342. package/src/ui-localization.test.ts +113 -113
  343. package/src/ui-range.test.ts +70 -70
  344. package/src/ui-selection.test.ts +155 -155
  345. package/src/ui-tier1.test.ts +142 -142
  346. package/src/virtual.test.ts +88 -88
  347. package/src/virtualization/column-virtualizer.test.ts +27 -27
  348. package/src/virtualization/column-virtualizer.ts +30 -30
  349. package/src/virtualization/svelte-virtualizer.svelte.ts +26 -26
  350. package/src/virtualization/types.ts +30 -30
  351. package/src/virtualization/virtualizer.test.ts +47 -47
  352. package/src/virtualization/virtualizer.ts +322 -322
  353. package/dist/cdn/GridMenus-BfTAKn84.js +0 -488
  354. package/dist/cdn/GridMenus-C3bJd7w8.js +0 -489
  355. package/dist/cdn/SvDateTimePicker-CHnUkWcH.js +0 -2206
  356. package/dist/cdn/SvDateTimePicker-CRQH_U7E.js +0 -2201
  357. package/dist/cdn/SvGridCellEditor-BGUCzuPB.js +0 -523
  358. package/dist/cdn/SvGridCellEditor-G8IMWIws.js +0 -522
@@ -1,662 +1,744 @@
1
- <script lang="ts" generics="TFeatures extends TableFeatures = TableFeatures, TData extends RowData = RowData">
2
- /**
3
- * The in-cell and full-row editor UI, lifted out of SvGrid.svelte.
4
- *
5
- * Editing is off by default (`editable` / `enableInlineEditing` both default
6
- * to false) and this markup only ever renders while a cell is actually being
7
- * edited, so it has no business sitting in the base bundle. SvGrid.svelte
8
- * loads it with `import()` the moment editing is enabled - well before any
9
- * double-click can happen - so behaviour is unchanged either way.
10
- *
11
- * Keep `SvGridDropdown` and `SvDateTimePicker` DYNAMIC below. Importing
12
- * either statically would drag ~22 KB into this chunk for every text edit,
13
- * and a static import from anywhere reachable by SvGrid.svelte has silently
14
- * defeated a lazy boundary in this codebase before.
15
- */
16
- import {
17
- type CellEditorOption,
18
- type Column,
19
- type EditorContext,
20
- type Row,
21
- type RowData,
22
- type TableFeatures,
23
- } from "./index";
24
- import {
25
- dateToTimeString,
26
- getEditableInputValue,
27
- getEditorClass,
28
- getEditorInputType,
29
- timeStringToDate,
30
- toValueArray,
31
- } from "./SvGrid.helpers";
32
- import {
33
- getCellEditor,
34
- hasCellEditor,
35
- resolveEditorProps,
36
- type CellEditorContext,
37
- } from "./editor-registry";
38
- import type { SvGridController } from "./SvGrid.controller.svelte";
39
-
40
- let {
41
- ctrl,
42
- column,
43
- row,
44
- fullRow = false,
45
- }: {
46
- ctrl: SvGridController<TFeatures, TData>;
47
- column: Column<TData>;
48
- row: Row<TData>;
49
- /** Render the full-row editor for this cell instead of the single-cell one. */
50
- fullRow?: boolean;
51
- } = $props();
52
-
53
- // Heavy editors stay behind their own `import()` so a text edit never pays
54
- // for the dropdown or the date picker.
55
- let DropdownEditor = $state<typeof import("./SvGridDropdown.svelte").default | null>(null);
56
- let DateEditor = $state<typeof import("./SvDateTimePicker.svelte").default | null>(null);
57
- $effect(() => {
58
- const t = ctrl.editingCell?.editorType;
59
- if (
60
- (t === "list" || t === "chips" || t === "select" || t === "rich-select") &&
61
- !DropdownEditor
62
- )
63
- import("./SvGridDropdown.svelte").then((m) => (DropdownEditor = m.default));
64
- if ((t === "date" || t === "datetime" || t === "time") && !DateEditor)
65
- import("./SvDateTimePicker.svelte").then((m) => (DateEditor = m.default));
66
- });
67
-
68
- const grid = $derived(ctrl.grid);
69
- const fullRowEdit = $derived(ctrl.fullRowEdit);
70
- const getColumnEditorOptions = $derived(ctrl.getColumnEditorOptions);
71
- const areEditorOptionsLoading = $derived(ctrl.areEditorOptionsLoading);
72
- const saveEditingCell = $derived(ctrl.saveEditingCell);
73
- const updateEditingCellValue = $derived(ctrl.updateEditingCellValue);
74
- const onEditorKeyDown = $derived(ctrl.onEditorKeyDown);
75
- const focusOnMount = $derived(ctrl.focusOnMount);
76
- const toggleCheckboxWithKeyboard = $derived(ctrl.toggleCheckboxWithKeyboard);
77
-
78
- function fullRowKeydown(e: KeyboardEvent) {
79
- if (e.key === "Enter") {
80
- e.preventDefault();
81
- ctrl.commitFullRowEdit();
82
- ctrl.gridRootEl?.focus({ preventScroll: true });
83
- } else if (e.key === "Escape") {
84
- e.preventDefault();
85
- ctrl.cancelFullRowEdit();
86
- ctrl.gridRootEl?.focus({ preventScroll: true });
87
- }
88
- }
89
- function optionValueOf(o: unknown): string {
90
- return typeof o === "object" && o !== null && "value" in o
91
- ? String((o as { value: unknown }).value)
92
- : String(o);
93
- }
94
- function optionLabelOf(o: unknown): string {
95
- return typeof o === "object" && o !== null && "label" in o
96
- ? String((o as { label: unknown }).label)
97
- : String(o);
98
- }
99
-
100
- // Build the interaction context handed to a CUSTOM cell editor registered via
101
- // `registerCellEditor`. Maps the grid's editing lifecycle onto the uniform
102
- // change / commit / cancel contract every registered editor speaks.
103
- function buildRegisteredEditorContext(): CellEditorContext {
104
- const cell = ctrl.editingCell;
105
- return {
106
- value: cell?.value,
107
- rowId: cell?.rowId ?? "",
108
- columnId: cell?.columnId ?? "",
109
- onChange: (v: unknown) => updateEditingCellValue(v),
110
- onCommit: (v?: unknown) => {
111
- if (v !== undefined) updateEditingCellValue(v);
112
- saveEditingCell();
113
- },
114
- onCancel: () => {
115
- ctrl.editingCell = null;
116
- ctrl.gridRootEl?.focus({ preventScroll: true });
117
- },
118
- // Tab out of an editor: commit, then step to the adjacent cell. Without
119
- // this a registered editor's Tab walks focus out of the grid (#48) - the
120
- // built-in editors already route through the same helper.
121
- onCommitAndMove: (v: unknown, direction: 1 | -1) => {
122
- if (v !== undefined) updateEditingCellValue(v);
123
- ctrl.commitAndMoveByTab(direction === -1);
124
- },
125
- // Close a popover editor without committing. Same effect as cancel today;
126
- // named separately so an editor can distinguish "dismiss my panel" from
127
- // "abandon the edit" if that ever diverges.
128
- onRequestClose: () => {
129
- ctrl.editingCell = null;
130
- ctrl.gridRootEl?.focus({ preventScroll: true });
131
- },
132
- inCell: true,
133
- };
134
- }
135
- </script>
136
-
137
- {#snippet chipsEditor(
138
- opts: CellEditorOption[],
139
- multi: boolean,
140
- selectedArr: Array<string | number>,
141
- optsLoading: boolean,
142
- )}
143
- {#if opts.length > 0}
144
- <!-- Options-driven chips editor: defer to the custom dropdown,
145
- which renders the selected values as chips in its trigger and
146
- pops out a styled listbox. Identical UX to the list editor
147
- with renderChipsInTrigger flipped on. -->
148
- {#if DropdownEditor}
149
- <DropdownEditor
150
- options={opts}
151
- loading={optsLoading}
152
- value={ctrl.editingCell?.value}
153
- multiple={multi}
154
- placeholder="Pick…"
155
- renderChipsInTrigger={true}
156
- onChange={(next) => {
157
- ctrl.editingCell = ctrl.editingCell
158
- ? { ...ctrl.editingCell, value: next }
159
- : ctrl.editingCell;
160
- }}
161
- onCommit={() => saveEditingCell()}
162
- onCancel={() => {
163
- ctrl.editingCell = null;
164
- ctrl.gridRootEl?.focus({ preventScroll: true });
165
- }}
166
- />
167
- {/if}
168
- {:else}
169
- <!-- Free-form chips: typed tags. Enter / comma commits a chip,
170
- Backspace on empty input removes the last chip, blur saves. -->
171
- <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
172
- <div
173
- class="sv-grid-cell-editor sv-grid-cell-editor-chips"
174
- role="group"
175
- tabindex={-1}
176
- >
177
- <div class="sv-grid-chips-row">
178
- {#each selectedArr as v, idx (String(v) + "_" + idx)}
179
- <span class="sv-grid-chip sv-grid-chip-removable">
180
- {String(v)}
181
- <button
182
- type="button"
183
- class="sv-grid-chip-remove"
184
- aria-label="Remove {String(v)}"
185
- onmousedown={(event) => event.preventDefault()}
186
- onclick={() => {
187
- const next = selectedArr.filter((_, i) => i !== idx);
188
- ctrl.editingCell = ctrl.editingCell
189
- ? {
190
- ...ctrl.editingCell,
191
- value: multi ? next : (next[0] ?? null),
192
- }
193
- : ctrl.editingCell;
194
- }}>×</button
195
- >
196
- </span>
197
- {/each}
198
- <input
199
- use:focusOnMount
200
- class="sv-grid-chip-input"
201
- type="text"
202
- placeholder={multi ? "Type, Enter to add" : "Type a value"}
203
- onkeydown={(event) => {
204
- if (event.key === "Enter" || (multi && event.key === ",")) {
205
- event.preventDefault();
206
- event.stopPropagation();
207
- const input = event.currentTarget as HTMLInputElement;
208
- const raw = input.value.trim();
209
- if (raw) {
210
- const next = multi ? [...selectedArr, raw] : [raw];
211
- ctrl.editingCell = ctrl.editingCell
212
- ? { ...ctrl.editingCell, value: multi ? next : raw }
213
- : ctrl.editingCell;
214
- input.value = "";
215
- if (!multi) saveEditingCell();
216
- }
217
- } else if (event.key === "Escape") {
218
- onEditorKeyDown(event);
219
- } else if (event.key === "Backspace") {
220
- const input = event.currentTarget as HTMLInputElement;
221
- if (input.value === "" && selectedArr.length > 0) {
222
- event.preventDefault();
223
- const next = selectedArr.slice(0, -1);
224
- ctrl.editingCell = ctrl.editingCell
225
- ? {
226
- ...ctrl.editingCell,
227
- value: multi ? next : (next[0] ?? null),
228
- }
229
- : ctrl.editingCell;
230
- }
231
- }
232
- }}
233
- onblur={() => saveEditingCell()}
234
- />
235
- {#if multi}
236
- <button
237
- type="button"
238
- class="sv-grid-chip-commit"
239
- onmousedown={(event) => event.preventDefault()}
240
- onclick={() => saveEditingCell()}
241
- aria-label="Commit chip selection">Done</button
242
- >
243
- {/if}
244
- </div>
245
- </div>
246
- {/if}
247
- {/snippet}
248
-
249
- {#if fullRow}
250
- {@const et = column.columnDef.editorType ?? "text"}
251
- {@const val = fullRowEdit?.draft[column.id]}
252
- {#if et === "checkbox"}
253
- <input
254
- type="checkbox"
255
- class="sv-grid-fr-editor sv-grid-fr-checkbox"
256
- checked={Boolean(val)}
257
- onchange={(e) =>
258
- ctrl.setFullRowDraft(column.id, e.currentTarget.checked)}
259
- onkeydown={fullRowKeydown}
260
- onpointerdown={(e) => e.stopPropagation()}
261
- onclick={(e) => e.stopPropagation()}
262
- />
263
- {:else if et === "list" || et === "select" || et === "rich-select"}
264
- {@const opts = getColumnEditorOptions(column, row)}
265
- <select
266
- class="sv-grid-cell-editor sv-grid-fr-editor"
267
- value={String(val ?? "")}
268
- onchange={(e) => ctrl.setFullRowDraft(column.id, e.currentTarget.value)}
269
- onkeydown={fullRowKeydown}
270
- onpointerdown={(e) => e.stopPropagation()}
271
- onclick={(e) => e.stopPropagation()}
272
- >
273
- {#each opts as o (optionValueOf(o))}
274
- <option value={optionValueOf(o)}>{optionLabelOf(o)}</option>
275
- {/each}
276
- </select>
277
- {:else}
278
- {@const inputType =
279
- et === "number"
280
- ? "number"
281
- : et === "date"
282
- ? "date"
283
- : et === "datetime"
284
- ? "datetime-local"
285
- : et === "time"
286
- ? "time"
287
- : et === "password"
288
- ? "password"
289
- : "text"}
290
- <input
291
- type={inputType}
292
- class="sv-grid-cell-editor sv-grid-fr-editor"
293
- value={String(val ?? "")}
294
- oninput={(e) => ctrl.setFullRowDraft(column.id, e.currentTarget.value)}
295
- onkeydown={fullRowKeydown}
296
- onpointerdown={(e) => e.stopPropagation()}
297
- onclick={(e) => e.stopPropagation()}
298
- />
299
- {/if}
300
- {:else}
301
- {#if column.columnDef.cellEditor}
302
- <!-- Custom editor slot. The columnDef provides a snippet that
303
- receives the editor context (value + commit + cancel) so the
304
- consumer fully owns the in-cell UI. -->
305
- {@const customEditor = column.columnDef
306
- .cellEditor as unknown as import("svelte").Snippet<
307
- [EditorContext<TData>]
308
- >}
309
- {@render customEditor({
310
- cell: row.getAllCells().find((c) => c.column.id === column.id)!,
311
- row,
312
- column,
313
- table: grid,
314
- getValue: () => ctrl.editingCell?.value,
315
- value: ctrl.editingCell?.value,
316
- update: (next: unknown) => {
317
- // Stage the draft without closing. Live-preview controls
318
- // (sliders, color pickers) call this on every input tick.
319
- ctrl.editingCell = ctrl.editingCell
320
- ? { ...ctrl.editingCell, value: next }
321
- : ctrl.editingCell;
322
- },
323
- commit: (next?: unknown) => {
324
- // Write + close. If the caller passed a value, stage it
325
- // first; otherwise save whatever update() last wrote.
326
- if (next !== undefined) {
327
- ctrl.editingCell = ctrl.editingCell
328
- ? { ...ctrl.editingCell, value: next }
329
- : ctrl.editingCell;
330
- }
331
- saveEditingCell();
332
- },
333
- cancel: () => {
334
- ctrl.editingCell = null;
335
- ctrl.gridRootEl?.focus({ preventScroll: true });
336
- },
337
- })}
338
- {:else if ctrl.editingCell?.editorType === "checkbox"}
339
- <button
340
- type="button"
341
- class="sv-grid-checkbox"
342
- role="checkbox"
343
- aria-checked={Boolean(ctrl.editingCell.value)}
344
- aria-label="Edit checkbox value"
345
- onclick={(event) => {
346
- event.stopPropagation();
347
- const nextValue = !ctrl.editingCell?.value;
348
- ctrl.editingCell = ctrl.editingCell
349
- ? { ...ctrl.editingCell, value: nextValue }
350
- : ctrl.editingCell;
351
- saveEditingCell();
352
- }}
353
- onkeydown={(event) =>
354
- toggleCheckboxWithKeyboard(event, () => {
355
- event.stopPropagation();
356
- const nextValue = !ctrl.editingCell?.value;
357
- ctrl.editingCell = ctrl.editingCell
358
- ? { ...ctrl.editingCell, value: nextValue }
359
- : ctrl.editingCell;
360
- saveEditingCell();
361
- })}
362
- onblur={() => saveEditingCell()}
363
- ></button>
364
- {:else if ctrl.editingCell?.editorType === "list"}
365
- {@const opts = getColumnEditorOptions(column, row)}
366
- {@const optsLoading = areEditorOptionsLoading(column, row)}
367
- {@const multi = column.columnDef.editorMultiple === true}
368
- {#if DropdownEditor}
369
- <DropdownEditor
370
- options={opts}
371
- loading={optsLoading}
372
- value={ctrl.editingCell?.value}
373
- multiple={multi}
374
- placeholder="Select…"
375
- onChange={(next) => {
376
- ctrl.editingCell = ctrl.editingCell
377
- ? { ...ctrl.editingCell, value: next }
378
- : ctrl.editingCell;
379
- }}
380
- onCommit={() => saveEditingCell()}
381
- onCancel={() => {
382
- ctrl.editingCell = null;
383
- ctrl.gridRootEl?.focus({ preventScroll: true });
384
- }}
385
- />
386
- {/if}
387
- {:else if ctrl.editingCell?.editorType === "chips"}
388
- {@const opts = getColumnEditorOptions(column, row)}
389
- {@const optsLoading = areEditorOptionsLoading(column, row)}
390
- {@const multi = column.columnDef.editorMultiple === true}
391
- {@const selectedArr = toValueArray(ctrl.editingCell?.value)}
392
- {@render chipsEditor(opts, multi, selectedArr, optsLoading)}
393
- {:else if ctrl.editingCell?.editorType === "rating"}
394
- {@const ratingVal = Math.max(
395
- 0,
396
- Math.min(5, Math.round(Number(ctrl.editingCell?.value) || 0)),
397
- )}
398
- <span class="sv-grid-rating-editor" role="radiogroup" aria-label="Rating">
399
- {#each [1, 2, 3, 4, 5] as n (n)}
400
- <button
401
- type="button"
402
- role="radio"
403
- aria-checked={ratingVal >= n}
404
- aria-label={`${n} ${n === 1 ? "star" : "stars"}`}
405
- class={`sv-grid-rating-star ${ratingVal >= n ? "sv-grid-rating-star-on" : ""}`}
406
- onmousedown={(event) => event.preventDefault()}
407
- onclick={(event) => {
408
- event.stopPropagation();
409
- ctrl.editingCell = ctrl.editingCell
410
- ? { ...ctrl.editingCell, value: n }
411
- : ctrl.editingCell;
412
- saveEditingCell();
413
- }}
414
- onkeydown={onEditorKeyDown}>★</button
415
- >
416
- {/each}
417
- <button
418
- type="button"
419
- aria-label="Clear rating"
420
- class="sv-grid-rating-clear"
421
- onmousedown={(event) => event.preventDefault()}
422
- onclick={(event) => {
423
- event.stopPropagation();
424
- ctrl.editingCell = ctrl.editingCell
425
- ? { ...ctrl.editingCell, value: 0 }
426
- : ctrl.editingCell;
427
- saveEditingCell();
428
- }}>×</button
429
- >
430
- </span>
431
- {:else if ctrl.editingCell?.editorType === "select"}
432
- <!-- Custom dropdown: opens a themed popover identical in feel to
433
- the existing 'list' editor (single-select, no typeahead). -->
434
- {@const selectOpts = getColumnEditorOptions(column, row)}
435
- {@const optsLoading = areEditorOptionsLoading(column, row)}
436
- {#if DropdownEditor}
437
- <DropdownEditor
438
- options={selectOpts}
439
- loading={optsLoading}
440
- value={ctrl.editingCell?.value}
441
- multiple={false}
442
- placeholder="Select…"
443
- onChange={(next) => {
444
- ctrl.editingCell = ctrl.editingCell
445
- ? { ...ctrl.editingCell, value: next }
446
- : ctrl.editingCell;
447
- }}
448
- onCommit={() => saveEditingCell()}
449
- onCancel={() => {
450
- ctrl.editingCell = null;
451
- ctrl.gridRootEl?.focus({ preventScroll: true });
452
- }}
453
- />
454
- {/if}
455
- {:else if ctrl.editingCell?.editorType === "rich-select"}
456
- <!-- Searchable combobox: same popover as 'select' with a
457
- typeahead filter input baked in at the top. -->
458
- {@const richOpts = getColumnEditorOptions(column, row)}
459
- {@const optsLoading = areEditorOptionsLoading(column, row)}
460
- {#if DropdownEditor}
461
- <DropdownEditor
462
- options={richOpts}
463
- loading={optsLoading}
464
- value={ctrl.editingCell?.value}
465
- multiple={false}
466
- searchable={true}
467
- placeholder="Search…"
468
- onChange={(next) => {
469
- ctrl.editingCell = ctrl.editingCell
470
- ? { ...ctrl.editingCell, value: next }
471
- : ctrl.editingCell;
472
- }}
473
- onCommit={() => saveEditingCell()}
474
- onCancel={() => {
475
- ctrl.editingCell = null;
476
- ctrl.gridRootEl?.focus({ preventScroll: true });
477
- }}
478
- />
479
- {/if}
480
- {:else if ctrl.editingCell?.editorType === "textarea"}
481
- <!-- Multi-line editor. Commits on Tab, Ctrl/Cmd+Enter, or blur.
482
- Plain Enter inserts a newline (the whole point of textarea).
483
- Esc cancels. -->
484
- <textarea
485
- use:focusOnMount
486
- class="sv-grid-cell-editor sv-grid-cell-editor-textarea"
487
- rows="4"
488
- value={String(ctrl.editingCell?.value ?? "")}
489
- onpointerdown={(event) => event.stopPropagation()}
490
- oninput={(event) =>
491
- updateEditingCellValue(
492
- (event.currentTarget as HTMLTextAreaElement).value,
493
- )}
494
- onkeydown={(event) => {
495
- event.stopPropagation();
496
- if (event.key === "Escape") {
497
- event.preventDefault();
498
- ctrl.editingCell = null;
499
- ctrl.gridRootEl?.focus({ preventScroll: true });
500
- return;
501
- }
502
- // Tab and Ctrl/Cmd+Enter both commit. Plain Enter inserts a newline.
503
- // Tab goes through the shared helper so it advances the active cell
504
- // like every other editor does (#48).
505
- if (event.key === "Tab") {
506
- event.preventDefault();
507
- ctrl.commitAndMoveByTab(event.shiftKey);
508
- return;
509
- }
510
- if (event.key === "Enter" && (event.ctrlKey || event.metaKey)) {
511
- event.preventDefault();
512
- saveEditingCell();
513
- ctrl.gridRootEl?.focus({ preventScroll: true });
514
- }
515
- }}
516
- onblur={() => saveEditingCell()}
517
- ></textarea>
518
- {:else if ctrl.editingCell?.editorType === "autocomplete"}
519
- <!-- Free-text autocomplete: a text input with a live-filtered
520
- suggestion list. Typing edits the value freely; clicking a
521
- suggestion (or blur) commits. Accepts values not in the list. -->
522
- {@const acOpts = getColumnEditorOptions(column, row)}
523
- {@const acText = String(ctrl.editingCell?.value ?? "")}
524
- {@const acFiltered = acText.trim()
525
- ? acOpts.filter((o) =>
526
- String(o.label).toLowerCase().includes(acText.toLowerCase()),
527
- )
528
- : acOpts}
529
- <div class="sv-grid-autocomplete">
530
- <input
531
- use:focusOnMount
532
- class="sv-grid-cell-editor sv-grid-cell-editor-autocomplete"
533
- type="text"
534
- value={acText}
535
- onpointerdown={(event) => event.stopPropagation()}
536
- oninput={(event) =>
537
- updateEditingCellValue(
538
- (event.currentTarget as HTMLInputElement).value,
539
- )}
540
- onblur={() => saveEditingCell()}
541
- onkeydown={onEditorKeyDown}
542
- />
543
- {#if acFiltered.length > 0}
544
- <div class="sv-grid-autocomplete-list" role="listbox">
545
- {#each acFiltered.slice(0, 50) as opt (opt.value)}
546
- <button
547
- type="button"
548
- class="sv-grid-autocomplete-option"
549
- role="option"
550
- aria-selected={String(opt.value) === acText}
551
- onmousedown={(event) => {
552
- event.preventDefault();
553
- ctrl.editingCell = ctrl.editingCell
554
- ? { ...ctrl.editingCell, value: opt.value }
555
- : ctrl.editingCell;
556
- saveEditingCell();
557
- }}>{opt.label}</button
558
- >
559
- {/each}
560
- </div>
561
- {/if}
562
- </div>
563
- {:else if ctrl.editingCell?.editorType === "date"}
564
- <!-- Rich date editor: SvCalendar popover over a formatted input. Opts
565
- out to the native <input type="date"> via editorType 'date-native'. -->
566
- {#if DateEditor}
567
- <DateEditor
568
- value={ctrl.editingCell?.value as string | number | Date | null}
569
- formatString="yyyy-MM-dd"
570
- dropDownDisplayMode="calendar"
571
- autoOpen
572
- block
573
- onChange={(d) => updateEditingCellValue(d)}
574
- onCommit={() => saveEditingCell()}
575
- onCancel={() => {
576
- ctrl.editingCell = null;
577
- ctrl.gridRootEl?.focus({ preventScroll: true });
578
- }}
579
- />
580
- {/if}
581
- {:else if ctrl.editingCell?.editorType === "datetime"}
582
- {#if DateEditor}
583
- <DateEditor
584
- value={ctrl.editingCell?.value as string | number | Date | null}
585
- formatString="yyyy-MM-dd HH:mm"
586
- dropDownDisplayMode="both"
587
- autoOpen
588
- block
589
- onChange={(d) => updateEditingCellValue(d)}
590
- onCommit={() => saveEditingCell()}
591
- onCancel={() => {
592
- ctrl.editingCell = null;
593
- ctrl.gridRootEl?.focus({ preventScroll: true });
594
- }}
595
- />
596
- {/if}
597
- {:else if ctrl.editingCell?.editorType === "time"}
598
- <!-- Rich time editor: SvTimePicker dial. Stores the 'HH:MM' string the
599
- `time` parser expects; opts out via editorType 'time-native'. -->
600
- {#if DateEditor}
601
- <DateEditor
602
- value={timeStringToDate(ctrl.editingCell?.value)}
603
- formatString="HH:mm"
604
- dropDownDisplayMode="time"
605
- autoOpen
606
- block
607
- onChange={(d) => updateEditingCellValue(dateToTimeString(d))}
608
- onCommit={() => saveEditingCell()}
609
- onCancel={() => {
610
- ctrl.editingCell = null;
611
- ctrl.gridRootEl?.focus({ preventScroll: true });
612
- }}
613
- />
614
- {/if}
615
- {:else if ctrl.editingCell?.editorType === "color"}
616
- <!-- Native <input type="color"> opens its picker in a separate OS
617
- overlay; once the picker closes, focus stays on the input so
618
- `blur` never fires on its own. Commit on `change` (which fires
619
- exactly once when the picker is dismissed) so the chosen color
620
- is saved without needing the user to click elsewhere. -->
621
- <input
622
- use:focusOnMount
623
- class={getEditorClass("color")}
624
- type="color"
625
- value={getEditableInputValue("color", ctrl.editingCell?.value)}
626
- oninput={(event) =>
627
- updateEditingCellValue(
628
- (event.currentTarget as HTMLInputElement).value,
629
- )}
630
- onchange={(event) => {
631
- updateEditingCellValue(
632
- (event.currentTarget as HTMLInputElement).value,
633
- );
634
- saveEditingCell();
635
- }}
636
- onblur={() => saveEditingCell()}
637
- onkeydown={onEditorKeyDown}
638
- />
639
- {:else if hasCellEditor(String(ctrl.editingCell?.editorType ?? ""))}
640
- <!-- Custom editor registered via `registerCellEditor(type, Component)`:
641
- mount it and hand it the uniform change / commit / cancel context. -->
642
- {@const _reg = getCellEditor(String(ctrl.editingCell?.editorType))!}
643
- {@const CustomCellEditor = _reg.component}
644
- <CustomCellEditor {...resolveEditorProps(_reg, buildRegisteredEditorContext())} />
645
- {:else}
646
- <input
647
- use:focusOnMount
648
- class={getEditorClass(ctrl.editingCell?.editorType ?? "text")}
649
- type={getEditorInputType(ctrl.editingCell?.editorType ?? "text")}
650
- value={getEditableInputValue(
651
- ctrl.editingCell?.editorType ?? "text",
652
- ctrl.editingCell?.value,
653
- )}
654
- oninput={(event) =>
655
- updateEditingCellValue(
656
- (event.currentTarget as HTMLInputElement).value,
657
- )}
658
- onblur={() => saveEditingCell()}
659
- onkeydown={onEditorKeyDown}
660
- />
661
- {/if}
662
- {/if}
1
+ <script lang="ts" generics="TFeatures extends TableFeatures = TableFeatures, TData extends RowData = RowData">
2
+ /**
3
+ * The in-cell and full-row editor UI, lifted out of SvGrid.svelte.
4
+ *
5
+ * Editing is off by default (`editable` / `enableInlineEditing` both default
6
+ * to false) and this markup only ever renders while a cell is actually being
7
+ * edited, so it has no business sitting in the base bundle. SvGrid.svelte
8
+ * loads it with `import()` the moment editing is enabled - well before any
9
+ * double-click can happen - so behaviour is unchanged either way.
10
+ *
11
+ * Keep `SvGridDropdown` and `SvDateTimePicker` DYNAMIC below. Importing
12
+ * either statically would drag ~22 KB into this chunk for every text edit,
13
+ * and a static import from anywhere reachable by SvGrid.svelte has silently
14
+ * defeated a lazy boundary in this codebase before.
15
+ */
16
+ import {
17
+ type CellEditorOption,
18
+ type Column,
19
+ type EditorContext,
20
+ type Row,
21
+ type RowData,
22
+ type TableFeatures,
23
+ } from "./index";
24
+ import {
25
+ dateToTimeString,
26
+ getEditableInputValue,
27
+ getEditorClass,
28
+ getEditorInputType,
29
+ getCellEditorInputType,
30
+ isNumericEditorInput,
31
+ timeStringToDate,
32
+ toValueArray,
33
+ } from "./SvGrid.helpers";
34
+ import {
35
+ getCellEditor,
36
+ hasCellEditor,
37
+ resolveEditorProps,
38
+ type CellEditorContext,
39
+ } from "./editor-registry";
40
+ import type { SvGridController } from "./SvGrid.controller.svelte";
41
+
42
+ let {
43
+ ctrl,
44
+ column,
45
+ row,
46
+ fullRow = false,
47
+ }: {
48
+ ctrl: SvGridController<TFeatures, TData>;
49
+ column: Column<TData>;
50
+ row: Row<TData>;
51
+ /** Render the full-row editor for this cell instead of the single-cell one. */
52
+ fullRow?: boolean;
53
+ } = $props();
54
+
55
+ // Heavy editors stay behind their own `import()` so a text edit never pays
56
+ // for the dropdown or the date picker.
57
+ let DropdownEditor = $state<typeof import("./SvGridDropdown.svelte").default | null>(null);
58
+ let DateEditor = $state<typeof import("./SvDateTimePicker.svelte").default | null>(null);
59
+ $effect(() => {
60
+ const t = ctrl.editingCell?.editorType;
61
+ if (
62
+ (t === "list" || t === "chips" || t === "select" || t === "rich-select") &&
63
+ !DropdownEditor
64
+ )
65
+ import("./SvGridDropdown.svelte").then((m) => (DropdownEditor = m.default));
66
+ if ((t === "date" || t === "datetime" || t === "time") && !DateEditor)
67
+ import("./SvDateTimePicker.svelte").then((m) => (DateEditor = m.default));
68
+ });
69
+
70
+ const grid = $derived(ctrl.grid);
71
+ const fullRowEdit = $derived(ctrl.fullRowEdit);
72
+ const getColumnEditorOptions = $derived(ctrl.getColumnEditorOptions);
73
+ const areEditorOptionsLoading = $derived(ctrl.areEditorOptionsLoading);
74
+ const saveEditingCell = $derived(ctrl.saveEditingCell);
75
+ const updateEditingCellValue = $derived(ctrl.updateEditingCellValue);
76
+ const onEditorKeyDown = $derived(ctrl.onEditorKeyDown);
77
+ const focusOnMount = $derived(ctrl.focusOnMount);
78
+ const toggleCheckboxWithKeyboard = $derived(ctrl.toggleCheckboxWithKeyboard);
79
+
80
+ /**
81
+ * Focus a button-based editor on mount. `focusOnMount` is for text controls -
82
+ * it also places the caret - and the checkbox and rating editors, being
83
+ * <button>s, had no equivalent and so never took focus at all. Their own key
84
+ * handlers therefore never fired: neither could be operated from the
85
+ * keyboard, and Escape never reached them, so the cell stayed stuck in edit
86
+ * mode until the user clicked somewhere else.
87
+ *
88
+ * `enabled` lets a group of buttons (the rating stars) pick which one holds
89
+ * focus, since an action cannot be applied conditionally.
90
+ */
91
+ function focusControlOnMount(node: HTMLElement, enabled: boolean = true) {
92
+ if (!enabled) return;
93
+ requestAnimationFrame(() => node.focus({ preventScroll: true }));
94
+ }
95
+
96
+ function fullRowKeydown(e: KeyboardEvent) {
97
+ if (e.key === "Enter") {
98
+ e.preventDefault();
99
+ ctrl.commitFullRowEdit();
100
+ ctrl.gridRootEl?.focus({ preventScroll: true });
101
+ } else if (e.key === "Escape") {
102
+ e.preventDefault();
103
+ ctrl.cancelFullRowEdit();
104
+ ctrl.gridRootEl?.focus({ preventScroll: true });
105
+ }
106
+ }
107
+ function optionValueOf(o: unknown): string {
108
+ return typeof o === "object" && o !== null && "value" in o
109
+ ? String((o as { value: unknown }).value)
110
+ : String(o);
111
+ }
112
+ function optionLabelOf(o: unknown): string {
113
+ return typeof o === "object" && o !== null && "label" in o
114
+ ? String((o as { label: unknown }).label)
115
+ : String(o);
116
+ }
117
+
118
+ // Build the interaction context handed to a CUSTOM cell editor registered via
119
+ // `registerCellEditor`. Maps the grid's editing lifecycle onto the uniform
120
+ // change / commit / cancel contract every registered editor speaks.
121
+ function buildRegisteredEditorContext(): CellEditorContext {
122
+ const cell = ctrl.editingCell;
123
+ return {
124
+ value: cell?.value,
125
+ rowId: cell?.rowId ?? "",
126
+ columnId: cell?.columnId ?? "",
127
+ onChange: (v: unknown) => updateEditingCellValue(v),
128
+ onCommit: (v?: unknown) => {
129
+ if (v !== undefined) updateEditingCellValue(v);
130
+ saveEditingCell();
131
+ },
132
+ onCancel: () => {
133
+ ctrl.editingCell = null;
134
+ ctrl.gridRootEl?.focus({ preventScroll: true });
135
+ },
136
+ // Tab out of an editor: commit, then step to the adjacent cell. Without
137
+ // this a registered editor's Tab walks focus out of the grid (#48) - the
138
+ // built-in editors already route through the same helper.
139
+ onCommitAndMove: (v: unknown, direction: 1 | -1) => {
140
+ if (v !== undefined) updateEditingCellValue(v);
141
+ ctrl.commitAndMoveByTab(direction === -1);
142
+ },
143
+ // Close a popover editor without committing. Same effect as cancel today;
144
+ // named separately so an editor can distinguish "dismiss my panel" from
145
+ // "abandon the edit" if that ever diverges.
146
+ onRequestClose: () => {
147
+ ctrl.editingCell = null;
148
+ ctrl.gridRootEl?.focus({ preventScroll: true });
149
+ },
150
+ inCell: true,
151
+ };
152
+ }
153
+ </script>
154
+
155
+ {#snippet chipsEditor(
156
+ opts: CellEditorOption[],
157
+ multi: boolean,
158
+ selectedArr: Array<string | number>,
159
+ optsLoading: boolean,
160
+ )}
161
+ {#if opts.length > 0}
162
+ <!-- Options-driven chips editor: defer to the custom dropdown,
163
+ which renders the selected values as chips in its trigger and
164
+ pops out a styled listbox. Identical UX to the list editor
165
+ with renderChipsInTrigger flipped on. -->
166
+ {#if DropdownEditor}
167
+ <DropdownEditor
168
+ options={opts}
169
+ loading={optsLoading}
170
+ value={ctrl.editingCell?.value}
171
+ multiple={multi}
172
+ placeholder="Pick…"
173
+ renderChipsInTrigger={true}
174
+ onChange={(next) => {
175
+ ctrl.editingCell = ctrl.editingCell
176
+ ? { ...ctrl.editingCell, value: next }
177
+ : ctrl.editingCell;
178
+ }}
179
+ onCommit={() => saveEditingCell()}
180
+ onCancel={() => {
181
+ ctrl.editingCell = null;
182
+ ctrl.gridRootEl?.focus({ preventScroll: true });
183
+ }}
184
+ />
185
+ {/if}
186
+ {:else}
187
+ <!-- Free-form chips: typed tags. Enter / comma commits a chip,
188
+ Backspace on empty input removes the last chip, blur saves. -->
189
+ <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
190
+ <div
191
+ class="sv-grid-cell-editor sv-grid-cell-editor-chips"
192
+ role="group"
193
+ tabindex={-1}
194
+ >
195
+ <div class="sv-grid-chips-row">
196
+ {#each selectedArr as v, idx (String(v) + "_" + idx)}
197
+ <span class="sv-grid-chip sv-grid-chip-removable">
198
+ {String(v)}
199
+ <button
200
+ type="button"
201
+ class="sv-grid-chip-remove"
202
+ aria-label="Remove {String(v)}"
203
+ onmousedown={(event) => event.preventDefault()}
204
+ onclick={() => {
205
+ const next = selectedArr.filter((_, i) => i !== idx);
206
+ ctrl.editingCell = ctrl.editingCell
207
+ ? {
208
+ ...ctrl.editingCell,
209
+ value: multi ? next : (next[0] ?? null),
210
+ }
211
+ : ctrl.editingCell;
212
+ }}>×</button
213
+ >
214
+ </span>
215
+ {/each}
216
+ <input
217
+ use:focusOnMount
218
+ class="sv-grid-chip-input"
219
+ type="text"
220
+ placeholder={multi ? "Type, Enter to add" : "Type a value"}
221
+ onkeydown={(event) => {
222
+ if (event.key === "Enter" || (multi && event.key === ",")) {
223
+ event.preventDefault();
224
+ event.stopPropagation();
225
+ const input = event.currentTarget as HTMLInputElement;
226
+ const raw = input.value.trim();
227
+ if (raw) {
228
+ const next = multi ? [...selectedArr, raw] : [raw];
229
+ ctrl.editingCell = ctrl.editingCell
230
+ ? { ...ctrl.editingCell, value: multi ? next : raw }
231
+ : ctrl.editingCell;
232
+ input.value = "";
233
+ if (!multi) saveEditingCell();
234
+ }
235
+ } else if (event.key === "Escape") {
236
+ onEditorKeyDown(event);
237
+ } else if (event.key === "Backspace") {
238
+ const input = event.currentTarget as HTMLInputElement;
239
+ if (input.value === "" && selectedArr.length > 0) {
240
+ event.preventDefault();
241
+ const next = selectedArr.slice(0, -1);
242
+ ctrl.editingCell = ctrl.editingCell
243
+ ? {
244
+ ...ctrl.editingCell,
245
+ value: multi ? next : (next[0] ?? null),
246
+ }
247
+ : ctrl.editingCell;
248
+ }
249
+ }
250
+ }}
251
+ onblur={() => saveEditingCell()}
252
+ />
253
+ {#if multi}
254
+ <button
255
+ type="button"
256
+ class="sv-grid-chip-commit"
257
+ onmousedown={(event) => event.preventDefault()}
258
+ onclick={() => saveEditingCell()}
259
+ aria-label="Commit chip selection">Done</button
260
+ >
261
+ {/if}
262
+ </div>
263
+ </div>
264
+ {/if}
265
+ {/snippet}
266
+
267
+ {#if fullRow}
268
+ {@const et = column.columnDef.editorType ?? "text"}
269
+ {@const val = fullRowEdit?.draft[column.id]}
270
+ {#if et === "checkbox"}
271
+ <input
272
+ type="checkbox"
273
+ class="sv-grid-fr-editor sv-grid-fr-checkbox"
274
+ checked={Boolean(val)}
275
+ onchange={(e) =>
276
+ ctrl.setFullRowDraft(column.id, e.currentTarget.checked)}
277
+ onkeydown={fullRowKeydown}
278
+ onpointerdown={(e) => e.stopPropagation()}
279
+ onclick={(e) => e.stopPropagation()}
280
+ />
281
+ {:else if et === "list" || et === "select" || et === "rich-select"}
282
+ {@const opts = getColumnEditorOptions(column, row)}
283
+ <select
284
+ class="sv-grid-cell-editor sv-grid-fr-editor"
285
+ value={String(val ?? "")}
286
+ onchange={(e) => ctrl.setFullRowDraft(column.id, e.currentTarget.value)}
287
+ onkeydown={fullRowKeydown}
288
+ onpointerdown={(e) => e.stopPropagation()}
289
+ onclick={(e) => e.stopPropagation()}
290
+ >
291
+ {#each opts as o (optionValueOf(o))}
292
+ <option value={optionValueOf(o)}>{optionLabelOf(o)}</option>
293
+ {/each}
294
+ </select>
295
+ {:else}
296
+ {@const inputType =
297
+ et === "number"
298
+ ? "number"
299
+ : et === "date"
300
+ ? "date"
301
+ : et === "datetime"
302
+ ? "datetime-local"
303
+ : et === "time"
304
+ ? "time"
305
+ : et === "password"
306
+ ? "password"
307
+ : "text"}
308
+ <input
309
+ type={inputType}
310
+ class="sv-grid-cell-editor sv-grid-fr-editor"
311
+ value={String(val ?? "")}
312
+ oninput={(e) => ctrl.setFullRowDraft(column.id, e.currentTarget.value)}
313
+ onkeydown={fullRowKeydown}
314
+ onpointerdown={(e) => e.stopPropagation()}
315
+ onclick={(e) => e.stopPropagation()}
316
+ />
317
+ {/if}
318
+ {:else}
319
+ {#if column.columnDef.cellEditor}
320
+ <!-- Custom editor slot. The columnDef provides a snippet that
321
+ receives the editor context (value + commit + cancel) so the
322
+ consumer fully owns the in-cell UI. -->
323
+ {@const customEditor = column.columnDef
324
+ .cellEditor as unknown as import("svelte").Snippet<
325
+ [EditorContext<TData>]
326
+ >}
327
+ {@render customEditor({
328
+ cell: row.getAllCells().find((c) => c.column.id === column.id)!,
329
+ row,
330
+ column,
331
+ table: grid,
332
+ getValue: () => ctrl.editingCell?.value,
333
+ value: ctrl.editingCell?.value,
334
+ update: (next: unknown) => {
335
+ // Stage the draft without closing. Live-preview controls
336
+ // (sliders, color pickers) call this on every input tick.
337
+ ctrl.editingCell = ctrl.editingCell
338
+ ? { ...ctrl.editingCell, value: next }
339
+ : ctrl.editingCell;
340
+ },
341
+ commit: (next?: unknown) => {
342
+ // Write + close. If the caller passed a value, stage it
343
+ // first; otherwise save whatever update() last wrote.
344
+ if (next !== undefined) {
345
+ ctrl.editingCell = ctrl.editingCell
346
+ ? { ...ctrl.editingCell, value: next }
347
+ : ctrl.editingCell;
348
+ }
349
+ saveEditingCell();
350
+ },
351
+ cancel: () => {
352
+ ctrl.editingCell = null;
353
+ ctrl.gridRootEl?.focus({ preventScroll: true });
354
+ },
355
+ })}
356
+ {:else if ctrl.editingCell?.editorType === "checkbox"}
357
+ <button
358
+ use:focusControlOnMount
359
+ type="button"
360
+ class="sv-grid-checkbox"
361
+ role="checkbox"
362
+ aria-checked={Boolean(ctrl.editingCell.value)}
363
+ aria-label="Edit checkbox value"
364
+ onclick={(event) => {
365
+ event.stopPropagation();
366
+ const nextValue = !ctrl.editingCell?.value;
367
+ ctrl.editingCell = ctrl.editingCell
368
+ ? { ...ctrl.editingCell, value: nextValue }
369
+ : ctrl.editingCell;
370
+ saveEditingCell();
371
+ }}
372
+ onkeydown={(event) => {
373
+ // Enter / Space are the checkbox's own activation keys. Everything
374
+ // else - Escape to cancel, Tab to commit and move on - goes to the
375
+ // shared editor handler, which this editor used to bypass entirely.
376
+ if (event.key === "Enter" || event.key === " ") {
377
+ toggleCheckboxWithKeyboard(event, () => {
378
+ event.stopPropagation();
379
+ const nextValue = !ctrl.editingCell?.value;
380
+ ctrl.editingCell = ctrl.editingCell
381
+ ? { ...ctrl.editingCell, value: nextValue }
382
+ : ctrl.editingCell;
383
+ saveEditingCell();
384
+ });
385
+ return;
386
+ }
387
+ onEditorKeyDown(event);
388
+ }}
389
+ onblur={() => saveEditingCell()}
390
+ ></button>
391
+ {:else if ctrl.editingCell?.editorType === "list"}
392
+ {@const opts = getColumnEditorOptions(column, row)}
393
+ {@const optsLoading = areEditorOptionsLoading(column, row)}
394
+ {@const multi = column.columnDef.editorMultiple === true}
395
+ {#if DropdownEditor}
396
+ <DropdownEditor
397
+ options={opts}
398
+ loading={optsLoading}
399
+ value={ctrl.editingCell?.value}
400
+ multiple={multi}
401
+ placeholder="Select…"
402
+ onChange={(next) => {
403
+ ctrl.editingCell = ctrl.editingCell
404
+ ? { ...ctrl.editingCell, value: next }
405
+ : ctrl.editingCell;
406
+ }}
407
+ onCommit={() => saveEditingCell()}
408
+ onCancel={() => {
409
+ ctrl.editingCell = null;
410
+ ctrl.gridRootEl?.focus({ preventScroll: true });
411
+ }}
412
+ />
413
+ {/if}
414
+ {:else if ctrl.editingCell?.editorType === "chips"}
415
+ {@const opts = getColumnEditorOptions(column, row)}
416
+ {@const optsLoading = areEditorOptionsLoading(column, row)}
417
+ {@const multi = column.columnDef.editorMultiple === true}
418
+ {@const selectedArr = toValueArray(ctrl.editingCell?.value)}
419
+ {@render chipsEditor(opts, multi, selectedArr, optsLoading)}
420
+ {:else if ctrl.editingCell?.editorType === "rating"}
421
+ {@const ratingVal = Math.max(
422
+ 0,
423
+ Math.min(5, Math.round(Number(ctrl.editingCell?.value) || 0)),
424
+ )}
425
+ <!-- Focus the star for the current rating (the first one when unrated),
426
+ the radio a radiogroup is expected to enter on. Without it nothing
427
+ in this editor held focus, so `onEditorKeyDown` below never ran and
428
+ Escape could not close the cell. -->
429
+ {@const focusStar = Math.min(5, Math.max(1, ratingVal))}
430
+ <span class="sv-grid-rating-editor" role="radiogroup" aria-label="Rating">
431
+ {#each [1, 2, 3, 4, 5] as n (n)}
432
+ <button
433
+ use:focusControlOnMount={n === focusStar}
434
+ type="button"
435
+ role="radio"
436
+ aria-checked={ratingVal >= n}
437
+ aria-label={`${n} ${n === 1 ? "star" : "stars"}`}
438
+ class={`sv-grid-rating-star ${ratingVal >= n ? "sv-grid-rating-star-on" : ""}`}
439
+ onmousedown={(event) => event.preventDefault()}
440
+ onclick={(event) => {
441
+ event.stopPropagation();
442
+ ctrl.editingCell = ctrl.editingCell
443
+ ? { ...ctrl.editingCell, value: n }
444
+ : ctrl.editingCell;
445
+ saveEditingCell();
446
+ }}
447
+ onkeydown={(event) => {
448
+ // Arrows move between the stars, the way a radiogroup is
449
+ // expected to work - without them the editor takes focus (see
450
+ // focusControlOnMount) but Space can only re-pick the star that
451
+ // already holds the value. Enter / Escape / Tab still fall
452
+ // through to the shared handler.
453
+ const key = event.key;
454
+ if (
455
+ key !== "ArrowLeft" &&
456
+ key !== "ArrowRight" &&
457
+ key !== "Home" &&
458
+ key !== "End"
459
+ ) {
460
+ onEditorKeyDown(event);
461
+ return;
462
+ }
463
+ event.preventDefault();
464
+ event.stopPropagation();
465
+ const current = Math.min(5, Math.max(1, ratingVal));
466
+ const next =
467
+ key === "Home"
468
+ ? 1
469
+ : key === "End"
470
+ ? 5
471
+ : key === "ArrowLeft"
472
+ ? Math.max(1, current - 1)
473
+ : Math.min(5, current + 1);
474
+ ctrl.editingCell = ctrl.editingCell
475
+ ? { ...ctrl.editingCell, value: next }
476
+ : ctrl.editingCell;
477
+ const stars = (
478
+ event.currentTarget as HTMLElement
479
+ ).parentElement?.querySelectorAll<HTMLElement>(
480
+ ".sv-grid-rating-star",
481
+ );
482
+ stars?.[next - 1]?.focus({ preventScroll: true });
483
+ }}>★</button
484
+ >
485
+ {/each}
486
+ <button
487
+ type="button"
488
+ aria-label="Clear rating"
489
+ class="sv-grid-rating-clear"
490
+ onmousedown={(event) => event.preventDefault()}
491
+ onclick={(event) => {
492
+ event.stopPropagation();
493
+ ctrl.editingCell = ctrl.editingCell
494
+ ? { ...ctrl.editingCell, value: 0 }
495
+ : ctrl.editingCell;
496
+ saveEditingCell();
497
+ }}>×</button
498
+ >
499
+ </span>
500
+ {:else if ctrl.editingCell?.editorType === "select"}
501
+ <!-- Custom dropdown: opens a themed popover identical in feel to
502
+ the existing 'list' editor (single-select, no typeahead). -->
503
+ {@const selectOpts = getColumnEditorOptions(column, row)}
504
+ {@const optsLoading = areEditorOptionsLoading(column, row)}
505
+ {#if DropdownEditor}
506
+ <DropdownEditor
507
+ options={selectOpts}
508
+ loading={optsLoading}
509
+ value={ctrl.editingCell?.value}
510
+ multiple={false}
511
+ placeholder="Select…"
512
+ onChange={(next) => {
513
+ ctrl.editingCell = ctrl.editingCell
514
+ ? { ...ctrl.editingCell, value: next }
515
+ : ctrl.editingCell;
516
+ }}
517
+ onCommit={() => saveEditingCell()}
518
+ onCancel={() => {
519
+ ctrl.editingCell = null;
520
+ ctrl.gridRootEl?.focus({ preventScroll: true });
521
+ }}
522
+ />
523
+ {/if}
524
+ {:else if ctrl.editingCell?.editorType === "rich-select"}
525
+ <!-- Searchable combobox: same popover as 'select' with a
526
+ typeahead filter input baked in at the top. -->
527
+ {@const richOpts = getColumnEditorOptions(column, row)}
528
+ {@const optsLoading = areEditorOptionsLoading(column, row)}
529
+ {#if DropdownEditor}
530
+ <DropdownEditor
531
+ options={richOpts}
532
+ loading={optsLoading}
533
+ value={ctrl.editingCell?.value}
534
+ multiple={false}
535
+ searchable={true}
536
+ placeholder="Search…"
537
+ onChange={(next) => {
538
+ ctrl.editingCell = ctrl.editingCell
539
+ ? { ...ctrl.editingCell, value: next }
540
+ : ctrl.editingCell;
541
+ }}
542
+ onCommit={() => saveEditingCell()}
543
+ onCancel={() => {
544
+ ctrl.editingCell = null;
545
+ ctrl.gridRootEl?.focus({ preventScroll: true });
546
+ }}
547
+ />
548
+ {/if}
549
+ {:else if ctrl.editingCell?.editorType === "textarea"}
550
+ <!-- Multi-line editor. Commits on Tab, Ctrl/Cmd+Enter, or blur.
551
+ Plain Enter inserts a newline (the whole point of textarea).
552
+ Esc cancels. -->
553
+ <textarea
554
+ use:focusOnMount
555
+ class="sv-grid-cell-editor sv-grid-cell-editor-textarea"
556
+ rows="4"
557
+ value={String(ctrl.editingCell?.value ?? "")}
558
+ onpointerdown={(event) => event.stopPropagation()}
559
+ oninput={(event) =>
560
+ updateEditingCellValue(
561
+ (event.currentTarget as HTMLTextAreaElement).value,
562
+ )}
563
+ onkeydown={(event) => {
564
+ event.stopPropagation();
565
+ if (event.key === "Escape") {
566
+ event.preventDefault();
567
+ ctrl.editingCell = null;
568
+ ctrl.gridRootEl?.focus({ preventScroll: true });
569
+ return;
570
+ }
571
+ // Tab and Ctrl/Cmd+Enter both commit. Plain Enter inserts a newline.
572
+ // Tab goes through the shared helper so it advances the active cell
573
+ // like every other editor does (#48).
574
+ if (event.key === "Tab") {
575
+ event.preventDefault();
576
+ ctrl.commitAndMoveByTab(event.shiftKey);
577
+ return;
578
+ }
579
+ if (event.key === "Enter" && (event.ctrlKey || event.metaKey)) {
580
+ event.preventDefault();
581
+ saveEditingCell();
582
+ ctrl.gridRootEl?.focus({ preventScroll: true });
583
+ }
584
+ }}
585
+ onblur={() => saveEditingCell()}
586
+ ></textarea>
587
+ {:else if ctrl.editingCell?.editorType === "autocomplete"}
588
+ <!-- Free-text autocomplete: a text input with a live-filtered
589
+ suggestion list. Typing edits the value freely; clicking a
590
+ suggestion (or blur) commits. Accepts values not in the list. -->
591
+ {@const acOpts = getColumnEditorOptions(column, row)}
592
+ {@const acText = String(ctrl.editingCell?.value ?? "")}
593
+ {@const acFiltered = acText.trim()
594
+ ? acOpts.filter((o) =>
595
+ String(o.label).toLowerCase().includes(acText.toLowerCase()),
596
+ )
597
+ : acOpts}
598
+ <div class="sv-grid-autocomplete">
599
+ <input
600
+ use:focusOnMount
601
+ class="sv-grid-cell-editor sv-grid-cell-editor-autocomplete"
602
+ type="text"
603
+ value={acText}
604
+ onpointerdown={(event) => event.stopPropagation()}
605
+ oninput={(event) =>
606
+ updateEditingCellValue(
607
+ (event.currentTarget as HTMLInputElement).value,
608
+ )}
609
+ onblur={() => saveEditingCell()}
610
+ onkeydown={onEditorKeyDown}
611
+ />
612
+ {#if acFiltered.length > 0}
613
+ <div class="sv-grid-autocomplete-list" role="listbox">
614
+ {#each acFiltered.slice(0, 50) as opt (opt.value)}
615
+ <button
616
+ type="button"
617
+ class="sv-grid-autocomplete-option"
618
+ role="option"
619
+ aria-selected={String(opt.value) === acText}
620
+ onmousedown={(event) => {
621
+ event.preventDefault();
622
+ ctrl.editingCell = ctrl.editingCell
623
+ ? { ...ctrl.editingCell, value: opt.value }
624
+ : ctrl.editingCell;
625
+ saveEditingCell();
626
+ }}>{opt.label}</button
627
+ >
628
+ {/each}
629
+ </div>
630
+ {/if}
631
+ </div>
632
+ {:else if ctrl.editingCell?.editorType === "date"}
633
+ <!-- Rich date editor: SvCalendar popover over a formatted input. Opts
634
+ out to the native <input type="date"> via editorType 'date-native'. -->
635
+ {#if DateEditor}
636
+ <DateEditor
637
+ value={ctrl.editingCell?.value as string | number | Date | null}
638
+ formatString="yyyy-MM-dd"
639
+ dropDownDisplayMode="calendar"
640
+ autoOpen
641
+ block
642
+ onChange={(d) => updateEditingCellValue(d)}
643
+ onCommit={() => saveEditingCell()}
644
+ onCancel={() => {
645
+ ctrl.editingCell = null;
646
+ ctrl.gridRootEl?.focus({ preventScroll: true });
647
+ }}
648
+ />
649
+ {/if}
650
+ {:else if ctrl.editingCell?.editorType === "datetime"}
651
+ {#if DateEditor}
652
+ <DateEditor
653
+ value={ctrl.editingCell?.value as string | number | Date | null}
654
+ formatString="yyyy-MM-dd HH:mm"
655
+ dropDownDisplayMode="both"
656
+ autoOpen
657
+ block
658
+ onChange={(d) => updateEditingCellValue(d)}
659
+ onCommit={() => saveEditingCell()}
660
+ onCancel={() => {
661
+ ctrl.editingCell = null;
662
+ ctrl.gridRootEl?.focus({ preventScroll: true });
663
+ }}
664
+ />
665
+ {/if}
666
+ {:else if ctrl.editingCell?.editorType === "time"}
667
+ <!-- Rich time editor: SvTimePicker dial. Stores the 'HH:MM' string the
668
+ `time` parser expects; opts out via editorType 'time-native'. -->
669
+ {#if DateEditor}
670
+ <DateEditor
671
+ value={timeStringToDate(ctrl.editingCell?.value)}
672
+ formatString="HH:mm"
673
+ dropDownDisplayMode="time"
674
+ autoOpen
675
+ block
676
+ onChange={(d) => updateEditingCellValue(dateToTimeString(d))}
677
+ onCommit={() => saveEditingCell()}
678
+ onCancel={() => {
679
+ ctrl.editingCell = null;
680
+ ctrl.gridRootEl?.focus({ preventScroll: true });
681
+ }}
682
+ />
683
+ {/if}
684
+ {:else if ctrl.editingCell?.editorType === "color"}
685
+ <!-- Native <input type="color"> opens its picker in a separate OS
686
+ overlay; once the picker closes, focus stays on the input so
687
+ `blur` never fires on its own. Commit on `change` (which fires
688
+ exactly once when the picker is dismissed) so the chosen color
689
+ is saved without needing the user to click elsewhere. -->
690
+ <input
691
+ use:focusOnMount
692
+ class={getEditorClass("color")}
693
+ type="color"
694
+ value={getEditableInputValue("color", ctrl.editingCell?.value)}
695
+ oninput={(event) =>
696
+ updateEditingCellValue(
697
+ (event.currentTarget as HTMLInputElement).value,
698
+ )}
699
+ onchange={(event) => {
700
+ updateEditingCellValue(
701
+ (event.currentTarget as HTMLInputElement).value,
702
+ );
703
+ saveEditingCell();
704
+ }}
705
+ onblur={() => saveEditingCell()}
706
+ onkeydown={onEditorKeyDown}
707
+ />
708
+ {:else if hasCellEditor(String(ctrl.editingCell?.editorType ?? ""))}
709
+ <!-- Custom editor registered via `registerCellEditor(type, Component)`:
710
+ mount it and hand it the uniform change / commit / cancel context. -->
711
+ {@const _reg = getCellEditor(String(ctrl.editingCell?.editorType))!}
712
+ {@const CustomCellEditor = _reg.component}
713
+ <CustomCellEditor {...resolveEditorProps(_reg, buildRegisteredEditorContext())} />
714
+ {:else}
715
+ {@const editorType = ctrl.editingCell?.editorType ?? "text"}
716
+ {@const isNumberEditor = getCellEditorInputType(editorType) === "text" &&
717
+ getEditorInputType(editorType) === "number"}
718
+ <input
719
+ use:focusOnMount
720
+ class={getEditorClass(editorType)}
721
+ type={getCellEditorInputType(editorType)}
722
+ inputmode={isNumberEditor ? "decimal" : undefined}
723
+ value={getEditableInputValue(
724
+ editorType,
725
+ ctrl.editingCell?.value,
726
+ )}
727
+ oninput={(event) => {
728
+ const input = event.currentTarget as HTMLInputElement;
729
+ // The number editor is a TEXT input so intermediate values survive
730
+ // (see getCellEditorInputType). That means nothing stops a letter
731
+ // being typed, which type="number" used to - so reject it here and
732
+ // put the last good draft back, rather than letting "12x" reach the
733
+ // commit and coerce to null.
734
+ if (isNumberEditor && !isNumericEditorInput(input.value)) {
735
+ input.value = String(ctrl.editingCell?.value ?? "");
736
+ return;
737
+ }
738
+ updateEditingCellValue(input.value);
739
+ }}
740
+ onblur={() => saveEditingCell()}
741
+ onkeydown={onEditorKeyDown}
742
+ />
743
+ {/if}
744
+ {/if}