|
|
@@ -0,0 +1,54 @@
|
|
|
+<script setup lang="ts">
|
|
|
+import { onMounted, onBeforeUnmount, ref, watch } from 'vue'
|
|
|
+import * as monaco from 'monaco-editor'
|
|
|
+import { initMonaco } from '.'
|
|
|
+import { createEditor, createModel } from './editor'
|
|
|
+import { LOG_LANGUAGE_ID } from './languages/log'
|
|
|
+
|
|
|
+const props = defineProps<{
|
|
|
+ modelValue: string
|
|
|
+}>()
|
|
|
+
|
|
|
+const emit = defineEmits<{
|
|
|
+ (e: 'update:modelValue', v: string): void
|
|
|
+}>()
|
|
|
+
|
|
|
+const container = ref<HTMLDivElement>()
|
|
|
+
|
|
|
+let editor: monaco.editor.IStandaloneCodeEditor
|
|
|
+let model: monaco.editor.ITextModel
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ initMonaco()
|
|
|
+
|
|
|
+ model = createModel(props.modelValue, LOG_LANGUAGE_ID)
|
|
|
+
|
|
|
+ editor = createEditor(container.value!, {
|
|
|
+ model,
|
|
|
+ theme: 'log-dark',
|
|
|
+ readOnly: false
|
|
|
+ })
|
|
|
+
|
|
|
+ editor.onDidChangeModelContent(() => {
|
|
|
+ emit('update:modelValue', model.getValue())
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+watch(
|
|
|
+ () => props.modelValue,
|
|
|
+ v => {
|
|
|
+ if (v !== model?.getValue()) {
|
|
|
+ model?.setValue(v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+)
|
|
|
+
|
|
|
+onBeforeUnmount(() => {
|
|
|
+ editor?.dispose()
|
|
|
+ model?.dispose()
|
|
|
+})
|
|
|
+</script>
|
|
|
+
|
|
|
+<template>
|
|
|
+ <div ref="container" style="width: 100%; height: 100%" />
|
|
|
+</template>
|