add NodeConnection

This commit is contained in:
peterkogo
2025-01-07 12:20:54 +01:00
parent 4fc8e08128
commit e37712bbb9
3 changed files with 11 additions and 6 deletions
@@ -1,7 +1,7 @@
import { useEffect, useMemo, useRef } from 'react'; import { useEffect, useMemo, useRef } from 'react';
import { import {
Connection, Connection,
HandleConnection, NodeConnection,
HandleType, HandleType,
areConnectionMapsEqual, areConnectionMapsEqual,
handleConnectionChange, handleConnectionChange,
@@ -38,7 +38,7 @@ export function useNodeConnections({
nodeId, nodeId,
onConnect, onConnect,
onDisconnect, onDisconnect,
}: UseNodeConnectionsParams): HandleConnection[] { }: UseNodeConnectionsParams): NodeConnection[] {
const _nodeId = useNodeId(); const _nodeId = useNodeId();
const currentNodeId = nodeId ?? _nodeId; const currentNodeId = nodeId ?? _nodeId;
@@ -46,7 +46,7 @@ export function useNodeConnections({
throw new Error(error014); throw new Error(error014);
} }
const prevConnections = useRef<Map<string, HandleConnection> | null>(null); const prevConnections = useRef<Map<string, NodeConnection> | null>(null);
const connections = useStore( const connections = useStore(
(state) => (state) =>
@@ -2,7 +2,7 @@ import { derived } from 'svelte/store';
import { import {
areConnectionMapsEqual, areConnectionMapsEqual,
errorMessages, errorMessages,
type HandleConnection, type NodeConnection,
type HandleType type HandleType
} from '@xyflow/system'; } from '@xyflow/system';
@@ -20,7 +20,7 @@ type UseNodeConnectionsParams = {
// onDisconnect?: (connections: Connection[]) => void; // onDisconnect?: (connections: Connection[]) => void;
}; };
const initialConnections: HandleConnection[] = []; const initialConnections: NodeConnection[] = [];
/** /**
* Hook to retrieve all edges connected to a node. Can be filtered by handle type and id. * Hook to retrieve all edges connected to a node. Can be filtered by handle type and id.
@@ -43,7 +43,7 @@ export function useNodeConnections({ type, nodeId, handleId }: UseNodeConnection
throw new Error(error014); throw new Error(error014);
} }
let prevConnections: Map<string, HandleConnection> | undefined = undefined; let prevConnections: Map<string, NodeConnection> | undefined = undefined;
return derived( return derived(
[edges, connectionLookup], [edges, connectionLookup],
+5
View File
@@ -33,10 +33,15 @@ export type Connection = {
targetHandle: string | null; targetHandle: string | null;
}; };
// TODO: remove in next version
export type HandleConnection = Connection & { export type HandleConnection = Connection & {
edgeId: string; edgeId: string;
}; };
export type NodeConnection = Connection & {
edgeId: string;
};
export enum ConnectionMode { export enum ConnectionMode {
Strict = 'strict', Strict = 'strict',
Loose = 'loose', Loose = 'loose',