-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
45 lines (37 loc) · 1.09 KB
/
main.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { createEditor, getMarkdown } from './editor/editor';
const importButton = document.getElementById('import-button');
const importDialog = document.getElementById('import-dialog');
const importTextarea = document.getElementById('import-textarea');
const exportButton = document.getElementById('export-button');
const exportDialog = document.getElementById('export-dialog');
const exportTextarea = document.getElementById('export-textarea');
const resetButton = document.getElementById('reset-button');
let editor = createEditor();
/**
* Import
*/
importButton.addEventListener('click', () => {
importDialog.showModal();
});
importDialog.addEventListener('close', () => {
const markdown = importTextarea.value;
importTextarea.value = "";
if (markdown) {
editor.destroy();
editor = createEditor({ markdown });
}
});
/**
* Export
*/
exportButton.addEventListener('click', async () => {
exportDialog.showModal();
exportTextarea.value = await getMarkdown(editor);
});
/**
* Reset
*/
resetButton.addEventListener('click', () => {
editor.destroy();
editor = createEditor();
});