1
+ import * as monaco from "monaco-editor" ;
1
2
import { useState , useEffect , useRef , Suspense , SetStateAction } from "react" ;
2
3
import MonacoEditor from "@monaco-editor/react" ;
3
4
4
5
import languageToSyntax from "../assets/mapLanguageToSyntax.json" ;
5
6
import { useAppSettings , useCodeEditor } from "@/store/store" ;
6
7
import { useTheme } from "@/context/ThemeProvider" ;
8
+ import { loader } from "@monaco-editor/react" ;
9
+
10
+ loader . config ( { monaco } ) ;
11
+
12
+ monaco . editor . defineTheme ( "transparent" , {
13
+ base : "vs-dark" ,
14
+ inherit : true ,
15
+ rules : [
16
+ {
17
+ background : "00000000" ,
18
+ } as any ,
19
+ {
20
+ token : "comment" ,
21
+ foreground : "6a9955" ,
22
+ } ,
23
+ {
24
+ token : "string" ,
25
+ foreground : "ce9178" ,
26
+ } ,
27
+ {
28
+ token : "number" ,
29
+ foreground : "b5cea8" ,
30
+ } ,
31
+ {
32
+ token : "keyword" ,
33
+ foreground : "569cd6" ,
34
+ } ,
35
+ {
36
+ token : "type" ,
37
+ foreground : "4ec9b0" ,
38
+ } ,
39
+ {
40
+ token : "delimiter" ,
41
+ foreground : "d4d4d4" ,
42
+ } ,
43
+ {
44
+ token : "tag" ,
45
+ foreground : "569cd6" ,
46
+ } ,
47
+ {
48
+ token : "attribute.name" ,
49
+ foreground : "9cdcfe" ,
50
+ } ,
51
+ {
52
+ token : "attribute.value" ,
53
+ foreground : "ce9178" ,
54
+ } ,
55
+ {
56
+ token : "operator" ,
57
+ foreground : "d4d4d4" ,
58
+ } ,
59
+ ] ,
60
+ colors : {
61
+ "editor.background" : "#00000000" ,
62
+ "editor.foreground" : "#d4d4d4" ,
63
+ "editor.lineHighlightBackground" : "#ffffff1a" ,
64
+ "editorCursor.foreground" : "#d4d4d4" ,
65
+ "editorWhitespace.foreground" : "#ffffff1a" ,
66
+ "editorIndentGuide.background" : "#ffffff1a" ,
67
+ "editorIndentGuide.activeBackground" : "#ffffff33" ,
68
+ "editor.selectionBackground" : "#264f78" ,
69
+
70
+ "minimap.background" : "#00000000" ,
71
+ "minimap.selectionHighlight" : "#264f7880" ,
72
+ "minimapSlider.background" : "#ffffff20" ,
73
+ "minimapSlider.hoverBackground" : "#ffffff33" ,
74
+ "minimapSlider.activeBackground" : "#ffffff44" ,
75
+ } ,
76
+ } ) ;
7
77
8
78
const Editor = ( ) => {
9
79
const { resolvedTheme : theme } = useTheme ( ) ;
@@ -22,9 +92,9 @@ const Editor = () => {
22
92
const resizeObserver = useRef < ResizeObserver | null > ( null ) ;
23
93
const [ editorOptions , setEditorOptions ] = useState ( { } ) ;
24
94
const execute = useCodeEditor ( ( s ) => s . execute ) ;
25
- const code = useCodeEditor ( s => s . code ) ;
26
- const language = useCodeEditor ( s => s . language ) ;
27
- const setCode = useCodeEditor ( s => s . setCode ) ;
95
+ const code = useCodeEditor ( ( s ) => s . code ) ;
96
+ const language = useCodeEditor ( ( s ) => s . language ) ;
97
+ const setCode = useCodeEditor ( ( s ) => s . setCode ) ;
28
98
29
99
const editorDidMount = ( editor : any , monaco : any ) => {
30
100
editor . onKeyDown ( ( event : any ) => {
@@ -104,9 +174,11 @@ const Editor = () => {
104
174
language = {
105
175
languageToSyntax [ language as keyof typeof languageToSyntax ]
106
176
}
107
- theme = { `vs- ${ theme } ` }
177
+ theme = { `transparent ` }
108
178
value = { code }
109
- options = { editorOptions }
179
+ options = { {
180
+ ...editorOptions ,
181
+ } }
110
182
onChange = { ( newCode , event ) => {
111
183
setCode ( newCode ?? "" ) ;
112
184
} }
0 commit comments