diff --git a/apps/client/src/entities/fnote.ts b/apps/client/src/entities/fnote.ts index be80a1142..39015cb24 100644 --- a/apps/client/src/entities/fnote.ts +++ b/apps/client/src/entities/fnote.ts @@ -1024,6 +1024,10 @@ class FNote { return this.mime === "text/x-sqlite;schema=trilium"; } + isTriliumScript() { + return this.mime.startsWith("application/javascript"); + } + /** * Provides note's date metadata. */ diff --git a/apps/client/src/widgets/react/Button.tsx b/apps/client/src/widgets/react/Button.tsx index 61d7fbd83..0ab6eae48 100644 --- a/apps/client/src/widgets/react/Button.tsx +++ b/apps/client/src/widgets/react/Button.tsx @@ -2,6 +2,7 @@ import type { RefObject } from "preact"; import type { CSSProperties } from "preact/compat"; import { useRef, useMemo } from "preact/hooks"; import { memo } from "preact/compat"; +import { CommandNames } from "../../components/app_context"; interface ButtonProps { name?: string; @@ -17,9 +18,10 @@ interface ButtonProps { disabled?: boolean; size?: "normal" | "small" | "micro"; style?: CSSProperties; + triggerCommand?: CommandNames; } -const Button = memo(({ name, buttonRef: _buttonRef, className, text, onClick, keyboardShortcut, icon, primary, disabled, size, style }: ButtonProps) => { +const Button = memo(({ name, buttonRef: _buttonRef, className, text, onClick, keyboardShortcut, icon, primary, disabled, size, style, triggerCommand }: ButtonProps) => { // Memoize classes array to prevent recreation const classes = useMemo(() => { const classList: string[] = ["btn"]; @@ -57,11 +59,12 @@ const Button = memo(({ name, buttonRef: _buttonRef, className, text, onClick, ke - -`; - -export default class ScriptExecutorWidget extends NoteContextAwareWidget { - - private $executeButton!: JQuery; - private $executeDescription!: JQuery; - - isEnabled() { - return ( - super.isEnabled() && - this.note && - (this.note.mime.startsWith("application/javascript") || this.isTriliumSqlite()) && - (this.note.hasLabel("executeDescription") || this.note.hasLabel("executeButton")) - ); - } - - getTitle() { - return { - show: this.isEnabled(), - activate: true - }; - } - - doRender() { - this.$widget = $(TPL); - this.contentSized(); - - this.$executeButton = this.$widget.find(".execute-button"); - this.$executeDescription = this.$widget.find(".execute-description"); - } - - async refreshWithNote(note: FNote) { - const executeTitle = note.getLabelValue("executeButton") || (this.isTriliumSqlite() ? t("script_executor.execute_query") : t("script_executor.execute_script")); - - this.$executeButton.text(executeTitle); - this.$executeButton.attr("title", executeTitle); - keyboardActionService.updateDisplayedShortcuts(this.$widget); - - const executeDescription = note.getLabelValue("executeDescription"); - - if (executeDescription) { - this.$executeDescription.show().html(executeDescription); - } else { - this.$executeDescription.empty().hide(); - } - } -}