2020-03-09 09:07:45 +00:00
|
|
|
import { initEditorLite } from '~/blob/utils';
|
2020-02-13 15:08:52 +00:00
|
|
|
import setupCollapsibleInputs from './collapsible_input';
|
2018-03-09 20:18:59 +00:00
|
|
|
|
2020-02-28 15:09:13 +00:00
|
|
|
let editor;
|
|
|
|
|
|
|
|
const initAce = () => {
|
2020-03-09 09:07:45 +00:00
|
|
|
const editorEl = document.getElementById('editor');
|
2020-02-28 15:09:13 +00:00
|
|
|
const form = document.querySelector('.snippet-form-holder form');
|
|
|
|
const content = document.querySelector('.snippet-file-content');
|
2020-03-09 09:07:45 +00:00
|
|
|
|
|
|
|
editor = initEditorLite({ el: editorEl });
|
|
|
|
|
2020-02-28 15:09:13 +00:00
|
|
|
form.addEventListener('submit', () => {
|
|
|
|
content.value = editor.getValue();
|
|
|
|
});
|
|
|
|
};
|
2016-06-24 18:26:11 +00:00
|
|
|
|
2020-02-28 15:09:13 +00:00
|
|
|
const initMonaco = () => {
|
|
|
|
const editorEl = document.getElementById('editor');
|
|
|
|
const contentEl = document.querySelector('.snippet-file-content');
|
2020-03-05 18:08:19 +00:00
|
|
|
const fileNameEl = document.querySelector('.js-snippet-file-name');
|
2020-02-28 15:09:13 +00:00
|
|
|
const form = document.querySelector('.snippet-form-holder form');
|
|
|
|
|
2020-03-09 09:07:45 +00:00
|
|
|
editor = initEditorLite({
|
2020-02-28 15:09:13 +00:00
|
|
|
el: editorEl,
|
|
|
|
blobPath: fileNameEl.value,
|
|
|
|
blobContent: contentEl.value,
|
2016-06-24 18:26:11 +00:00
|
|
|
});
|
2020-02-13 15:08:52 +00:00
|
|
|
|
2020-02-28 15:09:13 +00:00
|
|
|
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-02-13 15:08:52 +00:00
|
|
|
setupCollapsibleInputs();
|
2018-02-27 21:47:34 +00:00
|
|
|
};
|
2020-02-28 15:09:13 +00:00
|
|
|
|
|
|
|
export default () => {
|
|
|
|
initEditor();
|
|
|
|
};
|