@@ -31,6 +31,10 @@ export interface CommonProps {
31
31
dedicatedEditorKeywords ?: string [ ]
32
32
dedicatedEditorFunctions ?: monacoEditor . languages . CompletionItem [ ]
33
33
onChangeLanguage ?: ( langId : DSL ) => void
34
+ shouldOpenDedicatedEditor ?: boolean
35
+ onOpenDedicatedEditor ?: ( ) => void
36
+ onSubmitDedicatedEditor ?: ( langId : DSL ) => void
37
+ onCloseDedicatedEditor ?: ( langId : DSL ) => void
34
38
'data-testid' ?: string
35
39
}
36
40
@@ -60,6 +64,10 @@ const MonacoEditor = (props: Props) => {
60
64
dedicatedEditorLanguages = [ ] ,
61
65
dedicatedEditorKeywords = [ ] ,
62
66
dedicatedEditorFunctions = [ ] ,
67
+ shouldOpenDedicatedEditor,
68
+ onOpenDedicatedEditor,
69
+ onSubmitDedicatedEditor,
70
+ onCloseDedicatedEditor,
63
71
'data-testid' : dataTestId = 'monaco-editor'
64
72
} = props
65
73
@@ -82,6 +90,13 @@ const MonacoEditor = (props: Props) => {
82
90
monacoObjects . current ?. editor . updateOptions ( { readOnly : ! isEditing && ( disabled || readOnly ) } )
83
91
} , [ disabled , readOnly , isEditing ] )
84
92
93
+ useEffect ( ( ) => {
94
+ if ( shouldOpenDedicatedEditor ) {
95
+ setIsDedicatedEditorOpen ( true )
96
+ onOpenDedicatedEditor ?.( )
97
+ }
98
+ } , [ shouldOpenDedicatedEditor ] )
99
+
85
100
const editorDidMount = (
86
101
editor : monacoEditor . editor . IStandaloneCodeEditor ,
87
102
monaco : typeof monacoEditor ,
@@ -130,6 +145,7 @@ const MonacoEditor = (props: Props) => {
130
145
const { editor } = monacoObjects ?. current
131
146
132
147
setIsDedicatedEditorOpen ( true )
148
+ onOpenDedicatedEditor ?.( )
133
149
editor . updateOptions ( { readOnly : true } )
134
150
}
135
151
@@ -140,13 +156,12 @@ const MonacoEditor = (props: Props) => {
140
156
editor . focus ( )
141
157
}
142
158
143
- const updateArgFromDedicatedEditor = ( value : string = '' ) => {
159
+ const updateArgFromDedicatedEditor = ( value : string , selectedLang : DSL ) => {
144
160
if ( ! monacoObjects . current ) return
145
161
const { editor } = monacoObjects ?. current
146
162
147
163
const model = editor . getModel ( )
148
164
if ( ! model ) return
149
-
150
165
const position = editor . getPosition ( )
151
166
152
167
editor . updateOptions ( { readOnly : false } )
@@ -163,15 +178,17 @@ const MonacoEditor = (props: Props) => {
163
178
] )
164
179
setIsDedicatedEditorOpen ( false )
165
180
triggerUpdateCursorPosition ( editor )
181
+ onSubmitDedicatedEditor ?.( selectedLang )
166
182
}
167
183
168
- const onCancelDedicatedEditor = ( ) => {
184
+ const onCancelDedicatedEditor = ( selectedLang : DSL ) => {
169
185
setIsDedicatedEditorOpen ( false )
170
186
if ( ! monacoObjects . current ) return
171
187
const { editor } = monacoObjects ?. current
172
188
173
189
editor . updateOptions ( { readOnly : false } )
174
190
triggerUpdateCursorPosition ( editor )
191
+ onCloseDedicatedEditor ?.( selectedLang )
175
192
}
176
193
177
194
if ( monacoEditor ?. editor ) {
0 commit comments