@contentful/experiences-core 1.7.0-dev-20240604T1720-355786e.0 → 1.7.0-dev-20240606T0842-e8e5afe.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;
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, }, componentId) => {
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: transformWidthSizing({ value: cfWidth || cfImageOptions?.width, cfMargin, componentId }),
323
+ width: transformFill(cfWidth || cfImageOptions?.width),
346
324
  height: transformFill(cfHeight || cfImageOptions?.height),
347
325
  maxWidth: cfMaxWidth,
348
326
  ...transformGridColumn(cfColumnSpan),
@@ -2539,11 +2517,10 @@ class DeepReference {
2539
2517
  /**
2540
2518
  * Extracts referent from the path, using EntityStore as source of
2541
2519
  * entities during the resolution path.
2542
- * TODO: should it be called `extractLeafReferent` ? or `followToLeafReferent`
2543
2520
  */
2544
2521
  extractReferent(entityStore) {
2545
2522
  const headEntity = entityStore.getEntityFromLink(this.entityLink);
2546
- const maybeReferentLink = headEntity.fields[this.field];
2523
+ const maybeReferentLink = headEntity?.fields[this.field];
2547
2524
  if (undefined === maybeReferentLink) {
2548
2525
  // field references nothing (or even field doesn't exist)
2549
2526
  return undefined;
@@ -2632,27 +2609,20 @@ function gatherAutoFetchedReferentsFromIncludes(deepReferences, entriesResponse)
2632
2609
  console.debug(`[experiences-sdk-react::gatherAutoFetchedReferentsFromIncludes] Non-link value in headEntity. Probably broken path '${reference.originalPath}'`);
2633
2610
  continue;
2634
2611
  }
2635
- if (linkToReferent.sys.linkType === 'Entry') {
2636
- const referentEntry = entriesResponse.includes?.Entry?.find((entry) => entry.sys.id === linkToReferent.sys.id);
2637
- if (!referentEntry) {
2638
- throw new Error(`Logic Error: L2-referent Entry was not found within .includes (${JSON.stringify({
2639
- linkToReferent,
2640
- })})`);
2641
- }
2642
- autoFetchedReferentEntries.push(referentEntry);
2643
- }
2644
- else if (linkToReferent.sys.linkType === 'Asset') {
2645
- const referentAsset = entriesResponse.includes?.Asset?.find((entry) => entry.sys.id === linkToReferent.sys.id);
2646
- if (!referentAsset) {
2647
- throw new Error(`Logic Error: L2-referent Asset was not found within includes (${JSON.stringify({
2648
- linkToReferent,
2649
- })})`);
2650
- }
2651
- autoFetchedReferentAssets.push(referentAsset);
2652
- }
2653
- else {
2612
+ const linkType = linkToReferent.sys.linkType;
2613
+ if (!['Entry', 'Asset'].includes(linkType)) {
2654
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
+ })})`);
2655
2622
  }
2623
+ linkType === 'Entry'
2624
+ ? autoFetchedReferentEntries.push(referentEntity)
2625
+ : autoFetchedReferentAssets.push(referentEntity);
2656
2626
  } // for (reference of deepReferences)
2657
2627
  return { autoFetchedReferentAssets, autoFetchedReferentEntries };
2658
2628
  }
@@ -2789,10 +2759,10 @@ const fetchReferencedEntities = async ({ client, experienceEntry, locale, }) =>
2789
2759
  assetIds.push(dataBinding.sys.id);
2790
2760
  }
2791
2761
  }
2792
- const [entriesResponse, assetsResponse] = (await Promise.all([
2762
+ const [entriesResponse, assetsResponse] = await Promise.all([
2793
2763
  fetchAllEntries({ client, ids: entryIds, locale }),
2794
2764
  fetchAllAssets({ client, ids: assetIds, locale }),
2795
- ]));
2765
+ ]);
2796
2766
  const { autoFetchedReferentAssets, autoFetchedReferentEntries } = gatherAutoFetchedReferentsFromIncludes(deepReferences, entriesResponse);
2797
2767
  // Using client getEntries resolves all linked entry references, so we do not need to resolve entries in usedComponents
2798
2768
  const allResolvedEntries = [