chore(nodes): move update position into own function
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useDrag, useVueFlow } from '../../composables'
|
import { useDrag, useVueFlow } from '../../composables'
|
||||||
import type { NodeComponent, SnapGrid } from '../../types'
|
import type { NodeComponent, SnapGrid, XYZPosition } from '../../types'
|
||||||
import { NodeId } from '../../context'
|
import { NodeId } from '../../context'
|
||||||
import { getConnectedEdges, getHandleBounds, getXYZPos, handleNodeClick } from '../../utils'
|
import { getConnectedEdges, getHandleBounds, getXYZPos, handleNodeClick } from '../../utils'
|
||||||
|
|
||||||
@@ -67,26 +67,26 @@ watch(
|
|||||||
{ flush: 'post' },
|
{ flush: 'post' },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const updatePosition = (nodePos: XYZPosition, parentPos?: XYZPosition) => {
|
||||||
|
if (parentPos) {
|
||||||
|
node.computedPosition = getXYZPos({ x: parentPos.x, y: parentPos.y, z: parentPos.z! }, nodePos)
|
||||||
|
} else {
|
||||||
|
node.computedPosition = nodePos
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onUpdateNodeInternals((updateIds) => {
|
onUpdateNodeInternals((updateIds) => {
|
||||||
if (updateIds.includes(id)) {
|
if (updateIds.includes(id)) {
|
||||||
updateNodeDimensions([{ id, nodeElement: nodeElement.value, forceUpdate: true }])
|
updateNodeDimensions([{ id, nodeElement: nodeElement.value, forceUpdate: true }])
|
||||||
|
|
||||||
const xyzPos = {
|
updatePosition(
|
||||||
x: node.position.x,
|
{
|
||||||
y: node.position.y,
|
x: node.position.x,
|
||||||
z: node.computedPosition.z ? node.computedPosition.z : node.selected ? 1000 : 0,
|
y: node.position.y,
|
||||||
}
|
z: node.computedPosition.z ? node.computedPosition.z : node.selected ? 1000 : 0,
|
||||||
|
},
|
||||||
if (parentNode) {
|
parentNode ? { ...parentNode.computedPosition } : undefined,
|
||||||
if (parentNode.computedPosition.x && parentNode.computedPosition.y) {
|
)
|
||||||
node.computedPosition = getXYZPos(
|
|
||||||
{ x: parentNode.computedPosition.x, y: parentNode.computedPosition.y, z: parentNode.computedPosition.z! },
|
|
||||||
xyzPos,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
node.computedPosition = xyzPos
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -113,11 +113,7 @@ onMounted(() => {
|
|||||||
z: node.computedPosition.z ? node.computedPosition.z : node.selected ? 1000 : 0,
|
z: node.computedPosition.z ? node.computedPosition.z : node.selected ? 1000 : 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parentX && parentY) {
|
updatePosition(xyzPos, parentX && parentY ? { x: parentX, y: parentY, z: parentZ! } : undefined)
|
||||||
node.computedPosition = getXYZPos({ x: parentX, y: parentY, z: parentZ! }, xyzPos)
|
|
||||||
} else {
|
|
||||||
node.computedPosition = xyzPos
|
|
||||||
}
|
|
||||||
|
|
||||||
node.handleBounds = getHandleBounds(nodeElement.value, viewport.zoom)
|
node.handleBounds = getHandleBounds(nodeElement.value, viewport.zoom)
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user