import {Tree} from "../../util/Tree"; import {fetchPost} from "../../util/fetch"; import {Constants} from "../../constants"; import {hasClosestByClassName} from "../../protyle/util/hasClosest"; import {onGet} from "../../protyle/util/onGet"; import {openMobileFileById} from "../editor"; import {MenuItem} from "../../menus/Menu"; export class MobileBookmarks { public element: HTMLElement; private tree: Tree; private openNodes: string[]; constructor() { this.element = document.querySelector('#sidebar [data-type="sidebar-bookmark"]'); this.element.innerHTML = `
${window.siyuan.languages.bookmark}
`; this.tree = new Tree({ element: this.element.querySelector(".bookmarkList") as HTMLElement, data: null, click(element: HTMLElement) { openMobileFileById(element.getAttribute("data-node-id"), true, [Constants.CB_GET_FOCUS]); } }); this.element.addEventListener("click", (event) => { let target = event.target as HTMLElement; while (target && !target.isEqualNode(this.element)) { if (target.classList.contains("toolbar__icon")) { const type = target.getAttribute("data-type"); switch (type) { case "collapse": this.tree.collapseAll(); break; case "expand": this.tree.expandAll(); break; } } target = target.parentElement; } }); this.update(); } public update() { this.element.lastElementChild.classList.remove("fn__none") fetchPost("/api/bookmark/getBookmark", {}, response => { if (this.openNodes) { this.openNodes = this.tree.getExpandIds(); } this.tree.updateData(response.data); if (this.openNodes) { this.tree.setExpandIds(this.openNodes); } else { this.openNodes = this.tree.getExpandIds(); } this.element.lastElementChild.classList.add("fn__none") }); } }