1- import {
2- type Edge ,
3- type EdgeProps ,
4- getBezierPath ,
5- getSmoothStepPath ,
6- getStraightPath ,
7- } from '@xyflow/react'
8- import React , { useId } from 'react'
1+ import React from 'react'
92
103import { type LineageContextHook } from '../LineageContext'
114import {
@@ -14,6 +7,8 @@ import {
147 type LineageNodeData ,
158 type PathType ,
169} from '../utils'
10+ import { EdgeWithGradient } from './EdgeWithGradient'
11+ import type { Edge , EdgeProps } from '@xyflow/react'
1712
1813export interface EdgeData extends LineageEdgeData {
1914 startColor ?: string
@@ -26,101 +21,34 @@ export function FactoryEdgeWithGradient<
2621 TNodeData extends LineageNodeData = LineageNodeData ,
2722 TEdgeData extends EdgeData = EdgeData ,
2823> ( useLineage : LineageContextHook < TNodeData , TEdgeData > ) {
29- return React . memo ( function EdgeWithGradient ( {
30- id,
31- sourceX,
32- sourceY,
33- targetX,
34- targetY,
35- sourcePosition,
36- targetPosition,
37- style,
38- data,
39- markerEnd,
40- } : EdgeProps < Edge < TEdgeData > > ) {
24+ return React . memo ( ( { data, id, ...props } : EdgeProps < Edge < TEdgeData > > ) => {
4125 const edgeId = id as EdgeId
4226
4327 const { selectedEdges } = useLineage ( )
4428
45- const gradientId = useId ( )
46- const startColor = data ?. startColor || 'var(--color-lineage-edge)'
47- const endColor = data ?. endColor || 'var(--color-lineage-edge)'
48- const pathType = data ?. pathType || 'bezier'
49- const strokeWidth = data ?. strokeWidth || 4
50- const edgePath = getEdgePath ( pathType )
5129 const isActive = selectedEdges . has ( edgeId )
5230
53- function getEdgePath ( pathType : PathType ) {
54- return {
55- straight : getStraightPath ( {
56- sourceX,
57- sourceY,
58- targetX,
59- targetY,
60- } ) ,
61- smoothstep : getSmoothStepPath ( {
62- sourceX,
63- sourceY,
64- sourcePosition,
65- targetX,
66- targetY,
67- targetPosition,
68- borderRadius : 10 ,
69- } ) ,
70- bezier : getBezierPath ( {
71- sourceX,
72- sourceY,
73- sourcePosition,
74- targetX,
75- targetY,
76- targetPosition,
77- } ) ,
78- step : getSmoothStepPath ( {
79- sourceX,
80- sourceY,
81- sourcePosition,
82- targetX,
83- targetY,
84- targetPosition,
85- borderRadius : 0 ,
86- } ) ,
87- } [ pathType ]
31+ let startColor = 'var(--color-lineage-edge)'
32+ let endColor = 'var(--color-lineage-edge)'
33+
34+ if ( isActive && data ?. startColor ) {
35+ startColor = data ?. startColor
36+ }
37+
38+ if ( isActive && data ?. endColor ) {
39+ endColor = data ?. endColor
8840 }
8941
9042 return (
91- < >
92- < defs >
93- < linearGradient
94- id = { gradientId }
95- x1 = { sourceX }
96- y1 = { sourceY }
97- x2 = { targetX }
98- y2 = { targetY }
99- gradientUnits = "userSpaceOnUse"
100- >
101- < stop
102- offset = "0%"
103- stopColor = { isActive ? startColor : 'var(--color-lineage-edge)' }
104- />
105- < stop
106- offset = "100%"
107- stopColor = { isActive ? endColor : 'var(--color-lineage-edge)' }
108- />
109- </ linearGradient >
110- </ defs >
111- < path
112- id = { edgeId }
113- style = { {
114- ...style ,
115- stroke : `url(#${ gradientId } )` ,
116- strokeWidth,
117- fill : 'none' ,
118- } }
119- className = "react-flow__edge-path"
120- d = { edgePath [ 0 ] }
121- markerEnd = { markerEnd }
122- />
123- </ >
43+ < EdgeWithGradient
44+ { ...props }
45+ id = { edgeId }
46+ data = { {
47+ ...data ,
48+ startColor,
49+ endColor,
50+ } }
51+ />
12452 )
12553 } )
12654}
0 commit comments