feat(dock): registerPanel 支持 side 偏好(插件面板可默认落左栏)
背景:动态插件面板此前一律回填到右栏,左侧留白只能靠用户手动拖过去。 实现: 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)
This commit is contained in:
1 parent
149a490f9c
commit
034c0f92a1
6 files changed
+63
-12
No files matched your search
@@ -46,6 +46,8 @@
|
||||
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
|
||||
|
||||
+19
-8
@@ -38,17 +38,28 @@
|
||||
changed = true
|
||||
}
|
||||
})
|
||||
// v3.26.108:动态插件面板(plugin:*)不在 defaults 里 ⇒ 默认追加到右栏;用户移除过的(removed)不补。
|
||||
// v3.26.108:动态插件面板(plugin:*)不在 defaults 里 ⇒ 按注册时的 side 偏好回填(默认右栏);
|
||||
// 用户移除过的(任一侧 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
|
||||
var removedAny = (Array.isArray(next.left.removed) ? next.left.removed : [])
|
||||
.concat(Array.isArray(next.right.removed) ? next.right.removed : [])
|
||||
var dynLeft = []
|
||||
var dynRight = []
|
||||
Object.keys(panels).forEach(function (id) {
|
||||
if (id.indexOf('plugin:') !== 0) return
|
||||
if (placed.indexOf(id) >= 0 || removedAny.indexOf(id) >= 0) return
|
||||
var prefer = (panels[id] && panels[id].side === 'left') ? 'left' : 'right'
|
||||
if (prefer === 'left') dynLeft.push(id); else dynRight.push(id)
|
||||
})
|
||||
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] || ''
|
||||
;[['left', dynLeft], ['right', dynRight]].forEach(function (pair) {
|
||||
var side = pair[0]
|
||||
var ids = pair[1]
|
||||
if (!ids.length) return
|
||||
var cur = next[side]
|
||||
next[side] = Object.assign({}, cur, { list: (cur.list || []).concat(ids) })
|
||||
if (!next[side].active) next[side].active = next[side].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 }) })
|
||||
|
||||
Reference in new issue
Block a user