feat: 二级页面、孤儿路由防护、iframe 全屏与 DS Bot 侧栏隐藏 (v0.5.3-local.5)
借鉴同线分支 dsh-worktable 0.5.2-local.9 的四项改造,逐项评估后移植: - 二级页面:LayoutSpec.parentId + layoutTree 树形侧栏 + 折叠/展开。 仅一级嵌套;删父项目不级联删子页面(提升为顶级,避免误删用户内容)。 管理面板加「+新增二级页面」,继承父项目文件夹。 - 孤儿路由防护:register 遇 duplicate 路由只 warn 不抛,避免热重载时 旧 fiber 未释放导致新 fiber 激活失败、侧边栏抽屉整体消失。 - iframe allowFullScreen:项目窗格里的 HTML 看板可全屏。 - DS Bot 侧栏隐藏:由本插件注入 CSS,替代改 ds-bot/client.js 的做法 (ds-bot 随应用升级,改源码必丢)。nav.bt-home-nav 带标签选择器避免误伤。 未移植对方的状态防清空(stateStore.serverKeys):本仓 hostState.ts 已有 hydrated 守卫(读完宿主前禁写、读不到整场不写)与更细的 6 段退避重试, 覆盖面更强。 顺带修三个 Windows 兼容缺陷,否则 pack 门禁过不去: - release-prep.mjs:tar 加 --force-local(GNU tar 把 C: 当 rsh 主机) - preview-files.test.mjs:rmSync 删 junction 失败,加 unlinkSync 兜底 - widget-mount.test.mjs:提取段缺 normalizeProjects 依赖,起点前移 验证:npm run pack 全绿(139 项兼容回归 + 工厂门禁 10/10 + 结构 7 文件 + 独立安装 import + 锚点 14 场景 + Chromium 分栏 5 场景 + 服务端 3 场景)。 双资产同源 sha256 cf633ad7…。
This commit is contained in:
@@ -61,6 +61,8 @@ type ViewState = {
|
||||
orderBy: OrderBy
|
||||
dock: DockMode
|
||||
floatTop: number | null
|
||||
/** 折叠中的项目 id(这些项目不展开显示其二级页面;缺省 = 全部展开)*/
|
||||
foldedProjects?: string[]
|
||||
/** 控制室面板主题:dark/light/system(system = 跟随宿主 color-scheme,即 DSH 深色/白色/跟随系统设置) */
|
||||
consoleTheme?: 'dark' | 'light' | 'system'
|
||||
/** 控制室每行显示项目数(1-5,默认 3)*/
|
||||
@@ -328,6 +330,7 @@ function normalizeView(raw: any): ViewState {
|
||||
orderBy,
|
||||
dock: p.dock === 'float' ? 'float' : 'footer',
|
||||
floatTop: typeof p.floatTop === 'number' ? p.floatTop : null,
|
||||
foldedProjects: Array.isArray(p.foldedProjects) ? p.foldedProjects.filter((x: unknown): x is string => typeof x === 'string') : [],
|
||||
consoleTheme: p.consoleTheme === 'dark' || p.consoleTheme === 'light' || p.consoleTheme === 'system' ? p.consoleTheme : 'system',
|
||||
consoleCols: typeof p.consoleCols === 'number' && p.consoleCols >= 1 && p.consoleCols <= 5 ? Math.round(p.consoleCols) : 3,
|
||||
consoleShape: p.consoleShape === 'circle' ? 'circle' : 'square',
|
||||
@@ -2242,7 +2245,35 @@ function buildCustomLayoutPrompt(req: string): string {
|
||||
|
||||
const removeLayout = (id: string) => {
|
||||
invalidateWidgetProject(id)
|
||||
persistProjects((prev) => ({ ...prev, layouts: prev.layouts.filter((l) => l.id !== id) }))
|
||||
// 二级页面:删父项目不级联删子页面 —— 子页面提升为顶级,避免误删用户内容
|
||||
persistProjects((prev) => ({
|
||||
...prev,
|
||||
layouts: prev.layouts
|
||||
.filter((l) => l.id !== id)
|
||||
.map((l) => (l.parentId === id ? { ...l, parentId: undefined } : l)),
|
||||
}))
|
||||
}
|
||||
|
||||
// ── 二级页面:挂在某个项目下的独立布局页(仅一级)──
|
||||
const addSubPage = (parent: LayoutSpec) => {
|
||||
const parentName = projects.nameOverrides[parent.id] ?? parent.title
|
||||
const child = buildLayout('2h', parentName + ' · 新页面')
|
||||
child.parentId = parent.id
|
||||
const folder = projects.folders[parent.id]
|
||||
persistProjects((prev) => ({
|
||||
...prev,
|
||||
layouts: [...prev.layouts, child],
|
||||
folders: folder ? { ...prev.folders, [child.id]: folder } : prev.folders,
|
||||
}))
|
||||
invalidatePickState()
|
||||
openSplit(child)
|
||||
reportUsed(child.id)
|
||||
}
|
||||
|
||||
/** 折叠/展开某个项目的二级页面列表 */
|
||||
const toggleFold = (id: string) => {
|
||||
const folded = view.foldedProjects ?? []
|
||||
persistView({ foldedProjects: folded.includes(id) ? folded.filter((x) => x !== id) : [...folded, id] })
|
||||
}
|
||||
|
||||
// ── 变更视图:所有项目通用。布局项目 = 重建其布局条目;入驻项目 = 建立/更新视图覆盖。
|
||||
@@ -2476,6 +2507,30 @@ function buildCustomLayoutPrompt(req: string): string {
|
||||
const paneTitles = [...(l.top ?? []), ...l.main].map((p) => p.title).join(' ')
|
||||
return (l.title + ' ' + paneTitles).toLowerCase().includes(queryLower)
|
||||
})
|
||||
/** 侧栏树:父项目 + 其二级页面(仅一级嵌套;父项目不可见时子页面按顶级显示)*/
|
||||
const layoutTree = useMemo(() => {
|
||||
const visIds = new Set(visibleLayouts.map((l) => l.id))
|
||||
const kids = new Map<string, LayoutSpec[]>()
|
||||
const roots: LayoutSpec[] = []
|
||||
for (const l of visibleLayouts) {
|
||||
if (l.parentId && visIds.has(l.parentId)) {
|
||||
const arr = kids.get(l.parentId) ?? []
|
||||
arr.push(l)
|
||||
kids.set(l.parentId, arr)
|
||||
} else roots.push(l)
|
||||
}
|
||||
const ord = (a: LayoutSpec, b: LayoutSpec) => effectiveOrder.indexOf(a.id) - effectiveOrder.indexOf(b.id)
|
||||
const out: { node: LayoutSpec; depth: 0 | 1; hasKids: boolean }[] = []
|
||||
for (const r of [...roots].sort(ord)) {
|
||||
const cs = (kids.get(r.id) ?? []).sort(ord)
|
||||
out.push({ node: r, depth: 0, hasKids: cs.length > 0 })
|
||||
if (!(view.foldedProjects ?? []).includes(r.id)) {
|
||||
for (const c of cs) out.push({ node: c, depth: 1, hasKids: false })
|
||||
}
|
||||
}
|
||||
return out
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [visibleLayouts, effectiveOrder, view.foldedProjects])
|
||||
|
||||
const isFloat = float != null
|
||||
const floatStyle = isFloat
|
||||
@@ -2740,6 +2795,14 @@ function buildCustomLayoutPrompt(req: string): string {
|
||||
<EyeIcon closed={isHidden} />
|
||||
</button>
|
||||
<button type="button" className="dsh-wt_manageBtn" title={t('manage.changeView')} onClick={() => setViewPickFor(id)}>🧩</button>
|
||||
{layout && (
|
||||
<button
|
||||
type="button"
|
||||
className="dsh-wt_manageBtn"
|
||||
title={t('manage.addPage')}
|
||||
onClick={() => addSubPage(layout)}
|
||||
>+</button>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
className="dsh-wt_manageBtn"
|
||||
@@ -3197,13 +3260,15 @@ function buildCustomLayoutPrompt(req: string): string {
|
||||
{renderProjectSlot
|
||||
? renderProjectSlot('sidebar.worktable.project', ownerProps)
|
||||
: <div className="dsh-wt_empty">{t('empty')}</div>}
|
||||
{visibleLayouts.map((l) => (
|
||||
{layoutTree.map(({ node: l, depth, hasKids }, ti) => {
|
||||
const folded = (view.foldedProjects ?? []).includes(l.id)
|
||||
return (
|
||||
<button
|
||||
key={l.id}
|
||||
type="button"
|
||||
className="dsh-wt_layout"
|
||||
className={'dsh-wt_layout' + (depth === 1 ? ' dsh-wt_layoutSub' : '') + (hasKids ? ' dsh-wt_layoutHasKids' : '')}
|
||||
data-on={activeSplitId === l.id ? 'true' : 'false'}
|
||||
style={{ order: effectiveOrder.indexOf(l.id) + 1000, position: 'relative' }}
|
||||
style={{ order: ti + 1000, position: 'relative' }}
|
||||
onClick={() => { openSplit(l); reportUsed(l.id) }}
|
||||
>
|
||||
<span
|
||||
@@ -3227,9 +3292,19 @@ function buildCustomLayoutPrompt(req: string): string {
|
||||
aria-label={projects.bindings[l.id] ? t('bind.tipBound', { name: boundSessionTitle(projects.bindings[l.id]) }) : t('bind.tipUnbound')}
|
||||
onClick={(e) => { e.stopPropagation(); openBindPick(l.id, e.currentTarget as HTMLElement) }}
|
||||
><span className="dsh-wt_bindCircles" aria-hidden /></span>
|
||||
{hasKids ? (
|
||||
<span
|
||||
className={'dsh-wt_foldBtn' + (folded ? ' dsh-wt_foldBtnOff' : '')}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
title={folded ? t('tree.expand') : t('tree.fold')}
|
||||
onClick={(e) => { e.stopPropagation(); toggleFold(l.id) }}
|
||||
>{folded ? '▸' : '▾'}</span>
|
||||
) : <span className="dsh-wt_foldBtn dsh-wt_foldBtnGhost" aria-hidden />}
|
||||
<span className="dsh-wt_layoutArrow" aria-hidden>›</span>
|
||||
</button>
|
||||
))}
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{visibleShortcuts.length > 0 && (
|
||||
|
||||
@@ -60,6 +60,9 @@ export const zh = {
|
||||
'manage.deleteLayout': '删除布局',
|
||||
'manage.deleteProject': '删除项目',
|
||||
'manage.changeView': '变更视图',
|
||||
'manage.addPage': '新增二级页面',
|
||||
'tree.fold': '折叠二级页面',
|
||||
'tree.expand': '展开二级页面',
|
||||
'viewPick.title': '选择新视图(内容窗自动迁入)',
|
||||
'confirm.title': '删除项目',
|
||||
'confirm.cancel': '取消',
|
||||
@@ -299,6 +302,9 @@ export const en = {
|
||||
'manage.deleteLayout': 'Delete layout',
|
||||
'manage.deleteProject': 'Delete project',
|
||||
'manage.changeView': 'Change layout',
|
||||
'manage.addPage': 'Add sub page',
|
||||
'tree.fold': 'Collapse sub pages',
|
||||
'tree.expand': 'Expand sub pages',
|
||||
'viewPick.title': 'Pick a new layout (panes migrate automatically)',
|
||||
'confirm.title': 'Delete project',
|
||||
'confirm.cancel': 'Cancel',
|
||||
|
||||
@@ -70,6 +70,8 @@ export type LayoutSpec = {
|
||||
chatFullHeight?: boolean
|
||||
/** 顶行首次打开时高度占可用高度比例(0~1;0.5 = 上下等分);拖动后由存档值覆盖 */
|
||||
topHeightRatio?: number
|
||||
/** 二级页面:挂在某项目下的独立布局页(仅一级嵌套;缺省 = 顶级项目) */
|
||||
parentId?: string
|
||||
}
|
||||
|
||||
type Geom = { left: number; top: number; right: number; bottom: number }
|
||||
@@ -2479,7 +2481,7 @@ function FileViewer(props: { path: string }) {
|
||||
const ext = (props.path.split('.').pop() || '').toLowerCase()
|
||||
const fileUrl = '/api/worktable/file?path=' + encodeURIComponent(props.path)
|
||||
if (ext === 'pdf') {
|
||||
return <iframe className="dsh-wt_paneFrame" src={fileUrl} title={basenameOf(props.path)} />
|
||||
return <iframe className="dsh-wt_paneFrame" src={fileUrl} title={basenameOf(props.path)} allowFullScreen />
|
||||
}
|
||||
if (IMAGE_EXTS.test('.' + ext)) {
|
||||
return (
|
||||
|
||||
@@ -662,4 +662,22 @@ export const css = xtermCss + '\n' + [
|
||||
'.dsh-wt_updateSwitch::after{content:"";position:absolute;top:2px;right:2px;width:10px;height:10px;border-radius:50%;background:#fff;transition:right .15s}',
|
||||
'.dsh-wt_updateSwitch[data-off=true]{background:var(--dsw-alias-border-l1,#333a48)}',
|
||||
'.dsh-wt_updateSwitch[data-off=true]::after{right:14px}',
|
||||
// 二级页面:缩进 + 左侧引导折线
|
||||
'.dsh-wt_layoutSub{margin-left:20px;border-style:dashed;position:relative;height:30px!important}',
|
||||
'.dsh-wt_layoutSub .dsh-wt_layoutName{font-size:11.5px;color:var(--dsw-alias-label-secondary,#9aa4b2)}',
|
||||
'.dsh-wt_layoutSub::before{content:"";position:absolute;left:-12px;top:-11px;bottom:50%;width:9px;border-left:1.5px solid var(--dsw-alias-border-l2,#3a4150);border-bottom:1.5px solid var(--dsw-alias-border-l2,#3a4150);border-bottom-left-radius:6px;pointer-events:none}',
|
||||
// 折叠按钮:固定在最右(› 箭头右侧),无边框无底色;所有项目卡都占这个位置(无子页面的用 ghost 占位)
|
||||
'.dsh-wt_foldBtn{position:absolute;right:0px;top:50%;transform:translateY(-50%);z-index:3;display:inline-flex;align-items:center;justify-content:center;width:16px;height:18px;border-radius:4px;font-size:11px;line-height:1;cursor:pointer;color:var(--dsw-alias-label-secondary,#9aa4b2)}',
|
||||
'.dsh-wt_foldBtn:hover{color:var(--dsw-alias-label-primary,#e6e8eb)}',
|
||||
'.dsh-wt_foldBtnGhost{cursor:default;pointer-events:none}',
|
||||
'.dsh-wt_layoutHasKids .dsh-wt_layoutArrow{margin-right:0}',
|
||||
'.dsh-wt_manageRowSub{margin-left:20px}',
|
||||
// DS Bot 侧栏元素隐藏(迁移自「改 ds-bot/client.js 插 return null」的做法)。
|
||||
// 动机:ds-bot 是随应用升级的 .bundled-plugins tgz 安装,升级/重装必丢改;
|
||||
// 改为由本插件注入 CSS,只要工作台装着,ds-bot 随便升级都不丢。
|
||||
// 注意:nav.bt-home-nav 必须带 nav 标签选择器 —— BotHome 错误面板有同名 div,不能误伤。
|
||||
'[data-slot="sidebar.footer.action"] .bt-return{display:none!important}',
|
||||
'[data-testid="duet-transcript-toggle"]{display:none!important}',
|
||||
'nav.bt-home-nav{display:none!important}',
|
||||
'.bt-connect-wrap{display:none!important}',
|
||||
].join('\n')
|
||||
|
||||
+27
-12
@@ -295,19 +295,34 @@ export function apply(ctx: Context) {
|
||||
})()
|
||||
}
|
||||
// Direct WebServer routes do NOT inherit the host's /api authentication route.
|
||||
const register = (route: any, publicAsset = false) => ctx.effect(() => webServer.register({
|
||||
...route,
|
||||
handler: async (req: any, res: any) => {
|
||||
if (!publicAsset && route.path !== HEALTH_PATH) {
|
||||
const rejected = await requestRejection(ctx, req)
|
||||
if (rejected !== undefined) {
|
||||
if (route.path === '/api/worktable/state') stateLog('REJECT ' + req.method + ' -> ' + rejected)
|
||||
json(res, rejected, { error: rejectionText(rejected) }); return
|
||||
}
|
||||
// REQ: 容忍热重载期重复路由 —— 旧 fiber 尚未释放时再次注册会抛 duplicate,
|
||||
// 若直接抛出会让新 fiber 激活失败、客户端贡献(侧边栏抽屉)整体消失。
|
||||
// 此时跳过注册即可:路由仍由存活 fiber 服务,下次重启自然收敛回单 fiber。
|
||||
const register = (route: any, publicAsset = false) => {
|
||||
let dispose: (() => void) | undefined
|
||||
try {
|
||||
dispose = webServer.register({
|
||||
...route,
|
||||
handler: async (req: any, res: any) => {
|
||||
if (!publicAsset && route.path !== HEALTH_PATH) {
|
||||
const rejected = await requestRejection(ctx, req)
|
||||
if (rejected !== undefined) {
|
||||
if (route.path === '/api/worktable/state') stateLog('REJECT ' + req.method + ' -> ' + rejected)
|
||||
json(res, rejected, { error: rejectionText(rejected) }); return
|
||||
}
|
||||
}
|
||||
return route.handler(req, res)
|
||||
},
|
||||
})
|
||||
} catch (err) {
|
||||
if (String(err).includes('duplicate')) {
|
||||
ctx.logger?.warn('[dsh-worktable] 路由已被占用(热重载泄漏自保),跳过: ' + route?.path)
|
||||
return
|
||||
}
|
||||
return route.handler(req, res)
|
||||
},
|
||||
}), 'dsh-worktable: ' + route.path)
|
||||
throw err
|
||||
}
|
||||
try { ctx.effect(() => dispose, 'dsh-worktable: ' + route.path) } catch {}
|
||||
}
|
||||
|
||||
register({
|
||||
kind: 'exact', path: '/api/worktable/preview',
|
||||
|
||||
Reference in New Issue
Block a user