|
|
|
@ -1,4 +1,4 @@
|
|
|
|
import React, { type FC, useCallback, useEffect, useRef } from 'react'
|
|
|
|
import React, { type FC, useCallback, useEffect, useMemo, useRef } from 'react'
|
|
|
|
import useTheme from '@/hooks/use-theme'
|
|
|
|
import useTheme from '@/hooks/use-theme'
|
|
|
|
import { Theme } from '@/types/app'
|
|
|
|
import { Theme } from '@/types/app'
|
|
|
|
import classNames from '@/utils/classnames'
|
|
|
|
import classNames from '@/utils/classnames'
|
|
|
|
@ -30,6 +30,7 @@ const CodeEditor: FC<CodeEditorProps> = ({
|
|
|
|
const { theme } = useTheme()
|
|
|
|
const { theme } = useTheme()
|
|
|
|
const monacoRef = useRef<any>(null)
|
|
|
|
const monacoRef = useRef<any>(null)
|
|
|
|
const editorRef = useRef<any>(null)
|
|
|
|
const editorRef = useRef<any>(null)
|
|
|
|
|
|
|
|
const [isMounted, setIsMounted] = React.useState(false)
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
if (monacoRef.current) {
|
|
|
|
if (monacoRef.current) {
|
|
|
|
@ -64,6 +65,7 @@ const CodeEditor: FC<CodeEditorProps> = ({
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
monaco.editor.setTheme('light-theme')
|
|
|
|
monaco.editor.setTheme('light-theme')
|
|
|
|
|
|
|
|
setIsMounted(true)
|
|
|
|
}, [])
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
|
|
const formatJsonContent = useCallback(() => {
|
|
|
|
const formatJsonContent = useCallback(() => {
|
|
|
|
@ -76,6 +78,12 @@ const CodeEditor: FC<CodeEditorProps> = ({
|
|
|
|
onUpdate?.(value)
|
|
|
|
onUpdate?.(value)
|
|
|
|
}, [onUpdate])
|
|
|
|
}, [onUpdate])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const editorTheme = useMemo(() => {
|
|
|
|
|
|
|
|
if (theme === Theme.light)
|
|
|
|
|
|
|
|
return 'light-theme'
|
|
|
|
|
|
|
|
return 'dark-theme'
|
|
|
|
|
|
|
|
}, [theme])
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className={classNames('flex flex-col h-full bg-components-input-bg-normal overflow-hidden', hideTopMenu && 'pt-2', className)}>
|
|
|
|
<div className={classNames('flex flex-col h-full bg-components-input-bg-normal overflow-hidden', hideTopMenu && 'pt-2', className)}>
|
|
|
|
{!hideTopMenu && (
|
|
|
|
{!hideTopMenu && (
|
|
|
|
@ -110,6 +118,7 @@ const CodeEditor: FC<CodeEditorProps> = ({
|
|
|
|
<Editor
|
|
|
|
<Editor
|
|
|
|
height='100%'
|
|
|
|
height='100%'
|
|
|
|
defaultLanguage='json'
|
|
|
|
defaultLanguage='json'
|
|
|
|
|
|
|
|
theme={isMounted ? editorTheme : 'default-theme'} // sometimes not load the default theme
|
|
|
|
value={value}
|
|
|
|
value={value}
|
|
|
|
onChange={handleEditorChange}
|
|
|
|
onChange={handleEditorChange}
|
|
|
|
onMount={handleEditorDidMount}
|
|
|
|
onMount={handleEditorDidMount}
|
|
|
|
|