From f411f5b560613a1fc0b9d6543e484a59daff6373 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Wed, 18 Jan 2023 18:24:58 +0100 Subject: [PATCH] chore(core): cleanup Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> --- .../core/src/components/Nodes/NodeWrapper.vue | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/core/src/components/Nodes/NodeWrapper.vue b/packages/core/src/components/Nodes/NodeWrapper.vue index 51ae5c5f..60e13095 100644 --- a/packages/core/src/components/Nodes/NodeWrapper.vue +++ b/packages/core/src/components/Nodes/NodeWrapper.vue @@ -141,20 +141,31 @@ watch( watch([() => node.extent, () => nodeExtent], ([nodeExtent, globalExtent], [oldNodeExtent, oldGlobalExtent]) => { // update position if extent has actually changed if (nodeExtent !== oldNodeExtent || globalExtent !== oldGlobalExtent) { - // todo: can we solve this without a timeout? Without the timeout the initial extent is not properly calculated - setTimeout(clampPosition, 1) + if (isParentExtent()) { + // todo: can we solve this without a timeout? Without the timeout the initial extent is not properly calculated + setTimeout(clampPosition, 1) + } else { + clampPosition() + } } }) // clamp initial position to nodes' extent -if (node.extent === 'parent' || typeof node.extent === 'object') { +// if extent is parent, we need dimensions to properly clamp the position +if (isParentExtent()) { until(() => node.initialized) .toBe(true) .then(clampPosition) -} else { +} +// if extent is not parent, we can clamp it immediately +else { clampPosition() } +function isParentExtent() { + return node.extent === 'parent' || (typeof node.extent === 'object' && 'range' in node.extent && node.extent.range === 'parent') +} + /** this re-calculates the current position, necessary for clamping by a node's extent */ function clampPosition() { const { computedPosition, position } = calcNextPosition(node, node.computedPosition, nodeExtent, parentNode)