viewkitjs 0.37.0 → 0.38.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 (56) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/package.json +1 -1
  3. package/views/dist/contract.d.ts +6 -3
  4. package/views/dist/contract.js +4 -0
  5. package/views/dist/controls/field/looks.d.ts +1 -1
  6. package/views/dist/controls/field/looks.js +5 -3
  7. package/views/dist/controls/field.css +60 -1
  8. package/views/dist/controls/glyphs/glyphs.js +2 -0
  9. package/views/dist/controls/inline-input.css +3 -2
  10. package/views/dist/controls/internal/read-token.d.ts +2 -1
  11. package/views/dist/controls/internal/read-token.js +2 -1
  12. package/views/dist/controls/number-editor/tokens.d.ts +8 -0
  13. package/views/dist/controls/number-editor/tokens.js +2 -0
  14. package/views/dist/controls/number-editor.css +20 -0
  15. package/views/dist/controls/text-editor/tokens.d.ts +8 -0
  16. package/views/dist/controls/text-editor/tokens.js +2 -0
  17. package/views/dist/controls/text-editor.css +24 -2
  18. package/views/dist/controls/tooltip/tooltip.js +2 -1
  19. package/views/dist/field-row/FieldRow.js +15 -6
  20. package/views/dist/field-row/field-row-button.d.ts +12 -0
  21. package/views/dist/field-row/field-row-button.js +5 -0
  22. package/views/dist/fields/binding.d.ts +4 -0
  23. package/views/dist/grid/chrome/GridCellEditors.d.ts +1 -1
  24. package/views/dist/grid/chrome/GridCellOutline.d.ts +13 -1
  25. package/views/dist/grid/chrome/GridCellOutline.js +17 -0
  26. package/views/dist/grid/chrome/GridNumberEditor.js +2 -1
  27. package/views/dist/grid/chrome/GridRowCells.js +1 -1
  28. package/views/dist/grid/chrome/GridStructure.js +3 -3
  29. package/views/dist/grid/chrome/GridTextEditor.js +3 -1
  30. package/views/dist/grid/chrome/grid-body-place.js +2 -1
  31. package/views/dist/grid/chrome/grid-edit-session.d.ts +7 -3
  32. package/views/dist/grid/chrome/grid-edit-session.js +12 -3
  33. package/views/dist/grid/chrome/grid-editor-layer.d.ts +5 -4
  34. package/views/dist/grid/chrome/grid-row-props.d.ts +1 -1
  35. package/views/dist/grid/chrome/useGridKeyboard.d.ts +5 -1
  36. package/views/dist/grid/chrome/useGridKeyboard.js +9 -5
  37. package/views/dist/grid/chrome/useGridTableInteractionModel.d.ts +1 -1
  38. package/views/dist/grid/chrome/useGridTableInteractionModel.js +8 -3
  39. package/views/dist/internal/length.d.ts +2 -0
  40. package/views/dist/internal/length.js +16 -0
  41. package/views/dist/provider/components.d.ts +2 -1
  42. package/views/dist/selection/bar-overflow.d.ts +2 -0
  43. package/views/dist/selection/bar-overflow.js +2 -1
  44. package/views/dist/selection/bar-props.d.ts +1 -1
  45. package/views/dist/selection/verbs.d.ts +2 -2
  46. package/views/dist/styles.css +165 -5
  47. package/views/dist/styles.unlayered.css +165 -5
  48. package/views/docs/contract.md +9 -3
  49. package/views/docs/controls/number-editor.md +2 -0
  50. package/views/docs/controls/text-editor.md +2 -0
  51. package/views/docs/guides/selection.md +1 -1
  52. package/views/docs/guides/the-grid.md +1 -1
  53. package/views/docs/reference/field-row.md +1 -1
  54. package/views/docs/reference/looks.md +1 -1
  55. package/views/docs/reference/selection.md +1 -1
  56. package/views/docs/reference/views.md +1 -1
@@ -42,3 +42,20 @@ export const GRID_CELL_HOVER_RING = "hover:after:pointer-events-none hover:after
42
42
  export function GridCellOutline() {
43
43
  return (_jsx("span", { "aria-hidden": true, "data-slot": "vk-grid-outline", className: cx("pointer-events-none absolute inset-0 z-1 rounded-(--vk-outline-radius,var(--radius-sm)) border", "border-(color:--vk-outline,var(--vk-fg-subtle)) group-hover/gridcell:border-(color:--vk-outline-active,var(--vk-border-brand))") }));
44
44
  }
45
+ export const GRID_TYPED_RING = {
46
+ text: [
47
+ "[&_[data-slot=vk-text-box]]:outline [&_[data-slot=vk-text-box]]:-outline-offset-[calc(var(--vk-border-width)+var(--vk-border-width))]",
48
+ "[&_[data-slot=vk-text-box]]:outline-(color:--vk-outline,var(--vk-fg-subtle))",
49
+ "group-hover/gridcell:[&_[data-slot=vk-text-box]]:outline-(color:--vk-outline-active,var(--vk-border-brand))",
50
+ "[&_[data-slot=vk-text-box]]:rounded-[calc(var(--vk-outline-radius,var(--radius-sm))+var(--vk-border-width))]",
51
+ "[&_textarea[data-slot=vk-text-box]]:rounded-[calc(var(--vk-outline-radius,var(--radius-sm))+var(--vk-border-width))]",
52
+ "[&_[data-slot=vk-text-box]:is([aria-invalid=true],:has([aria-invalid=true]))]:outline-hidden",
53
+ ].join(" "),
54
+ number: [
55
+ "[&_[data-slot=vk-number-box]]:outline [&_[data-slot=vk-number-box]]:-outline-offset-[calc(var(--vk-border-width)+var(--vk-border-width))]",
56
+ "[&_[data-slot=vk-number-box]]:outline-(color:--vk-outline,var(--vk-fg-subtle))",
57
+ "group-hover/gridcell:[&_[data-slot=vk-number-box]]:outline-(color:--vk-outline-active,var(--vk-border-brand))",
58
+ "[&_[data-slot=vk-number-box]]:rounded-[calc(var(--vk-outline-radius,var(--radius-sm))+var(--vk-border-width))]",
59
+ "[&_[data-slot=vk-number-box]:is([aria-invalid=true],:has([aria-invalid=true]))]:outline-hidden",
60
+ ].join(" "),
61
+ };
@@ -8,6 +8,7 @@ import { useKeepInside } from "../../editors/keep-inside.js";
8
8
  import { cx } from "../../internal/cx.js";
9
9
  import { BODY_FIGURE_ROOM_PX, GRID_EDITOR_LAYER, GRID_TYPE_IN } from "./grid-editor-layer.js";
10
10
  import { GridFittedBox } from "./grid-fitted-box.js";
11
+ import { GRID_TYPED_RING } from "./GridCellOutline.js";
11
12
  import { GridRefusal, UNDER_CELL_CLASS, useGridEditSession } from "./grid-edit-session.js";
12
13
  export function GridNumberEditor({ title, initial, seed, unit, unitOptions, code, decimals = 2, durationUnit, allowEmpty = false, unitLeft = false, conversion, onCommit, onCancel, onTab, onEnter, refuse, type, bounds, }) {
13
14
  const editorRef = useRef(null);
@@ -32,7 +33,7 @@ export function GridNumberEditor({ title, initial, seed, unit, unitOptions, code
32
33
  form: surface === "sheet" ? "phone" : "computer",
33
34
  }
34
35
  : {}), onRequestClose: close }));
35
- return (_jsx(EditorPanel, { session: session, title: title, anchor: anchorRef, inPlace: true, sheetOnPhone: true, children: (surface) => body ? (surface === "sheet" ? (_jsxs("div", { className: "px-2 pb-3", children: [editor(surface), conversion ? _jsx(ConversionLine, { figure: conversion, className: "pt-1.5" }) : null] })) : (_jsxs("span", { "data-slot": "vk-grid-editor", "data-grown": "", ...GRID_TYPE_IN, className: cx(GRID_EDITOR_LAYER, unitLeft && "justify-end"), children: [_jsx(GridFittedBox, { boxRef: anchorRef, edge: false, room: BODY_FIGURE_ROOM_PX, grows: unitLeft ? "left" : "right", children: editor(surface) }), _jsx(GridRefusal, { reason: session.refusal }), conversion && !session.refusal ? _jsx(UnderCellConversion, { figure: conversion }) : null] }))) : surface === "sheet" ? (_jsxs("div", { className: "px-2 pb-3", children: [_jsx("div", { className: "flex h-10 min-w-0 items-center rounded-md border border-(color:--vk-border) px-2", children: editor(surface) }), conversion ? _jsx(ConversionLine, { figure: conversion, className: "pt-1.5" }) : null] })) : (_jsxs("span", { "data-slot": "vk-grid-editor", className: cx("relative flex h-full w-full min-w-0", unitLeft && "justify-end"), children: [_jsx(GridFittedBox, { boxRef: anchorRef, grows: unitLeft ? "left" : "right", children: editor(surface) }), _jsx(GridRefusal, { reason: session.refusal }), conversion && !session.refusal ? _jsx(UnderCellConversion, { figure: conversion }) : null] })) }));
36
+ return (_jsx(EditorPanel, { session: session, title: title, anchor: anchorRef, inPlace: true, sheetOnPhone: true, children: (surface) => body ? (surface === "sheet" ? (_jsxs("div", { className: "px-2 pb-3", children: [editor(surface), conversion ? _jsx(ConversionLine, { figure: conversion, className: "pt-1.5" }) : null] })) : (_jsxs("span", { "data-slot": "vk-grid-editor", "data-grown": "", ...GRID_TYPE_IN, className: cx(GRID_EDITOR_LAYER, GRID_TYPED_RING.number, unitLeft && "justify-end"), children: [_jsx(GridFittedBox, { boxRef: anchorRef, edge: false, room: BODY_FIGURE_ROOM_PX, grows: unitLeft ? "left" : "right", children: editor(surface) }), _jsx(GridRefusal, { reason: session.refusal }), conversion && !session.refusal ? _jsx(UnderCellConversion, { figure: conversion }) : null] }))) : surface === "sheet" ? (_jsxs("div", { className: "px-2 pb-3", children: [_jsx("div", { className: "flex h-10 min-w-0 items-center rounded-md border border-(color:--vk-border) px-2", children: editor(surface) }), conversion ? _jsx(ConversionLine, { figure: conversion, className: "pt-1.5" }) : null] })) : (_jsxs("span", { "data-slot": "vk-grid-editor", className: cx("relative flex h-full w-full min-w-0", unitLeft && "justify-end"), children: [_jsx(GridFittedBox, { boxRef: anchorRef, grows: unitLeft ? "left" : "right", children: editor(surface) }), _jsx(GridRefusal, { reason: session.refusal }), conversion && !session.refusal ? _jsx(UnderCellConversion, { figure: conversion }) : null] })) }));
36
37
  }
37
38
  function UnderCellConversion({ figure }) {
38
39
  const ref = useRef(null);
@@ -113,7 +113,7 @@ export function GridRowCells({ props }) {
113
113
  listConfig,
114
114
  onCommitCell,
115
115
  onCancel: () => onCancelEdit(rowKey, col.id),
116
- onClosing: (reason) => onEditorClosing?.(rowKey, col.id, reason),
116
+ onClosing: (reason, popover) => onEditorClosing?.(rowKey, col.id, reason, popover),
117
117
  onTab: tabTo,
118
118
  onEnter: () => onFocusCell(rowKey, col.id),
119
119
  };
@@ -20,9 +20,9 @@ function GridRowsSlot({ children }) {
20
20
  const { RowsWait, pending } = slot;
21
21
  return _jsx(RowsWait, { pending: pending, children: children });
22
22
  }
23
- function GridCollapseRegion({ collapsed, children, }) {
23
+ function GridCollapseRegion({ collapsed, rows = false, children, }) {
24
24
  const { Collapse } = useViews().components;
25
- return (_jsx(Collapse, { open: !collapsed, clipClassName: "pt-[2px] mt-[-2px] pb-2 -mb-2", children: children }));
25
+ return (_jsx(Collapse, { open: !collapsed, clipClassName: rows ? "pt-[2px] mt-[-2px] pb-2 -mb-2" : undefined, children: children }));
26
26
  }
27
27
  function GridGroupSection({ group, collapsed, count, selectable, foldOverChecks = false, sort, sortOptions, groupSummary, onToggleGroup, onGroupSummaryChange, renderGroupLabel, onHideGroup, groupMenu, menus, figures, countNoun, renderHeader, renderGroupCheckbox, selectGroup, renderRow, wrapRows, renderFooter, keptFor, barIndex, ariaColCount, oneHead, first, }) {
28
28
  const views = useViews();
@@ -68,7 +68,7 @@ function GridGroupSection({ group, collapsed, count, selectable, foldOverChecks
68
68
  canToggleFigures: !!onGroupSummaryChange,
69
69
  canHide: !!onHideGroup,
70
70
  canSelect: !!select,
71
- }).open && (_jsx(GridGroupMenu, { groupMenu: groupMenu, reshape: menus?.group && ((items) => menus.group(items, { group })), sort: sort, sortOptions: sortOptions ?? [], summary: summaryParts, onSummaryChange: onGroupSummaryChange, figures: figures, onHide: onHideGroup ? () => onHideGroup(group.key) : undefined, select: select }))] }) }), !oneHead && (_jsx(GridCollapseRegion, { collapsed: collapsed, children: renderHeader(selectable ? renderGroupCheckbox(group.items) : undefined, group.key) }))] }), _jsxs(GridCollapseRegion, { collapsed: collapsed, children: [wrapRows(_jsx(GridWindowRows, { groupKey: group.key, items: group.items, collapsed: collapsed, kept: keptFor(group.key), renderRow: renderRow })), renderFooter(group)] })] }));
71
+ }).open && (_jsx(GridGroupMenu, { groupMenu: groupMenu, reshape: menus?.group && ((items) => menus.group(items, { group })), sort: sort, sortOptions: sortOptions ?? [], summary: summaryParts, onSummaryChange: onGroupSummaryChange, figures: figures, onHide: onHideGroup ? () => onHideGroup(group.key) : undefined, select: select }))] }) }), !oneHead && (_jsx(GridCollapseRegion, { collapsed: collapsed, children: renderHeader(selectable ? renderGroupCheckbox(group.items) : undefined, group.key) }))] }), _jsxs(GridCollapseRegion, { collapsed: collapsed, rows: true, children: [wrapRows(_jsx(GridWindowRows, { groupKey: group.key, items: group.items, collapsed: collapsed, kept: keptFor(group.key), renderRow: renderRow })), renderFooter(group)] })] }));
72
72
  }
73
73
  export function GridBody({ empty, emptyState, grouped, oneHead, groups, rows, selectable, selecting, phoneChecks = false, foldOverChecks = false, allSelected, someSelected, selectAll, clearSelection, isCollapsed, countOf, sort, sortOptions, groupSummary, onToggleGroup, onGroupSummaryChange, renderGroupLabel, onHideGroup, groupMenu, menus, figures, countNoun, renderHeader, renderGroupCheckbox, selectGroup, renderRow, wrapRows, renderFooter, keptFor, barIndexOf, ariaColCount, }) {
74
74
  const { messages } = useViews();
@@ -7,6 +7,8 @@ import { TextEditorHost, } from "../../editors/TextEditor.js";
7
7
  import { GridRefusal, useGridEditSession } from "./grid-edit-session.js";
8
8
  import { BODY_FIGURE_ROOM_PX, GRID_EDITOR_LAYER, GRID_TYPE_IN } from "./grid-editor-layer.js";
9
9
  import { GridFittedBox } from "./grid-fitted-box.js";
10
+ import { GRID_TYPED_RING } from "./GridCellOutline.js";
11
+ import { cx } from "../../internal/cx.js";
10
12
  const TEXT_TYPES = new Set([
11
13
  "text",
12
14
  "url",
@@ -33,6 +35,6 @@ export function GridTextEditor({ initial, seed, type = "text", paragraph = false
33
35
  const [stored, setStored] = useState(seed === undefined);
34
36
  return (_jsx(EditorPanel, { session: session, title: title ?? "", anchor: null, inPlace: true, sheetOnPhone: true, children: (surface) => {
35
37
  const editor = (_jsx(TextEditorHost, { ref: editorRef, type: type, initial: initial, seed: seed, closeOnBlur: surface === "in-place", ...(paragraph ? { multiline: true } : {}), label: typeof title === "string" ? title : undefined, check: refuse, region: region, escapeKeeps: session.keeps ?? false, form: surface === "sheet" ? "phone" : "computer", place: "cell", onRequestClose: close }));
36
- return surface === "sheet" ? (open ? (_jsxs("div", { className: "flex items-center gap-2 px-4 pb-4", onInput: (e) => setStored(e.target.value === initial), children: [_jsx("div", { className: "min-w-0 flex-1", children: editor }), stored && _jsx(OpenValueAction, { type: open.type, value: open.value, label: initial })] })) : (_jsx("div", { className: "px-4 pb-4", children: editor }))) : (_jsxs("span", { "data-grown": "", ...GRID_TYPE_IN, className: GRID_EDITOR_LAYER, children: [_jsx(GridFittedBox, { boxRef: boxRef, edge: false, room: BODY_FIGURE_ROOM_PX, children: editor }), _jsx(GridRefusal, { reason: session.refusal })] }));
38
+ return surface === "sheet" ? (open ? (_jsxs("div", { className: "flex items-center gap-2 px-4 pb-4", onInput: (e) => setStored(e.target.value === initial), children: [_jsx("div", { className: "min-w-0 flex-1", children: editor }), stored && _jsx(OpenValueAction, { type: open.type, value: open.value, label: initial })] })) : (_jsx("div", { className: "px-4 pb-4", children: editor }))) : (_jsxs("span", { "data-grown": "", ...GRID_TYPE_IN, className: cx(GRID_EDITOR_LAYER, GRID_TYPED_RING.text), children: [_jsx(GridFittedBox, { boxRef: boxRef, edge: false, room: BODY_FIGURE_ROOM_PX, children: editor }), _jsx(GridRefusal, { reason: session.refusal })] }));
37
39
  } }));
38
40
  }
@@ -1,7 +1,8 @@
1
1
  "use client";
2
2
  import { useLayoutEffect, useState } from "react";
3
+ import { lengthPx } from "../../internal/length.js";
3
4
  const UNDER = 4;
4
- const stepOf = (el) => parseFloat(getComputedStyle(el).getPropertyValue("--vk-spacing")) || 0;
5
+ const stepOf = (el) => lengthPx(el, "--vk-spacing");
5
6
  export function useGridBodyPlace(anchor) {
6
7
  const [at, setAt] = useState(null);
7
8
  useLayoutEffect(() => {
@@ -8,9 +8,13 @@ type Handle<P> = {
8
8
  resolveClose: (reason: CloseReason) => CloseResolution<P>;
9
9
  };
10
10
  /** The cell around a grid editor, told the moment the editor starts to close: its session accepted an answer, and the
11
- * popover or the sheet begins its exit. With the reason the session closed by (null where it names none). The cell
12
- * stops wearing the editing state then, not once the exit is over, and a press away lets its pick go. */
13
- export declare const GridEditClosingContext: import("react").Context<((reason: CloseReason | null) => void) | null>;
11
+ * popover or the sheet begins its exit. With the reason the session closed by (null where it names none), and whether
12
+ * the editor stood in a computer's popover, which holds the focus until its exit ends. The cell stops wearing the
13
+ * editing state then, not once the exit is over; a press away lets its pick go, and a close that keeps the cell takes
14
+ * the focus back from the popover at once. */
15
+ export declare const GridEditClosingContext: import("react").Context<((reason: CloseReason | null, popover: boolean) => void) | null>;
16
+ /** Writes every kept answer still waiting out its popover's exit, so an undo heard now takes back the answer just given. */
17
+ export declare function flushGridKeptAnswers(): void;
14
18
  export type GridEditSessionArgs<P> = {
15
19
  editorRef: RefObject<Handle<P> | null>;
16
20
  /** Reshapes a commit before it is judged and written (a day field's timestamp trimmed to its day). */
@@ -9,6 +9,12 @@ import { useViews } from "../../provider/context.js";
9
9
  import { useDesktop } from "../../provider/desktop.js";
10
10
  export const GRID_SHEET_EXIT_MS = 500;
11
11
  export const GridEditClosingContext = createContext(null);
12
+ const keptFlushes = new Set();
13
+ export function flushGridKeptAnswers() {
14
+ for (const flush of [...keptFlushes])
15
+ flush();
16
+ }
17
+ const KEY_CLOSES = new Set(["enter", "tab", "shift-tab", "escape", "pick"]);
12
18
  export function useGridEditSession(args) {
13
19
  const { editorRef, mapPayload, inPlace = false } = args;
14
20
  const desktop = useDesktop();
@@ -30,8 +36,10 @@ export function useGridEditSession(args) {
30
36
  const flushRef = useRef(null);
31
37
  const leavingRef = useRef(false);
32
38
  const stopFlush = () => {
33
- if (flushRef.current)
39
+ if (flushRef.current) {
34
40
  document.removeEventListener("keydown", flushRef.current, true);
41
+ keptFlushes.delete(flushRef.current);
42
+ }
35
43
  flushRef.current = null;
36
44
  };
37
45
  const move = () => {
@@ -58,7 +66,7 @@ export function useGridEditSession(args) {
58
66
  keptRef.current = answer;
59
67
  if (leavingRef.current)
60
68
  return;
61
- if (sheet || (viaRef.current !== "enter" && viaRef.current !== "tab" && viaRef.current !== "shift-tab"))
69
+ if (sheet || !KEY_CLOSES.has(reasonRef.current))
62
70
  return;
63
71
  movedRef.current = true;
64
72
  move();
@@ -69,6 +77,7 @@ export function useGridEditSession(args) {
69
77
  stopFlush();
70
78
  };
71
79
  flushRef.current = flush;
80
+ keptFlushes.add(flush);
72
81
  document.addEventListener("keydown", flush, true);
73
82
  };
74
83
  const session = useAnchoredEditSession({
@@ -87,7 +96,7 @@ export function useGridEditSession(args) {
87
96
  if (reason !== null)
88
97
  return { accepted: false, reason };
89
98
  if (!leavingRef.current)
90
- closingRef.current?.(reasonRef.current);
99
+ closingRef.current?.(reasonRef.current, !sheet && !inPlace);
91
100
  if (inPlace && !sheet)
92
101
  write(answer, true);
93
102
  else
@@ -7,10 +7,11 @@
7
7
  */
8
8
  export declare const GRID_EDITOR_LAYER = "absolute -inset-px z-2 flex min-w-0";
9
9
  /**
10
- * What a cell typed in shows: only the caret. The layer tells ViewKit's Inline input it stands in a cell
11
- * (`data-inline-input-place`, inline-input.css): no edge, no ring and no ground of its own, so the cell shows as it was;
12
- * grown past its cell, the plain ground, never lifted. A text grows from the cell as the "In the cell" look grows it, whatever
13
- * the page's text look (`data-text-editor-box`). An app's own body draws its own look.
10
+ * What a cell typed in shows: the selected cell's ring round the caret and what is typed. The layer tells ViewKit's Inline
11
+ * input it stands in a cell (`data-inline-input-place`, inline-input.css): no edge, ring or ground of its own, so the cell
12
+ * shows as it was; grown past its cell, the plain ground, never lifted. The layer's `GRID_TYPED_RING` puts the grid's own
13
+ * selected ring on the box, so it goes round the box as it grows. A text grows from the cell as the "In the cell" look grows
14
+ * it, whatever the page's text look (`data-text-editor-box`). An app's own body draws its own look.
14
15
  */
15
16
  export declare const GRID_TYPE_IN: {
16
17
  readonly "data-inline-input-place": "cell";
@@ -76,7 +76,7 @@ export type GridRowProps<Row> = {
76
76
  * picked again, no longer `data-editing`. False on every row but the editing one. */
77
77
  editClosing?: boolean;
78
78
  /** Told when THIS row's open editor starts to close, with the reason it closed by (null where its panel names none). */
79
- onEditorClosing?: (rowId: string, columnId: string, reason: CloseReason | null) => void;
79
+ onEditorClosing?: (rowId: string, columnId: string, reason: CloseReason | null, popover: boolean) => void;
80
80
  /** columnId → optimistic pending value (undefined when this row has none). */
81
81
  pendingByCol?: Record<string, unknown>;
82
82
  /** columnId → `requested` for a pending value saved here but not yet accepted
@@ -6,7 +6,7 @@ import type { ListColumn } from "../../model/column-schema.js";
6
6
  import { type GridEditsState } from "../core/edits-sink.js";
7
7
  import type { GridRangeVerbs } from "./useGridRangeActions.js";
8
8
  import { type GridChromeTarget, type GridFocusShape } from "../core/grid-focus.js";
9
- export declare function useGridKeyboard<Row>({ rootRef, focusedCell, editingCell, editingEnabled, listConfig, rowWritable, visibleRowIds, rowByKey, visibleColIds, visibleColumns, rows, getRowId, pendingByRow, rangeVerbsRef, focusCell, clearFocus, startEdit, cancelEdit, commitEdit, refuseEdit, undo, redo, isLastEdited, editsState, rangeSetRect, rangeExtendTo, ranges, revealCell, releaseToFrame, lastCellRef, chrome, setChrome, shape, toggleGroup, }: {
9
+ export declare function useGridKeyboard<Row>({ rootRef, focusedCell, editingCell, editClosing, editingEnabled, listConfig, rowWritable, visibleRowIds, rowByKey, visibleColIds, visibleColumns, rows, getRowId, pendingByRow, rangeVerbsRef, focusCell, clearFocus, startEdit, cancelEdit, commitEdit, refuseEdit, undo, redo, isLastEdited, editsState, rangeSetRect, rangeExtendTo, ranges, revealCell, releaseToFrame, lastCellRef, chrome, setChrome, shape, toggleGroup, }: {
10
10
  rootRef: RefObject<HTMLDivElement | null>;
11
11
  /** A column name, a footer cell, a bar or a checkbox holding the focus (`useGridFocus`); null: a data cell, or
12
12
  * nothing. */
@@ -26,6 +26,10 @@ export declare function useGridKeyboard<Row>({ rootRef, focusedCell, editingCell
26
26
  revealCell: (pos: GridCellPos, behavior: ScrollBehavior) => void;
27
27
  focusedCell: GridCellPos | null;
28
28
  editingCell: GridCellPos | null;
29
+ /** The open editor has started to close and plays its exit (`useGridTableInteractionModel`): the cell stands as
30
+ * picked, and the keys that move or let go of the pick are its own again. A key that opens or writes still waits for
31
+ * the exit, so a cell can't reopen under its closing editor. */
32
+ editClosing?: boolean;
29
33
  editingEnabled: boolean;
30
34
  /** Workspace-settings capability config — the keyboard routes ask the same effective
31
35
  * write gate the cells do, so a lock holds here too. */
@@ -14,6 +14,7 @@ import { GridEditsSinkContext } from "../core/edits-sink.js";
14
14
  import { GRID_KEY_OWNING_SURFACES, gridFocusElement } from "./useGridFocus.js";
15
15
  import { isGridRowMenuKey, openGridRowMenu } from "./grid-row-menu-key.js";
16
16
  import { openGridEditEscape } from "./grid-edit-escape.js";
17
+ import { flushGridKeptAnswers } from "./grid-edit-session.js";
17
18
  import { bodyInnerStepFrame } from "../../editors/inner-escape.js";
18
19
  import { gridBarArrow, gridFocusStep, gridFocusTab, } from "../core/grid-focus.js";
19
20
  const NAV_KEYS = {
@@ -33,7 +34,7 @@ function eventBelongsElsewhere(target, root) {
33
34
  return true;
34
35
  return !!target.closest(INTERACTIVE) && !root?.contains(target);
35
36
  }
36
- export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnabled, listConfig, rowWritable, visibleRowIds, rowByKey, visibleColIds, visibleColumns, rows, getRowId, pendingByRow, rangeVerbsRef, focusCell, clearFocus, startEdit, cancelEdit, commitEdit, refuseEdit, undo, redo, isLastEdited = () => true, editsState, rangeSetRect, rangeExtendTo, ranges, revealCell, releaseToFrame, lastCellRef, chrome = null, setChrome = () => { }, shape, toggleGroup, }) {
37
+ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editClosing = false, editingEnabled, listConfig, rowWritable, visibleRowIds, rowByKey, visibleColIds, visibleColumns, rows, getRowId, pendingByRow, rangeVerbsRef, focusCell, clearFocus, startEdit, cancelEdit, commitEdit, refuseEdit, undo, redo, isLastEdited = () => true, editsState, rangeSetRect, rangeExtendTo, ranges, revealCell, releaseToFrame, lastCellRef, chrome = null, setChrome = () => { }, shape, toggleGroup, }) {
37
38
  const { ports, messages, conventions } = useViews();
38
39
  const navFromEditorRef = useRef({ tab: () => { } });
39
40
  const onEditorTab = useCallback((rowId, columnId, backwards) => navFromEditorRef.current.tab(rowId, columnId, backwards), []);
@@ -93,6 +94,7 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
93
94
  const holder = event.target?.closest?.('[data-slot="vk-grid"]') ?? null;
94
95
  if (holder ? holder !== rootRef.current : !isLastEdited())
95
96
  return;
97
+ flushGridKeptAnswers();
96
98
  const handled = event.shiftKey
97
99
  ? redo(resolveRow, scrollToCell)
98
100
  : undo(resolveRow, scrollToCell);
@@ -270,6 +272,7 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
270
272
  const bare = !event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey;
271
273
  const navDirection = NAV_KEYS[event.key];
272
274
  const navIntent = gridNavIntent(event);
275
+ const editorHolds = editingCell != null && !editClosing;
273
276
  rowMenuWatchRef.current?.();
274
277
  rowMenuWatchRef.current = null;
275
278
  if (isGridRowMenuKey(event) && !editingCell) {
@@ -281,14 +284,14 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
281
284
  }
282
285
  if (event.key === "Escape") {
283
286
  event.stopPropagation();
284
- if (editingCell)
287
+ if (editorHolds)
285
288
  (openGridEditEscape() ?? cancelEdit)();
286
289
  else {
287
290
  clearFocus();
288
291
  releaseToFrame();
289
292
  }
290
293
  }
291
- else if (navDirection && bare && !editingCell) {
294
+ else if (navDirection && bare && !editorHolds) {
292
295
  event.preventDefault();
293
296
  if (shape && navDirection !== "right") {
294
297
  const step = gridFocusStep({ kind: "cell", pos: focusedCell }, navDirection, shape);
@@ -302,7 +305,7 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
302
305
  focusCell(next.rowId, next.columnId);
303
306
  revealCell(next, "auto");
304
307
  }
305
- else if (navIntent && !editingCell) {
308
+ else if (navIntent && !editorHolds) {
306
309
  event.preventDefault();
307
310
  if (navIntent.kind === "selectAll") {
308
311
  const rect = wholeTableRect(visibleRowIds, visibleColIds);
@@ -328,7 +331,7 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
328
331
  revealCell(next, "auto");
329
332
  }
330
333
  else if (event.key === "Tab" && !event.metaKey && !event.ctrlKey && !event.altKey) {
331
- if (editingCell) {
334
+ if (editorHolds) {
332
335
  event.preventDefault();
333
336
  return;
334
337
  }
@@ -456,6 +459,7 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
456
459
  chrome,
457
460
  clearFocus,
458
461
  commitEdit,
462
+ editClosing,
459
463
  editingCell,
460
464
  editingEnabled,
461
465
  entryCell,
@@ -64,7 +64,7 @@ export declare function useGridTableInteractionModel<Row>({ rootRef, props, rows
64
64
  editWhole: boolean;
65
65
  editByKey: boolean;
66
66
  editClosing: boolean;
67
- onEditorClosing: (rowId: string, columnId: string, reason: CloseReason | null) => void;
67
+ onEditorClosing: (rowId: string, columnId: string, reason: CloseReason | null, popover: boolean) => void;
68
68
  focusCellSync: (rowId: string, columnId: string) => void;
69
69
  startEditSync: (rowId: string, columnId: string, seed?: string | null, whole?: boolean, byKey?: boolean) => void;
70
70
  cancelEdit: (rowId?: string, columnId?: string) => void;
@@ -12,7 +12,7 @@ import { gridFigureOf } from "../core/clipboard-model.js";
12
12
  import { sameStoredValue } from "viewkitjs/fields";
13
13
  import { gridRowIdFromKey } from "../core/coordinates.js";
14
14
  import { revealGridCell } from "./grid-scroll-owner.js";
15
- import { useGridFocus } from "./useGridFocus.js";
15
+ import { gridFocusElement, useGridFocus } from "./useGridFocus.js";
16
16
  import { gridBarOf } from "../core/grid-focus.js";
17
17
  import { useGridKeyboard } from "./useGridKeyboard.js";
18
18
  import { useGridPendingReconciliation } from "./useGridPendingReconciliation.js";
@@ -235,7 +235,7 @@ export function useGridTableInteractionModel({ rootRef, props, rows, visibleRows
235
235
  useEffect(() => {
236
236
  closingRef.current = { editingCell, held: cellPick.held, dropFocus, rangeClear };
237
237
  });
238
- const onEditorClosing = useCallback((rowId, columnId, reason) => {
238
+ const onEditorClosing = useCallback((rowId, columnId, reason, popover) => {
239
239
  const { editingCell: open, held, dropFocus: drop, rangeClear: clear } = closingRef.current;
240
240
  if (!open || open.rowId !== rowId || open.columnId !== columnId)
241
241
  return;
@@ -245,7 +245,11 @@ export function useGridTableInteractionModel({ rootRef, props, rows, visibleRows
245
245
  drop();
246
246
  clear();
247
247
  }
248
- }, []);
248
+ const keeps = reason === "escape" || reason === "pick" || reason === "enter";
249
+ const root = rootRef.current;
250
+ if (keeps && popover && root)
251
+ gridFocusElement(root, { kind: "cell", pos: open })?.focus({ preventScroll: true });
252
+ }, [rootRef]);
249
253
  const spreadsheetModel = useMemo(() => ({
250
254
  rows,
251
255
  rowByKey: rowIndex,
@@ -305,6 +309,7 @@ export function useGridTableInteractionModel({ rootRef, props, rows, visibleRows
305
309
  rootRef,
306
310
  focusedCell,
307
311
  editingCell,
312
+ editClosing,
308
313
  editingEnabled,
309
314
  listConfig,
310
315
  rowWritable,
@@ -0,0 +1,2 @@
1
+ /** A length in px ("4px" is 4, "0.25rem" is 4 under a 16px root, a calc() what it comes to), 0 where nothing declares it. */
2
+ export declare function lengthPx(el: Element | null | undefined, prop: `--${string}`): number;
@@ -0,0 +1,16 @@
1
+ export function lengthPx(el, prop) {
2
+ if (!el || typeof getComputedStyle === "undefined")
3
+ return 0;
4
+ const value = getComputedStyle(el).getPropertyValue(prop).trim();
5
+ if (!value)
6
+ return 0;
7
+ if (/^-?(\d+\.?\d*|\.\d+)(px)?$/.test(value))
8
+ return parseFloat(value);
9
+ const probe = el.ownerDocument.createElement("span");
10
+ probe.style.cssText = "position:absolute;visibility:hidden;pointer-events:none";
11
+ probe.style.setProperty("outline-offset", value);
12
+ el.appendChild(probe);
13
+ const px = parseFloat(getComputedStyle(probe).outlineOffset);
14
+ probe.remove();
15
+ return Number.isFinite(px) ? px : 0;
16
+ }
@@ -38,7 +38,8 @@ export type ViewsButtonProps = {
38
38
  /** The part's name, `vk-grid-row-more` on a row's ⋯. */
39
39
  "data-slot"?: string;
40
40
  /** Which one of a part that repeats, beside its `data-slot` (VK-1013: inside ViewKit's panels, under `panelControls`): a
41
- * rule's field, an action's verb. Forward it to your element. */
41
+ * rule's field, an action's verb; and a record's field row's target (`vk-field-row-target`, `-beside`, `-under`), which the
42
+ * Field's Box dresses. Forward it to your element. */
42
43
  "data-key"?: string;
43
44
  /** A state flag: `""` (present, no value) while the menu this button opens is open; absent when closed. */
44
45
  "data-open"?: "";
@@ -2,6 +2,8 @@ import type { ViewsMenuItem } from "../provider/components.js";
2
2
  import type { SelectionVerb } from "./verbs.js";
3
3
  /** How many verbs stay on the bar before the rest fold into More. */
4
4
  export declare const INLINE_VERBS = 4;
5
+ /** The first four verbs not marked `more` stand on the bar. More holds the marked ones, then the rest past
6
+ * four: the components map's bar's order (`moreRows`), so both list More alike. */
5
7
  export declare function splitVerbs(verbs: readonly SelectionVerb[]): {
6
8
  inline: SelectionVerb[];
7
9
  overflow: SelectionVerb[];
@@ -1,6 +1,7 @@
1
1
  export const INLINE_VERBS = 4;
2
2
  export function splitVerbs(verbs) {
3
- return { inline: verbs.slice(0, INLINE_VERBS), overflow: verbs.slice(INLINE_VERBS) };
3
+ const onBar = verbs.filter((verb) => !verb.more), kept = verbs.filter((verb) => verb.more);
4
+ return { inline: onBar.slice(0, INLINE_VERBS), overflow: [...kept, ...onBar.slice(INLINE_VERBS)] };
4
5
  }
5
6
  export function overflowItems(overflow) {
6
7
  const reason = (disabled, why) => disabled && why ? { disabledReason: why } : {};
@@ -11,7 +11,7 @@ export type SelectionBarProps = {
11
11
  };
12
12
  /** Clears the selection: the count chip, the phone's ✕. */
13
13
  onClear: () => void;
14
- /** What the selection lets a person do, in order: the first four on the bar, the rest in More. */
14
+ /** What the selection lets a person do, in order: the first four not marked `more` on ViewKit's own bar, the rest in More. */
15
15
  verbs: readonly SelectionVerb[];
16
16
  /** A batch is running: every control is disabled until it ends. */
17
17
  busy?: boolean;
@@ -35,7 +35,7 @@ export type SelectionOptionsVerb = {
35
35
  /** Its values: a status by its `slot`, a category by its `color`, a person or a company by `avatarUrl` (null: their initials)
36
36
  * and `kind`. ViewKit's own bar reads the value, the label, the slot and the colour. */
37
37
  options: ViewsPickerItem[];
38
- /** Kept off the bar, in More (CONTROLS.SelectionBar's bar). */
38
+ /** Kept off the bar, in More: on ViewKit's own bar and on CONTROLS.SelectionBar's. */
39
39
  more?: boolean;
40
40
  /** What every picked row holds, when they hold the same: a value, or null when every one is empty; left out, they differ.
41
41
  * CONTROLS.SelectionBar's bar marks it. */
@@ -58,7 +58,7 @@ export type SelectionVerb = ({
58
58
  kind: "group";
59
59
  label: string;
60
60
  icon?: ReactNode;
61
- /** Kept off the bar, in More (CONTROLS.SelectionBar's bar). */
61
+ /** Kept off the bar, in More: on ViewKit's own bar and on CONTROLS.SelectionBar's. */
62
62
  more?: boolean;
63
63
  disabled?: boolean;
64
64
  /** Why the group is disabled: its own button and More's row carry it, and so does each of its rows that