From 48c65b38675cd19cd74c2c970858c6b9bad3650b Mon Sep 17 00:00:00 2001 From: LegGasai Date: Thu, 12 Nov 2026 15:12:15 +0800 Subject: [PATCH 1/6] feat(client): add panel row trailing content, embedded hero options, and a shared title marquee Let a navigation row show trailing content such as a count, let an embedded conversation keep the blank Session of a Workspace its hero picks and name its own headline, and move the Session row title marquee into ui-primitives so other lists can use it. Refs #8312 --- .../client/ui-conversation/README.i18n.yaml | 4 +- packages/client/ui-conversation/README.md | 2 +- packages/client/ui-conversation/README.zh.md | 2 +- .../ui-conversation/src/client/apply.ts | 55 +++--- .../src/client/contract/slots.ts | 15 +- .../client/skeleton/ConversationContent.tsx | 4 +- .../src/client/skeleton/EmptyHero.tsx | 8 +- .../tests/apply-inject.client.spec.tsx | 19 +++ .../tests/skeleton.client.spec.tsx | 11 +- .../client/ui-primitives/README.i18n.yaml | 4 +- packages/client/ui-primitives/README.md | 1 + packages/client/ui-primitives/README.zh.md | 1 + .../ui-primitives/src/TitleMarquee.module.css | 17 ++ packages/client/ui-primitives/src/index.ts | 1 + .../client/ui-primitives/src/title-marquee.ts | 105 ++++++++++++ .../tests/title-marquee-styles.client.spec.ts | 28 ++++ .../tests/title-marquee.client.spec.tsx | 157 ++++++++++++++++++ packages/client/ui-sidebar/README.i18n.yaml | 8 +- packages/client/ui-sidebar/README.md | 4 +- packages/client/ui-sidebar/README.zh.md | 4 +- .../ui-sidebar/src/client/PanelIcon.tsx | 9 + .../src/client/SidebarRoot.module.css | 37 +++++ .../ui-sidebar/src/client/SidebarRoot.tsx | 5 +- .../ui-sidebar/src/client/contract/slots.ts | 21 +++ .../client/ui-sidebar/src/client/index.ts | 6 +- .../tests/panel-list.client.spec.tsx | 58 +++++++ .../src/client/rows/Rows.module.css | 18 -- .../ui-workspace/src/client/rows/Rows.tsx | 98 +---------- .../tests/browser-styles.client.spec.ts | 14 +- .../ui-workspace/tests/rows.client.spec.tsx | 4 +- .../src/client/slot-catalog.ts | 67 +++++++- 31 files changed, 609 insertions(+), 178 deletions(-) create mode 100644 packages/client/ui-primitives/src/TitleMarquee.module.css create mode 100644 packages/client/ui-primitives/src/title-marquee.ts create mode 100644 packages/client/ui-primitives/tests/title-marquee-styles.client.spec.ts create mode 100644 packages/client/ui-primitives/tests/title-marquee.client.spec.tsx diff --git a/packages/client/ui-conversation/README.i18n.yaml b/packages/client/ui-conversation/README.i18n.yaml index c1b711fdd5..57cd971975 100644 --- a/packages/client/ui-conversation/README.i18n.yaml +++ b/packages/client/ui-conversation/README.i18n.yaml @@ -21,8 +21,8 @@ en: 4a094cd97426ad18 zh: 5faadddb7e2b0a43 /deepseek-ai-dsh-client-ui-conversation/shell-and-standard-props: - en: 25dd776b1c1562f1 - zh: 1efe8e6e56e73153 + en: c0dd18a35ea8d9cd + zh: bc1ef35395f26b80 /deepseek-ai-dsh-client-ui-conversation/temporary-composer-entries: en: 59cd63057dfb6eeb zh: b2e2c86e810b7bb8 diff --git a/packages/client/ui-conversation/README.md b/packages/client/ui-conversation/README.md index 104a182d11..4a5ff288ec 100644 --- a/packages/client/ui-conversation/README.md +++ b/packages/client/ui-conversation/README.md @@ -106,7 +106,7 @@ A claimed command is one atomic chip at the start of the draft, and the claim la Workspace selection uses `uiWorkspace.openWorkspace` to prepare the target and commit navigation. Draft content, including structured references, and attachments move in its synchronous preparation callback only while that request is current and no submission is in flight; later navigation, owner disposal, or a submission in flight leaves the original draft in its Session. -The package occupies the root-scoped `main` key `conversation`. Its `main.conversation` shell keeps the resident `conversation.header` outside the optional-Session `conversation.content` Component Factory. The header hosts root-scoped navigation without a selected Session; titles, actions, and View tabs remain in its strict Session child. The Factory owns the shared body and Composer, reads the current Session through its standard Hook, and exposes strict-Session `views` plus root-scoped `widthControls` local positions. Its default adapter renders the existing `conversation.session` entry, while the main occurrence selects the width handles; an embedded occurrence can replace `views` and omit those handles without rendering the main Header. The shared body and Composer register the queue and Todo docks. The Todo dock uses the shared panel elevation above the composer; its rows use the shared idle, ongoing, and done markers for pending, in-progress, and completed items. `ctx.uiSession.provide()` materializes the Conversation and input sources from the same Session binding and supplies `inputActions` as a stable standard prop. +The package occupies the root-scoped `main` key `conversation`. Its `main.conversation` shell keeps the resident `conversation.header` outside the optional-Session `conversation.content` Component Factory. The header hosts root-scoped navigation without a selected Session; titles, actions, and View tabs remain in its strict Session child. The Factory owns the shared body and Composer, reads the current Session through its standard Hook, and exposes strict-Session `views` plus root-scoped `widthControls` local positions. Its default adapter renders the existing `conversation.session` entry, while the main occurrence selects the width handles; an embedded occurrence can replace `views` and omit those handles without rendering the main Header. An embedded occurrence may also pass `onWorkspaceSession`, which receives the blank Session of a Workspace the Hero's picker chose, retains it, and shows it, while the draft moves to it without that blank opening as the main Session, and `headline`, which replaces the Hero headline and preview badge. The shared body and Composer register the queue and Todo docks. The Todo dock uses the shared panel elevation above the composer; its rows use the shared idle, ongoing, and done markers for pending, in-progress, and completed items. `ctx.uiSession.provide()` materializes the Conversation and input sources from the same Session binding and supplies `inputActions` as a stable standard prop. A blank Session retains the header's leading and corner controls, including the right-sidebar opener, while hiding its title, actions, utilities, and View tabs. Selecting a Workspace creates the Session needed by these controls; the first message is not required. Without a selected Session, the strict header is absent; the resident header keeps the blank-Session 40px row on every platform, so the Hero input card sits at the same height before and after a Workspace is bound; on macOS desktop that row is also the window drag row. Sidebar entries retain their own data and execution prerequisites. A started Session header uses one row when fewer than two Views are available; the tab row reserves space only while rendered. When the title and actions do not fit, the title area clips them and fades its trailing edge before the utilities, which stay fully visible and clickable; overlays in the title and actions slots portal to stay outside that clip. diff --git a/packages/client/ui-conversation/README.zh.md b/packages/client/ui-conversation/README.zh.md index fb1ecf3770..d4870c62f7 100644 --- a/packages/client/ui-conversation/README.zh.md +++ b/packages/client/ui-conversation/README.zh.md @@ -106,7 +106,7 @@ root 作用域的 `conversation.session.header.views.actions` list 有注册项 工作区选择使用 `uiWorkspace.openWorkspace` 准备目标并提交导航。草稿内容(包括结构化引用)和附件仅在该请求仍为当前请求、且没有在途提交时,通过它的同步准备回调搬移;后续导航、所有者释放或在途提交都会把原草稿留在它的 Session 中。 -本包占据 root 作用域 `main` 中的 `conversation` key。其 `main.conversation` 外壳将常驻的 `conversation.header` 放在可选 Session 的 `conversation.content` Component Factory 外。未选中 Session 时,头部仍承载根作用域导航;标题、操作和 View 标签保留在严格 Session 子组件中。Factory 拥有共享正文与 Composer,通过其标准 Hook 读取当前 Session,并公开 strict-Session `views` 与 root-scoped `widthControls` 两个局部位置。默认 adapter 渲染现有 `conversation.session` entry,主 occurrence 选择宽度拖拽条;嵌入式 occurrence 可以替换 `views`、省略拖拽条,且不渲染主 Header。共享正文与 Composer 注册 queue dock 和 Todo dock。Todo dock 在 composer 上方使用共享面板 elevation;其中的行分别以共享 idle、ongoing 与 done 标记表示待处理、进行中与已完成。`ctx.uiSession.provide()` 从同一个 Session binding 物化 Conversation 与 input source,并将 `inputActions` 作为稳定标准 prop 提供。 +本包占据 root 作用域 `main` 中的 `conversation` key。其 `main.conversation` 外壳将常驻的 `conversation.header` 放在可选 Session 的 `conversation.content` Component Factory 外。未选中 Session 时,头部仍承载根作用域导航;标题、操作和 View 标签保留在严格 Session 子组件中。Factory 拥有共享正文与 Composer,通过其标准 Hook 读取当前 Session,并公开 strict-Session `views` 与 root-scoped `widthControls` 两个局部位置。默认 adapter 渲染现有 `conversation.session` entry,主 occurrence 选择宽度拖拽条;嵌入式 occurrence 可以替换 `views`、省略拖拽条,且不渲染主 Header。嵌入式 occurrence 还可以传入 `onWorkspaceSession` 与 `headline`:前者接收 Hero 选择器所选工作区的空白 Session,由它保留并显示该 Session,草稿随之移过去,而该空白 Session 不作为主 Session 打开;后者替换 Hero 的标题与预览徽标。共享正文与 Composer 注册 queue dock 和 Todo dock。Todo dock 在 composer 上方使用共享面板 elevation;其中的行分别以共享 idle、ongoing 与 done 标记表示待处理、进行中与已完成。`ctx.uiSession.provide()` 从同一个 Session binding 物化 Conversation 与 input source,并将 `inputActions` 作为稳定标准 prop 提供。 blank Session 保留 header 的 leading 与 corner 控件,包括右侧栏展开入口,同时隐藏标题、actions、utilities 和 View tabs。选择 Workspace 会创建这些控件所需的 Session,无需先发送消息。没有选中 Session 时,strict header 不挂载;常驻 header 在所有平台都保留与 blank Session 相同的 40px 行,因此绑定 Workspace 前后 Hero 输入卡片的高度位置不变;在 macOS 桌面上,这一行同时是窗口拖拽行。侧栏各入口仍遵循自身的数据与执行环境要求。 已开始的 Session 在可用 View 少于两个时使用单行标题栏,仅在渲染标签行时保留其高度。标题与 actions 放不下时,标题区域会裁剪它们,并在 utilities 之前渐隐其末端;utilities 始终完整可见且可点击;标题与 actions slot 中的浮层通过 portal 渲染,不受该裁剪影响。 diff --git a/packages/client/ui-conversation/src/client/apply.ts b/packages/client/ui-conversation/src/client/apply.ts index 4f292f0ece..623748c44e 100644 --- a/packages/client/ui-conversation/src/client/apply.ts +++ b/packages/client/ui-conversation/src/client/apply.ts @@ -124,6 +124,7 @@ interface WorkspaceNavigation { workspaceId: Parameters[0], beforeOpen: (sessionId: SessionId) => void, ): Promise + connectWorkspace(workspaceId: Parameters[0]): Promise } /** Action registration used by the composer without importing its command-UI consumer. */ @@ -368,32 +369,40 @@ export function apply(ctx: Context, config: Config = Config({})): void { hooks: { composerBlock: sessionId === undefined ? ABSENT_BLOCK : composerBlocks.storeFor(sessionId), }, - selectWorkspace: workspaceId => workspaceNavigation.openWorkspace(workspaceId, (nextId) => { - if (sessionId !== undefined && nextId !== sessionId) { - const from = inputHub.shell(sessionId) - // A draft with a submission in flight stays with the Session that is admitting it. - if (from.snapshot.phase !== 'plain' && from.snapshot.phase !== 'claimed') return - const draft = from.draftSnapshot - const attachmentIds = from.snapshot.attachmentIds - const next = inputHub.shell(nextId) - if (attachmentIds.length === 0 || next.addAttachments(attachmentIds)) { - const binding = sessions.binding(nextId) - if (binding === undefined) { - throw new Error(`ui-conversation: session "${nextId}" resolved no binding`) - } - // The same rule as intake: only an ordinary Session stages image uploads. - const ordinary = binding.session.getSnapshot().subagent === null - concreteConversation(ctx).rebindDraftFiles(nextId, attachmentIds, ordinary) - if (draft.text !== '') { - next.setDraft(draft) - from.setDraft('') - } - if (attachmentIds.length > 0) { - for (const id of attachmentIds) from.removeAttachment(id) + selectWorkspace: (workspaceId, report) => { + const moveDraft = (nextId: SessionId): void => { + if (sessionId !== undefined && nextId !== sessionId) { + const from = inputHub.shell(sessionId) + // A draft with a submission in flight stays with the Session that is admitting it. + if (from.snapshot.phase !== 'plain' && from.snapshot.phase !== 'claimed') return + const draft = from.draftSnapshot + const attachmentIds = from.snapshot.attachmentIds + const next = inputHub.shell(nextId) + if (attachmentIds.length === 0 || next.addAttachments(attachmentIds)) { + const binding = sessions.binding(nextId) + if (binding === undefined) { + throw new Error(`ui-conversation: session "${nextId}" resolved no binding`) + } + // The same rule as intake: only an ordinary Session stages image uploads. + const ordinary = binding.session.getSnapshot().subagent === null + concreteConversation(ctx).rebindDraftFiles(nextId, attachmentIds, ordinary) + if (draft.text !== '') { + next.setDraft(draft) + from.setDraft('') + } + if (attachmentIds.length > 0) { + for (const id of attachmentIds) from.removeAttachment(id) + } } } } - }), + if (report === undefined) return workspaceNavigation.openWorkspace(workspaceId, moveDraft) + // The receiver retains the Session before it returns, which the draft move needs. + return workspaceNavigation.connectWorkspace(workspaceId).then((nextId) => { + report(nextId) + moveDraft(nextId) + }) + }, }), }, ConversationContent) diff --git a/packages/client/ui-conversation/src/client/contract/slots.ts b/packages/client/ui-conversation/src/client/contract/slots.ts index f8bbf67c5b..27de549aa0 100644 --- a/packages/client/ui-conversation/src/client/contract/slots.ts +++ b/packages/client/ui-conversation/src/client/contract/slots.ts @@ -468,8 +468,11 @@ export type ConvViewProps = PropsRuntime<'conversation.view'> /** Business callbacks injected into the resident Conversation shell. */ export interface ConversationInjected { - /** Connect and open a blank Session in the selected Workspace. */ - selectWorkspace: (workspaceId: WorkspaceId) => Promise + /** + * Connect a blank Session in the selected Workspace and move the draft to it; it opens as the main Session unless + * `report` receives it, which retains it before the draft moves. + */ + selectWorkspace: (workspaceId: WorkspaceId, report?: (sessionId: SessionId) => void) => Promise /** Session-addressed composer block source, or the stable absent source. */ hooks: { composerBlock: ObservableSnapshot } } @@ -683,6 +686,14 @@ export interface ConversationContentInputProps { variant: 'main' | 'embedded' phase: 'settling' | 'hero' | 'active' hero: boolean + /** + * Receives the blank Session of a Workspace the Hero's picker chose instead of that blank opening as the main + * Session; an embedded occurrence that sets it shows the reported Session itself. It must retain the Session before + * it returns: the draft then moves to it. + */ + onWorkspaceSession?: ((sessionId: SessionId) => void) | undefined + /** Text the blank-session Hero shows instead of its default headline and preview badge. */ + headline?: string | undefined } /** Values passed from shared content to its occurrence-selected width controls. */ diff --git a/packages/client/ui-conversation/src/client/skeleton/ConversationContent.tsx b/packages/client/ui-conversation/src/client/skeleton/ConversationContent.tsx index 5c5d1149f8..06a8d09997 100644 --- a/packages/client/ui-conversation/src/client/skeleton/ConversationContent.tsx +++ b/packages/client/ui-conversation/src/client/skeleton/ConversationContent.tsx @@ -123,7 +123,7 @@ export function ConversationContent(props: ConversationContentProps) { onPick: (workspaceId) => { setPickerOpen(false) setPendingWorkspaceId(workspaceId) - void selectWorkspace(workspaceId).catch(() => { + void selectWorkspace(workspaceId, props.onWorkspaceSession).catch(() => { setPendingWorkspaceId(current => current === workspaceId ? undefined : current) }) }, @@ -164,7 +164,7 @@ export function ConversationContent(props: ConversationContentProps) { const composerBar = (
- {hero && } + {hero && } {hero && heroWorkspaceRow} {zone !== undefined && renderSlot('conversation.input.dock', zone)} {inputBar} diff --git a/packages/client/ui-conversation/src/client/skeleton/EmptyHero.tsx b/packages/client/ui-conversation/src/client/skeleton/EmptyHero.tsx index b46db926da..9adcf1e0ac 100644 --- a/packages/client/ui-conversation/src/client/skeleton/EmptyHero.tsx +++ b/packages/client/ui-conversation/src/client/skeleton/EmptyHero.tsx @@ -67,6 +67,8 @@ export interface HeroShellProps { t: HeroTranslate /** Authorized renderer for the hero brand-mark slot. */ renderSlot: ConversationContentProps['renderSlot'] + /** Text shown instead of the default headline and preview badge. */ + headline?: string | undefined /** Overlay content after the stack (modals). */ children?: ReactNode } @@ -129,7 +131,7 @@ function HeroFish({ hovering }: { hovering: boolean }) { * @param props - see {@link HeroShellProps}. * @returns the centered hero element tree. */ -export function HeroShell({ t, renderSlot, children }: HeroShellProps) { +export function HeroShell({ t, renderSlot, headline, children }: HeroShellProps) { const [hovering, setHovering] = useState(false) return (
@@ -152,8 +154,8 @@ export function HeroShell({ t, renderSlot, children }: HeroShellProps) { {/* Own element: keeps the headline text addressable apart from the badge. */} - {t('hero.headline')} - {t('hero.preview')} + {headline ?? t('hero.headline')} + {headline === undefined && {t('hero.preview')}}
diff --git a/packages/client/ui-conversation/tests/apply-inject.client.spec.tsx b/packages/client/ui-conversation/tests/apply-inject.client.spec.tsx index e6384343ef..5a19a1cbc6 100644 --- a/packages/client/ui-conversation/tests/apply-inject.client.spec.tsx +++ b/packages/client/ui-conversation/tests/apply-inject.client.spec.tsx @@ -96,6 +96,7 @@ async function bench(renderQuote = false) { const id = await connectWorkspace() replaceMain(id, beforeOpen) }, + connectWorkspace: async () => await connectWorkspace(), openSession, } as never) const sessionFake = sessionFakeFor() @@ -698,6 +699,24 @@ describe('Conversation inject API', () => { await b.runtime.dispose() }) + it('reports the blank of a picked Workspace to an embedding owner, which retains it, and moves the draft without opening it', async () => { + const b = await bench() + const resident = b.residentApi(ROOT) + b.inputApi(ROOT).actions.setDraft('review this') + const other = 'other-2' as SessionId + await b.runtime.sessions.add({ id: other, session: {} }) + b.connectWorkspace.mockResolvedValueOnce(other) + const held: SessionReference[] = [] + const report = vi.fn((id: SessionId) => { held.push(b.runtime.sessions.retain(id, { source: 'mainView' })) }) + await resident.selectWorkspace('workspace-3' as WorkspaceId, report) + expect(report).toHaveBeenCalledWith(other) + expect(b.opened).not.toHaveBeenCalledWith(other) + expect(b.inputApi(ROOT).state.getSnapshot().draft).toBe('') + expect(b.inputApi(other).state.getSnapshot().draft).toBe('review this') + for (const reference of held) reference.release() + await b.runtime.dispose() + }) + it('leaves a draft whose message is still being sent with its Session', async () => { const b = await bench() const pending = Promise.withResolvers>>() diff --git a/packages/client/ui-conversation/tests/skeleton.client.spec.tsx b/packages/client/ui-conversation/tests/skeleton.client.spec.tsx index e8c20dde27..fe3e12291b 100644 --- a/packages/client/ui-conversation/tests/skeleton.client.spec.tsx +++ b/packages/client/ui-conversation/tests/skeleton.client.spec.tsx @@ -437,6 +437,13 @@ describe('Hero chrome', () => { expect(brandMarkOwner.className).toBeTypeOf('string') expect(renderSlot.mock.calls[0]?.[2]?.fallback).toBeTruthy() }) + + it('shows an owner headline instead of the default headline and preview badge', () => { + const view = render( null) as never} headline="Review demo #42" />) + expect(view.getByText('Review demo #42')).toBeTruthy() + expect(view.queryByText('Into the Unknown')).toBeNull() + expect(view.queryByText('Preview')).toBeNull() + }) }) describe('ConversationRoot resident composer', () => { @@ -611,7 +618,7 @@ describe('ConversationRoot resident composer', () => { const owner = b.pickerOwner() as { open: boolean; onPick(id: WorkspaceId): void } expect(owner.open).toBe(true) act(() => { owner.onPick(wid('second')) }) - expect(b.retargetWorkspace).toHaveBeenCalledWith(wid('second')) + expect(b.retargetWorkspace).toHaveBeenCalledWith(wid('second'), undefined) expect(b.view.getByText('Selected Folder')).toBeTruthy() }) @@ -904,7 +911,7 @@ describe('ConversationRoot resident composer', () => { fireEvent.click(b.view.getByRole('button', { name: '选择工作区' })) const owner = b.pickerOwner() as { onPick(id: WorkspaceId): void } await act(async () => { owner.onPick(wid('second')); await Promise.resolve() }) - expect(selectWorkspace).toHaveBeenCalledWith(wid('second')) + expect(selectWorkspace).toHaveBeenCalledWith(wid('second'), undefined) expect(b.view.queryByText('Selected Folder')).toBeNull() expect(b.view.getByText('one')).toBeTruthy() }) diff --git a/packages/client/ui-primitives/README.i18n.yaml b/packages/client/ui-primitives/README.i18n.yaml index 3c1785b330..71960ca8e4 100644 --- a/packages/client/ui-primitives/README.i18n.yaml +++ b/packages/client/ui-primitives/README.i18n.yaml @@ -18,8 +18,8 @@ en: ead6be55c7c9d7cf zh: 125ad36db7328551 /deepseek-ai-dsh-client-ui-primitives/use-this-package/component-catalog: - en: 11686b52743a702d - zh: d865bb79d8f56ee1 + en: 2ce6588177efbdeb + zh: 10202a7a6471e974 /deepseek-ai-dsh-client-ui-primitives/use-this-package/controls-and-icons: en: 69acdb3375548a62 zh: c392c11faf88938f diff --git a/packages/client/ui-primitives/README.md b/packages/client/ui-primitives/README.md index 84930bb4ff..aa32ecec86 100644 --- a/packages/client/ui-primitives/README.md +++ b/packages/client/ui-primitives/README.md @@ -65,6 +65,7 @@ Check this table before writing a control in a feature package. A plugin cannot | `RiskConfirmation` | Sensitive action gated behind an explicit checkbox, using the shared warning-title layout. | | `Tooltip` | Hover and keyboard-focus text anchored to a cloned child; optional `delayMs` controls hover delay and `focusDelayMs` controls keyboard-focus delay, both defaulting to 0 ms. Optional `portal` rendering escapes clipping containers and ancestor stacking contexts that cap the bubble's z-index. | | `HoverCard`, `HoverCardGroup` | Readable, optionally copyable hover preview; a physical list can opt cards into shared first-display dwell and exclusive display. | +| `useTitleMarquee`, `titleMarqueeClass` | Scrolls a one-line clipped title to its far edge while its row is hovered and fades its clipping edges; the Session list uses it. | | `DraggableImage` | Original-image gestures with explicit transfer and feedback callbacks. | | `ImageLightbox` | Shared image modal with focus restoration and Escape dismissal. | | `usePointerGrace` | Cancelable dismissal delay that lets the pointer cross the gap between a trigger and its card; pending timers are cleared on unmount. | diff --git a/packages/client/ui-primitives/README.zh.md b/packages/client/ui-primitives/README.zh.md index eb1b989a1a..75a2b7092e 100644 --- a/packages/client/ui-primitives/README.zh.md +++ b/packages/client/ui-primitives/README.zh.md @@ -65,6 +65,7 @@ kind: "package-library" | `RiskConfirmation` | 以显式复选框把关的敏感操作确认,采用共用的警告标题布局。 | | `Tooltip` | 锚定在克隆子元素上的悬停与键盘聚焦提示;可选的 `delayMs` 控制悬停延迟,`focusDelayMs` 控制键盘聚焦延迟,均默认为 0 毫秒。可通过 `portal` 渲染到外层,避免被容器裁剪,或受祖先层叠上下文限制其 z-index。 | | `HoverCard`、`HoverCardGroup` | 可阅读、可选带复制按钮的悬停预览;物理列表可选择让卡片共享首次显示等待,并互斥显示。 | +| `useTitleMarquee`、`titleMarqueeClass` | 行被悬停时把被截断的单行标题滚动到末尾,并淡化截断边缘;会话列表使用它。 | | `DraggableImage` | 通过显式传递与反馈回调提供原图拖放。 | | `ImageLightbox` | 共享图片浮层,支持焦点恢复与 Esc 关闭。 | | `usePointerGrace` | 可取消的延迟关闭,让指针能够跨越触发控件与卡片间的空隙;卸载时清除待执行定时器。 | diff --git a/packages/client/ui-primitives/src/TitleMarquee.module.css b/packages/client/ui-primitives/src/TitleMarquee.module.css new file mode 100644 index 0000000000..7fa7e1ca34 --- /dev/null +++ b/packages/client/ui-primitives/src/TitleMarquee.module.css @@ -0,0 +1,17 @@ +/* While the marquee travels, both clipping edges fade in over 12px instead of + hard-cutting a character: the left once the title has moved off its start + (data-scrolled), the right while text still remains beyond the cell + (data-clipped). At the far edge the right fade lifts so the final character + reads at full strength. The mask rides the title element itself, so cells + beside it keep their full color. */ +.marquee[data-scrolled] { + mask-image: linear-gradient(to right, transparent, #000 12px); +} + +.marquee[data-clipped] { + mask-image: linear-gradient(to left, transparent, #000 12px); +} + +.marquee[data-scrolled][data-clipped] { + mask-image: linear-gradient(to right, transparent, #000 12px, #000 calc(100% - 12px), transparent); +} diff --git a/packages/client/ui-primitives/src/index.ts b/packages/client/ui-primitives/src/index.ts index 44dbcd8871..fb081ad24d 100644 --- a/packages/client/ui-primitives/src/index.ts +++ b/packages/client/ui-primitives/src/index.ts @@ -41,6 +41,7 @@ export { useAnchoredMaxHeight } from './useAnchoredMaxHeight.ts' export { useDismissOnOutsidePointer } from './useDismissOnOutsidePointer.ts' export { HoverCard } from './HoverCard.tsx' export { HoverCardGroup } from './HoverCardGroup.tsx' +export { titleMarqueeClass, useTitleMarquee } from './title-marquee.ts' export { usePointerGrace } from './pointer-grace.ts' export { ShortcutKeys } from './ShortcutKeys.tsx' export { observeComposition } from './keyboard-composition.ts' diff --git a/packages/client/ui-primitives/src/title-marquee.ts b/packages/client/ui-primitives/src/title-marquee.ts new file mode 100644 index 0000000000..878e1dd3de --- /dev/null +++ b/packages/client/ui-primitives/src/title-marquee.ts @@ -0,0 +1,105 @@ +/** + * Marquee of a one-line title that clips its own text: while its row is hovered, a title wider than its cell crawls to + * its far edge, and its clipping edges fade through the `data-scrolled` and `data-clipped` hooks that + * {@link titleMarqueeClass} styles. + */ + +import { useEffect, useMemo, useRef } from 'react' +import type { PointerEvent, RefObject } from 'react' +import css from './TitleMarquee.module.css' + +/** Class that fades a marquee title's clipping edges while it travels; add it to the title element. */ +/* v8 ignore next -- the stylesheet defines .marquee; the fallback only satisfies the class map's index signature. */ +export const titleMarqueeClass: string = css.marquee ?? '' + +/* Overflow this small hides no meaningful tail; scrolling for it reads as an + accidental jitter, so the title stays put. */ +const MIN_TITLE_REVEAL_PX = 8 + +/* Marquee travel speed: slow enough to read the text as it passes. */ +const TITLE_MARQUEE_PX_PER_MS = 0.03 + +/** + * Place the title's scroll position and publish the stylesheet's fade-mask + * hooks: `data-scrolled` while the title has left its start (left fade) and + * `data-clipped` while text remains beyond the right edge (right fade). + * @param title - the clipping title element. + * @param left - scroll offset in CSS pixels. + * @param range - the title's maximum scroll offset in CSS pixels. + */ +function placeTitle(title: HTMLSpanElement, left: number, range: number): void { + // jsdom implements no scrollTo; the lane's direct assignment is instant there + // anyway, so both paths land on the same position. + if (typeof title.scrollTo === 'function') title.scrollTo({ left, behavior: 'instant' }) + else title.scrollLeft = left + if (left > 0) title.dataset.scrolled = '' + else delete title.dataset.scrolled + if (left < range) title.dataset.clipped = '' + else delete title.dataset.clipped +} + +/** + * Return the title to its resting state: scrolled to the start with both fade + * masks off, so the resting ellipsis renders at full strength. + * @param title - the clipping title element. + */ +function restTitle(title: HTMLSpanElement): void { + if (typeof title.scrollTo === 'function') title.scrollTo({ left: 0, behavior: 'instant' }) + else title.scrollLeft = 0 + delete title.dataset.scrolled + delete title.dataset.clipped +} + +/** + * Marquee a title wider than its one-line cell while its row is hovered: the + * title clips its own text, so entering crawls it at a constant speed until the + * far edge (a fork's incremented title, for example) is in view, then rests + * there under the pointer. Overflow of at most {@link MIN_TITLE_REVEAL_PX} + * stays put — a barely-clipped title moving a few pixels reads as jitter, not a + * reveal. Leaving returns the title to the start in one step, because the + * resting ellipsis and the narrowed cell would otherwise meet the text while it + * travelled back. Reduced motion jumps to the far edge instead of crawling. + * @param title - ref to the clipping title element. + * @returns stable pointer enter/leave handlers for the row. + */ +export function useTitleMarquee(title: RefObject): { + enter: (event?: PointerEvent) => void + leave: () => void +} { + const frame = useRef(0) + const revealing = useRef(false) + useEffect(() => () => { cancelAnimationFrame(frame.current) }, []) + return useMemo(() => ({ + enter: (event?: PointerEvent): void => { + if (event?.pointerType === 'touch') return + /* v8 ignore next -- defensive: the title span renders unconditionally. */ + if (title.current === null) return + if (revealing.current) return + revealing.current = true + const element = title.current + const range = element.scrollWidth - element.clientWidth + if (range <= MIN_TITLE_REVEAL_PX) return + if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) { + placeTitle(element, range, range) + return + } + cancelAnimationFrame(frame.current) + let previous: number | undefined + let position = 0 + const step = (now: DOMHighResTimeStamp): void => { + position += previous === undefined ? 0 : (now - previous) * TITLE_MARQUEE_PX_PER_MS + previous = now + placeTitle(element, Math.min(position, range), range) + if (position < range) frame.current = requestAnimationFrame(step) + } + frame.current = requestAnimationFrame(step) + }, + leave: (): void => { + revealing.current = false + cancelAnimationFrame(frame.current) + /* v8 ignore next -- defensive: the title span renders unconditionally. */ + if (title.current === null) return + restTitle(title.current) + }, + }), [title]) +} diff --git a/packages/client/ui-primitives/tests/title-marquee-styles.client.spec.ts b/packages/client/ui-primitives/tests/title-marquee-styles.client.spec.ts new file mode 100644 index 0000000000..246c75d746 --- /dev/null +++ b/packages/client/ui-primitives/tests/title-marquee-styles.client.spec.ts @@ -0,0 +1,28 @@ +/** + * The title marquee's fade masks as CSS text. CSS Modules resolve to class-name maps in the component suites, so only + * the stylesheet can show that each clipping edge fades while the title travels. + */ +import { readFileSync } from 'node:fs' +import { fileURLToPath } from 'node:url' +import { describe, expect, it } from 'vitest' + +const css = readFileSync(fileURLToPath(new URL('../src/TitleMarquee.module.css', import.meta.url)), 'utf8') + .replace(/\/\*[\s\S]*?\*\//g, ' ') + +/** The mask image of the rule for one exact selector, with whitespace collapsed. */ +function mask(selector: string): string | undefined { + for (const [, selectors = '', body = ''] of css.matchAll(/([^{}]+)\{([^{}]*)\}/g)) { + if (selectors.trim() !== selector) continue + return /mask-image:\s*([^;]+);/.exec(body)?.[1]?.replace(/\s+/g, ' ').trim() + } + return undefined +} + +describe('TitleMarquee.module.css', () => { + it('fades the left edge once the title left its start, the right while text remains beyond it, and both mid-travel', () => { + expect(mask('.marquee[data-scrolled]')).toBe('linear-gradient(to right, transparent, #000 12px)') + expect(mask('.marquee[data-clipped]')).toBe('linear-gradient(to left, transparent, #000 12px)') + expect(mask('.marquee[data-scrolled][data-clipped]')) + .toBe('linear-gradient(to right, transparent, #000 12px, #000 calc(100% - 12px), transparent)') + }) +}) diff --git a/packages/client/ui-primitives/tests/title-marquee.client.spec.tsx b/packages/client/ui-primitives/tests/title-marquee.client.spec.tsx new file mode 100644 index 0000000000..56cf5028ff --- /dev/null +++ b/packages/client/ui-primitives/tests/title-marquee.client.spec.tsx @@ -0,0 +1,157 @@ +// @vitest-environment jsdom +/** + * The title marquee: while its row is hovered, a clipped title crawls to its far edge at a constant speed, or jumps + * there under reduced motion; touch and overflow too small to read stay put; leaving returns it to its start in one + * step. + */ +import { useRef, type ReactNode } from 'react' +import { cleanup, fireEvent, render, screen } from '@testing-library/react' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { titleMarqueeClass, useTitleMarquee } from '../src/title-marquee.ts' +import css from '../src/TitleMarquee.module.css' + +const TITLE = 'A title long enough to be clipped' + +/** A one-line row whose title marquees while it is hovered. */ +function Row(): ReactNode { + const title = useRef(null) + const marquee = useTitleMarquee(title) + return ( + + ) +} + +/** Render the row with its title clipped to `clientWidth` of `scrollWidth` pixels. */ +function renderRow(scrollWidth: number, clientWidth: number) { + const view = render() + const row = screen.getByRole('button') + const title = screen.getByText(TITLE) + // jsdom lays out nothing: the title's clipped geometry is stated outright. + Object.defineProperty(title, 'scrollWidth', { value: scrollWidth, configurable: true }) + Object.defineProperty(title, 'clientWidth', { value: clientWidth, configurable: true }) + return { view, row, title } +} + +/** The fade-mask hooks the title publishes. */ +function fades(title: HTMLElement): { readonly scrolled: boolean; readonly clipped: boolean } { + return { scrolled: title.hasAttribute('data-scrolled'), clipped: title.hasAttribute('data-clipped') } +} + +let reducedMotion = false + +beforeEach(() => { + reducedMotion = false + vi.useFakeTimers() + // jsdom implements no matchMedia; the stub answers the reduced-motion probe. + vi.stubGlobal('matchMedia', vi.fn((query: string) => ({ matches: reducedMotion && query === '(prefers-reduced-motion: reduce)' }))) +}) + +afterEach(() => { + cleanup() + vi.useRealTimers() + vi.unstubAllGlobals() +}) + +describe('useTitleMarquee', () => { + it('crawls a clipped title to its far edge at a constant speed while its row is hovered, and rests there', () => { + const { row, title } = renderRow(320, 180) + expect(titleMarqueeClass).toBe(css.marquee) + fireEvent.pointerEnter(row) + // The first frame only records the clock; travel begins on the second. + vi.advanceTimersByTime(16) + expect(title.scrollLeft).toBe(0) + expect(fades(title)).toEqual({ scrolled: false, clipped: true }) + // 30px a second: 1600ms of frames crawl 48px, off the start and short of the far edge. + vi.advanceTimersByTime(1600) + expect(title.scrollLeft).toBeCloseTo(48, 5) + expect(fades(title)).toEqual({ scrolled: true, clipped: true }) + vi.advanceTimersByTime(10_000) + expect(title.scrollLeft).toBe(140) + expect(fades(title)).toEqual({ scrolled: true, clipped: false }) + }) + + it('keeps crawling when the pointer enters the row again mid-crawl', () => { + const { row, title } = renderRow(320, 180) + fireEvent.pointerEnter(row) + vi.advanceTimersByTime(1616) + fireEvent.pointerEnter(row) + vi.advanceTimersByTime(1600) + expect(title.scrollLeft).toBeCloseTo(96, 5) + }) + + it('leaves a title that fits or overflows by at most 8px at its start, and crawls one a pixel wider', () => { + const fits = renderRow(180, 180) + fireEvent.pointerEnter(fits.row) + vi.advanceTimersByTime(1000) + expect(fits.title.scrollLeft).toBe(0) + expect(fades(fits.title)).toEqual({ scrolled: false, clipped: false }) + cleanup() + + const jitter = renderRow(188, 180) + fireEvent.pointerEnter(jitter.row) + vi.advanceTimersByTime(1000) + expect(jitter.title.scrollLeft).toBe(0) + cleanup() + + const reveal = renderRow(189, 180) + fireEvent.pointerEnter(reveal.row) + vi.advanceTimersByTime(1000) + expect(reveal.title.scrollLeft).toBe(9) + }) + + it('ignores a touch, which hovers nothing', () => { + const { row, title } = renderRow(320, 180) + // jsdom lacks PointerEvent; a plain event keeps the pointer type React reads. + const touch = new Event('pointerover', { bubbles: true }) + Object.defineProperty(touch, 'pointerType', { value: 'touch' }) + fireEvent(row, touch) + vi.advanceTimersByTime(1000) + expect(title.scrollLeft).toBe(0) + expect(fades(title)).toEqual({ scrolled: false, clipped: false }) + }) + + it('jumps a clipped title to its far edge under reduced motion', () => { + reducedMotion = true + const { row, title } = renderRow(320, 180) + fireEvent.pointerEnter(row) + expect(title.scrollLeft).toBe(140) + expect(fades(title)).toEqual({ scrolled: true, clipped: false }) + fireEvent.pointerLeave(row) + expect(title.scrollLeft).toBe(0) + expect(fades(title)).toEqual({ scrolled: false, clipped: false }) + }) + + it('returns the title to its start in one instant step on leave and cancels the crawl', () => { + const { row, title } = renderRow(320, 180) + const scrollTo = vi.fn<(options: ScrollToOptions) => void>() + Object.defineProperty(title, 'scrollTo', { value: scrollTo, configurable: true }) + fireEvent.pointerEnter(row) + vi.advanceTimersByTime(1616) + expect(scrollTo.mock.lastCall?.[0].left).toBeCloseTo(48, 5) + expect(scrollTo.mock.lastCall?.[0].behavior).toBe('instant') + fireEvent.pointerLeave(row) + expect(scrollTo).toHaveBeenLastCalledWith({ left: 0, behavior: 'instant' }) + expect(fades(title)).toEqual({ scrolled: false, clipped: false }) + const calls = scrollTo.mock.calls.length + vi.advanceTimersByTime(1000) + expect(scrollTo).toHaveBeenCalledTimes(calls) + + // Once left, the next hover crawls from the start again. + fireEvent.pointerEnter(row) + vi.advanceTimersByTime(16) + expect(scrollTo).toHaveBeenLastCalledWith({ left: 0, behavior: 'instant' }) + expect(fades(title)).toEqual({ scrolled: false, clipped: true }) + }) + + it('stops the crawl when the row unmounts', () => { + const { view, row, title } = renderRow(320, 180) + fireEvent.pointerEnter(row) + vi.advanceTimersByTime(1616) + const reached = title.scrollLeft + view.unmount() + vi.advanceTimersByTime(1000) + expect(title.scrollLeft).toBe(reached) + }) +}) diff --git a/packages/client/ui-sidebar/README.i18n.yaml b/packages/client/ui-sidebar/README.i18n.yaml index 5847e07229..0244697611 100644 --- a/packages/client/ui-sidebar/README.i18n.yaml +++ b/packages/client/ui-sidebar/README.i18n.yaml @@ -21,8 +21,8 @@ en: 6bc49e22f0f73f07 zh: 10883997ccb7d145 /deepseek-ai-dsh-client-ui-sidebar/use-this-package/global-panel-entries: - en: 8a23eab217042cc6 - zh: 2d760de4c83f996c + en: bae2249daceec5f1 + zh: da6a7d880d0af55b /deepseek-ai-dsh-client-ui-sidebar/use-this-package/collapse-behavior: en: 10381cbac96069a3 zh: c5849741a0be2f00 @@ -36,8 +36,8 @@ en: 3e84ffdf6c7c1731 zh: 3f7b19cac6d6674f /deepseek-ai-dsh-client-ui-sidebar/understand-the-implementation: - en: 76a542d822e94fc9 - zh: da25857ead58df5c + en: c13373b1c2fabd64 + zh: e01fbc5d5d760b2c /deepseek-ai-dsh-client-ui-sidebar/understand-the-implementation/slot-discipline: en: 6eefc5c45abe8a8f zh: 20b651e48a0ea903 diff --git a/packages/client/ui-sidebar/README.md b/packages/client/ui-sidebar/README.md index 43cfe45193..3a6528855c 100644 --- a/packages/client/ui-sidebar/README.md +++ b/packages/client/ui-sidebar/README.md @@ -41,6 +41,8 @@ The expanded brand row renders `sidebar.brand.mark` and `sidebar.brand.name` as Plugins add an icon component to the root-scoped `sidebar.panellist` list with an `id`, optional `order`, and a string or locale-aware `label`. The same id addresses the component registered in the layout's root-scoped `main` keyed slot; selecting a missing main entry throws without changing the current selection. The label supplies plain visible text, the accessible name, and the collapsed tooltip. Expanded navigation rows are 32px high with a 2px gap; collapsed rail controls remain 36px high with a 12px gap. Each row reads its own selected state through `usePanelInfo`; moving DOM focus to search or a directory picker does not change the displayed panel or its selected row. With no panel registrations, neither the list nor spacing for it is rendered. The shipped composition registers no example panel. +A panel may also register non-interactive content in the root-scoped `sidebar.panellist.trailing` list with the same `id`, such as a count. It receives `wide` and `active`; the expanded row shows it at its trailing edge, hidden while the row's unpin action shows on hover or keyboard focus and placed beside that action on devices without hover, and the collapsed rail shows it over the icon's top trailing corner. Its text becomes the row button's accessible description, so decorative parts must be `aria-hidden`. + While the root-scoped `sidebar.panellist.actions` list has registrations, a **More** button styled as a panel row follows the rows inside the navigation landmark; the collapsed rail shows its label as a tooltip. It opens a menu whose rows are that list's registrations. Each receives `entries` (customizable panels in registration order with `id`, `label`, `pinned`, and `active`; Plugins is never listed), `onOpen(id)`, which selects the panel, `onPinnedChange(id, pinned)`, and `onDismiss()`, which closes the menu. The sidebar keeps one in-memory list of unpinned panel ids shared by every Session; Plugins always shows. While More shows, expanded rows other than Plugins show an unpin action on hover or keyboard focus; devices without hover show it continuously. Its resting color matches the Session pin marker, and its tooltip says “Unpin from left sidebar”. Both sidebar and More entries follow the same registration order rather than pin timing. The default More menu lists only unpinned panels before plugin browsing and creation; opening a panel does not pin it, while its separate pin icon returns the row to the sidebar and dismisses the menu. Choices reset when the plugin reloads and legacy localStorage values are ignored. Unpinning hides only the row, and only while More shows; without `sidebar.panellist.actions` registrations every registered row shows again. The main panel, its registration, and the current selection stay unchanged. Unregistered panel ids remain in the in-memory list until the plugin reloads. ### Collapse behavior @@ -78,7 +80,7 @@ On Desktop, the official navigation controls report `sidebar_menu_click` with `m
Implementation internals — click to expand -The shell is pure composition: `SidebarRootComponentProps` composes the layout owner share, the global `useSessions` and `useWorkspaces` hooks, the declared brand, the `sidebar.workspaces` and `sidebar.settings` child slots, and injected navigation callbacks. The sidebar declares the `sidebar.panel.icon` Component Factory, which owns the `sidebar.panellist` list; panel rows and the More menu render a panel's registered icon through that factory. Panel metadata is derived from list registrations and locale changes; selection belongs to the layout store. The injected `trackEntryClick(attributes)` forwards to `ctx.get('productAnalytics')?.track('sidebar_menu_click', attributes)`, and `selectPanel` only selects, so each control supplies its own entry and position. +The shell is pure composition: `SidebarRootComponentProps` composes the layout owner share, the global `useSessions` and `useWorkspaces` hooks, the declared brand, the `sidebar.workspaces` and `sidebar.settings` child slots, and injected navigation callbacks. The sidebar declares the `sidebar.panel.icon` Component Factory, which owns the `sidebar.panellist` list, and the `sidebar.panel.trailing` Component Factory, which owns the `sidebar.panellist.trailing` list; panel rows and the More menu render a panel's registered icon through the first, and panel rows its trailing content through the second. Panel metadata is derived from list registrations and locale changes; selection belongs to the layout store. The injected `trackEntryClick(attributes)` forwards to `ctx.get('productAnalytics')?.track('sidebar_menu_click', attributes)`, and `selectPanel` only selects, so each control supplies its own entry and position. Expanded navigation uses 8px outer gutters, hover and selected fills inset 3px on each side, and a 16px leading cell with a 6px label gap. New Session centers its content with 4px side margins. Its initial 12px gap above navigation combines 4px outside the scrollport and an 8px gap that scrolls away. The logo row has no bottom margin; its content starts 16px from the column's left edge, with 5px between mark and name. Only the macOS non-fullscreen top toggle shifts 4px right while expanded, retaining that offset throughout its fade-out. Collapsed geometry stays independent. diff --git a/packages/client/ui-sidebar/README.zh.md b/packages/client/ui-sidebar/README.zh.md index 2f0c507119..264508f8e0 100644 --- a/packages/client/ui-sidebar/README.zh.md +++ b/packages/client/ui-sidebar/README.zh.md @@ -41,6 +41,8 @@ dsh Web 客户端的侧边栏让用户识别当前构建、启动新会话、将 插件在 root 作用域的 `sidebar.panellist` list 中注册图标组件,提供 `id`、可选 `order`,以及字符串或 locale-aware 的 `label`。同一个 id 寻址布局中 root 作用域 `main` keyed slot 的组件;选择不存在的主面板条目会抛错,并保留当前选中态。标签提供普通可见文字、无障碍名称和折叠提示。展开态导航行高 32px,间距为 2px;折叠窄栏控件保持 36px 高和 12px 间距。每一行通过 `usePanelInfo` 读取自己的选中态;DOM 焦点移到搜索框或目录选择器时,显示的面板及其列表项选中态不变。没有面板注册项时,列表及其间距均不渲染。产品随附的组合不注册示例面板。 +面板还可以用相同 `id` 在 root 作用域的 `sidebar.panellist.trailing` list 中注册不可交互的内容,例如数量。它接收 `wide` 与 `active`;展开的行在行尾显示它,悬停或键盘聚焦出现取消固定操作时隐藏,在不支持悬停的设备上放在该操作旁边;收起的窄栏在图标右上角显示它。它的文字成为行按钮的无障碍描述,因此装饰性的部分必须设为 `aria-hidden`。 + root 作用域的 `sidebar.panellist.actions` list 有注册项时,导航区域的面板行之后显示面板行样式的**更多**按钮;收起的窄栏以提示框显示其名称。它打开的菜单以该 list 的注册项为菜单行。每个注册项接收 `entries`(按注册顺序的可自定义面板,含 `id`、`label`、`pinned` 与 `active`;不含插件管理)、选中面板的 `onOpen(id)`、`onPinnedChange(id, pinned)`,以及关闭菜单的 `onDismiss()`。侧边栏在内存中保存所有会话共用的已收起面板 id 列表;插件管理入口始终显示。更多按钮显示时,展开态中除插件管理外的面板行在悬停或键盘聚焦时显示取消固定操作;不支持悬停的设备始终显示该操作。图标默认颜色与会话置顶标记一致,提示为“从左侧栏取消固定”。侧栏和更多菜单入口遵循相同的注册排序,不按固定时间重排。默认更多菜单在插件浏览和创建之前仅列出未固定的面板;打开面板不会将其固定,独立的固定图标则将该行放回侧边栏并关闭菜单。插件重新加载时选择重置,不读取旧 localStorage 值。收起只隐藏导航行,且仅在更多按钮显示时生效;`sidebar.panellist.actions` 没有注册项时,所有已注册的面板行重新显示。主面板、其注册和当前选中态不变。未注册面板的 id 保留在内存列表中,直到插件重新加载。 ### 折叠行为 @@ -78,7 +80,7 @@ root 作用域的 `sidebar.panellist.actions` list 有注册项时,导航区
实现细节——点击展开 -外壳是纯组合:`SidebarRootComponentProps` 组合布局 owner share、全局 `useSessions` 与 `useWorkspaces` 钩子、已声明的品牌、`sidebar.workspaces` 与 `sidebar.settings` 子 slot,以及注入的导航回调。侧边栏声明 `sidebar.panel.icon` Component Factory,由它拥有 `sidebar.panellist` list;面板行和更多菜单都通过该 factory 渲染面板注册的图标。面板元数据由列表注册和 locale 变化派生;选中态属于布局存储。注入的 `trackEntryClick(attributes)` 转发到 `ctx.get('productAnalytics')?.track('sidebar_menu_click', attributes)`;`selectPanel` 只负责选中,因此由各控件自行提供入口与位置。 +外壳是纯组合:`SidebarRootComponentProps` 组合布局 owner share、全局 `useSessions` 与 `useWorkspaces` 钩子、已声明的品牌、`sidebar.workspaces` 与 `sidebar.settings` 子 slot,以及注入的导航回调。侧边栏声明 `sidebar.panel.icon` Component Factory,由它拥有 `sidebar.panellist` list,并声明 `sidebar.panel.trailing` Component Factory,由它拥有 `sidebar.panellist.trailing` list;面板行和更多菜单通过前者渲染面板注册的图标,面板行通过后者渲染行尾内容。面板元数据由列表注册和 locale 变化派生;选中态属于布局存储。注入的 `trackEntryClick(attributes)` 转发到 `ctx.get('productAnalytics')?.track('sidebar_menu_click', attributes)`;`selectPanel` 只负责选中,因此由各控件自行提供入口与位置。 展开态导航的左右外距为 8px,悬停与选中底色在两侧各内缩 3px,前置单元宽 16px,与标签间隔 6px。新会话内容居中,左右外边距为 4px。它与导航的初始 12px 间距由滚动区外的 4px 和随内容滚走的 8px 组成。logo 行无底部外边距;内容从侧栏左边缘向内 16px 开始,标记与名称间隔 5px。仅 macOS 非全屏、侧栏展开时,顶部开关向右偏移 4px,并在整个淡出期间保持该偏移。折叠态尺寸独立保留。 diff --git a/packages/client/ui-sidebar/src/client/PanelIcon.tsx b/packages/client/ui-sidebar/src/client/PanelIcon.tsx index ba3ed5fc04..85b2fa9262 100644 --- a/packages/client/ui-sidebar/src/client/PanelIcon.tsx +++ b/packages/client/ui-sidebar/src/client/PanelIcon.tsx @@ -10,3 +10,12 @@ import type {} from './contract/slots.ts' export function PanelIcon({ id, size, active, renderSlot }: FactoryComponentPropsOf<'sidebar.panel.icon'>) { return renderSlot('sidebar.panellist', { size, active }, { only: id }) } + +/** + * Render the trailing content registered for one panel in its navigation row. + * @param props - Panel identity, row state, and the authorized child renderer. + * @returns The matching trailing content, or nothing without a registration. + */ +export function PanelTrailing({ id, wide, active, renderSlot }: FactoryComponentPropsOf<'sidebar.panel.trailing'>) { + return renderSlot('sidebar.panellist.trailing', { wide, active }, { only: id }) +} diff --git a/packages/client/ui-sidebar/src/client/SidebarRoot.module.css b/packages/client/ui-sidebar/src/client/SidebarRoot.module.css index a9de41653f..b7071769e5 100644 --- a/packages/client/ui-sidebar/src/client/SidebarRoot.module.css +++ b/packages/client/ui-sidebar/src/client/SidebarRoot.module.css @@ -661,6 +661,43 @@ outline-offset: -2px; } +/* A panel's trailing content: at the row's trailing edge, where the unpin action shows instead while the row is + hovered or focused, and over the icon's top trailing corner on the collapsed rail. It never takes pointer input. */ +.panelTrailing { + position: absolute; + right: 10px; + top: 50%; + display: inline-flex; + align-items: center; + transform: translateY(-50%); + color: var(--dsw-alias-label-tertiary); + font-size: 12px; + line-height: 18px; + font-variant-numeric: tabular-nums; + pointer-events: none; +} + +.panelTrailing:empty { + display: none; +} + +.collapsed .panelTrailing { + right: 5px; + top: 5px; + transform: none; +} + +@media (hover: hover) { + .panelEntry:has(.panelUnpin):hover .panelTrailing, + .panelEntry:has(.panelUnpin):has(:focus-visible) .panelTrailing { visibility: hidden; } +} + +/* Without hover the unpin action shows continuously, so the trailing content sits beside it and the title yields room. */ +@media (hover: none) { + .panelEntry:has(.panelUnpin) .panelTrailing { right: 38px; } + .panelEntryWide:has(.panelUnpin):has(.panelTrailing:not(:empty)) .panelRow { padding-right: 72px; } +} + @media (hover: hover) { .panelUnpin { opacity: 0; } .panelEntry:hover { background-color: var(--dsw-alias-interactive-bg-hover); } diff --git a/packages/client/ui-sidebar/src/client/SidebarRoot.tsx b/packages/client/ui-sidebar/src/client/SidebarRoot.tsx index b573b19cc8..ede4ab22c0 100644 --- a/packages/client/ui-sidebar/src/client/SidebarRoot.tsx +++ b/packages/client/ui-sidebar/src/client/SidebarRoot.tsx @@ -18,7 +18,7 @@ * scrollbar indirection away while it is elsewhere, so a list the user is not * pointing at carries no bar. */ -import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react' +import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from 'react' import clsx from 'clsx' import { FishLogo, IconAppsAddOutlineRegular, IconNewChatOutlineMedium, IconNewChatOutlineRegular, @@ -74,6 +74,7 @@ function PanelRow({ id, label, wide, unpinLabel, unpinTooltip, canUnpin, usePanelInfo, selectPanel, setPinned, trackEntryClick, renderFactorySlot, }: PanelRowProps) { const active = usePanelInfo(info => info.activePanelId === id) + const trailing = useId() return (
@@ -81,6 +82,7 @@ function PanelRow({ type="button" className={css.panelRow} aria-label={label} + aria-describedby={trailing} aria-current={active ? 'page' : undefined} onClick={() => { const entry = officialEntry(id) @@ -98,6 +100,7 @@ function PanelRow({ )} + {renderFactorySlot('sidebar.panel.trailing', { id, wide, active })} {wide && canUnpin && - {renderFactorySlot('sidebar.panel.trailing', { id, wide, active })} {wide && canUnpin &&