@cosmicdrift/kumiko-renderer 0.415.0 → 0.417.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 (221) hide show
  1. package/dist/app/action-form-body.d.ts +2 -5
  2. package/dist/app/action-form-body.js +50 -22
  3. package/dist/app/action-form-support.d.ts +4 -1
  4. package/dist/app/action-form-support.js +8 -4
  5. package/dist/app/client-actions.js +6 -4
  6. package/dist/app/config-edit-body.js +83 -82
  7. package/dist/app/entity-list-screen.js +1 -1
  8. package/dist/app/extension-sections.d.ts +2 -0
  9. package/dist/app/header-actions-bar.d.ts +3 -1
  10. package/dist/app/header-actions-bar.js +12 -4
  11. package/dist/app/locked-screen-header.d.ts +2 -0
  12. package/dist/app/locked-screen-header.js +8 -1
  13. package/dist/app/projection-detail-body.js +29 -8
  14. package/dist/app/projection-detail-guidance.d.ts +2 -1
  15. package/dist/app/projection-detail-guidance.js +45 -30
  16. package/dist/app/projection-detail-header-model.d.ts +1 -1
  17. package/dist/app/projection-detail-header-model.js +14 -6
  18. package/dist/app/projection-detail-header-region.js +25 -9
  19. package/dist/app/projection-detail-header.d.ts +2 -0
  20. package/dist/app/projection-detail-header.js +31 -4
  21. package/dist/app/projection-detail-navigation.d.ts +4 -0
  22. package/dist/app/projection-detail-navigation.js +5 -1
  23. package/dist/app/projection-list-shim.js +1 -0
  24. package/dist/app/row-actions.d.ts +4 -0
  25. package/dist/app/row-actions.js +19 -3
  26. package/dist/app/screen-shared.d.ts +1 -0
  27. package/dist/app/screen-shared.js +23 -3
  28. package/dist/app/use-projection-detail-actions.d.ts +16 -1
  29. package/dist/app/use-projection-detail-actions.js +23 -3
  30. package/dist/app/use-projection-detail-data.d.ts +2 -0
  31. package/dist/app/use-projection-detail-data.js +53 -10
  32. package/dist/app/use-projection-list-data.js +1 -1
  33. package/dist/card-options.d.ts +2 -0
  34. package/dist/components/ai-assist-payload.d.ts +2 -0
  35. package/dist/components/ai-assist-payload.js +8 -0
  36. package/dist/components/choice-chip-class.d.ts +1 -0
  37. package/dist/components/choice-chip-class.js +9 -0
  38. package/dist/components/edit-mounts.d.ts +3 -2
  39. package/dist/components/edit-mounts.js +2 -2
  40. package/dist/components/grid-cell-for-field.js +1 -1
  41. package/dist/components/multi-select-chips.d.ts +10 -0
  42. package/dist/components/multi-select-chips.js +19 -0
  43. package/dist/components/narrow-description.d.ts +3 -0
  44. package/dist/components/narrow-description.js +12 -0
  45. package/dist/components/related-list-section.d.ts +5 -3
  46. package/dist/components/related-list-section.js +52 -35
  47. package/dist/components/related-photo-grid.d.ts +11 -0
  48. package/dist/components/related-photo-grid.js +54 -0
  49. package/dist/components/render-edit-action-button.d.ts +2 -2
  50. package/dist/components/render-edit-field-grid.d.ts +12 -3
  51. package/dist/components/render-edit-field-grid.js +60 -18
  52. package/dist/components/render-edit-fields-section.js +45 -11
  53. package/dist/components/render-edit-header-actions.d.ts +2 -1
  54. package/dist/components/render-edit-header-actions.js +18 -1
  55. package/dist/components/render-edit-layout.js +5 -3
  56. package/dist/components/render-edit-logic.js +1 -0
  57. package/dist/components/render-edit-section-kinds.js +59 -10
  58. package/dist/components/render-edit-titles.js +1 -1
  59. package/dist/components/render-edit-types.d.ts +22 -1
  60. package/dist/components/render-field-ai-assist.d.ts +13 -0
  61. package/dist/components/render-field-ai-assist.js +90 -0
  62. package/dist/components/render-field-choice-inputs.js +4 -0
  63. package/dist/components/render-field-control.d.ts +1 -1
  64. package/dist/components/render-field-control.js +19 -9
  65. package/dist/components/render-field-value-chips.d.ts +9 -0
  66. package/dist/components/render-field-value-chips.js +47 -0
  67. package/dist/components/render-field-write-only.js +12 -4
  68. package/dist/components/render-list-hint-columns.d.ts +2 -0
  69. package/dist/components/render-list-hint-columns.js +43 -5
  70. package/dist/components/render-list-reference-columns.js +2 -4
  71. package/dist/components/render-list-row-tone.d.ts +2 -0
  72. package/dist/components/render-list-row-tone.js +6 -0
  73. package/dist/components/render-list-table-props.d.ts +13 -2
  74. package/dist/components/render-list-table-props.js +9 -3
  75. package/dist/components/render-list-types.d.ts +4 -0
  76. package/dist/components/render-list.js +12 -4
  77. package/dist/components/use-render-edit-sections.js +5 -1
  78. package/dist/components/use-render-list-columns.js +3 -3
  79. package/dist/components/write-form-registry.d.ts +13 -0
  80. package/dist/components/write-form-registry.js +6 -0
  81. package/dist/components/write-form-section.d.ts +5 -1
  82. package/dist/components/write-form-section.js +55 -16
  83. package/dist/headless/form/form-controller.d.ts +1 -0
  84. package/dist/headless/form/form-controller.js +1 -1
  85. package/dist/headless/format/index.d.ts +1 -0
  86. package/dist/headless/format/index.js +21 -0
  87. package/dist/headless/format/phone.d.ts +1 -0
  88. package/dist/headless/format/phone.js +8 -0
  89. package/dist/headless/format/relative-time.d.ts +15 -0
  90. package/dist/headless/format/relative-time.js +63 -0
  91. package/dist/headless/format/safe-locale.d.ts +1 -0
  92. package/dist/headless/format/safe-locale.js +13 -0
  93. package/dist/headless/index.d.ts +2 -2
  94. package/dist/headless/index.js +2 -2
  95. package/dist/headless/view-model/edit.d.ts +3 -2
  96. package/dist/headless/view-model/edit.js +162 -36
  97. package/dist/headless/view-model/field-text.d.ts +9 -0
  98. package/dist/headless/view-model/field-text.js +19 -0
  99. package/dist/headless/view-model/index.d.ts +1 -0
  100. package/dist/headless/view-model/index.js +1 -0
  101. package/dist/headless/view-model/list.js +6 -0
  102. package/dist/headless/view-model/types.d.ts +76 -5
  103. package/dist/hooks/use-list-table.js +11 -6
  104. package/dist/i18n-defaults.js +9 -2
  105. package/dist/index.d.ts +1 -1
  106. package/dist/primitives-record-guidance.d.ts +32 -1
  107. package/dist/primitives-share-types.d.ts +82 -0
  108. package/dist/primitives-share-types.js +1 -0
  109. package/dist/primitives.d.ts +44 -86
  110. package/dist/web/app/bold-markup.d.ts +3 -0
  111. package/dist/web/app/bold-markup.js +14 -0
  112. package/dist/web/app/dashboard-body.js +8 -3
  113. package/dist/web/app/dashboard-list-panel.js +8 -4
  114. package/dist/web/app/dashboard-panel-columns.d.ts +9 -0
  115. package/dist/web/app/dashboard-panel-columns.js +14 -0
  116. package/dist/web/app/dashboard-panels.js +31 -3
  117. package/dist/web/app/dashboard-shared.d.ts +3 -1
  118. package/dist/web/app/dashboard-shared.js +4 -4
  119. package/dist/web/app/dashboard-stat-group-panel.d.ts +1 -1
  120. package/dist/web/app/dashboard-stat-group-panel.js +24 -3
  121. package/dist/web/app/dashboard-text-panel.d.ts +1 -0
  122. package/dist/web/app/dashboard-text-panel.js +18 -11
  123. package/dist/web/app/relative-time.d.ts +0 -5
  124. package/dist/web/app/relative-time.js +11 -21
  125. package/dist/web/components/config-cascade.d.ts +2 -1
  126. package/dist/web/components/config-cascade.js +16 -4
  127. package/dist/web/drawn-icons.js +2 -1
  128. package/dist/web/layout/header-action-pinned.d.ts +4 -2
  129. package/dist/web/layout/header-action-pinned.js +13 -4
  130. package/dist/web/layout/header-overflow-menu.d.ts +2 -0
  131. package/dist/web/layout/header-overflow-menu.js +2 -0
  132. package/dist/web/layout/notification-bell.js +12 -3
  133. package/dist/web/layout/page-header-slot.d.ts +2 -0
  134. package/dist/web/layout/page-header-slot.js +4 -0
  135. package/dist/web/layout/screen-focus.js +4 -1
  136. package/dist/web/layout/shell-header.js +13 -5
  137. package/dist/web/primitives/banner.js +24 -8
  138. package/dist/web/primitives/card.js +5 -3
  139. package/dist/web/primitives/combobox.js +2 -2
  140. package/dist/web/primitives/data-table/actions-column.js +1 -1
  141. package/dist/web/primitives/data-table/card-body.d.ts +1 -1
  142. package/dist/web/primitives/data-table/card-body.js +37 -14
  143. package/dist/web/primitives/data-table/card-frame.d.ts +2 -0
  144. package/dist/web/primitives/data-table/card-frame.js +3 -0
  145. package/dist/web/primitives/data-table/card-row.js +34 -10
  146. package/dist/web/primitives/data-table/card-sort-select.js +1 -1
  147. package/dist/web/primitives/data-table/card-view.js +1 -1
  148. package/dist/web/primitives/data-table/data-cell-props.d.ts +4 -1
  149. package/dist/web/primitives/data-table/data-cell-props.js +3 -0
  150. package/dist/web/primitives/data-table/density.d.ts +3 -1
  151. package/dist/web/primitives/data-table/density.js +11 -4
  152. package/dist/web/primitives/data-table/row-click-guard.d.ts +2 -0
  153. package/dist/web/primitives/data-table/row-click-guard.js +19 -0
  154. package/dist/web/primitives/data-table/row-render-parts.d.ts +1 -1
  155. package/dist/web/primitives/data-table/row-render-parts.js +3 -5
  156. package/dist/web/primitives/data-table/sort-options-select.js +2 -2
  157. package/dist/web/primitives/data-table/sortable-header.js +4 -4
  158. package/dist/web/primitives/data-table/table-body.js +3 -1
  159. package/dist/web/primitives/data-table/table-chrome.js +1 -3
  160. package/dist/web/primitives/data-table/table-content.js +6 -6
  161. package/dist/web/primitives/data-table/table-data-cell.js +31 -17
  162. package/dist/web/primitives/data-table/table-header-row.js +1 -1
  163. package/dist/web/primitives/data-table/table-view.js +1 -1
  164. package/dist/web/primitives/data-table/toolbar.js +6 -7
  165. package/dist/web/primitives/data-table/use-data-table-state.d.ts +6 -1
  166. package/dist/web/primitives/data-table/use-data-table-state.js +12 -2
  167. package/dist/web/primitives/data-table-cell.d.ts +17 -3
  168. package/dist/web/primitives/data-table-cell.js +130 -36
  169. package/dist/web/primitives/data-table.js +1 -1
  170. package/dist/web/primitives/default-form.d.ts +1 -1
  171. package/dist/web/primitives/default-form.js +15 -11
  172. package/dist/web/primitives/drawer.js +2 -3
  173. package/dist/web/primitives/facet-filter.d.ts +1 -1
  174. package/dist/web/primitives/facet-filter.js +2 -5
  175. package/dist/web/primitives/facet-search-filter.js +1 -1
  176. package/dist/web/primitives/facet-trigger-label.d.ts +1 -4
  177. package/dist/web/primitives/facet-trigger-label.js +4 -7
  178. package/dist/web/primitives/field.js +15 -8
  179. package/dist/web/primitives/form-footer-parts.js +6 -3
  180. package/dist/web/primitives/form.js +6 -8
  181. package/dist/web/primitives/index.js +4 -0
  182. package/dist/web/primitives/inline-suffix.d.ts +2 -0
  183. package/dist/web/primitives/inline-suffix.js +5 -0
  184. package/dist/web/primitives/input-choice-kinds.js +12 -2
  185. package/dist/web/primitives/input-number-kinds.js +2 -2
  186. package/dist/web/primitives/input-text-kinds.js +1 -1
  187. package/dist/web/primitives/layout-elements.d.ts +4 -4
  188. package/dist/web/primitives/layout-elements.js +50 -13
  189. package/dist/web/primitives/layout.d.ts +1 -1
  190. package/dist/web/primitives/layout.js +1 -1
  191. package/dist/web/primitives/locale-number.d.ts +0 -1
  192. package/dist/web/primitives/locale-number.js +1 -13
  193. package/dist/web/primitives/money-input.js +10 -8
  194. package/dist/web/primitives/narrow-pinned-footer.js +7 -3
  195. package/dist/web/primitives/number-input.d.ts +2 -1
  196. package/dist/web/primitives/number-input.js +11 -5
  197. package/dist/web/primitives/page-header.d.ts +1 -1
  198. package/dist/web/primitives/page-header.js +8 -1
  199. package/dist/web/primitives/pager.js +12 -21
  200. package/dist/web/primitives/photo-grid.d.ts +3 -0
  201. package/dist/web/primitives/photo-grid.js +6 -0
  202. package/dist/web/primitives/record-steps.d.ts +1 -1
  203. package/dist/web/primitives/record-steps.js +7 -16
  204. package/dist/web/primitives/record-summary.d.ts +1 -1
  205. package/dist/web/primitives/record-summary.js +8 -3
  206. package/dist/web/primitives/row-actions.js +38 -24
  207. package/dist/web/primitives/step-list.d.ts +3 -0
  208. package/dist/web/primitives/step-list.js +11 -0
  209. package/dist/web/primitives/use-container-narrow.d.ts +12 -0
  210. package/dist/web/primitives/use-container-narrow.js +42 -0
  211. package/dist/web/ui/input.js +1 -1
  212. package/dist/web/ui/textarea.js +1 -1
  213. package/dist/web/widgets/dashboard-list-cards.js +6 -3
  214. package/dist/web/widgets/dashboard-list.d.ts +6 -1
  215. package/dist/web/widgets/dashboard-list.js +12 -7
  216. package/dist/web/widgets/drawer-panel-class.js +1 -1
  217. package/dist/web/widgets/progress-list.js +1 -1
  218. package/dist/web/widgets/stat-box-cell.js +1 -1
  219. package/package.json +5 -5
  220. package/src/changes.json +105 -0
  221. package/src/web/styles.css +3 -2
@@ -4,13 +4,17 @@ import * as z from "zod";
4
4
  import { ErrorReference } from "../app/error-reference.js";
5
5
  import { isPresent, REQUIRED_FIELD_I18N_KEY } from "../app/form-schema.js";
6
6
  import { dispatcherErrorText } from "../app/write-failed-error.js";
7
+ import { stripUntouchedEmptyStrings } from "../headless/form/form-controller.js";
7
8
  import { I18N_KEY_PARAM } from "../headless/index.js";
8
9
  import { useForm } from "../hooks/use-form.js";
9
10
  import { useTranslation } from "../i18n.js";
10
11
  import { useUnsavedInputSource } from "../leave-guard.js";
11
12
  import { STICKY_PRIMARY_ACTION_PROP, usePrimitives } from "../primitives.js";
12
13
  import { GridCellForField } from "./grid-cell-for-field.js";
14
+ import { narrowAwareDescription } from "./narrow-description.js";
15
+ import { appendixCellProps } from "./render-edit-field-grid.js";
13
16
  import { hasIssueWithoutVisibleField, issuesAfterEdit } from "./render-edit-logic.js";
17
+ import { useWriteFormRegistry } from "./write-form-registry.js";
14
18
  function buildWriteFormSchema(fields) {
15
19
  return z
16
20
  .object({})
@@ -30,13 +34,47 @@ function buildWriteFormSchema(fields) {
30
34
  }
31
35
  });
32
36
  }
37
+ // Only an error no rendered field can show gets the banner.
38
+ function submitErrorNotice(error, fields, translate) {
39
+ const issuePaths = (error.details?.fields ?? []).map((i) => i.path);
40
+ if (!hasIssueWithoutVisibleField(issuePaths, fields))
41
+ return null;
42
+ return {
43
+ message: dispatcherErrorText(error, translate),
44
+ ...(error.requestId !== undefined && { requestId: error.requestId }),
45
+ };
46
+ }
47
+ function useRegisterWriteForm(submitWith, controller, fields) {
48
+ const registry = useWriteFormRegistry();
49
+ useEffect(() => {
50
+ if (submitWith === undefined || registry === null)
51
+ return;
52
+ registry.set(submitWith, {
53
+ validate: () => controller.validate(),
54
+ invalidFieldLabels: () => Object.keys(controller.getSnapshot().errors).map((path) => fields.find((f) => f.field === path)?.label ?? path),
55
+ // Same as controller.submit: an untouched "" would fail an optional enum/email/date in the schema.
56
+ getValues: () => {
57
+ const { values, initial } = controller.getSnapshot();
58
+ return stripUntouchedEmptyStrings(values, initial, new Set());
59
+ },
60
+ rebase: () => controller.rebase(),
61
+ });
62
+ return () => {
63
+ registry.delete(submitWith);
64
+ };
65
+ }, [registry, submitWith, controller, fields]);
66
+ }
67
+ function WriteFormFeedback({ error, submitRow, }) {
68
+ const { Banner, Card } = usePrimitives();
69
+ return (_jsxs(_Fragment, { children: [error !== null && (_jsxs(Banner, { variant: "error", testId: "write-form-section-error", children: [error.message, _jsx(ErrorReference, { requestId: error.requestId })] })), submitRow !== null && (_jsx(Card, { options: { framed: false, footerBordered: false, footerInset: false }, slots: { footer: submitRow }, testId: "write-form-section-submit-row" }))] }));
70
+ }
33
71
  // A self-persisting form section for projectionDetail (see
34
72
  // EditWriteFormSection's doc). Deliberately NOT a nested <RenderEdit> — that
35
73
  // would render a second, invalid nested <form> inside the host's own form
36
74
  // element — so this mounts its own independent useForm() controller and
37
75
  // submits via a plain button click instead of native form submission.
38
- export function WriteFormSection({ section, featureName, translate, hideTitle, onSubmitted, actions, onFooterAction, }) {
39
- const { Section, Card, Grid, GridCell, Button, Banner } = usePrimitives();
76
+ export function WriteFormSection({ section, featureName, translate, hideTitle, labelTitle, onSubmitted, recordValues, actions, onFooterAction, }) {
77
+ const { Section, Card, Grid, GridCell, Button, StatusBadge } = usePrimitives();
40
78
  const t = useTranslation();
41
79
  const effectiveTranslate = translate ?? t;
42
80
  const initial = useMemo(() => Object.fromEntries(section.fields.map((f) => [f.field, f.value])), [section.fields]);
@@ -49,6 +87,8 @@ export function WriteFormSection({ section, featureName, translate, hideTitle, o
49
87
  useUnsavedInputSource(() => controller.getSnapshot().isDirty);
50
88
  const [isSubmitting, setIsSubmitting] = useState(false);
51
89
  const [error, setError] = useState(null);
90
+ const { submitWith } = section;
91
+ useRegisterWriteForm(submitWith, controller, section.fields);
52
92
  async function handleSubmit() {
53
93
  if (isSubmitting)
54
94
  return;
@@ -71,13 +111,7 @@ export function WriteFormSection({ section, featureName, translate, hideTitle, o
71
111
  // GridCellForField/RenderField path RenderEdit uses) — the banner stays
72
112
  // for anything no rendered field can show (`version`, `id`, a root
73
113
  // refine, a hidden field).
74
- const issuePaths = (result.error.details?.fields ?? []).map((i) => i.path);
75
- setError(hasIssueWithoutVisibleField(issuePaths, section.fields)
76
- ? {
77
- message: dispatcherErrorText(result.error, effectiveTranslate),
78
- ...(result.error.requestId !== undefined && { requestId: result.error.requestId }),
79
- }
80
- : null);
114
+ setError(submitErrorNotice(result.error, section.fields, effectiveTranslate));
81
115
  }
82
116
  finally {
83
117
  setIsSubmitting(false);
@@ -90,15 +124,16 @@ export function WriteFormSection({ section, featureName, translate, hideTitle, o
90
124
  // latest handleSubmit through a ref instead of capturing a stale closure.
91
125
  const handleSubmitRef = useRef(handleSubmit);
92
126
  handleSubmitRef.current = handleSubmit;
127
+ const sectionTestId = `write-form-${section.title ?? section.handler}`;
93
128
  const submitLabel = section.submitLabel ?? effectiveTranslate("kumiko.actions.save");
94
129
  const submitButton = (_jsx(Button, { type: "button", variant: "primary", disabled: isSubmitting, loading: isSubmitting, onClick: () => void handleSubmitRef.current(), testId: "write-form-section-submit", [STICKY_PRIMARY_ACTION_PROP]: true, children: submitLabel }));
95
130
  // biome-ignore lint/correctness/useExhaustiveDependencies: submitButton is rebuilt every render; isSubmitting and submitLabel are everything it shows.
96
131
  useEffect(() => {
97
- if (onFooterAction === undefined)
132
+ if (onFooterAction === undefined || submitWith !== undefined)
98
133
  return;
99
134
  onFooterAction(submitButton);
100
135
  return () => onFooterAction(undefined);
101
- }, [onFooterAction, isSubmitting, submitLabel]);
136
+ }, [onFooterAction, submitWith, isSubmitting, submitLabel]);
102
137
  const content = (_jsxs(_Fragment, { children: [_jsx(Grid, { columns: section.columns, children: section.fields.map((field) => (_jsx(GridCellForField, { field: { ...field, value: snapshot.values[field.field] }, columns: section.columns, issues: snapshot.errors[field.field], onChange: (v) => {
103
138
  controller.setField(field.field, v);
104
139
  const errors = controller.getSnapshot().errors;
@@ -106,16 +141,20 @@ export function WriteFormSection({ section, featureName, translate, hideTitle, o
106
141
  if (remaining !== errors)
107
142
  controller.setErrors(remaining);
108
143
  setError(null);
109
- }, GridCell: GridCell, featureName: featureName, allIssues: snapshot.errors, valueDisplay: "form", row: snapshot.values, ...(hideTitle !== true &&
110
- section.title !== undefined && { sectionTitle: section.title }) }, field.field))) }), error !== null && (_jsxs(Banner, { variant: "error", testId: "write-form-section-error", children: [error.message, _jsx(ErrorReference, { requestId: error.requestId })] })), onFooterAction === undefined && (_jsx(Card, { options: { framed: false, footerBordered: false, footerInset: false }, slots: { footer: submitButton }, testId: "write-form-section-submit-row" }))] }));
144
+ }, GridCell: GridCell, featureName: featureName, ...appendixCellProps({}, field, { ...recordValues, ...snapshot.values }, StatusBadge), allIssues: snapshot.errors, valueDisplay: "form", row: snapshot.values, ...(hideTitle !== true &&
145
+ section.title !== undefined && { sectionTitle: section.title }) }, field.field))) }), _jsx(WriteFormFeedback, { error: error, submitRow: onFooterAction === undefined && submitWith === undefined ? submitButton : null })] }));
111
146
  // Section always flattens to a borderless divider when rendered inside
112
147
  // RenderEdit's own <Form> in tabs mode (hideTitle) — an unframed Card panel
113
148
  // stands in, like render-edit.tsx's tabs-mode fields/extension branches.
114
149
  if (hideTitle) {
115
150
  return (_jsx(Card, { options: { framed: false }, slots: {
116
- ...(section.description !== undefined && { subtitle: section.description }),
151
+ ...(section.description !== undefined && {
152
+ subtitle: narrowAwareDescription(section.description, section.descriptionNarrow),
153
+ }),
117
154
  ...(actions !== undefined && { headerActions: actions }),
118
- }, testId: `write-form-${section.title ?? section.handler}`, children: content }));
155
+ }, testId: sectionTestId, children: content }));
119
156
  }
120
- return (_jsx(Section, { ...(section.title !== undefined && { title: section.title }), ...(section.description !== undefined && { subtitle: section.description }), ...(section.icon !== undefined && { icon: section.icon }), ...(actions !== undefined && { actions }), testId: `write-form-${section.title ?? section.handler}`, children: content }));
157
+ return (_jsx(Section, { ...(section.title !== undefined && { title: section.title }), ...(labelTitle === true && { titleStyle: "label" }), ...(section.description !== undefined && {
158
+ subtitle: narrowAwareDescription(section.description, section.descriptionNarrow),
159
+ }), ...(section.icon !== undefined && { icon: section.icon }), ...(actions !== undefined && { actions }), testId: sectionTestId, children: content }));
121
160
  }
@@ -1,2 +1,3 @@
1
1
  import type { FormController, FormControllerOptions, FormValues } from "./types.ts";
2
+ export declare function stripUntouchedEmptyStrings<TValues extends FormValues>(values: TValues, initial: TValues, forceIncludeEmpty: ReadonlySet<string>): TValues;
2
3
  export declare function createFormController<TValues extends FormValues, TCtx = unknown>(options: FormControllerOptions<TValues, TCtx>): FormController<TValues>;
@@ -71,7 +71,7 @@ function isCurrencyOnlyMoney(value) {
71
71
  "currency" in value &&
72
72
  !("amount" in value && value.amount !== undefined));
73
73
  }
74
- function stripUntouchedEmptyStrings(values, initial, forceIncludeEmpty) {
74
+ export function stripUntouchedEmptyStrings(values, initial, forceIncludeEmpty) {
75
75
  const v = values; // @cast-boundary form-values
76
76
  const ini = initial; // @cast-boundary form-values
77
77
  let out;
@@ -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,22 @@ 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, translate) {
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
+ style: isOneOf(RELATIVE_TIME_STYLES, style) ? style : "short",
292
+ absoluteAfterDays: typeof absoluteAfterDays === "number" ? absoluteAfterDays : 7,
293
+ withTime: spec["withTime"] !== false,
294
+ ...(translate !== undefined && { justNow: translate("kumiko.time.justNow") }),
295
+ ...(timeZone !== undefined && { timeZone }),
296
+ });
297
+ }
279
298
  const CELL_FORMATTERS = {
280
299
  timestamp: formatTemporalCell,
281
300
  date: formatTemporalCell,
@@ -287,7 +306,9 @@ const CELL_FORMATTERS = {
287
306
  unit: formatUnitSpecCell,
288
307
  priority: formatPriorityCell,
289
308
  enumOption: formatEnumOptionCell,
309
+ relativeTime: formatRelativeTimeCell,
290
310
  i18nText: formatI18nTextCell,
311
+ phone: (_spec, value) => String(value).trim(),
291
312
  image: formatFileCell,
292
313
  file: formatFileCell,
293
314
  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,15 @@
1
+ export type RelativeTimeOptions = {
2
+ readonly style?: Intl.RelativeTimeFormatStyle;
3
+ readonly absoluteAfterDays?: number;
4
+ readonly withTime?: boolean;
5
+ readonly timeZone?: string;
6
+ /** Translated text for past moments below a minute ("just now") instead of "N seconds ago". */
7
+ readonly justNow?: string;
8
+ };
9
+ /** "5 minutes ago" / "in 30 seconds" in the given locale. The unit grows with the
10
+ * distance (seconds below a minute, minutes below an hour, hours below a day);
11
+ * each step is chosen on the already rounded value so 59.6 minutes reads "1 hour"
12
+ * instead of "60 minutes". From a day on, the distance counts calendar days in
13
+ * `options.timeZone` (default: the runtime's zone), so "yesterday" means the day
14
+ * before today and not 24 hours ago. `numeric: "auto"` yields "now" and "yesterday". */
15
+ export declare function formatRelativeTime(atMs: number, nowMs: number, locale: string | undefined, options?: RelativeTimeOptions): string;
@@ -0,0 +1,63 @@
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
+ if (options.justNow !== undefined && seconds <= 0)
43
+ return options.justNow;
44
+ return formatter.format(seconds, "second");
45
+ }
46
+ const minutes = Math.round(seconds / SECONDS_PER_MINUTE);
47
+ if (Math.abs(minutes) < MINUTES_PER_HOUR)
48
+ return formatter.format(minutes, "minute");
49
+ const hours = Math.round(minutes / MINUTES_PER_HOUR);
50
+ if (Math.abs(hours) < HOURS_PER_DAY)
51
+ return formatter.format(hours, "hour");
52
+ const days = calendarDayNumber(atMs, options.timeZone) - calendarDayNumber(nowMs, options.timeZone);
53
+ // 23.5+ hours inside one calendar day still reads as hours, never as "today".
54
+ if (days === 0)
55
+ return formatter.format(hours, "hour");
56
+ if (options.absoluteAfterDays !== undefined && Math.abs(days) >= options.absoluteAfterDays) {
57
+ return formatAbsolute(atMs, safeLocale, options);
58
+ }
59
+ const relative = formatter.format(days, "day");
60
+ return days === -1 && options.withTime === true
61
+ ? `${relative}, ${formatClock(atMs, safeLocale, options.timeZone)}`
62
+ : relative;
63
+ }
@@ -0,0 +1 @@
1
+ export declare function resolveSafeLocale(locale: string | undefined): string;
@@ -0,0 +1,13 @@
1
+ const FALLBACK_LOCALE = "en-US";
2
+ // An invalid tag makes every Intl constructor and toLocaleString throw a
3
+ // RangeError; without an ErrorBoundary that would take down the page on
4
+ // focus/blur. Canonicalizing once up front keeps all call sites safe.
5
+ export function resolveSafeLocale(locale) {
6
+ const candidate = locale ?? (typeof navigator !== "undefined" ? navigator.language : undefined) ?? "";
7
+ try {
8
+ return Intl.getCanonicalLocales(candidate)[0] ?? FALLBACK_LOCALE;
9
+ }
10
+ catch {
11
+ return FALLBACK_LOCALE;
12
+ }
13
+ }
@@ -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, toInstant, } from "./format/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";
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";
@@ -13,4 +13,4 @@ export { PWA_CACHE_NAME_PREFIX, PWA_CACHE_SCOPE_HASH_LENGTH, PWA_SERVICE_WORKER_
13
13
  export type { Store, WritableStore } from "./store/index.ts";
14
14
  export { createStore, shallowEqual } from "./store/index.ts";
15
15
  export type { CellLink, CellLinkItem, ComputeEditViewModelInput, ComputeListViewModelInput, DerivedCellRoundingTarget, EditExtensionSectionViewModel, EditFieldSpec, EditFieldsSectionViewModel, EditFieldViewModel, EditFormMode, EditRelatedListSectionViewModel, EditSectionSpec, EditSectionViewModel, EditViewModel, EditWriteFormSectionViewModel, EmbeddedDerivedOp, EmbeddedListCellViewModel, EmbeddedListIssueGroups, FieldConditionCtx, FieldRenderer, ListColumnCellDisplay, ListColumnFileDisplay, ListColumnHintViewModel, ListColumnSpec, ListColumnViewModel, ListRowViewModel, ListViewModel, RuntimeCellLink, RuntimeCellLinkItems, RuntimeRenderer, ScreenSlots, Translate, } from "./view-model/index.ts";
16
- export { buildOptionLabels, computeDerivedCellValue, computeEditViewModel, computeListViewModel, computeRelatedListSectionViewModel, embeddedCellLabelKey, embeddedCellOptionLabelKey, fieldLabelKey, fieldOptionLabelKey, fieldOptionLabelKeyPrefix, groupEmbeddedListIssues, roundDerivedCellValue, sumEmbeddedListColumn, withDerivedCells, } from "./view-model/index.ts";
16
+ export { buildOptionLabels, computeDerivedCellValue, computeEditViewModel, computeListViewModel, computeRelatedListSectionViewModel, embeddedCellLabelKey, embeddedCellOptionLabelKey, fieldLabelKey, fieldOptionLabelKey, fieldOptionLabelKeyPrefix, fieldTextKey, groupEmbeddedListIssues, resolveFieldText, roundDerivedCellValue, sumEmbeddedListColumn, withDerivedCells, } from "./view-model/index.ts";
@@ -3,9 +3,9 @@
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, toInstant, } from "./format/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";
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";
10
10
  export { createStore, shallowEqual } from "./store/index.js";
11
- export { buildOptionLabels, computeDerivedCellValue, computeEditViewModel, computeListViewModel, computeRelatedListSectionViewModel, embeddedCellLabelKey, embeddedCellOptionLabelKey, fieldLabelKey, fieldOptionLabelKey, fieldOptionLabelKeyPrefix, groupEmbeddedListIssues, roundDerivedCellValue, sumEmbeddedListColumn, withDerivedCells, } from "./view-model/index.js";
11
+ export { buildOptionLabels, computeDerivedCellValue, computeEditViewModel, computeListViewModel, computeRelatedListSectionViewModel, embeddedCellLabelKey, embeddedCellOptionLabelKey, fieldLabelKey, fieldOptionLabelKey, fieldOptionLabelKeyPrefix, fieldTextKey, groupEmbeddedListIssues, resolveFieldText, roundDerivedCellValue, sumEmbeddedListColumn, withDerivedCells, } from "./view-model/index.js";
@@ -1,5 +1,5 @@
1
- import type { EditRelatedListSection, EntityDefinition, EntityEditScreenDefinition, FormDerivationScreen } from "@cosmicdrift/kumiko-framework/ui-types";
2
- import type { EditRelatedListSectionViewModel, EditViewModel, Translate } from "./types.ts";
1
+ import type { EditRelatedListSection, EditStepListSection, EntityDefinition, EntityEditScreenDefinition, FormDerivationScreen } from "@cosmicdrift/kumiko-framework/ui-types";
2
+ import type { EditRelatedListSectionViewModel, EditStepListSectionViewModel, EditViewModel, Translate } from "./types.ts";
3
3
  export type ComputeEditViewModelInput<TValues extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>> = {
4
4
  readonly screen: EntityEditScreenDefinition;
5
5
  readonly entity: Pick<EntityDefinition, "fields" | "defaultCurrency">;
@@ -21,5 +21,6 @@ export type ComputeEditViewModelInput<TValues extends Readonly<Record<string, un
21
21
  readonly actionFormScreenQn?: string;
22
22
  };
23
23
  export type EditFormMode = "create" | "update";
24
+ export declare function computeStepListSectionViewModel(sectionSpec: EditStepListSection, values: Readonly<Record<string, unknown>>, translate: Translate): EditStepListSectionViewModel;
24
25
  export declare function computeRelatedListSectionViewModel(sectionSpec: EditRelatedListSection, translate: Translate): EditRelatedListSectionViewModel;
25
26
  export declare function computeEditViewModel<TValues extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>>(input: ComputeEditViewModelInput<TValues>): EditViewModel;