Skip to content

Build your personal knowledge base with Trilium Notes

feat(client): expose full content width toggle in note actions

Elian Doran425743ac5b19
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 0be6fc1075..d420d664d4 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1936,6 +1936,9 @@
"toggle-on-hint": "Make the note a template",
"toggle-off-hint": "Remove the note as a template"
},
+ "full_content_width_switch": {
+ "title": "Full width"
+ },
"open-help-page": "Open help page",
"find": {
"case_sensitive": "Case sensitive",
diff --git a/apps/client/src/widgets/note_wrapper.spec.ts b/apps/client/src/widgets/note_wrapper.spec.ts
new file mode 100644
index 0000000000..2d007061c3
--- /dev/null
+++ b/apps/client/src/widgets/note_wrapper.spec.ts
@@ -0,0 +1,46 @@
+import { describe, expect, it } from "vitest";
+
+import { buildNote } from "../test/easy-froca";
+import { isFullWidthNote } from "./note_wrapper";
+
+describe("isFullWidthNote", () => {
+ it("opts a regular text note into full width via the fullContentWidth label", () => {
+ expect(isFullWidthNote(buildNote({ title: "Plain", type: "text" }))).toBe(false);
+ expect(isFullWidthNote(buildNote({ title: "Wide", type: "text", "#fullContentWidth": "" }))).toBe(true);
+ // An explicit "false" value disables it again.
+ expect(isFullWidthNote(buildNote({ title: "Narrow", type: "text", "#fullContentWidth": "false" }))).toBe(false);
+ });
+
+ it("treats layout-heavy note types as full width regardless of the label", () => {
+ for (const type of ["code", "image", "mermaid", "book", "render", "canvas", "webView", "noteMap", "mindMap", "spreadsheet"] as const) {
+ expect(isFullWidthNote(buildNote({ title: type, type }))).toBe(true);
+ }
+ });
+
+ it("treats media and PDF files as full width but leaves other files constrained", () => {
+ const pdf = buildNote({ title: "PDF", type: "file" });
+ pdf.mime = "application/pdf";
+ expect(isFullWidthNote(pdf)).toBe(true);
+
+ const video = buildNote({ title: "Video", type: "file" });
+ video.mime = "video/mp4";
+ expect(isFullWidthNote(video)).toBe(true);
+
+ const audio = buildNote({ title: "Audio", type: "file" });
+ audio.mime = "audio/mpeg";
+ expect(isFullWidthNote(audio)).toBe(true);
+
+ const doc = buildNote({ title: "Doc", type: "file" });
+ doc.mime = "application/msword";
+ expect(isFullWidthNote(doc)).toBe(false);
+ });
+
+ it("only constrains list/grid search views", () => {
+ expect(isFullWidthNote(buildNote({ title: "List", type: "search", "#viewType": "list" }))).toBe(false);
+ expect(isFullWidthNote(buildNote({ title: "Grid", type: "search", "#viewType": "grid" }))).toBe(false);
+ // Default (no viewType) behaves like a list and stays constrained.
+ expect(isFullWidthNote(buildNote({ title: "Default", type: "search" }))).toBe(false);
+ // Any other view (e.g. calendar) goes full width.
+ expect(isFullWidthNote(buildNote({ title: "Calendar", type: "search", "#viewType": "calendar" }))).toBe(true);
+ });
+});
diff --git a/apps/client/src/widgets/note_wrapper.ts b/apps/client/src/widgets/note_wrapper.ts
index 19e7cff921..8b1c12c74c 100644
--- a/apps/client/src/widgets/note_wrapper.ts
+++ b/apps/client/src/widgets/note_wrapper.ts
@@ -57,7 +57,7 @@ export default class NoteWrapperWidget extends FlexContainer<BasicWidget> {
return;
}
- this.$widget.toggleClass("full-content-width", this.#isFullWidthNote(note));
+ this.$widget.toggleClass("full-content-width", isFullWidthNote(note));
this.$widget.addClass(note.getCssClass());
@@ -74,22 +74,6 @@ export default class NoteWrapperWidget extends FlexContainer<BasicWidget> {
this.$widget.toggleClass("rtl", !!locale?.rtl);
}
- #isFullWidthNote(note: FNote) {
- if (["code", "image", "mermaid", "book", "render", "canvas", "webView", "noteMap", "mindMap", "spreadsheet"].includes(note.type)) {
- return true;
- }
-
- if (note.type === "file" && (note.mime === "application/pdf" || note.mime.startsWith("video/") || note.mime.startsWith("audio/"))) {
- return true;
- }
-
- if (note.type === "search" && ![ "grid", "list" ].includes(note.getLabelValue("viewType") ?? "list")) {
- return true;
- }
-
- return !!note?.isLabelTruthy("fullContentWidth");
- }
-
#hasBackgroundEffects(note: FNote): boolean {
const MIME_TYPES_WITH_BACKGROUND_EFFECTS = [
"application/pdf"
@@ -117,7 +101,7 @@ export default class NoteWrapperWidget extends FlexContainer<BasicWidget> {
async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
// listening on changes of note.type and CSS class
- const LABELS_CAUSING_REFRESH = ["cssClass", "language", "viewType", "color"];
+ const LABELS_CAUSING_REFRESH = ["cssClass", "language", "viewType", "color", "fullContentWidth"];
const noteId = this.noteContext?.noteId;
if (
loadResults.isNoteReloaded(noteId) ||
@@ -127,3 +111,24 @@ export default class NoteWrapperWidget extends FlexContainer<BasicWidget> {
}
}
}
+
+/**
+ * Whether a note should occupy the full available content width. Some note types are always
+ * full width by nature (e.g. canvas, collections, media), while regular notes opt in via the
+ * `fullContentWidth` label. Exported as a pure function for unit testing.
+ */
+export function isFullWidthNote(note: FNote) {
+ if (["code", "image", "mermaid", "book", "render", "canvas", "webView", "noteMap", "mindMap", "spreadsheet"].includes(note.type)) {
+ return true;
+ }
+
+ if (note.type === "file" && (note.mime === "application/pdf" || note.mime.startsWith("video/") || note.mime.startsWith("audio/"))) {
+ return true;
+ }
+
+ if (note.type === "search" && ![ "grid", "list" ].includes(note.getLabelValue("viewType") ?? "list")) {
+ return true;
+ }
+
+ return !!note?.isLabelTruthy("fullContentWidth");
+}
diff --git a/apps/client/src/widgets/ribbon/NoteActions.tsx b/apps/client/src/widgets/ribbon/NoteActions.tsx
index ea1b2a0be0..fe6c568017 100644
--- a/apps/client/src/widgets/ribbon/NoteActions.tsx
+++ b/apps/client/src/widgets/ribbon/NoteActions.tsx
@@ -234,6 +234,7 @@ function NoteBasicProperties({ note, focus }: {
const [ isBookmarked, setIsBookmarked ] = useNoteBookmarkState(note);
const [ isShared, switchShareState ] = useShareState(note);
const [ isTemplate, setIsTemplate ] = useNoteLabelBoolean(note, "template");
+ const [ isFullContentWidth, setIsFullContentWidth ] = useNoteLabelBoolean(note, "fullContentWidth");
const isProtected = useNoteProperty(note, "isProtected");
useEffect(() => {
@@ -275,6 +276,11 @@ function NoteBasicProperties({ note, focus }: {
helpPage="KC1HB96bqqHX"
disabled={note?.noteId.startsWith("_options")}
/>
+ <FormListToggleableItem
+ icon="bx bx-expand-horizontal"
+ title={t("full_content_width_switch.title")}
+ currentValue={isFullContentWidth} onChange={setIsFullContentWidth}
+ />
</>;
}
diff --git a/packages/commons/src/lib/attribute_names.ts b/packages/commons/src/lib/attribute_names.ts
index b235834ee5..a0a88f27c6 100644
--- a/packages/commons/src/lib/attribute_names.ts
+++ b/packages/commons/src/lib/attribute_names.ts
@@ -72,6 +72,7 @@ type Labels = {
webViewSrc: string;
"disabled:webViewSrc": string;
readOnly: boolean;
+ fullContentWidth: boolean;
displayMode: string;
tabWidth: number;
indentWithTabs: boolean;