chore(core): cleanup useUpdateNodePositions

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2022-12-25 11:44:04 +01:00
committed by Braks
parent 089859d837
commit f319f6249d

View File

@@ -1,4 +1,4 @@
import type { NodeDragItem, SnapGrid, XYPosition } from '~/types'
import type { NodeDragItem, XYPosition } from '~/types'
function useUpdateNodePositions() {
const { getSelectedNodes, nodeExtent, updateNodePositions, findNode, snapGrid, snapToGrid } = useVueFlow()
@@ -13,24 +13,18 @@ function useUpdateNodePositions() {
const positionDiffX = positionDiff.x * xVelo * factor
const positionDiffY = positionDiff.y * yVelo * factor
const nodeUpdates = getSelectedNodes.value.flatMap((n) => {
if (n.computedPosition) {
const nextPosition = { x: n.computedPosition.x + positionDiffX, y: n.computedPosition.y + positionDiffY }
const nodeUpdates = getSelectedNodes.value.map((n) => {
const nextPosition = { x: n.computedPosition.x + positionDiffX, y: n.computedPosition.y + positionDiffY }
const updatedPos = calcNextPosition(n, nextPosition, nodeExtent.value, n.parentNode ? findNode(n.parentNode) : undefined)
const updatedPos = calcNextPosition(n, nextPosition, nodeExtent.value, n.parentNode ? findNode(n.parentNode) : undefined)
return [
{
id: n.id,
position: updatedPos.position,
from: n.position,
distance: { x: positionDiff.x, y: positionDiff.y },
dimensions: n.dimensions,
},
] as NodeDragItem[]
}
return []
return {
id: n.id,
position: updatedPos.position,
from: n.position,
distance: { x: positionDiff.x, y: positionDiff.y },
dimensions: n.dimensions,
} as NodeDragItem
})
updateNodePositions(nodeUpdates, true, false)