| 1 | import { lazy, Suspense } from "react"; |
| 2 | |
| 3 | export interface EditorProps { |
| 4 | value: string; |
| 5 | language?: string; |
| 6 | readOnly?: boolean; |
| 7 | maxHeight?: number; |
| 8 | /** Original source size in bytes when the caller already has it. */ |
| 9 | sourceSize?: number; |
| 10 | /** Opt in to the workspace-oriented viewer with line numbers and search. */ |
| 11 | showLineNumbers?: boolean; |
| 12 | /** Request that the workspace-oriented viewer opens search after mounting. */ |
| 13 | searchRequestPending?: boolean; |
| 14 | /** Called once the viewer has consumed a pending search request. */ |
| 15 | onSearchRequestConsumed?: () => void; |
| 16 | } |
| 17 | |
| 18 | // ── EDITOR SEAM (code) ─────────────────────────────────────────────────────── |
| 19 | // Keep the established highlighted viewer for existing chat, diff, and tool |
| 20 | // surfaces. Workspace previews explicitly opt into the heavier searchable |
| 21 | // viewer, so this feature cannot silently change every code block in the app. |
| 22 | const HljsImpl = lazy(() => import("./editors/HljsCode")); |
| 23 | const LineNumberImpl = lazy(() => import("./editors/LineNumberCode")); |
| 24 | |
| 25 | export function CodeViewer(props: EditorProps) { |
| 26 | const Impl = props.showLineNumbers ? LineNumberImpl : HljsImpl; |
| 27 | return ( |
| 28 | <div className="code-block"> |
| 29 | <Suspense |
| 30 | fallback={ |
| 31 | <pre className="code code--loading"> |
| 32 | <code>{props.value}</code> |
| 33 | </pre> |
| 34 | } |
| 35 | > |
| 36 | <Impl {...props} /> |
| 37 | </Suspense> |
| 38 | </div> |
| 39 | ); |
| 40 | } |
| 41 |