@contentful/experiences-core 1.42.0-prerelease-20250625T0902-d9db401.0 → 1.42.0-prerelease-20250626T1154-6ca57b0.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 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, PatternProperty, PatternPropertyDefinition, PrimitiveValue, SchemaVersions, UnboundValue, ValuesByBreakpoint, VariableMapping } from '@contentful/experiences-validators';
3
+ export { BoundValue, Breakpoint, ComponentDefinitionPropertyType as ComponentDefinitionVariableType, ComponentPropertyValue, ComponentTreeNode, ComponentValue, DesignValue, ExperienceComponentSettings, ExperienceDataSource, ExperienceUnboundValues, NoValue, Parameter, ParameterDefinition, 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 PatternPropertySchema = z.object({
953
+ const ParameterSchema = z.object({
954
954
  type: z.literal('BoundValue'),
955
955
  path: z.string(),
956
956
  });
957
- const PatternPropertiesSchema = z.record(propertyKeySchema, PatternPropertySchema);
957
+ const ParametersSchema = z.record(propertyKeySchema, ParameterSchema);
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
- patternProperties: PatternPropertiesSchema.optional(),
974
+ parameters: ParametersSchema.optional(),
975
975
  });
976
976
  const ComponentVariableSchema = z.object({
977
977
  displayName: z.string().optional(),
@@ -1040,25 +1040,21 @@ 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
- patternPropertyDefinitionId: propertyKeySchema,
1043
+ parameterId: 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 PatternPropertyDefinitionSchema = z.object({
1050
- defaultSource: z
1051
- .strictObject({
1052
- type: z.enum(['Entry']),
1053
- contentTypeId: z.string(),
1054
- link: z.strictObject({
1055
- sys: z.strictObject({
1056
- type: z.literal('Link'),
1057
- id: z.string(),
1058
- linkType: z.enum(['Entry']),
1059
- }),
1049
+ const ParameterDefinitionSchema = z.object({
1050
+ defaultValue: z
1051
+ .record(z.string(), z.object({
1052
+ sys: z.object({
1053
+ type: z.literal('Link'),
1054
+ id: z.string(),
1055
+ linkType: z.enum(['Entry']),
1060
1056
  }),
1061
- })
1057
+ }))
1062
1058
  .optional(),
1063
1059
  contentTypes: z.record(z.string(), z.object({
1064
1060
  sys: z.object({
@@ -1068,7 +1064,7 @@ const PatternPropertyDefinitionSchema = z.object({
1068
1064
  }),
1069
1065
  })),
1070
1066
  });
1071
- const PatternPropertyDefinitionsSchema = z.record(propertyKeySchema, PatternPropertyDefinitionSchema);
1067
+ const ParameterDefinitionsSchema = z.record(propertyKeySchema, ParameterDefinitionSchema);
1072
1068
  const VariableMappingsSchema = z.record(propertyKeySchema, VariableMappingSchema);
1073
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
1074
1070
  ComponentVariableSchema);
@@ -1077,7 +1073,7 @@ const ComponentSettingsSchema = z.object({
1077
1073
  thumbnailId: z.enum(THUMBNAIL_IDS).optional(),
1078
1074
  category: z.string().max(50, 'Category must contain at most 50 characters').optional(),
1079
1075
  variableMappings: VariableMappingsSchema.optional(),
1080
- patternPropertyDefinitions: PatternPropertyDefinitionsSchema.optional(),
1076
+ parameterDefinitions: ParameterDefinitionsSchema.optional(),
1081
1077
  });
1082
1078
  z.object({
1083
1079
  componentTree: localeWrapper(ComponentTreeSchema),
@@ -2105,55 +2101,6 @@ const getOptimizedBackgroundImageAsset = (file, widthStyle, quality = '100%', fo
2105
2101
  }
2106
2102
  };
2107
2103
 
2108
- /**
2109
- * Turns a condition like `<768px` or `>1024px` into a media query rule.
2110
- * For example, `<768px` becomes `max-width:768px` and `>1024px` becomes `min-width:1024px`.
2111
- */
2112
- const toMediaQueryRule = (condition) => {
2113
- const [evaluation, pixelValue] = [condition[0], condition.substring(1)];
2114
- const mediaQueryRule = evaluation === '<' ? 'max-width' : 'min-width';
2115
- return `(${mediaQueryRule}:${pixelValue})`;
2116
- };
2117
- /**
2118
- * Converts a map of class names to CSS strings into a single CSS string.
2119
- *
2120
- * @param cssByClassName map of class names to CSS strings containing all rules for each class
2121
- * @returns joined string of all CSS class definitions
2122
- */
2123
- const toCompoundCss = (cssByClassName) => {
2124
- return Object.entries(cssByClassName).reduce((acc, [className, css]) => {
2125
- if (css === '')
2126
- return acc;
2127
- return `${acc}.${className}{${css}}`;
2128
- }, ``);
2129
- };
2130
- /**
2131
- * Create a single CSS string containing all class definitions for a given media query.
2132
- *
2133
- * @param cssByClassName map of class names to CSS strings containing all rules for each class
2134
- * @param condition e.g. "*", "<520px", ">520px"
2135
- * @param nextCondition optional next condition to create a disjunct media query that doesn't affect the next breakpoint
2136
- * @returns joined string of all CSS class definitions wrapped into media queries
2137
- */
2138
- const toMediaQuery = ({ cssByClassName, condition, nextCondition, }) => {
2139
- const compoundCss = toCompoundCss(cssByClassName);
2140
- if (compoundCss === '') {
2141
- return '';
2142
- }
2143
- const queryRule = toMediaQueryRule(condition);
2144
- if (!nextCondition) {
2145
- if (condition === '*') {
2146
- return compoundCss;
2147
- }
2148
- return `@media${queryRule}{${compoundCss}}`;
2149
- }
2150
- const nextRule = toMediaQueryRule(nextCondition);
2151
- if (condition === '*') {
2152
- return `@media not ${nextRule}{${compoundCss}}`;
2153
- }
2154
- return `@media${queryRule} and (not ${nextRule}){${compoundCss}}`;
2155
- };
2156
-
2157
2104
  const detachExperienceStyles = (experience) => {
2158
2105
  const experienceTreeRoot = experience.entityStore?.experienceEntryFields
2159
2106
  ?.componentTree;
@@ -2250,7 +2197,7 @@ const detachExperienceStyles = (experience) => {
2250
2197
  const isAnyVisibilityValueHidden = Object.values(propsByBreakpoint).some((designProperties) => designProperties.cfVisibility === false);
2251
2198
  // We always need an explicit value when using disjunct media queries
2252
2199
  // Example: desktop uses "false" and tablet is undefined -> we need to set `display: none` for tablet as well.
2253
- let previousVisibilityValue;
2200
+ let previousVisibilityValue = undefined;
2254
2201
  /* [Data format] `propsByBreakpoint` is a map of "breakpointId > propertyName > plainValue":
2255
2202
  * {
2256
2203
  * desktop: {
@@ -2264,7 +2211,7 @@ const detachExperienceStyles = (experience) => {
2264
2211
  const currentNodeClassNames = [];
2265
2212
  // Chain IDs to avoid overwriting styles across multiple instances of the same pattern
2266
2213
  // e.g. `{outerPatternNodeId}{innerPatternNodeId}-{currentNodeId}`
2267
- // (!) Notice that the chain of patterns (before the dash) follows the format of prebinding/ patternProperties
2214
+ // (!) Notice that the chain of patterns (before the dash) follows the format of prebinding/ parameters
2268
2215
  const currentNodeIdsChain = `${wrappingPatternNodeIds.join('')}-${currentNode.id}`;
2269
2216
  // For each breakpoint, resolve design tokens, create the CSS and generate a unique className.
2270
2217
  for (const breakpointId of breakpointIds) {
@@ -2361,7 +2308,7 @@ const detachExperienceStyles = (experience) => {
2361
2308
  });
2362
2309
  // once the whole tree was traversed, for each breakpoint, I aggregate the styles
2363
2310
  // for each generated className into one css string
2364
- const stylesheet = Object.values(mediaQueryDataByBreakpoint).reduce((acc, { condition, cssByClassName, visibilityCssByClassName }, index) => {
2311
+ return Object.values(mediaQueryDataByBreakpoint).reduce((acc, { condition, cssByClassName, visibilityCssByClassName }, index) => {
2365
2312
  const mediaQueryCss = toMediaQuery({ cssByClassName, condition });
2366
2313
  // Handle visibility separately to use disjunct media queries ("if desktop but not tablet ...")
2367
2314
  // Enables to hide on one breakpoint but render any unknown custom `display` value on another breakpoint.
@@ -2373,7 +2320,6 @@ const detachExperienceStyles = (experience) => {
2373
2320
  });
2374
2321
  return `${acc}${mediaQueryCss}${visibilityMediaQueryCss}`;
2375
2322
  }, '');
2376
- return stylesheet;
2377
2323
  };
2378
2324
  /**
2379
2325
  * Rendering pattern nodes inside pattern entry by injecting default values from the top:
@@ -2382,7 +2328,7 @@ const detachExperienceStyles = (experience) => {
2382
2328
  */
2383
2329
  const injectDefaultValuesForComponentValues = ({ patternNode, wrapperComponentSettings, }) => {
2384
2330
  const propertyDefinitions = wrapperComponentSettings?.variableDefinitions;
2385
- const resolvedProperties = Object.entries(patternNode.variables).reduce((resolvedProperties, [propertyName, propertyValue]) => {
2331
+ return Object.entries(patternNode.variables).reduce((resolvedProperties, [propertyName, propertyValue]) => {
2386
2332
  if (propertyValue.type === 'ComponentValue') {
2387
2333
  const componentValueKey = propertyValue.key;
2388
2334
  const componentDefaultValue = propertyDefinitions?.[componentValueKey].defaultValue;
@@ -2397,7 +2343,6 @@ const injectDefaultValuesForComponentValues = ({ patternNode, wrapperComponentSe
2397
2343
  }
2398
2344
  return resolvedProperties;
2399
2345
  }, {});
2400
- return resolvedProperties;
2401
2346
  };
2402
2347
  /**
2403
2348
  * In case of nested patterns, we need to resolve the ComponentValue properties and overwrite them with the value
@@ -2411,17 +2356,16 @@ const resolveComponentVariablesOverwrites = ({ patternNode, wrapperComponentVari
2411
2356
  // In case of rendering a pattern entry, there are no custom ComponentValues.
2412
2357
  // So we pass down the default values from this pattern node down to each deeper pattern level.
2413
2358
  if (!wrapperComponentVariablesOverwrites) {
2414
- const nextComponentVariablesOverwrites = injectDefaultValuesForComponentValues({
2359
+ return injectDefaultValuesForComponentValues({
2415
2360
  patternNode,
2416
2361
  wrapperComponentSettings,
2417
2362
  });
2418
- return nextComponentVariablesOverwrites;
2419
2363
  }
2420
2364
  // Rendering (nested) pattern node inside another pattern node (for both experience & pattern entry):
2421
2365
  // The `wrapperComponentVariablesOverwrites` from the top-most pattern node is passed through to each child
2422
2366
  // node (and nested pattern nodes). It replaces each ComponentValue in the subtree with either the overwrite
2423
2367
  // or the default value.
2424
- const nextComponentVariablesOverwrites = Object.entries(patternNode?.variables).reduce((resolvedValues, [propertyName, propertyValue]) => {
2368
+ return Object.entries(patternNode?.variables).reduce((resolvedValues, [propertyName, propertyValue]) => {
2425
2369
  if (propertyValue.type === 'ComponentValue') {
2426
2370
  // Copying the values from the parent node
2427
2371
  const overwritingValue = wrapperComponentVariablesOverwrites?.[propertyValue.key];
@@ -2437,7 +2381,6 @@ const resolveComponentVariablesOverwrites = ({ patternNode, wrapperComponentVari
2437
2381
  }
2438
2382
  return resolvedValues;
2439
2383
  }, {});
2440
- return nextComponentVariablesOverwrites;
2441
2384
  };
2442
2385
  const isCfStyleAttribute = (variableName) => {
2443
2386
  return CF_STYLE_ATTRIBUTES.includes(variableName);
@@ -2495,8 +2438,7 @@ const transformMedia$1 = (boundAsset, width, options) => {
2495
2438
  const targetValue = targetWidthObject ? getTargetValueInPixels(targetWidthObject) : assetWidth;
2496
2439
  if (targetValue < assetWidth)
2497
2440
  width = `${targetValue}px`;
2498
- const value = getOptimizedBackgroundImageAsset(asset.fields.file, width, options.quality, options.format);
2499
- return value;
2441
+ return getOptimizedBackgroundImageAsset(asset.fields.file, width, options.quality, options.format);
2500
2442
  }
2501
2443
  catch (error) {
2502
2444
  console.error('Error transforming image asset', error);
@@ -2717,6 +2659,55 @@ const flattenDesignTokenRegistry = (designTokenRegistry) => {
2717
2659
  }, {});
2718
2660
  };
2719
2661
 
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
+
2720
2711
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2721
2712
  function get(obj, path) {
2722
2713
  if (!path.length) {
@@ -4161,12 +4152,10 @@ const attachPrebindingDefaultValueAsDataSource = (experienceEntry) => {
4161
4152
  // Only supported for pattern entries since experience entries don't define pattern properties.
4162
4153
  return;
4163
4154
  }
4164
- const patternDefs = experienceEntry.fields.componentSettings?.patternPropertyDefinitions ?? {};
4165
- const defaultPrebinding = Object.values(patternDefs).find((def) => def?.defaultSource)?.defaultSource;
4166
- const { link, type } = defaultPrebinding ?? {};
4167
- if (!link || !type)
4168
- return;
4169
- const id = link.sys?.id;
4155
+ const patternDefs = experienceEntry.fields.componentSettings?.parameterDefinitions ?? {};
4156
+ const defaultPrebinding = Object.values(patternDefs).find((def) => def.defaultValue)?.defaultValue;
4157
+ const [value] = Object.values(defaultPrebinding ?? {});
4158
+ const id = value?.sys?.id;
4170
4159
  if (!id)
4171
4160
  return;
4172
4161
  experienceEntry.fields.dataSource = {
@@ -4174,7 +4163,7 @@ const attachPrebindingDefaultValueAsDataSource = (experienceEntry) => {
4174
4163
  [id]: {
4175
4164
  sys: {
4176
4165
  type: 'Link',
4177
- linkType: type,
4166
+ linkType: 'Entry',
4178
4167
  id,
4179
4168
  },
4180
4169
  },