@phis/ui 0.5.3 → 0.5.5

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 (211) hide show
  1. package/components/cms/phi-cms-layout-renderer.js +17 -7
  2. package/components/controls/phi-cascader-control.d.ts +9 -1
  3. package/components/controls/phi-cascader-control.js +25 -3
  4. package/components/controls/phi-money-control.d.ts +39 -0
  5. package/components/controls/phi-money-control.js +34 -0
  6. package/components/controls/phi-number-control.d.ts +6 -1
  7. package/components/controls/phi-number-control.js +3 -3
  8. package/components/controls/phi-options-provider.d.ts +7 -0
  9. package/components/controls/phi-options-provider.js +11 -0
  10. package/components/forms/extended-form-field-controls.d.ts +1 -0
  11. package/components/forms/extended-form-field-controls.js +23 -1
  12. package/components/forms/form-descriptor-runtime-client.js +13 -0
  13. package/components/forms/form-provider-contract.d.ts +43 -0
  14. package/components/forms/form-provider-contract.js +40 -0
  15. package/components/forms/money-field.d.ts +27 -0
  16. package/components/forms/money-field.js +78 -0
  17. package/components/forms/shared-form-provider-registry.js +4 -0
  18. package/components/layouts/clients/phi-flex-layout-client.js +17 -2
  19. package/components/layouts/clients/phi-layout-anchored-overlay.d.ts +2 -0
  20. package/components/layouts/clients/phi-layout-anchored-overlay.js +2 -0
  21. package/components/media/phi-media-picker-binding.js +6 -1
  22. package/components/media/phi-site-font-assets.js +6 -1
  23. package/components/motion/phi-sequence-run.d.ts +14 -1
  24. package/components/motion/phi-sequence-run.js +22 -3
  25. package/components/motion/phi-sequence-viewport.js +3 -1
  26. package/components/regions/presets/content-entry-editor-page-tree.js +5 -1
  27. package/components/regions/presets/content-entry-public-page-trees.js +2 -0
  28. package/components/tables/client/phi-table-binding.js +16 -3
  29. package/components/trees/client/phi-tree-binding.js +6 -2
  30. package/components/widgets/builder/stack-tabs.d.ts +2 -1
  31. package/components/widgets/builder/stack-tabs.js +18 -2
  32. package/components/widgets/client/shared/phi-collection-view-binding.js +10 -2
  33. package/components/widgets/client/shared/phi-rendered-value.d.ts +9 -1
  34. package/components/widgets/client/shared/phi-rendered-value.js +20 -1
  35. package/components/widgets/config/choice-shared.d.ts +1 -49
  36. package/components/widgets/config/choice-shared.js +0 -1
  37. package/components/widgets/config/stack-tabs.js +4 -3
  38. package/components/widgets/label-sets/gallery.js +6 -0
  39. package/components/widgets/label-sets/interval.d.ts +4 -0
  40. package/components/widgets/label-sets/interval.js +31 -0
  41. package/components/widgets/label-sets/record.js +6 -1
  42. package/components/widgets/label-sets/slot-upload.d.ts +4 -0
  43. package/components/widgets/label-sets/slot-upload.js +36 -0
  44. package/components/widgets/label-sets/table.js +6 -1
  45. package/components/widgets/label-types/gallery.d.ts +7 -0
  46. package/components/widgets/label-types/gallery.js +6 -0
  47. package/components/widgets/label-types/interval.d.ts +16 -0
  48. package/components/widgets/label-types/interval.js +21 -0
  49. package/components/widgets/label-types/record.d.ts +3 -0
  50. package/components/widgets/label-types/record.js +2 -0
  51. package/components/widgets/label-types/slot-upload.d.ts +24 -0
  52. package/components/widgets/label-types/slot-upload.js +16 -0
  53. package/components/widgets/label-types/table.d.ts +3 -0
  54. package/components/widgets/label-types/table.js +2 -0
  55. package/constants/record-field-kinds.d.ts +1 -1
  56. package/constants/record-field-kinds.js +1 -1
  57. package/constants/runtime-module-ownership.js +1 -0
  58. package/controls.d.ts +7 -0
  59. package/controls.js +4 -0
  60. package/helpers/cms-dialog.d.ts +39 -3
  61. package/helpers/cms-dialog.js +46 -4
  62. package/helpers/cms-page-catalog.d.ts +8 -0
  63. package/helpers/cms-page-catalog.js +18 -2
  64. package/helpers/cms-preset-nodes.d.ts +13 -3
  65. package/helpers/cms-preset-nodes.js +3 -2
  66. package/helpers/config-text-fields.d.ts +49 -0
  67. package/helpers/config-text-fields.js +122 -0
  68. package/helpers/money-amount.d.ts +48 -0
  69. package/helpers/money-amount.js +131 -0
  70. package/helpers/page-layout-check.js +15 -2
  71. package/helpers/preset-text-source-check.d.ts +22 -0
  72. package/helpers/preset-text-source-check.js +45 -0
  73. package/helpers/record-fields.d.ts +18 -5
  74. package/helpers/record-fields.js +38 -13
  75. package/helpers/text-source.d.ts +14 -5
  76. package/helpers/text-source.js +16 -3
  77. package/module-page-check.d.ts +1 -0
  78. package/module-page-check.js +1 -0
  79. package/module-records.d.ts +6 -3
  80. package/module-records.js +4 -2
  81. package/package.json +2 -2
  82. package/plugins/runtime/phi-slot-child-frame-view.js +1 -1
  83. package/plugins/runtime/slot-size-policy.d.ts +8 -2
  84. package/plugins/runtime/slot-size-policy.js +51 -16
  85. package/plugins/runtime-modules/accounting/module.d.ts +1 -1
  86. package/plugins/runtime-modules/accounting/trees/phi-default-accounting-page-tree.js +2 -0
  87. package/plugins/runtime-modules/app/module.d.ts +1 -1
  88. package/plugins/runtime-modules/asset/services/collection.js +1 -0
  89. package/plugins/runtime-modules/asset/trees/phi-default-builder-media-page-tree.js +2 -2
  90. package/plugins/runtime-modules/auth/trees/phi-default-admin-auth-settings-page-tree.js +3 -0
  91. package/plugins/runtime-modules/builder/clients/widget-inspector.js +2 -2
  92. package/plugins/runtime-modules/builder/offered-page-catalog.js +3 -3
  93. package/plugins/runtime-modules/builder/options-providers.js +7 -0
  94. package/plugins/runtime-modules/builder/trees/phi-builder-inspector-area-overlay-tree.server.js +3 -0
  95. package/plugins/runtime-modules/builder/trees/phi-default-builder-area-preset-tree.js +17 -3
  96. package/plugins/runtime-modules/contracts.d.ts +1 -1
  97. package/plugins/runtime-modules/core/definition.d.ts +43 -0
  98. package/plugins/runtime-modules/core/form-providers.d.ts +43 -0
  99. package/plugins/runtime-modules/core/widgets/breadcrumb/client.d.ts +6 -3
  100. package/plugins/runtime-modules/core/widgets/breadcrumb/client.js +6 -5
  101. package/plugins/runtime-modules/core/widgets/breadcrumb/plugin.js +1 -1
  102. package/plugins/runtime-modules/core/widgets/breadcrumb/server.d.ts +9 -1
  103. package/plugins/runtime-modules/core/widgets/breadcrumb/server.js +29 -3
  104. package/plugins/runtime-modules/core/widgets/button/config.d.ts +0 -1
  105. package/plugins/runtime-modules/core/widgets/button/config.js +0 -1
  106. package/plugins/runtime-modules/core/widgets/button/plugin.js +6 -25
  107. package/plugins/runtime-modules/core/widgets/card/config.d.ts +18 -2
  108. package/plugins/runtime-modules/core/widgets/card/config.js +16 -1
  109. package/plugins/runtime-modules/core/widgets/card/plugin.js +8 -10
  110. package/plugins/runtime-modules/core/widgets/card/server.d.ts +1 -2
  111. package/plugins/runtime-modules/core/widgets/card/server.js +16 -28
  112. package/plugins/runtime-modules/core/widgets/cascader/authoring.d.ts +4 -3
  113. package/plugins/runtime-modules/core/widgets/cascader/client.js +1 -1
  114. package/plugins/runtime-modules/core/widgets/cascader/config.d.ts +8 -2
  115. package/plugins/runtime-modules/core/widgets/cascader/config.js +22 -0
  116. package/plugins/runtime-modules/core/widgets/checkbox-group/config.d.ts +8 -2
  117. package/plugins/runtime-modules/core/widgets/checkbox-group/config.js +1 -1
  118. package/plugins/runtime-modules/core/widgets/description/config.d.ts +2 -1
  119. package/plugins/runtime-modules/core/widgets/entry-list/config.d.ts +2 -2
  120. package/plugins/runtime-modules/core/widgets/entry-list/config.js +0 -1
  121. package/plugins/runtime-modules/core/widgets/entry-list/plugin.js +1 -3
  122. package/plugins/runtime-modules/core/widgets/entry-list/server.d.ts +1 -3
  123. package/plugins/runtime-modules/core/widgets/entry-list/server.js +3 -3
  124. package/plugins/runtime-modules/core/widgets/gallery/authoring.js +12 -3
  125. package/plugins/runtime-modules/core/widgets/gallery/client.js +10 -1
  126. package/plugins/runtime-modules/core/widgets/gallery/config.d.ts +4 -1
  127. package/plugins/runtime-modules/core/widgets/gallery/config.js +8 -0
  128. package/plugins/runtime-modules/core/widgets/gallery/server.d.ts +1 -1
  129. package/plugins/runtime-modules/core/widgets/image/server.js +5 -9
  130. package/plugins/runtime-modules/core/widgets/markdown/config.d.ts +2 -1
  131. package/plugins/runtime-modules/core/widgets/markdown-toc/server.js +3 -5
  132. package/plugins/runtime-modules/core/widgets/multi-select/config.d.ts +1 -1
  133. package/plugins/runtime-modules/core/widgets/quick-links/plugin.js +2 -4
  134. package/plugins/runtime-modules/core/widgets/quick-links/server.d.ts +2 -5
  135. package/plugins/runtime-modules/core/widgets/quick-links/server.js +2 -6
  136. package/plugins/runtime-modules/core/widgets/record/client.js +8 -2
  137. package/plugins/runtime-modules/core/widgets/record/config.js +4 -0
  138. package/plugins/runtime-modules/core/widgets/result/config.d.ts +2 -2
  139. package/plugins/runtime-modules/core/widgets/result/config.js +0 -1
  140. package/plugins/runtime-modules/core/widgets/result/plugin.js +2 -4
  141. package/plugins/runtime-modules/core/widgets/result/server.d.ts +2 -3
  142. package/plugins/runtime-modules/core/widgets/result/server.js +11 -33
  143. package/plugins/runtime-modules/core/widgets/segmented/config.d.ts +1 -1
  144. package/plugins/runtime-modules/core/widgets/select-box/config.d.ts +1 -1
  145. package/plugins/runtime-modules/core/widgets/simple-text/config.d.ts +2 -1
  146. package/plugins/runtime-modules/core/widgets/simple-text/plugin.js +1 -1
  147. package/plugins/runtime-modules/core/widgets/slider/config.d.ts +11 -0
  148. package/plugins/runtime-modules/core/widgets/slider/config.js +1 -1
  149. package/plugins/runtime-modules/core/widgets/slot-upload/authoring.js +2 -1
  150. package/plugins/runtime-modules/core/widgets/slot-upload/client.d.ts +3 -1
  151. package/plugins/runtime-modules/core/widgets/slot-upload/client.js +45 -24
  152. package/plugins/runtime-modules/core/widgets/slot-upload/config.d.ts +11 -4
  153. package/plugins/runtime-modules/core/widgets/slot-upload/config.js +16 -1
  154. package/plugins/runtime-modules/core/widgets/slot-upload/plugin.js +2 -2
  155. package/plugins/runtime-modules/core/widgets/slot-upload/server.d.ts +8 -3
  156. package/plugins/runtime-modules/core/widgets/slot-upload/server.js +9 -3
  157. package/plugins/runtime-modules/core/widgets/spacer/config.d.ts +1 -1
  158. package/plugins/runtime-modules/core/widgets/spacer/config.js +1 -1
  159. package/plugins/runtime-modules/core/widgets/steps/config.d.ts +8 -3
  160. package/plugins/runtime-modules/core/widgets/steps/config.js +1 -2
  161. package/plugins/runtime-modules/core/widgets/steps/plugin.js +6 -30
  162. package/plugins/runtime-modules/core/widgets/table/client.js +4 -4
  163. package/plugins/runtime-modules/core/widgets/table/config.d.ts +6 -3
  164. package/plugins/runtime-modules/core/widgets/table/config.js +4 -1
  165. package/plugins/runtime-modules/core/widgets/timeline/config.d.ts +8 -1
  166. package/plugins/runtime-modules/core/widgets/timeline/config.js +1 -2
  167. package/plugins/runtime-modules/core/widgets/timeline/plugin.js +6 -37
  168. package/plugins/runtime-modules/descriptor-compiler.d.ts +11 -1
  169. package/plugins/runtime-modules/descriptor-compiler.js +49 -8
  170. package/plugins/runtime-modules/groups/definition.d.ts +1 -1
  171. package/plugins/runtime-modules/groups/forms.d.ts +18 -0
  172. package/plugins/runtime-modules/groups/forms.js +2 -2
  173. package/plugins/runtime-modules/groups/trees/phi-default-admin-groups-page-tree.js +8 -4
  174. package/plugins/runtime-modules/groups/trees/phi-default-app-groups-page-tree.js +2 -0
  175. package/plugins/runtime-modules/localization/trees/phi-default-editor-translations-page-tree.js +3 -0
  176. package/plugins/runtime-modules/page-preset-overlays.d.ts +18 -0
  177. package/plugins/runtime-modules/page-preset-overlays.js +70 -0
  178. package/plugins/runtime-modules/public/module.d.ts +1 -1
  179. package/plugins/runtime-modules/public/trees/phi-default-pub-welcome-page-tree.js +1 -0
  180. package/plugins/runtime-modules/resolver.js +5 -0
  181. package/plugins/runtime-modules/revisions/trees/phi-default-builder-revisions-page-tree.js +5 -2
  182. package/plugins/runtime-modules/search/widgets/search-box/server.js +3 -5
  183. package/plugins/runtime-modules/search/widgets/search-results/server.js +3 -5
  184. package/plugins/runtime-modules/theme/trees/phi-default-builder-theme-page-tree.js +4 -0
  185. package/plugins/runtime-modules/threads/trees/phi-default-threads-page-tree.js +6 -2
  186. package/plugins/runtime-modules/user-management/controller/client.js +6 -1
  187. package/plugins/runtime-modules/user-management/trees/phi-default-admin-users-page-tree.js +5 -3
  188. package/runtime-render-client.d.ts +1 -1
  189. package/runtime-render-client.js +2 -1
  190. package/server-helpers/cms-page-record.d.ts +2 -2
  191. package/server-helpers/cms-page-record.js +15 -5
  192. package/server-helpers/cms-request.js +34 -12
  193. package/server-helpers/cms-widget-texts.d.ts +14 -0
  194. package/server-helpers/cms-widget-texts.js +117 -0
  195. package/server-helpers/record-fields.d.ts +1 -1
  196. package/server-helpers/record-fields.js +1 -2
  197. package/server-helpers/record-samples.d.ts +4 -4
  198. package/server-helpers/record-samples.js +10 -2
  199. package/server-helpers/search-index.js +12 -3
  200. package/styles/root.css +6 -2
  201. package/types/cms-module-descriptors.d.ts +3 -0
  202. package/types/cms-plugins.d.ts +38 -5
  203. package/types/collection-provider.d.ts +7 -0
  204. package/types/core-widget-placements.d.ts +37 -0
  205. package/types/record-provider.d.ts +19 -3
  206. package/types/slot-size-policy.d.ts +19 -2
  207. package/types/table-widget.d.ts +33 -1
  208. package/types/table-widget.js +1 -0
  209. package/types/tree-widget.d.ts +7 -0
  210. package/types/widget-runtime.d.ts +1 -1
  211. package/types.d.ts +1 -0
@@ -58,6 +58,14 @@ export function createPhiLayoutOwnTextTranslator(plugin, node, runtime) {
58
58
  return texts.map((text, index) => (text.trim() ? translated[index]?.trim() || text : text));
59
59
  };
60
60
  }
61
+ /**
62
+ * The tree with its Widgets' words in the reader's language (`server-helpers/cms-widget-texts.ts`),
63
+ * imported lazily as the passes beside it are.
64
+ */
65
+ async function translatePhiCmsTreeWidgetTexts(tree, registry, runtime) {
66
+ const { translatePhiCmsTreeWidgetTexts: translate } = await import("../../server-helpers/cms-widget-texts");
67
+ return translate(tree, registry, runtime);
68
+ }
61
69
  /** Lazily imported for the reason above: the pass is `server-only`, the helpers beside it are not. */
62
70
  async function resolvePhiCmsTreeLinkTargets(...args) {
63
71
  const { resolvePhiCmsTreeLinkTargets: resolve } = await import("../../server-helpers/cms-link-targets");
@@ -268,16 +276,17 @@ function buildLayoutTree(tree, blockDefaultsByType) {
268
276
  });
269
277
  }
270
278
  export async function preparePhiCmsOverlayRenderContext({ tree, runtime, registry, signalScope, }) {
271
- const [featureResolution, links] = await Promise.all([
279
+ const [featureResolution, links, translatedTree] = await Promise.all([
272
280
  resolvePhiCmsTreeFeatures(tree, registry, runtime),
273
281
  resolvePhiCmsTreeLinkTargets(tree, runtime),
282
+ translatePhiCmsTreeWidgetTexts(tree, registry, runtime),
274
283
  ]);
275
284
  return {
276
- tree,
285
+ tree: translatedTree,
277
286
  runtime,
278
287
  registry,
279
288
  signalScope,
280
- createNode: buildLayoutNodeResolver(tree, registry.widgetBlockDefaultsByType),
289
+ createNode: buildLayoutNodeResolver(translatedTree, registry.widgetBlockDefaultsByType),
281
290
  // From the whole tree, not the Overlay alone: a block is a participant when anything in the tree
282
291
  // addresses it, and that is the same answer whether the zones render with the page or on demand.
283
292
  signalParticipants: resolvePhiTreeSignalParticipants(tree),
@@ -739,14 +748,15 @@ function renderLayoutNode(node, context) {
739
748
  return (_jsxs("div", { "data-phi-cms-orphaned-layout": node.widgetType, style: { display: "flex", flexDirection: "column", gap: 21, width: "100%", minWidth: 0 }, children: [diagnostic, orphanedChildren] }));
740
749
  }
741
750
  export async function PhiCmsLayoutRenderer({ tree, runtime, regionClassName, regionTypes, stackGap = 21, registry, }) {
742
- const filteredTree = filterPhiCmsRenderableTreeForViewer({
751
+ const viewerTree = filterPhiCmsRenderableTreeForViewer({
743
752
  tree,
744
753
  viewer: runtime.viewer,
745
754
  registry,
746
755
  });
747
- const [{ features, failures: featureFailures }, links] = await Promise.all([
748
- resolvePhiCmsTreeFeatures(filteredTree, registry, runtime),
749
- resolvePhiCmsTreeLinkTargets(filteredTree, runtime),
756
+ const [{ features, failures: featureFailures }, links, filteredTree] = await Promise.all([
757
+ resolvePhiCmsTreeFeatures(viewerTree, registry, runtime),
758
+ resolvePhiCmsTreeLinkTargets(viewerTree, runtime),
759
+ translatePhiCmsTreeWidgetTexts(viewerTree, registry, runtime),
750
760
  ]);
751
761
  const signalParticipants = resolvePhiTreeSignalParticipants(filteredTree);
752
762
  const allowedRegionTypes = regionTypes ? new Set(regionTypes) : null;
@@ -5,17 +5,25 @@ import type { PhiControlOption } from "./phi-control-options";
5
5
  import type { PhiTreeOption } from "../../types/tree";
6
6
  export type PhiCascaderNormalizeMode = "raw" | "path";
7
7
  export type PhiCascaderOption = PhiControlOption;
8
+ /** What a click may choose (`PhiCascaderControl`'s `select`). */
9
+ export type PhiCascaderSelect = "any" | "options";
8
10
  export declare function normalizePhiCascaderValue(value: string | null | undefined, options?: {
9
11
  separator?: string | null;
10
12
  rootValue?: string | null;
11
13
  normalize?: PhiCascaderNormalizeMode | null;
12
14
  }): string;
13
- export declare function PhiCascaderControl({ value, options, allowRoot, allowClear, expandTrigger, separator, rootValue, normalize, disabled, readOnly, label, placeholder, size, onChange, onFocus, onBlur, classNames, getPopupContainer, style, }: {
15
+ export declare function PhiCascaderControl({ value, options, allowRoot, allowClear, expandTrigger, select, separator, rootValue, normalize, disabled, readOnly, label, placeholder, size, onChange, onFocus, onBlur, classNames, getPopupContainer, style, }: {
14
16
  value?: string | null;
15
17
  options?: readonly PhiCascaderOption[];
16
18
  allowRoot?: boolean;
17
19
  allowClear?: boolean;
18
20
  expandTrigger?: CascaderProps["expandTrigger"];
21
+ /**
22
+ * What a click may choose. `any` (the default) takes every level, so a path picker can stop at a parent;
23
+ * `options` takes only a value the options name, and a level the Cascader made up from deeper paths is a
24
+ * group that opens and chooses nothing -- a page picker, whose folders are no Pages.
25
+ */
26
+ select?: PhiCascaderSelect;
19
27
  separator?: string;
20
28
  rootValue?: string;
21
29
  normalize?: PhiCascaderNormalizeMode;
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useMemo, useState } from "react";
3
+ import { useMemo, useRef, useState } from "react";
4
4
  import { Cascader } from "antd";
5
5
  import { PhiLabeledControl, usePhiControlLabel } from "./phi-labeled-control";
6
6
  import { PhiDescriptionHint } from "./phi-description-tooltip-icon";
@@ -135,7 +135,7 @@ function buildCascaderOptions(configuredOptions, currentValue, allowRoot, separa
135
135
  insertCascaderOption(options, { value: currentValue, label: titleizeSegment(currentValue, rootValue) }, allowRoot, separator, rootValue, normalize);
136
136
  return options;
137
137
  }
138
- export function PhiCascaderControl({ value, options, allowRoot = true, allowClear = false, expandTrigger = "click", separator = "/", rootValue = "/", normalize = "raw", disabled = false, readOnly = false, label, placeholder, size, onChange, onFocus, onBlur, classNames, getPopupContainer, style, }) {
138
+ export function PhiCascaderControl({ value, options, allowRoot = true, allowClear = false, expandTrigger = "click", select = "any", separator = "/", rootValue = "/", normalize = "raw", disabled = false, readOnly = false, label, placeholder, size, onChange, onFocus, onBlur, classNames, getPopupContainer, style, }) {
139
139
  const { labelId, labelledBy } = usePhiControlLabel(label);
140
140
  const { token } = usePhiConfig();
141
141
  const resolvedSeparator = separator.trim() || "/";
@@ -146,8 +146,20 @@ export function PhiCascaderControl({ value, options, allowRoot = true, allowClea
146
146
  normalize,
147
147
  });
148
148
  const [searchValue, setSearchValue] = useState("");
149
+ /*
150
+ * A click on a level that chooses nothing (`select: "options"`) still closes Ant Design's popup, the way
151
+ * a choice does. It stays open instead, on the level that was opened, so the click reads as "show me
152
+ * what is in here" rather than as nothing.
153
+ */
154
+ const [open, setOpen] = useState(false);
155
+ const keepOpen = useRef(false);
149
156
  const cascaderOptions = useMemo(() => buildCascaderOptions(options ?? [], normalizedValue, allowRoot, resolvedSeparator, resolvedRootValue, normalize), [allowRoot, normalize, normalizedValue, options, resolvedRootValue, resolvedSeparator]);
150
157
  const cascaderValue = findOptionPath(cascaderOptions, normalizedValue, resolvedSeparator, resolvedRootValue) ?? [];
158
+ const choosableValues = useMemo(() => new Set((options ?? []).map((option) => normalizePhiCascaderValue(option.value, {
159
+ separator: resolvedSeparator,
160
+ rootValue: resolvedRootValue,
161
+ normalize,
162
+ }))), [normalize, options, resolvedRootValue, resolvedSeparator]);
151
163
  function commit(nextValue) {
152
164
  const normalizedNextValue = normalizePhiCascaderValue(nextValue, {
153
165
  separator: resolvedSeparator,
@@ -157,10 +169,20 @@ export function PhiCascaderControl({ value, options, allowRoot = true, allowClea
157
169
  if (!allowRoot && normalizedNextValue === resolvedRootValue) {
158
170
  return;
159
171
  }
172
+ if (select === "options" && !choosableValues.has(normalizedNextValue)) {
173
+ keepOpen.current = true;
174
+ return;
175
+ }
160
176
  setSearchValue("");
161
177
  onChange?.(normalizedNextValue);
162
178
  }
163
- const control = (_jsx(Cascader, { "aria-labelledby": labelledBy, allowClear: allowClear, changeOnSelect: true, expandTrigger: expandTrigger, rootClassName: "phi-cascader-control", disabled: disabled || readOnly || !onChange, displayRender: (_, selectedOptions) => {
179
+ const control = (_jsx(Cascader, { "aria-labelledby": labelledBy, allowClear: allowClear, changeOnSelect: true, expandTrigger: expandTrigger, open: open, onOpenChange: (next) => {
180
+ if (!next && keepOpen.current) {
181
+ keepOpen.current = false;
182
+ return;
183
+ }
184
+ setOpen(next);
185
+ }, rootClassName: "phi-cascader-control", disabled: disabled || readOnly || !onChange, displayRender: (_, selectedOptions) => {
164
186
  const selectedLabels = (selectedOptions ?? [])
165
187
  .map((option) => option.label)
166
188
  .filter((label) => label != null);
@@ -0,0 +1,39 @@
1
+ import type { CSSProperties, FocusEventHandler } from "react";
2
+ import type { PhiControlSize, PhiControlVariant } from "../../types/control";
3
+ export type PhiMoneyControlProps = {
4
+ /** The DOM id of the input, so a `<label for>` outside the control can name it. */
5
+ id?: string;
6
+ /** The amount in minor units, a canonical integer string (`PhisPaymentMoney.minor`); `null` for none. */
7
+ value?: string | null;
8
+ /** The ISO 4217 code the amount is in; it decides how many places the number has. */
9
+ currency: string;
10
+ /** The page's locale, for how the number is written (`usePhiIntlLocale`). */
11
+ locale: string;
12
+ /** The least and the most the amount may be, in minor units. Nothing below zero is an amount. */
13
+ min?: string;
14
+ max?: string;
15
+ label?: string;
16
+ /** The field's accessible name where it shows no `label`. */
17
+ ariaLabel?: string;
18
+ placeholder?: string;
19
+ disabled?: boolean;
20
+ readOnly?: boolean;
21
+ size?: PhiControlSize;
22
+ variant?: PhiControlVariant;
23
+ style?: CSSProperties;
24
+ onChange?: (minor: string | null) => void;
25
+ onBlur?: FocusEventHandler<HTMLInputElement>;
26
+ };
27
+ /**
28
+ * An amount of money: minor units in and out, major units on screen, the currency beside the number.
29
+ *
30
+ * The number is held as a decimal string (`stringMode`), never as a float, and converted on its digits
31
+ * (`helpers/money-amount.ts`). It is written the way the page's locale writes numbers once the field is
32
+ * left, and while somebody types it shows exactly what they typed -- reformatting under the caret moves
33
+ * it. Leaving the field rounds to the currency's places and brings the amount into `min`..`max`.
34
+ *
35
+ * The currency is its ISO code, on the side the locale puts it ("CHF 12.50", "12,50 EUR"), and it is
36
+ * shown with an empty field too: unlike a unit, it says what is being asked for before there is an
37
+ * answer.
38
+ */
39
+ export declare function PhiMoneyControl({ id, value, currency, locale, min, max, label, ariaLabel, placeholder, disabled, readOnly, size, variant, style, onChange, onBlur, }: PhiMoneyControlProps): import("react").JSX.Element;
@@ -0,0 +1,34 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { InputNumber } from "antd";
4
+ import { PHI_LAYOUT } from "../../theme/phi-tokens";
5
+ import { comparePhiMinorAmounts, formatPhiMajorAmount, parsePhiLocaleAmount, phiMajorToMinorAmount, PHI_MINOR_AMOUNT_MAX, readPhiCurrencyExponent, resolvePhiCurrencyAffix, } from "../../helpers/money-amount";
6
+ import { PhiLabeledControl, usePhiControlLabel } from "./phi-labeled-control";
7
+ import { phisMinorToMajorAmount } from "@phis/contracts/payments";
8
+ /**
9
+ * An amount of money: minor units in and out, major units on screen, the currency beside the number.
10
+ *
11
+ * The number is held as a decimal string (`stringMode`), never as a float, and converted on its digits
12
+ * (`helpers/money-amount.ts`). It is written the way the page's locale writes numbers once the field is
13
+ * left, and while somebody types it shows exactly what they typed -- reformatting under the caret moves
14
+ * it. Leaving the field rounds to the currency's places and brings the amount into `min`..`max`.
15
+ *
16
+ * The currency is its ISO code, on the side the locale puts it ("CHF 12.50", "12,50 EUR"), and it is
17
+ * shown with an empty field too: unlike a unit, it says what is being asked for before there is an
18
+ * answer.
19
+ */
20
+ export function PhiMoneyControl({ id, value, currency, locale, min, max, label, ariaLabel, placeholder, disabled, readOnly, size, variant, style, onChange, onBlur, }) {
21
+ const { labelId, labelledBy } = usePhiControlLabel(label);
22
+ const exponent = readPhiCurrencyExponent(currency);
23
+ if (exponent === undefined) {
24
+ throw new Error(`PhiMoneyControl: "${currency}" is not an ISO 4217 currency a payment accepts.`);
25
+ }
26
+ const ceiling = max !== undefined && comparePhiMinorAmounts(max, PHI_MINOR_AMOUNT_MAX) < 0 ? max : PHI_MINOR_AMOUNT_MAX;
27
+ const affix = resolvePhiCurrencyAffix(locale, currency);
28
+ const control = (_jsx(InputNumber, { id: id, "aria-label": labelledBy ? undefined : ariaLabel, "aria-labelledby": labelledBy, stringMode: true, value: value == null ? null : phisMinorToMajorAmount(value, exponent), min: phisMinorToMajorAmount(min ?? "0", exponent), max: phisMinorToMajorAmount(ceiling, exponent), step: "1", precision: exponent, formatter: (next, info) => {
29
+ if (info.userTyping)
30
+ return info.input;
31
+ return next == null || next === "" ? "" : formatPhiMajorAmount(next, locale, exponent);
32
+ }, parser: (text) => parsePhiLocaleAmount(text ?? "", locale), prefix: affix.placement === "prefix" ? affix.text : undefined, suffix: affix.placement === "suffix" ? affix.text : undefined, placeholder: placeholder, disabled: disabled || (!onChange && !readOnly), readOnly: readOnly, size: size, variant: variant, style: { maxWidth: PHI_LAYOUT.numberControlMax, ...style }, onChange: (next) => onChange?.(next == null || next === "" ? null : phiMajorToMinorAmount(next, exponent)), onBlur: onBlur }));
33
+ return _jsx(PhiLabeledControl, { label: label, labelId: labelId, fill: style?.width === "100%", children: control });
34
+ }
@@ -5,6 +5,11 @@ export type PhiNumberControlProps = {
5
5
  id?: string;
6
6
  value?: number | null;
7
7
  label?: string;
8
+ /**
9
+ * The field's accessible name. Stated beside a `label`, it wins over it, as on `PhiTextControl` and
10
+ * `PhiSelectControl` (`usePhiControlLabel`).
11
+ */
12
+ ariaLabel?: string;
8
13
  /**
9
14
  * What the number is in, shown inside the field.
10
15
  *
@@ -27,4 +32,4 @@ export type PhiNumberControlProps = {
27
32
  onBlur?: FocusEventHandler<HTMLInputElement>;
28
33
  onKeyDown?: KeyboardEventHandler<HTMLInputElement>;
29
34
  };
30
- export declare function PhiNumberControl({ id, value, label, prefix, placeholder, min, max, step, precision, disabled, readOnly, size, variant, style, onChange, onBlur, onKeyDown, }: PhiNumberControlProps): import("react").JSX.Element;
35
+ export declare function PhiNumberControl({ id, value, label, ariaLabel, prefix, placeholder, min, max, step, precision, disabled, readOnly, size, variant, style, onChange, onBlur, onKeyDown, }: PhiNumberControlProps): import("react").JSX.Element;
@@ -3,9 +3,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { InputNumber } from "antd";
4
4
  import { PHI_LAYOUT } from "../../theme/phi-tokens";
5
5
  import { PhiLabeledControl, usePhiControlLabel } from "./phi-labeled-control";
6
- export function PhiNumberControl({ id, value, label, prefix, placeholder, min, max, step, precision, disabled, readOnly, size, variant, style, onChange, onBlur, onKeyDown, }) {
7
- const { labelId, labelledBy } = usePhiControlLabel(label);
8
- const control = (_jsx(InputNumber, { id: id, "aria-labelledby": labelledBy, value: value, prefix: prefix, placeholder: placeholder, min: min, max: max, step: step, precision: precision, disabled: disabled || (!onChange && !readOnly), readOnly: readOnly, size: size, variant: variant,
6
+ export function PhiNumberControl({ id, value, label, ariaLabel, prefix, placeholder, min, max, step, precision, disabled, readOnly, size, variant, style, onChange, onBlur, onKeyDown, }) {
7
+ const { labelId, labelledBy } = usePhiControlLabel(label, ariaLabel);
8
+ const control = (_jsx(InputNumber, { id: id, "aria-label": ariaLabel, "aria-labelledby": labelledBy, value: value, prefix: prefix, placeholder: placeholder, min: min, max: max, step: step, precision: precision, disabled: disabled || (!onChange && !readOnly), readOnly: readOnly, size: size, variant: variant,
9
9
  /*
10
10
  * The ceiling first, so a caller's own `maxWidth` replaces it rather than fighting it. A field
11
11
  * that needs to be wider than a number ever is says so, and says it in one place.
@@ -44,6 +44,13 @@ export type PhiControlOptionsProviderContext<TValue extends string | number = st
44
44
  * knowing which field supplies it or where that field lives.
45
45
  */
46
46
  dependencies: Record<string, unknown>;
47
+ /**
48
+ * The reader's language and the Site's time zone (`usePhiIntlLocale`, `usePhiIntlTimeZone`), for a
49
+ * provider whose option labels are words, amounts or dates. The hook puts both into every load key,
50
+ * outside `resolveLoadKey` like the dependencies, so a live language switch asks again.
51
+ */
52
+ locale: string;
53
+ timeZone: string;
47
54
  snapshot: unknown;
48
55
  asyncData: unknown;
49
56
  };
@@ -1,5 +1,6 @@
1
1
  "use client";
2
2
  import { readPhiDotPath } from "../../helpers/dot-path";
3
+ import { usePhiIntlLocale, usePhiIntlTimeZone } from "../root/phi-intl-locale";
3
4
  import { createContext, createElement, useContext, useEffect, useEffectEvent, useMemo, useState, useSyncExternalStore, } from "react";
4
5
  import { isPhiRuntimeDataProviderKey, } from "../../types/runtime-data-provider";
5
6
  const EMPTY_OPTIONS_PROVIDER_REGISTRY = new Map();
@@ -169,6 +170,8 @@ export function usePhiControlOptionsProvider({ options, optionsProvider, sourceC
169
170
  form: formValues,
170
171
  config: sourceConfig,
171
172
  }), [optionsProvider?.dependencies, formValues, sourceConfig]);
173
+ const locale = usePhiIntlLocale();
174
+ const timeZone = usePhiIntlTimeZone();
172
175
  const defaultProviderLoadKey = JSON.stringify({
173
176
  providerKey: optionsProvider?.providerKey ?? null,
174
177
  area: optionsProvider?.area ?? null,
@@ -184,11 +187,15 @@ export function usePhiControlOptionsProvider({ options, optionsProvider, sourceC
184
187
  // keystroke, so taking the search into account is the searching provider's own decision.
185
188
  search,
186
189
  dependencies: dependencyValues,
190
+ locale,
191
+ timeZone,
187
192
  snapshot: providerSnapshot,
188
193
  };
194
+ // The language and the zone are prefixed for the same reason the dependencies are.
189
195
  const providerLoadKey = registeredProvider?.load
190
196
  ? [
191
197
  registeredProvider.key,
198
+ JSON.stringify([locale, timeZone]),
192
199
  JSON.stringify(dependencyValues),
193
200
  registeredProvider.resolveLoadKey?.(loadContext) ?? defaultProviderLoadKey,
194
201
  ].join(":")
@@ -270,6 +277,8 @@ export function usePhiControlOptionsProvider({ options, optionsProvider, sourceC
270
277
  sourceConfig,
271
278
  search,
272
279
  dependencies: dependencyValues,
280
+ locale,
281
+ timeZone,
273
282
  snapshot: providerSnapshot,
274
283
  asyncData,
275
284
  }),
@@ -280,6 +289,8 @@ export function usePhiControlOptionsProvider({ options, optionsProvider, sourceC
280
289
  searchState,
281
290
  dependenciesSatisfied,
282
291
  dependencyValues,
292
+ locale,
293
+ timeZone,
283
294
  asyncData,
284
295
  asyncError,
285
296
  asyncPending,
@@ -4,3 +4,4 @@ export declare const PhiSliderFormControl: ComponentType<PhiFormFieldProviderPro
4
4
  export declare const PhiCascaderFormControl: ComponentType<PhiFormFieldProviderProps>;
5
5
  export declare const PhiNumberFormControl: ComponentType<PhiFormFieldProviderProps>;
6
6
  export declare const PhiStorageSizeFormControl: ComponentType<PhiFormFieldProviderProps>;
7
+ export declare const PhiMoneyFormControl: ComponentType<PhiFormFieldProviderProps>;
@@ -1,9 +1,13 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { PhiCascaderControl } from "../controls/phi-cascader-control";
4
+ import { PhiFlexControl } from "../controls/phi-flex-control";
5
+ import { PhiMoneyControl } from "../controls/phi-money-control";
4
6
  import { PhiNumberControl } from "../controls/phi-number-control";
5
7
  import { PhiSliderControl } from "../controls/phi-slider-control";
6
8
  import { resolvePhiFormText } from "./form-descriptor-contract";
9
+ import { readPhiMoneyFieldAmount, readPhiMoneyFieldAmounts, readPhiMoneyFieldConfig, updatePhiMoneyFieldAmounts, } from "./money-field";
10
+ import { usePhiIntlLocale } from "../root/phi-intl-locale";
7
11
  import { PHI_STORAGE_SIZE_UNIT_LABEL, phiBytesToStorageSize, phiStorageSizeToBytes, } from "./storage-size";
8
12
  /**
9
13
  * The unit beside a number, which is the value's and not the field's name ("days", not "Window (days)").
@@ -23,7 +27,7 @@ function readPhiNumberFieldPrefix(prefix, labels) {
23
27
  }
24
28
  /*
25
29
  * Field kinds most forms never have, loaded only where one is rendered: the slider, the cascader and
26
- * the number fields.
30
+ * the number and money fields.
27
31
  *
28
32
  * The shared registry is imported by every Form Widget, and a Contact form paid for the slider and the
29
33
  * cascader -- and through the compound controls for the Table and Tree Controls with every editor --
@@ -56,3 +60,21 @@ export const PhiStorageSizeFormControl = ({ id, value, onChange, placeholder, di
56
60
  */
57
61
  prefix: size == null ? undefined : PHI_STORAGE_SIZE_UNIT_LABEL, min: 0, step: 1, disabled: disabled, readOnly: readOnly, placeholder: placeholder, style: { width: "100%" }, onChange: (nextValue) => onChange?.(phiStorageSizeToBytes(nextValue)) }));
58
62
  };
63
+ /*
64
+ * The field holds minor units and shows major ones, as the storage size holds bytes and shows megabytes:
65
+ * the conversion is the Control's, on the digits (`helpers/money-amount.ts`), and a handler reads the
66
+ * contract's money and nothing else. The shapes and the config are `money-field.ts`.
67
+ */
68
+ export const PhiMoneyFormControl = ({ id, field, value, onChange, label, placeholder, disabled, readOnly, }) => {
69
+ const locale = usePhiIntlLocale();
70
+ const config = readPhiMoneyFieldConfig(field.config);
71
+ const { currency, currencies, min, max } = config;
72
+ if (currency !== undefined) {
73
+ return (_jsx(PhiMoneyControl, { id: id, value: readPhiMoneyFieldAmount(value, currency)?.minor ?? null, currency: currency, locale: locale, min: min, max: max, placeholder: placeholder, disabled: disabled, readOnly: readOnly, style: { width: "100%" }, onChange: (minor) => onChange?.(minor === null ? null : { currency, minor }) }));
74
+ }
75
+ const list = currencies ?? [];
76
+ const amounts = readPhiMoneyFieldAmounts(value, list);
77
+ return (_jsx(PhiFlexControl, { vertical: true, gap: "small", children: list.map((entry, index) => (_jsx(PhiMoneyControl, {
78
+ // The field's label names the first input; each one after it is named by the label and its currency.
79
+ id: index === 0 ? id : undefined, ariaLabel: index === 0 ? undefined : [label, entry].filter(Boolean).join(" "), value: amounts?.[entry] ?? null, currency: entry, locale: locale, min: min, max: max, placeholder: placeholder, disabled: disabled, readOnly: readOnly, style: { width: "100%" }, onChange: (minor) => onChange?.(updatePhiMoneyFieldAmounts(amounts, list, entry, minor)) }, entry))) }));
80
+ };
@@ -10,6 +10,7 @@ import { isPhiControllerSignalAddress } from "../../types/signals";
10
10
  import { readPhiRuntimeConditionStateSignalValue } from "../../types/runtime-condition";
11
11
  import { collectPhiRuntimeValueConditions } from "../../types/runtime-condition";
12
12
  import { usePhiTableProvider } from "../widgets/client/shared/phi-table-provider";
13
+ import { usePhiIntlLocale, usePhiIntlTimeZone } from "../root/phi-intl-locale";
13
14
  import { PhiFormControl } from "../controls/phi-form-control";
14
15
  import { readPhiRuntimeFormValuesSignalValue } from "./runtime-form-state";
15
16
  import { resolvePhiFormText } from "./form-descriptor-contract";
@@ -40,6 +41,17 @@ export function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedIniti
40
41
  const emitSignal = usePhiSignalEmitter(identity.sender);
41
42
  const source = widgetConfig?.source ?? null;
42
43
  const { provider, resource, bindingError } = usePhiTableProvider(source);
44
+ /*
45
+ * Sent with the record read, but held in a ref rather than made part of what starts one: a Form's
46
+ * values are what somebody is editing, and a language switch that read the record again would throw
47
+ * their edits away. The next read takes the language that is current then.
48
+ */
49
+ const locale = usePhiIntlLocale();
50
+ const timeZone = usePhiIntlTimeZone();
51
+ const intlRef = useRef({ locale, timeZone });
52
+ useEffect(() => {
53
+ intlRef.current = { locale, timeZone };
54
+ }, [locale, timeZone]);
43
55
  const initialValuesInput = widgetConfig?.formConfig.initialValues;
44
56
  const initialValuesFromQueryInput = widgetConfig?.formConfig.initialValuesFromQuery;
45
57
  const page = usePhiRuntimePageConditionState();
@@ -152,6 +164,7 @@ export function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedIniti
152
164
  resourceKey: source.resourceKey,
153
165
  rowIdentity,
154
166
  params: source.params,
167
+ ...intlRef.current,
155
168
  signal,
156
169
  });
157
170
  }, [bindingError, configuredInitialValues, provider, resource?.recordRead, source]);
@@ -24,6 +24,7 @@ export declare const PHI_FORM_FIELD_PROVIDER_KEYS: {
24
24
  readonly tree: `${string}/${string}`;
25
25
  readonly upload: `${string}/${string}`;
26
26
  readonly linkTarget: `${string}/${string}`;
27
+ readonly money: `${string}/${string}`;
27
28
  };
28
29
  export declare const PHI_AUTH_FORM_FIELD_PROVIDER_KEYS: {
29
30
  readonly termsConsent: `${string}/${string}`;
@@ -403,6 +404,48 @@ export declare const PHI_SHARED_FORM_FIELD_TYPE_PROVIDER_DESCRIPTORS: readonly [
403
404
  readonly label: "Area";
404
405
  readonly description: "Whose Pages are offered; Public when empty.";
405
406
  }];
407
+ }, {
408
+ readonly key: `${string}/${string}`;
409
+ readonly title: "Money";
410
+ readonly valueType: "json";
411
+ readonly presentation: "control";
412
+ readonly settingsFields: readonly [{
413
+ readonly key: "currency";
414
+ readonly type: "choice";
415
+ readonly mode: "single";
416
+ readonly valueType: "string";
417
+ readonly label: "Currency";
418
+ readonly description: "The currency of one amount.";
419
+ readonly options: {
420
+ value: string;
421
+ label: string;
422
+ }[];
423
+ }, {
424
+ readonly key: "currencies";
425
+ readonly type: "choice";
426
+ readonly mode: "multiple";
427
+ readonly valueType: "string[]";
428
+ readonly label: "Currencies";
429
+ readonly description: "One amount per currency, instead of a single currency.";
430
+ readonly options: {
431
+ value: string;
432
+ label: string;
433
+ }[];
434
+ }, {
435
+ readonly key: "min";
436
+ readonly type: "number";
437
+ readonly label: "Minimum";
438
+ readonly description: "In minor units: 100 is 1.00 CHF.";
439
+ readonly min: 0;
440
+ readonly precision: 0;
441
+ }, {
442
+ readonly key: "max";
443
+ readonly type: "number";
444
+ readonly label: "Maximum";
445
+ readonly description: "In minor units.";
446
+ readonly min: 0;
447
+ readonly precision: 0;
448
+ }];
406
449
  }];
407
450
  export declare const PHI_SHARED_FORM_VALIDATION_PROVIDER_DESCRIPTORS: readonly [{
408
451
  readonly key: `${string}/${string}`;
@@ -1,5 +1,6 @@
1
1
  import { createPhiModuleScopedKey } from "../../constants/runtime-module-ownership";
2
2
  import { PhiMediaKind } from "../../constants/media";
3
+ import { PHIS_PAYMENT_CURRENCY_EXPONENTS } from "@phis/contracts/payments";
3
4
  export function createPhiSharedFormProviderKey(kind, key) {
4
5
  const normalizedKey = key.trim();
5
6
  if (!normalizedKey || normalizedKey.includes("/") || normalizedKey.includes(":")) {
@@ -31,6 +32,7 @@ export const PHI_FORM_FIELD_PROVIDER_KEYS = {
31
32
  tree: createPhiSharedFormProviderKey("field", "tree"),
32
33
  upload: createPhiSharedFormProviderKey("field", "upload"),
33
34
  linkTarget: createPhiSharedFormProviderKey("field", "link-target"),
35
+ money: createPhiSharedFormProviderKey("field", "money"),
34
36
  };
35
37
  export const PHI_AUTH_FORM_FIELD_PROVIDER_KEYS = {
36
38
  termsConsent: createPhiSharedFormProviderKey("field", "auth-terms-consent"),
@@ -106,6 +108,10 @@ export const PHI_FORM_UPLOAD_LABEL_KEYS = {
106
108
  errorStorageUnreachable: "uploadErrorStorageUnreachable",
107
109
  errorFolderLocked: "uploadErrorFolderLocked",
108
110
  };
111
+ /** Every currency a payment accepts, by its ISO 4217 code, for the money field's settings. */
112
+ const PHI_MONEY_CURRENCY_OPTIONS = Object.keys(PHIS_PAYMENT_CURRENCY_EXPONENTS)
113
+ .sort()
114
+ .map((code) => ({ value: code, label: code }));
109
115
  export const PHI_SHARED_FORM_FIELD_TYPE_PROVIDER_DESCRIPTORS = [
110
116
  { key: PHI_FORM_FIELD_PROVIDER_KEYS.text, title: "Text", valueType: "string", presentation: "control", settingsFields: [{ key: "minLength", type: "number", label: "Minimum characters", min: 0 }, { key: "maxLength", type: "number", label: "Maximum characters", min: 0 }] },
111
117
  { key: PHI_FORM_FIELD_PROVIDER_KEYS.email, title: "Email", valueType: "string", presentation: "control", settingsFields: [{ key: "minLength", type: "number", label: "Minimum characters", min: 0 }, { key: "maxLength", type: "number", label: "Maximum characters", min: 0 }] },
@@ -270,6 +276,40 @@ export const PHI_SHARED_FORM_FIELD_TYPE_PROVIDER_DESCRIPTORS = [
270
276
  { key: "area", type: "string", label: "Area", description: "Whose Pages are offered; Public when empty." },
271
277
  ],
272
278
  },
279
+ /*
280
+ * An amount of money: minor units in the value, major units on screen beside the currency's code.
281
+ * `json`, because the value is the contract's money (`{ currency, minor }`) for one `currency`, or a
282
+ * price list (`{ CHF: "1990" }`) for several `currencies` -- see `money-field.ts`. `min` and `max`
283
+ * are minor units.
284
+ */
285
+ {
286
+ key: PHI_FORM_FIELD_PROVIDER_KEYS.money,
287
+ title: "Money",
288
+ valueType: "json",
289
+ presentation: "control",
290
+ settingsFields: [
291
+ {
292
+ key: "currency",
293
+ type: "choice",
294
+ mode: "single",
295
+ valueType: "string",
296
+ label: "Currency",
297
+ description: "The currency of one amount.",
298
+ options: PHI_MONEY_CURRENCY_OPTIONS,
299
+ },
300
+ {
301
+ key: "currencies",
302
+ type: "choice",
303
+ mode: "multiple",
304
+ valueType: "string[]",
305
+ label: "Currencies",
306
+ description: "One amount per currency, instead of a single currency.",
307
+ options: PHI_MONEY_CURRENCY_OPTIONS,
308
+ },
309
+ { key: "min", type: "number", label: "Minimum", description: "In minor units: 100 is 1.00 CHF.", min: 0, precision: 0 },
310
+ { key: "max", type: "number", label: "Maximum", description: "In minor units.", min: 0, precision: 0 },
311
+ ],
312
+ },
273
313
  ];
274
314
  export const PHI_SHARED_FORM_VALIDATION_PROVIDER_DESCRIPTORS = [
275
315
  { key: PHI_FORM_VALIDATION_PROVIDER_KEYS.required, title: "Required" },
@@ -0,0 +1,27 @@
1
+ import type { PhisPaymentMoney } from "@phis/contracts/payments";
2
+ export type PhiMoneyFieldConfig = {
3
+ /** The one currency of a single amount, or absent for a list. */
4
+ currency?: string;
5
+ /** The currencies of a list, in the order they are shown, or absent for a single amount. */
6
+ currencies?: readonly string[];
7
+ /** The least and the most an amount may be, in minor units; every entry of a list is held to them. */
8
+ min?: string;
9
+ max?: string;
10
+ };
11
+ /** A price list as the field holds it: minor units per currency code. */
12
+ export type PhiMoneyFieldAmounts = Readonly<Record<string, string>>;
13
+ /**
14
+ * The field's config, read strictly (`strict-config-reader.ts`): a value present and wrong is a
15
+ * `PhiConfigError` naming the field, never a default put in its place.
16
+ */
17
+ export declare function readPhiMoneyFieldConfig(config: Readonly<Record<string, unknown>> | undefined): PhiMoneyFieldConfig;
18
+ /**
19
+ * The value a single-amount field was given, or `null` for none. Anything else -- another currency, an
20
+ * amount that is not a canonical minor string -- is a record that does not fit the Form, and saying so
21
+ * is the only answer that does not overwrite it with nothing on the next save.
22
+ */
23
+ export declare function readPhiMoneyFieldAmount(value: unknown, currency: string): PhisPaymentMoney | null;
24
+ /** The value a price-list field was given, or `null` for none; the same refusal for a value that does not fit. */
25
+ export declare function readPhiMoneyFieldAmounts(value: unknown, currencies: readonly string[]): PhiMoneyFieldAmounts | null;
26
+ /** A list with one entry changed: an empty one is removed, and a list left with none is `null`. */
27
+ export declare function updatePhiMoneyFieldAmounts(amounts: PhiMoneyFieldAmounts | null, currencies: readonly string[], currency: string, minor: string | null): PhiMoneyFieldAmounts | null;
@@ -0,0 +1,78 @@
1
+ import { isPhiRecord } from "../../helpers/is-record";
2
+ import { comparePhiMinorAmounts, isPhiMinorAmount, PHI_MINOR_AMOUNT_MAX, readPhiCurrencyExponent, } from "../../helpers/money-amount";
3
+ import { createPhiConfigReader } from "../widgets/config/strict-config-reader";
4
+ function readCurrency(reader, key, value) {
5
+ return typeof value === "string" && readPhiCurrencyExponent(value) !== undefined
6
+ ? value
7
+ : reader.fail(key, "an ISO 4217 currency code a payment accepts", value);
8
+ }
9
+ function readMinorBound(reader, key) {
10
+ const value = reader.integer(key);
11
+ if (value === undefined)
12
+ return undefined;
13
+ const minor = String(value);
14
+ return value >= 0 && isPhiMinorAmount(minor) ? minor : reader.fail(key, `a whole number of minor units from 0 to ${PHI_MINOR_AMOUNT_MAX}`);
15
+ }
16
+ /**
17
+ * The field's config, read strictly (`strict-config-reader.ts`): a value present and wrong is a
18
+ * `PhiConfigError` naming the field, never a default put in its place.
19
+ */
20
+ export function readPhiMoneyFieldConfig(config) {
21
+ const reader = createPhiConfigReader(config ?? {}, "config");
22
+ const hasCurrency = reader.has("currency");
23
+ const hasCurrencies = reader.has("currencies");
24
+ if (hasCurrency === hasCurrencies) {
25
+ return reader.fail("currency", "either `currency` (one amount) or `currencies` (one amount per currency)", config?.currency);
26
+ }
27
+ const min = readMinorBound(reader, "min");
28
+ const max = readMinorBound(reader, "max");
29
+ if (min !== undefined && max !== undefined && comparePhiMinorAmounts(min, max) > 0) {
30
+ reader.fail("max", `at least the minimum ${min}`);
31
+ }
32
+ const bounds = { ...(min === undefined ? {} : { min }), ...(max === undefined ? {} : { max }) };
33
+ if (hasCurrency) {
34
+ return { currency: readCurrency(reader, "currency", reader.string("currency")), ...bounds };
35
+ }
36
+ const currencies = reader.stringList("currencies") ?? [];
37
+ if (currencies.length === 0)
38
+ reader.fail("currencies", "at least one currency");
39
+ currencies.forEach((currency, index) => readCurrency(reader, `currencies[${index}]`, currency));
40
+ if (new Set(currencies).size !== currencies.length)
41
+ reader.fail("currencies", "each currency once");
42
+ return { currencies, ...bounds };
43
+ }
44
+ function describe(value) {
45
+ return JSON.stringify(value) ?? String(value);
46
+ }
47
+ /**
48
+ * The value a single-amount field was given, or `null` for none. Anything else -- another currency, an
49
+ * amount that is not a canonical minor string -- is a record that does not fit the Form, and saying so
50
+ * is the only answer that does not overwrite it with nothing on the next save.
51
+ */
52
+ export function readPhiMoneyFieldAmount(value, currency) {
53
+ if (value === undefined || value === null)
54
+ return null;
55
+ if (isPhiRecord(value) && value.currency === currency && isPhiMinorAmount(value.minor)) {
56
+ return { currency, minor: value.minor };
57
+ }
58
+ throw new Error(`A money field in ${currency} was given ${describe(value)}; it holds { currency: "${currency}", minor: "<digits>" } or null.`);
59
+ }
60
+ /** The value a price-list field was given, or `null` for none; the same refusal for a value that does not fit. */
61
+ export function readPhiMoneyFieldAmounts(value, currencies) {
62
+ if (value === undefined || value === null)
63
+ return null;
64
+ if (isPhiRecord(value) && Object.entries(value).every(([currency, minor]) => currencies.includes(currency) && isPhiMinorAmount(minor))) {
65
+ return Object.keys(value).length === 0 ? null : value;
66
+ }
67
+ throw new Error(`A money field in ${currencies.join(", ")} was given ${describe(value)}; it holds minor units per currency or null.`);
68
+ }
69
+ /** A list with one entry changed: an empty one is removed, and a list left with none is `null`. */
70
+ export function updatePhiMoneyFieldAmounts(amounts, currencies, currency, minor) {
71
+ const next = {};
72
+ for (const entry of currencies) {
73
+ const amount = entry === currency ? minor : amounts?.[entry];
74
+ if (amount != null)
75
+ next[entry] = amount;
76
+ }
77
+ return Object.keys(next).length === 0 ? null : next;
78
+ }