|
1 |
| -import AceEditor from "react-ace"; |
2 |
| - |
3 |
| -import "ace-builds/src-noconflict/mode-python"; |
4 |
| -import "ace-builds/src-noconflict/theme-textmate"; |
5 |
| -import "ace-builds/src-noconflict/theme-twilight"; |
6 |
| -import "ace-builds/src-noconflict/ext-language_tools"; |
| 1 | +import BrowserOnly from '@docusaurus/BrowserOnly' |
7 | 2 |
|
8 | 3 | const editorOptions = {
|
9 | 4 | enableBasicAutocompletion: true,
|
10 | 5 | enableLiveAutocompletion: true,
|
11 | 6 | highlightActiveLine: false,
|
12 |
| - showPrintMargin: false, |
13 |
| -}; |
| 7 | + showPrintMargin: false |
| 8 | +} |
14 | 9 |
|
15 | 10 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
16 | 11 | const editorOnLoad = (editor: any) => {
|
17 |
| - editor.renderer.setScrollMargin(10, 10, 0, 0); |
18 |
| - editor.moveCursorTo(0, 0); |
19 |
| -}; |
| 12 | + editor.renderer.setScrollMargin(10, 10, 0, 0) |
| 13 | + editor.moveCursorTo(0, 0) |
| 14 | +} |
20 | 15 |
|
21 | 16 | export default function Editor({
|
22 | 17 | theme,
|
23 | 18 | input,
|
24 |
| - onChange, |
| 19 | + onChange |
25 | 20 | }: {
|
26 |
| - theme: string; |
27 |
| - input: string; |
28 |
| - onChange: (value: string) => void; |
| 21 | + theme: string |
| 22 | + input: string |
| 23 | + onChange: (value: string) => void |
29 | 24 | }) {
|
30 | 25 | return (
|
31 |
| - <AceEditor |
32 |
| - value={input} |
33 |
| - mode="python" |
34 |
| - name="CodeBlock" |
35 |
| - fontSize="0.9rem" |
36 |
| - className="flex-1 overflow-clip" |
37 |
| - theme={theme === "dark" ? "twilight" : "textmate"} |
38 |
| - onChange={onChange} |
39 |
| - width="100%" |
40 |
| - height="100%" |
41 |
| - onLoad={editorOnLoad} |
42 |
| - editorProps={{ $blockScrolling: true }} |
43 |
| - setOptions={editorOptions} |
44 |
| - wrapEnabled={true} |
45 |
| - /> |
46 |
| - ); |
| 26 | + <BrowserOnly fallback={<div>Loading...</div>}> |
| 27 | + {() => { |
| 28 | + const AceEditor = require('react-ace').default |
| 29 | + require('ace-builds/src-noconflict/mode-python') |
| 30 | + require('ace-builds/src-noconflict/theme-textmate') |
| 31 | + require('ace-builds/src-noconflict/theme-twilight') |
| 32 | + require('ace-builds/src-noconflict/ext-language_tools') |
| 33 | + return ( |
| 34 | + <AceEditor |
| 35 | + value={input} |
| 36 | + mode="python" |
| 37 | + name="CodeBlock" |
| 38 | + fontSize="0.9rem" |
| 39 | + className="flex-1 overflow-clip" |
| 40 | + theme={theme === 'dark' ? 'twilight' : 'textmate'} |
| 41 | + onChange={onChange} |
| 42 | + width="100%" |
| 43 | + height="100%" |
| 44 | + onLoad={editorOnLoad} |
| 45 | + editorProps={{ $blockScrolling: true }} |
| 46 | + setOptions={editorOptions} |
| 47 | + wrapEnabled={true} |
| 48 | + /> |
| 49 | + ) |
| 50 | + }} |
| 51 | + </BrowserOnly> |
| 52 | + ) |
47 | 53 | }
|
0 commit comments