feat(git-graph): 图谱视图与统一的底部面板(详情 / 内容 / 差异)
**图谱视图**(`GitGraphLens`):分支下拉框只筛选历史,不做任何写操作;提交行 是一行 28px——泳道连线 + 引用徽章 + 标题。徽章带图标(本地分支 = 分支图标、 远程跟踪分支 = 地球),`HEAD` 不单独成徽章,而是折叠进当前分支的徽章里做前置 ✓;徽章的颜色就是它所在车道的颜色,和连线、圆点走同一个五色映射。行上不再 有短 hash 与作者时间:hover 350 ms 弹一张中等密度的卡片(标题、徽章、作者· 相对时间、短 hash + 绝对日期),点击后看到的「详情」才是完整信息(完整 hash、 父提交、Markdown 正文)。列表到底自动加载下一页(IntersectionObserver + 在飞守卫),并保留手动按钮作为兜底。 **底部面板**:三个视角共用同一个可拖拽区域,标签集合**固定**为 `提交详情 / 内容 / 差异`,不随上方视角或选中项变化;没有内容的标签显示空态 (未选择提交 / 读取没有差异 / 此视图暂无内容)而不是消失——此前按选中项推导 标签集合,同一个面板看起来像三个不同的面板。选择、高度、激活标签都持久化。 **内容视图**:操作记录(read 的带行号源码;md/html/pdf 用插件自己的渲染器) 与 git 工作区文件(`fs.read` 读文件本身,二进制/超大走既有下载面板)并列。 读取是懒加载的:只为看 diff 打开文件时不会去读整个文档。md 默认渲染,html 默认源码、点了才渲染 iframe(沿用「选中不自动加载 iframe」的沙箱契约)。 **配色**:五个色槽全部用状态色令牌(business/success/warn/error + 次级灰)。 原来槽位 0 用 `brand-primary`,实测在深色主题下是 rgb(15,17,21),主线几乎 不可见——状态色是给细线和小字设计的,两种主题下都能读。 顺带:Git 视角把当前仓库 / 工作树报给父组件(`onTargetChange`),图谱与预览 才能跟着同一个目标走。 测试:`tests/git-graph-ui.spec.tsx`(19 项:请求时机、错误与重试、分页游标、 竞态与中止、行结构、HEAD 折叠、hover 卡片、自动加载)、`tests/changes-tab.spec.tsx` (固定三标签在各视角一致、内容视图懒加载、箭头键在标签间移动)、 `tests/markdown-surface.spec.tsx`(内容视图里的 markdown 链接认领)。
This commit is contained in:
1 parent
ff373c81ed
commit
a64f5cd8e9
30 files changed
+2357
-237
No files matched your search
+314
-127
@@ -3,16 +3,24 @@
|
||||
* worktree change, a commit patch, or a session file op — rendered through
|
||||
* the unified diff stack (the same one the diff tab uses). Git targets load
|
||||
* through the shared {@link useGitDiffTarget} hook (refreshable, with the
|
||||
* untracked full-addition fallback); op targets are pure snapshots (diff /
|
||||
* read view / error text). The pane is resizable by drag (clamped; the
|
||||
* height commits to the tab's persisted meta on release) and by keyboard;
|
||||
* git targets can expand into a dedicated diff tab via the shell.
|
||||
* untracked full-addition fallback); op targets are pure snapshots. The pane
|
||||
* is resizable by drag (clamped; the height commits to the tab's persisted
|
||||
* meta on release) and by keyboard; git targets can expand into a dedicated
|
||||
* diff tab via the shell.
|
||||
*
|
||||
* The pane's views are TABS, one per question: `content` answers "what is in
|
||||
* the file" (every read op, and the rendered view for md/html/pdf ops — the
|
||||
* plugin's renderers no longer hide behind a toggle inside the diff view),
|
||||
* `diff` answers "what changed" (git targets, write/edit ops), and extra
|
||||
* views the caller hosts (the graph commit's `details` card) sit ahead of
|
||||
* both. A read op has no `diff` tab — nothing changed. With one or zero tabs
|
||||
* the pane is byte-for-byte the strip-less preview of before.
|
||||
*/
|
||||
import { useEffect, useMemo, useRef, useState, type PointerEvent as ReactPointerEvent } from 'react'
|
||||
import { useEffect, useMemo, useRef, useState, type PointerEvent as ReactPointerEvent, type ReactNode } from 'react'
|
||||
import { IconCloseOutlineRegular, IconRefreshOutlineRegular, IconRightUpOutlineRegular, MarkdownDelegateProvider, MarkdownText } from '@deepseek-ai/dsh-client-ui-primitives'
|
||||
import type { Context } from '../../context-types.ts'
|
||||
import type { SessionScope } from '../api.ts'
|
||||
import { htmlUrl } from '../api.ts'
|
||||
import { api, htmlUrl } from '../api.ts'
|
||||
import { hostTransportBase } from '../desktop-env.ts'
|
||||
import { t } from '../locales.ts'
|
||||
import { baseName } from '../paths.ts'
|
||||
@@ -21,6 +29,7 @@ import { HTML_IFRAME_SANDBOX } from '../html-preview.ts'
|
||||
import type { SidebarDiffRef, SidebarTab } from '../state.ts'
|
||||
import { DiffRows, ReadRows } from '../diff/DiffRows.tsx'
|
||||
import { PdfView } from '../PdfView.tsx'
|
||||
import { BinaryDownload } from '../binary-download.tsx'
|
||||
import { DiffFiles } from '../diff/DiffFiles.tsx'
|
||||
import { langOfPath } from '../diff/highlight.ts'
|
||||
import { buildDiffSegments, diffLines, diffStats, parseUnifiedDiff, unifiedSegments, type DiffRow } from '../diff/rows.ts'
|
||||
@@ -105,6 +114,55 @@ function PaneToggle(props: { on: boolean; label: string; title?: string; onClick
|
||||
return <Chip active={props.on} title={props.title} onClick={props.onClick}>{props.label}</Chip>
|
||||
}
|
||||
|
||||
/** One tab of the pane's optional strip. */
|
||||
export interface PaneTab {
|
||||
readonly id: string
|
||||
readonly label: string
|
||||
}
|
||||
|
||||
/**
|
||||
* A compact tab strip — a real tablist with roving focus: the active tab is
|
||||
* the only tab stop, and Left/Right/Home/End move focus AND selection (the
|
||||
* standard automatic-activation model). Born as the bottom pane's strip
|
||||
* (details / diff); the changes tab's header reuses it for the lens switcher
|
||||
* so the page's two switchers read as one component. Rendered only when the
|
||||
* caller hosts more than one view, so a diff-only preview never grows a strip.
|
||||
*/
|
||||
export function PaneTabStrip(props: { tabs: readonly PaneTab[]; active: string; onSelect(id: string): void; className?: string; label?: string }) {
|
||||
const buttons = useRef<(HTMLButtonElement | null)[]>([])
|
||||
const move = (to: number): void => {
|
||||
const count = props.tabs.length
|
||||
if (count === 0) return
|
||||
const index = ((to % count) + count) % count
|
||||
props.onSelect(props.tabs[index]!.id)
|
||||
buttons.current[index]?.focus()
|
||||
}
|
||||
return (
|
||||
<div className={props.className === undefined ? css.paneTabs : `${css.paneTabs} ${props.className}`}
|
||||
role="tablist" aria-label={props.label}>
|
||||
{props.tabs.map((tab, index) => (
|
||||
<button
|
||||
key={tab.id}
|
||||
ref={(node) => { buttons.current[index] = node }}
|
||||
type="button"
|
||||
role="tab"
|
||||
className={css.paneTab}
|
||||
data-active={tab.id === props.active ? 'true' : undefined}
|
||||
aria-selected={tab.id === props.active}
|
||||
tabIndex={tab.id === props.active ? 0 : -1}
|
||||
onClick={() => { props.onSelect(tab.id) }}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === 'ArrowRight') { event.preventDefault(); move(index + 1) }
|
||||
else if (event.key === 'ArrowLeft') { event.preventDefault(); move(index - 1) }
|
||||
else if (event.key === 'Home') { event.preventDefault(); move(0) }
|
||||
else if (event.key === 'End') { event.preventDefault(); move(props.tabs.length - 1) }
|
||||
}}
|
||||
>{tab.label}</button>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** The reading-mode body of one markdown op target: the shared MarkdownText
|
||||
* pass (local image destinations already rewritten to the media route by
|
||||
* the caller). Mermaid fences render through the same chunk-resident
|
||||
@@ -174,14 +232,103 @@ export interface DiffPaneProps {
|
||||
onClose: () => void
|
||||
/** Expand the current git target into a dedicated diff tab. */
|
||||
onExpand: () => void
|
||||
/** The pane's views. The host may PIN the set (the changes tab pins
|
||||
* details/content/diff so the panel is identical in every lens; a pinned
|
||||
* id with nothing to show renders its empty state instead of vanishing).
|
||||
* Omitted, the set is composed from what this target actually offers. */
|
||||
tabs?: readonly PaneTab[]
|
||||
/** Bodies for ids the pane does not build itself (the caller's views). */
|
||||
bodies?: Readonly<Record<string, ReactNode>>
|
||||
/** The active tab id; an id not listed lands on the built-in home. */
|
||||
activeTab?: string
|
||||
onSelectTab?(id: string): void
|
||||
}
|
||||
|
||||
export function DiffPane({ target, ctx, scope, height, onHeightCommit, onClose, onExpand }: DiffPaneProps) {
|
||||
/** One tab's "nothing here" body — a page-level empty notice. */
|
||||
function PaneEmpty({ text }: { text: string }) {
|
||||
return <div className={css.paneBody}><Notice kind="empty" tone="page">{text}</Notice></div>
|
||||
}
|
||||
|
||||
export function DiffPane({ target, ctx, scope, height, onHeightCommit, onClose, onExpand, tabs, bodies, activeTab, onSelectTab }: DiffPaneProps) {
|
||||
// ── Git target loading (the shared loader: staged-side fallback, the
|
||||
// untracked full-addition fallback, refresh by tick, fold cache). ─────
|
||||
const gitRef = target.kind === 'git' ? target.ref : null
|
||||
/** The git target when it is a WORKTREE file (the only git target with a
|
||||
* content view, and the only one carrying a `path`). */
|
||||
const gitWorktree = gitRef !== null && gitRef.kind === 'worktree' ? gitRef : null
|
||||
const { loading, error, diffText, untracked, refresh, resolveFold } = useGitDiffTarget(gitRef, scope)
|
||||
|
||||
// ── The pane's views, resolved BEFORE anything loads: which tabs exist and
|
||||
// which one is on screen. Computed from raw target facts (`kind` and
|
||||
// `isError` do not change under redaction), so the loaders below can
|
||||
// defer their work for views that are not on screen. ──────────────────
|
||||
/** The path the content view is about: a worktree file's, or an op's. */
|
||||
const targetPath = gitWorktree !== null ? gitWorktree.path : target.kind === 'op' ? target.path : ''
|
||||
/** A target whose content view may RENDER: a non-error op, or a worktree
|
||||
* file (the plugin's renderers are the reason the content tab exists). */
|
||||
const renderable = (target.kind === 'op' && !target.op.isError) || gitWorktree !== null
|
||||
const mdOp = renderable && /\.(md|markdown|mdx)$/i.test(targetPath)
|
||||
const htmlOp = renderable && /\.(html?)$/i.test(targetPath)
|
||||
const pdfOp = renderable && /\.pdf$/i.test(targetPath)
|
||||
/** Source vs rendered inside the CONTENT tab. Markdown starts rendered (the
|
||||
* sanitized MarkdownText is the point of the tab); html starts on SOURCE —
|
||||
* selecting a row must never auto-load an iframe without an explicit click
|
||||
* (the sandbox spec pins this). */
|
||||
const [contentRaw, setContentRaw] = useState(htmlOp)
|
||||
const opKind = target.kind === 'op' ? target.op.kind : null
|
||||
const opError = target.kind === 'op' && target.op.isError
|
||||
/** What this target can offer: every read op has a content view, md/html/pdf
|
||||
* ops have one whatever they did, and a git WORKTREE file has one too (the
|
||||
* file itself, next to its patch). */
|
||||
const hasContentTab = target.kind === 'git'
|
||||
? target.ref.kind === 'worktree'
|
||||
: opKind !== null && !opError && (opKind === 'read' || mdOp || htmlOp || pdfOp)
|
||||
const hasDiffTab = target.kind === 'git' || (opKind !== null && (opKind !== 'read' || opError))
|
||||
/** The host may PIN the tab set (the changes tab pins details/content/diff
|
||||
* so the panel is identical in every lens); otherwise the set is composed
|
||||
* from what this target offers. An unlisted / absent active id lands on the
|
||||
* built-in home (`diff`, else `content`, else the first pinned view). */
|
||||
const allTabs: PaneTab[] = tabs !== undefined
|
||||
? [...tabs]
|
||||
: [
|
||||
...(hasContentTab ? [{ id: 'content', label: t('changesContentTab') }] : []),
|
||||
...(hasDiffTab ? [{ id: 'diff', label: t('changesDiffTab') }] : []),
|
||||
]
|
||||
const hasStrip = allTabs.length > 1
|
||||
const active = activeTab !== undefined && allTabs.some(tab => tab.id === activeTab)
|
||||
? activeTab
|
||||
: hasDiffTab ? 'diff' : hasContentTab ? 'content' : allTabs[0]?.id ?? 'diff'
|
||||
const activeExtra = active !== 'diff' && active !== 'content'
|
||||
|
||||
// ── The `content` tab of a GIT target: the worktree file itself (the diff
|
||||
// tab answers "what changed"; this one answers "what is in it"). Loaded
|
||||
// lazily — only while the content view is actually on screen — through
|
||||
// the same `fs.read` the editor uses, with the same path resolution the
|
||||
// diff loader applies to a worktree file. ──────────────────────────────
|
||||
const [gitContent, setGitContent] = useState<
|
||||
{ status: 'idle' | 'loading' | 'binary' | 'large' } | { status: 'text'; text: string } | { status: 'error'; error: string }
|
||||
>({ status: 'idle' })
|
||||
useEffect(() => {
|
||||
if (gitWorktree === null) { setGitContent({ status: 'idle' }); return }
|
||||
// Deferred until the content view is the one on screen: opening a file to
|
||||
// read its DIFF must not pull the whole document.
|
||||
if (active !== 'content') return
|
||||
const controller = new AbortController()
|
||||
setGitContent({ status: 'loading' })
|
||||
api.fsRead(scope, resolveSidebarPath(gitWorktree.repoRoot ?? gitWorktree.worktree ?? scope.cwd, gitWorktree.path), controller.signal)
|
||||
.then((result) => {
|
||||
if (controller.signal.aborted) return
|
||||
if (result.kind === 'text') setGitContent({ status: 'text', text: result.content })
|
||||
else if (result.kind === 'binary') setGitContent({ status: 'binary' })
|
||||
else setGitContent({ status: 'large' })
|
||||
})
|
||||
.catch((reason: unknown) => {
|
||||
if (controller.signal.aborted) return
|
||||
setGitContent({ status: 'error', error: reason instanceof Error ? reason.message : String(reason) })
|
||||
})
|
||||
return () => { controller.abort() }
|
||||
}, [gitWorktree, scope, active])
|
||||
|
||||
// ── Op target material (pure snapshots; the prior content came with the
|
||||
// target so a running op shows what is already known). ────────────────
|
||||
const opRaw = target.kind === 'op' ? target.op : null
|
||||
@@ -239,14 +386,13 @@ export function DiffPane({ target, ctx, scope, height, onHeightCommit, onClose,
|
||||
[op],
|
||||
)
|
||||
|
||||
// ── Markdown reading mode: .md op targets (read/write/edit, non-error)
|
||||
// toggle between the raw/diff view and the rendered document — the same
|
||||
// shared MarkdownText pass the editor preview uses, with local image
|
||||
// destinations rewritten through the /sidebar/file media route. ──────
|
||||
const mdOp = target.kind === 'op' && !target.op.isError && /\.(md|markdown|mdx)$/i.test(target.path)
|
||||
const [reading, setReading] = useState(false)
|
||||
const readingSrc = useMemo(() => {
|
||||
if (!mdOp || op === null) return ''
|
||||
// ── Content tab material: the file's full text, its source lines and the
|
||||
// rendered variants (the tab set itself was resolved at the top). ──────
|
||||
/** The textual source behind the content view — the op's snapshot for op
|
||||
* targets, the file on disk for a git worktree file. */
|
||||
const contentSrc = useMemo(() => {
|
||||
if (gitWorktree !== null) return gitContent.status === 'text' ? gitContent.text : ''
|
||||
if (target.kind !== 'op' || op === null) return ''
|
||||
if (op.kind === 'read') return parseReadContent(op.read ?? '')
|
||||
if (op.kind === 'write') return op.content ?? ''
|
||||
if (op.kind === 'edit' && op.edit !== undefined) {
|
||||
@@ -256,38 +402,33 @@ export function DiffPane({ target, ctx, scope, height, onHeightCommit, onClose,
|
||||
return op.edit.newString
|
||||
}
|
||||
return ''
|
||||
}, [mdOp, op, prior])
|
||||
const readingText = useMemo(
|
||||
() => (mdOp && reading && readingSrc !== '' && target.kind === 'op'
|
||||
? rewriteLocalImageUrls(readingSrc, scope, target.path, hostTransportBase())
|
||||
}, [gitWorktree, target.kind, op, prior, gitContent])
|
||||
/** The display path (for the language highlighter) and the resolved path the
|
||||
* media/html routes need — a child-repo path is relative to its repo root,
|
||||
* exactly as the diff loader resolves it. */
|
||||
const contentPath = targetPath
|
||||
const contentAbs = useMemo(
|
||||
() => (gitWorktree !== null
|
||||
? resolveSidebarPath(gitWorktree.repoRoot ?? gitWorktree.worktree ?? scope.cwd, gitWorktree.path)
|
||||
: resolveSidebarPath(scope.cwd, contentPath)),
|
||||
[gitWorktree, scope, contentPath],
|
||||
)
|
||||
/** Source lines: a read keeps its ORIGINAL numbering (`opReadLines`), a
|
||||
* whole-file source is renumbered from 1. */
|
||||
const contentLines = useMemo(
|
||||
() => (contentSrc === '' ? [] : contentSrc.split('\n').map((text, index) => ({ line: index + 1, text }))),
|
||||
[contentSrc],
|
||||
)
|
||||
const contentText = useMemo(
|
||||
() => (mdOp && !contentRaw && contentSrc !== ''
|
||||
? rewriteLocalImageUrls(contentSrc, scope, contentPath, hostTransportBase())
|
||||
: ''),
|
||||
[mdOp, reading, readingSrc, scope, target],
|
||||
[mdOp, contentRaw, contentSrc, scope, contentPath],
|
||||
)
|
||||
const htmlRenderSrc = useMemo(
|
||||
() => (htmlOp && contentAbs !== '' ? htmlUrl(scope, contentAbs) : ''),
|
||||
[htmlOp, scope, contentAbs],
|
||||
)
|
||||
|
||||
// ── HTML render mode: .html/.htm op targets (the editor html viewer's
|
||||
// ext set) load the SAVED file through the same /sidebar/html route the
|
||||
// editor's html viewer uses — relative assets (./style.css, img/x.png)
|
||||
// resolve inside the route, and a segmented read still renders the
|
||||
// whole document (the route serves the file, not the op snapshot). The
|
||||
// frame is always sandboxed (the attribute plus the route's CSP sandbox
|
||||
// header); the editor tab owns the warned no-sandbox escape hatch. ──
|
||||
const htmlOp = target.kind === 'op' && !target.op.isError && /\.(html?)$/i.test(target.path)
|
||||
const [rendering, setRendering] = useState(false)
|
||||
const htmlRenderSrc = useMemo(() => {
|
||||
if (!htmlOp || target.kind !== 'op') return ''
|
||||
return htmlUrl(scope, resolveSidebarPath(scope.cwd, target.path))
|
||||
}, [htmlOp, scope, target])
|
||||
|
||||
// ── PDF render mode: .pdf op targets (read / write / edit, non-error) reuse
|
||||
// the editor's PdfView verbatim — media-route bytes wrapped into an
|
||||
// explicitly-typed Blob so the browser's native PDF viewer opens (a
|
||||
// direct iframe src can fall back to a download). ──────────────────────
|
||||
const pdfOp = target.kind === 'op' && !target.op.isError && /\.pdf$/i.test(target.path)
|
||||
const [renderingPdf, setRenderingPdf] = useState(false)
|
||||
const pdfRenderPath = useMemo(() => {
|
||||
if (!pdfOp || target.kind !== 'op') return ''
|
||||
return resolveSidebarPath(scope.cwd, target.path)
|
||||
}, [pdfOp, scope, target])
|
||||
|
||||
// Header stats for git targets come off the parsed patch text.
|
||||
const gitStats = useMemo(() => {
|
||||
@@ -339,20 +480,80 @@ export function DiffPane({ target, ctx, scope, height, onHeightCommit, onClose,
|
||||
: target.ref.kind === 'worktree' ? target.ref.path : `${target.ref.hash} ${target.ref.subject}`
|
||||
const stats = gitStats ?? (target.kind === 'op' && op !== null && op.kind !== 'read' && !op.isError ? opStats : null)
|
||||
|
||||
const handle = (
|
||||
<div
|
||||
className={css.dragHandle}
|
||||
role="separator"
|
||||
aria-orientation="horizontal"
|
||||
aria-label={t('changesResizePreview')}
|
||||
tabIndex={0}
|
||||
onPointerDown={onHandleDown}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === 'ArrowUp') { event.preventDefault(); onHeightCommit(clamp(paneHeight + HEIGHT_STEP)) }
|
||||
if (event.key === 'ArrowDown') { event.preventDefault(); onHeightCommit(clamp(paneHeight - HEIGHT_STEP)) }
|
||||
}}
|
||||
/>
|
||||
)
|
||||
const strip = hasStrip ? <PaneTabStrip tabs={allTabs} active={active} onSelect={onSelectTab ?? (() => {})} /> : null
|
||||
|
||||
// A caller-hosted view (the graph commit's card) takes over the head AND
|
||||
// the body: same frame, same handle, same height behaviour — only the
|
||||
// content inside the frame changes. Nothing available → its empty state.
|
||||
if (activeExtra) {
|
||||
return (
|
||||
<div className={css.diffPane} style={{ height: paneHeight }}>
|
||||
{handle}
|
||||
{strip}
|
||||
<div className={css.altBody}>{bodies?.[active] ?? <PaneEmpty text={t('changesNoContent')} />}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** Which rendering the content view uses. Resolved up front so this stays a
|
||||
* single switch (an aliased-condition narrowing would turn `target` into
|
||||
* `never` in the remaining branch). */
|
||||
const contentView: 'pdf' | 'html' | 'md' | 'source' =
|
||||
pdfOp && contentAbs !== '' ? 'pdf'
|
||||
: htmlOp && !contentRaw && htmlRenderSrc !== '' ? 'html'
|
||||
: mdOp && !contentRaw && contentText !== '' ? 'md'
|
||||
: 'source'
|
||||
/** The `content` tab's body: the plugin's rendered view for md/html/pdf
|
||||
* (with the source toggle for md/html), line-numbered source otherwise, and
|
||||
* the worktree file itself for a git target — the diff tab keeps the patch. */
|
||||
const contentBody = (
|
||||
contentView === 'pdf'
|
||||
? (
|
||||
<div className={css.htmlPane}>
|
||||
<PdfView scope={scope} path={contentAbs} title={title} />
|
||||
</div>
|
||||
)
|
||||
: contentView === 'html'
|
||||
? <HtmlRenderPreview src={htmlRenderSrc} title={title} />
|
||||
: contentView === 'md'
|
||||
? <MdReadingView text={contentText} ctx={ctx} scope={scope} path={contentPath} />
|
||||
: gitWorktree !== null
|
||||
? (gitContent.status === 'loading' || gitContent.status === 'idle'
|
||||
? <div className={css.paneBody}><Notice kind="loading" tone="page">{t('loading')}</Notice></div>
|
||||
: gitContent.status === 'error'
|
||||
? <div className={css.paneBody}><Notice kind="error">{t('diffLoadError')}: {gitContent.error}</Notice></div>
|
||||
: gitContent.status === 'binary' || gitContent.status === 'large'
|
||||
? <div className={css.paneBody}><BinaryDownload scope={scope} path={contentAbs} /></div>
|
||||
: (
|
||||
<div className={css.paneBody}>
|
||||
<ReadRows lines={contentLines} lang={langOfPath(gitWorktree.path)} />
|
||||
</div>
|
||||
))
|
||||
: (
|
||||
<div className={css.paneBody}>
|
||||
<ReadRows lines={opKind === 'read' ? opReadLines : contentLines} lang={opLang} />
|
||||
</div>
|
||||
)
|
||||
)
|
||||
|
||||
return (
|
||||
<div className={css.diffPane} style={{ height: paneHeight }}>
|
||||
<div
|
||||
className={css.dragHandle}
|
||||
role="separator"
|
||||
aria-orientation="horizontal"
|
||||
aria-label={t('changesResizePreview')}
|
||||
tabIndex={0}
|
||||
onPointerDown={onHandleDown}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === 'ArrowUp') { event.preventDefault(); onHeightCommit(clamp(paneHeight + HEIGHT_STEP)) }
|
||||
if (event.key === 'ArrowDown') { event.preventDefault(); onHeightCommit(clamp(paneHeight - HEIGHT_STEP)) }
|
||||
}}
|
||||
/>
|
||||
{handle}
|
||||
{strip}
|
||||
<div className={css.diffHead}>
|
||||
{target.kind === 'op' && (
|
||||
<StatusBadge tone={target.op.kind}>
|
||||
@@ -366,7 +567,7 @@ export function DiffPane({ target, ctx, scope, height, onHeightCommit, onClose,
|
||||
<StatusBadge tone="neutral">{target.ref.hash}</StatusBadge>
|
||||
)}
|
||||
<span className={css.diffPath} title={title}>{title}</span>
|
||||
{stats !== null && (stats.added > 0 || stats.deleted > 0) && (
|
||||
{active === 'diff' && stats !== null && (stats.added > 0 || stats.deleted > 0) && (
|
||||
<span className={css.diffStats}>
|
||||
{stats.added > 0 && <span className={diffCss.statAdd}>+{String(stats.added)}</span>}
|
||||
{stats.deleted > 0 && <span className={diffCss.statDel}>−{String(stats.deleted)}</span>}
|
||||
@@ -400,25 +601,19 @@ export function DiffPane({ target, ctx, scope, height, onHeightCommit, onClose,
|
||||
onClick={toggleRedaction}
|
||||
/>
|
||||
)}
|
||||
{mdOp && (
|
||||
{/* The rendered/source toggle belongs to the CONTENT tab alone. */}
|
||||
{active === 'content' && mdOp && (
|
||||
<PaneToggle
|
||||
on={reading}
|
||||
label={t(reading ? 'changesMdRaw' : 'changesMdReading')}
|
||||
onClick={() => { setReading(value => !value) }}
|
||||
on={!contentRaw}
|
||||
label={t(contentRaw ? 'changesMdReading' : 'changesMdRaw')}
|
||||
onClick={() => { setContentRaw(value => !value) }}
|
||||
/>
|
||||
)}
|
||||
{htmlOp && (
|
||||
{active === 'content' && htmlOp && (
|
||||
<PaneToggle
|
||||
on={rendering}
|
||||
label={t(rendering ? 'changesHtmlRaw' : 'changesHtmlRender')}
|
||||
onClick={() => { setRendering(value => !value) }}
|
||||
/>
|
||||
)}
|
||||
{pdfOp && (
|
||||
<PaneToggle
|
||||
on={renderingPdf}
|
||||
label={t(renderingPdf ? 'changesPdfRaw' : 'changesPdfRender')}
|
||||
onClick={() => { setRenderingPdf(value => !value) }}
|
||||
on={!contentRaw}
|
||||
label={t(contentRaw ? 'changesHtmlRender' : 'changesHtmlRaw')}
|
||||
onClick={() => { setContentRaw(value => !value) }}
|
||||
/>
|
||||
)}
|
||||
<IconButton
|
||||
@@ -428,64 +623,56 @@ export function DiffPane({ target, ctx, scope, height, onHeightCommit, onClose,
|
||||
onClick={onClose}
|
||||
/>
|
||||
</div>
|
||||
{target.kind === 'op' && htmlOp && rendering && htmlRenderSrc !== ''
|
||||
? <HtmlRenderPreview src={htmlRenderSrc} title={target.path} />
|
||||
: target.kind === 'op' && pdfOp && renderingPdf && pdfRenderPath !== ''
|
||||
? (
|
||||
<div className={css.htmlPane}>
|
||||
<PdfView scope={scope} path={pdfRenderPath} title={target.path} />
|
||||
</div>
|
||||
)
|
||||
: target.kind === 'op' && mdOp && reading && readingText !== ''
|
||||
? <MdReadingView text={readingText} ctx={ctx} scope={scope} path={target.path} />
|
||||
: target.kind === 'op' && op !== null && op.isError
|
||||
? (
|
||||
<div className={css.paneBody}>
|
||||
<Notice kind="error" className={css.readError}>
|
||||
{op.errorText ?? t('changesError')}
|
||||
</Notice>
|
||||
</div>
|
||||
)
|
||||
: target.kind === 'op' && op !== null && op.kind === 'read'
|
||||
{active === 'content'
|
||||
? (hasContentTab ? contentBody : <PaneEmpty text={t('changesNoContent')} />)
|
||||
: active === 'diff'
|
||||
? (opError
|
||||
? (
|
||||
<div className={css.paneBody}>
|
||||
<ReadRows lines={opReadLines} lang={opLang} />
|
||||
<Notice kind="error" className={css.readError}>
|
||||
{op?.errorText ?? t('changesError')}
|
||||
</Notice>
|
||||
</div>
|
||||
)
|
||||
: target.kind === 'op'
|
||||
? (
|
||||
<div className={css.paneBody}>
|
||||
{op !== null && op.kind === 'write'
|
||||
&& prior === undefined
|
||||
&& <Notice kind="hint" tone="inline">{t('changesPriorUnknown')}</Notice>}
|
||||
<DiffRows key={target.op.callId} segments={opSegments} lang={opLang} />
|
||||
</div>
|
||||
)
|
||||
: loading
|
||||
? <div className={css.paneBody}><Notice kind="loading" tone="page">{t('loading')}</Notice></div>
|
||||
: error !== null
|
||||
? (
|
||||
<div className={css.paneBody}>
|
||||
<Notice kind="error">{t('diffLoadError')}: {error}</Notice>
|
||||
</div>
|
||||
)
|
||||
: (
|
||||
<div className={css.paneBody}>
|
||||
{/* The untracked fallback has NO diff text (git diff never
|
||||
lists the file): its content is the whole render. */}
|
||||
{((diffText !== null && diffText !== '') || untracked !== undefined) && (
|
||||
<DiffFiles
|
||||
diff={diffText ?? ''}
|
||||
resolveFold={resolveFold}
|
||||
untrackedPath={untracked !== undefined && target.ref.kind === 'worktree' ? target.ref.path : undefined}
|
||||
untrackedContent={untracked}
|
||||
/>
|
||||
)}
|
||||
{diffText === '' && untracked === undefined && (
|
||||
<Notice kind="empty" tone="page">{t('diffEmpty')}</Notice>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
: opKind === 'read'
|
||||
// A read changed nothing: the diff view says so plainly instead of
|
||||
// rendering an empty patch.
|
||||
? <PaneEmpty text={t('changesReadNoDiff')} />
|
||||
: target.kind === 'op'
|
||||
? (
|
||||
<div className={css.paneBody}>
|
||||
{op !== null && op.kind === 'write'
|
||||
&& prior === undefined
|
||||
&& <Notice kind="hint" tone="inline">{t('changesPriorUnknown')}</Notice>}
|
||||
<DiffRows key={target.op.callId} segments={opSegments} lang={opLang} />
|
||||
</div>
|
||||
)
|
||||
: loading
|
||||
? <div className={css.paneBody}><Notice kind="loading" tone="page">{t('loading')}</Notice></div>
|
||||
: error !== null
|
||||
? (
|
||||
<div className={css.paneBody}>
|
||||
<Notice kind="error">{t('diffLoadError')}: {error}</Notice>
|
||||
</div>
|
||||
)
|
||||
: (
|
||||
<div className={css.paneBody}>
|
||||
{/* The untracked fallback has NO diff text (git diff never
|
||||
lists the file): its content is the whole render. */}
|
||||
{((diffText !== null && diffText !== '') || untracked !== undefined) && (
|
||||
<DiffFiles
|
||||
diff={diffText ?? ''}
|
||||
resolveFold={resolveFold}
|
||||
untrackedPath={untracked !== undefined && target.ref.kind === 'worktree' ? target.ref.path : undefined}
|
||||
untrackedContent={untracked}
|
||||
/>
|
||||
)}
|
||||
{diffText === '' && untracked === undefined && (
|
||||
<Notice kind="empty" tone="page">{t('diffEmpty')}</Notice>
|
||||
)}
|
||||
</div>
|
||||
))
|
||||
: (bodies?.[active] ?? <PaneEmpty text={t('changesNoContent')} />)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user