@contentful/experiences-sdk-react 1.35.0-dev-20250324T2005-a11cb8e.0 → 1.35.0-prerelease-20250414T1325-5725f29.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.
@@ -9,7 +9,7 @@ import { resolveAssembly } from '../../core/preview/assemblyUtils.js';
9
9
  import PreviewUnboundImage from './PreviewUnboundImage.js';
10
10
  import { parseComponentProps } from '../../utils/parseComponentProps.js';
11
11
 
12
- const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern, resolveDesignValue, getPatternChildNodeClassName, wrappingPatternIds: parentWrappingPatternIds = new Set(), wrappingPatternProperties: parentWrappingPatternProperties = {}, patternNodeIdsChain = '', }) => {
12
+ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern, resolveDesignValue, getPatternChildNodeClassName, wrappingPatternIds: parentWrappingPatternIds = new Set(), patternNodeIdsChain = '', }) => {
13
13
  patternNodeIdsChain = `${patternNodeIdsChain}${rawNode.id}`;
14
14
  const isAssembly = useMemo(() => checkIsAssemblyNode({
15
15
  componentId: rawNode.definitionId,
@@ -20,25 +20,15 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
20
20
  ? resolveAssembly({
21
21
  node: rawNode,
22
22
  entityStore,
23
- parentPatternProperties: parentWrappingPatternProperties,
24
23
  })
25
24
  : rawNode;
26
- }, [entityStore, isAssembly, rawNode, parentWrappingPatternProperties]);
25
+ }, [entityStore, isAssembly, rawNode]);
27
26
  const wrappingPatternIds = useMemo(() => {
28
27
  if (isAssembly) {
29
28
  return new Set([node.definitionId, ...parentWrappingPatternIds]);
30
29
  }
31
30
  return parentWrappingPatternIds;
32
31
  }, [isAssembly, node, parentWrappingPatternIds]);
33
- // Merge the pattern properties of the current node with the parent's pattern properties
34
- // to ensure nested patterns receive relevant pattern properties that were bubbled up
35
- // during assembly serialization.
36
- const wrappingPatternProperties = useMemo(() => {
37
- if (isAssembly) {
38
- return { ...parentWrappingPatternProperties, ...(rawNode.patternProperties || {}) };
39
- }
40
- return parentWrappingPatternProperties;
41
- }, [isAssembly, rawNode, parentWrappingPatternProperties]);
42
32
  const componentRegistration = useMemo(() => {
43
33
  const registration = getComponentRegistration(node.definitionId);
44
34
  if (isAssembly && !registration) {
@@ -100,7 +90,7 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
100
90
  for (const slotId in componentRegistration.definition.slots) {
101
91
  const slotNode = node.children.find((child) => child.slotId === slotId);
102
92
  if (slotNode) {
103
- slotsProps[slotId] = (jsx(CompositionBlock, { node: slotNode, locale: locale, hyperlinkPattern: hyperlinkPattern, entityStore: entityStore, resolveDesignValue: resolveDesignValue, wrappingPatternIds: wrappingPatternIds, wrappingPatternProperties: wrappingPatternProperties, patternNodeIdsChain: patternNodeIdsChain }));
93
+ slotsProps[slotId] = (jsx(CompositionBlock, { node: slotNode, locale: locale, hyperlinkPattern: hyperlinkPattern, entityStore: entityStore, resolveDesignValue: resolveDesignValue, wrappingPatternIds: wrappingPatternIds, patternNodeIdsChain: patternNodeIdsChain }));
104
94
  }
105
95
  }
106
96
  }
@@ -130,7 +120,6 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
130
120
  hyperlinkPattern,
131
121
  locale,
132
122
  wrappingPatternIds,
133
- wrappingPatternProperties,
134
123
  patternNodeIdsChain,
135
124
  ]);
136
125
  // do not inject the stylesheet into the dom because it's already been done on the server side
@@ -159,7 +148,7 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
159
148
  ? node.children.map((childNode, index) => {
160
149
  return (jsx(CompositionBlock, { getPatternChildNodeClassName: isAssembly || getPatternChildNodeClassName
161
150
  ? _getPatternChildNodeClassName
162
- : undefined, node: childNode, locale: locale, hyperlinkPattern: hyperlinkPattern, entityStore: entityStore, resolveDesignValue: resolveDesignValue, wrappingPatternIds: wrappingPatternIds, wrappingPatternProperties: wrappingPatternProperties, patternNodeIdsChain: patternNodeIdsChain }, index));
151
+ : undefined, node: childNode, locale: locale, hyperlinkPattern: hyperlinkPattern, entityStore: entityStore, resolveDesignValue: resolveDesignValue, wrappingPatternIds: wrappingPatternIds, patternNodeIdsChain: patternNodeIdsChain }, index));
163
152
  })
164
153
  : null;
165
154
  if (isContainerOrSection(node.definitionId)) {
@@ -1 +1 @@
1
- {"version":3,"file":"CompositionBlock.js","sources":["../../../../src/blocks/preview/CompositionBlock.tsx"],"sourcesContent":["import React, { ReactNode, 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 PatternProperty,\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';\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 wrappingPatternProperties?: Record<string, PatternProperty>;\n};\n\nexport const CompositionBlock = ({\n node: rawNode,\n locale,\n entityStore,\n hyperlinkPattern,\n resolveDesignValue,\n getPatternChildNodeClassName,\n wrappingPatternIds: parentWrappingPatternIds = new Set(),\n wrappingPatternProperties: parentWrappingPatternProperties = {},\n patternNodeIdsChain = '',\n}: CompositionBlockProps) => {\n patternNodeIdsChain = `${patternNodeIdsChain}${rawNode.id}`;\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 parentPatternProperties: parentWrappingPatternProperties,\n })\n : rawNode;\n }, [entityStore, isAssembly, rawNode, parentWrappingPatternProperties]);\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 // Merge the pattern properties of the current node with the parent's pattern properties\n // to ensure nested patterns receive relevant pattern properties that were bubbled up\n // during assembly serialization.\n const wrappingPatternProperties = useMemo(() => {\n if (isAssembly) {\n return { ...parentWrappingPatternProperties, ...(rawNode.patternProperties || {}) };\n }\n return parentWrappingPatternProperties;\n }, [isAssembly, rawNode, parentWrappingPatternProperties]);\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 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 breakpoints: entityStore.breakpoints,\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 });\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 wrappingPatternProperties={wrappingPatternProperties}\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,\n entityStore,\n componentRegistration,\n isAssembly,\n getPatternChildNodeClassName,\n resolveDesignValue,\n hyperlinkPattern,\n locale,\n wrappingPatternIds,\n wrappingPatternProperties,\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 wrappingPatternProperties={wrappingPatternProperties}\n patternNodeIdsChain={patternNodeIdsChain}\n />\n );\n })\n : null;\n\n if (isContainerOrSection(node.definitionId)) {\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 },\n children ?? (typeof props.children === 'string' ? props.children : null),\n );\n};\n\nconst isContainerOrSection = (\n nodeDefinitionId: string,\n): nodeDefinitionId is 'contentful-container' | 'contentful-section' =>\n [CONTENTFUL_COMPONENTS.container.id, CONTENTFUL_COMPONENTS.section.id].includes(\n nodeDefinitionId as 'contentful-container' | 'contentful-section',\n );\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;AAiDa,MAAA,gBAAgB,GAAG,CAAC,EAC/B,IAAI,EAAE,OAAO,EACb,MAAM,EACN,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,4BAA4B,EAC5B,kBAAkB,EAAE,wBAAwB,GAAG,IAAI,GAAG,EAAE,EACxD,yBAAyB,EAAE,+BAA+B,GAAG,EAAE,EAC/D,mBAAmB,GAAG,EAAE,GACF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AAqB,CAAC,SAAS,CAAC,EAAE,EAAE,qBAAqB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,QAAQ,CAC7E,gBAAiE,CAClE;;;;"}
1
+ {"version":3,"file":"CompositionBlock.js","sources":["../../../../src/blocks/preview/CompositionBlock.tsx"],"sourcesContent":["import React, { ReactNode, 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 { 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';\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 patternNodeIdsChain = `${patternNodeIdsChain}${rawNode.id}`;\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 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 breakpoints: entityStore.breakpoints,\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 });\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,\n entityStore,\n componentRegistration,\n isAssembly,\n getPatternChildNodeClassName,\n resolveDesignValue,\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 (isContainerOrSection(node.definitionId)) {\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 },\n children ?? (typeof props.children === 'string' ? props.children : null),\n );\n};\n\nconst isContainerOrSection = (\n nodeDefinitionId: string,\n): nodeDefinitionId is 'contentful-container' | 'contentful-section' =>\n [CONTENTFUL_COMPONENTS.container.id, CONTENTFUL_COMPONENTS.section.id].includes(\n nodeDefinitionId as 'contentful-container' | 'contentful-section',\n );\n"],"names":["_jsx"],"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;IAC1B,mBAAmB,GAAG,GAAG,mBAAmB,CAAA,EAAG,OAAO,CAAC,EAAE,EAAE,CAAC;IAE5D,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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,aAAa,CACxB,SAAS,EACT;QACE,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,EAAE;AAEF,MAAM,oBAAoB,GAAG,CAC3B,gBAAwB,KAExB,CAAC,qBAAqB,CAAC,SAAS,CAAC,EAAE,EAAE,qBAAqB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,QAAQ,CAC7E,gBAAiE,CAClE;;;;"}
@@ -1,6 +1,5 @@
1
1
  import { checkIsAssemblyNode } from '@contentful/experiences-core';
2
2
  import { shouldUsePrebinding, resolvePrebindingPath } from '../../utils/prebindingUtils.js';
3
- import { PATTERN_PROPERTY_DIVIDER } from '@contentful/experiences-core/constants';
4
3
 
5
4
  /** While unfolding the assembly definition on the instance, this function will replace all
6
5
  * ComponentValue in the definitions tree with the actual value on the instance. */
@@ -19,16 +18,18 @@ const deserializeAssemblyNode = ({ node, componentInstanceVariables, componentSe
19
18
  patternProperties,
20
19
  variable: instanceProperty,
21
20
  });
22
- const path = resolvePrebindingPath({
23
- componentSettings,
24
- componentValueKey,
25
- patternProperties,
26
- });
27
- if (usePrebinding && path) {
28
- variables[variableName] = {
29
- type: 'BoundValue',
30
- path,
31
- };
21
+ if (usePrebinding) {
22
+ const path = resolvePrebindingPath({
23
+ componentSettings,
24
+ componentValueKey,
25
+ patternProperties,
26
+ });
27
+ if (path) {
28
+ variables[variableName] = {
29
+ type: 'BoundValue',
30
+ path,
31
+ };
32
+ }
32
33
  // For assembly, we look up the variable in the assembly instance and
33
34
  // replace the ComponentValue with that one.
34
35
  }
@@ -38,9 +39,6 @@ const deserializeAssemblyNode = ({ node, componentInstanceVariables, componentSe
38
39
  key: instanceProperty.key,
39
40
  };
40
41
  }
41
- else if (instanceProperty?.type === 'NoValue') {
42
- variables[variableName] = instanceProperty;
43
- }
44
42
  else if (instanceProperty?.type === 'BoundValue') {
45
43
  variables[variableName] = {
46
44
  type: 'BoundValue',
@@ -83,10 +81,9 @@ const deserializeAssemblyNode = ({ node, componentInstanceVariables, componentSe
83
81
  children,
84
82
  slotId: node.slotId,
85
83
  displayName: node.displayName,
86
- patternProperties: node.patternProperties,
87
84
  };
88
85
  };
89
- const resolveAssembly = ({ node, parentPatternProperties, entityStore, }) => {
86
+ const resolveAssembly = ({ node, entityStore, }) => {
90
87
  const isAssembly = checkIsAssemblyNode({
91
88
  componentId: node.definitionId,
92
89
  usedComponents: entityStore.usedComponents,
@@ -99,23 +96,6 @@ const resolveAssembly = ({ node, parentPatternProperties, entityStore, }) => {
99
96
  if (!assembly || !('fields' in assembly)) {
100
97
  return node;
101
98
  }
102
- const patternProperties = {};
103
- const allPatternProperties = {
104
- ...parentPatternProperties,
105
- ...(node.patternProperties || {}),
106
- };
107
- for (const [patternPropertyKey, patternProperty] of Object.entries(allPatternProperties)) {
108
- /**
109
- * Bubbled up pattern properties are a concatenation of the node id
110
- * and the pattern property definition id. We need to split them so
111
- * that the node only uses the pattern property definition id.
112
- */
113
- const [nodeId, patternPropertyDefinitionId] = patternPropertyKey.split(PATTERN_PROPERTY_DIVIDER);
114
- const isMatchingNode = nodeId === node.id;
115
- if (!isMatchingNode)
116
- continue;
117
- patternProperties[patternPropertyDefinitionId] = patternProperty;
118
- }
119
99
  const componentFields = assembly.fields;
120
100
  const deserializedNode = deserializeAssemblyNode({
121
101
  node: {
@@ -123,11 +103,10 @@ const resolveAssembly = ({ node, parentPatternProperties, entityStore, }) => {
123
103
  id: node.id,
124
104
  variables: node.variables,
125
105
  children: componentFields.componentTree.children,
126
- patternProperties,
127
106
  },
128
107
  componentInstanceVariables: node.variables,
129
108
  componentSettings: componentFields.componentSettings,
130
- patternProperties,
109
+ patternProperties: node.patternProperties || {},
131
110
  });
132
111
  entityStore.addAssemblyUnboundValues(componentFields.unboundValues);
133
112
  return deserializedNode;
@@ -1 +1 @@
1
- {"version":3,"file":"assemblyUtils.js","sources":["../../../../src/core/preview/assemblyUtils.ts"],"sourcesContent":["import { checkIsAssemblyNode, EntityStore } from '@contentful/experiences-core';\nimport type {\n ComponentPropertyValue,\n ComponentTreeNode,\n DesignValue,\n ExperienceComponentSettings,\n PatternProperty,\n} from '@contentful/experiences-core/types';\nimport { resolvePrebindingPath, shouldUsePrebinding } from '../../utils/prebindingUtils';\nimport { PATTERN_PROPERTY_DIVIDER } from '@contentful/experiences-core/constants';\n\n/** While unfolding the assembly definition on the instance, this function will replace all\n * ComponentValue in the definitions tree with the actual value on the instance. */\nexport const deserializeAssemblyNode = ({\n node,\n componentInstanceVariables,\n componentSettings,\n patternProperties,\n}: {\n node: ComponentTreeNode;\n componentInstanceVariables: ComponentTreeNode['variables'];\n componentSettings: ExperienceComponentSettings;\n patternProperties: Record<string, PatternProperty>;\n}): ComponentTreeNode => {\n const variables: Record<string, ComponentPropertyValue> = {};\n\n for (const [variableName, variable] of Object.entries(node.variables)) {\n variables[variableName] = variable;\n if (variable.type === 'ComponentValue') {\n const componentValueKey = variable.key;\n const instanceProperty = componentInstanceVariables[componentValueKey];\n const variableDefinition = componentSettings.variableDefinitions?.[componentValueKey];\n const defaultValue = variableDefinition?.defaultValue;\n\n const usePrebinding = shouldUsePrebinding({\n componentSettings,\n componentValueKey,\n patternProperties,\n variable: instanceProperty,\n });\n const path = resolvePrebindingPath({\n componentSettings,\n componentValueKey,\n patternProperties,\n });\n\n if (usePrebinding && path) {\n variables[variableName] = {\n type: 'BoundValue',\n path,\n };\n\n // For assembly, we look up the variable in the assembly instance and\n // replace the ComponentValue with that one.\n } else if (instanceProperty?.type === 'UnboundValue') {\n variables[variableName] = {\n type: 'UnboundValue',\n key: instanceProperty.key,\n };\n } else if (instanceProperty?.type === 'NoValue') {\n variables[variableName] = instanceProperty;\n } else if (instanceProperty?.type === 'BoundValue') {\n variables[variableName] = {\n type: 'BoundValue',\n path: instanceProperty.path,\n };\n } else if (instanceProperty?.type === 'HyperlinkValue') {\n variables[variableName] = {\n type: 'HyperlinkValue',\n linkTargetKey: instanceProperty.linkTargetKey,\n };\n } else if (instanceProperty?.type === 'DesignValue') {\n variables[variableName] = {\n type: 'DesignValue',\n valuesByBreakpoint: instanceProperty.valuesByBreakpoint,\n };\n } else if (!instanceProperty && defaultValue) {\n // So far, we only automatically fallback to the defaultValue for design properties\n if (variableDefinition.group === 'style') {\n variables[variableName] = {\n type: 'DesignValue',\n valuesByBreakpoint: (defaultValue as DesignValue).valuesByBreakpoint,\n };\n }\n }\n }\n }\n\n const children: ComponentTreeNode[] = node.children.map((child) =>\n deserializeAssemblyNode({\n node: child,\n componentInstanceVariables,\n componentSettings,\n patternProperties,\n }),\n );\n\n return {\n definitionId: node.definitionId,\n id: node.id,\n variables,\n children,\n slotId: node.slotId,\n displayName: node.displayName,\n patternProperties: node.patternProperties,\n };\n};\n\nexport const resolveAssembly = ({\n node,\n parentPatternProperties,\n entityStore,\n}: {\n node: ComponentTreeNode;\n entityStore: EntityStore;\n parentPatternProperties: Record<string, PatternProperty>;\n}) => {\n const isAssembly = checkIsAssemblyNode({\n componentId: node.definitionId,\n usedComponents: entityStore.usedComponents,\n });\n\n if (!isAssembly) {\n return node;\n }\n\n const componentId = node.definitionId as string;\n const assembly = entityStore.usedComponents?.find(\n (component) => component.sys.id === componentId,\n );\n\n if (!assembly || !('fields' in assembly)) {\n return node;\n }\n\n const patternProperties: Record<string, PatternProperty> = {};\n\n const allPatternProperties = {\n ...parentPatternProperties,\n ...(node.patternProperties || {}),\n };\n\n for (const [patternPropertyKey, patternProperty] of Object.entries(allPatternProperties)) {\n /**\n * Bubbled up pattern properties are a concatenation of the node id\n * and the pattern property definition id. We need to split them so\n * that the node only uses the pattern property definition id.\n */\n const [nodeId, patternPropertyDefinitionId] =\n patternPropertyKey.split(PATTERN_PROPERTY_DIVIDER);\n\n const isMatchingNode = nodeId === node.id;\n\n if (!isMatchingNode) continue;\n\n patternProperties[patternPropertyDefinitionId] = patternProperty;\n }\n\n const componentFields = assembly.fields;\n\n const deserializedNode = deserializeAssemblyNode({\n node: {\n definitionId: node.definitionId,\n id: node.id,\n variables: node.variables,\n children: componentFields.componentTree.children,\n patternProperties,\n },\n componentInstanceVariables: node.variables,\n componentSettings: componentFields.componentSettings!,\n patternProperties,\n });\n\n entityStore.addAssemblyUnboundValues(componentFields.unboundValues);\n\n return deserializedNode;\n};\n"],"names":[],"mappings":";;;;AAWA;AACmF;AAC5E,MAAM,uBAAuB,GAAG,CAAC,EACtC,IAAI,EACJ,0BAA0B,EAC1B,iBAAiB,EACjB,iBAAiB,GAMlB,KAAuB;IACtB,MAAM,SAAS,GAA2C,EAAE,CAAC;AAE7D,IAAA,KAAK,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACrE,QAAA,SAAS,CAAC,YAAY,CAAC,GAAG,QAAQ,CAAC;AACnC,QAAA,IAAI,QAAQ,CAAC,IAAI,KAAK,gBAAgB,EAAE;AACtC,YAAA,MAAM,iBAAiB,GAAG,QAAQ,CAAC,GAAG,CAAC;AACvC,YAAA,MAAM,gBAAgB,GAAG,0BAA0B,CAAC,iBAAiB,CAAC,CAAC;YACvE,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,mBAAmB,GAAG,iBAAiB,CAAC,CAAC;AACtF,YAAA,MAAM,YAAY,GAAG,kBAAkB,EAAE,YAAY,CAAC;YAEtD,MAAM,aAAa,GAAG,mBAAmB,CAAC;gBACxC,iBAAiB;gBACjB,iBAAiB;gBACjB,iBAAiB;AACjB,gBAAA,QAAQ,EAAE,gBAAgB;AAC3B,aAAA,CAAC,CAAC;YACH,MAAM,IAAI,GAAG,qBAAqB,CAAC;gBACjC,iBAAiB;gBACjB,iBAAiB;gBACjB,iBAAiB;AAClB,aAAA,CAAC,CAAC;AAEH,YAAA,IAAI,aAAa,IAAI,IAAI,EAAE;gBACzB,SAAS,CAAC,YAAY,C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,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE;AACxF;;;;AAIG;AACH,QAAA,MAAM,CAAC,MAAM,EAAE,2BAA2B,CAAC,GACzC,kBAAkB,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;AAErD,QAAA,MAAM,cAAc,GAAG,MAAM,KAAK,IAAI,CAAC,EAAE,CAAC;AAE1C,QAAA,IAAI,CAAC,cAAc;YAAE,SAAS;AAE9B,QAAA,iBAAiB,CAAC,2BAA2B,CAAC,GAAG,eAAe,CAAC;KAClE;AAED,IAAA,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC;IAExC,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AAC/C,QAAA,IAAI,EAAE;YACJ,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,SAAS,EAAE,IAAI,CAAC,SAAS;AACzB,YAAA,QAAQ,EAAE,eAAe,CAAC,aAAa,CAAC,QAAQ;YAChD,iBAAiB;AAClB,SAAA;QACD,0BAA0B,EAAE,IAAI,CAAC,SAAS;QAC1C,iBAAiB,EAAE,eAAe,CAAC,iBAAkB;QACrD,iBAAiB;AAClB,KAAA,CAAC,CAAC;AAEH,IAAA,WAAW,CAAC,wBAAwB,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;AAEpE,IAAA,OAAO,gBAAgB,CAAC;AAC1B;;;;"}
1
+ {"version":3,"file":"assemblyUtils.js","sources":["../../../../src/core/preview/assemblyUtils.ts"],"sourcesContent":["import { checkIsAssemblyNode, EntityStore } from '@contentful/experiences-core';\nimport type {\n ComponentPropertyValue,\n ComponentTreeNode,\n DesignValue,\n ExperienceComponentSettings,\n PatternProperty,\n} from '@contentful/experiences-core/types';\nimport { resolvePrebindingPath, shouldUsePrebinding } from '../../utils/prebindingUtils';\n\n/** While unfolding the assembly definition on the instance, this function will replace all\n * ComponentValue in the definitions tree with the actual value on the instance. */\nexport const deserializeAssemblyNode = ({\n node,\n componentInstanceVariables,\n componentSettings,\n patternProperties,\n}: {\n node: ComponentTreeNode;\n componentInstanceVariables: ComponentTreeNode['variables'];\n componentSettings: ExperienceComponentSettings;\n patternProperties: Record<string, PatternProperty>;\n}): ComponentTreeNode => {\n const variables: Record<string, ComponentPropertyValue> = {};\n\n for (const [variableName, variable] of Object.entries(node.variables)) {\n variables[variableName] = variable;\n if (variable.type === 'ComponentValue') {\n const componentValueKey = variable.key;\n const instanceProperty = componentInstanceVariables[componentValueKey];\n const variableDefinition = componentSettings.variableDefinitions?.[componentValueKey];\n const defaultValue = variableDefinition?.defaultValue;\n\n const usePrebinding = shouldUsePrebinding({\n componentSettings,\n componentValueKey,\n patternProperties,\n variable: instanceProperty,\n });\n\n if (usePrebinding) {\n const path = resolvePrebindingPath({\n componentSettings,\n componentValueKey,\n patternProperties,\n });\n\n if (path) {\n variables[variableName] = {\n type: 'BoundValue',\n path,\n };\n }\n\n // For assembly, we look up the variable in the assembly instance and\n // replace the ComponentValue with that one.\n } else if (instanceProperty?.type === 'UnboundValue') {\n variables[variableName] = {\n type: 'UnboundValue',\n key: instanceProperty.key,\n };\n } else if (instanceProperty?.type === 'BoundValue') {\n variables[variableName] = {\n type: 'BoundValue',\n path: instanceProperty.path,\n };\n } else if (instanceProperty?.type === 'HyperlinkValue') {\n variables[variableName] = {\n type: 'HyperlinkValue',\n linkTargetKey: instanceProperty.linkTargetKey,\n };\n } else if (instanceProperty?.type === 'DesignValue') {\n variables[variableName] = {\n type: 'DesignValue',\n valuesByBreakpoint: instanceProperty.valuesByBreakpoint,\n };\n } else if (!instanceProperty && defaultValue) {\n // So far, we only automatically fallback to the defaultValue for design properties\n if (variableDefinition.group === 'style') {\n variables[variableName] = {\n type: 'DesignValue',\n valuesByBreakpoint: (defaultValue as DesignValue).valuesByBreakpoint,\n };\n }\n }\n }\n }\n\n const children: ComponentTreeNode[] = node.children.map((child) =>\n deserializeAssemblyNode({\n node: child,\n componentInstanceVariables,\n componentSettings,\n patternProperties,\n }),\n );\n\n return {\n definitionId: node.definitionId,\n id: node.id,\n variables,\n children,\n slotId: node.slotId,\n displayName: node.displayName,\n };\n};\n\nexport const resolveAssembly = ({\n node,\n entityStore,\n}: {\n node: ComponentTreeNode;\n entityStore: EntityStore;\n}) => {\n const isAssembly = checkIsAssemblyNode({\n componentId: node.definitionId,\n usedComponents: entityStore.usedComponents,\n });\n\n if (!isAssembly) {\n return node;\n }\n\n const componentId = node.definitionId as string;\n const assembly = entityStore.usedComponents?.find(\n (component) => component.sys.id === componentId,\n );\n\n if (!assembly || !('fields' in assembly)) {\n return node;\n }\n\n const componentFields = assembly.fields;\n\n const deserializedNode = deserializeAssemblyNode({\n node: {\n definitionId: node.definitionId,\n id: node.id,\n variables: node.variables,\n children: componentFields.componentTree.children,\n },\n componentInstanceVariables: node.variables,\n componentSettings: componentFields.componentSettings!,\n patternProperties: node.patternProperties || {},\n });\n\n entityStore.addAssemblyUnboundValues(componentFields.unboundValues);\n\n return deserializedNode;\n};\n"],"names":[],"mappings":";;;AAUA;AACmF;AAC5E,MAAM,uBAAuB,GAAG,CAAC,EACtC,IAAI,EACJ,0BAA0B,EAC1B,iBAAiB,EACjB,iBAAiB,GAMlB,KAAuB;IACtB,MAAM,SAAS,GAA2C,EAAE,CAAC;AAE7D,IAAA,KAAK,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACrE,QAAA,SAAS,CAAC,YAAY,CAAC,GAAG,QAAQ,CAAC;AACnC,QAAA,IAAI,QAAQ,CAAC,IAAI,KAAK,gBAAgB,EAAE;AACtC,YAAA,MAAM,iBAAiB,GAAG,QAAQ,CAAC,GAAG,CAAC;AACvC,YAAA,MAAM,gBAAgB,GAAG,0BAA0B,CAAC,iBAAiB,CAAC,CAAC;YACvE,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,mBAAmB,GAAG,iBAAiB,CAAC,CAAC;AACt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Ae,GAAG,QAAQ,CAAC,MAAM,CAAC;IAExC,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AAC/C,QAAA,IAAI,EAAE;YACJ,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,SAAS,EAAE,IAAI,CAAC,SAAS;AACzB,YAAA,QAAQ,EAAE,eAAe,CAAC,aAAa,CAAC,QAAQ;AACjD,SAAA;QACD,0BAA0B,EAAE,IAAI,CAAC,SAAS;QAC1C,iBAAiB,EAAE,eAAe,CAAC,iBAAkB;AACrD,QAAA,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,IAAI,EAAE;AAChD,KAAA,CAAC,CAAC;AAEH,IAAA,WAAW,CAAC,wBAAwB,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;AAEpE,IAAA,OAAO,gBAAgB,CAAC;AAC1B;;;;"}
@@ -0,0 +1,24 @@
1
+ import { useCallback } from 'react';
2
+ import { useFetchByBase } from './useFetchByBase.js';
3
+ import { useDetectCanvasMode } from './useDetectCanvasMode.js';
4
+
5
+ /**
6
+ * A hook that allows specifying a custom fetch function to retrieve an experience with all its references.
7
+ * @param options.fetchFn - A function that returns a promise resolving to an experience instance created with `createExperience()`
8
+ * @param options.hyperlinkPattern - URL Pattern for generating links for hyperlink properties on nodes pointing to other experience pages
9
+ * @returns loading state, error message, and the experience instance that needs to be passed to `<ExperienceRoot>`
10
+ */
11
+ const useCustomFetch = ({ fetchFn, hyperlinkPattern }) => {
12
+ const mode = useDetectCanvasMode({ isClientSide: typeof window !== 'undefined' });
13
+ const fetchMethod = useCallback(() => {
14
+ return fetchFn();
15
+ // we purposely don't want to include the client in the dependencies as it can cause infinite loops if the
16
+ // user creates the client in the component
17
+ // eslint-disable-next-line react-hooks/exhaustive-deps
18
+ }, []);
19
+ const fetchResult = useFetchByBase(fetchMethod, mode);
20
+ return { ...fetchResult, experience: { ...fetchResult.experience, hyperlinkPattern } };
21
+ };
22
+
23
+ export { useCustomFetch };
24
+ //# sourceMappingURL=useCustomFetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCustomFetch.js","sources":["../../../src/hooks/useCustomFetch.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useFetchByBase } from './useFetchByBase';\nimport { useDetectCanvasMode } from './useDetectCanvasMode';\nimport { Experience } from '@contentful/experiences-core/types';\nimport { EntityStore } from '@contentful/experiences-core';\n\nexport type UseCustomFetchArgs = {\n fetchFn: () => Promise<Experience<EntityStore> | undefined>;\n /** The pattern being used to generate links for hyperlink properties **/\n hyperlinkPattern?: string;\n};\n\n/**\n * A hook that allows specifying a custom fetch function to retrieve an experience with all its references.\n * @param options.fetchFn - A function that returns a promise resolving to an experience instance created with `createExperience()`\n * @param options.hyperlinkPattern - URL Pattern for generating links for hyperlink properties on nodes pointing to other experience pages\n * @returns loading state, error message, and the experience instance that needs to be passed to `<ExperienceRoot>`\n */\nexport const useCustomFetch = ({ fetchFn, hyperlinkPattern }: UseCustomFetchArgs) => {\n const mode = useDetectCanvasMode({ isClientSide: typeof window !== 'undefined' });\n\n const fetchMethod = useCallback(() => {\n return fetchFn();\n // we purposely don't want to include the client in the dependencies as it can cause infinite loops if the\n // user creates the client in the component\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const fetchResult = useFetchByBase(fetchMethod, mode);\n\n return { ...fetchResult, experience: { ...fetchResult.experience, hyperlinkPattern } };\n};\n"],"names":[],"mappings":";;;;AAYA;;;;;AAKG;AACU,MAAA,cAAc,GAAG,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAsB,KAAI;AAClF,IAAA,MAAM,IAAI,GAAG,mBAAmB,CAAC,EAAE,YAAY,EAAE,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC,CAAC;AAElF,IAAA,MAAM,WAAW,GAAG,WAAW,CAAC,MAAK;QACnC,OAAO,OAAO,EAAE,CAAC;;;;KAIlB,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,WAAW,GAAG,cAAc,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AAEtD,IAAA,OAAO,EAAE,GAAG,WAAW,EAAE,UAAU,EAAE,EAAE,GAAG,WAAW,CAAC,UAAU,EAAE,gBAAgB,EAAE,EAAE,CAAC;AACzF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useFetchByBase.js","sources":["../../../src/hooks/useFetchByBase.ts"],"sourcesContent":["'use client';\nimport { useEffect, useState } from 'react';\nimport { EntityStore } from '@contentful/experiences-core';\nimport type { Experience } from '@contentful/experiences-core/types';\nimport { StudioCanvasMode } from '@contentful/experiences-core/constants';\n\nexport const useFetchByBase = (\n fetchMethod: () => Promise<Experience<EntityStore> | undefined>,\n mode: StudioCanvasMode,\n) => {\n const [experience, setExperience] = useState<Experience<EntityStore>>();\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error>();\n\n useEffect(() => {\n (async () => {\n // if we are in editor/read only mode, we don't want to fetch the experience here\n // it is passed via postMessage instead\n if (mode === StudioCanvasMode.EDITOR || mode === StudioCanvasMode.READ_ONLY) {\n return;\n }\n setIsLoading(true);\n setError(undefined);\n try {\n const exp = await fetchMethod();\n setExperience(exp);\n } catch (error) {\n setError(error as Error);\n } finally {\n setIsLoading(false);\n }\n })();\n }, [fetchMethod, mode]);\n\n // When a save event caused a canvas reload, the `receivedModeMessage` might time out and set the\n // mode temporarily to NONE. If it's set to a valid mode afterward, we ignore the fetch result.\n if (mode === StudioCanvasMode.EDITOR || mode === StudioCanvasMode.READ_ONLY) {\n return {\n error: undefined,\n experience: undefined,\n isLoading: false,\n mode,\n };\n }\n\n return {\n error,\n experience,\n isLoading,\n mode,\n };\n};\n"],"names":[],"mappings":";;;;;;;;;;;;AAkBM;;;;;AAKA;AACE;;;;;;;;;;AAQN;;;AAIA;;AAEI;AACA;AACA;;;;;;;;;;AAWN;;"}
1
+ {"version":3,"file":"useFetchByBase.js","sources":["../../../src/hooks/useFetchByBase.ts"],"sourcesContent":["'use client';\nimport { useEffect, useState } from 'react';\nimport { EntityStore } from '@contentful/experiences-core';\nimport type { Experience } from '@contentful/experiences-core/types';\nimport { StudioCanvasMode } from '@contentful/experiences-core/constants';\n\n// Typing the response explicitly ensures a stable interface for all fetchers\n// and creates more readable type definitions for the SDK consumers.\ntype UseFetchByBaseResponse = {\n error: Error | undefined;\n experience: Experience<EntityStore> | undefined;\n isLoading: boolean;\n mode: StudioCanvasMode;\n};\n\nexport const useFetchByBase = (\n fetchMethod: () => Promise<Experience<EntityStore> | undefined>,\n mode: StudioCanvasMode,\n): UseFetchByBaseResponse => {\n const [experience, setExperience] = useState<Experience<EntityStore>>();\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error>();\n\n useEffect(() => {\n (async () => {\n // if we are in editor/read only mode, we don't want to fetch the experience here\n // it is passed via postMessage instead\n if (mode === StudioCanvasMode.EDITOR || mode === StudioCanvasMode.READ_ONLY) {\n return;\n }\n setIsLoading(true);\n setError(undefined);\n try {\n const exp = await fetchMethod();\n setExperience(exp);\n } catch (error) {\n setError(error as Error);\n } finally {\n setIsLoading(false);\n }\n })();\n }, [fetchMethod, mode]);\n\n // When a save event caused a canvas reload, the `receivedModeMessage` might time out and set the\n // mode temporarily to NONE. If it's set to a valid mode afterward, we ignore the fetch result.\n if (mode === StudioCanvasMode.EDITOR || mode === StudioCanvasMode.READ_ONLY) {\n return {\n error: undefined,\n experience: undefined,\n isLoading: false,\n mode,\n };\n }\n\n return {\n error,\n experience,\n isLoading,\n mode,\n };\n};\n"],"names":[],"mappings":";;;;;;;;;;;;AA2BM;;;;;AAKA;AACE;;;;;;;;;;AAQN;;;AAIA;;AAEI;AACA;AACA;;;;;;;;;;AAWN;;"}
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as _contentful_experiences_core from '@contentful/experiences-core';
3
3
  import { EntityStore, VisualEditorMode } from '@contentful/experiences-core';
4
- export { VisualEditorMode, createExperience, defineBreakpoints, defineDesignTokens, detachExperienceStyles, fetchById, fetchBySlug } from '@contentful/experiences-core';
4
+ export { VisualEditorMode, createExperience, defineBreakpoints, defineDesignTokens, detachExperienceStyles, fetchById, fetchBySlug, fetchExperienceEntry, fetchReferencedEntities, localizeEntity } from '@contentful/experiences-core';
5
5
  import { Experience, ComponentRegistration, ComponentRegistrationOptions } from '@contentful/experiences-core/types';
6
6
  export { ComponentDefinition, ComponentRegistration, Experience } from '@contentful/experiences-core/types';
7
7
  import * as _contentful_experiences_core_constants from '@contentful/experiences-core/constants';
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.35.0-dev-20250324T2005-a11cb8e.0";
11
+ declare const SDK_VERSION = "1.35.0-prerelease-20250414T1325-5725f29.0";
12
12
 
13
13
  type ExperienceRootProps = {
14
14
  experience?: Experience<EntityStore> | string | null;
@@ -31,21 +31,13 @@ type UseFetchByIdArgs = {
31
31
  hyperlinkPattern?: string;
32
32
  };
33
33
  declare const useFetchById: ({ id, localeCode, client, experienceTypeId, hyperlinkPattern, }: UseFetchByIdArgs) => {
34
- experience: {
35
- hyperlinkPattern: string | undefined;
36
- entityStore?: _contentful_experiences_core.EntityStore | undefined;
37
- };
38
- error: undefined;
39
- isLoading: boolean;
40
- mode: _contentful_experiences_core_constants.StudioCanvasMode.READ_ONLY | _contentful_experiences_core_constants.StudioCanvasMode.EDITOR;
41
- } | {
42
34
  experience: {
43
35
  hyperlinkPattern: string | undefined;
44
36
  entityStore?: _contentful_experiences_core.EntityStore | undefined;
45
37
  };
46
38
  error: Error | undefined;
47
39
  isLoading: boolean;
48
- mode: _contentful_experiences_core_constants.StudioCanvasMode.NONE;
40
+ mode: _contentful_experiences_core_constants.StudioCanvasMode;
49
41
  };
50
42
 
51
43
  type UseFetchBySlugArgs = {
@@ -61,17 +53,30 @@ declare const useFetchBySlug: ({ slug, localeCode, client, experienceTypeId, hyp
61
53
  hyperlinkPattern: string | undefined;
62
54
  entityStore?: _contentful_experiences_core.EntityStore | undefined;
63
55
  };
64
- error: undefined;
56
+ error: Error | undefined;
65
57
  isLoading: boolean;
66
- mode: _contentful_experiences_core_constants.StudioCanvasMode.READ_ONLY | _contentful_experiences_core_constants.StudioCanvasMode.EDITOR;
67
- } | {
58
+ mode: _contentful_experiences_core_constants.StudioCanvasMode;
59
+ };
60
+
61
+ type UseCustomFetchArgs = {
62
+ fetchFn: () => Promise<Experience<EntityStore> | undefined>;
63
+ /** The pattern being used to generate links for hyperlink properties **/
64
+ hyperlinkPattern?: string;
65
+ };
66
+ /**
67
+ * A hook that allows specifying a custom fetch function to retrieve an experience with all its references.
68
+ * @param options.fetchFn - A function that returns a promise resolving to an experience instance created with `createExperience()`
69
+ * @param options.hyperlinkPattern - URL Pattern for generating links for hyperlink properties on nodes pointing to other experience pages
70
+ * @returns loading state, error message, and the experience instance that needs to be passed to `<ExperienceRoot>`
71
+ */
72
+ declare const useCustomFetch: ({ fetchFn, hyperlinkPattern }: UseCustomFetchArgs) => {
68
73
  experience: {
69
74
  hyperlinkPattern: string | undefined;
70
- entityStore?: _contentful_experiences_core.EntityStore | undefined;
75
+ entityStore?: EntityStore | undefined;
71
76
  };
72
77
  error: Error | undefined;
73
78
  isLoading: boolean;
74
- mode: _contentful_experiences_core_constants.StudioCanvasMode.NONE;
79
+ mode: _contentful_experiences_core_constants.StudioCanvasMode;
75
80
  };
76
81
 
77
82
  /**
@@ -89,4 +94,4 @@ declare const defineComponents: (componentRegistrations: ComponentRegistration[]
89
94
  */
90
95
  declare const maintainBasicComponentIdsWithoutPrefix: () => void;
91
96
 
92
- export { ExperienceRoot, defineComponents, maintainBasicComponentIdsWithoutPrefix, useFetchById, useFetchBySlug, SDK_VERSION as version };
97
+ export { ExperienceRoot, defineComponents, maintainBasicComponentIdsWithoutPrefix, useCustomFetch, useFetchById, useFetchBySlug, SDK_VERSION as version };
package/dist/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import { enableDebug, disableDebug } from '@contentful/experiences-core';
2
- export { VisualEditorMode, createExperience, defineBreakpoints, defineDesignTokens, detachExperienceStyles, fetchById, fetchBySlug } from '@contentful/experiences-core';
2
+ export { VisualEditorMode, createExperience, defineBreakpoints, defineDesignTokens, detachExperienceStyles, fetchById, fetchBySlug, fetchExperienceEntry, fetchReferencedEntities, localizeEntity } from '@contentful/experiences-core';
3
3
  import { SDK_VERSION } from './sdkVersion.js';
4
4
  export { ExperienceRoot } from './ExperienceRoot.js';
5
5
  import 'react';
6
6
  export { useFetchById } from './hooks/useFetchById.js';
7
7
  export { useFetchBySlug } from './hooks/useFetchBySlug.js';
8
+ export { useCustomFetch } from './hooks/useCustomFetch.js';
8
9
  export { defineComponents, maintainBasicComponentIdsWithoutPrefix } from './core/componentRegistry.js';
9
10
  export { CF_STYLE_ATTRIBUTES, CONTENTFUL_COMPONENTS, LATEST_SCHEMA_VERSION } from '@contentful/experiences-core/constants';
10
11
 
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { enableDebug, disableDebug } from '@contentful/experiences-core';\nimport { SDK_VERSION } from './sdkVersion';\nexport { SDK_VERSION as version };\n\nexport { ExperienceRoot } from './ExperienceRoot';\nexport { useFetchById, useFetchBySlug } from './hooks';\nexport { defineComponents, maintainBasicComponentIdsWithoutPrefix } from './core/componentRegistry';\nexport {\n defineDesignTokens,\n defineBreakpoints,\n VisualEditorMode,\n fetchById,\n fetchBySlug,\n createExperience,\n} from '@contentful/experiences-core';\nexport {\n CONTENTFUL_COMPONENTS,\n LATEST_SCHEMA_VERSION,\n CF_STYLE_ATTRIBUTES,\n} from '@contentful/experiences-core/constants';\n\n// Simple state store to store a few things that are needed across the SDK\nif (typeof window !== 'undefined') {\n if (!window.__EB__) {\n window.__EB__ = {};\n }\n window.__EB__.sdkVersion = SDK_VERSION;\n window.__EB__.enableDebug = enableDebug;\n window.__EB__.disableDebug = disableDebug;\n}\n\nexport type {\n Experience,\n ComponentDefinition,\n ComponentRegistration,\n} from '@contentful/experiences-core/types';\n\nexport { detachExperienceStyles } from '@contentful/experiences-core';\n"],"names":[],"mappings":";;;;;;;;;;AAqBA;AACA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AACjC,IAAA,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;AAClB,QAAA,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC;KACpB;AACD,IAAA,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,WAAW,CAAC;AACvC,IAAA,MAAM,CAAC,MAAM,CAAC,WAAW,GAAG,WAAW,CAAC;AACxC,IAAA,MAAM,CAAC,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;AAC5C;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { enableDebug, disableDebug } from '@contentful/experiences-core';\nimport { SDK_VERSION } from './sdkVersion';\nexport { SDK_VERSION as version };\n\nexport { ExperienceRoot } from './ExperienceRoot';\nexport { useFetchById, useFetchBySlug, useCustomFetch } from './hooks';\nexport { defineComponents, maintainBasicComponentIdsWithoutPrefix } from './core/componentRegistry';\nexport {\n defineDesignTokens,\n defineBreakpoints,\n VisualEditorMode,\n fetchById,\n fetchBySlug,\n createExperience,\n detachExperienceStyles,\n fetchReferencedEntities,\n fetchExperienceEntry,\n localizeEntity,\n} from '@contentful/experiences-core';\nexport {\n CONTENTFUL_COMPONENTS,\n LATEST_SCHEMA_VERSION,\n CF_STYLE_ATTRIBUTES,\n} from '@contentful/experiences-core/constants';\nexport type {\n Experience,\n ComponentDefinition,\n ComponentRegistration,\n} from '@contentful/experiences-core/types';\n\n// Simple state store to store a few things that are needed across the SDK\nif (typeof window !== 'undefined') {\n if (!window.__EB__) {\n window.__EB__ = {};\n }\n window.__EB__.sdkVersion = SDK_VERSION;\n window.__EB__.enableDebug = enableDebug;\n window.__EB__.disableDebug = disableDebug;\n}\n"],"names":[],"mappings":";;;;;;;;;;;AA8BA;AACA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AACjC,IAAA,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;AAClB,QAAA,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC;KACpB;AACD,IAAA,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,WAAW,CAAC;AACvC,IAAA,MAAM,CAAC,MAAM,CAAC,WAAW,GAAG,WAAW,CAAC;AACxC,IAAA,MAAM,CAAC,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;AAC5C;;;;"}
@@ -1,4 +1,4 @@
1
- const SDK_VERSION = '1.35.0-dev-20250324T2005-a11cb8e.0';
1
+ const SDK_VERSION = '1.35.0-prerelease-20250414T1325-5725f29.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.35.0-dev-20250324T2005-a11cb8e.0';\n"],"names":[],"mappings":"AAAO,MAAM,WAAW,GAAG;;;;"}
1
+ {"version":3,"file":"sdkVersion.js","sources":["../../src/sdkVersion.ts"],"sourcesContent":["export const SDK_VERSION = '1.35.0-prerelease-20250414T1325-5725f29.0';\n"],"names":[],"mappings":"AAAO,MAAM,WAAW,GAAG;;;;"}
@@ -1,5 +1,5 @@
1
1
  import { EntityStore } from '@contentful/experiences-core';
2
- import type { ComponentTreeNode, PatternProperty, ResolveDesignValueType } from '@contentful/experiences-core/types';
2
+ import type { ComponentTreeNode, ResolveDesignValueType } from '@contentful/experiences-core/types';
3
3
  type CompositionBlockProps = {
4
4
  node: ComponentTreeNode;
5
5
  locale: string;
@@ -13,7 +13,6 @@ type CompositionBlockProps = {
13
13
  * when storing & accessing cfSsrClassName.
14
14
  */
15
15
  patternNodeIdsChain?: string;
16
- wrappingPatternProperties?: Record<string, PatternProperty>;
17
16
  };
18
- export declare const CompositionBlock: ({ node: rawNode, locale, entityStore, hyperlinkPattern, resolveDesignValue, getPatternChildNodeClassName, wrappingPatternIds: parentWrappingPatternIds, wrappingPatternProperties: parentWrappingPatternProperties, patternNodeIdsChain, }: CompositionBlockProps) => import("react/jsx-runtime").JSX.Element | null;
17
+ export declare const CompositionBlock: ({ node: rawNode, locale, entityStore, hyperlinkPattern, resolveDesignValue, getPatternChildNodeClassName, wrappingPatternIds: parentWrappingPatternIds, patternNodeIdsChain, }: CompositionBlockProps) => import("react/jsx-runtime").JSX.Element | null;
19
18
  export {};
@@ -8,8 +8,7 @@ export declare const deserializeAssemblyNode: ({ node, componentInstanceVariable
8
8
  componentSettings: ExperienceComponentSettings;
9
9
  patternProperties: Record<string, PatternProperty>;
10
10
  }) => ComponentTreeNode;
11
- export declare const resolveAssembly: ({ node, parentPatternProperties, entityStore, }: {
11
+ export declare const resolveAssembly: ({ node, entityStore, }: {
12
12
  node: ComponentTreeNode;
13
13
  entityStore: EntityStore;
14
- parentPatternProperties: Record<string, PatternProperty>;
15
14
  }) => ComponentTreeNode;
@@ -1,3 +1,4 @@
1
1
  export { useBreakpoints } from './useBreakpoints';
2
2
  export * from './useFetchById';
3
3
  export * from './useFetchBySlug';
4
+ export * from './useCustomFetch';
@@ -0,0 +1,22 @@
1
+ import { Experience } from '@contentful/experiences-core/types';
2
+ import { EntityStore } from '@contentful/experiences-core';
3
+ export type UseCustomFetchArgs = {
4
+ fetchFn: () => Promise<Experience<EntityStore> | undefined>;
5
+ /** The pattern being used to generate links for hyperlink properties **/
6
+ hyperlinkPattern?: string;
7
+ };
8
+ /**
9
+ * A hook that allows specifying a custom fetch function to retrieve an experience with all its references.
10
+ * @param options.fetchFn - A function that returns a promise resolving to an experience instance created with `createExperience()`
11
+ * @param options.hyperlinkPattern - URL Pattern for generating links for hyperlink properties on nodes pointing to other experience pages
12
+ * @returns loading state, error message, and the experience instance that needs to be passed to `<ExperienceRoot>`
13
+ */
14
+ export declare const useCustomFetch: ({ fetchFn, hyperlinkPattern }: UseCustomFetchArgs) => {
15
+ experience: {
16
+ hyperlinkPattern: string | undefined;
17
+ entityStore?: EntityStore | undefined;
18
+ };
19
+ error: Error | undefined;
20
+ isLoading: boolean;
21
+ mode: import("@contentful/experiences-core/constants").StudioCanvasMode;
22
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,14 +1,11 @@
1
1
  import { EntityStore } from '@contentful/experiences-core';
2
2
  import type { Experience } from '@contentful/experiences-core/types';
3
3
  import { StudioCanvasMode } from '@contentful/experiences-core/constants';
4
- export declare const useFetchByBase: (fetchMethod: () => Promise<Experience<EntityStore> | undefined>, mode: StudioCanvasMode) => {
5
- error: undefined;
6
- experience: undefined;
7
- isLoading: boolean;
8
- mode: StudioCanvasMode.READ_ONLY | StudioCanvasMode.EDITOR;
9
- } | {
4
+ type UseFetchByBaseResponse = {
10
5
  error: Error | undefined;
11
6
  experience: Experience<EntityStore> | undefined;
12
7
  isLoading: boolean;
13
- mode: StudioCanvasMode.NONE;
8
+ mode: StudioCanvasMode;
14
9
  };
10
+ export declare const useFetchByBase: (fetchMethod: () => Promise<Experience<EntityStore> | undefined>, mode: StudioCanvasMode) => UseFetchByBaseResponse;
11
+ export {};
@@ -7,19 +7,11 @@ export type UseFetchByIdArgs = {
7
7
  hyperlinkPattern?: string;
8
8
  };
9
9
  export declare const useFetchById: ({ id, localeCode, client, experienceTypeId, hyperlinkPattern, }: UseFetchByIdArgs) => {
10
- experience: {
11
- hyperlinkPattern: string | undefined;
12
- entityStore?: import("@contentful/experiences-core").EntityStore | undefined;
13
- };
14
- error: undefined;
15
- isLoading: boolean;
16
- mode: import("@contentful/experiences-core/constants").StudioCanvasMode.READ_ONLY | import("@contentful/experiences-core/constants").StudioCanvasMode.EDITOR;
17
- } | {
18
10
  experience: {
19
11
  hyperlinkPattern: string | undefined;
20
12
  entityStore?: import("@contentful/experiences-core").EntityStore | undefined;
21
13
  };
22
14
  error: Error | undefined;
23
15
  isLoading: boolean;
24
- mode: import("@contentful/experiences-core/constants").StudioCanvasMode.NONE;
16
+ mode: import("@contentful/experiences-core/constants").StudioCanvasMode;
25
17
  };
@@ -8,19 +8,11 @@ export type UseFetchBySlugArgs = {
8
8
  hyperlinkPattern?: string;
9
9
  };
10
10
  export declare const useFetchBySlug: ({ slug, localeCode, client, experienceTypeId, hyperlinkPattern, }: UseFetchBySlugArgs) => {
11
- experience: {
12
- hyperlinkPattern: string | undefined;
13
- entityStore?: import("@contentful/experiences-core").EntityStore | undefined;
14
- };
15
- error: undefined;
16
- isLoading: boolean;
17
- mode: import("@contentful/experiences-core/constants").StudioCanvasMode.READ_ONLY | import("@contentful/experiences-core/constants").StudioCanvasMode.EDITOR;
18
- } | {
19
11
  experience: {
20
12
  hyperlinkPattern: string | undefined;
21
13
  entityStore?: import("@contentful/experiences-core").EntityStore | undefined;
22
14
  };
23
15
  error: Error | undefined;
24
16
  isLoading: boolean;
25
- mode: import("@contentful/experiences-core/constants").StudioCanvasMode.NONE;
17
+ mode: import("@contentful/experiences-core/constants").StudioCanvasMode;
26
18
  };
@@ -1,9 +1,8 @@
1
1
  import { SDK_VERSION } from './sdkVersion';
2
2
  export { SDK_VERSION as version };
3
3
  export { ExperienceRoot } from './ExperienceRoot';
4
- export { useFetchById, useFetchBySlug } from './hooks';
4
+ export { useFetchById, useFetchBySlug, useCustomFetch } from './hooks';
5
5
  export { defineComponents, maintainBasicComponentIdsWithoutPrefix } from './core/componentRegistry';
6
- export { defineDesignTokens, defineBreakpoints, VisualEditorMode, fetchById, fetchBySlug, createExperience, } from '@contentful/experiences-core';
6
+ export { defineDesignTokens, defineBreakpoints, VisualEditorMode, fetchById, fetchBySlug, createExperience, detachExperienceStyles, fetchReferencedEntities, fetchExperienceEntry, localizeEntity, } from '@contentful/experiences-core';
7
7
  export { CONTENTFUL_COMPONENTS, LATEST_SCHEMA_VERSION, CF_STYLE_ATTRIBUTES, } from '@contentful/experiences-core/constants';
8
8
  export type { Experience, ComponentDefinition, ComponentRegistration, } from '@contentful/experiences-core/types';
9
- export { detachExperienceStyles } from '@contentful/experiences-core';
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.35.0-dev-20250324T2005-a11cb8e.0";
1
+ export declare const SDK_VERSION = "1.35.0-prerelease-20250414T1325-5725f29.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/experiences-sdk-react",
3
- "version": "1.35.0-dev-20250324T2005-a11cb8e.0",
3
+ "version": "1.35.0-prerelease-20250414T1325-5725f29.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.35.0-dev-20250324T2005-a11cb8e.0",
45
- "@contentful/experiences-core": "1.35.0-dev-20250324T2005-a11cb8e.0",
46
- "@contentful/experiences-validators": "1.35.0-dev-20250324T2005-a11cb8e.0",
47
- "@contentful/experiences-visual-editor-react": "1.35.0-dev-20250324T2005-a11cb8e.0",
44
+ "@contentful/experiences-components-react": "1.35.0-prerelease-20250414T1325-5725f29.0",
45
+ "@contentful/experiences-core": "1.35.0-prerelease-20250414T1325-5725f29.0",
46
+ "@contentful/experiences-validators": "1.35.0-prerelease-20250414T1325-5725f29.0",
47
+ "@contentful/experiences-visual-editor-react": "1.35.0-prerelease-20250414T1325-5725f29.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": "5b84528a3a59a5445773309f5271bb6fdae56ef5"
105
+ "gitHead": "353c5494f903fafb7c01821f002725bdbd119dbc"
106
106
  }