import type { ReactElement } from 'react' import type { DocumentDiff } from './types' import { ArrowDown, ArrowUp, FilePlus, GitCompare } from 'lucide-react' import { Fragment } from 'react' import { statsParts } from './diffView' export interface DiffBarProps { diff: DocumentDiff /** 「只看改动」开着:连着没变的块折成一条 */ onlyChanges: boolean onToggleOnly: () => void /** 有没有改动可以跳(筛掉的不算) */ canMove: boolean /** 跳到上一处(-1)/ 下一处(1)改动 */ onMove: (step: 1 | -1) => void } /** * 筛选栏第二行(标差异时才有):对比基准(「对比:上一次提交」),改动统计(「新增 2 · 修改 3 · 删除 1」,各按改动色, * 没有的那种不写,都没有写「没有改动」),右边「只看改动」开关、上一处 / 下一处。基准里没有这个文件时只写基准,看横幅。 */ export function DiffBar({ diff, onlyChanges, onToggleOnly, canMove, onMove }: DiffBarProps): ReactElement { const parts = statsParts(diff.stats) return (
对比: {diff.base} {diff.newFile === undefined && ( <> · {parts.length === 0 ? '没有改动' : parts.map((part, index) => ( {index > 0 && ·} {part.text} ))} {([[-1, ArrowUp, '上一处改动'], [1, ArrowDown, '下一处改动']] as const).map(([step, Icon, label]) => ( ))} )}
) } /** 基准里没有这个文件(新文件、未跟踪的):预览顶部一条横幅,卡片不再逐张标绿。 */ export function NewFileBanner({ detail }: { detail: string }): ReactElement { return (
新文件,全部是新增 {detail}
) }