From 08db03800e172639aa122ea752172ee233cccf98 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 27 Aug 2025 22:59:07 +0300 Subject: [PATCH] feat(react/floating_buttons): port open Trilium API docs --- apps/client/src/widgets/FloatingButtons.tsx | 13 +++++++++++++ .../src/widgets/floating_buttons/code_buttons.ts | 16 ---------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/apps/client/src/widgets/FloatingButtons.tsx b/apps/client/src/widgets/FloatingButtons.tsx index 5ecae1b15..a2f3769fd 100644 --- a/apps/client/src/widgets/FloatingButtons.tsx +++ b/apps/client/src/widgets/FloatingButtons.tsx @@ -14,6 +14,7 @@ import appContext from "../components/app_context"; import protected_session_holder from "../services/protected_session_holder"; import options from "../services/options"; import { AttributeRow } from "../services/load_results"; +import { openInAppHelpFromUrl } from "../services/utils"; interface FloatingButtonContext { parentComponent: Component; @@ -65,6 +66,10 @@ const FLOATING_BUTTON_DEFINITIONS: FloatingButtonDefinition[] = [ { component: RunActiveNoteButton, isEnabled: ({ note }) => note.mime.startsWith("application/javascript") || note.mime === "text/x-sqlite;schema=trilium" + }, + { + component: OpenTriliumApiDocsButton, + isEnabled: ({ note }) => note.mime.startsWith("application/javascript;env=") } ]; @@ -225,6 +230,14 @@ function RunActiveNoteButton() { /> } +function OpenTriliumApiDocsButton({ note }: FloatingButtonContext) { + return openInAppHelpFromUrl(note.mime.endsWith("frontend") ? "Q2z6av6JZVWm" : "MEtfsqa5VwNi")} + /> +} + /** * Show button that displays floating button after click on close button */ diff --git a/apps/client/src/widgets/floating_buttons/code_buttons.ts b/apps/client/src/widgets/floating_buttons/code_buttons.ts index 712d1d9ee..c64fe7183 100644 --- a/apps/client/src/widgets/floating_buttons/code_buttons.ts +++ b/apps/client/src/widgets/floating_buttons/code_buttons.ts @@ -17,10 +17,6 @@ const TPL = /*html*/` } - - @@ -42,16 +38,6 @@ export default class CodeButtonsWidget extends NoteContextAwareWidget { doRender() { this.$widget = $(TPL); - this.$openTriliumApiDocsButton = this.$widget.find(".trilium-api-docs-button"); - this.$openTriliumApiDocsButton.on("click", () => { - toastService.showMessage(t("code_buttons.opening_api_docs_message")); - - if (this.note?.mime.endsWith("frontend")) { - window.open("https://triliumnext.github.io/Notes/Script%20API/interfaces/Frontend_Script_API.Api.html", "_blank"); - } else { - window.open("https://triliumnext.github.io/Notes/Script%20API/interfaces/Backend_Script_API.Api.html", "_blank"); - } - }); this.$executeButton = this.$widget.find(".execute-button"); this.$saveToNoteButton = this.$widget.find(".save-to-note-button"); @@ -74,8 +60,6 @@ export default class CodeButtonsWidget extends NoteContextAwareWidget { async refreshWithNote(note: FNote) { this.$saveToNoteButton.toggle(note.mime === "text/x-sqlite;schema=trilium" && note.isHiddenCompletely()); - - this.$openTriliumApiDocsButton.toggle(note.mime.startsWith("application/javascript;env=")); } async noteTypeMimeChangedEvent({ noteId }: EventData<"noteTypeMimeChanged">) {