-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathEditor.tsx
92 lines (87 loc) · 2.04 KB
/
Editor.tsx
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
import {
Connection,
ConnectionLineType,
EdgeChange,
MarkerType,
NodeChange,
useReactFlow,
} from "@reactflow/core";
import React, { useCallback, useState } from "react";
import ReactFlow, {
addEdge,
applyEdgeChanges,
applyNodeChanges,
Background,
Controls,
Edge,
MiniMap,
Node,
} from "reactflow";
import "reactflow/dist/style.css";
import { Bar } from "./Bar";
import shallow from "zustand/shallow";
import { Nodes, NodesState } from "./Nodes";
const selector = (state: NodesState) => ({
nodes: state.nodes,
edges: state.edges,
onNodesChange: state.onNodesChange,
onEdgesChange: state.onEdgesChange,
onConnect: state.onConnect,
addNode: state.addNode,
});
export function Editor() {
const { nodes, edges, onNodesChange, onEdgesChange, onConnect, addNode } =
Nodes.use(selector, shallow);
return (
<>
<ReactFlow
nodes={nodes}
onNodesChange={onNodesChange}
edges={edges}
onEdgesChange={onEdgesChange}
onConnect={onConnect}
proOptions={{
hideAttribution: true,
}}
nodeTypes={Nodes.nodeTypes}
className="bg-neutral-900"
defaultEdgeOptions={{
type: "smoothstep",
style: {
stroke: "#3b3b3b",
strokeWidth: 2,
},
markerEnd: {
type: MarkerType.ArrowClosed,
color: "#3b3b3b",
},
}}
nodeOrigin={[0.5, 0.5]}
connectionLineStyle={{
stroke: "#3b3b3b",
strokeWidth: 2,
}}
connectionLineType={ConnectionLineType.SmoothStep}
>
<Background />
<Controls />
{/* <MiniMap /> */}
</ReactFlow>
<Bar
onCreateNode={(newNode) => {
addNode({
...newNode,
data: {
...newNode.data,
locked: false,
running: false,
repeating: false,
},
id: Math.random().toString(),
});
}}
/>
</>
);
}
export namespace Editor {}