@@ -9,73 +9,73 @@ import * as monaco from 'monaco-editor';
9
9
import { setupThemePromise } from ' ./utils' ;
10
10
11
11
interface Props {
12
- value? : string
13
- language? : string ;
14
- readonly? : boolean
12
+ value? : string
13
+ language? : string ;
14
+ readonly? : boolean
15
15
}
16
16
17
17
const props = withDefaults (defineProps <Props >(), {
18
- value: ' ' ,
19
- readonly: false
18
+ value: ' ' ,
19
+ readonly: false
20
20
})
21
21
22
22
const emits = defineEmits <{
23
- (e : ' change' , value : string ): void ,
24
- (e : ' save' , value : string ): void
23
+ (e : ' change' , value : string ): void ,
24
+ (e : ' save' , value : string ): void
25
25
}>()
26
26
27
27
const containerRef = ref <HTMLDivElement | null >();
28
28
const ready = ref (false );
29
29
const editor = shallowRef <monaco .editor .IStandaloneCodeEditor | undefined >(undefined );
30
30
31
31
onMounted (async () => {
32
- const theme = await setupThemePromise ;
33
- ready .value = true ;
34
- await nextTick ();
32
+ const theme = await setupThemePromise ;
33
+ ready .value = true ;
34
+ await nextTick ();
35
35
36
- if (! containerRef .value ) {
37
- throw new Error (" Cannot find containerRef" );
38
- }
36
+ if (! containerRef .value ) {
37
+ throw new Error (" Cannot find containerRef" );
38
+ }
39
39
40
- const editorInstance = monaco .editor .create (containerRef .value , {
41
- theme ,
42
- value: props .value ,
43
- language: props .language ,
44
- readOnly: props .readonly ,
45
- automaticLayout: true ,
46
- scrollBeyondLastLine: false ,
47
- minimap: {
48
- enabled: false ,
49
- },
50
- inlineSuggest: {
51
- enabled: false ,
52
- },
53
- });
54
- editor .value = editorInstance
40
+ const editorInstance = monaco .editor .create (containerRef .value , {
41
+ theme ,
42
+ value: props .value ,
43
+ language: props .language ,
44
+ readOnly: props .readonly ,
45
+ automaticLayout: true ,
46
+ scrollBeyondLastLine: false ,
47
+ minimap: {
48
+ enabled: false ,
49
+ },
50
+ inlineSuggest: {
51
+ enabled: false ,
52
+ },
53
+ });
54
+ editor .value = editorInstance
55
55
56
- await loadGrammars (editorInstance );
56
+ await loadGrammars (editorInstance );
57
57
58
- editorInstance .addCommand (monaco .KeyMod .CtrlCmd | monaco .KeyCode .KeyS , () => {
59
- emits (' save' , editorInstance .getValue ());
60
- });
58
+ editorInstance .addCommand (monaco .KeyMod .CtrlCmd | monaco .KeyCode .KeyS , () => {
59
+ emits (' save' , editorInstance .getValue ());
60
+ });
61
61
62
- editorInstance .onDidChangeModelContent (() => {
63
- emits (' change' , editorInstance .getValue ());
64
- });
62
+ editorInstance .onDidChangeModelContent (() => {
63
+ emits (' change' , editorInstance .getValue ());
64
+ });
65
65
});
66
66
67
67
watchEffect (() => {
68
- if (editor .value && editor .value .getValue () !== props .value ) {
69
- editor .value .setValue (props .value );
70
- }
68
+ if (editor .value && editor .value .getValue () !== props .value ) {
69
+ editor .value .setValue (props .value );
70
+ }
71
71
})
72
72
73
73
onBeforeUnmount (() => {
74
- editor .value ?.dispose ();
74
+ editor .value ?.dispose ();
75
75
});
76
76
</script >
77
77
<template >
78
- <div class =" editor" ref =" containerRef" ></div >
78
+ <div class =" editor" ref =" containerRef" ></div >
79
79
</template >
80
80
<style >
81
81
.editor {
0 commit comments