@lushly-dev/violet-elements 0.0.0-stage → 0.2.0-preview.1

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 (426) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +262 -2
  3. package/custom-elements.json +42309 -0
  4. package/dist/accordion/violet-accordion.d.ts +24 -0
  5. package/dist/accordion/violet-accordion.js +133 -0
  6. package/dist/accordion/violet-accordion.js.map +1 -0
  7. package/dist/accordion-item/violet-accordion-item.d.ts +27 -0
  8. package/dist/accordion-item/violet-accordion-item.js +228 -0
  9. package/dist/accordion-item/violet-accordion-item.js.map +1 -0
  10. package/dist/alert/violet-alert.d.ts +44 -0
  11. package/dist/alert/violet-alert.js +346 -0
  12. package/dist/alert/violet-alert.js.map +1 -0
  13. package/dist/badge/violet-badge.d.ts +27 -0
  14. package/dist/badge/violet-badge.js +179 -0
  15. package/dist/badge/violet-badge.js.map +1 -0
  16. package/dist/breadcrumb/violet-breadcrumb.d.ts +20 -0
  17. package/dist/breadcrumb/violet-breadcrumb.js +88 -0
  18. package/dist/breadcrumb/violet-breadcrumb.js.map +1 -0
  19. package/dist/breadcrumb-item/violet-breadcrumb-item.d.ts +20 -0
  20. package/dist/breadcrumb-item/violet-breadcrumb-item.js +130 -0
  21. package/dist/breadcrumb-item/violet-breadcrumb-item.js.map +1 -0
  22. package/dist/button/violet-button.d.ts +76 -0
  23. package/dist/button/violet-button.js +281 -0
  24. package/dist/button/violet-button.js.map +1 -0
  25. package/dist/calendar/violet-calendar.d.ts +59 -0
  26. package/dist/calendar/violet-calendar.js +485 -0
  27. package/dist/calendar/violet-calendar.js.map +1 -0
  28. package/dist/card/violet-card.d.ts +30 -0
  29. package/dist/card/violet-card.js +249 -0
  30. package/dist/card/violet-card.js.map +1 -0
  31. package/dist/carousel/violet-carousel.d.ts +56 -0
  32. package/dist/carousel/violet-carousel.js +600 -0
  33. package/dist/carousel/violet-carousel.js.map +1 -0
  34. package/dist/checkbox/violet-checkbox.d.ts +82 -0
  35. package/dist/checkbox/violet-checkbox.js +465 -0
  36. package/dist/checkbox/violet-checkbox.js.map +1 -0
  37. package/dist/color-picker/violet-color-picker.d.ts +111 -0
  38. package/dist/color-picker/violet-color-picker.js +997 -0
  39. package/dist/color-picker/violet-color-picker.js.map +1 -0
  40. package/dist/color-picker/violet-color-utils.d.ts +21 -0
  41. package/dist/color-picker/violet-color-utils.js +126 -0
  42. package/dist/color-picker/violet-color-utils.js.map +1 -0
  43. package/dist/color-swatch/violet-color-swatch.d.ts +19 -0
  44. package/dist/color-swatch/violet-color-swatch.js +93 -0
  45. package/dist/color-swatch/violet-color-swatch.js.map +1 -0
  46. package/dist/combobox/violet-combobox.d.ts +86 -0
  47. package/dist/combobox/violet-combobox.js +669 -0
  48. package/dist/combobox/violet-combobox.js.map +1 -0
  49. package/dist/conversation/violet-approval-card.d.ts +34 -0
  50. package/dist/conversation/violet-approval-card.js +289 -0
  51. package/dist/conversation/violet-approval-card.js.map +1 -0
  52. package/dist/conversation/violet-chat-composer.d.ts +47 -0
  53. package/dist/conversation/violet-chat-composer.js +308 -0
  54. package/dist/conversation/violet-chat-composer.js.map +1 -0
  55. package/dist/conversation/violet-chat-suggestions.d.ts +21 -0
  56. package/dist/conversation/violet-chat-suggestions.js +159 -0
  57. package/dist/conversation/violet-chat-suggestions.js.map +1 -0
  58. package/dist/conversation/violet-conversation-thread.d.ts +26 -0
  59. package/dist/conversation/violet-conversation-thread.js +207 -0
  60. package/dist/conversation/violet-conversation-thread.js.map +1 -0
  61. package/dist/conversation/violet-message-media.d.ts +38 -0
  62. package/dist/conversation/violet-message-media.js +230 -0
  63. package/dist/conversation/violet-message-media.js.map +1 -0
  64. package/dist/conversation/violet-message-status.d.ts +17 -0
  65. package/dist/conversation/violet-message-status.js +168 -0
  66. package/dist/conversation/violet-message-status.js.map +1 -0
  67. package/dist/conversation/violet-message-text.d.ts +15 -0
  68. package/dist/conversation/violet-message-text.js +83 -0
  69. package/dist/conversation/violet-message-text.js.map +1 -0
  70. package/dist/conversation/violet-message.d.ts +28 -0
  71. package/dist/conversation/violet-message.js +189 -0
  72. package/dist/conversation/violet-message.js.map +1 -0
  73. package/dist/conversation/violet-reasoning-block.d.ts +22 -0
  74. package/dist/conversation/violet-reasoning-block.js +171 -0
  75. package/dist/conversation/violet-reasoning-block.js.map +1 -0
  76. package/dist/conversation/violet-source-citation.d.ts +25 -0
  77. package/dist/conversation/violet-source-citation.js +155 -0
  78. package/dist/conversation/violet-source-citation.js.map +1 -0
  79. package/dist/conversation/violet-tool-call-card.d.ts +37 -0
  80. package/dist/conversation/violet-tool-call-card.js +370 -0
  81. package/dist/conversation/violet-tool-call-card.js.map +1 -0
  82. package/dist/conversation/violet-tool-result-card.d.ts +27 -0
  83. package/dist/conversation/violet-tool-result-card.js +264 -0
  84. package/dist/conversation/violet-tool-result-card.js.map +1 -0
  85. package/dist/data-grid/violet-data-grid-attachment-cell-values.d.ts +15 -0
  86. package/dist/data-grid/violet-data-grid-attachment-cell-values.js +122 -0
  87. package/dist/data-grid/violet-data-grid-attachment-cell-values.js.map +1 -0
  88. package/dist/data-grid/violet-data-grid-attachment-cell.d.ts +79 -0
  89. package/dist/data-grid/violet-data-grid-attachment-cell.js +812 -0
  90. package/dist/data-grid/violet-data-grid-attachment-cell.js.map +1 -0
  91. package/dist/data-grid/violet-data-grid-cell-state.d.ts +20 -0
  92. package/dist/data-grid/violet-data-grid-cell-state.js +68 -0
  93. package/dist/data-grid/violet-data-grid-cell-state.js.map +1 -0
  94. package/dist/data-grid/violet-data-grid-cell-templates.d.ts +28 -0
  95. package/dist/data-grid/violet-data-grid-cell-templates.js +36 -0
  96. package/dist/data-grid/violet-data-grid-cell-templates.js.map +1 -0
  97. package/dist/data-grid/violet-data-grid-clipboard.d.ts +44 -0
  98. package/dist/data-grid/violet-data-grid-clipboard.js +127 -0
  99. package/dist/data-grid/violet-data-grid-clipboard.js.map +1 -0
  100. package/dist/data-grid/violet-data-grid-css.d.ts +7 -0
  101. package/dist/data-grid/violet-data-grid-css.js +20 -0
  102. package/dist/data-grid/violet-data-grid-css.js.map +1 -0
  103. package/dist/data-grid/violet-data-grid-data.d.ts +34 -0
  104. package/dist/data-grid/violet-data-grid-data.js +93 -0
  105. package/dist/data-grid/violet-data-grid-data.js.map +1 -0
  106. package/dist/data-grid/violet-data-grid-editing.d.ts +46 -0
  107. package/dist/data-grid/violet-data-grid-editing.js +75 -0
  108. package/dist/data-grid/violet-data-grid-editing.js.map +1 -0
  109. package/dist/data-grid/violet-data-grid-editor-option-helpers.d.ts +10 -0
  110. package/dist/data-grid/violet-data-grid-editor-option-helpers.js +84 -0
  111. package/dist/data-grid/violet-data-grid-editor-option-helpers.js.map +1 -0
  112. package/dist/data-grid/violet-data-grid-events.d.ts +4 -0
  113. package/dist/data-grid/violet-data-grid-events.js +46 -0
  114. package/dist/data-grid/violet-data-grid-events.js.map +1 -0
  115. package/dist/data-grid/violet-data-grid-fill.d.ts +37 -0
  116. package/dist/data-grid/violet-data-grid-fill.js +155 -0
  117. package/dist/data-grid/violet-data-grid-fill.js.map +1 -0
  118. package/dist/data-grid/violet-data-grid-geometry.d.ts +13 -0
  119. package/dist/data-grid/violet-data-grid-geometry.js +59 -0
  120. package/dist/data-grid/violet-data-grid-geometry.js.map +1 -0
  121. package/dist/data-grid/violet-data-grid-multi-picker-values.d.ts +3 -0
  122. package/dist/data-grid/violet-data-grid-multi-picker-values.js +40 -0
  123. package/dist/data-grid/violet-data-grid-multi-picker-values.js.map +1 -0
  124. package/dist/data-grid/violet-data-grid-multi-picker.d.ts +87 -0
  125. package/dist/data-grid/violet-data-grid-multi-picker.js +789 -0
  126. package/dist/data-grid/violet-data-grid-multi-picker.js.map +1 -0
  127. package/dist/data-grid/violet-data-grid-navigation.d.ts +29 -0
  128. package/dist/data-grid/violet-data-grid-navigation.js +63 -0
  129. package/dist/data-grid/violet-data-grid-navigation.js.map +1 -0
  130. package/dist/data-grid/violet-data-grid-persona-picker-values.d.ts +3 -0
  131. package/dist/data-grid/violet-data-grid-persona-picker-values.js +40 -0
  132. package/dist/data-grid/violet-data-grid-persona-picker-values.js.map +1 -0
  133. package/dist/data-grid/violet-data-grid-persona-picker.d.ts +86 -0
  134. package/dist/data-grid/violet-data-grid-persona-picker.js +840 -0
  135. package/dist/data-grid/violet-data-grid-persona-picker.js.map +1 -0
  136. package/dist/data-grid/violet-data-grid-pill-select.d.ts +65 -0
  137. package/dist/data-grid/violet-data-grid-pill-select.js +635 -0
  138. package/dist/data-grid/violet-data-grid-pill-select.js.map +1 -0
  139. package/dist/data-grid/violet-data-grid-pointer.d.ts +17 -0
  140. package/dist/data-grid/violet-data-grid-pointer.js +45 -0
  141. package/dist/data-grid/violet-data-grid-pointer.js.map +1 -0
  142. package/dist/data-grid/violet-data-grid-presentation.d.ts +142 -0
  143. package/dist/data-grid/violet-data-grid-presentation.js +152 -0
  144. package/dist/data-grid/violet-data-grid-presentation.js.map +1 -0
  145. package/dist/data-grid/violet-data-grid-rating-values.d.ts +3 -0
  146. package/dist/data-grid/violet-data-grid-rating-values.js +30 -0
  147. package/dist/data-grid/violet-data-grid-rating-values.js.map +1 -0
  148. package/dist/data-grid/violet-data-grid-rating.d.ts +39 -0
  149. package/dist/data-grid/violet-data-grid-rating.js +346 -0
  150. package/dist/data-grid/violet-data-grid-rating.js.map +1 -0
  151. package/dist/data-grid/violet-data-grid-reference-picker-values.d.ts +3 -0
  152. package/dist/data-grid/violet-data-grid-reference-picker-values.js +40 -0
  153. package/dist/data-grid/violet-data-grid-reference-picker-values.js.map +1 -0
  154. package/dist/data-grid/violet-data-grid-reference-picker.d.ts +98 -0
  155. package/dist/data-grid/violet-data-grid-reference-picker.js +933 -0
  156. package/dist/data-grid/violet-data-grid-reference-picker.js.map +1 -0
  157. package/dist/data-grid/violet-data-grid-resize.d.ts +36 -0
  158. package/dist/data-grid/violet-data-grid-resize.js +47 -0
  159. package/dist/data-grid/violet-data-grid-resize.js.map +1 -0
  160. package/dist/data-grid/violet-data-grid-selection.d.ts +27 -0
  161. package/dist/data-grid/violet-data-grid-selection.js +88 -0
  162. package/dist/data-grid/violet-data-grid-selection.js.map +1 -0
  163. package/dist/data-grid/violet-data-grid-sizing.d.ts +38 -0
  164. package/dist/data-grid/violet-data-grid-sizing.js +82 -0
  165. package/dist/data-grid/violet-data-grid-sizing.js.map +1 -0
  166. package/dist/data-grid/violet-data-grid-targets.d.ts +5 -0
  167. package/dist/data-grid/violet-data-grid-targets.js +41 -0
  168. package/dist/data-grid/violet-data-grid-targets.js.map +1 -0
  169. package/dist/data-grid/violet-data-grid-values.d.ts +19 -0
  170. package/dist/data-grid/violet-data-grid-values.js +60 -0
  171. package/dist/data-grid/violet-data-grid-values.js.map +1 -0
  172. package/dist/data-grid/violet-data-grid-virtualization.d.ts +31 -0
  173. package/dist/data-grid/violet-data-grid-virtualization.js +41 -0
  174. package/dist/data-grid/violet-data-grid-virtualization.js.map +1 -0
  175. package/dist/data-grid/violet-data-grid.d.ts +590 -0
  176. package/dist/data-grid/violet-data-grid.js +2998 -0
  177. package/dist/data-grid/violet-data-grid.js.map +1 -0
  178. package/dist/data-grid/violet-data-grid.styles.d.ts +1 -0
  179. package/dist/data-grid/violet-data-grid.styles.js +638 -0
  180. package/dist/data-grid/violet-data-grid.styles.js.map +1 -0
  181. package/dist/date-picker/violet-date-picker.d.ts +90 -0
  182. package/dist/date-picker/violet-date-picker.js +624 -0
  183. package/dist/date-picker/violet-date-picker.js.map +1 -0
  184. package/dist/date-range-picker/violet-date-range-picker.d.ts +64 -0
  185. package/dist/date-range-picker/violet-date-range-picker.js +470 -0
  186. package/dist/date-range-picker/violet-date-range-picker.js.map +1 -0
  187. package/dist/date-time/violet-date-utils.d.ts +50 -0
  188. package/dist/date-time/violet-date-utils.js +176 -0
  189. package/dist/date-time/violet-date-utils.js.map +1 -0
  190. package/dist/dialog/violet-dialog.d.ts +53 -0
  191. package/dist/dialog/violet-dialog.js +439 -0
  192. package/dist/dialog/violet-dialog.js.map +1 -0
  193. package/dist/divider/violet-divider.d.ts +15 -0
  194. package/dist/divider/violet-divider.js +88 -0
  195. package/dist/divider/violet-divider.js.map +1 -0
  196. package/dist/empty-state/violet-empty-state.d.ts +31 -0
  197. package/dist/empty-state/violet-empty-state.js +182 -0
  198. package/dist/empty-state/violet-empty-state.js.map +1 -0
  199. package/dist/file-explorer/violet-file-explorer.d.ts +164 -0
  200. package/dist/file-explorer/violet-file-explorer.js +1094 -0
  201. package/dist/file-explorer/violet-file-explorer.js.map +1 -0
  202. package/dist/file-upload/violet-file-upload.d.ts +109 -0
  203. package/dist/file-upload/violet-file-upload.js +950 -0
  204. package/dist/file-upload/violet-file-upload.js.map +1 -0
  205. package/dist/foundations/reference-component-set.d.ts +9 -0
  206. package/dist/foundations/reference-component-set.js +107 -0
  207. package/dist/foundations/reference-component-set.js.map +1 -0
  208. package/dist/foundations/token-registry.d.ts +38 -0
  209. package/dist/foundations/token-registry.js +203 -0
  210. package/dist/foundations/token-registry.js.map +1 -0
  211. package/dist/foundations/violet-direction.d.ts +11 -0
  212. package/dist/foundations/violet-direction.js +22 -0
  213. package/dist/foundations/violet-direction.js.map +1 -0
  214. package/dist/foundations/violet-form-disabled.d.ts +25 -0
  215. package/dist/foundations/violet-form-disabled.js +79 -0
  216. package/dist/foundations/violet-form-disabled.js.map +1 -0
  217. package/dist/foundations/violet-safe-url.d.ts +8 -0
  218. package/dist/foundations/violet-safe-url.js +21 -0
  219. package/dist/foundations/violet-safe-url.js.map +1 -0
  220. package/dist/gantt/violet-gantt-geometry.d.ts +18 -0
  221. package/dist/gantt/violet-gantt-geometry.js +78 -0
  222. package/dist/gantt/violet-gantt-geometry.js.map +1 -0
  223. package/dist/gantt/violet-gantt.d.ts +239 -0
  224. package/dist/gantt/violet-gantt.js +1627 -0
  225. package/dist/gantt/violet-gantt.js.map +1 -0
  226. package/dist/gantt/violet-gantt.styles.d.ts +1 -0
  227. package/dist/gantt/violet-gantt.styles.js +580 -0
  228. package/dist/gantt/violet-gantt.styles.js.map +1 -0
  229. package/dist/icon/generated/icon-sources.d.ts +9 -0
  230. package/dist/icon/generated/icon-sources.js +15 -0
  231. package/dist/icon/generated/icon-sources.js.map +1 -0
  232. package/dist/icon/generated/icons/system-arrow-up.d.ts +8 -0
  233. package/dist/icon/generated/icons/system-arrow-up.js +15 -0
  234. package/dist/icon/generated/icons/system-arrow-up.js.map +1 -0
  235. package/dist/icon/generated/icons/system-attach.d.ts +8 -0
  236. package/dist/icon/generated/icons/system-attach.js +15 -0
  237. package/dist/icon/generated/icons/system-attach.js.map +1 -0
  238. package/dist/icon/generated/icons/system-calendar.d.ts +8 -0
  239. package/dist/icon/generated/icons/system-calendar.js +15 -0
  240. package/dist/icon/generated/icons/system-calendar.js.map +1 -0
  241. package/dist/icon/generated/icons/system-checkmark.d.ts +8 -0
  242. package/dist/icon/generated/icons/system-checkmark.js +15 -0
  243. package/dist/icon/generated/icons/system-checkmark.js.map +1 -0
  244. package/dist/icon/generated/icons/system-chevron-right.d.ts +8 -0
  245. package/dist/icon/generated/icons/system-chevron-right.js +15 -0
  246. package/dist/icon/generated/icons/system-chevron-right.js.map +1 -0
  247. package/dist/icon/generated/icons/system-clock.d.ts +8 -0
  248. package/dist/icon/generated/icons/system-clock.js +15 -0
  249. package/dist/icon/generated/icons/system-clock.js.map +1 -0
  250. package/dist/icon/generated/icons/system-close.d.ts +8 -0
  251. package/dist/icon/generated/icons/system-close.js +15 -0
  252. package/dist/icon/generated/icons/system-close.js.map +1 -0
  253. package/dist/icon/generated/icons/system-dismiss.d.ts +8 -0
  254. package/dist/icon/generated/icons/system-dismiss.js +15 -0
  255. package/dist/icon/generated/icons/system-dismiss.js.map +1 -0
  256. package/dist/icon/generated/icons/system-document.d.ts +8 -0
  257. package/dist/icon/generated/icons/system-document.js +15 -0
  258. package/dist/icon/generated/icons/system-document.js.map +1 -0
  259. package/dist/icon/generated/icons/system-folder.d.ts +8 -0
  260. package/dist/icon/generated/icons/system-folder.js +15 -0
  261. package/dist/icon/generated/icons/system-folder.js.map +1 -0
  262. package/dist/icon/generated/icons/system-search.d.ts +8 -0
  263. package/dist/icon/generated/icons/system-search.js +15 -0
  264. package/dist/icon/generated/icons/system-search.js.map +1 -0
  265. package/dist/icon/generated/icons/system-settings.d.ts +8 -0
  266. package/dist/icon/generated/icons/system-settings.js +15 -0
  267. package/dist/icon/generated/icons/system-settings.js.map +1 -0
  268. package/dist/icon/generated/icons/system-sort-ascending.d.ts +8 -0
  269. package/dist/icon/generated/icons/system-sort-ascending.js +15 -0
  270. package/dist/icon/generated/icons/system-sort-ascending.js.map +1 -0
  271. package/dist/icon/generated/icons/system-sort-descending.d.ts +8 -0
  272. package/dist/icon/generated/icons/system-sort-descending.js +15 -0
  273. package/dist/icon/generated/icons/system-sort-descending.js.map +1 -0
  274. package/dist/icon/generated/icons/system-stop.d.ts +8 -0
  275. package/dist/icon/generated/icons/system-stop.js +15 -0
  276. package/dist/icon/generated/icons/system-stop.js.map +1 -0
  277. package/dist/icon/generated/icons/system-warning.d.ts +8 -0
  278. package/dist/icon/generated/icons/system-warning.js +15 -0
  279. package/dist/icon/generated/icons/system-warning.js.map +1 -0
  280. package/dist/icon/generated/index.d.ts +17 -0
  281. package/dist/icon/generated/index.js +22 -0
  282. package/dist/icon/generated/index.js.map +1 -0
  283. package/dist/icon/icon-registry.d.ts +20 -0
  284. package/dist/icon/icon-registry.js +22 -0
  285. package/dist/icon/icon-registry.js.map +1 -0
  286. package/dist/icon/violet-icon.d.ts +22 -0
  287. package/dist/icon/violet-icon.js +75 -0
  288. package/dist/icon/violet-icon.js.map +1 -0
  289. package/dist/icon-button/violet-icon-button.d.ts +29 -0
  290. package/dist/icon-button/violet-icon-button.js +193 -0
  291. package/dist/icon-button/violet-icon-button.js.map +1 -0
  292. package/dist/image/violet-image.d.ts +33 -0
  293. package/dist/image/violet-image.js +215 -0
  294. package/dist/image/violet-image.js.map +1 -0
  295. package/dist/index.d.ts +86 -0
  296. package/dist/index.js +87 -0
  297. package/dist/index.js.map +1 -0
  298. package/dist/listbox/violet-listbox.d.ts +41 -0
  299. package/dist/listbox/violet-listbox.js +323 -0
  300. package/dist/listbox/violet-listbox.js.map +1 -0
  301. package/dist/listbox/violet-selection-helpers.d.ts +9 -0
  302. package/dist/listbox/violet-selection-helpers.js +52 -0
  303. package/dist/listbox/violet-selection-helpers.js.map +1 -0
  304. package/dist/menu/violet-menu-item.d.ts +30 -0
  305. package/dist/menu/violet-menu-item.js +148 -0
  306. package/dist/menu/violet-menu-item.js.map +1 -0
  307. package/dist/menu/violet-menu.d.ts +70 -0
  308. package/dist/menu/violet-menu.js +480 -0
  309. package/dist/menu/violet-menu.js.map +1 -0
  310. package/dist/option/violet-option.d.ts +38 -0
  311. package/dist/option/violet-option.js +258 -0
  312. package/dist/option/violet-option.js.map +1 -0
  313. package/dist/option-group/violet-option-group.d.ts +20 -0
  314. package/dist/option-group/violet-option-group.js +100 -0
  315. package/dist/option-group/violet-option-group.js.map +1 -0
  316. package/dist/pagination/violet-pagination.d.ts +36 -0
  317. package/dist/pagination/violet-pagination.js +356 -0
  318. package/dist/pagination/violet-pagination.js.map +1 -0
  319. package/dist/persona/violet-persona.d.ts +28 -0
  320. package/dist/persona/violet-persona.js +250 -0
  321. package/dist/persona/violet-persona.js.map +1 -0
  322. package/dist/popover/violet-popover.d.ts +32 -0
  323. package/dist/popover/violet-popover.js +225 -0
  324. package/dist/popover/violet-popover.js.map +1 -0
  325. package/dist/progress/violet-progress.d.ts +22 -0
  326. package/dist/progress/violet-progress.js +197 -0
  327. package/dist/progress/violet-progress.js.map +1 -0
  328. package/dist/radio/violet-radio.d.ts +59 -0
  329. package/dist/radio/violet-radio.js +402 -0
  330. package/dist/radio/violet-radio.js.map +1 -0
  331. package/dist/radio-group/violet-radio-group.d.ts +89 -0
  332. package/dist/radio-group/violet-radio-group.js +388 -0
  333. package/dist/radio-group/violet-radio-group.js.map +1 -0
  334. package/dist/segment/violet-segment.d.ts +29 -0
  335. package/dist/segment/violet-segment.js +166 -0
  336. package/dist/segment/violet-segment.js.map +1 -0
  337. package/dist/segmented-control/violet-segmented-control.d.ts +64 -0
  338. package/dist/segmented-control/violet-segmented-control.js +349 -0
  339. package/dist/segmented-control/violet-segmented-control.js.map +1 -0
  340. package/dist/select/violet-select.d.ts +84 -0
  341. package/dist/select/violet-select.js +690 -0
  342. package/dist/select/violet-select.js.map +1 -0
  343. package/dist/skeleton/violet-skeleton.d.ts +18 -0
  344. package/dist/skeleton/violet-skeleton.js +150 -0
  345. package/dist/skeleton/violet-skeleton.js.map +1 -0
  346. package/dist/slider/violet-range-slider.d.ts +96 -0
  347. package/dist/slider/violet-range-slider.js +833 -0
  348. package/dist/slider/violet-range-slider.js.map +1 -0
  349. package/dist/slider/violet-slider.d.ts +80 -0
  350. package/dist/slider/violet-slider.js +666 -0
  351. package/dist/slider/violet-slider.js.map +1 -0
  352. package/dist/snackbar/violet-snackbar.d.ts +39 -0
  353. package/dist/snackbar/violet-snackbar.js +310 -0
  354. package/dist/snackbar/violet-snackbar.js.map +1 -0
  355. package/dist/spinner/violet-spinner.d.ts +15 -0
  356. package/dist/spinner/violet-spinner.js +99 -0
  357. package/dist/spinner/violet-spinner.js.map +1 -0
  358. package/dist/switch/violet-switch.d.ts +59 -0
  359. package/dist/switch/violet-switch.js +459 -0
  360. package/dist/switch/violet-switch.js.map +1 -0
  361. package/dist/tab/violet-tab.d.ts +23 -0
  362. package/dist/tab/violet-tab.js +245 -0
  363. package/dist/tab/violet-tab.js.map +1 -0
  364. package/dist/tab-panel/violet-tab-panel.d.ts +10 -0
  365. package/dist/tab-panel/violet-tab-panel.js +46 -0
  366. package/dist/tab-panel/violet-tab-panel.js.map +1 -0
  367. package/dist/tabs/violet-tabs.d.ts +48 -0
  368. package/dist/tabs/violet-tabs.js +398 -0
  369. package/dist/tabs/violet-tabs.js.map +1 -0
  370. package/dist/teaching-tip/violet-teaching-tip.d.ts +48 -0
  371. package/dist/teaching-tip/violet-teaching-tip.js +418 -0
  372. package/dist/teaching-tip/violet-teaching-tip.js.map +1 -0
  373. package/dist/text/violet-text.d.ts +18 -0
  374. package/dist/text/violet-text.js +128 -0
  375. package/dist/text/violet-text.js.map +1 -0
  376. package/dist/text-area/violet-text-area.d.ts +93 -0
  377. package/dist/text-area/violet-text-area.js +323 -0
  378. package/dist/text-area/violet-text-area.js.map +1 -0
  379. package/dist/text-field/violet-text-field.d.ts +132 -0
  380. package/dist/text-field/violet-text-field.js +445 -0
  381. package/dist/text-field/violet-text-field.js.map +1 -0
  382. package/dist/theme/generated/violet-theme-presets.generated.d.ts +9 -0
  383. package/dist/theme/generated/violet-theme-presets.generated.js +9 -0
  384. package/dist/theme/generated/violet-theme-presets.generated.js.map +1 -0
  385. package/dist/theme/generated/violet-theme.generated.d.ts +1048 -0
  386. package/dist/theme/generated/violet-theme.generated.js +362 -0
  387. package/dist/theme/generated/violet-theme.generated.js.map +1 -0
  388. package/dist/theme/index.d.ts +4 -0
  389. package/dist/theme/index.js +7 -0
  390. package/dist/theme/index.js.map +1 -0
  391. package/dist/theme/violet-theme-builtin.d.ts +14 -0
  392. package/dist/theme/violet-theme-builtin.js +19 -0
  393. package/dist/theme/violet-theme-builtin.js.map +1 -0
  394. package/dist/theme/violet-theme-css.d.ts +77 -0
  395. package/dist/theme/violet-theme-css.js +154 -0
  396. package/dist/theme/violet-theme-css.js.map +1 -0
  397. package/dist/theme/violet-theme-runtime.d.ts +72 -0
  398. package/dist/theme/violet-theme-runtime.js +221 -0
  399. package/dist/theme/violet-theme-runtime.js.map +1 -0
  400. package/dist/theme/violet-theme.d.ts +22 -0
  401. package/dist/theme/violet-theme.js +60 -0
  402. package/dist/theme/violet-theme.js.map +1 -0
  403. package/dist/theme/violet-token-defaults.d.ts +4 -0
  404. package/dist/theme/violet-token-defaults.js +198 -0
  405. package/dist/theme/violet-token-defaults.js.map +1 -0
  406. package/dist/time-picker/violet-time-picker.d.ts +59 -0
  407. package/dist/time-picker/violet-time-picker.js +369 -0
  408. package/dist/time-picker/violet-time-picker.js.map +1 -0
  409. package/dist/toast/violet-toast.d.ts +50 -0
  410. package/dist/toast/violet-toast.js +395 -0
  411. package/dist/toast/violet-toast.js.map +1 -0
  412. package/dist/tooltip/violet-tooltip.d.ts +34 -0
  413. package/dist/tooltip/violet-tooltip.js +387 -0
  414. package/dist/tooltip/violet-tooltip.js.map +1 -0
  415. package/dist/tree/violet-tree.d.ts +44 -0
  416. package/dist/tree/violet-tree.js +451 -0
  417. package/dist/tree/violet-tree.js.map +1 -0
  418. package/dist/tree-item/violet-tree-item.d.ts +49 -0
  419. package/dist/tree-item/violet-tree-item.js +359 -0
  420. package/dist/tree-item/violet-tree-item.js.map +1 -0
  421. package/package.json +78 -3
  422. package/tokens/interface.json +364 -0
  423. package/tokens/master-semantic.tokens.jsonc +7 -0
  424. package/tokens/raw-palette.proposal.jsonc +159 -0
  425. package/tokens/theme-presets.jsonc +7 -0
  426. package/tokens/violet-theme.export.json +1392 -0
@@ -0,0 +1,2998 @@
1
+ import { attr, FASTElement, html, observable, render, repeat, Updates, when, } from "@lushly-dev/fast-element";
2
+ import { elementScroll, observeElementOffset, observeElementRect, Virtualizer, } from "@tanstack/virtual-core";
3
+ import "../checkbox/violet-checkbox";
4
+ import "../icon/violet-icon";
5
+ import "../radio/violet-radio";
6
+ import "../text-field/violet-text-field";
7
+ import { registerSystemSortAscendingIcon } from "../icon/generated/icons/system-sort-ascending";
8
+ import { registerSystemSortDescendingIcon } from "../icon/generated/icons/system-sort-descending";
9
+ import { logicalArrowKey } from "../foundations/violet-direction";
10
+ import { styles } from "./violet-data-grid.styles";
11
+ import { resolveCellPartText as composeCellPartText, isCellSelected as computeIsCellSelected, isFillPreviewCell as computeIsFillPreviewCell, rangeEdgeForCell as computeRangeEdgeForCell, } from "./violet-data-grid-cell-state";
12
+ import { defaultCellContentTemplate, inputCellEditorTemplate, selectCellEditorTemplate, } from "./violet-data-grid-cell-templates";
13
+ import { copyTextForSelection, normalizePastedText as normalizeGridPastedText, resolvePasteOriginLocation, sampleAutosizeRows, } from "./violet-data-grid-clipboard";
14
+ import { cellValueFor as resolveCellValue, editorOptionsForColumn as resolveEditorOptionsForColumn, serializeCellValue as serializeGridCellValue, sortRows as sortGridRows, stringifyCellValue, } from "./violet-data-grid-data";
15
+ import { beginEditingState, cancelEditingState as clearEditingState, editorStringValue, focusEditorAtEnd, seedEditorValue, } from "./violet-data-grid-editing";
16
+ import { cellElementFromEvent, cellElementFromTarget as eventCellElementFromTarget, closestFromEventPath as eventClosestFromEventPath, } from "./violet-data-grid-events";
17
+ import { buildFillChanges, buildPasteChanges, clampFillBoundsToEditableTargets as clampEditableFillBounds, hasEditableCellsInBounds, } from "./violet-data-grid-fill";
18
+ import { locationFromCellElement as geometryLocationFromCellElement, nearestLocationForPoint as nearestGeometryLocationForPoint, preferredAxisForPoint, rectFromCellPair, } from "./violet-data-grid-geometry";
19
+ import { createCellSelection as createNavigationCellSelection, firstCellLocation as resolveNavigationFirstCellLocation, nextCellLocationForKey as resolveNextCellLocationForKey, } from "./violet-data-grid-navigation";
20
+ import { clearedFillSession, clearedPointerSelectionSession, isFillPointerEventForSession, isPointerSelectionEventForSession, markPointerSelectionMoved, pointerSelectionSuppressesNextClick, beginFillDrag as startFillDragSession, beginPointerSelection as startPointerSelectionSession, } from "./violet-data-grid-pointer";
21
+ import { createPresentedColumn as buildPresentedColumn, createPresentedRow as buildPresentedRow, syncEditingState, syncActiveCell as syncPresentedActiveCell, syncCellSelection as syncPresentedCellSelection, syncFillPreview as syncPresentedFillPreview, } from "./violet-data-grid-presentation";
22
+ import { clearedColumnResizeSession, columnResizeKeyShortcut, isColumnResizeShortcut, keyboardResizedColumnWidth as computeKeyboardResizedColumnWidth, resizedColumnWidth as computeResizedColumnWidth, isColumnResizeEventForSession, beginColumnResize as startColumnResizeSession, } from "./violet-data-grid-resize";
23
+ import { nextTabLocation, selectedLocations, locationForIndices as selectionLocationForIndices, rangeFromBounds as selectionRangeFromBounds, } from "./violet-data-grid-selection";
24
+ import { autosizedColumnWidth as computeAutosizedColumnWidth, minimumColumnWidth as computeMinimumColumnWidth, renderedColumnWidth as computeRenderedColumnWidth, resolvedColumnWidth as resolveGridColumnWidth, } from "./violet-data-grid-sizing";
25
+ import { isEditorElement as isGridEditorElement, isFillHandleTarget as isGridFillHandleTarget, isInteractiveCellWidgetTarget as isGridInteractiveCellWidgetTarget, } from "./violet-data-grid-targets";
26
+ import { opensOnSingleActiveClick as editorOpensOnSingleActiveClick, editStringForRawValue, booleanCellValue as normalizeBooleanCellValue, normalizedEditingValue as normalizeEditingValue, resolveEditingValue, } from "./violet-data-grid-values";
27
+ import { buildVirtualizerUpdateOptions, buildRenderedRows as computeRenderedRows, } from "./violet-data-grid-virtualization";
28
+ registerSystemSortAscendingIcon();
29
+ registerSystemSortDescendingIcon();
30
+ const bodyRowTemplate = html `
31
+ <tr
32
+ part="row"
33
+ data-index="${(x) => String(x.item.index)}"
34
+ data-selected="${(x, c) => String(c.parent.isRowSelected(x.row.id))}"
35
+ data-row-index="${(x) => String(x.item.index)}"
36
+ aria-rowindex="${(x) => String(x.item.index + 2)}"
37
+ aria-selected="${(x, c) => c.parent.selectionMode === "none" ? null : String(c.parent.isRowSelected(x.row.id))}"
38
+ >
39
+ <td
40
+ class="selection-cell"
41
+ part="cell"
42
+ headers="${(_x, c) => c.parent.selectionHeaderId}"
43
+ ?hidden="${(x, c) => c.parent.selectionMode === "none"}"
44
+ >
45
+ ${when((x, c) => c.parent.selectionMode === "single", html `
46
+ <violet-radio
47
+ class="selection-radio"
48
+ inline
49
+ value="${(x) => x.row.id}"
50
+ name="${(x, c) => c.parent.selectionControlName}"
51
+ aria-label="${(x, c) => c.parent.selectionLabelFor(x.row.id, x.row.label)}"
52
+ :checked="${(x, c) => c.parent.isRowSelected(x.row.id)}"
53
+ @pointerdown="${(x, c) => c.parent.handleSelectionControlPointerDown(c.event)}"
54
+ @click="${(x, c) => c.parent.handleSelectionControlClick(c.event)}"
55
+ @change="${(x, c) => c.parent.handleRowSelection(x.row.id, c.event)}"
56
+ ></violet-radio>
57
+ `)}
58
+ ${when((x, c) => c.parent.selectionMode === "multiple", html `
59
+ <violet-checkbox
60
+ class="selection-checkbox"
61
+ inline
62
+ aria-label="${(x, c) => c.parent.selectionLabelFor(x.row.id, x.row.label)}"
63
+ :checked="${(x, c) => c.parent.isRowSelected(x.row.id)}"
64
+ @pointerdown="${(x, c) => c.parent.handleSelectionControlPointerDown(c.event)}"
65
+ @click="${(x, c) => c.parent.handleRowCheckboxClick(x.row.id, c.event)}"
66
+ ></violet-checkbox>
67
+ `)}
68
+ </td>
69
+ ${repeat((x) => x.row.cells, html `
70
+ <td
71
+ id="${(x) => x.cellId}"
72
+ headers="${(x, c) => c.parentContext.parent.columnHeaderIdFor(x.columnId)}"
73
+ part="${(x) => x.resolvedCellPartText}"
74
+ data-align="${(x) => x.align}"
75
+ data-row-id="${(x) => x.rowId}"
76
+ data-column-id="${(x) => x.columnId}"
77
+ data-active="${(x) => String(x.active)}"
78
+ data-selected="${(x) => String(x.selected)}"
79
+ data-fill-preview="${(x) => String(x.fillPreview)}"
80
+ data-editing="${(x) => String(x.editing)}"
81
+ data-range-edge="${(x) => x.rangeEdge}"
82
+ style="${(x) => x.widthStyle}"
83
+ >
84
+ ${when((x) => x.editing && (x.editor === "text" || x.editor === "number"), html `
85
+ <span class="cell-sizing-content" aria-hidden="true">
86
+ ${render((x) => x, (x) => x.cellTemplate ?? defaultCellContentTemplate)}
87
+ </span>
88
+ ${inputCellEditorTemplate}
89
+ `)}
90
+ ${when((x) => x.editing && x.editor === "select", html `
91
+ <span class="cell-sizing-content" aria-hidden="true">
92
+ ${render((x) => x, (x) => x.cellTemplate ?? defaultCellContentTemplate)}
93
+ </span>
94
+ ${selectCellEditorTemplate}
95
+ `)}
96
+ ${when((x) => x.editing && x.editor === "custom", html `
97
+ <span class="cell-sizing-content" aria-hidden="true">
98
+ ${render((x) => x, (x) => x.cellTemplate ?? defaultCellContentTemplate)}
99
+ </span>
100
+ ${render((x) => x, (x) => x.editorTemplate ?? defaultCellContentTemplate)}
101
+ `)}
102
+ ${when((x) => !x.editing && x.editor === "checkbox", html `
103
+ <span class="cell-widget" data-align="${(x) => x.align}">
104
+ <violet-checkbox
105
+ class="cell-checkbox"
106
+ data-cell-widget="checkbox"
107
+ inline
108
+ aria-label="${(x) => `${x.columnLabel} for ${x.rowLabel}`}"
109
+ :checked="${(x) => normalizeBooleanCellValue(x.rawValue)}"
110
+ ?disabled="${(x) => !x.editable}"
111
+ @click="${(x, c) => c.parentContext.parent.handleCellCheckboxClick(x.rowId, x.columnId, c.event)}"
112
+ ></violet-checkbox>
113
+ </span>
114
+ `)}
115
+ ${when((x) => x.editing && Boolean(x.editingError), html `
116
+ <span
117
+ class="cell-editor-error"
118
+ id="${(x) => x.editingErrorId}"
119
+ role="alert"
120
+ >${(x) => x.editingError}</span>
121
+ `)}
122
+ ${when((x) => x.editing && Boolean(x.editingHint), html `
123
+ <span class="cell-editor-hint" id="${(x) => x.editingHintId}"
124
+ >${(x) => x.editingHint}</span>
125
+ `)}
126
+ ${when((x) => !x.editing && x.editor !== "checkbox", html `
127
+ ${render((x) => x, (x) => x.cellTemplate ?? defaultCellContentTemplate)}
128
+ `)}
129
+ ${when((x, c) => c.parentContext.parent.shouldShowFillHandleForCell(x.rowId, x.columnId), html `
130
+ <span class="fill-handle" data-fill-handle="true" aria-hidden="true"></span>
131
+ `)}
132
+ </td>
133
+ `)}
134
+ </tr>
135
+ `;
136
+ const fullTableTemplate = html `
137
+ <div class="table-canvas" style="--_virtual-total-size:${(x) => `${x.virtualTotalSize}px`};">
138
+ <table
139
+ class="table-full-table"
140
+ part="table"
141
+ aria-rowcount="${(x) => String(x.logicalRowCount)}"
142
+ aria-colcount="${(x) => String(x.logicalColumnCount)}"
143
+ >
144
+ <colgroup>
145
+ <col
146
+ class="selection-column"
147
+ style="${(x) => x.selectionMode === "none"
148
+ ? "width:0;inline-size:0;min-inline-size:0;max-inline-size:0;"
149
+ : "width:var(--_selection-column-size);inline-size:var(--_selection-column-size);min-inline-size:var(--_selection-column-size);max-inline-size:var(--_selection-column-size);"}"
150
+ />
151
+ ${repeat((x) => x.presentedColumns, html `
152
+ <col data-column-id="${(x) => x.id}" style="${(x) => x.widthStyle}" />
153
+ `)}
154
+ </colgroup>
155
+ <thead part="head">
156
+ <tr part="header-row">
157
+ <th
158
+ id="${(x) => x.selectionHeaderId}"
159
+ class="selection-header"
160
+ part="header-cell selection-header-cell"
161
+ scope="col"
162
+ aria-label="${(x) => x.selectionHeaderLabel}"
163
+ ?hidden="${(x) => x.selectionMode === "none"}"
164
+ >
165
+ <span class="visually-hidden">${(x) => x.selectionHeaderLabel}</span>
166
+ ${when((x) => x.selectionMode === "multiple" && x.presentedRows.length > 0, html `
167
+ <violet-checkbox
168
+ class="selection-checkbox"
169
+ inline
170
+ aria-label="Select all rows"
171
+ :checked="${(x) => x.allRowsSelected}"
172
+ :indeterminate="${(x) => x.partiallySelected}"
173
+ @pointerdown="${(x, c) => x.handleSelectionControlPointerDown(c.event)}"
174
+ @click="${(x, c) => x.handleToggleAllCheckboxClick(c.event)}"
175
+ ></violet-checkbox>
176
+ `)}
177
+ </th>
178
+ ${repeat((x) => x.presentedColumns, html `
179
+ <th
180
+ id="${(x, c) => c.parent.columnHeaderIdFor(x.id)}"
181
+ part="${(x) => x.headerPartText}"
182
+ scope="col"
183
+ data-column-id="${(x) => x.id}"
184
+ data-align="${(x) => x.align}"
185
+ aria-sort="${(x, c) => c.parent.sortStateFor(x.id)}"
186
+ style="${(x) => x.widthStyle}"
187
+ tabindex="${(x, c) => (x.sortable ? null : c.parent.columnHeaderTabIndexFor(x.id))}"
188
+ aria-keyshortcuts="${(x) => (x.sortable ? null : columnResizeKeyShortcut)}"
189
+ @keydown="${(x, c) => c.parent.handleColumnHeaderKeydown(x.id, c.event)}"
190
+ @focusin="${(x, c) => c.parent.handleColumnHeaderFocus(x.id, c.event)}"
191
+ >
192
+ ${when((x) => x.sortable, html `
193
+ <button
194
+ class="header-button"
195
+ type="button"
196
+ tabindex="${(x, c) => c.parent.columnHeaderTabIndexFor(x.id)}"
197
+ aria-keyshortcuts="${() => columnResizeKeyShortcut}"
198
+ @click="${(x, c) => c.parent.handleSortRequest(x.id)}"
199
+ >
200
+ <span class="header-label">${(x) => x.label}</span>
201
+ <violet-icon
202
+ class="sort-indicator"
203
+ data-sorted="${(x, c) => String(c.parent.isSortedColumn(x.id))}"
204
+ icon="${(x, c) => c.parent.sortIconNameFor(x.id)}"
205
+ decorative
206
+ ></violet-icon>
207
+ </button>
208
+ `)}
209
+ ${when((x) => !x.sortable, html `
210
+ <span class="header-label">${(x) => x.label}</span>
211
+ `)}
212
+ <button
213
+ class="column-resizer"
214
+ type="button"
215
+ tabindex="-1"
216
+ aria-label="${(x) => `Resize ${x.label} column`}"
217
+ data-column-resizer="${(x) => x.id}"
218
+ @pointerdown="${(x, c) => c.parent.handleColumnResizePointerDown(x.id, c.event)}"
219
+ @pointermove="${(x, c) => c.parent.handleColumnResizePointerMove(c.event)}"
220
+ @pointerup="${(x, c) => c.parent.handleColumnResizePointerUp(c.event)}"
221
+ @pointercancel="${(x, c) => c.parent.handleColumnResizePointerCancel(c.event)}"
222
+ @dblclick="${(x, c) => c.parent.handleColumnResizeDoubleClick(x.id, c.event)}"
223
+ @keydown="${(x, c) => c.parent.handleColumnResizeKeyDown(x.id, c.event)}"
224
+ ></button>
225
+ </th>
226
+ `)}
227
+ </tr>
228
+ </thead>
229
+ <tbody part="body">
230
+ <tr
231
+ class="virtual-spacer-row"
232
+ aria-hidden="true"
233
+ ?hidden="${(x) => !x.virtualize || x.virtualPaddingStart <= 0}"
234
+ >
235
+ <td
236
+ colspan="${(x) => String(x.columnSpan)}"
237
+ style="block-size:${(x) => `${x.virtualPaddingStart}px`};"
238
+ ></td>
239
+ </tr>
240
+ ${repeat((x) => x.renderedRows, bodyRowTemplate)}
241
+ <tr
242
+ class="virtual-spacer-row"
243
+ aria-hidden="true"
244
+ ?hidden="${(x) => !x.virtualize || x.virtualPaddingEnd <= 0}"
245
+ >
246
+ <td
247
+ colspan="${(x) => String(x.columnSpan)}"
248
+ style="block-size:${(x) => `${x.virtualPaddingEnd}px`};"
249
+ ></td>
250
+ </tr>
251
+ </tbody>
252
+ </table>
253
+ </div>
254
+ `;
255
+ const template = html `
256
+ <div class="grid-shell">
257
+ ${when((x) => x.shouldShowToolbar, html `
258
+ <div class="toolbar" part="toolbar">
259
+ ${when((x) => x.showsBuiltInFilter, html `
260
+ <div class="filter-shell">
261
+ <violet-text-field
262
+ class="filter-field"
263
+ aria-label="Filter rows"
264
+ type="search"
265
+ :value="${(x) => x.filterState.query ?? ""}"
266
+ placeholder="Filter visible rows"
267
+ @input="${(x, c) => x.handleFilterInput(c.event)}"
268
+ ></violet-text-field>
269
+ </div>
270
+ `)}
271
+ <div class="toolbar-meta">
272
+ <span>${(x) => x.rowSummary}</span>
273
+ <div class="toolbar-slot">
274
+ <slot
275
+ name="toolbar"
276
+ @slotchange="${(x, c) => x.handleToolbarSlotChange(c.event)}"
277
+ ></slot>
278
+ </div>
279
+ </div>
280
+ </div>
281
+ `)}
282
+
283
+ <slot class="default-slot"></slot>
284
+
285
+ <div class="table-region">
286
+ <div
287
+ class="edit-status"
288
+ part="edit-status"
289
+ role="status"
290
+ aria-live="polite"
291
+ aria-atomic="true"
292
+ >${(x) => x.editAnnouncement}</div>
293
+ ${when((x) => x.presentedRows.length > 0, html `
294
+ <div
295
+ class="table-scroll"
296
+ role="${(x) => (x.getAttribute("aria-label") ? "group" : null)}"
297
+ aria-label="${(x) => x.getAttribute("aria-label")}"
298
+ tabindex="${(x) => (x.focusMode === "cell" ? "0" : "-1")}"
299
+ aria-describedby="${(x) => (x.focusMode === "cell" ? x.activeCellLabelId : null)}"
300
+ aria-keyshortcuts="${(x) => (x.focusMode === "cell" ? columnResizeKeyShortcut : null)}"
301
+ @focus="${(x) => x.handleGridFocus()}"
302
+ @click="${(x, c) => x.handleGridClick(c.event)}"
303
+ @dblclick="${(x, c) => x.handleGridDoubleClick(c.event)}"
304
+ @pointerdown="${(x, c) => x.handleGridPointerDown(c.event)}"
305
+ @pointermove="${(x, c) => x.handleGridPointerMove(c.event)}"
306
+ @pointerup="${(x, c) => x.handleGridPointerUp(c.event)}"
307
+ @pointercancel="${(x, c) => x.handleGridPointerCancel(c.event)}"
308
+ @focusout="${(x, c) => x.handleGridFocusOut(c.event)}"
309
+ @input="${(x, c) => x.handleGridInput(c.event)}"
310
+ @change="${(x, c) => x.handleGridChange(c.event)}"
311
+ @copy="${(x, c) => x.handleGridCopy(c.event)}"
312
+ @paste="${(x, c) => x.handleGridPaste(c.event)}"
313
+ @keydown="${(x, c) => x.handleGridKeydown(c.event)}"
314
+ >
315
+ ${when((x) => x.focusMode === "cell", html `
316
+ <span class="visually-hidden" id="${(x) => x.activeCellLabelId}">
317
+ ${(x) => x.activeCellDescription}
318
+ </span>
319
+ `)}
320
+ ${fullTableTemplate}
321
+ </div>
322
+ `)}
323
+
324
+ ${when((x) => x.presentedRows.length === 0 && !x.busy, html `
325
+ <div class="empty-state" part="empty-state">
326
+ <slot name="empty">No rows available.</slot>
327
+ </div>
328
+ `)}
329
+
330
+ ${when((x) => x.busy, html `
331
+ <div class="loading-overlay" part="loading-state">
332
+ <slot name="loading">Loading rows...</slot>
333
+ </div>
334
+ `)}
335
+ </div>
336
+ </div>
337
+ `;
338
+ /**
339
+ * Violet reusable data grid component.
340
+ *
341
+ * @summary Semantic table-first data grid for FAST-AF and Violet.
342
+ * @fires sort-change - Emitted when the user changes sort intent.
343
+ * @fires selection-change - Emitted when row selection changes.
344
+ * @fires filter-change - Emitted when the built-in filter input changes.
345
+ * @fires active-cell-change - Emitted when the active cell changes in cell focus mode.
346
+ * @fires cell-selection-change - Emitted when the rectangular cell selection changes.
347
+ * @fires cell-copy - Emitted when an active cell or current range is copied as tab-separated text (cells containing tabs, newlines or quotes are quoted).
348
+ * @fires cell-copy-error - Emitted when writing to the clipboard fails or the async clipboard API is unavailable; detail includes the copy payload and `error`.
349
+ * @fires cell-paste - Emitted when pasted text is mapped onto editable cells.
350
+ * @fires cell-fill - Emitted when an autofill drag, or `fillSelection()`, maps source cells onto a larger target range.
351
+ * @fires column-width-change - Emitted when a column width is resized or autosized.
352
+ * @fires edit-start - Emitted when a cell enters edit mode.
353
+ * @fires edit-cancel - Emitted when a cell edit is cancelled.
354
+ * @fires cell-change - Emitted when a cell edit is committed.
355
+ * @remarks The column headers are part of the grid's keyboard model, so the grid adds one Tab stop, not
356
+ * one per column. In cell focus mode the grid is that Tab stop: ArrowUp from the first row moves focus to
357
+ * the active column's header, ArrowLeft/ArrowRight/Home/End move between headers, ArrowDown returns to the
358
+ * first row, and Shift+Tab returns to the active cell. In row focus mode the headers share a roving Tab
359
+ * stop (the last focused header, first by default) with the same arrow keys. Enter or Space on a sortable
360
+ * header sorts it. Column resizers are not Tab stops: Ctrl+Alt+R on any column header, or on the active
361
+ * cell in cell focus mode, moves focus to that column's resizer. ArrowLeft/ArrowRight resize it (Shift for
362
+ * larger steps), Enter autosizes it and Escape returns focus to where it came from.
363
+ * Virtualized mode uses TanStack Virtual core. The density-aware estimate bootstraps layout,
364
+ * then rendered rows are measured so theme target sizes and expanded cell controls remain aligned.
365
+ * @slot - Optional default slot rendered above the table region.
366
+ * @slot toolbar - Optional toolbar content rendered alongside grid metadata.
367
+ * @slot empty - Content rendered when no rows are available.
368
+ * @slot loading - Content rendered while the grid is busy.
369
+ * @csspart toolbar - Toolbar wrapper for filter and toolbar actions.
370
+ * @csspart table - Root semantic table element.
371
+ * @csspart head - Table head region.
372
+ * @csspart body - Table body region.
373
+ * @csspart header-row - Header row wrapper.
374
+ * @csspart header-cell - Header cell surface.
375
+ * @csspart selection-header-cell - The selection column's header cell (also a header-cell part).
376
+ * @csspart row - Body row wrapper.
377
+ * @csspart cell - Body cell surface.
378
+ * @csspart active-cell - Active cell state hook.
379
+ * @csspart fill-preview-cell - Autofill preview cell hook.
380
+ * @csspart selected-cell - Selected range cell state hook.
381
+ * @csspart selected-range-edge - Selected range boundary hook.
382
+ * @csspart edit-status - Visible live status for edit lifecycle feedback.
383
+ * @csspart empty-state - Empty-state container.
384
+ * @csspart loading-state - Busy/loading overlay container.
385
+ * @cssproperty --violet-data-grid-default-column-width - Width used when a column has no explicit width.
386
+ * @cssproperty --violet-data-grid-virtualized-max-block-size - Optional maximum virtual viewport height;
387
+ * set to `none` when the grid should fill a definite-height parent.
388
+ */
389
+ export class VioletDataGrid extends FASTElement {
390
+ #internals;
391
+ #rowVirtualizer;
392
+ #virtualizerCleanup;
393
+ #virtualizerFrame;
394
+ #rowMeasurementFrame;
395
+ #pointerSelectionSession;
396
+ #suppressNextGridClick;
397
+ #nativeCopyPending;
398
+ #fillSession;
399
+ #columnResizeReturnTarget;
400
+ #lastCellClickLocation;
401
+ #lastCellClickTimestamp;
402
+ #columnResizeSession;
403
+ #columnResizeHandle;
404
+ #measurementCanvas;
405
+ #rowIndexById;
406
+ #columnIndexById;
407
+ #selectedRowIdSet;
408
+ #columnRevision;
409
+ #rowPresentationCache;
410
+ #baseCellsByPresentedRow;
411
+ #sortKeyCache;
412
+ #decoratedRowCache;
413
+ #presentationRevision;
414
+ #interactionRevision;
415
+ #renderedPresentationRevision;
416
+ #renderedInteractionRevision;
417
+ #automaticEstimatedRowHeight;
418
+ #settingAutomaticEstimatedRowHeight;
419
+ #editorRecycleInProgress;
420
+ #editorRecycleFocusFrame;
421
+ #focusGeneration;
422
+ #selectionControlFocusRevision;
423
+ #editorRestoreFrame;
424
+ #editingEditorElement;
425
+ #nextEditingSessionId;
426
+ #editingSession;
427
+ #resolvingEditingSessionId;
428
+ #presentationRetainingSessionId;
429
+ #pendingEditorSelection;
430
+ constructor() {
431
+ super();
432
+ this.instanceId = ++violetDataGridInstanceCount;
433
+ this.#virtualizerCleanup = null;
434
+ this.#virtualizerFrame = null;
435
+ this.#rowMeasurementFrame = null;
436
+ this.#pointerSelectionSession = clearedPointerSelectionSession();
437
+ this.#suppressNextGridClick = false;
438
+ this.#nativeCopyPending = false;
439
+ this.#fillSession = clearedFillSession();
440
+ this.#columnResizeReturnTarget = null;
441
+ this.#lastCellClickLocation = null;
442
+ this.#lastCellClickTimestamp = 0;
443
+ this.#columnResizeSession = clearedColumnResizeSession();
444
+ this.#columnResizeHandle = null;
445
+ this.#measurementCanvas = null;
446
+ this.#rowIndexById = new Map();
447
+ this.#columnIndexById = new Map();
448
+ this.#selectedRowIdSet = new Set();
449
+ this.#columnRevision = 0;
450
+ this.#rowPresentationCache = new Map();
451
+ this.#baseCellsByPresentedRow = new WeakMap();
452
+ this.#sortKeyCache = new Map();
453
+ this.#decoratedRowCache = new Map();
454
+ this.#presentationRevision = 0;
455
+ this.#interactionRevision = 0;
456
+ this.#renderedPresentationRevision = -1;
457
+ this.#renderedInteractionRevision = -1;
458
+ this.#automaticEstimatedRowHeight = true;
459
+ this.#settingAutomaticEstimatedRowHeight = false;
460
+ this.#editorRecycleInProgress = false;
461
+ this.#editorRecycleFocusFrame = null;
462
+ this.#focusGeneration = 0;
463
+ this.#selectionControlFocusRevision = 0;
464
+ this.#editorRestoreFrame = null;
465
+ this.#editingEditorElement = null;
466
+ this.#nextEditingSessionId = 0;
467
+ this.#editingSession = null;
468
+ this.#resolvingEditingSessionId = null;
469
+ this.#presentationRetainingSessionId = null;
470
+ this.#pendingEditorSelection = null;
471
+ this.#handleFocusIntent = () => {
472
+ this.#focusGeneration += 1;
473
+ };
474
+ this.#internals = this.attachInternals();
475
+ this.selectionMode = "none";
476
+ this.stickyHeader = false;
477
+ this.busy = false;
478
+ this.virtualize = false;
479
+ this.density = "natural";
480
+ this.focusMode = "row";
481
+ this.sortMode = "local";
482
+ this.columns = [];
483
+ this.columnWidths = {};
484
+ this.rows = [];
485
+ this.showFilter = false;
486
+ this.sort = null;
487
+ this.filterState = {};
488
+ this.selectedRowIds = [];
489
+ this.presentedColumns = [];
490
+ this.presentedRows = [];
491
+ this.renderedRows = [];
492
+ this.activeCell = null;
493
+ this.cellSelection = null;
494
+ this.editingCell = null;
495
+ this.editingValue = "";
496
+ this.editingError = "";
497
+ this.editAnnouncement = "";
498
+ this.fillPreview = null;
499
+ this.#settingAutomaticEstimatedRowHeight = true;
500
+ this.estimatedRowHeight = this.rowHeightForDensity(this.density);
501
+ this.#settingAutomaticEstimatedRowHeight = false;
502
+ this.overscanCount = 5;
503
+ this.virtualPaddingStart = 0;
504
+ this.virtualPaddingEnd = 0;
505
+ this.virtualTotalSize = 0;
506
+ this.hasToolbarSlotContent = false;
507
+ this.headerFocusColumnId = null;
508
+ this.#rowVirtualizer = new Virtualizer({
509
+ count: 0,
510
+ getScrollElement: () => this.getScrollContainer(),
511
+ estimateSize: () => this.estimatedRowHeight,
512
+ scrollToFn: elementScroll,
513
+ observeElementRect,
514
+ observeElementOffset,
515
+ overscan: this.overscanCount,
516
+ getItemKey: (index) => this.presentedRows[index]?.id ?? index,
517
+ enabled: false,
518
+ onChange: () => {
519
+ this.syncRenderedRows();
520
+ },
521
+ });
522
+ }
523
+ connectedCallback() {
524
+ this.refreshPresentation();
525
+ super.connectedCallback();
526
+ this.ownerDocument.addEventListener("focusin", this.#handleFocusIntent, true);
527
+ this.ownerDocument.addEventListener("pointerdown", this.#handleFocusIntent, true);
528
+ this.#virtualizerCleanup ??= this.#rowVirtualizer._didMount();
529
+ this.hasToolbarSlotContent = this.querySelector('[slot="toolbar"]') !== null;
530
+ this.syncHostStates();
531
+ this.scheduleVirtualizerUpdate();
532
+ }
533
+ disconnectedCallback() {
534
+ // Consumers commit valid route transitions before detaching listeners.
535
+ // Disconnect is the fail-safe terminal path for anything still active,
536
+ // including invalid drafts that cannot remain in an invisible editor.
537
+ this.cancelActiveEdit();
538
+ this.ownerDocument.removeEventListener("focusin", this.#handleFocusIntent, true);
539
+ this.ownerDocument.removeEventListener("pointerdown", this.#handleFocusIntent, true);
540
+ if (this.#virtualizerFrame !== null) {
541
+ cancelAnimationFrame(this.#virtualizerFrame);
542
+ this.#virtualizerFrame = null;
543
+ }
544
+ if (this.#editorRecycleFocusFrame !== null) {
545
+ cancelAnimationFrame(this.#editorRecycleFocusFrame);
546
+ this.#editorRecycleFocusFrame = null;
547
+ }
548
+ this.#selectionControlFocusRevision += 1;
549
+ if (this.#editorRestoreFrame !== null) {
550
+ cancelAnimationFrame(this.#editorRestoreFrame);
551
+ this.#editorRestoreFrame = null;
552
+ }
553
+ if (this.#rowMeasurementFrame !== null) {
554
+ cancelAnimationFrame(this.#rowMeasurementFrame);
555
+ this.#rowMeasurementFrame = null;
556
+ }
557
+ this.#rowVirtualizer.measureElement(null);
558
+ this.#virtualizerCleanup?.();
559
+ this.#virtualizerCleanup = null;
560
+ super.disconnectedCallback();
561
+ }
562
+ selectionModeChanged() {
563
+ if (this.selectionMode === "none") {
564
+ this.selectedRowIds = [];
565
+ return;
566
+ }
567
+ if (this.selectionMode === "single" && this.selectedRowIds.length > 1) {
568
+ this.selectedRowIds = this.selectedRowIds.slice(0, 1);
569
+ }
570
+ this.updateInteractionState();
571
+ this.scheduleVirtualizerUpdate();
572
+ }
573
+ stickyHeaderChanged() {
574
+ this.syncHostStates();
575
+ }
576
+ busyChanged() {
577
+ this.syncHostStates();
578
+ }
579
+ virtualizeChanged() {
580
+ this.syncHostStates();
581
+ this.syncRenderedRows();
582
+ this.scheduleVirtualizerUpdate();
583
+ }
584
+ focusModeChanged() {
585
+ if (this.focusMode !== "cell") {
586
+ this.cancelActiveEdit();
587
+ this.activeCell = null;
588
+ this.cellSelection = null;
589
+ this.fillPreview = null;
590
+ return;
591
+ }
592
+ if (!this.activeCell && this.presentedRows.length > 0 && this.presentedColumns.length > 0) {
593
+ this.activeCell = this.firstCellLocation();
594
+ }
595
+ }
596
+ sortModeChanged() {
597
+ this.schedulePresentationRefresh();
598
+ }
599
+ columnsChanged() {
600
+ this.captureActiveEditorSelection();
601
+ this.cancelEditIfSourceTargetInvalidated();
602
+ this.#presentationRetainingSessionId = this.#editingSession?.id ?? null;
603
+ this.#columnRevision += 1;
604
+ this.#sortKeyCache.clear();
605
+ this.schedulePresentationRefresh();
606
+ }
607
+ columnWidthsChanged() {
608
+ this.#columnRevision += 1;
609
+ this.schedulePresentationRefresh();
610
+ }
611
+ rowsChanged() {
612
+ if (this.rows.length === 0) {
613
+ this.editAnnouncement = "";
614
+ }
615
+ this.captureActiveEditorSelection();
616
+ this.cancelEditIfSourceTargetInvalidated();
617
+ this.#presentationRetainingSessionId = this.#editingSession?.id ?? null;
618
+ this.#rowPresentationCache.clear();
619
+ this.#sortKeyCache.clear();
620
+ this.schedulePresentationRefresh();
621
+ }
622
+ showFilterChanged() {
623
+ this.syncHostStates();
624
+ }
625
+ sortChanged() {
626
+ this.commitActiveEdit();
627
+ this.clearRangeSelectionState();
628
+ this.schedulePresentationRefresh();
629
+ }
630
+ selectedRowIdsChanged() {
631
+ this.#selectedRowIdSet = new Set(this.selectedRowIds ?? []);
632
+ this.#interactionRevision += 1;
633
+ this.syncRenderedRows();
634
+ }
635
+ activeCellChanged() {
636
+ if (this.focusMode !== "cell") {
637
+ return;
638
+ }
639
+ this.updateInteractionState();
640
+ this.ensureActiveCellVisible();
641
+ this.$emit("active-cell-change", this.activeCell);
642
+ }
643
+ cellSelectionChanged() {
644
+ if (this.focusMode !== "cell") {
645
+ return;
646
+ }
647
+ this.updateInteractionState();
648
+ this.$emit("cell-selection-change", this.cellSelection);
649
+ }
650
+ editingCellChanged() {
651
+ if (!this.editingCell) {
652
+ this.#editingSession = null;
653
+ this.editingError = "";
654
+ }
655
+ else if (!this.sameEditingLocation(this.#editingSession?.location, this.editingCell)) {
656
+ this.#editingSession = {
657
+ id: ++this.#nextEditingSessionId,
658
+ location: { ...this.editingCell },
659
+ };
660
+ this.editingError = "";
661
+ }
662
+ this.updateInteractionState();
663
+ if (!this.editingCell || !this.#editingSession) {
664
+ return;
665
+ }
666
+ this.scheduleEditorRestore(this.#editingSession.id);
667
+ }
668
+ fillPreviewChanged() {
669
+ if (this.focusMode !== "cell") {
670
+ return;
671
+ }
672
+ this.updateInteractionState();
673
+ }
674
+ estimatedRowHeightChanged() {
675
+ if (!this.#settingAutomaticEstimatedRowHeight) {
676
+ this.#automaticEstimatedRowHeight = false;
677
+ }
678
+ this.syncRenderedRows();
679
+ this.scheduleVirtualizerUpdate();
680
+ }
681
+ densityChanged() {
682
+ if (this.#automaticEstimatedRowHeight) {
683
+ this.#settingAutomaticEstimatedRowHeight = true;
684
+ this.estimatedRowHeight = this.rowHeightForDensity(this.density);
685
+ this.#settingAutomaticEstimatedRowHeight = false;
686
+ }
687
+ this.syncRenderedRows();
688
+ this.scheduleVirtualizerUpdate();
689
+ }
690
+ overscanCountChanged() {
691
+ this.syncRenderedRows();
692
+ this.scheduleVirtualizerUpdate();
693
+ }
694
+ get hasRows() {
695
+ return this.presentedRows.length > 0;
696
+ }
697
+ get columnSpan() {
698
+ return this.presentedColumns.length + 1;
699
+ }
700
+ get logicalRowCount() {
701
+ return this.presentedRows.length + 1;
702
+ }
703
+ get logicalColumnCount() {
704
+ return this.presentedColumns.length + (this.selectionMode === "none" ? 0 : 1);
705
+ }
706
+ get selectionHeaderId() {
707
+ return `${this.localName}-selection-header-${this.instanceId}`;
708
+ }
709
+ columnHeaderIdFor(columnId) {
710
+ return `${this.localName}-header-${this.instanceId}-${this.sanitizeForId(columnId)}`;
711
+ }
712
+ get filterQuery() {
713
+ return this.filterState.query ?? "";
714
+ }
715
+ get showsBuiltInFilter() {
716
+ return this.showFilter;
717
+ }
718
+ get shouldShowToolbar() {
719
+ return this.showsBuiltInFilter || this.hasToolbarSlotContent;
720
+ }
721
+ get activeCellLabelId() {
722
+ return `${this.localName}-active-cell-${this.instanceId}`;
723
+ }
724
+ get activeCellDescription() {
725
+ if (!this.activeCell) {
726
+ return "No active cell.";
727
+ }
728
+ const rowIndex = this.#rowIndexById.get(this.activeCell.rowId) ?? -1;
729
+ const columnIndex = this.#columnIndexById.get(this.activeCell.columnId) ?? -1;
730
+ const columnLabel = this.presentedColumns[columnIndex]?.label ?? this.activeCell.columnId;
731
+ const cellText = this.cellTextAt(this.activeCell) || "empty";
732
+ const description = this.columnAccessoryText(this.activeCell.columnId, this.presentedRows[rowIndex]?.data, "describe");
733
+ return `Active cell row ${rowIndex + 1}, column ${columnLabel}, value ${cellText}${description ? `, ${description}` : ""}.`;
734
+ }
735
+ get rowSummary() {
736
+ const totalRows = this.presentedRows.length;
737
+ const selectedRows = this.selectedRowIds.filter((id) => this.#rowIndexById.has(id)).length;
738
+ if (this.selectionMode === "none") {
739
+ return `${totalRows} row${totalRows === 1 ? "" : "s"}`;
740
+ }
741
+ return `${selectedRows} selected / ${totalRows} row${totalRows === 1 ? "" : "s"}`;
742
+ }
743
+ get selectionHeaderLabel() {
744
+ if (this.selectionMode === "multiple") {
745
+ return "Select rows";
746
+ }
747
+ // Named for what its radios do ("Open"), the same verb that begins each radio's name.
748
+ return this.selectionLabel?.trim() || "Selected row";
749
+ }
750
+ get selectionControlName() {
751
+ return `${this.localName}-selection-${this.instanceId}`;
752
+ }
753
+ get allRowsSelected() {
754
+ const selectedRowIds = this.selectedRowIds ?? [];
755
+ return (this.hasRows &&
756
+ selectedRowIds.length >= this.presentedRows.length &&
757
+ this.presentedRows.every((row) => this.#selectedRowIdSet.has(row.id)));
758
+ }
759
+ get partiallySelected() {
760
+ const selectedRowIds = this.selectedRowIds ?? [];
761
+ if (selectedRowIds.length === 0) {
762
+ return false;
763
+ }
764
+ const selectedCount = this.presentedRows.filter((row) => this.#selectedRowIdSet.has(row.id)).length;
765
+ return selectedCount > 0 && selectedCount < this.presentedRows.length;
766
+ }
767
+ sortStateFor(columnId) {
768
+ if (!this.sort || this.sort.columnId !== columnId) {
769
+ return "none";
770
+ }
771
+ return this.sort.direction;
772
+ }
773
+ sortDirectionFor(columnId) {
774
+ if (!this.sort || this.sort.columnId !== columnId) {
775
+ return "ascending";
776
+ }
777
+ return this.sort.direction;
778
+ }
779
+ isSortedColumn(columnId) {
780
+ return this.sort?.columnId === columnId;
781
+ }
782
+ sortIconNameFor(columnId) {
783
+ return this.sortDirectionFor(columnId) === "descending"
784
+ ? "system/sort-descending"
785
+ : "system/sort-ascending";
786
+ }
787
+ isRowSelected(rowId) {
788
+ return this.#selectedRowIdSet.has(rowId);
789
+ }
790
+ selectionLabelFor(rowId, rowLabel) {
791
+ const name = rowLabel?.trim() || rowId;
792
+ const verb = this.selectionLabel?.trim();
793
+ if (verb && this.selectionMode === "single") {
794
+ return `${verb} ${name}`;
795
+ }
796
+ return `Select row ${name}`;
797
+ }
798
+ handleToolbarSlotChange(event) {
799
+ const slot = event.target;
800
+ this.hasToolbarSlotContent = Boolean(slot?.assignedNodes({ flatten: true }).length);
801
+ }
802
+ handleFilterInput(event) {
803
+ const input = event.currentTarget;
804
+ if (this.editingCell && !this.commitActiveEdit()) {
805
+ if (input) {
806
+ input.value = this.filterState.query ?? "";
807
+ }
808
+ this.refocusActiveEditor();
809
+ return;
810
+ }
811
+ const nextState = {
812
+ ...this.filterState,
813
+ query: input?.value ?? "",
814
+ };
815
+ this.clearRangeSelectionState();
816
+ this.filterState = nextState;
817
+ this.$emit("filter-change", nextState);
818
+ }
819
+ handleSelectionControlPointerDown(event) {
820
+ event.stopPropagation();
821
+ }
822
+ handleSelectionControlClick(event) {
823
+ event.stopPropagation();
824
+ }
825
+ handleToggleAllCheckboxClick(event) {
826
+ event.stopPropagation();
827
+ const checkbox = event.currentTarget;
828
+ const nextChecked = !this.allRowsSelected;
829
+ if (checkbox) {
830
+ checkbox.checked = nextChecked;
831
+ if ("indeterminate" in checkbox) {
832
+ checkbox.indeterminate = false;
833
+ }
834
+ }
835
+ this.updateSelection(nextChecked ? this.presentedRows.map((row) => row.id) : []);
836
+ }
837
+ handleRowCheckboxClick(rowId, event) {
838
+ event.stopPropagation();
839
+ const checkbox = event.currentTarget;
840
+ const nextChecked = !(checkbox?.checked ?? false);
841
+ if (checkbox) {
842
+ checkbox.checked = nextChecked;
843
+ if ("indeterminate" in checkbox) {
844
+ checkbox.indeterminate = false;
845
+ }
846
+ }
847
+ const current = new Set(this.selectedRowIds);
848
+ if (nextChecked) {
849
+ current.add(rowId);
850
+ }
851
+ else {
852
+ current.delete(rowId);
853
+ }
854
+ this.updateSelection([...current]);
855
+ }
856
+ handleCellCheckboxClick(rowId, columnId, event) {
857
+ event.stopPropagation();
858
+ const location = { rowId, columnId };
859
+ if (this.editingCell &&
860
+ !this.sameEditingLocation(this.editingCell, location) &&
861
+ !this.commitActiveEdit()) {
862
+ this.refocusActiveEditor();
863
+ return;
864
+ }
865
+ const cell = this.presentedCellAt(location);
866
+ if (!cell?.editable || cell.editor !== "checkbox") {
867
+ return;
868
+ }
869
+ const checkbox = event.currentTarget;
870
+ const nextChecked = !this.booleanCellValue(cell.rawValue);
871
+ if (checkbox) {
872
+ checkbox.checked = nextChecked;
873
+ if ("indeterminate" in checkbox) {
874
+ checkbox.indeterminate = false;
875
+ }
876
+ }
877
+ this.commitCheckboxCellToggle(location, nextChecked);
878
+ }
879
+ handleGridFocus() {
880
+ if (this.focusMode !== "cell" ||
881
+ this.activeCell ||
882
+ !this.presentedRows.length ||
883
+ !this.presentedColumns.length) {
884
+ return;
885
+ }
886
+ this.activeCell = this.firstCellLocation();
887
+ }
888
+ /**
889
+ * Returns true to let the browser perform the key's default action.
890
+ *
891
+ * FAST cancels the default action of any `@event` binding whose expression
892
+ * does not return exactly `true` (`HTMLBindingDirective.handleEvent`). A
893
+ * `void` return therefore cancels every keystroke, including characters and
894
+ * Backspace typed into an open cell editor. Return false only for keys this
895
+ * handler consumes.
896
+ */
897
+ handleGridKeydown(event) {
898
+ if (this.focusMode !== "cell") {
899
+ return true;
900
+ }
901
+ if (event.isComposing || event.keyCode === 229) {
902
+ return true;
903
+ }
904
+ const target = event.target;
905
+ if (this.isEditorElement(target)) {
906
+ if (event.key === "Enter") {
907
+ event.preventDefault();
908
+ if (this.commitActiveEdit()) {
909
+ this.getScrollContainer()?.focus({ preventScroll: true });
910
+ }
911
+ else {
912
+ this.refocusActiveEditor();
913
+ }
914
+ return false;
915
+ }
916
+ if (event.key === "Tab") {
917
+ event.preventDefault();
918
+ this.commitEditingCellAndMove(event.shiftKey ? -1 : 1);
919
+ return false;
920
+ }
921
+ if (event.key === "Escape") {
922
+ event.preventDefault();
923
+ this.cancelActiveEdit();
924
+ this.getScrollContainer()?.focus({ preventScroll: true });
925
+ return false;
926
+ }
927
+ // Every other key belongs to the editor: typing, Backspace, caret
928
+ // movement. Cancelling here is what made cell editing impossible.
929
+ return true;
930
+ }
931
+ if (target && target !== this.getScrollContainer()) {
932
+ return true;
933
+ }
934
+ if (isColumnResizeShortcut(event) && this.activeCell) {
935
+ event.preventDefault();
936
+ return !this.focusColumnResizer(this.activeCell.columnId, this.getScrollContainer());
937
+ }
938
+ if (event.key === "Tab") {
939
+ const currentCell = this.activeCell ?? this.firstCellLocation();
940
+ if (!currentCell) {
941
+ return true;
942
+ }
943
+ const nextLocation = this.nextTabCellLocation(currentCell, event.shiftKey ? -1 : 1);
944
+ if (!nextLocation) {
945
+ return true;
946
+ }
947
+ event.preventDefault();
948
+ this.setActiveCell(nextLocation);
949
+ return false;
950
+ }
951
+ if ((event.metaKey || event.ctrlKey) &&
952
+ !event.shiftKey &&
953
+ !event.altKey &&
954
+ event.key.toLowerCase() === "c") {
955
+ // Let the browser run its native copy so `handleGridCopy` can write through
956
+ // `clipboardData` (works in insecure contexts and Safari). If no copy event
957
+ // follows, fall back to the async clipboard API.
958
+ this.#nativeCopyPending = true;
959
+ setTimeout(() => {
960
+ if (!this.#nativeCopyPending) {
961
+ return;
962
+ }
963
+ this.#nativeCopyPending = false;
964
+ void this.handleCopyRequest();
965
+ }, 0);
966
+ return true;
967
+ }
968
+ if ((event.key === " " || event.key === "Spacebar" || event.key === "Enter") &&
969
+ this.activeCell) {
970
+ const activeCell = this.presentedCellAt(this.activeCell);
971
+ if (activeCell?.editable && activeCell.editor === "checkbox") {
972
+ event.preventDefault();
973
+ this.commitCheckboxCellToggle(this.activeCell, !this.booleanCellValue(activeCell.rawValue));
974
+ return false;
975
+ }
976
+ }
977
+ if ((event.key === "Enter" || event.key === "F2") && this.activeCell) {
978
+ const editableCell = this.presentedCellAt(this.activeCell);
979
+ if (!editableCell?.editable) {
980
+ return true;
981
+ }
982
+ event.preventDefault();
983
+ this.startEditingCell(this.activeCell);
984
+ return false;
985
+ }
986
+ if (event.key === "ArrowUp" &&
987
+ !event.shiftKey &&
988
+ !event.altKey &&
989
+ !event.ctrlKey &&
990
+ !event.metaKey &&
991
+ this.activeCell &&
992
+ this.activeCell.rowId === this.presentedRows[0]?.id) {
993
+ const header = this.columnHeaderFocusTargetFor(this.activeCell.columnId);
994
+ if (header) {
995
+ event.preventDefault();
996
+ header.focus();
997
+ return false;
998
+ }
999
+ }
1000
+ const nextLocation = this.nextCellLocationForKey(event);
1001
+ if (!nextLocation) {
1002
+ return true;
1003
+ }
1004
+ event.preventDefault();
1005
+ this.setActiveCell(nextLocation, { extendRange: event.shiftKey });
1006
+ return false;
1007
+ }
1008
+ handleGridClick(event) {
1009
+ if (this.focusMode !== "cell") {
1010
+ return true;
1011
+ }
1012
+ if (this.#suppressNextGridClick) {
1013
+ this.#suppressNextGridClick = false;
1014
+ return true;
1015
+ }
1016
+ const target = event.target;
1017
+ if (this.isEditorEvent(event) ||
1018
+ this.isEditorElement(target) ||
1019
+ this.isInteractiveCellWidgetEvent(event) ||
1020
+ this.isInteractiveCellWidgetTarget(target)) {
1021
+ return true;
1022
+ }
1023
+ const pointerEvent = event;
1024
+ const location = this.locationFromMouseEvent(pointerEvent) ??
1025
+ this.locationFromEvent(event) ??
1026
+ this.locationFromTarget(target);
1027
+ if (!location) {
1028
+ if (pointerEvent.detail >= 2 && this.activeCell) {
1029
+ const activeCell = this.presentedCellAt(this.activeCell);
1030
+ if (activeCell?.editable && activeCell.editor !== "checkbox") {
1031
+ this.startEditingCell(this.activeCell);
1032
+ }
1033
+ }
1034
+ return true;
1035
+ }
1036
+ if (this.editingCell &&
1037
+ !this.sameEditingLocation(this.editingCell, location) &&
1038
+ !this.commitActiveEdit()) {
1039
+ this.refocusActiveEditor();
1040
+ return true;
1041
+ }
1042
+ const sameActiveCell = this.activeCell?.rowId === location.rowId && this.activeCell?.columnId === location.columnId;
1043
+ const activeCell = this.presentedCellAt(location);
1044
+ if (sameActiveCell &&
1045
+ activeCell?.editable &&
1046
+ this.opensOnSingleActiveClick(activeCell.editor)) {
1047
+ this.startEditingCell(location);
1048
+ return true;
1049
+ }
1050
+ this.handleCellPointerActivate(location.rowId, location.columnId, pointerEvent.shiftKey);
1051
+ const timestamp = typeof pointerEvent.timeStamp === "number" ? pointerEvent.timeStamp : performance.now();
1052
+ const sameCellAsLastClick = this.#lastCellClickLocation?.rowId === location.rowId &&
1053
+ this.#lastCellClickLocation?.columnId === location.columnId;
1054
+ const withinDoubleClickWindow = timestamp - this.#lastCellClickTimestamp <= 350;
1055
+ if (pointerEvent.detail >= 2 || (sameCellAsLastClick && withinDoubleClickWindow)) {
1056
+ const cell = this.presentedCellAt(location);
1057
+ if (cell?.editable && cell.editor !== "checkbox") {
1058
+ this.startEditingCell(location);
1059
+ }
1060
+ }
1061
+ this.#lastCellClickLocation = location;
1062
+ this.#lastCellClickTimestamp = timestamp;
1063
+ return true;
1064
+ }
1065
+ handleGridDoubleClick(event) {
1066
+ if (this.focusMode !== "cell") {
1067
+ return true;
1068
+ }
1069
+ const target = event.target;
1070
+ if ((!target && !this.locationFromEvent(event)) ||
1071
+ this.isEditorEvent(event) ||
1072
+ this.isEditorElement(target) ||
1073
+ this.isInteractiveCellWidgetEvent(event) ||
1074
+ this.isInteractiveCellWidgetTarget(target) ||
1075
+ this.isFillHandleEvent(event) ||
1076
+ this.isFillHandleTarget(target)) {
1077
+ return true;
1078
+ }
1079
+ const location = this.locationFromMouseEvent(event) ??
1080
+ this.locationFromEvent(event) ??
1081
+ this.locationFromTarget(target);
1082
+ if (!location) {
1083
+ if (this.activeCell) {
1084
+ const activeCell = this.presentedCellAt(this.activeCell);
1085
+ if (activeCell?.editable && activeCell.editor !== "checkbox") {
1086
+ event.preventDefault();
1087
+ this.startEditingCell(this.activeCell);
1088
+ return false;
1089
+ }
1090
+ }
1091
+ return true;
1092
+ }
1093
+ const cell = this.presentedCellAt(location);
1094
+ if (cell?.editor === "checkbox") {
1095
+ return true;
1096
+ }
1097
+ event.preventDefault();
1098
+ this.handleCellPointerActivate(location.rowId, location.columnId, false);
1099
+ this.startEditingCell(location);
1100
+ return false;
1101
+ }
1102
+ handleGridPointerDown(event) {
1103
+ if (this.focusMode !== "cell" ||
1104
+ event.button !== 0 ||
1105
+ event.shiftKey ||
1106
+ this.isEditorEvent(event) ||
1107
+ this.isEditorElement(event.target) ||
1108
+ this.isInteractiveCellWidgetEvent(event) ||
1109
+ this.isInteractiveCellWidgetTarget(event.target)) {
1110
+ return true;
1111
+ }
1112
+ if (this.isFillHandleEvent(event) || this.isFillHandleTarget(event.target)) {
1113
+ this.beginFillDrag(event);
1114
+ return false;
1115
+ }
1116
+ const location = this.locationFromEvent(event) ?? this.locationFromTarget(event.target);
1117
+ if (!location) {
1118
+ return true;
1119
+ }
1120
+ const scrollContainer = this.getScrollContainer();
1121
+ this.#pointerSelectionSession = startPointerSelectionSession(event.pointerId, location);
1122
+ this.setActiveCell(location);
1123
+ scrollContainer?.focus({ preventScroll: true });
1124
+ try {
1125
+ scrollContainer?.setPointerCapture(event.pointerId);
1126
+ }
1127
+ catch {
1128
+ // Synthetic Storybook pointer events do not always create a capturable pointer.
1129
+ }
1130
+ event.preventDefault();
1131
+ return false;
1132
+ }
1133
+ handleGridPointerMove(event) {
1134
+ if (isFillPointerEventForSession(this.#fillSession, event.pointerId)) {
1135
+ this.handleFillPointerMove(event);
1136
+ return;
1137
+ }
1138
+ const session = this.#pointerSelectionSession;
1139
+ if (this.focusMode !== "cell" || !isPointerSelectionEventForSession(session, event.pointerId)) {
1140
+ return;
1141
+ }
1142
+ const location = this.locationFromPointerEvent(event);
1143
+ if (!location) {
1144
+ return;
1145
+ }
1146
+ const anchor = session.anchor;
1147
+ if (!anchor) {
1148
+ return;
1149
+ }
1150
+ const currentFocus = this.cellSelection?.focus ?? anchor;
1151
+ if (currentFocus.rowId === location.rowId && currentFocus.columnId === location.columnId) {
1152
+ return;
1153
+ }
1154
+ this.#pointerSelectionSession = markPointerSelectionMoved(session);
1155
+ this.cellSelection = this.createCellSelection(anchor, location);
1156
+ this.updateInteractionState();
1157
+ }
1158
+ handleGridPointerUp(event) {
1159
+ if (isFillPointerEventForSession(this.#fillSession, event.pointerId)) {
1160
+ this.handleFillPointerUp();
1161
+ return;
1162
+ }
1163
+ if (!isPointerSelectionEventForSession(this.#pointerSelectionSession, event.pointerId)) {
1164
+ return;
1165
+ }
1166
+ this.endPointerSelection(true);
1167
+ }
1168
+ handleGridPointerCancel(event) {
1169
+ if (isFillPointerEventForSession(this.#fillSession, event.pointerId)) {
1170
+ this.endFillDrag(false);
1171
+ return;
1172
+ }
1173
+ if (!isPointerSelectionEventForSession(this.#pointerSelectionSession, event.pointerId)) {
1174
+ return;
1175
+ }
1176
+ this.endPointerSelection(false);
1177
+ }
1178
+ handleGridInput(event) {
1179
+ const target = event.target;
1180
+ if (!this.isEditorElement(target) || !this.editingCell) {
1181
+ return;
1182
+ }
1183
+ this.editingValue = this.editorValueFromTarget(target);
1184
+ if (this.editingError) {
1185
+ this.editingError = "";
1186
+ this.updateInteractionState();
1187
+ this.scheduleEditorRestore(this.#editingSession?.id ?? null);
1188
+ }
1189
+ }
1190
+ handleGridChange(event) {
1191
+ const target = event.target;
1192
+ if (this.isEditorElement(target) && this.editingCell) {
1193
+ this.editingValue = this.editorValueFromTarget(target);
1194
+ const cell = this.presentedCellAt(this.editingCell);
1195
+ if (cell?.editor === "select" || target.dataset.commitOnChange === "true") {
1196
+ if (this.commitActiveEdit()) {
1197
+ this.getScrollContainer()?.focus({ preventScroll: true });
1198
+ }
1199
+ else {
1200
+ this.refocusActiveEditor();
1201
+ }
1202
+ }
1203
+ return;
1204
+ }
1205
+ }
1206
+ handleGridPaste(event) {
1207
+ if (this.focusMode !== "cell" ||
1208
+ this.isEditorEvent(event) ||
1209
+ this.isEditorElement(event.target)) {
1210
+ return true;
1211
+ }
1212
+ const text = event.clipboardData?.getData("text/plain") ?? "";
1213
+ const detail = this.pasteDetailForText(text);
1214
+ if (!detail) {
1215
+ return true;
1216
+ }
1217
+ event.preventDefault();
1218
+ this.$emit("cell-paste", detail);
1219
+ return false;
1220
+ }
1221
+ handleGridFocusOut(event) {
1222
+ const target = event.target;
1223
+ if (!this.isEditorElement(target)) {
1224
+ return;
1225
+ }
1226
+ const sessionId = this.#editingSession?.id ?? null;
1227
+ const relatedTarget = event.relatedTarget;
1228
+ if (this.isTargetWithinEditingOwnership(relatedTarget)) {
1229
+ return;
1230
+ }
1231
+ // A concrete outside target is an intentional focus transfer. Resolve it
1232
+ // before a pending row refresh can mistake the departure for DOM recycling.
1233
+ if (relatedTarget) {
1234
+ if (!this.commitActiveEdit()) {
1235
+ this.refocusActiveEditor();
1236
+ }
1237
+ return;
1238
+ }
1239
+ if (sessionId && this.#presentationRetainingSessionId === sessionId) {
1240
+ this.captureEditorSelection(target, sessionId);
1241
+ this.scheduleEditorRestore(sessionId, true);
1242
+ return;
1243
+ }
1244
+ requestAnimationFrame(() => {
1245
+ if (!this.editingCell || !sessionId || this.#editingSession?.id !== sessionId) {
1246
+ return;
1247
+ }
1248
+ const currentEditor = this.getActiveEditorElement();
1249
+ if (currentEditor && currentEditor !== target) {
1250
+ seedEditorValue(currentEditor, this.editingValue);
1251
+ this.restoreEditorSelection(currentEditor, sessionId);
1252
+ return;
1253
+ }
1254
+ if (this.#presentationRetainingSessionId === sessionId &&
1255
+ currentEditor !== target &&
1256
+ this.presentedCellAt(this.#editingSession.location)?.editable) {
1257
+ this.captureEditorSelection(target, sessionId);
1258
+ this.scheduleEditorRestore(sessionId, true);
1259
+ return;
1260
+ }
1261
+ if (currentEditor?.matches?.(":focus-within")) {
1262
+ return;
1263
+ }
1264
+ const editorShadowActiveElement = currentEditor?.shadowRoot?.activeElement;
1265
+ if (editorShadowActiveElement) {
1266
+ return;
1267
+ }
1268
+ const activeElement = this.shadowRoot?.activeElement;
1269
+ if (activeElement && this.isEditorElement(activeElement)) {
1270
+ return;
1271
+ }
1272
+ if (!this.commitActiveEdit()) {
1273
+ this.refocusActiveEditor();
1274
+ }
1275
+ });
1276
+ }
1277
+ async handleCopyRequest() {
1278
+ const detail = this.copyDetailForCurrentSelection();
1279
+ if (!detail) {
1280
+ return;
1281
+ }
1282
+ this.$emit("cell-copy", detail);
1283
+ const clipboard = globalThis.navigator?.clipboard;
1284
+ if (!clipboard?.writeText) {
1285
+ this.$emit("cell-copy-error", { ...detail, error: new Error("Clipboard API is unavailable.") });
1286
+ return;
1287
+ }
1288
+ try {
1289
+ await clipboard.writeText(detail.text);
1290
+ }
1291
+ catch (error) {
1292
+ this.$emit("cell-copy-error", { ...detail, error });
1293
+ }
1294
+ }
1295
+ /** Handles the native `copy` event, writing TSV through `clipboardData`. */
1296
+ handleGridCopy(event) {
1297
+ if (this.focusMode !== "cell" ||
1298
+ this.isEditorEvent(event) ||
1299
+ this.isEditorElement(event.target)) {
1300
+ return true;
1301
+ }
1302
+ this.#nativeCopyPending = false;
1303
+ const detail = this.copyDetailForCurrentSelection();
1304
+ if (!detail || !event.clipboardData) {
1305
+ return true;
1306
+ }
1307
+ event.clipboardData.setData("text/plain", detail.text);
1308
+ event.preventDefault();
1309
+ this.$emit("cell-copy", detail);
1310
+ return false;
1311
+ }
1312
+ handleSortRequest(columnId) {
1313
+ if (this.editingCell && !this.commitActiveEdit()) {
1314
+ this.refocusActiveEditor();
1315
+ return;
1316
+ }
1317
+ const currentDirection = this.sort?.columnId === columnId ? this.sort.direction : null;
1318
+ let nextSort;
1319
+ if (currentDirection === null) {
1320
+ nextSort = { columnId, direction: "ascending" };
1321
+ }
1322
+ else if (currentDirection === "ascending") {
1323
+ nextSort = { columnId, direction: "descending" };
1324
+ }
1325
+ else {
1326
+ nextSort = null;
1327
+ }
1328
+ this.sort = nextSort;
1329
+ this.$emit("sort-change", nextSort);
1330
+ }
1331
+ handleColumnResizePointerDown(columnId, event) {
1332
+ const session = startColumnResizeSession({
1333
+ button: event.button,
1334
+ pointerId: event.pointerId,
1335
+ columnId,
1336
+ clientX: event.clientX,
1337
+ startWidth: this.renderedColumnWidth(columnId),
1338
+ });
1339
+ if (!session) {
1340
+ return;
1341
+ }
1342
+ event.preventDefault();
1343
+ event.stopPropagation();
1344
+ const handle = event.currentTarget;
1345
+ this.#columnResizeSession = session;
1346
+ this.#columnResizeHandle = handle;
1347
+ try {
1348
+ handle?.setPointerCapture(event.pointerId);
1349
+ }
1350
+ catch {
1351
+ // Ignore capture failures for synthetic Storybook pointer events.
1352
+ }
1353
+ }
1354
+ handleColumnResizePointerMove(event) {
1355
+ const session = this.#columnResizeSession;
1356
+ if (!isColumnResizeEventForSession(session, event.pointerId) || !session.columnId) {
1357
+ return;
1358
+ }
1359
+ event.preventDefault();
1360
+ event.stopPropagation();
1361
+ const width = computeResizedColumnWidth({
1362
+ session,
1363
+ clientX: event.clientX,
1364
+ minimumWidth: this.minimumColumnWidth(session.columnId),
1365
+ });
1366
+ this.applyLiveColumnWidth(session.columnId, `${width}px`);
1367
+ }
1368
+ handleColumnResizePointerUp(event) {
1369
+ const session = this.#columnResizeSession;
1370
+ if (!isColumnResizeEventForSession(session, event.pointerId) || !session.columnId) {
1371
+ return;
1372
+ }
1373
+ event.preventDefault();
1374
+ event.stopPropagation();
1375
+ const width = computeResizedColumnWidth({
1376
+ session,
1377
+ clientX: event.clientX,
1378
+ minimumWidth: this.minimumColumnWidth(session.columnId),
1379
+ });
1380
+ this.commitColumnWidth(session.columnId, `${width}px`);
1381
+ this.endColumnResize();
1382
+ }
1383
+ handleColumnResizePointerCancel(event) {
1384
+ const session = this.#columnResizeSession;
1385
+ if (!isColumnResizeEventForSession(session, event.pointerId) || !session.columnId) {
1386
+ return;
1387
+ }
1388
+ event.preventDefault();
1389
+ event.stopPropagation();
1390
+ this.applyLiveColumnWidth(session.columnId, this.resolvedColumnWidth(session.columnId));
1391
+ this.endColumnResize();
1392
+ }
1393
+ handleColumnResizeKeyDown(columnId, event) {
1394
+ if (event.key === "Escape") {
1395
+ event.preventDefault();
1396
+ event.stopPropagation();
1397
+ this.returnFocusFromColumnResizer(columnId);
1398
+ return false;
1399
+ }
1400
+ if (event.key === "Tab") {
1401
+ // Resizers are not Tab stops: Tab continues from where Ctrl+Alt+R came from.
1402
+ this.returnFocusFromColumnResizer(columnId);
1403
+ return true;
1404
+ }
1405
+ if (event.altKey || event.ctrlKey || event.metaKey) {
1406
+ return true;
1407
+ }
1408
+ if (event.key === "Enter") {
1409
+ this.handleColumnResizeDoubleClick(columnId, event);
1410
+ return false;
1411
+ }
1412
+ const width = computeKeyboardResizedColumnWidth({
1413
+ key: event.key,
1414
+ shiftKey: event.shiftKey,
1415
+ currentWidth: this.renderedColumnWidth(columnId),
1416
+ minimumWidth: this.minimumColumnWidth(columnId),
1417
+ rtl: getComputedStyle(this).direction === "rtl",
1418
+ });
1419
+ if (width === null) {
1420
+ return true;
1421
+ }
1422
+ event.preventDefault();
1423
+ event.stopPropagation();
1424
+ this.applyLiveColumnWidth(columnId, `${width}px`);
1425
+ this.commitColumnWidth(columnId, `${width}px`);
1426
+ return false;
1427
+ }
1428
+ /**
1429
+ * Tab index for a column header's focus target: its sort button, or the header cell when it is not
1430
+ * sortable. Row focus mode keeps one header in the tab order; cell focus mode keeps none, because the
1431
+ * grid itself is the Tab stop.
1432
+ */
1433
+ columnHeaderTabIndexFor(columnId) {
1434
+ if (this.focusMode === "cell") {
1435
+ return "-1";
1436
+ }
1437
+ const columns = this.presentedColumns;
1438
+ const tabStopColumnId = columns.some((column) => column.id === this.headerFocusColumnId)
1439
+ ? this.headerFocusColumnId
1440
+ : columns[0]?.id;
1441
+ return columnId === tabStopColumnId ? "0" : "-1";
1442
+ }
1443
+ handleColumnHeaderFocus(columnId, event) {
1444
+ if (event.target === this.columnHeaderFocusTargetFor(columnId)) {
1445
+ this.headerFocusColumnId = columnId;
1446
+ }
1447
+ }
1448
+ /**
1449
+ * Handles keydown on a column header: the arrow keys, Home and End move between headers, ArrowDown
1450
+ * returns to the first row in cell focus mode, Shift+Tab returns to the active cell in cell focus mode,
1451
+ * and Ctrl+Alt+R moves focus to the column's resizer. Enter and Space reach the sort button natively.
1452
+ */
1453
+ handleColumnHeaderKeydown(columnId, event) {
1454
+ const header = this.columnHeaderFocusTargetFor(columnId);
1455
+ // Keys pressed on the column's resizer bubble through the header cell.
1456
+ if (!header || event.target !== header) {
1457
+ return true;
1458
+ }
1459
+ if (isColumnResizeShortcut(event)) {
1460
+ event.preventDefault();
1461
+ return !this.focusColumnResizer(columnId, header);
1462
+ }
1463
+ if (event.altKey || event.ctrlKey || event.metaKey) {
1464
+ return true;
1465
+ }
1466
+ if (event.key === "Tab") {
1467
+ if (!event.shiftKey || this.focusMode !== "cell") {
1468
+ return true;
1469
+ }
1470
+ // The header sits above the body within the grid's single Tab stop.
1471
+ event.preventDefault();
1472
+ this.getScrollContainer()?.focus({ preventScroll: true });
1473
+ return false;
1474
+ }
1475
+ if (event.shiftKey) {
1476
+ return true;
1477
+ }
1478
+ const columns = this.presentedColumns;
1479
+ const columnIndex = columns.findIndex((column) => column.id === columnId);
1480
+ let nextColumnId;
1481
+ switch (logicalArrowKey(event.key, this)) {
1482
+ case "ArrowLeft":
1483
+ nextColumnId = columns[Math.max(0, columnIndex - 1)]?.id;
1484
+ break;
1485
+ case "ArrowRight":
1486
+ nextColumnId = columns[Math.min(columns.length - 1, columnIndex + 1)]?.id;
1487
+ break;
1488
+ case "Home":
1489
+ nextColumnId = columns[0]?.id;
1490
+ break;
1491
+ case "End":
1492
+ nextColumnId = columns.at(-1)?.id;
1493
+ break;
1494
+ case "ArrowDown":
1495
+ return this.focusFirstRowFromHeader(columnId, event);
1496
+ default:
1497
+ return true;
1498
+ }
1499
+ event.preventDefault();
1500
+ if (nextColumnId) {
1501
+ this.columnHeaderFocusTargetFor(nextColumnId)?.focus();
1502
+ }
1503
+ return false;
1504
+ }
1505
+ handleColumnResizeDoubleClick(columnId, event) {
1506
+ event.preventDefault();
1507
+ event.stopPropagation();
1508
+ const width = `${this.autosizedColumnWidth(columnId)}px`;
1509
+ this.applyLiveColumnWidth(columnId, width);
1510
+ this.commitColumnWidth(columnId, width);
1511
+ }
1512
+ columnResizerFor(columnId) {
1513
+ return (this.shadowRoot?.querySelector(`[data-column-resizer="${CSS.escape(columnId)}"]`) ?? null);
1514
+ }
1515
+ /**
1516
+ * The element that takes focus for a column header: its sort button, or the header cell itself.
1517
+ */
1518
+ columnHeaderFocusTargetFor(columnId) {
1519
+ const header = this.shadowRoot?.querySelector(`th[data-column-id="${CSS.escape(columnId)}"]`);
1520
+ if (!header) {
1521
+ return null;
1522
+ }
1523
+ return header.querySelector(".header-button") ?? header;
1524
+ }
1525
+ focusFirstRowFromHeader(columnId, event) {
1526
+ const rowId = this.presentedRows[0]?.id;
1527
+ if (this.focusMode !== "cell" || !rowId) {
1528
+ return true;
1529
+ }
1530
+ event.preventDefault();
1531
+ this.setActiveCell({ rowId, columnId });
1532
+ this.getScrollContainer()?.focus({ preventScroll: true });
1533
+ return false;
1534
+ }
1535
+ focusColumnResizer(columnId, returnTarget) {
1536
+ const resizer = this.columnResizerFor(columnId);
1537
+ if (!resizer) {
1538
+ return false;
1539
+ }
1540
+ this.#columnResizeReturnTarget = returnTarget;
1541
+ resizer.focus();
1542
+ return true;
1543
+ }
1544
+ returnFocusFromColumnResizer(columnId) {
1545
+ const returnTarget = this.#columnResizeReturnTarget;
1546
+ this.#columnResizeReturnTarget = null;
1547
+ const fallback = this.columnHeaderFocusTargetFor(columnId) ?? this.getScrollContainer();
1548
+ (returnTarget?.isConnected ? returnTarget : fallback)?.focus({ preventScroll: true });
1549
+ }
1550
+ handleToggleAll(event) {
1551
+ const input = event.currentTarget;
1552
+ const nextSelected = input?.checked ? this.presentedRows.map((row) => row.id) : [];
1553
+ this.updateSelection(nextSelected);
1554
+ }
1555
+ handleRowSelection(rowId, event) {
1556
+ if (this.selectionMode === "none") {
1557
+ return;
1558
+ }
1559
+ const input = event.currentTarget;
1560
+ const checked = Boolean(input?.checked);
1561
+ if (this.selectionMode === "single") {
1562
+ this.updateSelection(checked ? [rowId] : []);
1563
+ return;
1564
+ }
1565
+ const current = new Set(this.selectedRowIds);
1566
+ if (checked) {
1567
+ current.add(rowId);
1568
+ }
1569
+ else {
1570
+ current.delete(rowId);
1571
+ }
1572
+ this.updateSelection([...current]);
1573
+ }
1574
+ handleCellPointerActivate(rowId, columnId, extendRange = false) {
1575
+ if (this.focusMode !== "cell") {
1576
+ return;
1577
+ }
1578
+ this.editAnnouncement = "";
1579
+ this.setActiveCell({ rowId, columnId }, { extendRange });
1580
+ this.getScrollContainer()?.focus({ preventScroll: true });
1581
+ }
1582
+ updateSelection(nextSelectedRowIds) {
1583
+ const uniqueSelected = [...new Set(nextSelectedRowIds)];
1584
+ this.selectedRowIds = uniqueSelected;
1585
+ this.$emit("selection-change", { selectedRowIds: uniqueSelected });
1586
+ }
1587
+ clearRangeSelectionState() {
1588
+ // Row selection is keyed by row id, so it intentionally survives sort and
1589
+ // filter changes; only the positional range/fill state is reset here.
1590
+ if (this.cellSelection) {
1591
+ this.cellSelection = null;
1592
+ }
1593
+ if (this.fillPreview) {
1594
+ this.fillPreview = null;
1595
+ }
1596
+ }
1597
+ commitColumnWidth(columnId, width) {
1598
+ const nextWidths = {
1599
+ ...(this.columnWidths ?? {}),
1600
+ [columnId]: width,
1601
+ };
1602
+ this.columnWidths = nextWidths;
1603
+ this.$emit("column-width-change", {
1604
+ columnId,
1605
+ width,
1606
+ columnWidths: nextWidths,
1607
+ });
1608
+ }
1609
+ endColumnResize() {
1610
+ if (this.#columnResizeHandle &&
1611
+ this.#columnResizeSession.pointerId !== null &&
1612
+ this.#columnResizeHandle.hasPointerCapture?.(this.#columnResizeSession.pointerId)) {
1613
+ try {
1614
+ this.#columnResizeHandle.releasePointerCapture(this.#columnResizeSession.pointerId);
1615
+ }
1616
+ catch {
1617
+ // Ignore release failures for synthetic Storybook pointer events.
1618
+ }
1619
+ }
1620
+ this.#columnResizeSession = clearedColumnResizeSession();
1621
+ this.#columnResizeHandle = null;
1622
+ }
1623
+ schedulePresentationRefresh() {
1624
+ if (!this.$fastController.isConnected) {
1625
+ return;
1626
+ }
1627
+ this.refreshPresentation();
1628
+ }
1629
+ refreshPresentation() {
1630
+ this.#presentationRevision += 1;
1631
+ const sourceColumns = this.columns ?? [];
1632
+ const sourceRows = this.rows ?? [];
1633
+ const sourceSelectedRowIds = this.selectedRowIds ?? [];
1634
+ const presentedColumns = sourceColumns.map((column) => this.createPresentedColumn(column));
1635
+ const sortedRows = this.sortRows(sourceRows, presentedColumns);
1636
+ const validSelectedIds = new Set(sortedRows.map((row) => row.id));
1637
+ const sourceRowsById = new Map(sourceRows.map((row) => [row.id, row]));
1638
+ const prunedSelection = sourceSelectedRowIds.filter((id) => validSelectedIds.has(id));
1639
+ if (prunedSelection.length !== sourceSelectedRowIds.length) {
1640
+ this.selectedRowIds = prunedSelection;
1641
+ this.$emit("selection-change", { selectedRowIds: prunedSelection });
1642
+ }
1643
+ this.presentedColumns = presentedColumns;
1644
+ this.#columnIndexById = new Map(presentedColumns.map((column, index) => [column.id, index]));
1645
+ this.#rowIndexById = new Map(sortedRows.map((row, index) => [row.id, index]));
1646
+ this.#selectedRowIdSet = new Set(prunedSelection);
1647
+ this.presentedRows = sortedRows.map((row) => this.createPresentedRow(row, presentedColumns));
1648
+ for (const [rowId, cached] of this.#rowPresentationCache) {
1649
+ if (!validSelectedIds.has(rowId) || sourceRowsById.get(rowId) !== cached.source) {
1650
+ this.#rowPresentationCache.delete(rowId);
1651
+ }
1652
+ }
1653
+ for (const [rowId, cached] of this.#sortKeyCache) {
1654
+ if (!validSelectedIds.has(rowId) || sourceRowsById.get(rowId) !== cached.source) {
1655
+ this.#sortKeyCache.delete(rowId);
1656
+ }
1657
+ }
1658
+ this.syncActiveCell();
1659
+ this.syncCellSelection();
1660
+ this.syncEditingCell();
1661
+ this.syncFillPreview();
1662
+ this.updateInteractionState();
1663
+ this.syncRenderedRows();
1664
+ this.scheduleVirtualizerUpdate();
1665
+ this.syncHostStates();
1666
+ }
1667
+ createPresentedColumn(column) {
1668
+ return buildPresentedColumn(column, {
1669
+ resolvedWidth: this.columnWidths?.[column.id] ?? column.width,
1670
+ mergePartNames: (base, extra) => this.mergePartNames(base, extra),
1671
+ });
1672
+ }
1673
+ createPresentedRow(row, columns) {
1674
+ const cached = this.#rowPresentationCache.get(row.id);
1675
+ if (cached?.source === row && cached.columnRevision === this.#columnRevision) {
1676
+ return cached.row;
1677
+ }
1678
+ const rowLabel = row.label?.trim() || row.id;
1679
+ let materializedCells = null;
1680
+ const presentedRow = {
1681
+ id: row.id,
1682
+ label: rowLabel,
1683
+ data: row.data,
1684
+ };
1685
+ const baseCells = () => {
1686
+ if (!materializedCells) {
1687
+ materializedCells = buildPresentedRow(row, columns, {
1688
+ cellValueFor: (rowValue, column) => this.cellValueFor(rowValue, column),
1689
+ serializeCellValue: (column, rowData, rawValue) => this.serializeCellValue(column, rowData, rawValue),
1690
+ cellIdFor: (rowId, columnId) => this.cellIdFor(rowId, columnId),
1691
+ editingErrorIdFor: (rowId, columnId) => this.cellEditorErrorIdFor(rowId, columnId),
1692
+ editorOptionsForColumn: (column, rowData) => this.editorOptionsForColumn(column, rowData),
1693
+ }).cells;
1694
+ }
1695
+ return materializedCells;
1696
+ };
1697
+ this.#baseCellsByPresentedRow.set(presentedRow, baseCells);
1698
+ Object.defineProperty(presentedRow, "cells", {
1699
+ configurable: false,
1700
+ enumerable: true,
1701
+ get: () => {
1702
+ const cells = baseCells();
1703
+ if (this.focusMode !== "cell") {
1704
+ return cells;
1705
+ }
1706
+ const rowIndex = this.#rowIndexById.get(row.id);
1707
+ if (rowIndex === undefined) {
1708
+ return cells;
1709
+ }
1710
+ return this.withInteractionState(presentedRow, rowIndex, this.interactionSnapshot()).cells;
1711
+ },
1712
+ });
1713
+ this.#rowPresentationCache.set(row.id, {
1714
+ source: row,
1715
+ columnRevision: this.#columnRevision,
1716
+ row: presentedRow,
1717
+ });
1718
+ return presentedRow;
1719
+ }
1720
+ updateInteractionState() {
1721
+ this.#interactionRevision += 1;
1722
+ this.syncRenderedRows();
1723
+ }
1724
+ withInteractionState(row, rowIndex, snapshot) {
1725
+ if (this.focusMode !== "cell") {
1726
+ return row;
1727
+ }
1728
+ const cached = this.#decoratedRowCache.get(row.id);
1729
+ if (cached?.source === row && cached.interactionRevision === this.#interactionRevision) {
1730
+ return cached.row;
1731
+ }
1732
+ const baseCells = this.#baseCellsByPresentedRow.get(row)?.() ?? row.cells;
1733
+ const decoratedRow = {
1734
+ id: row.id,
1735
+ label: row.label,
1736
+ data: row.data,
1737
+ cells: baseCells.map((cell, columnIndex) => {
1738
+ const indices = { rowIndex, columnIndex };
1739
+ const selected = computeIsCellSelected(snapshot.selectionBounds, indices);
1740
+ const rangeEdge = computeRangeEdgeForCell(snapshot.selectionBounds, indices);
1741
+ const fillPreview = computeIsFillPreviewCell(snapshot.fillPreviewBounds, snapshot.fillSourceBounds, indices);
1742
+ const active = this.isActiveCell(cell.rowId, cell.columnId);
1743
+ const editing = this.isEditingCell(cell.rowId, cell.columnId);
1744
+ const editingHint = editing && !this.editingError
1745
+ ? this.columnAccessoryText(cell.columnId, cell.rowData, "editorHint")
1746
+ : "";
1747
+ return {
1748
+ ...cell,
1749
+ active,
1750
+ selected,
1751
+ fillPreview,
1752
+ rangeEdge,
1753
+ editing,
1754
+ editValue: editing ? this.editingValue : "",
1755
+ editingError: editing ? this.editingError : "",
1756
+ editingHint,
1757
+ editingHintId: editingHint ? this.cellEditorHintIdFor(cell.rowId, cell.columnId) : "",
1758
+ resolvedCellPartText: composeCellPartText(cell.cellPartText, {
1759
+ selected,
1760
+ rangeEdge,
1761
+ fillPreview,
1762
+ active,
1763
+ editing,
1764
+ }),
1765
+ };
1766
+ }),
1767
+ };
1768
+ this.#decoratedRowCache.set(row.id, {
1769
+ source: row,
1770
+ interactionRevision: this.#interactionRevision,
1771
+ row: decoratedRow,
1772
+ });
1773
+ return decoratedRow;
1774
+ }
1775
+ resolvedColumnWidth(columnId) {
1776
+ return resolveGridColumnWidth(columnId, this.columnWidths, this.columns);
1777
+ }
1778
+ renderedColumnWidth(columnId) {
1779
+ const headerCell = this.headerCellElement(columnId);
1780
+ return computeRenderedColumnWidth({
1781
+ headerCell,
1782
+ resolvedWidth: this.resolvedColumnWidth(columnId),
1783
+ });
1784
+ }
1785
+ minimumColumnWidth(columnId) {
1786
+ const headerCell = this.headerCellElement(columnId);
1787
+ return computeMinimumColumnWidth(headerCell);
1788
+ }
1789
+ applyLiveColumnWidth(columnId, width) {
1790
+ const value = width ?? "";
1791
+ const rowId = CSS.escape(columnId);
1792
+ this.shadowRoot?.querySelectorAll(`[data-column-id="${rowId}"]`).forEach((element) => {
1793
+ const style = element.style;
1794
+ style.width = value;
1795
+ style.inlineSize = value;
1796
+ style.minInlineSize = value;
1797
+ style.maxInlineSize = value;
1798
+ });
1799
+ }
1800
+ headerCellElement(columnId) {
1801
+ const escaped = CSS.escape(columnId);
1802
+ return this.shadowRoot?.querySelector(`th[data-column-id="${escaped}"]`);
1803
+ }
1804
+ autosizedColumnWidth(columnId) {
1805
+ const columnIndex = this.#columnIndexById.get(columnId);
1806
+ const column = columnIndex === undefined ? undefined : this.presentedColumns[columnIndex];
1807
+ const headerCell = this.headerCellElement(columnId);
1808
+ const sampleCell = this.cellElementForLocation(this.presentedRows[0] ? { rowId: this.presentedRows[0].id, columnId } : null);
1809
+ if (!this.#measurementCanvas) {
1810
+ this.#measurementCanvas = document.createElement("canvas");
1811
+ }
1812
+ const canvas = this.#measurementCanvas;
1813
+ return computeAutosizedColumnWidth({
1814
+ columnId,
1815
+ column: column ?? null,
1816
+ rows: this.presentedRows,
1817
+ headerCell,
1818
+ sampleCell,
1819
+ getCellText: (location) => this.cellTextAt(location),
1820
+ sampleRows: sampleAutosizeRows(this.presentedRows),
1821
+ measurementCanvas: canvas,
1822
+ fontSource: this,
1823
+ });
1824
+ }
1825
+ cellValueFor(row, column) {
1826
+ return resolveCellValue(row, column.source);
1827
+ }
1828
+ editorOptionsForColumn(column, rowData) {
1829
+ return resolveEditorOptionsForColumn(column, rowData);
1830
+ }
1831
+ serializeCellValue(column, rowData, rawValue) {
1832
+ return serializeGridCellValue({
1833
+ column,
1834
+ rowData,
1835
+ rawValue,
1836
+ booleanCellValue: (value) => this.booleanCellValue(value),
1837
+ });
1838
+ }
1839
+ sortRows(rows, columns) {
1840
+ return sortGridRows({
1841
+ rows,
1842
+ columns: columns.map((column) => column.source),
1843
+ sort: this.sort,
1844
+ sortMode: this.sortMode,
1845
+ getSortKey: (row, column) => this.sortKeyFor(row, column),
1846
+ });
1847
+ }
1848
+ sortKeyFor(row, column) {
1849
+ const cached = this.#sortKeyCache.get(row.id);
1850
+ if (cached?.source === row && cached.column === column) {
1851
+ return cached.key;
1852
+ }
1853
+ const key = stringifyCellValue(resolveCellValue(row, column));
1854
+ this.#sortKeyCache.set(row.id, {
1855
+ source: row,
1856
+ column: column,
1857
+ key,
1858
+ });
1859
+ return key;
1860
+ }
1861
+ syncActiveCell() {
1862
+ this.activeCell = syncPresentedActiveCell({
1863
+ focusMode: this.focusMode,
1864
+ rows: this.presentedRows,
1865
+ columns: this.presentedColumns,
1866
+ activeCell: this.activeCell,
1867
+ });
1868
+ }
1869
+ syncCellSelection() {
1870
+ this.cellSelection = syncPresentedCellSelection({
1871
+ focusMode: this.focusMode,
1872
+ activeCell: this.activeCell,
1873
+ cellSelection: this.cellSelection,
1874
+ isValidLocation: (location) => this.isValidCellLocation(location),
1875
+ });
1876
+ }
1877
+ syncFillPreview() {
1878
+ this.fillPreview = syncPresentedFillPreview({
1879
+ focusMode: this.focusMode,
1880
+ fillPreview: this.fillPreview,
1881
+ isValidLocation: (location) => this.isValidCellLocation(location),
1882
+ });
1883
+ }
1884
+ syncEditingCell() {
1885
+ const nextState = syncEditingState({
1886
+ focusMode: this.focusMode,
1887
+ editingCell: this.editingCell,
1888
+ editingValue: this.editingValue,
1889
+ isEditableLocation: (location) => Boolean(this.presentedCellAt(location)?.editable),
1890
+ });
1891
+ if (this.editingCell && !nextState.editingCell) {
1892
+ this.cancelActiveEdit();
1893
+ return;
1894
+ }
1895
+ this.editingCell = nextState.editingCell;
1896
+ this.editingValue = nextState.editingValue;
1897
+ if (this.#editingSession) {
1898
+ this.scheduleEditorRestore(this.#editingSession.id);
1899
+ }
1900
+ }
1901
+ firstCellLocation() {
1902
+ return resolveNavigationFirstCellLocation(this.presentedRows, this.presentedColumns);
1903
+ }
1904
+ nextCellLocationForKey(event) {
1905
+ return resolveNextCellLocationForKey({
1906
+ rows: this.presentedRows,
1907
+ columns: this.presentedColumns,
1908
+ activeCell: this.activeCell,
1909
+ key: event.key,
1910
+ metaKey: event.ctrlKey || event.metaKey,
1911
+ });
1912
+ }
1913
+ setActiveCell(location, options = {}) {
1914
+ const extendRange = options.extendRange ?? false;
1915
+ if (!this.sameEditingLocation(this.activeCell, location)) {
1916
+ this.editAnnouncement = "";
1917
+ }
1918
+ if (extendRange) {
1919
+ const anchor = this.cellSelection?.anchor ?? this.activeCell ?? location;
1920
+ this.cellSelection = this.createCellSelection(anchor, location);
1921
+ }
1922
+ else if (this.cellSelection) {
1923
+ this.cellSelection = null;
1924
+ }
1925
+ this.activeCell = location;
1926
+ this.updateInteractionState();
1927
+ }
1928
+ startEditingCell(location) {
1929
+ if (this.editingCell) {
1930
+ if (this.sameEditingLocation(this.editingCell, location)) {
1931
+ this.refocusActiveEditor();
1932
+ return;
1933
+ }
1934
+ if (!this.commitActiveEdit()) {
1935
+ this.refocusActiveEditor();
1936
+ return;
1937
+ }
1938
+ }
1939
+ const cell = this.presentedCellAt(location);
1940
+ const nextState = beginEditingState(location, cell, cell ? this.editStringForCell(cell) : "");
1941
+ if (!nextState) {
1942
+ return;
1943
+ }
1944
+ this.cellSelection = null;
1945
+ this.editAnnouncement = "";
1946
+ this.editingError = "";
1947
+ this.#editingSession = {
1948
+ id: ++this.#nextEditingSessionId,
1949
+ location: { ...location },
1950
+ };
1951
+ this.editingValue = nextState.editingValue;
1952
+ this.editingCell = nextState.editingCell;
1953
+ this.$emit("edit-start", location);
1954
+ }
1955
+ opensOnSingleActiveClick(editor) {
1956
+ return editorOpensOnSingleActiveClick(editor);
1957
+ }
1958
+ /**
1959
+ * Commit the active edit synchronously.
1960
+ *
1961
+ * Returns true only when one session resolves. False means either there
1962
+ * was no edit or validation retained the same session; inspect
1963
+ * `editingCell` before and after when the distinction matters.
1964
+ */
1965
+ commitActiveEdit() {
1966
+ const session = this.currentEditingSession();
1967
+ if (!session || this.#resolvingEditingSessionId === session.id) {
1968
+ return false;
1969
+ }
1970
+ const cell = this.presentedCellAt(session.location);
1971
+ if (!cell?.editable || cell.editor === "checkbox") {
1972
+ return this.cancelActiveEdit();
1973
+ }
1974
+ const editor = this.getActiveEditorElement();
1975
+ if (editor) {
1976
+ this.editingValue = this.editorValueFromTarget(editor);
1977
+ }
1978
+ this.#resolvingEditingSessionId = session.id;
1979
+ const resolution = resolveEditingValue(cell, this.editingValue);
1980
+ this.#resolvingEditingSessionId = null;
1981
+ if (this.#editingSession?.id !== session.id) {
1982
+ return false;
1983
+ }
1984
+ if (!resolution.valid) {
1985
+ this.editingError = resolution.message;
1986
+ this.updateInteractionState();
1987
+ this.scheduleEditorRestore(session.id);
1988
+ return false;
1989
+ }
1990
+ const detail = {
1991
+ rowId: session.location.rowId,
1992
+ columnId: session.location.columnId,
1993
+ value: resolution.value,
1994
+ };
1995
+ this.clearEditingSession(session.id);
1996
+ this.$emit("cell-change", detail);
1997
+ return true;
1998
+ }
1999
+ commitEditingCell() {
2000
+ return this.commitActiveEdit();
2001
+ }
2002
+ commitEditingCellAndMove(direction) {
2003
+ const currentCell = this.editingCell;
2004
+ if (!currentCell) {
2005
+ return;
2006
+ }
2007
+ if (!this.commitActiveEdit()) {
2008
+ this.refocusActiveEditor();
2009
+ return;
2010
+ }
2011
+ const nextCell = this.nextTabCellLocation(currentCell, direction);
2012
+ this.setActiveCell(nextCell ?? currentCell);
2013
+ this.getScrollContainer()?.focus({ preventScroll: true });
2014
+ }
2015
+ /** Cancel the active edit synchronously and emit `edit-cancel` once. */
2016
+ cancelActiveEdit() {
2017
+ const session = this.currentEditingSession();
2018
+ if (!session) {
2019
+ return false;
2020
+ }
2021
+ const result = clearEditingState(session.location);
2022
+ this.clearEditingSession(session.id);
2023
+ this.$emit("edit-cancel", result.cancelledCell);
2024
+ return true;
2025
+ }
2026
+ /**
2027
+ * Fills from the current cell selection, or the active cell, without dragging (WCAG 2.5.7).
2028
+ * The source extends `count` rows or columns in `direction` and the new cells are filled exactly as
2029
+ * dragging the fill handle there would: the target stops at the first strip with a read-only
2030
+ * cell, the source tiles across it, `cell-fill` is emitted with the same detail, and the filled
2031
+ * range becomes the cell selection. Consumers can call it from a row or cell menu.
2032
+ * @returns The emitted `cell-fill` detail, or `null` when nothing was filled.
2033
+ */
2034
+ fillSelection(direction, count = 1) {
2035
+ if (this.focusMode !== "cell" || this.editingCell) {
2036
+ return null;
2037
+ }
2038
+ const source = this.currentFillSourceRange();
2039
+ const sourceBounds = this.boundsForRange(source);
2040
+ const steps = Math.floor(count);
2041
+ if (!source || !sourceBounds || !(steps >= 1) || !this.hasEditableCellsInRange(source)) {
2042
+ return null;
2043
+ }
2044
+ const lastRow = this.presentedRows.length - 1;
2045
+ const lastColumn = this.presentedColumns.length - 1;
2046
+ const rowIndex = direction === "down"
2047
+ ? Math.min(lastRow, sourceBounds.rowEnd + steps)
2048
+ : direction === "up"
2049
+ ? Math.max(0, sourceBounds.rowStart - steps)
2050
+ : sourceBounds.rowEnd;
2051
+ const columnIndex = direction === "right"
2052
+ ? Math.min(lastColumn, sourceBounds.columnEnd + steps)
2053
+ : direction === "left"
2054
+ ? Math.max(0, sourceBounds.columnStart - steps)
2055
+ : sourceBounds.columnEnd;
2056
+ const location = this.locationForIndices(rowIndex, columnIndex);
2057
+ const target = location ? this.fillPreviewRangeForLocation(location, source) : null;
2058
+ if (!target) {
2059
+ return null;
2060
+ }
2061
+ const detail = this.fillDetailFor(source, target);
2062
+ if (detail) {
2063
+ this.$emit("cell-fill", detail);
2064
+ }
2065
+ this.cellSelection = this.createCellSelection(target.anchor, target.focus);
2066
+ return detail;
2067
+ }
2068
+ currentEditingSession() {
2069
+ if (!this.editingCell) {
2070
+ return null;
2071
+ }
2072
+ if (this.sameEditingLocation(this.#editingSession?.location, this.editingCell)) {
2073
+ return this.#editingSession;
2074
+ }
2075
+ this.#editingSession = {
2076
+ id: ++this.#nextEditingSessionId,
2077
+ location: { ...this.editingCell },
2078
+ };
2079
+ return this.#editingSession;
2080
+ }
2081
+ clearEditingSession(sessionId) {
2082
+ if (this.#editingSession?.id !== sessionId) {
2083
+ return;
2084
+ }
2085
+ this.#editingSession = null;
2086
+ this.#editingEditorElement = null;
2087
+ this.#pendingEditorSelection = null;
2088
+ this.#presentationRetainingSessionId = null;
2089
+ this.#resolvingEditingSessionId = null;
2090
+ this.editingCell = null;
2091
+ this.editingValue = "";
2092
+ this.editingError = "";
2093
+ }
2094
+ sameEditingLocation(left, right) {
2095
+ return Boolean(left && right && left.rowId === right.rowId && left.columnId === right.columnId);
2096
+ }
2097
+ cancelEditIfSourceTargetInvalidated() {
2098
+ const location = this.editingCell;
2099
+ if (!location) {
2100
+ return;
2101
+ }
2102
+ const rowExists = (this.rows ?? []).some((row) => row.id === location.rowId);
2103
+ const column = (this.columns ?? []).find((column) => column.id === location.columnId);
2104
+ if (!rowExists || !column?.editable || column.editor === "checkbox") {
2105
+ this.cancelActiveEdit();
2106
+ }
2107
+ }
2108
+ scheduleEditorRestore(sessionId, forceFocus = false, attempt = 0) {
2109
+ if (!sessionId) {
2110
+ return;
2111
+ }
2112
+ if (this.#editorRestoreFrame !== null) {
2113
+ cancelAnimationFrame(this.#editorRestoreFrame);
2114
+ }
2115
+ this.#editorRestoreFrame = requestAnimationFrame(() => {
2116
+ this.#editorRestoreFrame = null;
2117
+ if (this.#editingSession?.id !== sessionId) {
2118
+ return;
2119
+ }
2120
+ const editor = this.getActiveEditorElement();
2121
+ if (!editor) {
2122
+ if (this.#presentationRetainingSessionId === sessionId && attempt < 3) {
2123
+ this.scheduleEditorRestore(sessionId, forceFocus, attempt + 1);
2124
+ return;
2125
+ }
2126
+ if (this.#presentationRetainingSessionId === sessionId) {
2127
+ this.cancelActiveEdit();
2128
+ }
2129
+ return;
2130
+ }
2131
+ if (editor === this.#editingEditorElement) {
2132
+ // FAST may move the same editor node while rebinding rows. Firefox
2133
+ // and WebKit drop focus on that move without replacing the element.
2134
+ if (forceFocus || this.#presentationRetainingSessionId === sessionId) {
2135
+ editor?.focus?.({ preventScroll: true });
2136
+ }
2137
+ if (this.#presentationRetainingSessionId === sessionId && attempt < 3) {
2138
+ this.scheduleEditorRestore(sessionId, forceFocus, attempt + 1);
2139
+ return;
2140
+ }
2141
+ this.#presentationRetainingSessionId = null;
2142
+ return;
2143
+ }
2144
+ seedEditorValue(editor, this.editingValue);
2145
+ this.restoreEditorSelection(editor, sessionId);
2146
+ this.#editingEditorElement = editor;
2147
+ if (this.#presentationRetainingSessionId === sessionId && attempt < 3) {
2148
+ this.scheduleEditorRestore(sessionId, true, attempt + 1);
2149
+ return;
2150
+ }
2151
+ this.#presentationRetainingSessionId = null;
2152
+ });
2153
+ }
2154
+ captureActiveEditorSelection() {
2155
+ const sessionId = this.#editingSession?.id;
2156
+ const editor = this.getActiveEditorElement();
2157
+ if (sessionId && editor) {
2158
+ this.captureEditorSelection(editor, sessionId);
2159
+ }
2160
+ }
2161
+ captureEditorSelection(editor, sessionId) {
2162
+ if (editor.selectionStart === null || editor.selectionStart === undefined) {
2163
+ return;
2164
+ }
2165
+ this.#pendingEditorSelection = {
2166
+ sessionId,
2167
+ start: editor.selectionStart,
2168
+ end: editor.selectionEnd ?? editor.selectionStart,
2169
+ direction: editor.selectionDirection ?? undefined,
2170
+ };
2171
+ }
2172
+ restoreEditorSelection(editor, sessionId) {
2173
+ if (!editor) {
2174
+ return;
2175
+ }
2176
+ const selection = this.#pendingEditorSelection;
2177
+ editor.focus?.({ preventScroll: true });
2178
+ if (selection?.sessionId === sessionId && editor.setSelectionRange) {
2179
+ editor.setSelectionRange(selection.start, selection.end, selection.direction);
2180
+ this.#pendingEditorSelection = null;
2181
+ return;
2182
+ }
2183
+ focusEditorAtEnd(editor);
2184
+ }
2185
+ refocusActiveEditor() {
2186
+ this.scheduleEditorRestore(this.#editingSession?.id ?? null, true);
2187
+ }
2188
+ isTargetWithinEditingOwnership(target) {
2189
+ const editor = this.getActiveEditorElement();
2190
+ if (!editor || !(target instanceof Node)) {
2191
+ return false;
2192
+ }
2193
+ if (editor.contains(target) || editor.shadowRoot?.contains(target)) {
2194
+ return true;
2195
+ }
2196
+ const element = target instanceof HTMLElement ? target : target.parentElement;
2197
+ const widget = element?.closest("[data-cell-widget]") ?? null;
2198
+ if (!widget) {
2199
+ return false;
2200
+ }
2201
+ const cell = widget.closest("td[data-row-id][data-column-id]");
2202
+ return Boolean(cell &&
2203
+ this.editingCell &&
2204
+ cell.dataset.rowId === this.editingCell.rowId &&
2205
+ cell.dataset.columnId === this.editingCell.columnId);
2206
+ }
2207
+ ensureActiveCellVisible() {
2208
+ if (!this.activeCell) {
2209
+ return;
2210
+ }
2211
+ const rowIndex = this.#rowIndexById.get(this.activeCell.rowId);
2212
+ if (rowIndex === undefined) {
2213
+ return;
2214
+ }
2215
+ if (this.virtualize) {
2216
+ this.#rowVirtualizer.scrollToIndex(rowIndex, { align: "auto" });
2217
+ }
2218
+ requestAnimationFrame(() => {
2219
+ const activeCell = this.getActiveCellElement();
2220
+ const scrollContainer = this.getScrollContainer();
2221
+ if (!activeCell || !scrollContainer) {
2222
+ return;
2223
+ }
2224
+ const cellRect = activeCell.getBoundingClientRect();
2225
+ const scrollRect = scrollContainer.getBoundingClientRect();
2226
+ if (cellRect.left < scrollRect.left) {
2227
+ scrollContainer.scrollLeft += cellRect.left - scrollRect.left;
2228
+ }
2229
+ else if (cellRect.right > scrollRect.right) {
2230
+ scrollContainer.scrollLeft += cellRect.right - scrollRect.right;
2231
+ }
2232
+ if (!this.virtualize) {
2233
+ if (cellRect.top < scrollRect.top) {
2234
+ scrollContainer.scrollTop += cellRect.top - scrollRect.top;
2235
+ }
2236
+ else if (cellRect.bottom > scrollRect.bottom) {
2237
+ scrollContainer.scrollTop += cellRect.bottom - scrollRect.bottom;
2238
+ }
2239
+ }
2240
+ });
2241
+ }
2242
+ cellTextAt(location) {
2243
+ return this.presentedCellAt(location)?.text ?? "";
2244
+ }
2245
+ createCellSelection(anchor, focus) {
2246
+ return createNavigationCellSelection(anchor, focus);
2247
+ }
2248
+ isValidCellLocation(location) {
2249
+ return Boolean(location &&
2250
+ this.#rowIndexById.has(location.rowId) &&
2251
+ this.#columnIndexById.has(location.columnId));
2252
+ }
2253
+ normalizedCellSelection() {
2254
+ return this.boundsForRange(this.cellSelection);
2255
+ }
2256
+ visualSelectionBounds() {
2257
+ return this.fillPreview
2258
+ ? this.boundsForRange(this.fillPreview)
2259
+ : this.normalizedCellSelection();
2260
+ }
2261
+ selectedCellLocations() {
2262
+ return selectedLocations(this.presentedRows, this.presentedColumns, this.normalizedCellSelection(), this.activeCell);
2263
+ }
2264
+ copyTextForLocations(locations) {
2265
+ return copyTextForSelection({
2266
+ selection: this.normalizedCellSelection(),
2267
+ locations,
2268
+ rows: this.presentedRows,
2269
+ columns: this.presentedColumns,
2270
+ getCellText: (location) => this.cellTextAt(location),
2271
+ });
2272
+ }
2273
+ copyDetailForCurrentSelection() {
2274
+ const cells = this.selectedCellLocations();
2275
+ if (!cells.length) {
2276
+ return null;
2277
+ }
2278
+ return {
2279
+ cells,
2280
+ text: this.copyTextForLocations(cells),
2281
+ };
2282
+ }
2283
+ pasteDetailForText(text) {
2284
+ const normalizedText = this.normalizePastedText(text);
2285
+ if (!normalizedText) {
2286
+ return null;
2287
+ }
2288
+ const origin = this.pasteOriginLocation();
2289
+ if (!origin) {
2290
+ return null;
2291
+ }
2292
+ const changes = this.pasteChangesForText(origin, normalizedText);
2293
+ if (!changes.length) {
2294
+ return null;
2295
+ }
2296
+ return {
2297
+ origin,
2298
+ text: normalizedText,
2299
+ changes,
2300
+ };
2301
+ }
2302
+ normalizePastedText(text) {
2303
+ return normalizeGridPastedText(text);
2304
+ }
2305
+ pasteOriginLocation() {
2306
+ return resolvePasteOriginLocation({
2307
+ selection: this.normalizedCellSelection(),
2308
+ rows: this.presentedRows,
2309
+ columns: this.presentedColumns,
2310
+ activeCell: this.activeCell,
2311
+ });
2312
+ }
2313
+ pasteChangesForText(origin, text) {
2314
+ const originIndices = this.cellIndicesFor(origin);
2315
+ if (!originIndices) {
2316
+ return [];
2317
+ }
2318
+ return buildPasteChanges({
2319
+ text,
2320
+ originIndices,
2321
+ selection: this.normalizedCellSelection(),
2322
+ selectedLocations: this.selectedCellLocations(),
2323
+ rows: this.presentedRows,
2324
+ columns: this.presentedColumns,
2325
+ normalizeValue: (cell, value) => this.normalizedEditingValue(cell, value),
2326
+ });
2327
+ }
2328
+ currentFillSourceRange() {
2329
+ const selection = this.normalizedCellSelection();
2330
+ if (selection) {
2331
+ return this.rangeFromBounds(selection);
2332
+ }
2333
+ return this.activeCell ? { anchor: this.activeCell, focus: this.activeCell } : null;
2334
+ }
2335
+ hasEditableCellsInRange(range) {
2336
+ return hasEditableCellsInBounds(this.presentedRows, this.boundsForRange(range));
2337
+ }
2338
+ shouldShowFillHandleForCell(rowId, columnId) {
2339
+ if (this.focusMode !== "cell") {
2340
+ return false;
2341
+ }
2342
+ const range = this.currentFillSourceRange();
2343
+ if (!range) {
2344
+ return false;
2345
+ }
2346
+ const bounds = this.visualSelectionBounds() ?? this.boundsForRange(range);
2347
+ const location = bounds ? this.locationForIndices(bounds.rowEnd, bounds.columnEnd) : null;
2348
+ if (!location || location.rowId !== rowId || location.columnId !== columnId) {
2349
+ return false;
2350
+ }
2351
+ return this.hasEditableCellsInRange(range);
2352
+ }
2353
+ currentFillSourceBounds() {
2354
+ return this.currentFillSourceRange()
2355
+ ? this.boundsForRange(this.currentFillSourceRange())
2356
+ : null;
2357
+ }
2358
+ boundsForRange(range) {
2359
+ if (!range) {
2360
+ return null;
2361
+ }
2362
+ const anchor = this.cellIndicesFor(range.anchor);
2363
+ const focus = this.cellIndicesFor(range.focus);
2364
+ if (!anchor || !focus) {
2365
+ return null;
2366
+ }
2367
+ return {
2368
+ rowStart: Math.min(anchor.rowIndex, focus.rowIndex),
2369
+ rowEnd: Math.max(anchor.rowIndex, focus.rowIndex),
2370
+ columnStart: Math.min(anchor.columnIndex, focus.columnIndex),
2371
+ columnEnd: Math.max(anchor.columnIndex, focus.columnIndex),
2372
+ };
2373
+ }
2374
+ rangeFromBounds(bounds) {
2375
+ return selectionRangeFromBounds(this.presentedRows, this.presentedColumns, bounds);
2376
+ }
2377
+ locationForIndices(rowIndex, columnIndex) {
2378
+ return selectionLocationForIndices(this.presentedRows, this.presentedColumns, rowIndex, columnIndex);
2379
+ }
2380
+ beginFillDrag(event) {
2381
+ const sourceRange = this.currentFillSourceRange();
2382
+ if (!sourceRange || !this.hasEditableCellsInRange(sourceRange)) {
2383
+ return;
2384
+ }
2385
+ const session = startFillDragSession(event.pointerId, sourceRange);
2386
+ if (!session) {
2387
+ return;
2388
+ }
2389
+ const scrollContainer = this.getScrollContainer();
2390
+ this.#fillSession = session;
2391
+ this.fillPreview = null;
2392
+ scrollContainer?.focus({ preventScroll: true });
2393
+ try {
2394
+ scrollContainer?.setPointerCapture(event.pointerId);
2395
+ }
2396
+ catch {
2397
+ // Synthetic Storybook pointer events do not always create a capturable pointer.
2398
+ }
2399
+ event.preventDefault();
2400
+ }
2401
+ handleFillPointerMove(event) {
2402
+ const sourceRange = this.#fillSession.sourceRange;
2403
+ if (!sourceRange) {
2404
+ return;
2405
+ }
2406
+ const sourceBounds = this.boundsForRange(sourceRange);
2407
+ const location = this.fillTargetLocationForPoint(event.clientX, event.clientY, sourceBounds);
2408
+ this.fillPreview = location ? this.fillPreviewRangeForLocation(location, sourceRange) : null;
2409
+ }
2410
+ handleFillPointerUp() {
2411
+ const detail = this.fillDetailForPreview();
2412
+ const previewRange = detail?.target ?? this.fillPreview;
2413
+ if (detail) {
2414
+ this.$emit("cell-fill", detail);
2415
+ }
2416
+ this.endFillDrag(true);
2417
+ if (!previewRange) {
2418
+ return;
2419
+ }
2420
+ this.cellSelection = this.createCellSelection(previewRange.anchor, previewRange.focus);
2421
+ }
2422
+ endFillDrag(suppressNextClick) {
2423
+ const scrollContainer = this.getScrollContainer();
2424
+ if (scrollContainer &&
2425
+ this.#fillSession.pointerId !== null &&
2426
+ scrollContainer.hasPointerCapture?.(this.#fillSession.pointerId)) {
2427
+ try {
2428
+ scrollContainer.releasePointerCapture(this.#fillSession.pointerId);
2429
+ }
2430
+ catch {
2431
+ // Ignore release failures for synthetic pointer events.
2432
+ }
2433
+ }
2434
+ this.#suppressNextGridClick = suppressNextClick;
2435
+ this.#fillSession = clearedFillSession();
2436
+ this.fillPreview = null;
2437
+ }
2438
+ fillPreviewRangeForLocation(location, sourceRange) {
2439
+ const sourceBounds = this.boundsForRange(sourceRange);
2440
+ const targetIndices = this.cellIndicesFor(location);
2441
+ if (!sourceBounds || !targetIndices) {
2442
+ return null;
2443
+ }
2444
+ const expandedBounds = {
2445
+ rowStart: Math.min(sourceBounds.rowStart, targetIndices.rowIndex),
2446
+ rowEnd: Math.max(sourceBounds.rowEnd, targetIndices.rowIndex),
2447
+ columnStart: Math.min(sourceBounds.columnStart, targetIndices.columnIndex),
2448
+ columnEnd: Math.max(sourceBounds.columnEnd, targetIndices.columnIndex),
2449
+ };
2450
+ const clampedBounds = this.clampFillBoundsToEditableTargets(expandedBounds, sourceBounds);
2451
+ if (clampedBounds.rowStart === sourceBounds.rowStart &&
2452
+ clampedBounds.rowEnd === sourceBounds.rowEnd &&
2453
+ clampedBounds.columnStart === sourceBounds.columnStart &&
2454
+ clampedBounds.columnEnd === sourceBounds.columnEnd) {
2455
+ return null;
2456
+ }
2457
+ return this.rangeFromBounds(clampedBounds);
2458
+ }
2459
+ clampFillBoundsToEditableTargets(expandedBounds, sourceBounds) {
2460
+ return clampEditableFillBounds(this.presentedRows, expandedBounds, sourceBounds);
2461
+ }
2462
+ fillTargetLocationForPoint(clientX, clientY, sourceBounds) {
2463
+ const direct = this.locationFromPointerEventLike(clientX, clientY);
2464
+ if (direct && (!sourceBounds || !this.locationWithinBounds(direct, sourceBounds))) {
2465
+ return direct;
2466
+ }
2467
+ const preferredAxis = sourceBounds
2468
+ ? this.fillPreferredAxisForPoint(clientX, clientY, sourceBounds)
2469
+ : null;
2470
+ if (preferredAxis) {
2471
+ const axisAlignedLocation = this.nearestLocationForPoint(clientX, clientY, (location) => {
2472
+ if (sourceBounds && this.locationWithinBounds(location, sourceBounds)) {
2473
+ return false;
2474
+ }
2475
+ const indices = this.cellIndicesFor(location);
2476
+ if (!indices || !sourceBounds) {
2477
+ return true;
2478
+ }
2479
+ if (preferredAxis === "horizontal") {
2480
+ return (indices.rowIndex >= sourceBounds.rowStart && indices.rowIndex <= sourceBounds.rowEnd);
2481
+ }
2482
+ return (indices.columnIndex >= sourceBounds.columnStart &&
2483
+ indices.columnIndex <= sourceBounds.columnEnd);
2484
+ });
2485
+ if (axisAlignedLocation) {
2486
+ return axisAlignedLocation;
2487
+ }
2488
+ }
2489
+ return this.nearestLocationForPoint(clientX, clientY, (location) => sourceBounds ? !this.locationWithinBounds(location, sourceBounds) : true);
2490
+ }
2491
+ fillPreferredAxisForPoint(clientX, clientY, sourceBounds) {
2492
+ return preferredAxisForPoint(clientX, clientY, this.rectForBounds(sourceBounds));
2493
+ }
2494
+ rectForBounds(bounds) {
2495
+ const start = this.locationForIndices(bounds.rowStart, bounds.columnStart);
2496
+ const end = this.locationForIndices(bounds.rowEnd, bounds.columnEnd);
2497
+ const startCell = this.cellElementForLocation(start);
2498
+ const endCell = this.cellElementForLocation(end);
2499
+ return rectFromCellPair(startCell, endCell);
2500
+ }
2501
+ fillDetailForPreview() {
2502
+ const source = this.#fillSession.sourceRange;
2503
+ const target = this.fillPreview;
2504
+ if (!source || !target) {
2505
+ return null;
2506
+ }
2507
+ return this.fillDetailFor(source, target);
2508
+ }
2509
+ fillDetailFor(source, target) {
2510
+ const sourceBounds = this.boundsForRange(source);
2511
+ const targetBounds = this.boundsForRange(target);
2512
+ if (!sourceBounds || !targetBounds) {
2513
+ return null;
2514
+ }
2515
+ const changes = buildFillChanges({
2516
+ rows: this.presentedRows,
2517
+ columns: this.presentedColumns,
2518
+ sourceBounds,
2519
+ targetBounds,
2520
+ normalizeValue: (cell, value) => this.normalizedEditingValue(cell, value),
2521
+ });
2522
+ if (!changes.length) {
2523
+ return null;
2524
+ }
2525
+ return {
2526
+ source,
2527
+ target,
2528
+ changes,
2529
+ };
2530
+ }
2531
+ presentedCellAt(location) {
2532
+ if (!location) {
2533
+ return null;
2534
+ }
2535
+ const rowIndex = this.#rowIndexById.get(location.rowId);
2536
+ const columnIndex = this.#columnIndexById.get(location.columnId);
2537
+ if (rowIndex === undefined || columnIndex === undefined) {
2538
+ return null;
2539
+ }
2540
+ return this.presentedRows[rowIndex]?.cells[columnIndex] ?? null;
2541
+ }
2542
+ editStringForCell(cell) {
2543
+ return editStringForRawValue(cell.rawValue);
2544
+ }
2545
+ normalizedEditingValue(cell, value) {
2546
+ return normalizeEditingValue(cell, value);
2547
+ }
2548
+ booleanCellValue(value) {
2549
+ return normalizeBooleanCellValue(value);
2550
+ }
2551
+ nextTabCellLocation(current, direction) {
2552
+ return nextTabLocation(this.presentedRows, this.presentedColumns, current, direction);
2553
+ }
2554
+ cellIndicesFor(location) {
2555
+ const rowIndex = this.#rowIndexById.get(location.rowId);
2556
+ const columnIndex = this.#columnIndexById.get(location.columnId);
2557
+ return rowIndex === undefined || columnIndex === undefined ? null : { rowIndex, columnIndex };
2558
+ }
2559
+ isEditingCell(rowId, columnId) {
2560
+ return this.editingCell?.rowId === rowId && this.editingCell?.columnId === columnId;
2561
+ }
2562
+ isEditorElement(target) {
2563
+ return isGridEditorElement(target);
2564
+ }
2565
+ editorValueFromTarget(target) {
2566
+ return editorStringValue(target);
2567
+ }
2568
+ isInteractiveCellWidgetTarget(target) {
2569
+ return isGridInteractiveCellWidgetTarget(target);
2570
+ }
2571
+ commitCheckboxCellToggle(location, checked) {
2572
+ const cell = this.presentedCellAt(location);
2573
+ if (!cell?.editable || cell.editor !== "checkbox") {
2574
+ return;
2575
+ }
2576
+ this.$emit("cell-change", {
2577
+ rowId: location.rowId,
2578
+ columnId: location.columnId,
2579
+ value: this.normalizedEditingValue(cell, checked),
2580
+ });
2581
+ }
2582
+ isFillHandleTarget(target) {
2583
+ return isGridFillHandleTarget(target);
2584
+ }
2585
+ closestFromEventPath(event, selector) {
2586
+ return eventClosestFromEventPath(event, selector);
2587
+ }
2588
+ isEditorEvent(event) {
2589
+ return this.closestFromEventPath(event, ".cell-editor") !== null;
2590
+ }
2591
+ isInteractiveCellWidgetEvent(event) {
2592
+ return event.composedPath().some((target) => isGridInteractiveCellWidgetTarget(target));
2593
+ }
2594
+ isFillHandleEvent(event) {
2595
+ return this.closestFromEventPath(event, '[data-fill-handle="true"]') !== null;
2596
+ }
2597
+ isActiveCell(rowId, columnId) {
2598
+ return this.activeCell?.rowId === rowId && this.activeCell?.columnId === columnId;
2599
+ }
2600
+ locationFromTarget(target) {
2601
+ const cell = this.cellElementFromTarget(target);
2602
+ return cell ? this.locationFromCellElement(cell) : null;
2603
+ }
2604
+ locationFromEvent(event) {
2605
+ const cell = cellElementFromEvent(event);
2606
+ return cell ? this.locationFromCellElement(cell) : null;
2607
+ }
2608
+ cellElementFromTarget(target) {
2609
+ return eventCellElementFromTarget(target);
2610
+ }
2611
+ locationFromPointerEvent(event) {
2612
+ const fromPoint = this.locationFromPointerEventLike(event.clientX, event.clientY);
2613
+ if (fromPoint) {
2614
+ return fromPoint;
2615
+ }
2616
+ const fromTarget = this.locationFromTarget(event.target);
2617
+ if (fromTarget) {
2618
+ return fromTarget;
2619
+ }
2620
+ return this.nearestLocationForPoint(event.clientX, event.clientY);
2621
+ }
2622
+ locationFromMouseEvent(event) {
2623
+ const fromPoint = this.locationFromPointerEventLike(event.clientX, event.clientY);
2624
+ if (fromPoint) {
2625
+ return fromPoint;
2626
+ }
2627
+ return this.nearestLocationForPoint(event.clientX, event.clientY);
2628
+ }
2629
+ locationFromPointerEventLike(clientX, clientY) {
2630
+ const elementAtPoint = this.shadowRoot?.elementFromPoint(clientX, clientY);
2631
+ return this.locationFromTarget(elementAtPoint ?? null);
2632
+ }
2633
+ nearestLocationForPoint(clientX, clientY, predicate) {
2634
+ const cells = Array.from(this.shadowRoot?.querySelectorAll("td[data-row-id][data-column-id]") ?? []);
2635
+ return nearestGeometryLocationForPoint({
2636
+ cells,
2637
+ clientX,
2638
+ clientY,
2639
+ predicate,
2640
+ });
2641
+ }
2642
+ locationWithinBounds(location, bounds) {
2643
+ const rowIndex = this.#rowIndexById.get(location.rowId);
2644
+ const columnIndex = this.#columnIndexById.get(location.columnId);
2645
+ return (rowIndex !== undefined &&
2646
+ columnIndex !== undefined &&
2647
+ rowIndex >= bounds.rowStart &&
2648
+ rowIndex <= bounds.rowEnd &&
2649
+ columnIndex >= bounds.columnStart &&
2650
+ columnIndex <= bounds.columnEnd);
2651
+ }
2652
+ locationFromCellElement(cell) {
2653
+ return geometryLocationFromCellElement(cell);
2654
+ }
2655
+ cellElementForLocation(location) {
2656
+ if (!location) {
2657
+ return null;
2658
+ }
2659
+ const rowId = CSS.escape(location.rowId);
2660
+ const columnId = CSS.escape(location.columnId);
2661
+ return this.shadowRoot?.querySelector(`td[data-row-id="${rowId}"][data-column-id="${columnId}"]`);
2662
+ }
2663
+ endPointerSelection(suppressNextClick) {
2664
+ const scrollContainer = this.getScrollContainer();
2665
+ const session = this.#pointerSelectionSession;
2666
+ if (scrollContainer &&
2667
+ session.pointerId !== null &&
2668
+ scrollContainer.hasPointerCapture?.(session.pointerId)) {
2669
+ try {
2670
+ scrollContainer.releasePointerCapture(session.pointerId);
2671
+ }
2672
+ catch {
2673
+ // Ignore release failures for synthetic pointer events.
2674
+ }
2675
+ }
2676
+ this.#suppressNextGridClick = pointerSelectionSuppressesNextClick(session, suppressNextClick);
2677
+ this.#pointerSelectionSession = clearedPointerSelectionSession();
2678
+ }
2679
+ cellIdFor(rowId, columnId) {
2680
+ return `${this.localName}-cell-${this.instanceId}-${this.sanitizeForId(rowId)}-${this.sanitizeForId(columnId)}`;
2681
+ }
2682
+ cellEditorErrorIdFor(rowId, columnId) {
2683
+ return `${this.cellIdFor(rowId, columnId)}-edit-error`;
2684
+ }
2685
+ cellEditorHintIdFor(rowId, columnId) {
2686
+ return `${this.cellIdFor(rowId, columnId)}-edit-hint`;
2687
+ }
2688
+ /** A column's trimmed `editorHint` or `describe` text for a row; never part of the serialized value. */
2689
+ columnAccessoryText(columnId, rowData, key) {
2690
+ const column = this.presentedColumns[this.#columnIndexById.get(columnId) ?? -1]?.source;
2691
+ if (!column || rowData === undefined) {
2692
+ return "";
2693
+ }
2694
+ const text = column[key]?.(rowData);
2695
+ return typeof text === "string" ? text.trim() : "";
2696
+ }
2697
+ getActiveCellElement() {
2698
+ if (!this.activeCell) {
2699
+ return null;
2700
+ }
2701
+ return this.shadowRoot?.getElementById(this.cellIdFor(this.activeCell.rowId, this.activeCell.columnId));
2702
+ }
2703
+ getActiveEditorElement() {
2704
+ if (!this.editingCell) {
2705
+ return null;
2706
+ }
2707
+ const rowId = CSS.escape(this.editingCell.rowId);
2708
+ const columnId = CSS.escape(this.editingCell.columnId);
2709
+ return this.shadowRoot?.querySelector(`.cell-editor[data-row-id="${rowId}"][data-column-id="${columnId}"]`);
2710
+ }
2711
+ /**
2712
+ * Encodes a row or column id into an id-safe token. Every character outside
2713
+ * [A-Za-z0-9] (including "_" and "-") becomes `_<hex>_`, so the mapping is
2714
+ * injective and a "-" delimiter between encoded parts is unambiguous.
2715
+ */
2716
+ sanitizeForId(value) {
2717
+ return Array.from(value, (character) => /[a-zA-Z0-9]/.test(character) ? character : `_${character.codePointAt(0)?.toString(16)}_`).join("");
2718
+ }
2719
+ syncHostStates() {
2720
+ this.toggleState("busy", this.busy);
2721
+ this.toggleState("sticky-header", this.stickyHeader);
2722
+ this.toggleState("virtualize", this.virtualize);
2723
+ this.toggleState("empty", !(this.presentedRows?.length ?? 0));
2724
+ this.#internals.ariaBusy = this.busy ? "true" : "false";
2725
+ }
2726
+ syncRenderedRows() {
2727
+ if (!Array.isArray(this.presentedRows) || !Array.isArray(this.presentedColumns)) {
2728
+ return;
2729
+ }
2730
+ const focusedSelectionControl = this.focusedSelectionControl();
2731
+ const virtualItems = this.virtualize ? this.#rowVirtualizer.getVirtualItems() : [];
2732
+ const totalSize = this.virtualize ? this.#rowVirtualizer.getTotalSize() : 0;
2733
+ const nextState = computeRenderedRows({
2734
+ virtualize: this.virtualize,
2735
+ rows: this.presentedRows,
2736
+ estimatedRowHeight: this.estimatedRowHeight,
2737
+ virtualItems,
2738
+ totalSize,
2739
+ });
2740
+ const nextRowIndices = new Set(nextState.renderedRows.map((rendered) => rendered.item.index));
2741
+ const presentationRevisionBeforeRecycle = this.#presentationRevision;
2742
+ this.recycleFocusedRowIfNeeded(nextRowIndices);
2743
+ if (this.#presentationRevision !== presentationRevisionBeforeRecycle) {
2744
+ // Committing the recycled editor emits `cell-change`; a handler that replaced
2745
+ // `rows` re-entered here, so `nextState` is stale. Recompute from the new rows.
2746
+ this.syncRenderedRows();
2747
+ return;
2748
+ }
2749
+ const snapshot = this.interactionSnapshot();
2750
+ this.virtualTotalSize = totalSize;
2751
+ const canReuseRenderedRows = this.#renderedPresentationRevision === this.#presentationRevision &&
2752
+ this.#renderedInteractionRevision === this.#interactionRevision;
2753
+ const previousRowsByIndex = canReuseRenderedRows
2754
+ ? new Map(this.renderedRows.map((rendered) => [rendered.item.index, rendered]))
2755
+ : new Map();
2756
+ const nextRenderedRows = nextState.renderedRows.map((rendered) => {
2757
+ const row = this.withInteractionState(rendered.row, rendered.item.index, snapshot);
2758
+ const previous = previousRowsByIndex.get(rendered.item.index);
2759
+ if (previous?.row === row) {
2760
+ previous.item = rendered.item;
2761
+ return previous;
2762
+ }
2763
+ return {
2764
+ item: rendered.item,
2765
+ row,
2766
+ };
2767
+ });
2768
+ if (nextRenderedRows.length !== this.renderedRows.length ||
2769
+ nextRenderedRows.some((rendered, index) => rendered !== this.renderedRows[index])) {
2770
+ this.renderedRows.splice(0, this.renderedRows.length, ...nextRenderedRows);
2771
+ }
2772
+ this.#renderedPresentationRevision = this.#presentationRevision;
2773
+ this.#renderedInteractionRevision = this.#interactionRevision;
2774
+ if (this.focusMode === "cell") {
2775
+ const renderedRowIds = new Set(nextState.renderedRows.map((rendered) => rendered.row.id));
2776
+ for (const rowId of this.#decoratedRowCache.keys()) {
2777
+ if (!renderedRowIds.has(rowId)) {
2778
+ this.#decoratedRowCache.delete(rowId);
2779
+ }
2780
+ }
2781
+ }
2782
+ else {
2783
+ this.#decoratedRowCache.clear();
2784
+ }
2785
+ this.virtualPaddingStart = nextState.virtualPaddingStart;
2786
+ this.virtualPaddingEnd = nextState.virtualPaddingEnd;
2787
+ this.scheduleRenderedRowMeasurement();
2788
+ this.restoreSelectionControlFocus(focusedSelectionControl);
2789
+ }
2790
+ focusedSelectionControl() {
2791
+ const element = this.shadowRoot?.activeElement;
2792
+ if (!(element instanceof HTMLElement))
2793
+ return null;
2794
+ const selector = element.matches("violet-radio.selection-radio")
2795
+ ? "violet-radio.selection-radio"
2796
+ : element.matches("violet-checkbox.selection-checkbox")
2797
+ ? "violet-checkbox.selection-checkbox"
2798
+ : null;
2799
+ const rowId = selector ? this.selectionControlRowId(element) : undefined;
2800
+ return selector && rowId
2801
+ ? { element, focusGeneration: this.#focusGeneration, rowId, selector }
2802
+ : null;
2803
+ }
2804
+ selectionControlRowId(element) {
2805
+ return (element
2806
+ ?.closest("tr[data-row-index]")
2807
+ ?.querySelector("td[data-row-id]")
2808
+ ?.getAttribute("data-row-id") ?? undefined);
2809
+ }
2810
+ restoreSelectionControlFocus(focused) {
2811
+ if (!focused)
2812
+ return;
2813
+ const revision = ++this.#selectionControlFocusRevision;
2814
+ Updates.enqueue(() => {
2815
+ if (revision !== this.#selectionControlFocusRevision)
2816
+ return;
2817
+ if (!this.$fastController.isConnected)
2818
+ return;
2819
+ const shadowActive = this.shadowRoot?.activeElement;
2820
+ if (shadowActive && shadowActive !== focused.element)
2821
+ return;
2822
+ const documentActive = this.ownerDocument.activeElement;
2823
+ if (!shadowActive &&
2824
+ documentActive &&
2825
+ documentActive !== this.ownerDocument.body &&
2826
+ documentActive !== this)
2827
+ return;
2828
+ if (shadowActive === focused.element &&
2829
+ this.selectionControlRowId(shadowActive) === focused.rowId)
2830
+ return;
2831
+ if (this.#focusGeneration !== focused.focusGeneration)
2832
+ return;
2833
+ const replacement = Array.from(this.shadowRoot?.querySelectorAll(focused.selector) ?? []).find((control) => this.selectionControlRowId(control) === focused.rowId);
2834
+ replacement?.focus({ preventScroll: true });
2835
+ });
2836
+ }
2837
+ #handleFocusIntent;
2838
+ interactionSnapshot() {
2839
+ return {
2840
+ selectionBounds: this.visualSelectionBounds(),
2841
+ fillPreviewBounds: this.fillPreview ? this.boundsForRange(this.fillPreview) : null,
2842
+ fillSourceBounds: this.#fillSession.sourceRange
2843
+ ? this.boundsForRange(this.#fillSession.sourceRange)
2844
+ : this.currentFillSourceBounds(),
2845
+ };
2846
+ }
2847
+ scheduleRenderedRowMeasurement() {
2848
+ if (!this.virtualize || !this.$fastController.isConnected) {
2849
+ return;
2850
+ }
2851
+ if (this.#rowMeasurementFrame !== null) {
2852
+ cancelAnimationFrame(this.#rowMeasurementFrame);
2853
+ }
2854
+ this.#rowMeasurementFrame = requestAnimationFrame(() => {
2855
+ this.#rowMeasurementFrame = null;
2856
+ if (!this.$fastController.isConnected) {
2857
+ return;
2858
+ }
2859
+ this.#rowVirtualizer.measureElement(null);
2860
+ const rows = this.shadowRoot?.querySelectorAll("tbody tr[data-index]");
2861
+ rows?.forEach((row) => {
2862
+ this.#rowVirtualizer.measureElement(row);
2863
+ });
2864
+ });
2865
+ }
2866
+ recycleFocusedRowIfNeeded(nextRowIndices) {
2867
+ if (!this.virtualize ||
2868
+ this.#editorRecycleInProgress ||
2869
+ (nextRowIndices.size === 0 && this.presentedRows.length > 0)) {
2870
+ return;
2871
+ }
2872
+ const editingRowIndex = this.editingCell
2873
+ ? this.#rowIndexById.get(this.editingCell.rowId)
2874
+ : undefined;
2875
+ const activeElement = this.shadowRoot?.activeElement;
2876
+ const focusedRow = activeElement?.closest?.("tr[data-row-index]");
2877
+ const focusedRowIndex = focusedRow
2878
+ ? Number.parseInt(focusedRow.dataset.rowIndex ?? "", 10)
2879
+ : Number.NaN;
2880
+ let shouldRestoreGridFocus = Number.isFinite(focusedRowIndex) && !nextRowIndices.has(focusedRowIndex);
2881
+ if (editingRowIndex !== undefined && !nextRowIndices.has(editingRowIndex)) {
2882
+ this.#editorRecycleInProgress = true;
2883
+ const editingLocation = this.editingCell;
2884
+ const editingCell = editingLocation ? this.presentedCellAt(editingLocation) : null;
2885
+ const editingSessionId = this.#editingSession?.id;
2886
+ const committed = this.commitEditingCell();
2887
+ if (!committed && editingSessionId && this.#editingSession?.id === editingSessionId) {
2888
+ const columnLabel = editingCell?.columnLabel ?? editingLocation?.columnId ?? "cell";
2889
+ this.editAnnouncement = `Unsaved invalid edit in ${columnLabel} was cancelled because its row left the visible grid.`;
2890
+ this.cancelActiveEdit();
2891
+ }
2892
+ this.#editorRecycleInProgress = false;
2893
+ shouldRestoreGridFocus = true;
2894
+ }
2895
+ if (!shouldRestoreGridFocus) {
2896
+ return;
2897
+ }
2898
+ if (this.#editorRecycleFocusFrame !== null) {
2899
+ cancelAnimationFrame(this.#editorRecycleFocusFrame);
2900
+ }
2901
+ this.#editorRecycleFocusFrame = requestAnimationFrame(() => {
2902
+ this.#editorRecycleFocusFrame = null;
2903
+ if (!this.editingCell) {
2904
+ this.getScrollContainer()?.focus({ preventScroll: true });
2905
+ }
2906
+ });
2907
+ }
2908
+ scheduleVirtualizerUpdate() {
2909
+ if (!this.$fastController.isConnected) {
2910
+ return;
2911
+ }
2912
+ if (this.#virtualizerFrame !== null) {
2913
+ cancelAnimationFrame(this.#virtualizerFrame);
2914
+ }
2915
+ this.#virtualizerFrame = requestAnimationFrame(() => {
2916
+ this.#virtualizerFrame = null;
2917
+ this.#rowVirtualizer.setOptions({
2918
+ ...this.#rowVirtualizer.options,
2919
+ ...buildVirtualizerUpdateOptions({
2920
+ rows: this.presentedRows,
2921
+ estimatedRowHeight: this.estimatedRowHeight,
2922
+ overscanCount: this.overscanCount,
2923
+ virtualize: this.virtualize,
2924
+ }),
2925
+ });
2926
+ this.#rowVirtualizer._willUpdate();
2927
+ this.#rowVirtualizer.measure();
2928
+ this.syncRenderedRows();
2929
+ });
2930
+ }
2931
+ getScrollContainer() {
2932
+ return this.shadowRoot?.querySelector(".table-scroll");
2933
+ }
2934
+ rowHeightForDensity(density) {
2935
+ switch (density) {
2936
+ case "compact":
2937
+ return 24;
2938
+ case "comfortable":
2939
+ return 44;
2940
+ default:
2941
+ return 32;
2942
+ }
2943
+ }
2944
+ toggleState(name, enabled) {
2945
+ if (enabled) {
2946
+ this.#internals.states.add(name);
2947
+ return;
2948
+ }
2949
+ this.#internals.states.delete(name);
2950
+ }
2951
+ mergePartNames(basePart, extraPart) {
2952
+ return extraPart ? `${basePart} ${extraPart}` : basePart;
2953
+ }
2954
+ }
2955
+ let violetDataGridInstanceCount = 0;
2956
+ attr({ attribute: "selection-mode" })(VioletDataGrid.prototype, "selectionMode");
2957
+ attr({ attribute: "selection-label" })(VioletDataGrid.prototype, "selectionLabel");
2958
+ attr({ attribute: "sticky-header", mode: "boolean" })(VioletDataGrid.prototype, "stickyHeader");
2959
+ attr({ mode: "boolean" })(VioletDataGrid.prototype, "busy");
2960
+ attr({ mode: "boolean" })(VioletDataGrid.prototype, "virtualize");
2961
+ attr({ attribute: "show-filter", mode: "boolean" })(VioletDataGrid.prototype, "showFilter");
2962
+ attr(VioletDataGrid.prototype, "density");
2963
+ attr({ attribute: "focus-mode" })(VioletDataGrid.prototype, "focusMode");
2964
+ attr({ attribute: "sort-mode" })(VioletDataGrid.prototype, "sortMode");
2965
+ observable(VioletDataGrid.prototype, "columns");
2966
+ observable(VioletDataGrid.prototype, "columnWidths");
2967
+ observable(VioletDataGrid.prototype, "rows");
2968
+ observable(VioletDataGrid.prototype, "sort");
2969
+ observable(VioletDataGrid.prototype, "filterState");
2970
+ observable(VioletDataGrid.prototype, "selectedRowIds");
2971
+ observable(VioletDataGrid.prototype, "presentedColumns");
2972
+ observable(VioletDataGrid.prototype, "presentedRows");
2973
+ observable(VioletDataGrid.prototype, "renderedRows");
2974
+ observable(VioletDataGrid.prototype, "activeCell");
2975
+ observable(VioletDataGrid.prototype, "cellSelection");
2976
+ observable(VioletDataGrid.prototype, "editingCell");
2977
+ observable(VioletDataGrid.prototype, "editingValue");
2978
+ observable(VioletDataGrid.prototype, "editingError");
2979
+ observable(VioletDataGrid.prototype, "editAnnouncement");
2980
+ observable(VioletDataGrid.prototype, "fillPreview");
2981
+ observable(VioletDataGrid.prototype, "estimatedRowHeight");
2982
+ observable(VioletDataGrid.prototype, "overscanCount");
2983
+ observable(VioletDataGrid.prototype, "virtualPaddingStart");
2984
+ observable(VioletDataGrid.prototype, "virtualPaddingEnd");
2985
+ observable(VioletDataGrid.prototype, "virtualTotalSize");
2986
+ observable(VioletDataGrid.prototype, "hasToolbarSlotContent");
2987
+ observable(VioletDataGrid.prototype, "headerFocusColumnId");
2988
+ if (!customElements.get("violet-data-grid")) {
2989
+ await FASTElement.define(VioletDataGrid, {
2990
+ name: "violet-data-grid",
2991
+ template,
2992
+ styles,
2993
+ shadowOptions: {
2994
+ delegatesFocus: true,
2995
+ },
2996
+ });
2997
+ }
2998
+ //# sourceMappingURL=violet-data-grid.js.map