Completed
Branch master (28f58d)
by Michael
02:42
created

T_CLASS ➔ ... ➔ ???   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 1
rs 10
1
class MenuView {
2
    constructor(items, editorView) {
3
        this.items = items;
4
        this.editorView = editorView;
5
6
        this.dom = document.createElement('div');
7
        this.dom.className = 'menubar';
8
        items.forEach(({ dom }) => this.dom.appendChild(dom));
9
        this.update();
10
11
        this.dom.addEventListener('mousedown', (e) => {
12
            e.preventDefault();
13
            editorView.focus();
14
            items.forEach(({ command, dom }) => {
15
                if (dom.contains(e.target)) { command(editorView.state, editorView.dispatch, editorView); }
16
            });
17
        });
18
    }
19
20
    update() {
21
        this.items.forEach(({ command, dom }) => {
22
            const active = command(this.editorView.state, null, this.editorView);
23
            dom.style.display = active ? '' : 'none'; // eslint-disable-line no-param-reassign
24
        });
25
    }
26
27
    destroy() {
28
        this.dom.remove();
29
    }
30
}
31
32
exports.MenuView = MenuView;
33