mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-03 06:42:27 +08:00
- Disable noisy biome rules (noExplicitAny, useExhaustiveDependencies, etc.) - Fix memory leak in file-preview-list.tsx with useRef pattern - Separate unmount cleanup into dedicated useEffect - Add ToolPartLike interface for type safety in chat-message-display - Add accessibility attributes (role, tabIndex, onKeyDown) - Replace autoFocus with useEffect focus pattern - Minor syntax improvements (optional chaining, key fixes)
54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
"use client"
|
|
|
|
import { Highlight, themes } from "prism-react-renderer"
|
|
|
|
interface CodeBlockProps {
|
|
code: string
|
|
language?: "xml" | "json"
|
|
}
|
|
|
|
export function CodeBlock({ code, language = "xml" }: CodeBlockProps) {
|
|
return (
|
|
<div className="overflow-hidden w-full">
|
|
<Highlight theme={themes.github} code={code} language={language}>
|
|
{({
|
|
className: _className,
|
|
style,
|
|
tokens,
|
|
getLineProps,
|
|
getTokenProps,
|
|
}) => (
|
|
<pre
|
|
className="text-[11px] leading-relaxed overflow-x-auto overflow-y-auto max-h-48 scrollbar-thin break-all"
|
|
style={{
|
|
...style,
|
|
fontFamily:
|
|
"var(--font-mono), ui-monospace, monospace",
|
|
backgroundColor: "transparent",
|
|
margin: 0,
|
|
padding: 0,
|
|
wordBreak: "break-all",
|
|
whiteSpace: "pre-wrap",
|
|
}}
|
|
>
|
|
{tokens.map((line, i) => (
|
|
<div
|
|
key={i}
|
|
{...getLineProps({ line })}
|
|
style={{ wordBreak: "break-all" }}
|
|
>
|
|
{line.map((token, key) => (
|
|
<span
|
|
key={key}
|
|
{...getTokenProps({ token })}
|
|
/>
|
|
))}
|
|
</div>
|
|
))}
|
|
</pre>
|
|
)}
|
|
</Highlight>
|
|
</div>
|
|
)
|
|
}
|