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
client/text editor/multicolumn layout: tweak the appearance in read-only view
Adorian Doranf7c525575346
diff --git a/apps/client/src/print.css b/apps/client/src/print.cssindex 40db923ac8..e460113890 100644--- a/apps/client/src/print.css+++ b/apps/client/src/print.css@@ -398,13 +398,6 @@ details::details-content {}/* #endregion */-/* #region Multicolumn layout */-.ck-content .trilium-multicolumn-layout {- --multicolumn-layout-border-color: #ccc;- --multicolumn-layout-stacked-background: #f0f0f0;-}-/* #endregion */-/* #region Page breaks */.page-break {page-break-after: always;diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Multicolumn layout.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Multicolumn layout.htmlindex 7fab86b03c..a964804e9c 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Multicolumn layout.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Multicolumn layout.html@@ -1,6 +1,9 @@<p>A multicolumn layout arranges content in two to four columns, side byside. A column can hold any kind of content, including tables, images andanother multicolumn layout.</p>+<p>The borders around the columns are only a guide while editing. In <a href="#root/_help_CoFPLs3dRlXc">read-only notes</a>, <a+ href="#root/_help_R9pX4DGra2Vt">shared notes</a> and printouts, the columns+ have no borders, and their text lines up with the rest of the note.</p><h2>Inserting a layout</h2><ul><li>In the formatting bar, go to <em>Insert</em> → <span class="tn-icon cke cke-trilium-multicolumn"></span> <em>Multicolumn layout</em> to@@ -55,13 +58,13 @@<h2>Narrow screens</h2><p>When a layout has too little room for its columns (narrower than about500 pixels, such as on a phone), the columns are stacked one below the- other, with alternating background colors instead of borders. This applies- to each layout on its own, so a layout inside a narrow column is stacked- while the outer one stays side by side.</p>+ other. While editing, alternating background colors take the place of the+ borders. This applies to each layout on its own, so a layout inside a narrow+ column is stacked while the outer one stays side by side.</p><h2>Printing and exporting</h2><ul><li>When printing or <a href="#root/_help_NRnIZmSMc5sj">exporting to PDF</a>,- the columns are printed side by side.</li>+ the columns are printed side by side, without borders.</li><li>Markdown has no columns, so Markdown export writes the content of thecolumns one after another.</li></ul>\ No newline at end of filediff --git a/docs/User Guide/User Guide/Note Types/Text/Multicolumn layout.md b/docs/User Guide/User Guide/Note Types/Text/Multicolumn layout.mdindex f968103a7c..ccdd6d117b 100644--- a/docs/User Guide/User Guide/Note Types/Text/Multicolumn layout.md+++ b/docs/User Guide/User Guide/Note Types/Text/Multicolumn layout.md@@ -1,6 +1,8 @@# Multicolumn layoutA multicolumn layout arranges content in two to four columns, side by side. A column can hold any kind of content, including tables, images and another multicolumn layout.+The borders around the columns are only a guide while editing. In [read-only notes](../../Basic%20Concepts%20and%20Features/Notes/Read-Only%20Notes.md), [shared notes](../../Advanced%20Usage/Sharing.md) and printouts, the columns have no borders, and their text lines up with the rest of the note.+## Inserting a layout* In the formatting bar, go to _Insert_ → <span class="tn-icon cke cke-trilium-multicolumn"></span> _Multicolumn layout_ to insert a layout with two columns.@@ -28,9 +30,9 @@ While the cursor is inside a layout, a toolbar appears above it with a button th## Narrow screens-When a layout has too little room for its columns (narrower than about 500 pixels, such as on a phone), the columns are stacked one below the other, with alternating background colors instead of borders. This applies to each layout on its own, so a layout inside a narrow column is stacked while the outer one stays side by side.+When a layout has too little room for its columns (narrower than about 500 pixels, such as on a phone), the columns are stacked one below the other. While editing, alternating background colors take the place of the borders. This applies to each layout on its own, so a layout inside a narrow column is stacked while the outer one stays side by side.## Printing and exporting-* When printing or [exporting to PDF](../../Basic%20Concepts%20and%20Features/Notes/Printing%20%26%20Exporting%20as%20PDF.md), the columns are printed side by side.+* When printing or [exporting to PDF](../../Basic%20Concepts%20and%20Features/Notes/Printing%20%26%20Exporting%20as%20PDF.md), the columns are printed side by side, without borders.* Markdown has no columns, so Markdown export writes the content of the columns one after another.\ No newline at end of filediff --git a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_layout.spec.ts b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_layout.spec.tsindex 13e8f4bc40..6c7670268b 100644--- a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_layout.spec.ts+++ b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_layout.spec.ts@@ -6,7 +6,12 @@ import { createTestEditor } from "../../../test/editor-kit.js";import { COLUMN_RATIOS, getColumnCount } from "./constants.js";import Multicolumn from "./multicolumn.js";-const GAP = 12;+const EDITOR_GAP = 12;++/** The gap between the columns of saved content, which is 2em. */+function savedGapOf(layout: Element) {+ return 2 * parseFloat(getComputedStyle(layout).fontSize);+}function layoutHtml(ratios: string, columns: string[]) {const content = columns.map(column => `<section>${column}</section>`).join("");@@ -43,11 +48,11 @@ function cornersOf(element: Element | null | undefined) {].join(" ");}-function expectWidthsToFollow(layout: HTMLElement, ratios: string) {+function expectWidthsToFollow(layout: HTMLElement, ratios: string, gap: number) {const columns = columnsOf(layout);const weights = ratios.split("-").map(Number);const total = weights.reduce((sum, weight) => sum + weight, 0);- const available = layout.getBoundingClientRect().width - GAP * (weights.length - 1);+ const available = layout.getBoundingClientRect().width - gap * (weights.length - 1);expect(columns).toHaveLength(weights.length);for (const [index, column] of columns.entries()) {@@ -75,7 +80,8 @@ describe("multicolumn layout styles", () => {const layout = container.querySelector<HTMLElement>(".trilium-multicolumn-layout");expect(layout, ratios).not.toBeNull();- expectWidthsToFollow(layout as HTMLElement, ratios);+ const element = layout as HTMLElement;+ expectWidthsToFollow(element, ratios, savedGapOf(element));container.remove();}});@@ -92,7 +98,7 @@ describe("multicolumn layout styles", () => {editable.querySelector<HTMLElement>(".trilium-multicolumn-layout.ck-widget");expect(layout, ratios).not.toBeNull();- expectWidthsToFollow(layout as HTMLElement, ratios);+ expectWidthsToFollow(layout as HTMLElement, ratios, EDITOR_GAP);}});@@ -111,12 +117,62 @@ describe("multicolumn layout styles", () => {"0px 8px 8px 0px"]);- const container = renderContent(layoutHtml("1-1", ["<p>A</p>", "<p>B</p>"]), 800);- container.dir = "rtl";- const columns = columnsOf(container.querySelector(".trilium-multicolumn-layout"));+ const rtlEditor = await createTestEditor([Essentials, Paragraph, Multicolumn], {+ language: { content: "ar" }+ });+ const rtlEditable = rtlEditor.ui.view.editable.element as HTMLElement;+ rtlEditable.style.width = "800px";+ rtlEditor.setData(layoutHtml("1-1", ["<p>A</p>", "<p>B</p>"]));+ expect(rtlEditable.dir).toBe("rtl");+ const columns = columnsOf(rtlEditable.querySelector(".trilium-multicolumn-layout"));expect(columns.map(cornersOf)).toEqual(["0px 8px 8px 0px", "8px 0px 0px 8px"]);});+ it("borders and pads the columns only in the editor", async () => {+ const editor = await createTestEditor([Essentials, Paragraph, Multicolumn]);+ const editable = editor.ui.view.editable.element as HTMLElement;+ editable.style.width = "800px";+ editor.setData(layoutHtml("1-1", ["<p>A</p>", "<p>B</p>"]));+ const editingColumns = columnsOf(editable.querySelector(".trilium-multicolumn-layout"));++ const container = renderContent(layoutHtml("1-1", ["<p>A</p>", "<p>B</p>"]), 800);+ const savedColumns = columnsOf(container.querySelector(".trilium-multicolumn-layout"));++ expect(editingColumns).toHaveLength(2);+ expect(savedColumns).toHaveLength(2);+ for (const column of editingColumns) {+ const style = getComputedStyle(column);+ expect([style.borderTopWidth, style.paddingLeft, style.paddingRight])+ .toEqual(["1px", "16px", "16px"]);+ }+ for (const column of savedColumns) {+ const style = getComputedStyle(column);+ expect([style.borderTopWidth, style.borderLeftWidth, style.paddingLeft])+ .toEqual(["0px", "0px", "0px"]);+ expect([style.paddingRight, cornersOf(column)]).toEqual(["0px", "0px 0px 0px 0px"]);+ }+ });++ it("lines the text of saved content up with the content around it, 2em apart", () => {+ const html = "<p>Outside</p>" ++ layoutHtml("1-2-1", ["<p>A</p>", "<p>B</p>", "<p>C</p>"]);+ const container = renderContent(html, 800);+ const outside = container.querySelector("p")?.getBoundingClientRect();+ const layout = container.querySelector(".trilium-multicolumn-layout");+ const columns = columnsOf(layout);+ const texts = columns.map(column =>+ column.querySelector("p")?.getBoundingClientRect());+ const gap = layout ? savedGapOf(layout) : NaN;++ expect(outside).toBeDefined();+ expect(texts).toHaveLength(3);+ expect(gap).toBeGreaterThan(EDITOR_GAP);+ expect(texts[0]?.left).toBeCloseTo(outside?.left ?? NaN, 0);+ expect(texts[2]?.right).toBeCloseTo(outside?.right ?? NaN, 0);+ expect((texts[1]?.left ?? NaN) - (texts[0]?.right ?? NaN)).toBeCloseTo(gap, 0);+ expect((texts[2]?.left ?? NaN) - (texts[1]?.right ?? NaN)).toBeCloseTo(gap, 0);+ });+/** Shows the layout toolbar the way the editor does and opens its dropdown. */async function openLayoutDropdown() {const editor = await createTestEditor([Essentials, Paragraph, Multicolumn]);@@ -165,23 +221,38 @@ describe("multicolumn layout styles", () => {}});- it("stacks the columns with alternating backgrounds and no borders below 500px", () => {- const html = layoutHtml("1-2-1", ["<p>A</p>", "<p>B</p>", "<p>C</p>"]);- const container = renderContent(html, 480);- const layout = container.querySelector(".trilium-multicolumn-layout");+ /** Returns the columns of a layout below 500px, after checking that they are stacked. */+ function expectStacked(layout: Element | null | undefined) {const columns = columnsOf(layout);+ const width = layout?.getBoundingClientRect().width ?? NaN;const boxes = columns.map(column => column.getBoundingClientRect());+ expect(columns).toHaveLength(3);+ expect(width).toBeLessThan(500);for (const [index, box] of boxes.entries()) {- expect(box.width).toBeCloseTo(480, 0);+ expect(box.width).toBeCloseTo(width, 0);expect(getComputedStyle(columns[index]).borderTopWidth).toBe("0px");if (index > 0) {expect(box.top).toBeCloseTo(boxes[index - 1].bottom, 0);}}- const backgrounds = columns.map(column => getComputedStyle(column).backgroundColor);- expect(backgrounds[0]).toBe(backgrounds[2]);- expect(backgrounds[1]).not.toBe(backgrounds[0]);+ return columns.map(column => getComputedStyle(column).backgroundColor);+ }++ it("stacks the columns below 500px, alternating backgrounds only in the editor", async () => {+ const html = layoutHtml("1-2-1", ["<p>A</p>", "<p>B</p>", "<p>C</p>"]);+ const editor = await createTestEditor([Essentials, Paragraph, Multicolumn]);+ const editable = editor.ui.view.editable.element as HTMLElement;+ editable.style.width = "480px";+ editor.setData(html);++ const editing = expectStacked(editable.querySelector(".trilium-multicolumn-layout"));+ expect(editing[0]).toBe(editing[2]);+ expect(editing[1]).not.toBe(editing[0]);++ const container = renderContent(html, 480);+ const saved = expectStacked(container.querySelector(".trilium-multicolumn-layout"));+ expect(saved).toEqual(["rgba(0, 0, 0, 0)", "rgba(0, 0, 0, 0)", "rgba(0, 0, 0, 0)"]);});it("stacks a nested layout by its own width", () => {@@ -190,7 +261,8 @@ describe("multicolumn layout styles", () => {const outer = container.querySelector<HTMLElement>(".trilium-multicolumn-layout");const innerColumns = columnsOf(outer?.querySelector(".trilium-multicolumn-layout"));- expectWidthsToFollow(outer as HTMLElement, "1-3");+ const element = outer as HTMLElement;+ expectWidthsToFollow(element, "1-3", savedGapOf(element));expect(innerColumns[1].getBoundingClientRect().top).toBeCloseTo(innerColumns[0].getBoundingClientRect().bottom, 0);});diff --git a/packages/ckeditor5/src/theme/multicolumn.css b/packages/ckeditor5/src/theme/multicolumn.cssindex 4534b79754..3a22e3d34a 100644--- a/packages/ckeditor5/src/theme/multicolumn.css+++ b/packages/ckeditor5/src/theme/multicolumn.css@@ -11,9 +11,8 @@contain-intrinsic-inline-size: 15rem;display: grid;grid-template-columns: repeat(2, minmax(0, 1fr));- column-gap: 12px;+ column-gap: 2em;margin: 1em 0;- border-radius: var(--multicolumn-layout-border-radius);&[data-trilium-column-ratios="1-3"] {grid-template-columns: minmax(0, 1fr) minmax(0, 3fr);@@ -36,19 +35,7 @@}& > section {- border: 1px solid var(--multicolumn-layout-border-color);- border-radius: var(--multicolumn-layout-border-radius);- padding: .75rem 1rem;-- &:not(:first-of-type) {- border-start-start-radius: 0;- border-end-start-radius: 0;- }-- &:not(:last-of-type) {- border-start-end-radius: 0;- border-end-end-radius: 0;- }+ padding-block: .75rem;& > :first-child {margin-top: 0;@@ -58,11 +45,35 @@margin-bottom: 0;}}++ &.ck-widget {+ column-gap: 12px;+ border-radius: var(--multicolumn-layout-border-radius);++ & > section {+ border: 1px solid var(--multicolumn-layout-border-color);+ border-radius: var(--multicolumn-layout-border-radius);+ padding-inline: 1rem;++ &:not(:first-of-type) {+ border-start-start-radius: 0;+ border-end-start-radius: 0;+ }++ &:not(:last-of-type) {+ border-start-end-radius: 0;+ border-end-end-radius: 0;+ }+ }+ }}@container multicolumn-layout (max-width: 500px) {.ck-content .trilium-multicolumn-layout > section {grid-column: 1 / -1;+ }++ .ck-content .trilium-multicolumn-layout.ck-widget > section {border: 0;border-radius: 0;diff --git a/packages/share-theme/src/styles/content.css b/packages/share-theme/src/styles/content.cssindex 904d8fce9f..6a29b6751f 100644--- a/packages/share-theme/src/styles/content.css+++ b/packages/share-theme/src/styles/content.css@@ -191,8 +191,3 @@ body.type-webView {--card-background-color: var(--background-secondary);--main-text-color: var(--text-primary);}--.ck-content .trilium-multicolumn-layout {- --multicolumn-layout-border-color: var(--background-highlight);- --multicolumn-layout-stacked-background: var(--background-secondary);-}