import { AdapterState } from "./adapter" class HistoryNode { id: string; type: string; prev: HistoryNode | null = null; next: HistoryNode | null = null; constructor(id: string, type: string) { this.id = id; this.type = type; } } export class NavigatorElement extends HTMLElement { static observedAttributes = [ "data-author", "data-message" ]; private _adapter: string = ""; private _history: HistoryNode | null = null; private _replyWith: string | null = null; private _gateway: string = ""; constructor() { super(); this.innerHTML = `
` } connectedCallback() { this._adapter = this.getAttribute("data-adapter") ?? ""; this._replyWith = this.getAttribute("data-replywith"); this._gateway = this.getAttribute("data-gateway") ?? ""; const prevBtn = this.querySelector(".nav_prev"); const nextBtn = this.querySelector(".nav_next"); const clearBtn = this.querySelector(".nav_clear"); if (prevBtn) { prevBtn.addEventListener("click", this.goPrev); } if (nextBtn) { nextBtn.addEventListener("click", this.goNext); } if (clearBtn) { clearBtn.addEventListener("click", this.clear); } } attributeChangedCallback(attr: string, prev: string, next: string) { switch (attr) { case "data-author": case "data-message": if (next == prev) { return; } if (this._history && this._history.prev && this._history.prev.id == next) { this._history = this._history.prev; } else { const h = this._history; this._history = new HistoryNode(next, attr.slice(attr.indexOf("-") + 1)); this._history.prev = h; } const panel = this.querySelector(".nav_container"); const datastore = AdapterState._instance.data.get(this._adapter); if (datastore && panel) { switch (attr) { case "data-author": const author = datastore.profileCache.get(next); panel.innerHTML = `