import React from 'react'; import { BaseEdge, getBezierPath, useInternalNode } from '@xyflow/react'; import { floatingPoints, isMeaningfulHandle } from './floatingEdge'; // Default edge: floats between the facing sides of its nodes; a condition keeps its branch handle. export default function SmartEdge({ id, source, target, sourceHandleId, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, markerEnd, style, interactionWidth, }) { const sourceNode = useInternalNode(source); const targetNode = useInternalNode(target); let points = { sx: sourceX, sy: sourceY, tx: targetX, ty: targetY, sourcePos: sourcePosition, targetPos: targetPosition }; if (sourceNode && targetNode) { points = floatingPoints(sourceNode, targetNode, { keepSource: isMeaningfulHandle(sourceNode, sourceHandleId) || sourceNode.type === 'portal', keepTarget: targetNode.type === 'portal', sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, }); } const [path] = getBezierPath({ sourceX: points.sx, sourceY: points.sy, sourcePosition: points.sourcePos, targetX: points.tx, targetY: points.ty, targetPosition: points.targetPos, curvature: 0.3, }); return ; }