@contentstack/studio-client 4.1.0 → 4.2.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.
- package/dist/breakpoints/BreakpointManager.js +3 -2
- package/dist/breakpoints/BreakpointManager.js.map +1 -1
- package/dist/breakpoints/breakpoint-origin.js +30 -0
- package/dist/breakpoints/breakpoint-origin.js.map +1 -0
- package/dist/canvas/canvas.type.js +1 -1
- package/dist/canvas/canvas.utils.js +165 -4
- package/dist/canvas/canvas.utils.js.map +1 -1
- package/dist/composable-studio/binding-defect-report.js +106 -0
- package/dist/composable-studio/binding-defect-report.js.map +1 -0
- package/dist/composable-studio/build-scoped-data.js +21 -11
- package/dist/composable-studio/build-scoped-data.js.map +1 -1
- package/dist/composable-studio/collect-data-needs.js +1 -1
- package/dist/composable-studio/data/pre-process-static-values.js +89 -19
- package/dist/composable-studio/data/pre-process-static-values.js.map +1 -1
- package/dist/composable-studio/delivery-setup-check.js +92 -0
- package/dist/composable-studio/delivery-setup-check.js.map +1 -0
- package/dist/composable-studio/resolution-failure-spec.js +53 -0
- package/dist/composable-studio/resolution-failure-spec.js.map +1 -0
- package/dist/composable-studio/resolution-telemetry.js +68 -0
- package/dist/composable-studio/resolution-telemetry.js.map +1 -0
- package/dist/composable-studio/sdk.js +683 -551
- package/dist/composable-studio/sdk.js.map +1 -1
- package/dist/composable-studio/section-binding/compute-all-section-auto-bindings.js +146 -0
- package/dist/composable-studio/section-binding/compute-all-section-auto-bindings.js.map +1 -0
- package/dist/composable-studio/section-binding/constants.js +27 -0
- package/dist/composable-studio/section-binding/constants.js.map +1 -0
- package/dist/composable-studio/section-binding/index.js +20 -0
- package/dist/composable-studio/section-binding/index.js.map +1 -0
- package/dist/composable-studio/section-binding/schema-path.js +112 -0
- package/dist/composable-studio/section-binding/schema-path.js.map +1 -0
- package/dist/composable-studio/section-binding/section-composition-auto-binding.js +815 -0
- package/dist/composable-studio/section-binding/section-composition-auto-binding.js.map +1 -0
- package/dist/composable-studio/section-binding/section-compositions.js +349 -0
- package/dist/composable-studio/section-binding/section-compositions.js.map +1 -0
- package/dist/composable-studio/section-binding/section-internal-ref-introspection.js +72 -0
- package/dist/composable-studio/section-binding/section-internal-ref-introspection.js.map +1 -0
- package/dist/composable-studio/section-binding/self-describe-section-bindings.js +132 -0
- package/dist/composable-studio/section-binding/self-describe-section-bindings.js.map +1 -0
- package/dist/composable-studio/section-binding/serialization.js +33 -0
- package/dist/composable-studio/section-binding/serialization.js.map +1 -0
- package/dist/composable-studio/section-data.js +5 -1
- package/dist/composable-studio/section-data.js.map +1 -1
- package/dist/composable-studio/setup-check-signal.js +48 -0
- package/dist/composable-studio/setup-check-signal.js.map +1 -0
- package/dist/composable-studio/studio-intelligence.manager.js +6 -2
- package/dist/composable-studio/studio-intelligence.manager.js.map +1 -1
- package/dist/config/config.schema.js +97 -104
- package/dist/config/config.schema.js.map +1 -1
- package/dist/config/process-user-config.js +41 -24
- package/dist/config/process-user-config.js.map +1 -1
- package/dist/config/stack-sdk-wrapper.js +22 -4
- package/dist/config/stack-sdk-wrapper.js.map +1 -1
- package/dist/context-menu/context-menu.js +1 -0
- package/dist/context-menu/context-menu.js.map +1 -1
- package/dist/dnd/dnd-manager.js +1 -0
- package/dist/dnd/dnd-manager.js.map +1 -1
- package/dist/editor.d.ts +34 -1
- package/dist/highlight-node/highlight-node-manager.js +89 -14
- package/dist/highlight-node/highlight-node-manager.js.map +1 -1
- package/dist/highlight-node/highlight-node.js +11 -5
- package/dist/highlight-node/highlight-node.js.map +1 -1
- package/dist/highlight-node/history-shortcut.js +78 -0
- package/dist/highlight-node/history-shortcut.js.map +1 -0
- package/dist/index.d.ts +1082 -354
- package/dist/index.js +18 -6
- package/dist/index.js.map +1 -1
- package/dist/query/query-executor.js +51 -9
- package/dist/query/query-executor.js.map +1 -1
- package/dist/renderer-mode.d.ts +68 -0
- package/dist/renderer-mode.js +2 -0
- package/dist/renderer-mode.js.map +1 -0
- package/dist/url-metadata/entry-check-key.js +14 -0
- package/dist/url-metadata/entry-check-key.js.map +1 -0
- package/dist/url-metadata/select-url-winner.js +64 -12
- package/dist/url-metadata/select-url-winner.js.map +1 -1
- package/dist/url-metadata/types.js +10 -1
- package/dist/url-metadata/types.js.map +1 -1
- package/dist/url-metadata/url-pattern-matcher.js +11 -2
- package/dist/url-metadata/url-pattern-matcher.js.map +1 -1
- package/dist/utils/canvas.js +0 -1
- package/dist/utils/canvas.js.map +1 -1
- package/dist/utils/check-bindings.js +5 -3
- package/dist/utils/check-bindings.js.map +1 -1
- package/dist/utils/classify-response-error.js +243 -33
- package/dist/utils/classify-response-error.js.map +1 -1
- package/dist/utils/composable-studio-error.js +7 -0
- package/dist/utils/composable-studio-error.js.map +1 -1
- package/dist/utils/conditionBlock.js +19 -6
- package/dist/utils/conditionBlock.js.map +1 -1
- package/dist/utils/constants.js +7 -2
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/http-error.constants.js +24 -1
- package/dist/utils/http-error.constants.js.map +1 -1
- package/dist/utils/include-path-rules.js +3 -2
- package/dist/utils/include-path-rules.js.map +1 -1
- package/dist/utils/load-error-classifier.js +18 -0
- package/dist/utils/load-error-classifier.js.map +1 -0
- package/dist/utils/parse-ui.js +27 -5
- package/dist/utils/parse-ui.js.map +1 -1
- package/dist/utils/preview-hash-refused.js +75 -0
- package/dist/utils/preview-hash-refused.js.map +1 -0
- package/dist/utils/reference_fetcher.js +79 -12
- package/dist/utils/reference_fetcher.js.map +1 -1
- package/dist/utils/require-stack.js +83 -20
- package/dist/utils/require-stack.js.map +1 -1
- package/dist/utils/serialize-for-inline-script.js +19 -0
- package/dist/utils/serialize-for-inline-script.js.map +1 -0
- package/dist/utils/served-by.js +32 -13
- package/dist/utils/served-by.js.map +1 -1
- package/dist/utils/spec-analyzer.js +24 -1
- package/dist/utils/spec-analyzer.js.map +1 -1
- package/dist/utils/studio-error-codes.js +34 -2
- package/dist/utils/studio-error-codes.js.map +1 -1
- package/dist/utils/studio-error.js +68 -7
- package/dist/utils/studio-error.js.map +1 -1
- package/dist/visual-builder/composition-save-event.js +36 -5
- package/dist/visual-builder/composition-save-event.js.map +1 -1
- package/package.json +12 -8
- package/dist/studio-internal/dist/utils/section-slot-walker.js +0 -63
- package/dist/studio-internal/dist/utils/section-slot-walker.js.map +0 -1
- package/dist/studio-internal/dist/utils/spec-compression.js +0 -43
- package/dist/studio-internal/dist/utils/spec-compression.js.map +0 -1
|
@@ -0,0 +1,815 @@
|
|
|
1
|
+
import { MAX_REFERENCE_TRAVERSAL_DEPTH } from './constants.js';
|
|
2
|
+
import { getSchemaFieldForPath, getSchemaPath } from './schema-path.js';
|
|
3
|
+
import { extractSectionInternalReferenceBindings } from './section-internal-ref-introspection.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Sentinel for `selectedField` meaning "the surrounding scope itself is the
|
|
7
|
+
* section's binding target". Used when a section sits inside a repeater whose
|
|
8
|
+
* item shape structurally IS the section's Global Field (no inner wrapper
|
|
9
|
+
* field to descend into). The SDK's getScopedData() already treats an empty
|
|
10
|
+
* string as "use the scope as-is".
|
|
11
|
+
*/
|
|
12
|
+
const SECTION_BINDING_SCOPE_ROOT = "";
|
|
13
|
+
/**
|
|
14
|
+
* What a placement's persisted `sectionBindingOverride` means for the binding
|
|
15
|
+
* this pass computes.
|
|
16
|
+
*
|
|
17
|
+
* Two generations of override live on that key. The retired "Data source"
|
|
18
|
+
* dropdown wrote a bare `selectedField`, chosen from THIS auto-binder's own
|
|
19
|
+
* match list, so re-validating it against the fresh list was the right
|
|
20
|
+
* staleness check (the page CT may have changed since it was saved). The
|
|
21
|
+
* Section data picker (ADR 0016) writes a `rootBinding`, validated by its own
|
|
22
|
+
* structural matcher, which accepts what this binder never lists: containment
|
|
23
|
+
* matches, nested fields, pinned entries, query results. Re-validating those
|
|
24
|
+
* here silently reverted every such pick — the row read "Navigation Menu 3",
|
|
25
|
+
* the canvas rendered the declared field — so an explicit root is taken as
|
|
26
|
+
* authoritative, exactly as `stampSelfDescribingSectionBindings` already does,
|
|
27
|
+
* and applies even when the auto-binder has no answer of its own (otherwise
|
|
28
|
+
* `resolveSectionBinding` falls back to the declared field and clobbers it).
|
|
29
|
+
*/
|
|
30
|
+
function applyInstanceBindingOverride(computed, override) {
|
|
31
|
+
if (!override)
|
|
32
|
+
return computed;
|
|
33
|
+
const ordered = computed
|
|
34
|
+
? [computed.selectedField, ...computed.alternativeFields]
|
|
35
|
+
: [];
|
|
36
|
+
const alternativeFields = ordered.filter((f) => f !== override.selectedField);
|
|
37
|
+
if (override.hasExplicitRoot) {
|
|
38
|
+
return {
|
|
39
|
+
selectedField: override.selectedField,
|
|
40
|
+
alternativeFields,
|
|
41
|
+
uidRemapping: override.uidRemapping ?? {},
|
|
42
|
+
explicitRoot: true,
|
|
43
|
+
fetchRootKey: override.fetchRootKey,
|
|
44
|
+
fetchRootPrefix: override.fetchRootPrefix,
|
|
45
|
+
rootBinding: override.rootBinding ?? null,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (!computed)
|
|
49
|
+
return null;
|
|
50
|
+
if (!ordered.includes(override.selectedField))
|
|
51
|
+
return computed;
|
|
52
|
+
return {
|
|
53
|
+
selectedField: override.selectedField,
|
|
54
|
+
alternativeFields,
|
|
55
|
+
uidRemapping: override.uidRemapping ?? computed.uidRemapping,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Rebase a placement that pinned NO root onto the fetch root of the nearest
|
|
60
|
+
* enclosing section that did (ADR 0017).
|
|
61
|
+
*
|
|
62
|
+
* A wrapper with a pinned-entry root changes which document everything in its
|
|
63
|
+
* slots resolves against. The SDK's cold-load seeder has always applied this
|
|
64
|
+
* (`walkSectionInstances` threads `inheritedRoot`), but the live editor map did
|
|
65
|
+
* not — so a slot child scoped from the page template in the canvas while a
|
|
66
|
+
* reload and the deployed site resolved it against the wrapper's document
|
|
67
|
+
* (E2E DR7.4). A placement with a root of its own is left alone: its own root
|
|
68
|
+
* wins outright rather than concatenating with the inherited prefix (DR7.5).
|
|
69
|
+
*/
|
|
70
|
+
function applyInheritedFetchRoot(binding, inherited) {
|
|
71
|
+
if (!inherited || binding?.explicitRoot)
|
|
72
|
+
return binding;
|
|
73
|
+
if (!binding) {
|
|
74
|
+
// The auto-binder had no answer, which is the NORMAL case for a slot child:
|
|
75
|
+
// it is anchored on the wrapper's content type, not the page's, so nothing
|
|
76
|
+
// in the page CT matches and `computeSectionAutoBinding` returns null. With
|
|
77
|
+
// no binding emitted at all the canvas fell back to the page template and
|
|
78
|
+
// the child rendered placeholders. The inherited root IS the answer here —
|
|
79
|
+
// the child reads its own fields at the root of the wrapper's document, so
|
|
80
|
+
// it contributes no field path of its own.
|
|
81
|
+
return {
|
|
82
|
+
selectedField: SECTION_BINDING_SCOPE_ROOT,
|
|
83
|
+
alternativeFields: [],
|
|
84
|
+
uidRemapping: {},
|
|
85
|
+
inheritedRoot: true,
|
|
86
|
+
fetchRootKey: inherited.fetchRootKey,
|
|
87
|
+
fetchRootPrefix: inherited.fetchRootPrefix,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
...binding,
|
|
92
|
+
inheritedRoot: true,
|
|
93
|
+
fetchRootKey: inherited.fetchRootKey,
|
|
94
|
+
fetchRootPrefix: inherited.fetchRootPrefix,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function getNestedSchemaForScope(schema, scopePath, contentTypeMap) {
|
|
98
|
+
if (!scopePath)
|
|
99
|
+
return schema;
|
|
100
|
+
const segments = getSchemaPath(scopePath);
|
|
101
|
+
let currentSchema = schema;
|
|
102
|
+
let refDepth = 0;
|
|
103
|
+
for (let i = 0; i < segments.length; i++) {
|
|
104
|
+
const segment = segments[i];
|
|
105
|
+
const field = currentSchema.find((entry) => entry.uid === segment);
|
|
106
|
+
if (!field)
|
|
107
|
+
return null;
|
|
108
|
+
if (i === segments.length - 1) {
|
|
109
|
+
if ("schema" in field && field.schema) {
|
|
110
|
+
return field.schema;
|
|
111
|
+
}
|
|
112
|
+
// Last segment is a `blocks`-type field (e.g. Repeater iterating
|
|
113
|
+
// `modular_blocks`). The iteration item is ONE of the blocks in
|
|
114
|
+
// the union. Return the merged schema of all blocks' fields so the
|
|
115
|
+
// structural matcher can find a `selected_field` that exists in
|
|
116
|
+
// at least one block (e.g. a nested `modular_blocks` field for
|
|
117
|
+
// recursive shapes). When multiple blocks have the same field uid
|
|
118
|
+
// with identical shapes, dedupe — when shapes differ we keep the
|
|
119
|
+
// first occurrence; callers can override via the Linked Field
|
|
120
|
+
// dropdown if needed.
|
|
121
|
+
if ("blocks" in field && field.blocks) {
|
|
122
|
+
const merged = [];
|
|
123
|
+
const seenUids = new Set();
|
|
124
|
+
for (const block of field.blocks) {
|
|
125
|
+
if (!block?.schema)
|
|
126
|
+
continue;
|
|
127
|
+
for (const blockField of block.schema) {
|
|
128
|
+
if (seenUids.has(blockField.uid))
|
|
129
|
+
continue;
|
|
130
|
+
seenUids.add(blockField.uid);
|
|
131
|
+
merged.push(blockField);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return merged.length > 0 ? merged : null;
|
|
135
|
+
}
|
|
136
|
+
// Last segment is a `reference` field: the iteration item is a resolved
|
|
137
|
+
// entry of one of the reference's target CTs. Return the target CT's
|
|
138
|
+
// schema so the caller can match a section's binding shape against it.
|
|
139
|
+
// Multi-target references (`reference_to` has >1 entry) require the
|
|
140
|
+
// caller to disambiguate via a ConditionBlock — we conservatively
|
|
141
|
+
// return null in that case (callers can fall back to a CB-narrowed
|
|
142
|
+
// path which will hit the single-target branch above with a different
|
|
143
|
+
// segment chain).
|
|
144
|
+
if ("reference_to" in field && field.reference_to) {
|
|
145
|
+
const refTo = field.reference_to;
|
|
146
|
+
if (!contentTypeMap || refTo.length !== 1)
|
|
147
|
+
return null;
|
|
148
|
+
if (refDepth >= MAX_REFERENCE_TRAVERSAL_DEPTH)
|
|
149
|
+
return null;
|
|
150
|
+
const targetCT = contentTypeMap.get(refTo[0]);
|
|
151
|
+
return targetCT?.schema ?? null;
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
if ("schema" in field && field.schema) {
|
|
156
|
+
currentSchema = field.schema;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if ("blocks" in field && field.blocks) {
|
|
160
|
+
const blockUid = segments[++i];
|
|
161
|
+
const block = field.blocks.find((entry) => entry.uid === blockUid);
|
|
162
|
+
if (!block?.schema)
|
|
163
|
+
return null;
|
|
164
|
+
currentSchema = block.schema;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
// Step through a reference segment: continue walking inside the target
|
|
168
|
+
// CT's schema. Only single-target references can be traversed without
|
|
169
|
+
// disambiguation — multi-target chains require a CB-narrowed step in
|
|
170
|
+
// the path, encoded by the caller.
|
|
171
|
+
if ("reference_to" in field && field.reference_to) {
|
|
172
|
+
const refTo = field.reference_to;
|
|
173
|
+
if (!contentTypeMap || refTo.length !== 1)
|
|
174
|
+
return null;
|
|
175
|
+
if (refDepth >= MAX_REFERENCE_TRAVERSAL_DEPTH)
|
|
176
|
+
return null;
|
|
177
|
+
const targetCT = contentTypeMap.get(refTo[0]);
|
|
178
|
+
if (!targetCT?.schema)
|
|
179
|
+
return null;
|
|
180
|
+
currentSchema = targetCT.schema;
|
|
181
|
+
refDepth++;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
return currentSchema;
|
|
187
|
+
}
|
|
188
|
+
function findFirstCompatibleField(sectionField, schema) {
|
|
189
|
+
if (!sectionField)
|
|
190
|
+
return null;
|
|
191
|
+
return (schema.find((field) => doFieldStructuresMatch(sectionField, field)) || null);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* If `contextSchemaPath` ends at a single-target reference, returns the
|
|
195
|
+
* target content type uid; otherwise null. Used by Scenario 4 to discover
|
|
196
|
+
* the effective CT for a section dropped inside a page-repeater of refs.
|
|
197
|
+
*/
|
|
198
|
+
function getContextScopeReferenceTarget(contextSchemaPath, pageSchema, contentTypeMap) {
|
|
199
|
+
if (!contextSchemaPath || !pageSchema)
|
|
200
|
+
return null;
|
|
201
|
+
const segments = getSchemaPath(contextSchemaPath);
|
|
202
|
+
if (segments.length === 0)
|
|
203
|
+
return null;
|
|
204
|
+
// Resolve the parent scope (everything but the terminal field) in a SINGLE
|
|
205
|
+
// `getNestedSchemaForScope` call. Walking segment-by-segment is wrong for
|
|
206
|
+
// paths that traverse modular blocks: a lone `blocks` segment returns the
|
|
207
|
+
// merged block schema WITHOUT consuming the following block-uid segment
|
|
208
|
+
// (e.g. `group`), so the next iteration can't find it and bails to null.
|
|
209
|
+
// `getNestedSchemaForScope` consumes block-uid pairs correctly within one
|
|
210
|
+
// call, so a context path like `blocks.group.rows.cards_row.products`
|
|
211
|
+
// resolves to the `cards_row` block schema and the terminal `products`
|
|
212
|
+
// reference is found.
|
|
213
|
+
const parentScope = segments.slice(0, -1).join(".");
|
|
214
|
+
const currentSchema = parentScope
|
|
215
|
+
? getNestedSchemaForScope(pageSchema, parentScope, contentTypeMap)
|
|
216
|
+
: pageSchema;
|
|
217
|
+
if (!currentSchema)
|
|
218
|
+
return null;
|
|
219
|
+
const tail = currentSchema.find((f) => f.uid === segments[segments.length - 1]);
|
|
220
|
+
if (!tail || tail.data_type !== "reference")
|
|
221
|
+
return null;
|
|
222
|
+
const refTo = tail.reference_to;
|
|
223
|
+
return Array.isArray(refTo) && refTo.length === 1 ? refTo[0] : null;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Returns true when the tail of `contextSchemaPath` is a single-target
|
|
227
|
+
* reference field whose target content type equals `linkedCTUid`. Used to
|
|
228
|
+
* decide whether a CT-anchored section dropped inside a page repeater can
|
|
229
|
+
* auto-bind to the scope root (Scenario 4 — the per-iteration value is a
|
|
230
|
+
* resolved entry of the linked CT).
|
|
231
|
+
*/
|
|
232
|
+
function contextScopeIsReferenceToCT(contextSchemaPath, pageSchema, linkedCTUid, contentTypeMap) {
|
|
233
|
+
return (getContextScopeReferenceTarget(contextSchemaPath, pageSchema, contentTypeMap) === linkedCTUid);
|
|
234
|
+
}
|
|
235
|
+
function isCompatibleExistingBinding(existing, computed) {
|
|
236
|
+
if (!existing || !computed)
|
|
237
|
+
return false;
|
|
238
|
+
const validFields = new Set([
|
|
239
|
+
computed.selectedField,
|
|
240
|
+
...computed.alternativeFields,
|
|
241
|
+
]);
|
|
242
|
+
return validFields.has(existing.selectedField);
|
|
243
|
+
}
|
|
244
|
+
function mergeSectionAutoBindings(computedBindings, existingBindings = {}) {
|
|
245
|
+
const merged = {
|
|
246
|
+
...computedBindings,
|
|
247
|
+
};
|
|
248
|
+
for (const [sectionUid, computed] of Object.entries(computedBindings)) {
|
|
249
|
+
// An explicit Section data is the composer's current choice by definition.
|
|
250
|
+
// The store entry it replaces (the declared field) is still among its
|
|
251
|
+
// alternatives, so the compatibility rule below would have kept the OLD
|
|
252
|
+
// one and reverted the pick on the very next recompute.
|
|
253
|
+
if (computed.explicitRoot)
|
|
254
|
+
continue;
|
|
255
|
+
const existing = existingBindings[sectionUid];
|
|
256
|
+
if (!isCompatibleExistingBinding(existing, computed))
|
|
257
|
+
continue;
|
|
258
|
+
merged[sectionUid] = {
|
|
259
|
+
...existing,
|
|
260
|
+
alternativeFields: [
|
|
261
|
+
...new Set([computed.selectedField, ...computed.alternativeFields].filter((field) => field !== existing.selectedField)),
|
|
262
|
+
],
|
|
263
|
+
// The inherited fetch root is derived from the CURRENT tree every pass —
|
|
264
|
+
// where the placement sits, not what the user picked — so the store entry
|
|
265
|
+
// (which predates the wrapper's root) must not drop it. `selectedField`
|
|
266
|
+
// still comes from `existing`: that half IS the user's choice.
|
|
267
|
+
...(computed.inheritedRoot
|
|
268
|
+
? {
|
|
269
|
+
inheritedRoot: true,
|
|
270
|
+
fetchRootKey: computed.fetchRootKey,
|
|
271
|
+
fetchRootPrefix: computed.fetchRootPrefix,
|
|
272
|
+
}
|
|
273
|
+
: {}),
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
// Preserve runtime overrides for sections where computeSectionAutoBinding
|
|
277
|
+
// returned null (e.g., saved uid_remapping guard skips auto-computation).
|
|
278
|
+
// Without this, setSectionAutoBindings wipes the user's override from the
|
|
279
|
+
// store before attachSectionCompositionContextsToData can use it.
|
|
280
|
+
for (const [sectionUid, existing] of Object.entries(existingBindings)) {
|
|
281
|
+
if (!(sectionUid in merged)) {
|
|
282
|
+
merged[sectionUid] = existing;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return merged;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Returns a sorted list of first-level child identifiers for a field.
|
|
289
|
+
* For groups/global_fields: sorted data_types of immediate children.
|
|
290
|
+
* For blocks: sorted block UIDs.
|
|
291
|
+
* For references: sorted reference_to content type UIDs.
|
|
292
|
+
* For simple fields: empty array.
|
|
293
|
+
*/
|
|
294
|
+
function getFirstLevelFieldTypes(field) {
|
|
295
|
+
if ("schema" in field && field.schema) {
|
|
296
|
+
return [...field.schema.map((f) => f.data_type)].sort();
|
|
297
|
+
}
|
|
298
|
+
if ("blocks" in field && field.blocks) {
|
|
299
|
+
return [...field.blocks.map((b) => b.uid)].sort();
|
|
300
|
+
}
|
|
301
|
+
if ("reference_to" in field && field.reference_to) {
|
|
302
|
+
return [...field.reference_to].sort();
|
|
303
|
+
}
|
|
304
|
+
return [];
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Returns true if two fields have the same data_type, multiple flag,
|
|
308
|
+
* and compatible first-level child structure.
|
|
309
|
+
*
|
|
310
|
+
* For `blocks` (modular blocks) fields the rule is intentionally loose:
|
|
311
|
+
* a match is declared if the two blocks fields share AT LEAST ONE
|
|
312
|
+
* common block uid in their unions. Rationale — sections typically wrap
|
|
313
|
+
* their Repeater in a ConditionBlock that narrows to ONE specific block
|
|
314
|
+
* uid, so they don't care whether the page's blocks union is a strict
|
|
315
|
+
* superset or subset of the section's; they just need the targeted
|
|
316
|
+
* block to be present on both sides. Strict-set equality would refuse
|
|
317
|
+
* obviously-correct pairings (page's nested modular_blocks allows only
|
|
318
|
+
* the inner block type while the section's modular_blocks allows
|
|
319
|
+
* several at root) and force manual overrides on the common recursive-
|
|
320
|
+
* shape pattern.
|
|
321
|
+
*
|
|
322
|
+
* `reference` fields follow the same loose rule for the same reason: when
|
|
323
|
+
* a section's schema is reference-typed, the picker auto-injects a
|
|
324
|
+
* Repeater + ConditionBlock at the section root, and the ConditionBlock
|
|
325
|
+
* narrows by `_content_type_uid` per iteration. So the section only needs
|
|
326
|
+
* ONE of its `reference_to` target CTs to overlap with the page field's
|
|
327
|
+
* `reference_to` for the binding to be useful — non-matching iterations
|
|
328
|
+
* simply don't render under their CB, exactly like blocks. Strict
|
|
329
|
+
* equality here would refuse pairings such as a section that handles
|
|
330
|
+
* `[hero, banner]` dropped on a page whose ref points to `[hero]` only.
|
|
331
|
+
*
|
|
332
|
+
* Other field types (group/global_field) still require exact first-level
|
|
333
|
+
* shape equality — those don't have ConditionBlock narrowing semantics,
|
|
334
|
+
* so the looser rule wouldn't be safe.
|
|
335
|
+
*/
|
|
336
|
+
function doFieldStructuresMatch(sectionField, pageField) {
|
|
337
|
+
if (sectionField.data_type !== pageField.data_type)
|
|
338
|
+
return false;
|
|
339
|
+
if ((sectionField.multiple ?? false) !== (pageField.multiple ?? false))
|
|
340
|
+
return false;
|
|
341
|
+
if (sectionField.data_type === "blocks") {
|
|
342
|
+
const sectionBlocks = new Set(getFirstLevelFieldTypes(sectionField));
|
|
343
|
+
const pageBlocks = getFirstLevelFieldTypes(pageField);
|
|
344
|
+
if (sectionBlocks.size === 0 || pageBlocks.length === 0)
|
|
345
|
+
return false;
|
|
346
|
+
return pageBlocks.some((uid) => sectionBlocks.has(uid));
|
|
347
|
+
}
|
|
348
|
+
if (sectionField.data_type === "reference") {
|
|
349
|
+
const sectionRefs = new Set(getFirstLevelFieldTypes(sectionField));
|
|
350
|
+
const pageRefs = getFirstLevelFieldTypes(pageField);
|
|
351
|
+
if (sectionRefs.size === 0 || pageRefs.length === 0)
|
|
352
|
+
return false;
|
|
353
|
+
return pageRefs.some((uid) => sectionRefs.has(uid));
|
|
354
|
+
}
|
|
355
|
+
const sectionTypes = getFirstLevelFieldTypes(sectionField);
|
|
356
|
+
const pageTypes = getFirstLevelFieldTypes(pageField);
|
|
357
|
+
if (sectionTypes.length !== pageTypes.length)
|
|
358
|
+
return false;
|
|
359
|
+
return sectionTypes.every((t, i) => t === pageTypes[i]);
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Case B match: the section's Global Field has no wrapper field within the
|
|
363
|
+
* surrounding scope, because the scope itself (e.g. a modular block whose
|
|
364
|
+
* schema mirrors the GF, or a list-of-Global-Field repeater item) IS the
|
|
365
|
+
* section's binding shape.
|
|
366
|
+
*
|
|
367
|
+
* Compares the section field's *children* against the entire scoped schema
|
|
368
|
+
* using the same shallow tolerance as `doFieldStructuresMatch` (sorted
|
|
369
|
+
* first-level data_types, same length).
|
|
370
|
+
*/
|
|
371
|
+
function scopeMatchesSectionField(sectionField, scopedPageSchema) {
|
|
372
|
+
if (!("schema" in sectionField) || !sectionField.schema)
|
|
373
|
+
return false;
|
|
374
|
+
// A list/multiple section field iterates a list and therefore cannot be
|
|
375
|
+
// equivalent to a single-item scope (one repeater iteration). When both the
|
|
376
|
+
// page repeater and the section repeater are multiple, the section binds to
|
|
377
|
+
// a matching nested list inside the scope (handled by findMatchingPageFields
|
|
378
|
+
// with lenient subset matching), NOT to the scope root.
|
|
379
|
+
if (sectionField.multiple)
|
|
380
|
+
return false;
|
|
381
|
+
const sectionChildren = sectionField.schema;
|
|
382
|
+
if (sectionChildren.length !== scopedPageSchema.length)
|
|
383
|
+
return false;
|
|
384
|
+
const sectionTypes = [...sectionChildren.map((f) => f.data_type)].sort();
|
|
385
|
+
const pageTypes = [...scopedPageSchema.map((f) => f.data_type)].sort();
|
|
386
|
+
return sectionTypes.every((t, i) => t === pageTypes[i]);
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Builds the section-child-uid → page-child-uid remapping when the section
|
|
390
|
+
* binds to the scope root (case B). The "page field" here is the entire
|
|
391
|
+
* scope, treated as if it were a virtual group whose schema is scopedPageSchema.
|
|
392
|
+
*/
|
|
393
|
+
function buildScopeRootUidRemapping(sectionField, scopedPageSchema) {
|
|
394
|
+
return buildFieldUidRemapping(sectionField, {
|
|
395
|
+
uid: SECTION_BINDING_SCOPE_ROOT,
|
|
396
|
+
data_type: sectionField.data_type,
|
|
397
|
+
schema: scopedPageSchema,
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Lenient structural match used when the section's selected_field is a list
|
|
402
|
+
* (multiple) and we want to find a nested multiple field inside the scope to
|
|
403
|
+
* bind to (the "repeater within repeater" auto-bind). Rules:
|
|
404
|
+
* - data_type and multiple must agree
|
|
405
|
+
* - candidate's first-level child data_types must be a multiset SUBSET of
|
|
406
|
+
* section's first-level child data_types
|
|
407
|
+
* Rationale: the section's components typically reference a subset of the
|
|
408
|
+
* authored fields; a candidate that covers that subset is a usable binding
|
|
409
|
+
* target even if it lacks fields the section's authored shape has (those
|
|
410
|
+
* deeper bindings resolve to undefined gracefully). Strict equality would
|
|
411
|
+
* reject obviously-compatible self-similar nestings (e.g. section group with
|
|
412
|
+
* a nested inner_group ↔ page's inner_group of the same primitive shape).
|
|
413
|
+
*/
|
|
414
|
+
function doFieldStructuresMatchLenient(sectionField, pageField) {
|
|
415
|
+
if (sectionField.data_type !== pageField.data_type)
|
|
416
|
+
return false;
|
|
417
|
+
if ((sectionField.multiple ?? false) !== (pageField.multiple ?? false))
|
|
418
|
+
return false;
|
|
419
|
+
// `blocks` and `reference` already use loose matching in doFieldStructuresMatch
|
|
420
|
+
// (CB-narrowed semantics). The multiset-subset rule is unsafe for them — it
|
|
421
|
+
// would compare data_types of block/reference children, which are unrelated
|
|
422
|
+
// to the CB filter — so defer to the strict matcher.
|
|
423
|
+
if (sectionField.data_type === "blocks" ||
|
|
424
|
+
sectionField.data_type === "reference") {
|
|
425
|
+
return doFieldStructuresMatch(sectionField, pageField);
|
|
426
|
+
}
|
|
427
|
+
const sectionTypes = getFirstLevelFieldTypes(sectionField);
|
|
428
|
+
const pageTypes = getFirstLevelFieldTypes(pageField);
|
|
429
|
+
if (pageTypes.length === 0)
|
|
430
|
+
return false;
|
|
431
|
+
// multiset subset: every page child data_type has a matching section child
|
|
432
|
+
const sectionCounts = new Map();
|
|
433
|
+
for (const t of sectionTypes)
|
|
434
|
+
sectionCounts.set(t, (sectionCounts.get(t) ?? 0) + 1);
|
|
435
|
+
for (const t of pageTypes) {
|
|
436
|
+
const c = sectionCounts.get(t) ?? 0;
|
|
437
|
+
if (c <= 0)
|
|
438
|
+
return false;
|
|
439
|
+
sectionCounts.set(t, c - 1);
|
|
440
|
+
}
|
|
441
|
+
return true;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Finds all top-level fields in pageSchema whose structure matches sectionField.
|
|
445
|
+
* Returns their UIDs as the matching field paths. Strict matching first; if
|
|
446
|
+
* sectionField is a list (multiple) and strict yields nothing, falls back to
|
|
447
|
+
* lenient subset matching so a structurally-compatible nested list inside the
|
|
448
|
+
* scope (e.g. inner_group) is preferred over the single-iteration scope-root
|
|
449
|
+
* fallback. For non-multiple section fields the behavior is unchanged.
|
|
450
|
+
*/
|
|
451
|
+
function findMatchingPageFields(sectionField, pageSchema) {
|
|
452
|
+
const strict = pageSchema
|
|
453
|
+
.filter((pageField) => doFieldStructuresMatch(sectionField, pageField))
|
|
454
|
+
.map((pageField) => pageField.uid);
|
|
455
|
+
if (strict.length > 0 || !sectionField.multiple)
|
|
456
|
+
return strict;
|
|
457
|
+
return pageSchema
|
|
458
|
+
.filter((pageField) => doFieldStructuresMatchLenient(sectionField, pageField))
|
|
459
|
+
.map((pageField) => pageField.uid);
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Builds a positional UID remapping from section child UIDs to page child UIDs.
|
|
463
|
+
* Matches children by index within the same data_type sequence.
|
|
464
|
+
* Only applies to group/global_field fields with nested schemas.
|
|
465
|
+
*
|
|
466
|
+
* Example:
|
|
467
|
+
* section schema: [{uid: "heading", data_type: "text"}, {uid: "body", data_type: "textarea"}]
|
|
468
|
+
* page schema: [{uid: "title", data_type: "text"}, {uid: "desc", data_type: "textarea"}]
|
|
469
|
+
* result: { heading: "title", body: "desc" }
|
|
470
|
+
*
|
|
471
|
+
* IMPORTANT — this remap is SHALLOW (one level of children only); it does NOT
|
|
472
|
+
* recurse into nested groups/blocks. Consequence for nested data:
|
|
473
|
+
* - NESTED GROUPS (a group inside a group): the inner group must use the SAME
|
|
474
|
+
* uid as the outer group (e.g. outer `grp1` → inner `grp1`). The inner level
|
|
475
|
+
* isn't remapped, so a section repeater bound to that group only resolves the
|
|
476
|
+
* inner items when the inner uid matches; differing uids → data won't render.
|
|
477
|
+
* - MODULAR BLOCKS: the page block's id must match the section's block id
|
|
478
|
+
* (the ConditionBlock condition value is the block uid, compared as-is) —
|
|
479
|
+
* differing block ids → the per-block iteration won't resolve.
|
|
480
|
+
* If recursive nested remapping is ever needed, this function must walk child
|
|
481
|
+
* schemas instead of relying on matching uids at each nested level.
|
|
482
|
+
*/
|
|
483
|
+
function buildFieldUidRemapping(sectionField, pageField) {
|
|
484
|
+
if (!("schema" in sectionField) || !("schema" in pageField))
|
|
485
|
+
return {};
|
|
486
|
+
const sectionSchema = sectionField.schema || [];
|
|
487
|
+
const pageSchema = pageField.schema || [];
|
|
488
|
+
const remapping = {};
|
|
489
|
+
sectionSchema.forEach((sField, i) => {
|
|
490
|
+
const pField = pageSchema[i];
|
|
491
|
+
if (pField && sField.data_type === pField.data_type) {
|
|
492
|
+
remapping[sField.uid] = pField.uid;
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
return remapping;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Computes the auto-binding for a section against the page's connected content type.
|
|
499
|
+
*
|
|
500
|
+
* The section's configured selected_field is ALWAYS used as the active binding
|
|
501
|
+
* (preserving the section author's intent and avoiding wrong-field substitution).
|
|
502
|
+
* Structural matching only discovers ALTERNATIVE fields for the dropdown.
|
|
503
|
+
*
|
|
504
|
+
* Algorithm:
|
|
505
|
+
* 1. Find the linked schema whose content_type_uid matches the page's connected CT.
|
|
506
|
+
* 2. Resolve the field at selected_field within that CT's schema.
|
|
507
|
+
* 3. Find all top-level fields in the PAGE's CT that structurally match.
|
|
508
|
+
* 4. Return selected_field unchanged as the active binding; other matches as alternatives.
|
|
509
|
+
*
|
|
510
|
+
* Returns null if the page CT doesn't match any linked schema, or if selected_field
|
|
511
|
+
* is not set on the matching schema.
|
|
512
|
+
* Skips computation if the SchemaLink already has uid_remapping set (user override).
|
|
513
|
+
*/
|
|
514
|
+
function computeSectionAutoBinding(linkedSchemas, pageConnectedContentTypeUid, contentTypeMap, contextSchemaPath,
|
|
515
|
+
/**
|
|
516
|
+
* Section composition's authored UI tree. Optional — when provided, enables
|
|
517
|
+
* Case 3 introspection: a CT-anchored section (no `selected_field`) whose
|
|
518
|
+
* linked CT differs from the page CT can still auto-bind by remapping its
|
|
519
|
+
* internal Repeater reference bindings onto overlapping page ref fields.
|
|
520
|
+
* Callers that don't have the section UI in scope can omit this; Case 3
|
|
521
|
+
* simply doesn't fire.
|
|
522
|
+
*/
|
|
523
|
+
sectionUi) {
|
|
524
|
+
if (!linkedSchemas?.length || !pageConnectedContentTypeUid)
|
|
525
|
+
return null;
|
|
526
|
+
// Primary match: section linked schema whose content_type_uid is the page's
|
|
527
|
+
// connected CT. This is the normal flow used by almost all drops.
|
|
528
|
+
let matchingSchema = linkedSchemas.find((s) => s.content_type_uid === pageConnectedContentTypeUid);
|
|
529
|
+
// Scenario 4 fallback: when the section is dropped inside a page repeater
|
|
530
|
+
// whose tail is a reference, the per-iteration scope IS an entry of the
|
|
531
|
+
// referenced CT — not the page CT. Look for a linked schema whose CT
|
|
532
|
+
// matches the scope's reference target so a CT-anchored section authored
|
|
533
|
+
// against the target CT can still auto-bind.
|
|
534
|
+
if (!matchingSchema && contextSchemaPath) {
|
|
535
|
+
const pageCT = contentTypeMap.get(pageConnectedContentTypeUid);
|
|
536
|
+
const scopeRefTarget = getContextScopeReferenceTarget(contextSchemaPath, pageCT?.schema, contentTypeMap);
|
|
537
|
+
if (scopeRefTarget) {
|
|
538
|
+
matchingSchema = linkedSchemas.find((s) => s.content_type_uid === scopeRefTarget);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
// Scoped page schema shared by the two no-direct-match fallbacks below
|
|
542
|
+
// (reference-target matching + Case 3). Both resolve against the same scope,
|
|
543
|
+
// so compute it once here. Only needed when nothing matched the page CT (or
|
|
544
|
+
// the Scenario 4 ref target) directly — the normal path further down derives
|
|
545
|
+
// its own from the resolved `matchingSchema`.
|
|
546
|
+
let fallbackScopedPageSchema = null;
|
|
547
|
+
if (!matchingSchema) {
|
|
548
|
+
const pageCT = contentTypeMap.get(pageConnectedContentTypeUid);
|
|
549
|
+
fallbackScopedPageSchema = pageCT
|
|
550
|
+
? getNestedSchemaForScope(pageCT.schema, contextSchemaPath, contentTypeMap)
|
|
551
|
+
: null;
|
|
552
|
+
}
|
|
553
|
+
// Reference-target matching fallback: a section anchored to a reference
|
|
554
|
+
// field expresses intent "iterate refs to <target CT>", regardless of the
|
|
555
|
+
// section's authored content_type_uid. When neither the primary (linked CT
|
|
556
|
+
// == page CT) nor the Scenario 4 fallback (scope tail is ref to linked CT)
|
|
557
|
+
// matched, scan the scoped page schema for any reference field whose
|
|
558
|
+
// `reference_to` overlaps with the section's anchor reference target. The
|
|
559
|
+
// chosen page field becomes selectedField directly — uidRemapping stays
|
|
560
|
+
// empty because the per-iteration value is a resolved entry of the target
|
|
561
|
+
// CT and the section's inner bindings (which resolve against template
|
|
562
|
+
// after the SDK scopes by selectedField) reference uids on that target CT.
|
|
563
|
+
if (!matchingSchema && fallbackScopedPageSchema) {
|
|
564
|
+
for (const linkedSchema of linkedSchemas) {
|
|
565
|
+
if (!linkedSchema.selected_field)
|
|
566
|
+
continue;
|
|
567
|
+
const sectionCT = contentTypeMap.get(linkedSchema.content_type_uid);
|
|
568
|
+
if (!sectionCT)
|
|
569
|
+
continue;
|
|
570
|
+
const sectionField = getSchemaFieldForPath(sectionCT.schema, linkedSchema.selected_field);
|
|
571
|
+
if (!sectionField || sectionField.data_type !== "reference")
|
|
572
|
+
continue;
|
|
573
|
+
if (linkedSchema.uid_remapping &&
|
|
574
|
+
Object.keys(linkedSchema.uid_remapping).length > 0) {
|
|
575
|
+
return null;
|
|
576
|
+
}
|
|
577
|
+
const matches = findMatchingPageFields(sectionField, fallbackScopedPageSchema);
|
|
578
|
+
if (matches.length === 0)
|
|
579
|
+
continue;
|
|
580
|
+
return {
|
|
581
|
+
selectedField: matches[0],
|
|
582
|
+
alternativeFields: matches.slice(1),
|
|
583
|
+
uidRemapping: {},
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
// Case 3 fallback: a CT-anchored section (no `selected_field`) authored
|
|
588
|
+
// against CT-X but dropped on a page whose CT differs. The section has
|
|
589
|
+
// internal Repeater bindings that target reference fields on its own CT —
|
|
590
|
+
// remap those uids onto page ref fields with overlapping `reference_to`
|
|
591
|
+
// targets so the section's inner Repeater iterates page data instead of
|
|
592
|
+
// resolving against a field uid that doesn't exist on the page entry.
|
|
593
|
+
//
|
|
594
|
+
// Returns SCOPE_ROOT with a uidRemapping = { [sectionRefUid]: pageRefUid }.
|
|
595
|
+
// The SDK's `applyUidRemapping` then renames the page entry's matching ref
|
|
596
|
+
// key to the section's expected key, so `template.<sectionRefUid>` resolves
|
|
597
|
+
// to the resolved entries the section author intended to iterate.
|
|
598
|
+
if (!matchingSchema && sectionUi && fallbackScopedPageSchema) {
|
|
599
|
+
for (const linkedSchema of linkedSchemas) {
|
|
600
|
+
// Only CT-level linked schemas (no `selected_field`) — the
|
|
601
|
+
// selected_field cases are already handled by the ref-target match
|
|
602
|
+
// above and the normal path below.
|
|
603
|
+
if (linkedSchema.selected_field)
|
|
604
|
+
continue;
|
|
605
|
+
const sectionCT = contentTypeMap.get(linkedSchema.content_type_uid);
|
|
606
|
+
if (!sectionCT)
|
|
607
|
+
continue;
|
|
608
|
+
if (linkedSchema.uid_remapping &&
|
|
609
|
+
Object.keys(linkedSchema.uid_remapping).length > 0) {
|
|
610
|
+
return null;
|
|
611
|
+
}
|
|
612
|
+
const internalRefs = extractSectionInternalReferenceBindings(sectionUi, sectionCT);
|
|
613
|
+
if (internalRefs.length === 0)
|
|
614
|
+
continue;
|
|
615
|
+
const uidRemapping = {};
|
|
616
|
+
for (const internalRef of internalRefs) {
|
|
617
|
+
// First overlapping page ref wins for each internal ref. When two
|
|
618
|
+
// section refs target the same CT and the page has only one
|
|
619
|
+
// matching ref, both remap to that single page ref — the SDK's
|
|
620
|
+
// applyUidRemapping happily renames the same page key under
|
|
621
|
+
// multiple section keys.
|
|
622
|
+
for (const pageField of fallbackScopedPageSchema) {
|
|
623
|
+
if (pageField.data_type !== "reference")
|
|
624
|
+
continue;
|
|
625
|
+
const pageRefTo = pageField.reference_to;
|
|
626
|
+
if (!pageRefTo || pageRefTo.length === 0)
|
|
627
|
+
continue;
|
|
628
|
+
if (pageRefTo.some((t) => internalRef.targetCTs.includes(t))) {
|
|
629
|
+
uidRemapping[internalRef.sectionRefUid] = pageField.uid;
|
|
630
|
+
break;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
if (Object.keys(uidRemapping).length === 0)
|
|
635
|
+
continue;
|
|
636
|
+
return {
|
|
637
|
+
selectedField: SECTION_BINDING_SCOPE_ROOT,
|
|
638
|
+
alternativeFields: [],
|
|
639
|
+
uidRemapping,
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
if (!matchingSchema)
|
|
644
|
+
return null;
|
|
645
|
+
// CT-level anchoring (section author picked "Entire Content Type" so no
|
|
646
|
+
// selected_field is set). When the page's connected CT matches the section's
|
|
647
|
+
// linked CT, the section binds to the page entry root — same uids on both
|
|
648
|
+
// sides, no remapping needed.
|
|
649
|
+
//
|
|
650
|
+
// Two cases are supported:
|
|
651
|
+
// (a) page-root drops (no contextSchemaPath) — original behavior.
|
|
652
|
+
// (b) drops inside a page repeater whose iteration value is a resolved
|
|
653
|
+
// reference entry of the section's linked CT (Scenario 4). The
|
|
654
|
+
// per-iteration scope IS an entry of the linked CT, so scope-root
|
|
655
|
+
// anchoring is exactly what we want. Recognized by walking the
|
|
656
|
+
// context schema path and checking that the tail is a single-target
|
|
657
|
+
// reference whose target CT equals the linked CT.
|
|
658
|
+
if (!matchingSchema.selected_field) {
|
|
659
|
+
if (contextSchemaPath &&
|
|
660
|
+
!contextScopeIsReferenceToCT(contextSchemaPath, contentTypeMap.get(pageConnectedContentTypeUid)?.schema, matchingSchema.content_type_uid, contentTypeMap)) {
|
|
661
|
+
return null;
|
|
662
|
+
}
|
|
663
|
+
return {
|
|
664
|
+
selectedField: SECTION_BINDING_SCOPE_ROOT,
|
|
665
|
+
alternativeFields: [],
|
|
666
|
+
uidRemapping: {},
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
// User has already explicitly chosen a different field — preserve their choice.
|
|
670
|
+
// A persisted empty uid_remapping ({}) is not a meaningful override; recompute
|
|
671
|
+
// for those so stale "" / empty bindings don't survive after the fix lands.
|
|
672
|
+
if (matchingSchema.uid_remapping &&
|
|
673
|
+
Object.keys(matchingSchema.uid_remapping).length > 0) {
|
|
674
|
+
return null;
|
|
675
|
+
}
|
|
676
|
+
const sectionContentType = contentTypeMap.get(matchingSchema.content_type_uid);
|
|
677
|
+
if (!sectionContentType)
|
|
678
|
+
return null;
|
|
679
|
+
const pageContentType = contentTypeMap.get(pageConnectedContentTypeUid);
|
|
680
|
+
if (!pageContentType)
|
|
681
|
+
return null;
|
|
682
|
+
const scopedPageSchema = getNestedSchemaForScope(pageContentType.schema, contextSchemaPath, contentTypeMap);
|
|
683
|
+
if (!scopedPageSchema)
|
|
684
|
+
return null;
|
|
685
|
+
const sectionField = getSchemaFieldForPath(scopedPageSchema, matchingSchema.selected_field) ||
|
|
686
|
+
getSchemaFieldForPath(sectionContentType.schema, matchingSchema.selected_field) ||
|
|
687
|
+
findFirstCompatibleField(getSchemaFieldForPath(sectionContentType.schema, matchingSchema.selected_field) || null, scopedPageSchema);
|
|
688
|
+
if (!sectionField)
|
|
689
|
+
return null;
|
|
690
|
+
const allMatchingPaths = findMatchingPageFields(sectionField, scopedPageSchema);
|
|
691
|
+
// Case B (scope-root match): inside a repeater/condition whose item shape
|
|
692
|
+
// itself mirrors the section's Global Field. Bind to the scope root and
|
|
693
|
+
// offer any inner field-level matches as alternatives.
|
|
694
|
+
const isScopeRootMatch = !!contextSchemaPath &&
|
|
695
|
+
scopeMatchesSectionField(sectionField, scopedPageSchema);
|
|
696
|
+
if (isScopeRootMatch) {
|
|
697
|
+
return {
|
|
698
|
+
selectedField: SECTION_BINDING_SCOPE_ROOT,
|
|
699
|
+
alternativeFields: allMatchingPaths,
|
|
700
|
+
uidRemapping: buildScopeRootUidRemapping(sectionField, scopedPageSchema),
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
const configuredField = matchingSchema.selected_field;
|
|
704
|
+
// The section's configured field already resolves on the page schema — keep it
|
|
705
|
+
// even when `findMatchingPageFields` (which scans only TOP-LEVEL page fields)
|
|
706
|
+
// didn't surface it. Otherwise a DEEP configured array path (e.g.
|
|
707
|
+
// `lvl1.lvl2.lvl3`) on a same-CT section gets wrongly rebound to a
|
|
708
|
+
// structurally-matching TOP-LEVEL array (e.g. `cards`) with a bogus
|
|
709
|
+
// uidRemapping — the author's own valid field must win.
|
|
710
|
+
const configuredResolvesOnPage = !!getSchemaFieldForPath(scopedPageSchema, configuredField);
|
|
711
|
+
const selectedField = configuredResolvesOnPage || allMatchingPaths.includes(configuredField)
|
|
712
|
+
? configuredField
|
|
713
|
+
: allMatchingPaths[0] || configuredField;
|
|
714
|
+
const selectedScopedField = selectedField === configuredField
|
|
715
|
+
? sectionField
|
|
716
|
+
: getSchemaFieldForPath(scopedPageSchema, selectedField);
|
|
717
|
+
const alternativeFields = allMatchingPaths.filter((p) => p !== selectedField);
|
|
718
|
+
return {
|
|
719
|
+
selectedField,
|
|
720
|
+
alternativeFields,
|
|
721
|
+
uidRemapping: selectedField !== configuredField && selectedScopedField
|
|
722
|
+
? buildFieldUidRemapping(sectionField, selectedScopedField)
|
|
723
|
+
: {},
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Computes a new binding result when the user explicitly switches to a different field
|
|
728
|
+
* via the dropdown. The override field may come from a DIFFERENT position in the page's
|
|
729
|
+
* content type schema, requiring UID remapping so the section's bindings still resolve.
|
|
730
|
+
*/
|
|
731
|
+
function computeAutoBindingForField(linkedSchemas, pageConnectedContentTypeUid, contentTypeMap, overrideSelectedField, contextSchemaPath) {
|
|
732
|
+
if (!linkedSchemas?.length || !pageConnectedContentTypeUid)
|
|
733
|
+
return null;
|
|
734
|
+
const matchingSchema = linkedSchemas.find((s) => s.content_type_uid === pageConnectedContentTypeUid);
|
|
735
|
+
// Cross-CT reference-target override: the dropdown was populated by the
|
|
736
|
+
// ref-target fallback in computeSectionAutoBinding (linked CT ≠ page CT,
|
|
737
|
+
// section anchor is a reference). The override value is a page ref uid;
|
|
738
|
+
// resolve it directly against the scoped page schema and confirm it sits
|
|
739
|
+
// in the set of overlapping page refs computed from the section's anchor.
|
|
740
|
+
if (!matchingSchema) {
|
|
741
|
+
const pageCT = contentTypeMap.get(pageConnectedContentTypeUid);
|
|
742
|
+
const scopedPageSchemaForRef = pageCT
|
|
743
|
+
? getNestedSchemaForScope(pageCT.schema, contextSchemaPath, contentTypeMap)
|
|
744
|
+
: null;
|
|
745
|
+
if (!scopedPageSchemaForRef)
|
|
746
|
+
return null;
|
|
747
|
+
for (const linkedSchema of linkedSchemas) {
|
|
748
|
+
if (!linkedSchema.selected_field)
|
|
749
|
+
continue;
|
|
750
|
+
const sectionCT = contentTypeMap.get(linkedSchema.content_type_uid);
|
|
751
|
+
if (!sectionCT)
|
|
752
|
+
continue;
|
|
753
|
+
const sectionRefField = getSchemaFieldForPath(sectionCT.schema, linkedSchema.selected_field);
|
|
754
|
+
if (!sectionRefField || sectionRefField.data_type !== "reference")
|
|
755
|
+
continue;
|
|
756
|
+
const matches = findMatchingPageFields(sectionRefField, scopedPageSchemaForRef);
|
|
757
|
+
if (!matches.includes(overrideSelectedField))
|
|
758
|
+
continue;
|
|
759
|
+
return {
|
|
760
|
+
selectedField: overrideSelectedField,
|
|
761
|
+
alternativeFields: matches.filter((p) => p !== overrideSelectedField),
|
|
762
|
+
uidRemapping: {},
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
return null;
|
|
766
|
+
}
|
|
767
|
+
if (!matchingSchema.selected_field)
|
|
768
|
+
return null;
|
|
769
|
+
const sectionContentType = contentTypeMap.get(matchingSchema.content_type_uid);
|
|
770
|
+
if (!sectionContentType)
|
|
771
|
+
return null;
|
|
772
|
+
const pageContentType = contentTypeMap.get(pageConnectedContentTypeUid);
|
|
773
|
+
if (!pageContentType)
|
|
774
|
+
return null;
|
|
775
|
+
const scopedPageSchema = getNestedSchemaForScope(pageContentType.schema, contextSchemaPath, contentTypeMap);
|
|
776
|
+
if (!scopedPageSchema)
|
|
777
|
+
return null;
|
|
778
|
+
// The section's ORIGINAL field (for structural comparison and building the remapping)
|
|
779
|
+
const sectionField = getSchemaFieldForPath(scopedPageSchema, matchingSchema.selected_field) ||
|
|
780
|
+
getSchemaFieldForPath(sectionContentType.schema, matchingSchema.selected_field) ||
|
|
781
|
+
findFirstCompatibleField(getSchemaFieldForPath(sectionContentType.schema, matchingSchema.selected_field) || null, scopedPageSchema);
|
|
782
|
+
if (!sectionField)
|
|
783
|
+
return null;
|
|
784
|
+
const allMatchingPaths = findMatchingPageFields(sectionField, scopedPageSchema);
|
|
785
|
+
// Case B override: user selected the scope-root sentinel from the dropdown.
|
|
786
|
+
if (overrideSelectedField === SECTION_BINDING_SCOPE_ROOT) {
|
|
787
|
+
if (!scopeMatchesSectionField(sectionField, scopedPageSchema))
|
|
788
|
+
return null;
|
|
789
|
+
return {
|
|
790
|
+
selectedField: SECTION_BINDING_SCOPE_ROOT,
|
|
791
|
+
alternativeFields: allMatchingPaths,
|
|
792
|
+
uidRemapping: buildScopeRootUidRemapping(sectionField, scopedPageSchema),
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
const overridePageField = getSchemaFieldForPath(scopedPageSchema, overrideSelectedField);
|
|
796
|
+
if (!overridePageField)
|
|
797
|
+
return null;
|
|
798
|
+
// Build remapping: section's original child UIDs → override field's child UIDs
|
|
799
|
+
const uidRemapping = buildFieldUidRemapping(sectionField, overridePageField);
|
|
800
|
+
// Include the scope-root sentinel as an alternative if it would also match.
|
|
801
|
+
const scopeRootAvailable = !!contextSchemaPath &&
|
|
802
|
+
scopeMatchesSectionField(sectionField, scopedPageSchema);
|
|
803
|
+
const alternativeFields = [
|
|
804
|
+
...(scopeRootAvailable ? [SECTION_BINDING_SCOPE_ROOT] : []),
|
|
805
|
+
...allMatchingPaths.filter((p) => p !== overrideSelectedField),
|
|
806
|
+
];
|
|
807
|
+
return {
|
|
808
|
+
selectedField: overrideSelectedField,
|
|
809
|
+
alternativeFields,
|
|
810
|
+
uidRemapping,
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
export { SECTION_BINDING_SCOPE_ROOT, applyInheritedFetchRoot, applyInstanceBindingOverride, buildFieldUidRemapping, computeAutoBindingForField, computeSectionAutoBinding, doFieldStructuresMatch, findMatchingPageFields, getFirstLevelFieldTypes, getNestedSchemaForScope, mergeSectionAutoBindings, scopeMatchesSectionField };
|
|
815
|
+
//# sourceMappingURL=section-composition-auto-binding.js.map
|