silkio-flowchart 0.0.0-stage → 0.1.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 +15 -0
- package/README.md +38 -3
- package/dist/FlowEdge.d.ts +45 -0
- package/dist/FlowEdge.js +390 -0
- package/dist/Shape.d.ts +48 -0
- package/dist/Shape.js +118 -0
- package/dist/ai-protocol.d.ts +146 -0
- package/dist/ai-protocol.js +578 -0
- package/dist/ai-report.d.ts +3 -0
- package/dist/ai-report.js +83 -0
- package/dist/ai.d.ts +6 -0
- package/dist/ai.js +7 -0
- package/dist/auto-layout.d.ts +15 -0
- package/dist/auto-layout.js +248 -0
- package/dist/commands.d.ts +106 -0
- package/dist/commands.js +264 -0
- package/dist/data.d.ts +24 -0
- package/dist/data.js +1 -0
- package/dist/edge-router.d.ts +24 -0
- package/dist/edge-router.js +22 -0
- package/dist/editing.d.ts +32 -0
- package/dist/editing.js +148 -0
- package/dist/flow-layout-capability.d.ts +7 -0
- package/dist/flow-layout-capability.js +2 -0
- package/dist/flowchart.d.ts +115 -0
- package/dist/flowchart.js +1425 -0
- package/dist/geometry.d.ts +98 -0
- package/dist/geometry.js +310 -0
- package/dist/history-codec.d.ts +47 -0
- package/dist/history-codec.js +410 -0
- package/dist/hover.d.ts +22 -0
- package/dist/hover.js +96 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +18 -0
- package/dist/interactions.d.ts +51 -0
- package/dist/interactions.js +636 -0
- package/dist/model.d.ts +58 -0
- package/dist/model.js +233 -0
- package/dist/overlay.d.ts +60 -0
- package/dist/overlay.js +242 -0
- package/dist/quick-create.d.ts +12 -0
- package/dist/quick-create.js +29 -0
- package/dist/selection.d.ts +8 -0
- package/dist/selection.js +31 -0
- package/dist/session.d.ts +68 -0
- package/dist/session.js +4 -0
- package/dist/shape-registry.d.ts +17 -0
- package/dist/shape-registry.js +36 -0
- package/dist/shapes.d.ts +56 -0
- package/dist/shapes.js +291 -0
- package/dist/snap-capability.d.ts +23 -0
- package/dist/snap-capability.js +32 -0
- package/dist/snap.d.ts +34 -0
- package/dist/snap.js +370 -0
- package/package.json +32 -3
|
@@ -0,0 +1,578 @@
|
|
|
1
|
+
import { dominantPortDir, placeNodeInDirection } from "./geometry";
|
|
2
|
+
// createNode 操作允许的四个相对方向(与端口手柄方向一一对应)
|
|
3
|
+
const PORT_DIRS = ["top", "right", "bottom", "left"];
|
|
4
|
+
// ---- 形状推断(纯函数,导出便于测试)----
|
|
5
|
+
const BUILTIN_SHAPES = [
|
|
6
|
+
"rect",
|
|
7
|
+
"diamond",
|
|
8
|
+
"ellipse",
|
|
9
|
+
"parallelogram",
|
|
10
|
+
"hexagon",
|
|
11
|
+
"database",
|
|
12
|
+
];
|
|
13
|
+
const ROLE_SHAPE = {
|
|
14
|
+
start: "ellipse",
|
|
15
|
+
end: "ellipse",
|
|
16
|
+
decision: "diamond",
|
|
17
|
+
io: "parallelogram",
|
|
18
|
+
process: "rect",
|
|
19
|
+
data: "database",
|
|
20
|
+
note: "rect",
|
|
21
|
+
};
|
|
22
|
+
// 形状兜底:合法内置 kind 优先,其次 role,最后按文本语义推断。
|
|
23
|
+
// 模型即使完全省略 shape 也能得到符合流程图惯例的形状。
|
|
24
|
+
export function inferFlowShape(node) {
|
|
25
|
+
const shape = typeof node.shape === "string" ? node.shape.toLowerCase() : "";
|
|
26
|
+
if (BUILTIN_SHAPES.includes(shape)) {
|
|
27
|
+
return shape;
|
|
28
|
+
}
|
|
29
|
+
if (typeof node.role === "string" && node.role in ROLE_SHAPE) {
|
|
30
|
+
return ROLE_SHAPE[node.role];
|
|
31
|
+
}
|
|
32
|
+
const t = node.text.trim();
|
|
33
|
+
if (/^(开始|结束|起点|终点|start|end)$/i.test(t))
|
|
34
|
+
return "ellipse";
|
|
35
|
+
if (/[??]|是否|判断|校验|检查|通过|满足条件/.test(t))
|
|
36
|
+
return "diamond";
|
|
37
|
+
if (/输入|输出|读取|打印|录入|导出|上报/.test(t))
|
|
38
|
+
return "parallelogram";
|
|
39
|
+
if (/数据库|存储|数据表|\bdb\b/i.test(t))
|
|
40
|
+
return "database";
|
|
41
|
+
return "rect";
|
|
42
|
+
}
|
|
43
|
+
// 当前画布 → 语义图:剥掉坐标与尺寸(x/y/width/height),但保留每条边当前
|
|
44
|
+
// 实际的出入端口方向(fromDir/toDir)——模型改图时据此原样带回未变更边的
|
|
45
|
+
// 走向,只有需要改走向的边才调整方向,避免整图重绘把连线接错侧。
|
|
46
|
+
// 供提示词上下文与「在现有图上修改」使用。
|
|
47
|
+
export function toSemanticGraph(data) {
|
|
48
|
+
return {
|
|
49
|
+
nodes: data.nodes.map((n) => ({
|
|
50
|
+
id: n.id,
|
|
51
|
+
shape: n.shape,
|
|
52
|
+
text: n.text,
|
|
53
|
+
})),
|
|
54
|
+
edges: data.edges.map((e) => ({
|
|
55
|
+
from: e.from,
|
|
56
|
+
to: e.to,
|
|
57
|
+
...(e.text ? { text: e.text } : {}),
|
|
58
|
+
...(e.fromDir ? { fromDir: e.fromDir } : {}),
|
|
59
|
+
...(e.toDir ? { toDir: e.toDir } : {}),
|
|
60
|
+
})),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// 几何保留合并:把布局器算出的绝对数据(laid)与当前画布数据(current)按 id
|
|
64
|
+
// 对位——已有节点沿用当前坐标/尺寸/端口方向,仅套用形状与文字变更(效果等同
|
|
65
|
+
// 工具条 replaceSelected 的「原地改形状」);新增节点复用端口手柄快速创建的同一
|
|
66
|
+
// 份几何 placeNodeInDirection:由布局里的相对方位推断手柄方向,沿该方向在相邻
|
|
67
|
+
// 已落位节点外侧以 CLICK_CREATE_GAP 落位(「在 a 下面加节点」= 点击 a 下方手柄),
|
|
68
|
+
// 链式新增依次沿前序新节点继续落位。多父/孤立/会重叠等复杂拓扑退回锚点平移
|
|
69
|
+
// (相邻共有节点位移均值,无则全局均值)。新增连线保留语义边显式给出的
|
|
70
|
+
// 端口方向(没有则由 FlowEdge 按实际位置自动选边)。用户手动排好的版式
|
|
71
|
+
// 不再被程序分层布局整体打回。
|
|
72
|
+
export function mergeFlowGeometry(current, laid) {
|
|
73
|
+
const geomOf = (n) => ({
|
|
74
|
+
x: n.x,
|
|
75
|
+
y: n.y,
|
|
76
|
+
width: n.width ?? 160,
|
|
77
|
+
height: n.height ?? 99,
|
|
78
|
+
});
|
|
79
|
+
const overlaps = (p, size, other) => p.x < other.x + other.width &&
|
|
80
|
+
p.x + size.width > other.x &&
|
|
81
|
+
p.y < other.y + other.height &&
|
|
82
|
+
p.y + size.height > other.y;
|
|
83
|
+
const curById = new Map();
|
|
84
|
+
for (const n of current.nodes)
|
|
85
|
+
if (n.id)
|
|
86
|
+
curById.set(n.id, n);
|
|
87
|
+
const laidById = new Map();
|
|
88
|
+
for (const n of laid.nodes)
|
|
89
|
+
if (n.id)
|
|
90
|
+
laidById.set(n.id, n);
|
|
91
|
+
// 已落位节点的几何与最终节点数据:初始为所有已有节点(当前几何)
|
|
92
|
+
const placed = new Map();
|
|
93
|
+
const resultById = new Map();
|
|
94
|
+
const deltaById = new Map();
|
|
95
|
+
let sumDx = 0;
|
|
96
|
+
let sumDy = 0;
|
|
97
|
+
for (const n of laid.nodes) {
|
|
98
|
+
if (!n.id)
|
|
99
|
+
continue;
|
|
100
|
+
const cur = curById.get(n.id);
|
|
101
|
+
if (!cur)
|
|
102
|
+
continue;
|
|
103
|
+
const merged = {
|
|
104
|
+
...cur,
|
|
105
|
+
shape: n.shape,
|
|
106
|
+
text: n.text,
|
|
107
|
+
width: cur.width ?? n.width,
|
|
108
|
+
height: cur.height ?? n.height,
|
|
109
|
+
};
|
|
110
|
+
resultById.set(n.id, merged);
|
|
111
|
+
placed.set(n.id, geomOf(merged));
|
|
112
|
+
const delta = { dx: cur.x - n.x, dy: cur.y - n.y };
|
|
113
|
+
deltaById.set(n.id, delta);
|
|
114
|
+
sumDx += delta.dx;
|
|
115
|
+
sumDy += delta.dy;
|
|
116
|
+
}
|
|
117
|
+
const count = deltaById.size;
|
|
118
|
+
const avgDx = count ? sumDx / count : 0;
|
|
119
|
+
const avgDy = count ? sumDy / count : 0;
|
|
120
|
+
// 语义图邻接表(无向):找新增节点的相邻已落位节点
|
|
121
|
+
const neighbors = new Map();
|
|
122
|
+
for (const e of laid.edges) {
|
|
123
|
+
for (const [a, b] of [
|
|
124
|
+
[e.from, e.to],
|
|
125
|
+
[e.to, e.from],
|
|
126
|
+
]) {
|
|
127
|
+
const list = neighbors.get(a) ?? [];
|
|
128
|
+
list.push(b);
|
|
129
|
+
neighbors.set(a, list);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// 兜底锚点:相邻共有节点位移均值;无则全局均值(全新画布为 0)
|
|
133
|
+
const anchorDelta = (id) => {
|
|
134
|
+
const deltas = [];
|
|
135
|
+
for (const nid of neighbors.get(id) ?? []) {
|
|
136
|
+
const d = deltaById.get(nid);
|
|
137
|
+
if (d)
|
|
138
|
+
deltas.push(d);
|
|
139
|
+
}
|
|
140
|
+
if (!deltas.length)
|
|
141
|
+
return { dx: avgDx, dy: avgDy };
|
|
142
|
+
return {
|
|
143
|
+
dx: deltas.reduce((s, d) => s + d.dx, 0) / deltas.length,
|
|
144
|
+
dy: deltas.reduce((s, d) => s + d.dy, 0) / deltas.length,
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
// 逐个落位新增节点:恰好一个已落位邻居时走手柄几何;否则锚点平移
|
|
148
|
+
for (const n of laid.nodes) {
|
|
149
|
+
if (!n.id || resultById.has(n.id))
|
|
150
|
+
continue;
|
|
151
|
+
const geom = geomOf(n);
|
|
152
|
+
const adjacent = (neighbors.get(n.id) ?? []).filter((id) => placed.has(id));
|
|
153
|
+
let pos = null;
|
|
154
|
+
// 全新画布(无任何共有节点)没有「保留既有版式」的前提,整图交给布局器,
|
|
155
|
+
// 不套用手柄间距覆盖布局器的层间距
|
|
156
|
+
if (deltaById.size > 0 && adjacent.length === 1) {
|
|
157
|
+
const src = adjacent[0];
|
|
158
|
+
const srcLaid = laidById.get(src);
|
|
159
|
+
if (srcLaid) {
|
|
160
|
+
const dir = dominantPortDir(geomOf(srcLaid), geom);
|
|
161
|
+
const candidate = placeNodeInDirection(placed.get(src), dir, geom);
|
|
162
|
+
// 与任何已落位节点重叠(多父汇聚/同父多子)时不用手柄几何,退回兜底
|
|
163
|
+
if (![...placed.values()].some((g) => overlaps(candidate, geom, g))) {
|
|
164
|
+
pos = candidate;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (!pos) {
|
|
169
|
+
const { dx, dy } = anchorDelta(n.id);
|
|
170
|
+
pos = { x: n.x + dx, y: n.y + dy };
|
|
171
|
+
}
|
|
172
|
+
const merged = { ...n, x: Math.round(pos.x), y: Math.round(pos.y) };
|
|
173
|
+
resultById.set(n.id, merged);
|
|
174
|
+
placed.set(n.id, geomOf(merged));
|
|
175
|
+
}
|
|
176
|
+
// 连线按「两端 + 标签」建多重集索引:同对节点多条带标签分支边也能区分
|
|
177
|
+
const edgeKey = (e) => `${e.from}\u0000${e.to}\u0000${e.text ?? ""}`;
|
|
178
|
+
const dirByKey = new Map();
|
|
179
|
+
for (const e of current.edges) {
|
|
180
|
+
const list = dirByKey.get(edgeKey(e)) ?? [];
|
|
181
|
+
list.push(e);
|
|
182
|
+
dirByKey.set(edgeKey(e), list);
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
nodes: laid.nodes.map((n) => resultById.get(n.id ?? "") ?? n),
|
|
186
|
+
edges: laid.edges.map((e) => {
|
|
187
|
+
// 既有连线沿用冻结的端口方向;新连线保留语义边显式方向,没有则由
|
|
188
|
+
// FlowEdge 按实际位置选边
|
|
189
|
+
const cur = dirByKey.get(edgeKey(e))?.shift();
|
|
190
|
+
return cur ? { ...e, fromDir: cur.fromDir, toDir: cur.toDir } : e;
|
|
191
|
+
}),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
// ---- 输出规整 ----
|
|
195
|
+
// 校验并规整 LLM 返回的语义图:补齐/去重 id、推断形状、丢弃悬空边、去重重复边。
|
|
196
|
+
// 与 mindmap 的 normalizeAIOps 同策略——脏字段直接抛错(不做部分应用),
|
|
197
|
+
// 但引用不存在的边属于常见模型失误,静默丢弃更符合「能生成就先出图」的体验。
|
|
198
|
+
export function normalizeAIFlowGraph(raw) {
|
|
199
|
+
const data = raw;
|
|
200
|
+
if (!data || !Array.isArray(data.nodes)) {
|
|
201
|
+
throw new Error("AI 返回格式错误:缺少 nodes 数组");
|
|
202
|
+
}
|
|
203
|
+
const used = new Set();
|
|
204
|
+
let seq = 0;
|
|
205
|
+
const nextId = () => {
|
|
206
|
+
let id;
|
|
207
|
+
do {
|
|
208
|
+
id = `n${++seq}`;
|
|
209
|
+
} while (used.has(id));
|
|
210
|
+
used.add(id);
|
|
211
|
+
return id;
|
|
212
|
+
};
|
|
213
|
+
const nodes = [];
|
|
214
|
+
for (let i = 0; i < data.nodes.length; i++) {
|
|
215
|
+
const n = data.nodes[i];
|
|
216
|
+
// text 允许空串或缺省(画布本身允许无文字节点,原样回显不得判脏);
|
|
217
|
+
// 仅非字符串才算脏字段整体抛错
|
|
218
|
+
if (!n || (n.text !== undefined && typeof n.text !== "string")) {
|
|
219
|
+
throw new Error(`AI 返回的 nodes[${i}] 缺少非空 text`);
|
|
220
|
+
}
|
|
221
|
+
const given = typeof n.id === "string" && n.id.trim() ? n.id.trim() : "";
|
|
222
|
+
// 重复 id / 缺失 id 一律重新分配,避免语义图中两个节点互相覆盖
|
|
223
|
+
const id = given && !used.has(given) ? given : nextId();
|
|
224
|
+
used.add(id);
|
|
225
|
+
nodes.push({ id, shape: inferFlowShape(n), text: (n.text ?? "").trim() });
|
|
226
|
+
}
|
|
227
|
+
// 引用解析:id 优先,其次按唯一文本匹配(模型常用节点文本当 from/to)
|
|
228
|
+
const byId = new Set(nodes.map((n) => n.id));
|
|
229
|
+
const textHits = new Map();
|
|
230
|
+
for (const n of nodes) {
|
|
231
|
+
const key = n.text.trim();
|
|
232
|
+
textHits.set(key, [...(textHits.get(key) ?? []), n.id]);
|
|
233
|
+
}
|
|
234
|
+
const resolveRef = (ref) => {
|
|
235
|
+
if (typeof ref !== "string" || !ref.trim())
|
|
236
|
+
return null;
|
|
237
|
+
const r = ref.trim();
|
|
238
|
+
if (byId.has(r))
|
|
239
|
+
return r;
|
|
240
|
+
const hits = textHits.get(r);
|
|
241
|
+
return hits?.length === 1 ? hits[0] : null;
|
|
242
|
+
};
|
|
243
|
+
const edges = [];
|
|
244
|
+
const seen = new Set();
|
|
245
|
+
// 出入端口方向:合法值保留(布局器按显式方向落边),非法值静默丢弃——
|
|
246
|
+
// 模型写错方向不应让整次 render 失败,退回自动选边即可
|
|
247
|
+
const dirOf = (v) => {
|
|
248
|
+
const d = typeof v === "string" ? v.trim().toLowerCase() : "";
|
|
249
|
+
return PORT_DIRS.includes(d) ? d : undefined;
|
|
250
|
+
};
|
|
251
|
+
const rawEdges = Array.isArray(data.edges) ? data.edges : [];
|
|
252
|
+
for (const e of rawEdges) {
|
|
253
|
+
const from = resolveRef(e?.from);
|
|
254
|
+
const to = resolveRef(e?.to);
|
|
255
|
+
if (!from || !to)
|
|
256
|
+
continue;
|
|
257
|
+
const text = typeof e?.text === "string" && e.text.trim() ? e.text.trim() : undefined;
|
|
258
|
+
const fromDir = dirOf(e?.fromDir);
|
|
259
|
+
const toDir = dirOf(e?.toDir);
|
|
260
|
+
const key = `${from}→${to}:${text ?? ""}`;
|
|
261
|
+
if (seen.has(key))
|
|
262
|
+
continue;
|
|
263
|
+
seen.add(key);
|
|
264
|
+
edges.push({
|
|
265
|
+
from,
|
|
266
|
+
to,
|
|
267
|
+
...(text ? { text } : {}),
|
|
268
|
+
...(fromDir ? { fromDir } : {}),
|
|
269
|
+
...(toDir ? { toDir } : {}),
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
return { nodes, edges };
|
|
273
|
+
}
|
|
274
|
+
// 校验并规整 LLM 返回的操作序列:render 的语义图当场规整(脏字段整体抛错),
|
|
275
|
+
// undo/redo/history 无载荷,answer 需非空 text,未知 op 抛错
|
|
276
|
+
export function normalizeAIFlowOps(raw) {
|
|
277
|
+
if (!Array.isArray(raw))
|
|
278
|
+
throw new Error("AI 返回格式错误:应为操作数组");
|
|
279
|
+
return raw.map((item, i) => {
|
|
280
|
+
const op = item;
|
|
281
|
+
const no = `(第 ${i + 1} 项)`;
|
|
282
|
+
if (op?.op === "undo" || op?.op === "redo" || op?.op === "history") {
|
|
283
|
+
return { op: op.op };
|
|
284
|
+
}
|
|
285
|
+
if (op?.op === "answer") {
|
|
286
|
+
if (typeof op.text !== "string" || !op.text.trim())
|
|
287
|
+
throw new Error(`AI answer 操作缺少 text${no}`);
|
|
288
|
+
return { op: "answer", text: op.text.trim() };
|
|
289
|
+
}
|
|
290
|
+
if (op?.op === "render") {
|
|
291
|
+
// graph 允许省略外层包装:{"op":"render","nodes":[...],"edges":[...]}
|
|
292
|
+
const source = op.graph ?? (Array.isArray(op.nodes) ? op : undefined);
|
|
293
|
+
if (!source)
|
|
294
|
+
throw new Error(`AI render 操作缺少 graph${no}`);
|
|
295
|
+
return { op: "render", graph: normalizeAIFlowGraph(source) };
|
|
296
|
+
}
|
|
297
|
+
if (op?.op === "createNode") {
|
|
298
|
+
const ref = typeof op.ref === "string" ? op.ref.trim() : "";
|
|
299
|
+
const dir = typeof op.dir === "string" ? op.dir.toLowerCase() : "";
|
|
300
|
+
if (!ref)
|
|
301
|
+
throw new Error(`AI createNode 操作缺少 ref${no}`);
|
|
302
|
+
if (!PORT_DIRS.includes(dir)) {
|
|
303
|
+
throw new Error(`AI createNode 操作的 dir 非法${no}: ${dir}`);
|
|
304
|
+
}
|
|
305
|
+
// 文字可为空(画布允许无文字节点);非字符串视为脏字段
|
|
306
|
+
if (op.text !== undefined && typeof op.text !== "string") {
|
|
307
|
+
throw new Error(`AI createNode 操作的 text 不是字符串${no}`);
|
|
308
|
+
}
|
|
309
|
+
const text = typeof op.text === "string" ? op.text.trim() : "";
|
|
310
|
+
// shape 省略 → 门面默认与参考节点同类型;给出时经内置形状推断收敛
|
|
311
|
+
const shape = op.shape === undefined
|
|
312
|
+
? undefined
|
|
313
|
+
: inferFlowShape({ shape: op.shape, role: op.role, text });
|
|
314
|
+
return {
|
|
315
|
+
op: "createNode",
|
|
316
|
+
ref,
|
|
317
|
+
dir: dir,
|
|
318
|
+
...(shape ? { shape } : {}),
|
|
319
|
+
text,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
if (op?.op === "replaceShape") {
|
|
323
|
+
// shape 必须是内置形状(这里就是要精确换成的目标,不能像 nodes[].shape
|
|
324
|
+
// 那样静默降级为 rect,否则模型笔误会被无声替换成矩形)
|
|
325
|
+
const ref = typeof op.ref === "string" ? op.ref.trim() : "";
|
|
326
|
+
if (!ref)
|
|
327
|
+
throw new Error(`AI replaceShape 操作缺少 ref${no}`);
|
|
328
|
+
const shape = typeof op.shape === "string" ? op.shape.toLowerCase() : "";
|
|
329
|
+
if (!BUILTIN_SHAPES.includes(shape)) {
|
|
330
|
+
throw new Error(`AI replaceShape 操作的 shape 非法${no}: ${String(op.shape)}`);
|
|
331
|
+
}
|
|
332
|
+
return { op: "replaceShape", ref, shape: shape };
|
|
333
|
+
}
|
|
334
|
+
if (op?.op === "setNodeText") {
|
|
335
|
+
// ref 必填;text 必须是字符串(可为空串,画布允许无文字节点)
|
|
336
|
+
const ref = typeof op.ref === "string" ? op.ref.trim() : "";
|
|
337
|
+
if (!ref)
|
|
338
|
+
throw new Error(`AI setNodeText 操作缺少 ref${no}`);
|
|
339
|
+
if (typeof op.text !== "string") {
|
|
340
|
+
throw new Error(`AI setNodeText 操作的 text 不是字符串${no}`);
|
|
341
|
+
}
|
|
342
|
+
return { op: "setNodeText", ref, text: op.text };
|
|
343
|
+
}
|
|
344
|
+
if (op?.op === "removeNode") {
|
|
345
|
+
const ref = typeof op.ref === "string" ? op.ref.trim() : "";
|
|
346
|
+
if (!ref)
|
|
347
|
+
throw new Error(`AI removeNode 操作缺少 ref${no}`);
|
|
348
|
+
return { op: "removeNode", ref };
|
|
349
|
+
}
|
|
350
|
+
if (op?.op === "removeEdge") {
|
|
351
|
+
// ref 为连线 id,或 { from, to, text? } 语义定位(复用 updateEdge 的
|
|
352
|
+
// ref 校验语义:from/to 必填非空字符串,text 可选)
|
|
353
|
+
const r = op.ref;
|
|
354
|
+
const str = (v) => typeof v === "string" && v.trim() ? v.trim() : undefined;
|
|
355
|
+
if (typeof r === "string") {
|
|
356
|
+
if (!r.trim())
|
|
357
|
+
throw new Error(`AI removeEdge 操作缺少 ref${no}`);
|
|
358
|
+
return { op: "removeEdge", ref: r.trim() };
|
|
359
|
+
}
|
|
360
|
+
const rec = r;
|
|
361
|
+
const from = str(rec?.from);
|
|
362
|
+
const to = str(rec?.to);
|
|
363
|
+
if (!from || !to) {
|
|
364
|
+
throw new Error(`AI removeEdge 操作缺少 ref.from / ref.to${no}`);
|
|
365
|
+
}
|
|
366
|
+
const text = str(rec?.text);
|
|
367
|
+
return {
|
|
368
|
+
op: "removeEdge",
|
|
369
|
+
ref: { from, to, ...(text ? { text } : {}) },
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
if (op?.op === "updateEdge") {
|
|
373
|
+
const r = op.ref;
|
|
374
|
+
const str = (v) => typeof v === "string" && v.trim() ? v.trim() : undefined;
|
|
375
|
+
const refFrom = str(r?.from);
|
|
376
|
+
const refTo = str(r?.to);
|
|
377
|
+
if (!refFrom || !refTo) {
|
|
378
|
+
throw new Error(`AI updateEdge 操作缺少 ref.from / ref.to${no}`);
|
|
379
|
+
}
|
|
380
|
+
const dirOf = (v, field) => {
|
|
381
|
+
if (v === undefined)
|
|
382
|
+
return undefined;
|
|
383
|
+
const d = typeof v === "string" ? v.toLowerCase() : "";
|
|
384
|
+
if (!PORT_DIRS.includes(d)) {
|
|
385
|
+
throw new Error(`AI updateEdge 操作的 ${field} 非法${no}: ${String(v)}`);
|
|
386
|
+
}
|
|
387
|
+
return d;
|
|
388
|
+
};
|
|
389
|
+
const refText = str(r?.text);
|
|
390
|
+
const nextFrom = str(op.from);
|
|
391
|
+
const nextTo = str(op.to);
|
|
392
|
+
const nextFromDir = dirOf(op.fromDir, "fromDir");
|
|
393
|
+
const nextToDir = dirOf(op.toDir, "toDir");
|
|
394
|
+
// 分支标签:省略保持不变;空字符串表示清除(须与「不改」显式区分),
|
|
395
|
+
// 非字符串视为脏字段
|
|
396
|
+
let nextText;
|
|
397
|
+
if (op.text !== undefined) {
|
|
398
|
+
if (typeof op.text !== "string") {
|
|
399
|
+
throw new Error(`AI updateEdge 操作的 text 不是字符串${no}`);
|
|
400
|
+
}
|
|
401
|
+
nextText = op.text.trim();
|
|
402
|
+
}
|
|
403
|
+
return {
|
|
404
|
+
op: "updateEdge",
|
|
405
|
+
ref: { from: refFrom, to: refTo, ...(refText ? { text: refText } : {}) },
|
|
406
|
+
...(nextFrom ? { from: nextFrom } : {}),
|
|
407
|
+
...(nextTo ? { to: nextTo } : {}),
|
|
408
|
+
...(nextFromDir ? { fromDir: nextFromDir } : {}),
|
|
409
|
+
...(nextToDir ? { toDir: nextToDir } : {}),
|
|
410
|
+
...(nextText !== undefined ? { text: nextText } : {}),
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
throw new Error(`AI 返回了未知操作类型${no}: ${String(op?.op)}`);
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
// 解析 AI 响应为「操作 + 回答」。容错与 mindmap 的 parseAIResponse 对齐:
|
|
417
|
+
// 1. ```json 代码块 / 前后空白自动剥离
|
|
418
|
+
// 2. 操作数组 / {ops:[...]} / 单个操作对象 {op:"undo"}
|
|
419
|
+
// 3. 裸语义图 {nodes,edges} / {graph:{...}}:等价于一条 render 操作
|
|
420
|
+
// 4. {answer:"..."} 或 {ops:[...],answer:"..."}:回答可独立或伴随操作
|
|
421
|
+
// 5. 非 JSON 纯文本:整体视为回答(模型输出坏 JSON 时也能看到它说了什么)
|
|
422
|
+
export function parseAIFlowOps(raw) {
|
|
423
|
+
let data = raw;
|
|
424
|
+
if (typeof raw === "string") {
|
|
425
|
+
const text = raw
|
|
426
|
+
.trim()
|
|
427
|
+
.replace(/^```(?:json)?\s*/i, "")
|
|
428
|
+
.replace(/```\s*$/, "")
|
|
429
|
+
.trim();
|
|
430
|
+
try {
|
|
431
|
+
data = JSON.parse(text);
|
|
432
|
+
}
|
|
433
|
+
catch {
|
|
434
|
+
if (!text)
|
|
435
|
+
throw new Error("AI 返回内容为空");
|
|
436
|
+
return { ops: [], answer: text };
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
// 数组:操作序列,其中 answer 操作提取为回答文本
|
|
440
|
+
if (Array.isArray(data))
|
|
441
|
+
return splitAnswer(normalizeAIFlowOps(data));
|
|
442
|
+
const obj = data;
|
|
443
|
+
if (!obj || typeof obj !== "object") {
|
|
444
|
+
throw new Error("AI 返回格式错误:应为操作数组或语义图 JSON 对象");
|
|
445
|
+
}
|
|
446
|
+
const answer = typeof obj.answer === "string" && obj.answer.trim() ? obj.answer.trim() : undefined;
|
|
447
|
+
// 单个操作对象(模型常省略外层数组)/ {ops:[...]}
|
|
448
|
+
if (typeof obj.op === "string") {
|
|
449
|
+
const inner = splitAnswer(normalizeAIFlowOps([obj]));
|
|
450
|
+
return { ops: inner.ops, answer: joinAnswer(answer, inner.answer) };
|
|
451
|
+
}
|
|
452
|
+
if (Array.isArray(obj.ops)) {
|
|
453
|
+
const inner = splitAnswer(normalizeAIFlowOps(obj.ops));
|
|
454
|
+
return { ops: inner.ops, answer: joinAnswer(answer, inner.answer) };
|
|
455
|
+
}
|
|
456
|
+
// 裸语义图 / {graph:{...}}:等价于一条 render 操作
|
|
457
|
+
const graphSource = obj.graph ?? (Array.isArray(obj.nodes) ? obj : undefined);
|
|
458
|
+
if (graphSource !== undefined) {
|
|
459
|
+
return {
|
|
460
|
+
ops: [{ op: "render", graph: normalizeAIFlowGraph(graphSource) }],
|
|
461
|
+
answer,
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
if (answer !== undefined)
|
|
465
|
+
return { ops: [], answer };
|
|
466
|
+
throw new Error("AI 返回格式错误:缺少 graph 或 answer");
|
|
467
|
+
}
|
|
468
|
+
// answer 操作与顶层 answer 字段合并为一段回答文本
|
|
469
|
+
function joinAnswer(a, b) {
|
|
470
|
+
return [a, b].filter((t) => !!t).join("\n\n") || undefined;
|
|
471
|
+
}
|
|
472
|
+
function splitAnswer(ops) {
|
|
473
|
+
const rest = [];
|
|
474
|
+
const answers = [];
|
|
475
|
+
for (const op of ops) {
|
|
476
|
+
if (op.op === "answer")
|
|
477
|
+
answers.push(op.text);
|
|
478
|
+
else
|
|
479
|
+
rest.push(op);
|
|
480
|
+
}
|
|
481
|
+
return { ops: rest, answer: answers.join("\n\n") || undefined };
|
|
482
|
+
}
|
|
483
|
+
// 「语义图 + 回答」的简化视图(兼容入口):多次 render 取最后一条,
|
|
484
|
+
// 控制类操作(undo/redo/history)在此视图中被忽略
|
|
485
|
+
export function parseAIFlowResponse(raw) {
|
|
486
|
+
const { ops, answer } = parseAIFlowOps(raw);
|
|
487
|
+
let graph;
|
|
488
|
+
for (const op of ops)
|
|
489
|
+
if (op.op === "render")
|
|
490
|
+
graph = op.graph;
|
|
491
|
+
return { graph, answer };
|
|
492
|
+
}
|
|
493
|
+
// ---- 默认提示词 ----
|
|
494
|
+
// AI 生成提示词模板:把请求渲染为大模型可直接使用的指令。核心约束是
|
|
495
|
+
// 「禁止输出任何几何字段」——坐标与端口方向由程序布局器计算,模型只需描述
|
|
496
|
+
// 流程语义;对话类能力(撤销/重做/查历史/看选中)以操作形式表达,由程序执行。
|
|
497
|
+
// 宿主可自行替换提示词,只需遵守上面的语义图与操作协议。
|
|
498
|
+
export function defaultAIFlowPrompt(req) {
|
|
499
|
+
const { selection, historyState } = req;
|
|
500
|
+
const selEmpty = !selection.nodes.length && !selection.edges.length;
|
|
501
|
+
return [
|
|
502
|
+
"你是流程图助手。需要生成或修改流程图、撤销/重做、查看历史时,只输出一个 JSON 对象,不要输出解释文字,不要用代码块包裹。",
|
|
503
|
+
"输出格式(按指令选择一种):",
|
|
504
|
+
'1. 改图:{"ops":[{"op":"render","graph":{"nodes":[{"id":"n1","shape":"ellipse","text":"开始"},{"id":"n2","shape":"diamond","text":"校验通过?"}],"edges":[{"from":"n1","to":"n2"},{"from":"n2","to":"n3","text":"是","fromDir":"right"}]}}]}',
|
|
505
|
+
' 也可以直接输出语义图 {"nodes":[...],"edges":[...]}(等价于一条 render 操作)。',
|
|
506
|
+
'2. 撤销 / 重做:{"ops":[{"op":"undo"}]} 或 {"ops":[{"op":"redo"}]};可连写多次表示连续撤销/重做,但不能与改图操作写在同一批。',
|
|
507
|
+
'3. 查看历史:{"ops":[{"op":"history"}]}(只读,程序会把可撤销/可重做的变更列表并入回答)。',
|
|
508
|
+
'4. 回答提问:{"ops":[{"op":"answer","text":"回答文本"}]} 或 {"answer":"回答文本"} 或纯文本。',
|
|
509
|
+
'5. 在指定节点旁新建:{"ops":[{"op":"createNode","ref":"n2","dir":"bottom","shape":"rect","text":"新步骤"}]};可连写多条。',
|
|
510
|
+
'6. 修改某条连线(首尾/出入端口/分支标签):{"ops":[{"op":"updateEdge","ref":{"from":"a","to":"b"},"fromDir":"right","toDir":"left","text":"是"}]};可连写多条。',
|
|
511
|
+
'7. 替换某节点的形状:{"ops":[{"op":"replaceShape","ref":"n2","shape":"diamond"}]};可连写多条。',
|
|
512
|
+
'8. 修改某节点的文字:{"ops":[{"op":"setNodeText","ref":"n2","text":"新文字"}]};可连写多条。',
|
|
513
|
+
'9. 删除某节点:{"ops":[{"op":"removeNode","ref":"n2"}]}(节点连同其关联连线一起删除);可连写多条。',
|
|
514
|
+
'10. 删除某条连线:{"ops":[{"op":"removeEdge","ref":{"from":"a","to":"b"}}]} 或 {"ops":[{"op":"removeEdge","ref":"边id"}]};可连写多条。',
|
|
515
|
+
"字段说明(updateEdge):",
|
|
516
|
+
"- ref:定位当前连线,from/to 为这条边现在的起点与终点节点 id;同对节点有多条分支边时加 text 填分支标签。",
|
|
517
|
+
"- fromDir / toDir:重接后的出入端口,只能是 top / bottom / left / right(如「从 a 的右边出、进 b 的左边」填 right / left);省略时程序按节点相对位置自动选边。",
|
|
518
|
+
"- from / to:把该端重接到别的节点(填节点 id 或唯一文字);省略表示端点节点不变,只改方向或标签。",
|
|
519
|
+
"- text:新的分支标签(是/否、通过/驳回等),空字符串表示清除标签;省略表示标签不变。只改标签时 from/to/fromDir/toDir 全部省略即可。",
|
|
520
|
+
"字段说明(createNode):",
|
|
521
|
+
"- ref:参考节点的 id,取下方「当前流程图」里的 nodes[].id;也可用该节点唯一文字。",
|
|
522
|
+
"- dir:新节点相对参考节点的方向,只能是 top / bottom / left / right(上 / 下 / 左 / 右)。",
|
|
523
|
+
"- shape:新节点形状,取值同 nodes[].shape;省略时与参考节点同类型。text 为节点文字,可为空字符串。",
|
|
524
|
+
"字段说明(replaceShape):",
|
|
525
|
+
"- ref:目标节点的 id 或唯一文字。",
|
|
526
|
+
"- shape:目标形状,只允许 rect / diamond / ellipse / parallelogram / hexagon / database。节点位置、尺寸、文字与全部连线保持不变,只换形状。",
|
|
527
|
+
"字段说明(setNodeText):",
|
|
528
|
+
"- ref:目标节点的 id 或唯一文字(可按改前文字定位)。",
|
|
529
|
+
"- text:新文字,可为空字符串(画布允许无文字节点)。节点位置、尺寸、形状与全部连线保持不变,只改文字。",
|
|
530
|
+
"字段说明(removeNode / removeEdge):",
|
|
531
|
+
"- removeNode.ref:待删节点的 id 或唯一文字;其关联连线随之删除,一次 Ctrl+Z 可整体恢复。",
|
|
532
|
+
"- removeEdge.ref:连线 id,或 { from, to } 加可选 text(同对节点有多条分支边时用标签区分)。",
|
|
533
|
+
"- 删除判断节点前先确认其分支已另行处理;删除后不要让其它节点变成没有连线的孤岛。",
|
|
534
|
+
"字段说明(render):",
|
|
535
|
+
"- nodes[].id:节点唯一标识,字符串;新节点可以给新 id 或省略(程序自动补全)。",
|
|
536
|
+
"- nodes[].shape:只允许 rect(步骤)、diamond(判断)、ellipse(开始/结束)、parallelogram(输入/输出)、hexagon(准备)、database(存储)。也可以用 role 字段代替(start/end/decision/io/process/data),程序会自动推断形状。",
|
|
537
|
+
"- nodes[].text:节点文字,简短;判断节点写成问句。允许 text 为空字符串(画布上存在无文字的节点,原样保留即可,不要替它虚构文字)。",
|
|
538
|
+
"- edges[].from / edges[].to:必须是 nodes 中存在的 id。edges[].text 只写分支短标签(是/否、通过/驳回、超时等),普通连线省略。",
|
|
539
|
+
"- edges[].fromDir / edges[].toDir(可选):固定这条线从起点哪一侧出(fromDir)与进入终点哪一侧(toDir),取值 top / bottom / left / right。判断节点想固定分支走向(如「是」从右出、「否」从下出)、或用户明确说了出入方向时给出;省略则由程序按布局自动选边。修改现有图时,下方「当前流程图」的边上带有 fromDir/toDir(即当前实际走向):未变更的边必须原样带上这两个字段,只有走向需要变化的边才修改它们。",
|
|
540
|
+
"严格禁止输出 x、y、width、height、坐标、位置等几何字段:布局与坐标由程序自动计算,输出这些字段会导致生成失败。端口方向只允许出现在 edges[].fromDir/toDir 与 updateEdge 操作中,其余位置一律不要输出。",
|
|
541
|
+
"绘图规则:",
|
|
542
|
+
"- 有且仅有一个开始节点;判断节点的每条出边都要写分支标签;流程要能走到结束节点。",
|
|
543
|
+
"- 循环/回退用一条指回已有节点的边表示,不要复制出重复节点;不要出现没有连线的孤立节点。",
|
|
544
|
+
"- 修改现有流程图时,保留未改动节点的 id 与文字,只增删需要变化的节点和边,输出完整的最终图(不是补丁)。",
|
|
545
|
+
"- 用户说「在 X 下面 / 上面 / 左边 / 右边新建节点」「给某个节点加一个分支节点」时,用 createNode 操作(方向按用户说的映射到 dir),不要重新输出整张图;这类操作不会改动其他节点的位置与整图结构。createNode 不能与 render 写在同一批。",
|
|
546
|
+
"- 用户说「把 a→b 改成从右边出、左边进」「某条边改连到 c」「调整连线的出入方向」「把 a→b 的分支标签改成 X / 去掉某条边的标签」时,用 updateEdge 操作,不要重新输出整张图;它只改这一条边的首尾、端口与标签,不动任何节点位置。updateEdge 不能与 render 写在同一批。",
|
|
547
|
+
"- 用户说「把某节点改成菱形/数据库/椭圆」等只换形状的要求时,用 replaceShape 操作,不要重新输出整张图;它保留节点位置、文字与全部连线。replaceShape 不能与 render 写在同一批。",
|
|
548
|
+
"- 用户说「把某节点的文字改成 X」「重命名某节点」等只改文字的要求时,用 setNodeText 操作,不要重新输出整张图;它保留节点位置、形状与全部连线。setNodeText 不能与 render 写在同一批。",
|
|
549
|
+
"- 用户说「删除某节点」「去掉某条连线」「移除某个步骤」时,用 removeNode / removeEdge 操作,不要重新输出整张图;删除动作可撤销,且不会打乱其它节点的位置。removeNode / removeEdge 不能与 render 写在同一批。",
|
|
550
|
+
"对话规则:",
|
|
551
|
+
"- 用户问「选中了什么」「这个节点是什么」时,只依据下方「当前选中」回答,不要改图;当前选中为空就直说没有选中任何节点或连线,不要编造。",
|
|
552
|
+
"- 用户说「撤销」「重做」时输出对应的 undo / redo 操作,不要试图通过重新生成整张图来模拟;下方「历史状态」为 0 条时应如实说明没有可撤销/可重做的变更。",
|
|
553
|
+
"- 用户问「刚才改了什么」「做过哪些操作」时输出 history 操作,由程序给出历史列表,不要凭空描述。",
|
|
554
|
+
"- 仅提问、咨询、无需改图时不要输出 nodes/edges。",
|
|
555
|
+
"",
|
|
556
|
+
// 对话历史:多轮上下文,取最近若干轮防止提示词膨胀
|
|
557
|
+
...(req.history.length
|
|
558
|
+
? [
|
|
559
|
+
"对话历史(按时间先后,仅供理解上下文):",
|
|
560
|
+
...req.history
|
|
561
|
+
.slice(-10)
|
|
562
|
+
.map((t) => `${t.role === "user" ? "用户" : "助手"}:${t.text}`),
|
|
563
|
+
"",
|
|
564
|
+
]
|
|
565
|
+
: []),
|
|
566
|
+
`历史状态:可撤销 ${historyState.undoCount} 条,可重做 ${historyState.redoCount} 条。`,
|
|
567
|
+
"",
|
|
568
|
+
selEmpty
|
|
569
|
+
? "当前选中:无(画布上没有选中的节点或连线)。"
|
|
570
|
+
: `当前选中(只读上下文,共 ${selection.nodes.length} 个节点、${selection.edges.length} 条连线):`,
|
|
571
|
+
...(selEmpty ? [] : [JSON.stringify(selection)]),
|
|
572
|
+
"",
|
|
573
|
+
"当前流程图(语义图,已剥离坐标;edges[].fromDir/toDir 为该连线当前实际的出入端口):",
|
|
574
|
+
JSON.stringify(req.graph),
|
|
575
|
+
"",
|
|
576
|
+
`用户指令:${req.prompt}`,
|
|
577
|
+
].join("\n");
|
|
578
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// 历史描述(AI history 操作的读取实现,纯函数,导出便于测试):
|
|
2
|
+
// 把撤销/重做栈的序列化命令转为人类可读文案。
|
|
3
|
+
// 各 kind 命令的载荷形状统一取自 commands.ts / history-codec.ts(与生产端、
|
|
4
|
+
// 解码端共享同一类型源),本模块只读不写。
|
|
5
|
+
// 形状 kind 的中文名:历史文案面向用户,未知 kind(第三方形状)退化为 kind 原文
|
|
6
|
+
const SHAPE_LABEL = {
|
|
7
|
+
rect: "矩形",
|
|
8
|
+
diamond: "判断",
|
|
9
|
+
ellipse: "椭圆",
|
|
10
|
+
parallelogram: "输入输出",
|
|
11
|
+
hexagon: "六边形",
|
|
12
|
+
database: "存储",
|
|
13
|
+
};
|
|
14
|
+
const shapeKindLabel = (kind) => SHAPE_LABEL[kind] ?? kind;
|
|
15
|
+
// 把单条序列化命令转为可读描述:"将「校验通过?」改为「是否为管理员」"。
|
|
16
|
+
// 节点文本按 id 经模型解析(已删节点的文本从载荷内嵌数据读取);
|
|
17
|
+
// 组合命令递归描述子命令并以分号连接;未知 kind 退化为 kind 字符串
|
|
18
|
+
export function describeHistoryCommand(s, model) {
|
|
19
|
+
const shapeText = (id) => (id ? model.shapes.get(id)?.text.text : "") || "(已不存在的节点)";
|
|
20
|
+
if (s.kind === "composite") {
|
|
21
|
+
const p = s.payload;
|
|
22
|
+
const children = (p?.children ?? [])
|
|
23
|
+
.map((c) => describeHistoryCommand(c, model))
|
|
24
|
+
.filter(Boolean);
|
|
25
|
+
return children.join(";") || s.kind;
|
|
26
|
+
}
|
|
27
|
+
switch (s.kind) {
|
|
28
|
+
case "flowchart.move": {
|
|
29
|
+
const p = s.payload;
|
|
30
|
+
const ids = p.v === "delta" ? (p.targets ?? []) : p.before.map((b) => b.shapeId);
|
|
31
|
+
return ids.length === 1
|
|
32
|
+
? `移动「${shapeText(ids[0])}」`
|
|
33
|
+
: `移动 ${ids.length} 个节点`;
|
|
34
|
+
}
|
|
35
|
+
case "flowchart.resize": {
|
|
36
|
+
const p = s.payload;
|
|
37
|
+
const ids = p.v === "single" ? [p.shapeId] : p.before.map((b) => b.shapeId);
|
|
38
|
+
return ids.length === 1
|
|
39
|
+
? `调整「${shapeText(ids[0])}」的大小`
|
|
40
|
+
: `调整 ${ids.length} 个节点的大小`;
|
|
41
|
+
}
|
|
42
|
+
case "flowchart.reconnect": {
|
|
43
|
+
const p = s.payload;
|
|
44
|
+
return `把连到「${shapeText(p.oldNodeId)}」的一端改接到「${shapeText(p.newNodeId)}」`;
|
|
45
|
+
}
|
|
46
|
+
case "flowchart.text": {
|
|
47
|
+
const p = s.payload;
|
|
48
|
+
return `将「${p.before}」改为「${p.after}」`;
|
|
49
|
+
}
|
|
50
|
+
case "flowchart.edgeText": {
|
|
51
|
+
const p = s.payload;
|
|
52
|
+
return `把连线标签从「${p.before || "空"}」改为「${p.after || "空"}」`;
|
|
53
|
+
}
|
|
54
|
+
case "flowchart.add-shape": {
|
|
55
|
+
const p = s.payload;
|
|
56
|
+
return `添加${shapeKindLabel(p.data.shape)}节点「${p.data.text}」`;
|
|
57
|
+
}
|
|
58
|
+
case "flowchart.connect": {
|
|
59
|
+
const p = s.payload;
|
|
60
|
+
return `连接「${shapeText(p.fromId)}」→「${shapeText(p.toId)}」`;
|
|
61
|
+
}
|
|
62
|
+
case "flowchart.delete": {
|
|
63
|
+
const p = s.payload;
|
|
64
|
+
if (p.v === "edge")
|
|
65
|
+
return "删除一条连线";
|
|
66
|
+
const first = p.items?.[0];
|
|
67
|
+
if (!first)
|
|
68
|
+
return "删除节点";
|
|
69
|
+
const more = (p.items?.length ?? 0) > 1 ? ` 等 ${p.items.length} 个节点` : "";
|
|
70
|
+
return `删除「${first.data.text}」${more}`;
|
|
71
|
+
}
|
|
72
|
+
case "flowchart.replace": {
|
|
73
|
+
const p = s.payload;
|
|
74
|
+
return `把「${p.oldData.text}」的形状改为「${shapeKindLabel(p.newData.shape)}」`;
|
|
75
|
+
}
|
|
76
|
+
case "flowchart.render": {
|
|
77
|
+
const p = s.payload;
|
|
78
|
+
return `重绘整张流程图(${p.after.data.nodes.length} 个节点)`;
|
|
79
|
+
}
|
|
80
|
+
default:
|
|
81
|
+
return s.kind;
|
|
82
|
+
}
|
|
83
|
+
}
|