fix(v0.1.3): 右侧工作台自动展开与回退

openTab 后聚焦并展开右栏;读不到页签或宿主拒绝时回退浮动面板;整行点击兜底页在主区渲染工作台,保证点击有反馈。
This commit is contained in:
qyh15 2026-11-17 11:43:45 +08:00
parent d1d403c1c0
commit d6ba6d611f
5 changed files with 131 additions and 12 deletions

49
preview/check-v013.mjs Normal file
View File

@ -0,0 +1,49 @@
import { spawn } from 'node:child_process'
import { mkdtemp, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
const url = process.argv[2]
const EDGE = 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'
const dir = dirname(fileURLToPath(import.meta.url))
const profile = await mkdtemp(join(tmpdir(), 'ss-v013-'))
const out = { consoleErrors: [] }
const sleep = ms => new Promise(r => setTimeout(r, ms))
let browser, ws
try {
browser = spawn(EDGE, ['--headless=new','--disable-gpu','--no-first-run','--no-default-browser-check','--remote-debugging-port=0','--user-data-dir=' + profile, 'about:blank'], { stdio: ['ignore','ignore','pipe'] })
const endpoint = await new Promise((resolve, reject) => { let log=''; const t=setTimeout(()=>reject(Error('timeout')),20000); browser.stderr.on('data', b=>{ log+=b; const m=log.match(/DevTools listening on (.+)/); if(m){clearTimeout(t);resolve(m[1].trim())} }); browser.on('error',reject) })
ws = new WebSocket(endpoint); await new Promise((r,j)=>{ws.onopen=r;ws.onerror=j})
let n=0; const pend=new Map()
ws.onmessage = e => { const m=JSON.parse(e.data); if(m.id){const p=pend.get(m.id);pend.delete(m.id);m.error?p.reject(Error(JSON.stringify(m.error))):p.resolve(m.result)} else if(m.method==='Runtime.exceptionThrown'){ out.consoleErrors.push('exception: '+(m.params.exceptionDetails.exception?.description||m.params.exceptionDetails.text)) } else if(m.method==='Runtime.consoleAPICalled' && ['error','warning'].includes(m.params.type)){ const t=(m.params.args||[]).map(a=>a.value??a.description??'').join(' '); if(/sansheng|sidebar/i.test(t)) out.consoleErrors.push(m.params.type+': '+t.slice(0,300)) } }
const cdp=(method,params={},sid)=>new Promise((res,rej)=>{const id=++n;pend.set(id,{resolve:res,reject:rej});ws.send(JSON.stringify({id,method,params,...(sid?{sessionId:sid}:{})}))})
const { targetId } = await cdp('Target.createTarget', { url: 'about:blank' })
const { sessionId } = await cdp('Target.attachToTarget', { targetId, flatten: true })
const call=(m,p={})=>cdp(m,p,sessionId)
await call('Page.enable'); await call('Runtime.enable')
const ev = async x => { const r=await call('Runtime.evaluate',{expression:x,returnByValue:true,awaitPromise:true}); if(r.exceptionDetails) throw Error(r.exceptionDetails.exception?.description||r.exceptionDetails.text); return r.result.value }
const waitFor = async (x,t=45000)=>{ const end=Date.now()+t; while(Date.now()<end){ try{ if(await ev(x)) return true }catch{} await sleep(250) } return false }
const shot = async name => { const r=await call('Page.captureScreenshot',{format:'png',captureBeyondViewport:false}); await writeFile(join(dir,name),Buffer.from(r.data,'base64')) }
await call('Emulation.setDeviceMetricsOverride',{width:1440,height:900,deviceScaleFactor:1,mobile:false})
await call('Page.navigate',{url})
await waitFor("document.readyState === 'complete'",30000)
try { await ev("(() => { const b=[...document.querySelectorAll('button')].find(x=>(x.innerText||'').trim()==='继续'); if(b)b.click(); return !!b })()") } catch {}
await sleep(700)
await waitFor("!!document.querySelector('.ssw-nav-hit')",60000)
out.collapseButtons = await ev("(() => [...document.querySelectorAll('button')].map(b=>b.getAttribute('aria-label')||b.getAttribute('title')||'').filter(t=>/收起|展开|collapse|expand|侧栏|sidebar/i.test(t)).slice(0,12))()")
out.rootBefore = await ev("!!document.querySelector('.ssw-root')")
if (process.argv.includes('--collapsed')) {
out.collapseClicked = await ev("(() => { const b=[...document.querySelectorAll('button')].find(x=>(x.getAttribute('aria-label')||'')==='收起右侧边栏'); if(!b) return false; b.click(); return true })()")
await sleep(900)
out.rootBeforeCollapsed = await ev("!!document.querySelector('.ssw-root')")
}
await ev("document.querySelector('.ssw-nav-hit').click(); true")
const opened = await waitFor("!!document.querySelector('.ssw-root')",20000)
await sleep(2500)
out.opened = opened
out.tabCount = await ev("[...document.querySelectorAll('[data-sidebar-right-tab]')].filter(e=>(e.innerText||'').includes('三省六部')).length")
out.seatCount = await ev("document.querySelectorAll('.ssw-seat').length")
out.rootText = await ev("(document.querySelector('.ssw-root')?.innerText||'').replace(/\s+/g,' ').slice(0,160)")
await shot('v013-workbench.png')
} catch(e) { out.fatal = String(e?.stack ?? e) } finally { try{ws?.close()}catch{}; try{browser?.kill()}catch{} }
console.log(JSON.stringify(out, null, 2))

BIN
preview/v013-workbench.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

View File

@ -1004,7 +1004,24 @@ function apply(ctx) {
}
function ensureRightTab() {
const tabs = get("sidebarRightTabs");
return !!(tabs && isFn(tabs.get) && tabs.get(TAB_KIND));
if (!tabs || !isFn(tabs.get)) return false;
try {
return !!(tabs.get(TAB_KIND) || tabs.get(TAB_TYPE_ID));
} catch {
return false;
}
}
function revealRightTab() {
const right = get("sidebarRight");
if (!right) return;
try {
const rows = isFn(right.openTabs?.getSnapshot) ? right.openTabs.getSnapshot() : [];
const row = Array.isArray(rows) ? rows.find((item) => item && item.kind === TAB_KIND) : null;
if (row && isFn(right.focus)) right.focus(row.tabId);
if (isFn(right.isExpanded) && !right.isExpanded() && isFn(right.toggleExpanded)) right.toggleExpanded();
} catch (error) {
console.warn("[sansheng] 展开右侧栏失败:", error && error.message ? error.message : error);
}
}
function tryOpenRightTab() {
const right = get("sidebarRight");
@ -1012,11 +1029,17 @@ function apply(ctx) {
if (!ensureRightTab()) return false;
try {
right.openTab(TAB_KIND);
return true;
} catch (error) {
console.warn("[sansheng] 打开右侧标签失败,改用浮动面板:", error && error.message ? error.message : error);
return false;
}
revealRightTab();
try {
const rows = isFn(right.openTabs?.getSnapshot) ? right.openTabs.getSnapshot() : null;
if (Array.isArray(rows) && rows.length > 0 && !rows.some((item) => item && item.kind === TAB_KIND)) return false;
} catch {
}
return true;
}
function SanshengTabBody() {
return (0, import_react.createElement)("div", { className: "ssw-tab-body" }, (0, import_react.createElement)(SanshengWorkbench, {}));
@ -1441,8 +1464,12 @@ function apply(ctx) {
);
}
function SanshengNavFallback() {
const [mode, setMode] = (0, import_react.useState)("pending");
(0, import_react.useEffect)(() => {
openRightWorkbench();
setMode(openRightWorkbench() ? "docked" : "inline");
}, []);
(0, import_react.useEffect)(() => {
if (mode !== "docked") return;
const layout = get("layout");
if (layout && isFn(layout.selectPanel)) {
try {
@ -1450,8 +1477,19 @@ function apply(ctx) {
} catch {
}
}
}, []);
return null;
}, [mode]);
if (mode !== "inline") return null;
return (0, import_react.createElement)("div", { className: "ssw-tab-body" }, (0, import_react.createElement)(SanshengWorkbench, {
onClose: () => {
const layout = get("layout");
if (layout && isFn(layout.selectPanel)) {
try {
layout.selectPanel(null);
} catch {
}
}
}
}));
}
function registerNavEntry() {
if (!ctx.slots || !isFn(ctx.slots.inject) || !isFn(ctx.slots.register)) {

View File

@ -1,6 +1,6 @@
{
"name": "dsh-sansheng-liubu",
"version": "0.1.2",
"version": "0.1.3",
"description": "三省六部:每个项目固定十席角色与独立会话的 DSH 插件(第一版)。",
"keywords": [
"dsh-plugin",

View File

@ -195,16 +195,37 @@ export function apply(ctx) {
// ---------- 右侧标签页(真实契约:register 类型 + 正文/标题 slot;不可用时回退浮动面板) ----------
function ensureRightTab() {
const tabs = get('sidebarRightTabs')
return !!(tabs && isFn(tabs.get) && tabs.get(TAB_KIND))
if (!tabs || !isFn(tabs.get)) return false
try { return !!(tabs.get(TAB_KIND) || tabs.get(TAB_TYPE_ID)) } catch { return false }
}
// 桌面版右栏常是收起状态:只 openTab 不展开,用户会以为“点了没反应”。
function revealRightTab() {
const right = get('sidebarRight')
if (!right) return
try {
const rows = isFn(right.openTabs?.getSnapshot) ? right.openTabs.getSnapshot() : []
const row = Array.isArray(rows) ? rows.find(item => item && item.kind === TAB_KIND) : null
if (row && isFn(right.focus)) right.focus(row.tabId)
if (isFn(right.isExpanded) && !right.isExpanded() && isFn(right.toggleExpanded)) right.toggleExpanded()
} catch (error) {
console.warn('[sansheng] 展开右侧栏失败:', error && error.message ? error.message : error)
}
}
function tryOpenRightTab() {
const right = get('sidebarRight')
if (!right || !isFn(right.openTab)) return false
if (!ensureRightTab()) return false
try { right.openTab(TAB_KIND); return true } catch (error) {
try { right.openTab(TAB_KIND) } catch (error) {
console.warn('[sansheng] 打开右侧标签失败,改用浮动面板:', error && error.message ? error.message : error)
return false
}
revealRightTab()
// 确认页签确实出现;宿主拒绝(例如当前没有会话面板)时返回 false,让调用方回退,避免“点了没反应”。
try {
const rows = isFn(right.openTabs?.getSnapshot) ? right.openTabs.getSnapshot() : null
if (Array.isArray(rows) && rows.length > 0 && !rows.some(item => item && item.kind === TAB_KIND)) return false
} catch { /* 读不到就按已打开处理 */ }
return true
}
function SanshengTabBody() {
return h('div', { className: 'ssw-tab-body' }, h(SanshengWorkbench, {}))
@ -558,16 +579,27 @@ export function apply(ctx) {
)
}
// 兜底:若宿主仍按整行点击切换了主区,这里立刻打开右侧工作台并切回会话,不遮挡中央聊天。
// 兜底:若宿主按整行点击切了主区,先把工作台打开到右侧并切回会话;
// 右侧打不开时就在主区直接渲染工作台(而不是空白),保证点击一定有反应。
function SanshengNavFallback() {
const [mode, setMode] = useState('pending')
useEffect(() => {
openRightWorkbench()
setMode(openRightWorkbench() ? 'docked' : 'inline')
}, [])
useEffect(() => {
if (mode !== 'docked') return
const layout = get('layout')
if (layout && isFn(layout.selectPanel)) {
try { layout.selectPanel(null) } catch { /* 忽略 */ }
}
}, [])
return null
}, [mode])
if (mode !== 'inline') return null
return h('div', { className: 'ssw-tab-body' }, h(SanshengWorkbench, {
onClose: () => {
const layout = get('layout')
if (layout && isFn(layout.selectPanel)) { try { layout.selectPanel(null) } catch { /* 忽略 */ } }
},
}))
}
function registerNavEntry() {