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

67 lines
1.4 KiB
Vue
Raw Normal View History

2020-04-08 14:13:33 +05:30
<script>
2020-04-22 19:07:51 +05:30
import { debounce } from 'lodash';
2020-10-24 23:57:45 +05:30
import { initEditorLite } from '~/blob/utils';
2021-01-03 14:25:43 +05:30
import { SNIPPET_MEASURE_BLOBS_CONTENT } from '~/performance_constants';
import eventHub from './eventhub';
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: '',
},
2020-10-24 23:57:45 +05:30
// This is used to help uniquely create a monaco model
// even if two blob's share a file path.
fileGlobalId: {
type: String,
required: false,
default: '',
},
2020-04-08 14:13:33 +05:30
},
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-10-24 23:57:45 +05:30
blobGlobalId: this.fileGlobalId,
});
2020-11-24 15:15:51 +05:30
this.editor.onDidChangeModelContent(debounce(this.onFileChange.bind(this), 250));
2020-10-24 23:57:45 +05:30
2021-01-03 14:25:43 +05:30
eventHub.$emit(SNIPPET_MEASURE_BLOBS_CONTENT);
2020-04-08 14:13:33 +05:30
},
2020-10-24 23:57:45 +05:30
beforeDestroy() {
this.editor.dispose();
},
2020-04-08 14:13:33 +05:30
methods: {
2020-10-24 23:57:45 +05:30
onFileChange() {
2020-04-22 19:07:51 +05:30
this.$emit('input', this.editor.getValue());
2020-10-24 23:57:45 +05:30
},
2020-04-08 14:13:33 +05:30
},
};
</script>
<template>
<div class="file-content code">
2020-10-24 23:57:45 +05:30
<div id="editor" ref="editor" data-editor-loading>
<pre class="editor-loading-content">{{ value }}</pre>
</div>
2020-04-08 14:13:33 +05:30
</div>
</template>