summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/snippet/snippet_bundle.js
blob: 76a1f6d1458880ea774c47f7cdd3cf569b7fbb96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { initEditorLite } from '~/blob/utils';
import setupCollapsibleInputs from './collapsible_input';

let editor;

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');

  editor = initEditorLite({
    el: editorEl,
    blobPath: fileNameEl.value,
    blobContent: contentEl.value,
  });

  fileNameEl.addEventListener('change', () => {
    editor.updateModelLanguage(fileNameEl.value);
  });

  form.addEventListener('submit', () => {
    contentEl.value = editor.getValue();
  });
};

export default () => {
  initMonaco();
  setupCollapsibleInputs();
};