fix(client): align optional native-opening toolbar actions

This commit is contained in:
yixiangihsiang committed 2026-11-17 17:06:54 +08:00
1 parent d743753caf
commit 7ca20080d7
12 files changed
+173 -12

No files matched your search

+136
View File
@@ -0,0 +1,136 @@
/** File headers preserve toolbar axes with available, single-app, and unavailable native opening. */
import { mkdir, mkdtemp, writeFile } from 'node:fs/promises'
import { join } from 'node:path'
import { chromium, type Page } from 'playwright'
import { expect, it, onTestFinished, vi } from 'vitest'
import type {} from '@deepseek-ai/dsh-api-session-controller'
import { createLaunchEnvironmentSnapshot } from '@deepseek-ai/dsh-launch-environment'
import { launchWebScaffold } from './scaffold.ts'
import { connectFreshWorkspace } from './support.ts'
const SHOTS = process.env.DSH_UI_REVIEW_OUTPUT
const ICON = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><rect x="1" y="1" width="14" height="14" rx="3" fill="#3b82f6"/></svg>'
/** @param page - assembled file or preview page. @returns visible header axes and action-seat geometry. */
async function geometry(page: Page) {
return page.locator('[data-dockkit-pane-active][data-dockkit-pane]').evaluate((column) => {
const rect = (selector: string) => {
const element = column.querySelector(selector)
if (element === null) throw new Error(`missing toolbar element: ${selector}`)
return element.getBoundingClientRect()
}
const center = (box: DOMRect) => box.x + box.width / 2
const upper = rect('[data-sidebar-right-toggle] svg')
const opener = column.querySelector<HTMLElement>('[data-open-target][data-size="compact"]')
const path = column.querySelector('[data-files-path],[data-textpreview-path]')!
const header = path.parentElement!
const seat = header.querySelector<HTMLElement>('[data-slot="sidebar.right.tab.files.actions"],[data-slot="sidebar.right.tab.document.actions"]')!
const group = seat.parentElement!
const right = column.getBoundingClientRect()
const search = column.querySelector('[data-files-search-toggle] svg')
const searchTarget = column.querySelector('[data-files-search-toggle]')
const folder = column.querySelector('[data-files-navigator-toggle] svg')
const refresh = column.querySelector('[data-textpreview-tool="reload"] svg')
const folderTarget = column.querySelector('[data-files-navigator-toggle]')
const refreshTarget = column.querySelector('[data-textpreview-tool="reload"]')
return {
width: right.width,
upperRight: center(upper),
upperSplit: center(rect('[data-dockkit-split-button] svg')),
upperMode: center(rect('[data-sidebar-right-mode] svg')),
upperPaintRight: upper.right - (1.5 / 16 * upper.width - 0.5),
search: search === null ? null : center(search.getBoundingClientRect()),
folder: folder === null ? null : center(folder.getBoundingClientRect()),
refresh: refresh === null ? null : center(refresh.getBoundingClientRect()),
openerRight: opener?.getBoundingClientRect().right ?? null,
openerWidth: opener?.getBoundingClientRect().width ?? null,
groupDisplay: getComputedStyle(group).display,
groupWidth: group.getBoundingClientRect().width,
searchToOpenerGap: opener === null || searchTarget === null ? null
: opener.getBoundingClientRect().left - searchTarget.getBoundingClientRect().right,
gap: folderTarget === null || refreshTarget === null ? null
: folderTarget.getBoundingClientRect().left - refreshTarget.getBoundingClientRect().right,
buttonsInside: [...header.querySelectorAll('button')].filter(button => button.getBoundingClientRect().width > 0)
.every((button) => { const box = button.getBoundingClientRect(); return box.left >= right.left && box.right <= right.right }),
origin: { x: right.x, y: right.y },
}
})
}
it.each([
{ state: 'available', apps: ['finder', 'terminal'], desktop: true },
{ state: 'single', apps: ['finder'], desktop: true },
{ state: 'unavailable', apps: [], desktop: false },
])('aligns native-opening toolbar columns: $state', async ({ state, apps, desktop }) => {
const scaffold = await launchWebScaffold({ openInAppEnvironment: createLaunchEnvironmentSnapshot([
{ source: 'process', values: { SSH_CONNECTION: '10.0.0.2 55000 10.0.0.9 22' } },
]) })
onTestFinished(() => scaffold.close())
const capability = vi.spyOn(scaffold.ctx.sessionController, 'canOpenWorkspacePath').mockReturnValue(desktop)
onTestFinished(() => { capability.mockRestore() })
const associations = vi.spyOn(scaffold.ctx.sessionController, 'workspacePathApplications').mockResolvedValue([
{ id: 'test-editor', name: 'Test editor', default: true, icon: null },
])
onTestFinished(() => { associations.mockRestore() })
const browser = await chromium.launch()
onTestFinished(() => browser.close())
const page = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: 'en-US' })
await page.route('**/open-in-app/apps', route => route.fulfill({ json: { apps } }))
await page.route('**/open-in-app/icon/*', route => route.fulfill({ body: ICON, contentType: 'image/svg+xml' }))
await page.goto(scaffold.authenticatedUrl)
await connectFreshWorkspace(page, scaffold.workspaceCwd)
await writeFile(join(scaffold.workspaceCwd, 'workspace', 'PREVIEW.md'), '# Toolbar alignment\n\nIsolated local review data.\n')
await page.locator('[data-sidebar-right-expand]').click()
const column = page.locator('[data-rightbar-col]')
await column.locator('[data-sidebar-right-guide-entry="files"]').click()
await column.locator('[data-files-page]').waitFor()
await column.locator('[data-files-reload]').click()
await column.getByRole('button', { name: 'PREVIEW.md', exact: true }).waitFor()
let output: string | undefined
if (SHOTS !== undefined) {
await mkdir(SHOTS, { recursive: true })
output = await mkdtemp(join(SHOTS, `${state}-`))
}
const evidence = []
for (const kind of ['files', 'preview'] as const) {
if (kind === 'preview') {
await page.setViewportSize({ width: 1680, height: 1000 })
await column.getByRole('button', { name: 'PREVIEW.md', exact: true }).click()
await column.locator('[data-textpreview-path]').waitFor()
await column.getByRole('heading', { name: 'Toolbar alignment', exact: true }).waitFor()
}
for (const theme of ['light', 'dark']) for (const width of [1680, 640]) {
await page.setViewportSize({ width, height: width === 640 ? 840 : 1000 })
await page.evaluate(dark => document.body.toggleAttribute('data-ds-dark-theme', dark), theme === 'dark')
await page.mouse.move(10, 300)
await expect.poll(async () => {
const g = await geometry(page)
if (desktop) return g.openerRight === null ? 100 : kind === 'files'
? state === 'single' ? Math.abs(g.searchToOpenerGap! - 4) : Math.abs(g.search! - g.upperSplit) : Math.abs(g.folder! - g.upperRight)
return g.openerRight !== null ? 100 : kind === 'files'
? Math.abs(g.search! - g.upperRight) : Math.max(Math.abs(g.folder! - g.upperRight), Math.abs(g.refresh! - g.upperMode))
}).toBeLessThan(0.5)
const g = await geometry(page)
expect(g.buttonsInside).toBe(true)
if (desktop && kind === 'files') expect(Math.abs(g.openerRight! - g.upperPaintRight)).toBeLessThan(0.5)
if (state === 'single' && kind === 'files') {
expect(g.groupWidth).toBe(g.openerWidth)
expect(g.openerWidth).toBe(24)
expect(g.searchToOpenerGap).toBe(4)
}
if (!desktop) {
expect(g.groupDisplay).toBe('none')
if (kind === 'preview') expect(g.gap).toBe(4)
}
expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(width)
const name = `${state}-${kind}-${theme}-${width}`
const box = await page.locator('[data-dockkit-pane-active][data-dockkit-pane]').boundingBox()
if (box === null) throw new Error('right pane disappeared')
if (output !== undefined) {
await page.screenshot({ path: join(output, `${name}.png`), clip: { ...box, height: Math.min(190, box.height) }, animations: 'disabled' })
}
evidence.push({ name, state, kind, theme, viewport: width, ...g })
}
}
if (output !== undefined) await writeFile(join(output, `${state}.json`), JSON.stringify(evidence, null, 2))
})
+1
View File
@@ -195,6 +195,7 @@
"tests/message-actions.e2e.ts",
"tests/open-in-app-ssh.e2e.ts",
"tests/open-in-app-menus.e2e.ts",
"tests/open-in-app-toolbar.e2e.ts",
"tests/fork-mid-turn.e2e.ts",
"tests/message-feedback.e2e.ts",
"tests/markdown-images.e2e.ts",
@@ -27,8 +27,8 @@
en: 595499992ceea693
zh: 83c6147c46a80dca
/deepseek-ai-dsh-client-ui-sidebar-documentpreview/office-preview:
en: 66e11a42a139eabe
zh: 3558b06326055847
en: bebd8e7099be43eb
zh: 36de81ff9913d049
/deepseek-ai-dsh-client-ui-sidebar-documentpreview/navigation:
en: 33215200b3e4a8ed
zh: 499e4b834f2db95a
@@ -114,7 +114,7 @@ A yellow rounded-triangle warning appears before Reload in the document toolbar
<details>
<summary>Office implementation — click to expand</summary>
The compact external-open frame precedes the workspace navigator toggle in the preview header. It leaves a separate gap after the display controls while preserving the refresh icon’s shared column.
The compact external-open frame precedes the workspace navigator toggle in the preview header. It leaves a separate gap after the display controls. When the action slot has no rendered content, its group contributes no gap, and the remaining icons align with the upper toolbar columns.
Office registration, loading, caching, and font notices live in `src/client/office/`. The injected Office face writes converted PDF bytes, font metadata, and failures through the declared store actions. The Office body triggers loading, binds cancellation to its lifecycle, and declares a nested PDF slot that reuses the lazy PDF body and its tab viewing state. The keyed `sidebar.right.tab.document.action` slot places renderer controls before Reload. The Office action shares the body’s store and reads only the current revision’s font metadata. Registration remains available without the Host renderer; optional `remote.officeKit` and `remote.workspaceFiles` injections supply conversion and freshness callbacks, and their removal restores unavailable guidance. Registrations and tab retention follow effect lifetimes. The [conversion service](../../document/office-kit/README.md) owns the Host Remote methods, mounted by `api/remotes`.
@@ -114,7 +114,7 @@ CSV 和 TSV 默认使用表格查看器,也可选择纯文本;CSV 还提供
<details>
<summary>Office 实现——点击展开</summary>
紧凑的外部打开边框位于预览标题行的工作区导航开关之前。它与显示控件之间留出独立间距,同时保留刷新图标共用的纵向列。
紧凑的外部打开边框位于预览标题行的工作区导航开关之前。它与显示控件之间留出独立间距。当操作 slot 没有渲染内容时,该组不占间距,剩余图标与上排工具栏共用纵向列。
Office 注册、加载、缓存和字体提示位于 `src/client/office/`。注入的 Office face 通过已声明的 store action 写入转换后的 PDF 字节、字体元数据和失败。Office 正文触发加载,将取消绑定到自身生命周期,并声明嵌套 PDF slot,复用惰性 PDF 正文及其 tab 阅读状态。keyed slot `sidebar.right.tab.document.action` 将渲染器操作放在刷新按钮前。Office 操作与正文共享 store,仅读取当前 revision 的字体元数据。Host 渲染器缺失时,注册仍然可用;可选的 `remote.officeKit` 和 `remote.workspaceFiles` 注入提供转换与版本检查回调,移除后恢复不可用提示。注册和 tab 状态保留都遵循 effect 生命周期。[转换服务](../../document/office-kit/README.zh.md)拥有 Host Remote 方法,由 `api/remotes` 挂载。
@@ -58,7 +58,7 @@
margin-inline-end: 6px;
}
.externalActions:empty {
.externalActions:not(:has(:global([data-slot]) > *)) {
display: none;
}
@@ -15,8 +15,8 @@
en: 81cb6e051699a7b4
zh: 566d0278acae69fa
/deepseek-ai-dsh-client-ui-sidebar-files/what-it-registers:
en: 8464f9d3f8ca3864
zh: 540152abe2976b2c
en: 5816aa2ff177de01
zh: 63a219b23ad46ab3
/deepseek-ai-dsh-client-ui-sidebar-files/the-navigator:
en: 3424600b15bde2d2
zh: 2cf1c99ffef2ad50
+1 -1
View File
@@ -30,7 +30,7 @@ Browse a Session's workspace tree beside the files you preview. Each pane keeps
The `workspace.files` command shows the navigator beside a docked preview or expands the search bar on an existing docked files page, and moves keyboard focus to its search field, keeping the tab; from the conversation it uses the current Session's active dock pane. Elsewhere — a tab without the navigator, a Session without a working directory, a floating tab — it opens or focuses the files page, whose tree always shows. A guide gives way to the files page, and repeated opens retain one files page per pane. Desktop defaults to Mod+P. The guide entry displays the effective shortcut; Windows and macOS Web use the [shortcut service’s platform defaults](../shortcuts/README.md); Linux Web leaves this command unbound by default.
- **The type** — `ctx.sidebarRightTabs.register(...)` with kind `files`, id `@deepseek-ai/dsh-client-ui-sidebar-files`, band `builtin`, no patterns, and one guide entry (order 10, its title and description from the `sidebarFiles` namespace, its glyph a yellow folder) that opens the type.
- **The page body** — the keyed `sidebar.right.pane.tab` seat under that id. Its header row spans the page and shows the root through the shared [`PathLabel`](../ui-primitives/README.md#component-catalog) with subdued directories and a primary final segment; a clipped path retains its trailing characters with a left-edge fade, and hovering reveals the full path. The tree's reload control and search-bar toggle precede the Session-scoped `sidebar.right.tab.files.actions` list, which the page's registration declares, with the displayed root passed as `absolutePath`; [`ui-open-in-app`](../ui-open-in-app/README.md) contributes the workspace directory opener. The trailing opener frame aligns with the visible right edge of the upper collapse glyph, inside its hit target. The pane's navigator fills the page below the header, docked or floating, and has no navigator toggle there.
- **The page body** — the keyed `sidebar.right.pane.tab` seat under that id. Its header row spans the page and shows the root through the shared [`PathLabel`](../ui-primitives/README.md#component-catalog) with subdued directories and a primary final segment; a clipped path retains its trailing characters with a left-edge fade, and hovering reveals the full path. The tree's reload control and search-bar toggle precede the Session-scoped `sidebar.right.tab.files.actions` list, which the page's registration declares, with the displayed root passed as `absolutePath`; [`ui-open-in-app`](../ui-open-in-app/README.md) contributes the workspace directory opener. The trailing opener frame aligns with the visible right edge of the upper collapse glyph, inside its hit target. A split opener keeps Search centered under Split. A single-application control keeps its intrinsic width and the ordinary 4px gap, without reserving an alignment column. Without rendered directory actions, this column and its gap disappear, and Search aligns under Collapse. The pane's navigator fills the page below the header, docked or floating, and has no navigator toggle there.
- **The rows** — the root-scoped Component Factory `sidebar.files.tree`, with caller-owned entries and a local `accessory` slot; see [Reusable tree Factory](#tree-factory).
- **The navigator** — the Session-scoped Component Factory `sidebar.files.navigator`, rendered directly by the page body and [`ui-sidebar-documentpreview`](../ui-sidebar-documentpreview/README.md) beside every preview, docked or floating. It draws the [search bar](#search), the tree, and its resize edge without a header of its own: beside a preview the preview's header is the only one, and the tree's reload and directory actions stay on the `files` page.
- **The toggle** — the Session-scoped Factory `sidebar.files.navigator.toggle`, rendered directly at the end of the preview header with `useTabInfo`. The folder artwork uses 16px inside the shared 28px hit target to balance its landscape silhouette against the adjacent toolbar glyphs. Both Factories share the page's store handle and inject face, retaining one open choice per pane; the page body has no navigator toggle.
@@ -30,7 +30,7 @@ kind: "package-reference"
命令 `workspace.files` 在焦点分栏内显示停靠预览旁的导航栏,或展开已有停靠文件页的搜索栏,并把键盘焦点移到其搜索框,保留该 tab;从聊天区触发时使用当前会话的活动停靠分栏。其他情况下(不带导航栏的 tab、没有工作目录的会话、浮动 tab)打开或聚焦文件页,文件页的目录树始终显示。文件页替换开始页,同一分栏内重复打开仍保留一个文件页。桌面默认键为 Mod+P。开始页入口显示有效快捷键;Windows 和 macOS Web 使用[快捷键服务的平台默认值](../shortcuts/README.zh.md);Linux Web 默认不绑定此命令。
- **类型**:`ctx.sidebarRightTabs.register(...)`,kind 为 `files`,id 为 `@deepseek-ai/dsh-client-ui-sidebar-files`,档位 `builtin`,没有 patterns,另有一个打开该类型的引导页入口(order 10,标题与描述取自 `sidebarFiles` 命名空间,图标为黄色文件夹)。
- **文件页正文**:以该 id 为键的 `sidebar.right.pane.tab` slot。其标题行横跨页面,通过共享的 [`PathLabel`](../ui-primitives/README.zh.md#component-catalog) 显示根路径,目录使用弱化颜色,最后一段使用主色;路径过长时保留尾部字符并在左侧渐隐,悬停显示完整路径。目录树的重新读取控件和搜索栏开关位于由文件页注册声明的 Session 作用域 `sidebar.right.tab.files.actions` 列表之前(通过 `absolutePath` 传入当前显示的根目录);[`ui-open-in-app`](../ui-open-in-app/README.zh.md) 在此提供工作区目录打开按钮。末端打开控件的边框与上排折叠图标的可见右边缘对齐,位于其热区内侧。标题行下方由该分栏的导航栏铺满整页,停靠与浮动时都一样,这里没有导航栏开关。
- **文件页正文**:以该 id 为键的 `sidebar.right.pane.tab` slot。其标题行横跨页面,通过共享的 [`PathLabel`](../ui-primitives/README.zh.md#component-catalog) 显示根路径,目录使用弱化颜色,最后一段使用主色;路径过长时保留尾部字符并在左侧渐隐,悬停显示完整路径。目录树的重新读取控件和搜索栏开关位于由文件页注册声明的 Session 作用域 `sidebar.right.tab.files.actions` 列表之前(通过 `absolutePath` 传入当前显示的根目录);[`ui-open-in-app`](../ui-open-in-app/README.zh.md) 在此提供工作区目录打开按钮。末端打开控件的边框与上排折叠图标的可见右边缘对齐,位于其热区内侧。双按钮打开控件使搜索与上排分屏图标中心对齐。单应用控件按实际宽度自然靠右,保留普通的 4px 间距,不预留对齐列。目录操作没有渲染内容时,该列及其间距消失,搜索与上排折叠图标对齐。标题行下方由该分栏的导航栏铺满整页,停靠与浮动时都一样,这里没有导航栏开关。
- **各行**:root 作用域的 Component Factory `sidebar.files.tree`,接收调用方的条目和局部 `accessory` slot;见[复用目录树 Factory](#tree-factory)。
- **导航栏**:Session 作用域的 Component Factory `sidebar.files.navigator`。文件页正文和 [`ui-sidebar-documentpreview`](../ui-sidebar-documentpreview/README.zh.md) 直接渲染它,显示在每个预览旁,无论停靠还是浮动。它绘制[搜索栏](#search)、目录树及其调整宽度的边缘,没有自己的标题行:预览旁只有预览自己的标题行,目录树的重新读取与目录操作留在 `files` 页上。
- **开关**:Session 作用域的 Factory `sidebar.files.navigator.toggle`,在预览头部末端直接渲染,传入 `useTabInfo`。文件夹图形使用 16px,在共用的 28px 热区内补足横向轮廓的视觉尺寸,与相邻工具栏图标保持平衡。两个 Factory 共用文件页的 store handle 和 inject face,每个分栏保留一份开关状态;文件页正文没有导航栏开关。
@@ -159,7 +159,7 @@
/* The page's 38px row flush under the pane's strip: the root's path, then
reload and the directory actions. With the strip's 38px above, its rule lies where the conversation header's does
(ui-conversation ConversationRoot `.header`, 76px with the same rule).
The trailing capsule meets the upper collapse glyph, 7.5px inside its hit target. */
Without a handoff, the final icon shares the upper collapse control’s column. */
.header {
display: flex;
flex: 0 0 auto;
@@ -167,10 +167,31 @@
align-items: center;
box-sizing: border-box;
height: 38px;
padding: 0 13.5px 0 16px;
padding: 0 6px 0 16px;
border-bottom: 0.5px solid var(--dsw-alias-border-l3);
}
/* A real handoff aligns its frame to the upper glyph. */
.header:has(.externalActions > :global([data-slot]) > *) {
padding-right: 13.5px;
}
.externalActions {
display: flex;
flex: none;
align-items: center;
}
/* Only a split control needs the extra separation to align Search with Split. */
.externalActions:has(button[aria-haspopup='menu']) {
margin-left: 4.5px;
}
/* The renderer retains a display:contents slot anchor when every contribution returns null. */
.externalActions:not(:has(:global([data-slot]) > *)) {
display: none;
}
/* The margin plus the header's gap keeps the path 16px clear of reload. */
.path {
margin-right: 12px;
@@ -111,7 +111,9 @@ export function FilesBody(props: FilesBodyProps): ReactNode {
<IconSearchOutlineRegular />
</button>
</Tooltip>
{renderSlot('sidebar.right.tab.files.actions', { absolutePath: cwd })}
<div className={css.externalActions}>
{renderSlot('sidebar.right.tab.files.actions', { absolutePath: cwd })}
</div>
</div>
<div className={css.content} data-files-content data-files-navigator-row>{navigator}</div>
</div>
+1
View File
@@ -184,6 +184,7 @@
"apps/web/tests/message-actions.e2e.ts",
"apps/web/tests/open-in-app-ssh.e2e.ts",
"apps/web/tests/open-in-app-menus.e2e.ts",
"apps/web/tests/open-in-app-toolbar.e2e.ts",
"apps/web/tests/fork-mid-turn.e2e.ts",
"apps/web/tests/message-feedback.e2e.ts",
"apps/web/tests/markdown-images.e2e.ts",