Files
architype/EditorNode.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

class EditorNode extends EditorInputBase {
constructor(id, label) {
super(id, label);
2019-07-03 01:42:17 +00:00
this.elem_.classList.add('node');
this.input_.placeholder = 'node name';
}
serialize() {
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-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
let iter = this.elem_.parentElement;
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) {
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();
}
}