-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentry_editor.js
More file actions
100 lines (85 loc) · 2.67 KB
/
Copy pathentry_editor.js
File metadata and controls
100 lines (85 loc) · 2.67 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { el, ValueInput, MarginBox, OptionInput } from './utils.js';
import { TagEditor } from './tag_editor.js';
export function EntryEditor(entryUrl, text, meta, allTags) {
const dom = el('div');
dom.classList.add('entreate-entry-editor');
const homeButton = el('button', {
onclick: (e) => {
dom.dispatchEvent(new CustomEvent('close', {
bubbles: true,
}));
},
classList: ['entreate-button'],
});
homeButton.innerText = 'Home';
dom.appendChild(homeButton);
let visibility = meta.visibility ? meta.visibility : 'private';
const saveButton = el('button', {
onclick: (e) => {
dom.dispatchEvent(new CustomEvent('save', {
bubbles: true,
detail: {
entryUrl,
text: editor.getValue(),
meta: Object.assign(meta, {
title: titleInput.getValue() ? titleInput.getValue() : 'Untitled',
tags,
visibility,
}),
},
}));
},
classList: ['entreate-button'],
});
saveButton.classList.add('entreate-button', 'entreate-button-confirm');
saveButton.innerText = 'Save';
dom.appendChild(saveButton);
const titleInput = ValueInput('Title', meta.title);
dom.appendChild(MarginBox(titleInput.dom));
const visibilityOptionInput = OptionInput('Visibility', ['private', 'friends', 'public'], visibility);
dom.appendChild(MarginBox(visibilityOptionInput));
visibilityOptionInput.addEventListener('option-selected', (e) => {
visibility = e.detail.option;
});
let tags = meta.tags;
const tagEditor = TagEditor(allTags, meta.tags);
dom.appendChild(MarginBox(tagEditor.dom));
tagEditor.dom.addEventListener('tags-changed', (e) => {
tags = e.detail.tags;
});
let fontSize = 16;
const decreaseFontBtn = el('button', {
onclick: () => {
fontSize -= 1;
textContainer.style['font-size'] = fontSize + 'px';
},
classList: ['entreate-button'],
});
decreaseFontBtn.innerText = "- Font size";
dom.appendChild(decreaseFontBtn);
const increaseFontBtn = el('button', {
onclick: () => {
fontSize += 1;
textContainer.style['font-size'] = fontSize + 'px';
},
classList: ['entreate-button'],
});
increaseFontBtn.innerText = "+ Font size";
dom.appendChild(increaseFontBtn);
const textContainer = el('div');
textContainer.classList.add('entreate-entry-editor__text');
dom.appendChild(textContainer);
const editor = CodeMirror(textContainer, {
lineNumbers: true,
value: text,
//viewportMargin: Infinity,
});
// See https://stackoverflow.com/a/19970695/943814
setTimeout(() => {
editor.refresh();
}, 0);
return {
dom,
updateTags: tagEditor.updateTags,
};
}