@affino/datagrid-vue 0.3.2 → 0.3.4

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 (544) hide show
  1. package/README.md +170 -195
  2. package/dist/advanced/clipboard.d.ts +5 -0
  3. package/dist/advanced/clipboard.d.ts.map +1 -0
  4. package/dist/advanced/clipboard.js +4 -0
  5. package/dist/advanced/editing.d.ts +22 -0
  6. package/dist/advanced/editing.d.ts.map +1 -0
  7. package/dist/advanced/editing.js +20 -0
  8. package/dist/advanced/filtering.d.ts +16 -0
  9. package/dist/advanced/filtering.d.ts.map +1 -0
  10. package/dist/advanced/filtering.js +15 -0
  11. package/dist/advanced/history.d.ts +3 -0
  12. package/dist/advanced/history.d.ts.map +1 -0
  13. package/dist/advanced/history.js +2 -0
  14. package/dist/advanced/index.d.ts +8 -0
  15. package/dist/advanced/index.d.ts.map +1 -0
  16. package/dist/advanced/index.js +7 -0
  17. package/dist/advanced/layout.d.ts +16 -0
  18. package/dist/advanced/layout.d.ts.map +1 -0
  19. package/dist/advanced/layout.js +14 -0
  20. package/dist/advanced/pointer.d.ts +12 -0
  21. package/dist/advanced/pointer.d.ts.map +1 -0
  22. package/dist/advanced/pointer.js +11 -0
  23. package/dist/advanced/selection.d.ts +13 -0
  24. package/dist/advanced/selection.d.ts.map +1 -0
  25. package/dist/advanced/selection.js +12 -0
  26. package/dist/advanced.d.ts +2 -136
  27. package/dist/advanced.d.ts.map +1 -1
  28. package/dist/advanced.js +2 -206
  29. package/dist/app/advancedFilterPanel.types.d.ts +18 -0
  30. package/dist/app/advancedFilterPanel.types.d.ts.map +1 -0
  31. package/dist/app/columnLayoutPanel.types.d.ts +18 -0
  32. package/dist/app/columnLayoutPanel.types.d.ts.map +1 -0
  33. package/dist/app/dataGridRowHeightMetrics.d.ts +19 -0
  34. package/dist/app/dataGridRowHeightMetrics.d.ts.map +1 -0
  35. package/dist/app/dataGridRowHeightMetrics.js +119 -0
  36. package/dist/app/index.d.ts +24 -0
  37. package/dist/app/index.d.ts.map +1 -0
  38. package/dist/app/index.js +21 -0
  39. package/dist/app/useDataGridAppActiveCellViewport.d.ts +19 -0
  40. package/dist/app/useDataGridAppActiveCellViewport.d.ts.map +1 -0
  41. package/dist/app/useDataGridAppActiveCellViewport.js +139 -0
  42. package/dist/app/useDataGridAppAdvancedFilterBuilder.d.ts +24 -0
  43. package/dist/app/useDataGridAppAdvancedFilterBuilder.d.ts.map +1 -0
  44. package/dist/app/useDataGridAppAdvancedFilterBuilder.js +139 -0
  45. package/dist/app/useDataGridAppCellSelection.d.ts +40 -0
  46. package/dist/app/useDataGridAppCellSelection.d.ts.map +1 -0
  47. package/dist/app/useDataGridAppCellSelection.js +290 -0
  48. package/dist/app/useDataGridAppClipboard.d.ts +49 -0
  49. package/dist/app/useDataGridAppClipboard.d.ts.map +1 -0
  50. package/dist/app/useDataGridAppClipboard.js +258 -0
  51. package/dist/app/useDataGridAppColumnLayoutPanel.d.ts +19 -0
  52. package/dist/app/useDataGridAppColumnLayoutPanel.d.ts.map +1 -0
  53. package/dist/app/useDataGridAppColumnLayoutPanel.js +75 -0
  54. package/dist/app/useDataGridAppControls.d.ts +88 -0
  55. package/dist/app/useDataGridAppControls.d.ts.map +1 -0
  56. package/dist/app/useDataGridAppControls.js +396 -0
  57. package/dist/app/useDataGridAppDiagnosticsPanel.d.ts +14 -0
  58. package/dist/app/useDataGridAppDiagnosticsPanel.d.ts.map +1 -0
  59. package/dist/app/useDataGridAppDiagnosticsPanel.js +23 -0
  60. package/dist/app/useDataGridAppFill.d.ts +33 -0
  61. package/dist/app/useDataGridAppFill.d.ts.map +1 -0
  62. package/dist/app/useDataGridAppFill.js +97 -0
  63. package/dist/app/useDataGridAppHeaderResize.d.ts +29 -0
  64. package/dist/app/useDataGridAppHeaderResize.d.ts.map +1 -0
  65. package/dist/app/useDataGridAppHeaderResize.js +57 -0
  66. package/dist/app/useDataGridAppInlineEditing.d.ts +47 -0
  67. package/dist/app/useDataGridAppInlineEditing.d.ts.map +1 -0
  68. package/dist/app/useDataGridAppInlineEditing.js +301 -0
  69. package/dist/app/useDataGridAppIntentHistory.d.ts +23 -0
  70. package/dist/app/useDataGridAppIntentHistory.d.ts.map +1 -0
  71. package/dist/app/useDataGridAppIntentHistory.js +37 -0
  72. package/dist/app/useDataGridAppInteractionController.d.ts +96 -0
  73. package/dist/app/useDataGridAppInteractionController.d.ts.map +1 -0
  74. package/dist/app/useDataGridAppInteractionController.js +1448 -0
  75. package/dist/app/useDataGridAppModeMeta.d.ts +11 -0
  76. package/dist/app/useDataGridAppModeMeta.d.ts.map +1 -0
  77. package/dist/app/useDataGridAppModeMeta.js +31 -0
  78. package/dist/app/useDataGridAppRowPresentation.d.ts +19 -0
  79. package/dist/app/useDataGridAppRowPresentation.d.ts.map +1 -0
  80. package/dist/app/useDataGridAppRowPresentation.js +106 -0
  81. package/dist/app/useDataGridAppRowSelection.d.ts +17 -0
  82. package/dist/app/useDataGridAppRowSelection.d.ts.map +1 -0
  83. package/dist/app/useDataGridAppRowSelection.js +85 -0
  84. package/dist/app/useDataGridAppRowSizing.d.ts +24 -0
  85. package/dist/app/useDataGridAppRowSizing.d.ts.map +1 -0
  86. package/dist/app/useDataGridAppRowSizing.js +215 -0
  87. package/dist/app/useDataGridAppRuntime.d.ts +32 -0
  88. package/dist/app/useDataGridAppRuntime.d.ts.map +1 -0
  89. package/dist/app/useDataGridAppRuntime.js +137 -0
  90. package/dist/app/useDataGridAppRuntimeSync.d.ts +21 -0
  91. package/dist/app/useDataGridAppRuntimeSync.d.ts.map +1 -0
  92. package/dist/app/useDataGridAppRuntimeSync.js +30 -0
  93. package/dist/app/useDataGridAppSelection.d.ts +24 -0
  94. package/dist/app/useDataGridAppSelection.d.ts.map +1 -0
  95. package/dist/app/useDataGridAppSelection.js +191 -0
  96. package/dist/app/useDataGridAppViewport.d.ts +57 -0
  97. package/dist/app/useDataGridAppViewport.d.ts.map +1 -0
  98. package/dist/app/useDataGridAppViewport.js +387 -0
  99. package/dist/app/useDataGridAppViewportLifecycle.d.ts +12 -0
  100. package/dist/app/useDataGridAppViewportLifecycle.d.ts.map +1 -0
  101. package/dist/app/useDataGridAppViewportLifecycle.js +33 -0
  102. package/dist/app/worker.d.ts +2 -0
  103. package/dist/app/worker.d.ts.map +1 -0
  104. package/dist/app/worker.js +1 -0
  105. package/dist/composables/dataGridFillBehavior.d.ts +2 -0
  106. package/dist/composables/dataGridFillBehavior.d.ts.map +1 -0
  107. package/dist/composables/dataGridFillBehavior.js +1 -0
  108. package/dist/composables/useAffinoGrid.d.ts +20 -0
  109. package/dist/composables/useAffinoGrid.d.ts.map +1 -0
  110. package/dist/composables/useAffinoGrid.js +17 -0
  111. package/dist/composables/useDataGridContext.d.ts +9 -0
  112. package/dist/composables/useDataGridContext.d.ts.map +1 -0
  113. package/dist/composables/useDataGridContext.js +12 -0
  114. package/dist/composables/useDataGridEngine.d.ts +18 -0
  115. package/dist/composables/useDataGridEngine.d.ts.map +1 -0
  116. package/dist/composables/useDataGridEngine.js +12 -0
  117. package/dist/composables/useDataGridEngineContext.d.ts +8 -0
  118. package/dist/composables/useDataGridEngineContext.d.ts.map +1 -0
  119. package/dist/composables/useDataGridEngineContext.js +15 -0
  120. package/dist/composables/useDataGridEventBridge.d.ts +27 -0
  121. package/dist/composables/useDataGridEventBridge.d.ts.map +1 -0
  122. package/dist/composables/useDataGridEventBridge.js +24 -0
  123. package/dist/composables/useDataGridManagedWheelScroll.d.ts +1 -1
  124. package/dist/composables/useDataGridManagedWheelScroll.d.ts.map +1 -1
  125. package/dist/composables/useDataGridManagedWheelScroll.js +1 -1
  126. package/dist/composables/useDataGridOverlayScrollState.d.ts +2 -2
  127. package/dist/composables/useDataGridRuntime.d.ts +74 -3
  128. package/dist/composables/useDataGridRuntime.d.ts.map +1 -1
  129. package/dist/composables/useDataGridRuntime.js +337 -21
  130. package/dist/composables/useDataGridTheme.d.ts +7 -0
  131. package/dist/composables/useDataGridTheme.d.ts.map +1 -0
  132. package/dist/composables/useDataGridTheme.js +10 -0
  133. package/dist/composables/useDataGridViewContext.d.ts +11 -0
  134. package/dist/composables/useDataGridViewContext.d.ts.map +1 -0
  135. package/dist/composables/useDataGridViewContext.js +12 -0
  136. package/dist/composables/useDataGridViewModel.d.ts +48 -0
  137. package/dist/composables/useDataGridViewModel.d.ts.map +1 -0
  138. package/dist/composables/useDataGridViewModel.js +40 -0
  139. package/dist/grid/createGrid.d.ts +3 -0
  140. package/dist/grid/createGrid.d.ts.map +1 -0
  141. package/dist/grid/createGrid.js +92 -0
  142. package/dist/grid/eventBus.d.ts +9 -0
  143. package/dist/grid/eventBus.d.ts.map +1 -0
  144. package/dist/grid/eventBus.js +39 -0
  145. package/dist/grid/types.d.ts +45 -0
  146. package/dist/grid/types.d.ts.map +1 -0
  147. package/dist/public.d.ts +12 -7
  148. package/dist/public.d.ts.map +1 -1
  149. package/dist/public.js +8 -5
  150. package/dist/worker.d.ts +3 -0
  151. package/dist/worker.d.ts.map +1 -0
  152. package/dist/worker.js +1 -0
  153. package/package.json +50 -15
  154. package/dist/adapters/adapterLifecycle.d.ts +0 -12
  155. package/dist/adapters/adapterLifecycle.d.ts.map +0 -1
  156. package/dist/adapters/clipboardAdapter.d.ts +0 -3
  157. package/dist/adapters/clipboardAdapter.d.ts.map +0 -1
  158. package/dist/adapters/clipboardAdapter.js +0 -38
  159. package/dist/adapters/columnPinNormalization.d.ts +0 -14
  160. package/dist/adapters/columnPinNormalization.d.ts.map +0 -1
  161. package/dist/adapters/columnPinNormalization.js +0 -55
  162. package/dist/adapters/hoverEnvironment.d.ts +0 -3
  163. package/dist/adapters/hoverEnvironment.d.ts.map +0 -1
  164. package/dist/adapters/hoverEnvironment.js +0 -24
  165. package/dist/adapters/selectionControllerAdapter.d.ts +0 -30
  166. package/dist/adapters/selectionControllerAdapter.d.ts.map +0 -1
  167. package/dist/adapters/selectionControllerAdapter.js +0 -77
  168. package/dist/adapters/selectionEnvironment.d.ts +0 -41
  169. package/dist/adapters/selectionEnvironment.d.ts.map +0 -1
  170. package/dist/adapters/selectionEnvironment.js +0 -188
  171. package/dist/adapters/selectionHeadlessAdapter.d.ts +0 -48
  172. package/dist/adapters/selectionHeadlessAdapter.d.ts.map +0 -1
  173. package/dist/adapters/selectionHeadlessAdapter.js +0 -160
  174. package/dist/adapters/sharedState.d.ts +0 -4
  175. package/dist/adapters/sharedState.d.ts.map +0 -1
  176. package/dist/adapters/sharedState.js +0 -27
  177. package/dist/adapters/viewportHostEnvironment.d.ts +0 -3
  178. package/dist/adapters/viewportHostEnvironment.d.ts.map +0 -1
  179. package/dist/adapters/viewportHostEnvironment.js +0 -46
  180. package/dist/cells/cellUtils.d.ts +0 -95
  181. package/dist/cells/cellUtils.d.ts.map +0 -1
  182. package/dist/cells/cellUtils.js +0 -20
  183. package/dist/cells/index.d.ts +0 -5
  184. package/dist/cells/index.d.ts.map +0 -1
  185. package/dist/cells/index.js +0 -4
  186. package/dist/cells/useCellEditing.d.ts +0 -42
  187. package/dist/cells/useCellEditing.d.ts.map +0 -1
  188. package/dist/cells/useCellEditing.js +0 -194
  189. package/dist/cells/useCellSelection.d.ts +0 -7
  190. package/dist/cells/useCellSelection.d.ts.map +0 -1
  191. package/dist/cells/useCellSelection.js +0 -48
  192. package/dist/cells/useCellStyle.d.ts +0 -22
  193. package/dist/cells/useCellStyle.d.ts.map +0 -1
  194. package/dist/cells/useCellStyle.js +0 -128
  195. package/dist/components/AffinoDataGridSimple.d.ts +0 -107
  196. package/dist/components/AffinoDataGridSimple.d.ts.map +0 -1
  197. package/dist/components/AffinoDataGridSimple.js +0 -349
  198. package/dist/components/DataGrid.d.ts +0 -57
  199. package/dist/components/DataGrid.d.ts.map +0 -1
  200. package/dist/components/DataGrid.js +0 -68
  201. package/dist/components/index.d.ts +0 -3
  202. package/dist/components/index.d.ts.map +0 -1
  203. package/dist/components/index.js +0 -2
  204. package/dist/components/overlayRenderer.d.ts +0 -36
  205. package/dist/components/overlayRenderer.d.ts.map +0 -1
  206. package/dist/components/overlayRenderer.js +0 -169
  207. package/dist/components/ui/VirtualList.types.d.ts +0 -5
  208. package/dist/components/ui/VirtualList.types.d.ts.map +0 -1
  209. package/dist/composables/internal/useAffinoDataGrid/index.d.ts +0 -16
  210. package/dist/composables/internal/useAffinoDataGrid/index.d.ts.map +0 -1
  211. package/dist/composables/internal/useAffinoDataGrid/index.js +0 -15
  212. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridActionRunner.d.ts +0 -34
  213. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridActionRunner.d.ts.map +0 -1
  214. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridActionRunner.js +0 -181
  215. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridBaseBindings.d.ts +0 -99
  216. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridBaseBindings.d.ts.map +0 -1
  217. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridBaseBindings.js +0 -316
  218. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridBindingSuite.d.ts +0 -40
  219. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridBindingSuite.d.ts.map +0 -1
  220. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridBindingSuite.js +0 -68
  221. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridClipboardFeature.d.ts +0 -37
  222. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridClipboardFeature.d.ts.map +0 -1
  223. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridClipboardFeature.js +0 -148
  224. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridContextMenuFeature.d.ts +0 -92
  225. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridContextMenuFeature.d.ts.map +0 -1
  226. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridContextMenuFeature.js +0 -91
  227. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridEditingFeature.d.ts +0 -81
  228. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridEditingFeature.d.ts.map +0 -1
  229. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridEditingFeature.js +0 -144
  230. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridEventHub.d.ts +0 -16
  231. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridEventHub.d.ts.map +0 -1
  232. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridEventHub.js +0 -105
  233. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridFeatureNormalization.d.ts +0 -74
  234. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridFeatureNormalization.d.ts.map +0 -1
  235. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridFeatureNormalization.js +0 -123
  236. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridFeatureSuite.d.ts +0 -32
  237. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridFeatureSuite.d.ts.map +0 -1
  238. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridFeatureSuite.js +0 -196
  239. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridFilteringFeature.d.ts +0 -25
  240. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridFilteringFeature.d.ts.map +0 -1
  241. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridFilteringFeature.js +0 -51
  242. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridHeaderFilters.d.ts +0 -65
  243. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridHeaderFilters.d.ts.map +0 -1
  244. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridHeaderFilters.js +0 -251
  245. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridIdentity.d.ts +0 -5
  246. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridIdentity.d.ts.map +0 -1
  247. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridIdentity.js +0 -30
  248. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridKeyboardDispatcher.d.ts +0 -22
  249. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridKeyboardDispatcher.d.ts.map +0 -1
  250. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridKeyboardDispatcher.js +0 -74
  251. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridLayoutProfiles.d.ts +0 -31
  252. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridLayoutProfiles.d.ts.map +0 -1
  253. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridLayoutProfiles.js +0 -64
  254. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridPointerLifecycle.d.ts +0 -9
  255. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridPointerLifecycle.d.ts.map +0 -1
  256. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridPointerLifecycle.js +0 -15
  257. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridRangeClipboard.d.ts +0 -61
  258. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridRangeClipboard.d.ts.map +0 -1
  259. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridRangeClipboard.js +0 -470
  260. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridResultAssembly.d.ts +0 -23
  261. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridResultAssembly.d.ts.map +0 -1
  262. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridResultAssembly.js +0 -131
  263. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridRowHeightFeature.d.ts +0 -30
  264. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridRowHeightFeature.d.ts.map +0 -1
  265. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridRowHeightFeature.js +0 -82
  266. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridRuntimeBootstrap.d.ts +0 -20
  267. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridRuntimeBootstrap.d.ts.map +0 -1
  268. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridRuntimeBootstrap.js +0 -66
  269. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridSelectionEngine.d.ts +0 -56
  270. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridSelectionEngine.d.ts.map +0 -1
  271. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridSelectionEngine.js +0 -365
  272. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridSelectionFeature.d.ts +0 -38
  273. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridSelectionFeature.d.ts.map +0 -1
  274. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridSelectionFeature.js +0 -170
  275. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridSortActionSuite.d.ts +0 -30
  276. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridSortActionSuite.d.ts.map +0 -1
  277. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridSortActionSuite.js +0 -36
  278. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridSortingFeature.d.ts +0 -15
  279. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridSortingFeature.d.ts.map +0 -1
  280. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridSortingFeature.js +0 -42
  281. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridStatusBar.d.ts +0 -32
  282. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridStatusBar.d.ts.map +0 -1
  283. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridStatusBar.js +0 -73
  284. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridSummaryFeature.d.ts +0 -27
  285. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridSummaryFeature.d.ts.map +0 -1
  286. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridSummaryFeature.js +0 -39
  287. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridTreeFeature.d.ts +0 -35
  288. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridTreeFeature.d.ts.map +0 -1
  289. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridTreeFeature.js +0 -220
  290. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridVisibilityFeature.d.ts +0 -28
  291. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridVisibilityFeature.d.ts.map +0 -1
  292. package/dist/composables/internal/useAffinoDataGrid/useAffinoDataGridVisibilityFeature.js +0 -59
  293. package/dist/composables/selection/selectionControllerStateScheduler.d.ts +0 -13
  294. package/dist/composables/selection/selectionControllerStateScheduler.d.ts.map +0 -1
  295. package/dist/composables/selection/selectionControllerStateScheduler.js +0 -48
  296. package/dist/composables/selection/selectionGeometry.d.ts +0 -47
  297. package/dist/composables/selection/selectionGeometry.d.ts.map +0 -1
  298. package/dist/composables/selection/selectionGeometry.js +0 -84
  299. package/dist/composables/selection/selectionInput.d.ts +0 -6
  300. package/dist/composables/selection/selectionInput.d.ts.map +0 -1
  301. package/dist/composables/selection/selectionInput.js +0 -6
  302. package/dist/composables/selection/selectionOverlayUpdateScheduler.d.ts +0 -21
  303. package/dist/composables/selection/selectionOverlayUpdateScheduler.d.ts.map +0 -1
  304. package/dist/composables/selection/selectionOverlayUpdateScheduler.js +0 -65
  305. package/dist/composables/selection/selectionStateSync.d.ts +0 -55
  306. package/dist/composables/selection/selectionStateSync.d.ts.map +0 -1
  307. package/dist/composables/selection/selectionStateSync.js +0 -30
  308. package/dist/composables/useAffinoDataGrid.d.ts +0 -4
  309. package/dist/composables/useAffinoDataGrid.d.ts.map +0 -1
  310. package/dist/composables/useAffinoDataGrid.js +0 -1556
  311. package/dist/composables/useAffinoDataGrid.types.d.ts +0 -706
  312. package/dist/composables/useAffinoDataGrid.types.d.ts.map +0 -1
  313. package/dist/composables/useAffinoDataGridClipboardFeature.d.ts +0 -37
  314. package/dist/composables/useAffinoDataGridClipboardFeature.d.ts.map +0 -1
  315. package/dist/composables/useAffinoDataGridClipboardFeature.js +0 -135
  316. package/dist/composables/useAffinoDataGridEditingFeature.d.ts +0 -50
  317. package/dist/composables/useAffinoDataGridEditingFeature.d.ts.map +0 -1
  318. package/dist/composables/useAffinoDataGridEditingFeature.js +0 -94
  319. package/dist/composables/useAffinoDataGridFilteringFeature.d.ts +0 -25
  320. package/dist/composables/useAffinoDataGridFilteringFeature.d.ts.map +0 -1
  321. package/dist/composables/useAffinoDataGridFilteringFeature.js +0 -51
  322. package/dist/composables/useAffinoDataGridMinimal.d.ts +0 -3
  323. package/dist/composables/useAffinoDataGridMinimal.d.ts.map +0 -1
  324. package/dist/composables/useAffinoDataGridMinimal.js +0 -6
  325. package/dist/composables/useAffinoDataGridSelectionFeature.d.ts +0 -38
  326. package/dist/composables/useAffinoDataGridSelectionFeature.d.ts.map +0 -1
  327. package/dist/composables/useAffinoDataGridSelectionFeature.js +0 -160
  328. package/dist/composables/useAffinoDataGridSummaryFeature.d.ts +0 -27
  329. package/dist/composables/useAffinoDataGridSummaryFeature.d.ts.map +0 -1
  330. package/dist/composables/useAffinoDataGridSummaryFeature.js +0 -39
  331. package/dist/composables/useAffinoDataGridTreeFeature.d.ts +0 -31
  332. package/dist/composables/useAffinoDataGridTreeFeature.d.ts.map +0 -1
  333. package/dist/composables/useAffinoDataGridTreeFeature.js +0 -183
  334. package/dist/composables/useAffinoDataGridUi.d.ts +0 -36
  335. package/dist/composables/useAffinoDataGridUi.d.ts.map +0 -1
  336. package/dist/composables/useAffinoDataGridUi.js +0 -81
  337. package/dist/composables/useAffinoDataGridVisibilityFeature.d.ts +0 -28
  338. package/dist/composables/useAffinoDataGridVisibilityFeature.d.ts.map +0 -1
  339. package/dist/composables/useAffinoDataGridVisibilityFeature.js +0 -59
  340. package/dist/composables/useAutoResizeColumn.d.ts +0 -14
  341. package/dist/composables/useAutoResizeColumn.d.ts.map +0 -1
  342. package/dist/composables/useAutoResizeColumn.js +0 -64
  343. package/dist/composables/useAxisVirtualizer.d.ts +0 -25
  344. package/dist/composables/useAxisVirtualizer.d.ts.map +0 -1
  345. package/dist/composables/useAxisVirtualizer.js +0 -41
  346. package/dist/composables/useColumnGroups.d.ts +0 -15
  347. package/dist/composables/useColumnGroups.d.ts.map +0 -1
  348. package/dist/composables/useColumnGroups.js +0 -35
  349. package/dist/composables/useColumnHeaderInteractions.d.ts +0 -38
  350. package/dist/composables/useColumnHeaderInteractions.d.ts.map +0 -1
  351. package/dist/composables/useColumnHeaderInteractions.js +0 -471
  352. package/dist/composables/useColumnVisibility.d.ts +0 -31
  353. package/dist/composables/useColumnVisibility.d.ts.map +0 -1
  354. package/dist/composables/useColumnVisibility.js +0 -124
  355. package/dist/composables/useDomSampling.d.ts +0 -17
  356. package/dist/composables/useDomSampling.d.ts.map +0 -1
  357. package/dist/composables/useDomSampling.js +0 -66
  358. package/dist/composables/useHorizontalViewport.d.ts +0 -35
  359. package/dist/composables/useHorizontalViewport.d.ts.map +0 -1
  360. package/dist/composables/useHorizontalViewport.js +0 -167
  361. package/dist/composables/useSelectableRows.d.ts +0 -24
  362. package/dist/composables/useSelectableRows.d.ts.map +0 -1
  363. package/dist/composables/useSelectableRows.js +0 -108
  364. package/dist/composables/useSelectionOverlayAdapter.d.ts +0 -34
  365. package/dist/composables/useSelectionOverlayAdapter.d.ts.map +0 -1
  366. package/dist/composables/useSelectionOverlayAdapter.js +0 -159
  367. package/dist/composables/useServerRowModel.d.ts +0 -30
  368. package/dist/composables/useServerRowModel.d.ts.map +0 -1
  369. package/dist/composables/useServerRowModel.js +0 -44
  370. package/dist/composables/useTableAdvancedFilterModal.d.ts +0 -30
  371. package/dist/composables/useTableAdvancedFilterModal.d.ts.map +0 -1
  372. package/dist/composables/useTableAdvancedFilterModal.js +0 -78
  373. package/dist/composables/useTableAutoColumnScheduler.d.ts +0 -26
  374. package/dist/composables/useTableAutoColumnScheduler.d.ts.map +0 -1
  375. package/dist/composables/useTableAutoColumnScheduler.js +0 -59
  376. package/dist/composables/useTableAutoScroll.d.ts +0 -18
  377. package/dist/composables/useTableAutoScroll.d.ts.map +0 -1
  378. package/dist/composables/useTableAutoScroll.js +0 -167
  379. package/dist/composables/useTableClipboardBridge.d.ts +0 -45
  380. package/dist/composables/useTableClipboardBridge.d.ts.map +0 -1
  381. package/dist/composables/useTableClipboardBridge.js +0 -185
  382. package/dist/composables/useTableColumnBindings.d.ts +0 -25
  383. package/dist/composables/useTableColumnBindings.d.ts.map +0 -1
  384. package/dist/composables/useTableColumnBindings.js +0 -72
  385. package/dist/composables/useTableColumnPinning.d.ts +0 -17
  386. package/dist/composables/useTableColumnPinning.d.ts.map +0 -1
  387. package/dist/composables/useTableColumnPinning.js +0 -49
  388. package/dist/composables/useTableDataModel.d.ts +0 -46
  389. package/dist/composables/useTableDataModel.d.ts.map +0 -1
  390. package/dist/composables/useTableDataModel.js +0 -411
  391. package/dist/composables/useTableEditing.d.ts +0 -67
  392. package/dist/composables/useTableEditing.d.ts.map +0 -1
  393. package/dist/composables/useTableEditing.js +0 -321
  394. package/dist/composables/useTableFilters.d.ts +0 -55
  395. package/dist/composables/useTableFilters.d.ts.map +0 -1
  396. package/dist/composables/useTableFilters.js +0 -723
  397. package/dist/composables/useTableFindReplaceBridge.d.ts +0 -27
  398. package/dist/composables/useTableFindReplaceBridge.d.ts.map +0 -1
  399. package/dist/composables/useTableFindReplaceBridge.js +0 -84
  400. package/dist/composables/useTableFocusManagement.d.ts +0 -35
  401. package/dist/composables/useTableFocusManagement.d.ts.map +0 -1
  402. package/dist/composables/useTableFocusManagement.js +0 -106
  403. package/dist/composables/useTableGridLayout.d.ts +0 -17
  404. package/dist/composables/useTableGridLayout.d.ts.map +0 -1
  405. package/dist/composables/useTableGridLayout.js +0 -47
  406. package/dist/composables/useTableGrouping.d.ts +0 -54
  407. package/dist/composables/useTableGrouping.d.ts.map +0 -1
  408. package/dist/composables/useTableGrouping.js +0 -255
  409. package/dist/composables/useTableHeaderLayout.d.ts +0 -33
  410. package/dist/composables/useTableHeaderLayout.d.ts.map +0 -1
  411. package/dist/composables/useTableHeaderLayout.js +0 -84
  412. package/dist/composables/useTableHistory.d.ts +0 -16
  413. package/dist/composables/useTableHistory.d.ts.map +0 -1
  414. package/dist/composables/useTableHistory.js +0 -37
  415. package/dist/composables/useTableHoverOverlay.d.ts +0 -36
  416. package/dist/composables/useTableHoverOverlay.d.ts.map +0 -1
  417. package/dist/composables/useTableHoverOverlay.js +0 -323
  418. package/dist/composables/useTableImperativeRendering.d.ts +0 -44
  419. package/dist/composables/useTableImperativeRendering.d.ts.map +0 -1
  420. package/dist/composables/useTableImperativeRendering.js +0 -82
  421. package/dist/composables/useTableLocalColumns.d.ts +0 -23
  422. package/dist/composables/useTableLocalColumns.d.ts.map +0 -1
  423. package/dist/composables/useTableLocalColumns.js +0 -40
  424. package/dist/composables/useTableOverlayController.d.ts +0 -14
  425. package/dist/composables/useTableOverlayController.d.ts.map +0 -1
  426. package/dist/composables/useTableOverlayController.js +0 -97
  427. package/dist/composables/useTableOverlayScrollState.d.ts +0 -17
  428. package/dist/composables/useTableOverlayScrollState.d.ts.map +0 -1
  429. package/dist/composables/useTableOverlayScrollState.js +0 -26
  430. package/dist/composables/useTablePanels.d.ts +0 -17
  431. package/dist/composables/useTablePanels.d.ts.map +0 -1
  432. package/dist/composables/useTablePanels.js +0 -60
  433. package/dist/composables/useTableRecalcWatcher.d.ts +0 -24
  434. package/dist/composables/useTableRecalcWatcher.d.ts.map +0 -1
  435. package/dist/composables/useTableRecalcWatcher.js +0 -30
  436. package/dist/composables/useTableRuntime.d.ts +0 -18
  437. package/dist/composables/useTableRuntime.d.ts.map +0 -1
  438. package/dist/composables/useTableRuntime.js +0 -43
  439. package/dist/composables/useTableSearchHighlights.d.ts +0 -18
  440. package/dist/composables/useTableSearchHighlights.d.ts.map +0 -1
  441. package/dist/composables/useTableSearchHighlights.js +0 -45
  442. package/dist/composables/useTableSelection.d.ts +0 -204
  443. package/dist/composables/useTableSelection.d.ts.map +0 -1
  444. package/dist/composables/useTableSelection.js +0 -3080
  445. package/dist/composables/useTableServerSync.d.ts +0 -35
  446. package/dist/composables/useTableServerSync.d.ts.map +0 -1
  447. package/dist/composables/useTableServerSync.js +0 -130
  448. package/dist/composables/useTableSorting.d.ts +0 -29
  449. package/dist/composables/useTableSorting.d.ts.map +0 -1
  450. package/dist/composables/useTableSorting.js +0 -84
  451. package/dist/composables/useTableStatusMetrics.d.ts +0 -22
  452. package/dist/composables/useTableStatusMetrics.d.ts.map +0 -1
  453. package/dist/composables/useTableStatusMetrics.js +0 -25
  454. package/dist/composables/useTableStickyColumns.d.ts +0 -39
  455. package/dist/composables/useTableStickyColumns.d.ts.map +0 -1
  456. package/dist/composables/useTableStickyColumns.js +0 -244
  457. package/dist/composables/useTableTheme.d.ts +0 -30
  458. package/dist/composables/useTableTheme.d.ts.map +0 -1
  459. package/dist/composables/useTableTheme.js +0 -207
  460. package/dist/composables/useTableViewport.d.ts +0 -103
  461. package/dist/composables/useTableViewport.d.ts.map +0 -1
  462. package/dist/composables/useTableViewport.js +0 -298
  463. package/dist/composables/useTableViewportMetrics.d.ts +0 -12
  464. package/dist/composables/useTableViewportMetrics.d.ts.map +0 -1
  465. package/dist/composables/useTableViewportMetrics.js +0 -179
  466. package/dist/composables/useTableZoom.d.ts +0 -16
  467. package/dist/composables/useTableZoom.d.ts.map +0 -1
  468. package/dist/composables/useTableZoom.js +0 -68
  469. package/dist/composables/useVerticalViewport.d.ts +0 -34
  470. package/dist/composables/useVerticalViewport.d.ts.map +0 -1
  471. package/dist/composables/useVerticalViewport.js +0 -210
  472. package/dist/composables/useVirtualDebug.d.ts +0 -169
  473. package/dist/composables/useVirtualDebug.d.ts.map +0 -1
  474. package/dist/composables/useVirtualDebug.js +0 -206
  475. package/dist/composables/useVirtualList.d.ts +0 -25
  476. package/dist/composables/useVirtualList.d.ts.map +0 -1
  477. package/dist/composables/useVirtualList.js +0 -54
  478. package/dist/context.d.ts +0 -463
  479. package/dist/context.d.ts.map +0 -1
  480. package/dist/context.js +0 -5
  481. package/dist/core/api/useUiTableApi.d.ts +0 -51
  482. package/dist/core/api/useUiTableApi.d.ts.map +0 -1
  483. package/dist/core/api/useUiTableApi.js +0 -103
  484. package/dist/core/columns/columnGroup.d.ts +0 -2
  485. package/dist/core/columns/columnGroup.d.ts.map +0 -1
  486. package/dist/core/columns/columnGroup.js +0 -1
  487. package/dist/core/columns/measurement.d.ts +0 -3
  488. package/dist/core/columns/measurement.d.ts.map +0 -1
  489. package/dist/core/columns/measurement.js +0 -132
  490. package/dist/core/virtualization/types.d.ts +0 -8
  491. package/dist/core/virtualization/types.d.ts.map +0 -1
  492. package/dist/core/virtualization/types.js +0 -4
  493. package/dist/core/virtualization/viewportConfig.d.ts +0 -6
  494. package/dist/core/virtualization/viewportConfig.d.ts.map +0 -1
  495. package/dist/core/virtualization/viewportConfig.js +0 -20
  496. package/dist/imperative/createDomControllerSuite.d.ts +0 -3
  497. package/dist/imperative/createDomControllerSuite.d.ts.map +0 -1
  498. package/dist/imperative/createDomControllerSuite.js +0 -24
  499. package/dist/imperative/selectionDomAdapter.d.ts +0 -54
  500. package/dist/imperative/selectionDomAdapter.d.ts.map +0 -1
  501. package/dist/imperative/selectionDomAdapter.js +0 -466
  502. package/dist/imperative/useImperativeTableAdapter.d.ts +0 -12
  503. package/dist/imperative/useImperativeTableAdapter.d.ts.map +0 -1
  504. package/dist/imperative/useImperativeTableAdapter.js +0 -80
  505. package/dist/piniaTableSettingsAdapter.d.ts +0 -5
  506. package/dist/piniaTableSettingsAdapter.d.ts.map +0 -1
  507. package/dist/piniaTableSettingsAdapter.js +0 -45
  508. package/dist/src/index.d.ts +0 -2
  509. package/dist/src/index.d.ts.map +0 -1
  510. package/dist/src/index.js +0 -1
  511. package/dist/src/piniaTableSettingsAdapter.d.ts +0 -4
  512. package/dist/src/piniaTableSettingsAdapter.d.ts.map +0 -1
  513. package/dist/src/piniaTableSettingsAdapter.js +0 -37
  514. package/dist/src/public.d.ts +0 -7
  515. package/dist/src/public.d.ts.map +0 -1
  516. package/dist/src/public.js +0 -6
  517. package/dist/src/tableSettingsStore.d.ts +0 -13
  518. package/dist/src/tableSettingsStore.d.ts.map +0 -1
  519. package/dist/src/tableSettingsStore.js +0 -134
  520. package/dist/stores/useFindReplaceStore.d.ts +0 -52
  521. package/dist/stores/useFindReplaceStore.d.ts.map +0 -1
  522. package/dist/stores/useFindReplaceStore.js +0 -237
  523. package/dist/tableSettingsStore.d.ts +0 -27
  524. package/dist/tableSettingsStore.d.ts.map +0 -1
  525. package/dist/tableSettingsStore.js +0 -154
  526. package/dist/tsconfig.public.tsbuildinfo +0 -1
  527. package/dist/types/overlay.d.ts +0 -26
  528. package/dist/types/overlay.d.ts.map +0 -1
  529. package/dist/types/overlay.js +0 -1
  530. package/dist/types/piniaPersist.d.ts +0 -11
  531. package/dist/types/piniaPersist.d.ts.map +0 -1
  532. package/dist/types/piniaPersist.js +0 -2
  533. package/dist/utils/columnStorage.d.ts +0 -9
  534. package/dist/utils/columnStorage.d.ts.map +0 -1
  535. package/dist/utils/columnStorage.js +0 -136
  536. package/dist/utils/createWheelAccumulator.d.ts +0 -22
  537. package/dist/utils/createWheelAccumulator.d.ts.map +0 -1
  538. package/dist/utils/createWheelAccumulator.js +0 -70
  539. package/dist/utils/sortStateAdapter.d.ts +0 -5
  540. package/dist/utils/sortStateAdapter.d.ts.map +0 -1
  541. package/dist/utils/sortStateAdapter.js +0 -24
  542. /package/dist/{adapters/adapterLifecycle.js → app/advancedFilterPanel.types.js} +0 -0
  543. /package/dist/{components/ui/VirtualList.types.js → app/columnLayoutPanel.types.js} +0 -0
  544. /package/dist/{composables/useAffinoDataGrid.types.js → grid/types.js} +0 -0
@@ -1,3080 +0,0 @@
1
- import { computed, isRef, nextTick, onBeforeUnmount, ref, shallowRef, watch, watchEffect } from "vue";
2
- import { moveSelectionArea } from "@affino/datagrid-core/selection/moveSelection";
3
- import { clampGridSelectionPoint, createGridSelectionRange, createGridSelectionRangeFromInput, resolveSelectionBounds, } from "../../core/selection/selectionState";
4
- import { canPasteIntoColumn } from "./useTableEditing";
5
- import { areaContainsCell, areaContainsColumn, areaContainsRow, areaEdges, anyAreaContainsColumn, anyAreaContainsRow, findAreaIndexContaining, findRangeIndexContaining as findRangeIndexContainingCell, rangeContainsCell, selectionEdges as computeSelectionEdges, } from "../../core/selection/geometry";
6
- import { clampCutPreviewState, resolveCutPreviewFromSnapshot, } from "../../core/selection/cutPreview";
7
- import { commitFillPreview } from "@affino/datagrid-core/selection/fillCommit";
8
- import { resolveAutoFillDown } from "../../core/selection/fillAuto";
9
- import { applyMatrixToGrid } from "@affino/datagrid-core/selection/matrix";
10
- import { remapSelectionState } from "@affino/datagrid-core/selection/remap";
11
- import { releaseFillHandleStyle } from "@affino/datagrid-core/selection/fillHandleStylePool";
12
- import { createSelectionSnapshot, selectionSnapshotSignature, } from "@affino/datagrid-core/selection/snapshot";
13
- import { setSelectionRanges as setSelectionRangesHeadless } from "@affino/datagrid-core/selection/operations";
14
- import { resolveFullColumnSelection, resolveFullRowSelection } from "@affino/datagrid-core/selection/fullSelection";
15
- import { startSelectionDragSession, updateSelectionDragSession, endSelectionDragSession, } from "@affino/datagrid-core/selection/dragSession";
16
- import { startFillDragSession as startCoreFillDragSession, updateFillDragSession as updateCoreFillDragSession, fillDragSessionWithPreview, } from "@affino/datagrid-core/selection/fillSession";
17
- import { createSharedStateContainer } from "@affino/datagrid-core/state/sharedStateContainer";
18
- import { createSelectionDomAdapter } from "../imperative/selectionDomAdapter";
19
- import { computeCursorOverlayRect, computeFillPreviewOverlayRects, computeCutPreviewOverlayRects, computeActiveRangeOverlayRects, computeStaticRangeOverlayRects, prepareSelectionOverlayResources, } from "@affino/datagrid-core/selection/selectionOverlay";
20
- import { releaseOverlayRect, releaseOverlayRectArray } from "@affino/datagrid-core/selection/selectionOverlayRectPool";
21
- import { useSelectionOverlayAdapter } from "./useSelectionOverlayAdapter";
22
- import { createTableOverlayScrollEmitter } from "./useTableOverlayScrollState";
23
- import { createVueSelectionEnvironment } from "../adapters/selectionEnvironment";
24
- import { createSelectionControllerAdapter } from "../adapters/selectionControllerAdapter";
25
- import { useSharedStateProperty } from "../adapters/sharedState";
26
- import { BASE_ROW_HEIGHT, FILL_HANDLE_SIZE, clamp, } from "../../core/utils/constants";
27
- import { toSelectionPointerCoordinates } from "./selection/selectionInput";
28
- import { buildSelectionOverlaySignature, createSelectionCellKey, detectFullColumnSelectionIndex, resolveRowHeaderClassValue, } from "./selection/selectionGeometry";
29
- import { createSelectionControllerStateScheduler } from "./selection/selectionControllerStateScheduler";
30
- import { createSelectionOverlayUpdateScheduler } from "./selection/selectionOverlayUpdateScheduler";
31
- import { reconcileSelectionState, syncSelectionFromControllerState } from "./selection/selectionStateSync";
32
- const isSelectionDebugEnabled = typeof window !== "undefined" && Boolean(window.__UNITLAB_SELECTION_DEBUG__ ?? window.__UNITLAB_TABLE_DEBUG__ ?? false);
33
- const selectionPerformance = typeof performance !== "undefined" ? performance : null;
34
- let overlayTimingCounter = 0;
35
- function runWithOverlayTiming(label, callback) {
36
- if (!isSelectionDebugEnabled || !selectionPerformance) {
37
- return callback();
38
- }
39
- const { mark, measure, clearMarks } = selectionPerformance;
40
- if (typeof mark !== "function" || typeof measure !== "function") {
41
- return callback();
42
- }
43
- const id = `ui-table-overlay:${label}:${overlayTimingCounter++}`;
44
- const startMark = `${id}:start`;
45
- const endMark = `${id}:end`;
46
- mark.call(selectionPerformance, startMark);
47
- try {
48
- return callback();
49
- }
50
- finally {
51
- mark.call(selectionPerformance, endMark);
52
- measure.call(selectionPerformance, id, startMark, endMark);
53
- if (typeof clearMarks === "function") {
54
- clearMarks.call(selectionPerformance, startMark);
55
- clearMarks.call(selectionPerformance, endMark);
56
- }
57
- }
58
- }
59
- function debugSelectionLog(...args) {
60
- if (!isSelectionDebugEnabled || typeof console === "undefined")
61
- return;
62
- // eslint-disable-next-line no-console
63
- console.log(...args);
64
- }
65
- export const useTableSelection = (options) => {
66
- const { containerRef, localColumns, processedRows, totalRowCount, viewport, isEditingCell, focusContainer, emitSelectionChange, setCellValueDirect, setCellValueFromPaste, getCellRawValue, dispatchEvents, recordHistory, refreshViewport, stopAutoScroll, updateAutoScroll, lastPointer, deleteRows, rowIndexColumnKey, rowSelectionMode: rowSelectionModeOption, getRowIdByIndex, findRowIndexById, resolveCellElement, resolveHeaderCellElement, overlayContainerRef, overlayComponentRef: overlayComponentRefOption, pinnedRightWidth: pinnedRightWidthRef, pinnedLeftOffset: pinnedLeftOffsetRef, pinnedRightOffset: pinnedRightOffsetRef, columnSurfaces: columnSurfacesRef, overlayScrollControlledExternally, } = options;
67
- const overlayComponentRef = overlayComponentRefOption ?? shallowRef(null);
68
- const pinnedRightWidth = pinnedRightWidthRef ?? ref(0);
69
- const pinnedLeftOffset = pinnedLeftOffsetRef ?? ref(0);
70
- const pinnedRightOffset = pinnedRightOffsetRef ?? pinnedRightWidth;
71
- const overlayScrollExternal = overlayScrollControlledExternally === true;
72
- const { effectiveRowHeight: effectiveRowHeightRef, viewportHeight: viewportHeightRef, viewportWidth: viewportWidthRef, } = viewport;
73
- const domAdapter = createSelectionDomAdapter({
74
- containerRef,
75
- overlayContainerRef,
76
- localColumns,
77
- totalRowCount,
78
- viewport,
79
- rowIndexColumnKey,
80
- getRowIdByIndex,
81
- resolveCellElement,
82
- resolveHeaderCellElement,
83
- });
84
- const selectionContext = {
85
- grid: getGridDimensions(),
86
- getRowIdByIndex,
87
- };
88
- watch(() => [totalRowCount.value, localColumns.value.length], () => {
89
- selectionContext.grid = getGridDimensions();
90
- }, { immediate: true });
91
- const rowSelectionMode = isRef(rowSelectionModeOption)
92
- ? rowSelectionModeOption
93
- : ref(rowSelectionModeOption ?? "cell");
94
- const isFullRowMode = computed(() => rowSelectionMode.value === "row");
95
- const selectionSharedState = createSharedStateContainer({
96
- selectionRanges: [],
97
- selectionAreas: [],
98
- selectedCell: null,
99
- anchorCell: null,
100
- activeRangeIndex: -1,
101
- dragAnchorCell: null,
102
- selectionDragSession: null,
103
- isDraggingSelection: false,
104
- isFillDragging: false,
105
- fullRowSelection: null,
106
- rowSelectionAnchor: null,
107
- isRowSelectionDragging: false,
108
- columnSelectionState: null,
109
- fillSession: null,
110
- });
111
- const selectionRanges = useSharedStateProperty(selectionSharedState, "selectionRanges");
112
- const selectionAreas = useSharedStateProperty(selectionSharedState, "selectionAreas");
113
- const selectedCell = useSharedStateProperty(selectionSharedState, "selectedCell");
114
- const anchorCell = useSharedStateProperty(selectionSharedState, "anchorCell");
115
- const activeRangeIndex = useSharedStateProperty(selectionSharedState, "activeRangeIndex");
116
- const dragAnchorCell = useSharedStateProperty(selectionSharedState, "dragAnchorCell");
117
- const selectionDragSession = useSharedStateProperty(selectionSharedState, "selectionDragSession");
118
- const isDraggingSelection = useSharedStateProperty(selectionSharedState, "isDraggingSelection");
119
- const isFillDragging = useSharedStateProperty(selectionSharedState, "isFillDragging");
120
- const fullRowSelection = useSharedStateProperty(selectionSharedState, "fullRowSelection");
121
- const rowSelectionAnchor = useSharedStateProperty(selectionSharedState, "rowSelectionAnchor");
122
- const isRowSelectionDragging = useSharedStateProperty(selectionSharedState, "isRowSelectionDragging");
123
- const columnSelectionState = useSharedStateProperty(selectionSharedState, "columnSelectionState");
124
- const fillSession = useSharedStateProperty(selectionSharedState, "fillSession");
125
- const selectionStateView = selectionSharedState.state;
126
- const initialHeadlessSelectionState = {
127
- ranges: selectionStateView.selectionRanges,
128
- areas: selectionStateView.selectionAreas,
129
- activeRangeIndex: selectionStateView.activeRangeIndex,
130
- selectedPoint: selectionStateView.selectedCell,
131
- anchorPoint: selectionStateView.anchorCell,
132
- dragAnchorPoint: selectionStateView.dragAnchorCell,
133
- };
134
- const fullColumnSelection = computed(() => detectFullColumnSelectionIndex(selectionRanges.value, getGridDimensions()));
135
- const selectionOverlayRects = ref([]);
136
- const activeSelectionOverlayRects = ref([]);
137
- const selectionCursorOverlay = shallowRef(null);
138
- const fillPreviewOverlayRects = ref([]);
139
- const cutPreviewOverlayRects = ref([]);
140
- const cutPreviewState = ref(null);
141
- const pendingCutState = ref(null);
142
- const cutPreviewRanges = computed(() => cutPreviewState.value?.areas ?? []);
143
- const cutPreviewActiveIndex = computed(() => cutPreviewState.value?.activeIndex ?? -1);
144
- const measureFillHandle = (range) => domAdapter.resolveFillHandleStyle({
145
- range,
146
- fillHandleSize: FILL_HANDLE_SIZE,
147
- });
148
- const measureCellRect = (point) => {
149
- const column = localColumns.value[point.colIndex];
150
- const key = column?.key;
151
- const element = key && typeof resolveCellElement === "function"
152
- ? resolveCellElement(point.rowIndex, key)
153
- : null;
154
- const rect = element?.getBoundingClientRect() ?? null;
155
- return {
156
- promise: Promise.resolve(rect),
157
- cancel() { },
158
- };
159
- };
160
- const { environment: selectionEnvironment, dispose: disposeSelectionEnvironment, } = createVueSelectionEnvironment({
161
- localColumns,
162
- selectionOverlayRects,
163
- activeSelectionOverlayRects,
164
- selectionCursorOverlay,
165
- fillPreviewOverlayRects,
166
- cutPreviewOverlayRects,
167
- focusContainer,
168
- resolveCellElement,
169
- resolveHeaderCellElement,
170
- getRowIdByIndex,
171
- findRowIndexById,
172
- measureFillHandle,
173
- measureCellRect,
174
- scrollSelectionIntoView: input => {
175
- const { range, cursor = selectedCell.value, attempt, maxAttempts = 2, } = input;
176
- domAdapter.scrollSelectionIntoView({
177
- range,
178
- cursor,
179
- attempt,
180
- maxAttempts,
181
- });
182
- },
183
- resolveCellFromPoint: (clientX, clientY) => domAdapter.resolveCellFromPoint(clientX, clientY),
184
- resolveRowIndexFromPoint: (clientX, clientY) => domAdapter.resolveRowIndexFromPoint(clientX, clientY),
185
- invalidateMetrics: () => domAdapter.invalidateMetrics(),
186
- stopAutoScroll,
187
- updateAutoScroll,
188
- });
189
- const selectionControllerAdapter = createSelectionControllerAdapter({
190
- environment: selectionEnvironment,
191
- context: getSelectionContext(),
192
- initialState: initialHeadlessSelectionState,
193
- });
194
- debugSelectionLog("controllerAdapter initialized", true);
195
- let lastOverlaySignature = { ranges: "", active: "", fill: "", cut: "" };
196
- let pendingOverlaySignature = null;
197
- const controllerFrameGlobal = typeof window !== "undefined" ? window : globalThis;
198
- const doApplyControllerState = (state) => {
199
- const nextOverlaySignature = buildOverlaySignature();
200
- const baseline = pendingOverlaySignature ?? lastOverlaySignature;
201
- const rangesChanged = nextOverlaySignature.ranges !== baseline.ranges;
202
- const activeChanged = nextOverlaySignature.active !== baseline.active;
203
- const fillChanged = nextOverlaySignature.fill !== baseline.fill;
204
- const cutChanged = nextOverlaySignature.cut !== baseline.cut;
205
- const overlayChanged = rangesChanged || activeChanged || fillChanged || cutChanged;
206
- emitSelectionChangeSnapshot();
207
- if (!overlayChanged) {
208
- updateCursorOverlayFromState(state);
209
- return;
210
- }
211
- if (rangesChanged) {
212
- pendingOverlaySignature = nextOverlaySignature;
213
- const resources = resolveOverlayComputationInputs(state);
214
- if (!resources) {
215
- let overlayUpdated = false;
216
- overlayUpdated = updateStaticRangeOverlayFromState(state, null, { commit: false, signature: nextOverlaySignature }) || overlayUpdated;
217
- if (fillChanged) {
218
- overlayUpdated = updateFillPreviewOverlayFromState(state, null, { commit: false }) || overlayUpdated;
219
- }
220
- if (cutChanged) {
221
- overlayUpdated = updateCutPreviewOverlayFromState(state, null, { commit: false }) || overlayUpdated;
222
- }
223
- if (activeChanged) {
224
- overlayUpdated = updateActiveRangeOverlayFromState(state, null, { commit: false }) || overlayUpdated;
225
- }
226
- updateCursorOverlayFromState(state, null);
227
- if (overlayUpdated) {
228
- commitOverlaySnapshotFromRefs();
229
- }
230
- scheduleOverlayUpdate();
231
- return;
232
- }
233
- let overlayUpdated = false;
234
- overlayUpdated = updateStaticRangeOverlayFromState(state, resources, { commit: false, signature: nextOverlaySignature }) || overlayUpdated;
235
- if (fillChanged) {
236
- overlayUpdated = updateFillPreviewOverlayFromState(state, resources, { commit: false }) || overlayUpdated;
237
- }
238
- if (cutChanged) {
239
- overlayUpdated = updateCutPreviewOverlayFromState(state, resources, { commit: false }) || overlayUpdated;
240
- }
241
- if (activeChanged) {
242
- overlayUpdated = updateActiveRangeOverlayFromState(state, resources, { commit: false }) || overlayUpdated;
243
- }
244
- updateCursorOverlayFromState(state, resources);
245
- if (overlayUpdated) {
246
- commitOverlaySnapshotFromRefs();
247
- }
248
- lastOverlaySignature = nextOverlaySignature;
249
- pendingOverlaySignature = null;
250
- return;
251
- }
252
- const resources = resolveOverlayComputationInputs(state);
253
- if (!resources || !resources.prepared) {
254
- pendingOverlaySignature = nextOverlaySignature;
255
- scheduleOverlayUpdate();
256
- return;
257
- }
258
- updateCursorOverlayFromState(state, resources);
259
- if (fillChanged) {
260
- updateFillPreviewOverlayFromState(state, resources, { commit: true });
261
- }
262
- if (cutChanged) {
263
- updateCutPreviewOverlayFromState(state, resources, { commit: true });
264
- }
265
- if (activeChanged) {
266
- updateActiveRangeOverlayFromState(state, resources, { commit: true });
267
- }
268
- lastOverlaySignature = nextOverlaySignature;
269
- pendingOverlaySignature = null;
270
- };
271
- const applyControllerState = (state) => {
272
- syncSelectionFromControllerState(selectionSharedState, state);
273
- reconcileSelectionState({
274
- state,
275
- grid: getGridDimensions(),
276
- existingColumnSelection: columnSelectionState.value,
277
- selectedPointRowIndex: state.selectedPoint?.rowIndex ?? null,
278
- setColumnSelectionState,
279
- clearColumnSelectionState,
280
- setSelectionDragSession: value => {
281
- selectionDragSession.value = value;
282
- },
283
- setFillSession,
284
- setFillDragging: value => {
285
- isFillDragging.value = value;
286
- },
287
- });
288
- controllerStateScheduler.schedule(state);
289
- };
290
- const runAutoScrollUpdate = (pointer) => {
291
- selectionControllerAdapter.sync({
292
- autoscroll: {
293
- active: true,
294
- pointer,
295
- },
296
- });
297
- };
298
- const haltAutoScroll = (fromControllerEvent = false) => {
299
- if (!fromControllerEvent) {
300
- selectionControllerAdapter.sync({
301
- autoscroll: {
302
- active: false,
303
- },
304
- });
305
- }
306
- lastPointer.value = null;
307
- };
308
- const lastSelectionSignature = ref("");
309
- const controllerStateScheduler = createSelectionControllerStateScheduler({
310
- applyState: state => {
311
- doApplyControllerState(state);
312
- },
313
- requestFrame: callback => {
314
- if (typeof controllerFrameGlobal.requestAnimationFrame === "function") {
315
- return controllerFrameGlobal.requestAnimationFrame(callback);
316
- }
317
- return controllerFrameGlobal.setTimeout(callback, 16);
318
- },
319
- cancelFrame: handle => {
320
- if (typeof handle === "number" && typeof controllerFrameGlobal.cancelAnimationFrame === "function") {
321
- ;
322
- controllerFrameGlobal.cancelAnimationFrame(handle);
323
- return;
324
- }
325
- controllerFrameGlobal.clearTimeout(handle);
326
- },
327
- scheduleNextTick: callback => {
328
- nextTick(() => callback());
329
- },
330
- });
331
- const overlayUpdateScheduler = createSelectionOverlayUpdateScheduler({
332
- request: (callback, options) => selectionEnvironment.scheduler.request(callback, options),
333
- cancel: handle => selectionEnvironment.scheduler.cancel(handle),
334
- flush: () => updateSelectionOverlay(),
335
- backgroundTimeout: 160,
336
- });
337
- const imperativeSnapshotCache = {
338
- hasCutPreview: false,
339
- rowSelection: new Set(),
340
- columnSelection: new Set(),
341
- anchorKey: null,
342
- cursorKey: null,
343
- cells: new Map(),
344
- rowClasses: new Map(),
345
- generation: 0,
346
- };
347
- let imperativeSnapshotGeneration = 0;
348
- const uiRangeCache = [];
349
- const uiRangePool = [];
350
- let uiActiveCellCache = { rowId: null, rowIndex: 0, colIndex: 0 };
351
- const uiSnapshotCache = {
352
- ranges: uiRangeCache,
353
- activeRangeIndex: 0,
354
- activeCell: null,
355
- clone: () => cloneUiSelectionSnapshot(uiSnapshotCache),
356
- };
357
- const controllerAutoscrollUnsubscribe = selectionControllerAdapter.subscribe(event => {
358
- if (event.type !== "autoscroll")
359
- return;
360
- if (event.active) {
361
- lastPointer.value = event.pointer;
362
- }
363
- else {
364
- haltAutoScroll(true);
365
- }
366
- });
367
- const invalidateSelectionMetrics = () => {
368
- if (selectionEnvironment.dom.invalidateMetrics) {
369
- selectionEnvironment.dom.invalidateMetrics();
370
- return;
371
- }
372
- domAdapter.invalidateMetrics();
373
- };
374
- function cloneSelectionPoint(point) {
375
- return {
376
- rowIndex: point.rowIndex,
377
- colIndex: point.colIndex,
378
- rowId: point.rowId ?? null,
379
- };
380
- }
381
- function cloneSelectionArea(area) {
382
- return {
383
- startRow: area.startRow,
384
- endRow: area.endRow,
385
- startCol: area.startCol,
386
- endCol: area.endCol,
387
- };
388
- }
389
- function cloneSelectionRange(range) {
390
- return {
391
- startRow: range.startRow,
392
- endRow: range.endRow,
393
- startCol: range.startCol,
394
- endCol: range.endCol,
395
- anchor: cloneSelectionPoint(range.anchor),
396
- focus: cloneSelectionPoint(range.focus),
397
- startRowId: range.startRowId ?? null,
398
- endRowId: range.endRowId ?? null,
399
- };
400
- }
401
- function cloneFillSession(session) {
402
- return {
403
- origin: {
404
- anchor: cloneSelectionPoint(session.origin.anchor),
405
- focus: cloneSelectionPoint(session.origin.focus),
406
- startRow: session.origin.startRow,
407
- endRow: session.origin.endRow,
408
- startCol: session.origin.startCol,
409
- endCol: session.origin.endCol,
410
- },
411
- originArea: cloneSelectionArea(session.originArea),
412
- preview: session.preview ? cloneSelectionArea(session.preview) : null,
413
- target: session.target ? cloneSelectionPoint(session.target) : null,
414
- axis: session.axis ?? null,
415
- };
416
- }
417
- function setFillSession(session) {
418
- fillSession.value = session ? cloneFillSession(session) : null;
419
- }
420
- function refreshFillSession(session) {
421
- setFillSession(session);
422
- }
423
- const fillPreviewRange = computed(() => fillSession.value?.preview ?? null);
424
- const fillHandleStyle = ref(null);
425
- let fillHandleMeasurement = null;
426
- function cancelFillHandleMeasurement() {
427
- if (fillHandleMeasurement) {
428
- fillHandleMeasurement.cancel();
429
- fillHandleMeasurement = null;
430
- }
431
- }
432
- const overlayDimensions = ref({ width: 0, height: 0 });
433
- const resolveOverlayElement = () => overlayContainerRef?.value ?? containerRef.value;
434
- watch(() => [resolveOverlayElement(), containerRef.value], ([overlayEl, containerEl], _previous, onCleanup) => {
435
- if (!overlayEl) {
436
- overlayDimensions.value = { width: 0, height: 0 };
437
- return;
438
- }
439
- let lastWidth = overlayDimensions.value.width;
440
- let lastHeight = overlayDimensions.value.height;
441
- const updateMetrics = () => {
442
- const nextWidth = overlayEl.clientWidth ?? 0;
443
- const nextHeight = overlayEl.clientHeight ?? 0;
444
- if (nextWidth === lastWidth && nextHeight === lastHeight) {
445
- return;
446
- }
447
- overlayDimensions.value = { width: nextWidth, height: nextHeight };
448
- lastWidth = nextWidth;
449
- lastHeight = nextHeight;
450
- scheduleOverlayUpdate();
451
- };
452
- updateMetrics();
453
- let resizeObserver = null;
454
- let intervalId = null;
455
- if (typeof ResizeObserver !== "undefined") {
456
- resizeObserver = new ResizeObserver(() => updateMetrics());
457
- resizeObserver.observe(overlayEl);
458
- if (containerEl && containerEl !== overlayEl) {
459
- resizeObserver.observe(containerEl);
460
- }
461
- }
462
- else if (typeof window !== "undefined") {
463
- intervalId = window.setInterval(updateMetrics, 250);
464
- }
465
- onCleanup(() => {
466
- resizeObserver?.disconnect();
467
- if (intervalId !== null) {
468
- window.clearInterval(intervalId);
469
- }
470
- });
471
- }, { immediate: true });
472
- const overlayViewport = computed(() => {
473
- const baseWidth = viewportWidthRef.value || overlayDimensions.value.width;
474
- return {
475
- width: baseWidth,
476
- height: viewportHeightRef.value || overlayDimensions.value.height,
477
- scrollLeft: viewport.scrollLeft.value,
478
- scrollTop: viewport.scrollTop.value,
479
- startRow: viewport.startIndex.value,
480
- endRow: viewport.endIndex.value,
481
- visibleStartCol: viewport.visibleStartCol.value,
482
- visibleEndCol: viewport.visibleEndCol.value,
483
- virtualizationEnabled: viewport.virtualizationEnabled.value !== false,
484
- };
485
- });
486
- const overlayScrollState = createTableOverlayScrollEmitter();
487
- const normalizeFinite = (value) => {
488
- if (!Number.isFinite(value ?? NaN)) {
489
- return 0;
490
- }
491
- return value;
492
- };
493
- if (!overlayScrollExternal) {
494
- watchEffect(() => {
495
- const viewportSnapshot = overlayViewport.value;
496
- const pinnedLeft = pinnedLeftOffset.value;
497
- const pinnedRight = pinnedRightOffset.value;
498
- const nextWidth = Math.max(0, normalizeFinite(viewportSnapshot?.width));
499
- const nextHeight = Math.max(0, normalizeFinite(viewportSnapshot?.height));
500
- const nextScrollLeft = normalizeFinite(viewportSnapshot?.scrollLeft);
501
- const nextScrollTop = normalizeFinite(viewportSnapshot?.scrollTop);
502
- const nextPinnedLeft = Math.max(0, normalizeFinite(pinnedLeft));
503
- const nextPinnedRight = Math.max(0, normalizeFinite(pinnedRight));
504
- overlayScrollState.emit({
505
- viewportWidth: nextWidth,
506
- viewportHeight: nextHeight,
507
- scrollLeft: nextScrollLeft,
508
- scrollTop: nextScrollTop,
509
- pinnedOffsetLeft: nextPinnedLeft,
510
- pinnedOffsetRight: nextPinnedRight,
511
- });
512
- }, { flush: "sync" });
513
- }
514
- const selectionOverlayAdapterHandle = useSelectionOverlayAdapter({
515
- overlayComponentRef,
516
- selectionRects: selectionOverlayRects,
517
- activeSelectionRects: activeSelectionOverlayRects,
518
- fillPreviewRects: fillPreviewOverlayRects,
519
- cutPreviewRects: cutPreviewOverlayRects,
520
- cursorRect: selectionCursorOverlay,
521
- fillHandleStyle,
522
- overlayViewport,
523
- pinnedLeftOffset,
524
- pinnedRightOffset,
525
- overlayScrollState,
526
- });
527
- const fillHandleSignature = computed(() => {
528
- const range = selectionControllerAdapter.fillHandleRange.value;
529
- if (!range)
530
- return "";
531
- const selected = selectedCell.value;
532
- return [
533
- range.startRow,
534
- range.endRow,
535
- range.startCol,
536
- range.endCol,
537
- selected?.rowIndex ?? "",
538
- selected?.colIndex ?? "",
539
- ].join(":");
540
- });
541
- const resolveControllerFillHandleRange = () => {
542
- const state = selectionControllerAdapter.state.value;
543
- if (isFillDragging.value)
544
- return null;
545
- if (isEditingCell.value)
546
- return null;
547
- if (fullRowSelection.value)
548
- return null;
549
- if (fullColumnSelection.value !== null)
550
- return null;
551
- if (!state.selectedPoint)
552
- return null;
553
- const index = state.activeRangeIndex;
554
- if (index < 0 || index >= state.ranges.length) {
555
- return null;
556
- }
557
- const range = state.ranges[index];
558
- if (!range) {
559
- return null;
560
- }
561
- return cloneSelectionRange(range);
562
- };
563
- const updateControllerFillHandleRange = () => {
564
- selectionControllerAdapter.sync({
565
- fillHandleRange: resolveControllerFillHandleRange(),
566
- });
567
- };
568
- watch(selectionControllerAdapter.state, state => {
569
- debugSelectionLog("controller state update", state);
570
- applyControllerState(state);
571
- updateControllerFillHandleRange();
572
- }, { immediate: true });
573
- watch(() => [
574
- isFillDragging.value,
575
- isEditingCell.value,
576
- fullRowSelection.value ? `${fullRowSelection.value.start}:${fullRowSelection.value.end}` : null,
577
- fullColumnSelection.value,
578
- ], () => {
579
- updateControllerFillHandleRange();
580
- }, { immediate: true });
581
- let lastResolvedFillHandleSignature = null;
582
- watch(() => ({
583
- range: selectionControllerAdapter.fillHandleRange.value,
584
- signature: fillHandleSignature.value,
585
- }), ({ range, signature }) => {
586
- if (!range || !signature) {
587
- lastResolvedFillHandleSignature = null;
588
- cancelFillHandleMeasurement();
589
- fillHandleStyle.value = null;
590
- return;
591
- }
592
- if (signature === lastResolvedFillHandleSignature)
593
- return;
594
- cancelFillHandleMeasurement();
595
- const measurement = selectionEnvironment.measurement.measureFillHandle(range);
596
- fillHandleMeasurement = measurement;
597
- lastResolvedFillHandleSignature = signature;
598
- measurement.promise
599
- .then(style => {
600
- if (fillHandleMeasurement !== measurement) {
601
- if (style) {
602
- releaseFillHandleStyle(style);
603
- }
604
- return;
605
- }
606
- fillHandleStyle.value = style;
607
- fillHandleMeasurement = null;
608
- })
609
- .catch(() => {
610
- if (fillHandleMeasurement !== measurement)
611
- return;
612
- fillHandleStyle.value = null;
613
- fillHandleMeasurement = null;
614
- });
615
- }, { immediate: true });
616
- const lastCommittedFillArea = ref(null);
617
- function cloneUiSelectionPoint(point) {
618
- return {
619
- rowId: point.rowId,
620
- rowIndex: point.rowIndex,
621
- colIndex: point.colIndex,
622
- };
623
- }
624
- function cloneUiSelectionRange(range) {
625
- return {
626
- startRow: range.startRow,
627
- endRow: range.endRow,
628
- startCol: range.startCol,
629
- endCol: range.endCol,
630
- startRowId: range.startRowId,
631
- endRowId: range.endRowId,
632
- anchor: cloneUiSelectionPoint(range.anchor),
633
- focus: cloneUiSelectionPoint(range.focus),
634
- };
635
- }
636
- function cloneUiSelectionSnapshot(source) {
637
- const ranges = source.ranges.map(cloneUiSelectionRange);
638
- const activeCell = source.activeCell ? cloneUiSelectionPoint(source.activeCell) : null;
639
- const snapshot = {
640
- ranges,
641
- activeRangeIndex: source.activeRangeIndex,
642
- activeCell,
643
- clone: () => cloneUiSelectionSnapshot(snapshot),
644
- };
645
- return snapshot;
646
- }
647
- function getGridDimensions() {
648
- return {
649
- rowCount: totalRowCount.value,
650
- colCount: localColumns.value.length,
651
- };
652
- }
653
- function getSelectionContext() {
654
- return selectionContext;
655
- }
656
- function clampPointToGrid(point) {
657
- return clampGridSelectionPoint(point, getSelectionContext());
658
- }
659
- function createSelectionPointByIndex(rowIndex, colIndex) {
660
- return clampPointToGrid({
661
- rowId: getRowIdByIndex(rowIndex),
662
- rowIndex,
663
- colIndex,
664
- });
665
- }
666
- function createRange(anchor, focus) {
667
- return createGridSelectionRange(anchor, focus, getSelectionContext());
668
- }
669
- function scheduleOverlayUpdate(options) {
670
- overlayUpdateScheduler.schedule(options);
671
- }
672
- function applyOverlayOffsetToRect(rect) {
673
- const clone = {
674
- id: rect.id,
675
- left: rect.left,
676
- top: rect.top,
677
- width: rect.width,
678
- height: rect.height,
679
- };
680
- if (typeof rect.active === "boolean") {
681
- clone.active = rect.active;
682
- }
683
- if (rect.pin) {
684
- clone.pin = rect.pin;
685
- }
686
- return clone;
687
- }
688
- function offsetOverlayRect(rect) {
689
- if (!rect)
690
- return null;
691
- const clone = applyOverlayOffsetToRect(rect);
692
- releaseOverlayRect(rect);
693
- return clone;
694
- }
695
- function offsetOverlayRectArray(rects, options) {
696
- const shouldRelease = options?.release !== false;
697
- if (!rects.length) {
698
- if (shouldRelease) {
699
- releaseOverlayRectArray(rects);
700
- }
701
- return [];
702
- }
703
- const result = new Array(rects.length);
704
- for (let index = 0; index < rects.length; index += 1) {
705
- result[index] = applyOverlayOffsetToRect(rects[index]);
706
- }
707
- if (shouldRelease) {
708
- releaseOverlayRectArray(rects);
709
- }
710
- return result;
711
- }
712
- function rectsEqual(left, right) {
713
- if (left === right)
714
- return true;
715
- if (!left || !right)
716
- return false;
717
- return (left.left === right.left &&
718
- left.top === right.top &&
719
- left.width === right.width &&
720
- left.height === right.height &&
721
- (left.pin ?? null) === (right.pin ?? null) &&
722
- (left.active ?? false) === (right.active ?? false) &&
723
- left.id === right.id);
724
- }
725
- function rectArraysEqual(left, right) {
726
- if (left === right)
727
- return true;
728
- if (left.length !== right.length)
729
- return false;
730
- for (let index = 0; index < left.length; index += 1) {
731
- if (!rectsEqual(left[index], right[index])) {
732
- return false;
733
- }
734
- }
735
- return true;
736
- }
737
- let cachedPreparedResources = null;
738
- let cachedStaticOverlayRects = null;
739
- function disposeStaticOverlayCache() {
740
- if (!cachedStaticOverlayRects) {
741
- return;
742
- }
743
- releaseOverlayRectArray(cachedStaticOverlayRects.rects);
744
- cachedStaticOverlayRects = null;
745
- }
746
- function buildPreparedResourceKey(context) {
747
- const columnKeys = context.columns.map(column => context.getColumnKey(column)).join("|");
748
- const pinnedLeftKeys = context.pinnedLeft.map(entry => context.getColumnKey(entry.column)).join("|");
749
- const pinnedRightKeys = context.pinnedRight.map(entry => context.getColumnKey(entry.column)).join("|");
750
- const widths = Array.from(context.columnWidthMap.entries())
751
- .sort((a, b) => (a[0] > b[0] ? 1 : a[0] < b[0] ? -1 : 0))
752
- .map(([key, value]) => `${key}:${value}`)
753
- .join("|");
754
- const surfaces = context.columnSurfaces
755
- ? Array.from(context.columnSurfaces.entries())
756
- .sort((a, b) => (a[0] > b[0] ? 1 : a[0] < b[0] ? -1 : 0))
757
- .map(([key, surface]) => {
758
- const left = Math.round(surface.left * 1000) / 1000;
759
- const width = Math.round(surface.width * 1000) / 1000;
760
- return `${key}:${left}:${width}:${surface.pin}`;
761
- })
762
- .join("|")
763
- : "";
764
- return [
765
- context.rowHeight,
766
- context.viewport.width,
767
- context.viewport.height,
768
- context.viewport.scrollTop,
769
- context.viewport.scrollLeft,
770
- columnKeys,
771
- pinnedLeftKeys,
772
- pinnedRightKeys,
773
- widths,
774
- surfaces,
775
- context.rowIndexColumnKey ?? "",
776
- ].join(";");
777
- }
778
- function resolvePreparedResourcesEntry(context) {
779
- const cacheKey = buildPreparedResourceKey(context);
780
- if (cachedPreparedResources && cachedPreparedResources.key === cacheKey) {
781
- return cachedPreparedResources;
782
- }
783
- const prepared = runWithOverlayTiming("prepareResources", () => prepareSelectionOverlayResources(context));
784
- const entry = { key: cacheKey, prepared };
785
- cachedPreparedResources = entry;
786
- return entry;
787
- }
788
- function commitOverlaySnapshotFromRefs() {
789
- selectionControllerAdapter.sync({
790
- overlaySnapshot: {
791
- ranges: selectionOverlayRects.value,
792
- activeRange: activeSelectionOverlayRects.value,
793
- fillPreview: fillPreviewOverlayRects.value,
794
- cutPreview: cutPreviewOverlayRects.value,
795
- cursor: selectionCursorOverlay.value,
796
- },
797
- });
798
- }
799
- function resolveOverlayComputationInputs(state = selectionControllerAdapter.state.value) {
800
- const rowHeight = resolveOverlayRowHeight();
801
- if (!(Number.isFinite(rowHeight) && rowHeight > 0)) {
802
- return null;
803
- }
804
- const context = {
805
- ranges: state.ranges,
806
- activeRangeIndex: state.activeRangeIndex,
807
- activeCell: state.selectedPoint ?? state.anchorPoint ?? null,
808
- fillPreview: fillPreviewRange.value,
809
- cutPreview: cutPreviewRanges.value,
810
- cutPreviewActiveIndex: cutPreviewActiveIndex.value,
811
- columns: localColumns.value,
812
- columnWidthMap: viewport.columnWidthMap.value,
813
- pinnedLeft: viewport.pinnedLeftEntries.value,
814
- pinnedRight: viewport.pinnedRightEntries.value,
815
- viewport: overlayViewport.value,
816
- rowHeight,
817
- getColumnKey: column => column.key,
818
- isSystemColumn: column => column.isSystem === true,
819
- rowIndexColumnKey,
820
- columnSurfaces: columnSurfacesRef?.value,
821
- };
822
- const preparedEntry = resolvePreparedResourcesEntry(context);
823
- return { context, prepared: preparedEntry.prepared, preparedKey: preparedEntry.key };
824
- }
825
- function resolveStaticOverlayRects(inputs, signature) {
826
- if (cachedStaticOverlayRects &&
827
- cachedStaticOverlayRects.signature === signature &&
828
- cachedStaticOverlayRects.preparedKey === inputs.preparedKey) {
829
- return cachedStaticOverlayRects.rects;
830
- }
831
- if (!inputs.prepared) {
832
- disposeStaticOverlayCache();
833
- cachedStaticOverlayRects = {
834
- signature,
835
- preparedKey: inputs.preparedKey,
836
- rects: [],
837
- };
838
- return cachedStaticOverlayRects.rects;
839
- }
840
- const rects = runWithOverlayTiming("computeStaticRangeRects", () => computeStaticRangeOverlayRects(inputs.context, inputs.prepared));
841
- disposeStaticOverlayCache();
842
- cachedStaticOverlayRects = {
843
- signature,
844
- preparedKey: inputs.preparedKey,
845
- rects,
846
- };
847
- return rects;
848
- }
849
- function buildOverlaySignature() {
850
- return buildSelectionOverlaySignature({
851
- ranges: selectionRanges.value,
852
- activeRangeIndex: activeRangeIndex.value,
853
- fillPreview: fillPreviewRange.value,
854
- cutPreviewAreas: cutPreviewRanges.value,
855
- });
856
- }
857
- function resolveOverlayRowHeight() {
858
- const measured = viewport.effectiveRowHeight.value;
859
- if (Number.isFinite(measured) && measured > 0) {
860
- return measured;
861
- }
862
- const sampleColumn = localColumns.value.find(column => {
863
- if (!column)
864
- return false;
865
- if (column.isSystem === true)
866
- return false;
867
- if (rowIndexColumnKey && column.key === rowIndexColumnKey)
868
- return false;
869
- return true;
870
- });
871
- if (sampleColumn) {
872
- const normalizedRow = clamp(viewport.startIndex.value ?? 0, 0, Math.max(totalRowCount.value - 1, 0));
873
- const cellElement = typeof resolveCellElement === "function"
874
- ? resolveCellElement(normalizedRow, sampleColumn.key)
875
- : null;
876
- const fallbackCell = cellElement ?? containerRef.value?.querySelector(`.ui-table-cell[data-row-index="${normalizedRow}"][data-col-key="${sampleColumn.key}"]`);
877
- const rect = fallbackCell?.getBoundingClientRect();
878
- if (rect && rect.height > 0) {
879
- return rect.height;
880
- }
881
- }
882
- return BASE_ROW_HEIGHT;
883
- }
884
- function updateStaticRangeOverlayFromState(state = selectionControllerAdapter.state.value, inputs, options) {
885
- const shouldCommit = options?.commit ?? false;
886
- const shouldUpdateSignature = options?.updateSignature ?? false;
887
- const signature = options?.signature ?? buildOverlaySignature();
888
- const staticSignature = signature.ranges;
889
- let overlayChanged = false;
890
- const resources = inputs === undefined ? resolveOverlayComputationInputs(state) : inputs;
891
- if (!resources) {
892
- if (selectionOverlayRects.value.length) {
893
- selectionOverlayRects.value = [];
894
- overlayChanged = true;
895
- if (shouldCommit) {
896
- commitOverlaySnapshotFromRefs();
897
- }
898
- }
899
- if (shouldUpdateSignature) {
900
- lastOverlaySignature = signature;
901
- pendingOverlaySignature = null;
902
- }
903
- disposeStaticOverlayCache();
904
- return overlayChanged;
905
- }
906
- const rects = resolveStaticOverlayRects(resources, staticSignature);
907
- const offsetRects = offsetOverlayRectArray(rects, { release: false });
908
- if (rectArraysEqual(selectionOverlayRects.value, offsetRects)) {
909
- if (shouldUpdateSignature) {
910
- lastOverlaySignature = signature;
911
- pendingOverlaySignature = null;
912
- }
913
- return overlayChanged;
914
- }
915
- selectionOverlayRects.value = offsetRects;
916
- overlayChanged = true;
917
- if (shouldCommit) {
918
- commitOverlaySnapshotFromRefs();
919
- }
920
- if (shouldUpdateSignature) {
921
- lastOverlaySignature = signature;
922
- pendingOverlaySignature = null;
923
- }
924
- return overlayChanged;
925
- }
926
- function updateCursorOverlayFromState(state = selectionControllerAdapter.state.value, inputs) {
927
- const activeRange = state.ranges.length
928
- ? state.ranges[clamp(state.activeRangeIndex, 0, state.ranges.length - 1)] ?? null
929
- : null;
930
- const isSingleCellActive = Boolean(activeRange &&
931
- activeRange.startRow === activeRange.endRow &&
932
- activeRange.startCol === activeRange.endCol);
933
- if (!isSingleCellActive) {
934
- if (selectionCursorOverlay.value) {
935
- selectionCursorOverlay.value = null;
936
- }
937
- return;
938
- }
939
- const point = state.selectedPoint ?? state.anchorPoint;
940
- if (!point) {
941
- if (selectionCursorOverlay.value) {
942
- selectionCursorOverlay.value = null;
943
- }
944
- return;
945
- }
946
- const resources = inputs === undefined ? resolveOverlayComputationInputs(state) : inputs;
947
- if (!resources || !resources.prepared) {
948
- if (selectionCursorOverlay.value) {
949
- selectionCursorOverlay.value = null;
950
- }
951
- return;
952
- }
953
- // ensure active cell populated for computation context reuse
954
- resources.context.activeCell = point;
955
- const cursorRect = runWithOverlayTiming("computeCursorRect", () => computeCursorOverlayRect(resources.context, resources.prepared));
956
- const offsetCursor = offsetOverlayRect(cursorRect);
957
- if (!rectsEqual(selectionCursorOverlay.value, offsetCursor)) {
958
- // HOT PATH: apply cursor update without touching range overlays
959
- selectionCursorOverlay.value = offsetCursor;
960
- }
961
- }
962
- function updateFillPreviewOverlayFromState(state = selectionControllerAdapter.state.value, inputs, options) {
963
- const shouldCommit = options?.commit ?? false;
964
- const shouldUpdateSignature = options?.updateSignature ?? false;
965
- const signatureOverride = options?.signature;
966
- let overlayChanged = false;
967
- const preview = fillPreviewRange.value;
968
- if (!preview) {
969
- if (fillPreviewOverlayRects.value.length) {
970
- fillPreviewOverlayRects.value = [];
971
- overlayChanged = true;
972
- }
973
- if (overlayChanged && shouldCommit) {
974
- commitOverlaySnapshotFromRefs();
975
- }
976
- if (shouldUpdateSignature) {
977
- lastOverlaySignature = signatureOverride ?? buildOverlaySignature();
978
- pendingOverlaySignature = null;
979
- }
980
- return overlayChanged;
981
- }
982
- const resources = inputs === undefined ? resolveOverlayComputationInputs(state) : inputs;
983
- if (!resources || !resources.prepared) {
984
- if (fillPreviewOverlayRects.value.length) {
985
- fillPreviewOverlayRects.value = [];
986
- overlayChanged = true;
987
- if (shouldCommit) {
988
- commitOverlaySnapshotFromRefs();
989
- }
990
- }
991
- if (shouldUpdateSignature) {
992
- lastOverlaySignature = signatureOverride ?? buildOverlaySignature();
993
- pendingOverlaySignature = null;
994
- }
995
- return overlayChanged;
996
- }
997
- const fillRects = runWithOverlayTiming("computeFillPreviewRects", () => computeFillPreviewOverlayRects(resources.context, resources.prepared));
998
- const offsetFillRects = offsetOverlayRectArray(fillRects);
999
- if (!rectArraysEqual(fillPreviewOverlayRects.value, offsetFillRects)) {
1000
- fillPreviewOverlayRects.value = offsetFillRects;
1001
- overlayChanged = true;
1002
- if (shouldCommit) {
1003
- commitOverlaySnapshotFromRefs();
1004
- }
1005
- }
1006
- if (shouldUpdateSignature) {
1007
- lastOverlaySignature = signatureOverride ?? buildOverlaySignature();
1008
- pendingOverlaySignature = null;
1009
- }
1010
- return overlayChanged;
1011
- }
1012
- function updateCutPreviewOverlayFromState(state = selectionControllerAdapter.state.value, inputs, options) {
1013
- const shouldCommit = options?.commit ?? false;
1014
- const shouldUpdateSignature = options?.updateSignature ?? false;
1015
- const signatureOverride = options?.signature;
1016
- let overlayChanged = false;
1017
- const cutAreas = cutPreviewRanges.value;
1018
- if (!cutAreas.length) {
1019
- if (cutPreviewOverlayRects.value.length) {
1020
- cutPreviewOverlayRects.value = [];
1021
- overlayChanged = true;
1022
- }
1023
- if (overlayChanged && shouldCommit) {
1024
- commitOverlaySnapshotFromRefs();
1025
- }
1026
- if (shouldUpdateSignature) {
1027
- lastOverlaySignature = signatureOverride ?? buildOverlaySignature();
1028
- pendingOverlaySignature = null;
1029
- }
1030
- return overlayChanged;
1031
- }
1032
- const resources = inputs === undefined ? resolveOverlayComputationInputs(state) : inputs;
1033
- if (!resources || !resources.prepared) {
1034
- if (cutPreviewOverlayRects.value.length) {
1035
- cutPreviewOverlayRects.value = [];
1036
- overlayChanged = true;
1037
- if (shouldCommit) {
1038
- commitOverlaySnapshotFromRefs();
1039
- }
1040
- }
1041
- if (shouldUpdateSignature) {
1042
- lastOverlaySignature = signatureOverride ?? buildOverlaySignature();
1043
- pendingOverlaySignature = null;
1044
- }
1045
- return overlayChanged;
1046
- }
1047
- const cutRects = runWithOverlayTiming("computeCutPreviewRects", () => computeCutPreviewOverlayRects(resources.context, resources.prepared));
1048
- const offsetCutRects = offsetOverlayRectArray(cutRects);
1049
- if (!rectArraysEqual(cutPreviewOverlayRects.value, offsetCutRects)) {
1050
- cutPreviewOverlayRects.value = offsetCutRects;
1051
- overlayChanged = true;
1052
- if (shouldCommit) {
1053
- commitOverlaySnapshotFromRefs();
1054
- }
1055
- }
1056
- if (shouldUpdateSignature) {
1057
- lastOverlaySignature = signatureOverride ?? buildOverlaySignature();
1058
- pendingOverlaySignature = null;
1059
- }
1060
- return overlayChanged;
1061
- }
1062
- function updateActiveRangeOverlayFromState(state = selectionControllerAdapter.state.value, inputs, options) {
1063
- const shouldCommit = options?.commit ?? false;
1064
- const shouldUpdateSignature = options?.updateSignature ?? false;
1065
- const signatureOverride = options?.signature;
1066
- let overlayChanged = false;
1067
- const hasRanges = state.ranges.length > 0;
1068
- const activeIndexRaw = state.activeRangeIndex;
1069
- const hasActive = hasRanges && activeIndexRaw >= 0 && activeIndexRaw < state.ranges.length;
1070
- if (!hasActive) {
1071
- if (activeSelectionOverlayRects.value.length) {
1072
- activeSelectionOverlayRects.value = [];
1073
- overlayChanged = true;
1074
- }
1075
- if (overlayChanged && shouldCommit) {
1076
- commitOverlaySnapshotFromRefs();
1077
- }
1078
- if (shouldUpdateSignature) {
1079
- lastOverlaySignature = signatureOverride ?? buildOverlaySignature();
1080
- pendingOverlaySignature = null;
1081
- }
1082
- return overlayChanged;
1083
- }
1084
- const resources = inputs ?? resolveOverlayComputationInputs(state);
1085
- if (!resources || !resources.prepared) {
1086
- if (activeSelectionOverlayRects.value.length) {
1087
- activeSelectionOverlayRects.value = [];
1088
- overlayChanged = true;
1089
- if (shouldCommit) {
1090
- commitOverlaySnapshotFromRefs();
1091
- }
1092
- }
1093
- if (shouldUpdateSignature) {
1094
- lastOverlaySignature = signatureOverride ?? buildOverlaySignature();
1095
- pendingOverlaySignature = null;
1096
- }
1097
- return overlayChanged;
1098
- }
1099
- const activeRects = runWithOverlayTiming("computeActiveRangeRects", () => computeActiveRangeOverlayRects(resources.context, resources.prepared));
1100
- const offsetActiveRects = offsetOverlayRectArray(activeRects);
1101
- if (!rectArraysEqual(activeSelectionOverlayRects.value, offsetActiveRects)) {
1102
- activeSelectionOverlayRects.value = offsetActiveRects;
1103
- overlayChanged = true;
1104
- if (shouldCommit) {
1105
- commitOverlaySnapshotFromRefs();
1106
- }
1107
- }
1108
- if (shouldUpdateSignature) {
1109
- lastOverlaySignature = signatureOverride ?? buildOverlaySignature();
1110
- pendingOverlaySignature = null;
1111
- }
1112
- return overlayChanged;
1113
- }
1114
- function updateSelectionOverlay() {
1115
- runWithOverlayTiming("updateSelectionOverlay", () => {
1116
- const state = selectionControllerAdapter.state.value;
1117
- const signature = pendingOverlaySignature ?? buildOverlaySignature();
1118
- const resources = resolveOverlayComputationInputs(state);
1119
- if (!resources || !resources.prepared) {
1120
- let overlayUpdated = false;
1121
- overlayUpdated = updateStaticRangeOverlayFromState(state, resources ?? null, { commit: false, signature }) || overlayUpdated;
1122
- overlayUpdated = updateActiveRangeOverlayFromState(state, resources ?? null, { commit: false, signature }) || overlayUpdated;
1123
- overlayUpdated = updateFillPreviewOverlayFromState(state, resources ?? null, { commit: false, signature }) || overlayUpdated;
1124
- overlayUpdated = updateCutPreviewOverlayFromState(state, resources ?? null, { commit: false, signature }) || overlayUpdated;
1125
- updateCursorOverlayFromState(state, resources ?? null);
1126
- if (overlayUpdated) {
1127
- commitOverlaySnapshotFromRefs();
1128
- }
1129
- pendingOverlaySignature = signature;
1130
- return;
1131
- }
1132
- let overlayUpdated = false;
1133
- overlayUpdated = updateStaticRangeOverlayFromState(state, resources, { commit: false, signature }) || overlayUpdated;
1134
- overlayUpdated = updateActiveRangeOverlayFromState(state, resources, { commit: false, signature }) || overlayUpdated;
1135
- overlayUpdated = updateFillPreviewOverlayFromState(state, resources, { commit: false, signature }) || overlayUpdated;
1136
- overlayUpdated = updateCutPreviewOverlayFromState(state, resources, { commit: false, signature }) || overlayUpdated;
1137
- updateCursorOverlayFromState(state, resources);
1138
- if (overlayUpdated) {
1139
- commitOverlaySnapshotFromRefs();
1140
- }
1141
- lastOverlaySignature = signature;
1142
- pendingOverlaySignature = null;
1143
- });
1144
- }
1145
- function getActiveRange() {
1146
- if (!selectionRanges.value.length)
1147
- return null;
1148
- const index = clamp(activeRangeIndex.value, 0, selectionRanges.value.length - 1);
1149
- return selectionRanges.value[index] ?? null;
1150
- }
1151
- function getActiveSelectionArea() {
1152
- const active = getActiveRange();
1153
- if (!active)
1154
- return null;
1155
- return {
1156
- startRow: active.startRow,
1157
- endRow: active.endRow,
1158
- startCol: active.startCol,
1159
- endCol: active.endCol,
1160
- };
1161
- }
1162
- function commitHeadlessSelectionState(state) {
1163
- selectionControllerAdapter.sync({ state });
1164
- applyControllerState(selectionControllerAdapter.state.value);
1165
- }
1166
- function commitSelectionResult(result) {
1167
- commitHeadlessSelectionState(result);
1168
- emitSelectionChangeSnapshot(true);
1169
- scheduleOverlayUpdate();
1170
- }
1171
- function reapplySelectionState(overrides) {
1172
- const baseState = selectionControllerAdapter.state.value;
1173
- const nextState = {
1174
- ranges: baseState.ranges,
1175
- areas: baseState.areas,
1176
- activeRangeIndex: baseState.activeRangeIndex,
1177
- selectedPoint: overrides?.selectedPoint === undefined ? baseState.selectedPoint : overrides.selectedPoint ?? null,
1178
- anchorPoint: overrides?.anchorPoint === undefined ? baseState.anchorPoint : overrides.anchorPoint ?? null,
1179
- dragAnchorPoint: overrides?.dragAnchorPoint === undefined ? baseState.dragAnchorPoint : overrides.dragAnchorPoint ?? null,
1180
- };
1181
- selectionControllerAdapter.sync({ state: nextState });
1182
- applyControllerState(selectionControllerAdapter.state.value);
1183
- }
1184
- function applySelectionUpdate(ranges, activeIndex, options) {
1185
- if (!options || (options.selectedPoint === undefined && options.anchorPoint === undefined && options.dragAnchorPoint === undefined)) {
1186
- selectionControllerAdapter.sync({
1187
- ranges: {
1188
- ranges,
1189
- activeRangeIndex: activeIndex,
1190
- },
1191
- });
1192
- applyControllerState(selectionControllerAdapter.state.value);
1193
- return;
1194
- }
1195
- const result = setSelectionRangesHeadless({
1196
- ranges,
1197
- context: getSelectionContext(),
1198
- activeRangeIndex: activeIndex,
1199
- selectedPoint: options?.selectedPoint,
1200
- anchorPoint: options?.anchorPoint,
1201
- dragAnchorPoint: options?.dragAnchorPoint,
1202
- });
1203
- commitSelectionResult(result);
1204
- }
1205
- function setSingleCellSelection(point) {
1206
- clearColumnSelectionState();
1207
- const target = clampPointToGrid(point);
1208
- debugSelectionLog("setSingleCellSelection via controller", target);
1209
- selectionControllerAdapter.sync({ focusPoint: target });
1210
- applyControllerState(selectionControllerAdapter.state.value);
1211
- }
1212
- function extendActiveRangeTo(point) {
1213
- debugSelectionLog("extendActiveRangeTo invoked");
1214
- clearColumnSelectionState();
1215
- const target = clampPointToGrid(point);
1216
- debugSelectionLog("extendSelection", { target, before: selectionControllerAdapter.state.value });
1217
- selectionControllerAdapter.sync({ extendPoint: target });
1218
- debugSelectionLog("extendSelection", { after: selectionControllerAdapter.state.value });
1219
- applyControllerState(selectionControllerAdapter.state.value);
1220
- }
1221
- function findRangeIndexContainingPoint(point) {
1222
- const normalized = clampPointToGrid(point);
1223
- return findRangeIndexContainingCell(selectionRanges.value, normalized.rowIndex, normalized.colIndex);
1224
- }
1225
- function toggleCellSelection(point) {
1226
- clearColumnSelectionState();
1227
- const target = clampPointToGrid(point);
1228
- selectionControllerAdapter.sync({ togglePoint: target });
1229
- applyControllerState(selectionControllerAdapter.state.value);
1230
- }
1231
- function clearCellSelection() {
1232
- clearColumnSelectionState();
1233
- selectionControllerAdapter.sync({ clearSelection: true });
1234
- applyControllerState(selectionControllerAdapter.state.value);
1235
- }
1236
- function emitSelectionChangeSnapshot(force = false) {
1237
- const coreSnapshot = buildCoreSelectionSnapshot();
1238
- const signature = selectionSnapshotSignature(coreSnapshot);
1239
- if (!force && signature === lastSelectionSignature.value)
1240
- return;
1241
- lastSelectionSignature.value = signature;
1242
- emitSelectionChange(convertToUiSnapshot(coreSnapshot));
1243
- }
1244
- function getSelectionSnapshot() {
1245
- const coreSnapshot = buildCoreSelectionSnapshot();
1246
- return convertToUiSnapshot(coreSnapshot).clone();
1247
- }
1248
- function buildCoreSelectionSnapshot() {
1249
- return createSelectionSnapshot({
1250
- ranges: selectionRanges.value,
1251
- activeRangeIndex: activeRangeIndex.value,
1252
- selectedPoint: selectedCell.value,
1253
- getRowIdByIndex,
1254
- });
1255
- }
1256
- function convertToUiSnapshot(coreSnapshot) {
1257
- const ranges = coreSnapshot.ranges;
1258
- const cacheRanges = uiRangeCache;
1259
- let index = 0;
1260
- for (; index < ranges.length; index += 1) {
1261
- const source = ranges[index];
1262
- let target = cacheRanges[index];
1263
- if (!target) {
1264
- target = uiRangePool.pop() ?? {
1265
- startRow: 0,
1266
- endRow: 0,
1267
- startCol: 0,
1268
- endCol: 0,
1269
- startRowId: null,
1270
- endRowId: null,
1271
- anchor: { rowId: null, rowIndex: 0, colIndex: 0 },
1272
- focus: { rowId: null, rowIndex: 0, colIndex: 0 },
1273
- };
1274
- cacheRanges[index] = target;
1275
- }
1276
- target.startRow = source.startRow;
1277
- target.endRow = source.endRow;
1278
- target.startCol = source.startCol;
1279
- target.endCol = source.endCol;
1280
- target.startRowId = source.startRowId ?? null;
1281
- target.endRowId = source.endRowId ?? null;
1282
- const anchor = target.anchor;
1283
- anchor.rowId = source.anchor.rowId ?? null;
1284
- anchor.rowIndex = source.anchor.rowIndex;
1285
- anchor.colIndex = source.anchor.colIndex;
1286
- const focus = target.focus;
1287
- focus.rowId = source.focus.rowId ?? null;
1288
- focus.rowIndex = source.focus.rowIndex;
1289
- focus.colIndex = source.focus.colIndex;
1290
- }
1291
- if (cacheRanges.length > ranges.length) {
1292
- for (let release = ranges.length; release < cacheRanges.length; release += 1) {
1293
- uiRangePool.push(cacheRanges[release]);
1294
- }
1295
- cacheRanges.length = ranges.length;
1296
- }
1297
- uiSnapshotCache.activeRangeIndex = coreSnapshot.activeRangeIndex;
1298
- if (coreSnapshot.activeCell) {
1299
- if (!uiActiveCellCache) {
1300
- uiActiveCellCache = { rowId: null, rowIndex: 0, colIndex: 0 };
1301
- }
1302
- uiActiveCellCache.rowId = coreSnapshot.activeCell.rowId ?? null;
1303
- uiActiveCellCache.rowIndex = coreSnapshot.activeCell.rowIndex;
1304
- uiActiveCellCache.colIndex = coreSnapshot.activeCell.colIndex;
1305
- uiSnapshotCache.activeCell = uiActiveCellCache;
1306
- }
1307
- else {
1308
- uiSnapshotCache.activeCell = null;
1309
- }
1310
- return uiSnapshotCache;
1311
- }
1312
- function focusCell(rowIndex, column, options) {
1313
- if (!hasGridData())
1314
- return false;
1315
- const { rowCount, colCount } = getGridDimensions();
1316
- const targetRow = clamp(rowIndex, 0, Math.max(rowCount - 1, 0));
1317
- if (isFullRowMode.value) {
1318
- clearFullColumnSelection();
1319
- const anchorRow = options?.extend
1320
- ? clamp(resolveRowAnchor(targetRow), 0, Math.max(rowCount - 1, 0))
1321
- : targetRow;
1322
- setFullRowSelectionRange(anchorRow, targetRow, {
1323
- focus: true,
1324
- preserveAnchor: options?.extend,
1325
- anchorRow,
1326
- });
1327
- nextTick(() => scrollSelectionIntoView());
1328
- return true;
1329
- }
1330
- const colIndex = typeof column === "number" ? column : localColumns.value.findIndex(col => col.key === column);
1331
- if (colIndex < 0)
1332
- return false;
1333
- const target = createSelectionPointByIndex(targetRow, clamp(colIndex, 0, Math.max(colCount - 1, 0)));
1334
- clearFullRowSelection();
1335
- clearFullColumnSelection();
1336
- if (options?.extend) {
1337
- extendActiveRangeTo(target);
1338
- }
1339
- else {
1340
- setSingleCellSelection(target);
1341
- }
1342
- focusContainer();
1343
- nextTick(() => scrollSelectionIntoView());
1344
- return true;
1345
- }
1346
- function getActiveCell() {
1347
- if (anchorCell.value) {
1348
- return { ...anchorCell.value };
1349
- }
1350
- return selectedCell.value ? { ...selectedCell.value } : null;
1351
- }
1352
- function getSelectionCursor(option) {
1353
- if (option?.preferAnchor) {
1354
- return anchorCell.value ?? selectedCell.value;
1355
- }
1356
- return selectedCell.value ?? anchorCell.value;
1357
- }
1358
- function goToRowEdge(edge, options) {
1359
- const active = getSelectionCursor();
1360
- if (!active)
1361
- return false;
1362
- const targetCol = edge === "start" ? 0 : Math.max(0, localColumns.value.length - 1);
1363
- return focusCell(active.rowIndex, targetCol, options);
1364
- }
1365
- function goToColumnEdge(edge, options) {
1366
- const active = getSelectionCursor();
1367
- if (!active)
1368
- return false;
1369
- const targetRow = edge === "start" ? 0 : Math.max(0, totalRowCount.value - 1);
1370
- return focusCell(targetRow, active.colIndex, options);
1371
- }
1372
- function goToGridEdge(edge, options) {
1373
- const targetRow = edge === "start" ? 0 : Math.max(0, totalRowCount.value - 1);
1374
- const targetCol = edge === "start" ? 0 : Math.max(0, localColumns.value.length - 1);
1375
- return focusCell(targetRow, targetCol, options);
1376
- }
1377
- function moveByPage(direction, options) {
1378
- const active = getSelectionCursor();
1379
- if (!active)
1380
- return false;
1381
- const rowHeight = effectiveRowHeightRef.value || 1;
1382
- const viewportHeight = viewportHeightRef.value || rowHeight;
1383
- const pageSize = Math.max(1, Math.round(viewportHeight / rowHeight));
1384
- const targetRow = active.rowIndex + direction * pageSize;
1385
- return focusCell(targetRow, active.colIndex, options);
1386
- }
1387
- function hasGridData() {
1388
- return totalRowCount.value > 0 && localColumns.value.length > 0;
1389
- }
1390
- function clearFullRowSelection(force = false) {
1391
- if (!force && isFullRowMode.value)
1392
- return;
1393
- fullRowSelection.value = null;
1394
- rowSelectionAnchor.value = null;
1395
- }
1396
- function setColumnSelectionState(column, anchorRow) {
1397
- columnSelectionState.value = {
1398
- column,
1399
- anchorRow,
1400
- };
1401
- }
1402
- function clearColumnSelectionState() {
1403
- columnSelectionState.value = null;
1404
- }
1405
- function clearFullColumnSelection() {
1406
- if (fullColumnSelection.value === null) {
1407
- return;
1408
- }
1409
- clearColumnSelectionState();
1410
- clearCellSelection();
1411
- }
1412
- function setFullRowSelectionRange(startRow, endRow, options) {
1413
- if (!hasGridData()) {
1414
- debugSelectionLog("moveSelection aborted: no grid data", {
1415
- rowCount: totalRowCount.value,
1416
- colCount: localColumns.value.length,
1417
- });
1418
- return;
1419
- }
1420
- const { rowCount, colCount } = getGridDimensions();
1421
- if (rowCount <= 0 || colCount <= 0)
1422
- return;
1423
- const normalizedStart = clamp(Math.min(startRow, endRow), 0, rowCount - 1);
1424
- const normalizedEnd = clamp(Math.max(startRow, endRow), 0, rowCount - 1);
1425
- if (normalizedStart > normalizedEnd)
1426
- return;
1427
- const nextAnchor = options?.preserveAnchor
1428
- ? rowSelectionAnchor.value
1429
- : options?.anchorRow ?? normalizedStart;
1430
- rowSelectionAnchor.value = nextAnchor != null
1431
- ? clamp(nextAnchor, normalizedStart, normalizedEnd)
1432
- : normalizedStart;
1433
- fullRowSelection.value = {
1434
- start: normalizedStart,
1435
- end: normalizedEnd,
1436
- };
1437
- clearFullColumnSelection();
1438
- const activeRow = rowSelectionAnchor.value ?? normalizedStart;
1439
- const result = resolveFullRowSelection({
1440
- startRow: normalizedStart,
1441
- endRow: normalizedEnd,
1442
- activeRow,
1443
- context: getSelectionContext(),
1444
- });
1445
- commitSelectionResult(result);
1446
- if (options?.focus ?? true) {
1447
- focusContainer();
1448
- }
1449
- }
1450
- function setFullColumnSelection(columnIndex, options) {
1451
- if (!hasGridData())
1452
- return;
1453
- const { rowCount, colCount } = getGridDimensions();
1454
- if (rowCount <= 0 || colCount <= 0)
1455
- return;
1456
- const normalizedColumn = clamp(columnIndex, 0, colCount - 1);
1457
- const anchorCandidate = options?.anchorRow ??
1458
- anchorCell.value?.rowIndex ??
1459
- selectedCell.value?.rowIndex ??
1460
- 0;
1461
- const normalizedAnchorRow = clamp(anchorCandidate, 0, Math.max(rowCount - 1, 0));
1462
- setColumnSelectionState(normalizedColumn, normalizedAnchorRow);
1463
- clearFullRowSelection();
1464
- const result = resolveFullColumnSelection({
1465
- columnIndex: normalizedColumn,
1466
- anchorRow: normalizedAnchorRow,
1467
- retainCursor: options?.retainCursor ?? false,
1468
- context: getSelectionContext(),
1469
- });
1470
- commitSelectionResult(result);
1471
- if (options?.focus ?? true) {
1472
- focusContainer();
1473
- }
1474
- }
1475
- function selectCell(rowIndex, columnKey, focus = true, options) {
1476
- if (!hasGridData())
1477
- return;
1478
- const colIndex = options?.colIndex ?? localColumns.value.findIndex(col => col.key === columnKey);
1479
- if (isFullRowMode.value && !options?.fullColumn) {
1480
- clearFullColumnSelection();
1481
- setFullRowSelectionRange(rowIndex, rowIndex, { focus, anchorRow: rowIndex });
1482
- return;
1483
- }
1484
- if (options?.fullRow) {
1485
- setFullRowSelectionRange(rowIndex, rowIndex, { focus, anchorRow: rowIndex });
1486
- return;
1487
- }
1488
- if (options?.fullColumn) {
1489
- if (isFullRowMode.value) {
1490
- if (focus)
1491
- focusContainer();
1492
- return;
1493
- }
1494
- if (colIndex === -1) {
1495
- clearFullColumnSelection();
1496
- clearCellSelection();
1497
- if (focus)
1498
- focusContainer();
1499
- return;
1500
- }
1501
- setFullColumnSelection(colIndex, { focus, anchorRow: rowIndex });
1502
- return;
1503
- }
1504
- clearFullRowSelection();
1505
- clearFullColumnSelection();
1506
- if (colIndex === -1) {
1507
- if (focus)
1508
- focusContainer();
1509
- return;
1510
- }
1511
- const clampedRow = clamp(rowIndex, 0, totalRowCount.value - 1);
1512
- const clampedCol = clamp(colIndex, 0, localColumns.value.length - 1);
1513
- setSingleCellSelection({ rowIndex: clampedRow, colIndex: clampedCol });
1514
- if (focus)
1515
- focusContainer();
1516
- }
1517
- function scrollSelectionIntoView(attempt = 0) {
1518
- const activeRange = getActiveRange();
1519
- const cursor = getSelectionCursor();
1520
- if (!activeRange && !cursor)
1521
- return;
1522
- selectionEnvironment.dom.scrollSelectionIntoView({
1523
- range: activeRange,
1524
- cursor: cursor ?? null,
1525
- attempt,
1526
- maxAttempts: 4,
1527
- });
1528
- }
1529
- function setSelection(rangesInput, options) {
1530
- const rangesArray = Array.isArray(rangesInput) ? rangesInput : [rangesInput];
1531
- if (!rangesArray.length) {
1532
- clearSelection();
1533
- return;
1534
- }
1535
- clearFullColumnSelection();
1536
- const normalized = rangesArray.map(range => normalizeExternalRange(range));
1537
- if (isFullRowMode.value) {
1538
- const target = normalized[0];
1539
- if (target) {
1540
- setFullRowSelectionRange(target.startRow, target.endRow, {
1541
- focus: options?.focus,
1542
- anchorRow: target.startRow,
1543
- });
1544
- }
1545
- else {
1546
- clearFullRowSelection(true);
1547
- clearCellSelection();
1548
- }
1549
- return;
1550
- }
1551
- clearFullRowSelection();
1552
- const activeIndex = options?.activeRangeIndex ?? 0;
1553
- applySelectionUpdate(normalized, activeIndex);
1554
- if (options?.focus ?? true) {
1555
- focusContainer();
1556
- nextTick(() => scrollSelectionIntoView());
1557
- }
1558
- }
1559
- function normalizeExternalRange(input) {
1560
- return createGridSelectionRangeFromInput({
1561
- startRow: input.startRow,
1562
- endRow: input.endRow,
1563
- startCol: input.startCol,
1564
- endCol: input.endCol,
1565
- anchor: input.anchor
1566
- ? {
1567
- rowId: input.anchor.rowId ?? null,
1568
- rowIndex: input.anchor.rowIndex,
1569
- colIndex: input.anchor.colIndex,
1570
- }
1571
- : undefined,
1572
- focus: input.focus
1573
- ? {
1574
- rowId: input.focus.rowId ?? null,
1575
- rowIndex: input.focus.rowIndex,
1576
- colIndex: input.focus.colIndex,
1577
- }
1578
- : undefined,
1579
- }, getSelectionContext());
1580
- }
1581
- function clearSelection() {
1582
- const hadColumnSelection = fullColumnSelection.value !== null;
1583
- clearFullRowSelection(true);
1584
- clearFullColumnSelection();
1585
- if (!hadColumnSelection) {
1586
- clearCellSelection();
1587
- }
1588
- }
1589
- function iterSelectionCells(callback) {
1590
- const { rowCount, colCount } = getGridDimensions();
1591
- const ranges = selectionRanges.value.length ? selectionRanges.value : [];
1592
- let hadRanges = false;
1593
- for (const range of ranges) {
1594
- hadRanges = true;
1595
- const startRow = clamp(range.startRow, 0, rowCount - 1);
1596
- const endRow = clamp(range.endRow, 0, rowCount - 1);
1597
- const startCol = clamp(range.startCol, 0, colCount - 1);
1598
- const endCol = clamp(range.endCol, 0, colCount - 1);
1599
- for (let row = startRow; row <= endRow; row += 1) {
1600
- for (let col = startCol; col <= endCol; col += 1) {
1601
- callback(row, col, localColumns.value[col]);
1602
- }
1603
- }
1604
- }
1605
- if (!hadRanges) {
1606
- const rowRange = fullRowSelection.value;
1607
- if (rowRange) {
1608
- const startRow = clamp(rowRange.start, 0, rowCount - 1);
1609
- const endRow = clamp(rowRange.end, 0, rowCount - 1);
1610
- for (let row = startRow; row <= endRow; row += 1) {
1611
- for (let col = 0; col < colCount; col += 1) {
1612
- callback(row, col, localColumns.value[col]);
1613
- }
1614
- }
1615
- return;
1616
- }
1617
- }
1618
- const activePoint = anchorCell.value ?? selectedCell.value;
1619
- if (!hadRanges && activePoint) {
1620
- const row = clamp(activePoint.rowIndex, 0, Math.max(rowCount - 1, 0));
1621
- const col = clamp(activePoint.colIndex, 0, Math.max(colCount - 1, 0));
1622
- callback(row, col, localColumns.value[col]);
1623
- }
1624
- }
1625
- function getSelectedCells() {
1626
- const cells = [];
1627
- iterSelectionCells((rowIndex, colIndex, column) => {
1628
- if (!column)
1629
- return;
1630
- const entry = processedRows.value[rowIndex];
1631
- const rowId = entry?.rowId ?? getRowIdByIndex(rowIndex);
1632
- if (rowId == null) {
1633
- return;
1634
- }
1635
- cells.push({
1636
- rowId,
1637
- rowIndex,
1638
- colIndex,
1639
- columnKey: column.key,
1640
- value: entry?.row?.[column.key],
1641
- row: entry?.row,
1642
- });
1643
- });
1644
- return cells;
1645
- }
1646
- function isCellSelected(rowIndex, colIndex) {
1647
- const rowRange = fullRowSelection.value;
1648
- if ((rowRange && rowIndex >= rowRange.start && rowIndex <= rowRange.end) || fullColumnSelection.value === colIndex) {
1649
- return false;
1650
- }
1651
- if (selectionAreas.value.length) {
1652
- return selectionAreas.value.some(area => areaContainsCell(area, rowIndex, colIndex));
1653
- }
1654
- return pointsMatch(anchorCell.value ?? selectedCell.value, rowIndex, colIndex);
1655
- }
1656
- function pointsMatch(point, rowIndex, colIndex) {
1657
- if (!point)
1658
- return false;
1659
- if (point.rowId != null) {
1660
- const candidateRowId = getRowIdByIndex(rowIndex);
1661
- if (candidateRowId != null && candidateRowId === point.rowId) {
1662
- return point.colIndex === colIndex;
1663
- }
1664
- }
1665
- return point.rowIndex === rowIndex && point.colIndex === colIndex;
1666
- }
1667
- function isSelectionAnchorCell(rowIndex, colIndex) {
1668
- return pointsMatch(anchorCell.value, rowIndex, colIndex);
1669
- }
1670
- function isSelectionCursorCell(rowIndex, colIndex) {
1671
- return pointsMatch(selectedCell.value ?? anchorCell.value, rowIndex, colIndex);
1672
- }
1673
- function isRowFullySelected(rowIndex) {
1674
- const range = fullRowSelection.value;
1675
- if (!range)
1676
- return false;
1677
- return rowIndex >= range.start && rowIndex <= range.end;
1678
- }
1679
- function isColumnFullySelected(colIndex) {
1680
- return fullColumnSelection.value === colIndex;
1681
- }
1682
- function isRowInSelectionRect(rowIndex) {
1683
- const rowRange = fullRowSelection.value;
1684
- if (rowRange && rowIndex >= rowRange.start && rowIndex <= rowRange.end) {
1685
- return true;
1686
- }
1687
- if (anyAreaContainsRow(selectionAreas.value, rowIndex)) {
1688
- return true;
1689
- }
1690
- const preview = fillPreviewRange.value;
1691
- if (preview && areaContainsRow(preview, rowIndex)) {
1692
- return true;
1693
- }
1694
- return false;
1695
- }
1696
- function isColumnInSelectionRect(colIndex) {
1697
- if (anyAreaContainsColumn(selectionAreas.value, colIndex)) {
1698
- return true;
1699
- }
1700
- const preview = fillPreviewRange.value;
1701
- if (preview && areaContainsColumn(preview, colIndex)) {
1702
- return true;
1703
- }
1704
- return false;
1705
- }
1706
- function isCellInFillPreview(rowIndex, colIndex) {
1707
- const preview = fillPreviewRange.value;
1708
- if (!preview || !areaContainsCell(preview, rowIndex, colIndex))
1709
- return false;
1710
- const origin = fillSession.value?.origin;
1711
- if (origin && rangeContainsCell(origin, rowIndex, colIndex)) {
1712
- return false;
1713
- }
1714
- return true;
1715
- }
1716
- function getSelectionEdges(rowIndex, colIndex) {
1717
- return computeSelectionEdges(selectionRanges.value, activeRangeIndex.value, rowIndex, colIndex);
1718
- }
1719
- function getFillPreviewEdges(rowIndex, colIndex) {
1720
- const preview = fillPreviewRange.value;
1721
- if (!preview)
1722
- return null;
1723
- const origin = fillSession.value?.origin;
1724
- if (origin && rangeContainsCell(origin, rowIndex, colIndex)) {
1725
- return null;
1726
- }
1727
- const edges = areaEdges(preview, rowIndex, colIndex);
1728
- if (!edges)
1729
- return null;
1730
- return {
1731
- ...edges,
1732
- active: true,
1733
- };
1734
- }
1735
- function beginCutPreview(snapshot) {
1736
- const result = resolveCutPreviewFromSnapshot(snapshot, getSelectionContext());
1737
- if (!result) {
1738
- pendingCutState.value = null;
1739
- cutPreviewState.value = null;
1740
- const controllerState = selectionControllerAdapter.state.value;
1741
- const resources = resolveOverlayComputationInputs(controllerState);
1742
- updateCutPreviewOverlayFromState(controllerState, resources, {
1743
- commit: true,
1744
- updateSignature: true,
1745
- });
1746
- return;
1747
- }
1748
- pendingCutState.value = snapshot
1749
- ? {
1750
- snapshot: snapshot.clone(),
1751
- fullRowRange: fullRowSelection.value
1752
- ? { start: fullRowSelection.value.start, end: fullRowSelection.value.end }
1753
- : null,
1754
- }
1755
- : null;
1756
- cutPreviewState.value = result;
1757
- const controllerState = selectionControllerAdapter.state.value;
1758
- const resources = resolveOverlayComputationInputs(controllerState);
1759
- updateCutPreviewOverlayFromState(controllerState, resources, {
1760
- commit: true,
1761
- updateSignature: true,
1762
- });
1763
- }
1764
- function clearCutPreview() {
1765
- cutPreviewState.value = null;
1766
- pendingCutState.value = null;
1767
- const controllerState = selectionControllerAdapter.state.value;
1768
- const resources = resolveOverlayComputationInputs(controllerState);
1769
- updateCutPreviewOverlayFromState(controllerState, resources, {
1770
- commit: true,
1771
- updateSignature: true,
1772
- });
1773
- }
1774
- function commitPendingCut() {
1775
- const pending = pendingCutState.value;
1776
- if (!pending)
1777
- return false;
1778
- if (!hasGridData()) {
1779
- pendingCutState.value = null;
1780
- return false;
1781
- }
1782
- const { snapshot, fullRowRange } = pending;
1783
- const { rowCount, colCount } = getGridDimensions();
1784
- let changed = false;
1785
- if (fullRowRange && deleteRows) {
1786
- const startRow = clamp(fullRowRange.start, 0, Math.max(rowCount - 1, 0));
1787
- const endRow = clamp(fullRowRange.end, 0, Math.max(rowCount - 1, 0));
1788
- if (startRow <= endRow) {
1789
- const rows = [];
1790
- for (let row = startRow; row <= endRow; row += 1) {
1791
- rows.push(row);
1792
- }
1793
- if (rows.length) {
1794
- const payload = rows.map(displayIndex => {
1795
- const entry = processedRows.value[displayIndex];
1796
- return {
1797
- displayIndex,
1798
- originalIndex: entry?.originalIndex ?? displayIndex,
1799
- row: entry?.row,
1800
- };
1801
- });
1802
- deleteRows(payload);
1803
- changed = true;
1804
- }
1805
- }
1806
- }
1807
- else {
1808
- const preview = resolveCutPreviewFromSnapshot(snapshot, getSelectionContext());
1809
- const areas = preview?.areas ?? [];
1810
- if (areas.length) {
1811
- const batchEvents = [];
1812
- const historyEntries = [];
1813
- for (const area of areas) {
1814
- const startRow = clamp(area.startRow, 0, Math.max(rowCount - 1, 0));
1815
- const endRow = clamp(area.endRow, 0, Math.max(rowCount - 1, 0));
1816
- const startCol = clamp(area.startCol, 0, Math.max(colCount - 1, 0));
1817
- const endCol = clamp(area.endCol, 0, Math.max(colCount - 1, 0));
1818
- for (let row = startRow; row <= endRow; row += 1) {
1819
- for (let col = startCol; col <= endCol; col += 1) {
1820
- const column = localColumns.value[col];
1821
- if (!column || !canPasteIntoColumn(column))
1822
- continue;
1823
- if (setCellValueDirect(row, col, null, {
1824
- collector: batchEvents,
1825
- historyCollector: historyEntries,
1826
- })) {
1827
- changed = true;
1828
- }
1829
- }
1830
- }
1831
- }
1832
- dispatchEvents(batchEvents);
1833
- if (historyEntries.length) {
1834
- recordHistory(historyEntries);
1835
- }
1836
- }
1837
- }
1838
- pendingCutState.value = null;
1839
- if (changed) {
1840
- scheduleOverlayUpdate();
1841
- }
1842
- return changed;
1843
- }
1844
- function hasCutPreview() {
1845
- return Boolean(cutPreviewState.value?.areas.length);
1846
- }
1847
- function isCellInCutPreview(rowIndex, colIndex) {
1848
- const areas = cutPreviewState.value?.areas;
1849
- if (!areas)
1850
- return false;
1851
- return areas.some(range => areaContainsCell(range, rowIndex, colIndex));
1852
- }
1853
- function getCutPreviewEdges(rowIndex, colIndex) {
1854
- const state = cutPreviewState.value;
1855
- if (!state)
1856
- return null;
1857
- const index = findAreaIndexContaining(state.areas, rowIndex, colIndex);
1858
- if (index === -1)
1859
- return null;
1860
- const edges = areaEdges(state.areas[index], rowIndex, colIndex);
1861
- if (!edges)
1862
- return null;
1863
- return {
1864
- ...edges,
1865
- active: index === state.activeIndex,
1866
- };
1867
- }
1868
- function buildSelectionSnapshot(options) {
1869
- imperativeSnapshotGeneration += 1;
1870
- const generation = imperativeSnapshotGeneration;
1871
- const snapshot = imperativeSnapshotCache;
1872
- const snapshotHasCutPreview = hasCutPreview();
1873
- const rowSelection = snapshot.rowSelection;
1874
- const columnSelection = snapshot.columnSelection;
1875
- rowSelection.clear();
1876
- columnSelection.clear();
1877
- const cells = snapshot.cells;
1878
- for (const [, cell] of cells) {
1879
- cell.generation = 0;
1880
- }
1881
- const rowClasses = snapshot.rowClasses;
1882
- for (const [, entry] of rowClasses) {
1883
- entry.generation = 0;
1884
- }
1885
- const activeRowIndex = (anchorCell.value ?? selectedCell.value)?.rowIndex ?? null;
1886
- for (let index = 0; index < options.rowIndices.length; index += 1) {
1887
- const rowIndex = options.rowIndices[index];
1888
- if (!Number.isFinite(rowIndex) || rowIndex < 0)
1889
- continue;
1890
- if (isRowFullySelected(rowIndex)) {
1891
- rowSelection.add(rowIndex);
1892
- }
1893
- }
1894
- for (let index = 0; index < options.columnIndices.length; index += 1) {
1895
- const columnIndex = options.columnIndices[index];
1896
- if (!Number.isFinite(columnIndex) || columnIndex < 0)
1897
- continue;
1898
- if (isColumnFullySelected(columnIndex)) {
1899
- columnSelection.add(columnIndex);
1900
- }
1901
- }
1902
- for (let rIndex = 0; rIndex < options.rowIndices.length; rIndex += 1) {
1903
- const rowIndex = options.rowIndices[rIndex];
1904
- if (!Number.isFinite(rowIndex) || rowIndex < 0)
1905
- continue;
1906
- const isFullRow = rowSelection.has(rowIndex);
1907
- const inSelectionRect = isRowInSelectionRect(rowIndex);
1908
- const isHighlighted = isFullRow || activeRowIndex === rowIndex || inSelectionRect;
1909
- const rowClassValue = resolveRowHeaderClassValue(isFullRow, isHighlighted, inSelectionRect);
1910
- const rowEntry = rowClasses.get(rowIndex);
1911
- if (rowEntry) {
1912
- rowEntry.value = rowClassValue;
1913
- rowEntry.generation = generation;
1914
- }
1915
- else {
1916
- rowClasses.set(rowIndex, { value: rowClassValue, generation });
1917
- }
1918
- for (let cIndex = 0; cIndex < options.columnIndices.length; cIndex += 1) {
1919
- const columnIndex = options.columnIndices[cIndex];
1920
- if (!Number.isFinite(columnIndex) || columnIndex < 0)
1921
- continue;
1922
- const key = createSelectionCellKey(rowIndex, columnIndex);
1923
- let cellState = cells.get(key);
1924
- if (!cellState) {
1925
- cellState = {
1926
- isSelected: false,
1927
- isRangeSelected: false,
1928
- isFillPreview: false,
1929
- fillPreviewEdges: null,
1930
- isCutPreview: false,
1931
- cutPreviewEdges: null,
1932
- rangeEdges: null,
1933
- generation,
1934
- };
1935
- cells.set(key, cellState);
1936
- }
1937
- else {
1938
- cellState.generation = generation;
1939
- }
1940
- cellState.isSelected = isCellSelected(rowIndex, columnIndex);
1941
- cellState.isRangeSelected = findRangeIndexContainingPoint({ rowIndex, colIndex: columnIndex }) !== -1;
1942
- cellState.isFillPreview = isCellInFillPreview(rowIndex, columnIndex);
1943
- cellState.fillPreviewEdges = cellState.isFillPreview ? getFillPreviewEdges(rowIndex, columnIndex) : null;
1944
- cellState.isCutPreview = snapshotHasCutPreview && isCellInCutPreview(rowIndex, columnIndex);
1945
- cellState.cutPreviewEdges = cellState.isCutPreview ? getCutPreviewEdges(rowIndex, columnIndex) : null;
1946
- cellState.rangeEdges = cellState.isRangeSelected ? getSelectionEdges(rowIndex, columnIndex) : null;
1947
- }
1948
- }
1949
- for (const [key, cell] of cells) {
1950
- if (cell.generation !== generation) {
1951
- cells.delete(key);
1952
- }
1953
- }
1954
- for (const [rowIndex, entry] of rowClasses) {
1955
- if (entry.generation !== generation) {
1956
- rowClasses.delete(rowIndex);
1957
- }
1958
- }
1959
- const anchor = anchorCell.value;
1960
- const cursor = selectedCell.value ?? anchorCell.value ?? null;
1961
- snapshot.hasCutPreview = snapshotHasCutPreview;
1962
- snapshot.anchorKey = anchor ? createSelectionCellKey(anchor.rowIndex, anchor.colIndex) : null;
1963
- snapshot.cursorKey = cursor ? createSelectionCellKey(cursor.rowIndex, cursor.colIndex) : null;
1964
- snapshot.generation = generation;
1965
- return snapshot;
1966
- }
1967
- function areCutPreviewStatesEqual(a, b) {
1968
- if (a === b)
1969
- return true;
1970
- if (!a || !b)
1971
- return false;
1972
- if (a.activeIndex !== b.activeIndex)
1973
- return false;
1974
- if (a.areas.length !== b.areas.length)
1975
- return false;
1976
- for (let index = 0; index < a.areas.length; index += 1) {
1977
- const left = a.areas[index];
1978
- const right = b.areas[index];
1979
- if (left.startRow !== right.startRow ||
1980
- left.endRow !== right.endRow ||
1981
- left.startCol !== right.startCol ||
1982
- left.endCol !== right.endCol) {
1983
- return false;
1984
- }
1985
- }
1986
- return true;
1987
- }
1988
- function rowHeaderClass(rowIndex) {
1989
- const cachedRow = imperativeSnapshotCache.rowClasses.get(rowIndex);
1990
- if (cachedRow && cachedRow.generation === imperativeSnapshotCache.generation) {
1991
- return cachedRow.value;
1992
- }
1993
- const isFull = isRowFullySelected(rowIndex);
1994
- const activeRow = (anchorCell.value ?? selectedCell.value)?.rowIndex ?? null;
1995
- const inSelection = isRowInSelectionRect(rowIndex);
1996
- const isHighlighted = isFull || activeRow === rowIndex || inSelection;
1997
- return resolveRowHeaderClassValue(isFull, isHighlighted, inSelection);
1998
- }
1999
- function onCellSelect(payload) {
2000
- const shouldFocus = payload.focus ?? true;
2001
- const colIndex = payload.colIndex ?? localColumns.value.findIndex(col => col.key === payload.key);
2002
- if (colIndex === -1) {
2003
- selectCell(payload.rowIndex, payload.key, shouldFocus, { colIndex });
2004
- return;
2005
- }
2006
- const clampedRow = clamp(payload.rowIndex, 0, Math.max(totalRowCount.value - 1, 0));
2007
- const clampedCol = clamp(colIndex, 0, Math.max(localColumns.value.length - 1, 0));
2008
- const point = createSelectionPointByIndex(clampedRow, clampedCol);
2009
- const event = payload.event;
2010
- if (isFullRowMode.value) {
2011
- const targetRow = point.rowIndex;
2012
- if (event?.shiftKey) {
2013
- const anchorRow = clamp(resolveRowAnchor(targetRow), 0, Math.max(totalRowCount.value - 1, 0));
2014
- setFullRowSelectionRange(anchorRow, targetRow, { focus: shouldFocus, anchorRow });
2015
- }
2016
- else {
2017
- setFullRowSelectionRange(targetRow, targetRow, { focus: shouldFocus, anchorRow: targetRow });
2018
- }
2019
- if (shouldFocus)
2020
- focusContainer();
2021
- return;
2022
- }
2023
- if (event?.shiftKey) {
2024
- extendActiveRangeTo(point);
2025
- if (shouldFocus)
2026
- focusContainer();
2027
- return;
2028
- }
2029
- if (event && (event.ctrlKey || event.metaKey)) {
2030
- toggleCellSelection(point);
2031
- if (shouldFocus)
2032
- focusContainer();
2033
- return;
2034
- }
2035
- selectCell(point.rowIndex, payload.key, shouldFocus, { colIndex: point.colIndex });
2036
- }
2037
- function resolveRowAnchor(fallback) {
2038
- if (rowSelectionAnchor.value != null)
2039
- return rowSelectionAnchor.value;
2040
- const active = anchorCell.value ?? selectedCell.value;
2041
- if (active)
2042
- return active.rowIndex;
2043
- return fallback;
2044
- }
2045
- function onRowIndexClick(rowIndex, event) {
2046
- if (!hasGridData())
2047
- return;
2048
- reapplySelectionState({ dragAnchorPoint: null });
2049
- const clampedRow = clamp(rowIndex, 0, Math.max(totalRowCount.value - 1, 0));
2050
- const isShift = Boolean(event?.shiftKey);
2051
- const isToggle = Boolean(event?.metaKey || event?.ctrlKey);
2052
- if (isShift) {
2053
- const anchorRow = clamp(resolveRowAnchor(clampedRow), 0, Math.max(totalRowCount.value - 1, 0));
2054
- setFullRowSelectionRange(anchorRow, clampedRow, { focus: true, anchorRow });
2055
- event?.preventDefault();
2056
- return;
2057
- }
2058
- if (isToggle) {
2059
- const range = fullRowSelection.value;
2060
- if (range && clampedRow >= range.start && clampedRow <= range.end) {
2061
- clearFullRowSelection(true);
2062
- clearCellSelection();
2063
- focusContainer();
2064
- return;
2065
- }
2066
- }
2067
- setFullRowSelectionRange(clampedRow, clampedRow, { focus: true, anchorRow: clampedRow });
2068
- rowSelectionAnchor.value = clampedRow;
2069
- if (event?.button !== 0)
2070
- return;
2071
- haltAutoScroll();
2072
- isRowSelectionDragging.value = true;
2073
- const pointer = toSelectionPointerCoordinates(event);
2074
- lastPointer.value = pointer;
2075
- runAutoScrollUpdate(pointer);
2076
- window.addEventListener("mousemove", onRowSelectionMouseMove, { passive: false });
2077
- window.addEventListener("mouseup", handleRowSelectionMouseUp);
2078
- event.preventDefault();
2079
- }
2080
- function onColumnHeaderClick(colIndex) {
2081
- if (!hasGridData())
2082
- return;
2083
- if (isFullRowMode.value) {
2084
- clearFullColumnSelection();
2085
- focusContainer();
2086
- return;
2087
- }
2088
- reapplySelectionState({ dragAnchorPoint: null });
2089
- const clampedIndex = clamp(colIndex, 0, Math.max(localColumns.value.length - 1, 0));
2090
- if (fullColumnSelection.value === clampedIndex) {
2091
- clearFullColumnSelection();
2092
- clearCellSelection();
2093
- focusContainer();
2094
- return;
2095
- }
2096
- setFullColumnSelection(clampedIndex, { focus: true });
2097
- }
2098
- function onCellDragStart(payload) {
2099
- if (isEditingCell.value)
2100
- return;
2101
- if (!hasGridData())
2102
- return;
2103
- if (payload.event.button !== 0)
2104
- return;
2105
- if (isFullRowMode.value)
2106
- return;
2107
- clearFullRowSelection();
2108
- clearFullColumnSelection();
2109
- isDraggingSelection.value = true;
2110
- const anchor = createSelectionPointByIndex(clamp(payload.rowIndex, 0, totalRowCount.value - 1), clamp(payload.colIndex, 0, localColumns.value.length - 1));
2111
- selectionDragSession.value = startSelectionDragSession({
2112
- anchorPoint: anchor,
2113
- context: getSelectionContext(),
2114
- });
2115
- reapplySelectionState({ dragAnchorPoint: anchor });
2116
- const pointer = toSelectionPointerCoordinates(payload.event);
2117
- lastPointer.value = pointer;
2118
- if (!selectionRanges.value.length) {
2119
- setSingleCellSelection(anchor);
2120
- }
2121
- haltAutoScroll();
2122
- runAutoScrollUpdate(pointer);
2123
- window.addEventListener("mousemove", onSelectionMouseMove, { passive: false });
2124
- window.addEventListener("mouseup", handleSelectionMouseUp);
2125
- focusContainer();
2126
- payload.event.preventDefault();
2127
- }
2128
- function onCellDragEnter(payload) {
2129
- if (!isDraggingSelection.value)
2130
- return;
2131
- if (!(payload.event.buttons & 1)) {
2132
- handleSelectionMouseUp();
2133
- return;
2134
- }
2135
- extendSelectionDragToPoint(createSelectionPointByIndex(payload.rowIndex, payload.colIndex));
2136
- }
2137
- function extendSelectionDragToPoint(point) {
2138
- if (!isDraggingSelection.value || !point)
2139
- return;
2140
- extendActiveRangeTo(point);
2141
- }
2142
- function updateSelectionDragFromPoint(clientX, clientY) {
2143
- if (!isDraggingSelection.value)
2144
- return;
2145
- const session = selectionDragSession.value;
2146
- if (session) {
2147
- const point = updateSelectionDragSession(session, {
2148
- clientX,
2149
- clientY,
2150
- resolvePoint: getCellFromPoint,
2151
- context: getSelectionContext(),
2152
- });
2153
- extendSelectionDragToPoint(point);
2154
- return;
2155
- }
2156
- extendSelectionDragToPoint(getCellFromPoint(clientX, clientY));
2157
- }
2158
- function onSelectionMouseMove(event) {
2159
- if (!isDraggingSelection.value)
2160
- return;
2161
- event.preventDefault();
2162
- const pointer = toSelectionPointerCoordinates(event);
2163
- lastPointer.value = pointer;
2164
- updateSelectionDragFromPoint(pointer.clientX, pointer.clientY);
2165
- runAutoScrollUpdate(pointer);
2166
- }
2167
- function handleSelectionMouseUp() {
2168
- if (!isDraggingSelection.value)
2169
- return;
2170
- isDraggingSelection.value = false;
2171
- window.removeEventListener("mouseup", handleSelectionMouseUp);
2172
- window.removeEventListener("mousemove", onSelectionMouseMove);
2173
- if (selectionDragSession.value) {
2174
- endSelectionDragSession(selectionDragSession.value);
2175
- selectionDragSession.value = null;
2176
- }
2177
- haltAutoScroll();
2178
- lastPointer.value = null;
2179
- }
2180
- function getCellFromPoint(clientX, clientY) {
2181
- const resolvePoint = selectionEnvironment.dom.resolveCellFromPoint;
2182
- const resolved = resolvePoint ? resolvePoint(clientX, clientY) : domAdapter.resolveCellFromPoint(clientX, clientY);
2183
- if (!resolved)
2184
- return null;
2185
- return clampPointToGrid(resolved);
2186
- }
2187
- function getRowIndexFromPoint(clientX, clientY) {
2188
- const resolveRow = selectionEnvironment.dom.resolveRowIndexFromPoint;
2189
- if (resolveRow) {
2190
- return resolveRow(clientX, clientY);
2191
- }
2192
- return domAdapter.resolveRowIndexFromPoint(clientX, clientY);
2193
- }
2194
- function updateRowSelectionFromPoint(clientX, clientY) {
2195
- const targetRow = getRowIndexFromPoint(clientX, clientY);
2196
- if (targetRow === null)
2197
- return;
2198
- const anchorRow = rowSelectionAnchor.value ?? targetRow;
2199
- setFullRowSelectionRange(anchorRow, targetRow, { focus: false, anchorRow });
2200
- }
2201
- function onRowSelectionMouseMove(event) {
2202
- if (!isRowSelectionDragging.value)
2203
- return;
2204
- event.preventDefault();
2205
- const pointer = toSelectionPointerCoordinates(event);
2206
- updateRowSelectionFromPoint(pointer.clientX, pointer.clientY);
2207
- lastPointer.value = pointer;
2208
- runAutoScrollUpdate(pointer);
2209
- }
2210
- function handleRowSelectionMouseUp() {
2211
- if (!isRowSelectionDragging.value)
2212
- return;
2213
- isRowSelectionDragging.value = false;
2214
- window.removeEventListener("mousemove", onRowSelectionMouseMove);
2215
- window.removeEventListener("mouseup", handleRowSelectionMouseUp);
2216
- haltAutoScroll();
2217
- lastPointer.value = null;
2218
- }
2219
- function startFillDrag(event) {
2220
- if (isEditingCell.value)
2221
- return;
2222
- if (isFullRowMode.value)
2223
- return;
2224
- const origin = getActiveRange();
2225
- if (!origin)
2226
- return;
2227
- event.preventDefault();
2228
- event.stopPropagation();
2229
- const session = startCoreFillDragSession({
2230
- origin,
2231
- context: getSelectionContext(),
2232
- });
2233
- if (!session)
2234
- return;
2235
- setFillSession(session);
2236
- isFillDragging.value = true;
2237
- const pointer = toSelectionPointerCoordinates(event);
2238
- lastPointer.value = pointer;
2239
- updateFillPreviewFromPoint(pointer.clientX, pointer.clientY);
2240
- runAutoScrollUpdate(pointer);
2241
- window.addEventListener("mousemove", onFillMouseMove, { passive: false });
2242
- window.addEventListener("mouseup", onFillMouseUp, { passive: false });
2243
- }
2244
- function onFillMouseMove(event) {
2245
- if (!isFillDragging.value)
2246
- return;
2247
- event.preventDefault();
2248
- const pointer = toSelectionPointerCoordinates(event);
2249
- updateFillPreviewFromPoint(pointer.clientX, pointer.clientY);
2250
- runAutoScrollUpdate(pointer);
2251
- }
2252
- function onFillMouseUp(event) {
2253
- if (!isFillDragging.value)
2254
- return;
2255
- event.preventDefault();
2256
- window.removeEventListener("mousemove", onFillMouseMove);
2257
- window.removeEventListener("mouseup", onFillMouseUp);
2258
- updateFillPreviewFromPoint(event.clientX, event.clientY);
2259
- haltAutoScroll();
2260
- const shouldCommit = Boolean(fillPreviewRange.value);
2261
- if (shouldCommit) {
2262
- applyFillOperation();
2263
- }
2264
- resetFillState();
2265
- scheduleOverlayUpdate();
2266
- }
2267
- function resetFillState() {
2268
- haltAutoScroll();
2269
- isFillDragging.value = false;
2270
- setFillSession(null);
2271
- const controllerState = selectionControllerAdapter.state.value;
2272
- updateFillPreviewOverlayFromState(controllerState, undefined, {
2273
- commit: true,
2274
- updateSignature: true,
2275
- });
2276
- }
2277
- function applyFillOperation() {
2278
- const session = fillSession.value;
2279
- if (!session || !session.preview)
2280
- return;
2281
- const origin = session.origin;
2282
- const preview = session.preview;
2283
- const batchEvents = [];
2284
- const historyEntries = [];
2285
- const result = commitFillPreview({
2286
- origin,
2287
- preview,
2288
- target: session.target ?? undefined,
2289
- context: getSelectionContext(),
2290
- reader: (rowIndex, colIndex) => getCellRawValue(rowIndex, colIndex),
2291
- writer: (rowIndex, colIndex, value) => setCellValueDirect(rowIndex, colIndex, value, {
2292
- collector: batchEvents,
2293
- historyCollector: historyEntries,
2294
- }),
2295
- });
2296
- dispatchEvents(batchEvents);
2297
- if (historyEntries.length) {
2298
- recordHistory(historyEntries);
2299
- }
2300
- const anchor = { ...origin.anchor };
2301
- if (!result) {
2302
- applySelectionUpdate([createRange(anchor, origin.focus)], 0);
2303
- lastCommittedFillArea.value = null;
2304
- focusContainer();
2305
- return;
2306
- }
2307
- const focus = result.changed ? { ...result.focus } : { ...origin.focus };
2308
- applySelectionUpdate([createRange(anchor, focus)], 0);
2309
- lastCommittedFillArea.value = result.changed ? { ...result.appliedArea } : null;
2310
- focusContainer();
2311
- }
2312
- function autoFillDownFromActiveRange() {
2313
- const origin = getActiveRange();
2314
- if (!origin)
2315
- return;
2316
- const context = getSelectionContext();
2317
- const result = resolveAutoFillDown({
2318
- origin,
2319
- context,
2320
- });
2321
- if (!result)
2322
- return;
2323
- const session = startCoreFillDragSession({
2324
- origin,
2325
- context,
2326
- });
2327
- if (!session)
2328
- return;
2329
- const hydratedSession = fillDragSessionWithPreview(session, {
2330
- preview: result.preview,
2331
- target: result.target,
2332
- context,
2333
- });
2334
- setFillSession(hydratedSession);
2335
- applyFillOperation();
2336
- resetFillState();
2337
- scheduleOverlayUpdate();
2338
- }
2339
- function handleAutoScrollFrame() {
2340
- const pointer = lastPointer.value;
2341
- if (isFillDragging.value && pointer) {
2342
- updateFillPreviewFromPoint(pointer.clientX, pointer.clientY);
2343
- }
2344
- else if (isDraggingSelection.value && pointer) {
2345
- updateSelectionDragFromPoint(pointer.clientX, pointer.clientY);
2346
- }
2347
- else if (isRowSelectionDragging.value && pointer) {
2348
- updateRowSelectionFromPoint(pointer.clientX, pointer.clientY);
2349
- }
2350
- scheduleOverlayUpdate();
2351
- }
2352
- function updateFillPreviewFromPoint(clientX, clientY) {
2353
- if (!fillSession.value)
2354
- return;
2355
- const target = getCellFromPoint(clientX, clientY);
2356
- const effectiveTarget = target ?? fillSession.value.target;
2357
- updateFillPreviewForTarget(effectiveTarget ?? null);
2358
- }
2359
- function updateFillPreviewForTarget(target) {
2360
- const session = fillSession.value;
2361
- if (!session)
2362
- return;
2363
- updateCoreFillDragSession(session, {
2364
- target,
2365
- context: getSelectionContext(),
2366
- });
2367
- refreshFillSession(session);
2368
- const controllerState = selectionControllerAdapter.state.value;
2369
- const resources = resolveOverlayComputationInputs(controllerState);
2370
- updateFillPreviewOverlayFromState(controllerState, resources, {
2371
- commit: true,
2372
- updateSignature: true,
2373
- });
2374
- updateCursorOverlayFromState(controllerState, resources);
2375
- }
2376
- function getBoundsForRange(range, fallbackToAll) {
2377
- return resolveSelectionBounds(range, getSelectionContext(), fallbackToAll);
2378
- }
2379
- function buildSelectionMatrix(range, options) {
2380
- const bounds = getBoundsForRange(range, options?.fallbackToAll ?? false);
2381
- if (!bounds)
2382
- return [];
2383
- const { rowCount, colCount } = getGridDimensions();
2384
- if (rowCount <= 0 || colCount <= 0)
2385
- return [];
2386
- const clampRow = (index) => clamp(index, 0, rowCount - 1);
2387
- const clampCol = (index) => clamp(index, 0, colCount - 1);
2388
- const columnIndices = [];
2389
- for (let colIndex = bounds.startCol; colIndex <= bounds.endCol; colIndex += 1) {
2390
- columnIndices.push(clampCol(colIndex));
2391
- }
2392
- if (!columnIndices.length) {
2393
- return [];
2394
- }
2395
- const matrix = [];
2396
- if (options?.includeHeaders) {
2397
- const headerRow = [];
2398
- for (const colIndex of columnIndices) {
2399
- const column = localColumns.value[colIndex];
2400
- const label = typeof column?.label === "string" && column.label.trim().length
2401
- ? column.label
2402
- : column?.key ?? "";
2403
- headerRow.push(String(label ?? ""));
2404
- }
2405
- matrix.push(headerRow);
2406
- }
2407
- for (let rowIndex = bounds.startRow; rowIndex <= bounds.endRow; rowIndex += 1) {
2408
- const safeRowIndex = clampRow(rowIndex);
2409
- const values = [];
2410
- for (const colIndex of columnIndices) {
2411
- const raw = getCellRawValue(safeRowIndex, colIndex);
2412
- if (raw === null || raw === undefined) {
2413
- values.push("");
2414
- continue;
2415
- }
2416
- if (typeof raw === "string") {
2417
- values.push(raw);
2418
- continue;
2419
- }
2420
- if (typeof raw === "number" || typeof raw === "boolean") {
2421
- values.push(String(raw));
2422
- continue;
2423
- }
2424
- values.push(raw?.toString?.() ?? "");
2425
- }
2426
- matrix.push(values);
2427
- }
2428
- return matrix;
2429
- }
2430
- function applyMatrixToSelection(matrix, baseOverride) {
2431
- if (!matrix.length || !matrix[0]?.length)
2432
- return;
2433
- const { rowCount, colCount } = getGridDimensions();
2434
- if (rowCount <= 0 || colCount <= 0)
2435
- return;
2436
- if (isFullRowMode.value)
2437
- return;
2438
- const matrixRowCount = matrix.length;
2439
- const matrixColBaseline = matrix[0]?.length ?? 0;
2440
- const activeRange = getActiveRange();
2441
- const selectionHeight = activeRange ? activeRange.endRow - activeRange.startRow + 1 : 0;
2442
- const selectionWidth = activeRange ? activeRange.endCol - activeRange.startCol + 1 : 0;
2443
- const selectionIsMultiCell = selectionHeight > 1 || selectionWidth > 1;
2444
- const matrixFitsSelection = selectionIsMultiCell &&
2445
- matrixRowCount <= selectionHeight &&
2446
- matrixColBaseline <= selectionWidth;
2447
- const selectionForPaste = matrixFitsSelection ? activeRange : null;
2448
- const basePoint = baseOverride
2449
- ? baseOverride
2450
- : selectionForPaste
2451
- ? selectionForPaste.anchor
2452
- : anchorCell.value ?? selectedCell.value ?? activeRange?.anchor ?? null;
2453
- const batchEvents = [];
2454
- const historyEntries = [];
2455
- const result = applyMatrixToGrid({
2456
- matrix,
2457
- selection: selectionForPaste,
2458
- basePoint,
2459
- context: getSelectionContext(),
2460
- writer: (rowIndex, colIndex, value) => setCellValueFromPaste(rowIndex, colIndex, value, {
2461
- collector: batchEvents,
2462
- historyCollector: historyEntries,
2463
- }),
2464
- });
2465
- if (!result) {
2466
- return;
2467
- }
2468
- if (result.nextSelection) {
2469
- applySelectionUpdate([result.nextSelection], 0);
2470
- }
2471
- dispatchEvents(batchEvents);
2472
- if (historyEntries.length) {
2473
- recordHistory(historyEntries);
2474
- }
2475
- if (result.changed) {
2476
- refreshViewport?.(true);
2477
- if (!result.nextSelection) {
2478
- scheduleOverlayUpdate();
2479
- }
2480
- }
2481
- focusContainer();
2482
- }
2483
- function clearSelectionValues() {
2484
- if (!hasGridData())
2485
- return false;
2486
- if (isFullRowMode.value)
2487
- return false;
2488
- const rowRange = fullRowSelection.value;
2489
- if (rowRange) {
2490
- const { rowCount } = getGridDimensions();
2491
- const startRow = clamp(rowRange.start, 0, rowCount - 1);
2492
- const endRow = clamp(rowRange.end, 0, rowCount - 1);
2493
- const rows = [];
2494
- for (let row = startRow; row <= endRow; row += 1) {
2495
- rows.push(row);
2496
- }
2497
- if (rows.length && deleteRows) {
2498
- const payload = rows.map(displayIndex => {
2499
- const entry = processedRows.value[displayIndex];
2500
- return {
2501
- displayIndex,
2502
- originalIndex: entry?.originalIndex ?? displayIndex,
2503
- row: entry?.row,
2504
- };
2505
- });
2506
- deleteRows(payload);
2507
- clearSelection();
2508
- focusContainer();
2509
- scheduleOverlayUpdate();
2510
- clearCutPreview();
2511
- return true;
2512
- }
2513
- }
2514
- const batchEvents = [];
2515
- const historyEntries = [];
2516
- let cleared = false;
2517
- iterSelectionCells((rowIndex, colIndex, column) => {
2518
- if (!column)
2519
- return;
2520
- if (!canPasteIntoColumn(column))
2521
- return;
2522
- if (setCellValueDirect(rowIndex, colIndex, null, {
2523
- collector: batchEvents,
2524
- historyCollector: historyEntries,
2525
- })) {
2526
- cleared = true;
2527
- }
2528
- });
2529
- dispatchEvents(batchEvents);
2530
- if (historyEntries.length) {
2531
- recordHistory(historyEntries);
2532
- }
2533
- if (cleared) {
2534
- focusContainer();
2535
- scheduleOverlayUpdate();
2536
- }
2537
- return cleared;
2538
- }
2539
- function handleDocumentMouseDown(event) {
2540
- const container = containerRef.value;
2541
- if (!container)
2542
- return;
2543
- const target = event.target;
2544
- if (!target)
2545
- return;
2546
- if (container.contains(target))
2547
- return;
2548
- if (target.closest(".ignore-selection"))
2549
- return;
2550
- clearFullRowSelection(true);
2551
- clearFullColumnSelection();
2552
- clearCellSelection();
2553
- }
2554
- function ensureSelectionBounds() {
2555
- if (!hasGridData()) {
2556
- clearCellSelection();
2557
- isEditingCell.value = false;
2558
- fullRowSelection.value = null;
2559
- clearColumnSelectionState();
2560
- isDraggingSelection.value = false;
2561
- selectionDragSession.value = null;
2562
- return;
2563
- }
2564
- const { rowCount, colCount } = getGridDimensions();
2565
- const clampedCutPreview = clampCutPreviewState(cutPreviewState.value, getSelectionContext());
2566
- if (!clampedCutPreview) {
2567
- if (cutPreviewState.value) {
2568
- cutPreviewState.value = null;
2569
- pendingCutState.value = null;
2570
- scheduleOverlayUpdate();
2571
- }
2572
- }
2573
- else if (!areCutPreviewStatesEqual(clampedCutPreview, cutPreviewState.value)) {
2574
- cutPreviewState.value = clampedCutPreview;
2575
- scheduleOverlayUpdate();
2576
- }
2577
- if (fullRowSelection.value) {
2578
- const nextStart = clamp(fullRowSelection.value.start, 0, Math.max(rowCount - 1, 0));
2579
- const nextEnd = clamp(fullRowSelection.value.end, 0, Math.max(rowCount - 1, 0));
2580
- if (nextStart > nextEnd) {
2581
- clearFullRowSelection(true);
2582
- clearCellSelection();
2583
- }
2584
- else if (nextStart !== fullRowSelection.value.start || nextEnd !== fullRowSelection.value.end) {
2585
- setFullRowSelectionRange(nextStart, nextEnd, { focus: false, preserveAnchor: true });
2586
- }
2587
- else if (rowSelectionAnchor.value != null) {
2588
- rowSelectionAnchor.value = clamp(rowSelectionAnchor.value, nextStart, nextEnd);
2589
- }
2590
- }
2591
- const detectedColumnSelection = detectFullColumnSelectionIndex(selectionRanges.value, { rowCount, colCount });
2592
- if (detectedColumnSelection !== null) {
2593
- if (!columnSelectionState.value || columnSelectionState.value.column !== detectedColumnSelection) {
2594
- const anchorRow = selectionRanges.value[0]?.anchor.rowIndex ?? null;
2595
- setColumnSelectionState(detectedColumnSelection, anchorRow);
2596
- }
2597
- }
2598
- else if (!columnSelectionState.value) {
2599
- clearColumnSelectionState();
2600
- }
2601
- const columnState = columnSelectionState.value;
2602
- if (columnState) {
2603
- const normalizedColumn = clamp(columnState.column, 0, Math.max(colCount - 1, 0));
2604
- const normalizedAnchorRow = columnState.anchorRow != null
2605
- ? clamp(columnState.anchorRow, 0, Math.max(rowCount - 1, 0))
2606
- : columnState.anchorRow;
2607
- if (normalizedColumn !== columnState.column || normalizedAnchorRow !== columnState.anchorRow) {
2608
- columnSelectionState.value = {
2609
- column: normalizedColumn,
2610
- anchorRow: normalizedAnchorRow,
2611
- };
2612
- }
2613
- if (rowCount > 0 && colCount > 0 && detectedColumnSelection !== normalizedColumn) {
2614
- setFullColumnSelection(normalizedColumn, {
2615
- focus: false,
2616
- anchorRow: normalizedAnchorRow ?? 0,
2617
- retainCursor: Boolean(selectedCell.value),
2618
- });
2619
- }
2620
- }
2621
- if (selectionRanges.value.length) {
2622
- applySelectionUpdate(selectionRanges.value, activeRangeIndex.value);
2623
- }
2624
- else {
2625
- const current = anchorCell.value ?? selectedCell.value;
2626
- if (current) {
2627
- setSingleCellSelection(clampPointToGrid(current));
2628
- }
2629
- }
2630
- reapplySelectionState();
2631
- if (selectionDragSession.value) {
2632
- selectionDragSession.value.anchor = clampPointToGrid(selectionDragSession.value.anchor);
2633
- }
2634
- }
2635
- function moveSelection(rowDelta, colDelta, options = {}) {
2636
- debugSelectionLog("moveSelection called", {
2637
- rowDelta,
2638
- colDelta,
2639
- options,
2640
- mode: rowSelectionMode.value,
2641
- hasCursor: Boolean(getSelectionCursor()),
2642
- });
2643
- if (isFullRowMode.value) {
2644
- if (!hasGridData())
2645
- return;
2646
- const { rowCount } = getGridDimensions();
2647
- const current = anchorCell.value ?? selectedCell.value;
2648
- const fallbackRow = current ? current.rowIndex : 0;
2649
- const targetRow = clamp(fallbackRow + rowDelta, 0, Math.max(rowCount - 1, 0));
2650
- const anchorRow = options.extend
2651
- ? clamp(resolveRowAnchor(fallbackRow), 0, Math.max(rowCount - 1, 0))
2652
- : targetRow;
2653
- clearFullColumnSelection();
2654
- setFullRowSelectionRange(anchorRow, targetRow, {
2655
- focus: true,
2656
- preserveAnchor: options.extend,
2657
- anchorRow,
2658
- });
2659
- nextTick(() => scrollSelectionIntoView());
2660
- return;
2661
- }
2662
- clearFullRowSelection();
2663
- clearFullColumnSelection();
2664
- if (!hasGridData())
2665
- return;
2666
- const current = getSelectionCursor();
2667
- if (!current) {
2668
- selectCell(0, localColumns.value[0].key, true, { colIndex: 0 });
2669
- return;
2670
- }
2671
- const rowCount = totalRowCount.value;
2672
- const colCount = localColumns.value.length;
2673
- const newRow = clamp(current.rowIndex + rowDelta, 0, rowCount - 1);
2674
- const newCol = clamp(current.colIndex + colDelta, 0, colCount - 1);
2675
- const point = createSelectionPointByIndex(newRow, newCol);
2676
- debugSelectionLog("moveSelection targeting", { point, extend: options.extend });
2677
- if (options.extend) {
2678
- extendActiveRangeTo(point);
2679
- }
2680
- else {
2681
- setSingleCellSelection(point);
2682
- }
2683
- focusContainer();
2684
- nextTick(() => scrollSelectionIntoView());
2685
- }
2686
- function performSelectionMove(source, target) {
2687
- const { rowCount, colCount } = getGridDimensions();
2688
- if (rowCount <= 0 || colCount <= 0)
2689
- return false;
2690
- const sourceHeight = source.endRow - source.startRow + 1;
2691
- const sourceWidth = source.endCol - source.startCol + 1;
2692
- if (sourceHeight <= 0 || sourceWidth <= 0)
2693
- return false;
2694
- const targetHeight = target.endRow - target.startRow + 1;
2695
- const targetWidth = target.endCol - target.startCol + 1;
2696
- if (targetHeight !== sourceHeight || targetWidth !== sourceWidth)
2697
- return false;
2698
- const columns = [];
2699
- for (let offset = 0; offset < sourceWidth; offset += 1) {
2700
- const column = localColumns.value[source.startCol + offset];
2701
- if (!column || !canPasteIntoColumn(column)) {
2702
- return false;
2703
- }
2704
- columns.push(column);
2705
- }
2706
- const events = [];
2707
- const historyEntries = [];
2708
- const moveResult = moveSelectionArea({
2709
- source,
2710
- target,
2711
- context: getSelectionContext(),
2712
- handlers: {
2713
- read: (rowIndex, colIndex) => getCellRawValue(rowIndex, colIndex),
2714
- clear: (rowIndex, colIndex) => setCellValueDirect(rowIndex, colIndex, null, {
2715
- collector: events,
2716
- historyCollector: historyEntries,
2717
- }),
2718
- write: (rowIndex, colIndex, value) => setCellValueDirect(rowIndex, colIndex, value, {
2719
- collector: events,
2720
- historyCollector: historyEntries,
2721
- }),
2722
- },
2723
- });
2724
- if (!moveResult || !moveResult.changed) {
2725
- return false;
2726
- }
2727
- dispatchEvents(events);
2728
- if (historyEntries.length) {
2729
- recordHistory(historyEntries);
2730
- }
2731
- const nextRange = {
2732
- startRow: moveResult.appliedArea.startRow,
2733
- endRow: moveResult.appliedArea.endRow,
2734
- startCol: moveResult.appliedArea.startCol,
2735
- endCol: moveResult.appliedArea.endCol,
2736
- anchor: createSelectionPointByIndex(moveResult.appliedArea.startRow, moveResult.appliedArea.startCol),
2737
- focus: createSelectionPointByIndex(moveResult.appliedArea.endRow, moveResult.appliedArea.endCol),
2738
- };
2739
- setSelection(nextRange, { focus: true });
2740
- focusContainer();
2741
- scheduleOverlayUpdate();
2742
- refreshViewport?.(true);
2743
- return true;
2744
- }
2745
- function canMoveActiveSelection() {
2746
- if (isFullRowMode.value)
2747
- return false;
2748
- if (isEditingCell.value)
2749
- return false;
2750
- if (fullRowSelection.value)
2751
- return false;
2752
- if (fullColumnSelection.value !== null)
2753
- return false;
2754
- if (selectionRanges.value.length !== 1)
2755
- return false;
2756
- return getActiveSelectionArea() != null;
2757
- }
2758
- function moveActiveSelectionTo(rowStart, colStart) {
2759
- const source = getActiveSelectionArea();
2760
- if (!source)
2761
- return false;
2762
- if (!canMoveActiveSelection())
2763
- return false;
2764
- const { rowCount, colCount } = getGridDimensions();
2765
- if (rowCount <= 0 || colCount <= 0)
2766
- return false;
2767
- const height = source.endRow - source.startRow + 1;
2768
- const width = source.endCol - source.startCol + 1;
2769
- const maxRowStart = Math.max(0, rowCount - height);
2770
- const maxColStart = Math.max(0, colCount - width);
2771
- const nextRowStart = clamp(rowStart, 0, maxRowStart);
2772
- const nextColStart = clamp(colStart, 0, maxColStart);
2773
- if (nextRowStart === source.startRow && nextColStart === source.startCol) {
2774
- return false;
2775
- }
2776
- const target = {
2777
- startRow: nextRowStart,
2778
- endRow: nextRowStart + height - 1,
2779
- startCol: nextColStart,
2780
- endCol: nextColStart + width - 1,
2781
- };
2782
- return performSelectionMove(source, target);
2783
- }
2784
- function moveByTab(forward) {
2785
- if (isFullRowMode.value) {
2786
- if (!hasGridData())
2787
- return false;
2788
- const { rowCount } = getGridDimensions();
2789
- const current = anchorCell.value ?? selectedCell.value;
2790
- const baseRow = current ? current.rowIndex : 0;
2791
- const delta = forward ? 1 : -1;
2792
- const targetRow = clamp(baseRow + delta, 0, Math.max(rowCount - 1, 0));
2793
- if (targetRow === baseRow) {
2794
- return false;
2795
- }
2796
- clearFullColumnSelection();
2797
- setFullRowSelectionRange(targetRow, targetRow, { focus: true, anchorRow: targetRow });
2798
- nextTick(() => scrollSelectionIntoView());
2799
- return true;
2800
- }
2801
- clearFullRowSelection();
2802
- clearFullColumnSelection();
2803
- if (!hasGridData())
2804
- return false;
2805
- const current = getSelectionCursor();
2806
- if (!current) {
2807
- selectCell(0, localColumns.value[0].key, true, { colIndex: 0 });
2808
- return true;
2809
- }
2810
- const rowCount = totalRowCount.value;
2811
- const colCount = localColumns.value.length;
2812
- let { rowIndex, colIndex } = current;
2813
- if (forward) {
2814
- if (rowIndex === rowCount - 1 && colIndex === colCount - 1) {
2815
- return false;
2816
- }
2817
- colIndex += 1;
2818
- if (colIndex >= colCount) {
2819
- colIndex = 0;
2820
- rowIndex = clamp(rowIndex + 1, 0, rowCount - 1);
2821
- }
2822
- }
2823
- else {
2824
- if (rowIndex === 0 && colIndex === 0) {
2825
- return false;
2826
- }
2827
- colIndex -= 1;
2828
- if (colIndex < 0) {
2829
- colIndex = colCount - 1;
2830
- rowIndex = clamp(rowIndex - 1, 0, rowCount - 1);
2831
- }
2832
- }
2833
- setSingleCellSelection({ rowIndex, colIndex });
2834
- focusContainer();
2835
- nextTick(() => scrollSelectionIntoView());
2836
- return true;
2837
- }
2838
- function triggerEditForSelection() {
2839
- if (isFullRowMode.value)
2840
- return null;
2841
- const active = getSelectionCursor();
2842
- if (!active)
2843
- return null;
2844
- const column = localColumns.value[active.colIndex];
2845
- if (!column)
2846
- return null;
2847
- if (!canPasteIntoColumn(column))
2848
- return null;
2849
- return {
2850
- rowIndex: active.rowIndex,
2851
- columnKey: column.key,
2852
- };
2853
- }
2854
- function refreshOverlayFromControllerState(options) {
2855
- if (options?.invalidateMetrics) {
2856
- invalidateSelectionMetrics();
2857
- }
2858
- const controllerState = selectionControllerAdapter.state.value;
2859
- const resources = resolveOverlayComputationInputs(controllerState);
2860
- updateCursorOverlayFromState(controllerState, resources);
2861
- if (options?.includeActive !== false) {
2862
- updateActiveRangeOverlayFromState(controllerState, resources, { commit: true });
2863
- }
2864
- updateFillPreviewOverlayFromState(controllerState, resources, { commit: true });
2865
- updateCutPreviewOverlayFromState(controllerState, resources, { commit: true });
2866
- if (options?.schedule !== false) {
2867
- scheduleOverlayUpdate({ priority: options?.priority });
2868
- }
2869
- }
2870
- watch(() => processedRows.value, () => {
2871
- if (!processedRows.value.length) {
2872
- clearCellSelection();
2873
- clearFullRowSelection(true);
2874
- clearFullColumnSelection();
2875
- return;
2876
- }
2877
- const remapped = remapSelectionState({
2878
- ranges: selectionRanges.value,
2879
- selected: selectedCell.value,
2880
- anchor: anchorCell.value,
2881
- dragAnchor: dragAnchorCell.value,
2882
- fillSession: fillSession.value,
2883
- }, {
2884
- context: getSelectionContext(),
2885
- findRowIndexById,
2886
- });
2887
- const resolved = setSelectionRangesHeadless({
2888
- ranges: remapped.ranges,
2889
- context: getSelectionContext(),
2890
- activeRangeIndex: activeRangeIndex.value,
2891
- selectedPoint: remapped.selected ?? undefined,
2892
- anchorPoint: remapped.anchor ?? undefined,
2893
- dragAnchorPoint: remapped.dragAnchor ?? undefined,
2894
- });
2895
- commitSelectionResult(resolved);
2896
- setFillSession(remapped.fillSession ?? null);
2897
- if (!resolved.selectedPoint && !resolved.anchorPoint && resolved.ranges.length === 0) {
2898
- clearCellSelection();
2899
- return;
2900
- }
2901
- });
2902
- watch(() => viewportWidthRef.value, () => {
2903
- refreshOverlayFromControllerState({
2904
- invalidateMetrics: true,
2905
- priority: "background",
2906
- });
2907
- });
2908
- watch(() => viewportHeightRef.value, () => {
2909
- refreshOverlayFromControllerState({
2910
- invalidateMetrics: true,
2911
- priority: "background",
2912
- });
2913
- });
2914
- watch(() => effectiveRowHeightRef.value, () => {
2915
- refreshOverlayFromControllerState({ priority: "background" });
2916
- });
2917
- watch(() => [
2918
- viewport.scrollLeft.value,
2919
- viewport.scrollTop.value,
2920
- viewport.visibleStartCol.value,
2921
- viewport.visibleEndCol.value,
2922
- viewport.startIndex.value,
2923
- viewport.endIndex.value,
2924
- ], () => {
2925
- refreshOverlayFromControllerState({ includeActive: false });
2926
- }, { flush: "post" });
2927
- watch(() => containerRef.value, () => {
2928
- refreshOverlayFromControllerState({
2929
- invalidateMetrics: true,
2930
- priority: "background",
2931
- });
2932
- });
2933
- if (overlayContainerRef) {
2934
- watch(() => overlayContainerRef.value, () => {
2935
- refreshOverlayFromControllerState({
2936
- invalidateMetrics: true,
2937
- priority: "background",
2938
- });
2939
- });
2940
- }
2941
- watch([selectedCell, anchorCell], ([focus, anchor]) => {
2942
- refreshOverlayFromControllerState({ schedule: false });
2943
- const target = anchor ?? focus;
2944
- if (!target || isDraggingSelection.value || isFillDragging.value || isRowSelectionDragging.value)
2945
- return;
2946
- nextTick(() => scrollSelectionIntoView());
2947
- });
2948
- watch(() => isEditingCell.value, () => {
2949
- refreshOverlayFromControllerState();
2950
- });
2951
- watch(() => localColumns.value.length, () => ensureSelectionBounds());
2952
- watch(() => totalRowCount.value, () => ensureSelectionBounds());
2953
- watch(rowSelectionMode, mode => {
2954
- if (mode === "row") {
2955
- if (!hasGridData()) {
2956
- clearFullRowSelection(true);
2957
- clearCellSelection();
2958
- return;
2959
- }
2960
- const { rowCount } = getGridDimensions();
2961
- const targetRow = clamp((anchorCell.value ?? selectedCell.value)?.rowIndex ?? 0, 0, Math.max(rowCount - 1, 0));
2962
- clearFullColumnSelection();
2963
- setFullRowSelectionRange(targetRow, targetRow, { focus: false, anchorRow: targetRow });
2964
- }
2965
- else {
2966
- const current = anchorCell.value ?? selectedCell.value;
2967
- clearFullRowSelection(true);
2968
- if (!hasGridData()) {
2969
- clearCellSelection();
2970
- return;
2971
- }
2972
- const { rowCount, colCount } = getGridDimensions();
2973
- const nextRow = clamp(current?.rowIndex ?? 0, 0, Math.max(rowCount - 1, 0));
2974
- const nextCol = clamp(current?.colIndex ?? 0, 0, Math.max(colCount - 1, 0));
2975
- setSingleCellSelection({ rowIndex: nextRow, colIndex: nextCol });
2976
- }
2977
- scheduleOverlayUpdate();
2978
- }, { flush: "post" });
2979
- onBeforeUnmount(() => {
2980
- overlayUpdateScheduler.cancel();
2981
- if (fillHandleStyle.value) {
2982
- fillHandleStyle.value = null;
2983
- }
2984
- controllerStateScheduler.cancel();
2985
- controllerAutoscrollUnsubscribe();
2986
- disposeSelectionEnvironment();
2987
- cancelFillHandleMeasurement();
2988
- disposeStaticOverlayCache();
2989
- window.removeEventListener("mouseup", handleSelectionMouseUp);
2990
- window.removeEventListener("mousemove", onSelectionMouseMove);
2991
- window.removeEventListener("mousemove", onFillMouseMove);
2992
- window.removeEventListener("mouseup", onFillMouseUp);
2993
- window.removeEventListener("mousemove", onRowSelectionMouseMove);
2994
- window.removeEventListener("mouseup", handleRowSelectionMouseUp);
2995
- document.removeEventListener("mousedown", handleDocumentMouseDown);
2996
- if (selectionDragSession.value) {
2997
- endSelectionDragSession(selectionDragSession.value);
2998
- selectionDragSession.value = null;
2999
- }
3000
- selectionSharedState.dispose();
3001
- });
3002
- if (typeof document !== "undefined") {
3003
- document.addEventListener("mousedown", handleDocumentMouseDown);
3004
- }
3005
- return {
3006
- selectedCell,
3007
- anchorCell,
3008
- selectionRanges,
3009
- activeRangeIndex,
3010
- fullRowSelection,
3011
- fullColumnSelection,
3012
- isDraggingSelection,
3013
- isFillDragging,
3014
- fillPreviewRange,
3015
- cutPreviewRanges,
3016
- cutPreviewActiveIndex,
3017
- fillHandleStyle,
3018
- selectionOverlayRects,
3019
- activeSelectionOverlayRects,
3020
- selectionCursorOverlay,
3021
- fillPreviewOverlayRects,
3022
- cutPreviewOverlayRects,
3023
- overlayScrollState,
3024
- selectionOverlayAdapter: selectionOverlayAdapterHandle,
3025
- scheduleOverlayUpdate,
3026
- setSelection,
3027
- clearSelection,
3028
- focusCell,
3029
- getActiveCell,
3030
- getSelectionSnapshot,
3031
- getActiveRange,
3032
- getActiveSelectionArea,
3033
- selectCell,
3034
- iterSelectionCells,
3035
- getSelectedCells,
3036
- isCellSelected,
3037
- isSelectionCursorCell,
3038
- isSelectionAnchorCell,
3039
- isCellInSelectionRange: (rowIndex, colIndex) => findRangeIndexContainingPoint({ rowIndex, colIndex }) !== -1,
3040
- isCellInCutPreview,
3041
- isRowFullySelected,
3042
- isColumnFullySelected,
3043
- isRowInSelectionRect,
3044
- isColumnInSelectionRect,
3045
- isCellInFillPreview,
3046
- getSelectionEdges,
3047
- getFillPreviewEdges,
3048
- getCutPreviewEdges,
3049
- rowHeaderClass,
3050
- onCellSelect,
3051
- onRowIndexClick,
3052
- onColumnHeaderClick,
3053
- onCellDragStart,
3054
- onCellDragEnter,
3055
- handleSelectionMouseUp,
3056
- moveSelection,
3057
- canMoveActiveSelection,
3058
- moveActiveSelectionTo,
3059
- moveByTab,
3060
- moveByPage,
3061
- goToRowEdge,
3062
- goToColumnEdge,
3063
- goToGridEdge,
3064
- triggerEditForSelection,
3065
- clearSelectionValues,
3066
- beginCutPreview,
3067
- clearCutPreview,
3068
- commitPendingCut,
3069
- hasCutPreview,
3070
- applyMatrixToSelection,
3071
- buildSelectionMatrix,
3072
- buildSelectionSnapshot,
3073
- getBoundsForRange,
3074
- startFillDrag,
3075
- autoFillDownFromActiveRange,
3076
- handleAutoScrollFrame,
3077
- lastCommittedFillArea,
3078
- selectionEnvironment,
3079
- };
3080
- };