From 68ec5d87d728cfd7c269c20aa39e318f67b7eef1 Mon Sep 17 00:00:00 2001 From: Andreas Schultz Date: Mon, 4 Apr 2022 09:53:11 +0200 Subject: [PATCH] Change boolean 'isSourceHandle' parameter to handleType: HandleType in 'onEdgeUpdateStart' function - In order to make the function better extendable in the future. --- src/components/Edges/wrapEdge.tsx | 5 +++-- src/container/EdgeRenderer/index.tsx | 3 ++- src/container/ReactFlow/index.tsx | 3 ++- src/types/index.ts | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/Edges/wrapEdge.tsx b/src/components/Edges/wrapEdge.tsx index 292463f0..2cad3166 100644 --- a/src/components/Edges/wrapEdge.tsx +++ b/src/components/Edges/wrapEdge.tsx @@ -137,10 +137,11 @@ export default (EdgeComponent: ComponentType) => { (event: React.MouseEvent, isSourceHandle: boolean) => { const nodeId = isSourceHandle ? target : source; const handleId = isSourceHandle ? targetHandleId : sourceHandleId; + const handleType = isSourceHandle ? 'target' : 'source' const isValidConnection = () => true; const isTarget = isSourceHandle; - onEdgeUpdateStart?.(event, edgeElement, isSourceHandle); + onEdgeUpdateStart?.(event, edgeElement, handleType); const _onEdgeUpdate = onEdgeUpdateEnd ? (evt: MouseEvent): void => onEdgeUpdateEnd(evt, edgeElement) @@ -156,7 +157,7 @@ export default (EdgeComponent: ComponentType) => { isTarget, isValidConnection, connectionMode, - isSourceHandle ? 'target' : 'source', + handleType, _onEdgeUpdate ); }, diff --git a/src/container/EdgeRenderer/index.tsx b/src/container/EdgeRenderer/index.tsx index def55e27..dde5a2fa 100644 --- a/src/container/EdgeRenderer/index.tsx +++ b/src/container/EdgeRenderer/index.tsx @@ -16,6 +16,7 @@ import { ConnectionMode, Transform, OnEdgeUpdateFunc, + HandleType, } from '../../types'; interface EdgeRendererProps { @@ -34,7 +35,7 @@ interface EdgeRendererProps { onEdgeMouseEnter?: (event: React.MouseEvent, edge: Edge) => void; onEdgeMouseMove?: (event: React.MouseEvent, edge: Edge) => void; onEdgeMouseLeave?: (event: React.MouseEvent, edge: Edge) => void; - onEdgeUpdateStart?: (event: React.MouseEvent, edge: Edge, isSourceHandle: boolean) => void; + onEdgeUpdateStart?: (event: React.MouseEvent, edge: Edge, handleType: HandleType) => void; onEdgeUpdateEnd?: (event: MouseEvent, edge: Edge) => void; edgeUpdaterRadius?: number; } diff --git a/src/container/ReactFlow/index.tsx b/src/container/ReactFlow/index.tsx index cc0ae8ea..96c27fcd 100644 --- a/src/container/ReactFlow/index.tsx +++ b/src/container/ReactFlow/index.tsx @@ -38,6 +38,7 @@ import { PanOnScrollMode, OnEdgeUpdateFunc, NodeExtent, + HandleType, } from '../../types'; import '../../style.css'; @@ -123,7 +124,7 @@ export interface ReactFlowProps extends Omit, 'on onEdgeMouseMove?: (event: ReactMouseEvent, edge: Edge) => void; onEdgeMouseLeave?: (event: ReactMouseEvent, edge: Edge) => void; onEdgeDoubleClick?: (event: ReactMouseEvent, edge: Edge) => void; - onEdgeUpdateStart?: (event: ReactMouseEvent, edge: Edge, isSourceHandle: boolean) => void; + onEdgeUpdateStart?: (event: ReactMouseEvent, edge: Edge, handleType: HandleType) => void; onEdgeUpdateEnd?: (event: MouseEvent, edge: Edge) => void; edgeUpdaterRadius?: number; nodeTypesId?: string; diff --git a/src/types/index.ts b/src/types/index.ts index ce257abd..c7fe2b7f 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -132,7 +132,7 @@ export interface WrapEdgeProps { onMouseMove?: (event: React.MouseEvent, edge: Edge) => void; onMouseLeave?: (event: React.MouseEvent, edge: Edge) => void; edgeUpdaterRadius?: number; - onEdgeUpdateStart?: (event: React.MouseEvent, edge: Edge, isSourceHandle: boolean) => void; + onEdgeUpdateStart?: (event: React.MouseEvent, edge: Edge, handleType: HandleType) => void; onEdgeUpdateEnd?: (event: MouseEvent, edge: Edge) => void; }