antares/src/renderer/components/QueryEditor.vue

78 lines
1.6 KiB
Vue
Raw Normal View History

2020-05-07 17:45:04 +02:00
<template>
<div class="editor-wrapper">
2020-08-20 18:06:02 +02:00
<div ref="editor" class="editor" />
2020-05-07 17:45:04 +02:00
</div>
</template>
<script>
2020-08-20 18:06:02 +02:00
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
2020-08-21 11:38:00 +02:00
import { completionItemProvider } from '@/suggestions/sql';
2020-05-07 17:45:04 +02:00
2020-08-21 11:38:00 +02:00
monaco.languages.registerCompletionItemProvider('sql', completionItemProvider(monaco));
2020-05-07 17:45:04 +02:00
export default {
name: 'QueryEditor',
props: {
2020-12-11 15:55:18 +01:00
value: String,
autoFocus: { type: Boolean, default: false }
2020-05-07 17:45:04 +02:00
},
data () {
return {
2020-08-20 18:06:02 +02:00
editor: null
2020-05-07 17:45:04 +02:00
};
},
mounted () {
2020-08-20 18:06:02 +02:00
this.editor = monaco.editor.create(this.$refs.editor, {
value: this.value,
language: 'sql',
theme: 'vs-dark',
autoIndent: true,
minimap: {
enabled: false
},
contextmenu: false,
2020-08-21 11:38:00 +02:00
wordBasedSuggestions: true,
2020-08-20 18:06:02 +02:00
acceptSuggestionOnEnter: 'smart',
2020-08-21 11:38:00 +02:00
quickSuggestions: true
2020-08-20 18:06:02 +02:00
});
2020-05-07 17:45:04 +02:00
2020-08-20 18:06:02 +02:00
this.editor.onDidChangeModelContent(e => {
const content = this.editor.getValue();
this.$emit('update:value', content);
});
2020-12-11 15:55:18 +01:00
if (this.autoFocus) {
setTimeout(() => {
this.editor.focus();
}, 20);
}
2020-08-20 18:06:02 +02:00
},
beforeDestroy () {
this.editor && this.editor.dispose();
2020-05-07 17:45:04 +02:00
}
};
</script>
2020-06-05 21:00:15 +02:00
<style lang="scss">
2020-07-31 18:16:28 +02:00
.editor-wrapper {
border-bottom: 1px solid #444;
2020-08-20 18:06:02 +02:00
.editor {
height: 200px;
width: 100%;
}
2020-07-31 18:16:28 +02:00
}
2020-06-05 21:00:15 +02:00
2020-07-31 18:16:28 +02:00
.CodeMirror {
.CodeMirror-scroll {
max-width: 100%;
}
2020-06-05 21:00:15 +02:00
2020-07-31 18:16:28 +02:00
.CodeMirror-line {
word-break: break-word !important;
white-space: pre-wrap !important;
}
}
2020-05-07 17:45:04 +02:00
</style>