MCPcopy Create free account
hub / github.com/triggerdotdev/jsonhero-web / CodeViewer

Function CodeViewer

app/components/CodeViewer.tsx:9–51  ·  view source on GitHub ↗
({ code, lang }: { code: string; lang?: "json" })

Source from the content-addressed store, hash-verified

7import { useHotkeys } from "react-hotkeys-hook";
8
9export function CodeViewer({ code, lang }: { code: string; lang?: "json" }) {
10 const editor = useRef(null);
11
12 const extensions = getViewerSetup();
13
14 if (!lang || lang === "json") {
15 extensions.push(jsonLang());
16 }
17
18 const [theme] = useTheme();
19
20 const { setContainer, view, state } = useCodeMirror({
21 container: editor.current,
22 extensions,
23 value: code,
24 editable: false,
25 contentEditable: false,
26 autoFocus: false,
27 basicSetup: false,
28 theme: theme === "light" ? lightTheme() : darkTheme(),
29 });
30
31 useEffect(() => {
32 if (editor.current) {
33 setContainer(editor.current);
34 }
35 }, [editor.current]);
36
37 useHotkeys(
38 "ctrl+a,meta+a,command+a",
39 (e) => {
40 e.preventDefault();
41 view?.dispatch({ selection: { anchor: 0, head: state?.doc.length } });
42 },
43 [view, state]
44 );
45
46 return (
47 <div>
48 <div ref={editor} />
49 </div>
50 );
51}

Callers

nothing calls this directly

Calls 4

getViewerSetupFunction · 0.90
useThemeFunction · 0.90
lightThemeFunction · 0.90
darkThemeFunction · 0.90

Tested by

no test coverage detected