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): group the preview, its title and Save in one card
Elian Doran33cdb55f6e08
diff --git a/apps/web-clipper/assets/theme.css b/apps/web-clipper/assets/theme.cssindex eb0247cc5c..20ff70bf72 100644--- a/apps/web-clipper/assets/theme.css+++ b/apps/web-clipper/assets/theme.css@@ -56,6 +56,8 @@--note-icon-background-color: #4f4f4f;--note-icon-color: white;+ --card-background-color: #0000000d;+--button-text-color: currentColor;--icon-button-size: 32px;--icon-button-icon-ratio: 0.65;@@ -113,6 +115,8 @@--note-icon-background-color: #444444;--note-icon-color: #d4d4d4;+ --card-background-color: #ffffff12;+--status-ok-color: #74d369;--status-warning-color: #d3c769;--status-error-color: #d36969;diff --git a/apps/web-clipper/entrypoints/popup/main.tsx b/apps/web-clipper/entrypoints/popup/main.tsxindex 0681168641..ed3faa698c 100644--- a/apps/web-clipper/entrypoints/popup/main.tsx+++ b/apps/web-clipper/entrypoints/popup/main.tsx@@ -238,34 +238,37 @@ function PagePreview({ disabled, shortcut }: { disabled: boolean, shortcut: strireturn (<div className="page-preview">- {page === undefined && <div className="page-preview-placeholder">Reading the page…</div>}- {page === null && <div className="page-preview-placeholder">This page cannot be saved as an article.</div>}{page && (- <>- <div className="page-heading">- <span className="page-icon"><Icon icon={Globe} /></span>- <div className="page-heading-text">- <input- type="text"- className="page-title"- aria-label="Note title"- placeholder="Note title"- value={title}- onInput={(e) => setTitle(e.currentTarget.value)}- />- <div className="page-meta">- {new URL(page.pageUrl).hostname}{published && ` · Published ${published}`}- </div>+ <div className="page-heading">+ <span className="page-icon"><Icon icon={Globe} /></span>+ <div className="page-heading-text">+ <input+ type="text"+ className="page-title"+ aria-label="Note title"+ placeholder="Note title"+ value={title}+ onInput={(e) => setTitle(e.currentTarget.value)}+ />+ <div className="page-meta">+ {new URL(page.pageUrl).hostname}{published && ` · Published ${published}`}</div></div>+ </div>+ )}++ <div className="page-body">+ {page === undefined && <div className="page-preview-placeholder">Reading the page…</div>}+ {page === null && <div className="page-preview-placeholder">This page cannot be saved as an article.</div>}+ {page && (<iframeclassName="page-content"title="Preview of the page"sandbox=""srcDoc={previewDocument(page)}/>- </>- )}+ )}+ </div><buttonclassName="btn btn-primary primary-action"diff --git a/apps/web-clipper/entrypoints/popup/popup.css b/apps/web-clipper/entrypoints/popup/popup.cssindex 198d51fab6..039fc176aa 100644--- a/apps/web-clipper/entrypoints/popup/popup.css+++ b/apps/web-clipper/entrypoints/popup/popup.css@@ -74,13 +74,16 @@ body {.capture-actions {display: flex;flex-direction: column;- gap: 10px;+ gap: 16px;}.page-preview {display: flex;flex-direction: column;- gap: 6px;+ gap: 10px;+ padding: 10px;+ border-radius: 8px;+ background: var(--card-background-color);.page-heading {display: flex;@@ -132,11 +135,27 @@ body {text-overflow: ellipsis;}+ .page-body {+ position: relative;+ overflow: hidden;+ border-radius: 6px;+ background: var(--main-background-color);++ &:has(.page-content)::after {+ content: "";+ position: absolute;+ inset: auto 0 0;+ height: 24px;+ background: linear-gradient(transparent, var(--main-background-color));+ pointer-events: none;+ }+ }+.page-content {+ display: block;width: 100%;height: 200px;- border: 1px solid var(--main-border-color);- border-radius: 6px;+ border: 0;background: var(--main-background-color);}@@ -145,8 +164,7 @@ body {align-items: center;justify-content: center;height: 120px;- border: 1px dashed var(--main-border-color);- border-radius: 6px;+ padding: 12px;color: var(--muted-text-color);text-align: center;}diff --git a/apps/web-clipper/entrypoints/popup/popup.spec.tsx b/apps/web-clipper/entrypoints/popup/popup.spec.tsxindex 1356bd865f..1e1f1ae2d6 100644--- a/apps/web-clipper/entrypoints/popup/popup.spec.tsx+++ b/apps/web-clipper/entrypoints/popup/popup.spec.tsx@@ -170,12 +170,13 @@ describe("popup", () => {expect(tabsQuery).toHaveBeenCalledWith({ active: true, currentWindow: true });expect(tabsSendMessage).toHaveBeenCalledWith(7, { name: "trilium-save-page" });+ expect(cardParts()).toEqual([ "page-heading", "page-body", "btn btn-primary primary-action" ]);const heading = container.querySelector(".page-heading");expect(heading).not.toBeNull();expect(heading?.querySelector(".page-icon svg path")).not.toBeNull();expect(heading?.querySelector<HTMLInputElement>(".page-title")?.value).toBe("An article");expect(heading?.querySelector(".page-meta")?.textContent).toBe("example.com · Published 2024-05-01");- const frame = container.querySelector<HTMLIFrameElement>("iframe.page-content");+ const frame = container.querySelector<HTMLIFrameElement>(".page-body iframe.page-content");expect(frame?.getAttribute("sandbox")).toBe("");expect(frame?.getAttribute("srcdoc")).toBe(previewDocument(PAGE));expect(button("Save page to Trilium")?.disabled).toBe(false);@@ -205,6 +206,7 @@ describe("popup", () => {}));await rerender();expect(placeholder()).toBe("Reading the page…");+ expect(cardParts()).toEqual([ "page-body", "btn btn-primary primary-action" ]);expect(button("Save page to Trilium")?.disabled).toBe(true);resolvePage(undefined);@@ -434,7 +436,7 @@ async function type(selector: string, value: string) {}function placeholder() {- return container.querySelector(".page-preview-placeholder")?.textContent;+ return container.querySelector(".page-body > .page-preview-placeholder")?.textContent;}async function click(text: string) {@@ -453,6 +455,13 @@ function toolbar() {});}+/** The class names of the preview card's parts, in order. */+function cardParts() {+ const card = container.querySelector(".page-preview");+ expect(card).not.toBeNull();+ return [ ...card?.children ?? [] ].map((part) => part.className);+}+function captureButtons() {return [ ...container.querySelectorAll<HTMLButtonElement>(".capture-actions button") ];}