2019-07-03 01:42:17 +00:00
|
|
|
<!--# include file="ListenUtils.js" -->
|
|
|
|
|
|
|
|
|
|
class EditorEntryBase extends ListenUtils {
|
2019-07-12 01:05:04 +00:00
|
|
|
constructor(id) {
|
2019-07-03 01:42:17 +00:00
|
|
|
super();
|
|
|
|
|
|
|
|
|
|
this.elem_ = document.createElement('li');
|
|
|
|
|
this.elem_.tabIndex = 0;
|
2019-07-12 01:05:04 +00:00
|
|
|
this.elem_.id = (id || ('entry' + idSource.getId()));
|
2019-07-03 01:42:17 +00:00
|
|
|
this.listen(this.elem_, 'focus', () => this.onElemFocus());
|
|
|
|
|
this.listen(this.elem_, 'keydown', (e) => this.onKeyDown(e));
|
|
|
|
|
|
|
|
|
|
this.elem_.xArchObj = this;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 02:26:00 +00:00
|
|
|
serialize(base) {
|
|
|
|
|
base.id = this.getId();
|
|
|
|
|
base.highlight = this.elem_.classList.contains('highlight');
|
|
|
|
|
return base;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 01:42:17 +00:00
|
|
|
remove() {
|
|
|
|
|
if (document.activeElement == this.elem_ ||
|
|
|
|
|
document.activeElement == document.body) {
|
|
|
|
|
if (this.elem_.nextElementSibling) {
|
|
|
|
|
this.elem_.nextElementSibling.focus();
|
|
|
|
|
} else if (this.elem_.previousElementSibling) {
|
|
|
|
|
this.elem_.previousElementSibling.focus();
|
|
|
|
|
} else if (this.elem_.parentElement) {
|
|
|
|
|
this.elem_.parentElement.focus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.elem_.remove();
|
|
|
|
|
this.clearListeners();
|
|
|
|
|
this.elem_.xArchObj = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wantFocus() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-10 21:32:52 +00:00
|
|
|
getElement() {
|
|
|
|
|
return this.elem_;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-11 05:12:08 +00:00
|
|
|
getId() {
|
|
|
|
|
return this.elem_.id;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 02:26:00 +00:00
|
|
|
setHighlight(highlight) {
|
|
|
|
|
this.elem_.classList.toggle('highlight', highlight);
|
|
|
|
|
for (let elem of document.getElementsByClassName('grid-' + this.getId())) {
|
|
|
|
|
elem.classList.toggle('highlight', highlight);
|
|
|
|
|
}
|
|
|
|
|
// Do NOT refresh: this bypasses the rendering pipeline
|
|
|
|
|
this.elem_.setAttribute('data-arch-snapshot', '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggleHighlight() {
|
|
|
|
|
this.setHighlight(!this.elem_.classList.contains('highlight'));
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 01:42:17 +00:00
|
|
|
onElemFocus() {
|
|
|
|
|
this.elem_.scrollIntoView({block: 'nearest'});
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 02:26:00 +00:00
|
|
|
onKeyDown(e) {
|
|
|
|
|
switch (e.key) {
|
|
|
|
|
case ' ':
|
|
|
|
|
this.toggleHighlight();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-07-03 01:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
afterDomAdd() {
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-11 04:25:06 +00:00
|
|
|
static addBefore(container, elem, ...rest) {
|
2019-07-12 03:44:37 +00:00
|
|
|
let entry = new this(null, ...rest);
|
2019-07-03 01:42:17 +00:00
|
|
|
container.insertBefore(entry.getElement(), elem);
|
|
|
|
|
entry.afterDomAdd();
|
2019-07-13 01:54:08 +00:00
|
|
|
return entry;
|
2019-07-03 01:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
2019-07-11 04:25:06 +00:00
|
|
|
static addAfter(container, elem, ...rest) {
|
2019-07-12 03:44:37 +00:00
|
|
|
let entry = new this(null, ...rest);
|
2019-07-03 01:42:17 +00:00
|
|
|
container.insertBefore(entry.getElement(), elem ? elem.nextSibling : null);
|
|
|
|
|
entry.afterDomAdd();
|
2019-07-13 01:54:08 +00:00
|
|
|
return entry;
|
2019-07-03 01:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unserialize(ser) {
|
|
|
|
|
switch (ser.type) {
|
|
|
|
|
case 'group':
|
|
|
|
|
return EditorGroup.unserialize(ser);
|
2019-07-10 21:32:52 +00:00
|
|
|
case 'help':
|
|
|
|
|
return EditorHelp.unserialize(ser);
|
2019-07-10 04:09:54 +00:00
|
|
|
case 'label':
|
|
|
|
|
return EditorLabel.unserialize(ser);
|
2019-07-03 01:42:17 +00:00
|
|
|
case 'link':
|
|
|
|
|
return EditorLink.unserialize(ser);
|
|
|
|
|
case 'node':
|
|
|
|
|
return EditorNode.unserialize(ser);
|
2019-07-14 20:44:07 +00:00
|
|
|
case 'tag':
|
|
|
|
|
return EditorTag.unserialize(ser);
|
2019-07-03 01:42:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|