@joshrp/react-flow-smart-edge 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +355 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +100 -0
- package/dist/index.mjs +409 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +108 -0
- package/src/SmartBezierEdge/index.tsx +26 -0
- package/src/SmartEdge/index.tsx +92 -0
- package/src/SmartStepEdge/index.tsx +29 -0
- package/src/SmartStraightEdge/index.tsx +29 -0
- package/src/functions/createGrid.ts +81 -0
- package/src/functions/drawSvgPath.ts +72 -0
- package/src/functions/generatePath.ts +60 -0
- package/src/functions/getBoundingBoxes.ts +138 -0
- package/src/functions/guaranteeWalkablePath.ts +38 -0
- package/src/functions/index.ts +7 -0
- package/src/functions/pointConversion.ts +49 -0
- package/src/functions/utils.ts +15 -0
- package/src/getSmartEdge/index.ts +160 -0
- package/src/index.tsx +18 -0
- package/src/internal/SmartEdgeDebug.tsx +43 -0
- package/src/internal/SmartEdgeDebugOverlay.tsx +24 -0
- package/src/internal/useSmartEdgeDebug.ts +26 -0
- package/src/pathfinding/aStar.ts +134 -0
- package/src/pathfinding/grid.ts +141 -0
- package/src/pathfinding/types.ts +3 -0
- package/src/stories/CustomLabel.tsx +94 -0
- package/src/stories/DummyData.ts +194 -0
- package/src/stories/GraphWrapper.tsx +23 -0
- package/src/stories/SmartEdge.stories.tsx +67 -0
- package/src/vite-env.d.ts +1 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { MarkerType } from "@xyflow/react";
|
|
2
|
+
import { SmartBezierEdge, SmartStraightEdge, SmartStepEdge } from "../index";
|
|
3
|
+
import { SmartEdgeCustomLabel } from "./CustomLabel";
|
|
4
|
+
import type { Node, Edge } from "@xyflow/react";
|
|
5
|
+
|
|
6
|
+
const markerEndType = MarkerType.Arrow;
|
|
7
|
+
|
|
8
|
+
export const edgeTypes = {
|
|
9
|
+
smartBezier: SmartBezierEdge,
|
|
10
|
+
smartStraight: SmartStraightEdge,
|
|
11
|
+
smartStep: SmartStepEdge,
|
|
12
|
+
smartBezierLabel: SmartEdgeCustomLabel,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const nodes: Node[] = [
|
|
16
|
+
{
|
|
17
|
+
id: "1",
|
|
18
|
+
data: {
|
|
19
|
+
label: "Node 1",
|
|
20
|
+
},
|
|
21
|
+
position: {
|
|
22
|
+
x: 490,
|
|
23
|
+
y: 40,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: "2",
|
|
28
|
+
data: {
|
|
29
|
+
label: "Node 2",
|
|
30
|
+
},
|
|
31
|
+
position: {
|
|
32
|
+
x: 270,
|
|
33
|
+
y: 130,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: "3",
|
|
38
|
+
data: {
|
|
39
|
+
label: "Node 3",
|
|
40
|
+
},
|
|
41
|
+
position: {
|
|
42
|
+
x: 40,
|
|
43
|
+
y: 220,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: "4",
|
|
48
|
+
data: {
|
|
49
|
+
label: "Node 4",
|
|
50
|
+
},
|
|
51
|
+
position: {
|
|
52
|
+
x: 270,
|
|
53
|
+
y: 220,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: "5",
|
|
58
|
+
data: {
|
|
59
|
+
label: "Node 5",
|
|
60
|
+
},
|
|
61
|
+
position: {
|
|
62
|
+
x: 470,
|
|
63
|
+
y: 220,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: "6",
|
|
68
|
+
data: {
|
|
69
|
+
label: "Node 6",
|
|
70
|
+
},
|
|
71
|
+
position: {
|
|
72
|
+
x: 515,
|
|
73
|
+
y: 310,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: "7",
|
|
78
|
+
data: {
|
|
79
|
+
label: "Node 7",
|
|
80
|
+
},
|
|
81
|
+
position: {
|
|
82
|
+
x: 470,
|
|
83
|
+
y: 130,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
export const edgesBezier: Edge[] = [
|
|
89
|
+
{
|
|
90
|
+
id: "e12",
|
|
91
|
+
source: "1",
|
|
92
|
+
target: "2",
|
|
93
|
+
type: "smartBezier",
|
|
94
|
+
markerEnd: { type: markerEndType },
|
|
95
|
+
label: "Edge Label",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: "e17",
|
|
99
|
+
source: "1",
|
|
100
|
+
target: "7",
|
|
101
|
+
type: "smartBezier",
|
|
102
|
+
markerEnd: { type: markerEndType },
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
id: "e23",
|
|
106
|
+
source: "2",
|
|
107
|
+
target: "3",
|
|
108
|
+
type: "smartBezier",
|
|
109
|
+
markerEnd: { type: markerEndType },
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: "e24",
|
|
113
|
+
source: "2",
|
|
114
|
+
target: "4",
|
|
115
|
+
type: "smartBezier",
|
|
116
|
+
markerEnd: { type: markerEndType },
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: "e25",
|
|
120
|
+
source: "2",
|
|
121
|
+
target: "5",
|
|
122
|
+
type: "smartBezier",
|
|
123
|
+
markerEnd: { type: markerEndType },
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
id: "e56",
|
|
127
|
+
source: "5",
|
|
128
|
+
target: "6",
|
|
129
|
+
type: "smartBezier",
|
|
130
|
+
markerEnd: { type: markerEndType },
|
|
131
|
+
data: {
|
|
132
|
+
customField: "custom data",
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
id: "e65",
|
|
137
|
+
source: "6",
|
|
138
|
+
target: "5",
|
|
139
|
+
type: "smartBezier",
|
|
140
|
+
markerEnd: { type: markerEndType },
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
id: "e61",
|
|
144
|
+
source: "6",
|
|
145
|
+
target: "1",
|
|
146
|
+
type: "smartBezier",
|
|
147
|
+
markerEnd: { type: markerEndType },
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
id: "e3",
|
|
151
|
+
source: "3",
|
|
152
|
+
target: "3",
|
|
153
|
+
type: "smartBezier",
|
|
154
|
+
markerEnd: { type: markerEndType },
|
|
155
|
+
},
|
|
156
|
+
];
|
|
157
|
+
|
|
158
|
+
export const edgesStraight: Edge[] = edgesBezier.map((edge) => ({
|
|
159
|
+
...edge,
|
|
160
|
+
type: "smartStraight",
|
|
161
|
+
}));
|
|
162
|
+
|
|
163
|
+
export const edgesStep: Edge[] = edgesBezier.map((edge) => ({
|
|
164
|
+
...edge,
|
|
165
|
+
type: "smartStep",
|
|
166
|
+
}));
|
|
167
|
+
|
|
168
|
+
export const edgesLabel: Edge[] = edgesBezier.map((edge) => ({
|
|
169
|
+
...edge,
|
|
170
|
+
type: "smartBezierLabel",
|
|
171
|
+
}));
|
|
172
|
+
|
|
173
|
+
export const simpleNodes: Node[] = [
|
|
174
|
+
{
|
|
175
|
+
id: "1",
|
|
176
|
+
data: { label: "Node 1 (Below)" },
|
|
177
|
+
position: { x: 300, y: 300 },
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
id: "2",
|
|
181
|
+
data: { label: "Node 2 (Above)" },
|
|
182
|
+
position: { x: 300, y: 120 },
|
|
183
|
+
},
|
|
184
|
+
];
|
|
185
|
+
|
|
186
|
+
export const simpleEdgesBezier: Edge[] = [
|
|
187
|
+
{
|
|
188
|
+
id: "e1-2-simple",
|
|
189
|
+
source: "1",
|
|
190
|
+
target: "2",
|
|
191
|
+
type: "smartBezier",
|
|
192
|
+
markerEnd: { type: markerEndType },
|
|
193
|
+
},
|
|
194
|
+
];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ReactFlow } from "@xyflow/react";
|
|
2
|
+
import type { ReactFlowProps } from "@xyflow/react";
|
|
3
|
+
import { SmartEdgeDebugProvider } from "../internal/SmartEdgeDebug";
|
|
4
|
+
import { SmartEdgeDebugOverlay } from "../internal/SmartEdgeDebugOverlay";
|
|
5
|
+
|
|
6
|
+
const style = {
|
|
7
|
+
background: "#fafafa",
|
|
8
|
+
width: "100%",
|
|
9
|
+
height: "500px",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export interface GraphWrapperProps extends ReactFlowProps {
|
|
13
|
+
smartEdgeDebug?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const GraphWrapper = (args: GraphWrapperProps) => (
|
|
17
|
+
<SmartEdgeDebugProvider value={args.smartEdgeDebug}>
|
|
18
|
+
<div data-testid="graph-wrapper" style={{ ...style, position: "relative" }}>
|
|
19
|
+
<ReactFlow {...args} />
|
|
20
|
+
<SmartEdgeDebugOverlay />
|
|
21
|
+
</div>
|
|
22
|
+
</SmartEdgeDebugProvider>
|
|
23
|
+
);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
edgesBezier,
|
|
3
|
+
edgesStraight,
|
|
4
|
+
edgesStep,
|
|
5
|
+
edgesLabel,
|
|
6
|
+
nodes,
|
|
7
|
+
edgeTypes,
|
|
8
|
+
simpleNodes,
|
|
9
|
+
simpleEdgesBezier,
|
|
10
|
+
} from "./DummyData";
|
|
11
|
+
import { GraphWrapper } from "./GraphWrapper";
|
|
12
|
+
import type { Meta, StoryFn } from "@storybook/react-vite";
|
|
13
|
+
import type { ReactFlowProps } from "@xyflow/react";
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
title: "Smart Edge",
|
|
17
|
+
component: GraphWrapper,
|
|
18
|
+
argTypes: {
|
|
19
|
+
smartEdgeDebug: {
|
|
20
|
+
control: { type: "boolean" },
|
|
21
|
+
defaultValue: false,
|
|
22
|
+
description: "Enable SmartEdge debug logging",
|
|
23
|
+
table: { category: "Debug" },
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
parameters: {
|
|
27
|
+
layout: "fullscreen",
|
|
28
|
+
},
|
|
29
|
+
} as Meta;
|
|
30
|
+
|
|
31
|
+
const Template: StoryFn<ReactFlowProps & { smartEdgeDebug?: boolean }> = (
|
|
32
|
+
args,
|
|
33
|
+
) => <GraphWrapper {...args} />;
|
|
34
|
+
|
|
35
|
+
export const SmartBezier = Template.bind({});
|
|
36
|
+
SmartBezier.args = {
|
|
37
|
+
edgeTypes,
|
|
38
|
+
defaultNodes: nodes,
|
|
39
|
+
defaultEdges: edgesBezier,
|
|
40
|
+
smartEdgeDebug: false,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const SmartStraight = Template.bind({});
|
|
44
|
+
SmartStraight.args = {
|
|
45
|
+
...SmartBezier.args,
|
|
46
|
+
defaultEdges: edgesStraight,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const SmartStep = Template.bind({});
|
|
50
|
+
SmartStep.args = {
|
|
51
|
+
...SmartBezier.args,
|
|
52
|
+
defaultEdges: edgesStep,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const SmartBezierWithCustomLabel = Template.bind({});
|
|
56
|
+
SmartBezierWithCustomLabel.args = {
|
|
57
|
+
...SmartBezier.args,
|
|
58
|
+
defaultEdges: edgesLabel,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const SmartBezierSimple = Template.bind({});
|
|
62
|
+
SmartBezierSimple.args = {
|
|
63
|
+
edgeTypes,
|
|
64
|
+
defaultNodes: simpleNodes,
|
|
65
|
+
defaultEdges: simpleEdgesBezier,
|
|
66
|
+
smartEdgeDebug: false,
|
|
67
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|