forked from raycast/ray-so
-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.tsx
56 lines (48 loc) · 1.69 KB
/
code.tsx
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
52
53
54
55
56
"use client";
import { useEffect } from "react";
import getWasm from "shiki/wasm";
import { highlighterAtom } from "./store";
import { useAtom } from "jotai";
import { shikiTheme } from "./store/themes";
import Frame from "./components/Frame";
import Controls from "./components/Controls";
import FrameContextStore from "./store/FrameContextStore";
import styles from "./code.module.css";
import NoSSR from "./components/NoSSR";
import { Highlighter, getHighlighterCore } from "shiki";
import { LANGUAGES } from "./util/languages";
import tailwindLight from "./assets/tailwind/light.json";
import tailwindDark from "./assets/tailwind/dark.json";
import ExportButton from "./components/ExportButton";
import { NavigationActions } from "@/components/navigation";
import { InfoDialog } from "./components/InfoDialog";
import FormatButton from "./components/FormatCodeButton";
export function Code() {
const [highlighter, setHighlighter] = useAtom(highlighterAtom);
useEffect(() => {
getHighlighterCore({
themes: [shikiTheme, tailwindLight, tailwindDark],
langs: [LANGUAGES.javascript.src(), LANGUAGES.tsx.src(), LANGUAGES.swift.src(), LANGUAGES.python.src()],
loadWasm: getWasm,
}).then((highlighter) => {
setHighlighter(highlighter as Highlighter);
});
}, []); // eslint-disable-line react-hooks/exhaustive-deps
return (
<>
<FrameContextStore>
<NavigationActions>
<InfoDialog />
<FormatButton />
<ExportButton />
</NavigationActions>
<div className={styles.app}>
<NoSSR>
{highlighter && <Frame />}
<Controls />
</NoSSR>
</div>
</FrameContextStore>
</>
);
}