Factor common Editor{Group,Link} code out into EditorSublistBase
This commit is contained in:
@@ -1,15 +1,10 @@
|
||||
class EditorGroup extends EditorEntryBase {
|
||||
class EditorGroup extends EditorSublistBase {
|
||||
constructor(id, entries) {
|
||||
super(id);
|
||||
|
||||
this.elem_.innerText = '□';
|
||||
this.elem_.classList.add('group');
|
||||
|
||||
let nodeList = document.createElement('div');
|
||||
this.nodes_ = new Editor(nodeList, [
|
||||
super(id, '□', 'group', [
|
||||
[EditorNode, [1, Number.POSITIVE_INFINITY]],
|
||||
[EditorLabel, [0, 1]],
|
||||
]);
|
||||
|
||||
if (entries && entries.length) {
|
||||
for (let entry of entries) {
|
||||
this.nodes_.addNodeAfter(entry.getLabel());
|
||||
@@ -17,22 +12,11 @@ class EditorGroup extends EditorEntryBase {
|
||||
} else {
|
||||
this.nodes_.addNodeAfter();
|
||||
}
|
||||
this.elem_.appendChild(nodeList);
|
||||
}
|
||||
|
||||
afterDomAdd() {
|
||||
this.nodes_.selectNext();
|
||||
let node = this.nodes_.getSelected().xArchObj;
|
||||
if (node.getLabel() == '') {
|
||||
node.startEdit();
|
||||
}
|
||||
}
|
||||
|
||||
serialize() {
|
||||
return super.serialize({
|
||||
type: 'group',
|
||||
label: this.getLabel(),
|
||||
labelObj: this.getLabelObj() ? this.getLabelObj().serialize() : null,
|
||||
members: this.nodes_.serialize(EditorNode),
|
||||
});
|
||||
}
|
||||
@@ -41,39 +25,6 @@ class EditorGroup extends EditorEntryBase {
|
||||
return this.nodes_.getEntries(EditorNode);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
static unserialize(ser) {
|
||||
//// Backwards compat
|
||||
// 3bdb240
|
||||
|
||||
Reference in New Issue
Block a user