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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

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';
2021-09-30 23:02:18 +05:30
import { initSourceEditor } from '~/blob/utils';
2021-01-29 00:20:46 +05:30
import { SNIPPET_MEASURE_BLOBS_CONTENT } from '~/performance/constants';
2021-01-03 14:25:43 +05:30
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() {
2021-09-30 23:02:18 +05:30
this.editor = initSourceEditor({
2020-04-08 14:13:33 +05:30
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>