2024-09-12 19:22:41 +08:00
|
|
|
import OnClickButtonWidget from "./onclick_button.js";
|
|
|
|
|
import appContext from "../../components/app_context.js";
|
|
|
|
|
import attributeService from "../../services/attributes.js";
|
|
|
|
|
import { t } from "../../services/i18n.js";
|
|
|
|
|
|
|
|
|
|
export default class ShowTocWidgetButton extends OnClickButtonWidget {
|
|
|
|
|
isEnabled() {
|
2025-01-09 18:07:02 +02:00
|
|
|
return super.isEnabled() && this.note && this.note.type === "text" && this.noteContext.viewScope.viewMode === "default";
|
2024-09-12 19:22:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
super();
|
|
|
|
|
|
|
|
|
|
this.icon("bx-objects-horizontal-left")
|
|
|
|
|
.title(t("show_toc_widget_button.show_toc"))
|
|
|
|
|
.titlePlacement("bottom")
|
2025-01-09 18:07:02 +02:00
|
|
|
.onClick((widget) => {
|
2024-09-12 19:22:41 +08:00
|
|
|
this.noteContext.viewScope.tocTemporarilyHidden = false;
|
|
|
|
|
appContext.triggerEvent("showTocWidget", { noteId: this.noteId });
|
|
|
|
|
this.toggleInt(false);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async refreshWithNote(note) {
|
|
|
|
|
this.toggleInt(this.noteContext.viewScope.tocTemporarilyHidden);
|
|
|
|
|
}
|
|
|
|
|
async reEvaluateTocWidgetVisibilityEvent({ noteId }) {
|
|
|
|
|
if (noteId === this.noteId) {
|
|
|
|
|
await this.refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
async entitiesReloadedEvent({ loadResults }) {
|
|
|
|
|
if (loadResults.isNoteContentReloaded(this.noteId)) {
|
|
|
|
|
await this.refresh();
|
2025-01-09 18:07:02 +02:00
|
|
|
} else if (
|
|
|
|
|
loadResults
|
|
|
|
|
.getAttributeRows()
|
|
|
|
|
.find((attr) => attr.type === "label" && (attr.name.toLowerCase().includes("readonly") || attr.name === "toc") && attributeService.isAffecting(attr, this.note))
|
|
|
|
|
) {
|
2024-09-12 19:22:41 +08:00
|
|
|
await this.refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async noteTypeMimeChangedEvent({ noteId }) {
|
|
|
|
|
if (this.isNote(noteId)) {
|
|
|
|
|
await this.refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|