import NoteContextAwareWidget from "../note_context_aware_widget.js"; import treeService from "../../services/tree.js"; import linkService from "../../services/link.js"; import { t } from "../../services/i18n.js"; const TPL = `
`; export default class NotePathsWidget extends NoteContextAwareWidget { get name() { return "notePaths"; } get toggleCommand() { return "toggleRibbonTabNotePaths"; } getTitle() { return { show: true, title: t("note_paths.title"), icon: "bx bx-collection" }; } doRender() { this.$widget = $(TPL); this.contentSized(); this.$notePathIntro = this.$widget.find(".note-path-intro"); this.$notePathList = this.$widget.find(".note-path-list"); this.$widget.on("show.bs.dropdown", () => this.renderDropdown()); } async refreshWithNote(note) { this.$notePathList.empty(); if (this.noteId === "root") { this.$notePathList.empty().append(await this.getRenderedPath("root")); return; } const sortedNotePaths = this.note.getSortedNotePathRecords(this.hoistedNoteId).filter((notePath) => !notePath.isHidden); if (sortedNotePaths.length > 0) { this.$notePathIntro.text(t("note_paths.intro_placed")); } else { this.$notePathIntro.text(t("note_paths.intro_not_placed")); } const renderedPaths = []; for (const notePathRecord of sortedNotePaths) { const notePath = notePathRecord.notePath.join("/"); renderedPaths.push(await this.getRenderedPath(notePath, notePathRecord)); } this.$notePathList.empty().append(...renderedPaths); } async getRenderedPath(notePath, notePathRecord = null) { const title = await treeService.getNotePathTitle(notePath); const $noteLink = await linkService.createLink(notePath, { title }); $noteLink.find("a").addClass("no-tooltip-preview tn-link"); const icons = []; if (this.notePath === notePath) { $noteLink.addClass("path-current"); } if (!notePathRecord || notePathRecord.isInHoistedSubTree) { $noteLink.addClass("path-in-hoisted-subtree"); } else { icons.push(``); } if (notePathRecord?.isArchived) { $noteLink.addClass("path-archived"); icons.push(``); } if (notePathRecord?.isSearch) { $noteLink.addClass("path-search"); icons.push(``); } if (icons.length > 0) { $noteLink.append(` ${icons.join(" ")}`); } return $("