@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.
- package/dist/blocks/preview/CompositionBlock.js +36 -39
- package/dist/blocks/preview/CompositionBlock.js.map +1 -1
- package/dist/blocks/preview/PreviewDeliveryRoot.js +1 -18
- package/dist/blocks/preview/PreviewDeliveryRoot.js.map +1 -1
- package/dist/core/preview/assemblyUtils.js +38 -74
- package/dist/core/preview/assemblyUtils.js.map +1 -1
- package/dist/core/styles/createStylesheetsForBuiltInStyles.js +1 -1
- package/dist/core/styles/createStylesheetsForBuiltInStyles.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/sdkVersion.js +1 -1
- package/dist/sdkVersion.js.map +1 -1
- package/dist/src/blocks/preview/CompositionBlock.d.ts +3 -3
- package/dist/src/blocks/preview/PreviewDeliveryRoot.d.ts +1 -1
- package/dist/src/core/preview/assemblyUtils.d.ts +8 -17
- package/dist/src/core/styles/createStylesheetsForBuiltInStyles.d.ts +1 -1
- package/dist/src/sdkVersion.d.ts +1 -1
- package/dist/src/utils/parseComponentProps.d.ts +3 -9
- package/dist/src/utils/prebindingUtils.d.ts +3 -6
- package/dist/test/__fixtures__/assembly.d.ts +2 -5
- package/dist/utils/parseComponentProps.js +2 -2
- package/dist/utils/parseComponentProps.js.map +1 -1
- package/dist/utils/prebindingUtils.js +11 -25
- package/dist/utils/prebindingUtils.js.map +1 -1
- package/package.json +6 -6
- package/dist/core/preview/PrebindingManager.js +0 -249
- package/dist/core/preview/PrebindingManager.js.map +0 -1
- package/dist/src/core/preview/PrebindingManager.d.ts +0 -152
- package/dist/src/core/preview/PrebindingManager.test.d.ts +0 -1
- package/dist/src/core/preview/__fixtures__.d.ts +0 -517
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import React, { useMemo } from 'react';
|
|
3
|
-
import { checkIsAssemblyNode, transformBoundContentValue, resolveHyperlinkPattern, splitDirectAndSlotChildren, getSdkOptions, sanitizeNodeProps } from '@contentful/experiences-core';
|
|
3
|
+
import { checkIsAssemblyNode, checkIsAssemblyEntry, transformBoundContentValue, resolveHyperlinkPattern, splitDirectAndSlotChildren, getSdkOptions, sanitizeNodeProps } from '@contentful/experiences-core';
|
|
4
4
|
import { HYPERLINK_DEFAULT_PATTERN, CONTENTFUL_COMPONENTS } from '@contentful/experiences-core/constants';
|
|
5
5
|
import { getComponentRegistration, createAssemblyRegistration } from '../../core/componentRegistry.js';
|
|
6
6
|
import { useInjectStylesheet } from '../../hooks/useInjectStylesheet.js';
|
|
@@ -9,53 +9,51 @@ import { resolvePattern } from '../../core/preview/assemblyUtils.js';
|
|
|
9
9
|
import { resolveMaybePrebindingDefaultValuePath } from '../../utils/prebindingUtils.js';
|
|
10
10
|
import { parseComponentProps } from '../../utils/parseComponentProps.js';
|
|
11
11
|
|
|
12
|
-
const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern, resolveDesignValue, getPatternChildNodeClassName, wrappingPatternIds: parentWrappingPatternIds = new Set(), patternRootNodeIdsChain: parentPatternRootNodeIdsChain =
|
|
12
|
+
const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern, resolveDesignValue, getPatternChildNodeClassName, wrappingPatternIds: parentWrappingPatternIds = new Set(), wrappingParameters: parentWrappingParameters = {}, patternRootNodeIdsChain: parentPatternRootNodeIdsChain = '', }) => {
|
|
13
13
|
const isPatternNode = useMemo(() => {
|
|
14
14
|
return checkIsAssemblyNode({
|
|
15
15
|
componentId: rawNode.definitionId,
|
|
16
16
|
usedComponents: entityStore.usedComponents,
|
|
17
17
|
});
|
|
18
18
|
}, [entityStore.usedComponents, rawNode.definitionId]);
|
|
19
|
+
const isPatternEntry = useMemo(() => {
|
|
20
|
+
return checkIsAssemblyEntry({ fields: entityStore.experienceEntryFields });
|
|
21
|
+
}, [entityStore]);
|
|
19
22
|
const patternRootNodeIdsChain = useMemo(() => {
|
|
20
23
|
if (isPatternNode) {
|
|
21
24
|
// Pattern nodes are chained without a separator (following the format for prebinding/parameters)
|
|
22
|
-
return
|
|
25
|
+
return `${parentPatternRootNodeIdsChain}${rawNode.id}`;
|
|
23
26
|
}
|
|
24
27
|
return parentPatternRootNodeIdsChain;
|
|
25
28
|
}, [isPatternNode, parentPatternRootNodeIdsChain, rawNode.id]);
|
|
26
|
-
const rootParameters = useMemo(() => {
|
|
27
|
-
// covers the case when previewing a pattern
|
|
28
|
-
// all parameters are defined on the tree root node and will be provided from the start
|
|
29
|
-
if (rootPatternParameters) {
|
|
30
|
-
return rootPatternParameters;
|
|
31
|
-
}
|
|
32
|
-
// covers the case when previewing an experience
|
|
33
|
-
// parameters here are stored in CMA, so we retrieve them from the pattern's node and pass it down
|
|
34
|
-
if (isPatternNode && rawNode.parameters && Object.keys(rawNode.parameters).length) {
|
|
35
|
-
return rawNode.parameters;
|
|
36
|
-
}
|
|
37
|
-
// in case none exist - it is likely a non-pattern component, or just a pattern that has no parameters
|
|
38
|
-
return undefined;
|
|
39
|
-
}, [rawNode, rootPatternParameters, isPatternNode]);
|
|
40
29
|
const node = useMemo(() => {
|
|
41
30
|
if (isPatternNode) {
|
|
42
31
|
return resolvePattern({
|
|
43
32
|
node: rawNode,
|
|
44
33
|
entityStore,
|
|
45
|
-
|
|
46
|
-
|
|
34
|
+
parentParameters: parentWrappingParameters,
|
|
35
|
+
patternRootNodeIdsChain,
|
|
47
36
|
});
|
|
48
37
|
}
|
|
49
38
|
else {
|
|
50
39
|
return rawNode;
|
|
51
40
|
}
|
|
52
|
-
}, [entityStore, isPatternNode, rawNode,
|
|
41
|
+
}, [entityStore, isPatternNode, rawNode, parentWrappingParameters, patternRootNodeIdsChain]);
|
|
53
42
|
const wrappingPatternIds = useMemo(() => {
|
|
54
43
|
if (isPatternNode) {
|
|
55
44
|
return new Set([node.definitionId, ...parentWrappingPatternIds]);
|
|
56
45
|
}
|
|
57
46
|
return parentWrappingPatternIds;
|
|
58
47
|
}, [isPatternNode, node, parentWrappingPatternIds]);
|
|
48
|
+
// Merge the pattern properties of the current node with the parent's pattern properties
|
|
49
|
+
// to ensure nested patterns receive relevant pattern properties that were bubbled up
|
|
50
|
+
// during assembly serialization.
|
|
51
|
+
const wrappingParameters = useMemo(() => {
|
|
52
|
+
if (isPatternNode) {
|
|
53
|
+
return { ...parentWrappingParameters, ...(rawNode.parameters || {}) };
|
|
54
|
+
}
|
|
55
|
+
return parentWrappingParameters;
|
|
56
|
+
}, [isPatternNode, rawNode, parentWrappingParameters]);
|
|
59
57
|
const componentRegistration = useMemo(() => {
|
|
60
58
|
const registration = getComponentRegistration(node.definitionId);
|
|
61
59
|
if (isPatternNode && !registration) {
|
|
@@ -107,24 +105,22 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
|
|
|
107
105
|
resolveUnboundValue: ({ mappingKey, defaultValue }) => {
|
|
108
106
|
return entityStore.unboundValues[mappingKey]?.value ?? defaultValue;
|
|
109
107
|
},
|
|
110
|
-
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
componentValueKey: mappingKey,
|
|
116
|
-
patternRootNodeIdsChain,
|
|
117
|
-
entityStore,
|
|
118
|
-
});
|
|
119
|
-
if (path) {
|
|
120
|
-
return resolveBoundValue({
|
|
121
|
-
propertyName,
|
|
122
|
-
dataType,
|
|
123
|
-
binding: {
|
|
124
|
-
type: 'BoundValue',
|
|
125
|
-
path,
|
|
126
|
-
},
|
|
108
|
+
resolvePrebindingValue: ({ mappingKey, propertyName, dataType, resolveBoundValue }) => {
|
|
109
|
+
if (isPatternEntry) {
|
|
110
|
+
const path = resolveMaybePrebindingDefaultValuePath({
|
|
111
|
+
componentValueKey: mappingKey,
|
|
112
|
+
entityStore,
|
|
127
113
|
});
|
|
114
|
+
if (path) {
|
|
115
|
+
return resolveBoundValue({
|
|
116
|
+
propertyName,
|
|
117
|
+
dataType,
|
|
118
|
+
binding: {
|
|
119
|
+
type: 'BoundValue',
|
|
120
|
+
path,
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
}
|
|
128
124
|
}
|
|
129
125
|
},
|
|
130
126
|
});
|
|
@@ -142,6 +138,7 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
|
|
|
142
138
|
};
|
|
143
139
|
}, [
|
|
144
140
|
node,
|
|
141
|
+
isPatternEntry,
|
|
145
142
|
entityStore,
|
|
146
143
|
componentRegistration,
|
|
147
144
|
isPatternNode,
|
|
@@ -164,7 +161,7 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
|
|
|
164
161
|
// Retrieves the CSS class name for a given child node ID.
|
|
165
162
|
const _getPatternChildNodeClassName = (childNodeId) => {
|
|
166
163
|
if (isPatternNode) {
|
|
167
|
-
const nodeIdsChain =
|
|
164
|
+
const nodeIdsChain = `${patternRootNodeIdsChain}-${childNodeId}`;
|
|
168
165
|
// @ts-expect-error -- property cfSsrClassName is a map (id to classNames) that is added during rendering in ssrStyles
|
|
169
166
|
const classesForNode = node.variables.cfSsrClassName?.[nodeIdsChain];
|
|
170
167
|
if (!classesForNode)
|
|
@@ -174,7 +171,7 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
|
|
|
174
171
|
return getPatternChildNodeClassName?.(childNodeId);
|
|
175
172
|
};
|
|
176
173
|
const { slotNodesMap, directChildNodes } = splitDirectAndSlotChildren(node.children, componentRegistration.definition);
|
|
177
|
-
const renderChildNode = (childNode, index) => (jsx(CompositionBlock, { getPatternChildNodeClassName: isPatternNode || getPatternChildNodeClassName ? _getPatternChildNodeClassName : undefined, node: childNode, locale: locale, hyperlinkPattern: hyperlinkPattern, entityStore: entityStore, resolveDesignValue: resolveDesignValue, wrappingPatternIds: wrappingPatternIds,
|
|
174
|
+
const renderChildNode = (childNode, index) => (jsx(CompositionBlock, { getPatternChildNodeClassName: isPatternNode || getPatternChildNodeClassName ? _getPatternChildNodeClassName : undefined, node: childNode, locale: locale, hyperlinkPattern: hyperlinkPattern, entityStore: entityStore, resolveDesignValue: resolveDesignValue, wrappingPatternIds: wrappingPatternIds, wrappingParameters: wrappingParameters, patternRootNodeIdsChain: patternRootNodeIdsChain }, childNode.id ?? index));
|
|
178
175
|
const renderedSlotNodesMap = Object.entries(slotNodesMap).reduce((acc, [slotId, nodes]) => {
|
|
179
176
|
if (nodes?.length) {
|
|
180
177
|
acc[slotId] = jsx(Fragment, { children: nodes.map(renderChildNode) });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompositionBlock.js","sources":["../../../../src/blocks/preview/CompositionBlock.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport type { UnresolvedLink } from 'contentful';\nimport { Entry } from 'contentful';\nimport {\n checkIsAssemblyNode,\n EntityStore,\n resolveHyperlinkPattern,\n sanitizeNodeProps,\n transformBoundContentValue,\n splitDirectAndSlotChildren,\n getSdkOptions,\n} from '@contentful/experiences-core';\nimport {\n CONTENTFUL_COMPONENTS,\n HYPERLINK_DEFAULT_PATTERN,\n} from '@contentful/experiences-core/constants';\nimport type {\n ComponentTreeNode,\n DesignValue,\n Parameter,\n PrimitiveValue,\n ResolveDesignValueType,\n StyleProps,\n} from '@contentful/experiences-core/types';\nimport { createAssemblyRegistration, getComponentRegistration } from '../../core/componentRegistry';\nimport { useInjectStylesheet } from '../../hooks/useInjectStylesheet';\nimport { Assembly, ContentfulContainer } from '@contentful/experiences-components-react';\nimport { resolvePattern } from '../../core/preview/assemblyUtils';\nimport { resolveMaybePrebindingDefaultValuePath } from '../../utils/prebindingUtils';\nimport { parseComponentProps } from '../../utils/parseComponentProps';\n\ntype CompositionBlockProps = {\n node: ComponentTreeNode;\n locale: string;\n entityStore: EntityStore;\n hyperlinkPattern?: string | undefined;\n resolveDesignValue: ResolveDesignValueType;\n getPatternChildNodeClassName?: (childNodeId: string) => string | undefined;\n /** Set of definition IDs of wrapping patterns to prevent circular dependencies. */\n wrappingPatternIds?: Set<string>;\n rootPatternParameters?: Record<string, Parameter>;\n /**\n * Chained IDs to ensure uniqueness across multiple instances of the same pattern\n * when storing & accessing cfSsrClassName.\n */\n patternRootNodeIdsChain?: Array<string>;\n};\n\nexport const CompositionBlock = ({\n node: rawNode,\n locale,\n entityStore,\n hyperlinkPattern,\n resolveDesignValue,\n getPatternChildNodeClassName,\n wrappingPatternIds: parentWrappingPatternIds = new Set(),\n patternRootNodeIdsChain: parentPatternRootNodeIdsChain = [],\n rootPatternParameters,\n}: CompositionBlockProps) => {\n const isPatternNode = useMemo(() => {\n return checkIsAssemblyNode({\n componentId: rawNode.definitionId,\n usedComponents: entityStore.usedComponents,\n });\n }, [entityStore.usedComponents, rawNode.definitionId]);\n\n const patternRootNodeIdsChain = useMemo(() => {\n if (isPatternNode) {\n // Pattern nodes are chained without a separator (following the format for prebinding/parameters)\n return [...parentPatternRootNodeIdsChain, rawNode.id!];\n }\n return parentPatternRootNodeIdsChain;\n }, [isPatternNode, parentPatternRootNodeIdsChain, rawNode.id]);\n\n const rootParameters = useMemo(() => {\n // covers the case when previewing a pattern\n // all parameters are defined on the tree root node and will be provided from the start\n if (rootPatternParameters) {\n return rootPatternParameters;\n }\n\n // covers the case when previewing an experience\n // parameters here are stored in CMA, so we retrieve them from the pattern's node and pass it down\n if (isPatternNode && rawNode.parameters && Object.keys(rawNode.parameters).length) {\n return rawNode.parameters;\n }\n\n // in case none exist - it is likely a non-pattern component, or just a pattern that has no parameters\n return undefined;\n }, [rawNode, rootPatternParameters, isPatternNode]);\n\n const node = useMemo(() => {\n if (isPatternNode) {\n return resolvePattern({\n node: rawNode,\n entityStore,\n parentPatternRootNodeIdsChain: patternRootNodeIdsChain,\n rootPatternParameters: rootParameters!,\n });\n } else {\n return rawNode;\n }\n }, [entityStore, isPatternNode, rawNode, patternRootNodeIdsChain, rootParameters]);\n\n const wrappingPatternIds = useMemo(() => {\n if (isPatternNode) {\n return new Set([node.definitionId, ...parentWrappingPatternIds]);\n }\n return parentWrappingPatternIds;\n }, [isPatternNode, node, parentWrappingPatternIds]);\n\n const componentRegistration = useMemo(() => {\n const registration = getComponentRegistration(node.definitionId as string);\n\n if (isPatternNode && !registration) {\n return createAssemblyRegistration({\n definitionId: node.definitionId as string,\n component: Assembly,\n });\n }\n return registration;\n }, [isPatternNode, node.definitionId]);\n\n const { ssrProps, contentProps, props, mediaQuery } = useMemo(() => {\n // In SSR, we store the className under breakpoints[0] which is resolved here to the actual string\n const cfSsrClassNameValues = node.variables.cfSsrClassName as DesignValue | undefined;\n const mainBreakpoint = entityStore.breakpoints[0];\n const cfSsrClassName = cfSsrClassNameValues?.valuesByBreakpoint?.[mainBreakpoint.id] as\n | string\n | undefined;\n\n // Don't enrich the assembly wrapper node with props\n if (!componentRegistration || isPatternNode) {\n const ssrProps = { cfSsrClassName };\n const props: Record<string, PrimitiveValue> = { className: cfSsrClassName };\n return {\n ssrProps,\n props,\n };\n }\n\n const ssrProps: Record<string, string | undefined> = {\n cfSsrClassName:\n node.id && getPatternChildNodeClassName\n ? getPatternChildNodeClassName(node.id)\n : cfSsrClassName,\n };\n\n const {\n contentProps = {},\n styleProps = {},\n customDesignProps = {},\n mediaQuery,\n } = parseComponentProps({\n breakpoints: entityStore.breakpoints,\n mainBreakpoint,\n componentDefinition: componentRegistration.definition,\n patternRootNodeIdsChain,\n node,\n resolveDesignValue,\n resolveBoundValue: ({ binding, propertyName, dataType }) => {\n const [, uuid] = binding.path.split('/');\n const boundEntityLink = entityStore.dataSource[uuid] as UnresolvedLink<'Entry' | 'Asset'>;\n return transformBoundContentValue(\n node.variables,\n entityStore,\n boundEntityLink,\n resolveDesignValue,\n propertyName,\n dataType,\n binding.path,\n );\n },\n resolveHyperlinkValue: ({ linkTargetKey }) => {\n const boundEntity = entityStore.dataSource[linkTargetKey];\n const hyperlinkEntry = entityStore.getEntryOrAsset(boundEntity, linkTargetKey);\n\n return resolveHyperlinkPattern(\n componentRegistration.definition.hyperlinkPattern ||\n hyperlinkPattern ||\n HYPERLINK_DEFAULT_PATTERN,\n hyperlinkEntry as Entry,\n locale,\n );\n },\n resolveUnboundValue: ({ mappingKey, defaultValue }) => {\n return entityStore.unboundValues[mappingKey]?.value ?? defaultValue;\n },\n resolveComponentValue: ({ mappingKey, propertyName, dataType, resolveBoundValue }) => {\n if (!entityStore.isExperienceAPatternEntry) {\n return;\n }\n\n const path = resolveMaybePrebindingDefaultValuePath({\n componentValueKey: mappingKey,\n patternRootNodeIdsChain,\n entityStore,\n });\n\n if (path) {\n return resolveBoundValue({\n propertyName,\n dataType,\n binding: {\n type: 'BoundValue',\n path,\n },\n });\n }\n },\n });\n\n const props: Record<string, PrimitiveValue> = {\n className: ssrProps.cfSsrClassName ?? mediaQuery?.className,\n ...styleProps,\n ...contentProps,\n ...customDesignProps,\n };\n\n return {\n ssrProps,\n contentProps,\n mediaQuery,\n props,\n };\n }, [\n node,\n entityStore,\n componentRegistration,\n isPatternNode,\n getPatternChildNodeClassName,\n resolveDesignValue,\n hyperlinkPattern,\n locale,\n patternRootNodeIdsChain,\n ]);\n\n // do not inject the stylesheet into the dom because it's already been done on the server side\n useInjectStylesheet(ssrProps.cfSsrClassName ? undefined : mediaQuery?.css);\n\n if (!componentRegistration) {\n return null;\n }\n\n // When detecting a circular dependency, we stop silently. The editor mode will render an actionable error.\n if (parentWrappingPatternIds.has(node.definitionId)) {\n return null;\n }\n\n const { component: component } = componentRegistration;\n\n // Retrieves the CSS class name for a given child node ID.\n const _getPatternChildNodeClassName = (childNodeId: string) => {\n if (isPatternNode) {\n const nodeIdsChain = [...patternRootNodeIdsChain, childNodeId].join('-');\n // @ts-expect-error -- property cfSsrClassName is a map (id to classNames) that is added during rendering in ssrStyles\n const classesForNode: DesignValue | undefined = node.variables.cfSsrClassName?.[nodeIdsChain];\n if (!classesForNode) return undefined;\n return resolveDesignValue(classesForNode.valuesByBreakpoint) as string;\n }\n return getPatternChildNodeClassName?.(childNodeId);\n };\n\n const { slotNodesMap, directChildNodes } = splitDirectAndSlotChildren(\n node.children,\n componentRegistration.definition,\n );\n\n const renderChildNode = (childNode: ComponentTreeNode, index: number) => (\n <CompositionBlock\n getPatternChildNodeClassName={\n isPatternNode || getPatternChildNodeClassName ? _getPatternChildNodeClassName : undefined\n }\n node={childNode}\n key={childNode.id ?? index}\n locale={locale}\n hyperlinkPattern={hyperlinkPattern}\n entityStore={entityStore}\n resolveDesignValue={resolveDesignValue}\n wrappingPatternIds={wrappingPatternIds}\n patternRootNodeIdsChain={patternRootNodeIdsChain}\n rootPatternParameters={rootParameters}\n />\n );\n\n const renderedSlotNodesMap = Object.entries(slotNodesMap).reduce(\n (acc, [slotId, nodes]) => {\n if (nodes?.length) {\n acc[slotId] = <>{nodes.map(renderChildNode)}</>;\n }\n return acc;\n },\n {} as Record<string, React.JSX.Element>,\n );\n\n const renderedChildren = directChildNodes?.map(renderChildNode);\n\n const sdkOptions = getSdkOptions();\n\n // TODO: we might be able to remove this special case as well by not dropping the two props in the sanitizeNodeProps function\n // We allow custom container rendering through a new sdk option (not introducing a breaking change for existing customers).\n if (\n isContainerOrSection(node.definitionId) &&\n !sdkOptions.__unsafe__enableBuiltInStructureOverwrites\n ) {\n return (\n <ContentfulContainer\n cfHyperlink={(contentProps as StyleProps).cfHyperlink}\n cfOpenInNewTab={(contentProps as StyleProps).cfOpenInNewTab}\n className={props.className as string | undefined}>\n {renderedChildren}\n </ContentfulContainer>\n );\n }\n\n return React.createElement(\n component,\n {\n ...sanitizeNodeProps(props),\n ...renderedSlotNodesMap,\n },\n // If there are no children, a custom property called `children` can be passed through to the custom component\n ...(renderedChildren ?? []),\n );\n};\n\nconst isContainerOrSection = (\n nodeDefinitionId: string,\n): nodeDefinitionId is 'contentful-container' | 'contentful-section' =>\n [CONTENTFUL_COMPONENTS.container.id, CONTENTFUL_COMPONENTS.section.id].includes(\n nodeDefinitionId as 'contentful-container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B,IAAI,EAAE,CAAC,CAC5B,CAAC;AACJ,EAAE;AAEF,MAAM,oBAAoB,GAAG,CAC3B,gBAAwB,KAExB,CAAC,qBAAqB,CAAC,SAAS,CAAC,EAAE,EAAE,qBAAqB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,QAAQ,CAC7E,gBAAiE,CAClE;;;;"}
|
|
1
|
+
{"version":3,"file":"CompositionBlock.js","sources":["../../../../src/blocks/preview/CompositionBlock.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport type { UnresolvedLink } from 'contentful';\nimport { Entry } from 'contentful';\nimport {\n checkIsAssemblyEntry,\n checkIsAssemblyNode,\n EntityStore,\n resolveHyperlinkPattern,\n sanitizeNodeProps,\n transformBoundContentValue,\n splitDirectAndSlotChildren,\n getSdkOptions,\n} from '@contentful/experiences-core';\nimport {\n CONTENTFUL_COMPONENTS,\n HYPERLINK_DEFAULT_PATTERN,\n} from '@contentful/experiences-core/constants';\nimport type {\n ComponentTreeNode,\n DesignValue,\n Parameter,\n PrimitiveValue,\n ResolveDesignValueType,\n StyleProps,\n} from '@contentful/experiences-core/types';\nimport { createAssemblyRegistration, getComponentRegistration } from '../../core/componentRegistry';\nimport { useInjectStylesheet } from '../../hooks/useInjectStylesheet';\nimport { Assembly, ContentfulContainer } from '@contentful/experiences-components-react';\nimport { resolvePattern } from '../../core/preview/assemblyUtils';\nimport { resolveMaybePrebindingDefaultValuePath } from '../../utils/prebindingUtils';\nimport { parseComponentProps } from '../../utils/parseComponentProps';\n\ntype CompositionBlockProps = {\n node: ComponentTreeNode;\n locale: string;\n entityStore: EntityStore;\n hyperlinkPattern?: string | undefined;\n resolveDesignValue: ResolveDesignValueType;\n getPatternChildNodeClassName?: (childNodeId: string) => string | undefined;\n /** Set of definition IDs of wrapping patterns to prevent circular dependencies. */\n wrappingPatternIds?: Set<string>;\n /**\n * Chained IDs to ensure uniqueness across multiple instances of the same pattern\n * when storing & accessing cfSsrClassName.\n */\n patternRootNodeIdsChain?: string;\n wrappingParameters?: Record<string, Parameter>;\n};\n\nexport const CompositionBlock = ({\n node: rawNode,\n locale,\n entityStore,\n hyperlinkPattern,\n resolveDesignValue,\n getPatternChildNodeClassName,\n wrappingPatternIds: parentWrappingPatternIds = new Set(),\n wrappingParameters: parentWrappingParameters = {},\n patternRootNodeIdsChain: parentPatternRootNodeIdsChain = '',\n}: CompositionBlockProps) => {\n const isPatternNode = useMemo(() => {\n return checkIsAssemblyNode({\n componentId: rawNode.definitionId,\n usedComponents: entityStore.usedComponents,\n });\n }, [entityStore.usedComponents, rawNode.definitionId]);\n\n const isPatternEntry = useMemo(() => {\n return checkIsAssemblyEntry({ fields: entityStore.experienceEntryFields } as unknown as Entry);\n }, [entityStore]);\n\n const patternRootNodeIdsChain = useMemo(() => {\n if (isPatternNode) {\n // Pattern nodes are chained without a separator (following the format for prebinding/parameters)\n return `${parentPatternRootNodeIdsChain}${rawNode.id}`;\n }\n return parentPatternRootNodeIdsChain;\n }, [isPatternNode, parentPatternRootNodeIdsChain, rawNode.id]);\n\n const node = useMemo(() => {\n if (isPatternNode) {\n return resolvePattern({\n node: rawNode,\n entityStore,\n parentParameters: parentWrappingParameters,\n patternRootNodeIdsChain,\n });\n } else {\n return rawNode;\n }\n }, [entityStore, isPatternNode, rawNode, parentWrappingParameters, patternRootNodeIdsChain]);\n\n const wrappingPatternIds = useMemo(() => {\n if (isPatternNode) {\n return new Set([node.definitionId, ...parentWrappingPatternIds]);\n }\n return parentWrappingPatternIds;\n }, [isPatternNode, node, parentWrappingPatternIds]);\n\n // Merge the pattern properties of the current node with the parent's pattern properties\n // to ensure nested patterns receive relevant pattern properties that were bubbled up\n // during assembly serialization.\n const wrappingParameters = useMemo(() => {\n if (isPatternNode) {\n return { ...parentWrappingParameters, ...(rawNode.parameters || {}) };\n }\n return parentWrappingParameters;\n }, [isPatternNode, rawNode, parentWrappingParameters]);\n\n const componentRegistration = useMemo(() => {\n const registration = getComponentRegistration(node.definitionId as string);\n\n if (isPatternNode && !registration) {\n return createAssemblyRegistration({\n definitionId: node.definitionId as string,\n component: Assembly,\n });\n }\n return registration;\n }, [isPatternNode, node.definitionId]);\n\n const { ssrProps, contentProps, props, mediaQuery } = useMemo(() => {\n // In SSR, we store the className under breakpoints[0] which is resolved here to the actual string\n const cfSsrClassNameValues = node.variables.cfSsrClassName as DesignValue | undefined;\n const mainBreakpoint = entityStore.breakpoints[0];\n const cfSsrClassName = cfSsrClassNameValues?.valuesByBreakpoint?.[mainBreakpoint.id] as\n | string\n | undefined;\n\n // Don't enrich the assembly wrapper node with props\n if (!componentRegistration || isPatternNode) {\n const ssrProps = { cfSsrClassName };\n const props: Record<string, PrimitiveValue> = { className: cfSsrClassName };\n return {\n ssrProps,\n props,\n };\n }\n\n const ssrProps: Record<string, string | undefined> = {\n cfSsrClassName:\n node.id && getPatternChildNodeClassName\n ? getPatternChildNodeClassName(node.id)\n : cfSsrClassName,\n };\n\n const {\n contentProps = {},\n styleProps = {},\n customDesignProps = {},\n mediaQuery,\n } = parseComponentProps({\n breakpoints: entityStore.breakpoints,\n mainBreakpoint,\n componentDefinition: componentRegistration.definition,\n patternRootNodeIdsChain,\n node,\n resolveDesignValue,\n resolveBoundValue: ({ binding, propertyName, dataType }) => {\n const [, uuid] = binding.path.split('/');\n const boundEntityLink = entityStore.dataSource[uuid] as UnresolvedLink<'Entry' | 'Asset'>;\n return transformBoundContentValue(\n node.variables,\n entityStore,\n boundEntityLink,\n resolveDesignValue,\n propertyName,\n dataType,\n binding.path,\n );\n },\n resolveHyperlinkValue: ({ linkTargetKey }) => {\n const boundEntity = entityStore.dataSource[linkTargetKey];\n const hyperlinkEntry = entityStore.getEntryOrAsset(boundEntity, linkTargetKey);\n\n return resolveHyperlinkPattern(\n componentRegistration.definition.hyperlinkPattern ||\n hyperlinkPattern ||\n HYPERLINK_DEFAULT_PATTERN,\n hyperlinkEntry as Entry,\n locale,\n );\n },\n resolveUnboundValue: ({ mappingKey, defaultValue }) => {\n return entityStore.unboundValues[mappingKey]?.value ?? defaultValue;\n },\n resolvePrebindingValue: ({ mappingKey, propertyName, dataType, resolveBoundValue }) => {\n if (isPatternEntry) {\n const path = resolveMaybePrebindingDefaultValuePath({\n componentValueKey: mappingKey,\n entityStore,\n });\n\n if (path) {\n return resolveBoundValue({\n propertyName,\n dataType,\n binding: {\n type: 'BoundValue',\n path,\n },\n });\n }\n }\n },\n });\n\n const props: Record<string, PrimitiveValue> = {\n className: ssrProps.cfSsrClassName ?? mediaQuery?.className,\n ...styleProps,\n ...contentProps,\n ...customDesignProps,\n };\n\n return {\n ssrProps,\n contentProps,\n mediaQuery,\n props,\n };\n }, [\n node,\n isPatternEntry,\n entityStore,\n componentRegistration,\n isPatternNode,\n getPatternChildNodeClassName,\n resolveDesignValue,\n hyperlinkPattern,\n locale,\n patternRootNodeIdsChain,\n ]);\n\n // do not inject the stylesheet into the dom because it's already been done on the server side\n useInjectStylesheet(ssrProps.cfSsrClassName ? undefined : mediaQuery?.css);\n\n if (!componentRegistration) {\n return null;\n }\n\n // When detecting a circular dependency, we stop silently. The editor mode will render an actionable error.\n if (parentWrappingPatternIds.has(node.definitionId)) {\n return null;\n }\n\n const { component: component } = componentRegistration;\n\n // Retrieves the CSS class name for a given child node ID.\n const _getPatternChildNodeClassName = (childNodeId: string) => {\n if (isPatternNode) {\n const nodeIdsChain = `${patternRootNodeIdsChain}-${childNodeId}`;\n // @ts-expect-error -- property cfSsrClassName is a map (id to classNames) that is added during rendering in ssrStyles\n const classesForNode: DesignValue | undefined = node.variables.cfSsrClassName?.[nodeIdsChain];\n if (!classesForNode) return undefined;\n return resolveDesignValue(classesForNode.valuesByBreakpoint) as string;\n }\n return getPatternChildNodeClassName?.(childNodeId);\n };\n\n const { slotNodesMap, directChildNodes } = splitDirectAndSlotChildren(\n node.children,\n componentRegistration.definition,\n );\n\n const renderChildNode = (childNode: ComponentTreeNode, index: number) => (\n <CompositionBlock\n getPatternChildNodeClassName={\n isPatternNode || getPatternChildNodeClassName ? _getPatternChildNodeClassName : undefined\n }\n node={childNode}\n key={childNode.id ?? index}\n locale={locale}\n hyperlinkPattern={hyperlinkPattern}\n entityStore={entityStore}\n resolveDesignValue={resolveDesignValue}\n wrappingPatternIds={wrappingPatternIds}\n wrappingParameters={wrappingParameters}\n patternRootNodeIdsChain={patternRootNodeIdsChain}\n />\n );\n\n const renderedSlotNodesMap = Object.entries(slotNodesMap).reduce(\n (acc, [slotId, nodes]) => {\n if (nodes?.length) {\n acc[slotId] = <>{nodes.map(renderChildNode)}</>;\n }\n return acc;\n },\n {} as Record<string, React.JSX.Element>,\n );\n\n const renderedChildren = directChildNodes?.map(renderChildNode);\n\n const sdkOptions = getSdkOptions();\n\n // TODO: we might be able to remove this special case as well by not dropping the two props in the sanitizeNodeProps function\n // We allow custom container rendering through a new sdk option (not introducing a breaking change for existing customers).\n if (\n isContainerOrSection(node.definitionId) &&\n !sdkOptions.__unsafe__enableBuiltInStructureOverwrites\n ) {\n return (\n <ContentfulContainer\n cfHyperlink={(contentProps as StyleProps).cfHyperlink}\n cfOpenInNewTab={(contentProps as StyleProps).cfOpenInNewTab}\n className={props.className as string | undefined}>\n {renderedChildren}\n </ContentfulContainer>\n );\n }\n\n return React.createElement(\n component,\n {\n ...sanitizeNodeProps(props),\n ...renderedSlotNodesMap,\n },\n // If there are no children, a custom property called `children` can be passed through to the custom component\n ...(renderedChildren ?? []),\n );\n};\n\nconst isContainerOrSection = (\n nodeDefinitionId: string,\n): nodeDefinitionId is 'contentful-container' | 'contentful-section' =>\n [CONTENTFUL_COMPONENTS.container.id, CONTENTFUL_COMPONENTS.section.id].includes(\n nodeDefinitionId as 'contentful-container' | 'contentful-section',\n );\n"],"names":["_jsx","_Fragment"],"mappings":";;;;;;;;;;;AAiDa,MAAA,gBAAgB,GAAG,CAAC,EAC/B,IAAI,EAAE,OAAO,EACb,MAAM,EACN,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,4BAA4B,EAC5B,kBAAkB,EAAE,wBAAwB,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AC,CAAC,QAAQ,CAC7E,gBAAiE,CAClE;;;;"}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import { debug
|
|
2
|
+
import { debug } from '@contentful/experiences-core';
|
|
3
3
|
import { CompositionBlock } from './CompositionBlock.js';
|
|
4
4
|
import { compatibleVersions } from '../../constants.js';
|
|
5
5
|
import { useBreakpoints } from '../../hooks/useBreakpoints.js';
|
|
6
6
|
import 'react';
|
|
7
7
|
import '@contentful/experiences-core/constants';
|
|
8
|
-
import { PrebindingManager } from '../../core/preview/PrebindingManager.js';
|
|
9
8
|
|
|
10
|
-
const initialPatternRootNodeIdsChain = ['root'];
|
|
11
9
|
const PreviewDeliveryRoot = ({ locale, experience }) => {
|
|
12
10
|
const { entityStore } = experience;
|
|
13
11
|
const { resolveDesignValue } = useBreakpoints(entityStore?.breakpoints ?? []);
|
|
@@ -18,21 +16,6 @@ const PreviewDeliveryRoot = ({ locale, experience }) => {
|
|
|
18
16
|
debug.warn(`[experiences-sdk-react::PreviewDeliveryRoot] Contentful experience schema version: ${entityStore.schemaVersion} does not match the compatible schema versions: ${compatibleVersions}. Aborting.`);
|
|
19
17
|
return null;
|
|
20
18
|
}
|
|
21
|
-
const isPreviewingAPattern = entityStore.isExperienceAPatternEntry;
|
|
22
|
-
if (isPreviewingAPattern) {
|
|
23
|
-
const prebindingDefinitions = entityStore.experienceEntryFields.componentSettings?.prebindingDefinitions ?? [];
|
|
24
|
-
PrebindingManager.storePrebindingDefinitions('root', entityStore.experienceEntryId, prebindingDefinitions);
|
|
25
|
-
const { dataSource, parameters: defaultParametersFromRootPattern } = generateDefaultDataSourceForPrebindingDefinition(prebindingDefinitions);
|
|
26
|
-
if (Object.keys(dataSource).length) {
|
|
27
|
-
entityStore.experienceEntryFields.dataSource = {
|
|
28
|
-
...entityStore.dataSource,
|
|
29
|
-
...dataSource,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
return entityStore.experienceEntryFields.componentTree.children.map((childNode, index) => {
|
|
33
|
-
return (jsx(CompositionBlock, { node: childNode, hyperlinkPattern: experience.hyperlinkPattern, locale: locale, entityStore: entityStore, resolveDesignValue: resolveDesignValue, patternRootNodeIdsChain: initialPatternRootNodeIdsChain, rootPatternParameters: defaultParametersFromRootPattern }, index));
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
19
|
return (jsx(Fragment, { children: entityStore.experienceEntryFields.componentTree.children.map((childNode, index) => (jsx(CompositionBlock, { node: childNode, hyperlinkPattern: experience.hyperlinkPattern, locale: locale, entityStore: entityStore, resolveDesignValue: resolveDesignValue }, index))) }));
|
|
37
20
|
};
|
|
38
21
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PreviewDeliveryRoot.js","sources":["../../../../src/blocks/preview/PreviewDeliveryRoot.tsx"],"sourcesContent":["import React from 'react';\nimport {
|
|
1
|
+
{"version":3,"file":"PreviewDeliveryRoot.js","sources":["../../../../src/blocks/preview/PreviewDeliveryRoot.tsx"],"sourcesContent":["import React from 'react';\nimport { debug, EntityStore } from '@contentful/experiences-core';\nimport type { Experience } from '@contentful/experiences-core/types';\nimport { CompositionBlock } from './CompositionBlock';\nimport { compatibleVersions } from '../../constants';\nimport { useBreakpoints } from '../../hooks';\n\ntype DeliveryRootProps = {\n experience: Experience<EntityStore>;\n locale: string;\n};\n\nexport const PreviewDeliveryRoot = ({ locale, experience }: DeliveryRootProps) => {\n const { entityStore } = experience;\n\n const { resolveDesignValue } = useBreakpoints(entityStore?.breakpoints ?? []);\n\n if (!entityStore?.experienceEntryFields || !entityStore?.schemaVersion) {\n return null;\n }\n\n if (!compatibleVersions.includes(entityStore.schemaVersion)) {\n debug.warn(\n `[experiences-sdk-react::PreviewDeliveryRoot] Contentful experience schema version: ${entityStore.schemaVersion} does not match the compatible schema versions: ${compatibleVersions}. Aborting.`,\n );\n return null;\n }\n\n return (\n <>\n {entityStore.experienceEntryFields.componentTree.children.map((childNode, index) => (\n <CompositionBlock\n key={index}\n node={childNode}\n hyperlinkPattern={experience.hyperlinkPattern}\n locale={locale}\n entityStore={entityStore}\n resolveDesignValue={resolveDesignValue}\n />\n ))}\n </>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;;AAYa,MAAA,mBAAmB,GAAG,CAAC,EAAE,MAAM,EAAE,UAAU,EAAqB,KAAI;AAC/E,IAAA,MAAM,EAAE,WAAW,EAAE,GAAG,UAAU,CAAC;AAEnC,IAAA,MAAM,EAAE,kBAAkB,EAAE,GAAG,cAAc,CAAC,WAAW,EAAE,WAAW,IAAI,EAAE,CAAC,CAAC;IAE9E,IAAI,CAAC,WAAW,EAAE,qBAAqB,IAAI,CAAC,WAAW,EAAE,aAAa,EAAE;AACtE,QAAA,OAAO,IAAI,CAAC;KACb;IAED,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE;QAC3D,KAAK,CAAC,IAAI,CACR,CAAsF,mFAAA,EAAA,WAAW,CAAC,aAAa,CAAmD,gDAAA,EAAA,kBAAkB,CAAa,WAAA,CAAA,CAClM,CAAC;AACF,QAAA,OAAO,IAAI,CAAC;KACb;IAED,QACEA,0BACG,WAAW,CAAC,qBAAqB,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,KAAK,MAC7EA,GAAA,CAAC,gBAAgB,EAAA,EAEf,IAAI,EAAE,SAAS,EACf,gBAAgB,EAAE,UAAU,CAAC,gBAAgB,EAC7C,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,kBAAkB,EAAE,kBAAkB,EALjC,EAAA,KAAK,CAMV,CACH,CAAC,EACD,CAAA,EACH;AACJ;;;;"}
|
|
@@ -1,34 +1,29 @@
|
|
|
1
|
-
import { mergeDesignValuesByBreakpoint
|
|
1
|
+
import { mergeDesignValuesByBreakpoint } from '@contentful/experiences-core';
|
|
2
|
+
import md5 from 'md5';
|
|
2
3
|
import { shouldUsePrebinding, resolvePrebindingPath } from '../../utils/prebindingUtils.js';
|
|
3
|
-
import {
|
|
4
|
+
import { PATTERN_PROPERTY_DIVIDER } from '@contentful/experiences-core/constants';
|
|
4
5
|
|
|
5
6
|
/** While unfolding the pattern definition on the instance, this function will replace all
|
|
6
7
|
* ComponentValue in the definitions tree with the actual value on the instance. */
|
|
7
|
-
const deserializePatternNode = ({ node,
|
|
8
|
+
const deserializePatternNode = ({ node, componentInstanceVariables, componentSettings, parameters, entityStore, }) => {
|
|
8
9
|
const variables = {};
|
|
9
|
-
let parentPatternNodeId = parentPatternRootNodeIdsChain.slice(-1)[0];
|
|
10
|
-
if (parentPatternNodeId === node.id) {
|
|
11
|
-
parentPatternNodeId = parentPatternRootNodeIdsChain.slice(-2)[0];
|
|
12
|
-
}
|
|
13
10
|
for (const [variableName, variable] of Object.entries(node.variables)) {
|
|
14
11
|
variables[variableName] = variable;
|
|
15
12
|
if (variable.type === 'ComponentValue') {
|
|
16
13
|
const componentValueKey = variable.key;
|
|
17
|
-
const instanceProperty =
|
|
14
|
+
const instanceProperty = componentInstanceVariables[componentValueKey];
|
|
18
15
|
const variableDefinition = componentSettings.variableDefinitions?.[componentValueKey];
|
|
19
16
|
const defaultValue = variableDefinition?.defaultValue;
|
|
20
17
|
const usePrebinding = shouldUsePrebinding({
|
|
21
18
|
componentSettings,
|
|
22
19
|
componentValueKey,
|
|
23
|
-
parameters:
|
|
24
|
-
patternRootNodeIdsChain: parentPatternRootNodeIdsChain,
|
|
20
|
+
parameters: parameters,
|
|
25
21
|
});
|
|
26
22
|
const path = resolvePrebindingPath({
|
|
27
23
|
componentSettings,
|
|
28
24
|
componentValueKey,
|
|
29
|
-
parameters:
|
|
25
|
+
parameters: parameters,
|
|
30
26
|
entityStore,
|
|
31
|
-
patternRootNodeIdsChain: parentPatternRootNodeIdsChain,
|
|
32
27
|
});
|
|
33
28
|
if (usePrebinding && path) {
|
|
34
29
|
variables[variableName] = {
|
|
@@ -64,12 +59,6 @@ const deserializePatternNode = ({ node, rootPatternVariables, componentSettings,
|
|
|
64
59
|
else if (instanceProperty?.type === 'DesignValue') {
|
|
65
60
|
variables[variableName] = mergeDesignValuesByBreakpoint(defaultValue, instanceProperty);
|
|
66
61
|
}
|
|
67
|
-
else if (instanceProperty?.type === 'ComponentValue') {
|
|
68
|
-
if (!usePrebinding) {
|
|
69
|
-
// @ts-expect-error ignore for now
|
|
70
|
-
variables[variableName] = defaultValue;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
62
|
else if (!instanceProperty && defaultValue) {
|
|
74
63
|
// So far, we only automatically fallback to the defaultValue for design properties
|
|
75
64
|
if (variableDefinition.group === 'style') {
|
|
@@ -81,85 +70,60 @@ const deserializePatternNode = ({ node, rootPatternVariables, componentSettings,
|
|
|
81
70
|
}
|
|
82
71
|
}
|
|
83
72
|
}
|
|
84
|
-
const children = node.children.map((child) => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
node: child,
|
|
92
|
-
rootPatternVariables,
|
|
93
|
-
componentSettings,
|
|
94
|
-
entityStore,
|
|
95
|
-
rootPatternParameters,
|
|
96
|
-
parentPatternRootNodeIdsChain,
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
return deserializePatternNode({
|
|
100
|
-
node: child,
|
|
101
|
-
rootPatternVariables,
|
|
102
|
-
componentSettings,
|
|
103
|
-
entityStore,
|
|
104
|
-
rootPatternParameters,
|
|
105
|
-
parentPatternRootNodeIdsChain,
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
const patternsChain = parentPatternRootNodeIdsChain.join('---');
|
|
109
|
-
const indexedNodeId = patternsChain ? [patternsChain, node.id].join('-') : node.id;
|
|
73
|
+
const children = node.children.map((child) => deserializePatternNode({
|
|
74
|
+
node: child,
|
|
75
|
+
componentInstanceVariables,
|
|
76
|
+
componentSettings,
|
|
77
|
+
parameters,
|
|
78
|
+
entityStore,
|
|
79
|
+
}));
|
|
110
80
|
return {
|
|
111
81
|
definitionId: node.definitionId,
|
|
112
82
|
id: node.id,
|
|
113
83
|
variables,
|
|
114
84
|
children,
|
|
115
|
-
pattern: {
|
|
116
|
-
nodeIdOnPattern: node.id,
|
|
117
|
-
parentPatternNodeId,
|
|
118
|
-
prefixedNodeId: indexedNodeId,
|
|
119
|
-
},
|
|
120
85
|
slotId: node.slotId,
|
|
121
86
|
displayName: node.displayName,
|
|
122
87
|
parameters: node.parameters,
|
|
123
88
|
};
|
|
124
89
|
};
|
|
125
|
-
const resolvePattern = ({ node,
|
|
90
|
+
const resolvePattern = ({ node, parentParameters, patternRootNodeIdsChain, entityStore, }) => {
|
|
126
91
|
const componentId = node.definitionId;
|
|
127
|
-
const
|
|
128
|
-
if (!
|
|
92
|
+
const assembly = entityStore.usedComponents?.find((component) => component.sys.id === componentId);
|
|
93
|
+
if (!assembly || !('fields' in assembly)) {
|
|
129
94
|
return node;
|
|
130
95
|
}
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
96
|
+
const parameters = {};
|
|
97
|
+
const allParameters = {
|
|
98
|
+
...parentParameters,
|
|
99
|
+
...(node.parameters || {}),
|
|
100
|
+
};
|
|
101
|
+
for (const [parameterKey, parameter] of Object.entries(allParameters)) {
|
|
102
|
+
/**
|
|
103
|
+
* Bubbled up pattern properties are a concatenation of the node id
|
|
104
|
+
* and the pattern property definition id. We need to split them so
|
|
105
|
+
* that the node only uses the pattern property definition id.
|
|
106
|
+
*/
|
|
107
|
+
const [hashKey, parameterId] = parameterKey.split(PATTERN_PROPERTY_DIVIDER);
|
|
108
|
+
const hashedNodeChain = md5(patternRootNodeIdsChain || '');
|
|
109
|
+
const isMatchingNode = hashKey === hashedNodeChain;
|
|
110
|
+
if (!isMatchingNode)
|
|
111
|
+
continue;
|
|
112
|
+
parameters[parameterId] = parameter;
|
|
149
113
|
}
|
|
114
|
+
const componentFields = assembly.fields;
|
|
150
115
|
const deserializedNode = deserializePatternNode({
|
|
151
116
|
node: {
|
|
152
117
|
definitionId: node.definitionId,
|
|
153
118
|
id: node.id,
|
|
154
119
|
variables: node.variables,
|
|
155
120
|
children: componentFields.componentTree.children,
|
|
156
|
-
parameters:
|
|
121
|
+
parameters: parameters,
|
|
157
122
|
},
|
|
158
|
-
|
|
123
|
+
componentInstanceVariables: node.variables,
|
|
159
124
|
componentSettings: componentFields.componentSettings,
|
|
125
|
+
parameters: parameters,
|
|
160
126
|
entityStore,
|
|
161
|
-
rootPatternParameters: parameters,
|
|
162
|
-
parentPatternRootNodeIdsChain,
|
|
163
127
|
});
|
|
164
128
|
entityStore.addAssemblyUnboundValues(componentFields.unboundValues);
|
|
165
129
|
return deserializedNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assemblyUtils.js","sources":["../../../../src/core/preview/assemblyUtils.ts"],"sourcesContent":["import {\n checkIsAssemblyNode,\n EntityStore,\n mergeDesignValuesByBreakpoint,\n} from '@contentful/experiences-core';\nimport type {\n ComponentPropertyValue,\n ComponentTreeNode,\n DesignValue,\n ExperienceComponentSettings,\n Parameter,\n} from '@contentful/experiences-core/types';\nimport { resolvePrebindingPath, shouldUsePrebinding } from '../../utils/prebindingUtils';\nimport { PrebindingManager } from './PrebindingManager';\n\ntype ComponentTreeNodeWithPatternInformation = ComponentTreeNode & {\n pattern?: {\n parentPatternNodeId: string;\n nodeIdOnPattern: string;\n prefixedNodeId: string;\n };\n};\n\n/** While unfolding the pattern definition on the instance, this function will replace all\n * ComponentValue in the definitions tree with the actual value on the instance. */\nexport const deserializePatternNode = ({\n node,\n rootPatternVariables,\n componentSettings,\n entityStore,\n rootPatternParameters,\n parentPatternRootNodeIdsChain,\n}: {\n node: ComponentTreeNode;\n rootPatternVariables: ComponentTreeNode['variables'];\n componentSettings: ExperienceComponentSettings;\n entityStore: EntityStore;\n rootPatternParameters: Record<string, Parameter>;\n parentPatternRootNodeIdsChain: string[];\n}): ComponentTreeNodeWithPatternInformation => {\n const variables: Record<string, ComponentPropertyValue> = {};\n\n let parentPatternNodeId = parentPatternRootNodeIdsChain.slice(-1)[0];\n if (parentPatternNodeId === node.id) {\n parentPatternNodeId = parentPatternRootNodeIdsChain.slice(-2)[0];\n }\n\n for (const [variableName, variable] of Object.entries(node.variables)) {\n variables[variableName] = variable;\n if (variable.type === 'ComponentValue') {\n const componentValueKey = variable.key;\n const instanceProperty = rootPatternVariables[componentValueKey];\n const variableDefinition = componentSettings.variableDefinitions?.[componentValueKey];\n const defaultValue = variableDefinition?.defaultValue;\n\n const usePrebinding = shouldUsePrebinding({\n componentSettings,\n componentValueKey,\n parameters: rootPatternParameters,\n patternRootNodeIdsChain: parentPatternRootNodeIdsChain,\n });\n const path = resolvePrebindingPath({\n componentSettings,\n componentValueKey,\n parameters: rootPatternParameters,\n entityStore,\n patternRootNodeIdsChain: parentPatternRootNodeIdsChain,\n });\n\n if (usePrebinding && path) {\n variables[variableName] = {\n type: 'BoundValue',\n path,\n };\n\n // For assembly, we look up the variable in the assembly instance and\n // replace the ComponentValue with that one.\n } else if (instanceProperty?.type === 'UnboundValue') {\n variables[variableName] = {\n type: 'UnboundValue',\n key: instanceProperty.key,\n };\n } else if (instanceProperty?.type === 'NoValue') {\n throw new Error(\n `Unexpected NoValue for variable \"${variableName}\" when deserializing pattern \"${node.definitionId}\". ` +\n `This can only happen if you created experience in pre-release version of prebinding and experience contains NoValue properties. ` +\n `Resave experience to fix this issue.`,\n );\n } else if (instanceProperty?.type === 'BoundValue') {\n variables[variableName] = {\n type: 'BoundValue',\n path: instanceProperty.path,\n };\n } else if (instanceProperty?.type === 'HyperlinkValue') {\n variables[variableName] = {\n type: 'HyperlinkValue',\n linkTargetKey: instanceProperty.linkTargetKey,\n };\n } else if (instanceProperty?.type === 'DesignValue') {\n variables[variableName] = mergeDesignValuesByBreakpoint(\n defaultValue as DesignValue | undefined,\n instanceProperty,\n );\n } else if (instanceProperty?.type === 'ComponentValue') {\n if (!usePrebinding) {\n // @ts-expect-error ignore for now\n variables[variableName] = defaultValue;\n }\n } else if (!instanceProperty && defaultValue) {\n // So far, we only automatically fallback to the defaultValue for design properties\n if (variableDefinition.group === 'style') {\n variables[variableName] = {\n type: 'DesignValue',\n valuesByBreakpoint: (defaultValue as DesignValue).valuesByBreakpoint,\n };\n }\n }\n }\n }\n\n const children: ComponentTreeNode[] = node.children.map((child) => {\n const isPatternNode = checkIsAssemblyNode({\n componentId: child.definitionId,\n usedComponents: entityStore.usedComponents,\n });\n\n if (isPatternNode) {\n return deserializePatternNode({\n node: child,\n rootPatternVariables,\n componentSettings,\n entityStore,\n rootPatternParameters,\n parentPatternRootNodeIdsChain,\n });\n }\n\n return deserializePatternNode({\n node: child,\n rootPatternVariables,\n componentSettings,\n entityStore,\n rootPatternParameters,\n parentPatternRootNodeIdsChain,\n });\n });\n\n const patternsChain = parentPatternRootNodeIdsChain.join('---');\n const indexedNodeId = patternsChain ? [patternsChain, node.id!].join('-') : node.id!;\n\n return {\n definitionId: node.definitionId,\n id: node.id,\n variables,\n children,\n pattern: {\n nodeIdOnPattern: node.id!,\n parentPatternNodeId,\n prefixedNodeId: indexedNodeId,\n },\n slotId: node.slotId,\n displayName: node.displayName,\n parameters: node.parameters,\n };\n};\n\nexport const resolvePattern = ({\n node,\n entityStore,\n parentPatternRootNodeIdsChain,\n rootPatternParameters,\n}: {\n node: ComponentTreeNode;\n entityStore: EntityStore;\n parentPatternRootNodeIdsChain: string[];\n rootPatternParameters: Record<string, Parameter>;\n}): ComponentTreeNodeWithPatternInformation => {\n const componentId = node.definitionId as string;\n const patternEntry = entityStore.usedComponents?.find(\n (component) => component.sys.id === componentId,\n );\n\n if (!patternEntry || !('fields' in patternEntry)) {\n return node;\n }\n\n const componentFields = patternEntry.fields;\n const parameters = rootPatternParameters;\n let nodeParameters: Record<string, Parameter> | undefined;\n\n if (rootPatternParameters) {\n nodeParameters = {};\n const prebindingDefinitions = componentFields.componentSettings?.prebindingDefinitions ?? [];\n const indexedNodeId = parentPatternRootNodeIdsChain.join('---');\n PrebindingManager.linkOriginalNodeIds(indexedNodeId, node.id!);\n PrebindingManager.storePrebindingDefinitions(indexedNodeId, componentId, prebindingDefinitions);\n\n const prebindingDefinition = prebindingDefinitions[0];\n\n if (prebindingDefinition && prebindingDefinition.parameterDefinitions) {\n for (const [parameterId] of Object.entries(prebindingDefinition.parameterDefinitions)) {\n const hoistedParameterId = PrebindingManager.getHoistedIdForParameterId(\n parameterId,\n indexedNodeId,\n );\n if (rootPatternParameters[hoistedParameterId]) {\n nodeParameters[parameterId] = rootPatternParameters[hoistedParameterId];\n }\n }\n }\n }\n\n const deserializedNode = deserializePatternNode({\n node: {\n definitionId: node.definitionId,\n id: node.id,\n variables: node.variables,\n children: componentFields.componentTree.children,\n parameters: nodeParameters,\n },\n rootPatternVariables: node.variables,\n componentSettings: componentFields.componentSettings!,\n entityStore,\n rootPatternParameters: parameters,\n parentPatternRootNodeIdsChain,\n });\n\n entityStore.addAssemblyUnboundValues(componentFields.unboundValues);\n\n return deserializedNode;\n};\n"],"names":[],"mappings":";;;;AAuBA;AACmF;AACtE,MAAA,sBAAsB,GAAG,CAAC,EACrC,IAAI,EACJ,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,qBAAqB,EACrB,6BAA6B,GAQ9B,KAA6C;IAC5C,MAAM,SAAS,GAA2C,EAAE,CAAC;AAE7D,IAAA,IAAI,mBAAmB,GAAG,6BAA6B,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACrE,IAAA,IAAI,mBAAmB,KAAK,IAAI,CAAC,EAAE,EAAE;QACnC,mBAAmB,GAAG,6BAA6B,CAAC,K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sBAAsB,CAAC;AAC9C,QAAA,IAAI,EAAE;YACJ,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,SAAS,EAAE,IAAI,CAAC,SAAS;AACzB,YAAA,QAAQ,EAAE,eAAe,CAAC,aAAa,CAAC,QAAQ;AAChD,YAAA,UAAU,EAAE,cAAc;AAC3B,SAAA;QACD,oBAAoB,EAAE,IAAI,CAAC,SAAS;QACpC,iBAAiB,EAAE,eAAe,CAAC,iBAAkB;QACrD,WAAW;AACX,QAAA,qBAAqB,EAAE,UAAU;QACjC,6BAA6B;AAC9B,KAAA,CAAC,CAAC;AAEH,IAAA,WAAW,CAAC,wBAAwB,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;AAEpE,IAAA,OAAO,gBAAgB,CAAC;AAC1B;;;;"}
|
|
1
|
+
{"version":3,"file":"assemblyUtils.js","sources":["../../../../src/core/preview/assemblyUtils.ts"],"sourcesContent":["import { EntityStore, mergeDesignValuesByBreakpoint } from '@contentful/experiences-core';\nimport md5 from 'md5';\nimport type {\n ComponentPropertyValue,\n ComponentTreeNode,\n DesignValue,\n ExperienceComponentSettings,\n Parameter,\n} from '@contentful/experiences-core/types';\nimport { resolvePrebindingPath, shouldUsePrebinding } from '../../utils/prebindingUtils';\nimport { PATTERN_PROPERTY_DIVIDER } from '@contentful/experiences-core/constants';\n\n/** While unfolding the pattern definition on the instance, this function will replace all\n * ComponentValue in the definitions tree with the actual value on the instance. */\nexport const deserializePatternNode = ({\n node,\n componentInstanceVariables,\n componentSettings,\n parameters,\n entityStore,\n}: {\n node: ComponentTreeNode;\n componentInstanceVariables: ComponentTreeNode['variables'];\n componentSettings: ExperienceComponentSettings;\n parameters: Record<string, Parameter>;\n entityStore: EntityStore;\n}): ComponentTreeNode => {\n const variables: Record<string, ComponentPropertyValue> = {};\n\n for (const [variableName, variable] of Object.entries(node.variables)) {\n variables[variableName] = variable;\n if (variable.type === 'ComponentValue') {\n const componentValueKey = variable.key;\n const instanceProperty = componentInstanceVariables[componentValueKey];\n const variableDefinition = componentSettings.variableDefinitions?.[componentValueKey];\n const defaultValue = variableDefinition?.defaultValue;\n\n const usePrebinding = shouldUsePrebinding({\n componentSettings,\n componentValueKey,\n parameters: parameters,\n });\n const path = resolvePrebindingPath({\n componentSettings,\n componentValueKey,\n parameters: parameters,\n entityStore,\n });\n\n if (usePrebinding && path) {\n variables[variableName] = {\n type: 'BoundValue',\n path,\n };\n\n // For assembly, we look up the variable in the assembly instance and\n // replace the ComponentValue with that one.\n } else if (instanceProperty?.type === 'UnboundValue') {\n variables[variableName] = {\n type: 'UnboundValue',\n key: instanceProperty.key,\n };\n } else if (instanceProperty?.type === 'NoValue') {\n throw new Error(\n `Unexpected NoValue for variable \"${variableName}\" when deserializing pattern \"${node.definitionId}\". ` +\n `This can only happen if you created experience in pre-release version of prebinding and experience contains NoValue properties. ` +\n `Resave experience to fix this issue.`,\n );\n } else if (instanceProperty?.type === 'BoundValue') {\n variables[variableName] = {\n type: 'BoundValue',\n path: instanceProperty.path,\n };\n } else if (instanceProperty?.type === 'HyperlinkValue') {\n variables[variableName] = {\n type: 'HyperlinkValue',\n linkTargetKey: instanceProperty.linkTargetKey,\n };\n } else if (instanceProperty?.type === 'DesignValue') {\n variables[variableName] = mergeDesignValuesByBreakpoint(\n defaultValue as DesignValue | undefined,\n instanceProperty,\n );\n } else if (!instanceProperty && defaultValue) {\n // So far, we only automatically fallback to the defaultValue for design properties\n if (variableDefinition.group === 'style') {\n variables[variableName] = {\n type: 'DesignValue',\n valuesByBreakpoint: (defaultValue as DesignValue).valuesByBreakpoint,\n };\n }\n }\n }\n }\n\n const children: ComponentTreeNode[] = node.children.map((child) =>\n deserializePatternNode({\n node: child,\n componentInstanceVariables,\n componentSettings,\n parameters,\n entityStore,\n }),\n );\n\n return {\n definitionId: node.definitionId,\n id: node.id,\n variables,\n children,\n slotId: node.slotId,\n displayName: node.displayName,\n parameters: node.parameters,\n };\n};\n\nexport const resolvePattern = ({\n node,\n parentParameters,\n patternRootNodeIdsChain,\n entityStore,\n}: {\n node: ComponentTreeNode;\n entityStore: EntityStore;\n parentParameters: Record<string, Parameter>;\n patternRootNodeIdsChain: string;\n}) => {\n const componentId = node.definitionId as string;\n const assembly = entityStore.usedComponents?.find(\n (component) => component.sys.id === componentId,\n );\n\n if (!assembly || !('fields' in assembly)) {\n return node;\n }\n\n const parameters: Record<string, Parameter> = {};\n\n const allParameters = {\n ...parentParameters,\n ...(node.parameters || {}),\n };\n\n for (const [parameterKey, parameter] of Object.entries(allParameters)) {\n /**\n * Bubbled up pattern properties are a concatenation of the node id\n * and the pattern property definition id. We need to split them so\n * that the node only uses the pattern property definition id.\n */\n const [hashKey, parameterId] = parameterKey.split(PATTERN_PROPERTY_DIVIDER);\n\n const hashedNodeChain = md5(patternRootNodeIdsChain || '');\n\n const isMatchingNode = hashKey === hashedNodeChain;\n\n if (!isMatchingNode) continue;\n\n parameters[parameterId] = parameter;\n }\n\n const componentFields = assembly.fields;\n\n const deserializedNode = deserializePatternNode({\n node: {\n definitionId: node.definitionId,\n id: node.id,\n variables: node.variables,\n children: componentFields.componentTree.children,\n parameters: parameters,\n },\n componentInstanceVariables: node.variables,\n componentSettings: componentFields.componentSettings!,\n parameters: parameters,\n entityStore,\n });\n\n entityStore.addAssemblyUnboundValues(componentFields.unboundValues);\n\n return deserializedNode;\n};\n"],"names":[],"mappings":";;;;;AAYA;AACmF;AACtE,MAAA,sBAAsB,GAAG,CAAC,EACrC,IAAI,EACJ,0BAA0B,EAC1B,iBAAiB,EACjB,UAAU,EACV,WAAW,GAOZ,KAAuB;IACtB,MAAM,SAAS,GAA2C,EAAE,CAAC;AAE7D,IAAA,KAAK,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACrE,QAAA,SAAS,CAAC,YAAY,CAAC,GAAG,QAAQ,CAAC;AACnC,QAAA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ACvB,SAAA;QACD,0BAA0B,EAAE,IAAI,CAAC,SAAS;QAC1C,iBAAiB,EAAE,eAAe,CAAC,iBAAkB;AACrD,QAAA,UAAU,EAAE,UAAU;QACtB,WAAW;AACZ,KAAA,CAAC,CAAC;AAEH,IAAA,WAAW,CAAC,wBAAwB,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;AAEpE,IAAA,OAAO,gBAAgB,CAAC;AAC1B;;;;"}
|
|
@@ -59,7 +59,7 @@ const createStylesheetsForBuiltInStyles = ({ designPropertiesByBreakpoint, break
|
|
|
59
59
|
*/
|
|
60
60
|
// Create a hash ensuring stability across nodes (and breakpoints between nodes)
|
|
61
61
|
const styleHash = patternRootNodeIdsChain
|
|
62
|
-
? md5(
|
|
62
|
+
? md5(`${patternRootNodeIdsChain}-${node.id}}-${breakpointCss}`)
|
|
63
63
|
: md5(`${node.id}-${breakpointCss}`);
|
|
64
64
|
// Create a CSS className with internal prefix to make sure the value can be processed
|
|
65
65
|
const className = `cfstyles-${styleHash}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createStylesheetsForBuiltInStyles.js","sources":["../../../../src/core/styles/createStylesheetsForBuiltInStyles.ts"],"sourcesContent":["import {\n addMinHeightForEmptyStructures,\n designTokensRegistry,\n flattenDesignTokenRegistry,\n maybePopulateDesignTokenValue,\n stringifyCssProperties,\n buildCfStyles,\n transformVisibility,\n} from '@contentful/experiences-core';\nimport { Breakpoint, ComponentTreeNode, PrimitiveValue } from '@contentful/experiences-core/types';\nimport md5 from 'md5';\n\nexport type ResolvedStylesheetData = Array<{\n className: string;\n breakpointCondition: string;\n css: string;\n visibilityCss?: string;\n}>;\n\n/**\n * For each provided breakpoint, create the CSS code and a unique class name.\n *\n * **Example Output:**\n * ```\n * [\n * { className: 'cfstyles-123', breakpointCondition: '*', css: 'margin:42px;' },\n * { className: 'cfstyles-456', breakpointCondition: '<768px', css: 'margin:13px;' },\n * ]\n * ```\n */\nexport const createStylesheetsForBuiltInStyles = ({\n designPropertiesByBreakpoint,\n breakpoints,\n node,\n patternRootNodeIdsChain,\n}: {\n designPropertiesByBreakpoint: Record<string, Record<string, PrimitiveValue>>;\n breakpoints: Breakpoint[];\n node: ComponentTreeNode;\n patternRootNodeIdsChain?:
|
|
1
|
+
{"version":3,"file":"createStylesheetsForBuiltInStyles.js","sources":["../../../../src/core/styles/createStylesheetsForBuiltInStyles.ts"],"sourcesContent":["import {\n addMinHeightForEmptyStructures,\n designTokensRegistry,\n flattenDesignTokenRegistry,\n maybePopulateDesignTokenValue,\n stringifyCssProperties,\n buildCfStyles,\n transformVisibility,\n} from '@contentful/experiences-core';\nimport { Breakpoint, ComponentTreeNode, PrimitiveValue } from '@contentful/experiences-core/types';\nimport md5 from 'md5';\n\nexport type ResolvedStylesheetData = Array<{\n className: string;\n breakpointCondition: string;\n css: string;\n visibilityCss?: string;\n}>;\n\n/**\n * For each provided breakpoint, create the CSS code and a unique class name.\n *\n * **Example Output:**\n * ```\n * [\n * { className: 'cfstyles-123', breakpointCondition: '*', css: 'margin:42px;' },\n * { className: 'cfstyles-456', breakpointCondition: '<768px', css: 'margin:13px;' },\n * ]\n * ```\n */\nexport const createStylesheetsForBuiltInStyles = ({\n designPropertiesByBreakpoint,\n breakpoints,\n node,\n patternRootNodeIdsChain,\n}: {\n designPropertiesByBreakpoint: Record<string, Record<string, PrimitiveValue>>;\n breakpoints: Breakpoint[];\n node: ComponentTreeNode;\n patternRootNodeIdsChain?: string;\n}): ResolvedStylesheetData => {\n const flattenedDesignTokens = flattenDesignTokenRegistry(designTokensRegistry);\n\n // When the node is hidden for any breakpoint, we need to handle this separately with a disjunct media query.\n const isAnyVisibilityValueHidden = Object.values(designPropertiesByBreakpoint).some(\n (designProperties) => designProperties.cfVisibility === false,\n );\n // We always need an explicit value when using disjunct media queries\n // Example: desktop uses \"false\" and tablet is undefined -> we need to set `display: none` for tablet as well.\n let previousVisibilityValue: boolean | undefined;\n\n const result: Array<{\n className: string;\n breakpointCondition: string;\n css: string;\n visibilityCss?: string;\n }> = [];\n\n for (const breakpoint of breakpoints) {\n let visibilityCss: string | undefined;\n const designProperties = designPropertiesByBreakpoint[breakpoint.id];\n if (!designProperties) {\n continue;\n }\n\n const designPropertiesWithResolvedDesignTokens = Object.entries(designProperties).reduce(\n (acc, [propertyName, value]) => ({\n ...acc,\n [propertyName]: maybePopulateDesignTokenValue(\n propertyName,\n value,\n flattenedDesignTokens,\n ) as string,\n }),\n {} as Record<string, PrimitiveValue>,\n );\n /* [Data Format] `designPropertiesWithResolvedDesignTokens` is a map of property name to plain design value:\n * designPropertiesWithResolvedDesignTokens = {\n * cfMargin: '42px',\n * cfBackgroundColor: 'rgba(246, 246, 246, 1)',\n * }\n */\n\n // Special case for visibility to override any custom `display` values but only for a specific breakpoint.\n if (isAnyVisibilityValueHidden) {\n const visibilityValue =\n (designPropertiesWithResolvedDesignTokens.cfVisibility as boolean | undefined) ??\n previousVisibilityValue;\n previousVisibilityValue = visibilityValue;\n const visibilityStyles = transformVisibility(visibilityValue);\n visibilityCss = stringifyCssProperties(visibilityStyles);\n }\n\n // Convert CF-specific property names to CSS variables, e.g. `cfMargin` -> `margin`\n const cfStyles = addMinHeightForEmptyStructures(\n buildCfStyles(designPropertiesWithResolvedDesignTokens),\n node,\n );\n /* [Data Format] `cfStyles` follows the shape of CSSProperties (camelCased CSS property names):\n * cfStyles = {\n * margin: '42px',\n * backgroundColor: 'rgba(246, 246, 246, 1)',\n * }\n */\n\n // Translate the map of CSSProperties into the final shape of CSS code for this specific breakpoint\n const breakpointCss = stringifyCssProperties(cfStyles);\n /* [Data Format] `breakpointCss`:\n * breakpointCss = \"margin:42px;background-color:rgba(246, 246, 246, 1);\"\n */\n\n // Create a hash ensuring stability across nodes (and breakpoints between nodes)\n const styleHash = patternRootNodeIdsChain\n ? md5(`${patternRootNodeIdsChain}-${node.id}}-${breakpointCss}`)\n : md5(`${node.id}-${breakpointCss}`);\n\n // Create a CSS className with internal prefix to make sure the value can be processed\n const className = `cfstyles-${styleHash}`;\n\n result.push({\n className,\n breakpointCondition: breakpoint.query,\n css: breakpointCss,\n visibilityCss,\n });\n }\n\n return result;\n};\n"],"names":[],"mappings":";;;AAmBA;;;;;;;;;;AAUG;AACI,MAAM,iCAAiC,GAAG,CAAC,EAChD,4BAA4B,EAC5B,WAAW,EACX,IAAI,EACJ,uBAAuB,GAMxB,KAA4B;AAC3B,IAAA,MAAM,qBAAqB,GAAG,0BAA0B,CAAC,oBAAoB,CAAC,CAAC;;IAG/E,MAAM,0BAA0B,GAAG,MAAM,CAAC,MAAM,CAAC,4BAA4B,CAAC,CAAC,IAAI,CACjF,CAAC,gBAAgB,KAAK,gBAAgB,CAAC,YAAY,KAAK,KAAK,CAC9D,CAAC;;;AAGF,IAAA,IAAI,uBAA4C,CAAC;IAEjD,MAAM,MAAM,GAKP,EAAE,CAAC;AAER,IAAA,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;AACpC,QAAA,IAAI,aAAiC,CAAC;QACtC,MAAM,gBAAgB,GAAG,4BAA4B,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QACrE,IAAI,CAAC,gBAAgB,EAAE;YACrB,SAAS;SACV;QAED,MAAM,wCAAwC,GAAG,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,MAAM,CACtF,CAAC,GAAG,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,MAAM;AAC/B,YAAA,GAAG,GAAG;YACN,CAAC,YAAY,GAAG,6BAA6B,CAC3C,YAAY,EACZ,KAAK,EACL,qBAAqB,CACZ;SACZ,CAAC,EACF,EAAoC,CACrC,CAAC;AACF;;;;;AAKG;;QAGH,IAAI,0BAA0B,EAAE;AAC9B,YAAA,MAAM,eAAe,GAClB,wCAAwC,CAAC,YAAoC;AAC9E,gBAAA,uBAAuB,CAAC;YAC1B,uBAAuB,GAAG,eAAe,CAAC;AAC1C,YAAA,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,eAAe,CAAC,CAAC;AAC9D,YAAA,aAAa,GAAG,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;SAC1D;;QAGD,MAAM,QAAQ,GAAG,8BAA8B,CAC7C,aAAa,CAAC,wCAAwC,CAAC,EACvD,IAAI,CACL,CAAC;AACF;;;;;AAKG;;AAGH,QAAA,MAAM,aAAa,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC;AACvD;;AAEG;;QAGH,MAAM,SAAS,GAAG,uBAAuB;AACvC,cAAE,GAAG,CAAC,CAAA,EAAG,uBAAuB,CAAA,CAAA,EAAI,IAAI,CAAC,EAAE,CAAA,EAAA,EAAK,aAAa,CAAA,CAAE,CAAC;cAC9D,GAAG,CAAC,CAAG,EAAA,IAAI,CAAC,EAAE,CAAI,CAAA,EAAA,aAAa,CAAE,CAAA,CAAC,CAAC;;AAGvC,QAAA,MAAM,SAAS,GAAG,CAAY,SAAA,EAAA,SAAS,EAAE,CAAC;QAE1C,MAAM,CAAC,IAAI,CAAC;YACV,SAAS;YACT,mBAAmB,EAAE,UAAU,CAAC,KAAK;AACrC,YAAA,GAAG,EAAE,aAAa;YAClB,aAAa;AACd,SAAA,CAAC,CAAC;KACJ;AAED,IAAA,OAAO,MAAM,CAAC;AAChB;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import * as _contentful_experiences_core_constants from '@contentful/experiences
|
|
|
9
9
|
export { CF_STYLE_ATTRIBUTES, CONTENTFUL_COMPONENTS, LATEST_SCHEMA_VERSION } from '@contentful/experiences-core/constants';
|
|
10
10
|
import { ContentfulClientApi } from 'contentful';
|
|
11
11
|
|
|
12
|
-
declare const SDK_VERSION = "3.8.0-
|
|
12
|
+
declare const SDK_VERSION = "3.8.0-prerelease-20250926T1312-a8b5fb7.0";
|
|
13
13
|
|
|
14
14
|
type ExperienceRootProps = {
|
|
15
15
|
experience?: Experience<EntityStore> | string | null;
|
package/dist/sdkVersion.js
CHANGED
package/dist/sdkVersion.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdkVersion.js","sources":["../../src/sdkVersion.ts"],"sourcesContent":["export const SDK_VERSION = '3.8.0-
|
|
1
|
+
{"version":3,"file":"sdkVersion.js","sources":["../../src/sdkVersion.ts"],"sourcesContent":["export const SDK_VERSION = '3.8.0-prerelease-20250926T1312-a8b5fb7.0';\n"],"names":[],"mappings":"AAAO,MAAM,WAAW,GAAG;;;;"}
|
|
@@ -9,12 +9,12 @@ type CompositionBlockProps = {
|
|
|
9
9
|
getPatternChildNodeClassName?: (childNodeId: string) => string | undefined;
|
|
10
10
|
/** Set of definition IDs of wrapping patterns to prevent circular dependencies. */
|
|
11
11
|
wrappingPatternIds?: Set<string>;
|
|
12
|
-
rootPatternParameters?: Record<string, Parameter>;
|
|
13
12
|
/**
|
|
14
13
|
* Chained IDs to ensure uniqueness across multiple instances of the same pattern
|
|
15
14
|
* when storing & accessing cfSsrClassName.
|
|
16
15
|
*/
|
|
17
|
-
patternRootNodeIdsChain?:
|
|
16
|
+
patternRootNodeIdsChain?: string;
|
|
17
|
+
wrappingParameters?: Record<string, Parameter>;
|
|
18
18
|
};
|
|
19
|
-
export declare const CompositionBlock: ({ node: rawNode, locale, entityStore, hyperlinkPattern, resolveDesignValue, getPatternChildNodeClassName, wrappingPatternIds: parentWrappingPatternIds, patternRootNodeIdsChain: parentPatternRootNodeIdsChain,
|
|
19
|
+
export declare const CompositionBlock: ({ node: rawNode, locale, entityStore, hyperlinkPattern, resolveDesignValue, getPatternChildNodeClassName, wrappingPatternIds: parentWrappingPatternIds, wrappingParameters: parentWrappingParameters, patternRootNodeIdsChain: parentPatternRootNodeIdsChain, }: CompositionBlockProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
20
20
|
export {};
|
|
@@ -4,5 +4,5 @@ type DeliveryRootProps = {
|
|
|
4
4
|
experience: Experience<EntityStore>;
|
|
5
5
|
locale: string;
|
|
6
6
|
};
|
|
7
|
-
export declare const PreviewDeliveryRoot: ({ locale, experience }: DeliveryRootProps) => import("react/jsx-runtime").JSX.Element |
|
|
7
|
+
export declare const PreviewDeliveryRoot: ({ locale, experience }: DeliveryRootProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
8
8
|
export {};
|