@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.
- package/CHANGELOG.md +571 -0
- package/README.md +5 -3
- package/dist/atoms/LoadMore.js +11 -1
- package/dist/atoms/RowMenu.js +5 -2
- package/dist/cells/cell-format.d.ts +3 -3
- package/dist/cells/cell-title.d.ts +1 -2
- package/dist/cells/cell-title.js +2 -2
- package/dist/cells/cell-values.js +6 -3
- package/dist/contract.d.ts +50 -9
- package/dist/contract.js +33 -5
- package/dist/display/converted.d.ts +19 -0
- package/dist/display/converted.js +12 -0
- package/dist/display/index.d.ts +1 -0
- package/dist/display/index.js +1 -0
- package/dist/display/link-click.d.ts +11 -0
- package/dist/display/link-click.js +3 -0
- package/dist/display/link.js +7 -3
- package/dist/display/multi-value.d.ts +1 -1
- package/dist/display/multi-value.js +1 -1
- package/dist/display/options.d.ts +7 -1
- package/dist/display/phone.js +3 -1
- package/dist/editors/ChipsEditor.d.ts +9 -4
- package/dist/editors/ChipsEditor.js +6 -2
- package/dist/editors/DateEditor.d.ts +21 -6
- package/dist/editors/DateEditor.js +118 -30
- package/dist/editors/EditorPanel.d.ts +61 -0
- package/dist/editors/EditorPanel.js +54 -0
- package/dist/editors/LocationEditor.d.ts +3 -0
- package/dist/editors/LocationEditor.js +14 -6
- package/dist/editors/NameEditor.d.ts +3 -0
- package/dist/editors/NameEditor.js +11 -7
- package/dist/editors/NumberEditor.d.ts +3 -0
- package/dist/editors/NumberEditor.js +6 -6
- package/dist/editors/RangeEditor.d.ts +16 -1
- package/dist/editors/RangeEditor.js +21 -5
- package/dist/editors/RelationEditor.d.ts +13 -28
- package/dist/editors/RelationEditor.js +17 -40
- package/dist/editors/RelationSetEditor.d.ts +53 -0
- package/dist/editors/RelationSetEditor.js +112 -0
- package/dist/editors/SelectEditor.d.ts +21 -3
- package/dist/editors/SelectEditor.js +55 -9
- package/dist/editors/TextEditor.d.ts +51 -0
- package/dist/editors/TextEditor.js +81 -0
- package/dist/editors/ValueListEditor.d.ts +3 -0
- package/dist/editors/ValueListEditor.js +4 -2
- package/dist/editors/edit-cores.d.ts +12 -9
- package/dist/editors/edit-cores.js +7 -6
- package/dist/editors/edit-session.d.ts +21 -11
- package/dist/editors/edit-session.js +19 -5
- package/dist/editors/keep-inside.d.ts +12 -0
- package/dist/editors/keep-inside.js +20 -0
- package/dist/editors/open-value.d.ts +21 -0
- package/dist/editors/open-value.js +36 -0
- package/dist/editors/open-values.d.ts +4 -0
- package/dist/editors/open-values.js +7 -0
- package/dist/editors/relation-kinds.d.ts +7 -0
- package/dist/editors/relation-kinds.js +21 -0
- package/dist/editors/relation-panel.d.ts +69 -0
- package/dist/editors/relation-panel.js +40 -0
- package/dist/field-row/FieldNoteLine.d.ts +14 -0
- package/dist/field-row/FieldNoteLine.js +14 -0
- package/dist/field-row/FieldRow.d.ts +73 -0
- package/dist/field-row/FieldRow.js +157 -0
- package/dist/field-row/FieldRowLane.d.ts +19 -0
- package/dist/field-row/FieldRowLane.js +11 -0
- package/dist/field-row/editors/RowChipsEditor.d.ts +11 -0
- package/dist/field-row/editors/RowChipsEditor.js +25 -0
- package/dist/field-row/editors/RowDateEditor.d.ts +16 -0
- package/dist/field-row/editors/RowDateEditor.js +18 -0
- package/dist/field-row/editors/RowEditor.d.ts +39 -0
- package/dist/field-row/editors/RowEditor.js +64 -0
- package/dist/field-row/editors/RowNameEditor.d.ts +4 -0
- package/dist/field-row/editors/RowNameEditor.js +15 -0
- package/dist/field-row/editors/RowNumberEditor.d.ts +12 -0
- package/dist/field-row/editors/RowNumberEditor.js +18 -0
- package/dist/field-row/editors/RowPlaceEditor.d.ts +8 -0
- package/dist/field-row/editors/RowPlaceEditor.js +18 -0
- package/dist/field-row/editors/RowRangeEditor.d.ts +4 -0
- package/dist/field-row/editors/RowRangeEditor.js +15 -0
- package/dist/field-row/editors/RowRelationEditor.d.ts +20 -0
- package/dist/field-row/editors/RowRelationEditor.js +77 -0
- package/dist/field-row/editors/RowSelectEditor.d.ts +13 -0
- package/dist/field-row/editors/RowSelectEditor.js +23 -0
- package/dist/field-row/editors/RowTextEditor.d.ts +15 -0
- package/dist/field-row/editors/RowTextEditor.js +16 -0
- package/dist/field-row/editors/RowValueListEditor.d.ts +4 -0
- package/dist/field-row/editors/RowValueListEditor.js +21 -0
- package/dist/field-row/editors/host.d.ts +59 -0
- package/dist/field-row/editors/host.js +1 -0
- package/dist/field-row/editors/row-session.d.ts +49 -0
- package/dist/field-row/editors/row-session.js +49 -0
- package/dist/field-row/index.d.ts +5 -0
- package/dist/field-row/index.js +5 -0
- package/dist/field-row/row-target.d.ts +20 -0
- package/dist/field-row/row-target.js +3 -0
- package/dist/field-row/useFieldWrite.d.ts +45 -0
- package/dist/field-row/useFieldWrite.js +190 -0
- package/dist/field-row/useRowSettlement.d.ts +33 -0
- package/dist/field-row/useRowSettlement.js +23 -0
- package/dist/fields/binding.d.ts +6 -1
- package/dist/fields/binding.js +13 -6
- package/dist/fields/edit-core-types.d.ts +9 -9
- package/dist/fields/edit-core-types.js +6 -6
- package/dist/fields/money.d.ts +5 -0
- package/dist/fields/money.js +10 -0
- package/dist/fields/number-edit.d.ts +6 -0
- package/dist/fields/number-edit.js +4 -0
- package/dist/fields/prepare-write.js +6 -1
- package/dist/fields/relation-source-types.d.ts +12 -0
- package/dist/fields/write-target.d.ts +50 -0
- package/dist/fields/write-target.js +10 -0
- package/dist/grid/chrome/GridAddColumn.js +1 -1
- package/dist/grid/chrome/GridAggregateMenu.d.ts +1 -1
- package/dist/grid/chrome/GridAggregateMenu.js +8 -6
- package/dist/grid/chrome/GridCellEditors.d.ts +7 -0
- package/dist/grid/chrome/GridCellEditors.js +87 -16
- package/dist/grid/chrome/GridCellOutline.d.ts +22 -43
- package/dist/grid/chrome/GridCellOutline.js +2 -7
- package/dist/grid/chrome/GridChipsEditor.d.ts +16 -6
- package/dist/grid/chrome/GridChipsEditor.js +21 -26
- package/dist/grid/chrome/GridColumnMenu.d.ts +1 -1
- package/dist/grid/chrome/GridColumnMenu.js +7 -3
- package/dist/grid/chrome/GridDateEditor.d.ts +23 -11
- package/dist/grid/chrome/GridDateEditor.js +13 -25
- package/dist/grid/chrome/GridFooter.d.ts +12 -2
- package/dist/grid/chrome/GridFooter.js +10 -6
- package/dist/grid/chrome/GridGroupMenu.js +20 -13
- package/dist/grid/chrome/GridHeader.d.ts +9 -4
- package/dist/grid/chrome/GridHeader.js +15 -10
- package/dist/grid/chrome/GridLongTextEditor.d.ts +28 -9
- package/dist/grid/chrome/GridLongTextEditor.js +16 -74
- package/dist/grid/chrome/GridNameEditor.d.ts +11 -6
- package/dist/grid/chrome/GridNameEditor.js +12 -27
- package/dist/grid/chrome/GridNumberEditor.d.ts +20 -6
- package/dist/grid/chrome/GridNumberEditor.js +46 -20
- package/dist/grid/chrome/GridPlaceEditor.d.ts +26 -0
- package/dist/grid/chrome/GridPlaceEditor.js +22 -0
- package/dist/grid/chrome/GridRangeEditor.d.ts +15 -5
- package/dist/grid/chrome/GridRangeEditor.js +16 -20
- package/dist/grid/chrome/GridRelationEditor.d.ts +38 -14
- package/dist/grid/chrome/GridRelationEditor.js +86 -24
- package/dist/grid/chrome/GridRow.d.ts +7 -1
- package/dist/grid/chrome/GridRow.js +57 -14
- package/dist/grid/chrome/GridRowActions.js +1 -1
- package/dist/grid/chrome/GridRowCells.js +18 -23
- package/dist/grid/chrome/GridSelectEditor.d.ts +19 -4
- package/dist/grid/chrome/GridSelectEditor.js +21 -27
- package/dist/grid/chrome/GridStructure.d.ts +9 -10
- package/dist/grid/chrome/GridStructure.js +10 -14
- package/dist/grid/chrome/GridTable.js +97 -30
- package/dist/grid/chrome/GridTableSurface.d.ts +39 -2
- package/dist/grid/chrome/GridTableSurface.js +12 -3
- package/dist/grid/chrome/GridTextEditor.d.ts +35 -1
- package/dist/grid/chrome/GridTextEditor.js +35 -37
- package/dist/grid/chrome/GridValueListEditor.d.ts +15 -3
- package/dist/grid/chrome/GridValueListEditor.js +10 -27
- package/dist/grid/chrome/cell-cut-off.d.ts +11 -0
- package/dist/grid/chrome/cell-cut-off.js +20 -0
- package/dist/grid/chrome/cells.js +1 -2
- package/dist/grid/chrome/checks.d.ts +2 -5
- package/dist/grid/chrome/checks.js +15 -5
- package/dist/grid/chrome/editors.d.ts +1 -1
- package/dist/grid/chrome/editors.js +1 -1
- package/dist/grid/chrome/grid-cell-classes.d.ts +2 -8
- package/dist/grid/chrome/grid-cell-classes.js +10 -8
- package/dist/grid/chrome/grid-cell-link.d.ts +13 -0
- package/dist/grid/chrome/grid-cell-link.js +9 -0
- package/dist/grid/chrome/grid-edit-session.d.ts +63 -0
- package/dist/grid/chrome/grid-edit-session.js +118 -0
- package/dist/grid/chrome/grid-hover.d.ts +60 -0
- package/dist/grid/chrome/grid-hover.js +81 -0
- package/dist/grid/chrome/grid-menu-focus.d.ts +43 -0
- package/dist/grid/chrome/grid-menu-focus.js +93 -0
- package/dist/grid/chrome/grid-row-menu-key.d.ts +15 -0
- package/dist/grid/chrome/grid-row-menu-key.js +36 -0
- package/dist/grid/chrome/grid-row-props.d.ts +16 -4
- package/dist/grid/chrome/grid-row-window.d.ts +61 -0
- package/dist/grid/chrome/grid-row-window.js +212 -0
- package/dist/grid/chrome/grid-scroll-owner.d.ts +38 -0
- package/dist/grid/chrome/grid-scroll-owner.js +75 -0
- package/dist/grid/chrome/grid-styles.d.ts +4 -1
- package/dist/grid/chrome/grid-styles.js +1 -0
- package/dist/grid/chrome/grid-table-props.d.ts +2 -3
- package/dist/grid/chrome/useGridFocus.d.ts +45 -0
- package/dist/grid/chrome/useGridFocus.js +122 -0
- package/dist/grid/chrome/useGridKeyboard.d.ts +21 -4
- package/dist/grid/chrome/useGridKeyboard.js +214 -38
- package/dist/grid/chrome/useGridRangeActions.d.ts +3 -1
- package/dist/grid/chrome/useGridRangeActions.js +17 -10
- package/dist/grid/chrome/useGridRangeGestures.js +68 -21
- package/dist/grid/chrome/useGridRowContextMenu.d.ts +4 -2
- package/dist/grid/chrome/useGridRowContextMenu.js +28 -2
- package/dist/grid/chrome/useGridScaleStyles.d.ts +3 -1
- package/dist/grid/chrome/useGridScaleStyles.js +6 -7
- package/dist/grid/chrome/useGridScrollArea.d.ts +21 -0
- package/dist/grid/chrome/useGridScrollArea.js +65 -0
- package/dist/grid/chrome/useGridTableInteractionModel.d.ts +28 -5
- package/dist/grid/chrome/useGridTableInteractionModel.js +66 -14
- package/dist/grid/chrome/useHeaderDragReorder.d.ts +2 -2
- package/dist/grid/core/clipboard-model.d.ts +2 -0
- package/dist/grid/core/clipboard-model.js +1 -1
- package/dist/grid/core/commit-model.d.ts +7 -0
- package/dist/grid/core/edge-scroll.d.ts +21 -0
- package/dist/grid/core/edge-scroll.js +23 -0
- package/dist/grid/core/editing-controller.d.ts +2 -1
- package/dist/grid/core/editing-controller.js +35 -9
- package/dist/grid/core/editing-model.d.ts +9 -0
- package/dist/grid/core/editing-model.js +12 -0
- package/dist/grid/core/flat-rows.d.ts +35 -0
- package/dist/grid/core/flat-rows.js +20 -0
- package/dist/grid/core/grid-aria.d.ts +27 -0
- package/dist/grid/core/grid-aria.js +39 -0
- package/dist/grid/core/grid-focus.d.ts +54 -0
- package/dist/grid/core/grid-focus.js +148 -0
- package/dist/grid/core/nav.d.ts +2 -2
- package/dist/grid/core/pending-reconciliation.d.ts +3 -0
- package/dist/grid/core/pending-reconciliation.js +5 -3
- package/dist/grid/core/row-window.d.ts +40 -0
- package/dist/grid/core/row-window.js +43 -0
- package/dist/grid/core/spreadsheet-operations.d.ts +17 -1
- package/dist/grid/core/spreadsheet-operations.js +33 -6
- package/dist/grid/core/useGridEditing.d.ts +3 -0
- package/dist/grid/core/useGridEditing.js +6 -3
- package/dist/grid/core/value-equality.d.ts +23 -1
- package/dist/grid/core/value-equality.js +46 -0
- package/dist/grid/useGridTablePrefs.d.ts +0 -1
- package/dist/grid/useGridTablePrefs.js +1 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/internal/viewport.d.ts +0 -2
- package/dist/internal/viewport.js +0 -14
- package/dist/model/column-capabilities.d.ts +2 -1
- package/dist/model/column-capabilities.js +28 -8
- package/dist/model/column-from.js +3 -0
- package/dist/model/column-inspect.d.ts +10 -2
- package/dist/model/column-inspect.js +9 -0
- package/dist/model/column-schema.d.ts +6 -1
- package/dist/model/column-types.d.ts +3 -1
- package/dist/model/column-types.js +1 -1
- package/dist/model/preferences.d.ts +0 -4
- package/dist/model/preferences.js +0 -1
- package/dist/model/prefs-buckets.d.ts +0 -1
- package/dist/model/prefs-buckets.js +0 -3
- package/dist/model/render-count.d.ts +6 -0
- package/dist/model/render-count.js +11 -0
- package/dist/provider/ViewsProvider.d.ts +5 -1
- package/dist/provider/ViewsProvider.js +9 -3
- package/dist/provider/components.d.ts +19 -1
- package/dist/provider/components.js +4 -2
- package/dist/provider/context.d.ts +5 -2
- package/dist/provider/desktop.d.ts +9 -0
- package/dist/provider/desktop.js +22 -0
- package/dist/provider/plain-input.d.ts +8 -0
- package/dist/provider/plain-input.js +5 -0
- package/dist/react.d.ts +2 -1
- package/dist/react.js +1 -0
- package/dist/selection/SelectCheckbox.d.ts +3 -1
- package/dist/selection/SelectCheckbox.js +2 -2
- package/dist/selection/useCheckDragSelect.js +6 -5
- package/docs/contract.md +93 -35
- package/docs/guides/atoms.md +1 -1
- package/docs/guides/cells.md +2 -2
- package/docs/guides/columns.md +3 -2
- package/docs/guides/display.md +1 -0
- package/docs/guides/editors.md +71 -13
- package/docs/guides/the-grid.md +32 -13
- package/docs/guides/the-provider.md +3 -1
- package/docs/index.md +3 -1
- package/docs/install.md +1 -1
- package/docs/reference/cells.md +1 -1
- package/docs/reference/display.md +3 -1
- package/docs/reference/editors-chips.md +2 -2
- package/docs/reference/editors-date.md +3 -3
- package/docs/reference/editors-location.md +1 -1
- package/docs/reference/editors-number.md +1 -1
- package/docs/reference/editors-open-values.md +1 -0
- package/docs/reference/editors-panel.md +12 -0
- package/docs/reference/editors-range.md +1 -1
- package/docs/reference/editors-relation.md +6 -3
- package/docs/reference/editors-select.md +3 -2
- package/docs/reference/editors-session.md +4 -2
- package/docs/reference/editors-text.md +9 -0
- package/docs/reference/editors-value-list.md +1 -1
- package/docs/reference/editors.md +2 -2
- package/docs/reference/field-row.md +16 -0
- package/docs/reference/grid.md +3 -3
- package/docs/reference/react.md +8 -5
- package/docs/reference/views.md +36 -15
- package/package.json +23 -4
- package/skills/views/SKILL.md +4 -4
- package/dist/grid/chrome/useGridScrollSync.d.ts +0 -38
- 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
|
|
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
|
-
|
|
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 =
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
50
|
+
revealCell(next, "auto");
|
|
49
51
|
},
|
|
50
52
|
};
|
|
51
|
-
}, [focusCell,
|
|
53
|
+
}, [focusCell, revealCell, visibleColIds, visibleRowIds]);
|
|
52
54
|
useEffect(() => {
|
|
53
55
|
if (!editingEnabled)
|
|
54
56
|
return;
|
|
55
|
-
const scrollToCell = (
|
|
56
|
-
|
|
57
|
-
|
|
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,
|
|
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
|
-
|
|
130
|
+
const root = rootRef.current;
|
|
131
|
+
if (!root)
|
|
77
132
|
return;
|
|
78
|
-
const
|
|
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
|
-
|
|
87
|
-
|
|
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
|
-
|
|
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
|
-
|
|
295
|
+
revealCell(next, "auto");
|
|
132
296
|
}
|
|
133
297
|
else if (event.key === "Tab" && !event.metaKey && !event.ctrlKey && !event.altKey) {
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 !== "
|
|
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
|
-
|
|
246
|
-
return () =>
|
|
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
|
-
|
|
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
|
-
|
|
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,
|