@contentful/experiences-core 3.8.0-dev-20250925T1014-c658e71.0 → 3.8.0-dev-20250926T1559-e1ab24d.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/index.js CHANGED
@@ -135,7 +135,6 @@ var PostMessageMethods;
135
135
  PostMessageMethods["REQUESTED_ENTITIES"] = "REQUESTED_ENTITIES";
136
136
  })(PostMessageMethods || (PostMessageMethods = {}));
137
137
  const SUPPORTED_IMAGE_FORMATS = ['jpg', 'png', 'webp', 'gif', 'avif'];
138
- const SIDELOADED_PREFIX = 'sideloaded_';
139
138
 
140
139
  const structureComponentIds = new Set([
141
140
  CONTENTFUL_COMPONENTS.section.id,
@@ -988,6 +987,16 @@ const ComponentVariableSchema = z.object({
988
987
  });
989
988
  const ComponentTreeNodeSchema = BaseComponentTreeNodeSchema.extend({
990
989
  children: z.lazy(() => ComponentTreeNodeSchema.array()),
990
+ }).superRefine(({ id, prebindingId, parameters }, ctx) => {
991
+ // We don't fail if parameters are present but prebindingId is not because
992
+ // older experiences (updated before 21-09-2025) always included parameters
993
+ // and they will start failing if we do.
994
+ if (prebindingId && !parameters) {
995
+ ctx.addIssue({
996
+ code: z.ZodIssueCode.custom,
997
+ message: `Found "prebindingId" but no "parameters" for node with id: "${id}"`,
998
+ });
999
+ }
991
1000
  });
992
1001
  const ComponentTreeSchema = z
993
1002
  .object({
@@ -1988,6 +1997,9 @@ const getPrebindingPathBySourceEntry = (preboundValueProperty, getHeadEntityByDa
1988
1997
  return undefined;
1989
1998
  }
1990
1999
  const contentTypeId = headEntity.sys.contentType.sys.id;
2000
+ if (!preboundValueProperty.pathsByContentType?.[contentTypeId]) {
2001
+ return undefined;
2002
+ }
1991
2003
  return preboundValueProperty.pathsByContentType?.[contentTypeId]?.path;
1992
2004
  };
1993
2005
  const parseDeepPath = (deepPathCandidate) => {
@@ -2411,6 +2423,7 @@ const detachExperienceStyles = (experience) => {
2411
2423
  if (!experienceTreeRoot) {
2412
2424
  return;
2413
2425
  }
2426
+ const isRenderingAPatternEntry = experience.entityStore?.isExperienceAPatternEntry;
2414
2427
  const mapOfDesignVariableKeys = flattenDesignTokenRegistry(designTokensRegistry);
2415
2428
  // getting breakpoints from the entry componentTree field
2416
2429
  const { breakpoints } = experienceTreeRoot;
@@ -2425,7 +2438,7 @@ const detachExperienceStyles = (experience) => {
2425
2438
  }), {});
2426
2439
  // getting the breakpoint ids
2427
2440
  const breakpointIds = Object.keys(mediaQueryDataByBreakpoint);
2428
- const iterateOverTreeAndExtractStyles = ({ componentTree, dataSource, unboundValues, componentSettings, componentVariablesOverwrites, patternWrapper, wrappingPatternIds, wrappingPatternNodeIds = [], }) => {
2441
+ const iterateOverTreeAndExtractStyles = ({ componentTree, dataSource, unboundValues, componentSettings, componentVariablesOverwrites, patternWrapper, wrappingPatternIds, wrappingPatternNodeIds = isRenderingAPatternEntry ? ['root'] : [], }) => {
2429
2442
  // traversing the tree
2430
2443
  const queue = [];
2431
2444
  queue.push(...componentTree.children);
@@ -2516,7 +2529,7 @@ const detachExperienceStyles = (experience) => {
2516
2529
  // Chain IDs to avoid overwriting styles across multiple instances of the same pattern
2517
2530
  // e.g. `{outerPatternNodeId}{innerPatternNodeId}-{currentNodeId}`
2518
2531
  // (!) Notice that the chain of patterns (before the dash) follows the format of prebinding/ parameters
2519
- const currentNodeIdsChain = `${wrappingPatternNodeIds.join('')}-${currentNode.id}`;
2532
+ const currentNodeIdsChain = [...wrappingPatternNodeIds, currentNode.id].join('-');
2520
2533
  // For each breakpoint, resolve design tokens, create the CSS and generate a unique className.
2521
2534
  for (const breakpointId of breakpointIds) {
2522
2535
  const propsByBreakpointWithResolvedDesignTokens = Object.entries(propsByBreakpoint[breakpointId]).reduce((acc, [variableName, variableValue]) => {
@@ -3691,7 +3704,7 @@ const generateDefaultDataSourceForPrebindingDefinition = (prebindingDefinitions
3691
3704
  const parameters = {};
3692
3705
  for (const [parameterId, parameterDefinition] of Object.entries(prebindingDefinition.parameterDefinitions ?? {})) {
3693
3706
  if (parameterDefinition.defaultSource && isLink(parameterDefinition.defaultSource.link)) {
3694
- const dataSourceKey = generateRandomId(7);
3707
+ const dataSourceKey = parameterDefinition.defaultSource.link.sys.id;
3695
3708
  dataSource[dataSourceKey] = parameterDefinition.defaultSource.link;
3696
3709
  parameters[parameterId] = {
3697
3710
  type: 'BoundValue',
@@ -4232,6 +4245,9 @@ class EntityStore extends EntityStoreBase {
4232
4245
  this._experienceEntryId = experienceEntry.sys.id;
4233
4246
  this._unboundValues = experienceEntry.fields.unboundValues;
4234
4247
  }
4248
+ this._isExperienceAPatternEntry = checkIsAssemblyEntry({
4249
+ fields: this._experienceEntryFields,
4250
+ });
4235
4251
  // DERIVE ENTITY STORE INSTANCE VARIBLES
4236
4252
  // Register prebindings
4237
4253
  {
@@ -4315,6 +4331,9 @@ class EntityStore extends EntityStoreBase {
4315
4331
  getCurrentLocale() {
4316
4332
  return this.locale;
4317
4333
  }
4334
+ get isExperienceAPatternEntry() {
4335
+ return this._isExperienceAPatternEntry;
4336
+ }
4318
4337
  get hoistedVariableMappings() {
4319
4338
  return this._hoistedVariableMappings;
4320
4339
  }
@@ -5027,92 +5046,6 @@ const removeSelfReferencingDataSource = (experienceEntry) => {
5027
5046
  experienceEntry.fields.dataSource = newDataSource;
5028
5047
  };
5029
5048
 
5030
- /**
5031
- * Attaches the default prebinding value (if any) to the experience entry's dataSource.
5032
- *
5033
- * This ensures that any default values defined in pattern property definitions are included
5034
- * in the dataSource, so that linked entities can be fetched and resolved correctly.
5035
- * Without this, defaults may be omitted, resulting in unresolved references during binding.
5036
- *
5037
- * @returns The number of sideloaded default values, or false if the entry is not a pattern.
5038
- */
5039
- const sideloadPrebindingDefaultValues = (patternEntry) => {
5040
- let sideloadedCount = 0;
5041
- const addDefaultValueToDataSource = (_definitionId, definition) => {
5042
- if (!definition.defaultSource) {
5043
- // prebinding preset doesn't have default value, which is perfectly fine
5044
- return;
5045
- }
5046
- const { contentTypeId, link, type, // At the time of writing, it means that defaultSource is a link to a Contentful Entry, but in the future it could be a link to third party resource or smth.
5047
- // this .type enumeration will not have the same meaning as `Link#sys#linkType`.
5048
- } = definition.defaultSource;
5049
- if (!isLink(link)) {
5050
- // default value is not a link, maybe due to a bug
5051
- return;
5052
- }
5053
- if (!type || !contentTypeId) {
5054
- // broken data structure, unlikely to happen, only due to a bug
5055
- return;
5056
- }
5057
- // Throw in the link to the default-entry into the dataSource, this way
5058
- // we rely on the mechanism of fetchReferencedEntities() to "sideload" them.
5059
- // Keep in mind that dataSource will be available as EntityStore.dataSource
5060
- // and now will contain also key for `sideloaded_uuid` entry.
5061
- // When "sideloading" entries into the entityStore, we must ensure that
5062
- // there's corresponding entry in the dataSource, because all bound variables
5063
- // are resolved, via path that is indirectly referencing the dataSource,
5064
- // eg. { type: 'BoundValue', path: '/sideloaded_uuid/fields/title' }
5065
- patternEntry.fields.dataSource = {
5066
- ...patternEntry.fields.dataSource,
5067
- [`${SIDELOADED_PREFIX}${link.sys.id}`]: {
5068
- // to highlight that this is a sideloaded entry, we prefix it
5069
- sys: {
5070
- type: 'Link',
5071
- linkType: link.sys.linkType,
5072
- id: link.sys.id,
5073
- },
5074
- },
5075
- };
5076
- sideloadedCount++;
5077
- };
5078
- if (!checkIsAssemblyEntry(patternEntry)) {
5079
- // Only supported for pattern entries since experience entries don't define pattern properties.
5080
- return false;
5081
- }
5082
- // --------------------
5083
- // Sideload prebinding values for the L1 parent pattern aka `pA`
5084
- // --------------------
5085
- const definitions = patternEntry.fields.componentSettings?.prebindingDefinitions?.[0].parameterDefinitions ?? {};
5086
- Object.entries(definitions).forEach(([id, definition]) => {
5087
- addDefaultValueToDataSource(id, definition);
5088
- });
5089
- // --------------------
5090
- // Sideload all default values for the L2 nested patterns, patterns aka`pB`
5091
- // --------------------
5092
- const nestedPatternEntriesLevel2 = (patternEntry.fields.usedComponents || []).filter((component) => component !== undefined && checkIsAssemblyEntry(component));
5093
- nestedPatternEntriesLevel2.forEach((patternEntry) => {
5094
- const parameterDefinitions = patternEntry.fields.componentSettings?.prebindingDefinitions?.[0].parameterDefinitions ?? {};
5095
- Object.entries(parameterDefinitions).forEach(([id, definition]) => {
5096
- addDefaultValueToDataSource(id, definition);
5097
- });
5098
- });
5099
- // --------------------
5100
- // Sideload all default values for the L3 nested patterns, patterns aka `pC`
5101
- // --------------------
5102
- const nestedPatternEntriesLevel3 = nestedPatternEntriesLevel2.flatMap((patternEntryLevel2) => {
5103
- const usedComponents = patternEntryLevel2.fields.usedComponents || [];
5104
- const filteredUsedComponents = usedComponents.filter((component) => component !== undefined && checkIsAssemblyEntry(component));
5105
- return filteredUsedComponents;
5106
- });
5107
- nestedPatternEntriesLevel3.forEach((patternEntry) => {
5108
- const parameterDefinitions = patternEntry.fields.componentSettings?.prebindingDefinitions?.[0].parameterDefinitions ?? {};
5109
- Object.entries(parameterDefinitions).forEach(([id, definition]) => {
5110
- addDefaultValueToDataSource(id, definition);
5111
- });
5112
- });
5113
- return sideloadedCount;
5114
- };
5115
-
5116
5049
  /**
5117
5050
  * Run additional checks on the references used in the experience entry and
5118
5051
  * process data required for prebinding. This must be used after fetching an
@@ -5123,7 +5056,6 @@ const sideloadPrebindingDefaultValues = (patternEntry) => {
5123
5056
  const prepareExperienceEntry = (experienceEntry) => {
5124
5057
  removeCircularPatternReferences(experienceEntry);
5125
5058
  removeSelfReferencingDataSource(experienceEntry);
5126
- sideloadPrebindingDefaultValues(experienceEntry);
5127
5059
  };
5128
5060
 
5129
5061
  const errorMessagesWhileFetching$1 = {