@contentful/experiences-visual-editor-react 3.2.1-dev-20250819T1408-2dcca7e.0 → 3.3.0-dev-20250820T0950-c569ea0.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
@@ -4894,7 +4894,7 @@ const sendCanvasGeometryUpdatedMessage = async (tree, sourceEvent) => {
4894
4894
  const rootRect = document.documentElement.getBoundingClientRect();
4895
4895
  const bodyRect = document.body.getBoundingClientRect();
4896
4896
  const width = Math.max(document.documentElement.offsetWidth, rootRect.width, bodyRect.width);
4897
- const height = Math.max(document.documentElement.offsetHeight, rootRect.height, bodyRect.height);
4897
+ const height = Math.max(document.documentElement.offsetHeight, rootRect.height, bodyRect.height, measureBodyContentHeight());
4898
4898
  sendMessage(OUTGOING_EVENTS.CanvasGeometryUpdated, {
4899
4899
  size: {
4900
4900
  width,
@@ -4942,6 +4942,31 @@ function waitForImageToBeLoaded(imageNode) {
4942
4942
  imageNode.addEventListener('error', handleImageLoad);
4943
4943
  });
4944
4944
  }
4945
+ // calculates the content height by finding the deepest node in the first 2 levels of the body
4946
+ function measureBodyContentHeight(depth = 2, node = document.body) {
4947
+ if (depth <= 0)
4948
+ return 0;
4949
+ let height = 0;
4950
+ for (const element of node.children) {
4951
+ const rect = element.getBoundingClientRect();
4952
+ const style = window.getComputedStyle(element);
4953
+ const isHidden = (rect.width === 0 && rect.height === 0) ||
4954
+ style.display === 'none' ||
4955
+ style.visibility === 'hidden';
4956
+ // ignore relative positioned elements that are anchored to the bottom,
4957
+ // as this can cause infinite height
4958
+ const isBottomAnchored = (style.position === 'fixed' ||
4959
+ style.position === 'absolute' ||
4960
+ style.position === 'relative' ||
4961
+ style.position === 'sticky') &&
4962
+ parseFloat(style.bottom) < 0;
4963
+ if (isHidden || isBottomAnchored) {
4964
+ continue;
4965
+ }
4966
+ height = Math.max(height, Math.ceil(rect.bottom), measureBodyContentHeight(depth - 1, element));
4967
+ }
4968
+ return height;
4969
+ }
4945
4970
 
4946
4971
  const useCanvasGeometryUpdates = ({ tree, canvasMode }) => {
4947
4972
  const debouncedUpdateGeometry = useMemo(() => debounce((tree, sourceEvent) => {