@phis/ui 0.7.7 → 0.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/components/controls/phi-form-control.js +12 -1
  2. package/components/forms/extended-form-field-controls.d.ts +1 -1
  3. package/components/forms/extended-form-field-controls.js +23 -7
  4. package/components/forms/form-provider-contract.d.ts +5 -0
  5. package/components/forms/form-provider-contract.js +9 -2
  6. package/components/forms/form-provider-registry.d.ts +6 -0
  7. package/components/forms/money-field-currency-key.d.ts +6 -0
  8. package/components/forms/money-field-currency-key.js +14 -0
  9. package/components/forms/money-field.d.ts +26 -3
  10. package/components/forms/money-field.js +54 -4
  11. package/components/regions/presets/navigation-redirect.d.ts +4 -1
  12. package/components/regions/presets/navigation-redirect.js +6 -3
  13. package/components/widgets/client/shared/phi-rendered-value.js +5 -3
  14. package/helpers/money-amount.d.ts +7 -0
  15. package/helpers/money-amount.js +15 -0
  16. package/package.json +1 -1
  17. package/plugins/runtime-modules/app/presets.js +3 -6
  18. package/plugins/runtime-modules/app/trees/phi-default-app-area-preset-tree.d.ts +3 -6
  19. package/plugins/runtime-modules/app/trees/phi-default-app-area-preset-tree.js +4 -7
  20. package/plugins/runtime-modules/builder/controller/client.d.ts +5 -5
  21. package/plugins/runtime-modules/builder/controller/client.js +2 -1
  22. package/plugins/runtime-modules/builder/controller/definition.d.ts +4 -4
  23. package/plugins/runtime-modules/builder/controller/definition.js +7 -0
  24. package/plugins/runtime-modules/builder/controller/draft-command-controller.d.ts +3 -1
  25. package/plugins/runtime-modules/builder/controller/draft-command-controller.js +2 -1
  26. package/plugins/runtime-modules/builder/controller/draft-status-controller.js +44 -17
  27. package/plugins/runtime-modules/builder/controller/server-definition.d.ts +4 -4
  28. package/plugins/runtime-modules/builder/controller/workspace-controller.d.ts +3 -1
  29. package/plugins/runtime-modules/builder/controller/workspace-controller.js +8 -10
  30. package/plugins/runtime-modules/builder/developer-workspace-store.d.ts +10 -0
  31. package/plugins/runtime-modules/builder/developer-workspace-store.js +35 -1
  32. package/plugins/runtime-modules/builder/offered-page-catalog.d.ts +6 -0
  33. package/plugins/runtime-modules/builder/offered-page-catalog.js +35 -6
  34. package/plugins/runtime-modules/builder/persistence.d.ts +4 -1
  35. package/plugins/runtime-modules/builder/persistence.js +10 -3
  36. package/plugins/runtime-modules/core/definition.d.ts +5 -0
  37. package/plugins/runtime-modules/core/form-providers.d.ts +5 -0
  38. package/plugins/runtime-modules/core/widgets/spacer/client.js +3 -3
  39. package/plugins/runtime-modules/phi-default-site-area-preset-tree.js +46 -39
  40. package/plugins/runtime-modules/preset-contracts/pub-area.d.ts +1 -1
  41. package/plugins/runtime-modules/preset-contracts/pub-area.js +1 -0
  42. package/plugins/runtime-modules/revisions/controller/client.js +48 -46
  43. package/plugins/runtime-modules/revisions/services/table.js +3 -1
  44. package/styles/builder-scaffold.css +7 -1
  45. package/styles/layout-authoring-scaffold.css +27 -0
@@ -1,11 +1,16 @@
1
1
  "use client";
2
2
  import { useCallback, useEffect, useRef, useState } from "react";
3
3
  import { PHI_SIGNAL_VALUE_SCHEMAS } from "../../../../types/signals";
4
+ import { readPhiDraftStatusSignalValue } from "../../../../types/draft-status";
5
+ import { isPhiBuilderAreaKey } from "../../../../constants/cms-areas";
6
+ import { isPhiRecord } from "../../../../helpers/is-record";
4
7
  import { usePhiSignalDispatcher, usePhiSignalListener } from "../../../../components/runtime/runtime-signal-bus";
5
8
  import { resolvePhiBuilderCmsStoragePath } from "../../../../helpers/cms-paths";
6
9
  import { resolvePhiBuilderActivePageCatalog, resolvePhiBuilderPagePresetSource, } from "../../../../helpers/cms-page-catalog";
7
10
  import { createPhiBuilderControllerAddress } from "../controller/address";
8
11
  import { createPhiBuilderHistoryContext, phiBuilderHistory } from "../history";
12
+ import { clearPhiBuilderDraftAllocation, getPhiBuilderDraftContextGeneration, invalidatePhiBuilderDraftContext, } from "../developer-workspace-store";
13
+ import { createPhiBuilderDraftAllocationKey } from "../draft-allocation-key";
9
14
  const PHI_BUILDER_NO_DRAFT_HISTORY_CONTEXT = "draft-status:none";
10
15
  function resolveTarget(workspace, area, pageKey, navKey, state) {
11
16
  if (workspace === "navigation") {
@@ -87,17 +92,20 @@ export function usePhiBuilderDraftStatusController({ commandWorkspace, effective
87
92
  const targetUrl = target?.url ?? null;
88
93
  const subject = target?.subject ?? null;
89
94
  const historyContext = target?.historyContext ?? null;
95
+ const requestKey = targetUrl === null || historyContext === null
96
+ ? null
97
+ : `${targetUrl}:${getPhiBuilderDraftContextGeneration(historyContext)}`;
90
98
  const [stored, setStored] = useState(null);
91
99
  /*
92
100
  * The history head each target was last saved or first read at. The status is read again whenever the
93
101
  * target changes -- an Area switched away from and back -- and taking the head at that moment called
94
102
  * every edit made before it saved: back on an Area with an unsaved edit, the badge said "Published".
95
- * A target keeps the head it was read or saved at until it is saved again.
103
+ * A target keeps its saved head until a revision action replaces that editing context.
96
104
  */
97
105
  const savedHeadsRef = useRef(new Map());
98
106
  const historyHead = phiBuilderHistory.useHead(historyContext ?? PHI_BUILDER_NO_DRAFT_HISTORY_CONTEXT);
99
107
  useEffect(() => {
100
- if (targetUrl === null) {
108
+ if (targetUrl === null || requestKey === null || historyContext === null) {
101
109
  return;
102
110
  }
103
111
  let cancelled = false;
@@ -105,16 +113,11 @@ export function usePhiBuilderDraftStatusController({ commandWorkspace, effective
105
113
  if (cancelled) {
106
114
  return;
107
115
  }
108
- setStored({
109
- requestKey: targetUrl,
110
- ...next,
111
- savedHead: (() => {
112
- if (!savedHeadsRef.current.has(targetUrl)) {
113
- savedHeadsRef.current.set(targetUrl, historyContext === null ? null : phiBuilderHistory.getHead(historyContext));
114
- }
115
- return savedHeadsRef.current.get(targetUrl);
116
- })(),
117
- });
116
+ const saved = savedHeadsRef.current.get(targetUrl);
117
+ const savedHead = saved?.requestKey === requestKey ? saved.head
118
+ : saved ? null : phiBuilderHistory.getHead(historyContext);
119
+ savedHeadsRef.current.set(targetUrl, { requestKey, head: savedHead });
120
+ setStored({ requestKey, ...next, savedHead });
118
121
  };
119
122
  void fetch(targetUrl, { method: "GET", cache: "no-store" })
120
123
  .then(async (response) => {
@@ -140,8 +143,8 @@ export function usePhiBuilderDraftStatusController({ commandWorkspace, effective
140
143
  return () => {
141
144
  cancelled = true;
142
145
  };
143
- }, [historyContext, targetUrl]);
144
- const current = stored === null || stored.requestKey !== targetUrl || subject === null
146
+ }, [historyContext, requestKey, targetUrl]);
147
+ const current = stored === null || stored.requestKey !== requestKey || subject === null
145
148
  ? null
146
149
  : stored.status === "error"
147
150
  ? { status: "error", revisionId: null, subject, error: stored.error }
@@ -169,6 +172,30 @@ export function usePhiBuilderDraftStatusController({ commandWorkspace, effective
169
172
  }
170
173
  }, [emitTo, serialized]);
171
174
  usePhiSignalListener((signal) => {
175
+ if (signal.scope === "area" &&
176
+ signal.channel === "draftStatus" &&
177
+ signal.action === "change" &&
178
+ signal.valueSchema === PHI_SIGNAL_VALUE_SCHEMAS.revisionsDraftStatus &&
179
+ signal.receiver === "broadcast" &&
180
+ signal.sender !== createPhiBuilderControllerAddress() &&
181
+ isPhiRecord(signal.value)) {
182
+ // Revisions names the exact draft it replaced. Ordinary status messages describe the canvas.
183
+ const { area, pageKey, areaModules } = signal.value;
184
+ const status = readPhiDraftStatusSignalValue(signal.value)?.status;
185
+ if (!isPhiBuilderAreaKey(area) || (status !== "draft" && status !== "published")) {
186
+ return;
187
+ }
188
+ if (areaModules === true) {
189
+ clearPhiBuilderDraftAllocation(createPhiBuilderDraftAllocationKey(area, "", "modules"));
190
+ }
191
+ else if (typeof pageKey === "string") {
192
+ invalidatePhiBuilderDraftContext({ workspace: "pages", area, pageKey });
193
+ }
194
+ else {
195
+ invalidatePhiBuilderDraftContext({ workspace: "structure", area });
196
+ }
197
+ return;
198
+ }
172
199
  if (signal.scope !== "area" ||
173
200
  signal.channel !== "draftStatus" ||
174
201
  signal.action !== "activate" ||
@@ -192,12 +219,12 @@ export function usePhiBuilderDraftStatusController({ commandWorkspace, effective
192
219
  }), [historyContext]);
193
220
  /** A save or publish of the workspace on screen: the state it stored, and the head it was taken at. */
194
221
  function reportSaved(status, revisionId, savedAt) {
195
- if (targetUrl === null) {
222
+ if (targetUrl === null || requestKey === null) {
196
223
  return;
197
224
  }
198
- savedHeadsRef.current.set(targetUrl, savedAt.head);
225
+ savedHeadsRef.current.set(targetUrl, { requestKey, head: savedAt.head });
199
226
  setStored({
200
- requestKey: targetUrl,
227
+ requestKey,
201
228
  status,
202
229
  revisionId,
203
230
  error: null,
@@ -84,14 +84,14 @@ export declare const PHI_BUILDER_RUNTIME_CONTROLLER_SERVER_DEFINITION: {
84
84
  id: string;
85
85
  channel: string;
86
86
  action: "change";
87
- valueType: "string";
88
- valueSchema?: undefined;
87
+ valueType: "json";
88
+ valueSchema: `${string}/signals/${string}`;
89
89
  } | {
90
90
  id: string;
91
91
  channel: string;
92
92
  action: "change";
93
- valueType: "json";
94
- valueSchema: `${string}/signals/${string}`;
93
+ valueType: "string";
94
+ valueSchema?: undefined;
95
95
  } | {
96
96
  id: string;
97
97
  channel: string;
@@ -5,9 +5,11 @@ import type { PhiAreaRootRoute, PhiAreaMeta } from "../../../../helpers/cms-area
5
5
  import type { PhiWorkspaceCatalogState } from "../../../../components/workspace/catalog-state";
6
6
  import { type PhiBuilderPageMetaPresentationLabels } from "../controller/definition";
7
7
  import type { PhiCmsTreeControllerSettings } from "../../../../types/cms";
8
+ import type { PhiAccessViewer } from "../../../../types/access";
8
9
  import { type PhiHistoryLabels } from "../../../../components/widgets/label-types/history";
9
10
  export type { PhiBuilderPageRegionKey, PhiBuilderRegionKey, PhiBuilderShellRegionKey, } from "../region-keys";
10
11
  export type PhiDeveloperBuilderWorkspaceControllerProps = {
12
+ viewer: PhiAccessViewer;
11
13
  shellPresetDraftsByArea?: Record<string, Record<string, PhiDeveloperBuilderRegionDraft>>;
12
14
  runtimeModuleDefinitions?: readonly PhiRuntimeModuleDefinition[];
13
15
  runtimeModuleIdsByArea?: Record<string, PhiRuntimeModuleId[]>;
@@ -27,4 +29,4 @@ export type PhiDeveloperBuilderWorkspaceControllerProps = {
27
29
  historyLabels: PhiHistoryLabels;
28
30
  signalRoutes?: PhiSignalRouteSet | null;
29
31
  };
30
- export declare function PhiDeveloperBuilderWorkspaceController({ shellPresetDraftsByArea, runtimeModuleDefinitions, runtimeModuleIdsByArea, modulePresetPagesByArea, areaPresetSourcesByArea, areaShellsByArea, navigationSurfacesByArea, unresolvedModuleIdsByArea, serverUnavailableModules, publicRouteClaims, publicRoutePaths, areaRootRoutesByArea, areaMetaByArea, areaControllerSettingsByArea, pageMetaLabels, historyLabels, signalRoutes, }: PhiDeveloperBuilderWorkspaceControllerProps): import("react").JSX.Element;
32
+ export declare function PhiDeveloperBuilderWorkspaceController({ viewer, shellPresetDraftsByArea, runtimeModuleDefinitions, runtimeModuleIdsByArea, modulePresetPagesByArea, areaPresetSourcesByArea, areaShellsByArea, navigationSurfacesByArea, unresolvedModuleIdsByArea, serverUnavailableModules, publicRouteClaims, publicRoutePaths, areaRootRoutesByArea, areaMetaByArea, areaControllerSettingsByArea, pageMetaLabels, historyLabels, signalRoutes, }: PhiDeveloperBuilderWorkspaceControllerProps): import("react").JSX.Element;
@@ -130,7 +130,7 @@ function usePhiDeveloperBuilderWorkspaceController(options) {
130
130
  const effectsWorkflowCorrelationRef = useRef(null);
131
131
  const initializedEffectsCorrelationRef = useRef(null);
132
132
  const effectsFormSubmissionRef = useRef(null);
133
- const { shellPresetDraftsByArea = {}, runtimeModuleDefinitions = [], runtimeModuleIdsByArea = {}, modulePresetPagesByArea = EMPTY_MODULE_PRESET_PAGES_BY_AREA, areaPresetSourcesByArea = {}, areaShellsByArea = EMPTY_AREA_SHELLS, navigationSurfacesByArea = {}, unresolvedModuleIdsByArea = EMPTY_RUNTIME_MODULE_IDS_BY_AREA, serverUnavailableModules = EMPTY_SERVER_UNAVAILABLE_MODULES, publicRouteClaims = EMPTY_PUBLIC_ROUTE_CLAIMS, publicRoutePaths = EMPTY_PUBLIC_ROUTE_PATHS, areaRootRoutesByArea = EMPTY_AREA_ROOT_ROUTES, areaMetaByArea = EMPTY_AREA_META, areaControllerSettingsByArea = EMPTY_AREA_CONTROLLER_SETTINGS, pageMetaLabels = PHI_BUILDER_PAGE_META_DEFAULT_PRESENTATION_LABELS, historyLabels, signalRoutes = null, } = options;
133
+ const { viewer, shellPresetDraftsByArea = {}, runtimeModuleDefinitions = [], runtimeModuleIdsByArea = {}, modulePresetPagesByArea = EMPTY_MODULE_PRESET_PAGES_BY_AREA, areaPresetSourcesByArea = {}, areaShellsByArea = EMPTY_AREA_SHELLS, navigationSurfacesByArea = {}, unresolvedModuleIdsByArea = EMPTY_RUNTIME_MODULE_IDS_BY_AREA, serverUnavailableModules = EMPTY_SERVER_UNAVAILABLE_MODULES, publicRouteClaims = EMPTY_PUBLIC_ROUTE_CLAIMS, publicRoutePaths = EMPTY_PUBLIC_ROUTE_PATHS, areaRootRoutesByArea = EMPTY_AREA_ROOT_ROUTES, areaMetaByArea = EMPTY_AREA_META, areaControllerSettingsByArea = EMPTY_AREA_CONTROLLER_SETTINGS, pageMetaLabels = PHI_BUILDER_PAGE_META_DEFAULT_PRESENTATION_LABELS, historyLabels, signalRoutes = null, } = options;
134
134
  /*
135
135
  * One declared output, delivered through every route written for it.
136
136
  *
@@ -187,6 +187,7 @@ function usePhiDeveloperBuilderWorkspaceController(options) {
187
187
  hasUnsavedChanges,
188
188
  reportSaved,
189
189
  state,
190
+ viewer,
190
191
  historyLabels,
191
192
  });
192
193
  const currentRuntimeModuleIdsByArea = state.runtimeModuleIdsByArea ?? EMPTY_RUNTIME_MODULE_IDS_BY_AREA;
@@ -211,24 +212,20 @@ function usePhiDeveloperBuilderWorkspaceController(options) {
211
212
  const publicRouteClaimsPreloadKey = useMemo(() => JSON.stringify(publicRouteClaims), [publicRouteClaims]);
212
213
  const serverUnavailableModulesPreloadKey = useMemo(() => JSON.stringify(serverUnavailableModules), [serverUnavailableModules]);
213
214
  const publicRoutePathsPreloadKey = useMemo(() => JSON.stringify(publicRoutePaths), [publicRoutePaths]);
214
- const areaRootRoutesPreloadKey = useMemo(() => JSON.stringify(areaRootRoutesByArea), [areaRootRoutesByArea]);
215
215
  /*
216
216
  * The Areas' root routes, handed to every workspace rather than to /shells alone.
217
217
  *
218
218
  * It is a baseline and not a draft: /pages reads it to leave `/` out of its page selector while the
219
- * root forwards, and nothing about that is an edit.
219
+ * root forwards. A save can update the client baseline between preloads, so a fresh server answer
220
+ * must be applied even when its content matches the answer the Controller received before that save.
220
221
  */
221
222
  useEffect(() => {
222
223
  setPhiDeveloperBuilderAreaRootRoutes(areaRootRoutesByArea);
223
- // The serialized preload is the identity that matters; the object is rebuilt on every render.
224
- // eslint-disable-next-line react-hooks/exhaustive-deps
225
- }, [areaRootRoutesPreloadKey]);
224
+ }, [areaRootRoutesByArea]);
226
225
  // What the Areas said about being found, read from the same revision and set the same way.
227
- const areaMetaPreloadKey = useMemo(() => JSON.stringify(areaMetaByArea), [areaMetaByArea]);
228
226
  useEffect(() => {
229
227
  setPhiDeveloperBuilderAreaMetaBaseline(areaMetaByArea);
230
- // eslint-disable-next-line react-hooks/exhaustive-deps
231
- }, [areaMetaPreloadKey]);
228
+ }, [areaMetaByArea]);
232
229
  // What each Shell tells its Controllers, carried into every save that states the Shell whole.
233
230
  const areaControllerSettingsPreloadKey = useMemo(() => JSON.stringify(areaControllerSettingsByArea), [areaControllerSettingsByArea]);
234
231
  useEffect(() => {
@@ -1444,8 +1441,9 @@ function usePhiDeveloperBuilderWorkspaceController(options) {
1444
1441
  */
1445
1442
  return _jsxs(_Fragment, { children: [pageMetaDialog, confirmDialog] });
1446
1443
  }
1447
- export function PhiDeveloperBuilderWorkspaceController({ shellPresetDraftsByArea = {}, runtimeModuleDefinitions = [], runtimeModuleIdsByArea = {}, modulePresetPagesByArea = EMPTY_MODULE_PRESET_PAGES_BY_AREA, areaPresetSourcesByArea = {}, areaShellsByArea = EMPTY_AREA_SHELLS, navigationSurfacesByArea = {}, unresolvedModuleIdsByArea = EMPTY_RUNTIME_MODULE_IDS_BY_AREA, serverUnavailableModules = EMPTY_SERVER_UNAVAILABLE_MODULES, publicRouteClaims = EMPTY_PUBLIC_ROUTE_CLAIMS, publicRoutePaths = EMPTY_PUBLIC_ROUTE_PATHS, areaRootRoutesByArea = EMPTY_AREA_ROOT_ROUTES, areaMetaByArea = EMPTY_AREA_META, areaControllerSettingsByArea = EMPTY_AREA_CONTROLLER_SETTINGS, pageMetaLabels = PHI_BUILDER_PAGE_META_DEFAULT_PRESENTATION_LABELS, historyLabels, signalRoutes = null, }) {
1444
+ export function PhiDeveloperBuilderWorkspaceController({ viewer, shellPresetDraftsByArea = {}, runtimeModuleDefinitions = [], runtimeModuleIdsByArea = {}, modulePresetPagesByArea = EMPTY_MODULE_PRESET_PAGES_BY_AREA, areaPresetSourcesByArea = {}, areaShellsByArea = EMPTY_AREA_SHELLS, navigationSurfacesByArea = {}, unresolvedModuleIdsByArea = EMPTY_RUNTIME_MODULE_IDS_BY_AREA, serverUnavailableModules = EMPTY_SERVER_UNAVAILABLE_MODULES, publicRouteClaims = EMPTY_PUBLIC_ROUTE_CLAIMS, publicRoutePaths = EMPTY_PUBLIC_ROUTE_PATHS, areaRootRoutesByArea = EMPTY_AREA_ROOT_ROUTES, areaMetaByArea = EMPTY_AREA_META, areaControllerSettingsByArea = EMPTY_AREA_CONTROLLER_SETTINGS, pageMetaLabels = PHI_BUILDER_PAGE_META_DEFAULT_PRESENTATION_LABELS, historyLabels, signalRoutes = null, }) {
1448
1445
  const controller = usePhiDeveloperBuilderWorkspaceController({
1446
+ viewer,
1449
1447
  shellPresetDraftsByArea,
1450
1448
  runtimeModuleDefinitions,
1451
1449
  runtimeModuleIdsByArea,
@@ -55,6 +55,7 @@ export type PhiDeveloperBuilderNodeSelection = {
55
55
  openWiring?: boolean;
56
56
  };
57
57
  export declare function selectPhiDeveloperBuilderNode(selection: PhiDeveloperBuilderNodeSelection): void;
58
+ export declare function getPhiBuilderDraftContextGeneration(context: string): number;
58
59
  export declare function patchPhiDeveloperBuilderState(next: Partial<Pick<PhiDeveloperBuilderState, "pickerWidgetCategoryFilters">>): void;
59
60
  type PhiBuilderRegionDraftMutationOptions = {
60
61
  history?: PhiBuilderHistoryRecording | null;
@@ -199,6 +200,15 @@ export declare function resetPhiBuilderSignalWiringSession(): void;
199
200
  */
200
201
  export declare function storePhiBuilderDraftAllocation(allocationKey: string, saved: PhiDeveloperBuilderDraftAllocation): void;
201
202
  export declare function clearPhiBuilderDraftAllocation(allocationKey: string): void;
203
+ /** A successful revision action supersedes the canvas and undo history of just that draft. */
204
+ export declare function invalidatePhiBuilderDraftContext(scope: {
205
+ workspace: "structure";
206
+ area: PhiDeveloperBuilderArea;
207
+ } | {
208
+ workspace: "pages";
209
+ area: PhiDeveloperBuilderArea;
210
+ pageKey: string;
211
+ }): void;
202
212
  /** Takes the next node sequence of a Draft, answering the allocation it was taken from. */
203
213
  export declare function takePhiBuilderDraftNodeSequence(allocationKey: string): PhiDeveloperBuilderDraftAllocation;
204
214
  /**
@@ -6,7 +6,9 @@ import { createPhiSignalCorrelationId } from "../../../components/runtime/runtim
6
6
  import { useRef, useSyncExternalStore } from "react";
7
7
  import { createPhiPluginStateStore } from "../../../components/state/plugin-state-store";
8
8
  import { phiWorkspaceCatalogStore, } from "../../../components/workspace/catalog-store";
9
- import { phiBuilderHistory } from "./history";
9
+ import { createPhiBuilderHistoryContext, phiBuilderHistory } from "./history";
10
+ import { createPhiBuilderDraftAllocationKey } from "./draft-allocation-key";
11
+ import { getPhiBuilderPageDraftKey, getPhiBuilderRegionDraftKey, PHI_BUILDER_PAGE_REGION_KEYS, PHI_BUILDER_SHELL_REGION_KEYS, } from "./region-keys";
10
12
  import { openPhiWorkspacePage, restorePhiWorkspaceCatalog, setPhiWorkspacePageKey, } from "./workspace-catalog-actions";
11
13
  export function normalizePhiDeveloperBuilderArea(scopeKey) {
12
14
  return isPhiBuilderAreaKey(scopeKey) ? scopeKey : "public";
@@ -204,6 +206,10 @@ export function selectPhiDeveloperBuilderNode(selection) {
204
206
  }));
205
207
  }
206
208
  const builderRegionDraftStore = createPhiPluginStateStore("@phis/ui/developer-region-drafts", () => ({}));
209
+ const builderDraftContextGenerations = new Map();
210
+ export function getPhiBuilderDraftContextGeneration(context) {
211
+ return builderDraftContextGenerations.get(context) ?? 0;
212
+ }
207
213
  export function patchPhiDeveloperBuilderState(next) {
208
214
  builderWorkspaceStore.patch(PHI_WORKSPACE_CATALOG_SCOPE, (current) => ({
209
215
  ...current,
@@ -813,6 +819,34 @@ export function clearPhiBuilderDraftAllocation(allocationKey) {
813
819
  return { ...current, draftAllocations };
814
820
  });
815
821
  }
822
+ /** A successful revision action supersedes the canvas and undo history of just that draft. */
823
+ export function invalidatePhiBuilderDraftContext(scope) {
824
+ const { area, workspace } = scope;
825
+ const context = createPhiBuilderHistoryContext(scope);
826
+ builderDraftContextGenerations.set(context, getPhiBuilderDraftContextGeneration(context) + 1);
827
+ const pageKey = workspace === "pages" ? scope.pageKey : null;
828
+ const regions = workspace === "pages" ? PHI_BUILDER_PAGE_REGION_KEYS : PHI_BUILDER_SHELL_REGION_KEYS;
829
+ restorePhiDeveloperRegionDrafts(Object.fromEntries(regions.map((region) => [getPhiBuilderRegionDraftKey(area, region, pageKey), null])));
830
+ if (pageKey === null) {
831
+ setPhiDeveloperBuilderAreaRootRoute(area, undefined);
832
+ restorePhiDeveloperBuilderAreaMeta(area, undefined);
833
+ }
834
+ else {
835
+ const metaKey = getPhiBuilderPageDraftKey(area, "page_meta", pageKey);
836
+ const deleteKey = getPhiBuilderPageDraftKey(area, "page_delete", pageKey);
837
+ builderWorkspaceStore.patch(PHI_WORKSPACE_CATALOG_SCOPE, (current) => {
838
+ const pageMetaDrafts = { ...current.pageMetaDrafts };
839
+ const deletedPageDrafts = { ...current.deletedPageDrafts };
840
+ const pageControllerSettings = { ...current.pageControllerSettings };
841
+ delete pageMetaDrafts[metaKey];
842
+ delete deletedPageDrafts[deleteKey];
843
+ delete pageControllerSettings[metaKey];
844
+ return { ...current, pageMetaDrafts, deletedPageDrafts, pageControllerSettings };
845
+ });
846
+ }
847
+ clearPhiBuilderDraftAllocation(createPhiBuilderDraftAllocationKey(area, pageKey ?? "", workspace === "pages" ? "page" : "area"));
848
+ phiBuilderHistory.clear(context);
849
+ }
816
850
  /** Takes the next node sequence of a Draft, answering the allocation it was taken from. */
817
851
  export function takePhiBuilderDraftNodeSequence(allocationKey) {
818
852
  const allocation = builderWorkspaceStore.getSnapshot(PHI_WORKSPACE_CATALOG_SCOPE).draftAllocations[allocationKey];
@@ -1,4 +1,5 @@
1
1
  import { type PhiBuilderPageCatalogArea, type PhiPresetPageNode } from "../../../helpers/cms-page-catalog";
2
+ import { type PhiAccessViewer } from "../../../types/access";
2
3
  import type { PhiDeveloperBuilderWorkspaceState } from "./developer-workspace-types";
3
4
  /**
4
5
  * The part of the workspace this reads, named rather than taken whole.
@@ -61,6 +62,11 @@ export declare function resolvePhiBuilderOfferedPageKey(state: PhiBuilderOffered
61
62
  pages: PhiPresetPageNode[];
62
63
  pageKey: string | null;
63
64
  };
65
+ /** The shell is drawn on the Page its Area leads to, below the landing at `/`. */
66
+ export declare function resolvePhiBuilderShellPreviewPage(state: PhiBuilderOfferedCatalogState, area: PhiBuilderPageCatalogArea, viewer: PhiAccessViewer): {
67
+ pages: PhiPresetPageNode[];
68
+ pageKey: string | null;
69
+ };
64
70
  /**
65
71
  * Whether the open Page is a root the Builder has taken over to construct itself.
66
72
  *
@@ -1,8 +1,10 @@
1
1
  "use client";
2
2
  import { resolvePhiBuilderAreaAsCmsArea } from "../../../constants/cms-areas";
3
+ import { isPhiCmsErrorPagePath } from "../../../constants/cms-error-pages";
3
4
  import { choosePhiAreaRootApplicant, resolvePhiAreaLandingSelection, } from "../../../helpers/cms-area-config";
4
- import { findPhiBuilderPageKeyFromStoragePath, normalizePhiBuilderCmsCatalogPath, resolvePhiBuilderActivePageCatalog, resolvePhiBuilderActivePageKey, resolvePhiBuilderRequestedPageKey, resolvePhiBuilderPageKeyFromCatalogPath, } from "../../../helpers/cms-page-catalog";
5
+ import { findPhiBuilderPageKeyFromStoragePath, findPhiPageNodePath, normalizePhiBuilderCmsCatalogPath, resolvePhiBuilderActivePageCatalog, resolvePhiBuilderActivePageKey, resolvePhiBuilderRequestedPageKey, resolvePhiBuilderPageKeyFromCatalogPath, } from "../../../helpers/cms-page-catalog";
5
6
  import { findFirstPhiCmsNavigationLinkPath } from "../../../components/regions/presets/navigation-redirect";
7
+ import { canPhiViewerAccess } from "../../../types/access";
6
8
  import { resolvePhiRuntimeAreaDefinition } from "../area-definitions";
7
9
  import { resolvePhiAreaRootRouteNavKey } from "../area-root-route";
8
10
  import { listPhiAlwaysActiveRuntimeModuleIds } from "../settings";
@@ -210,17 +212,44 @@ export function resolvePhiBuilderOfferedPageKey(state, area, requestedPageKey) {
210
212
  if (requested) {
211
213
  return { pages, pageKey: requested };
212
214
  }
213
- const rootRoute = readPhiBuilderStoredAreaRootRoute(state, area);
214
- const forwardTargetKey = rootRoute?.mode === "redirect"
215
- ? findPageKeyByReference(pages, rootRoute.targetLinkTarget.reference)
216
- : null;
217
215
  return {
218
216
  pages,
219
- pageKey: forwardTargetKey
217
+ pageKey: findAreaForwardTargetPageKey(state, area, pages)
220
218
  ?? findAreaNavigationEntryPageKey(state, area, pages)
221
219
  ?? resolvePhiBuilderActivePageKey(null, pages),
222
220
  };
223
221
  }
222
+ function findAreaForwardTargetPageKey(state, area, pages) {
223
+ const rootRoute = readPhiBuilderStoredAreaRootRoute(state, area);
224
+ return rootRoute?.mode === "redirect"
225
+ ? findPageKeyByReference(pages, rootRoute.targetLinkTarget.reference)
226
+ : null;
227
+ }
228
+ /** The shell is drawn on the Page its Area leads to, below the landing at `/`. */
229
+ export function resolvePhiBuilderShellPreviewPage(state, area, viewer) {
230
+ const pages = resolvePhiBuilderOfferedPageCatalog(state, area);
231
+ const isPreviewablePage = (key) => {
232
+ const page = key ? findPhiPageNodePath(pages, key)?.at(-1) : null;
233
+ if (!page?.storagePath || page.tombstoned || page.routeParameter) {
234
+ return false;
235
+ }
236
+ const path = normalizePhiBuilderCmsCatalogPath(page.storagePath);
237
+ return path !== "/" && !isPhiCmsErrorPagePath(path);
238
+ };
239
+ const forwardTargetKey = findAreaForwardTargetPageKey(state, area, pages);
240
+ if (isPreviewablePage(forwardTargetKey)) {
241
+ return { pages, pageKey: forwardTargetKey };
242
+ }
243
+ // Public has its Home entry in the header. Staff and App Area roots follow their own sidebar.
244
+ const navKey = area === "public" ? "public:header" : resolvePhiAreaRootRouteNavKey(resolvePhiBuilderAreaAsCmsArea(area));
245
+ const surface = state.navigationSurfacesByArea[area]?.find((candidate) => candidate.navKey === navKey);
246
+ const findPageKey = (path) => findPhiBuilderPageKeyFromStoragePath(area, path, pages);
247
+ const path = findFirstPhiCmsNavigationLinkPath(surface?.items ?? [], "/", {
248
+ isVisible: (item) => canPhiViewerAccess(viewer, item.accessPolicy),
249
+ acceptsPath: (candidate) => isPreviewablePage(findPageKey(candidate)),
250
+ });
251
+ return { pages, pageKey: path ? findPageKey(path) : null };
252
+ }
224
253
  /**
225
254
  * Where a root that forwards on its own actually lands.
226
255
  *
@@ -2,6 +2,8 @@ import type { PhiCmsContentWidgetNode, PhiCmsLayoutNode } from "../../../types/c
2
2
  import { type PhiCmsInstanceId } from "../../../types/cms-instance-id";
3
3
  import type { PhiDeveloperBuilderArea, PhiDeveloperBuilderRegionDraft, PhiDeveloperBuilderWorkspaceState } from "./developer-workspace-types";
4
4
  import type { PhiCmsWidgetContentBinding } from "../../../types/cms-plugins";
5
+ import type { PhiAccessViewer } from "../../../types/access";
6
+ import { type PhiBuilderOfferedCatalogState } from "./offered-page-catalog";
5
7
  import { type PhiPresetPageNode } from "../../../helpers/cms-page-catalog";
6
8
  import type { PhiCmsPresetIdentity, PhiCmsPresetSource } from "../../../types/cms-module-descriptors";
7
9
  import type { PhiBuilderPluginMeta, PhiBuilderWidgetMeta } from "../../../types/builder";
@@ -132,7 +134,8 @@ export declare function createPhiDeveloperBuilderPageDraft(input: {
132
134
  nextNodeSequence: number;
133
135
  previewHref: string | null;
134
136
  }>;
135
- export declare function previewPhiDeveloperBuilderDraft(state: Pick<PhiDeveloperBuilderWorkspaceState, "area" | "pageKey" | "modulePresetPagesByArea" | "customPages" | "persistedPageCatalogByArea" | "areaPresetSourcesByArea">, workspaceKind: PhiDeveloperBuilderWorkspaceKind, options?: {
137
+ export declare function previewPhiDeveloperBuilderDraft(state: Pick<PhiDeveloperBuilderWorkspaceState, "area" | "pageKey" | "areaPresetSourcesByArea"> & PhiBuilderOfferedCatalogState, workspaceKind: PhiDeveloperBuilderWorkspaceKind, options: {
138
+ viewer: PhiAccessViewer;
136
139
  pathname?: string | null;
137
140
  scope?: {
138
141
  area: PhiDeveloperBuilderArea;
@@ -10,6 +10,7 @@ import { stripPhiResolvedAssetProjections } from "../../../components/media/imag
10
10
  import { resolvePhiBuilderCmsStoragePath } from "../../../helpers/cms-paths";
11
11
  import { resolvePhiCmsWidgetContentBindingForConfig } from "../../../helpers/cms-content-binding";
12
12
  import { resolvePhiCmsRegionType } from "../../../helpers/cms-region-keys";
13
+ import { resolvePhiBuilderShellPreviewPage } from "./offered-page-catalog";
13
14
  import { resolvePhiAuthUiProviderModuleId, resolvePhiDeclaredMediaSpaces, resolvePhiDeclaredSeeds, isPhiRuntimeModuleSelectable, resolvePhiDeclaredThreadKinds, resolvePhiRuntimeModuleIdsForArea, } from "../../../plugins/runtime-modules/settings";
14
15
  import { createPhiBuilderDraftAllocationKey } from "./draft-allocation-key";
15
16
  import { clearPhiBuilderDraftAllocation, storePhiBuilderDraftAllocation, commitPhiDeveloperBuilderAreaConfig, readPhiBuilderEffectiveAreaRootRoute, readPhiBuilderEffectiveAreaMeta, } from "./developer-workspace-store";
@@ -783,9 +784,15 @@ export async function createPhiDeveloperBuilderPageDraft(input) {
783
784
  };
784
785
  }
785
786
  export async function previewPhiDeveloperBuilderDraft(state, workspaceKind, options) {
786
- const area = options?.scope?.area ?? state.area;
787
- const pageKey = options?.scope?.pageKey ?? state.pageKey;
788
- const pages = resolvePhiBuilderActivePageCatalog(area, state.modulePresetPagesByArea, state.customPages, state.persistedPageCatalogByArea);
787
+ const area = options.scope?.area ?? state.area;
788
+ const shellPreview = workspaceKind === "structure"
789
+ ? resolvePhiBuilderShellPreviewPage(state, area, options.viewer)
790
+ : null;
791
+ if (shellPreview?.pageKey === null) {
792
+ throw new Error(`No linked page in the ${area} Area is available for the shell preview.`);
793
+ }
794
+ const pageKey = shellPreview?.pageKey ?? options.scope?.pageKey ?? state.pageKey;
795
+ const pages = shellPreview?.pages ?? resolvePhiBuilderActivePageCatalog(area, state.modulePresetPagesByArea, state.customPages, state.persistedPageCatalogByArea);
789
796
  const pagePresetSource = resolvePhiBuilderPagePresetSource(pageKey, pages);
790
797
  const areaPresetSource = state.areaPresetSourcesByArea[area] ?? null;
791
798
  const draft = workspaceKind === "structure"
@@ -738,6 +738,11 @@ export declare const PHI_CORE_RUNTIME_MODULE_DEFINITION: {
738
738
  value: string;
739
739
  label: string;
740
740
  }[];
741
+ }, {
742
+ readonly key: "currencyField";
743
+ readonly type: "string";
744
+ readonly label: "Currency field";
745
+ readonly description: "The key of the field whose value is the currency of one amount, instead of a fixed currency.";
741
746
  }, {
742
747
  readonly key: "currencies";
743
748
  readonly type: "choice";
@@ -342,6 +342,11 @@ export declare const PHI_CORE_FORM_PROVIDER_DESCRIPTORS: {
342
342
  value: string;
343
343
  label: string;
344
344
  }[];
345
+ }, {
346
+ readonly key: "currencyField";
347
+ readonly type: "string";
348
+ readonly label: "Currency field";
349
+ readonly description: "The key of the field whose value is the currency of one amount, instead of a fixed currency.";
345
350
  }, {
346
351
  readonly key: "currencies";
347
352
  readonly type: "choice";
@@ -40,12 +40,12 @@ export function PhiSpacerWidget({ config, }) {
40
40
  flex: "1 1 auto",
41
41
  alignItems: "stretch",
42
42
  justifyContent: "center",
43
- }, children: _jsx("div", { style: {
43
+ }, children: _jsx("div", { className: isEditor ? "phi-builder-spacer-box" : undefined, style: {
44
44
  position: "relative",
45
45
  width: "100%",
46
46
  height: "100%",
47
- minWidth: 0,
48
- minHeight: 0,
47
+ minWidth: isEditor ? undefined : 0,
48
+ minHeight: isEditor ? undefined : 0,
49
49
  display: "flex",
50
50
  alignItems: "center",
51
51
  justifyContent: "center",
@@ -19,6 +19,7 @@ const SYNTHETIC_REGION_IDS = {
19
19
  regionFooterBottom: -33,
20
20
  };
21
21
  export async function buildPhiDefaultSiteAreaPresetTree({ page, runtime, presetKey, ownerModuleId, runtimeModuleArea, }) {
22
+ const isApp = runtimeModuleArea === "app";
22
23
  const PHI_DEFAULT_PUB_AREA_LAYOUT_IDS = createPhiPresetCmsInstanceIdMap({
23
24
  domain: "area",
24
25
  ownerModuleId,
@@ -161,7 +162,7 @@ export async function buildPhiDefaultSiteAreaPresetTree({ page, runtime, presetK
161
162
  label: "pub header main three column",
162
163
  config: {
163
164
  ...resolvePhiLayoutCreationPreset("threecol", "panel"),
164
- balancedSides: false,
165
+ balancedSides: isApp,
165
166
  justify: "space-between",
166
167
  contentAlign: "center",
167
168
  },
@@ -288,30 +289,36 @@ export async function buildPhiDefaultSiteAreaPresetTree({ page, runtime, presetK
288
289
  config: {},
289
290
  contentVersionId: null,
290
291
  },
291
- {
292
- id: PHI_DEFAULT_PUB_AREA_WIDGET_IDS.widgetNav,
293
- siteId: page.siteId,
294
- parentLayoutNodeId: PHI_DEFAULT_PUB_AREA_LAYOUT_IDS.layoutHeaderMain,
295
- widgetType: buildPhiCmsWidgetNamespacedTypeKey(resolvePhiCmsWidgetPluginKey("header-navigation"), "header-navigation"),
296
- slotIndex: PHI_CMS_THREE_COLUMN_LAYOUT_SLOT_INDEX.Middle,
297
- sortOrder: 10,
298
- status: 1,
299
- flags: 0,
300
- visibilityMask: page.visibilityMask,
301
- label: "pub header main navigation",
302
- /* The current entry on a rounded ground rather than a bar under it, in either mode. */
303
- config: {
304
- navKey: `${runtimeModuleArea}:header`,
305
- selectionStyle: "pill",
292
+ isApp
293
+ ? nodes.widget({
294
+ typeKey: "page-title",
295
+ id: PHI_DEFAULT_PUB_AREA_WIDGET_IDS.widgetPageTitle,
296
+ parentLayoutNodeId: PHI_DEFAULT_PUB_AREA_LAYOUT_IDS.layoutHeaderMain,
297
+ slotIndex: PHI_CMS_THREE_COLUMN_LAYOUT_SLOT_INDEX.Middle,
298
+ sortOrder: 10,
299
+ label: "Page title",
300
+ config: { display: "label" },
301
+ })
302
+ : {
303
+ id: PHI_DEFAULT_PUB_AREA_WIDGET_IDS.widgetNav,
304
+ siteId: page.siteId,
305
+ parentLayoutNodeId: PHI_DEFAULT_PUB_AREA_LAYOUT_IDS.layoutHeaderMain,
306
+ widgetType: buildPhiCmsWidgetNamespacedTypeKey(resolvePhiCmsWidgetPluginKey("header-navigation"), "header-navigation"),
307
+ slotIndex: PHI_CMS_THREE_COLUMN_LAYOUT_SLOT_INDEX.Middle,
308
+ sortOrder: 10,
309
+ status: 1,
310
+ flags: 0,
311
+ visibilityMask: page.visibilityMask,
312
+ label: "pub header main navigation",
313
+ /* The current entry on a rounded ground rather than a bar under it, in either mode. */
314
+ config: {
315
+ navKey: `${runtimeModuleArea}:header`,
316
+ selectionStyle: "pill",
317
+ },
318
+ contentVersionId: null,
306
319
  },
307
- contentVersionId: null,
308
- },
309
- /*
310
- * The magnifier, in Public only: the Area every visitor reads, and the one whose results Page it
311
- * opens. The App carries its box in its Sider where its preset puts one; the operator's Areas are
312
- * not searched. Before the locale switch, in the slot nothing else of this preset takes.
313
- */
314
- ...(runtimeModuleArea === "public"
320
+ // The magnifier leads to this Area's results Page wherever the Search Module is active.
321
+ ...(runtimeModuleArea === "public" || isApp
315
322
  ? [{
316
323
  id: PHI_DEFAULT_PUB_AREA_WIDGET_IDS.widgetSearch,
317
324
  siteId: page.siteId,
@@ -327,20 +334,20 @@ export async function buildPhiDefaultSiteAreaPresetTree({ page, runtime, presetK
327
334
  contentVersionId: null,
328
335
  }]
329
336
  : []),
330
- {
331
- id: PHI_DEFAULT_PUB_AREA_WIDGET_IDS.widgetLocale,
332
- siteId: page.siteId,
333
- parentLayoutNodeId: PHI_DEFAULT_PUB_AREA_LAYOUT_IDS.layoutHeaderActions,
334
- widgetType: buildPhiCmsWidgetNamespacedTypeKey(resolvePhiCmsWidgetPluginKey("locale"), "locale"),
335
- slotIndex: PHI_CMS_SEQUENTIAL_LAYOUT_SLOTS[1].slotIndex,
336
- sortOrder: 10,
337
- status: 1,
338
- flags: 0,
339
- visibilityMask: page.visibilityMask,
340
- label: "pub header main locale",
341
- config: {},
342
- contentVersionId: null,
343
- },
337
+ ...(!isApp ? [{
338
+ id: PHI_DEFAULT_PUB_AREA_WIDGET_IDS.widgetLocale,
339
+ siteId: page.siteId,
340
+ parentLayoutNodeId: PHI_DEFAULT_PUB_AREA_LAYOUT_IDS.layoutHeaderActions,
341
+ widgetType: buildPhiCmsWidgetNamespacedTypeKey(resolvePhiCmsWidgetPluginKey("locale"), "locale"),
342
+ slotIndex: PHI_CMS_SEQUENTIAL_LAYOUT_SLOTS[1].slotIndex,
343
+ sortOrder: 10,
344
+ status: 1,
345
+ flags: 0,
346
+ visibilityMask: page.visibilityMask,
347
+ label: "pub header main locale",
348
+ config: {},
349
+ contentVersionId: null,
350
+ }] : []),
344
351
  /*
345
352
  * The account trigger, in every Area that shares this preset.
346
353
  *
@@ -354,7 +361,7 @@ export async function buildPhiDefaultSiteAreaPresetTree({ page, runtime, presetK
354
361
  siteId: page.siteId,
355
362
  parentLayoutNodeId: PHI_DEFAULT_PUB_AREA_LAYOUT_IDS.layoutHeaderActions,
356
363
  widgetType: buildPhiCmsWidgetNamespacedTypeKey(resolvePhiCmsWidgetPluginKey("account"), "account"),
357
- slotIndex: PHI_CMS_SEQUENTIAL_LAYOUT_SLOTS[2].slotIndex,
364
+ slotIndex: PHI_CMS_SEQUENTIAL_LAYOUT_SLOTS[isApp ? 1 : 2].slotIndex,
358
365
  sortOrder: 20,
359
366
  status: 1,
360
367
  flags: 0,
@@ -1,4 +1,4 @@
1
1
  export declare const PHI_DEFAULT_PUB_AREA_PRESET_KEY = "public-area-preset";
2
2
  export declare const PHI_DEFAULT_PUB_AREA_LAYOUT_NODE_KEYS: readonly ["layoutHeaderMain", "layoutHeaderActions", "layoutHeaderBottom", "layoutSiderRight", "layoutFooterTop", "layoutFooterMain", "layoutFooterBottom"];
3
- export declare const PHI_DEFAULT_PUB_AREA_WIDGET_NODE_KEYS: readonly ["widgetBrand", "widgetNav", "widgetSearch", "widgetLocale", "widgetAccount", "widgetSiderRightNav", "widgetFooterLeft", "widgetFooterMiddle", "widgetFooterBottomText"];
3
+ export declare const PHI_DEFAULT_PUB_AREA_WIDGET_NODE_KEYS: readonly ["widgetBrand", "widgetNav", "widgetPageTitle", "widgetSearch", "widgetLocale", "widgetAccount", "widgetSiderRightNav", "widgetFooterLeft", "widgetFooterMiddle", "widgetFooterBottomText"];
4
4
  export declare const PHI_DEFAULT_PUB_AREA_COMPOSITION_NODE_KEYS: readonly ["widgetBrand", "widgetNav", "widgetLocale"];
@@ -11,6 +11,7 @@ export const PHI_DEFAULT_PUB_AREA_LAYOUT_NODE_KEYS = [
11
11
  export const PHI_DEFAULT_PUB_AREA_WIDGET_NODE_KEYS = [
12
12
  "widgetBrand",
13
13
  "widgetNav",
14
+ "widgetPageTitle",
14
15
  "widgetSearch",
15
16
  "widgetLocale",
16
17
  "widgetAccount",