@uipath/apollo-react 7.11.3 → 7.12.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 (181) hide show
  1. package/dist/canvas/components/CanvasDiffView/CanvasDiffView.cjs +6 -6
  2. package/dist/canvas/components/CanvasDiffView/CanvasDiffView.js +6 -6
  3. package/dist/canvas/components/JsonTree/JsonTree.cjs +2 -2
  4. package/dist/canvas/components/JsonTree/JsonTree.js +2 -2
  5. package/dist/canvas/components/NodeVariablesPanel/NodeVariablesPanel.cjs +6 -6
  6. package/dist/canvas/components/NodeVariablesPanel/NodeVariablesPanel.js +6 -6
  7. package/dist/canvas/components/StageNode/tasks/TaskContent.cjs +1 -1
  8. package/dist/canvas/components/StageNode/tasks/TaskContent.js +1 -1
  9. package/dist/canvas/locales/de.cjs +1 -1
  10. package/dist/canvas/locales/de.d.ts.map +1 -1
  11. package/dist/canvas/locales/de.js +1 -1
  12. package/dist/canvas/locales/en.cjs +1 -1
  13. package/dist/canvas/locales/en.d.ts.map +1 -1
  14. package/dist/canvas/locales/en.js +1 -1
  15. package/dist/canvas/locales/es-MX.cjs +1 -1
  16. package/dist/canvas/locales/es-MX.d.ts.map +1 -1
  17. package/dist/canvas/locales/es-MX.js +1 -1
  18. package/dist/canvas/locales/es.cjs +1 -1
  19. package/dist/canvas/locales/es.d.ts.map +1 -1
  20. package/dist/canvas/locales/es.js +1 -1
  21. package/dist/canvas/locales/fr.cjs +1 -1
  22. package/dist/canvas/locales/fr.d.ts.map +1 -1
  23. package/dist/canvas/locales/fr.js +1 -1
  24. package/dist/canvas/locales/ja.cjs +1 -1
  25. package/dist/canvas/locales/ja.d.ts.map +1 -1
  26. package/dist/canvas/locales/ja.js +1 -1
  27. package/dist/canvas/locales/ko.cjs +1 -1
  28. package/dist/canvas/locales/ko.d.ts.map +1 -1
  29. package/dist/canvas/locales/ko.js +1 -1
  30. package/dist/canvas/locales/pt-BR.cjs +1 -1
  31. package/dist/canvas/locales/pt-BR.d.ts.map +1 -1
  32. package/dist/canvas/locales/pt-BR.js +1 -1
  33. package/dist/canvas/locales/pt.cjs +1 -1
  34. package/dist/canvas/locales/pt.d.ts.map +1 -1
  35. package/dist/canvas/locales/pt.js +1 -1
  36. package/dist/canvas/locales/ro.cjs +1 -1
  37. package/dist/canvas/locales/ro.d.ts.map +1 -1
  38. package/dist/canvas/locales/ro.js +1 -1
  39. package/dist/canvas/locales/ru.cjs +1 -1
  40. package/dist/canvas/locales/ru.d.ts.map +1 -1
  41. package/dist/canvas/locales/ru.js +1 -1
  42. package/dist/canvas/locales/tr.cjs +1 -1
  43. package/dist/canvas/locales/tr.d.ts.map +1 -1
  44. package/dist/canvas/locales/tr.js +1 -1
  45. package/dist/canvas/locales/zh-CN.cjs +1 -1
  46. package/dist/canvas/locales/zh-CN.d.ts.map +1 -1
  47. package/dist/canvas/locales/zh-CN.js +1 -1
  48. package/dist/canvas/locales/zh-TW.cjs +1 -1
  49. package/dist/canvas/locales/zh-TW.d.ts.map +1 -1
  50. package/dist/canvas/locales/zh-TW.js +1 -1
  51. package/dist/canvas/styles/tailwind.canvas.css +1 -1
  52. package/dist/chat/locales/de.cjs +1 -1
  53. package/dist/chat/locales/de.d.ts.map +1 -1
  54. package/dist/chat/locales/de.js +1 -1
  55. package/dist/chat/locales/en.cjs +1 -1
  56. package/dist/chat/locales/en.d.ts.map +1 -1
  57. package/dist/chat/locales/en.js +1 -1
  58. package/dist/chat/locales/es-MX.cjs +1 -1
  59. package/dist/chat/locales/es-MX.d.ts.map +1 -1
  60. package/dist/chat/locales/es-MX.js +1 -1
  61. package/dist/chat/locales/es.cjs +1 -1
  62. package/dist/chat/locales/es.d.ts.map +1 -1
  63. package/dist/chat/locales/es.js +1 -1
  64. package/dist/chat/locales/fr.cjs +1 -1
  65. package/dist/chat/locales/fr.d.ts.map +1 -1
  66. package/dist/chat/locales/fr.js +1 -1
  67. package/dist/chat/locales/ja.cjs +1 -1
  68. package/dist/chat/locales/ja.d.ts.map +1 -1
  69. package/dist/chat/locales/ja.js +1 -1
  70. package/dist/chat/locales/ko.cjs +1 -1
  71. package/dist/chat/locales/ko.d.ts.map +1 -1
  72. package/dist/chat/locales/ko.js +1 -1
  73. package/dist/chat/locales/pt-BR.cjs +1 -1
  74. package/dist/chat/locales/pt-BR.d.ts.map +1 -1
  75. package/dist/chat/locales/pt-BR.js +1 -1
  76. package/dist/chat/locales/pt.cjs +1 -1
  77. package/dist/chat/locales/pt.d.ts.map +1 -1
  78. package/dist/chat/locales/pt.js +1 -1
  79. package/dist/chat/locales/ro.cjs +1 -1
  80. package/dist/chat/locales/ro.d.ts.map +1 -1
  81. package/dist/chat/locales/ro.js +1 -1
  82. package/dist/chat/locales/ru.cjs +1 -1
  83. package/dist/chat/locales/ru.d.ts.map +1 -1
  84. package/dist/chat/locales/ru.js +1 -1
  85. package/dist/chat/locales/tr.cjs +1 -1
  86. package/dist/chat/locales/tr.d.ts.map +1 -1
  87. package/dist/chat/locales/tr.js +1 -1
  88. package/dist/chat/locales/zh-CN.cjs +1 -1
  89. package/dist/chat/locales/zh-CN.d.ts.map +1 -1
  90. package/dist/chat/locales/zh-CN.js +1 -1
  91. package/dist/chat/locales/zh-TW.cjs +1 -1
  92. package/dist/chat/locales/zh-TW.d.ts.map +1 -1
  93. package/dist/chat/locales/zh-TW.js +1 -1
  94. package/dist/chat/styles/tailwind.chat.css +1 -1
  95. package/dist/decision-table/DecisionTable.cjs +454 -0
  96. package/dist/decision-table/DecisionTable.d.ts +36 -0
  97. package/dist/decision-table/DecisionTable.d.ts.map +1 -0
  98. package/dist/decision-table/DecisionTable.js +410 -0
  99. package/dist/decision-table/GridCell.cjs +153 -0
  100. package/dist/decision-table/GridCell.d.ts +43 -0
  101. package/dist/decision-table/GridCell.d.ts.map +1 -0
  102. package/dist/decision-table/GridCell.js +116 -0
  103. package/dist/decision-table/GridMenu.cjs +135 -0
  104. package/dist/decision-table/GridMenu.d.ts +30 -0
  105. package/dist/decision-table/GridMenu.d.ts.map +1 -0
  106. package/dist/decision-table/GridMenu.js +101 -0
  107. package/dist/decision-table/MarkGlyph.cjs +51 -0
  108. package/dist/decision-table/MarkGlyph.d.ts +7 -0
  109. package/dist/decision-table/MarkGlyph.d.ts.map +1 -0
  110. package/dist/decision-table/MarkGlyph.js +17 -0
  111. package/dist/decision-table/clipboardCodec.cjs +123 -0
  112. package/dist/decision-table/clipboardCodec.d.ts +8 -0
  113. package/dist/decision-table/clipboardCodec.d.ts.map +1 -0
  114. package/dist/decision-table/clipboardCodec.js +80 -0
  115. package/dist/decision-table/clippedTitle.cjs +39 -0
  116. package/dist/decision-table/clippedTitle.d.ts +3 -0
  117. package/dist/decision-table/clippedTitle.d.ts.map +1 -0
  118. package/dist/decision-table/clippedTitle.js +5 -0
  119. package/dist/decision-table/columnSizing.cjs +92 -0
  120. package/dist/decision-table/columnSizing.d.ts +13 -0
  121. package/dist/decision-table/columnSizing.d.ts.map +1 -0
  122. package/dist/decision-table/columnSizing.js +52 -0
  123. package/dist/decision-table/constants.cjs +84 -0
  124. package/dist/decision-table/constants.d.ts +14 -0
  125. package/dist/decision-table/constants.d.ts.map +1 -0
  126. package/dist/decision-table/constants.js +14 -0
  127. package/dist/decision-table/gridClipboard.cjs +129 -0
  128. package/dist/decision-table/gridClipboard.d.ts +19 -0
  129. package/dist/decision-table/gridClipboard.d.ts.map +1 -0
  130. package/dist/decision-table/gridClipboard.js +89 -0
  131. package/dist/decision-table/gridEvents.cjs +72 -0
  132. package/dist/decision-table/gridEvents.d.ts +14 -0
  133. package/dist/decision-table/gridEvents.d.ts.map +1 -0
  134. package/dist/decision-table/gridEvents.js +23 -0
  135. package/dist/decision-table/gridStyles.cjs +196 -0
  136. package/dist/decision-table/gridStyles.d.ts +47 -0
  137. package/dist/decision-table/gridStyles.d.ts.map +1 -0
  138. package/dist/decision-table/gridStyles.js +54 -0
  139. package/dist/decision-table/gridTypes.cjs +18 -0
  140. package/dist/decision-table/gridTypes.d.ts +93 -0
  141. package/dist/decision-table/gridTypes.d.ts.map +1 -0
  142. package/dist/decision-table/gridTypes.js +0 -0
  143. package/dist/decision-table/index.cjs +271 -0
  144. package/dist/decision-table/index.d.ts +13 -0
  145. package/dist/decision-table/index.d.ts.map +1 -0
  146. package/dist/decision-table/index.js +12 -0
  147. package/dist/decision-table/marks.cjs +39 -0
  148. package/dist/decision-table/marks.d.ts +20 -0
  149. package/dist/decision-table/marks.d.ts.map +1 -0
  150. package/dist/decision-table/marks.js +5 -0
  151. package/dist/decision-table/styles/tailwind.decision-table.css +2 -0
  152. package/dist/decision-table/useColumnWidths.cjs +313 -0
  153. package/dist/decision-table/useColumnWidths.d.ts +21 -0
  154. package/dist/decision-table/useColumnWidths.d.ts.map +1 -0
  155. package/dist/decision-table/useColumnWidths.js +279 -0
  156. package/dist/decision-table/useDragReorder.cjs +229 -0
  157. package/dist/decision-table/useDragReorder.d.ts +31 -0
  158. package/dist/decision-table/useDragReorder.d.ts.map +1 -0
  159. package/dist/decision-table/useDragReorder.js +186 -0
  160. package/dist/decision-table/useDragSelection.cjs +75 -0
  161. package/dist/decision-table/useDragSelection.d.ts +18 -0
  162. package/dist/decision-table/useDragSelection.d.ts.map +1 -0
  163. package/dist/decision-table/useDragSelection.js +41 -0
  164. package/dist/decision-table/useGridClipboard.cjs +195 -0
  165. package/dist/decision-table/useGridClipboard.d.ts +13 -0
  166. package/dist/decision-table/useGridClipboard.d.ts.map +1 -0
  167. package/dist/decision-table/useGridClipboard.js +161 -0
  168. package/dist/decision-table/useGridLayout.cjs +248 -0
  169. package/dist/decision-table/useGridLayout.d.ts +50 -0
  170. package/dist/decision-table/useGridLayout.d.ts.map +1 -0
  171. package/dist/decision-table/useGridLayout.js +211 -0
  172. package/dist/decision-table/useGridNavigation.cjs +441 -0
  173. package/dist/decision-table/useGridNavigation.d.ts +67 -0
  174. package/dist/decision-table/useGridNavigation.d.ts.map +1 -0
  175. package/dist/decision-table/useGridNavigation.js +404 -0
  176. package/dist/decision-table/useVirtualizedAxis.cjs +256 -0
  177. package/dist/decision-table/useVirtualizedAxis.d.ts +34 -0
  178. package/dist/decision-table/useVirtualizedAxis.d.ts.map +1 -0
  179. package/dist/decision-table/useVirtualizedAxis.js +219 -0
  180. package/dist/test/setup.d.ts.map +1 -1
  181. package/package.json +20 -10
@@ -0,0 +1,67 @@
1
+ import type { CellCommitMove, GridPosition, GridRange } from './gridTypes';
2
+ export type { GridPosition, GridRange };
3
+ export interface CellSelectionRange {
4
+ anchorColumnId: string;
5
+ anchorRowId: string;
6
+ focusColumnId: string;
7
+ focusRowId: string;
8
+ operation?: 'include' | 'exclude';
9
+ }
10
+ export type CellSelectionState = Array<CellSelectionRange>;
11
+ export type Updater<T> = T | ((old: T) => T);
12
+ export interface GridSelectionHandle {
13
+ read: () => GridRange | null;
14
+ restore: (range: GridRange | null) => void;
15
+ clear: () => void;
16
+ editing: () => boolean;
17
+ }
18
+ export type AxisSelection = 'row' | 'column' | null;
19
+ export type SelectionGesture = 'cell' | 'row' | 'column';
20
+ export declare const normalizedRect: (range: GridRange) => {
21
+ top: number;
22
+ bottom: number;
23
+ left: number;
24
+ right: number;
25
+ };
26
+ export interface GridNavigation {
27
+ focus: GridPosition | null;
28
+ singleSelection: GridPosition | null;
29
+ selectedIds: {
30
+ rowId: string;
31
+ columnId: string;
32
+ } | null;
33
+ range: GridRange | null;
34
+ axisSelection: AxisSelection;
35
+ focusRing: GridPosition | null;
36
+ editing: boolean;
37
+ openedByTyping: boolean;
38
+ select: (position: GridPosition) => void;
39
+ clear: () => void;
40
+ restore: (range: GridRange | null) => void;
41
+ extendTo: (position: GridPosition) => void;
42
+ selectAll: () => void;
43
+ selectRow: (row: number) => void;
44
+ selectColumn: (col: number) => void;
45
+ startEditAt: (position: GridPosition) => void;
46
+ commitEdit: (move: CellCommitMove) => void;
47
+ cancelEdit: () => void;
48
+ onKeyDown: (event: React.KeyboardEvent) => void;
49
+ }
50
+ export interface GridNavigationOptions {
51
+ onSelectionReplaced?: (gesture: SelectionGesture) => void;
52
+ canEditAt?: (position: GridPosition, gesture: EditGesture) => boolean;
53
+ onEscape?: () => void;
54
+ }
55
+ export type EditGesture = 'command' | 'type';
56
+ export interface GridSelectionSource {
57
+ table: {
58
+ state: {
59
+ cellSelection?: CellSelectionState;
60
+ };
61
+ setCellSelection: (updater: Updater<CellSelectionState>) => void;
62
+ };
63
+ rowIds: readonly string[];
64
+ colIds: readonly string[];
65
+ }
66
+ export declare const useGridNavigation: ({ table, rowIds, colIds }: GridSelectionSource, options?: GridNavigationOptions) => GridNavigation;
67
+ //# sourceMappingURL=useGridNavigation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useGridNavigation.d.ts","sourceRoot":"","sources":["../../src/decision-table/useGridNavigation.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,404 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2
+ import { flushSync } from "react-dom";
3
+ const normalizedRect = (range)=>({
4
+ top: Math.min(range.anchor.row, range.focus.row),
5
+ bottom: Math.max(range.anchor.row, range.focus.row),
6
+ left: Math.min(range.anchor.col, range.focus.col),
7
+ right: Math.max(range.anchor.col, range.focus.col)
8
+ });
9
+ const clamp = (value, max)=>Math.max(0, Math.min(value, max));
10
+ const GRID_ENTRY_KEYS = [
11
+ 'ArrowUp',
12
+ 'ArrowDown',
13
+ 'ArrowLeft',
14
+ 'ArrowRight',
15
+ 'Home',
16
+ 'End'
17
+ ];
18
+ const MOVE_DELTA = {
19
+ down: {
20
+ row: 1,
21
+ col: 0
22
+ },
23
+ right: {
24
+ row: 0,
25
+ col: 1
26
+ },
27
+ left: {
28
+ row: 0,
29
+ col: -1
30
+ },
31
+ none: {
32
+ row: 0,
33
+ col: 0
34
+ }
35
+ };
36
+ const isApplePlatform = ()=>{
37
+ if ("u" < typeof navigator) return false;
38
+ const platform = navigator.userAgentData?.platform ?? navigator.platform;
39
+ return /mac|iphone|ipad|ipod|ios/i.test(platform);
40
+ };
41
+ const isTypedCharacter = (event)=>{
42
+ if (1 !== event.key.length && 'Dead' !== event.key || event.metaKey || event.nativeEvent.isComposing) return false;
43
+ if (event.ctrlKey) return event.altKey && !isApplePlatform();
44
+ return !event.altKey || isApplePlatform();
45
+ };
46
+ const ARROW_DELTAS = {
47
+ ArrowUp: {
48
+ row: -1,
49
+ col: 0
50
+ },
51
+ ArrowDown: {
52
+ row: 1,
53
+ col: 0
54
+ },
55
+ ArrowLeft: {
56
+ row: 0,
57
+ col: -1
58
+ },
59
+ ArrowRight: {
60
+ row: 0,
61
+ col: 1
62
+ }
63
+ };
64
+ const useGridNavigation = ({ table, rowIds, colIds }, options = {})=>{
65
+ const [editing, setEditing] = useState(false);
66
+ const [openedByTyping, setOpenedByTyping] = useState(false);
67
+ const onSelectionReplacedRef = useRef(options.onSelectionReplaced);
68
+ onSelectionReplacedRef.current = options.onSelectionReplaced;
69
+ const announceReplaced = useCallback((gesture)=>onSelectionReplacedRef.current?.(gesture), []);
70
+ const canEditAtRef = useRef(options.canEditAt);
71
+ canEditAtRef.current = options.canEditAt;
72
+ const onEscapeRef = useRef(options.onEscape);
73
+ onEscapeRef.current = options.onEscape;
74
+ const tableRef = useRef(table);
75
+ tableRef.current = table;
76
+ const pendingRestoreRef = useRef(void 0);
77
+ const axisRectRef = useRef(null);
78
+ const rowCount = rowIds.length;
79
+ const colCount = colIds.length;
80
+ const hasCells = rowCount > 0 && colCount > 0;
81
+ const rowIndexById = useMemo(()=>new Map(rowIds.map((id, index)=>[
82
+ id,
83
+ index
84
+ ])), [
85
+ rowIds
86
+ ]);
87
+ const colIndexById = useMemo(()=>new Map(colIds.map((id, index)=>[
88
+ id,
89
+ index
90
+ ])), [
91
+ colIds
92
+ ]);
93
+ const toIds = useCallback((position)=>{
94
+ if (!hasCells) return null;
95
+ return {
96
+ rowId: rowIds[clamp(position.row, rowCount - 1)],
97
+ columnId: colIds[clamp(position.col, colCount - 1)]
98
+ };
99
+ }, [
100
+ hasCells,
101
+ rowIds,
102
+ colIds,
103
+ rowCount,
104
+ colCount
105
+ ]);
106
+ const setRange = useCallback((anchor, focus)=>{
107
+ const anchorIds = toIds(anchor);
108
+ const focusIds = toIds(focus);
109
+ if (!anchorIds || !focusIds) return;
110
+ tableRef.current.setCellSelection([
111
+ {
112
+ anchorRowId: anchorIds.rowId,
113
+ anchorColumnId: anchorIds.columnId,
114
+ focusRowId: focusIds.rowId,
115
+ focusColumnId: focusIds.columnId
116
+ }
117
+ ]);
118
+ }, [
119
+ toIds
120
+ ]);
121
+ const active = table.state.cellSelection?.[0];
122
+ const anchorRow = active ? rowIndexById.get(active.anchorRowId) : void 0;
123
+ const anchorCol = active ? colIndexById.get(active.anchorColumnId) : void 0;
124
+ const focusRow = active ? rowIndexById.get(active.focusRowId) : void 0;
125
+ const focusCol = active ? colIndexById.get(active.focusColumnId) : void 0;
126
+ const range = useMemo(()=>void 0 === anchorRow || void 0 === anchorCol || void 0 === focusRow || void 0 === focusCol ? null : {
127
+ anchor: {
128
+ row: anchorRow,
129
+ col: anchorCol
130
+ },
131
+ focus: {
132
+ row: focusRow,
133
+ col: focusCol
134
+ }
135
+ }, [
136
+ anchorRow,
137
+ anchorCol,
138
+ focusRow,
139
+ focusCol
140
+ ]);
141
+ const focus = useMemo(()=>range?.focus ?? null, [
142
+ range
143
+ ]);
144
+ const axisSelection = range ? axisRectRef.current : null;
145
+ const singleSelection = useMemo(()=>range && !axisSelection && range.anchor.row === range.focus.row && range.anchor.col === range.focus.col ? range.focus : null, [
146
+ range,
147
+ axisSelection
148
+ ]);
149
+ const focusRowId = range ? active?.focusRowId : void 0;
150
+ const focusColumnId = range ? active?.focusColumnId : void 0;
151
+ const selectedIds = useMemo(()=>void 0 === focusRowId || void 0 === focusColumnId ? null : {
152
+ rowId: focusRowId,
153
+ columnId: focusColumnId
154
+ }, [
155
+ focusRowId,
156
+ focusColumnId
157
+ ]);
158
+ useEffect(()=>{
159
+ if (table.state.cellSelection?.length && !range) {
160
+ table.setCellSelection([]);
161
+ setEditing(false);
162
+ }
163
+ }, [
164
+ table,
165
+ range
166
+ ]);
167
+ const select = useCallback((position)=>{
168
+ announceReplaced('cell');
169
+ axisRectRef.current = null;
170
+ setRange(position, position);
171
+ setEditing(false);
172
+ }, [
173
+ setRange,
174
+ announceReplaced
175
+ ]);
176
+ const clear = useCallback(()=>{
177
+ axisRectRef.current = null;
178
+ tableRef.current.setCellSelection([]);
179
+ setEditing(false);
180
+ }, []);
181
+ const restore = useCallback((next)=>{
182
+ axisRectRef.current = null;
183
+ pendingRestoreRef.current = next;
184
+ setEditing(false);
185
+ }, []);
186
+ useEffect(()=>{
187
+ const pending = pendingRestoreRef.current;
188
+ if (void 0 === pending) return;
189
+ pendingRestoreRef.current = void 0;
190
+ if (pending) setRange(pending.anchor, pending.focus);
191
+ else tableRef.current.setCellSelection([]);
192
+ });
193
+ const extendTo = useCallback((position)=>{
194
+ axisRectRef.current = null;
195
+ const focusIds = toIds(position);
196
+ if (!focusIds) return;
197
+ tableRef.current.setCellSelection((previous)=>{
198
+ const active = previous?.[0];
199
+ return [
200
+ {
201
+ anchorRowId: active?.anchorRowId ?? focusIds.rowId,
202
+ anchorColumnId: active?.anchorColumnId ?? focusIds.columnId,
203
+ focusRowId: focusIds.rowId,
204
+ focusColumnId: focusIds.columnId
205
+ }
206
+ ];
207
+ });
208
+ setEditing(false);
209
+ }, [
210
+ toIds
211
+ ]);
212
+ const selectAll = useCallback(()=>{
213
+ announceReplaced('cell');
214
+ axisRectRef.current = null;
215
+ setRange({
216
+ row: 0,
217
+ col: 0
218
+ }, {
219
+ row: rowCount - 1,
220
+ col: colCount - 1
221
+ });
222
+ setEditing(false);
223
+ }, [
224
+ setRange,
225
+ rowCount,
226
+ colCount,
227
+ announceReplaced
228
+ ]);
229
+ const selectRow = useCallback((row)=>{
230
+ announceReplaced('row');
231
+ setRange({
232
+ row,
233
+ col: colCount - 1
234
+ }, {
235
+ row,
236
+ col: 0
237
+ });
238
+ axisRectRef.current = 'row';
239
+ setEditing(false);
240
+ }, [
241
+ setRange,
242
+ colCount,
243
+ announceReplaced
244
+ ]);
245
+ const selectColumn = useCallback((col)=>{
246
+ announceReplaced('column');
247
+ setRange({
248
+ row: rowCount - 1,
249
+ col
250
+ }, {
251
+ row: 0,
252
+ col
253
+ });
254
+ axisRectRef.current = 'column';
255
+ setEditing(false);
256
+ }, [
257
+ setRange,
258
+ rowCount,
259
+ announceReplaced
260
+ ]);
261
+ const openEditAt = useCallback((position, byTyping)=>{
262
+ announceReplaced('cell');
263
+ axisRectRef.current = null;
264
+ setRange(position, position);
265
+ setOpenedByTyping(byTyping);
266
+ setEditing(true);
267
+ }, [
268
+ setRange,
269
+ announceReplaced
270
+ ]);
271
+ const startEditAt = useCallback((position)=>openEditAt(position, false), [
272
+ openEditAt
273
+ ]);
274
+ const commitEdit = useCallback((move)=>{
275
+ axisRectRef.current = null;
276
+ tableRef.current.setCellSelection((previous)=>{
277
+ const active = previous?.[0];
278
+ if (!active) return previous ?? [];
279
+ const row = rowIndexById.get(active.focusRowId);
280
+ const col = colIndexById.get(active.focusColumnId);
281
+ if (void 0 === row || void 0 === col) return previous;
282
+ const next = toIds({
283
+ row: row + MOVE_DELTA[move].row,
284
+ col: col + MOVE_DELTA[move].col
285
+ });
286
+ if (!next) return previous;
287
+ return [
288
+ {
289
+ anchorRowId: next.rowId,
290
+ anchorColumnId: next.columnId,
291
+ focusRowId: next.rowId,
292
+ focusColumnId: next.columnId
293
+ }
294
+ ];
295
+ });
296
+ setEditing(false);
297
+ }, [
298
+ toIds,
299
+ rowIndexById,
300
+ colIndexById
301
+ ]);
302
+ const cancelEdit = useCallback(()=>setEditing(false), []);
303
+ const onKeyDown = useCallback((event)=>{
304
+ if (editing) return;
305
+ if (event.defaultPrevented) return;
306
+ if ('Escape' === event.key) {
307
+ if (range) event.preventDefault();
308
+ clear();
309
+ onEscapeRef.current?.();
310
+ return;
311
+ }
312
+ const meta = event.metaKey || event.ctrlKey;
313
+ if (!focus) {
314
+ if (hasCells && (GRID_ENTRY_KEYS.includes(event.key) || 'Enter' === event.key || 'F2' === event.key)) {
315
+ event.preventDefault();
316
+ select({
317
+ row: 0,
318
+ col: 0
319
+ });
320
+ }
321
+ return;
322
+ }
323
+ if (meta && 'a' === event.key.toLowerCase()) {
324
+ event.preventDefault();
325
+ selectAll();
326
+ return;
327
+ }
328
+ const delta = ARROW_DELTAS[event.key];
329
+ if (delta) {
330
+ event.preventDefault();
331
+ const from = event.shiftKey && range ? range.focus : focus;
332
+ const next = {
333
+ row: meta ? 0 === delta.row ? from.row : delta.row < 0 ? 0 : rowCount - 1 : from.row + delta.row,
334
+ col: meta ? 0 === delta.col ? from.col : delta.col < 0 ? 0 : colCount - 1 : from.col + delta.col
335
+ };
336
+ if (event.shiftKey) extendTo(next);
337
+ else select(next);
338
+ return;
339
+ }
340
+ if ('Home' === event.key || 'End' === event.key) {
341
+ event.preventDefault();
342
+ const next = {
343
+ row: meta ? 'Home' === event.key ? 0 : rowCount - 1 : focus.row,
344
+ col: 'Home' === event.key ? 0 : colCount - 1
345
+ };
346
+ if (event.shiftKey) extendTo(next);
347
+ else select(next);
348
+ return;
349
+ }
350
+ if ('Enter' === event.key || 'F2' === event.key) {
351
+ event.preventDefault();
352
+ if (canEditAtRef.current?.(focus, 'command') !== false) {
353
+ setOpenedByTyping(false);
354
+ setEditing(true);
355
+ }
356
+ return;
357
+ }
358
+ if ('Tab' === event.key && !meta && !event.altKey) {
359
+ const col = focus.col + (event.shiftKey ? -1 : 1);
360
+ if (col < 0 || col >= colCount) return;
361
+ event.preventDefault();
362
+ select({
363
+ row: focus.row,
364
+ col
365
+ });
366
+ return;
367
+ }
368
+ if (isTypedCharacter(event) && canEditAtRef.current?.(focus, 'type') !== false) flushSync(()=>openEditAt(focus, true));
369
+ }, [
370
+ editing,
371
+ focus,
372
+ range,
373
+ hasCells,
374
+ rowCount,
375
+ colCount,
376
+ extendTo,
377
+ select,
378
+ selectAll,
379
+ clear,
380
+ openEditAt
381
+ ]);
382
+ return {
383
+ focus,
384
+ singleSelection,
385
+ selectedIds,
386
+ range,
387
+ axisSelection,
388
+ focusRing: axisSelection ? null : focus,
389
+ editing,
390
+ openedByTyping: editing && openedByTyping,
391
+ select,
392
+ clear,
393
+ restore,
394
+ extendTo,
395
+ selectAll,
396
+ selectRow,
397
+ selectColumn,
398
+ startEditAt,
399
+ commitEdit,
400
+ cancelEdit,
401
+ onKeyDown
402
+ };
403
+ };
404
+ export { normalizedRect, useGridNavigation };