Files
apes-sidebar/src/client/ui/kit.tsx
T
Menghuan1918 36fbc5ac7e feat(sidebar): 文件页与文件变动页 UIUX 重构 + 全局组件抽取
文件页(FileTree/TreePanel)
- Ctrl/Cmd 多选 + Shift 按可见行序连选(Esc/点空白/右键收敛),批量条支持复制路径、批量删除(共享 ConfirmDialog + 顺序 fsRemove)
- Git 变更着色:行名按状态上色 + M/A/D/U 徽标,目录按 dirHasChanges 着色,非仓库静默降级(数据来自共享 git 状态存储)
- 新建文件夹:fs.mkdir 路由 + mkdirWorkspaceEntry + 内联输入行(Enter/Esc/blur/IME 守卫)
- 性能:FileRow/DirRow memo(含反向验证)、搜索 hidden 停车不再卸载树、level 拉取世代守卫 + AbortController、fs.tree truncated 提示、use-dir-watch 入参 memo
- 拖拽上传视觉 token 化(硬编码色清零);可见性下传后隐藏页签停止轮询
- 右键「打开方式」改为复用 DSH 自带 open-in-app(宿主探测的关联应用 + 文件管理器显示)

文件变动页(changes/diff)
- 36px 头(宿主 SegmentedControl)+ 单一 ChangeRow + SectionHeader 分组 + 吸底提交条单状态行 + 历史独立空态
- 修掉:双份空态、暂存失败 unhandled rejection、手动刷新被丢、仓库切换刷新两次、worktree 清单缺 repoRoot、工作树被自动切走、预览持旧快照、恢复高度未 clamp、session ops 无谓轮询
- DiffPane/DiffTab 共用 use-git-diff;修掉 DiffPane 的 untracked 预览从不渲染

全局组件与宿主接入
- 新增 src/client/ui(IconButton/Chip/SectionHeader/Notice/ConfirmDialog/StatusBadge + 共享 git 状态存储)
- 新增 src/client/open-in-app.ts(宿主 open-in-app 客户端适配),删除自研 open-with 全链路与 open.external 路由
- 客户端 inject 补 remote / remote.session:缺声明时 ctx.get('remote').session 会抛出并把整个面板打成错误条(真实挂载 lane 抓到)
- 词典:+25 键 / -20 openWith* / -noChanges,20 份同步

验证:typecheck / lint / test(126 文件 1322 通过)/ build 全绿;
DSH_CMD='npx -y --package @deepseek-ai/dsh@0.1.7-rc.1 dsh' pnpm test:mount 7/7 通过(含 tab sweep 与 perf lane)
2026-09-28 00:27:31 +08:00

189 lines
6.3 KiB
TypeScript

/**
* The plugin's GLOBAL UI atoms — the one place the files page, the changes
* page, the tasks page and every future page take their row chrome, badges,
* state lines and confirmations from.
*
* Why they exist: the repo carried 14 duplicated empty/error/hint classes
* across four stylesheets (two of them byte-identical), two copies of the
* Cancel/Confirm modal, five icon-button recipes (including a class-NAME
* collision: `.iconButton` was a 28px circle in one sheet and a 24px square
* in another) and five chip/toggle recipes. These components own those
* pictures ONCE, cut to the plugin's native scale (see
* `docs/plans/2026-09-27-files-changes-uiux.md` §1): 12px body, 11px meta,
* 28px controls/rows, 2/3/4/8px radii, one accent.
*
* Skin contract: every paint comes from `kit.module.css` and resolves to a
* `--dsw-*` / `--ds-*` token (`tests/theme.spec.ts` scans the sheet).
*/
import { type MouseEvent, type ReactNode } from 'react'
import clsx from 'clsx'
import { Button, Modal } from '@deepseek-ai/dsh-client-ui-primitives'
import css from './kit.module.css'
/**
* A 28px (`md`) or 24px (`sm`) square glyph button — the ONE icon button of
* the plugin. Callers that need a pressed state pass `active`; the danger
* tone only recolors the glyph/hover, never the geometry.
*/
export function IconButton(props: {
icon: ReactNode
/** Accessible name; also the default hover title. */
label: string
title?: string
onClick(event: MouseEvent<HTMLButtonElement>): void
size?: 'md' | 'sm'
active?: boolean
disabled?: boolean
danger?: boolean
className?: string | undefined
}): ReactNode {
const { icon, label, title, onClick, size = 'md', active, disabled, danger } = props
return (
<button
type="button"
className={clsx(css.iconButton, size === 'sm' ? css.iconButtonSm : css.iconButtonMd,
active === true && css.iconButtonActive, danger === true && css.iconButtonDanger, props.className)}
aria-label={label}
title={title ?? label}
disabled={disabled}
aria-pressed={active}
onClick={(event) => { onClick(event) }}
>
{icon}
</button>
)
}
/**
* A small toggle chip (filters, list switches). `count` renders as a trailing
* figure in the meta rung; the chip's rest / hover / selected states are three
* different pictures (a bare fill swap reads as hover).
*/
export function Chip(props: {
children: ReactNode
active?: boolean
count?: number
title?: string
disabled?: boolean
onClick(): void
className?: string | undefined
}): ReactNode {
return (
<button
type="button"
className={clsx(css.chip, props.active === true && css.chipActive, props.className)}
data-active={props.active === true ? 'true' : undefined}
aria-pressed={props.active === true}
title={props.title}
disabled={props.disabled}
onClick={() => { props.onClick() }}
>
<span className={css.chipLabel}>{props.children}</span>
{props.count !== undefined && <span className={css.chipCount}>{props.count}</span>}
</button>
)
}
/**
* A 28px section band: a label (with an optional count) that may carry ONE
* trailing action. The hairline under it is the page's only section divider.
*/
export function SectionHeader(props: {
label: ReactNode
count?: number
action?: ReactNode
className?: string | undefined
children?: ReactNode
}): ReactNode {
return (
<div className={clsx(css.sectionHeader, props.className)}>
<span className={css.sectionLabel}>{props.label}</span>
{props.count !== undefined && <span className={css.sectionCount}>{props.count}</span>}
{props.children}
{props.action !== undefined && <span className={css.sectionAction}>{props.action}</span>}
</div>
)
}
/**
* The plugin's state lines: empty / loading / error / warn / hint.
* `tone` picks the geometry (`page` = centered 16px block, `well` = the
* compact 4/12/8 line inside a list, `inline` = 10px micro copy).
*/
export function Notice(props: {
kind: 'empty' | 'loading' | 'error' | 'warn' | 'hint'
tone?: 'page' | 'well' | 'inline'
role?: string
className?: string | undefined
children: ReactNode
}): ReactNode {
const tone = props.tone ?? 'well'
return (
<div
className={clsx(css.notice, tone === 'page' ? css.noticePage : tone === 'inline' ? css.noticeInline : css.noticeWell,
props.kind === 'error' && css.noticeError, props.kind === 'warn' && css.noticeWarn,
(props.kind === 'hint' || props.kind === 'loading') && css.noticeHint, props.className)}
data-kind={props.kind}
role={props.role ?? (props.kind === 'error' ? 'alert' : undefined)}
>
{props.children}
</div>
)
}
/**
* The ONE confirmation dialog: a quiet single-question body and a
* Cancel/Confirm footer, with `busy` locking both actions while the action
* runs. Destructive callers pass `danger` so the primary button reads as one.
*/
export function ConfirmDialog(props: {
open: boolean
title: string
description: string
confirmLabel: string
cancelLabel: string
danger?: boolean
busy?: boolean
onConfirm(): void
onClose(): void
}): ReactNode {
return (
<Modal
open={props.open}
onClose={props.onClose}
title={props.title}
closeLabel={props.cancelLabel}
footer={(
<>
<Button variant="outline" disabled={props.busy} onClick={props.onClose}>{props.cancelLabel}</Button>
<Button variant="primary" disabled={props.busy} onClick={props.onConfirm}>{props.confirmLabel}</Button>
</>
)}
>
<p className={css.confirmDesc} data-danger={props.danger === true ? 'true' : undefined}>{props.description}</p>
</Modal>
)
}
/**
* The status vocabulary shared by git rows, session-op rows and diff kinds.
* `neutral` is the fallback for a kind the caller has no tone for.
*/
export type StatusTone =
| 'modified' | 'added' | 'deleted' | 'untracked' | 'renamed'
| 'conflict' | 'read' | 'write' | 'edit' | 'neutral'
/** A compact status badge: a git letter, an op kind, a diff tag. */
export function StatusBadge(props: {
tone: StatusTone
title?: string
className?: string | undefined
children: ReactNode
}): ReactNode {
return (
<span className={clsx(css.statusBadge, props.className)} data-tone={props.tone} title={props.title}>
{props.children}
</span>
)
}