(
onClickConnectEnd?.(event as unknown as MouseEvent);
- store.setState({ connectionStartHandle: null });
+ store.setState({ connectionClickStartHandle: null });
};
- const connecting =
- connectionStartHandle?.nodeId === nodeId &&
- connectionStartHandle?.handleId === handleId &&
- connectionStartHandle?.type === type;
-
return (
(
connectable: isConnectable,
connectablestart: isConnectableStart,
connectableend: isConnectableEnd,
- connecting,
+ connecting: clickConnecting,
+ // this class is used to style the handle when the user is connecting
connectionindicator:
- (isConnectable && isConnectableStart && !connecting) || (isConnectableEnd && connecting),
+ isConnectable && ((isConnectableStart && !connecting) || (isConnectableEnd && connecting)),
},
])}
onMouseDown={onPointerDown}
diff --git a/packages/core/src/components/Handle/utils.ts b/packages/core/src/components/Handle/utils.ts
index 2825bb0e..b8e8cf6a 100644
--- a/packages/core/src/components/Handle/utils.ts
+++ b/packages/core/src/components/Handle/utils.ts
@@ -1,6 +1,6 @@
import { MouseEvent as ReactMouseEvent, TouchEvent as ReactTouchEvent } from 'react';
-import { ConnectionMode, ConnectionStatus } from '../../types';
+import { ConnectingHandle, ConnectionMode, ConnectionStatus } from '../../types';
import { getEventPosition, internalsSymbol } from '../../utils';
import type { Connection, HandleType, XYPosition, Node, NodeHandleBounds } from '../../types';
@@ -59,6 +59,7 @@ type Result = {
handleDomNode: Element | null;
isValid: boolean;
connection: Connection;
+ endHandle: ConnectingHandle | null;
};
const nullConnection: Connection = { source: null, target: null, sourceHandle: null, targetHandle: null };
@@ -70,7 +71,7 @@ export function isValidHandle(
connectionMode: ConnectionMode,
fromNodeId: string,
fromHandleId: string | null,
- fromType: string,
+ fromType: HandleType,
isValidConnection: ValidConnectionFunc,
doc: Document | ShadowRoot
) {
@@ -86,6 +87,7 @@ export function isValidHandle(
handleDomNode: handleToCheck,
isValid: false,
connection: nullConnection,
+ endHandle: null,
};
if (handleToCheck) {
@@ -113,6 +115,12 @@ export function isValidHandle(
: handleNodeId !== fromNodeId || handleId !== fromHandleId);
if (isValid) {
+ result.endHandle = {
+ nodeId: handleNodeId as string,
+ handleId,
+ type: handleType as HandleType,
+ };
+
result.isValid = isValidConnection(connection);
}
}
diff --git a/packages/core/src/store/index.ts b/packages/core/src/store/index.ts
index 58cc5080..f4365d45 100644
--- a/packages/core/src/store/index.ts
+++ b/packages/core/src/store/index.ts
@@ -275,8 +275,8 @@ const createRFStore = () =>
connectionHandleId: initialState.connectionHandleId,
connectionHandleType: initialState.connectionHandleType,
connectionStatus: initialState.connectionStatus,
- connectionTargetNodeId: initialState.connectionTargetNodeId,
- connectionTargetHandleId: initialState.connectionTargetHandleId,
+ connectionStartHandle: initialState.connectionStartHandle,
+ connectionEndHandle: initialState.connectionEndHandle,
}),
reset: () => set({ ...initialState }),
}));
diff --git a/packages/core/src/store/initialState.ts b/packages/core/src/store/initialState.ts
index 2722038d..8c4a5d76 100644
--- a/packages/core/src/store/initialState.ts
+++ b/packages/core/src/store/initialState.ts
@@ -31,8 +31,6 @@ const initialState: ReactFlowStore = {
connectionNodeId: null,
connectionHandleId: null,
connectionHandleType: 'source',
- connectionTargetNodeId: null,
- connectionTargetHandleId: null,
connectionPosition: { x: 0, y: 0 },
connectionStatus: null,
connectionMode: ConnectionMode.Strict,
@@ -57,6 +55,8 @@ const initialState: ReactFlowStore = {
multiSelectionActive: false,
connectionStartHandle: null,
+ connectionEndHandle: null,
+ connectionClickStartHandle: null,
connectOnClick: true,
ariaLiveMessage: '',
diff --git a/packages/core/src/types/general.ts b/packages/core/src/types/general.ts
index fab391d0..aeb33632 100644
--- a/packages/core/src/types/general.ts
+++ b/packages/core/src/types/general.ts
@@ -21,7 +21,7 @@ import type {
NodeOrigin,
} from './nodes';
import type { Edge, EdgeProps, WrapEdgeProps } from './edges';
-import type { HandleType, StartHandle } from './handles';
+import type { HandleType, ConnectingHandle } from './handles';
import type { DefaultEdgeOptions } from '.';
import type { ReactFlowInstance } from './instance';
@@ -167,10 +167,9 @@ export type ReactFlowStore = {
userSelectionActive: boolean;
userSelectionRect: SelectionRect | null;
+ // @todo remove this in next major version in favor of connectionStartHandle
connectionNodeId: string | null;
connectionHandleId: string | null;
- connectionTargetNodeId: string | null;
- connectionTargetHandleId: string | null;
connectionHandleType: HandleType | null;
connectionPosition: XYPosition;
connectionStatus: ConnectionStatus | null;
@@ -188,7 +187,10 @@ export type ReactFlowStore = {
multiSelectionActive: boolean;
- connectionStartHandle: StartHandle | null;
+ connectionStartHandle: ConnectingHandle | null;
+ connectionEndHandle: ConnectingHandle | null;
+ // @todo this is only used for the click connection - we might remove this in the next major version
+ connectionClickStartHandle: ConnectingHandle | null;
onNodeDragStart?: NodeDragHandler;
onNodeDrag?: NodeDragHandler;
diff --git a/packages/core/src/types/handles.ts b/packages/core/src/types/handles.ts
index aff196f6..7e40d1e5 100644
--- a/packages/core/src/types/handles.ts
+++ b/packages/core/src/types/handles.ts
@@ -2,18 +2,19 @@ import type { XYPosition, Position, Dimensions, OnConnect, Connection } from '.'
export type HandleType = 'source' | 'target';
-export interface HandleElement extends XYPosition, Dimensions {
- id?: string | null;
- position: Position;
-}
+export type HandleElement = XYPosition &
+ Dimensions & {
+ id?: string | null;
+ position: Position;
+ };
-export interface StartHandle {
+export type ConnectingHandle = {
nodeId: string;
type: HandleType;
handleId?: string | null;
-}
+};
-export interface HandleProps {
+export type HandleProps = {
type: HandleType;
position: Position;
isConnectable?: boolean;
@@ -22,4 +23,4 @@ export interface HandleProps {
onConnect?: OnConnect;
isValidConnection?: (connection: Connection) => boolean;
id?: string;
-}
+};