@phis/ui 0.5.7 → 0.6.1
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-amount-list-control.d.ts +69 -0
- package/components/controls/phi-amount-list-control.js +15 -0
- package/components/controls/phi-button-control.js +16 -2
- package/components/controls/phi-form-control.d.ts +6 -0
- package/components/controls/phi-form-control.js +23 -7
- package/components/controls/phi-media-picker-control.d.ts +3 -1
- package/components/controls/phi-media-picker-control.js +2 -2
- package/components/forms/form-descriptor-runtime-client.d.ts +3 -1
- package/components/forms/form-descriptor-runtime-client.js +2 -2
- package/components/forms/form-field-provider-modules.d.ts +23 -0
- package/components/forms/form-field-provider-modules.js +28 -0
- package/components/forms/form-provider-contract.d.ts +7 -0
- package/components/forms/form-provider-contract.js +7 -0
- package/components/forms/lazy-form-field-control.d.ts +14 -0
- package/components/forms/lazy-form-field-control.js +35 -0
- package/components/forms/phi-form-widget.d.ts +3 -2
- package/components/forms/phi-form-widget.js +21 -3
- package/components/forms/shared-form-provider-registry.js +1 -33
- package/components/media/phi-area-upload-widget.js +6 -58
- package/components/media/phi-media-picker-binding.d.ts +16 -1
- package/components/media/phi-media-picker-binding.js +3 -2
- package/components/media/phi-media-upload.d.ts +12 -0
- package/components/media/phi-media-upload.js +22 -0
- package/components/media/phi-upload-drop-area.d.ts +22 -0
- package/components/media/phi-upload-drop-area.js +49 -0
- package/components/root/phi-root-layout.d.ts +1 -0
- package/components/root/phi-root-layout.js +1 -0
- package/components/widgets/helpers/semantic-html-translation.d.ts +4 -1
- package/components/widgets/helpers/semantic-html-translation.js +4 -2
- package/components/widgets/label-sets/admin-users.d.ts +9 -1
- package/components/widgets/label-sets/admin-users.js +14 -2
- package/components/widgets/label-sets/slot-upload.js +6 -3
- package/components/widgets/label-types/slot-upload.d.ts +7 -1
- package/components/widgets/label-types/slot-upload.js +2 -1
- package/components/widgets/shared/markdown-render.js +6 -6
- package/constants/media-library-provider-keys.d.ts +9 -0
- package/constants/media-library-provider-keys.js +9 -0
- package/constants/media.d.ts +2 -0
- package/constants/media.js +2 -0
- package/constants/runtime-module-ownership.js +2 -0
- package/controls.d.ts +4 -0
- package/controls.js +2 -0
- package/gateway/signet-route.d.ts +24 -0
- package/gateway/signet-route.js +107 -0
- package/gateway/site-proxy.js +14 -7
- package/helpers/phi-metadata.d.ts +8 -6
- package/helpers/phi-metadata.js +9 -2
- package/helpers/phi-signet-head.d.ts +26 -0
- package/helpers/phi-signet-head.js +53 -0
- package/helpers/phi-signet-paths.d.ts +16 -0
- package/helpers/phi-signet-paths.js +19 -0
- package/helpers/phi-signet.d.ts +40 -0
- package/helpers/phi-signet.js +70 -0
- package/net/phi-next-proxy.d.ts +10 -8
- package/net/phi-next-proxy.js +27 -84
- package/next/proxy-runtime.js +15 -0
- package/next/root-route.js +7 -4
- package/next/site-proxy.js +21 -0
- package/package.json +3 -3
- package/plugins/runtime-modules/area-definitions.d.ts +24 -3
- package/plugins/runtime-modules/area-definitions.js +11 -3
- package/plugins/runtime-modules/asset/definition.d.ts +44 -2
- package/plugins/runtime-modules/asset/definition.js +5 -2
- package/plugins/runtime-modules/asset/form-providers.d.ts +63 -0
- package/plugins/runtime-modules/asset/form-providers.js +54 -0
- package/plugins/runtime-modules/asset/form-ui-provider.js +13 -3
- package/plugins/runtime-modules/asset/media-asset-field.d.ts +20 -0
- package/plugins/runtime-modules/asset/media-asset-field.js +33 -0
- package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +21 -0
- package/plugins/runtime-modules/asset/media-asset-form-control.js +74 -0
- package/plugins/runtime-modules/core/widgets/html/server.js +1 -1
- package/plugins/runtime-modules/core/widgets/slot-upload/client.js +28 -23
- package/plugins/runtime-modules/core/widgets/slot-upload/slot.d.ts +19 -0
- package/plugins/runtime-modules/core/widgets/slot-upload/slot.js +16 -0
- package/plugins/runtime-modules/public/presets.d.ts +12 -0
- package/plugins/runtime-modules/public/presets.js +10 -0
- package/plugins/runtime-modules/public/server.js +1 -1
- package/plugins/runtime-modules/public/trees/phi-default-pub-privacy-page-tree.d.ts +4 -0
- package/plugins/runtime-modules/public/trees/phi-default-pub-privacy-page-tree.js +66 -0
- package/plugins/runtime-modules/public-base-page-references.d.ts +2 -1
- package/plugins/runtime-modules/public-base-page-references.js +2 -1
- package/plugins/runtime-modules/resolver.js +38 -4
- package/plugins/runtime-modules/theme/controller/runtime.js +7 -2
- package/plugins/runtime-modules/theme/materialize-images.d.ts +16 -0
- package/plugins/runtime-modules/theme/materialize-images.js +37 -0
- package/plugins/runtime-modules/user-management/addon-roles.d.ts +35 -0
- package/plugins/runtime-modules/user-management/addon-roles.js +76 -0
- package/plugins/runtime-modules/user-management/cards.js +1 -1
- package/plugins/runtime-modules/user-management/client-data-providers.js +6 -0
- package/plugins/runtime-modules/user-management/data-providers.d.ts +11 -2
- package/plugins/runtime-modules/user-management/data-providers.js +12 -1
- package/plugins/runtime-modules/user-management/definition.d.ts +11 -2
- package/plugins/runtime-modules/user-management/ids.d.ts +1 -0
- package/plugins/runtime-modules/user-management/ids.js +1 -0
- package/plugins/runtime-modules/user-management/services/options.d.ts +8 -0
- package/plugins/runtime-modules/user-management/services/options.js +25 -0
- package/plugins/runtime-modules/user-management/services/table.js +9 -1
- package/plugins/runtime-modules/user-management/trees/phi-default-admin-users-page-tree.js +20 -2
- package/server-helpers/cms-widget-texts.js +1 -1
- package/server-helpers/search-index.js +22 -13
- package/server-helpers/search-text.d.ts +3 -2
- package/server-helpers/search-text.js +6 -5
- package/server-helpers/translate.d.ts +13 -2
- package/server-helpers/translate.js +10 -6
- package/styles/amount-list.css +142 -0
- package/styles/controls.css +156 -7
- package/styles/gradients.css +21 -20
- package/theme/phi-theme-blocks.d.ts +7 -6
- package/theme/phi-theme-composition.d.ts +19 -1
- package/theme/phi-theme-composition.js +15 -0
- package/theme/phi-theme-signet.d.ts +31 -0
- package/theme/phi-theme-signet.js +53 -0
- package/theme/phi-tokens.d.ts +1 -1
- package/theme/phi-tokens.js +5 -1
- package/types/cms-plugins.d.ts +10 -1
- package/types/site-theme.d.ts +29 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { PhiControlSize } from "../../types/control";
|
|
3
|
+
/**
|
|
4
|
+
* Lines and sums whose amounts stand in one column: a cart, a checkout, an order, a subscription's
|
|
5
|
+
* sign-up, a receipt.
|
|
6
|
+
*
|
|
7
|
+
* **It knows nothing about money.** An amount is text somebody else has already formatted, in whatever
|
|
8
|
+
* currency and locale the surface speaks. What this Control owns is the one thing a stack of rows cannot
|
|
9
|
+
* give it: every amount -- the items' and the totals' -- is in the same grid column, so their right edges
|
|
10
|
+
* are the same line and, with tabular digits, the figures stand digit under digit. Separate flex rows
|
|
11
|
+
* cannot do that; each one sizes its amount to itself.
|
|
12
|
+
*
|
|
13
|
+
* **One grid, rows through `subgrid`.** The list is a four-column grid -- media, text, controls, amount --
|
|
14
|
+
* and an item row and a total row are subgrids of it, so the amount column is sized by the widest amount
|
|
15
|
+
* of the whole list. `display: contents` would also share the columns, but it drops the row's box: no
|
|
16
|
+
* divider on a total, no role on a flattened element in some browsers. Rows are boxes, so `subgrid`.
|
|
17
|
+
*
|
|
18
|
+
* **Narrow is decided by the list's own width**, not the viewport's (`@container`, below 30rem): the item
|
|
19
|
+
* becomes two lines -- media and text, then controls and amount -- and the amount stays in the same
|
|
20
|
+
* column. Totals keep label left and amount right at every width. The container query needs
|
|
21
|
+
* `container-type: inline-size`, so the list takes the width its parent gives it (`width: 100%`) and has
|
|
22
|
+
* none of its own: in a shrink-to-fit parent -- an `inline-flex` or `fit-content` box -- it collapses to 0.
|
|
23
|
+
*
|
|
24
|
+
* **A list, with the sums as a description list.** The items are a `ul`: each is one thing with a name,
|
|
25
|
+
* free controls and an amount, and a table would need column headers that nothing here has (the
|
|
26
|
+
* controls cell has no name, the text cell is a title and a line). The sums are label/amount pairs, which
|
|
27
|
+
* is what `dl` says. The `ul` carries `role="list"` because list-style resets drop the role in Safari.
|
|
28
|
+
*
|
|
29
|
+
* **It is display, with no data source.** It sorts nothing, pages nothing and edits nothing; the
|
|
30
|
+
* quantity field or the remove button is whatever the surface passes as `controls`. It is not the Table
|
|
31
|
+
* Widget ([TABLES.md](../../TABLES.md)). It renders on the server: no state, no Ant Design, no theme hook;
|
|
32
|
+
* the rules are `styles/amount-list.css`.
|
|
33
|
+
*/
|
|
34
|
+
export type PhiAmountListItem = {
|
|
35
|
+
key: string;
|
|
36
|
+
/** The name of the line. It wraps; it is never cut off. */
|
|
37
|
+
title: ReactNode;
|
|
38
|
+
/** A second, quieter line under the title: "2 x 12,00 CHF", "per month". */
|
|
39
|
+
description?: ReactNode;
|
|
40
|
+
/** A small picture or icon before the title. */
|
|
41
|
+
media?: ReactNode;
|
|
42
|
+
/** Whatever the line can be operated with: a quantity field, a remove button. */
|
|
43
|
+
controls?: ReactNode;
|
|
44
|
+
/** The amount, already formatted. */
|
|
45
|
+
amount: ReactNode;
|
|
46
|
+
/** Quiet, under the amount: "incl. VAT". */
|
|
47
|
+
amountNote?: ReactNode;
|
|
48
|
+
};
|
|
49
|
+
export type PhiAmountListTotal = {
|
|
50
|
+
key: string;
|
|
51
|
+
label: ReactNode;
|
|
52
|
+
/** The amount, already formatted. */
|
|
53
|
+
amount: ReactNode;
|
|
54
|
+
/** Quiet, under the label. */
|
|
55
|
+
note?: ReactNode;
|
|
56
|
+
/** `strong` is for the line that is the answer: the grand total. */
|
|
57
|
+
emphasis?: "normal" | "strong";
|
|
58
|
+
/** A rule above this line, in the Theme's line colour. */
|
|
59
|
+
divided?: boolean;
|
|
60
|
+
};
|
|
61
|
+
export type PhiAmountListControlProps = {
|
|
62
|
+
items: readonly PhiAmountListItem[];
|
|
63
|
+
totals?: readonly PhiAmountListTotal[];
|
|
64
|
+
size?: PhiControlSize;
|
|
65
|
+
/** Stands in place of the list when there are no items and no totals. */
|
|
66
|
+
emptyText?: ReactNode;
|
|
67
|
+
ariaLabel?: string;
|
|
68
|
+
};
|
|
69
|
+
export declare function PhiAmountListControl({ items, totals, size, emptyText, ariaLabel, }: PhiAmountListControlProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
export function PhiAmountListControl({ items, totals, size = "medium", emptyText, ariaLabel, }) {
|
|
3
|
+
const hasTotals = totals != null && totals.length > 0;
|
|
4
|
+
if (items.length === 0 && !hasTotals) {
|
|
5
|
+
return emptyText != null ? _jsx("div", { className: "phi-amount-list__empty", children: emptyText }) : null;
|
|
6
|
+
}
|
|
7
|
+
return (_jsxs("div", { className: `phi-amount-list phi-amount-list--${size}`, role: ariaLabel ? "group" : undefined, "aria-label": ariaLabel, children: [items.length > 0 ? (_jsx("ul", { className: "phi-amount-list__items", role: "list", children: items.map((item) => (_jsxs("li", { className: "phi-amount-list__item", role: "listitem", children: [item.media != null ? _jsx("div", { className: "phi-amount-list__media", children: item.media }) : null, _jsxs("div", { className: "phi-amount-list__text", children: [_jsx("div", { className: "phi-amount-list__title", children: item.title }), item.description != null ? (_jsx("div", { className: "phi-amount-list__description", children: item.description })) : null] }), item.controls != null ? _jsx("div", { className: "phi-amount-list__controls", children: item.controls }) : null, _jsxs("div", { className: "phi-amount-list__amount", children: [_jsx("div", { children: item.amount }), item.amountNote != null ? _jsx("div", { className: "phi-amount-list__note", children: item.amountNote }) : null] })] }, item.key))) })) : null, hasTotals ? (_jsx("dl", { className: "phi-amount-list__totals", children: totals.map((total) => {
|
|
8
|
+
const className = [
|
|
9
|
+
"phi-amount-list__total",
|
|
10
|
+
total.emphasis === "strong" ? "phi-amount-list__total--strong" : null,
|
|
11
|
+
total.divided ? "phi-amount-list__total--divided" : null,
|
|
12
|
+
].filter(Boolean).join(" ");
|
|
13
|
+
return (_jsxs("div", { className: className, children: [_jsxs("dt", { className: "phi-amount-list__label", children: [_jsx("span", { children: total.label }), total.note != null ? _jsx("span", { className: "phi-amount-list__note", children: total.note }) : null] }), _jsx("dd", { className: "phi-amount-list__amount", children: total.amount })] }, total.key));
|
|
14
|
+
}) })) : null] }));
|
|
15
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { lazy, Suspense } from "react";
|
|
4
|
-
import { Button } from "antd";
|
|
4
|
+
import { Button, theme } from "antd";
|
|
5
5
|
import { PHI_THEME_GRADIENT_CSS_VARS, } from "../../theme/phi-theme-gradients";
|
|
6
6
|
import { PhiLink } from "../navigation/phi-link";
|
|
7
7
|
import { PhiHoverText } from "./phi-hover-text";
|
|
@@ -12,7 +12,10 @@ import { PhiHoverText } from "./phi-hover-text";
|
|
|
12
12
|
*/
|
|
13
13
|
const PhiLazyBadge = lazy(() => import("antd/es/badge"));
|
|
14
14
|
const PHI_GLASS_BUTTON_FILTER = "blur(12px) saturate(140%)";
|
|
15
|
+
/* How far the badge centre sits outside the icon's top-right corner, in px. */
|
|
16
|
+
const PHI_ICON_ONLY_BADGE_OUTSET = 2;
|
|
15
17
|
export function PhiButtonControl({ label, ariaLabel, ariaPressed, ariaExpanded, href, newTab, external, tooltip, icon, type = "default", shape, danger, ghost, gradient, glass, disabled, readOnly, loading, htmlType, block, size, style, badge, className, ref, onClick, }) {
|
|
18
|
+
const { token } = theme.useToken();
|
|
16
19
|
const visibleTooltip = typeof label === "string" && typeof tooltip === "string" && label === tooltip
|
|
17
20
|
? null
|
|
18
21
|
: tooltip;
|
|
@@ -50,11 +53,22 @@ export function PhiButtonControl({ label, ariaLabel, ariaPressed, ariaExpanded,
|
|
|
50
53
|
* The colour is the Button's. A link states one, and here the Button beneath it already has.
|
|
51
54
|
*/
|
|
52
55
|
const linked = href && !disabled && !readOnly ? (_jsx(PhiLink, { href: href, ...(external === undefined ? {} : { external }), newTab: newTab, prefetch: false, style: { display: "inline-flex", color: "inherit" }, children: button })) : button;
|
|
56
|
+
/*
|
|
57
|
+
* Ant Design centres the badge on the corner of what it wraps. Around a button with a label that is the
|
|
58
|
+
* button's corner, but around an icon-only button the box is far larger than the icon and the count
|
|
59
|
+
* floats beside it. So the count is moved in by the padding between box and icon, leaving it a little
|
|
60
|
+
* outside the icon's corner. Box and icon follow the Button's own size tokens: the height is
|
|
61
|
+
* `controlHeight*`, the icon inherits the content font size (`fontSize`, `fontSizeLG` for large).
|
|
62
|
+
*/
|
|
63
|
+
const iconOnly = icon != null && (label == null || label === false || label === "");
|
|
64
|
+
const iconOnlyHeight = size === "small" ? token.controlHeightSM : size === "large" ? token.controlHeightLG : token.controlHeight;
|
|
65
|
+
const iconOnlySize = size === "large" ? token.fontSizeLG : token.fontSize;
|
|
66
|
+
const iconOnlyInset = Math.max(0, Math.round((iconOnlyHeight - iconOnlySize) / 2 - PHI_ICON_ONLY_BADGE_OUTSET));
|
|
53
67
|
/*
|
|
54
68
|
* Rendered on the Server it is complete, and hydration waits for the chunk. Mounted in the browser before
|
|
55
69
|
* the chunk is there, the Button stands without its count until it arrives.
|
|
56
70
|
*/
|
|
57
|
-
const badged = badge?.enabled ? (_jsx(Suspense, { fallback: linked, children: _jsx(PhiLazyBadge, { color: badge.color, count: badge.value ?? 0, overflowCount: badge.overflowCount, showZero: badge.showZero, size: "small", children: linked }) })) : linked;
|
|
71
|
+
const badged = badge?.enabled ? (_jsx(Suspense, { fallback: linked, children: _jsx(PhiLazyBadge, { color: badge.color, count: badge.value ?? 0, overflowCount: badge.overflowCount, showZero: badge.showZero, size: "small", offset: iconOnly && iconOnlyInset > 0 ? [-iconOnlyInset, iconOnlyInset] : undefined, children: linked }) })) : linked;
|
|
58
72
|
if (!visibleTooltip)
|
|
59
73
|
return badged;
|
|
60
74
|
/*
|
|
@@ -16,6 +16,12 @@ export type PhiFormControlProps = {
|
|
|
16
16
|
disabled?: boolean;
|
|
17
17
|
readOnly?: boolean;
|
|
18
18
|
conditionControllerStates?: Readonly<Record<string, Record<string, unknown>>>;
|
|
19
|
+
/**
|
|
20
|
+
* The fields whose field type belongs to a Module that is not active in this Area. Each says so in the
|
|
21
|
+
* place of its control instead of failing as a missing Provider, and its value is neither validated nor
|
|
22
|
+
* dropped: what the form holds for it goes out with the submit unchanged.
|
|
23
|
+
*/
|
|
24
|
+
unavailableFieldKeys?: readonly string[];
|
|
19
25
|
form?: PhiFormControlFormInstance;
|
|
20
26
|
onValuesChange?: (changedValues: Record<string, unknown>, allValues: Record<string, unknown>) => void;
|
|
21
27
|
onSubmit: (values: Record<string, unknown>) => void | Promise<void>;
|
|
@@ -7,7 +7,7 @@ import { collectPhiRuntimeValueConditions, evaluatePhiRuntimeConditionExpression
|
|
|
7
7
|
import { extendPhiFormProviderRegistry, usePhiFormProviderRegistry, } from "../forms/form-provider-registry";
|
|
8
8
|
import { PhiAlertControl } from "./phi-alert-control";
|
|
9
9
|
import { PhiDescriptionHint } from "./phi-description-tooltip-icon";
|
|
10
|
-
import { PHI_FORM_FIELD_PROVIDER_KEYS, PHI_FORM_VALIDATION_PROVIDER_KEYS, } from "../forms/form-provider-contract";
|
|
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
12
|
import { PHI_SHARED_FORM_PROVIDER_REGISTRY } from "../forms/shared-form-provider-registry";
|
|
13
13
|
import { resolvePhiControlOptionsDependencies, usePhiControlOptionsProvider, } from "./phi-options-provider";
|
|
@@ -136,11 +136,12 @@ function PhiResolvedFormFieldControl({ id, provider, field, label, description,
|
|
|
136
136
|
// One empty object for every form without controllers, so the fields drawn are not recomputed on
|
|
137
137
|
// every render for a new `{}`.
|
|
138
138
|
const PHI_FORM_NO_CONTROLLER_STATES = Object.freeze({});
|
|
139
|
-
export const PhiFormControl = forwardRef(function PhiFormControl({ descriptor, registry, labels, formConfig, initialValues, submitOnEnter, disabled = false, readOnly = false, conditionControllerStates = PHI_FORM_NO_CONTROLLER_STATES, form: providedForm, onValuesChange, onSubmit, onSubmittingChange, onValidationFailed, onFormReady, onStateChange, onBlurCapture, }, ref) {
|
|
139
|
+
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) {
|
|
140
140
|
const contributedRegistry = usePhiFormProviderRegistry();
|
|
141
141
|
const activeRegistry = useMemo(() => registry ?? (contributedRegistry
|
|
142
142
|
? extendPhiFormProviderRegistry(PHI_SHARED_FORM_PROVIDER_REGISTRY, contributedRegistry)
|
|
143
143
|
: PHI_SHARED_FORM_PROVIDER_REGISTRY), [contributedRegistry, registry]);
|
|
144
|
+
const unavailableKeys = useMemo(() => new Set(unavailableFieldKeys ?? []), [unavailableFieldKeys]);
|
|
144
145
|
const [internalForm] = Form.useForm();
|
|
145
146
|
const form = providedForm ?? internalForm;
|
|
146
147
|
/*
|
|
@@ -244,7 +245,16 @@ export const PhiFormControl = forwardRef(function PhiFormControl({ descriptor, r
|
|
|
244
245
|
setSubmitting(true);
|
|
245
246
|
onSubmittingChange?.(true);
|
|
246
247
|
try {
|
|
247
|
-
|
|
248
|
+
/*
|
|
249
|
+
* A field that is not drawn is not part of what the form validated, and so not part of `values`.
|
|
250
|
+
* What it holds is what the Server knows about it, and a save that leaves it out would say it was
|
|
251
|
+
* emptied.
|
|
252
|
+
*/
|
|
253
|
+
const kept = Object.fromEntries([...unavailableKeys].flatMap((key) => {
|
|
254
|
+
const held = form.getFieldValue(key);
|
|
255
|
+
return held === undefined ? [] : [[key, held]];
|
|
256
|
+
}));
|
|
257
|
+
await onSubmit({ ...kept, ...values });
|
|
248
258
|
}
|
|
249
259
|
finally {
|
|
250
260
|
setSubmitting(false);
|
|
@@ -328,14 +338,16 @@ export const PhiFormControl = forwardRef(function PhiFormControl({ descriptor, r
|
|
|
328
338
|
* away as everything inside it.
|
|
329
339
|
*/
|
|
330
340
|
const lastInFlowFieldKey = useMemo(() => {
|
|
331
|
-
const inFlow = renderedFields.filter((field) =>
|
|
341
|
+
const inFlow = renderedFields.filter((field) => unavailableKeys.has(field.key) ||
|
|
342
|
+
activeRegistry.fieldTypesByKey.get(field.fieldProviderKey)?.presentation === "control");
|
|
332
343
|
return inFlow.length === 0 ? null : inFlow[inFlow.length - 1].key;
|
|
333
|
-
}, [activeRegistry, renderedFields]);
|
|
344
|
+
}, [activeRegistry, renderedFields, unavailableKeys]);
|
|
334
345
|
const placementByMode = useMemo(() => {
|
|
335
346
|
const entries = renderedFields.map((field) => ({
|
|
336
347
|
key: field.key,
|
|
337
348
|
placement: field.placement,
|
|
338
|
-
inFlow:
|
|
349
|
+
inFlow: unavailableKeys.has(field.key) ||
|
|
350
|
+
activeRegistry.fieldTypesByKey.get(field.fieldProviderKey)?.presentation === "control",
|
|
339
351
|
hasLabel: field.label != null && field.controlLabel == null,
|
|
340
352
|
}));
|
|
341
353
|
return {
|
|
@@ -343,7 +355,7 @@ export const PhiFormControl = forwardRef(function PhiFormControl({ descriptor, r
|
|
|
343
355
|
medium: resolvePhiFormGridPlacement(layout, entries, "medium"),
|
|
344
356
|
wide: resolvePhiFormGridPlacement(layout, entries, "wide"),
|
|
345
357
|
};
|
|
346
|
-
}, [activeRegistry, layout, renderedFields]);
|
|
358
|
+
}, [activeRegistry, layout, renderedFields, unavailableKeys]);
|
|
347
359
|
return (_jsx("div", { style: { width: "100%", minWidth: 0 }, children: _jsx(Form, { className: "phi-form-descriptor", name: formDomName, form: form, layout: "vertical", colon: false, initialValues: resolvedInitialValues, disabled: disabled,
|
|
348
360
|
/*
|
|
349
361
|
* The form is the grid, and its tracks are the twenty-four every range is written against. Labels
|
|
@@ -428,6 +440,10 @@ export const PhiFormControl = forwardRef(function PhiFormControl({ descriptor, r
|
|
|
428
440
|
: "0px"],
|
|
429
441
|
];
|
|
430
442
|
}));
|
|
443
|
+
if (!provider && unavailableKeys.has(field.key)) {
|
|
444
|
+
const unavailableLabel = field.label ? resolvePhiFormText(field.label, labels, formConfig) : undefined;
|
|
445
|
+
return (_jsx("div", { className: "phi-form-cell phi-form-cell--control", style: cellProperties("control"), children: _jsx(PhiAlertControl, { level: "info", title: labels?.[PHI_FORM_FIELD_UNAVAILABLE_LABEL_KEY]?.trim() || PHI_FORM_FIELD_UNAVAILABLE_DEFAULT_LABEL, description: unavailableLabel }) }, field.key));
|
|
446
|
+
}
|
|
431
447
|
if (!provider) {
|
|
432
448
|
return (_jsx("div", { className: "phi-form-cell phi-form-cell--control", style: cellProperties("control"), children: _jsx(PhiAlertControl, { level: "error", showIcon: true, title: `Form field is not renderable: ${field.key}`, description: `Missing field provider: ${field.fieldProviderKey}` }) }, field.key));
|
|
433
449
|
}
|
|
@@ -27,6 +27,8 @@ export type PhiMediaPickerControlProps = PhiPickerTransactionCallbacks<number |
|
|
|
27
27
|
showFolderFilter?: boolean;
|
|
28
28
|
showPagination?: boolean;
|
|
29
29
|
trigger?: ReactNode;
|
|
30
|
+
/** Which Assets may be chosen. The others are listed and greyed out; absent, every Asset may be. */
|
|
31
|
+
isAssetSelectable?: (asset: PhiMediaAssetTile) => boolean;
|
|
30
32
|
labels?: Partial<{
|
|
31
33
|
trigger: string;
|
|
32
34
|
title: string;
|
|
@@ -47,4 +49,4 @@ export type PhiMediaPickerControlProps = PhiPickerTransactionCallbacks<number |
|
|
|
47
49
|
onMinColumnWidthChange?: (minColumnWidth: number) => void;
|
|
48
50
|
onReload?: () => void;
|
|
49
51
|
};
|
|
50
|
-
export declare function PhiMediaPickerControl({ open, value, assets, spaces, spaceValue, folders, folderValue, query, page, pageSize, total, minColumnWidth, loading, disabled, readOnly, placement, showSearchBar, showFolderFilter, showPagination, trigger, labels, getPopupContainer, popupRootClassName, onOpenChange, onQueryChange, onSpaceChange, onFolderChange, onPageChange, onMinColumnWidthChange, onReload, onChange, onCommit, onDiscard, }: PhiMediaPickerControlProps): import("react").JSX.Element;
|
|
52
|
+
export declare function PhiMediaPickerControl({ open, value, assets, spaces, spaceValue, folders, folderValue, query, page, pageSize, total, minColumnWidth, loading, disabled, readOnly, placement, showSearchBar, showFolderFilter, showPagination, trigger, isAssetSelectable, labels, getPopupContainer, popupRootClassName, onOpenChange, onQueryChange, onSpaceChange, onFolderChange, onPageChange, onMinColumnWidthChange, onReload, onChange, onCommit, onDiscard, }: PhiMediaPickerControlProps): import("react").JSX.Element;
|
|
@@ -15,7 +15,7 @@ import { PhiSliderControl } from "./phi-slider-control";
|
|
|
15
15
|
import { PhiTextControl } from "./phi-text-control";
|
|
16
16
|
import { usePhiImmediatePicker } from "./use-phi-immediate-picker";
|
|
17
17
|
import { PhiIcon } from "../shell/phi-icon";
|
|
18
|
-
export function PhiMediaPickerControl({ open, value = null, assets, spaces = [], spaceValue = null, folders = [], folderValue = "/", query = "", page = 1, pageSize = 20, total = assets.length, minColumnWidth = PHI_MEDIA_PICKER_DEFAULT_COLUMN_WIDTH, loading, disabled, readOnly, placement = "left", showSearchBar = true, showFolderFilter = true, showPagination = true, trigger, labels, getPopupContainer, popupRootClassName, onOpenChange, onQueryChange, onSpaceChange, onFolderChange, onPageChange, onMinColumnWidthChange, onReload, onChange, onCommit, onDiscard, }) {
|
|
18
|
+
export function PhiMediaPickerControl({ open, value = null, assets, spaces = [], spaceValue = null, folders = [], folderValue = "/", query = "", page = 1, pageSize = 20, total = assets.length, minColumnWidth = PHI_MEDIA_PICKER_DEFAULT_COLUMN_WIDTH, loading, disabled, readOnly, placement = "left", showSearchBar = true, showFolderFilter = true, showPagination = true, trigger, isAssetSelectable, labels, getPopupContainer, popupRootClassName, onOpenChange, onQueryChange, onSpaceChange, onFolderChange, onPageChange, onMinColumnWidthChange, onReload, onChange, onCommit, onDiscard, }) {
|
|
19
19
|
const { token } = usePhiConfig();
|
|
20
20
|
const locked = disabled || readOnly;
|
|
21
21
|
const resolvedMinColumnWidth = normalizePhiMediaPickerMinColumnWidth(minColumnWidth);
|
|
@@ -29,7 +29,7 @@ export function PhiMediaPickerControl({ open, value = null, assets, spaces = [],
|
|
|
29
29
|
onOpenChange,
|
|
30
30
|
});
|
|
31
31
|
const selected = assets.find((asset) => asset.id === picker.value) ?? null;
|
|
32
|
-
const tileItems = assets.map((asset) => (_jsx(PhiMediaAssetTileControl, { asset: asset, minColumnWidth: resolvedMinColumnWidth, selected: asset.id === picker.value, size: "small", disabled: locked, showTypeLabel: false, showDeleteAction: false, showDimensions: false, showIdLabel: false, onSelect: (nextAsset) => {
|
|
32
|
+
const tileItems = assets.map((asset) => (_jsx(PhiMediaAssetTileControl, { asset: asset, minColumnWidth: resolvedMinColumnWidth, selected: asset.id === picker.value, size: "small", disabled: locked || (isAssetSelectable != null && !isAssetSelectable(asset)), showTypeLabel: false, showDeleteAction: false, showDimensions: false, showIdLabel: false, onSelect: (nextAsset) => {
|
|
33
33
|
picker.changeValue(nextAsset.id);
|
|
34
34
|
picker.closePicker("commit");
|
|
35
35
|
} }, asset.id)));
|
|
@@ -9,5 +9,7 @@ export type PhiFormDescriptorRuntimeClientProps = {
|
|
|
9
9
|
formId: string;
|
|
10
10
|
formControllerAddress: PhiSignalAddress;
|
|
11
11
|
widgetConfig?: PhiCmsFormWidgetConfig;
|
|
12
|
+
/** The fields whose field type belongs to a Module that is not active in this Area. */
|
|
13
|
+
unavailableFieldKeys?: readonly string[];
|
|
12
14
|
};
|
|
13
|
-
export declare function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedInitialValues, formId, formControllerAddress, widgetConfig, }: PhiFormDescriptorRuntimeClientProps): import("react").JSX.Element;
|
|
15
|
+
export declare function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedInitialValues, formId, formControllerAddress, widgetConfig, unavailableFieldKeys, }: PhiFormDescriptorRuntimeClientProps): import("react").JSX.Element;
|
|
@@ -27,7 +27,7 @@ import { usePhiInDialogBody } from "../overlays/phi-dialog-body-context";
|
|
|
27
27
|
/** How long before its window closes a token is renewed rather than sent: the request takes time too. */
|
|
28
28
|
const PHI_FORM_GUARD_EXPIRY_MARGIN_MS = 60_000;
|
|
29
29
|
const EMPTY_FORM_VALUES = {};
|
|
30
|
-
export function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedInitialValues, formId, formControllerAddress, widgetConfig, }) {
|
|
30
|
+
export function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedInitialValues, formId, formControllerAddress, widgetConfig, unavailableFieldKeys, }) {
|
|
31
31
|
const formClient = usePhiRuntimeFormClient({ controllerAddress: formControllerAddress });
|
|
32
32
|
const formRef = useRef(null);
|
|
33
33
|
const submitCorrelationRef = useRef(null);
|
|
@@ -467,7 +467,7 @@ export function PhiFormDescriptorRuntimeClient({ descriptor, labels, loadedIniti
|
|
|
467
467
|
activeForm.setFieldsValue(pendingValuesRef.current);
|
|
468
468
|
pendingValuesRef.current = null;
|
|
469
469
|
}
|
|
470
|
-
}, conditionControllerStates: conditionControllerStates, onValuesChange: (changed, all) => {
|
|
470
|
+
}, conditionControllerStates: conditionControllerStates, unavailableFieldKeys: unavailableFieldKeys, onValuesChange: (changed, all) => {
|
|
471
471
|
// A value moved, so whatever validation refused before is no longer what is being asked.
|
|
472
472
|
rejectedRef.current = false;
|
|
473
473
|
runtimeBinding.onValuesChange(changed, all);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { PhiFormFieldDescriptor, PhiFormProviderKey } from "../../types/form-descriptor";
|
|
2
|
+
import type { PhiRuntimeModuleId } from "../../types/cms-module-descriptors";
|
|
3
|
+
/**
|
|
4
|
+
* Which Modules a Form's field types belong to, other than the Form's own.
|
|
5
|
+
*
|
|
6
|
+
* A field type is a Module's to offer, and a Form of any Module may use it. For each field whose type an
|
|
7
|
+
* installed Module owns:
|
|
8
|
+
* - the owner is the Form's own Module: nothing to add, its UI provider is mounted anyway;
|
|
9
|
+
* - the owner is active in the Area and brings a UI provider: that provider is mounted for this Form;
|
|
10
|
+
* - the owner is not active in the Area: the field is marked unavailable, and the Form says so in its place.
|
|
11
|
+
*
|
|
12
|
+
* A key no installed Module owns (the shared registry's) is not this question's business.
|
|
13
|
+
*/
|
|
14
|
+
export declare function readPhiFormFieldProviderModules({ fields, formOwnerModuleId, ownerModuleIdByFieldTypeKey, activeModuleIds, uiProviderModuleIds, }: {
|
|
15
|
+
fields: readonly Pick<PhiFormFieldDescriptor, "key" | "fieldProviderKey">[];
|
|
16
|
+
formOwnerModuleId: PhiRuntimeModuleId;
|
|
17
|
+
ownerModuleIdByFieldTypeKey: ReadonlyMap<PhiFormProviderKey, PhiRuntimeModuleId>;
|
|
18
|
+
activeModuleIds: ReadonlySet<PhiRuntimeModuleId>;
|
|
19
|
+
uiProviderModuleIds: ReadonlySet<PhiRuntimeModuleId>;
|
|
20
|
+
}): {
|
|
21
|
+
providerModuleIds: `${string}/${string}`[];
|
|
22
|
+
unavailableFieldKeys: string[];
|
|
23
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which Modules a Form's field types belong to, other than the Form's own.
|
|
3
|
+
*
|
|
4
|
+
* A field type is a Module's to offer, and a Form of any Module may use it. For each field whose type an
|
|
5
|
+
* installed Module owns:
|
|
6
|
+
* - the owner is the Form's own Module: nothing to add, its UI provider is mounted anyway;
|
|
7
|
+
* - the owner is active in the Area and brings a UI provider: that provider is mounted for this Form;
|
|
8
|
+
* - the owner is not active in the Area: the field is marked unavailable, and the Form says so in its place.
|
|
9
|
+
*
|
|
10
|
+
* A key no installed Module owns (the shared registry's) is not this question's business.
|
|
11
|
+
*/
|
|
12
|
+
export function readPhiFormFieldProviderModules({ fields, formOwnerModuleId, ownerModuleIdByFieldTypeKey, activeModuleIds, uiProviderModuleIds, }) {
|
|
13
|
+
const providerModuleIds = new Set();
|
|
14
|
+
const unavailableFieldKeys = [];
|
|
15
|
+
for (const field of fields) {
|
|
16
|
+
const owner = ownerModuleIdByFieldTypeKey.get(field.fieldProviderKey);
|
|
17
|
+
if (!owner || owner === formOwnerModuleId) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (!activeModuleIds.has(owner)) {
|
|
21
|
+
unavailableFieldKeys.push(field.key);
|
|
22
|
+
}
|
|
23
|
+
else if (uiProviderModuleIds.has(owner)) {
|
|
24
|
+
providerModuleIds.add(owner);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return { providerModuleIds: [...providerModuleIds], unavailableFieldKeys };
|
|
28
|
+
}
|
|
@@ -83,6 +83,13 @@ export declare const PHI_FORM_LINK_TARGET_LABEL_KEYS: {
|
|
|
83
83
|
/** Where the Pages would be, when the Site could not list them. */
|
|
84
84
|
readonly pagesUnavailable: "linkTargetPagesUnavailable";
|
|
85
85
|
};
|
|
86
|
+
/**
|
|
87
|
+
* What a field says in the place of its control when the Module that owns its field type is not active in
|
|
88
|
+
* this Area (`PhiFormControl`'s `unavailableFieldKeys`), read from the Form's Label Set and falling back to
|
|
89
|
+
* English. The value the field holds is kept and sent unchanged.
|
|
90
|
+
*/
|
|
91
|
+
export declare const PHI_FORM_FIELD_UNAVAILABLE_LABEL_KEY = "fieldUnavailable";
|
|
92
|
+
export declare const PHI_FORM_FIELD_UNAVAILABLE_DEFAULT_LABEL = "This field is not available in this area.";
|
|
86
93
|
export declare const PHI_FORM_UPLOAD_LABEL_KEYS: {
|
|
87
94
|
readonly trigger: "uploadTrigger";
|
|
88
95
|
/** Beneath the trigger in an upload area (`config.presentation: "area"`): that a drop works too. */
|
|
@@ -91,6 +91,13 @@ export const PHI_FORM_LINK_TARGET_LABEL_KEYS = {
|
|
|
91
91
|
/** Where the Pages would be, when the Site could not list them. */
|
|
92
92
|
pagesUnavailable: "linkTargetPagesUnavailable",
|
|
93
93
|
};
|
|
94
|
+
/**
|
|
95
|
+
* What a field says in the place of its control when the Module that owns its field type is not active in
|
|
96
|
+
* this Area (`PhiFormControl`'s `unavailableFieldKeys`), read from the Form's Label Set and falling back to
|
|
97
|
+
* English. The value the field holds is kept and sent unchanged.
|
|
98
|
+
*/
|
|
99
|
+
export const PHI_FORM_FIELD_UNAVAILABLE_LABEL_KEY = "fieldUnavailable";
|
|
100
|
+
export const PHI_FORM_FIELD_UNAVAILABLE_DEFAULT_LABEL = "This field is not available in this area.";
|
|
94
101
|
export const PHI_FORM_UPLOAD_LABEL_KEYS = {
|
|
95
102
|
trigger: "uploadTrigger",
|
|
96
103
|
/** Beneath the trigger in an upload area (`config.presentation: "area"`): that a drop works too. */
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ComponentType } from "react";
|
|
2
|
+
import type { PhiFormFieldProviderProps } from "./form-provider-registry";
|
|
3
|
+
/**
|
|
4
|
+
* A field Control whose code loads when a field of its kind is first rendered.
|
|
5
|
+
*
|
|
6
|
+
* Every kind in the shared registry that has code of its own to ship: the choice and number fields, the slider and the
|
|
7
|
+
* cascader, the date and time picker, and the compound Table and Tree fields, which bring the Table and
|
|
8
|
+
* Tree Controls with an editor for every column kind. Only text and toggle fields stay in the registry
|
|
9
|
+
* itself. The choice fields stayed too once, as kinds nearly every form has -- but the form every
|
|
10
|
+
* Landing carries is the sign-in, which has none of them, and paid for the Select on every first visit.
|
|
11
|
+
*/
|
|
12
|
+
export declare function lazyPhiFormFieldControl(load: () => Promise<ComponentType<PhiFormFieldProviderProps>>,
|
|
13
|
+
/** How many control rows the field occupies once loaded, so the form keeps its height meanwhile. */
|
|
14
|
+
placeholderRows?: number): ComponentType<PhiFormFieldProviderProps>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { lazy, Suspense } from "react";
|
|
4
|
+
/**
|
|
5
|
+
* A field Control whose code loads when a field of its kind is first rendered.
|
|
6
|
+
*
|
|
7
|
+
* Every kind in the shared registry that has code of its own to ship: the choice and number fields, the slider and the
|
|
8
|
+
* cascader, the date and time picker, and the compound Table and Tree fields, which bring the Table and
|
|
9
|
+
* Tree Controls with an editor for every column kind. Only text and toggle fields stay in the registry
|
|
10
|
+
* itself. The choice fields stayed too once, as kinds nearly every form has -- but the form every
|
|
11
|
+
* Landing carries is the sign-in, which has none of them, and paid for the Select on every first visit.
|
|
12
|
+
*/
|
|
13
|
+
export function lazyPhiFormFieldControl(load,
|
|
14
|
+
/** How many control rows the field occupies once loaded, so the form keeps its height meanwhile. */
|
|
15
|
+
placeholderRows = 1) {
|
|
16
|
+
const LazyControl = lazy(async () => ({ default: await load() }));
|
|
17
|
+
/*
|
|
18
|
+
* Only shown where the browser renders the field before its chunk arrived -- a navigation without a
|
|
19
|
+
* server render. On a server-rendered page React keeps the server HTML until the chunk is there.
|
|
20
|
+
*/
|
|
21
|
+
const placeholder = (_jsx("div", { "aria-busy": "true", style: {
|
|
22
|
+
blockSize: `calc(var(--phi-control-height) * ${placeholderRows} + var(--phi-padding-sm) * ${placeholderRows - 1})`,
|
|
23
|
+
/*
|
|
24
|
+
* The Control shape, because this stands where a Control is about to stand. `grown-md` is half a
|
|
25
|
+
* Control line, which on the one-row placeholder is exactly the capsule and on a taller one is the
|
|
26
|
+
* capsule held -- the same answer the field itself will give when it arrives, so the shape does not
|
|
27
|
+
* change under the reader at the moment the chunk lands.
|
|
28
|
+
*/
|
|
29
|
+
borderRadius: "var(--phi-control-radius-grown-md)",
|
|
30
|
+
background: "var(--phi-color-fill-quaternary)",
|
|
31
|
+
} }));
|
|
32
|
+
return function PhiLazyFormFieldControl(props) {
|
|
33
|
+
return (_jsx(Suspense, { fallback: placeholder, children: _jsx(LazyControl, { ...props }) }));
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
1
2
|
import type { PhiBlockRuntime } from "../../types";
|
|
2
3
|
import type { PhiCmsRuntimeRenderRegistry } from "../../types/cms-plugins";
|
|
3
4
|
import type { PhiFormId } from "../../types/form-id";
|
|
@@ -5,11 +6,11 @@ import type { PhiCmsFormWidgetConfig } from "./form-widget-config";
|
|
|
5
6
|
import { type PhiRuntimeFeatureState } from "../../types/runtime-condition";
|
|
6
7
|
export type PhiFormWidgetProps = {
|
|
7
8
|
runtime: Pick<PhiBlockRuntime, "site" | "locale"> & Partial<Pick<PhiBlockRuntime, "area">>;
|
|
8
|
-
registry: Pick<PhiCmsRuntimeRenderRegistry, "formDefinitionsById" | "uiProviderModuleIds">;
|
|
9
|
+
registry: Pick<PhiCmsRuntimeRenderRegistry, "formDefinitionsById" | "uiProviderModuleIds" | "activeModuleIds" | "ownerModuleIdByFormFieldTypeKey">;
|
|
9
10
|
formId: PhiFormId;
|
|
10
11
|
formInstanceKey?: string | number | null;
|
|
11
12
|
config?: PhiCmsFormWidgetConfig;
|
|
12
13
|
/** What the active Modules published about this Site, as the renderer already resolved it. */
|
|
13
14
|
features?: PhiRuntimeFeatureState | null;
|
|
14
15
|
};
|
|
15
|
-
export declare function PhiFormWidget({ runtime, registry, formId, formInstanceKey, config, features, }: PhiFormWidgetProps): Promise<import("react").
|
|
16
|
+
export declare function PhiFormWidget({ runtime, registry, formId, formInstanceKey, config, features, }: PhiFormWidgetProps): Promise<string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined>;
|
|
@@ -6,6 +6,7 @@ import { resolvePhiFormLabels } from "./form-resolution";
|
|
|
6
6
|
import { createPhiRuntimeFormControllerAddress } from "./runtime-form-controller-address";
|
|
7
7
|
import { PhiRuntimeModuleRenderClientHost } from "../runtime/runtime-module-render-client-manifest";
|
|
8
8
|
import { PhiRuntimeRenderClientType } from "../../constants/runtime-render-client-types";
|
|
9
|
+
import { readPhiFormFieldProviderModules } from "./form-field-provider-modules";
|
|
9
10
|
import { resolvePhiFormText } from "./form-descriptor-contract";
|
|
10
11
|
import { PHI_FORM_DEFAULT_SUBMIT_LABEL } from "../../types/form-descriptor";
|
|
11
12
|
import { readPhiRuntimeConditionValue, } from "../../types/runtime-condition";
|
|
@@ -33,6 +34,20 @@ export async function PhiFormWidget({ runtime, registry, formId, formInstanceKey
|
|
|
33
34
|
};
|
|
34
35
|
const ownerModuleId = resolvedForm.definition.ownerModuleId;
|
|
35
36
|
const hasUiProvider = registry.uiProviderModuleIds.has(ownerModuleId);
|
|
37
|
+
/*
|
|
38
|
+
* A field type belongs to a Module, and the Form is not always that Module's own: the Media library's
|
|
39
|
+
* `media-asset` field stands in Forms of any Module. So the widget reads whose field types this Form
|
|
40
|
+
* uses and mounts those Modules' UI providers beside the Form owner's -- each wraps only this Form's
|
|
41
|
+
* subtree, and composes with the one outside it. A Module that is not active in this Area has nothing
|
|
42
|
+
* to mount; its fields are marked, and the Form says so in their place (`unavailableFieldKeys`).
|
|
43
|
+
*/
|
|
44
|
+
const { providerModuleIds: fieldProviderModuleIds, unavailableFieldKeys } = readPhiFormFieldProviderModules({
|
|
45
|
+
fields: resolvedForm.definition.descriptor.fields,
|
|
46
|
+
formOwnerModuleId: ownerModuleId,
|
|
47
|
+
ownerModuleIdByFieldTypeKey: registry.ownerModuleIdByFormFieldTypeKey,
|
|
48
|
+
activeModuleIds: registry.activeModuleIds,
|
|
49
|
+
uiProviderModuleIds: registry.uiProviderModuleIds,
|
|
50
|
+
});
|
|
36
51
|
/*
|
|
37
52
|
* Both reads happen here, on the server, and both are the form's own: what it is called, and what it
|
|
38
53
|
* already knows. Asking for either after hydration is a blank card for as long as the page takes to
|
|
@@ -78,9 +93,11 @@ export async function PhiFormWidget({ runtime, registry, formId, formInstanceKey
|
|
|
78
93
|
children: node,
|
|
79
94
|
};
|
|
80
95
|
const framed = (_jsx(PhiRuntimeModuleRenderClientHost, { type: PhiRuntimeRenderClientType.FormWidgetFrame, componentProps: frameProps }));
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
96
|
+
const providerModuleIds = [
|
|
97
|
+
...(hasUiProvider ? [ownerModuleId] : []),
|
|
98
|
+
...fieldProviderModuleIds,
|
|
99
|
+
];
|
|
100
|
+
return providerModuleIds.reduceRight((children, moduleId) => (_jsx(PhiRuntimeModuleUiProviderHost, { moduleId: moduleId, children: children })), framed);
|
|
84
101
|
};
|
|
85
102
|
return wrapFormUiProvider(_jsx(PhiRuntimeModuleRenderClientHost, { type: PhiRuntimeRenderClientType.FormDescriptor, componentProps: {
|
|
86
103
|
descriptor: resolvedForm.definition.descriptor,
|
|
@@ -89,5 +106,6 @@ export async function PhiFormWidget({ runtime, registry, formId, formInstanceKey
|
|
|
89
106
|
formId: resolvedForm.definition.formId,
|
|
90
107
|
formControllerAddress: renderOptions.formControllerAddress,
|
|
91
108
|
widgetConfig: config,
|
|
109
|
+
...(unavailableFieldKeys.length > 0 ? { unavailableFieldKeys } : {}),
|
|
92
110
|
} }));
|
|
93
111
|
}
|
|
@@ -1,44 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { lazy, Suspense } from "react";
|
|
4
3
|
import { createPhiFormProviderRegistry, } from "./form-provider-registry";
|
|
5
4
|
import { PHI_FORM_FIELD_PROVIDER_KEYS, PHI_FORM_VALIDATION_PROVIDER_KEYS, PHI_SHARED_FORM_FIELD_TYPE_PROVIDER_DESCRIPTORS, PHI_SHARED_FORM_VALIDATION_PROVIDER_DESCRIPTORS, } from "./form-provider-contract";
|
|
6
5
|
import { PhiTextControl } from "../controls/phi-text-control";
|
|
7
6
|
import { PhiCheckboxControl } from "../controls/phi-checkbox-control";
|
|
8
7
|
import { PhiCheckboxGroupControl } from "../controls/phi-checkbox-group-control";
|
|
9
8
|
import { PhiSwitchControl } from "../controls/phi-switch-control";
|
|
10
|
-
|
|
11
|
-
* A field Control whose code loads when a field of its kind is first rendered.
|
|
12
|
-
*
|
|
13
|
-
* Every kind below that has code of its own to ship: the choice and number fields, the slider and the
|
|
14
|
-
* cascader, the date and time picker, and the compound Table and Tree fields, which bring the Table and
|
|
15
|
-
* Tree Controls with an editor for every column kind. Only text and toggle fields stay in the registry
|
|
16
|
-
* itself. The choice fields stayed too once, as kinds nearly every form has -- but the form every
|
|
17
|
-
* Landing carries is the sign-in, which has none of them, and paid for the Select on every first visit.
|
|
18
|
-
*/
|
|
19
|
-
function lazyPhiFormFieldControl(load,
|
|
20
|
-
/** How many control rows the field occupies once loaded, so the form keeps its height meanwhile. */
|
|
21
|
-
placeholderRows = 1) {
|
|
22
|
-
const LazyControl = lazy(async () => ({ default: await load() }));
|
|
23
|
-
/*
|
|
24
|
-
* Only shown where the browser renders the field before its chunk arrived -- a navigation without a
|
|
25
|
-
* server render. On a server-rendered page React keeps the server HTML until the chunk is there.
|
|
26
|
-
*/
|
|
27
|
-
const placeholder = (_jsx("div", { "aria-busy": "true", style: {
|
|
28
|
-
blockSize: `calc(var(--phi-control-height) * ${placeholderRows} + var(--phi-padding-sm) * ${placeholderRows - 1})`,
|
|
29
|
-
/*
|
|
30
|
-
* The Control shape, because this stands where a Control is about to stand. `grown-md` is half a
|
|
31
|
-
* Control line, which on the one-row placeholder is exactly the capsule and on a taller one is the
|
|
32
|
-
* capsule held -- the same answer the field itself will give when it arrives, so the shape does not
|
|
33
|
-
* change under the reader at the moment the chunk lands.
|
|
34
|
-
*/
|
|
35
|
-
borderRadius: "var(--phi-control-radius-grown-md)",
|
|
36
|
-
background: "var(--phi-color-fill-quaternary)",
|
|
37
|
-
} }));
|
|
38
|
-
return function PhiLazyFormFieldControl(props) {
|
|
39
|
-
return (_jsx(Suspense, { fallback: placeholder, children: _jsx(LazyControl, { ...props }) }));
|
|
40
|
-
};
|
|
41
|
-
}
|
|
9
|
+
import { lazyPhiFormFieldControl } from "./lazy-form-field-control";
|
|
42
10
|
const PhiLazyLinkTargetFormControl = lazyPhiFormFieldControl(() => import("./link-target-form-control").then((module) => module.PhiLinkTargetFormControl));
|
|
43
11
|
const PhiLazySelectFormControl = lazyPhiFormFieldControl(() => import("./choice-form-field-controls").then((module) => module.PhiSelectFormControl));
|
|
44
12
|
const PhiLazyMultiSelectFormControl = lazyPhiFormFieldControl(() => import("./choice-form-field-controls").then((module) => module.PhiMultiSelectFormControl));
|