'use client' import type { FileStatusCode } from '@devframes/service-git' import type { DiffChangeType, DiffFileChange } from './parse-patch' import { useMemo, useState } from 'react' import { cn } from '../../lib/utils' import { Badge } from '../ui/badge' import { FileIcon } from '../ui/file-icon' import { Icon } from '../ui/icon' import { ScrollArea } from '../ui/scroll-area' import { Skeleton } from '../ui/skeleton' import { StatusMark } from '../ui/status-mark' import { buildFileModel } from './build-model' import { DiffFile } from './diff-file' import { parseUnifiedPatch } from './parse-patch' /** How the changed files are laid out. */ type DiffLayout = 'flat' | 'collapsible' export interface DiffPatchViewProps { /** Raw unified/git patch text; `null` while unavailable. */ patch: string | null loading: boolean /** True when the patch was clipped server-side (a size cap). */ truncated: boolean /** Set `false` to render inline when a scrolling parent already wraps it. */ scroll?: boolean /** * `flat` lists every file's diff; `collapsible` puts each behind a disclosure * header (a scannable list that expands on demand). Defaults to `flat`. */ layout?: DiffLayout } /** Map a parsed file's change type to a git status code (for the status mark). */ function changeTypeStatus(type: DiffChangeType): FileStatusCode { switch (type) { case 'new': return 'added' case 'deleted': return 'deleted' case 'rename-pure': case 'rename-changed': return 'renamed' default: return 'modified' } } /** * A single file's diff behind a clickable disclosure header (filename, change * icon and +/- counts). The diff body mounts only while expanded, so a * many-file commit stays a scannable list (and does no highlight work) until * you open a file. */ function DiffFileSection({ file, defaultOpen }: { file: DiffFileChange, defaultOpen: boolean }) { const [open, setOpen] = useState(defaultOpen) const model = useMemo(() => buildFileModel(file), [file]) const label = file.prevName ? `${file.prevName} → ${file.name}` : file.name return (
No textual diff available (binary or unchanged).
if (layout === 'collapsible') { return (Patch truncated.
}Patch truncated.
} > ) if (!scroll) return