@contentful/experiences-core 3.8.0-dev-20250926T1440-9676290.0 → 3.8.0-dev-20250929T1202-cb99bde.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,
@@ -1998,6 +1997,9 @@ const getPrebindingPathBySourceEntry = (preboundValueProperty, getHeadEntityByDa
1998
1997
  return undefined;
1999
1998
  }
2000
1999
  const contentTypeId = headEntity.sys.contentType.sys.id;
2000
+ if (!preboundValueProperty.pathsByContentType?.[contentTypeId]) {
2001
+ return undefined;
2002
+ }
2001
2003
  return preboundValueProperty.pathsByContentType?.[contentTypeId]?.path;
2002
2004
  };
2003
2005
  const parseDeepPath = (deepPathCandidate) => {
@@ -2421,6 +2423,7 @@ const detachExperienceStyles = (experience) => {
2421
2423
  if (!experienceTreeRoot) {
2422
2424
  return;
2423
2425
  }
2426
+ const isRenderingAPatternEntry = experience.entityStore?.isExperienceAPatternEntry;
2424
2427
  const mapOfDesignVariableKeys = flattenDesignTokenRegistry(designTokensRegistry);
2425
2428
  // getting breakpoints from the entry componentTree field
2426
2429
  const { breakpoints } = experienceTreeRoot;
@@ -2435,7 +2438,7 @@ const detachExperienceStyles = (experience) => {
2435
2438
  }), {});
2436
2439
  // getting the breakpoint ids
2437
2440
  const breakpointIds = Object.keys(mediaQueryDataByBreakpoint);
2438
- const iterateOverTreeAndExtractStyles = ({ componentTree, dataSource, unboundValues, componentSettings, componentVariablesOverwrites, patternWrapper, wrappingPatternIds, wrappingPatternNodeIds = [], }) => {
2441
+ const iterateOverTreeAndExtractStyles = ({ componentTree, dataSource, unboundValues, componentSettings, componentVariablesOverwrites, patternWrapper, wrappingPatternIds, wrappingPatternNodeIds = isRenderingAPatternEntry ? ['root'] : [], }) => {
2439
2442
  // traversing the tree
2440
2443
  const queue = [];
2441
2444
  queue.push(...componentTree.children);
@@ -2526,7 +2529,7 @@ const detachExperienceStyles = (experience) => {
2526
2529
  // Chain IDs to avoid overwriting styles across multiple instances of the same pattern
2527
2530
  // e.g. `{outerPatternNodeId}{innerPatternNodeId}-{currentNodeId}`
2528
2531
  // (!) Notice that the chain of patterns (before the dash) follows the format of prebinding/ parameters
2529
- const currentNodeIdsChain = `${wrappingPatternNodeIds.join('')}-${currentNode.id}`;
2532
+ const currentNodeIdsChain = [...wrappingPatternNodeIds, currentNode.id].join('-');
2530
2533
  // For each breakpoint, resolve design tokens, create the CSS and generate a unique className.
2531
2534
  for (const breakpointId of breakpointIds) {
2532
2535
  const propsByBreakpointWithResolvedDesignTokens = Object.entries(propsByBreakpoint[breakpointId]).reduce((acc, [variableName, variableValue]) => {
@@ -3701,7 +3704,7 @@ const generateDefaultDataSourceForPrebindingDefinition = (prebindingDefinitions
3701
3704
  const parameters = {};
3702
3705
  for (const [parameterId, parameterDefinition] of Object.entries(prebindingDefinition.parameterDefinitions ?? {})) {
3703
3706
  if (parameterDefinition.defaultSource && isLink(parameterDefinition.defaultSource.link)) {
3704
- const dataSourceKey = generateRandomId(7);
3707
+ const dataSourceKey = parameterDefinition.defaultSource.link.sys.id;
3705
3708
  dataSource[dataSourceKey] = parameterDefinition.defaultSource.link;
3706
3709
  parameters[parameterId] = {
3707
3710
  type: 'BoundValue',
@@ -4242,6 +4245,9 @@ class EntityStore extends EntityStoreBase {
4242
4245
  this._experienceEntryId = experienceEntry.sys.id;
4243
4246
  this._unboundValues = experienceEntry.fields.unboundValues;
4244
4247
  }
4248
+ this._isExperienceAPatternEntry = checkIsAssemblyEntry({
4249
+ fields: this._experienceEntryFields,
4250
+ });
4245
4251
  // DERIVE ENTITY STORE INSTANCE VARIBLES
4246
4252
  // Register prebindings
4247
4253
  {
@@ -4325,6 +4331,9 @@ class EntityStore extends EntityStoreBase {
4325
4331
  getCurrentLocale() {
4326
4332
  return this.locale;
4327
4333
  }
4334
+ get isExperienceAPatternEntry() {
4335
+ return this._isExperienceAPatternEntry;
4336
+ }
4328
4337
  get hoistedVariableMappings() {
4329
4338
  return this._hoistedVariableMappings;
4330
4339
  }
@@ -5037,92 +5046,6 @@ const removeSelfReferencingDataSource = (experienceEntry) => {
5037
5046
  experienceEntry.fields.dataSource = newDataSource;
5038
5047
  };
5039
5048
 
5040
- /**
5041
- * Attaches the default prebinding value (if any) to the experience entry's dataSource.
5042
- *
5043
- * This ensures that any default values defined in pattern property definitions are included
5044
- * in the dataSource, so that linked entities can be fetched and resolved correctly.
5045
- * Without this, defaults may be omitted, resulting in unresolved references during binding.
5046
- *
5047
- * @returns The number of sideloaded default values, or false if the entry is not a pattern.
5048
- */
5049
- const sideloadPrebindingDefaultValues = (patternEntry) => {
5050
- let sideloadedCount = 0;
5051
- const addDefaultValueToDataSource = (_definitionId, definition) => {
5052
- if (!definition.defaultSource) {
5053
- // prebinding preset doesn't have default value, which is perfectly fine
5054
- return;
5055
- }
5056
- 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.
5057
- // this .type enumeration will not have the same meaning as `Link#sys#linkType`.
5058
- } = definition.defaultSource;
5059
- if (!isLink(link)) {
5060
- // default value is not a link, maybe due to a bug
5061
- return;
5062
- }
5063
- if (!type || !contentTypeId) {
5064
- // broken data structure, unlikely to happen, only due to a bug
5065
- return;
5066
- }
5067
- // Throw in the link to the default-entry into the dataSource, this way
5068
- // we rely on the mechanism of fetchReferencedEntities() to "sideload" them.
5069
- // Keep in mind that dataSource will be available as EntityStore.dataSource
5070
- // and now will contain also key for `sideloaded_uuid` entry.
5071
- // When "sideloading" entries into the entityStore, we must ensure that
5072
- // there's corresponding entry in the dataSource, because all bound variables
5073
- // are resolved, via path that is indirectly referencing the dataSource,
5074
- // eg. { type: 'BoundValue', path: '/sideloaded_uuid/fields/title' }
5075
- patternEntry.fields.dataSource = {
5076
- ...patternEntry.fields.dataSource,
5077
- [`${SIDELOADED_PREFIX}${link.sys.id}`]: {
5078
- // to highlight that this is a sideloaded entry, we prefix it
5079
- sys: {
5080
- type: 'Link',
5081
- linkType: link.sys.linkType,
5082
- id: link.sys.id,
5083
- },
5084
- },
5085
- };
5086
- sideloadedCount++;
5087
- };
5088
- if (!checkIsAssemblyEntry(patternEntry)) {
5089
- // Only supported for pattern entries since experience entries don't define pattern properties.
5090
- return false;
5091
- }
5092
- // --------------------
5093
- // Sideload prebinding values for the L1 parent pattern aka `pA`
5094
- // --------------------
5095
- const definitions = patternEntry.fields.componentSettings?.prebindingDefinitions?.[0].parameterDefinitions ?? {};
5096
- Object.entries(definitions).forEach(([id, definition]) => {
5097
- addDefaultValueToDataSource(id, definition);
5098
- });
5099
- // --------------------
5100
- // Sideload all default values for the L2 nested patterns, patterns aka`pB`
5101
- // --------------------
5102
- const nestedPatternEntriesLevel2 = (patternEntry.fields.usedComponents || []).filter((component) => component !== undefined && checkIsAssemblyEntry(component));
5103
- nestedPatternEntriesLevel2.forEach((patternEntry) => {
5104
- const parameterDefinitions = patternEntry.fields.componentSettings?.prebindingDefinitions?.[0].parameterDefinitions ?? {};
5105
- Object.entries(parameterDefinitions).forEach(([id, definition]) => {
5106
- addDefaultValueToDataSource(id, definition);
5107
- });
5108
- });
5109
- // --------------------
5110
- // Sideload all default values for the L3 nested patterns, patterns aka `pC`
5111
- // --------------------
5112
- const nestedPatternEntriesLevel3 = nestedPatternEntriesLevel2.flatMap((patternEntryLevel2) => {
5113
- const usedComponents = patternEntryLevel2.fields.usedComponents || [];
5114
- const filteredUsedComponents = usedComponents.filter((component) => component !== undefined && checkIsAssemblyEntry(component));
5115
- return filteredUsedComponents;
5116
- });
5117
- nestedPatternEntriesLevel3.forEach((patternEntry) => {
5118
- const parameterDefinitions = patternEntry.fields.componentSettings?.prebindingDefinitions?.[0].parameterDefinitions ?? {};
5119
- Object.entries(parameterDefinitions).forEach(([id, definition]) => {
5120
- addDefaultValueToDataSource(id, definition);
5121
- });
5122
- });
5123
- return sideloadedCount;
5124
- };
5125
-
5126
5049
  /**
5127
5050
  * Run additional checks on the references used in the experience entry and
5128
5051
  * process data required for prebinding. This must be used after fetching an
@@ -5133,7 +5056,6 @@ const sideloadPrebindingDefaultValues = (patternEntry) => {
5133
5056
  const prepareExperienceEntry = (experienceEntry) => {
5134
5057
  removeCircularPatternReferences(experienceEntry);
5135
5058
  removeSelfReferencingDataSource(experienceEntry);
5136
- sideloadPrebindingDefaultValues(experienceEntry);
5137
5059
  };
5138
5060
 
5139
5061
  const errorMessagesWhileFetching$1 = {