-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEdgeDefaultV12.tsx
More file actions
155 lines (144 loc) · 5.21 KB
/
Copy pathEdgeDefaultV12.tsx
File metadata and controls
155 lines (144 loc) · 5.21 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import React, { memo } from "react";
import { BaseEdge, Edge, EdgeProps, EdgeText, GetBezierPathParams } from "@xyflow/react";
import { nodeContentUtils } from "../nodes/NodeContent";
import { ReactFlowVersions } from "../versionsupport";
import { EdgeDefaultDataProps, edgeDefaultUtils } from "./EdgeDefault";
import { getStraightPath } from "./utils";
/**
* @deprecated (v26) use EdgeDefaultDataProps
*/
export interface EdgeDefaultV12DataProps extends Record<string, unknown>, EdgeDefaultDataProps {
/**
* Set the marker used on the start or end of the edge.
*/
markerAppearance?: "arrow-closed" | "none";
}
/**
* @deprecated (v26) use EdgeDefaultProps
*/
export type EdgeDefaultV12Props = EdgeProps<Edge<EdgeDefaultV12DataProps>> & {
/**
* Callback handler that returns SVG path and label position of the edge.
*/
getPath?: (
edgeParams: Omit<GetBezierPathParams, "curvature"> & Record<string, unknown>
) => [path: string, labelX: number, labelY: number, offsetX: number, offsetY: number];
};
/**
* This element cannot be used directly, it must be connected via a `edgeTypes` definition.
* @see https://reactflow.dev/docs/api/nodes/
* @deprecated (v26) will be removed when `EdgeDefault` supports v12 directly
*/
export const EdgeDefaultV12 = memo(
({
id,
sourceX,
sourceY,
targetX,
targetY,
sourcePosition,
targetPosition,
label,
labelStyle,
labelShowBg,
labelBgStyle,
labelBgPadding = [5, 5],
labelBgBorderRadius = 3,
data = {},
getPath = getStraightPath,
...edgeOriginalProperties
}: EdgeDefaultV12Props) => {
const {
pathGlowWidth = 10,
highlightColor,
renderLabel,
edgeSvgProps,
intent,
arrowDirection = "normal",
strokeType,
} = data;
const [edgePath, labelX, labelY] = getPath({
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
targetPosition,
});
const edgeStyle = edgeOriginalProperties.style ?? {};
const { highlightCustomPropertySettings } = nodeContentUtils.evaluateHighlightColors(
"--edge-highlight",
highlightColor
);
const renderedLabel =
renderLabel?.([labelX, labelY, sourceX, targetX]) ??
(label ? (
<EdgeText
x={labelX}
y={labelY}
label={label}
labelStyle={labelStyle}
labelShowBg={labelShowBg}
labelBgStyle={labelBgStyle}
labelBgPadding={labelBgPadding || [5, 5]}
labelBgBorderRadius={labelBgBorderRadius || 3}
/>
) : null);
const appearance = data.markerAppearance ?? "arrow-closed";
const marker =
appearance !== "none"
? {
markerStart:
arrowDirection === "inversed" || arrowDirection === "bidirectional"
? `url(#react-flow__marker--${appearance}${intent ? `-${intent}` : "-none"}-reverse)`
: undefined,
markerEnd:
arrowDirection === "normal" || arrowDirection === "bidirectional"
? `url(#react-flow__marker--${appearance}${intent ? `-${intent}` : "-none"}`
: undefined,
}
: {};
return (
<g
{...edgeSvgProps}
className={edgeDefaultUtils.createEdgeDefaultClassName(
{ intent },
`${edgeSvgProps?.className ?? ""}`,
ReactFlowVersions.V12
)}
tabIndex={0}
role="button"
data-id={id}
aria-label={`Edge from ${edgeOriginalProperties.source} to ${edgeOriginalProperties.target}`}
aria-describedby={`react-flow__edge-desc-${id}`}
>
{highlightColor && (
<path
d={edgePath}
className={edgeDefaultUtils.createEdgeDefaultClassName(
{ highlightColor },
"react-flow__edge-path-highlight"
)}
strokeWidth={pathGlowWidth}
style={{
...highlightCustomPropertySettings,
}}
/>
)}
<BaseEdge
id={id}
path={edgePath}
{...marker}
className={edgeDefaultUtils.createEdgeDefaultClassName({ strokeType })}
interactionWidth={pathGlowWidth}
style={{
...edgeSvgProps?.style,
...edgeStyle,
color: edgeStyle.color || edgeStyle.stroke,
}}
/>
{renderedLabel}
</g>
);
}
);