@contentful/experiences-visual-editor-react 3.3.1-dev-20250825T0713-34ae1b3.0 → 3.3.1-dev-20250825T1222-bc8206a.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/index.js +34 -12
- package/dist/index.js.map +1 -1
- package/dist/renderApp.js +34 -12
- package/dist/renderApp.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -2151,6 +2151,27 @@ const tryParseMessage = (event) => {
|
|
|
2151
2151
|
return eventData;
|
|
2152
2152
|
};
|
|
2153
2153
|
|
|
2154
|
+
const splitDirectAndSlotChildren = (allChildNodes, componentDefinition) => {
|
|
2155
|
+
// Bridge difference between editor and delivery mode
|
|
2156
|
+
const getSlotId = (child) => {
|
|
2157
|
+
if ('data' in child)
|
|
2158
|
+
return child.data.slotId;
|
|
2159
|
+
return child.slotId;
|
|
2160
|
+
};
|
|
2161
|
+
const slotNodesMap = {};
|
|
2162
|
+
for (const slotId in componentDefinition.slots) {
|
|
2163
|
+
// We only allow one component per slot (container). This is just safer to not render components twice or not at all
|
|
2164
|
+
const nodes = allChildNodes.filter((child) => getSlotId(child) === slotId);
|
|
2165
|
+
slotNodesMap[slotId] = nodes.length ? nodes : null;
|
|
2166
|
+
}
|
|
2167
|
+
const directChildNodes = allChildNodes.filter((child) => getSlotId(child) === undefined);
|
|
2168
|
+
if (!componentDefinition.children || !directChildNodes.length) {
|
|
2169
|
+
// If there are no children allowed in the component or no children added, render as undefined
|
|
2170
|
+
return { slotNodesMap, directChildNodes: undefined };
|
|
2171
|
+
}
|
|
2172
|
+
return { slotNodesMap, directChildNodes };
|
|
2173
|
+
};
|
|
2174
|
+
|
|
2154
2175
|
const sendMessage = (eventType, data) => {
|
|
2155
2176
|
if (typeof window === 'undefined') {
|
|
2156
2177
|
return;
|
|
@@ -4905,18 +4926,19 @@ function EditorBlock({ node, resolveDesignValue, wrappingPatternIds: parentWrapp
|
|
|
4905
4926
|
if (isRootAssemblyNode && node.data.blockId && parentWrappingPatternIds.has(node.data.blockId)) {
|
|
4906
4927
|
return React.createElement(CircularDependencyErrorPlaceholder, { wrappingPatternIds: wrappingPatternIds });
|
|
4907
4928
|
}
|
|
4908
|
-
const
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4929
|
+
const { slotNodesMap, directChildNodes } = splitDirectAndSlotChildren(node.children, componentRegistration.definition);
|
|
4930
|
+
const renderChildNode = (childNode) => (React.createElement(EditorBlock, { key: childNode.data.id, node: childNode, resolveDesignValue: resolveDesignValue, wrappingPatternIds: wrappingPatternIds, entityStore: entityStore, areEntitiesFetched: areEntitiesFetched }));
|
|
4931
|
+
const renderedSlotNodesMap = Object.entries(slotNodesMap).reduce((acc, [slotId, nodes]) => {
|
|
4932
|
+
if (nodes?.length) {
|
|
4933
|
+
acc[slotId] = React.createElement(React.Fragment, null, nodes.map((slotChildNode) => renderChildNode(slotChildNode)));
|
|
4934
|
+
}
|
|
4935
|
+
else {
|
|
4936
|
+
acc[slotId] = React.createElement("div", { className: styles$1.emptySlot });
|
|
4937
|
+
}
|
|
4938
|
+
return acc;
|
|
4939
|
+
}, {});
|
|
4940
|
+
const renderedChildren = directChildNodes?.map((childNode) => renderChildNode(childNode));
|
|
4941
|
+
return (React.createElement(RegistrationComponent, { node: node, resolveDesignValue: resolveDesignValue, componentRegistration: componentRegistration, slotNodes: renderedSlotNodesMap, entityStore: entityStore, areEntitiesFetched: areEntitiesFetched }, renderedChildren));
|
|
4920
4942
|
}
|
|
4921
4943
|
const RegistrationComponent = ({ node, resolveDesignValue, componentRegistration, slotNodes, children, entityStore, areEntitiesFetched, }) => {
|
|
4922
4944
|
const { componentProps } = useComponentProps({
|