@contentful/experiences-visual-editor-react 1.28.1 → 1.28.2
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 +40 -24
- package/dist/index.js.map +1 -1
- package/dist/renderApp.js +40 -24
- package/dist/renderApp.js.map +1 -1
- package/package.json +4 -4
package/dist/renderApp.js
CHANGED
|
@@ -43078,7 +43078,7 @@ const builtInStyles = {
|
|
|
43078
43078
|
},
|
|
43079
43079
|
type: 'Text',
|
|
43080
43080
|
group: 'style',
|
|
43081
|
-
description: 'The
|
|
43081
|
+
description: 'The vertical alignment of the section',
|
|
43082
43082
|
defaultValue: 'center',
|
|
43083
43083
|
displayName: 'Vertical alignment',
|
|
43084
43084
|
},
|
|
@@ -56671,34 +56671,19 @@ const useBreakpoints = (breakpoints) => {
|
|
|
56671
56671
|
* and sends the DOM Rect to the client app
|
|
56672
56672
|
*/
|
|
56673
56673
|
const sendSelectedComponentCoordinates = (instanceId) => {
|
|
56674
|
-
|
|
56675
|
-
|
|
56676
|
-
let selectedElement = document.querySelector(`[data-cf-node-id="${instanceId}"]`);
|
|
56677
|
-
let selectedAssemblyChild = undefined;
|
|
56678
|
-
const [rootNodeId, nodeLocation] = instanceId.split('---');
|
|
56679
|
-
if (nodeLocation) {
|
|
56680
|
-
selectedAssemblyChild = selectedElement;
|
|
56681
|
-
selectedElement = document.querySelector(`[data-cf-node-id="${rootNodeId}"]`);
|
|
56682
|
-
}
|
|
56683
|
-
// Finds the first parent that is a VisualEditorBlock
|
|
56684
|
-
let parent = selectedElement?.parentElement;
|
|
56685
|
-
while (parent) {
|
|
56686
|
-
if (parent?.dataset?.cfNodeId) {
|
|
56687
|
-
break;
|
|
56688
|
-
}
|
|
56689
|
-
parent = parent?.parentElement;
|
|
56690
|
-
}
|
|
56691
|
-
if (selectedElement) {
|
|
56674
|
+
const selection = getSelectionNodes(instanceId);
|
|
56675
|
+
if (selection?.target) {
|
|
56692
56676
|
const sendUpdateSelectedComponentCoordinates = () => {
|
|
56693
56677
|
sendMessage(OUTGOING_EVENTS.UpdateSelectedComponentCoordinates, {
|
|
56694
|
-
selectedNodeCoordinates: getElementCoordinates(
|
|
56695
|
-
selectedAssemblyChildCoordinates:
|
|
56696
|
-
? getElementCoordinates(
|
|
56678
|
+
selectedNodeCoordinates: getElementCoordinates(selection.target),
|
|
56679
|
+
selectedAssemblyChildCoordinates: selection.patternChild
|
|
56680
|
+
? getElementCoordinates(selection.patternChild)
|
|
56697
56681
|
: undefined,
|
|
56698
|
-
parentCoordinates: parent ? getElementCoordinates(parent) : undefined,
|
|
56682
|
+
parentCoordinates: selection.parent ? getElementCoordinates(selection.parent) : undefined,
|
|
56699
56683
|
});
|
|
56700
56684
|
};
|
|
56701
|
-
|
|
56685
|
+
// If the target contains an image, wait for this image to be loaded before sending the coordinates
|
|
56686
|
+
const childImage = selection.target.querySelector('img');
|
|
56702
56687
|
if (childImage) {
|
|
56703
56688
|
const handleImageLoad = () => {
|
|
56704
56689
|
sendUpdateSelectedComponentCoordinates();
|
|
@@ -56709,6 +56694,37 @@ const sendSelectedComponentCoordinates = (instanceId) => {
|
|
|
56709
56694
|
sendUpdateSelectedComponentCoordinates();
|
|
56710
56695
|
}
|
|
56711
56696
|
};
|
|
56697
|
+
const getSelectionNodes = (instanceId) => {
|
|
56698
|
+
if (!instanceId)
|
|
56699
|
+
return;
|
|
56700
|
+
let selectedNode = document.querySelector(`[data-cf-node-id="${instanceId}"]`);
|
|
56701
|
+
let selectedPatternChild = null;
|
|
56702
|
+
let selectedParent = null;
|
|
56703
|
+
// Use RegEx instead of split to match the last occurrence of '---' in the instanceId instead of the first one
|
|
56704
|
+
const idMatch = instanceId.match(/(.*)---(.*)/);
|
|
56705
|
+
const rootNodeId = idMatch?.[1] ?? instanceId;
|
|
56706
|
+
const nodeLocation = idMatch?.[2];
|
|
56707
|
+
const isNestedPattern = nodeLocation && selectedNode?.dataset?.cfNodeBlockType === ASSEMBLY_NODE_TYPE;
|
|
56708
|
+
const isPatternChild = !isNestedPattern && nodeLocation;
|
|
56709
|
+
if (isPatternChild) {
|
|
56710
|
+
// For pattern child nodes, render the pattern itself as selected component
|
|
56711
|
+
selectedPatternChild = selectedNode;
|
|
56712
|
+
selectedNode = document.querySelector(`[data-cf-node-id="${rootNodeId}"]`);
|
|
56713
|
+
}
|
|
56714
|
+
else if (isNestedPattern) {
|
|
56715
|
+
// For nested patterns, return the upper pattern as parent
|
|
56716
|
+
selectedParent = document.querySelector(`[data-cf-node-id="${rootNodeId}"]`);
|
|
56717
|
+
}
|
|
56718
|
+
else {
|
|
56719
|
+
// Find the next valid parent of the selected element
|
|
56720
|
+
selectedParent = selectedNode?.parentElement ?? null;
|
|
56721
|
+
// Ensure that the selection parent is a VisualEditorBlock
|
|
56722
|
+
while (selectedParent && !selectedParent.dataset?.cfNodeId) {
|
|
56723
|
+
selectedParent = selectedParent?.parentElement;
|
|
56724
|
+
}
|
|
56725
|
+
}
|
|
56726
|
+
return { target: selectedNode, patternChild: selectedPatternChild, parent: selectedParent };
|
|
56727
|
+
};
|
|
56712
56728
|
|
|
56713
56729
|
// Note: During development, the hot reloading might empty this and it
|
|
56714
56730
|
// stays empty leading to not rendering assemblies. Ideally, this is
|