dsh-workflow-canvas 1.2.1 → 1.4.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/README.md +10 -7
- package/README.zh.md +10 -7
- package/client.js +1258 -324
- package/index.js +87 -13
- package/package.json +1 -1
- package/skills/workflow-canvas/SKILL.md +4 -3
package/client.js
CHANGED
|
@@ -31,6 +31,17 @@ window.__ModuleLoader__.load({
|
|
|
31
31
|
const KIND = 'workflow';
|
|
32
32
|
const STORAGE_PREFIX = 'dsh-workflow-canvas:v1:';
|
|
33
33
|
const PRESET_KEY = STORAGE_PREFIX + 'presets';
|
|
34
|
+
const SHORTCUTS_KEY = STORAGE_PREFIX + 'shortcuts';
|
|
35
|
+
const DEFAULT_SHORTCUTS = {
|
|
36
|
+
addNode: 'Shift+A',
|
|
37
|
+
duplicate: 'Shift+D',
|
|
38
|
+
delete: 'Delete',
|
|
39
|
+
undo: 'Ctrl+Z',
|
|
40
|
+
fitView: '',
|
|
41
|
+
autoLayout: '',
|
|
42
|
+
toggleDir: '',
|
|
43
|
+
};
|
|
44
|
+
const SHORTCUT_ORDER = ['addNode', 'duplicate', 'delete', 'undo', 'fitView', 'autoLayout', 'toggleDir'];
|
|
34
45
|
|
|
35
46
|
const NODE_W = 216;
|
|
36
47
|
const NODE_H = 234;
|
|
@@ -181,12 +192,12 @@ window.__ModuleLoader__.load({
|
|
|
181
192
|
'6. 连好后点「● 已启用」,然后对对话说「跑一次」,由我调用执行。',
|
|
182
193
|
'7. 遇到 Lead 节点会暂停,我做完再把结果交回去继续。',
|
|
183
194
|
'8. 没连线的节点显示为虚线,运行时会被跳过。',
|
|
184
|
-
'9.
|
|
195
|
+
'9. 右键单击节点 / 连线 / 空白处可弹出快捷菜单(含线上插点、复制删除、新建节点等);按住右键划过连线可切断(可在「⋯」开关)。',
|
|
185
196
|
'10. 点右上角「☰ 预设」顶部即可保存当前画布,开新对话时一键载入跨会话复用。',
|
|
186
197
|
'11. 你可以直接让我改画布:说「把那三个节点的分工改成…」,我会就地修改,不动你摆的位置。',
|
|
187
198
|
'12. session 线连到 Lead 时,我会在暂停那步拿到那个子代理的会话,可以继续追问它。',
|
|
188
199
|
'13. 按住鼠标中键(或空格 + 左键)拖动画布平移;点击子代理节点左下角状态可直达它的对话记录。',
|
|
189
|
-
'14.
|
|
200
|
+
'14. 快捷键:默认 Shift+A 新建节点,Shift+D 复制节点与连线,Delete 删除,Ctrl+Z 撤销,Esc 关闭弹窗(可在「⋯ → 快捷键设置」自定义)。',
|
|
190
201
|
].join('\n'),
|
|
191
202
|
openChat: '会话',
|
|
192
203
|
tipOpenRun: '点击打开该子代理的对话记录',
|
|
@@ -218,6 +229,47 @@ window.__ModuleLoader__.load({
|
|
|
218
229
|
runStarted: '已向当前会话发起画布执行',
|
|
219
230
|
runFailed: '发起运行失败',
|
|
220
231
|
runSendUnavailable: '当前宿主不支持从画布直接发起对话,请在聊天框发送消息启动',
|
|
232
|
+
dirLR: '⇄ 横排',
|
|
233
|
+
dirTB: '⇅ 竖排',
|
|
234
|
+
tipDir: '切换画布流向(横排 → / 竖排 ↓),竖排更适合窄侧边栏,切换时自动重排(可 ↶ 撤销)',
|
|
235
|
+
condSideR: '右出',
|
|
236
|
+
condSideL: '左出',
|
|
237
|
+
tipCondSide: '竖排模式下切换分支输出口在左侧或右侧',
|
|
238
|
+
refsBtn: '参考',
|
|
239
|
+
refsTitleGlobal: '全局参考 / 约束(注入所有节点)',
|
|
240
|
+
refsTitleNode: '节点参考 / 约束',
|
|
241
|
+
refsAdd: '+ 添加参考',
|
|
242
|
+
refsPh: '文件路径、URL 或约束条款,如 src/auth.js',
|
|
243
|
+
refsEmpty: '点击下方按钮添加参考文件、路径或规范约束(最多 16 条)',
|
|
244
|
+
tipRefs: '附加参考文件、目录或约束清单,运行时自动注入提示词',
|
|
245
|
+
delRefTip: '删除该参考项',
|
|
246
|
+
ctxNodeTitle: '节点操作',
|
|
247
|
+
ctxEdgeTitle: '连线操作',
|
|
248
|
+
ctxCanvasTitle: '画布操作',
|
|
249
|
+
ctxDup: '复制节点',
|
|
250
|
+
ctxDelNode: '删除节点',
|
|
251
|
+
ctxOpenChat: '打开子代理对话 ↗',
|
|
252
|
+
ctxEditText: '展开编辑文本',
|
|
253
|
+
ctxManageRefs: '管理参考清单',
|
|
254
|
+
ctxDelEdge: '删除连线',
|
|
255
|
+
ctxInsertAgent: '在此插入子代理',
|
|
256
|
+
ctxInsertCond: '在此插入条件节点',
|
|
257
|
+
ctxLangToggle: '界面语言',
|
|
258
|
+
shortcutsMenu: '⌨ 快捷键设置',
|
|
259
|
+
shortcutsTitle: '快捷键设置',
|
|
260
|
+
shortcutsHint: '点击右侧按键框后按下新组合键;按 Esc 取消录制,点 × 清除绑定。',
|
|
261
|
+
shortcutsReset: '恢复默认',
|
|
262
|
+
shortcutsPress: '请按键…',
|
|
263
|
+
shortcutsUnset: '未设置',
|
|
264
|
+
shortcutsResetOk: '快捷键已恢复默认',
|
|
265
|
+
shortcutsConflict: '已更新快捷键(原冲突项已清空)',
|
|
266
|
+
scAddNode: '新建节点(光标处)',
|
|
267
|
+
scDuplicate: '复制选中节点与连线',
|
|
268
|
+
scDelete: '删除选中节点',
|
|
269
|
+
scUndo: '撤销',
|
|
270
|
+
scFitView: '全览居中',
|
|
271
|
+
scAutoLayout: '自动排版',
|
|
272
|
+
scToggleDir: '切换横排 / 竖排',
|
|
221
273
|
fxLabel: '视觉效果',
|
|
222
274
|
fxMinimal: '极简',
|
|
223
275
|
fxStandard: '标准',
|
|
@@ -227,8 +279,8 @@ window.__ModuleLoader__.load({
|
|
|
227
279
|
tipLeadReady: '上游节点已全部完成,正等待在对话里拍板继续',
|
|
228
280
|
stDeadEnd: '无出边',
|
|
229
281
|
tipDeadEnd: '该子代理没有下游连线,运行时不生效;请连入下游节点或终审 Lead',
|
|
230
|
-
stSoloLead: '
|
|
231
|
-
tipSoloLead: '该 Lead
|
|
282
|
+
stSoloLead: '待填分工',
|
|
283
|
+
tipSoloLead: '该 Lead 阶段未连入子代理且分工为空,填写分工后即可作为主对话阶段运行',
|
|
232
284
|
singleModelHint: '当前仅 1 个可用模型,暂无其它备用路由',
|
|
233
285
|
importNone: '剪贴板里没有可识别的画布数据',
|
|
234
286
|
importBad: '画布数据格式不对',
|
|
@@ -325,12 +377,12 @@ window.__ModuleLoader__.load({
|
|
|
325
377
|
'6. Press ● ON, then ask in chat to run the canvas.',
|
|
326
378
|
'7. The run pauses at every Lead node so the conversation can do that step.',
|
|
327
379
|
'8. Unlinked nodes are dashed and skipped at run time.',
|
|
328
|
-
'9.
|
|
380
|
+
'9. Right-click a node, wire, or blank canvas for context actions (insert on wire, duplicate/delete, add nodes); right-drag across a wire to cut it (toggle under ⋯).',
|
|
329
381
|
'10. Open ☰ Presets to save the current canvas at the top and load it in any new chat.',
|
|
330
382
|
'11. You can ask me to edit the canvas; I patch it in place and keep your layout.',
|
|
331
383
|
'12. A session link into a Lead step hands me that child agent, so I can follow up with it.',
|
|
332
384
|
'13. Hold the middle mouse button (or Space + drag) to pan; click a subagent status badge at the bottom-left to open its chat.',
|
|
333
|
-
'14. Shortcuts: Shift+A adds a node at cursor,
|
|
385
|
+
'14. Shortcuts: Shift+A adds a node at cursor, Shift+D duplicates nodes & links, Delete removes selected, Ctrl+Z undoes, Esc closes popups (customizable under ⋯ → Shortcuts).',
|
|
334
386
|
].join('\n'),
|
|
335
387
|
openChat: 'Chat',
|
|
336
388
|
tipOpenRun: 'Click to open this subagent conversation',
|
|
@@ -362,6 +414,47 @@ window.__ModuleLoader__.load({
|
|
|
362
414
|
runStarted: 'Workflow run queued in this chat',
|
|
363
415
|
runFailed: 'Failed to start run',
|
|
364
416
|
runSendUnavailable: 'Direct canvas launch is unavailable in this host; send a message in chat to start',
|
|
417
|
+
dirLR: '⇄ Horiz',
|
|
418
|
+
dirTB: '⇅ Vert',
|
|
419
|
+
tipDir: 'Switch canvas direction (Horizontal → / Vertical ↓). Vertical fits narrow sidebars better and auto-layouts (undoable).',
|
|
420
|
+
condSideR: 'Out R',
|
|
421
|
+
condSideL: 'Out L',
|
|
422
|
+
tipCondSide: 'Flip condition branch sockets between left and right edges in vertical mode',
|
|
423
|
+
refsBtn: 'Refs',
|
|
424
|
+
refsTitleGlobal: 'Global references / rules (all nodes)',
|
|
425
|
+
refsTitleNode: 'Node references / rules',
|
|
426
|
+
refsAdd: '+ Add ref',
|
|
427
|
+
refsPh: 'File path, URL, or rule, e.g. src/auth.js',
|
|
428
|
+
refsEmpty: 'Add reference files, paths, or rules injected into prompts (up to 16)',
|
|
429
|
+
tipRefs: 'Attach reference files, paths, or constraints injected at run time',
|
|
430
|
+
delRefTip: 'Remove this reference',
|
|
431
|
+
ctxNodeTitle: 'Node',
|
|
432
|
+
ctxEdgeTitle: 'Link',
|
|
433
|
+
ctxCanvasTitle: 'Canvas',
|
|
434
|
+
ctxDup: 'Duplicate',
|
|
435
|
+
ctxDelNode: 'Delete',
|
|
436
|
+
ctxOpenChat: 'Open chat ↗',
|
|
437
|
+
ctxEditText: 'Expand editor',
|
|
438
|
+
ctxManageRefs: 'Manage refs',
|
|
439
|
+
ctxDelEdge: 'Delete link',
|
|
440
|
+
ctxInsertAgent: 'Insert Subagent here',
|
|
441
|
+
ctxInsertCond: 'Insert Condition here',
|
|
442
|
+
ctxLangToggle: 'Language',
|
|
443
|
+
shortcutsMenu: '⌨ Shortcuts',
|
|
444
|
+
shortcutsTitle: 'Keyboard Shortcuts',
|
|
445
|
+
shortcutsHint: 'Click a key button then press a new combo. Press Esc to cancel, or × to clear.',
|
|
446
|
+
shortcutsReset: 'Reset defaults',
|
|
447
|
+
shortcutsPress: 'Press keys…',
|
|
448
|
+
shortcutsUnset: 'Unbound',
|
|
449
|
+
shortcutsResetOk: 'Shortcuts reset to defaults',
|
|
450
|
+
shortcutsConflict: 'Shortcut updated (cleared conflict)',
|
|
451
|
+
scAddNode: 'Add node at cursor',
|
|
452
|
+
scDuplicate: 'Duplicate nodes & links',
|
|
453
|
+
scDelete: 'Delete selected nodes',
|
|
454
|
+
scUndo: 'Undo',
|
|
455
|
+
scFitView: 'Fit all in view',
|
|
456
|
+
scAutoLayout: 'Auto layout',
|
|
457
|
+
scToggleDir: 'Toggle Horiz / Vert layout',
|
|
365
458
|
fxLabel: 'Visual effects',
|
|
366
459
|
fxMinimal: 'Minimal',
|
|
367
460
|
fxStandard: 'Standard',
|
|
@@ -371,8 +464,8 @@ window.__ModuleLoader__.load({
|
|
|
371
464
|
tipLeadReady: 'Upstream steps are done; waiting for Lead in chat',
|
|
372
465
|
stDeadEnd: 'No out-link',
|
|
373
466
|
tipDeadEnd: 'This subagent has no outgoing link and is skipped at run time; wire it into a downstream node or Lead',
|
|
374
|
-
stSoloLead: 'Needs
|
|
375
|
-
tipSoloLead: 'This Lead
|
|
467
|
+
stSoloLead: 'Needs role',
|
|
468
|
+
tipSoloLead: 'This chained Lead stage has no subagent upstream and an empty role; fill in a role to make it active',
|
|
376
469
|
singleModelHint: 'Only 1 model available — no alternate fallback route',
|
|
377
470
|
importNone: 'No canvas data found in the clipboard',
|
|
378
471
|
importBad: 'Canvas data is malformed',
|
|
@@ -426,16 +519,16 @@ window.__ModuleLoader__.load({
|
|
|
426
519
|
background: C.base, color: C.text, fontSize: '13px',
|
|
427
520
|
},
|
|
428
521
|
toolbar: {
|
|
429
|
-
display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: '
|
|
430
|
-
padding: '8px
|
|
522
|
+
display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: '5px',
|
|
523
|
+
padding: '6px 8px', borderBottom: '1px solid ' + C.border, flex: '0 0 auto',
|
|
431
524
|
},
|
|
432
525
|
btn: {
|
|
433
|
-
padding: '
|
|
434
|
-
background: C.raised, color: C.text, fontSize: '
|
|
526
|
+
padding: '4px 8px', borderRadius: '6px', border: '1px solid ' + C.border,
|
|
527
|
+
background: C.raised, color: C.text, fontSize: '11px', cursor: 'pointer', whiteSpace: 'nowrap',
|
|
435
528
|
},
|
|
436
529
|
btnDirty: {
|
|
437
|
-
padding: '
|
|
438
|
-
background: C.raised, color: C.accent, fontSize: '
|
|
530
|
+
padding: '4px 8px', borderRadius: '6px', border: '1px solid ' + C.accent,
|
|
531
|
+
background: C.raised, color: C.accent, fontSize: '11px', fontWeight: 600,
|
|
439
532
|
cursor: 'pointer', whiteSpace: 'nowrap',
|
|
440
533
|
},
|
|
441
534
|
toolSep: {
|
|
@@ -468,6 +561,21 @@ window.__ModuleLoader__.load({
|
|
|
468
561
|
background: C.elevated, color: C.dim, fontSize: '11px', fontWeight: 600,
|
|
469
562
|
cursor: 'pointer', boxShadow: '0 4px 14px rgba(0,0,0,0.35)',
|
|
470
563
|
},
|
|
564
|
+
floatZoomBar: {
|
|
565
|
+
position: 'absolute', right: '10px', bottom: '10px', zIndex: 30,
|
|
566
|
+
display: 'inline-flex', alignItems: 'center', gap: '4px',
|
|
567
|
+
padding: '3px 5px', borderRadius: '999px',
|
|
568
|
+
background: C.elevated, border: '1px solid ' + C.border,
|
|
569
|
+
boxShadow: '0 4px 14px rgba(0,0,0,0.28)',
|
|
570
|
+
},
|
|
571
|
+
floatZoomBtn: {
|
|
572
|
+
padding: '2px 6px', borderRadius: '999px', border: 'none',
|
|
573
|
+
background: 'transparent', color: C.text, fontSize: '11px',
|
|
574
|
+
cursor: 'pointer', whiteSpace: 'nowrap', lineHeight: '16px',
|
|
575
|
+
},
|
|
576
|
+
ctxDivider: {
|
|
577
|
+
height: '1px', background: C.border, opacity: 0.65, margin: '3px 4px',
|
|
578
|
+
},
|
|
471
579
|
canvasWrap: {
|
|
472
580
|
position: 'relative', flex: '1 1 auto', minHeight: '0',
|
|
473
581
|
display: 'flex', flexDirection: 'column',
|
|
@@ -515,6 +623,19 @@ window.__ModuleLoader__.load({
|
|
|
515
623
|
helpTitle: { flex: '1 1 auto', fontSize: '13px', fontWeight: 600, color: C.text },
|
|
516
624
|
helpBody: { fontSize: '11px', lineHeight: '17px', color: C.dim },
|
|
517
625
|
helpLine: { whiteSpace: 'pre-wrap' },
|
|
626
|
+
shortcutRow: {
|
|
627
|
+
display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px',
|
|
628
|
+
padding: '6px 2px', borderBottom: '1px solid ' + C.border, fontSize: '11px', color: C.text,
|
|
629
|
+
},
|
|
630
|
+
shortcutKeyBtn: {
|
|
631
|
+
minWidth: '88px', padding: '3px 8px', borderRadius: '5px',
|
|
632
|
+
border: '1px solid ' + C.border, background: C.base, color: C.text,
|
|
633
|
+
fontSize: '11px', fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace',
|
|
634
|
+
cursor: 'pointer', textAlign: 'center', outline: 'none', whiteSpace: 'nowrap',
|
|
635
|
+
},
|
|
636
|
+
shortcutKeyRec: {
|
|
637
|
+
borderColor: C.accent, background: C.hover, color: C.accent, fontWeight: 600,
|
|
638
|
+
},
|
|
518
639
|
presetBar: {
|
|
519
640
|
marginLeft: 'auto', display: 'flex', alignItems: 'center',
|
|
520
641
|
gap: '6px', position: 'relative', flex: '0 0 auto',
|
|
@@ -571,13 +692,13 @@ window.__ModuleLoader__.load({
|
|
|
571
692
|
},
|
|
572
693
|
|
|
573
694
|
title: {
|
|
574
|
-
position: 'absolute', left: '10px', right: '
|
|
695
|
+
position: 'absolute', left: '10px', right: '62px', top: '8px', height: '18px',
|
|
575
696
|
fontWeight: 600, fontSize: '12px', lineHeight: '18px',
|
|
576
697
|
border: 'none', background: 'transparent', color: C.text, padding: 0, margin: 0,
|
|
577
698
|
outline: 'none', boxSizing: 'border-box', userSelect: 'text', zIndex: 2,
|
|
578
699
|
},
|
|
579
700
|
titleReadonly: {
|
|
580
|
-
position: 'absolute', left: '10px', right: '
|
|
701
|
+
position: 'absolute', left: '10px', right: '62px', top: '8px', height: '18px',
|
|
581
702
|
fontWeight: 600, fontSize: '12px', lineHeight: '18px',
|
|
582
703
|
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', zIndex: 2,
|
|
583
704
|
},
|
|
@@ -751,8 +872,7 @@ window.__ModuleLoader__.load({
|
|
|
751
872
|
position: 'absolute', top: (ROW_H - PORT) / 2, width: PORT, height: PORT,
|
|
752
873
|
borderRadius: '50%', background: C.raised, border: '2px solid ' + C.border,
|
|
753
874
|
boxSizing: 'border-box', cursor: 'crosshair', zIndex: 6,
|
|
754
|
-
|
|
755
|
-
padding: 0, margin: -3, boxShadow: '0 0 0 3px transparent',
|
|
875
|
+
padding: 0, margin: 0, boxShadow: '0 0 0 3px transparent',
|
|
756
876
|
},
|
|
757
877
|
nodeDelete: {
|
|
758
878
|
position: 'absolute', right: '-8px', top: '-8px', width: '18px', height: '18px',
|
|
@@ -783,26 +903,106 @@ window.__ModuleLoader__.load({
|
|
|
783
903
|
padding: '9px 10px', zIndex: 65, boxShadow: '0 14px 32px rgba(0,0,0,0.52)',
|
|
784
904
|
color: C.text, fontSize: '11px', lineHeight: '1.5', userSelect: 'text',
|
|
785
905
|
},
|
|
906
|
+
refsPopover: {
|
|
907
|
+
position: 'absolute', left: '100%', top: '0', marginLeft: '8px', width: '268px',
|
|
908
|
+
background: C.elevated, color: C.text, border: '1px solid ' + C.border, borderRadius: '8px',
|
|
909
|
+
padding: '8px 9px', zIndex: 72, boxShadow: '0 12px 28px rgba(0,0,0,0.34)',
|
|
910
|
+
},
|
|
911
|
+
refsRow: {
|
|
912
|
+
display: 'flex', alignItems: 'center', gap: '4px', marginBottom: '5px',
|
|
913
|
+
},
|
|
914
|
+
refsInput: {
|
|
915
|
+
flex: '1 1 auto', minWidth: 0, height: '22px', boxSizing: 'border-box',
|
|
916
|
+
padding: '0 6px', borderRadius: '4px', border: '1px solid ' + C.border,
|
|
917
|
+
background: C.base, color: C.text, fontSize: '10px', outline: 'none', userSelect: 'text',
|
|
918
|
+
},
|
|
786
919
|
};
|
|
787
920
|
|
|
788
921
|
let hostCtx = null;
|
|
789
922
|
let cachedModels = [];
|
|
790
923
|
|
|
924
|
+
function normalizeRefsUI(rawRefs) {
|
|
925
|
+
if (!Array.isArray(rawRefs) || !rawRefs.length) return [];
|
|
926
|
+
const out = [];
|
|
927
|
+
const seen = new Set();
|
|
928
|
+
for (const r of rawRefs) {
|
|
929
|
+
if (out.length >= 16) break;
|
|
930
|
+
const s = typeof r === 'string' ? r.trim() : '';
|
|
931
|
+
if (!s || seen.has(s)) continue;
|
|
932
|
+
seen.add(s);
|
|
933
|
+
out.push(s);
|
|
934
|
+
}
|
|
935
|
+
return out;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* Clamp a floating context menu inside the canvas wrap, flipping left/up when near the
|
|
940
|
+
* right or bottom edge so menu items never clip off narrow sidebars.
|
|
941
|
+
*/
|
|
942
|
+
function clampMenuPos(cx, cy, wrapW, wrapH, menuW, menuH) {
|
|
943
|
+
const pad = 8;
|
|
944
|
+
const sx = (cx + menuW > wrapW - pad)
|
|
945
|
+
? Math.max(pad, cx - menuW)
|
|
946
|
+
: Math.max(pad, Math.min(wrapW - menuW - pad, cx));
|
|
947
|
+
const sy = (cy + menuH > wrapH - pad)
|
|
948
|
+
? Math.max(pad, cy - menuH)
|
|
949
|
+
: Math.max(pad, Math.min(wrapH - menuH - pad, cy));
|
|
950
|
+
return { sx, sy };
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
* Clone all selected non-entry nodes and every internal edge connecting two cloned nodes,
|
|
955
|
+
* preserving edge type and condition branch while isolating mutable array fields.
|
|
956
|
+
*/
|
|
957
|
+
function cloneSelection(nodes, edges, selectedIds, stampOverride) {
|
|
958
|
+
const selSet = new Set((selectedIds || []).filter((id) => id !== 'lead'));
|
|
959
|
+
const sources = (nodes || []).filter((n) => n && selSet.has(n.id));
|
|
960
|
+
if (!sources.length) return { clones: [], clonedEdges: [] };
|
|
961
|
+
const stamp = stampOverride || Date.now().toString(36);
|
|
962
|
+
const idMap = new Map();
|
|
963
|
+
const clones = sources.map((src, idx) => {
|
|
964
|
+
const { runs: _runs, ...rest } = src;
|
|
965
|
+
const newId = 'n' + stamp + '_' + idx + Math.random().toString(36).slice(2, 4);
|
|
966
|
+
idMap.set(src.id, newId);
|
|
967
|
+
const clone = {
|
|
968
|
+
...rest,
|
|
969
|
+
id: newId,
|
|
970
|
+
x: (src.x || 0) + 28,
|
|
971
|
+
y: (src.y || 0) + 28,
|
|
972
|
+
};
|
|
973
|
+
if (Array.isArray(src.refs)) clone.refs = src.refs.slice();
|
|
974
|
+
if (Array.isArray(src.branches)) clone.branches = src.branches.map((b) => ({ ...b }));
|
|
975
|
+
return clone;
|
|
976
|
+
});
|
|
977
|
+
const clonedEdges = [];
|
|
978
|
+
let edgeIdx = 0;
|
|
979
|
+
for (const e of edges || []) {
|
|
980
|
+
if (!e || !idMap.has(e.from) || !idMap.has(e.to)) continue;
|
|
981
|
+
const nextEdge = {
|
|
982
|
+
...e,
|
|
983
|
+
id: 'e' + stamp + '_' + (edgeIdx++) + Math.random().toString(36).slice(2, 4),
|
|
984
|
+
from: idMap.get(e.from),
|
|
985
|
+
to: idMap.get(e.to),
|
|
986
|
+
};
|
|
987
|
+
clonedEdges.push(nextEdge);
|
|
988
|
+
}
|
|
989
|
+
return { clones, clonedEdges };
|
|
990
|
+
}
|
|
991
|
+
|
|
791
992
|
function socketCenterY(i) {
|
|
792
993
|
return SOCKET_BAND_TOP + i * ROW_H + ROW_H / 2;
|
|
793
994
|
}
|
|
794
995
|
|
|
795
996
|
/**
|
|
796
997
|
* Determine which node kinds can legally receive a wire dragged out from `fromNode`.
|
|
797
|
-
*
|
|
998
|
+
* All non-entry targets (agent, lead, condition) are valid, including Lead -> Lead stage chains.
|
|
798
999
|
*/
|
|
799
|
-
function compatibleTargetsForWire(
|
|
800
|
-
const fromLead = Boolean(fromNode && fromNode.kind === 'lead');
|
|
1000
|
+
function compatibleTargetsForWire(_fromNode, _edgeType) {
|
|
801
1001
|
return {
|
|
802
1002
|
agent: true,
|
|
803
|
-
lead:
|
|
1003
|
+
lead: true,
|
|
804
1004
|
condition: true,
|
|
805
|
-
leadBlockedReason:
|
|
1005
|
+
leadBlockedReason: '',
|
|
806
1006
|
};
|
|
807
1007
|
}
|
|
808
1008
|
|
|
@@ -930,6 +1130,37 @@ window.__ModuleLoader__.load({
|
|
|
930
1130
|
return socketCenterY(idx);
|
|
931
1131
|
}
|
|
932
1132
|
|
|
1133
|
+
function outputSocketX(fromNode, type, branch) {
|
|
1134
|
+
const b = typeof branch === 'string' ? branch.trim() : '';
|
|
1135
|
+
if (b || (fromNode && fromNode.kind === 'condition')) {
|
|
1136
|
+
const list = conditionBranchesForUI(fromNode);
|
|
1137
|
+
const idx = b ? Math.max(0, list.findIndex((x) => x.id === b)) : 0;
|
|
1138
|
+
return Math.round(((idx + 1) / (list.length + 1)) * NODE_W);
|
|
1139
|
+
}
|
|
1140
|
+
const idx = Math.max(0, SOCKET_TYPES.findIndex((t) => t.id === (type || 'prompt')));
|
|
1141
|
+
return Math.round(((idx + 1) / (SOCKET_TYPES.length + 1)) * NODE_W);
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
function inputSocketPos(node, direction) {
|
|
1145
|
+
if (direction === 'tb') return { x: node.x + NODE_W / 2, y: node.y };
|
|
1146
|
+
return { x: node.x, y: node.y + socketCenterY(0, node) };
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
function outputSocketPos(fromNode, type, branch, direction) {
|
|
1150
|
+
if (direction === 'tb') {
|
|
1151
|
+
const b = typeof branch === 'string' ? branch.trim() : '';
|
|
1152
|
+
if (b || (fromNode && fromNode.kind === 'condition')) {
|
|
1153
|
+
const onLeft = Boolean(fromNode && fromNode.tbSide === 'left');
|
|
1154
|
+
return {
|
|
1155
|
+
x: onLeft ? fromNode.x : (fromNode.x + NODE_W),
|
|
1156
|
+
y: fromNode.y + outputSocketY(fromNode, type, b),
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
return { x: fromNode.x + outputSocketX(fromNode, type, branch), y: fromNode.y + nodeHeight(fromNode) };
|
|
1160
|
+
}
|
|
1161
|
+
return { x: fromNode.x + NODE_W, y: fromNode.y + outputSocketY(fromNode, type, branch) };
|
|
1162
|
+
}
|
|
1163
|
+
|
|
933
1164
|
function edgeColorFor(fromNode, edge) {
|
|
934
1165
|
const b = edge && typeof edge.branch === 'string' ? edge.branch.trim() : '';
|
|
935
1166
|
if (b) {
|
|
@@ -983,26 +1214,52 @@ window.__ModuleLoader__.load({
|
|
|
983
1214
|
return doc;
|
|
984
1215
|
}
|
|
985
1216
|
|
|
986
|
-
/** Control points of one link, in canvas coordinates.
|
|
987
|
-
function edgeCurve(from, to, typeOrEdge) {
|
|
1217
|
+
/** Control points of one link, in canvas coordinates. Supports horizontal (lr) and vertical (tb) flow. */
|
|
1218
|
+
function edgeCurve(from, to, typeOrEdge, direction) {
|
|
988
1219
|
const type = (typeOrEdge && typeof typeOrEdge === 'object') ? (typeOrEdge.type || 'prompt') : (typeOrEdge || 'prompt');
|
|
989
1220
|
const branch = (typeOrEdge && typeof typeOrEdge === 'object') ? (typeOrEdge.branch || '') : '';
|
|
1221
|
+
if (direction === 'tb') {
|
|
1222
|
+
const isCondOut = Boolean(branch || (from && from.kind === 'condition'));
|
|
1223
|
+
if (isCondOut) {
|
|
1224
|
+
const onLeft = Boolean(from && from.tbSide === 'left');
|
|
1225
|
+
const x1 = from.x + WORLD_PAD + (onLeft ? 0 : NODE_W);
|
|
1226
|
+
const y1 = from.y + WORLD_PAD + outputSocketY(from, type, branch);
|
|
1227
|
+
const x2 = to.x + WORLD_PAD + NODE_W / 2;
|
|
1228
|
+
const y2 = to.y + WORLD_PAD;
|
|
1229
|
+
const outSpan = Math.max(46, Math.abs(x2 - x1) * 0.35);
|
|
1230
|
+
const dy = Math.max(46, Math.abs(y2 - y1) * 0.45);
|
|
1231
|
+
return {
|
|
1232
|
+
x1, y1,
|
|
1233
|
+
c1x: onLeft ? (x1 - outSpan) : (x1 + outSpan),
|
|
1234
|
+
c1y: y1,
|
|
1235
|
+
c2x: x2,
|
|
1236
|
+
c2y: y2 - dy,
|
|
1237
|
+
x2, y2,
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
const x1 = from.x + WORLD_PAD + outputSocketX(from, type, branch);
|
|
1241
|
+
const y1 = from.y + WORLD_PAD + nodeHeight(from);
|
|
1242
|
+
const x2 = to.x + WORLD_PAD + NODE_W / 2;
|
|
1243
|
+
const y2 = to.y + WORLD_PAD;
|
|
1244
|
+
const dy = Math.max(40, Math.abs(y2 - y1) * 0.5);
|
|
1245
|
+
return { x1, y1, c1x: x1, c1y: y1 + dy, c2x: x2, c2y: y2 - dy, x2, y2 };
|
|
1246
|
+
}
|
|
990
1247
|
const x1 = from.x + WORLD_PAD + NODE_W;
|
|
991
1248
|
const y1 = from.y + WORLD_PAD + outputSocketY(from, type, branch);
|
|
992
1249
|
const x2 = to.x + WORLD_PAD;
|
|
993
|
-
const y2 = to.y + WORLD_PAD + socketCenterY(0);
|
|
1250
|
+
const y2 = to.y + WORLD_PAD + socketCenterY(0, to);
|
|
994
1251
|
const dx = Math.max(40, Math.abs(x2 - x1) * 0.5);
|
|
995
1252
|
return { x1, y1, c1x: x1 + dx, c1y: y1, c2x: x2 - dx, c2y: y2, x2, y2 };
|
|
996
1253
|
}
|
|
997
1254
|
|
|
998
|
-
function edgePath(from, to, typeOrEdge) {
|
|
999
|
-
const c = edgeCurve(from, to, typeOrEdge);
|
|
1255
|
+
function edgePath(from, to, typeOrEdge, direction) {
|
|
1256
|
+
const c = edgeCurve(from, to, typeOrEdge, direction);
|
|
1000
1257
|
return 'M ' + c.x1 + ' ' + c.y1 + ' C ' + c.c1x + ' ' + c.c1y + ', ' + c.c2x + ' ' + c.c2y + ', ' + c.x2 + ' ' + c.y2;
|
|
1001
1258
|
}
|
|
1002
1259
|
|
|
1003
1260
|
/** Shortest distance between a point and one link, sampled along the curve. */
|
|
1004
|
-
function distanceToEdge(point, from, to, typeOrEdge) {
|
|
1005
|
-
const c = edgeCurve(from, to, typeOrEdge);
|
|
1261
|
+
function distanceToEdge(point, from, to, typeOrEdge, direction) {
|
|
1262
|
+
const c = edgeCurve(from, to, typeOrEdge, direction);
|
|
1006
1263
|
let best = Infinity;
|
|
1007
1264
|
let prevX = c.x1;
|
|
1008
1265
|
let prevY = c.y1;
|
|
@@ -1070,8 +1327,8 @@ window.__ModuleLoader__.load({
|
|
|
1070
1327
|
|
|
1071
1328
|
/**
|
|
1072
1329
|
* Reachable non-entry Lead nodes that have zero reachable subagent upstream
|
|
1073
|
-
*
|
|
1074
|
-
*
|
|
1330
|
+
* AND an empty `role` (blank placeholders). Filling a `role` turns them into
|
|
1331
|
+
* active main-conversation stage gates (Lead -> Lead chaining).
|
|
1075
1332
|
*/
|
|
1076
1333
|
function soloLeadNodeIds(nodes, edges) {
|
|
1077
1334
|
const list = Array.isArray(nodes) ? nodes : [];
|
|
@@ -1086,7 +1343,8 @@ window.__ModuleLoader__.load({
|
|
|
1086
1343
|
const src = byId.get(e.from);
|
|
1087
1344
|
return Boolean(src && src.kind !== 'lead');
|
|
1088
1345
|
});
|
|
1089
|
-
|
|
1346
|
+
const hasRole = Boolean(String(n.role || '').trim());
|
|
1347
|
+
if (!hasAgentUp && !hasRole) out.add(n.id);
|
|
1090
1348
|
}
|
|
1091
1349
|
return out;
|
|
1092
1350
|
}
|
|
@@ -1150,7 +1408,7 @@ window.__ModuleLoader__.load({
|
|
|
1150
1408
|
}
|
|
1151
1409
|
|
|
1152
1410
|
/** Tidy a DAG into symmetrical left-to-right columns by longest-path depth. */
|
|
1153
|
-
function layoutGraph(nodes, edges) {
|
|
1411
|
+
function layoutGraph(nodes, edges, direction) {
|
|
1154
1412
|
const list = Array.isArray(nodes) ? nodes : [];
|
|
1155
1413
|
const linkList = Array.isArray(edges) ? edges : [];
|
|
1156
1414
|
if (!list.length) return [];
|
|
@@ -1176,16 +1434,35 @@ window.__ModuleLoader__.load({
|
|
|
1176
1434
|
columns.get(col).push(n);
|
|
1177
1435
|
}
|
|
1178
1436
|
const posById = new Map();
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
const
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1437
|
+
if (direction === 'tb') {
|
|
1438
|
+
const COL_PITCH = 292;
|
|
1439
|
+
const ROW_GAP = 68;
|
|
1440
|
+
const MID_X = 340;
|
|
1441
|
+
const layers = Array.from(columns.keys()).sort((a, b) => a - b);
|
|
1442
|
+
let cursorY = 40;
|
|
1443
|
+
for (const layer of layers) {
|
|
1444
|
+
const layerNodes = columns.get(layer).slice().sort((a, b) => (a.x || 0) - (b.x || 0));
|
|
1445
|
+
const totalW = (layerNodes.length - 1) * COL_PITCH + NODE_W;
|
|
1446
|
+
const startX = Math.round(MID_X - totalW / 2);
|
|
1447
|
+
let maxH = NODE_H;
|
|
1448
|
+
layerNodes.forEach((n, idx) => {
|
|
1449
|
+
posById.set(n.id, { x: startX + idx * COL_PITCH, y: cursorY });
|
|
1450
|
+
maxH = Math.max(maxH, nodeHeight(n));
|
|
1451
|
+
});
|
|
1452
|
+
cursorY += maxH + ROW_GAP;
|
|
1453
|
+
}
|
|
1454
|
+
} else {
|
|
1455
|
+
const COL_PITCH = 300;
|
|
1456
|
+
const ROW_PITCH = 262;
|
|
1457
|
+
const MID_Y = 320;
|
|
1458
|
+
for (const [col, colNodes] of columns.entries()) {
|
|
1459
|
+
const ordered = colNodes.slice().sort((a, b) => (a.y || 0) - (b.y || 0));
|
|
1460
|
+
const totalH = (ordered.length - 1) * ROW_PITCH + NODE_H;
|
|
1461
|
+
const startY = Math.round(MID_Y - totalH / 2);
|
|
1462
|
+
ordered.forEach((n, row) => {
|
|
1463
|
+
posById.set(n.id, { x: 40 + col * COL_PITCH, y: startY + row * ROW_PITCH });
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1189
1466
|
}
|
|
1190
1467
|
return list.map((n) => {
|
|
1191
1468
|
const p = posById.get(n.id);
|
|
@@ -1194,7 +1471,7 @@ window.__ModuleLoader__.load({
|
|
|
1194
1471
|
}
|
|
1195
1472
|
|
|
1196
1473
|
/** Starter templates shipped with the plugin so new users can try one click away. */
|
|
1197
|
-
function builtinTemplates(lang) {
|
|
1474
|
+
function builtinTemplates(lang, direction) {
|
|
1198
1475
|
const en = lang === 'en';
|
|
1199
1476
|
const sweNodes = [
|
|
1200
1477
|
{
|
|
@@ -1387,25 +1664,25 @@ window.__ModuleLoader__.load({
|
|
|
1387
1664
|
{
|
|
1388
1665
|
id: 'tpl-swe',
|
|
1389
1666
|
name: en ? 'SWE Delivery: Scan → Sign-Off → Build → Review' : '软件工程:摸底 → 拍板 → 并行实现 → 独立审查',
|
|
1390
|
-
nodes: layoutGraph(sweNodes, sweEdges),
|
|
1667
|
+
nodes: layoutGraph(sweNodes, sweEdges, direction),
|
|
1391
1668
|
edges: sweEdges,
|
|
1392
1669
|
},
|
|
1393
1670
|
{
|
|
1394
1671
|
id: 'tpl-prd',
|
|
1395
1672
|
name: en ? 'PRD Research → Decide → Build → Review' : 'PRD 调研 → 拍板 → 并行产出 → 终审',
|
|
1396
|
-
nodes: layoutGraph(prdNodes, prdEdges),
|
|
1673
|
+
nodes: layoutGraph(prdNodes, prdEdges, direction),
|
|
1397
1674
|
edges: prdEdges,
|
|
1398
1675
|
},
|
|
1399
1676
|
{
|
|
1400
1677
|
id: 'tpl-ab',
|
|
1401
1678
|
name: en ? 'Parallel Options → Decide → Execute → Review' : '并行方案对比 → 拍板 → 执行 → 验收',
|
|
1402
|
-
nodes: layoutGraph(abNodes, abEdges),
|
|
1679
|
+
nodes: layoutGraph(abNodes, abEdges, direction),
|
|
1403
1680
|
edges: abEdges,
|
|
1404
1681
|
},
|
|
1405
1682
|
{
|
|
1406
1683
|
id: 'tpl-cond',
|
|
1407
1684
|
name: en ? 'Conditional: Run → Pass/Fail Branch → Review' : '条件分支:执行 → 判断分流 → 终审',
|
|
1408
|
-
nodes: layoutGraph(condNodes, condEdges),
|
|
1685
|
+
nodes: layoutGraph(condNodes, condEdges, direction),
|
|
1409
1686
|
edges: condEdges,
|
|
1410
1687
|
},
|
|
1411
1688
|
];
|
|
@@ -1445,39 +1722,43 @@ window.__ModuleLoader__.load({
|
|
|
1445
1722
|
? Math.max(1, Math.min(8, Math.floor(Number(opts.maxParallel))))
|
|
1446
1723
|
: 4;
|
|
1447
1724
|
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
}
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1725
|
+
const entryRefs = normalizeRefsUI(entry.refs);
|
|
1726
|
+
const planOut = {
|
|
1727
|
+
task,
|
|
1728
|
+
maxParallel,
|
|
1729
|
+
skipped: skipped.map((n) => n.label || n.id),
|
|
1730
|
+
nodes: active.map((n) => {
|
|
1731
|
+
const kind = n.kind === 'lead' ? 'lead' : (n.kind === 'condition' ? 'condition' : 'agent');
|
|
1732
|
+
const out = {
|
|
1733
|
+
id: n.id,
|
|
1734
|
+
kind,
|
|
1735
|
+
label: n.label || n.id,
|
|
1736
|
+
role: n.role || '',
|
|
1737
|
+
provider: n.provider || '',
|
|
1738
|
+
model: n.model || '',
|
|
1739
|
+
reasoning: n.reasoning || '',
|
|
1740
|
+
preset: kind === 'condition' ? 'minimal' : (n.preset === 'minimal' ? 'minimal' : 'standard'),
|
|
1741
|
+
keepSession: kind === 'condition' ? false : Boolean(n.keepSession),
|
|
1742
|
+
memoryChildId: kind === 'condition' ? '' : (n.memoryChildId || ''),
|
|
1743
|
+
// A structured link is the only thing that decides this: no separate switch.
|
|
1744
|
+
structured: planEdges.some((e) => e.from === n.id && e.type === 'structured'),
|
|
1745
|
+
fallbackModel: n.fallbackModel || '',
|
|
1746
|
+
fallbackProvider: n.fallbackProvider || '',
|
|
1747
|
+
};
|
|
1748
|
+
if (kind === 'condition' && isCustomBranches(n)) {
|
|
1749
|
+
out.branches = conditionBranchesForUI(n).map((b) => ({ id: b.id, label: b.label }));
|
|
1750
|
+
}
|
|
1751
|
+
if (kind === 'condition' && n.multiMatch) {
|
|
1752
|
+
out.multiMatch = true;
|
|
1753
|
+
}
|
|
1754
|
+
const nodeRefs = normalizeRefsUI(n.refs);
|
|
1755
|
+
if (nodeRefs.length) out.refs = nodeRefs;
|
|
1756
|
+
return out;
|
|
1757
|
+
}),
|
|
1758
|
+
edges: planEdges,
|
|
1480
1759
|
};
|
|
1760
|
+
if (entryRefs.length) planOut.refs = entryRefs;
|
|
1761
|
+
return { plan: planOut };
|
|
1481
1762
|
}
|
|
1482
1763
|
|
|
1483
1764
|
function loadCutMode() {
|
|
@@ -1536,6 +1817,101 @@ window.__ModuleLoader__.load({
|
|
|
1536
1817
|
return PARALLEL_STEPS[(idx + 1) % PARALLEL_STEPS.length];
|
|
1537
1818
|
}
|
|
1538
1819
|
|
|
1820
|
+
/** Canonicalize a shortcut string like "shift+d" or "cmd+z" -> "Shift+D" / "Ctrl+Z". */
|
|
1821
|
+
function normalizeShortcut(raw) {
|
|
1822
|
+
if (typeof raw !== 'string') return '';
|
|
1823
|
+
const trimmed = raw.trim();
|
|
1824
|
+
if (!trimmed) return '';
|
|
1825
|
+
const parts = trimmed.split('+').map((p) => p.trim()).filter(Boolean);
|
|
1826
|
+
let ctrl = false;
|
|
1827
|
+
let alt = false;
|
|
1828
|
+
let shift = false;
|
|
1829
|
+
let key = '';
|
|
1830
|
+
for (const p of parts) {
|
|
1831
|
+
const low = p.toLowerCase();
|
|
1832
|
+
if (low === 'ctrl' || low === 'control' || low === 'cmd' || low === 'meta' || low === 'mod') ctrl = true;
|
|
1833
|
+
else if (low === 'alt' || low === 'option') alt = true;
|
|
1834
|
+
else if (low === 'shift') shift = true;
|
|
1835
|
+
else if (low === 'del' || low === 'delete') key = 'Delete';
|
|
1836
|
+
else if (low === 'backspace') key = 'Backspace';
|
|
1837
|
+
else if (low === 'space' || p === ' ') key = 'Space';
|
|
1838
|
+
else if (low === 'enter' || low === 'return') key = 'Enter';
|
|
1839
|
+
else if (low === 'tab') key = 'Tab';
|
|
1840
|
+
else if (/^f\d{1,2}$/i.test(p)) key = p.toUpperCase();
|
|
1841
|
+
else if (p.length === 1) key = p.toUpperCase();
|
|
1842
|
+
else key = p.charAt(0).toUpperCase() + p.slice(1);
|
|
1843
|
+
}
|
|
1844
|
+
if (!key || key === 'Escape') return '';
|
|
1845
|
+
return (ctrl ? 'Ctrl+' : '') + (alt ? 'Alt+' : '') + (shift ? 'Shift+' : '') + key;
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
/** Extract a canonical shortcut string from a KeyboardEvent, or null for bare modifiers / Esc. */
|
|
1849
|
+
function formatShortcutFromEvent(ev) {
|
|
1850
|
+
if (!ev) return null;
|
|
1851
|
+
const rawKey = typeof ev.key === 'string' ? ev.key : '';
|
|
1852
|
+
if (!rawKey || rawKey === 'Control' || rawKey === 'Shift' || rawKey === 'Alt' || rawKey === 'Meta' || rawKey === 'Escape') {
|
|
1853
|
+
return null;
|
|
1854
|
+
}
|
|
1855
|
+
const code = typeof ev.code === 'string' ? ev.code : '';
|
|
1856
|
+
let key = '';
|
|
1857
|
+
if (/^Key[A-Z]$/.test(code)) key = code.slice(3);
|
|
1858
|
+
else if (/^Digit[0-9]$/.test(code)) key = code.slice(5);
|
|
1859
|
+
else if (rawKey === ' ') key = 'Space';
|
|
1860
|
+
else if (rawKey === 'Delete' || rawKey === 'Backspace' || rawKey === 'Enter' || rawKey === 'Tab') key = rawKey;
|
|
1861
|
+
else if (/^F\d{1,2}$/i.test(rawKey)) key = rawKey.toUpperCase();
|
|
1862
|
+
else if (rawKey.length === 1) key = rawKey.toUpperCase();
|
|
1863
|
+
else key = rawKey;
|
|
1864
|
+
const ctrl = Boolean(ev.ctrlKey || ev.metaKey);
|
|
1865
|
+
const alt = Boolean(ev.altKey);
|
|
1866
|
+
const shift = Boolean(ev.shiftKey);
|
|
1867
|
+
return normalizeShortcut((ctrl ? 'Ctrl+' : '') + (alt ? 'Alt+' : '') + (shift ? 'Shift+' : '') + key) || null;
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
function matchesShortcut(ev, binding) {
|
|
1871
|
+
const target = normalizeShortcut(binding);
|
|
1872
|
+
if (!target) return false;
|
|
1873
|
+
const actual = formatShortcutFromEvent(ev);
|
|
1874
|
+
return Boolean(actual) && actual === target;
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
function applyShortcutBinding(map, actionId, combo) {
|
|
1878
|
+
const next = { ...DEFAULT_SHORTCUTS, ...(map || {}) };
|
|
1879
|
+
const norm = normalizeShortcut(combo);
|
|
1880
|
+
let clearedConflict = false;
|
|
1881
|
+
if (norm) {
|
|
1882
|
+
for (const k of SHORTCUT_ORDER) {
|
|
1883
|
+
if (k !== actionId && normalizeShortcut(next[k]) === norm) {
|
|
1884
|
+
next[k] = '';
|
|
1885
|
+
clearedConflict = true;
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
next[actionId] = norm;
|
|
1890
|
+
return { next, clearedConflict };
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
function loadShortcuts() {
|
|
1894
|
+
try {
|
|
1895
|
+
const raw = window.localStorage.getItem(SHORTCUTS_KEY);
|
|
1896
|
+
if (!raw) return { ...DEFAULT_SHORTCUTS };
|
|
1897
|
+
const parsed = JSON.parse(raw);
|
|
1898
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return { ...DEFAULT_SHORTCUTS };
|
|
1899
|
+
const out = { ...DEFAULT_SHORTCUTS };
|
|
1900
|
+
for (const k of SHORTCUT_ORDER) {
|
|
1901
|
+
if (k in parsed) out[k] = normalizeShortcut(parsed[k]);
|
|
1902
|
+
}
|
|
1903
|
+
return out;
|
|
1904
|
+
} catch (_e) {
|
|
1905
|
+
return { ...DEFAULT_SHORTCUTS };
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
function saveShortcuts(map) {
|
|
1910
|
+
try {
|
|
1911
|
+
window.localStorage.setItem(SHORTCUTS_KEY, JSON.stringify(map));
|
|
1912
|
+
} catch (_e) { /* ignore */ }
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1539
1915
|
/** Pick 'left' or 'right' anchor so a wrapped toolbar dropdown never clips off the pane edge. */
|
|
1540
1916
|
function dropdownAlign(btnRect, containerRect, menuWidth) {
|
|
1541
1917
|
if (!btnRect || !containerRect) return 'right';
|
|
@@ -1651,7 +2027,7 @@ window.__ModuleLoader__.load({
|
|
|
1651
2027
|
if (!error) return this.props.children;
|
|
1652
2028
|
const message = String((error && error.message) || error);
|
|
1653
2029
|
const stack = String((error && error.stack) || '').slice(0, 900);
|
|
1654
|
-
|
|
2030
|
+
return h('div', {
|
|
1655
2031
|
style: {
|
|
1656
2032
|
padding: '12px', fontFamily: 'ui-monospace, monospace', fontSize: '11px',
|
|
1657
2033
|
color: '#e5534b', whiteSpace: 'pre-wrap', overflow: 'auto', height: '100%',
|
|
@@ -1676,6 +2052,11 @@ window.__ModuleLoader__.load({
|
|
|
1676
2052
|
const [menuAlign, setMenuAlign] = useState('right');
|
|
1677
2053
|
const [presetAlign, setPresetAlign] = useState('right');
|
|
1678
2054
|
const [helpOpen, setHelpOpen] = useState(false);
|
|
2055
|
+
const [shortcuts, setShortcuts] = useState(loadShortcuts);
|
|
2056
|
+
const shortcutsRef = useRef(shortcuts);
|
|
2057
|
+
shortcutsRef.current = shortcuts;
|
|
2058
|
+
const [shortcutsOpen, setShortcutsOpen] = useState(false);
|
|
2059
|
+
const [recordingAction, setRecordingAction] = useState(null);
|
|
1679
2060
|
const [cutMode, setCutMode] = useState(loadCutMode);
|
|
1680
2061
|
const [fxLevel, setFxLevel] = useState(loadEffectLevel);
|
|
1681
2062
|
const [maxParallel, setMaxParallel] = useState(loadMaxParallel);
|
|
@@ -1694,6 +2075,9 @@ window.__ModuleLoader__.load({
|
|
|
1694
2075
|
const [modelsLoading, setModelsLoading] = useState(() => cachedModels.length === 0);
|
|
1695
2076
|
const [openModelFor, setOpenModelFor] = useState(null);
|
|
1696
2077
|
const [enabled, setEnabled] = useState(() => Boolean(initial && initial.enabled));
|
|
2078
|
+
const [direction, setDirection] = useState(() => (initial && initial.direction === 'tb' ? 'tb' : 'lr'));
|
|
2079
|
+
const directionRef = useRef(direction);
|
|
2080
|
+
directionRef.current = direction;
|
|
1697
2081
|
|
|
1698
2082
|
const rootElRef = useRef(null);
|
|
1699
2083
|
const canvasWrapRef = useRef(null);
|
|
@@ -1702,6 +2086,8 @@ window.__ModuleLoader__.load({
|
|
|
1702
2086
|
const pointerInsideRoot = useRef(false);
|
|
1703
2087
|
const lastMouseRef = useRef(null);
|
|
1704
2088
|
const [addMenu, setAddMenu] = useState(null);
|
|
2089
|
+
const [ctxMenu, setCtxMenu] = useState(null);
|
|
2090
|
+
const rightClickRef = useRef(null);
|
|
1705
2091
|
const nodeDrag = useRef(null);
|
|
1706
2092
|
const panDrag = useRef(null);
|
|
1707
2093
|
const [panning, setPanning] = useState(false);
|
|
@@ -1720,6 +2106,7 @@ window.__ModuleLoader__.load({
|
|
|
1720
2106
|
const [runsById, setRunsById] = useState({});
|
|
1721
2107
|
const [runState, setRunState] = useState(null);
|
|
1722
2108
|
const [decisionViewFor, setDecisionViewFor] = useState(null);
|
|
2109
|
+
const [refsEditFor, setRefsEditFor] = useState(null);
|
|
1723
2110
|
const [sessionRunning, setSessionRunning] = useState(false);
|
|
1724
2111
|
const [runTriggering, setRunTriggering] = useState(false);
|
|
1725
2112
|
const runTriggeringRef = useRef(false);
|
|
@@ -1747,8 +2134,8 @@ window.__ModuleLoader__.load({
|
|
|
1747
2134
|
useEffect(() => {
|
|
1748
2135
|
const stamp = applyStamp.current;
|
|
1749
2136
|
applyStamp.current = null;
|
|
1750
|
-
saveDoc(sessionId, { nodes, edges, enabled }, stamp === null ? undefined : stamp);
|
|
1751
|
-
}, [sessionId, nodes, edges, enabled]);
|
|
2137
|
+
saveDoc(sessionId, { nodes, edges, enabled, direction }, stamp === null ? undefined : stamp);
|
|
2138
|
+
}, [sessionId, nodes, edges, enabled, direction]);
|
|
1752
2139
|
|
|
1753
2140
|
// Plan signature excludes visual (x, y) coordinates so dragging nodes does
|
|
1754
2141
|
// not trigger false "unsaved changes" warnings; `skipDirtyOnce` suppresses
|
|
@@ -2098,6 +2485,7 @@ window.__ModuleLoader__.load({
|
|
|
2098
2485
|
if (!e.ctrlKey && findScrollableChild(e.target, e.deltaY)) return;
|
|
2099
2486
|
e.preventDefault();
|
|
2100
2487
|
absorbScroll();
|
|
2488
|
+
setCtxMenu(null);
|
|
2101
2489
|
const rect = el.getBoundingClientRect();
|
|
2102
2490
|
const mx = e.clientX - rect.left;
|
|
2103
2491
|
const my = e.clientY - rect.top;
|
|
@@ -2307,10 +2695,10 @@ window.__ModuleLoader__.load({
|
|
|
2307
2695
|
const i = ns.length;
|
|
2308
2696
|
const center = viewportCenterWorld();
|
|
2309
2697
|
const x = atWorld && typeof atWorld.x === 'number'
|
|
2310
|
-
? (linkFrom ? Math.round(atWorld.x) : Math.round(atWorld.x - NODE_W / 2))
|
|
2698
|
+
? (linkFrom ? (directionRef.current === 'tb' ? Math.round(atWorld.x - NODE_W / 2) : Math.round(atWorld.x)) : Math.round(atWorld.x - NODE_W / 2))
|
|
2311
2699
|
: center.x + 40 + (ns.length % 3) * 30;
|
|
2312
2700
|
const y = atWorld && typeof atWorld.y === 'number'
|
|
2313
|
-
? (linkFrom ? Math.round(atWorld.y - socketCenterY(0)) : Math.round(atWorld.y - NODE_H / 2))
|
|
2701
|
+
? (linkFrom ? (directionRef.current === 'tb' ? Math.round(atWorld.y) : Math.round(atWorld.y - socketCenterY(0))) : Math.round(atWorld.y - NODE_H / 2))
|
|
2314
2702
|
: center.y - NODE_H / 2 + (ns.length % 3) * 40;
|
|
2315
2703
|
const defaultLabel = normKind === 'lead'
|
|
2316
2704
|
? 'Lead 步骤 ' + i
|
|
@@ -2345,6 +2733,63 @@ window.__ModuleLoader__.load({
|
|
|
2345
2733
|
}
|
|
2346
2734
|
setSelectedIds([newId]);
|
|
2347
2735
|
setAddMenu(null);
|
|
2736
|
+
setCtxMenu(null);
|
|
2737
|
+
};
|
|
2738
|
+
|
|
2739
|
+
const deleteEdgeById = (edgeId) => {
|
|
2740
|
+
pushSnapshot();
|
|
2741
|
+
setEdges((es) => es.filter((e) => e.id !== edgeId));
|
|
2742
|
+
setCtxMenu(null);
|
|
2743
|
+
flash(t('linkCut') + ' ×1');
|
|
2744
|
+
};
|
|
2745
|
+
|
|
2746
|
+
const insertNodeOnEdge = (edgeId, kind, atWorld) => {
|
|
2747
|
+
const edge = edgesRef.current.find((e) => e.id === edgeId);
|
|
2748
|
+
if (!edge) { setCtxMenu(null); return; }
|
|
2749
|
+
pushSnapshot();
|
|
2750
|
+
const normKind = kind === 'condition' ? 'condition' : 'agent';
|
|
2751
|
+
const newId = 'n' + Date.now().toString(36) + Math.random().toString(36).slice(2, 4);
|
|
2752
|
+
const prefs = lastNodePrefsRef.current || {};
|
|
2753
|
+
setNodes((ns) => {
|
|
2754
|
+
const i = ns.length;
|
|
2755
|
+
const x = atWorld && typeof atWorld.x === 'number' ? Math.round(atWorld.x - NODE_W / 2) : 200;
|
|
2756
|
+
const y = atWorld && typeof atWorld.y === 'number' ? Math.round(atWorld.y - NODE_H / 2) : 140;
|
|
2757
|
+
const defaultLabel = normKind === 'condition'
|
|
2758
|
+
? (lang === 'en' ? 'Condition ' + i : '条件判断 ' + i)
|
|
2759
|
+
: 'Node ' + i;
|
|
2760
|
+
return [...ns, {
|
|
2761
|
+
id: newId,
|
|
2762
|
+
kind: normKind,
|
|
2763
|
+
x,
|
|
2764
|
+
y,
|
|
2765
|
+
label: defaultLabel,
|
|
2766
|
+
provider: prefs.provider || '',
|
|
2767
|
+
model: prefs.model || '',
|
|
2768
|
+
reasoning: prefs.reasoning || '',
|
|
2769
|
+
preset: normKind === 'condition' ? 'minimal' : (prefs.preset || 'standard'),
|
|
2770
|
+
role: '',
|
|
2771
|
+
}];
|
|
2772
|
+
});
|
|
2773
|
+
setEdges((es) => {
|
|
2774
|
+
const kept = es.filter((e) => e.id !== edgeId);
|
|
2775
|
+
const e1 = {
|
|
2776
|
+
id: 'e' + Date.now().toString(36) + 'a',
|
|
2777
|
+
from: edge.from,
|
|
2778
|
+
to: newId,
|
|
2779
|
+
type: edge.type || 'prompt',
|
|
2780
|
+
};
|
|
2781
|
+
if (edge.branch) e1.branch = edge.branch;
|
|
2782
|
+
const e2 = {
|
|
2783
|
+
id: 'e' + Date.now().toString(36) + 'b',
|
|
2784
|
+
from: newId,
|
|
2785
|
+
to: edge.to,
|
|
2786
|
+
type: 'prompt',
|
|
2787
|
+
};
|
|
2788
|
+
if (normKind === 'condition') e2.branch = 'true';
|
|
2789
|
+
return kept.concat([e1, e2]);
|
|
2790
|
+
});
|
|
2791
|
+
setSelectedIds([newId]);
|
|
2792
|
+
setCtxMenu(null);
|
|
2348
2793
|
};
|
|
2349
2794
|
|
|
2350
2795
|
const updateNode = (id, patch) => {
|
|
@@ -2386,40 +2831,40 @@ window.__ModuleLoader__.load({
|
|
|
2386
2831
|
};
|
|
2387
2832
|
|
|
2388
2833
|
const duplicateSelected = () => {
|
|
2389
|
-
const
|
|
2390
|
-
|
|
2391
|
-
const sources = curSel
|
|
2392
|
-
.filter((id) => id !== 'lead')
|
|
2393
|
-
.map((id) => curNodes.find((n) => n.id === id))
|
|
2394
|
-
.filter(Boolean);
|
|
2395
|
-
if (!sources.length) return;
|
|
2834
|
+
const { clones, clonedEdges } = cloneSelection(nodesRef.current, edgesRef.current, selectedIdsRef.current);
|
|
2835
|
+
if (!clones.length) return;
|
|
2396
2836
|
pushSnapshot();
|
|
2397
|
-
const stamp = Date.now().toString(36);
|
|
2398
|
-
const clones = sources.map((src, idx) => {
|
|
2399
|
-
const { runs: _runs, ...rest } = src;
|
|
2400
|
-
return {
|
|
2401
|
-
...rest,
|
|
2402
|
-
id: 'n' + stamp + '_' + idx + Math.random().toString(36).slice(2, 4),
|
|
2403
|
-
x: (src.x || 0) + 28,
|
|
2404
|
-
y: (src.y || 0) + 28,
|
|
2405
|
-
};
|
|
2406
|
-
});
|
|
2407
2837
|
setNodes((ns) => ns.concat(clones));
|
|
2838
|
+
if (clonedEdges.length) setEdges((es) => es.concat(clonedEdges));
|
|
2408
2839
|
setSelectedIds(clones.map((c) => c.id));
|
|
2409
2840
|
flash(t('duplicatedNodes') + ' ×' + clones.length);
|
|
2410
2841
|
};
|
|
2411
2842
|
|
|
2412
|
-
const autoLayout = () => {
|
|
2843
|
+
const autoLayout = (overrideDir) => {
|
|
2413
2844
|
const curNodes = nodesRef.current;
|
|
2414
2845
|
const curEdges = edgesRef.current;
|
|
2415
2846
|
if (!curNodes.length) return;
|
|
2847
|
+
const dir = overrideDir || directionRef.current;
|
|
2416
2848
|
pushSnapshot();
|
|
2417
|
-
const next = layoutGraph(curNodes, curEdges);
|
|
2849
|
+
const next = layoutGraph(curNodes, curEdges, dir);
|
|
2418
2850
|
setNodes(next);
|
|
2419
2851
|
setTimeout(() => fitView(next), 0);
|
|
2420
2852
|
flash(t('layoutDone'));
|
|
2421
2853
|
};
|
|
2422
2854
|
|
|
2855
|
+
const toggleDirection = () => {
|
|
2856
|
+
const nextDir = directionRef.current === 'tb' ? 'lr' : 'tb';
|
|
2857
|
+
setDirection(nextDir);
|
|
2858
|
+
const curNodes = nodesRef.current;
|
|
2859
|
+
const curEdges = edgesRef.current;
|
|
2860
|
+
if (curNodes.length) {
|
|
2861
|
+
pushSnapshot();
|
|
2862
|
+
const next = layoutGraph(curNodes, curEdges, nextDir);
|
|
2863
|
+
setNodes(next);
|
|
2864
|
+
setTimeout(() => fitView(next), 0);
|
|
2865
|
+
}
|
|
2866
|
+
};
|
|
2867
|
+
|
|
2423
2868
|
const clearCanvas = () => {
|
|
2424
2869
|
const blank = [{ id: 'lead', kind: 'lead', x: 40, y: 203, label: 'Lead', task: '', provider: '', model: '', role: '' }];
|
|
2425
2870
|
pushSnapshot();
|
|
@@ -2497,6 +2942,11 @@ window.__ModuleLoader__.load({
|
|
|
2497
2942
|
|
|
2498
2943
|
/** Dragging any selected node moves the whole selection together. */
|
|
2499
2944
|
const onNodeDown = (e, id) => {
|
|
2945
|
+
if (e.button === 2) {
|
|
2946
|
+
const tag = e.target && e.target.tagName;
|
|
2947
|
+
if (tag !== 'INPUT' && tag !== 'TEXTAREA') e.stopPropagation();
|
|
2948
|
+
return;
|
|
2949
|
+
}
|
|
2500
2950
|
if (e.button !== 0 || spaceDown.current) return;
|
|
2501
2951
|
if (!contentRef.current) return;
|
|
2502
2952
|
const node = nodes.find((n) => n.id === id);
|
|
@@ -2512,10 +2962,53 @@ window.__ModuleLoader__.load({
|
|
|
2512
2962
|
setDragging(true);
|
|
2513
2963
|
setOpenModelFor(null);
|
|
2514
2964
|
setAddMenu(null);
|
|
2965
|
+
setCtxMenu(null);
|
|
2515
2966
|
e.preventDefault();
|
|
2516
2967
|
e.stopPropagation();
|
|
2517
2968
|
};
|
|
2518
2969
|
|
|
2970
|
+
const onNodeContextMenu = (e, node) => {
|
|
2971
|
+
const tag = e.target && e.target.tagName;
|
|
2972
|
+
if (tag === 'INPUT' || tag === 'TEXTAREA') return;
|
|
2973
|
+
e.preventDefault();
|
|
2974
|
+
e.stopPropagation();
|
|
2975
|
+
rightClickRef.current = null;
|
|
2976
|
+
const wrap = canvasWrapRef.current;
|
|
2977
|
+
if (!wrap) return;
|
|
2978
|
+
if (!selectedIdsRef.current.includes(node.id)) setSelectedIds([node.id]);
|
|
2979
|
+
const wrapRect = wrap.getBoundingClientRect();
|
|
2980
|
+
const pos = clampMenuPos(e.clientX - wrapRect.left, e.clientY - wrapRect.top, wrapRect.width, wrapRect.height, 180, 176);
|
|
2981
|
+
const world = pointTo(e);
|
|
2982
|
+
setCtxMenu({ kind: 'node', nodeId: node.id, sx: pos.sx, sy: pos.sy, wx: world.x, wy: world.y });
|
|
2983
|
+
setAddMenu(null);
|
|
2984
|
+
setMenuOpen(false);
|
|
2985
|
+
setPresetOpen(null);
|
|
2986
|
+
setOpenModelFor(null);
|
|
2987
|
+
setRoleEditFor(null);
|
|
2988
|
+
setDecisionViewFor(null);
|
|
2989
|
+
setRefsEditFor(null);
|
|
2990
|
+
};
|
|
2991
|
+
|
|
2992
|
+
const addNodeRef = (node) => {
|
|
2993
|
+
const cur = Array.isArray(node.refs) ? node.refs.slice() : [];
|
|
2994
|
+
if (cur.length >= 16) return;
|
|
2995
|
+
pushSnapshot();
|
|
2996
|
+
updateNode(node.id, { refs: cur.concat(['']) });
|
|
2997
|
+
};
|
|
2998
|
+
|
|
2999
|
+
const updateNodeRef = (node, idx, text) => {
|
|
3000
|
+
const cur = Array.isArray(node.refs) ? node.refs.slice() : [];
|
|
3001
|
+
cur[idx] = text;
|
|
3002
|
+
updateNode(node.id, { refs: cur });
|
|
3003
|
+
};
|
|
3004
|
+
|
|
3005
|
+
const removeNodeRef = (node, idx) => {
|
|
3006
|
+
const cur = Array.isArray(node.refs) ? node.refs.slice() : [];
|
|
3007
|
+
pushSnapshot();
|
|
3008
|
+
cur.splice(idx, 1);
|
|
3009
|
+
updateNode(node.id, { refs: cur });
|
|
3010
|
+
};
|
|
3011
|
+
|
|
2519
3012
|
const addConditionBranch = (node) => {
|
|
2520
3013
|
const current = isCustomBranches(node)
|
|
2521
3014
|
? conditionBranchesForUI(node, lang).map((b) => ({ id: b.id, label: b.label }))
|
|
@@ -2560,8 +3053,9 @@ window.__ModuleLoader__.load({
|
|
|
2560
3053
|
const node = nodes.find((n) => n.id === id);
|
|
2561
3054
|
if (!node) return;
|
|
2562
3055
|
const b = typeof branch === 'string' ? branch.trim() : '';
|
|
2563
|
-
const
|
|
2564
|
-
const
|
|
3056
|
+
const pos = outputSocketPos(node, type, b, directionRef.current);
|
|
3057
|
+
const sx = pos.x;
|
|
3058
|
+
const sy = pos.y;
|
|
2565
3059
|
const color = edgeColorFor(node, { type, branch: b });
|
|
2566
3060
|
setPending({ dir: 'out', fromId: id, type, branch: b, color, sx, sy, x: sx, y: sy });
|
|
2567
3061
|
setDragging(true);
|
|
@@ -2604,8 +3098,9 @@ window.__ModuleLoader__.load({
|
|
|
2604
3098
|
if (!link) {
|
|
2605
3099
|
const node = nodes.find((n) => n.id === id);
|
|
2606
3100
|
if (!node) return;
|
|
2607
|
-
const
|
|
2608
|
-
const
|
|
3101
|
+
const pos = inputSocketPos(node, directionRef.current);
|
|
3102
|
+
const sx = pos.x;
|
|
3103
|
+
const sy = pos.y;
|
|
2609
3104
|
setPending({ dir: 'in', toId: id, type: 'prompt', branch: '', color: '#8a8f98', sx, sy, x: sx, y: sy });
|
|
2610
3105
|
setDragging(true);
|
|
2611
3106
|
return;
|
|
@@ -2616,8 +3111,9 @@ window.__ModuleLoader__.load({
|
|
|
2616
3111
|
if (!from) return;
|
|
2617
3112
|
const b = typeof link.branch === 'string' ? link.branch.trim() : '';
|
|
2618
3113
|
const linkType = link.type || 'prompt';
|
|
2619
|
-
const
|
|
2620
|
-
const
|
|
3114
|
+
const pos = outputSocketPos(from, linkType, b, directionRef.current);
|
|
3115
|
+
const sx = pos.x;
|
|
3116
|
+
const sy = pos.y;
|
|
2621
3117
|
const color = edgeColorFor(from, link);
|
|
2622
3118
|
setPending({ dir: 'out', fromId: link.from, type: linkType, branch: b, color, sx, sy, x: sx, y: sy });
|
|
2623
3119
|
setDragging(true);
|
|
@@ -2704,12 +3200,12 @@ window.__ModuleLoader__.load({
|
|
|
2704
3200
|
};
|
|
2705
3201
|
}, []);
|
|
2706
3202
|
|
|
2707
|
-
//
|
|
3203
|
+
// Configurable canvas keyboard shortcuts (defaults: Shift+A, Shift+D, Delete, Ctrl+Z, Esc).
|
|
2708
3204
|
const keyActionsRef = useRef(null);
|
|
2709
3205
|
keyActionsRef.current = {
|
|
2710
|
-
undo, deleteSelected, duplicateSelected, openAddMenuAtCursor, addNode,
|
|
2711
|
-
addMenu, roleEditFor, openModelFor, menuOpen, presetOpen, helpOpen, decisionViewFor,
|
|
2712
|
-
setAddMenu, setRoleEditFor, setOpenModelFor, setMenuOpen, setPresetOpen, setHelpOpen, setDecisionViewFor,
|
|
3206
|
+
undo, deleteSelected, duplicateSelected, openAddMenuAtCursor, addNode, fitView, autoLayout, toggleDirection, flash, t,
|
|
3207
|
+
addMenu, ctxMenu, roleEditFor, openModelFor, menuOpen, presetOpen, helpOpen, shortcutsOpen, recordingAction, decisionViewFor, refsEditFor,
|
|
3208
|
+
setAddMenu, setCtxMenu, setRoleEditFor, setOpenModelFor, setMenuOpen, setPresetOpen, setHelpOpen, setShortcutsOpen, setRecordingAction, setShortcuts, setDecisionViewFor, setRefsEditFor,
|
|
2713
3209
|
};
|
|
2714
3210
|
useEffect(() => {
|
|
2715
3211
|
const isEditable = (target) => {
|
|
@@ -2720,19 +3216,41 @@ window.__ModuleLoader__.load({
|
|
|
2720
3216
|
const onKey = (ev) => {
|
|
2721
3217
|
const act = keyActionsRef.current;
|
|
2722
3218
|
if (!act) return;
|
|
3219
|
+
if (act.recordingAction) {
|
|
3220
|
+
ev.preventDefault();
|
|
3221
|
+
ev.stopPropagation();
|
|
3222
|
+
if (ev.key === 'Escape') {
|
|
3223
|
+
act.setRecordingAction(null);
|
|
3224
|
+
return;
|
|
3225
|
+
}
|
|
3226
|
+
const combo = formatShortcutFromEvent(ev);
|
|
3227
|
+
if (!combo) return;
|
|
3228
|
+
const { next, clearedConflict } = applyShortcutBinding(shortcutsRef.current, act.recordingAction, combo);
|
|
3229
|
+
shortcutsRef.current = next;
|
|
3230
|
+
saveShortcuts(next);
|
|
3231
|
+
act.setShortcuts(next);
|
|
3232
|
+
act.setRecordingAction(null);
|
|
3233
|
+
if (clearedConflict) act.flash(act.t('shortcutsConflict'));
|
|
3234
|
+
return;
|
|
3235
|
+
}
|
|
2723
3236
|
if (ev.key === 'Escape') {
|
|
2724
|
-
if (act.addMenu || act.roleEditFor || act.openModelFor || act.menuOpen || act.presetOpen || act.helpOpen || act.decisionViewFor) {
|
|
3237
|
+
if (act.addMenu || act.ctxMenu || act.roleEditFor || act.openModelFor || act.menuOpen || act.presetOpen || act.helpOpen || act.shortcutsOpen || act.decisionViewFor || act.refsEditFor) {
|
|
2725
3238
|
ev.preventDefault();
|
|
2726
3239
|
act.setAddMenu(null);
|
|
3240
|
+
act.setCtxMenu(null);
|
|
2727
3241
|
act.setRoleEditFor(null);
|
|
2728
3242
|
act.setOpenModelFor(null);
|
|
2729
3243
|
act.setMenuOpen(false);
|
|
2730
3244
|
act.setPresetOpen(null);
|
|
2731
3245
|
act.setHelpOpen(false);
|
|
3246
|
+
act.setShortcutsOpen(false);
|
|
3247
|
+
act.setRecordingAction(null);
|
|
2732
3248
|
act.setDecisionViewFor(null);
|
|
3249
|
+
act.setRefsEditFor(null);
|
|
2733
3250
|
}
|
|
2734
3251
|
return;
|
|
2735
3252
|
}
|
|
3253
|
+
if (act.shortcutsOpen) return;
|
|
2736
3254
|
if (isEditable(ev.target)) return;
|
|
2737
3255
|
if (act.addMenu) {
|
|
2738
3256
|
const lf = act.addMenu.linkFrom || null;
|
|
@@ -2755,23 +3273,41 @@ window.__ModuleLoader__.load({
|
|
|
2755
3273
|
const root = rootElRef.current;
|
|
2756
3274
|
const activeInRoot = Boolean(root && document.activeElement && root.contains(document.activeElement));
|
|
2757
3275
|
if (!pointerInsideRoot.current && !activeInRoot) return;
|
|
2758
|
-
const
|
|
2759
|
-
if (
|
|
3276
|
+
const sc = shortcutsRef.current || DEFAULT_SHORTCUTS;
|
|
3277
|
+
if (matchesShortcut(ev, sc.addNode)) {
|
|
2760
3278
|
ev.preventDefault();
|
|
2761
3279
|
act.openAddMenuAtCursor();
|
|
2762
3280
|
return;
|
|
2763
3281
|
}
|
|
2764
|
-
if (
|
|
3282
|
+
if (matchesShortcut(ev, sc.undo)) {
|
|
2765
3283
|
ev.preventDefault();
|
|
2766
3284
|
act.undo();
|
|
2767
3285
|
return;
|
|
2768
3286
|
}
|
|
2769
|
-
if (
|
|
3287
|
+
if (matchesShortcut(ev, sc.duplicate)) {
|
|
2770
3288
|
ev.preventDefault();
|
|
2771
3289
|
act.duplicateSelected();
|
|
2772
3290
|
return;
|
|
2773
3291
|
}
|
|
2774
|
-
if (
|
|
3292
|
+
if (matchesShortcut(ev, sc.fitView)) {
|
|
3293
|
+
ev.preventDefault();
|
|
3294
|
+
act.fitView();
|
|
3295
|
+
return;
|
|
3296
|
+
}
|
|
3297
|
+
if (matchesShortcut(ev, sc.autoLayout)) {
|
|
3298
|
+
ev.preventDefault();
|
|
3299
|
+
act.autoLayout();
|
|
3300
|
+
return;
|
|
3301
|
+
}
|
|
3302
|
+
if (matchesShortcut(ev, sc.toggleDir)) {
|
|
3303
|
+
ev.preventDefault();
|
|
3304
|
+
act.toggleDirection();
|
|
3305
|
+
return;
|
|
3306
|
+
}
|
|
3307
|
+
const allBound = Object.values(sc).map(normalizeShortcut);
|
|
3308
|
+
const delHit = matchesShortcut(ev, sc.delete)
|
|
3309
|
+
|| (normalizeShortcut(sc.delete) === 'Delete' && !allBound.includes('Backspace') && matchesShortcut(ev, 'Backspace'));
|
|
3310
|
+
if (delHit) {
|
|
2775
3311
|
if (selectedIdsRef.current.length) {
|
|
2776
3312
|
ev.preventDefault();
|
|
2777
3313
|
act.deleteSelected();
|
|
@@ -2782,32 +3318,6 @@ window.__ModuleLoader__.load({
|
|
|
2782
3318
|
return () => window.removeEventListener('keydown', onKey);
|
|
2783
3319
|
}, []);
|
|
2784
3320
|
|
|
2785
|
-
// Suppress the host context menu over the canvas while cutting is on.
|
|
2786
|
-
useEffect(() => {
|
|
2787
|
-
if (!cutMode) return undefined;
|
|
2788
|
-
const inside = (ev) => {
|
|
2789
|
-
const el = canvasElRef.current;
|
|
2790
|
-
return Boolean(el) && ev.target instanceof Node && el.contains(ev.target);
|
|
2791
|
-
};
|
|
2792
|
-
const onCtx = (ev) => { if (inside(ev)) ev.preventDefault(); };
|
|
2793
|
-
const onDown = (ev) => {
|
|
2794
|
-
if (ev.button !== 2 || !inside(ev) || ev.target.closest('[data-node]')) return;
|
|
2795
|
-
ev.preventDefault();
|
|
2796
|
-
const start = pointTo(ev);
|
|
2797
|
-
cutRef.current = start;
|
|
2798
|
-
cutHits.current = new Set();
|
|
2799
|
-
setCutPath([start]);
|
|
2800
|
-
setCutVictims([]);
|
|
2801
|
-
setDragging(true);
|
|
2802
|
-
};
|
|
2803
|
-
window.addEventListener('contextmenu', onCtx, true);
|
|
2804
|
-
window.addEventListener('mousedown', onDown, true);
|
|
2805
|
-
return () => {
|
|
2806
|
-
window.removeEventListener('contextmenu', onCtx, true);
|
|
2807
|
-
window.removeEventListener('mousedown', onDown, true);
|
|
2808
|
-
};
|
|
2809
|
-
}, [cutMode, sessionId]);
|
|
2810
|
-
|
|
2811
3321
|
useEffect(() => {
|
|
2812
3322
|
if (!dragging) return undefined;
|
|
2813
3323
|
const move = (ev) => onCanvasMove(ev);
|
|
@@ -2822,22 +3332,20 @@ window.__ModuleLoader__.load({
|
|
|
2822
3332
|
|
|
2823
3333
|
const onCanvasDown = (e) => {
|
|
2824
3334
|
if (e.button === 2) {
|
|
2825
|
-
if (!cutMode) return;
|
|
2826
3335
|
e.preventDefault();
|
|
2827
3336
|
try { window.getSelection().removeAllRanges(); } catch (_sel) { /* ignore */ }
|
|
2828
3337
|
const start = pointTo(e);
|
|
2829
|
-
|
|
2830
|
-
cutHits.current = new Set();
|
|
2831
|
-
setCutPath([start]);
|
|
2832
|
-
setCutVictims([]);
|
|
3338
|
+
rightClickRef.current = { clientX: e.clientX, clientY: e.clientY, start, moved: false };
|
|
2833
3339
|
setDragging(true);
|
|
2834
3340
|
return;
|
|
2835
3341
|
}
|
|
2836
3342
|
if (e.button !== 0) return;
|
|
2837
3343
|
if (roleEditFor) setRoleEditFor(null);
|
|
2838
3344
|
if (decisionViewFor) setDecisionViewFor(null);
|
|
3345
|
+
if (refsEditFor) setRefsEditFor(null);
|
|
2839
3346
|
if (menuOpen) setMenuOpen(false);
|
|
2840
3347
|
if (addMenu) setAddMenu(null);
|
|
3348
|
+
if (ctxMenu) setCtxMenu(null);
|
|
2841
3349
|
if (presetOpen) setPresetOpen(null);
|
|
2842
3350
|
e.preventDefault();
|
|
2843
3351
|
try { window.getSelection().removeAllRanges(); } catch (_sel) { /* ignore */ }
|
|
@@ -2856,6 +3364,17 @@ window.__ModuleLoader__.load({
|
|
|
2856
3364
|
commitView({ k: viewRef.current.k, x: pan.originX + dx, y: pan.originY + dy });
|
|
2857
3365
|
return;
|
|
2858
3366
|
}
|
|
3367
|
+
if (rightClickRef.current && !rightClickRef.current.moved) {
|
|
3368
|
+
if (Math.hypot(e.clientX - rightClickRef.current.clientX, e.clientY - rightClickRef.current.clientY) >= 6) {
|
|
3369
|
+
rightClickRef.current.moved = true;
|
|
3370
|
+
if (cutMode) {
|
|
3371
|
+
cutRef.current = rightClickRef.current.start;
|
|
3372
|
+
cutHits.current = new Set();
|
|
3373
|
+
setCutPath([rightClickRef.current.start]);
|
|
3374
|
+
setCutVictims([]);
|
|
3375
|
+
}
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
2859
3378
|
if (nodeDrag.current) {
|
|
2860
3379
|
const p = pointTo(e);
|
|
2861
3380
|
const drag = nodeDrag.current;
|
|
@@ -2884,7 +3403,7 @@ window.__ModuleLoader__.load({
|
|
|
2884
3403
|
const source = nodeMap.get(edge.from);
|
|
2885
3404
|
const target = nodeMap.get(edge.to);
|
|
2886
3405
|
if (!source || !target) continue;
|
|
2887
|
-
if (distanceToEdge(canvasSpot, source, target, edge) <= threshold) {
|
|
3406
|
+
if (distanceToEdge(canvasSpot, source, target, edge, directionRef.current) <= threshold) {
|
|
2888
3407
|
cutHits.current.add(edge.id);
|
|
2889
3408
|
}
|
|
2890
3409
|
}
|
|
@@ -2905,6 +3424,49 @@ window.__ModuleLoader__.load({
|
|
|
2905
3424
|
};
|
|
2906
3425
|
|
|
2907
3426
|
const onCanvasUp = (ev) => {
|
|
3427
|
+
if (rightClickRef.current) {
|
|
3428
|
+
const rc = rightClickRef.current;
|
|
3429
|
+
rightClickRef.current = null;
|
|
3430
|
+
if (!rc.moved) {
|
|
3431
|
+
const wrap = canvasWrapRef.current;
|
|
3432
|
+
if (wrap) {
|
|
3433
|
+
const wrapRect = wrap.getBoundingClientRect();
|
|
3434
|
+
const cx = rc.clientX - wrapRect.left;
|
|
3435
|
+
const cy = rc.clientY - wrapRect.top;
|
|
3436
|
+
const canvasSpot = { x: rc.start.x + WORLD_PAD, y: rc.start.y + WORLD_PAD };
|
|
3437
|
+
const threshold = Math.max(10, 14 / (viewRef.current.k || 1));
|
|
3438
|
+
const nodeMap = new Map(nodesRef.current.map((n) => [n.id, n]));
|
|
3439
|
+
let hitEdge = null;
|
|
3440
|
+
let bestDist = Infinity;
|
|
3441
|
+
for (const edge of edgesRef.current) {
|
|
3442
|
+
const source = nodeMap.get(edge.from);
|
|
3443
|
+
const target = nodeMap.get(edge.to);
|
|
3444
|
+
if (!source || !target) continue;
|
|
3445
|
+
const dist = distanceToEdge(canvasSpot, source, target, edge, directionRef.current);
|
|
3446
|
+
if (dist <= threshold && dist < bestDist) {
|
|
3447
|
+
bestDist = dist;
|
|
3448
|
+
hitEdge = edge;
|
|
3449
|
+
}
|
|
3450
|
+
}
|
|
3451
|
+
setAddMenu(null);
|
|
3452
|
+
setMenuOpen(false);
|
|
3453
|
+
setPresetOpen(null);
|
|
3454
|
+
setOpenModelFor(null);
|
|
3455
|
+
setRoleEditFor(null);
|
|
3456
|
+
setDecisionViewFor(null);
|
|
3457
|
+
setRefsEditFor(null);
|
|
3458
|
+
if (hitEdge) {
|
|
3459
|
+
const pos = clampMenuPos(cx, cy, wrapRect.width, wrapRect.height, 180, 120);
|
|
3460
|
+
setCtxMenu({ kind: 'edge', edgeId: hitEdge.id, sx: pos.sx, sy: pos.sy, wx: rc.start.x, wy: rc.start.y });
|
|
3461
|
+
} else {
|
|
3462
|
+
const pos = clampMenuPos(cx, cy, wrapRect.width, wrapRect.height, 186, 296);
|
|
3463
|
+
setCtxMenu({ kind: 'canvas', sx: pos.sx, sy: pos.sy, wx: rc.start.x, wy: rc.start.y });
|
|
3464
|
+
}
|
|
3465
|
+
}
|
|
3466
|
+
setDragging(false);
|
|
3467
|
+
return;
|
|
3468
|
+
}
|
|
3469
|
+
}
|
|
2908
3470
|
if (cutRef.current) {
|
|
2909
3471
|
cutRef.current = null;
|
|
2910
3472
|
setDragging(false);
|
|
@@ -2999,33 +3561,56 @@ window.__ModuleLoader__.load({
|
|
|
2999
3561
|
const byId = new Map(existing.map((n) => [n.id, n]));
|
|
3000
3562
|
const placed = new Map(existing.map((n) => [n.id, { x: n.x, y: n.y }]));
|
|
3001
3563
|
let addedCount = 0;
|
|
3564
|
+
const isTB = directionRef.current === 'tb';
|
|
3002
3565
|
const incoming = doc.nodes.map((n, i) => {
|
|
3003
3566
|
const prev = byId.get(n.id) || {};
|
|
3004
3567
|
let x = typeof n.x === 'number' ? n.x : prev.x;
|
|
3005
3568
|
let y = typeof n.y === 'number' ? n.y : prev.y;
|
|
3006
3569
|
if (typeof x !== 'number' || typeof y !== 'number') {
|
|
3007
|
-
// Place a newly patched node
|
|
3570
|
+
// Place a newly patched node downstream of its first upstream node,
|
|
3571
|
+
// respecting the active horizontal (lr) or vertical (tb) flow direction.
|
|
3008
3572
|
const parentEdge = rawIncomingEdges.find((e) => e && e.to === n.id && placed.has(e.from));
|
|
3009
3573
|
if (parentEdge) {
|
|
3010
3574
|
const parentPos = placed.get(parentEdge.from);
|
|
3011
|
-
const
|
|
3012
|
-
|
|
3013
|
-
|
|
3575
|
+
const parentNode = byId.get(parentEdge.from);
|
|
3576
|
+
if (isTB) {
|
|
3577
|
+
const targetY = parentPos.y + nodeHeight(parentNode) + 68;
|
|
3578
|
+
const siblingCount = Array.from(placed.values()).filter((p) => Math.abs(p.y - targetY) < 40).length;
|
|
3579
|
+
x = parentPos.x + siblingCount * 292;
|
|
3580
|
+
y = targetY;
|
|
3581
|
+
} else {
|
|
3582
|
+
const siblingCount = Array.from(placed.values()).filter((p) => Math.abs(p.x - (parentPos.x + 300)) < 40).length;
|
|
3583
|
+
x = parentPos.x + 300;
|
|
3584
|
+
y = parentPos.y + siblingCount * 240;
|
|
3585
|
+
}
|
|
3014
3586
|
} else {
|
|
3015
3587
|
const leadPos = placed.get('lead') || { x: 40, y: 80 };
|
|
3016
|
-
|
|
3017
|
-
|
|
3588
|
+
if (isTB) {
|
|
3589
|
+
x = merge ? leadPos.x + addedCount * 292 : 40 + i * 292;
|
|
3590
|
+
y = merge ? leadPos.y + NODE_H + 68 : 80;
|
|
3591
|
+
} else {
|
|
3592
|
+
x = merge ? leadPos.x + 300 : 60 + i * 300;
|
|
3593
|
+
y = merge ? leadPos.y + (addedCount + 1) * 240 : 80;
|
|
3594
|
+
}
|
|
3018
3595
|
}
|
|
3019
3596
|
addedCount += 1;
|
|
3020
3597
|
}
|
|
3021
3598
|
placed.set(n.id, { x, y });
|
|
3022
3599
|
return { ...prev, ...n, x, y };
|
|
3023
3600
|
});
|
|
3024
|
-
if (!merge)
|
|
3601
|
+
if (!merge) {
|
|
3602
|
+
return isTB ? layoutGraph(incoming, rawIncomingEdges, 'tb') : incoming;
|
|
3603
|
+
}
|
|
3025
3604
|
const touched = new Set(incoming.map((n) => n.id));
|
|
3026
3605
|
const kept = existing
|
|
3027
3606
|
.filter((n) => !touched.has(n.id) && !removedNodes.has(n.id))
|
|
3028
|
-
.map((n) =>
|
|
3607
|
+
.map((n) => {
|
|
3608
|
+
if (n.id !== 'lead') return n;
|
|
3609
|
+
const patch = {};
|
|
3610
|
+
if (typeof doc.task === 'string') patch.task = doc.task;
|
|
3611
|
+
if (Array.isArray(doc.refs)) patch.refs = doc.refs;
|
|
3612
|
+
return Object.keys(patch).length ? { ...n, ...patch } : n;
|
|
3613
|
+
});
|
|
3029
3614
|
return kept.concat(incoming);
|
|
3030
3615
|
});
|
|
3031
3616
|
setEdges((existing) => {
|
|
@@ -3300,7 +3885,7 @@ window.__ModuleLoader__.load({
|
|
|
3300
3885
|
if (models.length === 1) {
|
|
3301
3886
|
rows.push(h('div', { key: 'single-hint', style: S.presetEmpty }, t('singleModelHint')));
|
|
3302
3887
|
}
|
|
3303
|
-
|
|
3888
|
+
return h('div', { ref: isOpen ? dropdownRef : undefined, style: { position: 'relative', flex: '1 1 auto', minWidth: 0 } },
|
|
3304
3889
|
h('button', {
|
|
3305
3890
|
style: S.selectBtn,
|
|
3306
3891
|
type: 'button',
|
|
@@ -3346,7 +3931,7 @@ window.__ModuleLoader__.load({
|
|
|
3346
3931
|
}, t('memLatestOpt')),
|
|
3347
3932
|
...history.map((item) => {
|
|
3348
3933
|
const selectedRow = node.memoryChildId === item.childId;
|
|
3349
|
-
|
|
3934
|
+
return h('div', {
|
|
3350
3935
|
key: item.childId,
|
|
3351
3936
|
style: selectedRow ? { ...S.menuRow, background: C.hover, color: C.accent } : S.menuRow,
|
|
3352
3937
|
title: item.childId,
|
|
@@ -3357,7 +3942,7 @@ window.__ModuleLoader__.load({
|
|
|
3357
3942
|
}),
|
|
3358
3943
|
!history.length && h('div', { key: 'mem-empty', style: S.presetEmpty }, t('memEmpty')),
|
|
3359
3944
|
];
|
|
3360
|
-
|
|
3945
|
+
return h('div', { style: { display: 'flex', alignItems: 'center', gap: '4px', flex: '1 1 auto', minWidth: 0 } },
|
|
3361
3946
|
toggleBtn,
|
|
3362
3947
|
h('div', { ref: isOpen ? dropdownRef : undefined, style: { position: 'relative', flex: '0 0 64px', width: '64px' } },
|
|
3363
3948
|
h('button', {
|
|
@@ -3397,7 +3982,7 @@ window.__ModuleLoader__.load({
|
|
|
3397
3982
|
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
3398
3983
|
onClick: () => { updateNode(node.id, { reasoning: id }); setOpenModelFor(null); },
|
|
3399
3984
|
}, labelOf(id)));
|
|
3400
|
-
|
|
3985
|
+
return h('div', { ref: isOpen ? dropdownRef : undefined, style: { position: 'relative', flex: '1 1 auto', minWidth: 0 } },
|
|
3401
3986
|
h('button', {
|
|
3402
3987
|
style: S.selectBtn,
|
|
3403
3988
|
type: 'button',
|
|
@@ -3454,7 +4039,7 @@ window.__ModuleLoader__.load({
|
|
|
3454
4039
|
onClick: () => { updateNode(node.id, { provider: m.provider, model: m.model }); setOpenModelFor(null); },
|
|
3455
4040
|
}, m.modelName || m.model));
|
|
3456
4041
|
}
|
|
3457
|
-
|
|
4042
|
+
return h('div', { ref: isOpen ? dropdownRef : undefined, style: { position: 'relative', flex: '1 1 auto', minWidth: 0 } },
|
|
3458
4043
|
h('button', {
|
|
3459
4044
|
style: S.selectBtn,
|
|
3460
4045
|
type: 'button',
|
|
@@ -3504,8 +4089,18 @@ window.__ModuleLoader__.load({
|
|
|
3504
4089
|
const leadDoneIds = new Set();
|
|
3505
4090
|
const hasCondNode = nodes.some((x) => x.kind === 'condition');
|
|
3506
4091
|
if (enabled) {
|
|
4092
|
+
if (runState && runState.waitingLead && runState.waitingLead.id) {
|
|
4093
|
+
leadReadyIds.add(runState.waitingLead.id);
|
|
4094
|
+
}
|
|
4095
|
+
if (runState && Array.isArray(runState.done)) {
|
|
4096
|
+
for (const did of runState.done) {
|
|
4097
|
+
const dn = nodeById.get(did);
|
|
4098
|
+
if (dn && dn.kind === 'lead' && dn.id !== 'lead') leadDoneIds.add(did);
|
|
4099
|
+
}
|
|
4100
|
+
}
|
|
3507
4101
|
for (const n of nodes) {
|
|
3508
4102
|
if (n.kind !== 'lead' || n.id === 'lead' || !reachableIds.has(n.id)) continue;
|
|
4103
|
+
if (leadReadyIds.has(n.id) || leadDoneIds.has(n.id)) continue;
|
|
3509
4104
|
const upIds = edges
|
|
3510
4105
|
.filter((e) => e.to === n.id && e.from !== 'lead' && nodeById.has(e.from))
|
|
3511
4106
|
.map((e) => e.from);
|
|
@@ -3541,7 +4136,7 @@ window.__ModuleLoader__.load({
|
|
|
3541
4136
|
const to = nodeById.get(edge.to);
|
|
3542
4137
|
if (!from || !to) return null;
|
|
3543
4138
|
const color = edgeColorFor(from, edge);
|
|
3544
|
-
const d = edgePath(from, to, edge);
|
|
4139
|
+
const d = edgePath(from, to, edge, direction);
|
|
3545
4140
|
const highlighted = cutVictims.includes(edge.id);
|
|
3546
4141
|
const isPrunedEdge = !highlighted && (blockedEdgeSet.has(edgeKeyForState(edge)) || prunedSet.has(edge.from) || prunedSet.has(edge.to));
|
|
3547
4142
|
const hasSel = selectedSet.size > 0;
|
|
@@ -3631,14 +4226,16 @@ window.__ModuleLoader__.load({
|
|
|
3631
4226
|
|
|
3632
4227
|
const renderBand = (node) => {
|
|
3633
4228
|
const isEntry = node.id === 'lead';
|
|
4229
|
+
const isTB = direction === 'tb';
|
|
3634
4230
|
const inColor = inColorByNode.get(node.id) || null;
|
|
3635
4231
|
const inCount = inCountByNode.get(node.id) || 0;
|
|
3636
4232
|
const inText = inCount > 1 ? 'in ×' + inCount : 'in';
|
|
4233
|
+
const bandH = nodeHeight(node) - SOCKET_BAND_TOP;
|
|
3637
4234
|
const unifiedInSocket = !isEntry && h('div', {
|
|
3638
4235
|
style: {
|
|
3639
4236
|
...S.socket,
|
|
3640
|
-
top: (ROW_H - PORT) / 2,
|
|
3641
|
-
left: -PORT / 2,
|
|
4237
|
+
top: isTB ? (-SOCKET_BAND_TOP - PORT / 2) : ((ROW_H - PORT) / 2),
|
|
4238
|
+
left: isTB ? (NODE_W / 2 - PORT / 2) : (-PORT / 2),
|
|
3642
4239
|
borderColor: inColor || C.border,
|
|
3643
4240
|
background: inColor || C.elevated,
|
|
3644
4241
|
boxShadow: inColor
|
|
@@ -3653,9 +4250,10 @@ window.__ModuleLoader__.load({
|
|
|
3653
4250
|
const branches = conditionBranchesForUI(node, lang);
|
|
3654
4251
|
const condDec = decisionsById[node.id] || null;
|
|
3655
4252
|
const matchedBranchIds = condDec && Array.isArray(condDec.branches) ? new Set(condDec.branches) : null;
|
|
3656
|
-
|
|
4253
|
+
const onLeft = isTB && node.tbSide === 'left';
|
|
4254
|
+
return h('div', { style: S.band },
|
|
3657
4255
|
unifiedInSocket,
|
|
3658
|
-
h('span', { style: { ...S.rowLabel, position: 'absolute', left: '12px', top: '3px', pointerEvents: 'none' } }, inText),
|
|
4256
|
+
!isTB && h('span', { style: { ...S.rowLabel, position: 'absolute', left: '12px', top: '3px', pointerEvents: 'none' } }, inText),
|
|
3659
4257
|
branches.map((b) => {
|
|
3660
4258
|
const outLinked = connectedOut.has(node.id + '|branch:' + b.id);
|
|
3661
4259
|
const isMatchedBranch = Boolean(matchedBranchIds && matchedBranchIds.has(b.id));
|
|
@@ -3664,40 +4262,52 @@ window.__ModuleLoader__.load({
|
|
|
3664
4262
|
? (b.id === 'true' ? t('tipCondTrue') : t('tipCondFalse'))
|
|
3665
4263
|
: t('tipBranchOut');
|
|
3666
4264
|
const editKey = 'branch:' + node.id + ':' + b.id;
|
|
3667
|
-
|
|
4265
|
+
return h('div', {
|
|
4266
|
+
key: b.id,
|
|
4267
|
+
style: {
|
|
4268
|
+
...S.condBranchRow,
|
|
4269
|
+
justifyContent: onLeft ? 'flex-start' : 'flex-end',
|
|
4270
|
+
opacity: isUnmatchedBranch ? 0.48 : 1,
|
|
4271
|
+
},
|
|
4272
|
+
},
|
|
3668
4273
|
h('div', {
|
|
3669
|
-
style: {
|
|
4274
|
+
style: {
|
|
4275
|
+
display: 'flex',
|
|
4276
|
+
alignItems: 'center',
|
|
4277
|
+
marginLeft: onLeft ? '10px' : 0,
|
|
4278
|
+
marginRight: onLeft ? 0 : '10px',
|
|
4279
|
+
gap: '2px',
|
|
4280
|
+
},
|
|
3670
4281
|
onMouseDown: (e) => e.stopPropagation(),
|
|
3671
4282
|
},
|
|
3672
|
-
h('button', {
|
|
3673
|
-
type: 'button',
|
|
3674
|
-
style: S.condBranchExpand,
|
|
3675
|
-
title: t('tipExpandBranch'),
|
|
3676
|
-
onMouseEnter: (e) => { e.currentTarget.style.color = C.text; e.currentTarget.style.borderColor = b.color; },
|
|
3677
|
-
onMouseLeave: (e) => { e.currentTarget.style.color = C.dim; e.currentTarget.style.borderColor = C.border; },
|
|
3678
|
-
onClick: () => setRoleEditFor(roleEditFor === editKey ? null : editKey),
|
|
3679
|
-
}, '⤢'),
|
|
3680
4283
|
h('input', {
|
|
3681
4284
|
style: {
|
|
3682
4285
|
...S.condBranchInput,
|
|
3683
|
-
|
|
4286
|
+
textAlign: onLeft ? 'left' : 'right',
|
|
3684
4287
|
borderColor: isMatchedBranch ? b.color : C.border,
|
|
4288
|
+
...(onLeft ? { borderLeft: '2px solid ' + b.color } : { borderRight: '2px solid ' + b.color }),
|
|
3685
4289
|
},
|
|
3686
4290
|
value: b.label,
|
|
3687
4291
|
placeholder: t('branchPh'),
|
|
3688
4292
|
onFocus: () => setSelectedIds([node.id]),
|
|
3689
4293
|
onChange: (e) => renameConditionBranch(node, b.id, e.target.value),
|
|
3690
4294
|
}),
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
:
|
|
4295
|
+
h('button', {
|
|
4296
|
+
type: 'button',
|
|
4297
|
+
style: { ...S.condBranchExpand, marginRight: 0 },
|
|
4298
|
+
title: t('tipExpandBranch'),
|
|
4299
|
+
onMouseEnter: (e) => { e.currentTarget.style.color = C.text; e.currentTarget.style.borderColor = b.color; },
|
|
4300
|
+
onMouseLeave: (e) => { e.currentTarget.style.color = C.dim; e.currentTarget.style.borderColor = C.border; },
|
|
4301
|
+
onClick: () => setRoleEditFor(roleEditFor === editKey ? null : editKey),
|
|
4302
|
+
}, '⤢'),
|
|
4303
|
+
branches.length > 2 && h('button', {
|
|
4304
|
+
type: 'button',
|
|
4305
|
+
style: { ...S.condBranchDel, marginLeft: 0 },
|
|
4306
|
+
title: t('delBranchTip'),
|
|
4307
|
+
onMouseEnter: (e) => { e.currentTarget.style.color = '#e5534b'; },
|
|
4308
|
+
onMouseLeave: (e) => { e.currentTarget.style.color = C.dim; },
|
|
4309
|
+
onClick: () => removeConditionBranch(node, b.id),
|
|
4310
|
+
}, '×'),
|
|
3701
4311
|
),
|
|
3702
4312
|
roleEditFor === editKey && h('div', {
|
|
3703
4313
|
style: { ...S.rolePopover, top: '-8px' },
|
|
@@ -3721,7 +4331,7 @@ window.__ModuleLoader__.load({
|
|
|
3721
4331
|
style: {
|
|
3722
4332
|
...S.socket,
|
|
3723
4333
|
top: (COND_ROW_H - PORT) / 2,
|
|
3724
|
-
right: -PORT / 2,
|
|
4334
|
+
...(onLeft ? { left: -PORT / 2 } : { right: -PORT / 2 }),
|
|
3725
4335
|
borderColor: b.color,
|
|
3726
4336
|
background: outLinked ? b.color : C.elevated,
|
|
3727
4337
|
boxShadow: outLinked
|
|
@@ -3736,12 +4346,49 @@ window.__ModuleLoader__.load({
|
|
|
3736
4346
|
}),
|
|
3737
4347
|
);
|
|
3738
4348
|
}
|
|
4349
|
+
if (isTB) {
|
|
4350
|
+
return h('div', { style: S.band },
|
|
4351
|
+
unifiedInSocket,
|
|
4352
|
+
SOCKET_TYPES.map((sock) => {
|
|
4353
|
+
const outLinked = connectedOut.has(node.id + '|' + sock.id);
|
|
4354
|
+
const sx = outputSocketX(node, sock.id);
|
|
4355
|
+
return h(React.Fragment, { key: sock.id },
|
|
4356
|
+
h('span', {
|
|
4357
|
+
style: {
|
|
4358
|
+
...S.rowLabel,
|
|
4359
|
+
position: 'absolute',
|
|
4360
|
+
left: sx + 'px',
|
|
4361
|
+
top: (bandH - 23) + 'px',
|
|
4362
|
+
transform: 'translateX(-50%)',
|
|
4363
|
+
pointerEvents: 'none',
|
|
4364
|
+
whiteSpace: 'nowrap',
|
|
4365
|
+
},
|
|
4366
|
+
}, sock.label),
|
|
4367
|
+
h('div', {
|
|
4368
|
+
style: {
|
|
4369
|
+
...S.socket,
|
|
4370
|
+
top: bandH - PORT / 2,
|
|
4371
|
+
left: sx - PORT / 2,
|
|
4372
|
+
borderColor: sock.color,
|
|
4373
|
+
background: outLinked ? sock.color : C.elevated,
|
|
4374
|
+
boxShadow: outLinked
|
|
4375
|
+
? (fxLevel === 'vivid' ? '0 0 6px ' + sock.color : '0 0 0 2px ' + C.elevated)
|
|
4376
|
+
: '0 0 0 3px transparent',
|
|
4377
|
+
},
|
|
4378
|
+
title: t('tipSocketIn'),
|
|
4379
|
+
onMouseDown: (e) => onOutputDown(e, node.id, sock.id),
|
|
4380
|
+
onMouseUp: (e) => onOutputUp(e, node.id, sock.id),
|
|
4381
|
+
}),
|
|
4382
|
+
);
|
|
4383
|
+
}),
|
|
4384
|
+
);
|
|
4385
|
+
}
|
|
3739
4386
|
return h('div', { style: S.band },
|
|
3740
4387
|
unifiedInSocket,
|
|
3741
4388
|
!isEntry && h('span', { style: { ...S.rowLabel, position: 'absolute', left: '12px', top: '3px', pointerEvents: 'none' } }, inText),
|
|
3742
4389
|
SOCKET_TYPES.map((sock) => {
|
|
3743
4390
|
const outLinked = connectedOut.has(node.id + '|' + sock.id);
|
|
3744
|
-
|
|
4391
|
+
return h('div', { key: sock.id, style: S.row },
|
|
3745
4392
|
h('span', { style: { ...S.rowLabel, position: 'absolute', right: '12px' } }, sock.label),
|
|
3746
4393
|
h('div', {
|
|
3747
4394
|
style: {
|
|
@@ -3777,6 +4424,84 @@ window.__ModuleLoader__.load({
|
|
|
3777
4424
|
.map((n) => n.id);
|
|
3778
4425
|
};
|
|
3779
4426
|
|
|
4427
|
+
/** Compact "+ 参考" trigger docked cleanly in the top-right of every node header bar. */
|
|
4428
|
+
const refsControlBtn = (node) => {
|
|
4429
|
+
const count = normalizeRefsUI(node.refs).length;
|
|
4430
|
+
const isOpen = refsEditFor === node.id;
|
|
4431
|
+
return h('button', {
|
|
4432
|
+
type: 'button',
|
|
4433
|
+
style: {
|
|
4434
|
+
...(count > 0 || isOpen ? S.condModeBtnOn : S.condAddBtn),
|
|
4435
|
+
position: 'absolute',
|
|
4436
|
+
top: '9px',
|
|
4437
|
+
right: '10px',
|
|
4438
|
+
zIndex: 7,
|
|
4439
|
+
whiteSpace: 'nowrap',
|
|
4440
|
+
flex: '0 0 auto',
|
|
4441
|
+
},
|
|
4442
|
+
title: t('tipRefs'),
|
|
4443
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
4444
|
+
onClick: (e) => {
|
|
4445
|
+
e.stopPropagation();
|
|
4446
|
+
setRoleEditFor(null);
|
|
4447
|
+
setRefsEditFor(isOpen ? null : node.id);
|
|
4448
|
+
},
|
|
4449
|
+
}, count > 0 ? (t('refsBtn') + '×' + count) : ('+ ' + t('refsBtn')));
|
|
4450
|
+
};
|
|
4451
|
+
|
|
4452
|
+
const refsPopoverEl = (node) => {
|
|
4453
|
+
if (refsEditFor !== node.id) return null;
|
|
4454
|
+
const list = Array.isArray(node.refs) ? node.refs : [];
|
|
4455
|
+
const isGlobal = node.id === 'lead';
|
|
4456
|
+
return h('div', {
|
|
4457
|
+
style: S.refsPopover,
|
|
4458
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
4459
|
+
},
|
|
4460
|
+
h('div', {
|
|
4461
|
+
style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: '6px', fontSize: '10px', fontWeight: 600, color: C.dim },
|
|
4462
|
+
},
|
|
4463
|
+
h('span', null, (isGlobal ? t('refsTitleGlobal') : t('refsTitleNode')) + ' (' + list.length + '/16)'),
|
|
4464
|
+
h('button', {
|
|
4465
|
+
type: 'button',
|
|
4466
|
+
style: { background: 'transparent', border: 'none', color: C.dim, cursor: 'pointer', fontSize: '12px', padding: '0 2px' },
|
|
4467
|
+
onClick: () => setRefsEditFor(null),
|
|
4468
|
+
}, '×'),
|
|
4469
|
+
),
|
|
4470
|
+
list.length === 0
|
|
4471
|
+
? h('div', { style: { fontSize: '10px', color: C.dim, marginBottom: '6px', lineHeight: '1.4' } }, t('refsEmpty'))
|
|
4472
|
+
: h('div', { style: { maxHeight: '168px', overflowY: 'auto', marginBottom: '4px' } },
|
|
4473
|
+
list.map((val, idx) => h('div', { key: 'ref-' + idx, style: S.refsRow },
|
|
4474
|
+
h('input', {
|
|
4475
|
+
style: S.refsInput,
|
|
4476
|
+
value: typeof val === 'string' ? val : '',
|
|
4477
|
+
placeholder: t('refsPh'),
|
|
4478
|
+
autoFocus: idx === list.length - 1 && val === '',
|
|
4479
|
+
onKeyDown: (e) => {
|
|
4480
|
+
if (e.key === 'Enter' && list.length < 16) {
|
|
4481
|
+
e.preventDefault();
|
|
4482
|
+
addNodeRef(node);
|
|
4483
|
+
}
|
|
4484
|
+
},
|
|
4485
|
+
onChange: (e) => updateNodeRef(node, idx, e.target.value),
|
|
4486
|
+
}),
|
|
4487
|
+
h('button', {
|
|
4488
|
+
type: 'button',
|
|
4489
|
+
style: S.condBranchDel,
|
|
4490
|
+
title: t('delRefTip'),
|
|
4491
|
+
onMouseEnter: (e) => { e.currentTarget.style.color = '#e5534b'; },
|
|
4492
|
+
onMouseLeave: (e) => { e.currentTarget.style.color = C.dim; },
|
|
4493
|
+
onClick: () => removeNodeRef(node, idx),
|
|
4494
|
+
}, '×'),
|
|
4495
|
+
)),
|
|
4496
|
+
),
|
|
4497
|
+
list.length < 16 && h('button', {
|
|
4498
|
+
type: 'button',
|
|
4499
|
+
style: { ...S.btn, width: '100%', padding: '3px 8px', fontSize: '10px', textAlign: 'center' },
|
|
4500
|
+
onClick: () => addNodeRef(node),
|
|
4501
|
+
}, t('refsAdd')),
|
|
4502
|
+
);
|
|
4503
|
+
};
|
|
4504
|
+
|
|
3780
4505
|
return h('div', {
|
|
3781
4506
|
ref: rootElRef,
|
|
3782
4507
|
style: S.root,
|
|
@@ -3788,139 +4513,19 @@ window.__ModuleLoader__.load({
|
|
|
3788
4513
|
h('button', { style: S.btn, onClick: () => addNode('lead'), type: 'button' }, t('addLead')),
|
|
3789
4514
|
h('button', { style: S.btn, onClick: () => addNode('condition'), type: 'button' }, t('addCond')),
|
|
3790
4515
|
h('span', { style: S.toolSep }),
|
|
3791
|
-
h('button', { style: S.btn, onClick: undo, type: 'button', title: t('tipUndo') }, t('undo')),
|
|
3792
4516
|
h('button', {
|
|
3793
4517
|
style: enabled && dirty ? S.btnDirty : S.btn,
|
|
3794
4518
|
onClick: () => pushPlan(enabled),
|
|
3795
4519
|
type: 'button',
|
|
3796
4520
|
title: t('tipSync'),
|
|
3797
4521
|
}, t('sync')),
|
|
3798
|
-
h('span', { style: S.toolSep }),
|
|
3799
4522
|
h('button', {
|
|
3800
4523
|
style: S.btn,
|
|
3801
|
-
onClick:
|
|
4524
|
+
onClick: toggleDirection,
|
|
3802
4525
|
type: 'button',
|
|
3803
|
-
title: t('
|
|
3804
|
-
}, t('
|
|
3805
|
-
h('button', {
|
|
3806
|
-
style: { ...S.btn, cursor: 'ew-resize', minWidth: '50px', textAlign: 'center', fontVariantNumeric: 'tabular-nums' },
|
|
3807
|
-
onMouseDown: onZoomPillDown,
|
|
3808
|
-
onKeyDown: (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); focusLead(1); } },
|
|
3809
|
-
type: 'button',
|
|
3810
|
-
title: t('tipResetZoom'),
|
|
3811
|
-
}, Math.round(view.k * 100) + '%'),
|
|
4526
|
+
title: t('tipDir'),
|
|
4527
|
+
}, direction === 'tb' ? t('dirTB') : t('dirLR')),
|
|
3812
4528
|
syncNote ? h('span', { style: S.syncNote, title: syncNote }, syncNote) : null,
|
|
3813
|
-
h('span', { style: S.toolSep }),
|
|
3814
|
-
h('button', {
|
|
3815
|
-
style: S.btn,
|
|
3816
|
-
onClick: toggleLang,
|
|
3817
|
-
type: 'button',
|
|
3818
|
-
title: 'Switch language / 切换语言',
|
|
3819
|
-
}, t('lang')),
|
|
3820
|
-
h('div', { style: S.moreBar },
|
|
3821
|
-
h('button', {
|
|
3822
|
-
style: S.btn,
|
|
3823
|
-
type: 'button',
|
|
3824
|
-
title: t('tipMore'),
|
|
3825
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
3826
|
-
onClick: (e) => {
|
|
3827
|
-
const next = !menuOpen;
|
|
3828
|
-
if (next) {
|
|
3829
|
-
setPresetOpen(null);
|
|
3830
|
-
const rootRect = rootElRef.current && rootElRef.current.getBoundingClientRect();
|
|
3831
|
-
const btnRect = e.currentTarget && e.currentTarget.getBoundingClientRect();
|
|
3832
|
-
setMenuAlign(dropdownAlign(btnRect, rootRect, 204));
|
|
3833
|
-
}
|
|
3834
|
-
setMenuOpen(next);
|
|
3835
|
-
},
|
|
3836
|
-
}, '⋯'),
|
|
3837
|
-
menuOpen && h('div', {
|
|
3838
|
-
style: {
|
|
3839
|
-
...S.moreMenu,
|
|
3840
|
-
left: menuAlign === 'left' ? 0 : 'auto',
|
|
3841
|
-
right: menuAlign === 'left' ? 'auto' : 0,
|
|
3842
|
-
},
|
|
3843
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
3844
|
-
},
|
|
3845
|
-
h('div', {
|
|
3846
|
-
style: S.moreRow,
|
|
3847
|
-
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
3848
|
-
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
3849
|
-
onClick: () => { setMenuOpen(false); importFromClipboard(); },
|
|
3850
|
-
}, t('importBtn')),
|
|
3851
|
-
h('div', {
|
|
3852
|
-
style: S.moreRow,
|
|
3853
|
-
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
3854
|
-
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
3855
|
-
onClick: () => { setMenuOpen(false); exportToClipboard(); },
|
|
3856
|
-
}, t('exportBtn')),
|
|
3857
|
-
h('div', {
|
|
3858
|
-
style: S.moreRow,
|
|
3859
|
-
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
3860
|
-
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
3861
|
-
onClick: () => { setMenuOpen(false); autoLayout(); },
|
|
3862
|
-
}, t('autoLayoutBtn')),
|
|
3863
|
-
h('div', {
|
|
3864
|
-
style: { ...S.moreRow, color: '#e5534b' },
|
|
3865
|
-
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
3866
|
-
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
3867
|
-
onClick: () => { clearCanvas(); },
|
|
3868
|
-
}, t('clearCanvasBtn')),
|
|
3869
|
-
h('div', {
|
|
3870
|
-
style: S.moreRow,
|
|
3871
|
-
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
3872
|
-
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
3873
|
-
onClick: () => {
|
|
3874
|
-
const next = nextEffectLevel(fxLevel);
|
|
3875
|
-
setFxLevel(next);
|
|
3876
|
-
saveEffectLevel(next);
|
|
3877
|
-
flash(t('fxLabel') + t('sep') + fxName(next));
|
|
3878
|
-
},
|
|
3879
|
-
}, t('fxLabel') + t('sep') + fxName(fxLevel)),
|
|
3880
|
-
h('div', {
|
|
3881
|
-
style: { ...S.moreRow, display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px' },
|
|
3882
|
-
title: t('tipMaxParallel'),
|
|
3883
|
-
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
3884
|
-
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
3885
|
-
onClick: () => {
|
|
3886
|
-
const next = nextMaxParallel(maxParallel);
|
|
3887
|
-
setMaxParallel(next);
|
|
3888
|
-
maxParallelRef.current = next;
|
|
3889
|
-
saveMaxParallel(next);
|
|
3890
|
-
if (enabled) pushPlan(true, undefined, undefined, next);
|
|
3891
|
-
else flash(t('maxParallelLabel') + t('sep') + next);
|
|
3892
|
-
},
|
|
3893
|
-
},
|
|
3894
|
-
h('span', null, t('maxParallelLabel') + t('sep') + maxParallel),
|
|
3895
|
-
h('span', {
|
|
3896
|
-
title: t('tipMaxParallel'),
|
|
3897
|
-
style: {
|
|
3898
|
-
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
|
3899
|
-
width: '14px', height: '14px', borderRadius: '50%',
|
|
3900
|
-
border: '1px solid ' + (maxParallel > 4 ? '#d29922' : C.dim),
|
|
3901
|
-
color: maxParallel > 4 ? '#d29922' : C.dim,
|
|
3902
|
-
fontSize: '10px', fontWeight: 700, lineHeight: '12px', flex: '0 0 auto',
|
|
3903
|
-
},
|
|
3904
|
-
}, '!'),
|
|
3905
|
-
),
|
|
3906
|
-
h('div', {
|
|
3907
|
-
style: S.moreRow,
|
|
3908
|
-
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
3909
|
-
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
3910
|
-
onClick: () => {
|
|
3911
|
-
const next = !cutMode;
|
|
3912
|
-
setCutMode(next);
|
|
3913
|
-
saveCutMode(next);
|
|
3914
|
-
},
|
|
3915
|
-
}, t('cutLinks') + t('sep') + (cutMode ? t('on') : t('off'))),
|
|
3916
|
-
h('div', {
|
|
3917
|
-
style: S.moreRow,
|
|
3918
|
-
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
3919
|
-
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
3920
|
-
onClick: () => { setMenuOpen(false); setHelpOpen(true); },
|
|
3921
|
-
}, t('help')),
|
|
3922
|
-
),
|
|
3923
|
-
),
|
|
3924
4529
|
h('div', { style: S.presetBar },
|
|
3925
4530
|
(() => {
|
|
3926
4531
|
const feedback = status || (enabled ? (dirty ? t('unsaved') : t('synced')) : '');
|
|
@@ -3934,6 +4539,7 @@ window.__ModuleLoader__.load({
|
|
|
3934
4539
|
const next = presetOpen === 'menu' ? null : 'menu';
|
|
3935
4540
|
if (next) {
|
|
3936
4541
|
setMenuOpen(false);
|
|
4542
|
+
setCtxMenu(null);
|
|
3937
4543
|
const rootRect = rootElRef.current && rootElRef.current.getBoundingClientRect();
|
|
3938
4544
|
const btnRect = e.currentTarget && e.currentTarget.getBoundingClientRect();
|
|
3939
4545
|
setPresetAlign(dropdownAlign(btnRect, rootRect, 248));
|
|
@@ -3946,7 +4552,7 @@ window.__ModuleLoader__.load({
|
|
|
3946
4552
|
})(),
|
|
3947
4553
|
presetOpen === 'menu' && (() => {
|
|
3948
4554
|
const names = Object.keys(presets);
|
|
3949
|
-
const templates = builtinTemplates(lang);
|
|
4555
|
+
const templates = builtinTemplates(lang, direction);
|
|
3950
4556
|
return h('div', {
|
|
3951
4557
|
style: {
|
|
3952
4558
|
...S.presetMenu,
|
|
@@ -4002,9 +4608,145 @@ window.__ModuleLoader__.load({
|
|
|
4002
4608
|
}, h('span', { style: S.presetRowText, title: tpl.name }, tpl.name))),
|
|
4003
4609
|
);
|
|
4004
4610
|
})(),
|
|
4611
|
+
h('div', { style: S.moreBar },
|
|
4612
|
+
h('button', {
|
|
4613
|
+
style: S.btn,
|
|
4614
|
+
type: 'button',
|
|
4615
|
+
title: t('tipMore'),
|
|
4616
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
4617
|
+
onClick: (e) => {
|
|
4618
|
+
const next = !menuOpen;
|
|
4619
|
+
if (next) {
|
|
4620
|
+
setPresetOpen(null);
|
|
4621
|
+
setCtxMenu(null);
|
|
4622
|
+
const rootRect = rootElRef.current && rootElRef.current.getBoundingClientRect();
|
|
4623
|
+
const btnRect = e.currentTarget && e.currentTarget.getBoundingClientRect();
|
|
4624
|
+
setMenuAlign(dropdownAlign(btnRect, rootRect, 204));
|
|
4625
|
+
}
|
|
4626
|
+
setMenuOpen(next);
|
|
4627
|
+
},
|
|
4628
|
+
}, '⋯'),
|
|
4629
|
+
menuOpen && h('div', {
|
|
4630
|
+
style: {
|
|
4631
|
+
...S.moreMenu,
|
|
4632
|
+
left: menuAlign === 'left' ? 0 : 'auto',
|
|
4633
|
+
right: menuAlign === 'left' ? 'auto' : 0,
|
|
4634
|
+
},
|
|
4635
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
4636
|
+
},
|
|
4637
|
+
h('div', {
|
|
4638
|
+
style: S.moreRow,
|
|
4639
|
+
title: t('tipUndo'),
|
|
4640
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4641
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4642
|
+
onClick: () => { setMenuOpen(false); undo(); },
|
|
4643
|
+
}, t('undo')),
|
|
4644
|
+
h('div', {
|
|
4645
|
+
style: S.moreRow,
|
|
4646
|
+
title: t('tipLocate'),
|
|
4647
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4648
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4649
|
+
onClick: () => { setMenuOpen(false); fitView(); },
|
|
4650
|
+
}, t('locate')),
|
|
4651
|
+
h('div', { style: S.ctxDivider }),
|
|
4652
|
+
h('div', {
|
|
4653
|
+
style: S.moreRow,
|
|
4654
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4655
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4656
|
+
onClick: () => { setMenuOpen(false); importFromClipboard(); },
|
|
4657
|
+
}, t('importBtn')),
|
|
4658
|
+
h('div', {
|
|
4659
|
+
style: S.moreRow,
|
|
4660
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4661
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4662
|
+
onClick: () => { setMenuOpen(false); exportToClipboard(); },
|
|
4663
|
+
}, t('exportBtn')),
|
|
4664
|
+
h('div', {
|
|
4665
|
+
style: S.moreRow,
|
|
4666
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4667
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4668
|
+
onClick: () => { setMenuOpen(false); autoLayout(); },
|
|
4669
|
+
}, t('autoLayoutBtn')),
|
|
4670
|
+
h('div', {
|
|
4671
|
+
style: { ...S.moreRow, color: '#e5534b' },
|
|
4672
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4673
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4674
|
+
onClick: () => { clearCanvas(); },
|
|
4675
|
+
}, t('clearCanvasBtn')),
|
|
4676
|
+
h('div', { style: S.ctxDivider }),
|
|
4677
|
+
h('div', {
|
|
4678
|
+
style: S.moreRow,
|
|
4679
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4680
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4681
|
+
onClick: () => {
|
|
4682
|
+
const next = nextEffectLevel(fxLevel);
|
|
4683
|
+
setFxLevel(next);
|
|
4684
|
+
saveEffectLevel(next);
|
|
4685
|
+
flash(t('fxLabel') + t('sep') + fxName(next));
|
|
4686
|
+
},
|
|
4687
|
+
}, t('fxLabel') + t('sep') + fxName(fxLevel)),
|
|
4688
|
+
h('div', {
|
|
4689
|
+
style: { ...S.moreRow, display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px' },
|
|
4690
|
+
title: t('tipMaxParallel'),
|
|
4691
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4692
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4693
|
+
onClick: () => {
|
|
4694
|
+
const next = nextMaxParallel(maxParallel);
|
|
4695
|
+
setMaxParallel(next);
|
|
4696
|
+
maxParallelRef.current = next;
|
|
4697
|
+
saveMaxParallel(next);
|
|
4698
|
+
if (enabled) pushPlan(true, undefined, undefined, next);
|
|
4699
|
+
else flash(t('maxParallelLabel') + t('sep') + next);
|
|
4700
|
+
},
|
|
4701
|
+
},
|
|
4702
|
+
h('span', null, t('maxParallelLabel') + t('sep') + maxParallel),
|
|
4703
|
+
h('span', {
|
|
4704
|
+
title: t('tipMaxParallel'),
|
|
4705
|
+
style: {
|
|
4706
|
+
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
|
4707
|
+
width: '14px', height: '14px', borderRadius: '50%',
|
|
4708
|
+
border: '1px solid ' + (maxParallel > 4 ? '#d29922' : C.dim),
|
|
4709
|
+
color: maxParallel > 4 ? '#d29922' : C.dim,
|
|
4710
|
+
fontSize: '10px', fontWeight: 700, lineHeight: '12px', flex: '0 0 auto',
|
|
4711
|
+
},
|
|
4712
|
+
}, '!'),
|
|
4713
|
+
),
|
|
4714
|
+
h('div', {
|
|
4715
|
+
style: S.moreRow,
|
|
4716
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4717
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4718
|
+
onClick: () => {
|
|
4719
|
+
const next = !cutMode;
|
|
4720
|
+
setCutMode(next);
|
|
4721
|
+
saveCutMode(next);
|
|
4722
|
+
},
|
|
4723
|
+
}, t('cutLinks') + t('sep') + (cutMode ? t('on') : t('off'))),
|
|
4724
|
+
h('div', {
|
|
4725
|
+
style: S.moreRow,
|
|
4726
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4727
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4728
|
+
onClick: () => { toggleLang(); },
|
|
4729
|
+
}, t('ctxLangToggle') + t('sep') + (lang === 'zh' ? '中文' : 'EN')),
|
|
4730
|
+
h('div', {
|
|
4731
|
+
style: S.moreRow,
|
|
4732
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4733
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4734
|
+
onClick: () => { setMenuOpen(false); setRecordingAction(null); setShortcutsOpen(true); },
|
|
4735
|
+
}, t('shortcutsMenu')),
|
|
4736
|
+
h('div', {
|
|
4737
|
+
style: S.moreRow,
|
|
4738
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4739
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4740
|
+
onClick: () => { setMenuOpen(false); setHelpOpen(true); },
|
|
4741
|
+
}, t('help')),
|
|
4742
|
+
),
|
|
4743
|
+
),
|
|
4005
4744
|
),
|
|
4006
4745
|
),
|
|
4007
|
-
helpOpen && h('div', {
|
|
4746
|
+
helpOpen && h('div', {
|
|
4747
|
+
style: S.helpOverlay,
|
|
4748
|
+
onMouseDown: (e) => { e.stopPropagation(); if (e.target === e.currentTarget) setHelpOpen(false); },
|
|
4749
|
+
},
|
|
4008
4750
|
h('div', { style: S.helpCard },
|
|
4009
4751
|
h('div', { style: S.helpHead },
|
|
4010
4752
|
h('span', { style: S.helpTitle }, t('helpTitle')),
|
|
@@ -4013,10 +4755,92 @@ window.__ModuleLoader__.load({
|
|
|
4013
4755
|
h('div', { style: S.helpBody }, t('helpBody').split('\n').map((line, i) => h('div', { key: i, style: S.helpLine }, line))),
|
|
4014
4756
|
),
|
|
4015
4757
|
),
|
|
4758
|
+
shortcutsOpen && (() => {
|
|
4759
|
+
const actionLabels = {
|
|
4760
|
+
addNode: t('scAddNode'),
|
|
4761
|
+
duplicate: t('scDuplicate'),
|
|
4762
|
+
delete: t('scDelete'),
|
|
4763
|
+
undo: t('scUndo'),
|
|
4764
|
+
fitView: t('scFitView'),
|
|
4765
|
+
autoLayout: t('scAutoLayout'),
|
|
4766
|
+
toggleDir: t('scToggleDir'),
|
|
4767
|
+
};
|
|
4768
|
+
return h('div', {
|
|
4769
|
+
style: S.helpOverlay,
|
|
4770
|
+
onMouseDown: (e) => {
|
|
4771
|
+
e.stopPropagation();
|
|
4772
|
+
if (e.target === e.currentTarget) {
|
|
4773
|
+
setRecordingAction(null);
|
|
4774
|
+
setShortcutsOpen(false);
|
|
4775
|
+
}
|
|
4776
|
+
},
|
|
4777
|
+
},
|
|
4778
|
+
h('div', { style: { ...S.helpCard, maxWidth: '360px' } },
|
|
4779
|
+
h('div', { style: S.helpHead },
|
|
4780
|
+
h('span', { style: S.helpTitle }, t('shortcutsTitle')),
|
|
4781
|
+
h('button', {
|
|
4782
|
+
style: S.btn,
|
|
4783
|
+
type: 'button',
|
|
4784
|
+
onClick: () => {
|
|
4785
|
+
const resetMap = { ...DEFAULT_SHORTCUTS };
|
|
4786
|
+
shortcutsRef.current = resetMap;
|
|
4787
|
+
saveShortcuts(resetMap);
|
|
4788
|
+
setShortcuts(resetMap);
|
|
4789
|
+
setRecordingAction(null);
|
|
4790
|
+
flash(t('shortcutsResetOk'));
|
|
4791
|
+
},
|
|
4792
|
+
}, t('shortcutsReset')),
|
|
4793
|
+
h('button', {
|
|
4794
|
+
style: S.btn,
|
|
4795
|
+
type: 'button',
|
|
4796
|
+
onClick: () => { setRecordingAction(null); setShortcutsOpen(false); },
|
|
4797
|
+
}, t('close')),
|
|
4798
|
+
),
|
|
4799
|
+
h('div', { style: { fontSize: '10px', color: C.dim, marginBottom: '8px', lineHeight: '1.45' } }, t('shortcutsHint')),
|
|
4800
|
+
SHORTCUT_ORDER.map((actionId, idx) => {
|
|
4801
|
+
const binding = shortcuts[actionId] || '';
|
|
4802
|
+
const isRec = recordingAction === actionId;
|
|
4803
|
+
return h('div', {
|
|
4804
|
+
key: actionId,
|
|
4805
|
+
style: idx === SHORTCUT_ORDER.length - 1 ? { ...S.shortcutRow, borderBottom: 'none' } : S.shortcutRow,
|
|
4806
|
+
},
|
|
4807
|
+
h('span', null, actionLabels[actionId] || actionId),
|
|
4808
|
+
h('div', { style: { display: 'inline-flex', alignItems: 'center', gap: '4px' } },
|
|
4809
|
+
h('button', {
|
|
4810
|
+
type: 'button',
|
|
4811
|
+
style: isRec ? { ...S.shortcutKeyBtn, ...S.shortcutKeyRec } : (binding ? S.shortcutKeyBtn : { ...S.shortcutKeyBtn, color: C.dim }),
|
|
4812
|
+
onClick: () => setRecordingAction(isRec ? null : actionId),
|
|
4813
|
+
}, isRec ? t('shortcutsPress') : (binding || t('shortcutsUnset'))),
|
|
4814
|
+
binding
|
|
4815
|
+
? h('button', {
|
|
4816
|
+
type: 'button',
|
|
4817
|
+
style: S.condBranchDel,
|
|
4818
|
+
title: t('del'),
|
|
4819
|
+
onMouseEnter: (e) => { e.currentTarget.style.color = '#e5534b'; },
|
|
4820
|
+
onMouseLeave: (e) => { e.currentTarget.style.color = C.dim; },
|
|
4821
|
+
onClick: () => {
|
|
4822
|
+
const { next } = applyShortcutBinding(shortcutsRef.current, actionId, '');
|
|
4823
|
+
shortcutsRef.current = next;
|
|
4824
|
+
saveShortcuts(next);
|
|
4825
|
+
setShortcuts(next);
|
|
4826
|
+
if (recordingAction === actionId) setRecordingAction(null);
|
|
4827
|
+
},
|
|
4828
|
+
}, '×')
|
|
4829
|
+
: h('span', { style: S.condBranchDelSpacer }),
|
|
4830
|
+
),
|
|
4831
|
+
);
|
|
4832
|
+
}),
|
|
4833
|
+
),
|
|
4834
|
+
);
|
|
4835
|
+
})(),
|
|
4016
4836
|
h('div', {
|
|
4017
4837
|
ref: canvasWrapRef,
|
|
4018
4838
|
style: S.canvasWrap,
|
|
4019
4839
|
onMouseMove: (e) => { lastMouseRef.current = { clientX: e.clientX, clientY: e.clientY }; },
|
|
4840
|
+
onContextMenu: (e) => {
|
|
4841
|
+
const tag = e.target && e.target.tagName;
|
|
4842
|
+
if (tag !== 'INPUT' && tag !== 'TEXTAREA') e.preventDefault();
|
|
4843
|
+
},
|
|
4020
4844
|
},
|
|
4021
4845
|
h('button', {
|
|
4022
4846
|
style: enabled
|
|
@@ -4048,7 +4872,7 @@ window.__ModuleLoader__.load({
|
|
|
4048
4872
|
const lf = addMenu.linkFrom || null;
|
|
4049
4873
|
const srcNode = lf && lf.fromId ? nodeById.get(lf.fromId) : null;
|
|
4050
4874
|
const compat = lf ? compatibleTargetsForWire(srcNode, lf.type) : { agent: true, lead: true, condition: true, leadBlockedReason: '' };
|
|
4051
|
-
|
|
4875
|
+
return h('div', {
|
|
4052
4876
|
style: { ...S.addMenu, left: addMenu.sx + 'px', top: addMenu.sy + 'px' },
|
|
4053
4877
|
onMouseDown: (e) => e.stopPropagation(),
|
|
4054
4878
|
},
|
|
@@ -4074,6 +4898,100 @@ window.__ModuleLoader__.load({
|
|
|
4074
4898
|
}, h('span', null, t('addCond')), h('span', { style: S.addMenuHint }, '3')),
|
|
4075
4899
|
);
|
|
4076
4900
|
})(),
|
|
4901
|
+
ctxMenu && (() => {
|
|
4902
|
+
const menuRow = (key, label, onClick, opts) => {
|
|
4903
|
+
const danger = opts && opts.danger;
|
|
4904
|
+
const hint = opts && opts.hint;
|
|
4905
|
+
return h('div', {
|
|
4906
|
+
key,
|
|
4907
|
+
style: danger ? { ...S.addMenuRow, color: '#e5534b' } : S.addMenuRow,
|
|
4908
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4909
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4910
|
+
onClick,
|
|
4911
|
+
}, h('span', null, label), hint ? h('span', { style: S.addMenuHint }, hint) : null);
|
|
4912
|
+
};
|
|
4913
|
+
if (ctxMenu.kind === 'node') {
|
|
4914
|
+
const target = nodeById.get(ctxMenu.nodeId);
|
|
4915
|
+
if (!target) return null;
|
|
4916
|
+
const multiSel = selectedIds.length > 1 && selectedSet.has(target.id);
|
|
4917
|
+
const nonLeadCount = (multiSel ? selectedIds : [target.id]).filter((id) => id !== 'lead').length;
|
|
4918
|
+
const suffix = nonLeadCount > 1 ? ' ×' + nonLeadCount : '';
|
|
4919
|
+
const latestRun = target.kind !== 'lead' ? runsById[target.id] : null;
|
|
4920
|
+
return h('div', {
|
|
4921
|
+
style: { ...S.addMenu, minWidth: '172px', left: ctxMenu.sx + 'px', top: ctxMenu.sy + 'px' },
|
|
4922
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
4923
|
+
onContextMenu: (e) => e.preventDefault(),
|
|
4924
|
+
},
|
|
4925
|
+
h('div', { style: S.addMenuHead }, t('ctxNodeTitle')),
|
|
4926
|
+
menuRow('edit', t('ctxEditText'), () => { setCtxMenu(null); setRoleEditFor(target.id); }),
|
|
4927
|
+
menuRow('refs', t('ctxManageRefs'), () => { setCtxMenu(null); setRefsEditFor(target.id); }),
|
|
4928
|
+
latestRun && menuRow('chat', t('ctxOpenChat'), () => { setCtxMenu(null); openNodeSession(target); }),
|
|
4929
|
+
nonLeadCount > 0 && h('div', { style: S.ctxDivider }),
|
|
4930
|
+
nonLeadCount > 0 && menuRow('dup', t('ctxDup') + suffix, () => { setCtxMenu(null); duplicateSelected(); }, { hint: shortcuts.duplicate || '' }),
|
|
4931
|
+
nonLeadCount > 0 && menuRow('del', t('ctxDelNode') + suffix, () => {
|
|
4932
|
+
setCtxMenu(null);
|
|
4933
|
+
if (multiSel) deleteSelected();
|
|
4934
|
+
else deleteNode(target.id);
|
|
4935
|
+
}, { danger: true, hint: shortcuts.delete === 'Delete' ? 'Del' : (shortcuts.delete || '') }),
|
|
4936
|
+
);
|
|
4937
|
+
}
|
|
4938
|
+
if (ctxMenu.kind === 'edge') {
|
|
4939
|
+
const targetEdge = edges.find((ed) => ed.id === ctxMenu.edgeId);
|
|
4940
|
+
if (!targetEdge) return null;
|
|
4941
|
+
return h('div', {
|
|
4942
|
+
style: { ...S.addMenu, minWidth: '172px', left: ctxMenu.sx + 'px', top: ctxMenu.sy + 'px' },
|
|
4943
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
4944
|
+
onContextMenu: (e) => e.preventDefault(),
|
|
4945
|
+
},
|
|
4946
|
+
h('div', { style: S.addMenuHead }, t('ctxEdgeTitle')),
|
|
4947
|
+
menuRow('ins-agent', t('ctxInsertAgent'), () => insertNodeOnEdge(targetEdge.id, 'agent', { x: ctxMenu.wx, y: ctxMenu.wy })),
|
|
4948
|
+
menuRow('ins-cond', t('ctxInsertCond'), () => insertNodeOnEdge(targetEdge.id, 'condition', { x: ctxMenu.wx, y: ctxMenu.wy })),
|
|
4949
|
+
h('div', { style: S.ctxDivider }),
|
|
4950
|
+
menuRow('del-edge', t('ctxDelEdge'), () => deleteEdgeById(targetEdge.id), { danger: true }),
|
|
4951
|
+
);
|
|
4952
|
+
}
|
|
4953
|
+
return h('div', {
|
|
4954
|
+
style: { ...S.addMenu, minWidth: '176px', left: ctxMenu.sx + 'px', top: ctxMenu.sy + 'px' },
|
|
4955
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
4956
|
+
onContextMenu: (e) => e.preventDefault(),
|
|
4957
|
+
},
|
|
4958
|
+
h('div', { style: S.addMenuHead }, t('ctxCanvasTitle')),
|
|
4959
|
+
menuRow('add-agent', t('addAgent'), () => addNode('agent', { x: ctxMenu.wx, y: ctxMenu.wy })),
|
|
4960
|
+
menuRow('add-lead', t('addLead'), () => addNode('lead', { x: ctxMenu.wx, y: ctxMenu.wy })),
|
|
4961
|
+
menuRow('add-cond', t('addCond'), () => addNode('condition', { x: ctxMenu.wx, y: ctxMenu.wy })),
|
|
4962
|
+
h('div', { style: S.ctxDivider }),
|
|
4963
|
+
menuRow('undo', t('undo'), () => { setCtxMenu(null); undo(); }, { hint: shortcuts.undo || '' }),
|
|
4964
|
+
menuRow('layout', t('autoLayoutBtn'), () => { setCtxMenu(null); autoLayout(); }, { hint: shortcuts.autoLayout || '' }),
|
|
4965
|
+
menuRow('dir', direction === 'tb' ? t('dirLR') : t('dirTB'), () => { setCtxMenu(null); toggleDirection(); }, { hint: shortcuts.toggleDir || '' }),
|
|
4966
|
+
menuRow('fit', t('locate'), () => { setCtxMenu(null); fitView(); }, { hint: shortcuts.fitView || '' }),
|
|
4967
|
+
h('div', { style: S.ctxDivider }),
|
|
4968
|
+
menuRow('imp', t('importBtn'), () => { setCtxMenu(null); importFromClipboard(); }),
|
|
4969
|
+
menuRow('clr', t('clearCanvasBtn'), () => { setCtxMenu(null); clearCanvas(); }, { danger: true }),
|
|
4970
|
+
);
|
|
4971
|
+
})(),
|
|
4972
|
+
h('div', {
|
|
4973
|
+
style: S.floatZoomBar,
|
|
4974
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
4975
|
+
},
|
|
4976
|
+
h('button', {
|
|
4977
|
+
style: S.floatZoomBtn,
|
|
4978
|
+
type: 'button',
|
|
4979
|
+
title: t('tipLocate'),
|
|
4980
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4981
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4982
|
+
onClick: () => fitView(),
|
|
4983
|
+
}, '⊡'),
|
|
4984
|
+
h('span', { style: { width: '1px', height: '12px', background: C.border, opacity: 0.7 } }),
|
|
4985
|
+
h('button', {
|
|
4986
|
+
style: { ...S.floatZoomBtn, cursor: 'ew-resize', minWidth: '42px', textAlign: 'center', fontVariantNumeric: 'tabular-nums' },
|
|
4987
|
+
type: 'button',
|
|
4988
|
+
title: t('tipResetZoom'),
|
|
4989
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4990
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4991
|
+
onMouseDown: onZoomPillDown,
|
|
4992
|
+
onKeyDown: (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); focusLead(1); } },
|
|
4993
|
+
}, Math.round(view.k * 100) + '%'),
|
|
4994
|
+
),
|
|
4077
4995
|
h('div', {
|
|
4078
4996
|
ref: canvasElRef,
|
|
4079
4997
|
style: {
|
|
@@ -4166,6 +5084,10 @@ window.__ModuleLoader__.load({
|
|
|
4166
5084
|
const isPruned = enabled && prunedSet.has(node.id);
|
|
4167
5085
|
const condDecision = isCondKind ? (decisionsById[node.id] || null) : null;
|
|
4168
5086
|
const verdictInfo = condDecision ? conditionVerdictSummary(condDecision, lang) : null;
|
|
5087
|
+
const hasOpenPopover = decisionViewFor === node.id
|
|
5088
|
+
|| refsEditFor === node.id
|
|
5089
|
+
|| roleEditFor === node.id
|
|
5090
|
+
|| (typeof roleEditFor === 'string' && roleEditFor.includes(':' + node.id + ':'));
|
|
4169
5091
|
return h('div', {
|
|
4170
5092
|
key: node.id,
|
|
4171
5093
|
'data-node': node.id,
|
|
@@ -4178,10 +5100,11 @@ window.__ModuleLoader__.load({
|
|
|
4178
5100
|
...(isLeadKind ? S.leadNode : null),
|
|
4179
5101
|
...(isInactive || isPruned ? S.orphanNode : null),
|
|
4180
5102
|
...(stateStyle || null),
|
|
4181
|
-
...(
|
|
5103
|
+
...(hasOpenPopover ? { zIndex: 40 } : null),
|
|
4182
5104
|
},
|
|
4183
5105
|
title: isPruned ? t('tipPruned') : (isOrphan ? t('orphanTip') : (isSoloLead ? t('tipSoloLead') : (isDeadEnd ? t('tipDeadEnd') : undefined))),
|
|
4184
5106
|
onMouseDown: (e) => onNodeDown(e, node.id),
|
|
5107
|
+
onContextMenu: (e) => onNodeContextMenu(e, node),
|
|
4185
5108
|
},
|
|
4186
5109
|
h('div', {
|
|
4187
5110
|
className: (isRunning || isLeadReady) && fxLevel === 'vivid' ? 'dsh-wc-topbar-vivid' : undefined,
|
|
@@ -4220,6 +5143,7 @@ window.__ModuleLoader__.load({
|
|
|
4220
5143
|
disabled: btn.disabled,
|
|
4221
5144
|
style: {
|
|
4222
5145
|
...S.statusBtn,
|
|
5146
|
+
bottom: direction === 'tb' ? '28px' : '4px',
|
|
4223
5147
|
color,
|
|
4224
5148
|
background: bg,
|
|
4225
5149
|
borderColor,
|
|
@@ -4284,7 +5208,7 @@ window.__ModuleLoader__.load({
|
|
|
4284
5208
|
const bg = enabled && statusTint !== 'transparent' ? statusTint : C.elevated;
|
|
4285
5209
|
return h('button', {
|
|
4286
5210
|
type: 'button',
|
|
4287
|
-
style: { ...S.statusBtn, color, background: bg, borderColor: color === C.dim ? C.border : color },
|
|
5211
|
+
style: { ...S.statusBtn, bottom: (direction === 'tb' && !isCondKind) ? '28px' : '4px', color, background: bg, borderColor: color === C.dim ? C.border : color },
|
|
4288
5212
|
title: t('tipOpenRun'),
|
|
4289
5213
|
onMouseDown: (e) => e.stopPropagation(),
|
|
4290
5214
|
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
@@ -4293,9 +5217,10 @@ window.__ModuleLoader__.load({
|
|
|
4293
5217
|
}, enabled ? glyph : null, label, ' ↗');
|
|
4294
5218
|
}
|
|
4295
5219
|
if (!enabled) return null;
|
|
4296
|
-
|
|
5220
|
+
return h('div', {
|
|
4297
5221
|
style: {
|
|
4298
5222
|
...S.statusChip,
|
|
5223
|
+
bottom: (direction === 'tb' && !isCondKind) ? '28px' : '5px',
|
|
4299
5224
|
color: statusColor,
|
|
4300
5225
|
background: statusTint,
|
|
4301
5226
|
border: statusTint !== 'transparent' ? ('1px solid ' + statusColor) : 'none',
|
|
@@ -4395,6 +5320,13 @@ window.__ModuleLoader__.load({
|
|
|
4395
5320
|
h('div', { style: S.condLabelRow },
|
|
4396
5321
|
h('span', { style: S.fieldLabel }, t('condLabel')),
|
|
4397
5322
|
h('div', { style: S.condBtnGroup },
|
|
5323
|
+
direction === 'tb' && h('button', {
|
|
5324
|
+
type: 'button',
|
|
5325
|
+
style: S.condAddBtn,
|
|
5326
|
+
title: t('tipCondSide'),
|
|
5327
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
5328
|
+
onClick: () => updateNode(node.id, { tbSide: node.tbSide === 'left' ? 'right' : 'left' }),
|
|
5329
|
+
}, node.tbSide === 'left' ? t('condSideL') : t('condSideR')),
|
|
4398
5330
|
h('button', {
|
|
4399
5331
|
type: 'button',
|
|
4400
5332
|
style: node.multiMatch ? S.condModeBtnOn : S.condAddBtn,
|
|
@@ -4545,6 +5477,8 @@ window.__ModuleLoader__.load({
|
|
|
4545
5477
|
style: { maxHeight: '140px', overflowY: 'auto', whiteSpace: 'pre-wrap', wordBreak: 'break-word', color: C.text, fontSize: '11px' },
|
|
4546
5478
|
}, (condDecision.reason && String(condDecision.reason).trim()) || t('verdictNoReason')),
|
|
4547
5479
|
),
|
|
5480
|
+
refsControlBtn(node),
|
|
5481
|
+
refsPopoverEl(node),
|
|
4548
5482
|
renderBand(node),
|
|
4549
5483
|
);
|
|
4550
5484
|
}),
|
|
@@ -4583,7 +5517,7 @@ window.__ModuleLoader__.load({
|
|
|
4583
5517
|
try { console.error('[workflow-canvas] apply failed', error); } catch (_e) { /* ignore */ }
|
|
4584
5518
|
}
|
|
4585
5519
|
},
|
|
4586
|
-
__test: { topoOrder, wouldCycle, soloLeadNodeIds, layoutGraph, builtinTemplates, deadEndNodeIds, nextEffectLevel, nextMaxParallel, dropdownAlign, zoomAroundPoint, scrubZoom, buildPlan, loadDoc, saveDoc, storageKey, socketCenterY, nodeHeight, conditionBranchesForUI, distanceToEdge, edgeCurve, compatibleTargetsForWire, conditionVerdictSummary, entryRunButtonState },
|
|
5520
|
+
__test: { topoOrder, wouldCycle, soloLeadNodeIds, layoutGraph, builtinTemplates, deadEndNodeIds, nextEffectLevel, nextMaxParallel, dropdownAlign, zoomAroundPoint, scrubZoom, buildPlan, loadDoc, saveDoc, storageKey, socketCenterY, nodeHeight, conditionBranchesForUI, distanceToEdge, edgeCurve, compatibleTargetsForWire, conditionVerdictSummary, entryRunButtonState, outputSocketX, inputSocketPos, outputSocketPos, normalizeRefsUI, clampMenuPos, cloneSelection, DEFAULT_SHORTCUTS, normalizeShortcut, formatShortcutFromEvent, matchesShortcut, applyShortcutBinding },
|
|
4587
5521
|
};
|
|
4588
5522
|
},
|
|
4589
5523
|
});
|