@contentful/experiences-core 1.42.0-beta.0 → 1.42.0-dev-20250624T0633-2ccc3ab.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/exports.d.ts +1 -1
- package/dist/index.js +69 -64
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +3 -3
- package/package.json +3 -3
package/dist/exports.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { ASSEMBLY_BLOCK_NODE_TYPE, ASSEMBLY_DEFAULT_CATEGORY, ASSEMBLY_NODE_TYPE, ASSEMBLY_NODE_TYPES, CF_STYLE_ATTRIBUTES, CONTENTFUL_COMPONENTS, CONTENTFUL_COMPONENT_CATEGORY, CONTENTFUL_DEFAULT_CATEGORY, DEFAULT_IMAGE_WIDTH, EMPTY_CONTAINER_HEIGHT, HYPERLINK_DEFAULT_PATTERN, INCOMING_EVENTS, INTERNAL_EVENTS, LATEST_SCHEMA_VERSION, OUTGOING_EVENTS, PATTERN_PROPERTY_DIVIDER, PostMessageMethods, SCROLL_STATES, SUPPORTED_IMAGE_FORMATS, StudioCanvasMode, VISUAL_EDITOR_CONTAINER_ID, VISUAL_EDITOR_EVENTS } from './constants.js';
|
|
2
2
|
export { AssembliesAddedPayload, AssembliesRegisteredPayload, BackgroundImageAlignmentOption, BackgroundImageOptions, BackgroundImageScalingOption, Binding, BindingMap, BindingMapByBlockId, BoundComponentPropertyTypes, CSSProperties, CanvasErrorPayload, CanvasReloadPayload, CanvasResizedPayload, CanvasScrollPayload, ComponentBinding, ComponentDefinition, ComponentDefinitionVariable, ComponentDefinitionVariableBase, ComponentDefinitionVariableTypeMap, ComponentDefinitionVariableValidation, ComponentDragCanceledPayload, ComponentDragEndedPayload, ComponentDragStartedPayload, ComponentDraggingChangedPayload, ComponentDroppedPayload, ComponentMoveEndedPayload, ComponentMoveStartedPayload, ComponentMovedPayload, ComponentRegistration, ComponentRegistrationOptions, ComponentSelectedPayload, ConnectedPayload, ContainerStyleVariableName, Coordinates, DataSourceEntryValueType, DesignTokensDefinition, DesignTokensPayload, DesignVariableMap, DesignVariableTypes, DragWrapperProps, Experience, ExperienceEntry, ExperienceFields, ExperienceTree, ExperienceTreeNode, ExperienceUpdatedPayload, HoverComponentPayload, HoveredElement, ImageLoadingOption, ImageObjectFitOption, ImageObjectPositionOption, ImageOptions, IncomingComponentDragCanceledPayload, IncomingComponentMoveEndedPayload, IncomingEvent, IncomingMessage, IncomingMouseMovePayload, InternalEvent, Link, ManagementEntity, MouseMovePayload, NewHoveredElementPayload, OptimizedBackgroundImageAsset, OptimizedImageAsset, OutgoingEvent, OutgoingMessage, OutsideCanvasClickPayload, RawCoordinates, RecursiveDesignTokenDefinition, RegisteredBreakpointsPayload, RegisteredComponentsPayload, RequestComponentTreeUpdatePayload, RequestEditorModePayload, RequestEntitiesMessage, RequestEntitiesPayload, RequestReadOnlyModePayload, RequestedEntitiesMessage, RequestedEntitiesPayload, ResolveDesignValueType, SDKFeaturesPayload, ScrollState, SelectComponentPayload, SendMessageParams, StyleProps, UpdateSelectedComponentCoordinatesPayload, UpdatedEntityPayload, ValidationOption, VariableFormats, WrapperTags } from './types.js';
|
|
3
|
-
export { BoundValue, Breakpoint, ComponentDefinitionPropertyType as ComponentDefinitionVariableType, ComponentPropertyValue, ComponentTreeNode, ComponentValue, DesignValue, ExperienceComponentSettings, ExperienceDataSource, ExperienceUnboundValues, NoValue,
|
|
3
|
+
export { BoundValue, Breakpoint, ComponentDefinitionPropertyType as ComponentDefinitionVariableType, ComponentPropertyValue, ComponentTreeNode, ComponentValue, DesignValue, ExperienceComponentSettings, ExperienceDataSource, ExperienceUnboundValues, NoValue, PatternProperty, PatternPropertyDefinition, PrimitiveValue, SchemaVersions, UnboundValue, ValuesByBreakpoint, VariableMapping } from '@contentful/experiences-validators';
|
package/dist/index.js
CHANGED
|
@@ -950,11 +950,11 @@ const ComponentPropertyValueSchema = z.discriminatedUnion('type', [
|
|
|
950
950
|
]);
|
|
951
951
|
// TODO: finalize schema structure before release
|
|
952
952
|
// https://contentful.atlassian.net/browse/LUMOS-523
|
|
953
|
-
const
|
|
953
|
+
const PatternPropertySchema = z.object({
|
|
954
954
|
type: z.literal('BoundValue'),
|
|
955
955
|
path: z.string(),
|
|
956
956
|
});
|
|
957
|
-
const
|
|
957
|
+
const PatternPropertiesSchema = z.record(propertyKeySchema, PatternPropertySchema);
|
|
958
958
|
const BreakpointSchema = z
|
|
959
959
|
.object({
|
|
960
960
|
id: propertyKeySchema,
|
|
@@ -971,7 +971,7 @@ const BaseComponentTreeNodeSchema = z.object({
|
|
|
971
971
|
displayName: z.string().optional(),
|
|
972
972
|
slotId: z.string().optional(),
|
|
973
973
|
variables: z.record(propertyKeySchema, ComponentPropertyValueSchema),
|
|
974
|
-
|
|
974
|
+
patternProperties: PatternPropertiesSchema.optional(),
|
|
975
975
|
});
|
|
976
976
|
const ComponentVariableSchema = z.object({
|
|
977
977
|
displayName: z.string().optional(),
|
|
@@ -1040,13 +1040,13 @@ const THUMBNAIL_IDS = [
|
|
|
1040
1040
|
// TODO: finalize schema structure before release
|
|
1041
1041
|
// https://contentful.atlassian.net/browse/LUMOS-523
|
|
1042
1042
|
const VariableMappingSchema = z.object({
|
|
1043
|
-
|
|
1043
|
+
patternPropertyDefinitionId: propertyKeySchema,
|
|
1044
1044
|
type: z.literal('ContentTypeMapping'),
|
|
1045
1045
|
pathsByContentType: z.record(z.string(), z.object({ path: z.string() })),
|
|
1046
1046
|
});
|
|
1047
1047
|
// TODO: finalize schema structure before release
|
|
1048
1048
|
// https://contentful.atlassian.net/browse/LUMOS-523
|
|
1049
|
-
const
|
|
1049
|
+
const PatternPropertyDefinitionSchema = z.object({
|
|
1050
1050
|
defaultValue: z
|
|
1051
1051
|
.record(z.string(), z.object({
|
|
1052
1052
|
sys: z.object({
|
|
@@ -1064,7 +1064,7 @@ const ParameterDefinitionSchema = z.object({
|
|
|
1064
1064
|
}),
|
|
1065
1065
|
})),
|
|
1066
1066
|
});
|
|
1067
|
-
const
|
|
1067
|
+
const PatternPropertyDefinitionsSchema = z.record(propertyKeySchema, PatternPropertyDefinitionSchema);
|
|
1068
1068
|
const VariableMappingsSchema = z.record(propertyKeySchema, VariableMappingSchema);
|
|
1069
1069
|
const ComponentVariablesSchema = z.record(z.string().regex(/^[a-zA-Z0-9-_]{1,54}$/), // Here the key is <variableName>_<nanoidId> so we need to allow for a longer length
|
|
1070
1070
|
ComponentVariableSchema);
|
|
@@ -1073,7 +1073,7 @@ const ComponentSettingsSchema = z.object({
|
|
|
1073
1073
|
thumbnailId: z.enum(THUMBNAIL_IDS).optional(),
|
|
1074
1074
|
category: z.string().max(50, 'Category must contain at most 50 characters').optional(),
|
|
1075
1075
|
variableMappings: VariableMappingsSchema.optional(),
|
|
1076
|
-
|
|
1076
|
+
patternPropertyDefinitions: PatternPropertyDefinitionsSchema.optional(),
|
|
1077
1077
|
});
|
|
1078
1078
|
z.object({
|
|
1079
1079
|
componentTree: localeWrapper(ComponentTreeSchema),
|
|
@@ -2101,6 +2101,55 @@ const getOptimizedBackgroundImageAsset = (file, widthStyle, quality = '100%', fo
|
|
|
2101
2101
|
}
|
|
2102
2102
|
};
|
|
2103
2103
|
|
|
2104
|
+
/**
|
|
2105
|
+
* Turns a condition like `<768px` or `>1024px` into a media query rule.
|
|
2106
|
+
* For example, `<768px` becomes `max-width:768px` and `>1024px` becomes `min-width:1024px`.
|
|
2107
|
+
*/
|
|
2108
|
+
const toMediaQueryRule = (condition) => {
|
|
2109
|
+
const [evaluation, pixelValue] = [condition[0], condition.substring(1)];
|
|
2110
|
+
const mediaQueryRule = evaluation === '<' ? 'max-width' : 'min-width';
|
|
2111
|
+
return `(${mediaQueryRule}:${pixelValue})`;
|
|
2112
|
+
};
|
|
2113
|
+
/**
|
|
2114
|
+
* Converts a map of class names to CSS strings into a single CSS string.
|
|
2115
|
+
*
|
|
2116
|
+
* @param cssByClassName map of class names to CSS strings containing all rules for each class
|
|
2117
|
+
* @returns joined string of all CSS class definitions
|
|
2118
|
+
*/
|
|
2119
|
+
const toCompoundCss = (cssByClassName) => {
|
|
2120
|
+
return Object.entries(cssByClassName).reduce((acc, [className, css]) => {
|
|
2121
|
+
if (css === '')
|
|
2122
|
+
return acc;
|
|
2123
|
+
return `${acc}.${className}{${css}}`;
|
|
2124
|
+
}, ``);
|
|
2125
|
+
};
|
|
2126
|
+
/**
|
|
2127
|
+
* Create a single CSS string containing all class definitions for a given media query.
|
|
2128
|
+
*
|
|
2129
|
+
* @param cssByClassName map of class names to CSS strings containing all rules for each class
|
|
2130
|
+
* @param condition e.g. "*", "<520px", ">520px"
|
|
2131
|
+
* @param nextCondition optional next condition to create a disjunct media query that doesn't affect the next breakpoint
|
|
2132
|
+
* @returns joined string of all CSS class definitions wrapped into media queries
|
|
2133
|
+
*/
|
|
2134
|
+
const toMediaQuery = ({ cssByClassName, condition, nextCondition, }) => {
|
|
2135
|
+
const compoundCss = toCompoundCss(cssByClassName);
|
|
2136
|
+
if (compoundCss === '') {
|
|
2137
|
+
return '';
|
|
2138
|
+
}
|
|
2139
|
+
const queryRule = toMediaQueryRule(condition);
|
|
2140
|
+
if (!nextCondition) {
|
|
2141
|
+
if (condition === '*') {
|
|
2142
|
+
return compoundCss;
|
|
2143
|
+
}
|
|
2144
|
+
return `@media${queryRule}{${compoundCss}}`;
|
|
2145
|
+
}
|
|
2146
|
+
const nextRule = toMediaQueryRule(nextCondition);
|
|
2147
|
+
if (condition === '*') {
|
|
2148
|
+
return `@media not ${nextRule}{${compoundCss}}`;
|
|
2149
|
+
}
|
|
2150
|
+
return `@media${queryRule} and (not ${nextRule}){${compoundCss}}`;
|
|
2151
|
+
};
|
|
2152
|
+
|
|
2104
2153
|
const detachExperienceStyles = (experience) => {
|
|
2105
2154
|
const experienceTreeRoot = experience.entityStore?.experienceEntryFields
|
|
2106
2155
|
?.componentTree;
|
|
@@ -2197,7 +2246,7 @@ const detachExperienceStyles = (experience) => {
|
|
|
2197
2246
|
const isAnyVisibilityValueHidden = Object.values(propsByBreakpoint).some((designProperties) => designProperties.cfVisibility === false);
|
|
2198
2247
|
// We always need an explicit value when using disjunct media queries
|
|
2199
2248
|
// Example: desktop uses "false" and tablet is undefined -> we need to set `display: none` for tablet as well.
|
|
2200
|
-
let previousVisibilityValue
|
|
2249
|
+
let previousVisibilityValue;
|
|
2201
2250
|
/* [Data format] `propsByBreakpoint` is a map of "breakpointId > propertyName > plainValue":
|
|
2202
2251
|
* {
|
|
2203
2252
|
* desktop: {
|
|
@@ -2211,7 +2260,7 @@ const detachExperienceStyles = (experience) => {
|
|
|
2211
2260
|
const currentNodeClassNames = [];
|
|
2212
2261
|
// Chain IDs to avoid overwriting styles across multiple instances of the same pattern
|
|
2213
2262
|
// e.g. `{outerPatternNodeId}{innerPatternNodeId}-{currentNodeId}`
|
|
2214
|
-
// (!) Notice that the chain of patterns (before the dash) follows the format of prebinding/
|
|
2263
|
+
// (!) Notice that the chain of patterns (before the dash) follows the format of prebinding/ patternProperties
|
|
2215
2264
|
const currentNodeIdsChain = `${wrappingPatternNodeIds.join('')}-${currentNode.id}`;
|
|
2216
2265
|
// For each breakpoint, resolve design tokens, create the CSS and generate a unique className.
|
|
2217
2266
|
for (const breakpointId of breakpointIds) {
|
|
@@ -2308,7 +2357,7 @@ const detachExperienceStyles = (experience) => {
|
|
|
2308
2357
|
});
|
|
2309
2358
|
// once the whole tree was traversed, for each breakpoint, I aggregate the styles
|
|
2310
2359
|
// for each generated className into one css string
|
|
2311
|
-
|
|
2360
|
+
const stylesheet = Object.values(mediaQueryDataByBreakpoint).reduce((acc, { condition, cssByClassName, visibilityCssByClassName }, index) => {
|
|
2312
2361
|
const mediaQueryCss = toMediaQuery({ cssByClassName, condition });
|
|
2313
2362
|
// Handle visibility separately to use disjunct media queries ("if desktop but not tablet ...")
|
|
2314
2363
|
// Enables to hide on one breakpoint but render any unknown custom `display` value on another breakpoint.
|
|
@@ -2320,6 +2369,7 @@ const detachExperienceStyles = (experience) => {
|
|
|
2320
2369
|
});
|
|
2321
2370
|
return `${acc}${mediaQueryCss}${visibilityMediaQueryCss}`;
|
|
2322
2371
|
}, '');
|
|
2372
|
+
return stylesheet;
|
|
2323
2373
|
};
|
|
2324
2374
|
/**
|
|
2325
2375
|
* Rendering pattern nodes inside pattern entry by injecting default values from the top:
|
|
@@ -2328,7 +2378,7 @@ const detachExperienceStyles = (experience) => {
|
|
|
2328
2378
|
*/
|
|
2329
2379
|
const injectDefaultValuesForComponentValues = ({ patternNode, wrapperComponentSettings, }) => {
|
|
2330
2380
|
const propertyDefinitions = wrapperComponentSettings?.variableDefinitions;
|
|
2331
|
-
|
|
2381
|
+
const resolvedProperties = Object.entries(patternNode.variables).reduce((resolvedProperties, [propertyName, propertyValue]) => {
|
|
2332
2382
|
if (propertyValue.type === 'ComponentValue') {
|
|
2333
2383
|
const componentValueKey = propertyValue.key;
|
|
2334
2384
|
const componentDefaultValue = propertyDefinitions?.[componentValueKey].defaultValue;
|
|
@@ -2343,6 +2393,7 @@ const injectDefaultValuesForComponentValues = ({ patternNode, wrapperComponentSe
|
|
|
2343
2393
|
}
|
|
2344
2394
|
return resolvedProperties;
|
|
2345
2395
|
}, {});
|
|
2396
|
+
return resolvedProperties;
|
|
2346
2397
|
};
|
|
2347
2398
|
/**
|
|
2348
2399
|
* In case of nested patterns, we need to resolve the ComponentValue properties and overwrite them with the value
|
|
@@ -2356,16 +2407,17 @@ const resolveComponentVariablesOverwrites = ({ patternNode, wrapperComponentVari
|
|
|
2356
2407
|
// In case of rendering a pattern entry, there are no custom ComponentValues.
|
|
2357
2408
|
// So we pass down the default values from this pattern node down to each deeper pattern level.
|
|
2358
2409
|
if (!wrapperComponentVariablesOverwrites) {
|
|
2359
|
-
|
|
2410
|
+
const nextComponentVariablesOverwrites = injectDefaultValuesForComponentValues({
|
|
2360
2411
|
patternNode,
|
|
2361
2412
|
wrapperComponentSettings,
|
|
2362
2413
|
});
|
|
2414
|
+
return nextComponentVariablesOverwrites;
|
|
2363
2415
|
}
|
|
2364
2416
|
// Rendering (nested) pattern node inside another pattern node (for both experience & pattern entry):
|
|
2365
2417
|
// The `wrapperComponentVariablesOverwrites` from the top-most pattern node is passed through to each child
|
|
2366
2418
|
// node (and nested pattern nodes). It replaces each ComponentValue in the subtree with either the overwrite
|
|
2367
2419
|
// or the default value.
|
|
2368
|
-
|
|
2420
|
+
const nextComponentVariablesOverwrites = Object.entries(patternNode?.variables).reduce((resolvedValues, [propertyName, propertyValue]) => {
|
|
2369
2421
|
if (propertyValue.type === 'ComponentValue') {
|
|
2370
2422
|
// Copying the values from the parent node
|
|
2371
2423
|
const overwritingValue = wrapperComponentVariablesOverwrites?.[propertyValue.key];
|
|
@@ -2381,6 +2433,7 @@ const resolveComponentVariablesOverwrites = ({ patternNode, wrapperComponentVari
|
|
|
2381
2433
|
}
|
|
2382
2434
|
return resolvedValues;
|
|
2383
2435
|
}, {});
|
|
2436
|
+
return nextComponentVariablesOverwrites;
|
|
2384
2437
|
};
|
|
2385
2438
|
const isCfStyleAttribute = (variableName) => {
|
|
2386
2439
|
return CF_STYLE_ATTRIBUTES.includes(variableName);
|
|
@@ -2438,7 +2491,8 @@ const transformMedia$1 = (boundAsset, width, options) => {
|
|
|
2438
2491
|
const targetValue = targetWidthObject ? getTargetValueInPixels(targetWidthObject) : assetWidth;
|
|
2439
2492
|
if (targetValue < assetWidth)
|
|
2440
2493
|
width = `${targetValue}px`;
|
|
2441
|
-
|
|
2494
|
+
const value = getOptimizedBackgroundImageAsset(asset.fields.file, width, options.quality, options.format);
|
|
2495
|
+
return value;
|
|
2442
2496
|
}
|
|
2443
2497
|
catch (error) {
|
|
2444
2498
|
console.error('Error transforming image asset', error);
|
|
@@ -2659,55 +2713,6 @@ const flattenDesignTokenRegistry = (designTokenRegistry) => {
|
|
|
2659
2713
|
}, {});
|
|
2660
2714
|
};
|
|
2661
2715
|
|
|
2662
|
-
/**
|
|
2663
|
-
* Turns a condition like `<768px` or `>1024px` into a media query rule.
|
|
2664
|
-
* For example, `<768px` becomes `max-width:768px` and `>1024px` becomes `min-width:1024px`.
|
|
2665
|
-
*/
|
|
2666
|
-
const toMediaQueryRule = (condition) => {
|
|
2667
|
-
const [evaluation, pixelValue] = [condition[0], condition.substring(1)];
|
|
2668
|
-
const mediaQueryRule = evaluation === '<' ? 'max-width' : 'min-width';
|
|
2669
|
-
return `(${mediaQueryRule}:${pixelValue})`;
|
|
2670
|
-
};
|
|
2671
|
-
/**
|
|
2672
|
-
* Converts a map of class names to CSS strings into a single CSS string.
|
|
2673
|
-
*
|
|
2674
|
-
* @param cssByClassName map of class names to CSS strings containing all rules for each class
|
|
2675
|
-
* @returns joined string of all CSS class definitions
|
|
2676
|
-
*/
|
|
2677
|
-
const toCompoundCss = (cssByClassName) => {
|
|
2678
|
-
return Object.entries(cssByClassName).reduce((acc, [className, css]) => {
|
|
2679
|
-
if (css === '')
|
|
2680
|
-
return acc;
|
|
2681
|
-
return `${acc}.${className}{${css}}`;
|
|
2682
|
-
}, ``);
|
|
2683
|
-
};
|
|
2684
|
-
/**
|
|
2685
|
-
* Create a single CSS string containing all class definitions for a given media query.
|
|
2686
|
-
*
|
|
2687
|
-
* @param cssByClassName map of class names to CSS strings containing all rules for each class
|
|
2688
|
-
* @param condition e.g. "*", "<520px", ">520px"
|
|
2689
|
-
* @param nextCondition optional next condition to create a disjunct media query that doesn't affect the next breakpoint
|
|
2690
|
-
* @returns joined string of all CSS class definitions wrapped into media queries
|
|
2691
|
-
*/
|
|
2692
|
-
const toMediaQuery = ({ cssByClassName, condition, nextCondition, }) => {
|
|
2693
|
-
const compoundCss = toCompoundCss(cssByClassName);
|
|
2694
|
-
if (compoundCss === '') {
|
|
2695
|
-
return '';
|
|
2696
|
-
}
|
|
2697
|
-
const queryRule = toMediaQueryRule(condition);
|
|
2698
|
-
if (!nextCondition) {
|
|
2699
|
-
if (condition === '*') {
|
|
2700
|
-
return compoundCss;
|
|
2701
|
-
}
|
|
2702
|
-
return `@media${queryRule}{${compoundCss}}`;
|
|
2703
|
-
}
|
|
2704
|
-
const nextRule = toMediaQueryRule(nextCondition);
|
|
2705
|
-
if (condition === '*') {
|
|
2706
|
-
return `@media not ${nextRule}{${compoundCss}}`;
|
|
2707
|
-
}
|
|
2708
|
-
return `@media${queryRule} and (not ${nextRule}){${compoundCss}}`;
|
|
2709
|
-
};
|
|
2710
|
-
|
|
2711
2716
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2712
2717
|
function get(obj, path) {
|
|
2713
2718
|
if (!path.length) {
|
|
@@ -4152,7 +4157,7 @@ const attachPrebindingDefaultValueAsDataSource = (experienceEntry) => {
|
|
|
4152
4157
|
// Only supported for pattern entries since experience entries don't define pattern properties.
|
|
4153
4158
|
return;
|
|
4154
4159
|
}
|
|
4155
|
-
const patternDefs = experienceEntry.fields.componentSettings?.
|
|
4160
|
+
const patternDefs = experienceEntry.fields.componentSettings?.patternPropertyDefinitions ?? {};
|
|
4156
4161
|
const defaultPrebinding = Object.values(patternDefs).find((def) => def.defaultValue)?.defaultValue;
|
|
4157
4162
|
const [value] = Object.values(defaultPrebinding ?? {});
|
|
4158
4163
|
const id = value?.sys?.id;
|