@phis/ui 0.7.5 → 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.d.ts +3 -1
- package/components/controls/phi-form-control.js +15 -4
- package/components/forms/auth-admin-settings-labels.d.ts +1 -1
- package/components/forms/auth-admin-settings-labels.js +2 -2
- 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-descriptor-contract.d.ts +1 -1
- package/components/forms/form-descriptor-contract.js +1 -1
- package/components/forms/form-descriptor-runtime-client.d.ts +4 -1
- package/components/forms/form-descriptor-runtime-client.js +33 -11
- package/components/forms/form-media-limits.d.ts +12 -0
- package/components/forms/form-media-limits.js +14 -0
- 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 +14 -0
- package/components/forms/form-record-title.d.ts +14 -0
- package/components/forms/form-record-title.js +38 -0
- package/components/forms/form-widget-config.d.ts +3 -0
- package/components/forms/form-widget-config.js +2 -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/forms/phi-form-widget.d.ts +1 -1
- package/components/forms/phi-form-widget.js +4 -0
- package/components/overlays/phi-overlay-container-client.js +8 -8
- package/components/overlays/phi-overlay-title.d.ts +7 -0
- package/components/overlays/phi-overlay-title.js +21 -0
- package/components/regions/presets/navigation-redirect.d.ts +4 -1
- package/components/regions/presets/navigation-redirect.js +6 -3
- package/components/tables/client/phi-table-binding.d.ts +3 -1
- package/components/tables/client/phi-table-binding.js +90 -49
- package/components/tables/client/phi-table-filter-options.d.ts +27 -0
- package/components/tables/client/phi-table-filter-options.js +35 -0
- package/components/widgets/accessible-areas.d.ts +1 -1
- package/components/widgets/accessible-areas.js +1 -1
- package/components/widgets/client/shared/phi-rendered-value.d.ts +10 -0
- package/components/widgets/client/shared/phi-rendered-value.js +54 -4
- package/components/widgets/client/shared/phi-table-provider.d.ts +10 -1
- package/components/widgets/client/shared/phi-table-provider.js +22 -0
- package/components/widgets/label-sets/admin-users.d.ts +15 -0
- package/components/widgets/label-sets/admin-users.js +31 -0
- package/constants/core-data-provider-keys.d.ts +7 -0
- package/constants/core-data-provider-keys.js +7 -0
- package/constants/phi-base-role-metadata.d.ts +2 -2
- package/constants/phi-base-role-metadata.js +1 -1
- package/constants/runtime-module-ownership.js +3 -0
- package/forms.d.ts +1 -1
- package/forms.js +1 -1
- package/gateway/capability-media-limits.d.ts +10 -0
- package/gateway/capability-media-limits.js +40 -0
- package/gateway/server-capabilities.js +4 -0
- package/helpers/money-amount.d.ts +7 -0
- package/helpers/money-amount.js +15 -0
- package/helpers/preset-tree-contract-check.d.ts +3 -2
- package/helpers/preset-tree-contract-check.js +60 -0
- package/helpers/record-title.d.ts +7 -0
- package/helpers/record-title.js +25 -0
- package/helpers/record-widget.d.ts +15 -0
- package/helpers/record-widget.js +57 -0
- package/package.json +2 -2
- package/plugins/runtime-modules/accounting/client-data-providers.d.ts +7 -0
- package/plugins/runtime-modules/accounting/client-data-providers.js +9 -0
- package/plugins/runtime-modules/accounting/data-providers.d.ts +63 -0
- package/plugins/runtime-modules/accounting/data-providers.js +127 -0
- package/plugins/runtime-modules/accounting/definition.d.ts +54 -2
- package/plugins/runtime-modules/accounting/definition.js +5 -3
- package/plugins/runtime-modules/accounting/ids.d.ts +20 -0
- package/plugins/runtime-modules/accounting/ids.js +27 -0
- package/plugins/runtime-modules/accounting/module.d.ts +52 -0
- package/plugins/runtime-modules/accounting/presets.js +23 -4
- package/plugins/runtime-modules/accounting/services/products-table.d.ts +93 -0
- package/plugins/runtime-modules/accounting/services/products-table.js +158 -0
- package/plugins/runtime-modules/accounting/trees/accounting-products-label-set.d.ts +86 -0
- package/plugins/runtime-modules/accounting/trees/accounting-products-label-set.js +123 -0
- package/plugins/runtime-modules/accounting/trees/phi-default-accounting-products-page-tree.d.ts +21 -0
- package/plugins/runtime-modules/accounting/trees/phi-default-accounting-products-page-tree.js +435 -0
- 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/area-definitions.js +2 -2
- package/plugins/runtime-modules/asset/media-asset-field.d.ts +15 -0
- package/plugins/runtime-modules/asset/media-asset-field.js +21 -0
- package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +4 -0
- package/plugins/runtime-modules/asset/media-asset-form-control.js +10 -5
- package/plugins/runtime-modules/asset/media-assets-field.d.ts +8 -0
- package/plugins/runtime-modules/asset/media-assets-field.js +10 -0
- package/plugins/runtime-modules/asset/media-assets-form-control.d.ts +5 -0
- package/plugins/runtime-modules/asset/media-assets-form-control.js +15 -6
- package/plugins/runtime-modules/auth/admin-settings-forms.js +1 -1
- 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/client-manifests/accounting.js +5 -1
- package/plugins/runtime-modules/core/cards.js +2 -2
- package/plugins/runtime-modules/core/client-data-providers.js +5 -0
- package/plugins/runtime-modules/core/data-providers.js +14 -0
- 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/services/site-members-options.d.ts +27 -0
- package/plugins/runtime-modules/core/services/site-members-options.js +55 -0
- package/plugins/runtime-modules/core/widgets/form/config.d.ts +5 -0
- package/plugins/runtime-modules/core/widgets/form/config.js +3 -0
- package/plugins/runtime-modules/core/widgets/record/actions.d.ts +20 -0
- package/plugins/runtime-modules/core/widgets/record/actions.js +77 -0
- package/plugins/runtime-modules/core/widgets/record/client.js +71 -8
- package/plugins/runtime-modules/core/widgets/record/config.d.ts +66 -1
- package/plugins/runtime-modules/core/widgets/record/config.js +71 -2
- package/plugins/runtime-modules/core/widgets/spacer/client.js +3 -3
- package/plugins/runtime-modules/core/widgets/table/client.js +33 -29
- package/plugins/runtime-modules/core/widgets/table/config.js +5 -1
- package/plugins/runtime-modules/groups/data-providers.js +1 -1
- package/plugins/runtime-modules/groups/definition.js +1 -1
- package/plugins/runtime-modules/groups/page-visibility.d.ts +1 -1
- package/plugins/runtime-modules/groups/page-visibility.js +1 -1
- package/plugins/runtime-modules/groups/presets.js +1 -1
- package/plugins/runtime-modules/groups/services/options.js +1 -1
- package/plugins/runtime-modules/groups/services/table.js +1 -1
- package/plugins/runtime-modules/groups/trees/phi-default-app-groups-page-tree.js +2 -2
- 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/plugins/runtime-modules/user-management/addon-roles.d.ts +60 -4
- package/plugins/runtime-modules/user-management/addon-roles.js +92 -8
- package/plugins/runtime-modules/user-management/addresses.d.ts +1 -1
- package/plugins/runtime-modules/user-management/controller/client.js +1 -1
- package/plugins/runtime-modules/user-management/data-providers.js +1 -0
- package/plugins/runtime-modules/user-management/forms.js +22 -0
- package/plugins/runtime-modules/user-management/presets.js +2 -2
- package/plugins/runtime-modules/user-management/services/options.d.ts +4 -0
- package/plugins/runtime-modules/user-management/services/options.js +14 -6
- package/plugins/runtime-modules/user-management/services/table.js +12 -3
- package/plugins/runtime-modules/user-management/trees/phi-default-admin-users-page-tree.js +9 -4
- package/styles/builder-scaffold.css +7 -1
- package/styles/layout-authoring-scaffold.css +27 -0
- package/types/access.d.ts +1 -1
- package/types/access.js +7 -7
- package/types/core-widget-placements.d.ts +7 -0
- package/types/form-descriptor.d.ts +1 -1
- package/types/record-widget.d.ts +35 -0
- package/types/server-capabilities.d.ts +1 -1
- package/types/table-widget.d.ts +20 -0
- package/types/table-widget.js +44 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type FormInstance } from "antd";
|
|
2
2
|
import type { PhiFormDescriptor } from "../../types/form-descriptor";
|
|
3
|
-
import type { PhiFormProviderRegistry } from "../forms/form-provider-registry";
|
|
3
|
+
import type { PhiFormFieldProviderProps, PhiFormProviderRegistry } from "../forms/form-provider-registry";
|
|
4
4
|
export type PhiFormControlProps = {
|
|
5
5
|
descriptor: PhiFormDescriptor;
|
|
6
6
|
registry?: PhiFormProviderRegistry;
|
|
@@ -22,6 +22,8 @@ export type PhiFormControlProps = {
|
|
|
22
22
|
* dropped: what the form holds for it goes out with the submit unchanged.
|
|
23
23
|
*/
|
|
24
24
|
unavailableFieldKeys?: readonly string[];
|
|
25
|
+
/** The Media limits of the Add-on the Form's Module is bound to, handed to every field (`PhiFormFieldProviderProps`). */
|
|
26
|
+
mediaLimits?: PhiFormFieldProviderProps["mediaLimits"];
|
|
25
27
|
form?: PhiFormControlFormInstance;
|
|
26
28
|
onValuesChange?: (changedValues: Record<string, unknown>, allValues: Record<string, unknown>) => void;
|
|
27
29
|
onSubmit: (values: Record<string, unknown>) => void | Promise<void>;
|
|
@@ -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();
|
|
@@ -72,7 +83,7 @@ function pickPhiFormWatchedValues(values, keys) {
|
|
|
72
83
|
}
|
|
73
84
|
return picked;
|
|
74
85
|
}
|
|
75
|
-
function PhiResolvedFormFieldControl({ id, provider, field, label, description, labels, formConfig, placeholder, disabled, readOnly, value, checked, onChange, formContext, formValues, }) {
|
|
86
|
+
function PhiResolvedFormFieldControl({ id, provider, field, label, description, labels, formConfig, placeholder, disabled, readOnly, value, checked, onChange, formContext, formValues, mediaLimits, }) {
|
|
76
87
|
const staticOptions = useMemo(() => field.options?.map((option) => ({
|
|
77
88
|
...option,
|
|
78
89
|
label: resolvePhiFormText(option.label, labels, formConfig),
|
|
@@ -132,12 +143,12 @@ 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 }), 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 `{}`.
|
|
139
150
|
const PHI_FORM_NO_CONTROLLER_STATES = Object.freeze({});
|
|
140
|
-
export const PhiFormControl = forwardRef(function PhiFormControl({ descriptor, registry, labels, formConfig, initialValues, submitOnEnter, disabled = false, readOnly = false, conditionControllerStates = PHI_FORM_NO_CONTROLLER_STATES, unavailableFieldKeys, form: providedForm, onValuesChange, onSubmit, onSubmittingChange, onValidationFailed, onFormReady, onStateChange, onBlurCapture, }, ref) {
|
|
151
|
+
export const PhiFormControl = forwardRef(function PhiFormControl({ descriptor, registry, labels, formConfig, initialValues, submitOnEnter, disabled = false, readOnly = false, conditionControllerStates = PHI_FORM_NO_CONTROLLER_STATES, unavailableFieldKeys, mediaLimits, form: providedForm, onValuesChange, onSubmit, onSubmittingChange, onValidationFailed, onFormReady, onStateChange, onBlurCapture, }, ref) {
|
|
141
152
|
const contributedRegistry = usePhiFormProviderRegistry();
|
|
142
153
|
const activeRegistry = useMemo(() => registry ?? (contributedRegistry
|
|
143
154
|
? extendPhiFormProviderRegistry(PHI_SHARED_FORM_PROVIDER_REGISTRY, contributedRegistry)
|
|
@@ -518,6 +529,6 @@ export const PhiFormControl = forwardRef(function PhiFormControl({ descriptor, r
|
|
|
518
529
|
...resolveHoneypotStyle(provider.presentation),
|
|
519
530
|
}, children: _jsx(Form.Item, { name: field.key, messageVariables: { label: labelText ?? field.key }, hidden: hidden, valuePropName: provider.valuePropName, dependencies: dependencies, required: required, rules: resolvedRules.length === 0 ? undefined : resolvedRules, style: { marginBottom: 0 }, children: _jsx(PhiResolvedFormFieldControl, { provider: provider, field: field, label: providerLabel, description: providerDescription, labels: labels, formConfig: formConfig, placeholder: field.placeholder
|
|
520
531
|
? resolvePhiFormText(field.placeholder, labels, formConfig)
|
|
521
|
-
: undefined, disabled: disabled || submitting || readOnly || field.config?.disabled === true || fieldDisabled !== "not-matched", readOnly: readOnly, formContext: fieldFormContext, formValues: formValues }) }) })] }, field.key));
|
|
532
|
+
: undefined, disabled: disabled || submitting || readOnly || field.config?.disabled === true || fieldDisabled !== "not-matched", readOnly: readOnly, formContext: fieldFormContext, formValues: formValues, mediaLimits: mediaLimits }) }) })] }, field.key));
|
|
522
533
|
}) }) }));
|
|
523
534
|
});
|
|
@@ -36,7 +36,7 @@ const PHI_AUTH_ADMIN_SETTINGS_LABEL_SET = definePhiLabelSet({
|
|
|
36
36
|
totp_roles_label: "Required for roles",
|
|
37
37
|
totp_roles_hint: definePhiMessageLabel("Leave empty to require two-factor authentication for every site member."),
|
|
38
38
|
role_admin: "Admin",
|
|
39
|
-
|
|
39
|
+
role_maintainer: "Maintainer",
|
|
40
40
|
role_builder: "Builder",
|
|
41
41
|
role_author: "Author",
|
|
42
42
|
role_publisher: "Publisher",
|
|
@@ -152,7 +152,7 @@ export async function getPhiAuthAdminSettingsLabels(options) {
|
|
|
152
152
|
},
|
|
153
153
|
roles: {
|
|
154
154
|
admin: labels.role_admin,
|
|
155
|
-
|
|
155
|
+
maintainer: labels.role_maintainer,
|
|
156
156
|
builder: labels.role_builder,
|
|
157
157
|
author: labels.role_author,
|
|
158
158
|
publisher: labels.role_publisher,
|
|
@@ -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.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PhiFormFieldPlacementDescriptor, PhiFormGridRange } from "@phis/contracts/forms";
|
|
2
2
|
import { type PhiFormResponsiveMode, type PhiResolvedFormLayout } from "@phis/contracts/forms";
|
|
3
|
-
export { PHI_FORM_DEFAULT_LAYOUT, PHI_FORM_GRID_LAST_LINE, PHI_FORM_RESPONSIVE_MODES, PHI_FORM_ROW_END_HALF, PHI_FORM_ROW_FULL, PHI_FORM_SIDE_END_HALF, PHI_FORM_SIDE_START_HALF, PHI_FORM_STACKED_END_HALF, PHI_FORM_STACKED_FULL, PHI_FORM_STACKED_LAYOUT, assertPhiFormLabelSetKey, createPhiFormLabelText, createPhiFormLiteralText, parsePhiFormDescriptor, phiFormFlowHalfColumns, resolvePhiFormLayout, resolvePhiFormResponsiveGridRange, resolvePhiFormText, type PhiFormResponsiveMode, type PhiResolvedFormLayout, type PhiResolvedFormResponsiveGridRange, } from "@phis/contracts/forms";
|
|
3
|
+
export { PHI_FORM_DEFAULT_LAYOUT, PHI_FORM_GRID_LAST_LINE, PHI_FORM_RESPONSIVE_MODES, PHI_FORM_ROW_END_HALF, PHI_FORM_ROW_FULL, PHI_FORM_SIDE_END_HALF, PHI_FORM_SIDE_START_HALF, PHI_FORM_STACKED_END_HALF, PHI_FORM_STACKED_FULL, PHI_FORM_STACKED_LAYOUT, assertPhiFormLabelSetKey, createPhiFormLabelText, createPhiFormLiteralText, parsePhiFormDescriptor, phiFormFlowHalfColumns, resolvePhiFormLayout, resolvePhiFormErrorText, resolvePhiFormResponsiveGridRange, resolvePhiFormText, type PhiFormResponsiveMode, type PhiResolvedFormLayout, type PhiResolvedFormResponsiveGridRange, } from "@phis/contracts/forms";
|
|
4
4
|
export declare function shouldPhiFormSubmitOnKeyDown(input: {
|
|
5
5
|
key: string;
|
|
6
6
|
defaultPrevented: boolean;
|
|
@@ -5,7 +5,7 @@ import { PHI_CONTAINER_BREAKPOINT_COL3, PHI_CONTAINER_BREAKPOINT_CONTENT, } from
|
|
|
5
5
|
* stores descriptors and reads them by the same rules. What stays below is how this renderer turns the
|
|
6
6
|
* grid into rows and CSS, which is nobody else's business.
|
|
7
7
|
*/
|
|
8
|
-
export { PHI_FORM_DEFAULT_LAYOUT, PHI_FORM_GRID_LAST_LINE, PHI_FORM_RESPONSIVE_MODES, PHI_FORM_ROW_END_HALF, PHI_FORM_ROW_FULL, PHI_FORM_SIDE_END_HALF, PHI_FORM_SIDE_START_HALF, PHI_FORM_STACKED_END_HALF, PHI_FORM_STACKED_FULL, PHI_FORM_STACKED_LAYOUT, assertPhiFormLabelSetKey, createPhiFormLabelText, createPhiFormLiteralText, parsePhiFormDescriptor, phiFormFlowHalfColumns, resolvePhiFormLayout, resolvePhiFormResponsiveGridRange, resolvePhiFormText, } from "@phis/contracts/forms";
|
|
8
|
+
export { PHI_FORM_DEFAULT_LAYOUT, PHI_FORM_GRID_LAST_LINE, PHI_FORM_RESPONSIVE_MODES, PHI_FORM_ROW_END_HALF, PHI_FORM_ROW_FULL, PHI_FORM_SIDE_END_HALF, PHI_FORM_SIDE_START_HALF, PHI_FORM_STACKED_END_HALF, PHI_FORM_STACKED_FULL, PHI_FORM_STACKED_LAYOUT, assertPhiFormLabelSetKey, createPhiFormLabelText, createPhiFormLiteralText, parsePhiFormDescriptor, phiFormFlowHalfColumns, resolvePhiFormLayout, resolvePhiFormErrorText, resolvePhiFormResponsiveGridRange, resolvePhiFormText, } from "@phis/contracts/forms";
|
|
9
9
|
export function shouldPhiFormSubmitOnKeyDown(input) {
|
|
10
10
|
return input.key === "Enter" &&
|
|
11
11
|
!input.defaultPrevented &&
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PhiSignalAddress } from "../../types/signals";
|
|
2
2
|
import type { PhiFormDescriptor } from "../../types/form-descriptor";
|
|
3
3
|
import type { PhiCmsFormWidgetConfig } from "./form-widget-config";
|
|
4
|
+
import { type PhiFormControlProps } from "../controls/phi-form-control";
|
|
4
5
|
export type PhiFormDescriptorRuntimeClientProps = {
|
|
5
6
|
descriptor: PhiFormDescriptor;
|
|
6
7
|
labels?: Readonly<Record<string, string>>;
|
|
@@ -11,5 +12,7 @@ export type PhiFormDescriptorRuntimeClientProps = {
|
|
|
11
12
|
widgetConfig?: PhiCmsFormWidgetConfig;
|
|
12
13
|
/** The fields whose field type belongs to a Module that is not active in this Area. */
|
|
13
14
|
unavailableFieldKeys?: readonly string[];
|
|
15
|
+
/** The Media limits of the Add-on the Form's Module is bound to, for its Media fields (FORMS.md). */
|
|
16
|
+
mediaLimits?: PhiFormControlProps["mediaLimits"];
|
|
14
17
|
};
|
|
15
|
-
export declare function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedInitialValues, formId, formControllerAddress, widgetConfig, unavailableFieldKeys, }: PhiFormDescriptorRuntimeClientProps): import("react").JSX.Element;
|
|
18
|
+
export declare function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedInitialValues, formId, formControllerAddress, widgetConfig, unavailableFieldKeys, mediaLimits, }: PhiFormDescriptorRuntimeClientProps): import("react").JSX.Element;
|
|
@@ -13,7 +13,8 @@ import { usePhiTableProvider } from "../widgets/client/shared/phi-table-provider
|
|
|
13
13
|
import { usePhiIntlLocale, usePhiIntlTimeZone } from "../root/phi-intl-locale";
|
|
14
14
|
import { PhiFormControl } from "../controls/phi-form-control";
|
|
15
15
|
import { readPhiRuntimeFormValuesSignalValue } from "./runtime-form-state";
|
|
16
|
-
import { resolvePhiFormText } from "./form-descriptor-contract";
|
|
16
|
+
import { resolvePhiFormErrorText, resolvePhiFormText } from "./form-descriptor-contract";
|
|
17
|
+
import { PHI_FORM_RECORD_TITLE_CAPABILITY, resolvePhiFormRecordTitle } from "./form-record-title";
|
|
17
18
|
import { PhiFormWidgetSubmitOutlet, usePhiFormWidgetSubmit } from "./phi-form-widget-frame";
|
|
18
19
|
import { usePhiRuntimeFormClient } from "./runtime-form-client";
|
|
19
20
|
import { PhiAlertControl } from "../controls/phi-alert-control";
|
|
@@ -27,7 +28,7 @@ import { usePhiInDialogBody } from "../overlays/phi-dialog-body-context";
|
|
|
27
28
|
/** How long before its window closes a token is renewed rather than sent: the request takes time too. */
|
|
28
29
|
const PHI_FORM_GUARD_EXPIRY_MARGIN_MS = 60_000;
|
|
29
30
|
const EMPTY_FORM_VALUES = {};
|
|
30
|
-
export function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedInitialValues, formId, formControllerAddress, widgetConfig, unavailableFieldKeys, }) {
|
|
31
|
+
export function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedInitialValues, formId, formControllerAddress, widgetConfig, unavailableFieldKeys, mediaLimits, }) {
|
|
31
32
|
const formClient = usePhiRuntimeFormClient({ controllerAddress: formControllerAddress });
|
|
32
33
|
const formRef = useRef(null);
|
|
33
34
|
const submitCorrelationRef = useRef(null);
|
|
@@ -133,6 +134,23 @@ export function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedIniti
|
|
|
133
134
|
const emitCapability = useCallback((capabilityId, value = null, correlationId) => {
|
|
134
135
|
emitPhiSignalCapability(emitSignal, widgetConfig?.signalRoutes?.emits, capabilityId, value, correlationId);
|
|
135
136
|
}, [emitSignal, widgetConfig]);
|
|
137
|
+
/*
|
|
138
|
+
* The title the record gives the dialog, where the placement takes one (`titleFromRecord`): announced
|
|
139
|
+
* after every read, and empty as a row is asked for, so the last row's name does not stand over the
|
|
140
|
+
* next one while it loads. Empty is the Overlay's own title.
|
|
141
|
+
*/
|
|
142
|
+
const titleFromRecord = widgetConfig?.titleFromRecord ?? null;
|
|
143
|
+
const formConfig = widgetConfig?.formConfig;
|
|
144
|
+
const announceRecordTitle = useCallback((values, correlationId) => {
|
|
145
|
+
if (!titleFromRecord)
|
|
146
|
+
return;
|
|
147
|
+
emitCapability(PHI_FORM_RECORD_TITLE_CAPABILITY, resolvePhiFormRecordTitle(titleFromRecord, values, labels, formConfig), correlationId);
|
|
148
|
+
}, [emitCapability, formConfig, labels, titleFromRecord]);
|
|
149
|
+
// For the read on mount, which must not run again because the words around it changed.
|
|
150
|
+
const announceRecordTitleRef = useRef(announceRecordTitle);
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
announceRecordTitleRef.current = announceRecordTitle;
|
|
153
|
+
}, [announceRecordTitle]);
|
|
136
154
|
/*
|
|
137
155
|
* That the values now in the form have already been rejected, and nothing has changed since.
|
|
138
156
|
*
|
|
@@ -184,7 +202,7 @@ export function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedIniti
|
|
|
184
202
|
recordLoadRef.current?.abort();
|
|
185
203
|
recordLoadRef.current = null;
|
|
186
204
|
}, []);
|
|
187
|
-
const loadRecord = useCallback(async (rowIdentity) => {
|
|
205
|
+
const loadRecord = useCallback(async (rowIdentity, correlationId) => {
|
|
188
206
|
setLoading(true);
|
|
189
207
|
setError(null);
|
|
190
208
|
const abortController = beginRecordLoad();
|
|
@@ -196,6 +214,7 @@ export function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedIniti
|
|
|
196
214
|
recordIdentityRef.current = rowIdentity;
|
|
197
215
|
setRecord(values);
|
|
198
216
|
setRecordKey(rowIdentity == null ? "singleton" : String(rowIdentity));
|
|
217
|
+
announceRecordTitle(values, correlationId);
|
|
199
218
|
}
|
|
200
219
|
catch (readError) {
|
|
201
220
|
if (!signal.aborted) {
|
|
@@ -206,7 +225,7 @@ export function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedIniti
|
|
|
206
225
|
if (!signal.aborted)
|
|
207
226
|
setLoading(false);
|
|
208
227
|
}
|
|
209
|
-
}, [beginRecordLoad, readRecord]);
|
|
228
|
+
}, [announceRecordTitle, beginRecordLoad, readRecord]);
|
|
210
229
|
useEffect(() => {
|
|
211
230
|
if (!source || widgetConfig?.openActionKey)
|
|
212
231
|
return;
|
|
@@ -218,6 +237,7 @@ export function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedIniti
|
|
|
218
237
|
setRecord(values);
|
|
219
238
|
setRecordKey("singleton");
|
|
220
239
|
setError(null);
|
|
240
|
+
announceRecordTitleRef.current(values);
|
|
221
241
|
}).catch((readError) => {
|
|
222
242
|
if (!abortController.signal.aborted) {
|
|
223
243
|
setError(readError instanceof Error ? readError.message : "Form record loading failed.");
|
|
@@ -253,7 +273,8 @@ export function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedIniti
|
|
|
253
273
|
const action = readPhiTableActionSignalValue(signal.value);
|
|
254
274
|
if (!action || action.actionKey !== (widgetConfig?.openActionKey ?? "edit") || action.rowIdentity == null)
|
|
255
275
|
return;
|
|
256
|
-
|
|
276
|
+
announceRecordTitle(null, signal.correlationId);
|
|
277
|
+
void loadRecord(action.rowIdentity, signal.correlationId);
|
|
257
278
|
emitCapability("conditionStateRequest", null, signal.correlationId);
|
|
258
279
|
}
|
|
259
280
|
else if (route.capabilityId === "close") {
|
|
@@ -263,7 +284,7 @@ export function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedIniti
|
|
|
263
284
|
else if (route.capabilityId === "reload") {
|
|
264
285
|
const rowIdentity = recordIdentityRef.current;
|
|
265
286
|
if (rowIdentity != null)
|
|
266
|
-
void loadRecord(rowIdentity);
|
|
287
|
+
void loadRecord(rowIdentity, signal.correlationId);
|
|
267
288
|
}
|
|
268
289
|
else if (route.capabilityId === "submit") {
|
|
269
290
|
/*
|
|
@@ -297,7 +318,7 @@ export function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedIniti
|
|
|
297
318
|
setConditionControllerStates((current) => ({ ...current, [signal.sender]: next.state }));
|
|
298
319
|
}
|
|
299
320
|
}
|
|
300
|
-
}, [conditionControllerAddresses, emitCapability, formControllerAddress, identity.receiver, loadRecord, requestReset, requestSubmit, widgetConfig]), useMemo(() => {
|
|
321
|
+
}, [announceRecordTitle, conditionControllerAddresses, emitCapability, formControllerAddress, identity.receiver, loadRecord, requestReset, requestSubmit, widgetConfig]), useMemo(() => {
|
|
301
322
|
const listenRoutes = widgetConfig?.signalRoutes?.listens ?? [];
|
|
302
323
|
return listenRoutes.length === 0 ? null : {
|
|
303
324
|
scopes: Array.from(new Set(listenRoutes.map((route) => route.scope))),
|
|
@@ -467,7 +488,7 @@ export function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedIniti
|
|
|
467
488
|
activeForm.setFieldsValue(pendingValuesRef.current);
|
|
468
489
|
pendingValuesRef.current = null;
|
|
469
490
|
}
|
|
470
|
-
}, conditionControllerStates: conditionControllerStates, unavailableFieldKeys: unavailableFieldKeys, onValuesChange: (changed, all) => {
|
|
491
|
+
}, conditionControllerStates: conditionControllerStates, unavailableFieldKeys: unavailableFieldKeys, mediaLimits: mediaLimits, onValuesChange: (changed, all) => {
|
|
471
492
|
// A value moved, so whatever validation refused before is no longer what is being asked.
|
|
472
493
|
rejectedRef.current = false;
|
|
473
494
|
runtimeBinding.onValuesChange(changed, all);
|
|
@@ -523,14 +544,15 @@ export function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedIniti
|
|
|
523
544
|
/*
|
|
524
545
|
* The code first: it is the only part of a refusal that can be said in the visitor's
|
|
525
546
|
* language, because the descriptor maps it to a label. `error` is what the handler wrote
|
|
526
|
-
* for a log, and it stands in only where the code is absent or nothing maps it.
|
|
547
|
+
* for a log, and it stands in only where the code is absent or nothing maps it. A mapped
|
|
548
|
+
* text may name values of the same answer (`product`), filled after it is translated.
|
|
527
549
|
*/
|
|
528
550
|
const code = typeof result.payload?.code === "string" ? result.payload.code : null;
|
|
529
551
|
if (code === PHI_FORM_GUARD_EXPIRED_CODE && descriptor.guard)
|
|
530
552
|
renewGuard();
|
|
531
553
|
const declared = code ? descriptor.errors?.[code] : undefined;
|
|
532
554
|
const message = declared
|
|
533
|
-
?
|
|
555
|
+
? resolvePhiFormErrorText(declared, result.payload, labels)
|
|
534
556
|
: typeof result.payload?.error === "string"
|
|
535
557
|
? result.payload.error
|
|
536
558
|
: "Form submission failed.";
|
|
@@ -540,7 +562,7 @@ export function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedIniti
|
|
|
540
562
|
reportSuccess(correlationId);
|
|
541
563
|
const rowIdentity = recordIdentityRef.current;
|
|
542
564
|
if (source && (rowIdentity != null || !widgetConfig?.openActionKey)) {
|
|
543
|
-
void loadRecord(rowIdentity);
|
|
565
|
+
void loadRecord(rowIdentity, correlationId);
|
|
544
566
|
}
|
|
545
567
|
}
|
|
546
568
|
catch (submitError) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PhiCmsRuntimeRenderRegistry } from "../../types/cms-plugins";
|
|
2
|
+
import type { PhiRuntimeModuleId } from "../../types/cms-module-descriptors";
|
|
3
|
+
import type { PhiAddonMediaLimits } from "../../types/server-capabilities";
|
|
4
|
+
/**
|
|
5
|
+
* The Media limits a Form's Media fields apply: those of the Add-on the Form's own Module is bound to
|
|
6
|
+
* (its server binding's `providerId`), as the capability snapshot hands them on from the Add-on's
|
|
7
|
+
* manifest (`PhiCapabilityProvider.media`). The Form's Module and not the field's: the `media-asset`
|
|
8
|
+
* field belongs to the Media library and stands in Forms of any Module, and what it may take is the
|
|
9
|
+
* question of whoever stores the Form's value. `undefined` for a Core-bound Module, an Add-on that states
|
|
10
|
+
* none, and wherever there is no snapshot.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolvePhiFormMediaLimits(registry: Pick<PhiCmsRuntimeRenderRegistry, "runtimeModuleCatalog" | "serverCapabilities">, ownerModuleId: PhiRuntimeModuleId): PhiAddonMediaLimits | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Media limits a Form's Media fields apply: those of the Add-on the Form's own Module is bound to
|
|
3
|
+
* (its server binding's `providerId`), as the capability snapshot hands them on from the Add-on's
|
|
4
|
+
* manifest (`PhiCapabilityProvider.media`). The Form's Module and not the field's: the `media-asset`
|
|
5
|
+
* field belongs to the Media library and stands in Forms of any Module, and what it may take is the
|
|
6
|
+
* question of whoever stores the Form's value. `undefined` for a Core-bound Module, an Add-on that states
|
|
7
|
+
* none, and wherever there is no snapshot.
|
|
8
|
+
*/
|
|
9
|
+
export function resolvePhiFormMediaLimits(registry, ownerModuleId) {
|
|
10
|
+
const providerId = registry.runtimeModuleCatalog.get(ownerModuleId)?.definition.serverBinding.providerId;
|
|
11
|
+
if (!providerId)
|
|
12
|
+
return undefined;
|
|
13
|
+
return registry.serverCapabilities?.providers.find((provider) => provider.providerId === providerId)?.media;
|
|
14
|
+
}
|
|
@@ -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",
|
|
@@ -2,6 +2,7 @@ import { type ComponentType, type ReactNode } from "react";
|
|
|
2
2
|
import type { PhiFormControlRule } from "../controls/phi-form-control-contract";
|
|
3
3
|
import type { PhiFormFieldDescriptor, PhiFormFieldTypeProviderDescriptor, PhiFormProviderKey, PhiFormValidationProviderDescriptor, PhiFormValidationRuleDescriptor } from "../../types/form-descriptor";
|
|
4
4
|
import type { PhiControlOption } from "../controls/phi-control-options";
|
|
5
|
+
import type { PhiAddonMediaLimits } from "../../types/server-capabilities";
|
|
5
6
|
export type PhiFormFieldProviderProps = {
|
|
6
7
|
/**
|
|
7
8
|
* The DOM id the form gives this field, unique on the page: the field's label points at it. A
|
|
@@ -35,8 +36,21 @@ export type PhiFormFieldProviderProps = {
|
|
|
35
36
|
*/
|
|
36
37
|
holdSubmit(fieldKey: string, reason: string | null): void;
|
|
37
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>>;
|
|
38
45
|
/** What the Widget was placed with, for text a field takes from its placement rather than its form. */
|
|
39
46
|
formConfig?: Readonly<Record<string, unknown>>;
|
|
47
|
+
/**
|
|
48
|
+
* The Media limits of the Add-on the Form's Module is bound to, as its manifest states them and the
|
|
49
|
+
* capability snapshot hands them on (`PhiCapabilityProvider.media`). Absent for a Form of a Core-bound
|
|
50
|
+
* Module and for an Add-on that states none. The Media fields apply them (FORMS.md); other fields have
|
|
51
|
+
* nothing to do with them.
|
|
52
|
+
*/
|
|
53
|
+
mediaLimits?: PhiAddonMediaLimits;
|
|
40
54
|
};
|
|
41
55
|
export type PhiFormFieldTypeProvider = Omit<PhiFormFieldTypeProviderDescriptor, "ownerModuleId"> & {
|
|
42
56
|
Control: ComponentType<PhiFormFieldProviderProps>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type PhiFormTextDescriptor } from "@phis/contracts/forms";
|
|
2
|
+
export type PhiFormWidgetTitleFromRecord = {
|
|
3
|
+
template: PhiFormTextDescriptor;
|
|
4
|
+
field: string;
|
|
5
|
+
};
|
|
6
|
+
/** The Form Widget output that carries the title: `change`, `string`. */
|
|
7
|
+
export declare const PHI_FORM_RECORD_TITLE_CAPABILITY = "recordTitle";
|
|
8
|
+
/**
|
|
9
|
+
* The placement's `titleFromRecord`, or null where it states none. Strict: no field, or a source text
|
|
10
|
+
* without exactly one `%1`, is refused -- the translation is not there to read, so the fallback is.
|
|
11
|
+
*/
|
|
12
|
+
export declare function readPhiFormWidgetTitleFromRecord(value: unknown): PhiFormWidgetTitleFromRecord | null;
|
|
13
|
+
/** The title a record gives, in the reader's language, or "" without a record or a text or number there. */
|
|
14
|
+
export declare function resolvePhiFormRecordTitle(titleFromRecord: PhiFormWidgetTitleFromRecord, record: Readonly<Record<string, unknown>> | null, labels?: Readonly<Record<string, string>>, formConfig?: Readonly<Record<string, unknown>>): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { resolvePhiFormText } from "@phis/contracts/forms";
|
|
2
|
+
import { isPhiRecord } from "../../helpers/is-record";
|
|
3
|
+
import { checkPhiRecordTitleTemplate, fillPhiRecordTitle } from "../../helpers/record-title";
|
|
4
|
+
/** The Form Widget output that carries the title: `change`, `string`. */
|
|
5
|
+
export const PHI_FORM_RECORD_TITLE_CAPABILITY = "recordTitle";
|
|
6
|
+
function readTemplate(value) {
|
|
7
|
+
if (isPhiRecord(value) && value.kind === "literal" && typeof value.value === "string") {
|
|
8
|
+
return { kind: "literal", value: value.value };
|
|
9
|
+
}
|
|
10
|
+
if (isPhiRecord(value) && (value.kind === "label" || value.kind === "config") &&
|
|
11
|
+
typeof value.key === "string" && value.key.trim() && typeof value.fallback === "string") {
|
|
12
|
+
return { kind: value.kind, key: value.key.trim(), fallback: value.fallback };
|
|
13
|
+
}
|
|
14
|
+
throw new Error(`Form titleFromRecord.template ${JSON.stringify(value)} is no Form text ({ kind: "label", key, fallback }).`);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The placement's `titleFromRecord`, or null where it states none. Strict: no field, or a source text
|
|
18
|
+
* without exactly one `%1`, is refused -- the translation is not there to read, so the fallback is.
|
|
19
|
+
*/
|
|
20
|
+
export function readPhiFormWidgetTitleFromRecord(value) {
|
|
21
|
+
if (value == null)
|
|
22
|
+
return null;
|
|
23
|
+
if (!isPhiRecord(value))
|
|
24
|
+
throw new Error(`Form titleFromRecord ${JSON.stringify(value)} is no { template, field }.`);
|
|
25
|
+
const field = typeof value.field === "string" ? value.field.trim() : "";
|
|
26
|
+
if (!field)
|
|
27
|
+
throw new Error("Form titleFromRecord.field must name the record field the title takes its value from.");
|
|
28
|
+
const template = readTemplate(value.template);
|
|
29
|
+
const templateError = checkPhiRecordTitleTemplate(template.kind === "literal" ? template.value : template.fallback);
|
|
30
|
+
if (templateError)
|
|
31
|
+
throw new Error(`Form titleFromRecord.template ${templateError}`);
|
|
32
|
+
return { template, field };
|
|
33
|
+
}
|
|
34
|
+
/** The title a record gives, in the reader's language, or "" without a record or a text or number there. */
|
|
35
|
+
export function resolvePhiFormRecordTitle(titleFromRecord, record, labels, formConfig) {
|
|
36
|
+
const value = record?.[titleFromRecord.field];
|
|
37
|
+
return fillPhiRecordTitle(resolvePhiFormText(titleFromRecord.template, labels, formConfig), value);
|
|
38
|
+
}
|
|
@@ -2,6 +2,7 @@ import type { PhiCmsFormWidgetCardConfig, PhiCmsFormWidgetFeedbackConfig, PhiCms
|
|
|
2
2
|
import { type PhiProviderResourceSource } from "../../types/runtime-data-provider";
|
|
3
3
|
import { type PhiFormId } from "../../types/form-id";
|
|
4
4
|
import { readPhiSignalRouteSet } from "../../types/signals";
|
|
5
|
+
import { type PhiFormWidgetTitleFromRecord } from "./form-record-title";
|
|
5
6
|
import { type PhiCmsWidgetConfigBase } from "../widgets/config/parser-primitives";
|
|
6
7
|
export type PhiCmsFormWidgetConfig = PhiCmsWidgetConfigBase & {
|
|
7
8
|
formId: PhiFormId | null;
|
|
@@ -53,6 +54,8 @@ export type PhiCmsFormWidgetConfig = PhiCmsWidgetConfigBase & {
|
|
|
53
54
|
* in the Builder starts as the Table-driven kind.
|
|
54
55
|
*/
|
|
55
56
|
openActionKey?: string;
|
|
57
|
+
/** The title its record gives the dialog, announced on `recordTitle` (`form-record-title.ts`). */
|
|
58
|
+
titleFromRecord: PhiFormWidgetTitleFromRecord | null;
|
|
56
59
|
signalRoutes: ReturnType<typeof readPhiSignalRouteSet>;
|
|
57
60
|
};
|
|
58
61
|
export declare function parsePhiFormWidgetConfig(rawConfig: Record<string, unknown>): PhiCmsFormWidgetConfig;
|
|
@@ -2,6 +2,7 @@ import { isPhiRecord } from "../../helpers/is-record";
|
|
|
2
2
|
import { readPhiProviderResourceSource, } from "../../types/runtime-data-provider";
|
|
3
3
|
import { isPhiFormId, normalizePhiFormId } from "../../types/form-id";
|
|
4
4
|
import { readPhiSignalRouteSet } from "../../types/signals";
|
|
5
|
+
import { readPhiFormWidgetTitleFromRecord } from "./form-record-title";
|
|
5
6
|
import { readRenderableBlockConfig, } from "../widgets/config/parser-primitives";
|
|
6
7
|
import { PHI_LAYOUT } from "../../theme/phi-tokens";
|
|
7
8
|
function readRecord(value) {
|
|
@@ -118,6 +119,7 @@ export function parsePhiFormWidgetConfig(rawConfig) {
|
|
|
118
119
|
openActionKey: typeof rawConfig.openActionKey === "string" && rawConfig.openActionKey.trim()
|
|
119
120
|
? rawConfig.openActionKey.trim()
|
|
120
121
|
: undefined,
|
|
122
|
+
titleFromRecord: readPhiFormWidgetTitleFromRecord(rawConfig.titleFromRecord),
|
|
121
123
|
signalRoutes: readPhiSignalRouteSet(rawConfig.signalRoutes),
|
|
122
124
|
};
|
|
123
125
|
}
|
|
@@ -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
|