@affino/datagrid-orchestration 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +6 -0
  3. package/dist/src/createDataGridRuntime.d.ts +19 -0
  4. package/dist/src/createDataGridRuntime.d.ts.map +1 -0
  5. package/dist/src/createDataGridRuntime.js +33 -0
  6. package/dist/src/dataGridContextMenuContracts.d.ts +20 -0
  7. package/dist/src/dataGridContextMenuContracts.d.ts.map +1 -0
  8. package/dist/src/dataGridContextMenuContracts.js +1 -0
  9. package/dist/src/dataGridPointerContracts.d.ts +5 -0
  10. package/dist/src/dataGridPointerContracts.d.ts.map +1 -0
  11. package/dist/src/dataGridPointerContracts.js +1 -0
  12. package/dist/src/dataGridRangeMutationKernel.d.ts +27 -0
  13. package/dist/src/dataGridRangeMutationKernel.d.ts.map +1 -0
  14. package/dist/src/dataGridRangeMutationKernel.js +46 -0
  15. package/dist/src/dataGridWritableRef.d.ts +4 -0
  16. package/dist/src/dataGridWritableRef.d.ts.map +1 -0
  17. package/dist/src/dataGridWritableRef.js +1 -0
  18. package/dist/src/index.d.ts +77 -0
  19. package/dist/src/index.d.ts.map +1 -0
  20. package/dist/src/index.js +76 -0
  21. package/dist/src/selectionOverlayTransform.d.ts +16 -0
  22. package/dist/src/selectionOverlayTransform.d.ts.map +1 -0
  23. package/dist/src/selectionOverlayTransform.js +21 -0
  24. package/dist/src/useDataGridA11yCellIds.d.ts +16 -0
  25. package/dist/src/useDataGridA11yCellIds.d.ts.map +1 -0
  26. package/dist/src/useDataGridA11yCellIds.js +26 -0
  27. package/dist/src/useDataGridAxisAutoScrollDelta.d.ts +10 -0
  28. package/dist/src/useDataGridAxisAutoScrollDelta.d.ts.map +1 -0
  29. package/dist/src/useDataGridAxisAutoScrollDelta.js +20 -0
  30. package/dist/src/useDataGridCellCoordNormalizer.d.ts +26 -0
  31. package/dist/src/useDataGridCellCoordNormalizer.d.ts.map +1 -0
  32. package/dist/src/useDataGridCellCoordNormalizer.js +29 -0
  33. package/dist/src/useDataGridCellDatasetResolver.d.ts +16 -0
  34. package/dist/src/useDataGridCellDatasetResolver.d.ts.map +1 -0
  35. package/dist/src/useDataGridCellDatasetResolver.js +23 -0
  36. package/dist/src/useDataGridCellNavigation.d.ts +23 -0
  37. package/dist/src/useDataGridCellNavigation.d.ts.map +1 -0
  38. package/dist/src/useDataGridCellNavigation.js +111 -0
  39. package/dist/src/useDataGridCellPointerDownRouter.d.ts +42 -0
  40. package/dist/src/useDataGridCellPointerDownRouter.d.ts.map +1 -0
  41. package/dist/src/useDataGridCellPointerDownRouter.js +48 -0
  42. package/dist/src/useDataGridCellPointerHoverRouter.d.ts +24 -0
  43. package/dist/src/useDataGridCellPointerHoverRouter.d.ts.map +1 -0
  44. package/dist/src/useDataGridCellPointerHoverRouter.js +25 -0
  45. package/dist/src/useDataGridCellRangeHelpers.d.ts +30 -0
  46. package/dist/src/useDataGridCellRangeHelpers.d.ts.map +1 -0
  47. package/dist/src/useDataGridCellRangeHelpers.js +89 -0
  48. package/dist/src/useDataGridCellVisibilityScroller.d.ts +41 -0
  49. package/dist/src/useDataGridCellVisibilityScroller.d.ts.map +1 -0
  50. package/dist/src/useDataGridCellVisibilityScroller.js +43 -0
  51. package/dist/src/useDataGridCellVisualStatePredicates.d.ts +40 -0
  52. package/dist/src/useDataGridCellVisualStatePredicates.d.ts.map +1 -0
  53. package/dist/src/useDataGridCellVisualStatePredicates.js +126 -0
  54. package/dist/src/useDataGridClearSelectionLifecycle.d.ts +27 -0
  55. package/dist/src/useDataGridClearSelectionLifecycle.d.ts.map +1 -0
  56. package/dist/src/useDataGridClearSelectionLifecycle.js +21 -0
  57. package/dist/src/useDataGridClipboardBridge.d.ts +31 -0
  58. package/dist/src/useDataGridClipboardBridge.d.ts.map +1 -0
  59. package/dist/src/useDataGridClipboardBridge.js +138 -0
  60. package/dist/src/useDataGridClipboardMutations.d.ts +47 -0
  61. package/dist/src/useDataGridClipboardMutations.d.ts.map +1 -0
  62. package/dist/src/useDataGridClipboardMutations.js +216 -0
  63. package/dist/src/useDataGridClipboardValuePolicy.d.ts +5 -0
  64. package/dist/src/useDataGridClipboardValuePolicy.d.ts.map +1 -0
  65. package/dist/src/useDataGridClipboardValuePolicy.js +14 -0
  66. package/dist/src/useDataGridColumnFilterOrchestration.d.ts +64 -0
  67. package/dist/src/useDataGridColumnFilterOrchestration.d.ts.map +1 -0
  68. package/dist/src/useDataGridColumnFilterOrchestration.js +359 -0
  69. package/dist/src/useDataGridColumnLayoutOrchestration.d.ts +59 -0
  70. package/dist/src/useDataGridColumnLayoutOrchestration.d.ts.map +1 -0
  71. package/dist/src/useDataGridColumnLayoutOrchestration.js +151 -0
  72. package/dist/src/useDataGridColumnUiPolicy.d.ts +25 -0
  73. package/dist/src/useDataGridColumnUiPolicy.d.ts.map +1 -0
  74. package/dist/src/useDataGridColumnUiPolicy.js +55 -0
  75. package/dist/src/useDataGridContextMenu.d.ts +30 -0
  76. package/dist/src/useDataGridContextMenu.d.ts.map +1 -0
  77. package/dist/src/useDataGridContextMenu.js +147 -0
  78. package/dist/src/useDataGridContextMenuActionRouter.d.ts +19 -0
  79. package/dist/src/useDataGridContextMenuActionRouter.d.ts.map +1 -0
  80. package/dist/src/useDataGridContextMenuActionRouter.js +29 -0
  81. package/dist/src/useDataGridContextMenuAnchor.d.ts +33 -0
  82. package/dist/src/useDataGridContextMenuAnchor.d.ts.map +1 -0
  83. package/dist/src/useDataGridContextMenuAnchor.js +60 -0
  84. package/dist/src/useDataGridCopyRangeHelpers.d.ts +20 -0
  85. package/dist/src/useDataGridCopyRangeHelpers.d.ts.map +1 -0
  86. package/dist/src/useDataGridCopyRangeHelpers.js +28 -0
  87. package/dist/src/useDataGridDragPointerSelection.d.ts +22 -0
  88. package/dist/src/useDataGridDragPointerSelection.d.ts.map +1 -0
  89. package/dist/src/useDataGridDragPointerSelection.js +23 -0
  90. package/dist/src/useDataGridDragSelectionLifecycle.d.ts +18 -0
  91. package/dist/src/useDataGridDragSelectionLifecycle.d.ts.map +1 -0
  92. package/dist/src/useDataGridDragSelectionLifecycle.js +11 -0
  93. package/dist/src/useDataGridEditableValuePolicy.d.ts +32 -0
  94. package/dist/src/useDataGridEditableValuePolicy.d.ts.map +1 -0
  95. package/dist/src/useDataGridEditableValuePolicy.js +95 -0
  96. package/dist/src/useDataGridEnumTrigger.d.ts +17 -0
  97. package/dist/src/useDataGridEnumTrigger.d.ts.map +1 -0
  98. package/dist/src/useDataGridEnumTrigger.js +28 -0
  99. package/dist/src/useDataGridFillHandleStart.d.ts +30 -0
  100. package/dist/src/useDataGridFillHandleStart.d.ts.map +1 -0
  101. package/dist/src/useDataGridFillHandleStart.js +27 -0
  102. package/dist/src/useDataGridFillSelectionLifecycle.d.ts +24 -0
  103. package/dist/src/useDataGridFillSelectionLifecycle.d.ts.map +1 -0
  104. package/dist/src/useDataGridFillSelectionLifecycle.js +15 -0
  105. package/dist/src/useDataGridGlobalMouseDownContextMenuCloser.d.ts +10 -0
  106. package/dist/src/useDataGridGlobalMouseDownContextMenuCloser.d.ts.map +1 -0
  107. package/dist/src/useDataGridGlobalMouseDownContextMenuCloser.js +17 -0
  108. package/dist/src/useDataGridGlobalPointerLifecycle.d.ts +40 -0
  109. package/dist/src/useDataGridGlobalPointerLifecycle.d.ts.map +1 -0
  110. package/dist/src/useDataGridGlobalPointerLifecycle.js +153 -0
  111. package/dist/src/useDataGridGroupBadge.d.ts +13 -0
  112. package/dist/src/useDataGridGroupBadge.d.ts.map +1 -0
  113. package/dist/src/useDataGridGroupBadge.js +19 -0
  114. package/dist/src/useDataGridGroupMetaOrchestration.d.ts +18 -0
  115. package/dist/src/useDataGridGroupMetaOrchestration.d.ts.map +1 -0
  116. package/dist/src/useDataGridGroupMetaOrchestration.js +43 -0
  117. package/dist/src/useDataGridGroupValueLabelResolver.d.ts +10 -0
  118. package/dist/src/useDataGridGroupValueLabelResolver.d.ts.map +1 -0
  119. package/dist/src/useDataGridGroupValueLabelResolver.js +15 -0
  120. package/dist/src/useDataGridGroupingSortOrchestration.d.ts +13 -0
  121. package/dist/src/useDataGridGroupingSortOrchestration.d.ts.map +1 -0
  122. package/dist/src/useDataGridGroupingSortOrchestration.js +22 -0
  123. package/dist/src/useDataGridHeaderContextActions.d.ts +15 -0
  124. package/dist/src/useDataGridHeaderContextActions.d.ts.map +1 -0
  125. package/dist/src/useDataGridHeaderContextActions.js +41 -0
  126. package/dist/src/useDataGridHeaderInteractionRouter.d.ts +12 -0
  127. package/dist/src/useDataGridHeaderInteractionRouter.d.ts.map +1 -0
  128. package/dist/src/useDataGridHeaderInteractionRouter.js +35 -0
  129. package/dist/src/useDataGridHeaderLayerOrchestration.d.ts +13 -0
  130. package/dist/src/useDataGridHeaderLayerOrchestration.d.ts.map +1 -0
  131. package/dist/src/useDataGridHeaderLayerOrchestration.js +18 -0
  132. package/dist/src/useDataGridHeaderResizeOrchestration.d.ts +43 -0
  133. package/dist/src/useDataGridHeaderResizeOrchestration.d.ts.map +1 -0
  134. package/dist/src/useDataGridHeaderResizeOrchestration.js +180 -0
  135. package/dist/src/useDataGridHeaderSortOrchestration.d.ts +20 -0
  136. package/dist/src/useDataGridHeaderSortOrchestration.d.ts.map +1 -0
  137. package/dist/src/useDataGridHeaderSortOrchestration.js +86 -0
  138. package/dist/src/useDataGridHistoryActionRunner.d.ts +15 -0
  139. package/dist/src/useDataGridHistoryActionRunner.d.ts.map +1 -0
  140. package/dist/src/useDataGridHistoryActionRunner.js +35 -0
  141. package/dist/src/useDataGridInlineEditOrchestration.d.ts +46 -0
  142. package/dist/src/useDataGridInlineEditOrchestration.d.ts.map +1 -0
  143. package/dist/src/useDataGridInlineEditOrchestration.js +116 -0
  144. package/dist/src/useDataGridInlineEditorFocus.d.ts +9 -0
  145. package/dist/src/useDataGridInlineEditorFocus.d.ts.map +1 -0
  146. package/dist/src/useDataGridInlineEditorFocus.js +37 -0
  147. package/dist/src/useDataGridInlineEditorKeyRouter.d.ts +12 -0
  148. package/dist/src/useDataGridInlineEditorKeyRouter.d.ts.map +1 -0
  149. package/dist/src/useDataGridInlineEditorKeyRouter.js +31 -0
  150. package/dist/src/useDataGridInlineEditorSchema.d.ts +11 -0
  151. package/dist/src/useDataGridInlineEditorSchema.d.ts.map +1 -0
  152. package/dist/src/useDataGridInlineEditorSchema.js +26 -0
  153. package/dist/src/useDataGridInlineEditorTargetNavigation.d.ts +30 -0
  154. package/dist/src/useDataGridInlineEditorTargetNavigation.d.ts.map +1 -0
  155. package/dist/src/useDataGridInlineEditorTargetNavigation.js +66 -0
  156. package/dist/src/useDataGridIntentHistory.d.ts +25 -0
  157. package/dist/src/useDataGridIntentHistory.d.ts.map +1 -0
  158. package/dist/src/useDataGridIntentHistory.js +109 -0
  159. package/dist/src/useDataGridKeyboardCommandRouter.d.ts +18 -0
  160. package/dist/src/useDataGridKeyboardCommandRouter.d.ts.map +1 -0
  161. package/dist/src/useDataGridKeyboardCommandRouter.js +81 -0
  162. package/dist/src/useDataGridMoveMutationPolicy.d.ts +12 -0
  163. package/dist/src/useDataGridMoveMutationPolicy.d.ts.map +1 -0
  164. package/dist/src/useDataGridMoveMutationPolicy.js +81 -0
  165. package/dist/src/useDataGridMutationSnapshot.d.ts +46 -0
  166. package/dist/src/useDataGridMutationSnapshot.d.ts.map +1 -0
  167. package/dist/src/useDataGridMutationSnapshot.js +57 -0
  168. package/dist/src/useDataGridNavigationPrimitives.d.ts +42 -0
  169. package/dist/src/useDataGridNavigationPrimitives.d.ts.map +1 -0
  170. package/dist/src/useDataGridNavigationPrimitives.js +105 -0
  171. package/dist/src/useDataGridPointerAutoScroll.d.ts +32 -0
  172. package/dist/src/useDataGridPointerAutoScroll.d.ts.map +1 -0
  173. package/dist/src/useDataGridPointerAutoScroll.js +85 -0
  174. package/dist/src/useDataGridPointerCellCoordResolver.d.ts +45 -0
  175. package/dist/src/useDataGridPointerCellCoordResolver.d.ts.map +1 -0
  176. package/dist/src/useDataGridPointerCellCoordResolver.js +107 -0
  177. package/dist/src/useDataGridPointerModifierPolicy.d.ts +5 -0
  178. package/dist/src/useDataGridPointerModifierPolicy.d.ts.map +1 -0
  179. package/dist/src/useDataGridPointerModifierPolicy.js +8 -0
  180. package/dist/src/useDataGridPointerPreviewRouter.d.ts +37 -0
  181. package/dist/src/useDataGridPointerPreviewRouter.d.ts.map +1 -0
  182. package/dist/src/useDataGridPointerPreviewRouter.js +55 -0
  183. package/dist/src/useDataGridQuickFilterActions.d.ts +10 -0
  184. package/dist/src/useDataGridQuickFilterActions.d.ts.map +1 -0
  185. package/dist/src/useDataGridQuickFilterActions.js +12 -0
  186. package/dist/src/useDataGridRangeMoveLifecycle.d.ts +15 -0
  187. package/dist/src/useDataGridRangeMoveLifecycle.d.ts.map +1 -0
  188. package/dist/src/useDataGridRangeMoveLifecycle.js +21 -0
  189. package/dist/src/useDataGridRangeMoveStart.d.ts +34 -0
  190. package/dist/src/useDataGridRangeMoveStart.d.ts.map +1 -0
  191. package/dist/src/useDataGridRangeMoveStart.js +23 -0
  192. package/dist/src/useDataGridRangeMutationEngine.d.ts +44 -0
  193. package/dist/src/useDataGridRangeMutationEngine.d.ts.map +1 -0
  194. package/dist/src/useDataGridRangeMutationEngine.js +210 -0
  195. package/dist/src/useDataGridRowSelectionInputHandlers.d.ts +10 -0
  196. package/dist/src/useDataGridRowSelectionInputHandlers.d.ts.map +1 -0
  197. package/dist/src/useDataGridRowSelectionInputHandlers.js +12 -0
  198. package/dist/src/useDataGridRowSelectionOrchestration.d.ts +7 -0
  199. package/dist/src/useDataGridRowSelectionOrchestration.d.ts.map +1 -0
  200. package/dist/src/useDataGridRowSelectionOrchestration.js +60 -0
  201. package/dist/src/useDataGridRowsProjection.d.ts +21 -0
  202. package/dist/src/useDataGridRowsProjection.d.ts.map +1 -0
  203. package/dist/src/useDataGridRowsProjection.js +69 -0
  204. package/dist/src/useDataGridRuntimeService.d.ts +33 -0
  205. package/dist/src/useDataGridRuntimeService.d.ts.map +1 -0
  206. package/dist/src/useDataGridRuntimeService.js +209 -0
  207. package/dist/src/useDataGridSelectionComparators.d.ts +16 -0
  208. package/dist/src/useDataGridSelectionComparators.d.ts.map +1 -0
  209. package/dist/src/useDataGridSelectionComparators.js +21 -0
  210. package/dist/src/useDataGridSelectionMoveHandle.d.ts +38 -0
  211. package/dist/src/useDataGridSelectionMoveHandle.d.ts.map +1 -0
  212. package/dist/src/useDataGridSelectionMoveHandle.js +49 -0
  213. package/dist/src/useDataGridSelectionOverlayOrchestration.d.ts +60 -0
  214. package/dist/src/useDataGridSelectionOverlayOrchestration.d.ts.map +1 -0
  215. package/dist/src/useDataGridSelectionOverlayOrchestration.js +137 -0
  216. package/dist/src/useDataGridTabTargetResolver.d.ts +17 -0
  217. package/dist/src/useDataGridTabTargetResolver.d.ts.map +1 -0
  218. package/dist/src/useDataGridTabTargetResolver.js +30 -0
  219. package/dist/src/useDataGridViewportBlurHandler.d.ts +16 -0
  220. package/dist/src/useDataGridViewportBlurHandler.d.ts.map +1 -0
  221. package/dist/src/useDataGridViewportBlurHandler.js +62 -0
  222. package/dist/src/useDataGridViewportContextMenuRouter.d.ts +31 -0
  223. package/dist/src/useDataGridViewportContextMenuRouter.d.ts.map +1 -0
  224. package/dist/src/useDataGridViewportContextMenuRouter.js +78 -0
  225. package/dist/src/useDataGridViewportMeasureScheduler.d.ts +22 -0
  226. package/dist/src/useDataGridViewportMeasureScheduler.d.ts.map +1 -0
  227. package/dist/src/useDataGridViewportMeasureScheduler.js +65 -0
  228. package/dist/src/useDataGridViewportScrollLifecycle.d.ts +16 -0
  229. package/dist/src/useDataGridViewportScrollLifecycle.d.ts.map +1 -0
  230. package/dist/src/useDataGridViewportScrollLifecycle.js +28 -0
  231. package/dist/src/useDataGridVirtualRangeMetrics.d.ts +32 -0
  232. package/dist/src/useDataGridVirtualRangeMetrics.d.ts.map +1 -0
  233. package/dist/src/useDataGridVirtualRangeMetrics.js +26 -0
  234. package/dist/src/useDataGridVisibleRowsSyncScheduler.d.ts +21 -0
  235. package/dist/src/useDataGridVisibleRowsSyncScheduler.d.ts.map +1 -0
  236. package/dist/src/useDataGridVisibleRowsSyncScheduler.js +70 -0
  237. package/dist/tsconfig.public.tsbuildinfo +1 -0
  238. package/dist/tsconfig.tsbuildinfo +1 -0
  239. package/package.json +50 -0
@@ -0,0 +1,55 @@
1
+ export function useDataGridColumnUiPolicy(options) {
2
+ const selectColumnKey = options.selectColumnKey ?? "select";
3
+ const selectColumnMinWidth = options.selectColumnMinWidth ?? 48;
4
+ const selectColumnDefaultWidth = options.selectColumnDefaultWidth ?? 58;
5
+ const defaultColumnMinWidth = options.defaultColumnMinWidth ?? 110;
6
+ const defaultColumnWidth = options.defaultColumnWidth ?? 160;
7
+ function isGroupedByColumn(columnKey) {
8
+ const groupBy = options.resolveCurrentGroupBy();
9
+ return groupBy !== "none" && Boolean(groupBy) && columnKey === groupBy;
10
+ }
11
+ function isSortableColumn(columnKey) {
12
+ return columnKey !== selectColumnKey;
13
+ }
14
+ function isColumnResizable(columnKey) {
15
+ return columnKey !== selectColumnKey;
16
+ }
17
+ function resolveColumnFilterKind(columnKey) {
18
+ if (options.isEnumColumn(columnKey)) {
19
+ return "enum";
20
+ }
21
+ if (options.numericColumnKeys.has(columnKey)) {
22
+ return "number";
23
+ }
24
+ return "text";
25
+ }
26
+ function resolveEnumFilterOptions(columnKey) {
27
+ const editorOptions = options.resolveEnumEditorOptions(columnKey);
28
+ if (editorOptions && editorOptions.length) {
29
+ return [...editorOptions];
30
+ }
31
+ const values = new Set();
32
+ for (const row of options.resolveRows()) {
33
+ const value = options.resolveCellValue(row, columnKey);
34
+ if (value === null || typeof value === "undefined") {
35
+ continue;
36
+ }
37
+ values.add(String(value));
38
+ }
39
+ return [...values].sort((left, right) => left.localeCompare(right));
40
+ }
41
+ function resolveColumnWidth(column) {
42
+ if (column.key === selectColumnKey) {
43
+ return Math.max(selectColumnMinWidth, column.width ?? selectColumnDefaultWidth);
44
+ }
45
+ return Math.max(defaultColumnMinWidth, column.width ?? defaultColumnWidth);
46
+ }
47
+ return {
48
+ isGroupedByColumn,
49
+ isSortableColumn,
50
+ isColumnResizable,
51
+ resolveColumnFilterKind,
52
+ resolveEnumFilterOptions,
53
+ resolveColumnWidth,
54
+ };
55
+ }
@@ -0,0 +1,30 @@
1
+ import type { DataGridContextMenuAction, DataGridContextMenuState, OpenDataGridContextMenuInput } from "./dataGridContextMenuContracts";
2
+ export interface UseDataGridContextMenuOptions {
3
+ isColumnResizable?: (columnKey: string) => boolean;
4
+ onBeforeOpen?: () => void;
5
+ }
6
+ export interface DataGridContextMenuKeyboardIntentInput {
7
+ key: string;
8
+ activeIndex: number;
9
+ itemCount: number;
10
+ shiftKey?: boolean;
11
+ }
12
+ export interface DataGridContextMenuKeyboardIntentResult {
13
+ handled: boolean;
14
+ nextIndex: number;
15
+ shouldTrigger: boolean;
16
+ shouldClose: boolean;
17
+ }
18
+ export interface DataGridContextMenuSnapshot {
19
+ contextMenu: DataGridContextMenuState;
20
+ actions: readonly DataGridContextMenuAction[];
21
+ }
22
+ export interface UseDataGridContextMenuResult {
23
+ getSnapshot: () => DataGridContextMenuSnapshot;
24
+ subscribe: (listener: (snapshot: DataGridContextMenuSnapshot) => void) => () => void;
25
+ closeContextMenu: () => void;
26
+ openContextMenu: (clientX: number, clientY: number, context: OpenDataGridContextMenuInput) => void;
27
+ }
28
+ export declare function resolveDataGridContextMenuKeyboardIntent(input: DataGridContextMenuKeyboardIntentInput): DataGridContextMenuKeyboardIntentResult;
29
+ export declare function useDataGridContextMenu(options?: UseDataGridContextMenuOptions): UseDataGridContextMenuResult;
30
+ //# sourceMappingURL=useDataGridContextMenu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDataGridContextMenu.d.ts","sourceRoot":"","sources":["../../src/useDataGridContextMenu.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,wBAAwB,EACxB,4BAA4B,EAC7B,MAAM,gCAAgC,CAAA;AAEvC,MAAM,WAAW,6BAA6B;IAC5C,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAA;IAClD,YAAY,CAAC,EAAE,MAAM,IAAI,CAAA;CAC1B;AAED,MAAM,WAAW,sCAAsC;IACrD,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,uCAAuC;IACtD,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,OAAO,CAAA;IACtB,WAAW,EAAE,OAAO,CAAA;CACrB;AAED,MAAM,WAAW,2BAA2B;IAC1C,WAAW,EAAE,wBAAwB,CAAA;IACrC,OAAO,EAAE,SAAS,yBAAyB,EAAE,CAAA;CAC9C;AAED,MAAM,WAAW,4BAA4B;IAC3C,WAAW,EAAE,MAAM,2BAA2B,CAAA;IAC9C,SAAS,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,2BAA2B,KAAK,IAAI,KAAK,MAAM,IAAI,CAAA;IACpF,gBAAgB,EAAE,MAAM,IAAI,CAAA;IAC5B,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,4BAA4B,KAAK,IAAI,CAAA;CACnG;AAuDD,wBAAgB,wCAAwC,CACtD,KAAK,EAAE,sCAAsC,GAC5C,uCAAuC,CA+CzC;AAED,wBAAgB,sBAAsB,CACpC,OAAO,GAAE,6BAAkC,GAC1C,4BAA4B,CA6D9B"}
@@ -0,0 +1,147 @@
1
+ const DEFAULT_CONTEXT_MENU_STATE = {
2
+ visible: false,
3
+ x: 0,
4
+ y: 0,
5
+ zone: "cell",
6
+ columnKey: null,
7
+ rowId: null,
8
+ };
9
+ function createDefaultState() {
10
+ return { ...DEFAULT_CONTEXT_MENU_STATE };
11
+ }
12
+ function clamp(value, min, max) {
13
+ if (!Number.isFinite(value)) {
14
+ return min;
15
+ }
16
+ if (max <= min) {
17
+ return min;
18
+ }
19
+ return Math.max(min, Math.min(max, value));
20
+ }
21
+ function resolveContextMenuActions(contextMenu, isColumnResizable) {
22
+ if (!contextMenu.visible) {
23
+ return [];
24
+ }
25
+ if (contextMenu.zone === "header") {
26
+ const actions = [
27
+ { id: "sort-asc", label: "Sort ascending" },
28
+ { id: "sort-desc", label: "Sort descending" },
29
+ { id: "sort-clear", label: "Clear sort" },
30
+ { id: "filter", label: "Filter column" },
31
+ ];
32
+ const canResize = typeof contextMenu.columnKey === "string" &&
33
+ contextMenu.columnKey.length > 0 &&
34
+ (isColumnResizable?.(contextMenu.columnKey) ?? false);
35
+ if (canResize) {
36
+ actions.push({ id: "auto-size", label: "Auto size column" });
37
+ }
38
+ return actions;
39
+ }
40
+ return [
41
+ { id: "cut", label: "Cut" },
42
+ { id: "paste", label: "Paste" },
43
+ { id: "copy", label: "Copy" },
44
+ { id: "clear", label: "Clear values" },
45
+ ];
46
+ }
47
+ export function resolveDataGridContextMenuKeyboardIntent(input) {
48
+ const count = input.itemCount;
49
+ if (count <= 0) {
50
+ return { handled: false, nextIndex: -1, shouldTrigger: false, shouldClose: false };
51
+ }
52
+ const normalizedIndex = input.activeIndex >= 0 ? input.activeIndex : 0;
53
+ if (input.key === "ArrowDown") {
54
+ return {
55
+ handled: true,
56
+ nextIndex: (normalizedIndex + 1) % count,
57
+ shouldTrigger: false,
58
+ shouldClose: false,
59
+ };
60
+ }
61
+ if (input.key === "ArrowUp") {
62
+ return {
63
+ handled: true,
64
+ nextIndex: (normalizedIndex - 1 + count) % count,
65
+ shouldTrigger: false,
66
+ shouldClose: false,
67
+ };
68
+ }
69
+ if (input.key === "Home") {
70
+ return { handled: true, nextIndex: 0, shouldTrigger: false, shouldClose: false };
71
+ }
72
+ if (input.key === "End") {
73
+ return { handled: true, nextIndex: count - 1, shouldTrigger: false, shouldClose: false };
74
+ }
75
+ if (input.key === "Enter" || input.key === " ") {
76
+ return { handled: true, nextIndex: normalizedIndex, shouldTrigger: true, shouldClose: false };
77
+ }
78
+ if (input.key === "Escape") {
79
+ return { handled: true, nextIndex: normalizedIndex, shouldTrigger: false, shouldClose: true };
80
+ }
81
+ if (input.key === "Tab") {
82
+ return {
83
+ handled: true,
84
+ nextIndex: input.shiftKey
85
+ ? (normalizedIndex <= 0 ? count - 1 : normalizedIndex - 1)
86
+ : (normalizedIndex + 1) % count,
87
+ shouldTrigger: false,
88
+ shouldClose: false,
89
+ };
90
+ }
91
+ return { handled: false, nextIndex: normalizedIndex, shouldTrigger: false, shouldClose: false };
92
+ }
93
+ export function useDataGridContextMenu(options = {}) {
94
+ let contextMenu = createDefaultState();
95
+ const listeners = new Set();
96
+ function createSnapshot() {
97
+ return {
98
+ contextMenu,
99
+ actions: resolveContextMenuActions(contextMenu, options.isColumnResizable),
100
+ };
101
+ }
102
+ function emit() {
103
+ const snapshot = createSnapshot();
104
+ listeners.forEach(listener => listener(snapshot));
105
+ }
106
+ function subscribe(listener) {
107
+ listeners.add(listener);
108
+ listener(createSnapshot());
109
+ return () => {
110
+ listeners.delete(listener);
111
+ };
112
+ }
113
+ function closeContextMenu() {
114
+ contextMenu = createDefaultState();
115
+ emit();
116
+ }
117
+ function openContextMenu(clientX, clientY, context) {
118
+ options.onBeforeOpen?.();
119
+ const baseState = {
120
+ visible: true,
121
+ x: 0,
122
+ y: 0,
123
+ zone: context.zone,
124
+ columnKey: context.columnKey ?? null,
125
+ rowId: context.rowId ?? null,
126
+ };
127
+ const actionCount = resolveContextMenuActions(baseState, options.isColumnResizable).length;
128
+ const estimatedMenuWidth = 240;
129
+ const estimatedMenuHeight = Math.max(56, actionCount * 36 + 12);
130
+ const viewportWidth = typeof window !== "undefined" ? window.innerWidth : clientX + estimatedMenuWidth + 16;
131
+ const viewportHeight = typeof window !== "undefined" ? window.innerHeight : clientY + estimatedMenuHeight + 16;
132
+ const maxX = Math.max(8, viewportWidth - estimatedMenuWidth - 8);
133
+ const maxY = Math.max(8, viewportHeight - estimatedMenuHeight - 8);
134
+ contextMenu = {
135
+ ...baseState,
136
+ x: clamp(clientX, 8, maxX),
137
+ y: clamp(clientY, 8, maxY),
138
+ };
139
+ emit();
140
+ }
141
+ return {
142
+ getSnapshot: createSnapshot,
143
+ subscribe,
144
+ closeContextMenu,
145
+ openContextMenu,
146
+ };
147
+ }
@@ -0,0 +1,19 @@
1
+ import type { DataGridContextMenuActionId, DataGridContextMenuZone } from "./dataGridContextMenuContracts";
2
+ export interface DataGridContextMenuActionRouterState {
3
+ zone: DataGridContextMenuZone;
4
+ columnKey: string | null;
5
+ }
6
+ export interface UseDataGridContextMenuActionRouterOptions {
7
+ resolveContextMenuState: () => DataGridContextMenuActionRouterState;
8
+ runHeaderContextAction: (action: DataGridContextMenuActionId, columnKey: string) => boolean;
9
+ copySelection: (trigger: "context-menu") => Promise<boolean>;
10
+ pasteSelection: (trigger: "context-menu") => Promise<boolean>;
11
+ cutSelection: (trigger: "context-menu") => Promise<boolean>;
12
+ clearCurrentSelection: (trigger: "context-menu") => Promise<boolean>;
13
+ closeContextMenu: () => void;
14
+ }
15
+ export interface UseDataGridContextMenuActionRouterResult {
16
+ runContextMenuAction: (action: DataGridContextMenuActionId) => Promise<boolean>;
17
+ }
18
+ export declare function useDataGridContextMenuActionRouter(options: UseDataGridContextMenuActionRouterOptions): UseDataGridContextMenuActionRouterResult;
19
+ //# sourceMappingURL=useDataGridContextMenuActionRouter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDataGridContextMenuActionRouter.d.ts","sourceRoot":"","sources":["../../src/useDataGridContextMenuActionRouter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,2BAA2B,EAC3B,uBAAuB,EACxB,MAAM,gCAAgC,CAAA;AAEvC,MAAM,WAAW,oCAAoC;IACnD,IAAI,EAAE,uBAAuB,CAAA;IAC7B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;CACzB;AAED,MAAM,WAAW,yCAAyC;IACxD,uBAAuB,EAAE,MAAM,oCAAoC,CAAA;IACnE,sBAAsB,EAAE,CAAC,MAAM,EAAE,2BAA2B,EAAE,SAAS,EAAE,MAAM,KAAK,OAAO,CAAA;IAC3F,aAAa,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5D,cAAc,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAC7D,YAAY,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAC3D,qBAAqB,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IACpE,gBAAgB,EAAE,MAAM,IAAI,CAAA;CAC7B;AAED,MAAM,WAAW,wCAAwC;IACvD,oBAAoB,EAAE,CAAC,MAAM,EAAE,2BAA2B,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAChF;AAED,wBAAgB,kCAAkC,CAChD,OAAO,EAAE,yCAAyC,GACjD,wCAAwC,CA+B1C"}
@@ -0,0 +1,29 @@
1
+ export function useDataGridContextMenuActionRouter(options) {
2
+ async function runContextMenuAction(action) {
3
+ const context = options.resolveContextMenuState();
4
+ if (context.zone === "header") {
5
+ if (!context.columnKey) {
6
+ options.closeContextMenu();
7
+ return false;
8
+ }
9
+ return options.runHeaderContextAction(action, context.columnKey);
10
+ }
11
+ if (action === "copy") {
12
+ return options.copySelection("context-menu");
13
+ }
14
+ if (action === "paste") {
15
+ return options.pasteSelection("context-menu");
16
+ }
17
+ if (action === "cut") {
18
+ return options.cutSelection("context-menu");
19
+ }
20
+ if (action === "clear") {
21
+ return options.clearCurrentSelection("context-menu");
22
+ }
23
+ options.closeContextMenu();
24
+ return false;
25
+ }
26
+ return {
27
+ runContextMenuAction,
28
+ };
29
+ }
@@ -0,0 +1,33 @@
1
+ import type { OpenDataGridContextMenuInput } from "./dataGridContextMenuContracts";
2
+ export interface DataGridContextMenuAnchorCellCoord {
3
+ rowIndex: number;
4
+ columnIndex: number;
5
+ }
6
+ export interface DataGridContextMenuAnchorRange {
7
+ startRow: number;
8
+ endRow: number;
9
+ startColumn: number;
10
+ endColumn: number;
11
+ }
12
+ export interface DataGridContextMenuAnchorRowIdentity {
13
+ rowId: string | number;
14
+ }
15
+ export interface DataGridContextMenuAnchorColumnIdentity {
16
+ key: string;
17
+ }
18
+ export interface UseDataGridContextMenuAnchorOptions<TRow extends DataGridContextMenuAnchorRowIdentity = DataGridContextMenuAnchorRowIdentity, TColumn extends DataGridContextMenuAnchorColumnIdentity = DataGridContextMenuAnchorColumnIdentity, TCoord extends DataGridContextMenuAnchorCellCoord = DataGridContextMenuAnchorCellCoord, TRange extends DataGridContextMenuAnchorRange = DataGridContextMenuAnchorRange> {
19
+ resolveCurrentCellCoord: () => TCoord | null;
20
+ resolveViewportElement: () => HTMLElement | null;
21
+ resolveRowAtIndex: (rowIndex: number) => TRow | undefined;
22
+ resolveColumnAtIndex: (columnIndex: number) => TColumn | undefined;
23
+ resolveSelectionRange: () => TRange | null;
24
+ isMultiCellSelection: (range: TRange) => boolean;
25
+ isCoordInsideRange: (coord: TCoord, range: TRange) => boolean;
26
+ openContextMenu: (clientX: number, clientY: number, context: OpenDataGridContextMenuInput) => void;
27
+ isColumnContextEnabled?: (column: TColumn) => boolean;
28
+ }
29
+ export interface UseDataGridContextMenuAnchorResult {
30
+ openContextMenuFromCurrentCell: () => boolean;
31
+ }
32
+ export declare function useDataGridContextMenuAnchor<TRow extends DataGridContextMenuAnchorRowIdentity = DataGridContextMenuAnchorRowIdentity, TColumn extends DataGridContextMenuAnchorColumnIdentity = DataGridContextMenuAnchorColumnIdentity, TCoord extends DataGridContextMenuAnchorCellCoord = DataGridContextMenuAnchorCellCoord, TRange extends DataGridContextMenuAnchorRange = DataGridContextMenuAnchorRange>(options: UseDataGridContextMenuAnchorOptions<TRow, TColumn, TCoord, TRange>): UseDataGridContextMenuAnchorResult;
33
+ //# sourceMappingURL=useDataGridContextMenuAnchor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDataGridContextMenuAnchor.d.ts","sourceRoot":"","sources":["../../src/useDataGridContextMenuAnchor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,4BAA4B,EAC7B,MAAM,gCAAgC,CAAA;AAEvC,MAAM,WAAW,kCAAkC;IACjD,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,oCAAoC;IACnD,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,uCAAuC;IACtD,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,WAAW,mCAAmC,CAClD,IAAI,SAAS,oCAAoC,GAAG,oCAAoC,EACxF,OAAO,SAAS,uCAAuC,GAAG,uCAAuC,EACjG,MAAM,SAAS,kCAAkC,GAAG,kCAAkC,EACtF,MAAM,SAAS,8BAA8B,GAAG,8BAA8B;IAE9E,uBAAuB,EAAE,MAAM,MAAM,GAAG,IAAI,CAAA;IAC5C,sBAAsB,EAAE,MAAM,WAAW,GAAG,IAAI,CAAA;IAChD,iBAAiB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,GAAG,SAAS,CAAA;IACzD,oBAAoB,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,GAAG,SAAS,CAAA;IAClE,qBAAqB,EAAE,MAAM,MAAM,GAAG,IAAI,CAAA;IAC1C,oBAAoB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;IAChD,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;IAC7D,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,4BAA4B,KAAK,IAAI,CAAA;IAClG,sBAAsB,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAA;CACtD;AAED,MAAM,WAAW,kCAAkC;IACjD,8BAA8B,EAAE,MAAM,OAAO,CAAA;CAC9C;AA6BD,wBAAgB,4BAA4B,CAC1C,IAAI,SAAS,oCAAoC,GAAG,oCAAoC,EACxF,OAAO,SAAS,uCAAuC,GAAG,uCAAuC,EACjG,MAAM,SAAS,kCAAkC,GAAG,kCAAkC,EACtF,MAAM,SAAS,8BAA8B,GAAG,8BAA8B,EAE9E,OAAO,EAAE,mCAAmC,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,GAC1E,kCAAkC,CAwCpC"}
@@ -0,0 +1,60 @@
1
+ function clamp(value, min, max) {
2
+ return Math.max(min, Math.min(max, value));
3
+ }
4
+ function escapeCssAttributeValue(value) {
5
+ if (typeof CSS !== "undefined" && typeof CSS.escape === "function") {
6
+ return CSS.escape(value);
7
+ }
8
+ return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
9
+ }
10
+ function resolveCellAnchorPoint(viewport, selector) {
11
+ const element = viewport.querySelector(selector);
12
+ if (element) {
13
+ const rect = element.getBoundingClientRect();
14
+ return {
15
+ x: rect.left + clamp(rect.width * 0.5, 10, Math.max(10, rect.width - 10)),
16
+ y: rect.bottom - 4,
17
+ };
18
+ }
19
+ const viewportRect = viewport.getBoundingClientRect();
20
+ return {
21
+ x: viewportRect.left + clamp(viewportRect.width * 0.3, 10, Math.max(10, viewportRect.width - 10)),
22
+ y: viewportRect.top + clamp(viewportRect.height * 0.4, 10, Math.max(10, viewportRect.height - 10)),
23
+ };
24
+ }
25
+ export function useDataGridContextMenuAnchor(options) {
26
+ function openContextMenuFromCurrentCell() {
27
+ const current = options.resolveCurrentCellCoord();
28
+ const viewport = options.resolveViewportElement();
29
+ if (!current || !viewport) {
30
+ return false;
31
+ }
32
+ const row = options.resolveRowAtIndex(current.rowIndex);
33
+ const column = options.resolveColumnAtIndex(current.columnIndex);
34
+ if (!row || !column) {
35
+ return false;
36
+ }
37
+ if (!(options.isColumnContextEnabled?.(column) ?? column.key !== "select")) {
38
+ return false;
39
+ }
40
+ const rowId = String(row.rowId);
41
+ const columnKey = column.key;
42
+ const selector = `.datagrid-stage__cell[data-row-id="${escapeCssAttributeValue(rowId)}"][data-column-key="${escapeCssAttributeValue(columnKey)}"]`;
43
+ const anchor = resolveCellAnchorPoint(viewport, selector);
44
+ const range = options.resolveSelectionRange();
45
+ const zone = range &&
46
+ options.isMultiCellSelection(range) &&
47
+ options.isCoordInsideRange(current, range)
48
+ ? "range"
49
+ : "cell";
50
+ options.openContextMenu(anchor.x, anchor.y, {
51
+ zone,
52
+ columnKey,
53
+ rowId,
54
+ });
55
+ return true;
56
+ }
57
+ return {
58
+ openContextMenuFromCurrentCell,
59
+ };
60
+ }
@@ -0,0 +1,20 @@
1
+ export interface DataGridCopyRangeCoord {
2
+ rowIndex: number;
3
+ columnIndex: number;
4
+ }
5
+ export interface DataGridCopyRange {
6
+ startRow: number;
7
+ endRow: number;
8
+ startColumn: number;
9
+ endColumn: number;
10
+ }
11
+ export interface UseDataGridCopyRangeHelpersOptions<TCoord extends DataGridCopyRangeCoord = DataGridCopyRangeCoord, TRange extends DataGridCopyRange = DataGridCopyRange> {
12
+ resolveSelectionRange: () => TRange | null;
13
+ resolveCurrentCellCoord: () => TCoord | null;
14
+ }
15
+ export interface UseDataGridCopyRangeHelpersResult<TRange extends DataGridCopyRange = DataGridCopyRange> {
16
+ isMultiCellSelection: (range: TRange | null) => boolean;
17
+ resolveCopyRange: () => TRange | null;
18
+ }
19
+ export declare function useDataGridCopyRangeHelpers<TCoord extends DataGridCopyRangeCoord = DataGridCopyRangeCoord, TRange extends DataGridCopyRange = DataGridCopyRange>(options: UseDataGridCopyRangeHelpersOptions<TCoord, TRange>): UseDataGridCopyRangeHelpersResult<TRange>;
20
+ //# sourceMappingURL=useDataGridCopyRangeHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDataGridCopyRangeHelpers.d.ts","sourceRoot":"","sources":["../../src/useDataGridCopyRangeHelpers.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,kCAAkC,CACjD,MAAM,SAAS,sBAAsB,GAAG,sBAAsB,EAC9D,MAAM,SAAS,iBAAiB,GAAG,iBAAiB;IAEpD,qBAAqB,EAAE,MAAM,MAAM,GAAG,IAAI,CAAA;IAC1C,uBAAuB,EAAE,MAAM,MAAM,GAAG,IAAI,CAAA;CAC7C;AAED,MAAM,WAAW,iCAAiC,CAChD,MAAM,SAAS,iBAAiB,GAAG,iBAAiB;IAEpD,oBAAoB,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAA;IACvD,gBAAgB,EAAE,MAAM,MAAM,GAAG,IAAI,CAAA;CACtC;AAED,wBAAgB,2BAA2B,CACzC,MAAM,SAAS,sBAAsB,GAAG,sBAAsB,EAC9D,MAAM,SAAS,iBAAiB,GAAG,iBAAiB,EAEpD,OAAO,EAAE,kCAAkC,CAAC,MAAM,EAAE,MAAM,CAAC,GAC1D,iCAAiC,CAAC,MAAM,CAAC,CA6B3C"}
@@ -0,0 +1,28 @@
1
+ export function useDataGridCopyRangeHelpers(options) {
2
+ function isMultiCellSelection(range) {
3
+ if (!range) {
4
+ return false;
5
+ }
6
+ return range.startRow !== range.endRow || range.startColumn !== range.endColumn;
7
+ }
8
+ function resolveCopyRange() {
9
+ const selected = options.resolveSelectionRange();
10
+ if (selected) {
11
+ return selected;
12
+ }
13
+ const current = options.resolveCurrentCellCoord();
14
+ if (!current) {
15
+ return null;
16
+ }
17
+ return {
18
+ startRow: current.rowIndex,
19
+ endRow: current.rowIndex,
20
+ startColumn: current.columnIndex,
21
+ endColumn: current.columnIndex,
22
+ };
23
+ }
24
+ return {
25
+ isMultiCellSelection,
26
+ resolveCopyRange,
27
+ };
28
+ }
@@ -0,0 +1,22 @@
1
+ export interface DataGridDragPointerSelectionCoord {
2
+ rowIndex: number;
3
+ columnIndex: number;
4
+ }
5
+ export interface DataGridDragPointerSelectionCoordinates {
6
+ clientX: number;
7
+ clientY: number;
8
+ }
9
+ export interface UseDataGridDragPointerSelectionOptions<TCoord extends DataGridDragPointerSelectionCoord> {
10
+ isDragSelecting: () => boolean;
11
+ resolveDragPointer: () => DataGridDragPointerSelectionCoordinates | null;
12
+ resolveCellCoordFromPointer: (clientX: number, clientY: number) => TCoord | null;
13
+ resolveLastDragCoord: () => TCoord | null;
14
+ setLastDragCoord: (coord: TCoord) => void;
15
+ cellCoordsEqual: (a: TCoord | null, b: TCoord | null) => boolean;
16
+ applyCellSelection: (coord: TCoord, extend: boolean, fallbackAnchor?: TCoord, ensureVisible?: boolean) => void;
17
+ }
18
+ export interface UseDataGridDragPointerSelectionResult {
19
+ applyDragSelectionFromPointer: () => void;
20
+ }
21
+ export declare function useDataGridDragPointerSelection<TCoord extends DataGridDragPointerSelectionCoord>(options: UseDataGridDragPointerSelectionOptions<TCoord>): UseDataGridDragPointerSelectionResult;
22
+ //# sourceMappingURL=useDataGridDragPointerSelection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDataGridDragPointerSelection.d.ts","sourceRoot":"","sources":["../../src/useDataGridDragPointerSelection.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iCAAiC;IAChD,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,uCAAuC;IACtD,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,sCAAsC,CAAC,MAAM,SAAS,iCAAiC;IACtG,eAAe,EAAE,MAAM,OAAO,CAAA;IAC9B,kBAAkB,EAAE,MAAM,uCAAuC,GAAG,IAAI,CAAA;IACxE,2BAA2B,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAA;IAChF,oBAAoB,EAAE,MAAM,MAAM,GAAG,IAAI,CAAA;IACzC,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACzC,eAAe,EAAE,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAA;IAChE,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;CAC/G;AAED,MAAM,WAAW,qCAAqC;IACpD,6BAA6B,EAAE,MAAM,IAAI,CAAA;CAC1C;AAED,wBAAgB,+BAA+B,CAAC,MAAM,SAAS,iCAAiC,EAC9F,OAAO,EAAE,sCAAsC,CAAC,MAAM,CAAC,GACtD,qCAAqC,CAuBvC"}
@@ -0,0 +1,23 @@
1
+ export function useDataGridDragPointerSelection(options) {
2
+ function applyDragSelectionFromPointer() {
3
+ if (!options.isDragSelecting()) {
4
+ return;
5
+ }
6
+ const pointer = options.resolveDragPointer();
7
+ if (!pointer) {
8
+ return;
9
+ }
10
+ const coord = options.resolveCellCoordFromPointer(pointer.clientX, pointer.clientY);
11
+ if (!coord) {
12
+ return;
13
+ }
14
+ if (options.cellCoordsEqual(options.resolveLastDragCoord(), coord)) {
15
+ return;
16
+ }
17
+ options.setLastDragCoord(coord);
18
+ options.applyCellSelection(coord, true, undefined, false);
19
+ }
20
+ return {
21
+ applyDragSelectionFromPointer,
22
+ };
23
+ }
@@ -0,0 +1,18 @@
1
+ export interface UseDataGridDragSelectionLifecycleOptions<TCoord = {
2
+ rowIndex: number;
3
+ columnIndex: number;
4
+ }> {
5
+ setDragSelecting: (value: boolean) => void;
6
+ clearDragPointer: () => void;
7
+ clearLastDragCoord: () => void;
8
+ stopAutoScrollFrameIfIdle: () => void;
9
+ resolveLastDragCoord?: () => TCoord | null;
10
+ }
11
+ export interface UseDataGridDragSelectionLifecycleResult {
12
+ stopDragSelection: () => void;
13
+ }
14
+ export declare function useDataGridDragSelectionLifecycle<TCoord = {
15
+ rowIndex: number;
16
+ columnIndex: number;
17
+ }>(options: UseDataGridDragSelectionLifecycleOptions<TCoord>): UseDataGridDragSelectionLifecycleResult;
18
+ //# sourceMappingURL=useDataGridDragSelectionLifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDataGridDragSelectionLifecycle.d.ts","sourceRoot":"","sources":["../../src/useDataGridDragSelectionLifecycle.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wCAAwC,CAAC,MAAM,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE;IAC1G,gBAAgB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IAC1C,gBAAgB,EAAE,MAAM,IAAI,CAAA;IAC5B,kBAAkB,EAAE,MAAM,IAAI,CAAA;IAC9B,yBAAyB,EAAE,MAAM,IAAI,CAAA;IACrC,oBAAoB,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAA;CAC3C;AAED,MAAM,WAAW,uCAAuC;IACtD,iBAAiB,EAAE,MAAM,IAAI,CAAA;CAC9B;AAED,wBAAgB,iCAAiC,CAAC,MAAM,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EAClG,OAAO,EAAE,wCAAwC,CAAC,MAAM,CAAC,GACxD,uCAAuC,CAWzC"}
@@ -0,0 +1,11 @@
1
+ export function useDataGridDragSelectionLifecycle(options) {
2
+ function stopDragSelection() {
3
+ options.setDragSelecting(false);
4
+ options.clearDragPointer();
5
+ options.clearLastDragCoord();
6
+ options.stopAutoScrollFrameIfIdle();
7
+ }
8
+ return {
9
+ stopDragSelection,
10
+ };
11
+ }
@@ -0,0 +1,32 @@
1
+ export type DataGridEditableValueStrategy<TRow> = {
2
+ kind: "text";
3
+ apply: (row: TRow, draft: string) => void;
4
+ canPaste?: (draft: string) => boolean;
5
+ clearable?: boolean;
6
+ clear?: (row: TRow) => boolean;
7
+ } | {
8
+ kind: "enum";
9
+ isAllowed: (draft: string) => boolean;
10
+ apply: (row: TRow, draft: string) => void;
11
+ clearable?: boolean;
12
+ clear?: (row: TRow) => boolean;
13
+ } | {
14
+ kind: "number";
15
+ parse?: (draft: string) => number | null;
16
+ apply: (row: TRow, numericValue: number) => void;
17
+ clearable?: boolean;
18
+ clear?: (row: TRow) => boolean;
19
+ };
20
+ export interface UseDataGridEditableValuePolicyOptions<TRow, TColumnKey extends string> {
21
+ strategies: Readonly<Record<TColumnKey, DataGridEditableValueStrategy<TRow>>>;
22
+ defaultClearable?: boolean;
23
+ }
24
+ export interface UseDataGridEditableValuePolicyResult<TRow, TColumnKey extends string> {
25
+ hasEditablePolicy: (columnKey: string) => columnKey is TColumnKey;
26
+ applyEditedValue: (row: TRow, columnKey: TColumnKey, draft: string) => void;
27
+ canApplyPastedValue: (columnKey: TColumnKey, draft: string) => boolean;
28
+ isColumnClearableForCut: (columnKey: TColumnKey) => boolean;
29
+ clearEditedValue: (row: TRow, columnKey: TColumnKey) => boolean;
30
+ }
31
+ export declare function useDataGridEditableValuePolicy<TRow, TColumnKey extends string>(options: UseDataGridEditableValuePolicyOptions<TRow, TColumnKey>): UseDataGridEditableValuePolicyResult<TRow, TColumnKey>;
32
+ //# sourceMappingURL=useDataGridEditableValuePolicy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDataGridEditableValuePolicy.d.ts","sourceRoot":"","sources":["../../src/useDataGridEditableValuePolicy.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,6BAA6B,CAAC,IAAI,IAC1C;IACE,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACzC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;IACrC,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,OAAO,CAAA;CAC/B,GACD;IACE,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;IACrC,KAAK,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACzC,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,OAAO,CAAA;CAC/B,GACD;IACE,IAAI,EAAE,QAAQ,CAAA;IACd,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAA;IACxC,KAAK,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,KAAK,IAAI,CAAA;IAChD,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,OAAO,CAAA;CAC/B,CAAA;AAEL,MAAM,WAAW,qCAAqC,CAAC,IAAI,EAAE,UAAU,SAAS,MAAM;IACpF,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,6BAA6B,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC7E,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED,MAAM,WAAW,oCAAoC,CAAC,IAAI,EAAE,UAAU,SAAS,MAAM;IACnF,iBAAiB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,SAAS,IAAI,UAAU,CAAA;IACjE,gBAAgB,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAC3E,mBAAmB,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;IACtE,uBAAuB,EAAE,CAAC,SAAS,EAAE,UAAU,KAAK,OAAO,CAAA;IAC3D,gBAAgB,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,KAAK,OAAO,CAAA;CAChE;AAOD,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,UAAU,SAAS,MAAM,EAC5E,OAAO,EAAE,qCAAqC,CAAC,IAAI,EAAE,UAAU,CAAC,GAC/D,oCAAoC,CAAC,IAAI,EAAE,UAAU,CAAC,CAiGxD"}