feat(ctxmenu): 右键菜单「选中操作 / 该节点」收进二级菜单

一级原来 18 项、678px 高,屏幕下半区右键要内部滚动。现在一级只留
「添加节点 / 插件节点 / 选中操作 ▸ / 该节点 ▸」,高度 678 → 388px(无选中 355px)。

- 纯 CSS 展开(.iwb-ctx-subwrap:hover > .iwb-ctx-sub + :focus-within),
  不引入 React 状态;button 获得焦点也会展开,键盘 Tab 可用。
- 坑 1:一级菜单有 overflow-y:auto,会把绝对定位的子菜单裁掉 ⇒ 加 .iwb-ctx-noclip。
- 坑 2:子菜单自身也继承了 overflow-y:auto,把跨 6px 缝隙的 ::before 桥接裁没了,
  鼠标一滑就收起来 ⇒ 子菜单必须 overflow:visible。
- 定位:底对齐入口向上展开(两组都在菜单下半区,向下会顶出视口);
  右侧留 6px + 伪元素桥接,一级菜单 left 夹取保证右边恒有 ≥210px,200px 子菜单放得下。
- 粘贴/清空仍在同一个子菜单里,canPaste 仍只读一次 readClipboardGraph。

app.js 8946 → 8945 行(上限 8947)。verify:ci 全绿;Playwright 实测:
一级 388px、无选中 355px、跨缝隙悬停不收起、子菜单「复制选中」执行后节点数 +1。
This commit is contained in:
qiqi committed 2026-11-19 08:59:23 +08:00
1 parent 0d14728224
commit 9321356f59
2 files changed
+30 -15

No files matched your search

+14 -15
View File
@@ -8538,26 +8538,24 @@ const tbCenterSeed = (type, refs) => {
// 自定义右键菜单(屏蔽浏览器默认菜单)
connMenu && ConnectMenu ? el(ConnectMenu, { direction: connMenu.direction, options: connMenu.options, sx: connMenu.sx, sy: connMenu.sy, renderIcon: (t) => I(nodeTypeIcon(t) || 'star'), onPick: (type) => { const pm = connMenu; setConnMenu(null); ConnectMenuMod.pick({ direction: pm.direction, type, wx: pm.wx, wy: pm.wy, fromId: pm.fromId, toId: pm.toId, batchSrcId: pm.batchSrcId, defaults: DEFAULTS, uid, createNode: (t, sp, d, u) => CanvasNodeFactory.createNode(t, sp, d, u), nodes: refs.nodes, edges: refs.edges, pushHistory, commitCanvas, setSel, saveNow }) }, onClose: () => setConnMenu(null) }) : null,
ctxMenu ? el('div', { className: 'iwb-ctxmask', onPointerDown: (e) => { if (e.target === e.currentTarget) setCtxMenu(null) }, onContextMenu: (e) => { e.preventDefault(); setCtxMenu(null) } },
el('div', { className: 'iwb-ctxmenu', ref: ctxMenuRef, style: { left: Math.min(ctxMenu.x, (window.innerWidth || 1200) - 210), top: Math.min(ctxMenu.y, (window.innerHeight || 800) - 320) }, onPointerDown: (e) => e.stopPropagation(), onContextMenu: (e) => e.stopPropagation() },
el('div', { className: 'iwb-ctxmenu iwb-ctx-noclip', ref: ctxMenuRef, style: { left: Math.min(ctxMenu.x, (window.innerWidth || 1200) - 210), top: Math.min(ctxMenu.y, (window.innerHeight || 800) - 320) }, onPointerDown: (e) => e.stopPropagation(), onContextMenu: (e) => e.stopPropagation() },
el('div', { className: 'iwb-ctx-title' }, '添加节点'),
[['prompt', '提示词', I('file-text')], ['ref', '图片', I('ref')], ['textout', '文本', I('textout')], ['combine', '组合', I('server-plus')], ['batch', '连接', I('batch')], ['relay', '中继', I('circle-dot')], ['gen', '配置', I('gen')], ...(wPrivateToolsOn ? [['llm', '润色', I('llm')], ['layer', '分层', I('layer')]] : []), ['out', '输出', I('presentation')]].map(([t, label, ic]) => el('button', { key: t, className: 'iwb-ctx-item', onClick: () => { addNode(t, Math.round(ctxMenu.wx - NODE_W / 2), Math.round(ctxMenu.wy - 20)); setCtxMenu(null) } }, ic, el('span', { className: 'iwb-btn-text' }, label))),
// 插件节点单独成组(2026-11-19 用户要求):与内置节点之间加分割线 + 组标题,
// 不再挤在「输出」后面让用户以为也是内置类型。插件停用/未装时整组(含分隔线)不渲染。
...(pluginNodeVariants.length ? [el('div', { key: 'plug-sep', className: 'iwb-ctx-sep' }, null), el('div', { key: 'plug-title', className: 'iwb-ctx-title' }, '插件节点'), ...pluginNodeVariants.map((v) => el('button', { key: 'plugin-node-' + v.id, className: 'iwb-ctx-item', onClick: () => { addPluginNode(v.id, Math.round(ctxMenu.wx - NODE_W / 2), Math.round(ctxMenu.wy - 20)); setCtxMenu(null) } }, I('run'), el('span', { className: 'iwb-btn-text' }, String(v.title || v.id))))] : []),
el('div', { className: 'iwb-ctx-sep' }, null),
el('div', { className: 'iwb-ctx-title' }, sel.length ? '选中操作' : '画布操作'),
sel.length ? el('button', { className: 'iwb-ctx-item', onClick: () => { duplicateNodes(sel); setCtxMenu(null) } }, I('copy'), el('span', { className: 'iwb-btn-text' }, '复制选中(⌘D)')) : null,
sel.length ? el('button', { className: 'iwb-ctx-item', onClick: () => { exportSelectedGroup(); setCtxMenu(null) } }, I('upload'), el('span', { className: 'iwb-btn-text' }, '导出选中节点组')) : null,
(sel.length === 1 && refs.nodes.some((n) => n.id === sel[0] && n.type === 'prompt' && (n.data.text || '').trim())) ? el('button', { className: 'iwb-ctx-item', onClick: () => { addPromptToLibrary(sel[0]); setCtxMenu(null) } }, I('star'), el('span', { className: 'iwb-btn-text' }, '添加到提示词库')) : null,
(sel.length && groups.some((x) => x.memberIds.length && x.memberIds.every((id) => sel.includes(id)))) ? el('button', { className: 'iwb-ctx-item', onClick: () => { const gg = groups.find((x) => x.memberIds.length && x.memberIds.every((id) => sel.includes(id))); if (gg) saveGroupSnapshot(gg); setCtxMenu(null) } }, I('star'), el('span', { className: 'iwb-btn-text' }, '收藏节点组')) : null,
sel.length ? el('button', { className: 'iwb-ctx-item', onClick: () => { const ttlD = sel.map((id) => refs.nodes.find((n) => n.id === id)).filter((n) => n && n.data && n.data.title && String(n.data.title).trim()).map((n) => n.data.title)[0]; setCtxMenu(null); td.open({ title: '收藏选中节点为节点组', value: ttlD || ('节点组 ' + (savedGroups.length + 1)), onSubmit: (nm) => saveSelectionAsGroup(sel, nm) }) } }, I('star'), el('span', { className: 'iwb-btn-text' }, '收藏选中节点')) : null,
sel.length ? el('button', { className: 'iwb-ctx-item iwb-ctx-danger', onClick: () => { deleteNodes(sel); setCtxMenu(null) } }, I('x'), el('span', { className: 'iwb-btn-text' }, '删除选中(Delete)')) : null,
// v3.24.67:两按钮共读一次 readClipboardGraph(原来各调一次 ⇒ 一次菜单 4 次 getItem + 4 次 parse)
...(() => { const canPaste = !!readClipboardGraph(); return [
el('button', { className: 'iwb-ctx-item', disabled: !canPaste, onClick: () => { pasteCopiedNodes(); setCtxMenu(null) } }, I('paste'), el('span', { className: 'iwb-btn-text' }, '粘贴节点组')),
el('button', { className: 'iwb-ctx-item', disabled: !canPaste, onClick: () => { clearClipboard(); setCtxMenu(null) } }, I('x'), el('span', { className: 'iwb-btn-text' }, '清空剪贴板')),
] })(),
...(ctxMenu.targetId && refs.nodes.find((n) => n.id === ctxMenu.targetId) ? [el('div', { key: 'tgt-sep', className: 'iwb-ctx-sep' }, null), el('div', { key: 'tgt-title', className: 'iwb-ctx-title' }, '该节点')] : []),
// 两组收进二级菜单(2026-11-19 用户要求:一级 18 项太长)。入口是普通 button:
// hover / 键盘 Tab / 点击获得焦点都会用 :focus-within 展开,条目与原来完全一致。
(() => { const canPaste = !!readClipboardGraph(); return el('div', { className: 'iwb-ctx-subwrap' }, el('button', { className: 'iwb-ctx-item' }, I('copy'), el('span', { className: 'iwb-btn-text' }, sel.length ? '选中操作' : '画布操作'), el('i', { className: 'iwb-ctx-arrow' }, '▸')),
el('div', { className: 'iwb-ctxmenu iwb-ctx-sub' },
sel.length ? el('button', { className: 'iwb-ctx-item', onClick: () => { duplicateNodes(sel); setCtxMenu(null) } }, I('copy'), el('span', { className: 'iwb-btn-text' }, '复制选中(⌘D)')) : null, sel.length ? el('button', { className: 'iwb-ctx-item', onClick: () => { exportSelectedGroup(); setCtxMenu(null) } }, I('upload'), el('span', { className: 'iwb-btn-text' }, '导出选中节点组')) : null,
(sel.length === 1 && refs.nodes.some((n) => n.id === sel[0] && n.type === 'prompt' && (n.data.text || '').trim())) ? el('button', { className: 'iwb-ctx-item', onClick: () => { addPromptToLibrary(sel[0]); setCtxMenu(null) } }, I('star'), el('span', { className: 'iwb-btn-text' }, '添加到提示词库')) : null,
(sel.length && groups.some((x) => x.memberIds.length && x.memberIds.every((id) => sel.includes(id)))) ? el('button', { className: 'iwb-ctx-item', onClick: () => { const gg = groups.find((x) => x.memberIds.length && x.memberIds.every((id) => sel.includes(id))); if (gg) saveGroupSnapshot(gg); setCtxMenu(null) } }, I('star'), el('span', { className: 'iwb-btn-text' }, '收藏节点组')) : null, sel.length ? el('button', { className: 'iwb-ctx-item', onClick: () => { const ttlD = sel.map((id) => refs.nodes.find((n) => n.id === id)).filter((n) => n && n.data && n.data.title && String(n.data.title).trim()).map((n) => n.data.title)[0]; setCtxMenu(null); td.open({ title: '收藏选中节点为节点组', value: ttlD || ('节点组 ' + (savedGroups.length + 1)), onSubmit: (nm) => saveSelectionAsGroup(sel, nm) }) } }, I('star'), el('span', { className: 'iwb-btn-text' }, '收藏选中节点')) : null,
sel.length ? el('button', { className: 'iwb-ctx-item iwb-ctx-danger', onClick: () => { deleteNodes(sel); setCtxMenu(null) } }, I('x'), el('span', { className: 'iwb-btn-text' }, '删除选中(Delete)')) : null,
el('div', { className: 'iwb-ctx-sep' }, null),
el('button', { className: 'iwb-ctx-item', disabled: !canPaste, onClick: () => { pasteCopiedNodes(); setCtxMenu(null) } }, I('paste'), el('span', { className: 'iwb-btn-text' }, '粘贴节点组')), el('button', { className: 'iwb-ctx-item', disabled: !canPaste, onClick: () => { clearClipboard(); setCtxMenu(null) } }, I('x'), el('span', { className: 'iwb-btn-text' }, '清空剪贴板')),
)) })(),
(() => {
const tgt = ctxMenu.targetId ? refs.nodes.find((n) => n.id === ctxMenu.targetId) : null
if (!tgt) return null
@@ -8566,7 +8564,8 @@ const tbCenterSeed = (type, refs) => {
if (tgt.type === 'llm') items.push(el('button', { key: 'pol', className: 'iwb-ctx-item', onClick: () => { runLLM(tgt.id); setCtxMenu(null) } }, I('llm'), el('span', { className: 'iwb-btn-text' }, '▶ 润色')))
if (tgt.type === 'prompt' && (tgt.data.text || '').trim()) items.push(el('button', { key: 'fav', className: 'iwb-ctx-item', onClick: () => { addPromptToLibrary(tgt.id); setCtxMenu(null) } }, I('star'), el('span', { className: 'iwb-btn-text' }, '添加该提示词')))
items.push(el('button', { key: 'bgc', className: 'iwb-ctx-item', onClick: (e) => { const rc = e && e.currentTarget ? e.currentTarget.getBoundingClientRect() : null; setCtxMenu(null); if (UiGenCfgModule && UiGenCfgModule.openNodeBgPalette) UiGenCfgModule.openNodeBgPalette({ current: (tgt.data && tgt.data.bg) || '', anchorRect: rc, onPreview: (bg) => previewNodeBg([tgt.id], bg), onPreviewEnd: endNodeBgPreview, onPick: (bg) => updateNode(tgt.id, { bg }) }) } }, I('palette'), el('span', { className: 'iwb-btn-text' }, '背景色')), el('button', { key: 'ren', className: 'iwb-ctx-item', onClick: () => { setCtxMenu(null); wRenameNodeDialog(tgt, td, updateNode) } }, I('edit'), el('span', { className: 'iwb-btn-text' }, '重命名节点')), el('button', { key: 'del', className: 'iwb-ctx-item iwb-ctx-danger', onClick: () => { deleteNodes([tgt.id]); setCtxMenu(null) } }, I('x'), el('span', { className: 'iwb-btn-text' }, '删除该节点')))
return items
// 子菜单默认向上展开(底对齐入口):两组入口都在一级菜单下半区,向下会顶出视口
return el('div', { className: 'iwb-ctx-subwrap' }, el('button', { className: 'iwb-ctx-item' }, I('edit'), el('span', { className: 'iwb-btn-text' }, '该节点'), el('i', { className: 'iwb-ctx-arrow' }, '▸')), el('div', { className: 'iwb-ctxmenu iwb-ctx-sub' }, items))
})(),
el('div', { className: 'iwb-ctx-sep' }, null),
),
+16
View File
@@ -857,6 +857,22 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s
.iwb-ctx-item.iwb-ctx-danger .iwb-ic { color: #ef4444; }
.iwb-ctx-item.iwb-ctx-danger:hover:not(:disabled) { background: color-mix(in srgb, #ef4444 10%, transparent); color: #ef4444; }
.iwb-ctx-sep { height: 1px; margin: 4px 6px; background: var(--iwb-border); flex: 0 0 auto; }
/* ---- 二级菜单(2026-11-19 用户要求:一级太长了)----
* 「选中操作」「该节点」两组收进子菜单,一级只留入口。纯 CSS 展开(:hover + :focus-within),
* 不占 React 状态:鼠标悬停或键盘 Tab 到入口都会展开,点击入口也会(button 获得焦点)。
* 定位:默认贴父项右侧(一级菜单永远离视口右边 ≥210px,见 app.js 的 left 夹取,放得下 200px 子菜单);
* 最后一项「该节点」用 .iwb-ctx-sub-up 改为底对齐,避免向下溢出视口。 */
.iwb-ctx-subwrap { position: relative; display: flex; flex-direction: column; }
.iwb-ctx-arrow { margin-left: auto; padding-left: 10px; font-style: normal; font-size: 10px; line-height: 1; color: var(--iwb-text2); opacity: 0.7; }
.iwb-ctx-sub { position: absolute; left: calc(100% + 6px); bottom: -6px; display: none; min-width: 200px; overflow: visible; max-height: none; }
/* 6px 缝隙也要能滑过去,否则鼠标一移就收起来了。注意子菜单必须 overflow:visible,
* 否则这条桥接用的伪元素会被 .iwb-ctxmenu 继承来的 overflow-y:auto 裁掉,等于没加。 */
.iwb-ctx-sub::before { content: ''; position: absolute; left: -8px; top: 0; width: 8px; height: 100%; }
/* 兜底:入口本身就在菜单最顶上时改用向下展开 */
.iwb-ctx-sub-down { top: -6px; bottom: auto; }
.iwb-ctx-subwrap:hover > .iwb-ctx-sub, .iwb-ctx-subwrap:focus-within > .iwb-ctx-sub { display: flex; }
/* 一级菜单开了这个类就不再裁剪:overflow-y:auto 的祖先会把绝对定位的子菜单切掉 */
.iwb-ctxmenu.iwb-ctx-noclip { overflow: visible; max-height: none; }
/* ---- 历史图片:常量可选(单击选择 / 双击放大)+ 单图操作 ---- */
/* 选中有值(iwb-history-managed)时未选图片微暗,突出已选;基础 cursor 已统一为 pointer */