From dbd69abfa135f31fbd676240bfeceb542aa4d0da Mon Sep 17 00:00:00 2001 From: LegGasai Date: Fri, 6 Nov 2026 16:52:50 +0800 Subject: [PATCH] fix(panel): measure adopted Sessions and keep the panel overlay transient - The main width controls restart their measurement when the body adopts its first Session, so a Session opened from the blank home reports its gutter without waiting for a resize. - ConversationLayout gains `shown`: the width controls report null when the body stops showing a Session, and a released Session publishes it as not shown before its layout is dropped. Layouts no longer outlive their Session's binding scope. - The overlay follows its Session's layout and closes once the gutter can dock the panel or the body shows another Session, so it never reopens on its own. - Escape is left to an input method composing text, and focus moves to the toggle when the panel hides while it holds focus. - The client inject list names the context menu, Remote, and connection packages the panel reads, the README states Escape priority and the Chat-only gutter, and the Agent Note describes the turn rail as it is. --- .../2026-11-05-session-panel.i18n.yaml | 10 +-- .../feature/2026-11-05-session-panel.md | 6 +- .../feature/2026-11-05-session-panel.zh.md | 6 +- .../client/ui-conversation/README.i18n.yaml | 4 +- packages/client/ui-conversation/README.md | 2 +- packages/client/ui-conversation/README.zh.md | 2 +- .../src/client/contract/slots.ts | 19 +++-- .../src/client/conversation/assembly.ts | 4 +- .../src/client/conversation/layouts.ts | 71 +++++++++++++----- .../skeleton/ConversationWidthControls.tsx | 7 +- .../tests/layouts.client.spec.ts | 75 +++++++++++++++++++ .../tests/skeleton.client.spec.tsx | 29 ++++++- .../client/ui-session-panel/README.i18n.yaml | 4 +- packages/client/ui-session-panel/README.md | 2 +- packages/client/ui-session-panel/README.zh.md | 2 +- packages/client/ui-session-panel/package.json | 4 + .../src/client/SessionPanel.tsx | 45 +++++++++-- .../ui-session-panel/src/client/index.ts | 4 +- .../ui-session-panel/src/client/visibility.ts | 33 +++++++- .../tests/browser-plugin.client.spec.ts | 2 +- .../tests/components.client.spec.tsx | 63 +++++++++++++++- .../tests/visibility.client.spec.ts | 73 +++++++++++++++--- .../client/ui-session-panel/tsconfig.json | 3 + pnpm-lock.yaml | 3 + 24 files changed, 396 insertions(+), 77 deletions(-) create mode 100644 packages/client/ui-conversation/tests/layouts.client.spec.ts 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 4bd1f78eff..8fa5341ff8 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 @@ -12,14 +12,14 @@ en: 547fe8129b027892 zh: dc0807d782f551ae /agent-note-session-panel-over-the-conversation-body-s-end-gutter/decision/docking-follows-the-transcript-gutter: - en: 150a7e8bf3ad556a - zh: c40fcf40af63b353 + en: f406a8821cdc8dc9 + zh: 42178c0188cb0f2b /agent-note-session-panel-over-the-conversation-body-s-end-gutter/decision/sections-are-registrations-the-panel-draws-titles: en: f8e69329e832c764 zh: 2453aa8e794f46f5 -/agent-note-session-panel-over-the-conversation-body-s-end-gutter/decision/the-turn-rail-moves-to-the-start-edge: - en: 05a494885d439fde - zh: 1dc65e5266a9c7b1 +/agent-note-session-panel-over-the-conversation-body-s-end-gutter/decision/the-turn-rail-sits-at-the-start-edge: + en: 08e720a4ea75d4d6 + zh: 5e2e5b8452f67d36 /agent-note-session-panel-over-the-conversation-body-s-end-gutter/alternatives-considered: en: 9cf81cde02bf900b zh: 549d92a260541e3d 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 ca4b96e4ab..5b348b9722 100644 --- a/.agents/notes/implemented/feature/2026-11-05-session-panel.md +++ b/.agents/notes/implemented/feature/2026-11-05-session-panel.md @@ -18,7 +18,7 @@ The panel docks only while the gutter between the transcript column and the body The toggle and the panel read that source and one plugin-owned visibility state and decide the presentation with the same pure function. The toggle therefore reports `aria-expanded` truthfully and knows whether a press flips docking or opens the overlay, which a CSS-only container query cannot tell an element outside the body. -Docking follows one persisted preference shared by every Session and defaults to on. Without room, a press opens a transient overlay for that Session above the transcript and the composer stack; it never changes the preference, and docking from a wide gutter closes it. Hiding automatically and overlaying on request keeps the transcript uncovered without making the facts unreachable on laptop widths. +Docking follows one persisted preference shared by every Session and defaults to on. Without room, a press opens a transient overlay for that Session above the transcript and the composer stack; it never changes the preference, and it closes once its gutter can dock the panel or the main body shows another Session, so it never reappears on its own. The panel state follows the open overlay's layout source, which the Conversation shell marks as no longer shown when the main body leaves the Session, instead of a component cleanup that React's double mount would also run. Hiding automatically and overlaying on request keeps the transcript uncovered without making the facts unreachable on laptop widths. ### Sections are registrations; the panel draws titles @@ -26,9 +26,9 @@ Each section is one list registration with `id`, `order`, and a required `label` Rows from every contributor use the `PanelRow` primitive so icon, text, and trailing areas align across packages; a feature package cannot share its own row component with another feature package. -### The turn rail moves to the start edge +### The turn rail sits at the start edge -The turn rail used the end edge of the scrollport, which the docked panel now occupies. It moves to the start edge with its marks, focus ring, and preview mirrored; its existing 900px hiding rule still guarantees room beside the start-side width handle. +The turn rail sits at the scrollport's start edge with its marks, focus ring, and preview mirrored, leaving the end gutter to the docked panel; its 900px hiding rule guarantees room beside the start-side width handle. ## Alternatives considered 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 136ceff8a0..4c3712e197 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 @@ -18,7 +18,7 @@ Status: implemented 开关和面板读取同一个 source 和同一份插件持有的可见性状态,并用同一个纯函数决定呈现方式。因此开关能如实报告 `aria-expanded`,也知道按下后是切换停靠还是打开浮层;纯 CSS 的容器查询无法把结果告诉正文之外的元素。 -停靠遵循所有会话共用的一个持久化偏好,默认开启。没有空间时,按下开关会为该会话在正文和 composer 区域上方打开临时浮层;它从不改变偏好,宽留白下切换停靠也会关闭浮层。自动隐藏加按需浮层,既保证正文不被遮挡,也让笔记本宽度下的信息依然可达。 +停靠遵循所有会话共用的一个持久化偏好,默认开启。没有空间时,按下开关会为该会话在正文和 composer 区域上方打开临时浮层;它从不改变偏好;该会话的留白可以停靠面板,或主正文切到其他会话时,浮层关闭,因此不会自己重新出现。面板状态跟随打开浮层的会话的布局 source,主正文离开该会话时 Conversation 外壳会把它标记为不再显示;不用组件清理函数实现,因为 React 的双重挂载也会运行它。自动隐藏加按需浮层,既保证正文不被遮挡,也让笔记本宽度下的信息依然可达。 ### 分栏是注册项;面板绘制标题 @@ -26,9 +26,9 @@ Status: implemented 所有贡献方的行都使用 `PanelRow` 原语,使不同包的图标、文字与尾部区域对齐;功能包之间不能共享各自的行组件。 -### 轮次轨道移到起始边 +### 轮次轨道位于起始边 -轮次轨道原先贴在滚动容器末端边缘,停靠面板现在占用这里。轨道连同刻度、焦点环和预览镜像到起始边;原有的 900px 隐藏规则仍保证它旁边有足够空间容纳起始侧的宽度拖拽条。 +轮次轨道连同刻度、焦点环和预览位于滚动容器的起始边,末端留白留给停靠面板;它的 900px 隐藏规则保证旁边有足够空间容纳起始侧的宽度拖拽条。 ## Alternatives considered diff --git a/packages/client/ui-conversation/README.i18n.yaml b/packages/client/ui-conversation/README.i18n.yaml index 06d21c9a63..cab118cd76 100644 --- a/packages/client/ui-conversation/README.i18n.yaml +++ b/packages/client/ui-conversation/README.i18n.yaml @@ -21,8 +21,8 @@ en: cc4dafd1aae02468 zh: be6b67724b7ac4a3 /deepseek-ai-dsh-client-ui-conversation/shell-and-standard-props: - en: 1d9c21bd934d1a3b - zh: 3c47d27ea72b2a2e + en: 1939628ccfabb23d + zh: b0882827f338cf8c /deepseek-ai-dsh-client-ui-conversation/temporary-composer-entries: en: 59cd63057dfb6eeb zh: b2e2c86e810b7bb8 diff --git a/packages/client/ui-conversation/README.md b/packages/client/ui-conversation/README.md index 25bc4dab22..7a3bf52c8a 100644 --- a/packages/client/ui-conversation/README.md +++ b/packages/client/ui-conversation/README.md @@ -120,7 +120,7 @@ Active transcripts in the main occurrence expose content-width drag handles in t The width-handle indicator follows the pointer only during a captured drag; ordinary hover leaves its position unchanged. -The main occurrence of an active Session also renders the `conversation.session.panel` seat inside its body, beside the width handles and outside the scrollport; embedded occurrences and the blank home omit it. Its occupant positions itself against the body, which carries the transcript axis and the composer stack height `--dsh-composer-height`. `ctx.uiConversation.layouts.source(sessionId)` publishes that Session's `ConversationLayout`: `endGutter` is the space between the transcript column's end edge and the body's end edge, written by the main width controls after each measurement and drag frame and reset to zero when they unmount. It stays zero while a View other than Chat, which fills the body, is active. +The main occurrence of an active Session also renders the `conversation.session.panel` seat inside its body, beside the width handles and outside the scrollport; embedded occurrences and the blank home omit it. Its occupant positions itself against the body, which carries the transcript axis and the composer stack height `--dsh-composer-height`. `ctx.uiConversation.layouts.source(sessionId)` publishes that Session's `ConversationLayout`: `endGutter` is the space between the transcript column's end edge and the body's end edge, written by the main width controls after each measurement and drag frame, again when the body adopts its first Session, and reset to zero when they stop showing the Session; `shown` says whether the main body shows the Session. The gutter stays zero while a View other than the shipped Chat View (`chat`) is active, because those Views fill the body; a View registered under another id reads zero as well. A Session's layout is dropped when its binding scope is released. The resident composer survives no-Session and Session transitions. Whitespace hides its placeholder; a whitespace-only draft without attachments cannot be sent. The no-Session state keeps the same composer surface mounted but inert while the Workspace picker connects a blank Session. The surface is a shell-owned Lexical editor: reference chips are atomic decorator nodes carrying the owner's serialization identity (submission expands them through the owner codec), the claimed slash command is an atomic leading chip that carries its claim, folder text references carry the folder glyph as an icon prefix, and the draft's text and semantic references are persisted by the per-Session Conversation store. QueueDock reads `next-turn` from the Session `inbox` projection, including cold recovered messages, and excludes only requestIds still owned by local transcript submissions. Other queued rows retain their normal display and actions. Queue operations address exact queue occurrences through the scoped `ctx.conversation` service; queue previews use the [UserText Factory](#sent-user-text) (wire session forms fold to their label) and show local or durable images and files in original attachment order. Images use thumbnails; files use compact name-and-size cards. An edit exposes the literal sent text in the ui-primitives `InlineEditor`, so line breaks survive re-editing. Durable thumbnails resolve through the session image URL cache. Busy Enter behavior is stored in the Host-backed `ui-conversation` settings namespace. The composer keymap arbitrates the trigger menu's keys through the slash pipeline — Tab settles the highlighted completion (or drills a drillable one), Escape and Shift+Tab leave the menu without settling — and leaves every other key to the editor. An overlay that takes the keyboard hands it back through `SessionInput.focus()`, which rides Lexical's own focus so the caret returns where the draft left it rather than at the start. diff --git a/packages/client/ui-conversation/README.zh.md b/packages/client/ui-conversation/README.zh.md index 8f9964211f..90ae97ed3c 100644 --- a/packages/client/ui-conversation/README.zh.md +++ b/packages/client/ui-conversation/README.zh.md @@ -120,7 +120,7 @@ Session 首次绑定或缓存的 Session 成为 current 时,shell 会在渲染 宽度拖拽条的指示线只在已捕获指针的拖拽期间跟随指针,普通悬停不改变其位置。 -活跃 Session 的主 occurrence 还会在正文内渲染 `conversation.session.panel` 落位,与宽度拖拽条同层,位于滚动容器之外;嵌入式 occurrence 和空白首页不渲染它。占位组件相对正文定位,正文持有正文轴线与 composer 区域高度 `--dsh-composer-height`。`ctx.uiConversation.layouts.source(sessionId)` 发布该 Session 的 `ConversationLayout`:`endGutter` 是正文列末端边缘到正文末端边缘的距离,由主宽度控件在每次测量与拖拽帧后写入,控件卸载时归零。激活的是 Chat 以外的 View(这类 View 占满正文)时,它保持为零。 +活跃 Session 的主 occurrence 还会在正文内渲染 `conversation.session.panel` 落位,与宽度拖拽条同层,位于滚动容器之外;嵌入式 occurrence 和空白首页不渲染它。占位组件相对正文定位,正文持有正文轴线与 composer 区域高度 `--dsh-composer-height`。`ctx.uiConversation.layouts.source(sessionId)` 发布该 Session 的 `ConversationLayout`:`endGutter` 是正文列末端边缘到正文末端边缘的距离,由主宽度控件在每次测量与拖拽帧后写入,正文接上第一个 Session 时也会写入一次,不再显示该 Session 时归零;`shown` 表示主正文当前是否显示该 Session。激活的是内置 Chat View(`chat`)以外的 View 时留白保持为零,因为这类 View 占满正文;以其他 id 注册的 View 同样读到零。Session 的绑定 scope 释放时,它的布局随之丢弃。 常驻 composer 在无 Session 与有 Session 之间保持挂载。输入空白字符会隐藏占位提示;没有附件的纯空白草稿无法发送。无 Session 时,同一个编辑器表面保持 inert,Workspace picker 连接 blank Session。该表面是 shell 所有的 Lexical 编辑器:引用 chip 是携带 owner 序列化身份的原子 decorator 节点(提交时经 owner codec 展开),已认领的 slash command 是携带认领的行首原子 chip,文件夹文本引用以图标前缀携带文件夹图形,草稿文字和引用语义字段由逐 Session Conversation store 持久化。QueueDock 从 Session 的 `inbox` 投影读取 `next-turn`,包含从冷状态恢复的消息,仅排除仍由本地 transcript 提交承接的 requestId。其他排队行保留正常展示和操作。Queue 操作通过 scoped `ctx.conversation` service 寻址准确的 queue occurrence;queue 预览使用 [UserText Factory](#sent-user-text)(wire 会话形式折叠为其标签),并按原始附件顺序展示本地或持久化的图片和文件。图片使用缩略图,文件使用紧凑的名称与大小卡片。编辑态在 ui-primitives 的 `InlineEditor` 中展示字面发送文本,因此重新编辑不会丢失换行。持久化缩略图通过会话图片 URL 缓存解析。繁忙时 Enter 行为保存在 Host-backed `ui-conversation` settings namespace。 composer 键盘映射经斜杠流水线裁决触发菜单的按键——Tab 确认高亮补全项(可下钻项则下钻),Escape 与 Shift+Tab 离开菜单且不选定——其余按键交给编辑器自身。 接管键盘的浮层通过 `SessionInput.focus()` 把键盘还回来,该路径走 Lexical 自己的 focus,因此光标回到草稿原来的位置而不是开头。 diff --git a/packages/client/ui-conversation/src/client/contract/slots.ts b/packages/client/ui-conversation/src/client/contract/slots.ts index 9dbe00d8bb..d0520f411b 100644 --- a/packages/client/ui-conversation/src/client/contract/slots.ts +++ b/packages/client/ui-conversation/src/client/contract/slots.ts @@ -443,9 +443,12 @@ export interface ConversationLayout { * Inline space in CSS px between the transcript column's end edge and the * body's end edge. Zero before the first measurement, while the main body * shows another Session, and while the active View does not follow the - * transcript column (every View other than Chat). + * transcript column. Only the shipped Chat View (`chat`) follows it; a View + * registered under another id, and any View that fills the body, reads zero. */ readonly endGutter: number + /** Whether the main Conversation body currently shows the Session. */ + readonly shown: boolean } /** The header corner's occupant derives its state from standard Session props. */ @@ -500,9 +503,10 @@ export interface ConversationInjected { /** * Record the end gutter the main body measured for this occurrence's Session; * no effect without a Session. - * @param endGutter - space between the transcript column's end edge and the body's end edge, in CSS px. + * @param endGutter - space between the transcript column's end edge and the body's end edge, in CSS px; + * null when the body stops showing the Session. */ - reportEndGutter: (endGutter: number) => void + reportEndGutter: (endGutter: number | null) => void } /** Business callbacks injected into the strict Session body. */ @@ -696,11 +700,12 @@ export interface ConversationWidthControlsInputProps { /** Current body phase; handles render only for an active transcript. */ phase: ConversationContentInputProps['phase'] /** - * Receive the end gutter after each measurement and drag frame, and zero when - * the controls unmount. - * @param endGutter - space between the transcript column's end edge and the body's end edge, in CSS px. + * Receive the end gutter after each measurement and drag frame, and null when + * the controls unmount or a new callback replaces this one. + * @param endGutter - space between the transcript column's end edge and the body's end edge, in CSS px; + * null when the body stops showing the Session. */ - onEndGutter: (endGutter: number) => void + onEndGutter: (endGutter: number | null) => void } /** Full props of the reusable Conversation Factory definition. */ diff --git a/packages/client/ui-conversation/src/client/conversation/assembly.ts b/packages/client/ui-conversation/src/client/conversation/assembly.ts index d879921d9b..91348340d9 100644 --- a/packages/client/ui-conversation/src/client/conversation/assembly.ts +++ b/packages/client/ui-conversation/src/client/conversation/assembly.ts @@ -213,7 +213,7 @@ export class UiConversation extends Service { /** Plugin-owned handlers for selection and context-menu gestures. */ readonly interactions: ConversationInteractionRegistry /** Main Conversation body geometry per Session; the Conversation shell writes it and floating chrome reads it. */ - readonly layouts: ConversationLayouts = new ConversationLayouts() + readonly layouts: ConversationLayouts private readonly bindings = new WeakMapWithValues() private readonly images: HistoricalImageCache @@ -229,6 +229,7 @@ export class UiConversation extends Service { this.userText = new UserTextRegistry(ctx) this.interactions = new ConversationInteractionRegistry(ctx) this.images = new HistoricalImageCache(ctx, sessions) + this.layouts = new ConversationLayouts(sessionId => sessions.binding(sessionId)?.ctx) const rebuild = (): void => { for (const record of this.bindings.values) record.binding.rebuild() } @@ -250,6 +251,7 @@ export class UiConversation extends Service { disposeViews() disposeEvents() for (const record of [...this.bindings.values]) this.drop(record, true) + this.layouts.dispose() } }, 'ui-conversation assembly') } diff --git a/packages/client/ui-conversation/src/client/conversation/layouts.ts b/packages/client/ui-conversation/src/client/conversation/layouts.ts index 9caa7c35cf..5923c4ad39 100644 --- a/packages/client/ui-conversation/src/client/conversation/layouts.ts +++ b/packages/client/ui-conversation/src/client/conversation/layouts.ts @@ -1,46 +1,62 @@ /** Per-Session geometry of the main Conversation body, published through `ctx.uiConversation.layouts`. */ +import type { Context } from '@deepseek-ai/cordis' import { createSnapshotStore, type ObservableSnapshot, type SnapshotStore } from '@deepseek-ai/dsh-client-store' import type { SessionId } from '@deepseek-ai/dsh-session/types' import type { ConversationLayout } from '../contract/slots.ts' -const NO_LAYOUT: ConversationLayout = Object.freeze({ endGutter: 0 }) +const NO_LAYOUT: ConversationLayout = Object.freeze({ endGutter: 0, shown: false }) interface LayoutEntry { /** Last end gutter the main body's width controls measured, in CSS px. */ measured: number + /** Whether the main body shows the Session. */ + shown: boolean /** Whether the Session's active View follows the transcript column; false before the first activation. */ followsTranscript: boolean readonly store: SnapshotStore + /** Withdraw the release registered on the Session's scope. */ + release: () => void } /** - * Layout facts of the main Conversation body, kept per Session for the - * lifetime of the Conversation plugin. The Conversation shell writes them: - * the main body's width controls report the measured end gutter, and View - * activation reports whether the active View follows the transcript column. - * The published gutter is zero while it does not, because such a View fills - * the body. Floating chrome reads one Session's facts through `source`. + * Layout facts of the main Conversation body, kept per Session until the + * Session's binding scope is released. The Conversation shell writes them: + * the main body's width controls report the measured end gutter and when the + * body stops showing the Session, and View activation reports whether the + * active View follows the transcript column (only Chat does). The published + * gutter is zero while it does not, because such a View fills the body. + * Floating chrome reads one Session's facts through `source`. */ export class ConversationLayouts { private readonly entries = new Map() + /** + * @param scopeOf - the binding scope of a Session, whose release drops the + * Session's layout; undefined keeps the layout until `dispose`. + */ + constructor(private readonly scopeOf: (sessionId: SessionId) => Context | undefined) {} + /** * Read one Session's layout source. * @param sessionId - Session whose main body geometry is read. - * @returns a source whose identity is stable per Session and whose snapshot keeps its identity until the gutter changes. + * @returns a source whose identity is stable while the Session stays bound and whose snapshot keeps its identity until a fact changes. */ source(sessionId: SessionId): ObservableSnapshot { return this.entryOf(sessionId).store } /** - * Record the end gutter the main body measured while showing a Session. - * @param sessionId - Session the main body shows. - * @param endGutter - space between the transcript column's end edge and the body's end edge, in CSS px. + * Record the end gutter the main body measured while showing a Session, or that it stopped showing it. + * @param sessionId - Session the main body shows or showed. + * @param endGutter - space between the transcript column's end edge and the body's end edge, in CSS px; + * null when the body stops showing the Session. */ - measure(sessionId: SessionId, endGutter: number): void { + measure(sessionId: SessionId, endGutter: number | null): void { + // A Session already released is not shown; recording that would only recreate its entry. + if (endGutter === null && !this.entries.has(sessionId)) return const entry = this.entryOf(sessionId) - entry.measured = Math.max(0, endGutter) + entry.shown = endGutter !== null + entry.measured = endGutter === null ? 0 : Math.max(0, endGutter) this.publish(entry) } @@ -55,18 +71,35 @@ export class ConversationLayouts { this.publish(entry) } + /** Drop every Session's layout and withdraw the releases registered on their scopes. */ + dispose(): void { + for (const entry of [...this.entries.values()]) entry.release() + this.entries.clear() + } + private entryOf(sessionId: SessionId): LayoutEntry { - let entry = this.entries.get(sessionId) - if (entry === undefined) { - entry = { measured: 0, followsTranscript: false, store: createSnapshotStore(NO_LAYOUT) } - this.entries.set(sessionId, entry) + const existing = this.entries.get(sessionId) + if (existing !== undefined) return existing + const entry: LayoutEntry = { + measured: 0, shown: false, followsTranscript: false, store: createSnapshotStore(NO_LAYOUT), release: () => {}, + } + this.entries.set(sessionId, entry) + const scope = this.scopeOf(sessionId) + if (scope !== undefined) { + // Readers holding the source learn that a released Session is no longer shown. + const dispose = scope.effect(() => () => { + this.entries.delete(sessionId) + entry.store.set(NO_LAYOUT) + }, 'ui-conversation layout') + entry.release = () => { void dispose() } } return entry } private publish(entry: LayoutEntry): void { const endGutter = entry.followsTranscript ? entry.measured : 0 - if (entry.store.getSnapshot().endGutter === endGutter) return - entry.store.set(endGutter === 0 ? NO_LAYOUT : { endGutter }) + const current = entry.store.getSnapshot() + if (current.endGutter === endGutter && current.shown === entry.shown) return + entry.store.set(endGutter === 0 && !entry.shown ? NO_LAYOUT : { endGutter, shown: entry.shown }) } } diff --git a/packages/client/ui-conversation/src/client/skeleton/ConversationWidthControls.tsx b/packages/client/ui-conversation/src/client/skeleton/ConversationWidthControls.tsx index 1b35ee6137..63c08829a3 100644 --- a/packages/client/ui-conversation/src/client/skeleton/ConversationWidthControls.tsx +++ b/packages/client/ui-conversation/src/client/skeleton/ConversationWidthControls.tsx @@ -152,6 +152,9 @@ export function ConversationWidthControls({ container, phase, onEndGutter }: Con report.current((column - resolveContentWidth(column, preference)) / 2) }, []) + // A new callback means the body adopted a Session without remounting or + // resizing: the measurement restarts so that Session gets the current gutter, + // and the callback it replaces receives its final zero. useLayoutEffect(() => { if (container === null) return const observer = new ResizeObserver(() => { publishWidths(container) }) @@ -159,9 +162,9 @@ export function ConversationWidthControls({ container, phase, onEndGutter }: Con publishWidths(container) return () => { observer.disconnect() - report.current(0) + onEndGutter(null) } - }, [container, publishWidths]) + }, [container, onEndGutter, publishWidths]) const onStart = useCallback((): number => { if (container === null) return 680 diff --git a/packages/client/ui-conversation/tests/layouts.client.spec.ts b/packages/client/ui-conversation/tests/layouts.client.spec.ts new file mode 100644 index 0000000000..792fe539b4 --- /dev/null +++ b/packages/client/ui-conversation/tests/layouts.client.spec.ts @@ -0,0 +1,75 @@ +import { Context } from '@deepseek-ai/cordis' +import type { SessionId } from '@deepseek-ai/dsh-session/types' +import { describe, expect, it } from 'vitest' +import { ConversationLayouts } from '../src/client/conversation/layouts.ts' + +const S1 = 's1' as SessionId +const S2 = 's2' as SessionId + +describe('ConversationLayouts', () => { + it('publishes the measured gutter and whether the body shows the Session, while Chat is active', () => { + const layouts = new ConversationLayouts(() => undefined) + const source = layouts.source(S1) + expect(source.getSnapshot()).toEqual({ endGutter: 0, shown: false }) + layouts.measure(S1, 400) + // Before a View activates, nothing follows the transcript column. + expect(source.getSnapshot()).toEqual({ endGutter: 0, shown: true }) + layouts.activate(S1, true) + expect(source.getSnapshot()).toEqual({ endGutter: 400, shown: true }) + layouts.measure(S1, -5) + expect(source.getSnapshot()).toEqual({ endGutter: 0, shown: true }) + layouts.measure(S1, 360) + layouts.activate(S1, false) + expect(source.getSnapshot()).toEqual({ endGutter: 0, shown: true }) + layouts.activate(S1, true) + layouts.measure(S1, null) + expect(source.getSnapshot()).toEqual({ endGutter: 0, shown: false }) + expect(layouts.source(S2).getSnapshot()).toEqual({ endGutter: 0, shown: false }) + }) + + it('keeps the snapshot identity until a fact changes and notifies only on changes', () => { + const layouts = new ConversationLayouts(() => undefined) + const source = layouts.source(S1) + layouts.activate(S1, true) + layouts.measure(S1, 400) + const first = source.getSnapshot() + let notified = 0 + const off = source.subscribe(() => { notified += 1 }) + layouts.measure(S1, 400) + layouts.activate(S1, true) + expect(source.getSnapshot()).toBe(first) + expect(notified).toBe(0) + layouts.measure(S1, 380) + expect(notified).toBe(1) + off() + }) + + it('drops a Session layout when its scope is released, and every layout on dispose', async () => { + const root = new Context() + const one = root.plugin(() => {}) + const two = root.plugin(() => {}) + await Promise.all([one, two]) + const scopes = new Map([[S1, one], [S2, two]]) + const layouts = new ConversationLayouts(sessionId => scopes.get(sessionId)?.ctx) + const first = layouts.source(S1) + expect(layouts.source(S1)).toBe(first) + layouts.activate(S1, true) + layouts.measure(S1, 400) + const seen: unknown[] = [] + first.subscribe(() => { seen.push(first.getSnapshot()) }) + // A released Session no longer resolves a binding scope, and its readers see it hidden. + await scopes.get(S1)?.dispose() + scopes.delete(S1) + expect(seen).toEqual([{ endGutter: 0, shown: false }]) + // The body's final report after the release recreates nothing. + layouts.measure(S1, null) + expect(layouts.source(S1)).not.toBe(first) + expect(layouts.source(S1).getSnapshot()).toEqual({ endGutter: 0, shown: false }) + const second = layouts.source(S2) + layouts.dispose() + expect(layouts.source(S2)).not.toBe(second) + // A Session without a scope keeps its layout until dispose. + const unscoped = layouts.source('s3' as SessionId) + expect(layouts.source('s3' as SessionId)).toBe(unscoped) + }) +}) diff --git a/packages/client/ui-conversation/tests/skeleton.client.spec.tsx b/packages/client/ui-conversation/tests/skeleton.client.spec.tsx index c82b03cb77..69de5bd9f8 100644 --- a/packages/client/ui-conversation/tests/skeleton.client.spec.tsx +++ b/packages/client/ui-conversation/tests/skeleton.client.spec.tsx @@ -22,6 +22,7 @@ import { createConversationStore } from '../src/client/stores.ts' import { SessionInputShell } from '../src/client/input/facade.ts' import { en, zh } from '../src/client/locales.ts' import { ConversationContent } from '../src/client/skeleton/ConversationContent.tsx' +import { ConversationWidthControls } from '../src/client/skeleton/ConversationWidthControls.tsx' import { ConversationHeader } from '../src/client/skeleton/ConversationHeader.tsx' import { ConversationMainPanel } from '../src/client/skeleton/ConversationMainPanel.tsx' import { ConversationSession, ConversationSessionHeader } from '../src/client/skeleton/ConversationSession.tsx' @@ -33,7 +34,7 @@ import type { InputBarProps } from '../src/client/skeleton/InputBar.tsx' import type { ComposerBarOwnerProps, ConversationContentInputProps, ConversationContentProps, ConversationHeaderLineageOwnerProps, ConversationSessionHeaderSlotProps, ConversationSessionSlotProps, ConversationSlotProps, - ConversationViewActionsOwnerProps, ConversationViewsProps, HeroFrameOwnerProps, + ConversationViewActionsOwnerProps, ConversationViewsProps, HeroFrameOwnerProps, ConversationWidthControlsProps, } from '../src/client/contract/slots.ts' import type { ViewTab } from '../src/client/contract/views.ts' @@ -207,7 +208,7 @@ function mount( let actionsOwner: ConversationViewActionsOwnerProps | undefined const setPinned = vi.fn<(id: string, pinned: boolean) => void>() /** End gutters the main width controls reported, in order. */ - const gutters: number[] = [] + const gutters: (number | null)[] = [] const renderSlot = ((key: string, owner: object, opts?: { only?: string; fallback?: ReactNode; children?: ReactNode }) => { slotCalls.push(key) if (key === 'conversation.input.model' || key === 'conversation.input.plan') { @@ -1084,7 +1085,7 @@ describe('ConversationRoot resident composer', () => { expect(b.view.container.querySelector('[data-width-handle]')).toBeNull() }) - it('reports the end gutter after each measurement and drag frame, and zero on unmount', () => { + it('reports the end gutter after each measurement and drag frame, and that it stops showing the Session on unmount', () => { const b = mount(sessionSnapshotOf()) const content = b.view.container.querySelector('[data-conversation-content]') as HTMLElement Object.defineProperty(content, 'offsetWidth', { value: 1600, configurable: true }) @@ -1111,7 +1112,27 @@ describe('ConversationRoot resident composer', () => { } } b.view.unmount() - expect(b.gutters.at(-1)).toBe(0) + expect(b.gutters.at(-1)).toBeNull() + }) + + it('reports the end gutter to a newly adopted Session without a resize, and only once per callback', () => { + const body = document.createElement('div') + document.body.append(body) + Object.defineProperty(body, 'offsetWidth', { value: 1600, configurable: true }) + const props = (onEndGutter: (gutter: number | null) => void) => ({ container: body, phase: 'active', onEndGutter }) as + Pick as ConversationWidthControlsProps + const blank = vi.fn<(gutter: number | null) => void>() + const adopted = vi.fn<(gutter: number | null) => void>() + const view = render() + expect(blank).toHaveBeenLastCalledWith(340) + view.rerender() + expect(blank).toHaveBeenLastCalledWith(null) + expect(adopted.mock.calls).toEqual([[340]]) + view.rerender() + expect(adopted).toHaveBeenCalledOnce() + view.unmount() + expect(adopted).toHaveBeenLastCalledWith(null) + body.remove() }) it('renders the Session panel seat only for the main occurrence of an active Session', () => { diff --git a/packages/client/ui-session-panel/README.i18n.yaml b/packages/client/ui-session-panel/README.i18n.yaml index 0d5adc4dd8..f907fc7722 100644 --- a/packages/client/ui-session-panel/README.i18n.yaml +++ b/packages/client/ui-session-panel/README.i18n.yaml @@ -18,8 +18,8 @@ en: d7818d67e981be3c zh: c7c0c704d5ef8b34 /deepseek-ai-dsh-client-ui-session-panel/use-this-package/docking-and-the-overlay: - en: 1d99ccdba0457d10 - zh: 81833d87548d3225 + en: c10ebd54b9412ac1 + zh: a5e878ab049c44a9 /deepseek-ai-dsh-client-ui-session-panel/use-this-package/contribute-a-section: en: 46c0aa93bceeaf0d zh: 478acadcd8828db6 diff --git a/packages/client/ui-session-panel/README.md b/packages/client/ui-session-panel/README.md index f0ce954d68..776ac127d0 100644 --- a/packages/client/ui-session-panel/README.md +++ b/packages/client/ui-session-panel/README.md @@ -31,7 +31,7 @@ The `@deepseek-ai/dsh-web-app` bundle loads this package by default. The toggle The panel docks while the gutter between the transcript column and the body's end edge is at least 344px: 48px clear of the column and its width handle, the panel's 280px minimum width, and a 16px edge margin. Docked, it is 280–340px wide, starts 12px below the header, and scrolls inside itself. Pressing the toggle then flips one docking preference that every Session shares and that persists in `localStorage` under `dsh.sessionPanel.pinned`; the panel docks by default. -A narrower gutter hides the docked panel, so it never covers the transcript. This includes a narrow window, an expanded right sidebar, a dragged-wide transcript column, and every View other than Chat, because those Views fill the body. Pressing the toggle then opens the panel over the transcript with the prominent elevation, above the composer stack and not covering it. The overlay closes from the toggle, on Escape, and on a pointer press outside the panel, the toggle, and any open menu, such as a row's context menu; Escape returns focus to the toggle when focus was inside the panel, and a modal above the page keeps Escape. Closing it does not change the docking preference. At most one Session's overlay is open, and docking from a wide gutter closes it. +A narrower gutter hides the docked panel, so it never covers the transcript. This includes a narrow window, an expanded right sidebar, a dragged-wide transcript column, and every View other than Chat, because those Views fill the body. Pressing the toggle then opens the panel over the transcript with the prominent elevation, above the composer stack and not covering it. The overlay closes from the toggle, on Escape, and on a pointer press outside the panel, the toggle, and any open menu, such as a row's context menu; Escape returns focus to the toggle when focus was inside the panel. A modal above the page, an input method composing text, and a handler that already took the key, such as an open menu's, keep Escape; otherwise the overlay takes it first, so with the overlay open the first Escape from the composer closes the overlay and does not count toward stopping a running turn. Closing it does not change the docking preference. At most one Session's overlay is open; it closes once the gutter widens enough to dock and once the main body shows another Session, and switching back does not reopen it. When the panel hides while focus is inside it, focus moves to the toggle. ### Contribute a section diff --git a/packages/client/ui-session-panel/README.zh.md b/packages/client/ui-session-panel/README.zh.md index 86b6f8b12c..92130c15d4 100644 --- a/packages/client/ui-session-panel/README.zh.md +++ b/packages/client/ui-session-panel/README.zh.md @@ -31,7 +31,7 @@ kind: "package-reference" 正文列到对话区末端边缘的留白不少于 344px 时,面板停靠:与正文列及其宽度手柄保持 48px 间距,面板最小宽度 280px,外加 16px 边距。停靠时面板宽 280–340px,位于标题栏下方 12px,内容在面板内滚动。此时按开关会切换所有会话共用的停靠偏好,偏好存放在 `localStorage` 的 `dsh.sessionPanel.pinned` 中;默认停靠。 -留白更窄时隐藏停靠面板,保证不遮挡正文。窗口变窄、展开右侧栏、把正文列拖宽,以及切换到 Chat 以外的视图(这些视图占满对话区)都会如此。此时按开关,面板以更强的阴影浮在正文上方,位于输入框区域之上,且不遮挡输入框。浮层可以用开关关闭,也会在按 Esc 时,或在面板、开关和任何已打开的菜单(例如行的上下文菜单)之外按下指针时关闭;焦点原本在面板内时,按 Esc 后焦点回到开关,页面上方有模态框时 Esc 归模态框处理。关闭浮层不改变停靠偏好。同一时间最多一个会话的浮层处于打开状态,在宽留白下切换停靠也会关闭它。 +留白更窄时隐藏停靠面板,保证不遮挡正文。窗口变窄、展开右侧栏、把正文列拖宽,以及切换到 Chat 以外的视图(这些视图占满对话区)都会如此。此时按开关,面板以更强的阴影浮在正文上方,位于输入框区域之上,且不遮挡输入框。浮层可以用开关关闭,也会在按 Esc 时,或在面板、开关和任何已打开的菜单(例如行的上下文菜单)之外按下指针时关闭;焦点原本在面板内时,按 Esc 后焦点回到开关。页面上方有模态框、输入法正在组字,或已有处理程序(例如打开的菜单)接手了这次按键时,Esc 不归浮层;其余情况由浮层先处理,因此浮层打开时,在输入框按下的第一次 Esc 只关闭浮层,不计入停止当前轮次的连按。关闭浮层不改变停靠偏好。同一时间最多一个会话的浮层处于打开状态;留白变宽到可以停靠时,以及主正文切到其他会话时,浮层都会关闭,切回来也不会重新打开。面板隐藏时如果焦点在面板内,焦点移到开关。 ### 贡献分栏 diff --git a/packages/client/ui-session-panel/package.json b/packages/client/ui-session-panel/package.json index 44aa1ebc95..a67d989b2a 100644 --- a/packages/client/ui-session-panel/package.json +++ b/packages/client/ui-session-panel/package.json @@ -39,6 +39,7 @@ "@deepseek-ai/dsh-api-remotes": "workspace:*", "@deepseek-ai/dsh-api-session-controller": "workspace:*", "@deepseek-ai/dsh-api-workspace-controller": "workspace:*", + "@deepseek-ai/dsh-client-connection": "workspace:*", "@deepseek-ai/dsh-client-locale": "workspace:*", "@deepseek-ai/dsh-client-store": "workspace:*", "@deepseek-ai/dsh-client-test-runtime": "workspace:*", @@ -68,7 +69,10 @@ "dsh": { "client": { "inject": [ + "@deepseek-ai/dsh-api-remotes", + "@deepseek-ai/dsh-client-connection", "@deepseek-ai/dsh-client-locale", + "@deepseek-ai/dsh-client-ui-context-menu", "@deepseek-ai/dsh-client-ui-conversation", "@deepseek-ai/dsh-client-ui-primitives" ], diff --git a/packages/client/ui-session-panel/src/client/SessionPanel.tsx b/packages/client/ui-session-panel/src/client/SessionPanel.tsx index ffe655bc7d..39ff023b89 100644 --- a/packages/client/ui-session-panel/src/client/SessionPanel.tsx +++ b/packages/client/ui-session-panel/src/client/SessionPanel.tsx @@ -1,6 +1,6 @@ /** Floating Session panel: section titles drawn from the section roster, bodies from the section slot. */ -import { useCallback, useEffect, useMemo, useRef, type ReactNode } from 'react' -import { isBehindModal } from '@deepseek-ai/dsh-client-ui-primitives' +import { useCallback, useEffect, useMemo, useRef, type FocusEvent, type ReactNode } from 'react' +import { isBehindModal, observeComposition } from '@deepseek-ai/dsh-client-ui-primitives' import { panelElementId, toggleElementId } from './element-ids.ts' import type { SessionPanelProps, SessionPanelSectionOwnerProps } from './slots.ts' import { fitsLayout, presentationOf } from './visibility.ts' @@ -8,9 +8,10 @@ import css from './SessionPanel.module.css' /** * Close the overlay on Escape and on a pointerdown outside the panel. The - * toggle and open menus, such as a row's context menu, count as inside, and a - * modal above the page keeps Escape. Escape returns focus to the toggle when - * focus was inside the panel. + * toggle and open menus, such as a row's context menu, count as inside; a + * modal above the page and an input method composing text keep Escape, as + * does a handler that already took it. Escape returns focus to the toggle + * when focus was inside the panel. * @param panel - the overlay element. * @param open - whether the overlay shows; false detaches the listeners. * @param toggleId - id of the Session's toggle. @@ -19,6 +20,7 @@ import css from './SessionPanel.module.css' function useOverlayDismissal(panel: { readonly current: HTMLElement | null }, open: boolean, toggleId: string, close: () => void): void { useEffect(() => { if (!open) return + const composition = observeComposition(document) const inside = (target: EventTarget | null): boolean => target instanceof Element && ( panel.current?.contains(target) === true || document.getElementById(toggleId)?.contains(target) === true @@ -28,7 +30,7 @@ function useOverlayDismissal(panel: { readonly current: HTMLElement | null }, op if (!inside(event.target)) close() } const onKeyDown = (event: KeyboardEvent): void => { - if (event.key !== 'Escape' || event.defaultPrevented || isBehindModal(panel.current)) return + if (event.key !== 'Escape' || composition.guards(event) || event.defaultPrevented || isBehindModal(panel.current)) return event.preventDefault() const focused = panel.current?.contains(document.activeElement) === true close() @@ -39,10 +41,38 @@ function useOverlayDismissal(panel: { readonly current: HTMLElement | null }, op return () => { document.removeEventListener('pointerdown', onPointerDown) document.removeEventListener('keydown', onKeyDown) + composition.dispose() } }, [panel, open, toggleId, close]) } +/** + * Hand focus to the toggle when the panel hides with the keyboard inside it, + * as when a narrower gutter hides the docked panel: the focused control is + * gone and the toggle is the control that brings it back. + * @param hidden - whether the panel renders nothing. + * @param toggleId - id of the Session's toggle. + * @returns focus handlers for the panel element. + */ +function useFocusReturn(hidden: boolean, toggleId: string): { + readonly onFocus: () => void + readonly onBlur: (event: FocusEvent) => void +} { + const inside = useRef(false) + useEffect(() => { + if (!hidden || !inside.current) return + inside.current = false + document.getElementById(toggleId)?.focus({ preventScroll: true }) + }, [hidden, toggleId]) + return useMemo(() => ({ + onFocus: () => { inside.current = true }, + onBlur: (event) => { + // Removal can report no next target; only a move to another element leaves the panel. + if (event.relatedTarget instanceof Element && !event.currentTarget.contains(event.relatedTarget)) inside.current = false + }, + }), []) +} + /** * Render the panel while it docks or shows as an overlay. Each section keeps * its title row and body; CSS hides a section whose body rendered nothing. @@ -63,6 +93,7 @@ export function SessionPanel({ : { presentation, dismissOverlay }, [presentation, dismissOverlay]) useOverlayDismissal(panel, presentation === 'overlay', toggleElementId(sessionId), dismissOverlay) + const focus = useFocusReturn(owner === undefined, toggleElementId(sessionId)) if (owner === undefined) return null return (