feat(session-panel): dock by moving the transcript aside, without a pin
The panel no longer has a pin. While the docking preference is on and the end gutter is narrower than the 348px that docks the panel, the Conversation body moves the transcript column and the composer into the start gutter, at their own widths, and the panel docks in the room that leaves. Where the start gutter cannot give it, the transcript stays centered, the panel hides, and the toggle opens it over the transcript as before. The column never narrows for the panel. The panel's one dock probe has room while the gutter holds the panel or the body's largest end reserve covers it, so the plugin's state, toggle, and overlay rules are the gutter-only panel's. The width handles follow the moved column, and a drag beside the docked panel moves only the column's start edge. The drag mark of a section title passes pointer events through. The Web e2e lane's standard page starts with docking off, since the panel now docks at its 1680px width, and the specs that read the conversation alone hide a docked panel first.
This commit is contained in:
1 parent
1edd4e31d9
commit
ccbca7a7d2
42 files changed
+815
-1170
No files matched your search
@@ -21,8 +21,8 @@
|
||||
en: 08e720a4ea75d4d6
|
||||
zh: 5e2e5b8452f67d36
|
||||
/agent-note-session-panel-in-the-chat-view-s-end-gutter/alternatives-considered:
|
||||
en: 06f473c9dda80cb7
|
||||
zh: 974f7b94a46f9a2c
|
||||
en: 127de82059f075ff
|
||||
zh: f605915a6d9964fa
|
||||
/agent-note-session-panel-in-the-chat-view-s-end-gutter/consequences:
|
||||
en: 0392945cc28a0e6d
|
||||
zh: 9ea6cf996a380dd1
|
||||
en: f68c02110b2d2382
|
||||
zh: deb1d49b77387bde
|
||||
@@ -39,14 +39,14 @@ The turn rail sits at the scrollport's start edge with its marks, focus ring, an
|
||||
- **The dock kit's floating window.** `FloatLayer` windows are draggable, resizable, and positioned in viewport coordinates; a summary anchored to the transcript gutter needs none of that and would have to fight the window's own placement rules.
|
||||
- **Viewport-width breakpoints.** The transcript width is adaptive and draggable and the right sidebar takes a variable track, so a viewport breakpoint either covers the transcript or hides the panel with room to spare.
|
||||
- **CSS-only hiding with a click-time read.** A container query on the gutter can hide the docked panel, and the toggle could read the computed result when pressed, as the background-job trigger does. The toggle would still render without knowing whether the panel shows, so `aria-expanded` and its tooltip would be wrong whenever the preference says dock but the gutter is too narrow.
|
||||
- **Squeezing the transcript to make room by default.** Docking on laptop widths by moving the transcript column aside changes the centered column, the composer, and both width handles without the reader asking. The transcript makes room only for a panel the reader pins ([decision](2026-11-16-session-panel-pin-makes-room.md)).
|
||||
- **Narrowing the transcript to make room.** Docking in narrower frames by narrowing the transcript column changes the reading width without the reader asking. The column moves into its start gutter for the panel and keeps its width ([decision](2026-11-16-session-panel-makes-room.md)).
|
||||
- **A Session-scoped standard hook for the gutter.** Adding a hook to every Session-scoped Slot would make every component fixture in the client restate it; the docking decision has two readers, the panel and the toggle, and both read it from the plugin's own state.
|
||||
|
||||
## Consequences
|
||||
|
||||
- With the default transcript width, which stops at 880px, the body must be 1576px wide to dock, so laptop widths use the overlay unless the reader [pins the panel](2026-11-16-session-panel-pin-makes-room.md); the panel never covers the transcript unless the user opens it.
|
||||
- With the default transcript width, which stops at 880px, the body must be 1576px wide to dock in the gutter alone; narrower bodies dock by [moving the transcript aside](2026-11-16-session-panel-makes-room.md), and those too narrow for that use the overlay; the panel never covers the transcript unless the user opens it.
|
||||
- Sections from independent plugins share one surface, ordering, and title style without depending on each other, and an occupied section id can be replaced by a higher-priority registration.
|
||||
- `ui-chat` gained one slot and one custom property on its layer and observes nothing for them. Each mounted panel adds one `ResizeObserver` on each of its two probes, which call back only when a docking decision flips. `ui-conversation` caps the default transcript width at 880px.
|
||||
- `ui-chat` gained one slot and one custom property on its layer and observes nothing for them. Each mounted panel adds one `ResizeObserver` on its dock probe, which calls back only when the docking decision flips. `ui-conversation` caps the default transcript width at 880px.
|
||||
- The panel shows only in Chat Views; elsewhere the toggle stays in the header, unavailable. Every Chat View occurrence renders the aside, so a Session shown in the main body and in an embedded Conversation at once shows its overlay in both.
|
||||
- The turn rail's position changed for every user; its behavior and hiding rule did not.
|
||||
- Change requests, background jobs, and subagents became sections, replacing the change requests sidebar tab, its start-page entry, and the header controls of jobs and subagents; the header keeps the subagent breadcrumb switcher for child Sessions. A section mounts only while the panel shows, so state that must outlast hiding the panel, such as cleared job rows, lives in a per-Session slot store.
|
||||
@@ -39,14 +39,14 @@ Status: implemented
|
||||
- **dock kit 的悬浮窗。** `FloatLayer` 窗口可拖拽、可缩放、按视口坐标定位;锚定在正文留白的摘要用不上这些能力,还要对抗窗口自身的定位规则。
|
||||
- **按视口宽度断点。** 正文宽度自适应、可拖拽,右侧栏占用可变宽度,视口断点要么遮挡正文,要么在空间充足时也隐藏面板。
|
||||
- **纯 CSS 隐藏加点击时读取。** 对留白做容器查询可以隐藏停靠面板,开关在按下时读取计算结果,与后台任务按钮的做法相同。但开关渲染时仍不知道面板是否显示,偏好为停靠而留白不足时,`aria-expanded` 与提示文字都会出错。
|
||||
- **默认挤压正文腾出空间。** 在笔记本宽度下把正文列移开来停靠,会在用户没有要求的情况下改变居中的正文列、composer 和两侧宽度拖拽条。正文只为用户固定的面板让位([决策](2026-11-16-session-panel-pin-makes-room.zh.md))。
|
||||
- **让正文变窄来腾出空间。** 在更窄的外框里通过收窄正文列来停靠,会在用户没有要求的情况下改变阅读宽度。正文列为面板移入起始留白,宽度不变([决策](2026-11-16-session-panel-makes-room.zh.md))。
|
||||
- **会话作用域标准 hook。** 给每个会话作用域 Slot 增加一个留白 hook,会让客户端所有组件测试夹具都要补上它;停靠判断只有两个读取方,即面板和开关,两者都从插件自己的状态读取。
|
||||
|
||||
## Consequences
|
||||
|
||||
- 默认正文宽度最多 880px,此时对话区要 1576px 宽才能停靠,因此笔记本宽度使用浮层,除非用户[固定面板](2026-11-16-session-panel-pin-makes-room.zh.md);除非用户主动打开,面板不会遮挡正文。
|
||||
- 默认正文宽度最多 880px,此时对话区要 1576px 宽才能只靠留白停靠;更窄的对话区通过[让正文移开](2026-11-16-session-panel-makes-room.zh.md)来停靠,窄到无法移开时使用浮层;除非用户主动打开,面板不会遮挡正文。
|
||||
- 独立插件的分栏共享同一界面、排序和标题样式,彼此不依赖;已占用的分栏 id 可以被更高优先级的注册替换。
|
||||
- `ui-chat` 多了一个 slot,侧边层多了一个自定义属性,但不为它们观察任何尺寸。每个已挂载的面板在它的两个探针上各多一个 `ResizeObserver`,只在某项停靠判断翻转时回调。`ui-conversation` 把默认正文宽度上限定为 880px。
|
||||
- `ui-chat` 多了一个 slot,侧边层多了一个自定义属性,但不为它们观察任何尺寸。每个已挂载的面板在停靠探针上多一个 `ResizeObserver`,只在停靠判断翻转时回调。`ui-conversation` 把默认正文宽度上限定为 880px。
|
||||
- 面板只出现在 Chat 视图中;其他视图下开关仍在标题栏中,但不可用。每个 Chat 视图实例都会渲染侧边层,因此同一会话同时显示在主正文区和嵌入的对话中时,两处都会显示浮层。
|
||||
- 轮次轨道的位置对所有用户都变了;行为和隐藏规则不变。
|
||||
- 变更请求、后台任务和子智能体成为分栏,取代变更请求侧边栏标签页、其起始页入口,以及标题栏中的后台任务和子智能体控件;标题栏仍为子会话保留子智能体面包屑切换器。分栏只在面板显示时挂载,因此需要在隐藏面板后保留的状态(例如已清空的任务行)放在按会话划分的 slot store 中。
|
||||
@@ -0,0 +1,31 @@
|
||||
# Bilingual-pair consistency record for 2026-11-16-session-panel-makes-room.md (docs/i18n/README.md): per heading
|
||||
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
|
||||
# After editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write .agents/notes/implemented/feature/2026-11-16-session-panel-makes-room.md
|
||||
/agent-note-the-transcript-moves-aside-for-the-docked-session-panel:
|
||||
en: e70c9ec483c744d7
|
||||
zh: 022406f7ffae63a1
|
||||
/agent-note-the-transcript-moves-aside-for-the-docked-session-panel/problem:
|
||||
en: 5cab4a0fb9ad60c2
|
||||
zh: 074a63beaad1aa55
|
||||
/agent-note-the-transcript-moves-aside-for-the-docked-session-panel/decision:
|
||||
en: 2120aa7bf642ec99
|
||||
zh: af7493fa21357df0
|
||||
/agent-note-the-transcript-moves-aside-for-the-docked-session-panel/decision/the-body-owns-the-room-and-the-panel-asks-for-it:
|
||||
en: 133c15546f787723
|
||||
zh: 8e8cb9260af14207
|
||||
/agent-note-the-transcript-moves-aside-for-the-docked-session-panel/decision/one-probe-whose-answer-does-not-depend-on-the-room-made:
|
||||
en: 8dc78b8b67322164
|
||||
zh: c0f785ab10d9cbf0
|
||||
/agent-note-the-transcript-moves-aside-for-the-docked-session-panel/decision/width-handles-beside-the-docked-panel:
|
||||
en: f474cd213b7d7d90
|
||||
zh: c2a67709e43af311
|
||||
/agent-note-the-transcript-moves-aside-for-the-docked-session-panel/alternatives-considered:
|
||||
en: 5c820797fb214595
|
||||
zh: fccb1446abc9eaf5
|
||||
/agent-note-the-transcript-moves-aside-for-the-docked-session-panel/consequences:
|
||||
en: a3ac54b329c98be2
|
||||
zh: 8d31d1fe8391415f
|
||||
/agent-note-the-transcript-moves-aside-for-the-docked-session-panel/testing:
|
||||
en: ac6c37d6e85c30ba
|
||||
zh: 4d978cc079f323cc
|
||||
@@ -0,0 +1,50 @@
|
||||
# Agent Note: The transcript moves aside for the docked Session panel
|
||||
|
||||
Status: implemented
|
||||
|
||||
English | [中文](2026-11-16-session-panel-makes-room.zh.md)
|
||||
|
||||
## Problem
|
||||
|
||||
The [Session panel](2026-11-05-session-panel.md) docked only in a 348px end gutter. With the default transcript width that takes a Chat frame 1576px wide, and the left sidebar takes 280px of the window, so no window under about 1860px docks the panel in the gutter alone. On 1440px, 1512px, and 1728px windows it showed only as the overlay, which closes on the next press outside it. A reader who wants running subagents, background jobs, or change requests in view while working could not keep the panel open at those widths.
|
||||
|
||||
## Decision
|
||||
|
||||
While the docking preference is on and the end gutter is narrower than 348px, the Conversation body keeps that gutter free: the transcript column and the composer move toward the start edge by the missing gutter, at their own widths, and the panel docks in it. The body makes no room when that would leave less than the column's 32px side inset before it; the panel then hides, and the toggle opens it as the overlay. The column never narrows for the panel. The header toggle turns the docking preference off, which hides the panel and centers the transcript again. Nothing else opts in: the panel docks wherever it has room.
|
||||
|
||||
### The body owns the room, and the panel asks for it
|
||||
|
||||
[`ui-conversation`](../../../../packages/client/ui-conversation/README.md#end-reserve) owns the transcript's width axis, the scrollport, and the width handles, so it owns the room. A stylesheet asks for it by setting `--dsh-chat-end-reserve` on the Conversation body; the body derives `--dsh-chat-end-inset`, the scrollport's end padding, and `--dsh-chat-end-reserve-max`, the largest reserve the start gutter can give. The panel's stylesheet sets the reserve to 348px through a `:has()` rule that matches while its dock probe carries a mark, so the request needs no Slot prop and no render in the Chat View.
|
||||
|
||||
The body derives those lengths from the scrollport's width, which it measures and publishes as `--dsh-conversation-viewport-width`. Three boxes read the inset: the scrollport for its padding, the width handles in the body, and the [`ui-chat`](../../../../packages/client/ui-chat/README.md#scroll-ownership) aside layer, which reaches back across the inset so the panel sits at the scrollport's end edge. A length written with percentages resolves against a different box in each of them, and the scrollport's own content box changes with the inset. A measured pixel width gives all three the same value and does not change when the inset does.
|
||||
|
||||
### One probe whose answer does not depend on the room made
|
||||
|
||||
The panel's dock probe is 1px wide while the gutter holds the panel, or while the body's largest reserve covers that gutter. The second term reads the scrollport's width and the content width, not the inset, so the answer is the same before and after the transcript moves: the room the transcript makes cannot change the decision that asked for it, and the layout cannot oscillate. The plugin's state, its toggle, and its overlay rules are those of the gutter-only panel; only what its stylesheet counts as room widened.
|
||||
|
||||
### Width handles beside the docked panel
|
||||
|
||||
The handles follow the column: their positions take half the inset, and each takes its width from the gutter on its own side. While the body makes room, the reserve holds the column's end edge, so a drag moves only the start edge, and the width changes by the pointer's travel instead of twice it, on either handle. A column dragged wider than the start gutter can give takes its room back: the panel hides and the column centers, as a column dragged wide already hid the panel docked in the gutter.
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
- **A pin that opts in to making room.** The panel would dock at laptop widths only after the reader found and pressed a pin on it. In a wide window the pin changes nothing visible, and until it is pressed the default at laptop widths stays an overlay that closes on the next press. The panel docks wherever it can instead, and the toggle is the one control that hides it.
|
||||
- **Narrowing the column for the panel.** A floor such as 480px docks the panel in narrower frames, but it changes the reading width without the reader asking and makes the column's width depend on the panel as well as on the width the reader dragged. The column keeps its width, and a frame that cannot give the room shows the overlay.
|
||||
- **The docked panel covers the transcript.** It needs no layout change, but on a 1440px window the panel covers about 83px of the transcript column, and the actions at the end of each message, for as long as it shows.
|
||||
- **A measured reserve passed through Slot props.** The Conversation body, the Chat View, and the aside would each forward a callback for one consumer, and every change of the reserve would render the Chat View. A custom property needs neither.
|
||||
- **Percentages without a published width.** The inset would differ between the scrollport, the width handles, and the aside layer, and the largest reserve would read a width that the inset itself narrows.
|
||||
- **A second probe and a room type in the plugin's state.** The plugin would track the gutter and the reserve apart. Nothing reads them apart, so one probe reports their union and the plugin's interfaces stay as they were.
|
||||
- **No width handles while the transcript makes room.** The handles' positions stay simple, but the panel docks by default at laptop widths, so the reader would lose the width drag there.
|
||||
- **Making room in embedded Chat Views.** An embedded transcript's width is a percentage of its frame, so the inset would need that frame's own measure, and embedded frames are rarely wide enough. An embedded Chat View makes no room.
|
||||
|
||||
## Consequences
|
||||
|
||||
- The panel stays beside the transcript at laptop widths without a press. On a 1440px window with the sidebar open, the 742px column keeps its width and sits 143px toward the start edge while the panel is docked.
|
||||
- A reader who wants the transcript centered hides the panel from the toggle.
|
||||
- With the default transcript width the panel docks from a Chat frame about 1068px wide; below that, and beside a transcript dragged wide, it is the overlay it was.
|
||||
- A width drag beside the docked panel moves one edge of the column, not both.
|
||||
- `ui-conversation` publishes the scrollport's width and two derived lengths, pads its scrollport's end, and moves its width handles; `ui-chat`'s aside layer has an end margin and a gutter that counts the inset. Neither renders or observes anything more for them.
|
||||
|
||||
## Testing
|
||||
|
||||
Unit specs read the three stylesheets and evaluate the reserve, the inset, the gutter, the probe, and the handles around their boundaries, and drive a width drag at both scales. `apps/web/tests/session-panel-layout.e2e.ts` measures the shipped Web composition: the column, the composer, the width handles, the probe, and the panel across the gutter that holds the panel, the frames that make room, the last frame that can and the first that cannot, a reload, the toggle, and width drags that keep, lose, and regain the room.
|
||||
@@ -0,0 +1,50 @@
|
||||
# Agent Note: 正文为停靠的会话面板移开
|
||||
|
||||
Status: implemented
|
||||
|
||||
[English](2026-11-16-session-panel-makes-room.md) | 中文
|
||||
|
||||
## Problem
|
||||
|
||||
[会话面板](2026-11-05-session-panel.zh.md)原先只在 348px 的末端留白里停靠。默认正文宽度下,这要求 Chat 外框宽 1576px,而左侧栏占去窗口 280px,因此约 1860px 以下的窗口都无法只靠留白停靠面板。在 1440px、1512px 和 1728px 的窗口里,面板只能以浮层显示,在面板外按下指针就会关闭。想在工作时一直看到运行中的子智能体、后台任务或变更请求的用户,在这些宽度下无法让面板保持打开。
|
||||
|
||||
## Decision
|
||||
|
||||
停靠偏好开启、且末端留白窄于 348px 时,Conversation 主体空出这段留白:正文列和输入框保持各自宽度,向起始边缘移动所缺的留白,面板停靠在其中。如果移动后正文列之前剩不下它的 32px 侧边内边距,主体不让位;此时面板隐藏,按开关以浮层打开。正文列不会为面板变窄。标题栏开关关闭停靠偏好,面板随之隐藏,正文恢复居中。除此之外没有别的开关:面板在有位置的地方都会停靠。
|
||||
|
||||
### 位置归主体所有,面板提出申请
|
||||
|
||||
[`ui-conversation`](../../../../packages/client/ui-conversation/README.zh.md#end-reserve) 拥有正文的宽度轴、滚动容器和宽度手柄,因此这段位置也归它所有。样式表在 Conversation 主体上设置 `--dsh-chat-end-reserve` 来提出申请;主体据此推出滚动容器的末端内边距 `--dsh-chat-end-inset`,以及起始留白能让出的最大预留 `--dsh-chat-end-reserve-max`。面板的样式表通过一条 `:has()` 规则把预留设为 348px,该规则在停靠探针带有标记时匹配,因此申请不需要 Slot 属性,也不会让 Chat 视图重新渲染。
|
||||
|
||||
主体从滚动容器的宽度推出这些长度;它测量该宽度并发布为 `--dsh-conversation-viewport-width`。有三个盒子读取内边距:滚动容器用它作内边距,主体中的宽度手柄用它定位,[`ui-chat`](../../../../packages/client/ui-chat/README.zh.md#scroll-ownership) 的侧边层用它越过内边距延伸回去,让面板位于滚动容器的末端边缘。用百分比写出的长度在这三处会按不同的盒子解析,而滚动容器自身的内容盒又随内边距变化。测量得到的像素宽度让三处取得同一个值,并且不随内边距改变。
|
||||
|
||||
### 一个探针,结果不受让出的位置影响
|
||||
|
||||
留白放得下面板,或者主体的最大预留覆盖这段留白时,面板的停靠探针宽 1px。第二项读取的是滚动容器的宽度和正文宽度,而不是内边距,因此正文移动前后结果相同:正文让出的位置不会改变提出让位的那项判断,布局也不会来回振荡。插件的状态、开关和浮层规则与只靠留白停靠时相同,只是样式表认定的「有位置」范围变大了。
|
||||
|
||||
### 停靠面板旁的宽度手柄
|
||||
|
||||
手柄跟随正文列:它们的位置计入内边距的一半,各自的宽度取自所在一侧的留白。主体让位期间,预留固定了正文列的末端边缘,因此拖动只移动起始边缘,无论拖哪个手柄,宽度的变化都等于指针移动的距离而不是它的两倍。正文列被拖到超过起始留白能让出的宽度时会收回位置:面板隐藏,正文列居中;这与原先把正文拖宽会隐藏停靠在留白里的面板一致。
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
- **用图钉选择是否让位。** 用户要先找到并按下面板上的图钉,面板才会在笔记本宽度下停靠。在宽窗口里图钉没有任何可见效果;按下之前,笔记本宽度下的默认状态仍是点一下就关闭的浮层。现在面板在有位置的地方都会停靠,隐藏它只用开关这一个控件。
|
||||
- **为面板收窄正文列。** 设一个下限(例如 480px)可以让面板在更窄的外框里停靠,但会在用户没有要求的情况下改变阅读宽度,并且让正文列的宽度既取决于用户拖出的宽度,又取决于面板。正文列保持宽度,给不出位置的外框使用浮层。
|
||||
- **停靠的面板盖在正文上。** 不需要改动布局,但在 1440px 的窗口里,只要面板显示,就会一直遮住正文列约 83px 以及每条消息末尾的操作按钮。
|
||||
- **通过 Slot 属性传递测量出的预留值。** Conversation 主体、Chat 视图和侧边层都要为这一个使用方转发回调,预留值每次变化还会让 Chat 视图重新渲染。自定义属性两者都不需要。
|
||||
- **只用百分比,不发布宽度。** 内边距在滚动容器、宽度手柄和侧边层中会取得不同的值,而最大预留读到的宽度又会被内边距本身收窄。
|
||||
- **第二个探针,并在插件状态里区分两种位置。** 插件要分别记录留白和预留。没有任何地方需要区分它们,因此用一个探针报告两者的并集,插件的接口保持不变。
|
||||
- **正文让位期间不提供宽度手柄。** 手柄的定位更简单,但面板在笔记本宽度下默认停靠,用户在这些宽度下就无法拖动宽度。
|
||||
- **在嵌入的 Chat 视图中让位。** 嵌入的正文宽度是其外框的百分比,内边距需要该外框自己的测量值,而嵌入的外框很少够宽。嵌入的 Chat 视图不让位。
|
||||
|
||||
## Consequences
|
||||
|
||||
- 面板在笔记本宽度下无需任何操作就留在正文旁。在侧栏展开的 1440px 窗口里,面板停靠时 742px 的正文列宽度不变,向起始边缘偏移 143px。
|
||||
- 希望正文居中的用户用开关隐藏面板。
|
||||
- 默认正文宽度下,Chat 外框约 1068px 宽起面板停靠;更窄时,或者正文被拖得很宽时,面板仍是原来的浮层。
|
||||
- 在停靠面板旁拖动宽度时,正文列只移动一侧边缘,而不是两侧。
|
||||
- `ui-conversation` 发布滚动容器的宽度和两个推出的长度,给滚动容器的末端加内边距,并移动它的宽度手柄;`ui-chat` 的侧边层多了末端外边距,其留白包含内边距。两者都没有为此增加渲染或观察。
|
||||
|
||||
## Testing
|
||||
|
||||
单元测试读取三份样式表,并在边界附近计算预留、内边距、留白、探针和手柄的取值,还以两种比例驱动一次宽度拖动。`apps/web/tests/session-panel-layout.e2e.ts` 在随产品发布的 Web 组合中测量正文列、输入框、宽度手柄、探针和面板,覆盖放得下面板的留白、需要让位的外框、最后一个能让位和第一个不能让位的外框、刷新页面、开关,以及保持、失去和重新获得位置的宽度拖动。
|
||||
@@ -1,31 +0,0 @@
|
||||
# Bilingual-pair consistency record for 2026-11-16-session-panel-pin-makes-room.md (docs/i18n/README.md): per heading
|
||||
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
|
||||
# After editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write .agents/notes/implemented/feature/2026-11-16-session-panel-pin-makes-room.md
|
||||
/agent-note-a-pinned-session-panel-has-the-transcript-make-room:
|
||||
en: 0ff27427fe39e917
|
||||
zh: 785c97d304a8251c
|
||||
/agent-note-a-pinned-session-panel-has-the-transcript-make-room/problem:
|
||||
en: b057ffba84f49cc0
|
||||
zh: a94da96e3b88cb22
|
||||
/agent-note-a-pinned-session-panel-has-the-transcript-make-room/decision:
|
||||
en: 28d74b94f88d4f62
|
||||
zh: 1bd7b0bc7e84711f
|
||||
/agent-note-a-pinned-session-panel-has-the-transcript-make-room/decision/the-body-owns-the-room-and-the-panel-asks-for-it:
|
||||
en: 32162a47eda3346b
|
||||
zh: ef504938f57d89ad
|
||||
/agent-note-a-pinned-session-panel-has-the-transcript-make-room/decision/two-probes-that-do-not-depend-on-the-pin:
|
||||
en: 346ddc000d737c97
|
||||
zh: 91b930b9ea79baa6
|
||||
/agent-note-a-pinned-session-panel-has-the-transcript-make-room/decision/the-pin-and-the-docking-preference-stay-separate:
|
||||
en: 97af1842a791d745
|
||||
zh: 938605942fd434a1
|
||||
/agent-note-a-pinned-session-panel-has-the-transcript-make-room/alternatives-considered:
|
||||
en: 0867c07f5397ef57
|
||||
zh: 04a75d241d8049a6
|
||||
/agent-note-a-pinned-session-panel-has-the-transcript-make-room/consequences:
|
||||
en: 943b71da99af20f2
|
||||
zh: b7d8e5c15ab92ce4
|
||||
/agent-note-a-pinned-session-panel-has-the-transcript-make-room/testing:
|
||||
en: 8983497f0b7c2230
|
||||
zh: d7c4a7e93643d25d
|
||||
@@ -1,51 +0,0 @@
|
||||
# Agent Note: A pinned Session panel has the transcript make room
|
||||
|
||||
Status: implemented
|
||||
|
||||
English | [中文](2026-11-16-session-panel-pin-makes-room.zh.md)
|
||||
|
||||
## Problem
|
||||
|
||||
The [Session panel](2026-11-05-session-panel.md) docks only in a 348px end gutter. With the default transcript width that takes a Chat frame 1576px wide, and the left sidebar takes 280px of the window, so no window under about 1860px docks the panel. On 1440px, 1512px, and 1728px windows it shows only as the overlay, which closes on the next press outside it. A reader who wants running subagents, background jobs, or change requests in view while working cannot keep the panel open at those widths. The docking preference does not help: it says whether the panel shows where it already has room.
|
||||
|
||||
## Decision
|
||||
|
||||
The panel carries a pin: a toggle button in its top end corner, one preference for every Session, persisted in `localStorage` under `dsh.sessionPanel.held` and off by default. While the pin and the docking preference are both on and the gutter is narrower than 348px, the Conversation body keeps that gutter free. The transcript column and the composer move toward the start edge by the missing gutter at their own widths; once the column is 32px from the start edge it narrows instead. The panel then docks, and neither Escape nor an outside press hides it. The body makes no room when that would leave the column under 480px, a Chat frame under 860px; a pinned panel then behaves as an unpinned one until the frame is wide enough again. An unpinned panel behaves as it did.
|
||||
|
||||
### The body owns the room, and the panel asks for it
|
||||
|
||||
[`ui-conversation`](../../../../packages/client/ui-conversation/README.md#end-reserve) owns the transcript's width axis, the scrollport, and the width handles, so it owns the room. A stylesheet asks for it by setting `--dsh-chat-end-reserve` on the Conversation body; the body derives `--dsh-chat-end-inset`, the scrollport's end padding, and `--dsh-chat-end-reserve-max`, the largest reserve that leaves a 480px column. The panel's stylesheet sets the reserve to 348px through a `:has()` rule that matches while its gutter probe carries a mark, so the request needs no Slot prop and no render in the Chat View.
|
||||
|
||||
The body derives those lengths from the scrollport's width, which it measures and publishes as `--dsh-conversation-viewport-width`. Three boxes read the inset: the scrollport for its padding, the width handles in the body, and the [`ui-chat`](../../../../packages/client/ui-chat/README.md#scroll-ownership) aside layer, which reaches back across the inset so the panel sits at the scrollport's end edge. A length written with percentages resolves against a different box in each of them, and the scrollport's own content box changes with the inset. A measured pixel width gives all three the same value and does not change when the inset does.
|
||||
|
||||
### Two probes that do not depend on the pin
|
||||
|
||||
The panel reports two facts through 1px probes: its gutter holds it as the transcript stands, and the transcript can make that room. The gutter that the aside layer publishes counts the inset, and the gutter probe subtracts it, so a gutter the transcript made reads as no gutter. The plugin combines the facts with the pin: a panel can dock when its gutter holds it, or when the pin is on and the transcript can make room.
|
||||
|
||||
Keeping both facts independent of the pin gives the plugin what it needs before a press. It offers the pin on an overlay only where pinning would dock the panel. When the reader unpins a panel that only the pin kept beside the transcript, it knows the panel is about to lose its place and leaves it open as the overlay instead of removing it under the pointer. The room the transcript makes cannot change the decision that asked for it, so the layout cannot oscillate.
|
||||
|
||||
### The pin and the docking preference stay separate
|
||||
|
||||
The header toggle still hides and shows a pinned panel by flipping the docking preference, and hiding it gives the room back. Pinning also turns the docking preference on, because a reader who pins a panel wants it shown. The docking preference keeps its `localStorage` key, `dsh.sessionPanel.pinned`, so stored choices survive; the plugin's state calls it `docks` and the pin `pinned`.
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
- **A pinned panel covers the transcript.** It needs no layout change, but on a 1440px window the panel covers about 83px of the transcript column, and the actions at the end of each message, for as long as it is pinned. A panel kept open for a whole Session must not hide part of every reply.
|
||||
- **Making room whenever the panel shows.** It changes the transcript's position and width for every reader at laptop widths without a request. The [panel's own decision](2026-11-05-session-panel.md) keeps the transcript untouched by default, and the pin makes the trade the reader's choice.
|
||||
- **A measured reserve passed through Slot props.** The Conversation body, the Chat View, and the aside would each forward a callback for one consumer, and every change of the reserve would render the Chat View. A custom property needs neither.
|
||||
- **Percentages without a published width.** The inset would differ between the scrollport, the width handles, and the aside layer, and the test for a 480px column would read a width that the inset itself narrows.
|
||||
- **One probe whose rule follows the pin.** The plugin would not know whether an unpinned overlay can be pinned, or whether unpinning leaves the panel without room.
|
||||
- **Width handles while the transcript makes room.** The handles sit at the centered column's edges and a drag widens the column about its center. With the column's end edge held by the reserve, a drag would move only the start edge, at twice the pointer's speed. The handles do not show until the transcript centers again.
|
||||
- **Making room in embedded Chat Views.** An embedded transcript's width is a percentage of its frame, so the inset would need that frame's own measure, and embedded frames are rarely 860px wide. An embedded Chat View makes no room.
|
||||
|
||||
## Consequences
|
||||
|
||||
- A reader can keep the panel beside the transcript on laptop widths. On a 1440px window with the sidebar open, the 742px column keeps its width and moves 143px toward the start; on a 1280px window it narrows to 613px.
|
||||
- Below an 860px Chat frame the pin has no effect, and the panel is the overlay it was.
|
||||
- The width handles do not show while the transcript makes room; the reader unpins or hides the panel to drag the width.
|
||||
- `ui-conversation` publishes the scrollport's width and two derived lengths and pads its scrollport's end; `ui-chat`'s aside layer has an end margin and a gutter that counts the inset. Neither renders or observes anything more for them.
|
||||
- Each mounted panel observes two probes instead of one; both call back only when a decision flips.
|
||||
|
||||
## Testing
|
||||
|
||||
Unit specs read the three stylesheets and evaluate the reserve, the inset, the gutter, and both probes around their boundaries. `apps/web/tests/session-panel-layout.e2e.ts` measures the shipped Web composition: the column, the composer, the width handles, the probes, the panel, and the pin while pinning, narrowing to the 480px column, crossing that boundary, reloading, hiding from the toggle, and unpinning.
|
||||
@@ -1,51 +0,0 @@
|
||||
# Agent Note: 固定的会话面板让正文让出位置
|
||||
|
||||
Status: implemented
|
||||
|
||||
[English](2026-11-16-session-panel-pin-makes-room.md) | 中文
|
||||
|
||||
## Problem
|
||||
|
||||
[会话面板](2026-11-05-session-panel.zh.md)只在 348px 的末端留白里停靠。默认正文宽度下,这要求 Chat 外框宽 1576px,而左侧栏占去窗口 280px,因此约 1860px 以下的窗口都无法停靠面板。在 1440px、1512px 和 1728px 的窗口里,面板只能以浮层显示,在面板外按下指针就会关闭。想在工作时一直看到运行中的子智能体、后台任务或变更请求的用户,在这些宽度下无法让面板保持打开。停靠偏好帮不上忙:它只决定面板在已有空间的地方是否显示。
|
||||
|
||||
## Decision
|
||||
|
||||
面板带一个图钉:位于面板顶部末端角的切换按钮,所有会话共用一个偏好,存放在 `localStorage` 的 `dsh.sessionPanel.held` 中,默认关闭。图钉和停靠偏好都开启、且留白窄于 348px 时,Conversation 主体空出这段留白。正文列和输入框保持各自宽度,向起始边缘移动所缺的留白;正文列距起始边缘只剩 32px 后,改为变窄。面板随即停靠,按 Esc 或在面板外按下指针都不会隐藏它。如果让位会使正文列窄于 480px,也就是 Chat 外框窄于 860px,主体不让位;此时已固定的面板与未固定时相同,直到外框再次够宽。未固定的面板行为不变。
|
||||
|
||||
### 位置归主体所有,面板提出申请
|
||||
|
||||
[`ui-conversation`](../../../../packages/client/ui-conversation/README.zh.md#end-reserve) 拥有正文的宽度轴、滚动容器和宽度手柄,因此这段位置也归它所有。样式表在 Conversation 主体上设置 `--dsh-chat-end-reserve` 来提出申请;主体据此推出滚动容器的末端内边距 `--dsh-chat-end-inset`,以及让正文列保持 480px 时能给出的最大预留 `--dsh-chat-end-reserve-max`。面板的样式表通过一条 `:has()` 规则把预留设为 348px,该规则在留白探针带有标记时匹配,因此申请不需要 Slot 属性,也不会让 Chat 视图重新渲染。
|
||||
|
||||
主体从滚动容器的宽度推出这些长度;它测量该宽度并发布为 `--dsh-conversation-viewport-width`。有三个盒子读取内边距:滚动容器用它作内边距,主体中的宽度手柄用它定位,[`ui-chat`](../../../../packages/client/ui-chat/README.zh.md#scroll-ownership) 的侧边层用它越过内边距延伸回去,让面板位于滚动容器的末端边缘。用百分比写出的长度在这三处会按不同的盒子解析,而滚动容器自身的内容盒又随内边距变化。测量得到的像素宽度让三处取得同一个值,并且不随内边距改变。
|
||||
|
||||
### 两个不依赖图钉的探针
|
||||
|
||||
面板通过 1px 的探针报告两项事实:正文不动时留白放得下面板,以及正文能让出这段位置。侧边层发布的留白包含内边距,留白探针再把它减掉,因此正文让出的留白不算作留白。插件把这两项事实与图钉结合:留白放得下面板,或者图钉已开启且正文能让位时,面板可以停靠。
|
||||
|
||||
两项事实都不依赖图钉,插件因此在按下之前就掌握所需信息。只有固定后能停靠时,它才在浮层上提供图钉。用户取消固定一个仅靠图钉留在正文旁的面板时,它知道面板即将失去位置,于是让面板保持打开并变为浮层,而不是在指针下把它移走。正文让出的位置不会改变提出让位的那项判断,布局因此不会来回振荡。
|
||||
|
||||
### 图钉与停靠偏好保持独立
|
||||
|
||||
标题栏开关仍然通过切换停靠偏好来隐藏和显示已固定的面板,隐藏后让出的位置还给正文。固定面板同时会开启停靠偏好,因为固定面板的用户希望它显示出来。停靠偏好沿用 `localStorage` 键 `dsh.sessionPanel.pinned`,已保存的选择得以保留;插件状态中把它称为 `docks`,把图钉称为 `pinned`。
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
- **固定的面板盖在正文上。** 不需要改动布局,但在 1440px 的窗口里,只要面板处于固定状态,就会一直遮住正文列约 83px 以及每条消息末尾的操作按钮。整个会话期间都打开的面板不能遮住每条回复的一部分。
|
||||
- **面板一显示就让位。** 这会在用户没有要求的情况下,改变笔记本宽度下所有用户的正文位置和宽度。[面板自身的决策](2026-11-05-session-panel.zh.md)默认不动正文,图钉把这项取舍交给用户选择。
|
||||
- **通过 Slot 属性传递测量出的预留值。** Conversation 主体、Chat 视图和侧边层都要为这一个使用方转发回调,预留值每次变化还会让 Chat 视图重新渲染。自定义属性两者都不需要。
|
||||
- **只用百分比,不发布宽度。** 内边距在滚动容器、宽度手柄和侧边层中会取得不同的值,而判断能否保留 480px 正文列时读到的宽度又会被内边距本身收窄。
|
||||
- **一个探针,规则随图钉变化。** 插件将无法知道未固定的浮层能否固定,也无法知道取消固定后面板是否还有位置。
|
||||
- **正文让位期间保留宽度手柄。** 手柄位于居中正文列的两侧,拖动时正文列以中心为基准变宽。正文列的末端边缘被预留固定后,拖动只会移动起始边缘,速度是指针的两倍。手柄在正文重新居中之前不显示。
|
||||
- **在嵌入的 Chat 视图中让位。** 嵌入的正文宽度是其外框的百分比,内边距需要该外框自己的测量值,而嵌入的外框很少有 860px 宽。嵌入的 Chat 视图不让位。
|
||||
|
||||
## Consequences
|
||||
|
||||
- 用户可以在笔记本宽度下把面板留在正文旁。在侧栏展开的 1440px 窗口里,742px 的正文列宽度不变,向起始方向移动 143px;在 1280px 的窗口里,正文列收窄到 613px。
|
||||
- Chat 外框窄于 860px 时图钉不起作用,面板仍是原来的浮层。
|
||||
- 正文让位期间不显示宽度手柄;用户需要取消固定或隐藏面板后再拖动宽度。
|
||||
- `ui-conversation` 发布滚动容器的宽度和两个推出的长度,并给滚动容器的末端加内边距;`ui-chat` 的侧边层多了末端外边距,其留白包含内边距。两者都没有为此增加渲染或观察。
|
||||
- 每个已挂载的面板观察两个探针而不是一个;两者都只在判断翻转时回调。
|
||||
|
||||
## Testing
|
||||
|
||||
单元测试读取三份样式表,并在边界附近计算预留、内边距、留白和两个探针的取值。`apps/web/tests/session-panel-layout.e2e.ts` 在随产品发布的 Web 组合中测量:固定、收窄到 480px 正文列、越过该边界、刷新页面、用开关隐藏以及取消固定时的正文列、输入框、宽度手柄、探针、面板和图钉。
|
||||
@@ -627,7 +627,8 @@ describe('web e2e: agent teamwork panel', () => {
|
||||
expect(await panel.count()).toBe(1)
|
||||
await page.mouse.click(2, 2)
|
||||
await panel.waitFor({ state: 'detached' })
|
||||
await page.setViewportSize(viewport)
|
||||
// A width whose transcript cannot move aside for the panel, so the toggle opens it over the conversation.
|
||||
await page.setViewportSize({ width: 1100, height: viewport.height })
|
||||
await trigger.focus()
|
||||
await page.keyboard.press('Enter')
|
||||
await tasksHeading.waitFor()
|
||||
@@ -675,8 +676,9 @@ describe('web e2e: agent teamwork panel', () => {
|
||||
const row = board.locator(`[data-team-task="${task.id}"]`)
|
||||
const emptyRow = board.locator(`[data-team-task="${completed.id}"]`)
|
||||
onTestFinished(() => page.setViewportSize(viewport))
|
||||
// Constrain the panel so closed and expanded task rows both exercise its scrollbar.
|
||||
await page.setViewportSize({ width: viewport.width, height: 500 })
|
||||
// Constrain the panel so closed and expanded task rows both exercise its scrollbar, at a width whose transcript
|
||||
// cannot move aside for it: the panel opens over the conversation and stays mounted as the window narrows below.
|
||||
await page.setViewportSize({ width: 1100, height: 500 })
|
||||
await showSharedTasksSection(page)
|
||||
await row.waitFor()
|
||||
expect(await board.locator('[data-team-task-details], article').count()).toBe(0)
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
assertFixtureInventory, captureStableAria, compareOrRefreshGolden, fixtureUserPrompts,
|
||||
launchWebScaffold, selectedSessionFixture, watchConsole, webSnapshotMode, type WebScaffold,
|
||||
} from './scaffold.ts'
|
||||
import { connectFreshWorkspaceZh, saveFailureShot, ZH_BROWSER_LOCALE } from './support.ts'
|
||||
import { connectFreshWorkspaceZh, saveFailureShot, startWithSessionPanelHidden, ZH_BROWSER_LOCALE } from './support.ts'
|
||||
|
||||
const SNAPSHOT_DIR = fileURLToPath(new URL('../../../snapshots/web/deepseek-messages-chat', import.meta.url))
|
||||
const FIXTURE = join(SNAPSHOT_DIR, 'session.v3.jsonl')
|
||||
@@ -38,6 +38,7 @@ describe.skipIf(MODE === 'record')('web e2e: DeepSeek Messages conversation', ()
|
||||
await scaffold.ctx.agentDefaultModel.saveSelection({ provider: 'deepseek-messages', model: 'deepseek-v4-flash' })
|
||||
browser = await chromium.launch()
|
||||
page = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: ZH_BROWSER_LOCALE })
|
||||
await startWithSessionPanelHidden(page)
|
||||
tripwire = watchConsole(page)
|
||||
await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
|
||||
await connectFreshWorkspaceZh(page, scaffold.workspaceCwd)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
- complementary "会话面板":
|
||||
- button "固定会话面板"
|
||||
- region "环境":
|
||||
- heading "环境" [level=2]
|
||||
- text: dsh-{{worktree}} {{cwd}}/workspace/.agents/worktrees dsh-{{worktree}} 工作树 · 基于 release
|
||||
|
||||
@@ -18,7 +18,8 @@ import {
|
||||
webSnapshotMode, type WebScaffold,
|
||||
} from './scaffold.ts'
|
||||
import {
|
||||
connectFreshWorkspaceZh, hideSessionPanel, saveFailureShot, sessionPanelToggle, showSessionPanel, writeComposerDraft, ZH_BROWSER_LOCALE,
|
||||
connectFreshWorkspaceZh, dismissSessionPanel, hideSessionPanel, saveFailureShot, sessionPanelToggle, showSessionPanel,
|
||||
writeComposerDraft, ZH_BROWSER_LOCALE,
|
||||
} from './support.ts'
|
||||
|
||||
declare global {
|
||||
@@ -855,6 +856,8 @@ it.skipIf(MODE === 'record')('starts a Session in a worktree before its first me
|
||||
expect(notice).toBeLessThan(events.findIndex(event => event.type === 'assistant/message'))
|
||||
|
||||
// A change request bound the way a `gh pr create` result binds one.
|
||||
// The panel docked beside the conversation above; the toggle's attention mark is read with it hidden.
|
||||
await dismissSessionPanel(page)
|
||||
scaffold.ctx.forgeSession.track(session, PULL)
|
||||
await page.getByRole('button', { name: TOGGLE_ATTENTION, exact: true }).waitFor({ timeout: 20_000 })
|
||||
expect(await sessionPanelToggle(page).getAttribute('aria-expanded')).toBe('false')
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
webSnapshotMode,
|
||||
type WebScaffold,
|
||||
} from './scaffold.ts'
|
||||
import { saveFailureShot } from './support.ts'
|
||||
import { saveFailureShot, startWithSessionPanelHidden } from './support.ts'
|
||||
|
||||
const MODE = webSnapshotMode()
|
||||
const OVERLAY = fileURLToPath(new URL('../../../packages/experimental/webhook-github/examples/github-review/cordis.yml', import.meta.url))
|
||||
@@ -107,6 +107,7 @@ describe.skipIf(MODE === 'record')('web e2e: GitHub ready-for-review', () => {
|
||||
|
||||
browser = await chromium.launch()
|
||||
page = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: 'en-US' })
|
||||
await startWithSessionPanelHidden(page)
|
||||
await page.addInitScript(() => { localStorage.setItem('dsh.locale', 'en') })
|
||||
tripwire = watchConsole(page)
|
||||
await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/**
|
||||
* Session panel layout in the shipped Web composition. The panel's stylesheet
|
||||
* decides whether the Chat View's end gutter holds the docked panel, or the
|
||||
* transcript can make that room for a pinned panel, and tells the plugin
|
||||
* through two 1px probes, and it lays out the rows that contributors mark.
|
||||
* jsdom cannot evaluate that stylesheet, so this measures the probes, the
|
||||
* panel, and the toggle around the docking boundary, the transcript, the
|
||||
* composer, and the width handles around a pinned panel, the drag that
|
||||
* reorders sections, and the working folder row without and with a directory
|
||||
* context menu.
|
||||
* decides whether the docked panel has room, in the Chat View's end gutter or
|
||||
* by the transcript moving into its start gutter, and tells the plugin
|
||||
* through a 1px dock probe, and it lays out the rows that contributors mark.
|
||||
* jsdom cannot evaluate that stylesheet, so this measures the probe, the
|
||||
* panel, the toggle, the transcript, the composer, and the width handles
|
||||
* around the docking boundaries, a width drag beside the docked panel, the
|
||||
* drag that reorders sections, and the working folder row without and with a
|
||||
* directory context menu.
|
||||
*/
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
@@ -18,7 +18,7 @@ import { createLaunchEnvironmentSnapshot } from '@deepseek-ai/dsh-launch-environ
|
||||
import type { SessionId } from '@deepseek-ai/dsh-session'
|
||||
import { brandString } from '@deepseek-ai/dsh-brand'
|
||||
import { launchWebScaffold, seedSession, watchConsole, webSnapshotMode, type WebScaffold } from './scaffold.ts'
|
||||
import { newEnglishPage, saveFailureShot } from './support.ts'
|
||||
import { saveFailureShot } from './support.ts'
|
||||
|
||||
const FIXTURE = fileURLToPath(new URL('../../../snapshots/web/fresh-round-trip/session.v3.jsonl', import.meta.url))
|
||||
const MODE = webSnapshotMode()
|
||||
@@ -28,12 +28,21 @@ const TRANSCRIPT = 880
|
||||
/** The gutter that holds the docked panel: 40px clear of the transcript, its 300px minimum width, and the 8px edge inset. */
|
||||
const DOCK_GUTTER = 348
|
||||
|
||||
/**
|
||||
* A page at the lane's baseline size whose origin stores no docking choice.
|
||||
* The lane's standard page starts with docking off; this file measures the
|
||||
* panel as a reader first meets it.
|
||||
*/
|
||||
function newPanelPage(browser: Browser): Promise<Page> {
|
||||
return browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: 'en-US', timezoneId: 'Asia/Shanghai' })
|
||||
}
|
||||
|
||||
/** What the layout says about docking: the gutter, the probe, the panel's presentation and insets, and the toggle. */
|
||||
function docking(page: Page) {
|
||||
return page.evaluate(() => {
|
||||
const layer = document.querySelector<HTMLElement>('[data-chat-aside]')
|
||||
const column = document.querySelector<HTMLElement>('[data-chat-flow]')
|
||||
const probe = document.querySelector<HTMLElement>('[data-session-panel-probe="gutter"]')
|
||||
const probe = document.querySelector<HTMLElement>('[data-session-panel-probe]')
|
||||
const toggle = document.querySelector<HTMLElement>('[data-session-panel-toggle]')
|
||||
if (layer === null || column === null || probe === null || toggle === null) {
|
||||
throw new Error('aside layer, transcript column, dock probe, or panel toggle is missing')
|
||||
@@ -62,17 +71,16 @@ async function openSeed(page: Page): Promise<void> {
|
||||
return session.isVisible()
|
||||
}, { timeout: 15_000 }).toBe(true)
|
||||
await session.click()
|
||||
await page.locator('[data-session-panel-probe="gutter"]').waitFor({ state: 'attached', timeout: 30_000 })
|
||||
await page.locator('[data-session-panel-probe]').waitFor({ state: 'attached', timeout: 30_000 })
|
||||
}
|
||||
|
||||
/**
|
||||
* What the layout says around a pinned panel: the frame and the transcript
|
||||
* column in it, the scrollport's end inset, how far the composer card's
|
||||
* center sits from the column's, the width handles, both probes, the panel,
|
||||
* and its pin. `pin.center` is the glyph column's distance from the panel's
|
||||
* end edge and `pin.top` the button's from its top edge.
|
||||
* What the layout says around the panel: the frame and the transcript column
|
||||
* in it, the scrollport's end inset, how far the composer card's center sits
|
||||
* from the column's, each width handle's width and its distance from the
|
||||
* column edge it follows, the dock probe, the panel, and the toggle.
|
||||
*/
|
||||
function pinning(page: Page) {
|
||||
function layout(page: Page) {
|
||||
return page.evaluate(() => {
|
||||
const need = (selector: string): HTMLElement => {
|
||||
const element = document.querySelector<HTMLElement>(selector)
|
||||
@@ -84,8 +92,10 @@ function pinning(page: Page) {
|
||||
const card = need('[data-composer-card]').getBoundingClientRect()
|
||||
const panel = document.querySelector<HTMLElement>('[data-session-panel]')
|
||||
const box = panel?.getBoundingClientRect()
|
||||
const pin = panel?.querySelector<HTMLElement>('[data-session-panel-pin]')
|
||||
const pinBox = pin?.getBoundingClientRect()
|
||||
const handle = (side: 'left' | 'right'): { width: number; gap: number } => {
|
||||
const strip = need(`[data-width-handle="${side}"]`).getBoundingClientRect()
|
||||
return { width: strip.width, gap: side === 'left' ? flow.left - strip.right : strip.left - flow.right }
|
||||
}
|
||||
return {
|
||||
frame: frame.width,
|
||||
column: flow.width,
|
||||
@@ -93,22 +103,11 @@ function pinning(page: Page) {
|
||||
after: frame.right - flow.right,
|
||||
inset: getComputedStyle(need('[data-conversation-scroll]')).paddingInlineEnd,
|
||||
composerOffset: (card.left + card.right - flow.left - flow.right) / 2,
|
||||
handles: [...document.querySelectorAll<HTMLElement>('[data-width-handle]')].map(handle => handle.getBoundingClientRect().width),
|
||||
probes: {
|
||||
gutter: need('[data-session-panel-probe="gutter"]').getBoundingClientRect().width,
|
||||
reserve: need('[data-session-panel-probe="reserve"]').getBoundingClientRect().width,
|
||||
},
|
||||
handles: { left: handle('left'), right: handle('right') },
|
||||
probe: need('[data-session-panel-probe]').getBoundingClientRect().width,
|
||||
presentation: panel?.dataset['sessionPanel'] ?? null,
|
||||
expanded: need('[data-session-panel-toggle]').getAttribute('aria-expanded'),
|
||||
panel: box === undefined ? null : { width: box.width, clear: box.left - flow.right, edge: frame.right - box.right },
|
||||
pin: pin === null || pin === undefined || pinBox === undefined || box === undefined
|
||||
? null
|
||||
: {
|
||||
pressed: pin.getAttribute('aria-pressed'),
|
||||
target: [pinBox.width, pinBox.height],
|
||||
center: box.right - (pinBox.left + pinBox.width / 2),
|
||||
top: pinBox.top - box.top,
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -162,12 +161,6 @@ describe.skipIf(MODE === 'record')('web e2e: Session panel layout', () => {
|
||||
/** Viewport width the application keeps outside the Chat frame. */
|
||||
let chrome = 0
|
||||
|
||||
/** Resize the window so the Chat View's end gutter is exactly `gutter`, and wait for the layout to follow. */
|
||||
async function setGutter(gutter: number): Promise<void> {
|
||||
await page.setViewportSize({ width: TRANSCRIPT + 2 * gutter + chrome, height: page.viewportSize()!.height })
|
||||
await expect.poll(async () => (await docking(page)).gutter, { timeout: 10_000 }).toBe(gutter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize the window so the Chat frame is exactly `width` wide, and wait for
|
||||
* the layout to follow: the body publishes the scrollport's width a frame
|
||||
@@ -185,11 +178,21 @@ describe.skipIf(MODE === 'record')('web e2e: Session panel layout', () => {
|
||||
}), { timeout: 10_000 }).toBe(width)
|
||||
}
|
||||
|
||||
/** Resize the window so the gutter on each side of the centered 880px transcript is exactly `gutter`. */
|
||||
function setGutter(gutter: number): Promise<void> {
|
||||
return setFrame(TRANSCRIPT + 2 * gutter)
|
||||
}
|
||||
|
||||
/** Forget a dragged transcript width, so the next resize publishes the default again. */
|
||||
function forgetWidth(): Promise<void> {
|
||||
return page.evaluate(() => { localStorage.removeItem('dsh.conversation.contentWidth') })
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
scaffold = await launchWebScaffold()
|
||||
await seedSession(scaffold, await readFile(FIXTURE, 'utf8'), SEED_ID)
|
||||
browser = await chromium.launch()
|
||||
page = await newEnglishPage(browser)
|
||||
page = await newPanelPage(browser)
|
||||
await page.emulateMedia({ reducedMotion: 'reduce' })
|
||||
tripwire = watchConsole(page)
|
||||
await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
|
||||
@@ -210,155 +213,156 @@ describe.skipIf(MODE === 'record')('web e2e: Session panel layout', () => {
|
||||
if (failures.length > 0) throw new AggregateError(failures, 'Session panel layout teardown failed')
|
||||
})
|
||||
|
||||
it('docks exactly from the gutter that holds the panel at its minimum width', async () => {
|
||||
it('docks in the end gutter where it holds the panel, and elsewhere has the transcript move into its start gutter', async () => {
|
||||
onTestFailed(() => saveFailureShot(page, 'web-e2e-session-panel-dock'))
|
||||
await openSession()
|
||||
expect(Number.isInteger(chrome)).toBe(true)
|
||||
const toggle = page.locator('[data-session-panel-toggle]')
|
||||
const docked = { probe: 1, presentation: 'docked', expanded: 'true' }
|
||||
|
||||
await setGutter(DOCK_GUTTER - 1)
|
||||
await shows(page, null)
|
||||
expect(await docking(page)).toEqual({ gutter: DOCK_GUTTER - 1, probe: 0, presentation: null, expanded: 'false', panel: null })
|
||||
|
||||
// Half a pixel short, the probe is half a pixel wide and the panel stays hidden.
|
||||
await setGutter(DOCK_GUTTER - 0.5)
|
||||
expect(await docking(page)).toEqual({ gutter: DOCK_GUTTER - 0.5, probe: 0.5, presentation: null, expanded: 'false', panel: null })
|
||||
|
||||
await setGutter(DOCK_GUTTER)
|
||||
await shows(page, 'docked')
|
||||
expect(await docking(page)).toEqual({
|
||||
gutter: DOCK_GUTTER, probe: 1, presentation: 'docked', expanded: 'true', panel: { width: 300, clear: 40, edge: 8 },
|
||||
})
|
||||
|
||||
// A wider gutter widens the panel to its maximum at the same edge inset; the probe stays 1px.
|
||||
// A wide gutter: the transcript is centered and the panel is at its maximum width.
|
||||
await setGutter(DOCK_GUTTER + 100)
|
||||
expect(await docking(page)).toEqual({
|
||||
gutter: DOCK_GUTTER + 100, probe: 1, presentation: 'docked', expanded: 'true', panel: { width: 360, clear: 80, edge: 8 },
|
||||
await shows(page, 'docked')
|
||||
const wide = await layout(page)
|
||||
expect(wide).toMatchObject({
|
||||
column: TRANSCRIPT, before: DOCK_GUTTER + 100, after: DOCK_GUTTER + 100, inset: '0px', composerOffset: 0, ...docked,
|
||||
panel: { width: 360, clear: 80, edge: 8 },
|
||||
})
|
||||
expect([wide.handles.left.width, wide.handles.right.width]).toEqual([10, 10])
|
||||
|
||||
await setGutter(DOCK_GUTTER - 1)
|
||||
await shows(page, null)
|
||||
expect((await docking(page)).expanded).toBe('false')
|
||||
expect(tripwire.pageErrors).toEqual([])
|
||||
})
|
||||
|
||||
it('floats narrower than it docks, at the same edge inset, and docks once the gutter holds it', async () => {
|
||||
onTestFailed(() => saveFailureShot(page, 'web-e2e-session-panel-overlay'))
|
||||
await openSession()
|
||||
const toggle = page.locator('[data-session-panel-toggle]')
|
||||
await setGutter(260)
|
||||
await shows(page, null)
|
||||
await toggle.click()
|
||||
await shows(page, 'overlay')
|
||||
const overlay = await docking(page)
|
||||
expect(overlay).toMatchObject({ probe: 0, presentation: 'overlay', expanded: 'true', panel: { width: 280, edge: 8 } })
|
||||
// The overlay covers part of the transcript instead of keeping clear of it.
|
||||
expect(overlay.panel?.clear).toBeLessThan(0)
|
||||
|
||||
await page.keyboard.press('Escape')
|
||||
await shows(page, null)
|
||||
expect((await docking(page)).expanded).toBe('false')
|
||||
|
||||
// An open overlay gives way to the docked panel when the window widens enough.
|
||||
await toggle.click()
|
||||
await shows(page, 'overlay')
|
||||
// The narrowest gutter that holds the panel by itself.
|
||||
await setGutter(DOCK_GUTTER)
|
||||
await shows(page, 'docked')
|
||||
expect(await docking(page)).toMatchObject({ probe: 1, expanded: 'true', panel: { width: 300, clear: 40, edge: 8 } })
|
||||
expect(tripwire.pageErrors).toEqual([])
|
||||
})
|
||||
|
||||
it('has the transcript make room for a pinned panel, down to a 480px column, and gives the room back when unpinned', async () => {
|
||||
onTestFailed(() => saveFailureShot(page, 'web-e2e-session-panel-pin'))
|
||||
await openSession()
|
||||
const toggle = page.locator('[data-session-panel-toggle]')
|
||||
const pin = page.locator('[data-session-panel] [data-session-panel-pin]')
|
||||
const stored = (): Promise<string | null> => page.evaluate(() => localStorage.getItem('dsh.sessionPanel.held'))
|
||||
/** Press the scrollport's start corner, outside the panel and off the transcript. */
|
||||
const pressOutside = (): Promise<void> => page.locator('[data-conversation-scroll]').click({ position: { x: 8, y: 8 } })
|
||||
const held = { presentation: 'docked', expanded: 'true', panel: { width: 300, clear: 40, edge: 8 } }
|
||||
const pressed = { pressed: 'true', target: [24, 24], center: 22, top: 10 }
|
||||
|
||||
// A 260px gutter: the 880px column leaves no room to dock, and the transcript could make it.
|
||||
await setFrame(TRANSCRIPT + 2 * 260)
|
||||
await shows(page, null)
|
||||
expect(await pinning(page)).toMatchObject({
|
||||
column: TRANSCRIPT, before: 260, after: 260, inset: '0px', handles: [10, 10], probes: { gutter: 0, reserve: 1 }, expanded: 'false',
|
||||
expect(await layout(page)).toMatchObject({
|
||||
before: DOCK_GUTTER, after: DOCK_GUTTER, inset: '0px', ...docked, panel: { width: 300, clear: 40, edge: 8 },
|
||||
})
|
||||
await toggle.click()
|
||||
await shows(page, 'overlay')
|
||||
// The pin sits on the first title line, its glyph in the column of the rows' More buttons: 8px of panel inset and 14px.
|
||||
expect((await pinning(page)).pin).toEqual({ ...pressed, pressed: 'false' })
|
||||
expect(await stored()).toBeNull()
|
||||
|
||||
// Pinned, the panel docks: the column and the composer move aside by the missing 88px, twice over, and keep their width.
|
||||
await pin.click()
|
||||
await shows(page, 'docked')
|
||||
expect(await pinning(page)).toEqual({
|
||||
frame: TRANSCRIPT + 2 * 260, column: TRANSCRIPT, before: 172, after: DOCK_GUTTER, inset: '176px', composerOffset: 0,
|
||||
handles: [0, 0], probes: { gutter: 0, reserve: 1 }, ...held, pin: pressed,
|
||||
// One pixel short: the column moves that pixel toward the start edge, at its own width, and the panel stays docked.
|
||||
await setGutter(DOCK_GUTTER - 1)
|
||||
expect(await layout(page)).toMatchObject({
|
||||
column: TRANSCRIPT, before: DOCK_GUTTER - 2, after: DOCK_GUTTER, inset: '2px', composerOffset: 0, ...docked,
|
||||
panel: { width: 300, clear: 40, edge: 8 },
|
||||
})
|
||||
expect(await stored()).toBe('true')
|
||||
// Neither an outside press nor Escape closes it.
|
||||
await pressOutside()
|
||||
|
||||
// A 260px gutter: the column and the composer move 88px, twice over, and keep their width.
|
||||
await setGutter(260)
|
||||
const moved = await layout(page)
|
||||
expect(moved).toMatchObject({
|
||||
column: TRANSCRIPT, before: 172, after: DOCK_GUTTER, inset: '176px', composerOffset: 0, ...docked,
|
||||
panel: { width: 300, clear: 40, edge: 8 },
|
||||
})
|
||||
// The width handles moved with the column and keep their width.
|
||||
expect([moved.handles.left.width, moved.handles.right.width]).toEqual([10, 10])
|
||||
expect(moved.handles.left.gap).toBeCloseTo(wide.handles.left.gap, 1)
|
||||
expect(moved.handles.right.gap).toBeCloseTo(wide.handles.right.gap, 1)
|
||||
// Neither a press in the transcript's start gutter nor Escape closes the docked panel.
|
||||
await page.locator('[data-conversation-scroll]').click({ position: { x: 8, y: 8 } })
|
||||
await page.keyboard.press('Escape')
|
||||
expect(await pinning(page)).toMatchObject(held)
|
||||
expect(await layout(page)).toMatchObject({ before: 172, after: DOCK_GUTTER, ...docked })
|
||||
|
||||
// The start gutter is down to the transcript's 32px side inset: the column narrows instead.
|
||||
await setFrame(1000)
|
||||
expect(await pinning(page)).toMatchObject({ column: 620, before: 32, after: DOCK_GUTTER, inset: '316px', composerOffset: 0, ...held })
|
||||
// The narrowest frame that makes room leaves a 480px column.
|
||||
await setFrame(860)
|
||||
expect(await pinning(page)).toMatchObject({ column: 480, before: 32, after: DOCK_GUTTER, inset: '316px', ...held })
|
||||
// One pixel less makes none: the transcript centers again and the panel is left to the overlay.
|
||||
await setFrame(859)
|
||||
await shows(page, null)
|
||||
expect(await pinning(page)).toMatchObject({
|
||||
column: 680, before: 89.5, after: 89.5, inset: '0px', handles: [10, 10], probes: { gutter: 0, reserve: 0 }, expanded: 'false', panel: null,
|
||||
})
|
||||
// The toggle hides it, which gives the room back, and shows it again.
|
||||
await toggle.click()
|
||||
await shows(page, 'overlay')
|
||||
expect(await pinning(page)).toMatchObject({ inset: '0px', panel: { width: 280, edge: 8 }, pin: pressed })
|
||||
await page.keyboard.press('Escape')
|
||||
await shows(page, null)
|
||||
// Once the frame makes room again, the pinned panel docks without the toggle.
|
||||
await setFrame(860)
|
||||
expect(await layout(page)).toMatchObject({ before: 260, after: 260, inset: '0px', probe: 1, presentation: null, expanded: 'false' })
|
||||
await toggle.click()
|
||||
await shows(page, 'docked')
|
||||
expect(await pinning(page)).toMatchObject({ column: 480, after: DOCK_GUTTER, ...held })
|
||||
expect(await layout(page)).toMatchObject({ before: 172, after: DOCK_GUTTER, inset: '176px', ...docked })
|
||||
|
||||
// The pin survives a reload: the panel comes back beside the transcript.
|
||||
await setFrame(TRANSCRIPT + 2 * 260)
|
||||
// A reload docks it again, with the transcript already moved.
|
||||
await page.reload({ waitUntil: 'load' })
|
||||
await openSeed(page)
|
||||
await shows(page, 'docked')
|
||||
expect(await pinning(page)).toMatchObject({ column: TRANSCRIPT, before: 172, after: DOCK_GUTTER, inset: '176px', ...held, pin: pressed })
|
||||
expect(await layout(page)).toMatchObject({ column: TRANSCRIPT, before: 172, after: DOCK_GUTTER, inset: '176px', ...docked })
|
||||
expect(tripwire.pageErrors).toEqual([])
|
||||
})
|
||||
|
||||
// The toggle hides a pinned panel, which gives the room back, and shows it again.
|
||||
await toggle.click()
|
||||
await shows(page, null)
|
||||
expect(await pinning(page)).toMatchObject({ before: 260, after: 260, inset: '0px', handles: [10, 10], expanded: 'false' })
|
||||
await toggle.click()
|
||||
it('leaves the transcript centered where its start gutter cannot give the room, floats on request, and docks once it can', async () => {
|
||||
onTestFailed(() => saveFailureShot(page, 'web-e2e-session-panel-overlay'))
|
||||
await openSession()
|
||||
const toggle = page.locator('[data-session-panel-toggle]')
|
||||
// A stored width holds the column at 880px in these frames, so the boundary is 880 + 32 + 348.
|
||||
await page.evaluate(() => { localStorage.setItem('dsh.conversation.contentWidth', '880') })
|
||||
onTestFinished(forgetWidth)
|
||||
|
||||
// The narrowest frame that makes room leaves the column its 32px side inset at the start edge.
|
||||
await setFrame(TRANSCRIPT + 32 + DOCK_GUTTER)
|
||||
await shows(page, 'docked')
|
||||
expect(await pinning(page)).toMatchObject({ before: 172, after: DOCK_GUTTER, inset: '176px', handles: [0, 0], ...held })
|
||||
const last = await layout(page)
|
||||
expect(last).toMatchObject({
|
||||
column: TRANSCRIPT, before: 32, after: DOCK_GUTTER, inset: '316px', composerOffset: 0, probe: 1, expanded: 'true',
|
||||
panel: { width: 300, clear: 40, edge: 8 },
|
||||
})
|
||||
// The start handle has no gutter left to sit in; the end handle keeps its place before the panel.
|
||||
expect([last.handles.left.width, last.handles.right.width]).toEqual([0, 10])
|
||||
|
||||
// A gutter that holds the panel by itself needs no room made: the transcript stays centered and keeps its handles.
|
||||
await setFrame(TRANSCRIPT + 2 * (DOCK_GUTTER + 100))
|
||||
expect(await pinning(page)).toMatchObject({
|
||||
before: DOCK_GUTTER + 100, after: DOCK_GUTTER + 100, inset: '0px', handles: [10, 10], probes: { gutter: 1, reserve: 1 },
|
||||
presentation: 'docked', panel: { width: 360, clear: 80, edge: 8 }, pin: pressed,
|
||||
// One pixel less makes none: the column stays centered at its width and the panel hides.
|
||||
await setFrame(TRANSCRIPT + 32 + DOCK_GUTTER - 1)
|
||||
await shows(page, null)
|
||||
expect(await layout(page)).toMatchObject({
|
||||
column: TRANSCRIPT, before: 189.5, after: 189.5, inset: '0px', probe: 0, expanded: 'false', panel: null,
|
||||
})
|
||||
|
||||
// Unpinned where only the pin held it, the panel stays open as the overlay, which an outside press closes.
|
||||
await setFrame(TRANSCRIPT + 2 * 260)
|
||||
await shows(page, 'docked')
|
||||
await pin.click()
|
||||
// The toggle then opens it over the transcript, narrower than docked and at the same edge inset.
|
||||
await toggle.click()
|
||||
await shows(page, 'overlay')
|
||||
expect(await pinning(page)).toMatchObject({
|
||||
before: 260, after: 260, inset: '0px', handles: [10, 10], expanded: 'true', panel: { width: 280, edge: 8 },
|
||||
pin: { ...pressed, pressed: 'false' },
|
||||
})
|
||||
expect(await stored()).toBe('false')
|
||||
await pressOutside()
|
||||
const overlay = await layout(page)
|
||||
expect(overlay).toMatchObject({ before: 189.5, inset: '0px', probe: 0, presentation: 'overlay', expanded: 'true', panel: { width: 280, edge: 8 } })
|
||||
expect(overlay.panel?.clear).toBeLessThan(0)
|
||||
await page.keyboard.press('Escape')
|
||||
await shows(page, null)
|
||||
expect((await layout(page)).expanded).toBe('false')
|
||||
|
||||
// An open overlay gives way to the docked panel once the frame can make the room.
|
||||
await toggle.click()
|
||||
await shows(page, 'overlay')
|
||||
await setFrame(TRANSCRIPT + 32 + DOCK_GUTTER)
|
||||
await shows(page, 'docked')
|
||||
expect(await layout(page)).toMatchObject({ before: 32, after: DOCK_GUTTER, expanded: 'true', panel: { width: 300, clear: 40, edge: 8 } })
|
||||
expect(tripwire.pageErrors).toEqual([])
|
||||
})
|
||||
|
||||
it('resizes the transcript from either width handle beside the docked panel, moving only its start edge', async () => {
|
||||
onTestFailed(() => saveFailureShot(page, 'web-e2e-session-panel-width'))
|
||||
await openSession()
|
||||
await forgetWidth()
|
||||
onTestFinished(forgetWidth)
|
||||
await setGutter(260)
|
||||
await shows(page, 'docked')
|
||||
/** Drag a width handle `dx` pixels in one move and wait for the width it stores. */
|
||||
const drag = async (side: 'left' | 'right', dx: number, stored: string): Promise<void> => {
|
||||
const strip = (await page.locator(`[data-width-handle="${side}"]`).boundingBox())!
|
||||
const x = strip.x + strip.width / 2
|
||||
await page.mouse.move(x, 400)
|
||||
await page.mouse.down()
|
||||
await page.mouse.move(x + dx, 400)
|
||||
await page.mouse.up()
|
||||
await expect.poll(() => page.evaluate(() => localStorage.getItem('dsh.conversation.contentWidth'))).toBe(stored)
|
||||
}
|
||||
const beside = { presentation: 'docked', panel: { width: 300, clear: 40, edge: 8 } }
|
||||
|
||||
// The panel holds the column's end edge: 40px of travel on the start handle moves the start edge 40px.
|
||||
await drag('left', -40, '920')
|
||||
expect(await layout(page)).toMatchObject({ column: 920, before: 132, after: DOCK_GUTTER, ...beside })
|
||||
// The end handle sits between the column and the panel; travel toward the panel widens the column the same way.
|
||||
await drag('right', 20, '940')
|
||||
expect(await layout(page)).toMatchObject({ column: 940, before: 112, after: DOCK_GUTTER, ...beside })
|
||||
await drag('left', 60, '880')
|
||||
expect(await layout(page)).toMatchObject({ column: TRANSCRIPT, before: 172, after: DOCK_GUTTER, ...beside })
|
||||
|
||||
// In a gutter that holds the panel the column is centered, and both edges move with the pointer.
|
||||
await setGutter(DOCK_GUTTER + 100)
|
||||
await drag('right', 20, '920')
|
||||
expect(await layout(page)).toMatchObject({ column: 920, before: 428, after: 428, inset: '0px', presentation: 'docked' })
|
||||
|
||||
// Dragged wider than the start gutter can give, the column takes its room back: the panel hides and the column centers.
|
||||
await setGutter(260)
|
||||
expect(await layout(page)).toMatchObject({ column: 920, before: 132, after: DOCK_GUTTER, ...beside })
|
||||
await drag('left', -110, '1030')
|
||||
await shows(page, null)
|
||||
expect(await layout(page)).toMatchObject({ column: 1030, before: 185, after: 185, inset: '0px', probe: 0, expanded: 'false' })
|
||||
// Narrowed again, the panel docks without the toggle.
|
||||
await drag('left', 20, '990')
|
||||
await shows(page, 'docked')
|
||||
expect(await layout(page)).toMatchObject({ column: 990, before: 62, after: DOCK_GUTTER, ...beside })
|
||||
expect(tripwire.pageErrors).toEqual([])
|
||||
})
|
||||
|
||||
@@ -415,7 +419,7 @@ describe.skipIf(MODE === 'record')('web e2e: Session panel layout', () => {
|
||||
await expect.poll(async () => (await handle('subagents')).opacity).toBe('1')
|
||||
expect(await handle('subagents')).toEqual({ ...resting, opacity: '1', shown: false })
|
||||
expect(await head('background-jobs').locator('[data-session-panel-grip]').evaluate(element => getComputedStyle(element).opacity)).toBe('0')
|
||||
// Environment does not move: its title row is no drag source and has no handle, so only the pin sits at its end.
|
||||
// Environment does not move: its title row is no drag source and has no handle.
|
||||
expect(await head('environment').evaluate(element => ({
|
||||
draggable: (element as HTMLElement).draggable,
|
||||
cursor: getComputedStyle(element).cursor,
|
||||
@@ -461,8 +465,6 @@ describe.skipIf(MODE === 'record')('web e2e: Session panel layout', () => {
|
||||
await page.mouse.up()
|
||||
await expect.poll(order).toEqual(registered)
|
||||
expect(await stored()).toEqual(['environment', 'subagents', 'background-jobs', 'shared-tasks'])
|
||||
// The pin stays alone at the end of Environment's title line.
|
||||
expect((await pinning(page)).pin).toEqual({ pressed: 'false', target: [24, 24], center: 22, top: 10 })
|
||||
|
||||
// The order survives a reload.
|
||||
await dragOnto('background-jobs', 'subagents', 6)
|
||||
@@ -503,7 +505,7 @@ describe.skipIf(MODE === 'record')('web e2e: Session panel layout', () => {
|
||||
]) })
|
||||
onTestFinished(() => withMenu.close())
|
||||
await seedSession(withMenu, await readFile(FIXTURE, 'utf8'), SEED_ID)
|
||||
const other = await newEnglishPage(browser)
|
||||
const other = await newPanelPage(browser)
|
||||
onTestFinished(() => other.close())
|
||||
onTestFailed(() => saveFailureShot(other, 'web-e2e-session-panel-row-menu'))
|
||||
await other.emulateMedia({ reducedMotion: 'reduce' })
|
||||
|
||||
@@ -19,7 +19,9 @@ import {
|
||||
webSnapshotMode,
|
||||
type WebScaffold,
|
||||
} from './scaffold.ts'
|
||||
import { connectFreshWorkspace, newEnglishPage, saveFailureShot, sessionPanelToggle, showSessionPanel } from './support.ts'
|
||||
import {
|
||||
connectFreshWorkspace, dismissSessionPanel, newEnglishPage, saveFailureShot, sessionPanelToggle, showSessionPanel,
|
||||
} from './support.ts'
|
||||
import { brandString } from '@deepseek-ai/dsh-brand'
|
||||
|
||||
const SNAPSHOT_DIR = fileURLToPath(new URL('./expected/sidebar-subagent-activity', import.meta.url))
|
||||
@@ -169,9 +171,7 @@ describe('web e2e: sidebar subagent activity', () => {
|
||||
await panel.locator(`[data-session-panel-section="${section}"]`).locator('[data-state="ongoing"]').first()
|
||||
.waitFor({ timeout: 10_000 })
|
||||
}
|
||||
expect(await panel.getAttribute('data-session-panel')).toBe('overlay')
|
||||
await page.keyboard.press('Escape')
|
||||
await panel.waitFor({ state: 'detached' })
|
||||
await dismissSessionPanel(page)
|
||||
}
|
||||
try {
|
||||
await assertRunningSections()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
- complementary "Session panel":
|
||||
- button "Pin session panel"
|
||||
- region "Environment":
|
||||
- heading "Environment" [level=2]
|
||||
- text: workspace {{cwd}}
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
} from './scaffold.ts'
|
||||
import {
|
||||
connectFreshWorkspace, dismissSessionPanel, foldControlLayout, newEnglishPage, pinBrowserClock, pinHostClock, saveFailureShot,
|
||||
sessionPanelToggle, showSessionPanel, writeComposerDraft,
|
||||
showSessionPanel, writeComposerDraft,
|
||||
} from './support.ts'
|
||||
import { brandString } from '@deepseek-ai/dsh-brand'
|
||||
|
||||
@@ -857,6 +857,8 @@ describe('web e2e: persisted subagent conversation and human continuation', () =
|
||||
)
|
||||
await nestedRow.getByText(NESTED_LABEL, { exact: true }).click()
|
||||
await page.getByText(NESTED_PROMPT).waitFor()
|
||||
// The docked panel stays beside the grandchild's conversation; the snapshot below is of the conversation alone.
|
||||
await dismissSessionPanel(page)
|
||||
expect(await page.getByRole('textbox', { name: 'Message or run a task, / commands, @ files or sessions' }).isEnabled()).toBe(true)
|
||||
const hierarchy = page.getByRole('navigation', { name: 'Session hierarchy' })
|
||||
const crumbs = await hierarchy.getByRole('button').allTextContents()
|
||||
@@ -932,7 +934,7 @@ describe('web e2e: persisted subagent conversation and human continuation', () =
|
||||
await expect.poll(() => scaffold.ctx.agents.get(forkId)).not.toBeUndefined()
|
||||
|
||||
await sessions.getByRole('treeitem', { name: /Ask a research subagent to/ }).click()
|
||||
await sessionPanelToggle(page).press('Enter')
|
||||
await showSessionPanel(page)
|
||||
await page.locator(SUBAGENTS_SECTION).getByRole('treeitem', { name: new RegExp(LABEL) })
|
||||
.getByText(LABEL, { exact: true }).click()
|
||||
const input = page.locator('[data-composer-input][contenteditable="true"]').first()
|
||||
|
||||
@@ -25,7 +25,9 @@ import {
|
||||
acknowledgeReloadConnectionLoss, assertFixtureInventory, captureStableAria, compareOrRefreshGolden,
|
||||
launchWebScaffold, readPersistedEvents, watchConsole, webSnapshotMode, type WebScaffold,
|
||||
} from './scaffold.ts'
|
||||
import { connectFreshWorkspace, newEnglishPage, saveFailureShot, showSessionPanel } from './support.ts'
|
||||
import {
|
||||
connectFreshWorkspace, dismissSessionPanel, newEnglishPage, saveFailureShot, showSessionPanel,
|
||||
} from './support.ts'
|
||||
|
||||
const BASE_FIXTURE = fileURLToPath(new URL('../../../snapshots/web/live-interactions/session.v3.jsonl', import.meta.url))
|
||||
|
||||
@@ -210,6 +212,7 @@ describe.skipIf(MODE === 'record')('web e2e: composer interrupt for a running co
|
||||
await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
|
||||
acknowledgeReloadConnectionLoss(tripwire, warningStart)
|
||||
await (await showSessionPanel(page)).getByRole('treeitem', { name: new RegExp(LABEL) }).press('Enter')
|
||||
await dismissSessionPanel(page)
|
||||
const input = page.locator('[data-composer-input]').first()
|
||||
await input.waitFor({ timeout: 15_000 })
|
||||
await page.getByRole('button', { name: /^Task message received/ })
|
||||
@@ -269,6 +272,7 @@ describe.skipIf(MODE === 'record')('web e2e: composer interrupt for a running co
|
||||
await page.getByRole('navigation', { name: 'Session hierarchy' })
|
||||
.getByRole('button').first().click()
|
||||
await (await showSessionPanel(page)).getByRole('treeitem', { name: new RegExp(LABEL) }).press('Enter')
|
||||
await dismissSessionPanel(page)
|
||||
// A live continuable child advertises the ordinary steer-all gesture, so
|
||||
// that placeholder is the composer's accessible name in this window. It
|
||||
// changes back as the queue drains, so later interactions address the
|
||||
|
||||
@@ -213,12 +213,32 @@ export async function pinBrowserClock(page: Page): Promise<void> {
|
||||
* scenarios asserting the Chinese surface advertise
|
||||
* {@link ZH_BROWSER_LOCALE} instead. The context uses Asia/Shanghai to preserve
|
||||
* the recorded Web user-source timezone independently of the host timezone.
|
||||
* The page {@link startWithSessionPanelHidden | starts with the Session panel hidden}.
|
||||
* @param browser - Playwright browser owning the page.
|
||||
* @param height - Viewport height; width is fixed to the lane baseline.
|
||||
* @returns the initialized page.
|
||||
*/
|
||||
export async function newEnglishPage(browser: Browser, height = 1000): Promise<Page> {
|
||||
return await browser.newPage({ viewport: { width: 1680, height }, locale: 'en-US', timezoneId: 'Asia/Shanghai' })
|
||||
const page = await browser.newPage({ viewport: { width: 1680, height }, locale: 'en-US', timezoneId: 'Asia/Shanghai' })
|
||||
await startWithSessionPanelHidden(page)
|
||||
return page
|
||||
}
|
||||
|
||||
/**
|
||||
* Have a page start with the Session panel's docking turned off, as a reader
|
||||
* who hid the panel has it, unless the origin already stores a choice. At the
|
||||
* lane's baseline width the panel otherwise docks and moves the transcript
|
||||
* aside, which a scenario about the conversation alone does not expect.
|
||||
* @param page - a page that has not navigated yet.
|
||||
*/
|
||||
export async function startWithSessionPanelHidden(page: Page): Promise<void> {
|
||||
await page.addInitScript((key) => {
|
||||
try {
|
||||
if (localStorage.getItem(key) === null) localStorage.setItem(key, 'false')
|
||||
} catch (_storageUnavailable) {
|
||||
// Documents without storage access, such as about:blank, have no panel to keep hidden.
|
||||
}
|
||||
}, SESSION_PANEL_DOCKING_KEY)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -480,6 +500,9 @@ export async function openSettings(page: Page, locale: 'en' | 'zh' | 'ja'): Prom
|
||||
await page.getByRole('menuitem', { name: labels[locale][1], exact: true }).click()
|
||||
}
|
||||
|
||||
/** localStorage key of the Session panel's docking preference, which the header toggle flips. */
|
||||
export const SESSION_PANEL_DOCKING_KEY = 'dsh.sessionPanel.pinned'
|
||||
|
||||
/** The Session panel toggle in the Session header. */
|
||||
export function sessionPanelToggle(page: Page): Locator {
|
||||
return page.locator('[data-session-panel-toggle]')
|
||||
@@ -514,12 +537,17 @@ export async function showSessionPanel(page: Page): Promise<Locator> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the Session panel shown over the conversation with Escape.
|
||||
* Hide the Session panel: with Escape when it shows over the conversation,
|
||||
* and from its toggle when it is docked beside it, which turns docking off
|
||||
* until the toggle shows the panel again.
|
||||
* @param page - the page under test.
|
||||
*/
|
||||
export async function dismissSessionPanel(page: Page): Promise<void> {
|
||||
await page.keyboard.press('Escape')
|
||||
await page.locator('[data-session-panel]').waitFor({ state: 'detached' })
|
||||
const panel = page.locator('[data-session-panel]')
|
||||
const presentation = await panel.evaluateAll(elements => elements[0]?.getAttribute('data-session-panel') ?? null)
|
||||
if (presentation === 'docked') await sessionPanelToggle(page).click()
|
||||
else await page.keyboard.press('Escape')
|
||||
await panel.waitFor({ state: 'detached' })
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
en: 4a094cd97426ad18
|
||||
zh: 5faadddb7e2b0a43
|
||||
/deepseek-ai-dsh-client-ui-conversation/shell-and-standard-props:
|
||||
en: 6f2a1b67bf6685c2
|
||||
zh: 210d1c2c67a83419
|
||||
en: 23ffb0e9ec62bd76
|
||||
zh: 3f0a70b170a4880d
|
||||
/deepseek-ai-dsh-client-ui-conversation/temporary-composer-entries:
|
||||
en: 59cd63057dfb6eeb
|
||||
zh: b2e2c86e810b7bb8
|
||||
|
||||
@@ -124,7 +124,7 @@ The width-handle indicator follows the pointer only during a captured drag; ordi
|
||||
|
||||
<a id="end-reserve"></a>
|
||||
|
||||
The main Conversation body can keep room free at its inline end for something that stays beside the transcript, such as a pinned [Session panel](../ui-session-panel/README.md#the-pin). A stylesheet asks for it by setting the `--dsh-chat-end-reserve` length on the `[data-conversation-content]` element. The scrollport then pads its end by `--dsh-chat-end-inset`, so the space after the transcript column equals the reserve. While the start gutter lasts, the inset is twice the missing gutter, which moves the centered column and the composer toward the start edge at their own widths; once the column is down to its side inset at the start edge, the inset is the reserve less that side inset, which narrows the column instead. `--dsh-chat-end-reserve-max` is the largest reserve that leaves the column 480px wide; a larger request gets no inset, so whatever asks for room reads the maximum before it relies on that room. The body derives these lengths from the scrollport's width, which it publishes as `--dsh-conversation-viewport-width`, so they have the same values in the scrollport, the width handles, and the Chat aside layer. The width handles do not show while the inset is above zero, because they sit at the centered column's edges and a drag widens the column about its center. An embedded occurrence makes no room: its maximum and its inset are 0.
|
||||
The main Conversation body can keep room free at its inline end for something that stays beside the transcript, such as the docked [Session panel](../ui-session-panel/README.md#docking). A stylesheet asks for it by setting the `--dsh-chat-end-reserve` length on the `[data-conversation-content]` element. The scrollport then pads its end by `--dsh-chat-end-inset`, twice the missing gutter, which moves the centered transcript column and the composer toward the start edge at their own widths until the space after the column equals the reserve. `--dsh-chat-end-reserve-max` is the largest reserve the start gutter can give while the column keeps its width and its side inset; a larger request gets no inset, so whatever asks for room reads the maximum before it relies on that room. The body derives these lengths from the scrollport's width, which it publishes as `--dsh-conversation-viewport-width`, so they have the same values in the scrollport, the width handles, and the Chat aside layer. The width handles move with the column. While the inset is above zero the reserve holds the column's end edge, so a drag on either handle moves only the start edge and changes the width by the pointer's travel instead of twice it; a column dragged wider than the start gutter can give gets no inset and centers again. An embedded occurrence makes no room: its maximum and its inset are 0.
|
||||
|
||||
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. On Apple platforms, Home and End move the caret to the start or end of the current visual line instead of scrolling the conversation, and Shift extends the selection; End immediately before a quote takes the same path as Cmd+Right to the end of that line. 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.
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ Session 首次绑定或缓存的 Session 成为 current 时,shell 会在渲染
|
||||
|
||||
<a id="end-reserve"></a>
|
||||
|
||||
主 Conversation body 可以在行向末端空出一段位置,留给停在 transcript 旁边的内容,例如已固定的[会话面板](../ui-session-panel/README.zh.md#the-pin)。样式表在 `[data-conversation-content]` 元素上设置长度 `--dsh-chat-end-reserve` 来提出申请。滚动容器随即给末端加上 `--dsh-chat-end-inset` 的内边距,使 transcript 列后的空间等于预留值。起始侧还有留白时,内边距是所缺留白的两倍,居中的列和输入框保持各自宽度向起始边缘移动;列在起始边缘只剩两侧内边距后,内边距等于预留值减去该侧内边距,改为让列变窄。`--dsh-chat-end-reserve-max` 是让列保持 480px 宽时能给出的最大预留;超出它的申请得不到任何内边距,因此申请方要先读取这个最大值,再依赖这段位置。主体从滚动容器的宽度推出这些长度,并把该宽度发布为 `--dsh-conversation-viewport-width`,因此它们在滚动容器、宽度拖拽条和 Chat 侧边层中的值相同。内边距大于零时不显示宽度拖拽条,因为拖拽条位于居中列的两侧,拖动时列以中心为基准变宽。嵌入式 occurrence 不让位:它的最大预留和内边距都是 0。
|
||||
主 Conversation body 可以在行向末端空出一段位置,留给停在 transcript 旁边的内容,例如停靠的[会话面板](../ui-session-panel/README.zh.md#docking)。样式表在 `[data-conversation-content]` 元素上设置长度 `--dsh-chat-end-reserve` 来提出申请。滚动容器随即给末端加上 `--dsh-chat-end-inset` 的内边距,大小是所缺留白的两倍,居中的 transcript 列和输入框保持各自宽度向起始边缘移动,直到列后的空间等于预留值。`--dsh-chat-end-reserve-max` 是在列保持宽度和两侧内边距的前提下,起始留白能让出的最大预留;超出它的申请得不到任何内边距,因此申请方要先读取这个最大值,再依赖这段位置。主体从滚动容器的宽度推出这些长度,并把该宽度发布为 `--dsh-conversation-viewport-width`,因此它们在滚动容器、宽度拖拽条和 Chat 侧边层中的值相同。宽度拖拽条随列移动。内边距大于零时,预留固定了列的末端边缘,因此拖动任一拖拽条都只移动起始边缘,宽度的变化等于指针移动的距离而不是它的两倍;列被拖到超过起始留白能让出的宽度时不再有内边距,重新居中。嵌入式 occurrence 不让位:它的最大预留和内边距都是 0。
|
||||
|
||||
常驻 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 离开菜单且不选定——其余按键交给编辑器自身。 在 Apple 平台上,Home 与 End 把光标移到当前视觉行的行首或行末,而不是滚动对话,按住 Shift 时扩展选区;光标紧贴在 quote 左侧时,End 与 Cmd+Right 走同一路径移到该行末尾。 接管键盘的浮层通过 `SessionInput.focus()` 把键盘还回来,该路径走 Lexical 自己的 focus,因此光标回到草稿原来的位置而不是开头。
|
||||
|
||||
|
||||
@@ -349,23 +349,21 @@
|
||||
composer seat (z-index 9) stay above the strip, so the footer band is
|
||||
never a resize target. Pointer capture keeps a drag active under it. */
|
||||
z-index: 0;
|
||||
/* No strip while the end reserve moves the column off the body's center:
|
||||
the strips sit at the centered column's edges, and a drag widens the
|
||||
column about its center. */
|
||||
width: min(
|
||||
10px,
|
||||
calc((100% - var(--dsh-chat-content-width)) / 2 - 24px - 24px),
|
||||
calc(10px - var(--dsh-chat-end-inset) * 9999)
|
||||
);
|
||||
cursor: col-resize;
|
||||
}
|
||||
|
||||
/* The strips follow the column when the end reserve moves it off the body's
|
||||
center by half the end inset. Each strip takes its width from the gutter
|
||||
on its own side: the start gutter loses that half and the end gutter
|
||||
gains it. */
|
||||
.widthHandle[data-side='left'] {
|
||||
right: calc(50% + var(--dsh-chat-content-width) / 2 + 24px);
|
||||
right: calc(50% + var(--dsh-chat-end-inset) / 2 + var(--dsh-chat-content-width) / 2 + 24px);
|
||||
width: min(10px, calc((100% - var(--dsh-chat-end-inset) - var(--dsh-chat-content-width)) / 2 - 24px - 24px));
|
||||
}
|
||||
|
||||
.widthHandle[data-side='right'] {
|
||||
left: calc(50% + var(--dsh-chat-content-width) / 2 + 24px);
|
||||
left: calc(50% - var(--dsh-chat-end-inset) / 2 + var(--dsh-chat-content-width) / 2 + 24px);
|
||||
width: min(10px, calc((100% + var(--dsh-chat-end-inset) - var(--dsh-chat-content-width)) / 2 - 24px - 24px));
|
||||
}
|
||||
|
||||
/* The glow: a short 2px bar following the captured pointer's Y, centered in the strip
|
||||
@@ -480,25 +478,26 @@
|
||||
/* End reserve: room the body keeps free at its inline end for a surface
|
||||
that stays beside the transcript. A stylesheet asks for it by setting
|
||||
--dsh-chat-end-reserve on this element. The scrollport then pads its end
|
||||
by --dsh-chat-end-inset, which moves the centered transcript column and
|
||||
the composer aside until the space after the column equals the reserve:
|
||||
twice the missing gutter while the start gutter lasts, and after that the
|
||||
reserve less the transcript's side inset, which narrows the column
|
||||
instead. --dsh-chat-end-reserve-max is the largest reserve that leaves
|
||||
the column 480px; a larger one gets no inset at all, so the surface must
|
||||
read the maximum before it relies on the room. Every length derives from
|
||||
the scrollport's measured width, so the same values hold where a
|
||||
percentage would resolve against another box. */
|
||||
by --dsh-chat-end-inset, twice the missing gutter, which moves the
|
||||
centered transcript column and the composer toward the start edge at
|
||||
their own widths until the space after the column equals the reserve.
|
||||
--dsh-chat-end-reserve-max is the largest reserve the start gutter can
|
||||
give while the column keeps its width and its side inset; a larger one
|
||||
gets no inset at all, so the surface reads the maximum before it relies
|
||||
on the room. Every length derives from the scrollport's measured width,
|
||||
so the same values hold where a percentage would resolve against
|
||||
another box. */
|
||||
--dsh-chat-end-reserve-max: calc(
|
||||
var(--dsh-conversation-viewport-width, 0px) - 480px - var(--dsh-composer-side-clearance) - 16px
|
||||
var(--dsh-conversation-viewport-width, 0px) - var(--dsh-chat-content-width) - var(--dsh-composer-side-clearance) - 16px
|
||||
);
|
||||
/* The first term is 0 for a reserve above the maximum and at least 1000px, above any inset, otherwise: a
|
||||
step at the maximum, within a ten-thousandth of a pixel. */
|
||||
--dsh-chat-end-inset: min(
|
||||
max(0px, calc((var(--dsh-chat-end-reserve-max) - var(--dsh-chat-end-reserve, 0px) + 1px) * 9999)),
|
||||
max(0px, calc((var(--dsh-chat-end-reserve-max) - var(--dsh-chat-end-reserve, 0px)) * 10000000 + 1000px)),
|
||||
calc(2 * max(
|
||||
0px,
|
||||
var(--dsh-chat-end-reserve, 0px) - (var(--dsh-conversation-viewport-width, 0px) - var(--dsh-chat-content-width)) / 2
|
||||
)),
|
||||
max(0px, var(--dsh-chat-end-reserve, 0px) - var(--dsh-composer-side-clearance) - 16px)
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,22 @@ function resolveContentWidth(columnWidth: number, preference: number | null): nu
|
||||
return Math.max(680, Math.min(columnWidth * 0.64, 880))
|
||||
}
|
||||
|
||||
/**
|
||||
* How much the content width changes per pixel the pointer travels outward.
|
||||
* The centered column grows about its center, so both edges move and the
|
||||
* width changes by twice the travel. While the body keeps an end reserve
|
||||
* free, the column's end edge stays where the reserve holds it and only its
|
||||
* start edge moves, by the pointer's travel.
|
||||
* @param body - the Conversation body that holds the handles and the scrollport.
|
||||
* @returns 1 while the scrollport pads its end for a reserve, otherwise 2.
|
||||
*/
|
||||
function widthPerPixel(body: HTMLElement): number {
|
||||
const scrollport = body.querySelector<HTMLElement>('[data-conversation-scroll]')
|
||||
/* v8 ignore next -- the Conversation body always contains its scroll element. */
|
||||
if (scrollport === null) return 2
|
||||
return Number.parseFloat(getComputedStyle(scrollport).paddingInlineEnd) > 0 ? 1 : 2
|
||||
}
|
||||
|
||||
/** Convert a wheel event's vertical delta to scrollport pixels. */
|
||||
function wheelDeltaY(event: React.WheelEvent, scrollport: HTMLElement): number {
|
||||
if (event.deltaMode === WHEEL_DELTA_LINE) {
|
||||
@@ -41,22 +57,29 @@ function wheelDeltaY(event: React.WheelEvent, scrollport: HTMLElement): number {
|
||||
function WidthHandle(props: {
|
||||
side: 'left' | 'right'
|
||||
onStart: () => number
|
||||
/** Content-width change per pixel of outward pointer travel, read as the drag advances. */
|
||||
scale: () => number
|
||||
onDrag: (width: number) => void
|
||||
onCommit: (width: number) => void
|
||||
onEnd: () => void
|
||||
}) {
|
||||
const dragging = useRef(false)
|
||||
const base = useRef(0)
|
||||
/** The width the drag has reached, before the layout's limits apply. */
|
||||
const width = useRef(0)
|
||||
const origin = useRef(0)
|
||||
const latest = useRef(0)
|
||||
/** Pointer X the width was last advanced to. */
|
||||
const applied = useRef(0)
|
||||
const frame = useRef<number | null>(null)
|
||||
const callbacks = useRef(props)
|
||||
callbacks.current = props
|
||||
|
||||
const outwardWidth = () => {
|
||||
const dx = latest.current - origin.current
|
||||
const dx = latest.current - applied.current
|
||||
applied.current = latest.current
|
||||
const outward = callbacks.current.side === 'right' ? dx : -dx
|
||||
return base.current + outward * 2
|
||||
width.current += outward * callbacks.current.scale()
|
||||
return width.current
|
||||
}
|
||||
const cancelFrame = () => {
|
||||
if (frame.current !== null) { cancelAnimationFrame(frame.current); frame.current = null }
|
||||
@@ -67,7 +90,8 @@ function WidthHandle(props: {
|
||||
event.currentTarget.setPointerCapture(event.pointerId)
|
||||
origin.current = event.clientX
|
||||
latest.current = event.clientX
|
||||
base.current = callbacks.current.onStart()
|
||||
applied.current = event.clientX
|
||||
width.current = callbacks.current.onStart()
|
||||
dragging.current = true
|
||||
event.currentTarget.toggleAttribute('data-dragging', true)
|
||||
}, [])
|
||||
@@ -174,6 +198,7 @@ export function ConversationWidthControls({ container, phase }: ConversationWidt
|
||||
key={side}
|
||||
side={side}
|
||||
onStart={onStart}
|
||||
scale={() => widthPerPixel(container)}
|
||||
onDrag={onDrag}
|
||||
onCommit={onCommit}
|
||||
onEnd={onEnd}
|
||||
|
||||
@@ -11,9 +11,9 @@ import { describe, expect, it } from 'vitest'
|
||||
const css = readFileSync(fileURLToPath(new URL('../src/client/skeleton/ConversationRoot.module.css', import.meta.url)), 'utf8')
|
||||
.replace(/\/\*[\s\S]*?\*\//g, ' ')
|
||||
|
||||
/** Declarations of the rule with exactly this class selector, with whitespace collapsed. */
|
||||
/** Declarations of the rule with exactly this selector, with whitespace collapsed. */
|
||||
function declarationsOf(selector: string): Record<string, string> {
|
||||
const rule = new RegExp(`(?:^|[{}])\\s*\\${selector}\\s*\\{([^{}]*)\\}`).exec(css)
|
||||
const rule = new RegExp(`(?:^|[{}])\\s*${selector.replace(/[.[\]():*+^$\\'=]/g, '\\$&')}\\s*\\{([^{}]*)\\}`).exec(css)
|
||||
if (rule === null) throw new Error(`ConversationRoot.module.css has no \`${selector}\` rule`)
|
||||
return Object.fromEntries((rule[1] ?? '').split(';').map(part => part.trim()).filter(Boolean).map((part): [string, string] => {
|
||||
const colon = part.indexOf(':')
|
||||
@@ -27,41 +27,43 @@ describe('Conversation body end reserve', () => {
|
||||
it('derives the largest reserve and the inset from the scrollport width, the content width, and the side inset', () => {
|
||||
expect(body['--dsh-composer-side-clearance']).toBe('16px')
|
||||
expect(body['--dsh-chat-end-reserve-max']).toBe(
|
||||
'calc(var(--dsh-conversation-viewport-width, 0px) - 480px - var(--dsh-composer-side-clearance) - 16px)',
|
||||
'calc(var(--dsh-conversation-viewport-width, 0px) - var(--dsh-chat-content-width) - var(--dsh-composer-side-clearance) - 16px)',
|
||||
)
|
||||
expect(body['--dsh-chat-end-inset']).toBe(
|
||||
'min(max(0px, calc((var(--dsh-chat-end-reserve-max) - var(--dsh-chat-end-reserve, 0px) + 1px) * 9999)),'
|
||||
'min(max(0px, calc((var(--dsh-chat-end-reserve-max) - var(--dsh-chat-end-reserve, 0px)) * 10000000 + 1000px)),'
|
||||
+ ' calc(2 * max(0px, var(--dsh-chat-end-reserve, 0px)'
|
||||
+ ' - (var(--dsh-conversation-viewport-width, 0px) - var(--dsh-chat-content-width)) / 2)),'
|
||||
+ ' max(0px, var(--dsh-chat-end-reserve, 0px) - var(--dsh-composer-side-clearance) - 16px))',
|
||||
+ ' - (var(--dsh-conversation-viewport-width, 0px) - var(--dsh-chat-content-width)) / 2)))',
|
||||
)
|
||||
})
|
||||
|
||||
it('moves the column aside by twice the missing gutter, then narrows it, and makes no room under a 480px column', () => {
|
||||
it('moves the column aside by twice the missing gutter at its own width, and makes no room once the start gutter is at the side inset', () => {
|
||||
// The declarations above, evaluated for a scrollport `viewport` wide and a transcript `content` wide.
|
||||
const side = 32
|
||||
const reserveMax = (viewport: number, content: number): number => viewport - content - side
|
||||
const inset = (viewport: number, content: number, reserve: number): number => Math.min(
|
||||
Math.max(0, (viewport - 480 - side - reserve + 1) * 9999),
|
||||
Math.max(0, (reserveMax(viewport, content) - reserve) * 10000000 + 1000),
|
||||
2 * Math.max(0, reserve - (viewport - content) / 2),
|
||||
Math.max(0, reserve - side),
|
||||
)
|
||||
/** The space after the column once the scrollport pads its end: the column keeps `side` at least on both sides. */
|
||||
const after = (viewport: number, content: number, reserve: number): number => {
|
||||
/** The space before and after the column once the scrollport pads its end. */
|
||||
const gutters = (viewport: number, content: number, reserve: number): [number, number] => {
|
||||
const frame = viewport - inset(viewport, content, reserve)
|
||||
const column = Math.min(content, frame - 2 * side)
|
||||
return viewport - (frame - column) / 2 - column
|
||||
return [(frame - column) / 2, viewport - (frame + column) / 2]
|
||||
}
|
||||
// No reserve, or a gutter that already holds it: no inset.
|
||||
expect([inset(1153, 742, 0), inset(1576, 880, 348), inset(2013, 880, 348)]).toEqual([0, 0, 0])
|
||||
// The start gutter lasts: the column keeps its width and the space after it is the reserve.
|
||||
expect(inset(1153, 742, 348)).toBe(285)
|
||||
expect(after(1153, 742, 348)).toBe(348)
|
||||
// The start gutter is down to the side inset: the column narrows, and the space after it stays the reserve.
|
||||
expect([inset(993, 680, 348), after(993, 680, 348)]).toEqual([316, 348])
|
||||
expect(993 - 316 - 2 * side).toBe(613)
|
||||
// The narrowest scrollport that makes room leaves a 480px column; one pixel less makes none.
|
||||
expect([inset(860, 680, 348), 860 - 316 - 2 * side]).toEqual([316, 480])
|
||||
expect(inset(859, 680, 348)).toBe(0)
|
||||
// A gutter one pixel short: the column moves by that pixel.
|
||||
expect([inset(1574, 880, 348), gutters(1574, 880, 348)]).toEqual([2, [346, 348]])
|
||||
expect([inset(1400, 880, 348), gutters(1400, 880, 348)]).toEqual([176, [172, 348]])
|
||||
// The narrowest scrollport that makes room leaves the column its side inset before it.
|
||||
expect([reserveMax(1260, 880), inset(1260, 880, 348), gutters(1260, 880, 348)]).toEqual([348, 316, [32, 348]])
|
||||
// One pixel less makes none: the column stays centered at its width.
|
||||
expect([inset(1259, 880, 348), gutters(1259, 880, 348)]).toEqual([0, [189.5, 189.5]])
|
||||
// A fraction of a pixel short makes none either: the inset is all or nothing.
|
||||
expect(inset(1259.96, 880, 348)).toBe(0)
|
||||
expect(inset(1260.04, 880, 348)).toBeCloseTo(315.96, 6)
|
||||
// A scrollport narrower than the content width has no reserve to give, with or without a request.
|
||||
expect([inset(600, 680, 348), inset(600, 680, 0)]).toEqual([0, 0])
|
||||
})
|
||||
|
||||
it('pads the scrollport end by the inset and makes no room in an embedded occurrence', () => {
|
||||
@@ -70,9 +72,16 @@ describe('Conversation body end reserve', () => {
|
||||
expect([embedded['--dsh-chat-end-reserve-max'], embedded['--dsh-chat-end-inset']]).toEqual(['0px', '0px'])
|
||||
})
|
||||
|
||||
it('drops the width handles while the inset moves the column off the body center', () => {
|
||||
expect(declarationsOf('.widthHandle')['width']).toBe(
|
||||
'min(10px, calc((100% - var(--dsh-chat-content-width)) / 2 - 24px - 24px), calc(10px - var(--dsh-chat-end-inset) * 9999))',
|
||||
)
|
||||
it('moves each width handle with the column and sizes it from the gutter on its own side', () => {
|
||||
// Half the inset toward the start edge, as the column's center moves; the start gutter loses that half and the end gutter gains it.
|
||||
expect(declarationsOf(".widthHandle[data-side='left']")).toEqual({
|
||||
right: 'calc(50% + var(--dsh-chat-end-inset) / 2 + var(--dsh-chat-content-width) / 2 + 24px)',
|
||||
width: 'min(10px, calc((100% - var(--dsh-chat-end-inset) - var(--dsh-chat-content-width)) / 2 - 24px - 24px))',
|
||||
})
|
||||
expect(declarationsOf(".widthHandle[data-side='right']")).toEqual({
|
||||
left: 'calc(50% - var(--dsh-chat-end-inset) / 2 + var(--dsh-chat-content-width) / 2 + 24px)',
|
||||
width: 'min(10px, calc((100% + var(--dsh-chat-end-inset) - var(--dsh-chat-content-width)) / 2 - 24px - 24px))',
|
||||
})
|
||||
expect(declarationsOf('.widthHandle')['width']).toBeUndefined()
|
||||
})
|
||||
})
|
||||
@@ -1006,6 +1006,45 @@ describe('ConversationRoot resident composer', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('changes the width by the pointer travel, not twice it, while the scrollport pads its end for a reserve', () => {
|
||||
const b = mount(sessionSnapshotOf())
|
||||
const content = b.view.container.querySelector('[data-conversation-content]') as HTMLElement
|
||||
const root = content.parentElement as HTMLElement
|
||||
const scrollport = content.querySelector('[data-conversation-scroll]') as HTMLElement
|
||||
Object.defineProperty(content, 'offsetWidth', { value: 1600, configurable: true })
|
||||
act(() => { fireResize(content) })
|
||||
const handle = b.view.container.querySelector('[data-width-handle="left"]') as HTMLElement
|
||||
const names = ['setPointerCapture', 'releasePointerCapture', 'hasPointerCapture'] as const
|
||||
const originals = names.map(name =>
|
||||
[name, Object.getOwnPropertyDescriptor(Element.prototype, name)] as const)
|
||||
const captured = new Set<Element>()
|
||||
Element.prototype.setPointerCapture = function () { captured.add(this) }
|
||||
Element.prototype.releasePointerCapture = function () { captured.delete(this) }
|
||||
Element.prototype.hasPointerCapture = function () { return captured.has(this) }
|
||||
// The end inset as the layout resolves it; jsdom computes none.
|
||||
let inset = '176px'
|
||||
const computed = globalThis.getComputedStyle
|
||||
vi.spyOn(globalThis, 'getComputedStyle').mockImplementation((element, pseudo) => element === scrollport
|
||||
? { paddingInlineEnd: inset } as CSSStyleDeclaration
|
||||
: computed(element, pseudo))
|
||||
try {
|
||||
// The reserve holds the column's end edge: 25px outward on the start handle moves the start edge 25px → 880 + 25.
|
||||
fireEvent.pointerDown(handle, { pointerId: 1, clientX: 400, clientY: 300 })
|
||||
fireEvent.pointerUp(handle, { pointerId: 1, clientX: 375, clientY: 300 })
|
||||
expect(root.style.getPropertyValue('--dsh-chat-user-width')).toBe('905px')
|
||||
// Without the inset the column is centered and both edges move: 905 + 2 × 10.
|
||||
inset = '0px'
|
||||
fireEvent.pointerDown(handle, { pointerId: 1, clientX: 400, clientY: 300 })
|
||||
fireEvent.pointerUp(handle, { pointerId: 1, clientX: 390, clientY: 300 })
|
||||
expect(root.style.getPropertyValue('--dsh-chat-user-width')).toBe('925px')
|
||||
} finally {
|
||||
for (const [name, descriptor] of originals) {
|
||||
if (descriptor === undefined) Reflect.deleteProperty(Element.prototype, name)
|
||||
else Object.defineProperty(Element.prototype, name, descriptor)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('publishes the composer height and the scrollport height on the scrollport, and its width on the body', () => {
|
||||
const b = mount(sessionSnapshotOf())
|
||||
const body = b.view.container.querySelector('[data-conversation-content]') as HTMLElement
|
||||
|
||||
@@ -16,8 +16,9 @@ function rule(css: string, selector: string): string {
|
||||
|
||||
describe('conversation width handle styles', () => {
|
||||
it('keeps the gutter hit target narrow', () => {
|
||||
const handle = rule(conversationCss, '.widthHandle')
|
||||
expect(handle).toMatch(/width:\s*min\(\s*10px/)
|
||||
for (const side of ['left', 'right']) {
|
||||
expect(conversationCss).toMatch(new RegExp(`\\.widthHandle\\[data-side='${side}'\\]\\s*\\{[^}]*width:\\s*min\\(\\s*10px`, 's'))
|
||||
}
|
||||
})
|
||||
|
||||
it('keeps the hover indicator compact', () => {
|
||||
|
||||
@@ -3,35 +3,32 @@
|
||||
# After editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write packages/client/ui-session-panel/README.md
|
||||
/:
|
||||
en: 1761169a2df5c070
|
||||
zh: a45a8a9ffb9d8683
|
||||
en: 9cfd79fbc4ba3dcb
|
||||
zh: e5e498e99e2bebd2
|
||||
/deepseek-ai-dsh-client-ui-session-panel:
|
||||
en: aff5b9d70836e810
|
||||
zh: 2cb8c75d3c82fba9
|
||||
/deepseek-ai-dsh-client-ui-session-panel/summary:
|
||||
en: 2debf1b66e580cfb
|
||||
zh: 1b89f2b36f405c46
|
||||
en: dffaf73a0d9c9f39
|
||||
zh: cee2c2a16a33f3a2
|
||||
/deepseek-ai-dsh-client-ui-session-panel/table-of-contents:
|
||||
en: d152484eb41ac6b4
|
||||
zh: 09388d293f9be9cb
|
||||
/deepseek-ai-dsh-client-ui-session-panel/use-this-package:
|
||||
en: 62a513f72d48d6e2
|
||||
zh: 927305122645359d
|
||||
en: 6a4b6cec0c5a4e2a
|
||||
zh: 8aaec4b24bed0151
|
||||
/deepseek-ai-dsh-client-ui-session-panel/use-this-package/docking-and-the-overlay:
|
||||
en: c8509027a67b6338
|
||||
zh: a41c76ff7b4fd9bb
|
||||
/deepseek-ai-dsh-client-ui-session-panel/use-this-package/the-pin:
|
||||
en: 275d7ee3241b5cb4
|
||||
zh: c3823108af08a10e
|
||||
en: e7089ca0e65bc7cd
|
||||
zh: 437a2cc879a40d66
|
||||
/deepseek-ai-dsh-client-ui-session-panel/use-this-package/section-order:
|
||||
en: 8e133e09cd670888
|
||||
zh: 6ea7cd88c4a012ed
|
||||
en: c3e9b5a17ce1c083
|
||||
zh: 5bd2e6c3cb79ea11
|
||||
/deepseek-ai-dsh-client-ui-session-panel/use-this-package/contribute-a-section:
|
||||
en: 27fdd4ec3c830299
|
||||
zh: 0e70ac367e4176f8
|
||||
/deepseek-ai-dsh-client-ui-session-panel/understand-the-implementation:
|
||||
en: c74415b5b7d424d9
|
||||
zh: 3c0d83dd08d1d13e
|
||||
en: c1b1b584c6640d4d
|
||||
zh: 49ad6511bf928272
|
||||
/deepseek-ai-dsh-client-ui-session-panel/further-exploration:
|
||||
en: decfa1b92e25ec6c
|
||||
zh: 255c7862690a2f23
|
||||
@@ -42,8 +39,8 @@
|
||||
en: 47f982e326fe77fd
|
||||
zh: 275b2ef7eec3ab19
|
||||
/deepseek-ai-dsh-client-ui-session-panel/known-limitations-and-deferred-work:
|
||||
en: 212922b7cf8a00d6
|
||||
zh: 01e4dd04013b6f4e
|
||||
en: 10f0bfd677de5d91
|
||||
zh: 06ce985318d900b9
|
||||
/deepseek-ai-dsh-client-ui-session-panel/known-limitations-and-deferred-work/dev-note:
|
||||
en: e67f633dc6fe7773
|
||||
zh: b532016223ceceef
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
description: "The Session panel: a header toggle and a floating panel in the Chat View's aside whose sections other plugins register, with a pin that keeps it beside the transcript and the built-in Environment section."
|
||||
description: "The Session panel: a header toggle and a floating panel in the Chat View's aside whose sections other plugins register and the reader can reorder, with the built-in Environment section."
|
||||
kind: "package-reference"
|
||||
---
|
||||
|
||||
@@ -9,7 +9,7 @@ English | [中文](README.zh.md)
|
||||
|
||||
## Summary
|
||||
|
||||
`dsh-client-ui-session-panel` adds a Session header toggle that shows or hides a floating panel of facts about the current Session. The panel lives in the Chat View: it docks in the Chat View's end gutter when the gutter can hold it, and otherwise opens over the transcript on request. A pin on the panel has the transcript make room, so the panel docks at narrower widths too, and the reader can drag its sections into another order. It draws section titles and leaves section content to the plugins that register sections; it ships the Environment section with the working folder row.
|
||||
`dsh-client-ui-session-panel` adds a Session header toggle that shows or hides a floating panel of facts about the current Session. The panel lives in the Chat View: it docks beside the transcript, in the Chat View's end gutter or in the room the transcript leaves by moving into its start gutter, and where neither holds it opens over the transcript on request. The reader can drag its sections into another order. It draws section titles and leaves section content to the plugins that register sections; it ships the Environment section with the working folder row.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
@@ -27,27 +27,21 @@ English | [中文](README.zh.md)
|
||||
|
||||
The `@deepseek-ai/dsh-web-app` bundle loads this package by default. The toggle is the first Session header utility, before sharing and the schedule catalog. It is an icon button with the panel name and its indicators as its accessible name, a tooltip that says whether a press shows or hides the panel, shown after 500ms of hover or at once on keyboard focus, and `aria-expanded` for whether the panel shows.
|
||||
|
||||
<a id="docking"></a>
|
||||
### Docking and the overlay
|
||||
|
||||
The panel docks while the gutter between the transcript column and the Chat frame's end edge is at least 348px: 40px clear of the column and its width handle, the panel's 300px minimum width, and an 8px edge margin. Docked, it is 300–360px wide, 8px from the end edge, starts 12px below the header, stops above the composer stack, and scrolls inside itself in a reserved scrollbar column 2px from its end edge, so its content keeps one width whether or not it scrolls. 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. That key holds the docking preference, not [the pin](#the-pin).
|
||||
The panel docks while the gutter between the transcript column and the Chat frame's end edge is at least 348px: 40px clear of the column and its width handle, the panel's 300px minimum width, and an 8px edge margin. Docked, it is 300–360px wide, 8px from the end edge, starts 12px below the header, stops above the composer stack, and scrolls inside itself in a reserved scrollbar column 2px from its end edge, so its content keeps one width whether or not it scrolls. 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 unless [the pin](#the-pin) is on, so it never covers the transcript. This includes a narrow window, an expanded right sidebar, and a dragged-wide transcript column. Pressing the toggle then opens the panel over the transcript with the prominent elevation, 280px wide so it covers less of the transcript than the docked panel takes beside it, 8px from the end edge, 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 no Chat View shows the Session, as after switching to another Session or View, and switching back does not reopen it. When the panel hides while focus is inside it, focus moves to the toggle.
|
||||
Where the gutter is narrower than 348px, the Conversation body moves the transcript column and the composer toward the start edge, at their own widths, until the gutter is 348px, and the panel docks in it at its 300px minimum width ([end reserve](../ui-conversation/README.md#end-reserve)). The body moves them only while the docking preference is on, and only as far as leaves 32px before the column: with the default transcript width that takes a Chat frame about 1068px wide, and a transcript dragged wider takes a wider frame. Turning the docking preference off from the toggle centers the transcript again. An embedded Chat View, such as a side conversation, never moves its transcript.
|
||||
|
||||
Where the start gutter cannot give that room, the docked panel hides, so it never covers the transcript. This includes a narrow window, an expanded right sidebar, and a dragged-wide transcript column. Pressing the toggle then opens the panel over the transcript with the prominent elevation, 280px wide so it covers less of the transcript than the docked panel takes beside it, 8px from the end edge, 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 panel has room to dock and once no Chat View shows the Session, as after switching to another Session or View, and switching back does not reopen it. When the panel hides while focus is inside it, focus moves to the toggle.
|
||||
|
||||
Other Views, such as the trajectory View, show no panel. While no Chat View shows the Session, the toggle is unavailable: it stays in the header with its indicators, dimmed, and its tooltip asks to switch to the Chat view.
|
||||
|
||||
<a id="the-pin"></a>
|
||||
### The pin
|
||||
|
||||
The pin is a 24px button in the panel's top end corner, on the first shown section's title line, with its glyph in the column of the rows' More buttons. It is a toggle button named “Pin session panel” with `aria-pressed`, an outlined glyph in tertiary ink while off and a filled glyph in primary ink while on; its tooltip, shown after 500ms of hover or at once on keyboard focus, says what a press does. Every Session shares one pin, which persists in `localStorage` under `dsh.sessionPanel.held` and is off by default. The button shows where a press has an effect: on a docked panel, on an overlay whose transcript can make room, and wherever the pin is on.
|
||||
|
||||
While the pin and the docking preference are both on and the gutter is narrower than 348px, the Conversation body keeps that gutter free for the panel. The transcript column and the composer move toward the start edge by the missing gutter and keep their width; once the column is 32px from the start edge, it narrows instead. The panel docks in that gutter, 300px wide, and neither Escape nor an outside press hides it. The body makes no room when that would leave the column under 480px, which is a Chat frame under 860px wide. The pinned panel then behaves as an unpinned one: it hides, the toggle opens it as the overlay, and it docks again once the frame is wide enough. An embedded Chat View, such as a side conversation, never makes room. A gutter that holds the panel by itself needs no room made, and the transcript stays centered.
|
||||
|
||||
Pinning also sets the docking preference, so pinning a panel that the toggle had hidden in a wide window shows it. The toggle still hides and shows a pinned panel; hiding it gives the room back to the transcript. Unpinning a panel that only the pin kept beside the transcript leaves it open as the overlay, so it does not vanish under the pointer, and the next outside press closes it.
|
||||
|
||||
<a id="section-order"></a>
|
||||
### Section order
|
||||
|
||||
Environment always shows first. The other sections show in ascending `order` until the reader arranges them. The title row of each of those sections is a drag source: over it the pointer is a grab cursor and a drag handle shows at the row's end, in the column of the rows' More buttons. The handle is a mark, not a control, and takes no room in the row: the title's trailing content, such as a count, runs to the row's end. The row's end shows one of the two: the trailing content at rest, and the handle in its place while the pointer is over the title row and during a drag. Dragging the row dims its section, and the section under the pointer shows a 2px line on its top or bottom edge, whichever half the pointer is over; a drop moves the dragged section there. Over Environment the line is always on its bottom edge, since a section lands after it. Environment's title row is no drag source and has no handle, so the [pin](#the-pin) is the only control at its end.
|
||||
Environment always shows first. The other sections show in ascending `order` until the reader arranges them. The title row of each of those sections is a drag source: over it the pointer is a grab cursor and a drag handle shows at the row's end, in the column of the rows' More buttons. The handle is a mark, not a control, and takes no room in the row: the title's trailing content, such as a count, runs to the row's end. The row's end shows one of the two: the trailing content at rest, and the handle in its place while the pointer is over the title row and during a drag. Dragging the row dims its section, and the section under the pointer shows a 2px line on its top or bottom edge, whichever half the pointer is over; a drop moves the dragged section there. Over Environment the line is always on its bottom edge, since a section lands after it. Environment's title row is no drag source and has no handle.
|
||||
|
||||
The order is one preference for every Session, persisted in the browser's `localStorage` under `dsh.sessionPanel.sectionOrder` as a JSON array of the ids of every live section, including the ones with nothing to show. It belongs to the page's origin: another browser, another profile, or a Web server on another host or port starts from the registered order, and nothing sends the order to the Host. A section registered after the reader arranged the others follows the section it follows in the registered order.
|
||||
|
||||
@@ -87,9 +81,9 @@ A row whose single line clips its name or leaves out its owner, state, or measur
|
||||
<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 and pin, the Session whose overlay is open, and the room each mounted panel and each Session has to dock. The stylesheets decide that room. The aside layer publishes its end gutter as `--dsh-chat-aside-gutter`, and the Conversation body publishes the largest end reserve it can keep free as `--dsh-chat-end-reserve-max`; the docked width and two zero-height probes derive from them and from one set of metrics (40px clear, 8px edge, 300px minimum width). The gutter probe is 1px wide exactly from the 348px gutter that holds the panel at its minimum width as the transcript stands, and the reserve probe exactly from a largest reserve of 348px, where the transcript can make that room; each is 0 below it. The panel always renders both probes and attaches them through the injected `createProbeRef`, and the plugin observes only those elements with a `ResizeObserver`: it hears a decision flip and nothing while the window resizes on one side of it, the transcript width is dragged, or the transcript grows. A probe has room from 1px of width, a Session has a kind of room while any of its panels does, and a Session without a probe shows no Chat View. A panel can dock when its gutter holds it, or when the pin is on and the transcript can make room. The panel reads its own probes and the toggle its Session, and both decide the presentation with the same pure function, so the toggle's state never disagrees with the panel; opening, closing, or docking the panel renders nothing in the Chat View. Without `ResizeObserver` no probe gains room, and the panel shows only as an overlay. The aside layer also inherits the scrollport's composer and viewport heights.
|
||||
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 mounted panel and each Session has room to dock. The stylesheets decide that room. The aside layer publishes its end gutter as `--dsh-chat-aside-gutter`, and the Conversation body publishes the largest end reserve its start gutter can give as `--dsh-chat-end-reserve-max`; the docked width and a zero-height dock probe derive from them and from one set of metrics (40px clear, 8px edge, 300px minimum width). The probe is 1px wide while the gutter holds the panel at its minimum width, from 348px, or while the largest reserve covers that gutter, and 0 otherwise. The panel always renders the probe and attaches it through the injected `createProbeRef`, and the plugin observes only that element with a `ResizeObserver`: it hears the docking decision flip and nothing while the window resizes on one side of it, the transcript width is dragged, or the transcript grows. A probe has room from 1px of width, a Session has room while any of its probes does, and a Session without a probe shows no Chat View. The panel reads its own probe and the toggle its Session, and both decide the presentation with the same pure function, so the toggle's state never disagrees with the panel; opening, closing, or docking the panel renders nothing in the Chat View. Without `ResizeObserver` no probe gains room, and the panel shows only as an overlay. The aside layer also inherits the scrollport's composer and viewport heights.
|
||||
|
||||
While the pin and the docking preference are both on, the gutter probe carries `data-session-panel-reserve`, and a `:has()` rule in the panel's stylesheet sets `--dsh-chat-end-reserve` to 348px on the Conversation body, which then pads its scrollport's end ([end reserve](../ui-conversation/README.md#end-reserve)). The gutter the aside layer publishes counts that inset, and the gutter probe subtracts it, so neither probe depends on the pin: the plugin knows what pinning and unpinning do before either happens, and the room the transcript makes never changes the decision that asked for it.
|
||||
While the docking preference is on, the probe carries `data-session-panel-reserve`, and a `:has()` rule in the panel's stylesheet sets `--dsh-chat-end-reserve` to 348px on the Conversation body, which then pads its scrollport's end by the missing gutter ([end reserve](../ui-conversation/README.md#end-reserve)). The probe's second term reads the largest reserve, not the padding, so its answer is the same before and after the transcript moves: the room the transcript makes never changes the decision that asked for it.
|
||||
|
||||
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 and puts them in the reader's stored order, recomputed only when the ledger version, the locale revision, or that order 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.
|
||||
|
||||
@@ -97,11 +91,11 @@ 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) | Presentation, the shared visibility state with the pin, the room probes, and each Session's room to dock |
|
||||
| [`src/client/visibility.ts`](src/client/visibility.ts) | Presentation, the shared visibility state, the dock probes, and each Session's room to dock |
|
||||
| [`src/client/sections.ts`](src/client/sections.ts) | Section roster projection, the reader's stored order with Environment held first, and the move that changes it |
|
||||
| [`src/client/SessionPanel.tsx`](src/client/SessionPanel.tsx) | The panel, its probes, the pin, its section titles with their drag reordering, and Escape handling |
|
||||
| [`src/client/SessionPanel.tsx`](src/client/SessionPanel.tsx) | The panel, its dock probe, its section titles with their drag reordering, and Escape handling |
|
||||
| [`src/client/SessionPanelToggle.tsx`](src/client/SessionPanelToggle.tsx) | The header toggle and its indicators |
|
||||
| [`src/client/SessionPanel.module.css`](src/client/SessionPanel.module.css) | The panel's geometry, the probes, the pin, the request for the transcript's room, and the rules for marked rows |
|
||||
| [`src/client/SessionPanel.module.css`](src/client/SessionPanel.module.css) | The panel's geometry, the dock probe, the request for the transcript's room, and the rules for marked rows |
|
||||
| [`src/client/ProjectRow.tsx`](src/client/ProjectRow.tsx) | The working folder row |
|
||||
| [`src/client/PanelFold.tsx`](src/client/PanelFold.tsx) | The fold control of a folded list, offered as a Component Factory |
|
||||
| [`src/client/PanelDetails.tsx`](src/client/PanelDetails.tsx) | The details in a row's hover card, offered as a Component Factory |
|
||||
@@ -135,9 +129,8 @@ None; the package never assembles or sends provider requests.
|
||||
|
||||
These limits define current package constraints, not a task backlog.
|
||||
|
||||
- **An unpinned panel overlays at laptop widths** — with the default transcript width the body must be at least about 1580px wide to dock without the pin; narrower bodies use the overlay until the reader pins the panel.
|
||||
- **No width handles while the transcript makes room** — the handles sit at the centered column's edges and a drag widens the column about its center, so they do not show while a pinned panel holds the column off center. Unpinning or hiding the panel brings them back.
|
||||
- **Embedded Chat Views make no room** — an embedded transcript follows its frame's width, so a pinned panel docks there only in a gutter that holds it.
|
||||
- **Narrow frames overlay rather than dock** — the transcript keeps its width for the panel, so a Chat frame under about 1068px at the default transcript width, or a frame whose transcript was dragged wide, shows the panel only as the overlay.
|
||||
- **Embedded Chat Views make no room** — an embedded transcript follows its frame's width, so the panel docks there only in a gutter that holds it.
|
||||
- **No execution environment row** — the Client has no per-Session fact for the local machine, an SSH host, or the sandbox mode, so the Environment section names only the working folder.
|
||||
- **Sections cannot be hidden** — every live section shows; the reader can reorder sections but not hide one.
|
||||
- **Reordering needs a mouse** — dragging uses the browser's drag and drop, which a touch does not start, and the panel offers no keyboard way to reorder.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
description: "会话面板:会话标题栏开关与 Chat 视图侧边层中的悬浮面板,分栏由其他插件注册,可用图钉固定在正文旁,并内置「环境」分栏。"
|
||||
description: "会话面板:会话标题栏开关与 Chat 视图侧边层中的悬浮面板,分栏由其他插件注册,用户可以调整顺序,并内置「环境」分栏。"
|
||||
kind: "package-reference"
|
||||
---
|
||||
|
||||
@@ -9,7 +9,7 @@ kind: "package-reference"
|
||||
|
||||
## 概述
|
||||
|
||||
`dsh-client-ui-session-panel` 在会话标题栏加一个开关,用来显示或隐藏一块汇总当前会话信息的悬浮面板。面板只出现在 Chat 视图中:Chat 视图末端留白放得下面板时,面板停靠在留白里;放不下时,按需浮在对话正文上方。面板上的图钉让正文让出位置,使面板在更窄的宽度下也能停靠;用户还可以拖动分栏调整顺序。面板只绘制分栏标题,分栏内容交给注册分栏的插件;本包内置「环境」分栏及其工作目录行。
|
||||
`dsh-client-ui-session-panel` 在会话标题栏加一个开关,用来显示或隐藏一块汇总当前会话信息的悬浮面板。面板只出现在 Chat 视图中:它停靠在正文旁,位置是 Chat 视图的末端留白,或者正文移入起始留白后让出的位置;两者都放不下时,按需浮在对话正文上方。用户可以拖动分栏调整顺序。面板只绘制分栏标题,分栏内容交给注册分栏的插件;本包内置「环境」分栏及其工作目录行。
|
||||
|
||||
## 目录
|
||||
|
||||
@@ -27,27 +27,21 @@ kind: "package-reference"
|
||||
|
||||
`@deepseek-ai/dsh-web-app` 套件默认加载本包。开关是会话标题栏的第一个工具按钮,位于共享和计划任务目录之前。它是图标按钮:无障碍名称由面板名称和其角标组成,提示文字说明按下后是显示还是隐藏面板(悬停 500ms 后显示,键盘聚焦时立即显示),`aria-expanded` 表示面板当前是否显示。
|
||||
|
||||
<a id="docking"></a>
|
||||
### 停靠与浮层
|
||||
|
||||
正文列到 Chat 外框末端边缘的留白不少于 348px 时,面板停靠:与正文列及其宽度手柄保持 40px 间距,面板最小宽度 300px,外加 8px 边距。停靠时面板宽 300–360px,距末端边缘 8px,位于标题栏下方 12px,止于输入框区域上方,内容在面板内滚动,并为滚动条在距面板末端边缘 2px 处预留一列,因此无论是否滚动,内容宽度都不变。此时按开关会切换所有会话共用的停靠偏好,偏好存放在 `localStorage` 的 `dsh.sessionPanel.pinned` 中;默认停靠。这个键保存的是停靠偏好,不是[图钉](#the-pin)。
|
||||
正文列到 Chat 外框末端边缘的留白不少于 348px 时,面板停靠:与正文列及其宽度手柄保持 40px 间距,面板最小宽度 300px,外加 8px 边距。停靠时面板宽 300–360px,距末端边缘 8px,位于标题栏下方 12px,止于输入框区域上方,内容在面板内滚动,并为滚动条在距面板末端边缘 2px 处预留一列,因此无论是否滚动,内容宽度都不变。此时按开关会切换所有会话共用的停靠偏好,偏好存放在 `localStorage` 的 `dsh.sessionPanel.pinned` 中;默认停靠。
|
||||
|
||||
留白更窄时,除非[图钉](#the-pin)已开启,否则隐藏停靠面板,保证不遮挡正文。窗口变窄、展开右侧栏、把正文列拖宽都会如此。此时按开关,面板以更强的阴影浮在正文上方,宽 280px,比停靠时窄,以少遮挡正文,距末端边缘 8px,位于输入框区域之上,且不遮挡输入框。浮层可以用开关关闭,也会在按 Esc 时,或在面板、开关和任何已打开的菜单(例如行的上下文菜单)之外按下指针时关闭;焦点原本在面板内时,按 Esc 后焦点回到开关。页面上方有模态框、输入法正在组字,或已有处理程序(例如打开的菜单)接手了这次按键时,Esc 不归浮层;其余情况由浮层先处理,因此浮层打开时,在输入框按下的第一次 Esc 只关闭浮层,不计入停止当前轮次的连按。关闭浮层不改变停靠偏好。同一时间最多一个会话的浮层处于打开状态;留白变宽到可以停靠时,以及没有 Chat 视图再显示该会话时(例如切到其他会话或其他视图),浮层都会关闭,切回来也不会重新打开。面板隐藏时如果焦点在面板内,焦点移到开关。
|
||||
留白窄于 348px 时,Conversation 主体把正文列和输入框向起始边缘移动,两者宽度不变,直到留白达到 348px,面板以 300px 的最小宽度停靠在其中([末端预留](../ui-conversation/README.zh.md#end-reserve))。主体只在停靠偏好开启时移动它们,并且移动后正文列之前至少保留 32px:默认正文宽度下,这要求 Chat 外框约 1068px 宽;正文拖得更宽时需要更宽的外框。用开关关闭停靠偏好后,正文恢复居中。嵌入的 Chat 视图(例如侧边对话)始终不移动正文。
|
||||
|
||||
起始留白给不出这段位置时,停靠面板隐藏,保证不遮挡正文。窗口变窄、展开右侧栏、把正文列拖宽都会如此。此时按开关,面板以更强的阴影浮在正文上方,宽 280px,比停靠时窄,以少遮挡正文,距末端边缘 8px,位于输入框区域之上,且不遮挡输入框。浮层可以用开关关闭,也会在按 Esc 时,或在面板、开关和任何已打开的菜单(例如行的上下文菜单)之外按下指针时关闭;焦点原本在面板内时,按 Esc 后焦点回到开关。页面上方有模态框、输入法正在组字,或已有处理程序(例如打开的菜单)接手了这次按键时,Esc 不归浮层;其余情况由浮层先处理,因此浮层打开时,在输入框按下的第一次 Esc 只关闭浮层,不计入停止当前轮次的连按。关闭浮层不改变停靠偏好。同一时间最多一个会话的浮层处于打开状态;面板有位置可以停靠时,以及没有 Chat 视图再显示该会话时(例如切到其他会话或其他视图),浮层都会关闭,切回来也不会重新打开。面板隐藏时如果焦点在面板内,焦点移到开关。
|
||||
|
||||
轨迹等其他视图不显示面板。没有 Chat 视图显示该会话时,开关不可用:它连同角标留在标题栏中并变淡,悬停提示请用户切换到「对话」视图。
|
||||
|
||||
<a id="the-pin"></a>
|
||||
### 图钉
|
||||
|
||||
图钉是面板顶部末端角上的一个 24px 按钮,与第一个显示出来的分栏标题同一行,图标位于各行「更多」按钮所在的那一列。它是一个切换按钮,名称为「固定会话面板」,带 `aria-pressed`;关闭时是三级墨色的空心图标,开启时是主墨色的实心图标;提示文字说明按下后的效果,悬停 500ms 后显示,键盘聚焦时立即显示。所有会话共用一个图钉,状态存放在 `localStorage` 的 `dsh.sessionPanel.held` 中,默认关闭。按钮只在按下有效果的地方显示:已停靠的面板上、正文能让出位置的浮层上,以及图钉已开启的任何时候。
|
||||
|
||||
图钉和停靠偏好都开启、且留白窄于 348px 时,Conversation 主体为面板空出这段留白。正文列和输入框向起始边缘移动所缺的留白,宽度不变;正文列距起始边缘只剩 32px 后,改为变窄。面板停靠在这段留白里,宽 300px,按 Esc 或在面板外按下指针都不会隐藏它。如果让位会使正文列窄于 480px,也就是 Chat 外框窄于 860px,主体不让位。此时已固定的面板与未固定时相同:面板隐藏,按开关以浮层打开,外框够宽后重新停靠。嵌入的 Chat 视图(例如侧边对话)始终不让位。留白本身放得下面板时无需让位,正文保持居中。
|
||||
|
||||
固定面板同时会开启停靠偏好,因此在宽窗口中固定一个被开关隐藏的面板会让它显示出来。开关仍然可以隐藏和显示已固定的面板;隐藏后,让出的位置还给正文。取消固定一个仅靠图钉留在正文旁的面板时,面板保持打开并变为浮层,不会在指针下消失;下一次在面板外按下指针时关闭。
|
||||
|
||||
<a id="section-order"></a>
|
||||
### 分栏顺序
|
||||
|
||||
「环境」始终排在第一。用户调整之前,其余分栏按 `order` 升序显示。这些分栏的标题行都可以拖动:指针移到标题行上时变为抓手,行末出现拖动图标,位于各行「更多」按钮所在的那一列。图标只是标记,不是控件,也不占用标题行的空间:标题行末尾的内容(例如计数)一直排到行末。行末只显示两者之一:平时显示末尾的内容;指针位于标题行上以及拖动期间,图标取而代之。拖动标题行时,该分栏变淡,指针下方的分栏在上边缘或下边缘显示一条 2px 的线,取决于指针位于它的上半还是下半;松开后被拖动的分栏移到那里。指针在「环境」上方时,线始终在它的下边缘,因为分栏只能落在它之后。「环境」的标题行不能拖动,也没有拖动图标,因此行末只有[图钉](#the-pin)这一个控件。
|
||||
「环境」始终排在第一。用户调整之前,其余分栏按 `order` 升序显示。这些分栏的标题行都可以拖动:指针移到标题行上时变为抓手,行末出现拖动图标,位于各行「更多」按钮所在的那一列。图标只是标记,不是控件,也不占用标题行的空间:标题行末尾的内容(例如计数)一直排到行末。行末只显示两者之一:平时显示末尾的内容;指针位于标题行上以及拖动期间,图标取而代之。拖动标题行时,该分栏变淡,指针下方的分栏在上边缘或下边缘显示一条 2px 的线,取决于指针位于它的上半还是下半;松开后被拖动的分栏移到那里。指针在「环境」上方时,线始终在它的下边缘,因为分栏只能落在它之后。「环境」的标题行不能拖动,也没有拖动图标。
|
||||
|
||||
顺序是所有会话共用的一个偏好,保存在浏览器的 `localStorage` 中,键为 `dsh.sessionPanel.sectionOrder`,值是全部有效分栏(包括当前没有内容的分栏)的 id 组成的 JSON 数组。它属于页面所在的源:换一个浏览器、换一个浏览器配置,或访问另一个主机或端口上的 Web 服务,都从注册顺序开始;顺序不会发送到 Host。用户调整之后才注册的分栏,排在按注册顺序位于它前面的那个分栏之后。
|
||||
|
||||
@@ -87,9 +81,9 @@ kind: "package-reference"
|
||||
<details>
|
||||
<summary>实现内幕——点击展开</summary>
|
||||
|
||||
面板是 [`dsh-client-ui-chat`](../ui-chat/README.zh.md#scroll-ownership) 中 `conversation.chat.aside` 的占位组件,因此只渲染在 Chat 视图中。开关与面板是两个独立的 Slot 条目,共享一份插件持有的状态:持久化的停靠偏好与图钉、打开了浮层的会话,以及每个已挂载的面板和每个会话有哪些停靠空间。停靠空间由样式表决定。侧边层把末端留白发布为 `--dsh-chat-aside-gutter`,Conversation 主体把它最多能空出的末端预留发布为 `--dsh-chat-end-reserve-max`;停靠宽度和两个零高度的探针都由它们和同一组尺寸(间距 40px、边距 8px、最小宽度 300px)推出。留白探针恰好从留白 348px(正文不动时放得下最小宽度的面板)起宽 1px,预留探针恰好从最大预留 348px(正文能让出这段位置)起宽 1px;更窄时宽度都为 0。面板始终渲染两个探针,并通过注入的 `createProbeRef` 挂接它们;插件只用 `ResizeObserver` 观察这两个元素,所以只在某项判断翻转时收到通知,窗口在阈值同一侧缩放、拖动正文宽度或正文增长时都不会。探针宽度达到 1px 即有空间;会话的任一面板有某种空间时该会话就有这种空间,没有探针的会话表示没有 Chat 视图在显示它。留白放得下面板,或者图钉已开启且正文能让位时,面板可以停靠。面板读取自己的探针,开关读取所在会话,两者用同一个纯函数决定呈现方式,因此开关状态始终与面板一致;打开、关闭或停靠面板也不会让 Chat 视图重新渲染。没有 `ResizeObserver` 时任何探针都不会获得空间,面板只以浮层显示。侧边层还从滚动容器继承输入框区域与视口高度。
|
||||
面板是 [`dsh-client-ui-chat`](../ui-chat/README.zh.md#scroll-ownership) 中 `conversation.chat.aside` 的占位组件,因此只渲染在 Chat 视图中。开关与面板是两个独立的 Slot 条目,共享一份插件持有的状态:持久化的停靠偏好、打开了浮层的会话,以及每个已挂载的面板和每个会话是否有停靠空间。停靠空间由样式表决定。侧边层把末端留白发布为 `--dsh-chat-aside-gutter`,Conversation 主体把起始留白最多能让出的末端预留发布为 `--dsh-chat-end-reserve-max`;停靠宽度和一个零高度的停靠探针都由它们和同一组尺寸(间距 40px、边距 8px、最小宽度 300px)推出。留白放得下最小宽度的面板(从 348px 起),或者最大预留覆盖这段留白时,探针宽 1px,否则宽度为 0。面板始终渲染探针,并通过注入的 `createProbeRef` 挂接它;插件只用 `ResizeObserver` 观察这一个元素,所以只在停靠判断翻转时收到通知,窗口在阈值同一侧缩放、拖动正文宽度或正文增长时都不会。探针宽度达到 1px 即有停靠空间;会话的任一探针有空间时该会话就有停靠空间,没有探针的会话表示没有 Chat 视图在显示它。面板读取自己的探针,开关读取所在会话,两者用同一个纯函数决定呈现方式,因此开关状态始终与面板一致;打开、关闭或停靠面板也不会让 Chat 视图重新渲染。没有 `ResizeObserver` 时任何探针都不会获得空间,面板只以浮层显示。侧边层还从滚动容器继承输入框区域与视口高度。
|
||||
|
||||
图钉和停靠偏好都开启时,留白探针带有 `data-session-panel-reserve`,面板样式表中的一条 `:has()` 规则据此在 Conversation 主体上把 `--dsh-chat-end-reserve` 设为 348px,主体随即给滚动容器的末端加上内边距([末端预留](../ui-conversation/README.zh.md#end-reserve))。侧边层发布的留白包含这段内边距,留白探针再把它减掉,因此两个探针都不依赖图钉:插件在固定或取消固定之前就知道结果,正文让出的位置也不会反过来改变提出让位的那项判断。
|
||||
停靠偏好开启时,探针带有 `data-session-panel-reserve`,面板样式表中的一条 `:has()` 规则据此在 Conversation 主体上把 `--dsh-chat-end-reserve` 设为 348px,主体随即按所缺的留白给滚动容器的末端加上内边距([末端预留](../ui-conversation/README.zh.md#end-reserve))。探针的第二项读取的是最大预留而不是内边距,因此正文移动前后它的结果相同:正文让出的位置不会反过来改变提出让位的那项判断。
|
||||
|
||||
面板把分栏列表的实时注册(`entriesOfSlot`,因此同 `id` 且优先级更高的注册会替换已发布的分栏)投影为 `{ id, label }` 行,并按用户保存的顺序排列,只在台账版本、语言版本或该顺序变化时重新计算。它在各分栏自己的标题和正文容器里用 `renderSlot(..., { only: id })` 渲染内容;CSS `:has()` 规则隐藏正文出口为空的分栏,也包括行出口为空的共享分栏。
|
||||
|
||||
@@ -97,11 +91,11 @@ 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/SessionPanel.tsx`](src/client/SessionPanel.tsx) | 面板、停靠探针、分栏标题及其拖动排序,以及 Esc 处理 |
|
||||
| [`src/client/SessionPanelToggle.tsx`](src/client/SessionPanelToggle.tsx) | 标题栏开关及其角标 |
|
||||
| [`src/client/SessionPanel.module.css`](src/client/SessionPanel.module.css) | 面板的几何、探针、图钉、向正文申请位置的规则,以及带标记的行的样式规则 |
|
||||
| [`src/client/SessionPanel.module.css`](src/client/SessionPanel.module.css) | 面板的几何、停靠探针、向正文申请位置的规则,以及带标记的行的样式规则 |
|
||||
| [`src/client/ProjectRow.tsx`](src/client/ProjectRow.tsx) | 工作目录行 |
|
||||
| [`src/client/PanelFold.tsx`](src/client/PanelFold.tsx) | 被收起列表的收起控件,以 Component Factory 提供 |
|
||||
| [`src/client/PanelDetails.tsx`](src/client/PanelDetails.tsx) | 行的悬停卡片里的详情,以 Component Factory 提供 |
|
||||
@@ -135,9 +129,8 @@ kind: "package-reference"
|
||||
|
||||
以下限制定义的是当前包的约束,而非任务待办清单。
|
||||
|
||||
- **未固定的面板在笔记本宽度下使用浮层**——在默认正文宽度下,不用图钉时对话区宽度需约 1580px 以上才能停靠;更窄时使用浮层,直到用户固定面板。
|
||||
- **正文让位期间没有宽度手柄**——手柄位于居中正文列的两侧,拖动时正文列以中心为基准变宽,因此已固定的面板让正文列偏离中心时不显示手柄。取消固定或隐藏面板后手柄恢复。
|
||||
- **嵌入的 Chat 视图不让位**——嵌入的正文跟随外框宽度,因此已固定的面板在其中只在留白本身放得下时停靠。
|
||||
- **窄外框使用浮层而非停靠**——正文不会为面板变窄,因此默认正文宽度下 Chat 外框窄于约 1068px,或者正文被拖得很宽时,面板只以浮层显示。
|
||||
- **嵌入的 Chat 视图不让位**——嵌入的正文跟随外框宽度,因此面板在其中只在留白本身放得下时停靠。
|
||||
- **没有运行环境行**——客户端没有区分本机、SSH 主机或沙箱模式的会话级信息,因此「环境」分栏只显示工作目录。
|
||||
- **不能隐藏分栏**——所有有内容的分栏都会显示;用户可以调整分栏顺序,但不能隐藏某个分栏。
|
||||
- **调整顺序需要鼠标**——拖动使用浏览器的拖放,触摸不会触发拖放,面板也不提供用键盘调整顺序的方式。
|
||||
|
||||
@@ -9,18 +9,18 @@
|
||||
panel's width and the dock probe both derive from them, so the gutter that
|
||||
docks the panel is exactly the one that holds its minimum width. */
|
||||
.panel,
|
||||
.dockProbe,
|
||||
.reserveProbe {
|
||||
.dockProbe {
|
||||
--panel-clear: 40px;
|
||||
--panel-edge: 8px;
|
||||
--panel-min-width: 300px;
|
||||
}
|
||||
|
||||
/* A pinned panel has the Conversation body keep the gutter that docks it:
|
||||
the three metrics above, 348px. The body moves the transcript and the
|
||||
composer aside for it (ui-conversation's end reserve) and makes no room
|
||||
when that would leave the transcript column under 480px. The gutter probe
|
||||
carries the mark while the pin and the docking preference are both on. */
|
||||
/* While the docking preference is on, the dock probe carries a mark, and
|
||||
the panel asks the Conversation body to keep the gutter that docks it:
|
||||
the three metrics above, 348px. Where the gutter is narrower, the body
|
||||
moves the transcript and the composer into the start gutter for it
|
||||
(ui-conversation's end reserve) and makes no room when the start gutter
|
||||
cannot give it. */
|
||||
:global([data-conversation-content]):has(.dockProbe[data-session-panel-reserve]) {
|
||||
--dsh-chat-end-reserve: calc(40px + 8px + 300px);
|
||||
}
|
||||
@@ -66,84 +66,31 @@
|
||||
box-shadow: var(--dsw-elevation-prominent);
|
||||
}
|
||||
|
||||
/* The probes tell the plugin where the docked panel has room without a pixel
|
||||
measurement: each is 1px wide while its condition holds and 0 otherwise, a
|
||||
width under 0 being used as 0. A size observer on one therefore reports
|
||||
only when its decision flips, not while the window resizes on one side of
|
||||
it or the transcript grows. They have no height and take no pointer
|
||||
events. */
|
||||
.dockProbe,
|
||||
.reserveProbe {
|
||||
/* The dock probe tells the plugin whether the docked panel has room without
|
||||
a pixel measurement: it is 1px wide while the gutter holds the panel's
|
||||
minimum width, or while the Conversation body's largest end reserve covers
|
||||
that gutter, and 0 otherwise, a width under 0 being used as 0. A size
|
||||
observer on it therefore reports only when the docking decision flips,
|
||||
not while the window resizes on one side of it or the transcript grows.
|
||||
The second term does not depend on whether the body is making room, so
|
||||
the room the transcript makes never changes the decision that asked for
|
||||
it; it is the step the body takes its end inset from, so the probe has
|
||||
room exactly where the body makes it. It has no height and takes no
|
||||
pointer events. */
|
||||
.dockProbe {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: max(
|
||||
calc(var(--dsh-chat-aside-gutter, 0px) - var(--panel-clear) - var(--panel-edge) - var(--panel-min-width) + 1px),
|
||||
calc((var(--dsh-chat-end-reserve-max, 0px) - var(--panel-clear) - var(--panel-edge) - var(--panel-min-width)) * 10000000 + 1px)
|
||||
);
|
||||
max-width: 1px;
|
||||
height: 0;
|
||||
visibility: hidden;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* The gutter holds the panel's minimum width as the transcript stands. The
|
||||
gutter counts the body's end inset, so any inset takes the probe to 0: a
|
||||
gutter the transcript made is the reserve probe's to report. */
|
||||
.dockProbe {
|
||||
width: calc(
|
||||
var(--dsh-chat-aside-gutter, 0px) - var(--dsh-chat-end-inset, 0px) * 9999
|
||||
- var(--panel-clear) - var(--panel-edge) - var(--panel-min-width) + 1px
|
||||
);
|
||||
}
|
||||
|
||||
/* The transcript can make the room: the body's largest end reserve covers
|
||||
the gutter that docks the panel. It does not depend on the pin, so the
|
||||
plugin knows what pinning would do before the pin is on. */
|
||||
.reserveProbe {
|
||||
width: calc(var(--dsh-chat-end-reserve-max, 0px) - var(--panel-clear) - var(--panel-edge) - var(--panel-min-width) + 1px);
|
||||
}
|
||||
|
||||
/* The pin: the panel's top end corner, on the first shown section's title
|
||||
line. It floats, so that title row, which is a formatting context of its
|
||||
own, ends before it whichever section shows first; its bottom margin keeps
|
||||
the float clear of the rows under the title. A 24px target whose 14px
|
||||
glyph sits in the column of the rows' More buttons, 14px from the rows'
|
||||
end. Tertiary ink, and primary ink with the filled glyph while pinned. */
|
||||
.pin {
|
||||
/* Positioned, so it paints and takes presses above the sections, which are positioned for their landing lines. */
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
float: inline-end;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
margin: 4px 2px -4px 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: var(--dsw-radius-xs);
|
||||
color: var(--dsw-alias-label-tertiary);
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.pin[aria-pressed='true'] {
|
||||
color: var(--dsw-alias-label-primary);
|
||||
}
|
||||
|
||||
.pin:focus-visible {
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
@media (hover: hover) {
|
||||
.pin:hover {
|
||||
color: var(--dsw-alias-label-primary);
|
||||
background: var(--dsw-alias-interactive-bg-hover);
|
||||
}
|
||||
}
|
||||
|
||||
.pin:active {
|
||||
background: var(--dsw-alias-interactive-bg-active);
|
||||
}
|
||||
|
||||
.section {
|
||||
position: relative;
|
||||
padding: 4px 0 6px;
|
||||
@@ -240,12 +187,13 @@
|
||||
|
||||
/* The drag handle lies over the end of a draggable title row, in the column
|
||||
of the rows' More buttons: a 24px box whose center is 14px from the row's
|
||||
end. It is a mark, not a control: the whole title row is the drag source.
|
||||
It takes no room in the row, so the title's trailing content runs to the
|
||||
row's end as it does without the handle. The row's end shows one of the
|
||||
two: the trailing content at rest, and the handle in its place while the
|
||||
pointer is over the title row and during a drag. The hidden content keeps
|
||||
its box, so the title does not move. */
|
||||
end. It is a mark, not a control: the whole title row is the drag source,
|
||||
and the mark passes pointer events through to it and, at rest, to the
|
||||
trailing content under it. It takes no room in the row, so the title's
|
||||
trailing content runs to the row's end as it does without the handle. The
|
||||
row's end shows one of the two: the trailing content at rest, and the
|
||||
handle in its place while the pointer is over the title row and during a
|
||||
drag. The hidden content keeps its box, so the title does not move. */
|
||||
.grip {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
@@ -257,6 +205,7 @@
|
||||
height: 24px;
|
||||
color: var(--dsw-alias-label-tertiary);
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.section[data-dragging] .grip {
|
||||
|
||||
@@ -1,8 +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, useMemo, useRef, useState, type DragEvent, type FocusEvent, type ReactNode } from 'react'
|
||||
import {
|
||||
IconDragHandleOutlineRegular, IconPinFillRegular, IconPinOutlineRegular, isBehindModal, observeComposition, Tooltip, useRowDragPreview,
|
||||
} from '@deepseek-ai/dsh-client-ui-primitives'
|
||||
import { IconDragHandleOutlineRegular, isBehindModal, observeComposition, useRowDragPreview } from '@deepseek-ai/dsh-client-ui-primitives'
|
||||
import { panelElementId, toggleElementId } from './element-ids.ts'
|
||||
import { ENVIRONMENT_SECTION_ID } from './sections.ts'
|
||||
import type { SessionPanelProps, SessionPanelSectionOwnerProps } from './slots.ts'
|
||||
@@ -152,34 +150,29 @@ function useSectionReorder(moveSection: (id: string, target: string, placement:
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the panel while it docks or shows as an overlay, and always its two
|
||||
* probes. Each section keeps its title row and body; CSS hides a section
|
||||
* Render the panel while it docks or shows as an overlay, and always its
|
||||
* dock probe. 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. CSS sizes the docked panel from the Chat View's end
|
||||
* gutter and makes each probe 1px wide while its condition holds: the gutter
|
||||
* holds the panel, or the transcript can make that room. The plugin observes
|
||||
* the probes, so the panel renders again only when a decision flips. While
|
||||
* the pin and the docking preference are both on, the gutter probe carries
|
||||
* the mark that has the Conversation body keep the panel's room free. The
|
||||
* pin button shows where pressing it has an effect: on a docked panel, on an
|
||||
* overlay whose transcript can make room, and wherever the pin is on. The
|
||||
* title row of every section but Environment is draggable, which reorders
|
||||
* the sections, and holds a drag handle that its stylesheet shows on hover.
|
||||
* @param props - Session values, shared visibility, sections and their move action, the probes' room and their ref factory, the pin
|
||||
* action, and copy.
|
||||
* @returns the probes and, unless hidden, the panel.
|
||||
* gutter and makes the probe 1px wide while the panel has room to dock: that
|
||||
* gutter holds it, or the transcript can move aside to leave it. The plugin
|
||||
* observes the probe, so the panel renders again only when the docking
|
||||
* decision flips. While the docking preference is on, the probe carries the
|
||||
* mark that has the Conversation body keep the panel's room free. The title
|
||||
* row of every section but Environment is draggable, which reorders the
|
||||
* sections, and holds a drag handle that its stylesheet shows on hover.
|
||||
* @param props - Session values, shared visibility, sections and their move action, the dock probes and their ref factory, and copy.
|
||||
* @returns the dock probe and, unless hidden, the panel.
|
||||
*/
|
||||
export function SessionPanel({
|
||||
sessionId, useVisibility, useSections, useProbes, createProbeRef, setPinned, closeOverlay, moveSection, renderSlot, t,
|
||||
sessionId, useVisibility, useSections, useProbes, createProbeRef, closeOverlay, moveSection, renderSlot, t,
|
||||
}: SessionPanelProps): ReactNode {
|
||||
const probe = useId()
|
||||
// One ref lifecycle per probe of this mounted panel: the entry remounts with its Session, so the Session is fixed.
|
||||
const [gutterRef] = useState(() => createProbeRef(sessionId, probe, 'gutter'))
|
||||
const [reserveRef] = useState(() => createProbeRef(sessionId, probe, 'reserve'))
|
||||
const room = useProbes(probes => probes.get(probe))
|
||||
const presentation = useVisibility(visibility => presentationOf(room, visibility, sessionId))
|
||||
const pinned = useVisibility(visibility => visibility.pinned)
|
||||
const reserves = useVisibility(visibility => visibility.pinned && visibility.docks)
|
||||
// One ref lifecycle for this mounted panel: the entry remounts with its Session, so the Session is fixed.
|
||||
const [probeRef] = useState(() => createProbeRef(sessionId, probe))
|
||||
const fits = useProbes(probes => probes.get(probe) === true)
|
||||
const presentation = useVisibility(visibility => presentationOf(fits, visibility, sessionId))
|
||||
const docks = useVisibility(visibility => visibility.pinned)
|
||||
const sections = useSections(entries => entries)
|
||||
const panel = useRef<HTMLElement>(null)
|
||||
const dismissOverlay = useCallback(() => { closeOverlay(sessionId) }, [closeOverlay, sessionId])
|
||||
@@ -192,13 +185,7 @@ export function SessionPanel({
|
||||
const reorder = useSectionReorder(moveSection)
|
||||
return (
|
||||
<>
|
||||
<span
|
||||
ref={gutterRef}
|
||||
className={css.dockProbe}
|
||||
data-session-panel-probe="gutter"
|
||||
data-session-panel-reserve={reserves ? '' : undefined}
|
||||
/>
|
||||
<span ref={reserveRef} className={css.reserveProbe} data-session-panel-probe="reserve" />
|
||||
<span ref={probeRef} className={css.dockProbe} data-session-panel-probe="" data-session-panel-reserve={docks ? '' : undefined} />
|
||||
{owner !== undefined && (
|
||||
<aside
|
||||
id={panelElementId(sessionId)}
|
||||
@@ -209,20 +196,6 @@ export function SessionPanel({
|
||||
onBlur={focus.onBlur}
|
||||
data-session-panel={owner.presentation}
|
||||
>
|
||||
{(pinned || owner.presentation === 'docked' || room?.reserve === true) && (
|
||||
<Tooltip label={t(pinned ? 'pin.unpin' : 'pin.pin')} side="bottom" align="end" delayMs={500} portal>
|
||||
<button
|
||||
type="button"
|
||||
className={css.pin}
|
||||
aria-label={t('pin.name')}
|
||||
aria-pressed={pinned}
|
||||
data-session-panel-pin=""
|
||||
onClick={() => { setPinned(sessionId, !pinned) }}
|
||||
>
|
||||
{pinned ? <IconPinFillRegular size={14} /> : <IconPinOutlineRegular size={14} />}
|
||||
</button>
|
||||
</Tooltip>
|
||||
)}
|
||||
{sections.map((section) => {
|
||||
const titleId = `${panelElementId(sessionId)}-${section.id}`
|
||||
return (
|
||||
|
||||
@@ -17,9 +17,9 @@ import css from './SessionPanelToggle.module.css'
|
||||
export function SessionPanelToggle({
|
||||
sessionId, useDockable, useVisibility, toggle, renderSlot, t,
|
||||
}: SessionPanelToggleProps): ReactNode {
|
||||
const room = useDockable(entries => entries.get(sessionId))
|
||||
const shown = useVisibility(visibility => presentationOf(room, visibility, sessionId) !== 'hidden')
|
||||
const available = room !== 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')
|
||||
const nameId = useId()
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* Session panel plugin, browser half: a Session header toggle and a floating
|
||||
* panel in the Chat View's aside, with a pin that has the transcript make room
|
||||
* for it. The panel draws the titles of the sections other plugins register,
|
||||
* lays out the rows they mark, offers the fold control their lists end with
|
||||
* and the details their rows show on hover, and ships the Environment section
|
||||
* with the working folder row.
|
||||
* panel in the Chat View's aside. The panel draws the titles of the sections
|
||||
* other plugins register, lays out the rows they mark, offers the fold control
|
||||
* their lists end with and the details their rows show on hover, and ships the
|
||||
* Environment section with the working folder row.
|
||||
*/
|
||||
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
||||
import type { ObservableSnapshot } from '@deepseek-ai/dsh-client-store'
|
||||
@@ -34,7 +33,7 @@ declare module '@deepseek-ai/dsh-client-ui-slots' {
|
||||
|
||||
export type {
|
||||
EnvironmentSectionProps, PanelDetailsFact, PanelDetailsProps, PanelFoldProps, ProjectRowInjected, ProjectRowProps, SessionPanelDockable,
|
||||
SessionPanelIndicatorOwnerProps, SessionPanelInjected, SessionPanelPresentation, SessionPanelProbes, SessionPanelProps, SessionPanelRoom,
|
||||
SessionPanelIndicatorOwnerProps, SessionPanelInjected, SessionPanelPresentation, SessionPanelProbes, SessionPanelProps,
|
||||
SessionPanelSectionEntry, SessionPanelSectionOwnerProps, SessionPanelToggleInjected, SessionPanelToggleProps, SessionPanelVisibility,
|
||||
} from './slots.ts'
|
||||
|
||||
@@ -51,7 +50,7 @@ export function apply(ctx: ClientContext): void {
|
||||
ctx.effect(() => ctx.locale.register(NS, { zh, en, ja, es, fr, de, ru, pt }), 'ui-session-panel: dictionaries')
|
||||
const t = ctx.locale.bind(NS)
|
||||
const state = new SessionPanelState()
|
||||
ctx.effect(() => () => { state.dispose() }, 'ui-session-panel: overlay follower and room probes')
|
||||
ctx.effect(() => () => { state.dispose() }, 'ui-session-panel: overlay follower and dock probes')
|
||||
const sections = sectionSource(ctx)
|
||||
const host: ObservableSnapshot<RemoteHostFacts> = {
|
||||
getSnapshot: () => ctx.remote.$host,
|
||||
@@ -85,8 +84,7 @@ export function apply(ctx: ClientContext): void {
|
||||
},
|
||||
inject: (): SessionPanelInjected => ({
|
||||
hooks: { visibility: state.visibility, sections, probes: state.probes },
|
||||
createProbeRef: (sessionId, probe, member) => state.createProbeRef(sessionId, probe, member),
|
||||
setPinned: (sessionId, pinned) => { state.setPinned(sessionId, pinned) },
|
||||
createProbeRef: (sessionId, probe) => state.createProbeRef(sessionId, probe),
|
||||
closeOverlay: (sessionId) => { state.closeOverlay(sessionId) },
|
||||
moveSection: (id, target, placement) => { sections.move(id, target, placement) },
|
||||
}),
|
||||
|
||||
@@ -9,9 +9,6 @@ export const zh = {
|
||||
'toggle.show': '显示会话面板',
|
||||
'toggle.hide': '隐藏会话面板',
|
||||
'toggle.unavailable': '切换到「对话」视图后可显示会话面板',
|
||||
'pin.name': '固定会话面板',
|
||||
'pin.pin': '固定面板',
|
||||
'pin.unpin': '取消固定',
|
||||
'section.environment': '环境',
|
||||
'project.label': '工作目录',
|
||||
'project.actions': '工作目录操作',
|
||||
@@ -26,9 +23,6 @@ export const en: Record<SessionPanelKey, string> = {
|
||||
'toggle.show': 'Show session panel',
|
||||
'toggle.hide': 'Hide session panel',
|
||||
'toggle.unavailable': 'Switch to the Chat view to show the session panel',
|
||||
'pin.name': 'Pin session panel',
|
||||
'pin.pin': 'Pin panel',
|
||||
'pin.unpin': 'Unpin panel',
|
||||
'section.environment': 'Environment',
|
||||
'project.label': 'Working folder',
|
||||
'project.actions': 'Working folder actions',
|
||||
@@ -40,9 +34,6 @@ export const ja = {
|
||||
'toggle.show': 'セッションパネルを表示',
|
||||
'toggle.hide': 'セッションパネルを非表示',
|
||||
'toggle.unavailable': '「チャット」ビューに切り替えるとセッションパネルを表示できます',
|
||||
'pin.name': 'セッションパネルを固定',
|
||||
'pin.pin': 'パネルを固定',
|
||||
'pin.unpin': '固定を解除',
|
||||
'section.environment': '環境',
|
||||
'project.label': '作業フォルダー',
|
||||
'project.actions': '作業フォルダーの操作',
|
||||
@@ -54,9 +45,6 @@ export const es = {
|
||||
'toggle.show': 'Mostrar el panel de la sesión',
|
||||
'toggle.hide': 'Ocultar el panel de la sesión',
|
||||
'toggle.unavailable': 'Cambia a la vista Chat para mostrar el panel de la sesión',
|
||||
'pin.name': 'Fijar el panel de la sesión',
|
||||
'pin.pin': 'Fijar panel',
|
||||
'pin.unpin': 'Dejar de fijar',
|
||||
'section.environment': 'Entorno',
|
||||
'project.label': 'Carpeta de trabajo',
|
||||
'project.actions': 'Acciones de la carpeta de trabajo',
|
||||
@@ -68,9 +56,6 @@ export const fr = {
|
||||
'toggle.show': 'Afficher le panneau de session',
|
||||
'toggle.hide': 'Masquer le panneau de session',
|
||||
'toggle.unavailable': 'Passez à la vue Discussion pour afficher le panneau de session',
|
||||
'pin.name': 'Épingler le panneau de session',
|
||||
'pin.pin': 'Épingler le panneau',
|
||||
'pin.unpin': 'Détacher le panneau',
|
||||
'section.environment': 'Environnement',
|
||||
'project.label': 'Dossier de travail',
|
||||
'project.actions': 'Actions sur le dossier de travail',
|
||||
@@ -82,9 +67,6 @@ export const de = {
|
||||
'toggle.show': 'Sitzungsbereich anzeigen',
|
||||
'toggle.hide': 'Sitzungsbereich ausblenden',
|
||||
'toggle.unavailable': 'Wechseln Sie zur Ansicht „Chat“, um den Sitzungsbereich anzuzeigen',
|
||||
'pin.name': 'Sitzungsbereich anheften',
|
||||
'pin.pin': 'Bereich anheften',
|
||||
'pin.unpin': 'Bereich lösen',
|
||||
'section.environment': 'Umgebung',
|
||||
'project.label': 'Arbeitsordner',
|
||||
'project.actions': 'Aktionen für den Arbeitsordner',
|
||||
@@ -96,9 +78,6 @@ export const ru = {
|
||||
'toggle.show': 'Показать панель сеанса',
|
||||
'toggle.hide': 'Скрыть панель сеанса',
|
||||
'toggle.unavailable': 'Переключитесь на вид «Чат», чтобы показать панель сеанса',
|
||||
'pin.name': 'Закрепить панель сеанса',
|
||||
'pin.pin': 'Закрепить панель',
|
||||
'pin.unpin': 'Открепить панель',
|
||||
'section.environment': 'Среда',
|
||||
'project.label': 'Рабочая папка',
|
||||
'project.actions': 'Действия с рабочей папкой',
|
||||
@@ -110,9 +89,6 @@ export const pt = {
|
||||
'toggle.show': 'Mostrar painel da sessão',
|
||||
'toggle.hide': 'Ocultar painel da sessão',
|
||||
'toggle.unavailable': 'Mude para a visualização Chat para mostrar o painel da sessão',
|
||||
'pin.name': 'Fixar painel da sessão',
|
||||
'pin.pin': 'Fixar painel',
|
||||
'pin.unpin': 'Desafixar painel',
|
||||
'section.environment': 'Ambiente',
|
||||
'project.label': 'Pasta de trabalho',
|
||||
'project.actions': 'Ações da pasta de trabalho',
|
||||
|
||||
@@ -107,7 +107,7 @@ export interface PanelFoldProps {
|
||||
|
||||
/** How the panel currently shows. */
|
||||
export type SessionPanelPresentation =
|
||||
/** Beside the transcript: in the Chat View's end gutter, or in the room the transcript makes for a pinned panel. */
|
||||
/** Beside the transcript in the Chat View's end gutter, which the transcript moves aside to leave where it is narrower. */
|
||||
| 'docked'
|
||||
/** Over the transcript, opened from the toggle while the panel has no room to dock. */
|
||||
| 'overlay'
|
||||
@@ -136,34 +136,25 @@ export interface SessionPanelSectionEntry {
|
||||
|
||||
/** Panel visibility shared by the toggle and the panel. */
|
||||
export interface SessionPanelVisibility {
|
||||
/** Whether the panel docks while it has room, which the header toggle flips; persisted across reloads. */
|
||||
readonly docks: boolean
|
||||
/**
|
||||
* Whether the pin is on: the transcript then makes room for the panel where
|
||||
* the gutter alone is too narrow. Persisted across reloads.
|
||||
*/
|
||||
/** Whether the panel docks while it has room, in the gutter or where the transcript moves aside for it; persisted across reloads. */
|
||||
readonly pinned: boolean
|
||||
/** Session whose overlay is open, or null. */
|
||||
readonly overlay: SessionId | null
|
||||
}
|
||||
|
||||
/** The room one Chat View, or one Session across its Chat Views, has for the docked panel. */
|
||||
export interface SessionPanelRoom {
|
||||
/** The end gutter holds the docked panel as the transcript stands. */
|
||||
readonly gutter: boolean
|
||||
/** The transcript can move aside or narrow to leave the docked panel its room, which it does only for a pinned panel. */
|
||||
readonly reserve: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* The room each Session whose Chat View holds a panel has to dock it: a
|
||||
* member is true when at least one of the Session's Chat Views reports it. A
|
||||
* Whether each Session whose Chat View holds a panel has room to dock it:
|
||||
* true when, in at least one of its Chat Views, the end gutter holds the
|
||||
* docked panel or the transcript can move aside to leave that gutter. A
|
||||
* Session without an entry shows no Chat View.
|
||||
*/
|
||||
export type SessionPanelDockable = ReadonlyMap<SessionId, SessionPanelRoom>
|
||||
export type SessionPanelDockable = ReadonlyMap<SessionId, boolean>
|
||||
|
||||
/** The room of each mounted panel's Chat View, by the id the panel gave its probes. */
|
||||
export type SessionPanelProbes = ReadonlyMap<string, SessionPanelRoom>
|
||||
/**
|
||||
* Whether each mounted panel's Chat View has room for the docked panel, by
|
||||
* the id the panel gave its dock probe.
|
||||
*/
|
||||
export type SessionPanelProbes = ReadonlyMap<string, boolean>
|
||||
|
||||
/** Business face of the header toggle. */
|
||||
export interface SessionPanelToggleInjected {
|
||||
@@ -184,7 +175,7 @@ export interface SessionPanelToggleInjected {
|
||||
/** Business face of the panel. */
|
||||
export interface SessionPanelInjected {
|
||||
/**
|
||||
* Shared visibility, the projected section roster, and each mounted panel's
|
||||
* Shared visibility, the projected section roster, and each dock probe's
|
||||
* room; the renderer binds them as `useVisibility`, `useSections`, and `useProbes`.
|
||||
*/
|
||||
readonly hooks: {
|
||||
@@ -193,24 +184,15 @@ export interface SessionPanelInjected {
|
||||
readonly probes: ObservableSnapshot<SessionPanelProbes>
|
||||
}
|
||||
/**
|
||||
* Create the ref of one probe of a mounted panel, an element whose
|
||||
* stylesheet width says whether the Chat View has one kind of room for the
|
||||
* docked panel. The plugin observes the element while it is attached and
|
||||
* records what it decides under `probe`, and the Session's for the toggle.
|
||||
* Create the ref of one mounted panel's dock probe, the element whose
|
||||
* stylesheet width says whether the Chat View has room for the docked
|
||||
* panel. The plugin observes the element while it is attached and records
|
||||
* the probe's room under `probe`, and the Session's for the toggle.
|
||||
* @param sessionId - Session the panel's Chat View shows.
|
||||
* @param probe - identity of the panel within the page.
|
||||
* @param member - the room the probe decides.
|
||||
* @returns the ref callback for the probe element; detaching withdraws the probe.
|
||||
*/
|
||||
readonly createProbeRef: (sessionId: SessionId, probe: string, member: keyof SessionPanelRoom) => (element: HTMLElement | null) => void
|
||||
/**
|
||||
* Pin or unpin the panel. Pinning also sets the docking preference;
|
||||
* unpinning a panel that only the pin kept beside the transcript leaves it
|
||||
* open as the Session's overlay.
|
||||
* @param sessionId - Session whose panel holds the pin.
|
||||
* @param pinned - the new pin.
|
||||
*/
|
||||
readonly setPinned: (sessionId: SessionId, pinned: boolean) => void
|
||||
readonly createProbeRef: (sessionId: SessionId, probe: string) => (element: HTMLElement | null) => void
|
||||
/**
|
||||
* Close the Session's overlay.
|
||||
* @param sessionId - Session whose overlay closes; another Session's overlay stays.
|
||||
|
||||
@@ -1,127 +1,99 @@
|
||||
/** Session panel visibility: the persisted docking preference and pin, the transient overlay, the room probes, and the presentation. */
|
||||
/** Session panel visibility: the persisted docking preference, the transient overlay, the dock probes, and the presentation. */
|
||||
import { createSnapshotStore, type ObservableSnapshot } from '@deepseek-ai/dsh-client-store'
|
||||
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
||||
import type {
|
||||
SessionPanelDockable, SessionPanelPresentation, SessionPanelProbes, SessionPanelRoom, SessionPanelVisibility,
|
||||
} from './slots.ts'
|
||||
import type { SessionPanelDockable, SessionPanelPresentation, SessionPanelProbes, SessionPanelVisibility } from './slots.ts'
|
||||
|
||||
/** localStorage key of the docking preference; stored choices keep the name they were saved under. */
|
||||
export const DOCKS_STORAGE_KEY = 'dsh.sessionPanel.pinned'
|
||||
/** localStorage key of the pin. */
|
||||
export const PINNED_STORAGE_KEY = 'dsh.sessionPanel.held'
|
||||
/** localStorage key of the docking preference. */
|
||||
export const PINNED_STORAGE_KEY = 'dsh.sessionPanel.pinned'
|
||||
|
||||
const NO_SESSIONS: SessionPanelDockable = new Map()
|
||||
const NO_PROBES: SessionPanelProbes = new Map()
|
||||
const NO_ROOM: SessionPanelRoom = { gutter: false, reserve: false }
|
||||
|
||||
/**
|
||||
* Decide whether a panel has a place beside the transcript: its gutter holds
|
||||
* it, or the pin is on and the transcript can make room.
|
||||
* @param room - the room of the panel's Chat View or of its Session; absent while no Chat View reports it.
|
||||
* @param visibility - shared visibility state.
|
||||
* @returns whether the panel can dock.
|
||||
*/
|
||||
export function hasRoom(room: SessionPanelRoom | undefined, visibility: SessionPanelVisibility): boolean {
|
||||
return room !== undefined && (room.gutter || (visibility.pinned && room.reserve))
|
||||
}
|
||||
|
||||
/**
|
||||
* Decide how the panel shows for one Session.
|
||||
* @param room - the room of the panel's Chat View or of its Session; absent while no Chat View reports it.
|
||||
* @param fits - whether the gutter can hold the docked panel.
|
||||
* @param visibility - shared visibility state.
|
||||
* @param sessionId - Session whose panel is decided.
|
||||
* @returns the presentation, or `hidden` when the panel renders nothing.
|
||||
*/
|
||||
export function presentationOf(
|
||||
room: SessionPanelRoom | undefined, visibility: SessionPanelVisibility, sessionId: SessionId,
|
||||
fits: boolean, visibility: SessionPanelVisibility, sessionId: SessionId,
|
||||
): SessionPanelPresentation | 'hidden' {
|
||||
if (hasRoom(room, visibility)) return visibility.docks ? 'docked' : 'hidden'
|
||||
if (fits) return visibility.pinned ? 'docked' : 'hidden'
|
||||
return visibility.overlay === sessionId ? 'overlay' : 'hidden'
|
||||
}
|
||||
|
||||
function sameRoom(a: SessionPanelRoom | undefined, b: SessionPanelRoom | undefined): boolean {
|
||||
return a?.gutter === b?.gutter && a?.reserve === b?.reserve
|
||||
}
|
||||
|
||||
/**
|
||||
* Visibility shared by every Session's toggle and panel, and the room each
|
||||
* mounted panel and each Session has to dock. The stylesheets decide the
|
||||
* room: each mounted panel renders two probes that are 1px wide while a
|
||||
* condition holds and 0 otherwise, one while its Chat View's end gutter
|
||||
* holds the docked panel and one while the transcript can make that room,
|
||||
* and this state observes only the probes, so it hears a decision flip and
|
||||
* nothing while the window resizes on one side of it or the transcript
|
||||
* grows. Docking follows one preference and one pin for all Sessions; at
|
||||
* most one Session's overlay is open, and it closes once its Session can
|
||||
* dock or no Chat View shows that Session any longer.
|
||||
* Visibility shared by every Session's toggle and panel, and whether each
|
||||
* mounted panel and each Session has room to dock. The panel's stylesheet
|
||||
* decides the room: each mounted panel renders a dock probe that is 1px wide
|
||||
* while its Chat View's end gutter holds the docked panel and 0 otherwise,
|
||||
* and this state observes only that probe, so it hears the decision flip
|
||||
* and nothing while the window resizes on one side of it or the transcript
|
||||
* grows. 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 docks = createSnapshotStore<unknown>(true, { persist: { name: DOCKS_STORAGE_KEY } })
|
||||
// A stored value other than `true` keeps the default: the panel is not pinned.
|
||||
private readonly pinned = createSnapshotStore<unknown>(false, { persist: { name: PINNED_STORAGE_KEY } })
|
||||
private readonly pinned = createSnapshotStore<unknown>(true, { persist: { name: PINNED_STORAGE_KEY } })
|
||||
private readonly overlay = createSnapshotStore<SessionId | null>(null)
|
||||
private readonly room = createSnapshotStore<SessionPanelDockable>(NO_SESSIONS)
|
||||
private readonly fits = createSnapshotStore<SessionPanelProbes>(NO_PROBES)
|
||||
/** The Session of every panel with an attached probe, and which of its probes are attached. */
|
||||
private readonly owners = new Map<string, { readonly sessionId: SessionId; readonly attached: Set<keyof SessionPanelRoom> }>()
|
||||
/** The Session of every attached probe. */
|
||||
private readonly owners = new Map<string, SessionId>()
|
||||
/** Stops observing each attached probe. */
|
||||
private readonly detachers = new Set<() => void>()
|
||||
private current: SessionPanelVisibility = {
|
||||
docks: this.docks.getSnapshot() !== false, pinned: this.pinned.getSnapshot() === true, overlay: null,
|
||||
}
|
||||
|
||||
/** Stops following the open overlay's Session. */
|
||||
private current: SessionPanelVisibility = { pinned: this.pinned.getSnapshot() !== false, overlay: null }
|
||||
/** Stops following the open overlay's gutter. */
|
||||
private unfollow: () => void = () => {}
|
||||
|
||||
/** Combined visibility; the snapshot keeps its identity until a member changes. */
|
||||
readonly visibility: ObservableSnapshot<SessionPanelVisibility> = {
|
||||
getSnapshot: () => {
|
||||
const docks = this.docks.getSnapshot() !== false
|
||||
const pinned = this.pinned.getSnapshot() === true
|
||||
const pinned = this.pinned.getSnapshot() !== false
|
||||
const overlay = this.overlay.getSnapshot()
|
||||
if (docks !== this.current.docks || pinned !== this.current.pinned || overlay !== this.current.overlay) {
|
||||
this.current = { docks, pinned, overlay }
|
||||
}
|
||||
if (pinned !== this.current.pinned || overlay !== this.current.overlay) this.current = { pinned, overlay }
|
||||
return this.current
|
||||
},
|
||||
subscribe: (listener) => {
|
||||
const offs = [this.docks.subscribe(listener), this.pinned.subscribe(listener), this.overlay.subscribe(listener)]
|
||||
const offPinned = this.pinned.subscribe(listener)
|
||||
const offOverlay = this.overlay.subscribe(listener)
|
||||
return () => {
|
||||
for (const off of offs) off()
|
||||
offPinned()
|
||||
offOverlay()
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* The room each Session with a mounted panel has to dock it: each member is
|
||||
* true while any of the Session's Chat Views reports it. The snapshot keeps
|
||||
* its identity until a Session gains or loses its entry or its room changes.
|
||||
* Whether each Session with a mounted panel has room to dock it: true while
|
||||
* any of its probes does. The snapshot keeps its identity until a Session
|
||||
* gains or loses its entry or its room changes.
|
||||
*/
|
||||
readonly dockable: ObservableSnapshot<SessionPanelDockable> = this.room
|
||||
|
||||
/**
|
||||
* The room each mounted panel's probes report. The snapshot keeps its
|
||||
* identity until a panel's probes attach, detach, or flip.
|
||||
* Whether each attached probe's gutter holds the docked panel. The snapshot
|
||||
* keeps its identity until a probe attaches, detaches, or flips.
|
||||
*/
|
||||
readonly probes: ObservableSnapshot<SessionPanelProbes> = this.fits
|
||||
|
||||
/**
|
||||
* Create the element-ref lifecycle of one probe of a mounted panel.
|
||||
* Create the element-ref lifecycle of one mounted panel's dock probe.
|
||||
* Attaching the element enters the probe without room and observes its
|
||||
* size; a probe at least 1px wide has room. Detaching stops the
|
||||
* observation and withdraws the probe. Without `ResizeObserver` the probe
|
||||
* stays without room, so the panel shows only as an overlay.
|
||||
* @param sessionId - Session the panel's Chat View shows.
|
||||
* @param probe - identity of the panel within the page.
|
||||
* @param member - the room the probe's stylesheet width decides.
|
||||
* @returns the ref callback for the probe element.
|
||||
*/
|
||||
createProbeRef(sessionId: SessionId, probe: string, member: keyof SessionPanelRoom): (element: HTMLElement | null) => void {
|
||||
createProbeRef(sessionId: SessionId, probe: string): (element: HTMLElement | null) => void {
|
||||
let detach: (() => void) | undefined
|
||||
return (element) => {
|
||||
detach?.()
|
||||
detach = element === null ? undefined : this.attach(sessionId, probe, member, element)
|
||||
detach = element === null ? undefined : this.attach(sessionId, probe, element)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,36 +104,14 @@ export class SessionPanelState {
|
||||
* @param sessionId - Session whose header holds the toggle.
|
||||
*/
|
||||
toggle(sessionId: SessionId): void {
|
||||
const room = this.room.getSnapshot().get(sessionId)
|
||||
if (room === undefined) return
|
||||
const visibility = this.visibility.getSnapshot()
|
||||
if (hasRoom(room, visibility)) {
|
||||
this.docks.set(!visibility.docks)
|
||||
const dockable = this.room.getSnapshot().get(sessionId)
|
||||
if (dockable === undefined) return
|
||||
if (dockable) {
|
||||
this.pinned.set(!this.visibility.getSnapshot().pinned)
|
||||
this.setOverlay(null)
|
||||
return
|
||||
}
|
||||
this.setOverlay(visibility.overlay === sessionId ? null : sessionId)
|
||||
}
|
||||
|
||||
/**
|
||||
* Pin or unpin the panel from a Session's panel. Pinning also sets the
|
||||
* docking preference, so the panel docks wherever the transcript can make
|
||||
* room, and an open overlay then closes as its Session docks. Unpinning a
|
||||
* panel that only the pin kept beside the transcript leaves it open as the
|
||||
* Session's overlay.
|
||||
* @param sessionId - Session whose panel holds the pin.
|
||||
* @param pinned - the new pin.
|
||||
*/
|
||||
setPinned(sessionId: SessionId, pinned: boolean): void {
|
||||
if (pinned) {
|
||||
this.docks.set(true)
|
||||
this.pinned.set(true)
|
||||
return
|
||||
}
|
||||
const room = this.room.getSnapshot().get(sessionId)
|
||||
const held = room?.gutter === false && presentationOf(room, this.visibility.getSnapshot(), sessionId) === 'docked'
|
||||
this.pinned.set(false)
|
||||
if (held) this.setOverlay(sessionId)
|
||||
this.setOverlay(this.overlay.getSnapshot() === sessionId ? null : sessionId)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,19 +138,15 @@ export class SessionPanelState {
|
||||
this.overlay.set(sessionId)
|
||||
if (sessionId === null) return
|
||||
const check = (): void => {
|
||||
const room = this.room.getSnapshot().get(sessionId)
|
||||
if (room === undefined || hasRoom(room, this.visibility.getSnapshot())) this.closeOverlay(sessionId)
|
||||
}
|
||||
const offs = [this.room.subscribe(check), this.pinned.subscribe(check)]
|
||||
this.unfollow = () => {
|
||||
for (const off of offs) off()
|
||||
if (this.room.getSnapshot().get(sessionId) !== false) this.closeOverlay(sessionId)
|
||||
}
|
||||
this.unfollow = this.room.subscribe(check)
|
||||
}
|
||||
|
||||
private attach(sessionId: SessionId, probe: string, member: keyof SessionPanelRoom, element: HTMLElement): () => void {
|
||||
this.report(sessionId, probe, member, false)
|
||||
private attach(sessionId: SessionId, probe: string, element: HTMLElement): () => void {
|
||||
this.report(sessionId, probe, false)
|
||||
const measure: ResizeObserverCallback = (entries) => {
|
||||
for (const entry of entries) this.report(sessionId, probe, member, entry.contentRect.width >= 1)
|
||||
for (const entry of entries) this.report(sessionId, probe, entry.contentRect.width >= 1)
|
||||
}
|
||||
const observer = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(measure)
|
||||
observer?.observe(element)
|
||||
@@ -208,36 +154,32 @@ export class SessionPanelState {
|
||||
// The ref callback and dispose may both detach; the first one withdraws the probe.
|
||||
if (!this.detachers.delete(detach)) return
|
||||
observer?.disconnect()
|
||||
this.report(sessionId, probe, member, null)
|
||||
this.report(sessionId, probe, null)
|
||||
}
|
||||
this.detachers.add(detach)
|
||||
return detach
|
||||
}
|
||||
|
||||
/** Record what one probe decided, or its withdrawal, publishing only what changed. */
|
||||
private report(sessionId: SessionId, probe: string, member: keyof SessionPanelRoom, has: boolean | null): void {
|
||||
const owner = this.owners.get(probe) ?? { sessionId, attached: new Set<keyof SessionPanelRoom>() }
|
||||
if (has === null) owner.attached.delete(member)
|
||||
else owner.attached.add(member)
|
||||
/** Record one probe's room, or its withdrawal, publishing only what changed. */
|
||||
private report(sessionId: SessionId, probe: string, dockable: boolean | null): void {
|
||||
const fits = this.fits.getSnapshot()
|
||||
const before = fits.get(probe)
|
||||
// A panel keeps its entry while either of its probes is attached; a withdrawn probe reports no room.
|
||||
const after = owner.attached.size === 0 ? undefined : { ...before ?? NO_ROOM, [member]: has === true }
|
||||
if (after === undefined) this.owners.delete(probe)
|
||||
else this.owners.set(probe, owner)
|
||||
if (!sameRoom(before, after)) {
|
||||
if (fits.get(probe) !== (dockable ?? undefined)) {
|
||||
const next = new Map(fits)
|
||||
if (after === undefined) next.delete(probe)
|
||||
else next.set(probe, after)
|
||||
if (dockable === null) {
|
||||
next.delete(probe)
|
||||
this.owners.delete(probe)
|
||||
} else {
|
||||
next.set(probe, dockable)
|
||||
this.owners.set(probe, sessionId)
|
||||
}
|
||||
this.fits.set(next)
|
||||
}
|
||||
let any: SessionPanelRoom | undefined
|
||||
for (const [id, own] of this.fits.getSnapshot()) {
|
||||
if (this.owners.get(id)?.sessionId !== sessionId) continue
|
||||
any = { gutter: any?.gutter === true || own.gutter, reserve: any?.reserve === true || own.reserve }
|
||||
let any: boolean | undefined
|
||||
for (const [id, owner] of this.owners) {
|
||||
if (owner === sessionId) any = any === true || this.fits.getSnapshot().get(id) === true
|
||||
}
|
||||
const room = this.room.getSnapshot()
|
||||
if (sameRoom(room.get(sessionId), any)) return
|
||||
if (room.get(sessionId) === any) return
|
||||
const next = new Map(room)
|
||||
if (any === undefined) next.delete(sessionId)
|
||||
else next.set(sessionId, any)
|
||||
|
||||
@@ -74,20 +74,15 @@ describe('ui-session-panel browser half', () => {
|
||||
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)
|
||||
const attach = panel.createProbeRef(SID, 'main', 'gutter')
|
||||
const attach = panel.createProbeRef(SID, 'main')
|
||||
// The node suite has no DOM or ResizeObserver; the probe enters without room and stays unobserved.
|
||||
attach({} as HTMLElement)
|
||||
expect(panel.hooks.probes.getSnapshot().get('main')).toEqual({ gutter: false, reserve: false })
|
||||
expect(toggle.hooks.dockable.getSnapshot().get(SID)).toEqual({ gutter: false, reserve: false })
|
||||
expect(panel.hooks.probes.getSnapshot().get('main')).toBe(false)
|
||||
expect(toggle.hooks.dockable.getSnapshot().get(SID)).toBe(false)
|
||||
toggle.toggle(SID)
|
||||
expect(panel.hooks.visibility.getSnapshot()).toEqual({ docks: true, pinned: false, overlay: SID })
|
||||
expect(panel.hooks.visibility.getSnapshot()).toEqual({ pinned: true, overlay: SID })
|
||||
panel.closeOverlay(SID)
|
||||
expect(panel.hooks.visibility.getSnapshot().overlay).toBeNull()
|
||||
// The panel's pin reaches the same shared visibility.
|
||||
panel.setPinned(SID, true)
|
||||
expect(toggle.hooks.visibility.getSnapshot()).toEqual({ docks: true, pinned: true, overlay: null })
|
||||
panel.setPinned(SID, false)
|
||||
expect(toggle.hooks.visibility.getSnapshot().pinned).toBe(false)
|
||||
toggle.toggle(SID)
|
||||
// Disposing the plugin withdraws the probe and stops the open overlay from following the room to dock.
|
||||
await fiber.dispose()
|
||||
|
||||
@@ -14,16 +14,14 @@ import { SessionPanel } from '../src/client/SessionPanel.tsx'
|
||||
import { SessionPanelToggle } from '../src/client/SessionPanelToggle.tsx'
|
||||
import type {
|
||||
EnvironmentSectionProps, PanelDetailsProps, ProjectRowProps, SessionPanelDockable, SessionPanelProbes, SessionPanelProps,
|
||||
SessionPanelRoom, SessionPanelSectionEntry, SessionPanelSectionOwnerProps, SessionPanelToggleProps, SessionPanelVisibility,
|
||||
SessionPanelSectionEntry, SessionPanelSectionOwnerProps, SessionPanelToggleProps, SessionPanelVisibility,
|
||||
} from '../src/client/slots.ts'
|
||||
import { SessionPanelState } from '../src/client/visibility.ts'
|
||||
import { en, zh } from '../src/client/locales.ts'
|
||||
|
||||
const SID = 'session-1' as SessionId
|
||||
const t = makeTranslate(zh) as SessionPanelToggleProps['t']
|
||||
const DOCKED: SessionPanelVisibility = { docks: true, pinned: false, overlay: null }
|
||||
/** Room in the gutter alone, as a wide window gives, or none at all. */
|
||||
const roomOf = (gutter: boolean): SessionPanelRoom => ({ gutter, reserve: false })
|
||||
const DOCKED: SessionPanelVisibility = { pinned: true, overlay: null }
|
||||
|
||||
function selectorOf<T>(value: T) {
|
||||
return <S,>(select: (current: T) => S): S => select(value)
|
||||
@@ -57,7 +55,7 @@ function tooltipAfterHover(anchor: Element): { readonly early: boolean; readonly
|
||||
describe('SessionPanelToggle', () => {
|
||||
function toggleProps(dockable: boolean | undefined, visibility: SessionPanelVisibility, toggle = vi.fn()) {
|
||||
const renderSlot = vi.fn(() => <span>需要处理</span>)
|
||||
const entries: SessionPanelDockable = new Map(dockable === undefined ? [] : [[SID, roomOf(dockable)]])
|
||||
const entries: SessionPanelDockable = new Map(dockable === undefined ? [] : [[SID, dockable]])
|
||||
const props = {
|
||||
sessionId: SID, useDockable: selectorOf(entries), useVisibility: selectorOf(visibility), toggle, renderSlot, t,
|
||||
} as SessionPanelToggleProps
|
||||
@@ -89,7 +87,7 @@ describe('SessionPanelToggle', () => {
|
||||
})
|
||||
|
||||
it('reports an open overlay as expanded', () => {
|
||||
const { props } = toggleProps(false, { docks: false, pinned: false, overlay: SID })
|
||||
const { props } = toggleProps(false, { pinned: false, overlay: SID })
|
||||
render(<SessionPanelToggle {...props} />)
|
||||
expect(screen.getByRole('button').getAttribute('aria-expanded')).toBe('true')
|
||||
})
|
||||
@@ -107,7 +105,7 @@ describe('SessionPanelToggle', () => {
|
||||
})
|
||||
|
||||
it('is unavailable and says why while no Chat View shows the Session', () => {
|
||||
const { props } = toggleProps(undefined, { docks: true, pinned: false, overlay: SID })
|
||||
const { props } = toggleProps(undefined, { pinned: true, overlay: SID })
|
||||
render(<SessionPanelToggle {...props} />)
|
||||
const button = screen.getByRole('button')
|
||||
expect(button.getAttribute('aria-disabled')).toBe('true')
|
||||
@@ -129,11 +127,8 @@ describe('SessionPanel', () => {
|
||||
const probeIds = new Set<string>()
|
||||
afterEach(() => { probeIds.clear() })
|
||||
|
||||
/** Panel props whose panels all have this room: a boolean stands for the gutter alone. */
|
||||
function panelProps(dockable: boolean | SessionPanelRoom, visibility: SessionPanelVisibility, closeOverlay = vi.fn()) {
|
||||
const room = typeof dockable === 'boolean' ? roomOf(dockable) : dockable
|
||||
const setPinned = vi.fn<(sessionId: SessionId, pinned: boolean) => void>()
|
||||
const moveSection = vi.fn<(id: string, target: string, placement: 'before' | 'after') => void>()
|
||||
/** Panel props whose dock probes all have, or all lack, room to dock. */
|
||||
function panelProps(dockable: boolean, visibility: SessionPanelVisibility, closeOverlay = vi.fn()) {
|
||||
const owners: SessionPanelSectionOwnerProps[] = []
|
||||
const renderSlot = ((key: string, owner: object, opts?: { only?: string; entryKey?: string }): ReactNode => {
|
||||
if (key === 'conversation.session.panel.section.actions') {
|
||||
@@ -142,8 +137,9 @@ describe('SessionPanel', () => {
|
||||
owners.push(owner as SessionPanelSectionOwnerProps)
|
||||
return <p>{`${opts?.only ?? ''} body`}</p>
|
||||
}) as SessionPanelProps['renderSlot']
|
||||
const moveSection = vi.fn<(id: string, target: string, placement: 'before' | 'after') => void>()
|
||||
const attached = vi.fn<(element: HTMLElement | null) => void>()
|
||||
const createProbeRef = vi.fn((_sessionId: SessionId, probe: string, _member: keyof SessionPanelRoom) => {
|
||||
const createProbeRef = vi.fn((_sessionId: SessionId, probe: string) => {
|
||||
probeIds.add(probe)
|
||||
return attached
|
||||
})
|
||||
@@ -151,36 +147,33 @@ describe('SessionPanel', () => {
|
||||
sessionId: SID,
|
||||
useVisibility: selectorOf(visibility),
|
||||
useSections: selectorOf(SECTIONS),
|
||||
useProbes: <S,>(select: (probes: SessionPanelProbes) => S): S => select(new Map([...probeIds].map(id => [id, room]))),
|
||||
useProbes: <S,>(select: (probes: SessionPanelProbes) => S): S => select(new Map([...probeIds].map(id => [id, dockable]))),
|
||||
createProbeRef,
|
||||
setPinned,
|
||||
closeOverlay,
|
||||
moveSection,
|
||||
renderSlot,
|
||||
t,
|
||||
} as SessionPanelProps
|
||||
return { props, owners, closeOverlay, createProbeRef, attached, setPinned, moveSection }
|
||||
return { props, owners, closeOverlay, createProbeRef, attached, moveSection }
|
||||
}
|
||||
|
||||
it('attaches its two probes through the injected refs once, under one id, and detaches them on unmount', () => {
|
||||
it('attaches its dock probe through the injected ref once and detaches it on unmount', () => {
|
||||
const { props, createProbeRef, attached } = panelProps(true, DOCKED)
|
||||
const view = render(<SessionPanel {...props} />)
|
||||
const gutter = view.container.querySelector('[data-session-panel-probe="gutter"]')
|
||||
const reserve = view.container.querySelector('[data-session-panel-probe="reserve"]')
|
||||
expect([gutter, reserve]).not.toContain(null)
|
||||
const id = createProbeRef.mock.calls[0]?.[1]
|
||||
expect(createProbeRef.mock.calls).toEqual([[SID, id, 'gutter'], [SID, id, 'reserve']])
|
||||
expect(attached.mock.calls).toEqual([[gutter], [reserve]])
|
||||
// A later render keeps the refs, so the probes are neither detached nor attached again.
|
||||
const probe = view.container.querySelector('[data-session-panel-probe]')
|
||||
expect(probe).not.toBeNull()
|
||||
expect(createProbeRef.mock.calls).toEqual([[SID, expect.any(String)]])
|
||||
expect(attached.mock.calls).toEqual([[probe]])
|
||||
// A later render keeps the ref, so the probe is neither detached nor attached again.
|
||||
const next = panelProps(true, DOCKED)
|
||||
view.rerender(<SessionPanel {...next.props} />)
|
||||
expect(next.createProbeRef).not.toHaveBeenCalled()
|
||||
expect(attached).toHaveBeenCalledTimes(2)
|
||||
expect(attached).toHaveBeenCalledTimes(1)
|
||||
view.unmount()
|
||||
expect(attached.mock.calls.slice(-2)).toEqual([[null], [null]])
|
||||
expect(attached.mock.calls.at(-1)).toEqual([null])
|
||||
})
|
||||
|
||||
it('renders again only when one of its probes flips', () => {
|
||||
it('renders again only when its dock probe flips', () => {
|
||||
const observed: { readonly element: Element; readonly callback: ResizeObserverCallback }[] = []
|
||||
vi.stubGlobal('ResizeObserver', class {
|
||||
private readonly callback: ResizeObserverCallback
|
||||
@@ -194,22 +187,19 @@ describe('SessionPanel', () => {
|
||||
const props = {
|
||||
...base.props,
|
||||
useProbes: bindSnapshotSelector(state.probes),
|
||||
createProbeRef: (sessionId: SessionId, probe: string, member: keyof SessionPanelRoom) =>
|
||||
state.createProbeRef(sessionId, probe, member),
|
||||
createProbeRef: (sessionId: SessionId, probe: string) => state.createProbeRef(sessionId, probe),
|
||||
} as SessionPanelProps
|
||||
const view = render(<SessionPanel {...props} />)
|
||||
/** Report the gutter probe's width. */
|
||||
const resize = (width: number): void => {
|
||||
act(() => {
|
||||
for (const { element, callback } of observed) {
|
||||
if (element.getAttribute('data-session-panel-probe') !== 'gutter') continue
|
||||
callback([{ target: element, contentRect: { width } } as ResizeObserverEntry], {} as ResizeObserver)
|
||||
}
|
||||
})
|
||||
}
|
||||
expect(observed.map(entry => entry.element)).toEqual([...view.container.querySelectorAll('[data-session-panel-probe]')])
|
||||
expect(observed.map(entry => entry.element)).toEqual([view.container.querySelector('[data-session-panel-probe]')])
|
||||
expect(screen.queryByRole('complementary')).toBeNull()
|
||||
expect(state.dockable.getSnapshot().get(SID)).toEqual(roomOf(false))
|
||||
expect(state.dockable.getSnapshot().get(SID)).toBe(false)
|
||||
resize(1)
|
||||
expect(screen.getByRole('complementary').getAttribute('data-session-panel')).toBe('docked')
|
||||
// CSS sizes the docked panel; no measured width reaches its style.
|
||||
@@ -220,16 +210,17 @@ describe('SessionPanel', () => {
|
||||
// A probe under 1px wide sits within a pixel below the gutter that docks the panel.
|
||||
resize(0.5)
|
||||
expect(screen.queryByRole('complementary')).toBeNull()
|
||||
expect(state.dockable.getSnapshot().get(SID)).toEqual(roomOf(false))
|
||||
expect(state.dockable.getSnapshot().get(SID)).toBe(false)
|
||||
view.unmount()
|
||||
expect(state.dockable.getSnapshot().has(SID)).toBe(false)
|
||||
})
|
||||
|
||||
it('renders only its probes while hidden', () => {
|
||||
const { props } = panelProps(true, { docks: false, pinned: false, overlay: null })
|
||||
it('renders only its dock probe while hidden', () => {
|
||||
const { props } = panelProps(true, { pinned: false, overlay: null })
|
||||
const view = render(<SessionPanel {...props} />)
|
||||
expect(view.container.querySelector('[data-session-panel]')).toBeNull()
|
||||
expect([...view.container.children].map(child => child.getAttribute('data-session-panel-probe'))).toEqual(['gutter', 'reserve'])
|
||||
expect(view.container.children).toHaveLength(1)
|
||||
expect(view.container.firstElementChild?.hasAttribute('data-session-panel-probe')).toBe(true)
|
||||
})
|
||||
|
||||
it('docks with one titled region per section in roster order and each section body', () => {
|
||||
@@ -249,7 +240,7 @@ describe('SessionPanel', () => {
|
||||
})
|
||||
|
||||
it('closes the overlay on Escape from inside and returns focus to the toggle', () => {
|
||||
const { props, owners, closeOverlay } = panelProps(false, { docks: true, pinned: false, overlay: SID })
|
||||
const { props, owners, closeOverlay } = panelProps(false, { pinned: true, overlay: SID })
|
||||
const toggle = document.createElement('button')
|
||||
toggle.id = `dsh-session-panel-toggle-${SID}`
|
||||
document.body.append(toggle)
|
||||
@@ -271,7 +262,7 @@ describe('SessionPanel', () => {
|
||||
})
|
||||
|
||||
it('closes the overlay on Escape from the page without moving focus', () => {
|
||||
const { props, closeOverlay } = panelProps(false, { docks: true, pinned: false, overlay: SID })
|
||||
const { props, closeOverlay } = panelProps(false, { pinned: true, overlay: SID })
|
||||
render(<SessionPanel {...props} />)
|
||||
const outside = document.createElement('input')
|
||||
document.body.append(outside)
|
||||
@@ -286,7 +277,7 @@ describe('SessionPanel', () => {
|
||||
})
|
||||
|
||||
it('closes the overlay on an outside pointerdown but not on the panel, the toggle, or an open menu', () => {
|
||||
const { props, closeOverlay } = panelProps(false, { docks: true, pinned: false, overlay: SID })
|
||||
const { props, closeOverlay } = panelProps(false, { pinned: true, overlay: SID })
|
||||
const toggle = document.createElement('button')
|
||||
toggle.id = `dsh-session-panel-toggle-${SID}`
|
||||
const menu = document.createElement('div')
|
||||
@@ -315,7 +306,7 @@ describe('SessionPanel', () => {
|
||||
fireEvent.pointerDown(document.body)
|
||||
expect(docked.closeOverlay).not.toHaveBeenCalled()
|
||||
cleanup()
|
||||
const overlay = panelProps(false, { docks: true, pinned: false, overlay: SID })
|
||||
const overlay = panelProps(false, { pinned: true, overlay: SID })
|
||||
render(<SessionPanel {...overlay.props} />)
|
||||
const event = new KeyboardEvent('keydown', { key: 'Escape', bubbles: true, cancelable: true })
|
||||
event.preventDefault()
|
||||
@@ -336,7 +327,7 @@ describe('SessionPanel', () => {
|
||||
})
|
||||
|
||||
it('leaves Escape to an input method composing text, including the key that ends the composition', () => {
|
||||
const { props, closeOverlay } = panelProps(false, { docks: true, pinned: false, overlay: SID })
|
||||
const { props, closeOverlay } = panelProps(false, { pinned: true, overlay: SID })
|
||||
render(<SessionPanel {...props} />)
|
||||
fireEvent(document, new Event('compositionstart'))
|
||||
fireEvent.keyDown(document, { key: 'Escape', isComposing: true })
|
||||
@@ -379,109 +370,16 @@ describe('SessionPanel', () => {
|
||||
}
|
||||
})
|
||||
|
||||
describe('pin', () => {
|
||||
const PINNED: SessionPanelVisibility = { docks: true, pinned: true, overlay: null }
|
||||
const RESERVE: SessionPanelRoom = { gutter: false, reserve: true }
|
||||
const pin = (): HTMLElement | null => screen.queryByRole('button', { name: '固定会话面板' })
|
||||
|
||||
it('offers the pin on a docked panel, unpressed, and pins on a press', () => {
|
||||
const { props, setPinned } = panelProps(true, DOCKED)
|
||||
const view = render(<SessionPanel {...props} />)
|
||||
const button = pin()!
|
||||
expect(button.getAttribute('aria-pressed')).toBe('false')
|
||||
// The pin precedes the sections, so it is the panel's first control.
|
||||
expect(screen.getByRole('complementary').firstElementChild).toBe(button)
|
||||
// Unpinned, the body is not asked to keep the panel's room.
|
||||
expect(view.container.querySelector('[data-session-panel-reserve]')).toBeNull()
|
||||
fireEvent.click(button)
|
||||
expect(setPinned.mock.calls).toEqual([[SID, true]])
|
||||
expect(tooltipAfterHover(button)).toEqual({ early: false, at500: true })
|
||||
expect(screen.getByRole('tooltip', { hidden: true }).textContent).toBe('固定面板')
|
||||
})
|
||||
|
||||
it('shows a pinned panel in the room the transcript makes, pressed, asks the body for that room, and unpins on a press', () => {
|
||||
const { props, setPinned, owners } = panelProps(RESERVE, PINNED)
|
||||
const view = render(<SessionPanel {...props} />)
|
||||
expect(screen.getByRole('complementary').getAttribute('data-session-panel')).toBe('docked')
|
||||
expect(owners.every(owner => owner.presentation === 'docked')).toBe(true)
|
||||
const button = pin()!
|
||||
expect(button.getAttribute('aria-pressed')).toBe('true')
|
||||
expect(view.container.querySelector('[data-session-panel-reserve]')?.getAttribute('data-session-panel-probe')).toBe('gutter')
|
||||
fireEvent.click(button)
|
||||
expect(setPinned.mock.calls).toEqual([[SID, false]])
|
||||
fireEvent.keyDown(document.body, { key: 'Tab' })
|
||||
fireEvent.focus(button)
|
||||
expect(screen.getByRole('tooltip', { hidden: true }).textContent).toBe('取消固定')
|
||||
})
|
||||
|
||||
it('asks for no room while the toggle hides a pinned panel', () => {
|
||||
const { props } = panelProps(RESERVE, { docks: false, pinned: true, overlay: null })
|
||||
const view = render(<SessionPanel {...props} />)
|
||||
expect(screen.queryByRole('complementary')).toBeNull()
|
||||
expect(view.container.querySelector('[data-session-panel-reserve]')).toBeNull()
|
||||
})
|
||||
|
||||
it('offers the pin on an overlay only where the transcript can make room or the pin is already on', () => {
|
||||
const none = panelProps(false, { docks: true, pinned: false, overlay: SID })
|
||||
const view = render(<SessionPanel {...none.props} />)
|
||||
expect(screen.getByRole('complementary').getAttribute('data-session-panel')).toBe('overlay')
|
||||
expect(pin()).toBeNull()
|
||||
view.rerender(<SessionPanel {...panelProps(RESERVE, { docks: true, pinned: false, overlay: SID }).props} />)
|
||||
expect(pin()?.getAttribute('aria-pressed')).toBe('false')
|
||||
// Pinned where the transcript cannot make room: the overlay still offers the way to unpin.
|
||||
view.rerender(<SessionPanel {...panelProps(false, { docks: true, pinned: true, overlay: SID }).props} />)
|
||||
expect(screen.getByRole('complementary').getAttribute('data-session-panel')).toBe('overlay')
|
||||
expect(pin()?.getAttribute('aria-pressed')).toBe('true')
|
||||
})
|
||||
|
||||
it('keeps the panel mounted and the pin focused as a press docks the overlay and the next one returns it', () => {
|
||||
const observed: { readonly element: Element; readonly callback: ResizeObserverCallback }[] = []
|
||||
vi.stubGlobal('ResizeObserver', class {
|
||||
private readonly callback: ResizeObserverCallback
|
||||
constructor(callback: ResizeObserverCallback) { this.callback = callback }
|
||||
observe(element: Element): void { observed.push({ element, callback: this.callback }) }
|
||||
unobserve(): void {}
|
||||
disconnect(): void {}
|
||||
})
|
||||
const state = new SessionPanelState()
|
||||
const props = {
|
||||
...panelProps(false, DOCKED).props,
|
||||
useVisibility: bindSnapshotSelector(state.visibility),
|
||||
useProbes: bindSnapshotSelector(state.probes),
|
||||
createProbeRef: (sessionId: SessionId, probe: string, member: keyof SessionPanelRoom) =>
|
||||
state.createProbeRef(sessionId, probe, member),
|
||||
setPinned: (sessionId: SessionId, pinned: boolean) => { state.setPinned(sessionId, pinned) },
|
||||
closeOverlay: (sessionId: SessionId) => { state.closeOverlay(sessionId) },
|
||||
} as SessionPanelProps
|
||||
render(<SessionPanel {...props} />)
|
||||
// The transcript can make room; the gutter alone holds nothing.
|
||||
act(() => {
|
||||
for (const { element, callback } of observed) {
|
||||
if (element.getAttribute('data-session-panel-probe') !== 'reserve') continue
|
||||
callback([{ target: element, contentRect: { width: 1 } } as ResizeObserverEntry], {} as ResizeObserver)
|
||||
}
|
||||
})
|
||||
expect(screen.queryByRole('complementary')).toBeNull()
|
||||
act(() => { state.toggle(SID) })
|
||||
const panel = screen.getByRole('complementary')
|
||||
expect(panel.getAttribute('data-session-panel')).toBe('overlay')
|
||||
const button = pin()!
|
||||
button.focus()
|
||||
fireEvent.click(button)
|
||||
expect(panel.getAttribute('data-session-panel')).toBe('docked')
|
||||
expect(screen.getByRole('complementary')).toBe(panel)
|
||||
expect(document.activeElement).toBe(pin())
|
||||
// An outside press no longer closes it.
|
||||
fireEvent.pointerDown(document.body)
|
||||
fireEvent.keyDown(document, { key: 'Escape' })
|
||||
expect(screen.getByRole('complementary').getAttribute('data-session-panel')).toBe('docked')
|
||||
fireEvent.click(pin()!)
|
||||
expect(screen.getByRole('complementary')).toBe(panel)
|
||||
expect(panel.getAttribute('data-session-panel')).toBe('overlay')
|
||||
expect(document.activeElement).toBe(pin())
|
||||
fireEvent.pointerDown(document.body)
|
||||
expect(screen.queryByRole('complementary')).toBeNull()
|
||||
})
|
||||
it('marks its dock probe to ask the transcript for room while the docking preference is on, whether or not it shows', () => {
|
||||
const marked = (container: HTMLElement): boolean => container.querySelector('[data-session-panel-probe]')!.hasAttribute('data-session-panel-reserve')
|
||||
const docked = render(<SessionPanel {...panelProps(true, DOCKED).props} />)
|
||||
expect(marked(docked.container)).toBe(true)
|
||||
// Without room the panel is hidden or an overlay, and the mark stays: the transcript makes room once it can.
|
||||
docked.rerender(<SessionPanel {...panelProps(false, DOCKED).props} />)
|
||||
expect(marked(docked.container)).toBe(true)
|
||||
// The toggle turned docking off: the transcript keeps its place.
|
||||
docked.rerender(<SessionPanel {...panelProps(true, { pinned: false, overlay: null }).props} />)
|
||||
expect(marked(docked.container)).toBe(false)
|
||||
})
|
||||
|
||||
describe('section order', () => {
|
||||
@@ -528,8 +426,8 @@ describe('SessionPanel', () => {
|
||||
expect(headOf(id).lastElementChild).toBe(grip)
|
||||
expect([grip.tagName, grip.getAttribute('aria-hidden')]).toEqual(['SPAN', 'true'])
|
||||
}
|
||||
// The panel's only buttons are the pin and the control a section put in its own title row.
|
||||
expect(screen.getAllByRole('button').map(button => button.getAttribute('aria-label') ?? button.textContent)).toEqual(['固定会话面板', '刷新'])
|
||||
// The panel's only button is the control a section put in its own title row.
|
||||
expect(screen.getAllByRole('button').map(button => button.getAttribute('aria-label') ?? button.textContent)).toEqual(['刷新'])
|
||||
// Environment keeps its place: its title row is no drag source and has no handle.
|
||||
expect(headOf('environment').draggable).toBe(false)
|
||||
expect(gripOf('environment')).toBeNull()
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* The Session panel's stylesheet as CSS text. jsdom has no layout, so the
|
||||
* component suite cannot show that each probe is 1px wide exactly from the
|
||||
* room it reports, what a pinned panel asks of the Conversation body, or
|
||||
* that marked rows get one geometry; this reads the declarations and
|
||||
* evaluates the docking ones around their boundaries.
|
||||
* component suite cannot show that the dock probe is 1px wide exactly from
|
||||
* the gutter that holds the docked panel, or that marked rows get one
|
||||
* geometry; this reads the declarations and evaluates the docking ones for
|
||||
* gutters around that boundary.
|
||||
*/
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
@@ -31,7 +31,7 @@ const px = (value: string | undefined): number => {
|
||||
}
|
||||
|
||||
describe('SessionPanel.module.css docking geometry', () => {
|
||||
const metrics = declarationsOf('.panel, .dockProbe, .reserveProbe')
|
||||
const metrics = declarationsOf('.panel, .dockProbe')
|
||||
const clear = px(metrics['--panel-clear'])
|
||||
const edge = px(metrics['--panel-edge'])
|
||||
const minWidth = px(metrics['--panel-min-width'])
|
||||
@@ -43,19 +43,18 @@ describe('SessionPanel.module.css docking geometry', () => {
|
||||
expect(panel['width']).toBe(
|
||||
'clamp(var(--panel-min-width), calc(var(--dsh-chat-aside-gutter, 0px) - var(--panel-clear) - var(--panel-edge)), 360px)',
|
||||
)
|
||||
expect(declarationsOf('.dockProbe')['width']).toBe(
|
||||
'calc(var(--dsh-chat-aside-gutter, 0px) - var(--dsh-chat-end-inset, 0px) * 9999'
|
||||
+ ' - var(--panel-clear) - var(--panel-edge) - var(--panel-min-width) + 1px)',
|
||||
const probe = declarationsOf('.dockProbe')
|
||||
expect(probe['width']).toBe(
|
||||
'max(calc(var(--dsh-chat-aside-gutter, 0px) - var(--panel-clear) - var(--panel-edge) - var(--panel-min-width) + 1px),'
|
||||
+ ' calc((var(--dsh-chat-end-reserve-max, 0px) - var(--panel-clear) - var(--panel-edge) - var(--panel-min-width)) * 10000000 + 1px))',
|
||||
)
|
||||
expect(declarationsOf('.reserveProbe')['width']).toBe(
|
||||
'calc(var(--dsh-chat-end-reserve-max, 0px) - var(--panel-clear) - var(--panel-edge) - var(--panel-min-width) + 1px)',
|
||||
)
|
||||
expect(declarationsOf('.dockProbe, .reserveProbe')['max-width']).toBe('1px')
|
||||
expect(probe['max-width']).toBe('1px')
|
||||
})
|
||||
|
||||
it('makes the probe 1px wide exactly from the gutter that holds the panel at its minimum width', () => {
|
||||
// The declarations above, evaluated: a width below 0 is used as 0, and max-width caps the probe at 1px.
|
||||
const probeWidth = (gutter: number, inset = 0): number => Math.min(1, Math.max(0, gutter - inset * 9999 - clear - edge - minWidth + 1))
|
||||
const probeWidth = (gutter: number, reserveMax = 0): number =>
|
||||
Math.min(1, Math.max(0, gutter - clear - edge - minWidth + 1, (reserveMax - clear - edge - minWidth) * 10000000 + 1))
|
||||
const dockedWidth = (gutter: number): number => Math.min(360, Math.max(minWidth, gutter - clear - edge))
|
||||
expect([probeWidth(0), probeWidth(347), probeWidth(347.5), probeWidth(348), probeWidth(900)]).toEqual([0, 0, 0.5, 1, 1])
|
||||
// At the first gutter that docks, the panel is at its minimum width and keeps both clearances.
|
||||
@@ -64,42 +63,30 @@ describe('SessionPanel.module.css docking geometry', () => {
|
||||
expect([dockedWidth(377), dockedWidth(500)]).toEqual([329, 360])
|
||||
})
|
||||
|
||||
it('leaves a gutter the transcript made to the reserve probe, which is 1px wide exactly from the reserve that docks the panel', () => {
|
||||
const probeWidth = (gutter: number, inset: number): number =>
|
||||
Math.min(1, Math.max(0, gutter - inset * 9999 - clear - edge - minWidth + 1))
|
||||
// The body's end inset made this 348px gutter, so the gutter probe stays at 0, whatever the inset's size.
|
||||
expect([probeWidth(348, 285), probeWidth(348, 0.5)]).toEqual([0, 0])
|
||||
const reserveWidth = (reserveMax: number): number => Math.min(1, Math.max(0, reserveMax - clear - edge - minWidth + 1))
|
||||
expect([reserveWidth(0), reserveWidth(347), reserveWidth(347.5), reserveWidth(348), reserveWidth(900)]).toEqual([0, 0, 0.5, 1, 1])
|
||||
it('gives the probe room as well from the largest end reserve that covers the gutter, whatever the gutter is', () => {
|
||||
const probeWidth = (gutter: number, reserveMax: number): number =>
|
||||
Math.min(1, Math.max(0, gutter - clear - edge - minWidth + 1, (reserveMax - clear - edge - minWidth) * 10000000 + 1))
|
||||
// A 260px gutter holds no panel, and the transcript can leave 348px: room. This term is a step at 348px, as the
|
||||
// body's end inset is, so the probe has room exactly where the body makes it.
|
||||
expect([probeWidth(260, 347), probeWidth(260, 347.96), probeWidth(260, 348), probeWidth(260, 900)]).toEqual([0, 0, 1, 1])
|
||||
// The same answer once the transcript has made the 348px gutter, so making room does not change the decision.
|
||||
expect(probeWidth(348, 348)).toBe(1)
|
||||
// An embedded Chat View's body gives no reserve: only its gutter counts.
|
||||
expect([probeWidth(347, 0), probeWidth(348, 0)]).toEqual([0, 1])
|
||||
})
|
||||
|
||||
it('has a pinned panel ask the Conversation body for exactly the gutter that docks it', () => {
|
||||
it('asks the Conversation body for exactly the gutter that docks the panel while the probe carries the mark', () => {
|
||||
const request = declarationsOf(':global([data-conversation-content]):has(.dockProbe[data-session-panel-reserve])')
|
||||
expect(request).toEqual({ '--dsh-chat-end-reserve': 'calc(40px + 8px + 300px)' })
|
||||
expect(40 + 8 + 300).toBe(clear + edge + minWidth)
|
||||
})
|
||||
|
||||
it('keeps the probes out of sight, out of the layout flow, and away from the pointer', () => {
|
||||
expect(declarationsOf('.dockProbe, .reserveProbe')).toMatchObject({
|
||||
it('keeps the probe out of sight, out of the layout flow, and away from the pointer', () => {
|
||||
expect(declarationsOf('.dockProbe')).toMatchObject({
|
||||
'position': 'absolute', 'height': '0', 'visibility': 'hidden', 'pointer-events': 'none',
|
||||
})
|
||||
})
|
||||
|
||||
it('floats the pin at the panel end on the first title line, clear of the rows under it', () => {
|
||||
const pin = declarationsOf('.pin')
|
||||
expect(pin).toMatchObject({
|
||||
'float': 'inline-end', 'width': '24px', 'height': '24px', 'background': 'transparent', 'color': 'var(--dsw-alias-label-tertiary)',
|
||||
})
|
||||
// Above the positioned sections, which would otherwise cover a float and take its presses.
|
||||
expect(pin).toMatchObject({ 'position': 'relative', 'z-index': '1' })
|
||||
// 4px down to the first section's title row, 2px in so the glyph's center is 14px from the rows' end,
|
||||
// and a bottom margin that ends the float 4px above the title row's end.
|
||||
expect(pin['margin']).toBe('4px 2px -4px 0')
|
||||
expect(declarationsOf(".pin[aria-pressed='true']")).toEqual({ color: 'var(--dsw-alias-label-primary)' })
|
||||
// The pressed fill follows the hover fill, so a press on a hovered pin shows.
|
||||
expect(css.indexOf('.pin:active {')).toBeGreaterThan(css.indexOf('.pin:hover {'))
|
||||
})
|
||||
|
||||
it('floats the overlay narrower than the docked panel, at the same edge inset', () => {
|
||||
expect(declarationsOf(".panel[data-session-panel='overlay']")['width']).toBe('min(280px, calc(100% - 2 * var(--panel-edge)))')
|
||||
})
|
||||
@@ -115,6 +102,8 @@ describe('SessionPanel.module.css section reordering', () => {
|
||||
'position': 'absolute', 'top': '0', 'right': '2px', 'width': '24px', 'height': '24px',
|
||||
'color': 'var(--dsw-alias-label-tertiary)', 'opacity': '0',
|
||||
})
|
||||
// A mark over the row's end: presses reach the title row, and at rest the trailing content, through it.
|
||||
expect(declarationsOf('.grip')['pointer-events']).toBe('none')
|
||||
})
|
||||
|
||||
it('shows the handle in place of the trailing content on title-row hover and during a drag', () => {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// @vitest-environment jsdom
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
||||
import type { SessionPanelRoom } from '../src/client/slots.ts'
|
||||
import { DOCKS_STORAGE_KEY, PINNED_STORAGE_KEY, SessionPanelState, hasRoom, presentationOf } from '../src/client/visibility.ts'
|
||||
import { PINNED_STORAGE_KEY, SessionPanelState, presentationOf } from '../src/client/visibility.ts'
|
||||
|
||||
const A = 'session-a' as SessionId
|
||||
const B = 'session-b' as SessionId
|
||||
@@ -45,35 +44,19 @@ afterEach(() => {
|
||||
})
|
||||
|
||||
/**
|
||||
* One mounted panel's two probes under one id: a size report for each
|
||||
* element and their detachment, as the panel's refs drive them.
|
||||
* One mounted panel's dock probe: its id, a size report for its element, and
|
||||
* its detachment, as the panel's ref drives them.
|
||||
*/
|
||||
function probeOf(state: SessionPanelState, sessionId: SessionId, room: Partial<SessionPanelRoom> = {}) {
|
||||
function probeOf(state: SessionPanelState, sessionId: SessionId, width = 0) {
|
||||
nextProbe += 1
|
||||
const id = `probe-${nextProbe}`
|
||||
const attach = (member: keyof SessionPanelRoom) => {
|
||||
const element = document.createElement('span')
|
||||
const ref = state.createProbeRef(sessionId, id, member)
|
||||
ref(element)
|
||||
const observation = observations.get(element)
|
||||
if (observation === undefined) throw new Error('the probe element is not observed')
|
||||
if (room[member] === true) observation.report(1)
|
||||
return { observation, resize: observation.report, detach: () => { ref(null) } }
|
||||
}
|
||||
const gutter = attach('gutter')
|
||||
const reserve = attach('reserve')
|
||||
return {
|
||||
id,
|
||||
gutter,
|
||||
reserve,
|
||||
/** Report the gutter probe's width. */
|
||||
resize: gutter.resize,
|
||||
/** Detach both probes, as the panel's unmount does. */
|
||||
detach: () => {
|
||||
gutter.detach()
|
||||
reserve.detach()
|
||||
},
|
||||
}
|
||||
const element = document.createElement('span')
|
||||
const ref = state.createProbeRef(sessionId, id)
|
||||
ref(element)
|
||||
const observation = observations.get(element)
|
||||
if (observation === undefined) throw new Error('the probe element is not observed')
|
||||
if (width > 0) observation.report(width)
|
||||
return { id, element, observation, resize: observation.report, detach: () => { ref(null) } }
|
||||
}
|
||||
|
||||
/** A state whose Chat Views show `A` and `B` without room to dock. */
|
||||
@@ -82,104 +65,64 @@ function newState() {
|
||||
return { state, a: probeOf(state, A), b: probeOf(state, B) }
|
||||
}
|
||||
|
||||
const NONE: SessionPanelRoom = { gutter: false, reserve: false }
|
||||
const GUTTER: SessionPanelRoom = { gutter: true, reserve: false }
|
||||
const RESERVE: SessionPanelRoom = { gutter: false, reserve: true }
|
||||
const BOTH: SessionPanelRoom = { gutter: true, reserve: true }
|
||||
|
||||
describe('hasRoom', () => {
|
||||
it.each([
|
||||
[undefined, false, false],
|
||||
[undefined, true, false],
|
||||
[NONE, true, false],
|
||||
[GUTTER, false, true],
|
||||
[RESERVE, false, false],
|
||||
[RESERVE, true, true],
|
||||
[BOTH, false, true],
|
||||
] as const)('room=%j pinned=%s is %s', (room, pinned, expected) => {
|
||||
expect(hasRoom(room, { docks: true, pinned, overlay: null })).toBe(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe('presentationOf', () => {
|
||||
it.each([
|
||||
[GUTTER, true, false, null, 'docked'],
|
||||
[GUTTER, true, false, A, 'docked'],
|
||||
[GUTTER, false, false, null, 'hidden'],
|
||||
[GUTTER, false, false, A, 'hidden'],
|
||||
[NONE, true, false, null, 'hidden'],
|
||||
[NONE, false, false, null, 'hidden'],
|
||||
[NONE, true, false, A, 'overlay'],
|
||||
[NONE, false, false, A, 'overlay'],
|
||||
[NONE, true, false, B, 'hidden'],
|
||||
[undefined, true, true, A, 'overlay'],
|
||||
// The transcript can make room: that docks a pinned panel and leaves an unpinned one to the overlay.
|
||||
[RESERVE, true, true, null, 'docked'],
|
||||
[RESERVE, false, true, A, 'hidden'],
|
||||
[RESERVE, true, false, null, 'hidden'],
|
||||
[RESERVE, true, false, A, 'overlay'],
|
||||
[NONE, true, true, A, 'overlay'],
|
||||
] as const)('room=%j docks=%s pinned=%s overlay=%s shows %s', (room, docks, pinned, overlay, expected) => {
|
||||
expect(presentationOf(room, { docks, pinned, overlay }, A)).toBe(expected)
|
||||
[true, true, null, 'docked'],
|
||||
[true, true, A, 'docked'],
|
||||
[true, false, null, 'hidden'],
|
||||
[true, false, A, 'hidden'],
|
||||
[false, true, null, 'hidden'],
|
||||
[false, false, null, 'hidden'],
|
||||
[false, true, A, 'overlay'],
|
||||
[false, false, A, 'overlay'],
|
||||
[false, true, B, 'hidden'],
|
||||
] as const)('fits=%s pinned=%s overlay=%s shows %s', (fits, pinned, overlay, expected) => {
|
||||
expect(presentationOf(fits, { pinned, overlay }, A)).toBe(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe('SessionPanelState room probes', () => {
|
||||
it('enters attached probes without room and gives each its room from 1px of width', () => {
|
||||
describe('SessionPanelState dock probes', () => {
|
||||
it('enters an attached probe without room and gives it room from 1px of width', () => {
|
||||
const state = new SessionPanelState()
|
||||
expect(state.probes.getSnapshot().size).toBe(0)
|
||||
const probe = probeOf(state, A)
|
||||
expect(state.probes.getSnapshot().get(probe.id)).toEqual(NONE)
|
||||
expect(state.dockable.getSnapshot().get(A)).toEqual(NONE)
|
||||
expect(state.probes.getSnapshot().get(probe.id)).toBe(false)
|
||||
expect(state.dockable.getSnapshot().get(A)).toBe(false)
|
||||
// Within a pixel below the gutter that docks the panel the probe is narrower than 1px.
|
||||
probe.resize(0.5)
|
||||
expect(state.probes.getSnapshot().get(probe.id)).toEqual(NONE)
|
||||
expect(state.probes.getSnapshot().get(probe.id)).toBe(false)
|
||||
probe.resize(1)
|
||||
expect(state.probes.getSnapshot().get(probe.id)).toEqual(GUTTER)
|
||||
expect(state.dockable.getSnapshot().get(A)).toEqual(GUTTER)
|
||||
probe.reserve.resize(1)
|
||||
expect(state.probes.getSnapshot().get(probe.id)).toEqual(BOTH)
|
||||
expect(state.probes.getSnapshot().get(probe.id)).toBe(true)
|
||||
expect(state.dockable.getSnapshot().get(A)).toBe(true)
|
||||
probe.resize(0)
|
||||
expect(state.probes.getSnapshot().get(probe.id)).toEqual(RESERVE)
|
||||
expect(state.dockable.getSnapshot().get(A)).toEqual(RESERVE)
|
||||
expect(state.probes.getSnapshot().get(probe.id)).toBe(false)
|
||||
expect(state.dockable.getSnapshot().get(A)).toBe(false)
|
||||
})
|
||||
|
||||
it('gives a Session each room while any of its panels has it, and drops the Session once its last probe detaches', () => {
|
||||
it('gives a Session room while any of its probes has it, and drops the Session once its last probe detaches', () => {
|
||||
const state = new SessionPanelState()
|
||||
const main = probeOf(state, A, { gutter: true })
|
||||
const embedded = probeOf(state, A, { reserve: true })
|
||||
const other = probeOf(state, B)
|
||||
expect(state.probes.getSnapshot()).toEqual(new Map([[main.id, GUTTER], [embedded.id, RESERVE], [other.id, NONE]]))
|
||||
expect(state.dockable.getSnapshot()).toEqual(new Map([[A, BOTH], [B, NONE]]))
|
||||
const main = probeOf(state, A, 1)
|
||||
const embedded = probeOf(state, A)
|
||||
expect(state.probes.getSnapshot()).toEqual(new Map([[main.id, true], [embedded.id, false]]))
|
||||
expect(state.dockable.getSnapshot().get(A)).toBe(true)
|
||||
main.detach()
|
||||
expect(main.gutter.observation.disconnected).toBe(true)
|
||||
expect(state.probes.getSnapshot()).toEqual(new Map([[embedded.id, RESERVE], [other.id, NONE]]))
|
||||
expect(state.dockable.getSnapshot().get(A)).toEqual(RESERVE)
|
||||
expect(main.observation.disconnected).toBe(true)
|
||||
expect(state.probes.getSnapshot()).toEqual(new Map([[embedded.id, false]]))
|
||||
expect(state.dockable.getSnapshot().get(A)).toBe(false)
|
||||
embedded.resize(1)
|
||||
expect(state.dockable.getSnapshot().get(A)).toEqual(BOTH)
|
||||
expect(state.dockable.getSnapshot().get(A)).toBe(true)
|
||||
embedded.detach()
|
||||
expect(state.dockable.getSnapshot().has(A)).toBe(false)
|
||||
expect(state.probes.getSnapshot().size).toBe(1)
|
||||
// A second detachment of the same elements withdraws nothing more.
|
||||
expect(state.probes.getSnapshot().size).toBe(0)
|
||||
// A second detachment of the same element withdraws nothing more.
|
||||
const before = state.dockable.getSnapshot()
|
||||
embedded.detach()
|
||||
expect(state.dockable.getSnapshot()).toBe(before)
|
||||
})
|
||||
|
||||
it('keeps a panel entered while one of its probes stays attached, with no room from the withdrawn one', () => {
|
||||
const state = new SessionPanelState()
|
||||
const probe = probeOf(state, A, { gutter: true, reserve: true })
|
||||
probe.gutter.detach()
|
||||
expect(state.probes.getSnapshot().get(probe.id)).toEqual(RESERVE)
|
||||
expect(state.dockable.getSnapshot().get(A)).toEqual(RESERVE)
|
||||
probe.reserve.detach()
|
||||
expect(state.probes.getSnapshot().has(probe.id)).toBe(false)
|
||||
expect(state.dockable.getSnapshot().has(A)).toBe(false)
|
||||
})
|
||||
|
||||
it('publishes only when a probe flips or a Session changes its room', () => {
|
||||
const state = new SessionPanelState()
|
||||
const main = probeOf(state, A, { gutter: true })
|
||||
const main = probeOf(state, A, 1)
|
||||
const probes = state.probes.getSnapshot()
|
||||
const dockable = state.dockable.getSnapshot()
|
||||
let probeCalls = 0
|
||||
@@ -187,7 +130,6 @@ describe('SessionPanelState room probes', () => {
|
||||
const offProbes = state.probes.subscribe(() => { probeCalls += 1 })
|
||||
const offSessions = state.dockable.subscribe(() => { sessionCalls += 1 })
|
||||
main.resize(1)
|
||||
main.reserve.resize(0)
|
||||
expect(state.probes.getSnapshot()).toBe(probes)
|
||||
expect(state.dockable.getSnapshot()).toBe(dockable)
|
||||
// A second Chat View without room changes the probes, not the Session's room.
|
||||
@@ -204,10 +146,10 @@ describe('SessionPanelState room probes', () => {
|
||||
it('keeps a probe without room where ResizeObserver is missing', () => {
|
||||
vi.stubGlobal('ResizeObserver', undefined)
|
||||
const state = new SessionPanelState()
|
||||
const ref = state.createProbeRef(A, 'unobserved', 'gutter')
|
||||
const ref = state.createProbeRef(A, 'unobserved')
|
||||
ref(document.createElement('span'))
|
||||
expect(state.probes.getSnapshot().get('unobserved')).toEqual(NONE)
|
||||
expect(state.dockable.getSnapshot().get(A)).toEqual(NONE)
|
||||
expect(state.probes.getSnapshot().get('unobserved')).toBe(false)
|
||||
expect(state.dockable.getSnapshot().get(A)).toBe(false)
|
||||
ref(null)
|
||||
expect(state.dockable.getSnapshot().has(A)).toBe(false)
|
||||
})
|
||||
@@ -215,7 +157,7 @@ describe('SessionPanelState room probes', () => {
|
||||
it('stops observing every attached probe on dispose, after which a detachment withdraws nothing', () => {
|
||||
const { state, a, b } = newState()
|
||||
state.dispose()
|
||||
expect([a.gutter, a.reserve, b.gutter, b.reserve].map(probe => probe.observation.disconnected)).toEqual([true, true, true, true])
|
||||
expect([a.observation.disconnected, b.observation.disconnected]).toEqual([true, true])
|
||||
expect(state.probes.getSnapshot().size).toBe(0)
|
||||
expect(state.dockable.getSnapshot().size).toBe(0)
|
||||
const before = state.probes.getSnapshot()
|
||||
@@ -225,10 +167,10 @@ describe('SessionPanelState room probes', () => {
|
||||
})
|
||||
|
||||
describe('SessionPanelState visibility', () => {
|
||||
it('docks unpinned by default and keeps the snapshot identity until a member changes', () => {
|
||||
it('docks by default and keeps the snapshot identity until a member changes', () => {
|
||||
const { state } = newState()
|
||||
const first = state.visibility.getSnapshot()
|
||||
expect(first).toEqual({ docks: true, pinned: false, overlay: null })
|
||||
expect(first).toEqual({ pinned: true, overlay: null })
|
||||
expect(state.visibility.getSnapshot()).toBe(first)
|
||||
})
|
||||
|
||||
@@ -239,18 +181,18 @@ describe('SessionPanelState visibility', () => {
|
||||
a.resize(1)
|
||||
expect(state.visibility.getSnapshot().overlay).toBeNull()
|
||||
state.toggle(A)
|
||||
expect(state.visibility.getSnapshot()).toEqual({ docks: false, pinned: false, overlay: null })
|
||||
expect(localStorage.getItem(DOCKS_STORAGE_KEY)).toBe('false')
|
||||
expect(new SessionPanelState().visibility.getSnapshot().docks).toBe(false)
|
||||
expect(state.visibility.getSnapshot()).toEqual({ pinned: false, overlay: null })
|
||||
expect(localStorage.getItem(PINNED_STORAGE_KEY)).toBe('false')
|
||||
expect(new SessionPanelState().visibility.getSnapshot().pinned).toBe(false)
|
||||
state.toggle(A)
|
||||
expect(state.visibility.getSnapshot().docks).toBe(true)
|
||||
expect(state.visibility.getSnapshot().pinned).toBe(true)
|
||||
})
|
||||
|
||||
it('opens and closes one Session overlay without touching the docking preference', () => {
|
||||
const { state } = newState()
|
||||
state.toggle(A)
|
||||
state.toggle(B)
|
||||
expect(state.visibility.getSnapshot()).toEqual({ docks: true, pinned: false, overlay: B })
|
||||
expect(state.visibility.getSnapshot()).toEqual({ pinned: true, overlay: B })
|
||||
state.closeOverlay(A)
|
||||
expect(state.visibility.getSnapshot().overlay).toBe(B)
|
||||
state.toggle(B)
|
||||
@@ -267,25 +209,22 @@ describe('SessionPanelState visibility', () => {
|
||||
expect(state.visibility.getSnapshot()).toBe(before)
|
||||
})
|
||||
|
||||
it('treats a stored docking value other than false, and a stored pin other than true, as the default', () => {
|
||||
localStorage.setItem(DOCKS_STORAGE_KEY, '"yes"')
|
||||
it('treats a stored value other than false as the default', () => {
|
||||
localStorage.setItem(PINNED_STORAGE_KEY, '"yes"')
|
||||
expect(newState().state.visibility.getSnapshot()).toEqual({ docks: true, pinned: false, overlay: null })
|
||||
expect(newState().state.visibility.getSnapshot().pinned).toBe(true)
|
||||
})
|
||||
|
||||
it('notifies subscribers of every member and stops after unsubscribe', () => {
|
||||
it('notifies subscribers of both members and stops after unsubscribe', () => {
|
||||
const { state, a } = newState()
|
||||
let calls = 0
|
||||
const off = state.visibility.subscribe(() => { calls += 1 })
|
||||
state.toggle(A)
|
||||
a.resize(1)
|
||||
state.toggle(A)
|
||||
state.setPinned(A, true)
|
||||
const seen = calls
|
||||
expect(seen).toBeGreaterThanOrEqual(4)
|
||||
expect(seen).toBeGreaterThanOrEqual(2)
|
||||
off()
|
||||
state.toggle(A)
|
||||
state.setPinned(A, false)
|
||||
expect(calls).toBe(seen)
|
||||
})
|
||||
|
||||
@@ -295,9 +234,9 @@ describe('SessionPanelState visibility', () => {
|
||||
a.resize(0.5)
|
||||
expect(state.visibility.getSnapshot().overlay).toBe(A)
|
||||
a.resize(1)
|
||||
expect(state.visibility.getSnapshot()).toEqual({ docks: true, pinned: false, overlay: null })
|
||||
expect(state.visibility.getSnapshot()).toEqual({ pinned: true, overlay: null })
|
||||
a.resize(0)
|
||||
expect(presentationOf(state.dockable.getSnapshot().get(A), state.visibility.getSnapshot(), A)).toBe('hidden')
|
||||
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', () => {
|
||||
@@ -306,7 +245,7 @@ describe('SessionPanelState visibility', () => {
|
||||
a.detach()
|
||||
expect(state.visibility.getSnapshot().overlay).toBeNull()
|
||||
probeOf(state, A)
|
||||
expect(presentationOf(state.dockable.getSnapshot().get(A), state.visibility.getSnapshot(), A)).toBe('hidden')
|
||||
expect(presentationOf(false, state.visibility.getSnapshot(), A)).toBe('hidden')
|
||||
})
|
||||
|
||||
it('follows only the open overlay, and nothing after dispose', () => {
|
||||
@@ -322,94 +261,3 @@ describe('SessionPanelState visibility', () => {
|
||||
expect(state.visibility.getSnapshot().overlay).toBe(B)
|
||||
})
|
||||
})
|
||||
|
||||
describe('SessionPanelState pin', () => {
|
||||
const shown = (state: SessionPanelState, sessionId: SessionId) =>
|
||||
presentationOf(state.dockable.getSnapshot().get(sessionId), state.visibility.getSnapshot(), sessionId)
|
||||
|
||||
it('docks an overlay whose transcript can make room, and persists the pin', () => {
|
||||
const { state, a } = newState()
|
||||
a.reserve.resize(1)
|
||||
// Unpinned, the room the transcript could make docks nothing.
|
||||
state.toggle(A)
|
||||
expect(shown(state, A)).toBe('overlay')
|
||||
state.setPinned(A, true)
|
||||
expect(state.visibility.getSnapshot()).toEqual({ docks: true, pinned: true, overlay: null })
|
||||
expect(shown(state, A)).toBe('docked')
|
||||
expect(localStorage.getItem(PINNED_STORAGE_KEY)).toBe('true')
|
||||
expect(new SessionPanelState().visibility.getSnapshot().pinned).toBe(true)
|
||||
})
|
||||
|
||||
it('sets the docking preference with the pin, so a hidden panel shows again', () => {
|
||||
const { state, a } = newState()
|
||||
a.resize(1)
|
||||
state.toggle(A)
|
||||
expect(shown(state, A)).toBe('hidden')
|
||||
state.setPinned(A, true)
|
||||
expect(state.visibility.getSnapshot()).toEqual({ docks: true, pinned: true, overlay: null })
|
||||
expect(shown(state, A)).toBe('docked')
|
||||
})
|
||||
|
||||
it('hides and shows a pinned panel from the toggle without unpinning it', () => {
|
||||
const { state, a } = newState()
|
||||
a.reserve.resize(1)
|
||||
state.setPinned(A, true)
|
||||
state.toggle(A)
|
||||
expect(state.visibility.getSnapshot()).toEqual({ docks: false, pinned: true, overlay: null })
|
||||
expect(shown(state, A)).toBe('hidden')
|
||||
state.toggle(A)
|
||||
expect(shown(state, A)).toBe('docked')
|
||||
})
|
||||
|
||||
it('leaves a pinned panel to the overlay where the transcript cannot make room, and docks it again once it can', () => {
|
||||
const { state, a } = newState()
|
||||
state.setPinned(A, true)
|
||||
expect(shown(state, A)).toBe('hidden')
|
||||
state.toggle(A)
|
||||
expect(shown(state, A)).toBe('overlay')
|
||||
a.reserve.resize(1)
|
||||
expect(state.visibility.getSnapshot().overlay).toBeNull()
|
||||
expect(shown(state, A)).toBe('docked')
|
||||
a.reserve.resize(0)
|
||||
expect(shown(state, A)).toBe('hidden')
|
||||
})
|
||||
|
||||
it('keeps a panel that only the pin held beside the transcript open as the overlay when unpinned', () => {
|
||||
const { state, a } = newState()
|
||||
a.reserve.resize(1)
|
||||
state.setPinned(A, true)
|
||||
state.setPinned(A, false)
|
||||
expect(state.visibility.getSnapshot()).toEqual({ docks: true, pinned: false, overlay: A })
|
||||
expect(shown(state, A)).toBe('overlay')
|
||||
expect(localStorage.getItem(PINNED_STORAGE_KEY)).toBe('false')
|
||||
// The overlay follows its Session as any other: it closes once the gutter docks the panel.
|
||||
a.resize(1)
|
||||
expect(state.visibility.getSnapshot().overlay).toBeNull()
|
||||
})
|
||||
|
||||
it('opens no overlay when unpinning a panel its gutter holds, a hidden one, an overlay, or one no Chat View shows', () => {
|
||||
const { state, a } = newState()
|
||||
a.reserve.resize(1)
|
||||
a.resize(1)
|
||||
state.setPinned(A, true)
|
||||
state.setPinned(A, false)
|
||||
expect(state.visibility.getSnapshot()).toEqual({ docks: true, pinned: false, overlay: null })
|
||||
// Hidden from the toggle while pinned.
|
||||
a.resize(0)
|
||||
state.setPinned(A, true)
|
||||
state.toggle(A)
|
||||
state.setPinned(A, false)
|
||||
expect(state.visibility.getSnapshot()).toEqual({ docks: false, pinned: false, overlay: null })
|
||||
// Pinned where the transcript cannot make room: the open overlay stays the overlay.
|
||||
a.reserve.resize(0)
|
||||
state.setPinned(A, true)
|
||||
state.toggle(A)
|
||||
state.setPinned(A, false)
|
||||
expect(state.visibility.getSnapshot()).toEqual({ docks: true, pinned: false, overlay: A })
|
||||
state.closeOverlay(A)
|
||||
a.detach()
|
||||
state.setPinned(A, true)
|
||||
state.setPinned(A, false)
|
||||
expect(state.visibility.getSnapshot()).toEqual({ docks: true, pinned: false, overlay: null })
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user