From 1eac14129b9c5e851f5cd92c7c3946b895dce40e Mon Sep 17 00:00:00 2001 From: moklick Date: Mon, 26 Jun 2023 18:14:06 +0200 Subject: [PATCH] refactor(nodeExtent): include node width and height --- packages/system/src/utils/graph.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/system/src/utils/graph.ts b/packages/system/src/utils/graph.ts index 327adea6..d4f70370 100644 --- a/packages/system/src/utils/graph.ts +++ b/packages/system/src/utils/graph.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { boxToRect, - clamp, clampPosition, getBoundsOfBoxes, getOverlappingArea, @@ -203,6 +202,13 @@ export function fitView, Options exte return false; } +function clampNodeExtent(node: NodeDragItem | Node, extent?: CoordinateExtent | 'parent') { + if (!extent || extent === 'parent') { + return extent; + } + return [extent[0], [extent[1][0] - (node.width || 0), extent[1][1] - (node.height || 0)]]; +} + export function calcNextPosition( node: NodeDragItem | NodeType, nextPosition: XYPosition, @@ -211,7 +217,8 @@ export function calcNextPosition( nodeOrigin: NodeOrigin = [0, 0], onError?: OnError ): { position: XYPosition; positionAbsolute: XYPosition } { - let currentExtent = node.extent || nodeExtent; + const clampedNodeExtent = clampNodeExtent(node, node.extent || nodeExtent); + let currentExtent = clampedNodeExtent; let parentNode: NodeType | null = null; let parentPos = { x: 0, y: 0 }; @@ -238,7 +245,7 @@ export function calcNextPosition( : currentExtent; } else { onError?.('005', errorMessages['error005']()); - currentExtent = nodeExtent; + currentExtent = clampedNodeExtent; } } else if (node.extent && node.parentNode) { currentExtent = [