2019-07-03 01:42:17 +00:00
|
|
|
class EditorGroup extends EditorEntryBase {
|
2019-07-11 04:25:06 +00:00
|
|
|
constructor(entries) {
|
2019-07-03 01:42:17 +00:00
|
|
|
super();
|
|
|
|
|
|
2019-07-09 17:57:35 +00:00
|
|
|
this.elem_.innerText = '□';
|
2019-07-03 01:42:17 +00:00
|
|
|
this.elem_.classList.add('group');
|
|
|
|
|
|
|
|
|
|
let nodeList = document.createElement('div');
|
2019-07-10 08:14:53 +00:00
|
|
|
this.nodes_ = new Editor(nodeList, [
|
|
|
|
|
[EditorNode, [1, Number.POSITIVE_INFINITY]],
|
|
|
|
|
[EditorLabel, [0, 1]],
|
|
|
|
|
]);
|
2019-07-11 04:25:06 +00:00
|
|
|
if (entries && entries.length) {
|
|
|
|
|
for (let entry of entries) {
|
|
|
|
|
this.nodes_.addNodeAfter(entry.getLabel());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.nodes_.addNodeAfter();
|
|
|
|
|
}
|
2019-07-03 01:42:17 +00:00
|
|
|
this.elem_.appendChild(nodeList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
afterDomAdd() {
|
2019-07-09 17:57:35 +00:00
|
|
|
this.nodes_.selectNext();
|
2019-07-09 20:44:22 +00:00
|
|
|
this.nodes_.getSelected().xArchObj.startEdit();
|
2019-07-03 01:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serialize() {
|
|
|
|
|
return {
|
|
|
|
|
type: 'group',
|
|
|
|
|
label: this.getLabel(),
|
2019-07-10 08:14:53 +00:00
|
|
|
members: this.nodes_.serialize(EditorNode),
|
2019-07-10 23:46:25 +00:00
|
|
|
highlight: this.elem_.classList.contains('highlight'),
|
2019-07-03 01:42:17 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getNodes() {
|
2019-07-10 08:14:53 +00:00
|
|
|
return this.nodes_.getEntries(EditorNode);
|
2019-07-03 01:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getLabel() {
|
2019-07-10 08:14:53 +00:00
|
|
|
let label = this.nodes_.getEntries(EditorLabel)[0];
|
|
|
|
|
return label ? label.getLabel() : null;
|
2019-07-03 01:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setLabel(label) {
|
2019-07-10 08:14:53 +00:00
|
|
|
let obj = this.nodes_.getEntries(EditorLabel)[0];
|
|
|
|
|
if (obj) {
|
|
|
|
|
obj.setLabel(label);
|
|
|
|
|
} else {
|
|
|
|
|
this.nodes_.addLabelBefore();
|
|
|
|
|
this.setLabel(label);
|
|
|
|
|
}
|
2019-07-03 01:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
2019-07-10 23:46:25 +00:00
|
|
|
setHighlight(highlight) {
|
|
|
|
|
this.elem_.classList.toggle('highlight', highlight);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 01:42:17 +00:00
|
|
|
onKeyDown(e) {
|
|
|
|
|
super.onKeyDown(e);
|
|
|
|
|
|
|
|
|
|
switch (e.key) {
|
|
|
|
|
case 'Enter':
|
|
|
|
|
case 'ArrowRight':
|
|
|
|
|
case 'l':
|
|
|
|
|
this.nodes_.selectNext();
|
2019-07-09 17:57:35 +00:00
|
|
|
e.stopPropagation();
|
|
|
|
|
e.preventDefault();
|
2019-07-03 01:42:17 +00:00
|
|
|
break;
|
2019-07-10 23:46:25 +00:00
|
|
|
|
|
|
|
|
case ' ':
|
|
|
|
|
this.elem_.classList.toggle('highlight');
|
2019-07-11 04:44:33 +00:00
|
|
|
this.elem_.setAttribute('data-arch-refresh', '');
|
2019-07-10 23:46:25 +00:00
|
|
|
e.stopPropagation();
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
break;
|
2019-07-03 01:42:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unserialize(ser) {
|
|
|
|
|
let group = new EditorGroup();
|
|
|
|
|
group.nodes_.clear();
|
2019-07-10 21:35:03 +00:00
|
|
|
if (ser.label != null) {
|
|
|
|
|
group.setLabel(ser.label);
|
|
|
|
|
}
|
2019-07-10 23:46:25 +00:00
|
|
|
group.setHighlight(ser.highlight);
|
2019-07-03 01:42:17 +00:00
|
|
|
group.nodes_.unserialize(ser.members);
|
|
|
|
|
return group.getElement();
|
|
|
|
|
}
|
|
|
|
|
}
|