11import React , { memo } from "react" ;
2- import { BaseEdge , Edge , EdgeProps , EdgeText , getBezierPath } from "@xyflow/react" ;
2+ import { BaseEdge , Edge , EdgeProps , EdgeText , GetBezierPathParams } from "@xyflow/react" ;
33
44import { nodeContentUtils } from "../nodes/NodeContent" ;
55import { ReactFlowVersions } from "../versionsupport" ;
66
77import { EdgeDefaultDataProps , edgeDefaultUtils } from "./EdgeDefault" ;
8+ import { getStraightPath } from "./utils" ;
89
910/**
1011 * @deprecated (v26) use EdgeDefaultDataProps
@@ -19,7 +20,14 @@ export interface EdgeDefaultV12DataProps extends Record<string, unknown>, EdgeDe
1920/**
2021 * @deprecated (v26) use EdgeDefaultProps
2122 */
22- export type EdgeDefaultV12Props = EdgeProps < Edge < EdgeDefaultV12DataProps > > ;
23+ export type EdgeDefaultV12Props = EdgeProps < Edge < EdgeDefaultV12DataProps > > & {
24+ /**
25+ * Callback handler that returns SVG path and label position of the edge.
26+ */
27+ getPath ?: (
28+ edgeParams : Omit < GetBezierPathParams , "curvature" > & Record < string , unknown >
29+ ) => [ path : string , labelX : number , labelY : number , offsetX : number , offsetY : number ] ;
30+ } ;
2331
2432/**
2533 * This element cannot be used directly, it must be connected via a `edgeTypes` definition.
@@ -42,11 +50,12 @@ export const EdgeDefaultV12 = memo(
4250 labelBgPadding = [ 5 , 5 ] ,
4351 labelBgBorderRadius = 3 ,
4452 data = { } ,
53+ getPath = getStraightPath ,
4554 ...edgeOriginalProperties
4655 } : EdgeDefaultV12Props ) => {
4756 const { pathGlowWidth = 10 , highlightColor, renderLabel, edgeSvgProps, intent, inversePath, strokeType } = data ;
4857
49- const [ edgePath , labelX , labelY ] = getBezierPath ( {
58+ const [ edgePath , labelX , labelY ] = getPath ( {
5059 sourceX,
5160 sourceY,
5261 sourcePosition,
@@ -92,48 +101,43 @@ export const EdgeDefaultV12 = memo(
92101
93102 return (
94103 < g
95- className = {
96- "react-flow__edge " +
97- edgeDefaultUtils . createEdgeDefaultClassName (
98- { intent } ,
99- `${ edgeOriginalProperties . selected ? "selected" : "" } ` ,
100- ReactFlowVersions . V12
101- )
102- }
104+ { ...edgeSvgProps }
105+ className = { edgeDefaultUtils . createEdgeDefaultClassName (
106+ { intent } ,
107+ `${ edgeSvgProps ?. className ?? "" } ` ,
108+ ReactFlowVersions . V12
109+ ) }
103110 tabIndex = { 0 }
104111 role = "button"
105112 data-id = { id }
106113 aria-label = { `Edge from ${ edgeOriginalProperties . source } to ${ edgeOriginalProperties . target } ` }
107114 aria-describedby = { `react-flow__edge-desc-${ id } ` }
108115 >
109- < g className = { edgeSvgProps ?. className ?? "" } >
110- { highlightColor && (
111- < path
112- d = { edgePath }
113- className = { edgeDefaultUtils . createEdgeDefaultClassName (
114- { highlightColor } ,
115- "react-flow__edge-path-highlight"
116- ) }
117- strokeWidth = { 10 }
118- style = { {
119- ...highlightCustomPropertySettings ,
120- } }
121- />
122- ) }
123-
124- < BaseEdge
125- id = { id }
126- path = { edgePath }
127- { ...marker }
128- className = { edgeDefaultUtils . createEdgeDefaultClassName ( { strokeType } ) }
129- interactionWidth = { pathGlowWidth }
116+ { highlightColor && (
117+ < path
118+ d = { edgePath }
119+ className = { edgeDefaultUtils . createEdgeDefaultClassName (
120+ { highlightColor } ,
121+ "react-flow__edge-path-highlight"
122+ ) }
123+ strokeWidth = { pathGlowWidth }
130124 style = { {
131- ...edgeSvgProps ?. style ,
132- ...edgeStyle ,
133- color : edgeStyle . color || edgeStyle . stroke ,
125+ ...highlightCustomPropertySettings ,
134126 } }
135127 />
136- </ g >
128+ ) }
129+ < BaseEdge
130+ id = { id }
131+ path = { edgePath }
132+ { ...marker }
133+ className = { edgeDefaultUtils . createEdgeDefaultClassName ( { strokeType } ) }
134+ interactionWidth = { pathGlowWidth }
135+ style = { {
136+ ...edgeSvgProps ?. style ,
137+ ...edgeStyle ,
138+ color : edgeStyle . color || edgeStyle . stroke ,
139+ } }
140+ />
137141 { renderedLabel }
138142 </ g >
139143 ) ;
0 commit comments