FlowWeb / src /features /canvas /components /SmartEdge.jsx
danylokhodus's picture
Claude Opus 5.5
feat: quest board — web auto-layout, groups, archive, XP and rewards
2740e39
Raw History Blame Contribute Delete
1.37 kB
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 <BaseEdge id={id} path={path} markerEnd={markerEnd} style={style} interactionWidth={interactionWidth} />;
}