refactor(useConnection): return internal node, add node generic

This commit is contained in:
moklick
2024-07-10 11:58:49 +02:00
parent 1e429da911
commit 6904b5bd49
8 changed files with 50 additions and 36 deletions
+6 -10
View File
@@ -148,34 +148,30 @@ export const initialConnection: NoConnection = {
export type NoConnection = {
inProgress: false;
isValid: null;
from: null;
fromHandle: null;
fromPosition: null;
fromNode: null;
to: null;
toHandle: null;
toPosition: null;
toNode: null;
};
export type ConnectionInProgress = {
export type ConnectionInProgress<NodeType extends InternalNodeBase = InternalNodeBase> = {
inProgress: true;
isValid: boolean | null;
from: XYPosition;
fromHandle: Handle;
fromPosition: Position;
fromNode: NodeBase;
fromNode: NodeType;
to: XYPosition;
toHandle: Handle | null;
toPosition: Position;
toNode: NodeBase | null;
toNode: NodeType | null;
};
export type ConnectionState = ConnectionInProgress | NoConnection;
export type ConnectionState<NodeType extends InternalNodeBase = InternalNodeBase> =
| ConnectionInProgress<NodeType>
| NoConnection;
export type UpdateConnection = (params: ConnectionState) => void;
+2 -2
View File
@@ -104,7 +104,7 @@ function onPointerDown(
from,
fromHandle,
fromPosition: fromHandle.position,
fromNode: fromNodeInternal.internals.userNode,
fromNode: fromNodeInternal,
to: position,
toHandle: null,
@@ -163,7 +163,7 @@ function onPointerDown(
: position,
toHandle: result.toHandle,
toPosition: isValid && result.toHandle ? result.toHandle.position : oppositePosition[fromHandle.position],
toNode: result.toHandle ? nodeLookup.get(result.toHandle.nodeId)!.internals.userNode : null,
toNode: result.toHandle ? nodeLookup.get(result.toHandle.nodeId)! : null,
};
// we don't want to trigger an update when the connection