refactor(promptlib): 收藏入口归插件(宿主不再自带,随插件启停)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 43s
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:
1 parent
31a89401ff
commit
2cd52d1d4e
14 files changed
+122
-145
No files matched your search
+2
-2
@@ -105,8 +105,8 @@ IWB_WRITE_BOUNDARY_SNAPSHOT=1 node tests/architecture-boundary-guard-test.js #
|
||||
|
||||
| 守卫 | 位置 | 现在的上限 |
|
||||
|---|---|---|
|
||||
| `app.js` 总行数 | `tests/source-text-ratchet-test.js` `MAX_APP_JS_LINES` | **8,326**(另守「占总源码 ≤ 40%」,见 `MAX_APP_JS_SHARE`) |
|
||||
| `Workbench()` 行数 | 同上 `MAX_WORKBENCH_LINES` | **2,180** |
|
||||
| `app.js` 总行数 | `tests/source-text-ratchet-test.js` `MAX_APP_JS_LINES` | **8,324**(另守「占总源码 ≤ 40%」,见 `MAX_APP_JS_SHARE`) |
|
||||
| `Workbench()` 行数 | 同上 `MAX_WORKBENCH_LINES` | **2,178** |
|
||||
| 单组件行数(不含 Workbench)| 同上 `MAX_APP_COMPONENT_LINES` | **423** |
|
||||
|
||||
三条都是**只减不增**。确需在 app.js 增长时,必须**同步上调上限并在 commit 里写理由**(等于显式记账,不会悄悄发生)。
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
- 图片**新写入主通道 = IndexedDB Blob `{__blob}` / key `imgblob_<hash>_<len>`** (A) `app.js:2143`;`{__cache}`(Cache Storage)为兜底;\`ref_\`(`app.js` 内定义的 `IDB_REF_PREFIX = 'ref_'`)为 legacy 形态 (A)。
|
||||
- 大图判定:`isBigDataUrl` = `data:` 且 `length > 3000` (A) `app.js:2018`;**画布保存保留阈值** `< 16384` 才原样保留 (A) `app.js:2182`。**两处阈值并存,含义不同**。
|
||||
- 单测是**源码契约测试**:`tests/` 目录共 **493** 处源码文本钉点(`source.includes` / `source.indexOf` / `/re/.test(source)`),分布在 **20** 个文件(其中 `iwb-v32-web-test.js` 一个就占 **407**)→ **结构性重构会先打红测试**。**该数字已由 `tests/source-text-ratchet-test.js` 的「只减不增」棘轮守门**(2026-10-20 起守卫范围从 1 个文件扩到全目录:新增任何一处源码文本钉点都会打红)。**2026-11-12 复算**(`npm run audit:pins`,v3.24.76):二分 STRUCT **417** / NAME **76**;形态 **POS 403 / NEG 87 / COUNT 3**;难度 **易 62 / 中 316 / 难 115**。钉点减法第一批(v3.24.72)把 **537 → 505**:8 条探针钉点改为「门禁内 spec 是否真的读该计数器」、5 条改为运行时断言(生产态 `window` 上无探针)、10 条改为 DOM 断言(质量档位禁用 / 传输页无三模式按钮 / 模型项 title)、4 条改为运行时对象断言(健康检查两域、策略对象冻结)、其余 9 条有同文件 DOM 等价断言或仅剩 NEG。第二批(v3.24.76)把 **505 → 493**:94-5~7 三条「多标签释放语义」(10 处正则)换成 `tests/iwb-tabs-release.spec.js` 的 3 条真 e2e,剩 1 条「消费方契约」(断言该 spec 在门禁内且 spec 源码真的读两个探针);另 2 条 `wPurgeIntent.add` 钉点改为读 `src/workspace-purge.js`。**这一批一换就查出 3 个真缺陷**(objectURL 从未释放 / 彻底删除留孤儿标签 · session / 刷新后误回收打开标签的图)—— 见 CHANGELOG v3.24.76。
|
||||
- `app.js` = 单 IIFE **8,326 行**(**双层预算**:绝对上限 8,326 / 占总源码 ≤ 40%,现 **26.3%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,180 行**(上限 **2,180**,余量 0;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **115** 个模块 / 23,358 行,`sourceModules` 115 项;v3.24.68 新增 `clipboard-graph.js`,v3.24.74 新增 `image-admit.js`,v3.24.75 新增 `image-dedupe.js`,v3.24.76 新增 `workspace-purge.js`,v3.24.79 新增 `generation-provider-ping.js`,v3.24.80 删除无调用的 `createWBFlushViewport` 17 行)。
|
||||
- `app.js` = 单 IIFE **8,324 行**(**双层预算**:绝对上限 8,324 / 占总源码 ≤ 40%,现 **26.3%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,178 行**(上限 **2,178**,余量 0;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **115** 个模块 / 23,307 行,`sourceModules` 115 项;v3.24.68 新增 `clipboard-graph.js`,v3.24.74 新增 `image-admit.js`,v3.24.75 新增 `image-dedupe.js`,v3.24.76 新增 `workspace-purge.js`,v3.24.79 新增 `generation-provider-ping.js`,v3.24.80 删除无调用的 `createWBFlushViewport` 17 行)。
|
||||
- 门禁:`npm run verify` = `verify:ci`(`build` → `node --check app.js` → `node --check dist/app.js` → `check-dist.js` → `lint`(ESLint 正确性规则,`src/` + `app.js`,P4-16a)→ `test:unit` → `test` → `test:facts`)+ `test:e2e` (A) `package.json`。
|
||||
|
||||
## 2. 门禁与环境现状
|
||||
|
||||
+3
-2
@@ -55,9 +55,10 @@
|
||||
"dir": "promptlib",
|
||||
"main": "main.js",
|
||||
"style": "styles.css",
|
||||
"version": "1.13.1",
|
||||
"version": "1.14.0",
|
||||
"files": {
|
||||
"main.js": "720b8aaa040e0310e6c7d7d2fe1ad6ed0a0e437de77d56bf1a2905355c795e13",
|
||||
"manifest.json": "4d8d6ce8d5ebe6ba2864f0e7f3708492b82561c8467b0c006343cab3cab1f769",
|
||||
"main.js": "e6e9ec6aad1582ae00f23c88a762e84e28ae5403d6739291dd1a44a28e3f49fe",
|
||||
"styles.css": "203d61278ad98b2a07053851d0cfb42dd826564e5ae4d068ec950423cd09c46b"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -2201,12 +2201,40 @@
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 收藏(v1.14.0:宿主不再提供收藏入口,由插件自己注册)=====
|
||||
function plpNotifyCtx (ctx, t, ty) { try { if (ctx.promptlib && ctx.promptlib.notify) ctx.promptlib.notify(t, ty || 'ok') } catch (e) { /* ignore */ } }
|
||||
function plpCollect (ctx, nodeId) {
|
||||
var nodes = []
|
||||
try { nodes = (ctx.canvas && typeof ctx.canvas.getNodes === 'function') ? (ctx.canvas.getNodes() || []) : [] } catch (e) { nodes = [] }
|
||||
var n = null
|
||||
for (var i = 0; i < nodes.length; i++) if (nodes[i] && nodes[i].id === nodeId) { n = nodes[i]; break }
|
||||
var d0 = (n && n.data) || {}
|
||||
var text = String(d0.text || '').trim()
|
||||
var ttl = String(d0.title || '').trim()
|
||||
if (!text) { plpNotifyCtx(ctx, '提示词为空,无法收藏', 'err'); return Promise.resolve({ ok: false }) }
|
||||
var read = (ctx.data && typeof ctx.data.read === 'function') ? Promise.resolve(ctx.data.read()).catch(function () { return {} }) : Promise.resolve({})
|
||||
return read.then(function (d) {
|
||||
if (d && Array.isArray(d.prompts) && d.prompts.length) return { prompts: d.prompts, groups: Array.isArray(d.groups) ? d.groups : [] }
|
||||
return Promise.resolve(ctx.promptlib.list()).then(function (r) { return { prompts: (r && r.prompts) || [], groups: (r && r.groups) || [] } })
|
||||
}).then(function (cur) {
|
||||
var list = cur.prompts.slice()
|
||||
list.push({ id: 'q' + Date.now() + '_' + Math.floor(Math.random() * 1e6), name: ttl || ('提示词 ' + text.slice(0, 8) + '…'), text: text, tags: [], group: '' })
|
||||
var payload = { schemaVersion: 3, prompts: list, groups: cur.groups, updatedAt: Date.now() }
|
||||
var jobs = []
|
||||
if (ctx.data && typeof ctx.data.write === 'function') jobs.push(Promise.resolve(ctx.data.write(payload)).catch(function () {}))
|
||||
if (ctx.promptlib && typeof ctx.promptlib.save === 'function') jobs.push(Promise.resolve(ctx.promptlib.save({ prompts: list, groups: cur.groups })).catch(function () {}))
|
||||
return Promise.all(jobs)
|
||||
}).then(function () { plpNotifyCtx(ctx, '已收藏到未分组'); return { ok: true } })
|
||||
.catch(function () { plpNotifyCtx(ctx, '收藏失败,请重试', 'err'); return { ok: false } })
|
||||
}
|
||||
|
||||
|
||||
global.IWBPluginHost.register({
|
||||
id: 'promptlib',
|
||||
name: '提示词库',
|
||||
version: '1.13.1',
|
||||
version: '1.14.0',
|
||||
apiVersion: 1,
|
||||
capabilities: ['panels', 'promptlib', 'nodeTypes', 'canvas', 'canvasWrite'],
|
||||
capabilities: ['panels', 'promptlib', 'nodeTypes', 'canvas', 'canvasWrite', 'nodeActions', 'commands'],
|
||||
data: { schemaVersion: 3, maxBytes: 4 * 1024 * 1024 },
|
||||
settings: {
|
||||
panel: { type: 'custom', label: '分组与备份', render: renderPluginSettings },
|
||||
@@ -2433,6 +2461,29 @@
|
||||
}
|
||||
}
|
||||
|
||||
// v1.14.0:收藏入口归插件 —— 节点气泡(nodeAction)+ 右键「插件命令」;插件停用即消失
|
||||
if (ctx.nodeActions && typeof ctx.nodeActions.register === 'function') {
|
||||
ctx.nodeActions.register({
|
||||
id: 'collect-prompt',
|
||||
title: '收藏为提示词',
|
||||
icon: 'star',
|
||||
appliesTo: function (node) { return !!node && node.type === 'prompt' && String((node.data && node.data.text) || '').trim() !== '' },
|
||||
run: function (node) { if (node && node.id) plpCollect(ctx, node.id) },
|
||||
})
|
||||
}
|
||||
if (ctx.commands && typeof ctx.commands.register === 'function') {
|
||||
ctx.commands.register({
|
||||
id: 'collect-selected',
|
||||
title: '收藏选中的提示词',
|
||||
icon: 'star',
|
||||
run: function () {
|
||||
var sel = (ctx.canvas && typeof ctx.canvas.getSelectedNode === 'function') ? ctx.canvas.getSelectedNode() : null
|
||||
if (!sel || !sel.id) { plpNotifyCtx(ctx, '先选中一个提示词节点', 'err'); return }
|
||||
plpCollect(ctx, sel.id)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return {}
|
||||
})
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "promptlib",
|
||||
"name": "提示词库",
|
||||
"version": "1.13.1",
|
||||
"version": "1.14.0",
|
||||
"apiVersion": 1,
|
||||
"main": "main.js",
|
||||
"style": "styles.css",
|
||||
|
||||
@@ -1578,7 +1578,7 @@
|
||||
// ── 画布编辑命令集(2026-11-06 从 Workbench 外移;行为逐字保留)──────────────────
|
||||
// 语义与原 const 一致:每次渲染创建一次。调用点通过 app.js 的同名包装进入。
|
||||
function createWorkbenchCommands(ctx) {
|
||||
const { APP_VERSION, CLIPBOARD_KEY, CLIPBOARD_TTL_MS, CanvasGeometry, CanvasHistory, CanvasOps, CanvasStore, DEFAULTS, IDB, NODE_H, NODE_HEAD_H, NODE_W, api, c, cacheDoneUrls, cancelRunsFor, canvasEl, canvasSize, cloneNodeDefaults, commitCanvas, containsBigDataUrl, edges, groupPadOf, groups, hOf, hasGroupPad, hasNodeTitle, hydrateGroupSnapshot, isBigDataUrl, isImageProducer, nodeGroupGroups, nodeTypeH, nodeWidth, nodes, outputRequestSeq, outputs, pluginTypeId, prepareGroupSnapshotForStorage, pluginData, promptGroups, promptLib, 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 } = ctx
|
||||
const { APP_VERSION, CLIPBOARD_KEY, CLIPBOARD_TTL_MS, CanvasGeometry, CanvasHistory, CanvasOps, CanvasStore, DEFAULTS, IDB, NODE_H, NODE_HEAD_H, NODE_W, api, c, 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 } = ctx
|
||||
// ── v3.87.7/9 撤销历史不再钉住图片本体(OOM 修复)──
|
||||
// 症状:Chrome「Out of Memory」杀掉标签页。根因方向:快照浅拷贝共享引用大图 base64,历史栈深 60
|
||||
// → 被引用过的图无法 GC,LRU 的 unhydrate 也白做。修法:入栈前把大图**引用化**(写 Cache/IDB,只剩几字节)。
|
||||
@@ -1679,49 +1679,6 @@
|
||||
const undo = () => { if (refs.history && historyStore) { historyStore.setActive(refs.history); historyStore.undo() } }
|
||||
const redo = () => { if (refs.history && historyStore) { historyStore.setActive(refs.history); historyStore.redo() } }
|
||||
|
||||
const addPromptToLibrary = (id) => {
|
||||
const n = refs.nodes.find((x) => x.id === id)
|
||||
const text = (n && n.data.text || '').trim()
|
||||
if (!text) { setNotice({ type: 'err', text: '提示词为空,无法添加' }); return }
|
||||
const ttl = (n.data && n.data.title && String(n.data.title).trim()) ? String(n.data.title).trim() : ''
|
||||
const name = ttl || ('提示词 ' + text.slice(0, 8) + '…')
|
||||
const okNotice = () => { setNotice({ type: 'ok', text: '已添加提示词到未分组' }); showToast('已添加到提示词库(未分组)') }
|
||||
const failSave = (msg) => { setNotice({ type: 'err', text: msg }); showToast(msg, 'err') }
|
||||
// v3.26.109:提示词库插件 1.13 起「唯一真源 = plugin-data/promptlib.json」,宿主 localStorage 只在插件首次迁移时被读。
|
||||
// 只写宿主会「加进去了但面板看不见」(2026-11-27 用户实测)。正确做法:读插件数据为基底(保住 cover:{img} 引用),
|
||||
// 追加到未分组,写回插件数据 + 走插件 save 同步宿主镜像并通知面板刷新。
|
||||
if (promptLib && typeof promptLib.list === 'function' && typeof promptLib.save === 'function') {
|
||||
const store = (typeof pluginData === 'function') ? pluginData('promptlib') : null
|
||||
Promise.resolve(store && typeof store.read === 'function' ? store.read() : null)
|
||||
.catch(() => null)
|
||||
.then((d) => {
|
||||
if (d && Array.isArray(d.prompts) && d.prompts.length) return { prompts: d.prompts, groups: Array.isArray(d.groups) ? d.groups : [] }
|
||||
return Promise.resolve(promptLib.list()).then((r) => ({ prompts: (r && r.prompts) || [], groups: (r && r.groups) || [] }))
|
||||
})
|
||||
.then((cur) => {
|
||||
const list = (cur.prompts || []).slice()
|
||||
list.push({ id: uid('q'), name, text, tags: [], group: '' })
|
||||
const payload = { schemaVersion: 3, prompts: list, groups: cur.groups || [], updatedAt: Date.now() }
|
||||
const written = (store && typeof store.write === 'function') ? Promise.resolve(store.write(payload)).catch(() => null) : Promise.resolve(null)
|
||||
return written.then(() => promptLib.save({ prompts: list, groups: cur.groups || [] }))
|
||||
})
|
||||
.then((r) => { if (r && r.ok === false) { failSave(r.error || '提示词库保存失败,请重试'); return } okNotice() })
|
||||
.catch(() => failSave('提示词库保存失败,请重试'))
|
||||
return
|
||||
}
|
||||
// 回退:没有提示词库插件时的宿主存储路径(旧行为)
|
||||
const list = (refs.promptLibrary || []).slice()
|
||||
list.push({ id: uid('q'), name, text, tags: [], group: '' })
|
||||
setPrompts(list)
|
||||
refs.promptLibrary = list
|
||||
const gs = promptGroups.slice()
|
||||
setPromptGroups(gs)
|
||||
try { const st = _lstore(); if (st) st.set('iwb_lib_groups_cache', gs) } catch (e) { /* ignore */ }
|
||||
api('prompts', { prompts: list, groups: gs })
|
||||
.then((r) => { if (r && r.ok === false) failSave(r.error || '提示词库保存失败,请重试') })
|
||||
.catch(() => failSave('提示词库保存失败,请重试'))
|
||||
okNotice()
|
||||
}
|
||||
const UNDO_KEYS = ['model', 'provider', 'keyGroup', 'size', 'custom', 'customSize', 'quality', 'align16', 'variants', 'instruction', 'text', 'bg']
|
||||
const updateNode = (id, patch) => {
|
||||
// e2e 探针(仅 e2e 模式):统计"节点写回次数",用于锁住"打字不逐字符更新全局 store"的性能契约
|
||||
@@ -2262,7 +2219,7 @@
|
||||
setViewport(next)
|
||||
}
|
||||
|
||||
return { historyStore, HISTORY_IMG_REF_FIELDS, historyRefUsable, historyRefData, historyRawSnapshot, pushHistory, pushHistoryDebounced, restore, undo, redo, addPromptToLibrary, UNDO_KEYS, updateNode, clearGenResults, deleteNodes, deleteEdge, copyOffset, duplicateNodes, floatbarRefPaste, outResultUrls, stageClip, copyNodes, pasteGraph, readClipboardGraph, pasteCopiedNodes, clearClipboard, cutNodes, groupOf, makeGroup, ungroup, joinGroupOf, renameGroup, duplicateGroup, saveGroupSnapshot, saveSelectionAsGroup, instantiateGroup, loadSavedGroups, findSpot, placeAtDrop, addNode, addPluginNode, addRefFromUrl, refSrcOf, refreshOutputs, deleteOutputs, loadDemo, doFit }
|
||||
return { historyStore, HISTORY_IMG_REF_FIELDS, historyRefUsable, historyRefData, historyRawSnapshot, pushHistory, pushHistoryDebounced, restore, undo, redo, UNDO_KEYS, updateNode, clearGenResults, deleteNodes, deleteEdge, copyOffset, duplicateNodes, floatbarRefPaste, outResultUrls, stageClip, copyNodes, pasteGraph, readClipboardGraph, pasteCopiedNodes, clearClipboard, cutNodes, groupOf, makeGroup, ungroup, joinGroupOf, renameGroup, duplicateGroup, saveGroupSnapshot, saveSelectionAsGroup, instantiateGroup, loadSavedGroups, findSpot, placeAtDrop, addNode, addPluginNode, addRefFromUrl, refSrcOf, refreshOutputs, deleteOutputs, loadDemo, doFit }
|
||||
}
|
||||
// ── createWorkbenchSessions(2026-11-06 从 Workbench 外移;行为逐字保留)──────────────
|
||||
function createWorkbenchSessions(ctx) {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
'use strict'
|
||||
|
||||
function buildNodeEls(ctx) {
|
||||
const { CanvasGeometry, CanvasStore, EMPTY_OBJ, NODE_W, NodeCardMemo, addPromptToLibrary, 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 } = ctx
|
||||
const { 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 } = ctx
|
||||
const nodeEls = []
|
||||
const batchSourcesById = batchSourcesMap
|
||||
for (const n of nodes) {
|
||||
@@ -61,7 +61,6 @@
|
||||
taskCountOf,
|
||||
generationConcurrency: generationConcurrency(config),
|
||||
onRunLlm: runLLM,
|
||||
onFavorite: addPromptToLibrary,
|
||||
onCopyRef: addRefFromUrl,
|
||||
onPreview: nodeOnPreview,
|
||||
onInPortDown: (id) => {
|
||||
|
||||
@@ -152,13 +152,6 @@ function NodeCard(props) {
|
||||
onDoubleClick: (e) => { e.stopPropagation(); setTitleDraft((node.data && node.data.title && String(node.data.title).trim()) ? node.data.title : (nodeTypeTitle(node.type))); setEditingTitle(true) },
|
||||
}, (node.data && node.data.title && String(node.data.title).trim()) ? node.data.title : (nodeTypeTitle(node.type))),
|
||||
el('span', { className: 'iwb-node-headbtns' },
|
||||
node.type === 'prompt' ? el('button', {
|
||||
className: 'iwb-node-del',
|
||||
title: '添加到提示词库',
|
||||
'data-tip': '收藏',
|
||||
onPointerDown: (e) => e.stopPropagation(),
|
||||
onClick: () => props.onFavorite && props.onFavorite(node.id),
|
||||
}, I('star')) : null,
|
||||
node.type === 'ref' ? el('label', {
|
||||
className: 'iwb-node-del',
|
||||
title: '替换图片',
|
||||
|
||||
@@ -107,11 +107,13 @@ async function openCanvas (page, opts) {
|
||||
// 停靠栏面板(2026-11-26):v3.25.82 起「资源中心」浮窗被停靠栏插件面板取代。
|
||||
// 图库 = 右栏 .iwb-dock-btn[data-panel="gallery"];提示词库 = "prompts";节点组 = "groups";浏览器 = "browser"。
|
||||
async function openDockPanel (page, panelId) {
|
||||
const btn = page.locator('.iwb-dock-btn[data-panel="' + panelId + '"]').first()
|
||||
if (!(await btn.count())) {
|
||||
// 面板所在侧默认可能是关的:先开右栏再找(找不到右栏开关就开左栏)
|
||||
const rightToggle = page.locator('.iwb-top-nav-icon[title="显示 / 隐藏右栏"]').first()
|
||||
if (await rightToggle.count()) { await rightToggle.click(); await page.waitForTimeout(300) }
|
||||
// 2026-11-27:插件面板清单按 PluginHost.list() 过滤,插件还没注册完时按钮不存在 ⇒
|
||||
// 先等宿主初始化,再开栏;找不到就轮询(并行跑时首屏更慢,固定 300ms 会偶发失败)。
|
||||
await page.waitForFunction(() => Boolean(window.IWBPluginHost) && window.IWBPluginHost.snapshot().initialized === true, null, { timeout: 15000 }).catch(() => {})
|
||||
const rightToggle = page.locator('.iwb-top-nav-icon[title="显示 / 隐藏右栏"]').first()
|
||||
if (!(await page.locator('.iwb-dock[data-side="right"]').count()) && (await rightToggle.count())) {
|
||||
await rightToggle.click()
|
||||
await page.waitForTimeout(200)
|
||||
}
|
||||
const target = page.locator('.iwb-dock-btn[data-panel="' + panelId + '"]').first()
|
||||
await expect(target).toBeVisible({ timeout: 10000 })
|
||||
|
||||
@@ -125,34 +125,14 @@ async function enterCanvas(window) {
|
||||
assert.equal(window.document.querySelectorAll('.iwb-home-card').length, 0,
|
||||
'切到画布视图后首页卡片应已卸载(实际仍有残留 ⇒ 视图切换不干净)')
|
||||
|
||||
// ── 6. 保存失败必须变成用户看得见的回执(2026-11-12)──────────────────────
|
||||
// 为什么加:`api('prompts', …)` 在配额不足时 **resolve** { ok:false, error:'提示词库保存失败:…' },
|
||||
// 不是 reject。历史上调用点写 `.catch(() => {})` ⇒ 既抓不到失败,也把 api 造好的文案丢掉,
|
||||
// 用户看到的是「顺利加进去了」,刷新后数据消失 —— 与 v3.24.67~70 反复修的「没反应」同一类。
|
||||
// 这里用**真实渲染**钉住:让存储写入返回失败,点「添加到提示词库」,必须出现红色回执。
|
||||
const waitFor = async (fn, ms = 4000) => {
|
||||
const t0 = Date.now()
|
||||
while (Date.now() - t0 < ms) { if (fn()) return true; await sleep(20) }
|
||||
return false
|
||||
}
|
||||
const rt = window.IWBStorageRuntime
|
||||
assert.ok(rt && typeof rt.set === 'function', '应能拿到 IWBStorageRuntime.set 以模拟写入失败')
|
||||
const origSet = rt.set
|
||||
rt.set = () => false
|
||||
const addBtn = Array.from(window.document.querySelectorAll('button')).find((b) => b.title === '添加到提示词库')
|
||||
assert.ok(addBtn, '应能找到提示词卡片上的「添加到提示词库」按钮')
|
||||
addBtn.dispatchEvent(new window.MouseEvent('click', { bubbles: true, cancelable: true }))
|
||||
const gotToast = await waitFor(() => !!window.document.querySelector('.iwb-toast-err'))
|
||||
rt.set = origSet
|
||||
assert.ok(gotToast, '存储写入失败时,点「添加到提示词库」必须弹出 .iwb-toast-err —— ' +
|
||||
'一个都没有说明失败又被静默吞掉了(用户会以为已保存)')
|
||||
const toastText = String(window.document.querySelector('.iwb-toast-err').textContent || '')
|
||||
assert.ok(/保存失败/.test(toastText), '失败 toast 的文案要能说明是「保存失败」,实际:' + JSON.stringify(toastText))
|
||||
const meta2 = window.document.querySelector('.iwb-canvas-meta')
|
||||
const errInMeta2 = Array.from(meta2.querySelectorAll('.iwb-status-err')).map((el) => String(el.textContent || '')).join(' | ')
|
||||
assert.ok(/保存失败/.test(errInMeta2), '顶栏状态栏也要出现「保存失败」(首页/画布都要可见),实际:' + JSON.stringify(errInMeta2))
|
||||
// ── 6. 提示词收藏入口已归插件(2026-11-27)──────────────────────────────
|
||||
// 宿主的「添加到提示词库」按钮已移除:收集能力由 promptlib 插件注册(nodeActions / 插件命令),插件停用即消失。
|
||||
// 原先「点按钮 → 存储失败 → 红色回执」的宿主契约随之不存在,保存失败可见性改由插件负责。
|
||||
// 这里只钉「宿主不得再自带入口」。
|
||||
assert.equal(Array.from(window.document.querySelectorAll('button')).filter((b) => b.title === '添加到提示词库').length, 0,
|
||||
'宿主不应再渲染「添加到提示词库」入口(收集入口归插件)')
|
||||
|
||||
console.log('canvas meta / error notice checks passed(真实渲染:错误提示对用户可见 + 挂载位置正确 + 保存失败有红色回执)')
|
||||
console.log('canvas meta / error notice checks passed(真实渲染:错误提示对用户可见 + 挂载位置正确 + 收集入口已归插件)')
|
||||
window.close()
|
||||
// jsdom 里的 React 定时器会让事件循环不空 ⇒ 必须显式退出(见规则库 §13.44)
|
||||
process.exit(0)
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
// 提示词收藏(宿主 → 提示词库插件):2026-11-27 修复的回归守护
|
||||
// 提示词收藏(2026-11-27 起归插件):入口随插件启停,宿主不再自带
|
||||
//
|
||||
// 背景:提示词库插件 1.13 起「唯一真源 = plugin-data/promptlib.json」,宿主 localStorage 只在插件首次迁移时被读。
|
||||
// 旧实现只写宿主 ⇒ 条目「加进去了但面板看不见」。现在走插件能力:以插件数据为基底追加到未分组,再写回 + 通知刷新。
|
||||
// 契约:
|
||||
// ① 提示词节点选中后,气泡里的「收藏为提示词」由 promptlib 插件注册(nodeActions);
|
||||
// ② 右键菜单出现插件命令「收藏选中的提示词」(ctx.commands);
|
||||
// ③ 宿主不得保留自带的入库入口(气泡星标 / 右键「添加该提示词」/「添加到提示词库」);
|
||||
// ④ 收藏写入插件数据(plugin-data/promptlib.json),默认 group 为空(未分组);
|
||||
// ⑤ 插件停用 → 两个入口同时消失。
|
||||
const { test, expect } = require('./_pw-coverage')
|
||||
const W = require('./_helpers/wait')
|
||||
|
||||
@@ -20,15 +24,8 @@ async function boot (page) {
|
||||
await W.waitHomeReady(page)
|
||||
await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick()
|
||||
await page.waitForSelector('.iwb-canvas-topbar', { timeout: 20000 })
|
||||
await page.waitForTimeout(600)
|
||||
}
|
||||
|
||||
async function openPromptPanel (page) {
|
||||
await page.locator('.iwb-top-nav-icon[title="显示 / 隐藏右栏"]').first().click()
|
||||
await page.waitForTimeout(300)
|
||||
await page.locator('.iwb-dock-btn[data-panel="prompts"]').first().click()
|
||||
await expect(page.locator('.iwb-dock-body[data-panel="prompts"]')).toBeVisible({ timeout: 10000 })
|
||||
await page.waitForTimeout(600)
|
||||
await page.waitForFunction(() => Boolean(window.IWBPluginHost) && window.IWBPluginHost.snapshot().initialized === true)
|
||||
await page.waitForTimeout(800)
|
||||
}
|
||||
|
||||
const readData = (page) => page.evaluate(async () => {
|
||||
@@ -36,47 +33,46 @@ const readData = (page) => page.evaluate(async () => {
|
||||
return { prompts: (d && d.prompts) || [], groups: (d && d.groups) || [] }
|
||||
})
|
||||
|
||||
test('节点气泡收藏:写进插件数据、默认未分组、面板立刻可见', async ({ page }) => {
|
||||
const pluginAction = (page) => page.locator('.iwb-node-floatbar-plugin[data-tip="收藏为提示词"]')
|
||||
const hostEntry = (page) => page.locator('.iwb-node-floatbar button[aria-label="添加到提示词库"]')
|
||||
|
||||
test('气泡入口由插件提供;宿主不再自带;收藏进未分组', async ({ page }) => {
|
||||
await boot(page)
|
||||
await openPromptPanel(page)
|
||||
await page.locator('[data-node-id="p1"] .iwb-node-head').click()
|
||||
await page.locator('.iwb-node-floatbar button[aria-label="添加到提示词库"]').first().click()
|
||||
await expect(page.locator('.iwb-plp-card'), '收藏后面板应立刻出现该条目').toHaveCount(1, { timeout: 8000 })
|
||||
await expect(pluginAction(page), '插件应提供「收藏为提示词」气泡按钮').toBeVisible({ timeout: 10000 })
|
||||
await expect(hostEntry(page), '宿主不应再有自带收藏入口').toHaveCount(0)
|
||||
await pluginAction(page).click()
|
||||
await expect.poll(async () => (await readData(page)).prompts.length, { timeout: 8000 }).toBe(1)
|
||||
const d = await readData(page)
|
||||
expect(d.prompts.length, '插件数据应写入 1 条').toBe(1)
|
||||
expect(d.prompts[0].text).toBe('收藏用提示词')
|
||||
expect(String(d.prompts[0].group || ''), '默认应落在未分组(group 为空)').toBe('')
|
||||
expect(String(d.prompts[0].group || ''), '默认未分组').toBe('')
|
||||
})
|
||||
|
||||
test('右键「添加该提示词」:同样写入插件数据且未分组', async ({ page }) => {
|
||||
test('右键「插件命令」里有收藏入口,且宿主菜单无旧条目', async ({ page }) => {
|
||||
await boot(page)
|
||||
await page.locator('[data-node-id="p1"] .iwb-node-head').click()
|
||||
await page.locator('[data-node-id="p1"]').click({ button: 'right' })
|
||||
await page.locator('.iwb-ctxmenu:not(.iwb-ctx-sub) .iwb-ctx-item', { hasText: '该节点' }).first().hover()
|
||||
await page.locator('.iwb-ctxmenu.iwb-ctx-sub .iwb-ctx-item', { hasText: '添加该提示词' }).first().click()
|
||||
const main = '.iwb-ctxmenu:not(.iwb-ctx-sub)'
|
||||
await expect(page.locator(main)).toBeVisible({ timeout: 8000 })
|
||||
const cmd = page.locator(main + ' .iwb-ctx-item', { hasText: '收藏选中的提示词' })
|
||||
await expect(cmd, '插件命令应出现在右键菜单').toHaveCount(1)
|
||||
await expect(page.locator(main + ' .iwb-ctx-item', { hasText: '添加该提示词' }), '宿主旧条目应已移除').toHaveCount(0)
|
||||
await cmd.click()
|
||||
await expect.poll(async () => (await readData(page)).prompts.length, { timeout: 8000 }).toBe(1)
|
||||
const d = await readData(page)
|
||||
expect(String(d.prompts[0].group || '')).toBe('')
|
||||
expect(String((await readData(page)).prompts[0].group || '')).toBe('')
|
||||
})
|
||||
|
||||
test('追加不破坏既有条目(cover 引用原样保留,分组不被清空)', async ({ page }) => {
|
||||
test('插件停用后两个入口同时消失', async ({ page }) => {
|
||||
await boot(page)
|
||||
// 预置插件数据:一条带 cover:{img} 引用、且在「G」分组里
|
||||
await page.evaluate(async () => {
|
||||
await window.IWBPluginData.create('promptlib').write({
|
||||
schemaVersion: 3,
|
||||
prompts: [{ id: 'q0', name: '旧条目', text: '旧文案', tags: ['收藏'], group: 'G', cover: { img: 'old.jpg' } }],
|
||||
groups: [{ id: 'G', name: 'G' }],
|
||||
updatedAt: 1,
|
||||
})
|
||||
})
|
||||
await openPromptPanel(page)
|
||||
await page.locator('[data-node-id="p1"] .iwb-node-head').click()
|
||||
await page.locator('.iwb-node-floatbar button[aria-label="添加到提示词库"]').first().click()
|
||||
await expect.poll(async () => (await readData(page)).prompts.length, { timeout: 8000 }).toBe(2)
|
||||
const d = await readData(page)
|
||||
expect(d.prompts[0].cover && d.prompts[0].cover.img, '既有条目的封面引用不能被压平').toBe('old.jpg')
|
||||
expect(d.prompts[0].group, '既有条目分组不变').toBe('G')
|
||||
expect(String(d.prompts[1].group || ''), '新条目进未分组').toBe('')
|
||||
expect(d.groups.length, '分组表不被清空').toBe(1)
|
||||
await expect(pluginAction(page)).toBeVisible({ timeout: 10000 })
|
||||
await page.evaluate(() => window.IWBPluginHost.setEnabled('promptlib', false))
|
||||
await page.waitForTimeout(400)
|
||||
await page.locator('.iwb-canvas').click({ position: { x: 1200, y: 800 } })
|
||||
await page.locator('[data-node-id="p1"] .iwb-node-head').click()
|
||||
await expect(pluginAction(page), '停用后气泡入口应消失').toHaveCount(0)
|
||||
await page.locator('[data-node-id="p1"]').click({ button: 'right' })
|
||||
const main = '.iwb-ctxmenu:not(.iwb-ctx-sub)'
|
||||
await expect(page.locator(main)).toBeVisible({ timeout: 8000 })
|
||||
await expect(page.locator(main + ' .iwb-ctx-item', { hasText: '收藏选中的提示词' }), '停用后右键命令应消失').toHaveCount(0)
|
||||
})
|
||||
@@ -70,7 +70,7 @@ test('② 节点气泡:单选时图标显示 2 字功能名(改名/复制)
|
||||
const single = page.locator('.iwb-node-floatbar:not(.iwb-node-floatbar-group)')
|
||||
await expect(single).toBeVisible()
|
||||
|
||||
// 2026-11-27:单选气泡现为 解组/并入分组/放大编辑/改名/复制/添加到提示词库/替换/粘贴/下载;
|
||||
// 2026-11-27:单选气泡现为 解组/并入分组/放大编辑/改名/复制/替换/粘贴/下载(收藏入口已归 promptlib 插件);
|
||||
// 「删除」「收藏」只在多选气泡(单选删除走 Delete 键 / 右键菜单)——这里守 2 字提示,也守「不该出现」。
|
||||
for (const label of ['改名', '复制']) {
|
||||
const btn = single.locator(`button[aria-label="${label}"]`).first()
|
||||
|
||||
@@ -170,7 +170,7 @@ const MAX_SRC_COMPONENT_LINES = 531
|
||||
// · 图标解析统一(右键菜单 + 设置页走同一解析器,2 行) +2
|
||||
// 通用件(pick/grant/stat/readDataUrl/readBlob/参数校验)全部在 src/image-file-ref.js
|
||||
// 与 src/plugin-api-images.js,app.js 只做装配。
|
||||
const MAX_APP_JS_LINES = 8326 // +11(2026-11-27:停靠栏就绪后按新占位重新适应的监听;app.js 8315→8326) // +15(2026-11-26 复制/粘贴通道重写:DOM copy 事件装配、pasteCtx 增补实时选择/剪贴板读写、⌘V 改为主动粘贴;逻辑在 src/clipboard-graph.js 的 bindCopy 与 src/clipboard-paste.js 的 pasteFromKey) // +1(2026-11-26 相册外部路径重启复授权装配;逻辑在 src/image-file-ref.js) // +5(2026-11-26 标注覆盖保存:桌面端不再生成死 __cache(4 行)+ 插件 saveNodeImage 装配(1 行);事务逻辑在 src/runtime-workbench-logic.js)
|
||||
const MAX_APP_JS_LINES = 8324 // +11(2026-11-27:停靠栏就绪后按新占位重新适应的监听;app.js 8315→8326) // +15(2026-11-26 复制/粘贴通道重写:DOM copy 事件装配、pasteCtx 增补实时选择/剪贴板读写、⌘V 改为主动粘贴;逻辑在 src/clipboard-graph.js 的 bindCopy 与 src/clipboard-paste.js 的 pasteFromKey) // +1(2026-11-26 相册外部路径重启复授权装配;逻辑在 src/image-file-ref.js) // +5(2026-11-26 标注覆盖保存:桌面端不再生成死 __cache(4 行)+ 插件 saveNodeImage 装配(1 行);事务逻辑在 src/runtime-workbench-logic.js)
|
||||
const MAX_APP_JS_SHARE = 0.40
|
||||
|
||||
// ── 历史记账(供回溯,逐条保留)──────────────────────────────────────────────
|
||||
@@ -213,7 +213,7 @@ const MAX_APP_JS_SHARE = 0.40
|
||||
// 需要实时读 .iwb-world 变换 + 按同类型实测高度校正视觉中心;属装配层的 DOM 读取,
|
||||
// 放 src 会引入新的全局读取与边界快照改动,权衡后留在 app.js // +10(2026-11-01):背景色「悬停预览」的 DOM 补丁助手(纯 DOM,不写数据/不进撤销栈);
|
||||
// 属装配层最小的 DOM 操作,放 src 会引入新的全局读取与边界快照改动,权衡后留在 app.js
|
||||
const MAX_WORKBENCH_LINES = 2180 // +11(2026-11-27:同上,Workbench 2169→2180) // 2026-11-26 复制/粘贴通道重写(+14:refs 新增粘贴时间戳/系统剪贴板可信标记、pasteCtx 增补 ids/clipboardOf/stageClip/readNativeText、bindCopy 装配)
|
||||
const MAX_WORKBENCH_LINES = 2178 // +11(2026-11-27:同上,Workbench 2169→2180) // 2026-11-26 复制/粘贴通道重写(+14:refs 新增粘贴时间戳/系统剪贴板可信标记、pasteCtx 增补 ids/clipboardOf/stageClip/readNativeText、bindCopy 装配)
|
||||
// 2026-11-18 v3.25.21:模态层指针守卫(2 行)
|
||||
// 实测 3090 → 2998(省 92):① 生成取消族 cancelRunsFor/cancelRun/cancelTaskJobs
|
||||
// → src/runtime-workbench-logic.js 的 createCancelActions(−53);② 工作区列表写回族
|
||||
|
||||
Reference in new issue
Block a user