diff options
Diffstat (limited to 'src/ui/c-diff-editor/c-diff-editor.vue')
-rw-r--r-- | src/ui/c-diff-editor/c-diff-editor.vue | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/ui/c-diff-editor/c-diff-editor.vue b/src/ui/c-diff-editor/c-diff-editor.vue new file mode 100644 index 0000000..2aa2947 --- /dev/null +++ b/src/ui/c-diff-editor/c-diff-editor.vue @@ -0,0 +1,68 @@ +<script setup lang="ts"> +import * as monaco from 'monaco-editor'; +import { useStyleStore } from '@/stores/style.store'; + +const props = withDefaults(defineProps<{ options?: monaco.editor.IDiffEditorOptions }>(), { options: () => ({}) }); +const { options } = toRefs(props); + +const editorContainer = ref<HTMLElement | null>(null); +let editor: monaco.editor.IStandaloneDiffEditor | null = null; + +monaco.editor.defineTheme('it-tools-dark', { + base: 'vs-dark', + inherit: true, + rules: [], + colors: { + 'editor.background': '#00000000', + }, +}); + +monaco.editor.defineTheme('it-tools-light', { + base: 'vs', + inherit: true, + rules: [], + colors: { + 'editor.background': '#00000000', + }, +}); + +const styleStore = useStyleStore(); + +watch( + () => styleStore.isDarkTheme, + isDarkTheme => monaco.editor.setTheme(isDarkTheme ? 'it-tools-dark' : 'it-tools-light'), + { immediate: true }, +); + +watch( + () => options.value, + options => editor?.updateOptions(options), + { immediate: true, deep: true }, +); + +useResizeObserver(editorContainer, () => { + editor?.layout(); +}); + +onMounted(() => { + if (!editorContainer.value) { + return; + } + + editor = monaco.editor.createDiffEditor(editorContainer.value, { + originalEditable: true, + minimap: { + enabled: false, + }, + }); + + editor.setModel({ + original: monaco.editor.createModel('original text', 'txt'), + modified: monaco.editor.createModel('modified text', 'txt'), + }); +}); +</script> + +<template> + <div ref="editorContainer" h-600px /> +</template> |