viewkitjs 0.29.0 → 0.30.1
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 +127 -6
- package/MIGRATION.md +97 -8
- package/package.json +1 -1
- package/views/dist/cells/cell-format.d.ts +2 -2
- package/views/dist/cells/cell-values.js +0 -2
- package/views/dist/contract.d.ts +15 -18
- package/views/dist/contract.js +13 -27
- package/views/dist/controls/button/map-button.d.ts +5 -3
- package/views/dist/controls/button/map-button.js +14 -7
- package/views/dist/controls/controls.d.ts +2 -4
- package/views/dist/controls/controls.js +2 -2
- package/views/dist/controls/customize/customize.d.ts +51 -0
- package/views/dist/controls/customize/customize.js +128 -23
- package/views/dist/controls/customize/map-customize-body.d.ts +0 -3
- package/views/dist/controls/customize/map-customize-body.js +46 -11
- package/views/dist/controls/customize/map-ranges.d.ts +23 -0
- package/views/dist/controls/customize/map-ranges.js +41 -0
- package/views/dist/controls/customize/rules.d.ts +17 -1
- package/views/dist/controls/customize/rules.js +2 -0
- package/views/dist/controls/customize/words.d.ts +7 -0
- package/views/dist/controls/customize/words.js +5 -0
- package/views/dist/controls/customize.css +3 -0
- package/views/dist/controls/filter-editor/filter-editor.d.ts +2 -0
- package/views/dist/controls/filter-editor/filter-editor.js +1 -0
- package/views/dist/controls/filter-editor/rules.d.ts +1 -2
- package/views/dist/controls/index.d.ts +8 -8
- package/views/dist/controls/index.js +8 -8
- package/views/dist/controls/menu-list/menu-list.d.ts +16 -1
- package/views/dist/controls/menu-list/menu-list.js +26 -8
- package/views/dist/controls/menu-list.css +8 -0
- package/views/dist/controls/quick-filters/map-quick-filters-body.d.ts +1 -1
- package/views/dist/controls/quick-filters/map-quick-filters-body.js +6 -3
- package/views/dist/controls/sheet/map-sheet.js +1 -1
- package/views/dist/controls/text-editor/map-text-body.d.ts +1 -1
- package/views/dist/controls/text-editor/map-text-body.js +2 -2
- package/views/dist/controls/text-editor/text-editor.d.ts +3 -0
- package/views/dist/controls/text-editor/text-editor.js +16 -2
- package/views/dist/controls/text-editor.css +11 -0
- package/views/dist/controls/values-editor/values.js +6 -2
- package/views/dist/display/options.d.ts +1 -1
- package/views/dist/display/rich-text.js +0 -1
- package/views/dist/editors/ChipsEditor.d.ts +4 -5
- package/views/dist/editors/ChipsEditor.js +12 -78
- package/views/dist/editors/DateEditor.d.ts +12 -16
- package/views/dist/editors/DateEditor.js +40 -191
- package/views/dist/editors/EditorPanel.d.ts +2 -6
- package/views/dist/editors/EditorPanel.js +2 -2
- package/views/dist/editors/LocationEditor.d.ts +11 -19
- package/views/dist/editors/LocationEditor.js +19 -211
- package/views/dist/editors/NameEditor.d.ts +8 -16
- package/views/dist/editors/NameEditor.js +11 -100
- package/views/dist/editors/NumberEditor.d.ts +14 -21
- package/views/dist/editors/NumberEditor.js +22 -49
- package/views/dist/editors/RangeEditor.d.ts +9 -33
- package/views/dist/editors/RangeEditor.js +12 -97
- package/views/dist/editors/RelationEditor.d.ts +6 -9
- package/views/dist/editors/RelationEditor.js +11 -30
- package/views/dist/editors/RelationSetEditor.d.ts +13 -24
- package/views/dist/editors/RelationSetEditor.js +33 -101
- package/views/dist/editors/SelectEditor.d.ts +15 -17
- package/views/dist/editors/SelectEditor.js +15 -94
- package/views/dist/editors/TextEditor.d.ts +23 -26
- package/views/dist/editors/TextEditor.js +11 -48
- package/views/dist/editors/ValueListEditor.d.ts +14 -23
- package/views/dist/editors/ValueListEditor.js +16 -202
- package/views/dist/editors/body-panel.d.ts +13 -7
- package/views/dist/editors/body-panel.js +3 -7
- package/views/dist/editors/edit-cores.d.ts +15 -15
- package/views/dist/editors/edit-cores.js +14 -14
- package/views/dist/editors/number-body.d.ts +1 -1
- package/views/dist/editors/number-step.d.ts +0 -34
- package/views/dist/editors/number-step.js +0 -37
- package/views/dist/editors/option-add-flow.d.ts +1 -13
- package/views/dist/editors/option-add-flow.js +0 -22
- package/views/dist/editors/relation-links-body.d.ts +2 -3
- package/views/dist/editors/relation-picker.d.ts +13 -3
- package/views/dist/editors/relation-source.d.ts +0 -22
- package/views/dist/editors/relation-source.js +0 -21
- package/views/dist/field-row/FieldRow.js +5 -6
- package/views/dist/field-row/FieldRowLane.js +0 -1
- package/views/dist/field-row/editors/RowChipsEditor.js +2 -2
- package/views/dist/field-row/editors/RowDateEditor.d.ts +2 -2
- package/views/dist/field-row/editors/RowDateEditor.js +2 -2
- package/views/dist/field-row/editors/RowNameEditor.d.ts +2 -5
- package/views/dist/field-row/editors/RowNameEditor.js +7 -12
- package/views/dist/field-row/editors/RowNumberEditor.d.ts +1 -1
- package/views/dist/field-row/editors/RowNumberEditor.js +4 -4
- package/views/dist/field-row/editors/RowPlaceEditor.js +3 -3
- package/views/dist/field-row/editors/RowRangeEditor.d.ts +2 -5
- package/views/dist/field-row/editors/RowRangeEditor.js +7 -14
- package/views/dist/field-row/editors/RowRelationEditor.js +3 -3
- package/views/dist/field-row/editors/RowSelectEditor.js +2 -2
- package/views/dist/field-row/editors/RowTextEditor.d.ts +1 -1
- package/views/dist/field-row/editors/RowTextEditor.js +3 -4
- package/views/dist/field-row/editors/RowValueListEditor.js +5 -5
- package/views/dist/field-row/field-row-button.d.ts +6 -9
- package/views/dist/field-row/field-row-button.js +1 -6
- package/views/dist/field-row/field-row-checkbox.d.ts +1 -1
- package/views/dist/field-row/row-target.d.ts +0 -7
- package/views/dist/field-row/row-target.js +0 -2
- package/views/dist/grid/chrome/GridAddColumn.d.ts +2 -1
- package/views/dist/grid/chrome/GridAddColumn.js +8 -66
- package/views/dist/grid/chrome/GridAggregateMenu.d.ts +5 -7
- package/views/dist/grid/chrome/GridAggregateMenu.js +20 -39
- package/views/dist/grid/chrome/GridCellEditors.d.ts +2 -2
- package/views/dist/grid/chrome/GridCellEditors.js +12 -12
- package/views/dist/grid/chrome/GridChipsEditor.js +3 -3
- package/views/dist/grid/chrome/GridColumnMenu.d.ts +11 -12
- package/views/dist/grid/chrome/GridColumnMenu.js +32 -93
- package/views/dist/grid/chrome/GridDateEditor.d.ts +6 -6
- package/views/dist/grid/chrome/GridDateEditor.js +3 -3
- package/views/dist/grid/chrome/GridGroupMenu.d.ts +4 -6
- package/views/dist/grid/chrome/GridGroupMenu.js +21 -62
- package/views/dist/grid/chrome/GridHeader.d.ts +1 -2
- package/views/dist/grid/chrome/GridHeader.js +2 -2
- package/views/dist/grid/chrome/GridLongTextEditor.d.ts +17 -38
- package/views/dist/grid/chrome/GridLongTextEditor.js +6 -7
- package/views/dist/grid/chrome/GridNameEditor.js +4 -4
- package/views/dist/grid/chrome/GridNumberEditor.d.ts +4 -5
- package/views/dist/grid/chrome/GridNumberEditor.js +3 -4
- package/views/dist/grid/chrome/GridPlaceEditor.d.ts +2 -5
- package/views/dist/grid/chrome/GridPlaceEditor.js +5 -5
- package/views/dist/grid/chrome/GridRangeEditor.d.ts +6 -12
- package/views/dist/grid/chrome/GridRangeEditor.js +7 -15
- package/views/dist/grid/chrome/GridRelationEditor.js +5 -5
- package/views/dist/grid/chrome/GridRow.js +0 -3
- package/views/dist/grid/chrome/GridRowActions.d.ts +1 -1
- package/views/dist/grid/chrome/GridRowActions.js +0 -5
- package/views/dist/grid/chrome/GridRowCells.js +9 -6
- package/views/dist/grid/chrome/GridSelectEditor.js +3 -3
- package/views/dist/grid/chrome/GridStructure.js +0 -1
- package/views/dist/grid/chrome/GridTable.js +1 -1
- package/views/dist/grid/chrome/GridTextEditor.d.ts +5 -7
- package/views/dist/grid/chrome/GridTextEditor.js +4 -17
- package/views/dist/grid/chrome/GridValueListEditor.js +4 -4
- package/views/dist/grid/chrome/grid-body-place.d.ts +2 -3
- package/views/dist/grid/chrome/grid-body-place.js +4 -8
- package/views/dist/grid/chrome/grid-button.d.ts +7 -10
- package/views/dist/grid/chrome/grid-button.js +1 -6
- package/views/dist/grid/chrome/grid-cell-classes.js +1 -1
- package/views/dist/grid/chrome/grid-column-menu-items.d.ts +4 -4
- package/views/dist/grid/chrome/grid-column-menu-items.js +10 -6
- package/views/dist/grid/chrome/grid-group-menu-parts.d.ts +5 -9
- package/views/dist/grid/chrome/grid-group-menu-parts.js +1 -3
- package/views/dist/grid/chrome/grid-hover.js +0 -1
- package/views/dist/grid/chrome/grid-menu-focus.d.ts +7 -31
- package/views/dist/grid/chrome/grid-menu-focus.js +7 -47
- package/views/dist/grid/chrome/grid-styles.d.ts +0 -3
- package/views/dist/grid/chrome/grid-styles.js +0 -1
- package/views/dist/grid/chrome/grid-table-props.d.ts +6 -10
- package/views/dist/grid/chrome/useGridTableInteractionModel.js +2 -4
- package/views/dist/grid/core/editing-controller.d.ts +2 -1
- package/views/dist/grid/core/editing-controller.js +10 -2
- package/views/dist/grid/core/refusal-sentence.d.ts +3 -0
- package/views/dist/grid/core/refusal-sentence.js +2 -2
- package/views/dist/grid/core/write-states.d.ts +3 -1
- package/views/dist/grid/core/write-states.js +6 -2
- package/views/dist/grid/grid.css +1 -1
- package/views/dist/model/body-frame.d.ts +0 -32
- package/views/dist/model/body-frame.js +1 -15
- package/views/dist/model/column-inspect.d.ts +5 -5
- package/views/dist/model/column-inspect.js +2 -2
- package/views/dist/panels/customize-body.d.ts +1 -10
- package/views/dist/panels/customize-body.js +0 -3
- package/views/dist/panels/filter/MenuSelect.js +0 -5
- package/views/dist/panels/filter/RangeFilterBody.js +0 -1
- package/views/dist/panels/filter/details.d.ts +1 -5
- package/views/dist/panels/filter/details.js +0 -13
- package/views/dist/panels/filter/filter-list.d.ts +0 -1
- package/views/dist/panels/filter/filter-list.js +1 -1
- package/views/dist/panels/panel-button.d.ts +10 -12
- package/views/dist/panels/panel-button.js +1 -6
- package/views/dist/panels/react/chrome.d.ts +0 -17
- package/views/dist/panels/react/chrome.js +0 -8
- package/views/dist/panels/react/customize-body.d.ts +9 -12
- package/views/dist/panels/react/customize-body.js +57 -11
- package/views/dist/panels/react/customize.d.ts +9 -12
- package/views/dist/panels/react/customize.js +3 -112
- package/views/dist/panels/react/filter/FilterEditor.d.ts +4 -18
- package/views/dist/panels/react/filter/FilterEditor.js +6 -330
- package/views/dist/panels/react/filter/FilterFieldList.d.ts +1 -1
- package/views/dist/panels/react/filter/FilterFieldList.js +27 -59
- package/views/dist/panels/react/filter/PhoneFilterEditor.d.ts +1 -11
- package/views/dist/panels/react/filter/PhoneFilterEditor.js +8 -144
- package/views/dist/panels/react/filter/editor-ctx.d.ts +1 -33
- package/views/dist/panels/react/filter/editor-ctx.js +5 -33
- package/views/dist/panels/react/filter/filter-part-body.d.ts +3 -6
- package/views/dist/panels/react/filter/filter-part-body.js +0 -5
- package/views/dist/panels/react/filter/rule-writes.d.ts +1 -26
- package/views/dist/panels/react/filter/rule-writes.js +4 -95
- package/views/dist/panels/react/order-details.d.ts +1 -26
- package/views/dist/panels/react/order-details.js +3 -69
- package/views/dist/panels/react/panel-header.js +0 -1
- package/views/dist/panels/react/popover.d.ts +4 -7
- package/views/dist/panels/react/quick/QuickFiltersPanel.d.ts +2 -4
- package/views/dist/panels/react/quick/QuickFiltersPanel.js +16 -137
- package/views/dist/panels/react/sort/SortEditor.d.ts +4 -4
- package/views/dist/panels/react/sort/SortEditor.js +8 -245
- package/views/dist/panels/react/sort/SortFieldList.d.ts +1 -1
- package/views/dist/panels/react/sort/SortFieldList.js +11 -25
- package/views/dist/panels/react/toolbar/ToolbarAdvancedFilters.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarBarFilter.js +4 -16
- package/views/dist/panels/react/toolbar/ToolbarQuickFilters.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarSave.js +0 -4
- package/views/dist/panels/react/toolbar/ToolbarSearch.js +0 -1
- package/views/dist/panels/react/toolbar/ToolbarSortPill.js +3 -3
- package/views/dist/panels/react/view-actions.js +0 -1
- package/views/dist/panels/react/views-row/FoldingViewRow.js +5 -9
- package/views/dist/panels/react/views-row/ViewCreatePill.js +0 -1
- package/views/dist/panels/react/views-row/ViewPicker.js +7 -43
- package/views/dist/panels/react/views-row/ViewPickerRow.js +0 -2
- package/views/dist/panels/react/views-row/menu-classes.d.ts +0 -4
- package/views/dist/panels/react/views-row/menu-classes.js +0 -2
- package/views/dist/panels/react.d.ts +5 -12
- package/views/dist/panels/react.js +5 -12
- package/views/dist/provider/ViewsProvider.d.ts +2 -46
- package/views/dist/provider/ViewsProvider.js +2 -22
- package/views/dist/provider/components.d.ts +153 -106
- package/views/dist/provider/context.d.ts +1 -21
- package/views/dist/provider/missing-slot.d.ts +3 -7
- package/views/dist/provider/missing-slot.js +2 -9
- package/views/dist/react.d.ts +1 -2
- package/views/dist/selection/SelectionBar.js +2 -3
- package/views/dist/styles.css +40 -168
- package/views/dist/styles.unlayered.css +40 -168
- package/views/docs/contract.md +99 -123
- package/views/docs/getting-started.md +222 -2
- package/views/docs/guides/cells.md +222 -2
- package/views/docs/guides/display.md +1 -1
- package/views/docs/guides/editors.md +235 -20
- package/views/docs/guides/ports.md +1 -1
- package/views/docs/guides/selection.md +1 -1
- package/views/docs/guides/the-grid.md +14 -16
- package/views/docs/guides/the-provider.md +9 -15
- package/views/docs/reference/cells.md +1 -1
- package/views/docs/reference/controls.md +28 -15
- package/views/docs/reference/editors-chips.md +2 -2
- package/views/docs/reference/editors-date.md +4 -4
- package/views/docs/reference/editors-location.md +4 -7
- package/views/docs/reference/editors-name.md +3 -5
- package/views/docs/reference/editors-number.md +10 -10
- package/views/docs/reference/editors-panel.md +3 -3
- package/views/docs/reference/editors-range.md +3 -5
- package/views/docs/reference/editors-relation.md +4 -4
- package/views/docs/reference/editors-select.md +3 -3
- package/views/docs/reference/editors-text.md +3 -4
- package/views/docs/reference/editors-value-list.md +3 -3
- package/views/docs/reference/field-row.md +1 -1
- package/views/docs/reference/grid.md +2 -2
- package/views/docs/reference/panels-react.md +20 -34
- package/views/docs/reference/react.md +11 -18
- package/views/docs/reference/views.md +5 -5
- package/views/skills/views/SKILL.md +1 -1
- package/views/dist/editors/relation-panel.d.ts +0 -69
- package/views/dist/editors/relation-panel.js +0 -46
- package/views/dist/grid/chrome/GridColumnColorSection.d.ts +0 -13
- package/views/dist/grid/chrome/GridColumnColorSection.js +0 -40
- package/views/dist/grid/chrome/GridColumnDateSection.d.ts +0 -28
- package/views/dist/grid/chrome/GridColumnDateSection.js +0 -23
- package/views/dist/grid/chrome/GridColumnDurationSection.d.ts +0 -23
- package/views/dist/grid/chrome/GridColumnDurationSection.js +0 -24
- package/views/dist/grid/chrome/GridColumnNumberSection.d.ts +0 -29
- package/views/dist/grid/chrome/GridColumnNumberSection.js +0 -27
- package/views/dist/grid/chrome/GridColumnPercentSection.d.ts +0 -16
- package/views/dist/grid/chrome/GridColumnPercentSection.js +0 -16
- package/views/dist/grid/chrome/GridColumnSortSection.d.ts +0 -38
- package/views/dist/grid/chrome/GridColumnSortSection.js +0 -33
- package/views/dist/grid/chrome/GridFlyout.d.ts +0 -44
- package/views/dist/grid/chrome/GridFlyout.js +0 -80
- package/views/dist/grid/chrome/GridMenuRow.d.ts +0 -15
- package/views/dist/grid/chrome/GridMenuRow.js +0 -15
- package/views/dist/grid/chrome/grid-menu-search.d.ts +0 -7
- package/views/dist/grid/chrome/grid-menu-search.js +0 -7
- package/views/dist/panels/react/GroupBucketsList.d.ts +0 -16
- package/views/dist/panels/react/GroupBucketsList.js +0 -44
- package/views/dist/panels/react/LayoutColumnsList.d.ts +0 -24
- package/views/dist/panels/react/LayoutColumnsList.js +0 -101
- package/views/dist/panels/react/PopoverColumnDetail.d.ts +0 -11
- package/views/dist/panels/react/PopoverColumnDetail.js +0 -24
- package/views/dist/panels/react/drag.d.ts +0 -2
- package/views/dist/panels/react/drag.js +0 -5
- package/views/dist/panels/react/layout-detail.d.ts +0 -4
- package/views/dist/panels/react/layout-detail.js +0 -29
- package/views/dist/panels/react/root-list.d.ts +0 -6
- package/views/dist/panels/react/root-list.js +0 -31
- package/views/dist/panels/react/sort/use-sort-drag.d.ts +0 -17
- package/views/dist/panels/react/sort/use-sort-drag.js +0 -39
- package/views/dist/panels/react/view-footer.d.ts +0 -20
- package/views/dist/panels/react/view-footer.js +0 -41
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx
|
|
3
|
-
import { forwardRef,
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
4
4
|
import { sameListValue, } from "viewkitjs/fields";
|
|
5
5
|
import { useViews } from "../provider/context.js";
|
|
6
6
|
import { PickerFrame, pickerItemOf, typedPick, usePickerForm } from "./picker-slot.js";
|
|
7
|
-
import {
|
|
8
|
-
import { AddRows, bodyAdd, useOptionAdd } from "./option-add-flow.js";
|
|
7
|
+
import { bodyAdd, useOptionAdd } from "./option-add-flow.js";
|
|
9
8
|
export const ChipsEditor = forwardRef(function ChipsEditor({ values, suggestions, resolve: resolveValue, normalize, onRequestClose: closeAsked, message, creatable = true, label, addOption, seed, }, ref) {
|
|
10
9
|
const [draft, setDraft] = useState(values);
|
|
11
|
-
const [search, setSearch] = useState(seed ?? "");
|
|
12
|
-
const inputRef = useRef(null);
|
|
13
10
|
const draftRef = useRef(values);
|
|
14
11
|
const views = useViews();
|
|
15
12
|
const words = message ?? views.conventions.messages;
|
|
16
|
-
const {
|
|
13
|
+
const { Picker } = views.components;
|
|
17
14
|
const form = usePickerForm();
|
|
18
|
-
const { List, RowContent, Tag } = views.atoms;
|
|
19
|
-
const Add = views.icons.add;
|
|
20
15
|
const carried = useMemo(() => [...suggestions, ...draft], [suggestions, draft]);
|
|
21
16
|
const adding = useOptionAdd({
|
|
22
17
|
addOption,
|
|
23
18
|
offered: carried.map((value) => resolveValue(value)),
|
|
24
19
|
carried,
|
|
25
20
|
open: creatable,
|
|
26
|
-
onPick: (value) =>
|
|
21
|
+
onPick: (value) => setBoth(draftRef.current.includes(value) ? draftRef.current : [...draftRef.current, value]),
|
|
27
22
|
});
|
|
28
23
|
const resolve = (value) => {
|
|
29
24
|
const returned = suggestions.includes(value) ? undefined : adding.added(value);
|
|
@@ -46,73 +41,12 @@ export const ChipsEditor = forwardRef(function ChipsEditor({ values, suggestions
|
|
|
46
41
|
draftRef.current = next;
|
|
47
42
|
setDraft(next);
|
|
48
43
|
};
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
if (Picker)
|
|
51
|
-
return;
|
|
52
|
-
const box = inputRef.current;
|
|
53
|
-
box?.focus({ preventScroll: true });
|
|
54
|
-
if (seed)
|
|
55
|
-
box?.setSelectionRange(seed.length, seed.length);
|
|
56
|
-
}, []);
|
|
57
44
|
const clean = (raw) => (normalize ? normalize(raw) : raw.trim());
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
:
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const canAdd = !addOption && creatable && typed !== "" && ![...draft, ...rows].some((value) => value.toLowerCase() === needle);
|
|
66
|
-
const word = search.trim();
|
|
67
|
-
const named = addOption ? namedOption(word, carried.map((value) => resolveValue(value))) : undefined;
|
|
68
|
-
const addRow = !!addOption && word !== "" && !named;
|
|
69
|
-
const listed = named && rows.includes(named.value) ? [named.value, ...visible.filter((value) => value !== named.value)] : visible;
|
|
70
|
-
const add = (value) => {
|
|
71
|
-
if (!draftRef.current.includes(value))
|
|
72
|
-
setBoth([...draftRef.current, value]);
|
|
73
|
-
setSearch("");
|
|
74
|
-
inputRef.current?.focus();
|
|
75
|
-
};
|
|
76
|
-
const remove = (value) => {
|
|
77
|
-
setBoth(draftRef.current.filter((entry) => entry !== value));
|
|
78
|
-
inputRef.current?.focus();
|
|
79
|
-
};
|
|
80
|
-
const onFieldKeyDown = (event) => {
|
|
81
|
-
if (event.key === "Backspace" && search === "" && draft.length > 0) {
|
|
82
|
-
event.preventDefault();
|
|
83
|
-
remove(draft[draft.length - 1]);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
if (Picker) {
|
|
87
|
-
const offered = [...suggestions, ...draft.filter((value) => !suggestions.includes(value))];
|
|
88
|
-
return (_jsx(PickerFrame, { onTab: (reason) => onRequestClose(reason), onKey: (event) => {
|
|
89
|
-
if (event.key === "Escape")
|
|
90
|
-
onRequestClose("escape");
|
|
91
|
-
}, children: _jsx(Picker, { label: label ?? words({ key: "chips.add-placeholder" }), items: offered.map((value) => pickerItemOf(resolve(value))), multiple: true, value: draft, onValueChange: (next) => setBoth([...new Set(Array.isArray(next) ? next : [])].filter((value) => value !== "" && ((creatable && !addOption) || offered.includes(value)))), onDone: () => onRequestClose("pick"), search: words({ key: "chips.add-placeholder" }), onCreate: creatable && !addOption
|
|
92
|
-
? (typed) => typedPick(clean(typed), [...draftRef.current, ...suggestions], "")
|
|
93
|
-
: undefined, typed: seed, autoFocus: true, form: form, ...bodyAdd(adding, !!addOption) }) }));
|
|
94
|
-
}
|
|
95
|
-
return (_jsxs(Command.Root, { shouldFilter: false, loop: true, children: [_jsxs("div", { className: "flex flex-wrap items-center gap-1 border-b border-(color:--vk-border) px-2 py-2", onMouseDown: (event) => {
|
|
96
|
-
if (event.target === event.currentTarget) {
|
|
97
|
-
event.preventDefault();
|
|
98
|
-
inputRef.current?.focus();
|
|
99
|
-
}
|
|
100
|
-
}, children: [draft.map((value) => {
|
|
101
|
-
const option = resolve(value);
|
|
102
|
-
return (_jsx(Tag, { label: option.label, color: option.color ?? "gray", onRemove: () => remove(value) }, value));
|
|
103
|
-
}), _jsx(Command.Input, { chrome: "bare", ref: inputRef, value: search, onValueChange: (next) => {
|
|
104
|
-
setSearch(next);
|
|
105
|
-
adding.clear();
|
|
106
|
-
}, onKeyDown: (event) => {
|
|
107
|
-
onFieldKeyDown(event);
|
|
108
|
-
if (event.key === "Escape")
|
|
109
|
-
onRequestClose("escape");
|
|
110
|
-
if (event.key === "Tab") {
|
|
111
|
-
event.preventDefault();
|
|
112
|
-
onRequestClose(event.shiftKey ? "shift-tab" : "tab");
|
|
113
|
-
}
|
|
114
|
-
}, placeholder: draft.length === 0 ? words({ key: "chips.add-placeholder" }) : "", className: "h-5 min-w-20 flex-1 bg-transparent text-(length:--vk-input-text,13px) outline-hidden placeholder:text-(color:--vk-fg-subtlest)" })] }), _jsxs(Command.List, { className: "max-h-64 overscroll-contain scrollbar-overlay", children: [listed.length === 0 && !canAdd && !addRow && !adding.state && (_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: [listed.map((value) => {
|
|
115
|
-
const option = resolve(value);
|
|
116
|
-
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));
|
|
117
|
-
}), canAdd && (_jsx(Command.Item, { value: `__add__${typed}`, onSelect: () => add(typed), children: _jsx(RowContent, { size: "compact", tone: "muted", leading: _jsx(Add, { className: "h-4 w-4 shrink-0 text-(color:--vk-fg-subtle)" }), label: words({ key: "chips.add", values: { value: typed } }) }) })), addOption && _jsx(AddRows, { adding: adding, typed: addRow ? word : "" })] }) })] })] }));
|
|
45
|
+
const offered = [...suggestions, ...draft.filter((value) => !suggestions.includes(value))];
|
|
46
|
+
return (_jsx(PickerFrame, { onTab: (reason) => onRequestClose(reason), onKey: (event) => {
|
|
47
|
+
if (event.key === "Escape")
|
|
48
|
+
onRequestClose("escape");
|
|
49
|
+
}, children: _jsx(Picker, { label: label ?? words({ key: "chips.add-placeholder" }), items: offered.map((value) => pickerItemOf(resolve(value))), multiple: true, value: draft, onValueChange: (next) => setBoth([...new Set(Array.isArray(next) ? next : [])].filter((value) => value !== "" && ((creatable && !addOption) || offered.includes(value)))), onDone: () => onRequestClose("pick"), search: words({ key: "chips.add-placeholder" }), onCreate: creatable && !addOption
|
|
50
|
+
? (typed) => typedPick(clean(typed), [...draftRef.current, ...suggestions], "")
|
|
51
|
+
: undefined, typed: seed, autoFocus: true, form: form, ...bodyAdd(adding, !!addOption) }) }));
|
|
118
52
|
});
|
|
@@ -9,34 +9,30 @@ export type DateEditorHandle = {
|
|
|
9
9
|
*/
|
|
10
10
|
resolveClose: (reason: CloseReason) => CloseResolution<string>;
|
|
11
11
|
};
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const DateEditorHost: import("react").ForwardRefExoticComponent<{
|
|
13
13
|
/** The stored value — full ISO or "YYYY-MM-DD"; selects day + opening month. */
|
|
14
14
|
initial?: string;
|
|
15
|
-
/**
|
|
16
|
-
* mode). Without it, the
|
|
15
|
+
/** The time starts empty and stays out of the commit until set (form
|
|
16
|
+
* mode). Without it, the time is the stored one or 00:00 and every
|
|
17
17
|
* commit includes one. */
|
|
18
18
|
timeOptional?: boolean;
|
|
19
|
-
/** A calendar-day field: no time
|
|
20
|
-
* day click or a quick day asks the host to close with `pick`. Default false. */
|
|
19
|
+
/** A calendar-day field: no time, the commit is "YYYY-MM-DD". Default false. */
|
|
21
20
|
dayOnly?: boolean;
|
|
22
|
-
/** The date may be emptied:
|
|
23
|
-
*
|
|
21
|
+
/** The date may be emptied: the body offers No date, which asks the host
|
|
22
|
+
* to close with `pick` and commits "" (nothing when there was no date). */
|
|
24
23
|
clearable?: boolean;
|
|
25
|
-
/** The text the date
|
|
26
|
-
* opened the panel)
|
|
24
|
+
/** The text the date line opens with (a character typed on the cell that
|
|
25
|
+
* opened the panel), read as a typed date. */
|
|
27
26
|
seed?: string;
|
|
28
|
-
/** Put the
|
|
27
|
+
/** Put the focus in the body as the panel opens, without scrolling, so the keyboard is in the panel and Tab
|
|
29
28
|
* 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
|
|
29
|
+
* sheet opens with the keyboard down), leaves it off. A seed focuses it either way. */
|
|
31
30
|
focusDate?: boolean;
|
|
32
31
|
/** The panel saw a key that means "done" (Enter) or "leave" (Escape), or a
|
|
33
|
-
* pick
|
|
34
|
-
* host closes, then asks `resolveClose`. */
|
|
32
|
+
* pick. It never closes itself — the host closes, then asks `resolveClose`. */
|
|
35
33
|
onRequestClose: (reason: CloseReason) => void;
|
|
36
34
|
/** The host's words for this panel (fields' messages); default: the provider's conventions. */
|
|
37
35
|
message?: FieldMessageResolver;
|
|
38
|
-
/** The
|
|
39
|
-
fill?: boolean;
|
|
40
|
-
/** The field's name, for an app's `DateBody`. Default: the date box's words. */
|
|
36
|
+
/** The field's name, for the app's `DateBody`. Default: the date's words. */
|
|
41
37
|
label?: string;
|
|
42
38
|
} & import("react").RefAttributes<DateEditorHandle>>;
|
|
@@ -1,36 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx
|
|
3
|
-
import { forwardRef, useContext,
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useContext, useImperativeHandle, useRef, useState, } from "react";
|
|
4
4
|
import { formatChipDate, normalizeTime, parseDateText, toYmd, } from "viewkitjs/fields";
|
|
5
|
-
import { fromDayKey
|
|
6
|
-
import { cx } from "../internal/cx.js";
|
|
7
|
-
import { ELEMENT_RESET } from "../internal/reset.js";
|
|
5
|
+
import { fromDayKey } from "viewkitjs/fields/query";
|
|
8
6
|
import { useViews } from "../provider/context.js";
|
|
9
7
|
import { useMoment } from "../provider/moment.js";
|
|
10
|
-
import { isDesktopNow } from "../provider/desktop.js";
|
|
11
8
|
import { usePickerForm } from "./picker-slot.js";
|
|
12
|
-
import { tabbable
|
|
9
|
+
import { tabbable } from "./tab-ends.js";
|
|
13
10
|
import { commitInBrowserClock, EditorClockContext, todayIn, wallClockIn } from "../internal/zone-clock.js";
|
|
14
|
-
const QUICK_DAYS = {
|
|
15
|
-
today: { key: "date.today", offset: () => 0 },
|
|
16
|
-
tomorrow: { key: "date.tomorrow", offset: () => 1 },
|
|
17
|
-
"next-monday": { key: "date.next-monday", offset: (weekday) => (8 - weekday) % 7 || 7 },
|
|
18
|
-
"in-a-week": { key: "date.in-a-week", offset: () => 7 },
|
|
19
|
-
};
|
|
20
11
|
function todayOf(timeZone, now) {
|
|
21
12
|
return fromDayKey(todayIn(timeZone, now));
|
|
22
13
|
}
|
|
23
|
-
function quickDay(offset, timeZone, now) {
|
|
24
|
-
const today = todayOf(timeZone, now);
|
|
25
|
-
return new Date(today.getFullYear(), today.getMonth(), today.getDate() + offset(today.getDay()));
|
|
26
|
-
}
|
|
27
|
-
const CALENDAR_START = "1900-01";
|
|
28
|
-
const CALENDAR_END = `${new Date().getFullYear() + 10}-12`;
|
|
29
|
-
const TIME_OPTIONS = Array.from({ length: 96 }, (_, i) => {
|
|
30
|
-
const hh = String(Math.floor(i / 4)).padStart(2, "0");
|
|
31
|
-
const mm = String((i % 4) * 15).padStart(2, "0");
|
|
32
|
-
return `${hh}:${mm}`;
|
|
33
|
-
});
|
|
34
14
|
function readStored(iso, timeZone, dayOnly) {
|
|
35
15
|
if (!iso)
|
|
36
16
|
return undefined;
|
|
@@ -62,82 +42,26 @@ function initialHasTime(iso, parsed) {
|
|
|
62
42
|
return false;
|
|
63
43
|
return /T/.test(iso);
|
|
64
44
|
}
|
|
65
|
-
export const
|
|
66
|
-
const timeRef = useRef(null);
|
|
67
|
-
const dateRef = useRef(null);
|
|
45
|
+
export const DateEditorHost = forwardRef(function DateEditorHost({ initial, timeOptional = false, dayOnly = false, clearable = false, seed, focusDate = false, onRequestClose, message, label, }, ref) {
|
|
68
46
|
const views = useViews();
|
|
69
47
|
const now = useMoment() ?? undefined;
|
|
70
48
|
const words = message ?? views.conventions.messages;
|
|
71
|
-
const {
|
|
72
|
-
const { List, Row } = views.atoms;
|
|
49
|
+
const { DateBody } = views.components;
|
|
73
50
|
const quickPicks = views.datePicks ?? DEFAULT_DATE_PICKS;
|
|
74
|
-
const DateGlyph = views.icons.date;
|
|
75
|
-
const TimeGlyph = views.icons.time;
|
|
76
|
-
const [timeOpen, setTimeOpen] = useState(false);
|
|
77
|
-
const activeTimeRef = useRef(null);
|
|
78
51
|
const timeZone = useContext(EditorClockContext) === "browser" ? null : views.conventions.timeZone;
|
|
79
52
|
const stored = readStored(initial, timeZone, dayOnly);
|
|
80
53
|
const valid = stored?.day;
|
|
81
|
-
const [day, setDay] = useState(valid);
|
|
82
|
-
const [month, setMonth] = useState(valid);
|
|
83
54
|
const hadTime = initialHasTime(initial, valid);
|
|
84
55
|
const initialTime = stored && (!timeOptional || hadTime)
|
|
85
56
|
? (stored.time ?? "00:00")
|
|
86
57
|
: timeOptional
|
|
87
58
|
? ""
|
|
88
59
|
: "00:00";
|
|
89
|
-
const [timeVal, setTimeVal] = useState(initialTime);
|
|
90
|
-
const [dateVal, setDateVal] = useState(() => seed ?? (valid ? formatChipDate(valid) : ""));
|
|
91
60
|
const touchedRef = useRef(seed != null);
|
|
92
61
|
const dayRef = useRef(valid);
|
|
93
|
-
const dateTextRef = useRef(
|
|
94
|
-
const timeTextRef = useRef(
|
|
62
|
+
const dateTextRef = useRef(seed ?? (valid ? formatChipDate(valid) : ""));
|
|
63
|
+
const timeTextRef = useRef(initialTime);
|
|
95
64
|
const clearedRef = useRef(false);
|
|
96
|
-
const writeDateText = (text) => {
|
|
97
|
-
clearedRef.current = false;
|
|
98
|
-
dateTextRef.current = text;
|
|
99
|
-
setDateVal(text);
|
|
100
|
-
};
|
|
101
|
-
const writeTime = (text) => {
|
|
102
|
-
clearedRef.current = false;
|
|
103
|
-
timeTextRef.current = text;
|
|
104
|
-
setTimeVal(text);
|
|
105
|
-
};
|
|
106
|
-
const chooseDay = (d) => {
|
|
107
|
-
touchedRef.current = true;
|
|
108
|
-
dayRef.current = d;
|
|
109
|
-
setDay(d);
|
|
110
|
-
setMonth(d);
|
|
111
|
-
writeDateText(formatChipDate(d));
|
|
112
|
-
setTimeOpen(false);
|
|
113
|
-
if (dayOnly) {
|
|
114
|
-
onRequestClose("pick");
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
if (isDesktopNow(views.desktopQuery))
|
|
118
|
-
dateRef.current?.focus({ preventScroll: true });
|
|
119
|
-
};
|
|
120
|
-
useEffect(() => {
|
|
121
|
-
if (seed == null && !focusDate)
|
|
122
|
-
return;
|
|
123
|
-
const box = dateRef.current;
|
|
124
|
-
box?.focus({ preventScroll: true });
|
|
125
|
-
if (seed != null)
|
|
126
|
-
box?.setSelectionRange(seed.length, seed.length);
|
|
127
|
-
}, []);
|
|
128
|
-
const applyDateText = () => {
|
|
129
|
-
const current = dayRef.current ?? valid;
|
|
130
|
-
const typed = parseDateText(dateTextRef.current, (current ?? todayOf(timeZone, now)).getFullYear());
|
|
131
|
-
if (typed) {
|
|
132
|
-
dayRef.current = typed;
|
|
133
|
-
setDay(typed);
|
|
134
|
-
setMonth(typed);
|
|
135
|
-
writeDateText(formatChipDate(typed));
|
|
136
|
-
return typed;
|
|
137
|
-
}
|
|
138
|
-
writeDateText(current ? formatChipDate(current) : "");
|
|
139
|
-
return undefined;
|
|
140
|
-
};
|
|
141
65
|
const resolveClose = (reason) => {
|
|
142
66
|
if (reason === "escape")
|
|
143
67
|
return { kind: "cancel" };
|
|
@@ -160,15 +84,6 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
160
84
|
return payload === null ? { kind: "noop" } : { kind: "commit", payload };
|
|
161
85
|
};
|
|
162
86
|
useImperativeHandle(ref, () => ({ resolveClose }));
|
|
163
|
-
const nearest = normalizeTime(timeVal) ?? (initialTime || "00:00");
|
|
164
|
-
const [nh, nm] = nearest.split(":").map(Number);
|
|
165
|
-
const nearestTime = TIME_OPTIONS[Math.min(95, Math.round((nh * 60 + nm) / 15))];
|
|
166
|
-
useEffect(() => {
|
|
167
|
-
if (timeOpen)
|
|
168
|
-
activeTimeRef.current?.scrollIntoView({ block: "center" });
|
|
169
|
-
}, [timeOpen]);
|
|
170
|
-
const clearRef = useRef(null);
|
|
171
|
-
const clearControl = () => clearRef.current ? tabEnds(clearRef.current).first : undefined;
|
|
172
87
|
const tabbingRef = useRef(null);
|
|
173
88
|
const onTabOut = (event) => {
|
|
174
89
|
if (event.key !== "Tab" || event.altKey || event.ctrlKey || event.metaKey)
|
|
@@ -176,13 +91,6 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
176
91
|
const reachable = tabbable(event.currentTarget);
|
|
177
92
|
const first = reachable[0];
|
|
178
93
|
const last = reachable.at(-1);
|
|
179
|
-
const clear = clearControl();
|
|
180
|
-
if (!event.shiftKey && clear && event.target !== clear && reachable[reachable.indexOf(clear) - 1] === event.target) {
|
|
181
|
-
event.preventDefault();
|
|
182
|
-
event.stopPropagation();
|
|
183
|
-
clear.focus();
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
94
|
const leaving = event.shiftKey ? event.target === first : event.target === last;
|
|
187
95
|
if (!leaving) {
|
|
188
96
|
tabbingRef.current = event.shiftKey ? "shift-tab" : "tab";
|
|
@@ -207,96 +115,37 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
207
115
|
const bodyStart = !valid ? null : dayOnly || !initialTime ? toYmd(valid) : `${toYmd(valid)}T${initialTime}`;
|
|
208
116
|
const [bodyValue, setBodyValue] = useState(bodyStart);
|
|
209
117
|
const enteredRef = useRef(false);
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
if (
|
|
213
|
-
if (!clearable)
|
|
214
|
-
return;
|
|
215
|
-
clearedRef.current = true;
|
|
216
|
-
setBodyValue(null);
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
const read = readBodyValue(value);
|
|
220
|
-
if (!read)
|
|
118
|
+
const takeBodyValue = (value) => {
|
|
119
|
+
if (value === null) {
|
|
120
|
+
if (!clearable)
|
|
221
121
|
return;
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if (e.key === "Enter") {
|
|
252
|
-
e.preventDefault();
|
|
253
|
-
onRequestClose("enter");
|
|
254
|
-
}
|
|
255
|
-
else if (e.key === "Escape") {
|
|
256
|
-
onRequestClose("escape");
|
|
257
|
-
}
|
|
258
|
-
}, 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) => {
|
|
259
|
-
e.stopPropagation();
|
|
260
|
-
setTimeOpen(true);
|
|
261
|
-
timeRef.current?.focus();
|
|
262
|
-
}, 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) => {
|
|
263
|
-
touchedRef.current = true;
|
|
264
|
-
writeTime(e.target.value);
|
|
265
|
-
}, onFocus: () => setTimeOpen(true), placeholder: words({ key: "time.placeholder" }), "aria-label": words({ key: "time.label" }), onKeyDown: (e) => {
|
|
266
|
-
e.stopPropagation();
|
|
267
|
-
if (e.key === "Enter") {
|
|
268
|
-
e.preventDefault();
|
|
269
|
-
onRequestClose("enter");
|
|
270
|
-
}
|
|
271
|
-
else if (e.key === "Tab") {
|
|
272
|
-
setTimeOpen(false);
|
|
273
|
-
}
|
|
274
|
-
else if (e.key === "Escape") {
|
|
275
|
-
if (timeOpen)
|
|
276
|
-
setTimeOpen(false);
|
|
277
|
-
else
|
|
278
|
-
onRequestClose("escape");
|
|
279
|
-
}
|
|
280
|
-
}, className: "w-12 select-text bg-transparent text-sm tabular-nums text-(color:--vk-fg) outline-hidden placeholder:text-(color:--vk-fg-subtlest)" })] }), timeOpen && (_jsx("div", { className: "absolute right-0 top-full z-10 mt-1 max-h-56 w-24 overflow-y-auto overscroll-contain rounded-lg border border-(color:--vk-border) bg-(color:--vk-overlay) py-1 shadow-lg", children: TIME_OPTIONS.map((t) => {
|
|
281
|
-
const active = t === nearestTime;
|
|
282
|
-
return (_jsx("button", { ref: active ? activeTimeRef : undefined, type: "button", onClick: (e) => {
|
|
283
|
-
e.stopPropagation();
|
|
284
|
-
touchedRef.current = true;
|
|
285
|
-
writeTime(t);
|
|
286
|
-
setTimeOpen(false);
|
|
287
|
-
timeRef.current?.focus();
|
|
288
|
-
}, className: cx(ELEMENT_RESET, "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));
|
|
289
|
-
}) }))] }))] }), _jsx("div", { className: "flex gap-1 px-2 pt-2", children: quickPicks.map((pick) => (_jsx("button", { type: "button", onClick: (e) => {
|
|
290
|
-
e.stopPropagation();
|
|
291
|
-
chooseDay(quickDay(QUICK_DAYS[pick].offset, timeZone, now));
|
|
292
|
-
}, className: cx(ELEMENT_RESET, "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_DAYS[pick].key }) }, pick))) }), _jsx(Calendar, { locale: views.conventions.locale, ...(fill ? { className: "w-full" } : {}), value: (day ?? valid) ? toDayKey((day ?? valid)) : null, onChange: (picked) => {
|
|
293
|
-
const d = picked ? fromDayKey(picked) : null;
|
|
294
|
-
if (d)
|
|
295
|
-
chooseDay(d);
|
|
296
|
-
else if (dayOnly && dayRef.current)
|
|
297
|
-
chooseDay(dayRef.current);
|
|
298
|
-
}, month: toDayKey(month ?? todayOf(timeZone, now)).slice(0, 7), onMonthChange: (next) => setMonth(fromDayKey(`${next}-01`) ?? undefined), captionLayout: "dropdown", startMonth: CALENDAR_START, endMonth: CALENDAR_END }), clearable && (_jsx("div", { ref: clearRef, 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: () => {
|
|
299
|
-
clearedRef.current = true;
|
|
300
|
-
onRequestClose("pick");
|
|
301
|
-
} }) }) }))] }));
|
|
122
|
+
clearedRef.current = true;
|
|
123
|
+
setBodyValue(null);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const read = readBodyValue(value);
|
|
127
|
+
if (!read)
|
|
128
|
+
return;
|
|
129
|
+
clearedRef.current = false;
|
|
130
|
+
touchedRef.current = true;
|
|
131
|
+
dayRef.current = read.day;
|
|
132
|
+
dateTextRef.current = formatChipDate(read.day);
|
|
133
|
+
if (read.time)
|
|
134
|
+
timeTextRef.current = read.time;
|
|
135
|
+
else if (timeOptional)
|
|
136
|
+
timeTextRef.current = "";
|
|
137
|
+
const time = dayOnly ? null : (read.time ?? (timeOptional ? null : (normalizeTime(timeTextRef.current) ?? initialTime)));
|
|
138
|
+
setBodyValue(time ? `${toYmd(read.day)}T${time}` : toYmd(read.day));
|
|
139
|
+
};
|
|
140
|
+
const onBodyKey = (event) => {
|
|
141
|
+
enteredRef.current = event.key === "Enter" && !event.nativeEvent.isComposing && !event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey;
|
|
142
|
+
if (event.key === "Escape" && !event.altKey && !event.ctrlKey && !event.metaKey) {
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
event.stopPropagation();
|
|
145
|
+
onRequestClose("escape");
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
onTabOut(event);
|
|
149
|
+
};
|
|
150
|
+
return (_jsx("div", { "data-slot": "vk-date-editor", className: "contents", onKeyDownCapture: onBodyKey, onPointerDownCapture: () => (enteredRef.current = false), onBlurCapture: onTabAway, children: _jsx(DateBody, { label: label ?? words({ key: "date.label" }), value: bodyValue, onValueChange: takeBodyValue, onDone: () => onRequestClose(enteredRef.current ? "enter" : "pick"), time: !dayOnly, empty: clearable, picks: clearable ? [...quickPicks, "none"] : [...quickPicks], today: todayIn(timeZone, now), typed: seed, autoFocus: focusDate || seed != null, form: form }) }));
|
|
302
151
|
});
|
|
@@ -20,8 +20,7 @@ import type { EditSession } from "./edit-session.js";
|
|
|
20
20
|
* level the body marks inside its element (`EDITOR_INNER_ESCAPE`) is the body's, the sheet staying open.
|
|
21
21
|
* A refusal the host gave stays on screen under the editor, in the popover and the sheet (in a
|
|
22
22
|
* popover the app caps and scrolls, pinned whole to its bottom edge, the editor scrolling above it); in
|
|
23
|
-
* place, the host's own box draws it
|
|
24
|
-
* (`editorDrawsRefusal`).
|
|
23
|
+
* place, the host's own box draws it.
|
|
25
24
|
*
|
|
26
25
|
* The surface is chosen ONCE, when the session opens: a window crossing the desktop width
|
|
27
26
|
* mid-edit keeps the panel it opened in until the session ends.
|
|
@@ -54,9 +53,6 @@ export type EditorPanelProps = {
|
|
|
54
53
|
/** A click inside the popover or the sheet. The sheet keeps every press to itself after this; the
|
|
55
54
|
* popover leaves that to the host (a grid host stops it here). */
|
|
56
55
|
onPanelClick?: (event: ReactMouseEvent<HTMLDivElement>) => void;
|
|
57
|
-
/** The editor draws the session's refusal itself (a range with bands, between its boxes and its
|
|
58
|
-
* bands), so the panel draws none under it. Default false. */
|
|
59
|
-
editorDrawsRefusal?: boolean;
|
|
60
56
|
/** The body saves on its pick (a pick of one), so it needs no ✓: an app's Sheet that draws the
|
|
61
57
|
* panel's buttons in its head (the provider's `sheetActions: "head"`) is handed no `done`. The
|
|
62
58
|
* panel's own bar keeps its ✓. Default false. */
|
|
@@ -68,4 +64,4 @@ export type EditorPanelProps = {
|
|
|
68
64
|
export { EDITOR_INNER_ESCAPE } from "./inner-escape.js";
|
|
69
65
|
/** Where the panel opened its editor: the app's popover, its sheet, or where the value stands. */
|
|
70
66
|
export type EditorSurface = "popover" | "sheet" | "in-place";
|
|
71
|
-
export declare function EditorPanel({ session, title, anchor, inPlace, sheetOnPhone, snap, panelData,
|
|
67
|
+
export declare function EditorPanel({ session, title, anchor, inPlace, sheetOnPhone, snap, panelData, savesOnPick, children, ...popover }: EditorPanelProps): ReactNode;
|
|
@@ -27,7 +27,7 @@ function heardAround(target, anchor) {
|
|
|
27
27
|
return target.contains(box);
|
|
28
28
|
return target === document || target === document.body || target === document.documentElement;
|
|
29
29
|
}
|
|
30
|
-
export function EditorPanel({ session, title, anchor, inPlace = false, sheetOnPhone = false, snap = "auto", panelData,
|
|
30
|
+
export function EditorPanel({ session, title, anchor, inPlace = false, sheetOnPhone = false, snap = "auto", panelData, savesOnPick = false, children, ...popover }) {
|
|
31
31
|
const views = useViews();
|
|
32
32
|
const { Popover, Sheet, Button } = views.components;
|
|
33
33
|
const Discard = views.icons.close;
|
|
@@ -105,7 +105,7 @@ export function EditorPanel({ session, title, anchor, inPlace = false, sheetOnPh
|
|
|
105
105
|
}, []);
|
|
106
106
|
if (surface === "in-place")
|
|
107
107
|
return editor;
|
|
108
|
-
const reason = refusal
|
|
108
|
+
const reason = refusal ? (_jsx("p", { role: "alert", "data-slot": "vk-editor-refusal", className: cx("px-2 pb-2 text-xs text-(color:--vk-danger)", surface === "popover" && "sticky bottom-0 bg-(color:--vk-overlay)"), children: refusal })) : null;
|
|
109
109
|
if (surface === "popover") {
|
|
110
110
|
return (_jsxs(Popover, { ...popover, open: open, onOpenChange: (next, details) => {
|
|
111
111
|
if (next || details?.reason === "outside-press")
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { type CloseReason, type CloseResolution, type FieldConventions, type FieldDefOf, type LocationValue } from "viewkitjs/fields";
|
|
2
2
|
/**
|
|
3
|
-
* A PLACE — the country first, then that country's own parts
|
|
4
|
-
* country list when its place has none; once one is
|
|
5
|
-
* order with its own words (Romania's postal code, county and
|
|
6
|
-
* State, ZIP code), the parts the country asks for marked, never
|
|
7
|
-
* list, the region is picked from it, which stores the region's name and its
|
|
8
|
-
* when the editor lands on that country. A field limited to some parts edits only
|
|
9
|
-
* part it names that the country's format has no place for (Japan's has no city); those come
|
|
10
|
-
* generic order, as does a part a stored place holds that its country's format has no place for.
|
|
11
|
-
* Picking another country clears the region and its code. An editor closed untouched writes nothing.
|
|
12
|
-
* allows it (`clearable`), the editor ends with a Clear row that empties the whole place: the last stop of the
|
|
13
|
-
* editor's Tab, after its last box (or the first country list's search), and Enter or Space presses it.
|
|
3
|
+
* A PLACE — the country first, then that country's own parts, drawn by the app's `PartsBody` (`CONTROLS.PartsBody` is
|
|
4
|
+
* ViewKit's own). A field that takes the country opens on the country list when its place has none; once one is
|
|
5
|
+
* picked, the body shows the country's parts in its own order with its own words (Romania's postal code, county and
|
|
6
|
+
* city on one line; Hungary's city first; County, State, ZIP code), the parts the country asks for marked, never
|
|
7
|
+
* refused. Where the country has a region list, the region is picked from it, which stores the region's name and its
|
|
8
|
+
* ISO 3166-2 code; the list loads when the editor lands on that country. A field limited to some parts edits only
|
|
9
|
+
* those, and never loses a part it names that the country's format has no place for (Japan's has no city); those come
|
|
10
|
+
* after, in the generic order, as does a part a stored place holds that its country's format has no place for.
|
|
11
|
+
* Picking another country clears the region and its code. An editor closed untouched writes nothing.
|
|
14
12
|
*/
|
|
15
13
|
export type LocationEditorHandle = {
|
|
16
14
|
resolveClose: (reason: CloseReason) => CloseResolution<LocationValue | null>;
|
|
@@ -18,16 +16,10 @@ export type LocationEditorHandle = {
|
|
|
18
16
|
export declare const LocationEditor: import("react").ForwardRefExoticComponent<{
|
|
19
17
|
field: FieldDefOf<"location">;
|
|
20
18
|
initial: LocationValue | null;
|
|
19
|
+
/** The place may be emptied: the body is told so (`empty`), and an emptied place commits null. */
|
|
21
20
|
allowEmpty?: boolean;
|
|
22
21
|
conventions?: FieldConventions;
|
|
23
|
-
/**
|
|
24
|
-
* own (a phone's sheet), each in the app's field frame. Default `bare`. */
|
|
25
|
-
chrome?: "bare" | "field";
|
|
26
|
-
/** The field's name, for an app's `PartsBody`. Default: the field's label. */
|
|
22
|
+
/** The field's name, for the app's `PartsBody`. Default: the field's label. */
|
|
27
23
|
label?: string;
|
|
28
|
-
/** The place may be emptied: ViewKit's own body ends with a Clear row, which asks the host to close with `pick`
|
|
29
|
-
* and commits null (nothing when the place was already empty). Not drawn in a list opened from the boxes, nor
|
|
30
|
-
* with an app's `PartsBody`, which is told it may be emptied by `allowEmpty`. Default false. */
|
|
31
|
-
clearable?: boolean;
|
|
32
24
|
onRequestClose: (reason: CloseReason) => void;
|
|
33
25
|
} & import("react").RefAttributes<LocationEditorHandle>>;
|