@viewkitjs/views 0.0.0-stage → 0.1.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 +420 -0
- package/LICENSE.md +7 -0
- package/README.md +50 -2
- package/dist/atoms/CommandMenu.d.ts +2 -0
- package/dist/atoms/CommandMenu.js +20 -0
- package/dist/atoms/List.d.ts +2 -0
- package/dist/atoms/List.js +6 -0
- package/dist/atoms/LoadMore.d.ts +2 -0
- package/dist/atoms/LoadMore.js +25 -0
- package/dist/atoms/Loading.d.ts +2 -0
- package/dist/atoms/Loading.js +7 -0
- package/dist/atoms/PlatformMark.d.ts +2 -0
- package/dist/atoms/PlatformMark.js +4 -0
- package/dist/atoms/RelationLink.d.ts +2 -0
- package/dist/atoms/RelationLink.js +6 -0
- package/dist/atoms/Row.d.ts +3 -0
- package/dist/atoms/Row.js +30 -0
- package/dist/atoms/RowMenu.d.ts +2 -0
- package/dist/atoms/RowMenu.js +101 -0
- package/dist/atoms/StatusBadge.d.ts +2 -0
- package/dist/atoms/StatusBadge.js +7 -0
- package/dist/atoms/StatusMarker.d.ts +2 -0
- package/dist/atoms/StatusMarker.js +19 -0
- package/dist/atoms/Tag.d.ts +2 -0
- package/dist/atoms/Tag.js +13 -0
- package/dist/atoms/TickBox.d.ts +2 -0
- package/dist/atoms/TickBox.js +8 -0
- package/dist/atoms/defaults.d.ts +2 -0
- package/dist/atoms/defaults.js +27 -0
- package/dist/atoms/tones.d.ts +5 -0
- package/dist/atoms/tones.js +28 -0
- package/dist/atoms/types.d.ts +178 -0
- package/dist/atoms/types.js +3 -0
- package/dist/cells/cell-format.d.ts +138 -0
- package/dist/cells/cell-format.js +16 -0
- package/dist/cells/cell-title.d.ts +17 -0
- package/dist/cells/cell-title.js +8 -0
- package/dist/cells/cell-values.d.ts +28 -0
- package/dist/cells/cell-values.js +87 -0
- package/dist/cells/index.d.ts +4 -0
- package/dist/cells/index.js +4 -0
- package/dist/cells/legacy-field.d.ts +52 -0
- package/dist/cells/legacy-field.js +164 -0
- package/dist/cells/relation-wrap.d.ts +3 -0
- package/dist/cells/relation-wrap.js +24 -0
- package/dist/cells/use-cell-format.d.ts +5 -0
- package/dist/cells/use-cell-format.js +10 -0
- package/dist/contract.d.ts +431 -0
- package/dist/contract.js +663 -0
- package/dist/display/actor.d.ts +4 -0
- package/dist/display/actor.js +26 -0
- package/dist/display/boolean.d.ts +18 -0
- package/dist/display/boolean.js +43 -0
- package/dist/display/breakdown.d.ts +15 -0
- package/dist/display/breakdown.js +32 -0
- package/dist/display/currency.d.ts +9 -0
- package/dist/display/currency.js +29 -0
- package/dist/display/date.d.ts +12 -0
- package/dist/display/date.js +26 -0
- package/dist/display/display-cores.d.ts +31 -0
- package/dist/display/display-cores.js +57 -0
- package/dist/display/entity-chip.d.ts +26 -0
- package/dist/display/entity-chip.js +9 -0
- package/dist/display/format.d.ts +51 -0
- package/dist/display/format.js +181 -0
- package/dist/display/index.d.ts +8 -0
- package/dist/display/index.js +7 -0
- package/dist/display/link.d.ts +29 -0
- package/dist/display/link.js +48 -0
- package/dist/display/location.d.ts +7 -0
- package/dist/display/location.js +15 -0
- package/dist/display/multi-value.d.ts +18 -0
- package/dist/display/multi-value.js +28 -0
- package/dist/display/name.d.ts +6 -0
- package/dist/display/name.js +14 -0
- package/dist/display/number.d.ts +11 -0
- package/dist/display/number.js +27 -0
- package/dist/display/options.d.ts +153 -0
- package/dist/display/options.js +1 -0
- package/dist/display/percent.d.ts +4 -0
- package/dist/display/percent.js +33 -0
- package/dist/display/phone.d.ts +10 -0
- package/dist/display/phone.js +38 -0
- package/dist/display/range.d.ts +6 -0
- package/dist/display/range.js +29 -0
- package/dist/display/relation.d.ts +4 -0
- package/dist/display/relation.js +29 -0
- package/dist/display/rich-text.d.ts +10 -0
- package/dist/display/rich-text.js +34 -0
- package/dist/display/select.d.ts +6 -0
- package/dist/display/select.js +38 -0
- package/dist/display/text-class.d.ts +23 -0
- package/dist/display/text-class.js +5 -0
- package/dist/display/text.d.ts +19 -0
- package/dist/display/text.js +8 -0
- package/dist/display/use-display-options.d.ts +2 -0
- package/dist/display/use-display-options.js +14 -0
- package/dist/display/user.d.ts +11 -0
- package/dist/display/user.js +10 -0
- package/dist/display/value-list.d.ts +10 -0
- package/dist/display/value-list.js +12 -0
- package/dist/display/viewer.d.ts +4 -0
- package/dist/display/viewer.js +11 -0
- package/dist/display/web-href.d.ts +8 -0
- package/dist/display/web-href.js +12 -0
- package/dist/editors/ChipsEditor.d.ts +59 -0
- package/dist/editors/ChipsEditor.js +73 -0
- package/dist/editors/DateEditor.d.ts +25 -0
- package/dist/editors/DateEditor.js +122 -0
- package/dist/editors/LocationEditor.d.ts +22 -0
- package/dist/editors/LocationEditor.js +229 -0
- package/dist/editors/NameEditor.d.ts +22 -0
- package/dist/editors/NameEditor.js +91 -0
- package/dist/editors/NumberEditor.d.ts +67 -0
- package/dist/editors/NumberEditor.js +86 -0
- package/dist/editors/RangeEditor.d.ts +22 -0
- package/dist/editors/RangeEditor.js +70 -0
- package/dist/editors/RelationEditor.d.ts +65 -0
- package/dist/editors/RelationEditor.js +64 -0
- package/dist/editors/SelectEditor.d.ts +72 -0
- package/dist/editors/SelectEditor.js +59 -0
- package/dist/editors/ValueListEditor.d.ts +38 -0
- package/dist/editors/ValueListEditor.js +217 -0
- package/dist/editors/edit-cores.d.ts +83 -0
- package/dist/editors/edit-cores.js +38 -0
- package/dist/editors/edit-session.d.ts +74 -0
- package/dist/editors/edit-session.js +35 -0
- package/dist/editors/open-values.d.ts +28 -0
- package/dist/editors/open-values.js +26 -0
- package/dist/editors/relation-source.d.ts +66 -0
- package/dist/editors/relation-source.js +102 -0
- package/dist/fields/binding.d.ts +87 -0
- package/dist/fields/binding.js +117 -0
- package/dist/fields/currency.d.ts +92 -0
- package/dist/fields/currency.js +55 -0
- package/dist/fields/denomination.d.ts +42 -0
- package/dist/fields/denomination.js +11 -0
- package/dist/fields/edit-core-types.d.ts +40 -0
- package/dist/fields/edit-core-types.js +29 -0
- package/dist/fields/format-knobs.d.ts +34 -0
- package/dist/fields/format-knobs.js +36 -0
- package/dist/fields/menus.d.ts +28 -0
- package/dist/fields/menus.js +1 -0
- package/dist/fields/money.d.ts +59 -0
- package/dist/fields/money.js +77 -0
- package/dist/fields/number-edit.d.ts +11 -0
- package/dist/fields/number-edit.js +17 -0
- package/dist/fields/prepare-write.d.ts +55 -0
- package/dist/fields/prepare-write.js +67 -0
- package/dist/fields/relation-source-types.d.ts +54 -0
- package/dist/fields/relation-source-types.js +1 -0
- package/dist/figures.d.ts +52 -0
- package/dist/figures.js +63 -0
- package/dist/filters/date-filter.d.ts +2 -0
- package/dist/filters/date-filter.js +1 -0
- package/dist/filters/filter-model.d.ts +177 -0
- package/dist/filters/filter-model.js +41 -0
- package/dist/filters/number-filter.d.ts +2 -0
- package/dist/filters/number-filter.js +1 -0
- package/dist/filters/range-filter.d.ts +2 -0
- package/dist/filters/range-filter.js +1 -0
- package/dist/filters/registry.d.ts +136 -0
- package/dist/filters/registry.js +46 -0
- package/dist/filters/relation-filter.d.ts +16 -0
- package/dist/filters/relation-filter.js +53 -0
- package/dist/filters/text-filter.d.ts +2 -0
- package/dist/filters/text-filter.js +1 -0
- package/dist/filters/types.d.ts +27 -0
- package/dist/filters/types.js +1 -0
- package/dist/grouping/sort-groups.d.ts +18 -0
- package/dist/grouping/sort-groups.js +33 -0
- package/dist/grouping/types.d.ts +10 -0
- package/dist/grouping/types.js +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +29 -0
- package/dist/internal/chip.d.ts +4 -0
- package/dist/internal/chip.js +3 -0
- package/dist/internal/cx.d.ts +3 -0
- package/dist/internal/cx.js +3 -0
- package/dist/model/aggregates.d.ts +59 -0
- package/dist/model/aggregates.js +186 -0
- package/dist/model/card-density.d.ts +8 -0
- package/dist/model/card-density.js +10 -0
- package/dist/model/card-layout.d.ts +85 -0
- package/dist/model/card-layout.js +90 -0
- package/dist/model/column-capabilities.d.ts +162 -0
- package/dist/model/column-capabilities.js +233 -0
- package/dist/model/column-filters.d.ts +106 -0
- package/dist/model/column-filters.js +321 -0
- package/dist/model/column-format.d.ts +103 -0
- package/dist/model/column-format.js +1 -0
- package/dist/model/column-from.d.ts +28 -0
- package/dist/model/column-from.js +160 -0
- package/dist/model/column-inspect.d.ts +18 -0
- package/dist/model/column-inspect.js +6 -0
- package/dist/model/column-knobs.d.ts +20 -0
- package/dist/model/column-knobs.js +16 -0
- package/dist/model/column-money.d.ts +13 -0
- package/dist/model/column-money.js +27 -0
- package/dist/model/column-order.d.ts +36 -0
- package/dist/model/column-order.js +68 -0
- package/dist/model/column-schema.d.ts +335 -0
- package/dist/model/column-schema.js +1 -0
- package/dist/model/column-sort.d.ts +17 -0
- package/dist/model/column-sort.js +11 -0
- package/dist/model/column-state.d.ts +77 -0
- package/dist/model/column-state.js +95 -0
- package/dist/model/column-types.d.ts +109 -0
- package/dist/model/column-types.js +50 -0
- package/dist/model/column-warnings.d.ts +44 -0
- package/dist/model/column-warnings.js +24 -0
- package/dist/model/density.d.ts +3 -0
- package/dist/model/density.js +13 -0
- package/dist/model/field-type-of.d.ts +21 -0
- package/dist/model/field-type-of.js +11 -0
- package/dist/model/filter-capabilities.d.ts +1 -0
- package/dist/model/filter-capabilities.js +1 -0
- package/dist/model/filter-pushdown.d.ts +106 -0
- package/dist/model/filter-pushdown.js +147 -0
- package/dist/model/index.d.ts +40 -0
- package/dist/model/index.js +21 -0
- package/dist/model/part-rows.d.ts +28 -0
- package/dist/model/part-rows.js +40 -0
- package/dist/model/preferences.d.ts +151 -0
- package/dist/model/preferences.js +84 -0
- package/dist/model/prefs-buckets.d.ts +173 -0
- package/dist/model/prefs-buckets.js +71 -0
- package/dist/model/relation-filters.d.ts +45 -0
- package/dist/model/relation-filters.js +78 -0
- package/dist/model/render-count.d.ts +2 -0
- package/dist/model/render-count.js +24 -0
- package/dist/model/row-icon.d.ts +23 -0
- package/dist/model/row-icon.js +5 -0
- package/dist/model/view-rules.d.ts +73 -0
- package/dist/model/view-rules.js +216 -0
- package/dist/provider/ViewsProvider.d.ts +26 -0
- package/dist/provider/ViewsProvider.js +12 -0
- package/dist/provider/components.d.ts +222 -0
- package/dist/provider/components.js +3 -0
- package/dist/provider/context.d.ts +19 -0
- package/dist/provider/context.js +10 -0
- package/dist/provider/icons.d.ts +6 -0
- package/dist/provider/icons.js +1 -0
- package/dist/provider/ports.d.ts +35 -0
- package/dist/provider/ports.js +8 -0
- package/dist/react.d.ts +9 -0
- package/dist/react.js +4 -0
- package/dist/selection/SelectCheckbox.d.ts +17 -0
- package/dist/selection/SelectCheckbox.js +11 -0
- package/dist/selection/index.d.ts +7 -0
- package/dist/selection/index.js +6 -0
- package/dist/selection/model.d.ts +55 -0
- package/dist/selection/model.js +86 -0
- package/dist/selection/row-click.d.ts +35 -0
- package/dist/selection/row-click.js +20 -0
- package/dist/selection/types.d.ts +17 -0
- package/dist/selection/types.js +1 -0
- package/dist/selection/useCheckDragSelect.d.ts +61 -0
- package/dist/selection/useCheckDragSelect.js +165 -0
- package/dist/selection/useListSelection.d.ts +39 -0
- package/dist/selection/useListSelection.js +48 -0
- package/dist/selection/useListSelectionShortcuts.d.ts +6 -0
- package/dist/selection/useListSelectionShortcuts.js +14 -0
- package/dist/selection/useRestIntent.d.ts +18 -0
- package/dist/selection/useRestIntent.js +35 -0
- package/docs/contract.md +453 -0
- package/docs/install.md +105 -0
- package/docs/reshaping.md +19 -0
- package/package.json +114 -3
- package/skills/views/SKILL.md +87 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useImperativeHandle, useRef, useState } from "react";
|
|
4
|
+
import { useViews } from "../provider/context.js";
|
|
5
|
+
import { EndOfListSentinel, useRemotePage } from "./relation-source.js";
|
|
6
|
+
export { RELATION_PAGE_SIZE, RELATION_SEARCH_DEBOUNCE_MS } from "./relation-source.js";
|
|
7
|
+
export const RelationEditor = forwardRef(function RelationEditor({ candidates, initial, clearable, onRequestClose, kindGlyph, noneLabel, message, creates }, ref) {
|
|
8
|
+
const [picked, setPicked] = useState(undefined);
|
|
9
|
+
const pickedRef = useRef(undefined);
|
|
10
|
+
const [query, setQuery] = useState("");
|
|
11
|
+
const remote = candidates.kind === "remote";
|
|
12
|
+
const page = useRemotePage(candidates, query);
|
|
13
|
+
const rows = candidates.kind === "static" ? candidates.items : page.items;
|
|
14
|
+
const views = useViews();
|
|
15
|
+
const words = message ?? views.conventions.messages;
|
|
16
|
+
const { Command } = views.components;
|
|
17
|
+
const { List, Row, RowContent } = views.atoms;
|
|
18
|
+
const Add = views.icons.add;
|
|
19
|
+
const resolveClose = (reason) => {
|
|
20
|
+
if (reason !== "pick")
|
|
21
|
+
return { kind: "cancel" };
|
|
22
|
+
const value = pickedRef.current;
|
|
23
|
+
if (value === undefined)
|
|
24
|
+
return { kind: "noop" };
|
|
25
|
+
return value === initial ? { kind: "noop" } : { kind: "commit", payload: value };
|
|
26
|
+
};
|
|
27
|
+
useImperativeHandle(ref, () => ({ resolveClose }));
|
|
28
|
+
const pick = (id) => {
|
|
29
|
+
pickedRef.current = id;
|
|
30
|
+
setPicked(id);
|
|
31
|
+
onRequestClose("pick");
|
|
32
|
+
};
|
|
33
|
+
const current = picked === undefined ? initial : picked;
|
|
34
|
+
const glyphs = kindGlyph != null || rows.some((candidate) => candidate.icon != null);
|
|
35
|
+
const glyph = (node) => node != null ? (_jsx("span", { className: "flex size-3.5 items-center justify-center [&>svg]:size-3.5", children: node })) : undefined;
|
|
36
|
+
const none = clearable && (!remote || query === "");
|
|
37
|
+
const status = !remote
|
|
38
|
+
? null
|
|
39
|
+
: page.failed && rows.length === 0
|
|
40
|
+
? words({ key: "editor.search-failed" })
|
|
41
|
+
: page.searching
|
|
42
|
+
? words({ key: "editor.searching" })
|
|
43
|
+
: rows.length === 0 && !page.loadingMore
|
|
44
|
+
? words({ key: "editor.nothing-matches" })
|
|
45
|
+
: null;
|
|
46
|
+
const moreStatus = !remote
|
|
47
|
+
? null
|
|
48
|
+
: page.loadingMore
|
|
49
|
+
? words({ key: "editor.loading-more" })
|
|
50
|
+
: page.failed && rows.length > 0
|
|
51
|
+
? words({ key: "editor.search-failed" })
|
|
52
|
+
: null;
|
|
53
|
+
const paging = remote && !page.exhausted && rows.length > 0;
|
|
54
|
+
return (_jsxs(Command.Root, { shouldFilter: !remote, filter: remote
|
|
55
|
+
? undefined
|
|
56
|
+
: (value, search) => {
|
|
57
|
+
const label = rows.find((candidate) => candidate.id === value)?.label ?? "";
|
|
58
|
+
return label.toLowerCase().includes(search.toLowerCase()) ? 1 : 0;
|
|
59
|
+
}, children: [_jsx(Command.Input, { placeholder: words({ key: "editor.search" }), className: "h-9 text-[13px]", value: query, onValueChange: setQuery }), _jsxs(Command.List, { className: "max-h-72 overscroll-contain scrollbar-overlay", children: [remote ? (status && (_jsx("div", { role: "status", className: "py-4 text-center text-xs text-(color:--vk-fg-subtle)", children: status }))) : (_jsx(Command.Empty, { className: "py-4 text-center text-xs text-(color:--vk-fg-subtle)", children: words({ key: "editor.nothing-matches" }) })), _jsx(Command.Group, { className: "p-0", children: _jsxs(List, { children: [none && (_jsx(Command.Item, { value: "__none__", onSelect: () => pick(null), chosen: current == null, children: _jsx(RowContent, { size: "compact", leadingLane: glyphs, label: noneLabel ?? words({ key: "relation.none" }), tone: current == null ? "default" : "muted", chosen: current == null, chosenTint: false }) })), rows.map((candidate) => (_jsx(Command.Item, { value: candidate.id, onSelect: () => pick(candidate.id), chosen: candidate.id === current, children: _jsx(RowContent, { size: "compact", leading: glyph(candidate.icon ?? kindGlyph), leadingLane: glyphs, label: candidate.label, description: candidate.sublabel, trailing: candidate.badge ? (_jsx("span", { className: "ml-2 shrink-0 rounded-sm border border-(color:--vk-border) px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-(color:--vk-fg-subtle)", children: candidate.badge })) : undefined, chosen: candidate.id === current, chosenTint: false }) }, candidate.id)))] }) }), paging && _jsx(EndOfListSentinel, { onReveal: page.loadMore }), moreStatus && (_jsx("div", { role: "status", className: "py-3 text-center text-xs text-(color:--vk-fg-subtle)", children: moreStatus }))] }), creates && creates.length > 0 && (_jsx("div", { className: "border-t border-(color:--vk-border)", children: creates.map((create, index) => (_jsx(Row, { size: "compact", tone: "muted", leading: _jsx(Add, { className: "h-3.5 w-3.5 shrink-0" }), label: create.label(query.trim()), onClick: () => {
|
|
60
|
+
const typed = query.trim();
|
|
61
|
+
onRequestClose("pick");
|
|
62
|
+
create.onCreate(typed);
|
|
63
|
+
} }, index))) }))] }));
|
|
64
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type CategoryColor } from "@viewkitjs/fields/design/category-colors";
|
|
2
|
+
import type { StatusSlot } from "@viewkitjs/fields/design/status-slots";
|
|
3
|
+
import { type CloseReason, type CloseResolution, type FieldDefOf, type FieldMessageResolver } from "@viewkitjs/fields";
|
|
4
|
+
/**
|
|
5
|
+
* THE option-picking core — one panel, many surfaces.
|
|
6
|
+
*
|
|
7
|
+
* Every view that offers "choose one of a set" (grid cell, form field, later
|
|
8
|
+
* drawer row and board card) picks through THIS panel inside its own thin
|
|
9
|
+
* host. The host owns the popover, the anchor, the exit animation and the
|
|
10
|
+
* write; the core owns the rows, the draft, and WHAT A CLOSE MEANS for a
|
|
11
|
+
* select — a pick is the commit, everything else discards.
|
|
12
|
+
*
|
|
13
|
+
* It takes ready `PickerOption[]` rather than a field: the rows are the app's
|
|
14
|
+
* `Row` atom with its badges; colours are resolved by the caller (the grid's
|
|
15
|
+
* are per-user prefs), and resolving them here would drag grid state into a
|
|
16
|
+
* component the whole app renders. `pickerOptionsFromField` below is the
|
|
17
|
+
* mapping for a caller that HAS a field definition.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* One pickable option. `slot` → a semantic lifecycle state, drawn as the app's
|
|
21
|
+
* status badge; `color` → a decorative category, drawn as its tag; neither → a
|
|
22
|
+
* plain label. Colours are resolved by the CALLER (`resolveCategoryColor`:
|
|
23
|
+
* override → declared → derived), never here — that rule is what keeps a picker
|
|
24
|
+
* free of the list's per-user colour prefs.
|
|
25
|
+
*/
|
|
26
|
+
export type PickerOption = {
|
|
27
|
+
value: string;
|
|
28
|
+
label: string;
|
|
29
|
+
slot?: StatusSlot;
|
|
30
|
+
color?: CategoryColor;
|
|
31
|
+
/** The option's glyph (the app's own name), drawn by the app's AppIcon before its label. */
|
|
32
|
+
icon?: string;
|
|
33
|
+
};
|
|
34
|
+
export type SelectEditorHandle = {
|
|
35
|
+
/** What this close means. Synchronous, idempotent, no timer — the host
|
|
36
|
+
* closes, waits its own exit gap, then applies the answer. */
|
|
37
|
+
resolveClose: (reason: CloseReason) => CloseResolution<string>;
|
|
38
|
+
};
|
|
39
|
+
export declare const SelectEditor: import("react").ForwardRefExoticComponent<{
|
|
40
|
+
/** In display order, colours already resolved. */
|
|
41
|
+
options: PickerOption[];
|
|
42
|
+
/** The value the surface currently holds — checked in the list. */
|
|
43
|
+
initial?: string | null;
|
|
44
|
+
/** Offer "None" first — only when the surface says the value is optional.
|
|
45
|
+
* Picking it commits "", the empty value every host already maps to null
|
|
46
|
+
* (the form's own "none" state; the grid clears through Delete instead
|
|
47
|
+
* and never sets this). */
|
|
48
|
+
clearable?: boolean;
|
|
49
|
+
/** The user chose: the host closes, then asks `resolveClose("pick")`. */
|
|
50
|
+
onRequestClose: (reason: CloseReason) => void;
|
|
51
|
+
/** The host's words for this panel (fields' messages); default: the provider's conventions. */
|
|
52
|
+
message?: FieldMessageResolver;
|
|
53
|
+
/** An open select's panel (POR-865): a search over the options, and a row after them that uses the typed
|
|
54
|
+
* text when no option's value is it (POR-898: Enter picks the first match). Picking that row commits the
|
|
55
|
+
* trimmed text. */
|
|
56
|
+
creatable?: boolean;
|
|
57
|
+
} & import("react").RefAttributes<SelectEditorHandle>>;
|
|
58
|
+
/**
|
|
59
|
+
* A select field's options, dressed the way its cells are drawn — so what you
|
|
60
|
+
* pick in a form looks like what the grid shows.
|
|
61
|
+
*
|
|
62
|
+
* Archived options never reach a picker (`optionsOf`). A status keeps its
|
|
63
|
+
* semantic slots; a select gets the category-colour chain — the workspace's
|
|
64
|
+
* `optionColors` first, then the field's own, then the derived hue — which is
|
|
65
|
+
* the same colour the grid draws. `extraValues` are values the rows hold that
|
|
66
|
+
* no option names: offered so a stray value can be picked back, drawn as its
|
|
67
|
+
* raw code (a registry never invents a label); an archived value stays out.
|
|
68
|
+
*/
|
|
69
|
+
export declare function pickerOptionsFromField(field: FieldDefOf<"select" | "status">, opts?: {
|
|
70
|
+
optionColors?: Record<string, CategoryColor>;
|
|
71
|
+
extraValues?: readonly string[];
|
|
72
|
+
}): PickerOption[];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useImperativeHandle, useRef, useState } from "react";
|
|
4
|
+
import { resolveCategoryColor } from "@viewkitjs/fields/design/category-colors";
|
|
5
|
+
import { optionsOf, } from "@viewkitjs/fields";
|
|
6
|
+
import { useViews } from "../provider/context.js";
|
|
7
|
+
export const SelectEditor = forwardRef(function SelectEditor({ options, initial, clearable = false, onRequestClose, message, creatable = false }, ref) {
|
|
8
|
+
const [picked, setPicked] = useState(null);
|
|
9
|
+
const pickedRef = useRef(null);
|
|
10
|
+
const [query, setQuery] = useState("");
|
|
11
|
+
const views = useViews();
|
|
12
|
+
const words = message ?? views.conventions.messages;
|
|
13
|
+
const { List, Row, RowContent, StatusBadge, Tag } = views.atoms;
|
|
14
|
+
const { AppIcon, Command } = views.components;
|
|
15
|
+
const Add = views.icons.add;
|
|
16
|
+
const glyph = (icon) => (icon ? _jsx(AppIcon, { name: icon, className: "size-3 shrink-0" }) : undefined);
|
|
17
|
+
const resolveClose = (reason) => {
|
|
18
|
+
if (reason !== "pick")
|
|
19
|
+
return { kind: "cancel" };
|
|
20
|
+
const value = pickedRef.current;
|
|
21
|
+
if (value == null)
|
|
22
|
+
return { kind: "noop" };
|
|
23
|
+
return value === (initial ?? "") ? { kind: "noop" } : { kind: "commit", payload: value };
|
|
24
|
+
};
|
|
25
|
+
useImperativeHandle(ref, () => ({ resolveClose }));
|
|
26
|
+
const rows = clearable
|
|
27
|
+
? [{ value: "", label: words({ key: "relation.none" }) }, ...options]
|
|
28
|
+
: options;
|
|
29
|
+
const current = picked ?? initial ?? (clearable ? "" : undefined);
|
|
30
|
+
const choose = (value) => {
|
|
31
|
+
pickedRef.current = value;
|
|
32
|
+
setPicked(value);
|
|
33
|
+
onRequestClose("pick");
|
|
34
|
+
};
|
|
35
|
+
const badge = (option) => option.slot ? (_jsx(StatusBadge, { slot: option.slot, label: option.label, leading: glyph(option.icon) })) : option.color ? (_jsx(Tag, { label: option.label, color: option.color, leading: glyph(option.icon) })) : (option.label);
|
|
36
|
+
if (creatable) {
|
|
37
|
+
const typed = query.trim();
|
|
38
|
+
const needle = typed.toLowerCase();
|
|
39
|
+
const shown = (typed === "" ? rows : options).filter((option) => needle === "" || option.label.toLowerCase().includes(needle));
|
|
40
|
+
const useTyped = typed !== "" && !options.some((option) => option.value.toLowerCase() === needle);
|
|
41
|
+
const useRow = useTyped && (_jsx(Command.Item, { value: `__use__${typed}`, onSelect: () => choose(typed), children: _jsx(RowContent, { size: "compact", tone: "muted", leading: _jsx(Add, { className: "h-3.5 w-3.5 shrink-0" }), label: words({ key: "editor.use-value", values: { value: typed } }) }) }));
|
|
42
|
+
return (_jsxs(Command.Root, { shouldFilter: false, loop: true, children: [_jsx(Command.Input, { placeholder: words({ key: "editor.search" }), className: "h-9 text-[13px]", value: query, onValueChange: setQuery }), _jsxs(Command.List, { className: "max-h-72 overscroll-contain scrollbar-overlay", children: [!useTyped && shown.length === 0 && (_jsx(Command.Empty, { className: "py-4 text-center text-xs text-(color:--vk-fg-subtle)", children: words({ key: "editor.nothing-matches" }) })), _jsx(Command.Group, { className: "p-0", children: _jsxs(List, { children: [shown.map((option) => (_jsx(Command.Item, { value: option.value, onSelect: () => choose(option.value), chosen: current === option.value, children: _jsx(RowContent, { size: option.slot || option.color ? undefined : "compact", leading: option.slot || option.color ? undefined : glyph(option.icon), label: badge(option), chosen: current === option.value, chosenTint: false }) }, option.value))), useRow] }) })] })] }));
|
|
43
|
+
}
|
|
44
|
+
return (_jsx(List, { className: "max-h-72 overflow-y-auto overscroll-contain scrollbar-overlay", children: rows.map((option) => (_jsx(Row, { chosen: current === option.value, chosenTint: false, size: option.slot || option.color ? undefined : "compact", leading: option.slot || option.color ? undefined : glyph(option.icon), label: badge(option), onClick: () => choose(option.value) }, option.value))) }));
|
|
45
|
+
});
|
|
46
|
+
export function pickerOptionsFromField(field, opts = {}) {
|
|
47
|
+
const active = [...optionsOf(field)];
|
|
48
|
+
const declared = new Set(active.map((o) => o.value));
|
|
49
|
+
const archived = new Set(field.options.filter((o) => o.archived).map((o) => o.value));
|
|
50
|
+
const extras = (opts.extraValues ?? []).filter((v) => !declared.has(v) && !archived.has(v));
|
|
51
|
+
const dress = (value, label) => {
|
|
52
|
+
const option = field.options.find((o) => o.value === value);
|
|
53
|
+
const dressed = field.type === "status"
|
|
54
|
+
? { value, label, slot: option?.slot ?? "muted" }
|
|
55
|
+
: { value, label, color: resolveCategoryColor(value, active, opts.optionColors) };
|
|
56
|
+
return option?.icon ? { ...dressed, icon: option.icon } : dressed;
|
|
57
|
+
};
|
|
58
|
+
return [...active.map((o) => dress(o.value, o.label)), ...extras.map((v) => dress(v, v))];
|
|
59
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type CloseReason, type CloseResolution, type FieldDefOf, type MultipleType, type ValueItem } from "@viewkitjs/fields";
|
|
2
|
+
/**
|
|
3
|
+
* SEVERAL VALUES OF ONE KIND — emails, phones, links or domains, each with its
|
|
4
|
+
* label and one of them the main one (VK-58's `{ value, label, main }`).
|
|
5
|
+
*
|
|
6
|
+
* A row per value: the value, its label, a mark that makes it the main one and
|
|
7
|
+
* a remove. An Add row appends an empty one. Each value is read by its type's
|
|
8
|
+
* own rule (the field's single-value commit: an email's shape, a domain
|
|
9
|
+
* cleaned, a phone read in the host's region) when focus leaves its row, and a
|
|
10
|
+
* refusal is said under the row. Tab walks each row's main mark, value, label
|
|
11
|
+
* and remove, then Add, and Enter or Space presses a mark or a remove. Enter in
|
|
12
|
+
* a box, and Tab out of the editor, check every row first and stay open on a
|
|
13
|
+
* refusal.
|
|
14
|
+
*
|
|
15
|
+
* It is a draft, like the chips editor: the whole list commits ONCE when the
|
|
16
|
+
* host closes it, the main one first. Escape discards; any other close keeps
|
|
17
|
+
* what was built; closed untouched it writes nothing. A row left untouched
|
|
18
|
+
* keeps its stored value as stored, so a phone kept as typed is not rewritten
|
|
19
|
+
* by opening the editor. A row typed in commits its text, which the field's
|
|
20
|
+
* commit reads; a row whose reason still shows is refused there.
|
|
21
|
+
*/
|
|
22
|
+
export type ValueListEditorHandle = {
|
|
23
|
+
resolveClose: (reason: CloseReason) => CloseResolution<ValueItem<unknown>[] | null>;
|
|
24
|
+
};
|
|
25
|
+
export declare const ValueListEditor: import("react").ForwardRefExoticComponent<{
|
|
26
|
+
/** A `multiple` email, phone, url or domain field. */
|
|
27
|
+
field: FieldDefOf<MultipleType>;
|
|
28
|
+
/** The stored list: items, or a plain list of values. */
|
|
29
|
+
initial: unknown;
|
|
30
|
+
/** Whether the host keeps a label beside each value. Default true; false draws no label boxes and commits
|
|
31
|
+
* every label null. */
|
|
32
|
+
labels?: boolean;
|
|
33
|
+
/** A clear (no values) may be committed. */
|
|
34
|
+
allowEmpty?: boolean;
|
|
35
|
+
/** The record's country, where a phone typed without its country code is read; else the conventions' region. */
|
|
36
|
+
region?: string | null;
|
|
37
|
+
onRequestClose: (reason: CloseReason) => void;
|
|
38
|
+
} & import("react").RefAttributes<ValueListEditorHandle>>;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef, useState, } from "react";
|
|
4
|
+
import { acceptFieldCommit, phoneText, valueItems, valueKey, } from "@viewkitjs/fields";
|
|
5
|
+
import { cx } from "../internal/cx.js";
|
|
6
|
+
import { useViews } from "../provider/context.js";
|
|
7
|
+
function textOf(value) {
|
|
8
|
+
if (typeof value === "string")
|
|
9
|
+
return value;
|
|
10
|
+
return phoneText(value, null) || String(value);
|
|
11
|
+
}
|
|
12
|
+
export const ValueListEditor = forwardRef(function ValueListEditor({ field, initial, labels = true, allowEmpty = false, region, onRequestClose }, ref) {
|
|
13
|
+
const views = useViews();
|
|
14
|
+
const words = views.messages;
|
|
15
|
+
const { Row } = views.atoms;
|
|
16
|
+
const Add = views.icons.add;
|
|
17
|
+
const Remove = views.icons.close;
|
|
18
|
+
const boxRef = useRef(null);
|
|
19
|
+
const nextId = useRef(0);
|
|
20
|
+
const [opened] = useState(() => {
|
|
21
|
+
const items = valueItems(initial);
|
|
22
|
+
const main = items.find((item) => item.main);
|
|
23
|
+
const one = items.map((item) => ({ ...item, label: item.label?.trim() || null, main: item === main }));
|
|
24
|
+
const first = one.find((item) => item.main);
|
|
25
|
+
return first ? [first, ...one.filter((item) => item !== first)] : one;
|
|
26
|
+
});
|
|
27
|
+
const [rows, setRows] = useState(() => opened.length === 0
|
|
28
|
+
? [{ id: nextId.current++, text: "", label: "", main: true }]
|
|
29
|
+
: opened.map((item) => {
|
|
30
|
+
const text = textOf(item.value);
|
|
31
|
+
return { id: nextId.current++, text, label: item.label ?? "", main: item.main, stored: { value: item.value, text } };
|
|
32
|
+
}));
|
|
33
|
+
const rowsRef = useRef(rows);
|
|
34
|
+
const update = (next) => {
|
|
35
|
+
rowsRef.current = next;
|
|
36
|
+
setRows(next);
|
|
37
|
+
};
|
|
38
|
+
const focusRow = useRef(null);
|
|
39
|
+
const focusAdd = useRef(false);
|
|
40
|
+
const addRef = useRef(null);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
const first = boxRef.current?.querySelector("input[data-value]");
|
|
43
|
+
first?.focus();
|
|
44
|
+
}, []);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (focusAdd.current)
|
|
47
|
+
addRef.current?.querySelector("button")?.focus();
|
|
48
|
+
focusAdd.current = false;
|
|
49
|
+
if (focusRow.current == null)
|
|
50
|
+
return;
|
|
51
|
+
boxRef.current?.querySelector(`input[data-value="${focusRow.current}"]`)?.focus();
|
|
52
|
+
focusRow.current = null;
|
|
53
|
+
}, [rows]);
|
|
54
|
+
const single = (() => {
|
|
55
|
+
const { multiple: _multiple, ...one } = field;
|
|
56
|
+
return one;
|
|
57
|
+
})();
|
|
58
|
+
const untouched = (row) => row.stored !== undefined && row.text === row.stored.text;
|
|
59
|
+
const check = (row) => {
|
|
60
|
+
if (row.text.trim() === "" || untouched(row))
|
|
61
|
+
return null;
|
|
62
|
+
const read = acceptFieldCommit(single, row.text, { conventions: views.conventions, region });
|
|
63
|
+
return read.ok ? null : read.reason;
|
|
64
|
+
};
|
|
65
|
+
const checkAll = () => {
|
|
66
|
+
let ok = true;
|
|
67
|
+
const next = rowsRef.current.map((row) => {
|
|
68
|
+
const error = check(row) ?? undefined;
|
|
69
|
+
if (error)
|
|
70
|
+
ok = false;
|
|
71
|
+
return error === row.error ? row : { ...row, error };
|
|
72
|
+
});
|
|
73
|
+
if (next.some((row, at) => row !== rowsRef.current[at]))
|
|
74
|
+
update(next);
|
|
75
|
+
return ok;
|
|
76
|
+
};
|
|
77
|
+
const checkRow = (id) => {
|
|
78
|
+
const row = rowsRef.current.find((each) => each.id === id);
|
|
79
|
+
if (!row)
|
|
80
|
+
return true;
|
|
81
|
+
const error = check(row) ?? undefined;
|
|
82
|
+
if (error !== row.error)
|
|
83
|
+
update(rowsRef.current.map((each) => (each.id === id ? { ...each, error } : each)));
|
|
84
|
+
return error === undefined;
|
|
85
|
+
};
|
|
86
|
+
const resolveClose = (reason) => {
|
|
87
|
+
if (reason === "escape")
|
|
88
|
+
return { kind: "cancel" };
|
|
89
|
+
const kept = rowsRef.current.filter((row) => row.text.trim() !== "");
|
|
90
|
+
const items = kept.map((row) => ({
|
|
91
|
+
value: untouched(row) ? row.stored.value : row.text.trim(),
|
|
92
|
+
label: labels && row.label.trim() !== "" ? row.label.trim() : null,
|
|
93
|
+
main: row.main,
|
|
94
|
+
}));
|
|
95
|
+
if (items.length > 0 && !items.some((item) => item.main))
|
|
96
|
+
items[0] = { ...items[0], main: true };
|
|
97
|
+
const main = items.find((item) => item.main);
|
|
98
|
+
const next = main ? [main, ...items.filter((item) => item !== main)] : items;
|
|
99
|
+
const same = next.length === opened.length &&
|
|
100
|
+
next.every((item, at) => {
|
|
101
|
+
const was = opened[at];
|
|
102
|
+
return (valueKey(item.value) === valueKey(was.value) &&
|
|
103
|
+
item.label === (labels ? was.label : null) &&
|
|
104
|
+
item.main === was.main);
|
|
105
|
+
});
|
|
106
|
+
if (same)
|
|
107
|
+
return { kind: "noop" };
|
|
108
|
+
if (next.length === 0)
|
|
109
|
+
return allowEmpty ? { kind: "commit", payload: null } : { kind: "cancel" };
|
|
110
|
+
return { kind: "commit", payload: next };
|
|
111
|
+
};
|
|
112
|
+
useImperativeHandle(ref, () => ({ resolveClose }));
|
|
113
|
+
const set = (id, change) => update(rowsRef.current.map((row) => (row.id === id ? { ...row, ...change } : row)));
|
|
114
|
+
const makeMain = (id) => update(rowsRef.current.map((row) => ({ ...row, main: row.id === id })));
|
|
115
|
+
const remove = (id) => {
|
|
116
|
+
const at = rowsRef.current.findIndex((row) => row.id === id);
|
|
117
|
+
const left = rowsRef.current.filter((row) => row.id !== id);
|
|
118
|
+
const next = left[at];
|
|
119
|
+
if (next)
|
|
120
|
+
focusRow.current = next.id;
|
|
121
|
+
else
|
|
122
|
+
focusAdd.current = true;
|
|
123
|
+
update(left.length > 0 && !left.some((row) => row.main) ? left.map((row, i) => ({ ...row, main: i === 0 })) : left);
|
|
124
|
+
};
|
|
125
|
+
const add = () => {
|
|
126
|
+
const id = nextId.current++;
|
|
127
|
+
focusRow.current = id;
|
|
128
|
+
update([...rowsRef.current, { id, text: "", label: "", main: rowsRef.current.length === 0 }]);
|
|
129
|
+
};
|
|
130
|
+
const addButton = () => addRef.current?.querySelector("button") ?? null;
|
|
131
|
+
const controls = () => {
|
|
132
|
+
const walk = Array.from(boxRef.current?.querySelectorAll("[data-walk]") ?? []);
|
|
133
|
+
const add = addButton();
|
|
134
|
+
return add ? [...walk, add] : walk;
|
|
135
|
+
};
|
|
136
|
+
const keys = (id) => (e) => {
|
|
137
|
+
e.stopPropagation();
|
|
138
|
+
if (e.key === "Escape") {
|
|
139
|
+
onRequestClose("escape");
|
|
140
|
+
}
|
|
141
|
+
else if (e.key === "Enter") {
|
|
142
|
+
e.preventDefault();
|
|
143
|
+
if (checkAll())
|
|
144
|
+
onRequestClose("enter");
|
|
145
|
+
}
|
|
146
|
+
else if (e.key === "Tab") {
|
|
147
|
+
const all = controls();
|
|
148
|
+
const at = all.indexOf(e.currentTarget);
|
|
149
|
+
const to = all[at + (e.shiftKey ? -1 : 1)];
|
|
150
|
+
e.preventDefault();
|
|
151
|
+
if (!to) {
|
|
152
|
+
if (checkAll())
|
|
153
|
+
onRequestClose(e.shiftKey ? "shift-tab" : "tab");
|
|
154
|
+
}
|
|
155
|
+
else if (to !== addButton() || checkRow(id)) {
|
|
156
|
+
to.focus();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
const buttonKeys = (id, press) => (e) => {
|
|
161
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
162
|
+
e.preventDefault();
|
|
163
|
+
e.stopPropagation();
|
|
164
|
+
press();
|
|
165
|
+
}
|
|
166
|
+
else
|
|
167
|
+
keys(id)(e);
|
|
168
|
+
};
|
|
169
|
+
const noSpaceClick = (e) => {
|
|
170
|
+
if (e.key === " ")
|
|
171
|
+
e.preventDefault();
|
|
172
|
+
};
|
|
173
|
+
const addKeys = (e) => {
|
|
174
|
+
if (e.key === "Escape") {
|
|
175
|
+
e.stopPropagation();
|
|
176
|
+
onRequestClose("escape");
|
|
177
|
+
}
|
|
178
|
+
else if (e.key === "Tab") {
|
|
179
|
+
e.preventDefault();
|
|
180
|
+
e.stopPropagation();
|
|
181
|
+
const all = controls();
|
|
182
|
+
const back = all[all.length - 2];
|
|
183
|
+
if (e.shiftKey && back)
|
|
184
|
+
back.focus();
|
|
185
|
+
else if (checkAll())
|
|
186
|
+
onRequestClose(e.shiftKey ? "shift-tab" : "tab");
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
const blur = (id) => (e) => {
|
|
190
|
+
const to = e.relatedTarget;
|
|
191
|
+
const rowEl = e.currentTarget.closest("[data-row]");
|
|
192
|
+
if (!rowEl?.contains(to))
|
|
193
|
+
checkRow(id);
|
|
194
|
+
if (!boxRef.current?.contains(to))
|
|
195
|
+
onRequestClose("blur");
|
|
196
|
+
};
|
|
197
|
+
const input = "h-7 min-w-0 select-text rounded-md bg-transparent px-1.5 text-[length:var(--grid-text,0.8125rem)] text-(color:--vk-fg) outline-hidden placeholder:text-(color:--vk-fg-subtle) focus:bg-(color:--vk-hovered)";
|
|
198
|
+
const iconButton = "flex size-6 shrink-0 items-center justify-center rounded-md text-(color:--vk-fg-subtle) transition-colors hover:bg-(color:--vk-hovered) hover:text-(color:--vk-fg)";
|
|
199
|
+
return (_jsxs("div", { ref: boxRef, onMouseDown: (e) => {
|
|
200
|
+
if (!(e.target instanceof HTMLInputElement))
|
|
201
|
+
e.preventDefault();
|
|
202
|
+
}, className: "flex w-full min-w-0 flex-col gap-0.5", children: [rows.map((row) => {
|
|
203
|
+
const shown = row.text.trim() || field.label;
|
|
204
|
+
return (_jsxs("div", { "data-row": true, className: "flex flex-col", children: [_jsxs("div", { className: "flex min-w-0 items-center gap-1", children: [_jsx("button", { type: "button", "data-walk": true, "aria-pressed": row.main, "aria-label": row.main
|
|
205
|
+
? words({ key: "views.editors.values-main" })
|
|
206
|
+
: words({ key: "views.editors.values-make-main", values: { value: shown } }), title: row.main ? words({ key: "views.editors.values-main" }) : undefined, onClick: (e) => {
|
|
207
|
+
e.stopPropagation();
|
|
208
|
+
makeMain(row.id);
|
|
209
|
+
}, onKeyDown: buttonKeys(row.id, () => makeMain(row.id)), onKeyUp: noSpaceClick, onBlur: blur(row.id), className: iconButton, children: _jsx("span", { className: cx("size-2.5 rounded-full border border-(color:--vk-fg-subtle)", row.main && "border-(color:--vk-fg-brand) bg-(color:--vk-fg-brand)") }) }), _jsx("input", { "data-walk": true, "data-value": row.id, value: row.text, "aria-label": field.label, placeholder: field.label, "aria-invalid": row.error ? true : undefined, onChange: (e) => set(row.id, { text: e.target.value, error: undefined }), onKeyDown: keys(row.id), onBlur: blur(row.id), onClick: (e) => e.stopPropagation(), className: cx(input, "flex-1") }), labels && (_jsx("input", { "data-walk": true, value: row.label, "aria-label": words({ key: "views.editors.values-label" }), placeholder: words({ key: "views.editors.values-label" }), onChange: (e) => set(row.id, { label: e.target.value }), onKeyDown: keys(row.id), onBlur: blur(row.id), onClick: (e) => e.stopPropagation(), className: cx(input, "w-24") })), _jsx("button", { type: "button", "data-walk": true, "aria-label": words({ key: "views.editors.values-remove", values: { value: shown } }), onClick: (e) => {
|
|
210
|
+
e.stopPropagation();
|
|
211
|
+
remove(row.id);
|
|
212
|
+
}, onKeyDown: buttonKeys(row.id, () => remove(row.id)), onKeyUp: noSpaceClick, onBlur: blur(row.id), className: iconButton, children: _jsx(Remove, { className: "size-3.5" }) })] }), row.error && (_jsx("p", { role: "alert", className: "px-8 pb-1 text-xs text-(color:--vk-danger)", children: row.error }))] }, row.id));
|
|
213
|
+
}), _jsx("div", { ref: addRef, onKeyDown: addKeys, onBlur: (e) => {
|
|
214
|
+
if (!boxRef.current?.contains(e.relatedTarget))
|
|
215
|
+
onRequestClose("blur");
|
|
216
|
+
}, children: _jsx(Row, { tone: "muted", size: "compact", leading: _jsx(Add, { className: "size-3.5" }), label: words({ key: "views.editors.values-add" }), onMouseDown: (e) => e.preventDefault(), onClick: add }) })] }));
|
|
217
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ONE EDITOR PER STORAGE TYPE, and the table that picks between them — the EDIT
|
|
3
|
+
* twin of `DISPLAY_CORES` (spec §3.4), the same idea for the other family.
|
|
4
|
+
*
|
|
5
|
+
* The dispatch is a mapped record over `FieldType` for one reason: a type added
|
|
6
|
+
* to the union with no answer here fails to COMPILE. A host that imports the
|
|
7
|
+
* one core it happens to need cannot notice a type nobody serves — that gap
|
|
8
|
+
* compiles perfectly clean, and the first sign of it is a field that won't open
|
|
9
|
+
* in front of someone.
|
|
10
|
+
*
|
|
11
|
+
* THE MEMBERS THAT ARE `null` are an answer rather than a gap. `text`,
|
|
12
|
+
* `url`, `email` and `phone` have no panel, no draft and no parsing: a bare
|
|
13
|
+
* input the host already owns is the whole editor. `boolean` commits straight
|
|
14
|
+
* from its display control — the checkbox IS the edit, so there is nothing to
|
|
15
|
+
* mount, which is why `GRID_TYPE_RULES.boolean.editor` is `null` too.
|
|
16
|
+
* `actor` is set by the system.
|
|
17
|
+
* `rollup` and `formula` are derived — their value is computed, never
|
|
18
|
+
* committed, so no surface ever opens an editor on one. Spelling them out instead of leaving them out is what
|
|
19
|
+
* keeps the compiler's check worth having: an absent member reads as an
|
|
20
|
+
* oversight, a `null` reads as a decision.
|
|
21
|
+
*
|
|
22
|
+
* `percent` and `currency` are the NUMBER core — one figure, a different
|
|
23
|
+
* denomination; `status` is the SELECT core — one option from a vocabulary,
|
|
24
|
+
* wearing a slot instead of a colour; `user` is the RELATION core — a pointer
|
|
25
|
+
* at a member row. The same object reference each time, so the three pairs
|
|
26
|
+
* can never drift.
|
|
27
|
+
*
|
|
28
|
+
* THE CORE OWNS THE PANEL and what a close MEANS — the option list, the draft,
|
|
29
|
+
* `resolveClose(reason)` deciding commit or discard. THE HOST — grid cell, form
|
|
30
|
+
* field, drawer row, board card — owns its own mounting, focus and commit
|
|
31
|
+
* timing, because those differ per surface and no portable core can know them.
|
|
32
|
+
* Share the core, never the host (spec §2.2).
|
|
33
|
+
*/
|
|
34
|
+
import type { ForwardRefExoticComponent, RefAttributes } from "react";
|
|
35
|
+
import type { FieldType } from "@viewkitjs/fields";
|
|
36
|
+
import { ChipsEditor, type ChipsEditorHandle } from "./ChipsEditor.js";
|
|
37
|
+
import { DateEditor, type DateEditorHandle } from "./DateEditor.js";
|
|
38
|
+
import { hasEditCore } from "../fields/edit-core-types.js";
|
|
39
|
+
import { LocationEditor, type LocationEditorHandle } from "./LocationEditor.js";
|
|
40
|
+
import { NameEditor, type NameEditorHandle } from "./NameEditor.js";
|
|
41
|
+
import { NumberEditor, type NumberEditorHandle } from "./NumberEditor.js";
|
|
42
|
+
import { RangeEditor, type RangeEditorHandle } from "./RangeEditor.js";
|
|
43
|
+
import { RelationEditor, type RelationEditorHandle } from "./RelationEditor.js";
|
|
44
|
+
import { SelectEditor, type SelectEditorHandle } from "./SelectEditor.js";
|
|
45
|
+
/** The props a `forwardRef` component declares — its ref attributes included,
|
|
46
|
+
* which is how the handle below stays part of the comparison. */
|
|
47
|
+
type PropsOf<C> = C extends ForwardRefExoticComponent<infer P> ? P : never;
|
|
48
|
+
/** A core re-stated as ITS props against ITS handle. Stating both is what makes
|
|
49
|
+
* a member bound to the WRONG editor a type error, not merely a missing one. */
|
|
50
|
+
type Core<C, H> = ForwardRefExoticComponent<PropsOf<C> & RefAttributes<H>>;
|
|
51
|
+
/**
|
|
52
|
+
* `& Record<FieldType, unknown>` is load-bearing: it demands a member for every
|
|
53
|
+
* type in the union while still letting several of them be `null`, which a
|
|
54
|
+
* `{ [K in FieldType]: ... }` mapped type could only do by widening every
|
|
55
|
+
* member's type and giving up the per-type binding above.
|
|
56
|
+
*/
|
|
57
|
+
export declare const EDIT_CORES: {
|
|
58
|
+
date: Core<typeof DateEditor, DateEditorHandle>;
|
|
59
|
+
datetime: Core<typeof DateEditor, DateEditorHandle>;
|
|
60
|
+
select: Core<typeof SelectEditor, SelectEditorHandle>;
|
|
61
|
+
status: Core<typeof SelectEditor, SelectEditorHandle>;
|
|
62
|
+
multiselect: Core<typeof ChipsEditor, ChipsEditorHandle>;
|
|
63
|
+
relation: Core<typeof RelationEditor, RelationEditorHandle>;
|
|
64
|
+
user: Core<typeof RelationEditor, RelationEditorHandle>;
|
|
65
|
+
number: Core<typeof NumberEditor, NumberEditorHandle>;
|
|
66
|
+
percent: Core<typeof NumberEditor, NumberEditorHandle>;
|
|
67
|
+
currency: Core<typeof NumberEditor, NumberEditorHandle>;
|
|
68
|
+
range: Core<typeof RangeEditor, RangeEditorHandle>;
|
|
69
|
+
name: Core<typeof NameEditor, NameEditorHandle>;
|
|
70
|
+
location: Core<typeof LocationEditor, LocationEditorHandle>;
|
|
71
|
+
text: null;
|
|
72
|
+
url: null;
|
|
73
|
+
domain: null;
|
|
74
|
+
email: null;
|
|
75
|
+
phone: null;
|
|
76
|
+
boolean: null;
|
|
77
|
+
actor: null;
|
|
78
|
+
rich_text: null;
|
|
79
|
+
lookup: null;
|
|
80
|
+
rollup: null;
|
|
81
|
+
formula: null;
|
|
82
|
+
} & Record<FieldType, unknown>;
|
|
83
|
+
export { hasEditCore };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ChipsEditor } from "./ChipsEditor.js";
|
|
2
|
+
import { DateEditor } from "./DateEditor.js";
|
|
3
|
+
import { hasEditCore } from "../fields/edit-core-types.js";
|
|
4
|
+
import { LocationEditor } from "./LocationEditor.js";
|
|
5
|
+
import { NameEditor } from "./NameEditor.js";
|
|
6
|
+
import { NumberEditor } from "./NumberEditor.js";
|
|
7
|
+
import { RangeEditor } from "./RangeEditor.js";
|
|
8
|
+
import { RelationEditor } from "./RelationEditor.js";
|
|
9
|
+
import { SelectEditor } from "./SelectEditor.js";
|
|
10
|
+
export const EDIT_CORES = {
|
|
11
|
+
date: DateEditor,
|
|
12
|
+
datetime: DateEditor,
|
|
13
|
+
select: SelectEditor,
|
|
14
|
+
status: SelectEditor,
|
|
15
|
+
multiselect: ChipsEditor,
|
|
16
|
+
relation: RelationEditor,
|
|
17
|
+
user: RelationEditor,
|
|
18
|
+
number: NumberEditor,
|
|
19
|
+
percent: NumberEditor,
|
|
20
|
+
currency: NumberEditor,
|
|
21
|
+
range: RangeEditor,
|
|
22
|
+
name: NameEditor,
|
|
23
|
+
text: null,
|
|
24
|
+
url: null,
|
|
25
|
+
domain: null,
|
|
26
|
+
email: null,
|
|
27
|
+
phone: null,
|
|
28
|
+
boolean: null,
|
|
29
|
+
location: LocationEditor,
|
|
30
|
+
actor: null,
|
|
31
|
+
rich_text: null,
|
|
32
|
+
lookup: null,
|
|
33
|
+
rollup: null,
|
|
34
|
+
formula: null,
|
|
35
|
+
};
|
|
36
|
+
const NO_DRIFT = true;
|
|
37
|
+
void NO_DRIFT;
|
|
38
|
+
export { hasEditCore };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
import type { CloseReason, CloseResolution } from "@viewkitjs/fields";
|
|
3
|
+
/**
|
|
4
|
+
* THE ANCHORED EDIT SESSION — the handshake plumbing every host that opens a
|
|
5
|
+
* PANEL over a value repeats, in one place.
|
|
6
|
+
*
|
|
7
|
+
* It is not a host, and the distinction is the spec's (§2.2, "share the core,
|
|
8
|
+
* never the host"): a host owns its popover, its anchor, its focus decision and
|
|
9
|
+
* the shape of the payload it hands back, because those differ per surface. It
|
|
10
|
+
* does NOT own the one-answer guard or the exit gap — those are the same three
|
|
11
|
+
* lines on a drawer row, a board card and a calendar card, and they are exactly
|
|
12
|
+
* where a bug is invisible: a session that answers twice writes twice, and one
|
|
13
|
+
* that answers during its own exit animation unmounts the panel mid-flight.
|
|
14
|
+
*
|
|
15
|
+
* The package's, behind its own door (`@viewkitjs/views/editors/session`), so both
|
|
16
|
+
* host families reach it without reaching each other, and without loading the five
|
|
17
|
+
* editors the `./editors` registry does.
|
|
18
|
+
*/
|
|
19
|
+
/** The slice of a core's handle this needs: one synchronous, idempotent answer. */
|
|
20
|
+
type ResolvableHandle<P> = {
|
|
21
|
+
resolveClose: (reason: CloseReason) => CloseResolution<P>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The gap an anchored host waits between closing its popover and reporting its
|
|
25
|
+
* answer.
|
|
26
|
+
*
|
|
27
|
+
* The popover's exit animation has to play out before the value renders again
|
|
28
|
+
* behind it — notifying at once unmounts the panel mid-animation, which is the
|
|
29
|
+
* "no transition on close" bug the grid's cell editors document. The timer
|
|
30
|
+
* belongs to the SESSION and never to the core: it is what guarantees a delayed
|
|
31
|
+
* callback cannot fire twice or land in a session that has already reopened.
|
|
32
|
+
*
|
|
33
|
+
* A host that admits the answer synchronously clears this UI-only timer on
|
|
34
|
+
* unmount: the write already belongs to its coordinator. The legacy deferred
|
|
35
|
+
* mode used by card hosts keeps the timer because their answer still carries
|
|
36
|
+
* the write. New hosts should prefer synchronous admission.
|
|
37
|
+
*/
|
|
38
|
+
export declare const EDITOR_EXIT_MS = 160;
|
|
39
|
+
/**
|
|
40
|
+
* Opens already-open — the surface swapped its value for this editor, so there
|
|
41
|
+
* is no closed state to animate in from.
|
|
42
|
+
*
|
|
43
|
+
* `close(reason)` is the ONE door: Radix's dismiss, the core's own
|
|
44
|
+
* `onRequestClose`, and a host's keyboard handler all land here, and only the
|
|
45
|
+
* first counts. `mapPayload` is the host's one chance to reshape a commit
|
|
46
|
+
* before it leaves (a select's empty string becoming `null`, a day field's
|
|
47
|
+
* timestamp trimmed to its date) — applied to a commit alone, never to a cancel
|
|
48
|
+
* or a noop, which carry no payload to reshape.
|
|
49
|
+
*/
|
|
50
|
+
type AnchoredEditSessionBase<P> = {
|
|
51
|
+
editorRef: RefObject<ResolvableHandle<P> | null>;
|
|
52
|
+
mapPayload?: (payload: P) => unknown;
|
|
53
|
+
exitMs?: number;
|
|
54
|
+
};
|
|
55
|
+
type DeferredResolution<P> = AnchoredEditSessionBase<P> & {
|
|
56
|
+
/** Compatibility mode: the answer, including persistence, follows the exit. */
|
|
57
|
+
onDone: (resolution: CloseResolution<unknown>) => void;
|
|
58
|
+
onAttempt?: never;
|
|
59
|
+
onClose?: never;
|
|
60
|
+
};
|
|
61
|
+
type AdmittedResolution<P> = AnchoredEditSessionBase<P> & {
|
|
62
|
+
/** Ask synchronously whether this answer may close. Refusal is nonterminal. */
|
|
63
|
+
onAttempt: (resolution: CloseResolution<unknown>) => {
|
|
64
|
+
accepted: boolean;
|
|
65
|
+
};
|
|
66
|
+
/** Finish only the visual close after the exit gap. */
|
|
67
|
+
onClose: () => void;
|
|
68
|
+
onDone?: never;
|
|
69
|
+
};
|
|
70
|
+
export declare function useAnchoredEditSession<P>(args: DeferredResolution<P> | AdmittedResolution<P>): {
|
|
71
|
+
open: boolean;
|
|
72
|
+
close: (reason: CloseReason) => void;
|
|
73
|
+
};
|
|
74
|
+
export {};
|