@contentstack/studio-registry 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +341 -46
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/component-registry/registry-options-processor.js +27 -0
- package/dist/esm/component-registry/registry-options-processor.js.map +1 -1
- package/dist/esm/component-registry/registry.constant.js +2 -0
- package/dist/esm/component-registry/registry.constant.js.map +1 -1
- package/dist/esm/component-registry/registry.js +171 -4
- package/dist/esm/component-registry/registry.js.map +1 -1
- package/dist/esm/component-registry/singleton.js +59 -0
- package/dist/esm/component-registry/singleton.js.map +1 -0
- package/dist/esm/data-binder/retrieve-data.js +38 -17
- package/dist/esm/data-binder/retrieve-data.js.map +1 -1
- package/dist/esm/data-binder/retrieve-data.util.js +23 -4
- package/dist/esm/data-binder/retrieve-data.util.js.map +1 -1
- package/dist/esm/index.d.ts +128 -2
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +12 -9
package/dist/cjs/index.cjs
CHANGED
|
@@ -125,6 +125,7 @@ const INTERNAL_COMPONENTS_NAMES = {
|
|
|
125
125
|
LINK: "link",
|
|
126
126
|
LINK_CONTAINER: "link-container",
|
|
127
127
|
TEXT: "text",
|
|
128
|
+
NUMBER: "number",
|
|
128
129
|
BUTTON: "button",
|
|
129
130
|
JSON_RTE: "json-rte",
|
|
130
131
|
COLLAPSIBLE_TEXT: "collapsible-text",
|
|
@@ -161,6 +162,7 @@ const BUILT_IN_COMPONENTS = {
|
|
|
161
162
|
LINK: "link",
|
|
162
163
|
LINK_CONTAINER: "link-container",
|
|
163
164
|
TEXT: "text",
|
|
165
|
+
NUMBER: "number",
|
|
164
166
|
BUTTON: "button",
|
|
165
167
|
JSON_RTE: "json-rte",
|
|
166
168
|
COLLAPSIBLE_TEXT: "collapsible-text",
|
|
@@ -4034,6 +4036,7 @@ function processRegistryOptionsProps(props) {
|
|
|
4034
4036
|
delete processedProps[field].validate;
|
|
4035
4037
|
}
|
|
4036
4038
|
}
|
|
4039
|
+
validateSlotCountPropLinkages(props, processedProps);
|
|
4037
4040
|
return { props: processedProps, validators: propValidators };
|
|
4038
4041
|
}
|
|
4039
4042
|
function getExpandedPropTypes(prop) {
|
|
@@ -4050,6 +4053,32 @@ function getExpandedPropTypes(prop) {
|
|
|
4050
4053
|
};
|
|
4051
4054
|
return propTypeMapping[prop];
|
|
4052
4055
|
}
|
|
4056
|
+
function validateSlotCountPropLinkages(originalProps, processedProps) {
|
|
4057
|
+
if (!originalProps)
|
|
4058
|
+
return;
|
|
4059
|
+
for (const [field, prop] of Object.entries(originalProps)) {
|
|
4060
|
+
if (typeof prop === "string" || prop.type !== "slot")
|
|
4061
|
+
continue;
|
|
4062
|
+
const slotProp = prop;
|
|
4063
|
+
if (!slotProp.countProp)
|
|
4064
|
+
continue;
|
|
4065
|
+
const linkedProp = originalProps[slotProp.countProp];
|
|
4066
|
+
const linkedPropType = typeof linkedProp === "string" ? linkedProp : linkedProp?.type;
|
|
4067
|
+
if (!linkedProp || linkedPropType !== "number") {
|
|
4068
|
+
throw new Error(`Slot "${field}" references countProp "${slotProp.countProp}" which must be a registered number prop.`);
|
|
4069
|
+
}
|
|
4070
|
+
if (!slotProp.itemFactory || typeof slotProp.itemFactory !== "function") {
|
|
4071
|
+
throw new Error(`Slot "${field}" with countProp must provide an itemFactory function.`);
|
|
4072
|
+
}
|
|
4073
|
+
const existingSlotProp = processedProps[field];
|
|
4074
|
+
processedProps[field] = {
|
|
4075
|
+
...existingSlotProp,
|
|
4076
|
+
countProp: slotProp.countProp,
|
|
4077
|
+
itemFactory: slotProp.itemFactory,
|
|
4078
|
+
itemTemplate: slotProp.itemFactory(),
|
|
4079
|
+
};
|
|
4080
|
+
}
|
|
4081
|
+
}
|
|
4053
4082
|
function getBlockStyleSections() {
|
|
4054
4083
|
return STYLE_SECTION_CATEGORIES.block;
|
|
4055
4084
|
}
|
|
@@ -4070,6 +4099,10 @@ class ComponentRegistry {
|
|
|
4070
4099
|
componentRegistry = new Map();
|
|
4071
4100
|
propValidatorRegistry = new Map();
|
|
4072
4101
|
config;
|
|
4102
|
+
// Lazy loading infrastructure
|
|
4103
|
+
componentLoaders = new Map();
|
|
4104
|
+
loadedComponents = new Set();
|
|
4105
|
+
loadingPromises = new Map();
|
|
4073
4106
|
constructor(config) {
|
|
4074
4107
|
// TODO process options
|
|
4075
4108
|
this.config = config || getDefaultComponentRegistryOptions();
|
|
@@ -4079,6 +4112,9 @@ class ComponentRegistry {
|
|
|
4079
4112
|
this.getComponents = this.getComponents.bind(this);
|
|
4080
4113
|
this.getComponent = this.getComponent.bind(this);
|
|
4081
4114
|
this.hasComponent = this.hasComponent.bind(this);
|
|
4115
|
+
this.registerLazyComponent = this.registerLazyComponent.bind(this);
|
|
4116
|
+
this.loadComponent = this.loadComponent.bind(this);
|
|
4117
|
+
this.loadComponents = this.loadComponents.bind(this);
|
|
4082
4118
|
}
|
|
4083
4119
|
setConfig(config = {}) {
|
|
4084
4120
|
if (config.allowedBuiltInComponents !== undefined) {
|
|
@@ -4123,9 +4159,12 @@ class ComponentRegistry {
|
|
|
4123
4159
|
const { type: name } = componentConfig;
|
|
4124
4160
|
this.componentRegistry.set(name, componentConfig);
|
|
4125
4161
|
});
|
|
4126
|
-
// sync unregistered components
|
|
4162
|
+
// sync unregistered components (never remove system / built-in entries)
|
|
4127
4163
|
this.componentRegistry.forEach((componentConfig) => {
|
|
4128
4164
|
if (!updatedConfig.some((c) => c.type === componentConfig.type)) {
|
|
4165
|
+
if (SYSTEM_COMPONENTS.has(componentConfig.type)) {
|
|
4166
|
+
return;
|
|
4167
|
+
}
|
|
4129
4168
|
this.unregisterComponent(componentConfig.type);
|
|
4130
4169
|
}
|
|
4131
4170
|
});
|
|
@@ -4248,7 +4287,24 @@ class ComponentRegistry {
|
|
|
4248
4287
|
if (!this.componentRegistry.has(name)) {
|
|
4249
4288
|
throw new Error(`Component with type '${name}' is not registered.`);
|
|
4250
4289
|
}
|
|
4251
|
-
|
|
4290
|
+
const componentSchema = this.componentRegistry.get(name);
|
|
4291
|
+
// Check if this is a lazy component that hasn't been loaded yet
|
|
4292
|
+
if (componentSchema.component === null && this.componentLoaders.has(name)) {
|
|
4293
|
+
const errorMessage = [
|
|
4294
|
+
`Component '${name}' is registered as lazy but hasn't been loaded yet.`,
|
|
4295
|
+
"",
|
|
4296
|
+
"This usually happens when:",
|
|
4297
|
+
"1. fetchSpec() was not awaited before rendering",
|
|
4298
|
+
"2. The component is being used in editor mode without being loaded",
|
|
4299
|
+
"3. There was an error during component loading",
|
|
4300
|
+
"",
|
|
4301
|
+
"Fix: Ensure fetchSpec() is properly awaited:",
|
|
4302
|
+
" const spec = await fetchSpec({ ... });",
|
|
4303
|
+
" return <ComposableStudio spec={spec} />;",
|
|
4304
|
+
].join("\n");
|
|
4305
|
+
throw new Error(errorMessage);
|
|
4306
|
+
}
|
|
4307
|
+
return componentSchema;
|
|
4252
4308
|
}
|
|
4253
4309
|
/**
|
|
4254
4310
|
* Retrieves a component from the component registry by its name.
|
|
@@ -4274,11 +4330,9 @@ class ComponentRegistry {
|
|
|
4274
4330
|
unregisterComponent(node) {
|
|
4275
4331
|
const name = typeof node === "string" ? node : this.getComponentName(node);
|
|
4276
4332
|
if (!this.componentRegistry.has(name)) {
|
|
4277
|
-
console.error(`Component with type '${name}' is not registered.`);
|
|
4278
4333
|
return;
|
|
4279
4334
|
}
|
|
4280
4335
|
if (SYSTEM_COMPONENTS.has(name)) {
|
|
4281
|
-
console.error(`Component with type '${name}' is a system component and cannot be unregistered.`);
|
|
4282
4336
|
return;
|
|
4283
4337
|
}
|
|
4284
4338
|
this.componentRegistry.delete(name);
|
|
@@ -4317,6 +4371,203 @@ class ComponentRegistry {
|
|
|
4317
4371
|
}
|
|
4318
4372
|
return type;
|
|
4319
4373
|
}
|
|
4374
|
+
/**
|
|
4375
|
+
* Registers a lazy-loadable component with a loader function.
|
|
4376
|
+
* The component will be loaded on-demand when needed.
|
|
4377
|
+
*
|
|
4378
|
+
* @param config - Component configuration without the component itself
|
|
4379
|
+
* @param loader - Function that returns a Promise resolving to the component
|
|
4380
|
+
* @param registryType - Type of registry (internal or user-defined), defaults to user-defined
|
|
4381
|
+
*/
|
|
4382
|
+
registerLazyComponent(config, loader, registryType = "user-defined") {
|
|
4383
|
+
const { type } = config;
|
|
4384
|
+
if (!type) {
|
|
4385
|
+
throw new Error("Component type is required.");
|
|
4386
|
+
}
|
|
4387
|
+
// For internal components, allow registration even if already exists
|
|
4388
|
+
// This is needed for built-in component lazy loading
|
|
4389
|
+
const isInternal = registryType === "internal";
|
|
4390
|
+
if (this.componentRegistry.has(type) &&
|
|
4391
|
+
!this.config.overrideDefaultComponents &&
|
|
4392
|
+
!isInternal) {
|
|
4393
|
+
throw new Error(`Component with type '${type}' is already registered.`);
|
|
4394
|
+
}
|
|
4395
|
+
if (SYSTEM_COMPONENTS.has(type) && !isInternal) {
|
|
4396
|
+
throw new Error(`Component with type '${type}' is a system component and cannot be overridden.`);
|
|
4397
|
+
}
|
|
4398
|
+
// Store the loader
|
|
4399
|
+
this.componentLoaders.set(type, loader);
|
|
4400
|
+
// Register a placeholder in the registry with _lazy flag
|
|
4401
|
+
const { processedOptions, propValidators } = processRegistryOptions({
|
|
4402
|
+
...config,
|
|
4403
|
+
component: null, // Placeholder, will be loaded later
|
|
4404
|
+
}, {
|
|
4405
|
+
registry: registryType,
|
|
4406
|
+
});
|
|
4407
|
+
// Mark as lazy for internal tracking
|
|
4408
|
+
processedOptions._lazy = true;
|
|
4409
|
+
this.componentRegistry.set(type, processedOptions);
|
|
4410
|
+
this.propValidatorRegistry.set(type, propValidators);
|
|
4411
|
+
}
|
|
4412
|
+
/**
|
|
4413
|
+
* Loads a single component if it's registered as lazy and not yet loaded.
|
|
4414
|
+
* Returns immediately if already loaded or not a lazy component.
|
|
4415
|
+
*
|
|
4416
|
+
* @param componentType - The type of component to load
|
|
4417
|
+
* @returns Promise that resolves when the component is loaded
|
|
4418
|
+
*/
|
|
4419
|
+
async loadComponent(componentType) {
|
|
4420
|
+
// Already loaded
|
|
4421
|
+
if (this.loadedComponents.has(componentType)) {
|
|
4422
|
+
return;
|
|
4423
|
+
}
|
|
4424
|
+
// Already loading
|
|
4425
|
+
if (this.loadingPromises.has(componentType)) {
|
|
4426
|
+
return this.loadingPromises.get(componentType);
|
|
4427
|
+
}
|
|
4428
|
+
// Not a lazy component or not registered
|
|
4429
|
+
const loader = this.componentLoaders.get(componentType);
|
|
4430
|
+
if (!loader) {
|
|
4431
|
+
return;
|
|
4432
|
+
}
|
|
4433
|
+
const loadPromise = (async () => {
|
|
4434
|
+
try {
|
|
4435
|
+
const component = await loader();
|
|
4436
|
+
// Update the registry with the loaded component
|
|
4437
|
+
const existingConfig = this.componentRegistry.get(componentType);
|
|
4438
|
+
if (existingConfig) {
|
|
4439
|
+
const updatedConfig = {
|
|
4440
|
+
...existingConfig,
|
|
4441
|
+
component,
|
|
4442
|
+
};
|
|
4443
|
+
delete updatedConfig._lazy;
|
|
4444
|
+
this.componentRegistry.set(componentType, updatedConfig);
|
|
4445
|
+
}
|
|
4446
|
+
this.loadedComponents.add(componentType);
|
|
4447
|
+
this.loadingPromises.delete(componentType);
|
|
4448
|
+
}
|
|
4449
|
+
catch (error) {
|
|
4450
|
+
this.loadingPromises.delete(componentType);
|
|
4451
|
+
console.error(`Failed to load component '${componentType}':`, error);
|
|
4452
|
+
throw error;
|
|
4453
|
+
}
|
|
4454
|
+
})();
|
|
4455
|
+
this.loadingPromises.set(componentType, loadPromise);
|
|
4456
|
+
return loadPromise;
|
|
4457
|
+
}
|
|
4458
|
+
/**
|
|
4459
|
+
* Loads multiple components in parallel.
|
|
4460
|
+
* Deduplicates requests and uses caching.
|
|
4461
|
+
*
|
|
4462
|
+
* @param componentTypes - Array of component types to load
|
|
4463
|
+
* @returns Promise that resolves when all components are loaded
|
|
4464
|
+
*/
|
|
4465
|
+
async loadComponents(componentTypes) {
|
|
4466
|
+
const uniqueTypes = Array.from(new Set(componentTypes));
|
|
4467
|
+
await Promise.all(uniqueTypes.map((type) => this.loadComponent(type)));
|
|
4468
|
+
}
|
|
4469
|
+
/**
|
|
4470
|
+
* Checks if a component is registered as lazy-loadable.
|
|
4471
|
+
*
|
|
4472
|
+
* @param componentType - The type of component to check
|
|
4473
|
+
* @returns true if the component is lazy-loadable
|
|
4474
|
+
*/
|
|
4475
|
+
isLazyComponent(componentType) {
|
|
4476
|
+
return this.componentLoaders.has(componentType);
|
|
4477
|
+
}
|
|
4478
|
+
/**
|
|
4479
|
+
* Checks if a lazy component has been loaded.
|
|
4480
|
+
*
|
|
4481
|
+
* @param componentType - The type of component to check
|
|
4482
|
+
* @returns true if the component has been loaded
|
|
4483
|
+
*/
|
|
4484
|
+
isComponentLoaded(componentType) {
|
|
4485
|
+
return this.loadedComponents.has(componentType);
|
|
4486
|
+
}
|
|
4487
|
+
/**
|
|
4488
|
+
* Checks if a component has a loader registered (lazy) or is already registered (eager).
|
|
4489
|
+
* This is useful for SSR validation to ensure components are available before rendering.
|
|
4490
|
+
*
|
|
4491
|
+
* @param componentType - The type of component to check
|
|
4492
|
+
* @returns true if the component has a loader or is registered
|
|
4493
|
+
*/
|
|
4494
|
+
hasComponentLoader(componentType) {
|
|
4495
|
+
return (this.componentLoaders.has(componentType) ||
|
|
4496
|
+
this.componentRegistry.has(componentType));
|
|
4497
|
+
}
|
|
4498
|
+
/**
|
|
4499
|
+
* Gets all component types that have loaders registered (lazy components).
|
|
4500
|
+
* Useful for debugging and SSR setup validation.
|
|
4501
|
+
*
|
|
4502
|
+
* @returns Array of component types with lazy loaders
|
|
4503
|
+
*/
|
|
4504
|
+
getLazyComponentTypes() {
|
|
4505
|
+
return Array.from(this.componentLoaders.keys());
|
|
4506
|
+
}
|
|
4507
|
+
/**
|
|
4508
|
+
* Gets all registered component types (both lazy and eager).
|
|
4509
|
+
* Useful for debugging and validation.
|
|
4510
|
+
*
|
|
4511
|
+
* @returns Array of all registered component types
|
|
4512
|
+
*/
|
|
4513
|
+
getAllComponentTypes() {
|
|
4514
|
+
return Array.from(this.componentRegistry.keys());
|
|
4515
|
+
}
|
|
4516
|
+
}
|
|
4517
|
+
|
|
4518
|
+
/**
|
|
4519
|
+
* Singleton instance of ComponentRegistry.
|
|
4520
|
+
* This ensures all packages (studio-client, studio-react, etc.) use the same registry instance.
|
|
4521
|
+
*
|
|
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
|
|
4526
|
+
*/
|
|
4527
|
+
let instance = null;
|
|
4528
|
+
/**
|
|
4529
|
+
* Gets the singleton ComponentRegistry instance.
|
|
4530
|
+
* Creates it if it doesn't exist yet.
|
|
4531
|
+
*
|
|
4532
|
+
* @returns The singleton ComponentRegistry instance
|
|
4533
|
+
*
|
|
4534
|
+
* @example
|
|
4535
|
+
* ```typescript
|
|
4536
|
+
* import { getComponentRegistryInstance } from '@contentstack/studio-registry';
|
|
4537
|
+
*
|
|
4538
|
+
* const registry = getComponentRegistryInstance();
|
|
4539
|
+
* await registry.loadComponent('my-component');
|
|
4540
|
+
* ```
|
|
4541
|
+
*/
|
|
4542
|
+
function getComponentRegistryInstance() {
|
|
4543
|
+
if (!instance) {
|
|
4544
|
+
instance = new ComponentRegistry();
|
|
4545
|
+
}
|
|
4546
|
+
return instance;
|
|
4547
|
+
}
|
|
4548
|
+
/**
|
|
4549
|
+
* Resets the singleton instance.
|
|
4550
|
+
* Primarily useful for testing to ensure a clean state between tests.
|
|
4551
|
+
*
|
|
4552
|
+
* @example
|
|
4553
|
+
* ```typescript
|
|
4554
|
+
* import { resetComponentRegistryInstance } from '@contentstack/studio-registry';
|
|
4555
|
+
*
|
|
4556
|
+
* beforeEach(() => {
|
|
4557
|
+
* resetComponentRegistryInstance();
|
|
4558
|
+
* });
|
|
4559
|
+
* ```
|
|
4560
|
+
*/
|
|
4561
|
+
function resetComponentRegistryInstance() {
|
|
4562
|
+
instance = null;
|
|
4563
|
+
}
|
|
4564
|
+
/**
|
|
4565
|
+
* Checks if the singleton instance has been created.
|
|
4566
|
+
*
|
|
4567
|
+
* @returns true if the instance exists, false otherwise
|
|
4568
|
+
*/
|
|
4569
|
+
function hasComponentRegistryInstance() {
|
|
4570
|
+
return instance !== null;
|
|
4320
4571
|
}
|
|
4321
4572
|
|
|
4322
4573
|
const SIZE_TOKENS = {
|
|
@@ -5198,14 +5449,6 @@ const getCslpTag = ({ bindedField, data, }) => {
|
|
|
5198
5449
|
return cslpValue || {};
|
|
5199
5450
|
};
|
|
5200
5451
|
|
|
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
5452
|
/**
|
|
5210
5453
|
* This transforms the provided data into the format defined by the schema.
|
|
5211
5454
|
*
|
|
@@ -5305,24 +5548,6 @@ function removeCurrentBindingKey(entry, bindingMap, currentBindingKey) {
|
|
|
5305
5548
|
return [key, newValue];
|
|
5306
5549
|
}
|
|
5307
5550
|
|
|
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
5551
|
/**
|
|
5327
5552
|
* Extracts the binding path string from a Contentstack-like binding object.
|
|
5328
5553
|
* Flattens nested path objects into a dot-notation string.
|
|
@@ -5391,6 +5616,24 @@ const getTemplateBindingString = (binding) => {
|
|
|
5391
5616
|
.join(".");
|
|
5392
5617
|
};
|
|
5393
5618
|
|
|
5619
|
+
class DataSourceStrategyRegistry {
|
|
5620
|
+
static instance;
|
|
5621
|
+
strategies = new Map();
|
|
5622
|
+
constructor() { }
|
|
5623
|
+
static getInstance() {
|
|
5624
|
+
if (!DataSourceStrategyRegistry.instance) {
|
|
5625
|
+
DataSourceStrategyRegistry.instance = new DataSourceStrategyRegistry();
|
|
5626
|
+
}
|
|
5627
|
+
return DataSourceStrategyRegistry.instance;
|
|
5628
|
+
}
|
|
5629
|
+
register(type, strategy) {
|
|
5630
|
+
this.strategies.set(type, strategy);
|
|
5631
|
+
}
|
|
5632
|
+
get(type) {
|
|
5633
|
+
return this.strategies.get(type);
|
|
5634
|
+
}
|
|
5635
|
+
}
|
|
5636
|
+
|
|
5394
5637
|
/**
|
|
5395
5638
|
* Retrieves the default static value for a given property type.
|
|
5396
5639
|
*
|
|
@@ -5511,6 +5754,20 @@ const getFlattenedData = (data) => {
|
|
|
5511
5754
|
}
|
|
5512
5755
|
return data;
|
|
5513
5756
|
};
|
|
5757
|
+
/**
|
|
5758
|
+
* Composition/static data often stores single-select choice as `string[]` (one element).
|
|
5759
|
+
* `isDataMatchingPropType` treats `choice` as a `string` or `string[]` (multi-select);
|
|
5760
|
+
* single-select stored as `string[]` must still be unwrapped here before the type-mismatch fallback.
|
|
5761
|
+
*/
|
|
5762
|
+
function normalizeSingleSelectChoiceValue(resolvedData, prop) {
|
|
5763
|
+
if (prop.type !== "choice" || ("multiSelect" in prop && prop.multiSelect)) {
|
|
5764
|
+
return resolvedData;
|
|
5765
|
+
}
|
|
5766
|
+
if (Array.isArray(resolvedData)) {
|
|
5767
|
+
return resolvedData[0];
|
|
5768
|
+
}
|
|
5769
|
+
return resolvedData;
|
|
5770
|
+
}
|
|
5514
5771
|
const resolveMetadataBindings = (node, data) => {
|
|
5515
5772
|
if (!node.metadata?.bindings)
|
|
5516
5773
|
return;
|
|
@@ -5533,13 +5790,18 @@ const getRepeaterContextPath = (binding) => {
|
|
|
5533
5790
|
};
|
|
5534
5791
|
function isDataMatchingPropType(data, type) {
|
|
5535
5792
|
const dataType = getDataType(data);
|
|
5793
|
+
if (type === "choice") {
|
|
5794
|
+
return (dataType === "string" ||
|
|
5795
|
+
(dataType === "array" &&
|
|
5796
|
+
Array.isArray(data) &&
|
|
5797
|
+
data.every((item) => typeof item === "string")));
|
|
5798
|
+
}
|
|
5536
5799
|
const map = {
|
|
5537
5800
|
string: dataType === "string" || dataType === "number" || dataType === "boolean",
|
|
5538
5801
|
boolean: dataType === "boolean",
|
|
5539
5802
|
number: dataType === "number",
|
|
5540
5803
|
object: dataType === "object",
|
|
5541
5804
|
array: dataType === "array",
|
|
5542
|
-
choice: dataType === "string",
|
|
5543
5805
|
href: dataType === "string",
|
|
5544
5806
|
imageurl: dataType === "string",
|
|
5545
5807
|
datestring: dataType === "string",
|
|
@@ -5557,6 +5819,14 @@ function getDataType(data) {
|
|
|
5557
5819
|
return typeof data;
|
|
5558
5820
|
}
|
|
5559
5821
|
|
|
5822
|
+
const dataSourceCapabilities = {
|
|
5823
|
+
[DATA_SOURCES.CONTENTSTACK]: { supportsCslp: true },
|
|
5824
|
+
[DATA_SOURCES.COMPONENT_PROPS]: { supportsCslp: true },
|
|
5825
|
+
[DATA_SOURCES.TEMPLATE]: { supportsCslp: true },
|
|
5826
|
+
[DATA_SOURCES.REPEATER]: { supportsCslp: true },
|
|
5827
|
+
[DATA_SOURCES.QUERY]: { supportsCslp: true }, // Verified: Query supports CSLP now
|
|
5828
|
+
};
|
|
5829
|
+
|
|
5560
5830
|
// Responsible for resolving props to values
|
|
5561
5831
|
function retrievePropValue(args) {
|
|
5562
5832
|
const { data, componentOptions, node, cslp, placeholders = {}, getSlots, jsonRTE, isCompositionBeingEdited, } = args;
|
|
@@ -5651,7 +5921,8 @@ function retrievePropValue(args) {
|
|
|
5651
5921
|
}
|
|
5652
5922
|
}
|
|
5653
5923
|
}
|
|
5654
|
-
else if (dataPath
|
|
5924
|
+
else if (dataPath &&
|
|
5925
|
+
!(type === "choice" && bindedField?.type === "static_value")) {
|
|
5655
5926
|
resolvedData = get(data, dataPath, fallbackValue);
|
|
5656
5927
|
// Handle primitive values in repeater context
|
|
5657
5928
|
// When the array contains primitives (strings, numbers, etc.) instead of objects,
|
|
@@ -5681,6 +5952,7 @@ function retrievePropValue(args) {
|
|
|
5681
5952
|
// Skip if we already handled the repeater context case above.
|
|
5682
5953
|
if (type !== "object" && type !== "array" && !handledRepeaterContext) {
|
|
5683
5954
|
resolvedData = getFlattenedData(resolvedData);
|
|
5955
|
+
resolvedData = normalizeSingleSelectChoiceValue(resolvedData, prop);
|
|
5684
5956
|
// Fallback to static value if the resolved data is still not matching the expected primitive type
|
|
5685
5957
|
// This ensures that if a binding returns an object (e.g. during a structural change), we don't crash React
|
|
5686
5958
|
// and instead show the static value entered by the user.
|
|
@@ -5702,25 +5974,44 @@ function retrievePropValue(args) {
|
|
|
5702
5974
|
}
|
|
5703
5975
|
}
|
|
5704
5976
|
}
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
}
|
|
5977
|
+
// Normalize data type: convert arrays to single values for single-select props
|
|
5978
|
+
if (type === "choice" &&
|
|
5979
|
+
!prop.multiSelect &&
|
|
5980
|
+
Array.isArray(resolvedData)) {
|
|
5981
|
+
// Single-select props (choice, etc.) should receive single values, not arrays
|
|
5982
|
+
resolvedData = resolvedData[0];
|
|
5712
5983
|
}
|
|
5713
5984
|
}
|
|
5714
5985
|
else {
|
|
5715
|
-
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
5986
|
+
// For choice props, explicitly retrieve saved values from static content store
|
|
5987
|
+
if (type === "choice" && bindedField?.type === "static_value") {
|
|
5988
|
+
const staticContentKey = bindedField.value; // e.g., "B575hDbLkWhPSfB-alignment"
|
|
5989
|
+
// Try to find the saved value in the static content store
|
|
5990
|
+
let savedValue = undefined;
|
|
5991
|
+
// Check if we have access to the static_value from data
|
|
5992
|
+
if (data.static_value && typeof data.static_value === "object") {
|
|
5993
|
+
// Look for the value directly by key
|
|
5994
|
+
if (typeof staticContentKey === "string") {
|
|
5995
|
+
savedValue = data.static_value[staticContentKey];
|
|
5722
5996
|
}
|
|
5723
5997
|
}
|
|
5998
|
+
if (savedValue !== undefined) {
|
|
5999
|
+
resolvedData = savedValue;
|
|
6000
|
+
}
|
|
6001
|
+
else {
|
|
6002
|
+
resolvedData =
|
|
6003
|
+
staticValue !== undefined ? staticValue : fallbackValue;
|
|
6004
|
+
}
|
|
6005
|
+
}
|
|
6006
|
+
else {
|
|
6007
|
+
resolvedData = staticValue !== undefined ? staticValue : fallbackValue;
|
|
6008
|
+
}
|
|
6009
|
+
// Normalize data type: convert arrays to single values for single-select props
|
|
6010
|
+
if (type === "choice" &&
|
|
6011
|
+
!prop.multiSelect &&
|
|
6012
|
+
Array.isArray(resolvedData)) {
|
|
6013
|
+
// Single-select props (choice, etc.) should receive single values, not arrays
|
|
6014
|
+
resolvedData = resolvedData[0];
|
|
5724
6015
|
}
|
|
5725
6016
|
}
|
|
5726
6017
|
// 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.
|
|
@@ -5876,6 +6167,7 @@ exports.STYLE_SECTION_CATEGORIES = STYLE_SECTION_CATEGORIES;
|
|
|
5876
6167
|
exports.SYSTEM_COMPONENTS = SYSTEM_COMPONENTS;
|
|
5877
6168
|
exports.convertBindingPath = convertBindingPath;
|
|
5878
6169
|
exports.getBindingString = getBindingString;
|
|
6170
|
+
exports.getComponentRegistryInstance = getComponentRegistryInstance;
|
|
5879
6171
|
exports.getCslpPath = getCslpPath;
|
|
5880
6172
|
exports.getCslpTag = getCslpTag;
|
|
5881
6173
|
exports.getDataType = getDataType;
|
|
@@ -5888,8 +6180,11 @@ exports.getRepeaterContextPath = getRepeaterContextPath;
|
|
|
5888
6180
|
exports.getSlotData = getSlotData;
|
|
5889
6181
|
exports.getSymbolUIDFromNode = getSymbolUIDFromNode;
|
|
5890
6182
|
exports.getSymbolUIDFromUID = getSymbolUIDFromUID;
|
|
6183
|
+
exports.hasComponentRegistryInstance = hasComponentRegistryInstance;
|
|
5891
6184
|
exports.isDataMatchingPropType = isDataMatchingPropType;
|
|
5892
6185
|
exports.isKnownType = isKnownType;
|
|
6186
|
+
exports.normalizeSingleSelectChoiceValue = normalizeSingleSelectChoiceValue;
|
|
6187
|
+
exports.resetComponentRegistryInstance = resetComponentRegistryInstance;
|
|
5893
6188
|
exports.resolveMetadataBindings = resolveMetadataBindings;
|
|
5894
6189
|
exports.retrievePropValue = retrievePropValue;
|
|
5895
6190
|
//# sourceMappingURL=index.cjs.map
|