File size: 1,366 Bytes
2740e39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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} />;
}