Skip to content

Commit 9593bb5

Browse files
authored
Merge pull request #4 from xyflow/v12
V12
2 parents d0ebf1e + fc84911 commit 9593bb5

File tree

100 files changed

+24558
-35441
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+24558
-35441
lines changed

reactflow-astro/package-lock.json

Lines changed: 2034 additions & 1818 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

reactflow-astro/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
"astro": "astro"
1111
},
1212
"dependencies": {
13-
"@reactflow/core": "^11.9.0",
14-
"astro": "^3.0.13",
13+
"@xyflow/react": "^12.0.0",
14+
"astro": "^4.5.3",
1515
"react": "^18.2.0",
1616
"react-dom": "^18.2.0"
1717
},
1818
"devDependencies": {
19-
"@astrojs/react": "^3.0.2",
20-
"@types/react": "^18.2.21",
21-
"@types/react-dom": "^18.2.7"
19+
"@astrojs/react": "^3.1.0",
20+
"@types/react": "^18.2.65",
21+
"@types/react-dom": "^18.2.22"
2222
}
2323
}

reactflow-astro/public/favicon.ico

111 KB
Binary file not shown.

reactflow-astro/public/favicon.svg

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { useCallback } from "react";
2+
import {
3+
Background,
4+
Controls,
5+
MiniMap,
6+
ReactFlow,
7+
addEdge,
8+
useNodesState,
9+
useEdgesState,
10+
type OnConnect,
11+
} from "@xyflow/react";
12+
13+
import "@xyflow/react/dist/style.css";
14+
15+
import { initialNodes, nodeTypes, type CustomNodeType } from "./nodes";
16+
import { initialEdges, edgeTypes, type CustomEdgeType } from "./edges";
17+
18+
export default function App() {
19+
const [nodes, , onNodesChange] = useNodesState<CustomNodeType>(initialNodes);
20+
const [edges, setEdges, onEdgesChange] =
21+
useEdgesState<CustomEdgeType>(initialEdges);
22+
const onConnect: OnConnect = useCallback(
23+
(connection) => setEdges((edges) => addEdge(connection, edges)),
24+
[setEdges]
25+
);
26+
27+
return (
28+
<ReactFlow<CustomNodeType, CustomEdgeType>
29+
nodes={nodes}
30+
nodeTypes={nodeTypes}
31+
onNodesChange={onNodesChange}
32+
edges={edges}
33+
edgeTypes={edgeTypes}
34+
onEdgesChange={onEdgesChange}
35+
onConnect={onConnect}
36+
fitView
37+
>
38+
<Background />
39+
<MiniMap />
40+
<Controls />
41+
</ReactFlow>
42+
);
43+
}

reactflow-astro/src/components/Flow/CustomNode.tsx

Lines changed: 0 additions & 42 deletions
This file was deleted.

reactflow-astro/src/components/Flow/index.tsx

Lines changed: 0 additions & 72 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import {
2+
BaseEdge,
3+
EdgeLabelRenderer,
4+
getBezierPath,
5+
useReactFlow,
6+
type EdgeProps,
7+
type Edge,
8+
} from "@xyflow/react";
9+
10+
const buttonStyle = {
11+
width: 20,
12+
height: 20,
13+
background: "#eee",
14+
border: "1px solid #fff",
15+
cursor: "pointer",
16+
borderRadius: "50%",
17+
fontSize: "12px",
18+
lineHeight: 1,
19+
};
20+
21+
type ButtonEdgeData = {};
22+
23+
export type ButtonEdge = Edge<ButtonEdgeData>;
24+
25+
export default function ButtonEdge({
26+
id,
27+
sourceX,
28+
sourceY,
29+
targetX,
30+
targetY,
31+
sourcePosition,
32+
targetPosition,
33+
style = {},
34+
markerEnd,
35+
}: EdgeProps<ButtonEdge>) {
36+
const { setEdges } = useReactFlow();
37+
const [edgePath, labelX, labelY] = getBezierPath({
38+
sourceX,
39+
sourceY,
40+
sourcePosition,
41+
targetX,
42+
targetY,
43+
targetPosition,
44+
});
45+
46+
const onEdgeClick = () => {
47+
setEdges((edges) => edges.filter((edge) => edge.id !== id));
48+
};
49+
50+
return (
51+
<>
52+
<BaseEdge path={edgePath} markerEnd={markerEnd} style={style} />
53+
<EdgeLabelRenderer>
54+
<div
55+
style={{
56+
position: "absolute",
57+
transform: `translate(-50%, -50%) translate(${labelX}px,${labelY}px)`,
58+
fontSize: 12,
59+
// everything inside EdgeLabelRenderer has no pointer events by default
60+
// if you have an interactive element, set pointer-events: all
61+
pointerEvents: "all",
62+
}}
63+
className="nodrag nopan"
64+
>
65+
<button style={buttonStyle} onClick={onEdgeClick}>
66+
×
67+
</button>
68+
</div>
69+
</EdgeLabelRenderer>
70+
</>
71+
);
72+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { BuiltInEdge, Edge, EdgeTypes } from "@xyflow/react";
2+
3+
import ButtonEdge, { type ButtonEdge as ButtonEdgeType } from "./ButtonEdge";
4+
5+
export const initialEdges = [
6+
{ id: "a->c", source: "a", target: "c", animated: true },
7+
{ id: "b->d", source: "b", target: "d", type: "button-edge" },
8+
{ id: "c->d", source: "c", target: "d", animated: true },
9+
] satisfies Edge[];
10+
11+
export const edgeTypes = {
12+
// Add your custom edge types here!
13+
"button-edge": ButtonEdge,
14+
} satisfies EdgeTypes;
15+
16+
// Append the types of you custom edges to the BuiltInEdge type
17+
export type CustomEdgeType = BuiltInEdge | ButtonEdgeType;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { Node, NodeProps } from "@xyflow/react";
2+
import { Handle, Position } from "@xyflow/react";
3+
4+
export type PositionLoggerNodeData = {
5+
label?: string;
6+
};
7+
8+
export type PositionLoggerNode = Node<PositionLoggerNodeData>;
9+
10+
export default function PositionLoggerNode({
11+
positionAbsoluteX,
12+
positionAbsoluteY,
13+
data,
14+
}: NodeProps<PositionLoggerNode>) {
15+
const x = `${Math.round(positionAbsoluteX)}px`;
16+
const y = `${Math.round(positionAbsoluteY)}px`;
17+
18+
return (
19+
// We add this class to use the same styles as React Flow's default nodes.
20+
<div className="react-flow__node-default">
21+
{data.label && <div>{data.label}</div>}
22+
23+
<div>
24+
{x} {y}
25+
</div>
26+
27+
<Handle type="source" position={Position.Bottom} />
28+
</div>
29+
);
30+
}

0 commit comments

Comments
 (0)