Skip to content

Build your personal knowledge base with Trilium Notes

feat(text): merge image upload into the attach menu on desktop

Elian Doran16c8c0888e6c
diff --git a/apps/client/src/widgets/type_widgets/text/toolbar.spec.ts b/apps/client/src/widgets/type_widgets/text/toolbar.spec.ts
index 1293d91d12..5c5aa4f781 100644
--- a/apps/client/src/widgets/type_widgets/text/toolbar.spec.ts
+++ b/apps/client/src/widgets/type_widgets/text/toolbar.spec.ts
@@ -70,6 +70,20 @@ describe("the Insert group", () => {
});
});
+describe("the attach menu", () => {
+ it("replaces the image and file uploads on every toolbar, with the camera only on a phone", () => {
+ const classic = buildClassicToolbar(false, true);
+ const floating = buildFloatingToolbar(true);
+ for (const items of [ classic.toolbar.items, floating.blockToolbar ]) {
+ expect(items).toContain("attachMenu");
+ expect(items).not.toContain("imageUpload");
+ expect(items).not.toContain("fileUpload");
+ }
+ expect("attachMenu" in classic || "attachMenu" in floating).toBe(false);
+ expect(buildMobileToolbar(true).attachMenu).toStrictEqual({ camera: true });
+ });
+});
+
describe("buildClassicToolbar", () => {
it("reflects the multiline flag via shouldNotGroupWhenFull", () => {
expect(buildClassicToolbar(false, true).toolbar.shouldNotGroupWhenFull).toBe(false);
@@ -224,8 +238,6 @@ describe("buildMobileToolbar", () => {
todoList: "blockType",
fontSize: "fontSizeMenu",
fontColor: "colorMenu",
- imageUpload: "attachMenu",
- fileUpload: "attachMenu",
fontBackgroundColor: "colorMenu",
aiAssistant: "aiAssistantMenu"
};
diff --git a/apps/client/src/widgets/type_widgets/text/toolbar.ts b/apps/client/src/widgets/type_widgets/text/toolbar.ts
index c73b1b2933..ee05d36811 100644
--- a/apps/client/src/widgets/type_widgets/text/toolbar.ts
+++ b/apps/client/src/widgets/type_widgets/text/toolbar.ts
@@ -132,7 +132,8 @@ export function buildMobileToolbar(aiAssistant: boolean) {
"outdent", "indent", "moveBlockUp", "moveBlockDown",
"|",
"listTypeMenu", "listStartAt", "listReversed"
- ]
+ ],
+ attachMenu: { camera: true }
};
}
@@ -164,8 +165,7 @@ export function buildClassicToolbar(multilineToolbar: boolean, aiAssistant: bool
// down among the last items the assistant was grouped away at every ordinary note
// width.
...(aiAssistant ? ["aiAssistant"] : []),
- "imageUpload",
- "fileUpload",
+ "attachMenu",
"blockQuote",
"admonition",
"insertTable",
@@ -238,8 +238,7 @@ export function buildFloatingToolbar(aiAssistant: boolean) {
"numberedList",
"todoList",
"|",
- "imageUpload",
- "fileUpload",
+ "attachMenu",
"blockQuote",
"admonition",
"codeBlock",
diff --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.md
index 1a9c3f16a1..6bb81620f6 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
@@ -21,13 +21,13 @@ The system attachments are displayed at the end of the attachments list, in a de
## Attaching files from a text note
-To attach files to a <a class="reference-link" href="../../Note%20Types/Text.md">Text</a> note and embed them in its content, press the <span class="tn-icon cke cke-paper-clip"></span>_Attach file_ button in the <a class="reference-link" href="../../Note%20Types/Text/Formatting%20toolbar.md">Formatting toolbar</a>, next to the <span class="tn-icon cke cke-image-upload"></span>image upload button, and select one or more files (see _Embedding an attachment_ below). The arrow beside the button lists the same action as _Attach and embed file_, followed by _Attach file as a link_, which links the files instead. Both actions are also available as _Attach file as a link_ and _Attach and embed file_ in the <a class="reference-link" href="../../Note%20Types/Text/Slash%20Commands.md">Slash Commands</a>. On a phone, the button opens _Image_, _Camera_, _Attach and embed file_ and _Attach file as a link_ as a list instead (see <a class="reference-link" href="../../Installation%20%26%20Setup/Mobile%20Frontend.md">Mobile Frontend</a>).
+To attach files to a <a class="reference-link" href="../../Note%20Types/Text.md">Text</a> note and embed them in its content, press the <span class="tn-icon cke cke-paper-clip"></span>_Attach file_ button in the <a class="reference-link" href="../../Note%20Types/Text/Formatting%20toolbar.md">Formatting toolbar</a>, choose _Attach and embed file_ and select one or more files (see _Embedding an attachment_ below). The same menu offers _Image_, which inserts pictures (see <a class="reference-link" href="../../Note%20Types/Text/Images.md">Images</a>), and _Attach file as a link_, which links the files instead. Both file actions are also available as _Attach file as a link_ and _Attach and embed file_ in the <a class="reference-link" href="../../Note%20Types/Text/Slash%20Commands.md">Slash Commands</a>. On a phone, the menu also offers _Camera_ (see <a class="reference-link" href="../../Installation%20%26%20Setup/Mobile%20Frontend.md">Mobile Frontend</a>).
When files are attached as links:
* Each file becomes an attachment of the note, and a link to it is inserted at the cursor. Several files produce several links, separated by a space.
* While a file uploads, its link shows the file name and a toast shows the progress.
-* Pictures appear as links rather than images, and are attached exactly as they are, without being compressed. To display a picture in the text, use the image upload button instead (see <a class="reference-link" href="../../Note%20Types/Text/Images.md">Images</a>).
+* Pictures appear as links rather than images, and are attached exactly as they are, without being compressed. To display a picture in the text, use _Image_ in the same menu instead (see <a class="reference-link" href="../../Note%20Types/Text/Images.md">Images</a>).
Dragging a file that is not a picture from the file explorer onto the text also attaches it and inserts a link to it.
@@ -41,7 +41,7 @@ Links follow changes to their attachment: renaming it updates the title they sho
An attachment can be shown in the text instead of linked, the way <a class="reference-link" href="../../Note%20Types/Text/Include%20Note.md">Include Note</a> shows a note: a picture is displayed, a PDF, a video or a document is previewed, a code or text file is shown with syntax highlighting, and a Markdown file such as a `.md` file is shown rendered. An embedded code file can also be edited in place (see _Editing an include in place_ in <a class="reference-link" href="../../Note%20Types/Text/Include%20Note.md">Include Note</a>), and an embedded Markdown file shows its source, its rendering or both, as an included Markdown note does (see _Included Markdown_ there).
-* To attach files and embed them straight away, press the <span class="tn-icon cke cke-paper-clip"></span>_Attach file_ button. Each file gets an embed of its own, which shows the file name while the file uploads.
+* To attach files and embed them straight away, press the <span class="tn-icon cke cke-paper-clip"></span>_Attach file_ button and choose _Attach and embed file_. Each file gets an embed of its own, which shows the file name while the file uploads.
* To embed an attachment that is already linked, right-click a link to it in a text note being edited and select _Convert link to an embed_, at the end of the menu.
* A drawing canvas, inserted with <span class="tn-icon bx bx-pen"></span>_Drawing canvas_ in the <span class="tn-icon cke cke-plus"></span>_Insert_ menu, is an embed of a `Canvas.excalidraw` attachment that can be drawn on in place. An attached Excalidraw file (`.excalidraw`) is embedded as a drawing canvas too (see _Drawing canvases_ in <a class="reference-link" href="../../Note%20Types/Text/Include%20Note.md">Include Note</a>).
* An embed gets the box size that suits the attachment, as a new included note does (see _Box sizes_ there). To change its size, select the embed and use the box size menu in its toolbar, or the _Size_ submenu of its <span class="tn-icon bx bx-dots-vertical-rounded"></span>_More actions_ menu. A _Small_, _Medium_ or _Expandable_ embed can also be resized by dragging its handles (see _Resizing_ there).
diff --git a/docs/User Guide/User Guide/Installation & Setup/Mobile Frontend.md b/docs/User Guide/User Guide/Installation & Setup/Mobile Frontend.md
index bd7b9b834e..4ca9f40620 100644
--- a/docs/User Guide/User Guide/Installation & Setup/Mobile Frontend.md
+++ b/docs/User Guide/User Guide/Installation & Setup/Mobile Frontend.md
@@ -108,7 +108,7 @@ A single color button replaces the separate text and background color buttons. I
The <span class="tn-icon cke cke-link"></span> link button replaces the separate link and internal link buttons. It opens the _Add link_ dialog, which links to a note or to a web address, or _Edit link_ when the cursor is inside a link. The dialog does not open the keyboard by itself; tap the note or address field to type. The same button is on the row of text formatting, after the inline styles, to turn selected text into a link.
-The <span class="tn-icon cke cke-paper-clip"></span> button replaces the separate image upload and attach file buttons. It opens _Image_, _Camera_, _Attach and embed file_ and _Attach file as a link_ as a list. _Camera_ opens the device's camera and inserts the photo taken; the others open the device's file picker.
+The <span class="tn-icon cke cke-paper-clip"></span> button opens _Image_, _Camera_, _Attach and embed file_ and _Attach file as a link_ as a list: the menu of the desktop toolbar, with _Camera_ added. _Camera_ opens the device's camera and inserts the photo taken; the others open the device's file picker.
## Installing as a PWA
diff --git a/docs/User Guide/User Guide/Note Types/Text/Images.md b/docs/User Guide/User Guide/Note Types/Text/Images.md
index e1ec05d8ad..193403bd55 100644
--- a/docs/User Guide/User Guide/Note Types/Text/Images.md
+++ b/docs/User Guide/User Guide/Note Types/Text/Images.md
@@ -8,12 +8,12 @@ An image can be uploaded in the form of note's [attachment](../../Basic%20Concep
To add an image to the note:
* Simply drag it from file explorer onto the note editor inside Trilium and the image will be uploaded.
-* Alternatively, from the <a class="reference-link" href="Formatting%20toolbar.md">Formatting toolbar</a> look for the <span class="tn-icon cke cke-image-upload"></span> _Upload image from computer_ button.
-* On the <a class="reference-link" href="../../Installation%20%26%20Setup/Mobile%20Frontend.md">Mobile Frontend</a>, press the <span class="tn-icon cke cke-paper-clip"></span> button of the formatting toolbar and select _Camera_ to take a photo and insert it.
+* Alternatively, in the <a class="reference-link" href="Formatting%20toolbar.md">Formatting toolbar</a>, press the <span class="tn-icon cke cke-paper-clip"></span>_Attach file_ button and select _Image_.
+* On the <a class="reference-link" href="../../Installation%20%26%20Setup/Mobile%20Frontend.md">Mobile Frontend</a>, the same menu also offers _Camera_, which takes a photo and inserts it.
* You can also copy and paste an image from web (see section below).
> [!TIP]
-> To link a picture instead of displaying it, attach it with _Attach file as a link_, from the arrow beside the <span class="tn-icon cke cke-paper-clip"></span>_Attach file_ button. See <a class="reference-link" href="../../Basic%20Concepts%20and%20Features/Notes/Attachments.md">Attachments</a>.
+> To link a picture instead of displaying it, attach it with _Attach file as a link_, from the <span class="tn-icon cke cke-paper-clip"></span>_Attach file_ button. See <a class="reference-link" href="../../Basic%20Concepts%20and%20Features/Notes/Attachments.md">Attachments</a>.
## Clipboard & automatic download of images
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.md
index adae3a60be..0e10409d49 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
@@ -149,7 +149,7 @@ A drawing canvas is an Excalidraw canvas, like the one of a <a class="reference-
* To insert a drawing canvas, open the <span class="tn-icon cke cke-plus"></span> _Insert_ menu of the <a class="reference-link" href="Formatting%20toolbar.md">Formatting toolbar</a> and choose <span class="tn-icon bx bx-pen"></span> _Drawing canvas_, above _Mermaid diagram_. It is also available as _Drawing canvas_ in the <a class="reference-link" href="Slash%20Commands.md">Slash Commands</a>. The canvas is added empty and editable, in a _Medium_ box with its title hidden, and takes the focus, ready for drawing.
* To draw or write over an image, select the image and press the <span class="tn-icon bx bxs-pen"></span> _Convert image to a drawing canvas_ button of its toolbar. The image is replaced by an editable drawing canvas in a _Medium_ box, with its title hidden and the focus in it. The image sits at its original size in the middle of the canvas, zoomed so that all of it shows, and is locked so that it cannot be selected or moved by accident. While it is locked, the canvas can be zoomed in on the image but not zoomed out past it or scrolled beyond its edges. To move or resize the image anyway, right-click it and choose _Unlock_. The caption of the image is kept, but not its alignment or link. Only an image on its own line can be converted, not one inside a paragraph. Undo brings the image back.
-* An Excalidraw file (`.excalidraw`) attached with the <span class="tn-icon cke cke-paper-clip"></span>_Attach file_ button becomes a drawing canvas too, in a _Medium_ box titled with the file name. It starts with _Editable_ off, so the drawing shows but cannot be changed until _Editable_ is turned on (see below).
+* An Excalidraw file (`.excalidraw`) attached with _Attach and embed file_, under the <span class="tn-icon cke cke-paper-clip"></span>_Attach file_ button, becomes a drawing canvas too, in a _Medium_ box titled with the file name. It starts with _Editable_ off, so the drawing shows but cannot be changed until _Editable_ is turned on (see below).
* To draw on a canvas that does not have the focus, click it first. Until then, touch gestures scroll the note. The canvas then has the tools, menus and keyboard shortcuts of a Canvas note. The toolbars, the menus and the properties of the selected shapes show only while the canvas has the focus, so elsewhere the drawing reads like a picture in the text.
* The mouse wheel and the touchpad scroll the note over a canvas too, as over the text. To zoom, use the zoom buttons of the canvas toolbar; to move around the drawing, use the <span class="tn-icon bx bxs-hand"></span> _Hand_ tool. In fullscreen, the mouse wheel moves and zooms the drawing instead.
* The canvas toolbar replaces the Excalidraw menu: _Export image_, _Find on canvas_, _Library_ and _Help_ are at the end of its <span class="tn-icon bx bx-category"></span> _More tools_ menu. In fullscreen, the Excalidraw menu shows again.
diff --git a/packages/ckeditor5/src/plugins/mobile_toolbar_items.spec.ts b/packages/ckeditor5/src/plugins/mobile_toolbar_items.spec.ts
index 8ae136cd30..358e8c859d 100644
--- a/packages/ckeditor5/src/plugins/mobile_toolbar_items.spec.ts
+++ b/packages/ckeditor5/src/plugins/mobile_toolbar_items.spec.ts
@@ -462,14 +462,15 @@ describe("attachMenu", () => {
}
}
- async function createAttachEditor() {
+ async function createAttachEditor(camera = true) {
const requests: ToolbarGroupMenuRequest[] = [];
const host = { show: vi.fn((request: ToolbarGroupMenuRequest) => requests.push(request)), hide: vi.fn(), destroy: vi.fn() };
const editor = await createTestEditor([
Essentials, Paragraph, Image, ImageUpload, UploadCommands, FileUploadUI, MobileToolbarItems, ToolbarGroupMenu
], {
toolbar: ["attachMenu"],
- toolbarGroupMenu: { host: () => host }
+ toolbarGroupMenu: { host: () => host },
+ ...(camera ? { attachMenu: { camera: true } } : {})
});
return { editor, requests };
}
@@ -506,6 +507,13 @@ describe("attachMenu", () => {
expect(icons(tiles)).toStrictEqual([IconImageUpload, bxCamera, bxShapeSquare, bxLink]);
});
+ it("leaves out the camera unless it is asked for", async () => {
+ const { editor, requests } = await createAttachEditor(false);
+ getDropdown(editor, 0).buttonView.fire("open");
+ expect((requests.at(-1)?.items ?? []).map(rowText))
+ .toStrictEqual(["Image", "Attach and embed file", "Attach file as a link"]);
+ });
+
it("picks images for the image tile, takes a photo for the camera tile, and any file for the others", async () => {
const { editor, requests } = await createAttachEditor();
const upload = vi.spyOn(editor, "execute").mockImplementation(() => undefined);
diff --git a/packages/ckeditor5/src/plugins/mobile_toolbar_items.ts b/packages/ckeditor5/src/plugins/mobile_toolbar_items.ts
index c988761d9f..8374fc7e88 100644
--- a/packages/ckeditor5/src/plugins/mobile_toolbar_items.ts
+++ b/packages/ckeditor5/src/plugins/mobile_toolbar_items.ts
@@ -77,16 +77,17 @@ interface BlockType {
}
/**
- * Registers variants of toolbar items for the narrow toolbar of a phone. When a host is configured,
- * `ToolbarGroupMenu` opens the lists of both as the host application's menu.
+ * Registers variants of toolbar items, most of them for the narrow toolbar of a phone. When a host
+ * is configured, `ToolbarGroupMenu` opens their lists as the host application's menu.
*
* - `blockType`: what Notion calls "Turn into". The paragraph, the headings of the `heading`
* configuration, the bulleted, numbered and to-do lists and the code block, which replace each
* other, and the block quote and the admonition, which wrap the block. One dropdown, under an
* icon of its own rather than the name of the current block, which takes 8em.
* - `fontSizeMenu`: the `fontSize` dropdown.
- * - `attachMenu`: the image upload, a photo taken with the camera and the rows of the `fileUpload`
- * list as a list, under a paperclip. A row whose feature the editor lacks is left out.
+ * - `attachMenu`: the image upload, a photo taken with the camera when `attachMenu.camera` is set,
+ * and the rows of the `fileUpload` list as a list, under a paperclip. A row whose feature the
+ * editor lacks is left out.
* - `addImage`: the image upload of the menu bar, labelled "Image", which the `attachMenu` row
* is too, for the insert menu.
* - `addLink`: one link button, which opens the link dialog of the internal link button for a link to
@@ -281,14 +282,16 @@ export default class MobileToolbarItems extends Plugin {
if (editor.ui.componentFactory.has("addImage")) {
buttons.push(editor.ui.componentFactory.create("addImage") as ButtonView);
- const camera = editor.ui.componentFactory.create("menuBar:uploadImage") as ButtonView & {
- allowMultipleFiles: boolean;
- };
- camera.set({ label: t("Camera"), icon: bxCamera, allowMultipleFiles: false });
- // Rendering adds the file input, which `capture` points at the rear camera.
- camera.render();
- camera.element?.querySelector("input[type=file]")?.setAttribute("capture", "environment");
- buttons.push(camera);
+ if (editor.config.get("attachMenu")?.camera) {
+ const camera = editor.ui.componentFactory.create("menuBar:uploadImage") as ButtonView & {
+ allowMultipleFiles: boolean;
+ };
+ camera.set({ label: t("Camera"), icon: bxCamera, allowMultipleFiles: false });
+ // Rendering adds the file input, which `capture` points at the rear camera.
+ camera.render();
+ camera.element?.querySelector("input[type=file]")?.setAttribute("capture", "environment");
+ buttons.push(camera);
+ }
}
if (editor.plugins.has(FileUploadUI)) {
buttons.push(...editor.plugins.get(FileUploadUI).createListButtons(locale));
@@ -493,5 +496,13 @@ declare module "ckeditor5" {
* current number. Resolves to `null` when nothing is to change.
*/
listStartPrompt?(label: string, current: number): Promise<number | null>;
+
+ attachMenu?: {
+ /**
+ * Whether `attachMenu` offers a photo taken with the camera. Desktop browsers ignore the
+ * `capture` attribute of a file input, so there the row opens the same picker as "Image".
+ */
+ camera?: boolean;
+ };
}
}