From dd1b15029d7bd03b2a5900514aa9bccd4d0da1cd Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Mon, 19 Dec 2022 23:48:16 +0100 Subject: [PATCH] fix(core): drag position update Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> --- .../core/src/components/Nodes/NodeWrapper.vue | 19 ++++++++++--------- packages/core/src/composables/useDrag.ts | 3 +-- packages/core/src/types/changes.ts | 2 -- packages/core/src/utils/drag.ts | 14 +------------- 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/packages/core/src/components/Nodes/NodeWrapper.vue b/packages/core/src/components/Nodes/NodeWrapper.vue index 732b3e81..3c6a7e50 100644 --- a/packages/core/src/components/Nodes/NodeWrapper.vue +++ b/packages/core/src/components/Nodes/NodeWrapper.vue @@ -134,6 +134,7 @@ watch( function updatePosition(nodePos: XYZPosition, parentPos?: XYZPosition) { let nextPos = nodePos + if (parentPos) { nextPos = getXYZPos({ x: parentPos.x, y: parentPos.y, z: parentPos.z! }, nodePos) } @@ -145,21 +146,21 @@ onNodesInitialized(() => { initialized.value = true }) -until(initialized) - .toBe(true) - .then(() => { - const { computedPosition, position } = calcNextPosition(node, node.position, nodeExtent, parentNode) +onMounted(() => { + until(initialized) + .toBe(true) + .then(() => { + const { position } = calcNextPosition(node, node.computedPosition, nodeExtent, parentNode) - node.computedPosition = { ...node.computedPosition, ...computedPosition } - node.position = position - }) + node.computedPosition = { ...node.computedPosition, ...position } + }) +}) function updateInternals() { if (nodeElement.value) updateNodeDimensions([{ id, nodeElement: nodeElement.value, forceUpdate: true }]) - const { computedPosition, position } = calcNextPosition(node, node.position, nodeExtent, parentNode) + const { position } = calcNextPosition(node, node.position, nodeExtent, parentNode) - node.computedPosition = { ...node.computedPosition, ...computedPosition } node.position = position } diff --git a/packages/core/src/composables/useDrag.ts b/packages/core/src/composables/useDrag.ts index 646c3f76..cd53c4fb 100644 --- a/packages/core/src/composables/useDrag.ts +++ b/packages/core/src/composables/useDrag.ts @@ -98,7 +98,7 @@ function useDrag(params: UseDragParams) { nextPosition.y = snapY * Math.round(nextPosition.y / snapY) } - const { computedPosition, position } = calcNextPosition( + const { position } = calcNextPosition( n, nextPosition, nodeExtent, @@ -108,7 +108,6 @@ function useDrag(params: UseDragParams) { // we want to make sure that we only fire a change event when there is a changes hasChange = hasChange || n.position.x !== nextPosition.x || n.position.y !== nextPosition.y - n.computedPosition = { ...n.computedPosition, ...computedPosition } n.position = position return n diff --git a/packages/core/src/types/changes.ts b/packages/core/src/types/changes.ts index c2b7b5aa..1b8330ed 100644 --- a/packages/core/src/types/changes.ts +++ b/packages/core/src/types/changes.ts @@ -6,8 +6,6 @@ export interface NodeDragItem { id: string // relative node position (to parent) position: XYPosition - // absolute node position - computedPosition: XYZPosition // distance from the mouse cursor to the node when start dragging distance: XYPosition dimensions: Dimensions diff --git a/packages/core/src/utils/drag.ts b/packages/core/src/utils/drag.ts index e25912d2..49b15a24 100644 --- a/packages/core/src/utils/drag.ts +++ b/packages/core/src/utils/drag.ts @@ -27,7 +27,6 @@ export function getDragItems( markRaw({ id: n.id, position: n.position || { x: 0, y: 0 }, - computedPosition: n.computedPosition || { x: 0, y: 0, z: 1 }, distance: { x: mousePos.x - n.computedPosition?.x || 0, y: mousePos.y - n.computedPosition?.y || 0, @@ -106,18 +105,7 @@ export const calcNextPosition = ( const clampedPos = clampPosition(nextPosition, extent) - const parentPosition = { x: 0, y: 0 } - - if (parentNode) { - parentPosition.x = parentNode.computedPosition.x - parentPosition.y = parentNode.computedPosition.y - } - return { - position: { - x: clampedPos.x - parentPosition.x, - y: clampedPos.y - parentPosition.y, - }, - computedPosition: clampedPos, + position: clampedPos, } }