@contentstack/studio-registry 1.5.0 → 1.6.1

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.
@@ -76,6 +76,7 @@ const INTERNAL_COMPONENT_SECTIONS = {
76
76
  REGISTERED_COMPONENTS: "Registered Components",
77
77
  HTML_ELEMENT: "HTML Elements",
78
78
  SYMBOL: "Symbols",
79
+ SECTION_COMPOSITION: "Sections",
79
80
  };
80
81
  const INTERNAL_SECTIONS = Object.values(INTERNAL_COMPONENT_SECTIONS);
81
82
  const STYLE_SECTIONS_OPTIONS = [
@@ -130,6 +131,7 @@ const INTERNAL_COMPONENTS_NAMES = {
130
131
  JSON_RTE: "json-rte",
131
132
  COLLAPSIBLE_TEXT: "collapsible-text",
132
133
  PLAIN_TEXT: "plain-text",
134
+ RICH_TEXT: "rich-text",
133
135
  // * Media
134
136
  VIDEO: "video",
135
137
  EMBED: "embed",
@@ -143,6 +145,10 @@ const INTERNAL_COMPONENTS_NAMES = {
143
145
  CONDITION_BLOCK: "condition-block",
144
146
  SYMBOL: "symbol",
145
147
  FRAGMENT: "fragment",
148
+ // Exposed-slot placeholder authored inside a section composition. When the
149
+ // section is dropped into a page, each section-slot becomes a fill point
150
+ // the page composer can drop arbitrary components into.
151
+ SECTION_SLOT: "section-slot",
146
152
  // * HTML Elements
147
153
  HTML_ELEMENT: "html-element",
148
154
  STYLE_SHEET: "style-sheet",
@@ -185,6 +191,17 @@ const getSymbolUIDFromUID = (uid) => {
185
191
  return `${INTERNAL_COMPONENTS_NAMES.SYMBOL}-${uid}`;
186
192
  };
187
193
 
194
+ /**
195
+ * Extracts the composition UID from a section-composition node's metadata.
196
+ * Used to resolve section references to their actual composition identifiers.
197
+ *
198
+ * @param section - The section node containing metadata
199
+ * @returns The composition UID or undefined if not present
200
+ */
201
+ const getSectionUIDFromNode = (section) => {
202
+ return section.metadata?.compositionUID;
203
+ };
204
+
188
205
  /** Detect free variable `global` from Node.js. */
189
206
  var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
190
207
 
@@ -195,7 +212,7 @@ var freeSelf = typeof self == 'object' && self && self.Object === Object && self
195
212
  var root = freeGlobal || freeSelf || Function('return this')();
196
213
 
197
214
  /** Built-in value references. */
198
- var Symbol = root.Symbol;
215
+ var Symbol$1 = root.Symbol;
199
216
 
200
217
  /** Used for built-in method references. */
201
218
  var objectProto$e = Object.prototype;
@@ -211,7 +228,7 @@ var hasOwnProperty$b = objectProto$e.hasOwnProperty;
211
228
  var nativeObjectToString$1 = objectProto$e.toString;
212
229
 
213
230
  /** Built-in value references. */
214
- var symToStringTag$1 = Symbol ? Symbol.toStringTag : undefined;
231
+ var symToStringTag$1 = Symbol$1 ? Symbol$1.toStringTag : undefined;
215
232
 
216
233
  /**
217
234
  * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
@@ -266,7 +283,7 @@ var nullTag = '[object Null]',
266
283
  undefinedTag = '[object Undefined]';
267
284
 
268
285
  /** Built-in value references. */
269
- var symToStringTag = Symbol ? Symbol.toStringTag : undefined;
286
+ var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : undefined;
270
287
 
271
288
  /**
272
289
  * The base implementation of `getTag` without fallbacks for buggy environments.
@@ -383,7 +400,7 @@ function arrayMap(array, iteratee) {
383
400
  var isArray = Array.isArray;
384
401
 
385
402
  /** Used to convert symbols to primitives and strings. */
386
- var symbolProto$1 = Symbol ? Symbol.prototype : undefined,
403
+ var symbolProto$1 = Symbol$1 ? Symbol$1.prototype : undefined,
387
404
  symbolToString = symbolProto$1 ? symbolProto$1.toString : undefined;
388
405
 
389
406
  /**
@@ -2197,7 +2214,7 @@ function arrayPush(array, values) {
2197
2214
  }
2198
2215
 
2199
2216
  /** Built-in value references. */
2200
- var spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined;
2217
+ var spreadableSymbol = Symbol$1 ? Symbol$1.isConcatSpreadable : undefined;
2201
2218
 
2202
2219
  /**
2203
2220
  * Checks if `value` is a flattenable `arguments` object or array.
@@ -3034,7 +3051,7 @@ function cloneRegExp(regexp) {
3034
3051
  }
3035
3052
 
3036
3053
  /** Used to convert symbols to primitives and strings. */
3037
- var symbolProto = Symbol ? Symbol.prototype : undefined,
3054
+ var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined,
3038
3055
  symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
3039
3056
 
3040
3057
  /**
@@ -3891,6 +3908,7 @@ function getDefaultComponentSchemaInput(options) {
3891
3908
  hideFromComponentList: false,
3892
3909
  registry: "user-defined",
3893
3910
  icon: "",
3911
+ layerIcon: "",
3894
3912
  metadata: {},
3895
3913
  styles: {
3896
3914
  default: {
@@ -3953,6 +3971,16 @@ function processRegistryOptions(userConfig, options) {
3953
3971
  if ("icon" in userConfig && userConfig.icon) {
3954
3972
  defaultOptions.icon = userConfig.icon;
3955
3973
  }
3974
+ if (userConfig.layerIcon) {
3975
+ if (isValidLayerIcon(userConfig.layerIcon)) {
3976
+ defaultOptions.layerIcon = userConfig.layerIcon;
3977
+ }
3978
+ else {
3979
+ // Don't break registration over a bad icon — drop it and fall back to the default glyph.
3980
+ console.warn(`[studio] Ignoring invalid \`layerIcon\` for component "${userConfig.type}". ` +
3981
+ `Expected an inline SVG string, an absolute http(s)/data:image URL, or a servable relative path.`);
3982
+ }
3983
+ }
3956
3984
  if (userConfig.metadata) {
3957
3985
  defaultOptions.metadata = userConfig.metadata;
3958
3986
  }
@@ -3961,6 +3989,31 @@ function processRegistryOptions(userConfig, options) {
3961
3989
  propValidators,
3962
3990
  };
3963
3991
  }
3992
+ /**
3993
+ * Light, render-agnostic check that a `layerIcon` value is plausibly an inline SVG,
3994
+ * an image URL, or a servable path. This is developer feedback only — the Studio
3995
+ * builder still sanitizes/validates authoritatively at render time, since the value
3996
+ * crosses the postMessage boundary untrusted.
3997
+ */
3998
+ function isValidLayerIcon(value) {
3999
+ if (typeof value !== "string")
4000
+ return false;
4001
+ const v = value.trim();
4002
+ if (!v)
4003
+ return false;
4004
+ // Inline SVG markup (with or without an xml prolog).
4005
+ if (v.startsWith("<"))
4006
+ return v.includes("<svg");
4007
+ // Absolute http(s) URL.
4008
+ if (/^https?:\/\//i.test(v))
4009
+ return true;
4010
+ // A data URI must be an image.
4011
+ if (/^data:/i.test(v))
4012
+ return /^data:image\//i.test(v);
4013
+ // A relative/root-relative asset path. Must be explicitly path-shaped — a bare token
4014
+ // (e.g. a built-in icon NAME like "ComponentBox") is NOT a valid layerIcon.
4015
+ return v.startsWith("/") || v.startsWith("./") || v.startsWith("../");
4016
+ }
3964
4017
  function processStylesOptionsStyleSections(styleSections, defaultStyleSections) {
3965
4018
  if (typeof styleSections === "undefined" || styleSections === "all") {
3966
4019
  return defaultStyleSections;
@@ -4034,11 +4087,26 @@ function processRegistryOptionsProps(props) {
4034
4087
  }
4035
4088
  processedProps[field] = clone(prop);
4036
4089
  delete processedProps[field].validate;
4090
+ normalizeChoiceDefaultValue(processedProps[field]);
4037
4091
  }
4038
4092
  }
4039
4093
  validateSlotCountPropLinkages(props, processedProps);
4040
4094
  return { props: processedProps, validators: propValidators };
4041
4095
  }
4096
+ /**
4097
+ * The editor stores a single-select choice value as a `string[]` (and the SDK unwraps
4098
+ * it to a scalar on render). Authors may write a single-select `defaultValue` as a
4099
+ * scalar for ergonomics, so canonicalize it to a one-element array here — that keeps
4100
+ * one storage shape across every consumer. Without it, a scalar default reaches the
4101
+ * editor's array-only reader and the choice control renders with nothing selected.
4102
+ */
4103
+ function normalizeChoiceDefaultValue(prop) {
4104
+ if (prop.type === "choice" &&
4105
+ !prop.multiSelect &&
4106
+ typeof prop.defaultValue === "string") {
4107
+ prop.defaultValue = [prop.defaultValue];
4108
+ }
4109
+ }
4042
4110
  function getExpandedPropTypes(prop) {
4043
4111
  const propTypeMapping = {
4044
4112
  array: { type: "array", items: { type: "any" } },
@@ -4095,6 +4163,15 @@ function getDefaultComponentRegistryOptions() {
4095
4163
  };
4096
4164
  }
4097
4165
 
4166
+ /**
4167
+ * True when the value is an RSC client-reference proxy — what a `"use client"`
4168
+ * module's exports look like from the server module graph (Next.js App
4169
+ * Router, Turbopack). Invoking one during SSR throws "Attempted to call X()
4170
+ * from the server", so real implementations always take precedence over
4171
+ * proxies in the registry.
4172
+ */
4173
+ const isClientReferenceComponent = (component) => component?.$$typeof ===
4174
+ Symbol.for("react.client.reference");
4098
4175
  class ComponentRegistry {
4099
4176
  componentRegistry = new Map();
4100
4177
  propValidatorRegistry = new Map();
@@ -4162,7 +4239,9 @@ class ComponentRegistry {
4162
4239
  // sync unregistered components (never remove system / built-in entries)
4163
4240
  this.componentRegistry.forEach((componentConfig) => {
4164
4241
  if (!updatedConfig.some((c) => c.type === componentConfig.type)) {
4165
- if (SYSTEM_COMPONENTS.has(componentConfig.type)) {
4242
+ if (SYSTEM_COMPONENTS.has(componentConfig.type) ||
4243
+ componentConfig.metadata?.type === "symbol" ||
4244
+ componentConfig.metadata?.type === "section-composition") {
4166
4245
  return;
4167
4246
  }
4168
4247
  this.unregisterComponent(componentConfig.type);
@@ -4208,8 +4287,24 @@ class ComponentRegistry {
4208
4287
  console.warn("Default components are not allowed.");
4209
4288
  }
4210
4289
  }
4211
- // If already have and override not allowed continue with registered version
4212
- if (this.componentRegistry.has(type) && !options.overrideComponents) {
4290
+ const existing = this.componentRegistry.get(type);
4291
+ const existingIsClientReference = isClientReferenceComponent(existing?.component);
4292
+ const incomingIsClientReference = isClientReferenceComponent(componentConfig.component);
4293
+ // Never downgrade: a client-reference proxy (RSC server module graph)
4294
+ // must not replace an already-registered real implementation. The
4295
+ // registry is a globalThis singleton shared between the server graph
4296
+ // and the SSR pass — if the proxy wins, SSR emits empty placeholders
4297
+ // instead of content.
4298
+ if (existing && incomingIsClientReference && !existingIsClientReference) {
4299
+ return;
4300
+ }
4301
+ // If already have and override not allowed continue with registered
4302
+ // version — unless the stored entry is a client-reference proxy and a
4303
+ // real implementation just arrived (SSR/client graph registering after
4304
+ // the server graph): upgrade so server renders emit real content.
4305
+ if (existing &&
4306
+ !options.overrideComponents &&
4307
+ !(existingIsClientReference && !incomingIsClientReference)) {
4213
4308
  return;
4214
4309
  }
4215
4310
  const { processedOptions, propValidators } = processRegistryOptions(componentConfig, {
@@ -4236,23 +4331,64 @@ class ComponentRegistry {
4236
4331
  this.componentRegistry.set(type, processedOptions);
4237
4332
  });
4238
4333
  }
4334
+ registerSectionComponent(componentsConfigs) {
4335
+ componentsConfigs.forEach((componentConfig) => {
4336
+ const { type } = componentConfig;
4337
+ componentConfig["sections"] = [
4338
+ INTERNAL_COMPONENT_SECTIONS.SECTION_COMPOSITION,
4339
+ ];
4340
+ componentConfig["hideFromComponentList"] = true;
4341
+ const { processedOptions } = processRegistryOptions(componentConfig, {
4342
+ registry: "symbols",
4343
+ });
4344
+ this.componentRegistry.set(type, processedOptions);
4345
+ });
4346
+ }
4239
4347
  /**
4240
4348
  * Registers one or more components in the component registry.
4349
+ *
4350
+ * By default, duplicate registrations (same `type` registered twice) are
4351
+ * silently skipped — making the call **idempotent**. This is the desired
4352
+ * behaviour under:
4353
+ * - HMR re-evaluation (the same module runs twice in dev),
4354
+ * - dual-bundle scenarios (RSC + client both pull in the registration
4355
+ * module),
4356
+ * - prod build workers (each worker may re-import the module),
4357
+ * - test setup re-runs.
4358
+ *
4359
+ * The previous default — throwing on duplicate — forced every consumer to
4360
+ * wrap the call in `try/catch` to absorb the throw, which had the side
4361
+ * effect of masking real registration errors (typos in `type`, malformed
4362
+ * schemas). Real errors now surface on the first call; duplicates no longer
4363
+ * trip them up.
4364
+ *
4365
+ * Pass `{ strict: true }` to opt back into the old behaviour (throw on any
4366
+ * duplicate). This is useful in tests that want to assert a clean
4367
+ * registration boundary. `overrideDefaultComponents` on the registry config
4368
+ * still wins over both — it lets a duplicate replace the existing entry.
4369
+ *
4241
4370
  * @param components - An array of component options to register.
4371
+ * @param options - Per-call registration options. `strict: true` reinstates
4372
+ * the throw on duplicate.
4242
4373
  */
4243
- registerComponents(components) {
4374
+ registerComponents(components, options) {
4244
4375
  components.forEach((componentOption) => {
4245
4376
  const { type } = componentOption;
4246
4377
  if (!type) {
4247
4378
  throw new Error("Component type is required.");
4248
4379
  }
4249
- if (this.componentRegistry.has(type) &&
4250
- !this.config.overrideDefaultComponents) {
4251
- throw new Error(`Component with type '${type}' is already registered.`);
4252
- }
4253
4380
  if (SYSTEM_COMPONENTS.has(type)) {
4254
4381
  throw new Error(`Component with type '${type}' is a system component and cannot be overridden.`);
4255
4382
  }
4383
+ if (this.componentRegistry.has(type) &&
4384
+ !this.config.overrideDefaultComponents) {
4385
+ if (options?.strict) {
4386
+ throw new Error(`Component with type '${type}' is already registered.`);
4387
+ }
4388
+ // Idempotent default: silently skip duplicates so HMR/dual-graph/
4389
+ // worker re-evaluation does not break a working integration.
4390
+ return;
4391
+ }
4256
4392
  const { processedOptions, propValidators } = processRegistryOptions(componentOption, {
4257
4393
  registry: "user-defined",
4258
4394
  });
@@ -4369,6 +4505,10 @@ class ComponentRegistry {
4369
4505
  }
4370
4506
  return getSymbolUIDFromNode(node);
4371
4507
  }
4508
+ if (type === "section-composition") {
4509
+ const resolvedName = getSectionUIDFromNode(node) || type;
4510
+ return resolvedName;
4511
+ }
4372
4512
  return type;
4373
4513
  }
4374
4514
  /**
@@ -4516,34 +4656,72 @@ class ComponentRegistry {
4516
4656
  }
4517
4657
 
4518
4658
  /**
4519
- * Singleton instance of ComponentRegistry.
4520
- * This ensures all packages (studio-client, studio-react, etc.) use the same registry instance.
4659
+ * Cross-runtime singleton storage for SDK-owned registries.
4660
+ *
4661
+ * Why globalThis: a module-scoped `let instance` only exists within whichever
4662
+ * module-graph evaluates the file. Next.js maintains two graphs (RSC server +
4663
+ * client); Webpack/Turbopack treat them as independent realms. A registry
4664
+ * populated in one graph is invisible to the other. Prod build workers don't
4665
+ * share JS heap either — each worker has its own module-scoped state.
4666
+ *
4667
+ * globalThis is uniformly available across Node, browser, Edge runtime,
4668
+ * Cloudflare/Vercel workers, Deno, Bun, and Web Workers, and is shared by RSC
4669
+ * + client graphs within a single process. Storing SDK runtime singletons here
4670
+ * makes them visible to every consumer regardless of bundler or graph.
4521
4671
  *
4522
- * Using a singleton pattern here is appropriate because:
4523
- * 1. There should only be one component registry per application
4524
- * 2. Multiple packages need to access the same instance
4525
- * 3. Avoids circular dependencies between packages
4672
+ * The key is versioned (`_v1`) so future shape changes can land under `_v2`
4673
+ * without colliding with older SDK copies during a partial upgrade.
4526
4674
  */
4527
- let instance = null;
4675
+ const GLOBAL_STORE_KEY = "__contentstack_studio_registry_v1";
4528
4676
  /**
4529
- * Gets the singleton ComponentRegistry instance.
4530
- * Creates it if it doesn't exist yet.
4677
+ * Returns the SDK's versioned slot on globalThis, creating it on first call.
4678
+ * Always returns the same object reference within a single JS runtime.
4531
4679
  *
4532
- * @returns The singleton ComponentRegistry instance
4680
+ * Type-erased on purpose: each registry singleton casts to its own type on
4681
+ * read/write so the public API of `studio-registry` stays free of cross-
4682
+ * package import dependencies (e.g. `BreakpointManager` lives in
4683
+ * `studio-client`).
4684
+ */
4685
+ function getGlobalStudioStore() {
4686
+ const g = globalThis;
4687
+ if (!g[GLOBAL_STORE_KEY]) {
4688
+ g[GLOBAL_STORE_KEY] = {
4689
+ componentRegistry: null,
4690
+ designRegistry: null,
4691
+ breakpointManager: null,
4692
+ };
4693
+ }
4694
+ return g[GLOBAL_STORE_KEY];
4695
+ }
4696
+ /**
4697
+ * Clears the entire store. For tests only. Production code should never call
4698
+ * this — it would orphan every existing reference to the previous instances.
4699
+ */
4700
+ function resetGlobalStudioStore() {
4701
+ const g = globalThis;
4702
+ delete g[GLOBAL_STORE_KEY];
4703
+ }
4704
+
4705
+ /**
4706
+ * Singleton ComponentRegistry, backed by a versioned slot on `globalThis`.
4533
4707
  *
4534
- * @example
4535
- * ```typescript
4536
- * import { getComponentRegistryInstance } from '@contentstack/studio-registry';
4708
+ * The previous module-scoped `let instance` only existed within whichever
4709
+ * module-graph evaluated this file. Under Next.js's dual RSC/client graph or
4710
+ * across prod build workers, that meant two registries with no sharing —
4711
+ * `fetchCompositionData` (server) could see an empty registry while
4712
+ * `<StudioComponent>` (client) saw a populated one. See `common/global-store.ts`
4713
+ * for the full reasoning.
4537
4714
  *
4538
- * const registry = getComponentRegistryInstance();
4539
- * await registry.loadComponent('my-component');
4540
- * ```
4715
+ * After this change, all callers of `getComponentRegistryInstance()` resolve
4716
+ * to the same `ComponentRegistry` instance within a single JS runtime,
4717
+ * regardless of which graph or worker they were evaluated in.
4541
4718
  */
4542
4719
  function getComponentRegistryInstance() {
4543
- if (!instance) {
4544
- instance = new ComponentRegistry();
4720
+ const store = getGlobalStudioStore();
4721
+ if (!store.componentRegistry) {
4722
+ store.componentRegistry = new ComponentRegistry();
4545
4723
  }
4546
- return instance;
4724
+ return store.componentRegistry;
4547
4725
  }
4548
4726
  /**
4549
4727
  * Resets the singleton instance.
@@ -4559,7 +4737,7 @@ function getComponentRegistryInstance() {
4559
4737
  * ```
4560
4738
  */
4561
4739
  function resetComponentRegistryInstance() {
4562
- instance = null;
4740
+ getGlobalStudioStore().componentRegistry = null;
4563
4741
  }
4564
4742
  /**
4565
4743
  * Checks if the singleton instance has been created.
@@ -4567,7 +4745,7 @@ function resetComponentRegistryInstance() {
4567
4745
  * @returns true if the instance exists, false otherwise
4568
4746
  */
4569
4747
  function hasComponentRegistryInstance() {
4570
- return instance !== null;
4748
+ return getGlobalStudioStore().componentRegistry !== null;
4571
4749
  }
4572
4750
 
4573
4751
  const SIZE_TOKENS = {
@@ -5403,6 +5581,38 @@ class DesignRegistry {
5403
5581
  }
5404
5582
  }
5405
5583
 
5584
+ /**
5585
+ * Singleton DesignRegistry, backed by a versioned slot on `globalThis`.
5586
+ *
5587
+ * Previously, `studio-react/src/composable-studio/sdk.ts` did
5588
+ * `export const designRegistry = new DesignRegistry()` at module scope — which
5589
+ * means every separate module-graph (RSC vs client, build workers) got its own
5590
+ * `DesignRegistry`. Design tokens registered on one side were invisible to the
5591
+ * other. See `common/global-store.ts` for the dual-graph background.
5592
+ *
5593
+ * After this change, all callers of `getDesignRegistryInstance()` resolve to
5594
+ * the same `DesignRegistry` within a single JS runtime.
5595
+ */
5596
+ function getDesignRegistryInstance() {
5597
+ const store = getGlobalStudioStore();
5598
+ if (!store.designRegistry) {
5599
+ store.designRegistry = new DesignRegistry();
5600
+ }
5601
+ return store.designRegistry;
5602
+ }
5603
+ /**
5604
+ * Resets the singleton instance. For tests only.
5605
+ */
5606
+ function resetDesignRegistryInstance() {
5607
+ getGlobalStudioStore().designRegistry = null;
5608
+ }
5609
+ /**
5610
+ * Checks if the singleton instance has been created.
5611
+ */
5612
+ function hasDesignRegistryInstance() {
5613
+ return getGlobalStudioStore().designRegistry !== null;
5614
+ }
5615
+
5406
5616
  class JSONRTERegistry {
5407
5617
  config;
5408
5618
  constructor(config) {
@@ -5666,6 +5876,7 @@ function getDefaultPropStaticValue(args) {
5666
5876
  datestring: "",
5667
5877
  any: "",
5668
5878
  json_rte: {},
5879
+ plaintext: "",
5669
5880
  };
5670
5881
  if (args) {
5671
5882
  return defaultValues[args];
@@ -5686,6 +5897,7 @@ function isKnownType(type) {
5686
5897
  datestring: true,
5687
5898
  any: true,
5688
5899
  json_rte: true,
5900
+ plaintext: true,
5689
5901
  };
5690
5902
  return Object.keys(knownTypes).includes(type);
5691
5903
  }
@@ -5806,8 +6018,12 @@ function isDataMatchingPropType(data, type) {
5806
6018
  imageurl: dataType === "string",
5807
6019
  datestring: dataType === "string",
5808
6020
  json_rte: dataType === "object",
6021
+ // "any" accepts all data types — no validation
6022
+ any: true,
6023
+ // "plaintext" accepts singleline/multiline text, number, and boolean fields
6024
+ plaintext: dataType === "string" || dataType === "number" || dataType === "boolean",
5809
6025
  };
5810
- return map[type];
6026
+ return map[type] ?? false;
5811
6027
  }
5812
6028
  function getDataType(data) {
5813
6029
  if (typeof data === "object" && data !== null && !Array.isArray(data)) {
@@ -5827,6 +6043,48 @@ const dataSourceCapabilities = {
5827
6043
  [DATA_SOURCES.QUERY]: { supportsCslp: true }, // Verified: Query supports CSLP now
5828
6044
  };
5829
6045
 
6046
+ /**
6047
+ * Prop keys (`<nodeUid>-<field>`) for which a binding-type-mismatch error has
6048
+ * been reported to the editor and not yet retracted.
6049
+ *
6050
+ * The editor's "Data Mismatch Found" badge is driven entirely by the
6051
+ * UPDATE_BINDING_ERRORS messages we send from here — it has no other source of
6052
+ * truth. Previously we only ever SENT errors and never retracted them, so a
6053
+ * transient mismatch (e.g. a section repeater bound to scope-root that briefly
6054
+ * sees the whole entry OBJECT while a freshly-swapped schema re-scopes) left a
6055
+ * sticky error that survived even after the data resolved correctly. Tracking
6056
+ * what we've reported lets us emit a one-shot retraction the moment the data
6057
+ * matches again, so the badge reflects the live render instead of latching.
6058
+ */
6059
+ const reportedBindingErrors = new Set();
6060
+ /**
6061
+ * Retract every binding-mismatch error previously reported for `nodeUid`'s
6062
+ * props and forget them.
6063
+ *
6064
+ * The in-render retraction in `retrievePropValue` only clears the editor badge
6065
+ * when the SAME node re-renders with matching data — which never happens once
6066
+ * the node disappears (e.g. a repeater item removed, or a section swapped for a
6067
+ * different schema). Without this, such a node's badge would latch and its
6068
+ * entry would leak in `reportedBindingErrors` forever. Call this from the
6069
+ * node's unmount path so the badge reflects the live tree.
6070
+ *
6071
+ * Keys are `${nodeUid}-${field}`; the trailing `-` (and fixed-length uids)
6072
+ * makes the prefix match exact, so one node's uid can't match another's.
6073
+ */
6074
+ function clearReportedBindingErrorsForNode(nodeUid) {
6075
+ if (reportedBindingErrors.size === 0)
6076
+ return;
6077
+ const prefix = `${nodeUid}-`;
6078
+ for (const propKey of reportedBindingErrors) {
6079
+ if (!propKey.startsWith(prefix))
6080
+ continue;
6081
+ reportedBindingErrors.delete(propKey);
6082
+ studioMessenger.composableStudioEventManager?.send(studioMessenger.POST_MESSAGE_EVENTS.UPDATE_BINDING_ERRORS, {
6083
+ propKey,
6084
+ errorMessage: "",
6085
+ });
6086
+ }
6087
+ }
5830
6088
  // Responsible for resolving props to values
5831
6089
  function retrievePropValue(args) {
5832
6090
  const { data, componentOptions, node, cslp, placeholders = {}, getSlots, jsonRTE, isCompositionBeingEdited, } = args;
@@ -5855,6 +6113,11 @@ function retrievePropValue(args) {
5855
6113
  return;
5856
6114
  }
5857
6115
  let resolvedData;
6116
+ // When the value is resolved via the `dataSources.page.*` fallback below,
6117
+ // the CSLP tag must come from the SAME page path (not the section-local
6118
+ // binding, which missed). Holds that page path so the cslp block points the
6119
+ // edit tag at the field the value actually came from.
6120
+ let cslpPathOverride;
5858
6121
  if (type === "slot") {
5859
6122
  resolvedData = getSlotData({
5860
6123
  nodeProps: nodeProps,
@@ -5865,6 +6128,32 @@ function retrievePropValue(args) {
5865
6128
  mappedData[field] = resolvedData;
5866
6129
  return;
5867
6130
  }
6131
+ // Section exposed-prop override: the page composer's exposed-prop binding is
6132
+ // the SOLE source of truth for an exposed field — the internal node's own
6133
+ // binding must never leak through on a page. SectionCompositionProvider emits
6134
+ // an entry for EVERY exposed prop (even when the page value is cleared/empty),
6135
+ // so we apply on key PRESENCE, not on a non-undefined value. A cleared prop
6136
+ // therefore renders the page-resolved empty value instead of falling back to
6137
+ // the section's authored binding.
6138
+ const overridesForNode = data.dataSources?.section_exposed_overrides?.[node.uid];
6139
+ if (overridesForNode && field in overridesForNode) {
6140
+ mappedData[field] = overridesForNode[field];
6141
+ // Carry the page-resolved CSLP tag for this exposed prop. This branch
6142
+ // short-circuits BEFORE the cslp block (~L430), so without re-emitting
6143
+ // here a page-overridden field (e.g. a section's root component bound via
6144
+ // a non-repeater binding) renders with no `data-cslp` and loses its
6145
+ // live-preview edit overlay — even though its value resolves fine. The
6146
+ // SectionComposition wrappers stash the page node's resolved cslp object
6147
+ // alongside the value under `$<propKey>`, so it points at the PAGE entry
6148
+ // field (the override's source of truth). Repeater-context exposed props
6149
+ // are never in this map (they fall through to their own binding + cslp).
6150
+ if (cslp.appendTags) {
6151
+ const overrideCslp = overridesForNode[`$${field}`];
6152
+ if (overrideCslp)
6153
+ mappedData[`$${field}`] = overrideCslp;
6154
+ }
6155
+ return;
6156
+ }
5868
6157
  const nodePropConfig = nodeProps[field];
5869
6158
  const { binding: bindedField, value: staticValue } = nodePropConfig || {};
5870
6159
  //TODO: Get proper data for design
@@ -5924,6 +6213,40 @@ function retrievePropValue(args) {
5924
6213
  else if (dataPath &&
5925
6214
  !(type === "choice" && bindedField?.type === "static_value")) {
5926
6215
  resolvedData = get(data, dataPath, fallbackValue);
6216
+ // TEMP — slot-child page-context fallback (PHASE 8 will remove this).
6217
+ //
6218
+ // Section-slot wraps its children's data context so that:
6219
+ // dataSources.template / .contentstack / .contentstack_queries / .repeater
6220
+ // ALL refer to the section's LOCAL surrounding context — matching what
6221
+ // the Data Picker currently writes when authoring a slot child against
6222
+ // section-local fields.
6223
+ //
6224
+ // The page's outer entries live at `dataSources.page.template`, etc., as
6225
+ // the explicit escape namespace. But until the Picker is slot-aware
6226
+ // (Phase 8), it has no way to write `dataSources.page.X` paths — so a
6227
+ // page-level binding authored on a slot child still produces a
6228
+ // `dataSources.<source>.X` path that targets the section-local view and
6229
+ // resolves to undefined.
6230
+ //
6231
+ // Bridge: if the local resolution is missing AND a `page` sibling
6232
+ // namespace exists on dataSources, retry under `dataSources.page.X`. Remove
6233
+ // this fallback when the Picker emits explicit `dataSources.page.X`
6234
+ // paths.
6235
+ if ((resolvedData === undefined ||
6236
+ resolvedData === null ||
6237
+ resolvedData === fallbackValue) &&
6238
+ typeof dataPath === "string" &&
6239
+ dataPath.startsWith("dataSources.") &&
6240
+ !dataPath.startsWith("dataSources.page.") &&
6241
+ data?.dataSources?.page) {
6242
+ const pagePath = dataPath.replace(/^dataSources\./, "dataSources.page.");
6243
+ const pageResolved = get(data, pagePath, undefined);
6244
+ if (pageResolved !== undefined && pageResolved !== null) {
6245
+ resolvedData = pageResolved;
6246
+ // Mirror the value's source so the cslp block tags the page field.
6247
+ cslpPathOverride = pagePath;
6248
+ }
6249
+ }
5927
6250
  // Handle primitive values in repeater context
5928
6251
  // When the array contains primitives (strings, numbers, etc.) instead of objects,
5929
6252
  // the binding path will be like: dataSources.repeater.{uid}.context.{fieldName}
@@ -6028,6 +6351,7 @@ function retrievePropValue(args) {
6028
6351
  });
6029
6352
  if (isCompositionBeingEdited) {
6030
6353
  // In editor mode: Send to Visual Builder
6354
+ reportedBindingErrors.add(`${node.uid}-${field}`);
6031
6355
  studioMessenger.composableStudioEventManager?.send(studioMessenger.POST_MESSAGE_EVENTS.UPDATE_BINDING_ERRORS, {
6032
6356
  propKey: `${node.uid}-${field}`,
6033
6357
  errorMessage: getRegistryErrorMessage(RegistryErrorMessageKey.DATA_BINDING_TYPE_MISMATCH_EDITOR, { expectedType: type, receivedType }),
@@ -6046,6 +6370,21 @@ function retrievePropValue(args) {
6046
6370
  });
6047
6371
  }
6048
6372
  }
6373
+ else if (isCompositionBeingEdited) {
6374
+ // Data now matches the prop type. If we previously reported a mismatch for
6375
+ // this prop, retract it (empty errorMessage → the editor calls
6376
+ // removeBindingError) so a stale "Data Mismatch Found" badge doesn't
6377
+ // persist after the binding re-resolves — e.g. once a swapped section
6378
+ // schema finishes re-scoping a repeater's items to its array field.
6379
+ const propKey = `${node.uid}-${field}`;
6380
+ if (reportedBindingErrors.has(propKey)) {
6381
+ reportedBindingErrors.delete(propKey);
6382
+ studioMessenger.composableStudioEventManager?.send(studioMessenger.POST_MESSAGE_EVENTS.UPDATE_BINDING_ERRORS, {
6383
+ propKey,
6384
+ errorMessage: "",
6385
+ });
6386
+ }
6387
+ }
6049
6388
  mappedData[field] = resolvedData;
6050
6389
  if (type === "json_rte") {
6051
6390
  mappedData["jsonConfig"] = jsonRTE;
@@ -6053,7 +6392,13 @@ function retrievePropValue(args) {
6053
6392
  const isCSLPAbleType = bindedField?.type &&
6054
6393
  dataSourceCapabilities[bindedField.type]?.supportsCslp;
6055
6394
  if (cslp.appendTags && dataPath && isCSLPAbleType) {
6056
- const cslpValue = getCslpTag({ bindedField: dataPath, data });
6395
+ // Use the page-fallback path when the value came from there (cross-section
6396
+ // / slot-child page binding), so the edit tag points at the field that
6397
+ // actually supplied the value; otherwise the section-local binding path.
6398
+ const cslpValue = getCslpTag({
6399
+ bindedField: cslpPathOverride ?? dataPath,
6400
+ data,
6401
+ });
6057
6402
  if (cslpValue) {
6058
6403
  mappedData[`$${field}`] = cslpValue;
6059
6404
  }
@@ -6063,6 +6408,14 @@ function retrievePropValue(args) {
6063
6408
  mappedData["_uid"] = node.uid;
6064
6409
  mappedData["mode"] = node?.metadata?.mode;
6065
6410
  }
6411
+ if (node.type === "section-slot") {
6412
+ // Section-slot needs its own node uid at render time so it can look up
6413
+ // the page-side fill in SectionInstanceSlotsCtx.slotsMap[node.uid].
6414
+ mappedData["_uid"] = node.uid;
6415
+ // The authored Slot default (COMS-1659): rendered when a placement leaves
6416
+ // the slot empty (editor preview only; design keeps the dropzone).
6417
+ mappedData["defaultSection"] = node?.metadata?.defaultSection?.uid;
6418
+ }
6066
6419
  if (node.type === "condition-block") {
6067
6420
  mappedData["condition"] = node?.metadata?.condition;
6068
6421
  mappedData["mode"] = node?.metadata?.mode;
@@ -6080,6 +6433,34 @@ function retrievePropValue(args) {
6080
6433
  mappedData["symbol_props"][uid] = mappedData[field];
6081
6434
  });
6082
6435
  }
6436
+ if (node.type === "section-composition") {
6437
+ // Surface the page composer's LIVE binding type for each exposed prop so the
6438
+ // SectionComposition renderer can tell an untouched seed from a real override.
6439
+ // A repeater expose-time binding is only resolvable inside the section's own
6440
+ // Repeater scope; at page level it resolves to a placeholder, not undefined —
6441
+ // so the resolved VALUE can't distinguish "untouched" from "overridden". The
6442
+ // live binding type can: still `repeater` (or absent) ⇒ untouched, fall
6443
+ // through to the internal per-iteration binding; any page-resolvable type ⇒
6444
+ // the composer rebound it and the override must win.
6445
+ const bindingTypes = {};
6446
+ const autoSeeded = {};
6447
+ for (const field of Object.keys(nodeProps)) {
6448
+ const binding = nodeProps[field]?.binding;
6449
+ if (binding?.type)
6450
+ bindingTypes[field] = binding.type;
6451
+ // An auto-seeded binding means the page composer hasn't touched this exposed
6452
+ // prop — the renderer skips its override so the section's internal binding
6453
+ // resolves (re-scoped on schema switch / per repeater iteration).
6454
+ if (binding?.autoSeeded)
6455
+ autoSeeded[field] = true;
6456
+ }
6457
+ mappedData["section_exposed_binding_types"] = bindingTypes;
6458
+ mappedData["section_exposed_auto_seeded"] = autoSeeded;
6459
+ // Per-placement design/preview mode. The editor's SectionComposition uses
6460
+ // this to derive/override the render mode of every repeater, condition-block,
6461
+ // and section-slot inside the section. Ignored in production (renders live).
6462
+ mappedData["mode"] = node?.metadata?.mode;
6463
+ }
6083
6464
  // TODO: Add support for useData Hook for studio
6084
6465
  return mappedData;
6085
6466
  }
@@ -6165,6 +6546,7 @@ exports.JSONRTERegistry = JSONRTERegistry;
6165
6546
  exports.STYLE_SECTIONS_OPTIONS = STYLE_SECTIONS_OPTIONS;
6166
6547
  exports.STYLE_SECTION_CATEGORIES = STYLE_SECTION_CATEGORIES;
6167
6548
  exports.SYSTEM_COMPONENTS = SYSTEM_COMPONENTS;
6549
+ exports.clearReportedBindingErrorsForNode = clearReportedBindingErrorsForNode;
6168
6550
  exports.convertBindingPath = convertBindingPath;
6169
6551
  exports.getBindingString = getBindingString;
6170
6552
  exports.getComponentRegistryInstance = getComponentRegistryInstance;
@@ -6173,18 +6555,24 @@ exports.getCslpTag = getCslpTag;
6173
6555
  exports.getDataType = getDataType;
6174
6556
  exports.getDefaultPropStaticValue = getDefaultPropStaticValue;
6175
6557
  exports.getDesignClassesNames = getDesignClassesNames;
6558
+ exports.getDesignRegistryInstance = getDesignRegistryInstance;
6176
6559
  exports.getFlattenedData = getFlattenedData;
6560
+ exports.getGlobalStudioStore = getGlobalStudioStore;
6177
6561
  exports.getPlaceHolderComponent = getPlaceHolderComponent;
6178
6562
  exports.getRepeaterBinding = getRepeaterBinding;
6179
6563
  exports.getRepeaterContextPath = getRepeaterContextPath;
6564
+ exports.getSectionUIDFromNode = getSectionUIDFromNode;
6180
6565
  exports.getSlotData = getSlotData;
6181
6566
  exports.getSymbolUIDFromNode = getSymbolUIDFromNode;
6182
6567
  exports.getSymbolUIDFromUID = getSymbolUIDFromUID;
6183
6568
  exports.hasComponentRegistryInstance = hasComponentRegistryInstance;
6569
+ exports.hasDesignRegistryInstance = hasDesignRegistryInstance;
6184
6570
  exports.isDataMatchingPropType = isDataMatchingPropType;
6185
6571
  exports.isKnownType = isKnownType;
6186
6572
  exports.normalizeSingleSelectChoiceValue = normalizeSingleSelectChoiceValue;
6187
6573
  exports.resetComponentRegistryInstance = resetComponentRegistryInstance;
6574
+ exports.resetDesignRegistryInstance = resetDesignRegistryInstance;
6575
+ exports.resetGlobalStudioStore = resetGlobalStudioStore;
6188
6576
  exports.resolveMetadataBindings = resolveMetadataBindings;
6189
6577
  exports.retrievePropValue = retrievePropValue;
6190
6578
  //# sourceMappingURL=index.cjs.map