antares/src/renderer/components/QueryEditor.vue

62 lines
1.2 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>
import * as ace from 'ace-builds';
import 'ace-builds/webpack-resolver';
import 'ace-builds/src-noconflict/ext-language_tools';
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 () {
this.editor = ace.edit(this.$refs.editor, {
mode: 'ace/mode/sql',
theme: 'ace/theme/twilight',
2020-08-20 18:06:02 +02:00
value: this.value,
fontSize: '14px',
printMargin: false
2020-08-20 18:06:02 +02:00
});
2020-05-07 17:45:04 +02:00
this.editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true
});
this.editor.session.on('change', () => {
2020-08-20 18:06:02 +02:00
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-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-05-07 17:45:04 +02:00
</style>