@contentful/experiences-sdk-react 1.31.1-prerelease-20250218T2104-febb4f2.0 → 1.31.2-dev-20250220T0912-4b32230.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(), patternNodeIdsChain = '', }) => {
12
- const [hasRendered, setHasRendered] = React.useState(false);
14
+ const [hasRendered, setHasRendered] = useState(false);
13
15
  patternNodeIdsChain = `${patternNodeIdsChain}${rawNode.id}`;
14
16
  useEffect(() => {
15
17
  setHasRendered(true);
@@ -42,69 +44,83 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
42
44
  }
43
45
  return registration;
44
46
  }, [isAssembly, node.definitionId]);
45
- const nodeProps = useMemo(() => {
47
+ const { ssrProps, customDesignProps, contentProps, props, mediaQuery } = useMemo(() => {
46
48
  // In SSR, we store the className under breakpoints[0] which is resolved here to the actual string
47
49
  const cfSsrClassNameValues = node.variables.cfSsrClassName;
48
- const cfSsrClassName = resolveDesignValue(cfSsrClassNameValues?.valuesByBreakpoint, 'cfSsrClassName');
50
+ const mainBreakpoint = entityStore.breakpoints[0];
51
+ const cfSsrClassName = cfSsrClassNameValues?.valuesByBreakpoint?.[mainBreakpoint.id];
49
52
  // Don't enrich the assembly wrapper node with props
50
53
  if (!componentRegistration || isAssembly) {
51
- return { cfSsrClassName };
54
+ const ssrProps = { cfSsrClassName };
55
+ const props = { className: cfSsrClassName };
56
+ return {
57
+ ssrProps,
58
+ props,
59
+ customDesignProps: {},
60
+ };
52
61
  }
53
- const propMap = {
62
+ const ssrProps = {
54
63
  cfSsrClassName: node.id && getPatternChildNodeClassName
55
64
  ? getPatternChildNodeClassName(node.id)
56
65
  : cfSsrClassName,
57
66
  };
58
- const props = Object.entries(componentRegistration.definition.variables).reduce((acc, [variableName, variableDefinition]) => {
59
- const variable = node.variables[variableName];
60
- if (!variable)
61
- return acc;
62
- switch (variable.type) {
63
- case 'DesignValue':
64
- acc[variableName] = resolveDesignValue(variable.valuesByBreakpoint, variableName);
65
- break;
66
- case 'BoundValue': {
67
- const [, uuid] = variable.path.split('/');
68
- const binding = entityStore.dataSource[uuid];
69
- const value = transformBoundContentValue(node.variables, entityStore, binding, resolveDesignValue, variableName, variableDefinition, variable.path);
70
- acc[variableName] = value ?? variableDefinition.defaultValue;
71
- break;
72
- }
73
- case 'HyperlinkValue': {
74
- const binding = entityStore.dataSource[variable.linkTargetKey];
75
- const hyperlinkEntry = entityStore.getEntryOrAsset(binding, variable.linkTargetKey);
76
- const value = resolveHyperlinkPattern(componentRegistration.definition.hyperlinkPattern ||
77
- hyperlinkPattern ||
78
- HYPERLINK_DEFAULT_PATTERN, hyperlinkEntry, locale);
79
- if (value) {
80
- acc[variableName] = value;
81
- }
82
- break;
83
- }
84
- case 'UnboundValue': {
85
- const uuid = variable.key;
86
- acc[variableName] =
87
- entityStore.unboundValues[uuid]?.value ?? variableDefinition.defaultValue;
88
- break;
89
- }
90
- case 'ComponentValue':
91
- // We're rendering a pattern entry. Content cannot be set for ComponentValue type properties
92
- // directly in the pattern so we can safely use the default value
93
- // This can either a design (style) or a content variable
94
- acc[variableName] = variableDefinition.defaultValue;
95
- break;
96
- }
97
- return acc;
98
- }, propMap);
67
+ const { contentProps = {}, styleProps = {}, customDesignProps = {}, mediaQuery, } = parseComponentProps({
68
+ mainBreakpoint,
69
+ componentDefinition: componentRegistration.definition,
70
+ node,
71
+ resolveCustomDesignValue: ({ propertyName, valuesByBreakpoint }) => {
72
+ return resolveDesignValue(valuesByBreakpoint, propertyName);
73
+ },
74
+ resolveBoundValue: ({ binding, propertyName, dataType }) => {
75
+ const [, uuid] = binding.path.split('/');
76
+ const boundEntityLink = entityStore.dataSource[uuid];
77
+ const boundValue = transformBoundContentValue(node.variables, entityStore, boundEntityLink, resolveDesignValue, propertyName, dataType, binding.path);
78
+ return boundValue;
79
+ },
80
+ resolveHyperlinkValue: ({ linkTargetKey }) => {
81
+ const boundEntity = entityStore.dataSource[linkTargetKey];
82
+ const hyperlinkEntry = entityStore.getEntryOrAsset(boundEntity, linkTargetKey);
83
+ const value = resolveHyperlinkPattern(componentRegistration.definition.hyperlinkPattern ||
84
+ hyperlinkPattern ||
85
+ HYPERLINK_DEFAULT_PATTERN, hyperlinkEntry, locale);
86
+ return value;
87
+ },
88
+ resolveUnboundValue: ({ mappingKey, defaultValue }) => {
89
+ return entityStore.unboundValues[mappingKey]?.value ?? defaultValue;
90
+ },
91
+ resolveClassNamesFromBuiltInStyles: (designPropsByBreakpointId) => {
92
+ return resolveClassNamesFromBuiltInStyles({
93
+ designPropsByBreakpointId,
94
+ breakpoints: entityStore.breakpoints,
95
+ node,
96
+ });
97
+ },
98
+ });
99
+ const slotsProps = {};
99
100
  if (componentRegistration.definition.slots) {
100
101
  for (const slotId in componentRegistration.definition.slots) {
101
102
  const slotNode = node.children.find((child) => child.slotId === slotId);
102
103
  if (slotNode) {
103
- props[slotId] = (jsx(CompositionBlock, { node: slotNode, locale: locale, hyperlinkPattern: hyperlinkPattern, entityStore: entityStore, resolveDesignValue: resolveDesignValue, wrappingPatternIds: wrappingPatternIds, patternNodeIdsChain: patternNodeIdsChain }));
104
+ slotsProps[slotId] = (jsx(CompositionBlock, { node: slotNode, locale: locale, hyperlinkPattern: hyperlinkPattern, entityStore: entityStore, resolveDesignValue: resolveDesignValue, wrappingPatternIds: wrappingPatternIds, patternNodeIdsChain: patternNodeIdsChain }));
104
105
  }
105
106
  }
106
107
  }
107
- return props;
108
+ const props = {
109
+ className: ssrProps.cfSsrClassName ?? mediaQuery?.className,
110
+ ...styleProps,
111
+ ...contentProps,
112
+ ...customDesignProps,
113
+ ...slotsProps,
114
+ };
115
+ return {
116
+ ssrProps,
117
+ contentProps,
118
+ slotsProps,
119
+ styleProps,
120
+ customDesignProps,
121
+ mediaQuery,
122
+ props,
123
+ };
108
124
  }, [
109
125
  node.variables,
110
126
  node.id,
@@ -119,7 +135,8 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
119
135
  wrappingPatternIds,
120
136
  patternNodeIdsChain,
121
137
  ]);
122
- const className = useClassName({ props: nodeProps, node });
138
+ // do not inject the stylesheet into the dom because it's already been done on the server side
139
+ useInjectStylesheet(ssrProps.cfSsrClassName ? undefined : mediaQuery);
123
140
  if (!componentRegistration) {
124
141
  return null;
125
142
  }
@@ -148,23 +165,22 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
148
165
  })
149
166
  : null;
150
167
  if ([CONTENTFUL_COMPONENTS.container.id, CONTENTFUL_COMPONENTS.section.id].includes(node.definitionId)) {
151
- return (jsx(ContentfulContainer, { editorMode: false, cfHyperlink: nodeProps.cfHyperlink, cfOpenInNewTab: nodeProps.cfOpenInNewTab, className: className, children: children }));
168
+ return (jsx(ContentfulContainer, { editorMode: false, cfHyperlink: contentProps.cfHyperlink, cfOpenInNewTab: contentProps.cfOpenInNewTab, className: props.className, children: children }));
152
169
  }
153
170
  if (node.definitionId === CONTENTFUL_COMPONENTS.columns.id) {
154
- return (jsx(Columns, { editorMode: false, className: className, children: children }));
171
+ return (jsx(Columns, { editorMode: false, className: props.className, children: children }));
155
172
  }
156
173
  if (node.definitionId === CONTENTFUL_COMPONENTS.singleColumn.id) {
157
- return (jsx(SingleColumn, { editorMode: false, className: className, children: children }));
174
+ return (jsx(SingleColumn, { editorMode: false, className: props.className, children: children }));
158
175
  }
159
176
  if (node.definitionId === CONTENTFUL_COMPONENTS.image.id &&
160
177
  node.variables.cfImageAsset?.type === 'UnboundValue') {
161
- return jsx(PreviewUnboundImage, { node: node, nodeProps: nodeProps, component: component });
178
+ return (jsx(PreviewUnboundImage, { node: node, nodeProps: props, component: component, breakpoints: entityStore.breakpoints }));
162
179
  }
163
180
  return React.createElement(component, {
164
- ...sanitizeNodeProps(nodeProps),
165
- className,
166
- key: `${node.id}-${hasRendered}`,
167
- }, children ?? (typeof nodeProps.children === 'string' ? nodeProps.children : null));
181
+ key: Object.keys(customDesignProps).length ? `${node.id}-${hasRendered}` : node.id,
182
+ ...sanitizeNodeProps(props),
183
+ }, children ?? (typeof props.children === 'string' ? props.children : null));
168
184
  };
169
185
 
170
186
  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 * Chained IDs to ensure uniqueness across multiple instances of the same pattern\n * when storing & accessing cfSsrClassName.\n */\n patternNodeIdsChain?: 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 patternNodeIdsChain = '',\n}: CompositionBlockProps) => {\n const [hasRendered, setHasRendered] = React.useState(false);\n patternNodeIdsChain = `${patternNodeIdsChain}${rawNode.id}`;\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 patternNodeIdsChain={patternNodeIdsChain}\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 patternNodeIdsChain,\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 const nodeIdsChain = `${patternNodeIdsChain}${childNodeId}`;\n // @ts-expect-error -- property cfSsrClassName is a map (id to classNames) that is added during rendering in ssrStyles\n const classesForNode: DesignValue | undefined = node.variables.cfSsrClassName?.[nodeIdsChain];\n\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 patternNodeIdsChain={patternNodeIdsChain}\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":";;;;;;;;;;AA+CO,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,EACxD,mBAAmB,GAAG,EAAE,GACF,KAAI;AAC1B,IAAA,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC5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E,KAAK,EAAE,SAAS,EAAE,SAAS,EAAA,QAAA,EAC7C,QAAQ,EAAA,CACD,EACV;KACH;IAED,IAAI,IAAI,CAAC,YAAY,KAAK,qBAAqB,CAAC,YAAY,CAAC,EAAE,EAAE;AAC/D,QAAA,QACEA,GAAA,CAAC,YAAY,EAAA,EAAC,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAA,QAAA,EAClD,QAAQ,EAAA,CACI,EACf;KACH;IAED,IACE,IAAI,CAAC,YAAY,KAAK,qBAAqB,CAAC,KAAK,CAAC,EAAE;QACpD,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,KAAK,cAAc,EACpD;AACA,QAAA,OAAOA,GAAC,CAAA,mBAAmB,EAAC,EAAA,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,GAAI,CAAC;KACxF;AAED,IAAA,OAAO,KAAK,CAAC,aAAa,CACxB,SAAS,EACT;QACE,GAAG,iBAAiB,CAAC,SAAS,CAAC;QAC/B,SAAS;AACT,QAAA,GAAG,EAAE,CAAG,EAAA,IAAI,CAAC,EAAE,CAAA,CAAA,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 * Chained IDs to ensure uniqueness across multiple instances of the same pattern\n * when storing & accessing cfSsrClassName.\n */\n patternNodeIdsChain?: 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 patternNodeIdsChain = '',\n}: CompositionBlockProps) => {\n const [hasRendered, setHasRendered] = useState(false);\n patternNodeIdsChain = `${patternNodeIdsChain}${rawNode.id}`;\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, customDesignProps, 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 customDesignProps: {},\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 mainBreakpoint,\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 patternNodeIdsChain={patternNodeIdsChain}\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 patternNodeIdsChain,\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 const nodeIdsChain = `${patternNodeIdsChain}${childNodeId}`;\n // @ts-expect-error -- property cfSsrClassName is a map (id to classNames) that is added during rendering in ssrStyles\n const classesForNode: DesignValue | undefined = node.variables.cfSsrClassName?.[nodeIdsChain];\n\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 patternNodeIdsChain={patternNodeIdsChain}\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 key: Object.keys(customDesignProps).length ? `${node.id}-${hasRendered}` : node.id,\n ...sanitizeNodeProps(props),\n },\n children ?? (typeof props.children === 'string' ? props.children : null),\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;AAgDO,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,EACxD,mBAAmB,GAAG,EAAE,GACF,KAAI;IAC1B,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACtD,mBAAmB,GAAG,GAAG,mBAAmB,CAAA,EAAG,OAAO,CAAC,EAAE,EAAE,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,OAAO,CAAC,CAAC,CAAC;AAEvC,IAAA,MAAM,kBAAkB,GAAG,OAAO,CAAC,MAAK;QACtC,IAAI,UAAU,EAAE;AACd,YAAA,OAAO,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,wBAAwB,CAAC,CAAC,CAA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QACA,QACEA,IAAC,mBAAmB,EAAA,EAClB,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,KAAK,EAChB,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,WAAW,CAAC,WAAW,EACpC,CAAA,EACF;KACH;AAED,IAAA,OAAO,KAAK,CAAC,aAAa,CACxB,SAAS,EACT;QACE,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,CAAA,CAAA,EAAI,WAAW,CAAA,CAAE,GAAG,IAAI,CAAC,EAAE;QAClF,GAAG,iBAAiB,CAAC,KAAK,CAAC;KAC5B,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: classNames(nodeProps.className, imageMedia.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: classNames(nodeProps.className, imageMedia.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;YAC/B,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC;SACjE,CAAC,EAAA,CACE,EACN;AACJ;;;;"}
@@ -1,42 +1,18 @@
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
19
- return;
20
- }
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) {
5
+ const useInjectStylesheet = (stylesheet) => {
6
+ useInsertionEffect(() => {
7
+ if (!stylesheet) {
31
8
  return;
32
9
  }
33
10
  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;
11
+ styleTag.setAttribute('type', 'text/css');
12
+ styleTag.innerHTML = stylesheet.css;
13
+ document.head.appendChild(styleTag);
14
+ }, [stylesheet]);
39
15
  };
40
16
 
41
- export { useClassName };
17
+ export { useInjectStylesheet };
42
18
  //# 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\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?: { css: string; className: string }) => {\n useInsertionEffect(() => {\n if (!stylesheet) {\n return;\n }\n\n const styleTag = document.createElement('style');\n styleTag.setAttribute('type', 'text/css');\n styleTag.innerHTML = stylesheet.css;\n\n document.head.appendChild(styleTag);\n }, [stylesheet]);\n};\n"],"names":[],"mappings":";;;;AA+Da,MAAA,mBAAmB,GAAG,CAAC,UAA+C,KAAI;IACrF,kBAAkB,CAAC,MAAK;QACtB,IAAI,CAAC,UAAU,EAAE;YACf,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,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC;AAEpC,QAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AACtC,KAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;AACnB;;;;"}
@@ -0,0 +1,112 @@
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
+ const resolveClassNamesFromBuiltInStyles = ({ designPropsByBreakpointId, breakpoints, node, }) => {
7
+ const mapOfDesignVariableKeys = flattenDesignTokenRegistry(designTokensRegistry);
8
+ const result = [];
9
+ // then for each breakpoint
10
+ for (const breakpoint of breakpoints) {
11
+ const designProps = designPropsByBreakpointId[breakpoint.id];
12
+ if (!designProps) {
13
+ continue;
14
+ }
15
+ const propsByBreakpointWithResolvedDesignTokens = Object.entries(designProps).reduce((acc, [propName, propValue]) => {
16
+ return {
17
+ ...acc,
18
+ [propName]: maybePopulateDesignTokenValue(propName, propValue, mapOfDesignVariableKeys),
19
+ };
20
+ }, {});
21
+ // We convert cryptic prop keys to css variables
22
+ // Eg: cfMargin to margin
23
+ const stylesForBreakpoint = buildCfStyles(propsByBreakpointWithResolvedDesignTokens);
24
+ if (!node.children.length &&
25
+ isStructureWithRelativeHeight(node.definitionId, stylesForBreakpoint.height)) {
26
+ stylesForBreakpoint.minHeight = EMPTY_CONTAINER_HEIGHT;
27
+ }
28
+ const stylesForBreakpointWithoutUndefined = Object.fromEntries(Object.entries(stylesForBreakpoint)
29
+ .filter(([, value]) => value !== undefined)
30
+ .map(([key, value]) => [toCSSAttribute(key), value]));
31
+ /**
32
+ * stylesForBreakpoint {
33
+ margin: '0 0 0 0',
34
+ padding: '0 0 0 0',
35
+ 'background-color': 'rgba(246, 246, 246, 1)',
36
+ width: '100%',
37
+ height: 'fit-content',
38
+ 'max-width': 'none',
39
+ border: '0px solid rgba(0, 0, 0, 0)',
40
+ 'border-radius': '0px',
41
+ gap: '0px 0px',
42
+ 'align-items': 'center',
43
+ 'justify-content': 'safe center',
44
+ 'flex-direction': 'column',
45
+ 'flex-wrap': 'nowrap',
46
+ 'font-style': 'normal',
47
+ 'text-decoration': 'none',
48
+ 'box-sizing': 'border-box'
49
+ }
50
+ */
51
+ // I create a hash of the object above because that would ensure hash stability
52
+ const styleHash = md5(`${node.id}-${JSON.stringify(stylesForBreakpointWithoutUndefined)}`);
53
+ // and prefix the className to make sure the value can be processed
54
+ const className = `cfstyles-${styleHash}`;
55
+ // otherwise, save it to the stylesheet
56
+ result.push({
57
+ className,
58
+ breakpointCondition: breakpoint.query,
59
+ css: toCSSString(stylesForBreakpointWithoutUndefined),
60
+ });
61
+ }
62
+ return result;
63
+ };
64
+ const convertResolvedDesignValuesToMediaQuery = (styleSheetData) => {
65
+ /**
66
+ * {
67
+ * className: ['cfstyles-123', 'cfstyles-456'],
68
+ * styleSheet: `
69
+ * @media (max-width: 1024px) {
70
+ * .cfstyles-123 { color: red; }
71
+ * }
72
+ * @media (max-width: 768px) {
73
+ * .cfstyles-456 { color: blue; }
74
+ * }
75
+ * `
76
+ * }
77
+ */
78
+ const styleSheet = styleSheetData.reduce((acc, { breakpointCondition, className, css }) => {
79
+ if (acc.className.includes(className)) {
80
+ return acc;
81
+ }
82
+ const mediaQuery = toMediaQuery({
83
+ condition: breakpointCondition,
84
+ cssByClassName: { [className]: css },
85
+ });
86
+ return {
87
+ className: [...acc.className, className],
88
+ css: `${acc.css}${mediaQuery}`,
89
+ };
90
+ }, {
91
+ className: [],
92
+ css: '',
93
+ });
94
+ const className = styleSheet.className.join(' ');
95
+ return {
96
+ css: styleSheet.css,
97
+ className,
98
+ };
99
+ };
100
+ const useMediaQuery = ({ designPropsByBreakpointId, breakpoints, node, }) => {
101
+ return useMemo(() => {
102
+ const styleSheetData = resolveClassNamesFromBuiltInStyles({
103
+ designPropsByBreakpointId,
104
+ breakpoints,
105
+ node,
106
+ });
107
+ return convertResolvedDesignValuesToMediaQuery(styleSheetData);
108
+ }, [designPropsByBreakpointId, breakpoints, node]);
109
+ };
110
+
111
+ export { convertResolvedDesignValuesToMediaQuery, resolveClassNamesFromBuiltInStyles, useMediaQuery };
112
+ //# 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\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(`${node.id}-${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\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 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":";;;;;AAqBO,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,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,CAClF,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC,KAAI;YAC7B,OAAO;AACL,gBAAA,GAAG,GAAG;gBACN,CAAC,QAAQ,GAAG,6BAA6B,CAAC,QAAQ,EAAE,SAAS,EAAE,uBAAuB,CAAC;aACxF,CAAC;SACH,EACD,EAAE,CACH,CAAC;;;AAIF,QAAA,MAAM,mBAAmB,GAAG,aAAa,CAAC,yCAAyC,CAAC,CAAC;AAErF,QAAA,IACE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM;YACrB,6BAA6B,CAAC,IAAI,CAAC,YAAY,EAAE,mBAAmB,CAAC,MAAM,CAAC,EAC5E;AACA,YAAA,mBAAmB,CAAC,SAAS,GAAG,sBAAsB,CAAC;SACxD;QAED,MAAM,mCAAmC,GAA2B,MAAM,CAAC,WAAW,CACpF,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC;AAChC,aAAA,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,KAAK,KAAK,SAAS,CAAC;aAC1C,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAA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,EAAE;AACR,KAAA,CACF,CAAC;IAEF,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEjD,OAAO;QACL,GAAG,EAAE,UAAU,CAAC,GAAG;QACnB,SAAS;KACV,CAAC;AACJ,EAAE;AAEK,MAAM,aAAa,GAAG,CAAC,EAC5B,yBAAyB,EACzB,WAAW,EACX,IAAI,GAKL,KAAI;IACH,OAAO,OAAO,CAAC,MAAK;QAClB,MAAM,cAAc,GAAG,kCAAkC,CAAC;YACxD,yBAAyB;YACzB,WAAW;YACX,IAAI;AACL,SAAA,CAAC,CAAC;AAEH,QAAA,OAAO,uCAAuC,CAAC,cAAc,CAAC,CAAC;KAChE,EAAE,CAAC,yBAAyB,EAAE,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.31.1-prerelease-20250218T2104-febb4f2.0";
11
+ declare const SDK_VERSION = "1.31.2-dev-20250220T0912-4b32230.0";
12
12
 
13
13
  type ExperienceRootProps = {
14
14
  experience?: Experience<EntityStore> | string | null;
@@ -1,4 +1,4 @@
1
- const SDK_VERSION = '1.31.1-prerelease-20250218T2104-febb4f2.0';
1
+ const SDK_VERSION = '1.31.2-dev-20250220T0912-4b32230.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.31.1-prerelease-20250218T2104-febb4f2.0';\n"],"names":[],"mappings":"AAAO,MAAM,WAAW,GAAG;;;;"}
1
+ {"version":3,"file":"sdkVersion.js","sources":["../../src/sdkVersion.ts"],"sourcesContent":["export const SDK_VERSION = '1.31.2-dev-20250220T0912-4b32230.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,7 @@ 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
+ className: string;
17
+ }) => void;
@@ -0,0 +1,24 @@
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
+ className: string;
15
+ };
16
+ export declare const useMediaQuery: ({ designPropsByBreakpointId, breakpoints, node, }: {
17
+ designPropsByBreakpointId: Record<string, Record<string, any>>;
18
+ breakpoints: Breakpoint[];
19
+ node: ComponentTreeNode;
20
+ }) => {
21
+ css: string;
22
+ className: string;
23
+ };
24
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.31.1-prerelease-20250218T2104-febb4f2.0";
1
+ export declare const SDK_VERSION = "1.31.2-dev-20250220T0912-4b32230.0";
@@ -0,0 +1,46 @@
1
+ import { BoundComponentPropertyTypes, BoundValue, Breakpoint, 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: ({ mainBreakpoint, componentDefinition, node, resolveClassNamesFromBuiltInStyles, resolveCustomDesignValue, resolveBoundValue, resolveHyperlinkValue, resolveUnboundValue, }: {
14
+ mainBreakpoint: Breakpoint;
15
+ node: ComponentTreeNode;
16
+ componentDefinition: ComponentDefinition;
17
+ resolveClassNamesFromBuiltInStyles: (propsByBreakpointId: Record<string, Record<string, PrimitiveValue>>) => Array<{
18
+ className: string;
19
+ breakpointCondition: string;
20
+ css: string;
21
+ }>;
22
+ resolveCustomDesignValue: (data: {
23
+ propertyName: string;
24
+ valuesByBreakpoint: Record<string, any>;
25
+ }) => PrimitiveValue;
26
+ resolveBoundValue: (data: {
27
+ propertyName: string;
28
+ dataType: ComponentDefinitionVariableType;
29
+ binding: BoundValue;
30
+ }) => BoundComponentPropertyTypes;
31
+ resolveHyperlinkValue: (data: {
32
+ linkTargetKey: string;
33
+ }) => string | null;
34
+ resolveUnboundValue: (data: {
35
+ mappingKey: string;
36
+ defaultValue: ComponentDefinitionVariable["defaultValue"];
37
+ }) => any;
38
+ }) => {
39
+ styleProps: Record<string, Record<string, string | number | boolean | Record<any, any> | undefined>>;
40
+ mediaQuery: {
41
+ css: string;
42
+ className: string;
43
+ };
44
+ customDesignProps: Record<string, string | number | boolean | Record<any, any> | undefined>;
45
+ contentProps: Record<string, any>;
46
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -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,2 @@
1
+ import { Breakpoint } from '@contentful/experiences-core/types';
2
+ export declare const createBreakpoints: () => Breakpoint[];
@@ -0,0 +1,2 @@
1
+ import { ComponentDefinition } from '@contentful/experiences-core/types';
2
+ export declare const createComponentDefinition: () => ComponentDefinition;
@@ -0,0 +1,2 @@
1
+ import { ComponentTreeNode } from '@contentful/experiences-validators';
2
+ export declare const createComponentTreeNode: () => ComponentTreeNode;
@@ -0,0 +1,155 @@
1
+ import { isCfStyleAttribute } from '@contentful/experiences-core';
2
+ import { convertResolvedDesignValuesToMediaQuery } from '../hooks/useMediaQuery.js';
3
+
4
+ const isSpecialCaseCssProp = (propName) => {
5
+ return propName === 'cfBackgroundImageUrl' || propName.startsWith('cfBackgroundImageUrl_');
6
+ };
7
+ /**
8
+ * The previous logic of prop mapping was too complex and mixed different ues cases together.
9
+ * In this function, I aim to simplify the logic by focusing on the following specific cases FOR PREVIEW/DELIVERY MODES
10
+ * 1) Any non `DesignValue` props should be resolved and returned as is
11
+ * 2) Some exceptions like `cfImageAsset` and `cfBackgroundImageUrl` (BoundValue) should be handled separately
12
+ * and be resolved for the default breakpoint only (cause we don't allow binding per breakpoint anyway)
13
+ * 3) Those DesignValue props which can be converted to CSS should be grouped and resolved into a CSS media query
14
+ * for each breakpoint
15
+ * 4) Those DesignValue props which can NOT be converted to CSS (custom design props) should be resolved dynamically
16
+ * for each breakpoint
17
+ */
18
+ const parseComponentProps = ({ mainBreakpoint, componentDefinition, node, resolveClassNamesFromBuiltInStyles, resolveCustomDesignValue, resolveBoundValue, resolveHyperlinkValue, resolveUnboundValue, }) => {
19
+ const styleProps = {};
20
+ const customDesignProps = {};
21
+ const contentProps = {};
22
+ for (const [propName, propDefinition] of Object.entries(componentDefinition.variables)) {
23
+ const propertyValue = node.variables[propName];
24
+ if (!propertyValue)
25
+ continue;
26
+ switch (propertyValue.type) {
27
+ case 'DesignValue': {
28
+ if (isCfStyleAttribute(propName)) {
29
+ // 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
30
+ styleProps[propName] = propertyValue.valuesByBreakpoint;
31
+ }
32
+ else {
33
+ // for custom design props, the value will be resolved with the javascript per breakpoint at runtime
34
+ customDesignProps[propName] = resolveCustomDesignValue({
35
+ propertyName: propName,
36
+ valuesByBreakpoint: propertyValue.valuesByBreakpoint,
37
+ });
38
+ }
39
+ break;
40
+ }
41
+ case 'BoundValue': {
42
+ const boundValue = resolveBoundValue({
43
+ propertyName: propName,
44
+ dataType: propDefinition.type,
45
+ binding: propertyValue,
46
+ });
47
+ const propValue = boundValue ?? propDefinition.defaultValue;
48
+ if (isSpecialCaseCssProp(propName)) {
49
+ styleProps[propName] = { [mainBreakpoint.id]: propValue };
50
+ }
51
+ else {
52
+ contentProps[propName] = propValue;
53
+ }
54
+ break;
55
+ }
56
+ case 'HyperlinkValue': {
57
+ const hyperlink = resolveHyperlinkValue({
58
+ linkTargetKey: propertyValue.linkTargetKey,
59
+ });
60
+ if (hyperlink) {
61
+ contentProps[propName] = hyperlink;
62
+ }
63
+ break;
64
+ }
65
+ case 'UnboundValue': {
66
+ const unboundValue = resolveUnboundValue({
67
+ mappingKey: propertyValue.key,
68
+ defaultValue: propDefinition.defaultValue,
69
+ });
70
+ if (isSpecialCaseCssProp(propName)) {
71
+ styleProps[propName] = { [mainBreakpoint.id]: unboundValue };
72
+ }
73
+ else {
74
+ contentProps[propName] = unboundValue;
75
+ }
76
+ break;
77
+ }
78
+ case 'ComponentValue':
79
+ // We're rendering a pattern entry. Content cannot be set for ComponentValue type properties
80
+ // directly in the pattern so we can safely use the default value
81
+ // This can either a design (style) or a content variable
82
+ contentProps[propName] = propDefinition.defaultValue;
83
+ break;
84
+ }
85
+ }
86
+ /**
87
+ * {
88
+ desktop: {
89
+ cfVerticalAlignment: 'center',
90
+ cfHorizontalAlignment: 'center',
91
+ cfMargin: '0 0 0 0',
92
+ cfPadding: '0 0 0 0',
93
+ cfBackgroundColor: 'rgba(246, 246, 246, 1)',
94
+ cfWidth: 'fill',
95
+ cfHeight: 'fit-content',
96
+ cfMaxWidth: 'none',
97
+ cfFlexDirection: 'column',
98
+ cfFlexWrap: 'nowrap',
99
+ cfBorder: '0px solid rgba(0, 0, 0, 0)',
100
+ cfBorderRadius: '0px',
101
+ cfGap: '0px 0px',
102
+ cfBackgroundImageOptions: { scaling: 'fill', alignment: 'left top', targetSize: '2000px' }
103
+ },
104
+ tablet: {},
105
+ mobile: {}
106
+ }
107
+ */
108
+ const stylePropsIndexedByBreakpoint = Object.entries(styleProps).reduce((acc, [propName, valuesByBreakpoint]) => {
109
+ for (const [breakpointId, value] of Object.entries(valuesByBreakpoint)) {
110
+ if (!acc[breakpointId]) {
111
+ acc[breakpointId] = {};
112
+ }
113
+ acc[breakpointId][propName] = value;
114
+ }
115
+ return acc;
116
+ }, {});
117
+ /**
118
+ * [
119
+ * {
120
+ * className: 'cfstyles-123',
121
+ * breakpointCondition: '<=1024px',
122
+ * css: '.cfstyles-123 { color: red; }'
123
+ * },
124
+ * {
125
+ * className: 'cfstyles-456',
126
+ * breakpointCondition: '<=768px',
127
+ * css: '.cfstyles-456 { color: blue; }'
128
+ * }
129
+ * ]
130
+ */
131
+ const styleSheetData = resolveClassNamesFromBuiltInStyles(stylePropsIndexedByBreakpoint);
132
+ /**
133
+ * {
134
+ * className: ['cfstyles-123', 'cfstyles-456'],
135
+ * styleSheet: `
136
+ * @media (max-width: 1024px) {
137
+ * .cfstyles-123 { color: red; }
138
+ * }
139
+ * @media (max-width: 768px) {
140
+ * .cfstyles-456 { color: blue; }
141
+ * }
142
+ * `
143
+ * }
144
+ */
145
+ const mediaQuery = convertResolvedDesignValuesToMediaQuery(styleSheetData);
146
+ return {
147
+ styleProps,
148
+ mediaQuery,
149
+ customDesignProps,
150
+ contentProps,
151
+ };
152
+ };
153
+
154
+ export { parseComponentProps };
155
+ //# 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 Breakpoint,\n ComponentDefinition,\n ComponentDefinitionVariable,\n ComponentDefinitionVariableType,\n ComponentTreeNode,\n DesignValue,\n PrimitiveValue,\n} from '@contentful/experiences-core/types';\nimport { convertResolvedDesignValuesToMediaQuery } from '../hooks/useMediaQuery';\n\nconst isSpecialCaseCssProp = (propName: string) => {\n return propName === 'cfBackgroundImageUrl' || propName.startsWith('cfBackgroundImageUrl_');\n};\n\n/**\n * The previous logic of prop mapping was too complex and mixed different ues cases together.\n * In this function, I aim to simplify the logic by focusing on the following specific cases FOR PREVIEW/DELIVERY MODES\n * 1) Any non `DesignValue` props should be resolved and returned as is\n * 2) Some exceptions like `cfImageAsset` and `cfBackgroundImageUrl` (BoundValue) should be handled separately\n * and be resolved for the default breakpoint only (cause we don't allow binding per breakpoint anyway)\n * 3) Those DesignValue props which can be converted to CSS should be grouped and resolved into a CSS media query\n * for each breakpoint\n * 4) Those DesignValue props which can NOT be converted to CSS (custom design props) should be resolved dynamically\n * for each breakpoint\n */\nexport const parseComponentProps = ({\n mainBreakpoint,\n componentDefinition,\n node,\n resolveClassNamesFromBuiltInStyles,\n resolveCustomDesignValue,\n resolveBoundValue,\n resolveHyperlinkValue,\n resolveUnboundValue,\n}: {\n mainBreakpoint: Breakpoint;\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\n const propValue = boundValue ?? propDefinition.defaultValue;\n\n if (isSpecialCaseCssProp(propName)) {\n styleProps[propName] = { [mainBreakpoint.id]: propValue };\n } else {\n contentProps[propName] = propValue;\n }\n break;\n }\n\n case 'HyperlinkValue': {\n const hyperlink = resolveHyperlinkValue({\n linkTargetKey: propertyValue.linkTargetKey,\n });\n if (hyperlink) {\n contentProps[propName] = hyperlink;\n }\n break;\n }\n case 'UnboundValue': {\n const unboundValue = resolveUnboundValue({\n mappingKey: propertyValue.key,\n defaultValue: propDefinition.defaultValue,\n });\n\n if (isSpecialCaseCssProp(propName)) {\n styleProps[propName] = { [mainBreakpoint.id]: unboundValue };\n } else {\n contentProps[propName] = unboundValue;\n }\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":";;;AAcA,MAAM,oBAAoB,GAAG,CAAC,QAAgB,KAAI;IAChD,OAAO,QAAQ,KAAK,sBAAsB,IAAI,QAAQ,CAAC,UAAU,CAAC,uBAAuB,CAAC,CAAC;AAC7F,CAAC,CAAC;AAEF;;;;;;;;;;AAUG;MACU,mBAAmB,GAAG,CAAC,EAClC,cAAc,EACd,mBAAmB,EACnB,IAAI,EACJ,kCAAkC,EAClC,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,GAsBpB,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,IAA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;;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.31.1-prerelease-20250218T2104-febb4f2.0",
3
+ "version": "1.31.2-dev-20250220T0912-4b32230.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.31.1-prerelease-20250218T2104-febb4f2.0",
45
- "@contentful/experiences-core": "1.31.1-prerelease-20250218T2104-febb4f2.0",
46
- "@contentful/experiences-validators": "1.31.1-prerelease-20250218T2104-febb4f2.0",
47
- "@contentful/experiences-visual-editor-react": "1.31.1-prerelease-20250218T2104-febb4f2.0",
44
+ "@contentful/experiences-components-react": "1.31.2-dev-20250220T0912-4b32230.0",
45
+ "@contentful/experiences-core": "1.31.2-dev-20250220T0912-4b32230.0",
46
+ "@contentful/experiences-validators": "1.31.2-dev-20250220T0912-4b32230.0",
47
+ "@contentful/experiences-visual-editor-react": "1.31.2-dev-20250220T0912-4b32230.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": "b25a64bef095e7ad95d644918cd574f3a042fd50"
105
+ "gitHead": "cb86b09807990664d08948fed88316e346ecb86d"
106
106
  }