mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-10 09:48:48 +08:00

This reverts commit 58a8821c229898c45551da16476d44c010c345ef, reversing changes made to 50d491b432ce811c4d5e597e952eb18a89ae6c19.
73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import appContext, { type EventData } from "../../components/app_context.js";
|
|
import type FNote from "../../entities/fnote.js";
|
|
import type { NoteType } from "../../entities/fnote.js";
|
|
import { t } from "../../services/i18n.js";
|
|
import type { ViewScope } from "../../services/link.js";
|
|
import type { ViewTypeOptions } from "../../services/note_list_renderer.js";
|
|
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
|
|
|
const TPL = `
|
|
<button class="open-contextual-help-button" title="${t("help-button.title")}">
|
|
<span class="bx bx-help-circle"></span>
|
|
</button>
|
|
`;
|
|
|
|
const byNoteType: Record<Exclude<NoteType, "book">, string | null> = {
|
|
canvas: null,
|
|
code: null,
|
|
contentWidget: null,
|
|
doc: null,
|
|
file: null,
|
|
geoMap: "foPEtsL51pD2",
|
|
image: null,
|
|
launcher: null,
|
|
mermaid: null,
|
|
mindMap: null,
|
|
noteMap: null,
|
|
relationMap: null,
|
|
render: null,
|
|
search: null,
|
|
text: null,
|
|
webView: null
|
|
};
|
|
|
|
const byBookType: Record<ViewTypeOptions, string | null> = {
|
|
list: null,
|
|
grid: null,
|
|
calendar: "fDGg7QcJg3Xm"
|
|
};
|
|
|
|
export default class ContextualHelpButton extends NoteContextAwareWidget {
|
|
|
|
isEnabled() {
|
|
if (!super.isEnabled()) {
|
|
return false;
|
|
}
|
|
|
|
return !!ContextualHelpButton.#getUrlToOpen(this.note);
|
|
}
|
|
|
|
doRender() {
|
|
this.$widget = $(TPL);
|
|
}
|
|
|
|
static #getUrlToOpen(note: FNote | null | undefined) {
|
|
if (note && note.type !== "book" && byNoteType[note.type]) {
|
|
return byNoteType[note.type];
|
|
} else if (note && note.type === "book") {
|
|
return byBookType[note.getAttributeValue("label", "viewType") as ViewTypeOptions ?? ""]
|
|
}
|
|
}
|
|
|
|
async refreshWithNote(note: FNote | null | undefined): Promise<void> {
|
|
this.$widget.attr("data-in-app-help", ContextualHelpButton.#getUrlToOpen(this.note) ?? "");
|
|
}
|
|
|
|
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
|
|
if (this.note?.type === "book" && loadResults.getAttributeRows().find((attr) => attr.noteId === this.noteId && attr.name === "viewType")) {
|
|
this.refresh();
|
|
}
|
|
}
|
|
|
|
}
|