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 17:38:56 +01:00
committed by Braks
parent 4260e3158f
commit 2b513b5ae7
3 changed files with 4 additions and 9 deletions
@@ -10,7 +10,6 @@ const { id, type, name, draggable, selectable, connectable, ...props } = defineP
selectable: boolean selectable: boolean
connectable: HandleConnectable connectable: HandleConnectable
focusable: boolean focusable: boolean
snapGrid?: SnapGrid
type: NodeComponent | Function | Object | false type: NodeComponent | Function | Object | false
name: string name: string
node: GraphNode node: GraphNode
@@ -213,8 +212,6 @@ const onKeyDown = (event: KeyboardEvent) => {
x: arrowKeyDiffs[event.key].x, x: arrowKeyDiffs[event.key].x,
y: arrowKeyDiffs[event.key].y, y: arrowKeyDiffs[event.key].y,
}, },
!!props.snapGrid,
props.snapGrid,
event.shiftKey, event.shiftKey,
) )
} }
@@ -1,13 +1,13 @@
import type { NodeDragItem, SnapGrid, XYPosition } from '~/types' import type { NodeDragItem, SnapGrid, XYPosition } from '~/types'
function useUpdateNodePositions() { 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 // 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. // if snap grid is enabled, we use that for the velocity.
const xVelo = snapToGrid && snapGrid ? snapGrid[0] : 5 const xVelo = snapToGrid.value ? snapGrid.value[0] : 5
const yVelo = snapToGrid && snapGrid ? snapGrid[1] : 5 const yVelo = snapToGrid.value ? snapGrid.value[1] : 5
const factor = isShiftPressed ? 4 : 1 const factor = isShiftPressed ? 4 : 1
const positionDiffX = positionDiff.x * xVelo * factor const positionDiffX = positionDiff.x * xVelo * factor
-2
View File
@@ -34,8 +34,6 @@ export interface Node<Data = ElementData, CustomEvents extends Record<string, Cu
connectable?: HandleConnectable connectable?: HandleConnectable
focusable?: boolean focusable?: boolean
dragHandle?: string dragHandle?: string
/** move on grid */
snapGrid?: SnapGrid
/** called when used as target for new connection */ /** called when used as target for new connection */
isValidTargetPos?: ValidConnectionFunc isValidTargetPos?: ValidConnectionFunc
/** called when used as source for new connection */ /** called when used as source for new connection */