refactor(core): pass original event to edge update event params
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import EdgeAnchor from './EdgeAnchor'
|
||||
import type { Connection, EdgeComponent, EdgeUpdatable, GraphEdge, HandleType } from '~/types'
|
||||
import type { Connection, EdgeComponent, EdgeUpdatable, GraphEdge, HandleType, MouseTouchEvent } from '~/types'
|
||||
import { ConnectionMode, Position } from '~/types'
|
||||
|
||||
interface Props {
|
||||
@@ -24,7 +24,6 @@ const EdgeWrapper = defineComponent({
|
||||
emits,
|
||||
nodesSelectionActive,
|
||||
noPanClassName,
|
||||
getEdges,
|
||||
getEdgeTypes,
|
||||
removeSelectedEdges,
|
||||
findEdge,
|
||||
@@ -47,8 +46,6 @@ const EdgeWrapper = defineComponent({
|
||||
|
||||
const edgeUpdaterType = ref<HandleType>('source')
|
||||
|
||||
const mouseEvent = ref<MouseEvent>()
|
||||
|
||||
const edgeEl = ref<SVGElement>()
|
||||
|
||||
provide(EdgeId, props.id)
|
||||
@@ -222,13 +219,12 @@ const EdgeWrapper = defineComponent({
|
||||
mouseOver = false
|
||||
}
|
||||
|
||||
function onEdgeUpdate(connection: Connection) {
|
||||
if (!connectionExists(connection, getEdges.value)) hooks.emit.update({ edge, connection })
|
||||
function onEdgeUpdate(event: MouseTouchEvent, connection: Connection) {
|
||||
hooks.emit.update({ event, edge, connection })
|
||||
}
|
||||
|
||||
function onEdgeUpdateEnd() {
|
||||
if (!mouseEvent.value) return
|
||||
hooks.emit.updateEnd({ event: mouseEvent.value, edge })
|
||||
function onEdgeUpdateEnd(event: MouseTouchEvent) {
|
||||
hooks.emit.updateEnd({ event, edge })
|
||||
updating = false
|
||||
}
|
||||
|
||||
@@ -243,8 +239,6 @@ const EdgeWrapper = defineComponent({
|
||||
|
||||
edgeUpdaterType.value = type.value
|
||||
|
||||
mouseEvent.value = event
|
||||
|
||||
hooks.emit.updateStart({ event, edge })
|
||||
|
||||
handlePointerDown(event)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { MaybeRef } from '@vueuse/core'
|
||||
import type { Connection, ConnectionHandle, HandleType, ValidConnectionFunc } from '~/types'
|
||||
import type { Connection, ConnectionHandle, HandleType, MouseTouchEvent, ValidConnectionFunc } from '~/types'
|
||||
|
||||
interface UseHandleProps {
|
||||
handleId: MaybeRef<string | null>
|
||||
@@ -7,8 +7,8 @@ interface UseHandleProps {
|
||||
type: MaybeRef<HandleType>
|
||||
isValidConnection?: ValidConnectionFunc
|
||||
edgeUpdaterType?: MaybeRef<HandleType>
|
||||
onEdgeUpdate?: (connection: Connection) => void
|
||||
onEdgeUpdateEnd?: (event: MouseEvent | TouchEvent) => void
|
||||
onEdgeUpdate?: (event: MouseTouchEvent, connection: Connection) => void
|
||||
onEdgeUpdateEnd?: (event: MouseTouchEvent) => void
|
||||
}
|
||||
|
||||
const alwaysValid = () => true
|
||||
@@ -50,7 +50,7 @@ export default function useHandle({
|
||||
let connection: Connection | null = null
|
||||
let isValid = false
|
||||
|
||||
function handlePointerDown(event: MouseEvent | TouchEvent) {
|
||||
function handlePointerDown(event: MouseTouchEvent) {
|
||||
const isMouseTriggered = isMouseEvent(event)
|
||||
|
||||
if ((isMouseTriggered && event.button === 0) || !isMouseTriggered) {
|
||||
@@ -115,7 +115,7 @@ export default function useHandle({
|
||||
|
||||
emits.connectStart({ event, nodeId, handleId, handleType })
|
||||
|
||||
function onPointerMove(event: MouseEvent | TouchEvent) {
|
||||
function onPointerMove(event: MouseTouchEvent) {
|
||||
connectionPosition = getEventPosition(event, containerBounds)
|
||||
|
||||
prevClosestHandle = getClosestHandle(
|
||||
@@ -171,11 +171,11 @@ export default function useHandle({
|
||||
}
|
||||
}
|
||||
|
||||
function onPointerUp(event: MouseEvent | TouchEvent) {
|
||||
function onPointerUp(event: MouseTouchEvent) {
|
||||
if (prevClosestHandle) {
|
||||
if (connection && isValid) {
|
||||
if (!onEdgeUpdate) emits.connect({ ...(defaultEdgeOptions?.value || {}), ...connection })
|
||||
else onEdgeUpdate(connection)
|
||||
else onEdgeUpdate(event, connection)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user