fix(sidebar): keep the bottom workbench toggle while the right panel is open

The header toggle bailed out whenever the host's right sidebar was expanded,
so opening that panel first left the bottom workbench unreachable until it was
collapsed again. The session header's utilities seat and the panel's own
Split / Fullscreen / Collapse cluster sit in two different columns, so they
never overlap.

The blank-session fixed fallback keeps its guard: that entry anchors to the
left of the panel controls and would cover panel content while expanded.

tests/bottom-toggle.spec.tsx pins both behaviours.
This commit is contained in:
WinterXMQ committed 2026-10-25 01:31:21 +08:00
1 parent 740d73a09a
commit 788c5149c0
3 files changed
+75 -6

No files matched your search

+3 -4
View File
@@ -48,7 +48,6 @@ import { createOpenInApp } from './open-in-app.ts'
import { useCenterColumn } from './sidebar/use-center-column.ts'
import { useHostFeeds } from './sidebar/use-host-feeds.ts'
import { mountedSessions } from './native/surface.ts'
import { useRightPanelOpen } from './sidebar/right-panel-open.ts'
import type { TabDragPayload } from './TabBar.tsx'
import { t } from './locales.ts'
import { useSessionRoot } from './use-session-root.ts'
@@ -784,9 +783,9 @@ export function BottomDockToggle(props: { store: SidebarStore }) {
useCallback((callback: () => void) => store.subscribe(callback), [store]),
useCallback(() => store.getSnapshot(), [store]),
)
// 宿主右侧面板展开时不出现:那个状态下它右上角是一簇自己的控件
// (Split / Fullscreen / Collapse right sidebar),入口挤进去只会跟它们打架。
if (useRightPanelOpen()) return null
// 宿主右侧面板展开时**照常渲染**:本入口在会话头 utilities,位于右栏控件簇
// (Split / Fullscreen / Collapse right sidebar)左侧的独立一列,不会被它们盖住。
// 早先这里在右栏展开时早退,结果「先开右栏就再也打不开工作台」。
const open = snapshot.state?.bottomOpen === true
const label = open ? t('collapseBottomPanel') : t('expandBottomPanel')
return (
+3 -2
View File
@@ -197,8 +197,9 @@ export function DockFallback({ store }: { store: SidebarStore }): ReactNode {
if (phase === undefined || !phase.blank) return null
// 兜底:相位说 blank、但会话头的入口确实在 DOM 里 —— 让位,绝不叠出第二套。
if (headerEntry) return null
// 宿主右侧面板展开时不渲染(里面那个按钮本身也会返回 null,这里连空壳一起省掉):
// 那个状态下右上角是宿主自己的一簇控件,没有本入口的容身之处。
// 宿主右侧面板展开时不渲染:兜底入口是 fixed 定位、锚在那簇控件左侧,展开时锚点
// 落在面板内部,放过去会盖住面板内容。正常会话的顶部入口不受此限(见 Sidebar.tsx
// 的 BottomDockToggle:它在会话头 utilities 里,与旧栏控件分属两列)。
if (rightOpen) return null
// portal 到 body:面板宿主(z 20-30)的层叠上下文压不过会话头,按钮会被 titleRow
// 拦截点击。40 高于 AppFrame(20) 与会话头、低于 DSH 浮层(100+)。
+69
View File
@@ -0,0 +1,69 @@
/**
* 会话头里的底部工作台开关(`Sidebar.tsx` 的 `BottomDockToggle`)。
*
* 钉住一条行为:**宿主右侧面板展开时入口照常渲染**。早先这里在 `useRightPanelOpen()`
* 为真时早退,结果「先开右栏就再也打不开工作台」——右栏那簇控件
* (Split / Fullscreen / Collapse right sidebar)在右栏列内,本入口在会话头 utilities
* (中间列),两列不重叠,没有隐藏的理由。
*
* 空白会话的 fixed 兜底入口是另一件事(见 `dock-fallback.spec.tsx`),它在右栏展开时
* 仍然不渲染:那个入口锚在右栏控件左侧,展开时锚点落在面板内部。
*/
// @vitest-environment jsdom
import { afterEach, describe, expect, it } from 'vitest'
import { createElement } from 'react'
import { act } from 'react-dom/test-utils'
// First import: browser globals before the primitive-carrying sidebar graph loads.
import './browser-globals.ts'
import { renderRoot, setupReactAct } from './test-utils.ts'
import { BottomDockToggle } from '../src/client/Sidebar.tsx'
import { createSidebarStore } from '../src/client/state.ts'
setupReactAct()
function renderToggle(): { unmount: () => void; store: ReturnType<typeof createSidebarStore> } {
const store = createSidebarStore()
store.setSession('s1')
const view = renderRoot(createElement(BottomDockToggle, { store }))
return { unmount: view.unmount, store }
}
/** 宿主右侧面板**展开**态的控件:可见的 `[data-sidebar-right-toggle]`。 */
function appendExpandedRightPanelControl(): void {
const element = document.createElement('button')
element.setAttribute('data-sidebar-right-toggle', 'true')
element.getBoundingClientRect = () => ({
x: 900, y: 10, left: 900, top: 10, width: 28, height: 28, right: 928, bottom: 38,
toJSON: () => ({}),
}) as DOMRect
document.body.append(element)
}
afterEach(() => {
for (const element of document.querySelectorAll('[data-sidebar-right-toggle]')) element.remove()
})
describe('会话头底部开关', () => {
it('宿主右侧面板展开时仍然渲染入口', () => {
appendExpandedRightPanelControl()
const { unmount } = renderToggle()
try {
expect(document.querySelector('[data-dsh-bottom-toggle]'), '右栏展开也要有底部入口').not.toBeNull()
} finally {
unmount()
}
})
it('点击翻转 store 的 bottomOpen', () => {
const { unmount, store } = renderToggle()
try {
const element = document.querySelector('[data-dsh-bottom-toggle]')
if (element === null) throw new Error('missing element: bottom toggle')
expect(store.getSnapshot().state?.bottomOpen).toBe(false)
act(() => { element.dispatchEvent(new MouseEvent('click', { bubbles: true })) })
expect(store.getSnapshot().state?.bottomOpen).toBe(true)
} finally {
unmount()
}
})
})