171
171
172
172
<!-- YAML editor -->
173
173
<div class =" shadow-box mb-3 editor-box" :class =" {'edit-mode' : isEditMode}" >
174
- <prism-editor
174
+ <code-mirror
175
175
ref =" editor"
176
176
v-model =" stack.composeYAML"
177
- class =" yaml-editor"
178
- :highlight =" highlighterYAML"
179
- line-numbers :readonly =" !isEditMode"
180
- @input =" yamlCodeChange"
181
- @focus =" editorFocus = true"
182
- @blur =" editorFocus = false"
183
- ></prism-editor >
177
+ :extensions =" extensions"
178
+ minimal
179
+ wrap =" true"
180
+ dark =" true"
181
+ tab =" true"
182
+ :disabled =" !isEditMode"
183
+ :hasFocus =" editorFocus"
184
+ @change =" yamlCodeChange"
185
+ />
184
186
</div >
185
187
<div v-if =" isEditMode" class =" mb-3" >
186
188
{{ yamlError }}
190
192
<div v-if =" isEditMode" >
191
193
<h4 class =" mb-3" >.env</h4 >
192
194
<div class =" shadow-box mb-3 editor-box" :class =" {'edit-mode' : isEditMode}" >
193
- <prism-editor
195
+ <code-mirror
194
196
ref =" editor"
195
197
v-model =" stack.composeENV"
196
- class =" env-editor"
197
- :highlight =" highlighterENV"
198
- line-numbers :readonly =" !isEditMode"
199
- @focus =" editorFocus = true"
200
- @blur =" editorFocus = false"
201
- ></prism-editor >
198
+ :extensions =" extensionsEnv"
199
+ minimal
200
+ wrap =" true"
201
+ dark =" true"
202
+ tab =" true"
203
+ :disabled =" !isEditMode"
204
+ :hasFocus =" editorFocus"
205
+ @change =" yamlCodeChange"
206
+ />
202
207
</div >
203
208
</div >
204
209
241
246
</template >
242
247
243
248
<script >
244
- import { highlight , languages } from " prismjs/components/prism-core" ;
245
- import { PrismEditor } from " vue-prism-editor" ;
246
- import " prismjs/components/prism-yaml" ;
249
+ import CodeMirror from " vue-codemirror6" ;
250
+ import { yaml } from " @codemirror/lang-yaml" ;
251
+ import { python } from " @codemirror/lang-python" ;
252
+ import { dracula as editorTheme } from " thememirror" ;
253
+ import { lineNumbers , EditorView } from " @codemirror/view" ;
247
254
import { parseDocument , Document } from " yaml" ;
248
255
249
- import " prismjs/themes/prism-tomorrow.css" ;
250
- import " vue-prism-editor/dist/prismeditor.min.css" ;
251
256
import { FontAwesomeIcon } from " @fortawesome/vue-fontawesome" ;
252
257
import {
253
258
COMBINED_TERMINAL_COLS ,
@@ -261,6 +266,7 @@ import {
261
266
import { BModal } from " bootstrap-vue-next" ;
262
267
import NetworkInput from " ../components/NetworkInput.vue" ;
263
268
import dotenv from " dotenv" ;
269
+ import { ref } from " vue" ;
264
270
265
271
const template = `
266
272
services:
@@ -275,17 +281,12 @@ const envDefault = "# VARIABLE=value #comment";
275
281
let yamlErrorTimeout = null ;
276
282
277
283
let serviceStatusTimeout = null ;
278
- let prismjsSymbolDefinition = {
279
- " symbol" : {
280
- pattern: / (?<!\$ )\$ (\{ [^ {}] * \} | \w + )/ ,
281
- }
282
- };
283
284
284
285
export default {
285
286
components: {
286
287
NetworkInput,
287
288
FontAwesomeIcon,
288
- PrismEditor ,
289
+ CodeMirror ,
289
290
BModal,
290
291
},
291
292
beforeRouteUpdate (to , from , next ) {
@@ -294,10 +295,35 @@ export default {
294
295
beforeRouteLeave (to , from , next ) {
295
296
this .exitConfirm (next);
296
297
},
298
+ setup () {
299
+ const editorFocus = ref (false );
300
+
301
+ const focusEffectHandler = (state , focusing ) => {
302
+ editorFocus .value = focusing;
303
+ return null ;
304
+ };
305
+
306
+ const extensions = [
307
+ editorTheme,
308
+ yaml (),
309
+ lineNumbers (),
310
+ EditorView .focusChangeEffect .of (focusEffectHandler)
311
+ ];
312
+
313
+ const extensionsEnv = [
314
+ editorTheme,
315
+ python (),
316
+ lineNumbers (),
317
+ EditorView .focusChangeEffect .of (focusEffectHandler)
318
+ ];
319
+
320
+ return { extensions,
321
+ extensionsEnv,
322
+ editorFocus };
323
+ },
297
324
yamlDoc: null , // For keeping the yaml comments
298
325
data () {
299
326
return {
300
- editorFocus: false ,
301
327
jsonConfig: {},
302
328
envsubstJSONConfig: {},
303
329
yamlError: " " ,
@@ -318,7 +344,6 @@ export default {
318
344
};
319
345
},
320
346
computed: {
321
-
322
347
endpointDisplay () {
323
348
return this .$root .endpointDisplayFunction (this .endpoint );
324
349
},
@@ -668,46 +693,6 @@ export default {
668
693
this .isEditMode = false ;
669
694
},
670
695
671
- highlighterYAML (code ) {
672
- if (! languages .yaml_with_symbols ) {
673
- languages .yaml_with_symbols = languages .insertBefore (" yaml" , " punctuation" , {
674
- " symbol" : prismjsSymbolDefinition[" symbol" ]
675
- });
676
- }
677
- return highlight (code, languages .yaml_with_symbols );
678
- },
679
-
680
- highlighterENV (code ) {
681
- if (! languages .docker_env ) {
682
- languages .docker_env = {
683
- " comment" : {
684
- pattern: / (^ #| #). * $ / m ,
685
- greedy: true
686
- },
687
- " keyword" : {
688
- pattern: / ^ \w * (?=[:=] )/ m ,
689
- greedy: true
690
- },
691
- " value" : {
692
- pattern: / (?<=[:=] ). *? ((?= #)| $ )/ m ,
693
- greedy: true ,
694
- inside: {
695
- " string" : [
696
- {
697
- pattern: / ^ * '. *? (?<!\\ )'/ m ,
698
- },
699
- {
700
- pattern: / ^ * ". *? (?<!\\ )"| ^ . * $ / m ,
701
- inside: prismjsSymbolDefinition
702
- },
703
- ],
704
- },
705
- },
706
- };
707
- }
708
- return highlight (code, languages .docker_env );
709
- },
710
-
711
696
yamlToJSON (yaml ) {
712
697
let doc = parseDocument (yaml);
713
698
if (doc .errors .length > 0 ) {
0 commit comments