diff --git a/example/src/CustomNode/index.tsx b/example/src/CustomNode/index.tsx index 804aabea..85a1ee00 100644 --- a/example/src/CustomNode/index.tsx +++ b/example/src/CustomNode/index.tsx @@ -132,4 +132,4 @@ const CustomNodeFlow = () => { ); }; -export default CustomNodeFlow; +export default CustomNodeFlow; \ No newline at end of file diff --git a/package.json b/package.json index f6695619..abcfbf85 100644 --- a/package.json +++ b/package.json @@ -75,11 +75,11 @@ "typescript": "^4.4.4" }, "peerDependencies": { - "react": "16 || 17", - "react-dom": "16 || 17" + "react": "16 || 17", + "react-dom": "16 || 17" }, "files": [ "dist", "nocss" ] -} +} \ No newline at end of file diff --git a/src/components/ConnectionLine/index.tsx b/src/components/ConnectionLine/index.tsx index e3c71f9e..1246dc52 100644 --- a/src/components/ConnectionLine/index.tsx +++ b/src/components/ConnectionLine/index.tsx @@ -53,9 +53,22 @@ export default ({ return null; } - const sourceHandle = handleId - ? sourceNode.__rf.handleBounds[connectionHandleType].find((d: HandleElement) => d.id === handleId) - : sourceNode.__rf.handleBounds[connectionHandleType][0]; + const getSourceHandle = (handleId: ElementId | null, sourceNode: Node) => { + const handleBound = sourceNode.__rf.handleBounds[connectionHandleType]; + if (handleBound) { + if (handleId) { + return sourceNode.__rf.handleBounds[connectionHandleType].find((d: HandleElement) => d.id === handleId); + } + return sourceNode.__rf.handleBounds[connectionHandleType][0] + } + const handleType = connectionHandleType === 'source' ? 'target' : 'source'; + if (handleId) { + return sourceNode.__rf.handleBounds[handleType].find((d: HandleElement) => d.id === handleId); + } + return sourceNode.__rf.handleBounds[handleType][0] + } + + const sourceHandle = getSourceHandle(handleId, sourceNode); const sourceHandleX = sourceHandle ? sourceHandle.x + sourceHandle.width / 2 : sourceNode.__rf.width / 2; const sourceHandleY = sourceHandle ? sourceHandle.y + sourceHandle.height / 2 : sourceNode.__rf.height; const sourceX = sourceNode.__rf.position.x + sourceHandleX; @@ -68,6 +81,7 @@ export default ({ const targetPosition = isRightOrLeft ? Position.Left : Position.Top; if (CustomConnectionLineComponent) { + return (