@cosmicdrift/kumiko-renderer 0.417.0 → 0.419.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.
Files changed (53) hide show
  1. package/dist/app/action-form-body.js +5 -1
  2. package/dist/app/action-form-preview.d.ts +13 -0
  3. package/dist/app/action-form-preview.js +66 -0
  4. package/dist/app/action-form-support.d.ts +6 -1
  5. package/dist/app/action-form-support.js +26 -9
  6. package/dist/app/list-bulk-actions.d.ts +8 -1
  7. package/dist/app/list-bulk-actions.js +28 -4
  8. package/dist/components/embedded-list-paste.js +2 -2
  9. package/dist/components/multi-select-chips.js +5 -1
  10. package/dist/components/multi-select-count.d.ts +5 -0
  11. package/dist/components/multi-select-count.js +10 -0
  12. package/dist/components/render-edit-layout.js +2 -2
  13. package/dist/components/render-edit-types.d.ts +2 -0
  14. package/dist/components/render-field-ai-assist.js +23 -5
  15. package/dist/components/render-field-choice-inputs.js +3 -0
  16. package/dist/components/render-field-value-chips.js +2 -2
  17. package/dist/components/render-field-values.js +3 -3
  18. package/dist/data-table-bulk-types.d.ts +11 -2
  19. package/dist/data-table-bulk-types.js +3 -1
  20. package/dist/headless/form/form-controller.d.ts +1 -0
  21. package/dist/headless/form/form-controller.js +1 -1
  22. package/dist/headless/format/index.d.ts +1 -1
  23. package/dist/headless/format/index.js +1 -1
  24. package/dist/headless/format/money.d.ts +5 -0
  25. package/dist/headless/format/money.js +10 -0
  26. package/dist/headless/index.d.ts +1 -1
  27. package/dist/headless/index.js +1 -1
  28. package/dist/headless/view-model/types.d.ts +1 -1
  29. package/dist/hooks/use-bulk-run.d.ts +2 -2
  30. package/dist/i18n-defaults.js +1 -0
  31. package/dist/primitives.d.ts +4 -0
  32. package/dist/web/editor/editor-rail.js +1 -1
  33. package/dist/web/editor/editor-toolbar-pill.d.ts +4 -0
  34. package/dist/web/editor/editor-toolbar-pill.js +5 -0
  35. package/dist/web/editor/index.d.ts +1 -0
  36. package/dist/web/editor/index.js +1 -0
  37. package/dist/web/index.d.ts +1 -1
  38. package/dist/web/index.js +1 -1
  39. package/dist/web/layout/nav-tree.js +1 -1
  40. package/dist/web/layout/notification-bell.js +2 -2
  41. package/dist/web/layout/shell-header.js +2 -2
  42. package/dist/web/primitives/action-menu.d.ts +2 -0
  43. package/dist/web/primitives/action-menu.js +1 -1
  44. package/dist/web/primitives/data-table/use-bulk-selection.d.ts +1 -1
  45. package/dist/web/primitives/data-table/use-bulk-selection.js +5 -0
  46. package/dist/web/primitives/data-table-cell.js +2 -10
  47. package/dist/web/primitives/metric.js +4 -5
  48. package/dist/web/primitives/modal.d.ts +1 -1
  49. package/dist/web/primitives/modal.js +2 -2
  50. package/dist/web/primitives/row-actions.d.ts +1 -1
  51. package/dist/web/primitives/row-actions.js +3 -3
  52. package/dist/web/pwa/pwa-support.js +13 -7
  53. package/package.json +5 -5
@@ -12,6 +12,7 @@ import { PageHeaderSlotAvailableProvider } from "../page-header-slot.js";
12
12
  import { usePrimitives } from "../primitives.js";
13
13
  import { screenFillsHeight } from "../screen-fills-height.js";
14
14
  import { statusToneForOptionTone } from "../status-tone.js";
15
+ import { ActionFormPreviewPanel } from "./action-form-preview.js";
15
16
  import { actionFormSubmittableFields, synthesizeActionFormEntity, synthesizeActionFormScreen, } from "./action-form-shim.js";
16
17
  import { ActionFormLoadStatus, ActionFormSuccessBanner, DEFAULT_LOAD_ID_PARAM, isSecretFormField, resolveActionFormRecordId, resolveSuccessFacts, useActionFormLoad, } from "./action-form-support.js";
17
18
  import { useAppFeatures } from "./app-features-context.js";
@@ -303,6 +304,7 @@ export function ActionFormBody({ schema, screen, translate, entityId, initialOve
303
304
  if (loadState !== undefined && loadState.status !== "ready") {
304
305
  return (_jsx(ActionFormLoadStatus, { state: loadState, screenId: screen.id, translate: effectiveTranslate }));
305
306
  }
307
+ const { preview } = screen;
306
308
  return (_jsx(AiAssistPayloadProvider, { value: aiAssistPayload, children: _jsx(RenderEdit, { screen: synthScreen, entity: synthEntity, featureName: schema.featureName, initial: derivedInitial, ...(screen.derive !== undefined && { formDerivation: screen }), actionFormScreenQn: qualifyScreenId(schema.featureName, screen.id),
307
309
  // Extension sections in the actionForm see the initial form values
308
310
  // (incl. searchParams prefill, e.g. ?incidentId=...) as initialValues;
@@ -329,5 +331,7 @@ export function ActionFormBody({ schema, screen, translate, entityId, initialOve
329
331
  const { text, complete } = resolveFieldText(ref, values, effectiveTranslate);
330
332
  return complete ? text : undefined;
331
333
  },
332
- }), ...(summary !== undefined && { summary }), ...(translate !== undefined && { translate }) }, formEpoch) }));
334
+ }), ...(summary !== undefined && { summary }), ...(preview !== undefined && {
335
+ belowSections: (values) => (_jsx(ActionFormPreviewPanel, { preview: preview, fields: screen.fields, values: values, translate: effectiveTranslate, locale: locale })),
336
+ }), ...(translate !== undefined && { translate }) }, formEpoch) }));
333
337
  }
@@ -0,0 +1,13 @@
1
+ import type { ActionFormPreview } from "@cosmicdrift/kumiko-framework/ui-types";
2
+ import { type ReactNode } from "react";
3
+ import type { Translate } from "../headless/index.ts";
4
+ type FormValueMap = Readonly<Record<string, unknown>>;
5
+ /** Shows what the submit would do, from a query over the live form values. A failed query is a hint only. */
6
+ export declare function ActionFormPreviewPanel({ preview, fields, values, translate, locale, }: {
7
+ readonly preview: ActionFormPreview;
8
+ readonly fields: Readonly<Record<string, unknown>>;
9
+ readonly values: FormValueMap;
10
+ readonly translate: Translate;
11
+ readonly locale: string;
12
+ }): ReactNode;
13
+ export {};
@@ -0,0 +1,66 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { isPlainObject, propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
3
+ import { useMemo } from "react";
4
+ import { isCurrencyOnlyMoney } from "../headless/form/form-controller.js";
5
+ import { REFERENCE_SEARCH_DEBOUNCE_MS } from "../hooks/reference-limits.js";
6
+ import { useDebouncedValue } from "../hooks/use-debounced-value.js";
7
+ import { useQuery } from "../hooks/use-query.js";
8
+ import { usePrimitives } from "../primitives.js";
9
+ import { ActionFormFacts, resolveSuccessFacts } from "./action-form-support.js";
10
+ import { QueryLoadingBanner } from "./query-state-banners.js";
11
+ import { dispatcherErrorText } from "./write-failed-error.js";
12
+ function isEmptyValue(value) {
13
+ return (value === undefined ||
14
+ value === null ||
15
+ value === "" ||
16
+ (Array.isArray(value) && value.length === 0) ||
17
+ isCurrencyOnlyMoney(value));
18
+ }
19
+ /** Empty optional fields stay out: an untouched date input holds "", which a query schema rejects instead of reading it as absent. */
20
+ function pickPayload(values, fieldNames) {
21
+ const payload = {};
22
+ for (const name of fieldNames) {
23
+ if (Object.hasOwn(values, name) && !isEmptyValue(values[name]))
24
+ payload[name] = values[name];
25
+ }
26
+ return payload;
27
+ }
28
+ /** Required fields of the payload that are still empty: the query would only answer a validation error. */
29
+ function missingRequired(payload, fieldNames, fields) {
30
+ return fieldNames.some((name) => propertyOf(fields[name], "required") === true && isEmptyValue(payload[name]));
31
+ }
32
+ function parsePayload(serialized) {
33
+ const parsed = JSON.parse(serialized);
34
+ return isPlainObject(parsed) ? parsed : {};
35
+ }
36
+ function previewRows(data, listField) {
37
+ const entries = propertyOf(data, listField);
38
+ if (!Array.isArray(entries))
39
+ return [];
40
+ return entries.flatMap((entry, index) => isPlainObject(entry) ? [{ id: String(index), values: entry }] : []);
41
+ }
42
+ /** Shows what the submit would do, from a query over the live form values. A failed query is a hint only. */
43
+ export function ActionFormPreviewPanel({ preview, fields, values, translate, locale, }) {
44
+ const { Banner, DataTable, Grid } = usePrimitives();
45
+ const fieldNames = useMemo(() => preview.fields ?? Object.keys(fields), [preview.fields, fields]);
46
+ const serialized = useDebouncedValue(JSON.stringify(pickPayload(values, fieldNames)), REFERENCE_SEARCH_DEBOUNCE_MS);
47
+ const payload = useMemo(() => parsePayload(serialized), [serialized]);
48
+ const incomplete = missingRequired(payload, fieldNames, fields);
49
+ const query = useQuery(preview.query, payload, { enabled: !incomplete });
50
+ const facts = useMemo(() => resolveSuccessFacts(preview.facts, query.data, translate, locale), [preview.facts, query.data, translate, locale]);
51
+ const columns = useMemo(() => (preview.list?.columns ?? []).map((column) => ({
52
+ field: column.field,
53
+ label: translate(column.label),
54
+ type: column.type ?? "text",
55
+ sortable: false,
56
+ })), [preview.list, translate]);
57
+ const rows = useMemo(() => (preview.list === undefined ? [] : previewRows(query.data, preview.list.field)), [preview.list, query.data]);
58
+ if (incomplete)
59
+ return null;
60
+ if (query.error !== null) {
61
+ return (_jsx(Banner, { variant: "warning", testId: "action-form-preview-error", children: dispatcherErrorText(query.error, translate) }));
62
+ }
63
+ if (query.data === null)
64
+ return query.loading ? _jsx(QueryLoadingBanner, {}) : null;
65
+ return (_jsx(Banner, { variant: "hint", testId: "action-form-preview", ...(preview.title !== undefined && { title: translate(preview.title) }), children: _jsxs(Grid, { columns: 1, children: [_jsx(ActionFormFacts, { facts: facts, testIdPrefix: "action-form-preview-fact" }), preview.list !== undefined && _jsx(DataTable, { columns: columns, rows: rows })] }) }));
66
+ }
@@ -1,6 +1,6 @@
1
1
  import type { ActionFormLoad, ActionFormSuccessFact } from "@cosmicdrift/kumiko-framework/ui-types";
2
2
  import { type ReactNode } from "react";
3
- import type { DispatcherError, Translate } from "../headless/index.ts";
3
+ import { type DispatcherError, type Translate } from "../headless/index.ts";
4
4
  export declare const DEFAULT_LOAD_ID_PARAM = "id";
5
5
  /** Record id of a `load` form: the route path id, else the drawer prefill `id`
6
6
  * (the clicked row), else the URL `id` param. Only the id is read from these
@@ -64,6 +64,11 @@ export type ActionFormSuccessState = {
64
64
  readonly items?: readonly ResolvedSuccessItem[];
65
65
  };
66
66
  export declare function resolveSuccessFacts(facts: readonly ActionFormSuccessFact[] | undefined, data: unknown, translate: (key: string) => string, locale: string): readonly ResolvedSuccessFact[];
67
+ /** One line per fact, a list of values as a block; shared by the success box and the preview panel. */
68
+ export declare function ActionFormFacts({ testIdPrefix, facts, }: {
69
+ readonly facts: readonly ResolvedSuccessFact[];
70
+ readonly testIdPrefix?: string;
71
+ }): ReactNode;
67
72
  export declare function ActionFormSuccessBanner({ success, }: {
68
73
  readonly success: ActionFormSuccessState;
69
74
  }): ReactNode;
@@ -1,8 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
3
3
  import { useMemo } from "react";
4
+ import { applyFormatSpec, formatMoneyValue, } from "../headless/index.js";
4
5
  import { useQuery } from "../hooks/use-query.js";
5
6
  import { usePrimitives } from "../primitives.js";
7
+ import { isMoneyValue } from "./entity-edit-prefill.js";
6
8
  import { QueryLoadingBanner } from "./query-state-banners.js";
7
9
  import { dispatcherErrorText } from "./write-failed-error.js";
8
10
  export const DEFAULT_LOAD_ID_PARAM = "id";
@@ -37,9 +39,10 @@ function pickDeclaredFields(record, fieldNames) {
37
39
  }
38
40
  return picked;
39
41
  }
42
+ const NO_FIELDS = [];
40
43
  /** Loads the initial values of an actionForm declaring `load`; undefined for a
41
44
  * form without `load`. */
42
- export function useActionFormLoad(load, recordId, fieldNames, summaryFieldNames = [], prefill) {
45
+ export function useActionFormLoad(load, recordId, fieldNames, summaryFieldNames = NO_FIELDS, prefill) {
43
46
  const isSingleton = load?.singleton === true;
44
47
  const query = useQuery(load?.query ?? "", {
45
48
  ...(load?.passPrefill === true && prefill),
@@ -77,6 +80,15 @@ export function ActionFormLoadStatus({ state, screenId, translate, }) {
77
80
  }
78
81
  }
79
82
  }
83
+ function formatTypedFact(entry, type, locale) {
84
+ if (type === "money" && isMoneyValue(entry)) {
85
+ return formatMoneyValue(entry, locale);
86
+ }
87
+ if ((type === "date" || type === "timestamp") && typeof entry === "string") {
88
+ return applyFormatSpec({ format: type, locale }, entry);
89
+ }
90
+ return undefined;
91
+ }
80
92
  function factLine(entry, locale) {
81
93
  if (typeof entry === "number")
82
94
  return entry.toLocaleString(locale);
@@ -92,7 +104,7 @@ export function resolveSuccessFacts(facts, data, translate, locale) {
92
104
  (facts ?? []).forEach((fact, index) => {
93
105
  const value = propertyOf(data, fact.field);
94
106
  const entries = Array.isArray(value) ? value : [value];
95
- const lines = entries.flatMap((entry) => factLine(entry, locale) ?? []);
107
+ const lines = entries.flatMap((entry) => formatTypedFact(entry, fact.type, locale) ?? factLine(entry, locale) ?? []);
96
108
  if (lines.length > 0) {
97
109
  resolved.push({ key: String(index), label: translate(fact.label), lines });
98
110
  }
@@ -109,6 +121,17 @@ function SuccessItemHints({ items, }) {
109
121
  actions: (_jsx(Link, { href: item.link.href, onPress: item.link.onPress, className: "underline", testId: `action-form-success-item-${item.key}-link`, children: item.link.label })),
110
122
  }), children: _jsx(Text, { children: item.label }) }, item.key))) }));
111
123
  }
124
+ /** One line per fact, a list of values as a block; shared by the success box and the preview panel. */
125
+ export function ActionFormFacts({ testIdPrefix = "action-form-success-fact", facts, }) {
126
+ const { Grid, Text } = usePrimitives();
127
+ return facts.map((fact) => {
128
+ const factTestId = `${testIdPrefix}-${fact.key}`;
129
+ if (fact.lines.length === 1) {
130
+ return (_jsxs(Text, { testId: factTestId, children: [fact.label, ": ", fact.lines[0]] }, fact.key));
131
+ }
132
+ return (_jsxs(Grid, { columns: 1, testId: factTestId, children: [_jsxs(Text, { children: [fact.label, ":"] }), positionedLines(fact.lines).map(({ position, line }) => (_jsx(Text, { testId: `${factTestId}-line-${position}`, children: line }, position)))] }, fact.key));
133
+ });
134
+ }
112
135
  export function ActionFormSuccessBanner({ success, }) {
113
136
  const { Banner, Grid, Link, Text } = usePrimitives();
114
137
  const items = success.items ?? [];
@@ -116,13 +139,7 @@ export function ActionFormSuccessBanner({ success, }) {
116
139
  if (items.length > 0 && !hasFactsOrLinks)
117
140
  return _jsx(SuccessItemHints, { items: items });
118
141
  // Text renders inline, so the message and each fact sit in a one-column grid to get their own lines.
119
- const banner = (_jsxs(Banner, { variant: "info", testId: "action-form-success", children: [_jsxs(Grid, { columns: 1, children: [items.length === 0 && _jsx(Text, { testId: "action-form-success-text", children: success.text }), success.facts.map((fact) => {
120
- const factTestId = `action-form-success-fact-${fact.key}`;
121
- if (fact.lines.length === 1) {
122
- return (_jsxs(Text, { testId: factTestId, children: [fact.label, ": ", fact.lines[0]] }, fact.key));
123
- }
124
- return (_jsxs(Grid, { columns: 1, testId: factTestId, children: [_jsxs(Text, { children: [fact.label, ":"] }), positionedLines(fact.lines).map(({ position, line }) => (_jsx(Text, { testId: `${factTestId}-line-${position}`, children: line }, position)))] }, fact.key));
125
- })] }), success.links.map((link) => (_jsx(Link, { href: link.href, onPress: link.onPress, className: "ml-2 underline", testId: `action-form-success-link-${link.key}`, children: link.label }, link.key)))] }));
142
+ const banner = (_jsxs(Banner, { variant: "info", testId: "action-form-success", children: [_jsxs(Grid, { columns: 1, children: [items.length === 0 && _jsx(Text, { testId: "action-form-success-text", children: success.text }), _jsx(ActionFormFacts, { facts: success.facts })] }), success.links.map((link) => (_jsx(Link, { href: link.href, onPress: link.onPress, className: "ml-2 underline", testId: `action-form-success-link-${link.key}`, children: link.label }, link.key)))] }));
126
143
  if (items.length === 0)
127
144
  return banner;
128
145
  return (_jsxs(Grid, { columns: 1, children: [_jsx(SuccessItemHints, { items: items }), banner] }));
@@ -1,12 +1,18 @@
1
1
  import type { ListBulkAction, RowAction } from "@cosmicdrift/kumiko-framework/ui-types";
2
2
  import type { DataTableBulk, DataTableBulkAction } from "../data-table-bulk-types.ts";
3
3
  import type { Dispatcher, Translate } from "../headless/index.ts";
4
- /** Resolves each bulk action against its writeHandler row action; one that resolves to nothing is dropped. */
4
+ type BulkFormAction = Extract<ListBulkAction, {
5
+ readonly screen: string;
6
+ }>;
7
+ /** Opens the form of a bulk form action with the ids of the selected rows. */
8
+ export type OpenBulkForm = (action: BulkFormAction, ids: readonly string[]) => void;
9
+ /** Resolves each bulk action against its writeHandler row action; one that resolves to nothing is dropped. Form actions need `openBulkForm`. */
5
10
  export declare function buildListBulkActions(options: {
6
11
  readonly bulkActions: readonly ListBulkAction[];
7
12
  readonly rowActions: readonly RowAction[] | undefined;
8
13
  readonly translate: Translate;
9
14
  readonly dispatcher: Dispatcher;
15
+ readonly openBulkForm?: OpenBulkForm;
10
16
  }): readonly DataTableBulkAction[];
11
17
  /** DataTable `bulk` prop of a list screen; undefined without bulk actions or dispatcher. */
12
18
  export declare function useListBulk(options: {
@@ -16,3 +22,4 @@ export declare function useListBulk(options: {
16
22
  readonly dispatcher: Dispatcher | undefined;
17
23
  readonly reload: () => Promise<unknown>;
18
24
  }): DataTableBulk | undefined;
25
+ export {};
@@ -1,11 +1,24 @@
1
1
  import { evalFieldCondition } from "@cosmicdrift/kumiko-framework/ui-types";
2
2
  import { resolveActionIcon } from "@cosmicdrift/kumiko-types/action-icon";
3
3
  import { useMemo } from "react";
4
+ import { useNavigateWithInitialValues } from "./nav.js";
5
+ import { lastSegment } from "./qn.js";
4
6
  import { isWriteHandlerRowAction, refetchAfterWrite, writeRowAction } from "./row-actions.js";
5
7
  import { dispatcherErrorText } from "./write-failed-error.js";
8
+ function isBulkFormDeclaration(bulk) {
9
+ return "screen" in bulk;
10
+ }
6
11
  function asksForConfirm(bulk, rowAction) {
7
12
  return (bulk.confirm !== undefined || rowAction.confirm !== undefined || rowAction.style === "danger");
8
13
  }
14
+ function buildBulkFormAction(bulk, translate, openBulkForm) {
15
+ return {
16
+ id: bulk.id,
17
+ label: translate(bulk.label),
18
+ ...(bulk.icon !== undefined && { icon: bulk.icon }),
19
+ openForm: (rows) => openBulkForm(bulk, rows.map((row) => row.id)),
20
+ };
21
+ }
9
22
  function buildBulkAction(bulk, rowAction, translate, dispatcher) {
10
23
  const label = translate(rowAction.label);
11
24
  const visible = rowAction.visible;
@@ -30,10 +43,13 @@ function buildBulkAction(bulk, rowAction, translate, dispatcher) {
30
43
  },
31
44
  };
32
45
  }
33
- /** Resolves each bulk action against its writeHandler row action; one that resolves to nothing is dropped. */
46
+ /** Resolves each bulk action against its writeHandler row action; one that resolves to nothing is dropped. Form actions need `openBulkForm`. */
34
47
  export function buildListBulkActions(options) {
35
- const { bulkActions, rowActions, translate, dispatcher } = options;
48
+ const { bulkActions, rowActions, translate, dispatcher, openBulkForm } = options;
36
49
  return bulkActions.flatMap((bulk) => {
50
+ if (isBulkFormDeclaration(bulk)) {
51
+ return openBulkForm === undefined ? [] : [buildBulkFormAction(bulk, translate, openBulkForm)];
52
+ }
37
53
  const rowAction = rowActions?.find((action) => action.id === bulk.rowAction);
38
54
  if (rowAction === undefined || !isWriteHandlerRowAction(rowAction))
39
55
  return [];
@@ -43,12 +59,20 @@ export function buildListBulkActions(options) {
43
59
  /** DataTable `bulk` prop of a list screen; undefined without bulk actions or dispatcher. */
44
60
  export function useListBulk(options) {
45
61
  const { bulkActions, rowActions, translate, dispatcher, reload } = options;
62
+ const navigateWithInitialValues = useNavigateWithInitialValues();
46
63
  return useMemo(() => {
47
64
  if (bulkActions === undefined || dispatcher === undefined)
48
65
  return undefined;
49
- const actions = buildListBulkActions({ bulkActions, rowActions, translate, dispatcher });
66
+ const openBulkForm = (action, ids) => navigateWithInitialValues({ screenId: lastSegment(action.screen) }, { [action.idsField]: ids });
67
+ const actions = buildListBulkActions({
68
+ bulkActions,
69
+ rowActions,
70
+ translate,
71
+ dispatcher,
72
+ openBulkForm,
73
+ });
50
74
  if (actions.length === 0)
51
75
  return undefined;
52
76
  return { actions, reload: () => refetchAfterWrite(reload) };
53
- }, [bulkActions, rowActions, translate, dispatcher, reload]);
77
+ }, [bulkActions, rowActions, translate, dispatcher, reload, navigateWithInitialValues]);
54
78
  }
@@ -1,4 +1,4 @@
1
- import { currencyDecimals } from "../headless/index.js";
1
+ import { moneyAmountToMinor } from "../headless/index.js";
2
2
  // Locale-aware decimal parse for pasted text: strips space/NBSP thousands
3
3
  // separators outright, then treats whichever of "," or "." appears LAST in
4
4
  // the string as the decimal separator and strips the other one — handles
@@ -36,7 +36,7 @@ function coerceMoney(text, currency) {
36
36
  if (text.trim() === "")
37
37
  return undefined;
38
38
  const n = parseLocaleAwareDecimal(text);
39
- return n === undefined ? undefined : Math.round(n * 10 ** currencyDecimals(currency));
39
+ return n === undefined ? undefined : moneyAmountToMinor(n, currency);
40
40
  }
41
41
  function coerceSelect(column, text) {
42
42
  return (column.options ?? []).find((opt) => opt === text || column.optionLabels?.[opt] === text);
@@ -10,7 +10,11 @@ export function MultiSelectChips({ field, id, options, value, onChange, }) {
10
10
  const next = new Set(selected);
11
11
  if (!next.delete(optionValue))
12
12
  next.add(optionValue);
13
- onChange(options.filter((opt) => next.has(opt.value)).map((opt) => opt.value));
13
+ const optionValues = new Set(options.map((opt) => opt.value));
14
+ onChange([
15
+ ...options.filter((opt) => next.has(opt.value)).map((opt) => opt.value),
16
+ ...value.filter((stored) => !optionValues.has(stored) && next.has(stored)),
17
+ ]);
14
18
  };
15
19
  return (_jsx(Grid, { columns: "auto", tight: true, ariaLabelledBy: `${id}-label`, children: options.map((opt) => {
16
20
  const isSelected = selected.has(opt.value);
@@ -0,0 +1,5 @@
1
+ import type { ReactNode } from "react";
2
+ export declare function MultiSelectCount({ id, value, }: {
3
+ readonly id: string;
4
+ readonly value: readonly string[];
5
+ }): ReactNode;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useOptionalTranslation } from "../i18n.js";
3
+ import { usePrimitives } from "../primitives.js";
4
+ const keyAsText = (key) => key;
5
+ // MultiSelectFieldDef's `display: "count"`: the held values are not listed, only how many there are.
6
+ export function MultiSelectCount({ id, value, }) {
7
+ const t = useOptionalTranslation() ?? keyAsText;
8
+ const { Text } = usePrimitives();
9
+ return (_jsx(Text, { variant: "small", testId: `${id}-count`, children: t("kumiko.form.selection-count", { count: value.length }) }));
10
+ }
@@ -71,8 +71,8 @@ function buildFormChromeProps(model, { formHeaderRegion, titleActionMount }) {
71
71
  };
72
72
  }
73
73
  export function renderEditLayout(model) {
74
- const { props, state, sections, handleSubmit } = model.engine;
74
+ const { props, state, sections, form, handleSubmit } = model.engine;
75
75
  const header = buildHeaderActions(model);
76
76
  const { Form } = state.primitives;
77
- return (_jsx(ExtensionFormRegistryProvider, { value: state.extensionFormRegistry, children: _jsxs(FormUploadTrackerProvider, { value: state.trackUpload, children: [state.menuActionConfirmDialog, renderPageHeader(model, header), _jsx(Form, { onSubmit: () => void handleSubmit(), ...(state.focusFirstErrorKey > 0 && { focusFirstErrorKey: state.focusFirstErrorKey }), ...buildFormHeadingProps(model), ...buildFormActionProps(model, header), testId: "render-edit-form", stickyActions: state.isWizard || props.fillScreenHeight === true, ...buildFormChromeProps(model, header), children: _jsxs(AllFieldsRequiredProvider, { value: sections.showsAllRequiredHint || props.screen.layout.hideRequiredMarker === true, children: [props.leadContent, sections.showsAllRequiredHint && !state.insideDrawer && renderAllRequiredHint(model), renderDraftPicker(model), renderWizardProgress(model), state.isTabs && state.isStepped && renderTabStrip(model), renderEditSections(model), renderAfterFormSlot(model), props.formErrorOnTop !== true && renderFormErrorBanner(model), renderRootIssueBanners(model), renderExtensionErrorBanner(model), renderActionErrorBanner(model), renderDeleteDialog(model)] }) })] }) }));
77
+ return (_jsx(ExtensionFormRegistryProvider, { value: state.extensionFormRegistry, children: _jsxs(FormUploadTrackerProvider, { value: state.trackUpload, children: [state.menuActionConfirmDialog, renderPageHeader(model, header), _jsx(Form, { onSubmit: () => void handleSubmit(), ...(state.focusFirstErrorKey > 0 && { focusFirstErrorKey: state.focusFirstErrorKey }), ...buildFormHeadingProps(model), ...buildFormActionProps(model, header), testId: "render-edit-form", stickyActions: state.isWizard || props.fillScreenHeight === true, ...buildFormChromeProps(model, header), children: _jsxs(AllFieldsRequiredProvider, { value: sections.showsAllRequiredHint || props.screen.layout.hideRequiredMarker === true, children: [props.leadContent, sections.showsAllRequiredHint && !state.insideDrawer && renderAllRequiredHint(model), renderDraftPicker(model), renderWizardProgress(model), state.isTabs && state.isStepped && renderTabStrip(model), renderEditSections(model), props.belowSections?.(form.snapshot.values), renderAfterFormSlot(model), props.formErrorOnTop !== true && renderFormErrorBanner(model), renderRootIssueBanners(model), renderExtensionErrorBanner(model), renderActionErrorBanner(model), renderDeleteDialog(model)] }) })] }) }));
78
78
  }
@@ -223,6 +223,8 @@ export type RenderEditProps<TValues extends FormValues, TCtx = unknown> = {
223
223
  * rhythm — for content that belongs to the form but is no field (e.g. the
224
224
  * secret a confirm step refers to). */
225
225
  readonly leadContent?: ReactNode;
226
+ /** Rendered after the sections, above the form actions, with the live form values. */
227
+ readonly belowSections?: (values: Readonly<Record<string, unknown>>) => ReactNode;
226
228
  /** Blocks submit (button and Enter) while fields stay editable — unlike
227
229
  * `disabled`, which locks the whole form. For a gate the host owns, e.g.
228
230
  * an acknowledgement checkbox in `leadContent`. */
@@ -2,6 +2,8 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
2
2
  import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
3
3
  import { useEffect, useRef, useState } from "react";
4
4
  import { useOptionalDispatcher } from "../context/dispatcher-context.js";
5
+ import { REFERENCE_SEARCH_DEBOUNCE_MS } from "../hooks/reference-limits.js";
6
+ import { useDebouncedValue } from "../hooks/use-debounced-value.js";
5
7
  import { useTranslation } from "../i18n.js";
6
8
  import { usePrimitives } from "../primitives.js";
7
9
  import { useAiAssistPayload } from "./ai-assist-payload.js";
@@ -25,9 +27,11 @@ function AiAssistChips({ field, aiAssist, onChange, input, row }) {
25
27
  const [note, setNote] = useState(undefined);
26
28
  const activeRun = useRef(null);
27
29
  const contextValues = Object.fromEntries((aiAssist.contextFields ?? []).map((name) => [name, row?.[name]]));
28
- // Changed context (e.g. another selection) replaces the text; the first render never fetches.
29
- const contextKey = JSON.stringify(contextValues);
30
+ // Changed context (e.g. another selection) replaces an empty or AI-written text; the first render never fetches.
31
+ // Debounced so a text context field does not fire one server-side LLM query per keystroke.
32
+ const contextKey = useDebouncedValue(JSON.stringify(contextValues), REFERENCE_SEARCH_DEBOUNCE_MS);
30
33
  const seenContextKey = useRef(contextKey);
34
+ const lastGeneratedText = useRef(undefined);
31
35
  const run = async (chips, typed) => {
32
36
  if (dispatcher === undefined)
33
37
  return;
@@ -44,9 +48,17 @@ function AiAssistChips({ field, aiAssist, onChange, input, row }) {
44
48
  };
45
49
  setBusy(true);
46
50
  setFailed(false);
47
- const result = await dispatcher.query(aiAssist.query, payload, {
48
- signal: ctrl.signal,
49
- });
51
+ let result;
52
+ try {
53
+ result = await dispatcher.query(aiAssist.query, payload, { signal: ctrl.signal });
54
+ }
55
+ catch {
56
+ if (!ctrl.signal.aborted) {
57
+ setBusy(false);
58
+ setFailed(true);
59
+ }
60
+ return;
61
+ }
50
62
  if (ctrl.signal.aborted)
51
63
  return;
52
64
  setBusy(false);
@@ -59,16 +71,22 @@ function AiAssistChips({ field, aiAssist, onChange, input, row }) {
59
71
  setFailed(true);
60
72
  return;
61
73
  }
74
+ lastGeneratedText.current = text;
62
75
  onChange(text);
63
76
  };
64
77
  // The effect reads the latest run/active through a ref so it only fires when the context changes.
65
78
  const rerunWithCurrentChips = useRef(() => { });
66
79
  rerunWithCurrentChips.current = () => void run(active, undefined);
80
+ const hasHandWrittenText = useRef(false);
81
+ hasHandWrittenText.current = field.value !== "" && field.value !== lastGeneratedText.current;
67
82
  useEffect(() => {
68
83
  // skip: nothing changed since the last run (or since mount).
69
84
  if (seenContextKey.current === contextKey)
70
85
  return;
71
86
  seenContextKey.current = contextKey;
87
+ // skip: the user's own text is never replaced silently.
88
+ if (hasHandWrittenText.current)
89
+ return;
72
90
  rerunWithCurrentChips.current();
73
91
  }, [contextKey]);
74
92
  const toggle = (index) => {
@@ -3,6 +3,7 @@ import { AvailabilityOptionsMultiSelect, staticSelectOptions, } from "./availabi
3
3
  import { FileListField } from "./file-list-field.js";
4
4
  import { MultiSelectCheckboxes } from "./multi-select-checkboxes.js";
5
5
  import { MultiSelectChips } from "./multi-select-chips.js";
6
+ import { MultiSelectCount } from "./multi-select-count.js";
6
7
  import { stringArrayOf, stringValue, withPinnedValues } from "./render-field-values.js";
7
8
  function renderMultiSelectControl({ field, id, Input, onChange }, { common }, options, arrayValue) {
8
9
  if (field.display === "chips") {
@@ -13,6 +14,8 @@ function renderMultiSelectControl({ field, id, Input, onChange }, { common }, op
13
14
  export function renderMultiSelectInput(args, shared) {
14
15
  const { field } = args;
15
16
  const arrayValue = stringArrayOf(field.value);
17
+ if (field.display === "count")
18
+ return _jsx(MultiSelectCount, { id: args.id, value: arrayValue });
16
19
  const renderControl = (options) => renderMultiSelectControl(args, shared, options, arrayValue);
17
20
  if (field.selectOptionsAvailabilityQuery !== undefined && field.readOnly !== true) {
18
21
  return (_jsx(AvailabilityOptionsMultiSelect, { field: field, query: field.selectOptionsAvailabilityQuery.query, initialValues: arrayValue, children: renderControl }));
@@ -1,5 +1,5 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { currencyDecimals, formatMoney, resolveSafeMoneyLocale, } from "../headless/index.js";
2
+ import { currencyDecimals, formatMoney, moneyAmountToMinor, resolveSafeMoneyLocale, } from "../headless/index.js";
3
3
  import { useOptionalLocale } from "../i18n.js";
4
4
  import { usePrimitives } from "../primitives.js";
5
5
  import { choiceChipClass } from "./choice-chip-class.js";
@@ -38,7 +38,7 @@ export function ValueChipsControl({ field, from, row, onChange, input, }) {
38
38
  onChange(value);
39
39
  return;
40
40
  }
41
- onChange(moneyPayload(Math.round(value * 10 ** currencyDecimals(currency)), currency));
41
+ onChange(moneyPayload(moneyAmountToMinor(value, currency), currency));
42
42
  };
43
43
  return (_jsxs(_Fragment, { children: [input, values.length > 0 && (_jsx(Grid, { columns: "auto", tight: true, testId: `field-value-chips-${field.field}`, children: values.map((value) => {
44
44
  const selected = value === current;
@@ -1,5 +1,5 @@
1
1
  import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
2
- import { currencyDecimals } from "../headless/index.js";
2
+ import { currencyDecimals, moneyAmountToMinor } from "../headless/index.js";
3
3
  export function stringValue(v) {
4
4
  if (v === undefined || v === null)
5
5
  return "";
@@ -86,11 +86,11 @@ export function moneyMinorValue(v, currency) {
86
86
  if (v === undefined || v === null || v === "")
87
87
  return "";
88
88
  if (typeof v === "number")
89
- return Math.round(v * 10 ** currencyDecimals(currency));
89
+ return moneyAmountToMinor(v, currency);
90
90
  if (typeof v === "object") {
91
91
  const amount = propertyOf(v, "amount");
92
92
  if (typeof amount === "number")
93
- return Math.round(amount * 10 ** currencyDecimals(currency));
93
+ return moneyAmountToMinor(amount, currency);
94
94
  }
95
95
  return "";
96
96
  }
@@ -6,22 +6,31 @@ export type BulkRowOutcome = {
6
6
  readonly kind: "failed";
7
7
  readonly message: string;
8
8
  };
9
- export type DataTableBulkAction = {
9
+ type DataTableBulkActionBase = {
10
10
  readonly id: string;
11
- /** Translated label of the underlying row action. */
11
+ /** Translated label of the underlying row action or form action. */
12
12
  readonly label: string;
13
13
  readonly style?: "primary" | "secondary" | "danger";
14
14
  readonly icon?: IconKey;
15
15
  /** Present: one confirm dialog for the whole selection, with this text for `count` rows. */
16
16
  readonly confirmText?: (count: number) => string;
17
17
  readonly confirmLabel?: string;
18
+ };
19
+ export type DataTableBulkWriteAction = DataTableBulkActionBase & {
18
20
  /** False: the row action's `visible` hides it for this row; the run skips the row. */
19
21
  readonly appliesTo: (row: ListRowViewModel) => boolean;
20
22
  /** Exactly one server write for one row. Never throws for a rejected write. */
21
23
  readonly writeRow: (row: ListRowViewModel) => Promise<BulkRowOutcome>;
22
24
  };
25
+ export type DataTableBulkFormAction = DataTableBulkActionBase & {
26
+ /** Hands the whole selection to one form instead of running writes in the table. */
27
+ readonly openForm: (rows: readonly ListRowViewModel[]) => void;
28
+ };
29
+ export type DataTableBulkAction = DataTableBulkWriteAction | DataTableBulkFormAction;
30
+ export declare function isBulkFormAction(action: DataTableBulkAction): action is DataTableBulkFormAction;
23
31
  export type DataTableBulk = {
24
32
  readonly actions: readonly DataTableBulkAction[];
25
33
  /** Reloads the list once after a run. */
26
34
  readonly reload: () => Promise<void>;
27
35
  };
36
+ export {};
@@ -1 +1,3 @@
1
- export {};
1
+ export function isBulkFormAction(action) {
2
+ return "openForm" in action;
3
+ }
@@ -1,3 +1,4 @@
1
1
  import type { FormController, FormControllerOptions, FormValues } from "./types.ts";
2
+ export declare function isCurrencyOnlyMoney(value: unknown): boolean;
2
3
  export declare function stripUntouchedEmptyStrings<TValues extends FormValues>(values: TValues, initial: TValues, forceIncludeEmpty: ReadonlySet<string>): TValues;
3
4
  export declare function createFormController<TValues extends FormValues, TCtx = unknown>(options: FormControllerOptions<TValues, TCtx>): FormController<TValues>;
@@ -65,7 +65,7 @@ function valuesDiff(current, initial) {
65
65
  // The seed of an untouched optional money field (buildInitialValues); never a valid payload value.
66
66
  // Stripped only while the initial value was that seed too: clearing a stored amount must reach the
67
67
  // server, which rejects it visibly instead of keeping the old amount silently.
68
- function isCurrencyOnlyMoney(value) {
68
+ export function isCurrencyOnlyMoney(value) {
69
69
  return (typeof value === "object" &&
70
70
  value !== null &&
71
71
  "currency" in value &&
@@ -6,7 +6,7 @@ export declare const UNIT_FORMAT_KEYS: readonly string[];
6
6
  export { DOCUMENT_FALLBACK_CURRENCY, type DocumentDateOptions, formatDocumentDate, formatDocumentMoney, formatDocumentPercent, } from "./document-values.ts";
7
7
  export { escapeHtml, escapeHtmlAttr, escapeXml, isSafeHref, stripControlChars } from "./escape.ts";
8
8
  export { type HtmlValue, html, RawHtml, raw } from "./html-template.ts";
9
- export { currencyDecimals, formatMoney, resolveSafeMoneyLocale } from "./money.ts";
9
+ export { currencyDecimals, formatMoney, formatMoneyValue, moneyAmountToMinor, resolveSafeMoneyLocale, } from "./money.ts";
10
10
  export { telHref } from "./phone.ts";
11
11
  export declare function applyFormatSpec(spec: {
12
12
  format: string;
@@ -134,7 +134,7 @@ export const UNIT_FORMAT_KEYS = [
134
134
  export { DOCUMENT_FALLBACK_CURRENCY, formatDocumentDate, formatDocumentMoney, formatDocumentPercent, } from "./document-values.js";
135
135
  export { escapeHtml, escapeHtmlAttr, escapeXml, isSafeHref, stripControlChars } from "./escape.js";
136
136
  export { html, RawHtml, raw } from "./html-template.js";
137
- export { currencyDecimals, formatMoney, resolveSafeMoneyLocale } from "./money.js";
137
+ export { currencyDecimals, formatMoney, formatMoneyValue, moneyAmountToMinor, resolveSafeMoneyLocale, } from "./money.js";
138
138
  export { telHref } from "./phone.js";
139
139
  // JSON.stringify throws on BigInt and circular values; a cell must degrade to text instead of crashing the screen.
140
140
  function stringifyJsonOrString(value, indent) {
@@ -1,3 +1,8 @@
1
1
  export declare function currencyDecimals(code: string): number;
2
+ export declare function moneyAmountToMinor(amount: number, currency: string): number;
3
+ export declare function formatMoneyValue(value: {
4
+ readonly amount: number;
5
+ readonly currency: string;
6
+ }, locale?: string): string;
2
7
  export declare function resolveSafeMoneyLocale(locale: string | undefined): string;
3
8
  export declare function formatMoney(amountMinor: number, currency: string, locale?: string, fractionDigits?: number): string;
@@ -10,6 +10,16 @@ export function currencyDecimals(code) {
10
10
  return 3;
11
11
  return 2;
12
12
  }
13
+ // Major-unit amount → minor units scaled by currencyDecimals(currency), as
14
+ // formatMoney expects. Deliberately not rehydrateMoney's `amountMinor`: that
15
+ // uses a flat MINOR_UNIT_SCALE=100, which is wrong for JPY (0 decimals) and
16
+ // BHD (3 decimals).
17
+ export function moneyAmountToMinor(amount, currency) {
18
+ return Math.round(amount * 10 ** currencyDecimals(currency));
19
+ }
20
+ export function formatMoneyValue(value, locale) {
21
+ return formatMoney(moneyAmountToMinor(value.amount, value.currency), value.currency, locale);
22
+ }
13
23
  const FALLBACK_MONEY_LOCALE = "en-US";
14
24
  // An invalid tag makes Intl constructors throw a RangeError; canonicalizing up
15
25
  // front keeps server renders and client cells safe. No navigator lookup, so it
@@ -5,7 +5,7 @@ export type { BatchResult, Command, Dispatcher, DispatcherError, DispatcherStatu
5
5
  export { generateRequestId, StreamFrame, type StreamFrameEvent } from "./dispatcher/index.ts";
6
6
  export type { FieldConditionPredicate, FieldConditions, FieldConditionValue, FieldState, FormController, FormControllerOptions, FormSnapshot, FormValues, SubmitConfig, SubmitPayloadMode, SubmitResult, } from "./form/index.ts";
7
7
  export { createFormController, groupIssuesByPath, I18N_KEY_PARAM, relevantFieldIssues, zodErrorToFieldIssues, } from "./form/index.ts";
8
- export { applyFormatSpec, currencyDecimals, DOCUMENT_FALLBACK_CURRENCY, EMPTY_VALUE_PLACEHOLDER, escapeHtml, escapeHtmlAttr, escapeXml, formatDocumentDate, formatDocumentMoney, formatDocumentPercent, formatMoney, type HtmlValue, html, isSafeHref, RawHtml, raw, resolveSafeMoneyLocale, stripControlChars, telHref, toInstant, } from "./format/index.ts";
8
+ export { applyFormatSpec, currencyDecimals, DOCUMENT_FALLBACK_CURRENCY, EMPTY_VALUE_PLACEHOLDER, escapeHtml, escapeHtmlAttr, escapeXml, formatDocumentDate, formatDocumentMoney, formatDocumentPercent, formatMoney, formatMoneyValue, type HtmlValue, html, isSafeHref, moneyAmountToMinor, RawHtml, raw, resolveSafeMoneyLocale, stripControlChars, telHref, toInstant, } from "./format/index.ts";
9
9
  export type { NavDefinition, NavNode, NavRegistrySlice, NavTree, ResolveNavigationOptions, } from "./nav/index.ts";
10
10
  export { resolveNavigation } from "./nav/index.ts";
11
11
  export { pluralKey } from "./plural-key.ts";
@@ -3,7 +3,7 @@
3
3
  export { parseRefTarget } from "@cosmicdrift/kumiko-framework/ui-types";
4
4
  export { generateRequestId, StreamFrame } from "./dispatcher/index.js";
5
5
  export { createFormController, groupIssuesByPath, I18N_KEY_PARAM, relevantFieldIssues, zodErrorToFieldIssues, } from "./form/index.js";
6
- export { applyFormatSpec, currencyDecimals, DOCUMENT_FALLBACK_CURRENCY, EMPTY_VALUE_PLACEHOLDER, escapeHtml, escapeHtmlAttr, escapeXml, formatDocumentDate, formatDocumentMoney, formatDocumentPercent, formatMoney, html, isSafeHref, RawHtml, raw, resolveSafeMoneyLocale, stripControlChars, telHref, toInstant, } from "./format/index.js";
6
+ export { applyFormatSpec, currencyDecimals, DOCUMENT_FALLBACK_CURRENCY, EMPTY_VALUE_PLACEHOLDER, escapeHtml, escapeHtmlAttr, escapeXml, formatDocumentDate, formatDocumentMoney, formatDocumentPercent, formatMoney, formatMoneyValue, html, isSafeHref, moneyAmountToMinor, RawHtml, raw, resolveSafeMoneyLocale, stripControlChars, telHref, toInstant, } from "./format/index.js";
7
7
  export { resolveNavigation } from "./nav/index.js";
8
8
  export { pluralKey } from "./plural-key.js";
9
9
  export { PWA_CACHE_NAME_PREFIX, PWA_CACHE_SCOPE_HASH_LENGTH, PWA_SERVICE_WORKER_META_NAME, pwaCacheScopePrefixOf, } from "./pwa-service-worker-meta.js";
@@ -207,7 +207,7 @@ export type EditFieldViewModel = {
207
207
  * toggle instead of the default combobox dropdown. Set for
208
208
  * `type: "select"` when SelectFieldDef.display is "radio" or "dropdown" —
209
209
  * the renderer then skips its own radio-vs-dropdown heuristic. */
210
- readonly display?: "checkboxes" | "chips" | "dropdown" | "radio";
210
+ readonly display?: "checkboxes" | "chips" | "dropdown" | "radio" | "count";
211
211
  /** `type: "select"` only: tone per option, shown on the selected radio segment. */
212
212
  readonly optionTones?: Readonly<Partial<Record<string, SelectOptionTone>>>;
213
213
  /** Set for `type: "multiSelect"` when MultiSelectFieldDef.columns is
@@ -1,4 +1,4 @@
1
- import type { DataTableBulkAction } from "../data-table-bulk-types.ts";
1
+ import type { DataTableBulkWriteAction } from "../data-table-bulk-types.ts";
2
2
  import type { ListRowViewModel } from "../headless/index.ts";
3
3
  /** Parallel row writes of one run; more would crowd out the list's own requests. */
4
4
  export declare const BULK_WRITE_CONCURRENCY = 4;
@@ -10,7 +10,7 @@ export type BulkRunResult = {
10
10
  readonly notStartedIds: readonly string[];
11
11
  readonly firstFailureMessage?: string;
12
12
  };
13
- type BulkRunAction = Pick<DataTableBulkAction, "appliesTo" | "writeRow">;
13
+ type BulkRunAction = Pick<DataTableBulkWriteAction, "appliesTo" | "writeRow">;
14
14
  /** One write per row, at most `concurrency` at a time. Cancel stops new writes; running ones finish. */
15
15
  export declare function runBulkWrites({ rows, action, isCancelled, onRowSettled, concurrency, }: {
16
16
  readonly rows: readonly ListRowViewModel[];
@@ -182,6 +182,7 @@ export const kumikoDefaultTranslations = {
182
182
  "kumiko.list.row.collapse": "Collapse {title}",
183
183
  "kumiko.list.row.expand": "Expand {title}",
184
184
  "kumiko.list.bulk.selected": "{count} selected",
185
+ "kumiko.form.selection-count": "{count} selected",
185
186
  "kumiko.list.bulk.clear": "Clear selection",
186
187
  "kumiko.list.bulk.limit": "At most {max} rows per selection",
187
188
  "kumiko.list.bulk.select-all": "Select all rows on this page",
@@ -1116,6 +1116,8 @@ export type ModalProps = {
1116
1116
  readonly title: string;
1117
1117
  readonly children: ReactNode;
1118
1118
  readonly testId?: string;
1119
+ /** "wide" suits content with lists beside actions; web caps it at the viewport. */
1120
+ readonly size?: "default" | "wide";
1119
1121
  };
1120
1122
  /** Side panel for hosting an existing self-contained form/widget (own
1121
1123
  * submit/cancel buttons) without leaving the underlying screen — e.g. a
@@ -1373,6 +1375,8 @@ export type ActionOverflowMenuProps = {
1373
1375
  readonly items: readonly ActionMenuItemSpec[];
1374
1376
  /** aria-label for the three-dots trigger. */
1375
1377
  readonly label: string;
1378
+ /** Renders a labelled button (plus icon, text, chevron) instead of the three-dots icon. */
1379
+ readonly triggerLabel?: string;
1376
1380
  readonly testId?: string;
1377
1381
  };
1378
1382
  import type { CopyButtonProps, PromoPanelProps, SecretRevealProps, ShareButtonProps, StickyActionBarProps } from "./primitives-share-types.ts";
@@ -1,7 +1,7 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { cn } from "../lib/cn.js";
3
3
  export function RailSection({ title, action, testId, children, }) {
4
- return (_jsxs("section", { className: "flex flex-col border-b pb-1", "data-testid": testId, children: [_jsxs("div", { className: "flex flex-wrap items-center gap-x-2 gap-y-1 px-3.5 pt-2.5 pb-1", children: [_jsx("span", { className: "min-w-0 text-xs font-medium uppercase tracking-wider text-muted-foreground", children: title }), action !== undefined && _jsx("div", { className: "ml-auto", children: action })] }), children] }));
4
+ return (_jsxs("section", { className: "flex flex-col border-b pb-1", "data-testid": testId, children: [_jsxs("div", { className: "flex flex-wrap items-center gap-x-2 gap-y-1 px-3.5 pt-2.5 pb-1", children: [_jsx("span", { className: "min-w-0 text-xs font-medium uppercase tracking-wider text-muted-foreground", children: title }), action !== undefined && _jsx("div", { className: "ml-auto whitespace-nowrap", children: action })] }), children] }));
5
5
  }
6
6
  export function RailField({ children }) {
7
7
  return _jsx("div", { className: "flex flex-col gap-3 px-3.5 py-2", children: children });
@@ -0,0 +1,4 @@
1
+ import type { ReactNode } from "react";
2
+ export declare function EditorToolbarPill({ children }: {
3
+ readonly children: ReactNode;
4
+ }): ReactNode;
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // A compact outlined pill for a second toolbar row; a select button inside stays flat and fills the pill.
3
+ export function EditorToolbarPill({ children }) {
4
+ return (_jsx("span", { className: "inline-flex h-7 shrink-0 items-center rounded-md border border-input bg-background [&_button]:h-full [&_button]:min-h-0 [&_button[aria-haspopup=listbox]]:h-full [&_button[aria-haspopup=listbox]]:min-h-0 [&_button[aria-haspopup=listbox]]:w-auto [&_button[aria-haspopup=listbox]]:px-2 [&_button[aria-haspopup=listbox]]:py-0 [&_button[aria-haspopup=listbox]]:text-xs", children: children }));
5
+ }
@@ -2,5 +2,6 @@ export { type EditorActionTestIds, EditorFooter, type FooterTone } from "./edito
2
2
  export { EditorBody, EditorFrame, EditorInfoBar, type InfoBarTone } from "./editor-frame.tsx";
3
3
  export { EditorHeader, type EditorHeaderTestIds, EditorLocaleSwitch, type EditorMode, EditorModeSwitch, type EditorSaveActions, } from "./editor-header.tsx";
4
4
  export { RailField, RailHint, RailRow, RailSection } from "./editor-rail.tsx";
5
+ export { EditorToolbarPill } from "./editor-toolbar-pill.tsx";
5
6
  export { EditorWorkbench, type EditorWorkbenchProps, type WorkbenchSave, } from "./editor-workbench.tsx";
6
7
  export { formatRelativeWhen } from "./relative-when.ts";
@@ -2,5 +2,6 @@ export { EditorFooter } from "./editor-footer.js";
2
2
  export { EditorBody, EditorFrame, EditorInfoBar } from "./editor-frame.js";
3
3
  export { EditorHeader, EditorLocaleSwitch, EditorModeSwitch, } from "./editor-header.js";
4
4
  export { RailField, RailHint, RailRow, RailSection } from "./editor-rail.js";
5
+ export { EditorToolbarPill } from "./editor-toolbar-pill.js";
5
6
  export { EditorWorkbench, } from "./editor-workbench.js";
6
7
  export { formatRelativeWhen } from "./relative-when.js";
@@ -15,7 +15,7 @@ export { useResolvers } from "./app/resolvers-context.tsx";
15
15
  export { clearRememberedListState } from "./app/session-list-state-store.ts";
16
16
  export { DrawnFilter, DrawnPanel, DrawnPencil, DrawnSearch, DrawnSparkles, DrawnWand, } from "./drawn-icons.ts";
17
17
  export type { EditorActionTestIds, EditorHeaderTestIds, EditorMode, EditorSaveActions, EditorWorkbenchProps, FooterTone, InfoBarTone, WorkbenchSave, } from "./editor/index.ts";
18
- export { EditorBody, EditorFooter, EditorFrame, EditorHeader, EditorInfoBar, EditorLocaleSwitch, EditorModeSwitch, EditorWorkbench, formatRelativeWhen, RailField, RailHint, RailRow, RailSection, } from "./editor/index.ts";
18
+ export { EditorBody, EditorFooter, EditorFrame, EditorHeader, EditorInfoBar, EditorLocaleSwitch, EditorModeSwitch, EditorToolbarPill, EditorWorkbench, formatRelativeWhen, RailField, RailHint, RailRow, RailSection, } from "./editor/index.ts";
19
19
  export type { NavIconKey } from "./icons.tsx";
20
20
  export { Icon } from "./icons.tsx";
21
21
  export type { AppLayoutProps } from "./layout/app-layout.tsx";
package/dist/web/index.js CHANGED
@@ -13,7 +13,7 @@ export { PlainContentEditor } from "./app/plain-content-editor.js";
13
13
  export { useResolvers } from "./app/resolvers-context.js";
14
14
  export { clearRememberedListState } from "./app/session-list-state-store.js";
15
15
  export { DrawnFilter, DrawnPanel, DrawnPencil, DrawnSearch, DrawnSparkles, DrawnWand, } from "./drawn-icons.js";
16
- export { EditorBody, EditorFooter, EditorFrame, EditorHeader, EditorInfoBar, EditorLocaleSwitch, EditorModeSwitch, EditorWorkbench, formatRelativeWhen, RailField, RailHint, RailRow, RailSection, } from "./editor/index.js";
16
+ export { EditorBody, EditorFooter, EditorFrame, EditorHeader, EditorInfoBar, EditorLocaleSwitch, EditorModeSwitch, EditorToolbarPill, EditorWorkbench, formatRelativeWhen, RailField, RailHint, RailRow, RailSection, } from "./editor/index.js";
17
17
  export { Icon } from "./icons.js";
18
18
  export { AppLayout } from "./layout/app-layout.js";
19
19
  export { Avatar } from "./layout/avatar.js";
@@ -440,7 +440,7 @@ function NavSection({ node, collapsed, onToggle }) {
440
440
  !node.children.some((c) => c.provider === true || subtreeMatches(c, matches))) {
441
441
  return null;
442
442
  }
443
- return (_jsxs(SidebarGroup, { children: [_jsxs(SidebarGroupLabel, { className: plain ? PLAIN_GROUP_LABEL_CLASS : undefined, children: [displayLabel, plain && create !== undefined && (_jsx(TreeActionControl, { action: create, ariaLabel: navLabel(t, create.label), className: `${PLUS_BUTTON_CLASS} hover:bg-sidebar-foreground/10 hover:text-sidebar-foreground`, dispatch: dispatch, workspaceId: nav.route?.workspaceId, children: _jsx(Plus, { className: "size-3.5" }) }))] }), _jsx(SidebarGroupContent, { children: _jsx(SidebarMenu, { children: node.children.map((child) => (_jsx(NavMenuNode, { node: child, collapsed: collapsed, onToggle: onToggle }, child.qualifiedName))) }) })] }));
443
+ return (_jsxs(SidebarGroup, { children: [_jsxs(SidebarGroupLabel, { className: plain ? PLAIN_GROUP_LABEL_CLASS : undefined, children: [displayLabel, plain && create !== undefined && (_jsx(TreeActionControl, { action: create, ariaLabel: navLabel(t, create.label), className: `${PLUS_BUTTON_CLASS} hover:bg-sidebar-foreground/10 hover:text-sidebar-foreground group-data-[collapsible=icon]:hidden`, dispatch: dispatch, workspaceId: nav.route?.workspaceId, children: _jsx(Plus, { className: "size-3.5" }) }))] }), _jsx(SidebarGroupContent, { children: _jsx(SidebarMenu, { children: node.children.map((child) => (_jsx(NavMenuNode, { node: child, collapsed: collapsed, onToggle: onToggle }, child.qualifiedName))) }) })] }));
444
444
  }
445
445
  // A menu entry (top-level item or section child) supports three click modes:
446
446
  // `screen` is a route link (KumikoLink), `target` dispatches to EditorPanel
@@ -52,8 +52,8 @@ export function NotificationBell({ screens, menuEntry, }) {
52
52
  }), children: [_jsxs("div", { className: "flex items-center justify-between gap-2 border-b border-border px-3 py-2", children: [_jsx("h2", { className: "text-sm font-semibold", children: t("kumiko.notifications.title") }), inbox.unreadCount > 0 && (_jsx("button", { type: "button", className: "text-xs text-primary hover:underline", onClick: () => void inbox.markAllRead(), children: t("kumiko.notifications.markAllRead") }))] }), _jsxs("div", { className: "min-h-0 flex-1 overflow-y-auto", children: [inbox.failed && (_jsx("p", { role: "alert", className: "px-3 py-4 text-sm text-destructive", children: t("kumiko.notifications.loadFailed") })), !inbox.failed && !inbox.loading && inbox.rows.length === 0 && (_jsx("p", { className: "px-3 py-6 text-center text-sm text-muted-foreground", children: t("kumiko.notifications.empty") })), _jsx("ul", { children: inbox.rows.map((row) => (_jsx(NotificationRowItem, { row: row, createdLabel: formatRelative(Date.parse(row.createdAt)), onOpen: () => void openRow(row) }, row.id))) }), inbox.hasMore && (_jsx("button", { type: "button", className: "w-full px-3 py-2 text-sm text-primary hover:bg-accent", onClick: () => void inbox.loadMore(), children: t("kumiko.notifications.loadMore") }))] })] }) }));
53
53
  return (_jsxs(PopoverPrimitive.Root, { open: open, onOpenChange: setOpen, children: [menuEntry === undefined ? (
54
54
  // Stays mounted while the list is open, else "mark all read" would pull the anchor away.
55
- inbox.unreadCount > 0 || open ? (_jsx(PopoverPrimitive.Trigger, { asChild: true, children: _jsxs("button", { type: "button", "aria-label": label, "data-kumiko-layout": "notification-bell", className: triggerClass, children: [_jsx(Bell, { className: "size-4", "aria-hidden": "true" }), inbox.unreadCount > 0 && (_jsx("span", { "data-kumiko-layout": "notification-bell-badge", className: "absolute right-[3px] top-[3px] rounded-full bg-destructive px-1 py-0.5 text-[9.5px] font-semibold leading-none text-destructive-foreground", children: badge }))] }) })) : null) : (_jsxs(_Fragment, { children: [_jsx(PopoverPrimitive.Anchor, { virtualRef: menuEntry.anchorRef }), _jsxs("button", { type: "button", role: "menuitem", "data-testid": "notification-bell-menu-item", className: headerOverflowMenuItemClass, onClick: () => {
55
+ inbox.unreadCount > 0 || open ? (_jsx(PopoverPrimitive.Trigger, { asChild: true, children: _jsxs("button", { type: "button", "aria-label": label, "data-kumiko-layout": "notification-bell", className: triggerClass, children: [_jsx(Bell, { className: "size-4", "aria-hidden": "true" }), inbox.unreadCount > 0 && (_jsx("span", { "data-kumiko-layout": "notification-bell-badge", className: "absolute right-[3px] top-[3px] rounded-full bg-destructive px-1 py-0.5 text-[9.5px] font-semibold leading-none text-destructive-foreground", children: badge }))] }) })) : null) : (_jsxs(_Fragment, { children: [_jsx(PopoverPrimitive.Anchor, { virtualRef: menuEntry.anchorRef }), _jsxs("button", { type: "button", role: "menuitem", "aria-label": label, "data-testid": "notification-bell-menu-item", className: headerOverflowMenuItemClass, onClick: () => {
56
56
  setOpen(true);
57
57
  menuEntry.onSelect();
58
- }, children: [_jsx(Bell, { className: "size-4", "aria-hidden": "true" }), _jsx("span", { className: "flex-1", children: t("kumiko.notifications.label") }), inbox.unreadCount > 0 && (_jsx("span", { "data-kumiko-layout": "notification-bell-badge", className: "rounded-full bg-destructive px-1.5 py-0.5 text-[9.5px] font-semibold leading-none text-destructive-foreground", children: badge }))] })] })), panel] }));
58
+ }, children: [_jsx(Bell, { className: "size-4", "aria-hidden": "true" }), _jsx("span", { className: "flex-1", children: t("kumiko.notifications.label") }), inbox.unreadCount > 0 && (_jsx("span", { "data-kumiko-layout": "notification-bell-badge", "aria-hidden": "true", className: "rounded-full bg-destructive px-1.5 py-0.5 text-[9.5px] font-semibold leading-none text-destructive-foreground", children: badge }))] })] })), panel] }));
59
59
  }
@@ -204,10 +204,10 @@ function HeaderOverflow({ items, headerActions, bellScreens, }) {
204
204
  event.preventDefault();
205
205
  menuItems[next]?.focus();
206
206
  };
207
- return (_jsxs(_Fragment, { children: [_jsx("button", { ref: triggerRef, type: "button", "aria-label": t("kumiko.page-header.actions"), "aria-haspopup": "menu", "aria-expanded": open, "aria-controls": panelId, "data-testid": "shell-header-overflow-trigger", onClick: () => setOpen((wasOpen) => !wasOpen), className: "inline-flex size-10 shrink-0 items-center justify-center rounded-md border border-input bg-background text-foreground shadow-xs hover:bg-accent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring", children: _jsx(MoreHorizontal, { className: "size-4", "aria-hidden": "true" }) }), _jsxs("div", { ref: panelRef, id: panelId, role: "menu", "aria-label": t("kumiko.page-header.actions"), hidden: !open, onKeyDown: onPanelKeyDown, "data-testid": "shell-header-overflow", className: "absolute right-2 top-full z-30 mt-1 w-max min-w-[8rem] max-w-[calc(100vw-1rem)] rounded-md border bg-popover p-1 text-popover-foreground shadow-md", children: [bellScreens !== undefined && (_jsx(OverflowBellEntry, { screens: bellScreens, anchorRef: triggerRef, onSelect: () => setOpen(false), separated: items.length > 0 || headerActions !== undefined })), items.length > 0 && (_jsx("div", { className: "flex flex-col", children: items.map((item) => (_jsxs("button", { type: "button", role: "menuitem", disabled: item.disabled === true, "data-testid": item.testId ?? `shell-header-overflow-item-${item.id}`, onClick: () => {
207
+ return (_jsxs(_Fragment, { children: [_jsx("button", { ref: triggerRef, type: "button", "aria-label": t("kumiko.page-header.actions"), "aria-haspopup": "menu", "aria-expanded": open, "aria-controls": panelId, "data-testid": "shell-header-overflow-trigger", onClick: () => setOpen((wasOpen) => !wasOpen), className: "inline-flex size-10 shrink-0 items-center justify-center rounded-md border border-input bg-background text-foreground shadow-xs hover:bg-accent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring", children: _jsx(MoreHorizontal, { className: "size-4", "aria-hidden": "true" }) }), _jsxs("div", { ref: panelRef, id: panelId, role: "menu", "aria-label": t("kumiko.page-header.actions"), hidden: !open, onKeyDown: onPanelKeyDown, "data-testid": "shell-header-overflow", className: "absolute right-2 top-full z-30 mt-1 w-max min-w-[8rem] max-w-[calc(100vw-1rem)] rounded-md border bg-popover p-1 text-popover-foreground shadow-md", children: [bellScreens !== undefined && (_jsx(OverflowBellEntry, { screens: bellScreens, anchorRef: triggerRef, onSelect: () => setOpen(false), separated: foldsIntoOverflow(items, headerActions) })), items.length > 0 && (_jsx("div", { className: "flex flex-col", children: items.map((item) => (_jsxs("button", { type: "button", role: "menuitem", disabled: item.disabled === true, "data-testid": item.testId ?? `shell-header-overflow-item-${item.id}`, onClick: () => {
208
208
  setOpen(false);
209
209
  item.onSelect();
210
- }, className: cn(headerOverflowMenuItemClass, item.variant === "danger" && "text-destructive"), children: [item.icon !== undefined && Object.hasOwn(NAV_ICONS, item.icon) && (_jsx(Icon, { name: item.icon, className: "size-4 shrink-0" })), item.label] }, item.id))) })), items.length > 0 && headerActions !== undefined && (_jsx("hr", { className: "-mx-1 my-1 border-t border-border" })), headerActions !== undefined && (_jsx("div", { "data-kumiko-layout": "header-actions",
210
+ }, className: cn(headerOverflowMenuItemClass, item.variant === "danger" && "text-destructive"), children: [item.icon !== undefined && Object.hasOwn(NAV_ICONS, item.icon) && (_jsx(Icon, { name: item.icon, className: "size-4 shrink-0" })), item.label] }, item.id))) })), items.length > 0 && foldsIntoOverflow([], headerActions) && (_jsx("hr", { className: "-mx-1 my-1 border-t border-border" })), headerActions !== undefined && (_jsx("div", { "data-kumiko-layout": "header-actions",
211
211
  // Stacks direct children only; app wrappers opt in via HeaderActionGroup instead of
212
212
  // being restyled through a child selector that reaches into their markup.
213
213
  className: "flex flex-col items-stretch gap-1", onClick: () => setOpen(false), children: _jsx(HeaderOverflowMenuContext.Provider, { value: true, children: headerActions }) }))] })] }));
@@ -3,6 +3,8 @@ export type MenuItemDef = {
3
3
  readonly kind: "item";
4
4
  readonly id: string;
5
5
  readonly label: string;
6
+ readonly description?: string;
7
+ readonly testId?: string;
6
8
  /** Optional icon displayed before the label (16px). */
7
9
  readonly icon?: ReactNode;
8
10
  /** Display-only shortcut hint on the right (monospace, muted).
@@ -26,6 +26,6 @@ export function ActionMenu({ trigger, triggerLabel, items, align = "end", minWid
26
26
  // biome-ignore lint/suspicious/noArrayIndexKey: labels have no ID either, so their position provides identity
27
27
  return _jsx(DropdownMenuLabel, { children: item.label }, `label-${idx}`);
28
28
  }
29
- return (_jsxs(DropdownMenuItem, { onSelect: item.onSelect, disabled: item.disabled === true, "data-testid": `action-menu-item-${item.id}`, className: item.variant === "danger" ? "text-destructive focus:text-destructive" : undefined, children: [item.icon !== undefined && _jsx("span", { className: "size-4 shrink-0", children: item.icon }), _jsx("span", { className: "flex-1", children: item.label }), item.shortcut !== undefined && (_jsx("span", { className: "ml-auto text-xs text-muted-foreground tracking-wider font-mono", children: item.shortcut }))] }, item.id));
29
+ return (_jsxs(DropdownMenuItem, { onSelect: item.onSelect, disabled: item.disabled === true, "data-testid": item.testId ?? `action-menu-item-${item.id}`, className: item.variant === "danger" ? "text-destructive focus:text-destructive" : undefined, children: [item.icon !== undefined && _jsx("span", { className: "size-4 shrink-0", children: item.icon }), _jsxs("span", { className: "flex flex-1 flex-col", children: [item.label, item.description !== undefined && (_jsx("span", { className: "text-xs text-muted-foreground", children: item.description }))] }), item.shortcut !== undefined && (_jsx("span", { className: "ml-auto text-xs text-muted-foreground tracking-wider font-mono", children: item.shortcut }))] }, item.id));
30
30
  }) })] }));
31
31
  }
@@ -1,5 +1,5 @@
1
1
  import { type ReactNode } from "react";
2
- import type { DataTableBulk } from "../../../data-table-bulk-types.ts";
2
+ import { type DataTableBulk } from "../../../data-table-bulk-types.ts";
3
3
  import type { ListRowViewModel } from "../../../headless/index.ts";
4
4
  import type { PinnedCellProps } from "./use-column-pins.ts";
5
5
  export type BulkSelection = {
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useState } from "react";
3
+ import { isBulkFormAction, } from "../../../data-table-bulk-types.js";
3
4
  import { useBulkRun } from "../../../hooks/use-bulk-run.js";
4
5
  import { useOptionalTranslation } from "../../../i18n.js";
5
6
  import { cn } from "../../lib/cn.js";
@@ -36,6 +37,10 @@ export function useBulkSelection({ bulk, rows, titleField, rowTestId, flush, })
36
37
  const reload = bulk.reload;
37
38
  async function execute(action) {
38
39
  setPendingAction(undefined);
40
+ if (isBulkFormAction(action)) {
41
+ action.openForm(selection.selectedRows);
42
+ return;
43
+ }
39
44
  setResultActionLabel(action.label);
40
45
  const result = await run.start(action, selection.selectedRows);
41
46
  // Failed rows stay selected for a retry; so do rows a cancel kept from running.
@@ -5,7 +5,7 @@ import { Check } from "lucide-react";
5
5
  import { Fragment } from "react";
6
6
  import { rendererWarn } from "../../dev-console.js";
7
7
  import { fileIdsOf } from "../../file-ids-of.js";
8
- import { applyFormatSpec, EMPTY_VALUE_PLACEHOLDER, isSafeHref, telHref, } from "../../headless/index.js";
8
+ import { applyFormatSpec, EMPTY_VALUE_PLACEHOLDER, formatMoneyValue, isSafeHref, telHref, } from "../../headless/index.js";
9
9
  import { statusToneForOptionTone, statusToneForValue, useColumnRenderer, useOptionalPrimitives, } from "../../index.js";
10
10
  import { serverNowMs } from "../../server-clock.js";
11
11
  import { isSelectOptionTone } from "../../status-tone.js";
@@ -15,7 +15,6 @@ import { StatusBadge } from "../widgets/status-badge.js";
15
15
  import { HintCell } from "./data-table/hint-cell.js";
16
16
  import { FileDisplayCell } from "./file-thumbnail.js";
17
17
  import { FileViewAction } from "./file-view-action.js";
18
- import { currencyDecimals, formatMoney } from "./money-input.js";
19
18
  import "../react-css-custom-properties.js";
20
19
  import { useOptionalTranslation } from "../../index.js";
21
20
  import { isPlainPrimaryClick } from "./layout-elements.js";
@@ -159,14 +158,7 @@ export function defaultCellRender(value, type, optionLabels, locale, columnKey,
159
158
  if (type === "money") {
160
159
  if (!isMoneyValue(value))
161
160
  return String(value);
162
- // formatMoney expects minor units scaled by currencyDecimals(currency).
163
- // rehydrateMoney's `amountMinor` is scaled by a flat MINOR_UNIT_SCALE=100
164
- // instead, which disagrees with currencyDecimals for non-2-decimal
165
- // currencies (JPY: 0 decimals → 100x too high; BHD: 3 decimals → 10x too
166
- // low). Deriving minor units from `amount` keeps this consistent with
167
- // render-field.tsx's moneyMinorValue.
168
- const minor = Math.round(value.amount * 10 ** currencyDecimals(value.currency));
169
- return formatMoney(minor, value.currency, locale);
161
+ return formatMoneyValue(value, locale);
170
162
  }
171
163
  if (type === "select" || type === "multiSelect") {
172
164
  const values = Array.isArray(value) ? value : [value];
@@ -21,20 +21,19 @@ export function DefaultMetricBand({ lead, subtitle, children, testId, tiles, })
21
21
  // Below sm the narrow sub line replaces the regular one (board phone metrics are shorter).
22
22
  function useMetricSub({ sub, narrowSub }) {
23
23
  const narrow = useIsBelowSmViewport();
24
- return narrow && narrowSub !== undefined ? narrowSub : sub;
24
+ const beside = narrow && narrowSub !== undefined;
25
+ return { sub: beside ? narrowSub : sub, beside };
25
26
  }
26
27
  function MetricTile(props) {
27
28
  const { label, value, testId, onPress, tone, icon } = props;
28
- const sub = useMetricSub(props);
29
- const narrow = useIsBelowSmViewport();
30
29
  // The phone's short sub line ("of 2,850") stands beside the value like the board; the full one sits below.
31
- const subBeside = narrow && props.narrowSub !== undefined;
30
+ const { sub, beside: subBeside } = useMetricSub(props);
32
31
  const card = (_jsx(StatCard, { label: label, value: value, boardPadding: true, ...(sub !== undefined && { sub, subBelow: !subBeside }), ...(onPress !== undefined && { navigable: true }), ...(icon !== undefined && { icon: _jsx(Icon, { name: icon, className: "size-4" }) }), ...(tone !== undefined && { tone }), ...(testId !== undefined && { testId }) }));
33
32
  return onPress !== undefined ? (_jsx("button", { type: "button", className: "text-left", onClick: onPress, children: card })) : (card);
34
33
  }
35
34
  export function DefaultMetric(props) {
36
35
  const insideBand = useContext(InsideMetricBandContext);
37
- const sub = useMetricSub(props);
36
+ const { sub } = useMetricSub(props);
38
37
  if (props.tile === true)
39
38
  return _jsx(MetricTile, { ...props });
40
39
  const { label, value, testId, onPress } = props;
@@ -1,3 +1,3 @@
1
1
  import type { ReactNode } from "react";
2
2
  import type { ModalProps } from "../../index.ts";
3
- export declare function DefaultModal({ open, onOpenChange, title, children, testId, }: ModalProps): ReactNode;
3
+ export declare function DefaultModal({ open, onOpenChange, title, children, testId, size, }: ModalProps): ReactNode;
@@ -7,7 +7,7 @@ import { useTranslation } from "../../index.js";
7
7
  import { cn } from "../lib/cn.js";
8
8
  import { BareFormProvider } from "./contexts.js";
9
9
  import { ModalShell } from "./modal-shell.js";
10
- export function DefaultModal({ open, onOpenChange, title, children, testId, }) {
10
+ export function DefaultModal({ open, onOpenChange, title, children, testId, size = "default", }) {
11
11
  const t = useTranslation();
12
- return (_jsxs(ModalShell, { open: open, onOpenChange: onOpenChange, testId: testId, closeLabel: t("kumiko.dialog.close"), noAriaDescription: true, contentClassName: cn("grid w-full max-w-lg gap-4 border bg-card p-6 shadow-lg rounded-lg"), children: [_jsx(DialogPrimitive.Title, { className: "text-lg font-semibold leading-none tracking-tight", children: title }), _jsx("div", { onSubmit: (e) => e.stopPropagation(), children: _jsx(BareFormProvider, { children: children }) })] }));
12
+ return (_jsxs(ModalShell, { open: open, onOpenChange: onOpenChange, testId: testId, closeLabel: t("kumiko.dialog.close"), noAriaDescription: true, contentClassName: cn("grid w-full gap-4 border bg-card p-6 shadow-lg rounded-lg", size === "wide" ? "max-w-[min(830px,calc(100vw-2rem))]" : "max-w-lg"), children: [_jsx(DialogPrimitive.Title, { className: "text-lg font-semibold leading-none tracking-tight", children: title }), _jsx("div", { onSubmit: (e) => e.stopPropagation(), children: _jsx(BareFormProvider, { children: children }) })] }));
13
13
  }
@@ -12,4 +12,4 @@ export declare function RowActionsCell({ row, actions, mode, rowIsLink, compact,
12
12
  /** Small bordered buttons without the phone touch height; for buttons sitting inside a card. */
13
13
  readonly small?: boolean;
14
14
  }): ReactNode;
15
- export declare function ActionOverflowMenu({ items, label, testId }: ActionOverflowMenuProps): ReactNode;
15
+ export declare function ActionOverflowMenu({ items, label, triggerLabel, testId, }: ActionOverflowMenuProps): ReactNode;
@@ -1,5 +1,5 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Loader2, MoreHorizontal } from "lucide-react";
2
+ import { ChevronDown, Loader2, MoreHorizontal, Plus } from "lucide-react";
3
3
  import { useState } from "react";
4
4
  import { COMPACT_TAP_CLASSES } from "../../compact-tap-classes.js";
5
5
  import { needsActionConfirm, shouldRenderActionsIconOnly, useTranslation, WriteFailedError, } from "../../index.js";
@@ -187,9 +187,9 @@ function RowActionsKebab({ row, actions, }) {
187
187
  // secondary icon Button so it matches neighbouring icon buttons, including
188
188
  // the 44 px touch size on phones. Generic ActionMenuItemSpec items instead of
189
189
  // the DataTableRowAction schema (callers own confirm/danger handling per item).
190
- export function ActionOverflowMenu({ items, label, testId }) {
190
+ export function ActionOverflowMenu({ items, label, triggerLabel, testId, }) {
191
191
  const [open, setOpen] = useState(false);
192
- return (_jsxs(DropdownMenu, { open: open, onOpenChange: setOpen, children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx(UiButton, { type: "button", variant: "outline", size: "icon", className: SECONDARY_BUTTON_EXTRA_CLASSES, "aria-label": label, "data-testid": testId ?? "action-overflow-menu-trigger", children: _jsx(MoreHorizontal, { className: "size-4", "aria-hidden": "true" }) }) }), _jsx(DropdownMenuContent, { align: "end", children: items.map((item) => {
192
+ return (_jsxs(DropdownMenu, { open: open, onOpenChange: setOpen, children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx(UiButton, { type: "button", variant: "outline", size: triggerLabel === undefined ? "icon" : "sm", className: SECONDARY_BUTTON_EXTRA_CLASSES, "aria-label": label, "data-testid": testId ?? "action-overflow-menu-trigger", children: triggerLabel === undefined ? (_jsx(MoreHorizontal, { className: "size-4", "aria-hidden": "true" })) : (_jsxs(_Fragment, { children: [_jsx(Plus, { className: "size-4", "aria-hidden": "true" }), triggerLabel, _jsx(ChevronDown, { className: "size-3", "aria-hidden": "true" })] })) }) }), _jsx(DropdownMenuContent, { align: "end", children: items.map((item) => {
193
193
  const resolvedIcon = actionIconFor(item.icon);
194
194
  return (_jsxs(DropdownMenuItem, { "data-testid": item.testId ?? `${testId ?? "action-overflow-menu"}-item-${item.id}`, disabled: item.disabled === true, onSelect: (e) => {
195
195
  e.preventDefault();
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useState } from "react";
3
+ import { useBasePath } from "../../app/base-path-context.js";
3
4
  import { PWA_SERVICE_WORKER_META_NAME, pwaCacheScopePrefixOf, } from "../../headless/pwa-service-worker-meta.js";
4
5
  import { useTranslation } from "../../index.js";
5
6
  import { cn } from "../lib/cn.js";
@@ -56,16 +57,20 @@ function registerServiceWorker(serviceWorkerUrl) {
56
57
  .register(serviceWorkerUrl, { scope, updateViaCache: "none" })
57
58
  .catch(() => undefined);
58
59
  }
59
- // Only the registration for this document's scope is touched. A worker counts as the
60
+ // Only a registration scoped exactly to this app's base path is touched: getRegistration() also
61
+ // returns an enclosing scope, which belongs to another app on the origin. A worker counts as the
60
62
  // framework's own when it is served as /sw.js and left a cache with this scope's kumiko-pwa-
61
- // prefix; app-owned workers and other apps on the origin have no such marker.
62
- async function retireStaleServiceWorker() {
63
+ // prefix; app-owned workers have no such marker.
64
+ async function retireStaleServiceWorker(ownScopePath) {
63
65
  if (!("serviceWorker" in navigator) || typeof caches === "undefined")
64
66
  return;
65
- const registration = await navigator.serviceWorker.getRegistration();
67
+ const registration = await navigator.serviceWorker.getRegistration(ownScopePath);
66
68
  if (!registration?.active?.scriptURL.endsWith("/sw.js"))
67
69
  return;
68
- const cachePrefix = await pwaCacheScopePrefixOf(new URL(registration.scope).pathname);
70
+ const registeredScopePath = new URL(registration.scope).pathname;
71
+ if (registeredScopePath !== ownScopePath)
72
+ return;
73
+ const cachePrefix = await pwaCacheScopePrefixOf(registeredScopePath);
69
74
  const pwaCacheNames = (await caches.keys()).filter((name) => name.startsWith(cachePrefix));
70
75
  if (pwaCacheNames.length === 0)
71
76
  return;
@@ -108,14 +113,15 @@ function useInstallHint(enabled) {
108
113
  const HINT_BUTTON_CLASSES = cn("rounded-md px-3 py-1 text-xs font-medium", "hover:opacity-90 focus:outline-none focus:ring-2 focus:ring-ring");
109
114
  export function PwaSupport() {
110
115
  const t = useTranslation();
116
+ const basePath = useBasePath();
111
117
  const serviceWorkerUrl = readPwaServiceWorkerUrl();
112
118
  const [hint, dismiss] = useInstallHint(serviceWorkerUrl !== undefined);
113
119
  useEffect(() => {
114
120
  if (serviceWorkerUrl !== undefined)
115
121
  registerServiceWorker(serviceWorkerUrl);
116
122
  else
117
- retireStaleServiceWorker().catch(() => undefined);
118
- }, [serviceWorkerUrl]);
123
+ retireStaleServiceWorker(`${basePath}/`).catch(() => undefined);
124
+ }, [serviceWorkerUrl, basePath]);
119
125
  if (hint.kind === "none")
120
126
  return null;
121
127
  const install = async (event) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmicdrift/kumiko-renderer",
3
- "version": "0.417.0",
3
+ "version": "0.419.0",
4
4
  "description": "React renderer for Kumiko screens. The root export holds the platform-agnostic logic (primitives contract, hooks, KumikoScreen, navigation and SSE abstractions); ./headless the DOM-free UI logic, ./live the HTTP dispatcher, ./web the browser bindings (HTML primitives, history navigation, EventSource live events, createKumikoApp).",
5
5
  "license": "MIT",
6
6
  "author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
@@ -48,8 +48,8 @@
48
48
  }
49
49
  },
50
50
  "dependencies": {
51
- "@cosmicdrift/kumiko-framework": "0.417.0",
52
- "@cosmicdrift/kumiko-types": "0.417.0",
51
+ "@cosmicdrift/kumiko-framework": "0.419.0",
52
+ "@cosmicdrift/kumiko-types": "0.419.0",
53
53
  "@types/qrcode": "^1.5.6",
54
54
  "class-variance-authority": "^0.7.1",
55
55
  "clsx": "^2.1.1",
@@ -79,8 +79,8 @@
79
79
  }
80
80
  },
81
81
  "devDependencies": {
82
- "@cosmicdrift/kumiko-locale-de": "0.417.0",
83
- "@cosmicdrift/kumiko-testing": "0.417.0",
82
+ "@cosmicdrift/kumiko-locale-de": "0.419.0",
83
+ "@cosmicdrift/kumiko-testing": "0.419.0",
84
84
  "@tailwindcss/cli": "^4.3.3",
85
85
  "@testing-library/react": "^16.3.3",
86
86
  "@testing-library/user-event": "^14.6.8",