@phis/ui 0.5.5 → 0.5.6

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 (42) hide show
  1. package/components/controls/phi-anchor-nav-control.js +18 -1
  2. package/components/widgets/shared/card-body-client.d.ts +6 -2
  3. package/components/widgets/shared/card-body-client.js +27 -20
  4. package/components/widgets/shared/card-vocabulary.d.ts +7 -0
  5. package/components/widgets/shared/card-vocabulary.js +6 -0
  6. package/components/widgets/shared/markdown-body-client.js +7 -2
  7. package/constants/module-identity.d.ts +8 -0
  8. package/constants/module-identity.js +13 -0
  9. package/gateway/server-module-media.d.ts +12 -0
  10. package/gateway/server-module-media.js +83 -0
  11. package/helpers/cms-navigation-catalog.js +4 -1
  12. package/helpers/cms-page-catalog.d.ts +7 -0
  13. package/helpers/cms-preset-page-tree.js +16 -1
  14. package/helpers/module-media-check.d.ts +23 -0
  15. package/helpers/module-media-check.js +32 -0
  16. package/helpers/module-media.d.ts +7 -0
  17. package/helpers/module-media.js +15 -0
  18. package/helpers/route-address-check.d.ts +35 -0
  19. package/helpers/route-address-check.js +28 -0
  20. package/module-page-check.d.ts +2 -0
  21. package/module-page-check.js +2 -0
  22. package/package.json +1 -1
  23. package/plugins/runtime-modules/builder/area-shell-presets.server.js +2 -0
  24. package/plugins/runtime-modules/builder/navigation-folder-drop.js +2 -1
  25. package/plugins/runtime-modules/builder/options-providers.js +7 -1
  26. package/plugins/runtime-modules/builder/page-presets.server.js +2 -0
  27. package/plugins/runtime-modules/core/widgets/breadcrumb/server.js +9 -2
  28. package/plugins/runtime-modules/core/widgets/card/config.d.ts +7 -1
  29. package/plugins/runtime-modules/core/widgets/card/config.js +19 -2
  30. package/plugins/runtime-modules/core/widgets/card/editor.js +2 -0
  31. package/plugins/runtime-modules/core/widgets/card/server.js +2 -0
  32. package/plugins/runtime-modules/descriptor-compiler.d.ts +23 -3
  33. package/plugins/runtime-modules/descriptor-compiler.js +107 -12
  34. package/server-helpers/cms-area.js +9 -1
  35. package/server-helpers/cms-request.js +15 -2
  36. package/server-helpers/cms-root.js +2 -0
  37. package/server-helpers/module-folder-targets.d.ts +7 -0
  38. package/server-helpers/module-folder-targets.js +15 -0
  39. package/types/cms-module-descriptors.d.ts +24 -0
  40. package/types/module-media.d.ts +31 -0
  41. package/types/module-media.js +11 -0
  42. package/types.d.ts +1 -0
@@ -1,6 +1,7 @@
1
1
  /** A Page the Navigation can point at: it has a stable reference and has not been deleted. */
2
2
  export function isPhiBuilderNavigablePage(node) {
3
- return Boolean(node.reference) && node.tombstoned !== true;
3
+ // A list's entries are no Page a link can name (`routeParameter`): a link names one entry.
4
+ return Boolean(node.reference) && node.tombstoned !== true && !node.routeParameter;
4
5
  }
5
6
  /** Whether a catalog node would give the Navigation anything: a live Page, or one somewhere beneath it. */
6
7
  export function hasPhiBuilderNavigableContent(node) {
@@ -20,6 +20,9 @@ function resolveProviderArea(context) {
20
20
  ? context.optionsProvider.area
21
21
  : builderArea;
22
22
  }
23
+ function humanizeRouteParameter(name) {
24
+ return name.charAt(0).toUpperCase() + name.slice(1);
25
+ }
23
26
  function collectPageOptions(area, nodes) {
24
27
  return nodes.flatMap((node) => {
25
28
  /*
@@ -44,11 +47,14 @@ function collectPageOptions(area, nodes) {
44
47
  * by an author, and either way it hides where the Page answers: "Zz Nw Test" is `/zz-nw-test`.
45
48
  */
46
49
  const address = node.storagePath ?? path;
50
+ // A list's entries are a kind, not one Page: named so beside their pattern, `Slug · /blog/:slug`.
51
+ const description = node.routeParameter ? `${humanizeRouteParameter(node.routeParameter)} · ${address}` : address;
47
52
  return [
48
53
  {
49
54
  value: path,
50
55
  label,
51
- ...(address !== label ? { description: address } : {}),
56
+ ...(description !== label ? { description } : {}),
57
+ ...(node.routeParameter ? { icon: "antd:unordered-list" } : {}),
52
58
  },
53
59
  ...collectPageOptions(area, node.children ?? []),
54
60
  ];
@@ -15,6 +15,7 @@ import { resolvePhiBuilderAreaAsCmsArea } from "../../../constants/cms-areas";
15
15
  import { createPhiPresetCmsPageId, isPhiCmsInstanceId } from "../../../types/cms-instance-id";
16
16
  import { buildPhiBuilderAreaLandingSelection, buildPhiBuilderRuntimeModulesConfigForArea, } from "./area-shell-presets.server";
17
17
  import { readPhiServerApiCredentials } from "../../../helpers/phis-server-credentials";
18
+ import { createPhiModuleMediaLoader } from "../../../gateway/server-module-media";
18
19
  /**
19
20
  * The Area's routes as the Builder's server half must see them: the table the reader compiles.
20
21
  *
@@ -95,6 +96,7 @@ async function buildPhiRegistryPresetPageTree({ runtime, runtimeModuleCatalog, b
95
96
  siteId: runtime.site.id,
96
97
  path,
97
98
  runtime,
99
+ loadModuleMedia: createPhiModuleMediaLoader(runtime.site.key),
98
100
  }), {
99
101
  runtimeModuleCatalog,
100
102
  siteKey: runtime.site.key,
@@ -4,6 +4,7 @@ import { PhiRuntimeModuleRenderClientHost } from "../../../../../components/runt
4
4
  import { fetchSiteNavigationFolderTarget } from "../../../../../gateway/site-nav";
5
5
  import { readPhiServerApiCredentials } from "../../../../../helpers/phis-server-credentials";
6
6
  import { resolvePhiWidgetRecordField } from "../../../../../server-helpers/record-fields";
7
+ import { resolvePhiRequestModuleFolderTargets } from "../../../../../server-helpers/module-folder-targets";
7
8
  /** The folders a Page path lies in, outermost first: `/docs/guides/a` gives `/docs` and `/docs/guides`. */
8
9
  export function listPhiBreadcrumbFolderPaths(pagePath) {
9
10
  const segments = pagePath.split("/").filter(Boolean);
@@ -13,7 +14,8 @@ export function listPhiBreadcrumbFolderPaths(pagePath) {
13
14
  * Which folders of the Page's path lead somewhere, so the client links exactly those.
14
15
  *
15
16
  * A folder segment is a link when its folder address resolves to a Page (REFERENCES.md, "Folder
16
- * addresses"); one that resolves to nothing would be a link into a 404. Asked once per folder of the
17
+ * addresses") or a Module container's `folderTarget` leads it to one; one that resolves to nothing
18
+ * would be a link into a 404. Asked once per folder of the
17
19
  * path, which is the depth of the path and not the size of the Site, and only when the trail shows the
18
20
  * path at all. A failed lookup leaves that segment unlinked rather than failing the trail.
19
21
  */
@@ -34,7 +36,12 @@ async function resolveLinkedFolderPaths(props) {
34
36
  area: String(runtime.area),
35
37
  path,
36
38
  }).catch(() => null)));
37
- return folders.filter((_path, index) => answers[index] != null);
39
+ // Where the Site chose no target, a Module container's own (`folderTarget`) answers, as on a request.
40
+ const unanswered = folders.filter((_path, index) => answers[index] == null);
41
+ const moduleTargets = unanswered.length > 0
42
+ ? resolvePhiRequestModuleFolderTargets(runtime.area, unanswered)
43
+ : new Map();
44
+ return folders.filter((path, index) => answers[index] != null || moduleTargets.has(path));
38
45
  }
39
46
  /**
40
47
  * The title of the record the Page is about, for the trail's last item; `null` leaves the path segment.
@@ -5,7 +5,7 @@ import type { PhiImageAssetVariantKeyValue } from "../../../../../types/media";
5
5
  import { type PhiLinkTarget } from "../../../../../types/references";
6
6
  import { type PhiBackgroundOverlay } from "../../../../../components/widgets/config/background";
7
7
  import { type PhiBulletListEntry, type PhiBulletListStyle } from "../../../../../components/widgets/shared/bullet-list-vocabulary";
8
- import { type PhiCardBillingPeriod, type PhiCardHeadingLevel, type PhiCardHoverEffect, type PhiCardIconPlacement, type PhiCardTextAlign, type PhiCardBadgeStyle, type PhiCardMediaAspectRatio, type PhiCardVariant, type PhiCardWidgetBody } from "../../../../../components/widgets/shared/card-vocabulary";
8
+ import { type PhiCardBillingPeriod, type PhiCardHeadingLevel, type PhiCardHoverEffect, type PhiCardIconPlacement, type PhiCardIconSize, type PhiCardTextAlign, type PhiCardBadgeStyle, type PhiCardMediaAspectRatio, type PhiCardVariant, type PhiCardWidgetBody } from "../../../../../components/widgets/shared/card-vocabulary";
9
9
  import { type PhiSignalRouteSet } from "../../../../../types/signals";
10
10
  import { type PhiCmsWidgetConfigBase } from "../../../../../components/widgets/config/parser-primitives";
11
11
  type PhiCardImageSource = {
@@ -54,6 +54,10 @@ export type PhiCmsCardWidgetConfig = PhiCmsWidgetConfigBase & PhiCardImageSource
54
54
  /** The icon's colour and the ground it stands on; absent, the Theme's. */
55
55
  iconColor?: string;
56
56
  iconBackground?: string;
57
+ /** How large the icon is drawn, in fixed steps. Absent is `default`. */
58
+ iconSize?: PhiCardIconSize;
59
+ /** `false` draws the icon without its ground; absent is framed. */
60
+ iconFramed?: boolean;
57
61
  /** The picture's words for a reader who cannot see it; an Asset brings its own. */
58
62
  alt?: string;
59
63
  /**
@@ -145,6 +149,7 @@ export declare const PHI_CARD_WIDGET_DEFINITION: {
145
149
  headingLevel: "h3";
146
150
  textAlign: "start";
147
151
  badgeStyle: "none";
152
+ iconFramed: true;
148
153
  };
149
154
  creationConfig: {
150
155
  surface: {
@@ -171,6 +176,7 @@ export declare const PHI_CARD_WIDGET_DEFINITION: {
171
176
  headingLevel: "h3";
172
177
  textAlign: "start";
173
178
  badgeStyle: "none";
179
+ iconFramed: true;
174
180
  };
175
181
  fields: (({
176
182
  key: string;
@@ -8,7 +8,7 @@ import { readPhiMediaImageSourceConfig } from "../../../../../components/widgets
8
8
  import { PHI_SURFACE_CARD } from "../../../../../helpers/surface-presets";
9
9
  import { normalizePhiBackgroundWidgetConfig } from "../../../../../components/widgets/config/background";
10
10
  import { buildPhiBulletListFields, readPhiBulletListEntries, readPhiBulletListStyle, } from "../../../../../components/widgets/shared/bullet-list-vocabulary";
11
- import { PHI_CARD_HEADING_LEVELS, PHI_CARD_HOVER_EFFECTS, PHI_CARD_ICON_PLACEMENTS, PHI_CARD_TEXT_ALIGNS, PHI_CARD_BADGE_STYLES, PHI_CARD_MEDIA_ASPECT_RATIOS, PHI_CARD_VARIANTS, readPhiCardBillingPeriod, } from "../../../../../components/widgets/shared/card-vocabulary";
11
+ import { PHI_CARD_HEADING_LEVELS, PHI_CARD_HOVER_EFFECTS, PHI_CARD_ICON_PLACEMENTS, PHI_CARD_ICON_SIZES, PHI_CARD_TEXT_ALIGNS, PHI_CARD_BADGE_STYLES, PHI_CARD_MEDIA_ASPECT_RATIOS, PHI_CARD_VARIANTS, readPhiCardBillingPeriod, } from "../../../../../components/widgets/shared/card-vocabulary";
12
12
  import { readPhiControlLabel } from "../../../../../components/widgets/config/common-action-field";
13
13
  import { PHI_CARD_SIGNALS } from "../../../../../components/widgets/signals/control-signal-capabilities";
14
14
  import { readPhiSignalRouteSet } from "../../../../../types/signals";
@@ -51,6 +51,8 @@ function parsePhiCmsCardWidgetConfig(config) {
51
51
  iconPlacement: readChoice(readString(config.iconPlacement), PHI_CARD_ICON_PLACEMENTS),
52
52
  iconColor: readString(config.iconColor),
53
53
  iconBackground: readString(config.iconBackground),
54
+ iconSize: readChoice(readString(config.iconSize), PHI_CARD_ICON_SIZES),
55
+ iconFramed: readBoolean(config.iconFramed),
54
56
  alt: readString(config.alt),
55
57
  mediaAspectRatio: readChoice(readString(config.mediaAspectRatio), PHI_CARD_MEDIA_ASPECT_RATIOS),
56
58
  imageOpacity: readPhiCardImageOpacity(config.imageOpacity),
@@ -84,6 +86,8 @@ const PHI_CARD_DEFAULT_CONFIG = {
84
86
  headingLevel: "h3",
85
87
  textAlign: "start",
86
88
  badgeStyle: "none",
89
+ // Shown on in the Inspector; the reader treats an absent value as framed all the same.
90
+ iconFramed: true,
87
91
  };
88
92
  export const PHI_CARD_WIDGET_DEFINITION = {
89
93
  kind: "widget",
@@ -239,6 +243,18 @@ export const PHI_CARD_WIDGET_DEFINITION = {
239
243
  // Shown with an icon, and not under the Center variant, which puts it over the picture itself.
240
244
  visibleWhen: [{ field: "icon", notEquals: null }, { field: "variant", notEquals: "center" }],
241
245
  },
246
+ {
247
+ key: "iconSize",
248
+ type: "choice",
249
+ label: "Icon size",
250
+ options: [
251
+ { value: "default", label: "Default" },
252
+ { value: "large", label: "Large" },
253
+ { value: "xlarge", label: "Extra large" },
254
+ ],
255
+ visibleWhen: { field: "icon", notEquals: null },
256
+ },
257
+ { key: "iconFramed", type: "boolean", label: "Icon ground", visibleWhen: { field: "icon", notEquals: null } },
242
258
  /* Left empty, the Theme's: the secondary text colour on its quietest fill. */
243
259
  {
244
260
  key: "iconColor",
@@ -254,7 +270,8 @@ export const PHI_CARD_WIDGET_DEFINITION = {
254
270
  label: "Background",
255
271
  mode: "single",
256
272
  defaultToken: "colorFillQuaternary",
257
- visibleWhen: { field: "icon", notEquals: null },
273
+ // Without a ground there is nothing to colour.
274
+ visibleWhen: [{ field: "icon", notEquals: null }, { field: "iconFramed", notEquals: false }],
258
275
  },
259
276
  /*
260
277
  * Where the whole card leads, and how it answers the pointer: only a card that leads somewhere has
@@ -170,6 +170,8 @@ export function PhiCardWidgetEditor({ config, onChange }) {
170
170
  iconPlacement: config.iconPlacement,
171
171
  iconColor: config.iconColor,
172
172
  iconBackground: config.iconBackground,
173
+ iconSize: config.iconSize,
174
+ iconFramed: config.iconFramed,
173
175
  textAlign: config.textAlign,
174
176
  headingLevel: config.headingLevel,
175
177
  /*
@@ -93,6 +93,8 @@ export async function PhiCardWidget({ labels, config, runtime, links, preview =
93
93
  iconPlacement: config?.iconPlacement,
94
94
  iconColor: config?.iconColor,
95
95
  iconBackground: config?.iconBackground,
96
+ iconSize: config?.iconSize,
97
+ iconFramed: config?.iconFramed,
96
98
  textAlign: config?.textAlign,
97
99
  headingLevel: config?.headingLevel,
98
100
  href: link?.href,
@@ -8,6 +8,7 @@ import type { PhiRuntimeModuleCatalog } from "../../types/cms-plugins";
8
8
  import type { PhiBlockRuntime } from "../../types/widget-runtime";
9
9
  import { type PhiAccessViewer } from "../../types/access";
10
10
  import { type PhiAreaLandingSelection, type PhiPublicRoutePathAssignment } from "../../helpers/cms-area-config";
11
+ import type { PhiModuleMediaLoader } from "../../types/module-media";
11
12
  export declare function buildPhiCmsPresetIdentityKey(ownerModuleId: PhiRuntimeModuleId, presetKey: string): string;
12
13
  export declare function normalizePhiCmsRoutePath(value: string): `/${string}`;
13
14
  export declare function compilePhiCmsRoutePattern(descriptor: PhiCmsRoutePresetDescriptor): PhiCmsCompiledRoutePattern;
@@ -58,6 +59,22 @@ export declare function resolvePhiCmsActiveNavigationSurfaces({ catalog, area, a
58
59
  routeTable: PhiCmsActiveRouteTable;
59
60
  viewer?: PhiAccessViewer;
60
61
  }): readonly PhiCmsResolvedNavigationSurface[];
62
+ /**
63
+ * The Pages Module containers' folder addresses lead to by their descriptors (`folderTarget`), keyed by
64
+ * address; an address no Module container answers is not in the map.
65
+ *
66
+ * Asked where the Site's published Navigations name no target for an address -- a request no Page
67
+ * answers (`server-helpers/cms-request.ts`), a breadcrumb's folders -- so a Site's choice replaces the
68
+ * Module's, not the reverse. Every surface of the Area is searched once, because a folder address is the
69
+ * Area's, not one menu's.
70
+ */
71
+ export declare function resolvePhiCmsModuleNavigationFolderTargets(input: {
72
+ catalog: PhiCmsCompiledDescriptorCatalog;
73
+ area: PhiCmsAreaKey;
74
+ activeModuleIds: ReadonlySet<PhiRuntimeModuleId>;
75
+ routeTable: PhiCmsActiveRouteTable;
76
+ addresses: readonly string[];
77
+ }): Map<string, string>;
61
78
  export declare function resolvePhiCmsNavigationOverlay(surface: PhiCmsResolvedNavigationSurface, overlay: PhiCmsNavigationOverlay | null): PhiCmsNavigationOverlayResolution;
62
79
  export declare function resolvePhiCmsRoutePreset(table: PhiCmsActiveRouteTable, requestedPath: string): PhiCmsRoutePresetBinding | null;
63
80
  export declare function resolvePhiCmsRoutePresetByPageId(table: PhiCmsActiveRouteTable, pageId: PhiCmsInstanceId): PhiCmsRoutePresetBinding | null;
@@ -88,7 +105,7 @@ type PhiCmsPresetTreeForm = {
88
105
  * cannot see (one stored on the Site, one of a Module outside the catalog) is not judged.
89
106
  */
90
107
  export declare function assertPhiCmsPresetTreeContract(tree: PhiResolvedCmsPageTree, expectedPage?: PhiCmsPageNode, forms?: ReadonlyMap<string, PhiCmsPresetTreeForm>): void;
91
- export declare function composePhiCmsActiveAreaOverlayPresets({ tree, catalog, activeModuleIds, siteId, area, path, runtime, }: {
108
+ export declare function composePhiCmsActiveAreaOverlayPresets({ tree, catalog, activeModuleIds, siteId, area, path, runtime, loadModuleMedia, }: {
92
109
  tree: PhiResolvedCmsAreaPresetTree;
93
110
  catalog: PhiCmsCompiledDescriptorCatalog;
94
111
  activeModuleIds: ReadonlySet<PhiRuntimeModuleId>;
@@ -96,21 +113,24 @@ export declare function composePhiCmsActiveAreaOverlayPresets({ tree, catalog, a
96
113
  area: PhiCmsAreaKey;
97
114
  path: string;
98
115
  runtime: PhiBlockRuntime;
116
+ loadModuleMedia: PhiModuleMediaLoader;
99
117
  }): Promise<PhiResolvedCmsAreaPresetTree>;
100
- export declare function instantiatePhiCmsAreaShellPreset({ binding, catalog, siteId, path, runtime, }: {
118
+ export declare function instantiatePhiCmsAreaShellPreset({ binding, catalog, siteId, path, runtime, loadModuleMedia, }: {
101
119
  binding: PhiCmsAreaShellPresetBinding;
102
120
  catalog: PhiCmsCompiledDescriptorCatalog;
103
121
  siteId: number;
104
122
  path: string;
105
123
  runtime: PhiBlockRuntime;
124
+ loadModuleMedia: PhiModuleMediaLoader;
106
125
  }): Promise<PhiResolvedCmsPageTree>;
107
- export declare function instantiatePhiCmsRoutePreset({ binding, catalog, activeModuleIds, siteId, path, runtime, resolveMissingPageTitle, }: {
126
+ export declare function instantiatePhiCmsRoutePreset({ binding, catalog, activeModuleIds, siteId, path, runtime, loadModuleMedia, resolveMissingPageTitle, }: {
108
127
  binding: PhiCmsRoutePresetBinding;
109
128
  catalog: PhiCmsCompiledDescriptorCatalog;
110
129
  activeModuleIds: ReadonlySet<PhiRuntimeModuleId>;
111
130
  siteId: number;
112
131
  path: string;
113
132
  runtime: PhiBlockRuntime;
133
+ loadModuleMedia: PhiModuleMediaLoader;
114
134
  resolveMissingPageTitle?: (sourceTitle: string) => string | Promise<string>;
115
135
  }): Promise<PhiResolvedCmsPageTree>;
116
136
  export {};
@@ -7,12 +7,14 @@ import { resolvePhiRuntimeModuleSourceLocale } from "../../types/runtime-module-
7
7
  import { canPhiViewerAccess, PHI_VIEWER_ACCESS_ANYONE, } from "../../types/access";
8
8
  import { mergePhiCmsShellTrees, omitPhiCmsShellCompositionNodes, } from "./shell-tree-composition";
9
9
  import { resolvePhiRuntimeModuleAreaRoutePath } from "../../helpers/runtime-module-route-path";
10
+ import { createPhiPageReference } from "../../types/references";
10
11
  import { choosePhiAreaRootApplicant, orderPhiAreaPathClaimsByCover, isPhiAssignablePublicRoutePath, } from "../../helpers/cms-area-config";
11
12
  import { resolvePhiLayoutCreationPreset } from "../../helpers/cms-layout-defaults";
12
13
  import { PHI_DIALOG_BLEED_BODY_CONFIG, PHI_DIALOG_BODY_CONFIG, PHI_DIALOG_COMMANDS_CONFIG, PHI_DIALOG_WIDTH, isPhiFormSingleColumn, } from "../../helpers/cms-dialog";
13
14
  import { PhiCmsWidgetType } from "../../constants/cms-widget-types";
14
15
  import { buildPhiBasePageLayoutNode, PHI_BASE_PAGE_LAYOUT_NODE_ID, } from "../../components/regions/presets/phi-base-page-layout";
15
16
  import { concatPhiCmsTreeControllerSettings } from "../../helpers/cms-tree-controller-settings";
17
+ import { createPhiModuleMediaResolver } from "../../helpers/module-media";
16
18
  const PHI_CMS_REGION_TYPE_VALUES = new Set(Object.values(PhiCmsRegionType));
17
19
  const PHI_ROUTE_PARAMETER_PATTERN = /^:[A-Za-z][A-Za-z0-9_]*$/;
18
20
  const PHI_NAVIGATION_ANCHORS = new Set([
@@ -468,6 +470,16 @@ export function compilePhiCmsDescriptorCatalog({ catalog, areaDefinitions, }) {
468
470
  label: `${label}/${item.itemKey}`,
469
471
  });
470
472
  }
473
+ if (item.folderTarget !== undefined) {
474
+ /*
475
+ * The child's Page answers the folder address. Only a route has one: an Overlay, an external
476
+ * address or a sub-container is no Page to forward to.
477
+ */
478
+ const child = (item.children ?? []).find((entry) => entry.itemKey === item.folderTarget);
479
+ if (!child?.routePresetKey) {
480
+ throw new Error(`${label}/${item.itemKey}: folderTarget "${item.folderTarget}" names no direct child that goes to a route.`);
481
+ }
482
+ }
471
483
  visitNavigationRouteReferences(item.children ?? [], ownerModuleId, area, label);
472
484
  }
473
485
  };
@@ -908,10 +920,51 @@ function buildResolvedNavigationNode(catalog, routeTable, navKey, ownerModuleId,
908
920
  standsLast: "standing" in descriptor && descriptor.standing === "last",
909
921
  // An item that named a route and got nothing back. A container never is one: it named nothing.
910
922
  isUnrouted: Boolean(descriptor.routePresetKey) && !target,
923
+ folderTargetItemKey: descriptor.folderTarget ?? null,
911
924
  intrinsicChildren,
912
925
  injection,
913
926
  };
914
927
  }
928
+ /** The folder a path lies in; `/` is the Area root, a slot and no folder. */
929
+ function parentNavigationFolder(path) {
930
+ const index = path.lastIndexOf("/");
931
+ return index > 0 ? path.slice(0, index) : "/";
932
+ }
933
+ function resolveModuleNavigationFolderAddress(children) {
934
+ const folders = new Set(children.flatMap((child) => {
935
+ const path = child.kind === "container"
936
+ ? resolveModuleNavigationFolderAddress(child.children)
937
+ : child.target?.kind === "module" ? child.target.path : null;
938
+ return path ? [parentNavigationFolder(path)] : [];
939
+ }));
940
+ const [address] = folders;
941
+ return folders.size === 1 && address && address !== "/" ? address : null;
942
+ }
943
+ /**
944
+ * A Module container's folder, as its `folderTarget` names it: the folder its direct children share --
945
+ * a link by its route's path, a sub-container by its own folder -- and the Page of the child it names.
946
+ * The same rule as a Site's folder (`builder/navigation-folder-address.ts`). None where the children
947
+ * share no folder, or the named child does not answer here: the address then leads nowhere, as a
948
+ * container without a target does.
949
+ */
950
+ function resolveModuleNavigationFolder(node, children) {
951
+ const address = resolveModuleNavigationFolderAddress(children);
952
+ if (!address) {
953
+ return null;
954
+ }
955
+ const childId = node.intrinsicChildren.find((child) => child.definitionItemKey === node.folderTargetItemKey)?.item.id;
956
+ const target = children.find((child) => child.id === childId)?.target;
957
+ if (target?.kind !== "module") {
958
+ return null;
959
+ }
960
+ return {
961
+ address,
962
+ target: {
963
+ kind: "page",
964
+ reference: createPhiPageReference({ kind: "module", ownerModuleId: target.ownerModuleId, presetKey: target.presetKey }),
965
+ },
966
+ };
967
+ }
915
968
  function orderNavigationSiblings(intrinsic, injected, parentItemKey) {
916
969
  /*
917
970
  * An Area's entries first, the contributed ones after -- except the entries that said they stand
@@ -1097,10 +1150,13 @@ export function resolvePhiCmsActiveNavigationSurfaces({ catalog, area, activeMod
1097
1150
  */
1098
1151
  const materialize = (intrinsic, injected, parentItemKey) => orderNavigationSiblings(intrinsic, injected, parentItemKey)
1099
1152
  .filter(isNavigationNodeVisible)
1100
- .map((node) => ({
1101
- ...node.item,
1102
- children: materialize(node.intrinsicChildren, injectedByParent.get(node.definitionItemKey) ?? [], node.definitionItemKey),
1103
- }))
1153
+ .map((node) => {
1154
+ const children = materialize(node.intrinsicChildren, injectedByParent.get(node.definitionItemKey) ?? [], node.definitionItemKey);
1155
+ const folder = node.item.kind === "container" && node.folderTargetItemKey
1156
+ ? resolveModuleNavigationFolder(node, children)
1157
+ : null;
1158
+ return { ...node.item, ...(folder ? { folder } : {}), children };
1159
+ })
1104
1160
  .filter((item) => item.kind !== "container" || item.children.length > 0);
1105
1161
  return {
1106
1162
  area,
@@ -1110,6 +1166,34 @@ export function resolvePhiCmsActiveNavigationSurfaces({ catalog, area, activeMod
1110
1166
  };
1111
1167
  });
1112
1168
  }
1169
+ /**
1170
+ * The Pages Module containers' folder addresses lead to by their descriptors (`folderTarget`), keyed by
1171
+ * address; an address no Module container answers is not in the map.
1172
+ *
1173
+ * Asked where the Site's published Navigations name no target for an address -- a request no Page
1174
+ * answers (`server-helpers/cms-request.ts`), a breadcrumb's folders -- so a Site's choice replaces the
1175
+ * Module's, not the reverse. Every surface of the Area is searched once, because a folder address is the
1176
+ * Area's, not one menu's.
1177
+ */
1178
+ export function resolvePhiCmsModuleNavigationFolderTargets(input) {
1179
+ const wanted = new Set(input.addresses);
1180
+ const found = new Map();
1181
+ const visit = (items) => {
1182
+ for (const item of items) {
1183
+ const address = item.folder?.address;
1184
+ if (address && wanted.has(address) && !found.has(address) && item.folder?.target?.kind === "page") {
1185
+ found.set(address, item.folder.target.reference);
1186
+ }
1187
+ visit(item.children);
1188
+ }
1189
+ };
1190
+ if (wanted.size === 0)
1191
+ return found;
1192
+ for (const surface of resolvePhiCmsActiveNavigationSurfaces(input)) {
1193
+ visit(surface.items);
1194
+ }
1195
+ return found;
1196
+ }
1113
1197
  export function resolvePhiCmsNavigationOverlay(surface, overlay) {
1114
1198
  if (!overlay) {
1115
1199
  return { surface, diagnostics: [] };
@@ -1543,7 +1627,7 @@ function assertPhiCmsAreaOverlayTree(descriptor, tree, page, forms) {
1543
1627
  }
1544
1628
  }
1545
1629
  }
1546
- export async function composePhiCmsActiveAreaOverlayPresets({ tree, catalog, activeModuleIds, siteId, area, path, runtime, }) {
1630
+ export async function composePhiCmsActiveAreaOverlayPresets({ tree, catalog, activeModuleIds, siteId, area, path, runtime, loadModuleMedia, }) {
1547
1631
  const descriptors = (catalog.areaOverlaysByArea.get(area) ?? [])
1548
1632
  .filter((descriptor) => activeModuleIds.has(descriptor.ownerModuleId));
1549
1633
  if (descriptors.length === 0)
@@ -1561,7 +1645,12 @@ export async function composePhiCmsActiveAreaOverlayPresets({ tree, catalog, act
1561
1645
  // Loaded side by side -- each contribution is a Core round trip of its own -- and merged in
1562
1646
  // declaration order, which is what the ids and the controller settings below depend on.
1563
1647
  const targetRuntime = resolveTargetRuntime(runtime, area);
1564
- const contributions = await Promise.all(descriptors.map((descriptor) => descriptor.loadTree({ page, runtime: targetRuntime, catalog })));
1648
+ const contributions = await Promise.all(descriptors.map((descriptor) => descriptor.loadTree({
1649
+ page,
1650
+ runtime: targetRuntime,
1651
+ catalog,
1652
+ media: createPhiModuleMediaResolver(descriptor.ownerModuleId, loadModuleMedia),
1653
+ })));
1565
1654
  for (const [index, descriptor] of descriptors.entries()) {
1566
1655
  const contribution = contributions[index];
1567
1656
  assertPhiCmsAreaOverlayTree(descriptor, contribution, page, catalog.formDefinitionsById);
@@ -1591,27 +1680,32 @@ export async function composePhiCmsActiveAreaOverlayPresets({ tree, catalog, act
1591
1680
  function resolveTargetRuntime(runtime, area) {
1592
1681
  return runtime.area === area ? runtime : { ...runtime, area };
1593
1682
  }
1594
- async function loadShellTree(descriptor, catalog, page, runtime) {
1683
+ async function loadShellTree(descriptor, catalog, page, runtime, loadModuleMedia) {
1595
1684
  let composedTree = null;
1596
1685
  for (const source of descriptor.composition ?? []) {
1597
1686
  const sourceDescriptor = catalog.areaShellByIdentity.get(buildPhiCmsPresetIdentityKey(source.ownerModuleId, source.presetKey))?.descriptor;
1598
1687
  if (!sourceDescriptor) {
1599
1688
  throw new Error(`${descriptor.ownerModuleId}/${descriptor.presetKey}: unresolved shell composition source.`);
1600
1689
  }
1601
- const sourceTree = omitPhiCmsShellCompositionNodes(await loadShellTree(sourceDescriptor, catalog, page, runtime), sourceDescriptor, source.omitRegionTypes ?? [], source.omitNodeKeys ?? []);
1690
+ const sourceTree = omitPhiCmsShellCompositionNodes(await loadShellTree(sourceDescriptor, catalog, page, runtime, loadModuleMedia), sourceDescriptor, source.omitRegionTypes ?? [], source.omitNodeKeys ?? []);
1602
1691
  composedTree = composedTree ? mergePhiCmsShellTrees(composedTree, sourceTree) : sourceTree;
1603
1692
  }
1604
- const ownTree = await descriptor.loadTree({ page, runtime, catalog });
1693
+ const ownTree = await descriptor.loadTree({
1694
+ page,
1695
+ runtime,
1696
+ catalog,
1697
+ media: createPhiModuleMediaResolver(descriptor.ownerModuleId, loadModuleMedia),
1698
+ });
1605
1699
  assertPhiCmsPresetTreeContract(ownTree, page, catalog.formDefinitionsById);
1606
1700
  return composedTree ? mergePhiCmsShellTrees(composedTree, ownTree) : ownTree;
1607
1701
  }
1608
- export async function instantiatePhiCmsAreaShellPreset({ binding, catalog, siteId, path, runtime, }) {
1702
+ export async function instantiatePhiCmsAreaShellPreset({ binding, catalog, siteId, path, runtime, loadModuleMedia, }) {
1609
1703
  const page = createSyntheticPresetPage({ siteId, area: binding.descriptor.area, path });
1610
- const tree = await loadShellTree(binding.descriptor, catalog, page, resolveTargetRuntime(runtime, binding.descriptor.area));
1704
+ const tree = await loadShellTree(binding.descriptor, catalog, page, resolveTargetRuntime(runtime, binding.descriptor.area), loadModuleMedia);
1611
1705
  assertPhiCmsPresetTreeContract(tree, page, catalog.formDefinitionsById);
1612
1706
  return tree;
1613
1707
  }
1614
- export async function instantiatePhiCmsRoutePreset({ binding, catalog, activeModuleIds, siteId, path, runtime, resolveMissingPageTitle, }) {
1708
+ export async function instantiatePhiCmsRoutePreset({ binding, catalog, activeModuleIds, siteId, path, runtime, loadModuleMedia, resolveMissingPageTitle, }) {
1615
1709
  const descriptor = binding.descriptor;
1616
1710
  const page = createSyntheticPresetPage({
1617
1711
  siteId,
@@ -1625,6 +1719,7 @@ export async function instantiatePhiCmsRoutePreset({ binding, catalog, activeMod
1625
1719
  catalog,
1626
1720
  activeModuleIds,
1627
1721
  params: binding.params,
1722
+ media: createPhiModuleMediaResolver(descriptor.ownerModuleId, loadModuleMedia),
1628
1723
  });
1629
1724
  const tree = loadedTree.pageMeta?.title
1630
1725
  ? loadedTree
@@ -2,6 +2,7 @@ import "server-only";
2
2
  import { resolvePhiCmsAreaKey, resolvePhiCmsAreaMask } from "../constants/cms-areas";
3
3
  import { PhiCmsStatus } from "../constants/phi-cms";
4
4
  import { applyPhiPresetTreePublishedContent } from "./cms-bound-content";
5
+ import { createPhiModuleMediaLoader } from "../gateway/server-module-media";
5
6
  import { instantiatePhiCmsAreaShellPreset, resolvePhiCmsAreaShellPresetBinding, resolvePhiCmsDescriptorCatalog, } from "../plugins/runtime-modules/descriptor-compiler";
6
7
  function createSyntheticAreaPreset({ siteId, areaMask, }) {
7
8
  return {
@@ -43,7 +44,14 @@ export async function buildPhiLocalCmsAreaPayload({ areaMask, siteId, path, runt
43
44
  if (!binding) {
44
45
  return null;
45
46
  }
46
- const tree = await applyPhiPresetTreePublishedContent(await instantiatePhiCmsAreaShellPreset({ binding, catalog, siteId, path, runtime }), { runtimeModuleCatalog, siteKey: runtime.site.key, locale: runtime.locale.current });
47
+ const tree = await applyPhiPresetTreePublishedContent(await instantiatePhiCmsAreaShellPreset({
48
+ binding,
49
+ catalog,
50
+ siteId,
51
+ path,
52
+ runtime,
53
+ loadModuleMedia: createPhiModuleMediaLoader(runtime.site.key),
54
+ }), { runtimeModuleCatalog, siteKey: runtime.site.key, locale: runtime.locale.current });
47
55
  return buildAreaPresetPayloadFromTree({
48
56
  areaMask: resolvedAreaMask,
49
57
  siteId,
@@ -3,7 +3,7 @@ import { cache } from "react";
3
3
  import { notFound } from "next/navigation";
4
4
  import { resolvePhiCmsAreaKey, resolvePhiCmsAreaMask, } from "../constants/cms-areas";
5
5
  import { canPhiViewerAccess } from "../types/access";
6
- import { compilePhiCmsActiveRouteTable, instantiatePhiCmsRoutePreset, normalizePhiCmsRoutePath, resolvePhiCmsAreaShellPresetBinding, resolvePhiCmsDescriptorCatalog, resolvePhiCmsRoutePreset, } from "../plugins/runtime-modules/descriptor-compiler";
6
+ import { compilePhiCmsActiveRouteTable, instantiatePhiCmsRoutePreset, normalizePhiCmsRoutePath, resolvePhiCmsAreaShellPresetBinding, resolvePhiCmsDescriptorCatalog, resolvePhiCmsModuleNavigationFolderTargets, resolvePhiCmsRoutePreset, } from "../plugins/runtime-modules/descriptor-compiler";
7
7
  import { resolvePhiRuntimeModuleIdsForArea } from "../plugins/runtime-modules/settings";
8
8
  import { composePhiCmsPagePresetOverlays } from "../plugins/runtime-modules/page-preset-overlays";
9
9
  import { resolvePhiCmsRoutePage } from "../plugins/runtime-modules/route-page-resolution";
@@ -26,6 +26,7 @@ import { buildPhiBlockRuntime, loadPhiSiteRequestContext, } from "./runtime";
26
26
  import { trForLocale } from "./translate";
27
27
  import { readPhiAreaLandingSelection, readPhiAreaPresetRuntimeModuleIds, readPhiAreaPublicRoutePaths, } from "../helpers/cms-area-config";
28
28
  import { readPhiServerApiCredentials } from "../helpers/phis-server-credentials";
29
+ import { createPhiModuleMediaLoader } from "../gateway/server-module-media";
29
30
  async function instantiatePhiRoutePresetPage({ binding, requestedPath, areaMask, siteId, runtime, runtimeModuleCatalog, activeModuleKeys, }) {
30
31
  const catalog = resolvePhiCmsDescriptorCatalog(runtimeModuleCatalog);
31
32
  return {
@@ -43,6 +44,7 @@ async function instantiatePhiRoutePresetPage({ binding, requestedPath, areaMask,
43
44
  siteId,
44
45
  path: requestedPath,
45
46
  runtime,
47
+ loadModuleMedia: createPhiModuleMediaLoader(runtime.site.key),
46
48
  // The route's title is the owning Module's text, written in that Module's language.
47
49
  resolveMissingPageTitle: (sourceTitle) => trForLocale(runtime.locale.current, sourceTitle, 0, 0, "text", catalog.sourceLocaleByModuleId.get(binding.descriptor.ownerModuleId)),
48
50
  }), { runtimeModuleCatalog, siteKey: runtime.site.key, locale: runtime.locale.current }),
@@ -319,7 +321,8 @@ export async function resolvePhiCmsRequest({ siteKey, locale, area, path, cookie
319
321
  * a folder whose Navigation container leads to one. The server follows the published Navigations to a
320
322
  * Page reference, and the reference is resolved here, where Module routes are known.
321
323
  */
322
- const folderTargetReference = !loadedPage && areaAllowed && areaOwnedStoragePath && areaOwnedStoragePath !== "/"
324
+ const folderLookup = !loadedPage && areaAllowed && areaOwnedStoragePath && areaOwnedStoragePath !== "/";
325
+ const siteFolderTargetReference = folderLookup
323
326
  ? await fetchSiteNavigationFolderTarget({
324
327
  apiBaseUrl: readPhiServerApiCredentials().apiBaseUrl,
325
328
  internalToken: readPhiServerApiCredentials().internalToken,
@@ -328,6 +331,16 @@ export async function resolvePhiCmsRequest({ siteKey, locale, area, path, cookie
328
331
  path: areaOwnedStoragePath,
329
332
  })
330
333
  : null;
334
+ // Where the Site chose no target, a Module container's own (`folderTarget`) answers.
335
+ const folderTargetReference = siteFolderTargetReference ?? (folderLookup
336
+ ? resolvePhiCmsModuleNavigationFolderTargets({
337
+ catalog,
338
+ area: requestedAreaKey,
339
+ activeModuleIds: activeModuleKeys,
340
+ routeTable,
341
+ addresses: [areaOwnedStoragePath],
342
+ }).get(areaOwnedStoragePath) ?? null
343
+ : null);
331
344
  const folderTargetPath = folderTargetReference
332
345
  ? await resolvePhiAreaPageReferencePath({
333
346
  runtime: runtimeWithAuthProvider,
@@ -11,6 +11,7 @@ import { getPhiExactSiteArea } from "./cms";
11
11
  import { hasPhiCmsAuthorizedPreviewRead, resolvePhiCmsReviewParams, resolvePhiCmsRevisionFromSearchParams, resolvePhiCmsThemeReviewRequestContext, } from "./cms-review";
12
12
  import { setPhiRequestNavigationContext, setPhiRequestRuntime, } from "./request-runtime";
13
13
  import { buildPhiBlockRuntime, loadPhiSiteRequestContext } from "./runtime";
14
+ import { createPhiModuleMediaLoader } from "../gateway/server-module-media";
14
15
  import { composePhiCmsActiveAreaOverlayPresets, resolvePhiCmsAreaShellPresetBinding, resolvePhiCmsDescriptorCatalog, } from "../plugins/runtime-modules/descriptor-compiler";
15
16
  import { resolvePhiAuthUiRuntimeProjection } from "./auth-ui-provider";
16
17
  import { resolvePhiAreaRouteScope } from "./cms-request";
@@ -155,6 +156,7 @@ const loadPhiCmsRootScopeCached = cache(async function loadPhiCmsRootScopeCached
155
156
  area: resolvedRoute.area,
156
157
  path: resolvedRoute.cmsPath,
157
158
  runtime,
159
+ loadModuleMedia: createPhiModuleMediaLoader(requestContext.site.key),
158
160
  })
159
161
  : null;
160
162
  // The shell Header, Hero, and Footer Backgrounds live in this tree, and it is composed after the
@@ -0,0 +1,7 @@
1
+ import "server-only";
2
+ /**
3
+ * The Pages Module containers' folder addresses lead to in the Area this request serves
4
+ * (`folderTarget`), for the addresses asked; empty where the request set up no Navigation context for
5
+ * the Area -- a render outside a page request -- since nothing then says which Modules answer.
6
+ */
7
+ export declare function resolvePhiRequestModuleFolderTargets(area: unknown, addresses: readonly string[]): Map<string, string>;
@@ -0,0 +1,15 @@
1
+ import "server-only";
2
+ import { isPhiCmsAreaKey } from "../constants/cms-areas";
3
+ import { resolvePhiCmsModuleNavigationFolderTargets } from "../plugins/runtime-modules/descriptor-compiler";
4
+ import { maybeGetPhiRequestNavigationContext } from "./request-runtime";
5
+ /**
6
+ * The Pages Module containers' folder addresses lead to in the Area this request serves
7
+ * (`folderTarget`), for the addresses asked; empty where the request set up no Navigation context for
8
+ * the Area -- a render outside a page request -- since nothing then says which Modules answer.
9
+ */
10
+ export function resolvePhiRequestModuleFolderTargets(area, addresses) {
11
+ const context = isPhiCmsAreaKey(area) ? maybeGetPhiRequestNavigationContext(area) : null;
12
+ if (!context || !isPhiCmsAreaKey(area))
13
+ return new Map();
14
+ return resolvePhiCmsModuleNavigationFolderTargets({ ...context, area, addresses });
15
+ }