背景:资源中心浮窗下线后,停靠栏面板清单固定为 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)
69 lines
5.0 KiB
JavaScript
69 lines
5.0 KiB
JavaScript
// 停靠栏状态整理(v3.26.21):同侧去重 / 跨侧只保留左侧 / 默认回填规则
|
|
const assert = require('assert')
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
|
|
const src = fs.readFileSync(path.join(__dirname, '..', 'src', 'ui-dock-sanitize.js'), 'utf8')
|
|
const sandbox = {}
|
|
new Function('window', src)(sandbox)
|
|
const { sanitize } = sandbox.IWBUiDockSanitize
|
|
|
|
const panels = { prompts: {}, gallery: {}, groups: {}, styles: {} }
|
|
const noDefaults = { left: { list: [] }, right: { list: [] } }
|
|
const defaults = { left: { list: ['styles', 'groups'] }, right: { list: ['gallery', 'prompts'] } }
|
|
const mk = (l, r) => ({ left: { list: l, active: l[0] || '', open: true, w: 300, removed: [] }, right: { list: r, active: r[0] || '', open: true, w: 300, removed: [] } })
|
|
|
|
// 1) 同侧重复 → 去重(关掉默认回填,单独验证去重)
|
|
let d = sanitize(mk(['prompts', 'prompts', 'groups'], ['gallery']), panels, noDefaults)
|
|
assert.deepStrictEqual(d.left.list, ['prompts', 'groups'], '同侧应去重,实际 ' + JSON.stringify(d.left.list))
|
|
|
|
// 2) 同一 id 同时出现在两侧 → 只保留左侧
|
|
d = sanitize(mk(['prompts'], ['gallery', 'prompts']), panels, noDefaults)
|
|
assert.deepStrictEqual(d.right.list, ['gallery'], '右侧重复 id 应移除,实际 ' + JSON.stringify(d.right.list))
|
|
assert.strictEqual(d.left.list.indexOf('prompts') >= 0, true, '左侧应保留')
|
|
|
|
// 3) 未注册的面板 → 保留 id(插件可能还没加载完),active 回退到可用面板
|
|
d = sanitize(mk(['ghost', 'groups'], ['gallery']), panels, noDefaults)
|
|
assert.deepStrictEqual(d.left.list, ['ghost', 'groups'], '未注册 id 应保留(等插件加载),实际 ' + JSON.stringify(d.left.list))
|
|
assert.strictEqual(d.left.active, 'ghost', 'active 若仍在 list 中应保持(等插件加载)')
|
|
|
|
// 4) 默认回填:另一侧已有的不补;removed 里的不补
|
|
d = sanitize({ left: { list: ['prompts'], active: 'prompts', removed: ['styles'] }, right: { list: ['gallery'], active: 'gallery', removed: [] } }, panels, defaults)
|
|
assert.ok(d.left.list.indexOf('styles') < 0, 'removed 的 styles 不该被回填,实际 ' + JSON.stringify(d.left.list))
|
|
assert.deepStrictEqual(d.left.list, ['prompts', 'groups'], '其余默认面板应回填,实际 ' + JSON.stringify(d.left.list))
|
|
assert.ok(d.right.list.indexOf('prompts') < 0, '左侧已有的 prompts 不该回填到右侧,实际 ' + JSON.stringify(d.right.list))
|
|
|
|
// 5) 已干净的状态 → 原样返回(引用相等,避免无谓重渲染)
|
|
const clean = mk(['prompts'], ['gallery'])
|
|
assert.strictEqual(sanitize(clean, panels, noDefaults), clean, '干净状态应返回原对象')
|
|
|
|
|
|
// 6) 2026-11-27:动态插件面板(plugin:*)默认追加到右栏;removed 的不补;已摆过的不重复
|
|
const dynPanels = Object.assign({}, panels, { 'plugin:demo:p1': { title: '演示面板' }, 'plugin:demo:p2': {} })
|
|
d = sanitize(mk(['prompts'], ['gallery']), dynPanels, noDefaults)
|
|
assert.ok(d.right.list.indexOf('plugin:demo:p1') >= 0 && d.right.list.indexOf('plugin:demo:p2') >= 0,
|
|
'动态面板应追加到右栏,实际 ' + JSON.stringify(d.right.list))
|
|
assert.ok(d.left.list.indexOf('plugin:demo:p1') < 0, '动态面板不该进左栏')
|
|
|
|
d = sanitize({ left: { list: ['prompts'], active: 'prompts', removed: [] }, right: { list: ['gallery'], active: 'gallery', removed: ['plugin:demo:p1'] } }, dynPanels, noDefaults)
|
|
assert.ok(d.right.list.indexOf('plugin:demo:p1') < 0, 'removed 里的动态面板不该回填,实际 ' + JSON.stringify(d.right.list))
|
|
assert.ok(d.right.list.indexOf('plugin:demo:p2') >= 0, '其余动态面板仍应回填')
|
|
|
|
d = sanitize(mk(['plugin:demo:p1'], ['gallery']), dynPanels, noDefaults)
|
|
assert.strictEqual(d.right.list.filter(function (id) { return id === 'plugin:demo:p1' }).length, 0, '已在左栏的动态面板不该再进右栏')
|
|
|
|
// 7) 面板清单:动态面板进清单;固定面板已覆盖的插件不重复加;停用的插件不出现
|
|
const panelsSrc = fs.readFileSync(path.join(__dirname, '..', 'src', 'ui-dock-panels.js'), 'utf8')
|
|
const box2 = {}
|
|
new Function('window', panelsSrc)(box2)
|
|
const { build } = box2.IWBUIDockPanels
|
|
const hostOn = { list: function () { return [{ id: 'demo', enabled: true }, { id: 'gallery', enabled: true }] } }
|
|
const built = build(hostOn, [{ id: 'p1', title: '演示面板', icon: 'star', pluginId: 'demo', mount: function () {} }, { id: 'g2', title: '重复', pluginId: 'gallery', mount: function () {} }])
|
|
assert.ok(built['plugin:demo:p1'], '动态面板应出现在清单里')
|
|
assert.strictEqual(built['plugin:gallery:g2'], undefined, '固定面板已覆盖的插件不重复加')
|
|
assert.strictEqual(built.gallery.title, '图库', '固定面板应保留')
|
|
const builtOff = build({ list: function () { return [{ id: 'demo', enabled: false }] } }, [{ id: 'p1', title: '演示面板', pluginId: 'demo', mount: function () {} }])
|
|
assert.strictEqual(builtOff['plugin:demo:p1'], undefined, '停用的插件面板不该出现')
|
|
|
|
console.log('ui-dock-sanitize checks passed(同侧去重 / 跨侧保留左侧 / 未注册剔除 / 默认回填 / 动态插件面板回填 / 面板清单)')
|