@cosmicdrift/kumiko-renderer 0.414.0 → 0.416.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/dist/app/action-form-body.d.ts +1 -1
- package/dist/app/action-form-body.js +43 -16
- package/dist/app/action-form-support.d.ts +4 -1
- package/dist/app/action-form-support.js +8 -4
- package/dist/app/client-actions.js +6 -4
- package/dist/app/config-edit-body.js +13 -4
- package/dist/app/entity-list-screen.js +12 -9
- package/dist/app/extension-sections.d.ts +2 -0
- package/dist/app/list-facets.d.ts +1 -0
- package/dist/app/list-facets.js +10 -1
- package/dist/app/named-filter-facet.d.ts +0 -1
- package/dist/app/named-filter-facet.js +19 -10
- package/dist/app/projection-detail-body.js +8 -6
- package/dist/app/projection-detail-guidance-data.js +3 -1
- package/dist/app/projection-detail-guidance.d.ts +1 -1
- package/dist/app/projection-detail-guidance.js +45 -33
- package/dist/app/projection-detail-header-model.d.ts +1 -1
- package/dist/app/projection-detail-header-model.js +10 -5
- package/dist/app/projection-detail-header.js +5 -4
- package/dist/app/projection-detail-navigation.d.ts +6 -0
- package/dist/app/projection-detail-navigation.js +18 -4
- package/dist/app/screen-access.js +1 -2
- package/dist/app/screen-shared.d.ts +1 -0
- package/dist/app/screen-shared.js +23 -3
- package/dist/app/use-entity-list-payload.d.ts +2 -1
- package/dist/app/use-entity-list-payload.js +4 -2
- package/dist/app/use-projection-detail-actions.d.ts +14 -0
- package/dist/app/use-projection-detail-actions.js +40 -16
- package/dist/app/use-projection-detail-data.d.ts +2 -0
- package/dist/app/use-projection-detail-data.js +37 -10
- package/dist/app/use-row-decoration.d.ts +6 -4
- package/dist/app/use-row-decoration.js +67 -19
- package/dist/app/use-screen-list-rows.js +1 -1
- package/dist/card-options.d.ts +25 -0
- package/dist/card-options.js +1 -0
- package/dist/components/ai-assist-payload.d.ts +2 -0
- package/dist/components/ai-assist-payload.js +8 -0
- package/dist/components/edit-mounts.d.ts +3 -2
- package/dist/components/edit-mounts.js +2 -2
- package/dist/components/list-empty-state.d.ts +5 -0
- package/dist/components/list-empty-state.js +17 -1
- package/dist/components/multi-select-chips.d.ts +10 -0
- package/dist/components/multi-select-chips.js +18 -0
- package/dist/components/related-list-section.js +44 -32
- package/dist/components/related-photo-grid.d.ts +11 -0
- package/dist/components/related-photo-grid.js +40 -0
- package/dist/components/render-edit-action-button.d.ts +2 -2
- package/dist/components/render-edit-field-grid.js +3 -3
- package/dist/components/render-edit-header-actions.d.ts +2 -1
- package/dist/components/render-edit-header-actions.js +18 -1
- package/dist/components/render-edit-layout.js +2 -2
- package/dist/components/render-edit-logic.js +1 -0
- package/dist/components/render-edit-section-kinds.js +11 -0
- package/dist/components/render-edit-types.d.ts +11 -1
- package/dist/components/render-field-ai-assist.d.ts +13 -0
- package/dist/components/render-field-ai-assist.js +89 -0
- package/dist/components/render-field-choice-inputs.js +4 -0
- package/dist/components/render-field-control.d.ts +1 -1
- package/dist/components/render-field-control.js +18 -8
- package/dist/components/render-field-value-chips.d.ts +9 -0
- package/dist/components/render-field-value-chips.js +45 -0
- package/dist/components/render-field-write-only.js +12 -4
- package/dist/components/render-list-hint-columns.d.ts +2 -0
- package/dist/components/render-list-hint-columns.js +23 -0
- package/dist/components/render-list-toolbar-model.d.ts +2 -2
- package/dist/components/use-render-edit-sections.js +5 -1
- package/dist/components/use-render-list-columns.js +3 -3
- package/dist/context/screen-focus-context.d.ts +1 -1
- package/dist/context/screen-focus-context.js +3 -3
- package/dist/data-table-facet-types.d.ts +4 -0
- package/dist/headless/format/index.d.ts +1 -0
- package/dist/headless/format/index.js +20 -0
- package/dist/headless/format/phone.d.ts +1 -0
- package/dist/headless/format/phone.js +8 -0
- package/dist/headless/format/relative-time.d.ts +13 -0
- package/dist/headless/format/relative-time.js +60 -0
- package/dist/headless/format/safe-locale.d.ts +1 -0
- package/dist/headless/format/safe-locale.js +13 -0
- package/dist/headless/index.d.ts +3 -3
- package/dist/headless/index.js +3 -3
- package/dist/headless/pwa-service-worker-meta.d.ts +3 -0
- package/dist/headless/pwa-service-worker-meta.js +10 -0
- package/dist/headless/view-model/edit.d.ts +3 -2
- package/dist/headless/view-model/edit.js +78 -2
- package/dist/headless/view-model/field-text.d.ts +9 -0
- package/dist/headless/view-model/field-text.js +19 -0
- package/dist/headless/view-model/index.d.ts +1 -0
- package/dist/headless/view-model/index.js +1 -0
- package/dist/headless/view-model/types.d.ts +33 -3
- package/dist/i18n-defaults.js +4 -1
- package/dist/index.d.ts +1 -1
- package/dist/metric-types.d.ts +2 -0
- package/dist/primitives-record-guidance.d.ts +30 -1
- package/dist/primitives.d.ts +17 -27
- package/dist/web/app/dashboard-body.js +3 -2
- package/dist/web/app/dashboard-header.js +1 -1
- package/dist/web/app/dashboard-list-panel.js +9 -13
- package/dist/web/app/dashboard-panel-columns.d.ts +9 -0
- package/dist/web/app/dashboard-panel-columns.js +14 -0
- package/dist/web/app/dashboard-panels.d.ts +1 -0
- package/dist/web/app/dashboard-panels.js +9 -7
- package/dist/web/app/dashboard-reference-list-table.js +1 -0
- package/dist/web/app/dashboard-shared.js +3 -2
- package/dist/web/app/dashboard-stat-group-panel.d.ts +1 -0
- package/dist/web/app/dashboard-stat-group-panel.js +22 -8
- package/dist/web/app/dashboard-text-panel.d.ts +1 -0
- package/dist/web/app/dashboard-text-panel.js +18 -12
- package/dist/web/app/relative-time.d.ts +0 -5
- package/dist/web/app/relative-time.js +1 -20
- package/dist/web/drawn-icons.d.ts +6 -0
- package/dist/web/drawn-icons.js +30 -0
- package/dist/web/icons.js +6 -5
- package/dist/web/index.d.ts +2 -0
- package/dist/web/index.js +2 -0
- package/dist/web/layout/default-app-shell.js +3 -3
- package/dist/web/layout/nav-collapse-state.d.ts +2 -0
- package/dist/web/layout/nav-collapse-state.js +10 -0
- package/dist/web/layout/nav-tree.js +46 -23
- package/dist/web/layout/notification-bell.d.ts +7 -2
- package/dist/web/layout/notification-bell.js +16 -5
- package/dist/web/layout/shell-focus.d.ts +2 -2
- package/dist/web/layout/shell-focus.js +7 -3
- package/dist/web/layout/shell-header.d.ts +2 -1
- package/dist/web/layout/shell-header.js +56 -27
- package/dist/web/layout/shell-style.d.ts +3 -0
- package/dist/web/layout/shell-style.js +6 -0
- package/dist/web/layout/workspace-shell.d.ts +11 -1
- package/dist/web/layout/workspace-shell.js +6 -4
- package/dist/web/primitives/banner.d.ts +1 -1
- package/dist/web/primitives/banner.js +19 -9
- package/dist/web/primitives/card.js +18 -8
- package/dist/web/primitives/data-table/actions-column.d.ts +1 -1
- package/dist/web/primitives/data-table/actions-column.js +3 -1
- package/dist/web/primitives/data-table/card-body.d.ts +1 -1
- package/dist/web/primitives/data-table/card-body.js +11 -6
- package/dist/web/primitives/data-table/card-row.js +27 -18
- package/dist/web/primitives/data-table/data-cell-props.d.ts +2 -0
- package/dist/web/primitives/data-table/data-cell-props.js +2 -0
- package/dist/web/primitives/data-table/hint-cell.d.ts +1 -3
- package/dist/web/primitives/data-table/hint-cell.js +4 -10
- package/dist/web/primitives/data-table/row-click-guard.d.ts +2 -0
- package/dist/web/primitives/data-table/row-click-guard.js +19 -0
- package/dist/web/primitives/data-table/row-render-parts.d.ts +1 -1
- package/dist/web/primitives/data-table/row-render-parts.js +3 -2
- package/dist/web/primitives/data-table/sort-options-select.js +3 -3
- package/dist/web/primitives/data-table/table-body.js +2 -1
- package/dist/web/primitives/data-table/table-content.js +10 -6
- package/dist/web/primitives/data-table/table-view.js +8 -3
- package/dist/web/primitives/data-table/toolbar.d.ts +2 -0
- package/dist/web/primitives/data-table/toolbar.js +44 -9
- package/dist/web/primitives/data-table/totals-footer.js +4 -3
- package/dist/web/primitives/data-table-cell.d.ts +4 -1
- package/dist/web/primitives/data-table-cell.js +60 -20
- package/dist/web/primitives/default-form.js +6 -3
- package/dist/web/primitives/drawer.js +5 -1
- package/dist/web/primitives/facet-filter.d.ts +1 -1
- package/dist/web/primitives/facet-filter.js +16 -8
- package/dist/web/primitives/facet-search-filter.d.ts +2 -1
- package/dist/web/primitives/facet-search-filter.js +3 -2
- package/dist/web/primitives/facet-trigger-label.d.ts +8 -0
- package/dist/web/primitives/facet-trigger-label.js +9 -0
- package/dist/web/primitives/file-view-action.js +4 -1
- package/dist/web/primitives/form-footer-parts.js +4 -1
- package/dist/web/primitives/form.js +6 -8
- package/dist/web/primitives/index.js +4 -0
- package/dist/web/primitives/layout-elements.d.ts +1 -1
- package/dist/web/primitives/layout-elements.js +3 -3
- package/dist/web/primitives/locale-number.d.ts +0 -1
- package/dist/web/primitives/locale-number.js +1 -13
- package/dist/web/primitives/metric.js +17 -5
- package/dist/web/primitives/money-input.js +2 -1
- package/dist/web/primitives/narrow-pinned-footer.js +7 -3
- package/dist/web/primitives/number-input.js +2 -1
- package/dist/web/primitives/page-header.js +3 -2
- package/dist/web/primitives/pager.d.ts +3 -2
- package/dist/web/primitives/pager.js +16 -20
- package/dist/web/primitives/photo-grid.d.ts +3 -0
- package/dist/web/primitives/photo-grid.js +5 -0
- package/dist/web/primitives/record-breadcrumb.js +1 -1
- package/dist/web/primitives/record-steps.d.ts +1 -1
- package/dist/web/primitives/record-steps.js +11 -6
- package/dist/web/primitives/record-summary.d.ts +1 -1
- package/dist/web/primitives/record-summary.js +8 -3
- package/dist/web/primitives/segmented-select.js +6 -3
- package/dist/web/primitives/step-list.d.ts +3 -0
- package/dist/web/primitives/step-list.js +11 -0
- package/dist/web/primitives/tabs.js +6 -1
- package/dist/web/pwa/pwa-support.js +19 -1
- package/dist/web/ui/sidebar.d.ts +2 -1
- package/dist/web/ui/sidebar.js +4 -3
- package/dist/web/widgets/ai-text-field.js +3 -2
- package/dist/web/widgets/dashboard-list-cards.js +6 -14
- package/dist/web/widgets/dashboard-list.d.ts +10 -0
- package/dist/web/widgets/dashboard-list.js +36 -10
- package/dist/web/widgets/drawer-panel-class.d.ts +1 -0
- package/dist/web/widgets/drawer-panel-class.js +9 -1
- package/dist/web/widgets/drawer.js +2 -2
- package/dist/web/widgets/pdf-viewer-toolbar.js +3 -2
- package/dist/web/widgets/sheet-parts.js +3 -1
- package/dist/web/widgets/stat-box-cell.js +1 -1
- package/dist/web/widgets/stat.d.ts +7 -1
- package/dist/web/widgets/stat.js +12 -4
- package/dist/web/widgets/step-list-row.d.ts +4 -0
- package/dist/web/widgets/step-list-row.js +22 -14
- package/dist/web/widgets/step-list.d.ts +12 -4
- package/dist/web/widgets/step-list.js +38 -20
- package/package.json +5 -5
- package/src/changes.json +126 -0
- package/src/web/styles.css +6 -0
|
@@ -69,6 +69,8 @@ export type RenderEditProps<TValues extends FormValues, TCtx = unknown> = {
|
|
|
69
69
|
* same split as `onCopyLink`) — RenderEdit only wires the button, its
|
|
70
70
|
* busy state and its confirm dialog. */
|
|
71
71
|
readonly actions?: readonly RenderEditAction[];
|
|
72
|
+
/** Translated note on the left of the form footer (hidden below `sm`). */
|
|
73
|
+
readonly footerHint?: string;
|
|
72
74
|
/** Record actions declared with `placement: "menu"`, resolved like `actions`.
|
|
73
75
|
* Rendered in the header "…" menu ahead of copy-link/delete; without a
|
|
74
76
|
* header menu (drawer, card form, shell without a header slot) they fall
|
|
@@ -110,8 +112,10 @@ export type RenderEditProps<TValues extends FormValues, TCtx = unknown> = {
|
|
|
110
112
|
* above-control; below-control keeps the inputs of neighbouring fields
|
|
111
113
|
* on one line when an appendix expands. */
|
|
112
114
|
readonly fieldAppendixPlacement?: "above-control" | "below-control";
|
|
115
|
+
/** Renders the form-error banner above the sections instead of below them. */
|
|
116
|
+
readonly formErrorOnTop?: boolean;
|
|
113
117
|
/** Per-field help text rendered under the label (translated by the caller). */
|
|
114
|
-
readonly fieldDescription?: (fieldName: string) => ReactNode | undefined;
|
|
118
|
+
readonly fieldDescription?: (fieldName: string, values: Readonly<Record<string, unknown>>) => ReactNode | undefined;
|
|
115
119
|
/** Extra full-width row drawn right after a field's cell (configEdit actions). `dirty` is true
|
|
116
120
|
* while the form has unsaved changes. Called with the field name, returns a ReactNode or
|
|
117
121
|
* undefined. */
|
|
@@ -197,6 +201,8 @@ export type RenderEditProps<TValues extends FormValues, TCtx = unknown> = {
|
|
|
197
201
|
* redundant title above its content. Omitting this prop keeps unchanged
|
|
198
202
|
* behavior. */
|
|
199
203
|
readonly hideSectionTitles?: boolean;
|
|
204
|
+
/** Id of the active tab of a tabbed projectionDetail; handed to the `afterForm` slot. */
|
|
205
|
+
readonly activeTabId?: string;
|
|
200
206
|
/** Screen body fills the shell height: the form gets `fillHeight` and
|
|
201
207
|
* `stickyActions` (sections scroll, footer pinned). Set by KumikoScreen for
|
|
202
208
|
* screens with `fillHeight !== false`; dialogs and other embedded hosts
|
|
@@ -256,6 +262,10 @@ export type RenderEditAction = {
|
|
|
256
262
|
* drives both the icon-left-of-text render and the icon-only collapse
|
|
257
263
|
* rule (see `shouldRenderActionsIconOnly`). */
|
|
258
264
|
readonly icon?: IconKey;
|
|
265
|
+
/** "start" sets the button apart on the left of the form footer. */
|
|
266
|
+
readonly align?: "start";
|
|
267
|
+
/** Stays a visible button in the pinned footer below `sm` instead of folding into the "…" menu. */
|
|
268
|
+
readonly pinnedOnPhone?: true;
|
|
259
269
|
};
|
|
260
270
|
export type RenderEditChangeState<TValues extends FormValues> = {
|
|
261
271
|
readonly values: TValues;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { EditFieldViewModel } from "../headless/index.ts";
|
|
3
|
+
type AiAssist = NonNullable<EditFieldViewModel["aiAssist"]>;
|
|
4
|
+
type AiAssistControlProps = {
|
|
5
|
+
readonly field: EditFieldViewModel;
|
|
6
|
+
readonly aiAssist: AiAssist;
|
|
7
|
+
readonly onChange: (value: unknown) => void;
|
|
8
|
+
readonly input: ReactNode;
|
|
9
|
+
/** Current form values; `aiAssist.contextFields` are read from here. */
|
|
10
|
+
readonly row?: Readonly<Record<string, unknown>>;
|
|
11
|
+
};
|
|
12
|
+
export declare function AiAssistControl(props: AiAssistControlProps): ReactNode;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { useOptionalDispatcher } from "../context/dispatcher-context.js";
|
|
5
|
+
import { useTranslation } from "../i18n.js";
|
|
6
|
+
import { usePrimitives } from "../primitives.js";
|
|
7
|
+
import { useAiAssistPayload } from "./ai-assist-payload.js";
|
|
8
|
+
// Mounted only with a dispatcher; without one the field stays a plain input.
|
|
9
|
+
export function AiAssistControl(props) {
|
|
10
|
+
const dispatcher = useOptionalDispatcher();
|
|
11
|
+
return dispatcher === undefined ? props.input : _jsx(AiAssistChips, { ...props });
|
|
12
|
+
}
|
|
13
|
+
// Chips stack: every active chip contributes its params, so "shorter" and "mention warranty"
|
|
14
|
+
// can be combined. A click toggles the chip and re-runs the query with the new set.
|
|
15
|
+
function AiAssistChips({ field, aiAssist, onChange, input, row }) {
|
|
16
|
+
const { Button, Input, Banner } = usePrimitives();
|
|
17
|
+
const t = useTranslation();
|
|
18
|
+
const dispatcher = useOptionalDispatcher();
|
|
19
|
+
const contextPayload = useAiAssistPayload();
|
|
20
|
+
const [active, setActive] = useState(new Set());
|
|
21
|
+
const [instruction, setInstruction] = useState("");
|
|
22
|
+
const [busy, setBusy] = useState(false);
|
|
23
|
+
const [failed, setFailed] = useState(false);
|
|
24
|
+
const [note, setNote] = useState(undefined);
|
|
25
|
+
const activeRun = useRef(null);
|
|
26
|
+
const contextValues = Object.fromEntries((aiAssist.contextFields ?? []).map((name) => [name, row?.[name]]));
|
|
27
|
+
// Changed context (e.g. another selection) replaces the text; the first render never fetches.
|
|
28
|
+
const contextKey = JSON.stringify(contextValues);
|
|
29
|
+
const seenContextKey = useRef(contextKey);
|
|
30
|
+
const run = async (chips, typed) => {
|
|
31
|
+
if (dispatcher === undefined)
|
|
32
|
+
return;
|
|
33
|
+
activeRun.current?.abort();
|
|
34
|
+
const ctrl = new AbortController();
|
|
35
|
+
activeRun.current = ctrl;
|
|
36
|
+
const chipParams = Object.assign({}, ...[...chips].map((index) => aiAssist.chips?.[index]?.params));
|
|
37
|
+
const payload = {
|
|
38
|
+
...contextPayload,
|
|
39
|
+
...contextValues,
|
|
40
|
+
...chipParams,
|
|
41
|
+
...(typed !== undefined &&
|
|
42
|
+
aiAssist.prompt !== undefined && { [aiAssist.prompt.param]: typed }),
|
|
43
|
+
};
|
|
44
|
+
setBusy(true);
|
|
45
|
+
setFailed(false);
|
|
46
|
+
const result = await dispatcher.query(aiAssist.query, payload, {
|
|
47
|
+
signal: ctrl.signal,
|
|
48
|
+
});
|
|
49
|
+
if (ctrl.signal.aborted)
|
|
50
|
+
return;
|
|
51
|
+
setBusy(false);
|
|
52
|
+
const noteText = result.isSuccess && aiAssist.noteField !== undefined
|
|
53
|
+
? propertyOf(result.data, aiAssist.noteField)
|
|
54
|
+
: undefined;
|
|
55
|
+
setNote(typeof noteText === "string" && noteText !== "" ? noteText : undefined);
|
|
56
|
+
const text = result.isSuccess ? propertyOf(result.data, aiAssist.resultField) : undefined;
|
|
57
|
+
if (typeof text !== "string") {
|
|
58
|
+
setFailed(true);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
onChange(text);
|
|
62
|
+
};
|
|
63
|
+
// The effect reads the latest run/active through a ref so it only fires when the context changes.
|
|
64
|
+
const rerunWithCurrentChips = useRef(() => { });
|
|
65
|
+
rerunWithCurrentChips.current = () => void run(active, undefined);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
// skip: nothing changed since the last run (or since mount).
|
|
68
|
+
if (seenContextKey.current === contextKey)
|
|
69
|
+
return;
|
|
70
|
+
seenContextKey.current = contextKey;
|
|
71
|
+
rerunWithCurrentChips.current();
|
|
72
|
+
}, [contextKey]);
|
|
73
|
+
const toggle = (index) => {
|
|
74
|
+
const next = new Set(active);
|
|
75
|
+
if (!next.delete(index))
|
|
76
|
+
next.add(index);
|
|
77
|
+
setActive(next);
|
|
78
|
+
void run(next, undefined);
|
|
79
|
+
};
|
|
80
|
+
return (_jsxs(_Fragment, { children: [input, _jsxs("div", { className: "flex flex-wrap items-center gap-2", "data-testid": `field-ai-assist-${field.field}`, children: [aiAssist.chips?.map((chip, index) => (_jsx(Button, { variant: "secondary", size: "sm", pressed: active.has(index), disabled: busy || field.readOnly, testId: `field-ai-chip-${field.field}-${index}`, onClick: () => toggle(index), children: chip.label }, chip.label))), aiAssist.prompt !== undefined && (_jsx(Input, { kind: "text", id: `${field.field}-ai-instruction`, name: `${field.field}-ai-instruction`, value: instruction, onChange: setInstruction, onKeyDown: (event) => {
|
|
81
|
+
if (event.key !== "Enter")
|
|
82
|
+
return;
|
|
83
|
+
// Enter must not submit the host form.
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
if (busy || field.readOnly || instruction.trim() === "")
|
|
86
|
+
return;
|
|
87
|
+
void run(active, instruction.trim());
|
|
88
|
+
}, disabled: busy || field.readOnly, placeholder: aiAssist.prompt.placeholder ?? t("kumiko.field.aiAssist.prompt"), testId: `field-ai-prompt-${field.field}` }))] }), note !== undefined && (_jsx("span", { className: "text-xs text-muted-foreground", "data-testid": `field-ai-note-${field.field}`, children: note })), failed && (_jsx(Banner, { variant: "error", testId: `field-ai-error-${field.field}`, children: t("kumiko.field.aiAssist.failed") }))] }));
|
|
89
|
+
}
|
|
@@ -2,8 +2,12 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { AvailabilityOptionsMultiSelect, staticSelectOptions, } from "./availability-options-select.js";
|
|
3
3
|
import { FileListField } from "./file-list-field.js";
|
|
4
4
|
import { MultiSelectCheckboxes } from "./multi-select-checkboxes.js";
|
|
5
|
+
import { MultiSelectChips } from "./multi-select-chips.js";
|
|
5
6
|
import { stringArrayOf, stringValue, withPinnedValues } from "./render-field-values.js";
|
|
6
7
|
function renderMultiSelectControl({ field, id, Input, onChange }, { common }, options, arrayValue) {
|
|
8
|
+
if (field.display === "chips") {
|
|
9
|
+
return (_jsx(MultiSelectChips, { field: field, id: id, options: options, value: arrayValue, onChange: (v) => onChange(v) }));
|
|
10
|
+
}
|
|
7
11
|
return field.display === "checkboxes" ? (_jsx(MultiSelectCheckboxes, { field: field, id: id, options: options, value: arrayValue, onChange: (v) => onChange(v) })) : (_jsx(Input, { kind: "combobox", ...common, multiple: true, value: arrayValue, onChange: (v) => onChange(withPinnedValues(v, options, arrayValue)), options: options }));
|
|
8
12
|
}
|
|
9
13
|
export function renderMultiSelectInput(args, shared) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
import type
|
|
2
|
+
import { type EditFieldViewModel, type FieldIssue } from "../headless/index.ts";
|
|
3
3
|
import type { usePrimitives } from "../primitives.tsx";
|
|
4
4
|
import type { RenderInputArgs } from "./render-field-input-shared.ts";
|
|
5
5
|
export type ControlContext = RenderInputArgs & {
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { telHref } from "../headless/index.js";
|
|
2
3
|
import { AvailabilityOptionsSelect } from "./availability-options-select.js";
|
|
3
4
|
import { EmbeddedListField } from "./embedded-list-field.js";
|
|
4
5
|
import { QueryOptionsSelect } from "./query-options-select.js";
|
|
6
|
+
import { AiAssistControl } from "./render-field-ai-assist.js";
|
|
5
7
|
import { FillActionControl } from "./render-field-fill-action.js";
|
|
6
8
|
import { renderInput } from "./render-field-input.js";
|
|
7
9
|
import { isComplexFieldType, isFileFieldType } from "./render-field-meta.js";
|
|
8
10
|
import { FieldRendererOutput, readOnlyDisplayText } from "./render-field-read-only.js";
|
|
9
11
|
import { ReadOnlyReferenceValue, ReferenceInput } from "./render-field-reference.js";
|
|
12
|
+
import { ValueChipsControl } from "./render-field-value-chips.js";
|
|
10
13
|
import { WriteOnlyTextInput } from "./render-field-write-only.js";
|
|
11
14
|
function rowOf({ field, row }) {
|
|
12
15
|
return row ?? { [field.field]: field.value };
|
|
@@ -55,12 +58,6 @@ const selectAvailabilityRule = (ctx) => {
|
|
|
55
58
|
return undefined;
|
|
56
59
|
return (_jsx(AvailabilityOptionsSelect, { field: field, query: source.query, payload: source.payload, row: rowOf(ctx), id: id, hasError: hasError, onChange: onChange }));
|
|
57
60
|
};
|
|
58
|
-
// Only digits and a leading "+" survive into the tel: href, so a stored
|
|
59
|
-
// "+49 (30) 123-45" dials but can never smuggle other URI parts.
|
|
60
|
-
function telHrefDigits(value) {
|
|
61
|
-
const digits = value.replace(/[^\d]/g, "");
|
|
62
|
-
return value.trim().startsWith("+") ? `+${digits}` : digits;
|
|
63
|
-
}
|
|
64
61
|
function contactHref(field) {
|
|
65
62
|
if (field.type !== "text" || typeof field.value !== "string" || field.value.trim() === "") {
|
|
66
63
|
return undefined;
|
|
@@ -68,8 +65,7 @@ function contactHref(field) {
|
|
|
68
65
|
if (field.format === "email")
|
|
69
66
|
return `mailto:${field.value.trim()}`;
|
|
70
67
|
if (field.format === "phone") {
|
|
71
|
-
|
|
72
|
-
return digits.replace("+", "") === "" ? undefined : `tel:${digits}`;
|
|
68
|
+
return telHref(field.value);
|
|
73
69
|
}
|
|
74
70
|
return undefined;
|
|
75
71
|
}
|
|
@@ -95,6 +91,18 @@ const fillActionRule = (ctx) => {
|
|
|
95
91
|
return undefined;
|
|
96
92
|
return (_jsx(FillActionControl, { field: field, fillAction: fillAction, row: rowOf(ctx), onChange: onChange, disabled: fillDisabled === true, Banner: Banner, renderControl: (fill) => renderInput({ ...ctx, fill }) }));
|
|
97
93
|
};
|
|
94
|
+
const aiAssistRule = (ctx) => {
|
|
95
|
+
const { field, onChange } = ctx;
|
|
96
|
+
if (field.aiAssist === undefined || field.readOnly)
|
|
97
|
+
return undefined;
|
|
98
|
+
return (_jsx(AiAssistControl, { field: field, row: rowOf(ctx), aiAssist: field.aiAssist, onChange: onChange, input: renderInput(ctx) }));
|
|
99
|
+
};
|
|
100
|
+
const valueChipsRule = (ctx) => {
|
|
101
|
+
const { field, onChange } = ctx;
|
|
102
|
+
if (field.valueChips === undefined || field.readOnly)
|
|
103
|
+
return undefined;
|
|
104
|
+
return (_jsx(ValueChipsControl, { field: field, from: field.valueChips.from, row: rowOf(ctx), onChange: onChange, input: renderInput(ctx) }));
|
|
105
|
+
};
|
|
98
106
|
const CONTROL_RULES = [
|
|
99
107
|
fieldRendererRule,
|
|
100
108
|
embeddedListRule,
|
|
@@ -104,6 +112,8 @@ const CONTROL_RULES = [
|
|
|
104
112
|
readOnlyTextRule,
|
|
105
113
|
writeOnlyRule,
|
|
106
114
|
fillActionRule,
|
|
115
|
+
aiAssistRule,
|
|
116
|
+
valueChipsRule,
|
|
107
117
|
];
|
|
108
118
|
export function renderControl(ctx) {
|
|
109
119
|
for (const rule of CONTROL_RULES) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { type EditFieldViewModel } from "../headless/index.ts";
|
|
3
|
+
export declare function ValueChipsControl({ field, from, row, onChange, input, }: {
|
|
4
|
+
readonly field: EditFieldViewModel;
|
|
5
|
+
readonly from: string;
|
|
6
|
+
readonly row: Readonly<Record<string, unknown>>;
|
|
7
|
+
readonly onChange: (value: unknown) => void;
|
|
8
|
+
readonly input: ReactNode;
|
|
9
|
+
}): ReactNode;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { currencyDecimals, formatMoney, resolveSafeMoneyLocale, } from "../headless/index.js";
|
|
3
|
+
import { useOptionalLocale } from "../i18n.js";
|
|
4
|
+
import { usePrimitives } from "../primitives.js";
|
|
5
|
+
import { moneyPayload, resolveMoneyCurrency } from "./render-field-values.js";
|
|
6
|
+
function chipValues(row, from) {
|
|
7
|
+
const raw = row[from];
|
|
8
|
+
return Array.isArray(raw) ? raw.filter((v) => typeof v === "number") : [];
|
|
9
|
+
}
|
|
10
|
+
// Chip values are major units, like the text on the chip.
|
|
11
|
+
function chipText(field, value, currency, locale) {
|
|
12
|
+
if (field.type === "money") {
|
|
13
|
+
const decimals = currencyDecimals(currency);
|
|
14
|
+
return formatMoney(Math.round(value * 10 ** decimals), currency, locale, Number.isInteger(value) ? 0 : decimals);
|
|
15
|
+
}
|
|
16
|
+
return new Intl.NumberFormat(resolveSafeMoneyLocale(locale)).format(value);
|
|
17
|
+
}
|
|
18
|
+
// The form holds a money value as { amount (major units), currency }.
|
|
19
|
+
function currentMajorValue(field) {
|
|
20
|
+
const { value } = field;
|
|
21
|
+
if (field.type !== "money")
|
|
22
|
+
return typeof value === "number" ? value : undefined;
|
|
23
|
+
if (typeof value !== "object" || value === null || !("amount" in value))
|
|
24
|
+
return undefined;
|
|
25
|
+
return typeof value.amount === "number" ? value.amount : undefined;
|
|
26
|
+
}
|
|
27
|
+
// A money field stores {amount, currency}, a number field the bare number.
|
|
28
|
+
export function ValueChipsControl({ field, from, row, onChange, input, }) {
|
|
29
|
+
const { Button, Grid } = usePrimitives();
|
|
30
|
+
const locale = useOptionalLocale();
|
|
31
|
+
const values = chipValues(row, from);
|
|
32
|
+
const currency = resolveMoneyCurrency(field.value, field.currency);
|
|
33
|
+
const current = currentMajorValue(field);
|
|
34
|
+
const pick = (value) => {
|
|
35
|
+
if (field.type !== "money") {
|
|
36
|
+
onChange(value);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
onChange(moneyPayload(Math.round(value * 10 ** currencyDecimals(currency)), currency));
|
|
40
|
+
};
|
|
41
|
+
return (_jsxs(_Fragment, { children: [input, values.length > 0 && (_jsx(Grid, { columns: "auto", tight: true, testId: `field-value-chips-${field.field}`, children: values.map((value) => {
|
|
42
|
+
const selected = value === current;
|
|
43
|
+
return (_jsxs(Button, { variant: "secondary", size: "sm", pressed: selected, disabled: field.readOnly, testId: `field-value-chip-${field.field}-${value}`, onClick: () => pick(value), children: [selected ? "✓ " : "", chipText(field, value, currency, locale)] }, value));
|
|
44
|
+
}) }))] }));
|
|
45
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
3
|
import { useTranslation } from "../i18n.js";
|
|
4
4
|
import { usePrimitives } from "../primitives.js";
|
|
5
5
|
// Wire value of a writeOnly field is `true` (set) / `null` (empty), never the
|
|
@@ -12,11 +12,19 @@ export function WriteOnlyTextInput({ field, id, hasError, onChange, changed, })
|
|
|
12
12
|
const isSet = field.value === true;
|
|
13
13
|
const isMarkedForRemoval = field.value === null && changed;
|
|
14
14
|
const [replacing, setReplacing] = useState(false);
|
|
15
|
-
//
|
|
15
|
+
// The masked row returns when a value the user produced (typed text, a pending removal) turns
|
|
16
|
+
// back into `true` (save or Undo). A plain false -> true flip, e.g. the record arriving or
|
|
17
|
+
// reloading, must not close an open Replace, so only a user-produced value arms the reset.
|
|
18
|
+
const userEdited = useRef(false);
|
|
19
|
+
const userValue = typeof field.value === "string" || isMarkedForRemoval;
|
|
16
20
|
useEffect(() => {
|
|
17
|
-
if (
|
|
21
|
+
if (userValue)
|
|
22
|
+
userEdited.current = true;
|
|
23
|
+
else if (isSet && userEdited.current) {
|
|
24
|
+
userEdited.current = false;
|
|
18
25
|
setReplacing(false);
|
|
19
|
-
|
|
26
|
+
}
|
|
27
|
+
}, [isSet, userValue]);
|
|
20
28
|
if (isSet && !replacing && !field.readOnly) {
|
|
21
29
|
return (_jsxs(Grid, { columns: "auto", children: [_jsx(Text, { testId: `field-write-only-set-${field.field}`, children: t("kumiko.field.writeOnly.maskedSet") }), _jsx(Button, { type: "button", variant: "secondary", onClick: () => setReplacing(true), testId: `field-write-only-replace-${field.field}`, children: t("kumiko.field.writeOnly.replace") })] }));
|
|
22
30
|
}
|
|
@@ -3,6 +3,8 @@ import type { ListColumnHintViewModel, ListColumnViewModel, Translate } from "..
|
|
|
3
3
|
/** The hint's tone falls back to the list's `rowToneField`. */
|
|
4
4
|
export declare function hintViewModel(hint: ListColumnHint, rowToneField: string | undefined, translate: Translate): ListColumnHintViewModel;
|
|
5
5
|
export declare function withDisplayColumns(columns: readonly ListColumnViewModel[], screen: EntityListScreenDefinition): readonly ListColumnViewModel[];
|
|
6
|
+
export declare function withPillColumns(columns: readonly ListColumnViewModel[], screen: EntityListScreenDefinition): readonly ListColumnViewModel[];
|
|
6
7
|
export declare function withEmptyPlaceholderColumns(columns: readonly ListColumnViewModel[], screen: EntityListScreenDefinition): readonly ListColumnViewModel[];
|
|
7
8
|
export declare function withNarrowOnlyColumns(columns: readonly ListColumnViewModel[], screen: EntityListScreenDefinition): readonly ListColumnViewModel[];
|
|
9
|
+
export declare function withNarrowInlineColumns(columns: readonly ListColumnViewModel[], screen: EntityListScreenDefinition): readonly ListColumnViewModel[];
|
|
8
10
|
export declare function withHintColumns(columns: readonly ListColumnViewModel[], screen: EntityListScreenDefinition, translate: Translate): readonly ListColumnViewModel[];
|
|
@@ -12,6 +12,7 @@ export function hintViewModel(hint, rowToneField, translate) {
|
|
|
12
12
|
...(hint.reasonTitleField !== undefined && { reasonTitleField: hint.reasonTitleField }),
|
|
13
13
|
...(hint.detailField !== undefined && { detailField: hint.detailField }),
|
|
14
14
|
...(hint.narrowDetailField !== undefined && { narrowDetailField: hint.narrowDetailField }),
|
|
15
|
+
...(hint.narrowField !== undefined && { narrowField: hint.narrowField }),
|
|
15
16
|
...(hint.plainSentence === true && { plainSentence: true }),
|
|
16
17
|
...(toneField !== undefined && { toneField }),
|
|
17
18
|
};
|
|
@@ -31,6 +32,19 @@ export function withDisplayColumns(columns, screen) {
|
|
|
31
32
|
};
|
|
32
33
|
});
|
|
33
34
|
}
|
|
35
|
+
export function withPillColumns(columns, screen) {
|
|
36
|
+
const specs = new Map(screen.columns.map((spec) => [normalizeListColumn(spec).field, normalizeListColumn(spec)]));
|
|
37
|
+
return columns.map((col) => {
|
|
38
|
+
const spec = specs.get(col.field);
|
|
39
|
+
if (spec?.pillField === undefined)
|
|
40
|
+
return col;
|
|
41
|
+
return {
|
|
42
|
+
...col,
|
|
43
|
+
pillField: spec.pillField,
|
|
44
|
+
...(spec.pillToneField !== undefined && { pillToneField: spec.pillToneField }),
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
}
|
|
34
48
|
export function withEmptyPlaceholderColumns(columns, screen) {
|
|
35
49
|
const blank = new Set(screen.columns.flatMap((spec) => {
|
|
36
50
|
const column = normalizeListColumn(spec);
|
|
@@ -49,6 +63,15 @@ export function withNarrowOnlyColumns(columns, screen) {
|
|
|
49
63
|
return columns;
|
|
50
64
|
return columns.map((col) => narrowOnly.has(col.field) ? { ...col, showOnNarrowOnly: true } : col);
|
|
51
65
|
}
|
|
66
|
+
export function withNarrowInlineColumns(columns, screen) {
|
|
67
|
+
const inline = new Set(screen.columns.flatMap((spec) => {
|
|
68
|
+
const column = normalizeListColumn(spec);
|
|
69
|
+
return column.narrowInline === true ? [column.field] : [];
|
|
70
|
+
}));
|
|
71
|
+
if (inline.size === 0)
|
|
72
|
+
return columns;
|
|
73
|
+
return columns.map((col) => (inline.has(col.field) ? { ...col, narrowInline: true } : col));
|
|
74
|
+
}
|
|
52
75
|
// The hint cell owns its rendering: DataTableCell ignores the column's renderer and links once a hint is set.
|
|
53
76
|
export function withHintColumns(columns, screen, translate) {
|
|
54
77
|
const hints = new Map();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EntityListScreenDefinition } from "@cosmicdrift/kumiko-framework/ui-types";
|
|
1
|
+
import type { EntityListScreenDefinition, ListToolbarActionsPlacement } from "@cosmicdrift/kumiko-framework/ui-types";
|
|
2
2
|
import type { Translate } from "../headless/index.ts";
|
|
3
3
|
import { type ActionMenuItemSpec } from "../primitives.tsx";
|
|
4
4
|
import type { ToolbarActionButton } from "./render-list-toolbar-action.tsx";
|
|
@@ -8,7 +8,7 @@ type ToolbarModelInput = {
|
|
|
8
8
|
readonly pageHeaderSlotAvailable: boolean;
|
|
9
9
|
readonly pageHeaderCompact: boolean;
|
|
10
10
|
readonly createInPageHeader: boolean;
|
|
11
|
-
readonly toolbarActionsPlacement:
|
|
11
|
+
readonly toolbarActionsPlacement: ListToolbarActionsPlacement | undefined;
|
|
12
12
|
};
|
|
13
13
|
export declare function withPlusIconFallback(action: ToolbarActionButton, actions: readonly ToolbarActionButton[]): ToolbarActionButton;
|
|
14
14
|
export type ToolbarActionSplit = {
|
|
@@ -43,6 +43,7 @@ function useFilteredSections(vm, fieldsFilter) {
|
|
|
43
43
|
// exclusion emptied it: that would leave an empty wizard step / tab.
|
|
44
44
|
() => filterEditSections(vm.sections, fieldsFilter).filter((section) => section.kind === "extension" ||
|
|
45
45
|
section.kind === "relatedList" ||
|
|
46
|
+
section.kind === "stepList" ||
|
|
46
47
|
section.kind === "writeForm" ||
|
|
47
48
|
(section.fields.length === 0 && section.emptiedByWriteExclusion !== true) ||
|
|
48
49
|
section.visible), [vm.sections, fieldsFilter]);
|
|
@@ -61,7 +62,10 @@ export function useRenderEditSections(core) {
|
|
|
61
62
|
const vm = useEditViewModel(core);
|
|
62
63
|
const filteredSections = useFilteredSections(vm, props.fields);
|
|
63
64
|
const allFieldsRequired = useAllFieldsRequired(filteredSections);
|
|
64
|
-
const showsAllRequiredHint = allFieldsRequired &&
|
|
65
|
+
const showsAllRequiredHint = allFieldsRequired &&
|
|
66
|
+
hideSectionTitles !== true &&
|
|
67
|
+
!state.isWizard &&
|
|
68
|
+
props.screen.layout.allRequiredHint !== false;
|
|
65
69
|
// true when editable fields exist or an extension opted into composed submit.
|
|
66
70
|
const isFormEditable = hasEditableSection(filteredSections);
|
|
67
71
|
// A fieldless form (input-less secretMint mint — the secret is
|
|
@@ -2,7 +2,7 @@ import { normalizeListColumn } from "@cosmicdrift/kumiko-framework/ui-types";
|
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { useReferenceLinkResolver, useScreenLinkResolver, } from "../app/reference-link.js";
|
|
4
4
|
import { computeListViewModel } from "../headless/index.js";
|
|
5
|
-
import { withDisplayColumns, withEmptyPlaceholderColumns, withHintColumns, withNarrowOnlyColumns, } from "./render-list-hint-columns.js";
|
|
5
|
+
import { withDisplayColumns, withEmptyPlaceholderColumns, withHintColumns, withNarrowInlineColumns, withNarrowOnlyColumns, withPillColumns, } from "./render-list-hint-columns.js";
|
|
6
6
|
import { enrichReferenceColumns, selectReferenceColumns } from "./render-list-reference-columns.js";
|
|
7
7
|
import { useReferenceColumnLookups } from "./use-reference-column-lookups.js";
|
|
8
8
|
/** Cell link to the screen a row names in `screenField`, parametrized by the row's `paramsField` object. */
|
|
@@ -52,7 +52,7 @@ export function useRenderListColumns(input) {
|
|
|
52
52
|
const { referenceRequests, handleLookupMap, referenceLookups } = useReferenceColumnLookups(rows, referenceColumns);
|
|
53
53
|
const resolveReferenceLink = useReferenceLinkResolver();
|
|
54
54
|
const resolveScreenLink = useScreenLinkResolver();
|
|
55
|
-
const enrichedColumns = useMemo(() => withNarrowOnlyColumns(withDisplayColumns(withHintColumns(withScreenLinks(enrichReferenceColumns({
|
|
55
|
+
const enrichedColumns = useMemo(() => withNarrowOnlyColumns(withNarrowInlineColumns(withPillColumns(withDisplayColumns(withHintColumns(withScreenLinks(enrichReferenceColumns({
|
|
56
56
|
// Flag first: the reference renderer reads it while it is built.
|
|
57
57
|
columns: withEmptyPlaceholderColumns(vm.columns, screen),
|
|
58
58
|
referenceColumns,
|
|
@@ -60,7 +60,7 @@ export function useRenderListColumns(input) {
|
|
|
60
60
|
resolveReferenceLink,
|
|
61
61
|
featureName,
|
|
62
62
|
translate,
|
|
63
|
-
}), screen, resolveScreenLink), screen, translate), screen), screen), [
|
|
63
|
+
}), screen, resolveScreenLink), screen, translate), screen), screen), screen), screen), [
|
|
64
64
|
vm.columns,
|
|
65
65
|
referenceColumns,
|
|
66
66
|
referenceLookups,
|
|
@@ -10,5 +10,5 @@ export declare function ScreenFocusProvider({ children }: {
|
|
|
10
10
|
readonly children: ReactNode;
|
|
11
11
|
}): ReactNode;
|
|
12
12
|
export declare function useScreenFocus(): ScreenFocus | null;
|
|
13
|
-
/** Reports the focus while the calling screen is mounted; compared by value, cleared on unmount. */
|
|
13
|
+
/** Reports the focus while the calling screen is mounted; compared by value, cleared on unmount unless another screen has reported since. */
|
|
14
14
|
export declare function useSetScreenFocus(focus: ScreenFocus | null): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useContext, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { createContext, useContext, useEffect, useRef, useState, } from "react";
|
|
3
3
|
const ScreenFocusContext = createContext(null);
|
|
4
4
|
const noopSetScreenFocus = () => { };
|
|
5
5
|
const SetScreenFocusContext = createContext(noopSetScreenFocus);
|
|
@@ -10,7 +10,7 @@ export function ScreenFocusProvider({ children }) {
|
|
|
10
10
|
export function useScreenFocus() {
|
|
11
11
|
return useContext(ScreenFocusContext);
|
|
12
12
|
}
|
|
13
|
-
/** Reports the focus while the calling screen is mounted; compared by value, cleared on unmount. */
|
|
13
|
+
/** Reports the focus while the calling screen is mounted; compared by value, cleared on unmount unless another screen has reported since. */
|
|
14
14
|
export function useSetScreenFocus(focus) {
|
|
15
15
|
const setFocus = useContext(SetScreenFocusContext);
|
|
16
16
|
const key = focus === null ? null : JSON.stringify(focus);
|
|
@@ -23,6 +23,6 @@ export function useSetScreenFocus(focus) {
|
|
|
23
23
|
const stableFocus = lastReported.current.focus;
|
|
24
24
|
useEffect(() => {
|
|
25
25
|
setFocus(stableFocus);
|
|
26
|
-
return () => setFocus(null);
|
|
26
|
+
return () => setFocus((current) => (current === stableFocus ? null : current));
|
|
27
27
|
}, [setFocus, stableFocus]);
|
|
28
28
|
}
|
|
@@ -18,6 +18,8 @@ export type DataTableFacet = {
|
|
|
18
18
|
readonly showCounts?: boolean;
|
|
19
19
|
/** Chips only: hide chips whose `count` is 0 (unless pressed). */
|
|
20
20
|
readonly hideEmpty?: boolean;
|
|
21
|
+
/** Below `sm` the facet opens behind the filter icon next to the search field instead of standing as a pill. */
|
|
22
|
+
readonly narrowPlacement?: "behind-filter";
|
|
21
23
|
/** Present: the options come from a server-side search (reference facets), so the dropdown
|
|
22
24
|
* shows a search field and reports the typed term instead of filtering `options` itself. */
|
|
23
25
|
readonly onSearchChange?: (query: string) => void;
|
|
@@ -30,6 +32,8 @@ export type DataTableFacetChip = {
|
|
|
30
32
|
readonly label: string;
|
|
31
33
|
/** Selection a click sets; `[]` clears the facet. */
|
|
32
34
|
readonly values: readonly string[];
|
|
35
|
+
/** Select display: a divider line follows this chip. */
|
|
36
|
+
readonly separatorAfter?: boolean;
|
|
33
37
|
/** Matching row count, undefined while unknown. */
|
|
34
38
|
readonly count?: number;
|
|
35
39
|
};
|
|
@@ -7,6 +7,7 @@ export { DOCUMENT_FALLBACK_CURRENCY, type DocumentDateOptions, formatDocumentDat
|
|
|
7
7
|
export { escapeHtml, escapeHtmlAttr, escapeXml, isSafeHref, stripControlChars } from "./escape.ts";
|
|
8
8
|
export { type HtmlValue, html, RawHtml, raw } from "./html-template.ts";
|
|
9
9
|
export { currencyDecimals, formatMoney, resolveSafeMoneyLocale } from "./money.ts";
|
|
10
|
+
export { telHref } from "./phone.ts";
|
|
10
11
|
export declare function applyFormatSpec(spec: {
|
|
11
12
|
format: string;
|
|
12
13
|
} & Record<string, unknown>, value: unknown, translate?: (key: string, params?: Readonly<Record<string, string | number>>) => string): string;
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
4
4
|
import { isOneOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
5
5
|
import { rendererWarn } from "../../dev-console.js";
|
|
6
|
+
import { serverNowMs } from "../../server-clock.js";
|
|
7
|
+
import { formatRelativeTime } from "./relative-time.js";
|
|
6
8
|
export const EMPTY_VALUE_PLACEHOLDER = "—";
|
|
7
9
|
function toPlainDate(raw) {
|
|
8
10
|
try {
|
|
@@ -133,6 +135,7 @@ export { DOCUMENT_FALLBACK_CURRENCY, formatDocumentDate, formatDocumentMoney, fo
|
|
|
133
135
|
export { escapeHtml, escapeHtmlAttr, escapeXml, isSafeHref, stripControlChars } from "./escape.js";
|
|
134
136
|
export { html, RawHtml, raw } from "./html-template.js";
|
|
135
137
|
export { currencyDecimals, formatMoney, resolveSafeMoneyLocale } from "./money.js";
|
|
138
|
+
export { telHref } from "./phone.js";
|
|
136
139
|
// JSON.stringify throws on BigInt and circular values; a cell must degrade to text instead of crashing the screen.
|
|
137
140
|
function stringifyJsonOrString(value, indent) {
|
|
138
141
|
try {
|
|
@@ -276,6 +279,21 @@ function formatFileCell(_spec, value) {
|
|
|
276
279
|
function formatJsonCell(spec, value) {
|
|
277
280
|
return stringifyJsonOrString(value, typeof spec["indent"] === "number" ? spec["indent"] : 2);
|
|
278
281
|
}
|
|
282
|
+
const RELATIVE_TIME_STYLES = ["long", "short", "narrow"];
|
|
283
|
+
function formatRelativeTimeCell(spec, value) {
|
|
284
|
+
const atMs = typeof value === "number" ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
|
|
285
|
+
if (!Number.isFinite(atMs))
|
|
286
|
+
return String(value);
|
|
287
|
+
const style = spec["style"];
|
|
288
|
+
const absoluteAfterDays = spec["absoluteAfterDays"];
|
|
289
|
+
const timeZone = stringSpec(spec, "timeZone");
|
|
290
|
+
return formatRelativeTime(atMs, serverNowMs(), stringSpec(spec, "locale"), {
|
|
291
|
+
...(isOneOf(RELATIVE_TIME_STYLES, style) && { style }),
|
|
292
|
+
...(typeof absoluteAfterDays === "number" && { absoluteAfterDays }),
|
|
293
|
+
...(spec["withTime"] === true && { withTime: true }),
|
|
294
|
+
...(timeZone !== undefined && { timeZone }),
|
|
295
|
+
});
|
|
296
|
+
}
|
|
279
297
|
const CELL_FORMATTERS = {
|
|
280
298
|
timestamp: formatTemporalCell,
|
|
281
299
|
date: formatTemporalCell,
|
|
@@ -287,7 +305,9 @@ const CELL_FORMATTERS = {
|
|
|
287
305
|
unit: formatUnitSpecCell,
|
|
288
306
|
priority: formatPriorityCell,
|
|
289
307
|
enumOption: formatEnumOptionCell,
|
|
308
|
+
relativeTime: formatRelativeTimeCell,
|
|
290
309
|
i18nText: formatI18nTextCell,
|
|
310
|
+
phone: (_spec, value) => String(value).trim(),
|
|
291
311
|
image: formatFileCell,
|
|
292
312
|
file: formatFileCell,
|
|
293
313
|
json: formatJsonCell,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function telHref(value: string): string | undefined;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Only digits and a leading "+" survive into the tel: href, so a stored
|
|
2
|
+
// "+49 (30) 123-45" dials but can never smuggle other URI parts.
|
|
3
|
+
export function telHref(value) {
|
|
4
|
+
const digits = value.replace(/[^\d]/g, "");
|
|
5
|
+
if (digits === "")
|
|
6
|
+
return undefined;
|
|
7
|
+
return `tel:${value.trim().startsWith("+") ? "+" : ""}${digits}`;
|
|
8
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type RelativeTimeOptions = {
|
|
2
|
+
readonly style?: Intl.RelativeTimeFormatStyle;
|
|
3
|
+
readonly absoluteAfterDays?: number;
|
|
4
|
+
readonly withTime?: boolean;
|
|
5
|
+
readonly timeZone?: string;
|
|
6
|
+
};
|
|
7
|
+
/** "5 minutes ago" / "in 30 seconds" in the given locale. The unit grows with the
|
|
8
|
+
* distance (seconds below a minute, minutes below an hour, hours below a day);
|
|
9
|
+
* each step is chosen on the already rounded value so 59.6 minutes reads "1 hour"
|
|
10
|
+
* instead of "60 minutes". From a day on, the distance counts calendar days in
|
|
11
|
+
* `options.timeZone` (default: the runtime's zone), so "yesterday" means the day
|
|
12
|
+
* before today and not 24 hours ago. `numeric: "auto"` yields "now" and "yesterday". */
|
|
13
|
+
export declare function formatRelativeTime(atMs: number, nowMs: number, locale: string | undefined, options?: RelativeTimeOptions): string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { resolveSafeLocale } from "./safe-locale.js";
|
|
2
|
+
const SECONDS_PER_MINUTE = 60;
|
|
3
|
+
const MINUTES_PER_HOUR = 60;
|
|
4
|
+
const HOURS_PER_DAY = 24;
|
|
5
|
+
const MS_PER_DAY = 86_400_000;
|
|
6
|
+
function formatAbsolute(atMs, locale, options) {
|
|
7
|
+
return new Intl.DateTimeFormat(locale, {
|
|
8
|
+
day: "numeric",
|
|
9
|
+
month: "short",
|
|
10
|
+
year: "numeric",
|
|
11
|
+
...(options.withTime === true && { hour: "2-digit", minute: "2-digit" }),
|
|
12
|
+
timeZone: options.timeZone,
|
|
13
|
+
}).format(atMs);
|
|
14
|
+
}
|
|
15
|
+
function formatClock(atMs, locale, timeZone) {
|
|
16
|
+
return new Intl.DateTimeFormat(locale, { timeStyle: "short", timeZone }).format(atMs);
|
|
17
|
+
}
|
|
18
|
+
function calendarDayNumber(ms, timeZone) {
|
|
19
|
+
const parts = new Intl.DateTimeFormat("en-US", {
|
|
20
|
+
year: "numeric",
|
|
21
|
+
month: "numeric",
|
|
22
|
+
day: "numeric",
|
|
23
|
+
timeZone,
|
|
24
|
+
}).formatToParts(ms);
|
|
25
|
+
const part = (type) => Number(parts.find((p) => p.type === type)?.value);
|
|
26
|
+
return Date.UTC(part("year"), part("month") - 1, part("day")) / MS_PER_DAY;
|
|
27
|
+
}
|
|
28
|
+
/** "5 minutes ago" / "in 30 seconds" in the given locale. The unit grows with the
|
|
29
|
+
* distance (seconds below a minute, minutes below an hour, hours below a day);
|
|
30
|
+
* each step is chosen on the already rounded value so 59.6 minutes reads "1 hour"
|
|
31
|
+
* instead of "60 minutes". From a day on, the distance counts calendar days in
|
|
32
|
+
* `options.timeZone` (default: the runtime's zone), so "yesterday" means the day
|
|
33
|
+
* before today and not 24 hours ago. `numeric: "auto"` yields "now" and "yesterday". */
|
|
34
|
+
export function formatRelativeTime(atMs, nowMs, locale, options = {}) {
|
|
35
|
+
const safeLocale = resolveSafeLocale(locale);
|
|
36
|
+
const formatter = new Intl.RelativeTimeFormat(safeLocale, {
|
|
37
|
+
numeric: "auto",
|
|
38
|
+
style: options.style ?? "long",
|
|
39
|
+
});
|
|
40
|
+
const seconds = Math.round((atMs - nowMs) / 1000);
|
|
41
|
+
if (Math.abs(seconds) < SECONDS_PER_MINUTE)
|
|
42
|
+
return formatter.format(seconds, "second");
|
|
43
|
+
const minutes = Math.round(seconds / SECONDS_PER_MINUTE);
|
|
44
|
+
if (Math.abs(minutes) < MINUTES_PER_HOUR)
|
|
45
|
+
return formatter.format(minutes, "minute");
|
|
46
|
+
const hours = Math.round(minutes / MINUTES_PER_HOUR);
|
|
47
|
+
if (Math.abs(hours) < HOURS_PER_DAY)
|
|
48
|
+
return formatter.format(hours, "hour");
|
|
49
|
+
const days = calendarDayNumber(atMs, options.timeZone) - calendarDayNumber(nowMs, options.timeZone);
|
|
50
|
+
// 23.5+ hours inside one calendar day still reads as hours, never as "today".
|
|
51
|
+
if (days === 0)
|
|
52
|
+
return formatter.format(hours, "hour");
|
|
53
|
+
if (options.absoluteAfterDays !== undefined && Math.abs(days) >= options.absoluteAfterDays) {
|
|
54
|
+
return formatAbsolute(atMs, safeLocale, options);
|
|
55
|
+
}
|
|
56
|
+
const relative = formatter.format(days, "day");
|
|
57
|
+
return days === -1 && options.withTime === true
|
|
58
|
+
? `${relative}, ${formatClock(atMs, safeLocale, options.timeZone)}`
|
|
59
|
+
: relative;
|
|
60
|
+
}
|