@contentful/experiences-sdk-react 3.8.0-dev-20250926T1559-e1ab24d.0 → 3.8.0-prerelease-20250926T1312-a8b5fb7.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.
Files changed (29) hide show
  1. package/dist/blocks/preview/CompositionBlock.js +36 -39
  2. package/dist/blocks/preview/CompositionBlock.js.map +1 -1
  3. package/dist/blocks/preview/PreviewDeliveryRoot.js +1 -18
  4. package/dist/blocks/preview/PreviewDeliveryRoot.js.map +1 -1
  5. package/dist/core/preview/assemblyUtils.js +38 -74
  6. package/dist/core/preview/assemblyUtils.js.map +1 -1
  7. package/dist/core/styles/createStylesheetsForBuiltInStyles.js +1 -1
  8. package/dist/core/styles/createStylesheetsForBuiltInStyles.js.map +1 -1
  9. package/dist/index.d.ts +1 -1
  10. package/dist/sdkVersion.js +1 -1
  11. package/dist/sdkVersion.js.map +1 -1
  12. package/dist/src/blocks/preview/CompositionBlock.d.ts +3 -3
  13. package/dist/src/blocks/preview/PreviewDeliveryRoot.d.ts +1 -1
  14. package/dist/src/core/preview/assemblyUtils.d.ts +8 -17
  15. package/dist/src/core/styles/createStylesheetsForBuiltInStyles.d.ts +1 -1
  16. package/dist/src/sdkVersion.d.ts +1 -1
  17. package/dist/src/utils/parseComponentProps.d.ts +3 -9
  18. package/dist/src/utils/prebindingUtils.d.ts +3 -6
  19. package/dist/test/__fixtures__/assembly.d.ts +2 -5
  20. package/dist/utils/parseComponentProps.js +2 -2
  21. package/dist/utils/parseComponentProps.js.map +1 -1
  22. package/dist/utils/prebindingUtils.js +11 -25
  23. package/dist/utils/prebindingUtils.js.map +1 -1
  24. package/package.json +6 -6
  25. package/dist/core/preview/PrebindingManager.js +0 -249
  26. package/dist/core/preview/PrebindingManager.js.map +0 -1
  27. package/dist/src/core/preview/PrebindingManager.d.ts +0 -152
  28. package/dist/src/core/preview/PrebindingManager.test.d.ts +0 -1
  29. package/dist/src/core/preview/__fixtures__.d.ts +0 -517
@@ -1,26 +1,17 @@
1
1
  import { EntityStore } from '@contentful/experiences-core';
2
2
  import type { ComponentTreeNode, ExperienceComponentSettings, Parameter } from '@contentful/experiences-core/types';
3
- type ComponentTreeNodeWithPatternInformation = ComponentTreeNode & {
4
- pattern?: {
5
- parentPatternNodeId: string;
6
- nodeIdOnPattern: string;
7
- prefixedNodeId: string;
8
- };
9
- };
10
3
  /** While unfolding the pattern definition on the instance, this function will replace all
11
4
  * ComponentValue in the definitions tree with the actual value on the instance. */
12
- export declare const deserializePatternNode: ({ node, rootPatternVariables, componentSettings, entityStore, rootPatternParameters, parentPatternRootNodeIdsChain, }: {
5
+ export declare const deserializePatternNode: ({ node, componentInstanceVariables, componentSettings, parameters, entityStore, }: {
13
6
  node: ComponentTreeNode;
14
- rootPatternVariables: ComponentTreeNode["variables"];
7
+ componentInstanceVariables: ComponentTreeNode["variables"];
15
8
  componentSettings: ExperienceComponentSettings;
9
+ parameters: Record<string, Parameter>;
16
10
  entityStore: EntityStore;
17
- rootPatternParameters: Record<string, Parameter>;
18
- parentPatternRootNodeIdsChain: string[];
19
- }) => ComponentTreeNodeWithPatternInformation;
20
- export declare const resolvePattern: ({ node, entityStore, parentPatternRootNodeIdsChain, rootPatternParameters, }: {
11
+ }) => ComponentTreeNode;
12
+ export declare const resolvePattern: ({ node, parentParameters, patternRootNodeIdsChain, entityStore, }: {
21
13
  node: ComponentTreeNode;
22
14
  entityStore: EntityStore;
23
- parentPatternRootNodeIdsChain: string[];
24
- rootPatternParameters: Record<string, Parameter>;
25
- }) => ComponentTreeNodeWithPatternInformation;
26
- export {};
15
+ parentParameters: Record<string, Parameter>;
16
+ patternRootNodeIdsChain: string;
17
+ }) => ComponentTreeNode;
@@ -20,5 +20,5 @@ export declare const createStylesheetsForBuiltInStyles: ({ designPropertiesByBre
20
20
  designPropertiesByBreakpoint: Record<string, Record<string, PrimitiveValue>>;
21
21
  breakpoints: Breakpoint[];
22
22
  node: ComponentTreeNode;
23
- patternRootNodeIdsChain?: Array<string>;
23
+ patternRootNodeIdsChain?: string;
24
24
  }) => ResolvedStylesheetData;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "3.8.0-dev-20250926T1559-e1ab24d.0";
1
+ export declare const SDK_VERSION = "3.8.0-prerelease-20250926T1312-a8b5fb7.0";
@@ -15,11 +15,11 @@ type ResolveBoundValueType = (data: {
15
15
  dataType: ComponentDefinitionVariableType;
16
16
  binding: BoundValue;
17
17
  }) => BoundComponentPropertyTypes;
18
- export declare const parseComponentProps: ({ breakpoints, componentDefinition, patternRootNodeIdsChain, node, resolveDesignValue, resolveBoundValue, resolveHyperlinkValue, resolveUnboundValue, resolveComponentValue, }: {
18
+ export declare const parseComponentProps: ({ breakpoints, componentDefinition, patternRootNodeIdsChain, node, resolveDesignValue, resolveBoundValue, resolveHyperlinkValue, resolveUnboundValue, resolvePrebindingValue, }: {
19
19
  breakpoints: Breakpoint[];
20
20
  mainBreakpoint: Breakpoint;
21
21
  componentDefinition: ComponentDefinition;
22
- patternRootNodeIdsChain: Array<string>;
22
+ patternRootNodeIdsChain?: string;
23
23
  node: ComponentTreeNode;
24
24
  resolveDesignValue: ResolveDesignValueType;
25
25
  resolveBoundValue: ResolveBoundValueType;
@@ -30,13 +30,7 @@ export declare const parseComponentProps: ({ breakpoints, componentDefinition, p
30
30
  mappingKey: string;
31
31
  defaultValue: ComponentDefinitionVariable["defaultValue"];
32
32
  }) => PrimitiveValue;
33
- /**
34
- * This method will be called to resolve the values for components that are native (not from nested pattern) to the previewed pattern
35
- * Nested pattern's components are going to be resolved by the `resolvePattern` method from `assemblyUtils` file
36
- * @param data
37
- * @returns
38
- */
39
- resolveComponentValue: (data: {
33
+ resolvePrebindingValue: (data: {
40
34
  propertyName: string;
41
35
  mappingKey: string;
42
36
  dataType: ComponentDefinitionVariableType;
@@ -1,20 +1,17 @@
1
1
  import { type EntityStore } from '@contentful/experiences-core';
2
2
  import { ExperienceComponentSettings, Parameter } from '@contentful/experiences-validators';
3
- export declare const shouldUsePrebinding: ({ componentValueKey, componentSettings, parameters, patternRootNodeIdsChain, }: {
3
+ export declare const shouldUsePrebinding: ({ componentValueKey, componentSettings, parameters, }: {
4
4
  componentValueKey: string;
5
5
  componentSettings: ExperienceComponentSettings;
6
6
  parameters: Record<string, Parameter>;
7
- patternRootNodeIdsChain: string[];
8
7
  }) => boolean;
9
- export declare const resolvePrebindingPath: ({ componentValueKey, componentSettings, parameters, entityStore, patternRootNodeIdsChain, }: {
8
+ export declare const resolvePrebindingPath: ({ componentValueKey, componentSettings, parameters, entityStore, }: {
10
9
  componentValueKey: string;
11
10
  componentSettings: ExperienceComponentSettings;
12
11
  parameters: Record<string, Parameter>;
13
12
  entityStore: EntityStore;
14
- patternRootNodeIdsChain: string[];
15
13
  }) => string;
16
- export declare const resolveMaybePrebindingDefaultValuePath: ({ componentValueKey, patternRootNodeIdsChain, entityStore, }: {
14
+ export declare const resolveMaybePrebindingDefaultValuePath: ({ componentValueKey, entityStore, }: {
17
15
  componentValueKey: string;
18
- patternRootNodeIdsChain: string[];
19
16
  entityStore: EntityStore;
20
17
  }) => string | undefined;
@@ -1,5 +1,4 @@
1
- import type { ComponentTreeNode, ExperienceComponentSettings, ExperienceEntry, ExperienceTreeNode, SchemaVersions } from '@contentful/experiences-core/types';
2
- import { ExperienceComponentTree } from '@contentful/experiences-validators';
1
+ import type { ComponentTreeNode, ExperienceEntry, ExperienceTreeNode, SchemaVersions } from '@contentful/experiences-core/types';
3
2
  type createAssemblyEntryArgs = {
4
3
  schemaVersion?: SchemaVersions;
5
4
  id?: string;
@@ -7,13 +6,11 @@ type createAssemblyEntryArgs = {
7
6
  entry: ExperienceEntry;
8
7
  node: ComponentTreeNode;
9
8
  }>;
10
- prebindingDefinitions?: ExperienceComponentSettings['prebindingDefinitions'];
11
- componentTreeChildren?: ExperienceComponentTree['children'];
12
9
  };
13
10
  export declare const defaultAssemblyId = "assembly-id";
14
11
  export declare const assemblyGeneratedVariableName = "text_uuid1Assembly";
15
12
  export declare const assemblyGeneratedDesignVariableName = "cfWidth_uuid2Assembly";
16
- export declare const createAssemblyEntry: ({ schemaVersion, id, nestedPatterns, prebindingDefinitions, componentTreeChildren, }?: createAssemblyEntryArgs) => ExperienceEntry;
13
+ export declare const createAssemblyEntry: ({ schemaVersion, id, nestedPatterns, }?: createAssemblyEntryArgs) => ExperienceEntry;
17
14
  type createAssemblyNodeArgs = {
18
15
  id: string;
19
16
  blockId?: string;
@@ -15,7 +15,7 @@ import { createStylesheetsForBuiltInStyles } from '../core/styles/createStyleshe
15
15
  const isSpecialCaseCssProp = (propName) => {
16
16
  return propName === 'cfBackgroundImageUrl' || propName.startsWith('cfBackgroundImageUrl_');
17
17
  };
18
- const parseComponentProps = ({ breakpoints, componentDefinition, patternRootNodeIdsChain, node, resolveDesignValue, resolveBoundValue, resolveHyperlinkValue, resolveUnboundValue, resolveComponentValue, }) => {
18
+ const parseComponentProps = ({ breakpoints, componentDefinition, patternRootNodeIdsChain, node, resolveDesignValue, resolveBoundValue, resolveHyperlinkValue, resolveUnboundValue, resolvePrebindingValue, }) => {
19
19
  const styleProps = {};
20
20
  const customDesignProps = {};
21
21
  const contentProps = {};
@@ -85,7 +85,7 @@ const parseComponentProps = ({ breakpoints, componentDefinition, patternRootNode
85
85
  case 'ComponentValue': {
86
86
  // This can either be a design (style) or a content property.
87
87
  // Where prebinding is used, we resolve like they are a BoundValue.
88
- const propValue = resolveComponentValue({
88
+ const propValue = resolvePrebindingValue({
89
89
  propertyName: propName,
90
90
  mappingKey: propertyValue.key,
91
91
  dataType: propDefinition.type,
@@ -1 +1 @@
1
- {"version":3,"file":"parseComponentProps.js","sources":["../../../src/utils/parseComponentProps.ts"],"sourcesContent":["import { isCfStyleAttribute, debug } from '@contentful/experiences-core';\nimport {\n BoundComponentPropertyTypes,\n BoundValue,\n Breakpoint,\n ComponentDefinition,\n ComponentDefinitionVariable,\n ComponentDefinitionVariableType,\n ComponentTreeNode,\n DesignValue,\n PrimitiveValue,\n ResolveDesignValueType,\n} from '@contentful/experiences-core/types';\nimport { convertResolvedDesignValuesToMediaQuery } from '../core/styles/convertResolvedDesignValuesToMediaQuery';\nimport { createStylesheetsForBuiltInStyles } from '../core/styles/createStylesheetsForBuiltInStyles';\n\n// TODO: Test this for nested patterns as the name might be just a random hash without the actual name (needs to be validated).\n/**\n * Checks if prop is a \"siamese\" prop. So far we have only one such prop: `cfBackgroundImageUrl`.\n * It is considered \"siamese\" because despite being a content variable, it always goes in pair\n * (is coupled) with the `cfBackgroundImageOptions` design variable. Without presence of the\n * `cfBackgroundImageUrl` the `cfBackgroundImageOptions` is useless (and is not going to be\n * rendered by the styleTransformers.ts#transformBackgroundImageUrl()).\n *\n * Because of this coupling, we need to create an \"ephemeral\" cfBackgroundImageUrl style(!) prop.\n */\nconst isSpecialCaseCssProp = (propName: string) => {\n return propName === 'cfBackgroundImageUrl' || propName.startsWith('cfBackgroundImageUrl_');\n};\n\n/**\n * The previous logic of prop mapping was too complex and mixed different ues cases together.\n * In this function, I aim to simplify the logic by focusing on the following specific cases FOR PREVIEW/DELIVERY MODES\n * 1) Any non `DesignValue` props should be resolved and returned as is\n * 2) Some exceptions like `cfImageAsset` and `cfBackgroundImageUrl` (BoundValue) should be handled separately\n * and be resolved for the default breakpoint only (cause we don't allow binding per breakpoint anyway)\n * 3) Those DesignValue props which can be converted to CSS should be grouped and resolved into a CSS media query\n * for each breakpoint\n * 4) Those DesignValue props which can NOT be converted to CSS (custom design props) should be resolved dynamically\n * for each breakpoint\n */\ntype ResolveBoundValueType = (data: {\n propertyName: string;\n dataType: ComponentDefinitionVariableType;\n binding: BoundValue;\n}) => BoundComponentPropertyTypes;\n\nexport const parseComponentProps = ({\n breakpoints,\n componentDefinition,\n patternRootNodeIdsChain,\n node,\n resolveDesignValue,\n resolveBoundValue,\n resolveHyperlinkValue,\n resolveUnboundValue,\n resolveComponentValue,\n}: {\n breakpoints: Breakpoint[];\n mainBreakpoint: Breakpoint;\n componentDefinition: ComponentDefinition;\n patternRootNodeIdsChain: Array<string>;\n node: ComponentTreeNode;\n resolveDesignValue: ResolveDesignValueType;\n resolveBoundValue: ResolveBoundValueType;\n resolveHyperlinkValue: (data: { linkTargetKey: string }) => string | null;\n resolveUnboundValue: (data: {\n mappingKey: string;\n defaultValue: ComponentDefinitionVariable['defaultValue'];\n }) => PrimitiveValue;\n /**\n * This method will be called to resolve the values for components that are native (not from nested pattern) to the previewed pattern\n * Nested pattern's components are going to be resolved by the `resolvePattern` method from `assemblyUtils` file\n * @param data\n * @returns\n */\n resolveComponentValue: (data: {\n propertyName: string;\n mappingKey: string;\n dataType: ComponentDefinitionVariableType;\n resolveBoundValue: ResolveBoundValueType;\n }) => PrimitiveValue;\n}) => {\n const styleProps: Record<string, DesignValue['valuesByBreakpoint']> = {};\n const customDesignProps: Record<string, PrimitiveValue> = {};\n const contentProps: Record<string, PrimitiveValue> = {};\n\n debug.log(\n '[experiences-sdk-react::parseComponentProps] Parsing component props for node with id: ',\n node.id,\n );\n\n for (const [propName, propDefinition] of Object.entries(componentDefinition.variables)) {\n const propertyValue = node.variables[propName];\n if (!propertyValue) continue;\n\n switch (propertyValue.type) {\n case 'DesignValue': {\n if (isCfStyleAttribute(propName)) {\n // for such properties we know how to convert them to CSS, so we will build a media query from it below after the loop is over\n styleProps[propName] = propertyValue.valuesByBreakpoint;\n } else {\n // for custom design props, the value will be resolved with the javascript per breakpoint at runtime\n customDesignProps[propName] = resolveDesignValue(propertyValue.valuesByBreakpoint);\n }\n break;\n }\n case 'BoundValue': {\n const boundValue = resolveBoundValue({\n propertyName: propName,\n dataType: propDefinition.type as ComponentDefinitionVariableType,\n binding: propertyValue,\n });\n\n const propValue = boundValue ?? propDefinition.defaultValue;\n\n if (isSpecialCaseCssProp(propName)) {\n // styleProps[propName] = { [mainBreakpoint.id]: propValue };\n // Here we create kind of \"fake\" style property out of a bound value.\n // As bound values are breakpoint-universal (they apply to all breakpoints),\n // but styleProps are breakpoint-specific, we need to ensure that\n // semantically our \"fake\" emphemeral style property will be universall as well,\n // by expanding it to all the breakpoints. This is important as\n // styleTransformers.ts#transformBackgroundImageUrl() expects\n // cfBackgroundImageUrl to be present for all breakpoints\n // where cfBackgroundImageOptions is present.\n styleProps[propName] = Object.fromEntries(breakpoints.map((b) => [b.id, propValue]));\n } else {\n contentProps[propName] = propValue;\n }\n break;\n }\n\n case 'HyperlinkValue': {\n const hyperlink = resolveHyperlinkValue({\n linkTargetKey: propertyValue.linkTargetKey,\n });\n if (hyperlink) {\n contentProps[propName] = hyperlink;\n }\n break;\n }\n case 'UnboundValue': {\n const unboundValue = resolveUnboundValue({\n mappingKey: propertyValue.key,\n defaultValue: propDefinition.defaultValue,\n });\n\n if (isSpecialCaseCssProp(propName)) {\n styleProps[propName] = Object.fromEntries(breakpoints.map((b) => [b.id, unboundValue]));\n } else {\n contentProps[propName] = unboundValue;\n }\n break;\n }\n case 'ComponentValue': {\n // This can either be a design (style) or a content property.\n // Where prebinding is used, we resolve like they are a BoundValue.\n const propValue =\n resolveComponentValue({\n propertyName: propName,\n mappingKey: propertyValue.key,\n dataType: propDefinition.type,\n resolveBoundValue,\n }) ?? propDefinition.defaultValue;\n\n if (isSpecialCaseCssProp(propName)) {\n styleProps[propName] = Object.fromEntries(breakpoints.map((b) => [b.id, propValue]));\n } else {\n contentProps[propName] = propValue;\n }\n break;\n }\n default:\n break;\n }\n }\n /* [Data Format] After resolving all properties, `styleProps` contains solely the plain design values\n * styleProps = {\n * cfMargin: { desktop: '42px', tablet: '13px' },\n * cfBackgroundColor: { desktop: 'rgba(246, 246, 246, 1)' },\n * cfBackgroundImage: { desktop: 'url(https://example.com/image.jpg)' }\n * }\n */\n\n const stylePropsIndexedByBreakpoint = Object.entries(styleProps).reduce<\n Record<string, Record<string, PrimitiveValue>>\n >((acc, [propName, valuesByBreakpoint]) => {\n for (const [breakpointId, value] of Object.entries(valuesByBreakpoint)) {\n if (!acc[breakpointId]) {\n acc[breakpointId] = {};\n }\n\n acc[breakpointId][propName] = value;\n }\n\n return acc;\n }, {});\n /* [Data Format] `stylePropsIndexedByBreakpoint` contains the plain design values grouped by breakpoint\n * stylePropsIndexedByBreakpoint = {\n * desktop: {\n * cfMargin: '42px',\n * cfBackgroundColor: 'rgba(246, 246, 246, 1)',\n * cfBackgroundImage: 'url(https://example.com/image.jpg)'\n * },\n * tablet: {\n * cfMargin: '13px'\n * }\n * }\n */\n\n const stylesheetData = createStylesheetsForBuiltInStyles({\n designPropertiesByBreakpoint: stylePropsIndexedByBreakpoint,\n breakpoints,\n node,\n patternRootNodeIdsChain,\n });\n /* [Data Format] Stylesheet data provides objects containing `className`, `breakpointCondition`, and `css`.\n * stylesheetData = [{\n * className: 'uniqueMD5Hash',\n * breakpointCondition: '<768px',\n * css: 'margin:13px;'\n * visibilityCss: 'display:none !important;'\n * }, ...]\n */\n const mediaQuery = convertResolvedDesignValuesToMediaQuery(stylesheetData);\n /* [Data Format] `mediaQuery` is a joined string of all media query CSS code\n * mediaQuery = \".cfstyles-123{margin:42px;}@media(max-width:768px){.cfstyles-456{margin:13px;}}\"\n */\n return {\n styleProps,\n mediaQuery,\n customDesignProps,\n contentProps,\n };\n};\n"],"names":[],"mappings":";;;;AAgBA;AACA;;;;;;;;AAQG;AACH,MAAM,oBAAoB,GAAG,CAAC,QAAgB,KAAI;IAChD,OAAO,QAAQ,KAAK,sBAAsB,IAAI,QAAQ,CAAC,UAAU,CAAC,uBAAuB,CAAC,CAAC;AAC7F,CAAC,CAAC;AAmBW,MAAA,mBAAmB,GAAG,CAAC,EAClC,WAAW,EACX,mBAAmB,EACnB,uBAAuB,EACvB,IAAI,EACJ,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,GA0BtB,KAAI;IACH,MAAM,UAAU,GAAsD,EAAE,CAAC;IACzE,MAAM,iBAAiB,GAAmC,EAAE,CAAC;IAC7D,MAAM,YAAY,GAAmC,EAAE,CAAC;IAExD,KAAK,CAAC,GAA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;AAMG;IAEH,MAAM,6BAA6B,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,MAAM,CAErE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,kBAAkB,CAAC,KAAI;AACxC,QAAA,KAAK,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE;AACtE,YAAA,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE;AACtB,gBAAA,GAAG,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;aACxB;YAED,GAAG,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;SACrC;AAED,QAAA,OAAO,GAAG,CAAC;KACZ,EAAE,EAAE,CAAC,CAAC;AACP;;;;;;;;;;;AAWG;IAEH,MAAM,cAAc,GAAG,iCAAiC,CAAC;AACvD,QAAA,4BAA4B,EAAE,6BAA6B;QAC3D,WAAW;QACX,IAAI;QACJ,uBAAuB;AACxB,KAAA,CAAC,CAAC;AACH;;;;;;;AAOG;AACH,IAAA,MAAM,UAAU,GAAG,uCAAuC,CAAC,cAAc,CAAC,CAAC;AAC3E;;AAEG;IACH,OAAO;QACL,UAAU;QACV,UAAU;QACV,iBAAiB;QACjB,YAAY;KACb,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"parseComponentProps.js","sources":["../../../src/utils/parseComponentProps.ts"],"sourcesContent":["import { isCfStyleAttribute, debug } from '@contentful/experiences-core';\nimport {\n BoundComponentPropertyTypes,\n BoundValue,\n Breakpoint,\n ComponentDefinition,\n ComponentDefinitionVariable,\n ComponentDefinitionVariableType,\n ComponentTreeNode,\n DesignValue,\n PrimitiveValue,\n ResolveDesignValueType,\n} from '@contentful/experiences-core/types';\nimport { convertResolvedDesignValuesToMediaQuery } from '../core/styles/convertResolvedDesignValuesToMediaQuery';\nimport { createStylesheetsForBuiltInStyles } from '../core/styles/createStylesheetsForBuiltInStyles';\n\n// TODO: Test this for nested patterns as the name might be just a random hash without the actual name (needs to be validated).\n/**\n * Checks if prop is a \"siamese\" prop. So far we have only one such prop: `cfBackgroundImageUrl`.\n * It is considered \"siamese\" because despite being a content variable, it always goes in pair\n * (is coupled) with the `cfBackgroundImageOptions` design variable. Without presence of the\n * `cfBackgroundImageUrl` the `cfBackgroundImageOptions` is useless (and is not going to be\n * rendered by the styleTransformers.ts#transformBackgroundImageUrl()).\n *\n * Because of this coupling, we need to create an \"ephemeral\" cfBackgroundImageUrl style(!) prop.\n */\nconst isSpecialCaseCssProp = (propName: string) => {\n return propName === 'cfBackgroundImageUrl' || propName.startsWith('cfBackgroundImageUrl_');\n};\n\n/**\n * The previous logic of prop mapping was too complex and mixed different ues cases together.\n * In this function, I aim to simplify the logic by focusing on the following specific cases FOR PREVIEW/DELIVERY MODES\n * 1) Any non `DesignValue` props should be resolved and returned as is\n * 2) Some exceptions like `cfImageAsset` and `cfBackgroundImageUrl` (BoundValue) should be handled separately\n * and be resolved for the default breakpoint only (cause we don't allow binding per breakpoint anyway)\n * 3) Those DesignValue props which can be converted to CSS should be grouped and resolved into a CSS media query\n * for each breakpoint\n * 4) Those DesignValue props which can NOT be converted to CSS (custom design props) should be resolved dynamically\n * for each breakpoint\n */\ntype ResolveBoundValueType = (data: {\n propertyName: string;\n dataType: ComponentDefinitionVariableType;\n binding: BoundValue;\n}) => BoundComponentPropertyTypes;\n\nexport const parseComponentProps = ({\n breakpoints,\n componentDefinition,\n patternRootNodeIdsChain,\n node,\n resolveDesignValue,\n resolveBoundValue,\n resolveHyperlinkValue,\n resolveUnboundValue,\n resolvePrebindingValue,\n}: {\n breakpoints: Breakpoint[];\n mainBreakpoint: Breakpoint;\n componentDefinition: ComponentDefinition;\n patternRootNodeIdsChain?: string;\n node: ComponentTreeNode;\n resolveDesignValue: ResolveDesignValueType;\n resolveBoundValue: ResolveBoundValueType;\n resolveHyperlinkValue: (data: { linkTargetKey: string }) => string | null;\n resolveUnboundValue: (data: {\n mappingKey: string;\n defaultValue: ComponentDefinitionVariable['defaultValue'];\n }) => PrimitiveValue;\n resolvePrebindingValue: (data: {\n propertyName: string;\n mappingKey: string;\n dataType: ComponentDefinitionVariableType;\n resolveBoundValue: ResolveBoundValueType;\n }) => PrimitiveValue;\n}) => {\n const styleProps: Record<string, DesignValue['valuesByBreakpoint']> = {};\n const customDesignProps: Record<string, PrimitiveValue> = {};\n const contentProps: Record<string, PrimitiveValue> = {};\n\n debug.log(\n '[experiences-sdk-react::parseComponentProps] Parsing component props for node with id: ',\n node.id,\n );\n\n for (const [propName, propDefinition] of Object.entries(componentDefinition.variables)) {\n const propertyValue = node.variables[propName];\n if (!propertyValue) continue;\n\n switch (propertyValue.type) {\n case 'DesignValue': {\n if (isCfStyleAttribute(propName)) {\n // for such properties we know how to convert them to CSS, so we will build a media query from it below after the loop is over\n styleProps[propName] = propertyValue.valuesByBreakpoint;\n } else {\n // for custom design props, the value will be resolved with the javascript per breakpoint at runtime\n customDesignProps[propName] = resolveDesignValue(propertyValue.valuesByBreakpoint);\n }\n break;\n }\n case 'BoundValue': {\n const boundValue = resolveBoundValue({\n propertyName: propName,\n dataType: propDefinition.type as ComponentDefinitionVariableType,\n binding: propertyValue,\n });\n\n const propValue = boundValue ?? propDefinition.defaultValue;\n\n if (isSpecialCaseCssProp(propName)) {\n // styleProps[propName] = { [mainBreakpoint.id]: propValue };\n // Here we create kind of \"fake\" style property out of a bound value.\n // As bound values are breakpoint-universal (they apply to all breakpoints),\n // but styleProps are breakpoint-specific, we need to ensure that\n // semantically our \"fake\" emphemeral style property will be universall as well,\n // by expanding it to all the breakpoints. This is important as\n // styleTransformers.ts#transformBackgroundImageUrl() expects\n // cfBackgroundImageUrl to be present for all breakpoints\n // where cfBackgroundImageOptions is present.\n styleProps[propName] = Object.fromEntries(breakpoints.map((b) => [b.id, propValue]));\n } else {\n contentProps[propName] = propValue;\n }\n break;\n }\n\n case 'HyperlinkValue': {\n const hyperlink = resolveHyperlinkValue({\n linkTargetKey: propertyValue.linkTargetKey,\n });\n if (hyperlink) {\n contentProps[propName] = hyperlink;\n }\n break;\n }\n case 'UnboundValue': {\n const unboundValue = resolveUnboundValue({\n mappingKey: propertyValue.key,\n defaultValue: propDefinition.defaultValue,\n });\n\n if (isSpecialCaseCssProp(propName)) {\n styleProps[propName] = Object.fromEntries(breakpoints.map((b) => [b.id, unboundValue]));\n } else {\n contentProps[propName] = unboundValue;\n }\n break;\n }\n case 'ComponentValue': {\n // This can either be a design (style) or a content property.\n // Where prebinding is used, we resolve like they are a BoundValue.\n const propValue =\n resolvePrebindingValue({\n propertyName: propName,\n mappingKey: propertyValue.key,\n dataType: propDefinition.type,\n resolveBoundValue,\n }) ?? propDefinition.defaultValue;\n\n if (isSpecialCaseCssProp(propName)) {\n styleProps[propName] = Object.fromEntries(breakpoints.map((b) => [b.id, propValue]));\n } else {\n contentProps[propName] = propValue;\n }\n break;\n }\n default:\n break;\n }\n }\n /* [Data Format] After resolving all properties, `styleProps` contains solely the plain design values\n * styleProps = {\n * cfMargin: { desktop: '42px', tablet: '13px' },\n * cfBackgroundColor: { desktop: 'rgba(246, 246, 246, 1)' },\n * cfBackgroundImage: { desktop: 'url(https://example.com/image.jpg)' }\n * }\n */\n\n const stylePropsIndexedByBreakpoint = Object.entries(styleProps).reduce<\n Record<string, Record<string, PrimitiveValue>>\n >((acc, [propName, valuesByBreakpoint]) => {\n for (const [breakpointId, value] of Object.entries(valuesByBreakpoint)) {\n if (!acc[breakpointId]) {\n acc[breakpointId] = {};\n }\n\n acc[breakpointId][propName] = value;\n }\n\n return acc;\n }, {});\n /* [Data Format] `stylePropsIndexedByBreakpoint` contains the plain design values grouped by breakpoint\n * stylePropsIndexedByBreakpoint = {\n * desktop: {\n * cfMargin: '42px',\n * cfBackgroundColor: 'rgba(246, 246, 246, 1)',\n * cfBackgroundImage: 'url(https://example.com/image.jpg)'\n * },\n * tablet: {\n * cfMargin: '13px'\n * }\n * }\n */\n\n const stylesheetData = createStylesheetsForBuiltInStyles({\n designPropertiesByBreakpoint: stylePropsIndexedByBreakpoint,\n breakpoints,\n node,\n patternRootNodeIdsChain,\n });\n /* [Data Format] Stylesheet data provides objects containing `className`, `breakpointCondition`, and `css`.\n * stylesheetData = [{\n * className: 'uniqueMD5Hash',\n * breakpointCondition: '<768px',\n * css: 'margin:13px;'\n * visibilityCss: 'display:none !important;'\n * }, ...]\n */\n const mediaQuery = convertResolvedDesignValuesToMediaQuery(stylesheetData);\n /* [Data Format] `mediaQuery` is a joined string of all media query CSS code\n * mediaQuery = \".cfstyles-123{margin:42px;}@media(max-width:768px){.cfstyles-456{margin:13px;}}\"\n */\n return {\n styleProps,\n mediaQuery,\n customDesignProps,\n contentProps,\n };\n};\n"],"names":[],"mappings":";;;;AAgBA;AACA;;;;;;;;AAQG;AACH,MAAM,oBAAoB,GAAG,CAAC,QAAgB,KAAI;IAChD,OAAO,QAAQ,KAAK,sBAAsB,IAAI,QAAQ,CAAC,UAAU,CAAC,uBAAuB,CAAC,CAAC;AAC7F,CAAC,CAAC;AAmBW,MAAA,mBAAmB,GAAG,CAAC,EAClC,WAAW,EACX,mBAAmB,EACnB,uBAAuB,EACvB,IAAI,EACJ,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,GAoBvB,KAAI;IACH,MAAM,UAAU,GAAsD,EAAE,CAAC;IACzE,MAAM,iBAAiB,GAAmC,EAAE,CAAC;IAC7D,MAAM,YAAY,GAAmC,EAAE,CAAC;IAExD,KAAK,CAAC,GAAG,CACP,yFAAyF,EACzF,IAAI,CAAC,EAAE,CACR,CAAC;AAEF,IAAA,KAAK,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE;QACtF,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AAC/C,QAAA,IAAI,CAAC,aAAa;YAAE,SAAS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G,CAAC,YAAY,CAAC,EAAE;AACtB,gBAAA,GAAG,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;aACxB;YAED,GAAG,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;SACrC;AAED,QAAA,OAAO,GAAG,CAAC;KACZ,EAAE,EAAE,CAAC,CAAC;AACP;;;;;;;;;;;AAWG;IAEH,MAAM,cAAc,GAAG,iCAAiC,CAAC;AACvD,QAAA,4BAA4B,EAAE,6BAA6B;QAC3D,WAAW;QACX,IAAI;QACJ,uBAAuB;AACxB,KAAA,CAAC,CAAC;AACH;;;;;;;AAOG;AACH,IAAA,MAAM,UAAU,GAAG,uCAAuC,CAAC,cAAc,CAAC,CAAC;AAC3E;;AAEG;IACH,OAAO;QACL,UAAU;QACV,UAAU;QACV,iBAAiB;QACjB,YAAY;KACb,CAAC;AACJ;;;;"}
@@ -1,36 +1,28 @@
1
1
  import { isLink } from '@contentful/experiences-core';
2
- import { PrebindingManager } from '../core/preview/PrebindingManager.js';
2
+ import { SIDELOADED_PREFIX } from '@contentful/experiences-core/constants';
3
3
 
4
- const shouldUsePrebinding = ({ componentValueKey, componentSettings, parameters, patternRootNodeIdsChain, }) => {
4
+ const shouldUsePrebinding = ({ componentValueKey, componentSettings, parameters, }) => {
5
5
  const { prebindingDefinitions } = componentSettings;
6
6
  const { parameterDefinitions, variableMappings, allowedVariableOverrides } = prebindingDefinitions?.[0] || {};
7
7
  const variableMapping = variableMappings?.[componentValueKey];
8
8
  const parameterDefinition = parameterDefinitions?.[variableMapping?.parameterId || ''];
9
- const patternRootNodeIds = patternRootNodeIdsChain.join('---');
10
- const hoistedParameterId = PrebindingManager.getHoistedIdForParameterId(variableMapping?.parameterId || '', patternRootNodeIds);
11
- const parameter = parameters?.[hoistedParameterId];
9
+ const parameter = parameters?.[variableMapping?.parameterId || ''];
12
10
  const isValidForPrebinding = !!parameterDefinition &&
13
11
  !!parameter &&
14
12
  !!variableMapping &&
15
13
  !!allowedVariableOverrides &&
16
14
  Array.isArray(allowedVariableOverrides);
17
- if (!isValidForPrebinding) {
18
- return false;
19
- }
20
- // removed 'NoValue' check
21
- const isForDirectBindingOnly = allowedVariableOverrides.includes(componentValueKey);
22
- return !isForDirectBindingOnly;
15
+ const isForDirectBindingOnly = (allowedVariableOverrides) => allowedVariableOverrides.includes(componentValueKey); // removed 'NoValue' check
16
+ return isValidForPrebinding && !isForDirectBindingOnly(allowedVariableOverrides);
23
17
  };
24
- const resolvePrebindingPath = ({ componentValueKey, componentSettings, parameters, entityStore, patternRootNodeIdsChain, }) => {
18
+ const resolvePrebindingPath = ({ componentValueKey, componentSettings, parameters, entityStore, }) => {
25
19
  const prebindingDefinition = componentSettings.prebindingDefinitions?.[0];
26
20
  if (!prebindingDefinition)
27
21
  return '';
28
22
  const variableMapping = prebindingDefinition.variableMappings?.[componentValueKey];
29
23
  if (!variableMapping)
30
24
  return '';
31
- const patternRootNodeIds = patternRootNodeIdsChain.join('---');
32
- const hoistedParameterId = PrebindingManager.getHoistedIdForParameterId(variableMapping.parameterId, patternRootNodeIds);
33
- const parameter = parameters?.[hoistedParameterId];
25
+ const parameter = parameters?.[variableMapping.parameterId];
34
26
  if (!parameter)
35
27
  return '';
36
28
  const dataSourceKey = parameter.path.split('/')[1];
@@ -41,22 +33,17 @@ const resolvePrebindingPath = ({ componentValueKey, componentSettings, parameter
41
33
  if (!entity || entity.sys.type === 'Asset')
42
34
  return '';
43
35
  const contentType = entity.sys.contentType.sys.id;
44
- const hoistedParameterDefinition = entityStore.hoistedParameterDefinitions[hoistedParameterId];
45
- if (!hoistedParameterDefinition || !hoistedParameterDefinition.contentTypes.includes(contentType))
46
- return '';
47
36
  const fieldPath = variableMapping?.pathsByContentType?.[contentType]?.path;
48
37
  if (!fieldPath)
49
38
  return '';
50
39
  return parameter.path + fieldPath;
51
40
  };
52
- const resolveMaybePrebindingDefaultValuePath = ({ componentValueKey, patternRootNodeIdsChain, entityStore, }) => {
41
+ const resolveMaybePrebindingDefaultValuePath = ({ componentValueKey, entityStore, }) => {
53
42
  const variableMapping = entityStore.hoistedVariableMappings[componentValueKey];
54
43
  if (!variableMapping)
55
44
  return;
56
- const patternRootNodeIds = patternRootNodeIdsChain.join('---');
57
45
  const pdID = variableMapping.parameterId;
58
- const hoistedpdID = PrebindingManager.getHoistedIdForParameterId(pdID, patternRootNodeIds);
59
- const prebindingDefinition = entityStore.hoistedParameterDefinitions[hoistedpdID];
46
+ const prebindingDefinition = entityStore.hoistedParameterDefinitions[pdID];
60
47
  if (!prebindingDefinition) {
61
48
  // probably shouldn't happen, as if ppd is not defined, then variableMapping should not be defined either
62
49
  return;
@@ -70,7 +57,7 @@ const resolveMaybePrebindingDefaultValuePath = ({ componentValueKey, patternRoot
70
57
  // just extra safety check, defaultEntryLink should always be a link
71
58
  return;
72
59
  }
73
- if (prebindingDefinition.contentTypes.includes(contentTypeId)) {
60
+ if (contentTypeId in prebindingDefinition.contentTypes) {
74
61
  const entity = entityStore.getEntityFromLink(defaultEntryLink);
75
62
  if (!entity) {
76
63
  // looks like sideloading of the prebinding default value didn't work as expected.
@@ -82,10 +69,9 @@ const resolveMaybePrebindingDefaultValuePath = ({ componentValueKey, patternRoot
82
69
  // Path not found or degenerate shape (e.g. empty string '')
83
70
  return;
84
71
  }
85
- const fullDefaultValuePath = `/${defaultEntryLink.sys.id}${fieldPath}`;
72
+ const fullDefaultValuePath = `/${SIDELOADED_PREFIX}${defaultEntryLink.sys.id}${fieldPath}`;
86
73
  return fullDefaultValuePath;
87
74
  }
88
- return undefined;
89
75
  };
90
76
 
91
77
  export { resolveMaybePrebindingDefaultValuePath, resolvePrebindingPath, shouldUsePrebinding };
@@ -1 +1 @@
1
- {"version":3,"file":"prebindingUtils.js","sources":["../../../src/utils/prebindingUtils.ts"],"sourcesContent":["import { type EntityStore, isLink } from '@contentful/experiences-core';\nimport { ExperienceComponentSettings, Parameter } from '@contentful/experiences-validators';\nimport { PrebindingManager } from '../core/preview/PrebindingManager';\n\nexport const shouldUsePrebinding = ({\n componentValueKey,\n componentSettings,\n parameters,\n patternRootNodeIdsChain,\n}: {\n componentValueKey: string;\n componentSettings: ExperienceComponentSettings;\n parameters: Record<string, Parameter>;\n patternRootNodeIdsChain: string[];\n}) => {\n const { prebindingDefinitions } = componentSettings;\n const { parameterDefinitions, variableMappings, allowedVariableOverrides } =\n prebindingDefinitions?.[0] || {};\n\n const variableMapping = variableMappings?.[componentValueKey];\n\n const parameterDefinition = parameterDefinitions?.[variableMapping?.parameterId || ''];\n\n const patternRootNodeIds = patternRootNodeIdsChain.join('---');\n const hoistedParameterId = PrebindingManager.getHoistedIdForParameterId(\n variableMapping?.parameterId || '',\n patternRootNodeIds,\n );\n const parameter = parameters?.[hoistedParameterId];\n\n const isValidForPrebinding =\n !!parameterDefinition &&\n !!parameter &&\n !!variableMapping &&\n !!allowedVariableOverrides &&\n Array.isArray(allowedVariableOverrides);\n\n if (!isValidForPrebinding) {\n return false;\n }\n\n // removed 'NoValue' check\n const isForDirectBindingOnly = allowedVariableOverrides.includes(componentValueKey);\n return !isForDirectBindingOnly;\n};\n\nexport const resolvePrebindingPath = ({\n componentValueKey,\n componentSettings,\n parameters,\n entityStore,\n patternRootNodeIdsChain,\n}: {\n componentValueKey: string;\n componentSettings: ExperienceComponentSettings;\n parameters: Record<string, Parameter>;\n entityStore: EntityStore;\n patternRootNodeIdsChain: string[];\n}) => {\n const prebindingDefinition = componentSettings.prebindingDefinitions?.[0];\n if (!prebindingDefinition) return '';\n\n const variableMapping = prebindingDefinition.variableMappings?.[componentValueKey];\n\n if (!variableMapping) return '';\n\n const patternRootNodeIds = patternRootNodeIdsChain.join('---');\n const hoistedParameterId = PrebindingManager.getHoistedIdForParameterId(\n variableMapping.parameterId,\n patternRootNodeIds,\n );\n const parameter = parameters?.[hoistedParameterId];\n\n if (!parameter) return '';\n\n const dataSourceKey = parameter.path.split('/')[1];\n\n const entityLink = entityStore.dataSource[dataSourceKey];\n if (!entityLink) return '';\n\n const entity = entityStore.getEntityFromLink(entityLink);\n if (!entity || entity.sys.type === 'Asset') return '';\n\n const contentType = entity.sys.contentType.sys.id;\n\n const hoistedParameterDefinition = entityStore.hoistedParameterDefinitions[hoistedParameterId];\n if (!hoistedParameterDefinition || !hoistedParameterDefinition.contentTypes.includes(contentType))\n return '';\n\n const fieldPath = variableMapping?.pathsByContentType?.[contentType]?.path;\n\n if (!fieldPath) return '';\n\n return parameter.path + fieldPath;\n};\n\nexport const resolveMaybePrebindingDefaultValuePath = ({\n componentValueKey,\n patternRootNodeIdsChain,\n entityStore,\n}: {\n componentValueKey: string;\n patternRootNodeIdsChain: string[];\n entityStore: EntityStore;\n}): string | undefined => {\n const variableMapping = entityStore.hoistedVariableMappings[componentValueKey];\n if (!variableMapping) return;\n\n const patternRootNodeIds = patternRootNodeIdsChain.join('---');\n\n const pdID = variableMapping.parameterId;\n const hoistedpdID = PrebindingManager.getHoistedIdForParameterId(pdID, patternRootNodeIds);\n const prebindingDefinition = entityStore.hoistedParameterDefinitions[hoistedpdID];\n\n if (!prebindingDefinition) {\n // probably shouldn't happen, as if ppd is not defined, then variableMapping should not be defined either\n return;\n }\n if (!prebindingDefinition.defaultSource) {\n // pretty normal, prebinding definitions are not required to have default source\n return;\n }\n\n const { contentTypeId, link: defaultEntryLink } = prebindingDefinition.defaultSource;\n\n if (!isLink(defaultEntryLink)) {\n // just extra safety check, defaultEntryLink should always be a link\n return;\n }\n\n if (prebindingDefinition.contentTypes.includes(contentTypeId)) {\n const entity = entityStore.getEntityFromLink(defaultEntryLink);\n if (!entity) {\n // looks like sideloading of the prebinding default value didn't work as expected.\n // And didn't sideload the entry into entityStore (and didn't add it's sideloaded_dsKey to the entityStore.dataSource)\n return;\n }\n\n const fieldPath = variableMapping.pathsByContentType[contentTypeId].path;\n if (!fieldPath) {\n // Path not found or degenerate shape (e.g. empty string '')\n return;\n }\n\n const fullDefaultValuePath = `/${defaultEntryLink.sys.id}${fieldPath}`;\n return fullDefaultValuePath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CAAC,aAAa,CAAC,CAAC,IAAI,CAAC;QACzE,IAAI,CAAC,SAAS,EAAE;;YAEd,OAAO;SACR;QAED,MAAM,oBAAoB,GAAG,CAAA,CAAA,EAAI,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAA,EAAG,SAAS,CAAA,CAAE,CAAC;AACvE,QAAA,OAAO,oBAAoB,CAAC;KAC7B;AAED,IAAA,OAAO,SAAS,CAAC;AACnB;;;;"}
1
+ {"version":3,"file":"prebindingUtils.js","sources":["../../../src/utils/prebindingUtils.ts"],"sourcesContent":["import { type EntityStore, isLink } from '@contentful/experiences-core';\nimport { SIDELOADED_PREFIX } from '@contentful/experiences-core/constants';\nimport { ExperienceComponentSettings, Parameter } from '@contentful/experiences-validators';\n\nexport const shouldUsePrebinding = ({\n componentValueKey,\n componentSettings,\n parameters,\n}: {\n componentValueKey: string;\n componentSettings: ExperienceComponentSettings;\n parameters: Record<string, Parameter>;\n}) => {\n const { prebindingDefinitions } = componentSettings;\n const { parameterDefinitions, variableMappings, allowedVariableOverrides } =\n prebindingDefinitions?.[0] || {};\n\n const variableMapping = variableMappings?.[componentValueKey];\n\n const parameterDefinition = parameterDefinitions?.[variableMapping?.parameterId || ''];\n const parameter = parameters?.[variableMapping?.parameterId || ''];\n\n const isValidForPrebinding =\n !!parameterDefinition &&\n !!parameter &&\n !!variableMapping &&\n !!allowedVariableOverrides &&\n Array.isArray(allowedVariableOverrides);\n\n const isForDirectBindingOnly = (allowedVariableOverrides: string[]) =>\n allowedVariableOverrides.includes(componentValueKey); // removed 'NoValue' check\n\n return isValidForPrebinding && !isForDirectBindingOnly(allowedVariableOverrides);\n};\n\nexport const resolvePrebindingPath = ({\n componentValueKey,\n componentSettings,\n parameters,\n entityStore,\n}: {\n componentValueKey: string;\n componentSettings: ExperienceComponentSettings;\n parameters: Record<string, Parameter>;\n entityStore: EntityStore;\n}) => {\n const prebindingDefinition = componentSettings.prebindingDefinitions?.[0];\n if (!prebindingDefinition) return '';\n\n const variableMapping = prebindingDefinition.variableMappings?.[componentValueKey];\n\n if (!variableMapping) return '';\n\n const parameter = parameters?.[variableMapping.parameterId];\n\n if (!parameter) return '';\n\n const dataSourceKey = parameter.path.split('/')[1];\n\n const entityLink = entityStore.dataSource[dataSourceKey];\n if (!entityLink) return '';\n\n const entity = entityStore.getEntityFromLink(entityLink);\n if (!entity || entity.sys.type === 'Asset') return '';\n\n const contentType = entity.sys.contentType.sys.id;\n\n const fieldPath = variableMapping?.pathsByContentType?.[contentType]?.path;\n\n if (!fieldPath) return '';\n\n return parameter.path + fieldPath;\n};\n\nexport const resolveMaybePrebindingDefaultValuePath = ({\n componentValueKey,\n entityStore,\n}: {\n componentValueKey: string;\n entityStore: EntityStore;\n}): string | undefined => {\n const variableMapping = entityStore.hoistedVariableMappings[componentValueKey];\n if (!variableMapping) return;\n\n const pdID = variableMapping.parameterId;\n const prebindingDefinition = entityStore.hoistedParameterDefinitions[pdID];\n\n if (!prebindingDefinition) {\n // probably shouldn't happen, as if ppd is not defined, then variableMapping should not be defined either\n return;\n }\n if (!prebindingDefinition.defaultSource) {\n // pretty normal, prebinding definitions are not required to have default source\n return;\n }\n\n const { contentTypeId, link: defaultEntryLink } = prebindingDefinition.defaultSource;\n\n if (!isLink(defaultEntryLink)) {\n // just extra safety check, defaultEntryLink should always be a link\n return;\n }\n\n if (contentTypeId in prebindingDefinition.contentTypes) {\n const entity = entityStore.getEntityFromLink(defaultEntryLink);\n if (!entity) {\n // looks like sideloading of the prebinding default value didn't work as expected.\n // And didn't sideload the entry into entityStore (and didn't add it's sideloaded_dsKey to the entityStore.dataSource)\n return;\n }\n\n const fieldPath = variableMapping.pathsByContentType[contentTypeId].path;\n if (!fieldPath) {\n // Path not found or degenerate shape (e.g. empty string '')\n return;\n }\n\n const fullDefaultValuePath = `/${SIDELOADED_PREFIX}${defaultEntryLink.sys.id}${fieldPath}`;\n return fullDefaultValuePath;\n }\n};\n"],"names":[],"mappings":";;;AAIO,MAAM,mBAAmB,GAA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AAE;;QAEvC,OAAO;KACR;IAED,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,gBAAgB,EAAE,GAAG,oBAAoB,CAAC,aAAa,CAAC;AAErF,IAAA,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE;;QAE7B,OAAO;KACR;AAED,IAAA,IAAI,aAAa,IAAI,oBAAoB,CAAC,YAAY,EAAE;QACtD,MAAM,MAAM,GAAG,WAAW,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;QAC/D,IAAI,CAAC,MAAM,EAAE;;;YAGX,OAAO;SACR;QAED,MAAM,SAAS,GAAG,eAAe,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC;QACzE,IAAI,CAAC,SAAS,EAAE;;YAEd,OAAO;SACR;AAED,QAAA,MAAM,oBAAoB,GAAG,CAAI,CAAA,EAAA,iBAAiB,CAAG,EAAA,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAG,EAAA,SAAS,EAAE,CAAC;AAC3F,QAAA,OAAO,oBAAoB,CAAC;KAC7B;AACH;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/experiences-sdk-react",
3
- "version": "3.8.0-dev-20250926T1559-e1ab24d.0",
3
+ "version": "3.8.0-prerelease-20250926T1312-a8b5fb7.0",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "typings": "./dist/src/index.d.ts",
@@ -41,10 +41,10 @@
41
41
  "depcruise": "depcruise src"
42
42
  },
43
43
  "dependencies": {
44
- "@contentful/experiences-components-react": "3.8.0-dev-20250926T1559-e1ab24d.0",
45
- "@contentful/experiences-core": "3.8.0-dev-20250926T1559-e1ab24d.0",
46
- "@contentful/experiences-validators": "3.8.0-dev-20250926T1559-e1ab24d.0",
47
- "@contentful/experiences-visual-editor-react": "3.8.0-dev-20250926T1559-e1ab24d.0",
44
+ "@contentful/experiences-components-react": "3.8.0-prerelease-20250926T1312-a8b5fb7.0",
45
+ "@contentful/experiences-core": "3.8.0-prerelease-20250926T1312-a8b5fb7.0",
46
+ "@contentful/experiences-validators": "3.8.0-prerelease-20250926T1312-a8b5fb7.0",
47
+ "@contentful/experiences-visual-editor-react": "3.8.0-prerelease-20250926T1312-a8b5fb7.0",
48
48
  "@contentful/rich-text-types": "^17.0.0",
49
49
  "csstype": "^3.1.2",
50
50
  "immer": "^10.0.3",
@@ -95,5 +95,5 @@
95
95
  "dist",
96
96
  "package.json"
97
97
  ],
98
- "gitHead": "f8d4de61859767b45b66ecd2d9ab5df6e899466c"
98
+ "gitHead": "997f59d83781aba41da311c32652d2e23720e2b9"
99
99
  }
@@ -1,249 +0,0 @@
1
- const NODE_ID_SEPARATOR = '---'; // separator used to separate pattern levels in deseralizePatternNode
2
- /**
3
- * PrebindingManager utility class for resolving parameter bindings across nested patterns.
4
- *
5
- * The core approach is to first resolve the top-level parameterId using `getParameterIdByNodeId`,
6
- * which uses the paramIdToOverwriteIdMap, set when storing pre-binding based on the passToNodes chain to determine which parameter in the parent pattern
7
- * overrides a given parameterId (with some additionally workaround due to node ID renaming for patterns).
8
- * Once the owning top-level `parameterId` is found, we can follow the `passToNodes` chain back
9
- * down to retrieve all nested overrides — including parameter definitions, allowed content types,
10
- * and default sources — up to three levels deep.
11
- *
12
- * ## Lifecycle
13
- * This utility class currently uses static state, with Zustand stores supplementing the “latest” data
14
- * for root-level patterns data — for example, when overwriting content types on nested patterns or binding
15
- * fields on simple patterns. If we need the override mappings to be reactive, we could easily move
16
- * the full override chain tracking into Zustand but currently we can rely on the pattern definition
17
- * stores we have currently.
18
- *
19
- * The state is populated during deserialization, where we call `storePrebindingDefinitions` for each
20
- * pattern node. It is ready to be consumed at each level as nodes are deserialized top-down:
21
- * 1. Pattern C (Template Pattern)
22
- * 2. Pattern B (Nested Pattern)
23
- * 3. Pattern A (Simple Pattern)
24
- *
25
- * At each level, accessing overrides is possible:
26
- * - Pattern C has everything it needs once deserialized with its own parameters
27
- * - Pattern B has everything it needs once deserialized, with its own parameters possibly overridden by C
28
- * - Pattern A has its own parameters and possiblle overrites by B and/or C
29
- *
30
- * After actions that modify patterns without re-deserializing the tree — such as duplication,
31
- * deletion, or detachment — this state must be kept up to date via storePrebindingDefinitions
32
- * or storeParameterDefinitions if only parameter definitions are updated.
33
- *
34
- * ## Core Data Structures
35
- *
36
- * - prebindingDefinitions - A collection of all prebinding definitions aggregated
37
- * from the parent pattern down to all nested patterns.
38
- *
39
- * - prebindingDefinitionIdsByNodeId - Same as above, but indexed by `nodeId`. This allows us
40
- * to easily find the prebinding definition id for a given node ID.
41
- *
42
- * - parameterDefinitionsById - A collection of all parameter definitions aggregated
43
- * from the parent pattern down to nested patterns.
44
- *
45
- * - variableMappingByPatternId - A collection of all variable mappings aggregated from
46
- * the parent pattern down to nested patterns, indexed by
47
- * `patternId` for efficient access.
48
- *
49
- * - newToOriginalNodeIdMap - When deserializing pattern child nodes, we replace their
50
- * node IDs with new ones based on their location inside the
51
- * pattern. This prevents conflicts when multiple instances
52
- * of the same pattern exist. The issue is that prebinding
53
- * `passToNodes` resolution requires the original node ID.
54
- * This map allows us to retrieve it to follow the chain.
55
- *
56
- * - paramIdToOverwriteIdMap - Tracks parameter ID overrides through the `passToNodes`
57
- * chain, allowing us to resolve overrides correctly from
58
- * the top-level parameter down to the lowest-level.
59
- */
60
- class PrebindingManager {
61
- static prebindingDefinitions = new Map();
62
- static prebindingDefinitionIdsByNodeId = new Map();
63
- static parameterDefinitionsById = new Map();
64
- static parameterDefinitionsByNodeId = new Map();
65
- static variableMappingByPatternId = new Map();
66
- static newToOriginalNodeIdMap = new Map();
67
- static paramIdToOverwriteIdMap = new Map();
68
- /**
69
- * Links new node IDs to original node IDs
70
- * - This is used to track the original node IDs for pattern instances as we change them when deserializing pattern nodes.
71
- * @param newNodeId
72
- * @param originalNodeId
73
- */
74
- static linkOriginalNodeIds(newNodeId, originalNodeId) {
75
- PrebindingManager.newToOriginalNodeIdMap.set(newNodeId, originalNodeId);
76
- }
77
- /**
78
- * Initializes the pattern editor manager by storing the definitions during deserialization
79
- * for the root pattern and all nested patterns.
80
- *
81
- * @param nodeId - The ID of the pattern node.
82
- * @param patternEntryId - The ID of the pattern entry from the patterns store.
83
- * @param prebindingDefinitions - The prebinding definitions from the current pattern's component settings.
84
- */
85
- static storePrebindingDefinitions(nodeId, patternEntryId, prebindingDefinitions) {
86
- for (const definition of prebindingDefinitions ?? []) {
87
- PrebindingManager.prebindingDefinitions.set(definition.id, { ...definition });
88
- PrebindingManager.prebindingDefinitionIdsByNodeId.set(nodeId, [definition.id]); // can only be one right now
89
- if (definition.variableMappings) {
90
- PrebindingManager.variableMappingByPatternId.set(patternEntryId, definition.variableMappings);
91
- }
92
- // Store the parameter definitions for the node
93
- PrebindingManager.storeParameterDefinitions(nodeId, definition.parameterDefinitions || {});
94
- }
95
- }
96
- /**
97
- * Stores parameter definitions for a given nodeId.
98
- * @param nodeId - The ID of the node to store parameter definitions for.
99
- * @param parameterDefinitions - The parameter definitions to store.
100
- */
101
- static storeParameterDefinitions(nodeId, parameterDefinitions) {
102
- // Reset the list of parameter definitions for the nodeId
103
- PrebindingManager.parameterDefinitionsByNodeId.set(nodeId, []);
104
- const updatedParameterDefinitionsByNodeId = [];
105
- for (const [parameterId, parameter] of Object.entries(parameterDefinitions || {})) {
106
- PrebindingManager.parameterDefinitionsById.set(parameterId, {
107
- parameterId,
108
- parameter,
109
- });
110
- if (parameter.passToNodes) {
111
- const { parameterId: paramIdToOverwrite, nodeId: targetNodeId } = parameter.passToNodes[0] ?? {};
112
- if (paramIdToOverwrite) {
113
- const existing = PrebindingManager.paramIdToOverwriteIdMap.get(paramIdToOverwrite) ?? [];
114
- const hasMatchingOverride = existing.some((it) => it.overwrittenByParamId === parameterId &&
115
- it.originalNodeIdToOverride === targetNodeId &&
116
- it.indexedParentPatternNodeId === nodeId);
117
- // Only add the override if it doesn't already exist to save duplicates
118
- if (!hasMatchingOverride) {
119
- PrebindingManager.paramIdToOverwriteIdMap.set(paramIdToOverwrite, [
120
- ...existing,
121
- {
122
- overwrittenByParamId: parameterId,
123
- originalNodeIdToOverride: targetNodeId,
124
- indexedParentPatternNodeId: nodeId,
125
- },
126
- ]);
127
- }
128
- }
129
- }
130
- updatedParameterDefinitionsByNodeId.push({ parameterId, parameter });
131
- }
132
- PrebindingManager.parameterDefinitionsByNodeId.set(nodeId, updatedParameterDefinitionsByNodeId);
133
- }
134
- /**
135
- * Resolves the top-level parameterId for a given nodeId.
136
- *
137
- * @param nodeId - The nodeId to resolve the parameterId for
138
- * @param useStoreParameters - Whether to use the zustand store parameters or not
139
- * @returns string | undefined - The resolved parameterId or undefined if not found
140
- **/
141
- static getParameterIdByNodeId(nodeId) {
142
- const nativeParameterDefinitionForNodeId = PrebindingManager.getNativeParameterDefinitionByNodeId(nodeId);
143
- if (!nativeParameterDefinitionForNodeId) {
144
- return undefined;
145
- }
146
- const hoistedParameterId = PrebindingManager.getHoistedIdForParameterId(nativeParameterDefinitionForNodeId?.parameterId, nodeId);
147
- return hoistedParameterId;
148
- }
149
- /* Returns the parameter definitions from a parameterId
150
- * @param parameterId - The parameter to resolve all levels for
151
- * @param useStoreParameters - Whether to use the zustand store parameters or not
152
- * @returns [l1ParameterDefinitions, l2ParameterDefinitions, l3ParameterDefinitions]: Array of parameter definitions for each level
153
- */
154
- static getParameterDefinitionsByParameterId(parameterId) {
155
- const l1Definition = PrebindingManager.parameterDefinitionsById.get(parameterId);
156
- const l1PassToNode = (l1Definition?.parameter?.passToNodes || [])[0];
157
- // Level 2
158
- const l2Definition = PrebindingManager.parameterDefinitionsById.get(l1PassToNode?.parameterId);
159
- const l2PassToNode = (l2Definition?.parameter?.passToNodes || [])[0];
160
- let l3Definition;
161
- // Level 3
162
- if (l2PassToNode) {
163
- // If the child definition has passToNodes, we can look up the child parameter definition by its composite key
164
- l3Definition = PrebindingManager.parameterDefinitionsById.get(l2PassToNode?.parameterId);
165
- }
166
- // Return the definitions for all three levels unless they are all empty
167
- const definitions = [l1Definition, l2Definition, l3Definition];
168
- if (!definitions || !definitions.filter(Boolean).length) {
169
- return undefined; // No definitions found
170
- }
171
- return definitions;
172
- }
173
- /**
174
- * Returns all parameter definitions defined on the pattern of the given nodeId OR the pattern, wrapping the given nodeId
175
- */
176
- static getAllParameterDefinitionsForNodeId(nodeId) {
177
- return Object.fromEntries((PrebindingManager.parameterDefinitionsByNodeId.get(nodeId) ?? []).map(({ parameterId, parameter }) => [parameterId, parameter]));
178
- }
179
- /**
180
- * Return all parameter ID's on a pattern by NodeId
181
- * @param nodeId - The nodeId to return params for
182
- * @returns string[] An array of parameter IDs or undefined
183
- */
184
- static getAllParameterIdsByNodeId(nodeId) {
185
- return Object.keys(PrebindingManager.getAllParameterDefinitionsForNodeId(nodeId));
186
- }
187
- /**
188
- * Get the highest level overriding parameterId for a given parameterId + nodeId combination
189
- * @param parameterId - The parameter to resolve
190
- * @param indexedNodeId - The indexed node ID to resolve the parameterId for
191
- * @returns string - The resolved parameterId - will be from "root" in patterns or the parent pattern node in experiences
192
- */
193
- static getHoistedIdForParameterId(parameterId, indexedNodeId) {
194
- let currentParamId = parameterId;
195
- let currentIndexedNodeId = indexedNodeId;
196
- let currentOriginalNodeId = PrebindingManager.newToOriginalNodeIdMap.get(indexedNodeId) ?? indexedNodeId;
197
- let override;
198
- do {
199
- const overrides = PrebindingManager.paramIdToOverwriteIdMap.get(currentParamId) ?? [];
200
- const splitByDash = currentIndexedNodeId.split(NODE_ID_SEPARATOR);
201
- override = overrides.find((it) => it.originalNodeIdToOverride === currentOriginalNodeId &&
202
- ((splitByDash.length > 1 &&
203
- currentIndexedNodeId.includes(it.indexedParentPatternNodeId)) ||
204
- (splitByDash.length === 1 && it.indexedParentPatternNodeId === 'root')));
205
- if (override) {
206
- const { overwrittenByParamId, indexedParentPatternNodeId } = override;
207
- currentParamId = overwrittenByParamId;
208
- currentIndexedNodeId = indexedParentPatternNodeId;
209
- currentOriginalNodeId =
210
- PrebindingManager.newToOriginalNodeIdMap.get(indexedParentPatternNodeId) ??
211
- indexedParentPatternNodeId;
212
- }
213
- } while (override);
214
- return currentParamId;
215
- }
216
- /**
217
- * Retrieves the native parameter definition for a given nodeId. ie one without passToNodes on the node.
218
- * @param nodeId - The nodeId to retrieve the native parameter definition for
219
- * @returns The native parameter definition for the given nodeId, or undefined if not found
220
- */
221
- static getNativeParameterDefinitionByNodeId(nodeId) {
222
- const parameterDefinitionsForNodeId = PrebindingManager.parameterDefinitionsByNodeId.get(nodeId);
223
- return PrebindingManager.extractNativeParameterDefinition(parameterDefinitionsForNodeId);
224
- }
225
- static extractNativeParameterDefinition(parameterDefinitions) {
226
- const { parameterId, parameter } = parameterDefinitions?.find((it) => !it.parameter.passToNodes?.length) || {};
227
- if (!parameterId || !parameter)
228
- return;
229
- return {
230
- parameterId,
231
- parameter,
232
- };
233
- }
234
- /**
235
- * Resets all properties of the PrebindingManager class
236
- * triggered when we leave ExperienceBuilder back to experience folder view.
237
- **/
238
- static reset() {
239
- PrebindingManager.prebindingDefinitions = new Map();
240
- PrebindingManager.parameterDefinitionsById = new Map();
241
- PrebindingManager.parameterDefinitionsByNodeId = new Map();
242
- PrebindingManager.variableMappingByPatternId = new Map();
243
- PrebindingManager.newToOriginalNodeIdMap = new Map();
244
- PrebindingManager.paramIdToOverwriteIdMap = new Map();
245
- }
246
- }
247
-
248
- export { PrebindingManager };
249
- //# sourceMappingURL=PrebindingManager.js.map