Skip to content

Commit 53e7bbb

Browse files
author
xwj02155382
committed
feat: add README.md
1 parent 22703b9 commit 53e7bbb

File tree

1 file changed

+183
-1
lines changed

1 file changed

+183
-1
lines changed
Lines changed: 183 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,183 @@
1-
# Studio Flow Editor
1+
# Studio Flow Editor
2+
3+
一个基于 ReactFlow 的流程图编辑器组件,提供图形化编辑、节点管理、边连接等功能。
4+
5+
## 特性
6+
7+
- 🎨 基于 ReactFlow 的流程图编辑器
8+
- 📦 支持节点和边的增删改查
9+
- 🖱️ 支持拖拽、缩放、平移等交互
10+
- 🎯 支持自定义节点和边的样式
11+
- 🔄 支持数据导入导出
12+
- 🎮 提供丰富的工具函数和 hooks
13+
14+
## 安装
15+
16+
```bash
17+
npm install @graphscope/studio-flow-editor
18+
#
19+
yarn add @graphscope/studio-flow-editor
20+
```
21+
22+
## 快速开始
23+
24+
```tsx
25+
import { GraphEditor, GraphProvider } from '@graphscope/studio-flow-editor';
26+
27+
function App() {
28+
return (
29+
<GraphProvider>
30+
<GraphEditor/>
31+
</GraphProvider>
32+
);
33+
}
34+
```
35+
36+
## 组件
37+
38+
### GraphEditor
39+
40+
流程图编辑器主组件。
41+
42+
```tsx
43+
<GraphEditor/>
44+
```
45+
46+
#### Props
47+
48+
49+
| 参数 | 类型 | 说明 |
50+
| -------------- | --------------- | ------------------------------------------ |
51+
| children | React.ReactNode | 可以在 ReactFlow 内部添加自定义子组件 |
52+
| showBackground | boolean | 可以在 ReactFlow 是否显示背景,默认为 true |
53+
| showMinimap | boolean | 是否显示迷你地图,默认为 true |
54+
| showDefaultBtn | boolean | 是否显示默认按钮控制器,默认为 true |
55+
56+
### 按钮组件
57+
58+
#### AddNode
59+
60+
添加节点按钮。
61+
62+
```tsx
63+
import { AddNode } from '@graphscope/studio-flow-editor';
64+
65+
<AddNode />
66+
```
67+
68+
#### ClearCanvas
69+
70+
清空画布按钮。
71+
72+
```tsx
73+
import { ClearCanvas } from '@graphscope/studio-flow-editor';
74+
75+
<ClearCanvas />
76+
```
77+
78+
#### ExportSvg
79+
80+
导出 SVG 按钮。
81+
82+
```tsx
83+
import { ExportSvg } from '@graphscope/studio-flow-editor';
84+
85+
<ExportSvg />
86+
```
87+
88+
## Hooks
89+
90+
### useGraphStore
91+
92+
状态管理 hook。
93+
94+
```tsx
95+
import { useGraphStore } from '@graphscope/studio-flow-editor';
96+
97+
const { store, updateStore } = useGraphStore();
98+
```
99+
100+
### useClearCanvas
101+
102+
清空画布 hook。
103+
104+
```tsx
105+
import { useClearCanvas } from '@graphscope/studio-flow-editor';
106+
107+
const { clearCanvas } = useClearCanvas();
108+
```
109+
110+
### useAddNode
111+
112+
添加节点 hook。
113+
114+
```tsx
115+
import { useAddNode } from '@graphscope/studio-flow-editor';
116+
117+
const { addNode } = useAddNode();
118+
```
119+
120+
### useExportSvg
121+
122+
导出 SVG hook。
123+
124+
```tsx
125+
import { useExportSvg } from '@graphscope/studio-flow-editor';
126+
127+
const { exportSvg } = useExportSvg();
128+
```
129+
130+
## 工具函数
131+
132+
### 布局工具
133+
134+
```typescript
135+
import { getBBox } from '@graphscope/studio-flow-editor';
136+
137+
// 获取节点边界框
138+
const bbox = getBBox(nodes);
139+
```
140+
141+
### 标签工具
142+
143+
```typescript
144+
import { createNodeLabel, createEdgeLabel } from '@graphscope/studio-flow-editor';
145+
146+
// 创建节点标签
147+
const nodeLabel = createNodeLabel();
148+
149+
// 创建边标签
150+
const edgeLabel = createEdgeLabel();
151+
```
152+
153+
### 数据处理
154+
155+
```typescript
156+
import { fakeSnapshot } from '@graphscope/studio-flow-editor';
157+
158+
// 创建数据快照
159+
const snapshot = fakeSnapshot(data);
160+
161+
162+
## 类型定义
163+
164+
```typescript
165+
import { ISchemaNode, ISchemaEdge } from '@graphscope/studio-flow-editor';
166+
167+
// 节点类型
168+
const node: ISchemaNode = {
169+
id: '1',
170+
type: 'default',
171+
position: { x: 0, y: 0 },
172+
data: { label: 'Node 1' }
173+
};
174+
175+
// 边类型
176+
const edge: ISchemaEdge = {
177+
id: 'e1-2',
178+
source: '1',
179+
target: '2',
180+
data: { label: 'Edge 1-2' }
181+
};
182+
```
183+

0 commit comments

Comments
 (0)