fix(core): avoid undraggable selected nodes being dragged
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { NodeDragItem, XYPosition } from '~/types'
|
||||
|
||||
function useUpdateNodePositions() {
|
||||
const { getSelectedNodes, nodeExtent, updateNodePositions, findNode, snapGrid, snapToGrid } = useVueFlow()
|
||||
const { getSelectedNodes, nodeExtent, updateNodePositions, findNode, snapGrid, snapToGrid, nodesDraggable } = useVueFlow()
|
||||
|
||||
return (positionDiff: XYPosition, isShiftPressed = false) => {
|
||||
// by default a node moves 5px on each key press, or 20px if shift is pressed
|
||||
@@ -13,24 +13,26 @@ function useUpdateNodePositions() {
|
||||
const positionDiffX = positionDiff.x * xVelo * factor
|
||||
const positionDiffY = positionDiff.y * yVelo * factor
|
||||
|
||||
const nodeUpdates = getSelectedNodes.value.map((n) => {
|
||||
const nextPosition = { x: n.computedPosition.x + positionDiffX, y: n.computedPosition.y + positionDiffY }
|
||||
const nodeUpdates = getSelectedNodes.value
|
||||
.filter((n) => n.draggable || (nodesDraggable && typeof n.draggable === 'undefined'))
|
||||
.map((n) => {
|
||||
const nextPosition = { x: n.computedPosition.x + positionDiffX, y: n.computedPosition.y + positionDiffY }
|
||||
|
||||
const { computedPosition } = calcNextPosition(
|
||||
n,
|
||||
nextPosition,
|
||||
nodeExtent.value,
|
||||
n.parentNode ? findNode(n.parentNode) : undefined,
|
||||
)
|
||||
const { computedPosition } = calcNextPosition(
|
||||
n,
|
||||
nextPosition,
|
||||
nodeExtent.value,
|
||||
n.parentNode ? findNode(n.parentNode) : undefined,
|
||||
)
|
||||
|
||||
return {
|
||||
id: n.id,
|
||||
position: computedPosition,
|
||||
from: n.position,
|
||||
distance: { x: positionDiff.x, y: positionDiff.y },
|
||||
dimensions: n.dimensions,
|
||||
} as NodeDragItem
|
||||
})
|
||||
return {
|
||||
id: n.id,
|
||||
position: computedPosition,
|
||||
from: n.position,
|
||||
distance: { x: positionDiff.x, y: positionDiff.y },
|
||||
dimensions: n.dimensions,
|
||||
} as NodeDragItem
|
||||
})
|
||||
|
||||
updateNodePositions(nodeUpdates, true, false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user