Skip to content

Build your personal knowledge base with Trilium Notes

feat(share): show a shared canvas note in the pan and zoom viewer

Elian Doran154660f91b28
diff --git a/packages/share-theme/src/content/note_view.tsx b/packages/share-theme/src/content/note_view.tsx
index 78cfb96e0c..ef26c1dea2 100644
--- a/packages/share-theme/src/content/note_view.tsx
+++ b/packages/share-theme/src/content/note_view.tsx
@@ -11,9 +11,9 @@ import { drawMermaid, loadMermaid, readMermaidTheme } from "./mermaid.js";
import { ZoomViewer } from "./zoom_viewer.js";
/**
- * Mounts the note in place of the content the page rendered for visitors without scripts: an image
- * or a Mermaid note's diagram in a viewer that pans and zooms it, any other note with the app's own
- * widget for its type, read-only.
+ * Mounts the note in place of the content the page rendered for visitors without scripts: an
+ * image, a canvas or a Mermaid note's diagram in a viewer that pans and zooms it, any other note
+ * with the app's own widget for its type, read-only.
*/
export default function mountNoteView(container: HTMLElement, payload: AppPayload) {
container.replaceChildren();
@@ -27,9 +27,13 @@ export default function mountNoteView(container: HTMLElement, payload: AppPayloa
function SharedNoteView({ note }: { note: FNote }) {
switch (note.type) {
- case "image": return <ImageView note={note} />;
- case "mermaid": return <MermaidView note={note} />;
- default: return <NoteView note={note} />;
+ case "image":
+ case "canvas":
+ return <ImageView note={note} />;
+ case "mermaid":
+ return <MermaidView note={note} />;
+ default:
+ return <NoteView note={note} />;
}
}
@@ -58,7 +62,10 @@ function NoteView({ note }: { note: FNote }) {
);
}
-/** Shows an image note's image, which the share serves, in a viewer that takes the page. */
+/**
+ * Shows the image the share serves for an image note, or the SVG a canvas note keeps of its
+ * drawing, in a viewer that takes the page.
+ */
function ImageView({ note }: { note: FNote }) {
const src = `api/images/${note.noteId}/${encodeURIComponent(note.title)}?${note.blobId}`;
return (
diff --git a/packages/trilium-core/src/share/content_renderer.spec.ts b/packages/trilium-core/src/share/content_renderer.spec.ts
index f1ad0db7fe..d6af1218cd 100644
--- a/packages/trilium-core/src/share/content_renderer.spec.ts
+++ b/packages/trilium-core/src/share/content_renderer.spec.ts
@@ -1692,15 +1692,15 @@ describe("content_renderer pages", () => {
expect(auto.classList.contains("hljs")).toBe(false);
expect(render({ type: "code", mime: "text/x-markdown", content: " " }).isEmpty).toBe(true);
- for (const type of [ "canvas", "mindMap" ]) {
- expect(render({ id: `${type}Note`, type, title: "A picture", content: "" }).content)
- .toMatch(new RegExp(`^<img src="api/images/${type}Note/A%20picture\\?`));
+ expect(render({ id: "mindMapNote", type: "mindMap", title: "A picture", content: "" }).content)
+ .toMatch(/^<img src="api\/images\/mindMapNote\/A%20picture\?/);
+ for (const type of [ "image", "canvas" ]) {
+ const image = render({ id: `${type}Note`, type, title: "A picture", content: "" });
+ expect(image.isAppView).toBe(true);
+ expect(parse(String(image.content))
+ .querySelector(`.share-note-view[data-note-id=${type}Note] > img`)?.getAttribute("src"))
+ .toMatch(new RegExp(`^api/images/${type}Note/A%20picture\\?`));
}
- const image = render({ id: "imageNote", type: "image", title: "A picture", content: "" });
- expect(image.isAppView).toBe(true);
- expect(parse(String(image.content))
- .querySelector(".share-note-view[data-note-id=imageNote] > img")?.getAttribute("src"))
- .toMatch(/^api\/images\/imageNote\/A%20picture\?/);
const file = (id: string, mime: string) =>
render({ id, type: "file", mime, content: "" }).content;
expect(file("pdfNote", "application/pdf"))
diff --git a/packages/trilium-core/src/share/content_renderer.ts b/packages/trilium-core/src/share/content_renderer.ts
index 92da7ddf72..b5a4f623dd 100644
--- a/packages/trilium-core/src/share/content_renderer.ts
+++ b/packages/trilium-core/src/share/content_renderer.ts
@@ -491,10 +491,10 @@ export function getContent(note: SNote | BNote, options: ShareRenderOptions = {}
} else if (note.type === "mermaid") {
renderMermaid(result, note);
hostNoteView(result, note);
- } else if (note.type === "image") {
+ } else if (note.type === "image" || note.type === "canvas") {
renderImage(result, note);
hostNoteView(result, note);
- } else if (["canvas", "mindMap"].includes(note.type)) {
+ } else if (note.type === "mindMap") {
renderImage(result, note);
} else if (note.type === "file") {
renderFile(note, result);