feat(dock): 动态插件面板进停靠栏(panels 能力恢复 UI 落点)

背景:资源中心浮窗下线后,停靠栏面板清单固定为 5 个(节点组/浏览器/风格库/提示词库/图库),
插件通过 ctx.ui.registerPanel 注册的面板没有 UI 落点 —— 能力还在但用户看不到。

实现:
1. src/ui-dock-panels.js:build(PluginHost, pluginPanels) 追加动态面板,key = plugin:<pluginId>:<panelId>;
   固定面板已覆盖的插件不重复加;插件停用时整个面板消失。
2. src/ui-dock-sanitize.js:新出现的 plugin:* 面板默认回填到右栏(removed 里的不补、已摆过的不重复)。
3. src/ui-dock.js:挂载时把 panelId 一起传给 pluginMount。
4. app.js:build 传 wPluginPanels;pluginMount(id, panelId) 按插件+面板 id 精确解析。

验证:
- tests/ui-dock-sanitize-test.js 新增「动态面板回填 + 清单构建」断言(含 removed / 重复 / 停用)
- tests/_plugin-host-probe.spec.js 的 fixme 用例改回真跑:启用后右栏出现面板按钮 → 点击挂载出 PANEL-MOUNTED → 停用后按钮消失
- npm run verify:ci 全绿(含 e2e 冒烟 31 条 / 45s)
This commit is contained in:
qiqi authored and qiqi@local committed 2026-11-27 07:55:00 +08:00
1 parent 0f06128b3a
commit 00f05f686f
7 files changed
+78 -17

No files matched your search

+20 -1
View File
@@ -16,19 +16,38 @@
gallery: { title: '图库', icon: 'ref', pluginId: 'gallery', hint: '图库插件未安装 · 设置 → 插件 → 市场安装' },
}
function build (PluginHost) {
function build (PluginHost, pluginPanels) {
let list = []
try { list = (PluginHost && typeof PluginHost.list === 'function') ? (PluginHost.list() || []) : [] } catch (e) { list = [] }
const ready = list.length > 0
const out = {}
const fixedPlugins = {}
for (const k of Object.keys(ALL)) {
const p = ALL[k]
if (p.pluginId) fixedPlugins[p.pluginId] = true
if (ready && p.pluginId) {
const hit = list.find((x) => x && x.id === p.pluginId)
if (!hit || !hit.enabled) continue
}
out[k] = p
}
// 2026-11-27:动态插件面板(ctx.ui.registerPanel)也进停靠栏。
// 固定面板已覆盖的插件不重复加(gallery/prompts 等有专属面板);插件停用时整个面板消失。
const dyn = Array.isArray(pluginPanels) ? pluginPanels : []
for (const e of dyn) {
if (!e || !e.id || !e.pluginId) continue
if (fixedPlugins[e.pluginId]) continue
if (ready) {
const hit = list.find((x) => x && x.id === e.pluginId)
if (!hit || !hit.enabled) continue
}
out['plugin:' + e.pluginId + ':' + e.id] = {
title: e.title || e.id,
icon: e.icon || 'puzzle',
pluginId: e.pluginId,
panelId: e.id,
}
}
return out
}
+11
View File
@@ -38,6 +38,17 @@
changed = true
}
})
// v3.26.108:动态插件面板(plugin:*)不在 defaults 里 ⇒ 默认追加到右栏;用户移除过的(removed)不补。
var placed = (next.left.list || []).concat(next.right.list || [])
var rightRemoved = Array.isArray(next.right.removed) ? next.right.removed : []
var dyn = Object.keys(panels).filter(function (id) {
return id.indexOf('plugin:') === 0 && placed.indexOf(id) < 0 && rightRemoved.indexOf(id) < 0
})
if (dyn.length) {
next.right = Object.assign({}, next.right, { list: (next.right.list || []).concat(dyn) })
if (!next.right.active) next.right.active = next.right.list[0] || ''
changed = true
}
var dup = (next.left.list || []).filter(function (id) { return (next.right.list || []).indexOf(id) >= 0 })
if (dup.length) {
next.right = Object.assign({}, next.right, { list: next.right.list.filter(function (id) { return dup.indexOf(id) < 0 }) })
+1 -1
View File
@@ -362,7 +362,7 @@
if (!p) return el('div', { className: 'iwb-dock-empty' }, '面板加载中…')
if (p.node) return p.node
if (p.pluginId) {
const mount = (props.pluginMount && props.pluginMount(p.pluginId)) || null
const mount = (props.pluginMount && props.pluginMount(p.pluginId, p.panelId)) || null
if (!mount) return el('div', { className: 'iwb-dock-empty' }, p.hint || ((p.title || '插件') + ' 未加载'))
return el(PluginBox, { mount, fallback: p.fallback || null })
}