feat(plugins): 分享/导入分享、单节点收藏走提示词库、组内解组、图库打开目录与删除字节、插件设置页 token 化
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 2m1s

This commit is contained in:
qiqi committed 2026-11-24 10:39:25 +08:00
1 parent a378dc52ad
commit 2f8f355716
15 files changed
+284 -63

No files matched your search

+8 -5
View File
@@ -2058,6 +2058,7 @@ try { if (window.IWBMiniMapFit && typeof window.IWBMiniMapFit.install === 'funct
}
return added
}
const wDelGalleryBytes /* 图库删图一并清理磁盘字节(只删索引会留下文件) */ = (names) => { const F = (typeof window !== 'undefined') ? window.IWBStorageFile : null; try { if (F && F.deleteGalleryBytesFor) F.deleteGalleryBytesFor(names, lsGet(OUT_KEY, [])).catch(() => {}) } catch (e) { /* ignore */ } }
async function wActionOutputs(args) {
const action = args && args.action
if (ModularOutputStore && action === 'clear') {
@@ -2067,14 +2068,14 @@ try { if (window.IWBMiniMapFit && typeof window.IWBMiniMapFit.install === 'funct
}
if (ModularOutputStore && action === 'delete') {
const names = Array.isArray(args.names) ? args.names : []
await wPruneOutputIdb(names) // 缩略图 + 原图一并移除
await wPruneOutputIdb(names); await wDelGalleryBytes(names) // 缩略图 + 原图 + 磁盘字节
const modular = await ModularOutputStore.remove(names)
if (modular && modular.ok) return { ok: true, removed: modular.meta && modular.meta.removed !== undefined ? modular.meta.removed : names.length }
}
if (action === 'clear') { await wClearOutputIdb(); lsSet(OUT_KEY, []); return { ok: true } }
if (action === 'delete') {
const names = Array.isArray(args.names) ? args.names : []
await wPruneOutputIdb(names)
await wPruneOutputIdb(names); await wDelGalleryBytes(names)
const idx = lsGet(OUT_KEY, [])
lsSet(OUT_KEY, idx.filter((f) => !names.includes(f.name)))
return { ok: true, removed: names.length }
@@ -8242,7 +8243,7 @@ const tbCenterSeed = (type, refs) => {
return { ok: false, error: '剪贴板不可用' }
} catch (e) { return { ok: false, error: '剪贴板不可用' } }
},
notify: (text, type) => { setNotice({ type: type === 'err' ? 'err' : 'ok', text: String(text || '') }); showToast(String(text || ''), type) },
notify: (text, type) => { setNotice({ type: type === 'err' ? 'err' : 'ok', text: String(text || '') }); showToast(String(text || ''), type) }, paste: () => window.IWBDesktopHelpers.clipboardReadText(),
// v3.25.97:提示词封面 —— 图片走宿主内容寻址存储(images/plugin/prompt/),条目只存 ref。
putCover: (u) => wPromptCoverCtl().put(u),
coverUrl: (r) => wPromptCoverCtl().url(r),
@@ -8268,7 +8269,7 @@ const tbCenterSeed = (type, refs) => {
return { ok: failed.length === 0, count: n, failed: failed }
},
insert: async (names, o) => ({ ok: true, inserted: await insertOutputsToCanvas((outputs || []).filter((f) => names.indexOf(f.name) >= 0), (o && o.insertK) || '1k') }),
remove: async (names) => { const n = await deleteOutputs(names); return { ok: n > 0, removed: n } },
remove: async (names) => { const n = await deleteOutputs(names); return { ok: n > 0, removed: n } }, openFolder: () => window.IWBDesktopHelpers.openGalleryDir(),
})
// 节点组库插件(grouplib):数据仍由宿主持有,插件只拿读写/实例化能力
if (window.IWBPluginGroupLib) {
@@ -8530,12 +8531,14 @@ const tbCenterSeed = (type, refs) => {
})()
: (() => { const sn = (refs.nodes || nodes).find((n) => n && n.id === sel[0]); if (!sn) return null; const title = (sn.data && sn.data.title) || (nodeTypeTitle(sn.type)); const metaLabel = floatbarMetaLabel(wRawCfg(), sn); const pl = floatbarPlace(sn.y, sn.y + hOf(sn), floatbarLift(hasNodeTitle(sn), nodeInGroup(sn), true), viewport); return el('div', { className: 'iwb-node-floatbar' + (pl.below ? ' iwb-node-floatbar-below' : ''), onPointerDown: (e) => e.stopPropagation(), style: { left: viewport.x + (sn.x + nodeWidth(sn) / 2) * viewport.scale, top: pl.top, '--iwb-fb-k': String(pl.k) } }, metaLabel ? el('span', { className: 'iwb-node-floatbar-title', title: '当前服务商 · Key 分组' }, metaLabel) : null,
UiGenCfgModule && UiGenCfgModule.NodeBgPalette ? el(UiGenCfgModule.NodeBgPalette, { key: 'bgc', current: (sn.data && sn.data.bg) || '', onPreview: (bg) => previewNodeBg([sn.id], bg), onPreviewEnd: endNodeBgPreview, onPick: (bg) => updateNode(sn.id, { bg }) }) : null,
groupOf(sn.id) ? el('button', { 'aria-label': '解组', 'data-tip': '解组', onClick: (e) => { e.stopPropagation(); const g = groupOf(sn.id); if (g) ungroup(g.id) } }, I('ungroup')) : null,
// 未编组且与某个分组相连 ⇒「并入分组」(多个相连组时取成员最多的)
!groupOf(sn.id) && IWWorkbenchLogic.connectedGroupIdsOf(refs, sn.id).length ? el('button', { 'aria-label': '并入分组', 'data-tip': '并入分组', onClick: (e) => { e.stopPropagation(); joinGroupOf(sn.id) } }, I('group')) : null,
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(); saveSelectionAsGroup([sn.id], title) } }, I('star')) : null,
// 单节点不再有「收藏为节点组」;提示词的星标 = 添加到提示词库(与标题栏星标同一入口)
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,
+2 -2
View File
@@ -183,7 +183,7 @@
| `storage-reconcile` | 存储对账(`createReconciler`/`check`) | 内联对账 | 存储层收口 |
| `runtime-recovery-runner` | 执行恢复候选(`candidate`/`valid`/`run`) | 内联恢复 | 断点恢复 |
| `canvas-domain` | 画布域模型(`commit`/`updateNode`/`deleteNodes`…) | `CanvasStore` 那一套 | Workbench 解耦(P2-9) |
- **耦合面已冻结**:`tests/architecture-boundary-guard-test.js`(进 `npm run test:unit` 末环)冻结 app.js↔src 耦合面(**86** 项)与 `sourceModules` 顺序(**108** 项);命名例外由第 5 组冻结,新增非 `IWB` 前缀导出即打红。
- **耦合面已冻结**:`tests/architecture-boundary-guard-test.js`(进 `npm run test:unit` 末环)冻结 app.js↔src 耦合面(**87** 项)与 `sourceModules` 顺序(**108** 项);命名例外由第 5 组冻结,新增非 `IWB` 前缀导出即打红。
## 12. 易踩的坑
@@ -254,7 +254,7 @@
**信任模型(必须明示)**:形态 A 的插件是**可信代码**(与核心同权限、无沙箱);启停与设置是 UX 与可维护性手段,**不是安全边界**(同 §13.27 教训:前端开关一定可被绕过)。
**守门与快照**:`tests/architecture-boundary-guard-test.js` 冻结「app.js ↔ src 耦合面」(**86** 项)与 `sourceModules` 顺序(**108** 项);新增模块、新增耦合、新增 dev 探针都**必须有意重生成对应快照**(`IWB_WRITE_BOUNDARY_SNAPSHOT=1`)。契约与行为的可执行验证在 `tests/plugin-host-test.js`(宿主单测)与 `tests/_plugin-host-probe.spec.js`(真实浏览器探针,`_` 前缀 + `iwb-dev-probe`,不进 34 门禁)。
**守门与快照**:`tests/architecture-boundary-guard-test.js` 冻结「app.js ↔ src 耦合面」(**87** 项)与 `sourceModules` 顺序(**108** 项);新增模块、新增耦合、新增 dev 探针都**必须有意重生成对应快照**(`IWB_WRITE_BOUNDARY_SNAPSHOT=1`)。契约与行为的可执行验证在 `tests/plugin-host-test.js`(宿主单测)与 `tests/_plugin-host-probe.spec.js`(真实浏览器探针,`_` 前缀 + `iwb-dev-probe`,不进 34 门禁)。
**关键陷阱**:`normalizeNodes`(现位于 `src/canvas-normalize.js`)会**静默丢弃**不在 `NODE_H` 里的节点类型 ⇒ 新增节点类型必须先登记 `NODE_H`,否则节点一刷新就消失(§13.27 规则三的同一失败模式)。
+14 -2
View File
@@ -129,8 +129,20 @@
setBtn.setAttribute('aria-expanded', 'false')
var settings = el('div', { class: 'iwb-gal-settings', role: 'dialog', 'aria-label': '图库设置' })
settings.style.display = 'none'
// 2026-11-24:底栏加「打开本地图库目录」图标(文件夹),放在设置图标左边;只桌面端可用。
var folderBtn = iconBtn('打开本地目录', function (svg) {
svgPath(svg, 'M2 4.5h4l1.5 2H14v6.5H2z')
}, '在系统文件管理器里打开本地图库目录(images/gallery)')
folderBtn.addEventListener('click', function (e) {
e.stopPropagation()
if (!ctx.gallery || typeof ctx.gallery.openFolder !== 'function') { setStatus('仅桌面端可打开本地目录'); return }
Promise.resolve(ctx.gallery.openFolder()).then(function (r) {
if (r && r.ok === false) setStatus('打开失败:' + ((r && r.error) || '仅桌面端可用'))
}).catch(function (err) { setStatus('打开失败:' + ((err && err.message) || err)) })
})
folderBtn.style.display = (typeof window !== 'undefined' && window.__TAURI__ && window.__TAURI__.core) ? '' : 'none'
// v1.4.2:刷新与设置同放右侧工具组(此前刷新在左侧信息区,空间不足时会向右溢出、压住设置图标)
var tools = el('div', { class: 'iwb-gal-tools' }, refreshBtn, setBtn)
var tools = el('div', { class: 'iwb-gal-tools' }, refreshBtn, folderBtn, setBtn)
var foot = el('div', { class: 'iwb-gal-foot' },
el('div', { class: 'iwb-gal-foot-left' }, countEl, pickedEl, failEl, statusEl), tools)
var wrap = el('div', { class: 'iwb-history-embedded' }, [head, grid, more, empty, foot, settings])
@@ -543,7 +555,7 @@
global.IWBPluginHost.register({
id: 'gallery',
name: '图库',
version: '1.6.11',
version: '1.6.12',
apiVersion: 1,
capabilities: ['panels', 'gallery'],
data: { schemaVersion: 1, maxBytes: 65536 },
+2 -2
View File
@@ -1,7 +1,7 @@
{
"id": "gallery",
"name": "图库",
"version": "1.6.11",
"version": "1.6.12",
"apiVersion": 1,
"main": "main.js",
"style": "styles.css",
@@ -13,7 +13,7 @@
"图库"
],
"files": {
"main.js": "cf456629b21f9001d7cc8016a6af0d2b065aae110ef822b7946e6279ec822f11",
"main.js": "a5fb039684937de44d1033c75d9872b9e6d1c8c2c9582cd5feee948562e9b7d1",
"styles.css": "35ae17de8b0f3bddab9cbef6270cd8bbf5153c9ecf6ed2b4f06216f6fef45b8b"
}
}
+11 -5
View File
@@ -22,9 +22,9 @@
"dir": "gallery",
"main": "main.js",
"style": "styles.css",
"version": "1.6.11",
"version": "1.6.12",
"files": {
"main.js": "cf456629b21f9001d7cc8016a6af0d2b065aae110ef822b7946e6279ec822f11",
"main.js": "a5fb039684937de44d1033c75d9872b9e6d1c8c2c9582cd5feee948562e9b7d1",
"styles.css": "35ae17de8b0f3bddab9cbef6270cd8bbf5153c9ecf6ed2b4f06216f6fef45b8b"
}
},
@@ -44,10 +44,10 @@
"dir": "promptlib",
"main": "main.js",
"style": "styles.css",
"version": "1.8.24",
"version": "1.9.0",
"files": {
"main.js": "0bab5f57c173d0bf45a16881042d9b3b1973a2afe2e6c3745a27fd5181b793b0",
"styles.css": "e14fee1fd446188ef44913cc2d549e02480b10d95a67371078ec4fa623786d60"
"main.js": "317d52224dcec5850e2f8dd1d1193346f059595106211565bbe02f3ef7e74199",
"styles.css": "d799321065172c2844c565cea9abc69053663ef9ec962e35911e0331bcff85aa"
}
},
{
@@ -62,6 +62,12 @@
"version": "0.6.1",
"integrity": "sha256-Dlp/oBiy6d5wX5ESJyrQLc8Ye1NhaW9/wKEqk8TyDU4="
},
{
"id": "sticky",
"file": "plugin-sticky.950efcab13b1.js",
"version": "1.0.0",
"integrity": "sha256-lQ78qxOx/trCPmS+3BpQgUM0+akJw+eoQ1YN3V/wnt4="
},
{
"id": "style-source",
"file": "plugin-style-source.05c108f8a63c.js",
+100 -3
View File
@@ -151,6 +151,25 @@
return 'promptlib-backup-' + d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0') + '.json'
}
// 单条提示词分享(2026-11-24):文本带前缀,可直接粘到聊天软件;导入两种都认(带前缀 / 纯 JSON)。
var SHARE_TAG = 'IWB-PROMPT-SHARE'
function plpParseShare (raw) {
var t = String(raw || '').trim()
if (t.indexOf(SHARE_TAG) === 0) t = t.slice(SHARE_TAG.length).trim()
var obj = null
try { obj = JSON.parse(t) } catch (e) { return null }
var item = obj && (obj.kind === 'prompt-share' ? obj.sharing : (obj.sharing || (obj.text ? obj : null)))
if (!item || typeof item.text !== 'string' || !item.text.trim()) return null
return item
}
function plpSharePayload (p) {
return plpCoverUrl(p).then(function (cv) {
var body = { app: 'image-workbench', kind: 'prompt-share', version: 1, sharing: { name: p.name || '', text: p.text || '', vars: detectVars(p.text || ''), group: p.group || '', tags: p.tags || [] } }
if (cv && cv.length < 300000) body.sharing.cover = cv
return SHARE_TAG + '\n' + JSON.stringify(body)
})
}
function renderPluginSettings () {
var root = el('div', { class: 'iwb-plp-settings' })
var state = { prompts: [], groups: [] }
@@ -283,7 +302,31 @@
})
}).catch(function (e) { impBtn.disabled = false; status.textContent = '导入失败:' + ((e && e.message) || e) })
})
s2.appendChild(el('div', { class: 'iwb-plp-sbtns' }, expBtn, impBtn))
var impShareBtn = el('button', { class: 'iwb-btn iwb-btn-sm', title: '读取剪贴板里别人分享的单条提示词', text: '导入分享…' })
impShareBtn.addEventListener('click', function () {
impShareBtn.disabled = true; status.textContent = '读取剪贴板…'
Promise.resolve(PLP_CTX.promptlib.paste && PLP_CTX.promptlib.paste()).then(function (r) {
impShareBtn.disabled = false
if (!r || r.ok === false) { status.textContent = '读取剪贴板失败'; return null }
var item = plpParseShare(r.text)
if (!item) { status.textContent = '剪贴板里没有可识别的提示词分享'; return null }
var name = String(item.name || '').trim() || ('导入的提示词 ' + String(item.text).slice(0, 8) + '…')
state.prompts = state.prompts.concat([{ id: 'q' + Date.now().toString(36) + Math.random().toString(36).slice(2, 6), name: name, text: item.text, group: String(item.group || ''), tags: item.tags || [], vars: detectVars(item.text) }])
var g2 = String(item.group || '').trim()
if (g2 && !state.groups.some(function (x) { return x.name === g2 })) state.groups = state.groups.concat([{ id: g2, name: g2 }])
return save()
}).then(function (r2) {
if (!r2) return
return PLP_CTX.promptlib.list().then(function (cur) {
state.prompts = (cur && cur.prompts) || state.prompts
state.groups = (cur && cur.groups) || state.groups
paint(); refreshUsage()
status.textContent = '已导入分享'
plpNotify('已导入分享的提示词')
})
}).catch(function (e) { impShareBtn.disabled = false; status.textContent = '导入失败:' + ((e && e.message) || e) })
})
s2.appendChild(el('div', { class: 'iwb-plp-sbtns' }, expBtn, impBtn, impShareBtn))
s2.appendChild(el('label', { class: 'iwb-plp-sopt' }, overwrite, el('span', { text: '导入时覆盖同名条目' })))
s2.appendChild(status)
root.appendChild(s2)
@@ -658,6 +701,9 @@
var ed = el('button', { class: 'iwb-ctx-item', text: '编辑…' })
ed.addEventListener('click', function () { closeMenu(); openEditModal(p, false) })
menu.appendChild(ed)
var sh = el('button', { class: 'iwb-ctx-item', text: '分享…' })
sh.addEventListener('click', function () { closeMenu(); doShare(p) })
menu.appendChild(sh)
document.body.appendChild(menu)
menuEl = menu
setTimeout(function () { document.addEventListener('pointerdown', onDocDown, true) }, 0)
@@ -1254,9 +1300,47 @@
if (c.img && FILEAPI) return Promise.resolve(FILEAPI.get(String(c.img))).then(function (r) { return (r && r.ok && r.url) || '' }).catch(function () { return '' })
return Promise.resolve('')
}
// ===== 2026-11-24:单条提示词分享 / 导入别人的分享 =====
// 分享格式刻意做成「可读的 JSON 文本」,直接粘到微信/QQ 也能看懂;导入时两种都认:
// ① 带 IWB-PROMPT 头的整段文本 ② 直接是 {kind:'prompt-share'} 的 JSON
function sharePayload (p) {
return coverToDataUrl(p).then(function (cv) {
var body = { app: 'image-workbench', kind: 'prompt-share', version: 1, sharing: { name: p.name || '', text: p.text || '', vars: varsOf(p), group: p.group || '', tags: p.tags || [] } }
if (cv && cv.length < 300000) body.sharing.cover = cv
return SHARE_TAG + '\n' + JSON.stringify(body)
})
}
function doShare (p) {
if (!p) return
sharePayload(p).then(function (text) {
return Promise.resolve(api.copy(text)).then(function (r) {
if (r && r.ok === false) { notify('分享失败:' + ((r && r.error) || '剪贴板不可用'), 'err'); return }
notify('已复制分享内容,粘贴给对方即可')
})
}).catch(function (e) { notify('分享失败:' + ((e && e.message) || e), 'err') })
}
function doImportShare () {
return Promise.resolve(api.paste && api.paste()).then(function (r) {
if (!r || r.ok === false) { notify('读取剪贴板失败:' + ((r && r.error) || '剪贴板不可用'), 'err'); return { ok: false } }
var item = plpParseShare(r.text)
if (!item) { notify('剪贴板里没有可识别的提示词分享', 'err'); return { ok: false, error: 'no-share' } }
var name = String(item.name || '').trim() || ('导入的提示词 ' + String(item.text).slice(0, 8) + '…')
var incoming = normalize({ id: uid('q'), name: name, text: item.text, group: String(item.group || ''), tags: item.tags || [] })
var cv = item.cover
var ready = (typeof cv === 'string' && cv.indexOf('data:') === 0 && FILEAPI)
? Promise.resolve(FILEAPI.put(hashName(cv) + '.jpg', cv)).then(function (res) { return res && res.ok ? Object.assign({}, incoming, { cover: { img: hashName(cv) + '.jpg' } }) : incoming }).catch(function () { return incoming })
: Promise.resolve(incoming)
return ready.then(function (p2) {
prompts = prompts.concat([p2])
return persist().then(function () { render(); notify('已导入分享:' + (p2.name || '')); return { ok: true, name: p2.name } })
})
}).catch(function (e) { notify('导入失败:' + ((e && e.message) || e), 'err'); return { ok: false } })
}
function openBackup () {
var exportBtn = el('button', { class: 'iwb-btn iwb-btn-sm iwb-btn-primary', text: '导出备份…' })
var importBtn = el('button', { class: 'iwb-btn iwb-btn-sm', text: '导入备份…' })
var importShareBtn = el('button', { class: 'iwb-btn iwb-btn-sm', title: '读取剪贴板里的单条提示词分享并加入提示词库', text: '导入分享…' })
var overwrite = el('input', { type: 'checkbox' })
var status = el('div', { class: 'iwb-hint', text: '' })
openDialog({
@@ -1276,6 +1360,7 @@
bodyEl.appendChild(box)
footEl.appendChild(exportBtn)
footEl.appendChild(importBtn)
footEl.appendChild(importShareBtn)
exportBtn.addEventListener('click', function () {
exportBtn.disabled = true
status.textContent = '正在导出…'
@@ -1296,6 +1381,16 @@
else { status.textContent = '导出失败:' + ((r && r.error) || '未知错误'); notify('导出失败', 'err') }
}).catch(function (e) { exportBtn.disabled = false; status.textContent = '导出失败:' + ((e && e.message) || e); notify('导出失败', 'err') })
})
importShareBtn.addEventListener('click', function () {
importShareBtn.disabled = true
status.textContent = '读取剪贴板…'
doImportShare().then(function (r) {
importShareBtn.disabled = false
if (r && r.ok) status.textContent = '已导入分享:' + (r.name || '')
else if (r && r.error === 'no-share') status.textContent = '剪贴板里没有可识别的提示词分享'
else status.textContent = '导入失败'
}).catch(function (e) { importShareBtn.disabled = false; status.textContent = '导入失败:' + ((e && e.message) || e) })
})
importBtn.addEventListener('click', function () {
importBtn.disabled = true
status.textContent = '等待选择文件…'
@@ -1411,6 +1506,8 @@
})
})
cp.addEventListener('click', function () { Promise.resolve(api.copy(filled())).then(function (r) { if (r && r.ok === false) notify('复制失败', 'err'); else notify('已复制全文') }) })
var share = el('button', { class: 'iwb-btn iwb-btn-sm', title: '复制这条提示词的分享内容,粘贴给对方即可导入', text: '分享' })
share.addEventListener('click', function () { doShare(p) })
ins.addEventListener('click', function () { dlg.close(); beginPlacement('prompt', { text: filled(), name: p.name || '' }) })
var insImg = null
if (p.cover) {
@@ -1425,7 +1522,7 @@
}).catch(function () { notify('插入封面失败', 'err') })
})
}
footEl.appendChild(del); footEl.appendChild(el('span', { class: 'iwb-drawer-spacer' })); if (insTpl) footEl.appendChild(insTpl); footEl.appendChild(cp)
footEl.appendChild(del); footEl.appendChild(el('span', { class: 'iwb-drawer-spacer' })); if (insTpl) footEl.appendChild(insTpl); footEl.appendChild(cp); footEl.appendChild(share)
if (insImg) footEl.appendChild(insImg)
footEl.appendChild(ins)
},
@@ -1763,7 +1860,7 @@
global.IWBPluginHost.register({
id: 'promptlib',
name: '提示词库',
version: '1.8.24',
version: '1.9.0',
apiVersion: 1,
capabilities: ['panels', 'promptlib', 'nodeTypes', 'canvas', 'canvasWrite'],
data: { schemaVersion: 3, maxBytes: 4 * 1024 * 1024 },
+3 -3
View File
@@ -1,7 +1,7 @@
{
"id": "promptlib",
"name": "提示词库",
"version": "1.8.24",
"version": "1.9.0",
"apiVersion": 1,
"main": "main.js",
"style": "styles.css",
@@ -13,7 +13,7 @@
"提示词"
],
"files": {
"main.js": "0bab5f57c173d0bf45a16881042d9b3b1973a2afe2e6c3745a27fd5181b793b0",
"styles.css": "e14fee1fd446188ef44913cc2d549e02480b10d95a67371078ec4fa623786d60"
"main.js": "317d52224dcec5850e2f8dd1d1193346f059595106211565bbe02f3ef7e74199",
"styles.css": "d799321065172c2844c565cea9abc69053663ef9ec962e35911e0331bcff85aa"
}
}
+5 -3
View File
@@ -178,9 +178,11 @@
/* v1.5.10:设置页 */
.iwb-plp-settings{display:flex;flex-direction:column;gap: 16px}
.iwb-plp-ssec{border:1px solid var(--iwb-border,#e3e5e9);border-radius:12px;padding: 12px 12px;display:flex;flex-direction:column;gap:8px}
.iwb-plp-stitle{font-weight:600;font-size: 13px}
.iwb-plp-sgroups{display:flex;flex-direction:column;border:1px solid var(--iwb-border,#eef0f2);border-radius:10px;overflow:hidden}
/* 2026-11-24:插件设置页跟随宿主的设置分组 token(不再自画卡片,避免卡片套卡片) */
.iwb-plp-ssec{border:0;border-top:1px solid var(--iwb-set-divider,var(--iwb-border,#e3e5e9));border-radius:0;padding:var(--iwb-space-12) 0 0;display:flex;flex-direction:column;gap:var(--iwb-space-8)}
.iwb-plp-ssec:first-child{border-top:0;padding-top:0}
.iwb-plp-stitle{font-weight:600;font-size:var(--iwb-font-md,13px);color:var(--iwb-text,#2a2f36)}
.iwb-plp-sgroups{display:flex;flex-direction:column;border:1px solid var(--iwb-set-input-border,var(--iwb-border,#eef0f2));border-radius:var(--iwb-radius-card,10px);overflow:hidden}
.iwb-plp-sgrow{display:flex;align-items:center;gap:8px;padding: 6px 10px;border-top:1px solid var(--iwb-border,#f1f3f5)}
.iwb-plp-sgrow:first-child{border-top:0}
.iwb-plp-sgrip{width:12px;height:12px;background:radial-gradient(var(--iwb-text2,#c2c7cf) 1px,transparent 1px);background-size:4px 4px;border-radius: 6px;flex:0 0 auto}
+1
View File
@@ -32,6 +32,7 @@
download: call('download'),
insert: call('insert'),
remove: call('remove'),
openFolder: call('openFolder'),
}
// 纯函数:把宿主 outputs + 查询参数变成插件要的条目(不含 data,避免把 base64 递给插件)
+2
View File
@@ -5,6 +5,7 @@
* save({prompts, groups}) → 落盘(宿主仍持有数据:iwb_web_prompts + 分组缓存)
* insert(text, name) → 在画布视口中心插入提示词节点(插件不碰画布状态)
* copy(text) → 走宿主剪贴板(失败有可见提示)
* paste() → 读剪贴板文本(导入别人的分享用)
* insertImage(cover, name) → 把封面作为参考图节点插入画布
* notify(text, type) → 宿主 toast / 提示条
* putCover(dataUrl) → 封面入宿主图片库(返回 ref)
@@ -52,6 +53,7 @@
save: call('save'),
insert: call('insert'),
copy: call('copy'),
paste: call('paste'),
insertImage: call('insertImage'),
notify: call('notify'),
putCover: call('putCover'),
+31
View File
@@ -26,6 +26,9 @@
getAutoDownload() { return !!(state.impl && state.impl.getAutoDownload && state.impl.getAutoDownload()) },
setAutoDownload(on) { if (state.impl && state.impl.setAutoDownload) state.impl.setAutoDownload(on) },
openDataDir() { return state.impl ? state.impl.openDataDir() : Promise.reject(new Error('仅桌面端可用')) },
// 2026-11-24:插件要「打开本地图库目录」「读剪贴板导入分享」——都落在宿主桥里,app.js 只做装配。
openDataSubpath(rel) { return state.impl && state.impl.openDataSubpath ? state.impl.openDataSubpath(rel) : Promise.reject(new Error('仅桌面端可用')) },
clipboardReadText() { return state.impl && state.impl.clipboardReadText ? state.impl.clipboardReadText() : Promise.resolve('') },
// 原生剪贴板图片(v3.26):WKWebView 里 paste 事件拿不到 Finder 复制的图片,
// navigator.clipboard.write 也常不可用,统一走 Rust 侧 arboard。
clipboardReadImage() { return state.impl && state.impl.clipboardReadImage ? state.impl.clipboardReadImage() : Promise.resolve(null) },
@@ -37,5 +40,33 @@
uninstall(id) { return state.impl && state.impl.marketUninstall ? state.impl.marketUninstall(id) : Promise.resolve({ ok: false, error: '仅桌面端可用' }) },
},
}
// 2026-11-24:插件侧「打开资料目录子路径」「读剪贴板文本」两个小能力。
// 放在桥里而不是 app.js:一是 app.js 有行数棘轮,二是它们只依赖 __TAURI__。
const helpers = {
async openGalleryDir () {
try {
const T = (typeof window !== 'undefined') ? window.__TAURI__ : null
if (!T || !T.core || typeof T.core.invoke !== 'function') return { ok: false, error: '仅桌面端可打开本地目录' }
const p = await T.core.invoke('open_data_subpath', { rel: 'images/gallery' })
return { ok: true, path: p }
} catch (e) { return { ok: false, error: String((e && e.message) || e) } }
},
async clipboardReadText () {
try {
const T = (typeof window !== 'undefined') ? window.__TAURI__ : null
if (T && T.core && typeof T.core.invoke === 'function') {
const t = await T.core.invoke('clipboard_read_text')
if (t) return { ok: true, text: String(t) }
}
} catch (e) { /* 落到 navigator */ }
try {
const cb = navigator.clipboard
if (cb && typeof cb.readText === 'function') return { ok: true, text: String((await cb.readText()) || '') }
} catch (e) { return { ok: false, error: '浏览器拒绝了剪贴板读取' } }
return { ok: false, error: '剪贴板不可用' }
},
}
global.IWBDesktopHelpers = helpers
global.IWBDesktop = bridge
})(typeof window !== 'undefined' ? window : globalThis)
+59 -1
View File
@@ -1256,8 +1256,66 @@
} catch (e) { return { ok: false, error: String((e && e.message) || e) } }
}
/* 删除指定 key 的图片字节(2026-11-24):图库删图时索引清了、文件却还在 images/gallery/ 里,
* 用户看到的「数据库里没删」就是这个。这里按登记表把文件移进 trash/(不直删,可找回),
* 同时删掉登记项;画布仍引用同一文件时不搬(同一图可能既被画布引用又被图库引用)。 */
async function deleteImageBytes(keys) {
try {
if (!enabled() || !dir) return { ok: false, error: '资料目录未就绪' }
const list = Array.isArray(keys) ? keys : []
if (!list.length) return { ok: true, moved: 0 }
const canvasKeys = new Set()
try {
const cd = await join(dir, 'canvases')
const ents = await fs().readDir(cd)
for (const e of ents) {
if (!e || e.isDirectory || !/\.json$/i.test(e.name) || e.name === 'active.json') continue
let txt = ''
try { txt = await fs().readTextFile(await join(cd, e.name)) } catch (err) { continue }
for (const hit of (txt.match(/"__blob"\s*:\s*"([^"]+)"/g) || [])) { const km = /"([^"]+)"$/.exec(hit); if (km) canvasKeys.add(km[1]) }
}
} catch (e) { /* 画布读不到:按「不引用」处理,仍移到 trash 而非直删 */ }
const keepFiles = new Set()
for (const k of canvasKeys) { const a = assets[k]; if (a && a.f) keepFiles.add(a.f) }
const trashAbs = await join(dir, 'trash')
let moved = 0
for (const key of list) {
const k = String(key)
const a = assets[k]
if (a && a.f) {
delete assets[k]
if (!keepFiles.has(a.f)) {
try {
const sub = String(a.f).split('/')[1] || ''
const targetDir = sub ? await join(trashAbs, sub) : trashAbs
await fs().mkdir(targetDir, { recursive: true })
await fs().rename(await join(dir, a.f), await join(targetDir, a.f.split('/').pop()))
moved++
} catch (e) { /* 单条失败忽略 */ }
}
}
if (Object.prototype.hasOwnProperty.call(small, k)) delete small[k]
}
schedule()
return { ok: true, moved: moved }
} catch (e) { return { ok: false, error: String((e && e.message) || e) } }
}
// 2026-11-24:按图库条目名删字节 —— app.js 只传 names + 索引,逻辑留在这里(app.js 行数棘轮)。
async function deleteGalleryBytesFor (names, index) {
const wanted = Array.isArray(names) ? names : []
if (!wanted.length) return { ok: true, moved: 0 }
const keys = []
for (const it of (Array.isArray(index) ? index : [])) {
if (!it || wanted.indexOf(it.name) < 0) continue
if (it.idb) keys.push(it.idb)
if (it.origIdb) keys.push(it.origIdb)
}
return deleteImageBytes(keys)
}
global.IWBStorageFile = {
enabled, ready: init, flush, runtime, pickDir, switchTo, migrateTo, gcImages, rotateTrash, galleryThumb, readDisplayThumb, readDisplayThumbUrl, writeDisplayThumb, writeDisplayThumbBlob, pruneThumbs, cleanupLegacy, maintain,
enabled, ready: init, flush, runtime, pickDir, switchTo, migrateTo, deleteImageBytes, deleteGalleryBytesFor, gcImages, rotateTrash, galleryThumb, readDisplayThumb, readDisplayThumbUrl, writeDisplayThumb, writeDisplayThumbBlob, pruneThumbs, cleanupLegacy, maintain,
plugins: { manifest: pluginManifest, read: pluginRead, write: pluginWrite, remove: pluginRemove, dir: pluginDir, listLocal: pluginListLocal, listDirs: pluginListDirs, readFile: pluginReadFile, writeFile: pluginWriteFile, writeBinary: pluginWriteBinary, mkdir: pluginMkdir, removeDir: pluginRemoveDir, renameDir: pluginRenameDir, existsDir: pluginExistsDir },
pluginData: { read: pluginDataRead, write: pluginDataWrite, remove: pluginDataRemove, list: pluginDataList },
pluginFiles: { put: pluginFilePut, get: pluginFileGet, list: pluginFileList, remove: pluginFileRemove, stat: pluginFileStat, dir: pluginFilesDir },
+42 -36
View File
@@ -806,36 +806,17 @@ function GSetGroup (props) {
function renderPluginSettingsPage (ctx) {
const { PluginHost, activePlugin, setMsg, setPluginsRev, setTab } = ctx
const pluginSettingsPage = activePlugin ? el('div', { className: 'iwb-gset-page' },
el('div', { className: 'iwb-mk-setrow' },
el('div', { className: 'iwb-mk-setrow-main' },
el('div', { className: 'iwb-mk-setrow-title' }, activePlugin.name,
el('span', { className: 'iwb-plugin-tag' + (activePlugin.enabled ? '' : ' iwb-plugin-tag-warn'), style: { marginLeft: 8 } }, activePlugin.enabled ? '已启用' : '未启用'),
activePlugin.compatible ? null : el('span', { className: 'iwb-plugin-tag iwb-plugin-tag-warn', style: { marginLeft: 4 } }, 'apiVersion 不兼容'),
),
el('div', { className: 'iwb-hint' }, activePlugin.id + ' · v' + activePlugin.version),
),
el('button', { className: 'iwb-btn iwb-btn-sm', onClick: function () {
try { if (PluginHost && typeof PluginHost.persist === 'function') PluginHost.persist() } catch (e) { /* ignore */ }
if (setMsg) setMsg('已保存插件设置')
} }, '保存设置'),
el('button', { className: 'iwb-btn iwb-btn-sm', onClick: function () { setTab('plugins') } }, '返回'),
),
activePlugin.error ? el('div', { className: 'iwb-status-err' }, activePlugin.error) : null,
el('div', { className: 'iwb-section-sub' }, '设置'),
Object.keys(activePlugin.settingsSchema || {}).length ? Object.keys(activePlugin.settingsSchema).map(function (key) {
const spec = activePlugin.settingsSchema[key] || {}
const value = activePlugin.settings && activePlugin.settings[key] !== undefined ? activePlugin.settings[key] : spec.default
const commit = function (next) { PluginHost.setSetting(activePlugin.id, key, next); setPluginsRev(function (v) { return v + 1 }) }
const isCustom = spec.type === 'custom' && typeof spec.render === 'function'
// 说明在上、控件在下(左对齐):右侧 260px 的窄框放地址/多行内容既看不全也
// 改不动;boolean 仍是行末开关(这类是「开/关」而不是填写内容)。
const stacked = isCustom || spec.type === 'text' || spec.type === 'number'
return el('div', { key: key, className: 'iwb-mk-setrow' + (stacked ? ' iwb-mk-setrow-col' : '') },
el('div', { className: 'iwb-mk-setrow-main' },
el('div', { className: 'iwb-mk-setrow-title' }, spec.label || key),
spec.desc ? el('div', { className: 'iwb-hint' }, spec.desc) : null,
),
if (!activePlugin) return el('div', { className: 'iwb-hint' }, '插件不存在或已卸载。')
// 2026-11-24:插件设置页按设置面板 token 重排(GSetGroup + 行网格),不再自造 mk-setrow 卡片。
const rows = Object.keys(activePlugin.settingsSchema || {}).map(function (key) {
const spec = activePlugin.settingsSchema[key] || {}
const value = activePlugin.settings && activePlugin.settings[key] !== undefined ? activePlugin.settings[key] : spec.default
const commit = function (next) { PluginHost.setSetting(activePlugin.id, key, next); setPluginsRev(function (v) { return v + 1 }) }
const isCustom = spec.type === 'custom' && typeof spec.render === 'function'
const stacked = isCustom || spec.type === 'text' || spec.type === 'number'
return el('div', { key: key, className: 'iwb-gset-row' + (stacked ? ' iwb-gset-row-stacked' : '') },
el('div', { className: 'iwb-gset-row-label' }, spec.label || key),
el('div', { className: 'iwb-gset-row-ctl' },
spec.type === 'boolean'
? el('label', { className: 'iwb-switch' },
el('input', { type: 'checkbox', checked: Boolean(value), onChange: function (e) { commit(e.target.checked) } }),
@@ -844,15 +825,40 @@ function GSetGroup (props) {
: isCustom
? el(PluginCustomSetting, { key: 'custom-' + key, spec: spec, value: value, commit: commit, pluginId: activePlugin.id })
: el('input', {
className: 'iwb-input', type: spec.type === 'number' ? 'number' : 'text',
style: { maxWidth: '520px' },
className: 'iwb-input iwb-grow', type: spec.type === 'number' ? 'number' : 'text',
value: value === undefined ? '' : String(value),
onChange: function (e) { commit(spec.type === 'number' ? Number(e.target.value) : e.target.value) },
}),
)
}) : el('div', { className: 'iwb-hint' }, '该插件没有可配置项。'),
) : el('div', { className: 'iwb-hint' }, '插件不存在或已卸载。')
return pluginSettingsPage
),
)
})
return el('div', { className: 'iwb-gset-page' },
el('div', { className: 'iwb-gset-group' },
el('div', { className: 'iwb-gset-group-h' }, activePlugin.name),
el('div', { className: 'iwb-gset-group-body' },
el('div', { className: 'iwb-gset-row' },
el('div', { className: 'iwb-gset-row-label' }, '插件信息'),
el('div', { className: 'iwb-gset-row-ctl' },
el('span', { className: 'iwb-plugin-tag' + (activePlugin.enabled ? '' : ' iwb-plugin-tag-warn') }, activePlugin.enabled ? '已启用' : '未启用'),
activePlugin.compatible ? null : el('span', { className: 'iwb-plugin-tag iwb-plugin-tag-warn' }, 'apiVersion 不兼容'),
el('span', { className: 'iwb-gset-hint' }, activePlugin.id + ' · v' + activePlugin.version),
),
),
activePlugin.error ? el('div', { className: 'iwb-gset-row' }, el('div', { className: 'iwb-gset-row-label' }, '错误'), el('div', { className: 'iwb-gset-row-ctl' }, el('span', { className: 'iwb-status-err' }, activePlugin.error))) : null,
rows.length ? rows : el('div', { className: 'iwb-gset-row' }, el('div', { className: 'iwb-gset-row-label' }, '设置'), el('div', { className: 'iwb-gset-row-ctl' }, el('span', { className: 'iwb-gset-hint' }, '该插件没有可配置项。'))),
el('div', { className: 'iwb-gset-row' },
el('div', { className: 'iwb-gset-row-label' }, '操作'),
el('div', { className: 'iwb-gset-row-ctl' },
el('button', { className: 'iwb-btn iwb-btn-sm iwb-btn-primary', onClick: function () {
try { if (PluginHost && typeof PluginHost.persist === 'function') PluginHost.persist() } catch (e) { /* ignore */ }
if (setMsg) setMsg('已保存插件设置')
} }, '保存设置'),
el('button', { className: 'iwb-btn iwb-btn-sm', onClick: function () { setTab('plugins') } }, '返回'),
),
),
),
),
)
}
function renderAutoBackupSection (ctx) {
+1
View File
@@ -10,6 +10,7 @@
"IWBCanvasText",
"IWBCrashLog",
"IWBDesktop",
"IWBDesktopHelpers",
"IWBDockArea",
"IWBGalleryHydration",
"IWBGenerationRequestShape",
+3 -1
View File
@@ -110,7 +110,9 @@ async function boot ({ items, thumb, clock }) {
assert.strictEqual(env.window.getComputedStyle(tools).display, 'flex', '工具组应为横排 flex(否则图标会竖排)')
assert.ok(tools, '底栏应有右侧工具组')
const footBtns = Array.from(tools.querySelectorAll('button'))
assert.strictEqual(footBtns.length, 2, '工具组应为刷新+设置两个图标,实际 ' + footBtns.length)
// 2026-11-24:工具组多了「打开本地目录」图标(文件夹,仅桌面端可见)⇒ 顺序固定为 刷新 / 打开目录 / 设置
assert.strictEqual(footBtns.length, 3, '工具组应为刷新 + 打开目录 + 设置三个图标,实际 ' + footBtns.length)
assert.strictEqual(footBtns[2].getAttribute('aria-label'), '设置', '设置必须是最右边的图标(打开目录在它左边)')
const btn = footBtns.find((b) => b.getAttribute('aria-label') === '刷新')
assert.ok(btn, '底部应有刷新按钮(aria-label=刷新)')
// 刷新不能再留在左侧信息区(否则空间不足会向右压住设置)