@phis/ui 0.6.10 → 0.7.0

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 (115) hide show
  1. package/components/cms/phi-cms-area-render-scope.d.ts +2 -0
  2. package/components/cms/phi-cms-area-render-scope.js +1 -1
  3. package/components/cms/phi-cms-error-page.js +1 -1
  4. package/components/cms/phi-cms-page-render-scope.d.ts +0 -1
  5. package/components/cms/phi-cms-page-render-scope.js +1 -1
  6. package/components/cms/phi-cms-root-layout.js +1 -0
  7. package/components/cms/phi-cms-runtime-registry.d.ts +4 -4
  8. package/components/cms/phi-cms-runtime-registry.js +4 -4
  9. package/components/controls/phi-padding-control.js +18 -5
  10. package/components/layouts/layout-definitions.d.ts +8 -0
  11. package/components/regions/presets/phi-base-page-column.js +1 -2
  12. package/components/regions/presets/phi-header-top-actions-layout.d.ts +2 -2
  13. package/components/regions/presets/phi-header-top-actions-layout.js +2 -4
  14. package/components/regions/presets/phi-settings-page-shell-tree.js +0 -2
  15. package/components/widgets/label-sets/padding.js +2 -0
  16. package/components/widgets/label-sets/region.js +2 -0
  17. package/components/widgets/label-types/padding.d.ts +2 -0
  18. package/components/widgets/label-types/padding.js +1 -0
  19. package/components/widgets/label-types/region.d.ts +2 -0
  20. package/components/widgets/label-types/region.js +1 -0
  21. package/components/widgets/label-types/revisions.js +2 -2
  22. package/components/workspace/catalog-state.d.ts +17 -1
  23. package/components/workspace/catalog-store.js +1 -0
  24. package/gateway/dashboard-cards-route.js +4 -9
  25. package/gateway/form-handler-resolution.js +10 -34
  26. package/gateway/navigation-target-route.js +4 -10
  27. package/gateway/page-references-route.js +3 -8
  28. package/gateway/site-area.d.ts +43 -6
  29. package/gateway/site-area.js +70 -17
  30. package/helpers/cms-area-config.d.ts +36 -14
  31. package/helpers/cms-area-config.js +72 -26
  32. package/helpers/cms-dialog.d.ts +0 -1
  33. package/helpers/cms-dialog.js +0 -1
  34. package/helpers/cms-layout-defaults.d.ts +4 -0
  35. package/helpers/cms-layout-defaults.js +14 -17
  36. package/helpers/cms-region-keys.d.ts +1 -1
  37. package/helpers/page-layout-check.js +4 -1
  38. package/next/seo-routes.js +24 -28
  39. package/package.json +2 -2
  40. package/plugins/runtime-modules/accounting/presets.d.ts +0 -1
  41. package/plugins/runtime-modules/accounting/trees/phi-default-accounting-area-preset-tree.js +0 -2
  42. package/plugins/runtime-modules/admin/presets.d.ts +0 -1
  43. package/plugins/runtime-modules/admin/trees/phi-default-admin-area-preset-tree.js +0 -2
  44. package/plugins/runtime-modules/app/presets.d.ts +0 -1
  45. package/plugins/runtime-modules/app/trees/phi-default-app-area-preset-tree.js +0 -2
  46. package/plugins/runtime-modules/area-definitions.d.ts +17 -0
  47. package/plugins/runtime-modules/area-definitions.js +6 -0
  48. package/plugins/runtime-modules/asset/trees/phi-default-builder-media-page-tree.js +0 -2
  49. package/plugins/runtime-modules/builder/area-shell-presets.server.d.ts +21 -5
  50. package/plugins/runtime-modules/builder/area-shell-presets.server.js +171 -63
  51. package/plugins/runtime-modules/builder/clients/shells-workspace.js +12 -1
  52. package/plugins/runtime-modules/builder/controller/client.js +2 -0
  53. package/plugins/runtime-modules/builder/controller/definition.d.ts +1 -0
  54. package/plugins/runtime-modules/builder/controller/draft-command-controller.d.ts +2 -3
  55. package/plugins/runtime-modules/builder/controller/draft-command-controller.js +56 -25
  56. package/plugins/runtime-modules/builder/controller/draft-status-controller.js +13 -7
  57. package/plugins/runtime-modules/builder/controller/server-definition.d.ts +1 -0
  58. package/plugins/runtime-modules/builder/controller/server-definition.js +7 -4
  59. package/plugins/runtime-modules/builder/controller/workspace-controller.d.ts +2 -1
  60. package/plugins/runtime-modules/builder/controller/workspace-controller.js +9 -3
  61. package/plugins/runtime-modules/builder/data-providers.d.ts +1 -1
  62. package/plugins/runtime-modules/builder/definition.d.ts +1 -1
  63. package/plugins/runtime-modules/builder/developer-workspace-store.js +1 -0
  64. package/plugins/runtime-modules/builder/page-preset-catalog.server.d.ts +0 -2
  65. package/plugins/runtime-modules/builder/page-preset-catalog.server.js +0 -16
  66. package/plugins/runtime-modules/builder/persistence.d.ts +20 -25
  67. package/plugins/runtime-modules/builder/persistence.js +67 -75
  68. package/plugins/runtime-modules/builder/services/runtime-modules-table.d.ts +17 -0
  69. package/plugins/runtime-modules/builder/services/runtime-modules-table.js +79 -2
  70. package/plugins/runtime-modules/builder/trees/phi-builder-inspector-area-overlay-tree.server.js +0 -1
  71. package/plugins/runtime-modules/builder/trees/phi-default-builder-area-preset-tree.d.ts +0 -1
  72. package/plugins/runtime-modules/builder/trees/phi-default-builder-area-preset-tree.js +1 -10
  73. package/plugins/runtime-modules/builder/workspace-catalog-actions.d.ts +2 -1
  74. package/plugins/runtime-modules/builder/workspace-catalog-actions.js +3 -1
  75. package/plugins/runtime-modules/core/widgets/cascader/authoring.d.ts +1 -1
  76. package/plugins/runtime-modules/descriptor-compiler.d.ts +16 -2
  77. package/plugins/runtime-modules/descriptor-compiler.js +69 -13
  78. package/plugins/runtime-modules/editor/services/releases-table.js +26 -14
  79. package/plugins/runtime-modules/editor/trees/phi-default-editor-area-preset-tree.js +0 -2
  80. package/plugins/runtime-modules/groups/definition.d.ts +1 -1
  81. package/plugins/runtime-modules/localization/trees/phi-default-admin-locales-page-tree.js +0 -2
  82. package/plugins/runtime-modules/phi-default-site-area-preset-tree.js +0 -4
  83. package/plugins/runtime-modules/revisions/controller/client.js +13 -7
  84. package/plugins/runtime-modules/revisions/services/table.js +10 -3
  85. package/plugins/runtime-modules/revisions/trees/phi-default-builder-revisions-page-tree.js +0 -1
  86. package/plugins/runtime-modules/shell-tree-composition.d.ts +0 -2
  87. package/plugins/runtime-modules/shell-tree-composition.js +0 -3
  88. package/plugins/runtime-modules/theme/trees/phi-default-builder-theme-page-tree.js +0 -6
  89. package/plugins/runtime-modules/theme/widgets/brand-controls/client.js +17 -1
  90. package/server-helpers/area-root-door-warmup.d.ts +5 -2
  91. package/server-helpers/area-root-door-warmup.js +2 -10
  92. package/server-helpers/cms-area.d.ts +9 -1
  93. package/server-helpers/cms-area.js +16 -11
  94. package/server-helpers/cms-lookup.js +1 -1
  95. package/server-helpers/cms-request.d.ts +58 -13
  96. package/server-helpers/cms-request.js +103 -33
  97. package/server-helpers/cms-root.d.ts +4 -0
  98. package/server-helpers/cms-root.js +48 -35
  99. package/server-helpers/cms.d.ts +5 -5
  100. package/server-helpers/public-login-route.js +4 -9
  101. package/server-helpers/search-index.js +9 -14
  102. package/styles/shell.css +12 -0
  103. package/theme/antd-css-var-contract.d.ts +6 -0
  104. package/theme/antd-css-var-contract.js +6 -0
  105. package/theme/phi-theme-tokens.d.ts +3 -2
  106. package/theme/phi-theme-tokens.js +11 -1
  107. package/theme/phi-theme.d.ts +2 -0
  108. package/theme/phi-theme.js +2 -0
  109. package/theme/phi-tokens.d.ts +1 -0
  110. package/theme/phi-tokens.js +7 -0
  111. package/theme.d.ts +1 -1
  112. package/theme.js +1 -1
  113. package/types/cms-module-descriptors.d.ts +26 -1
  114. package/types/cms-plugins.d.ts +3 -0
  115. package/types/cms.d.ts +10 -3
@@ -3,13 +3,13 @@ import { applyPhiPresetTreesCurrentContent } from "../../../server-helpers/cms-b
3
3
  import { cache } from "react";
4
4
  import { cookies } from "next/headers";
5
5
  import { PHI_BUILDER_AREA_KEYS } from "../../../constants/cms-areas";
6
- import { getSiteAreaStructures } from "../../../gateway/site-area";
7
- import { readPhiRuntimeModuleIdsForArea } from "../../../plugins/runtime-modules/settings";
8
- import { readPhiAreaPresetRuntimeModuleIds, readPhiAreaPublicRoutePaths, readPhiAreaRootRoute, readPhiAreaMeta, resolvePhiAreaLandingSelection, } from "../../../helpers/cms-area-config";
6
+ import { getExactSiteArea, getSiteAreaStructures } from "../../../gateway/site-area";
7
+ import { listPhiAlwaysActiveRuntimeModuleIds, readPhiRuntimeModuleIdsForArea, } from "../../../plugins/runtime-modules/settings";
8
+ import { buildPhiAreaShellPresetConfig, readPhiAreaSelectionRuntimeModuleIds, readPhiAreaPublicRoutePaths, readPhiAreaRootRoute, readPhiAreaMeta, resolvePhiAreaLandingSelection, } from "../../../helpers/cms-area-config";
9
9
  import { PHI_BUILDER_SHELL_REGION_KEYS } from "./region-keys";
10
10
  import { buildPhiProjectedBuilderRegionDrafts } from "./draft-background-assets.server";
11
11
  import { resolvePhiBuilderAreaAsCmsArea } from "../../../constants/cms-areas";
12
- import { instantiatePhiCmsAreaShellPreset, resolvePhiCmsAreaShellPresetBinding, resolvePhiCmsDescriptorCatalog, } from "../../../plugins/runtime-modules/descriptor-compiler";
12
+ import { instantiatePhiCmsAreaShellPreset, listPhiCmsAreaShellProviders, resolvePhiCmsAreaBaseShellPresetBinding, resolvePhiCmsAreaShellPresetBinding, resolvePhiCmsDescriptorCatalog, } from "../../../plugins/runtime-modules/descriptor-compiler";
13
13
  import { PHI_BUILDER_AREA_SEARCH_PARAM, normalizePhiBuilderAreaSearchParam, } from "../../../helpers/cms-scope-search-params";
14
14
  import { readPhiServerApiCredentials } from "../../../helpers/phis-server-credentials";
15
15
  import { createPhiModuleMediaLoader } from "../../../gateway/server-module-media";
@@ -21,8 +21,9 @@ import { createPhiModuleMediaLoader } from "../../../gateway/server-module-media
21
21
  */
22
22
  const loadInstalledAreaShellPresetTrees = cache(async function loadInstalledAreaShellPresetTrees(runtime, runtimeModuleCatalog) {
23
23
  const catalog = resolvePhiCmsDescriptorCatalog(runtimeModuleCatalog);
24
+ const states = await loadPhiBuilderAreaStoredStates(runtime.site.key, runtime.locale.current, readPhiServerApiCredentials().apiBaseUrl, readPhiServerApiCredentials().internalToken, runtimeModuleCatalog);
24
25
  const installed = (await Promise.all(PHI_BUILDER_AREA_KEYS.map(async (area) => {
25
- const binding = resolvePhiCmsAreaShellPresetBinding(catalog, resolvePhiBuilderAreaAsCmsArea(area));
26
+ const binding = states.get(area)?.shellBinding ?? null;
26
27
  if (!binding) {
27
28
  return null;
28
29
  }
@@ -46,16 +47,6 @@ const loadInstalledAreaShellPresetTrees = cache(async function loadInstalledArea
46
47
  async function instantiateAreaShellPresetTree(runtime, area, runtimeModuleCatalog) {
47
48
  return (await loadInstalledAreaShellPresetTrees(runtime, runtimeModuleCatalog)).get(area) ?? null;
48
49
  }
49
- function resolveAreaPresetSource(area, runtimeModuleCatalog) {
50
- const binding = resolvePhiCmsAreaShellPresetBinding(resolvePhiCmsDescriptorCatalog(runtimeModuleCatalog), resolvePhiBuilderAreaAsCmsArea(area));
51
- if (!binding) {
52
- throw new Error(`Builder target Area "${area}" has no shell preset binding.`);
53
- }
54
- return {
55
- ownerModuleId: binding.descriptor.ownerModuleId,
56
- presetKey: binding.descriptor.presetKey,
57
- };
58
- }
59
50
  function buildInstalledShellDraftsForArea(runtime, area, runtimeModuleCatalog) {
60
51
  return instantiateAreaShellPresetTree(runtime, area, runtimeModuleCatalog).then((installedTree) => {
61
52
  if (!installedTree) {
@@ -81,48 +72,114 @@ function resolveStructureAreaPath(area) {
81
72
  return "/";
82
73
  }
83
74
  }
84
- function readRuntimeModulesConfigFromStructureTree(tree, area, runtimeModuleCatalog) {
85
- const presetTree = tree && "preset" in tree ? tree : null;
86
- const reading = readPhiRuntimeModuleIdsForArea(area, readPhiAreaPresetRuntimeModuleIds(presetTree, area), [...runtimeModuleCatalog.values()].map((entry) => entry.definition));
75
+ function readRuntimeModulesConfig(selection, area, runtimeModuleCatalog) {
76
+ const reading = readPhiRuntimeModuleIdsForArea(area, readPhiAreaSelectionRuntimeModuleIds(selection, area), [...runtimeModuleCatalog.values()].map((entry) => entry.definition));
87
77
  if (reading.unresolved.length > 0) {
88
78
  console.warn("[phi-builder] Stored Module selection names Modules this build cannot serve.", { area, unresolved: reading.unresolved });
89
79
  }
90
80
  return {
91
81
  moduleIds: reading.moduleIds,
92
82
  unresolvedModuleIds: reading.unresolved.map((entry) => entry.moduleId),
93
- publicRoutePaths: readPhiAreaPublicRoutePaths(presetTree?.preset.config),
83
+ publicRoutePaths: readPhiAreaPublicRoutePaths(selection?.config),
94
84
  };
95
85
  }
86
+ function toPresetIdentityKey(source) {
87
+ return `${source.ownerModuleId}\u001f${source.presetKey}`;
88
+ }
89
+ /** As many identities as Core answers in one structures read. */
90
+ const PHI_BUILDER_AREA_STRUCTURES_READ_LIMIT = 16;
91
+ /**
92
+ * The Area's effective shell under a selection, as the Builder sees it.
93
+ *
94
+ * The selection the Builder holds -- the open Module draft first -- with the Modules every Area runs
95
+ * anyway, so a Module that brings its own shell applies here as soon as it is selected, before the
96
+ * selection is published.
97
+ */
98
+ function resolveBuilderAreaShellBinding(area, selection, runtimeModuleCatalog) {
99
+ const catalog = resolvePhiCmsDescriptorCatalog(runtimeModuleCatalog);
100
+ const cmsArea = resolvePhiBuilderAreaAsCmsArea(area);
101
+ const definitions = [...runtimeModuleCatalog.values()].map((entry) => entry.definition);
102
+ const activeModuleIds = new Set([
103
+ ...readRuntimeModulesConfig(selection, area, runtimeModuleCatalog).moduleIds,
104
+ ...listPhiAlwaysActiveRuntimeModuleIds(cmsArea, definitions),
105
+ ]);
106
+ return resolvePhiCmsAreaShellPresetBinding(catalog, cmsArea, activeModuleIds);
107
+ }
96
108
  /**
97
- * What the Site stores about every Area's Shell: per Area the open structure draft, else what is
98
- * published, else nothing. One request for all of them, once per request.
109
+ * What the Site stores about every Area: per Area its Module selection and its one structure. One
110
+ * request for all of them, once per request.
99
111
  *
100
112
  * The Builder needs every Area on every view -- the Modules page edits their selections together, and
101
113
  * the Area switch carries the next Area's selection -- and read them with a draft read and, where no
102
114
  * draft was open, a published read per Area: eleven of a Builder view's seventeen Core calls
103
115
  * (AUDIT-2026-10-13, PM3). Keyed by the values the request turns on and never by an object, and read
104
- * whole, so the Shell drafts, the Area config and the Module selection all come from one revision. The
116
+ * whole, so the Shell drafts, the Area config and the Module selection all come from one answer. The
105
117
  * cookie header is read inside, where it is one value per request anyway.
118
+ *
119
+ * A structure answers only under the identity it is stored under, and an Area of `shellProviders:
120
+ * "module"` may stand on the base shell or on any Module's: so each Area is asked under every shell it
121
+ * could take, in the same request, and whichever answers is the one it stores. That is also how the
122
+ * Builder learns a structure stands on a shell the Area no longer takes.
106
123
  */
107
- const loadPhiBuilderAreaStructures = cache(async function loadPhiBuilderAreaStructures(siteKey, locale, apiBaseUrl, internalToken, runtimeModuleCatalog) {
108
- const areas = PHI_BUILDER_AREA_KEYS.map((area) => ({ area, ...resolveAreaPresetSource(area, runtimeModuleCatalog) }));
124
+ const loadPhiBuilderAreaStoredStates = cache(async function loadPhiBuilderAreaStoredStates(siteKey, locale, apiBaseUrl, internalToken, runtimeModuleCatalog) {
125
+ const catalog = resolvePhiCmsDescriptorCatalog(runtimeModuleCatalog);
126
+ const requests = PHI_BUILDER_AREA_KEYS.flatMap((area) => {
127
+ const cmsArea = resolvePhiBuilderAreaAsCmsArea(area);
128
+ const base = resolvePhiCmsAreaBaseShellPresetBinding(catalog, cmsArea);
129
+ if (!base) {
130
+ throw new Error(`Builder target Area "${area}" has no shell preset binding.`);
131
+ }
132
+ return [base, ...listPhiCmsAreaShellProviders(catalog, cmsArea)].map(({ descriptor }) => ({
133
+ area,
134
+ ownerModuleId: descriptor.ownerModuleId,
135
+ presetKey: descriptor.presetKey,
136
+ }));
137
+ });
109
138
  const cookieHeader = (await cookies()).toString();
139
+ const chunks = [];
140
+ for (let index = 0; index < requests.length; index += PHI_BUILDER_AREA_STRUCTURES_READ_LIMIT) {
141
+ chunks.push(requests.slice(index, index + PHI_BUILDER_AREA_STRUCTURES_READ_LIMIT));
142
+ }
110
143
  // A failed read is not "never asked": answering with the preset default would let the Builder show and
111
144
  // save it over what the Area actually stores.
112
- const structures = await getSiteAreaStructures({
145
+ const answers = (await Promise.all(chunks.map((areas) => getSiteAreaStructures({
113
146
  apiBaseUrl,
114
147
  internalToken,
115
148
  siteKey,
116
149
  locale,
117
150
  cookieHeader,
118
- areas: areas.map(({ area, ownerModuleId, presetKey }) => ({ area, ownerModuleId, presetKey })),
119
- }).catch((error) => {
120
- throw new Error("Failed to resolve the builder structure of the Areas.", { cause: error });
121
- });
122
- return new Map(structures.map((structure, index) => [areas[index].area, {
123
- draft: structure.draft?.preset ?? null,
124
- published: structure.draft ? null : structure.published?.preset ?? null,
125
- }]));
151
+ areas,
152
+ })))).flat();
153
+ const states = new Map();
154
+ for (const area of PHI_BUILDER_AREA_KEYS) {
155
+ const entries = answers.filter((answer) => answer.area === area);
156
+ if (entries.length === 0) {
157
+ throw new Error(`The builder structure read did not answer for area "${area}".`);
158
+ }
159
+ const { modules } = entries[0];
160
+ const selection = modules.draft ?? modules.published;
161
+ const answered = entries.find((entry) => entry.draft != null || entry.published != null) ?? null;
162
+ const storedPayload = answered?.draft ?? answered?.published ?? null;
163
+ const stored = answered && storedPayload
164
+ ? {
165
+ sourcePreset: storedPayload.sourcePreset,
166
+ draft: answered.draft?.preset ?? null,
167
+ published: answered.draft ? null : answered.published?.preset ?? null,
168
+ }
169
+ : null;
170
+ const shellBinding = resolveBuilderAreaShellBinding(area, selection, runtimeModuleCatalog);
171
+ const standsOnShell = stored != null && shellBinding != null &&
172
+ toPresetIdentityKey(stored.sourcePreset) === toPresetIdentityKey(shellBinding.descriptor);
173
+ states.set(area, {
174
+ modules: selection,
175
+ modulesDraftOpen: modules.draft != null,
176
+ stored,
177
+ shellBinding,
178
+ draft: standsOnShell ? stored.draft : null,
179
+ published: standsOnShell ? stored.published : null,
180
+ });
181
+ }
182
+ return states;
126
183
  });
127
184
  /**
128
185
  * The Areas whose structure has an open draft, from the one read every Builder view makes.
@@ -131,15 +188,15 @@ const loadPhiBuilderAreaStructures = cache(async function loadPhiBuilderAreaStru
131
188
  * and it is still one request for every Area.
132
189
  */
133
190
  export async function readPhiBuilderAreasWithOpenDraft(runtimeModuleCatalog, { siteKey, locale, apiBaseUrl, internalToken }) {
134
- const structures = await loadPhiBuilderAreaStructures(siteKey, locale, apiBaseUrl, internalToken, runtimeModuleCatalog);
135
- return PHI_BUILDER_AREA_KEYS.filter((area) => structures.get(area)?.draft != null);
191
+ const states = await loadPhiBuilderAreaStoredStates(siteKey, locale, apiBaseUrl, internalToken, runtimeModuleCatalog);
192
+ return PHI_BUILDER_AREA_KEYS.filter((area) => states.get(area)?.stored?.draft != null);
136
193
  }
137
194
  async function loadPhiBuilderAreaStructure(siteKey, locale, apiBaseUrl, internalToken, area, runtimeModuleCatalog) {
138
- const structure = (await loadPhiBuilderAreaStructures(siteKey, locale, apiBaseUrl, internalToken, runtimeModuleCatalog)).get(area);
139
- if (!structure) {
195
+ const state = (await loadPhiBuilderAreaStoredStates(siteKey, locale, apiBaseUrl, internalToken, runtimeModuleCatalog)).get(area);
196
+ if (!state) {
140
197
  throw new Error(`The builder structure read did not answer for area "${area}".`);
141
198
  }
142
- return structure;
199
+ return state;
143
200
  }
144
201
  const buildShellDraftsForArea = cache(async function buildShellDraftsForArea(runtime, siteKey, locale, apiBaseUrl, internalToken, area, runtimeModuleCatalog) {
145
202
  const { draft, published } = await loadPhiBuilderAreaStructure(siteKey, locale, apiBaseUrl, internalToken, area, runtimeModuleCatalog);
@@ -157,16 +214,22 @@ const buildShellDraftsForArea = cache(async function buildShellDraftsForArea(run
157
214
  * The config an Area currently states about its Shell, from the same three sources the drafts come from.
158
215
  *
159
216
  * An open structure draft first, because that is what the Builder is looking at; then what is
160
- * published; then nothing, which is the Area saying it has never been asked and letting the code-owned
161
- * preset answer. The installed preset is deliberately not consulted: it carries no config, and reading
162
- * a value out of it would put a stored-looking answer in front of a Builder who never stored one.
217
+ * published; then what the effective shell proposes (`PhiCmsAreaShellPresetDescriptor.settings`), which
218
+ * is what a visitor is served while nothing is stored on that shell. The dialog shows that proposal as
219
+ * the current answer, so the first save writes it rather than losing it. A shell that proposes nothing
220
+ * answers null: the Area was never asked, and phis-ui's defaults stand.
163
221
  *
164
222
  * Read once and read whole, because everything the Shell says about itself arrives in the same
165
223
  * revision: the root route and the two SEO answers are one fetch, not one each.
166
224
  */
167
225
  async function buildPhiBuilderAreaPresetConfig(runtime, area, runtimeModuleCatalog) {
168
- const { draft, published } = await loadPhiBuilderAreaStructure(runtime.site.key, runtime.locale.current, readPhiServerApiCredentials().apiBaseUrl, readPhiServerApiCredentials().internalToken, area, runtimeModuleCatalog);
169
- return (draft ?? published)?.preset.config ?? null;
226
+ const { draft, published, shellBinding } = await loadPhiBuilderAreaStructure(runtime.site.key, runtime.locale.current, readPhiServerApiCredentials().apiBaseUrl, readPhiServerApiCredentials().internalToken, area, runtimeModuleCatalog);
227
+ const stored = draft ?? published;
228
+ if (stored) {
229
+ return stored.preset.config ?? null;
230
+ }
231
+ const proposed = buildPhiAreaShellPresetConfig(shellBinding?.descriptor.settings);
232
+ return Object.keys(proposed).length > 0 ? proposed : null;
170
233
  }
171
234
  /** What an Area says its `/` resolves to. */
172
235
  async function buildPhiBuilderAreaRootRoute(runtime, area, runtimeModuleCatalog) {
@@ -201,34 +264,39 @@ export const buildPhiBuilderStructureShellDraftsForArea = cache(async function b
201
264
  return buildShellDraftsForArea(runtime, runtime.site.key, runtime.locale.current, readPhiServerApiCredentials().apiBaseUrl, readPhiServerApiCredentials().internalToken, area, runtimeModuleCatalog);
202
265
  });
203
266
  /**
204
- * What an Area's Modules namespace says, as the Builder sees it: the draft first, then what is
205
- * published, then the preset the code ships. Both answers come from one load because they are one
206
- * config -- reading the assigned Public addresses separately would fetch the Area a second time and,
207
- * worse, could read a different revision than the Module selection it belongs to.
267
+ * What an Area's Module selection says, as the Builder sees it: the open Module draft, then what is
268
+ * published, then the default list the Area ships with. Both answers come from one load because they are
269
+ * one config -- reading the assigned Public addresses separately could read a different revision than
270
+ * the Module selection it belongs to.
208
271
  */
209
- const buildRuntimeModulesConfigForArea = cache(async function buildRuntimeModulesConfigForArea(runtime, siteKey, locale, apiBaseUrl, internalToken, area, runtimeModuleCatalog) {
210
- const { draft, published } = await loadPhiBuilderAreaStructure(siteKey, locale, apiBaseUrl, internalToken, area, runtimeModuleCatalog);
211
- const stored = draft ?? published;
212
- if (stored) {
213
- return readRuntimeModulesConfigFromStructureTree(stored, area, runtimeModuleCatalog);
214
- }
215
- return readRuntimeModulesConfigFromStructureTree(await instantiateAreaShellPresetTree(runtime, area, runtimeModuleCatalog), area, runtimeModuleCatalog);
272
+ const buildRuntimeModulesConfigForArea = cache(async function buildRuntimeModulesConfigForArea(siteKey, locale, apiBaseUrl, internalToken, area, runtimeModuleCatalog) {
273
+ const { modules } = await loadPhiBuilderAreaStructure(siteKey, locale, apiBaseUrl, internalToken, area, runtimeModuleCatalog);
274
+ return readRuntimeModulesConfig(modules, area, runtimeModuleCatalog);
216
275
  });
217
276
  export function buildPhiBuilderRuntimeModulesConfigForArea(runtime, area, runtimeModuleCatalog) {
218
- return buildRuntimeModulesConfigForArea(runtime, runtime.site.key, runtime.locale.current, readPhiServerApiCredentials().apiBaseUrl, readPhiServerApiCredentials().internalToken, area, runtimeModuleCatalog);
277
+ return buildRuntimeModulesConfigForArea(runtime.site.key, runtime.locale.current, readPhiServerApiCredentials().apiBaseUrl, readPhiServerApiCredentials().internalToken, area, runtimeModuleCatalog);
219
278
  }
220
279
  /**
221
280
  * The Modules the published Area answers with, as opposed to the draft the Builder edits.
222
281
  *
223
- * Without a published revision the shell preset's default list decides, which is what a visitor is
224
- * served in that case too. Read for the collision dialog, which has to say whether an address it asks to
225
- * move already stands on the live Site.
282
+ * Without a published selection the Area's default list decides, which is what a visitor is served in
283
+ * that case too. Read for the collision dialog, which has to say whether an address it asks to move
284
+ * already stands on the live Site. The structures read answers the published selection only where no
285
+ * Module draft is open; with one open, the live read says what is published.
226
286
  */
227
287
  export const buildPhiBuilderPublishedRuntimeModuleIdsForArea = cache(async function buildPhiBuilderPublishedRuntimeModuleIdsForArea(runtime, area, runtimeModuleCatalog) {
228
288
  const { apiBaseUrl, internalToken } = readPhiServerApiCredentials();
229
- const { published } = await loadPhiBuilderAreaStructure(runtime.site.key, runtime.locale.current, apiBaseUrl, internalToken, area, runtimeModuleCatalog);
230
- const tree = published ?? await instantiateAreaShellPresetTree(runtime, area, runtimeModuleCatalog);
231
- return readRuntimeModulesConfigFromStructureTree(tree, area, runtimeModuleCatalog).moduleIds;
289
+ const state = await loadPhiBuilderAreaStructure(runtime.site.key, runtime.locale.current, apiBaseUrl, internalToken, area, runtimeModuleCatalog);
290
+ const published = state.modulesDraftOpen
291
+ ? (await getExactSiteArea({
292
+ apiBaseUrl,
293
+ internalToken,
294
+ siteKey: runtime.site.key,
295
+ path: resolveStructureAreaPath(area),
296
+ locale: runtime.locale.current,
297
+ }))?.modules ?? null
298
+ : state.modules;
299
+ return readRuntimeModulesConfig(published, area, runtimeModuleCatalog).moduleIds;
232
300
  });
233
301
  export async function buildPhiBuilderRuntimeModuleIdsForArea(runtime, area, runtimeModuleCatalog) {
234
302
  return (await buildPhiBuilderRuntimeModulesConfigForArea(runtime, area, runtimeModuleCatalog)).moduleIds;
@@ -293,8 +361,8 @@ export async function buildPhiBuilderAreaMetaByArea(runtime, runtimeModuleCatalo
293
361
  }
294
362
  /**
295
363
  * What every Area's Shell tells its Controllers, from the same chain the drafts come from: the open
296
- * structure draft, else what is published, else the code-owned Shell. Carried into every structure save
297
- * and every Module save baseline, which state the tree whole.
364
+ * structure draft, else what is published, else the code-owned Shell. Carried into every structure save,
365
+ * which states the tree whole.
298
366
  */
299
367
  export async function buildPhiBuilderAreaControllerSettingsByArea(runtime, runtimeModuleCatalog) {
300
368
  const areas = PHI_BUILDER_AREA_KEYS;
@@ -316,3 +384,43 @@ export async function buildPhiBuilderStructureShellPresetDraftsByArea(runtime, r
316
384
  ]));
317
385
  return Object.fromEntries(entries);
318
386
  }
387
+ /**
388
+ * The shell every Area takes, as the identity a structure save, a draft read and a Revisions scope name:
389
+ * the shell of the one Module that brings one and is selected there, else the base Module's.
390
+ */
391
+ export async function buildPhiBuilderAreaPresetSourcesByArea(runtime, runtimeModuleCatalog) {
392
+ const states = await loadPhiBuilderAreaStoredStates(runtime.site.key, runtime.locale.current, readPhiServerApiCredentials().apiBaseUrl, readPhiServerApiCredentials().internalToken, runtimeModuleCatalog);
393
+ const sources = {};
394
+ for (const area of PHI_BUILDER_AREA_KEYS) {
395
+ const descriptor = states.get(area)?.shellBinding?.descriptor;
396
+ if (descriptor) {
397
+ sources[area] = {
398
+ ownerModuleId: descriptor.ownerModuleId,
399
+ presetKey: descriptor.presetKey,
400
+ sourcePresetVersion: descriptor.shellPresetVersion,
401
+ };
402
+ }
403
+ }
404
+ return sources;
405
+ }
406
+ /**
407
+ * Per Area, which Modules bring a shell for it and which shell its stored structure stands on.
408
+ *
409
+ * The first is what the Modules table refuses a second provider by; the second is what it warns about
410
+ * when a provider is switched on over a stored structure of another shell, and what "Clear Area" and a
411
+ * refused structure save name.
412
+ */
413
+ export async function buildPhiBuilderAreaShellsByArea(runtime, runtimeModuleCatalog) {
414
+ const catalog = resolvePhiCmsDescriptorCatalog(runtimeModuleCatalog);
415
+ const states = await loadPhiBuilderAreaStoredStates(runtime.site.key, runtime.locale.current, readPhiServerApiCredentials().apiBaseUrl, readPhiServerApiCredentials().internalToken, runtimeModuleCatalog);
416
+ const shells = {};
417
+ for (const area of PHI_BUILDER_AREA_KEYS) {
418
+ const stored = states.get(area)?.stored?.sourcePreset ?? null;
419
+ shells[area] = {
420
+ providerModuleIds: listPhiCmsAreaShellProviders(catalog, resolvePhiBuilderAreaAsCmsArea(area))
421
+ .map((binding) => binding.moduleId),
422
+ storedSource: stored ? { ownerModuleId: stored.ownerModuleId, presetKey: stored.presetKey } : null,
423
+ };
424
+ }
425
+ return shells;
426
+ }
@@ -39,6 +39,17 @@ export function PhiDeveloperBuilderShellsWorkspaceWidgetClient({ serverPreviewRe
39
39
  */
40
40
  const siderLeftDraftKey = getPhiBuilderRegionDraftKey(area, "sider_left", pageKey);
41
41
  const siderLeftDraft = usePhiDeveloperRegionDraftsValue(useCallback((drafts) => drafts[siderLeftDraftKey] ?? null, [siderLeftDraftKey]));
42
+ /*
43
+ * Whose shell this is: the base Module's, or the one an active Module brings in its place. Named under
44
+ * the top Region, because editing it stores a structure for exactly that shell.
45
+ */
46
+ const shellOwnerModuleId = usePhiDeveloperBuilderStateValue((state) => state.areaPresetSourcesByArea[area]?.ownerModuleId ?? null);
47
+ const shellOwnerTitle = usePhiDeveloperBuilderStateValue((state) => shellOwnerModuleId
48
+ ? state.runtimeModuleDefinitions.find((definition) => definition.moduleId === shellOwnerModuleId)?.title ?? shellOwnerModuleId
49
+ : null);
50
+ const shellOwnerSubtitle = shellOwnerTitle
51
+ ? regionLabels.structure.surface.shellOwner.replace("%1", shellOwnerTitle)
52
+ : null;
42
53
  const siderLeftFullHeight = hasPhiConfigFlag((siderLeftDraft ?? structureShellDrafts?.[siderLeftDraftKey])?.regionConfig, PhiCmsFlags.FullHeight);
43
54
  const renderStructureRegion = (regionKey, title, subtitle) => {
44
55
  const fallbackDraft = structureShellDrafts?.[getPhiBuilderRegionDraftKey(area, regionKey, pageKey)] ?? null;
@@ -55,7 +66,7 @@ export function PhiDeveloperBuilderShellsWorkspaceWidgetClient({ serverPreviewRe
55
66
  [area]: fallbackDraft,
56
67
  }, serverPreview: serverPreviewRegions?.[regionKey] ?? null, pickerLabels: pickerLabels, containerClassName: "phi-builder-workspace-region-scaffold" }, regionKey));
57
68
  };
58
- return (_jsx(PhiStructureDndProvider, { children: _jsx("div", { style: { minWidth: 0, width: "100%", minHeight: 0, flex: "1 1 auto" }, children: _jsx(PhiStructureRegionLayout, { labels: regionLabels, headerTop: renderStructureRegion("header_top", regionLabels.regions.headerTop.title), headerMain: renderStructureRegion("header_main", regionLabels.regions.headerMain.title), siderLeft: renderStructureRegion("sider_left", regionLabels.regions.siderLeft.title, siderLeftFullHeight
69
+ return (_jsx(PhiStructureDndProvider, { children: _jsx("div", { style: { minWidth: 0, width: "100%", minHeight: 0, flex: "1 1 auto" }, children: _jsx(PhiStructureRegionLayout, { labels: regionLabels, headerTop: renderStructureRegion("header_top", regionLabels.regions.headerTop.title, shellOwnerSubtitle), headerMain: renderStructureRegion("header_main", regionLabels.regions.headerMain.title), siderLeft: renderStructureRegion("sider_left", regionLabels.regions.siderLeft.title, siderLeftFullHeight
59
70
  ? regionLabels.structure.surface.siderSpansShell
60
71
  : regionLabels.structure.surface.siderBesideContent), footerMain: renderStructureRegion("footer_main", regionLabels.regions.footerMain.title), footerBottom: renderStructureRegion("footer_bottom", regionLabels.regions.footerBottom.title), style: {
61
72
  minWidth: 0,
@@ -11,6 +11,7 @@ export const PHI_BUILDER_RUNTIME_CONTROLLER_PLUGIN = {
11
11
  !preloadData.runtimeModuleIdsByArea ||
12
12
  !preloadData.modulePresetPagesByArea ||
13
13
  !preloadData.areaPresetSourcesByArea ||
14
+ !preloadData.areaShellsByArea ||
14
15
  !preloadData.navigationSurfacesByArea ||
15
16
  !preloadData.unresolvedModuleIdsByArea ||
16
17
  !preloadData.serverUnavailableModules ||
@@ -30,6 +31,7 @@ export const PHI_BUILDER_RUNTIME_CONTROLLER_PLUGIN = {
30
31
  runtimeModuleIdsByArea: preloadData.runtimeModuleIdsByArea,
31
32
  modulePresetPagesByArea: preloadData.modulePresetPagesByArea,
32
33
  areaPresetSourcesByArea: preloadData.areaPresetSourcesByArea,
34
+ areaShellsByArea: preloadData.areaShellsByArea,
33
35
  navigationSurfacesByArea: preloadData.navigationSurfacesByArea,
34
36
  unresolvedModuleIdsByArea: preloadData.unresolvedModuleIdsByArea,
35
37
  serverUnavailableModules: preloadData.serverUnavailableModules,
@@ -44,6 +44,7 @@ export type PhiBuilderRuntimeControllerPreload = {
44
44
  areaControllerSettingsByArea: Record<string, PhiCmsTreeControllerSettings>;
45
45
  modulePresetPagesByArea: PhiBuilderModulePresetPagesByArea;
46
46
  areaPresetSourcesByArea: Partial<Record<PhiBuilderAreaKey, PhiCmsPresetSource>>;
47
+ areaShellsByArea: PhiWorkspaceCatalogState["areaShellsByArea"];
47
48
  navigationSurfacesByArea: Partial<Record<PhiBuilderAreaKey, readonly PhiCmsResolvedNavigationSurface[]>>;
48
49
  pageMetaLabels: PhiBuilderPageMetaPresentationLabels;
49
50
  historyLabels: PhiHistoryLabels;
@@ -1,8 +1,8 @@
1
1
  import { type PhiHistoryLabels } from "../../../../components/widgets/label-types/history";
2
2
  import type { PhiBuilderSavedHistoryHead } from "./draft-status-controller";
3
- import type { PhiDeveloperBuilderArea, PhiDeveloperBuilderRegionDraft, PhiDeveloperBuilderWorkspaceState } from "../developer-workspace-types";
3
+ import type { PhiDeveloperBuilderArea, PhiDeveloperBuilderWorkspaceState } from "../developer-workspace-types";
4
4
  export type PhiDeveloperBuilderToolbarCommand = "save" | "preview" | "publish" | "undo" | "redo" | "reset";
5
- export declare function usePhiBuilderDraftCommandController({ effectiveArea, effectiveNavKey, effectivePageKey, pathname, captureHistoryHead, reportSaved, hasUnsavedChanges, shellPresetDraftsByArea, state, historyLabels, }: {
5
+ export declare function usePhiBuilderDraftCommandController({ effectiveArea, effectiveNavKey, effectivePageKey, pathname, captureHistoryHead, reportSaved, hasUnsavedChanges, state, historyLabels, }: {
6
6
  effectiveArea: PhiDeveloperBuilderArea;
7
7
  effectiveNavKey: string;
8
8
  effectivePageKey: string;
@@ -13,7 +13,6 @@ export declare function usePhiBuilderDraftCommandController({ effectiveArea, eff
13
13
  reportSaved: (status: "draft" | "published", revisionId: number | null, savedAt: PhiBuilderSavedHistoryHead) => void;
14
14
  /** Whether the workspace on screen holds edits no stored revision has. */
15
15
  hasUnsavedChanges: boolean;
16
- shellPresetDraftsByArea: Record<string, Record<string, PhiDeveloperBuilderRegionDraft>>;
17
16
  state: PhiDeveloperBuilderWorkspaceState;
18
17
  /** What an undo or redo says it moved, in the author's language. */
19
18
  historyLabels: PhiHistoryLabels;
@@ -9,7 +9,7 @@ import { getPhiBuilderPageDraftKey } from "../region-keys";
9
9
  import { resolvePhiBuilderCmsStoragePath } from "../../../../helpers/cms-paths";
10
10
  import { resolvePhiBuilderActivePageCatalog, resolvePhiBuilderActivePageKey, resolvePhiBuilderPagePresetSource, } from "../../../../helpers/cms-page-catalog";
11
11
  import { deleteCmsDraft } from "../../../../helpers/cms-draft-delete";
12
- import { buildPhiBuilderLiveHref, clearPhiDeveloperBuilderDraftAllocation, createPhiDeveloperBuilderInitialPageDrafts, getPhiDeveloperBuilderModulesDraftAllocation, savePhiDeveloperBuilderModulesDraft, publishPhiDeveloperBuilderModulesDraft, previewPhiDeveloperBuilderDraft, publishPhiDeveloperBuilderDraft, savePhiDeveloperBuilderDraft, } from "../persistence";
12
+ import { buildPhiBuilderLiveHref, clearPhiDeveloperBuilderDraftAllocation, createPhiDeveloperBuilderInitialPageDrafts, getPhiDeveloperBuilderModulesDraftAllocation, savePhiDeveloperBuilderModulesDraft, publishPhiDeveloperBuilderModulesDraft, previewPhiDeveloperBuilderDraft, publishPhiDeveloperBuilderDraft, savePhiDeveloperBuilderDraft, PhiBuilderAreaStructureTakenError, } from "../persistence";
13
13
  import { clearPhiBuilderNavigationDraft, getPhiBuilderNavigationDraftSnapshot, updatePhiBuilderNavigationDraft, restorePhiBuilderNavigationDraft, setPhiBuilderNavigationDraft, } from "../navigation-store";
14
14
  import { deletePhiBuilderNavigationDraft, loadPhiBuilderNavigationDraft, loadPhiBuilderNavigationScope, publishPhiBuilderNavigationDraft, savePhiBuilderNavigationDraft, } from "../navigation-persistence";
15
15
  import { clearPhiBuilderModuleAreasDirty, getPhiDeveloperRegionDraftsSnapshot, markPhiBuilderPageDeleted, restorePhiBuilderWorkspaceState, mergePhiDeveloperRegionDrafts, restorePhiDeveloperBuilderAreaMeta, restorePhiDeveloperRegionDrafts, setPhiDeveloperBuilderAreaRootRoute, } from "../developer-workspace-store";
@@ -19,7 +19,7 @@ import { usePhiBuilderModuleMetas } from "../plugin-meta-store";
19
19
  import { setPhiWorkspaceModuleSelection } from "../workspace-catalog-actions";
20
20
  import { applyPhiBuilderNavigationFolderTargets, refreshPhiBuilderNavigationFolderAddresses, } from "../navigation-folder-address";
21
21
  import { createPhiBuilderNavigationPathContext } from "../navigation-path-context";
22
- export function usePhiBuilderDraftCommandController({ effectiveArea, effectiveNavKey, effectivePageKey, pathname, captureHistoryHead, reportSaved, hasUnsavedChanges, shellPresetDraftsByArea, state, historyLabels, }) {
22
+ export function usePhiBuilderDraftCommandController({ effectiveArea, effectiveNavKey, effectivePageKey, pathname, captureHistoryHead, reportSaved, hasUnsavedChanges, state, historyLabels, }) {
23
23
  /*
24
24
  * Every one of these is a command from a toolbar somewhere else, so there is nothing on screen to
25
25
  * hang a Popconfirm on. Drawn as a Dialog by this Controller rather than asked of Ant Design's
@@ -126,12 +126,9 @@ export function usePhiBuilderDraftCommandController({ effectiveArea, effectiveNa
126
126
  * Asked side by side, and a failed read is the command's failure: taking it for "no draft" told the
127
127
  * author there was nothing to publish while a draft stood.
128
128
  */
129
- const asked = await Promise.all(Object.entries(state.areaPresetSourcesByArea).flatMap(([area, source]) => source
130
- ? [getPhiDeveloperBuilderModulesDraftAllocation({
131
- area: area,
132
- areaPresetSource: source,
133
- }).then((allocation) => allocation ? area : null)]
134
- : []));
129
+ const asked = await Promise.all(Object.keys(state.areaPresetSourcesByArea).map((area) => getPhiDeveloperBuilderModulesDraftAllocation({
130
+ area: area,
131
+ }).then((allocation) => allocation ? area : null)));
135
132
  return asked.filter((area) => area !== null);
136
133
  }
137
134
  async function runSaveCommand(workspaceKind) {
@@ -144,18 +141,7 @@ export function usePhiBuilderDraftCommandController({ effectiveArea, effectiveNa
144
141
  const savedAt = captureHistoryHead();
145
142
  let lastRevisionId = null;
146
143
  for (const area of areas) {
147
- const modulesResult = await savePhiDeveloperBuilderModulesDraft(state, getPhiDeveloperRegionDraftsSnapshot(), {
148
- builderPlugins: builderModuleMetas.plugins,
149
- scope: { area },
150
- /*
151
- * The Area's code-owned Shell, which this controller holds on every Builder page -- the same
152
- * drafts "reset shell" restores from. A Module selection for an Area nobody has saved yet
153
- * needs a Shell baseline, and the Modules workspace hydrates no region drafts of its own: it
154
- * edits a selection rather than a structure. Without this the save asked the operator to go
155
- * and create a Shell that already exists in code.
156
- */
157
- shellPresetDrafts: shellPresetDraftsByArea[area] ?? null,
158
- });
144
+ const modulesResult = await savePhiDeveloperBuilderModulesDraft(state, { scope: { area } });
159
145
  lastRevisionId = modulesResult.revisionId;
160
146
  }
161
147
  reportSaved("draft", lastRevisionId, savedAt);
@@ -206,11 +192,7 @@ export function usePhiBuilderDraftCommandController({ effectiveArea, effectiveNa
206
192
  }
207
193
  const savedAt = captureHistoryHead();
208
194
  for (const area of areas) {
209
- await publishPhiDeveloperBuilderModulesDraft(state, getPhiDeveloperRegionDraftsSnapshot(), {
210
- builderPlugins: builderModuleMetas.plugins,
211
- scope: { area },
212
- shellPresetDrafts: shellPresetDraftsByArea[area] ?? null,
213
- });
195
+ await publishPhiDeveloperBuilderModulesDraft(state, { scope: { area } });
214
196
  }
215
197
  clearPhiBuilderModuleAreasDirty();
216
198
  reportSaved("published", null, savedAt);
@@ -465,6 +447,51 @@ export function usePhiBuilderDraftCommandController({ effectiveArea, effectiveNa
465
447
  },
466
448
  });
467
449
  }
450
+ /**
451
+ * A structure save Core refused because the Area stores its one structure under another shell -- the
452
+ * base shell's, saved before a Module that brings its own was switched on. The stored structure is
453
+ * cleared only when asked, and the Module selection stays; then the command runs again.
454
+ */
455
+ function confirmClearStoredStructure(error, command, workspaceKind) {
456
+ confirm({
457
+ title: "Clear the stored structure?",
458
+ content: `${error.message} Clearing removes the structure saved for that shell, with its drafts and ` +
459
+ "revisions, and changes nothing live while that shell is not the one the Area takes. Then this " +
460
+ "structure is saved.",
461
+ confirmLabel: "Clear and save",
462
+ danger: true,
463
+ cancelLabel: "Cancel",
464
+ onConfirm: async () => {
465
+ if (activeDraftActionRef.current != null) {
466
+ return;
467
+ }
468
+ setActiveDraftAction(command);
469
+ try {
470
+ await deleteCmsDraft("/api/site/cms/area/override", {
471
+ area: error.area,
472
+ ownerModuleId: error.storedSource.ownerModuleId,
473
+ presetKey: error.storedSource.presetKey,
474
+ });
475
+ clearPhiDeveloperBuilderDraftAllocation({
476
+ area: error.area,
477
+ pageKey: effectivePageKey,
478
+ workspaceKind: "structure",
479
+ });
480
+ await (command === "save" ? runSaveCommand(workspaceKind) : runPublishCommand(workspaceKind));
481
+ }
482
+ catch (retryError) {
483
+ showMessage({
484
+ level: "error",
485
+ content: retryError instanceof Error ? retryError.message : "Clearing the stored structure failed.",
486
+ });
487
+ throw retryError;
488
+ }
489
+ finally {
490
+ setActiveDraftAction(null);
491
+ }
492
+ },
493
+ });
494
+ }
468
495
  function runResetCommand(workspaceKind) {
469
496
  if (workspaceKind === "structure" || workspaceKind === "pages") {
470
497
  confirmDiscardDraft(workspaceKind);
@@ -555,6 +582,10 @@ export function usePhiBuilderDraftCommandController({ effectiveArea, effectiveNa
555
582
  : runPreviewCommand(workspaceKind);
556
583
  action
557
584
  .catch((error) => {
585
+ if (error instanceof PhiBuilderAreaStructureTakenError && (command === "save" || command === "publish")) {
586
+ confirmClearStoredStructure(error, command, workspaceKind);
587
+ return;
588
+ }
558
589
  const fallback = command === "save"
559
590
  ? "CMS draft save failed."
560
591
  : command === "publish"
@@ -39,6 +39,18 @@ function resolveTarget(workspace, area, pageKey, navKey, state) {
39
39
  if (!state.catalogHydrated) {
40
40
  return null;
41
41
  }
42
+ /*
43
+ * The Module selection has its own Draft, stored apart from the structure and naming no shell, so it
44
+ * reports its own status: asking the structure endpoint here would show the shell's Draft on a page
45
+ * that cannot save one. The structure's Draft is asked under the shell the Area takes.
46
+ */
47
+ if (workspace === "modules") {
48
+ return {
49
+ url: `/api/site/cms/area/modules/draft?${new URLSearchParams({ area }).toString()}`,
50
+ subject: area === "public" ? "/" : `${area}/`,
51
+ historyContext: createPhiBuilderHistoryContext({ workspace }),
52
+ };
53
+ }
42
54
  const sourcePreset = state.areaPresetSourcesByArea[area] ?? null;
43
55
  if (!sourcePreset) {
44
56
  throw new Error(`Builder target Area "${area}" has no source preset identity.`);
@@ -48,14 +60,8 @@ function resolveTarget(workspace, area, pageKey, navKey, state) {
48
60
  ownerModuleId: sourcePreset.ownerModuleId,
49
61
  presetKey: sourcePreset.presetKey,
50
62
  }).toString();
51
- /*
52
- * The Module selection has its own Draft on the same Area revision, so it reports its own status:
53
- * asking the structure endpoint here would show the shell's Draft on a page that cannot save one.
54
- */
55
63
  return {
56
- url: workspace === "modules"
57
- ? `/api/site/cms/area/modules/draft?${query}`
58
- : `/api/site/cms/area/draft?${query}`,
64
+ url: `/api/site/cms/area/draft?${query}`,
59
65
  subject: area === "public" ? "/" : `${area}/`,
60
66
  historyContext: createPhiBuilderHistoryContext({ workspace, area }),
61
67
  };
@@ -20,6 +20,7 @@ export declare const PHI_BUILDER_RUNTIME_CONTROLLER_SERVER_DEFINITION: {
20
20
  areaControllerSettingsByArea: Record<string, import("../../../../types/cms").PhiCmsTreeControllerSettings>;
21
21
  modulePresetPagesByArea: import("../../../../helpers/cms-page-catalog").PhiBuilderModulePresetPagesByArea;
22
22
  areaPresetSourcesByArea: Partial<Record<"public" | "app" | "admin" | "builder" | "editor" | "accounting", import("../../../../types").PhiCmsPresetSource>>;
23
+ areaShellsByArea: Partial<Record<"public" | "app" | "admin" | "builder" | "editor" | "accounting", import("../../../../components/workspace/catalog-state").PhiWorkspaceAreaShellState>>;
23
24
  navigationSurfacesByArea: Partial<Record<"public" | "app" | "admin" | "builder" | "editor" | "accounting", readonly import("../../../../types/cms-module-descriptors").PhiCmsResolvedNavigationSurface[]>>;
24
25
  pageMetaLabels: {
25
26
  createTitle: string;