-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditorSublistBase.js
More file actions
60 lines (51 loc) · 1.27 KB
/
EditorSublistBase.js
File metadata and controls
60 lines (51 loc) · 1.27 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
class EditorSublistBase extends EditorEntryBase {
constructor(id, icon, cls, limits) {
super(id);
this.elem_.innerText = icon;
this.elem_.classList.add(cls);
let nodeList = document.createElement('div');
this.nodes_ = new Editor(nodeList, limits);
this.elem_.appendChild(nodeList);
}
afterDomAdd() {
this.nodes_.selectNext();
let node = this.nodes_.getSelected().xArchObj;
if (node.getLabel() == '') {
node.startEdit();
}
}
serialize(base) {
super.serialize(base);
base.label = this.getLabel();
base.labelObj = this.getLabelObj() ? this.getLabelObj().serialize() : null;
return base;
}
getLabel() {
let label = this.getLabelObj();
return label ? label.getLabel() : null;
}
setLabel(label, labelId) {
let obj = this.nodes_.getEntries(EditorLabel)[0];
if (obj) {
obj.setLabel(label);
} else {
this.nodes_.addLabelBefore(labelId);
this.setLabel(label);
}
}
getLabelObj() {
return this.nodes_.getEntries(EditorLabel)[0];
}
onKeyDown(e) {
super.onKeyDown(e);
switch (e.key) {
case 'Enter':
case 'ArrowRight':
case 'l':
this.nodes_.selectNext();
e.stopPropagation();
e.preventDefault();
break;
}
}
}