Skip to content

Build your personal knowledge base with Trilium Notes

client/text editor/multicolumn layout: use large figures for the column layout selection dropdown

Adorian Dorane8a8762539dc
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index c942c9e3d3..8639c72c35 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -4394,8 +4394,8 @@
"multicolumn-layout": "Multicolumn layout",
"multicolumn-layout-toolbar": "Multicolumn layout toolbar",
"column-layout": "Column layout",
- "0-columns": "%0 columns",
- "arrange-content-in-two-to-four-columns-side-by-side": "Arrange content in two to four columns side by side."
+ "arrange-content-in-two-to-four-columns-side-by-side": "Arrange content in two to four columns side by side.",
+ "0-columns-1": "%0 columns (%1)"
},
"task-state-dropped-title": "Invalid task states",
"task-state-dropped-message_one": "A custom task state definition is invalid and was ignored.",
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.html
index 98fd55dd20..5888bff2fa 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
@@ -11,9 +11,10 @@
the layout is inserted, the selection moves into the first column.</p>
<h2>Changing the columns</h2>
<p>While the cursor is inside a layout, a toolbar appears above it with a
- dropdown of the available layouts, grouped by the number of columns:</p>
-<figure
-class="table">
+ button that shows the current layout. Clicking it opens a row of figures,
+ one for each available layout; hovering over a figure shows its number
+ of columns and their widths:</p>
+<figure class="table">
<table>
<thead>
<tr>
diff --git a/docs/User Guide/User Guide/Note Types/Text/Multicolumn layout.md b/docs/User Guide/User Guide/Note Types/Text/Multicolumn layout.md
index a74e4970dd..fc9ca7f283 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
@@ -10,7 +10,7 @@ A new layout has two columns of equal width. If text is selected when the layout
## Changing the columns
-While the cursor is inside a layout, a toolbar appears above it with a dropdown of the available layouts, grouped by the number of columns:
+While the cursor is inside a layout, a toolbar appears above it with a button that shows the current layout. Clicking it opens a row of figures, one for each available layout; hovering over a figure shows its number of columns and their widths:
| Columns | Widths |
| --- | --- |
diff --git a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_layout.spec.ts b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_layout.spec.ts
index 1e8830aca0..13e8f4bc40 100644
--- a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_layout.spec.ts
+++ b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_layout.spec.ts
@@ -117,6 +117,54 @@ describe("multicolumn layout styles", () => {
expect(columns.map(cornersOf)).toEqual(["0px 8px 8px 0px", "8px 0px 0px 8px"]);
});
+ /** Shows the layout toolbar the way the editor does and opens its dropdown. */
+ async function openLayoutDropdown() {
+ const editor = await createTestEditor([Essentials, Paragraph, Multicolumn]);
+ editor.setData(layoutHtml("1-3", ["<p>A</p>", "<p>B</p>"]));
+ editor.ui.focusTracker.isFocused = true;
+ editor.ui.update();
+ const toolbar = document.querySelector("[aria-label='Multicolumn layout toolbar']");
+ const button = toolbar?.querySelector<HTMLElement>(".ck-dropdown__button");
+ button?.click();
+ return { toolbar, button };
+ }
+
+ it("separates the tiles of each column count by 20px in the open dropdown", async () => {
+ const { toolbar } = await openLayoutDropdown();
+ const tiles = [...toolbar?.querySelectorAll(".ck-list-styles-list > .ck-button") ?? []];
+ const boxes = tiles.map(tile => tile.getBoundingClientRect());
+ const gaps = boxes.slice(1).map((box, index) => box.left - boxes[index].right);
+
+ expect(gaps).toHaveLength(5);
+ expect(gaps[2]).toBeCloseTo(20, 1);
+ expect(gaps[4]).toBeCloseTo(20, 1);
+ expect(gaps[0]).toBeLessThan(20);
+ expect(gaps[1]).toBeCloseTo(gaps[0], 1);
+ expect(gaps[3]).toBeCloseTo(gaps[0], 1);
+ });
+
+ it("draws the layout figures as outlines at the size of the editor's icons", async () => {
+ const { toolbar, button } = await openLayoutDropdown();
+ const icons = [
+ button?.querySelector("svg.ck-icon"),
+ toolbar?.querySelector(".ck-list-styles-list svg.ck-icon")
+ ];
+ for (const [index, size] of [20, 44].entries()) {
+ const icon = icons[index];
+ const rect = icon?.querySelector("rect");
+ const dots = [...icon?.querySelectorAll("circle") ?? []];
+ expect(icon?.getBoundingClientRect().width).toBeCloseTo(size, 0);
+ expect(rect && getComputedStyle(rect).fill).toBe("none");
+
+ // The outline is centered on the box, so 0.75px of it lies inside, then the 1px gap.
+ const box = (rect as Element).getBoundingClientRect();
+ const first = dots[0].getBoundingClientRect();
+ const last = dots[dots.length - 1].getBoundingClientRect();
+ expect(first.top - box.top).toBeCloseTo(1.75, 1);
+ expect(box.bottom - last.bottom).toBeCloseTo(1.75, 1);
+ }
+ });
+
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);
diff --git a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_ui.spec.ts b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_ui.spec.ts
index 1537981ccc..32b7133849 100644
--- a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_ui.spec.ts
+++ b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_ui.spec.ts
@@ -6,8 +6,6 @@ import {
ContextualBalloon,
type DropdownView,
Essentials,
- type ListItemGroupView,
- type ListItemView,
type ModelElement,
Paragraph,
type ToolbarView,
@@ -15,11 +13,14 @@ import {
type ViewElement,
WidgetToolbarRepository
} from "ckeditor5";
-import { beforeEach, describe, expect, it, vi } from "vitest";
+import { beforeEach, describe, expect, it, onTestFinished, vi } from "vitest";
import { createTestEditor } from "../../../test/editor-kit.js";
+import multicolumnIcon from "../../icons/multicolumn.svg?raw";
+import type TileRowView from "../tile_row_view.js";
+import { COLUMN_RATIOS } from "./constants.js";
import Multicolumn from "./multicolumn.js";
-import { formatRatios } from "./multicolumn_ui.js";
+import { createLayoutFigure, formatRatios } from "./multicolumn_ui.js";
interface ToolbarDefinition {
view: ToolbarView;
@@ -63,58 +64,64 @@ describe("MulticolumnUI", () => {
function createDropdown() {
const dropdown = editor.ui.componentFactory.create("columnLayout") as DropdownView;
dropdown.render();
+ const element = dropdown.element as HTMLElement;
+ document.body.appendChild(element);
+ onTestFinished(() => element.remove());
dropdown.isOpen = true;
return dropdown;
}
- function groupsOf(dropdown: DropdownView) {
- const groups = [...dropdown.listView?.items ?? []] as ListItemGroupView[];
- return groups.map(group => ({
- label: group.label,
- buttons: ([...group.items] as ListItemView[])
- .map(item => item.children.first as ButtonView)
- }));
+ function tilesOf(dropdown: DropdownView) {
+ const row = dropdown.panelView.children.first as TileRowView;
+ return [...row.tiles];
}
- it("lists every layout grouped by column count and checks the current one", () => {
+ it("shows a figure of every layout, with the current one on and focused", () => {
setModelData(editor.model, layout("1-3", paragraph("A[]"), paragraph("B")));
const dropdown = createDropdown();
- const groups = groupsOf(dropdown);
-
- const labels = groups.map(group => [
- group.label,
- group.buttons.map(button => button.label)
- ]);
- expect(labels).toEqual([
- ["2 columns", ["50%-50%", "25%-75%", "75%-25%"]],
- ["3 columns", ["33%-33%-33%", "25%-50%-25%"]],
- ["4 columns", ["25%-25%-25%-25%"]]
+ const tiles = tilesOf(dropdown);
+
+ expect(tiles.map(tile => tile.label)).toEqual([
+ "2 columns (50%-50%)",
+ "2 columns (25%-75%)",
+ "2 columns (75%-25%)",
+ "3 columns (33%-33%-33%)",
+ "3 columns (25%-50%-25%)",
+ "4 columns (25%-25%-25%-25%)"
]);
- const checked = groups.flatMap(group => group.buttons).filter(button => button.isOn);
- expect(checked.map(button => button.label)).toEqual(["25%-75%"]);
- expect(dropdown.buttonView.label).toBe("25%-75%");
+ expect(tiles.every(tile => tile.tooltip)).toBe(true);
+ expect(tiles.map(tile => tile.icon))
+ .toEqual(COLUMN_RATIOS.map(ratios => createLayoutFigure(ratios, 44)));
+
+ expect(tiles.filter(tile => tile.isOn).map(tile => tile.label))
+ .toEqual(["2 columns (25%-75%)"]);
+ expect(document.activeElement).toBe(tiles[1].element);
+ expect(dropdown.buttonView.label).toBe("Column layout");
+ expect(dropdown.buttonView.icon).toBe(createLayoutFigure("1-3", 20));
expect(dropdown.isEnabled).toBe(true);
});
- it("applies the chosen layout and returns the focus to the editor", () => {
+ it("applies the chosen layout, closes and returns the focus to the editor", () => {
setModelData(editor.model, layout("1-1", paragraph("A[]"), paragraph("B")));
const dropdown = createDropdown();
const focus = vi.spyOn(editor.editing.view, "focus");
- groupsOf(dropdown)[1].buttons[1].fire("execute");
+ tilesOf(dropdown)[4].fire("execute");
expect(getModelData(editor.model, { withoutSelection: true }))
.toBe(layout("1-2-1", paragraph("A"), paragraph("B"), paragraph("")));
- expect(dropdown.buttonView.label).toBe("25%-50%-25%");
+ expect(dropdown.buttonView.icon).toBe(createLayoutFigure("1-2-1", 20));
+ expect(dropdown.isOpen).toBe(false);
expect(focus).toHaveBeenCalled();
});
- it("is disabled and blank outside a layout", () => {
+ it("is disabled outside a layout and shows the insert icon", () => {
setModelData(editor.model, "<paragraph>[]</paragraph>");
const dropdown = createDropdown();
expect(dropdown.isEnabled).toBe(false);
- expect(dropdown.buttonView.label).toBe("");
+ expect(dropdown.buttonView.icon).toBe(multicolumnIcon);
+ expect(tilesOf(dropdown).some(tile => tile.isOn)).toBe(false);
});
});
@@ -143,8 +150,8 @@ describe("MulticolumnUI", () => {
expect(editor.plugins.get(ContextualBalloon).visibleView).toBe(toolbar);
expect(toolbar.ariaLabel).toBe("Multicolumn layout toolbar");
const items = [...toolbar.items] as DropdownView[];
- expect(items.map(item => [item.buttonView.tooltip, item.buttonView.label]))
- .toEqual([["Column layout", "25%-75%"]]);
+ expect(items.map(item => [item.buttonView.label, item.buttonView.icon]))
+ .toEqual([["Column layout", createLayoutFigure("1-3", 20)]]);
});
it("belongs to the innermost layout that holds or is the selection", () => {
@@ -170,4 +177,49 @@ describe("MulticolumnUI", () => {
expect(["1-1", "3-1", "1-1-1", "1-2-1"].map(formatRatios))
.toEqual(["50%-50%", "75%-25%", "33%-33%-33%", "25%-50%-25%"]);
});
+
+ describe("layout figure", () => {
+ function draw(ratios: string, size: number) {
+ const svg = new DOMParser()
+ .parseFromString(createLayoutFigure(ratios, size), "image/svg+xml");
+ const rect = svg.querySelector("rect");
+ const number = (element: Element | null, name: string) =>
+ Number(element?.getAttribute(name));
+ const dots = [...svg.querySelectorAll("circle")]
+ .map(dot => ({ x: number(dot, "cx"), y: number(dot, "cy"), r: number(dot, "r") }));
+ return {
+ viewBox: svg.documentElement.getAttribute("viewBox"),
+ box: ["x", "y", "width", "height"].map(name => number(rect, name)),
+ columns: [...new Set(dots.map(dot => dot.x))],
+ dots: dots.filter(dot => dot.x === dots[0].x)
+ };
+ }
+
+ it("draws a dotted line between each pair of columns, 4px in from the sides", () => {
+ const figures = COLUMN_RATIOS.map(ratios => draw(ratios, 44));
+
+ expect(figures.map(figure => figure.columns)).toEqual([
+ [22], [13], [31],
+ [16, 28], [13, 31],
+ [13, 22, 31]
+ ]);
+ expect(figures[0].viewBox).toBe("0 0 44 44");
+ expect(figures[0].box).toEqual([4, 6.6, 36, 30.8]);
+ });
+
+ it("spaces the dots evenly and keeps 1px from the outline at both ends, at any size", () => {
+ for (const [size, count] of [[44, 9], [20, 4]]) {
+ const { box: [, top, , height], dots } = draw("1-1", size);
+ const outline = 1.5 / 2;
+ const first = dots[0];
+ const last = dots[dots.length - 1];
+ const steps = dots.slice(1).map((dot, index) => dot.y - dots[index].y);
+
+ expect(dots, `${size}px`).toHaveLength(count);
+ expect(first.y - first.r - (top + outline)).toBeCloseTo(1, 2);
+ expect(top + height - outline - (last.y + last.r)).toBeCloseTo(1, 2);
+ expect(Math.max(...steps) - Math.min(...steps)).toBeLessThan(.02);
+ }
+ });
+ });
});
diff --git a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_ui.ts b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_ui.ts
index 9959166858..ccbb8b891d 100644
--- a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_ui.ts
+++ b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_ui.ts
@@ -1,16 +1,14 @@
import {
- addListToDropdown,
ButtonView,
- Collection,
createDropdown,
- type ListDropdownGroupDefinition,
+ focusChildOnDropdownOpen,
type Locale,
Plugin,
- UIModel,
WidgetToolbarRepository
} from "ckeditor5";
import multicolumnIcon from "../../icons/multicolumn.svg?raw";
+import TileRowView from "../tile_row_view.js";
import { findSelectedWidget } from "../widget_utils.js";
import { COLUMN_RATIOS, getColumnCount, LAYOUT_WIDGET_PROPERTY } from "./constants.js";
import type {
@@ -60,49 +58,89 @@ export default class MulticolumnUI extends Plugin {
return button;
}
- /** A dropdown of every column layout, grouped by column count. */
+ /** A dropdown with a figure of every column layout, grouped by column count. */
private createLayoutDropdown(locale: Locale) {
const editor = this.editor;
- const t = editor.t;
+ const label = editor.t("Column layout");
const command = editor.commands.get("columnLayout") as ColumnLayoutCommand;
const dropdown = createDropdown(locale);
- dropdown.buttonView.set({ withText: true, tooltip: t("Column layout") });
- dropdown.buttonView.bind("label").to(command, "value", value =>
- value ? formatRatios(value) : "");
+ dropdown.buttonView.set({ label, tooltip: true });
+ dropdown.buttonView.bind("icon").to(command, "value", value =>
+ value ? createLayoutFigure(value, BUTTON_ICON_SIZE) : multicolumnIcon);
dropdown.bind("isEnabled").to(command, "isEnabled");
- const groups = new Map<number, ListDropdownGroupDefinition>();
+ const groups = new Map<number, ButtonView[]>();
for (const ratios of COLUMN_RATIOS) {
const count = getColumnCount(ratios);
- let group = groups.get(count);
- if (!group) {
- group = { type: "group", label: t("%0 columns", count), items: new Collection() };
- groups.set(count, group);
- }
-
- const model = new UIModel({
- label: formatRatios(ratios),
- ratios,
- role: "menuitemradio",
- withText: true
+ const tile = new ButtonView(locale);
+ tile.set({
+ label: editor.t("%0 columns (%1)", [count, formatRatios(ratios)]),
+ icon: createLayoutFigure(ratios, TILE_ICON_SIZE),
+ tooltip: true,
+ isToggleable: true
});
- model.bind("isOn").to(command, "value", value => value === ratios);
- group.items.add({ type: "button", model });
+ tile.bind("isOn").to(command, "value", value => value === ratios);
+ this.listenTo(tile, "execute", () => {
+ editor.execute("columnLayout", { value: ratios });
+ editor.editing.view.focus();
+ });
+ groups.set(count, [...groups.get(count) ?? [], tile]);
}
- addListToDropdown(dropdown, new Collection([...groups.values()]), { role: "menu" });
- this.listenTo(dropdown, "execute", evt => {
- const { ratios } = evt.source as unknown as { ratios: string };
- editor.execute("columnLayout", { value: ratios });
- editor.editing.view.focus();
- });
+ const row = new TileRowView(locale, [...groups.values()], label);
+ row.delegate("execute").to(dropdown);
+ dropdown.panelView.children.add(row);
+ focusChildOnDropdownOpen(dropdown, () => row.tiles.find(tile => tile.isOn));
return dropdown;
}
}
/** Formats column weights as rounded percentages, such as `25%-75%` for `1-3`. */
export function formatRatios(ratios: string): string {
+ return getShares(ratios).map(share => `${Math.round(share * 100)}%`).join("-");
+}
+
+/**
+ * Draws column weights as a square icon of `size` pixels: a rounded rectangle split into columns by
+ * dotted lines, with 4px of padding and corner radius at 44px. The outline, the dots and the gap
+ * between the end dots and the outline are in pixels, so each size has a drawing of its own.
+ */
+export function createLayoutFigure(ratios: string, size: number): string {
+ const outline = 1.5;
+ const dotRadius = 1;
+ const padding = size / 11;
+ const width = size - 2 * padding;
+ const top = size * .15;
+ const height = size * .7;
+ const inset = outline / 2 + 1 + dotRadius;
+ const span = height - 2 * inset;
+ const steps = Math.max(1, Math.round(span / 3));
+
+ let edge = padding;
+ const dots = getShares(ratios).slice(0, -1).flatMap(share => {
+ edge += share * width;
+ return Array.from({ length: steps + 1 }, (_, step) => {
+ const y = top + inset + span * step / steps;
+ return `<circle cx="${round(edge)}" cy="${round(y)}" r="${dotRadius}"/>`;
+ });
+ });
+
+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}">` +
+ `<rect x="${round(padding)}" y="${round(top)}" width="${round(width)}" ` +
+ `height="${round(height)}" rx="${round(padding)}" fill="none" stroke="currentColor" ` +
+ `stroke-width="${outline}"/><g fill="currentColor">${dots.join("")}</g></svg>`;
+}
+
+/** The icon sizes of a list style tile and of a toolbar button, in pixels. */
+const TILE_ICON_SIZE = 44;
+const BUTTON_ICON_SIZE = 20;
+
+function getShares(ratios: string) {
const weights = ratios.split("-").map(Number);
const total = weights.reduce((sum, weight) => sum + weight, 0);
- return weights.map(weight => `${Math.round(weight / total * 100)}%`).join("-");
+ return weights.map(weight => weight / total);
+}
+
+function round(value: number) {
+ return Math.round(value * 100) / 100;
}
diff --git a/packages/ckeditor5/src/plugins/tile_row_view.spec.ts b/packages/ckeditor5/src/plugins/tile_row_view.spec.ts
new file mode 100644
index 0000000000..94a1f365d6
--- /dev/null
+++ b/packages/ckeditor5/src/plugins/tile_row_view.spec.ts
@@ -0,0 +1,109 @@
+import { ButtonView, keyCodes, Locale } from "ckeditor5";
+import editorStylesheetUrl from "ckeditor5/ckeditor5.css?url";
+import { beforeAll, describe, expect, it, onTestFinished, vi } from "vitest";
+
+import TileRowView from "./tile_row_view.js";
+
+/** Builds a row of groups with the given lengths, each tile labeled by its position in the row. */
+function createRow(lengths: number[], locale = new Locale()) {
+ let position = 0;
+ const groups = lengths.map(length => Array.from({ length }, () => {
+ const tile = new ButtonView(locale);
+ tile.set({ label: String(position++) });
+ return tile;
+ }));
+ const row = new TileRowView(locale, groups, "Tiles");
+ row.render();
+ const element = row.element as HTMLElement;
+ document.body.appendChild(element);
+ onTestFinished(() => {
+ element.remove();
+ row.destroy();
+ });
+ return row;
+}
+
+function focusedLabel(row: TileRowView) {
+ return row.tiles.find(tile => tile.element === document.activeElement)?.label;
+}
+
+/** Focuses the tile with the label, presses the key and returns the label focused after. */
+function move(row: TileRowView, from: string, keyCode: number) {
+ row.tiles.find(tile => tile.label === from)?.focus();
+ expect(focusedLabel(row)).toBe(from);
+ const event = new KeyboardEvent("keydown", { keyCode, bubbles: true, cancelable: true });
+ document.activeElement?.dispatchEvent(event);
+ expect(event.defaultPrevented).toBe(true);
+ return focusedLabel(row);
+}
+
+describe("TileRowView", () => {
+ beforeAll(() => new Promise<void>((resolve, reject) => {
+ const link = document.createElement("link");
+ link.rel = "stylesheet";
+ link.href = editorStylesheetUrl;
+ link.onload = () => resolve();
+ link.onerror = () => reject(new Error("the editor stylesheet did not load"));
+ document.head.appendChild(link);
+ }));
+
+ it("lays out every tile as a square on one row, styled as the list style grid", () => {
+ const row = createRow([2, 3, 1]);
+ const element = row.element as HTMLElement;
+ expect(element.classList).toContain("ck-list-styles-list");
+ expect(element.getAttribute("aria-label")).toBe("Tiles");
+
+ const boxes = [...row.tiles].map(tile =>
+ (tile.element as HTMLElement).getBoundingClientRect());
+ expect(new Set(boxes.map(box => box.top)).size).toBe(1);
+ expect(boxes[0].width).toBeCloseTo(boxes[0].height, 0);
+
+ const columnGap = parseFloat(getComputedStyle(element).columnGap);
+ expect(columnGap).toBeGreaterThan(0);
+ expect(columnGap).toBeLessThan(20);
+ const groupStarts = [2, 5];
+ for (const [index, box] of boxes.entries()) {
+ if (index > 0) {
+ const expected = groupStarts.includes(index) ? 20 : columnGap;
+ expect(box.left - boxes[index - 1].right, `before ${index}`).toBeCloseTo(expected, 1);
+ }
+ }
+ });
+
+ it("focuses the tile that is on, or else the first one", () => {
+ const row = createRow([3]);
+ row.focus();
+ expect(focusedLabel(row)).toBe("0");
+
+ (row.tiles.get(2) as ButtonView).isOn = true;
+ row.focus();
+ expect(focusedLabel(row)).toBe("2");
+ });
+
+ it("moves with the left and right arrows, wrapping at the ends", () => {
+ const row = createRow([3]);
+
+ expect(move(row, "0", keyCodes.arrowright)).toBe("1");
+ expect(move(row, "2", keyCodes.arrowright)).toBe("0");
+ expect(move(row, "0", keyCodes.arrowleft)).toBe("2");
+ expect(move(row, "1", keyCodes.arrowdown)).toBe("1");
+ });
+
+ it("swaps the left and right arrows in a right-to-left interface", () => {
+ const row = createRow([3], new Locale({ uiLanguage: "ar" }));
+
+ expect(move(row, "1", keyCodes.arrowright)).toBe("0");
+ expect(move(row, "1", keyCodes.arrowleft)).toBe("2");
+ });
+
+ it("passes on the execute event of its tiles", () => {
+ const row = createRow([2]);
+ const execute = vi.fn();
+ row.on("execute", execute);
+
+ row.tiles.last?.fire("execute");
+
+ expect(execute).toHaveBeenCalledOnce();
+ expect(execute.mock.calls[0][0].source).toBe(row.tiles.last);
+ });
+});
diff --git a/packages/ckeditor5/src/plugins/tile_row_view.ts b/packages/ckeditor5/src/plugins/tile_row_view.ts
new file mode 100644
index 0000000000..2c15f01079
--- /dev/null
+++ b/packages/ckeditor5/src/plugins/tile_row_view.ts
@@ -0,0 +1,71 @@
+import {
+ addKeyboardHandlingForGrid,
+ type ButtonView,
+ FocusTracker,
+ KeystrokeHandler,
+ type Locale,
+ View,
+ type ViewCollection
+} from "ckeditor5";
+
+import "../theme/tile_row.css";
+
+/**
+ * Groups of square buttons on one row, 20px apart, styled and navigated with the arrow keys as
+ * CKEditor's list style grid.
+ */
+export default class TileRowView extends View {
+
+ public readonly tiles: ViewCollection<ButtonView>;
+ public readonly focusTracker = new FocusTracker();
+ public readonly keystrokes = new KeystrokeHandler();
+
+ constructor(locale: Locale, groups: ButtonView[][], ariaLabel: string) {
+ super(locale);
+ const tiles = groups.flat();
+ for (const [first] of groups.slice(1)) {
+ first.extendTemplate({ attributes: { class: "ck-tile-row__group-start" } });
+ }
+ this.tiles = this.createCollection(tiles);
+ this.tiles.delegate("execute").to(this);
+ addKeyboardHandlingForGrid({
+ keystrokeHandler: this.keystrokes,
+ focusTracker: this.focusTracker,
+ gridItems: this.tiles,
+ numberOfColumns: tiles.length,
+ uiLanguageDirection: locale.uiLanguageDirection
+ });
+
+ this.setTemplate({
+ tag: "div",
+ attributes: {
+ class: ["ck", "ck-list-styles-list", "ck-tile-row"],
+ style: { gridTemplateColumns: `repeat(${tiles.length}, auto)` },
+ "aria-label": ariaLabel
+ },
+ children: this.tiles
+ });
+ }
+
+ public override render(): void {
+ super.render();
+ for (const tile of this.tiles) {
+ this.focusTracker.add(tile);
+ }
+ /* v8 ignore next -- super.render() has just built this view's element */
+ if (this.element) {
+ this.keystrokes.listenTo(this.element);
+ }
+ }
+
+ /** Focuses the tile that is on, or the first one. */
+ public focus(): void {
+ (this.tiles.find(tile => tile.isOn) ?? this.tiles.first)?.focus();
+ }
+
+ public override destroy(): void {
+ super.destroy();
+ this.focusTracker.destroy();
+ this.keystrokes.destroy();
+ }
+}
diff --git a/packages/ckeditor5/src/theme/tile_row.css b/packages/ckeditor5/src/theme/tile_row.css
new file mode 100644
index 0000000000..d473586c57
--- /dev/null
+++ b/packages/ckeditor5/src/theme/tile_row.css
@@ -0,0 +1,8 @@
+.ck.ck-list-styles-list.ck-tile-row {
+ justify-content: start;
+
+ /* `--ck-spacing-medium` is the column gap of `.ck-list-styles-list`. */
+ & > .ck-button.ck-tile-row__group-start {
+ margin-inline-start: calc(20px - var(--ck-spacing-medium));
+ }
+}