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

76 lines
1.7 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';
import {
SNIPPET_MARK_BLOBS_CONTENT,
SNIPPET_MARK_EDIT_APP_START,
SNIPPET_MEASURE_BLOBS_CONTENT,
SNIPPET_MEASURE_BLOBS_CONTENT_WITHIN_APP,
} from '~/performance_constants';
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,
});
this.editor.onChangeContent(debounce(this.onFileChange.bind(this), 250));
window.requestAnimationFrame(() => {
if (!performance.getEntriesByName(SNIPPET_MARK_BLOBS_CONTENT).length) {
performance.mark(SNIPPET_MARK_BLOBS_CONTENT);
performance.measure(SNIPPET_MEASURE_BLOBS_CONTENT);
performance.measure(SNIPPET_MEASURE_BLOBS_CONTENT_WITHIN_APP, SNIPPET_MARK_EDIT_APP_START);
}
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>