forked from lastmjs/assess-elements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
juicy-ace-editor.ts
49 lines (40 loc) · 1.39 KB
/
juicy-ace-editor.ts
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
//TODO The only reason this is called juicy-ace-editor is so that I don't have to update the code tag in assessml
//TODO Change the name of this element eventually and then update assessml
import 'ace-builds/src-min-noconflict/ace.js';
import 'ace-builds/src-min-noconflict/mode-javascript.js';
class JuicyAceEditor extends HTMLElement {
editor: any;
get value() {
return this.editor.getValue();
}
set value(val) {
if (this.editor) {
this.editor.setValue(val, 1);
}
}
connectedCallback() {
this.innerHTML = `
<style>
#${this.id}-container {
display: flex;
flex-direction: column;
height: 50vh;
}
#${this.id}-editor {
flex: 1;
font-size: 1.5em;
}
</style>
<div id="${this.id}-container">
<div id="${this.id}-editor"></div>
</div>
`;
this.editor = ace.edit(this.querySelector(`#${this.id}-editor`));
this.editor.session.setUseWorker(false);
this.editor.session.setMode('ace/mode/javascript');
this.editor.on('change', () => {
this.dispatchEvent(new CustomEvent('value-changed'));
});
}
}
window.customElements.define('juicy-ace-editor', JuicyAceEditor);