15
15
* limitations under the License.
16
16
*/
17
17
import { 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' ;
23
20
import { useEffect , useMemo , useRef , useState } from 'react' ;
24
21
import {
25
22
type FieldValues ,
@@ -29,26 +26,13 @@ import {
29
26
} from 'react-hook-form' ;
30
27
import { useTranslation } from 'react-i18next' ;
31
28
32
- import { genControllerProps } from './util ' ;
29
+ import { monaco , setupMonacoEditor } from '@/utils/monaco ' ;
33
30
34
- type SetupMonacoProps = {
35
- monaco : Monaco ;
36
- } ;
31
+ import { genControllerProps } from './util' ;
37
32
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 ( ) ;
50
34
51
- const options : editor . IStandaloneEditorConstructionOptions = {
35
+ const options : monaco . editor . IStandaloneEditorConstructionOptions = {
52
36
minimap : { enabled : false } ,
53
37
contextmenu : false ,
54
38
lineNumbersMinChars : 3 ,
@@ -102,11 +86,9 @@ export const FormItemEditor = <T extends FieldValues>(
102
86
fieldState,
103
87
} = useController < T > ( enhancedControllerProps ) ;
104
88
105
- const monaco = useMonaco ( ) ;
106
89
const [ internalLoading , setLoading ] = useState ( false ) ;
107
90
108
91
useEffect ( ( ) => {
109
- if ( ! monaco ) return ;
110
92
setLoading ( true ) ;
111
93
112
94
const schemas = [ ] ;
@@ -125,7 +107,7 @@ export const FormItemEditor = <T extends FieldValues>(
125
107
} ) ;
126
108
127
109
setLoading ( false ) ;
128
- } , [ monaco , customSchema ] ) ;
110
+ } , [ customSchema ] ) ;
129
111
130
112
return (
131
113
< InputWrapper
@@ -155,7 +137,6 @@ export const FormItemEditor = <T extends FieldValues>(
155
137
restField . disabled && 'editor-wrapper--disabled'
156
138
) ,
157
139
} }
158
- beforeMount = { ( monaco ) => setupMonaco ( { monaco } ) }
159
140
defaultValue = { controllerProps . defaultValue }
160
141
value = { value }
161
142
onChange = { fOnChange }
0 commit comments