streamline onselectionchange
This commit is contained in:
@@ -69,7 +69,8 @@
|
||||
edges = $bindable([]),
|
||||
viewport = $bindable(undefined),
|
||||
...props
|
||||
}: SvelteFlowProps<NodeType, EdgeType> & HTMLAttributes<HTMLDivElement> = $props();
|
||||
}: SvelteFlowProps<NodeType, EdgeType> &
|
||||
Omit<HTMLAttributes<HTMLDivElement>, 'onselectionchange'> = $props();
|
||||
|
||||
// svelte-ignore non_reactive_update
|
||||
let store = createStore<NodeType, EdgeType>({
|
||||
@@ -113,8 +114,8 @@
|
||||
// handle selection change
|
||||
$effect(() => {
|
||||
const params = { nodes: store.selectedNodes, edges: store.selectedEdges };
|
||||
untrack(() => props.onselectionchanged)?.(params);
|
||||
for (const handler of store.selectionChangedHandlers.values()) {
|
||||
untrack(() => props.onselectionchange)?.(params);
|
||||
for (const handler of store.selectionChangeHandlers.values()) {
|
||||
handler(params);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
clientWidth?: number;
|
||||
clientHeight?: number;
|
||||
children?: Snippet;
|
||||
rest: SvelteFlowRestProps<NodeType, EdgeType> & HTMLAttributes<HTMLDivElement>;
|
||||
rest: SvelteFlowRestProps<NodeType, EdgeType> &
|
||||
Omit<HTMLAttributes<HTMLDivElement>, 'onselectionchange'>;
|
||||
} = $props();
|
||||
|
||||
// Unfortunately we have to destructure the props here this way,
|
||||
@@ -52,7 +53,7 @@
|
||||
onclickconnectstart,
|
||||
onclickconnectend,
|
||||
oninit,
|
||||
onselectionchanged,
|
||||
onselectionchange,
|
||||
clickConnect,
|
||||
fitView,
|
||||
fitViewOptions,
|
||||
|
||||
@@ -36,7 +36,7 @@ import type {
|
||||
OnBeforeDelete,
|
||||
IsValidConnection,
|
||||
OnBeforeReconnect,
|
||||
OnSelectionChanged
|
||||
OnSelectionChange
|
||||
} from '$lib/types';
|
||||
|
||||
import type { Component } from 'svelte';
|
||||
@@ -454,5 +454,5 @@ export type SvelteFlowProps<
|
||||
/** This handler gets called when the flow is finished initializing */
|
||||
oninit?: () => void;
|
||||
/** This event handler gets called when the selected nodes & edges change */
|
||||
onselectionchanged?: OnSelectionChanged<NodeType, EdgeType>;
|
||||
onselectionchange?: OnSelectionChange<NodeType, EdgeType>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user