@contentful/experiences-core 1.6.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.
- package/dist/deep-binding/DeepReference.d.ts +0 -1
- package/dist/entity/EntityStore.d.ts +1 -1
- package/dist/index.js +37 -49
- package/dist/index.js.map +1 -1
- package/dist/registries/breakpointsRegistry.d.ts +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/utils/styleUtils/stylesUtils.d.ts +1 -1
- package/package.json +3 -3
|
@@ -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 {
|
|
@@ -300,27 +299,6 @@ const transformBackgroundImage = (cfBackgroundImageUrl, cfBackgroundImageOptions
|
|
|
300
299
|
backgroundSize: matchBackgroundSize(cfBackgroundImageOptions?.scaling),
|
|
301
300
|
};
|
|
302
301
|
};
|
|
303
|
-
const transformWidthSizing = ({ value, cfMargin, componentId, }) => {
|
|
304
|
-
if (!value || !componentId)
|
|
305
|
-
return;
|
|
306
|
-
const transformedValue = transformFill(value);
|
|
307
|
-
if (isContentfulStructureComponent(componentId)) {
|
|
308
|
-
const marginValues = cfMargin ? cfMargin.split(' ') : [];
|
|
309
|
-
const rightMargin = marginValues[1] || '0px';
|
|
310
|
-
const leftMargin = marginValues[3] || '0px';
|
|
311
|
-
const calcValue = `calc(${transformedValue} - ${leftMargin} - ${rightMargin})`;
|
|
312
|
-
/**
|
|
313
|
-
* We want to check if the calculated value is valid CSS. If this fails,
|
|
314
|
-
* this means the `transformedValue` is not a calculable value (not a px, rem, or %).
|
|
315
|
-
* The value may instead be a string such as `min-content` or `max-content`. In
|
|
316
|
-
* that case we don't want to use calc and instead return the raw value.
|
|
317
|
-
*/
|
|
318
|
-
if (typeof window !== 'undefined' && CSS.supports('width', calcValue)) {
|
|
319
|
-
return calcValue;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
return transformedValue;
|
|
323
|
-
};
|
|
324
302
|
|
|
325
303
|
const toCSSAttribute = (key) => {
|
|
326
304
|
let val = key.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());
|
|
@@ -337,12 +315,12 @@ const buildStyleTag = ({ styles, nodeId }) => {
|
|
|
337
315
|
const styleRule = `.${className}{ ${stylesStr} }`;
|
|
338
316
|
return [className, styleRule];
|
|
339
317
|
};
|
|
340
|
-
const buildCfStyles = ({ cfHorizontalAlignment, cfVerticalAlignment, cfFlexDirection, cfFlexWrap, cfMargin, cfPadding, cfBackgroundColor, cfWidth, cfHeight, cfMaxWidth, cfBorder, cfBorderRadius, cfGap, cfBackgroundImageUrl, cfBackgroundImageOptions, cfFontSize, cfFontWeight, cfImageOptions, cfLineHeight, cfLetterSpacing, cfTextColor, cfTextAlign, cfTextTransform, cfTextBold, cfTextItalic, cfTextUnderline, cfColumnSpan, }
|
|
318
|
+
const buildCfStyles = ({ cfHorizontalAlignment, cfVerticalAlignment, cfFlexDirection, cfFlexWrap, cfMargin, cfPadding, cfBackgroundColor, cfWidth, cfHeight, cfMaxWidth, cfBorder, cfBorderRadius, cfGap, cfBackgroundImageUrl, cfBackgroundImageOptions, cfFontSize, cfFontWeight, cfImageOptions, cfLineHeight, cfLetterSpacing, cfTextColor, cfTextAlign, cfTextTransform, cfTextBold, cfTextItalic, cfTextUnderline, cfColumnSpan, }) => {
|
|
341
319
|
return {
|
|
342
320
|
margin: cfMargin,
|
|
343
321
|
padding: cfPadding,
|
|
344
322
|
backgroundColor: cfBackgroundColor,
|
|
345
|
-
width:
|
|
323
|
+
width: transformFill(cfWidth || cfImageOptions?.width),
|
|
346
324
|
height: transformFill(cfHeight || cfImageOptions?.height),
|
|
347
325
|
maxWidth: cfMaxWidth,
|
|
348
326
|
...transformGridColumn(cfColumnSpan),
|
|
@@ -1215,13 +1193,31 @@ const columnsBuiltInStyles = {
|
|
|
1215
1193
|
};
|
|
1216
1194
|
|
|
1217
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
|
+
};
|
|
1218
1214
|
/**
|
|
1219
1215
|
* Register design tokens styling
|
|
1220
1216
|
* @param designTokenDefinition - {[key:string]: Record<string, string>}
|
|
1221
1217
|
* @returns void
|
|
1222
1218
|
*/
|
|
1223
1219
|
const defineDesignTokens = (designTokenDefinition) => {
|
|
1224
|
-
Object.assign(designTokensRegistry, designTokenDefinition);
|
|
1220
|
+
Object.assign(designTokensRegistry, ensureValidCompositeValues(designTokenDefinition));
|
|
1225
1221
|
};
|
|
1226
1222
|
const templateStringRegex = /\${(.+?)}/g;
|
|
1227
1223
|
const getDesignTokenRegistration = (breakpointValue, variableName) => {
|
|
@@ -1365,7 +1361,7 @@ const BreakpointSchema = z
|
|
|
1365
1361
|
query: z.string().regex(/^\*$|^<[0-9*]+px$/),
|
|
1366
1362
|
previewSize: z.string(),
|
|
1367
1363
|
displayName: z.string(),
|
|
1368
|
-
|
|
1364
|
+
displayIcon: z.enum(['desktop', 'tablet', 'mobile']).optional(),
|
|
1369
1365
|
})
|
|
1370
1366
|
.strict();
|
|
1371
1367
|
const UnboundValuesSchema = z.record(uuidKeySchema, z.object({
|
|
@@ -2521,11 +2517,10 @@ class DeepReference {
|
|
|
2521
2517
|
/**
|
|
2522
2518
|
* Extracts referent from the path, using EntityStore as source of
|
|
2523
2519
|
* entities during the resolution path.
|
|
2524
|
-
* TODO: should it be called `extractLeafReferent` ? or `followToLeafReferent`
|
|
2525
2520
|
*/
|
|
2526
2521
|
extractReferent(entityStore) {
|
|
2527
2522
|
const headEntity = entityStore.getEntityFromLink(this.entityLink);
|
|
2528
|
-
const maybeReferentLink = headEntity
|
|
2523
|
+
const maybeReferentLink = headEntity?.fields[this.field];
|
|
2529
2524
|
if (undefined === maybeReferentLink) {
|
|
2530
2525
|
// field references nothing (or even field doesn't exist)
|
|
2531
2526
|
return undefined;
|
|
@@ -2614,27 +2609,20 @@ function gatherAutoFetchedReferentsFromIncludes(deepReferences, entriesResponse)
|
|
|
2614
2609
|
console.debug(`[experiences-sdk-react::gatherAutoFetchedReferentsFromIncludes] Non-link value in headEntity. Probably broken path '${reference.originalPath}'`);
|
|
2615
2610
|
continue;
|
|
2616
2611
|
}
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
if (!referentEntry) {
|
|
2620
|
-
throw new Error(`Logic Error: L2-referent Entry was not found within .includes (${JSON.stringify({
|
|
2621
|
-
linkToReferent,
|
|
2622
|
-
})})`);
|
|
2623
|
-
}
|
|
2624
|
-
autoFetchedReferentEntries.push(referentEntry);
|
|
2625
|
-
}
|
|
2626
|
-
else if (linkToReferent.sys.linkType === 'Asset') {
|
|
2627
|
-
const referentAsset = entriesResponse.includes?.Asset?.find((entry) => entry.sys.id === linkToReferent.sys.id);
|
|
2628
|
-
if (!referentAsset) {
|
|
2629
|
-
throw new Error(`Logic Error: L2-referent Asset was not found within includes (${JSON.stringify({
|
|
2630
|
-
linkToReferent,
|
|
2631
|
-
})})`);
|
|
2632
|
-
}
|
|
2633
|
-
autoFetchedReferentAssets.push(referentAsset);
|
|
2634
|
-
}
|
|
2635
|
-
else {
|
|
2612
|
+
const linkType = linkToReferent.sys.linkType;
|
|
2613
|
+
if (!['Entry', 'Asset'].includes(linkType)) {
|
|
2636
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
|
+
})})`);
|
|
2637
2622
|
}
|
|
2623
|
+
linkType === 'Entry'
|
|
2624
|
+
? autoFetchedReferentEntries.push(referentEntity)
|
|
2625
|
+
: autoFetchedReferentAssets.push(referentEntity);
|
|
2638
2626
|
} // for (reference of deepReferences)
|
|
2639
2627
|
return { autoFetchedReferentAssets, autoFetchedReferentEntries };
|
|
2640
2628
|
}
|
|
@@ -2771,10 +2759,10 @@ const fetchReferencedEntities = async ({ client, experienceEntry, locale, }) =>
|
|
|
2771
2759
|
assetIds.push(dataBinding.sys.id);
|
|
2772
2760
|
}
|
|
2773
2761
|
}
|
|
2774
|
-
const [entriesResponse, assetsResponse] =
|
|
2762
|
+
const [entriesResponse, assetsResponse] = await Promise.all([
|
|
2775
2763
|
fetchAllEntries({ client, ids: entryIds, locale }),
|
|
2776
2764
|
fetchAllAssets({ client, ids: assetIds, locale }),
|
|
2777
|
-
])
|
|
2765
|
+
]);
|
|
2778
2766
|
const { autoFetchedReferentAssets, autoFetchedReferentEntries } = gatherAutoFetchedReferentsFromIncludes(deepReferences, entriesResponse);
|
|
2779
2767
|
// Using client getEntries resolves all linked entry references, so we do not need to resolve entries in usedComponents
|
|
2780
2768
|
const allResolvedEntries = [
|