@@ -27,28 +27,16 @@ import {
27
27
ZapIcon ,
28
28
} from "lucide-react" ;
29
29
import { type FC , useCallback , useEffect , useRef , useState } from "react" ;
30
- import CodeEditor from "react-simple-code- editor" ;
30
+ import { Editor as MonacoEditor } from "@monaco- editor/react " ;
31
31
32
- // The following imports can't be re-ordered otherwise things break
33
- // @ts -expect-error TODO: create types for this
34
- import { highlight , languages } from "prismjs/components/prism-core" ;
35
- import "prismjs/components/prism-hcl" ;
36
- import "prismjs/themes/prism.css" ;
37
32
import { cn } from "@/utils/cn" ;
38
33
import type { ParameterFormType } from "@/gen/types" ;
39
34
import { multiSelect , radio , switchInput , textInput } from "@/client/snippets" ;
40
-
41
- // Adds line numbers to the highlight.
42
- const hightlightWithLineNumbers = ( input : string , language : unknown ) =>
43
- highlight ( input , language )
44
- . split ( "\n" )
45
- . map (
46
- ( line : string , i : number ) =>
47
- `<span class='editorLineNumber'>${ i + 1 } </span>${ line } ` ,
48
- )
49
- . join ( "\n" ) ;
35
+ import { useTheme } from "@/client/contexts/theme" ;
50
36
51
37
export const Editor : FC = ( ) => {
38
+ const { appliedTheme } = useTheme ( ) ;
39
+
52
40
const $code = useStore ( ( state ) => state . code ) ;
53
41
const $setCode = useStore ( ( state ) => state . setCode ) ;
54
42
@@ -160,7 +148,7 @@ export const Editor: FC = () => {
160
148
) }
161
149
>
162
150
< Button
163
- className = "pointer-events-auto z-10"
151
+ className = "pointer-events-auto z-10 hidden "
164
152
variant = "subtle"
165
153
size = "sm"
166
154
onClick = { onCopy }
@@ -170,15 +158,30 @@ export const Editor: FC = () => {
170
158
</ div >
171
159
172
160
< Tabs . Content value = "code" asChild = { true } >
173
- < div className = "h-full w-full overflow-y-scroll bg-surface-secondary font-mono" >
174
- < CodeEditor
161
+ < div className = "h-full w-full bg-surface-secondary font-mono" >
162
+ < MonacoEditor
175
163
value = { $code }
176
- onValueChange = { ( code ) => $setCode ( code ) }
177
- highlight = { ( code ) =>
178
- hightlightWithLineNumbers ( code , languages . hcl )
179
- }
180
- textareaId = "codeArea"
181
- className = "editor pt-3"
164
+ onChange = { ( code ) => {
165
+ if ( code !== undefined ) {
166
+ $setCode ( code ) ;
167
+ }
168
+ } }
169
+ theme = { appliedTheme === "dark" ? "vs-dark" : "vs-light" }
170
+ className = ""
171
+ defaultLanguage = "hcl"
172
+ options = { {
173
+ minimap : {
174
+ enabled : false ,
175
+ } ,
176
+ automaticLayout : true ,
177
+ fontFamily : "DM Mono" ,
178
+ fontSize : 14 ,
179
+ wordWrap : "on" ,
180
+ padding : {
181
+ top : 16 ,
182
+ bottom : 16 ,
183
+ } ,
184
+ } }
182
185
/>
183
186
</ div >
184
187
</ Tabs . Content >
0 commit comments