1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
/**
* MonacoViewer wraps the Monaco editor for both the read-only code preview
* and the editable editor pane. It is the only module importing Monaco, and
* is meant to be lazy-loaded (see CodeView / EditorPane).
*
* @example
* <MonacoViewer content="package main" language="go" readOnly />
*/
import Editor, { type OnChange, type OnMount } from "@monaco-editor/react";
import "../monaco-setup";
import { useTheme } from "../theme";
interface MonacoViewerProps {
content: string;
language: string;
readOnly?: boolean;
/** Called with the new text on every edit (editable mode). */
onChange?: OnChange;
/** Gives access to the editor instance (key bindings, focus). */
onMount?: OnMount;
}
export default function MonacoViewer({
content,
language,
readOnly = false,
onChange,
onMount,
}: MonacoViewerProps) {
// Monaco has its own palettes; pick the one matching the app theme.
const theme =
useTheme((state) => state.theme) === "dark" ? "vs-dark" : "light";
return (
<Editor
height="100%"
language={language}
value={content}
theme={theme}
onChange={onChange}
onMount={onMount}
options={{
readOnly,
minimap: { enabled: false },
scrollBeyondLastLine: false,
fontSize: 13,
automaticLayout: true,
}}
/>
);
}
|