2020-04-08 14:13:33 +05:30
|
|
|
import { initEditorLite } from '~/blob/utils';
|
2020-03-13 15:44:24 +05:30
|
|
|
import setupCollapsibleInputs from './collapsible_input';
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
let editor;
|
|
|
|
|
|
|
|
const initAce = () => {
|
|
|
|
const editorEl = document.getElementById('editor');
|
|
|
|
const form = document.querySelector('.snippet-form-holder form');
|
|
|
|
const content = document.querySelector('.snippet-file-content');
|
|
|
|
|
|
|
|
editor = initEditorLite({ el: editorEl });
|
|
|
|
|
|
|
|
form.addEventListener('submit', () => {
|
|
|
|
content.value = editor.getValue();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const initMonaco = () => {
|
|
|
|
const editorEl = document.getElementById('editor');
|
|
|
|
const contentEl = document.querySelector('.snippet-file-content');
|
|
|
|
const fileNameEl = document.querySelector('.js-snippet-file-name');
|
|
|
|
const form = document.querySelector('.snippet-form-holder form');
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
editor = initEditorLite({
|
|
|
|
el: editorEl,
|
|
|
|
blobPath: fileNameEl.value,
|
|
|
|
blobContent: contentEl.value,
|
2016-09-13 17:45:13 +05:30
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
fileNameEl.addEventListener('change', () => {
|
|
|
|
editor.updateModelLanguage(fileNameEl.value);
|
|
|
|
});
|
|
|
|
|
|
|
|
form.addEventListener('submit', () => {
|
|
|
|
contentEl.value = editor.getValue();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const initEditor = () => {
|
|
|
|
if (window?.gon?.features?.monacoSnippets) {
|
|
|
|
initMonaco();
|
|
|
|
} else {
|
|
|
|
initAce();
|
|
|
|
}
|
2020-03-13 15:44:24 +05:30
|
|
|
setupCollapsibleInputs();
|
2018-03-27 19:54:05 +05:30
|
|
|
};
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
export default () => {
|
|
|
|
initEditor();
|
|
|
|
};
|