Skip to content

Build your personal knowledge base with Trilium Notes

feat(share): give full-width notes the whole window, as in the app

Elian Doran4a801747bf2e
diff --git a/apps/client/src/widgets/note_wrapper.ts b/apps/client/src/widgets/note_wrapper.ts
index bc4ba650b0..7b984ec09b 100644
--- a/apps/client/src/widgets/note_wrapper.ts
+++ b/apps/client/src/widgets/note_wrapper.ts
@@ -1,3 +1,5 @@
+import { isFullWidthNoteType } from "@triliumnext/commons";
+
import type { EventData } from "../components/app_context.js";
import type NoteContext from "../components/note_context.js";
import type FNote from "../entities/fnote.js";
@@ -140,11 +142,7 @@ export function isAlwaysFullWidthByType(note: FNote) {
return true;
}
- if (["code", "image", "mermaid", "book", "render", "canvas", "webView", "noteMap", "relationMap", "mindMap", "spreadsheet"].includes(note.type)) {
- return true;
- }
-
- if (note.type === "file" && (note.mime === "application/pdf" || note.mime.startsWith("video/") || note.mime.startsWith("audio/"))) {
+ if (isFullWidthNoteType(note.type, note.mime)) {
return true;
}
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/Content width.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/Content width.html
index 787b60e497..b7597f2f8b 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/Content width.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/Content width.html
@@ -31,6 +31,9 @@
</aside>
<h2>Shared notes</h2>
<p>On a <a href="#root/_help_R9pX4DGra2Vt">shared page</a>, a text note is
- shown at a fixed reading width, whatever the width configured in Options.
- A note with <code>fullContentWidth</code> uses the whole width of the page
- there too.</p>
\ No newline at end of file
+ shown at a fixed reading width, whatever the width configured in Options,
+ and the navigation tree, the content and the table of contents are kept
+ together in a column centered on a wide screen. A note with <code>fullContentWidth</code>,
+ or of a type that is full width in the application, uses the whole width
+ of the window there, with the navigation tree and the table of contents
+ at its edges.</p>
\ No newline at end of file
diff --git a/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/Content width.md b/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/Content width.md
index 72e4fbd376..6c0cebdef4 100644
--- a/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/Content width.md
+++ b/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/Content width.md
@@ -23,4 +23,4 @@ For notes with large elements such as <a class="reference-link" href="../../Not
## Shared notes
-On a [shared page](../../Advanced%20Usage/Sharing.md), a text note is shown at a fixed reading width, whatever the width configured in Options. A note with `fullContentWidth` uses the whole width of the page there too.
\ No newline at end of file
+On a [shared page](../../Advanced%20Usage/Sharing.md), a text note is shown at a fixed reading width, whatever the width configured in Options, and the navigation tree, the content and the table of contents are kept together in a column centered on a wide screen. A note with `fullContentWidth`, or of a type that is full width in the application, uses the whole width of the window there, with the navigation tree and the table of contents at its edges.
\ No newline at end of file
diff --git a/packages/commons/src/lib/notes.spec.ts b/packages/commons/src/lib/notes.spec.ts
index 7e2bfb50b9..5b9805517e 100644
--- a/packages/commons/src/lib/notes.spec.ts
+++ b/packages/commons/src/lib/notes.spec.ts
@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
import {
CANVAS_ATTACHMENT_MIME, GEO_LOCATION_ATTRIBUTE, GEO_SHAPE_ATTRIBUTE, getImageAttachmentTitle,
- getMimeIcon, getNoteIcon, MAP_POSITION_ATTRIBUTE, MAP_SHAPE_ATTRIBUTE,
+ getMimeIcon, getNoteIcon, isFullWidthNoteType, MAP_POSITION_ATTRIBUTE, MAP_SHAPE_ATTRIBUTE,
NOTE_TYPE_ICONS, NOTE_TYPE_IMAGE_ATTACHMENTS, parseMindMapNoteLink
} from "./notes.js";
import { NoteType } from "./rows.js";
@@ -274,3 +274,18 @@ describe("getMimeIcon", () => {
expect(getMimeIcon("toString")).toBe("bx bx-file");
});
});
+
+describe("isFullWidthNoteType", () => {
+ it("takes the full width for canvas-like types and for PDF, video and audio files", () => {
+ for (const type of [ "code", "image", "mermaid", "book", "canvas", "webView", "mindMap", "spreadsheet" ]) {
+ expect(isFullWidthNoteType(type, "")).toBe(true);
+ }
+ expect(isFullWidthNoteType("file", "application/pdf")).toBe(true);
+ expect(isFullWidthNoteType("file", "video/mp4")).toBe(true);
+ expect(isFullWidthNoteType("file", "audio/ogg")).toBe(true);
+
+ expect(isFullWidthNoteType("text", "text/html")).toBe(false);
+ expect(isFullWidthNoteType("file", "application/zip")).toBe(false);
+ expect(isFullWidthNoteType("search", "")).toBe(false);
+ });
+});
diff --git a/packages/commons/src/lib/notes.ts b/packages/commons/src/lib/notes.ts
index 1fa17fbfd9..4a70963151 100644
--- a/packages/commons/src/lib/notes.ts
+++ b/packages/commons/src/lib/notes.ts
@@ -214,6 +214,24 @@ export function getCodeLanguageIcon(language: Pick<MimeTypeDefinition, "icon"> |
return language?.icon ?? NOTE_TYPE_ICONS.code;
}
+/**
+ * Whether a note of `type` and `mime` always takes the full width of the content, whatever its
+ * `#fullContentWidth` label says: canvas-like types, and files shown in a viewer (PDF, video, audio).
+ */
+export function isFullWidthNoteType(type: string, mime: string) {
+ if (FULL_WIDTH_NOTE_TYPES.includes(type)) {
+ return true;
+ }
+
+ return type === "file"
+ && (mime === "application/pdf" || mime.startsWith("video/") || mime.startsWith("audio/"));
+}
+
+const FULL_WIDTH_NOTE_TYPES = [
+ "code", "image", "mermaid", "book", "render", "canvas", "webView", "noteMap", "relationMap",
+ "mindMap", "spreadsheet"
+];
+
function getFileMimeIcon(mime: string): string {
if (mime.startsWith("video/")) return "bx bx-video";
if (mime.startsWith("audio/")) return "bx bx-music";
diff --git a/packages/share-theme/src/model/page.spec.ts b/packages/share-theme/src/model/page.spec.ts
index eeedf25705..0771856aeb 100644
--- a/packages/share-theme/src/model/page.spec.ts
+++ b/packages/share-theme/src/model/page.spec.ts
@@ -392,8 +392,7 @@ describe("getContentClasses", () => {
it("styles text and Markdown notes as the editor's content, and marks empty content", () => {
expect(classes("text", "text/html")).toBe("type-text ck-content");
expect(classes("code", "text/x-markdown")).toBe("type-code ck-content");
- expect(classes("code", "application/javascript")).toBe("type-code");
- expect(classes("book", "", true)).toBe("type-book no-content");
+ expect(classes("text", "text/html", true)).toBe("type-text ck-content no-content");
});
it("marks content as full width with #fullContentWidth, as the app does", () => {
@@ -402,6 +401,16 @@ describe("getContentClasses", () => {
expect(classes("text", "text/html", false, { fullContentWidth: "false" }))
.toBe("type-text ck-content");
});
+
+ it("marks the types the app always shows at full width, but not a Markdown note", () => {
+ expect(classes("canvas", "application/json")).toBe("type-canvas full-content-width");
+ expect(classes("file", "application/pdf")).toBe("type-file full-content-width");
+ expect(classes("code", "application/javascript")).toBe("type-code full-content-width");
+ expect(classes("code", "text/x-markdown")).toBe("type-code ck-content");
+ expect(classes("file", "application/zip")).toBe("type-file");
+ expect(classes("file", "application/zip", false, { fullContentWidth: "" }))
+ .toBe("type-file full-content-width");
+ });
});
describe("getChildLinks", () => {
diff --git a/packages/share-theme/src/model/page.ts b/packages/share-theme/src/model/page.ts
index 8239c6e0d2..aed4316a18 100644
--- a/packages/share-theme/src/model/page.ts
+++ b/packages/share-theme/src/model/page.ts
@@ -6,6 +6,7 @@
import {
isRightToLeftLanguage, resolveContentLanguage, toLanguageTag
} from "@triliumnext/commons/src/lib/i18n.js";
+import { isFullWidthNoteType } from "@triliumnext/commons/src/lib/notes.js";
/** The parts of a note the page model reads; core's `SNote` and `BNote` both provide them. */
export interface ShareNote {
@@ -331,15 +332,18 @@ export function getShareLink(note: ShareNote, sanitizeUrl: (url: string) => stri
/**
* Returns the classes of the content element: the note's type, `ck-content` for content the text
* editor's styles apply to (text notes and Markdown code notes), `full-content-width` for a note
- * with `#fullContentWidth`, as in the app, and `no-content` when empty.
+ * with `#fullContentWidth` or of a type the app always shows at full width, and `no-content` when
+ * empty. A Markdown note reads as text, so its type does not make it full width.
*/
export function getContentClasses(note: ShareNote, isEmpty = false) {
const isEditorContent = note.type === "text"
|| (note.type === "code" && note.mime === "text/x-markdown");
+ const isFullWidth = (!isEditorContent && isFullWidthNoteType(note.type, note.mime))
+ || note.isLabelTruthy("fullContentWidth");
return [
`type-${note.type}`,
isEditorContent && "ck-content",
- note.isLabelTruthy("fullContentWidth") && "full-content-width",
+ isFullWidth && "full-content-width",
isEmpty && "no-content"
].filter(Boolean).join(" ");
}
diff --git a/packages/share-theme/src/page/layout.css b/packages/share-theme/src/page/layout.css
index 6bf6ff20a6..636ac44c41 100644
--- a/packages/share-theme/src/page/layout.css
+++ b/packages/share-theme/src/page/layout.css
@@ -5,6 +5,10 @@
margin-inline: auto;
}
+#split-pane:has(#content.full-content-width) {
+ max-width: none;
+}
+
#left-pane {
display: flex;
flex-direction: column;