refactor(conenctionline): simplify getSourceHandle helper
This commit is contained in:
+1
-1
@@ -82,4 +82,4 @@
|
|||||||
"dist",
|
"dist",
|
||||||
"nocss"
|
"nocss"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,14 @@ interface ConnectionLineProps {
|
|||||||
CustomConnectionLineComponent?: ConnectionLineComponent;
|
CustomConnectionLineComponent?: ConnectionLineComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getSourceHandle = (handleId: ElementId | null, sourceNode: Node, connectionHandleType: HandleType) => {
|
||||||
|
const handleTypeInverted = connectionHandleType === 'source' ? 'target' : 'source';
|
||||||
|
const handleBound =
|
||||||
|
sourceNode.__rf.handleBounds[connectionHandleType] || sourceNode.__rf.handleBounds[handleTypeInverted];
|
||||||
|
|
||||||
|
return handleId ? handleBound.find((d: HandleElement) => d.id === handleId) : handleBound[0];
|
||||||
|
};
|
||||||
|
|
||||||
export default ({
|
export default ({
|
||||||
connectionNodeId,
|
connectionNodeId,
|
||||||
connectionHandleId,
|
connectionHandleId,
|
||||||
@@ -53,22 +61,7 @@ export default ({
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getSourceHandle = (handleId: ElementId | null, sourceNode: Node) => {
|
const sourceHandle = getSourceHandle(handleId, sourceNode, connectionHandleType);
|
||||||
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 sourceHandleX = sourceHandle ? sourceHandle.x + sourceHandle.width / 2 : sourceNode.__rf.width / 2;
|
||||||
const sourceHandleY = sourceHandle ? sourceHandle.y + sourceHandle.height / 2 : sourceNode.__rf.height;
|
const sourceHandleY = sourceHandle ? sourceHandle.y + sourceHandle.height / 2 : sourceNode.__rf.height;
|
||||||
const sourceX = sourceNode.__rf.position.x + sourceHandleX;
|
const sourceX = sourceNode.__rf.position.x + sourceHandleX;
|
||||||
@@ -81,7 +74,6 @@ export default ({
|
|||||||
const targetPosition = isRightOrLeft ? Position.Left : Position.Top;
|
const targetPosition = isRightOrLeft ? Position.Left : Position.Top;
|
||||||
|
|
||||||
if (CustomConnectionLineComponent) {
|
if (CustomConnectionLineComponent) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<g className="react-flow__connection">
|
<g className="react-flow__connection">
|
||||||
<CustomConnectionLineComponent
|
<CustomConnectionLineComponent
|
||||||
|
|||||||
Reference in New Issue
Block a user