fix(reconnect): use connectionDragThreshold
This commit is contained in:
@@ -1,5 +1,12 @@
|
|||||||
// Reconnectable edges have a anchors around their handles to reconnect the edge.
|
// Reconnectable edges have a anchors around their handles to reconnect the edge.
|
||||||
import { XYHandle, type Connection, EdgePosition, FinalConnectionState, HandleType } from '@xyflow/system';
|
import {
|
||||||
|
XYHandle,
|
||||||
|
type Connection,
|
||||||
|
EdgePosition,
|
||||||
|
FinalConnectionState,
|
||||||
|
HandleType,
|
||||||
|
OnConnectStart,
|
||||||
|
} from '@xyflow/system';
|
||||||
|
|
||||||
import { EdgeAnchor } from '../Edges/EdgeAnchor';
|
import { EdgeAnchor } from '../Edges/EdgeAnchor';
|
||||||
import type { EdgeWrapperProps, Edge } from '../../types/edges';
|
import type { EdgeWrapperProps, Edge } from '../../types/edges';
|
||||||
@@ -60,15 +67,17 @@ export function EdgeUpdateAnchors<EdgeType extends Edge = Edge>({
|
|||||||
} = store.getState();
|
} = store.getState();
|
||||||
const isTarget = oppositeHandle.type === 'target';
|
const isTarget = oppositeHandle.type === 'target';
|
||||||
|
|
||||||
setReconnecting(true);
|
|
||||||
onReconnectStart?.(event, edge, oppositeHandle.type);
|
|
||||||
|
|
||||||
const _onReconnectEnd = (evt: MouseEvent | TouchEvent, connectionState: FinalConnectionState) => {
|
const _onReconnectEnd = (evt: MouseEvent | TouchEvent, connectionState: FinalConnectionState) => {
|
||||||
setReconnecting(false);
|
setReconnecting(false);
|
||||||
onReconnectEnd?.(evt, edge, oppositeHandle.type, connectionState);
|
onReconnectEnd?.(evt, edge, oppositeHandle.type, connectionState);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onConnectEdge = (connection: Connection) => onReconnect?.(edge, connection);
|
const onConnectEdge = (connection: Connection) => onReconnect?.(edge, connection);
|
||||||
|
const _onConnectStart: OnConnectStart = (_event, params) => {
|
||||||
|
setReconnecting(true);
|
||||||
|
onReconnectStart?.(event, edge, oppositeHandle.type);
|
||||||
|
onConnectStart?.(_event, params);
|
||||||
|
};
|
||||||
|
|
||||||
XYHandle.onPointerDown(event.nativeEvent, {
|
XYHandle.onPointerDown(event.nativeEvent, {
|
||||||
autoPanOnConnect,
|
autoPanOnConnect,
|
||||||
@@ -86,7 +95,7 @@ export function EdgeUpdateAnchors<EdgeType extends Edge = Edge>({
|
|||||||
panBy,
|
panBy,
|
||||||
isValidConnection,
|
isValidConnection,
|
||||||
onConnect: onConnectEdge,
|
onConnect: onConnectEdge,
|
||||||
onConnectStart,
|
onConnectStart: _onConnectStart,
|
||||||
onConnectEnd,
|
onConnectEnd,
|
||||||
onReconnectEnd: _onReconnectEnd,
|
onReconnectEnd: _onReconnectEnd,
|
||||||
updateConnection,
|
updateConnection,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { useStore } from '$lib/store';
|
import { useStore } from '$lib/store';
|
||||||
import type { Edge } from '$lib/types';
|
import type { Edge } from '$lib/types';
|
||||||
import { XYHandle, type HandleType } from '@xyflow/system';
|
import { XYHandle, type HandleType, type OnConnectStart } from '@xyflow/system';
|
||||||
import { getContext } from 'svelte';
|
import { getContext } from 'svelte';
|
||||||
import { EdgeLabel } from '../EdgeLabel';
|
import { EdgeLabel } from '../EdgeLabel';
|
||||||
import type { EdgeReconnectAnchorProps } from './types';
|
import type { EdgeReconnectAnchorProps } from './types';
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
position,
|
position,
|
||||||
class: className,
|
class: className,
|
||||||
size = 25,
|
size = 25,
|
||||||
|
dragThreshold = 1,
|
||||||
children,
|
children,
|
||||||
...rest
|
...rest
|
||||||
}: EdgeReconnectAnchorProps = $props();
|
}: EdgeReconnectAnchorProps = $props();
|
||||||
@@ -52,8 +53,11 @@
|
|||||||
let newEdge: Edge | undefined;
|
let newEdge: Edge | undefined;
|
||||||
let edge = edgeLookup.get(edgeId)!;
|
let edge = edgeLookup.get(edgeId)!;
|
||||||
|
|
||||||
reconnecting = true;
|
const _onConnectStart: OnConnectStart = (evt, params) => {
|
||||||
onreconnectstart?.(event, edge, type);
|
reconnecting = true;
|
||||||
|
onreconnectstart?.(event, edge, type);
|
||||||
|
onconnectstart?.(evt, params);
|
||||||
|
};
|
||||||
|
|
||||||
const opposite =
|
const opposite =
|
||||||
type === 'target'
|
type === 'target'
|
||||||
@@ -79,7 +83,7 @@
|
|||||||
cancelConnection,
|
cancelConnection,
|
||||||
panBy,
|
panBy,
|
||||||
isValidConnection,
|
isValidConnection,
|
||||||
onConnectStart: onconnectstart,
|
onConnectStart: _onConnectStart,
|
||||||
onConnectEnd: onconnectend,
|
onConnectEnd: onconnectend,
|
||||||
onConnect: (connection) => {
|
onConnect: (connection) => {
|
||||||
newEdge = { ...edge, ...connection };
|
newEdge = { ...edge, ...connection };
|
||||||
@@ -98,7 +102,7 @@
|
|||||||
updateConnection,
|
updateConnection,
|
||||||
getTransform: () => [store.viewport.x, store.viewport.y, store.viewport.zoom],
|
getTransform: () => [store.viewport.x, store.viewport.y, store.viewport.zoom],
|
||||||
getFromHandle: () => store.connection.fromHandle,
|
getFromHandle: () => store.connection.fromHandle,
|
||||||
dragThreshold: store.connectionDragThreshold
|
dragThreshold: dragThreshold ?? store.connectionDragThreshold
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -10,4 +10,5 @@ export type EdgeReconnectAnchorProps = {
|
|||||||
position?: XYPosition;
|
position?: XYPosition;
|
||||||
size?: number;
|
size?: number;
|
||||||
children?: Snippet;
|
children?: Snippet;
|
||||||
|
dragThreshold?: number;
|
||||||
} & HTMLAttributes<HTMLDivElement>;
|
} & HTMLAttributes<HTMLDivElement>;
|
||||||
|
|||||||
Reference in New Issue
Block a user