feat(core): add pan on connection drag
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -35,7 +35,9 @@ export default function useHandle({
|
|||||||
connectionClickStartHandle,
|
connectionClickStartHandle,
|
||||||
nodesConnectable,
|
nodesConnectable,
|
||||||
defaultEdgeOptions,
|
defaultEdgeOptions,
|
||||||
|
autoPanOnConnect,
|
||||||
findNode,
|
findNode,
|
||||||
|
panBy,
|
||||||
getNodes,
|
getNodes,
|
||||||
startConnection,
|
startConnection,
|
||||||
updateConnection,
|
updateConnection,
|
||||||
@@ -61,6 +63,8 @@ export default function useHandle({
|
|||||||
|
|
||||||
let prevClosestHandle: ConnectionHandle | null
|
let prevClosestHandle: ConnectionHandle | null
|
||||||
|
|
||||||
|
let autoPanId = 0
|
||||||
|
|
||||||
const { x, y } = getEventPosition(event)
|
const { x, y } = getEventPosition(event)
|
||||||
const clickedHandle = doc?.elementFromPoint(x, y)
|
const clickedHandle = doc?.elementFromPoint(x, y)
|
||||||
const handleType = getHandleType(unref(edgeUpdaterType), clickedHandle)
|
const handleType = getHandleType(unref(edgeUpdaterType), clickedHandle)
|
||||||
@@ -72,6 +76,7 @@ export default function useHandle({
|
|||||||
|
|
||||||
let prevActiveHandle: Element
|
let prevActiveHandle: Element
|
||||||
let connectionPosition = getEventPosition(event, containerBounds)
|
let connectionPosition = getEventPosition(event, containerBounds)
|
||||||
|
let autoPanStarted = false
|
||||||
|
|
||||||
const handleLookup = getHandleLookup({
|
const handleLookup = getHandleLookup({
|
||||||
nodes: getNodes.value,
|
nodes: getNodes.value,
|
||||||
@@ -80,6 +85,17 @@ export default function useHandle({
|
|||||||
handleType,
|
handleType,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// when the user is moving the mouse close to the edge of the canvas while connecting we move the canvas
|
||||||
|
const autoPan = () => {
|
||||||
|
if (!autoPanOnConnect) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const [xMovement, yMovement] = calcAutoPan(connectionPosition, containerBounds)
|
||||||
|
|
||||||
|
panBy({ x: xMovement, y: yMovement })
|
||||||
|
autoPanId = requestAnimationFrame(autoPan)
|
||||||
|
}
|
||||||
|
|
||||||
startConnection(
|
startConnection(
|
||||||
{
|
{
|
||||||
nodeId: unref(nodeId),
|
nodeId: unref(nodeId),
|
||||||
@@ -104,6 +120,11 @@ export default function useHandle({
|
|||||||
handleLookup,
|
handleLookup,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (!autoPanStarted) {
|
||||||
|
autoPan()
|
||||||
|
autoPanStarted = true
|
||||||
|
}
|
||||||
|
|
||||||
const { connection, handleDomNode, isValid } = isValidHandle(
|
const { connection, handleDomNode, isValid } = isValidHandle(
|
||||||
event,
|
event,
|
||||||
prevClosestHandle,
|
prevClosestHandle,
|
||||||
@@ -140,6 +161,9 @@ export default function useHandle({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onPointerUp(event: MouseEvent | TouchEvent) {
|
function onPointerUp(event: MouseEvent | TouchEvent) {
|
||||||
|
cancelAnimationFrame(autoPanId)
|
||||||
|
autoPanStarted = false
|
||||||
|
|
||||||
if (prevClosestHandle) {
|
if (prevClosestHandle) {
|
||||||
const { connection, isValid } = isValidHandle(
|
const { connection, isValid } = isValidHandle(
|
||||||
event,
|
event,
|
||||||
|
|||||||
Reference in New Issue
Block a user