dsh-workflow-canvas 1.3.0 → 1.4.1
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 +11 -8
- package/README.zh.md +11 -8
- package/client.js +1099 -297
- package/index.js +87 -13
- package/package.json +20 -2
- package/skills/workflow-canvas/SKILL.md +4 -3
package/client.js
CHANGED
|
@@ -31,6 +31,18 @@ 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
|
+
redo: 'Ctrl+Shift+Z',
|
|
41
|
+
fitView: '',
|
|
42
|
+
autoLayout: '',
|
|
43
|
+
toggleDir: '',
|
|
44
|
+
};
|
|
45
|
+
const SHORTCUT_ORDER = ['addNode', 'duplicate', 'delete', 'undo', 'redo', 'fitView', 'autoLayout', 'toggleDir'];
|
|
34
46
|
|
|
35
47
|
const NODE_W = 216;
|
|
36
48
|
const NODE_H = 234;
|
|
@@ -103,7 +115,7 @@ window.__ModuleLoader__.load({
|
|
|
103
115
|
const LANG_KEY = STORAGE_PREFIX + 'lang';
|
|
104
116
|
const I18N = {
|
|
105
117
|
zh: {
|
|
106
|
-
addAgent: '+ 子代理', addLead: '+ Lead', addCond: '+ 条件', undo: '↶ 撤销', sync: '↥ 同步',
|
|
118
|
+
addAgent: '+ 子代理', addLead: '+ Lead', addCond: '+ 条件', undo: '↶ 撤销', redo: '↷ 重做', sync: '↥ 同步',
|
|
107
119
|
enabled: '● 已启用', disabled: '○ 已禁用', presetName: '预设名', save: '☆ 保存',
|
|
108
120
|
presets: '☰ 预设', unsaved: '有未同步改动', synced: '已同步',
|
|
109
121
|
pickModel: '选择模型', loadingModels: '加载中…', defaultEffort: '默认',
|
|
@@ -154,7 +166,7 @@ window.__ModuleLoader__.load({
|
|
|
154
166
|
loadedPreset: '已载入预设', invalidPreset: '预设内容无效', deletedPreset: '已删除预设',
|
|
155
167
|
syncFailed: '同步失败', upToDate: '已是最新', syncedToHost: '已同步到 Host',
|
|
156
168
|
syncedWithStdWarn: '已同步(含可写/命令节点,请确认主对话权限已放开)',
|
|
157
|
-
cannotOpen: '无法打开会话', undoDone: '已撤销', undoNone: '没有可撤销的操作',
|
|
169
|
+
cannotOpen: '无法打开会话', undoDone: '已撤销', undoNone: '没有可撤销的操作', redoDone: '已重做', redoNone: '没有可重做的操作',
|
|
158
170
|
leadLocked: '入口 Lead 不能删除', modelsMissing: '模型列表未加载',
|
|
159
171
|
tipLead: 'Lead 步骤在对话里执行,画布不追踪其状态',
|
|
160
172
|
tipOrphan: '未连线:运行时会被跳过', tipStatus: '子代理节点的运行状态',
|
|
@@ -181,12 +193,12 @@ window.__ModuleLoader__.load({
|
|
|
181
193
|
'6. 连好后点「● 已启用」,然后对对话说「跑一次」,由我调用执行。',
|
|
182
194
|
'7. 遇到 Lead 节点会暂停,我做完再把结果交回去继续。',
|
|
183
195
|
'8. 没连线的节点显示为虚线,运行时会被跳过。',
|
|
184
|
-
'9.
|
|
196
|
+
'9. 右键单击节点 / 连线 / 空白处可弹出快捷菜单(含线上插点、复制删除、新建节点等);按住右键划过连线可切断(可在「⋯」开关)。',
|
|
185
197
|
'10. 点右上角「☰ 预设」顶部即可保存当前画布,开新对话时一键载入跨会话复用。',
|
|
186
198
|
'11. 你可以直接让我改画布:说「把那三个节点的分工改成…」,我会就地修改,不动你摆的位置。',
|
|
187
199
|
'12. session 线连到 Lead 时,我会在暂停那步拿到那个子代理的会话,可以继续追问它。',
|
|
188
200
|
'13. 按住鼠标中键(或空格 + 左键)拖动画布平移;点击子代理节点左下角状态可直达它的对话记录。',
|
|
189
|
-
'14.
|
|
201
|
+
'14. 快捷键:默认 Shift+A 新建节点,Shift+D 复制节点与连线,Delete 删除,Ctrl+Z 撤销,Esc 关闭弹窗(可在「⋯ → 快捷键设置」自定义)。',
|
|
190
202
|
].join('\n'),
|
|
191
203
|
openChat: '会话',
|
|
192
204
|
tipOpenRun: '点击打开该子代理的对话记录',
|
|
@@ -224,6 +236,42 @@ window.__ModuleLoader__.load({
|
|
|
224
236
|
condSideR: '右出',
|
|
225
237
|
condSideL: '左出',
|
|
226
238
|
tipCondSide: '竖排模式下切换分支输出口在左侧或右侧',
|
|
239
|
+
refsBtn: '参考',
|
|
240
|
+
refsTitleGlobal: '全局参考 / 约束(注入所有节点)',
|
|
241
|
+
refsTitleNode: '节点参考 / 约束',
|
|
242
|
+
refsAdd: '+ 添加参考',
|
|
243
|
+
refsPh: '文件路径、URL 或约束条款,如 src/auth.js',
|
|
244
|
+
refsEmpty: '点击下方按钮添加参考文件、路径或规范约束(最多 16 条)',
|
|
245
|
+
tipRefs: '附加参考文件、目录或约束清单,运行时自动注入提示词',
|
|
246
|
+
delRefTip: '删除该参考项',
|
|
247
|
+
ctxNodeTitle: '节点操作',
|
|
248
|
+
ctxEdgeTitle: '连线操作',
|
|
249
|
+
ctxCanvasTitle: '画布操作',
|
|
250
|
+
ctxDup: '复制节点',
|
|
251
|
+
ctxDelNode: '删除节点',
|
|
252
|
+
ctxOpenChat: '打开子代理对话 ↗',
|
|
253
|
+
ctxEditText: '展开编辑文本',
|
|
254
|
+
ctxManageRefs: '管理参考清单',
|
|
255
|
+
ctxDelEdge: '删除连线',
|
|
256
|
+
ctxInsertAgent: '在此插入子代理',
|
|
257
|
+
ctxInsertCond: '在此插入条件节点',
|
|
258
|
+
ctxLangToggle: '界面语言',
|
|
259
|
+
shortcutsMenu: '⌨ 快捷键设置',
|
|
260
|
+
shortcutsTitle: '快捷键设置',
|
|
261
|
+
shortcutsHint: '点击右侧按键框后按下新组合键;按 Esc 取消录制,点 × 清除绑定。',
|
|
262
|
+
shortcutsReset: '恢复默认',
|
|
263
|
+
shortcutsPress: '请按键…',
|
|
264
|
+
shortcutsUnset: '未设置',
|
|
265
|
+
shortcutsResetOk: '快捷键已恢复默认',
|
|
266
|
+
shortcutsConflict: '已更新快捷键(原冲突项已清空)',
|
|
267
|
+
scAddNode: '新建节点(光标处)',
|
|
268
|
+
scDuplicate: '复制选中节点与连线',
|
|
269
|
+
scDelete: '删除选中节点',
|
|
270
|
+
scUndo: '撤销',
|
|
271
|
+
scRedo: '重做',
|
|
272
|
+
scFitView: '全览居中',
|
|
273
|
+
scAutoLayout: '自动排版',
|
|
274
|
+
scToggleDir: '切换横排 / 竖排',
|
|
227
275
|
fxLabel: '视觉效果',
|
|
228
276
|
fxMinimal: '极简',
|
|
229
277
|
fxStandard: '标准',
|
|
@@ -233,13 +281,13 @@ window.__ModuleLoader__.load({
|
|
|
233
281
|
tipLeadReady: '上游节点已全部完成,正等待在对话里拍板继续',
|
|
234
282
|
stDeadEnd: '无出边',
|
|
235
283
|
tipDeadEnd: '该子代理没有下游连线,运行时不生效;请连入下游节点或终审 Lead',
|
|
236
|
-
stSoloLead: '
|
|
237
|
-
tipSoloLead: '该 Lead
|
|
284
|
+
stSoloLead: '待填分工',
|
|
285
|
+
tipSoloLead: '该 Lead 阶段未连入子代理且分工为空,填写分工后即可作为主对话阶段运行',
|
|
238
286
|
singleModelHint: '当前仅 1 个可用模型,暂无其它备用路由',
|
|
239
287
|
importNone: '剪贴板里没有可识别的画布数据',
|
|
240
288
|
importBad: '画布数据格式不对',
|
|
241
289
|
tipSync: '把当前画布同步给 Host(会在对话里留一条同步记录)',
|
|
242
|
-
tipUndo: '撤销上一步结构改动', tipSave: '把当前画布保存为预设(可在新会话载入)',
|
|
290
|
+
tipUndo: '撤销上一步结构改动', tipRedo: '重做上一步撤销的改动(Ctrl+Shift+Z / Ctrl+Y)', tipSave: '把当前画布保存为预设(可在新会话载入)',
|
|
243
291
|
tipPresets: '保存当前画布、跨会话复用,或载入内置模板', tipModel: '推理等级(默认 = 该模型声明的 defaultEffort)',
|
|
244
292
|
tipMemory: '记忆:复用这个节点上一次的会话(跨运行及重启后可恢复)',
|
|
245
293
|
memLatest: '最新',
|
|
@@ -253,7 +301,7 @@ window.__ModuleLoader__.load({
|
|
|
253
301
|
lang: 'ZH',
|
|
254
302
|
},
|
|
255
303
|
en: {
|
|
256
|
-
addAgent: '+ Subagent', addLead: '+ Lead', addCond: '+ Condition', undo: '↶ Undo', sync: '↥ Sync',
|
|
304
|
+
addAgent: '+ Subagent', addLead: '+ Lead', addCond: '+ Condition', undo: '↶ Undo', redo: '↷ Redo', sync: '↥ Sync',
|
|
257
305
|
enabled: '● ON', disabled: '○ OFF', presetName: 'Preset name', save: '☆ Save',
|
|
258
306
|
presets: '☰ Presets', unsaved: 'Unsaved changes', synced: 'Synced',
|
|
259
307
|
pickModel: 'Pick a model', loadingModels: 'Loading…', defaultEffort: 'default',
|
|
@@ -304,7 +352,7 @@ window.__ModuleLoader__.load({
|
|
|
304
352
|
loadedPreset: 'Loaded preset', invalidPreset: 'Preset content is invalid', deletedPreset: 'Deleted preset',
|
|
305
353
|
syncFailed: 'Sync failed', upToDate: 'Already up to date', syncedToHost: 'Synced to host',
|
|
306
354
|
syncedWithStdWarn: 'Synced (has write/tool nodes — check main chat permission mode)',
|
|
307
|
-
cannotOpen: 'Cannot open the session', undoDone: 'Undone', undoNone: 'Nothing to undo',
|
|
355
|
+
cannotOpen: 'Cannot open the session', undoDone: 'Undone', undoNone: 'Nothing to undo', redoDone: 'Redone', redoNone: 'Nothing to redo',
|
|
308
356
|
leadLocked: 'The entry Lead cannot be deleted', modelsMissing: 'Model list is not loaded',
|
|
309
357
|
tipLead: 'Lead steps run in the chat; the canvas does not track them',
|
|
310
358
|
tipOrphan: 'Unlinked: skipped when the canvas runs', tipStatus: 'Subagent run status',
|
|
@@ -331,12 +379,12 @@ window.__ModuleLoader__.load({
|
|
|
331
379
|
'6. Press ● ON, then ask in chat to run the canvas.',
|
|
332
380
|
'7. The run pauses at every Lead node so the conversation can do that step.',
|
|
333
381
|
'8. Unlinked nodes are dashed and skipped at run time.',
|
|
334
|
-
'9.
|
|
382
|
+
'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 ⋯).',
|
|
335
383
|
'10. Open ☰ Presets to save the current canvas at the top and load it in any new chat.',
|
|
336
384
|
'11. You can ask me to edit the canvas; I patch it in place and keep your layout.',
|
|
337
385
|
'12. A session link into a Lead step hands me that child agent, so I can follow up with it.',
|
|
338
386
|
'13. Hold the middle mouse button (or Space + drag) to pan; click a subagent status badge at the bottom-left to open its chat.',
|
|
339
|
-
'14. Shortcuts: Shift+A adds a node at cursor,
|
|
387
|
+
'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).',
|
|
340
388
|
].join('\n'),
|
|
341
389
|
openChat: 'Chat',
|
|
342
390
|
tipOpenRun: 'Click to open this subagent conversation',
|
|
@@ -374,6 +422,42 @@ window.__ModuleLoader__.load({
|
|
|
374
422
|
condSideR: 'Out R',
|
|
375
423
|
condSideL: 'Out L',
|
|
376
424
|
tipCondSide: 'Flip condition branch sockets between left and right edges in vertical mode',
|
|
425
|
+
refsBtn: 'Refs',
|
|
426
|
+
refsTitleGlobal: 'Global references / rules (all nodes)',
|
|
427
|
+
refsTitleNode: 'Node references / rules',
|
|
428
|
+
refsAdd: '+ Add ref',
|
|
429
|
+
refsPh: 'File path, URL, or rule, e.g. src/auth.js',
|
|
430
|
+
refsEmpty: 'Add reference files, paths, or rules injected into prompts (up to 16)',
|
|
431
|
+
tipRefs: 'Attach reference files, paths, or constraints injected at run time',
|
|
432
|
+
delRefTip: 'Remove this reference',
|
|
433
|
+
ctxNodeTitle: 'Node',
|
|
434
|
+
ctxEdgeTitle: 'Link',
|
|
435
|
+
ctxCanvasTitle: 'Canvas',
|
|
436
|
+
ctxDup: 'Duplicate',
|
|
437
|
+
ctxDelNode: 'Delete',
|
|
438
|
+
ctxOpenChat: 'Open chat ↗',
|
|
439
|
+
ctxEditText: 'Expand editor',
|
|
440
|
+
ctxManageRefs: 'Manage refs',
|
|
441
|
+
ctxDelEdge: 'Delete link',
|
|
442
|
+
ctxInsertAgent: 'Insert Subagent here',
|
|
443
|
+
ctxInsertCond: 'Insert Condition here',
|
|
444
|
+
ctxLangToggle: 'Language',
|
|
445
|
+
shortcutsMenu: '⌨ Shortcuts',
|
|
446
|
+
shortcutsTitle: 'Keyboard Shortcuts',
|
|
447
|
+
shortcutsHint: 'Click a key button then press a new combo. Press Esc to cancel, or × to clear.',
|
|
448
|
+
shortcutsReset: 'Reset defaults',
|
|
449
|
+
shortcutsPress: 'Press keys…',
|
|
450
|
+
shortcutsUnset: 'Unbound',
|
|
451
|
+
shortcutsResetOk: 'Shortcuts reset to defaults',
|
|
452
|
+
shortcutsConflict: 'Shortcut updated (cleared conflict)',
|
|
453
|
+
scAddNode: 'Add node at cursor',
|
|
454
|
+
scDuplicate: 'Duplicate nodes & links',
|
|
455
|
+
scDelete: 'Delete selected nodes',
|
|
456
|
+
scUndo: 'Undo',
|
|
457
|
+
scRedo: 'Redo',
|
|
458
|
+
scFitView: 'Fit all in view',
|
|
459
|
+
scAutoLayout: 'Auto layout',
|
|
460
|
+
scToggleDir: 'Toggle Horiz / Vert layout',
|
|
377
461
|
fxLabel: 'Visual effects',
|
|
378
462
|
fxMinimal: 'Minimal',
|
|
379
463
|
fxStandard: 'Standard',
|
|
@@ -383,13 +467,13 @@ window.__ModuleLoader__.load({
|
|
|
383
467
|
tipLeadReady: 'Upstream steps are done; waiting for Lead in chat',
|
|
384
468
|
stDeadEnd: 'No out-link',
|
|
385
469
|
tipDeadEnd: 'This subagent has no outgoing link and is skipped at run time; wire it into a downstream node or Lead',
|
|
386
|
-
stSoloLead: 'Needs
|
|
387
|
-
tipSoloLead: 'This Lead
|
|
470
|
+
stSoloLead: 'Needs role',
|
|
471
|
+
tipSoloLead: 'This chained Lead stage has no subagent upstream and an empty role; fill in a role to make it active',
|
|
388
472
|
singleModelHint: 'Only 1 model available — no alternate fallback route',
|
|
389
473
|
importNone: 'No canvas data found in the clipboard',
|
|
390
474
|
importBad: 'Canvas data is malformed',
|
|
391
475
|
tipSync: 'Publish this canvas to the host (leaves one sync record in the chat)',
|
|
392
|
-
tipUndo: 'Undo the last structural change', tipSave: 'Save this canvas as a preset (reusable in new chats)',
|
|
476
|
+
tipUndo: 'Undo the last structural change', tipRedo: 'Redo the last undone change (Ctrl+Shift+Z / Ctrl+Y)', tipSave: 'Save this canvas as a preset (reusable in new chats)',
|
|
393
477
|
tipPresets: 'Save this canvas for new chats, or load a preset / starter template', tipModel: 'Reasoning effort (default = the model\'s defaultEffort)',
|
|
394
478
|
tipMemory: 'Memory: reuse this node\'s previous session (persisted across runs and restarts)',
|
|
395
479
|
memLatest: 'Latest',
|
|
@@ -438,16 +522,16 @@ window.__ModuleLoader__.load({
|
|
|
438
522
|
background: C.base, color: C.text, fontSize: '13px',
|
|
439
523
|
},
|
|
440
524
|
toolbar: {
|
|
441
|
-
display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: '
|
|
442
|
-
padding: '8px
|
|
525
|
+
display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: '5px',
|
|
526
|
+
padding: '6px 8px', borderBottom: '1px solid ' + C.border, flex: '0 0 auto',
|
|
443
527
|
},
|
|
444
528
|
btn: {
|
|
445
|
-
padding: '
|
|
446
|
-
background: C.raised, color: C.text, fontSize: '
|
|
529
|
+
padding: '4px 8px', borderRadius: '6px', border: '1px solid ' + C.border,
|
|
530
|
+
background: C.raised, color: C.text, fontSize: '11px', cursor: 'pointer', whiteSpace: 'nowrap',
|
|
447
531
|
},
|
|
448
532
|
btnDirty: {
|
|
449
|
-
padding: '
|
|
450
|
-
background: C.raised, color: C.accent, fontSize: '
|
|
533
|
+
padding: '4px 8px', borderRadius: '6px', border: '1px solid ' + C.accent,
|
|
534
|
+
background: C.raised, color: C.accent, fontSize: '11px', fontWeight: 600,
|
|
451
535
|
cursor: 'pointer', whiteSpace: 'nowrap',
|
|
452
536
|
},
|
|
453
537
|
toolSep: {
|
|
@@ -480,6 +564,21 @@ window.__ModuleLoader__.load({
|
|
|
480
564
|
background: C.elevated, color: C.dim, fontSize: '11px', fontWeight: 600,
|
|
481
565
|
cursor: 'pointer', boxShadow: '0 4px 14px rgba(0,0,0,0.35)',
|
|
482
566
|
},
|
|
567
|
+
floatZoomBar: {
|
|
568
|
+
position: 'absolute', right: '10px', bottom: '10px', zIndex: 30,
|
|
569
|
+
display: 'inline-flex', alignItems: 'center', gap: '4px',
|
|
570
|
+
padding: '3px 5px', borderRadius: '999px',
|
|
571
|
+
background: C.elevated, border: '1px solid ' + C.border,
|
|
572
|
+
boxShadow: '0 4px 14px rgba(0,0,0,0.28)',
|
|
573
|
+
},
|
|
574
|
+
floatZoomBtn: {
|
|
575
|
+
padding: '2px 6px', borderRadius: '999px', border: 'none',
|
|
576
|
+
background: 'transparent', color: C.text, fontSize: '11px',
|
|
577
|
+
cursor: 'pointer', whiteSpace: 'nowrap', lineHeight: '16px',
|
|
578
|
+
},
|
|
579
|
+
ctxDivider: {
|
|
580
|
+
height: '1px', background: C.border, opacity: 0.65, margin: '3px 4px',
|
|
581
|
+
},
|
|
483
582
|
canvasWrap: {
|
|
484
583
|
position: 'relative', flex: '1 1 auto', minHeight: '0',
|
|
485
584
|
display: 'flex', flexDirection: 'column',
|
|
@@ -527,6 +626,19 @@ window.__ModuleLoader__.load({
|
|
|
527
626
|
helpTitle: { flex: '1 1 auto', fontSize: '13px', fontWeight: 600, color: C.text },
|
|
528
627
|
helpBody: { fontSize: '11px', lineHeight: '17px', color: C.dim },
|
|
529
628
|
helpLine: { whiteSpace: 'pre-wrap' },
|
|
629
|
+
shortcutRow: {
|
|
630
|
+
display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px',
|
|
631
|
+
padding: '6px 2px', borderBottom: '1px solid ' + C.border, fontSize: '11px', color: C.text,
|
|
632
|
+
},
|
|
633
|
+
shortcutKeyBtn: {
|
|
634
|
+
minWidth: '88px', padding: '3px 8px', borderRadius: '5px',
|
|
635
|
+
border: '1px solid ' + C.border, background: C.base, color: C.text,
|
|
636
|
+
fontSize: '11px', fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace',
|
|
637
|
+
cursor: 'pointer', textAlign: 'center', outline: 'none', whiteSpace: 'nowrap',
|
|
638
|
+
},
|
|
639
|
+
shortcutKeyRec: {
|
|
640
|
+
borderColor: C.accent, background: C.hover, color: C.accent, fontWeight: 600,
|
|
641
|
+
},
|
|
530
642
|
presetBar: {
|
|
531
643
|
marginLeft: 'auto', display: 'flex', alignItems: 'center',
|
|
532
644
|
gap: '6px', position: 'relative', flex: '0 0 auto',
|
|
@@ -583,13 +695,13 @@ window.__ModuleLoader__.load({
|
|
|
583
695
|
},
|
|
584
696
|
|
|
585
697
|
title: {
|
|
586
|
-
position: 'absolute', left: '10px', right: '
|
|
698
|
+
position: 'absolute', left: '10px', right: '62px', top: '8px', height: '18px',
|
|
587
699
|
fontWeight: 600, fontSize: '12px', lineHeight: '18px',
|
|
588
700
|
border: 'none', background: 'transparent', color: C.text, padding: 0, margin: 0,
|
|
589
701
|
outline: 'none', boxSizing: 'border-box', userSelect: 'text', zIndex: 2,
|
|
590
702
|
},
|
|
591
703
|
titleReadonly: {
|
|
592
|
-
position: 'absolute', left: '10px', right: '
|
|
704
|
+
position: 'absolute', left: '10px', right: '62px', top: '8px', height: '18px',
|
|
593
705
|
fontWeight: 600, fontSize: '12px', lineHeight: '18px',
|
|
594
706
|
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', zIndex: 2,
|
|
595
707
|
},
|
|
@@ -763,8 +875,7 @@ window.__ModuleLoader__.load({
|
|
|
763
875
|
position: 'absolute', top: (ROW_H - PORT) / 2, width: PORT, height: PORT,
|
|
764
876
|
borderRadius: '50%', background: C.raised, border: '2px solid ' + C.border,
|
|
765
877
|
boxSizing: 'border-box', cursor: 'crosshair', zIndex: 6,
|
|
766
|
-
|
|
767
|
-
padding: 0, margin: -3, boxShadow: '0 0 0 3px transparent',
|
|
878
|
+
padding: 0, margin: 0, boxShadow: '0 0 0 3px transparent',
|
|
768
879
|
},
|
|
769
880
|
nodeDelete: {
|
|
770
881
|
position: 'absolute', right: '-8px', top: '-8px', width: '18px', height: '18px',
|
|
@@ -795,26 +906,116 @@ window.__ModuleLoader__.load({
|
|
|
795
906
|
padding: '9px 10px', zIndex: 65, boxShadow: '0 14px 32px rgba(0,0,0,0.52)',
|
|
796
907
|
color: C.text, fontSize: '11px', lineHeight: '1.5', userSelect: 'text',
|
|
797
908
|
},
|
|
909
|
+
refsPopover: {
|
|
910
|
+
position: 'absolute', left: '100%', top: '0', marginLeft: '8px', width: '268px',
|
|
911
|
+
background: C.elevated, color: C.text, border: '1px solid ' + C.border, borderRadius: '8px',
|
|
912
|
+
padding: '8px 9px', zIndex: 72, boxShadow: '0 12px 28px rgba(0,0,0,0.34)',
|
|
913
|
+
},
|
|
914
|
+
refsRow: {
|
|
915
|
+
display: 'flex', alignItems: 'center', gap: '4px', marginBottom: '5px',
|
|
916
|
+
},
|
|
917
|
+
refsInput: {
|
|
918
|
+
flex: '1 1 auto', minWidth: 0, height: '22px', boxSizing: 'border-box',
|
|
919
|
+
padding: '0 6px', borderRadius: '4px', border: '1px solid ' + C.border,
|
|
920
|
+
background: C.base, color: C.text, fontSize: '10px', outline: 'none', userSelect: 'text',
|
|
921
|
+
},
|
|
798
922
|
};
|
|
799
923
|
|
|
800
924
|
let hostCtx = null;
|
|
801
925
|
let cachedModels = [];
|
|
802
926
|
|
|
927
|
+
function normalizeRefsUI(rawRefs) {
|
|
928
|
+
if (!Array.isArray(rawRefs) || !rawRefs.length) return [];
|
|
929
|
+
const out = [];
|
|
930
|
+
const seen = new Set();
|
|
931
|
+
for (const r of rawRefs) {
|
|
932
|
+
if (out.length >= 16) break;
|
|
933
|
+
const s = typeof r === 'string' ? r.trim() : '';
|
|
934
|
+
if (!s || seen.has(s)) continue;
|
|
935
|
+
seen.add(s);
|
|
936
|
+
out.push(s);
|
|
937
|
+
}
|
|
938
|
+
return out;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/**
|
|
942
|
+
* Clamp a floating context menu inside the canvas wrap, flipping left/up when near the
|
|
943
|
+
* right or bottom edge so menu items never clip off narrow sidebars.
|
|
944
|
+
*/
|
|
945
|
+
function clampMenuPos(cx, cy, wrapW, wrapH, menuW, menuH) {
|
|
946
|
+
const pad = 8;
|
|
947
|
+
const sx = (cx + menuW > wrapW - pad)
|
|
948
|
+
? Math.max(pad, cx - menuW)
|
|
949
|
+
: Math.max(pad, Math.min(wrapW - menuW - pad, cx));
|
|
950
|
+
const sy = (cy + menuH > wrapH - pad)
|
|
951
|
+
? Math.max(pad, cy - menuH)
|
|
952
|
+
: Math.max(pad, Math.min(wrapH - menuH - pad, cy));
|
|
953
|
+
return { sx, sy };
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
/**
|
|
957
|
+
* Clone all selected non-entry nodes and every internal edge connecting two cloned nodes,
|
|
958
|
+
* preserving edge type and condition branch while isolating mutable array fields.
|
|
959
|
+
*/
|
|
960
|
+
function cloneSelection(nodes, edges, selectedIds, stampOverride) {
|
|
961
|
+
const selSet = new Set((selectedIds || []).filter((id) => id !== 'lead'));
|
|
962
|
+
const sources = (nodes || []).filter((n) => n && selSet.has(n.id));
|
|
963
|
+
if (!sources.length) return { clones: [], clonedEdges: [] };
|
|
964
|
+
const stamp = stampOverride || Date.now().toString(36);
|
|
965
|
+
const idMap = new Map();
|
|
966
|
+
const clones = sources.map((src, idx) => {
|
|
967
|
+
const { runs: _runs, ...rest } = src;
|
|
968
|
+
const newId = 'n' + stamp + '_' + idx + Math.random().toString(36).slice(2, 4);
|
|
969
|
+
idMap.set(src.id, newId);
|
|
970
|
+
const clone = {
|
|
971
|
+
...rest,
|
|
972
|
+
id: newId,
|
|
973
|
+
x: (src.x || 0) + 28,
|
|
974
|
+
y: (src.y || 0) + 28,
|
|
975
|
+
};
|
|
976
|
+
if (Array.isArray(src.refs)) clone.refs = src.refs.slice();
|
|
977
|
+
if (Array.isArray(src.branches)) clone.branches = src.branches.map((b) => ({ ...b }));
|
|
978
|
+
return clone;
|
|
979
|
+
});
|
|
980
|
+
const clonedEdges = [];
|
|
981
|
+
let edgeIdx = 0;
|
|
982
|
+
for (const e of edges || []) {
|
|
983
|
+
if (!e || !idMap.has(e.from) || !idMap.has(e.to)) continue;
|
|
984
|
+
const nextEdge = {
|
|
985
|
+
...e,
|
|
986
|
+
id: 'e' + stamp + '_' + (edgeIdx++) + Math.random().toString(36).slice(2, 4),
|
|
987
|
+
from: idMap.get(e.from),
|
|
988
|
+
to: idMap.get(e.to),
|
|
989
|
+
};
|
|
990
|
+
clonedEdges.push(nextEdge);
|
|
991
|
+
}
|
|
992
|
+
return { clones, clonedEdges };
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
/** Compute the next node selection when clicking `id` (Shift/Ctrl toggles membership). */
|
|
996
|
+
function nextSelectionOnNodeClick(selectedIds, id, additive) {
|
|
997
|
+
const cur = Array.isArray(selectedIds) ? selectedIds : [];
|
|
998
|
+
if (additive) {
|
|
999
|
+
if (cur.includes(id)) return { next: cur.filter((x) => x !== id), toggledOff: true };
|
|
1000
|
+
return { next: cur.concat([id]), toggledOff: false };
|
|
1001
|
+
}
|
|
1002
|
+
return { next: cur.includes(id) ? cur : [id], toggledOff: false };
|
|
1003
|
+
}
|
|
1004
|
+
|
|
803
1005
|
function socketCenterY(i) {
|
|
804
1006
|
return SOCKET_BAND_TOP + i * ROW_H + ROW_H / 2;
|
|
805
1007
|
}
|
|
806
1008
|
|
|
807
1009
|
/**
|
|
808
1010
|
* Determine which node kinds can legally receive a wire dragged out from `fromNode`.
|
|
809
|
-
*
|
|
1011
|
+
* All non-entry targets (agent, lead, condition) are valid, including Lead -> Lead stage chains.
|
|
810
1012
|
*/
|
|
811
|
-
function compatibleTargetsForWire(
|
|
812
|
-
const fromLead = Boolean(fromNode && fromNode.kind === 'lead');
|
|
1013
|
+
function compatibleTargetsForWire(_fromNode, _edgeType) {
|
|
813
1014
|
return {
|
|
814
1015
|
agent: true,
|
|
815
|
-
lead:
|
|
1016
|
+
lead: true,
|
|
816
1017
|
condition: true,
|
|
817
|
-
leadBlockedReason:
|
|
1018
|
+
leadBlockedReason: '',
|
|
818
1019
|
};
|
|
819
1020
|
}
|
|
820
1021
|
|
|
@@ -955,7 +1156,7 @@ window.__ModuleLoader__.load({
|
|
|
955
1156
|
|
|
956
1157
|
function inputSocketPos(node, direction) {
|
|
957
1158
|
if (direction === 'tb') return { x: node.x + NODE_W / 2, y: node.y };
|
|
958
|
-
return { x: node.x, y: node.y + socketCenterY(0) };
|
|
1159
|
+
return { x: node.x, y: node.y + socketCenterY(0, node) };
|
|
959
1160
|
}
|
|
960
1161
|
|
|
961
1162
|
function outputSocketPos(fromNode, type, branch, direction) {
|
|
@@ -1059,7 +1260,7 @@ window.__ModuleLoader__.load({
|
|
|
1059
1260
|
const x1 = from.x + WORLD_PAD + NODE_W;
|
|
1060
1261
|
const y1 = from.y + WORLD_PAD + outputSocketY(from, type, branch);
|
|
1061
1262
|
const x2 = to.x + WORLD_PAD;
|
|
1062
|
-
const y2 = to.y + WORLD_PAD + socketCenterY(0);
|
|
1263
|
+
const y2 = to.y + WORLD_PAD + socketCenterY(0, to);
|
|
1063
1264
|
const dx = Math.max(40, Math.abs(x2 - x1) * 0.5);
|
|
1064
1265
|
return { x1, y1, c1x: x1 + dx, c1y: y1, c2x: x2 - dx, c2y: y2, x2, y2 };
|
|
1065
1266
|
}
|
|
@@ -1139,8 +1340,8 @@ window.__ModuleLoader__.load({
|
|
|
1139
1340
|
|
|
1140
1341
|
/**
|
|
1141
1342
|
* Reachable non-entry Lead nodes that have zero reachable subagent upstream
|
|
1142
|
-
*
|
|
1143
|
-
*
|
|
1343
|
+
* AND an empty `role` (blank placeholders). Filling a `role` turns them into
|
|
1344
|
+
* active main-conversation stage gates (Lead -> Lead chaining).
|
|
1144
1345
|
*/
|
|
1145
1346
|
function soloLeadNodeIds(nodes, edges) {
|
|
1146
1347
|
const list = Array.isArray(nodes) ? nodes : [];
|
|
@@ -1155,7 +1356,8 @@ window.__ModuleLoader__.load({
|
|
|
1155
1356
|
const src = byId.get(e.from);
|
|
1156
1357
|
return Boolean(src && src.kind !== 'lead');
|
|
1157
1358
|
});
|
|
1158
|
-
|
|
1359
|
+
const hasRole = Boolean(String(n.role || '').trim());
|
|
1360
|
+
if (!hasAgentUp && !hasRole) out.add(n.id);
|
|
1159
1361
|
}
|
|
1160
1362
|
return out;
|
|
1161
1363
|
}
|
|
@@ -1533,39 +1735,43 @@ window.__ModuleLoader__.load({
|
|
|
1533
1735
|
? Math.max(1, Math.min(8, Math.floor(Number(opts.maxParallel))))
|
|
1534
1736
|
: 4;
|
|
1535
1737
|
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1738
|
+
const entryRefs = normalizeRefsUI(entry.refs);
|
|
1739
|
+
const planOut = {
|
|
1740
|
+
task,
|
|
1741
|
+
maxParallel,
|
|
1742
|
+
skipped: skipped.map((n) => n.label || n.id),
|
|
1743
|
+
nodes: active.map((n) => {
|
|
1744
|
+
const kind = n.kind === 'lead' ? 'lead' : (n.kind === 'condition' ? 'condition' : 'agent');
|
|
1745
|
+
const out = {
|
|
1746
|
+
id: n.id,
|
|
1747
|
+
kind,
|
|
1748
|
+
label: n.label || n.id,
|
|
1749
|
+
role: n.role || '',
|
|
1750
|
+
provider: n.provider || '',
|
|
1751
|
+
model: n.model || '',
|
|
1752
|
+
reasoning: n.reasoning || '',
|
|
1753
|
+
preset: kind === 'condition' ? 'minimal' : (n.preset === 'minimal' ? 'minimal' : 'standard'),
|
|
1754
|
+
keepSession: kind === 'condition' ? false : Boolean(n.keepSession),
|
|
1755
|
+
memoryChildId: kind === 'condition' ? '' : (n.memoryChildId || ''),
|
|
1756
|
+
// A structured link is the only thing that decides this: no separate switch.
|
|
1757
|
+
structured: planEdges.some((e) => e.from === n.id && e.type === 'structured'),
|
|
1758
|
+
fallbackModel: n.fallbackModel || '',
|
|
1759
|
+
fallbackProvider: n.fallbackProvider || '',
|
|
1760
|
+
};
|
|
1761
|
+
if (kind === 'condition' && isCustomBranches(n)) {
|
|
1762
|
+
out.branches = conditionBranchesForUI(n).map((b) => ({ id: b.id, label: b.label }));
|
|
1763
|
+
}
|
|
1764
|
+
if (kind === 'condition' && n.multiMatch) {
|
|
1765
|
+
out.multiMatch = true;
|
|
1766
|
+
}
|
|
1767
|
+
const nodeRefs = normalizeRefsUI(n.refs);
|
|
1768
|
+
if (nodeRefs.length) out.refs = nodeRefs;
|
|
1769
|
+
return out;
|
|
1770
|
+
}),
|
|
1771
|
+
edges: planEdges,
|
|
1568
1772
|
};
|
|
1773
|
+
if (entryRefs.length) planOut.refs = entryRefs;
|
|
1774
|
+
return { plan: planOut };
|
|
1569
1775
|
}
|
|
1570
1776
|
|
|
1571
1777
|
function loadCutMode() {
|
|
@@ -1624,6 +1830,101 @@ window.__ModuleLoader__.load({
|
|
|
1624
1830
|
return PARALLEL_STEPS[(idx + 1) % PARALLEL_STEPS.length];
|
|
1625
1831
|
}
|
|
1626
1832
|
|
|
1833
|
+
/** Canonicalize a shortcut string like "shift+d" or "cmd+z" -> "Shift+D" / "Ctrl+Z". */
|
|
1834
|
+
function normalizeShortcut(raw) {
|
|
1835
|
+
if (typeof raw !== 'string') return '';
|
|
1836
|
+
const trimmed = raw.trim();
|
|
1837
|
+
if (!trimmed) return '';
|
|
1838
|
+
const parts = trimmed.split('+').map((p) => p.trim()).filter(Boolean);
|
|
1839
|
+
let ctrl = false;
|
|
1840
|
+
let alt = false;
|
|
1841
|
+
let shift = false;
|
|
1842
|
+
let key = '';
|
|
1843
|
+
for (const p of parts) {
|
|
1844
|
+
const low = p.toLowerCase();
|
|
1845
|
+
if (low === 'ctrl' || low === 'control' || low === 'cmd' || low === 'meta' || low === 'mod') ctrl = true;
|
|
1846
|
+
else if (low === 'alt' || low === 'option') alt = true;
|
|
1847
|
+
else if (low === 'shift') shift = true;
|
|
1848
|
+
else if (low === 'del' || low === 'delete') key = 'Delete';
|
|
1849
|
+
else if (low === 'backspace') key = 'Backspace';
|
|
1850
|
+
else if (low === 'space' || p === ' ') key = 'Space';
|
|
1851
|
+
else if (low === 'enter' || low === 'return') key = 'Enter';
|
|
1852
|
+
else if (low === 'tab') key = 'Tab';
|
|
1853
|
+
else if (/^f\d{1,2}$/i.test(p)) key = p.toUpperCase();
|
|
1854
|
+
else if (p.length === 1) key = p.toUpperCase();
|
|
1855
|
+
else key = p.charAt(0).toUpperCase() + p.slice(1);
|
|
1856
|
+
}
|
|
1857
|
+
if (!key || key === 'Escape') return '';
|
|
1858
|
+
return (ctrl ? 'Ctrl+' : '') + (alt ? 'Alt+' : '') + (shift ? 'Shift+' : '') + key;
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
/** Extract a canonical shortcut string from a KeyboardEvent, or null for bare modifiers / Esc. */
|
|
1862
|
+
function formatShortcutFromEvent(ev) {
|
|
1863
|
+
if (!ev) return null;
|
|
1864
|
+
const rawKey = typeof ev.key === 'string' ? ev.key : '';
|
|
1865
|
+
if (!rawKey || rawKey === 'Control' || rawKey === 'Shift' || rawKey === 'Alt' || rawKey === 'Meta' || rawKey === 'Escape') {
|
|
1866
|
+
return null;
|
|
1867
|
+
}
|
|
1868
|
+
const code = typeof ev.code === 'string' ? ev.code : '';
|
|
1869
|
+
let key = '';
|
|
1870
|
+
if (/^Key[A-Z]$/.test(code)) key = code.slice(3);
|
|
1871
|
+
else if (/^Digit[0-9]$/.test(code)) key = code.slice(5);
|
|
1872
|
+
else if (rawKey === ' ') key = 'Space';
|
|
1873
|
+
else if (rawKey === 'Delete' || rawKey === 'Backspace' || rawKey === 'Enter' || rawKey === 'Tab') key = rawKey;
|
|
1874
|
+
else if (/^F\d{1,2}$/i.test(rawKey)) key = rawKey.toUpperCase();
|
|
1875
|
+
else if (rawKey.length === 1) key = rawKey.toUpperCase();
|
|
1876
|
+
else key = rawKey;
|
|
1877
|
+
const ctrl = Boolean(ev.ctrlKey || ev.metaKey);
|
|
1878
|
+
const alt = Boolean(ev.altKey);
|
|
1879
|
+
const shift = Boolean(ev.shiftKey);
|
|
1880
|
+
return normalizeShortcut((ctrl ? 'Ctrl+' : '') + (alt ? 'Alt+' : '') + (shift ? 'Shift+' : '') + key) || null;
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
function matchesShortcut(ev, binding) {
|
|
1884
|
+
const target = normalizeShortcut(binding);
|
|
1885
|
+
if (!target) return false;
|
|
1886
|
+
const actual = formatShortcutFromEvent(ev);
|
|
1887
|
+
return Boolean(actual) && actual === target;
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
function applyShortcutBinding(map, actionId, combo) {
|
|
1891
|
+
const next = { ...DEFAULT_SHORTCUTS, ...(map || {}) };
|
|
1892
|
+
const norm = normalizeShortcut(combo);
|
|
1893
|
+
let clearedConflict = false;
|
|
1894
|
+
if (norm) {
|
|
1895
|
+
for (const k of SHORTCUT_ORDER) {
|
|
1896
|
+
if (k !== actionId && normalizeShortcut(next[k]) === norm) {
|
|
1897
|
+
next[k] = '';
|
|
1898
|
+
clearedConflict = true;
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
next[actionId] = norm;
|
|
1903
|
+
return { next, clearedConflict };
|
|
1904
|
+
}
|
|
1905
|
+
|
|
1906
|
+
function loadShortcuts() {
|
|
1907
|
+
try {
|
|
1908
|
+
const raw = window.localStorage.getItem(SHORTCUTS_KEY);
|
|
1909
|
+
if (!raw) return { ...DEFAULT_SHORTCUTS };
|
|
1910
|
+
const parsed = JSON.parse(raw);
|
|
1911
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return { ...DEFAULT_SHORTCUTS };
|
|
1912
|
+
const out = { ...DEFAULT_SHORTCUTS };
|
|
1913
|
+
for (const k of SHORTCUT_ORDER) {
|
|
1914
|
+
if (k in parsed) out[k] = normalizeShortcut(parsed[k]);
|
|
1915
|
+
}
|
|
1916
|
+
return out;
|
|
1917
|
+
} catch (_e) {
|
|
1918
|
+
return { ...DEFAULT_SHORTCUTS };
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
function saveShortcuts(map) {
|
|
1923
|
+
try {
|
|
1924
|
+
window.localStorage.setItem(SHORTCUTS_KEY, JSON.stringify(map));
|
|
1925
|
+
} catch (_e) { /* ignore */ }
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1627
1928
|
/** Pick 'left' or 'right' anchor so a wrapped toolbar dropdown never clips off the pane edge. */
|
|
1628
1929
|
function dropdownAlign(btnRect, containerRect, menuWidth) {
|
|
1629
1930
|
if (!btnRect || !containerRect) return 'right';
|
|
@@ -1739,7 +2040,7 @@ window.__ModuleLoader__.load({
|
|
|
1739
2040
|
if (!error) return this.props.children;
|
|
1740
2041
|
const message = String((error && error.message) || error);
|
|
1741
2042
|
const stack = String((error && error.stack) || '').slice(0, 900);
|
|
1742
|
-
|
|
2043
|
+
return h('div', {
|
|
1743
2044
|
style: {
|
|
1744
2045
|
padding: '12px', fontFamily: 'ui-monospace, monospace', fontSize: '11px',
|
|
1745
2046
|
color: '#e5534b', whiteSpace: 'pre-wrap', overflow: 'auto', height: '100%',
|
|
@@ -1764,6 +2065,11 @@ window.__ModuleLoader__.load({
|
|
|
1764
2065
|
const [menuAlign, setMenuAlign] = useState('right');
|
|
1765
2066
|
const [presetAlign, setPresetAlign] = useState('right');
|
|
1766
2067
|
const [helpOpen, setHelpOpen] = useState(false);
|
|
2068
|
+
const [shortcuts, setShortcuts] = useState(loadShortcuts);
|
|
2069
|
+
const shortcutsRef = useRef(shortcuts);
|
|
2070
|
+
shortcutsRef.current = shortcuts;
|
|
2071
|
+
const [shortcutsOpen, setShortcutsOpen] = useState(false);
|
|
2072
|
+
const [recordingAction, setRecordingAction] = useState(null);
|
|
1767
2073
|
const [cutMode, setCutMode] = useState(loadCutMode);
|
|
1768
2074
|
const [fxLevel, setFxLevel] = useState(loadEffectLevel);
|
|
1769
2075
|
const [maxParallel, setMaxParallel] = useState(loadMaxParallel);
|
|
@@ -1793,6 +2099,8 @@ window.__ModuleLoader__.load({
|
|
|
1793
2099
|
const pointerInsideRoot = useRef(false);
|
|
1794
2100
|
const lastMouseRef = useRef(null);
|
|
1795
2101
|
const [addMenu, setAddMenu] = useState(null);
|
|
2102
|
+
const [ctxMenu, setCtxMenu] = useState(null);
|
|
2103
|
+
const rightClickRef = useRef(null);
|
|
1796
2104
|
const nodeDrag = useRef(null);
|
|
1797
2105
|
const panDrag = useRef(null);
|
|
1798
2106
|
const [panning, setPanning] = useState(false);
|
|
@@ -1803,6 +2111,7 @@ window.__ModuleLoader__.load({
|
|
|
1803
2111
|
const syncTimer = useRef(null);
|
|
1804
2112
|
const lastSync = useRef('');
|
|
1805
2113
|
const historyRef = useRef([]);
|
|
2114
|
+
const redoRef = useRef([]);
|
|
1806
2115
|
const [dirty, setDirty] = useState(() => Boolean(initial && initial.enabled));
|
|
1807
2116
|
const [view, setView] = useState({ k: 1, x: 0, y: 0 });
|
|
1808
2117
|
const viewRef = useRef(view);
|
|
@@ -1811,6 +2120,7 @@ window.__ModuleLoader__.load({
|
|
|
1811
2120
|
const [runsById, setRunsById] = useState({});
|
|
1812
2121
|
const [runState, setRunState] = useState(null);
|
|
1813
2122
|
const [decisionViewFor, setDecisionViewFor] = useState(null);
|
|
2123
|
+
const [refsEditFor, setRefsEditFor] = useState(null);
|
|
1814
2124
|
const [sessionRunning, setSessionRunning] = useState(false);
|
|
1815
2125
|
const [runTriggering, setRunTriggering] = useState(false);
|
|
1816
2126
|
const runTriggeringRef = useRef(false);
|
|
@@ -2189,6 +2499,7 @@ window.__ModuleLoader__.load({
|
|
|
2189
2499
|
if (!e.ctrlKey && findScrollableChild(e.target, e.deltaY)) return;
|
|
2190
2500
|
e.preventDefault();
|
|
2191
2501
|
absorbScroll();
|
|
2502
|
+
setCtxMenu(null);
|
|
2192
2503
|
const rect = el.getBoundingClientRect();
|
|
2193
2504
|
const mx = e.clientX - rect.left;
|
|
2194
2505
|
const my = e.clientY - rect.top;
|
|
@@ -2333,21 +2644,35 @@ window.__ModuleLoader__.load({
|
|
|
2333
2644
|
};
|
|
2334
2645
|
}, []);
|
|
2335
2646
|
|
|
2336
|
-
// Snapshot before every structural change so a mis-click can be undone.
|
|
2647
|
+
// Snapshot before every structural change so a mis-click can be undone/redone.
|
|
2337
2648
|
const pushSnapshot = () => {
|
|
2338
|
-
historyRef.current.push({ nodes, edges });
|
|
2649
|
+
historyRef.current.push({ nodes: nodesRef.current, edges: edgesRef.current });
|
|
2339
2650
|
if (historyRef.current.length > 50) historyRef.current.shift();
|
|
2651
|
+
redoRef.current = [];
|
|
2340
2652
|
};
|
|
2341
2653
|
|
|
2342
2654
|
const undo = () => {
|
|
2343
2655
|
const prev = historyRef.current.pop();
|
|
2344
2656
|
if (!prev) { flash(t('undoNone')); return; }
|
|
2657
|
+
redoRef.current.push({ nodes: nodesRef.current, edges: edgesRef.current });
|
|
2658
|
+
if (redoRef.current.length > 50) redoRef.current.shift();
|
|
2345
2659
|
setNodes(prev.nodes);
|
|
2346
2660
|
setEdges(prev.edges);
|
|
2347
2661
|
setSelectedIds([]);
|
|
2348
2662
|
flash(t('undoDone'));
|
|
2349
2663
|
};
|
|
2350
2664
|
|
|
2665
|
+
const redo = () => {
|
|
2666
|
+
const next = redoRef.current.pop();
|
|
2667
|
+
if (!next) { flash(t('redoNone')); return; }
|
|
2668
|
+
historyRef.current.push({ nodes: nodesRef.current, edges: edgesRef.current });
|
|
2669
|
+
if (historyRef.current.length > 50) historyRef.current.shift();
|
|
2670
|
+
setNodes(next.nodes);
|
|
2671
|
+
setEdges(next.edges);
|
|
2672
|
+
setSelectedIds([]);
|
|
2673
|
+
flash(t('redoDone'));
|
|
2674
|
+
};
|
|
2675
|
+
|
|
2351
2676
|
const openRun = (node, run) => {
|
|
2352
2677
|
try {
|
|
2353
2678
|
const sr = hostCtx && hostCtx.sidebarRight;
|
|
@@ -2436,6 +2761,63 @@ window.__ModuleLoader__.load({
|
|
|
2436
2761
|
}
|
|
2437
2762
|
setSelectedIds([newId]);
|
|
2438
2763
|
setAddMenu(null);
|
|
2764
|
+
setCtxMenu(null);
|
|
2765
|
+
};
|
|
2766
|
+
|
|
2767
|
+
const deleteEdgeById = (edgeId) => {
|
|
2768
|
+
pushSnapshot();
|
|
2769
|
+
setEdges((es) => es.filter((e) => e.id !== edgeId));
|
|
2770
|
+
setCtxMenu(null);
|
|
2771
|
+
flash(t('linkCut') + ' ×1');
|
|
2772
|
+
};
|
|
2773
|
+
|
|
2774
|
+
const insertNodeOnEdge = (edgeId, kind, atWorld) => {
|
|
2775
|
+
const edge = edgesRef.current.find((e) => e.id === edgeId);
|
|
2776
|
+
if (!edge) { setCtxMenu(null); return; }
|
|
2777
|
+
pushSnapshot();
|
|
2778
|
+
const normKind = kind === 'condition' ? 'condition' : 'agent';
|
|
2779
|
+
const newId = 'n' + Date.now().toString(36) + Math.random().toString(36).slice(2, 4);
|
|
2780
|
+
const prefs = lastNodePrefsRef.current || {};
|
|
2781
|
+
setNodes((ns) => {
|
|
2782
|
+
const i = ns.length;
|
|
2783
|
+
const x = atWorld && typeof atWorld.x === 'number' ? Math.round(atWorld.x - NODE_W / 2) : 200;
|
|
2784
|
+
const y = atWorld && typeof atWorld.y === 'number' ? Math.round(atWorld.y - NODE_H / 2) : 140;
|
|
2785
|
+
const defaultLabel = normKind === 'condition'
|
|
2786
|
+
? (lang === 'en' ? 'Condition ' + i : '条件判断 ' + i)
|
|
2787
|
+
: 'Node ' + i;
|
|
2788
|
+
return [...ns, {
|
|
2789
|
+
id: newId,
|
|
2790
|
+
kind: normKind,
|
|
2791
|
+
x,
|
|
2792
|
+
y,
|
|
2793
|
+
label: defaultLabel,
|
|
2794
|
+
provider: prefs.provider || '',
|
|
2795
|
+
model: prefs.model || '',
|
|
2796
|
+
reasoning: prefs.reasoning || '',
|
|
2797
|
+
preset: normKind === 'condition' ? 'minimal' : (prefs.preset || 'standard'),
|
|
2798
|
+
role: '',
|
|
2799
|
+
}];
|
|
2800
|
+
});
|
|
2801
|
+
setEdges((es) => {
|
|
2802
|
+
const kept = es.filter((e) => e.id !== edgeId);
|
|
2803
|
+
const e1 = {
|
|
2804
|
+
id: 'e' + Date.now().toString(36) + 'a',
|
|
2805
|
+
from: edge.from,
|
|
2806
|
+
to: newId,
|
|
2807
|
+
type: edge.type || 'prompt',
|
|
2808
|
+
};
|
|
2809
|
+
if (edge.branch) e1.branch = edge.branch;
|
|
2810
|
+
const e2 = {
|
|
2811
|
+
id: 'e' + Date.now().toString(36) + 'b',
|
|
2812
|
+
from: newId,
|
|
2813
|
+
to: edge.to,
|
|
2814
|
+
type: 'prompt',
|
|
2815
|
+
};
|
|
2816
|
+
if (normKind === 'condition') e2.branch = 'true';
|
|
2817
|
+
return kept.concat([e1, e2]);
|
|
2818
|
+
});
|
|
2819
|
+
setSelectedIds([newId]);
|
|
2820
|
+
setCtxMenu(null);
|
|
2439
2821
|
};
|
|
2440
2822
|
|
|
2441
2823
|
const updateNode = (id, patch) => {
|
|
@@ -2477,25 +2859,11 @@ window.__ModuleLoader__.load({
|
|
|
2477
2859
|
};
|
|
2478
2860
|
|
|
2479
2861
|
const duplicateSelected = () => {
|
|
2480
|
-
const
|
|
2481
|
-
|
|
2482
|
-
const sources = curSel
|
|
2483
|
-
.filter((id) => id !== 'lead')
|
|
2484
|
-
.map((id) => curNodes.find((n) => n.id === id))
|
|
2485
|
-
.filter(Boolean);
|
|
2486
|
-
if (!sources.length) return;
|
|
2862
|
+
const { clones, clonedEdges } = cloneSelection(nodesRef.current, edgesRef.current, selectedIdsRef.current);
|
|
2863
|
+
if (!clones.length) return;
|
|
2487
2864
|
pushSnapshot();
|
|
2488
|
-
const stamp = Date.now().toString(36);
|
|
2489
|
-
const clones = sources.map((src, idx) => {
|
|
2490
|
-
const { runs: _runs, ...rest } = src;
|
|
2491
|
-
return {
|
|
2492
|
-
...rest,
|
|
2493
|
-
id: 'n' + stamp + '_' + idx + Math.random().toString(36).slice(2, 4),
|
|
2494
|
-
x: (src.x || 0) + 28,
|
|
2495
|
-
y: (src.y || 0) + 28,
|
|
2496
|
-
};
|
|
2497
|
-
});
|
|
2498
2865
|
setNodes((ns) => ns.concat(clones));
|
|
2866
|
+
if (clonedEdges.length) setEdges((es) => es.concat(clonedEdges));
|
|
2499
2867
|
setSelectedIds(clones.map((c) => c.id));
|
|
2500
2868
|
flash(t('duplicatedNodes') + ' ×' + clones.length);
|
|
2501
2869
|
};
|
|
@@ -2602,23 +2970,73 @@ window.__ModuleLoader__.load({
|
|
|
2602
2970
|
|
|
2603
2971
|
/** Dragging any selected node moves the whole selection together. */
|
|
2604
2972
|
const onNodeDown = (e, id) => {
|
|
2973
|
+
if (e.button === 2) {
|
|
2974
|
+
const tag = e.target && e.target.tagName;
|
|
2975
|
+
if (tag !== 'INPUT' && tag !== 'TEXTAREA') e.stopPropagation();
|
|
2976
|
+
return;
|
|
2977
|
+
}
|
|
2605
2978
|
if (e.button !== 0 || spaceDown.current) return;
|
|
2606
2979
|
if (!contentRef.current) return;
|
|
2607
2980
|
const node = nodes.find((n) => n.id === id);
|
|
2608
2981
|
if (!node) return;
|
|
2609
2982
|
const p = pointTo(e);
|
|
2610
|
-
const
|
|
2611
|
-
|
|
2983
|
+
const additive = Boolean(e.shiftKey || e.ctrlKey || e.metaKey);
|
|
2984
|
+
const { next: group, toggledOff } = nextSelectionOnNodeClick(selectedIds, id, additive);
|
|
2985
|
+
setSelectedIds(group);
|
|
2986
|
+
setOpenModelFor(null);
|
|
2987
|
+
setAddMenu(null);
|
|
2988
|
+
setCtxMenu(null);
|
|
2989
|
+
e.preventDefault();
|
|
2990
|
+
e.stopPropagation();
|
|
2991
|
+
if (toggledOff) return;
|
|
2612
2992
|
const origins = group
|
|
2613
2993
|
.map((nid) => nodes.find((n) => n.id === nid))
|
|
2614
2994
|
.filter(Boolean)
|
|
2615
2995
|
.map((n) => ({ id: n.id, x: n.x, y: n.y }));
|
|
2616
2996
|
nodeDrag.current = { origins, startX: p.x, startY: p.y, moved: false };
|
|
2617
2997
|
setDragging(true);
|
|
2618
|
-
|
|
2619
|
-
|
|
2998
|
+
};
|
|
2999
|
+
|
|
3000
|
+
const onNodeContextMenu = (e, node) => {
|
|
3001
|
+
const tag = e.target && e.target.tagName;
|
|
3002
|
+
if (tag === 'INPUT' || tag === 'TEXTAREA') return;
|
|
2620
3003
|
e.preventDefault();
|
|
2621
3004
|
e.stopPropagation();
|
|
3005
|
+
rightClickRef.current = null;
|
|
3006
|
+
const wrap = canvasWrapRef.current;
|
|
3007
|
+
if (!wrap) return;
|
|
3008
|
+
if (!selectedIdsRef.current.includes(node.id)) setSelectedIds([node.id]);
|
|
3009
|
+
const wrapRect = wrap.getBoundingClientRect();
|
|
3010
|
+
const pos = clampMenuPos(e.clientX - wrapRect.left, e.clientY - wrapRect.top, wrapRect.width, wrapRect.height, 180, 176);
|
|
3011
|
+
const world = pointTo(e);
|
|
3012
|
+
setCtxMenu({ kind: 'node', nodeId: node.id, sx: pos.sx, sy: pos.sy, wx: world.x, wy: world.y });
|
|
3013
|
+
setAddMenu(null);
|
|
3014
|
+
setMenuOpen(false);
|
|
3015
|
+
setPresetOpen(null);
|
|
3016
|
+
setOpenModelFor(null);
|
|
3017
|
+
setRoleEditFor(null);
|
|
3018
|
+
setDecisionViewFor(null);
|
|
3019
|
+
setRefsEditFor(null);
|
|
3020
|
+
};
|
|
3021
|
+
|
|
3022
|
+
const addNodeRef = (node) => {
|
|
3023
|
+
const cur = Array.isArray(node.refs) ? node.refs.slice() : [];
|
|
3024
|
+
if (cur.length >= 16) return;
|
|
3025
|
+
pushSnapshot();
|
|
3026
|
+
updateNode(node.id, { refs: cur.concat(['']) });
|
|
3027
|
+
};
|
|
3028
|
+
|
|
3029
|
+
const updateNodeRef = (node, idx, text) => {
|
|
3030
|
+
const cur = Array.isArray(node.refs) ? node.refs.slice() : [];
|
|
3031
|
+
cur[idx] = text;
|
|
3032
|
+
updateNode(node.id, { refs: cur });
|
|
3033
|
+
};
|
|
3034
|
+
|
|
3035
|
+
const removeNodeRef = (node, idx) => {
|
|
3036
|
+
const cur = Array.isArray(node.refs) ? node.refs.slice() : [];
|
|
3037
|
+
pushSnapshot();
|
|
3038
|
+
cur.splice(idx, 1);
|
|
3039
|
+
updateNode(node.id, { refs: cur });
|
|
2622
3040
|
};
|
|
2623
3041
|
|
|
2624
3042
|
const addConditionBranch = (node) => {
|
|
@@ -2812,12 +3230,12 @@ window.__ModuleLoader__.load({
|
|
|
2812
3230
|
};
|
|
2813
3231
|
}, []);
|
|
2814
3232
|
|
|
2815
|
-
//
|
|
3233
|
+
// Configurable canvas keyboard shortcuts (defaults: Shift+A, Shift+D, Delete, Ctrl+Z, Esc).
|
|
2816
3234
|
const keyActionsRef = useRef(null);
|
|
2817
3235
|
keyActionsRef.current = {
|
|
2818
|
-
undo, deleteSelected, duplicateSelected, openAddMenuAtCursor, addNode,
|
|
2819
|
-
addMenu, roleEditFor, openModelFor, menuOpen, presetOpen, helpOpen, decisionViewFor,
|
|
2820
|
-
setAddMenu, setRoleEditFor, setOpenModelFor, setMenuOpen, setPresetOpen, setHelpOpen, setDecisionViewFor,
|
|
3236
|
+
undo, redo, deleteSelected, duplicateSelected, openAddMenuAtCursor, addNode, fitView, autoLayout, toggleDirection, flash, t,
|
|
3237
|
+
addMenu, ctxMenu, roleEditFor, openModelFor, menuOpen, presetOpen, helpOpen, shortcutsOpen, recordingAction, decisionViewFor, refsEditFor,
|
|
3238
|
+
setAddMenu, setCtxMenu, setRoleEditFor, setOpenModelFor, setMenuOpen, setPresetOpen, setHelpOpen, setShortcutsOpen, setRecordingAction, setShortcuts, setDecisionViewFor, setRefsEditFor,
|
|
2821
3239
|
};
|
|
2822
3240
|
useEffect(() => {
|
|
2823
3241
|
const isEditable = (target) => {
|
|
@@ -2828,19 +3246,41 @@ window.__ModuleLoader__.load({
|
|
|
2828
3246
|
const onKey = (ev) => {
|
|
2829
3247
|
const act = keyActionsRef.current;
|
|
2830
3248
|
if (!act) return;
|
|
3249
|
+
if (act.recordingAction) {
|
|
3250
|
+
ev.preventDefault();
|
|
3251
|
+
ev.stopPropagation();
|
|
3252
|
+
if (ev.key === 'Escape') {
|
|
3253
|
+
act.setRecordingAction(null);
|
|
3254
|
+
return;
|
|
3255
|
+
}
|
|
3256
|
+
const combo = formatShortcutFromEvent(ev);
|
|
3257
|
+
if (!combo) return;
|
|
3258
|
+
const { next, clearedConflict } = applyShortcutBinding(shortcutsRef.current, act.recordingAction, combo);
|
|
3259
|
+
shortcutsRef.current = next;
|
|
3260
|
+
saveShortcuts(next);
|
|
3261
|
+
act.setShortcuts(next);
|
|
3262
|
+
act.setRecordingAction(null);
|
|
3263
|
+
if (clearedConflict) act.flash(act.t('shortcutsConflict'));
|
|
3264
|
+
return;
|
|
3265
|
+
}
|
|
2831
3266
|
if (ev.key === 'Escape') {
|
|
2832
|
-
if (act.addMenu || act.roleEditFor || act.openModelFor || act.menuOpen || act.presetOpen || act.helpOpen || act.decisionViewFor) {
|
|
3267
|
+
if (act.addMenu || act.ctxMenu || act.roleEditFor || act.openModelFor || act.menuOpen || act.presetOpen || act.helpOpen || act.shortcutsOpen || act.decisionViewFor || act.refsEditFor) {
|
|
2833
3268
|
ev.preventDefault();
|
|
2834
3269
|
act.setAddMenu(null);
|
|
3270
|
+
act.setCtxMenu(null);
|
|
2835
3271
|
act.setRoleEditFor(null);
|
|
2836
3272
|
act.setOpenModelFor(null);
|
|
2837
3273
|
act.setMenuOpen(false);
|
|
2838
3274
|
act.setPresetOpen(null);
|
|
2839
3275
|
act.setHelpOpen(false);
|
|
3276
|
+
act.setShortcutsOpen(false);
|
|
3277
|
+
act.setRecordingAction(null);
|
|
2840
3278
|
act.setDecisionViewFor(null);
|
|
3279
|
+
act.setRefsEditFor(null);
|
|
2841
3280
|
}
|
|
2842
3281
|
return;
|
|
2843
3282
|
}
|
|
3283
|
+
if (act.shortcutsOpen) return;
|
|
2844
3284
|
if (isEditable(ev.target)) return;
|
|
2845
3285
|
if (act.addMenu) {
|
|
2846
3286
|
const lf = act.addMenu.linkFrom || null;
|
|
@@ -2863,23 +3303,47 @@ window.__ModuleLoader__.load({
|
|
|
2863
3303
|
const root = rootElRef.current;
|
|
2864
3304
|
const activeInRoot = Boolean(root && document.activeElement && root.contains(document.activeElement));
|
|
2865
3305
|
if (!pointerInsideRoot.current && !activeInRoot) return;
|
|
2866
|
-
const
|
|
2867
|
-
if (
|
|
3306
|
+
const sc = shortcutsRef.current || DEFAULT_SHORTCUTS;
|
|
3307
|
+
if (matchesShortcut(ev, sc.addNode)) {
|
|
2868
3308
|
ev.preventDefault();
|
|
2869
3309
|
act.openAddMenuAtCursor();
|
|
2870
3310
|
return;
|
|
2871
3311
|
}
|
|
2872
|
-
|
|
3312
|
+
const allBound = Object.values(sc).map(normalizeShortcut);
|
|
3313
|
+
if (matchesShortcut(ev, sc.undo)) {
|
|
2873
3314
|
ev.preventDefault();
|
|
2874
3315
|
act.undo();
|
|
2875
3316
|
return;
|
|
2876
3317
|
}
|
|
2877
|
-
if (
|
|
3318
|
+
if (matchesShortcut(ev, sc.redo)
|
|
3319
|
+
|| (normalizeShortcut(sc.redo) === 'Ctrl+Shift+Z' && !allBound.includes('Ctrl+Y') && matchesShortcut(ev, 'Ctrl+Y'))) {
|
|
3320
|
+
ev.preventDefault();
|
|
3321
|
+
act.redo();
|
|
3322
|
+
return;
|
|
3323
|
+
}
|
|
3324
|
+
if (matchesShortcut(ev, sc.duplicate)) {
|
|
2878
3325
|
ev.preventDefault();
|
|
2879
3326
|
act.duplicateSelected();
|
|
2880
3327
|
return;
|
|
2881
3328
|
}
|
|
2882
|
-
if (
|
|
3329
|
+
if (matchesShortcut(ev, sc.fitView)) {
|
|
3330
|
+
ev.preventDefault();
|
|
3331
|
+
act.fitView();
|
|
3332
|
+
return;
|
|
3333
|
+
}
|
|
3334
|
+
if (matchesShortcut(ev, sc.autoLayout)) {
|
|
3335
|
+
ev.preventDefault();
|
|
3336
|
+
act.autoLayout();
|
|
3337
|
+
return;
|
|
3338
|
+
}
|
|
3339
|
+
if (matchesShortcut(ev, sc.toggleDir)) {
|
|
3340
|
+
ev.preventDefault();
|
|
3341
|
+
act.toggleDirection();
|
|
3342
|
+
return;
|
|
3343
|
+
}
|
|
3344
|
+
const delHit = matchesShortcut(ev, sc.delete)
|
|
3345
|
+
|| (normalizeShortcut(sc.delete) === 'Delete' && !allBound.includes('Backspace') && matchesShortcut(ev, 'Backspace'));
|
|
3346
|
+
if (delHit) {
|
|
2883
3347
|
if (selectedIdsRef.current.length) {
|
|
2884
3348
|
ev.preventDefault();
|
|
2885
3349
|
act.deleteSelected();
|
|
@@ -2890,32 +3354,6 @@ window.__ModuleLoader__.load({
|
|
|
2890
3354
|
return () => window.removeEventListener('keydown', onKey);
|
|
2891
3355
|
}, []);
|
|
2892
3356
|
|
|
2893
|
-
// Suppress the host context menu over the canvas while cutting is on.
|
|
2894
|
-
useEffect(() => {
|
|
2895
|
-
if (!cutMode) return undefined;
|
|
2896
|
-
const inside = (ev) => {
|
|
2897
|
-
const el = canvasElRef.current;
|
|
2898
|
-
return Boolean(el) && ev.target instanceof Node && el.contains(ev.target);
|
|
2899
|
-
};
|
|
2900
|
-
const onCtx = (ev) => { if (inside(ev)) ev.preventDefault(); };
|
|
2901
|
-
const onDown = (ev) => {
|
|
2902
|
-
if (ev.button !== 2 || !inside(ev) || ev.target.closest('[data-node]')) return;
|
|
2903
|
-
ev.preventDefault();
|
|
2904
|
-
const start = pointTo(ev);
|
|
2905
|
-
cutRef.current = start;
|
|
2906
|
-
cutHits.current = new Set();
|
|
2907
|
-
setCutPath([start]);
|
|
2908
|
-
setCutVictims([]);
|
|
2909
|
-
setDragging(true);
|
|
2910
|
-
};
|
|
2911
|
-
window.addEventListener('contextmenu', onCtx, true);
|
|
2912
|
-
window.addEventListener('mousedown', onDown, true);
|
|
2913
|
-
return () => {
|
|
2914
|
-
window.removeEventListener('contextmenu', onCtx, true);
|
|
2915
|
-
window.removeEventListener('mousedown', onDown, true);
|
|
2916
|
-
};
|
|
2917
|
-
}, [cutMode, sessionId]);
|
|
2918
|
-
|
|
2919
3357
|
useEffect(() => {
|
|
2920
3358
|
if (!dragging) return undefined;
|
|
2921
3359
|
const move = (ev) => onCanvasMove(ev);
|
|
@@ -2930,22 +3368,20 @@ window.__ModuleLoader__.load({
|
|
|
2930
3368
|
|
|
2931
3369
|
const onCanvasDown = (e) => {
|
|
2932
3370
|
if (e.button === 2) {
|
|
2933
|
-
if (!cutMode) return;
|
|
2934
3371
|
e.preventDefault();
|
|
2935
3372
|
try { window.getSelection().removeAllRanges(); } catch (_sel) { /* ignore */ }
|
|
2936
3373
|
const start = pointTo(e);
|
|
2937
|
-
|
|
2938
|
-
cutHits.current = new Set();
|
|
2939
|
-
setCutPath([start]);
|
|
2940
|
-
setCutVictims([]);
|
|
3374
|
+
rightClickRef.current = { clientX: e.clientX, clientY: e.clientY, start, moved: false };
|
|
2941
3375
|
setDragging(true);
|
|
2942
3376
|
return;
|
|
2943
3377
|
}
|
|
2944
3378
|
if (e.button !== 0) return;
|
|
2945
3379
|
if (roleEditFor) setRoleEditFor(null);
|
|
2946
3380
|
if (decisionViewFor) setDecisionViewFor(null);
|
|
3381
|
+
if (refsEditFor) setRefsEditFor(null);
|
|
2947
3382
|
if (menuOpen) setMenuOpen(false);
|
|
2948
3383
|
if (addMenu) setAddMenu(null);
|
|
3384
|
+
if (ctxMenu) setCtxMenu(null);
|
|
2949
3385
|
if (presetOpen) setPresetOpen(null);
|
|
2950
3386
|
e.preventDefault();
|
|
2951
3387
|
try { window.getSelection().removeAllRanges(); } catch (_sel) { /* ignore */ }
|
|
@@ -2964,6 +3400,17 @@ window.__ModuleLoader__.load({
|
|
|
2964
3400
|
commitView({ k: viewRef.current.k, x: pan.originX + dx, y: pan.originY + dy });
|
|
2965
3401
|
return;
|
|
2966
3402
|
}
|
|
3403
|
+
if (rightClickRef.current && !rightClickRef.current.moved) {
|
|
3404
|
+
if (Math.hypot(e.clientX - rightClickRef.current.clientX, e.clientY - rightClickRef.current.clientY) >= 6) {
|
|
3405
|
+
rightClickRef.current.moved = true;
|
|
3406
|
+
if (cutMode) {
|
|
3407
|
+
cutRef.current = rightClickRef.current.start;
|
|
3408
|
+
cutHits.current = new Set();
|
|
3409
|
+
setCutPath([rightClickRef.current.start]);
|
|
3410
|
+
setCutVictims([]);
|
|
3411
|
+
}
|
|
3412
|
+
}
|
|
3413
|
+
}
|
|
2967
3414
|
if (nodeDrag.current) {
|
|
2968
3415
|
const p = pointTo(e);
|
|
2969
3416
|
const drag = nodeDrag.current;
|
|
@@ -3013,6 +3460,49 @@ window.__ModuleLoader__.load({
|
|
|
3013
3460
|
};
|
|
3014
3461
|
|
|
3015
3462
|
const onCanvasUp = (ev) => {
|
|
3463
|
+
if (rightClickRef.current) {
|
|
3464
|
+
const rc = rightClickRef.current;
|
|
3465
|
+
rightClickRef.current = null;
|
|
3466
|
+
if (!rc.moved) {
|
|
3467
|
+
const wrap = canvasWrapRef.current;
|
|
3468
|
+
if (wrap) {
|
|
3469
|
+
const wrapRect = wrap.getBoundingClientRect();
|
|
3470
|
+
const cx = rc.clientX - wrapRect.left;
|
|
3471
|
+
const cy = rc.clientY - wrapRect.top;
|
|
3472
|
+
const canvasSpot = { x: rc.start.x + WORLD_PAD, y: rc.start.y + WORLD_PAD };
|
|
3473
|
+
const threshold = Math.max(10, 14 / (viewRef.current.k || 1));
|
|
3474
|
+
const nodeMap = new Map(nodesRef.current.map((n) => [n.id, n]));
|
|
3475
|
+
let hitEdge = null;
|
|
3476
|
+
let bestDist = Infinity;
|
|
3477
|
+
for (const edge of edgesRef.current) {
|
|
3478
|
+
const source = nodeMap.get(edge.from);
|
|
3479
|
+
const target = nodeMap.get(edge.to);
|
|
3480
|
+
if (!source || !target) continue;
|
|
3481
|
+
const dist = distanceToEdge(canvasSpot, source, target, edge, directionRef.current);
|
|
3482
|
+
if (dist <= threshold && dist < bestDist) {
|
|
3483
|
+
bestDist = dist;
|
|
3484
|
+
hitEdge = edge;
|
|
3485
|
+
}
|
|
3486
|
+
}
|
|
3487
|
+
setAddMenu(null);
|
|
3488
|
+
setMenuOpen(false);
|
|
3489
|
+
setPresetOpen(null);
|
|
3490
|
+
setOpenModelFor(null);
|
|
3491
|
+
setRoleEditFor(null);
|
|
3492
|
+
setDecisionViewFor(null);
|
|
3493
|
+
setRefsEditFor(null);
|
|
3494
|
+
if (hitEdge) {
|
|
3495
|
+
const pos = clampMenuPos(cx, cy, wrapRect.width, wrapRect.height, 180, 120);
|
|
3496
|
+
setCtxMenu({ kind: 'edge', edgeId: hitEdge.id, sx: pos.sx, sy: pos.sy, wx: rc.start.x, wy: rc.start.y });
|
|
3497
|
+
} else {
|
|
3498
|
+
const pos = clampMenuPos(cx, cy, wrapRect.width, wrapRect.height, 186, 322);
|
|
3499
|
+
setCtxMenu({ kind: 'canvas', sx: pos.sx, sy: pos.sy, wx: rc.start.x, wy: rc.start.y });
|
|
3500
|
+
}
|
|
3501
|
+
}
|
|
3502
|
+
setDragging(false);
|
|
3503
|
+
return;
|
|
3504
|
+
}
|
|
3505
|
+
}
|
|
3016
3506
|
if (cutRef.current) {
|
|
3017
3507
|
cutRef.current = null;
|
|
3018
3508
|
setDragging(false);
|
|
@@ -3107,33 +3597,56 @@ window.__ModuleLoader__.load({
|
|
|
3107
3597
|
const byId = new Map(existing.map((n) => [n.id, n]));
|
|
3108
3598
|
const placed = new Map(existing.map((n) => [n.id, { x: n.x, y: n.y }]));
|
|
3109
3599
|
let addedCount = 0;
|
|
3600
|
+
const isTB = directionRef.current === 'tb';
|
|
3110
3601
|
const incoming = doc.nodes.map((n, i) => {
|
|
3111
3602
|
const prev = byId.get(n.id) || {};
|
|
3112
3603
|
let x = typeof n.x === 'number' ? n.x : prev.x;
|
|
3113
3604
|
let y = typeof n.y === 'number' ? n.y : prev.y;
|
|
3114
3605
|
if (typeof x !== 'number' || typeof y !== 'number') {
|
|
3115
|
-
// Place a newly patched node
|
|
3606
|
+
// Place a newly patched node downstream of its first upstream node,
|
|
3607
|
+
// respecting the active horizontal (lr) or vertical (tb) flow direction.
|
|
3116
3608
|
const parentEdge = rawIncomingEdges.find((e) => e && e.to === n.id && placed.has(e.from));
|
|
3117
3609
|
if (parentEdge) {
|
|
3118
3610
|
const parentPos = placed.get(parentEdge.from);
|
|
3119
|
-
const
|
|
3120
|
-
|
|
3121
|
-
|
|
3611
|
+
const parentNode = byId.get(parentEdge.from);
|
|
3612
|
+
if (isTB) {
|
|
3613
|
+
const targetY = parentPos.y + nodeHeight(parentNode) + 68;
|
|
3614
|
+
const siblingCount = Array.from(placed.values()).filter((p) => Math.abs(p.y - targetY) < 40).length;
|
|
3615
|
+
x = parentPos.x + siblingCount * 292;
|
|
3616
|
+
y = targetY;
|
|
3617
|
+
} else {
|
|
3618
|
+
const siblingCount = Array.from(placed.values()).filter((p) => Math.abs(p.x - (parentPos.x + 300)) < 40).length;
|
|
3619
|
+
x = parentPos.x + 300;
|
|
3620
|
+
y = parentPos.y + siblingCount * 240;
|
|
3621
|
+
}
|
|
3122
3622
|
} else {
|
|
3123
3623
|
const leadPos = placed.get('lead') || { x: 40, y: 80 };
|
|
3124
|
-
|
|
3125
|
-
|
|
3624
|
+
if (isTB) {
|
|
3625
|
+
x = merge ? leadPos.x + addedCount * 292 : 40 + i * 292;
|
|
3626
|
+
y = merge ? leadPos.y + NODE_H + 68 : 80;
|
|
3627
|
+
} else {
|
|
3628
|
+
x = merge ? leadPos.x + 300 : 60 + i * 300;
|
|
3629
|
+
y = merge ? leadPos.y + (addedCount + 1) * 240 : 80;
|
|
3630
|
+
}
|
|
3126
3631
|
}
|
|
3127
3632
|
addedCount += 1;
|
|
3128
3633
|
}
|
|
3129
3634
|
placed.set(n.id, { x, y });
|
|
3130
3635
|
return { ...prev, ...n, x, y };
|
|
3131
3636
|
});
|
|
3132
|
-
if (!merge)
|
|
3637
|
+
if (!merge) {
|
|
3638
|
+
return isTB ? layoutGraph(incoming, rawIncomingEdges, 'tb') : incoming;
|
|
3639
|
+
}
|
|
3133
3640
|
const touched = new Set(incoming.map((n) => n.id));
|
|
3134
3641
|
const kept = existing
|
|
3135
3642
|
.filter((n) => !touched.has(n.id) && !removedNodes.has(n.id))
|
|
3136
|
-
.map((n) =>
|
|
3643
|
+
.map((n) => {
|
|
3644
|
+
if (n.id !== 'lead') return n;
|
|
3645
|
+
const patch = {};
|
|
3646
|
+
if (typeof doc.task === 'string') patch.task = doc.task;
|
|
3647
|
+
if (Array.isArray(doc.refs)) patch.refs = doc.refs;
|
|
3648
|
+
return Object.keys(patch).length ? { ...n, ...patch } : n;
|
|
3649
|
+
});
|
|
3137
3650
|
return kept.concat(incoming);
|
|
3138
3651
|
});
|
|
3139
3652
|
setEdges((existing) => {
|
|
@@ -3408,7 +3921,7 @@ window.__ModuleLoader__.load({
|
|
|
3408
3921
|
if (models.length === 1) {
|
|
3409
3922
|
rows.push(h('div', { key: 'single-hint', style: S.presetEmpty }, t('singleModelHint')));
|
|
3410
3923
|
}
|
|
3411
|
-
|
|
3924
|
+
return h('div', { ref: isOpen ? dropdownRef : undefined, style: { position: 'relative', flex: '1 1 auto', minWidth: 0 } },
|
|
3412
3925
|
h('button', {
|
|
3413
3926
|
style: S.selectBtn,
|
|
3414
3927
|
type: 'button',
|
|
@@ -3454,7 +3967,7 @@ window.__ModuleLoader__.load({
|
|
|
3454
3967
|
}, t('memLatestOpt')),
|
|
3455
3968
|
...history.map((item) => {
|
|
3456
3969
|
const selectedRow = node.memoryChildId === item.childId;
|
|
3457
|
-
|
|
3970
|
+
return h('div', {
|
|
3458
3971
|
key: item.childId,
|
|
3459
3972
|
style: selectedRow ? { ...S.menuRow, background: C.hover, color: C.accent } : S.menuRow,
|
|
3460
3973
|
title: item.childId,
|
|
@@ -3465,7 +3978,7 @@ window.__ModuleLoader__.load({
|
|
|
3465
3978
|
}),
|
|
3466
3979
|
!history.length && h('div', { key: 'mem-empty', style: S.presetEmpty }, t('memEmpty')),
|
|
3467
3980
|
];
|
|
3468
|
-
|
|
3981
|
+
return h('div', { style: { display: 'flex', alignItems: 'center', gap: '4px', flex: '1 1 auto', minWidth: 0 } },
|
|
3469
3982
|
toggleBtn,
|
|
3470
3983
|
h('div', { ref: isOpen ? dropdownRef : undefined, style: { position: 'relative', flex: '0 0 64px', width: '64px' } },
|
|
3471
3984
|
h('button', {
|
|
@@ -3505,7 +4018,7 @@ window.__ModuleLoader__.load({
|
|
|
3505
4018
|
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
3506
4019
|
onClick: () => { updateNode(node.id, { reasoning: id }); setOpenModelFor(null); },
|
|
3507
4020
|
}, labelOf(id)));
|
|
3508
|
-
|
|
4021
|
+
return h('div', { ref: isOpen ? dropdownRef : undefined, style: { position: 'relative', flex: '1 1 auto', minWidth: 0 } },
|
|
3509
4022
|
h('button', {
|
|
3510
4023
|
style: S.selectBtn,
|
|
3511
4024
|
type: 'button',
|
|
@@ -3562,7 +4075,7 @@ window.__ModuleLoader__.load({
|
|
|
3562
4075
|
onClick: () => { updateNode(node.id, { provider: m.provider, model: m.model }); setOpenModelFor(null); },
|
|
3563
4076
|
}, m.modelName || m.model));
|
|
3564
4077
|
}
|
|
3565
|
-
|
|
4078
|
+
return h('div', { ref: isOpen ? dropdownRef : undefined, style: { position: 'relative', flex: '1 1 auto', minWidth: 0 } },
|
|
3566
4079
|
h('button', {
|
|
3567
4080
|
style: S.selectBtn,
|
|
3568
4081
|
type: 'button',
|
|
@@ -3612,8 +4125,18 @@ window.__ModuleLoader__.load({
|
|
|
3612
4125
|
const leadDoneIds = new Set();
|
|
3613
4126
|
const hasCondNode = nodes.some((x) => x.kind === 'condition');
|
|
3614
4127
|
if (enabled) {
|
|
4128
|
+
if (runState && runState.waitingLead && runState.waitingLead.id) {
|
|
4129
|
+
leadReadyIds.add(runState.waitingLead.id);
|
|
4130
|
+
}
|
|
4131
|
+
if (runState && Array.isArray(runState.done)) {
|
|
4132
|
+
for (const did of runState.done) {
|
|
4133
|
+
const dn = nodeById.get(did);
|
|
4134
|
+
if (dn && dn.kind === 'lead' && dn.id !== 'lead') leadDoneIds.add(did);
|
|
4135
|
+
}
|
|
4136
|
+
}
|
|
3615
4137
|
for (const n of nodes) {
|
|
3616
4138
|
if (n.kind !== 'lead' || n.id === 'lead' || !reachableIds.has(n.id)) continue;
|
|
4139
|
+
if (leadReadyIds.has(n.id) || leadDoneIds.has(n.id)) continue;
|
|
3617
4140
|
const upIds = edges
|
|
3618
4141
|
.filter((e) => e.to === n.id && e.from !== 'lead' && nodeById.has(e.from))
|
|
3619
4142
|
.map((e) => e.from);
|
|
@@ -3764,7 +4287,7 @@ window.__ModuleLoader__.load({
|
|
|
3764
4287
|
const condDec = decisionsById[node.id] || null;
|
|
3765
4288
|
const matchedBranchIds = condDec && Array.isArray(condDec.branches) ? new Set(condDec.branches) : null;
|
|
3766
4289
|
const onLeft = isTB && node.tbSide === 'left';
|
|
3767
|
-
|
|
4290
|
+
return h('div', { style: S.band },
|
|
3768
4291
|
unifiedInSocket,
|
|
3769
4292
|
!isTB && h('span', { style: { ...S.rowLabel, position: 'absolute', left: '12px', top: '3px', pointerEvents: 'none' } }, inText),
|
|
3770
4293
|
branches.map((b) => {
|
|
@@ -3775,7 +4298,7 @@ window.__ModuleLoader__.load({
|
|
|
3775
4298
|
? (b.id === 'true' ? t('tipCondTrue') : t('tipCondFalse'))
|
|
3776
4299
|
: t('tipBranchOut');
|
|
3777
4300
|
const editKey = 'branch:' + node.id + ':' + b.id;
|
|
3778
|
-
|
|
4301
|
+
return h('div', {
|
|
3779
4302
|
key: b.id,
|
|
3780
4303
|
style: {
|
|
3781
4304
|
...S.condBranchRow,
|
|
@@ -3789,18 +4312,10 @@ window.__ModuleLoader__.load({
|
|
|
3789
4312
|
alignItems: 'center',
|
|
3790
4313
|
marginLeft: onLeft ? '10px' : 0,
|
|
3791
4314
|
marginRight: onLeft ? 0 : '10px',
|
|
3792
|
-
|
|
4315
|
+
gap: '2px',
|
|
3793
4316
|
},
|
|
3794
4317
|
onMouseDown: (e) => e.stopPropagation(),
|
|
3795
4318
|
},
|
|
3796
|
-
h('button', {
|
|
3797
|
-
type: 'button',
|
|
3798
|
-
style: { ...S.condBranchExpand, marginRight: onLeft ? 0 : '2px', marginLeft: onLeft ? '2px' : 0 },
|
|
3799
|
-
title: t('tipExpandBranch'),
|
|
3800
|
-
onMouseEnter: (e) => { e.currentTarget.style.color = C.text; e.currentTarget.style.borderColor = b.color; },
|
|
3801
|
-
onMouseLeave: (e) => { e.currentTarget.style.color = C.dim; e.currentTarget.style.borderColor = C.border; },
|
|
3802
|
-
onClick: () => setRoleEditFor(roleEditFor === editKey ? null : editKey),
|
|
3803
|
-
}, '⤢'),
|
|
3804
4319
|
h('input', {
|
|
3805
4320
|
style: {
|
|
3806
4321
|
...S.condBranchInput,
|
|
@@ -3813,16 +4328,22 @@ window.__ModuleLoader__.load({
|
|
|
3813
4328
|
onFocus: () => setSelectedIds([node.id]),
|
|
3814
4329
|
onChange: (e) => renameConditionBranch(node, b.id, e.target.value),
|
|
3815
4330
|
}),
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
:
|
|
4331
|
+
h('button', {
|
|
4332
|
+
type: 'button',
|
|
4333
|
+
style: { ...S.condBranchExpand, marginRight: 0 },
|
|
4334
|
+
title: t('tipExpandBranch'),
|
|
4335
|
+
onMouseEnter: (e) => { e.currentTarget.style.color = C.text; e.currentTarget.style.borderColor = b.color; },
|
|
4336
|
+
onMouseLeave: (e) => { e.currentTarget.style.color = C.dim; e.currentTarget.style.borderColor = C.border; },
|
|
4337
|
+
onClick: () => setRoleEditFor(roleEditFor === editKey ? null : editKey),
|
|
4338
|
+
}, '⤢'),
|
|
4339
|
+
branches.length > 2 && h('button', {
|
|
4340
|
+
type: 'button',
|
|
4341
|
+
style: { ...S.condBranchDel, marginLeft: 0 },
|
|
4342
|
+
title: t('delBranchTip'),
|
|
4343
|
+
onMouseEnter: (e) => { e.currentTarget.style.color = '#e5534b'; },
|
|
4344
|
+
onMouseLeave: (e) => { e.currentTarget.style.color = C.dim; },
|
|
4345
|
+
onClick: () => removeConditionBranch(node, b.id),
|
|
4346
|
+
}, '×'),
|
|
3826
4347
|
),
|
|
3827
4348
|
roleEditFor === editKey && h('div', {
|
|
3828
4349
|
style: { ...S.rolePopover, top: '-8px' },
|
|
@@ -3903,7 +4424,7 @@ window.__ModuleLoader__.load({
|
|
|
3903
4424
|
!isEntry && h('span', { style: { ...S.rowLabel, position: 'absolute', left: '12px', top: '3px', pointerEvents: 'none' } }, inText),
|
|
3904
4425
|
SOCKET_TYPES.map((sock) => {
|
|
3905
4426
|
const outLinked = connectedOut.has(node.id + '|' + sock.id);
|
|
3906
|
-
|
|
4427
|
+
return h('div', { key: sock.id, style: S.row },
|
|
3907
4428
|
h('span', { style: { ...S.rowLabel, position: 'absolute', right: '12px' } }, sock.label),
|
|
3908
4429
|
h('div', {
|
|
3909
4430
|
style: {
|
|
@@ -3939,6 +4460,84 @@ window.__ModuleLoader__.load({
|
|
|
3939
4460
|
.map((n) => n.id);
|
|
3940
4461
|
};
|
|
3941
4462
|
|
|
4463
|
+
/** Compact "+ 参考" trigger docked cleanly in the top-right of every node header bar. */
|
|
4464
|
+
const refsControlBtn = (node) => {
|
|
4465
|
+
const count = normalizeRefsUI(node.refs).length;
|
|
4466
|
+
const isOpen = refsEditFor === node.id;
|
|
4467
|
+
return h('button', {
|
|
4468
|
+
type: 'button',
|
|
4469
|
+
style: {
|
|
4470
|
+
...(count > 0 || isOpen ? S.condModeBtnOn : S.condAddBtn),
|
|
4471
|
+
position: 'absolute',
|
|
4472
|
+
top: '9px',
|
|
4473
|
+
right: '10px',
|
|
4474
|
+
zIndex: 7,
|
|
4475
|
+
whiteSpace: 'nowrap',
|
|
4476
|
+
flex: '0 0 auto',
|
|
4477
|
+
},
|
|
4478
|
+
title: t('tipRefs'),
|
|
4479
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
4480
|
+
onClick: (e) => {
|
|
4481
|
+
e.stopPropagation();
|
|
4482
|
+
setRoleEditFor(null);
|
|
4483
|
+
setRefsEditFor(isOpen ? null : node.id);
|
|
4484
|
+
},
|
|
4485
|
+
}, count > 0 ? (t('refsBtn') + '×' + count) : ('+ ' + t('refsBtn')));
|
|
4486
|
+
};
|
|
4487
|
+
|
|
4488
|
+
const refsPopoverEl = (node) => {
|
|
4489
|
+
if (refsEditFor !== node.id) return null;
|
|
4490
|
+
const list = Array.isArray(node.refs) ? node.refs : [];
|
|
4491
|
+
const isGlobal = node.id === 'lead';
|
|
4492
|
+
return h('div', {
|
|
4493
|
+
style: S.refsPopover,
|
|
4494
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
4495
|
+
},
|
|
4496
|
+
h('div', {
|
|
4497
|
+
style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: '6px', fontSize: '10px', fontWeight: 600, color: C.dim },
|
|
4498
|
+
},
|
|
4499
|
+
h('span', null, (isGlobal ? t('refsTitleGlobal') : t('refsTitleNode')) + ' (' + list.length + '/16)'),
|
|
4500
|
+
h('button', {
|
|
4501
|
+
type: 'button',
|
|
4502
|
+
style: { background: 'transparent', border: 'none', color: C.dim, cursor: 'pointer', fontSize: '12px', padding: '0 2px' },
|
|
4503
|
+
onClick: () => setRefsEditFor(null),
|
|
4504
|
+
}, '×'),
|
|
4505
|
+
),
|
|
4506
|
+
list.length === 0
|
|
4507
|
+
? h('div', { style: { fontSize: '10px', color: C.dim, marginBottom: '6px', lineHeight: '1.4' } }, t('refsEmpty'))
|
|
4508
|
+
: h('div', { style: { maxHeight: '168px', overflowY: 'auto', marginBottom: '4px' } },
|
|
4509
|
+
list.map((val, idx) => h('div', { key: 'ref-' + idx, style: S.refsRow },
|
|
4510
|
+
h('input', {
|
|
4511
|
+
style: S.refsInput,
|
|
4512
|
+
value: typeof val === 'string' ? val : '',
|
|
4513
|
+
placeholder: t('refsPh'),
|
|
4514
|
+
autoFocus: idx === list.length - 1 && val === '',
|
|
4515
|
+
onKeyDown: (e) => {
|
|
4516
|
+
if (e.key === 'Enter' && list.length < 16) {
|
|
4517
|
+
e.preventDefault();
|
|
4518
|
+
addNodeRef(node);
|
|
4519
|
+
}
|
|
4520
|
+
},
|
|
4521
|
+
onChange: (e) => updateNodeRef(node, idx, e.target.value),
|
|
4522
|
+
}),
|
|
4523
|
+
h('button', {
|
|
4524
|
+
type: 'button',
|
|
4525
|
+
style: S.condBranchDel,
|
|
4526
|
+
title: t('delRefTip'),
|
|
4527
|
+
onMouseEnter: (e) => { e.currentTarget.style.color = '#e5534b'; },
|
|
4528
|
+
onMouseLeave: (e) => { e.currentTarget.style.color = C.dim; },
|
|
4529
|
+
onClick: () => removeNodeRef(node, idx),
|
|
4530
|
+
}, '×'),
|
|
4531
|
+
)),
|
|
4532
|
+
),
|
|
4533
|
+
list.length < 16 && h('button', {
|
|
4534
|
+
type: 'button',
|
|
4535
|
+
style: { ...S.btn, width: '100%', padding: '3px 8px', fontSize: '10px', textAlign: 'center' },
|
|
4536
|
+
onClick: () => addNodeRef(node),
|
|
4537
|
+
}, t('refsAdd')),
|
|
4538
|
+
);
|
|
4539
|
+
};
|
|
4540
|
+
|
|
3942
4541
|
return h('div', {
|
|
3943
4542
|
ref: rootElRef,
|
|
3944
4543
|
style: S.root,
|
|
@@ -3950,145 +4549,19 @@ window.__ModuleLoader__.load({
|
|
|
3950
4549
|
h('button', { style: S.btn, onClick: () => addNode('lead'), type: 'button' }, t('addLead')),
|
|
3951
4550
|
h('button', { style: S.btn, onClick: () => addNode('condition'), type: 'button' }, t('addCond')),
|
|
3952
4551
|
h('span', { style: S.toolSep }),
|
|
3953
|
-
h('button', { style: S.btn, onClick: undo, type: 'button', title: t('tipUndo') }, t('undo')),
|
|
3954
4552
|
h('button', {
|
|
3955
4553
|
style: enabled && dirty ? S.btnDirty : S.btn,
|
|
3956
4554
|
onClick: () => pushPlan(enabled),
|
|
3957
4555
|
type: 'button',
|
|
3958
4556
|
title: t('tipSync'),
|
|
3959
4557
|
}, t('sync')),
|
|
3960
|
-
h('span', { style: S.toolSep }),
|
|
3961
4558
|
h('button', {
|
|
3962
4559
|
style: S.btn,
|
|
3963
|
-
onClick: () => fitView(),
|
|
3964
|
-
type: 'button',
|
|
3965
|
-
title: t('tipLocate'),
|
|
3966
|
-
}, t('locate')),
|
|
3967
|
-
h('button', {
|
|
3968
|
-
style: { ...S.btn, cursor: 'ew-resize', minWidth: '50px', textAlign: 'center', fontVariantNumeric: 'tabular-nums' },
|
|
3969
|
-
onMouseDown: onZoomPillDown,
|
|
3970
|
-
onKeyDown: (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); focusLead(1); } },
|
|
3971
|
-
type: 'button',
|
|
3972
|
-
title: t('tipResetZoom'),
|
|
3973
|
-
}, Math.round(view.k * 100) + '%'),
|
|
3974
|
-
h('button', {
|
|
3975
|
-
style: direction === 'tb' ? S.btnDirty : S.btn,
|
|
3976
4560
|
onClick: toggleDirection,
|
|
3977
4561
|
type: 'button',
|
|
3978
4562
|
title: t('tipDir'),
|
|
3979
4563
|
}, direction === 'tb' ? t('dirTB') : t('dirLR')),
|
|
3980
4564
|
syncNote ? h('span', { style: S.syncNote, title: syncNote }, syncNote) : null,
|
|
3981
|
-
h('span', { style: S.toolSep }),
|
|
3982
|
-
h('button', {
|
|
3983
|
-
style: S.btn,
|
|
3984
|
-
onClick: toggleLang,
|
|
3985
|
-
type: 'button',
|
|
3986
|
-
title: 'Switch language / 切换语言',
|
|
3987
|
-
}, t('lang')),
|
|
3988
|
-
h('div', { style: S.moreBar },
|
|
3989
|
-
h('button', {
|
|
3990
|
-
style: S.btn,
|
|
3991
|
-
type: 'button',
|
|
3992
|
-
title: t('tipMore'),
|
|
3993
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
3994
|
-
onClick: (e) => {
|
|
3995
|
-
const next = !menuOpen;
|
|
3996
|
-
if (next) {
|
|
3997
|
-
setPresetOpen(null);
|
|
3998
|
-
const rootRect = rootElRef.current && rootElRef.current.getBoundingClientRect();
|
|
3999
|
-
const btnRect = e.currentTarget && e.currentTarget.getBoundingClientRect();
|
|
4000
|
-
setMenuAlign(dropdownAlign(btnRect, rootRect, 204));
|
|
4001
|
-
}
|
|
4002
|
-
setMenuOpen(next);
|
|
4003
|
-
},
|
|
4004
|
-
}, '⋯'),
|
|
4005
|
-
menuOpen && h('div', {
|
|
4006
|
-
style: {
|
|
4007
|
-
...S.moreMenu,
|
|
4008
|
-
left: menuAlign === 'left' ? 0 : 'auto',
|
|
4009
|
-
right: menuAlign === 'left' ? 'auto' : 0,
|
|
4010
|
-
},
|
|
4011
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
4012
|
-
},
|
|
4013
|
-
h('div', {
|
|
4014
|
-
style: S.moreRow,
|
|
4015
|
-
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4016
|
-
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4017
|
-
onClick: () => { setMenuOpen(false); importFromClipboard(); },
|
|
4018
|
-
}, t('importBtn')),
|
|
4019
|
-
h('div', {
|
|
4020
|
-
style: S.moreRow,
|
|
4021
|
-
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4022
|
-
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4023
|
-
onClick: () => { setMenuOpen(false); exportToClipboard(); },
|
|
4024
|
-
}, t('exportBtn')),
|
|
4025
|
-
h('div', {
|
|
4026
|
-
style: S.moreRow,
|
|
4027
|
-
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4028
|
-
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4029
|
-
onClick: () => { setMenuOpen(false); autoLayout(); },
|
|
4030
|
-
}, t('autoLayoutBtn')),
|
|
4031
|
-
h('div', {
|
|
4032
|
-
style: { ...S.moreRow, color: '#e5534b' },
|
|
4033
|
-
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4034
|
-
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4035
|
-
onClick: () => { clearCanvas(); },
|
|
4036
|
-
}, t('clearCanvasBtn')),
|
|
4037
|
-
h('div', {
|
|
4038
|
-
style: S.moreRow,
|
|
4039
|
-
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4040
|
-
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4041
|
-
onClick: () => {
|
|
4042
|
-
const next = nextEffectLevel(fxLevel);
|
|
4043
|
-
setFxLevel(next);
|
|
4044
|
-
saveEffectLevel(next);
|
|
4045
|
-
flash(t('fxLabel') + t('sep') + fxName(next));
|
|
4046
|
-
},
|
|
4047
|
-
}, t('fxLabel') + t('sep') + fxName(fxLevel)),
|
|
4048
|
-
h('div', {
|
|
4049
|
-
style: { ...S.moreRow, display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px' },
|
|
4050
|
-
title: t('tipMaxParallel'),
|
|
4051
|
-
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4052
|
-
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4053
|
-
onClick: () => {
|
|
4054
|
-
const next = nextMaxParallel(maxParallel);
|
|
4055
|
-
setMaxParallel(next);
|
|
4056
|
-
maxParallelRef.current = next;
|
|
4057
|
-
saveMaxParallel(next);
|
|
4058
|
-
if (enabled) pushPlan(true, undefined, undefined, next);
|
|
4059
|
-
else flash(t('maxParallelLabel') + t('sep') + next);
|
|
4060
|
-
},
|
|
4061
|
-
},
|
|
4062
|
-
h('span', null, t('maxParallelLabel') + t('sep') + maxParallel),
|
|
4063
|
-
h('span', {
|
|
4064
|
-
title: t('tipMaxParallel'),
|
|
4065
|
-
style: {
|
|
4066
|
-
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
|
4067
|
-
width: '14px', height: '14px', borderRadius: '50%',
|
|
4068
|
-
border: '1px solid ' + (maxParallel > 4 ? '#d29922' : C.dim),
|
|
4069
|
-
color: maxParallel > 4 ? '#d29922' : C.dim,
|
|
4070
|
-
fontSize: '10px', fontWeight: 700, lineHeight: '12px', flex: '0 0 auto',
|
|
4071
|
-
},
|
|
4072
|
-
}, '!'),
|
|
4073
|
-
),
|
|
4074
|
-
h('div', {
|
|
4075
|
-
style: S.moreRow,
|
|
4076
|
-
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4077
|
-
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4078
|
-
onClick: () => {
|
|
4079
|
-
const next = !cutMode;
|
|
4080
|
-
setCutMode(next);
|
|
4081
|
-
saveCutMode(next);
|
|
4082
|
-
},
|
|
4083
|
-
}, t('cutLinks') + t('sep') + (cutMode ? t('on') : t('off'))),
|
|
4084
|
-
h('div', {
|
|
4085
|
-
style: S.moreRow,
|
|
4086
|
-
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4087
|
-
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4088
|
-
onClick: () => { setMenuOpen(false); setHelpOpen(true); },
|
|
4089
|
-
}, t('help')),
|
|
4090
|
-
),
|
|
4091
|
-
),
|
|
4092
4565
|
h('div', { style: S.presetBar },
|
|
4093
4566
|
(() => {
|
|
4094
4567
|
const feedback = status || (enabled ? (dirty ? t('unsaved') : t('synced')) : '');
|
|
@@ -4102,6 +4575,7 @@ window.__ModuleLoader__.load({
|
|
|
4102
4575
|
const next = presetOpen === 'menu' ? null : 'menu';
|
|
4103
4576
|
if (next) {
|
|
4104
4577
|
setMenuOpen(false);
|
|
4578
|
+
setCtxMenu(null);
|
|
4105
4579
|
const rootRect = rootElRef.current && rootElRef.current.getBoundingClientRect();
|
|
4106
4580
|
const btnRect = e.currentTarget && e.currentTarget.getBoundingClientRect();
|
|
4107
4581
|
setPresetAlign(dropdownAlign(btnRect, rootRect, 248));
|
|
@@ -4170,9 +4644,152 @@ window.__ModuleLoader__.load({
|
|
|
4170
4644
|
}, h('span', { style: S.presetRowText, title: tpl.name }, tpl.name))),
|
|
4171
4645
|
);
|
|
4172
4646
|
})(),
|
|
4647
|
+
h('div', { style: S.moreBar },
|
|
4648
|
+
h('button', {
|
|
4649
|
+
style: S.btn,
|
|
4650
|
+
type: 'button',
|
|
4651
|
+
title: t('tipMore'),
|
|
4652
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
4653
|
+
onClick: (e) => {
|
|
4654
|
+
const next = !menuOpen;
|
|
4655
|
+
if (next) {
|
|
4656
|
+
setPresetOpen(null);
|
|
4657
|
+
setCtxMenu(null);
|
|
4658
|
+
const rootRect = rootElRef.current && rootElRef.current.getBoundingClientRect();
|
|
4659
|
+
const btnRect = e.currentTarget && e.currentTarget.getBoundingClientRect();
|
|
4660
|
+
setMenuAlign(dropdownAlign(btnRect, rootRect, 204));
|
|
4661
|
+
}
|
|
4662
|
+
setMenuOpen(next);
|
|
4663
|
+
},
|
|
4664
|
+
}, '⋯'),
|
|
4665
|
+
menuOpen && h('div', {
|
|
4666
|
+
style: {
|
|
4667
|
+
...S.moreMenu,
|
|
4668
|
+
left: menuAlign === 'left' ? 0 : 'auto',
|
|
4669
|
+
right: menuAlign === 'left' ? 'auto' : 0,
|
|
4670
|
+
},
|
|
4671
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
4672
|
+
},
|
|
4673
|
+
h('div', {
|
|
4674
|
+
style: S.moreRow,
|
|
4675
|
+
title: t('tipUndo'),
|
|
4676
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4677
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4678
|
+
onClick: () => { setMenuOpen(false); undo(); },
|
|
4679
|
+
}, t('undo')),
|
|
4680
|
+
h('div', {
|
|
4681
|
+
style: S.moreRow,
|
|
4682
|
+
title: t('tipRedo'),
|
|
4683
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4684
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4685
|
+
onClick: () => { setMenuOpen(false); redo(); },
|
|
4686
|
+
}, t('redo')),
|
|
4687
|
+
h('div', {
|
|
4688
|
+
style: S.moreRow,
|
|
4689
|
+
title: t('tipLocate'),
|
|
4690
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4691
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4692
|
+
onClick: () => { setMenuOpen(false); fitView(); },
|
|
4693
|
+
}, t('locate')),
|
|
4694
|
+
h('div', { style: S.ctxDivider }),
|
|
4695
|
+
h('div', {
|
|
4696
|
+
style: S.moreRow,
|
|
4697
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4698
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4699
|
+
onClick: () => { setMenuOpen(false); importFromClipboard(); },
|
|
4700
|
+
}, t('importBtn')),
|
|
4701
|
+
h('div', {
|
|
4702
|
+
style: S.moreRow,
|
|
4703
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4704
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4705
|
+
onClick: () => { setMenuOpen(false); exportToClipboard(); },
|
|
4706
|
+
}, t('exportBtn')),
|
|
4707
|
+
h('div', {
|
|
4708
|
+
style: S.moreRow,
|
|
4709
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4710
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4711
|
+
onClick: () => { setMenuOpen(false); autoLayout(); },
|
|
4712
|
+
}, t('autoLayoutBtn')),
|
|
4713
|
+
h('div', {
|
|
4714
|
+
style: { ...S.moreRow, color: '#e5534b' },
|
|
4715
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4716
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4717
|
+
onClick: () => { clearCanvas(); },
|
|
4718
|
+
}, t('clearCanvasBtn')),
|
|
4719
|
+
h('div', { style: S.ctxDivider }),
|
|
4720
|
+
h('div', {
|
|
4721
|
+
style: S.moreRow,
|
|
4722
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4723
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4724
|
+
onClick: () => {
|
|
4725
|
+
const next = nextEffectLevel(fxLevel);
|
|
4726
|
+
setFxLevel(next);
|
|
4727
|
+
saveEffectLevel(next);
|
|
4728
|
+
flash(t('fxLabel') + t('sep') + fxName(next));
|
|
4729
|
+
},
|
|
4730
|
+
}, t('fxLabel') + t('sep') + fxName(fxLevel)),
|
|
4731
|
+
h('div', {
|
|
4732
|
+
style: { ...S.moreRow, display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px' },
|
|
4733
|
+
title: t('tipMaxParallel'),
|
|
4734
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4735
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4736
|
+
onClick: () => {
|
|
4737
|
+
const next = nextMaxParallel(maxParallel);
|
|
4738
|
+
setMaxParallel(next);
|
|
4739
|
+
maxParallelRef.current = next;
|
|
4740
|
+
saveMaxParallel(next);
|
|
4741
|
+
if (enabled) pushPlan(true, undefined, undefined, next);
|
|
4742
|
+
else flash(t('maxParallelLabel') + t('sep') + next);
|
|
4743
|
+
},
|
|
4744
|
+
},
|
|
4745
|
+
h('span', null, t('maxParallelLabel') + t('sep') + maxParallel),
|
|
4746
|
+
h('span', {
|
|
4747
|
+
title: t('tipMaxParallel'),
|
|
4748
|
+
style: {
|
|
4749
|
+
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
|
4750
|
+
width: '14px', height: '14px', borderRadius: '50%',
|
|
4751
|
+
border: '1px solid ' + (maxParallel > 4 ? '#d29922' : C.dim),
|
|
4752
|
+
color: maxParallel > 4 ? '#d29922' : C.dim,
|
|
4753
|
+
fontSize: '10px', fontWeight: 700, lineHeight: '12px', flex: '0 0 auto',
|
|
4754
|
+
},
|
|
4755
|
+
}, '!'),
|
|
4756
|
+
),
|
|
4757
|
+
h('div', {
|
|
4758
|
+
style: S.moreRow,
|
|
4759
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4760
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4761
|
+
onClick: () => {
|
|
4762
|
+
const next = !cutMode;
|
|
4763
|
+
setCutMode(next);
|
|
4764
|
+
saveCutMode(next);
|
|
4765
|
+
},
|
|
4766
|
+
}, t('cutLinks') + t('sep') + (cutMode ? t('on') : t('off'))),
|
|
4767
|
+
h('div', {
|
|
4768
|
+
style: S.moreRow,
|
|
4769
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4770
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4771
|
+
onClick: () => { toggleLang(); },
|
|
4772
|
+
}, t('ctxLangToggle') + t('sep') + (lang === 'zh' ? '中文' : 'EN')),
|
|
4773
|
+
h('div', {
|
|
4774
|
+
style: S.moreRow,
|
|
4775
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4776
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4777
|
+
onClick: () => { setMenuOpen(false); setRecordingAction(null); setShortcutsOpen(true); },
|
|
4778
|
+
}, t('shortcutsMenu')),
|
|
4779
|
+
h('div', {
|
|
4780
|
+
style: S.moreRow,
|
|
4781
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4782
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4783
|
+
onClick: () => { setMenuOpen(false); setHelpOpen(true); },
|
|
4784
|
+
}, t('help')),
|
|
4785
|
+
),
|
|
4786
|
+
),
|
|
4173
4787
|
),
|
|
4174
4788
|
),
|
|
4175
|
-
helpOpen && h('div', {
|
|
4789
|
+
helpOpen && h('div', {
|
|
4790
|
+
style: S.helpOverlay,
|
|
4791
|
+
onMouseDown: (e) => { e.stopPropagation(); if (e.target === e.currentTarget) setHelpOpen(false); },
|
|
4792
|
+
},
|
|
4176
4793
|
h('div', { style: S.helpCard },
|
|
4177
4794
|
h('div', { style: S.helpHead },
|
|
4178
4795
|
h('span', { style: S.helpTitle }, t('helpTitle')),
|
|
@@ -4181,10 +4798,93 @@ window.__ModuleLoader__.load({
|
|
|
4181
4798
|
h('div', { style: S.helpBody }, t('helpBody').split('\n').map((line, i) => h('div', { key: i, style: S.helpLine }, line))),
|
|
4182
4799
|
),
|
|
4183
4800
|
),
|
|
4801
|
+
shortcutsOpen && (() => {
|
|
4802
|
+
const actionLabels = {
|
|
4803
|
+
addNode: t('scAddNode'),
|
|
4804
|
+
duplicate: t('scDuplicate'),
|
|
4805
|
+
delete: t('scDelete'),
|
|
4806
|
+
undo: t('scUndo'),
|
|
4807
|
+
redo: t('scRedo'),
|
|
4808
|
+
fitView: t('scFitView'),
|
|
4809
|
+
autoLayout: t('scAutoLayout'),
|
|
4810
|
+
toggleDir: t('scToggleDir'),
|
|
4811
|
+
};
|
|
4812
|
+
return h('div', {
|
|
4813
|
+
style: S.helpOverlay,
|
|
4814
|
+
onMouseDown: (e) => {
|
|
4815
|
+
e.stopPropagation();
|
|
4816
|
+
if (e.target === e.currentTarget) {
|
|
4817
|
+
setRecordingAction(null);
|
|
4818
|
+
setShortcutsOpen(false);
|
|
4819
|
+
}
|
|
4820
|
+
},
|
|
4821
|
+
},
|
|
4822
|
+
h('div', { style: { ...S.helpCard, maxWidth: '360px' } },
|
|
4823
|
+
h('div', { style: S.helpHead },
|
|
4824
|
+
h('span', { style: S.helpTitle }, t('shortcutsTitle')),
|
|
4825
|
+
h('button', {
|
|
4826
|
+
style: S.btn,
|
|
4827
|
+
type: 'button',
|
|
4828
|
+
onClick: () => {
|
|
4829
|
+
const resetMap = { ...DEFAULT_SHORTCUTS };
|
|
4830
|
+
shortcutsRef.current = resetMap;
|
|
4831
|
+
saveShortcuts(resetMap);
|
|
4832
|
+
setShortcuts(resetMap);
|
|
4833
|
+
setRecordingAction(null);
|
|
4834
|
+
flash(t('shortcutsResetOk'));
|
|
4835
|
+
},
|
|
4836
|
+
}, t('shortcutsReset')),
|
|
4837
|
+
h('button', {
|
|
4838
|
+
style: S.btn,
|
|
4839
|
+
type: 'button',
|
|
4840
|
+
onClick: () => { setRecordingAction(null); setShortcutsOpen(false); },
|
|
4841
|
+
}, t('close')),
|
|
4842
|
+
),
|
|
4843
|
+
h('div', { style: { fontSize: '10px', color: C.dim, marginBottom: '8px', lineHeight: '1.45' } }, t('shortcutsHint')),
|
|
4844
|
+
SHORTCUT_ORDER.map((actionId, idx) => {
|
|
4845
|
+
const binding = shortcuts[actionId] || '';
|
|
4846
|
+
const isRec = recordingAction === actionId;
|
|
4847
|
+
return h('div', {
|
|
4848
|
+
key: actionId,
|
|
4849
|
+
style: idx === SHORTCUT_ORDER.length - 1 ? { ...S.shortcutRow, borderBottom: 'none' } : S.shortcutRow,
|
|
4850
|
+
},
|
|
4851
|
+
h('span', null, actionLabels[actionId] || actionId),
|
|
4852
|
+
h('div', { style: { display: 'inline-flex', alignItems: 'center', gap: '4px' } },
|
|
4853
|
+
h('button', {
|
|
4854
|
+
type: 'button',
|
|
4855
|
+
style: isRec ? { ...S.shortcutKeyBtn, ...S.shortcutKeyRec } : (binding ? S.shortcutKeyBtn : { ...S.shortcutKeyBtn, color: C.dim }),
|
|
4856
|
+
onClick: () => setRecordingAction(isRec ? null : actionId),
|
|
4857
|
+
}, isRec ? t('shortcutsPress') : (binding || t('shortcutsUnset'))),
|
|
4858
|
+
binding
|
|
4859
|
+
? h('button', {
|
|
4860
|
+
type: 'button',
|
|
4861
|
+
style: S.condBranchDel,
|
|
4862
|
+
title: t('del'),
|
|
4863
|
+
onMouseEnter: (e) => { e.currentTarget.style.color = '#e5534b'; },
|
|
4864
|
+
onMouseLeave: (e) => { e.currentTarget.style.color = C.dim; },
|
|
4865
|
+
onClick: () => {
|
|
4866
|
+
const { next } = applyShortcutBinding(shortcutsRef.current, actionId, '');
|
|
4867
|
+
shortcutsRef.current = next;
|
|
4868
|
+
saveShortcuts(next);
|
|
4869
|
+
setShortcuts(next);
|
|
4870
|
+
if (recordingAction === actionId) setRecordingAction(null);
|
|
4871
|
+
},
|
|
4872
|
+
}, '×')
|
|
4873
|
+
: h('span', { style: S.condBranchDelSpacer }),
|
|
4874
|
+
),
|
|
4875
|
+
);
|
|
4876
|
+
}),
|
|
4877
|
+
),
|
|
4878
|
+
);
|
|
4879
|
+
})(),
|
|
4184
4880
|
h('div', {
|
|
4185
4881
|
ref: canvasWrapRef,
|
|
4186
4882
|
style: S.canvasWrap,
|
|
4187
4883
|
onMouseMove: (e) => { lastMouseRef.current = { clientX: e.clientX, clientY: e.clientY }; },
|
|
4884
|
+
onContextMenu: (e) => {
|
|
4885
|
+
const tag = e.target && e.target.tagName;
|
|
4886
|
+
if (tag !== 'INPUT' && tag !== 'TEXTAREA') e.preventDefault();
|
|
4887
|
+
},
|
|
4188
4888
|
},
|
|
4189
4889
|
h('button', {
|
|
4190
4890
|
style: enabled
|
|
@@ -4216,7 +4916,7 @@ window.__ModuleLoader__.load({
|
|
|
4216
4916
|
const lf = addMenu.linkFrom || null;
|
|
4217
4917
|
const srcNode = lf && lf.fromId ? nodeById.get(lf.fromId) : null;
|
|
4218
4918
|
const compat = lf ? compatibleTargetsForWire(srcNode, lf.type) : { agent: true, lead: true, condition: true, leadBlockedReason: '' };
|
|
4219
|
-
|
|
4919
|
+
return h('div', {
|
|
4220
4920
|
style: { ...S.addMenu, left: addMenu.sx + 'px', top: addMenu.sy + 'px' },
|
|
4221
4921
|
onMouseDown: (e) => e.stopPropagation(),
|
|
4222
4922
|
},
|
|
@@ -4242,6 +4942,101 @@ window.__ModuleLoader__.load({
|
|
|
4242
4942
|
}, h('span', null, t('addCond')), h('span', { style: S.addMenuHint }, '3')),
|
|
4243
4943
|
);
|
|
4244
4944
|
})(),
|
|
4945
|
+
ctxMenu && (() => {
|
|
4946
|
+
const menuRow = (key, label, onClick, opts) => {
|
|
4947
|
+
const danger = opts && opts.danger;
|
|
4948
|
+
const hint = opts && opts.hint;
|
|
4949
|
+
return h('div', {
|
|
4950
|
+
key,
|
|
4951
|
+
style: danger ? { ...S.addMenuRow, color: '#e5534b' } : S.addMenuRow,
|
|
4952
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
4953
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
4954
|
+
onClick,
|
|
4955
|
+
}, h('span', null, label), hint ? h('span', { style: S.addMenuHint }, hint) : null);
|
|
4956
|
+
};
|
|
4957
|
+
if (ctxMenu.kind === 'node') {
|
|
4958
|
+
const target = nodeById.get(ctxMenu.nodeId);
|
|
4959
|
+
if (!target) return null;
|
|
4960
|
+
const multiSel = selectedIds.length > 1 && selectedSet.has(target.id);
|
|
4961
|
+
const nonLeadCount = (multiSel ? selectedIds : [target.id]).filter((id) => id !== 'lead').length;
|
|
4962
|
+
const suffix = nonLeadCount > 1 ? ' ×' + nonLeadCount : '';
|
|
4963
|
+
const latestRun = target.kind !== 'lead' ? runsById[target.id] : null;
|
|
4964
|
+
return h('div', {
|
|
4965
|
+
style: { ...S.addMenu, minWidth: '172px', left: ctxMenu.sx + 'px', top: ctxMenu.sy + 'px' },
|
|
4966
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
4967
|
+
onContextMenu: (e) => e.preventDefault(),
|
|
4968
|
+
},
|
|
4969
|
+
h('div', { style: S.addMenuHead }, t('ctxNodeTitle')),
|
|
4970
|
+
menuRow('edit', t('ctxEditText'), () => { setCtxMenu(null); setRoleEditFor(target.id); }),
|
|
4971
|
+
menuRow('refs', t('ctxManageRefs'), () => { setCtxMenu(null); setRefsEditFor(target.id); }),
|
|
4972
|
+
latestRun && menuRow('chat', t('ctxOpenChat'), () => { setCtxMenu(null); openNodeSession(target); }),
|
|
4973
|
+
nonLeadCount > 0 && h('div', { style: S.ctxDivider }),
|
|
4974
|
+
nonLeadCount > 0 && menuRow('dup', t('ctxDup') + suffix, () => { setCtxMenu(null); duplicateSelected(); }, { hint: shortcuts.duplicate || '' }),
|
|
4975
|
+
nonLeadCount > 0 && menuRow('del', t('ctxDelNode') + suffix, () => {
|
|
4976
|
+
setCtxMenu(null);
|
|
4977
|
+
if (multiSel) deleteSelected();
|
|
4978
|
+
else deleteNode(target.id);
|
|
4979
|
+
}, { danger: true, hint: shortcuts.delete === 'Delete' ? 'Del' : (shortcuts.delete || '') }),
|
|
4980
|
+
);
|
|
4981
|
+
}
|
|
4982
|
+
if (ctxMenu.kind === 'edge') {
|
|
4983
|
+
const targetEdge = edges.find((ed) => ed.id === ctxMenu.edgeId);
|
|
4984
|
+
if (!targetEdge) return null;
|
|
4985
|
+
return h('div', {
|
|
4986
|
+
style: { ...S.addMenu, minWidth: '172px', left: ctxMenu.sx + 'px', top: ctxMenu.sy + 'px' },
|
|
4987
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
4988
|
+
onContextMenu: (e) => e.preventDefault(),
|
|
4989
|
+
},
|
|
4990
|
+
h('div', { style: S.addMenuHead }, t('ctxEdgeTitle')),
|
|
4991
|
+
menuRow('ins-agent', t('ctxInsertAgent'), () => insertNodeOnEdge(targetEdge.id, 'agent', { x: ctxMenu.wx, y: ctxMenu.wy })),
|
|
4992
|
+
menuRow('ins-cond', t('ctxInsertCond'), () => insertNodeOnEdge(targetEdge.id, 'condition', { x: ctxMenu.wx, y: ctxMenu.wy })),
|
|
4993
|
+
h('div', { style: S.ctxDivider }),
|
|
4994
|
+
menuRow('del-edge', t('ctxDelEdge'), () => deleteEdgeById(targetEdge.id), { danger: true }),
|
|
4995
|
+
);
|
|
4996
|
+
}
|
|
4997
|
+
return h('div', {
|
|
4998
|
+
style: { ...S.addMenu, minWidth: '176px', left: ctxMenu.sx + 'px', top: ctxMenu.sy + 'px' },
|
|
4999
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
5000
|
+
onContextMenu: (e) => e.preventDefault(),
|
|
5001
|
+
},
|
|
5002
|
+
h('div', { style: S.addMenuHead }, t('ctxCanvasTitle')),
|
|
5003
|
+
menuRow('add-agent', t('addAgent'), () => addNode('agent', { x: ctxMenu.wx, y: ctxMenu.wy })),
|
|
5004
|
+
menuRow('add-lead', t('addLead'), () => addNode('lead', { x: ctxMenu.wx, y: ctxMenu.wy })),
|
|
5005
|
+
menuRow('add-cond', t('addCond'), () => addNode('condition', { x: ctxMenu.wx, y: ctxMenu.wy })),
|
|
5006
|
+
h('div', { style: S.ctxDivider }),
|
|
5007
|
+
menuRow('undo', t('undo'), () => { setCtxMenu(null); undo(); }, { hint: shortcuts.undo || '' }),
|
|
5008
|
+
menuRow('redo', t('redo'), () => { setCtxMenu(null); redo(); }, { hint: shortcuts.redo || '' }),
|
|
5009
|
+
menuRow('layout', t('autoLayoutBtn'), () => { setCtxMenu(null); autoLayout(); }, { hint: shortcuts.autoLayout || '' }),
|
|
5010
|
+
menuRow('dir', direction === 'tb' ? t('dirLR') : t('dirTB'), () => { setCtxMenu(null); toggleDirection(); }, { hint: shortcuts.toggleDir || '' }),
|
|
5011
|
+
menuRow('fit', t('locate'), () => { setCtxMenu(null); fitView(); }, { hint: shortcuts.fitView || '' }),
|
|
5012
|
+
h('div', { style: S.ctxDivider }),
|
|
5013
|
+
menuRow('imp', t('importBtn'), () => { setCtxMenu(null); importFromClipboard(); }),
|
|
5014
|
+
menuRow('clr', t('clearCanvasBtn'), () => { setCtxMenu(null); clearCanvas(); }, { danger: true }),
|
|
5015
|
+
);
|
|
5016
|
+
})(),
|
|
5017
|
+
h('div', {
|
|
5018
|
+
style: S.floatZoomBar,
|
|
5019
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
5020
|
+
},
|
|
5021
|
+
h('button', {
|
|
5022
|
+
style: S.floatZoomBtn,
|
|
5023
|
+
type: 'button',
|
|
5024
|
+
title: t('tipLocate'),
|
|
5025
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
5026
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
5027
|
+
onClick: () => fitView(),
|
|
5028
|
+
}, '⊡'),
|
|
5029
|
+
h('span', { style: { width: '1px', height: '12px', background: C.border, opacity: 0.7 } }),
|
|
5030
|
+
h('button', {
|
|
5031
|
+
style: { ...S.floatZoomBtn, cursor: 'ew-resize', minWidth: '42px', textAlign: 'center', fontVariantNumeric: 'tabular-nums' },
|
|
5032
|
+
type: 'button',
|
|
5033
|
+
title: t('tipResetZoom'),
|
|
5034
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
5035
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
5036
|
+
onMouseDown: onZoomPillDown,
|
|
5037
|
+
onKeyDown: (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); focusLead(1); } },
|
|
5038
|
+
}, Math.round(view.k * 100) + '%'),
|
|
5039
|
+
),
|
|
4245
5040
|
h('div', {
|
|
4246
5041
|
ref: canvasElRef,
|
|
4247
5042
|
style: {
|
|
@@ -4334,6 +5129,10 @@ window.__ModuleLoader__.load({
|
|
|
4334
5129
|
const isPruned = enabled && prunedSet.has(node.id);
|
|
4335
5130
|
const condDecision = isCondKind ? (decisionsById[node.id] || null) : null;
|
|
4336
5131
|
const verdictInfo = condDecision ? conditionVerdictSummary(condDecision, lang) : null;
|
|
5132
|
+
const hasOpenPopover = decisionViewFor === node.id
|
|
5133
|
+
|| refsEditFor === node.id
|
|
5134
|
+
|| roleEditFor === node.id
|
|
5135
|
+
|| (typeof roleEditFor === 'string' && roleEditFor.includes(':' + node.id + ':'));
|
|
4337
5136
|
return h('div', {
|
|
4338
5137
|
key: node.id,
|
|
4339
5138
|
'data-node': node.id,
|
|
@@ -4346,10 +5145,11 @@ window.__ModuleLoader__.load({
|
|
|
4346
5145
|
...(isLeadKind ? S.leadNode : null),
|
|
4347
5146
|
...(isInactive || isPruned ? S.orphanNode : null),
|
|
4348
5147
|
...(stateStyle || null),
|
|
4349
|
-
...(
|
|
5148
|
+
...(hasOpenPopover ? { zIndex: 40 } : null),
|
|
4350
5149
|
},
|
|
4351
5150
|
title: isPruned ? t('tipPruned') : (isOrphan ? t('orphanTip') : (isSoloLead ? t('tipSoloLead') : (isDeadEnd ? t('tipDeadEnd') : undefined))),
|
|
4352
5151
|
onMouseDown: (e) => onNodeDown(e, node.id),
|
|
5152
|
+
onContextMenu: (e) => onNodeContextMenu(e, node),
|
|
4353
5153
|
},
|
|
4354
5154
|
h('div', {
|
|
4355
5155
|
className: (isRunning || isLeadReady) && fxLevel === 'vivid' ? 'dsh-wc-topbar-vivid' : undefined,
|
|
@@ -4462,7 +5262,7 @@ window.__ModuleLoader__.load({
|
|
|
4462
5262
|
}, enabled ? glyph : null, label, ' ↗');
|
|
4463
5263
|
}
|
|
4464
5264
|
if (!enabled) return null;
|
|
4465
|
-
|
|
5265
|
+
return h('div', {
|
|
4466
5266
|
style: {
|
|
4467
5267
|
...S.statusChip,
|
|
4468
5268
|
bottom: (direction === 'tb' && !isCondKind) ? '28px' : '5px',
|
|
@@ -4722,6 +5522,8 @@ window.__ModuleLoader__.load({
|
|
|
4722
5522
|
style: { maxHeight: '140px', overflowY: 'auto', whiteSpace: 'pre-wrap', wordBreak: 'break-word', color: C.text, fontSize: '11px' },
|
|
4723
5523
|
}, (condDecision.reason && String(condDecision.reason).trim()) || t('verdictNoReason')),
|
|
4724
5524
|
),
|
|
5525
|
+
refsControlBtn(node),
|
|
5526
|
+
refsPopoverEl(node),
|
|
4725
5527
|
renderBand(node),
|
|
4726
5528
|
);
|
|
4727
5529
|
}),
|
|
@@ -4760,7 +5562,7 @@ window.__ModuleLoader__.load({
|
|
|
4760
5562
|
try { console.error('[workflow-canvas] apply failed', error); } catch (_e) { /* ignore */ }
|
|
4761
5563
|
}
|
|
4762
5564
|
},
|
|
4763
|
-
__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 },
|
|
5565
|
+
__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, nextSelectionOnNodeClick, DEFAULT_SHORTCUTS, normalizeShortcut, formatShortcutFromEvent, matchesShortcut, applyShortcutBinding },
|
|
4764
5566
|
};
|
|
4765
5567
|
},
|
|
4766
5568
|
});
|