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(client): hide full-width toggle for inherently full-width notes
Elian Doran0b21f423284a
diff --git a/apps/client/src/widgets/note_wrapper.spec.ts b/apps/client/src/widgets/note_wrapper.spec.tsindex 2d007061c3..be7a3ab3bc 100644--- a/apps/client/src/widgets/note_wrapper.spec.ts+++ b/apps/client/src/widgets/note_wrapper.spec.ts@@ -1,7 +1,25 @@import { describe, expect, it } from "vitest";import { buildNote } from "../test/easy-froca";-import { isFullWidthNote } from "./note_wrapper";+import { isAlwaysFullWidthByType, isFullWidthNote } from "./note_wrapper";++describe("isAlwaysFullWidthByType", () => {+ it("is false for a regular text note regardless of the fullContentWidth label", () => {+ expect(isAlwaysFullWidthByType(buildNote({ title: "Plain", type: "text" }))).toBe(false);+ expect(isAlwaysFullWidthByType(buildNote({ title: "Wide", type: "text", "#fullContentWidth": "" }))).toBe(false);+ });++ it("is true for layout-heavy types, media/PDF files and non-list/grid searches", () => {+ expect(isAlwaysFullWidthByType(buildNote({ title: "Canvas", type: "canvas" }))).toBe(true);++ const pdf = buildNote({ title: "PDF", type: "file" });+ pdf.mime = "application/pdf";+ expect(isAlwaysFullWidthByType(pdf)).toBe(true);++ expect(isAlwaysFullWidthByType(buildNote({ title: "Calendar", type: "search", "#viewType": "calendar" }))).toBe(true);+ expect(isAlwaysFullWidthByType(buildNote({ title: "List", type: "search", "#viewType": "list" }))).toBe(false);+ });+});describe("isFullWidthNote", () => {it("opts a regular text note into full width via the fullContentWidth label", () => {diff --git a/apps/client/src/widgets/note_wrapper.ts b/apps/client/src/widgets/note_wrapper.tsindex 8b1c12c74c..1bb7e9c43f 100644--- a/apps/client/src/widgets/note_wrapper.ts+++ b/apps/client/src/widgets/note_wrapper.ts@@ -113,11 +113,11 @@ 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.+ * Whether a note is full width purely because of its type (e.g. canvas, collections, media),+ * irrespective of the `fullContentWidth` label. For these notes the label has no effect, so the+ * UI toggle is hidden. Exported as a pure function for unit testing.*/-export function isFullWidthNote(note: FNote) {+export function isAlwaysFullWidthByType(note: FNote) {if (["code", "image", "mermaid", "book", "render", "canvas", "webView", "noteMap", "mindMap", "spreadsheet"].includes(note.type)) {return true;}@@ -130,5 +130,14 @@ export function isFullWidthNote(note: FNote) {return true;}- return !!note?.isLabelTruthy("fullContentWidth");+ return false;+}++/**+ * Whether a note should occupy the full available content width. Some note types are always+ * full width by nature (see {@link isAlwaysFullWidthByType}), while regular notes opt in via the+ * `fullContentWidth` label. Exported as a pure function for unit testing.+ */+export function isFullWidthNote(note: FNote) {+ return isAlwaysFullWidthByType(note) || !!note?.isLabelTruthy("fullContentWidth");}diff --git a/apps/client/src/widgets/ribbon/NoteActions.tsx b/apps/client/src/widgets/ribbon/NoteActions.tsxindex fe6c568017..bd0f30147a 100644--- a/apps/client/src/widgets/ribbon/NoteActions.tsx+++ b/apps/client/src/widgets/ribbon/NoteActions.tsx@@ -21,6 +21,7 @@ import ws from "../../services/ws";import ClosePaneButton from "../buttons/close_pane_button";import CreatePaneButton from "../buttons/create_pane_button";import MovePaneButton from "../buttons/move_pane_button";+import { isAlwaysFullWidthByType } from "../note_wrapper";import ActionButton from "../react/ActionButton";import Dropdown from "../react/Dropdown";import { FormDropdownDivider, FormDropdownSubmenu, FormListHeader, FormListItem, FormListToggleableItem } from "../react/FormList";@@ -276,11 +277,13 @@ 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}- />+ {!isAlwaysFullWidthByType(note) &&+ <FormListToggleableItem+ icon="bx bx-expand-horizontal"+ title={t("full_content_width_switch.title")}+ currentValue={isFullContentWidth} onChange={setIsFullContentWidth}+ />+ }</>;}