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/content manager: tweak context menus
Adorian Doranbd35364dd07a
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex e1f52233e2..babc2c30fc 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2617,6 +2617,7 @@"loading": "Retrieving content...","filter_placeholder": "Type text to filter by title...","clear_filter": "Clear filter",+ "item_menu": "Actions","no_matches": "No active content matches the filter.","toggle_enable": "Enable","toggle_disable": "Disable",diff --git a/apps/client/src/widgets/collections/legacy/ListOrGridView.css b/apps/client/src/widgets/collections/legacy/ListOrGridView.cssindex d32f4de2f2..3bde9e7476 100644--- a/apps/client/src/widgets/collections/legacy/ListOrGridView.css+++ b/apps/client/src/widgets/collections/legacy/ListOrGridView.css@@ -83,7 +83,9 @@letter-spacing: .5pt;}- .tn-icon {+ /* The row's own note icon only: a bare `.tn-icon` would also catch icons of anything nested in+ the row, such as the entries of a dropdown menu opened from it. */+ .note-icon {display: flex;flex-shrink: 0;justify-content: center;diff --git a/apps/client/src/widgets/type_widgets/options/content_manager.tsx b/apps/client/src/widgets/type_widgets/options/content_manager.tsxindex 139930b6fc..223f1dfd51 100644--- a/apps/client/src/widgets/type_widgets/options/content_manager.tsx+++ b/apps/client/src/widgets/type_widgets/options/content_manager.tsx@@ -1,12 +1,10 @@import "./content_manager.css";import clsx from "clsx";-import type { TargetedMouseEvent } from "preact";import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";import appContext from "../../../components/app_context";import type FNote from "../../../entities/fnote";-import contextMenu, { type MenuItem } from "../../../menus/context_menu";import branches from "../../../services/branches";import {buildLocationTree,@@ -24,7 +22,6 @@ import debounce from "../../../services/debounce";import { t } from "../../../services/i18n";import { isMobile } from "../../../services/utils";import { ListView, type ListViewOptions } from "../../collections/legacy/ListOrGridView";-import ActionButton from "../../react/ActionButton";import { Badge } from "../../react/Badge";import Button, { ButtonGroup } from "../../react/Button";import Dropdown from "../../react/Dropdown";@@ -46,49 +43,40 @@ const FILTER_DEBOUNCE_MS = 300;* note in the context of its parent, which this list is not: these notes live all over the tree.*/function ContentItemMenu({ note }: { note: FNote }) {- const openMenu = useCallback((e: TargetedMouseEvent<HTMLElement>) => {- const items: MenuItem<ContentItemCommand>[] = [- { title: t("link_context_menu.open_note_in_new_tab"), command: "openNoteInNewTab", uiIcon: "bx bx-link-external" },- { title: t("tree-context-menu.delete"), command: "deleteNote", uiIcon: "bx bx-trash destructive-action-icon" }- ];-- void contextMenu.show<ContentItemCommand>({- x: e.pageX,- y: e.pageY,- items,- selectMenuItemHandler: ({ command }) => {- if (command === "openNoteInNewTab") {- void appContext.tabManager.openContextWithNote(note.noteId, {- hoistedNoteId: appContext.tabManager.getActiveContext()?.hoistedNoteId ?? null- });- } else if (command === "deleteNote") {- const branchId = getDisplayedBranchId(note, appContext.tabManager.getActiveContextNotePath());-- if (branchId) {- // One branch, not all of them: the dialog counts a note's *other* placements- // to warn about clones and offer "delete all clones", so passing every branch- // would zero that count and remove them all silently.- // `moveToParent` is off — the user is on this page, not on the note.- void branches.deleteNotes([ branchId ], false, false);- }- }- }- });-- e.stopPropagation();- }, [ note ]);-return (- <ActionButton- className="note-book-item-menu"- icon="bx bx-dots-vertical-rounded" text=""- onClick={openMenu}- />+ <Dropdown+ buttonClassName="note-book-item-menu bx bx-dots-vertical-rounded"+ hideToggleArrow noSelectButtonStyle noDropdownListStyle iconAction+ // Out of the row and into the body: nested, the open menu would still count as hovering+ // the row, leaving it highlighted while the cursor is over the menu.+ portalToBody+ title={t("content_manager.item_menu")}+ dropdownContainerClassName={isMobile() ? "mobile-bottom-menu" : undefined}+ >+ <FormListItem+ icon="bx bx-link-external"+ onClick={() => void appContext.tabManager.openContextWithNote(note.noteId, {+ hoistedNoteId: appContext.tabManager.getActiveContext()?.hoistedNoteId ?? null+ })}+ >{t("link_context_menu.open_note_in_new_tab")}</FormListItem>++ <FormListItem+ icon="bx bx-trash destructive-action-icon"+ onClick={() => {+ const branchId = getDisplayedBranchId(note, appContext.tabManager.getActiveContextNotePath());+ if (!branchId) return;++ // One branch, not all of them: the dialog counts a note's *other* placements to+ // warn about clones and offer "delete all clones", so passing every branch would+ // zero that count and remove them all silently.+ // `moveToParent` is off — the user is on this page, not on the note.+ void branches.deleteNotes([ branchId ], false, false);+ }}+ >{t("tree-context-menu.delete")}</FormListItem>+ </Dropdown>);}-type ContentItemCommand = "openNoteInNewTab" | "deleteNote";-/*** A row's trailing detail, all within one container so the category and the properties read as a* single run rather than as two groups.