@viewkitjs/views 0.3.0 → 0.5.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 +641 -0
- package/README.md +3 -3
- package/dist/atoms/CommandMenu.d.ts +1 -1
- package/dist/atoms/CommandMenu.js +7 -3
- package/dist/atoms/DrillRows.d.ts +3 -0
- package/dist/atoms/DrillRows.js +25 -0
- package/dist/atoms/PanelRows.d.ts +5 -0
- package/dist/atoms/PanelRows.js +40 -0
- package/dist/atoms/PanelSearch.d.ts +2 -0
- package/dist/atoms/PanelSearch.js +21 -0
- package/dist/atoms/RelationRoles.d.ts +2 -0
- package/dist/atoms/RelationRoles.js +6 -0
- package/dist/atoms/Row.js +2 -1
- package/dist/atoms/RowMenu.js +2 -1
- package/dist/atoms/SelectionSheet.d.ts +3 -0
- package/dist/atoms/SelectionSheet.js +30 -0
- package/dist/atoms/StatusMarker.js +3 -1
- package/dist/atoms/Tag.js +2 -1
- package/dist/atoms/defaults.js +14 -0
- package/dist/atoms/types.d.ts +146 -8
- package/dist/cells/cell-values.js +4 -2
- package/dist/cells/relation-wrap.js +3 -1
- package/dist/contract.d.ts +212 -17
- package/dist/contract.js +208 -6
- package/dist/display/boolean.js +3 -1
- package/dist/display/date.d.ts +1 -1
- package/dist/display/date.js +4 -2
- package/dist/display/format.js +20 -4
- package/dist/display/link.js +4 -3
- package/dist/display/multi-value.js +2 -1
- package/dist/display/percent.js +2 -1
- package/dist/display/phone.js +2 -1
- package/dist/display/range.js +3 -13
- package/dist/display/relation.js +23 -8
- package/dist/display/rich-text.js +2 -1
- package/dist/editors/ChipsEditor.d.ts +5 -1
- package/dist/editors/ChipsEditor.js +15 -2
- package/dist/editors/DateEditor.d.ts +2 -0
- package/dist/editors/DateEditor.js +76 -10
- package/dist/editors/EditorPanel.d.ts +14 -4
- package/dist/editors/EditorPanel.js +21 -4
- package/dist/editors/LocationEditor.js +35 -3
- package/dist/editors/NumberEditor.js +3 -2
- package/dist/editors/RangeEditor.d.ts +8 -0
- package/dist/editors/RangeEditor.js +3 -2
- package/dist/editors/RelationEditor.d.ts +2 -0
- package/dist/editors/RelationEditor.js +16 -2
- package/dist/editors/RelationSetEditor.d.ts +4 -2
- package/dist/editors/RelationSetEditor.js +36 -2
- package/dist/editors/SelectEditor.d.ts +5 -2
- package/dist/editors/SelectEditor.js +31 -4
- package/dist/editors/TextEditor.js +3 -1
- package/dist/editors/ValueListEditor.d.ts +3 -0
- package/dist/editors/ValueListEditor.js +10 -4
- package/dist/editors/edit-session.d.ts +14 -2
- package/dist/editors/edit-session.js +13 -5
- package/dist/editors/escape-rule.d.ts +12 -0
- package/dist/editors/escape-rule.js +8 -0
- package/dist/editors/open-value.js +2 -1
- package/dist/editors/picker-slot.d.ts +25 -0
- package/dist/editors/picker-slot.js +37 -0
- package/dist/editors/relation-picker.d.ts +44 -0
- package/dist/editors/relation-picker.js +49 -0
- package/dist/editors/relation-source.d.ts +1 -0
- package/dist/editors/relation-source.js +7 -1
- package/dist/field-row/FieldNoteLine.js +2 -1
- package/dist/field-row/FieldRow.js +41 -6
- package/dist/field-row/FieldRowLane.js +3 -1
- package/dist/field-row/editors/RowChipsEditor.js +1 -1
- package/dist/field-row/editors/RowDateEditor.js +1 -1
- package/dist/field-row/editors/RowEditor.js +2 -1
- package/dist/field-row/editors/RowRangeEditor.js +2 -1
- package/dist/field-row/editors/RowRelationEditor.js +2 -2
- package/dist/field-row/editors/RowSelectEditor.d.ts +1 -1
- package/dist/field-row/editors/RowSelectEditor.js +2 -2
- package/dist/field-row/editors/RowValueListEditor.js +1 -1
- package/dist/field-row/editors/host.d.ts +3 -0
- package/dist/field-row/editors/row-session.js +4 -1
- package/dist/fields/menus.d.ts +2 -0
- package/dist/fields/range-unit.d.ts +7 -0
- package/dist/fields/range-unit.js +13 -0
- package/dist/figures.d.ts +5 -48
- package/dist/figures.js +1 -63
- package/dist/grid/chrome/GridAddColumn.d.ts +8 -0
- package/dist/grid/chrome/GridAddColumn.js +66 -9
- package/dist/grid/chrome/GridAggregateMenu.d.ts +5 -2
- package/dist/grid/chrome/GridAggregateMenu.js +33 -4
- package/dist/grid/chrome/GridCellEditors.d.ts +9 -2
- package/dist/grid/chrome/GridCellEditors.js +24 -5
- package/dist/grid/chrome/GridCellOutline.d.ts +3 -2
- package/dist/grid/chrome/GridCellOutline.js +11 -1
- package/dist/grid/chrome/GridChipsEditor.js +1 -1
- package/dist/grid/chrome/GridColumnColorSection.d.ts +2 -0
- package/dist/grid/chrome/GridColumnColorSection.js +2 -2
- package/dist/grid/chrome/GridColumnDateSection.d.ts +4 -0
- package/dist/grid/chrome/GridColumnDateSection.js +2 -2
- package/dist/grid/chrome/GridColumnDurationSection.d.ts +4 -0
- package/dist/grid/chrome/GridColumnDurationSection.js +2 -2
- package/dist/grid/chrome/GridColumnMenu.d.ts +10 -6
- package/dist/grid/chrome/GridColumnMenu.js +62 -24
- package/dist/grid/chrome/GridColumnNumberSection.d.ts +4 -0
- package/dist/grid/chrome/GridColumnNumberSection.js +2 -2
- package/dist/grid/chrome/GridColumnPercentSection.d.ts +1 -0
- package/dist/grid/chrome/GridColumnPercentSection.js +1 -1
- package/dist/grid/chrome/GridColumnSortSection.d.ts +3 -3
- package/dist/grid/chrome/GridDateEditor.js +1 -1
- package/dist/grid/chrome/GridFooter.js +7 -48
- package/dist/grid/chrome/GridGroupMenu.d.ts +11 -5
- package/dist/grid/chrome/GridGroupMenu.js +28 -13
- package/dist/grid/chrome/GridHeader.d.ts +3 -1
- package/dist/grid/chrome/GridHeader.js +8 -8
- package/dist/grid/chrome/GridNumberEditor.js +3 -24
- package/dist/grid/chrome/GridRangeEditor.js +3 -2
- package/dist/grid/chrome/GridRelationEditor.js +2 -2
- package/dist/grid/chrome/GridRow.d.ts +2 -1
- package/dist/grid/chrome/GridRow.js +13 -37
- package/dist/grid/chrome/GridRowActions.js +2 -1
- package/dist/grid/chrome/GridRowCells.js +9 -4
- package/dist/grid/chrome/GridSelectEditor.js +30 -20
- package/dist/grid/chrome/GridStructure.d.ts +11 -4
- package/dist/grid/chrome/GridStructure.js +19 -7
- package/dist/grid/chrome/GridTable.js +138 -16
- package/dist/grid/chrome/GridTableSurface.d.ts +25 -12
- package/dist/grid/chrome/GridTableSurface.js +13 -6
- package/dist/grid/chrome/GridTextEditor.js +3 -1
- package/dist/grid/chrome/GridValueListEditor.js +1 -1
- package/dist/grid/chrome/cell-clipboard.d.ts +1 -1
- package/dist/grid/chrome/cell-clipboard.js +1 -1
- package/dist/grid/chrome/checks.d.ts +10 -2
- package/dist/grid/chrome/checks.js +17 -11
- package/dist/grid/chrome/column-glyph.d.ts +2 -2
- package/dist/grid/chrome/column-glyph.js +4 -0
- package/dist/grid/chrome/grid-add-column-items.d.ts +13 -0
- package/dist/grid/chrome/grid-add-column-items.js +40 -0
- package/dist/grid/chrome/grid-cell-classes.d.ts +2 -0
- package/dist/grid/chrome/grid-cell-classes.js +10 -4
- package/dist/grid/chrome/grid-column-menu-items.d.ts +75 -0
- package/dist/grid/chrome/grid-column-menu-items.js +263 -0
- package/dist/grid/chrome/grid-edit-escape.d.ts +4 -0
- package/dist/grid/chrome/grid-edit-escape.js +12 -0
- package/dist/grid/chrome/grid-edit-session.d.ts +2 -1
- package/dist/grid/chrome/grid-edit-session.js +14 -1
- package/dist/grid/chrome/grid-figure-value.d.ts +25 -0
- package/dist/grid/chrome/grid-figure-value.js +40 -0
- package/dist/grid/chrome/grid-fitted-box.d.ts +15 -0
- package/dist/grid/chrome/grid-fitted-box.js +26 -0
- package/dist/grid/chrome/grid-group-menu-items.d.ts +31 -0
- package/dist/grid/chrome/grid-group-menu-items.js +75 -0
- package/dist/grid/chrome/grid-group-menu-parts.d.ts +27 -0
- package/dist/grid/chrome/grid-group-menu-parts.js +19 -0
- package/dist/grid/chrome/grid-hover.d.ts +1 -0
- package/dist/grid/chrome/grid-hover.js +13 -1
- package/dist/grid/chrome/grid-lab.d.ts +7 -0
- package/dist/grid/chrome/grid-lab.js +7 -0
- package/dist/grid/chrome/grid-menu-focus.d.ts +12 -0
- package/dist/grid/chrome/grid-menu-focus.js +13 -0
- package/dist/grid/chrome/{useGridRowContextMenu.d.ts → grid-row-menu-items.d.ts} +15 -4
- package/dist/grid/chrome/{useGridRowContextMenu.js → grid-row-menu-items.js} +15 -18
- package/dist/grid/chrome/grid-row-props.d.ts +3 -1
- package/dist/grid/chrome/grid-row-window.d.ts +15 -5
- package/dist/grid/chrome/grid-row-window.js +44 -10
- package/dist/grid/chrome/grid-rows-menu.d.ts +38 -0
- package/dist/grid/chrome/grid-rows-menu.js +83 -0
- package/dist/grid/chrome/grid-table-props.d.ts +53 -8
- package/dist/grid/chrome/useGridBandFigures.d.ts +26 -0
- package/dist/grid/chrome/useGridBandFigures.js +50 -0
- package/dist/grid/chrome/useGridBoxes.d.ts +22 -0
- package/dist/grid/chrome/useGridBoxes.js +22 -0
- package/dist/grid/chrome/useGridColumnLayout.js +29 -4
- package/dist/grid/chrome/useGridKeyboard.js +7 -2
- package/dist/grid/chrome/useGridPartColumns.d.ts +5 -0
- package/dist/grid/chrome/useGridPartColumns.js +9 -0
- package/dist/grid/chrome/useGridRangeGestures.js +2 -1
- package/dist/grid/chrome/useGridRecorder.d.ts +16 -0
- package/dist/grid/chrome/useGridRecorder.js +144 -0
- package/dist/grid/chrome/useGridRowOpener.d.ts +41 -0
- package/dist/grid/chrome/useGridRowOpener.js +83 -0
- package/dist/grid/chrome/useGridScrollArea.d.ts +38 -12
- package/dist/grid/chrome/useGridScrollArea.js +70 -17
- package/dist/grid/chrome/useGridTableInteractionModel.d.ts +1 -0
- package/dist/grid/chrome/useGridTableInteractionModel.js +67 -9
- package/dist/grid/core/clipboard-model.d.ts +11 -3
- package/dist/grid/core/clipboard-model.js +9 -4
- package/dist/grid/core/commit-model.d.ts +7 -0
- package/dist/grid/core/editing-controller.d.ts +31 -1
- package/dist/grid/core/editing-controller.js +65 -0
- package/dist/grid/core/grid-recorder.d.ts +111 -0
- package/dist/grid/core/grid-recorder.js +223 -0
- package/dist/grid/core/part-edits.d.ts +18 -0
- package/dist/grid/core/part-edits.js +48 -0
- package/dist/grid/core/pending-reconciliation.js +12 -3
- package/dist/grid/core/refusal-sentence.d.ts +3 -0
- package/dist/grid/core/refusal-sentence.js +15 -0
- package/dist/grid/core/row-opened-from.d.ts +21 -0
- package/dist/grid/core/row-opened-from.js +11 -0
- package/dist/grid/core/useGridEditing.d.ts +16 -2
- package/dist/grid/core/useGridEditing.js +10 -4
- package/dist/grid/core/value-equality.d.ts +19 -1
- package/dist/grid/core/value-equality.js +24 -0
- package/dist/grid/index.d.ts +4 -1
- package/dist/grid/index.js +1 -0
- package/dist/grid/useGridTablePrefs.d.ts +1 -1
- package/dist/grid-lab.d.ts +18 -0
- package/dist/grid-lab.js +16 -0
- package/dist/grouping/sort-groups.d.ts +6 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/internal/reset.d.ts +9 -0
- package/dist/internal/reset.js +1 -0
- package/dist/model/aggregates.d.ts +3 -3
- package/dist/model/aggregates.js +17 -71
- package/dist/model/column-capabilities.d.ts +29 -2
- package/dist/model/column-capabilities.js +27 -3
- package/dist/model/column-filters.js +24 -4
- package/dist/model/column-inspect.d.ts +2 -1
- package/dist/model/column-order.d.ts +2 -2
- package/dist/model/column-schema.d.ts +18 -7
- package/dist/model/column-state.d.ts +9 -20
- package/dist/model/column-state.js +1 -4
- package/dist/model/column-types.d.ts +1 -15
- package/dist/model/column-types.js +1 -1
- package/dist/model/part-columns.d.ts +17 -0
- package/dist/model/part-columns.js +67 -0
- package/dist/model/part-rows.d.ts +3 -10
- package/dist/model/part-rows.js +6 -11
- package/dist/model/part-write.d.ts +11 -0
- package/dist/model/part-write.js +52 -0
- package/dist/model/preferences.d.ts +3 -23
- package/dist/model/preferences.js +1 -17
- package/dist/model/prefs-buckets.d.ts +0 -27
- package/dist/model/prefs-buckets.js +1 -1
- package/dist/model/relation-filters.d.ts +0 -1
- package/dist/model/relation-filters.js +1 -1
- package/dist/model/row-icon.d.ts +5 -9
- package/dist/model/view-rules.d.ts +32 -6
- package/dist/model/view-rules.js +101 -21
- package/dist/provider/ViewsProvider.d.ts +22 -2
- package/dist/provider/ViewsProvider.js +21 -2
- package/dist/provider/components.d.ts +197 -9
- package/dist/provider/context.d.ts +12 -1
- package/dist/provider/desktop.d.ts +3 -0
- package/dist/provider/desktop.js +7 -4
- package/dist/provider/menu-groups.d.ts +3 -2
- package/dist/provider/menu-groups.js +13 -7
- package/dist/provider/missing-slot.d.ts +10 -0
- package/dist/provider/missing-slot.js +15 -0
- package/dist/provider/plain-input.d.ts +3 -2
- package/dist/provider/plain-input.js +3 -1
- package/dist/react.d.ts +3 -2
- package/dist/selection/SelectionBar.d.ts +18 -0
- package/dist/selection/SelectionBar.js +92 -0
- package/dist/selection/SelectionBarPhone.d.ts +3 -0
- package/dist/selection/SelectionBarPhone.js +14 -0
- package/dist/selection/bar-overflow.d.ts +12 -0
- package/dist/selection/bar-overflow.js +42 -0
- package/dist/selection/bar-parts.d.ts +15 -0
- package/dist/selection/bar-parts.js +17 -0
- package/dist/selection/index.d.ts +2 -0
- package/dist/selection/index.js +1 -0
- package/dist/selection/types.d.ts +3 -2
- package/dist/selection/verbs.d.ts +34 -0
- package/dist/selection/verbs.js +1 -0
- package/docs/contract.md +142 -39
- package/docs/getting-started.md +1 -1
- package/docs/guides/atoms.md +32 -4
- package/docs/guides/columns.md +1 -1
- package/docs/guides/display.md +1 -1
- package/docs/guides/editors.md +3 -3
- package/docs/guides/ports.md +1 -1
- package/docs/guides/selection.md +32 -20
- package/docs/guides/the-grid.md +43 -21
- package/docs/guides/the-provider.md +14 -4
- package/docs/index.md +2 -0
- package/docs/install.md +8 -1
- package/docs/reference/editors-date.md +2 -0
- package/docs/reference/editors-panel.md +4 -4
- package/docs/reference/editors-range.md +1 -1
- package/docs/reference/editors-relation.md +3 -3
- package/docs/reference/editors-select.md +1 -1
- package/docs/reference/editors-session.md +3 -2
- package/docs/reference/editors-value-list.md +1 -1
- package/docs/reference/field-row.md +2 -2
- package/docs/reference/grid.md +25 -6
- package/docs/reference/react.md +30 -8
- package/docs/reference/selection.md +10 -2
- package/docs/reference/views.md +42 -36
- package/package.json +22 -3
- package/skills/views/SKILL.md +3 -3
|
@@ -3,6 +3,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { phoneHref } from "@viewkitjs/fields";
|
|
4
4
|
import { webHref } from "../display/web-href.js";
|
|
5
5
|
import { cx } from "../internal/cx.js";
|
|
6
|
+
import { ELEMENT_RESET } from "../internal/reset.js";
|
|
6
7
|
import { useViews } from "../provider/context.js";
|
|
7
8
|
const OPENABLE = new Set(["email", "phone", "url", "domain"]);
|
|
8
9
|
export function isOpenableType(type) {
|
|
@@ -32,5 +33,5 @@ export function OpenValueAction({ type, value, label, compact = false, }) {
|
|
|
32
33
|
: type === "phone"
|
|
33
34
|
? { key: "views.editors.open-phone", values: { value: label } }
|
|
34
35
|
: { key: "views.editors.open-link", values: { value: label } });
|
|
35
|
-
return (_jsx("a", { href: href, ...(web ? { target: "_blank", rel: "noopener noreferrer" } : {}), "aria-label": name, title: name, "data-no-nav": true, onClick: (event) => event.stopPropagation(), className: cx("flex 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)", compact ? "-my-1 size-7" : "size-8"), children: _jsx(Icon, { className: "size-4" }) }));
|
|
36
|
+
return (_jsx("a", { href: href, ...(web ? { target: "_blank", rel: "noopener noreferrer" } : {}), "aria-label": name, title: name, "data-no-nav": true, onClick: (event) => event.stopPropagation(), className: cx(ELEMENT_RESET, "flex 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)", compact ? "-my-1 size-7" : "size-8"), children: _jsx(Icon, { className: "size-4" }) }));
|
|
36
37
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type KeyboardEvent, type ReactNode } from "react";
|
|
2
|
+
import type { ViewsPickerItem } from "../provider/components.js";
|
|
3
|
+
/**
|
|
4
|
+
* What every pick editor shares when the app hands its own `Picker`: the form it opens in, its rows as
|
|
5
|
+
* data, the rule that turns typed text into a value, and the frame that keeps Tab the editor's. The
|
|
6
|
+
* package's own; no entry point exports it.
|
|
7
|
+
*/
|
|
8
|
+
/** The computer's form or the phone's, read once as the editor opens, as the panel chooses its surface
|
|
9
|
+
* once. Never subscribed, so an editor that draws its own list adds no listener. */
|
|
10
|
+
export declare function usePickerForm(): "computer" | "phone";
|
|
11
|
+
/** One of the editor's options as a row of the app's body: what is set, and nothing more. */
|
|
12
|
+
export declare function pickerItemOf(option: Pick<ViewsPickerItem, "value" | "label" | "slot" | "color" | "icon">): ViewsPickerItem;
|
|
13
|
+
/** The value typed text makes: a known value it names in any case ("retail" picks `Retail`), else the
|
|
14
|
+
* trimmed text; blank text makes `fallback`. */
|
|
15
|
+
export declare function typedPick(typed: string, known: readonly string[], fallback: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* The box around the app's body. Tab and Shift-Tab are the editor's, taken in the capture phase before
|
|
18
|
+
* the body hears them (a body that loops focus would keep them); every other key goes to `onKey` first,
|
|
19
|
+
* for the editor's own Escape rule, then on to the body.
|
|
20
|
+
*/
|
|
21
|
+
export declare function PickerFrame({ onTab, onKey, children, }: {
|
|
22
|
+
onTab: (reason: "tab" | "shift-tab") => void;
|
|
23
|
+
onKey?: (event: KeyboardEvent<HTMLDivElement>) => void;
|
|
24
|
+
children: ReactNode;
|
|
25
|
+
}): ReactNode;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { useViews } from "../provider/context.js";
|
|
5
|
+
import { isDesktopNow } from "../provider/desktop.js";
|
|
6
|
+
export function usePickerForm() {
|
|
7
|
+
const { desktopQuery } = useViews();
|
|
8
|
+
const [form] = useState(() => (isDesktopNow(desktopQuery) ? "computer" : "phone"));
|
|
9
|
+
return form;
|
|
10
|
+
}
|
|
11
|
+
export function pickerItemOf(option) {
|
|
12
|
+
return {
|
|
13
|
+
value: option.value,
|
|
14
|
+
label: option.label,
|
|
15
|
+
...(option.slot !== undefined ? { slot: option.slot } : {}),
|
|
16
|
+
...(option.color !== undefined ? { color: option.color } : {}),
|
|
17
|
+
...(option.icon !== undefined ? { icon: option.icon } : {}),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function typedPick(typed, known, fallback) {
|
|
21
|
+
const text = typed.trim();
|
|
22
|
+
if (text === "")
|
|
23
|
+
return fallback;
|
|
24
|
+
const needle = text.toLowerCase();
|
|
25
|
+
return known.find((value) => value.toLowerCase() === needle) ?? text;
|
|
26
|
+
}
|
|
27
|
+
export function PickerFrame({ onTab, onKey, children, }) {
|
|
28
|
+
return (_jsx("div", { className: "contents", onKeyDownCapture: (event) => {
|
|
29
|
+
if (event.key === "Tab" && !event.altKey && !event.ctrlKey && !event.metaKey) {
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
event.stopPropagation();
|
|
32
|
+
onTab(event.shiftKey ? "shift-tab" : "tab");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
onKey?.(event);
|
|
36
|
+
}, children: children }));
|
|
37
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from "react";
|
|
2
|
+
import type { ViewsPickerProps } from "../provider/components.js";
|
|
3
|
+
import type { RelationCreate } from "./relation-panel.js";
|
|
4
|
+
import { type RelationCandidate, type RelationSource } from "./relation-source.js";
|
|
5
|
+
/** A held record as the body shows it: from its candidate where the page has it, else from its link. */
|
|
6
|
+
export type RelationHeld = {
|
|
7
|
+
id: string;
|
|
8
|
+
label: string;
|
|
9
|
+
icon?: ReactNode;
|
|
10
|
+
kind?: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A RELATION'S LIST THROUGH THE APP'S OWN PICKER — what stands where `RelationPanel` stands when the app hands
|
|
14
|
+
* a `Picker`. ViewKit still filters a static source (by label, as its own list does) and fetches a remote one
|
|
15
|
+
* (`useRemotePage`: the debounce, the abort, the paging), so the body draws the rows it is handed and reports
|
|
16
|
+
* each typed query back. Held records come first, by the same search rule; the host's create rows become the
|
|
17
|
+
* body's actions. What a pick means is the core's: this hands it ids it handed out, nothing else.
|
|
18
|
+
*/
|
|
19
|
+
export declare function RelationPickerBody({ Picker, label, candidates, query, onQueryChange, held, multiple, value, onValueChange, onDone, empty, creates, onCreate, kindGlyph, lead, onTab, typed, autoFocus, search, }: {
|
|
20
|
+
Picker: ComponentType<ViewsPickerProps>;
|
|
21
|
+
label: string;
|
|
22
|
+
candidates: RelationSource;
|
|
23
|
+
query: string;
|
|
24
|
+
onQueryChange: (query: string) => void;
|
|
25
|
+
/** Held records, listed first while they match the query. */
|
|
26
|
+
held: readonly RelationHeld[];
|
|
27
|
+
multiple: boolean;
|
|
28
|
+
value: string | string[] | null;
|
|
29
|
+
/** What the body handed back, with every id it was never handed dropped (one: not passed on at all; null
|
|
30
|
+
* passes only with `empty` set). `found` gives a handed id's candidate, for a core building a new record. */
|
|
31
|
+
onValueChange: (value: string | string[] | null, found: (id: string) => RelationCandidate | undefined) => void;
|
|
32
|
+
onDone: () => void;
|
|
33
|
+
empty?: string;
|
|
34
|
+
creates?: RelationCreate[];
|
|
35
|
+
/** A create row was picked, with the trimmed query: the core asks to close, then runs it. */
|
|
36
|
+
onCreate: (create: RelationCreate, query: string) => void;
|
|
37
|
+
kindGlyph?: ReactNode;
|
|
38
|
+
lead?: ViewsPickerProps["lead"];
|
|
39
|
+
onTab: (reason: "tab" | "shift-tab") => void;
|
|
40
|
+
typed?: string;
|
|
41
|
+
autoFocus: boolean;
|
|
42
|
+
/** The search's words: the host's messages where it handed some. */
|
|
43
|
+
search: string;
|
|
44
|
+
}): ReactNode;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useViews } from "../provider/context.js";
|
|
4
|
+
import { PickerFrame, usePickerForm } from "./picker-slot.js";
|
|
5
|
+
import { useRemotePage } from "./relation-source.js";
|
|
6
|
+
const matches = (label, query) => label.toLowerCase().includes(query.trim().toLowerCase());
|
|
7
|
+
export function RelationPickerBody({ Picker, label, candidates, query, onQueryChange, held, multiple, value, onValueChange, onDone, empty, creates, onCreate, kindGlyph, lead, onTab, typed, autoFocus, search, }) {
|
|
8
|
+
const views = useViews();
|
|
9
|
+
const Add = views.icons.add;
|
|
10
|
+
const form = usePickerForm();
|
|
11
|
+
const remote = candidates.kind === "remote";
|
|
12
|
+
const page = useRemotePage(candidates, query);
|
|
13
|
+
const rows = candidates.kind === "static" ? candidates.items.filter((candidate) => matches(candidate.label, query)) : page.items;
|
|
14
|
+
const heldIds = new Set(held.map((record) => record.id));
|
|
15
|
+
const shownHeld = held.filter((record) => matches(record.label, query));
|
|
16
|
+
const byId = new Map();
|
|
17
|
+
for (const candidate of candidates.kind === "static" ? candidates.items : page.items)
|
|
18
|
+
byId.set(candidate.id, candidate);
|
|
19
|
+
const itemOf = (record) => {
|
|
20
|
+
const full = byId.get(record.id) ?? record;
|
|
21
|
+
const glyph = full.icon ?? kindGlyph;
|
|
22
|
+
return {
|
|
23
|
+
value: full.id,
|
|
24
|
+
label: full.label,
|
|
25
|
+
...(full.sublabel !== undefined ? { line: full.sublabel } : {}),
|
|
26
|
+
...(full.badge !== undefined ? { badge: full.badge } : {}),
|
|
27
|
+
...(glyph != null ? { glyph } : {}),
|
|
28
|
+
...(full.avatarUrl !== undefined ? { avatarUrl: full.avatarUrl } : {}),
|
|
29
|
+
...(full.kind !== undefined ? { kind: full.kind } : {}),
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const items = [...shownHeld.map(itemOf), ...rows.filter((candidate) => !heldIds.has(candidate.id)).map(itemOf)];
|
|
33
|
+
const handed = new Set([...items.map((item) => item.value), ...heldIds]);
|
|
34
|
+
const found = (id) => byId.get(id);
|
|
35
|
+
const take = (next) => {
|
|
36
|
+
if (Array.isArray(next))
|
|
37
|
+
return onValueChange([...new Set(next)].filter((id) => handed.has(id)), found);
|
|
38
|
+
if (next === null ? empty !== undefined : handed.has(next))
|
|
39
|
+
onValueChange(next, found);
|
|
40
|
+
};
|
|
41
|
+
const trimmed = query.trim();
|
|
42
|
+
const actions = creates?.map((create, index) => ({
|
|
43
|
+
key: `create-${index}`,
|
|
44
|
+
label: create.label(trimmed),
|
|
45
|
+
icon: _jsx(Add, { className: "size-3.5" }),
|
|
46
|
+
onSelect: () => onCreate(create, trimmed),
|
|
47
|
+
}));
|
|
48
|
+
return (_jsx(PickerFrame, { onTab: onTab, children: _jsx(Picker, { label: label, items: items, multiple: multiple, value: value, onValueChange: take, onDone: onDone, empty: empty, search: search, onSearch: onQueryChange, doing: !remote ? undefined : page.searching ? "searching" : page.failed && page.items.length === 0 ? "failed" : undefined, onRetry: remote && page.failed && page.items.length === 0 ? page.retry : undefined, onMore: remote && !page.exhausted && page.items.length > 0 ? page.loadMore : undefined, actions: actions, lead: lead, typed: typed, autoFocus: autoFocus, form: form }) }));
|
|
49
|
+
}
|
|
@@ -78,7 +78,13 @@ export function useRemotePage(source, query) {
|
|
|
78
78
|
return;
|
|
79
79
|
run(queryRef.current, current.offset);
|
|
80
80
|
}, [remote, run]);
|
|
81
|
-
|
|
81
|
+
const retry = useCallback(() => {
|
|
82
|
+
if (!remote)
|
|
83
|
+
return;
|
|
84
|
+
abortRef.current?.abort();
|
|
85
|
+
run(queryRef.current, 0);
|
|
86
|
+
}, [remote, run]);
|
|
87
|
+
return { ...page, loadMore, retry };
|
|
82
88
|
}
|
|
83
89
|
export function EndOfListSentinel({ onReveal }) {
|
|
84
90
|
const ref = useRef(null);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
import { cx } from "../internal/cx.js";
|
|
5
|
+
import { ELEMENT_RESET } from "../internal/reset.js";
|
|
5
6
|
import { useViews } from "../provider/context.js";
|
|
6
7
|
const NOTE_CLASS = "mt-0.5 text-xs leading-5 text-(color:--vk-fg-subtle) wrap-break-word";
|
|
7
8
|
export function FieldNoteLine({ note }) {
|
|
@@ -10,5 +11,5 @@ export function FieldNoteLine({ note }) {
|
|
|
10
11
|
if (!note.quote) {
|
|
11
12
|
return (_jsx("p", { "data-field-note": true, className: NOTE_CLASS, children: note.text }));
|
|
12
13
|
}
|
|
13
|
-
return (_jsxs("div", { children: [_jsx("button", { type: "button", "data-field-note": true, "aria-expanded": open, onClick: () => setOpen((value) => !value), className: cx(NOTE_CLASS, "block text-left underline decoration-dotted underline-offset-2 transition-colors hover:text-(color:--vk-fg)"), children: note.text }), _jsx(Collapse, { open: open, children: _jsxs("p", { className: "mt-1 border-l-2 border-(color:--vk-border) pl-2 text-xs leading-5 text-(color:--vk-fg-subtle) italic wrap-break-word", children: ["\u201C", note.quote, "\u201D"] }) })] }));
|
|
14
|
+
return (_jsxs("div", { children: [_jsx("button", { type: "button", "data-field-note": true, "aria-expanded": open, onClick: () => setOpen((value) => !value), className: cx(ELEMENT_RESET, NOTE_CLASS, "block text-left underline decoration-dotted underline-offset-2 transition-colors hover:text-(color:--vk-fg)"), children: note.text }), _jsx(Collapse, { open: open, children: _jsxs("p", { className: "mt-1 border-l-2 border-(color:--vk-border) pl-2 text-xs leading-5 text-(color:--vk-fg-subtle) italic wrap-break-word", children: ["\u201C", note.quote, "\u201D"] }) })] }));
|
|
14
15
|
}
|
|
@@ -5,6 +5,7 @@ import { optimisticDisplay, phoneText, presentedDef, resolveFieldMessage, } from
|
|
|
5
5
|
import { ConvertedFigure } from "../display/converted.js";
|
|
6
6
|
import { renderFieldValue } from "../display/display-cores.js";
|
|
7
7
|
import { cx } from "../internal/cx.js";
|
|
8
|
+
import { ELEMENT_RESET } from "../internal/reset.js";
|
|
8
9
|
import { useViews } from "../provider/context.js";
|
|
9
10
|
import { RowEditor } from "./editors/RowEditor.js";
|
|
10
11
|
import { FieldNoteLine } from "./FieldNoteLine.js";
|
|
@@ -13,12 +14,14 @@ import { FieldWriteReconciliationRequired, } from "../fields/write-target.js";
|
|
|
13
14
|
import { OpenValueAction, isOpenableType } from "../editors/open-value.js";
|
|
14
15
|
import { FIELD_ROW_TARGET as TARGET, FIELD_ROW_TARGET_BESIDE as TARGET_BESIDE, FIELD_ROW_TARGET_UNDER as TARGET_UNDER, } from "./row-target.js";
|
|
15
16
|
import { settlementAttributes, useRowSettlement } from "./useRowSettlement.js";
|
|
17
|
+
const EDITOR_PANEL = '[data-slot="vk-editor-panel"]';
|
|
16
18
|
function FieldRowImpl({ binding, row, value, editValue, writable, ready = true, unread = false, refusal, onCommit, opts, menu, meta, note, kindIcon, }) {
|
|
17
19
|
const { field } = binding;
|
|
18
20
|
const { atoms, components, conventions, icons } = useViews();
|
|
19
21
|
const { CommandMenu } = atoms;
|
|
20
22
|
const { AppIcon } = components;
|
|
21
23
|
const [editing, setEditing] = useState(false);
|
|
24
|
+
const [byKey, setByKey] = useState(false);
|
|
22
25
|
const [pending, setPending] = useState(null);
|
|
23
26
|
const [error, setError] = useState(null);
|
|
24
27
|
const [retryDraft, setRetryDraft] = useState(null);
|
|
@@ -26,8 +29,13 @@ function FieldRowImpl({ binding, row, value, editValue, writable, ready = true,
|
|
|
26
29
|
const message = opts?.presentation?.message ?? resolveFieldMessage;
|
|
27
30
|
const buttonRef = useRef(null);
|
|
28
31
|
const focusBack = useRef(null);
|
|
32
|
+
const leaving = useRef(null);
|
|
29
33
|
const closed = (after) => {
|
|
30
|
-
focusBack.current = after.focusBack ? {} : null;
|
|
34
|
+
focusBack.current = after.focusBack && !leaving.current?.gone ? {} : null;
|
|
35
|
+
if (!focusBack.current) {
|
|
36
|
+
leaving.current?.stop();
|
|
37
|
+
leaving.current = null;
|
|
38
|
+
}
|
|
31
39
|
setEditing(false);
|
|
32
40
|
};
|
|
33
41
|
useEffect(() => {
|
|
@@ -45,13 +53,34 @@ function FieldRowImpl({ binding, row, value, editValue, writable, ready = true,
|
|
|
45
53
|
return;
|
|
46
54
|
}
|
|
47
55
|
focusBack.current = null;
|
|
56
|
+
const gone = leaving.current?.gone ?? false;
|
|
57
|
+
leaving.current?.stop();
|
|
58
|
+
leaving.current = null;
|
|
48
59
|
const active = document.activeElement;
|
|
49
60
|
const moved = "left" in armed && active !== armed.left && active !== null && active !== document.body;
|
|
50
|
-
if (!moved)
|
|
61
|
+
if (!moved && !gone)
|
|
51
62
|
button.focus({ preventScroll: true });
|
|
52
63
|
}, [editing, pending, ready]);
|
|
64
|
+
useEffect(() => () => leaving.current?.stop(), []);
|
|
53
65
|
const shown = pending && "optimistic" in pending ? pending.optimistic : value;
|
|
54
66
|
const isEmpty = shown == null || shown === "" || (Array.isArray(shown) && shown.length === 0);
|
|
67
|
+
const watchLeaving = () => {
|
|
68
|
+
leaving.current?.stop();
|
|
69
|
+
const watch = { gone: false, stop: () => { } };
|
|
70
|
+
const letGo = (event) => {
|
|
71
|
+
if (event.target instanceof Element && event.target.closest(EDITOR_PANEL))
|
|
72
|
+
return;
|
|
73
|
+
watch.gone = true;
|
|
74
|
+
watch.stop();
|
|
75
|
+
};
|
|
76
|
+
watch.stop = () => {
|
|
77
|
+
document.removeEventListener("pointerdown", letGo, true);
|
|
78
|
+
document.removeEventListener("focusin", letGo, true);
|
|
79
|
+
};
|
|
80
|
+
document.addEventListener("pointerdown", letGo, true);
|
|
81
|
+
document.addEventListener("focusin", letGo, true);
|
|
82
|
+
leaving.current = watch;
|
|
83
|
+
};
|
|
55
84
|
const attempt = (resolution) => {
|
|
56
85
|
if (resolution.kind !== "commit")
|
|
57
86
|
return { accepted: true };
|
|
@@ -143,15 +172,21 @@ function FieldRowImpl({ binding, row, value, editValue, writable, ready = true,
|
|
|
143
172
|
},
|
|
144
173
|
}));
|
|
145
174
|
const valueNode = (_jsxs("span", { className: "flex min-w-0 flex-1 items-center gap-2", children: [_jsx("span", { className: "min-w-0 wrap-break-word", children: body }), meta ? _jsx("span", { className: "shrink-0 text-xs text-(color:--vk-fg-subtle)", children: meta }) : null] }));
|
|
146
|
-
const editButton = (className, children) => (_jsx("button", { ref: buttonRef, type: "button", "aria-label": field.label, disabled: !ready
|
|
175
|
+
const editButton = (className, children) => (_jsx("button", { ref: buttonRef, type: "button", "aria-label": field.label, disabled: !ready, "aria-disabled": pending ? true : undefined, onClick: (event) => {
|
|
176
|
+
if (pending)
|
|
177
|
+
return;
|
|
147
178
|
setError(null);
|
|
179
|
+
setByKey(event.detail === 0);
|
|
148
180
|
setEditing(true);
|
|
149
|
-
}, className: className, children: children }));
|
|
150
|
-
return (_jsxs("div", { className: "flex items-start gap-3 border-b border-(color:--vk-border) py-2.5 last:border-0", "aria-busy": pending ? "true" : undefined, children: [_jsx("span", { className: "flex h-5 w-3.5 shrink-0 items-center justify-center", children: glyph }), _jsx("span", { className: "w-32 shrink-0 text-sm leading-5 text-(color:--vk-fg-subtle)", children: field.label }), _jsxs("div", { className: cx("min-w-0 flex-1 text-sm leading-5 text-(color:--vk-fg)", settlement.requested && "italic opacity-80"), ...settlementAttributes(settlement.requested, field.provenance, conventions), children: [editing ? (_jsx("div", { children: _jsx(RowEditor, { binding: binding, row: row, initial: retryDraft ? retryDraft.commit : editValue, shown: shown, conversion: convertedFrom ? body : undefined, anchor: _jsx("span", { className: cx(TARGET, "bg-(color:--vk-neutral)"), children: valueNode }), onAttempt:
|
|
181
|
+
}, className: cx(ELEMENT_RESET, className, "aria-disabled:pointer-events-none"), children: children }));
|
|
182
|
+
return (_jsxs("div", { className: "flex items-start gap-3 border-b border-(color:--vk-border) py-2.5 last:border-0", "aria-busy": pending ? "true" : undefined, children: [_jsx("span", { className: "flex h-5 w-3.5 shrink-0 items-center justify-center", children: glyph }), _jsx("span", { className: "w-32 shrink-0 text-sm leading-5 text-(color:--vk-fg-subtle)", children: field.label }), _jsxs("div", { className: cx("min-w-0 flex-1 text-sm leading-5 text-(color:--vk-fg)", settlement.requested && "italic opacity-80"), ...settlementAttributes(settlement.requested, field.provenance, conventions), children: [editing ? (_jsx("div", { children: _jsx(RowEditor, { binding: binding, row: row, initial: retryDraft ? retryDraft.commit : editValue, shown: shown, conversion: convertedFrom ? body : undefined, anchor: _jsx("span", { className: cx(TARGET, "bg-(color:--vk-neutral)"), children: valueNode }), onAttempt: (resolution) => {
|
|
183
|
+
watchLeaving();
|
|
184
|
+
return attempt(resolution);
|
|
185
|
+
}, onClose: closed, message: message, kindIcon: kindIcon, openedByKey: byKey }) })) : hasMenu && !verbsInLane ? (_jsx(CommandMenu, { trigger: _jsx("button", { type: "button", "aria-label": field.label, className: cx(ELEMENT_RESET, TARGET), disabled: !ready, children: valueNode }), items: menuItems, align: "start" })) : writable && shownDef.type !== "boolean" ? (valueOverButton ? (_jsxs("div", { className: "relative min-w-0", children: [editButton(cx(TARGET_UNDER, "disabled:pointer-events-none")), _jsx("span", { "data-slot": "vk-row-value-layer", className: cx("pointer-events-none relative block min-w-0 [&_a]:pointer-events-auto [&_button]:pointer-events-auto", pending && "opacity-70"), children: valueNode })] })) : openType ? (_jsxs("div", { className: "flex min-w-0 items-center gap-1", children: [editButton(cx(TARGET_BESIDE, "disabled:pointer-events-none", pending && "opacity-70"), valueNode), _jsx(OpenValueAction, { type: openType, value: openValue, label: openLabel, compact: true })] })) : (editButton(cx(TARGET, "disabled:pointer-events-none", pending && "opacity-70"), valueNode))) : (_jsx("span", { className: "block min-w-0", children: valueNode })), !editing && note ? (_jsx(FieldNoteLine, { note: typeof note === "string" ? { text: note } : note })) : null, !editing && error && retryDraft ? (_jsx("div", { role: "alert", className: "mt-1 text-xs text-(color:--vk-danger)", children: _jsx("button", { type: "button", onClick: () => {
|
|
151
186
|
setError(null);
|
|
152
187
|
const retried = attempt({ kind: "commit", payload: retryDraft.commit });
|
|
153
188
|
if (!retried.accepted)
|
|
154
189
|
setError(retried.reason);
|
|
155
|
-
}, className: "hover:underline", children: error }) })) : null] }), _jsx(FieldRowLane, { label: field.label, verbsInLane: verbsInLane, hasMenu: hasMenu, items: menuItems, ready: ready, writable: writable, refusal: refusal })] }));
|
|
190
|
+
}, className: cx(ELEMENT_RESET, "hover:underline"), children: error }) })) : null] }), _jsx(FieldRowLane, { label: field.label, verbsInLane: verbsInLane, hasMenu: hasMenu, items: menuItems, ready: ready, writable: writable, refusal: refusal })] }));
|
|
156
191
|
}
|
|
157
192
|
export const FieldRow = memo(FieldRowImpl);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { cx } from "../internal/cx.js";
|
|
4
|
+
import { ELEMENT_RESET } from "../internal/reset.js";
|
|
3
5
|
import { useViews } from "../provider/context.js";
|
|
4
6
|
export function FieldRowLane({ label, verbsInLane, hasMenu, items, ready, writable, refusal, }) {
|
|
5
7
|
const { atoms, icons } = useViews();
|
|
@@ -7,5 +9,5 @@ export function FieldRowLane({ label, verbsInLane, hasMenu, items, ready, writab
|
|
|
7
9
|
const Chevron = icons.chevronDown;
|
|
8
10
|
const More = icons.more;
|
|
9
11
|
const Lock = icons.lock;
|
|
10
|
-
return (_jsx("span", { className: "flex h-5 w-3 shrink-0 items-center justify-center", children: verbsInLane ? (_jsx(CommandMenu, { trigger: _jsx("button", { type: "button", "aria-label": label, className: "group -m-1 p-1", disabled: !ready, children: _jsx(Chevron, { className: "h-3 w-3 text-(color:--vk-fg-subtlest) transition-colors group-hover:text-(color:--vk-fg-subtle)" }) }), items: items, align: "end" })) : hasMenu ? (_jsx(More, { className: "h-3 w-3 text-(color:--vk-fg-subtlest)" })) : !writable && refusal ? (_jsx("span", { title: refusal, className: "leading-none", children: _jsx(Lock, { className: "h-3 w-3 text-(color:--vk-fg-subtlest)" }) })) : null }));
|
|
12
|
+
return (_jsx("span", { className: "flex h-5 w-3 shrink-0 items-center justify-center", children: verbsInLane ? (_jsx(CommandMenu, { trigger: _jsx("button", { type: "button", "aria-label": label, className: cx(ELEMENT_RESET, "group -m-1 p-1"), disabled: !ready, children: _jsx(Chevron, { className: "h-3 w-3 text-(color:--vk-fg-subtlest) transition-colors group-hover:text-(color:--vk-fg-subtle)" }) }), items: items, align: "end", label: label })) : hasMenu ? (_jsx(More, { className: "h-3 w-3 text-(color:--vk-fg-subtlest)" })) : !writable && refusal ? (_jsx("span", { title: refusal, className: "leading-none", children: _jsx(Lock, { className: "h-3 w-3 text-(color:--vk-fg-subtlest)" }) })) : null }));
|
|
11
13
|
}
|
|
@@ -21,5 +21,5 @@ export function RowChipsEditor({ field, initial, anchor, onAttempt, onClose, mes
|
|
|
21
21
|
label: optionFor(field, value)?.label ?? value,
|
|
22
22
|
color: resolveCategoryColor(value, field.options, undefined),
|
|
23
23
|
});
|
|
24
|
-
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, className: "block min-w-0", children: anchor }), _jsx(EditorPanel, { session: session, title: field.label, anchor: anchorRef, align: "start", alignOffset: -OPTION_ROW_INSET, sideOffset: 4, initialFocus: false, chrome: "menu", className: "w-64 z-90", children: _jsx(ChipsEditor, { ref: editorRef, values: values, suggestions: offeredValues(field, known), resolve: resolve, normalize: normalizerFor(field), creatable: takesNewValues(field), onRequestClose: close, message: message }) })] }));
|
|
24
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, className: "block min-w-0", children: anchor }), _jsx(EditorPanel, { session: session, title: field.label, anchor: anchorRef, align: "start", alignOffset: -OPTION_ROW_INSET, sideOffset: 4, initialFocus: false, chrome: "menu", className: "w-64 z-90", children: _jsx(ChipsEditor, { ref: editorRef, values: values, suggestions: offeredValues(field, known), resolve: resolve, normalize: normalizerFor(field), creatable: takesNewValues(field), onRequestClose: close, message: message, label: field.label }) })] }));
|
|
25
25
|
}
|
|
@@ -14,5 +14,5 @@ export function RowDateEditor({ field, initial, anchor, onAttempt, onClose, mess
|
|
|
14
14
|
onClose,
|
|
15
15
|
mapPayload: (payload) => (payload === "" ? null : dayOnly ? payload.slice(0, 10) : payload),
|
|
16
16
|
});
|
|
17
|
-
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, className: "block min-w-0", children: anchor }), _jsx(EditorPanel, { session: session, title: field.label, anchor: anchorRef, align: "start", sideOffset: 4, initialFocus: false, chrome: "menu", className: "z-90 w-auto", children: (surface) => (_jsx(DateEditor, { ref: editorRef, initial: typeof initial === "string" && initial !== "" ? initial : undefined, timeOptional: dayOnly, dayOnly: dayOnly, clearable: !!field.nullable, fill: surface === "sheet", onRequestClose: close, message: message })) })] }));
|
|
17
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, className: "block min-w-0", children: anchor }), _jsx(EditorPanel, { session: session, title: field.label, anchor: anchorRef, align: "start", sideOffset: 4, initialFocus: false, chrome: "menu", className: "z-90 w-auto", children: (surface) => (_jsx(DateEditor, { ref: editorRef, label: field.label, initial: typeof initial === "string" && initial !== "" ? initial : undefined, timeOptional: dayOnly, dayOnly: dayOnly, clearable: !!field.nullable, fill: surface === "sheet", onRequestClose: close, message: message })) })] }));
|
|
18
18
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { EditFieldTypeContext } from "../../editors/escape-rule.js";
|
|
3
4
|
import { RowChipsEditor } from "./RowChipsEditor.js";
|
|
4
5
|
import { RowDateEditor } from "./RowDateEditor.js";
|
|
5
6
|
import { RowNameEditor } from "./RowNameEditor.js";
|
|
@@ -60,5 +61,5 @@ export function RowEditor(props) {
|
|
|
60
61
|
if (!mountsHost(field))
|
|
61
62
|
return hostless(field);
|
|
62
63
|
const Host = ROW_HOSTS[field.type];
|
|
63
|
-
return _jsx(Host, { ...props, field: field });
|
|
64
|
+
return (_jsx(EditFieldTypeContext.Provider, { value: field.type, children: _jsx(Host, { ...props, field: field }) }));
|
|
64
65
|
}
|
|
@@ -11,5 +11,6 @@ export function RowRangeEditor({ field, initial, onAttempt, onClose, }) {
|
|
|
11
11
|
const editorRef = useRef(null);
|
|
12
12
|
const anchorRef = useRef(null);
|
|
13
13
|
const { session, close } = useRowEditSession({ editorRef, inPlace: true, onAttempt, onClose });
|
|
14
|
-
|
|
14
|
+
const banded = (field.presets?.length ?? 0) > 0;
|
|
15
|
+
return (_jsxs(EditorPanel, { session: session, title: field.label, anchor: anchorRef, inPlace: true, children: [_jsx(RangeEditor, { ref: editorRef, initial: isRangeValue(initial) ? initial : null, decimals: rangeDecimals(field), allowEmpty: !!field.nullable, suffix: field.of === "percent" ? "%" : field.of === "currency" ? field.code?.fixed : undefined, align: "start", bands: field.presets, refusal: session.refusal, conventions: conventions, onRequestClose: close }), !banded && _jsx(RowRefusal, { text: session.refusal })] }));
|
|
15
16
|
}
|
|
@@ -38,7 +38,7 @@ function RowRelationOneEditor({ binding, field, initial, anchor, onAttempt, onCl
|
|
|
38
38
|
});
|
|
39
39
|
if (!binding.relation)
|
|
40
40
|
return null;
|
|
41
|
-
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, className: "block min-w-0", children: anchor }), _jsx(EditorPanel, { session: session, title: field.label, anchor: anchorRef, align: "start", alignOffset: -OPTION_ROW_INSET, sideOffset: 4, initialFocus: false, chrome: "menu", className: "w-64 z-90", children: _jsx(RelationEditor, { ref: editorRef, candidates: candidates, initial: relationIdOf(initial), clearable: !!field.nullable, kindGlyph: kindGlyph, focusSearch: !sheet, onRequestClose: close, message: message }) })] }));
|
|
41
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, className: "block min-w-0", children: anchor }), _jsx(EditorPanel, { session: session, title: field.label, anchor: anchorRef, align: "start", alignOffset: -OPTION_ROW_INSET, sideOffset: 4, initialFocus: false, chrome: "menu", className: "w-64 z-90", savesOnPick: true, children: _jsx(RelationEditor, { ref: editorRef, candidates: candidates, initial: relationIdOf(initial), clearable: !!field.nullable, kindGlyph: kindGlyph, focusSearch: !sheet, onRequestClose: close, message: message, label: field.label }) })] }));
|
|
42
42
|
}
|
|
43
43
|
function RowRelationSetEditor({ binding, field, initial, shown, anchor, onAttempt, onClose, message, kindIcon, }) {
|
|
44
44
|
const editorRef = useRef(null);
|
|
@@ -53,7 +53,7 @@ function RowRelationSetEditor({ binding, field, initial, shown, anchor, onAttemp
|
|
|
53
53
|
const candidates = binding.relation;
|
|
54
54
|
if (!candidates)
|
|
55
55
|
return null;
|
|
56
|
-
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, className: "block min-w-0", children: anchor }), _jsx(EditorPanel, { session: session, title: field.label, anchor: anchorRef, align: "start", alignOffset: -OPTION_ROW_INSET, sideOffset: 4, initialFocus: false, chrome: "menu", className: "w-64 z-90", children: _jsx(RelationSetEditor, { ref: editorRef, candidates: candidates, initial: setItems(field, initial, shown, candidates), lead: field.links?.primary === "flag", kindGlyph: kindGlyph, focusSearch: !sheet, onRequestClose: close, message: message }) })] }));
|
|
56
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, className: "block min-w-0", children: anchor }), _jsx(EditorPanel, { session: session, title: field.label, anchor: anchorRef, align: "start", alignOffset: -OPTION_ROW_INSET, sideOffset: 4, initialFocus: false, chrome: "menu", className: "w-64 z-90", children: _jsx(RelationSetEditor, { ref: editorRef, candidates: candidates, initial: setItems(field, initial, shown, candidates), lead: field.links?.primary === "flag", kindGlyph: kindGlyph, focusSearch: !sheet, onRequestClose: close, message: message, label: field.label }) })] }));
|
|
57
57
|
}
|
|
58
58
|
function setItems(field, initial, shown, candidates) {
|
|
59
59
|
const labels = new Map();
|
|
@@ -10,4 +10,4 @@ import { type RowHostProps } from "./host.js";
|
|
|
10
10
|
* MEANS for a select — a pick commits, everything else discards — are the
|
|
11
11
|
* core's, in one component for every surface.
|
|
12
12
|
*/
|
|
13
|
-
export declare function RowSelectEditor<Row>({ field, initial, anchor, onAttempt, onClose, message, }: RowHostProps<Row, "select" | "status">): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare function RowSelectEditor<Row>({ field, initial, anchor, onAttempt, onClose, message, openedByKey, }: RowHostProps<Row, "select" | "status">): import("react/jsx-runtime").JSX.Element;
|
|
@@ -7,7 +7,7 @@ import { useOpenValues } from "../../editors/open-values.js";
|
|
|
7
7
|
import { SelectEditor, pickerOptionsFromField, } from "../../editors/SelectEditor.js";
|
|
8
8
|
import { OPTION_ROW_INSET } from "./host.js";
|
|
9
9
|
import { useRowEditSession } from "./row-session.js";
|
|
10
|
-
export function RowSelectEditor({ field, initial, anchor, onAttempt, onClose, message, }) {
|
|
10
|
+
export function RowSelectEditor({ field, initial, anchor, onAttempt, onClose, message, openedByKey = false, }) {
|
|
11
11
|
const editorRef = useRef(null);
|
|
12
12
|
const anchorRef = useRef(null);
|
|
13
13
|
const known = useOpenValues(field);
|
|
@@ -19,5 +19,5 @@ export function RowSelectEditor({ field, initial, anchor, onAttempt, onClose, me
|
|
|
19
19
|
onClose,
|
|
20
20
|
mapPayload: (payload) => (payload === "" ? null : payload),
|
|
21
21
|
});
|
|
22
|
-
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, className: "block min-w-0", children: anchor }), _jsx(EditorPanel, { session: session, title: field.label, anchor: anchorRef, align: "start", alignOffset: -OPTION_ROW_INSET, sideOffset: 4, initialFocus: false, chrome: "menu", className: "w-56 z-90", children: _jsx(SelectEditor, { ref: editorRef, options: options, initial: current, clearable: !!field.nullable, creatable: isOpenVocabulary(field), focusSearch: !sheet, onRequestClose: close, message: message }) })] }));
|
|
22
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, className: "block min-w-0", children: anchor }), _jsx(EditorPanel, { session: session, title: field.label, anchor: anchorRef, align: "start", alignOffset: -OPTION_ROW_INSET, sideOffset: 4, initialFocus: false, chrome: "menu", className: "w-56 z-90", savesOnPick: true, children: _jsx(SelectEditor, { ref: editorRef, options: options, initial: current, clearable: !!field.nullable, creatable: isOpenVocabulary(field), focusSearch: !sheet, focusList: openedByKey && !sheet, onRequestClose: close, message: message, label: field.label }) })] }));
|
|
23
23
|
}
|
|
@@ -10,7 +10,7 @@ function RowValueListEditor({ field, binding, row, initial, anchor, onAttempt, o
|
|
|
10
10
|
const anchorRef = useRef(null);
|
|
11
11
|
const { session, close } = useRowEditSession({ editorRef, onAttempt, onClose });
|
|
12
12
|
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, className: "block min-w-0", children: anchor }), _jsx(EditorPanel, { session: session, title: field.label, anchor: anchorRef, align: "start", sideOffset: 4, initialFocus: false, chrome: "menu", className: "w-96 max-w-[calc(100vw-2rem)] z-90", children: (surface) => {
|
|
13
|
-
const editor = (_jsx(ValueListEditor, { ref: editorRef, field: field, initial: initial, labels: binding.labels !== false, allowEmpty: true, region: binding.region?.(row), openLinks: surface === "sheet", onRequestClose: close }));
|
|
13
|
+
const editor = (_jsx(ValueListEditor, { ref: editorRef, field: field, initial: initial, labels: binding.labels !== false, allowEmpty: true, region: binding.region?.(row), openLinks: surface === "sheet", escapeKeeps: session.keeps ?? false, onRequestClose: close }));
|
|
14
14
|
return _jsx("div", { className: surface === "sheet" ? "px-4 pb-4" : "p-1.5", children: editor });
|
|
15
15
|
} })] }));
|
|
16
16
|
}
|
|
@@ -34,6 +34,9 @@ export type RowEditorProps<Row> = {
|
|
|
34
34
|
/** The accepted answer has finished the host's visual close; `RowClosed` says what the row does next. */
|
|
35
35
|
onClose: (closed: RowClosed) => void;
|
|
36
36
|
message?: FieldMessageResolver;
|
|
37
|
+
/** The row's button was pressed by a key (Enter or Space), not a pointer: a picker then takes the focus in its
|
|
38
|
+
* list, so the arrows and Enter reach it. Default false. */
|
|
39
|
+
openedByKey?: boolean;
|
|
37
40
|
/** The app's own icon name for a record kind (`AppIcon`'s name), or undefined: the glyph a
|
|
38
41
|
* relation's candidates wear. Unanswered, they wear the field type's glyph. */
|
|
39
42
|
kindIcon?: (kind: string) => string | undefined;
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useRef, useState } from "react";
|
|
3
|
+
import { useContext, useRef, useState } from "react";
|
|
4
4
|
import { useAnchoredEditSession } from "../../editors/edit-session.js";
|
|
5
|
+
import { EditFieldTypeContext, useEscapeRule } from "../../editors/escape-rule.js";
|
|
5
6
|
import { useDesktop } from "../../provider/desktop.js";
|
|
6
7
|
export const ROW_SHEET_EXIT_MS = 500;
|
|
7
8
|
const RETURNS_FOCUS = new Set(["tab", "shift-tab", "escape", "enter", "pick"]);
|
|
8
9
|
export function useRowEditSession({ editorRef, mapPayload, inPlace = false, onAttempt, onClose, }) {
|
|
9
10
|
const desktop = useDesktop();
|
|
10
11
|
const [sheet] = useState(() => !inPlace && !desktop);
|
|
12
|
+
const escape = useEscapeRule(useContext(EditFieldTypeContext));
|
|
11
13
|
const reasonRef = useRef(null);
|
|
12
14
|
const closedRef = useRef({ focusBack: false });
|
|
13
15
|
const session = useAnchoredEditSession({
|
|
14
16
|
editorRef,
|
|
15
17
|
mapPayload,
|
|
18
|
+
escape,
|
|
16
19
|
onAttempt: (resolution) => {
|
|
17
20
|
const reason = reasonRef.current;
|
|
18
21
|
const attempt = onAttempt(resolution);
|
package/dist/fields/menus.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export type FieldRowMenuItem = {
|
|
|
10
10
|
onClick: () => void;
|
|
11
11
|
destructive?: boolean;
|
|
12
12
|
disabled?: boolean;
|
|
13
|
+
/** Why the disabled verb can't be used now, in words, handed to the app's menu. */
|
|
14
|
+
disabledReason?: string;
|
|
13
15
|
};
|
|
14
16
|
/**
|
|
15
17
|
* Field key → the verbs a row offers INSTEAD of an editor.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FieldDefOf, RangePeriod } from "@viewkitjs/fields";
|
|
2
|
+
/** A period as it trails a figure. */
|
|
3
|
+
export declare const RANGE_PERIOD_SHORT: Readonly<Record<RangePeriod, string>>;
|
|
4
|
+
/** The unit a range's figures are in: a percent's %, a fixed currency's code, else the field's own suffix. */
|
|
5
|
+
export declare function rangeUnit(def: FieldDefOf<"range">): string | undefined;
|
|
6
|
+
/** The period a range's figures cover, as it trails them ("/mo"), or undefined when it names none. */
|
|
7
|
+
export declare function rangePeriodShort(def: FieldDefOf<"range">): string | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const RANGE_PERIOD_SHORT = {
|
|
2
|
+
hour: "/h",
|
|
3
|
+
day: "/day",
|
|
4
|
+
week: "/wk",
|
|
5
|
+
month: "/mo",
|
|
6
|
+
year: "/yr",
|
|
7
|
+
};
|
|
8
|
+
export function rangeUnit(def) {
|
|
9
|
+
return def.of === "percent" ? "%" : def.of === "currency" ? def.code?.fixed : def.format?.suffix;
|
|
10
|
+
}
|
|
11
|
+
export function rangePeriodShort(def) {
|
|
12
|
+
return def.period ? RANGE_PERIOD_SHORT[def.period] : undefined;
|
|
13
|
+
}
|
package/dist/figures.d.ts
CHANGED
|
@@ -1,52 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A GROUP'S FIGURES, AS THE DATABASE COUNTED THEM (POR-470).
|
|
3
3
|
*
|
|
4
|
-
* A source list holds a page, not the list, so a footer or a group header that
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* footer pick the database can answer is read from them. Four, not one per
|
|
9
|
-
* pick: two parts' sums, counts, mins and maxes combine exactly, so a group
|
|
10
|
-
* folded from many discovery rows (the days of a week, a row under each of its
|
|
11
|
-
* tags) still answers an average, which a mean of the parts' means does not.
|
|
12
|
-
* Pure and free of the engine: the chassis reads it, the engine produces it.
|
|
13
|
-
*
|
|
14
|
-
* It imports NOTHING, not even a type: the source engine runs on the server,
|
|
15
|
-
* and the list model (`model/`) reaches browser modules — a type import is an
|
|
16
|
-
* edge the library ratchet follows (L004). So the footer picks are named here,
|
|
17
|
-
* and every caller hands a `ListAggregateKind`: a pick added there and not
|
|
18
|
-
* here fails the checker at the footer's call.
|
|
19
|
-
*/
|
|
20
|
-
/** The footer picks, as `model/column-schema.ts` names them (`ListAggregateKind`). */
|
|
21
|
-
export type FigureKind = "none" | "sum" | "avg" | "min" | "max" | "count" | "filled" | "unique" | "ratio";
|
|
22
|
-
export type ColumnFigure = {
|
|
23
|
-
sum: number | null;
|
|
24
|
-
count: number;
|
|
25
|
-
min: number | null;
|
|
26
|
-
max: number | null;
|
|
27
|
-
};
|
|
28
|
-
/** A group's — or the whole list's — figures: its rows, and each totalled key's figure. */
|
|
29
|
-
export type GroupFigures = {
|
|
30
|
-
rows: number;
|
|
31
|
-
fields: Record<string, ColumnFigure>;
|
|
32
|
-
};
|
|
33
|
-
export declare const EMPTY_FIGURE: ColumnFigure;
|
|
34
|
-
/** Two parts' figures as the figure of both. A null is a value absent, never a zero. */
|
|
35
|
-
export declare function combineFigure(a: ColumnFigure, b: ColumnFigure): ColumnFigure;
|
|
36
|
-
/** The figure of some values, a blank not counted. */
|
|
37
|
-
export declare function figureOf(values: readonly (number | null | undefined)[]): ColumnFigure;
|
|
38
|
-
/**
|
|
39
|
-
* The number a footer pick shows, or null for nothing to show. Follows the
|
|
40
|
-
* browser's own aggregate (`computeAggregate`): over no values, sum, avg, min
|
|
41
|
-
* and max are null; Count is the group's rows; Filled is the values present.
|
|
42
|
-
* Unique and Ratio are not the database's to answer.
|
|
43
|
-
*/
|
|
44
|
-
export declare function figureFor(kind: FigureKind, figures: GroupFigures, key: string): number | null;
|
|
45
|
-
/**
|
|
46
|
-
* A ratio formula's footer from its two parts' figures: sum over sum, as a
|
|
47
|
-
* percent (0–100), divided once — the browser's own `ratio` over the same
|
|
48
|
-
* rows. Null when either part was not totalled or the denominator is empty.
|
|
4
|
+
* A source list holds a page, not the list, so a footer or a group header that totals the rows in hand is wrong past
|
|
5
|
+
* the first page: it reads the figures the database answered for the whole group. Their shape and rules are
|
|
6
|
+
* `@viewkitjs/fields`' (the query entry's figures), which answers the same shape in memory, so the browser and a
|
|
7
|
+
* database are held to one answer. Re-exported here under the names the grid and the apps already read.
|
|
49
8
|
*/
|
|
50
|
-
export
|
|
51
|
-
/** Whether an answer's field is a `GroupFigures` — the hook hands a first page's own fields over untyped. */
|
|
52
|
-
export declare function isGroupFigures(value: unknown): value is GroupFigures;
|
|
9
|
+
export { EMPTY_FIGURE, combineFigure, figureFor, figureOf, isGroupFigures, ratioFigure, type ColumnFigure, type FigureKind, type GroupFigures, } from "@viewkitjs/fields/query";
|