@viewkitjs/views 0.2.0 → 0.3.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 (292) hide show
  1. package/CHANGELOG.md +571 -0
  2. package/README.md +5 -3
  3. package/dist/atoms/LoadMore.js +11 -1
  4. package/dist/atoms/RowMenu.js +5 -2
  5. package/dist/cells/cell-format.d.ts +3 -3
  6. package/dist/cells/cell-title.d.ts +1 -2
  7. package/dist/cells/cell-title.js +2 -2
  8. package/dist/cells/cell-values.js +6 -3
  9. package/dist/contract.d.ts +50 -9
  10. package/dist/contract.js +33 -5
  11. package/dist/display/converted.d.ts +19 -0
  12. package/dist/display/converted.js +12 -0
  13. package/dist/display/index.d.ts +1 -0
  14. package/dist/display/index.js +1 -0
  15. package/dist/display/link-click.d.ts +11 -0
  16. package/dist/display/link-click.js +3 -0
  17. package/dist/display/link.js +7 -3
  18. package/dist/display/multi-value.d.ts +1 -1
  19. package/dist/display/multi-value.js +1 -1
  20. package/dist/display/options.d.ts +7 -1
  21. package/dist/display/phone.js +3 -1
  22. package/dist/editors/ChipsEditor.d.ts +9 -4
  23. package/dist/editors/ChipsEditor.js +6 -2
  24. package/dist/editors/DateEditor.d.ts +21 -6
  25. package/dist/editors/DateEditor.js +118 -30
  26. package/dist/editors/EditorPanel.d.ts +61 -0
  27. package/dist/editors/EditorPanel.js +54 -0
  28. package/dist/editors/LocationEditor.d.ts +3 -0
  29. package/dist/editors/LocationEditor.js +14 -6
  30. package/dist/editors/NameEditor.d.ts +3 -0
  31. package/dist/editors/NameEditor.js +11 -7
  32. package/dist/editors/NumberEditor.d.ts +3 -0
  33. package/dist/editors/NumberEditor.js +6 -6
  34. package/dist/editors/RangeEditor.d.ts +16 -1
  35. package/dist/editors/RangeEditor.js +21 -5
  36. package/dist/editors/RelationEditor.d.ts +13 -28
  37. package/dist/editors/RelationEditor.js +17 -40
  38. package/dist/editors/RelationSetEditor.d.ts +53 -0
  39. package/dist/editors/RelationSetEditor.js +112 -0
  40. package/dist/editors/SelectEditor.d.ts +21 -3
  41. package/dist/editors/SelectEditor.js +55 -9
  42. package/dist/editors/TextEditor.d.ts +51 -0
  43. package/dist/editors/TextEditor.js +81 -0
  44. package/dist/editors/ValueListEditor.d.ts +3 -0
  45. package/dist/editors/ValueListEditor.js +4 -2
  46. package/dist/editors/edit-cores.d.ts +12 -9
  47. package/dist/editors/edit-cores.js +7 -6
  48. package/dist/editors/edit-session.d.ts +21 -11
  49. package/dist/editors/edit-session.js +19 -5
  50. package/dist/editors/keep-inside.d.ts +12 -0
  51. package/dist/editors/keep-inside.js +20 -0
  52. package/dist/editors/open-value.d.ts +21 -0
  53. package/dist/editors/open-value.js +36 -0
  54. package/dist/editors/open-values.d.ts +4 -0
  55. package/dist/editors/open-values.js +7 -0
  56. package/dist/editors/relation-kinds.d.ts +7 -0
  57. package/dist/editors/relation-kinds.js +21 -0
  58. package/dist/editors/relation-panel.d.ts +69 -0
  59. package/dist/editors/relation-panel.js +40 -0
  60. package/dist/field-row/FieldNoteLine.d.ts +14 -0
  61. package/dist/field-row/FieldNoteLine.js +14 -0
  62. package/dist/field-row/FieldRow.d.ts +73 -0
  63. package/dist/field-row/FieldRow.js +157 -0
  64. package/dist/field-row/FieldRowLane.d.ts +19 -0
  65. package/dist/field-row/FieldRowLane.js +11 -0
  66. package/dist/field-row/editors/RowChipsEditor.d.ts +11 -0
  67. package/dist/field-row/editors/RowChipsEditor.js +25 -0
  68. package/dist/field-row/editors/RowDateEditor.d.ts +16 -0
  69. package/dist/field-row/editors/RowDateEditor.js +18 -0
  70. package/dist/field-row/editors/RowEditor.d.ts +39 -0
  71. package/dist/field-row/editors/RowEditor.js +64 -0
  72. package/dist/field-row/editors/RowNameEditor.d.ts +4 -0
  73. package/dist/field-row/editors/RowNameEditor.js +15 -0
  74. package/dist/field-row/editors/RowNumberEditor.d.ts +12 -0
  75. package/dist/field-row/editors/RowNumberEditor.js +18 -0
  76. package/dist/field-row/editors/RowPlaceEditor.d.ts +8 -0
  77. package/dist/field-row/editors/RowPlaceEditor.js +18 -0
  78. package/dist/field-row/editors/RowRangeEditor.d.ts +4 -0
  79. package/dist/field-row/editors/RowRangeEditor.js +15 -0
  80. package/dist/field-row/editors/RowRelationEditor.d.ts +20 -0
  81. package/dist/field-row/editors/RowRelationEditor.js +77 -0
  82. package/dist/field-row/editors/RowSelectEditor.d.ts +13 -0
  83. package/dist/field-row/editors/RowSelectEditor.js +23 -0
  84. package/dist/field-row/editors/RowTextEditor.d.ts +15 -0
  85. package/dist/field-row/editors/RowTextEditor.js +16 -0
  86. package/dist/field-row/editors/RowValueListEditor.d.ts +4 -0
  87. package/dist/field-row/editors/RowValueListEditor.js +21 -0
  88. package/dist/field-row/editors/host.d.ts +59 -0
  89. package/dist/field-row/editors/host.js +1 -0
  90. package/dist/field-row/editors/row-session.d.ts +49 -0
  91. package/dist/field-row/editors/row-session.js +49 -0
  92. package/dist/field-row/index.d.ts +5 -0
  93. package/dist/field-row/index.js +5 -0
  94. package/dist/field-row/row-target.d.ts +20 -0
  95. package/dist/field-row/row-target.js +3 -0
  96. package/dist/field-row/useFieldWrite.d.ts +45 -0
  97. package/dist/field-row/useFieldWrite.js +190 -0
  98. package/dist/field-row/useRowSettlement.d.ts +33 -0
  99. package/dist/field-row/useRowSettlement.js +23 -0
  100. package/dist/fields/binding.d.ts +6 -1
  101. package/dist/fields/binding.js +13 -6
  102. package/dist/fields/edit-core-types.d.ts +9 -9
  103. package/dist/fields/edit-core-types.js +6 -6
  104. package/dist/fields/money.d.ts +5 -0
  105. package/dist/fields/money.js +10 -0
  106. package/dist/fields/number-edit.d.ts +6 -0
  107. package/dist/fields/number-edit.js +4 -0
  108. package/dist/fields/prepare-write.js +6 -1
  109. package/dist/fields/relation-source-types.d.ts +12 -0
  110. package/dist/fields/write-target.d.ts +50 -0
  111. package/dist/fields/write-target.js +10 -0
  112. package/dist/grid/chrome/GridAddColumn.js +1 -1
  113. package/dist/grid/chrome/GridAggregateMenu.d.ts +1 -1
  114. package/dist/grid/chrome/GridAggregateMenu.js +8 -6
  115. package/dist/grid/chrome/GridCellEditors.d.ts +7 -0
  116. package/dist/grid/chrome/GridCellEditors.js +87 -16
  117. package/dist/grid/chrome/GridCellOutline.d.ts +22 -43
  118. package/dist/grid/chrome/GridCellOutline.js +2 -7
  119. package/dist/grid/chrome/GridChipsEditor.d.ts +16 -6
  120. package/dist/grid/chrome/GridChipsEditor.js +21 -26
  121. package/dist/grid/chrome/GridColumnMenu.d.ts +1 -1
  122. package/dist/grid/chrome/GridColumnMenu.js +7 -3
  123. package/dist/grid/chrome/GridDateEditor.d.ts +23 -11
  124. package/dist/grid/chrome/GridDateEditor.js +13 -25
  125. package/dist/grid/chrome/GridFooter.d.ts +12 -2
  126. package/dist/grid/chrome/GridFooter.js +10 -6
  127. package/dist/grid/chrome/GridGroupMenu.js +20 -13
  128. package/dist/grid/chrome/GridHeader.d.ts +9 -4
  129. package/dist/grid/chrome/GridHeader.js +15 -10
  130. package/dist/grid/chrome/GridLongTextEditor.d.ts +28 -9
  131. package/dist/grid/chrome/GridLongTextEditor.js +16 -74
  132. package/dist/grid/chrome/GridNameEditor.d.ts +11 -6
  133. package/dist/grid/chrome/GridNameEditor.js +12 -27
  134. package/dist/grid/chrome/GridNumberEditor.d.ts +20 -6
  135. package/dist/grid/chrome/GridNumberEditor.js +46 -20
  136. package/dist/grid/chrome/GridPlaceEditor.d.ts +26 -0
  137. package/dist/grid/chrome/GridPlaceEditor.js +22 -0
  138. package/dist/grid/chrome/GridRangeEditor.d.ts +15 -5
  139. package/dist/grid/chrome/GridRangeEditor.js +16 -20
  140. package/dist/grid/chrome/GridRelationEditor.d.ts +38 -14
  141. package/dist/grid/chrome/GridRelationEditor.js +86 -24
  142. package/dist/grid/chrome/GridRow.d.ts +7 -1
  143. package/dist/grid/chrome/GridRow.js +57 -14
  144. package/dist/grid/chrome/GridRowActions.js +1 -1
  145. package/dist/grid/chrome/GridRowCells.js +18 -23
  146. package/dist/grid/chrome/GridSelectEditor.d.ts +19 -4
  147. package/dist/grid/chrome/GridSelectEditor.js +21 -27
  148. package/dist/grid/chrome/GridStructure.d.ts +9 -10
  149. package/dist/grid/chrome/GridStructure.js +10 -14
  150. package/dist/grid/chrome/GridTable.js +97 -30
  151. package/dist/grid/chrome/GridTableSurface.d.ts +39 -2
  152. package/dist/grid/chrome/GridTableSurface.js +12 -3
  153. package/dist/grid/chrome/GridTextEditor.d.ts +35 -1
  154. package/dist/grid/chrome/GridTextEditor.js +35 -37
  155. package/dist/grid/chrome/GridValueListEditor.d.ts +15 -3
  156. package/dist/grid/chrome/GridValueListEditor.js +10 -27
  157. package/dist/grid/chrome/cell-cut-off.d.ts +11 -0
  158. package/dist/grid/chrome/cell-cut-off.js +20 -0
  159. package/dist/grid/chrome/cells.js +1 -2
  160. package/dist/grid/chrome/checks.d.ts +2 -5
  161. package/dist/grid/chrome/checks.js +15 -5
  162. package/dist/grid/chrome/editors.d.ts +1 -1
  163. package/dist/grid/chrome/editors.js +1 -1
  164. package/dist/grid/chrome/grid-cell-classes.d.ts +2 -8
  165. package/dist/grid/chrome/grid-cell-classes.js +10 -8
  166. package/dist/grid/chrome/grid-cell-link.d.ts +13 -0
  167. package/dist/grid/chrome/grid-cell-link.js +9 -0
  168. package/dist/grid/chrome/grid-edit-session.d.ts +63 -0
  169. package/dist/grid/chrome/grid-edit-session.js +118 -0
  170. package/dist/grid/chrome/grid-hover.d.ts +60 -0
  171. package/dist/grid/chrome/grid-hover.js +81 -0
  172. package/dist/grid/chrome/grid-menu-focus.d.ts +43 -0
  173. package/dist/grid/chrome/grid-menu-focus.js +93 -0
  174. package/dist/grid/chrome/grid-row-menu-key.d.ts +15 -0
  175. package/dist/grid/chrome/grid-row-menu-key.js +36 -0
  176. package/dist/grid/chrome/grid-row-props.d.ts +16 -4
  177. package/dist/grid/chrome/grid-row-window.d.ts +61 -0
  178. package/dist/grid/chrome/grid-row-window.js +212 -0
  179. package/dist/grid/chrome/grid-scroll-owner.d.ts +38 -0
  180. package/dist/grid/chrome/grid-scroll-owner.js +75 -0
  181. package/dist/grid/chrome/grid-styles.d.ts +4 -1
  182. package/dist/grid/chrome/grid-styles.js +1 -0
  183. package/dist/grid/chrome/grid-table-props.d.ts +2 -3
  184. package/dist/grid/chrome/useGridFocus.d.ts +45 -0
  185. package/dist/grid/chrome/useGridFocus.js +122 -0
  186. package/dist/grid/chrome/useGridKeyboard.d.ts +21 -4
  187. package/dist/grid/chrome/useGridKeyboard.js +214 -38
  188. package/dist/grid/chrome/useGridRangeActions.d.ts +3 -1
  189. package/dist/grid/chrome/useGridRangeActions.js +17 -10
  190. package/dist/grid/chrome/useGridRangeGestures.js +68 -21
  191. package/dist/grid/chrome/useGridRowContextMenu.d.ts +4 -2
  192. package/dist/grid/chrome/useGridRowContextMenu.js +28 -2
  193. package/dist/grid/chrome/useGridScaleStyles.d.ts +3 -1
  194. package/dist/grid/chrome/useGridScaleStyles.js +6 -7
  195. package/dist/grid/chrome/useGridScrollArea.d.ts +21 -0
  196. package/dist/grid/chrome/useGridScrollArea.js +65 -0
  197. package/dist/grid/chrome/useGridTableInteractionModel.d.ts +28 -5
  198. package/dist/grid/chrome/useGridTableInteractionModel.js +66 -14
  199. package/dist/grid/chrome/useHeaderDragReorder.d.ts +2 -2
  200. package/dist/grid/core/clipboard-model.d.ts +2 -0
  201. package/dist/grid/core/clipboard-model.js +1 -1
  202. package/dist/grid/core/commit-model.d.ts +7 -0
  203. package/dist/grid/core/edge-scroll.d.ts +21 -0
  204. package/dist/grid/core/edge-scroll.js +23 -0
  205. package/dist/grid/core/editing-controller.d.ts +2 -1
  206. package/dist/grid/core/editing-controller.js +35 -9
  207. package/dist/grid/core/editing-model.d.ts +9 -0
  208. package/dist/grid/core/editing-model.js +12 -0
  209. package/dist/grid/core/flat-rows.d.ts +35 -0
  210. package/dist/grid/core/flat-rows.js +20 -0
  211. package/dist/grid/core/grid-aria.d.ts +27 -0
  212. package/dist/grid/core/grid-aria.js +39 -0
  213. package/dist/grid/core/grid-focus.d.ts +54 -0
  214. package/dist/grid/core/grid-focus.js +148 -0
  215. package/dist/grid/core/nav.d.ts +2 -2
  216. package/dist/grid/core/pending-reconciliation.d.ts +3 -0
  217. package/dist/grid/core/pending-reconciliation.js +5 -3
  218. package/dist/grid/core/row-window.d.ts +40 -0
  219. package/dist/grid/core/row-window.js +43 -0
  220. package/dist/grid/core/spreadsheet-operations.d.ts +17 -1
  221. package/dist/grid/core/spreadsheet-operations.js +33 -6
  222. package/dist/grid/core/useGridEditing.d.ts +3 -0
  223. package/dist/grid/core/useGridEditing.js +6 -3
  224. package/dist/grid/core/value-equality.d.ts +23 -1
  225. package/dist/grid/core/value-equality.js +46 -0
  226. package/dist/grid/useGridTablePrefs.d.ts +0 -1
  227. package/dist/grid/useGridTablePrefs.js +1 -3
  228. package/dist/index.d.ts +1 -0
  229. package/dist/index.js +1 -0
  230. package/dist/internal/viewport.d.ts +0 -2
  231. package/dist/internal/viewport.js +0 -14
  232. package/dist/model/column-capabilities.d.ts +2 -1
  233. package/dist/model/column-capabilities.js +28 -8
  234. package/dist/model/column-from.js +3 -0
  235. package/dist/model/column-inspect.d.ts +10 -2
  236. package/dist/model/column-inspect.js +9 -0
  237. package/dist/model/column-schema.d.ts +6 -1
  238. package/dist/model/column-types.d.ts +3 -1
  239. package/dist/model/column-types.js +1 -1
  240. package/dist/model/preferences.d.ts +0 -4
  241. package/dist/model/preferences.js +0 -1
  242. package/dist/model/prefs-buckets.d.ts +0 -1
  243. package/dist/model/prefs-buckets.js +0 -3
  244. package/dist/model/render-count.d.ts +6 -0
  245. package/dist/model/render-count.js +11 -0
  246. package/dist/provider/ViewsProvider.d.ts +5 -1
  247. package/dist/provider/ViewsProvider.js +9 -3
  248. package/dist/provider/components.d.ts +19 -1
  249. package/dist/provider/components.js +4 -2
  250. package/dist/provider/context.d.ts +5 -2
  251. package/dist/provider/desktop.d.ts +9 -0
  252. package/dist/provider/desktop.js +22 -0
  253. package/dist/provider/plain-input.d.ts +8 -0
  254. package/dist/provider/plain-input.js +5 -0
  255. package/dist/react.d.ts +2 -1
  256. package/dist/react.js +1 -0
  257. package/dist/selection/SelectCheckbox.d.ts +3 -1
  258. package/dist/selection/SelectCheckbox.js +2 -2
  259. package/dist/selection/useCheckDragSelect.js +6 -5
  260. package/docs/contract.md +93 -35
  261. package/docs/guides/atoms.md +1 -1
  262. package/docs/guides/cells.md +2 -2
  263. package/docs/guides/columns.md +3 -2
  264. package/docs/guides/display.md +1 -0
  265. package/docs/guides/editors.md +71 -13
  266. package/docs/guides/the-grid.md +32 -13
  267. package/docs/guides/the-provider.md +3 -1
  268. package/docs/index.md +3 -1
  269. package/docs/install.md +1 -1
  270. package/docs/reference/cells.md +1 -1
  271. package/docs/reference/display.md +3 -1
  272. package/docs/reference/editors-chips.md +2 -2
  273. package/docs/reference/editors-date.md +3 -3
  274. package/docs/reference/editors-location.md +1 -1
  275. package/docs/reference/editors-number.md +1 -1
  276. package/docs/reference/editors-open-values.md +1 -0
  277. package/docs/reference/editors-panel.md +12 -0
  278. package/docs/reference/editors-range.md +1 -1
  279. package/docs/reference/editors-relation.md +6 -3
  280. package/docs/reference/editors-select.md +3 -2
  281. package/docs/reference/editors-session.md +4 -2
  282. package/docs/reference/editors-text.md +9 -0
  283. package/docs/reference/editors-value-list.md +1 -1
  284. package/docs/reference/editors.md +2 -2
  285. package/docs/reference/field-row.md +16 -0
  286. package/docs/reference/grid.md +3 -3
  287. package/docs/reference/react.md +8 -5
  288. package/docs/reference/views.md +36 -15
  289. package/package.json +23 -4
  290. package/skills/views/SKILL.md +4 -4
  291. package/dist/grid/chrome/useGridScrollSync.d.ts +0 -38
  292. package/dist/grid/chrome/useGridScrollSync.js +0 -176
@@ -0,0 +1,122 @@
1
+ "use client";
2
+ import { useCallback, useEffect, useRef, useState } from "react";
3
+ import { GRID_ADD_COLUMN, GRID_RAIL_COLUMN, } from "../core/grid-focus.js";
4
+ const esc = (value) => CSS.escape(value);
5
+ export const GRID_KEY_OWNING_SURFACES = 'input:not([type="checkbox"]), textarea, select, [contenteditable="true"], [role="menu"], [role="dialog"]';
6
+ export function gridFocusElement(root, target) {
7
+ switch (target.kind) {
8
+ case "cell":
9
+ return root.querySelector(`[data-row-id="${esc(target.pos.rowId)}"] [data-col-id="${esc(target.pos.columnId)}"]`);
10
+ case "rail": {
11
+ const row = `[data-row-id="${esc(target.rowKey)}"] [data-slot="vk-grid-rail"]`;
12
+ return root.querySelector(`${row} button, ${row} input`);
13
+ }
14
+ case "head": {
15
+ const head = root.querySelector(`[data-slot="vk-grid-header"][data-group-key="${esc(target.groupKey)}"]`);
16
+ if (!head)
17
+ return null;
18
+ if (target.columnId === GRID_RAIL_COLUMN) {
19
+ return head.querySelector('[data-slot="vk-grid-rail"] button, [data-slot="vk-grid-rail"] input');
20
+ }
21
+ if (target.columnId === GRID_ADD_COLUMN)
22
+ return head.querySelector('[data-slot="vk-grid-tail"] button');
23
+ return head.querySelector(`[data-headcell="${esc(target.columnId)}"]`);
24
+ }
25
+ case "foot": {
26
+ const foot = root.querySelector(`[data-slot="vk-grid-footer"][data-group-key="${esc(target.groupKey)}"]`);
27
+ return foot?.querySelector(`[data-footcell="${esc(target.columnId)}"]`) ?? null;
28
+ }
29
+ case "bar": {
30
+ const group = root.querySelector(`[data-slot="vk-grid-group"][data-group-key="${esc(target.groupKey)}"]`);
31
+ if (!group)
32
+ return null;
33
+ return target.part === "name"
34
+ ? group.querySelector("[data-bar-name]")
35
+ : group.querySelector('[data-slot="vk-grid-group-header"] [aria-haspopup]');
36
+ }
37
+ }
38
+ }
39
+ export function gridFocusOnPress(event, part) {
40
+ if (event.pointerType !== "mouse" || event.button !== 0)
41
+ return;
42
+ const target = event.target;
43
+ if (!target?.closest || target.closest(GRID_KEY_OWNING_SURFACES))
44
+ return;
45
+ const element = target.closest(part);
46
+ if (!element || element.contains(document.activeElement))
47
+ return;
48
+ element.focus({ preventScroll: true });
49
+ }
50
+ export function gridChromeFallback(root, target) {
51
+ if (target.kind === "head" || target.kind === "foot") {
52
+ const slot = target.kind === "head" ? "vk-grid-header" : "vk-grid-footer";
53
+ const attr = target.kind === "head" ? "data-headcell" : "data-footcell";
54
+ const line = root.querySelector(`[data-slot="${slot}"][data-group-key="${esc(target.groupKey)}"]`);
55
+ const first = line?.querySelector(`[${attr}]`)?.getAttribute(attr);
56
+ return first != null ? { kind: target.kind, groupKey: target.groupKey, columnId: first } : null;
57
+ }
58
+ if (target.kind === "bar" && target.part === "menu") {
59
+ const name = { kind: "bar", groupKey: target.groupKey, part: "name" };
60
+ return gridFocusElement(root, name) ? name : null;
61
+ }
62
+ return null;
63
+ }
64
+ function targetKey(target) {
65
+ if (!target)
66
+ return "";
67
+ return target.kind === "cell" ? `cell:${target.pos.rowId}:${target.pos.columnId}` : JSON.stringify(target);
68
+ }
69
+ export function useGridFocus({ rootRef, focusedCell, editingCell, }) {
70
+ const [chrome, setChromeState] = useState(null);
71
+ const target = chrome ?? (focusedCell ? { kind: "cell", pos: focusedCell } : null);
72
+ const key = targetKey(target);
73
+ const lastCellRef = useRef(null);
74
+ useEffect(() => {
75
+ if (!focusedCell)
76
+ return;
77
+ lastCellRef.current = focusedCell;
78
+ setChromeState(null);
79
+ }, [focusedCell]);
80
+ const heldRef = useRef(false);
81
+ const setChrome = useCallback((next) => setChromeState(next), []);
82
+ const releaseToFrame = useCallback(() => {
83
+ rootRef.current?.focus({ preventScroll: true });
84
+ }, [rootRef]);
85
+ useEffect(() => {
86
+ const root = rootRef.current;
87
+ if (!root || !chrome || gridFocusElement(root, chrome))
88
+ return;
89
+ const fallback = gridChromeFallback(root, chrome);
90
+ setChromeState(fallback);
91
+ const active = document.activeElement;
92
+ if (!fallback && (active == null || active === document.body))
93
+ root.focus({ preventScroll: true });
94
+ });
95
+ useEffect(() => {
96
+ const root = rootRef.current;
97
+ const answered = editingCell != null &&
98
+ target?.kind === "cell" &&
99
+ (target.pos.rowId !== editingCell.rowId || target.pos.columnId !== editingCell.columnId);
100
+ if (!root || (editingCell && !answered))
101
+ return;
102
+ const active = document.activeElement;
103
+ const onBody = active == null || active === document.body;
104
+ const free = answered || onBody || (root.contains(active) && !active.closest(GRID_KEY_OWNING_SURFACES));
105
+ if (!target) {
106
+ if (heldRef.current && onBody)
107
+ root.focus({ preventScroll: true });
108
+ else if (free && !onBody && active !== root && active instanceof HTMLElement && !active.closest("[data-grid-guard]"))
109
+ active.blur();
110
+ heldRef.current = false;
111
+ return;
112
+ }
113
+ const element = gridFocusElement(root, target);
114
+ if (element && free && active !== element) {
115
+ element.focus({ preventScroll: true });
116
+ if (target.kind !== "cell")
117
+ element.scrollIntoView?.({ block: "nearest", inline: "nearest" });
118
+ }
119
+ heldRef.current = element != null && document.activeElement === element;
120
+ }, [key, editingCell, rootRef]);
121
+ return { chrome, setChrome, target, releaseToFrame, lastCellRef };
122
+ }
@@ -1,11 +1,28 @@
1
1
  import { type RefObject } from "react";
2
- import type { GridCellPos } from "../core/coordinates.js";
2
+ import { type GridCellPos } from "../core/coordinates.js";
3
3
  import type { GridCellRange } from "../core/useGridRange.js";
4
4
  import type { ListSettingsConfig } from "../../model/column-capabilities.js";
5
5
  import type { ListColumn } from "../../model/column-schema.js";
6
6
  import type { GridRangeVerbs } from "./useGridRangeActions.js";
7
- export declare function useGridKeyboard<Row>({ rootRef, focusedCell, editingCell, editingEnabled, listConfig, visibleRowIds, rowByKey, visibleColIds, visibleColumns, rows, getRowId, pendingByRow, rangeVerbsRef, focusCell, clearFocus, startEdit, cancelEdit, commitEdit, refuseEdit, undo, redo, rangeSetSingle, rangeSetRect, rangeExtendTo, ranges, }: {
7
+ import { type GridChromeTarget, type GridFocusShape } from "../core/grid-focus.js";
8
+ export declare function useGridKeyboard<Row>({ rootRef, focusedCell, editingCell, editingEnabled, listConfig, visibleRowIds, rowByKey, visibleColIds, visibleColumns, rows, getRowId, pendingByRow, rangeVerbsRef, focusCell, clearFocus, startEdit, cancelEdit, commitEdit, refuseEdit, undo, redo, rangeSetRect, rangeExtendTo, ranges, revealCell, releaseToFrame, lastCellRef, chrome, setChrome, shape, toggleGroup, }: {
8
9
  rootRef: RefObject<HTMLDivElement | null>;
10
+ /** A column name, a footer cell, a bar or a checkbox holding the focus (`useGridFocus`); null: a data cell, or
11
+ * nothing. */
12
+ chrome?: GridChromeTarget | null;
13
+ setChrome?: (target: GridChromeTarget | null) => void;
14
+ /** What the keyboard walks beyond the data cells: the sections, their footers and menus, the checkbox lane. None:
15
+ * a grid whose keys stay on its data cells. */
16
+ shape?: GridFocusShape;
17
+ /** Collapse or open a group: a bar's Enter, Space, ← and →. */
18
+ toggleGroup?: (groupKey: string) => void;
19
+ /** Puts real focus on the grid's frame: Escape's let-go (`useGridFocus`). */
20
+ releaseToFrame: () => void;
21
+ /** The last data cell that held the focus: an arrow on the let-go frame comes back in there. */
22
+ lastCellRef: RefObject<GridCellPos | null>;
23
+ /** The grid's one reveal (`grid-scroll-owner.ts`'s `revealGridCell`, with the table's `revealRow`): brings a
24
+ * cell into view whether or not the page holds its row. */
25
+ revealCell: (pos: GridCellPos, behavior: ScrollBehavior) => void;
9
26
  focusedCell: GridCellPos | null;
10
27
  editingCell: GridCellPos | null;
11
28
  editingEnabled: boolean;
@@ -33,15 +50,15 @@ export declare function useGridKeyboard<Row>({ rootRef, focusedCell, editingCell
33
50
  rangeExtendTo: (pos: GridCellPos) => void;
34
51
  /** Live ranges — the last one is active; read for its head. */
35
52
  ranges: GridCellRange[];
36
- startEdit: (rowId: string, columnId: string, seed?: string) => void;
53
+ startEdit: (rowId: string, columnId: string, seed?: string | null, whole?: boolean) => void;
37
54
  cancelEdit: () => void;
38
55
  commitEdit: (row: Row, rowId: string, columnId: string, previous: unknown, next: unknown) => void;
39
56
  /** Say why a cell can't be written; answers whether it said anything. */
40
57
  refuseEdit: (columnId: string) => boolean;
41
58
  undo: (resolveRow: (rowId: string) => Row | undefined, onApply?: (pos: GridCellPos) => void) => boolean;
42
59
  redo: (resolveRow: (rowId: string) => Row | undefined, onApply?: (pos: GridCellPos) => void) => boolean;
43
- rangeSetSingle: (pos: GridCellPos) => void;
44
60
  }): {
45
61
  onEditorTab: (rowId: string, columnId: string, backwards: boolean) => void;
46
62
  onEditorEnter: (rowId: string, columnId: string) => void;
63
+ enterGrid: (_which: "start" | "end", from: Element | null) => void;
47
64
  };
@@ -3,16 +3,21 @@ import { useCallback, useEffect, useRef } from "react";
3
3
  import { useViews } from "../../provider/context.js";
4
4
  import { cellClearPrev, cellEditBaseline } from "../core/clipboard-model.js";
5
5
  import { gridBooleanMode, gridClearRefusal, columnEffectiveWritable, gridColumnHasEditor, } from "../../model/column-capabilities.js";
6
- import { gridColumnInspectable } from "../../model/column-inspect.js";
6
+ import { gridColumnInspectable, isWholeTextColumn } from "../../model/column-inspect.js";
7
+ import { findGridCell, gridCellCutOff } from "./cell-cut-off.js";
8
+ import { gridRowIdFromKey } from "../core/coordinates.js";
7
9
  import { activeRangeHead, gridNavIntent, nextCellLinear, nextCellPos, resolveNavTarget, wholeTableRect, } from "../core/nav.js";
8
10
  import { copyCell } from "./cell-clipboard.js";
11
+ import { GRID_KEY_OWNING_SURFACES, gridFocusElement } from "./useGridFocus.js";
12
+ import { isGridRowMenuKey, openGridRowMenu } from "./grid-row-menu-key.js";
13
+ import { gridBarArrow, gridFocusStep, gridFocusTab, } from "../core/grid-focus.js";
9
14
  const NAV_KEYS = {
10
15
  ArrowUp: "up",
11
16
  ArrowDown: "down",
12
17
  ArrowLeft: "left",
13
18
  ArrowRight: "right",
14
19
  };
15
- const KEY_OWNING_SURFACES = 'input, textarea, select, [contenteditable="true"], [role="menu"], [role="dialog"]';
20
+ const KEY_OWNING_SURFACES = GRID_KEY_OWNING_SURFACES;
16
21
  const INTERACTIVE = 'button, a[href], [role="button"], [tabindex]:not([tabindex="-1"])';
17
22
  function eventBelongsElsewhere(target, root) {
18
23
  if (!target?.closest)
@@ -21,16 +26,13 @@ function eventBelongsElsewhere(target, root) {
21
26
  return true;
22
27
  return !!target.closest(INTERACTIVE) && !root?.contains(target);
23
28
  }
24
- function revealGridCell(root, pos, behavior) {
25
- const row = root?.querySelector(`[data-row-id="${CSS.escape(pos.rowId)}"]`);
26
- const cell = row?.querySelector(`[data-col-id="${CSS.escape(pos.columnId)}"]`) ?? row;
27
- cell?.scrollIntoView({ block: "nearest", inline: "nearest", behavior });
28
- }
29
- export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnabled, listConfig, visibleRowIds, rowByKey, visibleColIds, visibleColumns, rows, getRowId, pendingByRow, rangeVerbsRef, focusCell, clearFocus, startEdit, cancelEdit, commitEdit, refuseEdit, undo, redo, rangeSetSingle, rangeSetRect, rangeExtendTo, ranges, }) {
29
+ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnabled, listConfig, visibleRowIds, rowByKey, visibleColIds, visibleColumns, rows, getRowId, pendingByRow, rangeVerbsRef, focusCell, clearFocus, startEdit, cancelEdit, commitEdit, refuseEdit, undo, redo, rangeSetRect, rangeExtendTo, ranges, revealCell, releaseToFrame, lastCellRef, chrome = null, setChrome = () => { }, shape, toggleGroup, }) {
30
30
  const { ports, messages } = useViews();
31
31
  const navFromEditorRef = useRef({ tab: () => { }, enter: () => { } });
32
32
  const onEditorTab = useCallback((rowId, columnId, backwards) => navFromEditorRef.current.tab(rowId, columnId, backwards), []);
33
33
  const onEditorEnter = useCallback((rowId, columnId) => navFromEditorRef.current.enter(rowId, columnId), []);
34
+ const rowMenuWatchRef = useRef(null);
35
+ useEffect(() => () => rowMenuWatchRef.current?.(), []);
34
36
  useEffect(() => {
35
37
  navFromEditorRef.current = {
36
38
  tab: (rowId, columnId, backwards) => {
@@ -38,23 +40,27 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
38
40
  if (!next)
39
41
  return;
40
42
  focusCell(next.rowId, next.columnId);
41
- revealGridCell(rootRef.current, next, "auto");
43
+ revealCell(next, "auto");
42
44
  },
43
45
  enter: (rowId, columnId) => {
44
46
  const next = nextCellPos({ rowId, columnId }, "down", visibleRowIds, visibleColIds);
45
47
  if (!next)
46
48
  return;
47
49
  focusCell(next.rowId, next.columnId);
48
- revealGridCell(rootRef.current, next, "auto");
50
+ revealCell(next, "auto");
49
51
  },
50
52
  };
51
- }, [focusCell, rootRef, visibleColIds, visibleRowIds]);
53
+ }, [focusCell, revealCell, visibleColIds, visibleRowIds]);
52
54
  useEffect(() => {
53
55
  if (!editingEnabled)
54
56
  return;
55
- const scrollToCell = (pos) => {
56
- rangeSetSingle(pos);
57
- requestAnimationFrame(() => revealGridCell(rootRef.current, pos, "smooth"));
57
+ const scrollToCell = ({ rowId, columnId }) => {
58
+ const key = rowByKey.has(rowId) ? rowId : visibleRowIds.find((k) => gridRowIdFromKey(k) === rowId);
59
+ if (key == null)
60
+ return;
61
+ const pos = { rowId: key, columnId };
62
+ focusCell(key, columnId);
63
+ requestAnimationFrame(() => revealCell(pos, "smooth"));
58
64
  };
59
65
  const onKeyDown = (event) => {
60
66
  if (!(event.metaKey || event.ctrlKey) || event.altKey || event.key.toLowerCase() !== "z") {
@@ -71,11 +77,153 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
71
77
  };
72
78
  window.addEventListener("keydown", onKeyDown, true);
73
79
  return () => window.removeEventListener("keydown", onKeyDown, true);
74
- }, [editingEnabled, getRowId, rangeSetSingle, redo, rootRef, rows, undo]);
80
+ }, [editingEnabled, focusCell, getRowId, redo, revealCell, rootRef, rowByKey, rows, undo, visibleRowIds]);
81
+ const entryCell = useCallback(() => {
82
+ const root = rootRef.current;
83
+ const columnId = visibleColIds[0];
84
+ if (!root || columnId == null)
85
+ return null;
86
+ const visible = new Set(visibleRowIds);
87
+ const top = root.querySelector('[data-slot="vk-grid-scroll"]')?.getBoundingClientRect().top ?? 0;
88
+ let first = null;
89
+ for (const row of root.querySelectorAll('[data-slot="vk-grid-row"]')) {
90
+ const key = row.getAttribute("data-row-id");
91
+ if (key == null || !visible.has(key))
92
+ continue;
93
+ first ??= key;
94
+ if (row.getBoundingClientRect().top >= top) {
95
+ first = key;
96
+ break;
97
+ }
98
+ }
99
+ first ??= visibleRowIds[0] ?? null;
100
+ return first == null ? null : { rowId: first, columnId };
101
+ }, [rootRef, visibleColIds, visibleRowIds]);
102
+ const enterGrid = useCallback((_which, from) => {
103
+ const root = rootRef.current;
104
+ if (!root || (from != null && root.contains(from)))
105
+ return;
106
+ if (focusedCell) {
107
+ revealCell(focusedCell, "auto");
108
+ gridFocusElement(root, { kind: "cell", pos: focusedCell })?.focus({ preventScroll: true });
109
+ return;
110
+ }
111
+ const chromeElement = chrome ? gridFocusElement(root, chrome) : null;
112
+ if (chromeElement) {
113
+ chromeElement.focus({ preventScroll: true });
114
+ return;
115
+ }
116
+ if (chrome)
117
+ setChrome(null);
118
+ const entry = entryCell();
119
+ if (entry) {
120
+ focusCell(entry.rowId, entry.columnId);
121
+ return;
122
+ }
123
+ const head = root.querySelector('[data-slot="vk-grid-header"] [data-headcell]');
124
+ const groupKey = head?.closest('[data-slot="vk-grid-header"]')?.getAttribute("data-group-key");
125
+ const columnId = head?.getAttribute("data-headcell");
126
+ if (groupKey != null && columnId != null)
127
+ setChrome({ kind: "head", groupKey, columnId });
128
+ }, [chrome, entryCell, focusCell, focusedCell, revealCell, rootRef, setChrome]);
75
129
  useEffect(() => {
76
- if (!focusedCell)
130
+ const root = rootRef.current;
131
+ if (!root)
77
132
  return;
78
- const resolveFocused = () => {
133
+ const leave = (backwards) => root.querySelector(`[data-grid-guard="${backwards ? "start" : "end"}"]`)?.focus({ preventScroll: true });
134
+ const onFrameKey = (event) => {
135
+ if (event.target !== root)
136
+ return;
137
+ if (event.key === "Tab" && !event.metaKey && !event.ctrlKey && !event.altKey) {
138
+ leave(event.shiftKey);
139
+ return;
140
+ }
141
+ if (!NAV_KEYS[event.key] || event.metaKey || event.ctrlKey || event.altKey)
142
+ return;
143
+ event.preventDefault();
144
+ const last = lastCellRef.current;
145
+ const back = last && visibleRowIds.includes(last.rowId) && visibleColIds.includes(last.columnId) ? last : entryCell();
146
+ if (!back)
147
+ return;
148
+ focusCell(back.rowId, back.columnId);
149
+ revealCell(back, "auto");
150
+ };
151
+ const moveTo = (next) => {
152
+ if (next.kind === "cell") {
153
+ setChrome(null);
154
+ focusCell(next.pos.rowId, next.pos.columnId);
155
+ revealCell(next.pos, "auto");
156
+ return;
157
+ }
158
+ if (focusedCell)
159
+ clearFocus();
160
+ setChrome(next);
161
+ };
162
+ const onChromeKey = (event, at) => {
163
+ if (!shape)
164
+ return;
165
+ const plain = !event.metaKey && !event.ctrlKey && !event.altKey;
166
+ if (event.key === "Escape") {
167
+ event.stopPropagation();
168
+ setChrome(null);
169
+ releaseToFrame();
170
+ return;
171
+ }
172
+ if (event.key === "Tab" && plain) {
173
+ const next = gridFocusTab(at, event.shiftKey, shape);
174
+ if (!next) {
175
+ setChrome(null);
176
+ leave(event.shiftKey);
177
+ return;
178
+ }
179
+ event.preventDefault();
180
+ moveTo(next);
181
+ return;
182
+ }
183
+ const dir = NAV_KEYS[event.key];
184
+ if (dir && plain && !event.shiftKey) {
185
+ event.preventDefault();
186
+ if (at.kind === "bar" && at.part === "name" && (dir === "left" || dir === "right")) {
187
+ const section = shape.sections.find((s) => s.groupKey === at.groupKey);
188
+ const move = gridBarArrow(section?.collapsed ?? false, dir, section?.menu ?? false);
189
+ if (move === "collapse" || move === "open") {
190
+ toggleGroup?.(at.groupKey);
191
+ return;
192
+ }
193
+ if (move === "none")
194
+ return;
195
+ }
196
+ const next = gridFocusStep(at, dir, shape);
197
+ if (next)
198
+ moveTo(next);
199
+ return;
200
+ }
201
+ if ((event.key === "Enter" || event.key === " ") && plain && !event.shiftKey) {
202
+ event.preventDefault();
203
+ if (at.kind === "bar" && at.part === "name") {
204
+ toggleGroup?.(at.groupKey);
205
+ return;
206
+ }
207
+ gridFocusElement(root, at)?.click();
208
+ }
209
+ };
210
+ const onKeyDown = (event) => {
211
+ const target = event.target;
212
+ if (target?.closest?.(KEY_OWNING_SURFACES))
213
+ return;
214
+ if (chrome) {
215
+ onChromeKey(event, chrome);
216
+ return;
217
+ }
218
+ if (!focusedCell) {
219
+ onFrameKey(event);
220
+ return;
221
+ }
222
+ if (target !== root && !target?.closest?.('[data-slot="vk-grid-cell"]'))
223
+ return;
224
+ handleCellKey(event, focusedCell, leave);
225
+ };
226
+ const resolveFocusedAt = (focusedCell) => {
79
227
  const entry = rowByKey.get(focusedCell.rowId);
80
228
  return {
81
229
  column: visibleColumns.find((column) => column.id === focusedCell.columnId),
@@ -83,27 +231,43 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
83
231
  rowId: entry?.rowId ?? focusedCell.rowId,
84
232
  };
85
233
  };
86
- const onKeyDown = (event) => {
87
- if (eventBelongsElsewhere(event.target, rootRef.current))
88
- return;
234
+ function handleCellKey(event, focusedCell, leave) {
235
+ const resolveFocused = () => resolveFocusedAt(focusedCell);
89
236
  const mod = (event.metaKey || event.ctrlKey) && !event.shiftKey && !event.altKey;
90
237
  const bare = !event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey;
91
238
  const navDirection = NAV_KEYS[event.key];
92
239
  const navIntent = gridNavIntent(event);
240
+ rowMenuWatchRef.current?.();
241
+ rowMenuWatchRef.current = null;
242
+ if (isGridRowMenuKey(event) && !editingCell) {
243
+ event.preventDefault();
244
+ const cell = root ? gridFocusElement(root, { kind: "cell", pos: focusedCell }) : null;
245
+ if (cell)
246
+ rowMenuWatchRef.current = openGridRowMenu(cell);
247
+ return;
248
+ }
93
249
  if (event.key === "Escape") {
94
250
  event.stopPropagation();
95
251
  if (editingCell)
96
252
  cancelEdit();
97
- else
253
+ else {
98
254
  clearFocus();
255
+ releaseToFrame();
256
+ }
99
257
  }
100
258
  else if (navDirection && bare && !editingCell) {
101
259
  event.preventDefault();
260
+ if (shape && navDirection !== "right") {
261
+ const step = gridFocusStep({ kind: "cell", pos: focusedCell }, navDirection, shape);
262
+ if (step)
263
+ moveTo(step);
264
+ return;
265
+ }
102
266
  const next = nextCellPos(focusedCell, navDirection, visibleRowIds, visibleColIds);
103
267
  if (!next)
104
268
  return;
105
269
  focusCell(next.rowId, next.columnId);
106
- revealGridCell(rootRef.current, next, "auto");
270
+ revealCell(next, "auto");
107
271
  }
108
272
  else if (navIntent && !editingCell) {
109
273
  event.preventDefault();
@@ -128,24 +292,31 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
128
292
  rangeExtendTo(next);
129
293
  else
130
294
  rangeSetRect(focusedCell, next);
131
- revealGridCell(rootRef.current, next, "auto");
295
+ revealCell(next, "auto");
132
296
  }
133
297
  else if (event.key === "Tab" && !event.metaKey && !event.ctrlKey && !event.altKey) {
134
- event.preventDefault();
135
- if (editingCell)
298
+ if (editingCell) {
299
+ event.preventDefault();
136
300
  return;
301
+ }
137
302
  const next = nextCellLinear(focusedCell, event.shiftKey, visibleRowIds, visibleColIds);
138
- if (!next)
303
+ if (!next) {
304
+ leave(event.shiftKey);
139
305
  return;
306
+ }
307
+ event.preventDefault();
140
308
  focusCell(next.rowId, next.columnId);
141
- revealGridCell(rootRef.current, next, "auto");
309
+ revealCell(next, "auto");
142
310
  }
143
311
  else if (event.key === "Enter" && !editingCell) {
144
312
  const column = visibleColumns.find((item) => item.id === focusedCell.columnId);
145
313
  event.preventDefault();
314
+ const whole = column != null &&
315
+ isWholeTextColumn(column) &&
316
+ gridCellCutOff(findGridCell(rootRef.current, focusedCell));
146
317
  if (column &&
147
- ((editingEnabled && gridColumnHasEditor(column)) || gridColumnInspectable(column))) {
148
- startEdit(focusedCell.rowId, focusedCell.columnId);
318
+ ((editingEnabled && gridColumnHasEditor(column)) || gridColumnInspectable(column) || whole)) {
319
+ startEdit(focusedCell.rowId, focusedCell.columnId, undefined, whole);
149
320
  return;
150
321
  }
151
322
  if (column &&
@@ -163,7 +334,7 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
163
334
  if (!next)
164
335
  return;
165
336
  focusCell(next.rowId, next.columnId);
166
- revealGridCell(rootRef.current, next, "auto");
337
+ revealCell(next, "auto");
167
338
  }
168
339
  else if (mod && event.key.toLowerCase() === "c" && !editingCell) {
169
340
  event.preventDefault();
@@ -234,26 +405,27 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
234
405
  if (!gridColumnHasEditor(column))
235
406
  return;
236
407
  event.preventDefault();
237
- const seedable = column.type !== "select" &&
238
- column.type !== "status" &&
239
- column.type !== "date" &&
240
- column.type !== "multiselect" &&
408
+ const seedable = column.type !== "multiselect" &&
241
409
  !column.multiple;
242
410
  startEdit(focusedCell.rowId, focusedCell.columnId, seedable ? event.key : undefined);
243
411
  }
244
- };
245
- window.addEventListener("keydown", onKeyDown, true);
246
- return () => window.removeEventListener("keydown", onKeyDown, true);
412
+ }
413
+ root.addEventListener("keydown", onKeyDown);
414
+ return () => root.removeEventListener("keydown", onKeyDown);
247
415
  }, [
248
416
  cancelEdit,
417
+ chrome,
249
418
  clearFocus,
250
419
  commitEdit,
251
420
  editingCell,
252
421
  editingEnabled,
422
+ entryCell,
253
423
  focusCell,
254
424
  focusedCell,
255
425
  getRowId,
426
+ lastCellRef,
256
427
  listConfig,
428
+ releaseToFrame,
257
429
  messages,
258
430
  pendingByRow,
259
431
  ports,
@@ -263,12 +435,16 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
263
435
  ranges,
264
436
  rangeSetRect,
265
437
  rangeExtendTo,
438
+ revealCell,
266
439
  rootRef,
267
440
  rows,
441
+ setChrome,
442
+ shape,
268
443
  startEdit,
444
+ toggleGroup,
269
445
  visibleColIds,
270
446
  visibleColumns,
271
447
  visibleRowIds,
272
448
  ]);
273
- return { onEditorTab, onEditorEnter };
449
+ return { onEditorTab, onEditorEnter, enterGrid };
274
450
  }
@@ -18,7 +18,7 @@ export type GridRangeVerbs = {
18
18
  activeRangeHasClearable: () => boolean;
19
19
  cellInActiveRange: (rowId: string, columnId: string) => boolean;
20
20
  };
21
- export declare function useGridRangeActions<Row>({ ranges, focusedCell, editingCell, editingEnabled, fillTargetRow, visibleRowIds, visibleColumns, spreadsheetModel, commitBatch, focusCell, rangeSetRect, rangeExtendTo, }: {
21
+ export declare function useGridRangeActions<Row>({ ranges, focusedCell, editingCell, editingEnabled, fillTargetRow, visibleRowIds, visibleColumns, spreadsheetModel, commitBatch, focusCell, rangeSetRect, rangeExtendTo, revealCell, }: {
22
22
  ranges: GridCellRange[];
23
23
  focusedCell: GridCellPos | null;
24
24
  editingCell: GridCellPos | null;
@@ -33,6 +33,8 @@ export declare function useGridRangeActions<Row>({ ranges, focusedCell, editingC
33
33
  focusCell: (rowId: string, columnId: string) => void;
34
34
  rangeSetRect: (anchor: GridCellPos, head: GridCellPos) => void;
35
35
  rangeExtendTo: (pos: GridCellPos, fallbackAnchor?: GridCellPos) => void;
36
+ /** The grid's one reveal: a paste brings where it landed into view, drawn or not. */
37
+ revealCell: (pos: GridCellPos, behavior: ScrollBehavior) => void;
36
38
  }): {
37
39
  visibleColIds: string[];
38
40
  rowSpansMap: Map<string, import("../core/range-model.js").GridRowRangeSpan[]>;
@@ -7,8 +7,8 @@ import { resolveActiveRangeRect } from "../core/range-model.js";
7
7
  import { deriveGridSelectValues } from "../core/column-values.js";
8
8
  import { buildGridCopyMatrix, extendGridFillPreview, gridRectHasClearable, planGridClear, planGridFill, planGridPaste, } from "../core/spreadsheet-operations.js";
9
9
  import { copyCells, getGridClipboard, parseTsvText } from "./cell-clipboard.js";
10
- export function useGridRangeActions({ ranges, focusedCell, editingCell, editingEnabled, fillTargetRow, visibleRowIds, visibleColumns, spreadsheetModel, commitBatch, focusCell, rangeSetRect, rangeExtendTo, }) {
11
- const { ports, messages } = useViews();
10
+ export function useGridRangeActions({ ranges, focusedCell, editingCell, editingEnabled, fillTargetRow, visibleRowIds, visibleColumns, spreadsheetModel, commitBatch, focusCell, rangeSetRect, rangeExtendTo, revealCell, }) {
11
+ const { ports, messages, conventions } = useViews();
12
12
  const visibleColIds = useMemo(() => visibleColumns.map((col) => col.id), [visibleColumns]);
13
13
  const spanRanges = useMemo(() => extendGridFillPreview(ranges, fillTargetRow, visibleRowIds, visibleColIds), [fillTargetRow, ranges, visibleColIds, visibleRowIds]);
14
14
  const rowSpansMap = useMemo(() => computeRowRangeSpans(spanRanges, visibleRowIds, visibleColIds), [spanRanges, visibleColIds, visibleRowIds]);
@@ -58,24 +58,28 @@ export function useGridRangeActions({ ranges, focusedCell, editingCell, editingE
58
58
  const rect = rectOfActiveRange();
59
59
  return !!rect && gridRectHasClearable(visibleColumns, rect);
60
60
  };
61
- const clearRange = () => {
61
+ const clearRange = (quiet = false) => {
62
62
  if (!editingEnabled)
63
63
  return;
64
64
  const rect = rectOfActiveRange();
65
65
  if (!rect)
66
66
  return;
67
- if (!activeRangeHasClearable()) {
67
+ const plan = planGridClear(spreadsheetModel, rect);
68
+ if (plan.edits.length > 0)
69
+ commitBatch(plan.edits);
70
+ for (const { reason } of plan.refusals)
71
+ ports.toast.error(reason);
72
+ if (plan.required.length > 0) {
73
+ const fields = new Intl.ListFormat(conventions.locale, { type: "conjunction" }).format(plan.required);
74
+ ports.toast.error(messages({ key: "views.grid.clear-required", values: { fields } }));
75
+ }
76
+ else if (!quiet && plan.edits.length === 0 && plan.refusals.length === 0 && !activeRangeHasClearable()) {
68
77
  ports.toast.error(messages({ key: "views.grid.clear-none" }));
69
- return;
70
78
  }
71
- const edits = planGridClear(spreadsheetModel, rect);
72
- if (edits.length > 0)
73
- commitBatch(edits);
74
79
  };
75
80
  const cutRange = () => {
76
81
  copyRange();
77
- if (activeRangeHasClearable())
78
- clearRange();
82
+ clearRange(true);
79
83
  };
80
84
  const pasteMatrix = (matrix, anchor) => {
81
85
  if (!editingEnabled)
@@ -86,6 +90,7 @@ export function useGridRangeActions({ ranges, focusedCell, editingCell, editingE
86
90
  if (plan.selection) {
87
91
  focusCell(plan.selection.anchor.rowId, plan.selection.anchor.columnId);
88
92
  rangeSetRect(plan.selection.anchor, plan.selection.head);
93
+ revealCell(plan.selection.anchor, "auto");
89
94
  }
90
95
  }
91
96
  sayRefusals("paste", plan);
@@ -118,6 +123,7 @@ export function useGridRangeActions({ ranges, focusedCell, editingCell, editingE
118
123
  };
119
124
  }, [
120
125
  commitBatch,
126
+ conventions,
121
127
  editingEnabled,
122
128
  focusCell,
123
129
  focusedCell,
@@ -125,6 +131,7 @@ export function useGridRangeActions({ ranges, focusedCell, editingCell, editingE
125
131
  ports,
126
132
  rangeSetRect,
127
133
  ranges,
134
+ revealCell,
128
135
  sayRefusals,
129
136
  selectValuesByColumn,
130
137
  spreadsheetModel,