@contentful/experiences-core 1.6.1-prerelease-20240605T1751-661cb0e.0 → 1.7.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.
|
@@ -17,7 +17,6 @@ declare class DeepReference {
|
|
|
17
17
|
/**
|
|
18
18
|
* Extracts referent from the path, using EntityStore as source of
|
|
19
19
|
* entities during the resolution path.
|
|
20
|
-
* TODO: should it be called `extractLeafReferent` ? or `followToLeafReferent`
|
|
21
20
|
*/
|
|
22
21
|
extractReferent(entityStore: EntityStoreBase): Link<'Asset' | 'Entry'> | undefined;
|
|
23
22
|
static from(opt: DeepReferenceOpts): DeepReference;
|
|
@@ -22,7 +22,7 @@ declare class EntityStore extends EntityStoreBase {
|
|
|
22
22
|
displayName: string;
|
|
23
23
|
query: string;
|
|
24
24
|
previewSize: string;
|
|
25
|
-
|
|
25
|
+
displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
|
|
26
26
|
}[];
|
|
27
27
|
get dataSource(): Record<string, {
|
|
28
28
|
sys: {
|
package/dist/index.js
CHANGED
|
@@ -215,7 +215,6 @@ const transformBorderStyle = (value) => {
|
|
|
215
215
|
// Just accept the passed value
|
|
216
216
|
if (parts.length < 3)
|
|
217
217
|
return { border: value };
|
|
218
|
-
// Replace the second part always with `solid` and set the box sizing accordingly
|
|
219
218
|
const [borderSize, borderStyle, ...borderColorParts] = parts;
|
|
220
219
|
const borderColor = borderColorParts.join(' ');
|
|
221
220
|
return {
|
|
@@ -1194,13 +1193,31 @@ const columnsBuiltInStyles = {
|
|
|
1194
1193
|
};
|
|
1195
1194
|
|
|
1196
1195
|
let designTokensRegistry = {};
|
|
1196
|
+
// This function is used to ensure that the composite values are valid since composite values are optional.
|
|
1197
|
+
// Therefore only border and in the future text related design tokens are/will be checked in this funciton.
|
|
1198
|
+
// Ensuring values for simple key-value design tokens are not neccessary since they are required via typescript.
|
|
1199
|
+
const ensureValidCompositeValues = (designTokenDefinition) => {
|
|
1200
|
+
// TODO: add validation logic when text related design tokens are added
|
|
1201
|
+
// Border validation
|
|
1202
|
+
if (designTokenDefinition.border) {
|
|
1203
|
+
for (const borderKey in designTokenDefinition.border) {
|
|
1204
|
+
const borderValue = designTokenDefinition.border[borderKey];
|
|
1205
|
+
designTokenDefinition.border[borderKey] = {
|
|
1206
|
+
width: borderValue.width || '1px',
|
|
1207
|
+
style: borderValue.style || 'solid',
|
|
1208
|
+
color: borderValue.color || '#000000',
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
return designTokenDefinition;
|
|
1213
|
+
};
|
|
1197
1214
|
/**
|
|
1198
1215
|
* Register design tokens styling
|
|
1199
1216
|
* @param designTokenDefinition - {[key:string]: Record<string, string>}
|
|
1200
1217
|
* @returns void
|
|
1201
1218
|
*/
|
|
1202
1219
|
const defineDesignTokens = (designTokenDefinition) => {
|
|
1203
|
-
Object.assign(designTokensRegistry, designTokenDefinition);
|
|
1220
|
+
Object.assign(designTokensRegistry, ensureValidCompositeValues(designTokenDefinition));
|
|
1204
1221
|
};
|
|
1205
1222
|
const templateStringRegex = /\${(.+?)}/g;
|
|
1206
1223
|
const getDesignTokenRegistration = (breakpointValue, variableName) => {
|
|
@@ -1344,7 +1361,7 @@ const BreakpointSchema = z
|
|
|
1344
1361
|
query: z.string().regex(/^\*$|^<[0-9*]+px$/),
|
|
1345
1362
|
previewSize: z.string(),
|
|
1346
1363
|
displayName: z.string(),
|
|
1347
|
-
|
|
1364
|
+
displayIcon: z.enum(['desktop', 'tablet', 'mobile']).optional(),
|
|
1348
1365
|
})
|
|
1349
1366
|
.strict();
|
|
1350
1367
|
const UnboundValuesSchema = z.record(uuidKeySchema, z.object({
|
|
@@ -2500,11 +2517,10 @@ class DeepReference {
|
|
|
2500
2517
|
/**
|
|
2501
2518
|
* Extracts referent from the path, using EntityStore as source of
|
|
2502
2519
|
* entities during the resolution path.
|
|
2503
|
-
* TODO: should it be called `extractLeafReferent` ? or `followToLeafReferent`
|
|
2504
2520
|
*/
|
|
2505
2521
|
extractReferent(entityStore) {
|
|
2506
2522
|
const headEntity = entityStore.getEntityFromLink(this.entityLink);
|
|
2507
|
-
const maybeReferentLink = headEntity
|
|
2523
|
+
const maybeReferentLink = headEntity?.fields[this.field];
|
|
2508
2524
|
if (undefined === maybeReferentLink) {
|
|
2509
2525
|
// field references nothing (or even field doesn't exist)
|
|
2510
2526
|
return undefined;
|
|
@@ -2593,27 +2609,20 @@ function gatherAutoFetchedReferentsFromIncludes(deepReferences, entriesResponse)
|
|
|
2593
2609
|
console.debug(`[experiences-sdk-react::gatherAutoFetchedReferentsFromIncludes] Non-link value in headEntity. Probably broken path '${reference.originalPath}'`);
|
|
2594
2610
|
continue;
|
|
2595
2611
|
}
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
if (!referentEntry) {
|
|
2599
|
-
throw new Error(`Logic Error: L2-referent Entry was not found within .includes (${JSON.stringify({
|
|
2600
|
-
linkToReferent,
|
|
2601
|
-
})})`);
|
|
2602
|
-
}
|
|
2603
|
-
autoFetchedReferentEntries.push(referentEntry);
|
|
2604
|
-
}
|
|
2605
|
-
else if (linkToReferent.sys.linkType === 'Asset') {
|
|
2606
|
-
const referentAsset = entriesResponse.includes?.Asset?.find((entry) => entry.sys.id === linkToReferent.sys.id);
|
|
2607
|
-
if (!referentAsset) {
|
|
2608
|
-
throw new Error(`Logic Error: L2-referent Asset was not found within includes (${JSON.stringify({
|
|
2609
|
-
linkToReferent,
|
|
2610
|
-
})})`);
|
|
2611
|
-
}
|
|
2612
|
-
autoFetchedReferentAssets.push(referentAsset);
|
|
2613
|
-
}
|
|
2614
|
-
else {
|
|
2612
|
+
const linkType = linkToReferent.sys.linkType;
|
|
2613
|
+
if (!['Entry', 'Asset'].includes(linkType)) {
|
|
2615
2614
|
console.debug(`[experiences-sdk-react::gatherAutoFetchedReferentsFromIncludes] Unhandled linkType :${JSON.stringify(linkToReferent)}`);
|
|
2615
|
+
continue;
|
|
2616
|
+
}
|
|
2617
|
+
const referentEntity = entriesResponse.includes?.[linkType]?.find((entity) => entity.sys.id === linkToReferent.sys.id);
|
|
2618
|
+
if (!referentEntity) {
|
|
2619
|
+
throw new Error(`Logic Error: L2-referent ${linkType} was not found within .includes (${JSON.stringify({
|
|
2620
|
+
linkToReferent,
|
|
2621
|
+
})})`);
|
|
2616
2622
|
}
|
|
2623
|
+
linkType === 'Entry'
|
|
2624
|
+
? autoFetchedReferentEntries.push(referentEntity)
|
|
2625
|
+
: autoFetchedReferentAssets.push(referentEntity);
|
|
2617
2626
|
} // for (reference of deepReferences)
|
|
2618
2627
|
return { autoFetchedReferentAssets, autoFetchedReferentEntries };
|
|
2619
2628
|
}
|
|
@@ -2750,10 +2759,10 @@ const fetchReferencedEntities = async ({ client, experienceEntry, locale, }) =>
|
|
|
2750
2759
|
assetIds.push(dataBinding.sys.id);
|
|
2751
2760
|
}
|
|
2752
2761
|
}
|
|
2753
|
-
const [entriesResponse, assetsResponse] =
|
|
2762
|
+
const [entriesResponse, assetsResponse] = await Promise.all([
|
|
2754
2763
|
fetchAllEntries({ client, ids: entryIds, locale }),
|
|
2755
2764
|
fetchAllAssets({ client, ids: assetIds, locale }),
|
|
2756
|
-
])
|
|
2765
|
+
]);
|
|
2757
2766
|
const { autoFetchedReferentAssets, autoFetchedReferentEntries } = gatherAutoFetchedReferentsFromIncludes(deepReferences, entriesResponse);
|
|
2758
2767
|
// Using client getEntries resolves all linked entry references, so we do not need to resolve entries in usedComponents
|
|
2759
2768
|
const allResolvedEntries = [
|