@gantfdt/semiword 0.0.0-stage → 1.0.0
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 +6 -0
- package/README.md +258 -2
- package/dist-lib/FlowchartEditor-EFUVACVN.mjs +442 -0
- package/dist-lib/FlowchartEditor-EFUVACVN.mjs.map +1 -0
- package/dist-lib/MindmapEditor-CCJRPI4I.mjs +141 -0
- package/dist-lib/MindmapEditor-CCJRPI4I.mjs.map +1 -0
- package/dist-lib/WhiteboardEditor-STZ7W7XX.mjs +120 -0
- package/dist-lib/WhiteboardEditor-STZ7W7XX.mjs.map +1 -0
- package/dist-lib/ai.d.mts +33 -0
- package/dist-lib/ai.mjs +14 -0
- package/dist-lib/ai.mjs.map +1 -0
- package/dist-lib/chunk-347SCO7S.mjs +3 -0
- package/dist-lib/chunk-347SCO7S.mjs.map +1 -0
- package/dist-lib/chunk-4F4NEVHE.mjs +100 -0
- package/dist-lib/chunk-4F4NEVHE.mjs.map +1 -0
- package/dist-lib/chunk-4W6PPBHQ.mjs +474 -0
- package/dist-lib/chunk-4W6PPBHQ.mjs.map +1 -0
- package/dist-lib/chunk-7AAZUM6M.mjs +45 -0
- package/dist-lib/chunk-7AAZUM6M.mjs.map +1 -0
- package/dist-lib/chunk-BBZ5ZBEK.mjs +1510 -0
- package/dist-lib/chunk-BBZ5ZBEK.mjs.map +1 -0
- package/dist-lib/chunk-CREU4TZJ.mjs +24 -0
- package/dist-lib/chunk-CREU4TZJ.mjs.map +1 -0
- package/dist-lib/chunk-EEUFVA37.mjs +4024 -0
- package/dist-lib/chunk-EEUFVA37.mjs.map +1 -0
- package/dist-lib/chunk-EOIJPQZI.mjs +370 -0
- package/dist-lib/chunk-EOIJPQZI.mjs.map +1 -0
- package/dist-lib/chunk-EOUNN3NA.mjs +1517 -0
- package/dist-lib/chunk-EOUNN3NA.mjs.map +1 -0
- package/dist-lib/chunk-FOIP7DEC.mjs +12 -0
- package/dist-lib/chunk-FOIP7DEC.mjs.map +1 -0
- package/dist-lib/chunk-GGIOCI2I.mjs +2442 -0
- package/dist-lib/chunk-GGIOCI2I.mjs.map +1 -0
- package/dist-lib/chunk-IICCIMZU.mjs +5272 -0
- package/dist-lib/chunk-IICCIMZU.mjs.map +1 -0
- package/dist-lib/chunk-JC5ZZPSL.mjs +600 -0
- package/dist-lib/chunk-JC5ZZPSL.mjs.map +1 -0
- package/dist-lib/chunk-K7Z56Q4M.mjs +6327 -0
- package/dist-lib/chunk-K7Z56Q4M.mjs.map +1 -0
- package/dist-lib/chunk-NPPS63UI.mjs +285 -0
- package/dist-lib/chunk-NPPS63UI.mjs.map +1 -0
- package/dist-lib/chunk-PFA3XERW.mjs +19 -0
- package/dist-lib/chunk-PFA3XERW.mjs.map +1 -0
- package/dist-lib/chunk-QWDJU3H7.mjs +18 -0
- package/dist-lib/chunk-QWDJU3H7.mjs.map +1 -0
- package/dist-lib/chunk-TOA6CRSJ.mjs +3917 -0
- package/dist-lib/chunk-TOA6CRSJ.mjs.map +1 -0
- package/dist-lib/chunk-W627LLF4.mjs +16 -0
- package/dist-lib/chunk-W627LLF4.mjs.map +1 -0
- package/dist-lib/chunk-XAEALEVP.mjs +547 -0
- package/dist-lib/chunk-XAEALEVP.mjs.map +1 -0
- package/dist-lib/chunk-ZM3WULHX.mjs +910 -0
- package/dist-lib/chunk-ZM3WULHX.mjs.map +1 -0
- package/dist-lib/context-DKwyjx1q.d.mts +37 -0
- package/dist-lib/designer.d.mts +215 -0
- package/dist-lib/designer.mjs +15 -0
- package/dist-lib/designer.mjs.map +1 -0
- package/dist-lib/document.d.mts +12 -0
- package/dist-lib/document.mjs +4 -0
- package/dist-lib/document.mjs.map +1 -0
- package/dist-lib/editor.d.mts +408 -0
- package/dist-lib/editor.mjs +19 -0
- package/dist-lib/editor.mjs.map +1 -0
- package/dist-lib/gant-ai.d.mts +40 -0
- package/dist-lib/gant-ai.mjs +217 -0
- package/dist-lib/gant-ai.mjs.map +1 -0
- package/dist-lib/index.d.mts +22 -0
- package/dist-lib/index.mjs +19 -0
- package/dist-lib/index.mjs.map +1 -0
- package/dist-lib/interface-RYndHNLS.d.mts +91 -0
- package/dist-lib/io.d.mts +75 -0
- package/dist-lib/io.mjs +9 -0
- package/dist-lib/io.mjs.map +1 -0
- package/dist-lib/memoryHistoryStore-DY47xjO_.d.mts +280 -0
- package/dist-lib/mindmapConstants-X75XUXV3.mjs +4 -0
- package/dist-lib/mindmapConstants-X75XUXV3.mjs.map +1 -0
- package/dist-lib/resolve-BMcwblyP.d.mts +114 -0
- package/dist-lib/sdk.d.mts +60 -0
- package/dist-lib/sdk.mjs +137 -0
- package/dist-lib/sdk.mjs.map +1 -0
- package/dist-lib/shapes-5SMSF6ML.mjs +4 -0
- package/dist-lib/shapes-5SMSF6ML.mjs.map +1 -0
- package/dist-lib/storage.d.mts +91 -0
- package/dist-lib/storage.mjs +5 -0
- package/dist-lib/storage.mjs.map +1 -0
- package/dist-lib/template.d.mts +155 -0
- package/dist-lib/template.mjs +6 -0
- package/dist-lib/template.mjs.map +1 -0
- package/dist-lib/types-CO6ppyIY.d.mts +18 -0
- package/dist-lib/types-CUsV1hUm.d.mts +49 -0
- package/dist-lib/types-ClQ38-C_.d.mts +256 -0
- package/dist-lib/types-D1D2miCr.d.mts +117 -0
- package/dist-lib/types-DiyyKlc1.d.mts +355 -0
- package/dist-lib/types-s1JYaGtG.d.mts +56 -0
- package/dist-lib/types-vl8k8NDK.d.mts +562 -0
- package/dist-lib/useDocumentPersistence-DOpnQsZQ.d.mts +228 -0
- package/package.json +282 -4
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { STENCIL_NODES, EDGE_TYPES, registerFlowShapes, CONNECTING_CONNECTOR, CONNECTING_ROUTER } from './chunk-EOIJPQZI.mjs';
|
|
2
|
+
import { useIsMounted, useContainerReady } from './chunk-7AAZUM6M.mjs';
|
|
3
|
+
import { createGraphicEditorShellStyles, createStyles, Radio2, Space, Tooltip, Button, EditorActionBar, finalizeSvgRoot } from './chunk-ZM3WULHX.mjs';
|
|
4
|
+
import './chunk-4W6PPBHQ.mjs';
|
|
5
|
+
import { tr } from './chunk-W627LLF4.mjs';
|
|
6
|
+
import { useRef, useState, useCallback, useEffect } from 'react';
|
|
7
|
+
import { DeleteOutlined, ZoomInOutlined, ZoomOutOutlined, CompressOutlined } from '@ant-design/icons';
|
|
8
|
+
import { Graph } from '@antv/x6';
|
|
9
|
+
import { Snapline } from '@antv/x6-plugin-snapline';
|
|
10
|
+
import { Selection } from '@antv/x6-plugin-selection';
|
|
11
|
+
import { Keyboard } from '@antv/x6-plugin-keyboard';
|
|
12
|
+
import { Export } from '@antv/x6-plugin-export';
|
|
13
|
+
import { Dnd } from '@antv/x6-plugin-dnd';
|
|
14
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
15
|
+
|
|
16
|
+
// src/editor/plugins/builtin/flowchart/flowchartStyle.ts
|
|
17
|
+
var useShellStyles = createGraphicEditorShellStyles({ toolbarWrap: true });
|
|
18
|
+
var useFlowchartLocalStyles = createStyles(({ css, token }) => ({
|
|
19
|
+
root: css`
|
|
20
|
+
display: flex;
|
|
21
|
+
height: 100%;
|
|
22
|
+
`,
|
|
23
|
+
/** 左侧块面板 */
|
|
24
|
+
stencil: css`
|
|
25
|
+
width: 148px;
|
|
26
|
+
flex-shrink: 0;
|
|
27
|
+
display: flex;
|
|
28
|
+
flex-direction: column;
|
|
29
|
+
padding: 10px;
|
|
30
|
+
gap: 10px;
|
|
31
|
+
border-right: 1px solid ${token.colorBorderSecondary};
|
|
32
|
+
background: ${token.colorBgContainer};
|
|
33
|
+
overflow-y: auto;
|
|
34
|
+
`,
|
|
35
|
+
stencilNode: css`
|
|
36
|
+
display: flex;
|
|
37
|
+
align-items: center;
|
|
38
|
+
justify-content: center;
|
|
39
|
+
gap: 6px;
|
|
40
|
+
height: 40px;
|
|
41
|
+
padding: 0 8px;
|
|
42
|
+
border: 1px solid ${token.colorBorder};
|
|
43
|
+
border-radius: ${token.borderRadius}px;
|
|
44
|
+
background: ${token.colorBgElevated};
|
|
45
|
+
color: ${token.colorText};
|
|
46
|
+
font-size: 13px;
|
|
47
|
+
cursor: grab;
|
|
48
|
+
user-select: none;
|
|
49
|
+
transition: all 0.2s;
|
|
50
|
+
|
|
51
|
+
&:hover {
|
|
52
|
+
border-color: ${token.colorPrimary};
|
|
53
|
+
color: ${token.colorPrimary};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
img {
|
|
57
|
+
width: 16px;
|
|
58
|
+
height: 16px;
|
|
59
|
+
}
|
|
60
|
+
`,
|
|
61
|
+
stencilTitle: css`
|
|
62
|
+
font-size: 12px;
|
|
63
|
+
font-weight: 500;
|
|
64
|
+
color: ${token.colorTextSecondary};
|
|
65
|
+
margin-top: 4px;
|
|
66
|
+
`,
|
|
67
|
+
main: css`
|
|
68
|
+
flex: 1;
|
|
69
|
+
min-width: 0;
|
|
70
|
+
display: flex;
|
|
71
|
+
flex-direction: column;
|
|
72
|
+
`,
|
|
73
|
+
canvas: css`
|
|
74
|
+
width: 100%;
|
|
75
|
+
height: 100%;
|
|
76
|
+
`,
|
|
77
|
+
/** 内联文本编辑框:双击 cell 时绝对定位覆盖在其屏幕位置 */
|
|
78
|
+
textEditor: css`
|
|
79
|
+
position: absolute;
|
|
80
|
+
z-index: 10;
|
|
81
|
+
box-sizing: border-box;
|
|
82
|
+
padding: 2px 4px;
|
|
83
|
+
border: 1px solid ${token.colorPrimary};
|
|
84
|
+
border-radius: ${token.borderRadiusXS}px;
|
|
85
|
+
background: ${token.colorBgElevated};
|
|
86
|
+
color: ${token.colorText};
|
|
87
|
+
font-size: 13px;
|
|
88
|
+
line-height: 1.4;
|
|
89
|
+
text-align: center;
|
|
90
|
+
outline: none;
|
|
91
|
+
resize: none;
|
|
92
|
+
box-shadow: ${token.boxShadowSecondary};
|
|
93
|
+
`
|
|
94
|
+
}));
|
|
95
|
+
function useFlowchartEditorStyles() {
|
|
96
|
+
const { styles: local } = useFlowchartLocalStyles();
|
|
97
|
+
const { styles: shell } = useShellStyles();
|
|
98
|
+
return {
|
|
99
|
+
styles: {
|
|
100
|
+
...local,
|
|
101
|
+
toolbar: shell.toolbar,
|
|
102
|
+
spacer: shell.spacer,
|
|
103
|
+
canvasWrap: shell.canvas
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function createGraph(container, edgeTypeRef) {
|
|
108
|
+
const graph = new Graph({
|
|
109
|
+
container,
|
|
110
|
+
autoResize: true,
|
|
111
|
+
// async:false -- 让模型变更同步渲染进实时 SVG DOM,导出快照的 toSVG 克隆这份实时 SVG,
|
|
112
|
+
// 同步渲染确保刚拖入 / 更新的节点一定已在 DOM 中、不被漏掉。
|
|
113
|
+
async: false,
|
|
114
|
+
background: { color: "#fafafa" },
|
|
115
|
+
grid: { visible: true, type: "dot", size: 12, args: { color: "#e0e0e0" } },
|
|
116
|
+
panning: true,
|
|
117
|
+
mousewheel: { enabled: true, modifiers: ["ctrl", "meta"] },
|
|
118
|
+
connecting: {
|
|
119
|
+
router: CONNECTING_ROUTER,
|
|
120
|
+
connector: CONNECTING_CONNECTOR,
|
|
121
|
+
anchor: "center",
|
|
122
|
+
connectionPoint: "boundary",
|
|
123
|
+
allowBlank: false,
|
|
124
|
+
allowLoop: false,
|
|
125
|
+
allowNode: false,
|
|
126
|
+
snap: { radius: 20 },
|
|
127
|
+
// 按当前选中的连线类型创建对应样式的边
|
|
128
|
+
createEdge() {
|
|
129
|
+
return graph.createEdge({ shape: edgeTypeRef.current });
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
highlighting: {
|
|
133
|
+
magnetAvailable: {
|
|
134
|
+
name: "stroke",
|
|
135
|
+
args: { attrs: { stroke: "#43bbef", "stroke-width": 2 } }
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
graph.use(new Snapline({ enabled: true })).use(new Selection({ enabled: true, showNodeSelectionBox: true, rubberband: true })).use(new Keyboard({ enabled: true })).use(new Export());
|
|
140
|
+
return graph;
|
|
141
|
+
}
|
|
142
|
+
function wireGraphEvents(graph, containerRef, onCellDblClick) {
|
|
143
|
+
const showPorts = (nodeId, show) => {
|
|
144
|
+
const ports = containerRef.current?.querySelectorAll(`[data-cell-id="${CSS.escape(nodeId)}"] .x6-port-body`);
|
|
145
|
+
ports?.forEach((p) => {
|
|
146
|
+
p.style.visibility = show ? "visible" : "hidden";
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
graph.on("node:mouseenter", ({ node }) => showPorts(node.id, true));
|
|
150
|
+
graph.on("node:mouseleave", ({ node }) => showPorts(node.id, false));
|
|
151
|
+
graph.on("cell:dblclick", ({ cell, e }) => {
|
|
152
|
+
e.stopPropagation();
|
|
153
|
+
onCellDblClick(cell);
|
|
154
|
+
});
|
|
155
|
+
graph.bindKey(["delete", "backspace"], () => {
|
|
156
|
+
const cells = graph.getSelectedCells();
|
|
157
|
+
if (cells.length) graph.removeCells(cells);
|
|
158
|
+
return false;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function loadInitialData(graph, value) {
|
|
162
|
+
const loadDefaultNodes = () => {
|
|
163
|
+
graph.fromJSON({
|
|
164
|
+
nodes: [
|
|
165
|
+
{ shape: "_type_start", x: 300, y: 80, attrs: { text: { text: tr("\u5F00\u59CB") } } },
|
|
166
|
+
{ shape: "_type_end", x: 300, y: 320, attrs: { text: { text: tr("\u7ED3\u675F") } } }
|
|
167
|
+
]
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
try {
|
|
171
|
+
if (value?.cells?.length) {
|
|
172
|
+
graph.fromJSON({ cells: value.cells });
|
|
173
|
+
} else {
|
|
174
|
+
loadDefaultNodes();
|
|
175
|
+
}
|
|
176
|
+
} catch (e) {
|
|
177
|
+
console.warn("[flowchart] fromJSON \u8F7D\u5165\u5931\u8D25\uFF0C\u56DE\u9000\u9ED8\u8BA4\u8282\u70B9:", e);
|
|
178
|
+
try {
|
|
179
|
+
graph.clearCells();
|
|
180
|
+
loadDefaultNodes();
|
|
181
|
+
} catch {
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
graph.centerContent();
|
|
185
|
+
}
|
|
186
|
+
function useFlowchartGraph({
|
|
187
|
+
ready,
|
|
188
|
+
containerRef,
|
|
189
|
+
graphRef,
|
|
190
|
+
dndRef,
|
|
191
|
+
value,
|
|
192
|
+
onCellDblClick
|
|
193
|
+
}) {
|
|
194
|
+
const edgeTypeRef = useRef("approve");
|
|
195
|
+
useEffect(() => {
|
|
196
|
+
if (!ready || !containerRef.current) return;
|
|
197
|
+
registerFlowShapes();
|
|
198
|
+
const graph = createGraph(containerRef.current, edgeTypeRef);
|
|
199
|
+
wireGraphEvents(graph, containerRef, onCellDblClick);
|
|
200
|
+
loadInitialData(graph, value);
|
|
201
|
+
graphRef.current = graph;
|
|
202
|
+
dndRef.current = new Dnd({
|
|
203
|
+
target: graph,
|
|
204
|
+
getDragNode: (node) => node.clone({ keepId: true }),
|
|
205
|
+
getDropNode: (node) => node.clone({ keepId: true })
|
|
206
|
+
});
|
|
207
|
+
return () => {
|
|
208
|
+
dndRef.current?.dispose();
|
|
209
|
+
dndRef.current = null;
|
|
210
|
+
graph.dispose();
|
|
211
|
+
graphRef.current = null;
|
|
212
|
+
};
|
|
213
|
+
}, [ready]);
|
|
214
|
+
return { edgeTypeRef };
|
|
215
|
+
}
|
|
216
|
+
function getCellText(cell) {
|
|
217
|
+
if (cell.isNode()) {
|
|
218
|
+
const text2 = cell.attr("text/text");
|
|
219
|
+
return typeof text2 === "string" ? text2 : "";
|
|
220
|
+
}
|
|
221
|
+
const labels = cell.isEdge() ? cell.getLabels() : [];
|
|
222
|
+
const first = labels[0];
|
|
223
|
+
const text = first?.attrs?.label?.text;
|
|
224
|
+
return typeof text === "string" ? text : "";
|
|
225
|
+
}
|
|
226
|
+
function useFlowchartTextEditor({ graphRef, wrapRef }) {
|
|
227
|
+
const [textEditor, setTextEditor] = useState(null);
|
|
228
|
+
const textareaRef = useRef(null);
|
|
229
|
+
const openTextEditor = useCallback(
|
|
230
|
+
(cell) => {
|
|
231
|
+
const graph = graphRef.current;
|
|
232
|
+
const wrap = wrapRef.current;
|
|
233
|
+
if (!graph || !wrap) return;
|
|
234
|
+
const bbox = cell.getBBox();
|
|
235
|
+
const topLeft = graph.localToClient(bbox.x, bbox.y);
|
|
236
|
+
const bottomRight = graph.localToClient(bbox.x + bbox.width, bbox.y + bbox.height);
|
|
237
|
+
const wrapRect = wrap.getBoundingClientRect();
|
|
238
|
+
setTextEditor({
|
|
239
|
+
cellId: cell.id,
|
|
240
|
+
left: topLeft.x - wrapRect.left,
|
|
241
|
+
top: topLeft.y - wrapRect.top,
|
|
242
|
+
width: Math.max(bottomRight.x - topLeft.x, 40),
|
|
243
|
+
height: Math.max(bottomRight.y - topLeft.y, 24),
|
|
244
|
+
value: getCellText(cell)
|
|
245
|
+
});
|
|
246
|
+
},
|
|
247
|
+
[graphRef, wrapRef]
|
|
248
|
+
);
|
|
249
|
+
useEffect(() => {
|
|
250
|
+
if (textEditor && textareaRef.current) {
|
|
251
|
+
textareaRef.current.focus();
|
|
252
|
+
textareaRef.current.select();
|
|
253
|
+
}
|
|
254
|
+
}, [textEditor?.cellId]);
|
|
255
|
+
const commitTextEditor = useCallback(() => {
|
|
256
|
+
const graph = graphRef.current;
|
|
257
|
+
const current = textEditor;
|
|
258
|
+
setTextEditor(null);
|
|
259
|
+
if (!current || !graph) return;
|
|
260
|
+
const cell = graph.getCellById(current.cellId);
|
|
261
|
+
if (cell) {
|
|
262
|
+
const text = current.value;
|
|
263
|
+
if (cell.isNode()) {
|
|
264
|
+
cell.attr("text/text", text);
|
|
265
|
+
} else if (cell.isEdge()) {
|
|
266
|
+
cell.setLabels(text ? [{ attrs: { label: { text } } }] : []);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}, [graphRef, textEditor]);
|
|
270
|
+
const cancelTextEditor = useCallback(() => setTextEditor(null), []);
|
|
271
|
+
return { textEditor, setTextEditor, textareaRef, openTextEditor, commitTextEditor, cancelTextEditor };
|
|
272
|
+
}
|
|
273
|
+
function FlowchartTextEditorOverlay({
|
|
274
|
+
state,
|
|
275
|
+
textareaRef,
|
|
276
|
+
className,
|
|
277
|
+
onChange,
|
|
278
|
+
onCommit,
|
|
279
|
+
onCancel
|
|
280
|
+
}) {
|
|
281
|
+
if (!state) return null;
|
|
282
|
+
return /* @__PURE__ */ jsx(
|
|
283
|
+
"textarea",
|
|
284
|
+
{
|
|
285
|
+
ref: textareaRef,
|
|
286
|
+
className,
|
|
287
|
+
style: {
|
|
288
|
+
left: state.left,
|
|
289
|
+
top: state.top,
|
|
290
|
+
width: state.width,
|
|
291
|
+
height: state.height
|
|
292
|
+
},
|
|
293
|
+
value: state.value,
|
|
294
|
+
onChange: (e) => onChange(e.target.value),
|
|
295
|
+
onBlur: onCommit,
|
|
296
|
+
onKeyDown: (e) => {
|
|
297
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
298
|
+
e.preventDefault();
|
|
299
|
+
onCommit();
|
|
300
|
+
} else if (e.key === "Escape") {
|
|
301
|
+
e.preventDefault();
|
|
302
|
+
onCancel();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
function processExportedSvg(raw) {
|
|
309
|
+
const empty = { svg: "", width: 0, height: 0 };
|
|
310
|
+
if (!raw) return empty;
|
|
311
|
+
const doc = new DOMParser().parseFromString(raw, "image/svg+xml");
|
|
312
|
+
if (doc.querySelector("parsererror") || doc.documentElement.tagName.toLowerCase() !== "svg") {
|
|
313
|
+
return empty;
|
|
314
|
+
}
|
|
315
|
+
return finalizeSvgRoot(doc.documentElement, {
|
|
316
|
+
stripSelectors: [".x6-port", ".x6-port-body", ".x6-cell-tool", ".x6-cell-tools"],
|
|
317
|
+
forceAspectRatio: true
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
function FlowchartEditor({ value, onSave, onCancel }) {
|
|
321
|
+
const { styles } = useFlowchartEditorStyles();
|
|
322
|
+
const wrapRef = useRef(null);
|
|
323
|
+
const containerRef = useRef(null);
|
|
324
|
+
const graphRef = useRef(null);
|
|
325
|
+
const dndRef = useRef(null);
|
|
326
|
+
const [edgeType, setEdgeType] = useState("approve");
|
|
327
|
+
const mountedRef = useIsMounted();
|
|
328
|
+
const ready = useContainerReady(containerRef);
|
|
329
|
+
const { textEditor, setTextEditor, textareaRef, openTextEditor, commitTextEditor, cancelTextEditor } = useFlowchartTextEditor({ graphRef, wrapRef });
|
|
330
|
+
const { edgeTypeRef } = useFlowchartGraph({
|
|
331
|
+
ready,
|
|
332
|
+
containerRef,
|
|
333
|
+
graphRef,
|
|
334
|
+
dndRef,
|
|
335
|
+
value,
|
|
336
|
+
onCellDblClick: openTextEditor
|
|
337
|
+
});
|
|
338
|
+
const handleStencilMouseDown = useCallback((shape, label, e) => {
|
|
339
|
+
const graph = graphRef.current;
|
|
340
|
+
const dnd = dndRef.current;
|
|
341
|
+
if (!graph || !dnd) return;
|
|
342
|
+
const node = graph.createNode({ shape, attrs: { text: { text: tr(label) } } });
|
|
343
|
+
dnd.start(node, e.nativeEvent);
|
|
344
|
+
}, []);
|
|
345
|
+
const handleEdgeTypeChange = useCallback(
|
|
346
|
+
(next) => {
|
|
347
|
+
edgeTypeRef.current = next;
|
|
348
|
+
setEdgeType(next);
|
|
349
|
+
},
|
|
350
|
+
[edgeTypeRef]
|
|
351
|
+
);
|
|
352
|
+
const handleDelete = useCallback(() => {
|
|
353
|
+
const graph = graphRef.current;
|
|
354
|
+
if (!graph) return;
|
|
355
|
+
const cells = graph.getSelectedCells();
|
|
356
|
+
if (cells.length) graph.removeCells(cells);
|
|
357
|
+
}, []);
|
|
358
|
+
const handleZoom = useCallback((factor) => {
|
|
359
|
+
graphRef.current?.zoom(factor);
|
|
360
|
+
}, []);
|
|
361
|
+
const handleFit = useCallback(() => {
|
|
362
|
+
graphRef.current?.zoomToFit({ padding: 24, maxScale: 1 });
|
|
363
|
+
}, []);
|
|
364
|
+
const handleSave = useCallback(async () => {
|
|
365
|
+
const graph = graphRef.current;
|
|
366
|
+
if (!graph) return;
|
|
367
|
+
graph.cleanSelection();
|
|
368
|
+
graph.matrix({ a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 });
|
|
369
|
+
const data = graph.toJSON();
|
|
370
|
+
let result = { svg: "", width: 0, height: 0 };
|
|
371
|
+
try {
|
|
372
|
+
const raw = await new Promise((resolve) => {
|
|
373
|
+
graph.toSVG((svgString) => resolve(svgString), {
|
|
374
|
+
copyStyles: false,
|
|
375
|
+
preserveDimensions: true,
|
|
376
|
+
// 内容包围盒四周留白,避免贴边节点描边被裁
|
|
377
|
+
viewBox: (() => {
|
|
378
|
+
const box = graph.getContentArea();
|
|
379
|
+
const PAD = 16;
|
|
380
|
+
return {
|
|
381
|
+
x: box.x - PAD,
|
|
382
|
+
y: box.y - PAD,
|
|
383
|
+
width: box.width + PAD * 2,
|
|
384
|
+
height: box.height + PAD * 2
|
|
385
|
+
};
|
|
386
|
+
})()
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
result = processExportedSvg(raw);
|
|
390
|
+
} catch {
|
|
391
|
+
result = { svg: "", width: 0, height: 0 };
|
|
392
|
+
}
|
|
393
|
+
if (!mountedRef.current) return;
|
|
394
|
+
onSave({ data, ...result });
|
|
395
|
+
}, [onSave]);
|
|
396
|
+
return /* @__PURE__ */ jsxs("div", { className: styles.root, children: [
|
|
397
|
+
/* @__PURE__ */ jsxs("div", { className: styles.stencil, children: [
|
|
398
|
+
STENCIL_NODES.map((n) => /* @__PURE__ */ jsxs(
|
|
399
|
+
"div",
|
|
400
|
+
{
|
|
401
|
+
className: styles.stencilNode,
|
|
402
|
+
onMouseDown: (e) => handleStencilMouseDown(n.shape, n.label, e),
|
|
403
|
+
children: [
|
|
404
|
+
/* @__PURE__ */ jsx("img", { src: n.icon, alt: "" }),
|
|
405
|
+
/* @__PURE__ */ jsx("span", { children: tr(n.label) })
|
|
406
|
+
]
|
|
407
|
+
},
|
|
408
|
+
n.shape
|
|
409
|
+
)),
|
|
410
|
+
/* @__PURE__ */ jsx("div", { className: styles.stencilTitle, children: tr("\u64CD\u4F5C\u7C7B\u578B") }),
|
|
411
|
+
/* @__PURE__ */ jsx(Radio2.Group, { value: edgeType, onChange: (e) => handleEdgeTypeChange(e.target.value), children: /* @__PURE__ */ jsx(Space, { direction: "vertical", size: 4, children: EDGE_TYPES.map((t) => /* @__PURE__ */ jsx(Radio2, { value: t.value, children: tr(t.label) }, t.value)) }) })
|
|
412
|
+
] }),
|
|
413
|
+
/* @__PURE__ */ jsxs("div", { className: styles.main, children: [
|
|
414
|
+
/* @__PURE__ */ jsxs("div", { className: styles.toolbar, children: [
|
|
415
|
+
/* @__PURE__ */ jsx(Tooltip, { title: tr("\u5220\u9664\u9009\u4E2D"), children: /* @__PURE__ */ jsx(Button, { size: "small", icon: /* @__PURE__ */ jsx(DeleteOutlined, {}), onClick: handleDelete }) }),
|
|
416
|
+
/* @__PURE__ */ jsx(Tooltip, { title: tr("\u653E\u5927"), children: /* @__PURE__ */ jsx(Button, { size: "small", icon: /* @__PURE__ */ jsx(ZoomInOutlined, {}), onClick: () => handleZoom(0.1) }) }),
|
|
417
|
+
/* @__PURE__ */ jsx(Tooltip, { title: tr("\u7F29\u5C0F"), children: /* @__PURE__ */ jsx(Button, { size: "small", icon: /* @__PURE__ */ jsx(ZoomOutOutlined, {}), onClick: () => handleZoom(-0.1) }) }),
|
|
418
|
+
/* @__PURE__ */ jsx(Tooltip, { title: tr("\u9002\u5E94\u753B\u5E03"), children: /* @__PURE__ */ jsx(Button, { size: "small", icon: /* @__PURE__ */ jsx(CompressOutlined, {}), onClick: handleFit }) }),
|
|
419
|
+
/* @__PURE__ */ jsx("span", { className: styles.spacer }),
|
|
420
|
+
/* @__PURE__ */ jsx(EditorActionBar, { onCancel, onSave: handleSave })
|
|
421
|
+
] }),
|
|
422
|
+
/* @__PURE__ */ jsxs("div", { className: styles.canvasWrap, ref: wrapRef, children: [
|
|
423
|
+
/* @__PURE__ */ jsx("div", { ref: containerRef, className: styles.canvas }),
|
|
424
|
+
/* @__PURE__ */ jsx(
|
|
425
|
+
FlowchartTextEditorOverlay,
|
|
426
|
+
{
|
|
427
|
+
state: textEditor,
|
|
428
|
+
textareaRef,
|
|
429
|
+
className: styles.textEditor,
|
|
430
|
+
onChange: (next) => setTextEditor((current) => current ? { ...current, value: next } : current),
|
|
431
|
+
onCommit: commitTextEditor,
|
|
432
|
+
onCancel: cancelTextEditor
|
|
433
|
+
}
|
|
434
|
+
)
|
|
435
|
+
] })
|
|
436
|
+
] })
|
|
437
|
+
] });
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
export { FlowchartEditor as default };
|
|
441
|
+
//# sourceMappingURL=FlowchartEditor-EFUVACVN.mjs.map
|
|
442
|
+
//# sourceMappingURL=FlowchartEditor-EFUVACVN.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/editor/plugins/builtin/flowchart/flowchartStyle.ts","../src/editor/plugins/builtin/flowchart/useFlowchartGraph.ts","../src/editor/plugins/builtin/flowchart/flowchartTextEditor.tsx","../src/editor/plugins/builtin/flowchart/FlowchartEditor.tsx"],"names":["text","useRef","useEffect","useState","useCallback","jsx","Radio"],"mappings":";;;;;;;;;;;;;;;;AAIA,IAAM,cAAA,GAAiB,8BAAA,CAA+B,EAAE,WAAA,EAAa,MAAM,CAAA;AAG3E,IAAM,0BAA0B,YAAA,CAAa,CAAC,EAAE,GAAA,EAAK,OAAM,MAAO;AAAA,EAChE,IAAA,EAAM,GAAA;AAAA;AAAA;AAAA,EAAA,CAAA;AAAA;AAAA,EAKN,OAAA,EAAS,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAA,EAOmB,MAAM,oBAAoB,CAAA;AAAA,gBAAA,EACtC,MAAM,gBAA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Content":["import { createStyles } from '../../../ui';\r\nimport { createGraphicEditorShellStyles } from '../shared/graphicblock';\r\n\r\n/** 共享壳样式:工具行允许换行(toolbar/spacer 直接复用,canvas 用作 canvasWrap) */\r\nconst useShellStyles = createGraphicEditorShellStyles({ toolbarWrap: true });\r\n\r\n/** FlowchartEditor 本地样式:左侧块面板 + 主区布局 + 画布 + 内联文本编辑框 */\r\nconst useFlowchartLocalStyles = createStyles(({ css, token }) => ({\r\n root: css`\r\n display: flex;\r\n height: 100%;\r\n `,\r\n /** 左侧块面板 */\r\n stencil: css`\r\n width: 148px;\r\n flex-shrink: 0;\r\n display: flex;\r\n flex-direction: column;\r\n padding: 10px;\r\n gap: 10px;\r\n border-right: 1px solid ${token.colorBorderSecondary};\r\n background: ${token.colorBgContainer};\r\n overflow-y: auto;\r\n `,\r\n stencilNode: css`\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n gap: 6px;\r\n height: 40px;\r\n padding: 0 8px;\r\n border: 1px solid ${token.colorBorder};\r\n border-radius: ${token.borderRadius}px;\r\n background: ${token.colorBgElevated};\r\n color: ${token.colorText};\r\n font-size: 13px;\r\n cursor: grab;\r\n user-select: none;\r\n transition: all 0.2s;\r\n\r\n &:hover {\r\n border-color: ${token.colorPrimary};\r\n color: ${token.colorPrimary};\r\n }\r\n\r\n img {\r\n width: 16px;\r\n height: 16px;\r\n }\r\n `,\r\n stencilTitle: css`\r\n font-size: 12px;\r\n font-weight: 500;\r\n color: ${token.colorTextSecondary};\r\n margin-top: 4px;\r\n `,\r\n main: css`\r\n flex: 1;\r\n min-width: 0;\r\n display: flex;\r\n flex-direction: column;\r\n `,\r\n canvas: css`\r\n width: 100%;\r\n height: 100%;\r\n `,\r\n /** 内联文本编辑框:双击 cell 时绝对定位覆盖在其屏幕位置 */\r\n textEditor: css`\r\n position: absolute;\r\n z-index: 10;\r\n box-sizing: border-box;\r\n padding: 2px 4px;\r\n border: 1px solid ${token.colorPrimary};\r\n border-radius: ${token.borderRadiusXS}px;\r\n background: ${token.colorBgElevated};\r\n color: ${token.colorText};\r\n font-size: 13px;\r\n line-height: 1.4;\r\n text-align: center;\r\n outline: none;\r\n resize: none;\r\n box-shadow: ${token.boxShadowSecondary};\r\n `,\r\n}));\r\n\r\n/** FlowchartEditor 布局样式:本地样式 + 共享壳的 toolbar/spacer/canvasWrap 拼装。 */\r\nexport function useFlowchartEditorStyles() {\r\n const { styles: local } = useFlowchartLocalStyles();\r\n const { styles: shell } = useShellStyles();\r\n return {\r\n styles: {\r\n ...local,\r\n toolbar: shell.toolbar,\r\n spacer: shell.spacer,\r\n canvasWrap: shell.canvas,\r\n },\r\n };\r\n}\r\n","import { useEffect, useRef, type RefObject, type MutableRefObject } from 'react';\r\nimport { Graph, type Cell } from '@antv/x6';\r\nimport { Snapline } from '@antv/x6-plugin-snapline';\r\nimport { Selection } from '@antv/x6-plugin-selection';\r\nimport { Keyboard } from '@antv/x6-plugin-keyboard';\r\nimport { Export } from '@antv/x6-plugin-export';\r\nimport { Dnd } from '@antv/x6-plugin-dnd';\r\nimport { registerFlowShapes, CONNECTING_ROUTER, CONNECTING_CONNECTOR } from './shapes';\r\nimport type { FlowchartData } from './interface';\r\nimport { tr } from '../../../i18n';\r\n\r\n/**\r\n * x6 流程图画布初始化 hook(FlowchartEditor 专用)。\r\n *\r\n * 承载画布创建、插件装配(对齐线/框选/键盘/导出/DnD)、端口悬停显隐、\r\n * 双击进入文本编辑、删除快捷键与初始数据载入。\r\n */\r\ninterface UseFlowchartGraphOptions {\r\n /** 容器是否就绪(懒加载首帧尺寸可能为 0,就绪后再初始化) */\r\n ready: boolean;\r\n containerRef: RefObject<HTMLDivElement | null>;\r\n graphRef: MutableRefObject<Graph | null>;\r\n dndRef: MutableRefObject<Dnd | null>;\r\n /** 初始图数据(x6 toJSON 结构) */\r\n value: FlowchartData | null;\r\n /** 双击节点/边回调(打开内联文本编辑框) */\r\n onCellDblClick: (cell: Cell) => void;\r\n}\r\n\r\n/** 创建 x6 画布并装配插件(对齐线/框选/键盘/导出),返回待装配事件的 Graph 实例 */\r\nfunction createGraph(container: HTMLDivElement, edgeTypeRef: MutableRefObject<string>): Graph {\r\n // 显式标注 Graph 类型:connecting.createEdge 闭包内引用 graph 自身,\r\n // 缺少标注会形成循环类型推断(TS7022/7023)\r\n const graph: Graph = new Graph({\r\n container,\r\n autoResize: true,\r\n // async:false -- 让模型变更同步渲染进实时 SVG DOM,导出快照的 toSVG 克隆这份实时 SVG,\r\n // 同步渲染确保刚拖入 / 更新的节点一定已在 DOM 中、不被漏掉。\r\n async: false,\r\n background: { color: '#fafafa' },\r\n grid: { visible: true, type: 'dot', size: 12, args: { color: '#e0e0e0' } },\r\n panning: true,\r\n mousewheel: { enabled: true, modifiers: ['ctrl', 'meta'] },\r\n connecting: {\r\n router: CONNECTING_ROUTER,\r\n connector: CONNECTING_CONNECTOR,\r\n anchor: 'center',\r\n connectionPoint: 'boundary',\r\n allowBlank: false,\r\n allowLoop: false,\r\n allowNode: false,\r\n snap: { radius: 20 },\r\n // 按当前选中的连线类型创建对应样式的边\r\n createEdge() {\r\n return graph.createEdge({ shape: edgeTypeRef.current });\r\n },\r\n },\r\n highlighting: {\r\n magnetAvailable: {\r\n name: 'stroke',\r\n args: { attrs: { stroke: '#43bbef', 'stroke-width': 2 } },\r\n },\r\n },\r\n });\r\n\r\n graph\r\n .use(new Snapline({ enabled: true }))\r\n .use(new Selection({ enabled: true, showNodeSelectionBox: true, rubberband: true }))\r\n .use(new Keyboard({ enabled: true }))\r\n .use(new Export());\r\n\r\n return graph;\r\n}\r\n\r\n/** 装配画布交互事件:端口悬停显隐、双击进入文本编辑、删除快捷键 */\r\nfunction wireGraphEvents(\r\n graph: Graph,\r\n containerRef: RefObject<HTMLDivElement | null>,\r\n onCellDblClick: (cell: Cell) => void\r\n): void {\r\n // 连接桩默认隐藏(框架 getDefaultPorts 设置 visibility:hidden),悬停节点时显示\r\n const showPorts = (nodeId: string, show: boolean) => {\r\n // CSS.escape 转义 nodeId,防御 id 含引号/括号等字符时选择器解析失配或被注入\r\n const ports = containerRef.current?.querySelectorAll(`[data-cell-id=\"${CSS.escape(nodeId)}\"] .x6-port-body`) as\r\n NodeListOf<SVGElement> | undefined;\r\n ports?.forEach(p => {\r\n p.style.visibility = show ? 'visible' : 'hidden';\r\n });\r\n };\r\n graph.on('node:mouseenter', ({ node }) => showPorts(node.id, true));\r\n graph.on('node:mouseleave', ({ node }) => showPorts(node.id, false));\r\n\r\n // 双击节点/边 → 打开内联文本编辑框\r\n graph.on('cell:dblclick', ({ cell, e }) => {\r\n e.stopPropagation();\r\n onCellDblClick(cell);\r\n });\r\n\r\n // Delete/Backspace 删除选中\r\n graph.bindKey(['delete', 'backspace'], () => {\r\n const cells = graph.getSelectedCells();\r\n if (cells.length) graph.removeCells(cells);\r\n return false;\r\n });\r\n}\r\n\r\n/** 载入初始数据:无数据时预置开始/结束节点(对齐框架 createData),载入失败回退默认节点 */\r\nfunction loadInitialData(graph: Graph, value: FlowchartData | null): void {\r\n // value.cells 来自持久化数据,可能损坏或含未注册 shape;fromJSON 抛错会导致\r\n // 编辑态白屏。用 try/catch 兜底:解析失败时回退到默认开始/结束节点,保证画布可用。\r\n const loadDefaultNodes = () => {\r\n graph.fromJSON({\r\n nodes: [\r\n { shape: '_type_start', x: 300, y: 80, attrs: { text: { text: tr('开始') } } },\r\n { shape: '_type_end', x: 300, y: 320, attrs: { text: { text: tr('结束') } } },\r\n ],\r\n });\r\n };\r\n try {\r\n if (value?.cells?.length) {\r\n graph.fromJSON({ cells: value.cells });\r\n } else {\r\n loadDefaultNodes();\r\n }\r\n } catch (e) {\r\n console.warn('[flowchart] fromJSON 载入失败,回退默认节点:', e);\r\n try {\r\n graph.clearCells();\r\n loadDefaultNodes();\r\n } catch {\r\n /* 默认节点为内置常量,理论不会失败;再失败则留空画布,不阻断渲染 */\r\n }\r\n }\r\n graph.centerContent();\r\n}\r\n\r\nexport function useFlowchartGraph({\r\n ready,\r\n containerRef,\r\n graphRef,\r\n dndRef,\r\n value,\r\n onCellDblClick,\r\n}: UseFlowchartGraphOptions) {\r\n // createEdge 回调里要读最新的连线类型,用 ref 避免闭包捕获旧值\r\n const edgeTypeRef = useRef<string>('approve');\r\n\r\n // 初始化 x6 画布(容器就绪后执行一次):建图 → 装事件 → 载数据 → 挂 DnD\r\n useEffect(() => {\r\n if (!ready || !containerRef.current) return;\r\n\r\n registerFlowShapes();\r\n\r\n const graph = createGraph(containerRef.current, edgeTypeRef);\r\n wireGraphEvents(graph, containerRef, onCellDblClick);\r\n loadInitialData(graph, value);\r\n\r\n graphRef.current = graph;\r\n\r\n // 左侧面板拖拽:节点从面板拖入画布。\r\n // 注意:Dnd 不经 graph.use() 注册,也不会随 graph.dispose() 一并清理,\r\n // 必须在 cleanup 中显式 dispose(见下),否则每次进出编辑态泄漏整个实例。\r\n dndRef.current = new Dnd({\r\n target: graph,\r\n getDragNode: node => node.clone({ keepId: true }),\r\n getDropNode: node => node.clone({ keepId: true }),\r\n });\r\n\r\n return () => {\r\n // 先 dispose dnd 再 dispose graph(dnd 内部仍引用 graph,顺序不可颠倒),\r\n // 不 dispose 会随每次进出编辑态泄漏一个完整 X6 Graph 与 body 残留 DOM\r\n dndRef.current?.dispose();\r\n dndRef.current = null;\r\n graph.dispose();\r\n graphRef.current = null;\r\n };\r\n // 容器就绪后初始化一次:value 作为初始快照,后续更新通过重挂载 NodeView 完成;\r\n // onCellDblClick 为稳定 useCallback 引用,有意不进依赖。\r\n // (exhaustive-deps 在本项目 eslint 配置中未启用,无需行内 disable)\r\n }, [ready]);\r\n\r\n return { edgeTypeRef };\r\n}\r\n","import { useEffect, useRef, useState, useCallback } from 'react';\r\nimport type { Cell } from '@antv/x6';\r\nimport type { FlowchartTextEditorOverlayProps, TextEditorState, UseFlowchartTextEditorOptions } from './interface';\r\n\r\n/**\r\n * 流程图内联文本编辑(FlowchartEditor 专用)。\r\n *\r\n * 双击节点/边后在其 bbox 位置浮出 textarea,Enter 提交(Shift+Enter 换行)、\r\n * Esc 取消、失焦提交。hook 承载状态与读写逻辑,Overlay 组件承载浮层渲染。\r\n */\r\n\r\n/** 读取 cell 当前文本(节点在 text/text,边在 labels[0]) */\r\nfunction getCellText(cell: Cell): string {\r\n if (cell.isNode()) {\r\n const text = cell.attr('text/text');\r\n return typeof text === 'string' ? text : '';\r\n }\r\n const labels = cell.isEdge() ? cell.getLabels() : [];\r\n const first = labels[0] as { attrs?: { label?: { text?: unknown } } } | undefined;\r\n const text = first?.attrs?.label?.text;\r\n return typeof text === 'string' ? text : '';\r\n}\r\n\r\nexport function useFlowchartTextEditor({ graphRef, wrapRef }: UseFlowchartTextEditorOptions) {\r\n // 内联文本编辑框状态(null 表示未在编辑)\r\n const [textEditor, setTextEditor] = useState<TextEditorState | null>(null);\r\n const textareaRef = useRef<HTMLTextAreaElement>(null);\r\n\r\n // 打开某个 cell 的内联文本编辑框:把 cell 的图坐标 bbox 转成相对 wrap 的屏幕像素\r\n const openTextEditor = useCallback(\r\n (cell: Cell) => {\r\n const graph = graphRef.current;\r\n const wrap = wrapRef.current;\r\n if (!graph || !wrap) return;\r\n const bbox = cell.getBBox();\r\n // 图局部坐标 → 客户端坐标,再减去 wrap 的客户端偏移得到相对定位\r\n const topLeft = graph.localToClient(bbox.x, bbox.y);\r\n const bottomRight = graph.localToClient(bbox.x + bbox.width, bbox.y + bbox.height);\r\n const wrapRect = wrap.getBoundingClientRect();\r\n setTextEditor({\r\n cellId: cell.id,\r\n left: topLeft.x - wrapRect.left,\r\n top: topLeft.y - wrapRect.top,\r\n width: Math.max(bottomRight.x - topLeft.x, 40),\r\n height: Math.max(bottomRight.y - topLeft.y, 24),\r\n value: getCellText(cell),\r\n });\r\n },\r\n [graphRef, wrapRef]\r\n );\r\n\r\n // 文本编辑框出现后自动聚焦并全选。\r\n // 依赖收窄到 cellId:若依赖整个 textEditor 对象,每次输入 onChange 产生新引用\r\n // 都会重新 focus()+select() 全选,导致下一键覆盖全部内容、无法连续输入。\r\n useEffect(() => {\r\n if (textEditor && textareaRef.current) {\r\n textareaRef.current.focus();\r\n textareaRef.current.select();\r\n }\r\n }, [textEditor?.cellId]);\r\n\r\n // 提交内联文本编辑:写回目标 cell。\r\n // 副作用(cell.attr/setLabels)在 setState updater 外执行、updater 保持纯函数,\r\n // StrictMode 双调 updater 时不会重复写回;当前值直接读 state(非闭包旧值)。\r\n const commitTextEditor = useCallback(() => {\r\n const graph = graphRef.current;\r\n const current = textEditor;\r\n setTextEditor(null);\r\n if (!current || !graph) return;\r\n const cell = graph.getCellById(current.cellId);\r\n if (cell) {\r\n const text = current.value;\r\n if (cell.isNode()) {\r\n cell.attr('text/text', text);\r\n } else if (cell.isEdge()) {\r\n cell.setLabels(text ? [{ attrs: { label: { text } } }] : []);\r\n }\r\n }\r\n }, [graphRef, textEditor]);\r\n\r\n const cancelTextEditor = useCallback(() => setTextEditor(null), []);\r\n\r\n return { textEditor, setTextEditor, textareaRef, openTextEditor, commitTextEditor, cancelTextEditor };\r\n}\r\n\r\n/** 内联文本编辑 textarea 浮层(渲染在 canvasWrap 内,绝对定位到目标 cell 上方) */\r\nexport function FlowchartTextEditorOverlay({\r\n state,\r\n textareaRef,\r\n className,\r\n onChange,\r\n onCommit,\r\n onCancel,\r\n}: FlowchartTextEditorOverlayProps) {\r\n if (!state) return null;\r\n return (\r\n <textarea\r\n ref={textareaRef}\r\n className={className}\r\n style={{\r\n left: state.left,\r\n top: state.top,\r\n width: state.width,\r\n height: state.height,\r\n }}\r\n value={state.value}\r\n onChange={e => onChange(e.target.value)}\r\n onBlur={onCommit}\r\n onKeyDown={e => {\r\n // Enter 提交(Shift+Enter 换行),Esc 取消\r\n if (e.key === 'Enter' && !e.shiftKey) {\r\n e.preventDefault();\r\n onCommit();\r\n } else if (e.key === 'Escape') {\r\n e.preventDefault();\r\n onCancel();\r\n }\r\n }}\r\n />\r\n );\r\n}\r\n","import { useRef, useCallback, useState } from 'react';\r\nimport type { Graph } from '@antv/x6';\r\nimport type { Dnd } from '@antv/x6-plugin-dnd';\r\nimport { Button, Space, Tooltip, AntdRadio } from '../../../ui';\r\nimport { DeleteOutlined, ZoomInOutlined, ZoomOutOutlined, CompressOutlined } from '@ant-design/icons';\r\nimport { useContainerReady } from '../shared/useContainerReady';\r\nimport { EditorActionBar, finalizeSvgRoot } from '../shared/graphicblock';\r\nimport { useIsMounted } from '../shared/useIsMounted';\r\nimport { STENCIL_NODES, EDGE_TYPES } from './shapes';\r\nimport { useFlowchartEditorStyles } from './flowchartStyle';\r\nimport { useFlowchartGraph } from './useFlowchartGraph';\r\nimport { useFlowchartTextEditor, FlowchartTextEditorOverlay } from './flowchartTextEditor';\r\nimport type { FlowchartData, FlowchartEditorProps } from './interface';\r\nimport { tr } from '../../../i18n';\r\n\r\n/**\r\n * 处理 x6 导出的裸 SVG 字符串:解析校验后走共享后处理 finalizeSvgRoot——\r\n * 1. 剥离仅用于编辑交互的元素--连接桩(.x6-port*)与单元工具(.x6-cell-tool*),\r\n * 导出后直接物理删除(净化阶段不放行 visibility,端口会在预览态显现);\r\n * 2. 读取 SVG 根元素的 width/height 作为内容自然尺寸,供预览态约束块尺寸。\r\n *\r\n * x6 导出插件已为根 SVG 设置自洽的 viewBox 与 width/height,无需手算坐标;\r\n * forceAspectRatio=true:无条件补 preserveAspectRatio(预览等比居中)。\r\n */\r\nfunction processExportedSvg(raw: string): { svg: string; width: number; height: number } {\r\n const empty = { svg: '', width: 0, height: 0 };\r\n if (!raw) return empty;\r\n const doc = new DOMParser().parseFromString(raw, 'image/svg+xml');\r\n if (doc.querySelector('parsererror') || doc.documentElement.tagName.toLowerCase() !== 'svg') {\r\n return empty;\r\n }\r\n // 剥离连接桩与单元工具(vertices / arrowhead 等),只保留节点与连线本体\r\n return finalizeSvgRoot(doc.documentElement, {\r\n stripSelectors: ['.x6-port', '.x6-port-body', '.x6-cell-tool', '.x6-cell-tools'],\r\n forceAspectRatio: true,\r\n });\r\n}\r\n\r\n/**\r\n * x6 流程图可编辑画布,对齐框架工作流设计器(procomponents/business/flow)。\r\n *\r\n * 左侧块面板拖拽节点、画布连线(三种业务连线)、缩放、删除、导出 SVG 快照。\r\n * 复用框架节点 / 连线定义,保证视觉一致;不套用工作流业务校验。\r\n * 画布初始化在 useFlowchartGraph,内联文本编辑在 FlowchartTextEditor。\r\n */\r\nexport default function FlowchartEditor({ value, onSave, onCancel }: FlowchartEditorProps) {\r\n const { styles } = useFlowchartEditorStyles();\r\n const wrapRef = useRef<HTMLDivElement>(null);\r\n const containerRef = useRef<HTMLDivElement>(null);\r\n const graphRef = useRef<Graph | null>(null);\r\n const dndRef = useRef<Dnd | null>(null);\r\n const [edgeType, setEdgeType] = useState<string>('approve');\r\n // 组件是否仍挂载:保存时导出 SVG 为异步,用户在导出期间点「取消」会卸载本组件,\r\n // 此时不应再把已取消的修改经 onSave 写回文档(与 mindmap/whiteboard 编辑器一致)。\r\n const mountedRef = useIsMounted();\r\n // 懒加载首帧容器尺寸可能为 0,等容器就绪再初始化 x6,避免画布尺寸异常\r\n const ready = useContainerReady(containerRef);\r\n\r\n // 内联文本编辑(双击节点/边触发)\r\n const { textEditor, setTextEditor, textareaRef, openTextEditor, commitTextEditor, cancelTextEditor } =\r\n useFlowchartTextEditor({ graphRef, wrapRef });\r\n\r\n // x6 画布初始化(容器就绪后执行一次)\r\n const { edgeTypeRef } = useFlowchartGraph({\r\n ready,\r\n containerRef,\r\n graphRef,\r\n dndRef,\r\n value,\r\n onCellDblClick: openTextEditor,\r\n });\r\n\r\n // 从左侧面板开始拖拽:创建对应 shape 的节点交给 dnd\r\n const handleStencilMouseDown = useCallback((shape: string, label: string, e: React.MouseEvent<HTMLDivElement>) => {\r\n const graph = graphRef.current;\r\n const dnd = dndRef.current;\r\n if (!graph || !dnd) return;\r\n const node = graph.createNode({ shape, attrs: { text: { text: tr(label) } } });\r\n dnd.start(node, e.nativeEvent);\r\n }, []);\r\n\r\n const handleEdgeTypeChange = useCallback(\r\n (next: string) => {\r\n edgeTypeRef.current = next;\r\n setEdgeType(next);\r\n },\r\n [edgeTypeRef]\r\n );\r\n\r\n const handleDelete = useCallback(() => {\r\n const graph = graphRef.current;\r\n if (!graph) return;\r\n const cells = graph.getSelectedCells();\r\n if (cells.length) graph.removeCells(cells);\r\n }, []);\r\n\r\n const handleZoom = useCallback((factor: number) => {\r\n graphRef.current?.zoom(factor);\r\n }, []);\r\n\r\n const handleFit = useCallback(() => {\r\n graphRef.current?.zoomToFit({ padding: 24, maxScale: 1 });\r\n }, []);\r\n\r\n const handleSave = useCallback(async () => {\r\n const graph = graphRef.current;\r\n if (!graph) return;\r\n // 导出前清掉选中态:选中框、边工具(vertices/arrowhead)等都是交互元素,\r\n // 不应进入快照。连接桩另在 processExportedSvg 里物理剥离。\r\n graph.cleanSelection();\r\n\r\n // 导出前把视口(viewport)的平移/缩放复位为 identity:\r\n // x6 的 pan/zoom 变换加在 x6-graph-svg-viewport 上,导出插件 toSVG 只移除了\r\n // x6-graph-svg-stage 的 transform、保留了 viewport 变换;而下方 viewBox 取的是\r\n // getContentArea() 的「本地坐标」。复位 viewport 让内容回到本地坐标系、与 viewBox 对齐,\r\n // 全部节点才能完整导出(matrix 是同步 DOM 写入;保存后编辑器即卸载,视口复位对用户不可见)。\r\n graph.matrix({ a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 });\r\n\r\n const data = graph.toJSON() as FlowchartData;\r\n let result = { svg: '', width: 0, height: 0 };\r\n try {\r\n // viewBox 用 getContentArea():返回「本地坐标系」下所有 cell 的真实包围盒,\r\n // 与画布 pan/zoom 无关。preserveDimensions 让根 SVG 带上与 viewBox 一致的\r\n // width/height,processExportedSvg 据此读出内容自然尺寸。\r\n const raw = await new Promise<string>(resolve => {\r\n graph.toSVG((svgString: string) => resolve(svgString), {\r\n copyStyles: false,\r\n preserveDimensions: true,\r\n // 内容包围盒四周留白,避免贴边节点描边被裁\r\n viewBox: (() => {\r\n const box = graph.getContentArea();\r\n const PAD = 16;\r\n return {\r\n x: box.x - PAD,\r\n y: box.y - PAD,\r\n width: box.width + PAD * 2,\r\n height: box.height + PAD * 2,\r\n };\r\n })(),\r\n });\r\n });\r\n result = processExportedSvg(raw);\r\n } catch {\r\n result = { svg: '', width: 0, height: 0 };\r\n }\r\n // 导出为异步,其间可能已被取消卸载;写回前确认仍挂载,避免把取消的修改落库。\r\n if (!mountedRef.current) return;\r\n onSave({ data, ...result });\r\n }, [onSave]);\r\n\r\n return (\r\n <div className={styles.root}>\r\n {/* 左侧块面板 */}\r\n <div className={styles.stencil}>\r\n {STENCIL_NODES.map(n => (\r\n <div\r\n key={n.shape}\r\n className={styles.stencilNode}\r\n onMouseDown={e => handleStencilMouseDown(n.shape, n.label, e)}>\r\n <img src={n.icon} alt=\"\" />\r\n <span>{tr(n.label)}</span>\r\n </div>\r\n ))}\r\n <div className={styles.stencilTitle}>{tr('操作类型')}</div>\r\n <AntdRadio.Group value={edgeType} onChange={e => handleEdgeTypeChange(e.target.value)}>\r\n <Space direction=\"vertical\" size={4}>\r\n {EDGE_TYPES.map(t => (\r\n <AntdRadio key={t.value} value={t.value}>\r\n {tr(t.label)}\r\n </AntdRadio>\r\n ))}\r\n </Space>\r\n </AntdRadio.Group>\r\n </div>\r\n\r\n {/* 右侧:工具栏 + 画布 */}\r\n <div className={styles.main}>\r\n <div className={styles.toolbar}>\r\n <Tooltip title={tr('删除选中')}>\r\n <Button size=\"small\" icon={<DeleteOutlined />} onClick={handleDelete} />\r\n </Tooltip>\r\n <Tooltip title={tr('放大')}>\r\n <Button size=\"small\" icon={<ZoomInOutlined />} onClick={() => handleZoom(0.1)} />\r\n </Tooltip>\r\n <Tooltip title={tr('缩小')}>\r\n <Button size=\"small\" icon={<ZoomOutOutlined />} onClick={() => handleZoom(-0.1)} />\r\n </Tooltip>\r\n <Tooltip title={tr('适应画布')}>\r\n <Button size=\"small\" icon={<CompressOutlined />} onClick={handleFit} />\r\n </Tooltip>\r\n <span className={styles.spacer} />\r\n <EditorActionBar onCancel={onCancel} onSave={handleSave} />\r\n </div>\r\n <div className={styles.canvasWrap} ref={wrapRef}>\r\n <div ref={containerRef} className={styles.canvas} />\r\n <FlowchartTextEditorOverlay\r\n state={textEditor}\r\n textareaRef={textareaRef}\r\n className={styles.textEditor}\r\n onChange={next => setTextEditor(current => (current ? { ...current, value: next } : current))}\r\n onCommit={commitTextEditor}\r\n onCancel={cancelTextEditor}\r\n />\r\n </div>\r\n </div>\r\n </div>\r\n );\r\n}\r\n"]}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { useContainerReady, useIsMounted } from './chunk-7AAZUM6M.mjs';
|
|
2
|
+
import { THEME_CONFIG, DEFAULT_DATA } from './chunk-PFA3XERW.mjs';
|
|
3
|
+
import { createGraphicEditorShellStyles, createStyles, Space, Tooltip, Button, EditorActionBar, finalizeSvgRoot } from './chunk-ZM3WULHX.mjs';
|
|
4
|
+
import { decodeSvgDataUri } from './chunk-4W6PPBHQ.mjs';
|
|
5
|
+
import { tr } from './chunk-W627LLF4.mjs';
|
|
6
|
+
import { useRef, useState, useEffect, useCallback } from 'react';
|
|
7
|
+
import MindMap from 'simple-mind-map';
|
|
8
|
+
import Export from 'simple-mind-map/src/plugins/Export.js';
|
|
9
|
+
import 'simple-mind-map/dist/simpleMindMap.esm.css';
|
|
10
|
+
import { PlusOutlined, NodeExpandOutlined, DeleteOutlined } from '@ant-design/icons';
|
|
11
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
12
|
+
|
|
13
|
+
// src/editor/plugins/builtin/mindmap/mindmapStyle.ts
|
|
14
|
+
var useShellStyles = createGraphicEditorShellStyles({ toolbarWrap: true });
|
|
15
|
+
var useCanvasOverrides = createStyles(({ css }) => ({
|
|
16
|
+
canvas: css`
|
|
17
|
+
* {
|
|
18
|
+
box-sizing: content-box;
|
|
19
|
+
}
|
|
20
|
+
`
|
|
21
|
+
}));
|
|
22
|
+
function useMindmapStyles() {
|
|
23
|
+
const { styles: shell, cx } = useShellStyles();
|
|
24
|
+
const { styles: overrides } = useCanvasOverrides();
|
|
25
|
+
return {
|
|
26
|
+
styles: {
|
|
27
|
+
...shell,
|
|
28
|
+
canvas: cx(shell.canvas, overrides.canvas)
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
MindMap.usePlugin(Export);
|
|
33
|
+
function processExportedSvg(dataUrl) {
|
|
34
|
+
const empty = { svg: "", width: 0, height: 0 };
|
|
35
|
+
const raw = decodeSvgDataUri(dataUrl);
|
|
36
|
+
if (!raw) return empty;
|
|
37
|
+
const doc = new DOMParser().parseFromString(raw, "image/svg+xml");
|
|
38
|
+
if (doc.querySelector("parsererror") || doc.documentElement.tagName.toLowerCase() !== "svg") {
|
|
39
|
+
return empty;
|
|
40
|
+
}
|
|
41
|
+
return finalizeSvgRoot(doc.documentElement, { stripSelectors: [".smm-hover-node"] });
|
|
42
|
+
}
|
|
43
|
+
function MindmapEditor({ value, onSave, onCancel }) {
|
|
44
|
+
const { styles } = useMindmapStyles();
|
|
45
|
+
const containerRef = useRef(null);
|
|
46
|
+
const mindMapRef = useRef(null);
|
|
47
|
+
const [activeNode, setActiveNode] = useState(null);
|
|
48
|
+
const ready = useContainerReady(containerRef);
|
|
49
|
+
const mountedRef = useIsMounted();
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (!ready || !containerRef.current) return;
|
|
52
|
+
const mindMap = new MindMap({
|
|
53
|
+
el: containerRef.current,
|
|
54
|
+
data: value && value.data ? value : DEFAULT_DATA,
|
|
55
|
+
layout: "logicalStructure",
|
|
56
|
+
themeConfig: THEME_CONFIG,
|
|
57
|
+
// 允许双击/回车编辑节点文本(默认开启,显式声明便于阅读)
|
|
58
|
+
enableFreeDrag: false
|
|
59
|
+
});
|
|
60
|
+
mindMapRef.current = mindMap;
|
|
61
|
+
const handleActive = (_node, activeNodeList) => {
|
|
62
|
+
const current = activeNodeList[activeNodeList.length - 1];
|
|
63
|
+
setActiveNode(current ? { isRoot: current.layerIndex === 0 } : null);
|
|
64
|
+
};
|
|
65
|
+
mindMap.on("node_active", handleActive);
|
|
66
|
+
const activateRoot = () => {
|
|
67
|
+
const { root } = mindMap.renderer;
|
|
68
|
+
root?.active?.();
|
|
69
|
+
mindMap.off("node_tree_render_end", activateRoot);
|
|
70
|
+
};
|
|
71
|
+
mindMap.on("node_tree_render_end", activateRoot);
|
|
72
|
+
return () => {
|
|
73
|
+
mindMap.off("node_active", handleActive);
|
|
74
|
+
mindMap.off("node_tree_render_end", activateRoot);
|
|
75
|
+
mindMap.destroy();
|
|
76
|
+
mindMapRef.current = null;
|
|
77
|
+
setActiveNode(null);
|
|
78
|
+
};
|
|
79
|
+
}, [ready]);
|
|
80
|
+
const handleInsertChild = useCallback(() => {
|
|
81
|
+
mindMapRef.current?.execCommand("INSERT_CHILD_NODE", false);
|
|
82
|
+
}, []);
|
|
83
|
+
const handleInsertSibling = useCallback(() => {
|
|
84
|
+
mindMapRef.current?.execCommand("INSERT_NODE", false);
|
|
85
|
+
}, []);
|
|
86
|
+
const handleRemove = useCallback(() => {
|
|
87
|
+
mindMapRef.current?.execCommand("REMOVE_NODE");
|
|
88
|
+
setActiveNode(null);
|
|
89
|
+
}, []);
|
|
90
|
+
const handleSave = useCallback(async () => {
|
|
91
|
+
const mindMap = mindMapRef.current;
|
|
92
|
+
if (!mindMap) return;
|
|
93
|
+
const data = mindMap.getData(false);
|
|
94
|
+
let result = { svg: "", width: 0, height: 0 };
|
|
95
|
+
try {
|
|
96
|
+
const dataUrl = await mindMap.export("svg", false, "mindmap");
|
|
97
|
+
result = processExportedSvg(dataUrl);
|
|
98
|
+
} catch {
|
|
99
|
+
result = { svg: "", width: 0, height: 0 };
|
|
100
|
+
}
|
|
101
|
+
if (!mountedRef.current) return;
|
|
102
|
+
onSave({ data, ...result });
|
|
103
|
+
}, [onSave]);
|
|
104
|
+
const noActive = activeNode === null;
|
|
105
|
+
const isRootActive = activeNode?.isRoot ?? false;
|
|
106
|
+
return /* @__PURE__ */ jsxs("div", { className: styles.root, children: [
|
|
107
|
+
/* @__PURE__ */ jsxs("div", { className: styles.toolbar, children: [
|
|
108
|
+
/* @__PURE__ */ jsxs(Space, { size: 4, children: [
|
|
109
|
+
/* @__PURE__ */ jsx(Tooltip, { title: noActive ? tr("\u5148\u9009\u4E2D\u4E00\u4E2A\u8282\u70B9") : tr("\u4E3A\u9009\u4E2D\u8282\u70B9\u6DFB\u52A0\u5B50\u8282\u70B9"), children: /* @__PURE__ */ jsx(Button, { size: "small", icon: /* @__PURE__ */ jsx(PlusOutlined, {}), disabled: noActive, onClick: handleInsertChild, children: tr("\u5B50\u8282\u70B9") }) }),
|
|
110
|
+
/* @__PURE__ */ jsx(Tooltip, { title: noActive ? tr("\u5148\u9009\u4E2D\u4E00\u4E2A\u8282\u70B9") : tr("\u4E3A\u9009\u4E2D\u8282\u70B9\u6DFB\u52A0\u540C\u7EA7\u8282\u70B9"), children: /* @__PURE__ */ jsx(
|
|
111
|
+
Button,
|
|
112
|
+
{
|
|
113
|
+
size: "small",
|
|
114
|
+
icon: /* @__PURE__ */ jsx(NodeExpandOutlined, {}),
|
|
115
|
+
disabled: noActive || isRootActive,
|
|
116
|
+
onClick: handleInsertSibling,
|
|
117
|
+
children: tr("\u540C\u7EA7\u8282\u70B9")
|
|
118
|
+
}
|
|
119
|
+
) }),
|
|
120
|
+
/* @__PURE__ */ jsx(Tooltip, { title: noActive ? tr("\u5148\u9009\u4E2D\u4E00\u4E2A\u8282\u70B9") : tr("\u5220\u9664\u9009\u4E2D\u8282\u70B9"), children: /* @__PURE__ */ jsx(
|
|
121
|
+
Button,
|
|
122
|
+
{
|
|
123
|
+
size: "small",
|
|
124
|
+
icon: /* @__PURE__ */ jsx(DeleteOutlined, {}),
|
|
125
|
+
danger: true,
|
|
126
|
+
disabled: noActive || isRootActive,
|
|
127
|
+
onClick: handleRemove,
|
|
128
|
+
children: tr("\u5220\u9664\u8282\u70B9")
|
|
129
|
+
}
|
|
130
|
+
) })
|
|
131
|
+
] }),
|
|
132
|
+
/* @__PURE__ */ jsx("span", { className: styles.spacer }),
|
|
133
|
+
/* @__PURE__ */ jsx(EditorActionBar, { onCancel, onSave: handleSave })
|
|
134
|
+
] }),
|
|
135
|
+
/* @__PURE__ */ jsx("div", { ref: containerRef, className: styles.canvas })
|
|
136
|
+
] });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export { MindmapEditor as default };
|
|
140
|
+
//# sourceMappingURL=MindmapEditor-CCJRPI4I.mjs.map
|
|
141
|
+
//# sourceMappingURL=MindmapEditor-CCJRPI4I.mjs.map
|