@phis/ui 0.5.1 → 0.5.3

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 (195) hide show
  1. package/README.md +1 -1
  2. package/components/controls/phi-border-control.js +1 -1
  3. package/components/controls/phi-bound-radius-control.js +9 -9
  4. package/components/controls/phi-brand-control.js +1 -1
  5. package/components/controls/phi-drawer-control-adapter.js +4 -4
  6. package/components/controls/phi-dropdown-control.js +2 -2
  7. package/components/controls/phi-form-control.js +1 -1
  8. package/components/controls/phi-image-control.js +1 -1
  9. package/components/controls/phi-mask-picker-control.js +6 -6
  10. package/components/controls/phi-select-control.js +1 -1
  11. package/components/controls/phi-theme-scope-control.js +1 -1
  12. package/components/controls/use-phi-color-control-presets.js +2 -2
  13. package/components/forms/compound-form-controls.js +2 -2
  14. package/components/forms/extended-form-field-controls.js +1 -1
  15. package/components/forms/shared-form-provider-registry.js +2 -2
  16. package/components/layouts/clients/phi-flex-layout-client.js +4 -4
  17. package/components/layouts/clients/phi-grid-layout-client.js +3 -3
  18. package/components/layouts/clients/phi-sequence-slot-editor.js +1 -1
  19. package/components/layouts/layout-definitions.d.ts +4 -4
  20. package/components/layouts/phi-page-region-layout.js +1 -1
  21. package/components/layouts/phi-structure-region-layout.js +3 -3
  22. package/components/media/phi-asset-focal-rect-widget.js +4 -4
  23. package/components/media/phi-asset-inspector-section.js +1 -1
  24. package/components/media/phi-media-kind-icon.js +2 -2
  25. package/components/media/phi-media-restricted-icon.js +1 -1
  26. package/components/overlays/phi-overlay-container-client.js +1 -1
  27. package/components/regions/presets/phi-base-page-column.d.ts +5 -2
  28. package/components/regions/presets/phi-base-page-column.js +6 -2
  29. package/components/root/phi-config-provider.js +1 -1
  30. package/components/root/phi-root-background.js +1 -1
  31. package/components/root/phi-root-theme-resolver.js +1 -1
  32. package/components/shell/phi-module-icons.js +1 -1
  33. package/components/widgets/built-in/builder-workspace-preview.js +8 -8
  34. package/components/widgets/client/bullet-list-entries-editor.js +2 -2
  35. package/components/widgets/client/external-document-editor.js +1 -1
  36. package/components/widgets/client/html-editor.js +3 -3
  37. package/components/widgets/config/background.d.ts +1 -1
  38. package/components/widgets/config/background.js +1 -1
  39. package/components/widgets/inspector-field-row.js +1 -1
  40. package/components/widgets/label-sets/inspector.js +2 -0
  41. package/components/widgets/label-types/inspector.d.ts +1 -0
  42. package/components/widgets/label-types/inspector.js +1 -0
  43. package/components/widgets/shared/card-body-client.js +1 -1
  44. package/components/widgets/shared/result-body-client.js +1 -1
  45. package/constants/media-library-provider-keys.d.ts +8 -1
  46. package/constants/media-library-provider-keys.js +8 -1
  47. package/constants/record-field-kinds.d.ts +6 -0
  48. package/constants/record-field-kinds.js +7 -0
  49. package/constants/runtime-module-ownership.js +1 -1
  50. package/helpers/border-widget-style.d.ts +2 -2
  51. package/helpers/border-widget-style.js +2 -2
  52. package/helpers/cms-dialog.d.ts +4 -4
  53. package/helpers/cms-layout-defaults.d.ts +2 -2
  54. package/helpers/cms-page-catalog.d.ts +5 -0
  55. package/helpers/cms-preset-page-tree.d.ts +4 -0
  56. package/helpers/cms-preset-page-tree.js +2 -0
  57. package/helpers/cms-region-keys.d.ts +1 -1
  58. package/helpers/layout-style.d.ts +2 -2
  59. package/helpers/page-layout-check.d.ts +4 -1
  60. package/helpers/page-layout-check.js +26 -0
  61. package/helpers/record-fields.d.ts +9 -0
  62. package/helpers/record-fields.js +84 -0
  63. package/helpers/surface-presets.d.ts +6 -6
  64. package/helpers/surface-style.d.ts +1 -1
  65. package/helpers.d.ts +0 -1
  66. package/helpers.js +0 -2
  67. package/module-page-check.d.ts +12 -0
  68. package/module-page-check.js +12 -0
  69. package/module-records.d.ts +4 -2
  70. package/module-records.js +3 -1
  71. package/next/antd-form-context-loader.mjs +31 -0
  72. package/next/config.d.mts +2 -0
  73. package/next/config.mjs +36 -3
  74. package/package.json +10 -1
  75. package/plugins/runtime-modules/asset/data-providers.d.ts +0 -65
  76. package/plugins/runtime-modules/asset/data-providers.js +0 -40
  77. package/plugins/runtime-modules/asset/definition.d.ts +0 -60
  78. package/plugins/runtime-modules/asset/ids.d.ts +0 -1
  79. package/plugins/runtime-modules/asset/ids.js +1 -2
  80. package/plugins/runtime-modules/asset/presets.d.ts +1 -0
  81. package/plugins/runtime-modules/asset/server.js +0 -5
  82. package/plugins/runtime-modules/blog/presets.d.ts +1 -0
  83. package/plugins/runtime-modules/builder/clients/inspector-config-field.d.ts +4 -1
  84. package/plugins/runtime-modules/builder/clients/inspector-config-field.js +13 -4
  85. package/plugins/runtime-modules/builder/clients/inspector-link-target-field.js +1 -1
  86. package/plugins/runtime-modules/builder/clients/inspector-section-widget.js +14 -1
  87. package/plugins/runtime-modules/builder/clients/inspector-signal-section.js +2 -2
  88. package/plugins/runtime-modules/builder/clients/layout-inspector.js +1 -1
  89. package/plugins/runtime-modules/builder/clients/layout-scaffold-buttons.js +4 -4
  90. package/plugins/runtime-modules/builder/clients/layout-scaffold-overlays.js +1 -1
  91. package/plugins/runtime-modules/builder/clients/region-inspector.js +1 -1
  92. package/plugins/runtime-modules/builder/clients/region-visibility-fields.js +1 -1
  93. package/plugins/runtime-modules/builder/clients/shells-workspace.js +1 -1
  94. package/plugins/runtime-modules/builder/clients/structure-canvas.js +2 -2
  95. package/plugins/runtime-modules/builder/clients/widget-effects-editor.js +1 -1
  96. package/plugins/runtime-modules/builder/clients/widget-inspector.d.ts +4 -1
  97. package/plugins/runtime-modules/builder/clients/widget-inspector.js +3 -2
  98. package/plugins/runtime-modules/builder/page-presets.server.d.ts +6 -0
  99. package/plugins/runtime-modules/builder/page-presets.server.js +8 -0
  100. package/plugins/runtime-modules/builder/pages-workspace.js +12 -1
  101. package/plugins/runtime-modules/builder/render-root-node-scaffold.js +5 -5
  102. package/plugins/runtime-modules/builder/structure-dnd.js +2 -2
  103. package/plugins/runtime-modules/builder/widgets/test-block/client.js +1 -1
  104. package/plugins/runtime-modules/content-entry-routes.d.ts +1 -0
  105. package/plugins/runtime-modules/contracts.d.ts +1 -1
  106. package/plugins/runtime-modules/contracts.js +41 -1
  107. package/plugins/runtime-modules/core/data-providers.d.ts +60 -0
  108. package/plugins/runtime-modules/core/data-providers.js +41 -0
  109. package/plugins/runtime-modules/core/definition.d.ts +55 -0
  110. package/plugins/runtime-modules/core/server.js +5 -0
  111. package/plugins/runtime-modules/core/widgets/button/config.d.ts +34 -0
  112. package/plugins/runtime-modules/core/widgets/button/config.js +16 -0
  113. package/plugins/runtime-modules/core/widgets/button/plugin.js +37 -6
  114. package/plugins/runtime-modules/core/widgets/card/config.d.ts +13 -2
  115. package/plugins/runtime-modules/core/widgets/description/config.d.ts +13 -2
  116. package/plugins/runtime-modules/core/widgets/description/editor.js +13 -13
  117. package/plugins/runtime-modules/core/widgets/entry-list/config.d.ts +11 -0
  118. package/plugins/runtime-modules/core/widgets/gallery/client.d.ts +4 -1
  119. package/plugins/runtime-modules/core/widgets/gallery/client.js +29 -21
  120. package/plugins/runtime-modules/core/widgets/gallery/config.d.ts +16 -0
  121. package/plugins/runtime-modules/core/widgets/gallery/config.js +16 -0
  122. package/plugins/runtime-modules/core/widgets/gallery/server.d.ts +1 -1
  123. package/plugins/runtime-modules/core/widgets/gallery/server.js +11 -0
  124. package/plugins/runtime-modules/core/widgets/header-navigation/authoring.js +2 -3
  125. package/plugins/runtime-modules/core/widgets/header-navigation/client.d.ts +1 -3
  126. package/plugins/runtime-modules/core/widgets/header-navigation/client.js +9 -5
  127. package/plugins/runtime-modules/core/widgets/header-navigation/config.d.ts +1 -4
  128. package/plugins/runtime-modules/core/widgets/header-navigation/plugin.js +2 -3
  129. package/plugins/runtime-modules/core/widgets/header-navigation/server.d.ts +2 -2
  130. package/plugins/runtime-modules/core/widgets/header-navigation/server.js +1 -2
  131. package/plugins/runtime-modules/core/widgets/image/config.d.ts +35 -0
  132. package/plugins/runtime-modules/core/widgets/image/config.js +8 -0
  133. package/plugins/runtime-modules/core/widgets/image/plugin.js +19 -1
  134. package/plugins/runtime-modules/core/widgets/image/server.d.ts +3 -1
  135. package/plugins/runtime-modules/core/widgets/image/server.js +2 -2
  136. package/plugins/runtime-modules/core/widgets/markdown/config.d.ts +13 -0
  137. package/plugins/runtime-modules/core/widgets/markdown/config.js +8 -0
  138. package/plugins/runtime-modules/core/widgets/markdown/editor.js +7 -7
  139. package/plugins/runtime-modules/core/widgets/markdown/plugin.js +20 -7
  140. package/plugins/runtime-modules/core/widgets/record/authoring.js +1 -1
  141. package/plugins/runtime-modules/core/widgets/result/config.d.ts +11 -0
  142. package/plugins/runtime-modules/core/widgets/simple-text/config.d.ts +13 -0
  143. package/plugins/runtime-modules/core/widgets/simple-text/config.js +9 -0
  144. package/plugins/runtime-modules/core/widgets/simple-text/editor.js +1 -1
  145. package/plugins/runtime-modules/core/widgets/simple-text/plugin.js +14 -1
  146. package/plugins/runtime-modules/core/widgets/spacer/client.js +1 -1
  147. package/plugins/runtime-modules/core/widgets/table/config.d.ts +37 -0
  148. package/plugins/runtime-modules/descriptor-compiler.js +8 -0
  149. package/plugins/runtime-modules/editor/presets.d.ts +1 -0
  150. package/plugins/runtime-modules/groups/definition.d.ts +1 -1
  151. package/plugins/runtime-modules/localization/presets.d.ts +1 -0
  152. package/plugins/runtime-modules/news/presets.d.ts +1 -0
  153. package/plugins/runtime-modules/resolver.js +2 -0
  154. package/plugins/runtime-modules/revisions/presets.d.ts +1 -0
  155. package/plugins/runtime-modules/theme/presets.d.ts +1 -0
  156. package/plugins/runtime-modules/theme/widgets/brand-controls/client.js +37 -1
  157. package/server-helpers/cms-page-record.d.ts +26 -0
  158. package/server-helpers/cms-page-record.js +42 -0
  159. package/server-helpers/cms-request.js +48 -4
  160. package/server-helpers/record-fields.d.ts +62 -0
  161. package/server-helpers/record-fields.js +87 -0
  162. package/server-helpers/record-samples.d.ts +21 -0
  163. package/server-helpers/record-samples.js +41 -0
  164. package/styles/builder-scaffold.css +19 -19
  165. package/styles/controls.css +121 -108
  166. package/styles/gradients.css +23 -23
  167. package/styles/layout-affordances.css +15 -15
  168. package/styles/layout-authoring-scaffold.css +20 -20
  169. package/styles/layout.css +9 -9
  170. package/styles/root.css +4 -4
  171. package/styles/shell.css +48 -17
  172. package/theme/antd-css-var-contract.d.ts +93 -78
  173. package/theme/antd-css-var-contract.js +99 -79
  174. package/theme/phi-container-breakpoints.d.ts +4 -1
  175. package/theme/phi-container-breakpoints.js +4 -1
  176. package/theme/phi-control-shape.d.ts +1 -1
  177. package/theme/phi-theme-gradients.d.ts +2 -2
  178. package/theme/phi-theme-gradients.js +14 -14
  179. package/theme/phi-theme-palette.d.ts +1 -1
  180. package/theme/phi-theme-palette.js +2 -2
  181. package/theme/phi-theme-tokens.d.ts +10 -4
  182. package/theme/phi-theme-tokens.js +78 -23
  183. package/theme/phi-theme.d.ts +14 -0
  184. package/theme/phi-theme.js +14 -0
  185. package/theme/phi-tokens.d.ts +6 -1
  186. package/theme/phi-tokens.js +22 -2
  187. package/theme.d.ts +1 -1
  188. package/theme.js +1 -1
  189. package/types/cms-module-descriptors.d.ts +6 -0
  190. package/types/cms-plugins.d.ts +19 -1
  191. package/types/core-widget-placements.d.ts +10 -0
  192. package/types/record-provider.d.ts +92 -0
  193. package/types/widget-runtime.d.ts +5 -0
  194. /package/plugins/runtime-modules/{asset/services/folder-images.server.d.ts → core/services/media-folder-images.server.d.ts} +0 -0
  195. /package/plugins/runtime-modules/{asset/services/folder-images.server.js → core/services/media-folder-images.server.js} +0 -0
@@ -21,7 +21,10 @@ import { PHI_THEME_HEADING_FONT_VARIABLE, readPhiThemeHeadingFont, resolvePhiThe
21
21
  import { resolvePhiThemeRuntimePayload } from "../../../../../theme/phi-theme-runtime";
22
22
  import { resolvePhiAntdAliasTokens } from "../../../../../theme/phi-antd-token-resolver";
23
23
  import { buildPhiThemeStructuralTokens } from "../../../../../theme/phi-theme";
24
- import { PHI_CONTROL_HEIGHTS, PHI_PADDING, PHI_RADII, } from "../../../../../theme/phi-tokens";
24
+ import { PHI_CONTROL_HEIGHTS, PHI_LAYOUT, PHI_PADDING, PHI_RADII, } from "../../../../../theme/phi-tokens";
25
+ import { PHI_CONTAINER_BREAKPOINT_REGION } from "../../../../../theme/phi-container-breakpoints";
26
+ import { PHI_SPACE } from "../../../../../theme/antd-css-var-contract";
27
+ import { PHI_THEME_PAGE_PADDING_BANDS, PHI_THEME_PAGE_PADDING_SIDES } from "../../../../../theme/phi-theme-tokens";
25
28
  import { PHI_COLOR_PICKER_NEUTRAL_PRESETS, PHI_COLOR_PICKER_PRESETS } from "../../../../../components/widgets/config/color-picker-presets";
26
29
  import { PHI_SPACING_TOKEN_KEYS } from "../../../../../components/widgets/config/spacing-options";
27
30
  import { PhiColorFieldControl } from "../../../../../components/controls/phi-color-field-control";
@@ -41,6 +44,7 @@ import { PhiButtonControl } from "../../../../../components/controls/phi-button-
41
44
  import { PhiCheckboxControl } from "../../../../../components/controls/phi-checkbox-control";
42
45
  import { PhiLabeledControl } from "../../../../../components/controls/phi-labeled-control";
43
46
  import { PhiNumberControl } from "../../../../../components/controls/phi-number-control";
47
+ import { PhiPaddingControl } from "../../../../../components/controls/phi-padding-control";
44
48
  import { PhiColorControl } from "../../../../../components/controls/phi-color-control";
45
49
  import { PhiLinkTargetControl } from "../../../../../components/widgets/client/shared/phi-link-target-control";
46
50
  import { usePhiPageReferenceOptions } from "../../../../../components/widgets/client/shared/use-page-reference-options";
@@ -83,6 +87,8 @@ const BRAND_THEME_STYLE_SECTION_KEYS = [
83
87
  "fontFamily",
84
88
  "fontSize",
85
89
  "wireframe",
90
+ "pageWidth",
91
+ "pagePadding",
86
92
  ];
87
93
  /*
88
94
  * The shadow under each kind of Button (theme/phi-button-shadow.ts). "Theme" is no step at all -- the
@@ -1300,6 +1306,13 @@ export function PhiBuilderBrandStyleControlsWidgetClient({ runtime, config, }) {
1300
1306
  /** One row per size step: a label and the preset picker; Border Radius and Control Height share it. */
1301
1307
  const renderPresetSizeRows = (items, options) => (_jsx(PhiFlexControl, { vertical: true, gap: clientToken.paddingXS, children: items.map((item) => (_jsxs(PhiFlexControl, { align: "center", gap: clientToken.paddingSM, wrap: "nowrap", children: [_jsx(PhiTypographyControl, { style: { flex: `0 0 ${fieldLabelWidth}px` }, children: item.label }), _jsx(PhiPresetSizeControl, { value: item.value, fallbackKey: item.fallbackPreset, options: options, onChange: (value) => updateToken({ [item.key]: value }) })] }, item.key))) }));
1302
1308
  const wireframe = readEffectiveTokenBoolean(styleTokenInput, "wireframe", true);
1309
+ const pageMax = readEffectiveTokenNumber(styleTokenInput, "pageMax", PHI_LAYOUT.pageMax);
1310
+ const [pagePaddingBand, setPagePaddingBand] = useState("Phone");
1311
+ const pagePaddingDefault = PHI_SPACE[PHI_LAYOUT.pagePadding[pagePaddingBand.toLowerCase()]];
1312
+ const pagePadding = Object.fromEntries(PHI_THEME_PAGE_PADDING_SIDES.map((side) => [
1313
+ `padding${side}`,
1314
+ readEffectiveTokenString(styleTokenInput, `pagePadding${side}${pagePaddingBand}`, pagePaddingDefault),
1315
+ ]));
1303
1316
  const baseFontSize = readEffectiveTokenNumber(styleTokenInput, "fontSize", 12);
1304
1317
  function updateToken(tokenPatch) {
1305
1318
  publishDraft(mergeThemeToken(state.draft, tokenPatch));
@@ -1409,6 +1422,29 @@ export function PhiBuilderBrandStyleControlsWidgetClient({ runtime, config, }) {
1409
1422
  label: _jsx(PhiTypographyControl, { strong: true, children: "Wireframe" }),
1410
1423
  children: (_jsxs(PhiFlexControl, { align: "center", justify: "space-between", gap: clientToken.paddingSM, wrap: "wrap", children: [_jsx(PhiTypographyControl, { type: "secondary", children: "Dividing lines in dialogs and popovers, outlined steps and radios" }), _jsx(PhiSwitchControl, { checked: wireframe, checkedLabel: "On", uncheckedLabel: "Off", onChange: (checked) => updateToken({ wireframe: checked }) })] })),
1411
1424
  },
1425
+ {
1426
+ /*
1427
+ * How wide a Page may get (`PHI_PAGE.max`). Never below the width from which a Region counts
1428
+ * as wide: a narrower Page could never be wide, and the Theme refuses one when it is saved.
1429
+ * Emptied, the Theme says nothing and the house default stands.
1430
+ */
1431
+ key: "pageWidth",
1432
+ label: _jsx(PhiTypographyControl, { strong: true, children: "Page Width" }),
1433
+ children: (_jsxs(PhiFlexControl, { vertical: true, gap: clientToken.paddingXS, children: [_jsxs(PhiFlexControl, { align: "center", gap: clientToken.paddingSM, wrap: "nowrap", children: [_jsx(PhiTypographyControl, { style: { flex: `0 0 ${fieldLabelWidth}px` }, children: "Maximum" }), _jsx(PhiNumberControl, { prefix: "px", value: pageMax, step: 1, min: PHI_CONTAINER_BREAKPOINT_REGION, onChange: (next) => updateToken({ pageMax: next == null ? undefined : next }) })] }), _jsxs(PhiTypographyControl, { type: "secondary", children: ["How wide a Page gets on a wide screen. At least ", PHI_CONTAINER_BREAKPOINT_REGION, "px, the width from which a Region counts as wide."] })] })),
1434
+ },
1435
+ {
1436
+ /*
1437
+ * How far a Page's content stands in (`PHI_PAGE.padding`), per side and per screen: a phone
1438
+ * below 768, a tablet below 1200, a desktop from there. Only the default of the Page column
1439
+ * the presets and packages build; a Layout that states its own padding keeps it.
1440
+ */
1441
+ key: "pagePadding",
1442
+ label: _jsx(PhiTypographyControl, { strong: true, children: "Page Padding" }),
1443
+ children: (_jsxs(PhiFlexControl, { vertical: true, gap: clientToken.paddingXS, children: [_jsx(PhiSegmentedControl, { value: pagePaddingBand, options: PHI_THEME_PAGE_PADDING_BANDS.map((band) => ({ value: band, label: band })), onChange: setPagePaddingBand }), _jsx(PhiPaddingControl, { value: pagePadding, showGap: false, onChange: (next) => updateToken(Object.fromEntries(PHI_THEME_PAGE_PADDING_SIDES.map((side) => {
1444
+ const value = next?.[`padding${side}`] ?? next?.padding;
1445
+ return [`pagePadding${side}${pagePaddingBand}`, value == null ? undefined : value];
1446
+ }))) }), _jsx(PhiTypographyControl, { type: "secondary", children: "The default of a Page that does not set its own: a phone below 768px, a tablet below 1200px." })] })),
1447
+ },
1412
1448
  ] }) })] }));
1413
1449
  }
1414
1450
  /**
@@ -0,0 +1,26 @@
1
+ import "server-only";
2
+ import type { PhiBlockRuntime } from "../types";
3
+ import type { PhiCmsRoutePresetBinding } from "../types/cms-module-descriptors";
4
+ import type { PhiRuntimeModuleCatalog, PhiRuntimeModuleId } from "../types/cms-plugins";
5
+ import type { PhiRuntimeDataProviderBinding } from "../types/runtime-data-provider";
6
+ /**
7
+ * The record a route's Page is about, read before anything is drawn (MODULES.md, "The fields of a record,
8
+ * and the record a Page is about").
9
+ *
10
+ * `missing` is an address that names no record: the caller answers 404. An unavailable Provider is not
11
+ * that -- the Page is drawn, its Widgets say what they could not read, and the title stays the route's.
12
+ */
13
+ export type PhiCmsPageRecord = {
14
+ status: "missing";
15
+ } | {
16
+ status: "ok";
17
+ binding: PhiRuntimeDataProviderBinding;
18
+ title: string | null;
19
+ description: string | null;
20
+ };
21
+ export declare function resolvePhiCmsPageRecord({ binding, runtime, runtimeModuleCatalog, activeModuleIds }: {
22
+ binding: PhiCmsRoutePresetBinding;
23
+ runtime: PhiBlockRuntime;
24
+ runtimeModuleCatalog: PhiRuntimeModuleCatalog;
25
+ activeModuleIds: ReadonlySet<PhiRuntimeModuleId>;
26
+ }): Promise<PhiCmsPageRecord | null>;
@@ -0,0 +1,42 @@
1
+ import "server-only";
2
+ import { readPhiPageRecordField, resolvePhiRecordFields } from "./record-fields";
3
+ import { resolvePhiRecordSource } from "./record-source";
4
+ /** What the record Providers of the active Modules offer, as a render's registry holds it. */
5
+ function buildRecordRegistry(runtimeModuleCatalog, activeModuleIds) {
6
+ const entries = [...activeModuleIds].flatMap((moduleId) => {
7
+ const entry = runtimeModuleCatalog.get(moduleId);
8
+ return entry ? [entry] : [];
9
+ });
10
+ return {
11
+ recordProviderLoadersByKey: new Map(entries.flatMap((entry) => (entry.recordProviders ?? []).map((provider) => [provider.key, provider.load]))),
12
+ recordFieldsLoadersByKey: new Map(entries.flatMap((entry) => (entry.recordProviders ?? []).flatMap((provider) => provider.loadFields ? [[provider.key, provider.loadFields]] : []))),
13
+ dataProviderDescriptorsByKey: new Map(entries.flatMap((entry) => (entry.definition.dataProviders ?? []).map((provider) => [provider.key, provider]))),
14
+ };
15
+ }
16
+ export async function resolvePhiCmsPageRecord({ binding, runtime, runtimeModuleCatalog, activeModuleIds }) {
17
+ const declaration = binding.descriptor.pageRecord;
18
+ if (!declaration) {
19
+ return null;
20
+ }
21
+ const route = `${binding.descriptor.ownerModuleId}/${binding.descriptor.presetKey}`;
22
+ const registry = buildRecordRegistry(runtimeModuleCatalog, activeModuleIds);
23
+ const descriptor = registry.dataProviderDescriptorsByKey.get(declaration.providerKey);
24
+ if (descriptor?.kind !== "record" || !descriptor.record) {
25
+ throw new Error(`${route}: its page record names "${declaration.providerKey}", which is no active record Provider with declared fields.`);
26
+ }
27
+ // A Public page is rendered once for everybody, so it cannot be about what only one account may read.
28
+ if (descriptor.record.audience === "viewer" && binding.descriptor.area === "public") {
29
+ throw new Error(`${route}: a Public route cannot be about a record of audience "viewer".`);
30
+ }
31
+ const record = {
32
+ providerKey: declaration.providerKey,
33
+ params: Object.fromEntries(Object.entries(declaration.params).map(([name, routeParam]) => [name, binding.params[routeParam] ?? ""])),
34
+ };
35
+ const source = await resolvePhiRecordSource({ registry, runtime, binding: record });
36
+ if (source.status === "missing") {
37
+ return { status: "missing" };
38
+ }
39
+ const fields = await resolvePhiRecordFields({ registry, runtime, binding: record });
40
+ const text = (key) => readPhiPageRecordField(fields, key, ["text"])?.value.trim() || null;
41
+ return { status: "ok", binding: record, title: text(declaration.titleField), description: text(declaration.descriptionField) };
42
+ }
@@ -1,5 +1,6 @@
1
1
  import "server-only";
2
2
  import { cache } from "react";
3
+ import { notFound } from "next/navigation";
3
4
  import { resolvePhiCmsAreaKey, resolvePhiCmsAreaMask, } from "../constants/cms-areas";
4
5
  import { canPhiViewerAccess } from "../types/access";
5
6
  import { compilePhiCmsActiveRouteTable, instantiatePhiCmsRoutePreset, normalizePhiCmsRoutePath, resolvePhiCmsAreaShellPresetBinding, resolvePhiCmsDescriptorCatalog, resolvePhiCmsRoutePreset, } from "../plugins/runtime-modules/descriptor-compiler";
@@ -14,6 +15,7 @@ import { logRuntimeEvent } from "../net/log";
14
15
  import { getPhiCmsPage, getPhiExactSiteArea } from "./cms";
15
16
  import { buildPhiLocalCmsAreaPayload } from "./cms-area";
16
17
  import { applyPhiPresetTreePublishedContent } from "./cms-bound-content";
18
+ import { resolvePhiCmsPageRecord } from "./cms-page-record";
17
19
  import { resolvePhiAreaPageReferencePath, resolvePhiAreaRootRouteDecision } from "./area-root-route";
18
20
  import { fetchSiteNavigationFolderTarget } from "../gateway/site-nav";
19
21
  import { applyPhiAreaRootRouteDecision, buildPhiFolderAddressRedirectPage } from "../helpers/cms-area-root-route";
@@ -134,7 +136,25 @@ function mapResolvedPageToRequestedContext(pagePayload, areaMask, path) {
134
136
  },
135
137
  };
136
138
  }
137
- function buildPhiRuntimePage(pagePayload) {
139
+ /** The record's own title and description on the Page; `msgId: 0`, because they are no Site message. */
140
+ function applyPhiPageRecordMeta(pagePayload, record) {
141
+ if (!record.title && !record.description) {
142
+ return pagePayload;
143
+ }
144
+ const field = (value) => ({ msgId: 0, source: value, value });
145
+ const pageMeta = pagePayload.page.pageMeta;
146
+ return {
147
+ ...pagePayload,
148
+ page: {
149
+ ...pagePayload.page,
150
+ pageMeta: {
151
+ title: record.title ? field(record.title) : pageMeta?.title ?? null,
152
+ description: record.description ? field(record.description) : pageMeta?.description ?? null,
153
+ },
154
+ },
155
+ };
156
+ }
157
+ function buildPhiRuntimePage(pagePayload, record) {
138
158
  const pageMeta = pagePayload.page.pageMeta;
139
159
  return {
140
160
  path: pagePayload.page.page.path,
@@ -144,6 +164,7 @@ function buildPhiRuntimePage(pagePayload) {
144
164
  title: pageMeta?.title?.value ?? null,
145
165
  description: pageMeta?.description?.value ?? null,
146
166
  noindex: hasPhiFlag(pagePayload.page.page.flags, PhiCmsFlags.NoIndex),
167
+ ...(record ? { record } : {}),
147
168
  };
148
169
  }
149
170
  export async function resolvePhiCmsRequest({ siteKey, locale, area, path, cookieHeader, apiBaseUrl, internalToken, requestContext, searchParams, loadResolvedCmsPage, loadExactCmsArea, runtimeModuleCatalog, purpose = "render", }) {
@@ -232,6 +253,29 @@ export async function resolvePhiCmsRequest({ siteKey, locale, area, path, cookie
232
253
  activeModuleKeys,
233
254
  }),
234
255
  });
256
+ /*
257
+ * The record the Page is about, where its route names one: read once, here, for the Module's own tree
258
+ * and for a stored override of it alike -- the override holds no address, only Widgets bound to the
259
+ * record's fields. A Page stored at this exact address is its own and about no record. An address that
260
+ * names no record is no Page: a 404 while rendering, nothing for a lookup.
261
+ */
262
+ const routeIsParametrised = routeBinding ? Object.keys(routeBinding.params).length > 0 : false;
263
+ const routePresetAnswered = loadedPage?.sourcePreset?.presetKey === routeBinding?.descriptor.presetKey
264
+ && loadedPage?.sourcePreset?.ownerModuleId === routeBinding?.descriptor.ownerModuleId;
265
+ const pageRecord = loadedPage && routeBinding && routeIsParametrised && routePresetAnswered
266
+ ? await resolvePhiCmsPageRecord({
267
+ binding: routeBinding,
268
+ runtime: runtimeWithAuthProvider,
269
+ runtimeModuleCatalog,
270
+ activeModuleIds: activeModuleKeys,
271
+ })
272
+ : null;
273
+ if (pageRecord?.status === "missing") {
274
+ if (purpose === "lookup") {
275
+ return null;
276
+ }
277
+ notFound();
278
+ }
235
279
  /*
236
280
  * The Area root, as the Builder configured it.
237
281
  *
@@ -294,13 +338,13 @@ export async function resolvePhiCmsRequest({ siteKey, locale, area, path, cookie
294
338
  const effectivePage = resolvedPage
295
339
  ? mapResolvedPageToRequestedContext(resolvedPage, areaMask, path)
296
340
  : null;
297
- const resolvedContent = effectivePage;
298
- if (!resolvedContent) {
341
+ if (!effectivePage) {
299
342
  return null;
300
343
  }
344
+ const resolvedContent = pageRecord ? applyPhiPageRecordMeta(effectivePage, pageRecord) : effectivePage;
301
345
  const resolvedRuntime = {
302
346
  ...runtimeWithAuthProvider,
303
- page: buildPhiRuntimePage(resolvedContent),
347
+ page: buildPhiRuntimePage(resolvedContent, pageRecord?.binding),
304
348
  };
305
349
  if (purpose === "lookup") {
306
350
  return {
@@ -0,0 +1,62 @@
1
+ import "server-only";
2
+ import type { PhiBlockRuntime } from "../types";
3
+ import type { PhiCmsRuntimeRenderRegistry } from "../types/cms-plugins";
4
+ import type { PhiRecordField, PhiRecordFieldKind } from "../types/record-provider";
5
+ import type { PhiRuntimeDataProviderBinding } from "../types/runtime-data-provider";
6
+ type PhiRecordFieldsRegistry = Pick<PhiCmsRuntimeRenderRegistry, "recordProviderLoadersByKey" | "recordFieldsLoadersByKey" | "dataProviderDescriptorsByKey">;
7
+ /**
8
+ * The declared fields of one record (MODULES.md, "The fields of a record, and the record a Page is about").
9
+ *
10
+ * `none` is a Page that is about no record, or a binding to a Provider that declares no fields: a Widget
11
+ * bound to a field there has nothing to show and is not at fault. `missing` and `unavailable` are the
12
+ * record's own two failures, as `resolvePhiRecordSource` tells them apart.
13
+ */
14
+ export type PhiPageRecordFieldsResult = {
15
+ status: "ok";
16
+ fields: ReadonlyMap<string, PhiRecordField>;
17
+ } | {
18
+ status: "none";
19
+ } | {
20
+ status: "missing";
21
+ } | {
22
+ status: "unavailable";
23
+ reason: string;
24
+ };
25
+ /** The declared fields of the record a binding names, read once per request for the same record. */
26
+ export declare function resolvePhiRecordFields({ registry, runtime, binding }: {
27
+ registry: PhiRecordFieldsRegistry;
28
+ runtime: PhiBlockRuntime;
29
+ binding: PhiRuntimeDataProviderBinding | null | undefined;
30
+ }): Promise<PhiPageRecordFieldsResult>;
31
+ /** The declared fields of the record this Page is about (`runtime.page.record`). */
32
+ export declare function resolvePhiPageRecordFields({ registry, runtime }: {
33
+ registry: PhiRecordFieldsRegistry;
34
+ runtime: PhiBlockRuntime;
35
+ }): Promise<PhiPageRecordFieldsResult>;
36
+ /** One field of a result, if the record has it and it is of one of the kinds asked for. */
37
+ export declare function readPhiPageRecordField<K extends PhiRecordFieldKind>(result: PhiPageRecordFieldsResult, key: string | null | undefined, kinds: readonly K[]): Extract<PhiRecordField, {
38
+ kind: K;
39
+ }> | null;
40
+ /**
41
+ * What a Widget that names a field of the page record is to draw.
42
+ *
43
+ * `bound: false` is a Widget that names none, or a Page that is about no record -- a template open in the
44
+ * Builder, a Widget copied to an ordinary Page: it draws its own content, which stands in for the field.
45
+ * `bound: true` with no field is a record that does not have it, and the Widget draws nothing of its own
46
+ * in its place.
47
+ */
48
+ export type PhiWidgetRecordField<K extends PhiRecordFieldKind> = {
49
+ bound: false;
50
+ } | {
51
+ bound: true;
52
+ field: Extract<PhiRecordField, {
53
+ kind: K;
54
+ }> | null;
55
+ };
56
+ export declare function resolvePhiWidgetRecordField<K extends PhiRecordFieldKind>({ registry, runtime, key, kinds }: {
57
+ registry: PhiRecordFieldsRegistry | undefined;
58
+ runtime: PhiBlockRuntime;
59
+ key: string | null | undefined;
60
+ kinds: readonly K[];
61
+ }): Promise<PhiWidgetRecordField<K>>;
62
+ export {};
@@ -0,0 +1,87 @@
1
+ import "server-only";
2
+ import { logRuntimeEvent } from "../net/log";
3
+ import { readPhiRecordFieldValue } from "../helpers/record-fields";
4
+ import { phiRuntime } from "./phi-runtime";
5
+ import { resolvePhiRecordSource } from "./record-source";
6
+ import { definePhiRequestMemoWith } from "./request-memo";
7
+ const resolveFields = definePhiRequestMemoWith(async (key, using) => {
8
+ const providerKey = key.providerKey;
9
+ const descriptor = using.registry.dataProviderDescriptorsByKey.get(providerKey);
10
+ const declared = descriptor?.kind === "record" ? descriptor.record?.fields : undefined;
11
+ const loadFields = using.registry.recordFieldsLoadersByKey.get(providerKey);
12
+ if (!declared || !loadFields) {
13
+ return { status: "none" };
14
+ }
15
+ const source = await resolvePhiRecordSource({
16
+ registry: using.registry,
17
+ runtime: using.runtime,
18
+ binding: { providerKey, params: key.params },
19
+ });
20
+ if (source.status !== "ok") {
21
+ return source;
22
+ }
23
+ try {
24
+ const read = await loadFields();
25
+ const values = await read(source.record, {
26
+ apiBaseUrl: using.apiBaseUrl,
27
+ internalToken: using.internalToken,
28
+ siteKey: key.siteKey,
29
+ locale: key.locale,
30
+ runtime: using.runtime,
31
+ });
32
+ const fields = new Map();
33
+ for (const field of declared) {
34
+ const raw = values[field.key];
35
+ if (raw === undefined || raw === null)
36
+ continue;
37
+ const value = readPhiRecordFieldValue(field.kind, raw);
38
+ if (value === undefined) {
39
+ logRuntimeEvent("warn", "cms.record.field_invalid", {
40
+ message: `Record provider "${key.providerKey}" answered field "${field.key}" with a value that is no ${field.kind}.`,
41
+ siteKey: key.siteKey,
42
+ area: using.runtime.area,
43
+ meta: { providerKey: key.providerKey, field: field.key, kind: field.kind },
44
+ });
45
+ continue;
46
+ }
47
+ fields.set(field.key, { kind: field.kind, value });
48
+ }
49
+ return { status: "ok", fields };
50
+ }
51
+ catch (error) {
52
+ logRuntimeEvent("error", "cms.record.fields_failed", {
53
+ message: `Failed to read the fields of record provider "${key.providerKey}" for this render.`,
54
+ siteKey: key.siteKey,
55
+ area: using.runtime.area,
56
+ error,
57
+ meta: { providerKey: key.providerKey },
58
+ });
59
+ return { status: "unavailable", reason: error instanceof Error ? error.message : String(error) };
60
+ }
61
+ });
62
+ /** The declared fields of the record a binding names, read once per request for the same record. */
63
+ export function resolvePhiRecordFields({ registry, runtime, binding }) {
64
+ if (!binding) {
65
+ return Promise.resolve({ status: "none" });
66
+ }
67
+ const rt = phiRuntime(runtime);
68
+ return resolveFields({ providerKey: binding.providerKey, params: binding.params ?? {}, siteKey: rt.siteKey, locale: runtime.locale.current }, { registry, runtime, apiBaseUrl: rt.apiBaseUrl, internalToken: rt.internalToken });
69
+ }
70
+ /** The declared fields of the record this Page is about (`runtime.page.record`). */
71
+ export function resolvePhiPageRecordFields({ registry, runtime }) {
72
+ return resolvePhiRecordFields({ registry, runtime, binding: runtime.page?.record });
73
+ }
74
+ /** One field of a result, if the record has it and it is of one of the kinds asked for. */
75
+ export function readPhiPageRecordField(result, key, kinds) {
76
+ if (result.status !== "ok" || !key)
77
+ return null;
78
+ const field = result.fields.get(key);
79
+ return field && kinds.includes(field.kind) ? field : null;
80
+ }
81
+ export async function resolvePhiWidgetRecordField({ registry, runtime, key, kinds }) {
82
+ if (!key || !registry) {
83
+ return { bound: false };
84
+ }
85
+ const result = await resolvePhiPageRecordFields({ registry, runtime });
86
+ return result.status === "none" ? { bound: false } : { bound: true, field: readPhiPageRecordField(result, key, kinds) };
87
+ }
@@ -0,0 +1,21 @@
1
+ import "server-only";
2
+ import type { PhiBlockRuntime } from "../types";
3
+ import type { PhiCmsRuntimeRenderRegistry } from "../types/cms-plugins";
4
+ import type { PhiCmsPageRecordDescriptor } from "../types/record-provider";
5
+ import type { PhiRuntimeDataProviderBinding } from "../types/runtime-data-provider";
6
+ type PhiRecordSamplesRegistry = Pick<PhiCmsRuntimeRenderRegistry, "recordSamplesLoadersByKey">;
7
+ /**
8
+ * The record the Builder's Preview shows a template with (MODULES.md, "The fields of a record, and the
9
+ * record a Page is about"): the first sample the route's record Provider offers, as the binding a Page
10
+ * about a record carries.
11
+ *
12
+ * A sample's `params` are the Provider's own parameters (`{ slug: "chair" }`), not the route's, so they
13
+ * become the binding as they are. `null` is a Provider that offers no samples or none now, or one whose
14
+ * reader fails: the template then previews with its Widgets' own content, as it does in the Editor.
15
+ */
16
+ export declare function resolvePhiPageRecordSampleBinding({ registry, runtime, pageRecord }: {
17
+ registry: PhiRecordSamplesRegistry;
18
+ runtime: PhiBlockRuntime;
19
+ pageRecord: PhiCmsPageRecordDescriptor;
20
+ }): Promise<PhiRuntimeDataProviderBinding | null>;
21
+ export {};
@@ -0,0 +1,41 @@
1
+ import "server-only";
2
+ import { logRuntimeEvent } from "../net/log";
3
+ import { phiRuntime } from "./phi-runtime";
4
+ /**
5
+ * The record the Builder's Preview shows a template with (MODULES.md, "The fields of a record, and the
6
+ * record a Page is about"): the first sample the route's record Provider offers, as the binding a Page
7
+ * about a record carries.
8
+ *
9
+ * A sample's `params` are the Provider's own parameters (`{ slug: "chair" }`), not the route's, so they
10
+ * become the binding as they are. `null` is a Provider that offers no samples or none now, or one whose
11
+ * reader fails: the template then previews with its Widgets' own content, as it does in the Editor.
12
+ */
13
+ export async function resolvePhiPageRecordSampleBinding({ registry, runtime, pageRecord }) {
14
+ const loadSamples = registry.recordSamplesLoadersByKey.get(pageRecord.providerKey);
15
+ if (!loadSamples) {
16
+ return null;
17
+ }
18
+ const rt = phiRuntime(runtime);
19
+ try {
20
+ const read = await loadSamples();
21
+ const samples = await read({
22
+ apiBaseUrl: rt.apiBaseUrl,
23
+ internalToken: rt.internalToken,
24
+ siteKey: rt.siteKey,
25
+ locale: runtime.locale.current,
26
+ runtime,
27
+ });
28
+ const sample = samples[0];
29
+ return sample ? { providerKey: pageRecord.providerKey, params: sample.params } : null;
30
+ }
31
+ catch (error) {
32
+ logRuntimeEvent("warn", "cms.record.samples_failed", {
33
+ message: `Failed to read the samples of record provider "${pageRecord.providerKey}" for the Preview.`,
34
+ siteKey: rt.siteKey,
35
+ area: runtime.area,
36
+ error,
37
+ meta: { providerKey: pageRecord.providerKey },
38
+ });
39
+ return null;
40
+ }
41
+ }
@@ -82,46 +82,46 @@
82
82
  }
83
83
 
84
84
  :where(.phi-builder-structure-region__slot[data-phi-builder-region-mode="editor"][data-phi-region-slot]) {
85
- border: 1px dashed var(--ant-color-border-secondary);
85
+ border: 1px dashed var(--phi-color-border-secondary);
86
86
  /* Half-transparent: an unauthored Region has no ground, and the Theme Root Background stays visible. */
87
- background: color-mix(in srgb, var(--ant-color-bg-container) 50%, transparent);
88
- box-shadow: inset 0 0 0 1px var(--ant-color-border-secondary);
87
+ background: color-mix(in srgb, var(--phi-color-bg-container) 50%, transparent);
88
+ box-shadow: inset 0 0 0 1px var(--phi-color-border-secondary);
89
89
  padding: 0;
90
90
  gap: 0;
91
91
  cursor: pointer;
92
92
  }
93
93
 
94
94
  :where(.phi-builder-structure-region__slot[data-phi-builder-region-mode="editor"]:not([data-phi-region-slot])) {
95
- padding: var(--ant-padding-xs);
96
- gap: var(--ant-padding-xs);
95
+ padding: var(--phi-padding-xs);
96
+ gap: var(--phi-padding-xs);
97
97
  cursor: pointer;
98
98
  }
99
99
 
100
100
  :where(.phi-builder-structure-region__slot[data-phi-builder-region-mode="editor"][data-phi-region-slot][data-phi-builder-region-selected="true"]) {
101
- border-color: var(--ant-color-primary);
102
- box-shadow: inset 0 0 0 1px var(--ant-color-primary);
101
+ border-color: var(--phi-color-primary);
102
+ box-shadow: inset 0 0 0 1px var(--phi-color-primary);
103
103
  }
104
104
 
105
105
  :where(.phi-builder-structure-region__slot[data-phi-builder-region-mode="editor"][data-phi-region-slot][data-phi-builder-region-picking="true"]) {
106
- border-color: var(--ant-color-primary);
107
- background: var(--ant-color-fill-quaternary);
108
- box-shadow: inset 0 0 0 1px var(--ant-color-primary);
106
+ border-color: var(--phi-color-primary);
107
+ background: var(--phi-color-fill-quaternary);
108
+ box-shadow: inset 0 0 0 1px var(--phi-color-primary);
109
109
  }
110
110
 
111
111
  :where(.phi-builder-structure-region__slot[data-phi-builder-region-mode="editor"][data-phi-region-slot][data-phi-structure-drop-state="accepted"]) {
112
- border-color: var(--ant-color-success) !important;
113
- background: var(--ant-color-success-bg) !important;
114
- box-shadow: inset 0 0 0 2px var(--ant-color-success) !important;
112
+ border-color: var(--phi-color-success) !important;
113
+ background: var(--phi-color-success-bg) !important;
114
+ box-shadow: inset 0 0 0 2px var(--phi-color-success) !important;
115
115
  }
116
116
 
117
117
  :where(.phi-builder-structure-region__slot[data-phi-builder-region-mode="editor"][data-phi-region-slot][data-phi-structure-drop-state="rejected"]) {
118
- border-color: var(--ant-color-error) !important;
119
- background: var(--ant-color-error-bg) !important;
120
- box-shadow: inset 0 0 0 2px var(--ant-color-error) !important;
118
+ border-color: var(--phi-color-error) !important;
119
+ background: var(--phi-color-error-bg) !important;
120
+ box-shadow: inset 0 0 0 2px var(--phi-color-error) !important;
121
121
  }
122
122
 
123
123
  :where(.phi-builder-structure-region__slot[data-phi-builder-region-mode="preview"][data-phi-region-slot]) {
124
- border: 1px dashed var(--ant-color-border-secondary);
124
+ border: 1px dashed var(--phi-color-border-secondary);
125
125
  /* Preview mirrors the live Shell, where an unauthored Region is transparent. */
126
126
  background: transparent;
127
127
  box-shadow: none;
@@ -140,7 +140,7 @@
140
140
  }
141
141
 
142
142
  :where(.phi-builder-workspace-region-scaffold) {
143
- --phi-builder-region-padding: var(--ant-padding-xs);
143
+ --phi-builder-region-padding: var(--phi-padding-xs);
144
144
  }
145
145
 
146
146
  :where(.phi-builder-structure-region--full-height) {
@@ -280,7 +280,7 @@
280
280
  gap: 8px;
281
281
  min-width: 0;
282
282
  min-height: 0;
283
- padding: var(--ant-padding-sm);
283
+ padding: var(--phi-padding-sm);
284
284
  box-sizing: border-box;
285
285
  pointer-events: none;
286
286
  }