fix(core): drag position update

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2022-12-20 00:38:56 +01:00
committed by Braks
parent 6df5746064
commit dd1b15029d
4 changed files with 12 additions and 26 deletions
@@ -134,6 +134,7 @@ watch(
function updatePosition(nodePos: XYZPosition, parentPos?: XYZPosition) { function updatePosition(nodePos: XYZPosition, parentPos?: XYZPosition) {
let nextPos = nodePos let nextPos = nodePos
if (parentPos) { if (parentPos) {
nextPos = getXYZPos({ x: parentPos.x, y: parentPos.y, z: parentPos.z! }, nodePos) nextPos = getXYZPos({ x: parentPos.x, y: parentPos.y, z: parentPos.z! }, nodePos)
} }
@@ -145,21 +146,21 @@ onNodesInitialized(() => {
initialized.value = true initialized.value = true
}) })
until(initialized) onMounted(() => {
.toBe(true) until(initialized)
.then(() => { .toBe(true)
const { computedPosition, position } = calcNextPosition(node, node.position, nodeExtent, parentNode) .then(() => {
const { position } = calcNextPosition(node, node.computedPosition, nodeExtent, parentNode)
node.computedPosition = { ...node.computedPosition, ...computedPosition } node.computedPosition = { ...node.computedPosition, ...position }
node.position = position })
}) })
function updateInternals() { function updateInternals() {
if (nodeElement.value) updateNodeDimensions([{ id, nodeElement: nodeElement.value, forceUpdate: true }]) 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 node.position = position
} }
+1 -2
View File
@@ -98,7 +98,7 @@ function useDrag(params: UseDragParams) {
nextPosition.y = snapY * Math.round(nextPosition.y / snapY) nextPosition.y = snapY * Math.round(nextPosition.y / snapY)
} }
const { computedPosition, position } = calcNextPosition( const { position } = calcNextPosition(
n, n,
nextPosition, nextPosition,
nodeExtent, 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 // 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 hasChange = hasChange || n.position.x !== nextPosition.x || n.position.y !== nextPosition.y
n.computedPosition = { ...n.computedPosition, ...computedPosition }
n.position = position n.position = position
return n return n
-2
View File
@@ -6,8 +6,6 @@ export interface NodeDragItem {
id: string id: string
// relative node position (to parent) // relative node position (to parent)
position: XYPosition position: XYPosition
// absolute node position
computedPosition: XYZPosition
// distance from the mouse cursor to the node when start dragging // distance from the mouse cursor to the node when start dragging
distance: XYPosition distance: XYPosition
dimensions: Dimensions dimensions: Dimensions
+1 -13
View File
@@ -27,7 +27,6 @@ export function getDragItems(
markRaw({ markRaw({
id: n.id, id: n.id,
position: n.position || { x: 0, y: 0 }, position: n.position || { x: 0, y: 0 },
computedPosition: n.computedPosition || { x: 0, y: 0, z: 1 },
distance: { distance: {
x: mousePos.x - n.computedPosition?.x || 0, x: mousePos.x - n.computedPosition?.x || 0,
y: mousePos.y - n.computedPosition?.y || 0, y: mousePos.y - n.computedPosition?.y || 0,
@@ -106,18 +105,7 @@ export const calcNextPosition = (
const clampedPos = clampPosition(nextPosition, extent) const clampedPos = clampPosition(nextPosition, extent)
const parentPosition = { x: 0, y: 0 }
if (parentNode) {
parentPosition.x = parentNode.computedPosition.x
parentPosition.y = parentNode.computedPosition.y
}
return { return {
position: { position: clampedPos,
x: clampedPos.x - parentPosition.x,
y: clampedPos.y - parentPosition.y,
},
computedPosition: clampedPos,
} }
} }