add onselectiondrag events

This commit is contained in:
peterkogo
2025-05-13 15:54:25 +02:00
parent e6aeff4acb
commit 17646123de
5 changed files with 30 additions and 2 deletions
@@ -47,6 +47,9 @@ export default function drag<NodeType extends Node = Node, EdgeType extends Edge
nodeDragThreshold: store.nodeDragThreshold, nodeDragThreshold: store.nodeDragThreshold,
unselectNodesAndEdges: store.unselectNodesAndEdges, unselectNodesAndEdges: store.unselectNodesAndEdges,
updateNodePositions: store.updateNodePositions, updateNodePositions: store.updateNodePositions,
onSelectionDrag: store.onselectiondrag,
onSelectionDragStart: store.onselectiondragstart,
onSelectionDragStop: store.onselectiondragstop,
panBy: store.panBy panBy: store.panBy
}; };
} }
@@ -54,6 +54,9 @@
onclickconnectend, onclickconnectend,
oninit, oninit,
onselectionchange, onselectionchange,
onselectiondragstart,
onselectiondrag,
onselectiondragstop,
clickConnect, clickConnect,
fitView, fitView,
fitViewOptions, fitViewOptions,
@@ -40,7 +40,13 @@ import type {
} from '$lib/types'; } from '$lib/types';
import type { Component } from 'svelte'; import type { Component } from 'svelte';
import type { EdgeEvents, NodeEvents, NodeSelectionEvents, PaneEvents } from '$lib/types/events'; import type {
EdgeEvents,
NodeEvents,
NodeSelectionEvents,
OnSelectionDrag,
PaneEvents
} from '$lib/types/events';
export type SvelteFlowProps< export type SvelteFlowProps<
NodeType extends Node = Node, NodeType extends Node = Node,
@@ -455,4 +461,10 @@ export type SvelteFlowProps<
oninit?: () => void; oninit?: () => void;
/** This event handler gets called when the selected nodes & edges change */ /** This event handler gets called when the selected nodes & edges change */
onselectionchange?: OnSelectionChange<NodeType, EdgeType>; onselectionchange?: OnSelectionChange<NodeType, EdgeType>;
/** This event handler gets called when a user starts to drag a selection box. */
onselectiondragstart?: OnSelectionDrag<NodeType>;
/** This event handler gets called when a user drags a selection box. */
onselectiondrag?: OnSelectionDrag<NodeType>;
/** This event handler gets called when a user stops dragging a selection box. */
onselectiondragstop?: OnSelectionDrag<NodeType>;
}; };
@@ -60,7 +60,8 @@ import type {
EdgeLayouted, EdgeLayouted,
InternalNode, InternalNode,
OnBeforeReconnect, OnBeforeReconnect,
OnSelectionChange OnSelectionChange,
OnSelectionDrag
} from '$lib/types'; } from '$lib/types';
import type { StoreSignals } from './types'; import type { StoreSignals } from './types';
@@ -359,6 +360,10 @@ export function getInitialStore<NodeType extends Node = Node, EdgeType extends E
onclickconnectend?: OnConnectEnd = $derived(signals.props.onclickconnectend); onclickconnectend?: OnConnectEnd = $derived(signals.props.onclickconnectend);
clickConnectStartHandle: Pick<Handle, 'id' | 'nodeId' | 'type'> | null = $state(null); clickConnectStartHandle: Pick<Handle, 'id' | 'nodeId' | 'type'> | null = $state(null);
onselectiondrag?: OnSelectionDrag<NodeType> = $derived(signals.props.onselectiondrag);
onselectiondragstart?: OnSelectionDrag<NodeType> = $derived(signals.props.onselectiondragstart);
onselectiondragstop?: OnSelectionDrag<NodeType> = $derived(signals.props.onselectiondragstop);
resolveFitView = async () => { resolveFitView = async () => {
if (!this.panZoom) { if (!this.panZoom) {
return; return;
+5
View File
@@ -70,3 +70,8 @@ export type EdgeEvents<EdgeType extends Edge = Edge> = {
/** This event handler is called when the pointer of a user enters an edge. */ /** This event handler is called when the pointer of a user enters an edge. */
onedgepointerleave?: ({ edge, event }: { edge: EdgeType; event: PointerEvent }) => void; onedgepointerleave?: ({ edge, event }: { edge: EdgeType; event: PointerEvent }) => void;
}; };
export type OnSelectionDrag<NodeType extends Node = Node> = (
event: MouseEvent,
nodes: NodeType[]
) => void;