@contentful/experiences-core 1.26.1-prerelease-20241211T1921-aab05f6.0 → 1.27.0-prerelease-20241213T0010-0475c78.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/entity/EntityStore.d.ts +2 -7
- package/dist/index.js +43 -14
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -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?.
|
|
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
|
-
|
|
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'
|
|
@@ -2023,21 +2024,31 @@ const transformRichText = (entryOrAsset, entityStore, path) => {
|
|
|
2023
2024
|
};
|
|
2024
2025
|
}
|
|
2025
2026
|
if (typeof value === 'object' && value.nodeType === BLOCKS.DOCUMENT) {
|
|
2026
|
-
//resolve any
|
|
2027
|
+
// resolve any links to assets/entries/hyperlinks
|
|
2027
2028
|
const richTextDocument = value;
|
|
2028
|
-
richTextDocument
|
|
2029
|
-
|
|
2030
|
-
node.data.target.sys.type === 'Link') {
|
|
2031
|
-
const entity = entityStore.getEntityFromLink(node.data.target);
|
|
2032
|
-
if (entity) {
|
|
2033
|
-
node.data.target = entity;
|
|
2034
|
-
}
|
|
2035
|
-
}
|
|
2036
|
-
});
|
|
2037
|
-
return value;
|
|
2029
|
+
resolveLinks(richTextDocument, entityStore);
|
|
2030
|
+
return richTextDocument;
|
|
2038
2031
|
}
|
|
2039
2032
|
return undefined;
|
|
2040
2033
|
};
|
|
2034
|
+
const isLinkTarget = (node) => {
|
|
2035
|
+
return node?.data?.target?.sys?.type === 'Link';
|
|
2036
|
+
};
|
|
2037
|
+
const resolveLinks = (node, entityStore) => {
|
|
2038
|
+
if (!node)
|
|
2039
|
+
return;
|
|
2040
|
+
// Resolve link if current node has one
|
|
2041
|
+
if (isLinkTarget(node)) {
|
|
2042
|
+
const entity = entityStore.getEntityFromLink(node.data.target);
|
|
2043
|
+
if (entity) {
|
|
2044
|
+
node.data.target = entity;
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
// Process content array if it exists
|
|
2048
|
+
if ('content' in node && Array.isArray(node.content)) {
|
|
2049
|
+
node.content.forEach((childNode) => resolveLinks(childNode, entityStore));
|
|
2050
|
+
}
|
|
2051
|
+
};
|
|
2041
2052
|
|
|
2042
2053
|
function getOptimizedImageUrl(url, width, quality, format) {
|
|
2043
2054
|
if (url.startsWith('//')) {
|
|
@@ -3114,6 +3125,21 @@ class EditorModeEntityStore extends EditorEntityStore {
|
|
|
3114
3125
|
}
|
|
3115
3126
|
}
|
|
3116
3127
|
|
|
3128
|
+
const gatherUsedComponentsWithDeepRefernces = (experienceEntryFields) => {
|
|
3129
|
+
const usedComponentDeepReferences = [];
|
|
3130
|
+
const usedComponents = experienceEntryFields?.usedComponents;
|
|
3131
|
+
if (!usedComponents || usedComponents.length === 0) {
|
|
3132
|
+
return [];
|
|
3133
|
+
}
|
|
3134
|
+
for (const component of usedComponents) {
|
|
3135
|
+
if ('fields' in component) {
|
|
3136
|
+
usedComponentDeepReferences.push(component);
|
|
3137
|
+
usedComponentDeepReferences.push(...gatherUsedComponentsWithDeepRefernces(component.fields));
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
return usedComponentDeepReferences;
|
|
3141
|
+
};
|
|
3142
|
+
|
|
3117
3143
|
class EntityStore extends EntityStoreBase {
|
|
3118
3144
|
constructor(options) {
|
|
3119
3145
|
if (typeof options === 'string') {
|
|
@@ -3128,6 +3154,7 @@ class EntityStore extends EntityStoreBase {
|
|
|
3128
3154
|
});
|
|
3129
3155
|
this._experienceEntry = _experienceEntry;
|
|
3130
3156
|
this._unboundValues = _unboundValues;
|
|
3157
|
+
this._usedComponentsWithDeepReferences = gatherUsedComponentsWithDeepRefernces(this._experienceEntry);
|
|
3131
3158
|
}
|
|
3132
3159
|
else {
|
|
3133
3160
|
const { experienceEntry, entities, locale } = options;
|
|
@@ -3135,6 +3162,7 @@ class EntityStore extends EntityStoreBase {
|
|
|
3135
3162
|
if (isExperienceEntry(experienceEntry)) {
|
|
3136
3163
|
this._experienceEntry = experienceEntry.fields;
|
|
3137
3164
|
this._unboundValues = experienceEntry.fields.unboundValues;
|
|
3165
|
+
this._usedComponentsWithDeepReferences = gatherUsedComponentsWithDeepRefernces(this._experienceEntry);
|
|
3138
3166
|
}
|
|
3139
3167
|
else {
|
|
3140
3168
|
throw new Error('Provided entry is not experience entry');
|
|
@@ -3160,7 +3188,7 @@ class EntityStore extends EntityStoreBase {
|
|
|
3160
3188
|
return this._unboundValues ?? {};
|
|
3161
3189
|
}
|
|
3162
3190
|
get usedComponents() {
|
|
3163
|
-
return this.
|
|
3191
|
+
return this._usedComponentsWithDeepReferences ?? [];
|
|
3164
3192
|
}
|
|
3165
3193
|
/**
|
|
3166
3194
|
* Extend the existing set of unbound values with the ones from the assembly definition.
|
|
@@ -3238,6 +3266,7 @@ const fetchExperienceEntry = async ({ client, experienceTypeId, locale, identifi
|
|
|
3238
3266
|
const entries = await client.getEntries({
|
|
3239
3267
|
content_type: experienceTypeId,
|
|
3240
3268
|
locale,
|
|
3269
|
+
include: 3, // fetching max 3 level deep references due to nested patterns
|
|
3241
3270
|
...filter,
|
|
3242
3271
|
});
|
|
3243
3272
|
if (entries.items.length > 1) {
|