mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
3.6 KiB
136 lines
3.6 KiB
4 years ago
|
<template>
|
||
3 years ago
|
<v-container class="ma-0 pa-0" fluid>
|
||
4 years ago
|
<v-col cols="12" class="px-0">
|
||
|
<v-toolbar text height="42" class="grey--text">
|
||
|
{{ heading }}
|
||
3 years ago
|
<v-spacer />
|
||
3 years ago
|
<x-btn tooltip="Prettify SQL" small outlined btn.class="grey--text" @click="pretify"> Prettify </x-btn>
|
||
3 years ago
|
</v-toolbar>
|
||
4 years ago
|
<monaco-editor
|
||
3 years ago
|
ref="editor"
|
||
|
v-model="codeLocal"
|
||
4 years ago
|
:style="cssStyle ? cssStyle : ''"
|
||
|
class="editor card"
|
||
|
theme="vs-dark"
|
||
3 years ago
|
lang="sql"
|
||
4 years ago
|
:minimap="minimap"
|
||
3 years ago
|
:read-only="readOnly"
|
||
|
@selection="selectionFn"
|
||
|
/>
|
||
4 years ago
|
</v-col>
|
||
|
</v-container>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import sqlFormatter from 'sql-formatter';
|
||
|
import MonacoEditor from './index.js';
|
||
4 years ago
|
|
||
3 years ago
|
export default {
|
||
|
ssr: false,
|
||
|
components: {
|
||
3 years ago
|
MonacoEditor,
|
||
3 years ago
|
// sqlFormatter
|
||
|
},
|
||
|
props: ['code', 'cssStyle', 'readOnly', 'heading'],
|
||
3 years ago
|
data() {
|
||
3 years ago
|
return {
|
||
|
codeLocal: `${this.code || ''}`,
|
||
|
selection: null,
|
||
|
minimap: {
|
||
3 years ago
|
enabled: true,
|
||
|
},
|
||
|
};
|
||
3 years ago
|
},
|
||
|
computed: {},
|
||
|
watch: {
|
||
3 years ago
|
codeLocal(newValue) {
|
||
3 years ago
|
// INFO: for updating value of prop `code` in parent comp
|
||
3 years ago
|
this.$emit('update:code', newValue);
|
||
4 years ago
|
},
|
||
3 years ago
|
code(newValue) {
|
||
3 years ago
|
this.codeLocal = newValue;
|
||
|
},
|
||
3 years ago
|
},
|
||
3 years ago
|
beforeCreate() {
|
||
3 years ago
|
// console.log(MonacoEditor)
|
||
|
},
|
||
3 years ago
|
created() {
|
||
3 years ago
|
//
|
||
|
},
|
||
|
methods: {
|
||
3 years ago
|
selectionFn() {
|
||
3 years ago
|
const editor = this.$refs.editor.getMonaco();
|
||
|
const range = editor.getSelection();
|
||
|
const selectedText = editor.getModel().getValueInRange(range);
|
||
|
this.selection = selectedText;
|
||
|
this.selectionRange = range;
|
||
4 years ago
|
},
|
||
3 years ago
|
pretify() {
|
||
3 years ago
|
// console.log("this.code", this.code);
|
||
3 years ago
|
const editor = this.$refs.editor.getMonaco();
|
||
4 years ago
|
|
||
3 years ago
|
if (this.selection && this.selectionRange) {
|
||
|
const op = {
|
||
|
identifier: 'prettifySelection',
|
||
|
range: this.selectionRange,
|
||
|
text: sqlFormatter.format(this.selection),
|
||
3 years ago
|
forceMoveMarkers: true,
|
||
|
};
|
||
|
editor.executeEdits('sqlFormatter', [op]);
|
||
|
this.selection = null;
|
||
|
this.selectionRange = null;
|
||
3 years ago
|
} else {
|
||
|
// console.log("selected format before:: ", this.codeLocal);
|
||
|
const op = {
|
||
|
identifier: 'prettifyDoc',
|
||
|
range: editor.getModel().getFullModelRange(),
|
||
|
text: sqlFormatter.format(this.codeLocal || ''),
|
||
3 years ago
|
forceMoveMarkers: true,
|
||
|
};
|
||
|
editor.executeEdits('sqlFormatter', [op]);
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
toggleMiniMap() {
|
||
3 years ago
|
const editor = this.$refs.editor.getMonaco();
|
||
|
this.minimap.enabled = !this.minimap.enabled;
|
||
3 years ago
|
editor.updateOptions({
|
||
|
minimap: {
|
||
3 years ago
|
enabled: this.minimap.enabled,
|
||
|
},
|
||
|
});
|
||
|
},
|
||
|
},
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
|
<style>
|
||
3 years ago
|
.editor {
|
||
|
/* width: 100%;
|
||
4 years ago
|
height: 800px; */
|
||
3 years ago
|
}
|
||
4 years ago
|
</style>
|
||
|
<!--
|
||
|
/**
|
||
|
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
|
||
|
*
|
||
|
* @author Naveen MR <oof1lab@gmail.com>
|
||
|
* @author Pranav C Balan <pranavxc@gmail.com>
|
||
|
*
|
||
|
* @license GNU AGPL version 3 or any later version
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of the
|
||
|
* License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Affero General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|