1515 * limitations under the License.
1616 */
1717import { InputWrapper , type InputWrapperProps , Skeleton } from '@mantine/core' ;
18- import { Editor , loader , type Monaco , useMonaco } from '@monaco-editor/react' ;
19- import { clsx } from 'clsx' ;
20- import { editor } from 'monaco-editor' ;
21- import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker' ;
22- import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker' ;
18+ import { Editor } from '@monaco-editor/react' ;
19+ import clsx from 'clsx' ;
2320import { useEffect , useMemo , useRef , useState } from 'react' ;
2421import {
2522 type FieldValues ,
@@ -29,26 +26,13 @@ import {
2926} from 'react-hook-form' ;
3027import { useTranslation } from 'react-i18next' ;
3128
32- import { genControllerProps } from './util ' ;
29+ import { monaco , setupMonacoEditor } from '@/utils/monaco ' ;
3330
34- type SetupMonacoProps = {
35- monaco : Monaco ;
36- } ;
31+ import { genControllerProps } from './util' ;
3732
38- const setupMonaco = ( { monaco } : SetupMonacoProps ) => {
39- window . MonacoEnvironment = {
40- getWorker ( _ , label ) {
41- if ( label === 'json' ) {
42- return new jsonWorker ( ) ;
43- }
44- return new editorWorker ( ) ;
45- } ,
46- } ;
47- loader . config ( { monaco } ) ;
48- return loader . init ( ) ;
49- } ;
33+ setupMonacoEditor ( ) ;
5034
51- const options : editor . IStandaloneEditorConstructionOptions = {
35+ const options : monaco . editor . IStandaloneEditorConstructionOptions = {
5236 minimap : { enabled : false } ,
5337 contextmenu : false ,
5438 lineNumbersMinChars : 3 ,
@@ -102,11 +86,9 @@ export const FormItemEditor = <T extends FieldValues>(
10286 fieldState,
10387 } = useController < T > ( enhancedControllerProps ) ;
10488
105- const monaco = useMonaco ( ) ;
10689 const [ internalLoading , setLoading ] = useState ( false ) ;
10790
10891 useEffect ( ( ) => {
109- if ( ! monaco ) return ;
11092 setLoading ( true ) ;
11193
11294 const schemas = [ ] ;
@@ -125,7 +107,7 @@ export const FormItemEditor = <T extends FieldValues>(
125107 } ) ;
126108
127109 setLoading ( false ) ;
128- } , [ monaco , customSchema ] ) ;
110+ } , [ customSchema ] ) ;
129111
130112 return (
131113 < InputWrapper
@@ -155,7 +137,6 @@ export const FormItemEditor = <T extends FieldValues>(
155137 restField . disabled && 'editor-wrapper--disabled'
156138 ) ,
157139 } }
158- beforeMount = { ( monaco ) => setupMonaco ( { monaco } ) }
159140 defaultValue = { controllerProps . defaultValue }
160141 value = { value }
161142 onChange = { fOnChange }
0 commit comments