mirror of
https://github.com/zadam/trilium.git
synced 2025-10-09 07:05:31 +08:00
feat(react/floating_buttons): port open Trilium API docs
This commit is contained in:
parent
04b7e0cde9
commit
08db03800e
2 changed files with 13 additions and 16 deletions
|
@ -14,6 +14,7 @@ import appContext from "../components/app_context";
|
||||||
import protected_session_holder from "../services/protected_session_holder";
|
import protected_session_holder from "../services/protected_session_holder";
|
||||||
import options from "../services/options";
|
import options from "../services/options";
|
||||||
import { AttributeRow } from "../services/load_results";
|
import { AttributeRow } from "../services/load_results";
|
||||||
|
import { openInAppHelpFromUrl } from "../services/utils";
|
||||||
|
|
||||||
interface FloatingButtonContext {
|
interface FloatingButtonContext {
|
||||||
parentComponent: Component;
|
parentComponent: Component;
|
||||||
|
@ -65,6 +66,10 @@ const FLOATING_BUTTON_DEFINITIONS: FloatingButtonDefinition[] = [
|
||||||
{
|
{
|
||||||
component: RunActiveNoteButton,
|
component: RunActiveNoteButton,
|
||||||
isEnabled: ({ note }) => note.mime.startsWith("application/javascript") || note.mime === "text/x-sqlite;schema=trilium"
|
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 <ActionButton
|
||||||
|
icon="bx bx-help-circle"
|
||||||
|
text={t("code_buttons.trilium_api_docs_button_title")}
|
||||||
|
onClick={() => openInAppHelpFromUrl(note.mime.endsWith("frontend") ? "Q2z6av6JZVWm" : "MEtfsqa5VwNi")}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show button that displays floating button after click on close button
|
* Show button that displays floating button after click on close button
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -17,10 +17,6 @@ const TPL = /*html*/`
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<button class="trilium-api-docs-button floating-button btn" title="${t("code_buttons.trilium_api_docs_button_title")}">
|
|
||||||
<span class="bx bx-help-circle"></span>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button class="save-to-note-button floating-button btn" title="${t("code_buttons.save_to_note_button_title")}">
|
<button class="save-to-note-button floating-button btn" title="${t("code_buttons.save_to_note_button_title")}">
|
||||||
<span class="bx bx-save"></span>
|
<span class="bx bx-save"></span>
|
||||||
</button>
|
</button>
|
||||||
|
@ -42,16 +38,6 @@ export default class CodeButtonsWidget extends NoteContextAwareWidget {
|
||||||
|
|
||||||
doRender() {
|
doRender() {
|
||||||
this.$widget = $(TPL);
|
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.$executeButton = this.$widget.find(".execute-button");
|
||||||
this.$saveToNoteButton = this.$widget.find(".save-to-note-button");
|
this.$saveToNoteButton = this.$widget.find(".save-to-note-button");
|
||||||
|
@ -74,8 +60,6 @@ export default class CodeButtonsWidget extends NoteContextAwareWidget {
|
||||||
|
|
||||||
async refreshWithNote(note: FNote) {
|
async refreshWithNote(note: FNote) {
|
||||||
this.$saveToNoteButton.toggle(note.mime === "text/x-sqlite;schema=trilium" && note.isHiddenCompletely());
|
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">) {
|
async noteTypeMimeChangedEvent({ noteId }: EventData<"noteTypeMimeChanged">) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue