@phis/ui 0.7.7 → 0.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/controls/phi-form-control.js +12 -1
- package/components/forms/extended-form-field-controls.d.ts +1 -1
- package/components/forms/extended-form-field-controls.js +23 -7
- package/components/forms/form-provider-contract.d.ts +5 -0
- package/components/forms/form-provider-contract.js +9 -2
- package/components/forms/form-provider-registry.d.ts +6 -0
- package/components/forms/money-field-currency-key.d.ts +6 -0
- package/components/forms/money-field-currency-key.js +14 -0
- package/components/forms/money-field.d.ts +26 -3
- package/components/forms/money-field.js +54 -4
- package/components/regions/presets/navigation-redirect.d.ts +4 -1
- package/components/regions/presets/navigation-redirect.js +6 -3
- package/components/widgets/client/shared/phi-rendered-value.js +5 -3
- package/helpers/money-amount.d.ts +7 -0
- package/helpers/money-amount.js +15 -0
- package/package.json +1 -1
- package/plugins/runtime-modules/app/presets.js +3 -6
- package/plugins/runtime-modules/app/trees/phi-default-app-area-preset-tree.d.ts +3 -6
- package/plugins/runtime-modules/app/trees/phi-default-app-area-preset-tree.js +4 -7
- package/plugins/runtime-modules/builder/controller/client.d.ts +5 -5
- package/plugins/runtime-modules/builder/controller/client.js +2 -1
- package/plugins/runtime-modules/builder/controller/definition.d.ts +4 -4
- package/plugins/runtime-modules/builder/controller/definition.js +7 -0
- package/plugins/runtime-modules/builder/controller/draft-command-controller.d.ts +3 -1
- package/plugins/runtime-modules/builder/controller/draft-command-controller.js +2 -1
- package/plugins/runtime-modules/builder/controller/draft-status-controller.js +44 -17
- package/plugins/runtime-modules/builder/controller/server-definition.d.ts +4 -4
- package/plugins/runtime-modules/builder/controller/workspace-controller.d.ts +3 -1
- package/plugins/runtime-modules/builder/controller/workspace-controller.js +8 -10
- package/plugins/runtime-modules/builder/developer-workspace-store.d.ts +10 -0
- package/plugins/runtime-modules/builder/developer-workspace-store.js +35 -1
- package/plugins/runtime-modules/builder/offered-page-catalog.d.ts +6 -0
- package/plugins/runtime-modules/builder/offered-page-catalog.js +35 -6
- package/plugins/runtime-modules/builder/persistence.d.ts +4 -1
- package/plugins/runtime-modules/builder/persistence.js +10 -3
- package/plugins/runtime-modules/core/definition.d.ts +5 -0
- package/plugins/runtime-modules/core/form-providers.d.ts +5 -0
- package/plugins/runtime-modules/core/widgets/spacer/client.js +3 -3
- package/plugins/runtime-modules/phi-default-site-area-preset-tree.js +46 -39
- package/plugins/runtime-modules/preset-contracts/pub-area.d.ts +1 -1
- package/plugins/runtime-modules/preset-contracts/pub-area.js +1 -0
- package/plugins/runtime-modules/revisions/controller/client.js +48 -46
- package/plugins/runtime-modules/revisions/services/table.js +3 -1
- package/styles/builder-scaffold.css +7 -1
- package/styles/layout-authoring-scaffold.css +27 -0
|
@@ -9,6 +9,7 @@ import { PhiAlertControl } from "./phi-alert-control";
|
|
|
9
9
|
import { PhiDescriptionHint } from "./phi-description-tooltip-icon";
|
|
10
10
|
import { PHI_FORM_FIELD_PROVIDER_KEYS, PHI_FORM_FIELD_UNAVAILABLE_DEFAULT_LABEL, PHI_FORM_FIELD_UNAVAILABLE_LABEL_KEY, PHI_FORM_VALIDATION_PROVIDER_KEYS, } from "../forms/form-provider-contract";
|
|
11
11
|
import { phiFormCellOpensColumn, phiFormControlGridColumn, phiFormFieldFollowsLayoutColumns, phiFormLabelGridColumn, resolvePhiFormGridPlacement, resolvePhiFormLayout, PHI_FORM_RESPONSIVE_MODES, resolvePhiFormText, shouldPhiFormSubmitOnKeyDown, } from "../forms/form-descriptor-contract";
|
|
12
|
+
import { readPhiMoneyFieldCurrencyFieldKey } from "../forms/money-field-currency-key";
|
|
12
13
|
import { PHI_SHARED_FORM_PROVIDER_REGISTRY } from "../forms/shared-form-provider-registry";
|
|
13
14
|
import { resolvePhiControlOptionsDependencies, usePhiControlOptionsProvider, } from "./phi-options-provider";
|
|
14
15
|
/** The id Ant Design gives a Form Item's control: the form's name and the field's key, joined by `_`. */
|
|
@@ -60,6 +61,16 @@ function collectPhiFormWatchedKeys(fields) {
|
|
|
60
61
|
if (dependency.source === "form")
|
|
61
62
|
keys.add(dependency.valuePath.split(".")[0] ?? "");
|
|
62
63
|
}
|
|
64
|
+
const currencyField = field.fieldProviderKey === PHI_FORM_FIELD_PROVIDER_KEYS.money
|
|
65
|
+
? readPhiMoneyFieldCurrencyFieldKey(field.config)
|
|
66
|
+
: null;
|
|
67
|
+
if (currencyField !== null) {
|
|
68
|
+
// A key no field of the Form has would leave the amount with no currency for good, silently.
|
|
69
|
+
if (currencyField === field.key || !fields.some((other) => other.key === currencyField)) {
|
|
70
|
+
throw new Error(`The money field "${field.key}" takes its currency from "${currencyField}", which is no other field of its Form.`);
|
|
71
|
+
}
|
|
72
|
+
keys.add(currencyField);
|
|
73
|
+
}
|
|
63
74
|
}
|
|
64
75
|
keys.delete("");
|
|
65
76
|
return [...keys].sort();
|
|
@@ -132,7 +143,7 @@ function PhiResolvedFormFieldControl({ id, provider, field, label, description,
|
|
|
132
143
|
const controlLabel = field.controlLabel
|
|
133
144
|
? resolvePhiFormText(field.controlLabel, labels, formConfig)
|
|
134
145
|
: undefined;
|
|
135
|
-
return (_jsxs(_Fragment, { children: [_jsx(Control, { id: id, field: field, label: label, description: description, controlLabel: controlLabel, labels: labels, formConfig: formConfig, placeholder: placeholder, options: resolvedOptions.options, onSearch: resolvedOptions.search.enabled ? setSearchDraft : undefined, filterOptionsLocally: resolvedOptions.search.filterLocally, disabled: disabled, readOnly: readOnly, value: value, checked: checked, onChange: onChange, formContext: formContext, ...(mediaLimits ? { mediaLimits } : {}) }), resolvedOptions.warning ? (_jsx(PhiAlertControl, { level: "warning", showIcon: true, title: resolvedOptions.warning })) : null] }));
|
|
146
|
+
return (_jsxs(_Fragment, { children: [_jsx(Control, { id: id, field: field, label: label, description: description, controlLabel: controlLabel, labels: labels, formConfig: formConfig, placeholder: placeholder, options: resolvedOptions.options, onSearch: resolvedOptions.search.enabled ? setSearchDraft : undefined, filterOptionsLocally: resolvedOptions.search.filterLocally, disabled: disabled, readOnly: readOnly, value: value, checked: checked, onChange: onChange, formContext: formContext, ...(formValues ? { formValues } : {}), ...(mediaLimits ? { mediaLimits } : {}) }), resolvedOptions.warning ? (_jsx(PhiAlertControl, { level: "warning", showIcon: true, title: resolvedOptions.warning })) : null] }));
|
|
136
147
|
}
|
|
137
148
|
// One empty object for every form without controllers, so the fields drawn are not recomputed on
|
|
138
149
|
// every render for a new `{}`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ComponentType } from "react";
|
|
2
2
|
import type { PhiFormFieldProviderProps } from "./form-provider-registry";
|
|
3
3
|
export declare const PhiSliderFormControl: ComponentType<PhiFormFieldProviderProps>;
|
|
4
4
|
export declare const PhiCascaderFormControl: ComponentType<PhiFormFieldProviderProps>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect } from "react";
|
|
3
4
|
import { PhiCascaderControl } from "../controls/phi-cascader-control";
|
|
4
5
|
import { PhiFlexControl } from "../controls/phi-flex-control";
|
|
5
6
|
import { PhiMoneyControl } from "../controls/phi-money-control";
|
|
6
7
|
import { PhiNumberControl } from "../controls/phi-number-control";
|
|
7
8
|
import { PhiSliderControl } from "../controls/phi-slider-control";
|
|
8
9
|
import { resolvePhiFormText } from "./form-descriptor-contract";
|
|
9
|
-
import { readPhiMoneyFieldAmount, readPhiMoneyFieldAmounts, readPhiMoneyFieldConfig, updatePhiMoneyFieldAmounts, } from "./money-field";
|
|
10
|
+
import { readPhiMoneyFieldAmount, readPhiMoneyFieldAmounts, readPhiMoneyFieldConfig, readPhiMoneyFieldLinkedCurrency, readPhiMoneyFieldOptionCurrencies, updatePhiMoneyFieldAmounts, } from "./money-field";
|
|
10
11
|
import { usePhiIntlLocale } from "../root/phi-intl-locale";
|
|
11
12
|
import { PHI_STORAGE_SIZE_UNIT_LABEL, phiBytesToStorageSize, phiStorageSizeToBytes, } from "./storage-size";
|
|
12
13
|
/**
|
|
@@ -65,14 +66,29 @@ export const PhiStorageSizeFormControl = ({ id, value, onChange, placeholder, di
|
|
|
65
66
|
* the conversion is the Control's, on the digits (`helpers/money-amount.ts`), and a handler reads the
|
|
66
67
|
* contract's money and nothing else. The shapes and the config are `money-field.ts`.
|
|
67
68
|
*/
|
|
68
|
-
export const PhiMoneyFormControl = ({ id, field, value, onChange, label, placeholder, disabled, readOnly, }) => {
|
|
69
|
+
export const PhiMoneyFormControl = ({ id, field, value, onChange, label, placeholder, disabled, readOnly, options, formValues, }) => {
|
|
69
70
|
const locale = usePhiIntlLocale();
|
|
70
|
-
const config = readPhiMoneyFieldConfig(field.config);
|
|
71
|
-
const {
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
const config = readPhiMoneyFieldConfig(field.config, { hasOptionsProvider: field.optionsProvider !== undefined });
|
|
72
|
+
const { currencies, currenciesFromOptions, currencyField, min, max } = config;
|
|
73
|
+
const currency = currencyField === undefined ? config.currency : readPhiMoneyFieldLinkedCurrency(currencyField, formValues);
|
|
74
|
+
/*
|
|
75
|
+
* An amount the value holds in another currency than the one its field now names was entered for the
|
|
76
|
+
* old one: it is no price in the new one, so it is shown empty and cleared, as a dependent choice is
|
|
77
|
+
* when its parent changes. Only a `currencyField` amount can get there; a fixed currency that does not
|
|
78
|
+
* match is a record that does not fit the Form and throws below.
|
|
79
|
+
*/
|
|
80
|
+
const stale = currencyField !== undefined && value != null
|
|
81
|
+
&& !(typeof value === "object" && value.currency === currency);
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (stale)
|
|
84
|
+
onChange?.(null);
|
|
85
|
+
}, [onChange, stale]);
|
|
86
|
+
if (currencyField !== undefined && currency === null)
|
|
87
|
+
return null;
|
|
88
|
+
if (currency !== undefined && currency !== null) {
|
|
89
|
+
return (_jsx(PhiMoneyControl, { id: id, value: stale ? null : 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
90
|
}
|
|
75
|
-
const list = currencies ?? [];
|
|
91
|
+
const list = currenciesFromOptions ? readPhiMoneyFieldOptionCurrencies(options, value) : currencies ?? [];
|
|
76
92
|
const amounts = readPhiMoneyFieldAmounts(value, list);
|
|
77
93
|
return (_jsx(PhiFlexControl, { vertical: true, gap: "small", children: list.map((entry, index) => (_jsx(PhiMoneyControl, {
|
|
78
94
|
// The field's label names the first input; each one after it is named by the label and its currency.
|
|
@@ -411,6 +411,11 @@ export declare const PHI_SHARED_FORM_FIELD_TYPE_PROVIDER_DESCRIPTORS: readonly [
|
|
|
411
411
|
value: string;
|
|
412
412
|
label: string;
|
|
413
413
|
}[];
|
|
414
|
+
}, {
|
|
415
|
+
readonly key: "currencyField";
|
|
416
|
+
readonly type: "string";
|
|
417
|
+
readonly label: "Currency field";
|
|
418
|
+
readonly description: "The key of the field whose value is the currency of one amount, instead of a fixed currency.";
|
|
414
419
|
}, {
|
|
415
420
|
readonly key: "currencies";
|
|
416
421
|
readonly type: "choice";
|
|
@@ -273,8 +273,9 @@ export const PHI_SHARED_FORM_FIELD_TYPE_PROVIDER_DESCRIPTORS = [
|
|
|
273
273
|
/*
|
|
274
274
|
* An amount of money: minor units in the value, major units on screen beside the currency's code.
|
|
275
275
|
* `json`, because the value is the contract's money (`{ currency, minor }`) for one `currency`, or a
|
|
276
|
-
* price list (`{ CHF: "1990" }`) for several `currencies
|
|
277
|
-
*
|
|
276
|
+
* price list (`{ CHF: "1990" }`) for several `currencies`, or for the currencies an `optionsProvider`
|
|
277
|
+
* answers; one amount's currency may be another field's value (`currencyField`) -- see
|
|
278
|
+
* `money-field.ts`. `min` and `max` are minor units.
|
|
278
279
|
*/
|
|
279
280
|
{
|
|
280
281
|
key: PHI_FORM_FIELD_PROVIDER_KEYS.money,
|
|
@@ -291,6 +292,12 @@ export const PHI_SHARED_FORM_FIELD_TYPE_PROVIDER_DESCRIPTORS = [
|
|
|
291
292
|
description: "The currency of one amount.",
|
|
292
293
|
options: PHI_MONEY_CURRENCY_OPTIONS,
|
|
293
294
|
},
|
|
295
|
+
{
|
|
296
|
+
key: "currencyField",
|
|
297
|
+
type: "string",
|
|
298
|
+
label: "Currency field",
|
|
299
|
+
description: "The key of the field whose value is the currency of one amount, instead of a fixed currency.",
|
|
300
|
+
},
|
|
294
301
|
{
|
|
295
302
|
key: "currencies",
|
|
296
303
|
type: "choice",
|
|
@@ -36,6 +36,12 @@ export type PhiFormFieldProviderProps = {
|
|
|
36
36
|
*/
|
|
37
37
|
holdSubmit(fieldKey: string, reason: string | null): void;
|
|
38
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* The live values of the fields this Form watches -- those a `visibleWhen`, `disabledWhen` or options
|
|
41
|
+
* dependency reads, and a money field's `currencyField` -- for a field whose own drawing follows a
|
|
42
|
+
* sibling. Only those keys: any other is absent, however it is filled.
|
|
43
|
+
*/
|
|
44
|
+
formValues?: Readonly<Record<string, unknown>>;
|
|
39
45
|
/** What the Widget was placed with, for text a field takes from its placement rather than its form. */
|
|
40
46
|
formConfig?: Readonly<Record<string, unknown>>;
|
|
41
47
|
/**
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Form field a money field takes its currency from, or `null` for one that states its own: what the
|
|
3
|
+
* Form watches for it, read as loosely as a list of watched keys needs and as strictly as the field's
|
|
4
|
+
* own Control reads it once drawn.
|
|
5
|
+
*/
|
|
6
|
+
export declare function readPhiMoneyFieldCurrencyFieldKey(config: Readonly<Record<string, unknown>> | undefined): string | null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Apart from `money-field.ts` because the Form reads it for every field it draws, to know what to
|
|
3
|
+
* watch: that file brings the currency table and the config reader, which a Form without a money field
|
|
4
|
+
* has no use for.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The Form field a money field takes its currency from, or `null` for one that states its own: what the
|
|
8
|
+
* Form watches for it, read as loosely as a list of watched keys needs and as strictly as the field's
|
|
9
|
+
* own Control reads it once drawn.
|
|
10
|
+
*/
|
|
11
|
+
export function readPhiMoneyFieldCurrencyFieldKey(config) {
|
|
12
|
+
const key = config?.currencyField;
|
|
13
|
+
return typeof key === "string" && key !== "" ? key : null;
|
|
14
|
+
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import type { PhisPaymentMoney } from "@phis/contracts/payments";
|
|
2
|
+
export { readPhiMoneyFieldCurrencyFieldKey } from "./money-field-currency-key";
|
|
2
3
|
export type PhiMoneyFieldConfig = {
|
|
3
4
|
/** The one currency of a single amount, or absent for a list. */
|
|
4
5
|
currency?: string;
|
|
5
|
-
/** The currencies of a list, in the order they are shown
|
|
6
|
+
/** The currencies of a list, in the order they are shown; absent for a single amount and for a list from the options. */
|
|
6
7
|
currencies?: readonly string[];
|
|
8
|
+
/** A price list whose currencies are the options' values: the field has an `optionsProvider` and neither of the two. */
|
|
9
|
+
currenciesFromOptions?: true;
|
|
10
|
+
/** The key of the Form field whose value is the one amount's currency, in place of `currency`. */
|
|
11
|
+
currencyField?: string;
|
|
7
12
|
/** The least and the most an amount may be, in minor units; every entry of a list is held to them. */
|
|
8
13
|
min?: string;
|
|
9
14
|
max?: string;
|
|
@@ -12,9 +17,27 @@ export type PhiMoneyFieldConfig = {
|
|
|
12
17
|
export type PhiMoneyFieldAmounts = Readonly<Record<string, string>>;
|
|
13
18
|
/**
|
|
14
19
|
* 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.
|
|
20
|
+
* `PhiConfigError` naming the field, never a default put in its place. `hasOptionsProvider` says whether
|
|
21
|
+
* the field names an `optionsProvider`; with one, neither `currency` nor `currencies` may be set, because
|
|
22
|
+
* a list given twice would leave open which one counts.
|
|
16
23
|
*/
|
|
17
|
-
export declare function readPhiMoneyFieldConfig(config: Readonly<Record<string, unknown>> | undefined
|
|
24
|
+
export declare function readPhiMoneyFieldConfig(config: Readonly<Record<string, unknown>> | undefined, { hasOptionsProvider }?: {
|
|
25
|
+
hasOptionsProvider?: boolean;
|
|
26
|
+
}): PhiMoneyFieldConfig;
|
|
27
|
+
/**
|
|
28
|
+
* The currencies of a list from the options: each option's value an ISO 4217 code a payment accepts, in
|
|
29
|
+
* the Provider's order, then every currency the value holds that the options leave out. An option that
|
|
30
|
+
* is not such a code throws -- the Provider answered something that is not a currency, and guessing past
|
|
31
|
+
* it would show a price under the wrong name.
|
|
32
|
+
*/
|
|
33
|
+
export declare function readPhiMoneyFieldOptionCurrencies(options: readonly {
|
|
34
|
+
value: unknown;
|
|
35
|
+
}[] | undefined, value: unknown): readonly string[];
|
|
36
|
+
/**
|
|
37
|
+
* The currency a `currencyField` amount is in: the other field's value, `null` while it names none. A
|
|
38
|
+
* value that is a code a payment does not accept throws, as a config naming one does.
|
|
39
|
+
*/
|
|
40
|
+
export declare function readPhiMoneyFieldLinkedCurrency(currencyField: string, values: Readonly<Record<string, unknown>> | null | undefined): string | null;
|
|
18
41
|
/**
|
|
19
42
|
* The value a single-amount field was given, or `null` for none. Anything else -- another currency, an
|
|
20
43
|
* amount that is not a canonical minor string -- is a record that does not fit the Form, and saying so
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isPhiRecord } from "../../helpers/is-record";
|
|
2
2
|
import { comparePhiMinorAmounts, isPhiMinorAmount, PHI_MINOR_AMOUNT_MAX, readPhiCurrencyExponent, } from "../../helpers/money-amount";
|
|
3
3
|
import { createPhiConfigReader } from "../widgets/config/strict-config-reader";
|
|
4
|
+
export { readPhiMoneyFieldCurrencyFieldKey } from "./money-field-currency-key";
|
|
4
5
|
function readCurrency(reader, key, value) {
|
|
5
6
|
return typeof value === "string" && readPhiCurrencyExponent(value) !== undefined
|
|
6
7
|
? value
|
|
@@ -15,14 +16,21 @@ function readMinorBound(reader, key) {
|
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* 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
|
+
* `PhiConfigError` naming the field, never a default put in its place. `hasOptionsProvider` says whether
|
|
20
|
+
* the field names an `optionsProvider`; with one, neither `currency` nor `currencies` may be set, because
|
|
21
|
+
* a list given twice would leave open which one counts.
|
|
19
22
|
*/
|
|
20
|
-
export function readPhiMoneyFieldConfig(config) {
|
|
23
|
+
export function readPhiMoneyFieldConfig(config, { hasOptionsProvider = false } = {}) {
|
|
21
24
|
const reader = createPhiConfigReader(config ?? {}, "config");
|
|
22
25
|
const hasCurrency = reader.has("currency");
|
|
23
26
|
const hasCurrencies = reader.has("currencies");
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
const hasCurrencyField = reader.has("currencyField");
|
|
28
|
+
const set = [hasCurrency, hasCurrencies, hasCurrencyField, hasOptionsProvider].filter(Boolean).length;
|
|
29
|
+
if (set !== 1) {
|
|
30
|
+
const key = hasOptionsProvider
|
|
31
|
+
? (hasCurrency ? "currency" : hasCurrencies ? "currencies" : "currencyField")
|
|
32
|
+
: hasCurrencyField && (hasCurrency || hasCurrencies) ? "currencyField" : "currency";
|
|
33
|
+
return reader.fail(key, "exactly one of `currency` (one amount), `currencyField` (one amount in the currency another field holds), `currencies` (one amount per currency) or an `optionsProvider` naming the currencies", config?.[key]);
|
|
26
34
|
}
|
|
27
35
|
const min = readMinorBound(reader, "min");
|
|
28
36
|
const max = readMinorBound(reader, "max");
|
|
@@ -30,6 +38,12 @@ export function readPhiMoneyFieldConfig(config) {
|
|
|
30
38
|
reader.fail("max", `at least the minimum ${min}`);
|
|
31
39
|
}
|
|
32
40
|
const bounds = { ...(min === undefined ? {} : { min }), ...(max === undefined ? {} : { max }) };
|
|
41
|
+
if (hasOptionsProvider)
|
|
42
|
+
return { currenciesFromOptions: true, ...bounds };
|
|
43
|
+
if (hasCurrencyField) {
|
|
44
|
+
const currencyField = reader.string("currencyField");
|
|
45
|
+
return currencyField ? { currencyField, ...bounds } : reader.fail("currencyField", "the key of another field of the Form", currencyField);
|
|
46
|
+
}
|
|
33
47
|
if (hasCurrency) {
|
|
34
48
|
return { currency: readCurrency(reader, "currency", reader.string("currency")), ...bounds };
|
|
35
49
|
}
|
|
@@ -41,6 +55,42 @@ export function readPhiMoneyFieldConfig(config) {
|
|
|
41
55
|
reader.fail("currencies", "each currency once");
|
|
42
56
|
return { currencies, ...bounds };
|
|
43
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* The currencies of a list from the options: each option's value an ISO 4217 code a payment accepts, in
|
|
60
|
+
* the Provider's order, then every currency the value holds that the options leave out. An option that
|
|
61
|
+
* is not such a code throws -- the Provider answered something that is not a currency, and guessing past
|
|
62
|
+
* it would show a price under the wrong name.
|
|
63
|
+
*/
|
|
64
|
+
export function readPhiMoneyFieldOptionCurrencies(options, value) {
|
|
65
|
+
const currencies = [];
|
|
66
|
+
for (const option of options ?? []) {
|
|
67
|
+
const code = option.value;
|
|
68
|
+
if (typeof code !== "string" || readPhiCurrencyExponent(code) === undefined) {
|
|
69
|
+
throw new Error(`A money field's options name ${describe(code)}; each option's value is an ISO 4217 currency code a payment accepts.`);
|
|
70
|
+
}
|
|
71
|
+
if (!currencies.includes(code))
|
|
72
|
+
currencies.push(code);
|
|
73
|
+
}
|
|
74
|
+
if (isPhiRecord(value)) {
|
|
75
|
+
for (const code of Object.keys(value)) {
|
|
76
|
+
if (!currencies.includes(code) && readPhiCurrencyExponent(code) !== undefined)
|
|
77
|
+
currencies.push(code);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return currencies;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The currency a `currencyField` amount is in: the other field's value, `null` while it names none. A
|
|
84
|
+
* value that is a code a payment does not accept throws, as a config naming one does.
|
|
85
|
+
*/
|
|
86
|
+
export function readPhiMoneyFieldLinkedCurrency(currencyField, values) {
|
|
87
|
+
const code = values?.[currencyField];
|
|
88
|
+
if (code === undefined || code === null || code === "")
|
|
89
|
+
return null;
|
|
90
|
+
if (typeof code === "string" && readPhiCurrencyExponent(code) !== undefined)
|
|
91
|
+
return code;
|
|
92
|
+
throw new Error(`A money field takes its currency from "${currencyField}", which holds ${describe(code)}; it holds an ISO 4217 currency code a payment accepts.`);
|
|
93
|
+
}
|
|
44
94
|
function describe(value) {
|
|
45
95
|
return JSON.stringify(value) ?? String(value);
|
|
46
96
|
}
|
|
@@ -16,7 +16,10 @@ import type { PhiCmsPageNode, PhiResolvedCmsPageTree } from "../../../types/cms"
|
|
|
16
16
|
* external address nor another Area's root is a place in the Area. Neither is the path the redirecting page itself answers: an Area root whose sidebar still carries an item pointing
|
|
17
17
|
* at "/" would forward to itself forever, which is the whole reason `skipPath` exists.
|
|
18
18
|
*/
|
|
19
|
-
export declare function findFirstPhiCmsNavigationLinkPath(items: readonly PhiCmsResolvedNavigationItem[], skipPath?: string
|
|
19
|
+
export declare function findFirstPhiCmsNavigationLinkPath(items: readonly PhiCmsResolvedNavigationItem[], skipPath?: string, options?: {
|
|
20
|
+
isVisible?: (item: PhiCmsResolvedNavigationItem) => boolean;
|
|
21
|
+
acceptsPath?: (path: string) => boolean;
|
|
22
|
+
}): string | null;
|
|
20
23
|
/**
|
|
21
24
|
* A page that resolves by forwarding.
|
|
22
25
|
*
|
|
@@ -16,15 +16,18 @@ import { readPhiCmsNavigationTargetPath } from "../../../helpers/navigation-targ
|
|
|
16
16
|
* external address nor another Area's root is a place in the Area. Neither is the path the redirecting page itself answers: an Area root whose sidebar still carries an item pointing
|
|
17
17
|
* at "/" would forward to itself forever, which is the whole reason `skipPath` exists.
|
|
18
18
|
*/
|
|
19
|
-
export function findFirstPhiCmsNavigationLinkPath(items, skipPath) {
|
|
19
|
+
export function findFirstPhiCmsNavigationLinkPath(items, skipPath, options) {
|
|
20
20
|
for (const item of items) {
|
|
21
|
+
if (options?.isVisible && !options.isVisible(item)) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
21
24
|
const path = (item.target?.kind === "custom" && item.target.external === true) || item.target?.kind === "area"
|
|
22
25
|
? null
|
|
23
26
|
: readPhiCmsNavigationTargetPath(item.target);
|
|
24
|
-
if (item.kind === "link" && path && path !== skipPath) {
|
|
27
|
+
if (item.kind === "link" && path && path !== skipPath && (options?.acceptsPath?.(path) ?? true)) {
|
|
25
28
|
return path;
|
|
26
29
|
}
|
|
27
|
-
const childPath = findFirstPhiCmsNavigationLinkPath(item.children, skipPath);
|
|
30
|
+
const childPath = findFirstPhiCmsNavigationLinkPath(item.children, skipPath, options);
|
|
28
31
|
if (childPath) {
|
|
29
32
|
return childPath;
|
|
30
33
|
}
|
|
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { formatPhisMoney } from "@phis/contracts/payments";
|
|
4
4
|
import { formatPhiDate, formatPhiDateTime } from "../../../../helpers/format-date-time";
|
|
5
5
|
import { readPhiInternalPath } from "../../../../helpers/internal-path";
|
|
6
|
-
import {
|
|
6
|
+
import { readPhiMoneyValues } from "../../../../helpers/money-amount";
|
|
7
7
|
import { formatPhiInterval, readPhiIntervalValue } from "../../label-types/interval";
|
|
8
8
|
import { usePhiIntlLocale, usePhiIntlTimeZone } from "../../../root/phi-intl-locale";
|
|
9
9
|
import { PhiFlexControl } from "../../../controls/phi-flex-control";
|
|
@@ -45,8 +45,10 @@ function PhiRenderedDate({ value, withTime }) {
|
|
|
45
45
|
return withTime ? formatPhiDateTime(value, locale, timeZone) : formatPhiDate(value, locale, timeZone);
|
|
46
46
|
}
|
|
47
47
|
/** The reader's locale, not the server's or the browser's, and the currency's own places. */
|
|
48
|
+
/** One amount, or a price list's amounts in its order, side by side. */
|
|
48
49
|
function PhiRenderedMoney({ value }) {
|
|
49
|
-
|
|
50
|
+
const locale = usePhiIntlLocale();
|
|
51
|
+
return value.map((amount) => formatPhisMoney(amount, locale)).join(" · ");
|
|
50
52
|
}
|
|
51
53
|
/**
|
|
52
54
|
* The square a picture is drawn in, in a cell and in a record alike: a line of a list. The server's `icon`
|
|
@@ -100,7 +102,7 @@ export function renderPhiValueContent(value, definition, labels, presentation =
|
|
|
100
102
|
* nothing rather than its JSON -- a cell that says `{"currency":"CHF"}` is no amount of money.
|
|
101
103
|
*/
|
|
102
104
|
if (definition.renderer === "money") {
|
|
103
|
-
const money =
|
|
105
|
+
const money = readPhiMoneyValues(value);
|
|
104
106
|
return money ? _jsx(PhiRenderedMoney, { value: money }) : null;
|
|
105
107
|
}
|
|
106
108
|
if (definition.renderer === "interval") {
|
|
@@ -10,6 +10,13 @@ export declare function isPhiMinorAmount(value: unknown): value is string;
|
|
|
10
10
|
* integer, which is how a row out of JSON often carries it. The answer is always the contract's shape.
|
|
11
11
|
*/
|
|
12
12
|
export declare function readPhiMoneyValue(value: unknown): PhisPaymentMoney | null;
|
|
13
|
+
/**
|
|
14
|
+
* The amounts a value handed over as money holds, in its order, or `null` where it is none: one amount as
|
|
15
|
+
* `readPhiMoneyValue` reads it, or a price list as the `money` Form field holds one -- minor units per
|
|
16
|
+
* currency code (`{ CHF: "1990", GBP: "1590" }`), each a currency a payment accepts. A list with no entry,
|
|
17
|
+
* or with one entry that is not an amount, is none: half a price list drawn would read as the whole.
|
|
18
|
+
*/
|
|
19
|
+
export declare function readPhiMoneyValues(value: unknown): readonly PhisPaymentMoney[] | null;
|
|
13
20
|
/** `-1`, `0` or `1` as `left` is less than, equal to or more than `right`; both minor amounts. */
|
|
14
21
|
export declare function comparePhiMinorAmounts(left: string, right: string): number;
|
|
15
22
|
/**
|
package/helpers/money-amount.js
CHANGED
|
@@ -40,6 +40,21 @@ export function readPhiMoneyValue(value) {
|
|
|
40
40
|
const text = typeof minor === "number" && Number.isSafeInteger(minor) && minor >= 0 ? String(minor) : minor;
|
|
41
41
|
return isPhiMinorAmount(text) ? { currency, minor: text } : null;
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* The amounts a value handed over as money holds, in its order, or `null` where it is none: one amount as
|
|
45
|
+
* `readPhiMoneyValue` reads it, or a price list as the `money` Form field holds one -- minor units per
|
|
46
|
+
* currency code (`{ CHF: "1990", GBP: "1590" }`), each a currency a payment accepts. A list with no entry,
|
|
47
|
+
* or with one entry that is not an amount, is none: half a price list drawn would read as the whole.
|
|
48
|
+
*/
|
|
49
|
+
export function readPhiMoneyValues(value) {
|
|
50
|
+
const one = readPhiMoneyValue(value);
|
|
51
|
+
if (one)
|
|
52
|
+
return [one];
|
|
53
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
54
|
+
return null;
|
|
55
|
+
const amounts = Object.entries(value).map(([currency, minor]) => readPhiMoneyValue({ currency, minor }));
|
|
56
|
+
return amounts.length > 0 && amounts.every((amount) => amount !== null) ? amounts : null;
|
|
57
|
+
}
|
|
43
58
|
/** `-1`, `0` or `1` as `left` is less than, equal to or more than `right`; both minor amounts. */
|
|
44
59
|
export function comparePhiMinorAmounts(left, right) {
|
|
45
60
|
const difference = BigInt(left) - BigInt(right);
|
package/package.json
CHANGED
|
@@ -9,12 +9,9 @@ export const PHI_APP_RUNTIME_MODULE_AREA_SHELLS = [
|
|
|
9
9
|
shellPresetVersion: 1,
|
|
10
10
|
area: "app",
|
|
11
11
|
/*
|
|
12
|
-
* The Site shell with
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* What App has that Public does not is somewhere for the Modules a signed-in person works with,
|
|
16
|
-
* and that is the whole of the overlay. Nothing is omitted from the base, so the two trees cannot
|
|
17
|
-
* disagree about a Region: composition refuses a Region type stated twice.
|
|
12
|
+
* The App variant of the Site shell, with the App's left sider added. The Site shell owns the
|
|
13
|
+
* header and footer and the overlay owns the sidebar. Composition refuses a Region type stated
|
|
14
|
+
* twice.
|
|
18
15
|
*/
|
|
19
16
|
loadTree: async ({ page, runtime }) => {
|
|
20
17
|
const [{ buildPhiDefaultSiteAreaPresetTree }, { buildPhiDefaultAppAreaPresetTree }, { mergePhiCmsShellTrees },] = await Promise.all([
|
|
@@ -3,15 +3,12 @@ import type { PhiBlockRuntime } from "../../../../types";
|
|
|
3
3
|
/**
|
|
4
4
|
* The App's own left sider, laid over the Site shell rather than replacing it.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* that place and nothing else, so the Site shell stays the single description of everything above and
|
|
9
|
-
* below it.
|
|
6
|
+
* The Site shell builds the App's header and footer. This overlay gives the signed-in person's
|
|
7
|
+
* Modules a place in the App's own sidebar.
|
|
10
8
|
*
|
|
11
9
|
* The sider is where the Area's navigation belongs, and the reason is in SETTINGS.md section 3: a
|
|
12
10
|
* shell Region outlives a move between Pages, while a Page-owned one is built again for each of them.
|
|
13
|
-
* Navigation placed in the latter rebuilds itself under the hand that just used it.
|
|
14
|
-
* stands above it for the same reason (SEARCH.md): a member searches from wherever they are.
|
|
11
|
+
* Navigation placed in the latter rebuilds itself under the hand that just used it.
|
|
15
12
|
*/
|
|
16
13
|
export declare function buildPhiDefaultAppAreaPresetTree({ page, runtime, }: {
|
|
17
14
|
page: PhiCmsPageNode;
|
|
@@ -14,19 +14,16 @@ const SYNTHETIC_APP_WIDGET_IDS = createPhiPresetCmsInstanceIdMap({
|
|
|
14
14
|
domain: "area",
|
|
15
15
|
ownerModuleId: PHI_APP_RUNTIME_MODULE_ID,
|
|
16
16
|
presetKey: "app-area-preset",
|
|
17
|
-
}, ["widgetSiderLeftNav"
|
|
17
|
+
}, ["widgetSiderLeftNav"]);
|
|
18
18
|
/**
|
|
19
19
|
* The App's own left sider, laid over the Site shell rather than replacing it.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* that place and nothing else, so the Site shell stays the single description of everything above and
|
|
24
|
-
* below it.
|
|
21
|
+
* The Site shell builds the App's header and footer. This overlay gives the signed-in person's
|
|
22
|
+
* Modules a place in the App's own sidebar.
|
|
25
23
|
*
|
|
26
24
|
* The sider is where the Area's navigation belongs, and the reason is in SETTINGS.md section 3: a
|
|
27
25
|
* shell Region outlives a move between Pages, while a Page-owned one is built again for each of them.
|
|
28
|
-
* Navigation placed in the latter rebuilds itself under the hand that just used it.
|
|
29
|
-
* stands above it for the same reason (SEARCH.md): a member searches from wherever they are.
|
|
26
|
+
* Navigation placed in the latter rebuilds itself under the hand that just used it.
|
|
30
27
|
*/
|
|
31
28
|
export async function buildPhiDefaultAppAreaPresetTree({ page, runtime, }) {
|
|
32
29
|
const nodes = createPhiCmsPresetNodes(page);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type PhiBuilderRuntimeControllerConfig, type PhiBuilderRuntimeControllerPreload } from "./definition";
|
|
2
2
|
export declare const PHI_BUILDER_RUNTIME_CONTROLLER_PLUGIN: {
|
|
3
|
-
renderController: ({ preloadData, config }: import("../../../../types").PhiRuntimeControllerRenderArgs<PhiBuilderRuntimeControllerConfig, PhiBuilderRuntimeControllerPreload>) => import("react").FunctionComponentElement<import("./workspace-controller").PhiDeveloperBuilderWorkspaceControllerProps>;
|
|
3
|
+
renderController: ({ preloadData, config, runtime }: import("../../../../types").PhiRuntimeControllerRenderArgs<PhiBuilderRuntimeControllerConfig, PhiBuilderRuntimeControllerPreload>) => import("react").FunctionComponentElement<import("./workspace-controller").PhiDeveloperBuilderWorkspaceControllerProps>;
|
|
4
4
|
kind: "controller";
|
|
5
5
|
pluginKey: string;
|
|
6
6
|
key: string;
|
|
@@ -55,14 +55,14 @@ export declare const PHI_BUILDER_RUNTIME_CONTROLLER_PLUGIN: {
|
|
|
55
55
|
id: string;
|
|
56
56
|
channel: string;
|
|
57
57
|
action: "change";
|
|
58
|
-
valueType: "
|
|
59
|
-
valueSchema
|
|
58
|
+
valueType: "json";
|
|
59
|
+
valueSchema: `${string}/signals/${string}`;
|
|
60
60
|
} | {
|
|
61
61
|
id: string;
|
|
62
62
|
channel: string;
|
|
63
63
|
action: "change";
|
|
64
|
-
valueType: "
|
|
65
|
-
valueSchema
|
|
64
|
+
valueType: "string";
|
|
65
|
+
valueSchema?: undefined;
|
|
66
66
|
} | {
|
|
67
67
|
id: string;
|
|
68
68
|
channel: string;
|
|
@@ -5,7 +5,7 @@ import { PhiDeveloperBuilderWorkspaceControllerMount } from "./mount";
|
|
|
5
5
|
import { PHI_BUILDER_RUNTIME_CONTROLLER_DEFINITION, } from "./definition";
|
|
6
6
|
export const PHI_BUILDER_RUNTIME_CONTROLLER_PLUGIN = {
|
|
7
7
|
...PHI_BUILDER_RUNTIME_CONTROLLER_DEFINITION,
|
|
8
|
-
renderController: ({ preloadData, config }) => {
|
|
8
|
+
renderController: ({ preloadData, config, runtime }) => {
|
|
9
9
|
if (!preloadData?.shellPresetDraftsByArea ||
|
|
10
10
|
!preloadData.runtimeModuleDefinitions ||
|
|
11
11
|
!preloadData.runtimeModuleIdsByArea ||
|
|
@@ -25,6 +25,7 @@ export const PHI_BUILDER_RUNTIME_CONTROLLER_PLUGIN = {
|
|
|
25
25
|
throw new Error("Builder runtime controller requires server preload data.");
|
|
26
26
|
}
|
|
27
27
|
return createElement(PhiDeveloperBuilderWorkspaceControllerMount, {
|
|
28
|
+
viewer: runtime.viewer,
|
|
28
29
|
signalRoutes: config.signalRoutes,
|
|
29
30
|
shellPresetDraftsByArea: preloadData.shellPresetDraftsByArea,
|
|
30
31
|
runtimeModuleDefinitions: preloadData.runtimeModuleDefinitions,
|
|
@@ -105,14 +105,14 @@ export declare const PHI_BUILDER_RUNTIME_CONTROLLER_DEFINITION: {
|
|
|
105
105
|
id: string;
|
|
106
106
|
channel: string;
|
|
107
107
|
action: "change";
|
|
108
|
-
valueType: "
|
|
109
|
-
valueSchema
|
|
108
|
+
valueType: "json";
|
|
109
|
+
valueSchema: `${string}/signals/${string}`;
|
|
110
110
|
} | {
|
|
111
111
|
id: string;
|
|
112
112
|
channel: string;
|
|
113
113
|
action: "change";
|
|
114
|
-
valueType: "
|
|
115
|
-
valueSchema
|
|
114
|
+
valueType: "string";
|
|
115
|
+
valueSchema?: undefined;
|
|
116
116
|
} | {
|
|
117
117
|
id: string;
|
|
118
118
|
channel: string;
|
|
@@ -150,6 +150,13 @@ export const PHI_BUILDER_RUNTIME_CONTROLLER_DEFINITION = {
|
|
|
150
150
|
action: "activate",
|
|
151
151
|
valueType: "none",
|
|
152
152
|
},
|
|
153
|
+
{
|
|
154
|
+
id: "revisionDraftStatus",
|
|
155
|
+
channel: "draftStatus",
|
|
156
|
+
action: "change",
|
|
157
|
+
valueType: "json",
|
|
158
|
+
valueSchema: PHI_SIGNAL_VALUE_SCHEMAS.revisionsDraftStatus,
|
|
159
|
+
},
|
|
153
160
|
{
|
|
154
161
|
id: "builderMode",
|
|
155
162
|
channel: "builderMode",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { PhiAccessViewer } from "../../../../types/access";
|
|
1
2
|
import { type PhiHistoryLabels } from "../../../../components/widgets/label-types/history";
|
|
2
3
|
import type { PhiBuilderSavedHistoryHead } from "./draft-status-controller";
|
|
3
4
|
import type { PhiDeveloperBuilderArea, PhiDeveloperBuilderWorkspaceState } from "../developer-workspace-types";
|
|
4
5
|
export type PhiDeveloperBuilderToolbarCommand = "save" | "preview" | "publish" | "undo" | "redo" | "reset";
|
|
5
|
-
export declare function usePhiBuilderDraftCommandController({ effectiveArea, effectiveNavKey, effectivePageKey, pathname, captureHistoryHead, reportSaved, hasUnsavedChanges, state, historyLabels, }: {
|
|
6
|
+
export declare function usePhiBuilderDraftCommandController({ effectiveArea, effectiveNavKey, effectivePageKey, pathname, captureHistoryHead, reportSaved, hasUnsavedChanges, state, viewer, historyLabels, }: {
|
|
6
7
|
effectiveArea: PhiDeveloperBuilderArea;
|
|
7
8
|
effectiveNavKey: string;
|
|
8
9
|
effectivePageKey: string;
|
|
@@ -14,6 +15,7 @@ export declare function usePhiBuilderDraftCommandController({ effectiveArea, eff
|
|
|
14
15
|
/** Whether the workspace on screen holds edits no stored revision has. */
|
|
15
16
|
hasUnsavedChanges: boolean;
|
|
16
17
|
state: PhiDeveloperBuilderWorkspaceState;
|
|
18
|
+
viewer: PhiAccessViewer;
|
|
17
19
|
/** What an undo or redo says it moved, in the author's language. */
|
|
18
20
|
historyLabels: PhiHistoryLabels;
|
|
19
21
|
}): {
|
|
@@ -19,7 +19,7 @@ import { usePhiBuilderModuleMetas } from "../plugin-meta-store";
|
|
|
19
19
|
import { setPhiWorkspaceModuleSelection } from "../workspace-catalog-actions";
|
|
20
20
|
import { applyPhiBuilderNavigationFolderTargets, refreshPhiBuilderNavigationFolderAddresses, } from "../navigation-folder-address";
|
|
21
21
|
import { createPhiBuilderNavigationPathContext } from "../navigation-path-context";
|
|
22
|
-
export function usePhiBuilderDraftCommandController({ effectiveArea, effectiveNavKey, effectivePageKey, pathname, captureHistoryHead, reportSaved, hasUnsavedChanges, state, historyLabels, }) {
|
|
22
|
+
export function usePhiBuilderDraftCommandController({ effectiveArea, effectiveNavKey, effectivePageKey, pathname, captureHistoryHead, reportSaved, hasUnsavedChanges, state, viewer, historyLabels, }) {
|
|
23
23
|
/*
|
|
24
24
|
* Every one of these is a command from a toolbar somewhere else, so there is nothing on screen to
|
|
25
25
|
* hang a Popconfirm on. Drawn as a Dialog by this Controller rather than asked of Ant Design's
|
|
@@ -258,6 +258,7 @@ export function usePhiBuilderDraftCommandController({ effectiveArea, effectiveNa
|
|
|
258
258
|
* before it opens, and which of the two it shows.
|
|
259
259
|
*/
|
|
260
260
|
const result = await previewPhiDeveloperBuilderDraft(state, workspaceKind, {
|
|
261
|
+
viewer,
|
|
261
262
|
pathname,
|
|
262
263
|
scope: previewScope,
|
|
263
264
|
});
|