refactor(session-panel): size the panel in CSS and render only when the dock decision changes

The aside layer now publishes its end gutter through an observable source
instead of React state, so neither resizes nor transcript updates re-render
it. The panel's docked width comes from --dsh-chat-content-width in CSS, and
the panel and its toggle subscribe only to whether the gutter holds the
docked panel; a mounted panel registers its source with the shared state
instead of pushing measured gutters from an effect.
This commit is contained in:
LegGasai committed 2026-11-13 11:17:14 +08:00
1 parent 94a2639e05
commit 6af99291a8
19 files changed
+264 -212

No files matched your search

+2 -2
View File
@@ -39,8 +39,8 @@
en: f6d8bbae13a1a8f8
zh: 96c8f400c215e33d
/deepseek-ai-dsh-client-ui-chat/scroll-ownership:
en: 983f27806146e9ea
zh: bb60333c7a6736ed
en: 26d32be41a7bb8af
zh: 3a5f8a10ec8a271f
/deepseek-ai-dsh-client-ui-chat/model-experience:
en: c17b4dd43a61c569
zh: f7414309810c3a08
+1 -1
View File
@@ -160,7 +160,7 @@ Chat restores semantic anchors across history prepend and renderer remounts, wit
The turn rail and back-to-bottom button sit outside the clipped transcript. They use the shared conversation scrollport for sticky positioning, or the Chat frame for absolute positioning when Chat owns its scrollport. The rail sits at the scrollport's start edge, which leaves the end gutter to the [Session panel](../ui-session-panel/README.md), and its previews open toward the transcript. The rail hides when the transcript's available width, excluding its horizontal padding, is at most 900px; the browser viewport width is not the criterion.
The `conversation.chat.aside` slot holds one Session-level occupant beside the transcript, such as the [Session panel](../ui-session-panel/README.md). Every Chat View occurrence, main or embedded, renders it in a zero-height layer at the top of the Chat frame, positioned like the turn rail, so it stays in place while the transcript scrolls and inherits `--dsh-composer-height` and `--dsh-conversation-viewport-height` from the shared scrollport. The layer stacks above the turn rail and the back-to-bottom button and passes pointer events through. Its owner prop `endGutter` is half the width the frame leaves around the transcript column, in whole CSS px, computed from the widths a `ResizeObserver` reports for the layer and the column. It follows window and sidebar resizes and dragged column widths without reading element geometry, stays zero without `ResizeObserver`, and re-renders the layer only when it changes.
The `conversation.chat.aside` slot holds one Session-level occupant beside the transcript, such as the [Session panel](../ui-session-panel/README.md). Every Chat View occurrence, main or embedded, renders it in a zero-height layer at the top of the Chat frame, positioned like the turn rail, so it stays in place while the transcript scrolls and inherits `--dsh-composer-height` and `--dsh-conversation-viewport-height` from the shared scrollport. The layer stacks above the turn rail and the back-to-bottom button and passes pointer events through. Its owner prop `endGutter` is an observable source of half the width the frame leaves around the transcript column, in whole CSS px, computed from the widths a `ResizeObserver` reports for the layer and the column. It follows window and sidebar resizes and dragged column widths without reading element geometry and stays zero without `ResizeObserver`. The source keeps its identity, so the layer renders once and a resize re-renders only an occupant whose derived value changes; an occupant sizes itself in CSS, where the same gutter is `(100% - var(--dsh-chat-content-width)) / 2` of the layer.
The transcript root uses `overflow-x: visible; overflow-y: clip`: vertical overflow is clipped without creating a scroll container. Sticky Markdown code banners and expanded compaction headers therefore retain the actual conversation scrollport as their reference when no nearer scrolling ancestor exists. Capped process groups and terminal sections keep their own scrollports.
+1 -1
View File
@@ -160,7 +160,7 @@ Chat 会在历史前插与 renderer 重新挂载时恢复语义锚点,并且
轮次轨道与回到底部按钮位于正文裁剪层外。它们相对共享会话滚动容器做 sticky 定位;Chat 自己持有滚动容器时,则相对 Chat 外框做 absolute 定位。轮次轨道贴在滚动容器的起始边,把末端留白让给[会话面板](../ui-session-panel/README.zh.md),预览朝正文方向弹出。正文扣除水平内边距后的可用宽度不超过 900px 时,隐藏轮次轨道;判断依据不是浏览器视口宽度。
`conversation.chat.aside` slot 放一个位于正文旁边、面向整个会话的组件,例如[会话面板](../ui-session-panel/README.zh.md)。每个 Chat 视图实例(主正文区或嵌入的)都会渲染它:它位于 Chat 外框顶部的零高度图层中,定位方式与轮次轨道相同,因此不随正文滚动,并从共享滚动容器继承 `--dsh-composer-height` 与 `--dsh-conversation-viewport-height`。该图层叠在轮次轨道与回到底部按钮之上,自身不拦截指针事件。owner 属性 `endGutter` 是外框在正文列两侧留出宽度的一半(整数 CSS px),由 `ResizeObserver` 报告的图层与正文列宽度算出。它跟随窗口、侧栏尺寸变化和拖动后的正文宽度,不读取元素几何;没有 `ResizeObserver` 时保持为 0;只有它变化时图层才重新渲染。
`conversation.chat.aside` slot 放一个位于正文旁边、面向整个会话的组件,例如[会话面板](../ui-session-panel/README.zh.md)。每个 Chat 视图实例(主正文区或嵌入的)都会渲染它:它位于 Chat 外框顶部的零高度图层中,定位方式与轮次轨道相同,因此不随正文滚动,并从共享滚动容器继承 `--dsh-composer-height` 与 `--dsh-conversation-viewport-height`。该图层叠在轮次轨道与回到底部按钮之上,自身不拦截指针事件。owner 属性 `endGutter` 是一个可订阅的数据源,值为外框在正文列两侧留出宽度的一半(整数 CSS px),由 `ResizeObserver` 报告的图层与正文列宽度算出。它跟随窗口、侧栏尺寸变化和拖动后的正文宽度,不读取元素几何;没有 `ResizeObserver` 时保持为 0。数据源的引用不变,因此图层只渲染一次,尺寸变化只让由它推导出的值发生变化的占位组件重新渲染;占位组件用 CSS 决定自身尺寸,同一留白在图层中为 `(100% - var(--dsh-chat-content-width)) / 2`。
正文根节点使用 `overflow-x: visible; overflow-y: clip`:裁剪纵向溢出,但不创建滚动容器。因此,在没有更近的滚动祖先时,Markdown 代码块的 sticky 头栏和展开的压缩摘要头栏仍以实际会话滚动容器为参照。限高过程组和终端区域保留各自的滚动容器。
@@ -1,5 +1,6 @@
/** The Chat View's aside layer: one Session-level occupant beside the transcript, given the end gutter it keeps within. */
/** The Chat View's aside layer: one Session-level occupant beside the transcript, given the end gutter as an observable source. */
import { memo, useLayoutEffect, useMemo, useRef, useState, type RefObject } from 'react'
import { createSnapshotStore, type ObservableSnapshot } from '@deepseek-ai/dsh-client-store'
import type { PropsRenderSlots } from '@deepseek-ai/dsh-client-ui-slots'
import type { ChatAsideOwnerProps } from '../contract/slots.ts'
import css from './ChatView.module.css'
@@ -9,12 +10,16 @@ import css from './ChatView.module.css'
* layer, which spans the Chat frame, and for the transcript column, which
* covers window and sidebar resizes and a dragged column width. The column
* is centered in the frame, so the gutter is half their difference; no
* element geometry is read. Without ResizeObserver the gutter stays zero.
* element geometry is read. Each change is published to the returned source,
* so the layer itself never re-renders for a resize. Without ResizeObserver
* the gutter stays zero.
* @param layer - the aside layer, a child of the Chat frame that precedes the transcript column.
* @returns the gutter in whole CSS px, zero until both widths are known.
* @returns the gutter in whole CSS px, zero until both widths are known; one source for the layer's lifetime.
*/
function useEndGutter(layer: RefObject<HTMLElement>): number {
const [gutter, setGutter] = useState(0)
function useEndGutter(layer: RefObject<HTMLElement>): ObservableSnapshot<number> {
const [gutter] = useState(() => createSnapshotStore(0))
// Observing before the first paint lets the first report land before that paint, so an occupant that the gutter
// shows, such as a docked panel, does not miss the frame in which its Chat View mounts.
useLayoutEffect(() => {
if (typeof ResizeObserver === 'undefined') return
// The frame's DOM is in place, though its own refs attach after this child's layout effect.
@@ -28,19 +33,19 @@ function useEndGutter(layer: RefObject<HTMLElement>): number {
else columnWidth = entry.contentRect.width
}
if (layerWidth === undefined || columnWidth === undefined) return
setGutter(Math.max(0, Math.round((layerWidth - columnWidth) / 2)))
gutter.set(Math.max(0, Math.round((layerWidth - columnWidth) / 2)))
})
observer.observe(layerElement)
observer.observe(column)
return () => { observer.disconnect() }
}, [layer])
}, [layer, gutter])
return gutter
}
/**
* Render the aside layer with its occupant. The Chat View's `renderSlot` is
* stable per registration, so the layer re-renders only when the gutter
* changes, not with every transcript update.
* stable per registration and the gutter source keeps its identity, so the
* layer renders once: neither transcript updates nor resizes re-render it.
* @param props - the Chat View's slot renderer.
* @returns the zero-height aside layer.
*/
@@ -391,10 +391,14 @@ export type ChatFlowSlotProps =
export interface ChatAsideOwnerProps {
/**
* Inline space in CSS px between the transcript column's end edge and the
* Chat frame's end edge, measured again whenever the frame or the column
* resizes; zero before the first measurement.
* Chat frame's end edge, followed whenever the frame or the column resizes;
* zero before the first measurement. The source keeps its identity for the
* layer's lifetime and publishes changes without re-rendering the layer, so
* an occupant subscribes for the decisions it derives from the gutter and
* sizes itself in CSS, where the gutter is
* `(100% - var(--dsh-chat-content-width)) / 2` of the layer.
*/
readonly endGutter: number
readonly endGutter: ObservableSnapshot<number>
}
/** Full Chat view props. */
@@ -448,7 +452,7 @@ declare module '@deepseek-ai/dsh-client-ui-slots' {
* scrolls and inherits the shared scrollport's composer and viewport
* heights. The layer passes pointer events through; the occupant
* positions itself in it, enables its own pointer events, and keeps
* within `endGutter` to stay clear of the transcript column.
* within the end gutter to stay clear of the transcript column.
*/
'conversation.chat.aside': { kind: 'single'; scope: 'session'; owner: ChatAsideOwnerProps }
@@ -869,7 +869,7 @@ describe('Chat node rendering', () => {
})
describe('ChatView', () => {
it('renders the aside with half the width the frame leaves around the transcript column, following resizes', () => {
it('gives the aside a gutter source that follows half the width the frame leaves around the transcript column, rendering the aside once', () => {
const observers: { callback: ResizeObserverCallback; targets: Element[] }[] = []
vi.stubGlobal('ResizeObserver', class {
readonly targets: Element[] = []
@@ -892,31 +892,34 @@ describe('ChatView', () => {
const entries = sizes.map(([target, width]) => ({ target, contentRect: { width } }) as ResizeObserverEntry)
act(() => { gutter?.callback(entries, {} as ResizeObserver) })
}
expect(h.asideOwners).toHaveLength(1)
const source = (h.asideOwners[0] as ChatAsideOwnerProps).endGutter
const published: number[] = []
const off = source.subscribe(() => { published.push(source.getSnapshot()) })
// Nothing is known until both widths arrive.
deliver([layer, 1600.4])
expect(h.asideOwners.at(-1)).toEqual({ endGutter: 0 })
expect(source.getSnapshot()).toBe(0)
deliver([column, 760])
expect(h.asideOwners.at(-1)).toEqual({ endGutter: 420 })
expect(source.getSnapshot()).toBe(420)
deliver([column, 880])
expect(h.asideOwners.at(-1)).toEqual({ endGutter: 360 })
// Height-only growth reports the same widths and keeps the owner identity.
const owner = h.asideOwners.at(-1)
expect(source.getSnapshot()).toBe(360)
// Height-only growth reports the same widths and publishes nothing.
deliver([column, 880])
expect(h.asideOwners.at(-1)).toBe(owner)
deliver([layer, 700])
expect(h.asideOwners.at(-1)).toEqual({ endGutter: 0 })
expect(source.getSnapshot()).toBe(0)
expect(published).toEqual([420, 360, 0])
off()
expect(rect).not.toHaveBeenCalled()
// Transcript updates do not re-render the aside.
const settled = h.asideOwners.length
// Neither resizes nor transcript updates re-render the aside.
act(() => { h.setSession({ running: true }) })
expect(h.asideOwners).toHaveLength(settled)
expect(h.asideOwners).toHaveLength(1)
})
it('keeps the aside gutter at zero without ResizeObserver', () => {
vi.stubGlobal('ResizeObserver', undefined)
const h = makeHarness({}, {}, chatSnapshotFixture({ nodes: [user(1, 'hello')] }))
render(<h.ChatView {...h.props} />)
expect(h.asideOwners.at(-1)).toEqual({ endGutter: 0 })
expect((h.asideOwners.at(-1) as ChatAsideOwnerProps).endGutter.getSnapshot()).toBe(0)
})
it('renders only referenced Nodes without deleting unreferenced Node data', () => {
@@ -24,11 +24,11 @@
en: a297c196bb631928
zh: 523b71276d8f847e
/deepseek-ai-dsh-client-ui-session-panel/understand-the-implementation:
en: f996b40c78ce18ba
zh: d66ed6289f8eed50
en: a6e70aa8e7e3e7fa
zh: 2633f04bbf1e6711
/deepseek-ai-dsh-client-ui-session-panel/further-exploration:
en: 5fa707ada69696c4
zh: 595d8b2d7de42181
en: 413e4e321768d4b2
zh: 85444059cd1dc565
/deepseek-ai-dsh-client-ui-session-panel/model-experience:
en: 7e8bbe318a76fd54
zh: c60e87da2a37642a
+3 -3
View File
@@ -54,7 +54,7 @@ Summary rows from every package use the `PanelRow` primitive, so icon, text, and
<details>
<summary>Implementation internals — click to expand</summary>
The panel is the `conversation.chat.aside` occupant of [`dsh-client-ui-chat`](../ui-chat/README.md#scroll-ownership), so it renders only in Chat Views. The toggle and the panel are separate Slot entries that share one plugin-owned state: the persisted docking preference, the Session whose overlay is open, and the end gutter each mounted panel reports from its `endGutter` owner prop. A panel withdraws its report when it unmounts or its Chat View moves to another Session. The panel decides its presentation from its own gutter; the toggle reads the widest gutter of its Session, and a Session without one shows no Chat View. Both decide with the same pure function, so the toggle's state never disagrees with the panel. The aside layer inherits the scrollport's composer and viewport heights, and the docked width follows the gutter through `--dsh-session-panel-gutter`.
The panel is the `conversation.chat.aside` occupant of [`dsh-client-ui-chat`](../ui-chat/README.md#scroll-ownership), so it renders only in Chat Views. The toggle and the panel are separate Slot entries that share one plugin-owned state: the persisted docking preference, the Session whose overlay is open, and whether each Session has room to dock. Each mounted panel registers the `endGutter` source of its Chat View with that state, and stops when it unmounts or its Chat View moves to another Session; a Session has room while any of its sources holds the docked panel, and a Session without a source shows no Chat View. The panel decides its presentation from its own source, and both decide with the same pure function, so the toggle's state never disagrees with the panel. The panel and the toggle subscribe only to whether the gutter holds the docked panel, so a resize renders them again only when it crosses the 344px threshold, and opening, closing, or docking the panel renders nothing in the Chat View. The aside layer inherits the scrollport's composer and viewport heights and the transcript width `--dsh-chat-content-width`, from which CSS sizes the docked panel.
The panel projects the section list's live registrations (`entriesOfSlot`, so a higher-priority registration with the same `id` replaces a shipped section) into `{ id, label }` rows, recomputed only when the ledger version or the locale revision changes. It renders each section through `renderSlot(..., { only: id })` inside its own title and body; a CSS `:has()` rule hides a section whose body outlet stayed empty, including a shared section whose row outlet stayed empty.
@@ -62,7 +62,7 @@ The panel projects the section list's live registrations (`entriesOfSlot`, so a
|---|---|
| [`src/client/index.ts`](src/client/index.ts) | Dictionaries, the toggle, the panel, the Environment section, and the project row |
| [`src/client/slots.ts`](src/client/slots.ts) | Slot declarations and component props |
| [`src/client/visibility.ts`](src/client/visibility.ts) | Docking threshold, presentation, the shared visibility state, and the reported gutters |
| [`src/client/visibility.ts`](src/client/visibility.ts) | Docking threshold, presentation, the shared visibility state, and each Session's room to dock |
| [`src/client/sections.ts`](src/client/sections.ts) | Section roster projection |
| [`src/client/SessionPanel.tsx`](src/client/SessionPanel.tsx) | The panel, its section titles, and Escape handling |
| [`src/client/SessionPanelToggle.tsx`](src/client/SessionPanelToggle.tsx) | The header toggle and its indicators |
@@ -76,7 +76,7 @@ The panel projects the section list's live registrations (`entriesOfSlot`, so a
## Further Exploration
- [Web Client Slots](../../../docs/subsystems/slots.md) — list, keyed, and owner-prop semantics the sections rely on.
- [`dsh-client-ui-chat`](../ui-chat/README.md#scroll-ownership) — the `conversation.chat.aside` layer and its end gutter.
- [`dsh-client-ui-chat`](../ui-chat/README.md#scroll-ownership) — the `conversation.chat.aside` layer and its end gutter source.
- [`dsh-client-ui-conversation`](../ui-conversation/README.md) — the Session header utilities.
- [`dsh-client-ui-primitives`](../ui-primitives/README.md#component-catalog) — `PanelRow` and `PathLabel`.
@@ -54,7 +54,7 @@ kind: "package-reference"
<details>
<summary>实现内幕——点击展开</summary>
面板是 [`dsh-client-ui-chat`](../ui-chat/README.zh.md#scroll-ownership) 中 `conversation.chat.aside` 的占位组件,因此只渲染在 Chat 视图中。开关与面板是两个独立的 Slot 条目,共享一份插件持有的状态:持久化的停靠偏好、打开了浮层的会话,以及每个已挂载面板从 owner 属性 `endGutter` 上报的末端留白。面板卸载或其 Chat 视图换到另一个会话时撤回上报。面板根据自己的留白决定呈现方式;开关读取该会话最宽的留白,没有留白的会话表示没有 Chat 视图在显示它。两者用同一个纯函数决定,因此开关状态始终与面板一致。侧边层从滚动容器继承输入框区域与视口高度,停靠宽度通过 `--dsh-session-panel-gutter` 跟随留白。
面板是 [`dsh-client-ui-chat`](../ui-chat/README.zh.md#scroll-ownership) 中 `conversation.chat.aside` 的占位组件,因此只渲染在 Chat 视图中。开关与面板是两个独立的 Slot 条目,共享一份插件持有的状态:持久化的停靠偏好、打开了浮层的会话,以及每个会话是否有停靠空间。每个已挂载的面板把所在 Chat 视图的 `endGutter` 数据源登记到这份状态里,面板卸载或其 Chat 视图换到另一个会话时取消登记;会话的任一数据源能容纳停靠面板时,该会话就有停靠空间,没有数据源的会话表示没有 Chat 视图在显示它。面板根据自己的数据源决定呈现方式,两者用同一个纯函数决定,因此开关状态始终与面板一致。面板与开关只订阅留白能否容纳停靠面板,因此尺寸变化只在跨过 344px 阈值时才让它们重新渲染;打开、关闭或停靠面板也不会让 Chat 视图重新渲染。侧边层从滚动容器继承输入框区域与视口高度,以及正文宽度 `--dsh-chat-content-width`,停靠宽度由 CSS 据此算出。
面板把分栏列表的实时注册(`entriesOfSlot`,因此同 `id` 且优先级更高的注册会替换已发布的分栏)投影为 `{ id, label }` 行,只在台账版本或语言版本变化时重新计算。它在各分栏自己的标题和正文容器里用 `renderSlot(..., { only: id })` 渲染内容;CSS `:has()` 规则隐藏正文出口为空的分栏,也包括行出口为空的共享分栏。
@@ -62,7 +62,7 @@ kind: "package-reference"
|---|---|
| [`src/client/index.ts`](src/client/index.ts) | 字典、开关、面板、「环境」分栏与项目行 |
| [`src/client/slots.ts`](src/client/slots.ts) | Slot 声明与组件 props |
| [`src/client/visibility.ts`](src/client/visibility.ts) | 停靠阈值、呈现方式、共享可见性状态与上报的留白 |
| [`src/client/visibility.ts`](src/client/visibility.ts) | 停靠阈值、呈现方式、共享可见性状态与每个会话的停靠空间 |
| [`src/client/sections.ts`](src/client/sections.ts) | 分栏名单投影 |
| [`src/client/SessionPanel.tsx`](src/client/SessionPanel.tsx) | 面板、分栏标题与 Esc 处理 |
| [`src/client/SessionPanelToggle.tsx`](src/client/SessionPanelToggle.tsx) | 标题栏开关及其角标 |
@@ -76,7 +76,7 @@ kind: "package-reference"
## 进一步探索
- [Web Client Slots](../../../docs/subsystems/slots.zh.md)——分栏依赖的 list、keyed 与 owner props 语义。
- [`dsh-client-ui-chat`](../ui-chat/README.zh.md#scroll-ownership)——`conversation.chat.aside` 图层及其末端留白。
- [`dsh-client-ui-chat`](../ui-chat/README.zh.md#scroll-ownership)——`conversation.chat.aside` 图层及其末端留白数据源。
- [`dsh-client-ui-conversation`](../ui-conversation/README.zh.md)——会话标题栏工具区。
- [`dsh-client-ui-primitives`](../ui-primitives/README.zh.md#component-catalog)——`PanelRow` 与 `PathLabel`。
@@ -1,15 +1,16 @@
/* The panel floats in the Chat View's aside layer, a zero-height box at the
top of the Chat frame that passes pointer events through. The layer
/* The panel floats in the Chat View's aside layer, a zero-height box across
the top of the Chat frame that passes pointer events through. The layer
inherits the scrollport's --dsh-conversation-viewport-height and
--dsh-composer-height; the panel receives the Chat View's end gutter as
--dsh-session-panel-gutter. */
--dsh-composer-height, and the transcript width --dsh-chat-content-width,
so the end gutter is half the layer width the transcript leaves. */
.panel {
position: absolute;
top: 12px;
right: 16px;
box-sizing: border-box;
/* The docked width keeps 48px clear of the transcript column and its width handle. */
width: clamp(280px, calc(var(--dsh-session-panel-gutter, 0px) - 64px), 340px);
/* The docked width keeps 48px clear of the transcript column and its width handle,
as the back-to-bottom control computes the same gutter. */
width: clamp(280px, calc((100% - var(--dsh-chat-content-width, 100%)) / 2 - 64px), 340px);
/* Stops above the composer stack, whose seat fades and takes presses across the body's full width. */
max-height: calc(var(--dsh-conversation-viewport-height, 100dvh) - var(--dsh-composer-height, 152px) - 24px);
overflow-y: auto;
@@ -1,6 +1,6 @@
/** Floating Session panel in the Chat View's aside: section titles drawn from the section roster, bodies from the section slot. */
import {
useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, type CSSProperties, type FocusEvent, type ReactNode,
useCallback, useEffect, useLayoutEffect, useMemo, useRef, useSyncExternalStore, type FocusEvent, type ReactNode,
} from 'react'
import { isBehindModal, observeComposition } from '@deepseek-ai/dsh-client-ui-primitives'
import { panelElementId, toggleElementId } from './element-ids.ts'
@@ -75,33 +75,23 @@ function useFocusReturn(hidden: boolean, toggleId: string): {
}), [])
}
/**
* Report the Chat View's end gutter for this panel while it is mounted, and
* withdraw it when the panel unmounts or its Chat View moves to another
* Session. A changed gutter replaces the report without withdrawing it.
* @param measure - records one panel's gutter.
* @param sessionId - Session the Chat View shows.
* @param endGutter - the Chat View's end gutter in CSS px.
*/
function useGutterReport(measure: SessionPanelProps['measure'], sessionId: SessionPanelProps['sessionId'], endGutter: number): void {
const instance = useId()
useLayoutEffect(() => () => { measure(sessionId, instance, null) }, [measure, sessionId, instance])
useLayoutEffect(() => { measure(sessionId, instance, endGutter) }, [measure, sessionId, instance, endGutter])
}
/**
* 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.
* The overlay closes on Escape and on an outside pointerdown. The docked
* width follows the Chat View's end gutter.
* @param props - Session values, the Chat View's end gutter, shared visibility, sections, the gutter report, and copy.
* The overlay closes on Escape and on an outside pointerdown. CSS sizes the
* docked panel from the transcript width; the gutter source decides only
* whether it can dock, so a resize re-renders the panel only when it crosses
* the docking threshold.
* @param props - Session values, the Chat View's end gutter source, shared visibility, sections, the gutter tracking, and copy.
* @returns the panel, or null while it is hidden.
*/
export function SessionPanel({
sessionId, endGutter, useVisibility, useSections, measure, closeOverlay, renderSlot, t,
sessionId, endGutter, useVisibility, useSections, track, closeOverlay, renderSlot, t,
}: SessionPanelProps): ReactNode {
useGutterReport(measure, sessionId, endGutter)
const fits = fitsGutter(endGutter)
// Registered before paint, so a Chat View remount keeps the header toggle available instead of flashing unavailable.
useLayoutEffect(() => track(sessionId, endGutter), [track, sessionId, endGutter])
const followGutter = useCallback((listener: () => void) => endGutter.subscribe(listener), [endGutter])
const fits = useSyncExternalStore(followGutter, () => fitsGutter(endGutter.getSnapshot()))
const presentation = useVisibility(visibility => presentationOf(fits, visibility, sessionId))
const sections = useSections(entries => entries)
const panel = useRef<HTMLElement>(null)
@@ -117,7 +107,6 @@ export function SessionPanel({
<aside
id={panelElementId(sessionId)}
className={css.panel}
style={{ '--dsh-session-panel-gutter': `${endGutter}px` } as CSSProperties}
aria-label={t('panel.name')}
ref={panel}
onFocus={focus.onFocus}
@@ -3,7 +3,7 @@ import type { ReactNode } from 'react'
import { Button, IconFlatListOutlineRegular, Tooltip } from '@deepseek-ai/dsh-client-ui-primitives'
import { panelElementId, toggleElementId } from './element-ids.ts'
import type { SessionPanelToggleProps } from './slots.ts'
import { fitsGutter, presentationOf } from './visibility.ts'
import { presentationOf } from './visibility.ts'
import css from './SessionPanelToggle.module.css'
/**
@@ -11,16 +11,15 @@ import css from './SessionPanelToggle.module.css'
* text of any indicator; the expanded state says whether the panel shows.
* While no Chat View shows the Session, as in the trajectory View, the panel
* has no place to show: the toggle is unavailable and its tooltip says so.
* @param props - Session values, the Chat View gutters, shared visibility, the toggle action, and copy.
* @param props - Session values, the room to dock, shared visibility, the toggle action, and copy.
* @returns the header entry.
*/
export function SessionPanelToggle({
sessionId, useGutters, useVisibility, toggle, renderSlot, t,
sessionId, useDockable, useVisibility, toggle, renderSlot, t,
}: SessionPanelToggleProps): ReactNode {
const gutter = useGutters(gutters => gutters.get(sessionId))
const fits = gutter !== undefined && fitsGutter(gutter)
const shown = useVisibility(visibility => presentationOf(fits, visibility, sessionId) !== 'hidden')
const available = gutter !== undefined
const dockable = useDockable(entries => entries.get(sessionId))
const shown = useVisibility(visibility => presentationOf(dockable === true, visibility, sessionId) !== 'hidden')
const available = dockable !== undefined
const open = available && shown
const label = available ? t(open ? 'toggle.hide' : 'toggle.show') : t('toggle.unavailable')
return (
@@ -29,7 +29,7 @@ declare module '@deepseek-ai/dsh-client-ui-slots' {
}
export type {
EnvironmentSectionProps, ProjectRowInjected, ProjectRowProps, SessionPanelGutters, SessionPanelIndicatorOwnerProps, SessionPanelInjected,
EnvironmentSectionProps, ProjectRowInjected, ProjectRowProps, SessionPanelDockable, SessionPanelIndicatorOwnerProps, SessionPanelInjected,
SessionPanelPresentation, SessionPanelProps, SessionPanelSectionEntry, SessionPanelSectionOwnerProps,
SessionPanelToggleInjected, SessionPanelToggleProps, SessionPanelVisibility,
} from './slots.ts'
@@ -63,7 +63,7 @@ export function apply(ctx: ClientContext): void {
'conversation.session.panel.indicator': { kind: 'list', scope: 'session', inline: true },
},
inject: (): SessionPanelToggleInjected => ({
hooks: { visibility: state.visibility, gutters: state.gutters },
hooks: { visibility: state.visibility, dockable: state.dockable },
toggle: (sessionId) => { state.toggle(sessionId) },
}),
}, SessionPanelToggle))
@@ -77,7 +77,7 @@ export function apply(ctx: ClientContext): void {
},
inject: (): SessionPanelInjected => ({
hooks: { visibility: state.visibility, sections },
measure: (sessionId, instance, endGutter) => { state.measure(sessionId, instance, endGutter) },
track: (sessionId, endGutter) => state.track(sessionId, endGutter),
closeOverlay: (sessionId) => { state.closeOverlay(sessionId) },
}),
}, SessionPanel))
@@ -83,18 +83,18 @@ export interface SessionPanelVisibility {
}
/**
* End gutter of each Session whose Chat View holds a panel, in CSS px; the
* widest one when several Chat Views show the Session. A Session without an
* entry shows no Chat View.
* Whether each Session whose Chat View holds a panel has room to dock it:
* true when the end gutter of at least one of its Chat Views holds the docked
* panel. A Session without an entry shows no Chat View.
*/
export type SessionPanelGutters = ReadonlyMap<SessionId, number>
export type SessionPanelDockable = ReadonlyMap<SessionId, boolean>
/** Business face of the header toggle. */
export interface SessionPanelToggleInjected {
/** Shared visibility and the Chat View gutters; the renderer binds them as `useVisibility` and `useGutters`. */
/** Shared visibility and each Session's room to dock; the renderer binds them as `useVisibility` and `useDockable`. */
readonly hooks: {
readonly visibility: ObservableSnapshot<SessionPanelVisibility>
readonly gutters: ObservableSnapshot<SessionPanelGutters>
readonly dockable: ObservableSnapshot<SessionPanelDockable>
}
/**
* Show or hide the panel. With room to dock this flips the docking
@@ -113,12 +113,13 @@ export interface SessionPanelInjected {
readonly sections: ObservableSnapshot<readonly SessionPanelSectionEntry[]>
}
/**
* Record the end gutter of one mounted panel, or that it unmounted.
* Follow a mounted panel's Chat View gutter for the Session's room to dock,
* which the toggle reads, until the returned disposer runs.
* @param sessionId - Session the panel's Chat View shows.
* @param instance - identity of the panel within the page.
* @param endGutter - the Chat View's end gutter in CSS px; null when the panel unmounts or leaves the Session.
* @param endGutter - the Chat View's end gutter source.
* @returns stops following the source.
*/
readonly measure: (sessionId: SessionId, instance: string, endGutter: number | null) => void
readonly track: (sessionId: SessionId, endGutter: ObservableSnapshot<number>) => () => void
/**
* Close the Session's overlay.
* @param sessionId - Session whose overlay closes; another Session's overlay stays.
@@ -1,7 +1,7 @@
/** Session panel visibility: the persisted docking preference, the transient overlay, the Chat View gutters, and their presentation. */
/** Session panel visibility: the persisted docking preference, the transient overlay, each Session's room to dock, and the presentation. */
import { createSnapshotStore, type ObservableSnapshot } from '@deepseek-ai/dsh-client-store'
import type { SessionId } from '@deepseek-ai/dsh-session/types'
import type { SessionPanelGutters, SessionPanelPresentation, SessionPanelVisibility } from './slots.ts'
import type { SessionPanelDockable, SessionPanelPresentation, SessionPanelVisibility } from './slots.ts'
/** localStorage key of the docking preference. */
export const PINNED_STORAGE_KEY = 'dsh.sessionPanel.pinned'
@@ -13,7 +13,7 @@ export const PINNED_STORAGE_KEY = 'dsh.sessionPanel.pinned'
*/
export const DOCK_MIN_GUTTER = 344
const NO_GUTTERS: SessionPanelGutters = new Map()
const NO_ENTRIES: SessionPanelDockable = new Map()
/**
* Whether a Chat View's end gutter can hold the docked panel.
@@ -39,19 +39,19 @@ export function presentationOf(
}
/**
* Visibility shared by every Session's toggle and panel, and the end gutter
* each mounted panel reports from its Chat View. Docking follows one
* preference for all Sessions; at most one Session's overlay is open, and it
* closes once its Session's gutter can hold the docked panel or no Chat View
* shows that Session any longer.
* Visibility shared by every Session's toggle and panel, and whether each
* Session has room to dock, derived from the end gutters of the Chat Views
* whose panels are mounted. Docking follows one preference for all Sessions;
* at most one Session's overlay is open, and it closes once its Session has
* room to dock or no Chat View shows that Session any longer.
*/
export class SessionPanelState {
// A stored value other than `false` keeps the default: the panel docks.
private readonly pinned = createSnapshotStore<unknown>(true, { persist: { name: PINNED_STORAGE_KEY } })
private readonly overlay = createSnapshotStore<SessionId | null>(null)
private readonly widest = createSnapshotStore<SessionPanelGutters>(NO_GUTTERS)
/** Gutter of every mounted panel, by Session and panel instance. */
private readonly reports = new Map<SessionId, Map<string, number>>()
private readonly room = createSnapshotStore<SessionPanelDockable>(NO_ENTRIES)
/** The Chat View gutter source of every mounted panel, by Session; each registration is its own entry. */
private readonly sources = new Map<SessionId, Set<{ readonly gutter: ObservableSnapshot<number> }>>()
private current: SessionPanelVisibility = { pinned: this.pinned.getSnapshot() !== false, overlay: null }
/** Stops following the open overlay's gutter. */
private unfollow: () => void = () => {}
@@ -74,28 +74,34 @@ export class SessionPanelState {
},
}
/** The widest gutter of each Session with a mounted panel; the snapshot keeps its identity until one changes. */
readonly gutters: ObservableSnapshot<SessionPanelGutters> = this.widest
/**
* Whether each Session with a mounted panel has room to dock it. The
* snapshot keeps its identity until a Session gains or loses its entry or
* crosses the docking threshold, so a resize that stays on one side of the
* threshold publishes nothing.
*/
readonly dockable: ObservableSnapshot<SessionPanelDockable> = this.room
/**
* Record the end gutter of one mounted panel, or that it unmounted.
* Follow the Chat View gutter of one mounted panel until the returned
* disposer runs; a Session has room to dock while any of its sources does.
* @param sessionId - Session the panel's Chat View shows.
* @param instance - identity of the panel within the page.
* @param endGutter - the gutter in CSS px, or null when the panel unmounts or leaves the Session.
* @param gutter - the Chat View's end gutter source.
* @returns stops following the source.
*/
measure(sessionId: SessionId, instance: string, endGutter: number | null): void {
const panels = this.reports.get(sessionId) ?? new Map<string, number>()
if (endGutter === null) panels.delete(instance)
else panels.set(instance, endGutter)
if (panels.size === 0) this.reports.delete(sessionId)
else this.reports.set(sessionId, panels)
const widest = panels.size === 0 ? undefined : Math.max(...panels.values())
const gutters = this.widest.getSnapshot()
if (gutters.get(sessionId) === widest) return
const next = new Map(gutters)
if (widest === undefined) next.delete(sessionId)
else next.set(sessionId, widest)
this.widest.set(next)
track(sessionId: SessionId, gutter: ObservableSnapshot<number>): () => void {
const entry = { gutter }
const sources = this.sources.get(sessionId) ?? new Set()
sources.add(entry)
this.sources.set(sessionId, sources)
const off = gutter.subscribe(() => { this.publish(sessionId) })
this.publish(sessionId)
return () => {
off()
sources.delete(entry)
if (sources.size === 0) this.sources.delete(sessionId)
this.publish(sessionId)
}
}
/**
@@ -105,9 +111,9 @@ export class SessionPanelState {
* @param sessionId - Session whose header holds the toggle.
*/
toggle(sessionId: SessionId): void {
const gutter = this.widest.getSnapshot().get(sessionId)
if (gutter === undefined) return
if (fitsGutter(gutter)) {
const dockable = this.room.getSnapshot().get(sessionId)
if (dockable === undefined) return
if (dockable) {
this.pinned.set(!this.visibility.getSnapshot().pinned)
this.setOverlay(null)
return
@@ -134,9 +140,20 @@ export class SessionPanelState {
this.overlay.set(sessionId)
if (sessionId === null) return
const check = (): void => {
const gutter = this.widest.getSnapshot().get(sessionId)
if (gutter === undefined || fitsGutter(gutter)) this.closeOverlay(sessionId)
if (this.room.getSnapshot().get(sessionId) !== false) this.closeOverlay(sessionId)
}
this.unfollow = this.widest.subscribe(check)
this.unfollow = this.room.subscribe(check)
}
/** Recompute one Session's room to dock from its sources, publishing only a changed entry. */
private publish(sessionId: SessionId): void {
const sources = this.sources.get(sessionId)
const dockable = sources === undefined ? undefined : [...sources].some(source => fitsGutter(source.gutter.getSnapshot()))
const room = this.room.getSnapshot()
if (room.get(sessionId) === dockable) return
const next = new Map(room)
if (dockable === undefined) next.delete(sessionId)
else next.set(sessionId, dockable)
this.room.set(next)
}
}
@@ -67,21 +67,21 @@ describe('ui-session-panel browser half', () => {
expect(ctx.slots.entries('conversation.session.panel.environment.row').map(entry => entry.options.id)).toEqual(['project'])
})
it('hands the toggle the gutters the panel reports, and both the shared visibility', async () => {
it('hands the toggle the room to dock the panel tracks, and both the shared visibility', async () => {
const { ctx, fiber } = await bench()
const toggle = faceOf(ctx, 'conversation.session.header.utilities', 'session-panel') as SessionPanelToggleInjected
const panel = faceOf(ctx, 'conversation.chat.aside', undefined) as SessionPanelInjected
expect(toggle.hooks.visibility).toBe(panel.hooks.visibility)
panel.measure(SID, 'main', 300)
expect(toggle.hooks.gutters.getSnapshot().get(SID)).toBe(300)
const stop = panel.track(SID, createSnapshotStore(300))
expect(toggle.hooks.dockable.getSnapshot().get(SID)).toBe(false)
toggle.toggle(SID)
expect(panel.hooks.visibility.getSnapshot()).toEqual({ pinned: true, overlay: SID })
panel.closeOverlay(SID)
expect(panel.hooks.visibility.getSnapshot().overlay).toBeNull()
toggle.toggle(SID)
// Disposing the plugin stops the open overlay from following the gutters.
// Disposing the plugin stops the open overlay from following the room to dock.
await fiber.dispose()
panel.measure(SID, 'main', null)
stop()
expect(panel.hooks.visibility.getSnapshot().overlay).toBe(SID)
})
@@ -5,12 +5,13 @@ import { useRef, type ReactNode } from 'react'
import { useModalLayer } from '@deepseek-ai/dsh-client-ui-primitives'
import { contextMenuHook, makeTranslate } from '@deepseek-ai/dsh-client-test-runtime'
import type { SessionId } from '@deepseek-ai/dsh-session/types'
import { createSnapshotStore } from '@deepseek-ai/dsh-client-store'
import { EnvironmentSection } from '../src/client/EnvironmentSection.tsx'
import { ProjectRow } from '../src/client/ProjectRow.tsx'
import { SessionPanel } from '../src/client/SessionPanel.tsx'
import { SessionPanelToggle } from '../src/client/SessionPanelToggle.tsx'
import type {
EnvironmentSectionProps, ProjectRowProps, SessionPanelGutters, SessionPanelProps, SessionPanelSectionEntry,
EnvironmentSectionProps, ProjectRowProps, SessionPanelDockable, SessionPanelProps, SessionPanelSectionEntry,
SessionPanelSectionOwnerProps, SessionPanelToggleProps, SessionPanelVisibility,
} from '../src/client/slots.ts'
import { DOCK_MIN_GUTTER } from '../src/client/visibility.ts'
@@ -52,17 +53,17 @@ function tooltipAfterHover(anchor: Element): { readonly early: boolean; readonly
}
describe('SessionPanelToggle', () => {
function toggleProps(gutter: number | undefined, visibility: SessionPanelVisibility, toggle = vi.fn()) {
function toggleProps(dockable: boolean | undefined, visibility: SessionPanelVisibility, toggle = vi.fn()) {
const renderSlot = vi.fn(() => <span>需要处理</span>)
const gutters: SessionPanelGutters = new Map(gutter === undefined ? [] : [[SID, gutter]])
const entries: SessionPanelDockable = new Map(dockable === undefined ? [] : [[SID, dockable]])
const props = {
sessionId: SID, useGutters: selectorOf(gutters), useVisibility: selectorOf(visibility), toggle, renderSlot, t,
sessionId: SID, useDockable: selectorOf(entries), useVisibility: selectorOf(visibility), toggle, renderSlot, t,
} as SessionPanelToggleProps
return { props, toggle, renderSlot }
}
it('names the panel together with its indicators and reports the docked panel as expanded', () => {
const { props, renderSlot } = toggleProps(WIDE, DOCKED)
const { props, renderSlot } = toggleProps(true, DOCKED)
render(<SessionPanelToggle {...props} />)
const button = screen.getByRole('button', { name: '会话面板 需要处理' })
expect(button.getAttribute('aria-expanded')).toBe('true')
@@ -71,12 +72,12 @@ describe('SessionPanelToggle', () => {
})
it('flips docking with room to dock and opens the overlay without it', () => {
const wide = toggleProps(WIDE, DOCKED)
const wide = toggleProps(true, DOCKED)
render(<SessionPanelToggle {...wide.props} />)
fireEvent.click(screen.getByRole('button'))
expect(wide.toggle).toHaveBeenCalledWith(SID)
cleanup()
const narrow = toggleProps(NARROW, DOCKED)
const narrow = toggleProps(false, DOCKED)
render(<SessionPanelToggle {...narrow.props} />)
const button = screen.getByRole('button')
expect(button.getAttribute('aria-expanded')).toBe('false')
@@ -86,19 +87,19 @@ describe('SessionPanelToggle', () => {
})
it('reports an open overlay as expanded', () => {
const { props } = toggleProps(NARROW, { pinned: false, overlay: SID })
const { props } = toggleProps(false, { pinned: false, overlay: SID })
render(<SessionPanelToggle {...props} />)
expect(screen.getByRole('button').getAttribute('aria-expanded')).toBe('true')
})
it('tells its indicators whether the panel shows', () => {
const { props, renderSlot } = toggleProps(NARROW, DOCKED)
const { props, renderSlot } = toggleProps(false, DOCKED)
render(<SessionPanelToggle {...props} />)
expect(renderSlot).toHaveBeenCalledWith('conversation.session.panel.indicator', { panelShown: false })
})
it('shows its tooltip after 500ms of hover', () => {
const { props } = toggleProps(WIDE, DOCKED)
const { props } = toggleProps(true, DOCKED)
render(<SessionPanelToggle {...props} />)
expect(tooltipAfterHover(screen.getByRole('button'))).toEqual({ early: false, at500: true })
})
@@ -122,7 +123,8 @@ describe('SessionPanel', () => {
{ id: 'change-requests', label: '变更请求' },
]
function panelProps(endGutter: number, visibility: SessionPanelVisibility, closeOverlay = vi.fn(), measure = vi.fn()) {
function panelProps(gutter: number, visibility: SessionPanelVisibility, closeOverlay = vi.fn(), track = vi.fn(() => () => {})) {
const endGutter = createSnapshotStore(gutter)
const owners: SessionPanelSectionOwnerProps[] = []
const renderSlot = ((key: string, owner: object, opts?: { only?: string; entryKey?: string }): ReactNode => {
if (key === 'conversation.session.panel.section.actions') {
@@ -136,28 +138,49 @@ describe('SessionPanel', () => {
endGutter,
useVisibility: selectorOf(visibility),
useSections: selectorOf(SECTIONS),
measure,
track,
closeOverlay,
renderSlot,
t,
} as SessionPanelProps
return { props, owners, closeOverlay, measure }
return { props, owners, closeOverlay, track, endGutter }
}
it('reports its Chat View gutter while mounted, replacing it on change and withdrawing it on a Session change and unmount', () => {
const measure = vi.fn()
const view = render(<SessionPanel {...panelProps(420, DOCKED, vi.fn(), measure).props} />)
expect(measure.mock.calls).toEqual([[SID, expect.any(String), 420]])
const instance = measure.mock.calls[0]?.[1] as string
expect(screen.getByRole('complementary').style.getPropertyValue('--dsh-session-panel-gutter')).toBe('420px')
view.rerender(<SessionPanel {...panelProps(400, DOCKED, vi.fn(), measure).props} />)
expect(measure.mock.calls.at(-1)).toEqual([SID, instance, 400])
expect(measure.mock.calls.some(call => call[2] === null)).toBe(false)
it('tracks its Chat View gutter source while mounted, moving with a Session change and stopping on unmount', () => {
const stops: string[] = []
const track = vi.fn((sessionId: SessionId) => () => { stops.push(sessionId) })
const first = panelProps(420, DOCKED, vi.fn(), track)
const view = render(<SessionPanel {...first.props} />)
expect(track.mock.calls).toEqual([[SID, first.endGutter]])
// A gutter change publishes through the source; the registration stays.
act(() => { first.endGutter.set(400) })
expect(track).toHaveBeenCalledTimes(1)
const other = 'session-2' as SessionId
view.rerender(<SessionPanel {...{ ...panelProps(400, DOCKED, vi.fn(), measure).props, sessionId: other }} />)
expect(measure.mock.calls.slice(-2)).toEqual([[SID, instance, null], [other, instance, 400]])
view.rerender(<SessionPanel {...{ ...first.props, sessionId: other }} />)
expect(stops).toEqual([SID])
expect(track.mock.calls.at(-1)).toEqual([other, first.endGutter])
view.unmount()
expect(measure.mock.calls.at(-1)).toEqual([other, instance, null])
expect(stops).toEqual([SID, other])
// CSS sizes the docked panel; no measured width reaches its style.
render(<SessionPanel {...panelProps(420, DOCKED).props} />)
expect(screen.getByRole('complementary').getAttribute('style')).toBeNull()
})
it('renders again only when its gutter crosses the docking threshold', () => {
const { props, owners, endGutter } = panelProps(WIDE + 100, DOCKED)
render(<SessionPanel {...props} />)
const renders = (): number => owners.length
const settled = renders()
act(() => { endGutter.set(WIDE + 40) })
act(() => { endGutter.set(WIDE) })
expect(renders()).toBe(settled)
expect(screen.getByRole('complementary').getAttribute('data-session-panel')).toBe('docked')
act(() => { endGutter.set(NARROW) })
expect(screen.queryByRole('complementary')).toBeNull()
act(() => { endGutter.set(NARROW - 200) })
act(() => { endGutter.set(WIDE + 10) })
expect(screen.getByRole('complementary').getAttribute('data-session-panel')).toBe('docked')
expect(renders()).toBe(settled * 2)
})
it('renders nothing while hidden', () => {
@@ -1,6 +1,7 @@
// @vitest-environment jsdom
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import type { SessionId } from '@deepseek-ai/dsh-session/types'
import { createSnapshotStore } from '@deepseek-ai/dsh-client-store'
import {
DOCK_MIN_GUTTER, PINNED_STORAGE_KEY, SessionPanelState, fitsGutter, presentationOf,
} from '../src/client/visibility.ts'
@@ -10,12 +11,17 @@ const B = 'session-b' as SessionId
const NARROW = 200
const WIDE = DOCK_MIN_GUTTER
/** A Chat View whose panel the state tracks: its gutter source and the disposer of that registration. */
function chatView(state: SessionPanelState, sessionId: SessionId, gutter: number) {
const source = createSnapshotStore(gutter)
const stop = state.track(sessionId, source)
return { source, stop }
}
/** A state whose Chat Views show `A` and `B` with narrow gutters. */
function newState(): SessionPanelState {
function newState() {
const state = new SessionPanelState()
state.measure(A, 'main', NARROW)
state.measure(B, 'main', NARROW)
return state
return { state, a: chatView(state, A, NARROW), b: chatView(state, B, NARROW) }
}
beforeEach(() => { localStorage.clear() })
@@ -45,35 +51,37 @@ describe('presentationOf', () => {
})
})
describe('SessionPanelState gutters', () => {
it('keeps the widest gutter of each Session and drops a Session once its last panel unmounts', () => {
describe('SessionPanelState room to dock', () => {
it('gives a Session room while any of its Chat Views has it, and drops the Session once its last panel stops', () => {
const state = new SessionPanelState()
const empty = state.gutters.getSnapshot()
expect(empty.size).toBe(0)
state.measure(A, 'main', 420)
state.measure(A, 'embedded', 16)
expect(state.gutters.getSnapshot().get(A)).toBe(420)
state.measure(A, 'main', null)
expect(state.gutters.getSnapshot().get(A)).toBe(16)
state.measure(A, 'embedded', null)
expect(state.gutters.getSnapshot().has(A)).toBe(false)
// A withdrawal for a panel that never reported changes nothing.
const before = state.gutters.getSnapshot()
state.measure(B, 'main', null)
expect(state.gutters.getSnapshot()).toBe(before)
expect(state.dockable.getSnapshot().size).toBe(0)
const main = chatView(state, A, 420)
const embedded = chatView(state, A, 16)
expect(state.dockable.getSnapshot().get(A)).toBe(true)
main.stop()
expect(state.dockable.getSnapshot().get(A)).toBe(false)
embedded.source.set(WIDE)
expect(state.dockable.getSnapshot().get(A)).toBe(true)
embedded.stop()
expect(state.dockable.getSnapshot().has(A)).toBe(false)
// A stopped source publishes nothing.
const before = state.dockable.getSnapshot()
embedded.source.set(NARROW)
expect(state.dockable.getSnapshot()).toBe(before)
})
it('keeps the snapshot identity until a widest gutter changes', () => {
it('publishes only when a Session crosses the docking threshold', () => {
const state = new SessionPanelState()
state.measure(A, 'main', 420)
const first = state.gutters.getSnapshot()
const view = chatView(state, A, 420)
const first = state.dockable.getSnapshot()
let calls = 0
const off = state.gutters.subscribe(() => { calls += 1 })
state.measure(A, 'embedded', 16)
state.measure(A, 'main', 420)
expect(state.gutters.getSnapshot()).toBe(first)
const off = state.dockable.subscribe(() => { calls += 1 })
view.source.set(400)
view.source.set(WIDE)
chatView(state, A, 16)
expect(state.dockable.getSnapshot()).toBe(first)
expect(calls).toBe(0)
state.measure(A, 'main', 400)
view.source.set(WIDE - 1)
expect(calls).toBe(1)
off()
})
@@ -81,17 +89,17 @@ describe('SessionPanelState gutters', () => {
describe('SessionPanelState visibility', () => {
it('docks by default and keeps the snapshot identity until a member changes', () => {
const state = newState()
const { state } = newState()
const first = state.visibility.getSnapshot()
expect(first).toEqual({ pinned: true, overlay: null })
expect(state.visibility.getSnapshot()).toBe(first)
})
it('flips and persists the docking preference when the gutter has room, closing any overlay', () => {
const state = newState()
const { state, a } = newState()
state.toggle(A)
expect(state.visibility.getSnapshot().overlay).toBe(A)
state.measure(A, 'main', WIDE)
a.source.set(WIDE)
expect(state.visibility.getSnapshot().overlay).toBeNull()
state.toggle(A)
expect(state.visibility.getSnapshot()).toEqual({ pinned: false, overlay: null })
@@ -102,7 +110,7 @@ describe('SessionPanelState visibility', () => {
})
it('opens and closes one Session overlay without touching the docking preference', () => {
const state = newState()
const { state } = newState()
state.toggle(A)
state.toggle(B)
expect(state.visibility.getSnapshot()).toEqual({ pinned: true, overlay: B })
@@ -124,15 +132,15 @@ describe('SessionPanelState visibility', () => {
it('treats a stored value other than false as the default', () => {
localStorage.setItem(PINNED_STORAGE_KEY, '"yes"')
expect(newState().visibility.getSnapshot().pinned).toBe(true)
expect(newState().state.visibility.getSnapshot().pinned).toBe(true)
})
it('notifies subscribers of both members and stops after unsubscribe', () => {
const state = newState()
const { state, a } = newState()
let calls = 0
const off = state.visibility.subscribe(() => { calls += 1 })
state.toggle(A)
state.measure(A, 'main', WIDE)
a.source.set(WIDE)
state.toggle(A)
const seen = calls
expect(seen).toBeGreaterThanOrEqual(2)
@@ -142,34 +150,34 @@ describe('SessionPanelState visibility', () => {
})
it('closes an overlay once its gutter can dock the panel, without reopening it when the gutter narrows again', () => {
const state = newState()
const { state, a } = newState()
state.toggle(A)
state.measure(A, 'main', 300)
a.source.set(300)
expect(state.visibility.getSnapshot().overlay).toBe(A)
state.measure(A, 'main', WIDE)
a.source.set(WIDE)
expect(state.visibility.getSnapshot()).toEqual({ pinned: true, overlay: null })
state.measure(A, 'main', NARROW)
a.source.set(NARROW)
expect(presentationOf(false, state.visibility.getSnapshot(), A)).toBe('hidden')
})
it('closes an overlay once no Chat View shows its Session, so returning to it shows no overlay', () => {
const state = newState()
const { state, a } = newState()
state.toggle(A)
state.measure(A, 'main', null)
a.stop()
expect(state.visibility.getSnapshot().overlay).toBeNull()
state.measure(A, 'main', NARROW)
chatView(state, A, NARROW)
expect(presentationOf(false, state.visibility.getSnapshot(), A)).toBe('hidden')
})
it('follows only the open overlay, and nothing after dispose', () => {
const state = newState()
const { state, a, b } = newState()
state.toggle(A)
state.toggle(B)
// A's Chat View no longer matters once B holds the overlay.
state.measure(A, 'main', null)
a.stop()
expect(state.visibility.getSnapshot().overlay).toBe(B)
state.dispose()
state.measure(B, 'main', null)
b.stop()
expect(state.visibility.getSnapshot().overlay).toBe(B)
})
})
@@ -221,12 +221,14 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
kind: 'single',
scope: 'session',
summary: 'One Session-level occupant beside the transcript, such as a summary panel.',
doc: 'One Session-level occupant beside the transcript, such as a summary\npanel. Every Chat View occurrence renders it in a zero-height layer at\nthe top of the Chat frame, which stays in place while the transcript\nscrolls and inherits the shared scrollport\'s composer and viewport\nheights. The layer passes pointer events through; the occupant\npositions itself in it, enables its own pointer events, and keeps\nwithin `endGutter` to stay clear of the transcript column.',
doc: 'One Session-level occupant beside the transcript, such as a summary\npanel. Every Chat View occurrence renders it in a zero-height layer at\nthe top of the Chat frame, which stays in place while the transcript\nscrolls and inherits the shared scrollport\'s composer and viewport\nheights. The layer passes pointer events through; the occupant\npositions itself in it, enables its own pointer events, and keeps\nwithin the end gutter to stay clear of the transcript column.',
registerOptions: [],
ownerProps: [
'/** Geometry the Chat View gives its aside occupant. */\nexport interface ChatAsideOwnerProps {\n /**\n * Inline space in CSS px between the transcript column\'s end edge and the\n * Chat frame\'s end edge, measured again whenever the frame or the column\n * resizes; zero before the first measurement.\n */\n readonly endGutter: number\n}',
'/** Geometry the Chat View gives its aside occupant. */\nexport interface ChatAsideOwnerProps {\n /**\n * Inline space in CSS px between the transcript column\'s end edge and the\n * Chat frame\'s end edge, followed whenever the frame or the column resizes;\n * zero before the first measurement. The source keeps its identity for the\n * layer\'s lifetime and publishes changes without re-rendering the layer, so\n * an occupant subscribes for the decisions it derives from the gutter and\n * sizes itself in CSS, where the gutter is\n * `(100% - var(--dsh-chat-content-width)) / 2` of the layer.\n */\n readonly endGutter: ObservableSnapshot<number>\n}',
],
ownerPropsReferences: [
'ObservableSnapshot',
],
ownerPropsReferences: [],
standardProps: [
'useRemoteAccess: (action: RemoteEndpoint) => boolean',
'useResource: UseResource',
@@ -257,7 +259,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
],
replaceRisk: 'shadows-shipped-ui',
example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.chat.aside\', () => ctx.slots.register(\n { name: \'conversation.chat.aside\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:453',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:457',
},
{
key: 'conversation.chat.assistant-actions',
@@ -321,7 +323,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
],
replaceRisk: 'none',
example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.chat.assistant-actions\', () => ctx.slots.register(\n { name: \'conversation.chat.assistant-actions\', id: \'my-entry\', order: 100, label: \'My entry\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:518',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:522',
},
{
key: 'conversation.chat.commandview',
@@ -375,7 +377,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
],
replaceRisk: 'shadows-shipped-ui',
example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.chat.commandview\', () => ctx.slots.register(\n { name: \'conversation.chat.commandview\', key: \'<one key the owner dispatches>\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:500',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:504',
},
{
key: 'conversation.chat.flow',
@@ -422,7 +424,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
],
replaceRisk: 'shadows-shipped-ui',
example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.chat.flow\', () => ctx.slots.register(\n { name: \'conversation.chat.flow\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:456',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:460',
},
{
key: 'conversation.chat.markdown.fence',
@@ -488,7 +490,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
],
replaceRisk: 'wraps-owner-content',
example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.chat.markdown.fence\', () => ctx.slots.register(\n { name: \'conversation.chat.markdown.fence\', id: \'my-layer\', order: 100 },\n ({ children }) => React.createElement(\'div\', null, children),\n ))\n },\n}',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:443',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:447',
},
{
key: 'conversation.chat.message.images',
@@ -535,7 +537,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
],
replaceRisk: 'shadows-shipped-ui',
example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.chat.message.images\', () => ctx.slots.register(\n { name: \'conversation.chat.message.images\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:492',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:496',
},
{
key: 'conversation.chat.node',
@@ -608,7 +610,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
],
replaceRisk: 'shadows-shipped-ui',
example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.chat.node\', () => ctx.slots.register(\n { name: \'conversation.chat.node\', key: \'<one key the owner dispatches>\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:468',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:472',
},
{
key: 'conversation.chat.reasoning.body',
@@ -652,7 +654,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
],
replaceRisk: 'shadows-shipped-ui',
example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.chat.reasoning.body\', () => ctx.slots.register(\n { name: \'conversation.chat.reasoning.body\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:506',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:510',
},
{
key: 'conversation.chat.text-interaction',
@@ -704,7 +706,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
],
replaceRisk: 'shadows-shipped-ui',
example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.chat.text-interaction\', () => ctx.slots.register(\n { name: \'conversation.chat.text-interaction\', key: \'<one key the owner dispatches>\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:441',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:445',
},
{
key: 'conversation.chat.turnTail',
@@ -771,7 +773,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
],
replaceRisk: 'none',
example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.chat.turnTail\', () => ctx.slots.register(\n { name: \'conversation.chat.turnTail\', id: \'my-entry\', order: 100, label: \'My entry\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:512',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:516',
},
{
key: 'conversation.chat.user.before',
@@ -821,7 +823,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
],
replaceRisk: 'none',
example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.chat.user.before\', () => ctx.slots.register(\n { name: \'conversation.chat.user.before\', select: owner => null },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:482',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:486',
},
{
key: 'conversation.chat.user.images',
@@ -868,7 +870,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
],
replaceRisk: 'shadows-shipped-ui',
example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.chat.user.images\', () => ctx.slots.register(\n { name: \'conversation.chat.user.images\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:494',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:498',
},
{
key: 'conversation.composer',
@@ -4692,7 +4694,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
],
replaceRisk: 'none',
example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'shell.quota-notice\', () => ctx.slots.register(\n { name: \'shell.quota-notice\', select: owner => null },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:526',
source: 'packages/client/ui-chat/src/client/contract/slots.ts:530',
},
{
key: 'sidebar',