refactor(core,nodes): remove snapGrid option from nodes - use global one instead

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2022-12-25 11:32:15 +01:00
committed by Braks
parent 4260e3158f
commit 2b513b5ae7
3 changed files with 4 additions and 9 deletions

View File

@@ -10,7 +10,6 @@ const { id, type, name, draggable, selectable, connectable, ...props } = defineP
selectable: boolean
connectable: HandleConnectable
focusable: boolean
snapGrid?: SnapGrid
type: NodeComponent | Function | Object | false
name: string
node: GraphNode
@@ -213,8 +212,6 @@ const onKeyDown = (event: KeyboardEvent) => {
x: arrowKeyDiffs[event.key].x,
y: arrowKeyDiffs[event.key].y,
},
!!props.snapGrid,
props.snapGrid,
event.shiftKey,
)
}

View File

@@ -1,13 +1,13 @@
import type { NodeDragItem, SnapGrid, XYPosition } from '~/types'
function useUpdateNodePositions() {
const { getSelectedNodes, nodeExtent, updateNodePositions, findNode } = useVueFlow()
const { getSelectedNodes, nodeExtent, updateNodePositions, findNode, snapGrid, snapToGrid } = useVueFlow()
return (positionDiff: XYPosition, snapToGrid: boolean, snapGrid: SnapGrid | undefined, isShiftPressed = false) => {
return (positionDiff: XYPosition, isShiftPressed = false) => {
// by default a node moves 5px on each key press, or 20px if shift is pressed
// if snap grid is enabled, we use that for the velocity.
const xVelo = snapToGrid && snapGrid ? snapGrid[0] : 5
const yVelo = snapToGrid && snapGrid ? snapGrid[1] : 5
const xVelo = snapToGrid.value ? snapGrid.value[0] : 5
const yVelo = snapToGrid.value ? snapGrid.value[1] : 5
const factor = isShiftPressed ? 4 : 1
const positionDiffX = positionDiff.x * xVelo * factor

View File

@@ -34,8 +34,6 @@ export interface Node<Data = ElementData, CustomEvents extends Record<string, Cu
connectable?: HandleConnectable
focusable?: boolean
dragHandle?: string
/** move on grid */
snapGrid?: SnapGrid
/** called when used as target for new connection */
isValidTargetPos?: ValidConnectionFunc
/** called when used as source for new connection */