@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
|
@@ -23,10 +23,12 @@ import type { PickerOption } from "./SelectEditor.js";
|
|
|
23
23
|
* through them. That is also why a pick does NOT close this core — it is the
|
|
24
24
|
* one that never sees the `pick` reason.
|
|
25
25
|
*
|
|
26
|
-
* ## Its close rule
|
|
26
|
+
* ## Its close rule
|
|
27
27
|
*
|
|
28
|
-
* An outside click COMMITS (you built a set; leaving keeps it) and
|
|
29
|
-
*
|
|
28
|
+
* An outside click COMMITS (you built a set; leaving keeps it), Tab and
|
|
29
|
+
* Shift-Tab commit too and move on, and Escape DISCARDS, as the date editor's
|
|
30
|
+
* does. The pickers that end on a pick (the
|
|
31
|
+
* select, the relation) cancel on both. Closing unchanged is a noop —
|
|
30
32
|
* the dirty check is `sameListValue`, the same one the commit path uses, so
|
|
31
33
|
* opening a cell to look at it never writes to it.
|
|
32
34
|
*/
|
|
@@ -52,8 +54,11 @@ export declare const ChipsEditor: import("react").ForwardRefExoticComponent<{
|
|
|
52
54
|
* added value goes through it on the way in — the same function the route
|
|
53
55
|
* applies, so `Ops Team` and `ops-team` cannot come apart. */
|
|
54
56
|
normalize?: (raw: string) => string;
|
|
55
|
-
/** The core saw a key that means "done" (Escape). Picks never close it. */
|
|
57
|
+
/** The core saw a key that means "done" (Escape, Tab, Shift-Tab). Picks never close it. */
|
|
56
58
|
onRequestClose: (reason: CloseReason) => void;
|
|
57
59
|
/** The host's words for this panel (fields' messages); default: the provider's conventions. */
|
|
58
60
|
message?: FieldMessageResolver;
|
|
61
|
+
/** Offer a row that adds the typed text when nothing held or offered is it. Default true; a closed
|
|
62
|
+
* vocabulary passes false, and its search only filters what it offers. */
|
|
63
|
+
creatable?: boolean;
|
|
59
64
|
} & import("react").RefAttributes<ChipsEditorHandle>>;
|
|
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState, } from "react";
|
|
4
4
|
import { sameListValue, } from "@viewkitjs/fields";
|
|
5
5
|
import { useViews } from "../provider/context.js";
|
|
6
|
-
export const ChipsEditor = forwardRef(function ChipsEditor({ values, suggestions, resolve, normalize, onRequestClose, message }, ref) {
|
|
6
|
+
export const ChipsEditor = forwardRef(function ChipsEditor({ values, suggestions, resolve, normalize, onRequestClose, message, creatable = true }, ref) {
|
|
7
7
|
const [draft, setDraft] = useState(values);
|
|
8
8
|
const [search, setSearch] = useState("");
|
|
9
9
|
const inputRef = useRef(null);
|
|
@@ -37,7 +37,7 @@ export const ChipsEditor = forwardRef(function ChipsEditor({ values, suggestions
|
|
|
37
37
|
: rows;
|
|
38
38
|
const typed = clean(search);
|
|
39
39
|
const needle = typed.toLowerCase();
|
|
40
|
-
const canAdd = typed !== "" && ![...draft, ...rows].some((value) => value.toLowerCase() === needle);
|
|
40
|
+
const canAdd = creatable && typed !== "" && ![...draft, ...rows].some((value) => value.toLowerCase() === needle);
|
|
41
41
|
const add = (value) => {
|
|
42
42
|
if (!draftRef.current.includes(value))
|
|
43
43
|
setBoth([...draftRef.current, value]);
|
|
@@ -66,6 +66,10 @@ export const ChipsEditor = forwardRef(function ChipsEditor({ values, suggestions
|
|
|
66
66
|
onFieldKeyDown(event);
|
|
67
67
|
if (event.key === "Escape")
|
|
68
68
|
onRequestClose("escape");
|
|
69
|
+
if (event.key === "Tab") {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
onRequestClose(event.shiftKey ? "shift-tab" : "tab");
|
|
72
|
+
}
|
|
69
73
|
}, placeholder: draft.length === 0 ? words({ key: "chips.add-placeholder" }) : "", className: "h-5 min-w-20 flex-1 bg-transparent text-[13px] outline-hidden placeholder:text-(color:--vk-fg-subtlest)" })] }), _jsxs(Command.List, { className: "max-h-64 overscroll-contain scrollbar-overlay", children: [visible.length === 0 && !canAdd && (_jsx(Command.Empty, { className: "py-4 text-center text-xs text-(color:--vk-fg-subtle)", children: rows.length === 0 ? words({ key: "chips.everything-picked" }) : words({ key: "editor.nothing-matches" }) })), _jsx(Command.Group, { className: "p-0", children: _jsxs(List, { children: [visible.map((value) => {
|
|
70
74
|
const option = resolve(value);
|
|
71
75
|
return (_jsx(Command.Item, { value: value, onSelect: () => add(value), children: _jsx(RowContent, { size: "compact", label: _jsx(Tag, { label: option.label, color: option.color ?? "gray" }) }) }, value));
|
|
@@ -2,9 +2,8 @@ import { type CloseReason, type CloseResolution, type FieldMessageResolver } fro
|
|
|
2
2
|
export type DateEditorHandle = {
|
|
3
3
|
/**
|
|
4
4
|
* THE close handshake (lib/fields/close): the host learned that a close
|
|
5
|
-
* happened and asks what it means.
|
|
6
|
-
*
|
|
7
|
-
* not read; it is the host's to distinguish. Pure and idempotent: no state
|
|
5
|
+
* happened and asks what it means. Escape discards; every other reason
|
|
6
|
+
* commits the draft when dirty, else nothing. Pure and idempotent: no state
|
|
8
7
|
* moves, no timer runs, nothing is called back. The host closes its
|
|
9
8
|
* popover, waits its own exit gap, and then applies the answer.
|
|
10
9
|
*/
|
|
@@ -15,11 +14,27 @@ export declare const DateEditor: import("react").ForwardRefExoticComponent<{
|
|
|
15
14
|
initial?: string;
|
|
16
15
|
/** Time chip starts empty and stays out of the commit until set (form
|
|
17
16
|
* mode). Without it, the chip carries the stored time or 00:00 and every
|
|
18
|
-
* commit includes one
|
|
17
|
+
* commit includes one. */
|
|
19
18
|
timeOptional?: boolean;
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
19
|
+
/** A calendar-day field: no time chip, the commit is "YYYY-MM-DD", and a
|
|
20
|
+
* day click or a quick day asks the host to close with `pick`. Default false. */
|
|
21
|
+
dayOnly?: boolean;
|
|
22
|
+
/** The date may be emptied: a Clear row after the calendar, which asks the
|
|
23
|
+
* host to close with `pick` and commits "" (nothing when there was no date). */
|
|
24
|
+
clearable?: boolean;
|
|
25
|
+
/** The text the date box opens with (a character typed on the cell that
|
|
26
|
+
* opened the panel): focused, the caret after it, and read as a typed date. */
|
|
27
|
+
seed?: string;
|
|
28
|
+
/** Put the caret in the date box as the panel opens, without scrolling, so the keyboard is in the panel and Tab
|
|
29
|
+
* walks its controls. Default false: a host whose surface puts focus there itself, or never should (a phone's
|
|
30
|
+
* sheet opens with the keyboard down), leaves it off. A seed focuses the box either way. */
|
|
31
|
+
focusDate?: boolean;
|
|
32
|
+
/** The panel saw a key that means "done" (Enter) or "leave" (Escape), or a
|
|
33
|
+
* pick (`dayOnly`'s day click, the Clear row). It never closes itself — the
|
|
34
|
+
* host closes, then asks `resolveClose`. */
|
|
22
35
|
onRequestClose: (reason: CloseReason) => void;
|
|
23
36
|
/** The host's words for this panel (fields' messages); default: the provider's conventions. */
|
|
24
37
|
message?: FieldMessageResolver;
|
|
38
|
+
/** The calendar takes the panel's whole width (a phone's sheet), rather than its own. Default false. */
|
|
39
|
+
fill?: boolean;
|
|
25
40
|
} & import("react").RefAttributes<DateEditorHandle>>;
|
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
3
|
-
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef, useState, } from "react";
|
|
4
4
|
import { formatChipDate, normalizeTime, parseDateText, toYmd, } from "@viewkitjs/fields";
|
|
5
5
|
import { fromDayKey, toDayKey } from "@viewkitjs/fields/query";
|
|
6
6
|
import { cx } from "../internal/cx.js";
|
|
7
7
|
import { useViews } from "../provider/context.js";
|
|
8
|
+
import { isDesktopNow } from "../provider/desktop.js";
|
|
9
|
+
const QUICK_DAYS = [
|
|
10
|
+
{ key: "date.today", offset: () => 0 },
|
|
11
|
+
{ key: "date.tomorrow", offset: () => 1 },
|
|
12
|
+
{ key: "date.next-monday", offset: (weekday) => (8 - weekday) % 7 || 7 },
|
|
13
|
+
];
|
|
14
|
+
function quickDay(offset) {
|
|
15
|
+
const now = new Date();
|
|
16
|
+
return new Date(now.getFullYear(), now.getMonth(), now.getDate() + offset(now.getDay()));
|
|
17
|
+
}
|
|
18
|
+
const FOCUSABLE = "input, select, textarea, button, a[href], [tabindex]";
|
|
19
|
+
function tabEnds(root) {
|
|
20
|
+
const reachable = Array.from(root.querySelectorAll(FOCUSABLE)).filter((element) => element.tabIndex >= 0 &&
|
|
21
|
+
!element.disabled &&
|
|
22
|
+
element.closest("[hidden], [inert]") === null);
|
|
23
|
+
return { first: reachable[0], last: reachable.at(-1) };
|
|
24
|
+
}
|
|
8
25
|
const CALENDAR_START = "1900-01";
|
|
9
26
|
const CALENDAR_END = `${new Date().getFullYear() + 10}-12`;
|
|
10
27
|
const TIME_OPTIONS = Array.from({ length: 96 }, (_, i) => {
|
|
@@ -12,22 +29,29 @@ const TIME_OPTIONS = Array.from({ length: 96 }, (_, i) => {
|
|
|
12
29
|
const mm = String((i % 4) * 15).padStart(2, "0");
|
|
13
30
|
return `${hh}:${mm}`;
|
|
14
31
|
});
|
|
32
|
+
function readStored(iso) {
|
|
33
|
+
if (!iso)
|
|
34
|
+
return undefined;
|
|
35
|
+
const parsed = fromDayKey(iso) ?? new Date(iso);
|
|
36
|
+
return Number.isNaN(parsed.getTime()) ? undefined : parsed;
|
|
37
|
+
}
|
|
15
38
|
function initialHasTime(iso, parsed) {
|
|
16
39
|
if (!iso || !parsed)
|
|
17
40
|
return false;
|
|
18
41
|
return /T/.test(iso);
|
|
19
42
|
}
|
|
20
|
-
export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional = false, onRequestClose, message }, ref) {
|
|
43
|
+
export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional = false, dayOnly = false, clearable = false, seed, focusDate = false, onRequestClose, message, fill = false, }, ref) {
|
|
21
44
|
const timeRef = useRef(null);
|
|
45
|
+
const dateRef = useRef(null);
|
|
22
46
|
const views = useViews();
|
|
23
47
|
const words = message ?? views.conventions.messages;
|
|
24
|
-
const { Calendar } = views.components;
|
|
48
|
+
const { Calendar, Input } = views.components;
|
|
49
|
+
const { List, Row } = views.atoms;
|
|
25
50
|
const DateGlyph = views.icons.date;
|
|
26
51
|
const TimeGlyph = views.icons.time;
|
|
27
52
|
const [timeOpen, setTimeOpen] = useState(false);
|
|
28
53
|
const activeTimeRef = useRef(null);
|
|
29
|
-
const
|
|
30
|
-
const valid = parsed && !Number.isNaN(parsed.getTime()) ? parsed : undefined;
|
|
54
|
+
const valid = readStored(initial);
|
|
31
55
|
const [day, setDay] = useState(valid);
|
|
32
56
|
const [month, setMonth] = useState(valid);
|
|
33
57
|
const hadTime = initialHasTime(initial, valid);
|
|
@@ -37,24 +61,70 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
37
61
|
? ""
|
|
38
62
|
: "00:00";
|
|
39
63
|
const [timeVal, setTimeVal] = useState(initialTime);
|
|
40
|
-
const [dateVal, setDateVal] = useState(() => formatChipDate(valid ?? new Date()));
|
|
41
|
-
const touchedRef = useRef(
|
|
64
|
+
const [dateVal, setDateVal] = useState(() => seed ?? formatChipDate(valid ?? new Date()));
|
|
65
|
+
const touchedRef = useRef(seed != null);
|
|
66
|
+
const dayRef = useRef(valid);
|
|
67
|
+
const dateTextRef = useRef(dateVal);
|
|
68
|
+
const timeTextRef = useRef(timeVal);
|
|
69
|
+
const clearedRef = useRef(false);
|
|
70
|
+
const writeDateText = (text) => {
|
|
71
|
+
clearedRef.current = false;
|
|
72
|
+
dateTextRef.current = text;
|
|
73
|
+
setDateVal(text);
|
|
74
|
+
};
|
|
75
|
+
const writeTime = (text) => {
|
|
76
|
+
clearedRef.current = false;
|
|
77
|
+
timeTextRef.current = text;
|
|
78
|
+
setTimeVal(text);
|
|
79
|
+
};
|
|
80
|
+
const chooseDay = (d) => {
|
|
81
|
+
touchedRef.current = true;
|
|
82
|
+
dayRef.current = d;
|
|
83
|
+
setDay(d);
|
|
84
|
+
setMonth(d);
|
|
85
|
+
writeDateText(formatChipDate(d));
|
|
86
|
+
setTimeOpen(false);
|
|
87
|
+
if (dayOnly) {
|
|
88
|
+
onRequestClose("pick");
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (isDesktopNow(views.desktopQuery))
|
|
92
|
+
dateRef.current?.focus({ preventScroll: true });
|
|
93
|
+
};
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (seed == null && !focusDate)
|
|
96
|
+
return;
|
|
97
|
+
const box = dateRef.current;
|
|
98
|
+
box?.focus({ preventScroll: true });
|
|
99
|
+
if (seed != null)
|
|
100
|
+
box?.setSelectionRange(seed.length, seed.length);
|
|
101
|
+
}, []);
|
|
42
102
|
const applyDateText = () => {
|
|
43
|
-
const base =
|
|
44
|
-
const typed = parseDateText(
|
|
103
|
+
const base = dayRef.current ?? valid ?? new Date();
|
|
104
|
+
const typed = parseDateText(dateTextRef.current, base.getFullYear());
|
|
45
105
|
if (typed) {
|
|
106
|
+
dayRef.current = typed;
|
|
46
107
|
setDay(typed);
|
|
47
108
|
setMonth(typed);
|
|
48
|
-
|
|
109
|
+
writeDateText(formatChipDate(typed));
|
|
49
110
|
return typed;
|
|
50
111
|
}
|
|
51
|
-
|
|
112
|
+
writeDateText(formatChipDate(base));
|
|
52
113
|
return undefined;
|
|
53
114
|
};
|
|
54
|
-
const resolveClose = () => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
115
|
+
const resolveClose = (reason) => {
|
|
116
|
+
if (reason === "escape")
|
|
117
|
+
return { kind: "cancel" };
|
|
118
|
+
if (clearedRef.current)
|
|
119
|
+
return valid ? { kind: "commit", payload: "" } : { kind: "noop" };
|
|
120
|
+
const year = (dayRef.current ?? valid ?? new Date()).getFullYear();
|
|
121
|
+
const typed = parseDateText(dateTextRef.current, year);
|
|
122
|
+
const d = typed ?? dayRef.current ?? valid;
|
|
123
|
+
if (dayOnly) {
|
|
124
|
+
const changed = d != null && (valid ? toYmd(d) !== toYmd(valid) : touchedRef.current);
|
|
125
|
+
return changed && d ? { kind: "commit", payload: toYmd(d) } : { kind: "noop" };
|
|
126
|
+
}
|
|
127
|
+
const time = normalizeTime(timeTextRef.current) ?? (timeOptional ? null : initialTime);
|
|
58
128
|
const timePart = timeOptional ? time : (time ?? initialTime);
|
|
59
129
|
const dirty = d != null &&
|
|
60
130
|
(valid ? toYmd(d) !== toYmd(valid) || (timePart ?? "") !== initialTime : touchedRef.current);
|
|
@@ -70,9 +140,20 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
70
140
|
if (timeOpen)
|
|
71
141
|
activeTimeRef.current?.scrollIntoView({ block: "center" });
|
|
72
142
|
}, [timeOpen]);
|
|
73
|
-
|
|
143
|
+
const onTabOut = (event) => {
|
|
144
|
+
if (event.key !== "Tab" || event.altKey || event.ctrlKey || event.metaKey)
|
|
145
|
+
return;
|
|
146
|
+
const { first, last } = tabEnds(event.currentTarget);
|
|
147
|
+
const leaving = event.shiftKey ? event.target === first : event.target === last;
|
|
148
|
+
if (!leaving)
|
|
149
|
+
return;
|
|
150
|
+
event.preventDefault();
|
|
151
|
+
event.stopPropagation();
|
|
152
|
+
onRequestClose(event.shiftKey ? "shift-tab" : "tab");
|
|
153
|
+
};
|
|
154
|
+
return (_jsxs("div", { "data-slot": "vk-date-editor", className: "contents", onKeyDownCapture: onTabOut, children: [_jsxs("div", { className: "flex items-center gap-1.5 border-b border-(color:--vk-border) p-2", children: [_jsxs("div", { className: "flex h-8 min-w-0 flex-1 items-center gap-2 rounded-lg bg-(color:--vk-neutral) px-2.5 focus-within:bg-(color:--vk-neutral-hovered)", children: [_jsx(DateGlyph, { className: "h-3.5 w-3.5 shrink-0 text-(color:--vk-fg-subtlest)" }), _jsx(Input, { ref: dateRef, type: "text", value: dateVal, onChange: (e) => {
|
|
74
155
|
touchedRef.current = true;
|
|
75
|
-
|
|
156
|
+
writeDateText(e.target.value);
|
|
76
157
|
}, onBlur: applyDateText, onFocus: () => setTimeOpen(false), placeholder: words({ key: "date.placeholder" }), "aria-label": words({ key: "date.label" }), onClick: (e) => e.stopPropagation(), onKeyDown: (e) => {
|
|
77
158
|
e.stopPropagation();
|
|
78
159
|
if (e.key === "Enter") {
|
|
@@ -82,19 +163,22 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
82
163
|
else if (e.key === "Escape") {
|
|
83
164
|
onRequestClose("escape");
|
|
84
165
|
}
|
|
85
|
-
}, className: "w-0 min-w-0 flex-1 select-text bg-transparent text-sm tabular-nums text-(color:--vk-fg) outline-hidden placeholder:text-(color:--vk-fg-subtlest)" })] }), _jsxs("div", { className: "relative shrink-0", children: [_jsxs("div", { className: "flex h-8 cursor-text items-center gap-2 rounded-lg bg-(color:--vk-neutral) px-2.5 focus-within:bg-(color:--vk-neutral-hovered)", onClick: (e) => {
|
|
166
|
+
}, className: "w-0 min-w-0 flex-1 select-text bg-transparent text-sm tabular-nums text-(color:--vk-fg) outline-hidden placeholder:text-(color:--vk-fg-subtlest)" })] }), !dayOnly && (_jsxs("div", { className: "relative shrink-0", children: [_jsxs("div", { className: "flex h-8 cursor-text items-center gap-2 rounded-lg bg-(color:--vk-neutral) px-2.5 focus-within:bg-(color:--vk-neutral-hovered)", onClick: (e) => {
|
|
86
167
|
e.stopPropagation();
|
|
87
168
|
setTimeOpen(true);
|
|
88
169
|
timeRef.current?.focus();
|
|
89
|
-
}, children: [_jsx(TimeGlyph, { className: "h-3.5 w-3.5 text-(color:--vk-fg-subtlest)" }), _jsx(
|
|
170
|
+
}, children: [_jsx(TimeGlyph, { className: "h-3.5 w-3.5 text-(color:--vk-fg-subtlest)" }), _jsx(Input, { ref: timeRef, type: "text", inputMode: "numeric", value: timeVal, onChange: (e) => {
|
|
90
171
|
touchedRef.current = true;
|
|
91
|
-
|
|
172
|
+
writeTime(e.target.value);
|
|
92
173
|
}, onFocus: () => setTimeOpen(true), placeholder: words({ key: "time.placeholder" }), "aria-label": words({ key: "time.label" }), onKeyDown: (e) => {
|
|
93
174
|
e.stopPropagation();
|
|
94
175
|
if (e.key === "Enter") {
|
|
95
176
|
e.preventDefault();
|
|
96
177
|
onRequestClose("enter");
|
|
97
178
|
}
|
|
179
|
+
else if (e.key === "Tab") {
|
|
180
|
+
setTimeOpen(false);
|
|
181
|
+
}
|
|
98
182
|
else if (e.key === "Escape") {
|
|
99
183
|
if (timeOpen)
|
|
100
184
|
setTimeOpen(false);
|
|
@@ -106,17 +190,21 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
106
190
|
return (_jsx("button", { ref: active ? activeTimeRef : undefined, type: "button", onClick: (e) => {
|
|
107
191
|
e.stopPropagation();
|
|
108
192
|
touchedRef.current = true;
|
|
109
|
-
|
|
193
|
+
writeTime(t);
|
|
110
194
|
setTimeOpen(false);
|
|
111
195
|
timeRef.current?.focus();
|
|
112
196
|
}, className: cx("w-full px-3 py-1.5 text-left text-sm tabular-nums hover:bg-(color:--vk-hovered)", active ? "bg-(color:--vk-neutral) font-medium text-(color:--vk-fg)" : "text-(color:--vk-fg-subtle)"), children: t }, t));
|
|
113
|
-
}) }))] })] }), _jsx(
|
|
197
|
+
}) }))] }))] }), _jsx("div", { className: "flex gap-1 px-2 pt-2", children: QUICK_DAYS.map((quick) => (_jsx("button", { type: "button", onClick: (e) => {
|
|
198
|
+
e.stopPropagation();
|
|
199
|
+
chooseDay(quickDay(quick.offset));
|
|
200
|
+
}, className: "h-7 rounded-md bg-(color:--vk-neutral) px-2 text-xs text-(color:--vk-fg-subtle) hover:bg-(color:--vk-neutral-hovered) hover:text-(color:--vk-fg)", children: words({ key: quick.key }) }, quick.key))) }), _jsx(Calendar, { locale: views.conventions.locale, ...(fill ? { className: "w-full" } : {}), value: (day ?? valid) ? toDayKey((day ?? valid)) : null, onChange: (picked) => {
|
|
114
201
|
const d = picked ? fromDayKey(picked) : null;
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
202
|
+
if (d)
|
|
203
|
+
chooseDay(d);
|
|
204
|
+
else if (dayOnly && dayRef.current)
|
|
205
|
+
chooseDay(dayRef.current);
|
|
206
|
+
}, month: month ? toDayKey(month).slice(0, 7) : undefined, onMonthChange: (next) => setMonth(fromDayKey(`${next}-01`) ?? undefined), captionLayout: "dropdown", startMonth: CALENDAR_START, endMonth: CALENDAR_END }), clearable && (_jsx("div", { className: "border-t border-(color:--vk-border) py-1", children: _jsx(List, { children: _jsx(Row, { size: "compact", tone: "muted", label: words({ key: "date.clear" }), onClick: () => {
|
|
207
|
+
clearedRef.current = true;
|
|
208
|
+
onRequestClose("pick");
|
|
209
|
+
} }) }) }))] }));
|
|
122
210
|
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type CSSProperties, type MouseEvent as ReactMouseEvent, type ReactNode } from "react";
|
|
2
|
+
import type { ViewsAlign, ViewsAnchor, ViewsSheetProps, ViewsSide } from "../provider/components.js";
|
|
3
|
+
import type { EditSession } from "./edit-session.js";
|
|
4
|
+
/**
|
|
5
|
+
* THE EDITOR PANEL — where an editor opens, for every surface: the app's popover on a desktop,
|
|
6
|
+
* the app's sheet on a phone, and nothing at all for a type-in editor that stays where its value
|
|
7
|
+
* stands. The editor inside never reads which.
|
|
8
|
+
*
|
|
9
|
+
* It owns what each surface's dismissals MEAN, so no host decides them: on a desktop the popover's
|
|
10
|
+
* Escape discards (unless it comes from an inner level the editor marked, `EDITOR_INNER_ESCAPE`,
|
|
11
|
+
* which the editor closes itself), its outside press is the editor's own rule, and a focus leaving it
|
|
12
|
+
* closes as a blur; on a phone every way a sheet
|
|
13
|
+
* goes away (a swipe, its backdrop, Escape, the bar's ✕) discards, and the bar's ✓ closes as done.
|
|
14
|
+
* A refusal the host gave stays on screen under the editor, in the popover and the sheet; in
|
|
15
|
+
* place, the host's own box draws it.
|
|
16
|
+
*
|
|
17
|
+
* The surface is chosen ONCE, when the session opens: a window crossing the desktop width
|
|
18
|
+
* mid-edit keeps the panel it opened in until the session ends.
|
|
19
|
+
*/
|
|
20
|
+
export type EditorPanelProps = {
|
|
21
|
+
/** The session the host opened: its `open`, its `close` and its `refusal`. Either mode. */
|
|
22
|
+
session: EditSession;
|
|
23
|
+
/** The field's name: the sheet's title. */
|
|
24
|
+
title: ReactNode;
|
|
25
|
+
/** What the popover opens on, on the desktop. */
|
|
26
|
+
anchor: ViewsAnchor;
|
|
27
|
+
/** A type-in editor: on the desktop its children are drawn where they stand, with no popover. Default false. */
|
|
28
|
+
inPlace?: boolean;
|
|
29
|
+
/** With `inPlace`: on the phone, open the type-in editor in the sheet instead of where it stands.
|
|
30
|
+
* Default false. A picker always opens the sheet on the phone, and ignores this. */
|
|
31
|
+
sheetOnPhone?: boolean;
|
|
32
|
+
/** The sheet's snap hint. Default "auto". */
|
|
33
|
+
snap?: ViewsSheetProps["snap"];
|
|
34
|
+
/** Handed to the popover as they are. */
|
|
35
|
+
side?: ViewsSide;
|
|
36
|
+
align?: ViewsAlign;
|
|
37
|
+
sideOffset?: number;
|
|
38
|
+
alignOffset?: number;
|
|
39
|
+
initialFocus?: boolean;
|
|
40
|
+
chrome?: "panel" | "menu";
|
|
41
|
+
className?: string;
|
|
42
|
+
style?: CSSProperties;
|
|
43
|
+
/** Set on the popover's panel, over `{ "data-slot": "vk-editor-panel" }`. */
|
|
44
|
+
panelData?: Readonly<Record<`data-${string}`, string>>;
|
|
45
|
+
/** A click inside the popover or the sheet. The sheet keeps every press to itself after this; the
|
|
46
|
+
* popover leaves that to the host (a grid host stops it here). */
|
|
47
|
+
onPanelClick?: (event: ReactMouseEvent<HTMLDivElement>) => void;
|
|
48
|
+
/** The editor, or a function of the surface the panel chose, for a type-in host that draws
|
|
49
|
+
* differently in place (its own refusal, say) than in the sheet. */
|
|
50
|
+
children: ReactNode | ((surface: EditorSurface) => ReactNode);
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* The mark an editor puts on an inner level of its own (a list it opened from its boxes) while
|
|
54
|
+
* Escape there means "close that level", not "throw the edit away". An app's popover may hear
|
|
55
|
+
* Escape before the editor does (on the document, in the capture phase), so the panel asks: an
|
|
56
|
+
* Escape from inside the mark is left to the editor.
|
|
57
|
+
*/
|
|
58
|
+
export declare const EDITOR_INNER_ESCAPE = "data-vk-inner-escape";
|
|
59
|
+
/** Where the panel opened its editor: the app's popover, its sheet, or where the value stands. */
|
|
60
|
+
export type EditorSurface = "popover" | "sheet" | "in-place";
|
|
61
|
+
export declare function EditorPanel({ session, title, anchor, inPlace, sheetOnPhone, snap, panelData, children, ...popover }: EditorPanelProps): ReactNode;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useLayoutEffect, useState, } from "react";
|
|
4
|
+
import { useDesktop } from "../provider/desktop.js";
|
|
5
|
+
import { useViews } from "../provider/context.js";
|
|
6
|
+
export const EDITOR_INNER_ESCAPE = "data-vk-inner-escape";
|
|
7
|
+
function innerEscape(event) {
|
|
8
|
+
const target = event.target;
|
|
9
|
+
return target instanceof Element && target.closest(`[${EDITOR_INNER_ESCAPE}]`) !== null;
|
|
10
|
+
}
|
|
11
|
+
export function EditorPanel({ session, title, anchor, inPlace = false, sheetOnPhone = false, snap = "auto", panelData, children, ...popover }) {
|
|
12
|
+
const views = useViews();
|
|
13
|
+
const { Popover, Sheet, Button } = views.components;
|
|
14
|
+
const Discard = views.icons.close;
|
|
15
|
+
const Save = views.icons.check;
|
|
16
|
+
const desktop = useDesktop();
|
|
17
|
+
const [surface] = useState(() => desktop ? (inPlace ? "in-place" : "popover") : inPlace && !sheetOnPhone ? "in-place" : "sheet");
|
|
18
|
+
const { open, close, refusal } = session;
|
|
19
|
+
const editor = typeof children === "function" ? children(surface) : children;
|
|
20
|
+
useLayoutEffect(() => {
|
|
21
|
+
if (surface !== "in-place")
|
|
22
|
+
return;
|
|
23
|
+
const box = anchor instanceof HTMLElement ? anchor : anchor && "current" in anchor ? anchor.current : null;
|
|
24
|
+
box?.scrollIntoView?.({ block: "nearest", inline: "nearest" });
|
|
25
|
+
}, []);
|
|
26
|
+
if (surface === "in-place")
|
|
27
|
+
return editor;
|
|
28
|
+
const reason = refusal ? (_jsx("p", { role: "alert", "data-slot": "vk-editor-refusal", className: "px-2 pb-2 text-xs text-(color:--vk-danger)", children: refusal })) : null;
|
|
29
|
+
if (surface === "popover") {
|
|
30
|
+
return (_jsxs(Popover, { ...popover, open: open, onOpenChange: (next, details) => {
|
|
31
|
+
if (next || details?.reason === "outside-press")
|
|
32
|
+
return;
|
|
33
|
+
if (details?.reason === "focus-out")
|
|
34
|
+
close("blur");
|
|
35
|
+
else
|
|
36
|
+
close(details?.reason === "escape-key" ? "escape" : "outside");
|
|
37
|
+
}, anchor: anchor, onEscape: (event) => {
|
|
38
|
+
if (innerEscape(event))
|
|
39
|
+
return false;
|
|
40
|
+
close("escape");
|
|
41
|
+
}, onOutsidePress: () => {
|
|
42
|
+
if (open)
|
|
43
|
+
close("outside");
|
|
44
|
+
}, panelData: { "data-slot": "vk-editor-panel", ...panelData }, children: [editor, reason] }));
|
|
45
|
+
}
|
|
46
|
+
const keep = (event) => event.stopPropagation();
|
|
47
|
+
return (_jsx("span", { className: "contents", onClick: (event) => {
|
|
48
|
+
popover.onPanelClick?.(event);
|
|
49
|
+
event.stopPropagation();
|
|
50
|
+
}, onDoubleClick: keep, onContextMenu: keep, children: _jsx(Sheet, { open: open, onOpenChange: (next) => {
|
|
51
|
+
if (!next)
|
|
52
|
+
close("escape");
|
|
53
|
+
}, title: title, snap: snap, children: _jsxs("div", { "data-slot": "vk-editor-panel", children: [_jsxs("div", { "data-slot": "vk-editor-bar", className: "flex items-center justify-between px-2 pb-1", children: [_jsx(Button, { variant: "ghost", size: "icon", "aria-label": views.messages({ key: "views.editors.discard" }), onClick: () => close("escape"), children: _jsx(Discard, { className: "size-4" }) }), _jsx(Button, { variant: "ghost", size: "icon", "aria-label": views.messages({ key: "views.editors.save" }), onClick: () => close("enter"), children: _jsx(Save, { className: "size-4" }) })] }), editor, reason] }) }) }));
|
|
54
|
+
}
|
|
@@ -18,5 +18,8 @@ export declare const LocationEditor: import("react").ForwardRefExoticComponent<{
|
|
|
18
18
|
initial: LocationValue | null;
|
|
19
19
|
allowEmpty?: boolean;
|
|
20
20
|
conventions?: FieldConventions;
|
|
21
|
+
/** How each part's box is drawn: `bare` for a popover's compact rows, `field` where the boxes stand on their
|
|
22
|
+
* own (a phone's sheet), each in the app's field frame. Default `bare`. */
|
|
23
|
+
chrome?: "bare" | "field";
|
|
21
24
|
onRequestClose: (reason: CloseReason) => void;
|
|
22
25
|
} & import("react").RefAttributes<LocationEditorHandle>>;
|
|
@@ -5,6 +5,7 @@ import { COUNTRY_CODES, countryName, LOCATION_PARTS, placeFormat, sameStoredValu
|
|
|
5
5
|
import { loadRegions, regionLabel } from "@viewkitjs/fields/places";
|
|
6
6
|
import { placeWordKey } from "../contract.js";
|
|
7
7
|
import { useViews } from "../provider/context.js";
|
|
8
|
+
import { EDITOR_INNER_ESCAPE } from "./EditorPanel.js";
|
|
8
9
|
const GENERIC = ["line1", "line2", "postalCode", "city", "region"];
|
|
9
10
|
function folded(text) {
|
|
10
11
|
return text.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase();
|
|
@@ -22,12 +23,12 @@ function withFilled(kept, draft) {
|
|
|
22
23
|
const filled = GENERIC.filter((part) => !kept.has(part) && draft[part]?.trim());
|
|
23
24
|
return filled.length === 0 ? kept : new Set([...kept, ...filled]);
|
|
24
25
|
}
|
|
25
|
-
export const LocationEditor = forwardRef(function LocationEditor({ field, initial, allowEmpty = false, conventions, onRequestClose }, ref) {
|
|
26
|
+
export const LocationEditor = forwardRef(function LocationEditor({ field, initial, allowEmpty = false, conventions, chrome = "bare", onRequestClose }, ref) {
|
|
26
27
|
const views = useViews();
|
|
27
28
|
const locale = (conventions ?? views.conventions).locale;
|
|
28
29
|
const say = (message) => views.messages(message);
|
|
29
30
|
const { List, RowContent } = views.atoms;
|
|
30
|
-
const { Command } = views.components;
|
|
31
|
+
const { Command, Input } = views.components;
|
|
31
32
|
const boxRef = useRef(null);
|
|
32
33
|
const parts = field.parts ?? LOCATION_PARTS;
|
|
33
34
|
const takesCountry = parts.includes("countryCode");
|
|
@@ -182,8 +183,14 @@ export const LocationEditor = forwardRef(function LocationEditor({ field, initia
|
|
|
182
183
|
? { "aria-required": true, "data-required": "" }
|
|
183
184
|
: { "data-required": "" }
|
|
184
185
|
: {};
|
|
185
|
-
const
|
|
186
|
-
const
|
|
186
|
+
const framed = chrome === "field";
|
|
187
|
+
const input = framed
|
|
188
|
+
? "w-24 min-w-0 flex-1 select-text"
|
|
189
|
+
: "h-7 w-24 min-w-0 flex-1 select-text bg-transparent text-(length:--vk-text) text-(color:--vk-fg) outline-hidden";
|
|
190
|
+
const button = framed
|
|
191
|
+
? "h-9 w-24 min-w-0 flex-1 cursor-pointer truncate rounded-md border border-(color:--vk-border) bg-transparent px-3 text-left text-(length:--vk-text) text-(color:--vk-fg) outline-hidden"
|
|
192
|
+
: `${input} cursor-pointer truncate text-left`;
|
|
193
|
+
const line = (box) => (framed ? _jsx("span", { className: "flex min-w-0 items-center gap-1.5", children: box }) : box);
|
|
187
194
|
const search = (value, onChange, placeholder) => (_jsx(Command.Input, { ref: focusSearch, value: value, onValueChange: onChange, placeholder: placeholder, className: "h-9 text-[13px]", onKeyDown: (e) => {
|
|
188
195
|
if (e.key === "Escape") {
|
|
189
196
|
e.stopPropagation();
|
|
@@ -219,9 +226,10 @@ export const LocationEditor = forwardRef(function LocationEditor({ field, initia
|
|
|
219
226
|
else {
|
|
220
227
|
const focusPart = rows[0]?.[0];
|
|
221
228
|
const focus = (part) => (part === focusPart ? { "data-place-focus": "" } : {});
|
|
222
|
-
body = (_jsxs(_Fragment, { children: [takesCountry && country && (_jsx("button", { type: "button", "data-place-control": "", "aria-label": `${say({ key: "views.editors.place-change-country" })}: ${countryName(country, locale)}`, onClick: () => setChoosingCountry(true), onKeyDown: keys, className: `${button} font-medium`, children: countryName(country, locale) })), rows.map((row) => (_jsx("span", { className: "flex min-w-0 items-center gap-1.5", children: row.map((part) => part === "region" && regionList ? (_jsx("button", { type: "button", "data-place-control": "", ...focus(part), ...required(part, "button"), "data-place-part": part, "aria-label": draft.region ? `${labelOf(part)}: ${draft.region}` : labelOf(part), onFocus: () => (lastFocused.current = part), onClick: () => setChoosingRegion(true), onKeyDown: keys, className: `${button} ${draft.region ? "" : "text-(color:--vk-fg-subtle)"}`, children: draft.region || labelOf(part) }, part)) : (_jsx(
|
|
229
|
+
body = (_jsxs(_Fragment, { children: [takesCountry && country && line(_jsx("button", { type: "button", "data-place-control": "", "aria-label": `${say({ key: "views.editors.place-change-country" })}: ${countryName(country, locale)}`, onClick: () => setChoosingCountry(true), onKeyDown: keys, className: `${button} font-medium`, children: countryName(country, locale) })), rows.map((row) => (_jsx("span", { className: "flex min-w-0 items-center gap-1.5", children: row.map((part) => part === "region" && regionList ? (_jsx("button", { type: "button", "data-place-control": "", ...focus(part), ...required(part, "button"), "data-place-part": part, "aria-label": draft.region ? `${labelOf(part)}: ${draft.region}` : labelOf(part), onFocus: () => (lastFocused.current = part), onClick: () => setChoosingRegion(true), onKeyDown: keys, className: `${button} ${draft.region ? "" : "text-(color:--vk-fg-subtle)"}`, children: draft.region || labelOf(part) }, part)) : (_jsx(Input, { "data-place-control": "", ...focus(part), ...required(part, "input"), "data-place-part": part, onFocus: () => (lastFocused.current = part), value: draft[part] ?? "", "aria-label": labelOf(part), placeholder: labelOf(part), onChange: (e) => type(part, e.target.value), onKeyDown: keys, onClick: (e) => e.stopPropagation(), chrome: chrome, className: input }, part))) }, row.join(" "))))] }));
|
|
223
230
|
}
|
|
224
|
-
|
|
231
|
+
const inner = (choosingRegion && regionList !== null) || (choosingCountry && country !== null);
|
|
232
|
+
return (_jsx("div", { ref: boxRef, ...(inner ? { [EDITOR_INNER_ESCAPE]: "" } : {}), onBlur: blur, onMouseDown: (e) => {
|
|
225
233
|
if (!(e.target instanceof HTMLInputElement))
|
|
226
234
|
e.preventDefault();
|
|
227
235
|
}, className: "flex w-full min-w-0 flex-col gap-1.5", children: body }));
|
|
@@ -18,5 +18,8 @@ export declare const NameEditor: import("react").ForwardRefExoticComponent<{
|
|
|
18
18
|
seed?: string;
|
|
19
19
|
allowEmpty?: boolean;
|
|
20
20
|
conventions?: FieldConventions;
|
|
21
|
+
/** How the boxes are drawn: `bare` in a cell or a popover, `field` where they stand on their own (a phone's
|
|
22
|
+
* sheet), each in the app's field frame. Default `bare`. */
|
|
23
|
+
chrome?: "bare" | "field";
|
|
21
24
|
onRequestClose: (reason: CloseReason) => void;
|
|
22
25
|
} & import("react").RefAttributes<NameEditorHandle>>;
|
|
@@ -12,8 +12,9 @@ const LABELS = {
|
|
|
12
12
|
function fromParts(given, family) {
|
|
13
13
|
return [given.trim(), family.trim()].filter(Boolean).join(" ");
|
|
14
14
|
}
|
|
15
|
-
export const NameEditor = forwardRef(function NameEditor({ initial, seed, allowEmpty = false, onRequestClose }, ref) {
|
|
15
|
+
export const NameEditor = forwardRef(function NameEditor({ initial, seed, allowEmpty = false, chrome = "bare", onRequestClose }, ref) {
|
|
16
16
|
const views = useViews();
|
|
17
|
+
const { Input } = views.components;
|
|
17
18
|
const boxRef = useRef(null);
|
|
18
19
|
const givenRef = useRef(null);
|
|
19
20
|
const refs = {
|
|
@@ -71,11 +72,17 @@ export const NameEditor = forwardRef(function NameEditor({ initial, seed, allowE
|
|
|
71
72
|
if (!boxRef.current?.contains(e.relatedTarget))
|
|
72
73
|
onRequestClose("blur");
|
|
73
74
|
};
|
|
74
|
-
const input =
|
|
75
|
+
const input = chrome === "field"
|
|
76
|
+
? "w-28 min-w-0 flex-1 select-text"
|
|
77
|
+
: "h-full w-28 min-w-0 flex-1 select-text bg-transparent text-(length:--vk-text) text-(color:--vk-fg) outline-hidden";
|
|
75
78
|
const box = (which, value, onChange) => {
|
|
76
79
|
const label = views.messages({ key: LABELS[which] });
|
|
77
|
-
return (_jsx(
|
|
80
|
+
return (_jsx(Input, { ref: refs[which], value: value, "aria-label": label, placeholder: label, onChange: (e) => onChange(e.target.value), onKeyDown: keys(which), onBlur: blur, onClick: (e) => e.stopPropagation(), chrome: chrome, className: input }));
|
|
78
81
|
};
|
|
82
|
+
const fullBox = box("full", full, (next) => {
|
|
83
|
+
setOwnFull(true);
|
|
84
|
+
setTypedFull(next);
|
|
85
|
+
});
|
|
79
86
|
return (_jsxs("span", { ref: boxRef, onMouseDown: (e) => {
|
|
80
87
|
if (!(e.target instanceof HTMLInputElement))
|
|
81
88
|
e.preventDefault();
|
|
@@ -85,8 +92,5 @@ export const NameEditor = forwardRef(function NameEditor({ initial, seed, allowE
|
|
|
85
92
|
}), box("family", family, (next) => {
|
|
86
93
|
setPartsEdited(true);
|
|
87
94
|
setFamily(next);
|
|
88
|
-
})] }),
|
|
89
|
-
setOwnFull(true);
|
|
90
|
-
setTypedFull(next);
|
|
91
|
-
})] }));
|
|
95
|
+
})] }), chrome === "field" ? (_jsx("span", { className: "flex min-w-0 items-center gap-1.5", children: fullBox })) : (fullBox)] }));
|
|
92
96
|
});
|
|
@@ -36,6 +36,9 @@ export declare const NumberEditor: import("react").ForwardRefExoticComponent<{
|
|
|
36
36
|
unit?: string;
|
|
37
37
|
/** Selectable units — presence makes the chip a picker. */
|
|
38
38
|
unitOptions?: string[];
|
|
39
|
+
/** The currency's code where the field fixes one (`numberEditCode`): drawn beside the amount
|
|
40
|
+
* as a unit is, and never part of the commit. Ignored when `unit` is given. */
|
|
41
|
+
code?: string;
|
|
39
42
|
/** Rounding + initial formatting precision — in the STORED unit. An
|
|
40
43
|
* integer field passes 0 (spec §8.2). */
|
|
41
44
|
decimals?: number;
|
|
@@ -5,14 +5,14 @@ import { formatNumberText, parseNumber, roundTo, } from "@viewkitjs/fields";
|
|
|
5
5
|
import { durationUnitToMs, formatDurationInput, msToDurationUnit, parseDurationInput, } from "@viewkitjs/fields/query";
|
|
6
6
|
import { cx } from "../internal/cx.js";
|
|
7
7
|
import { useViews } from "../provider/context.js";
|
|
8
|
-
export const NumberEditor = forwardRef(function NumberEditor({ initial, seed, unit, unitOptions, decimals = 2, durationUnit, allowEmpty = false, unitLeft = false, align = "end", conventions, onRequestClose, }, ref) {
|
|
8
|
+
export const NumberEditor = forwardRef(function NumberEditor({ initial, seed, unit, unitOptions, code, decimals = 2, durationUnit, allowEmpty = false, unitLeft = false, align = "end", conventions, onRequestClose, }, ref) {
|
|
9
9
|
const inputRef = useRef(null);
|
|
10
10
|
const chipRef = useRef(null);
|
|
11
11
|
const [currentUnit, setCurrentUnit] = useState(unit);
|
|
12
12
|
const [unitOpen, setUnitOpen] = useState(false);
|
|
13
13
|
const views = useViews();
|
|
14
14
|
const cv = conventions ?? views.conventions;
|
|
15
|
-
const { Popover } = views.components;
|
|
15
|
+
const { Popover, Input } = views.components;
|
|
16
16
|
const { List, Row } = views.atoms;
|
|
17
17
|
useEffect(() => {
|
|
18
18
|
const el = inputRef.current;
|
|
@@ -58,7 +58,7 @@ export const NumberEditor = forwardRef(function NumberEditor({ initial, seed, un
|
|
|
58
58
|
return { kind: "commit", payload: { value: parsed, unit: currentUnit } };
|
|
59
59
|
};
|
|
60
60
|
useImperativeHandle(ref, () => ({ resolveClose }));
|
|
61
|
-
return (_jsxs("span", { className: "flex h-full w-full min-w-0 items-center gap-1.5", children: [_jsx(
|
|
61
|
+
return (_jsxs("span", { className: "flex h-full w-full min-w-0 items-center gap-1.5", children: [_jsx(Input, { ref: inputRef, defaultValue: seed ?? initialText, inputMode: durationUnit ? "text" : "decimal", onKeyDown: (e) => {
|
|
62
62
|
e.stopPropagation();
|
|
63
63
|
if (e.key === "Enter") {
|
|
64
64
|
e.preventDefault();
|
|
@@ -74,13 +74,13 @@ export const NumberEditor = forwardRef(function NumberEditor({ initial, seed, un
|
|
|
74
74
|
}, onBlur: () => {
|
|
75
75
|
if (!unitOpen)
|
|
76
76
|
onRequestClose("blur");
|
|
77
|
-
}, onClick: (e) => e.stopPropagation(), className: cx("h-full min-w-0 select-text bg-transparent tabular-nums text-(length:--vk-text) text-(color:--vk-fg) outline-hidden", align === "start" ? "w-40 flex-none text-left" : "w-full flex-1 text-right") }), unit &&
|
|
78
|
-
(unitOptions && unitOptions.length > 0 ? (_jsxs(_Fragment, { children: [_jsx("button", { ref: chipRef, type: "button", tabIndex: -1, onMouseDown: (e) => e.preventDefault(), onClick: (e) => {
|
|
77
|
+
}, onClick: (e) => e.stopPropagation(), className: cx("h-full min-w-0 select-text bg-transparent tabular-nums text-(length:--vk-text) text-(color:--vk-fg) outline-hidden", align === "start" ? "w-40 flex-none text-left" : "w-full flex-1 text-right") }), (unit ?? code) &&
|
|
78
|
+
(unit && unitOptions && unitOptions.length > 0 ? (_jsxs(_Fragment, { children: [_jsx("button", { ref: chipRef, type: "button", tabIndex: -1, onMouseDown: (e) => e.preventDefault(), onClick: (e) => {
|
|
79
79
|
e.stopPropagation();
|
|
80
80
|
setUnitOpen((o) => !o);
|
|
81
81
|
}, className: cx("shrink-0 text-xs font-normal text-(color:--vk-fg-subtle) transition-colors hover:text-(color:--vk-fg)", unitLeft && "order-first"), children: currentUnit }), _jsx(Popover, { open: unitOpen, onOpenChange: (next) => setUnitOpen(next), anchor: chipRef, side: "bottom", align: unitLeft ? "start" : "end", sideOffset: 6, initialFocus: false, onOutsidePress: (event) => (chipRef.current?.contains(event.target) ? false : undefined), onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: "w-24", children: _jsx(List, { children: unitOptions.map((u) => (_jsx(Row, { label: u, chosen: u === currentUnit, onMouseDown: (e) => e.preventDefault(), onClick: () => {
|
|
82
82
|
setCurrentUnit(u);
|
|
83
83
|
setUnitOpen(false);
|
|
84
84
|
inputRef.current?.focus();
|
|
85
|
-
} }, u))) }) })] })) : (_jsx("span", { className: cx("shrink-0 text-xs font-normal text-(color:--vk-fg-subtlest)", unitLeft && "order-first"), children: unit })))] }));
|
|
85
|
+
} }, u))) }) })] })) : (_jsx("span", { className: cx("shrink-0 text-xs font-normal text-(color:--vk-fg-subtlest)", unitLeft && "order-first"), children: unit ?? code })))] }));
|
|
86
86
|
});
|