-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodemirror.js
49 lines (41 loc) · 1.36 KB
/
codemirror.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
46
47
48
import './node_modules/codemirror/lib/codemirror.js'
//import './node_modules/codemirror/theme/monokai.css'
//import './node_modules/codemirror/lib/codemirror.css'
import './node_modules/codemirror/mode/markdown/markdown.js'
import './node_modules/codemirror/keymap/vim.js'
import './node_modules/codemirror/addon/search/searchcursor.js'
customElements.define('code-mirror',
class extends HTMLElement {
connectedCallback() {
this._editor = CodeMirror(this, {
indentUnit: 4,
mode: this.mode,
theme: this.theme,
lineNumbers: true,
keyMap: this.keymap,
value: this._editorValue,
autofocus: true
});
this._editor.on('changes', () => {
this._editorValue = this._editor.getValue()
this.dispatchEvent(new CustomEvent('editorChanged'))
})
}
constructor() {
super();
this.mode = this.getAttribute('mode');
this.keymap = this.getAttribute('keymap');
this.theme = this.getAttribute('theme');
this._editorValue = this.getAttribute('editorValue');
const editorElem = document.createElement("editor");
}
get editorValue() {
return this._editorValue;
}
set editorValue(v) {
if (this._editorValue === v) return
this._editorValue = v
if (!this._editor) return
this._editor.setValue(v)
}
})