chore(core): cleanup
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -18,27 +18,26 @@ interface UseDragParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function useDrag(params: UseDragParams) {
|
function useDrag(params: UseDragParams) {
|
||||||
|
const {
|
||||||
const {
|
vueFlowRef,
|
||||||
vueFlowRef,
|
snapToGrid,
|
||||||
snapToGrid,
|
snapGrid,
|
||||||
snapGrid,
|
noDragClassName,
|
||||||
noDragClassName,
|
nodes,
|
||||||
nodes,
|
nodeExtent,
|
||||||
nodeExtent,
|
viewport,
|
||||||
viewport,
|
autoPanOnNodeDrag,
|
||||||
autoPanOnNodeDrag,
|
nodesDraggable,
|
||||||
nodesDraggable,
|
panBy,
|
||||||
panBy,
|
findNode,
|
||||||
findNode,
|
multiSelectionActive,
|
||||||
multiSelectionActive,
|
nodesSelectionActive,
|
||||||
nodesSelectionActive,
|
selectNodesOnDrag,
|
||||||
selectNodesOnDrag,
|
removeSelectedElements,
|
||||||
removeSelectedElements,
|
addSelectedNodes,
|
||||||
addSelectedNodes,
|
updateNodePositions,
|
||||||
updateNodePositions,
|
emits,
|
||||||
emits,
|
} = $(useVueFlow())
|
||||||
} = $(useVueFlow())
|
|
||||||
|
|
||||||
const { onStart, onDrag, onStop, el, disabled, id, selectable } = params
|
const { onStart, onDrag, onStop, el, disabled, id, selectable } = params
|
||||||
|
|
||||||
@@ -56,11 +55,11 @@ function useDrag(params: UseDragParams) {
|
|||||||
|
|
||||||
let autoPanId = $ref(0)
|
let autoPanId = $ref(0)
|
||||||
let autoPanStarted = $ref(false)
|
let autoPanStarted = $ref(false)
|
||||||
let previousTransform = $ref<XYPosition>({ x: 0, y: 0 })
|
let previousTransform = $ref<XYPosition>({ x: 0, y: 0 })
|
||||||
|
|
||||||
const getPointerPosition = useGetPointerPosition()
|
const getPointerPosition = useGetPointerPosition()
|
||||||
|
|
||||||
const updateNodes = ({ x, y }: XYPosition, onBeforeUpdate: (position: XYPosition) => XYPosition = (xyPos) => xyPos) => {
|
const updateNodes = ({ x, y }: XYPosition) => {
|
||||||
lastPos = { x, y }
|
lastPos = { x, y }
|
||||||
|
|
||||||
let hasChange = false
|
let hasChange = false
|
||||||
@@ -73,7 +72,7 @@ function useDrag(params: UseDragParams) {
|
|||||||
nextPosition.y = snapGrid[1] * Math.round(nextPosition.y / snapGrid[1])
|
nextPosition.y = snapGrid[1] * Math.round(nextPosition.y / snapGrid[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
let { computedPosition } = calcNextPosition(
|
const { computedPosition } = calcNextPosition(
|
||||||
n,
|
n,
|
||||||
nextPosition,
|
nextPosition,
|
||||||
emits.error,
|
emits.error,
|
||||||
@@ -81,9 +80,7 @@ function useDrag(params: UseDragParams) {
|
|||||||
n.parentNode ? findNode(n.parentNode) : undefined,
|
n.parentNode ? findNode(n.parentNode) : undefined,
|
||||||
)
|
)
|
||||||
|
|
||||||
computedPosition = onBeforeUpdate(computedPosition)
|
// we want to make sure that we only fire a change event when there is a change
|
||||||
|
|
||||||
// we want to make sure that we only fire a change event when there is a change
|
|
||||||
hasChange = hasChange || n.position.x !== computedPosition.x || n.position.y !== computedPosition.y
|
hasChange = hasChange || n.position.x !== computedPosition.x || n.position.y !== computedPosition.y
|
||||||
|
|
||||||
n.position = computedPosition
|
n.position = computedPosition
|
||||||
@@ -112,30 +109,28 @@ function useDrag(params: UseDragParams) {
|
|||||||
|
|
||||||
const autoPan = (): void => {
|
const autoPan = (): void => {
|
||||||
if (!containerBounds) {
|
if (!containerBounds) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const [xMovement, yMovement] = calcAutoPan(mousePosition, containerBounds)
|
const [xMovement, yMovement] = calcAutoPan(mousePosition, containerBounds)
|
||||||
|
|
||||||
if (xMovement !== 0 || yMovement !== 0) {
|
if (xMovement !== 0 || yMovement !== 0) {
|
||||||
const nextPos = {
|
const nextPos = {
|
||||||
x: (lastPos.x ?? 0) - xMovement / viewport.zoom,
|
x: (lastPos.x ?? 0) - xMovement / viewport.zoom,
|
||||||
y: (lastPos.y ?? 0) - yMovement / viewport.zoom,
|
y: (lastPos.y ?? 0) - yMovement / viewport.zoom,
|
||||||
}
|
}
|
||||||
|
|
||||||
panBy({ x: xMovement, y: yMovement }, (transform) => {
|
panBy({ x: xMovement, y: yMovement }, (transform) => {
|
||||||
if (
|
if (
|
||||||
Math.round(transform.x) !== Math.round(previousTransform.x) ||
|
Math.round(transform.x) !== Math.round(previousTransform.x) ||
|
||||||
Math.round(transform.y) !== Math.round(previousTransform.y)
|
Math.round(transform.y) !== Math.round(previousTransform.y)
|
||||||
) {
|
) {
|
||||||
previousTransform = transform
|
updateNodes(nextPos)
|
||||||
|
previousTransform = transform
|
||||||
updateNodes(nextPos)
|
lastPos = nextPos
|
||||||
|
}
|
||||||
lastPos = nextPos
|
})
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
autoPanId = requestAnimationFrame(autoPan)
|
autoPanId = requestAnimationFrame(autoPan)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user