debian-mirror-gitlab/app/assets/javascripts/blob/components/blob_edit_content.vue

47 lines
919 B
Vue
Raw Normal View History

2020-04-08 14:13:33 +05:30
<script>
import { initEditorLite } from '~/blob/utils';
2020-04-22 19:07:51 +05:30
import { debounce } from 'lodash';
2020-04-08 14:13:33 +05:30
export default {
props: {
value: {
type: String,
2020-04-22 19:07:51 +05:30
required: false,
default: '',
2020-04-08 14:13:33 +05:30
},
fileName: {
type: String,
required: false,
default: '',
},
},
data() {
return {
editor: null,
};
},
watch: {
fileName(newVal) {
this.editor.updateModelLanguage(newVal);
},
},
mounted() {
this.editor = initEditorLite({
el: this.$refs.editor,
blobPath: this.fileName,
2020-04-22 19:07:51 +05:30
blobContent: this.value,
2020-04-08 14:13:33 +05:30
});
},
methods: {
2020-04-22 19:07:51 +05:30
triggerFileChange: debounce(function debouncedFileChange() {
this.$emit('input', this.editor.getValue());
}, 250),
2020-04-08 14:13:33 +05:30
},
};
</script>
<template>
<div class="file-content code">
2020-04-22 19:07:51 +05:30
<pre id="editor" ref="editor" data-editor-loading @keyup="triggerFileChange">{{ value }}</pre>
2020-04-08 14:13:33 +05:30
</div>
</template>