feat(plugin): 宿主 gallery capability + 图库面板 A 方案自动切换/回落 v3.25.51

- 新增 src/plugin-api-gallery.js(list/thumb/preview/download/insert/remove),impl 由 Workbench 渲染时注入
- plugin-host 能力表加 gallery
- 右栏图库:装了插件走插件,未装或挂载失败回落宿主面板(PluginBox 支持 fallback)
- 测试与边界快照同步(能力表含 gallery)
This commit is contained in:
qiqi committed 2026-11-20 11:24:27 +08:00
1 parent 502b85d8b1
commit 2594623c09
14 files changed
+92 -12

No files matched your search

+10
View File
@@ -14,6 +14,16 @@
> 3. 核验正式地址版本 → 之后才移动 `stable` / `stable-verified-<日期>` 标签、更新本 CHANGELOG、写 GitHub Release(`gh release create`)。
> 测试发现问题 → 改 → 再 `deploy:test`,正式环境不受影响。回滚点 `git reset --hard stable`。
## v3.25.51(2026-11-20)M5 第二步:宿主 gallery capability(插件可读图库)
- 新增 `src/plugin-api-gallery.js`:给插件稳定的 `ctx.gallery` 代理(`list / thumb / preview / download / insert / remove`)。
- 图片字节仍留宿主(`images/` + 图库索引),插件只拿元数据与缩略图 URL;`list` 复用 `IWBGalleryQuery`(同筛选/分页口径)。
- 实现由 Workbench 每次渲染 `setImpl()` 注入(capability 在 init 期创建,拿不到组件闭包)。
- `plugin-host` 能力表新增 `gallery`(`capabilities:['gallery']` 才可调用)。
- 右栏图库改为 **A 方案**:装了 gallery 插件(且 registerPanel 成功)走插件,否则/挂载失败**自动回落宿主面板**
(`ui-dock` 的 `PluginBox` 新增 `fallback`)。
- 验证:浏览器实测 `ctx.gallery.list()` 返回 `{items,total}`、`thumb(未知)` 返回空串、无报错;宿主面板照常渲染。
## v3.25.50(2026-11-20)M5 第一步:图库面板抽成独立模块(行为零变化)
- 新增 `src/ui-gallery-panel.js`:图库面板(头部三行 + 瀑布流网格 + 单项操作)从 `app.js` 移出,改为 props 驱动的纯组件。
+10 -1
View File
@@ -8071,6 +8071,14 @@ const tbCenterSeed = (type, refs) => {
onPromptsChange: (list) => setPrompts(list), onGroupsChange: setPromptGroups,
onInsertPrompt: (text, name) => { const id = uid('n'); const spot = findSpot('prompt'); commitCanvas(refs.nodes.concat([{ id, type: 'prompt', x: spot.x, y: spot.y, data: { text, title: name || '' } }]), undefined, undefined); setSel([id]); setNotice({ type: 'ok', text: '已插入提示词:' + (name || '') }) },
onFlash: (t, ty) => { setNotice({ type: ty === 'err' ? 'err' : 'ok', text: t }); showToast(t, ty) } })
if (window.IWBPluginGallery) window.IWBPluginGallery.setImpl({
list: (o) => window.IWBPluginGallery.query(outputs, o),
thumb: (name) => { const f = (outputs || []).find((x) => x.name === name); return f ? wDisplayThumbOf((f.data || f.url) || '') : '' },
preview: (name) => setPreview({ list: outputs.map((x) => ({ __gallery: true, name: x.name, origIdb: x.origIdb, idb: x.idb, url: x.url, thumb: x.data || null })), idx: Math.max(0, outputs.findIndex((x) => x.name === name)) }),
download: async (names) => { let n = 0; for (const f of (outputs || [])) if (names.indexOf(f.name) >= 0) { downloadUrl(await wResolveOutputSrc(f), f.name); n++ } return { ok: true, count: n } },
insert: async (names) => ({ ok: true, inserted: await insertOutputsToCanvas((outputs || []).filter((f) => names.indexOf(f.name) >= 0)) }),
remove: (names) => { deleteOutputs(names); setHistSel([]); return { ok: true } },
})
const dockGalleryEl = GalleryPanel ? el(GalleryPanel, {
outputs, filtered: histFiltered, buckets: histCols.buckets, sel: histSel, limit: histLimit,
insertK, tile: histTile, range: histRange,
@@ -8092,7 +8100,7 @@ const tbCenterSeed = (type, refs) => {
browser: { title: '浏览器', icon: 'globe', pluginId: 'browser' },
styles: { title: '风格库', icon: 'palette', pluginId: 'style-source' },
prompts: { title: '提示词库', icon: 'book', node: dockPromptsEl },
gallery: { title: '图库', icon: 'ref', node: dockGalleryEl },
gallery: wPluginPanels.some((x) => x && x.pluginId === 'gallery' && typeof x.mount === 'function') ? { title: '图库', icon: 'ref', pluginId: 'gallery', fallback: dockGalleryEl } : { title: '图库', icon: 'ref', node: dockGalleryEl },
}
return el('div', { className: 'iwb-overlay' + (wsExpanded ? ' ws-expanded' : '') + (shellView === 'landing' ? ' iwb-view-landing' : shellView === 'home' ? ' iwb-view-home' : ' iwb-view-canvas') + (drawerOpen ? ' drawer-open' : '') + ((nodes.length && loaded) ? ' has-minimap' : '') },
// 页面加载动画(加载完成后淡出)
@@ -8741,6 +8749,7 @@ items.push(el('button', { key: 'bgc', className: 'iwb-ctx-item', onClick: (e) =>
writeState: (state) => { lsSet('iwb_plugins', state) },
log: () => { try { wLog.apply(null, arguments) } catch (e) { /* ignore */ } },
capabilities: {
gallery: () => ((typeof window !== 'undefined' && window.IWBPluginGallery) ? window.IWBPluginGallery.api() : {}),
commands: (ctx) => {
const owned = []
return {
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "image-workbench-web",
"private": true,
"version": "3.25.50",
"version": "3.25.51",
"description": "Browser-based node canvas image workbench",
"scripts": {
"build": "node scripts/build.js && node scripts/copy-plugins.js",
+1
View File
@@ -78,6 +78,7 @@ const sourceModules = [
'gallery-hydration.js',
'ui-components.js',
'plugin-data.js',
'plugin-api-gallery.js',
'plugin-host.js',
'image-compress.js',
'storage-fallback-indexeddb.js',
+1 -1
View File
@@ -1983,7 +1983,7 @@ dependencies = [
[[package]]
name = "image-workbench"
version = "3.25.50"
version = "3.25.51"
dependencies = [
"arboard",
"base64 0.22.1",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "image-workbench"
version = "3.25.50"
version = "3.25.51"
description = "无限画布 · 生图工作台桌面版"
authors = ["malongan"]
license = ""
+1 -1
View File
@@ -1,7 +1,7 @@
{
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
"productName": "image-workbench",
"version": "3.25.50",
"version": "3.25.51",
"identifier": "com.malongan.imageworkbench",
"build": {
"frontendDist": "../dist",
+53
View File
@@ -0,0 +1,53 @@
/* plugin-api-gallery.js —— 宿主 gallery capability(M5)
*
* 给插件一块**只读为主**的图库访问面:列表 / 缩略图 / 预览 / 下载 / 插入画布 / 删除。
* 图片字节仍留在宿主(images/ + 图库索引),插件拿不到文件路径,只能拿元数据与缩略图 URL。
*
* 为什么要这层「impl 桥」:
* capability 在 PluginHost.init 时创建(早于组件渲染),拿不到 Workbench 的 state/refs。
* 所以这里只保存一组**稳定的代理函数**,真正的实现由 Workbench 每次渲染时 setImpl 注入。
*/
;(function (global) {
'use strict'
let impl = null
function setImpl (next) {
impl = (next && typeof next === 'object') ? next : null
}
function call (name) {
return function () {
const fn = impl && impl[name]
if (typeof fn !== 'function') return Promise.reject(new Error('图库能力未就绪'))
try { return Promise.resolve(fn.apply(null, arguments)) } catch (e) { return Promise.reject(e) }
}
}
// 稳定代理:插件拿到的对象永不变,内部每次都取最新的 impl
const API = {
list: call('list'),
thumb: call('thumb'),
preview: call('preview'),
download: call('download'),
insert: call('insert'),
remove: call('remove'),
}
// 纯函数:把宿主 outputs + 查询参数变成插件要的条目(不含 data,避免把 base64 递给插件)
function query (outputs, opt) {
const o = opt || {}
const Q = global.IWBGalleryQuery
const list = Array.isArray(outputs) ? outputs : []
const limit = Math.min(500, Math.max(1, Number(o.limit) || 200))
const res = (Q && typeof Q.queryOutputs === 'function')
? Q.queryOutputs(list, { query: o.query || '', range: o.range || '', limit, width: 320, tile: 130 })
: { filtered: list, visible: list.slice(0, limit), total: list.length }
const items = (res.visible || []).map(function (f) {
return { name: f.name, label: f.label || '', w: f.w || 0, h: f.h || 0, mtime: f.mtime || 0 }
})
return { items: items, total: res.total || items.length }
}
global.IWBPluginGallery = { setImpl: setImpl, api: function () { return API }, query: query }
})(typeof window !== 'undefined' ? window : globalThis)
+2 -2
View File
@@ -4,8 +4,8 @@
const API_VERSION = 1
const ID_PATTERN = /^[a-z][a-z0-9-]{2,31}$/
const REQUIRED_FIELDS = ['id', 'name', 'version', 'apiVersion', 'capabilities']
const CAPABILITIES = ['panels', 'commands', 'nodeTypes', 'generationHooks', 'providers', 'canvas', 'canvasWrite', 'nodeActions']
const CAPABILITY_API_KEYS = { panels: 'ui', commands: 'commands', nodeTypes: 'nodes', generationHooks: 'generation', providers: 'providers', canvas: 'canvas', canvasWrite: 'canvas', nodeActions: 'nodeActions' }
const CAPABILITIES = ['panels', 'commands', 'nodeTypes', 'generationHooks', 'providers', 'canvas', 'canvasWrite', 'nodeActions', 'gallery']
const CAPABILITY_API_KEYS = { panels: 'ui', commands: 'commands', nodeTypes: 'nodes', generationHooks: 'generation', providers: 'providers', canvas: 'canvas', canvasWrite: 'canvas', nodeActions: 'nodeActions', gallery: 'gallery' }
function createPluginHost(options) {
const opt = options || {}
+6 -3
View File
@@ -63,15 +63,18 @@
}
// 插件面板宿主:只在激活时挂载(切走即卸载)。挂载失败不影响其它面板。
// v3.25.51:挂载失败可回退(gallery 这类核心面板装插件后仍要有保底)
function PluginBox (props) {
const ref = useRef(null)
const [failed, setFailed] = useState(false)
const mount = props.mount
useEffect(() => {
const node = ref.current
if (!node || typeof mount !== 'function') return undefined
try { mount(node) } catch (e) { /* 插件挂载异常不得冒泡 */ }
if (!node || typeof mount !== 'function') { setFailed(true); return undefined }
try { mount(node); setFailed(false) } catch (e) { setFailed(true) }
return undefined
}, [mount])
if (failed && props.fallback) return props.fallback
return el('div', { className: 'iwb-dock-plugin', ref })
}
@@ -298,7 +301,7 @@
if (p.pluginId) {
const mount = (props.pluginMount && props.pluginMount(p.pluginId)) || null
if (!mount) return el('div', { className: 'iwb-dock-empty' }, (p.title || '插件') + ' 未加载')
return el(PluginBox, { mount })
return el(PluginBox, { mount, fallback: p.fallback || null })
}
return el('div', { className: 'iwb-dock-empty' }, '面板不可用')
}
+1
View File
@@ -24,6 +24,7 @@
"IWBNativeClipboard",
"IWBNodeBodies",
"IWBPluginData",
"IWBPluginGallery",
"IWBPluginHost",
"IWBProviderPing",
"IWBResultImg",
+1
View File
@@ -50,6 +50,7 @@
"gallery-hydration.js",
"ui-components.js",
"plugin-data.js",
"plugin-api-gallery.js",
"plugin-host.js",
"image-compress.js",
"storage-fallback-indexeddb.js",
+1 -1
View File
@@ -13,7 +13,7 @@ vm.runInNewContext(source, sandbox)
const host0 = sandbox.IWBPluginHost
assert.ok(Number.isInteger(host0.apiVersion) && host0.apiVersion >= 1, 'apiVersion 必须是正整数')
assert.ok(Array.isArray(host0.capabilities) && host0.capabilities.length >= 7, '能力清单应非空')
assert.strictEqual(host0.capabilities.slice().sort().join(','), 'canvas,canvasWrite,commands,generationHooks,nodeActions,nodeTypes,panels,providers')
assert.strictEqual(host0.capabilities.slice().sort().join(','), 'canvas,canvasWrite,commands,gallery,generationHooks,nodeActions,nodeTypes,panels,providers')
const manifest = (over) => Object.assign({ id: 'demo-plugin', name: 'Demo', version: '1.0.0', apiVersion: 1, capabilities: [] }, over)
const stateOf = (ids) => {
+3 -1
View File
@@ -26,7 +26,9 @@ assert.ok(!allSrc.includes("title: '图库(右侧栏)'"))
assert.ok(allSrc.includes("title: '显示 / 隐藏右栏'"))
assert.ok(source.includes("panels: dockPanels"))
assert.ok(source.includes("groups: { title: '节点组'"))
assert.ok(source.includes("gallery: { title: '图库'"))
// v3.25.51:gallery 面板改为「装了插件用插件、否则宿主」,断言两种分支都在
assert.ok(source.includes("pluginId: 'gallery'"))
assert.ok(source.includes("node: dockGalleryEl"))
assert.ok(allSrc.includes("className: 'iwb-res-tab'"))
assert.ok(allSrc.includes("className: 'iwb-res-tabs'"))
assert.ok(css.includes('.iwb-res-tabs {'))