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
client/menus: refactor
Adorian Doranb26803b627c7
diff --git a/apps/client/src/menus/context_menu.ts b/apps/client/src/menus/context_menu.tsindex 09b51694d9..786c53e4ef 100644--- a/apps/client/src/menus/context_menu.ts+++ b/apps/client/src/menus/context_menu.ts@@ -15,7 +15,7 @@ export interface ContextMenuOptions<T> {}interface MenuSeparatorItem {- title: "----";+ kind: "separator";}interface MenuHeader {@@ -161,7 +161,7 @@ class ContextMenu {continue;}- if (item.title === "----") {+ if ("kind" in item && item.kind === "separator") {$parent.append($("<div>").addClass("dropdown-divider"));} else if ("kind" in item && item.kind === "header") {$parent.append($("<h6>").addClass("dropdown-header").text(item.title));diff --git a/apps/client/src/menus/electron_context_menu.ts b/apps/client/src/menus/electron_context_menu.tsindex 51415c6558..cbd35dcb8d 100644--- a/apps/client/src/menus/electron_context_menu.ts+++ b/apps/client/src/menus/electron_context_menu.ts@@ -112,7 +112,7 @@ function setupContextMenu() {// Replace the placeholder with the real search keyword.let searchUrl = searchEngineUrl.replace("{keyword}", encodeURIComponent(params.selectionText));- items.push({ title: "----" });+ items.push({ kind: "separator" });items.push({title: t("electron_context_menu.search_online", { term: shortenedSelection, searchEngine: searchEngineName }),diff --git a/apps/client/src/menus/launcher_context_menu.ts b/apps/client/src/menus/launcher_context_menu.tsindex 2ac7decee3..717180690a 100644--- a/apps/client/src/menus/launcher_context_menu.ts+++ b/apps/client/src/menus/launcher_context_menu.ts@@ -45,16 +45,16 @@ export default class LauncherContextMenu implements SelectMenuItemEventListener<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,isVisibleRoot || isAvailableRoot ? { title: t("launcher_context_menu.add-spacer"), command: "addSpacerLauncher", uiIcon: "bx bx-dots-horizontal" } : null,- isVisibleRoot || isAvailableRoot ? { title: "----" } : null,+ isVisibleRoot || isAvailableRoot ? { kind: "separator" } : null,isAvailableItem ? { title: t("launcher_context_menu.move-to-visible-launchers"), command: "moveLauncherToVisible", uiIcon: "bx bx-show", enabled: true } : null,isVisibleItem ? { title: t("launcher_context_menu.move-to-available-launchers"), command: "moveLauncherToAvailable", uiIcon: "bx bx-hide", enabled: true } : null,- isVisibleItem || isAvailableItem ? { title: "----" } : null,+ isVisibleItem || isAvailableItem ? { kind: "separator" } : null,{ title: `${t("launcher_context_menu.duplicate-launcher")}`, command: "duplicateSubtree", uiIcon: "bx bx-outline", enabled: isItem },{ title: `${t("launcher_context_menu.delete")}`, command: "deleteNotes", uiIcon: "bx bx-trash destructive-action-icon", enabled: canBeDeleted },- { title: "----" },+ { kind: "separator" },{ title: t("launcher_context_menu.reset"), command: "resetLauncher", uiIcon: "bx bx-reset destructive-action-icon", enabled: canBeReset }];diff --git a/apps/client/src/menus/tree_context_menu.ts b/apps/client/src/menus/tree_context_menu.tsindex 4ef5179122..6504b49eb5 100644--- a/apps/client/src/menus/tree_context_menu.ts+++ b/apps/client/src/menus/tree_context_menu.ts@@ -93,7 +93,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree? null: { title: t("tree-context-menu.unhoist-note"), command: "toggleNoteHoisting", keyboardShortcut: "toggleNoteHoisting", uiIcon: "bx bx-door-open" },- { title: "----" },+ { kind: "separator" },{title: t("tree-context-menu.insert-note-after"),@@ -115,13 +115,13 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Treecolumns: 2},- { title: "----" },+ { kind: "separator" },{ title: t("tree-context-menu.protect-subtree"), command: "protectSubtree", uiIcon: "bx bx-check-shield", enabled: noSelectedNotes },{ title: t("tree-context-menu.unprotect-subtree"), command: "unprotectSubtree", uiIcon: "bx bx-shield", enabled: noSelectedNotes },- { title: "----" },+ { kind: "separator" },{title: t("tree-context-menu.advanced"),@@ -130,7 +130,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Treeitems: [{ title: t("tree-context-menu.apply-bulk-actions"), command: "openBulkActionsDialog", uiIcon: "bx bx-list-plus", enabled: true },- { title: "----" },+ { kind: "separator" },{title: t("tree-context-menu.edit-branch-prefix"),@@ -141,7 +141,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree},{ title: t("tree-context-menu.convert-to-attachment"), command: "convertNoteToAttachment", uiIcon: "bx bx-paperclip", enabled: isNotRoot && !isHoisted && notOptionsOrHelp },- { title: "----" },+ { kind: "separator" },{ title: t("tree-context-menu.expand-subtree"), command: "expandSubtree", keyboardShortcut: "expandSubtree", uiIcon: "bx bx-expand", enabled: noSelectedNotes },{ title: t("tree-context-menu.collapse-subtree"), command: "collapseSubtree", keyboardShortcut: "collapseSubtree", uiIcon: "bx bx-collapse", enabled: noSelectedNotes },@@ -153,14 +153,14 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Treeenabled: noSelectedNotes && notSearch},- { title: "----" },+ { kind: "separator" },{ title: t("tree-context-menu.copy-note-path-to-clipboard"), command: "copyNotePathToClipboard", uiIcon: "bx bx-directions", enabled: true },{ title: t("tree-context-menu.recent-changes-in-subtree"), command: "recentChangesInSubtree", uiIcon: "bx bx-history", enabled: noSelectedNotes && notOptionsOrHelp }]},- { title: "----" },+ { kind: "separator" },{title: t("tree-context-menu.cut"),@@ -241,13 +241,13 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Treeenabled: isNotRoot && !isHoisted && parentNotSearch && notOptionsOrHelp},- { title: "----" },+ { kind: "separator" },{ title: t("tree-context-menu.import-into-note"), command: "importIntoNote", uiIcon: "bx bx-import", enabled: notSearch && noSelectedNotes && notOptionsOrHelp },{ title: t("tree-context-menu.export"), command: "exportNote", uiIcon: "bx bx-export", enabled: notSearch && noSelectedNotes && notOptionsOrHelp },- { title: "----" },+ { kind: "separator" },{title: t("tree-context-menu.search-in-subtree"),diff --git a/apps/client/src/services/note_types.ts b/apps/client/src/services/note_types.tsindex 0dba6a0c0b..daa9bf000a 100644--- a/apps/client/src/services/note_types.ts+++ b/apps/client/src/services/note_types.ts@@ -73,7 +73,7 @@ const BETA_BADGE = {title: t("note_types.beta-feature")};-const SEPARATOR = { title: "----" };+const SEPARATOR = { kind: "separator" };const creationDateCache = new Map<string, Date>();let rootCreationDate: Date | undefined;@@ -157,7 +157,7 @@ async function getBuiltInTemplates(title: string | null, command: TreeCommandNamconst items: MenuItem<TreeCommandNames>[] = [];if (title) {items.push({- title: "title",+ title: title,kind: "header"});} else {diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.tsindex d3f74fde40..0c818a1112 100644--- a/apps/client/src/widgets/collections/board/context_menu.ts+++ b/apps/client/src/widgets/collections/board/context_menu.ts@@ -41,7 +41,7 @@ export function openNoteContextMenu(api: Api, event: ContextMenuEvent, note: FNoy: event.pageY,items: [...link_context_menu.getItems(),- { title: "----" },+ { kind: "separator" },{title: t("board_view.move-to"),uiIcon: "bx bx-transfer",@@ -52,7 +52,7 @@ export function openNoteContextMenu(api: Api, event: ContextMenuEvent, note: FNo})),},getArchiveMenuItem(note),- { title: "----" },+ { kind: "separator" },{title: t("board_view.insert-above"),uiIcon: "bx bx-list-plus",@@ -63,7 +63,7 @@ export function openNoteContextMenu(api: Api, event: ContextMenuEvent, note: FNouiIcon: "bx bx-empty",handler: () => api.insertRowAtPosition(column, branchId, "after")},- { title: "----" },+ { kind: "separator" },{title: t("board_view.remove-from-board"),uiIcon: "bx bx-task-x",diff --git a/apps/client/src/widgets/collections/geomap/context_menu.ts b/apps/client/src/widgets/collections/geomap/context_menu.tsindex 617c4637f4..dd583e266a 100644--- a/apps/client/src/widgets/collections/geomap/context_menu.ts+++ b/apps/client/src/widgets/collections/geomap/context_menu.ts@@ -10,14 +10,14 @@ import link from "../../../services/link.js";export default function openContextMenu(noteId: string, e: LeafletMouseEvent, isEditable: boolean) {let items: MenuItem<keyof CommandMappings>[] = [...buildGeoLocationItem(e),- { title: "----" },+ { kind: "separator" },...linkContextMenu.getItems(),];if (isEditable) {items = [...items,- { title: "----" },+ { kind: "separator" },{ title: t("geo-map-context.remove-from-map"), command: "deleteFromMap", uiIcon: "bx bx-trash" }];}@@ -46,7 +46,7 @@ export function openMapContextMenu(noteId: string, e: LeafletMouseEvent, isEditaif (isEditable) {items = [...items,- { title: "----" },+ { kind: "separator" },{title: t("geo-map-context.add-note"),handler: () => createNewNote(noteId, e),diff --git a/apps/client/src/widgets/collections/table/context_menu.ts b/apps/client/src/widgets/collections/table/context_menu.tsindex 16cbd39ff5..eb0a303ae6 100644--- a/apps/client/src/widgets/collections/table/context_menu.ts+++ b/apps/client/src/widgets/collections/table/context_menu.ts@@ -74,7 +74,7 @@ function showColumnContextMenu(parentComponent: Component, e: MouseEvent, columnhandler: () => tabulator.clearSort()},{- title: "----"+ kind: "separator"},{title: t("table_view.hide-column", { title }),@@ -86,7 +86,7 @@ function showColumnContextMenu(parentComponent: Component, e: MouseEvent, columnuiIcon: "bx bx-columns",items: buildColumnItems(tabulator)},- { title: "----" },+ { kind: "separator" },{title: t("table_view.add-column-to-the-left"),uiIcon: "bx bx-horizontal-left",@@ -105,7 +105,7 @@ function showColumnContextMenu(parentComponent: Component, e: MouseEvent, columndirection: "after"})},- { title: "----" },+ { kind: "separator" },{title: t("table_view.edit-column"),uiIcon: "bx bxs-edit-alt",@@ -143,7 +143,7 @@ function showHeaderContextMenu(parentComponent: Component, e: MouseEvent, tabulauiIcon: "bx bx-columns",items: buildColumnItems(tabulator)},- { title: "----" },+ { kind: "separator" },{title: t("table_view.new-column"),uiIcon: "bx bx-empty",@@ -174,7 +174,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, rocontextMenu.show({items: [...link_context_menu.getItems(),- { title: "----" },+ { kind: "separator" },{title: t("table_view.row-insert-above"),uiIcon: "bx bx-horizontal-left bx-rotate-90",@@ -214,7 +214,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro}})},- { title: "----" },+ { kind: "separator" },{title: t("table_context_menu.delete_row"),uiIcon: "bx bx-trash",diff --git a/apps/client/src/widgets/dialogs/note_type_chooser.tsx b/apps/client/src/widgets/dialogs/note_type_chooser.tsxindex bc6e8abc96..fba12accad 100644--- a/apps/client/src/widgets/dialogs/note_type_chooser.tsx+++ b/apps/client/src/widgets/dialogs/note_type_chooser.tsx@@ -41,7 +41,7 @@ export default function NoteTypeChooserDialogComponent() {let index = -1;setNoteTypes((noteTypes ?? []).map((item) => {- if (item.title === "----") {+ if ("kind" in item && item.kind === "separator") {index++;return {title: SEPARATOR_TITLE_REPLACEMENTS[index],@@ -95,7 +95,7 @@ export default function NoteTypeChooserDialogComponent() {<FormGroup name="note-type" label={t("note_type_chooser.modal_body")}><FormList onSelect={onNoteTypeSelected}>{noteTypes.map((_item) => {- if (_item.title === "----") {+ if ("kind" in _item && _item.kind === "separator") {return;}diff --git a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsxindex 596a70300c..a9e88246e3 100644--- a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx+++ b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx@@ -24,7 +24,7 @@ export default function MobileDetailMenu() {items: [{ title: t("mobile_detail_menu.insert_child_note"), command: "insertChildNote", uiIcon: "bx bx-plus", enabled: note?.type !== "search" },{ title: t("mobile_detail_menu.delete_this_note"), command: "delete", uiIcon: "bx bx-trash", enabled: note?.noteId !== "root" },- { title: "----" },+ { kind: "separator" },{ title: "Note revisions", command: "showRevisions", uiIcon: "bx bx-history" }],selectMenuItemHandler: async ({ command }) => {diff --git a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsxindex 32cae708b3..3376362650 100644--- a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx+++ b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx@@ -387,7 +387,7 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxIitems: [{ title: t("attribute_editor.add_new_label"), command: "addNewLabel", uiIcon: "bx bx-hash" },{ title: t("attribute_editor.add_new_relation"), command: "addNewRelation", uiIcon: "bx bx-transfer" },- { title: "----" },+ { kind: "separator" },{ title: t("attribute_editor.add_new_label_definition"), command: "addNewLabelDefinition", uiIcon: "bx bx-empty" },{ title: t("attribute_editor.add_new_relation_definition"), command: "addNewRelationDefinition", uiIcon: "bx bx-empty" }],diff --git a/apps/client/src/widgets/tab_row.ts b/apps/client/src/widgets/tab_row.tsindex cf13678786..1f48de5169 100644--- a/apps/client/src/widgets/tab_row.ts+++ b/apps/client/src/widgets/tab_row.ts@@ -356,11 +356,11 @@ export default class TabRowWidget extends BasicWidget {{ title: t("tab_row.close_right_tabs"), command: "closeRightTabs", uiIcon: "bx bx-empty", enabled: appContext.tabManager.noteContexts?.at(-1)?.ntxId !== ntxId },{ title: t("tab_row.close_all_tabs"), command: "closeAllTabs", uiIcon: "bx bx-empty" },- { title: "----" },+ { kind: "separator" },{ title: t("tab_row.reopen_last_tab"), command: "reopenLastTab", uiIcon: "bx bx-undo", enabled: appContext.tabManager.recentlyClosedTabs.length !== 0 },- { title: "----" },+ { kind: "separator" },{ title: t("tab_row.move_tab_to_new_window"), command: "moveTabToNewWindow", uiIcon: "bx bx-window-open" },{ title: t("tab_row.copy_tab_to_new_window"), command: "copyTabToNewWindow", uiIcon: "bx bx-empty" }