@@ -9,73 +9,73 @@ import * as monaco from 'monaco-editor';
99import { setupThemePromise } from ' ./utils' ;
1010
1111interface Props {
12- value? : string
13- language? : string ;
14- readonly? : boolean
12+ value? : string
13+ language? : string ;
14+ readonly? : boolean
1515}
1616
1717const props = withDefaults (defineProps <Props >(), {
18- value: ' ' ,
19- readonly: false
18+ value: ' ' ,
19+ readonly: false
2020})
2121
2222const 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
2525}>()
2626
2727const containerRef = ref <HTMLDivElement | null >();
2828const ready = ref (false );
2929const editor = shallowRef <monaco .editor .IStandaloneCodeEditor | undefined >(undefined );
3030
3131onMounted (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 ();
3535
36- if (! containerRef .value ) {
37- throw new Error (" Cannot find containerRef" );
38- }
36+ if (! containerRef .value ) {
37+ throw new Error (" Cannot find containerRef" );
38+ }
3939
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
5555
56- await loadGrammars (editorInstance );
56+ await loadGrammars (editorInstance );
5757
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+ });
6161
62- editorInstance .onDidChangeModelContent (() => {
63- emits (' change' , editorInstance .getValue ());
64- });
62+ editorInstance .onDidChangeModelContent (() => {
63+ emits (' change' , editorInstance .getValue ());
64+ });
6565});
6666
6767watchEffect (() => {
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+ }
7171})
7272
7373onBeforeUnmount (() => {
74- editor .value ?.dispose ();
74+ editor .value ?.dispose ();
7575});
7676 </script >
7777<template >
78- <div class =" editor" ref =" containerRef" ></div >
78+ <div class =" editor" ref =" containerRef" ></div >
7979</template >
8080<style >
8181.editor {
0 commit comments