@contentful/experiences-core 1.26.1-dev-20241211T2213-315389a.0 → 1.27.0-beta.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.
@@ -12,6 +12,7 @@ type EntityStoreArgs = {
12
12
  declare class EntityStore extends EntityStoreBase {
13
13
  private _experienceEntry;
14
14
  private _unboundValues;
15
+ private _usedComponentsWithDeepReferences;
15
16
  constructor(json: string);
16
17
  constructor({ experienceEntry, entities, locale }: EntityStoreArgs);
17
18
  getCurrentLocale(): string;
@@ -34,13 +35,7 @@ declare class EntityStore extends EntityStoreBase {
34
35
  get unboundValues(): Record<string, {
35
36
  value?: string | number | boolean | Record<any, any> | undefined;
36
37
  }>;
37
- get usedComponents(): {
38
- sys: {
39
- type: "Link";
40
- id: string;
41
- linkType: "Entry";
42
- };
43
- }[] | ExperienceEntry[];
38
+ get usedComponents(): ExperienceEntry[];
44
39
  /**
45
40
  * Extend the existing set of unbound values with the ones from the assembly definition.
46
41
  * When creating a new assembly out of a container, the unbound value keys are copied and
package/dist/index.js CHANGED
@@ -1560,7 +1560,7 @@ const detachExperienceStyles = (experience) => {
1560
1560
  if (!currentNode) {
1561
1561
  break;
1562
1562
  }
1563
- const usedComponents = experience.entityStore?.experienceEntryFields?.usedComponents ?? [];
1563
+ const usedComponents = experience.entityStore?.usedComponents ?? [];
1564
1564
  const isPatternNode = checkIsAssemblyNode({
1565
1565
  componentId: currentNode.definitionId,
1566
1566
  usedComponents,
@@ -1825,7 +1825,8 @@ const resolveBackgroundImageBinding = ({ variableData, getBoundEntityById, dataS
1825
1825
  const defaultValueKey = variableDefinition.defaultValue?.key;
1826
1826
  const defaultValue = unboundValues[defaultValueKey].value;
1827
1827
  const userSetValue = componentVariablesOverwrites?.[variableDefinitionKey];
1828
- if (!userSetValue) {
1828
+ // userSetValue is a ComponentValue we can safely return the default value
1829
+ if (!userSetValue || userSetValue.type === 'ComponentValue') {
1829
1830
  return defaultValue;
1830
1831
  }
1831
1832
  // at this point userSetValue will either be type of 'DesignValue' or 'BoundValue'
@@ -3114,6 +3115,21 @@ class EditorModeEntityStore extends EditorEntityStore {
3114
3115
  }
3115
3116
  }
3116
3117
 
3118
+ const gatherUsedComponentsWithDeepRefernces = (experienceEntryFields) => {
3119
+ const usedComponentDeepReferences = [];
3120
+ const usedComponents = experienceEntryFields?.usedComponents;
3121
+ if (!usedComponents || usedComponents.length === 0) {
3122
+ return [];
3123
+ }
3124
+ for (const component of usedComponents) {
3125
+ if ('fields' in component) {
3126
+ usedComponentDeepReferences.push(component);
3127
+ usedComponentDeepReferences.push(...gatherUsedComponentsWithDeepRefernces(component.fields));
3128
+ }
3129
+ }
3130
+ return usedComponentDeepReferences;
3131
+ };
3132
+
3117
3133
  class EntityStore extends EntityStoreBase {
3118
3134
  constructor(options) {
3119
3135
  if (typeof options === 'string') {
@@ -3128,6 +3144,7 @@ class EntityStore extends EntityStoreBase {
3128
3144
  });
3129
3145
  this._experienceEntry = _experienceEntry;
3130
3146
  this._unboundValues = _unboundValues;
3147
+ this._usedComponentsWithDeepReferences = gatherUsedComponentsWithDeepRefernces(this._experienceEntry);
3131
3148
  }
3132
3149
  else {
3133
3150
  const { experienceEntry, entities, locale } = options;
@@ -3135,6 +3152,7 @@ class EntityStore extends EntityStoreBase {
3135
3152
  if (isExperienceEntry(experienceEntry)) {
3136
3153
  this._experienceEntry = experienceEntry.fields;
3137
3154
  this._unboundValues = experienceEntry.fields.unboundValues;
3155
+ this._usedComponentsWithDeepReferences = gatherUsedComponentsWithDeepRefernces(this._experienceEntry);
3138
3156
  }
3139
3157
  else {
3140
3158
  throw new Error('Provided entry is not experience entry');
@@ -3160,7 +3178,7 @@ class EntityStore extends EntityStoreBase {
3160
3178
  return this._unboundValues ?? {};
3161
3179
  }
3162
3180
  get usedComponents() {
3163
- return this._experienceEntry?.usedComponents ?? [];
3181
+ return this._usedComponentsWithDeepReferences ?? [];
3164
3182
  }
3165
3183
  /**
3166
3184
  * Extend the existing set of unbound values with the ones from the assembly definition.
@@ -3238,6 +3256,7 @@ const fetchExperienceEntry = async ({ client, experienceTypeId, locale, identifi
3238
3256
  const entries = await client.getEntries({
3239
3257
  content_type: experienceTypeId,
3240
3258
  locale,
3259
+ include: 3, // fetching max 3 level deep references due to nested patterns
3241
3260
  ...filter,
3242
3261
  });
3243
3262
  if (entries.items.length > 1) {