refactor(promptlib): 收藏入口归插件(宿主不再自带,随插件启停)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 43s

按项目所有人要求:提示词库插件负责「管理与收集」的完整能力,宿主只保留基础接口。

宿主侧移除(全部 4 处入口 + 实现):
- 节点气泡星标(app.js 单选气泡的「添加到提示词库」)
- 「选中操作 ▸ 添加到提示词库」、「该节点 ▸ 添加该提示词」
- 提示词节点标题栏星标(src/ui-node-card.js)
- src/runtime-workbench-logic.js 的 addPromptToLibrary(约 45 行)与 ui-canvas-nodes 的 onFavorite 注入

宿主侧保留:promptlib 能力(list/save/insert/copy/notify/onChanged/file*)、prompts 状态与 api('prompts')(备份/迁移)、插件数据通道。

宿主侧补回(此前缺失):右键菜单重新渲染 ctx.commands 注册的插件命令(「插件命令」分区)。

插件 promptlib 1.13.1 → 1.14.0:
- capabilities 增 nodeActions / commands
- nodeActions「收藏为提示词」:仅对 type=prompt 且 text 非空的节点出现(气泡按钮)
- commands「收藏选中的提示词」:右键「插件命令」入口
- 收藏写入插件数据 plugin-data/promptlib.json(以现有数据为基底,保留 cover:{img} 与分组),
  新条目 group:'' 即未分组,并 notify 回执

测试:
- tests/iwb-prompt-collect.spec.js 改为 3 条新契约:插件提供气泡入口 + 宿主无自带入口;
  右键插件命令可用且宿主旧条目已移除;插件停用后两个入口同时消失
- canvas-meta-notice 的旧「点按钮报错回执」用例改为「宿主不得再渲染该入口」
- tests/_helpers/wait.js openDockPanel 加固(等插件宿主初始化,修并行偶发)
- 棘轮下调:app.js 8324 / Workbench 2178

验证:npm run verify:ci 全绿(含 e2e 冒烟 31 条)。
This commit is contained in:
qiqi authored and qiqi@local committed 2026-11-27 10:06:03 +08:00
1 parent 31a89401ff
commit 2cd52d1d4e
14 files changed
+122 -145

No files matched your search

+5 -7
View File
@@ -6428,7 +6428,7 @@ const tbCenterSeed = (type, refs) => {
// src/runtime-workbench-logic.js.createWorkbenchCommands(2026-11-06)。
// 位置保持原位:消费方都在其后,避免渲染期提前访问。
let wbCmdCache = null
const wbCmd = () => wbCmdCache || (wbCmdCache = IWWorkbenchLogic.createWorkbenchCommands({ APP_VERSION, CLIPBOARD_KEY, CLIPBOARD_TTL_MS, CanvasGeometry, CanvasHistory, CanvasOps, CanvasStore, DEFAULTS, IDB, NODE_H, NODE_HEAD_H, NODE_W, api, cacheDoneUrls, cancelRunsFor, canvasEl, canvasSize, cloneNodeDefaults, commitCanvas, containsBigDataUrl, edges, groupPadOf, groups, hOf, hasGroupPad, hasNodeTitle, hydrateGroupSnapshot, isBigDataUrl, isImageProducer, nodeGroupGroups, nodeTypeH, nodeWidth, nodes, outputRequestSeq, outputs, pluginTypeId, prepareGroupSnapshotForStorage, promptGroups, promptLib: (typeof window !== 'undefined' && window.IWBPluginPromptLib) ? window.IWBPluginPromptLib.api() : null, pluginData: (typeof window !== 'undefined' && window.IWBPluginData) ? window.IWBPluginData.create.bind(window.IWBPluginData) : null, prompts, refs, saveNow, selRef, sessionsStore, setNodeGroupGroups, setNotice, setOutputs, setOutputsInfo, setPromptGroups, setPrompts, setSavedGroups, setSel, setSelEdge, setViewport, showToast, stripBigValueSync, uid, wBoardNeedsHydrate, wCacheKeyOf, wClipDrop, wClipReadLs, wClipValid, wEnsureImgUrl, wHydrateWorkspace, wImportImage, wUnhydrateWorkspace, CanvasActions, CanvasNodeFactory, wPluginNodeVariants, onSweptE2E: (n) => { if (typeof window !== 'undefined' && window.__IWB_E2E__ === true) window.__IWB_E2E_SWEPT__ = n }, onNodeUpdateE2E: () => { if (typeof window !== 'undefined' && window.__IWB_E2E__ === true) window.__IWB_E2E_UPDATES__ = (window.__IWB_E2E_UPDATES__ || 0) + 1 } }))
const wbCmd = () => wbCmdCache || (wbCmdCache = IWWorkbenchLogic.createWorkbenchCommands({ APP_VERSION, CLIPBOARD_KEY, CLIPBOARD_TTL_MS, CanvasGeometry, CanvasHistory, CanvasOps, CanvasStore, DEFAULTS, IDB, NODE_H, NODE_HEAD_H, NODE_W, api, cacheDoneUrls, cancelRunsFor, canvasEl, canvasSize, cloneNodeDefaults, commitCanvas, containsBigDataUrl, edges, groupPadOf, groups, hOf, hasGroupPad, hasNodeTitle, hydrateGroupSnapshot, isBigDataUrl, isImageProducer, nodeGroupGroups, nodeTypeH, nodeWidth, nodes, outputRequestSeq, outputs, pluginTypeId, prepareGroupSnapshotForStorage, promptGroups, prompts, refs, saveNow, selRef, sessionsStore, setNodeGroupGroups, setNotice, setOutputs, setOutputsInfo, setPromptGroups, setPrompts, setSavedGroups, setSel, setSelEdge, setViewport, showToast, stripBigValueSync, uid, wBoardNeedsHydrate, wCacheKeyOf, wClipDrop, wClipReadLs, wClipValid, wEnsureImgUrl, wHydrateWorkspace, wImportImage, wUnhydrateWorkspace, CanvasActions, CanvasNodeFactory, wPluginNodeVariants, onSweptE2E: (n) => { if (typeof window !== 'undefined' && window.__IWB_E2E__ === true) window.__IWB_E2E_SWEPT__ = n }, onNodeUpdateE2E: () => { if (typeof window !== 'undefined' && window.__IWB_E2E__ === true) window.__IWB_E2E_UPDATES__ = (window.__IWB_E2E_UPDATES__ || 0) + 1 } }))
const historyStore = new Proxy({}, { get: (_t, k) => { const v = wbCmd().historyStore; const f = v[k]; return typeof f === 'function' ? f.bind(v) : f } })
const { historySnapHasBigImage, historySnapshotBytes } = CanvasHistory // 块外仍被引用的历史判据
const HISTORY_IMG_REF_FIELDS = (...a) => wbCmd().HISTORY_IMG_REF_FIELDS(...a)
@@ -6440,7 +6440,6 @@ const tbCenterSeed = (type, refs) => {
const restore = (...a) => wbCmd().restore(...a)
const undo = (...a) => wbCmd().undo(...a)
const redo = (...a) => wbCmd().redo(...a)
const addPromptToLibrary = (...a) => wbCmd().addPromptToLibrary(...a)
const UNDO_KEYS = (...a) => wbCmd().UNDO_KEYS(...a)
const updateNode = (...a) => wbCmd().updateNode(...a)
const clearGenResults = (...a) => wbCmd().clearGenResults(...a)
@@ -7343,7 +7342,7 @@ const tbCenterSeed = (type, refs) => {
))
}
const nodeEls = IWBCanvasNodes.buildNodeEls({
CanvasGeometry, CanvasStore, EMPTY_OBJ, NODE_W, NodeCardMemo, addPromptToLibrary, addRefFromUrl, batchPortTop, batchSourcesMap, canConnect, cancelRun, config, connTarget,
CanvasGeometry, CanvasStore, EMPTY_OBJ, NODE_W, NodeCardMemo, addRefFromUrl, batchPortTop, batchSourcesMap, canConnect, cancelRun, config, connTarget,
defaultNodeBoxWidth, deleteNodes, duplicateNodes, edges, el, generationConcurrency, hOf, inPortWorld, isBatchSrc, lodViewport, nodeDerived, nodeOnMeasure, nodeOnPreview,
nodeOnSelect, nodeTypeH, nodeWidth, nodes, pushHistory, refs, runLLM, runLayerNode, runNode, runOutSources, saveNow, sel, selRef,
setConn, setConnTarget, setNotice, setSel, taskCountOf, thumbRev, typesRev, uiZoom, uid, updateNode, visibleIds, wLodEnabled, zoomToNode,
@@ -7756,8 +7755,6 @@ const tbCenterSeed = (type, refs) => {
sn.type === 'prompt' ? el('button', { 'aria-label': '放大编辑', 'data-tip': '放大编辑', onClick: (e) => { e.stopPropagation(); if (IWNodeBodies && IWNodeBodies.openPromptExpand) IWNodeBodies.openPromptExpand({ value: (sn.data && sn.data.text) || '', onCommit: (v) => updateNode(sn.id, { text: v }) }) } }, I('maximize')) : null,
el('button', { 'aria-label': '改名', 'data-tip': '改名', onClick: (e) => { e.stopPropagation(); wRenameNodeDialog(sn, td, updateNode) } }, I('edit')),
el('button', { 'aria-label': '复制', 'data-tip': '复制', onClick: (e) => { e.stopPropagation(); duplicateNodes(sel) } }, I('copy')),
// 单节点不再有「收藏为节点组」;提示词的星标 = 添加到提示词库(与标题栏星标同一入口)
sn.type === 'prompt' ? el('button', { 'aria-label': '添加到提示词库', 'data-tip': '添加到提示词库', onClick: (e) => { e.stopPropagation(); addPromptToLibrary(sn.id) } }, I('star')) : null,
sn.type === 'ref' ? el('label', { 'aria-label': '替换', 'data-tip': '替换', onPointerDown: (e) => e.stopPropagation() }, I('upload'), el('input', { type: 'file', accept: 'image/*', style: { display: 'none' }, onChange: (e) => { const f = e.target.files && e.target.files[0]; if (!f) return; try { const rd = new FileReader(); rd.onload = () => wImportImage(rd.result, { onError: (msg) => setNotice({ type: 'err', text: msg }) }, (r) => { if (!r || !r.ok || !r.data) return; updateNode(sn.id, { data: r.data, name: f.name, localName: null, url: '' }) }); rd.onerror = () => setNotice({ type: 'err', text: '读取图片文件失败:' + String(f.name || '') }); rd.readAsDataURL(f) } catch (err) { console.error(err) } } }, null)) : null,
sn.type === 'ref' ? el('button', { 'aria-label': '粘贴', 'data-tip': '粘贴', onClick: (e) => { e.stopPropagation(); floatbarRefPaste(sn.id) }, onPointerDown: (e) => e.stopPropagation() }, I('paste')) : null,
sn.type === 'out' ? (() => { const uout = outResultUrls(sn.id); return el('button', { 'aria-label': '下载', 'data-tip': '下载', disabled: !uout.length, onClick: (e) => { e.stopPropagation(); uout.forEach((u, i) => setTimeout(() => downloadUrl(u, 'image-' + String(i + 1).padStart(3, '0') + '.png'), i * 350)) } }, I('download')) })() : null,
@@ -7880,7 +7877,6 @@ const tbCenterSeed = (type, refs) => {
(() => { 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),
@@ -7893,11 +7889,13 @@ const tbCenterSeed = (type, refs) => {
if (isImageProducer(tgt)) items.push(el('button', { key: 'run', className: 'iwb-ctx-item', onClick: () => { runProducer(tgt.id); setCtxMenu(null) } }, I('run'), el('span', { className: 'iwb-btn-text' }, tgt.type === 'layer' ? '运行该分层' : '运行该生图')))
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 === 'ref' && tgt.data && typeof tgt.data.orig === 'string' && tgt.data.orig) items.push(el('button', { key: 'restore-orig', className: 'iwb-ctx-item', onClick: () => { pushHistory(); updateNode(tgt.id, { data: tgt.data.orig, url: '', orig: '' }); setCtxMenu(null) } }, I('undo'), 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 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))
})(),
// 插件命令(v3.26.109 恢复渲染):由 ctx.commands.register 注册,插件停用即消失
wPluginCommands.length ? el('div', { className: 'iwb-ctx-sep' }, null) : null,
...wPluginCommands.map((c) => el('button', { key: 'pcmd_' + c.id, className: 'iwb-ctx-item iwb-ctx-plugin', onClick: () => { setCtxMenu(null); try { const r = c.run(); if (r && typeof r.catch === 'function') r.catch(() => {}) } catch (e) { setNotice({ type: 'err', text: '插件命令失败:' + String((e && e.message) || e) }) } } }, I(c.icon || 'puzzle'), el('span', { className: 'iwb-btn-text' }, c.title))),
el('div', { className: 'iwb-ctx-sep' }, null),
),
) : null,