import React from 'react'; import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; import { cn } from '@/lib/utils'; import { getLanguageFromExtension } from '@/lib/toolHelpers'; import { parseDiffToUnified } from './message/toolRenderers'; const DIFF_CUSTOM_STYLE: React.CSSProperties = { margin: 0, padding: 0, fontSize: 'inherit', background: 'transparent', backgroundColor: 'transparent', borderRadius: 0, overflow: 'visible', whiteSpace: 'pre-wrap', wordBreak: 'break-all', overflowWrap: 'anywhere', }; const DIFF_CODE_TAG_PROPS = { style: { background: 'transparent', backgroundColor: 'transparent', fontSize: 'inherit' } as React.CSSProperties, }; interface DiffPreviewProps { diff: string; syntaxTheme: { [key: string]: React.CSSProperties }; filePath?: string; } export const DiffPreview: React.FC = ({ diff, syntaxTheme, filePath }) => (
{parseDiffToUnified(diff).map((hunk, hunkIdx) => (
{`${hunk.file || filePath?.split('/').pop() || 'file'} (line ${hunk.oldStart})`}
{hunk.lines.map((line, lineIdx) => (
{line.lineNumber || ''}
{line.content}
))}
))}
); interface WritePreviewProps { content: string; syntaxTheme: { [key: string]: React.CSSProperties }; filePath?: string; } export const WritePreview: React.FC = ({ content, syntaxTheme, filePath }) => { const lines = content.split('\n'); const language = getLanguageFromExtension(filePath ?? '') || 'text'; const displayPath = filePath?.split('/').pop() || 'New file'; const lineCount = Math.max(lines.length, 1); const headerLineLabel = lineCount === 1 ? 'line 1' : `lines 1-${lineCount}`; return (
{`${displayPath} (${headerLineLabel})`}
{lines.map((line, lineIdx) => (
{lineIdx + 1}
{line || ' '}
))}
); };