@contentful/experiences-visual-editor-react 1.40.0-alpha-20250604T0813-1f6e699.0 → 1.40.0-alpha-20250626T1127-cab6b9d.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 CHANGED
@@ -1433,6 +1433,10 @@ const findOutermostCoordinates = (first, second) => {
1433
1433
  left: Math.min(first.left, second.left),
1434
1434
  };
1435
1435
  };
1436
+ const isElementHidden = (rect) => {
1437
+ /** if the rect has no size and position, its element is not rendered in the DOM */
1438
+ return rect.width === 0 && rect.height === 0 && rect.x === 0 && rect.y === 0;
1439
+ };
1436
1440
  const getElementCoordinates = (element) => {
1437
1441
  const rect = element.getBoundingClientRect();
1438
1442
  /**
@@ -4192,6 +4196,9 @@ const collectNodeCoordinates = (node, nodeToCoordinatesMap) => {
4192
4196
  const selectedElement = document.querySelector(`[data-cf-node-id="${node.data.id}"]`);
4193
4197
  if (selectedElement) {
4194
4198
  const rect = getElementCoordinates(selectedElement);
4199
+ if (isElementHidden(rect)) {
4200
+ return;
4201
+ }
4195
4202
  nodeToCoordinatesMap[node.data.id] = {
4196
4203
  coordinates: {
4197
4204
  x: rect.x + window.scrollX,
@@ -4228,7 +4235,7 @@ const waitForAllImagesToBeLoaded = () => {
4228
4235
  }));
4229
4236
  };
4230
4237
 
4231
- const useCanvasGeometryUpdates = ({ tree, rootContainerRef, }) => {
4238
+ const useCanvasGeometryUpdates = ({ tree }) => {
4232
4239
  const debouncedUpdateGeometry = useMemo(() => debounce((tree, sourceEvent) => {
4233
4240
  // When the DOM changed, we still need to wait for the next frame to ensure that
4234
4241
  // rendering is complete (e.g. this is required when deleting a node).
@@ -4255,22 +4262,19 @@ const useCanvasGeometryUpdates = ({ tree, rootContainerRef, }) => {
4255
4262
  }, [debouncedUpdateGeometry]);
4256
4263
  // Handling DOM mutations
4257
4264
  useEffect(() => {
4258
- if (!rootContainerRef.current)
4259
- return;
4260
4265
  const observer = new MutationObserver(() => debouncedUpdateGeometry(treeRef.current, 'mutation'));
4261
- observer.observe(rootContainerRef.current, {
4266
+ observer.observe(document.documentElement, {
4262
4267
  childList: true,
4263
4268
  subtree: true,
4264
4269
  attributes: true,
4265
4270
  });
4266
4271
  return () => observer.disconnect();
4267
- }, [debouncedUpdateGeometry, rootContainerRef]);
4272
+ }, [debouncedUpdateGeometry]);
4268
4273
  };
4269
4274
 
4270
4275
  const RootRenderer = () => {
4271
- const rootContainerRef = useRef(null);
4272
4276
  const tree = useTreeStore((state) => state.tree);
4273
- useCanvasGeometryUpdates({ tree, rootContainerRef });
4277
+ useCanvasGeometryUpdates({ tree });
4274
4278
  useEditorSubscriber();
4275
4279
  const breakpoints = useTreeStore((state) => state.breakpoints);
4276
4280
  const { resolveDesignValue } = useBreakpoints(breakpoints);
@@ -4279,7 +4283,7 @@ const RootRenderer = () => {
4279
4283
  const rootBlockId = tree.root.data.blockId ?? ROOT_ID;
4280
4284
  const wrappingPatternIds = rootBlockId !== ROOT_ID ? new Set([rootBlockId]) : new Set();
4281
4285
  return (React.createElement(React.Fragment, null,
4282
- React.createElement("div", { "data-ctfl-root": true, className: styles$2.rootContainer, ref: rootContainerRef }, !tree.root.children.length ? (React.createElement(EmptyCanvasMessage, null)) : (tree.root.children.map((topLevelChildNode) => (React.createElement(EditorBlock, { key: topLevelChildNode.data.id, node: topLevelChildNode, resolveDesignValue: resolveDesignValue, wrappingPatternIds: wrappingPatternIds })))))));
4286
+ React.createElement("div", { "data-ctfl-root": true, className: styles$2.rootContainer }, !tree.root.children.length ? (React.createElement(EmptyCanvasMessage, null)) : (tree.root.children.map((topLevelChildNode) => (React.createElement(EditorBlock, { key: topLevelChildNode.data.id, node: topLevelChildNode, resolveDesignValue: resolveDesignValue, wrappingPatternIds: wrappingPatternIds })))))));
4283
4287
  };
4284
4288
 
4285
4289
  const useInitializeEditor = () => {