Add monaco editor

This commit is contained in:
2024-03-07 13:41:39 +02:00
parent 650267ca1e
commit de7abfadd9
14 changed files with 334 additions and 197 deletions

View File

@ -0,0 +1,60 @@
<template>
<div :id="name"></div>
</template>
<script>
import loader from '@monaco-editor/loader';
let monacoResultInst = null;
export default {
name: "monacoEditor",
props: {
name: {
type: String,
required: true,
},
language: {
type: String,
default: 'text',
},
value: {
type: String,
default: '',
},
readonly: {
type: Boolean,
default: true,
},
},
mounted() {
loader.init().then((monaco) => {
monacoResultInst = monaco;
monaco.editor.create(document.querySelector(`#${this.name}`), {
value: '',
language: this.language,
readOnly: this.readonly,
});
});
},
watch: {
value: {
// the callback will be called immediately after the start of the observation
immediate: true,
deep: true,
async handler(value, oldValue) {
while (!monacoResultInst) {
await new Promise(r => setTimeout(r, 10));
}
monacoResultInst.editor.getModels()[0].setValue(value.toString());
}
}
}
};
</script>
<style scoped>
</style>