feat(ui): 自由窗口——tab 拖出侧边栏成为可移动/缩放/置顶的浮动窗口 (v0.16.0)

- 拖出:标签栏 tab 拖到主会话列(HTML5 DnD 检测 + 虚线提示浮层)或右键菜单
  「移动到自由窗口」(右/底面板共用 TabBar),tab 从 pane 移动进 SidebarState.floats
- 窗口(FreeWindow,渲染于 [data-dsh-panel-host] z-42):头部 pointer 拖动
  (rAF 直写 + 松手提交)、拖到 pane 高亮停靠(center 合并)、SE 角缩放、
  点击置顶、头部右键(回到侧边栏/关闭)、X = closeTab 走正常生命周期
- 服务语义:openTab dedupe/id 聚焦浮动 tab = 置顶窗口(不展开面板);
  closeTab/activateTab 兼顾 floats;agent 终端 reconcile 覆盖浮窗;
  features 单调新增 'floatWindows',版本 0.16.0
- 持久化:floats 随会话 localStorage,sanitizeState 宽容校验 + 几何钳制,
  uid 播种覆盖 float 前缀;i18n 三键 19 语言同步
- 关键修复(e2e 发现):portal 覆盖层(头部 Menu)的合成事件沿 React 树
  冒泡回拖拽表面,劫持菜单行点击——拖拽起点加 DOM 同源守卫(jsdom 不复现)
- e2e-mount.sh:缺省 tarball 改取 mtime 最新(旧字典序选择会把冒烟挂到
  过期产物);新增 tests/e2e/float-window.e2e.ts 双用例
This commit is contained in:
Menghuan1918 committed 2026-08-23 23:44:18 +08:00
1 parent d6d8db0416
commit f17a1b30ac
39 files changed
+2100 -96

No files matched your search

+68 -2
View File
@@ -2,7 +2,7 @@
* Tests for the BetterSidebar service registry: register/dispose lifecycle,
* matchFileViewer priority/exts/detect algorithm, and openTab dedupe.
*/
import { describe, it, expect } from 'vitest'
import { describe, it, expect, vi } from 'vitest'
// Mock browser globals (SidebarStore.reduce → schedulePersist uses window.setTimeout)
const g = globalThis as Record<string, unknown>
@@ -21,7 +21,7 @@ if (g.localStorage === undefined) {
}
import { createBetterSidebarService, matchUrlTarget, SIDEBAR_FEATURES, SIDEBAR_SERVICE_VERSION } from '../src/client/service.ts'
import { createSidebarStore, allLeaves, makeDefaultState, openDiffTab, openTabInActivePane, sanitizeState } from '../src/client/state.ts'
import { createSidebarStore, allLeaves, floatTab, makeDefaultState, openDiffTab, openTabInActivePane, sanitizeState } from '../src/client/state.ts'
describe('BetterSidebar service', () => {
it('registerTab adds to the registry and dispose removes it', () => {
@@ -1055,4 +1055,70 @@ describe('independent CR follow-up fixes', () => {
service.registerFileViewer({ id: 'csv', exts: ['csv'], fetchStrategy: 'custom', component: () => null })
expect(() => service.registerFileViewer({ id: 'csv', exts: ['csv'], fetchStrategy: 'custom', component: () => null })).toThrow(/already registered/)
})
describe('free windows (v0.16.0)', () => {
it('openTab dedupe focuses a FLOATING tab by raising its window (no duplicate, no panel expansion)', () => {
const store = createSidebarStore()
const service = createBetterSidebarService(store)
service.registerTab({ id: 'singleton', title: 'S', dedupeKey: () => 'singleton', component: () => null })
store.setSession('s1')
service.openTab({ type: 'singleton', title: 'S' })
// Float the singleton out, then float a second tab above it and
// collapse the panel — the focus must raise the window in place
// without reopening a tab or expanding anything.
store.reduce(s => floatTab(s, 'singleton', 100, 100))
service.openTab({ type: 'singleton', title: 'S' })
store.reduce(s => floatTab(s, (s.splits as { tabs: Array<{ id: string }> }).tabs[0]!.id, 100, 100))
const before = store.getSnapshot().state!
expect(before.floats).toHaveLength(2)
store.reduce(s => ({ ...s, panelOpen: false }))
service.openTab({ type: 'singleton', title: 'S' })
const after = store.getSnapshot().state!
// Raised to the top, not duplicated.
expect(after.floats).toHaveLength(2)
expect(after.floats.at(-1)!.tab.type).toBe('singleton')
// The panel stays collapsed (a floating tab is already in sight).
expect(after.panelOpen).toBe(false)
expect(allLeaves(after.splits).some(l => l.tabs.some(t => t.type === 'singleton'))).toBe(false)
})
it('closeTab on a floating tab closes it WITH the window and fires onClose', () => {
const store = createSidebarStore()
const service = createBetterSidebarService(store)
const onClose = vi.fn()
service.registerTab({ id: 'notes', title: 'Notes', single: true, onClose, component: () => null })
store.setSession('s1')
service.openTab({ type: 'notes', title: 'Notes' })
store.reduce(s => floatTab(s, 'notes', 50, 50))
expect(store.getSnapshot().state!.floats).toHaveLength(1)
service.closeTab('notes', { sessionId: 's1' })
const after = store.getSnapshot().state!
expect(after.floats).toHaveLength(0)
expect(onClose).toHaveBeenCalledTimes(1)
// Unknown ids stay a strict no-op.
service.closeTab('notes')
expect(store.getSnapshot().state).toBe(after)
})
it('activateTab on a floating tab raises the window and fires onActivate', () => {
const store = createSidebarStore()
const service = createBetterSidebarService(store)
const onActivate = vi.fn()
service.registerTab({ id: 'notes', title: 'Notes', single: true, onActivate, component: () => null })
store.setSession('s1')
service.openTab({ type: 'notes', title: 'Notes' })
service.openTab({ type: 'notes', title: 'Notes' })
store.reduce(s => floatTab(s, 'notes', 50, 50))
store.reduce(s => floatTab(s, (s.splits as { tabs: Array<{ id: string }> }).tabs[0]!.id, 60, 60))
const before = store.getSnapshot().state!
expect(before.floats).toHaveLength(2)
expect(before.floats.at(-1)!.tab.type).not.toBe('notes')
service.activateTab('notes')
const after = store.getSnapshot().state!
expect(after.floats.at(-1)!.tab.type).toBe('notes')
// Two activations total: the second openTab's dedupe focus (before the
// float) plus THIS explicit activateTab — both legitimate focuses.
expect(onActivate).toHaveBeenCalledTimes(2)
})
})
})