@contentstack/studio-registry 1.4.0 → 1.4.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 = [
@@ -125,6 +126,7 @@ const INTERNAL_COMPONENTS_NAMES = {
125
126
  LINK: "link",
126
127
  LINK_CONTAINER: "link-container",
127
128
  TEXT: "text",
129
+ NUMBER: "number",
128
130
  BUTTON: "button",
129
131
  JSON_RTE: "json-rte",
130
132
  COLLAPSIBLE_TEXT: "collapsible-text",
@@ -142,6 +144,10 @@ const INTERNAL_COMPONENTS_NAMES = {
142
144
  CONDITION_BLOCK: "condition-block",
143
145
  SYMBOL: "symbol",
144
146
  FRAGMENT: "fragment",
147
+ // Exposed-slot placeholder authored inside a section composition. When the
148
+ // section is dropped into a page, each section-slot becomes a fill point
149
+ // the page composer can drop arbitrary components into.
150
+ SECTION_SLOT: "section-slot",
145
151
  // * HTML Elements
146
152
  HTML_ELEMENT: "html-element",
147
153
  STYLE_SHEET: "style-sheet",
@@ -161,6 +167,7 @@ const BUILT_IN_COMPONENTS = {
161
167
  LINK: "link",
162
168
  LINK_CONTAINER: "link-container",
163
169
  TEXT: "text",
170
+ NUMBER: "number",
164
171
  BUTTON: "button",
165
172
  JSON_RTE: "json-rte",
166
173
  COLLAPSIBLE_TEXT: "collapsible-text",
@@ -183,6 +190,17 @@ const getSymbolUIDFromUID = (uid) => {
183
190
  return `${INTERNAL_COMPONENTS_NAMES.SYMBOL}-${uid}`;
184
191
  };
185
192
 
193
+ /**
194
+ * Extracts the composition UID from a section-composition node's metadata.
195
+ * Used to resolve section references to their actual composition identifiers.
196
+ *
197
+ * @param section - The section node containing metadata
198
+ * @returns The composition UID or undefined if not present
199
+ */
200
+ const getSectionUIDFromNode = (section) => {
201
+ return section.metadata?.compositionUID;
202
+ };
203
+
186
204
  /** Detect free variable `global` from Node.js. */
187
205
  var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
188
206
 
@@ -4034,6 +4052,7 @@ function processRegistryOptionsProps(props) {
4034
4052
  delete processedProps[field].validate;
4035
4053
  }
4036
4054
  }
4055
+ validateSlotCountPropLinkages(props, processedProps);
4037
4056
  return { props: processedProps, validators: propValidators };
4038
4057
  }
4039
4058
  function getExpandedPropTypes(prop) {
@@ -4050,6 +4069,32 @@ function getExpandedPropTypes(prop) {
4050
4069
  };
4051
4070
  return propTypeMapping[prop];
4052
4071
  }
4072
+ function validateSlotCountPropLinkages(originalProps, processedProps) {
4073
+ if (!originalProps)
4074
+ return;
4075
+ for (const [field, prop] of Object.entries(originalProps)) {
4076
+ if (typeof prop === "string" || prop.type !== "slot")
4077
+ continue;
4078
+ const slotProp = prop;
4079
+ if (!slotProp.countProp)
4080
+ continue;
4081
+ const linkedProp = originalProps[slotProp.countProp];
4082
+ const linkedPropType = typeof linkedProp === "string" ? linkedProp : linkedProp?.type;
4083
+ if (!linkedProp || linkedPropType !== "number") {
4084
+ throw new Error(`Slot "${field}" references countProp "${slotProp.countProp}" which must be a registered number prop.`);
4085
+ }
4086
+ if (!slotProp.itemFactory || typeof slotProp.itemFactory !== "function") {
4087
+ throw new Error(`Slot "${field}" with countProp must provide an itemFactory function.`);
4088
+ }
4089
+ const existingSlotProp = processedProps[field];
4090
+ processedProps[field] = {
4091
+ ...existingSlotProp,
4092
+ countProp: slotProp.countProp,
4093
+ itemFactory: slotProp.itemFactory,
4094
+ itemTemplate: slotProp.itemFactory(),
4095
+ };
4096
+ }
4097
+ }
4053
4098
  function getBlockStyleSections() {
4054
4099
  return STYLE_SECTION_CATEGORIES.block;
4055
4100
  }
@@ -4070,6 +4115,10 @@ class ComponentRegistry {
4070
4115
  componentRegistry = new Map();
4071
4116
  propValidatorRegistry = new Map();
4072
4117
  config;
4118
+ // Lazy loading infrastructure
4119
+ componentLoaders = new Map();
4120
+ loadedComponents = new Set();
4121
+ loadingPromises = new Map();
4073
4122
  constructor(config) {
4074
4123
  // TODO process options
4075
4124
  this.config = config || getDefaultComponentRegistryOptions();
@@ -4079,6 +4128,9 @@ class ComponentRegistry {
4079
4128
  this.getComponents = this.getComponents.bind(this);
4080
4129
  this.getComponent = this.getComponent.bind(this);
4081
4130
  this.hasComponent = this.hasComponent.bind(this);
4131
+ this.registerLazyComponent = this.registerLazyComponent.bind(this);
4132
+ this.loadComponent = this.loadComponent.bind(this);
4133
+ this.loadComponents = this.loadComponents.bind(this);
4082
4134
  }
4083
4135
  setConfig(config = {}) {
4084
4136
  if (config.allowedBuiltInComponents !== undefined) {
@@ -4123,9 +4175,14 @@ class ComponentRegistry {
4123
4175
  const { type: name } = componentConfig;
4124
4176
  this.componentRegistry.set(name, componentConfig);
4125
4177
  });
4126
- // sync unregistered components
4178
+ // sync unregistered components (never remove system / built-in entries)
4127
4179
  this.componentRegistry.forEach((componentConfig) => {
4128
4180
  if (!updatedConfig.some((c) => c.type === componentConfig.type)) {
4181
+ if (SYSTEM_COMPONENTS.has(componentConfig.type) ||
4182
+ componentConfig.metadata?.type === "symbol" ||
4183
+ componentConfig.metadata?.type === "section-composition") {
4184
+ return;
4185
+ }
4129
4186
  this.unregisterComponent(componentConfig.type);
4130
4187
  }
4131
4188
  });
@@ -4197,23 +4254,64 @@ class ComponentRegistry {
4197
4254
  this.componentRegistry.set(type, processedOptions);
4198
4255
  });
4199
4256
  }
4257
+ registerSectionComponent(componentsConfigs) {
4258
+ componentsConfigs.forEach((componentConfig) => {
4259
+ const { type } = componentConfig;
4260
+ componentConfig["sections"] = [
4261
+ INTERNAL_COMPONENT_SECTIONS.SECTION_COMPOSITION,
4262
+ ];
4263
+ componentConfig["hideFromComponentList"] = true;
4264
+ const { processedOptions } = processRegistryOptions(componentConfig, {
4265
+ registry: "symbols",
4266
+ });
4267
+ this.componentRegistry.set(type, processedOptions);
4268
+ });
4269
+ }
4200
4270
  /**
4201
4271
  * Registers one or more components in the component registry.
4272
+ *
4273
+ * By default, duplicate registrations (same `type` registered twice) are
4274
+ * silently skipped — making the call **idempotent**. This is the desired
4275
+ * behaviour under:
4276
+ * - HMR re-evaluation (the same module runs twice in dev),
4277
+ * - dual-bundle scenarios (RSC + client both pull in the registration
4278
+ * module),
4279
+ * - prod build workers (each worker may re-import the module),
4280
+ * - test setup re-runs.
4281
+ *
4282
+ * The previous default — throwing on duplicate — forced every consumer to
4283
+ * wrap the call in `try/catch` to absorb the throw, which had the side
4284
+ * effect of masking real registration errors (typos in `type`, malformed
4285
+ * schemas). Real errors now surface on the first call; duplicates no longer
4286
+ * trip them up.
4287
+ *
4288
+ * Pass `{ strict: true }` to opt back into the old behaviour (throw on any
4289
+ * duplicate). This is useful in tests that want to assert a clean
4290
+ * registration boundary. `overrideDefaultComponents` on the registry config
4291
+ * still wins over both — it lets a duplicate replace the existing entry.
4292
+ *
4202
4293
  * @param components - An array of component options to register.
4294
+ * @param options - Per-call registration options. `strict: true` reinstates
4295
+ * the throw on duplicate.
4203
4296
  */
4204
- registerComponents(components) {
4297
+ registerComponents(components, options) {
4205
4298
  components.forEach((componentOption) => {
4206
4299
  const { type } = componentOption;
4207
4300
  if (!type) {
4208
4301
  throw new Error("Component type is required.");
4209
4302
  }
4210
- if (this.componentRegistry.has(type) &&
4211
- !this.config.overrideDefaultComponents) {
4212
- throw new Error(`Component with type '${type}' is already registered.`);
4213
- }
4214
4303
  if (SYSTEM_COMPONENTS.has(type)) {
4215
4304
  throw new Error(`Component with type '${type}' is a system component and cannot be overridden.`);
4216
4305
  }
4306
+ if (this.componentRegistry.has(type) &&
4307
+ !this.config.overrideDefaultComponents) {
4308
+ if (options?.strict) {
4309
+ throw new Error(`Component with type '${type}' is already registered.`);
4310
+ }
4311
+ // Idempotent default: silently skip duplicates so HMR/dual-graph/
4312
+ // worker re-evaluation does not break a working integration.
4313
+ return;
4314
+ }
4217
4315
  const { processedOptions, propValidators } = processRegistryOptions(componentOption, {
4218
4316
  registry: "user-defined",
4219
4317
  });
@@ -4248,7 +4346,24 @@ class ComponentRegistry {
4248
4346
  if (!this.componentRegistry.has(name)) {
4249
4347
  throw new Error(`Component with type '${name}' is not registered.`);
4250
4348
  }
4251
- return this.componentRegistry.get(name);
4349
+ const componentSchema = this.componentRegistry.get(name);
4350
+ // Check if this is a lazy component that hasn't been loaded yet
4351
+ if (componentSchema.component === null && this.componentLoaders.has(name)) {
4352
+ const errorMessage = [
4353
+ `Component '${name}' is registered as lazy but hasn't been loaded yet.`,
4354
+ "",
4355
+ "This usually happens when:",
4356
+ "1. fetchSpec() was not awaited before rendering",
4357
+ "2. The component is being used in editor mode without being loaded",
4358
+ "3. There was an error during component loading",
4359
+ "",
4360
+ "Fix: Ensure fetchSpec() is properly awaited:",
4361
+ " const spec = await fetchSpec({ ... });",
4362
+ " return <ComposableStudio spec={spec} />;",
4363
+ ].join("\n");
4364
+ throw new Error(errorMessage);
4365
+ }
4366
+ return componentSchema;
4252
4367
  }
4253
4368
  /**
4254
4369
  * Retrieves a component from the component registry by its name.
@@ -4274,11 +4389,9 @@ class ComponentRegistry {
4274
4389
  unregisterComponent(node) {
4275
4390
  const name = typeof node === "string" ? node : this.getComponentName(node);
4276
4391
  if (!this.componentRegistry.has(name)) {
4277
- console.error(`Component with type '${name}' is not registered.`);
4278
4392
  return;
4279
4393
  }
4280
4394
  if (SYSTEM_COMPONENTS.has(name)) {
4281
- console.error(`Component with type '${name}' is a system component and cannot be unregistered.`);
4282
4395
  return;
4283
4396
  }
4284
4397
  this.componentRegistry.delete(name);
@@ -4315,8 +4428,247 @@ class ComponentRegistry {
4315
4428
  }
4316
4429
  return getSymbolUIDFromNode(node);
4317
4430
  }
4431
+ if (type === "section-composition") {
4432
+ const resolvedName = getSectionUIDFromNode(node) || type;
4433
+ return resolvedName;
4434
+ }
4318
4435
  return type;
4319
4436
  }
4437
+ /**
4438
+ * Registers a lazy-loadable component with a loader function.
4439
+ * The component will be loaded on-demand when needed.
4440
+ *
4441
+ * @param config - Component configuration without the component itself
4442
+ * @param loader - Function that returns a Promise resolving to the component
4443
+ * @param registryType - Type of registry (internal or user-defined), defaults to user-defined
4444
+ */
4445
+ registerLazyComponent(config, loader, registryType = "user-defined") {
4446
+ const { type } = config;
4447
+ if (!type) {
4448
+ throw new Error("Component type is required.");
4449
+ }
4450
+ // For internal components, allow registration even if already exists
4451
+ // This is needed for built-in component lazy loading
4452
+ const isInternal = registryType === "internal";
4453
+ if (this.componentRegistry.has(type) &&
4454
+ !this.config.overrideDefaultComponents &&
4455
+ !isInternal) {
4456
+ throw new Error(`Component with type '${type}' is already registered.`);
4457
+ }
4458
+ if (SYSTEM_COMPONENTS.has(type) && !isInternal) {
4459
+ throw new Error(`Component with type '${type}' is a system component and cannot be overridden.`);
4460
+ }
4461
+ // Store the loader
4462
+ this.componentLoaders.set(type, loader);
4463
+ // Register a placeholder in the registry with _lazy flag
4464
+ const { processedOptions, propValidators } = processRegistryOptions({
4465
+ ...config,
4466
+ component: null, // Placeholder, will be loaded later
4467
+ }, {
4468
+ registry: registryType,
4469
+ });
4470
+ // Mark as lazy for internal tracking
4471
+ processedOptions._lazy = true;
4472
+ this.componentRegistry.set(type, processedOptions);
4473
+ this.propValidatorRegistry.set(type, propValidators);
4474
+ }
4475
+ /**
4476
+ * Loads a single component if it's registered as lazy and not yet loaded.
4477
+ * Returns immediately if already loaded or not a lazy component.
4478
+ *
4479
+ * @param componentType - The type of component to load
4480
+ * @returns Promise that resolves when the component is loaded
4481
+ */
4482
+ async loadComponent(componentType) {
4483
+ // Already loaded
4484
+ if (this.loadedComponents.has(componentType)) {
4485
+ return;
4486
+ }
4487
+ // Already loading
4488
+ if (this.loadingPromises.has(componentType)) {
4489
+ return this.loadingPromises.get(componentType);
4490
+ }
4491
+ // Not a lazy component or not registered
4492
+ const loader = this.componentLoaders.get(componentType);
4493
+ if (!loader) {
4494
+ return;
4495
+ }
4496
+ const loadPromise = (async () => {
4497
+ try {
4498
+ const component = await loader();
4499
+ // Update the registry with the loaded component
4500
+ const existingConfig = this.componentRegistry.get(componentType);
4501
+ if (existingConfig) {
4502
+ const updatedConfig = {
4503
+ ...existingConfig,
4504
+ component,
4505
+ };
4506
+ delete updatedConfig._lazy;
4507
+ this.componentRegistry.set(componentType, updatedConfig);
4508
+ }
4509
+ this.loadedComponents.add(componentType);
4510
+ this.loadingPromises.delete(componentType);
4511
+ }
4512
+ catch (error) {
4513
+ this.loadingPromises.delete(componentType);
4514
+ console.error(`Failed to load component '${componentType}':`, error);
4515
+ throw error;
4516
+ }
4517
+ })();
4518
+ this.loadingPromises.set(componentType, loadPromise);
4519
+ return loadPromise;
4520
+ }
4521
+ /**
4522
+ * Loads multiple components in parallel.
4523
+ * Deduplicates requests and uses caching.
4524
+ *
4525
+ * @param componentTypes - Array of component types to load
4526
+ * @returns Promise that resolves when all components are loaded
4527
+ */
4528
+ async loadComponents(componentTypes) {
4529
+ const uniqueTypes = Array.from(new Set(componentTypes));
4530
+ await Promise.all(uniqueTypes.map((type) => this.loadComponent(type)));
4531
+ }
4532
+ /**
4533
+ * Checks if a component is registered as lazy-loadable.
4534
+ *
4535
+ * @param componentType - The type of component to check
4536
+ * @returns true if the component is lazy-loadable
4537
+ */
4538
+ isLazyComponent(componentType) {
4539
+ return this.componentLoaders.has(componentType);
4540
+ }
4541
+ /**
4542
+ * Checks if a lazy component has been loaded.
4543
+ *
4544
+ * @param componentType - The type of component to check
4545
+ * @returns true if the component has been loaded
4546
+ */
4547
+ isComponentLoaded(componentType) {
4548
+ return this.loadedComponents.has(componentType);
4549
+ }
4550
+ /**
4551
+ * Checks if a component has a loader registered (lazy) or is already registered (eager).
4552
+ * This is useful for SSR validation to ensure components are available before rendering.
4553
+ *
4554
+ * @param componentType - The type of component to check
4555
+ * @returns true if the component has a loader or is registered
4556
+ */
4557
+ hasComponentLoader(componentType) {
4558
+ return (this.componentLoaders.has(componentType) ||
4559
+ this.componentRegistry.has(componentType));
4560
+ }
4561
+ /**
4562
+ * Gets all component types that have loaders registered (lazy components).
4563
+ * Useful for debugging and SSR setup validation.
4564
+ *
4565
+ * @returns Array of component types with lazy loaders
4566
+ */
4567
+ getLazyComponentTypes() {
4568
+ return Array.from(this.componentLoaders.keys());
4569
+ }
4570
+ /**
4571
+ * Gets all registered component types (both lazy and eager).
4572
+ * Useful for debugging and validation.
4573
+ *
4574
+ * @returns Array of all registered component types
4575
+ */
4576
+ getAllComponentTypes() {
4577
+ return Array.from(this.componentRegistry.keys());
4578
+ }
4579
+ }
4580
+
4581
+ /**
4582
+ * Cross-runtime singleton storage for SDK-owned registries.
4583
+ *
4584
+ * Why globalThis: a module-scoped `let instance` only exists within whichever
4585
+ * module-graph evaluates the file. Next.js maintains two graphs (RSC server +
4586
+ * client); Webpack/Turbopack treat them as independent realms. A registry
4587
+ * populated in one graph is invisible to the other. Prod build workers don't
4588
+ * share JS heap either — each worker has its own module-scoped state.
4589
+ *
4590
+ * globalThis is uniformly available across Node, browser, Edge runtime,
4591
+ * Cloudflare/Vercel workers, Deno, Bun, and Web Workers, and is shared by RSC
4592
+ * + client graphs within a single process. Storing SDK runtime singletons here
4593
+ * makes them visible to every consumer regardless of bundler or graph.
4594
+ *
4595
+ * The key is versioned (`_v1`) so future shape changes can land under `_v2`
4596
+ * without colliding with older SDK copies during a partial upgrade.
4597
+ */
4598
+ const GLOBAL_STORE_KEY = "__contentstack_studio_registry_v1";
4599
+ /**
4600
+ * Returns the SDK's versioned slot on globalThis, creating it on first call.
4601
+ * Always returns the same object reference within a single JS runtime.
4602
+ *
4603
+ * Type-erased on purpose: each registry singleton casts to its own type on
4604
+ * read/write so the public API of `studio-registry` stays free of cross-
4605
+ * package import dependencies (e.g. `BreakpointManager` lives in
4606
+ * `studio-client`).
4607
+ */
4608
+ function getGlobalStudioStore() {
4609
+ const g = globalThis;
4610
+ if (!g[GLOBAL_STORE_KEY]) {
4611
+ g[GLOBAL_STORE_KEY] = {
4612
+ componentRegistry: null,
4613
+ designRegistry: null,
4614
+ breakpointManager: null,
4615
+ };
4616
+ }
4617
+ return g[GLOBAL_STORE_KEY];
4618
+ }
4619
+ /**
4620
+ * Clears the entire store. For tests only. Production code should never call
4621
+ * this — it would orphan every existing reference to the previous instances.
4622
+ */
4623
+ function resetGlobalStudioStore() {
4624
+ const g = globalThis;
4625
+ delete g[GLOBAL_STORE_KEY];
4626
+ }
4627
+
4628
+ /**
4629
+ * Singleton ComponentRegistry, backed by a versioned slot on `globalThis`.
4630
+ *
4631
+ * The previous module-scoped `let instance` only existed within whichever
4632
+ * module-graph evaluated this file. Under Next.js's dual RSC/client graph or
4633
+ * across prod build workers, that meant two registries with no sharing —
4634
+ * `fetchCompositionData` (server) could see an empty registry while
4635
+ * `<StudioComponent>` (client) saw a populated one. See `common/global-store.ts`
4636
+ * for the full reasoning.
4637
+ *
4638
+ * After this change, all callers of `getComponentRegistryInstance()` resolve
4639
+ * to the same `ComponentRegistry` instance within a single JS runtime,
4640
+ * regardless of which graph or worker they were evaluated in.
4641
+ */
4642
+ function getComponentRegistryInstance() {
4643
+ const store = getGlobalStudioStore();
4644
+ if (!store.componentRegistry) {
4645
+ store.componentRegistry = new ComponentRegistry();
4646
+ }
4647
+ return store.componentRegistry;
4648
+ }
4649
+ /**
4650
+ * Resets the singleton instance.
4651
+ * Primarily useful for testing to ensure a clean state between tests.
4652
+ *
4653
+ * @example
4654
+ * ```typescript
4655
+ * import { resetComponentRegistryInstance } from '@contentstack/studio-registry';
4656
+ *
4657
+ * beforeEach(() => {
4658
+ * resetComponentRegistryInstance();
4659
+ * });
4660
+ * ```
4661
+ */
4662
+ function resetComponentRegistryInstance() {
4663
+ getGlobalStudioStore().componentRegistry = null;
4664
+ }
4665
+ /**
4666
+ * Checks if the singleton instance has been created.
4667
+ *
4668
+ * @returns true if the instance exists, false otherwise
4669
+ */
4670
+ function hasComponentRegistryInstance() {
4671
+ return getGlobalStudioStore().componentRegistry !== null;
4320
4672
  }
4321
4673
 
4322
4674
  const SIZE_TOKENS = {
@@ -5152,6 +5504,38 @@ class DesignRegistry {
5152
5504
  }
5153
5505
  }
5154
5506
 
5507
+ /**
5508
+ * Singleton DesignRegistry, backed by a versioned slot on `globalThis`.
5509
+ *
5510
+ * Previously, `studio-react/src/composable-studio/sdk.ts` did
5511
+ * `export const designRegistry = new DesignRegistry()` at module scope — which
5512
+ * means every separate module-graph (RSC vs client, build workers) got its own
5513
+ * `DesignRegistry`. Design tokens registered on one side were invisible to the
5514
+ * other. See `common/global-store.ts` for the dual-graph background.
5515
+ *
5516
+ * After this change, all callers of `getDesignRegistryInstance()` resolve to
5517
+ * the same `DesignRegistry` within a single JS runtime.
5518
+ */
5519
+ function getDesignRegistryInstance() {
5520
+ const store = getGlobalStudioStore();
5521
+ if (!store.designRegistry) {
5522
+ store.designRegistry = new DesignRegistry();
5523
+ }
5524
+ return store.designRegistry;
5525
+ }
5526
+ /**
5527
+ * Resets the singleton instance. For tests only.
5528
+ */
5529
+ function resetDesignRegistryInstance() {
5530
+ getGlobalStudioStore().designRegistry = null;
5531
+ }
5532
+ /**
5533
+ * Checks if the singleton instance has been created.
5534
+ */
5535
+ function hasDesignRegistryInstance() {
5536
+ return getGlobalStudioStore().designRegistry !== null;
5537
+ }
5538
+
5155
5539
  class JSONRTERegistry {
5156
5540
  config;
5157
5541
  constructor(config) {
@@ -5198,14 +5582,6 @@ const getCslpTag = ({ bindedField, data, }) => {
5198
5582
  return cslpValue || {};
5199
5583
  };
5200
5584
 
5201
- const dataSourceCapabilities = {
5202
- [DATA_SOURCES.CONTENTSTACK]: { supportsCslp: true },
5203
- [DATA_SOURCES.COMPONENT_PROPS]: { supportsCslp: true },
5204
- [DATA_SOURCES.TEMPLATE]: { supportsCslp: true },
5205
- [DATA_SOURCES.REPEATER]: { supportsCslp: true },
5206
- [DATA_SOURCES.QUERY]: { supportsCslp: true }, // Verified: Query supports CSLP now
5207
- };
5208
-
5209
5585
  /**
5210
5586
  * This transforms the provided data into the format defined by the schema.
5211
5587
  *
@@ -5305,24 +5681,6 @@ function removeCurrentBindingKey(entry, bindingMap, currentBindingKey) {
5305
5681
  return [key, newValue];
5306
5682
  }
5307
5683
 
5308
- class DataSourceStrategyRegistry {
5309
- static instance;
5310
- strategies = new Map();
5311
- constructor() { }
5312
- static getInstance() {
5313
- if (!DataSourceStrategyRegistry.instance) {
5314
- DataSourceStrategyRegistry.instance = new DataSourceStrategyRegistry();
5315
- }
5316
- return DataSourceStrategyRegistry.instance;
5317
- }
5318
- register(type, strategy) {
5319
- this.strategies.set(type, strategy);
5320
- }
5321
- get(type) {
5322
- return this.strategies.get(type);
5323
- }
5324
- }
5325
-
5326
5684
  /**
5327
5685
  * Extracts the binding path string from a Contentstack-like binding object.
5328
5686
  * Flattens nested path objects into a dot-notation string.
@@ -5391,6 +5749,24 @@ const getTemplateBindingString = (binding) => {
5391
5749
  .join(".");
5392
5750
  };
5393
5751
 
5752
+ class DataSourceStrategyRegistry {
5753
+ static instance;
5754
+ strategies = new Map();
5755
+ constructor() { }
5756
+ static getInstance() {
5757
+ if (!DataSourceStrategyRegistry.instance) {
5758
+ DataSourceStrategyRegistry.instance = new DataSourceStrategyRegistry();
5759
+ }
5760
+ return DataSourceStrategyRegistry.instance;
5761
+ }
5762
+ register(type, strategy) {
5763
+ this.strategies.set(type, strategy);
5764
+ }
5765
+ get(type) {
5766
+ return this.strategies.get(type);
5767
+ }
5768
+ }
5769
+
5394
5770
  /**
5395
5771
  * Retrieves the default static value for a given property type.
5396
5772
  *
@@ -5511,6 +5887,20 @@ const getFlattenedData = (data) => {
5511
5887
  }
5512
5888
  return data;
5513
5889
  };
5890
+ /**
5891
+ * Composition/static data often stores single-select choice as `string[]` (one element).
5892
+ * `isDataMatchingPropType` treats `choice` as a `string` or `string[]` (multi-select);
5893
+ * single-select stored as `string[]` must still be unwrapped here before the type-mismatch fallback.
5894
+ */
5895
+ function normalizeSingleSelectChoiceValue(resolvedData, prop) {
5896
+ if (prop.type !== "choice" || ("multiSelect" in prop && prop.multiSelect)) {
5897
+ return resolvedData;
5898
+ }
5899
+ if (Array.isArray(resolvedData)) {
5900
+ return resolvedData[0];
5901
+ }
5902
+ return resolvedData;
5903
+ }
5514
5904
  const resolveMetadataBindings = (node, data) => {
5515
5905
  if (!node.metadata?.bindings)
5516
5906
  return;
@@ -5533,13 +5923,18 @@ const getRepeaterContextPath = (binding) => {
5533
5923
  };
5534
5924
  function isDataMatchingPropType(data, type) {
5535
5925
  const dataType = getDataType(data);
5926
+ if (type === "choice") {
5927
+ return (dataType === "string" ||
5928
+ (dataType === "array" &&
5929
+ Array.isArray(data) &&
5930
+ data.every((item) => typeof item === "string")));
5931
+ }
5536
5932
  const map = {
5537
5933
  string: dataType === "string" || dataType === "number" || dataType === "boolean",
5538
5934
  boolean: dataType === "boolean",
5539
5935
  number: dataType === "number",
5540
5936
  object: dataType === "object",
5541
5937
  array: dataType === "array",
5542
- choice: dataType === "string",
5543
5938
  href: dataType === "string",
5544
5939
  imageurl: dataType === "string",
5545
5940
  datestring: dataType === "string",
@@ -5557,6 +5952,14 @@ function getDataType(data) {
5557
5952
  return typeof data;
5558
5953
  }
5559
5954
 
5955
+ const dataSourceCapabilities = {
5956
+ [DATA_SOURCES.CONTENTSTACK]: { supportsCslp: true },
5957
+ [DATA_SOURCES.COMPONENT_PROPS]: { supportsCslp: true },
5958
+ [DATA_SOURCES.TEMPLATE]: { supportsCslp: true },
5959
+ [DATA_SOURCES.REPEATER]: { supportsCslp: true },
5960
+ [DATA_SOURCES.QUERY]: { supportsCslp: true }, // Verified: Query supports CSLP now
5961
+ };
5962
+
5560
5963
  // Responsible for resolving props to values
5561
5964
  function retrievePropValue(args) {
5562
5965
  const { data, componentOptions, node, cslp, placeholders = {}, getSlots, jsonRTE, isCompositionBeingEdited, } = args;
@@ -5595,6 +5998,18 @@ function retrievePropValue(args) {
5595
5998
  mappedData[field] = resolvedData;
5596
5999
  return;
5597
6000
  }
6001
+ // Section exposed-prop override: the page composer's exposed-prop binding is
6002
+ // the SOLE source of truth for an exposed field — the internal node's own
6003
+ // binding must never leak through on a page. SectionCompositionProvider emits
6004
+ // an entry for EVERY exposed prop (even when the page value is cleared/empty),
6005
+ // so we apply on key PRESENCE, not on a non-undefined value. A cleared prop
6006
+ // therefore renders the page-resolved empty value instead of falling back to
6007
+ // the section's authored binding.
6008
+ const overridesForNode = data.dataSources?.section_exposed_overrides?.[node.uid];
6009
+ if (overridesForNode && field in overridesForNode) {
6010
+ mappedData[field] = overridesForNode[field];
6011
+ return;
6012
+ }
5598
6013
  const nodePropConfig = nodeProps[field];
5599
6014
  const { binding: bindedField, value: staticValue } = nodePropConfig || {};
5600
6015
  //TODO: Get proper data for design
@@ -5651,8 +6066,41 @@ function retrievePropValue(args) {
5651
6066
  }
5652
6067
  }
5653
6068
  }
5654
- else if (dataPath) {
6069
+ else if (dataPath &&
6070
+ !(type === "choice" && bindedField?.type === "static_value")) {
5655
6071
  resolvedData = get(data, dataPath, fallbackValue);
6072
+ // TEMP — slot-child page-context fallback (PHASE 8 will remove this).
6073
+ //
6074
+ // Section-slot wraps its children's data context so that:
6075
+ // dataSources.template / .contentstack / .contentstack_queries / .repeater
6076
+ // ALL refer to the section's LOCAL surrounding context — matching what
6077
+ // the Data Picker currently writes when authoring a slot child against
6078
+ // section-local fields.
6079
+ //
6080
+ // The page's outer entries live at `dataSources.page.template`, etc., as
6081
+ // the explicit escape namespace. But until the Picker is slot-aware
6082
+ // (Phase 8), it has no way to write `dataSources.page.X` paths — so a
6083
+ // page-level binding authored on a slot child still produces a
6084
+ // `dataSources.<source>.X` path that targets the section-local view and
6085
+ // resolves to undefined.
6086
+ //
6087
+ // Bridge: if the local resolution is missing AND a `page` sibling
6088
+ // namespace exists on dataSources, retry under `dataSources.page.X`. Remove
6089
+ // this fallback when the Picker emits explicit `dataSources.page.X`
6090
+ // paths.
6091
+ if ((resolvedData === undefined ||
6092
+ resolvedData === null ||
6093
+ resolvedData === fallbackValue) &&
6094
+ typeof dataPath === "string" &&
6095
+ dataPath.startsWith("dataSources.") &&
6096
+ !dataPath.startsWith("dataSources.page.") &&
6097
+ data?.dataSources?.page) {
6098
+ const pagePath = dataPath.replace(/^dataSources\./, "dataSources.page.");
6099
+ const pageResolved = get(data, pagePath, undefined);
6100
+ if (pageResolved !== undefined && pageResolved !== null) {
6101
+ resolvedData = pageResolved;
6102
+ }
6103
+ }
5656
6104
  // Handle primitive values in repeater context
5657
6105
  // When the array contains primitives (strings, numbers, etc.) instead of objects,
5658
6106
  // the binding path will be like: dataSources.repeater.{uid}.context.{fieldName}
@@ -5681,6 +6129,7 @@ function retrievePropValue(args) {
5681
6129
  // Skip if we already handled the repeater context case above.
5682
6130
  if (type !== "object" && type !== "array" && !handledRepeaterContext) {
5683
6131
  resolvedData = getFlattenedData(resolvedData);
6132
+ resolvedData = normalizeSingleSelectChoiceValue(resolvedData, prop);
5684
6133
  // Fallback to static value if the resolved data is still not matching the expected primitive type
5685
6134
  // This ensures that if a binding returns an object (e.g. during a structural change), we don't crash React
5686
6135
  // and instead show the static value entered by the user.
@@ -5702,25 +6151,44 @@ function retrievePropValue(args) {
5702
6151
  }
5703
6152
  }
5704
6153
  }
5705
- if (type === "choice") {
5706
- if (!prop.multiSelect) {
5707
- // we are explicitly checking for single select choice type to ensure we don't have a mismatch in the data type.
5708
- if (Array.isArray(resolvedData)) {
5709
- resolvedData = resolvedData[0];
5710
- }
5711
- }
6154
+ // Normalize data type: convert arrays to single values for single-select props
6155
+ if (type === "choice" &&
6156
+ !prop.multiSelect &&
6157
+ Array.isArray(resolvedData)) {
6158
+ // Single-select props (choice, etc.) should receive single values, not arrays
6159
+ resolvedData = resolvedData[0];
5712
6160
  }
5713
6161
  }
5714
6162
  else {
5715
- resolvedData = staticValue !== undefined ? staticValue : fallbackValue;
5716
- // TODO: THIS IS A TEMPORARY FIX TO HANDLE THE CASE WHERE THE DATA TYPE IS NOT MATCHING THE PROP TYPE. WE WILL REMOVE THIS ELSE BLOCK.
5717
- if (type === "choice") {
5718
- if (!prop.multiSelect) {
5719
- // we are explicitly checking for single select choice type to ensure we don't have a mismatch in the data type.
5720
- if (Array.isArray(resolvedData)) {
5721
- resolvedData = resolvedData[0];
6163
+ // For choice props, explicitly retrieve saved values from static content store
6164
+ if (type === "choice" && bindedField?.type === "static_value") {
6165
+ const staticContentKey = bindedField.value; // e.g., "B575hDbLkWhPSfB-alignment"
6166
+ // Try to find the saved value in the static content store
6167
+ let savedValue = undefined;
6168
+ // Check if we have access to the static_value from data
6169
+ if (data.static_value && typeof data.static_value === "object") {
6170
+ // Look for the value directly by key
6171
+ if (typeof staticContentKey === "string") {
6172
+ savedValue = data.static_value[staticContentKey];
5722
6173
  }
5723
6174
  }
6175
+ if (savedValue !== undefined) {
6176
+ resolvedData = savedValue;
6177
+ }
6178
+ else {
6179
+ resolvedData =
6180
+ staticValue !== undefined ? staticValue : fallbackValue;
6181
+ }
6182
+ }
6183
+ else {
6184
+ resolvedData = staticValue !== undefined ? staticValue : fallbackValue;
6185
+ }
6186
+ // Normalize data type: convert arrays to single values for single-select props
6187
+ if (type === "choice" &&
6188
+ !prop.multiSelect &&
6189
+ Array.isArray(resolvedData)) {
6190
+ // Single-select props (choice, etc.) should receive single values, not arrays
6191
+ resolvedData = resolvedData[0];
5724
6192
  }
5725
6193
  }
5726
6194
  // TODO: @ravencolevol: In case of the missing string value, we are providing a placeholder component, failing this check. We have to revisit the placeholder component logic.
@@ -5772,6 +6240,11 @@ function retrievePropValue(args) {
5772
6240
  mappedData["_uid"] = node.uid;
5773
6241
  mappedData["mode"] = node?.metadata?.mode;
5774
6242
  }
6243
+ if (node.type === "section-slot") {
6244
+ // Section-slot needs its own node uid at render time so it can look up
6245
+ // the page-side fill in SectionInstanceSlotsCtx.slotsMap[node.uid].
6246
+ mappedData["_uid"] = node.uid;
6247
+ }
5775
6248
  if (node.type === "condition-block") {
5776
6249
  mappedData["condition"] = node?.metadata?.condition;
5777
6250
  mappedData["mode"] = node?.metadata?.mode;
@@ -5876,20 +6349,30 @@ exports.STYLE_SECTION_CATEGORIES = STYLE_SECTION_CATEGORIES;
5876
6349
  exports.SYSTEM_COMPONENTS = SYSTEM_COMPONENTS;
5877
6350
  exports.convertBindingPath = convertBindingPath;
5878
6351
  exports.getBindingString = getBindingString;
6352
+ exports.getComponentRegistryInstance = getComponentRegistryInstance;
5879
6353
  exports.getCslpPath = getCslpPath;
5880
6354
  exports.getCslpTag = getCslpTag;
5881
6355
  exports.getDataType = getDataType;
5882
6356
  exports.getDefaultPropStaticValue = getDefaultPropStaticValue;
5883
6357
  exports.getDesignClassesNames = getDesignClassesNames;
6358
+ exports.getDesignRegistryInstance = getDesignRegistryInstance;
5884
6359
  exports.getFlattenedData = getFlattenedData;
6360
+ exports.getGlobalStudioStore = getGlobalStudioStore;
5885
6361
  exports.getPlaceHolderComponent = getPlaceHolderComponent;
5886
6362
  exports.getRepeaterBinding = getRepeaterBinding;
5887
6363
  exports.getRepeaterContextPath = getRepeaterContextPath;
6364
+ exports.getSectionUIDFromNode = getSectionUIDFromNode;
5888
6365
  exports.getSlotData = getSlotData;
5889
6366
  exports.getSymbolUIDFromNode = getSymbolUIDFromNode;
5890
6367
  exports.getSymbolUIDFromUID = getSymbolUIDFromUID;
6368
+ exports.hasComponentRegistryInstance = hasComponentRegistryInstance;
6369
+ exports.hasDesignRegistryInstance = hasDesignRegistryInstance;
5891
6370
  exports.isDataMatchingPropType = isDataMatchingPropType;
5892
6371
  exports.isKnownType = isKnownType;
6372
+ exports.normalizeSingleSelectChoiceValue = normalizeSingleSelectChoiceValue;
6373
+ exports.resetComponentRegistryInstance = resetComponentRegistryInstance;
6374
+ exports.resetDesignRegistryInstance = resetDesignRegistryInstance;
6375
+ exports.resetGlobalStudioStore = resetGlobalStudioStore;
5893
6376
  exports.resolveMetadataBindings = resolveMetadataBindings;
5894
6377
  exports.retrievePropValue = retrievePropValue;
5895
6378
  //# sourceMappingURL=index.cjs.map