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/text editor/include notes: add a three dots menu
Adorian Dorande8016aecb06
diff --git a/apps/client/src/menus/link_context_menu.spec.ts b/apps/client/src/menus/link_context_menu.spec.tsindex 95efe99bf1..59917374a9 100644--- a/apps/client/src/menus/link_context_menu.spec.ts+++ b/apps/client/src/menus/link_context_menu.spec.ts@@ -292,7 +292,7 @@ describe("openContextMenu", () => {expect(mocks.getTextEditorContaining).toHaveBeenCalledTimes(1);});- describe("on the title of an attachment embed", () => {+ describe("from the title row of an attachment embed", () => {const execute = vi.fn();const selectIncludeAt = vi.fn();const convertCommand = { isEnabled: true };@@ -319,28 +319,36 @@ describe("openContextMenu", () => {editable = document.createElement("div");editable.className = "ck-editor__editable";editable.setAttribute("contenteditable", "true");- editable.innerHTML = `<section class="include-note"><h4 class="include-note-title">`- + `<span><a href="#">report.pdf</a></span></h4></section>`;+ editable.innerHTML = `<section class="include-note">`+ + `<div class="include-note-title-row">`+ + `<h4 class="include-note-title"><span><a href="#">report.pdf</a></span></h4>`+ + `<button class="include-note-menu"></button></div></section>`;});- async function openOnTitle() {- const link = editable.querySelector("a") ?? undefined;- await linkContextMenu.openContextMenu("root/n1", contextMenuEvent(link), VIEW_SCOPE);+ /** Opens the menu as right-clicking `selector`, the title link by default, does. */+ async function openOnTitle(selector = "a") {+ const target = editable.querySelector<HTMLElement>(selector) ?? undefined;+ await linkContextMenu.openContextMenu("root/n1", contextMenuEvent(target), VIEW_SCOPE);return mocks.show.mock.lastCall?.[0].items;}it("ends the menu with converting the embed to a link, selecting it first", async () => {- const items = await openOnTitle();-- const title = editable.querySelector(".include-note-title");- expect(selectIncludeAt).toHaveBeenCalledWith(title);- expect(items.slice(4)).toMatchObject([- { kind: "separator" },- { title: "Download" },- { title: "link_context_menu.convert_embed_to_link", uiIcon: "bx bx-link" }- ]);- items.at(-1).handler();- expect(execute).toHaveBeenCalledWith("convertEmbedToLink");+ // Right-clicking the title, then pressing the menu button beside it.+ for (const selector of [ "a", "button.include-note-menu" ]) {+ selectIncludeAt.mockClear();+ execute.mockClear();+ const items = await openOnTitle(selector);++ const titleRow = editable.querySelector(".include-note-title-row");+ expect(selectIncludeAt).toHaveBeenCalledWith(titleRow);+ expect(items.slice(4)).toMatchObject([+ { kind: "separator" },+ { title: "Download" },+ { title: "link_context_menu.convert_embed_to_link", uiIcon: "bx bx-link" }+ ]);+ items.at(-1).handler();+ expect(execute).toHaveBeenCalledWith("convertEmbedToLink");+ }});it("leaves it out in a read-only note, or for an embed it cannot convert", async () => {diff --git a/apps/client/src/menus/link_context_menu.ts b/apps/client/src/menus/link_context_menu.tsindex 7a0e9558c0..6db69a97fb 100644--- a/apps/client/src/menus/link_context_menu.ts+++ b/apps/client/src/menus/link_context_menu.ts@@ -153,15 +153,18 @@ async function getConvertToEmbedItem(e: ContextMenuEvent): Promise<MenuItem<Comm};}-/** "Convert to link", for the title of an attachment embed in a text note open for editing. */+/**+ * "Convert to link", for a menu opened from the title row of an attachment embed in a text note+ * open for editing.+ */async function getConvertToLinkItem(e: ContextMenuEvent): Promise<MenuItem<CommandNames> | null> {- const title = e.target instanceof Element- ? e.target.closest<HTMLElement>(".include-note-title")+ const titleRow = e.target instanceof Element+ ? e.target.closest<HTMLElement>(".include-note-title-row"): null;- const editor = await getEditingTextEditor(title);- // `convertEmbedToLink` acts on the selected embed, so the right-clicked one is selected first.- if (!title || !editor?.plugins.has("IncludeNote")- || !editor.plugins.get("IncludeNote").selectIncludeAt(title)+ const editor = await getEditingTextEditor(titleRow);+ // `convertEmbedToLink` acts on the selected embed, so the embed of the menu is selected first.+ if (!titleRow || !editor?.plugins.has("IncludeNote")+ || !editor.plugins.get("IncludeNote").selectIncludeAt(titleRow)|| !editor.commands.get("convertEmbedToLink")?.isEnabled) {return null;}diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.cssindex 7fe2be0eb9..221900bd88 100644--- a/apps/client/src/stylesheets/style.css+++ b/apps/client/src/stylesheets/style.css@@ -1582,7 +1582,8 @@ body.mobile .modal-content-with-sidebar > .modal-main > .modal-header > .modal-t.include-note-toggle,.include-note-open,-.include-note-fullscreen {+.include-note-fullscreen,+.include-note-menu {background: none;border: none;padding: 2px;@@ -1598,7 +1599,8 @@ body.mobile .modal-content-with-sidebar > .modal-main > .modal-header > .modal-t.include-note-toggle:hover,.include-note-open:hover,-.include-note-fullscreen:hover {+.include-note-fullscreen:hover,+.include-note-menu:hover {color: var(--main-link-color);}diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex f2c9a405f6..83510d31f8 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -4219,7 +4219,8 @@"cancel": "Cancel","fullscreen": "Fullscreen","exit_fullscreen": "Exit fullscreen",- "open_in_new_tab": "Open in new tab"+ "open_in_new_tab": "Open in new tab",+ "more_actions": "More actions"},"spreadsheet": {"read-only": "This note is read-only.",diff --git a/apps/client/src/widgets/type_widgets/text/utils.spec.ts b/apps/client/src/widgets/type_widgets/text/utils.spec.tsindex 044d7c6048..ef321cf934 100644--- a/apps/client/src/widgets/type_widgets/text/utils.spec.ts+++ b/apps/client/src/widgets/type_widgets/text/utils.spec.ts@@ -23,10 +23,14 @@ vi.mock("../../../services/content_renderer", async () => {};});vi.mock("../../../services/i18n", () => ({ t: (key: string) => key }));-const openTabWithNoteWithHoisting = vi.hoisted(() => vi.fn());+const { openTabWithNoteWithHoisting, openContextMenu } = vi.hoisted(() => ({+ openTabWithNoteWithHoisting: vi.fn(),+ openContextMenu: vi.fn()+}));vi.mock("../../../components/app_context", () => ({default: { tabManager: { openTabWithNoteWithHoisting } }}));+vi.mock("../../../menus/link_context_menu", () => ({ default: { openContextMenu } }));import content_renderer from "../../../services/content_renderer";import froca from "../../../services/froca";@@ -146,7 +150,8 @@ describe("loadIncludedAttachment", () => {expect($row.children().map((_, child) => child.className).get()).toEqual(["include-note-title","include-note-open bx bx-link-external",- "include-note-fullscreen bx bx-fullscreen"+ "include-note-fullscreen bx bx-fullscreen",+ "include-note-menu bx bx-dots-vertical-rounded"]);expect(button.title).toBe("common.fullscreen");@@ -223,8 +228,12 @@ describe("loadIncludedAttachment", () => {});});-describe("the button opening an include in a new tab", () => {+describe("the buttons after the title of an include", () => {+ const attachmentScope = { viewMode: "attachments", attachmentId: "att1" };+beforeEach(() => {+ openTabWithNoteWithHoisting.mockClear();+ openContextMenu.mockClear();vi.mocked(froca.getNote).mockResolvedValue(note);vi.mocked(froca.getAttachment).mockResolvedValue({ attachmentId: "att1", ownerId: "owner" } as unknown as FAttachment@@ -236,37 +245,55 @@ describe("the button opening an include in a new tab", () => {));});- it("follows the title of a note or attachment at any size, and opens it", async () => {- const attachmentScope = { viewMode: "attachments", attachmentId: "att1" };-+ /** A note box and an attachment box of each size, with the note and view scope each shows. */+ async function loadEveryBox() {+ const boxes: [ JQuery<HTMLElement>, string, object | undefined ][] = [];for (const boxSize of [ "small", "medium", "full", "expandable" ]) {const $note = $('<div class="include-note-wrapper">');const $attachment = $('<div class="include-note-wrapper">');await loadIncludedNote("noteY", $note, boxSize);await loadIncludedAttachment("att1", $attachment, boxSize);-- const boxes: [ JQuery<HTMLElement>, string, object | undefined ][] = [- [ $note, "noteY", undefined ],- [ $attachment, "owner", attachmentScope ]- ];- for (const [ $el, notePath, viewScope ] of boxes) {- const $button = $el.find(".include-note-title").next();- expect($button.attr("class")).toBe("include-note-open bx bx-link-external");- expect($button.attr("title")).toBe("common.open_in_new_tab");-- const click = new MouseEvent("click", { bubbles: true });- const stopPropagation = vi.spyOn(click, "stopPropagation");- $button[0].dispatchEvent(click);- expect(openTabWithNoteWithHoisting).toHaveBeenLastCalledWith(notePath, {- viewScope,- activate: true,- placement: "afterCurrent"- });- expect(stopPropagation).toHaveBeenCalled();- }+ boxes.push([ $note, "noteY", undefined ], [ $attachment, "owner", attachmentScope ]);+ }+ return boxes;+ }++ function click(button: HTMLElement) {+ const event = new MouseEvent("click", { bubbles: true });+ const stopPropagation = vi.spyOn(event, "stopPropagation");+ button.dispatchEvent(event);+ return { event, stopPropagation };+ }++ it("opens the note or attachment in a new tab, from right after the title", async () => {+ for (const [ $el, notePath, viewScope ] of await loadEveryBox()) {+ const $button = $el.find(".include-note-title").next();+ expect($button.attr("class")).toBe("include-note-open bx bx-link-external");+ expect($button.attr("title")).toBe("common.open_in_new_tab");++ const { stopPropagation } = click($button[0]);+ expect(openTabWithNoteWithHoisting).toHaveBeenLastCalledWith(notePath, {+ viewScope,+ activate: true,+ placement: "afterCurrent"+ });+ expect(stopPropagation).toHaveBeenCalled();}expect(openTabWithNoteWithHoisting).toHaveBeenCalledTimes(8);});++ it("opens the context menu of the note or attachment from the end of the row", async () => {+ for (const [ $el, notePath, viewScope ] of await loadEveryBox()) {+ const $button = $el.find(".include-note-title-row").children().last();+ expect($button.attr("class")).toBe("include-note-menu bx bx-dots-vertical-rounded");+ expect($button.attr("title")).toBe("common.more_actions");++ const { event, stopPropagation } = click($button[0]);+ expect(openContextMenu).toHaveBeenLastCalledWith(notePath, event, viewScope);+ expect(stopPropagation).toHaveBeenCalled();+ }+ expect(openContextMenu).toHaveBeenCalledTimes(8);+ });});describe("getAttachmentHref", () => {diff --git a/apps/client/src/widgets/type_widgets/text/utils.ts b/apps/client/src/widgets/type_widgets/text/utils.tsindex c8968997db..8ca057428c 100644--- a/apps/client/src/widgets/type_widgets/text/utils.ts+++ b/apps/client/src/widgets/type_widgets/text/utils.ts@@ -1,6 +1,7 @@import { h } from "preact";import appContext from "../../../components/app_context";+import linkContextMenu from "../../../menus/link_context_menu";import content_renderer from "../../../services/content_renderer";import froca from "../../../services/froca";import { t } from "../../../services/i18n";@@ -93,7 +94,12 @@ async function fillIncludeBox(const $toggle = $('<button class="include-note-toggle bx bx-chevron-right" aria-expanded="false">');const $title = $('<h4 class="include-note-title">').append($link);- $titleRow.append($toggle, $title, createOpenInNewTabButton(notePath, viewScope));+ $titleRow.append(+ $toggle,+ $title,+ createOpenInNewTabButton(notePath, viewScope),+ createMenuButton(notePath, viewScope)+ );$wrapper.append($titleRow);const { $renderedContent, type } = await renderContent();@@ -121,6 +127,7 @@ async function fillIncludeBox(await mountExitFullscreenControls($content);}+ $titleRow.append(createMenuButton(notePath, viewScope));$wrapper.append($titleRow, $content);}@@ -145,6 +152,18 @@ function createOpenInNewTabButton(notePath: string, viewScope: ViewScope | undef});}+/** A button opening the context menu that right-clicking the title of an include box opens. */+function createMenuButton(notePath: string, viewScope: ViewScope | undefined) {+ return $('<button type="button" class="include-note-menu bx bx-dots-vertical-rounded">')+ .attr({ title: t("common.more_actions") })+ .on("click", (e) => {+ e.stopPropagation();+ if (e.originalEvent) {+ void linkContextMenu.openContextMenu(notePath, e.originalEvent, viewScope);+ }+ });+}+/** A button giving `content` the whole screen. */function createFullscreenButton(content: HTMLElement) {return $('<button type="button" class="include-note-fullscreen bx bx-fullscreen">')diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Attachments.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Attachments.htmlindex b1fb3debc5..f49dda3c5c 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Attachments.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Attachments.html@@ -84,8 +84,9 @@at the end of its title. To return, press <span class="tn-icon bx bx-exit"></span> <em>Exit fullscreen</em> inthe top-right corner, or <kbd>Esc</kbd>.</li><li>To turn the embed back into a link, select it and press the <span class="tn-icon cke cke-link"></span> <em>Convert to link</em> button- in its toolbar, or right-click its title and select <em>Convert to link</em>,- at the end of the menu.</li>+ in its toolbar. <em>Convert to link</em> also ends the menu that right-clicking+ the title of the embed or pressing its <span class="tn-icon bx bx-dots-vertical-rounded"></span> <em>More actions</em> button+ opens.</li></ul><p>An embed follows its attachment like a link does. Converting the attachmentinto a note turns the embed into an included note. In a <a href="#root/_help_R9pX4DGra2Vt">shared note</a>,diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Include Note.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Include Note.htmlindex dab7c5051f..354bf0169f 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Include Note.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Include Note.html@@ -12,6 +12,10 @@<h2>Opening an included note</h2><p>To open an included note in a new tab, press the <span class="tn-icon bx bx-link-external"></span> <em>Open in new tab</em> buttonat the end of its title. An embedded attachment has the same button.</p>+<p>The <span class="tn-icon bx bx-dots-vertical-rounded"></span> <em>More actions</em> button+ at the end of the title row opens the same menu as right-clicking the title:+ the other places to open the note in and, for an embedded attachment, the+ actions on the attachment.</p><h2>Included notes in the share functionality</h2><p>If a <a href="#root/_help_R9pX4DGra2Vt">shared note</a> contains one ormore included notes, they will be displayed in the content of the notediff --git a/docs/User Guide/User Guide/Basic Concepts and Features/Notes/Attachments.md b/docs/User Guide/User Guide/Basic Concepts and Features/Notes/Attachments.mdindex 7e7330cb1f..242f912a48 100644--- a/docs/User Guide/User Guide/Basic Concepts and Features/Notes/Attachments.md+++ b/docs/User Guide/User Guide/Basic Concepts and Features/Notes/Attachments.md@@ -44,7 +44,7 @@ An attachment can be shown in the text instead of linked, the way <a class="ref* An embed takes the default box size of included notes. To change its size, select the embed and use the box size menu in its toolbar.* To open the attachment in a new tab, press the <span class="tn-icon bx bx-link-external"></span> _Open in new tab_ button at the end of the embed's title.* To show an embed of size _Medium_ or _Full_ on the whole screen, press the <span class="tn-icon bx bx-fullscreen"></span> _Fullscreen_ button at the end of its title. To return, press <span class="tn-icon bx bx-exit"></span> _Exit fullscreen_ in the top-right corner, or <kbd>Esc</kbd>.-* To turn the embed back into a link, select it and press the <span class="tn-icon cke cke-link"></span> _Convert to link_ button in its toolbar, or right-click its title and select _Convert to link_, at the end of the menu.+* To turn the embed back into a link, select it and press the <span class="tn-icon cke cke-link"></span> _Convert to link_ button in its toolbar. _Convert to link_ also ends the menu that right-clicking the title of the embed or pressing its <span class="tn-icon bx bx-dots-vertical-rounded"></span> _More actions_ button opens.An embed follows its attachment like a link does. Converting the attachment into a note turns the embed into an included note. In a [shared note](../../Advanced%20Usage/Sharing.md), an embedded picture is displayed, and any other attachment appears as a link to download it.diff --git a/docs/User Guide/User Guide/Note Types/Text/Include Note.md b/docs/User Guide/User Guide/Note Types/Text/Include Note.mdindex 25aa198665..b44e5b3735 100644--- a/docs/User Guide/User Guide/Note Types/Text/Include Note.md+++ b/docs/User Guide/User Guide/Note Types/Text/Include Note.md@@ -13,6 +13,8 @@ An [attachment](../../Basic%20Concepts%20and%20Features/Notes/Attachments.md) caTo open an included note in a new tab, press the <span class="tn-icon bx bx-link-external"></span> _Open in new tab_ button at the end of its title. An embedded attachment has the same button.+The <span class="tn-icon bx bx-dots-vertical-rounded"></span> _More actions_ button at the end of the title row opens the same menu as right-clicking the title: the other places to open the note in and, for an embedded attachment, the actions on the attachment.+## Included notes in the share functionalityIf a [shared note](../../Advanced%20Usage/Sharing.md) contains one or more included notes, they will be displayed in the content of the note as if they were part of the note itself.