From 6753c19188251df201affa7934e5aa0fcfc431b5 Mon Sep 17 00:00:00 2001 From: moklick Date: Wed, 3 Apr 2024 10:16:47 +0200 Subject: [PATCH] fix(parentExpand): prevent jumping --- packages/system/src/utils/store.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/system/src/utils/store.ts b/packages/system/src/utils/store.ts index c404c0f9..47b4f7f5 100644 --- a/packages/system/src/utils/store.ts +++ b/packages/system/src/utils/store.ts @@ -54,7 +54,10 @@ export function updateAbsolutePositions( node.internals.positionAbsolute = positionChanged ? { x, y } : currPosition; node.internals.z = z; - node.internals.isParent = !!parentNodeIds?.has(id); + + if (parentNodeIds !== undefined) { + node.internals.isParent = !!parentNodeIds?.has(id); + } nodeLookup.set(id, node); } @@ -164,12 +167,9 @@ export function handleParentExpand(nodes: InternalNodeBase[], nodeLookup: NodeLo const { position } = getNodePositionWithOrigin(origParent, origParent.origin); const dimensions = getNodeDimensions(origParent); - let xChange = null; - let yChange = null; - if (rect.x < position.x || rect.y < position.y) { - xChange = Math.abs(position.x - rect.x); - yChange = Math.abs(position.y - rect.y); + const xChange = Math.round(Math.abs(position.x - rect.x)); + const yChange = Math.round(Math.abs(position.y - rect.y)); changes.push({ id, @@ -180,10 +180,18 @@ export function handleParentExpand(nodes: InternalNodeBase[], nodeLookup: NodeLo }, }); - // @todo we need to reset child node positions if < 0 - } + changes.push({ + id, + type: 'dimensions', + resizing: true, + dimensions: { + width: dimensions.width + xChange, + height: dimensions.height + yChange, + }, + }); - if (dimensions.width < rect.width || dimensions.height < rect.height) { + // @todo we need to reset child node positions if < 0 + } else if (dimensions.width < rect.width || dimensions.height < rect.height) { changes.push({ id, type: 'dimensions',