@@ -27,28 +27,16 @@ import {
2727 ZapIcon ,
2828} from "lucide-react" ;
2929import { 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 " ;
3131
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" ;
3732import { cn } from "@/utils/cn" ;
3833import type { ParameterFormType } from "@/gen/types" ;
3934import { 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" ;
5036
5137export const Editor : FC = ( ) => {
38+ const { appliedTheme } = useTheme ( ) ;
39+
5240 const $code = useStore ( ( state ) => state . code ) ;
5341 const $setCode = useStore ( ( state ) => state . setCode ) ;
5442
@@ -160,7 +148,7 @@ export const Editor: FC = () => {
160148 ) }
161149 >
162150 < Button
163- className = "pointer-events-auto z-10"
151+ className = "pointer-events-auto z-10 hidden "
164152 variant = "subtle"
165153 size = "sm"
166154 onClick = { onCopy }
@@ -170,15 +158,30 @@ export const Editor: FC = () => {
170158 </ div >
171159
172160 < 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
175163 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+ defaultLanguage = "hcl"
171+ loading = ""
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+ } }
182185 />
183186 </ div >
184187 </ Tabs . Content >
0 commit comments