Skip to content

Build your personal knowledge base with Trilium Notes

port toc widget button

Jind28dfc2b649d
diff --git a/src/public/app/components/app_context.ts b/src/public/app/components/app_context.ts
index 39141b881d..6dad4246d2 100644
--- a/src/public/app/components/app_context.ts
+++ b/src/public/app/components/app_context.ts
@@ -312,6 +312,9 @@ type EventMappings = {
showHighlightsListWidget: {
noteId: string;
};
+ showTocWidget: {
+ noteId: string;
+ };
showSearchError: {
error: string;
};
@@ -350,9 +353,6 @@ type EventMappings = {
refreshNoteList: {
noteId: string;
};
- showToc: {
- noteId: string;
- };
noteTypeMimeChanged: { noteId: string };
zenModeChanged: { isEnabled: boolean };
};
diff --git a/src/public/app/widgets/buttons/show_highlights_list_widget_button.ts b/src/public/app/widgets/buttons/show_highlights_list_widget_button.ts
index b5ce7920ba..622bf35ca4 100644
--- a/src/public/app/widgets/buttons/show_highlights_list_widget_button.ts
+++ b/src/public/app/widgets/buttons/show_highlights_list_widget_button.ts
@@ -16,7 +16,7 @@ export default class ShowHighlightsListWidgetButton extends OnClickButtonWidget
this.icon("bx-highlight")
.title(t("show_highlights_list_widget_button.show_highlights_list"))
.titlePlacement("bottom")
- .onClick((widget) => {
+ .onClick(() => {
if (this.noteContext?.viewScope && this.noteId) {
this.noteContext.viewScope.highlightsListTemporarilyHidden = false;
appContext.triggerEvent("showHighlightsListWidget", { noteId: this.noteId });
diff --git a/src/public/app/widgets/buttons/show_toc_widget_button.js b/src/public/app/widgets/buttons/show_toc_widget_button.js
deleted file mode 100644
index 226d482a41..0000000000
--- a/src/public/app/widgets/buttons/show_toc_widget_button.js
+++ /dev/null
@@ -1,49 +0,0 @@
-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() {
- return super.isEnabled() && this.note && this.note.type === "text" && this.noteContext.viewScope.viewMode === "default";
- }
-
- constructor() {
- super();
-
- this.icon("bx-objects-horizontal-left")
- .title(t("show_toc_widget_button.show_toc"))
- .titlePlacement("bottom")
- .onClick((widget) => {
- 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();
- } else if (
- loadResults
- .getAttributeRows()
- .find((attr) => attr.type === "label" && (attr.name.toLowerCase().includes("readonly") || attr.name === "toc") && attributeService.isAffecting(attr, this.note))
- ) {
- await this.refresh();
- }
- }
-
- async noteTypeMimeChangedEvent({ noteId }) {
- if (this.isNote(noteId)) {
- await this.refresh();
- }
- }
-}
diff --git a/src/public/app/widgets/buttons/show_toc_widget_button.ts b/src/public/app/widgets/buttons/show_toc_widget_button.ts
new file mode 100644
index 0000000000..7b4dad89aa
--- /dev/null
+++ b/src/public/app/widgets/buttons/show_toc_widget_button.ts
@@ -0,0 +1,62 @@
+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";
+import LoadResults from "../../services/load_results.js";
+import type { AttributeRow } from "../../services/load_results.js";
+
+export default class ShowTocWidgetButton extends OnClickButtonWidget {
+ isEnabled(): boolean {
+ return Boolean(super.isEnabled() && this.note && this.note.type === "text" && this.noteContext?.viewScope?.viewMode === "default");
+ }
+
+ constructor() {
+ super();
+
+ this.icon("bx-objects-horizontal-left")
+ .title(t("show_toc_widget_button.show_toc"))
+ .titlePlacement("bottom")
+ .onClick(() => {
+ if (this.noteContext?.viewScope && this.noteId) {
+ this.noteContext.viewScope.tocTemporarilyHidden = false;
+ appContext.triggerEvent("showTocWidget", { noteId: this.noteId });
+ }
+ this.toggleInt(false);
+ });
+ }
+
+ async refreshWithNote(): Promise<void> {
+ if (this.noteContext?.viewScope) {
+ this.toggleInt(this.noteContext.viewScope.tocTemporarilyHidden);
+ }
+ }
+
+ async reEvaluateTocWidgetVisibilityEvent({ noteId }: { noteId: string }): Promise<void> {
+ if (noteId === this.noteId) {
+ await this.refresh();
+ }
+ }
+
+ async entitiesReloadedEvent({ loadResults }: { loadResults: LoadResults }): Promise<void> {
+ if (this.noteId && loadResults.isNoteContentReloaded(this.noteId)) {
+ await this.refresh();
+ } else if (
+ loadResults
+ .getAttributeRows()
+ .find((attr: AttributeRow) =>
+ attr.type === "label" &&
+ (attr.name?.toLowerCase().includes("readonly") || attr.name === "toc") &&
+ this.note &&
+ attributeService.isAffecting(attr, this.note)
+ )
+ ) {
+ await this.refresh();
+ }
+ }
+
+ async noteTypeMimeChangedEvent({ noteId }: { noteId: string }): Promise<void> {
+ if (this.isNote(noteId)) {
+ await this.refresh();
+ }
+ }
+}
diff --git a/src/public/app/widgets/toc.ts b/src/public/app/widgets/toc.ts
index 1958da572d..6a843a11fd 100644
--- a/src/public/app/widgets/toc.ts
+++ b/src/public/app/widgets/toc.ts
@@ -329,7 +329,7 @@ export default class TocWidget extends RightPanelWidget {
appContext.triggerEvent("reEvaluateTocWidgetVisibility", { noteId: this.noteId });
}
- async showTocWidgetEvent({ noteId }: EventData<"showToc">) {
+ async showTocWidgetEvent({ noteId }: EventData<"showTocWidget">) {
if (this.noteId === noteId) {
await this.refresh();
this.triggerCommand("reEvaluateRightPaneVisibility");