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
feat(web-clipper): put the popup's other actions in an icon toolbar
Elian Doran7aecb66f2eed
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Web Clipper.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Web Clipper.htmlindex 4a57050fbd..5482fc9365 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Web Clipper.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Web Clipper.html@@ -41,11 +41,13 @@the extension cannot read, such as the browser's own pages, say so instead.The keyboard shortcut and the context menu still save the page right away,without a preview.</li>- <li>Below the preview are <em>Crop screenshot</em>, <em>Visible area screenshot</em>, <em>Link with a note</em> and <em>All tabs in window</em> (which- saves the links of every tab in the current window as a list). An action- that has a keyboard shortcut shows it.</li>- <li><em>Link with a note</em> opens a small editor in place of the actions.- The first sentence or line of the text becomes the note's title, unless <em>Keep page title as note title</em> is+ <li>Below the preview, a row of buttons offers the other actions: <em>Crop</em> (a+ screenshot of an area you select), <em>Screenshot</em> (of the visible part+ of the page), <em>Note</em> (a link with a note) and <em>Tabs</em> (saves the+ links of every tab in the current window as a list). Hovering over a button+ shows its full name and, if it has one, its keyboard shortcut.</li>+ <li><em>Note</em> opens a small editor in place of the actions. The first sentence+ or line of the text becomes the note's title, unless <em>Keep page title as note title</em> ischecked. Press <em>Save</em> or <kbd>Ctrl</kbd>+<kbd>Enter</kbd> to save it,or the back arrow to return to the actions.</li><li>If the current page was already clipped, a notice at the top offers todiff --git a/apps/web-clipper/entrypoints/popup/main.tsx b/apps/web-clipper/entrypoints/popup/main.tsxindex 25288bbfdf..effd8ce59e 100644--- a/apps/web-clipper/entrypoints/popup/main.tsx+++ b/apps/web-clipper/entrypoints/popup/main.tsx@@ -18,6 +18,7 @@ import { useEffect, useRef, useState } from "preact/hooks";import type { TriliumSearchNoteStatus, TriliumSearchStatus } from "../background/trilium_server_facade";const HELP_URL = "https://docs.triliumnotes.org/user-guide/setup/web-clipper";+const DISCONNECTED_TITLE = "This action can't be performed without active connection to Trilium.";type PopupMessage = {name: "trilium-search-status";@@ -159,11 +160,6 @@ function CaptureActions({ disabled, shortcuts, onWriteNote }: {shortcuts: Shortcuts;onWriteNote: () => void;}) {- const actionProps = {- disabled,- title: disabled ? "This action can't be performed without active connection to Trilium." : undefined- };-function sendAndClose(name: string) {void sendMessage({ name });window.close();@@ -173,30 +169,49 @@ function CaptureActions({ disabled, shortcuts, onWriteNote }: {<div className="capture-actions"><PagePreview disabled={disabled} shortcut={shortcuts.saveWholePage} />- <div className="action-tiles">- <button className="btn btn-secondary action-tile" {...actionProps} onClick={() => sendAndClose("save-cropped-screenshot")}>- <Icon icon={Crop} />- <span className="action-label">Crop screenshot</span>- <Shortcut keys={shortcuts.saveCroppedScreenshot} />- </button>- <button className="btn btn-secondary action-tile" {...actionProps} onClick={() => sendAndClose("save-whole-screenshot")}>- <Icon icon={Screenshot} />- <span className="action-label">Visible area screenshot</span>- </button>- <button className="btn btn-secondary action-tile" {...actionProps} onClick={onWriteNote}>- <Icon icon={Link} />- <span className="action-label">Link with a note</span>- </button>- <button className="btn btn-secondary action-tile" {...actionProps} onClick={() => sendMessage({ name: "save-tabs" })}>- <Icon icon={Tabs} />- <span className="action-label">All tabs in window</span>- <Shortcut keys={shortcuts.saveTabs} />- </button>+ <div className="toolbar">+ <ToolbarAction+ icon={Crop} label="Crop" name="Crop screenshot"+ shortcut={shortcuts.saveCroppedScreenshot} disabled={disabled}+ onClick={() => sendAndClose("save-cropped-screenshot")}+ />+ <ToolbarAction+ icon={Screenshot} label="Screenshot" name="Visible area screenshot" disabled={disabled}+ onClick={() => sendAndClose("save-whole-screenshot")}+ />+ <ToolbarAction icon={Link} label="Note" name="Link with a note" disabled={disabled} onClick={onWriteNote} />+ <ToolbarAction+ icon={Tabs} label="Tabs" name="All tabs in window"+ shortcut={shortcuts.saveTabs} disabled={disabled}+ onClick={() => sendMessage({ name: "save-tabs" })}+ /></div></div>);}+/** A secondary action: an icon over a short label, its full name and shortcut in the tooltip. */+function ToolbarAction({ icon, label, name, shortcut, disabled, onClick }: {+ icon: IconDefinition;+ label: string;+ name: string;+ shortcut?: string;+ disabled: boolean;+ onClick: () => void;+}) {+ let title = shortcut ? `${name} (${shortcut})` : name;+ if (disabled) {+ title = DISCONNECTED_TITLE;+ }++ return (+ <button className="toolbar-action" disabled={disabled} title={title} aria-label={name} onClick={onClick}>+ <Icon icon={icon} />+ <span className="action-label">{label}</span>+ </button>+ );+}+/*** The readable version of the current page, with its title editable, and the button that saves it.* The page's HTML comes from an arbitrary website, so it is shown only in a sandboxed frame.@@ -249,7 +264,7 @@ function PagePreview({ disabled, shortcut }: { disabled: boolean, shortcut: stri<buttonclassName="btn btn-primary primary-action"disabled={disabled || !page}- title={disabled ? "This action can't be performed without active connection to Trilium." : undefined}+ title={disabled ? DISCONNECTED_TITLE : undefined}onClick={page ? () => save(page) : undefined}><Icon icon={Article} />diff --git a/apps/web-clipper/entrypoints/popup/popup.css b/apps/web-clipper/entrypoints/popup/popup.cssindex 44ec6bf956..a5b044c367 100644--- a/apps/web-clipper/entrypoints/popup/popup.css+++ b/apps/web-clipper/entrypoints/popup/popup.css@@ -126,24 +126,44 @@ body {}}- .action-tiles {+ .toolbar {display: grid;- grid-template-columns: 1fr 1fr;- gap: 6px;+ grid-template-columns: repeat(4, 1fr);+ gap: 4px;}- button.btn.action-tile {- justify-content: flex-start;- min-width: 0;- padding: 4px 8px;- font-size: 0.95em;+ .toolbar-action {+ display: flex;+ flex-direction: column;+ align-items: center;+ gap: 4px;+ padding: 6px 4px;+ border: 0;+ border-radius: 6px;+ background: transparent;+ color: var(--main-text-color);+ font-size: 0.85em;+ line-height: 1.3;+ cursor: pointer;++ svg.icon {+ width: 22px;+ height: 22px;+ color: var(--cmd-button-icon-color);+ }- .action-label {- overflow: hidden;- flex-grow: 1;- text-align: start;- white-space: nowrap;- text-overflow: ellipsis;+ &:hover:not(:disabled) {+ background: var(--icon-button-hover-background);+ color: var(--icon-button-hover-color);+ }++ &:active:not(:disabled) svg.icon {+ transform: scale(0.9);+ }++ &:disabled {+ cursor: default;+ opacity: 0.5;}}diff --git a/apps/web-clipper/entrypoints/popup/popup.spec.tsx b/apps/web-clipper/entrypoints/popup/popup.spec.tsxindex 7316591e16..e8405a644a 100644--- a/apps/web-clipper/entrypoints/popup/popup.spec.tsx+++ b/apps/web-clipper/entrypoints/popup/popup.spec.tsx@@ -63,7 +63,9 @@ describe("popup", () => {await receive({ name: "trilium-search-status", triliumSearch: { status: "found-desktop", port: 37840, url: "" } });expect(status()).toEqual({ dot: "status-dot status-dot-ok", text: "Connected to the desktop app on port 37840" });expect(container.querySelector(".connection .status-ok")).not.toBeNull();- expect(captureButtons().every((button) => !button.disabled && !button.title)).toBe(true);+ expect(captureButtons().every((button) => !button.disabled)).toBe(true);+ expect(button("Save page to Trilium")?.title).toBe("");+ expect(button("Crop screenshot")?.title).toBe("Crop screenshot (Ctrl+Shift+E)");expect(sendMessage).toHaveBeenCalledWith({ name: "trigger-trilium-search-note-url" });await receive({@@ -155,10 +157,13 @@ describe("popup", () => {it("shows the keyboard shortcut of each action that has one", () => {expect(getAllCommands).toHaveBeenCalledOnce();expect(shortcutOf("Save page to Trilium")).toBe("Alt+Shift+S");- expect(shortcutOf("Crop screenshot")).toBe("Ctrl+Shift+E");- expect(shortcutOf("All tabs in window")).toBeUndefined();- expect(shortcutOf("Visible area screenshot")).toBeUndefined();- expect(shortcutOf("Link with a note")).toBeUndefined();+ expect(toolbar()).toEqual([+ { label: "Crop", title: "Crop screenshot (Ctrl+Shift+E)" },+ { label: "Screenshot", title: "Visible area screenshot" },+ { label: "Note", title: "Link with a note" },+ { label: "Tabs", title: "All tabs in window" }+ ]);+ expect(container.querySelectorAll(".toolbar-action kbd")).toHaveLength(0);});it("previews the readable page with its title, source and date", () => {@@ -438,6 +443,13 @@ function shortcutOf(text: string) {return button(text)?.querySelector("kbd")?.textContent;}+function toolbar() {+ return [ ...container.querySelectorAll<HTMLButtonElement>(".toolbar-action") ].map((action) => {+ expect(action.getAttribute("aria-label")).toBe(action.title.replace(/ \(.*\)$/, ""));+ return { label: action.querySelector(".action-label")?.textContent, title: action.title };+ });+}+function captureButtons() {return [ ...container.querySelectorAll<HTMLButtonElement>(".capture-actions button") ];}diff --git a/docs/User Guide/User Guide/Installation & Setup/Web Clipper.md b/docs/User Guide/User Guide/Installation & Setup/Web Clipper.mdindex e820d5d7aa..dd9d956d11 100644--- a/docs/User Guide/User Guide/Installation & Setup/Web Clipper.md+++ b/docs/User Guide/User Guide/Installation & Setup/Web Clipper.md@@ -31,8 +31,8 @@ Clicking the extension's button in the browser toolbar opens its popup:* The header shows whether the extension is connected to Trilium, as a colored dot (green when connected, amber when the versions are not compatible, red when Trilium was not found), next to the buttons for the extension's options and for this help page.* The popup reads the current page as an article and shows a preview of what will be saved: the note's title, which can be edited before saving, the website and the publication date (when the page states one), and the article's text and images. _Save page to Trilium_ saves it. Pages the extension cannot read, such as the browser's own pages, say so instead. The keyboard shortcut and the context menu still save the page right away, without a preview.-* Below the preview are _Crop screenshot_, _Visible area screenshot_, _Link with a note_ and _All tabs in window_ (which saves the links of every tab in the current window as a list). An action that has a keyboard shortcut shows it.-* _Link with a note_ opens a small editor in place of the actions. The first sentence or line of the text becomes the note's title, unless _Keep page title as note title_ is checked. Press _Save_ or <kbd>Ctrl</kbd>+<kbd>Enter</kbd> to save it, or the back arrow to return to the actions.+* Below the preview, a row of buttons offers the other actions: _Crop_ (a screenshot of an area you select), _Screenshot_ (of the visible part of the page), _Note_ (a link with a note) and _Tabs_ (saves the links of every tab in the current window as a list). Hovering over a button shows its full name and, if it has one, its keyboard shortcut.+* _Note_ opens a small editor in place of the actions. The first sentence or line of the text becomes the note's title, unless _Keep page title as note title_ is checked. Press _Save_ or <kbd>Ctrl</kbd>+<kbd>Enter</kbd> to save it, or the back arrow to return to the actions.* If the current page was already clipped, a notice at the top offers to open the note in Trilium.* If Trilium cannot be found, the popup explains why instead of showing the actions, with buttons to look for Trilium again and to open the options.* The bottom of the popup describes the connection, with a button to check it again.