@contentstack/studio-registry 1.3.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.
Files changed (40) hide show
  1. package/dist/cjs/index.cjs +722 -89
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/esm/common/global-store.js +49 -0
  4. package/dist/esm/common/global-store.js.map +1 -0
  5. package/dist/esm/component-registry/registry-options-processor.js +27 -0
  6. package/dist/esm/component-registry/registry-options-processor.js.map +1 -1
  7. package/dist/esm/component-registry/registry.constant.js +8 -0
  8. package/dist/esm/component-registry/registry.constant.js.map +1 -1
  9. package/dist/esm/component-registry/registry.js +224 -9
  10. package/dist/esm/component-registry/registry.js.map +1 -1
  11. package/dist/esm/component-registry/singleton.js +51 -0
  12. package/dist/esm/component-registry/singleton.js.map +1 -0
  13. package/dist/esm/data-binder/cslp.js +4 -1
  14. package/dist/esm/data-binder/cslp.js.map +1 -1
  15. package/dist/esm/data-binder/retrieve-data.js +156 -30
  16. package/dist/esm/data-binder/retrieve-data.js.map +1 -1
  17. package/dist/esm/data-binder/retrieve-data.util.js +70 -52
  18. package/dist/esm/data-binder/retrieve-data.util.js.map +1 -1
  19. package/dist/esm/data-binder/strategies/contentstack.js +19 -0
  20. package/dist/esm/data-binder/strategies/contentstack.js.map +1 -0
  21. package/dist/esm/data-binder/strategies/dataSourceCapabilities.js +12 -0
  22. package/dist/esm/data-binder/strategies/dataSourceCapabilities.js.map +1 -0
  23. package/dist/esm/data-binder/strategies/query.js +17 -0
  24. package/dist/esm/data-binder/strategies/query.js.map +1 -0
  25. package/dist/esm/data-binder/strategies/repeater.js +18 -0
  26. package/dist/esm/data-binder/strategies/repeater.js.map +1 -0
  27. package/dist/esm/data-binder/strategies/template.js +16 -0
  28. package/dist/esm/data-binder/strategies/template.js.map +1 -0
  29. package/dist/esm/data-binder/strategies/utils.js +20 -0
  30. package/dist/esm/data-binder/strategies/utils.js.map +1 -0
  31. package/dist/esm/data-binder/strategy-registry.js +20 -0
  32. package/dist/esm/data-binder/strategy-registry.js.map +1 -0
  33. package/dist/esm/design-registry/singleton.js +37 -0
  34. package/dist/esm/design-registry/singleton.js.map +1 -0
  35. package/dist/esm/index.d.ts +236 -6
  36. package/dist/esm/index.js +5 -1
  37. package/dist/esm/index.js.map +1 -1
  38. package/dist/esm/utils/sections.js +13 -0
  39. package/dist/esm/utils/sections.js.map +1 -0
  40. package/package.json +9 -9
@@ -64,6 +64,7 @@ const DATA_SOURCES = {
64
64
  TEMPLATE: "template",
65
65
  CONTENTSTACK: "contentstack",
66
66
  REPEATER: "repeater",
67
+ QUERY: "contentstack_queries",
67
68
  SYMBOL_PROPS: "symbol_props",
68
69
  };
69
70
  const INTERNAL_COMPONENT_SECTIONS = {
@@ -75,6 +76,7 @@ const INTERNAL_COMPONENT_SECTIONS = {
75
76
  REGISTERED_COMPONENTS: "Registered Components",
76
77
  HTML_ELEMENT: "HTML Elements",
77
78
  SYMBOL: "Symbols",
79
+ SECTION_COMPOSITION: "Sections",
78
80
  };
79
81
  const INTERNAL_SECTIONS = Object.values(INTERNAL_COMPONENT_SECTIONS);
80
82
  const STYLE_SECTIONS_OPTIONS = [
@@ -124,6 +126,7 @@ const INTERNAL_COMPONENTS_NAMES = {
124
126
  LINK: "link",
125
127
  LINK_CONTAINER: "link-container",
126
128
  TEXT: "text",
129
+ NUMBER: "number",
127
130
  BUTTON: "button",
128
131
  JSON_RTE: "json-rte",
129
132
  COLLAPSIBLE_TEXT: "collapsible-text",
@@ -141,6 +144,10 @@ const INTERNAL_COMPONENTS_NAMES = {
141
144
  CONDITION_BLOCK: "condition-block",
142
145
  SYMBOL: "symbol",
143
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",
144
151
  // * HTML Elements
145
152
  HTML_ELEMENT: "html-element",
146
153
  STYLE_SHEET: "style-sheet",
@@ -160,6 +167,7 @@ const BUILT_IN_COMPONENTS = {
160
167
  LINK: "link",
161
168
  LINK_CONTAINER: "link-container",
162
169
  TEXT: "text",
170
+ NUMBER: "number",
163
171
  BUTTON: "button",
164
172
  JSON_RTE: "json-rte",
165
173
  COLLAPSIBLE_TEXT: "collapsible-text",
@@ -182,6 +190,17 @@ const getSymbolUIDFromUID = (uid) => {
182
190
  return `${INTERNAL_COMPONENTS_NAMES.SYMBOL}-${uid}`;
183
191
  };
184
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
+
185
204
  /** Detect free variable `global` from Node.js. */
186
205
  var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
187
206
 
@@ -4033,6 +4052,7 @@ function processRegistryOptionsProps(props) {
4033
4052
  delete processedProps[field].validate;
4034
4053
  }
4035
4054
  }
4055
+ validateSlotCountPropLinkages(props, processedProps);
4036
4056
  return { props: processedProps, validators: propValidators };
4037
4057
  }
4038
4058
  function getExpandedPropTypes(prop) {
@@ -4049,6 +4069,32 @@ function getExpandedPropTypes(prop) {
4049
4069
  };
4050
4070
  return propTypeMapping[prop];
4051
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
+ }
4052
4098
  function getBlockStyleSections() {
4053
4099
  return STYLE_SECTION_CATEGORIES.block;
4054
4100
  }
@@ -4069,6 +4115,10 @@ class ComponentRegistry {
4069
4115
  componentRegistry = new Map();
4070
4116
  propValidatorRegistry = new Map();
4071
4117
  config;
4118
+ // Lazy loading infrastructure
4119
+ componentLoaders = new Map();
4120
+ loadedComponents = new Set();
4121
+ loadingPromises = new Map();
4072
4122
  constructor(config) {
4073
4123
  // TODO process options
4074
4124
  this.config = config || getDefaultComponentRegistryOptions();
@@ -4078,6 +4128,9 @@ class ComponentRegistry {
4078
4128
  this.getComponents = this.getComponents.bind(this);
4079
4129
  this.getComponent = this.getComponent.bind(this);
4080
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);
4081
4134
  }
4082
4135
  setConfig(config = {}) {
4083
4136
  if (config.allowedBuiltInComponents !== undefined) {
@@ -4122,9 +4175,14 @@ class ComponentRegistry {
4122
4175
  const { type: name } = componentConfig;
4123
4176
  this.componentRegistry.set(name, componentConfig);
4124
4177
  });
4125
- // sync unregistered components
4178
+ // sync unregistered components (never remove system / built-in entries)
4126
4179
  this.componentRegistry.forEach((componentConfig) => {
4127
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
+ }
4128
4186
  this.unregisterComponent(componentConfig.type);
4129
4187
  }
4130
4188
  });
@@ -4196,23 +4254,64 @@ class ComponentRegistry {
4196
4254
  this.componentRegistry.set(type, processedOptions);
4197
4255
  });
4198
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
+ }
4199
4270
  /**
4200
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
+ *
4201
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.
4202
4296
  */
4203
- registerComponents(components) {
4297
+ registerComponents(components, options) {
4204
4298
  components.forEach((componentOption) => {
4205
4299
  const { type } = componentOption;
4206
4300
  if (!type) {
4207
4301
  throw new Error("Component type is required.");
4208
4302
  }
4209
- if (this.componentRegistry.has(type) &&
4210
- !this.config.overrideDefaultComponents) {
4211
- throw new Error(`Component with type '${type}' is already registered.`);
4212
- }
4213
4303
  if (SYSTEM_COMPONENTS.has(type)) {
4214
4304
  throw new Error(`Component with type '${type}' is a system component and cannot be overridden.`);
4215
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
+ }
4216
4315
  const { processedOptions, propValidators } = processRegistryOptions(componentOption, {
4217
4316
  registry: "user-defined",
4218
4317
  });
@@ -4247,7 +4346,24 @@ class ComponentRegistry {
4247
4346
  if (!this.componentRegistry.has(name)) {
4248
4347
  throw new Error(`Component with type '${name}' is not registered.`);
4249
4348
  }
4250
- 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;
4251
4367
  }
4252
4368
  /**
4253
4369
  * Retrieves a component from the component registry by its name.
@@ -4273,11 +4389,9 @@ class ComponentRegistry {
4273
4389
  unregisterComponent(node) {
4274
4390
  const name = typeof node === "string" ? node : this.getComponentName(node);
4275
4391
  if (!this.componentRegistry.has(name)) {
4276
- console.error(`Component with type '${name}' is not registered.`);
4277
4392
  return;
4278
4393
  }
4279
4394
  if (SYSTEM_COMPONENTS.has(name)) {
4280
- console.error(`Component with type '${name}' is a system component and cannot be unregistered.`);
4281
4395
  return;
4282
4396
  }
4283
4397
  this.componentRegistry.delete(name);
@@ -4314,8 +4428,247 @@ class ComponentRegistry {
4314
4428
  }
4315
4429
  return getSymbolUIDFromNode(node);
4316
4430
  }
4431
+ if (type === "section-composition") {
4432
+ const resolvedName = getSectionUIDFromNode(node) || type;
4433
+ return resolvedName;
4434
+ }
4317
4435
  return type;
4318
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;
4319
4672
  }
4320
4673
 
4321
4674
  const SIZE_TOKENS = {
@@ -5151,6 +5504,38 @@ class DesignRegistry {
5151
5504
  }
5152
5505
  }
5153
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
+
5154
5539
  class JSONRTERegistry {
5155
5540
  config;
5156
5541
  constructor(config) {
@@ -5173,6 +5558,9 @@ class JSONRTERegistry {
5173
5558
  * @returns The path of the CSLP path.
5174
5559
  */
5175
5560
  function getCslpPath(binding) {
5561
+ if (typeof binding !== "string") {
5562
+ return "";
5563
+ }
5176
5564
  const bindingParts = binding.split(".");
5177
5565
  const lastPart = bindingParts.pop();
5178
5566
  const cslpPath = bindingParts.join(".") + ".$." + lastPart;
@@ -5293,6 +5681,92 @@ function removeCurrentBindingKey(entry, bindingMap, currentBindingKey) {
5293
5681
  return [key, newValue];
5294
5682
  }
5295
5683
 
5684
+ /**
5685
+ * Extracts the binding path string from a Contentstack-like binding object.
5686
+ * Flattens nested path objects into a dot-notation string.
5687
+ */
5688
+ const getBindingStringForCS = (binding) => {
5689
+ //TODO: fix this types and data source uid
5690
+ const path = binding.value.path;
5691
+ const flattenPath = (path) => {
5692
+ if (!path || Object.keys(path).length === 0)
5693
+ return "";
5694
+ const key = Object.keys(path)[0];
5695
+ const value = path[key];
5696
+ const flattenValue = flattenPath(value);
5697
+ return flattenValue ? `${key}.${flattenValue}` : key;
5698
+ };
5699
+ return flattenPath(path);
5700
+ };
5701
+
5702
+ const getContentstackBindingString = (binding) => {
5703
+ // STORED AT dataSources.contentstack.ct_uid:euid.<bindingString>
5704
+ const { _content_type_uid, uid } = binding.value;
5705
+ const entryKey = `${_content_type_uid}:${uid}`;
5706
+ return [
5707
+ DATA_SOURCES_PREFIX,
5708
+ DATA_SOURCES.CONTENTSTACK,
5709
+ entryKey,
5710
+ getBindingStringForCS(binding),
5711
+ ]
5712
+ .filter(Boolean)
5713
+ .join(".");
5714
+ };
5715
+
5716
+ const getQueryBindingString = (binding) => {
5717
+ // STORED AT dataSources.query.<queryUID>.<bindingString>
5718
+ // Binding value structure: { queryUID: string, path: CSBindingPath }
5719
+ const { queryUID } = binding.value;
5720
+ const suffix = getBindingStringForCS(binding);
5721
+ // Keep the full path including "data" and "count" - the schema structure is the source of truth
5722
+ const finalPath = [DATA_SOURCES_PREFIX, DATA_SOURCES.QUERY, queryUID, suffix]
5723
+ .filter(Boolean)
5724
+ .join(".");
5725
+ return finalPath;
5726
+ };
5727
+
5728
+ const getRepeaterBindingString = (binding) => {
5729
+ const { repeaterUID } = binding.value;
5730
+ return [
5731
+ DATA_SOURCES_PREFIX,
5732
+ DATA_SOURCES.REPEATER,
5733
+ repeaterUID,
5734
+ "context",
5735
+ getBindingStringForCS(binding),
5736
+ ]
5737
+ .filter(Boolean)
5738
+ .join(".");
5739
+ };
5740
+
5741
+ const getTemplateBindingString = (binding) => {
5742
+ // STORED AT dataSources.template.<bindingString>
5743
+ return [
5744
+ DATA_SOURCES_PREFIX,
5745
+ DATA_SOURCES.TEMPLATE,
5746
+ getBindingStringForCS(binding),
5747
+ ]
5748
+ .filter(Boolean)
5749
+ .join(".");
5750
+ };
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
+
5296
5770
  /**
5297
5771
  * Retrieves the default static value for a given property type.
5298
5772
  *
@@ -5365,60 +5839,68 @@ function getPlaceHolderComponent(placeholders, prop, type) {
5365
5839
  : getDefaultPropStaticValue(type);
5366
5840
  return placeholderComponent;
5367
5841
  }
5368
- const getBindingStringForCS = (binding) => {
5369
- //TODO: fix this types and data source uid
5370
- const path = binding.value.path;
5371
- const flattenPath = (path) => {
5372
- if (Object.keys(path).length === 0)
5373
- return "";
5374
- const key = Object.keys(path)[0];
5375
- const value = path[key];
5376
- const flattenValue = flattenPath(value);
5377
- return flattenValue ? `${key}.${flattenValue}` : key;
5378
- };
5379
- return flattenPath(path);
5380
- };
5842
+ // Register default strategies (Side-effect initialization)
5843
+ const registry = DataSourceStrategyRegistry.getInstance();
5844
+ registry.register(DATA_SOURCES.CONTENTSTACK, {
5845
+ getBindingString: (binding) => getContentstackBindingString(binding),
5846
+ });
5847
+ registry.register(DATA_SOURCES.TEMPLATE, {
5848
+ getBindingString: (binding) => getTemplateBindingString(binding),
5849
+ });
5850
+ registry.register(DATA_SOURCES.QUERY, {
5851
+ getBindingString: (binding) => getQueryBindingString(binding),
5852
+ convertPath: (path) => path.split("."),
5853
+ });
5854
+ registry.register(DATA_SOURCES.REPEATER, {
5855
+ getBindingString: (binding) => getRepeaterBindingString(binding),
5856
+ });
5857
+ registry.register(DATA_SOURCES.COMPONENT_PROPS, {
5858
+ getBindingString: (binding) => [DATA_SOURCES.COMPONENT_PROPS, binding.value].filter(Boolean).join("."),
5859
+ });
5860
+ registry.register(DATA_SOURCES.STATIC_VALUE, {
5861
+ getBindingString: (binding) => [DATA_SOURCES.STATIC_VALUE, binding.value].filter(Boolean).join("."),
5862
+ });
5863
+ registry.register(DATA_SOURCES.SYMBOL_PROPS, {
5864
+ getBindingString: (binding) => [DATA_SOURCES.SYMBOL_PROPS, binding.value].filter(Boolean).join("."),
5865
+ });
5381
5866
  const getBindingString = (binding) => {
5382
- if (binding.type === DATA_SOURCES.TEMPLATE) {
5383
- // STORED AT dataSources.template.<bindingString>
5384
- return [
5385
- DATA_SOURCES_PREFIX,
5386
- DATA_SOURCES.TEMPLATE,
5387
- getBindingStringForCS(binding),
5388
- ].join(".");
5389
- }
5390
- if (binding.type === DATA_SOURCES.CONTENTSTACK) {
5391
- // STORED AT dataSources.contentstack.ct_uid:euid.<bindingString>
5392
- const { _content_type_uid, uid } = binding.value;
5393
- const entryKey = `${_content_type_uid}:${uid}`;
5394
- return [
5395
- DATA_SOURCES_PREFIX,
5396
- DATA_SOURCES.CONTENTSTACK,
5397
- entryKey,
5398
- getBindingStringForCS(binding),
5399
- ].join(".");
5400
- }
5401
- if (binding.type === DATA_SOURCES.REPEATER) {
5402
- const { repeaterUID } = binding.value;
5403
- return [
5404
- DATA_SOURCES_PREFIX,
5405
- DATA_SOURCES.REPEATER,
5406
- repeaterUID,
5407
- "context",
5408
- getBindingStringForCS(binding),
5409
- ].join(".");
5410
- }
5411
- if (binding.type === DATA_SOURCES.COMPONENT_PROPS) {
5412
- return [DATA_SOURCES.COMPONENT_PROPS, binding.value].join(".");
5413
- }
5414
- if (binding.type === DATA_SOURCES.STATIC_VALUE) {
5415
- return [DATA_SOURCES.STATIC_VALUE, binding.value].join(".");
5416
- }
5417
- if (binding.type === DATA_SOURCES.SYMBOL_PROPS) {
5418
- return [DATA_SOURCES.SYMBOL_PROPS, binding.value].join(".");
5867
+ const strategy = DataSourceStrategyRegistry.getInstance().get(binding.type);
5868
+ if (strategy) {
5869
+ return strategy.getBindingString(binding);
5419
5870
  }
5871
+ // Fallback for simple string bindings
5420
5872
  return binding.value;
5421
5873
  };
5874
+ const convertBindingPath = (bindingType, path) => {
5875
+ const strategy = DataSourceStrategyRegistry.getInstance().get(bindingType);
5876
+ if (strategy && strategy.convertPath) {
5877
+ return strategy.convertPath(path);
5878
+ }
5879
+ return path;
5880
+ };
5881
+ const getFlattenedData = (data) => {
5882
+ if (data && typeof data === "object" && !Array.isArray(data)) {
5883
+ const keys = Object.keys(data).filter((key) => key !== "$" && key !== "_metadata");
5884
+ if (keys.length === 1) {
5885
+ return getFlattenedData(data[keys[0]]);
5886
+ }
5887
+ }
5888
+ return data;
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
+ }
5422
5904
  const resolveMetadataBindings = (node, data) => {
5423
5905
  if (!node.metadata?.bindings)
5424
5906
  return;
@@ -5441,13 +5923,18 @@ const getRepeaterContextPath = (binding) => {
5441
5923
  };
5442
5924
  function isDataMatchingPropType(data, type) {
5443
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
+ }
5444
5932
  const map = {
5445
- string: dataType === "string",
5933
+ string: dataType === "string" || dataType === "number" || dataType === "boolean",
5446
5934
  boolean: dataType === "boolean",
5447
5935
  number: dataType === "number",
5448
5936
  object: dataType === "object",
5449
5937
  array: dataType === "array",
5450
- choice: dataType === "string",
5451
5938
  href: dataType === "string",
5452
5939
  imageurl: dataType === "string",
5453
5940
  datestring: dataType === "string",
@@ -5465,6 +5952,14 @@ function getDataType(data) {
5465
5952
  return typeof data;
5466
5953
  }
5467
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
+
5468
5963
  // Responsible for resolving props to values
5469
5964
  function retrievePropValue(args) {
5470
5965
  const { data, componentOptions, node, cslp, placeholders = {}, getSlots, jsonRTE, isCompositionBeingEdited, } = args;
@@ -5503,14 +5998,47 @@ function retrievePropValue(args) {
5503
5998
  mappedData[field] = resolvedData;
5504
5999
  return;
5505
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
+ }
5506
6013
  const nodePropConfig = nodeProps[field];
5507
- const { binding: bindedField } = nodePropConfig || {};
6014
+ const { binding: bindedField, value: staticValue } = nodePropConfig || {};
5508
6015
  //TODO: Get proper data for design
5509
6016
  const placeholderComponent = getPlaceHolderComponent(placeholders, prop, type);
5510
- const fallbackValue = defaultValue ?? placeholderComponent;
6017
+ const fallbackValue = staticValue !== undefined
6018
+ ? staticValue
6019
+ : (defaultValue ?? placeholderComponent);
5511
6020
  const dataPath = bindedField && getBindingString(bindedField);
5512
6021
  if ((type === "array" || type === "object") && dataPath) {
5513
- const bindedData = get(data, dataPath);
6022
+ let pathForGet = dataPath;
6023
+ // Use strategy-based path conversion (Agnostic)
6024
+ if (bindedField?.type && typeof dataPath === "string") {
6025
+ pathForGet = convertBindingPath(bindedField.type, dataPath);
6026
+ }
6027
+ let bindedData = get(data, pathForGet);
6028
+ // Strictly handle QueryResult { entries: Entry[], count: number } structure.
6029
+ // If we're expecting an array and the bindedData matches the QueryResult pattern,
6030
+ // we extract the entries array.
6031
+ if (type === "array" &&
6032
+ bindedData &&
6033
+ typeof bindedData === "object" &&
6034
+ !Array.isArray(bindedData) &&
6035
+ "entries" in bindedData &&
6036
+ Array.isArray(bindedData.entries)) {
6037
+ bindedData = bindedData.entries;
6038
+ }
6039
+ // Note: If bindedData is a direct array [], it will fall through.
6040
+ // As per the requirement "expects {result: [], count: number} only and no direct []",
6041
+ // we are now enforcing the unwrapping for the expected object structure.
5514
6042
  const bindingMap = nodePropConfig.bindingMap;
5515
6043
  const isBindingMapEmpty = Object.keys(bindingMap || {}).length === 0;
5516
6044
  const transformedData = !isBindingMapEmpty
@@ -5518,21 +6046,67 @@ function retrievePropValue(args) {
5518
6046
  : bindedData;
5519
6047
  resolvedData = transformedData ?? fallbackValue;
5520
6048
  if (type === "array") {
5521
- const cslpObj = getCslpTag({ bindedField: dataPath, data });
5522
- if (cslpObj["data-cslp"]) {
5523
- mappedData[`$${field}Items`] = transformedData.map((_, idx) => {
5524
- return { "data-cslp": `${cslpObj["data-cslp"]}.$${idx}` };
5525
- });
6049
+ const isCSLPAbleType = bindedField?.type &&
6050
+ dataSourceCapabilities[bindedField.type]?.supportsCslp;
6051
+ if (cslp.appendTags &&
6052
+ isCSLPAbleType &&
6053
+ Array.isArray(transformedData)) {
6054
+ const cslpObj = getCslpTag({ bindedField: dataPath, data });
6055
+ if (cslpObj["data-cslp"]) {
6056
+ mappedData[`$${field}Items`] = transformedData.map((_, idx) => {
6057
+ return { "data-cslp": `${cslpObj["data-cslp"]}.$${idx}` };
6058
+ });
6059
+ }
6060
+ }
6061
+ if (isCompositionBeingEdited &&
6062
+ isCSLPAbleType &&
6063
+ Array.isArray(resolvedData) &&
6064
+ resolvedData.length === 0) {
6065
+ resolvedData = [{}];
5526
6066
  }
5527
6067
  }
5528
6068
  }
5529
- else if (dataPath) {
6069
+ else if (dataPath &&
6070
+ !(type === "choice" && bindedField?.type === "static_value")) {
5530
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
+ }
5531
6104
  // Handle primitive values in repeater context
5532
6105
  // When the array contains primitives (strings, numbers, etc.) instead of objects,
5533
6106
  // the binding path will be like: dataSources.repeater.{uid}.context.{fieldName}
5534
6107
  // But context IS the primitive value, so accessing context.fieldName returns undefined.
5535
6108
  // In this case, we should return the context itself.
6109
+ let handledRepeaterContext = false;
5536
6110
  if (dataPath.includes("dataSources.repeater")) {
5537
6111
  const pathParts = dataPath.split(".");
5538
6112
  // Check if path is: dataSources.repeater.{uid}.context.{fieldName}
@@ -5545,29 +6119,76 @@ function retrievePropValue(args) {
5545
6119
  const isPrimitive = typeof contextValue !== "object" || contextValue === null;
5546
6120
  if (isPrimitive) {
5547
6121
  resolvedData = contextValue;
6122
+ handledRepeaterContext = true;
5548
6123
  }
5549
6124
  }
5550
6125
  }
5551
6126
  }
5552
- if (type === "choice") {
5553
- if (!prop.multiSelect) {
5554
- // we are explicitly checking for single select choice type to ensure we don't have a mismatch in the data type.
5555
- if (Array.isArray(resolvedData)) {
5556
- resolvedData = resolvedData[0];
6127
+ // Unwrap single-key objects (common in Contentstack Modular Blocks)
6128
+ // We only do this if we are not explicitly expecting an object or array.
6129
+ // Skip if we already handled the repeater context case above.
6130
+ if (type !== "object" && type !== "array" && !handledRepeaterContext) {
6131
+ resolvedData = getFlattenedData(resolvedData);
6132
+ resolvedData = normalizeSingleSelectChoiceValue(resolvedData, prop);
6133
+ // Fallback to static value if the resolved data is still not matching the expected primitive type
6134
+ // This ensures that if a binding returns an object (e.g. during a structural change), we don't crash React
6135
+ // and instead show the static value entered by the user.
6136
+ if (!isDataMatchingPropType(resolvedData, type)) {
6137
+ if (type === "string") {
6138
+ const actualType = getDataType(resolvedData);
6139
+ if (actualType === "object" || actualType === "array") {
6140
+ resolvedData =
6141
+ "This content may not display correctly in this view. Please contact your development team to update the component so it can support this type of content.";
6142
+ }
6143
+ else {
6144
+ resolvedData =
6145
+ staticValue !== undefined ? staticValue : fallbackValue;
6146
+ }
6147
+ }
6148
+ else {
6149
+ resolvedData =
6150
+ staticValue !== undefined ? staticValue : fallbackValue;
5557
6151
  }
5558
6152
  }
5559
6153
  }
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];
6160
+ }
5560
6161
  }
5561
6162
  else {
5562
- resolvedData = fallbackValue;
5563
- // 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.
5564
- if (type === "choice") {
5565
- if (!prop.multiSelect) {
5566
- // we are explicitly checking for single select choice type to ensure we don't have a mismatch in the data type.
5567
- if (Array.isArray(resolvedData)) {
5568
- 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];
5569
6173
  }
5570
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];
5571
6192
  }
5572
6193
  }
5573
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.
@@ -5606,13 +6227,8 @@ function retrievePropValue(args) {
5606
6227
  if (type === "json_rte") {
5607
6228
  mappedData["jsonConfig"] = jsonRTE;
5608
6229
  }
5609
- const cslpAbleTypes = [
5610
- DATA_SOURCES.CONTENTSTACK,
5611
- DATA_SOURCES.COMPONENT_PROPS,
5612
- DATA_SOURCES.TEMPLATE,
5613
- DATA_SOURCES.REPEATER,
5614
- ];
5615
- const isCSLPAbleType = bindedField?.type && cslpAbleTypes.includes(bindedField.type);
6230
+ const isCSLPAbleType = bindedField?.type &&
6231
+ dataSourceCapabilities[bindedField.type]?.supportsCslp;
5616
6232
  if (cslp.appendTags && dataPath && isCSLPAbleType) {
5617
6233
  const cslpValue = getCslpTag({ bindedField: dataPath, data });
5618
6234
  if (cslpValue) {
@@ -5624,6 +6240,11 @@ function retrievePropValue(args) {
5624
6240
  mappedData["_uid"] = node.uid;
5625
6241
  mappedData["mode"] = node?.metadata?.mode;
5626
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
+ }
5627
6248
  if (node.type === "condition-block") {
5628
6249
  mappedData["condition"] = node?.metadata?.condition;
5629
6250
  mappedData["mode"] = node?.metadata?.mode;
@@ -5726,20 +6347,32 @@ exports.JSONRTERegistry = JSONRTERegistry;
5726
6347
  exports.STYLE_SECTIONS_OPTIONS = STYLE_SECTIONS_OPTIONS;
5727
6348
  exports.STYLE_SECTION_CATEGORIES = STYLE_SECTION_CATEGORIES;
5728
6349
  exports.SYSTEM_COMPONENTS = SYSTEM_COMPONENTS;
6350
+ exports.convertBindingPath = convertBindingPath;
5729
6351
  exports.getBindingString = getBindingString;
6352
+ exports.getComponentRegistryInstance = getComponentRegistryInstance;
5730
6353
  exports.getCslpPath = getCslpPath;
5731
6354
  exports.getCslpTag = getCslpTag;
5732
6355
  exports.getDataType = getDataType;
5733
6356
  exports.getDefaultPropStaticValue = getDefaultPropStaticValue;
5734
6357
  exports.getDesignClassesNames = getDesignClassesNames;
6358
+ exports.getDesignRegistryInstance = getDesignRegistryInstance;
6359
+ exports.getFlattenedData = getFlattenedData;
6360
+ exports.getGlobalStudioStore = getGlobalStudioStore;
5735
6361
  exports.getPlaceHolderComponent = getPlaceHolderComponent;
5736
6362
  exports.getRepeaterBinding = getRepeaterBinding;
5737
6363
  exports.getRepeaterContextPath = getRepeaterContextPath;
6364
+ exports.getSectionUIDFromNode = getSectionUIDFromNode;
5738
6365
  exports.getSlotData = getSlotData;
5739
6366
  exports.getSymbolUIDFromNode = getSymbolUIDFromNode;
5740
6367
  exports.getSymbolUIDFromUID = getSymbolUIDFromUID;
6368
+ exports.hasComponentRegistryInstance = hasComponentRegistryInstance;
6369
+ exports.hasDesignRegistryInstance = hasDesignRegistryInstance;
5741
6370
  exports.isDataMatchingPropType = isDataMatchingPropType;
5742
6371
  exports.isKnownType = isKnownType;
6372
+ exports.normalizeSingleSelectChoiceValue = normalizeSingleSelectChoiceValue;
6373
+ exports.resetComponentRegistryInstance = resetComponentRegistryInstance;
6374
+ exports.resetDesignRegistryInstance = resetDesignRegistryInstance;
6375
+ exports.resetGlobalStudioStore = resetGlobalStudioStore;
5743
6376
  exports.resolveMetadataBindings = resolveMetadataBindings;
5744
6377
  exports.retrievePropValue = retrievePropValue;
5745
6378
  //# sourceMappingURL=index.cjs.map