Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 插件详情页顶栏吸顶,补回 mac 缺失的窗口拖拽区 (#1165)
zhanghengxd4be734ef6645
diff --git a/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx b/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsxindex d6dbdb013c..f5a3e31d69 100644--- a/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx+++ b/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx@@ -2,7 +2,8 @@* Plugin detail presentation for configuration, Tools, permissions, and factual metadata.** Inputs: the renderer-safe Plugin detail model plus the installed Ghost when available.- * Outputs: accessible detail interactions and a single-row responsive action hero.+ * Outputs: accessible detail interactions, a single-row responsive action hero, and the sticky+ * top bar that carries the back affordance plus this page's macOS window-drag region.* [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md*/@@ -11,7 +12,6 @@ import * as Dialog from '@radix-ui/react-dialog';import {AppWindow,Bot,- ArrowLeft,ChevronDown,Copy,Cpu,@@ -58,6 +58,7 @@ import type { GhostPermissionItem, GhostToolDecl, InstalledGhost } from '../../.import { type GhostPluginDetail } from './lib/ghostPluginViewModel';import { GhostPluginIcon } from './GhostPluginIcon';import { ghostPluginSummary } from './lib/ghostPluginDetailModel';+import { PluginDetailTopBar, usePluginDetailScrolled } from './PluginDetailTopBar';import './plugin-motion.css';interface GhostPluginDetailViewProps {@@ -141,6 +142,7 @@ export function GhostPluginDetailView({onIconLoadError,}: GhostPluginDetailViewProps) {const { t } = useTranslation();+ const { scrolled, onScroll } = usePluginDetailScrolled();const [descriptionExpanded, setDescriptionExpanded] = useState(false);const [descriptionOverflows, setDescriptionOverflows] = useState(false);const descriptionRef = useRef<HTMLParagraphElement>(null);@@ -194,18 +196,16 @@ export function GhostPluginDetailView({}, [detail.id, summary]);return (- <main className="plugin-motion-root h-full min-h-0 w-full overflow-y-auto bg-[var(--surface)] [scrollbar-gutter:stable_both-edges]">+ <main+ className="plugin-motion-root h-full min-h-0 w-full overflow-y-auto bg-[var(--surface)] [scrollbar-gutter:stable_both-edges]"+ onScroll={onScroll}+ >+ <PluginDetailTopBar+ label={t('settings.ghosts.detail.backToList')}+ onBack={onBack}+ scrolled={scrolled}+ /><article className="plugin-detail-frame mx-auto w-full max-w-[824px] px-8 pb-16 pt-5 max-[760px]:px-6">- <button- type="button"- onClick={onBack}- className="-ml-3 mb-7 inline-flex h-9 w-fit select-none items-center gap-2 rounded-full px-3 text-13 text-[var(--text-secondary)] transition-colors duration-150 hover:bg-[var(--surface-hover-soft)] hover:text-[var(--text-primary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]"- style={WINDOW_NO_DRAG_STYLE}- >- <ArrowLeft size={16} aria-hidden="true" />- {t('settings.ghosts.detail.backToList')}- </button>-<header><div className="plugin-detail-hero grid grid-cols-[64px_minmax(0,1fr)_auto] items-center gap-3"><GhostPluginIcondiff --git a/apps/desktop/src/renderer/features/plugin/MarketPluginDetailView.tsx b/apps/desktop/src/renderer/features/plugin/MarketPluginDetailView.tsxindex 187f81374c..0d656ea3cf 100644--- a/apps/desktop/src/renderer/features/plugin/MarketPluginDetailView.tsx+++ b/apps/desktop/src/renderer/features/plugin/MarketPluginDetailView.tsx@@ -1,12 +1,12 @@-import { ArrowLeft, Download, ShieldCheck } from 'lucide-react';+import { Download, ShieldCheck } from 'lucide-react';import { useTranslation } from 'react-i18next';-import { WINDOW_NO_DRAG_STYLE } from '@/components/layout/windowDrag';import { cn } from '@/lib/utils';import { ghostPermissionItems } from '../../../shared/ghost';import type { PluginMarketDetail } from '../../../shared/pluginMarket';import { GhostPluginIcon } from './GhostPluginIcon';import { pluginPresentationOrigin } from './lib/pluginMarketPresentation';+import { PluginDetailTopBar, usePluginDetailScrolled } from './PluginDetailTopBar';interface MarketPluginDetailViewProps {detail: PluginMarketDetail;@@ -24,6 +24,7 @@ export function MarketPluginDetailView({onIconLoadError,}: MarketPluginDetailViewProps) {const { t } = useTranslation();+ const { scrolled, onScroll } = usePluginDetailScrolled();const permissions = ghostPermissionItems(detail.manifest);const presentationOrigin = pluginPresentationOrigin(detail);const actionKey =@@ -38,18 +39,16 @@ export function MarketPluginDetailView({busy || detail.installState === 'installed' || detail.installState === 'conflict';return (- <main className="plugin-motion-root h-full min-h-0 w-full overflow-y-auto bg-[var(--surface)] [scrollbar-gutter:stable_both-edges]">+ <main+ className="plugin-motion-root h-full min-h-0 w-full overflow-y-auto bg-[var(--surface)] [scrollbar-gutter:stable_both-edges]"+ onScroll={onScroll}+ >+ <PluginDetailTopBar+ label={t('settings.ghosts.detail.backToList')}+ onBack={onBack}+ scrolled={scrolled}+ /><article className="plugin-detail-frame mx-auto w-full max-w-[824px] px-8 pb-16 pt-5 max-[760px]:px-6">- <button- type="button"- onClick={onBack}- className="-ml-3 mb-7 inline-flex h-9 items-center gap-2 rounded-full px-3 text-13 text-[var(--text-secondary)] transition-colors duration-150 hover:bg-[var(--surface-hover-soft)] hover:text-[var(--text-primary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]"- style={WINDOW_NO_DRAG_STYLE}- >- <ArrowLeft size={16} aria-hidden="true" />- {t('settings.ghosts.detail.backToList')}- </button>-<header><div className="plugin-detail-hero grid grid-cols-[64px_minmax(0,1fr)_auto] items-center gap-3"><GhostPluginIcondiff --git a/apps/desktop/src/renderer/features/plugin/PluginDetailTopBar.tsx b/apps/desktop/src/renderer/features/plugin/PluginDetailTopBar.tsxnew file mode 100644index 0000000000..7259659385--- /dev/null+++ b/apps/desktop/src/renderer/features/plugin/PluginDetailTopBar.tsx@@ -0,0 +1,98 @@+/**+ * Shared sticky top bar for both Plugin detail surfaces (installed + market).+ *+ * Inputs: the back affordance's label and handler, plus the owning scroll frame's scrolled flag.+ * Outputs: the back button and, on macOS, the page's own window-drag region.+ * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md+ */++import { useCallback, useState, type UIEvent } from 'react';+import { ArrowLeft } from 'lucide-react';++import { WINDOW_DRAG_STYLE, WINDOW_NO_DRAG_STYLE } from '@/components/layout/windowDrag';+import { useMacFullscreen } from '@/hooks/useMacFullscreen';+import { cn } from '@/lib/utils';++interface PluginDetailTopBarProps {+ label: string;+ onBack: () => void;+ /** 滚动帧是否已离开顶部;顶栏据此从透明切到实底 + hairline。 */+ scrolled: boolean;+}++/**+ * 详情页滚动帧的「已离开顶部」判定。返回的 onScroll 直接挂在滚动容器上;+ * scrollTop > 0 是布尔量,同值 setState 由 React bail out,重渲染只发生在+ * 跨越顶部的那一次。+ */+export function usePluginDetailScrolled(): {+ scrolled: boolean;+ onScroll: (event: UIEvent<HTMLElement>) => void;+} {+ const [scrolled, setScrolled] = useState(false);+ const onScroll = useCallback((event: UIEvent<HTMLElement>) => {+ setScrolled(event.currentTarget.scrollTop > 0);+ }, []);+ return { scrolled, onScroll };+}++/**+ * 详情页顶行:返回入口 + mac 侧的窗口拖拽区。+ *+ * mac 上通用 ContentHeader 在「侧栏展开 + 无注入内容 + 无右栏」时整条隐藏+ * (ContentHeader.tsx 的 useContentHeaderHidden),自带顶部内容的页面自行承担+ * 窗口拖动(windowDrag.tsx 的约定),本行是插件详情页的那一份。Windows /+ * Linux 的通用 header 常驻,那 46px 即窗口抓手,本行在这两端纯作视觉顶栏。+ * 行内交互元素标 no-drag 挖洞,且必须是本行的后代 —— Electron 的挖洞只在+ * drag 元素自身后代上生效。+ *+ * sticky 让拖拽区在任意滚动位置都在场。滚动态为实底:正文滚到本行下方会落进+ * Electron 的 drag 矩形,实底背景同时把这些元素遮住,视觉与命中区一致。+ *+ * 高度 h-16 + 内容垂直居中,常规宽度下与列表页 PluginManagementHeader 同规格+ * (PluginManagementLayout.tsx:212),列表与详情切换时顶栏高度恒定。主面板窄到+ * 720px 以内时列表页顶栏排成工具行 + 页签行、撑到 7rem(plugin-motion.css 的+ * container query,作用域是列表页的 plugin-management-layout-root);本行只承载+ * 返回入口一个控件,各宽度下恒为 h-16。+ *+ * hairline 走 after 伪元素,脱离布局流,透明态与实底态之间高度恒定;article 的+ * pt-5 之下,hero 起点为 64 + 20 = 84px。+ *+ * hairline 只画在 mac:那里 ContentHeader 整条隐藏,本行的 hairline 是顶栏与正文+ * 之间唯一的边界。Windows / Linux 的 ContentHeader 常驻且自带 border-b,其+ * --titlebar-border 是 --border-default 的 alias(cindy-light.ts:127 /+ * cindy-dark.ts:131,两端同值),两条线同时出现即为一片 --surface 上相隔 64px 的+ * 两条同色平行线;那两端由 ContentHeader 的下边框充当顶部分隔,本行只留实底。+ */+export function PluginDetailTopBar({ label, onBack, scrolled }: PluginDetailTopBarProps) {+ const { isMac } = useMacFullscreen();++ return (+ <div+ data-testid="plugin-detail-top-bar"+ className={cn(+ 'sticky top-0 z-20 w-full',+ 'transition-[background-color] duration-[var(--motion-fast,150ms)] motion-reduce:transition-none',+ scrolled ? 'bg-[var(--surface)]' : 'bg-transparent',+ isMac && [+ 'after:pointer-events-none after:absolute after:inset-x-0 after:bottom-0 after:h-px after:bg-[var(--border-default)]',+ 'after:transition-opacity after:duration-[var(--motion-fast,150ms)] motion-reduce:after:transition-none',+ scrolled ? 'after:opacity-100' : 'after:opacity-0',+ ],+ )}+ style={isMac ? WINDOW_DRAG_STYLE : undefined}+ >+ <div className="mx-auto flex h-16 w-full max-w-[824px] items-center px-8 max-[760px]:px-6">+ <button+ type="button"+ onClick={onBack}+ className="-ml-3 inline-flex h-9 w-fit select-none items-center gap-2 rounded-full px-3 text-13 text-[var(--text-secondary)] transition-colors duration-[var(--motion-fast,150ms)] hover:bg-[var(--surface-hover-soft)] hover:text-[var(--text-primary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]"+ style={WINDOW_NO_DRAG_STYLE}+ >+ <ArrowLeft size={16} aria-hidden="true" />+ {label}+ </button>+ </div>+ </div>+ );+}diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginDetailSections.test.tsx b/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginDetailSections.test.tsxindex b76a24c102..36cdcf4438 100644--- a/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginDetailSections.test.tsx+++ b/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginDetailSections.test.tsx@@ -152,13 +152,20 @@ describe('Ghost plugin detail sections', () => {const scrollSurface = container.querySelector('main');const detailFrame = container.querySelector('article');- const backButton = detailFrame?.querySelector(':scope > button');+ // 返回按钮住在吸顶顶栏里(mac 的窗口拖拽区)。顶栏内层复用同一条 824px+ // 内容框,与正文左缘对齐。+ const topBar = container.querySelector('[data-testid="plugin-detail-top-bar"]');+ const topBarFrame = topBar?.querySelector(':scope > div');+ const backButton = topBar?.querySelector('button');const detailHero = detailFrame?.querySelector('.plugin-detail-hero');const detailActions = detailFrame?.querySelector('.plugin-detail-actions');expect(scrollSurface?.className).toContain('[scrollbar-gutter:stable_both-edges]');expect(detailFrame?.className).toContain('plugin-detail-frame');expect(detailFrame?.className).toContain('mx-auto');expect(detailFrame?.className).toContain('max-w-[824px]');+ expect(topBar?.className).toContain('sticky');+ expect(topBarFrame?.className).toContain('mx-auto');+ expect(topBarFrame?.className).toContain('max-w-[824px]');expect(backButton?.className).toContain('-ml-3');expect(detailHero?.className).toContain('grid-cols-[64px_minmax(0,1fr)_auto]');expect(detailActions?.className).toContain('flex-nowrap');diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/PluginDetailTopBar.test.tsx b/apps/desktop/src/renderer/features/plugin/__tests__/PluginDetailTopBar.test.tsxnew file mode 100644index 0000000000..b77c957613--- /dev/null+++ b/apps/desktop/src/renderer/features/plugin/__tests__/PluginDetailTopBar.test.tsx@@ -0,0 +1,147 @@+/**+ * Regression coverage for the Plugin detail sticky top bar.+ *+ * 这条顶栏是 mac 上插件详情页的窗口拖拽区(通用 ContentHeader 在「侧栏展开 ++ * 无注入内容 + 无右栏」时整条隐藏);Windows / Linux 的通用 header 常驻,拖拽+ * 区归它。本文件锁住这个平台分流与顶栏的吸顶几何。+ * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md+ * @vitest-environment jsdom+ */++import { fireEvent, render, screen } from '@testing-library/react';+import { afterEach, describe, expect, it, vi } from 'vitest';++import { PluginDetailTopBar, usePluginDetailScrolled } from '../PluginDetailTopBar';++/** jsdom 下 `-webkit-app-region` 只能从 React 写进 style 对象的驼峰键读回。 */+function appRegionOf(element: HTMLElement): string {+ return (element.style as CSSStyleDeclaration & { WebkitAppRegion?: string }).WebkitAppRegion ?? '';+}++afterEach(() => {+ vi.unstubAllGlobals();+ Reflect.deleteProperty(window, 'electronAPI');+});++function stubPlatform(platform: 'darwin' | 'win32' | 'linux') {+ vi.stubGlobal('electronAPI', {+ platform,+ getFullscreenState: () => Promise.resolve(false),+ onFullscreenChange: () => () => {},+ });+}++/** 滚动容器 + 顶栏的最小宿主,复刻两个详情视图的接线方式。 */+function Harness({ onBack = () => {} }: { onBack?: () => void }) {+ const { scrolled, onScroll } = usePluginDetailScrolled();+ return (+ <main data-testid="scroll-frame" onScroll={onScroll}>+ <PluginDetailTopBar label="Back" onBack={onBack} scrolled={scrolled} />+ </main>+ );+}++describe('PluginDetailTopBar', () => {+ it('carries the window drag region on macOS and keeps the back button clickable', () => {+ stubPlatform('darwin');+ const onBack = vi.fn();++ render(<Harness onBack={onBack} />);++ const bar = screen.getByTestId('plugin-detail-top-bar');+ expect(appRegionOf(bar)).toBe('drag');++ // Electron 的挖洞只在 drag 元素自身后代上生效(ContentHeader.tsx /+ // FileTabsBar.tsx 都记过这条),所以返回按钮必须落在本行内部。+ const back = screen.getByRole('button', { name: 'Back' });+ expect(bar.contains(back)).toBe(true);+ expect(appRegionOf(back)).toBe('no-drag');++ fireEvent.click(back);+ expect(onBack).toHaveBeenCalledTimes(1);+ });++ it.each(['win32', 'linux'] as const)(+ 'leaves the drag region to the shared ContentHeader on %s',+ (platform) => {+ stubPlatform(platform);++ render(<Harness />);++ const bar = screen.getByTestId('plugin-detail-top-bar');+ expect(appRegionOf(bar)).toBe('');+ },+ );++ it.each(['win32', 'linux'] as const)(+ 'leaves the top separator to the shared ContentHeader on %s',+ (platform) => {+ stubPlatform(platform);++ render(<Harness />);++ // 这两端 ContentHeader 常驻且自带 border-b(--titlebar-border 与+ // --border-default 同值),本行只留实底,顶部分隔由那条下边框承担。+ const bar = screen.getByTestId('plugin-detail-top-bar');+ expect(bar.className).not.toContain('after:');++ const frame = screen.getByTestId('scroll-frame');+ Object.defineProperty(frame, 'scrollTop', { value: 24, configurable: true });+ fireEvent.scroll(frame);+ expect(bar.className).toContain('bg-[var(--surface)]');+ expect(bar.className).not.toContain('after:');+ },+ );++ it.each(['darwin', 'win32', 'linux'] as const)('sticks to the top on %s', (platform) => {+ stubPlatform(platform);++ render(<Harness />);++ // 吸顶三端一致,返回入口常驻;平台分流只作用于 drag。+ const bar = screen.getByTestId('plugin-detail-top-bar');+ expect(bar.className).toContain('sticky');++ const frame = screen.getByTestId('scroll-frame');+ Object.defineProperty(frame, 'scrollTop', { value: 24, configurable: true });+ fireEvent.scroll(frame);+ expect(bar.className).toContain('bg-[var(--surface)]');+ });++ it('matches the catalog header height at regular pane widths', () => {+ stubPlatform('darwin');++ render(<Harness />);++ // 列表与详情是同一条顶栏的两个状态,几何取自 PluginManagementLayout.tsx+ // 的 PluginManagementHeader(h-16 + flex h-full items-center)。列表页在+ // 720px 以内排两行撑到 7rem,那条 container query 的作用域是列表页根节点,+ // 本行各宽度下恒为 h-16。+ const frame = screen.getByTestId('plugin-detail-top-bar').firstElementChild;+ expect(frame?.className).toContain('h-16');+ expect(frame?.className).toContain('items-center');+ });++ it('turns opaque only after the frame leaves the top', () => {+ stubPlatform('darwin');++ render(<Harness />);++ const bar = screen.getByTestId('plugin-detail-top-bar');+ // 顶部静止态:透明背景,hairline 隐藏。+ expect(bar.className).toContain('bg-transparent');+ expect(bar.className).toContain('after:opacity-0');++ const frame = screen.getByTestId('scroll-frame');+ Object.defineProperty(frame, 'scrollTop', { value: 24, configurable: true });+ fireEvent.scroll(frame);++ // 滚动态为实底:落进 drag 矩形的正文元素同时被背景遮住,视觉与命中区一致。+ expect(bar.className).toContain('bg-[var(--surface)]');+ expect(bar.className).toContain('after:opacity-100');++ Object.defineProperty(frame, 'scrollTop', { value: 0, configurable: true });+ fireEvent.scroll(frame);+ expect(bar.className).toContain('bg-transparent');+ });+});