@phis/ui 0.7.3 → 0.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/components/controls/phi-form-control.js +1 -0
  2. package/components/controls/phi-media-asset-tile-control.d.ts +4 -3
  3. package/components/controls/phi-media-picker-control.d.ts +9 -11
  4. package/components/controls/phi-media-picker-control.js +9 -11
  5. package/components/controls/phi-options-provider.d.ts +14 -1
  6. package/components/controls/phi-options-provider.js +73 -2
  7. package/components/forms/form-field-labels.d.ts +3 -3
  8. package/components/forms/form-field-labels.js +13 -5
  9. package/components/forms/media-asset-field-keys.d.ts +9 -1
  10. package/components/forms/media-asset-field-keys.js +13 -1
  11. package/components/media/label-sets/media.js +4 -0
  12. package/components/media/media-folder-name-path.d.ts +14 -0
  13. package/components/media/media-folder-name-path.js +40 -2
  14. package/components/media/media-library-resource.d.ts +70 -0
  15. package/components/media/media-library-resource.js +41 -0
  16. package/components/media/media-widget-labels.d.ts +13 -0
  17. package/components/media/media-widget-labels.js +2 -0
  18. package/components/media/phi-area-upload-widget.d.ts +31 -1
  19. package/components/media/phi-area-upload-widget.js +33 -7
  20. package/components/media/phi-image-preview-data.d.ts +8 -1
  21. package/components/media/phi-image-preview-data.js +29 -0
  22. package/components/media/phi-media-picker-binding.d.ts +22 -20
  23. package/components/media/phi-media-picker-binding.js +20 -33
  24. package/components/media/use-media-library-add-picker.d.ts +94 -0
  25. package/components/media/use-media-library-add-picker.js +40 -0
  26. package/components/widgets/client/shared/phi-choice-controller.js +22 -15
  27. package/constants/media-library-provider-keys.d.ts +7 -0
  28. package/constants/media-library-provider-keys.js +7 -0
  29. package/constants/runtime-module-ownership.js +1 -0
  30. package/helpers/preset-tree-contract-check.d.ts +35 -0
  31. package/helpers/preset-tree-contract-check.js +211 -0
  32. package/module-page-check.d.ts +6 -0
  33. package/module-page-check.js +6 -0
  34. package/package.json +1 -1
  35. package/plugins/runtime-modules/asset/data-providers.d.ts +56 -38
  36. package/plugins/runtime-modules/asset/data-providers.js +4 -32
  37. package/plugins/runtime-modules/asset/definition.d.ts +115 -38
  38. package/plugins/runtime-modules/asset/definition.js +2 -1
  39. package/plugins/runtime-modules/asset/form-providers.d.ts +85 -2
  40. package/plugins/runtime-modules/asset/form-providers.js +70 -11
  41. package/plugins/runtime-modules/asset/form-ui-provider.js +7 -1
  42. package/plugins/runtime-modules/asset/media-asset-field.d.ts +7 -7
  43. package/plugins/runtime-modules/asset/media-asset-field.js +11 -33
  44. package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +8 -7
  45. package/plugins/runtime-modules/asset/media-asset-form-control.js +42 -83
  46. package/plugins/runtime-modules/asset/media-assets-field.d.ts +37 -0
  47. package/plugins/runtime-modules/asset/media-assets-field.js +81 -0
  48. package/plugins/runtime-modules/asset/media-assets-form-control.d.ts +27 -0
  49. package/plugins/runtime-modules/asset/media-assets-form-control.js +182 -0
  50. package/plugins/runtime-modules/asset/media-field-picker-labels.d.ts +9 -0
  51. package/plugins/runtime-modules/asset/media-field-picker-labels.js +49 -0
  52. package/plugins/runtime-modules/asset/services/collection.js +12 -0
  53. package/plugins/runtime-modules/builder/clients/inspector-config-field.js +11 -6
  54. package/plugins/runtime-modules/core/widgets/cascader/client.js +13 -12
  55. package/plugins/runtime-modules/core/widgets/checkbox-group/client.js +5 -4
  56. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding-tools.d.ts +24 -0
  57. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding-tools.js +55 -0
  58. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding.d.ts +26 -2
  59. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding.js +125 -32
  60. package/plugins/runtime-modules/core/widgets/collection-view/client.d.ts +7 -2
  61. package/plugins/runtime-modules/core/widgets/collection-view/client.js +12 -4
  62. package/plugins/runtime-modules/core/widgets/collection-view/config.d.ts +25 -0
  63. package/plugins/runtime-modules/core/widgets/collection-view/config.js +34 -0
  64. package/plugins/runtime-modules/core/widgets/collection-view/image-preview-grid.js +4 -1
  65. package/plugins/runtime-modules/core/widgets/collection-view/server.d.ts +3 -2
  66. package/plugins/runtime-modules/core/widgets/collection-view/server.js +20 -18
  67. package/plugins/runtime-modules/core/widgets/multi-select/client.js +6 -4
  68. package/plugins/runtime-modules/descriptor-compiler.d.ts +4 -0
  69. package/plugins/runtime-modules/descriptor-compiler.js +9 -204
  70. package/plugins/runtime-modules/resolver.js +31 -5
  71. package/types/collection-view-widget.d.ts +19 -0
  72. package/types/core-widget-placements.d.ts +9 -0
  73. package/types/media.d.ts +16 -0
@@ -7,18 +7,26 @@ import { isPhiStackSignalMessage, PHI_STACK_META_SIGNAL_CHANNEL, readPhiStackSig
7
7
  import { usePhiSignalListener } from "../../../runtime/runtime-signal-bus";
8
8
  import { usePhiControlSignalController } from "./phi-control-signals";
9
9
  import { usePhiControlOptionsProvider } from "../../../controls/phi-options-provider";
10
+ /**
11
+ * What a choice holds, as far as known before its options resolve: a configured value is the fallback a
12
+ * pick holds against. Without one the fallback is the provider's own answer, so only a pick is told.
13
+ */
14
+ function readPhiChoiceHeldValue(picked, configuredValue) {
15
+ if (configuredValue == null)
16
+ return picked?.value;
17
+ return picked?.source === configuredValue ? picked.value : configuredValue;
18
+ }
10
19
  export function usePhiChoiceController({ config, signalsEnabled = true, typeKey, defaultKey, sender, }) {
20
+ // A pick, held against the fallback it replaced; declared first so the provider hears it.
21
+ const [picked, setPicked] = useState(null);
11
22
  const resolvedOptions = usePhiControlOptionsProvider({
12
23
  options: config?.options,
13
24
  optionsProvider: config?.optionsProvider,
25
+ selectedValues: readPhiChoiceHeldValue(picked, config?.value),
14
26
  });
15
27
  const fallbackValue = config?.value ?? resolvedOptions.value ?? resolvedOptions.options.at(0)?.value ?? "";
16
28
  const readOnly = config?.readOnly === true;
17
- const [state, setState] = useState(() => ({
18
- source: fallbackValue,
19
- value: fallbackValue,
20
- }));
21
- const value = state.source === fallbackValue ? state.value : fallbackValue;
29
+ const value = picked?.source === fallbackValue ? picked.value : fallbackValue;
22
30
  /*
23
31
  * Options a sender replaced, held against the configured list they replaced. When the configuration
24
32
  * brings a different list, that one is what the Control was given last, so the sent one steps aside.
@@ -38,7 +46,7 @@ export function usePhiChoiceController({ config, signalsEnabled = true, typeKey,
38
46
  initialDisabled: config?.disabled === true,
39
47
  initialReadOnly: readOnly,
40
48
  clearValue: fallbackValue,
41
- onSetValue: (nextValue) => setState({ source: fallbackValue, value: nextValue }),
49
+ onSetValue: (nextValue) => setPicked({ source: fallbackValue, value: nextValue }),
42
50
  onReceiveCapability: (capabilityId, signal) => {
43
51
  if (capabilityId !== "options") {
44
52
  return false;
@@ -55,7 +63,7 @@ export function usePhiChoiceController({ config, signalsEnabled = true, typeKey,
55
63
  if (readOnly) {
56
64
  return;
57
65
  }
58
- setState({
66
+ setPicked({
59
67
  source: fallbackValue,
60
68
  value: nextValue,
61
69
  });
@@ -84,19 +92,18 @@ function mapPhiStackSlotsToChoiceOptions(message) {
84
92
  }));
85
93
  }
86
94
  export function usePhiStackChoiceController({ config, signalsEnabled = true, typeKey, defaultKey, sender, }) {
95
+ // A pick, held against the fallback it replaced; declared first so the provider hears it.
96
+ const [picked, setPicked] = useState(null);
87
97
  const resolvedOptions = usePhiControlOptionsProvider({
88
98
  options: config?.options,
89
99
  optionsProvider: config?.optionsProvider,
100
+ selectedValues: readPhiChoiceHeldValue(picked, config?.value),
90
101
  });
91
102
  const stackMode = config?.valueMode === "stack-slot-index";
92
103
  const fallbackValue = config?.value ?? resolvedOptions.value ?? resolvedOptions.options.at(0)?.value ?? "";
93
104
  const readOnly = config?.readOnly === true;
94
- const [state, setState] = useState(() => ({
95
- source: fallbackValue,
96
- value: fallbackValue,
97
- }));
98
105
  const [stackOptions, setStackOptions] = useState([]);
99
- const value = state.source === fallbackValue ? state.value : fallbackValue;
106
+ const value = picked?.source === fallbackValue ? picked.value : fallbackValue;
100
107
  const stackMetaListenRoute = findPhiSignalRoutesByCapabilityId(config?.signalRoutes?.listens, "stackMeta")[0] ?? null;
101
108
  /*
102
109
  * The Stack this Choice follows: the one its `stackMeta` request is addressed to. Every Stack answers
@@ -114,7 +121,7 @@ export function usePhiStackChoiceController({ config, signalsEnabled = true, typ
114
121
  initialDisabled: config?.disabled === true,
115
122
  initialReadOnly: readOnly,
116
123
  clearValue: fallbackValue,
117
- onSetValue: (nextValue) => setState({ source: fallbackValue, value: nextValue }),
124
+ onSetValue: (nextValue) => setPicked({ source: fallbackValue, value: nextValue }),
118
125
  coerceValue: (nextValue) => (typeof nextValue === "string" ? nextValue : nextValue == null ? "" : String(nextValue)),
119
126
  });
120
127
  const emitControlCapability = controlSignals.emitCapability;
@@ -140,7 +147,7 @@ export function usePhiStackChoiceController({ config, signalsEnabled = true, typ
140
147
  }
141
148
  setStackOptions(mapPhiStackSlotsToChoiceOptions(message) ?? []);
142
149
  const nextValue = String(message.value.activeSlotIndex);
143
- setState((current) => current.source === fallbackValue && current.value === nextValue
150
+ setPicked((current) => current?.source === fallbackValue && current.value === nextValue
144
151
  ? current
145
152
  : { source: fallbackValue, value: nextValue });
146
153
  }, useMemo(() => ({
@@ -151,7 +158,7 @@ export function usePhiStackChoiceController({ config, signalsEnabled = true, typ
151
158
  if (readOnly) {
152
159
  return;
153
160
  }
154
- setState({
161
+ setPicked({
155
162
  source: fallbackValue,
156
163
  value: nextValue,
157
164
  });
@@ -50,3 +50,10 @@ export declare const PHI_MEDIA_LIBRARY_ITEM_RENDERER_KEY: `${string}/${string}`;
50
50
  * holds no reference to the Module -- the resolver reads it to mount the library Provider the picker needs.
51
51
  */
52
52
  export declare const PHI_MEDIA_ASSET_FORM_FIELD_PROVIDER_KEY: PhiFormProviderKey;
53
+ /**
54
+ * The `media-assets` Form field type: several Assets of the Site's Media library, as an ordered list of
55
+ * their ids -- the many-picture counterpart of `media-asset`, for a record that has several (a product's
56
+ * gallery). Named on the same terms: the Asset Module owns, declares and serves it (FORMS.md), and the
57
+ * resolver reads this key to mount the library Provider its picker and tiles read.
58
+ */
59
+ export declare const PHI_MEDIA_ASSETS_FORM_FIELD_PROVIDER_KEY: PhiFormProviderKey;
@@ -51,3 +51,10 @@ export const PHI_MEDIA_LIBRARY_ITEM_RENDERER_KEY = createPhiSharedRuntimeItemRen
51
51
  * holds no reference to the Module -- the resolver reads it to mount the library Provider the picker needs.
52
52
  */
53
53
  export const PHI_MEDIA_ASSET_FORM_FIELD_PROVIDER_KEY = createPhiModuleScopedKey("form-field", "media-asset");
54
+ /**
55
+ * The `media-assets` Form field type: several Assets of the Site's Media library, as an ordered list of
56
+ * their ids -- the many-picture counterpart of `media-asset`, for a record that has several (a product's
57
+ * gallery). Named on the same terms: the Asset Module owns, declares and serves it (FORMS.md), and the
58
+ * resolver reads this key to mount the library Provider its picker and tiles read.
59
+ */
60
+ export const PHI_MEDIA_ASSETS_FORM_FIELD_PROVIDER_KEY = createPhiModuleScopedKey("form-field", "media-assets");
@@ -48,6 +48,7 @@ const PHI_RUNTIME_MODULE_OWNERSHIP = {
48
48
  "form-field/hidden": ["core", "hidden"],
49
49
  "form-field/honeypot": ["core", "honeypot"],
50
50
  "form-field/media-asset": ["asset", "media-asset"],
51
+ "form-field/media-assets": ["asset", "media-assets"],
51
52
  "form-field/money": ["core", "money"],
52
53
  "form-field/multi-select": ["core", "multi-select"],
53
54
  "form-field/number": ["core", "number"],
@@ -0,0 +1,35 @@
1
+ import type { PhiFormDescriptor } from "@phis/contracts/forms";
2
+ import type { PhiCmsPageNode, PhiResolvedCmsPageTree } from "../types/cms";
3
+ /**
4
+ * The rules every preset tree is held to (THIRD_PARTY_MODULES.md, "Checking a Page preset"), as findings.
5
+ *
6
+ * One source for two callers. The descriptor compiler runs it on every tree a preset loads while a Site
7
+ * serves the Page and throws the first finding (`assertPhiCmsPresetTreeContract`): the Page answers 500. A
8
+ * Module package runs it, from `@phis/ui/module/page-check`, over every tree its presets build in its own
9
+ * tests, with its own Forms, so the same tree fails there before it ships.
10
+ *
11
+ * The rules: every node a preset instance id, none twice, every parent, Region root, Overlay root and Page
12
+ * root resolved; the base page layout node only as the canonical scaffold; an actions Footer the canonical
13
+ * Flex preset; a modal's body and actions the dialog's (`helpers/cms-dialog.ts`), and a modal at the default
14
+ * `PHI_DIALOG_WIDTH` not holding only Forms of one column. The findings come in the order the compiler used
15
+ * to throw them, so its first is the error it always gave.
16
+ *
17
+ * `page` is the Page the tree was asked for: a tree whose Page or Regions belong to another is refused.
18
+ * `forms` are the Forms the caller can see, by id or as definitions; a Form not among them -- one stored on
19
+ * the Site, one of another Module -- is not judged, and without `forms` the dialog width is not checked.
20
+ */
21
+ export type PhiPresetTreeContractFinding = {
22
+ /** The node's id, or "page" for the Page itself. */
23
+ node: string;
24
+ message: string;
25
+ };
26
+ type PresetTreeForm = {
27
+ descriptor: PhiFormDescriptor;
28
+ };
29
+ export declare function checkPhiPresetTreeContract(tree: PhiResolvedCmsPageTree, options?: {
30
+ page?: PhiCmsPageNode;
31
+ forms?: ReadonlyMap<string, PresetTreeForm> | Iterable<PresetTreeForm & {
32
+ formId: string;
33
+ }>;
34
+ }): PhiPresetTreeContractFinding[];
35
+ export {};
@@ -0,0 +1,211 @@
1
+ import { buildPhiBasePageLayoutNode, PHI_BASE_PAGE_LAYOUT_NODE_ID } from "../components/regions/presets/phi-base-page-layout";
2
+ import { PhiCmsLayoutType } from "../constants/cms-layout-type-keys";
3
+ import { PhiCmsWidgetType } from "../constants/cms-widget-types";
4
+ import { isPhiCmsInstanceId, readPhiCmsInstanceIdDescriptor } from "../types/cms-instance-id";
5
+ import { PHI_DIALOG_BLEED_BODY_CONFIG, PHI_DIALOG_BODY_CONFIG, PHI_DIALOG_COMMANDS_CONFIG, PHI_DIALOG_WIDTH, isPhiFormSingleColumn, } from "./cms-dialog";
6
+ import { resolvePhiLayoutCreationPreset } from "./cms-layout-defaults";
7
+ function stablePresetNodeJson(value) {
8
+ if (Array.isArray(value)) {
9
+ return `[${value.map(stablePresetNodeJson).join(",")}]`;
10
+ }
11
+ if (value && typeof value === "object") {
12
+ return `{${Object.entries(value)
13
+ .filter(([, entry]) => entry !== undefined)
14
+ .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))
15
+ .map(([key, entry]) => `${JSON.stringify(key)}:${stablePresetNodeJson(entry)}`)
16
+ .join(",")}}`;
17
+ }
18
+ return JSON.stringify(value) ?? "undefined";
19
+ }
20
+ function readFormsById(forms) {
21
+ if (!forms || forms instanceof Map)
22
+ return forms;
23
+ return new Map([...forms].map((form) => [form.formId, form]));
24
+ }
25
+ export function checkPhiPresetTreeContract(tree, options = {}) {
26
+ const findings = [];
27
+ const report = (node, message) => findings.push({ node, message });
28
+ const expectedPage = options.page;
29
+ const forms = readFormsById(options.forms);
30
+ const layoutIds = new Set();
31
+ const allIds = new Set();
32
+ if (expectedPage &&
33
+ (tree.page.siteId !== expectedPage.siteId ||
34
+ tree.page.areaMask !== expectedPage.areaMask ||
35
+ tree.page.path !== expectedPage.path)) {
36
+ report("page", "Preset loader returned a Page outside its requested context.");
37
+ }
38
+ const checkId = (node, kind) => {
39
+ if (!isPhiCmsInstanceId(node.id) || readPhiCmsInstanceIdDescriptor(node.id)?.origin !== "preset") {
40
+ report(String(node.id), `${kind} has invalid instance id "${String(node.id)}".`);
41
+ }
42
+ if (allIds.has(node.id)) {
43
+ report(node.id, `Preset tree contains duplicate instance id "${node.id}".`);
44
+ }
45
+ allIds.add(node.id);
46
+ };
47
+ for (const node of tree.overlays)
48
+ checkId(node, "Preset Overlay");
49
+ for (const node of tree.layoutNodes) {
50
+ checkId(node, "Preset layout node");
51
+ layoutIds.add(node.id);
52
+ }
53
+ for (const node of tree.contentWidgets)
54
+ checkId(node, "Preset widget node");
55
+ for (const node of tree.layoutNodes) {
56
+ if (node.parentLayoutNodeId != null && !layoutIds.has(node.parentLayoutNodeId)) {
57
+ report(node.id, `Preset layout "${node.id}" has unresolved parent "${node.parentLayoutNodeId}".`);
58
+ }
59
+ }
60
+ for (const node of tree.contentWidgets) {
61
+ if (!layoutIds.has(node.parentLayoutNodeId)) {
62
+ report(node.id, `Preset widget "${node.id}" has unresolved parent "${node.parentLayoutNodeId}".`);
63
+ }
64
+ }
65
+ for (const region of tree.regions) {
66
+ if (expectedPage && region.pageId !== expectedPage.id) {
67
+ report(region.rootLayoutNodeId, `Preset region "${region.regionType}" belongs to a different Page.`);
68
+ }
69
+ if (!layoutIds.has(region.rootLayoutNodeId)) {
70
+ report(region.rootLayoutNodeId, `Preset region "${region.regionType}" has unresolved root "${region.rootLayoutNodeId}".`);
71
+ }
72
+ }
73
+ const layoutsById = new Map(tree.layoutNodes.map((node) => [node.id, node]));
74
+ checkBasePageLayoutNode(tree, layoutsById, report);
75
+ for (const overlay of tree.overlays) {
76
+ if (!layoutIds.has(overlay.bodyLayoutNodeId)) {
77
+ report(overlay.id, `Preset Overlay "${overlay.id}" has unresolved Body root "${overlay.bodyLayoutNodeId}".`);
78
+ }
79
+ if (overlay.headerLayoutNodeId != null && !layoutIds.has(overlay.headerLayoutNodeId)) {
80
+ report(overlay.id, `Preset Overlay "${overlay.id}" has unresolved Header root "${overlay.headerLayoutNodeId}".`);
81
+ }
82
+ if (overlay.footerPresentation === "none") {
83
+ continue;
84
+ }
85
+ const footerLayout = layoutsById.get(overlay.footerLayoutNodeId);
86
+ if (!footerLayout) {
87
+ report(overlay.id, `Preset Overlay "${overlay.id}" has unresolved Footer root "${overlay.footerLayoutNodeId}".`);
88
+ continue;
89
+ }
90
+ if (overlay.footerPresentation === "actions") {
91
+ if (footerLayout.widgetType !== PhiCmsLayoutType.Flex) {
92
+ report(overlay.id, `Preset Overlay "${overlay.id}" actions Footer must use the Phi Flex Layout.`);
93
+ continue;
94
+ }
95
+ const expectedConfig = resolvePhiLayoutCreationPreset("flex", "overlay-actions");
96
+ const mismatch = Object.entries(expectedConfig).find(([key, value]) => JSON.stringify(footerLayout.config[key]) !== JSON.stringify(value));
97
+ if (mismatch) {
98
+ report(overlay.id, `Preset Overlay "${overlay.id}" actions Footer does not match the canonical Layout preset at "${mismatch[0]}".`);
99
+ continue;
100
+ }
101
+ if (overlay.overlayType === "modal") {
102
+ checkDialogCommands(overlay.id, footerLayout.id, tree.contentWidgets, report);
103
+ }
104
+ }
105
+ }
106
+ for (const overlay of tree.overlays) {
107
+ if (overlay.overlayType !== "modal")
108
+ continue;
109
+ const body = layoutsById.get(overlay.bodyLayoutNodeId);
110
+ if (body)
111
+ checkDialogBody(overlay.id, body, report);
112
+ if (forms)
113
+ checkDialogWidth(overlay, tree, forms, report);
114
+ }
115
+ for (const rootLayoutNodeId of [
116
+ tree.page.heroRootLayoutNodeId,
117
+ tree.page.headerBottomRootLayoutNodeId,
118
+ tree.page.siderRightRootLayoutNodeId,
119
+ tree.page.footerTopRootLayoutNodeId,
120
+ tree.page.drawerRightRootLayoutNodeId,
121
+ tree.page.contentRootLayoutNodeId,
122
+ ]) {
123
+ if (rootLayoutNodeId != null && !layoutIds.has(rootLayoutNodeId)) {
124
+ report("page", `Preset Page has unresolved root "${rootLayoutNodeId}".`);
125
+ }
126
+ }
127
+ return findings;
128
+ }
129
+ /**
130
+ * Equal id must mean equal node: the shared page scaffold carries the same instance id in every
131
+ * built-in preset tree, which stays sound only while every copy is the canonical node. A preset that
132
+ * wants different chrome gets its own Layout node in a slot -- a deviating copy of the scaffold is a
133
+ * contract violation, not a customisation.
134
+ */
135
+ function checkBasePageLayoutNode(tree, layoutsById, report) {
136
+ for (const node of [...tree.overlays, ...tree.contentWidgets]) {
137
+ if (node.id === PHI_BASE_PAGE_LAYOUT_NODE_ID) {
138
+ report(node.id, "The base page layout instance id is reserved for the scaffold Layout node.");
139
+ }
140
+ }
141
+ const node = layoutsById.get(PHI_BASE_PAGE_LAYOUT_NODE_ID);
142
+ if (!node) {
143
+ return;
144
+ }
145
+ const canonical = buildPhiBasePageLayoutNode(tree.page);
146
+ const mismatch = Object.keys(canonical)
147
+ .find((key) => stablePresetNodeJson(node[key]) !== stablePresetNodeJson(canonical[key]));
148
+ if (mismatch) {
149
+ report(node.id, `Preset tree carries a deviating base page layout node: "${String(mismatch)}" is ` +
150
+ `${stablePresetNodeJson(node[mismatch])}, canonical is ${stablePresetNodeJson(canonical[mismatch])}.`);
151
+ }
152
+ }
153
+ /*
154
+ * A dialog's body and actions are one answer for every dialog (`helpers/cms-dialog.ts`), checked here as
155
+ * the footer Layout is: a Preset that builds its dialog node by node must arrive at the same look as one
156
+ * that calls `dialog`. A vertical Flex carries the whole body config; a Layout of another kind -- a Stack
157
+ * of tabs -- carries the ground and the inset, which are what make it the dialog's body.
158
+ */
159
+ function checkDialogBody(overlayId, body, report) {
160
+ // The bleed body is the other answer, for content that runs to the edge; it is matched whole.
161
+ const bleed = PHI_DIALOG_BLEED_BODY_CONFIG.padding === body.config.padding;
162
+ const required = bleed
163
+ ? PHI_DIALOG_BLEED_BODY_CONFIG
164
+ : body.widgetType === PhiCmsLayoutType.FlexVertical
165
+ ? PHI_DIALOG_BODY_CONFIG
166
+ : { surface: PHI_DIALOG_BODY_CONFIG.surface, padding: PHI_DIALOG_BODY_CONFIG.padding };
167
+ const mismatch = Object.entries(required).find(([key, value]) => JSON.stringify(body.config[key]) !== JSON.stringify(value));
168
+ if (mismatch) {
169
+ report(overlayId, `Preset Overlay "${overlayId}" Body "${body.id}" does not match the dialog body (${bleed ? "PHI_DIALOG_BLEED_BODY_CONFIG" : "PHI_DIALOG_BODY_CONFIG"}) at "${mismatch[0]}".`);
170
+ }
171
+ }
172
+ function checkDialogCommands(overlayId, footerLayoutId, widgets, report) {
173
+ for (const widget of widgets) {
174
+ if (widget.parentLayoutNodeId !== footerLayoutId || widget.widgetType !== PhiCmsWidgetType.CommandToolbar)
175
+ continue;
176
+ const mismatch = Object.entries(PHI_DIALOG_COMMANDS_CONFIG).find(([key, value]) => widget.config[key] !== value);
177
+ if (mismatch) {
178
+ report(widget.id, `Preset Overlay "${overlayId}" actions "${widget.id}" do not match the dialog actions (PHI_DIALOG_COMMANDS_CONFIG) at "${mismatch[0]}".`);
179
+ }
180
+ }
181
+ }
182
+ /*
183
+ * A dialog is as wide as its Form needs (`helpers/cms-dialog.ts`): one column takes
184
+ * `PHI_DIALOG_WIDTH_SINGLE_COLUMN`, two keep `PHI_DIALOG_WIDTH`. What is refused is the one width a Preset
185
+ * did not choose -- the default, holding nothing but Forms of one column. Any other width was stated, by a
186
+ * caller that knows what else the body holds; a Form the caller cannot see is not judged.
187
+ */
188
+ function checkDialogWidth(overlay, tree, forms, report) {
189
+ if (stablePresetNodeJson(overlay.config.width) !== stablePresetNodeJson(PHI_DIALOG_WIDTH))
190
+ return;
191
+ const bodyLayoutIds = new Set([overlay.bodyLayoutNodeId]);
192
+ for (let grown = true; grown;) {
193
+ grown = false;
194
+ for (const node of tree.layoutNodes) {
195
+ if (node.parentLayoutNodeId != null && bodyLayoutIds.has(node.parentLayoutNodeId) && !bodyLayoutIds.has(node.id)) {
196
+ bodyLayoutIds.add(node.id);
197
+ grown = true;
198
+ }
199
+ }
200
+ }
201
+ const formIds = tree.contentWidgets
202
+ .filter((widget) => widget.widgetType === PhiCmsWidgetType.Form && bodyLayoutIds.has(widget.parentLayoutNodeId))
203
+ .map((widget) => widget.config.formId);
204
+ if (formIds.length === 0)
205
+ return;
206
+ const descriptors = formIds.map((formId) => (typeof formId === "string" ? forms.get(formId) : undefined)?.descriptor);
207
+ if (descriptors.every((descriptor) => descriptor != null && isPhiFormSingleColumn(descriptor))) {
208
+ report(overlay.id, `Preset Overlay "${overlay.id}" holds the one-column Form "${String(formIds[0])}" at the full dialog width ` +
209
+ "(PHI_DIALOG_WIDTH). Hand the Form to `dialog` as `body.form`, or state `width: PHI_DIALOG_WIDTH_SINGLE_COLUMN`.");
210
+ }
211
+ }
@@ -7,9 +7,15 @@
7
7
  * build, and treats a finding as an error; it is never called while a Site serves a request, and so it is
8
8
  * never part of `@phis/ui/helpers`.
9
9
  *
10
+ * `checkPhiPresetTreeContract` is the one exception to "never at request time" for the code behind it, not
11
+ * for this door: the descriptor compiler runs the same rules on every tree a preset loads and throws the
12
+ * first finding. Here a package runs them first, with its own Forms, so a tree the compiler would refuse
13
+ * fails the package's tests instead of answering 500 on a Site.
14
+ *
10
15
  * No `server-only` here, on purpose: a test in a package loads this door without a mock.
11
16
  */
12
17
  export { createPhiDeclaredMediaResolver, type PhiModuleMediaFinding } from "./helpers/module-media-check";
13
18
  export { checkPhiPagePresetLayout, type PhiPageLayoutFinding } from "./helpers/page-layout-check";
14
19
  export { checkPhiPresetTextSources, type PhiPresetTextSourceFinding } from "./helpers/preset-text-source-check";
20
+ export { checkPhiPresetTreeContract, type PhiPresetTreeContractFinding } from "./helpers/preset-tree-contract-check";
15
21
  export { checkPhiRouteAddresses, type PhiRouteAddressFinding, type PhiRouteAddressSubject } from "./helpers/route-address-check";
@@ -7,9 +7,15 @@
7
7
  * build, and treats a finding as an error; it is never called while a Site serves a request, and so it is
8
8
  * never part of `@phis/ui/helpers`.
9
9
  *
10
+ * `checkPhiPresetTreeContract` is the one exception to "never at request time" for the code behind it, not
11
+ * for this door: the descriptor compiler runs the same rules on every tree a preset loads and throws the
12
+ * first finding. Here a package runs them first, with its own Forms, so a tree the compiler would refuse
13
+ * fails the package's tests instead of answering 500 on a Site.
14
+ *
10
15
  * No `server-only` here, on purpose: a test in a package loads this door without a mock.
11
16
  */
12
17
  export { createPhiDeclaredMediaResolver } from "./helpers/module-media-check";
13
18
  export { checkPhiPagePresetLayout } from "./helpers/page-layout-check";
14
19
  export { checkPhiPresetTextSources } from "./helpers/preset-text-source-check";
20
+ export { checkPhiPresetTreeContract } from "./helpers/preset-tree-contract-check";
15
21
  export { checkPhiRouteAddresses } from "./helpers/route-address-check";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phis/ui",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "license": "Apache-2.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -41,44 +41,62 @@ export declare const PHI_ASSET_RUNTIME_DATA_PROVIDER_DESCRIPTORS: ({
41
41
  description: string;
42
42
  availableToAuthoringChrome: true;
43
43
  resources: {
44
- resourceKey: string;
45
- title: string;
46
- itemIdentityPath: string;
47
- itemRendererKey: `${string}/${string}`;
48
- selectionValueSchema: `${string}/signals/${string}`;
49
- defaultForWidget: true;
50
- query: {
51
- search: true;
52
- pagination: true;
53
- filterFields: ({
54
- key: string;
55
- title: string;
56
- type: "enum[]";
57
- } | {
58
- key: string;
59
- title: string;
60
- type: "path";
61
- })[];
44
+ readonly resourceKey: "assets";
45
+ readonly title: "Assets";
46
+ readonly itemIdentityPath: "id";
47
+ readonly itemRendererKey: `${string}/${string}`;
48
+ readonly selectionValueSchema: `${string}/signals/${string}`;
49
+ readonly defaultForWidget: true;
50
+ readonly query: {
51
+ readonly search: true;
52
+ readonly pagination: true;
53
+ readonly filterFields: readonly [{
54
+ readonly key: "kind";
55
+ readonly title: "Kind";
56
+ readonly type: "enum[]";
57
+ }, {
58
+ readonly key: "presentationFlags";
59
+ readonly title: "Flags";
60
+ readonly type: "enum[]";
61
+ }, {
62
+ readonly key: "folderId";
63
+ readonly title: "Folder";
64
+ readonly type: "path";
65
+ }];
62
66
  };
63
- actions: ({
64
- key: string;
65
- title: string;
66
- scope: "resource";
67
- panelKey?: undefined;
68
- } | {
69
- key: string;
70
- title: string;
71
- scope: "resource";
72
- panelKey: string;
73
- } | {
74
- key: string;
75
- title: string;
76
- scope: "item";
77
- panelKey?: undefined;
78
- })[];
79
- panels: {
80
- key: string;
81
- title: string;
82
- }[];
67
+ readonly actions: readonly [{
68
+ readonly key: "createFolder";
69
+ readonly title: "Create folder";
70
+ readonly scope: "resource";
71
+ }, {
72
+ readonly key: "lockFolder";
73
+ readonly title: "Lock folder";
74
+ readonly scope: "resource";
75
+ }, {
76
+ readonly key: "unlockFolder";
77
+ readonly title: "Unlock folder";
78
+ readonly scope: "resource";
79
+ }, {
80
+ readonly key: "upload";
81
+ readonly title: "Upload";
82
+ readonly scope: "resource";
83
+ readonly panelKey: "upload";
84
+ }, {
85
+ readonly key: "refresh";
86
+ readonly title: "Reload";
87
+ readonly scope: "resource";
88
+ }, {
89
+ readonly key: "update";
90
+ readonly title: "Update";
91
+ readonly scope: "item";
92
+ }, {
93
+ readonly key: "delete";
94
+ readonly title: "Delete";
95
+ readonly scope: "item";
96
+ }];
97
+ readonly panels: readonly [{
98
+ readonly key: "upload";
99
+ readonly title: "Upload assets";
100
+ }];
83
101
  }[];
84
102
  })[];
@@ -1,5 +1,5 @@
1
- import { PHI_SIGNAL_VALUE_SCHEMAS } from "../../../types/signals";
2
- import { PHI_ASSET_RUNTIME_DATA_PROVIDER_KEYS, PHI_ASSET_RUNTIME_ITEM_RENDERER_KEY } from "./ids";
1
+ import { PHI_MEDIA_LIBRARY_ASSET_RESOURCE } from "../../../components/media/media-library-resource";
2
+ import { PHI_ASSET_RUNTIME_DATA_PROVIDER_KEYS } from "./ids";
3
3
  import { PHI_ASSET_RUNTIME_MODULE_ID } from "./ids";
4
4
  /** The existing User and Group Spaces, one resource per kind, for the Admin storage table. */
5
5
  export const PHI_ASSET_STORAGE_SPACES_RESOURCES = [
@@ -92,35 +92,7 @@ export const PHI_ASSET_RUNTIME_DATA_PROVIDER_DESCRIPTORS = [
92
92
  // The Builder's own pickers read this regardless of whether the edited Area activates
93
93
  // this Module: a phis:asset reference resolves through the core resolver either way.
94
94
  availableToAuthoringChrome: true,
95
- resources: [
96
- {
97
- resourceKey: "assets",
98
- title: "Assets",
99
- itemIdentityPath: "id",
100
- itemRendererKey: PHI_ASSET_RUNTIME_ITEM_RENDERER_KEY,
101
- selectionValueSchema: PHI_SIGNAL_VALUE_SCHEMAS.mediaAssetSelection,
102
- defaultForWidget: true,
103
- query: {
104
- search: true,
105
- pagination: true,
106
- filterFields: [
107
- { key: "kind", title: "Kind", type: "enum[]" },
108
- { key: "presentationFlags", title: "Flags", type: "enum[]" },
109
- { key: "folderId", title: "Folder", type: "path" },
110
- ],
111
- },
112
- actions: [
113
- { key: "createFolder", title: "Create folder", scope: "resource" },
114
- // The Folder the listing is filtered to; Core refuses every change to what a locked one holds.
115
- { key: "lockFolder", title: "Lock folder", scope: "resource" },
116
- { key: "unlockFolder", title: "Unlock folder", scope: "resource" },
117
- { key: "upload", title: "Upload", scope: "resource", panelKey: "upload" },
118
- { key: "refresh", title: "Reload", scope: "resource" },
119
- { key: "update", title: "Update", scope: "item" },
120
- { key: "delete", title: "Delete", scope: "item" },
121
- ],
122
- panels: [{ key: "upload", title: "Upload assets" }],
123
- },
124
- ],
95
+ // The Foundation states the resource, because its Media preview grid hands it to the renderer too.
96
+ resources: [PHI_MEDIA_LIBRARY_ASSET_RESOURCE],
125
97
  },
126
98
  ];