Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(client/ts): use command names enum in context menu
Elian Doran19652fbbce3e
diff --git a/src/public/app/components/app_context.ts b/src/public/app/components/app_context.tsindex d629c2e283..145be6504f 100644--- a/src/public/app/components/app_context.ts+++ b/src/public/app/components/app_context.ts@@ -69,19 +69,40 @@ type CommandMappings = {notePath: string;hoistedNoteId: string;viewScope: ViewScope;- }+ },+ openNoteInNewTab: CommandData;+ openNoteInNewSplit: CommandData;+ openNoteInNewWindow: CommandData;+ openNoteInSplit: CommandData;+ openInTab: CommandData;+ insertNoteAfter: CommandData;+ insertChildNote: CommandData;+ convertNoteToAttachment: CommandData;+ copyNotePathToClipboard: CommandData;executeInActiveNoteDetailWidget: CommandData & {callback: (value: NoteDetailWidget | PromiseLike<NoteDetailWidget>) => void};addTextToActiveEditor: CommandData & {text: string;};+ /** Works only in the electron context menu. */+ replaceMisspelling: CommandData;importMarkdownInline: CommandData;showPasswordNotSet: CommandData;showProtectedSessionPasswordDialog: CommandData;closeProtectedSessionPasswordDialog: CommandData;resetLauncher: CommandData;+ addNoteLauncher: CommandData;+ addScriptLauncher: CommandData;+ addWidgetLauncher: CommandData;+ addSpacerLauncher: CommandData;+ moveLauncherToVisible: CommandData;+ moveLauncherToAvailable: CommandData;+ duplicateSubtree: CommandData;+ deleteNotes: CommandData;+ copyImageReferenceToClipboard: CommandData;+ copyImageToClipboard: CommandData;}type EventMappings = {diff --git a/src/public/app/menus/context_menu.ts b/src/public/app/menus/context_menu.tsindex fd3021fd21..5bc43e76ff 100644--- a/src/public/app/menus/context_menu.ts+++ b/src/public/app/menus/context_menu.ts@@ -1,3 +1,4 @@+import { CommandNames } from '../components/app_context.js';import keyboardActionService from '../services/keyboard_actions.js';interface ContextMenuOptions {@@ -14,7 +15,7 @@ interface MenuSeparatorItem {export interface MenuCommandItem {title: string;- command?: string;+ command?: CommandNames;type?: string;uiIcon?: string;templateNoteId?: string;diff --git a/src/public/app/menus/electron_context_menu.ts b/src/public/app/menus/electron_context_menu.tsindex faa10a62a1..68bab36365 100644--- a/src/public/app/menus/electron_context_menu.ts+++ b/src/public/app/menus/electron_context_menu.ts@@ -1,7 +1,7 @@import utils from "../services/utils.js";import options from "../services/options.js";import zoomService from "../components/zoom.js";-import contextMenu from "./context_menu.js";+import contextMenu, { MenuItem } from "./context_menu.js";import { t } from "../services/i18n.js";import type { BrowserWindow } from "electron";@@ -18,7 +18,7 @@ function setupContextMenu() {const isMac = process.platform === "darwin";const platformModifier = isMac ? 'Meta' : 'Ctrl';- const items = [];+ const items: MenuItem[] = [];if (params.misspelledWord) {for (const suggestion of params.dictionarySuggestions) {diff --git a/src/public/app/menus/launcher_context_menu.ts b/src/public/app/menus/launcher_context_menu.tsindex b67a9b9c94..4b3d485875 100644--- a/src/public/app/menus/launcher_context_menu.ts+++ b/src/public/app/menus/launcher_context_menu.ts@@ -38,7 +38,7 @@ export default class LauncherContextMenu implements SelectMenuItemEventListenerconst canBeDeleted = !note?.noteId.startsWith("_"); // fixed notes can't be deletedconst canBeReset = !canBeDeleted && note?.isLaunchBarConfig();- return [+ const items: (MenuItem | null)[] = [(isVisibleRoot || isAvailableRoot) ? { title: t("launcher_context_menu.add-note-launcher"), command: 'addNoteLauncher', uiIcon: "bx bx-note" } : null,(isVisibleRoot || isAvailableRoot) ? { title: t("launcher_context_menu.add-script-launcher"), command: 'addScriptLauncher', uiIcon: "bx bx-code-curly" } : null,(isVisibleRoot || isAvailableRoot) ? { title: t("launcher_context_menu.add-custom-widget"), command: 'addWidgetLauncher', uiIcon: "bx bx-customize" } : null,@@ -55,7 +55,8 @@ export default class LauncherContextMenu implements SelectMenuItemEventListener{ title: "----" },{ title: t("launcher_context_menu.reset"), command: "resetLauncher", uiIcon: "bx bx-reset destructive-action-icon", enabled: canBeReset}- ].filter(row => row !== null);+ ];+ return items.filter(row => row !== null);}async selectMenuItemHandler({command}: MenuCommandItem) {diff --git a/src/public/app/services/note_types.ts b/src/public/app/services/note_types.tsindex cb491b4c49..722061f189 100644--- a/src/public/app/services/note_types.ts+++ b/src/public/app/services/note_types.ts@@ -2,19 +2,20 @@ import server from "./server.js";import froca from "./froca.js";import { t } from "./i18n.js";import { MenuItem } from "../menus/context_menu.js";+import { CommandNames } from "../components/app_context.js";-async function getNoteTypeItems(command?: string) {+async function getNoteTypeItems(command?: CommandNames) {const items: MenuItem[] = [- { title: t("note_types.text"), command: command, type: "text", uiIcon: "bx bx-note" },- { title: t("note_types.code"), command: command, type: "code", uiIcon: "bx bx-code" },- { title: t("note_types.saved-search"), command: command, type: "search", uiIcon: "bx bx-file-find" },- { title: t("note_types.relation-map"), command: command, type: "relationMap", uiIcon: "bx bxs-network-chart" },- { title: t("note_types.note-map"), command: command, type: "noteMap", uiIcon: "bx bxs-network-chart" },- { title: t("note_types.render-note"), command: command, type: "render", uiIcon: "bx bx-extension" },- { title: t("note_types.book"), command: command, type: "book", uiIcon: "bx bx-book" },- { title: t("note_types.mermaid-diagram"), command: command, type: "mermaid", uiIcon: "bx bx-selection" },- { title: t("note_types.canvas"), command: command, type: "canvas", uiIcon: "bx bx-pen" },- { title: t("note_types.web-view"), command: command, type: "webView", uiIcon: "bx bx-globe-alt" },+ { title: t("note_types.text"), command, type: "text", uiIcon: "bx bx-note" },+ { title: t("note_types.code"), command, type: "code", uiIcon: "bx bx-code" },+ { title: t("note_types.saved-search"), command, type: "search", uiIcon: "bx bx-file-find" },+ { title: t("note_types.relation-map"), command, type: "relationMap", uiIcon: "bx bxs-network-chart" },+ { title: t("note_types.note-map"), command, type: "noteMap", uiIcon: "bx bxs-network-chart" },+ { title: t("note_types.render-note"), command, type: "render", uiIcon: "bx bx-extension" },+ { title: t("note_types.book"), command, type: "book", uiIcon: "bx bx-book" },+ { title: t("note_types.mermaid-diagram"), command, type: "mermaid", uiIcon: "bx bx-selection" },+ { title: t("note_types.canvas"), command, type: "canvas", uiIcon: "bx bx-pen" },+ { title: t("note_types.web-view"), command, type: "webView", uiIcon: "bx bx-globe-alt" },{ title: t("note_types.mind-map"), command, type: "mindMap", uiIcon: "bx bx-sitemap" }];