@contentful/experiences-sdk-react 3.3.0 → 3.3.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocks/preview/CompositionBlock.js +14 -27
- package/dist/blocks/preview/CompositionBlock.js.map +1 -1
- package/dist/core/componentRegistry.js +6 -1
- package/dist/core/componentRegistry.js.map +1 -1
- package/dist/hooks/useInitializeVisualEditor.js +2 -1
- package/dist/hooks/useInitializeVisualEditor.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/sdkVersion.js +1 -1
- package/dist/sdkVersion.js.map +1 -1
- package/dist/src/sdkVersion.d.ts +1 -1
- package/dist/utils/withComponentWrapper.js +15 -9
- package/dist/utils/withComponentWrapper.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
1
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import React, { useMemo } from 'react';
|
|
3
|
-
import { checkIsAssemblyNode, checkIsAssemblyEntry, transformBoundContentValue, resolveHyperlinkPattern, sanitizeNodeProps } from '@contentful/experiences-core';
|
|
3
|
+
import { checkIsAssemblyNode, checkIsAssemblyEntry, transformBoundContentValue, resolveHyperlinkPattern, splitDirectAndSlotChildren, sanitizeNodeProps } from '@contentful/experiences-core';
|
|
4
4
|
import { HYPERLINK_DEFAULT_PATTERN, CONTENTFUL_COMPONENTS } from '@contentful/experiences-core/constants';
|
|
5
5
|
import { getComponentRegistration, createAssemblyRegistration } from '../../core/componentRegistry.js';
|
|
6
6
|
import { useInjectStylesheet } from '../../hooks/useInjectStylesheet.js';
|
|
@@ -76,7 +76,6 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
|
|
|
76
76
|
return {
|
|
77
77
|
ssrProps,
|
|
78
78
|
props,
|
|
79
|
-
customDesignProps: {},
|
|
80
79
|
};
|
|
81
80
|
}
|
|
82
81
|
const ssrProps = {
|
|
@@ -125,28 +124,15 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
|
|
|
125
124
|
}
|
|
126
125
|
},
|
|
127
126
|
});
|
|
128
|
-
const slotsProps = {};
|
|
129
|
-
if (componentRegistration.definition.slots) {
|
|
130
|
-
for (const slotId in componentRegistration.definition.slots) {
|
|
131
|
-
const slotNode = node.children.find((child) => child.slotId === slotId);
|
|
132
|
-
if (slotNode) {
|
|
133
|
-
slotsProps[slotId] = (jsx(CompositionBlock, { node: slotNode, locale: locale, hyperlinkPattern: hyperlinkPattern, entityStore: entityStore, resolveDesignValue: resolveDesignValue, wrappingPatternIds: wrappingPatternIds, wrappingParameters: wrappingParameters, patternRootNodeIdsChain: patternRootNodeIdsChain }));
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
127
|
const props = {
|
|
138
128
|
className: ssrProps.cfSsrClassName ?? mediaQuery?.className,
|
|
139
129
|
...styleProps,
|
|
140
130
|
...contentProps,
|
|
141
131
|
...customDesignProps,
|
|
142
|
-
...slotsProps,
|
|
143
132
|
};
|
|
144
133
|
return {
|
|
145
134
|
ssrProps,
|
|
146
135
|
contentProps,
|
|
147
|
-
slotsProps,
|
|
148
|
-
styleProps,
|
|
149
|
-
customDesignProps,
|
|
150
136
|
mediaQuery,
|
|
151
137
|
props,
|
|
152
138
|
};
|
|
@@ -160,8 +146,6 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
|
|
|
160
146
|
resolveDesignValue,
|
|
161
147
|
hyperlinkPattern,
|
|
162
148
|
locale,
|
|
163
|
-
wrappingPatternIds,
|
|
164
|
-
wrappingParameters,
|
|
165
149
|
patternRootNodeIdsChain,
|
|
166
150
|
]);
|
|
167
151
|
// do not inject the stylesheet into the dom because it's already been done on the server side
|
|
@@ -186,20 +170,23 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
|
|
|
186
170
|
}
|
|
187
171
|
return getPatternChildNodeClassName?.(childNodeId);
|
|
188
172
|
};
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
173
|
+
const { slotNodesMap, directChildNodes } = splitDirectAndSlotChildren(node.children, componentRegistration.definition);
|
|
174
|
+
const renderChildNode = (childNode) => (jsx(CompositionBlock, { getPatternChildNodeClassName: isPatternNode || getPatternChildNodeClassName ? _getPatternChildNodeClassName : undefined, node: childNode, locale: locale, hyperlinkPattern: hyperlinkPattern, entityStore: entityStore, resolveDesignValue: resolveDesignValue, wrappingPatternIds: wrappingPatternIds, wrappingParameters: wrappingParameters, patternRootNodeIdsChain: patternRootNodeIdsChain }, childNode.id));
|
|
175
|
+
const renderedSlotNodesMap = Object.entries(slotNodesMap).reduce((acc, [slotId, nodes]) => {
|
|
176
|
+
if (nodes?.length) {
|
|
177
|
+
acc[slotId] = jsx(Fragment, { children: nodes.map((slotChildNode) => renderChildNode(slotChildNode)) });
|
|
178
|
+
}
|
|
179
|
+
return acc;
|
|
180
|
+
}, {});
|
|
181
|
+
const renderedChildren = directChildNodes?.map((childNode) => renderChildNode(childNode));
|
|
196
182
|
// TODO: we might be able to remove this special case as well by not dropping the two props in the sanitizeNodeProps function
|
|
197
183
|
if (isContainerOrSection(node.definitionId)) {
|
|
198
|
-
return (jsx(ContentfulContainer, { cfHyperlink: contentProps.cfHyperlink, cfOpenInNewTab: contentProps.cfOpenInNewTab, className: props.className, children:
|
|
184
|
+
return (jsx(ContentfulContainer, { cfHyperlink: contentProps.cfHyperlink, cfOpenInNewTab: contentProps.cfOpenInNewTab, className: props.className, children: renderedChildren }));
|
|
199
185
|
}
|
|
200
186
|
return React.createElement(component, {
|
|
201
187
|
...sanitizeNodeProps(props),
|
|
202
|
-
|
|
188
|
+
...renderedSlotNodesMap,
|
|
189
|
+
}, renderedChildren);
|
|
203
190
|
};
|
|
204
191
|
const isContainerOrSection = (nodeDefinitionId) => [CONTENTFUL_COMPONENTS.container.id, CONTENTFUL_COMPONENTS.section.id].includes(nodeDefinitionId);
|
|
205
192
|
|
|
@@ -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 { Entry } from 'contentful';\nimport {\n checkIsAssemblyEntry,\n checkIsAssemblyNode,\n EntityStore,\n resolveHyperlinkPattern,\n sanitizeNodeProps,\n transformBoundContentValue,\n} from '@contentful/experiences-core';\nimport {\n CONTENTFUL_COMPONENTS,\n HYPERLINK_DEFAULT_PATTERN,\n} from '@contentful/experiences-core/constants';\nimport type {\n ComponentTreeNode,\n DesignValue,\n Parameter,\n PrimitiveValue,\n ResolveDesignValueType,\n StyleProps,\n} from '@contentful/experiences-core/types';\nimport { createAssemblyRegistration, getComponentRegistration } from '../../core/componentRegistry';\nimport { useInjectStylesheet } from '../../hooks/useInjectStylesheet';\nimport { Assembly, ContentfulContainer } from '@contentful/experiences-components-react';\nimport { resolvePattern } from '../../core/preview/assemblyUtils';\nimport { resolveMaybePrebindingDefaultValuePath } from '../../utils/prebindingUtils';\nimport { parseComponentProps } from '../../utils/parseComponentProps';\n\ntype CompositionBlockProps = {\n node: ComponentTreeNode;\n locale: string;\n entityStore: EntityStore;\n hyperlinkPattern?: string | undefined;\n resolveDesignValue: ResolveDesignValueType;\n getPatternChildNodeClassName?: (childNodeId: string) => string | undefined;\n /** Set of definition IDs of wrapping patterns to prevent circular dependencies. */\n wrappingPatternIds?: Set<string>;\n /**\n * Chained IDs to ensure uniqueness across multiple instances of the same pattern\n * when storing & accessing cfSsrClassName.\n */\n patternRootNodeIdsChain?: string;\n wrappingParameters?: Record<string, Parameter>;\n};\n\nexport const CompositionBlock = ({\n node: rawNode,\n locale,\n entityStore,\n hyperlinkPattern,\n resolveDesignValue,\n getPatternChildNodeClassName,\n wrappingPatternIds: parentWrappingPatternIds = new Set(),\n wrappingParameters: parentWrappingParameters = {},\n patternRootNodeIdsChain: parentPatternRootNodeIdsChain = '',\n}: CompositionBlockProps) => {\n const isPatternNode = useMemo(() => {\n return checkIsAssemblyNode({\n componentId: rawNode.definitionId,\n usedComponents: entityStore.usedComponents,\n });\n }, [entityStore.usedComponents, rawNode.definitionId]);\n\n const isPatternEntry = useMemo(() => {\n return checkIsAssemblyEntry({ fields: entityStore.experienceEntryFields } as unknown as Entry);\n }, [entityStore]);\n\n const patternRootNodeIdsChain = useMemo(() => {\n if (isPatternNode) {\n // Pattern nodes are chained without a separator (following the format for prebinding/parameters)\n return `${parentPatternRootNodeIdsChain}${rawNode.id}`;\n }\n return parentPatternRootNodeIdsChain;\n }, [isPatternNode, parentPatternRootNodeIdsChain, rawNode.id]);\n\n const node = useMemo(() => {\n if (isPatternNode) {\n return resolvePattern({\n node: rawNode,\n entityStore,\n parentParameters: parentWrappingParameters,\n patternRootNodeIdsChain,\n });\n } else {\n return rawNode;\n }\n }, [entityStore, isPatternNode, rawNode, parentWrappingParameters, patternRootNodeIdsChain]);\n\n const wrappingPatternIds = useMemo(() => {\n if (isPatternNode) {\n return new Set([node.definitionId, ...parentWrappingPatternIds]);\n }\n return parentWrappingPatternIds;\n }, [isPatternNode, node, parentWrappingPatternIds]);\n\n // Merge the pattern properties of the current node with the parent's pattern properties\n // to ensure nested patterns receive relevant pattern properties that were bubbled up\n // during assembly serialization.\n const wrappingParameters = useMemo(() => {\n if (isPatternNode) {\n return { ...parentWrappingParameters, ...(rawNode.parameters || {}) };\n }\n return parentWrappingParameters;\n }, [isPatternNode, rawNode, parentWrappingParameters]);\n\n const componentRegistration = useMemo(() => {\n const registration = getComponentRegistration(node.definitionId as string);\n\n if (isPatternNode && !registration) {\n return createAssemblyRegistration({\n definitionId: node.definitionId as string,\n component: Assembly,\n });\n }\n return registration;\n }, [isPatternNode, node.definitionId]);\n\n const { ssrProps, contentProps, props, mediaQuery } = useMemo(() => {\n // In SSR, we store the className under breakpoints[0] which is resolved here to the actual string\n const cfSsrClassNameValues = node.variables.cfSsrClassName as DesignValue | undefined;\n const mainBreakpoint = entityStore.breakpoints[0];\n const cfSsrClassName = cfSsrClassNameValues?.valuesByBreakpoint?.[mainBreakpoint.id] as\n | string\n | undefined;\n\n // Don't enrich the assembly wrapper node with props\n if (!componentRegistration || isPatternNode) {\n const ssrProps = { cfSsrClassName };\n const props: Record<string, PrimitiveValue> = { className: cfSsrClassName };\n return {\n ssrProps,\n props,\n 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 patternRootNodeIdsChain,\n node,\n resolveDesignValue,\n resolveBoundValue: ({ binding, propertyName, dataType }) => {\n const [, uuid] = binding.path.split('/');\n const boundEntityLink = entityStore.dataSource[uuid] as UnresolvedLink<'Entry' | 'Asset'>;\n return transformBoundContentValue(\n node.variables,\n entityStore,\n boundEntityLink,\n resolveDesignValue,\n propertyName,\n dataType,\n binding.path,\n );\n },\n resolveHyperlinkValue: ({ linkTargetKey }) => {\n const boundEntity = entityStore.dataSource[linkTargetKey];\n const hyperlinkEntry = entityStore.getEntryOrAsset(boundEntity, linkTargetKey);\n\n return resolveHyperlinkPattern(\n componentRegistration.definition.hyperlinkPattern ||\n hyperlinkPattern ||\n HYPERLINK_DEFAULT_PATTERN,\n hyperlinkEntry as Entry,\n locale,\n );\n },\n resolveUnboundValue: ({ mappingKey, defaultValue }) => {\n return entityStore.unboundValues[mappingKey]?.value ?? defaultValue;\n },\n resolvePrebindingValue: ({ mappingKey, propertyName, dataType, resolveBoundValue }) => {\n if (isPatternEntry) {\n const path = resolveMaybePrebindingDefaultValuePath({\n componentValueKey: mappingKey,\n entityStore,\n });\n\n if (path) {\n return resolveBoundValue({\n propertyName,\n dataType,\n binding: {\n type: 'BoundValue',\n path,\n },\n });\n }\n }\n },\n });\n\n const 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 wrappingParameters={wrappingParameters}\n patternRootNodeIdsChain={patternRootNodeIdsChain}\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 isPatternEntry,\n entityStore,\n componentRegistration,\n isPatternNode,\n getPatternChildNodeClassName,\n resolveDesignValue,\n hyperlinkPattern,\n locale,\n wrappingPatternIds,\n wrappingParameters,\n patternRootNodeIdsChain,\n ]);\n\n // do not inject the stylesheet into the dom because it's already been done on the server side\n useInjectStylesheet(ssrProps.cfSsrClassName ? undefined : mediaQuery?.css);\n\n if (!componentRegistration) {\n return null;\n }\n\n // When detecting a circular dependency, we stop silently. The editor mode will render an actionable error.\n if (parentWrappingPatternIds.has(node.definitionId)) {\n return null;\n }\n\n const { component: component } = componentRegistration;\n\n // Retrieves the CSS class name for a given child node ID.\n const _getPatternChildNodeClassName = (childNodeId: string) => {\n if (isPatternNode) {\n const nodeIdsChain = `${patternRootNodeIdsChain}-${childNodeId}`;\n // @ts-expect-error -- property cfSsrClassName is a map (id to classNames) that is added during rendering in ssrStyles\n const classesForNode: DesignValue | undefined = node.variables.cfSsrClassName?.[nodeIdsChain];\n if (!classesForNode) return undefined;\n return resolveDesignValue(classesForNode.valuesByBreakpoint) as string;\n }\n return getPatternChildNodeClassName?.(childNodeId);\n };\n\n const children =\n componentRegistration.definition.children === true\n ? node.children.map((childNode: ComponentTreeNode, index) => {\n return (\n <CompositionBlock\n getPatternChildNodeClassName={\n isPatternNode || 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 wrappingParameters={wrappingParameters}\n patternRootNodeIdsChain={patternRootNodeIdsChain}\n />\n );\n })\n : null;\n\n // TODO: we might be able to remove this special case as well by not dropping the two props in the sanitizeNodeProps function\n if (isContainerOrSection(node.definitionId)) {\n return (\n <ContentfulContainer\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 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+Ca,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,kBAAkB,EAAE,wBAAwB,GAAG,EAAE,EACjD,uBAAuB,EAAE,6BAA6B,GAAG,EAAE,GACrC,KAAI;AA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AAoB,GAAG,CAC3B,gBAAwB,KAExB,CAAC,qBAAqB,CAAC,SAAS,CAAC,EAAE,EAAE,qBAAqB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,QAAQ,CAC7E,gBAAiE,CAClE;;;;"}
|
|
1
|
+
{"version":3,"file":"CompositionBlock.js","sources":["../../../../src/blocks/preview/CompositionBlock.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport type { UnresolvedLink } from 'contentful';\nimport { Entry } from 'contentful';\nimport {\n checkIsAssemblyEntry,\n checkIsAssemblyNode,\n EntityStore,\n resolveHyperlinkPattern,\n sanitizeNodeProps,\n transformBoundContentValue,\n splitDirectAndSlotChildren,\n} from '@contentful/experiences-core';\nimport {\n CONTENTFUL_COMPONENTS,\n HYPERLINK_DEFAULT_PATTERN,\n} from '@contentful/experiences-core/constants';\nimport type {\n ComponentTreeNode,\n DesignValue,\n Parameter,\n PrimitiveValue,\n ResolveDesignValueType,\n StyleProps,\n} from '@contentful/experiences-core/types';\nimport { createAssemblyRegistration, getComponentRegistration } from '../../core/componentRegistry';\nimport { useInjectStylesheet } from '../../hooks/useInjectStylesheet';\nimport { Assembly, ContentfulContainer } from '@contentful/experiences-components-react';\nimport { resolvePattern } from '../../core/preview/assemblyUtils';\nimport { resolveMaybePrebindingDefaultValuePath } from '../../utils/prebindingUtils';\nimport { parseComponentProps } from '../../utils/parseComponentProps';\n\ntype CompositionBlockProps = {\n node: ComponentTreeNode;\n locale: string;\n entityStore: EntityStore;\n hyperlinkPattern?: string | undefined;\n resolveDesignValue: ResolveDesignValueType;\n getPatternChildNodeClassName?: (childNodeId: string) => string | undefined;\n /** Set of definition IDs of wrapping patterns to prevent circular dependencies. */\n wrappingPatternIds?: Set<string>;\n /**\n * Chained IDs to ensure uniqueness across multiple instances of the same pattern\n * when storing & accessing cfSsrClassName.\n */\n patternRootNodeIdsChain?: string;\n wrappingParameters?: Record<string, Parameter>;\n};\n\nexport const CompositionBlock = ({\n node: rawNode,\n locale,\n entityStore,\n hyperlinkPattern,\n resolveDesignValue,\n getPatternChildNodeClassName,\n wrappingPatternIds: parentWrappingPatternIds = new Set(),\n wrappingParameters: parentWrappingParameters = {},\n patternRootNodeIdsChain: parentPatternRootNodeIdsChain = '',\n}: CompositionBlockProps) => {\n const isPatternNode = useMemo(() => {\n return checkIsAssemblyNode({\n componentId: rawNode.definitionId,\n usedComponents: entityStore.usedComponents,\n });\n }, [entityStore.usedComponents, rawNode.definitionId]);\n\n const isPatternEntry = useMemo(() => {\n return checkIsAssemblyEntry({ fields: entityStore.experienceEntryFields } as unknown as Entry);\n }, [entityStore]);\n\n const patternRootNodeIdsChain = useMemo(() => {\n if (isPatternNode) {\n // Pattern nodes are chained without a separator (following the format for prebinding/parameters)\n return `${parentPatternRootNodeIdsChain}${rawNode.id}`;\n }\n return parentPatternRootNodeIdsChain;\n }, [isPatternNode, parentPatternRootNodeIdsChain, rawNode.id]);\n\n const node = useMemo(() => {\n if (isPatternNode) {\n return resolvePattern({\n node: rawNode,\n entityStore,\n parentParameters: parentWrappingParameters,\n patternRootNodeIdsChain,\n });\n } else {\n return rawNode;\n }\n }, [entityStore, isPatternNode, rawNode, parentWrappingParameters, patternRootNodeIdsChain]);\n\n const wrappingPatternIds = useMemo(() => {\n if (isPatternNode) {\n return new Set([node.definitionId, ...parentWrappingPatternIds]);\n }\n return parentWrappingPatternIds;\n }, [isPatternNode, node, parentWrappingPatternIds]);\n\n // Merge the pattern properties of the current node with the parent's pattern properties\n // to ensure nested patterns receive relevant pattern properties that were bubbled up\n // during assembly serialization.\n const wrappingParameters = useMemo(() => {\n if (isPatternNode) {\n return { ...parentWrappingParameters, ...(rawNode.parameters || {}) };\n }\n return parentWrappingParameters;\n }, [isPatternNode, rawNode, parentWrappingParameters]);\n\n const componentRegistration = useMemo(() => {\n const registration = getComponentRegistration(node.definitionId as string);\n\n if (isPatternNode && !registration) {\n return createAssemblyRegistration({\n definitionId: node.definitionId as string,\n component: Assembly,\n });\n }\n return registration;\n }, [isPatternNode, node.definitionId]);\n\n const { ssrProps, contentProps, props, mediaQuery } = useMemo(() => {\n // In SSR, we store the className under breakpoints[0] which is resolved here to the actual string\n const cfSsrClassNameValues = node.variables.cfSsrClassName as DesignValue | undefined;\n const mainBreakpoint = entityStore.breakpoints[0];\n const cfSsrClassName = cfSsrClassNameValues?.valuesByBreakpoint?.[mainBreakpoint.id] as\n | string\n | undefined;\n\n // Don't enrich the assembly wrapper node with props\n if (!componentRegistration || isPatternNode) {\n const ssrProps = { cfSsrClassName };\n const props: Record<string, PrimitiveValue> = { className: cfSsrClassName };\n return {\n ssrProps,\n props,\n };\n }\n\n const ssrProps: Record<string, string | undefined> = {\n cfSsrClassName:\n node.id && getPatternChildNodeClassName\n ? getPatternChildNodeClassName(node.id)\n : cfSsrClassName,\n };\n\n const {\n contentProps = {},\n styleProps = {},\n customDesignProps = {},\n mediaQuery,\n } = parseComponentProps({\n breakpoints: entityStore.breakpoints,\n mainBreakpoint,\n componentDefinition: componentRegistration.definition,\n patternRootNodeIdsChain,\n node,\n resolveDesignValue,\n resolveBoundValue: ({ binding, propertyName, dataType }) => {\n const [, uuid] = binding.path.split('/');\n const boundEntityLink = entityStore.dataSource[uuid] as UnresolvedLink<'Entry' | 'Asset'>;\n return transformBoundContentValue(\n node.variables,\n entityStore,\n boundEntityLink,\n resolveDesignValue,\n propertyName,\n dataType,\n binding.path,\n );\n },\n resolveHyperlinkValue: ({ linkTargetKey }) => {\n const boundEntity = entityStore.dataSource[linkTargetKey];\n const hyperlinkEntry = entityStore.getEntryOrAsset(boundEntity, linkTargetKey);\n\n return resolveHyperlinkPattern(\n componentRegistration.definition.hyperlinkPattern ||\n hyperlinkPattern ||\n HYPERLINK_DEFAULT_PATTERN,\n hyperlinkEntry as Entry,\n locale,\n );\n },\n resolveUnboundValue: ({ mappingKey, defaultValue }) => {\n return entityStore.unboundValues[mappingKey]?.value ?? defaultValue;\n },\n resolvePrebindingValue: ({ mappingKey, propertyName, dataType, resolveBoundValue }) => {\n if (isPatternEntry) {\n const path = resolveMaybePrebindingDefaultValuePath({\n componentValueKey: mappingKey,\n entityStore,\n });\n\n if (path) {\n return resolveBoundValue({\n propertyName,\n dataType,\n binding: {\n type: 'BoundValue',\n path,\n },\n });\n }\n }\n },\n });\n\n const props: Record<string, PrimitiveValue> = {\n className: ssrProps.cfSsrClassName ?? mediaQuery?.className,\n ...styleProps,\n ...contentProps,\n ...customDesignProps,\n };\n\n return {\n ssrProps,\n contentProps,\n mediaQuery,\n props,\n };\n }, [\n node,\n isPatternEntry,\n entityStore,\n componentRegistration,\n isPatternNode,\n getPatternChildNodeClassName,\n resolveDesignValue,\n hyperlinkPattern,\n locale,\n patternRootNodeIdsChain,\n ]);\n\n // do not inject the stylesheet into the dom because it's already been done on the server side\n useInjectStylesheet(ssrProps.cfSsrClassName ? undefined : mediaQuery?.css);\n\n if (!componentRegistration) {\n return null;\n }\n\n // When detecting a circular dependency, we stop silently. The editor mode will render an actionable error.\n if (parentWrappingPatternIds.has(node.definitionId)) {\n return null;\n }\n\n const { component: component } = componentRegistration;\n\n // Retrieves the CSS class name for a given child node ID.\n const _getPatternChildNodeClassName = (childNodeId: string) => {\n if (isPatternNode) {\n const nodeIdsChain = `${patternRootNodeIdsChain}-${childNodeId}`;\n // @ts-expect-error -- property cfSsrClassName is a map (id to classNames) that is added during rendering in ssrStyles\n const classesForNode: DesignValue | undefined = node.variables.cfSsrClassName?.[nodeIdsChain];\n if (!classesForNode) return undefined;\n return resolveDesignValue(classesForNode.valuesByBreakpoint) as string;\n }\n return getPatternChildNodeClassName?.(childNodeId);\n };\n\n const { slotNodesMap, directChildNodes } = splitDirectAndSlotChildren(\n node.children,\n componentRegistration.definition,\n );\n\n const renderChildNode = (childNode: ComponentTreeNode) => (\n <CompositionBlock\n getPatternChildNodeClassName={\n isPatternNode || getPatternChildNodeClassName ? _getPatternChildNodeClassName : undefined\n }\n node={childNode}\n key={childNode.id}\n locale={locale}\n hyperlinkPattern={hyperlinkPattern}\n entityStore={entityStore}\n resolveDesignValue={resolveDesignValue}\n wrappingPatternIds={wrappingPatternIds}\n wrappingParameters={wrappingParameters}\n patternRootNodeIdsChain={patternRootNodeIdsChain}\n />\n );\n\n const renderedSlotNodesMap = Object.entries(slotNodesMap).reduce(\n (acc, [slotId, nodes]) => {\n if (nodes?.length) {\n acc[slotId] = <>{nodes.map((slotChildNode) => renderChildNode(slotChildNode))}</>;\n }\n return acc;\n },\n {} as Record<string, React.JSX.Element>,\n );\n\n const renderedChildren = directChildNodes?.map((childNode) => renderChildNode(childNode));\n\n // TODO: we might be able to remove this special case as well by not dropping the two props in the sanitizeNodeProps function\n if (isContainerOrSection(node.definitionId)) {\n return (\n <ContentfulContainer\n cfHyperlink={(contentProps as StyleProps).cfHyperlink}\n cfOpenInNewTab={(contentProps as StyleProps).cfOpenInNewTab}\n className={props.className as string | undefined}>\n {renderedChildren}\n </ContentfulContainer>\n );\n }\n\n return React.createElement(\n component,\n {\n ...sanitizeNodeProps(props),\n ...renderedSlotNodesMap,\n },\n renderedChildren,\n );\n};\n\nconst isContainerOrSection = (\n nodeDefinitionId: string,\n): nodeDefinitionId is 'contentful-container' | 'contentful-section' =>\n [CONTENTFUL_COMPONENTS.container.id, CONTENTFUL_COMPONENTS.section.id].includes(\n nodeDefinitionId as 'contentful-container' | 'contentful-section',\n );\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;AAgDa,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,kBAAkB,EAAE,wBAAwB,GAAG,EAAE,EACjD,uBAAuB,EAAE,6BAA6B,GAAG,EAAE,GACrC,KAAI;AAC1B,IAAA,MAAM,aAAa,GAAG,OAAO,CAAC,MAAK;AACjC,QAAA,OAAO,mBAAmB,CAAC;YACzB,WAAW,E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AAI;AACvB,QAAA,IAAI,KAAK,EAAE,MAAM,EAAE;YACjB,GAAG,CAAC,MAAM,CAAC,GAAGA,0BAAG,KAAK,CAAC,GAAG,CAAC,CAAC,aAAa,KAAK,eAAe,CAAC,aAAa,CAAC,CAAC,GAAI,CAAC;SACnF;AACD,QAAA,OAAO,GAAG,CAAC;KACZ,EACD,EAAuC,CACxC,CAAC;AAEF,IAAA,MAAM,gBAAgB,GAAG,gBAAgB,EAAE,GAAG,CAAC,CAAC,SAAS,KAAK,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;;AAG1F,IAAA,IAAI,oBAAoB,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE;QAC3C,QACEA,GAAC,CAAA,mBAAmB,EAClB,EAAA,WAAW,EAAG,YAA2B,CAAC,WAAW,EACrD,cAAc,EAAG,YAA2B,CAAC,cAAc,EAC3D,SAAS,EAAE,KAAK,CAAC,SAA+B,EAC/C,QAAA,EAAA,gBAAgB,EACG,CAAA,EACtB;KACH;AAED,IAAA,OAAO,KAAK,CAAC,aAAa,CACxB,SAAS,EACT;QACE,GAAG,iBAAiB,CAAC,KAAK,CAAC;AAC3B,QAAA,GAAG,oBAAoB;KACxB,EACD,gBAAgB,CACjB,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,7 +1,7 @@
|
|
|
1
1
|
import * as Components from '@contentful/experiences-components-react';
|
|
2
2
|
import { containerDefinition, sectionDefinition, columnsDefinition, singleColumnDefinition, dividerDefinition } from '@contentful/experiences-components-react';
|
|
3
3
|
import { CONTENTFUL_COMPONENTS, INTERNAL_EVENTS, OUTGOING_EVENTS, ASSEMBLY_DEFAULT_CATEGORY } from '@contentful/experiences-core/constants';
|
|
4
|
-
import { builtInStyles, optionalBuiltInStyles, sendMessage, breakpointsRegistry, designTokensRegistry } from '@contentful/experiences-core';
|
|
4
|
+
import { defineSdkOptions, builtInStyles, optionalBuiltInStyles, sendMessage, breakpointsRegistry, designTokensRegistry } from '@contentful/experiences-core';
|
|
5
5
|
import { validateComponentDefinition } from '@contentful/experiences-validators';
|
|
6
6
|
import { withComponentWrapper } from '../utils/withComponentWrapper.js';
|
|
7
7
|
import { SDK_VERSION } from '../sdkVersion.js';
|
|
@@ -256,6 +256,11 @@ const defineComponents = (componentRegistrations, options) => {
|
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
|
+
if (options?.__disableTextAlignmentTransform) {
|
|
260
|
+
defineSdkOptions({
|
|
261
|
+
__disableTextAlignmentTransform: true,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
259
264
|
for (const registration of componentRegistrations) {
|
|
260
265
|
// Fill definitions with fallbacks values
|
|
261
266
|
const enrichedComponentRegistration = enrichComponentDefinition(registration);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"componentRegistry.js","sources":["../../../src/core/componentRegistry.ts"],"sourcesContent":["import * as Components from '@contentful/experiences-components-react';\nimport type {\n ComponentRegistration,\n ComponentDefinition,\n ComponentRegistrationOptions,\n DesignTokensDefinition,\n} from '@contentful/experiences-core/types';\nimport {\n OUTGOING_EVENTS,\n INTERNAL_EVENTS,\n CONTENTFUL_COMPONENTS,\n ASSEMBLY_DEFAULT_CATEGORY,\n} from '@contentful/experiences-core/constants';\nimport {\n builtInStyles as builtInStyleDefinitions,\n designTokensRegistry,\n breakpointsRegistry,\n optionalBuiltInStyles,\n sendMessage,\n} from '@contentful/experiences-core';\nimport { validateComponentDefinition } from '@contentful/experiences-validators';\nimport { withComponentWrapper } from '../utils/withComponentWrapper';\nimport { SDK_VERSION } from '../constants';\nimport {\n sectionDefinition,\n containerDefinition,\n columnsDefinition,\n singleColumnDefinition,\n dividerDefinition,\n} from '@contentful/experiences-components-react';\n\nconst CssVarRegex = /var\\(--[\\w-]+\\)/;\n\nconst cloneObject = <T>(targetObject: T): T => {\n if (typeof structuredClone !== 'undefined') {\n return structuredClone(targetObject);\n }\n\n return JSON.parse(JSON.stringify(targetObject));\n};\n\nconst applyComponentDefinitionFallbacks = (componentDefinition: ComponentDefinition) => {\n const clone = cloneObject(componentDefinition);\n for (const variable of Object.values(clone.variables)) {\n variable.group = variable.group ?? 'content';\n }\n return clone;\n};\n\nconst applyBuiltInStyleDefinitions = (componentDefinition: ComponentDefinition) => {\n const clone = cloneObject(componentDefinition);\n\n // set margin built-in style by default\n if (!clone.builtInStyles) {\n clone.builtInStyles = ['cfMargin'];\n }\n\n if (!clone.variables) {\n clone.variables = {};\n }\n\n // Enforce the presence of this property for toggling visibility on any node\n clone.variables['cfVisibility'] = builtInStyleDefinitions['cfVisibility'];\n\n for (const style of clone.builtInStyles || []) {\n if (builtInStyleDefinitions[style]) {\n clone.variables[style] = builtInStyleDefinitions[style] as any; // TODO: fix type\n }\n if (optionalBuiltInStyles[style]) {\n clone.variables[style] = optionalBuiltInStyles[style] as any; // TODO: fix type\n }\n }\n return clone;\n};\n\nexport const enrichComponentDefinition = ({\n component,\n definition,\n options,\n}: ComponentRegistration): ComponentRegistration => {\n const definitionWithFallbacks = applyComponentDefinitionFallbacks(definition);\n const definitionWithBuiltInStyles = applyBuiltInStyleDefinitions(definitionWithFallbacks);\n return {\n component: withComponentWrapper(component, options),\n definition: definitionWithBuiltInStyles,\n options,\n };\n};\n\nconst DEFAULT_COMPONENT_REGISTRATIONS = {\n container: {\n component: Components.ContentfulContainer,\n definition: containerDefinition,\n },\n section: {\n component: Components.ContentfulContainer,\n definition: sectionDefinition,\n },\n columns: {\n component: Components.Columns,\n definition: columnsDefinition,\n },\n singleColumn: {\n component: Components.SingleColumn,\n definition: singleColumnDefinition,\n },\n button: enrichComponentDefinition({\n component: Components.Button,\n definition: Components.ButtonComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n heading: enrichComponentDefinition({\n component: Components.Heading,\n definition: Components.HeadingComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n image: enrichComponentDefinition({\n component: Components.Image,\n definition: Components.ImageComponentDefinition,\n options: { wrapComponent: false },\n }),\n richText: enrichComponentDefinition({\n component: Components.RichText,\n definition: Components.RichTextComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n text: enrichComponentDefinition({\n component: Components.Text,\n definition: Components.TextComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n divider: enrichComponentDefinition({\n component: Components.ContentfulDivider,\n definition: dividerDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n carousel: enrichComponentDefinition({\n component: Components.Carousel,\n definition: Components.carouselDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n} satisfies Record<string, ComponentRegistration>;\n\n// pre-filling with the default component registrations\nexport const componentRegistry = new Map<string, ComponentRegistration>([\n [DEFAULT_COMPONENT_REGISTRATIONS.section.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.section],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.container.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.container,\n ],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.singleColumn.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.singleColumn,\n ],\n [DEFAULT_COMPONENT_REGISTRATIONS.columns.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.columns],\n [DEFAULT_COMPONENT_REGISTRATIONS.button.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.button],\n [DEFAULT_COMPONENT_REGISTRATIONS.heading.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.heading],\n [DEFAULT_COMPONENT_REGISTRATIONS.image.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.image],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.richText.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.richText,\n ],\n [DEFAULT_COMPONENT_REGISTRATIONS.text.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.text],\n [DEFAULT_COMPONENT_REGISTRATIONS.divider.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.divider],\n]);\n\nexport const optionalBuiltInComponents = [\n DEFAULT_COMPONENT_REGISTRATIONS.button.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.heading.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.image.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.richText.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.text.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.divider.definition.id,\n];\n\nexport const sendRegisteredComponentsMessage = () => {\n // Send the definitions (without components) via the connection message to the experience builder\n const registeredDefinitions = Array.from(componentRegistry.values())\n .map(({ definition }) => definition)\n // Pattern definitions are empty placeholder within the SDK without variables\n // We don't send those to the editor as they would overwrite the actual correct definitions.\n .filter((definition) => definition.category !== ASSEMBLY_DEFAULT_CATEGORY);\n\n sendMessage(OUTGOING_EVENTS.RegisteredComponents, {\n definitions: registeredDefinitions,\n });\n};\n\nexport const runRegisteredComponentValidations = () => {\n Array.from(componentRegistry.values()).map(({ definition }) => {\n const validation = validateComponentDefinition(definition);\n if (!validation.success) {\n throw new Error(\n `Invalid component definition for component '${definition.name}'. Failed with errors: \\n${JSON.stringify(validation.errors, null, 2)}`,\n );\n }\n });\n};\n\nconst getSingleCssVariableValue = (\n element: HTMLDivElement,\n cssVariableValue: string,\n cssAttribute: any,\n) => {\n element.style[cssAttribute] = cssVariableValue;\n const styles = getComputedStyle(element);\n const resolvedValue = styles.getPropertyValue(cssAttribute);\n return resolvedValue;\n};\n\nconst getAllCssVariableValues = (\n element: HTMLDivElement,\n cssVariable: Record<string, string>,\n cssAttribute: any,\n) => {\n const resolvedCssVariables = {} as Record<string, string>;\n\n Object.keys(cssVariable).forEach((key) => {\n const cssVariableValue = cssVariable[key];\n if (CssVarRegex.test(cssVariableValue)) {\n const resolvedValue = getSingleCssVariableValue(element, cssVariableValue, cssAttribute);\n resolvedCssVariables[cssVariableValue] = resolvedValue;\n }\n });\n return resolvedCssVariables;\n};\n\ntype CssMapType = {\n variable?: Record<string, string>;\n property: string;\n};\n\nconst resolveCssVariables = (designTokensDefinition: DesignTokensDefinition) => {\n const {\n spacing,\n sizing,\n color,\n borderRadius,\n fontSize,\n lineHeight,\n letterSpacing,\n textColor,\n border,\n } = designTokensDefinition;\n const resolvedCssVariables = {} as Record<string, string>;\n\n // Create an element\n const element = document.createElement('div');\n document.body.appendChild(element);\n\n const cssProperties: CssMapType[] = [\n { variable: spacing, property: 'margin' },\n { variable: sizing, property: 'width' },\n { variable: color, property: 'background-color' },\n { variable: borderRadius, property: 'border-radius' },\n { variable: fontSize, property: 'font-size' },\n { variable: lineHeight, property: 'line-height' },\n { variable: letterSpacing, property: 'letter-spacing' },\n { variable: textColor, property: 'color' },\n ];\n\n cssProperties.forEach(({ variable, property }) => {\n if (variable) {\n const rawResolvedValues = getAllCssVariableValues(element, variable, property);\n Object.assign(resolvedCssVariables, rawResolvedValues);\n }\n });\n\n if (border) {\n const tempResolvedValue = {} as Record<string, string>;\n Object.keys(border).forEach((borderKey) => {\n const { width, style, color } = border[borderKey];\n\n if (width && CssVarRegex.test(width)) {\n const resolvedValue = getSingleCssVariableValue(element, width, 'border-width');\n tempResolvedValue[width] = resolvedValue;\n }\n if (style && CssVarRegex.test(style)) {\n const resolvedValue = getSingleCssVariableValue(element, style, 'border-style');\n tempResolvedValue[style] = resolvedValue;\n }\n if (color && CssVarRegex.test(color)) {\n const resolvedValue = getSingleCssVariableValue(element, color, 'border-color');\n tempResolvedValue[color] = resolvedValue;\n }\n Object.assign(resolvedCssVariables, tempResolvedValue);\n });\n }\n\n document.body.removeChild(element);\n return resolvedCssVariables;\n};\n\nexport const sendConnectedEventWithRegisteredComponents = () => {\n // Send the definitions (without components) via the connection message to the experience builder\n const registeredDefinitions = Array.from(componentRegistry.values()).map(\n ({ definition }) => definition,\n );\n\n sendMessage(OUTGOING_EVENTS.Connected, {\n sdkVersion: SDK_VERSION,\n definitions: registeredDefinitions,\n });\n\n sendMessage(OUTGOING_EVENTS.RegisteredBreakpoints, {\n breakpoints: breakpointsRegistry,\n });\n\n sendMessage(OUTGOING_EVENTS.DesignTokens, {\n designTokens: designTokensRegistry,\n resolvedCssVariables: resolveCssVariables(designTokensRegistry),\n });\n};\n\n/**\n * Registers multiple components and their component definitions at once\n * @param componentRegistrations - ComponentRegistration[]\n * @returns void\n */\nexport const defineComponents = (\n componentRegistrations: ComponentRegistration[],\n options?: ComponentRegistrationOptions,\n) => {\n if (options?.experimentalComponents?.carousel) {\n componentRegistry.set(\n CONTENTFUL_COMPONENTS.carousel.id,\n DEFAULT_COMPONENT_REGISTRATIONS.carousel,\n );\n }\n\n if (options?.enabledBuiltInComponents) {\n for (const id of optionalBuiltInComponents) {\n if (!options.enabledBuiltInComponents.includes(id)) {\n componentRegistry.delete(id);\n }\n }\n }\n\n for (const registration of componentRegistrations) {\n // Fill definitions with fallbacks values\n const enrichedComponentRegistration = enrichComponentDefinition(registration);\n\n componentRegistry.set(\n enrichedComponentRegistration.definition.id,\n enrichedComponentRegistration,\n );\n }\n\n if (typeof window !== 'undefined') {\n window.dispatchEvent(new CustomEvent(INTERNAL_EVENTS.ComponentsRegistered));\n }\n};\n\n/**\n * use this function only in tests\n */\nexport const resetComponentRegistry = () => {\n componentRegistry.clear();\n for (const registration of Object.values(DEFAULT_COMPONENT_REGISTRATIONS)) {\n componentRegistry.set(registration.definition.id, registration);\n }\n};\n\nexport const getComponentRegistration = (id: string) => componentRegistry.get(id);\n\nexport const addComponentRegistration = (componentRegistration: ComponentRegistration) => {\n componentRegistry.set(componentRegistration.definition.id, componentRegistration);\n};\n\nexport const createAssemblyRegistration = ({\n definitionId,\n definitionName,\n component,\n}: {\n definitionId: string;\n definitionName?: string;\n component: ComponentRegistration['component'];\n}) => {\n const componentRegistration = componentRegistry.get(definitionId);\n\n if (componentRegistration) {\n return componentRegistration;\n }\n\n const definition = {\n id: definitionId,\n name: definitionName || 'Component',\n variables: {},\n children: true,\n category: ASSEMBLY_DEFAULT_CATEGORY,\n };\n\n addComponentRegistration({ component, definition });\n\n return componentRegistry.get(definitionId);\n};\n"],"names":["builtInStyleDefinitions"],"mappings":";;;;;;;;AA+BA,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC,MAAM,WAAW,GAAG,CAAI,YAAe,KAAO;AAC5C,IAAA,IAAI,OAAO,eAAe,KAAK,WAAW,EAAE;AAC1C,QAAA,OAAO,eAAe,CAAC,YAAY,CAAC,CAAC;KACtC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;AAClD,CAAC,CAAC;AAEF,MAAM,iCAAiC,GAAG,CAAC,mBAAwC,KAAI;AACrF,IAAA,MAAM,KAAK,GAAG,WAAW,CAAC,mBAAmB,CAAC,CAAC;AAC/C,IAAA,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE;QACrD,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,IAAI,SAAS,CAAC;KAC9C;AACD,IAAA,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,4BAA4B,GAAG,CAAC,mBAAwC,KAAI;AAChF,IAAA,MAAM,KAAK,GAAG,WAAW,CAAC,mBAAmB,CAAC,CAAC;;AAG/C,IAAA,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE;AACxB,QAAA,KAAK,CAAC,aAAa,GAAG,CAAC,UAAU,CAAC,CAAC;KACpC;AAED,IAAA,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE;AACpB,QAAA,KAAK,CAAC,SAAS,GAAG,EAAE,CAAC;KACtB;;IAGD,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,GAAGA,aAAuB,CAAC,cAAc,CAAC,CAAC;IAE1E,KAAK,MAAM,KAAK,IAAI,KAAK,C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AAA,MAAM,UAAU,GAAG;AACjB,QAAA,EAAE,EAAE,YAAY;QAChB,IAAI,EAAE,cAAc,IAAI,WAAW;AACnC,QAAA,SAAS,EAAE,EAAE;AACb,QAAA,QAAQ,EAAE,IAAI;AACd,QAAA,QAAQ,EAAE,yBAAyB;KACpC,CAAC;AAEF,IAAA,wBAAwB,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;AAEpD,IAAA,OAAO,iBAAiB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAC7C;;;;"}
|
|
1
|
+
{"version":3,"file":"componentRegistry.js","sources":["../../../src/core/componentRegistry.ts"],"sourcesContent":["import * as Components from '@contentful/experiences-components-react';\nimport type {\n ComponentRegistration,\n ComponentDefinition,\n ComponentRegistrationOptions,\n DesignTokensDefinition,\n} from '@contentful/experiences-core/types';\nimport {\n OUTGOING_EVENTS,\n INTERNAL_EVENTS,\n CONTENTFUL_COMPONENTS,\n ASSEMBLY_DEFAULT_CATEGORY,\n} from '@contentful/experiences-core/constants';\nimport {\n builtInStyles as builtInStyleDefinitions,\n designTokensRegistry,\n breakpointsRegistry,\n optionalBuiltInStyles,\n sendMessage,\n defineSdkOptions,\n} from '@contentful/experiences-core';\nimport { validateComponentDefinition } from '@contentful/experiences-validators';\nimport { withComponentWrapper } from '../utils/withComponentWrapper';\nimport { SDK_VERSION } from '../constants';\nimport {\n sectionDefinition,\n containerDefinition,\n columnsDefinition,\n singleColumnDefinition,\n dividerDefinition,\n} from '@contentful/experiences-components-react';\n\nconst CssVarRegex = /var\\(--[\\w-]+\\)/;\n\nconst cloneObject = <T>(targetObject: T): T => {\n if (typeof structuredClone !== 'undefined') {\n return structuredClone(targetObject);\n }\n\n return JSON.parse(JSON.stringify(targetObject));\n};\n\nconst applyComponentDefinitionFallbacks = (componentDefinition: ComponentDefinition) => {\n const clone = cloneObject(componentDefinition);\n for (const variable of Object.values(clone.variables)) {\n variable.group = variable.group ?? 'content';\n }\n return clone;\n};\n\nconst applyBuiltInStyleDefinitions = (componentDefinition: ComponentDefinition) => {\n const clone = cloneObject(componentDefinition);\n\n // set margin built-in style by default\n if (!clone.builtInStyles) {\n clone.builtInStyles = ['cfMargin'];\n }\n\n if (!clone.variables) {\n clone.variables = {};\n }\n\n // Enforce the presence of this property for toggling visibility on any node\n clone.variables['cfVisibility'] = builtInStyleDefinitions['cfVisibility'];\n\n for (const style of clone.builtInStyles || []) {\n if (builtInStyleDefinitions[style]) {\n clone.variables[style] = builtInStyleDefinitions[style] as any; // TODO: fix type\n }\n if (optionalBuiltInStyles[style]) {\n clone.variables[style] = optionalBuiltInStyles[style] as any; // TODO: fix type\n }\n }\n return clone;\n};\n\nexport const enrichComponentDefinition = ({\n component,\n definition,\n options,\n}: ComponentRegistration): ComponentRegistration => {\n const definitionWithFallbacks = applyComponentDefinitionFallbacks(definition);\n const definitionWithBuiltInStyles = applyBuiltInStyleDefinitions(definitionWithFallbacks);\n return {\n component: withComponentWrapper(component, options),\n definition: definitionWithBuiltInStyles,\n options,\n };\n};\n\nconst DEFAULT_COMPONENT_REGISTRATIONS = {\n container: {\n component: Components.ContentfulContainer,\n definition: containerDefinition,\n },\n section: {\n component: Components.ContentfulContainer,\n definition: sectionDefinition,\n },\n columns: {\n component: Components.Columns,\n definition: columnsDefinition,\n },\n singleColumn: {\n component: Components.SingleColumn,\n definition: singleColumnDefinition,\n },\n button: enrichComponentDefinition({\n component: Components.Button,\n definition: Components.ButtonComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n heading: enrichComponentDefinition({\n component: Components.Heading,\n definition: Components.HeadingComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n image: enrichComponentDefinition({\n component: Components.Image,\n definition: Components.ImageComponentDefinition,\n options: { wrapComponent: false },\n }),\n richText: enrichComponentDefinition({\n component: Components.RichText,\n definition: Components.RichTextComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n text: enrichComponentDefinition({\n component: Components.Text,\n definition: Components.TextComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n divider: enrichComponentDefinition({\n component: Components.ContentfulDivider,\n definition: dividerDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n carousel: enrichComponentDefinition({\n component: Components.Carousel,\n definition: Components.carouselDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n} satisfies Record<string, ComponentRegistration>;\n\n// pre-filling with the default component registrations\nexport const componentRegistry = new Map<string, ComponentRegistration>([\n [DEFAULT_COMPONENT_REGISTRATIONS.section.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.section],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.container.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.container,\n ],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.singleColumn.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.singleColumn,\n ],\n [DEFAULT_COMPONENT_REGISTRATIONS.columns.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.columns],\n [DEFAULT_COMPONENT_REGISTRATIONS.button.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.button],\n [DEFAULT_COMPONENT_REGISTRATIONS.heading.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.heading],\n [DEFAULT_COMPONENT_REGISTRATIONS.image.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.image],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.richText.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.richText,\n ],\n [DEFAULT_COMPONENT_REGISTRATIONS.text.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.text],\n [DEFAULT_COMPONENT_REGISTRATIONS.divider.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.divider],\n]);\n\nexport const optionalBuiltInComponents = [\n DEFAULT_COMPONENT_REGISTRATIONS.button.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.heading.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.image.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.richText.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.text.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.divider.definition.id,\n];\n\nexport const sendRegisteredComponentsMessage = () => {\n // Send the definitions (without components) via the connection message to the experience builder\n const registeredDefinitions = Array.from(componentRegistry.values())\n .map(({ definition }) => definition)\n // Pattern definitions are empty placeholder within the SDK without variables\n // We don't send those to the editor as they would overwrite the actual correct definitions.\n .filter((definition) => definition.category !== ASSEMBLY_DEFAULT_CATEGORY);\n\n sendMessage(OUTGOING_EVENTS.RegisteredComponents, {\n definitions: registeredDefinitions,\n });\n};\n\nexport const runRegisteredComponentValidations = () => {\n Array.from(componentRegistry.values()).map(({ definition }) => {\n const validation = validateComponentDefinition(definition);\n if (!validation.success) {\n throw new Error(\n `Invalid component definition for component '${definition.name}'. Failed with errors: \\n${JSON.stringify(validation.errors, null, 2)}`,\n );\n }\n });\n};\n\nconst getSingleCssVariableValue = (\n element: HTMLDivElement,\n cssVariableValue: string,\n cssAttribute: any,\n) => {\n element.style[cssAttribute] = cssVariableValue;\n const styles = getComputedStyle(element);\n const resolvedValue = styles.getPropertyValue(cssAttribute);\n return resolvedValue;\n};\n\nconst getAllCssVariableValues = (\n element: HTMLDivElement,\n cssVariable: Record<string, string>,\n cssAttribute: any,\n) => {\n const resolvedCssVariables = {} as Record<string, string>;\n\n Object.keys(cssVariable).forEach((key) => {\n const cssVariableValue = cssVariable[key];\n if (CssVarRegex.test(cssVariableValue)) {\n const resolvedValue = getSingleCssVariableValue(element, cssVariableValue, cssAttribute);\n resolvedCssVariables[cssVariableValue] = resolvedValue;\n }\n });\n return resolvedCssVariables;\n};\n\ntype CssMapType = {\n variable?: Record<string, string>;\n property: string;\n};\n\nconst resolveCssVariables = (designTokensDefinition: DesignTokensDefinition) => {\n const {\n spacing,\n sizing,\n color,\n borderRadius,\n fontSize,\n lineHeight,\n letterSpacing,\n textColor,\n border,\n } = designTokensDefinition;\n const resolvedCssVariables = {} as Record<string, string>;\n\n // Create an element\n const element = document.createElement('div');\n document.body.appendChild(element);\n\n const cssProperties: CssMapType[] = [\n { variable: spacing, property: 'margin' },\n { variable: sizing, property: 'width' },\n { variable: color, property: 'background-color' },\n { variable: borderRadius, property: 'border-radius' },\n { variable: fontSize, property: 'font-size' },\n { variable: lineHeight, property: 'line-height' },\n { variable: letterSpacing, property: 'letter-spacing' },\n { variable: textColor, property: 'color' },\n ];\n\n cssProperties.forEach(({ variable, property }) => {\n if (variable) {\n const rawResolvedValues = getAllCssVariableValues(element, variable, property);\n Object.assign(resolvedCssVariables, rawResolvedValues);\n }\n });\n\n if (border) {\n const tempResolvedValue = {} as Record<string, string>;\n Object.keys(border).forEach((borderKey) => {\n const { width, style, color } = border[borderKey];\n\n if (width && CssVarRegex.test(width)) {\n const resolvedValue = getSingleCssVariableValue(element, width, 'border-width');\n tempResolvedValue[width] = resolvedValue;\n }\n if (style && CssVarRegex.test(style)) {\n const resolvedValue = getSingleCssVariableValue(element, style, 'border-style');\n tempResolvedValue[style] = resolvedValue;\n }\n if (color && CssVarRegex.test(color)) {\n const resolvedValue = getSingleCssVariableValue(element, color, 'border-color');\n tempResolvedValue[color] = resolvedValue;\n }\n Object.assign(resolvedCssVariables, tempResolvedValue);\n });\n }\n\n document.body.removeChild(element);\n return resolvedCssVariables;\n};\n\nexport const sendConnectedEventWithRegisteredComponents = () => {\n // Send the definitions (without components) via the connection message to the experience builder\n const registeredDefinitions = Array.from(componentRegistry.values()).map(\n ({ definition }) => definition,\n );\n\n sendMessage(OUTGOING_EVENTS.Connected, {\n sdkVersion: SDK_VERSION,\n definitions: registeredDefinitions,\n });\n\n sendMessage(OUTGOING_EVENTS.RegisteredBreakpoints, {\n breakpoints: breakpointsRegistry,\n });\n\n sendMessage(OUTGOING_EVENTS.DesignTokens, {\n designTokens: designTokensRegistry,\n resolvedCssVariables: resolveCssVariables(designTokensRegistry),\n });\n};\n\n/**\n * Registers multiple components and their component definitions at once\n * @param componentRegistrations - ComponentRegistration[]\n * @returns void\n */\nexport const defineComponents = (\n componentRegistrations: ComponentRegistration[],\n options?: ComponentRegistrationOptions,\n) => {\n if (options?.experimentalComponents?.carousel) {\n componentRegistry.set(\n CONTENTFUL_COMPONENTS.carousel.id,\n DEFAULT_COMPONENT_REGISTRATIONS.carousel,\n );\n }\n\n if (options?.enabledBuiltInComponents) {\n for (const id of optionalBuiltInComponents) {\n if (!options.enabledBuiltInComponents.includes(id)) {\n componentRegistry.delete(id);\n }\n }\n }\n\n if (options?.__disableTextAlignmentTransform) {\n defineSdkOptions({\n __disableTextAlignmentTransform: true,\n });\n }\n\n for (const registration of componentRegistrations) {\n // Fill definitions with fallbacks values\n const enrichedComponentRegistration = enrichComponentDefinition(registration);\n\n componentRegistry.set(\n enrichedComponentRegistration.definition.id,\n enrichedComponentRegistration,\n );\n }\n\n if (typeof window !== 'undefined') {\n window.dispatchEvent(new CustomEvent(INTERNAL_EVENTS.ComponentsRegistered));\n }\n};\n\n/**\n * use this function only in tests\n */\nexport const resetComponentRegistry = () => {\n componentRegistry.clear();\n for (const registration of Object.values(DEFAULT_COMPONENT_REGISTRATIONS)) {\n componentRegistry.set(registration.definition.id, registration);\n }\n};\n\nexport const getComponentRegistration = (id: string) => componentRegistry.get(id);\n\nexport const addComponentRegistration = (componentRegistration: ComponentRegistration) => {\n componentRegistry.set(componentRegistration.definition.id, componentRegistration);\n};\n\nexport const createAssemblyRegistration = ({\n definitionId,\n definitionName,\n component,\n}: {\n definitionId: string;\n definitionName?: string;\n component: ComponentRegistration['component'];\n}) => {\n const componentRegistration = componentRegistry.get(definitionId);\n\n if (componentRegistration) {\n return componentRegistration;\n }\n\n const definition = {\n id: definitionId,\n name: definitionName || 'Component',\n variables: {},\n children: true,\n category: ASSEMBLY_DEFAULT_CATEGORY,\n };\n\n addComponentRegistration({ component, definition });\n\n return componentRegistry.get(definitionId);\n};\n"],"names":["builtInStyleDefinitions"],"mappings":";;;;;;;;AAgCA,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEt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AAW;AACnC,QAAA,SAAS,EAAE,EAAE;AACb,QAAA,QAAQ,EAAE,IAAI;AACd,QAAA,QAAQ,EAAE,yBAAyB;KACpC,CAAC;AAEF,IAAA,wBAAwB,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;AAEpD,IAAA,OAAO,iBAAiB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAC7C;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState, useRef, useEffect } from 'react';
|
|
2
|
-
import { runBreakpointsValidation, designTokensRegistry, breakpointsRegistry } from '@contentful/experiences-core';
|
|
2
|
+
import { runBreakpointsValidation, designTokensRegistry, breakpointsRegistry, sdkOptionsRegistry } from '@contentful/experiences-core';
|
|
3
3
|
import { runRegisteredComponentValidations, sendConnectedEventWithRegisteredComponents, sendRegisteredComponentsMessage, componentRegistry } from '../core/componentRegistry.js';
|
|
4
4
|
import { INTERNAL_EVENTS, VISUAL_EDITOR_EVENTS } from '@contentful/experiences-core/constants';
|
|
5
5
|
|
|
@@ -40,6 +40,7 @@ const useInitializeVisualEditor = (params) => {
|
|
|
40
40
|
componentRegistry,
|
|
41
41
|
designTokens: designTokensRegistry,
|
|
42
42
|
breakpoints: breakpointsRegistry,
|
|
43
|
+
sdkOptions: sdkOptionsRegistry,
|
|
43
44
|
locale,
|
|
44
45
|
entities: initialEntities ?? [],
|
|
45
46
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInitializeVisualEditor.js","sources":["../../../src/hooks/useInitializeVisualEditor.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport { EntityStore, breakpointsRegistry } from '@contentful/experiences-core';\nimport {\n componentRegistry,\n sendConnectedEventWithRegisteredComponents,\n sendRegisteredComponentsMessage,\n runRegisteredComponentValidations,\n} from '../core/componentRegistry';\nimport { INTERNAL_EVENTS, VISUAL_EDITOR_EVENTS } from '@contentful/experiences-core/constants';\nimport {
|
|
1
|
+
{"version":3,"file":"useInitializeVisualEditor.js","sources":["../../../src/hooks/useInitializeVisualEditor.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport { EntityStore, breakpointsRegistry } from '@contentful/experiences-core';\nimport {\n componentRegistry,\n sendConnectedEventWithRegisteredComponents,\n sendRegisteredComponentsMessage,\n runRegisteredComponentValidations,\n} from '../core/componentRegistry';\nimport { INTERNAL_EVENTS, VISUAL_EDITOR_EVENTS } from '@contentful/experiences-core/constants';\nimport {\n designTokensRegistry,\n runBreakpointsValidation,\n sdkOptionsRegistry,\n} from '@contentful/experiences-core';\n\ntype InitializeVisualEditorParams = {\n initialLocale: string;\n initialEntities?: EntityStore['entities'];\n};\n\nexport const useInitializeVisualEditor = (params: InitializeVisualEditorParams) => {\n const { initialLocale, initialEntities } = params;\n const [locale, setLocale] = useState<string>(initialLocale);\n const hasConnectEventBeenSent = useRef(false);\n\n // sends component definitions to the web app\n // InternalEvents.COMPONENTS_REGISTERED is triggered by defineComponents function\n useEffect(() => {\n if (!hasConnectEventBeenSent.current) {\n runRegisteredComponentValidations();\n runBreakpointsValidation();\n // sending CONNECT but with the registered components now\n sendConnectedEventWithRegisteredComponents();\n hasConnectEventBeenSent.current = true;\n }\n\n const onComponentsRegistered = () => {\n runRegisteredComponentValidations();\n sendRegisteredComponentsMessage();\n };\n\n if (typeof window !== 'undefined') {\n window.addEventListener(INTERNAL_EVENTS.ComponentsRegistered, onComponentsRegistered);\n }\n\n return () => {\n if (typeof window !== 'undefined') {\n window.removeEventListener(INTERNAL_EVENTS.ComponentsRegistered, onComponentsRegistered);\n }\n };\n }, []);\n\n useEffect(() => {\n setLocale(initialLocale);\n }, [initialLocale]);\n\n useEffect(() => {\n const onVisualEditorReady = () => {\n window.dispatchEvent(\n new CustomEvent(INTERNAL_EVENTS.VisualEditorInitialize, {\n detail: {\n componentRegistry,\n designTokens: designTokensRegistry,\n breakpoints: breakpointsRegistry,\n sdkOptions: sdkOptionsRegistry,\n locale,\n entities: initialEntities ?? [],\n },\n }),\n );\n };\n\n window.addEventListener(VISUAL_EDITOR_EVENTS.Ready, onVisualEditorReady);\n return () => {\n window.removeEventListener(VISUAL_EDITOR_EVENTS.Ready, onVisualEditorReady);\n };\n }, [locale, initialEntities]);\n};\n"],"names":[],"mappings":";;;;;AAoBa,MAAA,yBAAyB,GAAG,CAAC,MAAoC,KAAI;AAChF,IAAA,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,GAAG,MAAM,CAAC;IAClD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAS,aAAa,CAAC,CAAC;AAC5D,IAAA,MAAM,uBAAuB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;;;IAI9C,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,uBAAuB,CAAC,OAAO,EAAE;AACpC,YAAA,iCAAiC,EAAE,CAAC;AACpC,YAAA,wBAAwB,EAAE,CAAC;;AAE3B,YAAA,0CAA0C,EAAE,CAAC;AAC7C,YAAA,uBAAuB,CAAC,OAAO,GAAG,IAAI,CAAC;SACxC;QAED,MAAM,sBAAsB,GAAG,MAAK;AAClC,YAAA,iCAAiC,EAAE,CAAC;AACpC,YAAA,+BAA+B,EAAE,CAAC;AACpC,SAAC,CAAC;AAEF,QAAA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;YACjC,MAAM,CAAC,gBAAgB,CAAC,eAAe,CAAC,oBAAoB,EAAE,sBAAsB,CAAC,CAAC;SACvF;AAED,QAAA,OAAO,MAAK;AACV,YAAA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;gBACjC,MAAM,CAAC,mBAAmB,CAAC,eAAe,CAAC,oBAAoB,EAAE,sBAAsB,CAAC,CAAC;aAC1F;AACH,SAAC,CAAC;KACH,EAAE,EAAE,CAAC,CAAC;IAEP,SAAS,CAAC,MAAK;QACb,SAAS,CAAC,aAAa,CAAC,CAAC;AAC3B,KAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IAEpB,SAAS,CAAC,MAAK;QACb,MAAM,mBAAmB,GAAG,MAAK;YAC/B,MAAM,CAAC,aAAa,CAClB,IAAI,WAAW,CAAC,eAAe,CAAC,sBAAsB,EAAE;AACtD,gBAAA,MAAM,EAAE;oBACN,iBAAiB;AACjB,oBAAA,YAAY,EAAE,oBAAoB;AAClC,oBAAA,WAAW,EAAE,mBAAmB;AAChC,oBAAA,UAAU,EAAE,kBAAkB;oBAC9B,MAAM;oBACN,QAAQ,EAAE,eAAe,IAAI,EAAE;AAChC,iBAAA;AACF,aAAA,CAAC,CACH,CAAC;AACJ,SAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;AACzE,QAAA,OAAO,MAAK;YACV,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;AAC9E,SAAC,CAAC;AACJ,KAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;AAChC;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import * as _contentful_experiences_core_constants from '@contentful/experiences
|
|
|
9
9
|
export { CF_STYLE_ATTRIBUTES, CONTENTFUL_COMPONENTS, LATEST_SCHEMA_VERSION } from '@contentful/experiences-core/constants';
|
|
10
10
|
import { ContentfulClientApi } from 'contentful';
|
|
11
11
|
|
|
12
|
-
declare const SDK_VERSION = "3.3.0";
|
|
12
|
+
declare const SDK_VERSION = "3.3.1-beta.0";
|
|
13
13
|
|
|
14
14
|
type ExperienceRootProps = {
|
|
15
15
|
experience?: Experience<EntityStore> | string | null;
|
package/dist/sdkVersion.js
CHANGED
package/dist/sdkVersion.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdkVersion.js","sources":["../../src/sdkVersion.ts"],"sourcesContent":["export const SDK_VERSION = '3.3.0';\n"],"names":[],"mappings":"AAAO,MAAM,WAAW,GAAG;;;;"}
|
|
1
|
+
{"version":3,"file":"sdkVersion.js","sources":["../../src/sdkVersion.ts"],"sourcesContent":["export const SDK_VERSION = '3.3.1-beta.0';\n"],"names":[],"mappings":"AAAO,MAAM,WAAW,GAAG;;;;"}
|
package/dist/src/sdkVersion.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "3.3.0";
|
|
1
|
+
export declare const SDK_VERSION = "3.3.1-beta.0";
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
|
|
4
|
+
// NOTE: We're use this as a default for `options`. When only one option is explicitly defined,
|
|
5
|
+
// all other default options are dropped as we're not merging the provided options with the default ones.
|
|
6
|
+
// We started merging both options with SDK v3 but many customers wouldn't upgrade as it suddenly added
|
|
7
|
+
// wrappers to their components because they only set the options to `{ wrapContainerWidth: "100%" }`.
|
|
8
|
+
// With v2, it results in `wrapComponent` being undefined but with v3, it resulted in it being `true` and
|
|
9
|
+
// thus causing unexpected layout changes.
|
|
10
|
+
// We rolled back that change to let customers migrate smoothly for now but will adjust this behaviour with
|
|
11
|
+
// v4.
|
|
12
|
+
const DEFAULT_OPTIONS = {
|
|
13
|
+
wrapComponent: true,
|
|
14
|
+
wrapContainer: 'div',
|
|
15
|
+
};
|
|
4
16
|
/**
|
|
5
17
|
* Sets up a component to be consumed by Experience Builder. This function can be used to wrap a component with a container component, or to pass props to the component directly.
|
|
6
18
|
* @param Component Component to be used by Experience Builder.
|
|
@@ -8,17 +20,11 @@ import React from 'react';
|
|
|
8
20
|
* @default { wrapComponent: true, wrapContainer: 'div' }
|
|
9
21
|
* @returns A component that can be passed to `defineComponents`.
|
|
10
22
|
*/
|
|
11
|
-
function withComponentWrapper(Component, options =
|
|
12
|
-
const mergedOptions = {
|
|
13
|
-
// Merge default values with overwriting options
|
|
14
|
-
wrapComponent: true,
|
|
15
|
-
wrapContainer: 'div',
|
|
16
|
-
...options,
|
|
17
|
-
};
|
|
23
|
+
function withComponentWrapper(Component, options = DEFAULT_OPTIONS) {
|
|
18
24
|
const Wrapped = (props) => {
|
|
19
|
-
const Tag =
|
|
25
|
+
const Tag = options.wrapContainer ?? 'div';
|
|
20
26
|
const { className = '', 'data-cf-node-id': dataCfNodeId, 'data-cf-node-block-id': dataCfNodeBlockId, 'data-cf-node-block-type': dataCfNodeBlockType, ...componentProps } = props;
|
|
21
|
-
const component =
|
|
27
|
+
const component = options.wrapComponent ? (jsx(Tag, { "data-component-wrapper": true, className: className, "data-cf-node-id": dataCfNodeId, "data-cf-node-block-id": dataCfNodeBlockId, "data-cf-node-block-type": dataCfNodeBlockType, children: jsx(Component, { ...componentProps }) })) : (React.createElement(Component, props));
|
|
22
28
|
return component;
|
|
23
29
|
};
|
|
24
30
|
return Wrapped;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withComponentWrapper.js","sources":["../../../src/utils/withComponentWrapper.tsx"],"sourcesContent":["import { ComponentRegistration } from '@contentful/experiences-core/types';\nimport React from 'react';\ninterface CFProps extends React.HtmlHTMLAttributes<HTMLElement> {\n /**\n * Classes to be applied to the container component if `wrapComponent` is true, or directly to the child component if false.\n */\n className?: string;\n 'data-cf-node-id': string;\n 'data-cf-node-block-id': string;\n 'data-cf-node-block-type': string;\n}\n\n/**\n * Sets up a component to be consumed by Experience Builder. This function can be used to wrap a component with a container component, or to pass props to the component directly.\n * @param Component Component to be used by Experience Builder.\n * @param options Options for the `withComponentWrapper` function.\n * @default { wrapComponent: true, wrapContainer: 'div' }\n * @returns A component that can be passed to `defineComponents`.\n */\nexport function withComponentWrapper<T>(\n Component: React.ElementType,\n options: ComponentRegistration['options'] =
|
|
1
|
+
{"version":3,"file":"withComponentWrapper.js","sources":["../../../src/utils/withComponentWrapper.tsx"],"sourcesContent":["import { ComponentRegistration } from '@contentful/experiences-core/types';\nimport React from 'react';\ninterface CFProps extends React.HtmlHTMLAttributes<HTMLElement> {\n /**\n * Classes to be applied to the container component if `wrapComponent` is true, or directly to the child component if false.\n */\n className?: string;\n 'data-cf-node-id': string;\n 'data-cf-node-block-id': string;\n 'data-cf-node-block-type': string;\n}\n\n// NOTE: We're use this as a default for `options`. When only one option is explicitly defined,\n// all other default options are dropped as we're not merging the provided options with the default ones.\n// We started merging both options with SDK v3 but many customers wouldn't upgrade as it suddenly added\n// wrappers to their components because they only set the options to `{ wrapContainerWidth: \"100%\" }`.\n// With v2, it results in `wrapComponent` being undefined but with v3, it resulted in it being `true` and\n// thus causing unexpected layout changes.\n// We rolled back that change to let customers migrate smoothly for now but will adjust this behaviour with\n// v4.\nconst DEFAULT_OPTIONS = {\n wrapComponent: true,\n wrapContainer: 'div' as keyof JSX.IntrinsicElements,\n};\n\n/**\n * Sets up a component to be consumed by Experience Builder. This function can be used to wrap a component with a container component, or to pass props to the component directly.\n * @param Component Component to be used by Experience Builder.\n * @param options Options for the `withComponentWrapper` function.\n * @default { wrapComponent: true, wrapContainer: 'div' }\n * @returns A component that can be passed to `defineComponents`.\n */\nexport function withComponentWrapper<T>(\n Component: React.ElementType,\n options: ComponentRegistration['options'] = DEFAULT_OPTIONS,\n) {\n const Wrapped: React.FC<CFProps & T> = (props) => {\n const Tag = options.wrapContainer ?? 'div';\n const {\n className = '',\n 'data-cf-node-id': dataCfNodeId,\n 'data-cf-node-block-id': dataCfNodeBlockId,\n 'data-cf-node-block-type': dataCfNodeBlockType,\n ...componentProps\n } = props;\n const component = options.wrapComponent ? (\n <Tag\n data-component-wrapper\n className={className}\n data-cf-node-id={dataCfNodeId}\n data-cf-node-block-id={dataCfNodeBlockId}\n data-cf-node-block-type={dataCfNodeBlockType}>\n <Component {...componentProps} />\n </Tag>\n ) : (\n React.createElement(Component, props)\n );\n return component;\n };\n\n return Wrapped;\n}\n"],"names":["_jsx"],"mappings":";;;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,eAAe,GAAG;AACtB,IAAA,aAAa,EAAE,IAAI;AACnB,IAAA,aAAa,EAAE,KAAoC;CACpD,CAAC;AAEF;;;;;;AAMG;SACa,oBAAoB,CAClC,SAA4B,EAC5B,UAA4C,eAAe,EAAA;AAE3D,IAAA,MAAM,OAAO,GAA0B,CAAC,KAAK,KAAI;AAC/C,QAAA,MAAM,GAAG,GAAG,OAAO,CAAC,aAAa,IAAI,KAAK,CAAC;QAC3C,MAAM,EACJ,SAAS,GAAG,EAAE,EACd,iBAAiB,EAAE,YAAY,EAC/B,uBAAuB,EAAE,iBAAiB,EAC1C,yBAAyB,EAAE,mBAAmB,EAC9C,GAAG,cAAc,EAClB,GAAG,KAAK,CAAC;AACV,QAAA,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,IACrCA,IAAC,GAAG,EAAA,EAAA,wBAAA,EAAA,IAAA,EAEF,SAAS,EAAE,SAAS,qBACH,YAAY,EAAA,uBAAA,EACN,iBAAiB,EACf,yBAAA,EAAA,mBAAmB,EAC5C,QAAA,EAAAA,GAAA,CAAC,SAAS,EAAK,EAAA,GAAA,cAAc,GAAI,EAC7B,CAAA,KAEN,KAAK,CAAC,aAAa,CAAC,SAAS,EAAE,KAAK,CAAC,CACtC,CAAC;AACF,QAAA,OAAO,SAAS,CAAC;AACnB,KAAC,CAAC;AAEF,IAAA,OAAO,OAAO,CAAC;AACjB;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/experiences-sdk-react",
|
|
3
|
-
"version": "3.3.0",
|
|
3
|
+
"version": "3.3.1-beta.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"typings": "./dist/src/index.d.ts",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"depcruise": "depcruise src"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@contentful/experiences-components-react": "3.3.0",
|
|
45
|
-
"@contentful/experiences-core": "3.3.0",
|
|
46
|
-
"@contentful/experiences-validators": "3.3.0",
|
|
47
|
-
"@contentful/experiences-visual-editor-react": "3.3.0",
|
|
44
|
+
"@contentful/experiences-components-react": "3.3.1-beta.0",
|
|
45
|
+
"@contentful/experiences-core": "3.3.1-beta.0",
|
|
46
|
+
"@contentful/experiences-validators": "3.3.1-beta.0",
|
|
47
|
+
"@contentful/experiences-visual-editor-react": "3.3.1-beta.0",
|
|
48
48
|
"@contentful/rich-text-types": "^17.0.0",
|
|
49
49
|
"csstype": "^3.1.2",
|
|
50
50
|
"immer": "^10.0.3",
|
|
@@ -98,5 +98,5 @@
|
|
|
98
98
|
"dist",
|
|
99
99
|
"package.json"
|
|
100
100
|
],
|
|
101
|
-
"gitHead": "
|
|
101
|
+
"gitHead": "6879c631faa6408402869b134801a5d3772b43da"
|
|
102
102
|
}
|