2019-07-13 03:23:19 +00:00
|
|
|
class EditorNode extends EditorInputBase {
|
2019-07-12 01:05:04 +00:00
|
|
|
constructor(id, label) {
|
2019-07-13 03:23:19 +00:00
|
|
|
super(id, label);
|
2019-07-03 01:42:17 +00:00
|
|
|
|
|
|
|
|
this.elem_.classList.add('node');
|
|
|
|
|
this.input_.placeholder = 'node name';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serialize() {
|
2019-07-13 03:23:19 +00:00
|
|
|
return super.serialize({
|
2019-07-03 01:42:17 +00:00
|
|
|
type: 'node',
|
2019-07-10 23:19:39 +00:00
|
|
|
highlight: this.elem_.classList.contains('highlight'),
|
2019-07-13 03:23:19 +00:00
|
|
|
});
|
2019-07-03 01:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
2019-07-10 23:19:39 +00:00
|
|
|
setHighlight(highlight) {
|
|
|
|
|
this.elem_.classList.toggle('highlight', highlight);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 01:42:17 +00:00
|
|
|
isSoft() {
|
|
|
|
|
// Nested nodes are presumed to be references to other nodes if they exist
|
|
|
|
|
for (let iter = this.elem_.parentElement; iter; iter = iter.parentElement) {
|
|
|
|
|
if (iter.xArchObj) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onKeyDown(e) {
|
|
|
|
|
super.onKeyDown(e);
|
|
|
|
|
|
|
|
|
|
switch (e.key) {
|
2019-07-10 23:19:39 +00:00
|
|
|
case ' ':
|
|
|
|
|
this.elem_.classList.toggle('highlight');
|
2019-07-12 03:54:03 +00:00
|
|
|
this.elem_.setAttribute('data-arch-snapshot', '');
|
2019-07-10 23:19:39 +00:00
|
|
|
this.onInput();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
break;
|
2019-07-03 01:42:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unserialize(ser) {
|
2019-07-12 01:05:04 +00:00
|
|
|
let node = new EditorNode(ser.id);
|
2019-07-03 01:42:17 +00:00
|
|
|
node.setLabel(ser.label);
|
2019-07-10 23:19:39 +00:00
|
|
|
node.setHighlight(ser.highlight);
|
2019-07-03 01:42:17 +00:00
|
|
|
return node.getElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|