@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
|
@@ -1,23 +1,32 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type TextEditorType } from "../../editors/TextEditor.js";
|
|
1
3
|
/**
|
|
2
4
|
* The GRID's long-text panel — reading and editing a paragraph in ONE surface.
|
|
3
5
|
*
|
|
4
6
|
* A `format.long` text is a paragraph, and a paragraph in a 37px cell is one
|
|
5
7
|
* clipped line with no way in. So editing it does not swap the cell for a
|
|
6
8
|
* one-line input: it opens a panel ON the cell (top-left on the cell's
|
|
7
|
-
* top-left, the column's width) holding the whole value in
|
|
8
|
-
* caret at the end — Attio's model.
|
|
9
|
-
*
|
|
9
|
+
* top-left, the column's width) holding the whole value in the shared
|
|
10
|
+
* `TextEditor` as a paragraph, the caret at the end — Attio's model.
|
|
11
|
+
* Inspection is the same panel read-only: the value is selectable, copyable,
|
|
12
|
+
* and never written.
|
|
10
13
|
*
|
|
11
14
|
* Anchored like the select and date editors: the cell's own content stays on
|
|
12
15
|
* screen behind the popover, `useAnchoredEditSession` owns the one-answer
|
|
13
|
-
* guard and the exit gap, and
|
|
14
|
-
* the panel opens above the cell.
|
|
16
|
+
* guard and the exit gap, and the app's popover owns the viewport — with no
|
|
17
|
+
* room below the panel opens above the cell. On a phone it opens in the sheet
|
|
18
|
+
* instead (`EditorPanel`), titled with the column's header; the answer waits
|
|
19
|
+
* for the sheet to slide away, and ✓ never moves the selection.
|
|
15
20
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
21
|
+
* It also opens a LINE whole (`paragraph={false}`): a plain text or a text
|
|
22
|
+
* name its cell cut off. The box wraps so all of it shows, but it is
|
|
23
|
+
* still a line: Enter commits and advances, and a newline is written as a space.
|
|
24
|
+
*
|
|
25
|
+
* Keys are a paragraph's: Enter is a newline; ⌘ or Ctrl Enter commits and
|
|
26
|
+
* advances; Tab commits and moves; Escape cancels; an outside click commits.
|
|
27
|
+
* The host grid's click-away listener clears the cell's focus after that commit.
|
|
19
28
|
*/
|
|
20
|
-
export declare function GridLongTextEditor({ initial, seed, readOnly, markdown, onCommit, onCancel, onTab, onEnter, }: {
|
|
29
|
+
export declare function GridLongTextEditor({ initial, seed, readOnly, markdown, paragraph, type, title, refuse, onCommit, onCancel, onTab, onEnter, }: {
|
|
21
30
|
/** The stored value the session opens on ("" when unset). */
|
|
22
31
|
initial: string;
|
|
23
32
|
/** Type-to-replace: the character that opened this editor replaces the value. */
|
|
@@ -27,10 +36,20 @@ export declare function GridLongTextEditor({ initial, seed, readOnly, markdown,
|
|
|
27
36
|
/** Markdown keeps its first line's indent: it is tidied only at its edges
|
|
28
37
|
* (`normalizeMarkdown`), where plain long text is trimmed. */
|
|
29
38
|
markdown?: boolean;
|
|
39
|
+
/** A paragraph (default): Enter is a newline. False: a line shown whole, where Enter commits. */
|
|
40
|
+
paragraph?: boolean;
|
|
41
|
+
/** The text editor's type for a line (its keyboard on a phone). Default: rich text when
|
|
42
|
+
* `markdown`, else text. */
|
|
43
|
+
type?: TextEditorType;
|
|
44
|
+
/** The sheet's title on a phone: the column's header. */
|
|
45
|
+
title?: ReactNode;
|
|
30
46
|
onCommit: (value: string) => void;
|
|
31
47
|
onCancel: () => void;
|
|
32
48
|
/** Commit happened via Tab — move to the next cell in reading order. */
|
|
33
49
|
onTab?: (backwards: boolean) => void;
|
|
34
50
|
/** Commit happened via ⌘-Enter — advance one row down. */
|
|
35
51
|
onEnter?: () => void;
|
|
52
|
+
/** The grid's judgement of a value before it is written: its reason when it would refuse it.
|
|
53
|
+
* A refused value stays open in the panel with that reason. */
|
|
54
|
+
refuse?: (value: string) => string | null;
|
|
36
55
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,85 +1,34 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
4
|
+
import { EditorPanel } from "../../editors/EditorPanel.js";
|
|
5
|
+
import { TextEditor } from "../../editors/TextEditor.js";
|
|
5
6
|
import { useViews } from "../../provider/context.js";
|
|
6
7
|
import { cx } from "../../internal/cx.js";
|
|
7
|
-
import {
|
|
8
|
+
import { useGridEditSession } from "./grid-edit-session.js";
|
|
8
9
|
const MIN_W = 320;
|
|
9
10
|
const MAX_W = 512;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const { components, messages } = useViews();
|
|
13
|
-
const { Popover } = components;
|
|
11
|
+
export function GridLongTextEditor({ initial, seed, readOnly = false, markdown = false, paragraph = true, type, title, refuse, onCommit, onCancel, onTab, onEnter, }) {
|
|
12
|
+
const { messages } = useViews();
|
|
14
13
|
const anchorRef = useRef(null);
|
|
15
|
-
const
|
|
14
|
+
const editorRef = useRef(null);
|
|
16
15
|
const [cell, setCell] = useState(null);
|
|
17
16
|
useLayoutEffect(() => {
|
|
18
17
|
const anchor = anchorRef.current;
|
|
19
18
|
if (anchor)
|
|
20
19
|
setCell(measureCell(anchor));
|
|
21
20
|
}, []);
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const next = tidy(areaRef.current?.value ?? "");
|
|
30
|
-
return next === tidy(initial) ? { kind: "noop" } : { kind: "commit", payload: next };
|
|
31
|
-
},
|
|
21
|
+
const { session, close } = useGridEditSession({
|
|
22
|
+
editorRef,
|
|
23
|
+
refuse: refuse && ((value) => refuse(value)),
|
|
24
|
+
onCommit: (payload) => onCommit(payload),
|
|
25
|
+
onCancel,
|
|
26
|
+
onTab,
|
|
27
|
+
onEnter,
|
|
32
28
|
});
|
|
33
|
-
const viaRef = useRef(null);
|
|
34
|
-
const { open, close } = useAnchoredEditSession({
|
|
35
|
-
editorRef: handleRef,
|
|
36
|
-
onDone: (resolution) => {
|
|
37
|
-
if (resolution.kind === "commit") {
|
|
38
|
-
onCommit(resolution.payload);
|
|
39
|
-
if (viaRef.current === "enter")
|
|
40
|
-
onEnter?.();
|
|
41
|
-
if (viaRef.current === "tab")
|
|
42
|
-
onTab?.(false);
|
|
43
|
-
if (viaRef.current === "shift-tab")
|
|
44
|
-
onTab?.(true);
|
|
45
|
-
}
|
|
46
|
-
else
|
|
47
|
-
onCancel();
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
const closeVia = (reason) => {
|
|
51
|
-
viaRef.current = reason;
|
|
52
|
-
close(reason);
|
|
53
|
-
};
|
|
54
|
-
const attach = useCallback((el) => {
|
|
55
|
-
areaRef.current = el;
|
|
56
|
-
if (!el)
|
|
57
|
-
return;
|
|
58
|
-
el.focus({ preventScroll: true });
|
|
59
|
-
el.setSelectionRange(el.value.length, el.value.length);
|
|
60
|
-
grow(el);
|
|
61
|
-
}, []);
|
|
62
|
-
const onKeyDown = (event) => {
|
|
63
|
-
event.stopPropagation();
|
|
64
|
-
if (event.key === "Escape") {
|
|
65
|
-
event.preventDefault();
|
|
66
|
-
closeVia("escape");
|
|
67
|
-
}
|
|
68
|
-
else if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
|
|
69
|
-
event.preventDefault();
|
|
70
|
-
closeVia("enter");
|
|
71
|
-
}
|
|
72
|
-
else if (event.key === "Tab") {
|
|
73
|
-
event.preventDefault();
|
|
74
|
-
closeVia(event.shiftKey ? "shift-tab" : "tab");
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
29
|
const width = cell ? Math.min(MAX_W, Math.max(MIN_W, cell.width)) : MIN_W;
|
|
78
30
|
const padY = cell ? Math.max(0, (cell.height - cell.lineHeight) / 2 - 1) : 8;
|
|
79
|
-
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, "aria-hidden": true, className: "pointer-events-none absolute inset-0" }), _jsx(
|
|
80
|
-
if (!next)
|
|
81
|
-
closeVia("outside");
|
|
82
|
-
}, anchor: anchorRef, align: "start", sideOffset: cell ? -cell.height : 0, onEscape: () => closeVia("escape"), onOutsidePress: () => closeVia("outside"), initialFocus: false, panelData: { "data-slot": "vk-grid-editor" }, onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: cx("z-90 rounded-sm p-0", readOnly ? "border-(color:--vk-border)" : "border-(color:--vk-border-brand)"), style: { width }, children: _jsx("textarea", { ref: attach, "data-grid-editor": true, "aria-label": messages({ key: readOnly ? "views.grid.value" : "views.grid.edit-value" }), defaultValue: seed ?? initial, readOnly: readOnly, rows: 1, onKeyDown: onKeyDown, onInput: (e) => grow(e.currentTarget), style: cell
|
|
31
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, "aria-hidden": true, className: "pointer-events-none absolute inset-0" }), _jsx(EditorPanel, { session: session, title: title ?? "", anchor: anchorRef, align: "start", sideOffset: cell ? -cell.height : 0, initialFocus: false, panelData: { "data-slot": "vk-grid-editor" }, onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: cx("z-90 rounded-sm p-0", readOnly ? "border-(color:--vk-border)" : "border-(color:--vk-border-brand)"), style: { width }, children: (surface) => (_jsx(TextEditor, { ref: editorRef, type: type ?? (markdown ? "rich_text" : "text"), multiline: paragraph, wraps: !paragraph, initial: initial, seed: seed, readOnly: readOnly, closeOnBlur: false, label: messages({ key: readOnly ? "views.grid.value" : "views.grid.edit-value" }), boxData: { "data-grid-editor": "" }, onRequestClose: close, style: cell && surface === "popover"
|
|
83
32
|
? {
|
|
84
33
|
paddingLeft: cell.paddingX,
|
|
85
34
|
paddingRight: cell.paddingX,
|
|
@@ -88,7 +37,7 @@ export function GridLongTextEditor({ initial, seed, readOnly = false, markdown =
|
|
|
88
37
|
fontSize: cell.fontSize,
|
|
89
38
|
lineHeight: `${cell.lineHeight}px`,
|
|
90
39
|
}
|
|
91
|
-
: undefined, className: cx("block w-full resize-none select-text bg-transparent text-(color:--vk-fg) outline-hidden", "overflow-y-auto overscroll-contain") }) })] }));
|
|
40
|
+
: undefined, className: cx("block w-full resize-none select-text bg-transparent text-(color:--vk-fg) outline-hidden", "overflow-y-auto overscroll-contain", surface === "sheet" && "px-4 py-2") })) })] }));
|
|
92
41
|
}
|
|
93
42
|
function measureCell(anchor) {
|
|
94
43
|
const box = anchor.getBoundingClientRect();
|
|
@@ -118,10 +67,3 @@ function resolveLength(host, value) {
|
|
|
118
67
|
host.removeChild(probe);
|
|
119
68
|
return px;
|
|
120
69
|
}
|
|
121
|
-
function grow(el) {
|
|
122
|
-
el.style.height = "auto";
|
|
123
|
-
const style = getComputedStyle(el);
|
|
124
|
-
const line = parseFloat(style.lineHeight) || 22;
|
|
125
|
-
const pad = (parseFloat(style.paddingTop) || 0) + (parseFloat(style.paddingBottom) || 0);
|
|
126
|
-
el.style.height = `${Math.min(el.scrollHeight, line * MAX_LINES + pad)}px`;
|
|
127
|
-
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
1
2
|
import type { NameValue } from "@viewkitjs/fields";
|
|
2
3
|
/**
|
|
3
|
-
* The GRID's host around the shared `NameEditor`. Anchored, like the
|
|
4
|
-
*
|
|
5
|
-
* while the cell's own name stays on screen.
|
|
6
|
-
* one-answer guard and the exit gap; the
|
|
7
|
-
*
|
|
4
|
+
* The GRID's host around the shared `NameEditor`. Anchored, like the place and
|
|
5
|
+
* value list editors: three boxes do not fit a cell, so they open in a panel
|
|
6
|
+
* under it while the cell's own name stays on screen. The edit session owns the
|
|
7
|
+
* one-answer guard and the exit gap; the editor panel opens the popover on a
|
|
8
|
+
* desktop and the sheet on a phone, titled with the column's header, where the
|
|
9
|
+
* boxes wear the app's field frame. A blur onto another box is not a close, and
|
|
10
|
+
* in the sheet no blur is one (a tap on ✕ or ✓ blurs a box first).
|
|
8
11
|
*/
|
|
9
|
-
export declare function GridNameEditor({ initial, seed, allowEmpty, onCommit, onCancel, onTab, onEnter, }: {
|
|
12
|
+
export declare function GridNameEditor({ title, initial, seed, allowEmpty, onCommit, onCancel, onTab, onEnter, }: {
|
|
13
|
+
/** The field's name: the sheet's title on a phone. */
|
|
14
|
+
title: ReactNode;
|
|
10
15
|
initial: NameValue | null;
|
|
11
16
|
/** Type-to-replace: the character that opened this editor replaces the given box. */
|
|
12
17
|
seed?: string;
|
|
@@ -1,36 +1,21 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useRef } from "react";
|
|
4
|
-
import {
|
|
4
|
+
import { EditorPanel } from "../../editors/EditorPanel.js";
|
|
5
5
|
import { NameEditor } from "../../editors/NameEditor.js";
|
|
6
|
-
import {
|
|
7
|
-
export function GridNameEditor({ initial, seed, allowEmpty = false, onCommit, onCancel, onTab, onEnter, }) {
|
|
8
|
-
const { Popover } = useViews().components;
|
|
6
|
+
import { useGridEditSession } from "./grid-edit-session.js";
|
|
7
|
+
export function GridNameEditor({ title, initial, seed, allowEmpty = false, onCommit, onCancel, onTab, onEnter, }) {
|
|
9
8
|
const anchorRef = useRef(null);
|
|
10
9
|
const editorRef = useRef(null);
|
|
11
|
-
const
|
|
12
|
-
const { open, close } = useAnchoredEditSession({
|
|
10
|
+
const { session, close } = useGridEditSession({
|
|
13
11
|
editorRef,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
onEnter?.();
|
|
19
|
-
if (viaRef.current === "tab")
|
|
20
|
-
onTab?.(false);
|
|
21
|
-
if (viaRef.current === "shift-tab")
|
|
22
|
-
onTab?.(true);
|
|
23
|
-
}
|
|
24
|
-
else
|
|
25
|
-
onCancel();
|
|
26
|
-
},
|
|
12
|
+
onCommit: (payload) => onCommit(payload),
|
|
13
|
+
onCancel,
|
|
14
|
+
onTab,
|
|
15
|
+
onEnter,
|
|
27
16
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, "aria-hidden": true, className: "pointer-events-none absolute inset-0" }), _jsx(Popover, { open: open, onOpenChange: (next) => {
|
|
33
|
-
if (!next)
|
|
34
|
-
closeVia("outside");
|
|
35
|
-
}, anchor: anchorRef, align: "start", sideOffset: 4, onEscape: () => closeVia("escape"), onOutsidePress: () => closeVia("outside"), initialFocus: false, panelData: { "data-slot": "vk-grid-editor" }, onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: "z-90 w-80 p-2", children: _jsx(NameEditor, { ref: editorRef, initial: initial, seed: seed, allowEmpty: allowEmpty, onRequestClose: closeVia }) })] }));
|
|
17
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, "aria-hidden": true, className: "pointer-events-none absolute inset-0" }), _jsx(EditorPanel, { session: session, title: title, anchor: anchorRef, align: "start", sideOffset: 4, initialFocus: false, panelData: { "data-slot": "vk-grid-editor" }, onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: "z-90 w-80 p-2", children: (surface) => {
|
|
18
|
+
const editor = (_jsx(NameEditor, { ref: editorRef, initial: initial, seed: seed, allowEmpty: allowEmpty, chrome: surface === "sheet" ? "field" : "bare", onRequestClose: close }));
|
|
19
|
+
return surface === "sheet" ? _jsx("div", { className: "px-4 pb-4", children: editor }) : editor;
|
|
20
|
+
} })] }));
|
|
36
21
|
}
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
1
2
|
import type { DurationUnit } from "@viewkitjs/fields/query";
|
|
2
3
|
import type { GridNumberEditValue } from "../core/edit-values.js";
|
|
3
4
|
/**
|
|
4
5
|
* The GRID's host around the shared `NumberEditor` (`@viewkitjs/views/editors/number`) —
|
|
5
6
|
* the typed field and its unit chip are one component across every surface;
|
|
6
|
-
*
|
|
7
|
-
* and the focus move that
|
|
7
|
+
* the edit session owns the one-answer guard, and the editor panel decides where
|
|
8
|
+
* it opens. This host owns the grid's part: the write, and the focus move that
|
|
9
|
+
* follows it.
|
|
8
10
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
11
|
+
* On a desktop it is INLINE — it replaces the cell's content rather than opening
|
|
12
|
+
* a panel over it, so there is no animation to play out and the commit lands at
|
|
13
|
+
* once, before the focus moves: the order undo depends on. On a phone it opens in
|
|
14
|
+
* the sheet (a cell is too small to type into under a finger), and the answer
|
|
15
|
+
* waits for the sheet to slide away.
|
|
12
16
|
*/
|
|
13
|
-
export declare function GridNumberEditor({ initial, seed, unit, unitOptions, decimals, durationUnit, allowEmpty, unitLeft, onCommit, onCancel, onTab, onEnter, }: {
|
|
17
|
+
export declare function GridNumberEditor({ title, initial, seed, unit, unitOptions, code, decimals, durationUnit, allowEmpty, unitLeft, conversion, onCommit, onCancel, onTab, onEnter, refuse, }: {
|
|
18
|
+
/** The field's name: the sheet's title on a phone. */
|
|
19
|
+
title: ReactNode;
|
|
14
20
|
/** Signed raw value (e.g. -47.50 for an "out" transaction in its own currency). */
|
|
15
21
|
initial: number;
|
|
16
22
|
/** Type-to-replace: the character that opened this editor. */
|
|
@@ -19,6 +25,8 @@ export declare function GridNumberEditor({ initial, seed, unit, unitOptions, dec
|
|
|
19
25
|
unit?: string;
|
|
20
26
|
/** Selectable units — presence makes the chip a picker. */
|
|
21
27
|
unitOptions?: string[];
|
|
28
|
+
/** A fixed currency's code, drawn beside the amount (never committed). */
|
|
29
|
+
code?: string;
|
|
22
30
|
/** Rounding + initial formatting precision. */
|
|
23
31
|
decimals?: number;
|
|
24
32
|
/** A duration column's STORED unit — the core edits it as human text. */
|
|
@@ -27,9 +35,15 @@ export declare function GridNumberEditor({ initial, seed, unit, unitOptions, dec
|
|
|
27
35
|
/** Right-aligned columns put the chip on the LEFT so the number stays flush
|
|
28
36
|
* with the column's right edge. */
|
|
29
37
|
unitLeft?: boolean;
|
|
38
|
+
/** The figure the cell showed, when it showed the row's amount converted into another currency: named under
|
|
39
|
+
* the editor, which opens on the row's own amount. */
|
|
40
|
+
conversion?: ReactNode;
|
|
30
41
|
onCommit: (payload: GridNumberEditValue) => void;
|
|
31
42
|
onCancel: () => void;
|
|
32
43
|
onTab?: (backwards: boolean) => void;
|
|
33
44
|
/** Commit happened via Enter — advance one row down (Sheets). */
|
|
34
45
|
onEnter?: () => void;
|
|
46
|
+
/** The grid's judgement of a value before it is written: its reason when it would refuse it.
|
|
47
|
+
* A refused value keeps the editor open with that reason. */
|
|
48
|
+
refuse?: (value: GridNumberEditValue) => string | null;
|
|
35
49
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,25 +1,51 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useRef } from "react";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useLayoutEffect, useRef } from "react";
|
|
4
4
|
import { NumberEditor } from "../../editors/NumberEditor.js";
|
|
5
|
-
|
|
5
|
+
import { EditorPanel } from "../../editors/EditorPanel.js";
|
|
6
|
+
import { ConversionLine } from "../../display/converted.js";
|
|
7
|
+
import { useKeepInside } from "../../editors/keep-inside.js";
|
|
8
|
+
import { cx } from "../../internal/cx.js";
|
|
9
|
+
import { GRID_GROUND } from "./grid-styles.js";
|
|
10
|
+
import { GridRefusal, UNDER_CELL_CLASS, useGridEditSession } from "./grid-edit-session.js";
|
|
11
|
+
export function GridNumberEditor({ title, initial, seed, unit, unitOptions, code, decimals = 2, durationUnit, allowEmpty = false, unitLeft = false, conversion, onCommit, onCancel, onTab, onEnter, refuse, }) {
|
|
6
12
|
const editorRef = useRef(null);
|
|
7
|
-
const
|
|
8
|
-
const close = (
|
|
9
|
-
|
|
13
|
+
const anchorRef = useRef(null);
|
|
14
|
+
const { session, close } = useGridEditSession({
|
|
15
|
+
editorRef,
|
|
16
|
+
inPlace: true,
|
|
17
|
+
refuse: refuse && ((value) => refuse(value)),
|
|
18
|
+
onCommit: (payload) => onCommit(payload),
|
|
19
|
+
onCancel,
|
|
20
|
+
onTab,
|
|
21
|
+
onEnter,
|
|
22
|
+
});
|
|
23
|
+
const editor = (_jsx(NumberEditor, { ref: editorRef, initial: initial, seed: seed, unit: unit, unitOptions: unitOptions, code: code, decimals: decimals, durationUnit: durationUnit, allowEmpty: allowEmpty, unitLeft: unitLeft, onRequestClose: close }));
|
|
24
|
+
return (_jsx(EditorPanel, { session: session, title: title, anchor: anchorRef, inPlace: true, sheetOnPhone: true, children: (surface) => 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 }), 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(FittedBox, { boxRef: anchorRef, children: editor }), _jsx(GridRefusal, { reason: session.refusal }), conversion && !session.refusal ? _jsx(UnderCellConversion, { figure: conversion }) : null] })) }));
|
|
25
|
+
}
|
|
26
|
+
const FITTED_MAX_PX = 320;
|
|
27
|
+
function FittedBox({ boxRef, children }) {
|
|
28
|
+
const fit = useCallback(() => {
|
|
29
|
+
const box = boxRef.current;
|
|
30
|
+
const input = box?.querySelector("input");
|
|
31
|
+
if (!box || !input)
|
|
10
32
|
return;
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
|
|
33
|
+
box.style.minWidth = "";
|
|
34
|
+
const over = input.scrollWidth - input.clientWidth;
|
|
35
|
+
const width = over > 0 ? Math.min(box.offsetWidth + over + 1, FITTED_MAX_PX) : 0;
|
|
36
|
+
if (width > box.offsetWidth) {
|
|
37
|
+
box.style.minWidth = `${width}px`;
|
|
38
|
+
box.dataset.grown = "";
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
delete box.dataset.grown;
|
|
42
|
+
}
|
|
43
|
+
}, [boxRef]);
|
|
44
|
+
useLayoutEffect(fit, [fit]);
|
|
45
|
+
return (_jsxs("span", { ref: boxRef, onInput: fit, className: "group/fitted relative flex h-full w-full min-w-0 shrink-0 data-grown:z-2", children: [_jsx("span", { "aria-hidden": true, className: cx("pointer-events-none absolute inset-y-0 -inset-x-(--vk-px) -z-1 hidden rounded-sm border border-(color:--vk-border-brand) shadow-lg shadow-black/20 group-data-grown/fitted:block dark:shadow-black/50", GRID_GROUND) }), children] }));
|
|
46
|
+
}
|
|
47
|
+
function UnderCellConversion({ figure }) {
|
|
48
|
+
const ref = useRef(null);
|
|
49
|
+
useKeepInside(ref);
|
|
50
|
+
return (_jsx("span", { ref: ref, className: UNDER_CELL_CLASS, children: _jsx(ConversionLine, { figure: figure }) }));
|
|
25
51
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { FieldDefOf, LocationValue } from "@viewkitjs/fields";
|
|
3
|
+
/**
|
|
4
|
+
* The GRID's host around the shared `LocationEditor`. Anchored, like the name
|
|
5
|
+
* and value list editors: a country and its parts do not fit a cell, so they
|
|
6
|
+
* open in a panel under it while the cell's own place stays on screen. The edit
|
|
7
|
+
* session owns the one-answer guard and the exit gap; the editor panel opens the
|
|
8
|
+
* popover on a desktop and the sheet on a phone, titled with the column's
|
|
9
|
+
* header. An emptied place always reaches `refuse`, so a field that can't be
|
|
10
|
+
* emptied says so in the editor rather than closing on nothing. No seed: a key
|
|
11
|
+
* typed on a place cell opens the place as it is.
|
|
12
|
+
*/
|
|
13
|
+
export declare function GridPlaceEditor({ field, title, initial, refuse, onCommit, onCancel, onTab, onEnter, }: {
|
|
14
|
+
field: FieldDefOf<"location">;
|
|
15
|
+
/** The field's name: the sheet's title on a phone. */
|
|
16
|
+
title: ReactNode;
|
|
17
|
+
initial: LocationValue | null;
|
|
18
|
+
/** The grid's judgement of a place before it is written, an emptied one (`null`) included: its
|
|
19
|
+
* reason when it would refuse it. A refused place keeps the editor open with that reason. */
|
|
20
|
+
refuse?: (place: LocationValue | null) => string | null;
|
|
21
|
+
onCommit: (place: LocationValue | null) => void;
|
|
22
|
+
onCancel: () => void;
|
|
23
|
+
onTab?: (backwards: boolean) => void;
|
|
24
|
+
/** Commit happened via Enter — advance one row down. */
|
|
25
|
+
onEnter?: () => void;
|
|
26
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef } from "react";
|
|
4
|
+
import { EditorPanel } from "../../editors/EditorPanel.js";
|
|
5
|
+
import { LocationEditor } from "../../editors/LocationEditor.js";
|
|
6
|
+
import { useGridEditSession } from "./grid-edit-session.js";
|
|
7
|
+
export function GridPlaceEditor({ field, title, initial, refuse, onCommit, onCancel, onTab, onEnter, }) {
|
|
8
|
+
const anchorRef = useRef(null);
|
|
9
|
+
const editorRef = useRef(null);
|
|
10
|
+
const { session, close } = useGridEditSession({
|
|
11
|
+
editorRef,
|
|
12
|
+
refuse: refuse && ((place) => refuse(place)),
|
|
13
|
+
onCommit: (place) => onCommit(place),
|
|
14
|
+
onCancel,
|
|
15
|
+
onTab,
|
|
16
|
+
onEnter,
|
|
17
|
+
});
|
|
18
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, "aria-hidden": true, className: "pointer-events-none absolute inset-0" }), _jsx(EditorPanel, { session: session, title: title, anchor: anchorRef, align: "start", sideOffset: 4, initialFocus: false, panelData: { "data-slot": "vk-grid-editor" }, onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: "z-90 w-96 p-2", children: (surface) => {
|
|
19
|
+
const editor = (_jsx(LocationEditor, { ref: editorRef, field: field, initial: initial, allowEmpty: true, onRequestClose: close }));
|
|
20
|
+
return surface === "sheet" ? _jsx("div", { className: "px-4 pb-4", children: editor }) : editor;
|
|
21
|
+
} })] }));
|
|
22
|
+
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { RangePreset, RangeValue } from "@viewkitjs/fields";
|
|
2
3
|
/**
|
|
3
|
-
* The GRID's host around the shared `RangeEditor` —
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* The GRID's host around the shared `RangeEditor` — like the number host: the
|
|
5
|
+
* edit session owns the one-answer guard and the editor panel decides where it
|
|
6
|
+
* opens. On a desktop the two boxes replace the cell's content, the write lands
|
|
7
|
+
* at once, and only then does focus move; on a phone they open in the sheet and
|
|
8
|
+
* the answer waits for the sheet to slide away.
|
|
6
9
|
*/
|
|
7
|
-
export declare function GridRangeEditor({ initial, seed, decimals, allowEmpty, suffix, onCommit, onCancel, onTab, onEnter, }: {
|
|
10
|
+
export declare function GridRangeEditor({ title, initial, seed, decimals, allowEmpty, suffix, bands, onCommit, onCancel, onTab, onEnter, refuse, }: {
|
|
11
|
+
/** The field's name: the sheet's title on a phone. */
|
|
12
|
+
title: ReactNode;
|
|
8
13
|
initial: RangeValue | null;
|
|
9
14
|
/** Type-to-replace: the character that opened this editor replaces the low box. */
|
|
10
15
|
seed?: string;
|
|
@@ -12,9 +17,14 @@ export declare function GridRangeEditor({ initial, seed, decimals, allowEmpty, s
|
|
|
12
17
|
allowEmpty?: boolean;
|
|
13
18
|
/** "%", a currency code — drawn after the high box. */
|
|
14
19
|
suffix?: string;
|
|
20
|
+
/** The field's bands: a menu under the cell on the desktop, listed under the boxes in the sheet. */
|
|
21
|
+
bands?: readonly RangePreset[];
|
|
15
22
|
onCommit: (payload: RangeValue) => void;
|
|
16
23
|
onCancel: () => void;
|
|
17
24
|
onTab?: (backwards: boolean) => void;
|
|
18
25
|
/** Commit happened via Enter — advance one row down. */
|
|
19
26
|
onEnter?: () => void;
|
|
27
|
+
/** The grid's judgement of a value before it is written: its reason when it would refuse it.
|
|
28
|
+
* A refused value keeps the editor open with that reason. */
|
|
29
|
+
refuse?: (value: RangeValue) => string | null;
|
|
20
30
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useRef } from "react";
|
|
4
4
|
import { RangeEditor } from "../../editors/RangeEditor.js";
|
|
5
|
-
|
|
5
|
+
import { EditorPanel } from "../../editors/EditorPanel.js";
|
|
6
|
+
import { GridRefusal, useGridEditSession } from "./grid-edit-session.js";
|
|
7
|
+
export function GridRangeEditor({ title, initial, seed, decimals = 0, allowEmpty = false, suffix, bands, onCommit, onCancel, onTab, onEnter, refuse, }) {
|
|
6
8
|
const editorRef = useRef(null);
|
|
7
|
-
const
|
|
8
|
-
const close = (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (reason === "tab")
|
|
20
|
-
onTab?.(false);
|
|
21
|
-
if (reason === "shift-tab")
|
|
22
|
-
onTab?.(true);
|
|
23
|
-
};
|
|
24
|
-
return (_jsx("span", { "data-slot": "vk-grid-editor", className: "flex h-full w-full min-w-0", children: _jsx(RangeEditor, { ref: editorRef, initial: initial, seed: seed, decimals: decimals, allowEmpty: allowEmpty, suffix: suffix, onRequestClose: close }) }));
|
|
9
|
+
const anchorRef = useRef(null);
|
|
10
|
+
const { session, close } = useGridEditSession({
|
|
11
|
+
editorRef,
|
|
12
|
+
inPlace: true,
|
|
13
|
+
refuse: refuse && ((value) => refuse(value)),
|
|
14
|
+
onCommit: (payload) => onCommit(payload),
|
|
15
|
+
onCancel,
|
|
16
|
+
onTab,
|
|
17
|
+
onEnter,
|
|
18
|
+
});
|
|
19
|
+
const editor = (sheet) => (_jsx(RangeEditor, { ref: editorRef, initial: initial, seed: seed, decimals: decimals, allowEmpty: allowEmpty, suffix: suffix, bands: bands, bandsAt: sheet ? "below" : "popover", boxClassName: sheet ? "h-10 rounded-md border border-(color:--vk-border) px-2" : undefined, onRequestClose: close }));
|
|
20
|
+
return (_jsx(EditorPanel, { session: session, title: title, anchor: anchorRef, inPlace: true, sheetOnPhone: true, children: (surface) => surface === "sheet" ? (_jsx("div", { className: "px-2 pb-3", children: editor(true) })) : (_jsxs("span", { ref: anchorRef, "data-slot": "vk-grid-editor", className: "relative flex h-full w-full min-w-0", children: [editor(false), _jsx(GridRefusal, { reason: session.refusal })] })) }));
|
|
25
21
|
}
|
|
@@ -1,21 +1,45 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* The candidate list is the column's, not the table's: every subscription you
|
|
9
|
-
* could link to, including ones no row currently points at — which is the whole
|
|
10
|
-
* difference from the Filter panel's list, and the reason a table of ten rows
|
|
11
|
-
* can still move a transaction onto any of seventy subscriptions.
|
|
12
|
-
*/
|
|
13
|
-
export declare function GridRelationEditor({ candidates, current, clearable, onCommit, onCancel, }: {
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { RelationDraftLink } from "@viewkitjs/fields";
|
|
3
|
+
import { type RelationSetItem } from "../../editors/RelationEditor.js";
|
|
4
|
+
import type { RelationCellCreate, RelationSource } from "../../fields/relation-source-types.js";
|
|
5
|
+
export declare function GridRelationEditor({ title, candidates, current, clearable, seed, create, refuse, onCommit, onLink, onCancel, }: {
|
|
6
|
+
/** The field's name: the sheet's title on a phone. */
|
|
7
|
+
title: ReactNode;
|
|
14
8
|
candidates: RelationSource;
|
|
15
9
|
/** The linked id, or null when the cell is empty. */
|
|
16
10
|
current: string | null;
|
|
17
11
|
/** Offer "None" — only when the column says the link is optional. */
|
|
18
12
|
clearable: boolean;
|
|
19
|
-
|
|
13
|
+
/** The letter typed on the cell that opened the picker: its search starts from it. */
|
|
14
|
+
seed?: string;
|
|
15
|
+
/** The app's create row, from the column. */
|
|
16
|
+
create?: RelationCellCreate;
|
|
17
|
+
/** The pick, with its kind where the candidate named one. */
|
|
18
|
+
onCommit: (id: string | null, kind?: string) => void;
|
|
19
|
+
/** The record the app's form created, to link to the cell once the editor is gone. */
|
|
20
|
+
onLink?: (id: string, kind?: string) => void;
|
|
21
|
+
onCancel: () => void;
|
|
22
|
+
/** The grid's judgement of a value before it is written: its reason when it would refuse it.
|
|
23
|
+
* A refused value keeps the editor open with that reason. */
|
|
24
|
+
refuse?: (value: string | null, kind?: string) => string | null;
|
|
25
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
/**
|
|
27
|
+
* The grid's host for a relation holding several records: the set is edited with the list open and
|
|
28
|
+
* leaves as one change, as pick many does — Tab and Shift-Tab save it and move on.
|
|
29
|
+
*/
|
|
30
|
+
export declare function GridRelationSetEditor({ title, candidates, current, lead, seed, create, refuse, onCommit, onLink, onCancel, onTab, }: {
|
|
31
|
+
title: ReactNode;
|
|
32
|
+
candidates: RelationSource;
|
|
33
|
+
/** The linked records, in their stored order, with what each row shows. */
|
|
34
|
+
current: readonly RelationSetItem[];
|
|
35
|
+
/** The field leads by a flag. */
|
|
36
|
+
lead: boolean;
|
|
37
|
+
seed?: string;
|
|
38
|
+
create?: RelationCellCreate;
|
|
39
|
+
onCommit: (links: RelationDraftLink[]) => void;
|
|
40
|
+
/** The record the app's form created, added to the set saved at close (or the set as it opened). */
|
|
41
|
+
onLink?: (base: RelationDraftLink[], added: RelationDraftLink) => void;
|
|
20
42
|
onCancel: () => void;
|
|
43
|
+
onTab?: (backwards: boolean) => void;
|
|
44
|
+
refuse?: (links: RelationDraftLink[]) => string | null;
|
|
21
45
|
}): import("react/jsx-runtime").JSX.Element;
|