Skip to content

Commit

Permalink
Prevent resizing row child element completely over adjacent element (#…
Browse files Browse the repository at this point in the history
…732)

Prevent resizing row child element over adjacent element
  • Loading branch information
apedroferreira authored Aug 4, 2022
1 parent ef6ee80 commit 8fcc7e1
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1137,9 +1137,14 @@ export default function RenderOverlay({ canvasHostRef }: RenderOverlayProps) {

const minGridColumnWidth = overlayGridRef.current.getMinColumnWidth();

const previousSibling = appDom.getSiblingBeforeNode(dom, draggedNode, 'children');
const previousSiblingInfo = previousSibling && nodesInfo[previousSibling.id];
const previousSiblingRect = previousSiblingInfo?.rect;

if (
draggedEdge === RECTANGLE_EDGE_LEFT &&
cursorPos.x > parentRect.x + minGridColumnWidth &&
cursorPos.x >
Math.max(parentRect.x, previousSiblingRect?.x || 0) + minGridColumnWidth &&
cursorPos.x < draggedNodeRect.x + draggedNodeRect.width - minGridColumnWidth
) {
const updatedTransformScale =
Expand All @@ -1148,10 +1153,20 @@ export default function RenderOverlay({ canvasHostRef }: RenderOverlayProps) {
resizePreviewElement.style.transformOrigin = '100% 50%';
resizePreviewElement.style.transform = `scaleX(${updatedTransformScale})`;
}

const nextSibling = appDom.getSiblingAfterNode(dom, draggedNode, 'children');
const nextSiblingInfo = nextSibling && nodesInfo[nextSibling.id];
const nextSiblingRect = nextSiblingInfo?.rect;

if (
draggedEdge === RECTANGLE_EDGE_RIGHT &&
cursorPos.x > draggedNodeRect.x + minGridColumnWidth &&
cursorPos.x < parentRect.x + parentRect.width - minGridColumnWidth
cursorPos.x <
Math.min(
parentRect.x + parentRect.width,
nextSiblingRect ? nextSiblingRect?.x + nextSiblingRect?.width : 0,
) -
minGridColumnWidth
) {
const updatedTransformScale = snappedToGridCursorRelativePosX / draggedNodeRect.width;

Expand Down

0 comments on commit 8fcc7e1

Please sign in to comment.