@contentful/experiences-sdk-react 1.30.5-dev-20250206T1804-ed40499.0 → 1.30.5-prerelease-20250207T1349-200d927.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.
@@ -1,15 +1,17 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
- import React, { useEffect, useMemo } from 'react';
3
- import { checkIsAssemblyNode, resolveHyperlinkPattern, transformBoundContentValue, sanitizeNodeProps } from '@contentful/experiences-core';
2
+ import React, { useState, useEffect, useMemo } from 'react';
3
+ import { checkIsAssemblyNode, transformBoundContentValue, resolveHyperlinkPattern, 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
- import { useClassName } from '../../hooks/useClassName.js';
6
+ import { useInjectStylesheet } from '../../hooks/useClassName.js';
7
7
  import { Assembly, ContentfulContainer, Columns, SingleColumn } from '@contentful/experiences-components-react';
8
8
  import { resolveAssembly } from '../../core/preview/assemblyUtils.js';
9
9
  import PreviewUnboundImage from './PreviewUnboundImage.js';
10
+ import { parseComponentProps } from '../../utils/parseComponentProps.js';
11
+ import { resolveClassNamesFromBuiltInStyles } from '../../hooks/useMediaQuery.js';
10
12
 
11
13
  const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern, resolveDesignValue, getPatternChildNodeClassName, wrappingPatternIds: parentWrappingPatternIds = new Set(), }) => {
12
- const [hasRendered, setHasRendered] = React.useState(false);
14
+ const [hasRendered, setHasRendered] = useState(false);
13
15
  useEffect(() => {
14
16
  setHasRendered(true);
15
17
  }, []);
@@ -41,69 +43,81 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
41
43
  }
42
44
  return registration;
43
45
  }, [isAssembly, node.definitionId]);
44
- const nodeProps = useMemo(() => {
46
+ const { ssrProps, contentProps, props, mediaQuery } = useMemo(() => {
45
47
  // In SSR, we store the className under breakpoints[0] which is resolved here to the actual string
46
48
  const cfSsrClassNameValues = node.variables.cfSsrClassName;
47
- const cfSsrClassName = resolveDesignValue(cfSsrClassNameValues?.valuesByBreakpoint, 'cfSsrClassName');
49
+ const mainBreakpoint = entityStore.breakpoints[0];
50
+ const cfSsrClassName = cfSsrClassNameValues?.valuesByBreakpoint?.[mainBreakpoint.id];
48
51
  // Don't enrich the assembly wrapper node with props
49
52
  if (!componentRegistration || isAssembly) {
50
- return { cfSsrClassName };
53
+ const ssrProps = { cfSsrClassName };
54
+ const props = { className: cfSsrClassName };
55
+ return {
56
+ ssrProps,
57
+ props,
58
+ };
51
59
  }
52
- const propMap = {
60
+ const ssrProps = {
53
61
  cfSsrClassName: node.id && getPatternChildNodeClassName
54
62
  ? getPatternChildNodeClassName(node.id)
55
63
  : cfSsrClassName,
56
64
  };
57
- const props = Object.entries(componentRegistration.definition.variables).reduce((acc, [variableName, variableDefinition]) => {
58
- const variable = node.variables[variableName];
59
- if (!variable)
60
- return acc;
61
- switch (variable.type) {
62
- case 'DesignValue':
63
- acc[variableName] = resolveDesignValue(variable.valuesByBreakpoint, variableName);
64
- break;
65
- case 'BoundValue': {
66
- const [, uuid] = variable.path.split('/');
67
- const binding = entityStore.dataSource[uuid];
68
- const value = transformBoundContentValue(node.variables, entityStore, binding, resolveDesignValue, variableName, variableDefinition, variable.path);
69
- acc[variableName] = value ?? variableDefinition.defaultValue;
70
- break;
71
- }
72
- case 'HyperlinkValue': {
73
- const binding = entityStore.dataSource[variable.linkTargetKey];
74
- const hyperlinkEntry = entityStore.getEntryOrAsset(binding, variable.linkTargetKey);
75
- const value = resolveHyperlinkPattern(componentRegistration.definition.hyperlinkPattern ||
76
- hyperlinkPattern ||
77
- HYPERLINK_DEFAULT_PATTERN, hyperlinkEntry, locale);
78
- if (value) {
79
- acc[variableName] = value;
80
- }
81
- break;
82
- }
83
- case 'UnboundValue': {
84
- const uuid = variable.key;
85
- acc[variableName] =
86
- entityStore.unboundValues[uuid]?.value ?? variableDefinition.defaultValue;
87
- break;
88
- }
89
- case 'ComponentValue':
90
- // We're rendering a pattern entry. Content cannot be set for ComponentValue type properties
91
- // directly in the pattern so we can safely use the default value
92
- // This can either a design (style) or a content variable
93
- acc[variableName] = variableDefinition.defaultValue;
94
- break;
95
- }
96
- return acc;
97
- }, propMap);
65
+ const { contentProps = {}, styleProps = {}, customDesignProps = {}, mediaQuery, } = parseComponentProps({
66
+ componentDefinition: componentRegistration.definition,
67
+ node,
68
+ resolveCustomDesignValue: ({ propertyName, valuesByBreakpoint }) => {
69
+ return resolveDesignValue(valuesByBreakpoint, propertyName);
70
+ },
71
+ resolveBoundValue: ({ binding, propertyName, dataType }) => {
72
+ const [, uuid] = binding.path.split('/');
73
+ const boundEntityLink = entityStore.dataSource[uuid];
74
+ const boundValue = transformBoundContentValue(node.variables, entityStore, boundEntityLink, resolveDesignValue, propertyName, dataType, binding.path);
75
+ return boundValue;
76
+ },
77
+ resolveHyperlinkValue: ({ linkTargetKey }) => {
78
+ const boundEntity = entityStore.dataSource[linkTargetKey];
79
+ const hyperlinkEntry = entityStore.getEntryOrAsset(boundEntity, linkTargetKey);
80
+ const value = resolveHyperlinkPattern(componentRegistration.definition.hyperlinkPattern ||
81
+ hyperlinkPattern ||
82
+ HYPERLINK_DEFAULT_PATTERN, hyperlinkEntry, locale);
83
+ return value;
84
+ },
85
+ resolveUnboundValue: ({ mappingKey, defaultValue }) => {
86
+ return entityStore.unboundValues[mappingKey]?.value ?? defaultValue;
87
+ },
88
+ resolveClassNamesFromBuiltInStyles: (designPropsByBreakpointId) => {
89
+ return resolveClassNamesFromBuiltInStyles({
90
+ designPropsByBreakpointId,
91
+ breakpoints: entityStore.breakpoints,
92
+ node,
93
+ });
94
+ },
95
+ });
96
+ const slotsProps = {};
98
97
  if (componentRegistration.definition.slots) {
99
98
  for (const slotId in componentRegistration.definition.slots) {
100
99
  const slotNode = node.children.find((child) => child.slotId === slotId);
101
100
  if (slotNode) {
102
- props[slotId] = (jsx(CompositionBlock, { node: slotNode, locale: locale, hyperlinkPattern: hyperlinkPattern, entityStore: entityStore, resolveDesignValue: resolveDesignValue, wrappingPatternIds: wrappingPatternIds }));
101
+ slotsProps[slotId] = (jsx(CompositionBlock, { node: slotNode, locale: locale, hyperlinkPattern: hyperlinkPattern, entityStore: entityStore, resolveDesignValue: resolveDesignValue, wrappingPatternIds: wrappingPatternIds }));
103
102
  }
104
103
  }
105
104
  }
106
- return props;
105
+ const props = {
106
+ className: ssrProps.cfSsrClassName ?? mediaQuery?.className,
107
+ ...styleProps,
108
+ ...contentProps,
109
+ ...customDesignProps,
110
+ ...slotsProps,
111
+ };
112
+ return {
113
+ ssrProps,
114
+ contentProps,
115
+ slotsProps,
116
+ styleProps,
117
+ customDesignProps,
118
+ mediaQuery,
119
+ props,
120
+ };
107
121
  }, [
108
122
  node.variables,
109
123
  node.id,
@@ -117,7 +131,8 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
117
131
  locale,
118
132
  wrappingPatternIds,
119
133
  ]);
120
- const className = useClassName({ props: nodeProps, node });
134
+ // do not inject the stylesheet into the dom because it's already been done on the server side
135
+ useInjectStylesheet(ssrProps.cfSsrClassName ? undefined : mediaQuery);
121
136
  if (!componentRegistration) {
122
137
  return null;
123
138
  }
@@ -145,23 +160,22 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
145
160
  })
146
161
  : null;
147
162
  if ([CONTENTFUL_COMPONENTS.container.id, CONTENTFUL_COMPONENTS.section.id].includes(node.definitionId)) {
148
- return (jsx(ContentfulContainer, { editorMode: false, cfHyperlink: nodeProps.cfHyperlink, cfOpenInNewTab: nodeProps.cfOpenInNewTab, className: className, children: children }));
163
+ return (jsx(ContentfulContainer, { editorMode: false, cfHyperlink: contentProps.cfHyperlink, cfOpenInNewTab: contentProps.cfOpenInNewTab, className: props.className, children: children }));
149
164
  }
150
165
  if (node.definitionId === CONTENTFUL_COMPONENTS.columns.id) {
151
- return (jsx(Columns, { editorMode: false, className: className, children: children }));
166
+ return (jsx(Columns, { editorMode: false, className: props.className, children: children }));
152
167
  }
153
168
  if (node.definitionId === CONTENTFUL_COMPONENTS.singleColumn.id) {
154
- return (jsx(SingleColumn, { editorMode: false, className: className, children: children }));
169
+ return (jsx(SingleColumn, { editorMode: false, className: props.className, children: children }));
155
170
  }
156
171
  if (node.definitionId === CONTENTFUL_COMPONENTS.image.id &&
157
172
  node.variables.cfImageAsset?.type === 'UnboundValue') {
158
- return jsx(PreviewUnboundImage, { node: node, nodeProps: nodeProps, component: component });
173
+ return (jsx(PreviewUnboundImage, { node: node, nodeProps: props, component: component, breakpoints: entityStore.breakpoints }));
159
174
  }
160
175
  return React.createElement(component, {
161
- ...sanitizeNodeProps(nodeProps),
162
- className,
176
+ ...sanitizeNodeProps(props),
163
177
  key: `${node.id}-${hasRendered}`,
164
- }, children ?? (typeof nodeProps.children === 'string' ? nodeProps.children : null));
178
+ }, children ?? (typeof props.children === 'string' ? props.children : null));
165
179
  };
166
180
 
167
181
  export { CompositionBlock };
@@ -1 +1 @@
1
- {"version":3,"file":"CompositionBlock.js","sources":["../../../../src/blocks/preview/CompositionBlock.tsx"],"sourcesContent":["import React, { useEffect, useMemo } from 'react';\nimport type { UnresolvedLink } from 'contentful';\nimport {\n EntityStore,\n resolveHyperlinkPattern,\n sanitizeNodeProps,\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 PrimitiveValue,\n ResolveDesignValueType,\n StyleProps,\n} from '@contentful/experiences-core/types';\nimport { createAssemblyRegistration, getComponentRegistration } from '../../core/componentRegistry';\nimport { checkIsAssemblyNode, transformBoundContentValue } from '@contentful/experiences-core';\nimport { useClassName } from '../../hooks/useClassName';\nimport {\n Assembly,\n Columns,\n ContentfulContainer,\n SingleColumn,\n} from '@contentful/experiences-components-react';\n\nimport { resolveAssembly } from '../../core/preview/assemblyUtils';\nimport { Entry } from 'contentful';\nimport PreviewUnboundImage from './PreviewUnboundImage';\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 wrappingPatternIds?: Set<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}: CompositionBlockProps) => {\n const [hasRendered, setHasRendered] = React.useState(false);\n\n useEffect(() => {\n setHasRendered(true);\n }, []);\n\n const isAssembly = useMemo(\n () =>\n checkIsAssemblyNode({\n componentId: rawNode.definitionId,\n usedComponents: entityStore.usedComponents,\n }),\n [entityStore.usedComponents, rawNode.definitionId],\n );\n\n const node = useMemo(() => {\n return isAssembly\n ? resolveAssembly({\n node: rawNode,\n entityStore,\n })\n : rawNode;\n }, [entityStore, isAssembly, rawNode]);\n\n const wrappingPatternIds = useMemo(() => {\n if (isAssembly) {\n return new Set([node.definitionId, ...parentWrappingPatternIds]);\n }\n return parentWrappingPatternIds;\n }, [isAssembly, node, parentWrappingPatternIds]);\n\n const componentRegistration = useMemo(() => {\n const registration = getComponentRegistration(node.definitionId as string);\n\n if (isAssembly && !registration) {\n return createAssemblyRegistration({\n definitionId: node.definitionId as string,\n component: Assembly,\n });\n }\n return registration;\n }, [isAssembly, node.definitionId]);\n\n const nodeProps = 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 cfSsrClassName = resolveDesignValue(\n cfSsrClassNameValues?.valuesByBreakpoint,\n 'cfSsrClassName',\n );\n\n // Don't enrich the assembly wrapper node with props\n if (!componentRegistration || isAssembly) {\n return { cfSsrClassName };\n }\n\n const propMap: Record<string, PrimitiveValue> = {\n cfSsrClassName:\n node.id && getPatternChildNodeClassName\n ? getPatternChildNodeClassName(node.id)\n : cfSsrClassName,\n };\n\n const props = Object.entries(componentRegistration.definition.variables).reduce(\n (acc, [variableName, variableDefinition]) => {\n const variable = node.variables[variableName];\n if (!variable) return acc;\n\n switch (variable.type) {\n case 'DesignValue':\n acc[variableName] = resolveDesignValue(variable.valuesByBreakpoint, variableName);\n break;\n case 'BoundValue': {\n const [, uuid] = variable.path.split('/');\n const binding = entityStore.dataSource[uuid] as UnresolvedLink<'Entry' | 'Asset'>;\n\n const value = transformBoundContentValue(\n node.variables,\n entityStore,\n binding,\n resolveDesignValue,\n variableName,\n variableDefinition,\n variable.path,\n );\n acc[variableName] = value ?? variableDefinition.defaultValue;\n break;\n }\n\n case 'HyperlinkValue': {\n const binding = entityStore.dataSource[variable.linkTargetKey];\n const hyperlinkEntry = entityStore.getEntryOrAsset(binding, variable.linkTargetKey);\n\n const value = resolveHyperlinkPattern(\n componentRegistration.definition.hyperlinkPattern ||\n hyperlinkPattern ||\n HYPERLINK_DEFAULT_PATTERN,\n hyperlinkEntry as Entry,\n locale,\n );\n if (value) {\n acc[variableName] = value;\n }\n break;\n }\n case 'UnboundValue': {\n const uuid = variable.key;\n acc[variableName] =\n entityStore.unboundValues[uuid]?.value ?? variableDefinition.defaultValue;\n break;\n }\n case 'ComponentValue':\n // We're rendering a pattern entry. Content cannot be set for ComponentValue type properties\n // directly in the pattern so we can safely use the default value\n // This can either a design (style) or a content variable\n acc[variableName] = variableDefinition.defaultValue;\n break;\n default:\n break;\n }\n return acc;\n },\n propMap,\n );\n\n if (componentRegistration.definition.slots) {\n for (const slotId in componentRegistration.definition.slots) {\n const slotNode = node.children.find((child) => child.slotId === slotId);\n if (slotNode) {\n props[slotId] = (\n <CompositionBlock\n node={slotNode}\n locale={locale}\n hyperlinkPattern={hyperlinkPattern}\n entityStore={entityStore}\n resolveDesignValue={resolveDesignValue}\n wrappingPatternIds={wrappingPatternIds}\n />\n );\n }\n }\n }\n\n return props;\n }, [\n node.variables,\n node.id,\n node.children,\n resolveDesignValue,\n componentRegistration,\n isAssembly,\n getPatternChildNodeClassName,\n entityStore,\n hyperlinkPattern,\n locale,\n wrappingPatternIds,\n ]);\n\n const className = useClassName({ props: nodeProps, node });\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 } = componentRegistration;\n\n // Retrieves the CSS class name for a given child node ID.\n const _getPatternChildNodeClassName = (childNodeId: string) => {\n if (isAssembly) {\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?.[childNodeId];\n if (!classesForNode) return undefined;\n return resolveDesignValue(classesForNode.valuesByBreakpoint, 'cfSsrClassName') as string;\n }\n return getPatternChildNodeClassName?.(childNodeId);\n };\n\n const children =\n componentRegistration.definition.children === true\n ? node.children.map((childNode: ComponentTreeNode, index) => {\n return (\n <CompositionBlock\n getPatternChildNodeClassName={\n isAssembly || getPatternChildNodeClassName\n ? _getPatternChildNodeClassName\n : undefined\n }\n node={childNode}\n key={index}\n locale={locale}\n hyperlinkPattern={hyperlinkPattern}\n entityStore={entityStore}\n resolveDesignValue={resolveDesignValue}\n wrappingPatternIds={wrappingPatternIds}\n />\n );\n })\n : null;\n\n if (\n [CONTENTFUL_COMPONENTS.container.id, CONTENTFUL_COMPONENTS.section.id].includes(\n node.definitionId,\n )\n ) {\n return (\n <ContentfulContainer\n editorMode={false}\n cfHyperlink={(nodeProps as StyleProps).cfHyperlink}\n cfOpenInNewTab={(nodeProps as StyleProps).cfOpenInNewTab}\n className={className}>\n {children}\n </ContentfulContainer>\n );\n }\n\n if (node.definitionId === CONTENTFUL_COMPONENTS.columns.id) {\n return (\n <Columns editorMode={false} className={className}>\n {children}\n </Columns>\n );\n }\n\n if (node.definitionId === CONTENTFUL_COMPONENTS.singleColumn.id) {\n return (\n <SingleColumn editorMode={false} className={className}>\n {children}\n </SingleColumn>\n );\n }\n\n if (\n node.definitionId === CONTENTFUL_COMPONENTS.image.id &&\n node.variables.cfImageAsset?.type === 'UnboundValue'\n ) {\n return <PreviewUnboundImage node={node} nodeProps={nodeProps} component={component} />;\n }\n\n return React.createElement(\n component,\n {\n ...sanitizeNodeProps(nodeProps),\n className,\n key: `${node.id}-${hasRendered}`,\n },\n children ?? (typeof nodeProps.children === 'string' ? nodeProps.children : null),\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;;;;AA0CO,MAAM,gBAAgB,GAAG,CAAC,EAC/B,IAAI,EAAE,OAAO,EACb,MAAM,EACN,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,4BAA4B,EAC5B,kBAAkB,EAAE,wBAAwB,GAAG,IAAI,GAAG,EAAE,GAClC,KAAI;AAC1B,IAAA,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE5D,SAAS,CAAC,MAAK;QACb,cAAc,CAAC,IAAI,CAAC,CAAC;KACtB,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,UAAU,GAAG,OAAO,CACxB,MACE,mBAAmB,CAAC;QAClB,WAAW,EAAE,OAAO,CAAC,YAAY;QACjC,cAAc,EAAE,WAAW,CAAC,cAAc;KAC3C,CAAC,EACJ,CAAC,WAAW,CAAC,cAAc,EAAE,OAAO,CAAC,YAAY,CAAC,CACnD,CAAC;AAEF,IAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAK;AACxB,QAAA,OAAO,UAAU;cACb,eAAe,CAAC;AACd,gBAAA,IAAI,EAAE,OAAO;gBACb,WAAW;aACZ,CAAC;cACF,OAAO,CAAC;KACb,EAAE,CAAC,WAAW,EAAE,UAAU,EAAE,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EAAI,WAAW,CAAE,CAAA;KACjC,EACD,QAAQ,KAAK,OAAO,SAAS,CAAC,QAAQ,KAAK,QAAQ,GAAG,SAAS,CAAC,QAAQ,GAAG,IAAI,CAAC,CACjF,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"CompositionBlock.js","sources":["../../../../src/blocks/preview/CompositionBlock.tsx"],"sourcesContent":["import React, { ReactNode, useEffect, useMemo, useState } from 'react';\nimport type { UnresolvedLink } from 'contentful';\nimport {\n EntityStore,\n resolveHyperlinkPattern,\n sanitizeNodeProps,\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 PrimitiveValue,\n ResolveDesignValueType,\n StyleProps,\n} from '@contentful/experiences-core/types';\nimport { createAssemblyRegistration, getComponentRegistration } from '../../core/componentRegistry';\nimport { checkIsAssemblyNode, transformBoundContentValue } from '@contentful/experiences-core';\nimport { useInjectStylesheet } from '../../hooks/useClassName';\nimport {\n Assembly,\n Columns,\n ContentfulContainer,\n SingleColumn,\n} from '@contentful/experiences-components-react';\nimport { resolveAssembly } from '../../core/preview/assemblyUtils';\nimport { Entry } from 'contentful';\nimport PreviewUnboundImage from './PreviewUnboundImage';\nimport { parseComponentProps } from '../../utils/parseComponentProps';\nimport { resolveClassNamesFromBuiltInStyles } from '../../hooks/useMediaQuery';\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 wrappingPatternIds?: Set<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}: CompositionBlockProps) => {\n const [hasRendered, setHasRendered] = useState(false);\n\n useEffect(() => {\n setHasRendered(true);\n }, []);\n\n const isAssembly = useMemo(\n () =>\n checkIsAssemblyNode({\n componentId: rawNode.definitionId,\n usedComponents: entityStore.usedComponents,\n }),\n [entityStore.usedComponents, rawNode.definitionId],\n );\n\n const node = useMemo(() => {\n return isAssembly\n ? resolveAssembly({\n node: rawNode,\n entityStore,\n })\n : rawNode;\n }, [entityStore, isAssembly, rawNode]);\n\n const wrappingPatternIds = useMemo(() => {\n if (isAssembly) {\n return new Set([node.definitionId, ...parentWrappingPatternIds]);\n }\n return parentWrappingPatternIds;\n }, [isAssembly, node, parentWrappingPatternIds]);\n\n const componentRegistration = useMemo(() => {\n const registration = getComponentRegistration(node.definitionId as string);\n\n if (isAssembly && !registration) {\n return createAssemblyRegistration({\n definitionId: node.definitionId as string,\n component: Assembly,\n });\n }\n return registration;\n }, [isAssembly, 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 || isAssembly) {\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 componentDefinition: componentRegistration.definition,\n node,\n resolveCustomDesignValue: ({ propertyName, valuesByBreakpoint }) => {\n return resolveDesignValue(valuesByBreakpoint, propertyName);\n },\n resolveBoundValue: ({ binding, propertyName, dataType }) => {\n const [, uuid] = binding.path.split('/');\n const boundEntityLink = entityStore.dataSource[uuid] as UnresolvedLink<'Entry' | 'Asset'>;\n const boundValue = transformBoundContentValue(\n node.variables,\n entityStore,\n boundEntityLink,\n resolveDesignValue,\n propertyName,\n dataType,\n binding.path,\n );\n\n return boundValue;\n },\n resolveHyperlinkValue: ({ linkTargetKey }) => {\n const boundEntity = entityStore.dataSource[linkTargetKey];\n const hyperlinkEntry = entityStore.getEntryOrAsset(boundEntity, linkTargetKey);\n\n const value = resolveHyperlinkPattern(\n componentRegistration.definition.hyperlinkPattern ||\n hyperlinkPattern ||\n HYPERLINK_DEFAULT_PATTERN,\n hyperlinkEntry as Entry,\n locale,\n );\n\n return value;\n },\n resolveUnboundValue: ({ mappingKey, defaultValue }) => {\n return entityStore.unboundValues[mappingKey]?.value ?? defaultValue;\n },\n resolveClassNamesFromBuiltInStyles: (designPropsByBreakpointId) => {\n return resolveClassNamesFromBuiltInStyles({\n designPropsByBreakpointId,\n breakpoints: entityStore.breakpoints,\n node,\n });\n },\n });\n\n const slotsProps: Record<string, ReactNode> = {};\n\n if (componentRegistration.definition.slots) {\n for (const slotId in componentRegistration.definition.slots) {\n const slotNode = node.children.find((child) => child.slotId === slotId);\n if (slotNode) {\n slotsProps[slotId] = (\n <CompositionBlock\n node={slotNode}\n locale={locale}\n hyperlinkPattern={hyperlinkPattern}\n entityStore={entityStore}\n resolveDesignValue={resolveDesignValue}\n wrappingPatternIds={wrappingPatternIds}\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 ...slotsProps,\n };\n\n return {\n ssrProps,\n contentProps,\n slotsProps,\n styleProps,\n customDesignProps,\n mediaQuery,\n props,\n };\n }, [\n node.variables,\n node.id,\n node.children,\n resolveDesignValue,\n componentRegistration,\n isAssembly,\n getPatternChildNodeClassName,\n entityStore,\n hyperlinkPattern,\n locale,\n wrappingPatternIds,\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);\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 } = componentRegistration;\n\n // Retrieves the CSS class name for a given child node ID.\n const _getPatternChildNodeClassName = (childNodeId: string) => {\n if (isAssembly) {\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?.[childNodeId];\n if (!classesForNode) return undefined;\n return resolveDesignValue(classesForNode.valuesByBreakpoint, 'cfSsrClassName') as string;\n }\n return getPatternChildNodeClassName?.(childNodeId);\n };\n\n const children =\n componentRegistration.definition.children === true\n ? node.children.map((childNode: ComponentTreeNode, index) => {\n return (\n <CompositionBlock\n getPatternChildNodeClassName={\n isAssembly || getPatternChildNodeClassName\n ? _getPatternChildNodeClassName\n : undefined\n }\n node={childNode}\n key={index}\n locale={locale}\n hyperlinkPattern={hyperlinkPattern}\n entityStore={entityStore}\n resolveDesignValue={resolveDesignValue}\n wrappingPatternIds={wrappingPatternIds}\n />\n );\n })\n : null;\n\n if (\n [CONTENTFUL_COMPONENTS.container.id, CONTENTFUL_COMPONENTS.section.id].includes(\n node.definitionId,\n )\n ) {\n return (\n <ContentfulContainer\n editorMode={false}\n cfHyperlink={(contentProps as StyleProps).cfHyperlink}\n cfOpenInNewTab={(contentProps as StyleProps).cfOpenInNewTab}\n className={props.className as string | undefined}>\n {children}\n </ContentfulContainer>\n );\n }\n\n if (node.definitionId === CONTENTFUL_COMPONENTS.columns.id) {\n return (\n <Columns editorMode={false} className={props.className as string | undefined}>\n {children}\n </Columns>\n );\n }\n\n if (node.definitionId === CONTENTFUL_COMPONENTS.singleColumn.id) {\n return (\n <SingleColumn editorMode={false} className={props.className as string | undefined}>\n {children}\n </SingleColumn>\n );\n }\n\n if (\n node.definitionId === CONTENTFUL_COMPONENTS.image.id &&\n node.variables.cfImageAsset?.type === 'UnboundValue'\n ) {\n return (\n <PreviewUnboundImage\n node={node}\n nodeProps={props}\n component={component}\n breakpoints={entityStore.breakpoints}\n />\n );\n }\n\n return React.createElement(\n component,\n {\n ...sanitizeNodeProps(props),\n key: `${node.id}-${hasRendered}`,\n },\n children ?? (typeof props.children === 'string' ? props.children : null),\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;AA2CO,MAAM,gBAAgB,GAAG,CAAC,EAC/B,IAAI,EAAE,OAAO,EACb,MAAM,EACN,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,4BAA4B,EAC5B,kBAAkB,EAAE,wBAAwB,GAAG,IAAI,GAAG,EAAE,GAClC,KAAI;IAC1B,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEtD,SAAS,CAAC,MAAK;QACb,cAAc,CAAC,IAAI,CAAC,CAAC;KACtB,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,UAAU,GAAG,OAAO,CACxB,MACE,mBAAmB,CAAC;QAClB,WAAW,EAAE,OAAO,CAAC,YAAY;QACjC,cAAc,EAAE,WAAW,CAAC,cAAc;KAC3C,CAAC,EACJ,CAAC,WAAW,CAAC,cAAc,EAAE,OAAO,CAAC,YAAY,CAAC,CACnD,CAAC;AAEF,IAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAK;AACxB,QAAA,OAAO,UAAU;cACb,eAAe,CAAC;AACd,gBAAA,IAAI,EAAE,OAAO;gBACb,WAAW;aACZ,CAAC;cACF,OAAO,CAAC;KACb,EAAE,CAAC,WAAW,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;AAEvC,IAAA,MAAM,kBAAkB,GAAG,OAAO,CAAC,MAAK;QACtC,IAAI,UAAU,EAAE;AACd,YAAA,OAAO,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AAC,WAAW,EACpC,CAAA,EACF;KACH;AAED,IAAA,OAAO,KAAK,CAAC,aAAa,CACxB,SAAS,EACT;QACE,GAAG,iBAAiB,CAAC,KAAK,CAAC;AAC3B,QAAA,GAAG,EAAE,CAAG,EAAA,IAAI,CAAC,EAAE,CAAA,CAAA,EAAI,WAAW,CAAE,CAAA;KACjC,EACD,QAAQ,KAAK,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ,GAAG,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,CACzE,CAAC;AACJ;;;;"}
@@ -1,33 +1,50 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
- import React from 'react';
2
+ import React, { useMemo } from 'react';
3
3
  import { sanitizeNodeProps } from '@contentful/experiences-core';
4
- import { useClassName } from '../../hooks/useClassName.js';
4
+ import { useMediaQuery } from '../../hooks/useMediaQuery.js';
5
+ import { useInjectStylesheet } from '../../hooks/useClassName.js';
6
+ import classNames from 'classnames';
5
7
 
6
8
  /**
7
9
  * This component is used to render a placeholder Image component in the preview
8
10
  * when the image is unbound. It applies the Image size styles to a wrapping div.
9
11
  */
10
- const PreviewUnboundImage = ({ node, nodeProps, component, }) => {
11
- const wrapperStyle = {
12
- position: 'relative',
13
- };
14
- const modifiedNodeProps = { ...nodeProps };
15
- if (typeof modifiedNodeProps.cfImageOptions === 'object') {
16
- const { width, height, ...restImageOptions } = modifiedNodeProps.cfImageOptions;
17
- // Apply the Image size styles to the wrapping div
18
- wrapperStyle.height = String(height);
19
- wrapperStyle.width = String(width);
20
- // Set the Image height and width to 100% to fill the wrapping div
21
- modifiedNodeProps.cfImageOptions = {
22
- ...restImageOptions,
23
- height: '100%',
24
- width: '100%',
25
- };
26
- }
27
- const className = useClassName({ props: modifiedNodeProps, node });
28
- return (jsx("div", { className: "cf-preview-unbound-image", style: wrapperStyle, children: React.createElement(component, {
29
- ...sanitizeNodeProps(modifiedNodeProps),
30
- className,
12
+ const PreviewUnboundImage = ({ breakpoints, node, nodeProps, component, }) => {
13
+ const { wrapperStyle, imageStyle } = useMemo(() => {
14
+ const imageStyle = {};
15
+ const wrapperStyle = {};
16
+ if (nodeProps.cfImageOptions && typeof nodeProps.cfImageOptions === 'object') {
17
+ for (const [breakpointId, styles] of Object.entries(nodeProps.cfImageOptions)) {
18
+ imageStyle[breakpointId] = {
19
+ cfImageOptions: {
20
+ ...styles,
21
+ height: '100%',
22
+ width: '100%',
23
+ },
24
+ };
25
+ wrapperStyle[breakpointId] = {
26
+ cfHeight: styles.height,
27
+ cfWidth: styles.width,
28
+ };
29
+ }
30
+ }
31
+ return { imageStyle, wrapperStyle };
32
+ }, [nodeProps.cfImageOptions]);
33
+ const wrapperMedia = useMediaQuery({
34
+ designPropsByBreakpointId: wrapperStyle,
35
+ node,
36
+ breakpoints,
37
+ });
38
+ const imageMedia = useMediaQuery({
39
+ designPropsByBreakpointId: imageStyle,
40
+ node,
41
+ breakpoints,
42
+ });
43
+ useInjectStylesheet(wrapperMedia);
44
+ useInjectStylesheet(imageMedia);
45
+ return (jsx("div", { className: classNames('cf-preview-unbound-image', wrapperMedia.className), children: React.createElement(component, {
46
+ ...sanitizeNodeProps(nodeProps),
47
+ className: imageMedia.css ? imageMedia.className : nodeProps.className,
31
48
  }) }));
32
49
  };
33
50
 
@@ -1 +1 @@
1
- {"version":3,"file":"PreviewUnboundImage.js","sources":["../../../../src/blocks/preview/PreviewUnboundImage.tsx"],"sourcesContent":["import React from 'react';\nimport type {\n ComponentTreeNode,\n CSSProperties,\n PrimitiveValue,\n} from '@contentful/experiences-core/types';\nimport { sanitizeNodeProps } from '@contentful/experiences-core';\nimport { useClassName } from '../../hooks/useClassName';\n\ninterface PreviewUnboundImageProps {\n node: ComponentTreeNode;\n nodeProps: Record<PropertyKey, PrimitiveValue>;\n component: React.ElementType;\n}\n\n/**\n * This component is used to render a placeholder Image component in the preview\n * when the image is unbound. It applies the Image size styles to a wrapping div.\n */\nconst PreviewUnboundImage: React.FC<PreviewUnboundImageProps> = ({\n node,\n nodeProps,\n component,\n}) => {\n const wrapperStyle: CSSProperties = {\n position: 'relative',\n };\n\n const modifiedNodeProps = { ...nodeProps };\n if (typeof modifiedNodeProps.cfImageOptions === 'object') {\n const { width, height, ...restImageOptions } = modifiedNodeProps.cfImageOptions;\n\n // Apply the Image size styles to the wrapping div\n wrapperStyle.height = String(height);\n wrapperStyle.width = String(width);\n\n // Set the Image height and width to 100% to fill the wrapping div\n modifiedNodeProps.cfImageOptions = {\n ...restImageOptions,\n height: '100%',\n width: '100%',\n };\n }\n\n const className = useClassName({ props: modifiedNodeProps, node });\n\n return (\n <div className=\"cf-preview-unbound-image\" style={wrapperStyle}>\n {React.createElement(component, {\n ...sanitizeNodeProps(modifiedNodeProps),\n className,\n })}\n </div>\n );\n};\n\nexport default PreviewUnboundImage;\n"],"names":["_jsx"],"mappings":";;;;;AAeA;;;AAGG;AACG,MAAA,mBAAmB,GAAuC,CAAC,EAC/D,IAAI,EACJ,SAAS,EACT,SAAS,GACV,KAAI;AACH,IAAA,MAAM,YAAY,GAAkB;AAClC,QAAA,QAAQ,EAAE,UAAU;KACrB,CAAC;AAEF,IAAA,MAAM,iBAAiB,GAAG,EAAE,GAAG,SAAS,EAAE,CAAC;AAC3C,IAAA,IAAI,OAAO,iBAAiB,CAAC,cAAc,KAAK,QAAQ,EAAE;AACxD,QAAA,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,gBAAgB,EAAE,GAAG,iBAAiB,CAAC,cAAc,CAAC;;AAGhF,QAAA,YAAY,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AACrC,QAAA,YAAY,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;;QAGnC,iBAAiB,CAAC,cAAc,GAAG;AACjC,YAAA,GAAG,gBAAgB;AACnB,YAAA,MAAM,EAAE,MAAM;AACd,YAAA,KAAK,EAAE,MAAM;SACd,CAAC;KACH;AAED,IAAA,MAAM,SAAS,GAAG,YAAY,CAAC,EAAE,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC;AAEnE,IAAA,QACEA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,0BAA0B,EAAC,KAAK,EAAE,YAAY,YAC1D,KAAK,CAAC,aAAa,CAAC,SAAS,EAAE;YAC9B,GAAG,iBAAiB,CAAC,iBAAiB,CAAC;YACvC,SAAS;SACV,CAAC,EAAA,CACE,EACN;AACJ;;;;"}
1
+ {"version":3,"file":"PreviewUnboundImage.js","sources":["../../../../src/blocks/preview/PreviewUnboundImage.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport type {\n Breakpoint,\n ComponentTreeNode,\n PrimitiveValue,\n} from '@contentful/experiences-core/types';\nimport { sanitizeNodeProps } from '@contentful/experiences-core';\nimport { useMediaQuery } from '../../hooks/useMediaQuery';\nimport { useInjectStylesheet } from '../../hooks/useClassName';\nimport classNames from 'classnames';\n\ninterface PreviewUnboundImageProps {\n breakpoints: Breakpoint[];\n node: ComponentTreeNode;\n nodeProps: Record<PropertyKey, PrimitiveValue>;\n component: React.ElementType;\n}\n\n/**\n * This component is used to render a placeholder Image component in the preview\n * when the image is unbound. It applies the Image size styles to a wrapping div.\n */\nconst PreviewUnboundImage: React.FC<PreviewUnboundImageProps> = ({\n breakpoints,\n node,\n nodeProps,\n component,\n}) => {\n const { wrapperStyle, imageStyle } = useMemo(() => {\n const imageStyle: Record<string, any> = {};\n const wrapperStyle: Record<string, any> = {};\n\n if (nodeProps.cfImageOptions && typeof nodeProps.cfImageOptions === 'object') {\n for (const [breakpointId, styles] of Object.entries(nodeProps.cfImageOptions)) {\n imageStyle[breakpointId] = {\n cfImageOptions: {\n ...styles,\n height: '100%',\n width: '100%',\n },\n };\n\n wrapperStyle[breakpointId] = {\n cfHeight: styles.height,\n cfWidth: styles.width,\n };\n }\n }\n\n return { imageStyle, wrapperStyle };\n }, [nodeProps.cfImageOptions]);\n\n const wrapperMedia = useMediaQuery({\n designPropsByBreakpointId: wrapperStyle,\n node,\n breakpoints,\n });\n\n const imageMedia = useMediaQuery({\n designPropsByBreakpointId: imageStyle,\n node,\n breakpoints,\n });\n\n useInjectStylesheet(wrapperMedia);\n useInjectStylesheet(imageMedia);\n\n return (\n <div className={classNames('cf-preview-unbound-image', wrapperMedia.className)}>\n {React.createElement(component, {\n ...sanitizeNodeProps(nodeProps),\n className: imageMedia.css ? imageMedia.className : nodeProps.className,\n })}\n </div>\n );\n};\n\nexport default PreviewUnboundImage;\n"],"names":["_jsx"],"mappings":";;;;;;;AAkBA;;;AAGG;AACH,MAAM,mBAAmB,GAAuC,CAAC,EAC/D,WAAW,EACX,IAAI,EACJ,SAAS,EACT,SAAS,GACV,KAAI;IACH,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,MAAK;QAChD,MAAM,UAAU,GAAwB,EAAE,CAAC;QAC3C,MAAM,YAAY,GAAwB,EAAE,CAAC;QAE7C,IAAI,SAAS,CAAC,cAAc,IAAI,OAAO,SAAS,CAAC,cAAc,KAAK,QAAQ,EAAE;AAC5E,YAAA,KAAK,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,cAAc,CAAC,EAAE;gBAC7E,UAAU,CAAC,YAAY,CAAC,GAAG;AACzB,oBAAA,cAAc,EAAE;AACd,wBAAA,GAAG,MAAM;AACT,wBAAA,MAAM,EAAE,MAAM;AACd,wBAAA,KAAK,EAAE,MAAM;AACd,qBAAA;iBACF,CAAC;gBAEF,YAAY,CAAC,YAAY,CAAC,GAAG;oBAC3B,QAAQ,EAAE,MAAM,CAAC,MAAM;oBACvB,OAAO,EAAE,MAAM,CAAC,KAAK;iBACtB,CAAC;aACH;SACF;AAED,QAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC;AACtC,KAAC,EAAE,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC;IAE/B,MAAM,YAAY,GAAG,aAAa,CAAC;AACjC,QAAA,yBAAyB,EAAE,YAAY;QACvC,IAAI;QACJ,WAAW;AACZ,KAAA,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,aAAa,CAAC;AAC/B,QAAA,yBAAyB,EAAE,UAAU;QACrC,IAAI;QACJ,WAAW;AACZ,KAAA,CAAC,CAAC;IAEH,mBAAmB,CAAC,YAAY,CAAC,CAAC;IAClC,mBAAmB,CAAC,UAAU,CAAC,CAAC;AAEhC,IAAA,QACEA,GAAK,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,UAAU,CAAC,0BAA0B,EAAE,YAAY,CAAC,SAAS,CAAC,EAC3E,QAAA,EAAA,KAAK,CAAC,aAAa,CAAC,SAAS,EAAE;YAC9B,GAAG,iBAAiB,CAAC,SAAS,CAAC;AAC/B,YAAA,SAAS,EAAE,UAAU,CAAC,GAAG,GAAG,UAAU,CAAC,SAAS,GAAG,SAAS,CAAC,SAAS;SACvE,CAAC,EAAA,CACE,EACN;AACJ;;;;"}
@@ -151,7 +151,11 @@ const optionalBuiltInComponents = [
151
151
  ];
152
152
  const sendRegisteredComponentsMessage = () => {
153
153
  // Send the definitions (without components) via the connection message to the experience builder
154
- const registeredDefinitions = Array.from(componentRegistry.values()).map(({ definition }) => definition);
154
+ const registeredDefinitions = Array.from(componentRegistry.values())
155
+ .map(({ definition }) => definition)
156
+ // Pattern definitions are empty placeholder within the SDK without variables
157
+ // We don't send those to the editor as they would overwrite the actual correct definitions.
158
+ .filter((definition) => definition.category !== ASSEMBLY_DEFAULT_CATEGORY);
155
159
  sendMessage(OUTGOING_EVENTS.RegisteredComponents, {
156
160
  definitions: registeredDefinitions,
157
161
  });
@@ -1 +1 @@
1
- {"version":3,"file":"componentRegistry.js","sources":["../../../src/core/componentRegistry.ts"],"sourcesContent":["import * as Components from '@contentful/experiences-components-react';\nimport type {\n ComponentRegistration,\n ComponentDefinition,\n ComponentRegistrationOptions,\n DesignTokensDefinition,\n} from '@contentful/experiences-core/types';\nimport {\n OUTGOING_EVENTS,\n INTERNAL_EVENTS,\n CONTENTFUL_COMPONENTS,\n ASSEMBLY_DEFAULT_CATEGORY,\n} from '@contentful/experiences-core/constants';\nimport {\n builtInStyles as builtInStyleDefinitions,\n designTokensRegistry,\n breakpointsRegistry,\n optionalBuiltInStyles,\n sendMessage,\n} from '@contentful/experiences-core';\nimport { validateComponentDefinition } from '@contentful/experiences-validators';\nimport { withComponentWrapper } from '../utils/withComponentWrapper';\nimport { SDK_VERSION } from '../constants';\nimport {\n sectionDefinition,\n containerDefinition,\n columnsDefinition,\n singleColumnDefinition,\n dividerDefinition,\n} from '@contentful/experiences-components-react';\n\nconst CssVarRegex = /var\\(--[\\w-]+\\)/;\n\nconst cloneObject = <T>(targetObject: T): T => {\n if (typeof structuredClone !== 'undefined') {\n return structuredClone(targetObject);\n }\n\n return JSON.parse(JSON.stringify(targetObject));\n};\n\nconst applyComponentDefinitionFallbacks = (componentDefinition: ComponentDefinition) => {\n const clone = cloneObject(componentDefinition);\n for (const variable of Object.values(clone.variables)) {\n variable.group = variable.group ?? 'content';\n }\n return clone;\n};\n\nconst applyBuiltInStyleDefinitions = (componentDefinition: ComponentDefinition) => {\n if ([CONTENTFUL_COMPONENTS.container.id].includes(componentDefinition.id)) {\n return componentDefinition;\n }\n\n const clone = cloneObject(componentDefinition);\n\n // set margin built-in style by default\n if (!clone.builtInStyles) {\n clone.builtInStyles = ['cfMargin'];\n }\n\n if (!clone.variables) {\n clone.variables = {};\n }\n\n // Enforce the presence of this property for toggling visibility on any node\n clone.variables['cfVisibility'] = builtInStyleDefinitions['cfVisibility'];\n\n for (const style of clone.builtInStyles || []) {\n if (builtInStyleDefinitions[style]) {\n clone.variables[style] = builtInStyleDefinitions[style] as any; // TODO: fix type\n }\n if (optionalBuiltInStyles[style]) {\n clone.variables[style] = optionalBuiltInStyles[style] as any; // TODO: fix type\n }\n }\n return clone;\n};\n\nexport const enrichComponentDefinition = ({\n component,\n definition,\n options,\n}: ComponentRegistration): ComponentRegistration => {\n const definitionWithFallbacks = applyComponentDefinitionFallbacks(definition);\n const definitionWithBuiltInStyles = applyBuiltInStyleDefinitions(definitionWithFallbacks);\n return {\n component: withComponentWrapper(component, options),\n definition: definitionWithBuiltInStyles,\n options,\n };\n};\n\nconst DEFAULT_COMPONENT_REGISTRATIONS = {\n container: {\n component: Components.ContentfulContainer,\n definition: containerDefinition,\n },\n section: {\n component: Components.ContentfulContainer,\n definition: sectionDefinition,\n },\n columns: {\n component: Components.Columns,\n definition: columnsDefinition,\n },\n singleColumn: {\n component: Components.SingleColumn,\n definition: singleColumnDefinition,\n },\n button: enrichComponentDefinition({\n component: Components.Button,\n definition: Components.ButtonComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n heading: enrichComponentDefinition({\n component: Components.Heading,\n definition: Components.HeadingComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n image: enrichComponentDefinition({\n component: Components.Image,\n definition: Components.ImageComponentDefinition,\n options: { wrapComponent: false },\n }),\n richText: enrichComponentDefinition({\n component: Components.RichText,\n definition: Components.RichTextComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n text: enrichComponentDefinition({\n component: Components.Text,\n definition: Components.TextComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n divider: {\n // Don't wrap this component `withComponentWrapper`. Need to explicitly ignore dragProps\n component: Components.ContentfulDivider,\n definition: dividerDefinition,\n options: {\n wrapComponent: false,\n },\n },\n carousel: enrichComponentDefinition({\n component: Components.Carousel,\n definition: Components.carouselDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n} satisfies Record<string, ComponentRegistration>;\n\n// pre-filling with the default component registrations\nexport const componentRegistry = new Map<string, ComponentRegistration>([\n [DEFAULT_COMPONENT_REGISTRATIONS.section.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.section],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.container.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.container,\n ],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.singleColumn.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.singleColumn,\n ],\n [DEFAULT_COMPONENT_REGISTRATIONS.columns.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.columns],\n [DEFAULT_COMPONENT_REGISTRATIONS.button.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.button],\n [DEFAULT_COMPONENT_REGISTRATIONS.heading.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.heading],\n [DEFAULT_COMPONENT_REGISTRATIONS.image.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.image],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.richText.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.richText,\n ],\n [DEFAULT_COMPONENT_REGISTRATIONS.text.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.text],\n [DEFAULT_COMPONENT_REGISTRATIONS.divider.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.divider],\n]);\n\nexport const optionalBuiltInComponents = [\n DEFAULT_COMPONENT_REGISTRATIONS.button.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.heading.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.image.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.richText.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.text.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.divider.definition.id,\n];\n\nexport const sendRegisteredComponentsMessage = () => {\n // Send the definitions (without components) via the connection message to the experience builder\n const registeredDefinitions = Array.from(componentRegistry.values()).map(\n ({ definition }) => definition,\n );\n\n sendMessage(OUTGOING_EVENTS.RegisteredComponents, {\n definitions: registeredDefinitions,\n });\n};\n\nexport const runRegisteredComponentValidations = () => {\n Array.from(componentRegistry.values()).map(({ definition }) => {\n const validation = validateComponentDefinition(definition);\n if (!validation.success) {\n throw new Error(\n `Invalid component definition for component '${definition.name}'. Failed with errors: \\n${JSON.stringify(validation.errors, null, 2)}`,\n );\n }\n });\n};\n\nconst getSingleCssVariableValue = (\n element: HTMLDivElement,\n cssVariableValue: string,\n cssAttribute: any,\n) => {\n element.style[cssAttribute] = cssVariableValue;\n const styles = getComputedStyle(element);\n const resolvedValue = styles.getPropertyValue(cssAttribute);\n return resolvedValue;\n};\n\nconst getAllCssVariableValues = (\n element: HTMLDivElement,\n cssVariable: Record<string, string>,\n cssAttribute: any,\n) => {\n const resolvedCssVariables = {} as Record<string, string>;\n\n Object.keys(cssVariable).forEach((key) => {\n const cssVariableValue = cssVariable[key];\n if (CssVarRegex.test(cssVariableValue)) {\n const resolvedValue = getSingleCssVariableValue(element, cssVariableValue, cssAttribute);\n resolvedCssVariables[cssVariableValue] = resolvedValue;\n }\n });\n return resolvedCssVariables;\n};\n\ntype CssMapType = {\n variable?: Record<string, string>;\n property: string;\n};\n\nconst resolveCssVariables = (designTokensDefinition: DesignTokensDefinition) => {\n const {\n spacing,\n sizing,\n color,\n borderRadius,\n fontSize,\n lineHeight,\n letterSpacing,\n textColor,\n border,\n } = designTokensDefinition;\n const resolvedCssVariables = {} as Record<string, string>;\n\n // Create an element\n const element = document.createElement('div');\n document.body.appendChild(element);\n\n const cssProperties: CssMapType[] = [\n { variable: spacing, property: 'margin' },\n { variable: sizing, property: 'width' },\n { variable: color, property: 'background-color' },\n { variable: borderRadius, property: 'border-radius' },\n { variable: fontSize, property: 'font-size' },\n { variable: lineHeight, property: 'line-height' },\n { variable: letterSpacing, property: 'letter-spacing' },\n { variable: textColor, property: 'color' },\n ];\n\n cssProperties.forEach(({ variable, property }) => {\n if (variable) {\n const rawResolvedValues = getAllCssVariableValues(element, variable, property);\n Object.assign(resolvedCssVariables, rawResolvedValues);\n }\n });\n\n if (border) {\n const tempResolvedValue = {} as Record<string, string>;\n Object.keys(border).forEach((borderKey) => {\n const { width, style, color } = border[borderKey];\n\n if (width && CssVarRegex.test(width)) {\n const resolvedValue = getSingleCssVariableValue(element, width, 'border-width');\n tempResolvedValue[width] = resolvedValue;\n }\n if (style && CssVarRegex.test(style)) {\n const resolvedValue = getSingleCssVariableValue(element, style, 'border-style');\n tempResolvedValue[style] = resolvedValue;\n }\n if (color && CssVarRegex.test(color)) {\n const resolvedValue = getSingleCssVariableValue(element, color, 'border-color');\n tempResolvedValue[color] = resolvedValue;\n }\n Object.assign(resolvedCssVariables, tempResolvedValue);\n });\n }\n\n document.body.removeChild(element);\n return resolvedCssVariables;\n};\n\nexport const sendConnectedEventWithRegisteredComponents = () => {\n // Send the definitions (without components) via the connection message to the experience builder\n const registeredDefinitions = Array.from(componentRegistry.values()).map(\n ({ definition }) => definition,\n );\n\n sendMessage(OUTGOING_EVENTS.Connected, {\n sdkVersion: SDK_VERSION,\n definitions: registeredDefinitions,\n });\n\n sendMessage(OUTGOING_EVENTS.RegisteredBreakpoints, {\n breakpoints: breakpointsRegistry,\n });\n\n sendMessage(OUTGOING_EVENTS.DesignTokens, {\n designTokens: designTokensRegistry,\n resolvedCssVariables: resolveCssVariables(designTokensRegistry),\n });\n};\n\n/**\n * Registers multiple components and their component definitions at once\n * @param componentRegistrations - ComponentRegistration[]\n * @returns void\n */\nexport const defineComponents = (\n componentRegistrations: ComponentRegistration[],\n options?: ComponentRegistrationOptions,\n) => {\n if (options?.experimentalComponents?.carousel) {\n componentRegistry.set(\n CONTENTFUL_COMPONENTS.carousel.id,\n DEFAULT_COMPONENT_REGISTRATIONS.carousel,\n );\n }\n\n if (options?.enabledBuiltInComponents) {\n for (const id of optionalBuiltInComponents) {\n if (!options.enabledBuiltInComponents.includes(id)) {\n componentRegistry.delete(id);\n }\n }\n }\n\n for (const registration of componentRegistrations) {\n // Fill definitions with fallbacks values\n const enrichedComponentRegistration = enrichComponentDefinition(registration);\n\n componentRegistry.set(\n enrichedComponentRegistration.definition.id,\n enrichedComponentRegistration,\n );\n }\n\n if (typeof window !== 'undefined') {\n window.dispatchEvent(new CustomEvent(INTERNAL_EVENTS.ComponentsRegistered));\n }\n};\n\n/**\n * use this function only in tests\n */\nexport const resetComponentRegistry = () => {\n componentRegistry.clear();\n for (const registration of Object.values(DEFAULT_COMPONENT_REGISTRATIONS)) {\n componentRegistry.set(registration.definition.id, registration);\n }\n};\n\nexport const getComponentRegistration = (id: string) => componentRegistry.get(id);\n\nexport const addComponentRegistration = (componentRegistration: ComponentRegistration) => {\n componentRegistry.set(componentRegistration.definition.id, componentRegistration);\n};\n\nexport const createAssemblyRegistration = ({\n definitionId,\n definitionName,\n component,\n}: {\n definitionId: string;\n definitionName?: string;\n component: ComponentRegistration['component'];\n}) => {\n const componentRegistration = componentRegistry.get(definitionId);\n\n if (componentRegistration) {\n return componentRegistration;\n }\n\n const definition = {\n id: definitionId,\n name: definitionName || 'Component',\n variables: {},\n children: true,\n category: ASSEMBLY_DEFAULT_CATEGORY,\n };\n\n addComponentRegistration({ component, definition });\n\n return componentRegistry.get(definitionId);\n};\n\n/**\n * @deprecated This method is used to maintain the basic component ids (without the prefix 'contentful-') in order to be compatible\n * with experiences created with an older alpha version of the SDK. Components in these experiences should be migrated to use\n * the components with the 'contentful-' prefix. To do so, load the experience in the editor, and replace any older basic components\n * (marked with [OLD] in the UI) with the new components (without the [OLD]). This method (and functionality for the older components)\n * will be removed in the next major release.\n */\nexport const maintainBasicComponentIdsWithoutPrefix = () => {\n optionalBuiltInComponents.forEach((id) => {\n if (componentRegistry.has(id) && id.startsWith('contentful-')) {\n const registeredComponent = componentRegistry.get(id)!;\n const definition = registeredComponent.definition;\n const newDefinition = cloneObject(definition);\n newDefinition.name = newDefinition.name + '[OLD]';\n const newId = id.replace('contentful-', '');\n newDefinition.id = newId;\n const newRegisteredComponent = { ...registeredComponent, definition: newDefinition };\n componentRegistry.set(newId, newRegisteredComponent);\n }\n });\n};\n"],"names":["builtInStyleDefinitions"],"mappings":";;;;;;;;AA+BA,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC,MAAM,WAAW,GAAG,CAAI,YAAe,KAAO;AAC5C,IAAA,IAAI,OAAO,eAAe,KAAK,WAAW,EAAE;AAC1C,QAA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,CAAC;AAEpD,IAAA,OAAO,iBAAiB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAC7C,EAAE;AAEF;;;;;;AAMG;AACI,MAAM,sCAAsC,GAAG,MAAK;AACzD,IAAA,yBAAyB,CAAC,OAAO,CAAC,CAAC,EAAE,KAAI;AACvC,QAAA,IAAI,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE;YAC7D,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC;AACvD,YAAA,MAAM,UAAU,GAAG,mBAAmB,CAAC,UAAU,CAAC;AAClD,YAAA,MAAM,aAAa,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;YAC9C,aAAa,CAAC,IAAI,GAAG,aAAa,CAAC,IAAI,GAAG,OAAO,CAAC;YAClD,MAAM,KAAK,GAAG,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;AAC5C,YAAA,aAAa,CAAC,EAAE,GAAG,KAAK,CAAC;YACzB,MAAM,sBAAsB,GAAG,EAAE,GAAG,mBAAmB,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;AACrF,YAAA,iBAAiB,CAAC,GAAG,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAC;SACtD;AACH,KAAC,CAAC,CAAC;AACL;;;;"}
1
+ {"version":3,"file":"componentRegistry.js","sources":["../../../src/core/componentRegistry.ts"],"sourcesContent":["import * as Components from '@contentful/experiences-components-react';\nimport type {\n ComponentRegistration,\n ComponentDefinition,\n ComponentRegistrationOptions,\n DesignTokensDefinition,\n} from '@contentful/experiences-core/types';\nimport {\n OUTGOING_EVENTS,\n INTERNAL_EVENTS,\n CONTENTFUL_COMPONENTS,\n ASSEMBLY_DEFAULT_CATEGORY,\n} from '@contentful/experiences-core/constants';\nimport {\n builtInStyles as builtInStyleDefinitions,\n designTokensRegistry,\n breakpointsRegistry,\n optionalBuiltInStyles,\n sendMessage,\n} from '@contentful/experiences-core';\nimport { validateComponentDefinition } from '@contentful/experiences-validators';\nimport { withComponentWrapper } from '../utils/withComponentWrapper';\nimport { SDK_VERSION } from '../constants';\nimport {\n sectionDefinition,\n containerDefinition,\n columnsDefinition,\n singleColumnDefinition,\n dividerDefinition,\n} from '@contentful/experiences-components-react';\n\nconst CssVarRegex = /var\\(--[\\w-]+\\)/;\n\nconst cloneObject = <T>(targetObject: T): T => {\n if (typeof structuredClone !== 'undefined') {\n return structuredClone(targetObject);\n }\n\n return JSON.parse(JSON.stringify(targetObject));\n};\n\nconst applyComponentDefinitionFallbacks = (componentDefinition: ComponentDefinition) => {\n const clone = cloneObject(componentDefinition);\n for (const variable of Object.values(clone.variables)) {\n variable.group = variable.group ?? 'content';\n }\n return clone;\n};\n\nconst applyBuiltInStyleDefinitions = (componentDefinition: ComponentDefinition) => {\n if ([CONTENTFUL_COMPONENTS.container.id].includes(componentDefinition.id)) {\n return componentDefinition;\n }\n\n const clone = cloneObject(componentDefinition);\n\n // set margin built-in style by default\n if (!clone.builtInStyles) {\n clone.builtInStyles = ['cfMargin'];\n }\n\n if (!clone.variables) {\n clone.variables = {};\n }\n\n // Enforce the presence of this property for toggling visibility on any node\n clone.variables['cfVisibility'] = builtInStyleDefinitions['cfVisibility'];\n\n for (const style of clone.builtInStyles || []) {\n if (builtInStyleDefinitions[style]) {\n clone.variables[style] = builtInStyleDefinitions[style] as any; // TODO: fix type\n }\n if (optionalBuiltInStyles[style]) {\n clone.variables[style] = optionalBuiltInStyles[style] as any; // TODO: fix type\n }\n }\n return clone;\n};\n\nexport const enrichComponentDefinition = ({\n component,\n definition,\n options,\n}: ComponentRegistration): ComponentRegistration => {\n const definitionWithFallbacks = applyComponentDefinitionFallbacks(definition);\n const definitionWithBuiltInStyles = applyBuiltInStyleDefinitions(definitionWithFallbacks);\n return {\n component: withComponentWrapper(component, options),\n definition: definitionWithBuiltInStyles,\n options,\n };\n};\n\nconst DEFAULT_COMPONENT_REGISTRATIONS = {\n container: {\n component: Components.ContentfulContainer,\n definition: containerDefinition,\n },\n section: {\n component: Components.ContentfulContainer,\n definition: sectionDefinition,\n },\n columns: {\n component: Components.Columns,\n definition: columnsDefinition,\n },\n singleColumn: {\n component: Components.SingleColumn,\n definition: singleColumnDefinition,\n },\n button: enrichComponentDefinition({\n component: Components.Button,\n definition: Components.ButtonComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n heading: enrichComponentDefinition({\n component: Components.Heading,\n definition: Components.HeadingComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n image: enrichComponentDefinition({\n component: Components.Image,\n definition: Components.ImageComponentDefinition,\n options: { wrapComponent: false },\n }),\n richText: enrichComponentDefinition({\n component: Components.RichText,\n definition: Components.RichTextComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n text: enrichComponentDefinition({\n component: Components.Text,\n definition: Components.TextComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n divider: {\n // Don't wrap this component `withComponentWrapper`. Need to explicitly ignore dragProps\n component: Components.ContentfulDivider,\n definition: dividerDefinition,\n options: {\n wrapComponent: false,\n },\n },\n carousel: enrichComponentDefinition({\n component: Components.Carousel,\n definition: Components.carouselDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n} satisfies Record<string, ComponentRegistration>;\n\n// pre-filling with the default component registrations\nexport const componentRegistry = new Map<string, ComponentRegistration>([\n [DEFAULT_COMPONENT_REGISTRATIONS.section.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.section],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.container.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.container,\n ],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.singleColumn.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.singleColumn,\n ],\n [DEFAULT_COMPONENT_REGISTRATIONS.columns.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.columns],\n [DEFAULT_COMPONENT_REGISTRATIONS.button.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.button],\n [DEFAULT_COMPONENT_REGISTRATIONS.heading.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.heading],\n [DEFAULT_COMPONENT_REGISTRATIONS.image.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.image],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.richText.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.richText,\n ],\n [DEFAULT_COMPONENT_REGISTRATIONS.text.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.text],\n [DEFAULT_COMPONENT_REGISTRATIONS.divider.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.divider],\n]);\n\nexport const optionalBuiltInComponents = [\n DEFAULT_COMPONENT_REGISTRATIONS.button.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.heading.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.image.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.richText.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.text.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.divider.definition.id,\n];\n\nexport const sendRegisteredComponentsMessage = () => {\n // Send the definitions (without components) via the connection message to the experience builder\n const registeredDefinitions = Array.from(componentRegistry.values())\n .map(({ definition }) => definition)\n // Pattern definitions are empty placeholder within the SDK without variables\n // We don't send those to the editor as they would overwrite the actual correct definitions.\n .filter((definition) => definition.category !== ASSEMBLY_DEFAULT_CATEGORY);\n\n sendMessage(OUTGOING_EVENTS.RegisteredComponents, {\n definitions: registeredDefinitions,\n });\n};\n\nexport const runRegisteredComponentValidations = () => {\n Array.from(componentRegistry.values()).map(({ definition }) => {\n const validation = validateComponentDefinition(definition);\n if (!validation.success) {\n throw new Error(\n `Invalid component definition for component '${definition.name}'. Failed with errors: \\n${JSON.stringify(validation.errors, null, 2)}`,\n );\n }\n });\n};\n\nconst getSingleCssVariableValue = (\n element: HTMLDivElement,\n cssVariableValue: string,\n cssAttribute: any,\n) => {\n element.style[cssAttribute] = cssVariableValue;\n const styles = getComputedStyle(element);\n const resolvedValue = styles.getPropertyValue(cssAttribute);\n return resolvedValue;\n};\n\nconst getAllCssVariableValues = (\n element: HTMLDivElement,\n cssVariable: Record<string, string>,\n cssAttribute: any,\n) => {\n const resolvedCssVariables = {} as Record<string, string>;\n\n Object.keys(cssVariable).forEach((key) => {\n const cssVariableValue = cssVariable[key];\n if (CssVarRegex.test(cssVariableValue)) {\n const resolvedValue = getSingleCssVariableValue(element, cssVariableValue, cssAttribute);\n resolvedCssVariables[cssVariableValue] = resolvedValue;\n }\n });\n return resolvedCssVariables;\n};\n\ntype CssMapType = {\n variable?: Record<string, string>;\n property: string;\n};\n\nconst resolveCssVariables = (designTokensDefinition: DesignTokensDefinition) => {\n const {\n spacing,\n sizing,\n color,\n borderRadius,\n fontSize,\n lineHeight,\n letterSpacing,\n textColor,\n border,\n } = designTokensDefinition;\n const resolvedCssVariables = {} as Record<string, string>;\n\n // Create an element\n const element = document.createElement('div');\n document.body.appendChild(element);\n\n const cssProperties: CssMapType[] = [\n { variable: spacing, property: 'margin' },\n { variable: sizing, property: 'width' },\n { variable: color, property: 'background-color' },\n { variable: borderRadius, property: 'border-radius' },\n { variable: fontSize, property: 'font-size' },\n { variable: lineHeight, property: 'line-height' },\n { variable: letterSpacing, property: 'letter-spacing' },\n { variable: textColor, property: 'color' },\n ];\n\n cssProperties.forEach(({ variable, property }) => {\n if (variable) {\n const rawResolvedValues = getAllCssVariableValues(element, variable, property);\n Object.assign(resolvedCssVariables, rawResolvedValues);\n }\n });\n\n if (border) {\n const tempResolvedValue = {} as Record<string, string>;\n Object.keys(border).forEach((borderKey) => {\n const { width, style, color } = border[borderKey];\n\n if (width && CssVarRegex.test(width)) {\n const resolvedValue = getSingleCssVariableValue(element, width, 'border-width');\n tempResolvedValue[width] = resolvedValue;\n }\n if (style && CssVarRegex.test(style)) {\n const resolvedValue = getSingleCssVariableValue(element, style, 'border-style');\n tempResolvedValue[style] = resolvedValue;\n }\n if (color && CssVarRegex.test(color)) {\n const resolvedValue = getSingleCssVariableValue(element, color, 'border-color');\n tempResolvedValue[color] = resolvedValue;\n }\n Object.assign(resolvedCssVariables, tempResolvedValue);\n });\n }\n\n document.body.removeChild(element);\n return resolvedCssVariables;\n};\n\nexport const sendConnectedEventWithRegisteredComponents = () => {\n // Send the definitions (without components) via the connection message to the experience builder\n const registeredDefinitions = Array.from(componentRegistry.values()).map(\n ({ definition }) => definition,\n );\n\n sendMessage(OUTGOING_EVENTS.Connected, {\n sdkVersion: SDK_VERSION,\n definitions: registeredDefinitions,\n });\n\n sendMessage(OUTGOING_EVENTS.RegisteredBreakpoints, {\n breakpoints: breakpointsRegistry,\n });\n\n sendMessage(OUTGOING_EVENTS.DesignTokens, {\n designTokens: designTokensRegistry,\n resolvedCssVariables: resolveCssVariables(designTokensRegistry),\n });\n};\n\n/**\n * Registers multiple components and their component definitions at once\n * @param componentRegistrations - ComponentRegistration[]\n * @returns void\n */\nexport const defineComponents = (\n componentRegistrations: ComponentRegistration[],\n options?: ComponentRegistrationOptions,\n) => {\n if (options?.experimentalComponents?.carousel) {\n componentRegistry.set(\n CONTENTFUL_COMPONENTS.carousel.id,\n DEFAULT_COMPONENT_REGISTRATIONS.carousel,\n );\n }\n\n if (options?.enabledBuiltInComponents) {\n for (const id of optionalBuiltInComponents) {\n if (!options.enabledBuiltInComponents.includes(id)) {\n componentRegistry.delete(id);\n }\n }\n }\n\n for (const registration of componentRegistrations) {\n // Fill definitions with fallbacks values\n const enrichedComponentRegistration = enrichComponentDefinition(registration);\n\n componentRegistry.set(\n enrichedComponentRegistration.definition.id,\n enrichedComponentRegistration,\n );\n }\n\n if (typeof window !== 'undefined') {\n window.dispatchEvent(new CustomEvent(INTERNAL_EVENTS.ComponentsRegistered));\n }\n};\n\n/**\n * use this function only in tests\n */\nexport const resetComponentRegistry = () => {\n componentRegistry.clear();\n for (const registration of Object.values(DEFAULT_COMPONENT_REGISTRATIONS)) {\n componentRegistry.set(registration.definition.id, registration);\n }\n};\n\nexport const getComponentRegistration = (id: string) => componentRegistry.get(id);\n\nexport const addComponentRegistration = (componentRegistration: ComponentRegistration) => {\n componentRegistry.set(componentRegistration.definition.id, componentRegistration);\n};\n\nexport const createAssemblyRegistration = ({\n definitionId,\n definitionName,\n component,\n}: {\n definitionId: string;\n definitionName?: string;\n component: ComponentRegistration['component'];\n}) => {\n const componentRegistration = componentRegistry.get(definitionId);\n\n if (componentRegistration) {\n return componentRegistration;\n }\n\n const definition = {\n id: definitionId,\n name: definitionName || 'Component',\n variables: {},\n children: true,\n category: ASSEMBLY_DEFAULT_CATEGORY,\n };\n\n addComponentRegistration({ component, definition });\n\n return componentRegistry.get(definitionId);\n};\n\n/**\n * @deprecated This method is used to maintain the basic component ids (without the prefix 'contentful-') in order to be compatible\n * with experiences created with an older alpha version of the SDK. Components in these experiences should be migrated to use\n * the components with the 'contentful-' prefix. To do so, load the experience in the editor, and replace any older basic components\n * (marked with [OLD] in the UI) with the new components (without the [OLD]). This method (and functionality for the older components)\n * will be removed in the next major release.\n */\nexport const maintainBasicComponentIdsWithoutPrefix = () => {\n optionalBuiltInComponents.forEach((id) => {\n if (componentRegistry.has(id) && id.startsWith('contentful-')) {\n const registeredComponent = componentRegistry.get(id)!;\n const definition = registeredComponent.definition;\n const newDefinition = cloneObject(definition);\n newDefinition.name = newDefinition.name + '[OLD]';\n const newId = id.replace('contentful-', '');\n newDefinition.id = newId;\n const newRegisteredComponent = { ...registeredComponent, definition: newDefinition };\n componentRegistry.set(newId, newRegisteredComponent);\n }\n });\n};\n"],"names":["builtInStyleDefinitions"],"mappings":";;;;;;;;AA+BA,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC,MAAM,WAAW,GAAG,CAAI,YAAe,KAAO;AAC5C,IAAA,IAAI,OAAO,eAAe,KAAK,WAAW,EAAE;AAC1C,QAAA,OAAO,eAAe,CAAC,YAAY,CAAC,CAAC;KACtC;IAED,OAAO,IAAI,CAAC,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,UAAU,EAAE,CAAC,CAAC;AAEpD,IAAA,OAAO,iBAAiB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAC7C,EAAE;AAEF;;;;;;AAMG;AACI,MAAM,sCAAsC,GAAG,MAAK;AACzD,IAAA,yBAAyB,CAAC,OAAO,CAAC,CAAC,EAAE,KAAI;AACvC,QAAA,IAAI,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE;YAC7D,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC;AACvD,YAAA,MAAM,UAAU,GAAG,mBAAmB,CAAC,UAAU,CAAC;AAClD,YAAA,MAAM,aAAa,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;YAC9C,aAAa,CAAC,IAAI,GAAG,aAAa,CAAC,IAAI,GAAG,OAAO,CAAC;YAClD,MAAM,KAAK,GAAG,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;AAC5C,YAAA,aAAa,CAAC,EAAE,GAAG,KAAK,CAAC;YACzB,MAAM,sBAAsB,GAAG,EAAE,GAAG,mBAAmB,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;AACrF,YAAA,iBAAiB,CAAC,GAAG,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAC;SACtD;AACH,KAAC,CAAC,CAAC;AACL;;;;"}
@@ -1,42 +1,24 @@
1
- import { useState, useLayoutEffect } from 'react';
2
- import { buildCfStyles, isStructureWithRelativeHeight, buildStyleTag } from '@contentful/experiences-core';
3
- import { EMPTY_CONTAINER_HEIGHT } from '@contentful/experiences-core/constants';
1
+ import { useInsertionEffect } from 'react';
2
+ import '@contentful/experiences-core';
3
+ import '@contentful/experiences-core/constants';
4
4
 
5
- /**
6
- * This hook can generate className and inject styles on a client side as a <style> tag
7
- * or it derives the className set on the server side
8
- *
9
- * @param node: the componenet node for which the styles will be injected
10
- * @param props: the props of the component, represented by the node
11
- * @returns the className that was eitner generated on the client side or derived from the value, set on server side
12
- */
13
- const useClassName = ({ node, props, }) => {
14
- const [className, setClassName] = useState(props.cfSsrClassName ?? '');
15
- // Once our React support allows it (>=18), this should be implemented with useInsertionEffect.
16
- useLayoutEffect(() => {
17
- if (props.cfSsrClassName) {
18
- // class name has been already set on the server side. No need to calculate it on client side anymore
5
+ const injectedStyles = [];
6
+ const useInjectStylesheet = (stylesheet) => {
7
+ useInsertionEffect(() => {
8
+ if (!stylesheet) {
19
9
  return;
20
10
  }
21
- const cfStyles = buildCfStyles(props);
22
- if (Object.keys(cfStyles).length === 0) {
23
- return;
24
- }
25
- if (!node.children.length &&
26
- isStructureWithRelativeHeight(node.definitionId, cfStyles.height)) {
27
- cfStyles.minHeight = EMPTY_CONTAINER_HEIGHT;
28
- }
29
- const [className, styleRule] = buildStyleTag({ styles: cfStyles });
30
- if (!className || !styleRule) {
11
+ if (injectedStyles.includes(stylesheet.hash)) {
31
12
  return;
32
13
  }
33
14
  const styleTag = document.createElement('style');
34
- styleTag.dataset['cfStyles'] = className;
35
- setClassName(className);
36
- document.head.appendChild(styleTag).innerHTML = styleRule;
37
- }, [props, node]);
38
- return className;
15
+ styleTag.setAttribute('type', 'text/css');
16
+ styleTag.id = stylesheet.hash;
17
+ styleTag.innerHTML = stylesheet.css;
18
+ document.head.appendChild(styleTag);
19
+ injectedStyles.push(stylesheet.hash);
20
+ }, [stylesheet]);
39
21
  };
40
22
 
41
- export { useClassName };
23
+ export { useInjectStylesheet };
42
24
  //# sourceMappingURL=useClassName.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useClassName.js","sources":["../../../src/hooks/useClassName.ts"],"sourcesContent":["import { useLayoutEffect, useState } from 'react';\n\nimport {\n buildCfStyles,\n buildStyleTag,\n isStructureWithRelativeHeight,\n} from '@contentful/experiences-core';\nimport { ComponentTreeNode } from '@contentful/experiences-core/types';\nimport { EMPTY_CONTAINER_HEIGHT } from '@contentful/experiences-core/constants';\n\n/**\n * This hook can generate className and inject styles on a client side as a <style> tag\n * or it derives the className set on the server side\n *\n * @param node: the componenet node for which the styles will be injected\n * @param props: the props of the component, represented by the node\n * @returns the className that was eitner generated on the client side or derived from the value, set on server side\n */\nexport const useClassName = ({\n node,\n props,\n}: {\n node: ComponentTreeNode;\n props: Record<string, any>;\n}) => {\n const [className, setClassName] = useState<string>(props.cfSsrClassName ?? '');\n // Once our React support allows it (>=18), this should be implemented with useInsertionEffect.\n useLayoutEffect(() => {\n if (props.cfSsrClassName) {\n // class name has been already set on the server side. No need to calculate it on client side anymore\n return;\n }\n\n const cfStyles = buildCfStyles(props);\n\n if (Object.keys(cfStyles).length === 0) {\n return;\n }\n\n if (\n !node.children.length &&\n isStructureWithRelativeHeight(node.definitionId, cfStyles.height)\n ) {\n cfStyles.minHeight = EMPTY_CONTAINER_HEIGHT;\n }\n\n const [className, styleRule] = buildStyleTag({ styles: cfStyles });\n\n if (!className || !styleRule) {\n return;\n }\n\n const styleTag = document.createElement('style');\n styleTag.dataset['cfStyles'] = className;\n\n setClassName(className);\n\n document.head.appendChild(styleTag).innerHTML = styleRule;\n }, [props, node]);\n\n return className;\n};\n"],"names":[],"mappings":";;;;AAUA;;;;;;;AAOG;AACU,MAAA,YAAY,GAAG,CAAC,EAC3B,IAAI,EACJ,KAAK,GAIN,KAAI;AACH,IAAA,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAS,KAAK,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC;;IAE/E,eAAe,CAAC,MAAK;AACnB,QAAA,IAAI,KAAK,CAAC,cAAc,EAAE;;YAExB,OAAO;SACR;AAED,QAAA,MAAM,QAAQ,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;QAEtC,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;YACtC,OAAO;SACR;AAED,QAAA,IACE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM;YACrB,6BAA6B,CAAC,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,EACjE;AACA,YAAA,QAAQ,CAAC,SAAS,GAAG,sBAAsB,CAAC;SAC7C;AAED,QAAA,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,aAAa,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;AAEnE,QAAA,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,EAAE;YAC5B,OAAO;SACR;QAED,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AACjD,QAAA,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC;QAEzC,YAAY,CAAC,SAAS,CAAC,CAAC;QAExB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC;AAC5D,KAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;AAElB,IAAA,OAAO,SAAS,CAAC;AACnB;;;;"}
1
+ {"version":3,"file":"useClassName.js","sources":["../../../src/hooks/useClassName.ts"],"sourcesContent":["import { useLayoutEffect, useState, useInsertionEffect } from 'react';\n\nimport {\n buildCfStyles,\n buildStyleTag,\n isStructureWithRelativeHeight,\n} from '@contentful/experiences-core';\nimport { ComponentTreeNode } from '@contentful/experiences-core/types';\nimport { EMPTY_CONTAINER_HEIGHT } from '@contentful/experiences-core/constants';\n\nconst injectedStyles: Array<string> = [];\n\n/**\n * This hook can generate className and inject styles on a client side as a <style> tag\n * or it derives the className set on the server side\n *\n * @param node: the componenet node for which the styles will be injected\n * @param props: the props of the component, represented by the node\n * @returns the className that was eitner generated on the client side or derived from the value, set on server side\n */\nexport const useClassName = ({\n node,\n props,\n}: {\n node: ComponentTreeNode;\n props: Record<string, any>;\n}) => {\n const [className, setClassName] = useState<string>(props.cfSsrClassName ?? '');\n // Once our React support allows it (>=18), this should be implemented with useInsertionEffect.\n useLayoutEffect(() => {\n if (props.cfSsrClassName) {\n // class name has been already set on the server side. No need to calculate it on client side anymore\n return;\n }\n\n const cfStyles = buildCfStyles(props);\n\n if (Object.keys(cfStyles).length === 0) {\n return;\n }\n\n if (\n !node.children.length &&\n isStructureWithRelativeHeight(node.definitionId, cfStyles.height)\n ) {\n cfStyles.minHeight = EMPTY_CONTAINER_HEIGHT;\n }\n\n const [className, styleRule] = buildStyleTag({ styles: cfStyles });\n\n if (!className || !styleRule) {\n return;\n }\n\n const styleTag = document.createElement('style');\n styleTag.dataset['cfStyles'] = className;\n\n setClassName(className);\n\n document.head.appendChild(styleTag).innerHTML = styleRule;\n }, [props, node]);\n\n return className;\n};\n\nexport const useInjectStylesheet = (stylesheet?: {\n css: string;\n hash: string;\n className: string;\n}) => {\n useInsertionEffect(() => {\n if (!stylesheet) {\n return;\n }\n\n if (injectedStyles.includes(stylesheet.hash)) {\n return;\n }\n\n const styleTag = document.createElement('style');\n styleTag.setAttribute('type', 'text/css');\n styleTag.id = stylesheet.hash;\n styleTag.innerHTML = stylesheet.css;\n\n document.head.appendChild(styleTag);\n injectedStyles.push(stylesheet.hash);\n }, [stylesheet]);\n};\n"],"names":[],"mappings":";;;;AAUA,MAAM,cAAc,GAAkB,EAAE,CAAC;AAuD5B,MAAA,mBAAmB,GAAG,CAAC,UAInC,KAAI;IACH,kBAAkB,CAAC,MAAK;QACtB,IAAI,CAAC,UAAU,EAAE;YACf,OAAO;SACR;QAED,IAAI,cAAc,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;YAC5C,OAAO;SACR;QAED,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AACjD,QAAA,QAAQ,CAAC,YAAY,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAC1C,QAAA,QAAQ,CAAC,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC;AAC9B,QAAA,QAAQ,CAAC,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC;AAEpC,QAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AACpC,QAAA,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AACvC,KAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;AACnB;;;;"}
@@ -0,0 +1,115 @@
1
+ import { flattenDesignTokenRegistry, designTokensRegistry, maybePopulateDesignTokenValue, buildCfStyles, isStructureWithRelativeHeight, toCSSAttribute, toCSSString, toMediaQuery } from '@contentful/experiences-core';
2
+ import { EMPTY_CONTAINER_HEIGHT } from '@contentful/experiences-core/constants';
3
+ import md5 from 'md5';
4
+ import { useMemo } from 'react';
5
+
6
+ // TODO: move to ssrStyles.ts file and reuse it there
7
+ const resolveClassNamesFromBuiltInStyles = ({ designPropsByBreakpointId, breakpoints, node, }) => {
8
+ const mapOfDesignVariableKeys = flattenDesignTokenRegistry(designTokensRegistry);
9
+ const result = [];
10
+ // then for each breakpoint
11
+ for (const breakpoint of breakpoints) {
12
+ const designProps = designPropsByBreakpointId[breakpoint.id];
13
+ if (!designProps) {
14
+ continue;
15
+ }
16
+ const propsByBreakpointWithResolvedDesignTokens = Object.entries(designProps).reduce((acc, [propName, propValue]) => {
17
+ return {
18
+ ...acc,
19
+ [propName]: maybePopulateDesignTokenValue(propName, propValue, mapOfDesignVariableKeys),
20
+ };
21
+ }, {});
22
+ // We convert cryptic prop keys to css variables
23
+ // Eg: cfMargin to margin
24
+ const stylesForBreakpoint = buildCfStyles(propsByBreakpointWithResolvedDesignTokens);
25
+ if (!node.children.length &&
26
+ isStructureWithRelativeHeight(node.definitionId, stylesForBreakpoint.height)) {
27
+ stylesForBreakpoint.minHeight = EMPTY_CONTAINER_HEIGHT;
28
+ }
29
+ const stylesForBreakpointWithoutUndefined = Object.fromEntries(Object.entries(stylesForBreakpoint)
30
+ .filter(([, value]) => value !== undefined)
31
+ .map(([key, value]) => [toCSSAttribute(key), value]));
32
+ /**
33
+ * stylesForBreakpoint {
34
+ margin: '0 0 0 0',
35
+ padding: '0 0 0 0',
36
+ 'background-color': 'rgba(246, 246, 246, 1)',
37
+ width: '100%',
38
+ height: 'fit-content',
39
+ 'max-width': 'none',
40
+ border: '0px solid rgba(0, 0, 0, 0)',
41
+ 'border-radius': '0px',
42
+ gap: '0px 0px',
43
+ 'align-items': 'center',
44
+ 'justify-content': 'safe center',
45
+ 'flex-direction': 'column',
46
+ 'flex-wrap': 'nowrap',
47
+ 'font-style': 'normal',
48
+ 'text-decoration': 'none',
49
+ 'box-sizing': 'border-box'
50
+ }
51
+ */
52
+ // I create a hash of the object above because that would ensure hash stability
53
+ const styleHash = md5(JSON.stringify(stylesForBreakpointWithoutUndefined));
54
+ // and prefix the className to make sure the value can be processed
55
+ const className = `cfstyles-${styleHash}`;
56
+ // otherwise, save it to the stylesheet
57
+ result.push({
58
+ className,
59
+ breakpointCondition: breakpoint.query,
60
+ css: toCSSString(stylesForBreakpointWithoutUndefined),
61
+ });
62
+ }
63
+ return result;
64
+ };
65
+ // TODO: move to ssrStyles.ts file and reuse it there
66
+ const convertResolvedDesignValuesToMediaQuery = (styleSheetData) => {
67
+ /**
68
+ * {
69
+ * className: ['cfstyles-123', 'cfstyles-456'],
70
+ * styleSheet: `
71
+ * @media (max-width: 1024px) {
72
+ * .cfstyles-123 { color: red; }
73
+ * }
74
+ * @media (max-width: 768px) {
75
+ * .cfstyles-456 { color: blue; }
76
+ * }
77
+ * `
78
+ * }
79
+ */
80
+ const styleSheet = styleSheetData.reduce((acc, { breakpointCondition, className, css }) => {
81
+ if (acc.className.includes(className)) {
82
+ return acc;
83
+ }
84
+ const mediaQuery = toMediaQuery({
85
+ condition: breakpointCondition,
86
+ cssByClassName: { [className]: css },
87
+ });
88
+ return {
89
+ className: [...acc.className, className],
90
+ css: `${acc.css}${mediaQuery}`,
91
+ };
92
+ }, {
93
+ className: [],
94
+ css: '',
95
+ });
96
+ const className = styleSheet.className.join(' ');
97
+ return {
98
+ css: styleSheet.css,
99
+ hash: `cf-${md5(className)}`,
100
+ className,
101
+ };
102
+ };
103
+ const useMediaQuery = ({ designPropsByBreakpointId, breakpoints, node, }) => {
104
+ return useMemo(() => {
105
+ const styleSheetData = resolveClassNamesFromBuiltInStyles({
106
+ designPropsByBreakpointId,
107
+ breakpoints,
108
+ node,
109
+ });
110
+ return convertResolvedDesignValuesToMediaQuery(styleSheetData);
111
+ }, [designPropsByBreakpointId, breakpoints, node]);
112
+ };
113
+
114
+ export { convertResolvedDesignValuesToMediaQuery, resolveClassNamesFromBuiltInStyles, useMediaQuery };
115
+ //# sourceMappingURL=useMediaQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMediaQuery.js","sources":["../../../src/hooks/useMediaQuery.ts"],"sourcesContent":["import {\n buildCfStyles,\n designTokensRegistry,\n flattenDesignTokenRegistry,\n isStructureWithRelativeHeight,\n maybePopulateDesignTokenValue,\n toCSSAttribute,\n toCSSString,\n toMediaQuery,\n} from '@contentful/experiences-core';\nimport { EMPTY_CONTAINER_HEIGHT } from '@contentful/experiences-core/constants';\nimport { Breakpoint, ComponentTreeNode } from '@contentful/experiences-core/types';\nimport md5 from 'md5';\nimport { useMemo } from 'react';\n\ntype ResolvedStylesheetData = Array<{\n className: string;\n breakpointCondition: string;\n css: string;\n}>;\n\n// TODO: move to ssrStyles.ts file and reuse it there\nexport const resolveClassNamesFromBuiltInStyles = ({\n designPropsByBreakpointId,\n breakpoints,\n node,\n}: {\n designPropsByBreakpointId: Record<string, Record<string, any>>;\n breakpoints: Breakpoint[];\n node: ComponentTreeNode;\n}): ResolvedStylesheetData => {\n const mapOfDesignVariableKeys = flattenDesignTokenRegistry(designTokensRegistry);\n const currentNodeClassNames: string[] = [];\n\n const result: Array<{\n className: string;\n breakpointCondition: string;\n css: string;\n }> = [];\n\n // then for each breakpoint\n for (const breakpoint of breakpoints) {\n const designProps = designPropsByBreakpointId[breakpoint.id];\n if (!designProps) {\n continue;\n }\n\n const propsByBreakpointWithResolvedDesignTokens = Object.entries(designProps).reduce(\n (acc, [propName, propValue]) => {\n return {\n ...acc,\n [propName]: maybePopulateDesignTokenValue(propName, propValue, mapOfDesignVariableKeys),\n };\n },\n {},\n );\n\n // We convert cryptic prop keys to css variables\n // Eg: cfMargin to margin\n const stylesForBreakpoint = buildCfStyles(propsByBreakpointWithResolvedDesignTokens);\n\n if (\n !node.children.length &&\n isStructureWithRelativeHeight(node.definitionId, stylesForBreakpoint.height)\n ) {\n stylesForBreakpoint.minHeight = EMPTY_CONTAINER_HEIGHT;\n }\n\n const stylesForBreakpointWithoutUndefined: Record<string, string> = Object.fromEntries(\n Object.entries(stylesForBreakpoint)\n .filter(([, value]) => value !== undefined)\n .map(([key, value]) => [toCSSAttribute(key), value]),\n );\n\n /**\n * stylesForBreakpoint {\n margin: '0 0 0 0',\n padding: '0 0 0 0',\n 'background-color': 'rgba(246, 246, 246, 1)',\n width: '100%',\n height: 'fit-content',\n 'max-width': 'none',\n border: '0px solid rgba(0, 0, 0, 0)',\n 'border-radius': '0px',\n gap: '0px 0px',\n 'align-items': 'center',\n 'justify-content': 'safe center',\n 'flex-direction': 'column',\n 'flex-wrap': 'nowrap',\n 'font-style': 'normal',\n 'text-decoration': 'none',\n 'box-sizing': 'border-box'\n }\n */\n // I create a hash of the object above because that would ensure hash stability\n const styleHash = md5(JSON.stringify(stylesForBreakpointWithoutUndefined));\n\n // and prefix the className to make sure the value can be processed\n const className = `cfstyles-${styleHash}`;\n\n // I save the generated hashes into an array to later save it in the tree node\n // as cfSsrClassName prop\n // making sure to avoid the duplicates in case styles for > 1 breakpoints are the same\n if (!currentNodeClassNames.includes(className)) {\n currentNodeClassNames.push(className);\n }\n\n // otherwise, save it to the stylesheet\n result.push({\n className,\n breakpointCondition: breakpoint.query,\n css: toCSSString(stylesForBreakpointWithoutUndefined),\n });\n }\n\n return result;\n};\n\n// TODO: move to ssrStyles.ts file and reuse it there\nexport const convertResolvedDesignValuesToMediaQuery = (styleSheetData: ResolvedStylesheetData) => {\n /**\n * {\n * className: ['cfstyles-123', 'cfstyles-456'],\n * styleSheet: `\n * @media (max-width: 1024px) {\n * .cfstyles-123 { color: red; }\n * }\n * @media (max-width: 768px) {\n * .cfstyles-456 { color: blue; }\n * }\n * `\n * }\n */\n const styleSheet = styleSheetData.reduce<{ className: Array<string>; css: string }>(\n (acc, { breakpointCondition, className, css }) => {\n if (acc.className.includes(className)) {\n return acc;\n }\n\n const mediaQuery = toMediaQuery({\n condition: breakpointCondition,\n cssByClassName: { [className]: css },\n });\n return {\n className: [...acc.className, className],\n css: `${acc.css}${mediaQuery}`,\n };\n },\n {\n className: [],\n css: '',\n },\n );\n\n const className = styleSheet.className.join(' ');\n\n return {\n css: styleSheet.css,\n hash: `cf-${md5(className)}`,\n className,\n };\n};\n\nexport const useMediaQuery = ({\n designPropsByBreakpointId,\n breakpoints,\n node,\n}: {\n designPropsByBreakpointId: Record<string, Record<string, any>>;\n breakpoints: Breakpoint[];\n node: ComponentTreeNode;\n}) => {\n return useMemo(() => {\n const styleSheetData = resolveClassNamesFromBuiltInStyles({\n designPropsByBreakpointId,\n breakpoints,\n node,\n });\n\n return convertResolvedDesignValuesToMediaQuery(styleSheetData);\n }, [designPropsByBreakpointId, breakpoints, node]);\n};\n"],"names":[],"mappings":";;;;;AAqBA;AACO,MAAM,kCAAkC,GAAG,CAAC,EACjD,yBAAyB,EACzB,WAAW,EACX,IAAI,GAKL,KAA4B;AAC3B,IAAA,MAAM,uBAAuB,GAAG,0BAA0B,CAAC,oBAAoB,CAAC,CAAC;IAGjF,MAAM,MAAM,GAIP,EAAE,CAAC;;AAGR,IAAA,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;QACpC,MAAM,WAAW,GAAG,yBAAyB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QAC7D,IAAI,CAAC,WAAW,EAAE;YAChB,SAAS;SACV;QAED,MAAM,yCAAyC,GAAG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AAE,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;AACrD;;;;"}
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ import * as _contentful_experiences_core_constants from '@contentful/experiences
8
8
  export { CF_STYLE_ATTRIBUTES, CONTENTFUL_COMPONENTS, LATEST_SCHEMA_VERSION } from '@contentful/experiences-core/constants';
9
9
  import { ContentfulClientApi } from 'contentful';
10
10
 
11
- declare const SDK_VERSION = "1.30.5-dev-20250206T1804-ed40499.0";
11
+ declare const SDK_VERSION = "1.30.5-prerelease-20250207T1349-200d927.0";
12
12
 
13
13
  type ExperienceRootProps = {
14
14
  experience?: Experience<EntityStore> | string | null;
@@ -1,4 +1,4 @@
1
- const SDK_VERSION = '1.30.5-dev-20250206T1804-ed40499.0';
1
+ const SDK_VERSION = '1.30.5-prerelease-20250207T1349-200d927.0';
2
2
 
3
3
  export { SDK_VERSION };
4
4
  //# sourceMappingURL=sdkVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sdkVersion.js","sources":["../../src/sdkVersion.ts"],"sourcesContent":["export const SDK_VERSION = '1.30.5-dev-20250206T1804-ed40499.0';\n"],"names":[],"mappings":"AAAO,MAAM,WAAW,GAAG;;;;"}
1
+ {"version":3,"file":"sdkVersion.js","sources":["../../src/sdkVersion.ts"],"sourcesContent":["export const SDK_VERSION = '1.30.5-prerelease-20250207T1349-200d927.0';\n"],"names":[],"mappings":"AAAO,MAAM,WAAW,GAAG;;;;"}
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
- import type { ComponentTreeNode, PrimitiveValue } from '@contentful/experiences-core/types';
2
+ import type { Breakpoint, ComponentTreeNode, PrimitiveValue } from '@contentful/experiences-core/types';
3
3
  interface PreviewUnboundImageProps {
4
+ breakpoints: Breakpoint[];
4
5
  node: ComponentTreeNode;
5
6
  nodeProps: Record<PropertyKey, PrimitiveValue>;
6
7
  component: React.ElementType;
@@ -11,3 +11,8 @@ export declare const useClassName: ({ node, props, }: {
11
11
  node: ComponentTreeNode;
12
12
  props: Record<string, any>;
13
13
  }) => string;
14
+ export declare const useInjectStylesheet: (stylesheet?: {
15
+ css: string;
16
+ hash: string;
17
+ className: string;
18
+ }) => void;
@@ -0,0 +1,26 @@
1
+ import { Breakpoint, ComponentTreeNode } from '@contentful/experiences-core/types';
2
+ type ResolvedStylesheetData = Array<{
3
+ className: string;
4
+ breakpointCondition: string;
5
+ css: string;
6
+ }>;
7
+ export declare const resolveClassNamesFromBuiltInStyles: ({ designPropsByBreakpointId, breakpoints, node, }: {
8
+ designPropsByBreakpointId: Record<string, Record<string, any>>;
9
+ breakpoints: Breakpoint[];
10
+ node: ComponentTreeNode;
11
+ }) => ResolvedStylesheetData;
12
+ export declare const convertResolvedDesignValuesToMediaQuery: (styleSheetData: ResolvedStylesheetData) => {
13
+ css: string;
14
+ hash: string;
15
+ className: string;
16
+ };
17
+ export declare const useMediaQuery: ({ designPropsByBreakpointId, breakpoints, node, }: {
18
+ designPropsByBreakpointId: Record<string, Record<string, any>>;
19
+ breakpoints: Breakpoint[];
20
+ node: ComponentTreeNode;
21
+ }) => {
22
+ css: string;
23
+ hash: string;
24
+ className: string;
25
+ };
26
+ export {};
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.30.5-dev-20250206T1804-ed40499.0";
1
+ export declare const SDK_VERSION = "1.30.5-prerelease-20250207T1349-200d927.0";
@@ -0,0 +1,46 @@
1
+ import { BoundComponentPropertyTypes, BoundValue, ComponentDefinition, ComponentDefinitionVariable, ComponentDefinitionVariableType, ComponentTreeNode, PrimitiveValue } from '@contentful/experiences-core/types';
2
+ /**
3
+ * The previous logic of prop mapping was too complex and mixed different ues cases together.
4
+ * In this function, I aim to simplify the logic by focusing on the following specific cases FOR PREVIEW/DELIVERY MODES
5
+ * 1) Any non `DesignValue` props should be resolved and returned as is
6
+ * 2) Some exceptions like `cfImageAsset` and `cfBackgroundImageUrl` (BoundValue) should be handled separately
7
+ * and be resolved for the default breakpoint only (cause we don't allow binding per breakpoint anyway)
8
+ * 3) Those DesignValue props which can be converted to CSS should be grouped and resolved into a CSS media query
9
+ * for each breakpoint
10
+ * 4) Those DesignValue props which can NOT be converted to CSS (custom design props) should be resolved dynamically
11
+ * for each breakpoint
12
+ */
13
+ export declare const parseComponentProps: ({ componentDefinition, node, resolveClassNamesFromBuiltInStyles, resolveCustomDesignValue, resolveBoundValue, resolveHyperlinkValue, resolveUnboundValue, }: {
14
+ node: ComponentTreeNode;
15
+ componentDefinition: ComponentDefinition;
16
+ resolveClassNamesFromBuiltInStyles: (propsByBreakpointId: Record<string, Record<string, PrimitiveValue>>) => Array<{
17
+ className: string;
18
+ breakpointCondition: string;
19
+ css: string;
20
+ }>;
21
+ resolveCustomDesignValue: (data: {
22
+ propertyName: string;
23
+ valuesByBreakpoint: Record<string, any>;
24
+ }) => PrimitiveValue;
25
+ resolveBoundValue: (data: {
26
+ propertyName: string;
27
+ dataType: ComponentDefinitionVariableType;
28
+ binding: BoundValue;
29
+ }) => BoundComponentPropertyTypes;
30
+ resolveHyperlinkValue: (data: {
31
+ linkTargetKey: string;
32
+ }) => string | null;
33
+ resolveUnboundValue: (data: {
34
+ mappingKey: string;
35
+ defaultValue: ComponentDefinitionVariable["defaultValue"];
36
+ }) => any;
37
+ }) => {
38
+ styleProps: Record<string, Record<string, string | number | boolean | Record<any, any> | undefined>>;
39
+ mediaQuery: {
40
+ css: string;
41
+ hash: string;
42
+ className: string;
43
+ };
44
+ customDesignProps: Record<string, string | number | boolean | Record<any, any> | undefined>;
45
+ contentProps: Record<string, any>;
46
+ };
@@ -1,12 +1,16 @@
1
- import type { ExperienceEntry, ExperienceTreeNode, SchemaVersions } from '@contentful/experiences-core/types';
1
+ import type { ComponentTreeNode, ExperienceEntry, ExperienceTreeNode, SchemaVersions } from '@contentful/experiences-core/types';
2
2
  type createAssemblyEntryArgs = {
3
3
  schemaVersion?: SchemaVersions;
4
4
  id?: string;
5
+ nestedPatterns?: Array<{
6
+ entry: ExperienceEntry;
7
+ node: ComponentTreeNode;
8
+ }>;
5
9
  };
6
10
  export declare const defaultAssemblyId = "assembly-id";
7
11
  export declare const assemblyGeneratedVariableName = "text_uuid1Assembly";
8
12
  export declare const assemblyGeneratedDesignVariableName = "cfWidth_uuid2Assembly";
9
- export declare const createAssemblyEntry: ({ schemaVersion, id, }?: createAssemblyEntryArgs) => ExperienceEntry;
13
+ export declare const createAssemblyEntry: ({ schemaVersion, id, nestedPatterns, }?: createAssemblyEntryArgs) => ExperienceEntry;
10
14
  type createAssemblyNodeArgs = {
11
15
  id: string;
12
16
  blockId?: string;
@@ -0,0 +1,141 @@
1
+ import { isCfStyleAttribute } from '@contentful/experiences-core';
2
+ import { convertResolvedDesignValuesToMediaQuery } from '../hooks/useMediaQuery.js';
3
+
4
+ /**
5
+ * The previous logic of prop mapping was too complex and mixed different ues cases together.
6
+ * In this function, I aim to simplify the logic by focusing on the following specific cases FOR PREVIEW/DELIVERY MODES
7
+ * 1) Any non `DesignValue` props should be resolved and returned as is
8
+ * 2) Some exceptions like `cfImageAsset` and `cfBackgroundImageUrl` (BoundValue) should be handled separately
9
+ * and be resolved for the default breakpoint only (cause we don't allow binding per breakpoint anyway)
10
+ * 3) Those DesignValue props which can be converted to CSS should be grouped and resolved into a CSS media query
11
+ * for each breakpoint
12
+ * 4) Those DesignValue props which can NOT be converted to CSS (custom design props) should be resolved dynamically
13
+ * for each breakpoint
14
+ */
15
+ const parseComponentProps = ({ componentDefinition, node, resolveClassNamesFromBuiltInStyles, resolveCustomDesignValue, resolveBoundValue, resolveHyperlinkValue, resolveUnboundValue, }) => {
16
+ const styleProps = {};
17
+ const customDesignProps = {};
18
+ const contentProps = {};
19
+ for (const [propName, propDefinition] of Object.entries(componentDefinition.variables)) {
20
+ const propertyValue = node.variables[propName];
21
+ if (!propertyValue)
22
+ continue;
23
+ switch (propertyValue.type) {
24
+ case 'DesignValue': {
25
+ if (isCfStyleAttribute(propName)) {
26
+ // 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
27
+ styleProps[propName] = propertyValue.valuesByBreakpoint;
28
+ }
29
+ else {
30
+ // for custom design props, the value will be resolved with the javascript per breakpoint at runtime
31
+ customDesignProps[propName] = resolveCustomDesignValue({
32
+ propertyName: propName,
33
+ valuesByBreakpoint: propertyValue.valuesByBreakpoint,
34
+ });
35
+ }
36
+ break;
37
+ }
38
+ case 'BoundValue': {
39
+ const boundValue = resolveBoundValue({
40
+ propertyName: propName,
41
+ dataType: propDefinition.type,
42
+ binding: propertyValue,
43
+ });
44
+ contentProps[propName] = boundValue ?? propDefinition.defaultValue;
45
+ break;
46
+ }
47
+ case 'HyperlinkValue': {
48
+ const hyperlink = resolveHyperlinkValue({
49
+ linkTargetKey: propertyValue.linkTargetKey,
50
+ });
51
+ if (hyperlink) {
52
+ contentProps[propName] = hyperlink;
53
+ }
54
+ break;
55
+ }
56
+ case 'UnboundValue': {
57
+ const unboundValue = resolveUnboundValue({
58
+ mappingKey: propertyValue.key,
59
+ defaultValue: propDefinition.defaultValue,
60
+ });
61
+ contentProps[propName] = unboundValue;
62
+ break;
63
+ }
64
+ case 'ComponentValue':
65
+ // We're rendering a pattern entry. Content cannot be set for ComponentValue type properties
66
+ // directly in the pattern so we can safely use the default value
67
+ // This can either a design (style) or a content variable
68
+ contentProps[propName] = propDefinition.defaultValue;
69
+ break;
70
+ }
71
+ }
72
+ /**
73
+ * {
74
+ desktop: {
75
+ cfVerticalAlignment: 'center',
76
+ cfHorizontalAlignment: 'center',
77
+ cfMargin: '0 0 0 0',
78
+ cfPadding: '0 0 0 0',
79
+ cfBackgroundColor: 'rgba(246, 246, 246, 1)',
80
+ cfWidth: 'fill',
81
+ cfHeight: 'fit-content',
82
+ cfMaxWidth: 'none',
83
+ cfFlexDirection: 'column',
84
+ cfFlexWrap: 'nowrap',
85
+ cfBorder: '0px solid rgba(0, 0, 0, 0)',
86
+ cfBorderRadius: '0px',
87
+ cfGap: '0px 0px',
88
+ cfBackgroundImageOptions: { scaling: 'fill', alignment: 'left top', targetSize: '2000px' }
89
+ },
90
+ tablet: {},
91
+ mobile: {}
92
+ }
93
+ */
94
+ const stylePropsIndexedByBreakpoint = Object.entries(styleProps).reduce((acc, [propName, valuesByBreakpoint]) => {
95
+ for (const [breakpointId, value] of Object.entries(valuesByBreakpoint)) {
96
+ if (!acc[breakpointId]) {
97
+ acc[breakpointId] = {};
98
+ }
99
+ acc[breakpointId][propName] = value;
100
+ }
101
+ return acc;
102
+ }, {});
103
+ /**
104
+ * [
105
+ * {
106
+ * className: 'cfstyles-123',
107
+ * breakpointCondition: '<=1024px',
108
+ * css: '.cfstyles-123 { color: red; }'
109
+ * },
110
+ * {
111
+ * className: 'cfstyles-456',
112
+ * breakpointCondition: '<=768px',
113
+ * css: '.cfstyles-456 { color: blue; }'
114
+ * }
115
+ * ]
116
+ */
117
+ const styleSheetData = resolveClassNamesFromBuiltInStyles(stylePropsIndexedByBreakpoint);
118
+ /**
119
+ * {
120
+ * className: ['cfstyles-123', 'cfstyles-456'],
121
+ * styleSheet: `
122
+ * @media (max-width: 1024px) {
123
+ * .cfstyles-123 { color: red; }
124
+ * }
125
+ * @media (max-width: 768px) {
126
+ * .cfstyles-456 { color: blue; }
127
+ * }
128
+ * `
129
+ * }
130
+ */
131
+ const mediaQuery = convertResolvedDesignValuesToMediaQuery(styleSheetData);
132
+ return {
133
+ styleProps,
134
+ mediaQuery,
135
+ customDesignProps,
136
+ contentProps,
137
+ };
138
+ };
139
+
140
+ export { parseComponentProps };
141
+ //# sourceMappingURL=parseComponentProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseComponentProps.js","sources":["../../../src/utils/parseComponentProps.ts"],"sourcesContent":["import { isCfStyleAttribute } from '@contentful/experiences-core';\nimport {\n BoundComponentPropertyTypes,\n BoundValue,\n ComponentDefinition,\n ComponentDefinitionVariable,\n ComponentDefinitionVariableType,\n ComponentTreeNode,\n DesignValue,\n PrimitiveValue,\n} from '@contentful/experiences-core/types';\nimport { convertResolvedDesignValuesToMediaQuery } from '../hooks/useMediaQuery';\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 */\nexport const parseComponentProps = ({\n componentDefinition,\n node,\n resolveClassNamesFromBuiltInStyles,\n resolveCustomDesignValue,\n resolveBoundValue,\n resolveHyperlinkValue,\n resolveUnboundValue,\n}: {\n node: ComponentTreeNode;\n componentDefinition: ComponentDefinition;\n resolveClassNamesFromBuiltInStyles: (\n propsByBreakpointId: Record<string, Record<string, PrimitiveValue>>,\n ) => Array<{ className: string; breakpointCondition: string; css: string }>;\n resolveCustomDesignValue: (data: {\n propertyName: string;\n valuesByBreakpoint: Record<string, any>;\n }) => PrimitiveValue;\n resolveBoundValue: (data: {\n propertyName: string;\n dataType: ComponentDefinitionVariableType;\n binding: BoundValue;\n }) => BoundComponentPropertyTypes;\n resolveHyperlinkValue: (data: { linkTargetKey: string }) => string | null;\n resolveUnboundValue: (data: {\n mappingKey: string;\n defaultValue: ComponentDefinitionVariable['defaultValue'];\n }) => any;\n}) => {\n const styleProps: Record<string, DesignValue['valuesByBreakpoint']> = {};\n const customDesignProps: Record<string, PrimitiveValue> = {};\n const contentProps: Record<string, any> = {};\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] = resolveCustomDesignValue({\n propertyName: propName,\n valuesByBreakpoint: propertyValue.valuesByBreakpoint,\n });\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 contentProps[propName] = boundValue ?? propDefinition.defaultValue;\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 contentProps[propName] = unboundValue;\n break;\n }\n case 'ComponentValue':\n // We're rendering a pattern entry. Content cannot be set for ComponentValue type properties\n // directly in the pattern so we can safely use the default value\n // This can either a design (style) or a content variable\n contentProps[propName] = propDefinition.defaultValue;\n break;\n default:\n break;\n }\n }\n\n /**\n * {\n desktop: {\n cfVerticalAlignment: 'center',\n cfHorizontalAlignment: 'center',\n cfMargin: '0 0 0 0',\n cfPadding: '0 0 0 0',\n cfBackgroundColor: 'rgba(246, 246, 246, 1)',\n cfWidth: 'fill',\n cfHeight: 'fit-content',\n cfMaxWidth: 'none',\n cfFlexDirection: 'column',\n cfFlexWrap: 'nowrap',\n cfBorder: '0px solid rgba(0, 0, 0, 0)',\n cfBorderRadius: '0px',\n cfGap: '0px 0px',\n cfBackgroundImageOptions: { scaling: 'fill', alignment: 'left top', targetSize: '2000px' }\n },\n tablet: {},\n mobile: {}\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\n /**\n * [\n * {\n * className: 'cfstyles-123',\n * breakpointCondition: '<=1024px',\n * css: '.cfstyles-123 { color: red; }'\n * },\n * {\n * className: 'cfstyles-456',\n * breakpointCondition: '<=768px',\n * css: '.cfstyles-456 { color: blue; }'\n * }\n * ]\n */\n const styleSheetData = resolveClassNamesFromBuiltInStyles(stylePropsIndexedByBreakpoint);\n\n /**\n * {\n * className: ['cfstyles-123', 'cfstyles-456'],\n * styleSheet: `\n * @media (max-width: 1024px) {\n * .cfstyles-123 { color: red; }\n * }\n * @media (max-width: 768px) {\n * .cfstyles-456 { color: blue; }\n * }\n * `\n * }\n */\n const mediaQuery = convertResolvedDesignValuesToMediaQuery(styleSheetData);\n\n return {\n styleProps,\n mediaQuery,\n customDesignProps,\n contentProps,\n };\n};\n"],"names":[],"mappings":";;;AAaA;;;;;;;;;;AAUG;MACU,mBAAmB,GAAG,CAAC,EAClC,mBAAmB,EACnB,IAAI,EACJ,kCAAkC,EAClC,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,GAqBpB,KAAI;IACH,MAAM,UAAU,GAAsD,EAAE,CAAC;IACzE,MAAM,iBAAiB,GAAmC,EAAE,CAAC;IAC7D,MAAM,YAAY,GAAwB,EAAE,CAAC;AAE7C,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;AAE7B,QAAA,QAAQ,aAAa,CAAC,IAAI;YACxB,KAAK,aAAa,EAAE;AAClB,gBAAA,IAAI,kBAAkB,CAAC,QAAQ,CAAC,EAAE;;AAEhC,oBAAA,UAAU,CAAC,QAAQ,CAAC,GAAG,aAAa,CAAC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AAQ,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;AAEP;;;;;;;;;;;;;AAaG;AACH,IAAA,MAAM,cAAc,GAAG,kCAAkC,CAAC,6BAA6B,CAAC,CAAC;AAEzF;;;;;;;;;;;;AAYG;AACH,IAAA,MAAM,UAAU,GAAG,uCAAuC,CAAC,cAAc,CAAC,CAAC;IAE3E,OAAO;QACL,UAAU;QACV,UAAU;QACV,iBAAiB;QACjB,YAAY;KACb,CAAC;AACJ;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/experiences-sdk-react",
3
- "version": "1.30.5-dev-20250206T1804-ed40499.0",
3
+ "version": "1.30.5-prerelease-20250207T1349-200d927.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": "1.30.5-dev-20250206T1804-ed40499.0",
45
- "@contentful/experiences-core": "1.30.5-dev-20250206T1804-ed40499.0",
46
- "@contentful/experiences-validators": "1.30.5-dev-20250206T1804-ed40499.0",
47
- "@contentful/experiences-visual-editor-react": "1.30.5-dev-20250206T1804-ed40499.0",
44
+ "@contentful/experiences-components-react": "1.30.5-prerelease-20250207T1349-200d927.0",
45
+ "@contentful/experiences-core": "1.30.5-prerelease-20250207T1349-200d927.0",
46
+ "@contentful/experiences-validators": "1.30.5-prerelease-20250207T1349-200d927.0",
47
+ "@contentful/experiences-visual-editor-react": "1.30.5-prerelease-20250207T1349-200d927.0",
48
48
  "@contentful/rich-text-types": "^17.0.0",
49
49
  "classnames": "^2.3.2",
50
50
  "csstype": "^3.1.2",
@@ -102,5 +102,5 @@
102
102
  "dist",
103
103
  "package.json"
104
104
  ],
105
- "gitHead": "2a5fa908986bdb67b902737c2b6baf9ae18d86ab"
105
+ "gitHead": "3cf3a2124931f9404934eede743e2c42e1de64a5"
106
106
  }