背景:动态插件面板此前一律回填到右栏,左侧留白只能靠用户手动拖过去。 实现: 1. app.js:registerPanel 接受 panel.side('left' 缺省 right),side 内联进面板条目 (app.js 行数棘轮不变,仍 8325)。 2. src/ui-dock-panels.js:build() 把 side 透传到面板清单(缺省 right)。 3. src/ui-dock-sanitize.js:回填按 side 分栏;「用户移除过」改判任一侧 removed (避免插件换侧后已移除的面板又冒出来)。 验证: - tests/ui-dock-sanitize-test.js 新增 side 回填 + 左栏 removed + 清单透传断言 - tests/_plugin-host-probe.spec.js:注册带 side:'left' 的面板 → 按钮出现在左栏、点击挂载出 LEFT-MOUNTED、右栏无该按钮、停用后左右两边都消失 - npm run verify:ci 全绿(含 e2e 冒烟 31 条 / 45s)
58 lines
2.6 KiB
JavaScript
58 lines
2.6 KiB
JavaScript
/* ui-dock-panels.js —— 停靠栏面板清单(v3.25.82)
|
|
*
|
|
* 职责:给出「当前可用」的左右栏面板表。
|
|
* 规则(用户裁定):插件被关闭/未安装时,该面板不出现在左右栏;
|
|
* 若某侧一个可用面板都没有,ui-dock 会整侧不渲染。
|
|
* 兜底:插件宿主尚未就绪(list 为空,jsdom/首次启动)时不过滤,避免把面板全藏掉。
|
|
*/
|
|
;(function (global) {
|
|
'use strict'
|
|
|
|
const ALL = {
|
|
groups: { title: '节点组', icon: 'group', pluginId: 'grouplib', hint: '节点组插件未安装 · 设置 → 插件 → 市场安装' },
|
|
browser: { title: '浏览器', icon: 'globe', pluginId: 'browser' },
|
|
styles: { title: '风格库', icon: 'palette', pluginId: 'style-source' },
|
|
prompts: { title: '提示词库', icon: 'book', pluginId: 'promptlib', hint: '提示词库插件未安装 · 设置 → 插件 → 市场安装' },
|
|
gallery: { title: '图库', icon: 'ref', pluginId: 'gallery', hint: '图库插件未安装 · 设置 → 插件 → 市场安装' },
|
|
}
|
|
|
|
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,
|
|
// 2026-11-27:注册时的 side 偏好(默认 right);ui-dock-sanitize 据此决定回填到哪一侧
|
|
side: e.side === 'left' ? 'left' : 'right',
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
global.IWBUIDockPanels = { build, ALL }
|
|
})(typeof window !== 'undefined' ? window : globalThis)
|