move handleEdgeSelection into store, fix hooks

This commit is contained in:
peterkogo
2024-12-18 16:20:37 +01:00
parent 988a0cb7d7
commit 19e233af2d
10 changed files with 66 additions and 63 deletions
+24
View File
@@ -309,6 +309,29 @@ export function createStore(signals: StoreSignals): SvelteFlowStore {
}
}
function handleEdgeSelection(id: string) {
const edge = store.edgeLookup.get(id);
if (!edge) {
console.warn('012', errorMessages['error012'](id));
return;
}
const selectable =
edge.selectable || (store.elementsSelectable && typeof edge.selectable === 'undefined');
if (selectable) {
store.selectionRect = null;
store.selectionRectMode = null;
if (!edge.selected) {
addSelectedEdges([id]);
} else if (edge.selected && store.multiselectionKeyPressed) {
unselectNodesAndEdges({ nodes: [], edges: [edge] });
}
}
}
function panBy(delta: XYPosition) {
return panBySystem({
delta,
@@ -354,6 +377,7 @@ export function createStore(signals: StoreSignals): SvelteFlowStore {
addSelectedNodes,
addSelectedEdges,
handleNodeSelection,
handleEdgeSelection,
panBy,
updateConnection,
cancelConnection,
+1
View File
@@ -30,6 +30,7 @@ export type SvelteFlowStoreActions = {
addSelectedNodes: (ids: string[]) => void;
addSelectedEdges: (ids: string[]) => void;
handleNodeSelection: (id: string) => void;
handleEdgeSelection: (id: string) => void;
panBy: (delta: XYPosition) => Promise<boolean>;
updateConnection: UpdateConnection;
cancelConnection: () => void;