From eba69b9fd647298a5921f8b1007f2cfdc33a0315 Mon Sep 17 00:00:00 2001 From: LegGasai Date: Fri, 13 Nov 2026 19:51:46 +0800 Subject: [PATCH] refactor(session-panel): share the row look through CSS marks instead of a row Factory A row Factory took each contributor's icon, text, trailing control, and menu as React nodes in props, which the client rules forbid. Each contributor now writes its own row markup and marks the parts with `data-session-panel-row` and `data-row-part`; the panel's stylesheet lays them out, so rows from every package keep one geometry and a contributor can restyle a part with its own class. A menu part that renders nothing, such as the shared menu button while its target has no menu entries, takes no room and no longer makes the row highlight. --- .../2026-11-05-session-panel.i18n.yaml | 4 +- .../feature/2026-11-05-session-panel.md | 2 +- .../feature/2026-11-05-session-panel.zh.md | 2 +- apps/web/tests/session-panel-dock.e2e.ts | 161 ----------- apps/web/tests/session-panel-layout.e2e.ts | 253 ++++++++++++++++++ apps/web/tsconfig.json | 2 +- .../client/ui-session-panel/README.i18n.yaml | 8 +- packages/client/ui-session-panel/README.md | 17 +- packages/client/ui-session-panel/README.zh.md | 17 +- packages/client/ui-session-panel/package.json | 1 - .../src/client/PanelRow.module.css | 155 ----------- .../ui-session-panel/src/client/PanelRow.tsx | 64 ----- .../src/client/ProjectRow.tsx | 25 +- .../src/client/SessionPanel.module.css | 171 ++++++++++++ .../ui-session-panel/src/client/index.ts | 13 +- .../ui-session-panel/src/client/slots.ts | 13 - .../tests/browser-plugin.client.spec.ts | 4 +- .../tests/components.client.spec.tsx | 13 + .../tests/panel-row.client.spec.tsx | 66 ----- .../tests/session-panel-styles.client.spec.ts | 52 +++- .../src/client/slot-catalog.ts | 8 +- pnpm-lock.yaml | 3 - tsconfig.host.json | 2 +- 23 files changed, 545 insertions(+), 511 deletions(-) delete mode 100644 apps/web/tests/session-panel-dock.e2e.ts create mode 100644 apps/web/tests/session-panel-layout.e2e.ts delete mode 100644 packages/client/ui-session-panel/src/client/PanelRow.module.css delete mode 100644 packages/client/ui-session-panel/src/client/PanelRow.tsx delete mode 100644 packages/client/ui-session-panel/tests/panel-row.client.spec.tsx diff --git a/.agents/notes/implemented/feature/2026-11-05-session-panel.i18n.yaml b/.agents/notes/implemented/feature/2026-11-05-session-panel.i18n.yaml index f96974bfe0..a661424786 100644 --- a/.agents/notes/implemented/feature/2026-11-05-session-panel.i18n.yaml +++ b/.agents/notes/implemented/feature/2026-11-05-session-panel.i18n.yaml @@ -15,8 +15,8 @@ en: 8a97ac8ac0b40d0c zh: d42fe9c23b9dcd79 /agent-note-session-panel-in-the-chat-view-s-end-gutter/decision/sections-are-registrations-the-panel-draws-titles: - en: d93135868e42f9a0 - zh: b3336f9be64ef789 + en: d6f85e07351ad90e + zh: f883a99c8ca98522 /agent-note-session-panel-in-the-chat-view-s-end-gutter/decision/the-turn-rail-sits-at-the-start-edge: en: 08e720a4ea75d4d6 zh: 5e2e5b8452f67d36 diff --git a/.agents/notes/implemented/feature/2026-11-05-session-panel.md b/.agents/notes/implemented/feature/2026-11-05-session-panel.md index 1783d5903a..7dbb92ce80 100644 --- a/.agents/notes/implemented/feature/2026-11-05-session-panel.md +++ b/.agents/notes/implemented/feature/2026-11-05-session-panel.md @@ -24,7 +24,7 @@ Docking follows one persisted preference shared by every Session and defaults to Each section is one list registration with `id`, `order`, and a required `label`. The panel projects the live registrations into titles, draws each title, and renders the section body with `renderSlot(..., { only: id })`; a CSS `:has()` rule hides a section whose body rendered nothing, so a section opts out by rendering nothing and no effect reports visibility to the owner. Trailing title controls are a keyed slot addressed by the section `id`, and a section that several plugins share declares its own row slot, as the built-in Environment section does with `conversation.session.panel.environment.row`. Marks that must stay visible while the panel is hidden go in an indicator list over the toggle. -Rows from every contributor render through the plugin's `conversation.session.panel.row` Component Factory so icon, text, and trailing areas align across packages; a feature package cannot share its own row component with another feature package. +Rows from every contributor share one look through the panel's stylesheet instead of a shared component: each contributor writes its row's markup and marks the parts, and the panel lays them out, so icon, text, and trailing areas align across packages. A shared row component would receive each contributor's icon, text, and controls as React nodes in props, which the client rules forbid, and a feature package cannot share its own row component with another feature package. ### The turn rail sits at the start edge diff --git a/.agents/notes/implemented/feature/2026-11-05-session-panel.zh.md b/.agents/notes/implemented/feature/2026-11-05-session-panel.zh.md index cf1153ee86..de8e0914a5 100644 --- a/.agents/notes/implemented/feature/2026-11-05-session-panel.zh.md +++ b/.agents/notes/implemented/feature/2026-11-05-session-panel.zh.md @@ -24,7 +24,7 @@ Status: implemented 每个分栏是一次 list 注册,带 `id`、`order` 和必填的 `label`。面板把实时注册投影成标题并逐个绘制,再用 `renderSlot(..., { only: id })` 渲染分栏正文;CSS `:has()` 规则隐藏正文没有渲染内容的分栏,因此分栏不渲染任何内容即可退出,不需要 effect 向拥有者上报可见性。标题尾部控件是以分栏 `id` 为键的 keyed slot;多个插件共用的分栏声明自己的行 slot,内置「环境」分栏就以 `conversation.session.panel.environment.row` 这样做。面板隐藏时也要可见的标记放进开关上的角标列表。 -所有贡献方的行都通过插件的 Component Factory `conversation.session.panel.row` 渲染,使不同包的图标、文字与尾部区域对齐;功能包之间不能共享各自的行组件。 +各贡献方的行通过面板的样式表共享同一外观,而不是共享组件:各贡献方自己写行的标记并标出各个部分,由面板统一排版,使不同包的图标、文字与尾部区域对齐。共享的行组件要把各贡献方的图标、文字和控件作为 React 节点从 props 传入,这是客户端规则禁止的;功能包之间也不能共享各自的行组件。 ### 轮次轨道位于起始边 diff --git a/apps/web/tests/session-panel-dock.e2e.ts b/apps/web/tests/session-panel-dock.e2e.ts deleted file mode 100644 index 92ea27624e..0000000000 --- a/apps/web/tests/session-panel-dock.e2e.ts +++ /dev/null @@ -1,161 +0,0 @@ -/** - * Session panel docking in the shipped Web composition. The panel's stylesheet - * decides whether the Chat View's end gutter holds the docked panel and tells - * the plugin through a 1px dock probe; jsdom cannot evaluate that stylesheet, - * so this measures the probe, the panel, and the toggle around the boundary. - */ -import { readFile } from 'node:fs/promises' -import { fileURLToPath } from 'node:url' -import type { Browser, Page } from 'playwright' -import { chromium } from 'playwright' -import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest' -import type { SessionId } from '@deepseek-ai/dsh-session' -import { brandString } from '@deepseek-ai/dsh-brand' -import { launchWebScaffold, seedSession, watchConsole, webSnapshotMode, type WebScaffold } from './scaffold.ts' -import { newEnglishPage, saveFailureShot } from './support.ts' - -const FIXTURE = fileURLToPath(new URL('../../../snapshots/web/fresh-round-trip/session.v3.jsonl', import.meta.url)) -const MODE = webSnapshotMode() -const SEED_ID = brandString('session-panel-dock-web-e2e') -/** The default transcript width in a frame wide enough to dock. */ -const TRANSCRIPT = 880 -/** The gutter that holds the docked panel: 40px clear of the transcript, its 300px minimum width, and the 8px edge inset. */ -const DOCK_GUTTER = 348 - -/** What the layout says about docking: the gutter, the probe, the panel's presentation and insets, and the toggle. */ -function docking(page: Page) { - return page.evaluate(() => { - const layer = document.querySelector('[data-chat-aside]') - const column = document.querySelector('[data-chat-flow]') - const probe = document.querySelector('[data-session-panel-probe]') - const toggle = document.querySelector('[data-session-panel-toggle]') - if (layer === null || column === null || probe === null || toggle === null) { - throw new Error('aside layer, transcript column, dock probe, or panel toggle is missing') - } - const frame = layer.getBoundingClientRect() - const flow = column.getBoundingClientRect() - const panel = document.querySelector('[data-session-panel]') - const box = panel?.getBoundingClientRect() - return { - gutter: (frame.width - flow.width) / 2, - probe: probe.getBoundingClientRect().width, - presentation: panel?.dataset['sessionPanel'] ?? null, - expanded: toggle.getAttribute('aria-expanded'), - panel: box === undefined ? null : { width: box.width, clear: box.left - flow.right, edge: frame.right - box.right }, - } - }) -} - -describe.skipIf(MODE === 'record')('web e2e: Session panel docking', () => { - let scaffold: WebScaffold - let browser: Browser - let page: Page - let tripwire: ReturnType - /** Viewport width the application keeps outside the Chat frame. */ - let chrome = 0 - - /** Resize the window so the Chat View's end gutter is exactly `gutter`, and wait for the layout to follow. */ - async function setGutter(gutter: number): Promise { - await page.setViewportSize({ width: TRANSCRIPT + 2 * gutter + chrome, height: page.viewportSize()!.height }) - await expect.poll(async () => (await docking(page)).gutter, { timeout: 10_000 }).toBe(gutter) - } - - /** Wait until the panel shows this way (null: not at all) and its entrance has finished. */ - async function shows(presentation: 'docked' | 'overlay' | null): Promise { - await expect.poll(async () => (await docking(page)).presentation, { timeout: 10_000 }).toBe(presentation) - if (presentation === null) return - await page.locator('[data-session-panel]').evaluate(async (element) => { - await Promise.all(element.getAnimations().map(animation => animation.finished)) - }) - } - - beforeAll(async () => { - scaffold = await launchWebScaffold() - await seedSession(scaffold, await readFile(FIXTURE, 'utf8'), SEED_ID) - browser = await chromium.launch() - page = await newEnglishPage(browser) - await page.emulateMedia({ reducedMotion: 'reduce' }) - tripwire = watchConsole(page) - await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' }) - }, 120_000) - - /** Open the seeded Session and learn how much of the window lies outside the Chat frame. */ - async function openSession(): Promise { - if (chrome !== 0) return - const session = page.locator(`[data-row-key="session:${SEED_ID}"]`) - await expect.poll(async () => { - if (await session.isVisible()) return true - const group = page.locator('[role="treeitem"][aria-expanded]').first() - if (await group.count() > 0 && await group.getAttribute('aria-expanded') === 'false') await group.click() - return session.isVisible() - }, { timeout: 15_000 }).toBe(true) - await session.click() - await page.locator('[data-session-panel-probe]').waitFor({ state: 'attached', timeout: 30_000 }) - const frame = await page.locator('[data-chat-aside]').evaluate(element => element.getBoundingClientRect().width) - chrome = page.viewportSize()!.width - frame - } - - afterAll(async () => { - const failures: unknown[] = [] - try { await browser?.close() } catch (error) { failures.push(error) } - try { await scaffold?.close() } catch (error) { failures.push(error) } - if (failures.length > 0) throw new AggregateError(failures, 'Session panel docking teardown failed') - }) - - it('docks exactly from the gutter that holds the panel at its minimum width', async () => { - onTestFailed(() => saveFailureShot(page, 'web-e2e-session-panel-dock')) - await openSession() - expect(Number.isInteger(chrome)).toBe(true) - - await setGutter(DOCK_GUTTER - 1) - await shows(null) - expect(await docking(page)).toEqual({ gutter: DOCK_GUTTER - 1, probe: 0, presentation: null, expanded: 'false', panel: null }) - - // Half a pixel short, the probe is half a pixel wide and the panel stays hidden. - await setGutter(DOCK_GUTTER - 0.5) - expect(await docking(page)).toEqual({ gutter: DOCK_GUTTER - 0.5, probe: 0.5, presentation: null, expanded: 'false', panel: null }) - - await setGutter(DOCK_GUTTER) - await shows('docked') - expect(await docking(page)).toEqual({ - gutter: DOCK_GUTTER, probe: 1, presentation: 'docked', expanded: 'true', panel: { width: 300, clear: 40, edge: 8 }, - }) - - // A wider gutter widens the panel to its maximum at the same edge inset; the probe stays 1px. - await setGutter(DOCK_GUTTER + 100) - expect(await docking(page)).toEqual({ - gutter: DOCK_GUTTER + 100, probe: 1, presentation: 'docked', expanded: 'true', panel: { width: 360, clear: 80, edge: 8 }, - }) - - await setGutter(DOCK_GUTTER - 1) - await shows(null) - expect((await docking(page)).expanded).toBe('false') - expect(tripwire.pageErrors).toEqual([]) - }) - - it('floats narrower than it docks, at the same edge inset, and docks once the gutter holds it', async () => { - onTestFailed(() => saveFailureShot(page, 'web-e2e-session-panel-overlay')) - await openSession() - const toggle = page.locator('[data-session-panel-toggle]') - await setGutter(260) - await shows(null) - await toggle.click() - await shows('overlay') - const overlay = await docking(page) - expect(overlay).toMatchObject({ probe: 0, presentation: 'overlay', expanded: 'true', panel: { width: 280, edge: 8 } }) - // The overlay covers part of the transcript instead of keeping clear of it. - expect(overlay.panel?.clear).toBeLessThan(0) - - await page.keyboard.press('Escape') - await shows(null) - expect((await docking(page)).expanded).toBe('false') - - // An open overlay gives way to the docked panel when the window widens enough. - await toggle.click() - await shows('overlay') - await setGutter(DOCK_GUTTER) - await shows('docked') - expect(await docking(page)).toMatchObject({ probe: 1, expanded: 'true', panel: { width: 300, clear: 40, edge: 8 } }) - expect(tripwire.pageErrors).toEqual([]) - }) -}) diff --git a/apps/web/tests/session-panel-layout.e2e.ts b/apps/web/tests/session-panel-layout.e2e.ts new file mode 100644 index 0000000000..7d3186d0d4 --- /dev/null +++ b/apps/web/tests/session-panel-layout.e2e.ts @@ -0,0 +1,253 @@ +/** + * Session panel layout in the shipped Web composition. The panel's stylesheet + * decides whether the Chat View's end gutter holds the docked panel and tells + * the plugin through a 1px dock probe, and it lays out the rows that + * contributors mark. jsdom cannot evaluate that stylesheet, so this measures + * the probe, the panel, and the toggle around the docking boundary, and the + * working folder row without and with a directory context menu. + */ +import { readFile } from 'node:fs/promises' +import { fileURLToPath } from 'node:url' +import type { Browser, Page } from 'playwright' +import { chromium } from 'playwright' +import { afterAll, beforeAll, describe, expect, it, onTestFailed, onTestFinished } from 'vitest' +import { createLaunchEnvironmentSnapshot } from '@deepseek-ai/dsh-launch-environment' +import type { SessionId } from '@deepseek-ai/dsh-session' +import { brandString } from '@deepseek-ai/dsh-brand' +import { launchWebScaffold, seedSession, watchConsole, webSnapshotMode, type WebScaffold } from './scaffold.ts' +import { newEnglishPage, saveFailureShot } from './support.ts' + +const FIXTURE = fileURLToPath(new URL('../../../snapshots/web/fresh-round-trip/session.v3.jsonl', import.meta.url)) +const MODE = webSnapshotMode() +const SEED_ID = brandString('session-panel-layout-web-e2e') +/** The default transcript width in a frame wide enough to dock. */ +const TRANSCRIPT = 880 +/** The gutter that holds the docked panel: 40px clear of the transcript, its 300px minimum width, and the 8px edge inset. */ +const DOCK_GUTTER = 348 + +/** What the layout says about docking: the gutter, the probe, the panel's presentation and insets, and the toggle. */ +function docking(page: Page) { + return page.evaluate(() => { + const layer = document.querySelector('[data-chat-aside]') + const column = document.querySelector('[data-chat-flow]') + const probe = document.querySelector('[data-session-panel-probe]') + const toggle = document.querySelector('[data-session-panel-toggle]') + if (layer === null || column === null || probe === null || toggle === null) { + throw new Error('aside layer, transcript column, dock probe, or panel toggle is missing') + } + const frame = layer.getBoundingClientRect() + const flow = column.getBoundingClientRect() + const panel = document.querySelector('[data-session-panel]') + const box = panel?.getBoundingClientRect() + return { + gutter: (frame.width - flow.width) / 2, + probe: probe.getBoundingClientRect().width, + presentation: panel?.dataset['sessionPanel'] ?? null, + expanded: toggle.getAttribute('aria-expanded'), + panel: box === undefined ? null : { width: box.width, clear: box.left - flow.right, edge: frame.right - box.right }, + } + }) +} + +/** Open the seeded Session through the sidebar and wait for the panel's dock probe. */ +async function openSeed(page: Page): Promise { + const session = page.locator(`[data-row-key="session:${SEED_ID}"]`) + await expect.poll(async () => { + if (await session.isVisible()) return true + const group = page.locator('[role="treeitem"][aria-expanded]').first() + if (await group.count() > 0 && await group.getAttribute('aria-expanded') === 'false') await group.click() + return session.isVisible() + }, { timeout: 15_000 }).toBe(true) + await session.click() + await page.locator('[data-session-panel-probe]').waitFor({ state: 'attached', timeout: 30_000 }) +} + +/** Wait until the panel shows this way (null: not at all) and its entrance has finished. */ +async function shows(page: Page, presentation: 'docked' | 'overlay' | null): Promise { + await expect.poll(async () => (await docking(page)).presentation, { timeout: 10_000 }).toBe(presentation) + if (presentation === null) return + await page.locator('[data-session-panel]').evaluate(async (element) => { + await Promise.all(element.getAnimations().map(animation => animation.finished)) + }) +} + +/** + * The working folder row as laid out: its line, how far the centers of its + * icon and menu columns sit from its edges, the room after its text, and what + * the pointer state shows. `menu` is null while the menu part renders nothing. + */ +function rowLayout(page: Page) { + return page.locator('[data-session-panel] [data-session-panel-project]').evaluate((element) => { + const box = element.getBoundingClientRect() + const icon = element.querySelector('[data-row-part="icon"]')!.getBoundingClientRect() + const content = element.querySelector('[data-row-part="content"]')! + const menu = element.querySelector('[data-row-part="menu"]')! + const column = menu.getBoundingClientRect() + const button = menu.querySelector('button')?.getBoundingClientRect() + return { + height: box.height, + iconCenter: icon.left + icon.width / 2 - box.left, + iconSize: [icon.width, icon.height], + clipped: getComputedStyle(content).textOverflow, + afterText: box.right - content.getBoundingClientRect().right, + menu: button === undefined + ? null + : { + center: box.right - (column.left + column.width / 2), + target: [button.width, button.height], + opacity: getComputedStyle(menu).opacity, + }, + hovered: element.matches(':hover'), + highlighted: getComputedStyle(element).backgroundColor !== 'rgba(0, 0, 0, 0)', + } + }) +} + +describe.skipIf(MODE === 'record')('web e2e: Session panel layout', () => { + let scaffold: WebScaffold + let browser: Browser + let page: Page + let tripwire: ReturnType + /** Viewport width the application keeps outside the Chat frame. */ + let chrome = 0 + + /** Resize the window so the Chat View's end gutter is exactly `gutter`, and wait for the layout to follow. */ + async function setGutter(gutter: number): Promise { + await page.setViewportSize({ width: TRANSCRIPT + 2 * gutter + chrome, height: page.viewportSize()!.height }) + await expect.poll(async () => (await docking(page)).gutter, { timeout: 10_000 }).toBe(gutter) + } + + beforeAll(async () => { + scaffold = await launchWebScaffold() + await seedSession(scaffold, await readFile(FIXTURE, 'utf8'), SEED_ID) + browser = await chromium.launch() + page = await newEnglishPage(browser) + await page.emulateMedia({ reducedMotion: 'reduce' }) + tripwire = watchConsole(page) + await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' }) + }, 120_000) + + /** Open the seeded Session and learn how much of the window lies outside the Chat frame. */ + async function openSession(): Promise { + if (chrome !== 0) return + await openSeed(page) + const frame = await page.locator('[data-chat-aside]').evaluate(element => element.getBoundingClientRect().width) + chrome = page.viewportSize()!.width - frame + } + + afterAll(async () => { + const failures: unknown[] = [] + try { await browser?.close() } catch (error) { failures.push(error) } + try { await scaffold?.close() } catch (error) { failures.push(error) } + if (failures.length > 0) throw new AggregateError(failures, 'Session panel layout teardown failed') + }) + + it('docks exactly from the gutter that holds the panel at its minimum width', async () => { + onTestFailed(() => saveFailureShot(page, 'web-e2e-session-panel-dock')) + await openSession() + expect(Number.isInteger(chrome)).toBe(true) + + await setGutter(DOCK_GUTTER - 1) + await shows(page, null) + expect(await docking(page)).toEqual({ gutter: DOCK_GUTTER - 1, probe: 0, presentation: null, expanded: 'false', panel: null }) + + // Half a pixel short, the probe is half a pixel wide and the panel stays hidden. + await setGutter(DOCK_GUTTER - 0.5) + expect(await docking(page)).toEqual({ gutter: DOCK_GUTTER - 0.5, probe: 0.5, presentation: null, expanded: 'false', panel: null }) + + await setGutter(DOCK_GUTTER) + await shows(page, 'docked') + expect(await docking(page)).toEqual({ + gutter: DOCK_GUTTER, probe: 1, presentation: 'docked', expanded: 'true', panel: { width: 300, clear: 40, edge: 8 }, + }) + + // A wider gutter widens the panel to its maximum at the same edge inset; the probe stays 1px. + await setGutter(DOCK_GUTTER + 100) + expect(await docking(page)).toEqual({ + gutter: DOCK_GUTTER + 100, probe: 1, presentation: 'docked', expanded: 'true', panel: { width: 360, clear: 80, edge: 8 }, + }) + + await setGutter(DOCK_GUTTER - 1) + await shows(page, null) + expect((await docking(page)).expanded).toBe('false') + expect(tripwire.pageErrors).toEqual([]) + }) + + it('floats narrower than it docks, at the same edge inset, and docks once the gutter holds it', async () => { + onTestFailed(() => saveFailureShot(page, 'web-e2e-session-panel-overlay')) + await openSession() + const toggle = page.locator('[data-session-panel-toggle]') + await setGutter(260) + await shows(page, null) + await toggle.click() + await shows(page, 'overlay') + const overlay = await docking(page) + expect(overlay).toMatchObject({ probe: 0, presentation: 'overlay', expanded: 'true', panel: { width: 280, edge: 8 } }) + // The overlay covers part of the transcript instead of keeping clear of it. + expect(overlay.panel?.clear).toBeLessThan(0) + + await page.keyboard.press('Escape') + await shows(page, null) + expect((await docking(page)).expanded).toBe('false') + + // An open overlay gives way to the docked panel when the window widens enough. + await toggle.click() + await shows(page, 'overlay') + await setGutter(DOCK_GUTTER) + await shows(page, 'docked') + expect(await docking(page)).toMatchObject({ probe: 1, expanded: 'true', panel: { width: 300, clear: 40, edge: 8 } }) + expect(tripwire.pageErrors).toEqual([]) + }) + + it('lays the working folder row out by its marks, with no room or highlight for a menu that renders nothing', async () => { + onTestFailed(() => saveFailureShot(page, 'web-e2e-session-panel-row')) + await openSession() + await setGutter(DOCK_GUTTER + 100) + await shows(page, 'docked') + const row = page.locator('[data-session-panel] [data-session-panel-project]') + await row.waitFor() + await page.mouse.move(5, 5) + // This composition registers no directory menu entries, so the shared More button renders nothing: + // the text runs to the row's 6px padding, and the row has nothing to highlight for. + const resting = { height: 28, iconCenter: 14, iconSize: [16, 16], clipped: 'ellipsis', afterText: 6, menu: null, highlighted: false } + expect(await rowLayout(page)).toEqual({ ...resting, hovered: false }) + await row.hover() + expect(await rowLayout(page)).toEqual({ ...resting, hovered: true }) + expect(tripwire.pageErrors).toEqual([]) + }) + + it('puts a rendered menu on the panel end column and shows it, with the row highlight, on hover', async () => { + // The directory context menu comes from Open In; SSH facts keep it from probing this runner's native applications. + const withMenu = await launchWebScaffold({ openInAppEnvironment: createLaunchEnvironmentSnapshot([ + { source: 'process', values: { SSH_CONNECTION: '10.0.0.2 55000 10.0.0.9 22' } }, + ]) }) + onTestFinished(() => withMenu.close()) + await seedSession(withMenu, await readFile(FIXTURE, 'utf8'), SEED_ID) + const other = await newEnglishPage(browser) + onTestFinished(() => other.close()) + onTestFailed(() => saveFailureShot(other, 'web-e2e-session-panel-row-menu')) + await other.emulateMedia({ reducedMotion: 'reduce' }) + const errors = watchConsole(other) + // Wide enough for the gutter to hold the docked panel. + await other.setViewportSize({ width: 2200, height: 1000 }) + await other.goto(withMenu.authenticatedUrl, { waitUntil: 'load' }) + await openSeed(other) + await shows(other, 'docked') + const row = other.locator('[data-session-panel] [data-session-panel-project]') + await row.locator('[data-row-part="menu"] button').waitFor({ state: 'attached' }) + await other.mouse.move(5, 5) + // The 16px menu column and the 8px gap before it follow the text; the 24px target reaches past the column. + const resting = { height: 28, iconCenter: 14, iconSize: [16, 16], clipped: 'ellipsis', afterText: 30 } + expect(await rowLayout(other)).toEqual({ + ...resting, menu: { center: 14, target: [24, 24], opacity: '0' }, hovered: false, highlighted: false, + }) + await row.hover() + await expect.poll(async () => (await rowLayout(other)).menu?.opacity).toBe('1') + expect(await rowLayout(other)).toEqual({ + ...resting, menu: { center: 14, target: [24, 24], opacity: '1' }, hovered: true, highlighted: true, + }) + await other.mouse.move(5, 5) + await expect.poll(async () => (await rowLayout(other)).highlighted).toBe(false) + expect(errors.pageErrors).toEqual([]) + }) +}) diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index f12cc2fdea..65bc6f4628 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -25,7 +25,7 @@ "exclude": [ "tests/home-whale.e2e.ts", "tests/sidebar-drawer.e2e.ts", - "tests/session-panel-dock.e2e.ts", + "tests/session-panel-layout.e2e.ts", "tests/creation-recommendations.e2e.ts", "tests/plugin-recommendations.e2e.ts", "tests/japanese-plugin-metadata.e2e.ts", diff --git a/packages/client/ui-session-panel/README.i18n.yaml b/packages/client/ui-session-panel/README.i18n.yaml index c91a8899ce..97d36774c6 100644 --- a/packages/client/ui-session-panel/README.i18n.yaml +++ b/packages/client/ui-session-panel/README.i18n.yaml @@ -21,11 +21,11 @@ en: 67b33b9f412a687d zh: 2a9b8c89c8bb22e4 /deepseek-ai-dsh-client-ui-session-panel/use-this-package/contribute-a-section: - en: 853f022d35daac99 - zh: 0caf8d2f6f207d82 + en: 1e82e57556909a29 + zh: fc68f414ec254403 /deepseek-ai-dsh-client-ui-session-panel/understand-the-implementation: - en: e3fc397ec6c8ef3b - zh: 097a67dadb267010 + en: e414b3b6a3aef7fc + zh: 384ad365ae5529a9 /deepseek-ai-dsh-client-ui-session-panel/further-exploration: en: 09b403af819bd155 zh: e949998de4794393 diff --git a/packages/client/ui-session-panel/README.md b/packages/client/ui-session-panel/README.md index 72fb750344..957fbe8480 100644 --- a/packages/client/ui-session-panel/README.md +++ b/packages/client/ui-session-panel/README.md @@ -44,7 +44,18 @@ Plugins share a title by registering rows in a section owner's row slot. The bui Marks that must stay visible while the panel is hidden, such as an attention dot, go in the `conversation.session.panel.indicator` list. Each occupant is one element: the toggle sizes it to a 6px dot at the glyph's corner, and the occupant sets its `background` and includes text that names it, which becomes part of the toggle's accessible name. Occupants overlap, and a higher `order` paints above a lower one. The `panelShown` owner prop lets a mark that only repeats the panel's content render nothing while the panel shows. -The plugin offers its row as the `conversation.session.panel.row` Component Factory. Sections and Environment rows from every package render their rows with `renderFactorySlot('conversation.session.panel.row', props)`, so icon, text, and trailing areas line up across sections. A row has a 16px decorative icon that inherits the row ink, single-line content that clips with an ellipsis, and an optional trailing value or control. `menu` holds row actions, such as a More button, after the trailing area in a 16px column whose center sits 14px from the row's end; a plain `button` there gets a 24px target and a tertiary glyph that darkens on hover without a fill, so it needs no tooltip of its own. They show on row hover, on focus inside the row, and while one has its menu open, and always without hover. `onActivate` makes the whole row one button while the trailing area and the menu stay separate controls; a row with an action or row actions fills as a whole on hover and while one of its menus is open. `className` adds to the row's class, and `attributes`, such as `role`, `data-*` markers, and context-menu trigger props, reach the row element; other props are ignored. +Rows share one look without sharing a component. A section's component, or an Environment row entry, writes its row's markup and marks the parts, and the panel's stylesheet lays them out, so icon, text, and trailing areas line up across packages while each package owns what its row contains. + +| Mark | Part | +|---|---| +| `data-session-panel-row` | The row: one 28px line. A row with an action or a menu highlights as a whole on hover and while one of its menus is open. | +| `data-row-part="body"` | The icon and the text. A `} - {trailing !== undefined && {trailing}} - {menu !== undefined && {menu}} - - ) -} diff --git a/packages/client/ui-session-panel/src/client/ProjectRow.tsx b/packages/client/ui-session-panel/src/client/ProjectRow.tsx index add253e0da..15f64d245d 100644 --- a/packages/client/ui-session-panel/src/client/ProjectRow.tsx +++ b/packages/client/ui-session-panel/src/client/ProjectRow.tsx @@ -3,7 +3,6 @@ import type { ReactNode } from 'react' import { IconFolderCloseRegular, Tooltip } from '@deepseek-ai/dsh-client-ui-primitives' import { abbreviateHomePath, pathPartsOf } from '@deepseek-ai/dsh-util-workspace-path' import type {} from '@deepseek-ai/dsh-working-directory/types' -import { PanelRow } from './PanelRow.tsx' import type { ProjectRowProps } from './slots.ts' import css from './ProjectRow.module.css' @@ -34,17 +33,19 @@ export function ProjectRow({ const parent = ROOT.test(directory) ? directory : directory.replace(/[/\\]+$/, '') const target = { kind: 'directory', value: { sessionId, path } } as const return ( - } - menu={renderFactorySlot('contextMenu.button', { target, label: t('project.actions') })} - attributes={{ ...getTriggerProps(target), 'data-session-panel-project': '' }} - > - - - {name} - {parent !== '' && {parent}} +
+ + + + + + {name} + {parent !== '' && {parent}} + + - - + + {renderFactorySlot('contextMenu.button', { target, label: t('project.actions') })} +
) } diff --git a/packages/client/ui-session-panel/src/client/SessionPanel.module.css b/packages/client/ui-session-panel/src/client/SessionPanel.module.css index 2bd861ff5e..fa05289733 100644 --- a/packages/client/ui-session-panel/src/client/SessionPanel.module.css +++ b/packages/client/ui-session-panel/src/client/SessionPanel.module.css @@ -137,3 +137,174 @@ animation: none; } } + +/* Rows. The rows of every section share one look without sharing a + component: each contributor writes its row's markup and marks the parts, + and these rules lay them out. + + [data-session-panel-row] the row: one 28px line + [data-row-part='body'] the icon and the text; a }> - Local changes -
, - ) - fireEvent.click(screen.getByRole('button', { name: 'Local changes' })) - expect(onActivate).toHaveBeenCalledTimes(1) - fireEvent.click(screen.getByRole('button', { name: 'More' })) - expect(onTrailing).toHaveBeenCalledTimes(1) - expect(onActivate).toHaveBeenCalledTimes(1) - }) - - it('places row actions after the trailing area and marks only rows with an action or row actions as interactive', () => { - const view = render( - } trailing={value} menu={}>Project, - ) - const row = view.container.querySelector('[data-panel-row]') as HTMLElement - expect([...row.children].map(child => child.textContent)).toEqual(['Project', 'value', 'More']) - const interactive = row.className - cleanup() - const plain = render(} trailing={value}>Project) - const staticRow = plain.container.querySelector('[data-panel-row]') as HTMLElement - expect(staticRow.children).toHaveLength(2) - expect(staticRow.className).not.toBe(interactive) - }) - - it('puts its attributes, such as context-menu handlers and markers, and its class on the row element', () => { - const onContextMenu = vi.fn() - const view = render( - } className="placed" attributes={{ onContextMenu, tabIndex: 0, 'data-marker': 'on' }}>Row, - ) - const row = view.container.querySelector('[data-panel-row]') as HTMLElement - expect(row.className).toContain('placed') - expect(row.tabIndex).toBe(0) - expect(row.getAttribute('data-marker')).toBe('on') - fireEvent.contextMenu(row) - expect(onContextMenu).toHaveBeenCalledTimes(1) - }) - - it('leaves props outside its own, such as a Factory occurrence adds, off the row element', () => { - const extra = { renderFactorySlot: vi.fn(), useFactorySlot: vi.fn(), useWorkspaces: vi.fn() } - const view = render(, children: 'Row', ...extra }} />) - const row = view.container.querySelector('[data-panel-row]') as HTMLElement - expect(row.getAttributeNames().sort()).toEqual(['class', 'data-panel-row']) - }) -}) diff --git a/packages/client/ui-session-panel/tests/session-panel-styles.client.spec.ts b/packages/client/ui-session-panel/tests/session-panel-styles.client.spec.ts index 1b82c25b9b..048c87a7a7 100644 --- a/packages/client/ui-session-panel/tests/session-panel-styles.client.spec.ts +++ b/packages/client/ui-session-panel/tests/session-panel-styles.client.spec.ts @@ -1,8 +1,9 @@ /** - * The Session panel's docking geometry as CSS text. jsdom has no layout, so - * the component suite cannot show that the dock probe is 1px wide exactly - * from the gutter that holds the docked panel; this reads the declarations - * and evaluates them for gutters around that boundary. + * The Session panel's stylesheet as CSS text. jsdom has no layout, so the + * component suite cannot show that the dock probe is 1px wide exactly from + * the gutter that holds the docked panel, or that marked rows get one + * geometry; this reads the declarations and evaluates the docking ones for + * gutters around that boundary. */ import { readFileSync } from 'node:fs' import { fileURLToPath } from 'node:url' @@ -70,3 +71,46 @@ describe('SessionPanel.module.css docking geometry', () => { expect(declarationsOf(".panel[data-session-panel='overlay']")['width']).toBe('min(280px, calc(100% - 2 * var(--panel-edge)))') }) }) + +describe('SessionPanel.module.css row rules', () => { + /** A rule for marked row markup: `.panel :where()`. */ + const row = (inner: string, tail = ''): Record => declarationsOf(`.panel :where(${inner})${tail}`) + + it('lays a marked row out as one 28px line with the icon and the menu on fixed columns', () => { + expect(row('[data-session-panel-row]')).toMatchObject({ + 'display': 'flex', 'align-items': 'center', 'gap': '8px', 'min-height': '28px', 'padding': '0 6px', + }) + expect(row("[data-session-panel-row] > [data-row-part='body']")).toMatchObject({ flex: '1 1 auto', height: '28px', gap: '8px' }) + // 6px of padding and half of the 16px box put the icon's center 14px from the row's start, and the menu's from its end. + expect(row("[data-session-panel-row] [data-row-part='icon']")).toMatchObject({ width: '16px', height: '16px', flex: 'none' }) + expect(row("[data-session-panel-row] > [data-row-part='menu']")).toMatchObject({ 'width': '16px', 'justify-content': 'center' }) + expect(row("[data-session-panel-row] [data-row-part='content']")).toMatchObject({ + 'overflow': 'hidden', 'text-overflow': 'ellipsis', 'white-space': 'nowrap', + }) + }) + + it('makes a button body the action of the whole row and rings the row when it has keyboard focus', () => { + expect(row("[data-session-panel-row] > button[data-row-part='body']", '::after')).toMatchObject({ position: 'absolute', inset: '0' }) + expect(row("[data-session-panel-row] > [data-row-part='trailing'], [data-session-panel-row] > [data-row-part='menu']")) + .toMatchObject({ 'position': 'relative', 'z-index': '1' }) + expect(row("[data-session-panel-row]:has(> button[data-row-part='body']:focus-visible)")['outline-offset']).toBe('-2px') + }) + + it('gives a plain button in the menu a 24px target and a tertiary glyph without a fill', () => { + expect(row("[data-session-panel-row] > [data-row-part='menu']", ' button')).toMatchObject({ + width: '24px', height: '24px', margin: '-4px', background: 'transparent', color: 'var(--dsw-alias-label-tertiary)', + }) + }) + + it('highlights only a row with an action or a menu that renders something, and keeps an open menu and its row shown', () => { + const interactive = "[data-session-panel-row]:has(> button[data-row-part='body'], > [data-row-part='menu']:not(:empty))" + expect(row("[data-session-panel-row] > [data-row-part='menu']:empty")).toEqual({ display: 'none' }) + expect(row(`${interactive}:has([aria-expanded='true'])`)['background']).toBe('var(--dsw-alias-interactive-bg-hover)') + expect(row("[data-session-panel-row] > [data-row-part='menu']:has([aria-expanded='true'])")['opacity']).toBe('1') + // Hover rules stay inside the hover media query, where the menu hides until the row is hovered or focused. + const hover = /@media \(hover: hover\) \{([\s\S]*?)\n\}/.exec(css)?.[1] ?? '' + expect(hover).toContain(`.panel :where(${interactive}:hover)`) + expect(hover).toMatch(/\[data-row-part='menu'\]\) \{\s*opacity: 0;/) + expect(css.replace(/@media \(hover: hover\) \{[\s\S]*?\n\}/g, '')).not.toContain(':hover') + }) +}) diff --git a/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts b/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts index 874bdf7dde..e3027ab67c 100644 --- a/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts +++ b/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts @@ -2465,7 +2465,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [ ], replaceRisk: 'none', example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.session.panel.environment.row\', () => ctx.slots.register(\n { name: \'conversation.session.panel.environment.row\', id: \'my-entry\', order: 100, label: \'My entry\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}', - source: 'packages/client/ui-session-panel/src/client/slots.ts:57', + source: 'packages/client/ui-session-panel/src/client/slots.ts:44', }, { key: 'conversation.session.panel.indicator', @@ -2525,7 +2525,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [ occupants: [], replaceRisk: 'none', example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.session.panel.indicator\', () => ctx.slots.register(\n { name: \'conversation.session.panel.indicator\', id: \'my-entry\', order: 100, label: \'My entry\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}', - source: 'packages/client/ui-session-panel/src/client/slots.ts:50', + source: 'packages/client/ui-session-panel/src/client/slots.ts:37', }, { key: 'conversation.session.panel.section', @@ -2589,7 +2589,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [ ], replaceRisk: 'none', example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.session.panel.section\', () => ctx.slots.register(\n { name: \'conversation.session.panel.section\', id: \'my-entry\', order: 100, label: \'My entry\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}', - source: 'packages/client/ui-session-panel/src/client/slots.ts:35', + source: 'packages/client/ui-session-panel/src/client/slots.ts:22', }, { key: 'conversation.session.panel.section.actions', @@ -2635,7 +2635,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [ occupants: [], replaceRisk: 'none', example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.session.panel.section.actions\', () => ctx.slots.register(\n { name: \'conversation.session.panel.section.actions\', key: \'\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}', - source: 'packages/client/ui-session-panel/src/client/slots.ts:41', + source: 'packages/client/ui-session-panel/src/client/slots.ts:28', }, { key: 'conversation.trajectory.images', diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 75d98df139..fd45dfa3b3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5827,9 +5827,6 @@ importers: '@testing-library/react': specifier: ^16.3.3 version: 16.3.3(@testing-library/dom@10.4.2)(@types/react-dom@18.3.7(@types/react@18.3.31))(@types/react@18.3.31)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) - clsx: - specifier: ^2.0.0 - version: 2.1.1 react: specifier: ^18.2.0 version: 18.3.1 diff --git a/tsconfig.host.json b/tsconfig.host.json index 667142dfc8..b134115dd4 100644 --- a/tsconfig.host.json +++ b/tsconfig.host.json @@ -11,7 +11,7 @@ "snapshots/session/headless.snapshot.ts", "apps/web/tests/home-whale.e2e.ts", "apps/web/tests/sidebar-drawer.e2e.ts", - "apps/web/tests/session-panel-dock.e2e.ts", + "apps/web/tests/session-panel-layout.e2e.ts", "apps/web/tests/creation-recommendations.e2e.ts", "apps/web/tests/plugin-recommendations.e2e.ts", "apps/web/tests/japanese-plugin-metadata.e2e.ts",