Skip to content

Build your personal knowledge base with Trilium Notes

client/text editor/content embed: add alignment support

Adorian Dorane86098444f4f
diff --git a/apps/client/src/menus/link_context_menu.spec.ts b/apps/client/src/menus/link_context_menu.spec.ts
index 63ca83aac6..7dd2d9e2ae 100644
--- a/apps/client/src/menus/link_context_menu.spec.ts
+++ b/apps/client/src/menus/link_context_menu.spec.ts
@@ -636,6 +636,37 @@ describe("openContextMenu", () => {
]);
});
+ it("offers the positions after the size, for content that has them", async () => {
+ state = { ...state, position: "wrap-left" };
+ const items = await openOn(editable.querySelector("a"));
+ const option = (key: string, icon: string, checked = false) => ({
+ title: `link_context_menu.${key}`, uiIcon: `cke cke-object-${icon}`, checked
+ });
+
+ expect(items.slice(7, 9)).toMatchObject([
+ { title: "link_context_menu.include_size" },
+ {
+ title: "link_context_menu.include_position",
+ uiIcon: "cke cke-object-inline-left",
+ enabled: true,
+ items: [
+ { kind: "header", title: "link_context_menu.break_text" },
+ option("align_left", "left"),
+ option("align_center", "center"),
+ option("align_right", "right"),
+ { kind: "header", title: "link_context_menu.wrap_text" },
+ option("align_left", "inline-left", true),
+ option("align_right", "inline-right")
+ ]
+ }
+ ]);
+ expect(items).toHaveLength(14);
+ expect(pick(items[8].items[2]))
+ .toEqual([ [ "contentEmbedPosition", { value: "center" } ] ]);
+ expect(pick(items[8].items[6]))
+ .toEqual([ [ "contentEmbedPosition", { value: "wrap-right" } ] ]);
+ });
+
it("offers the items of its content after Editable, in a group of their own", async () => {
state = { ...state, isEditable: true, isEditableToggleable: true };
const content = embed().querySelector<HTMLElement>(".include-note-content");
diff --git a/apps/client/src/menus/link_context_menu.ts b/apps/client/src/menus/link_context_menu.ts
index 8a61b2f535..5102c65430 100644
--- a/apps/client/src/menus/link_context_menu.ts
+++ b/apps/client/src/menus/link_context_menu.ts
@@ -1,4 +1,4 @@
-import type { CKTextEditor, ContentEmbedState } from "@triliumnext/ckeditor5";
+import type { CKTextEditor, ContentEmbedState, PositionValue } from "@triliumnext/ckeditor5";
import type { GeoMouseEvent } from "../widgets/collections/geomap/map.js";
@@ -34,6 +34,40 @@ interface MenuEmbed {
const CHECK_ICON = "bx bx-check";
+/** The positions of an embed under one heading of its menu. */
+interface PositionGroup {
+ titleKey: string;
+ positions: { value: PositionValue; titleKey: string }[];
+}
+
+/** The positions of an embed, under how the text runs around it, as its toolbar lists them. */
+const POSITION_GROUPS: PositionGroup[] = [
+ {
+ titleKey: "link_context_menu.break_text",
+ positions: [
+ { value: "left", titleKey: "link_context_menu.align_left" },
+ { value: "center", titleKey: "link_context_menu.align_center" },
+ { value: "right", titleKey: "link_context_menu.align_right" }
+ ]
+ },
+ {
+ titleKey: "link_context_menu.wrap_text",
+ positions: [
+ { value: "wrap-left", titleKey: "link_context_menu.align_left" },
+ { value: "wrap-right", titleKey: "link_context_menu.align_right" }
+ ]
+ }
+];
+
+/** The icons of the positions, from the editor's icon font. */
+const POSITION_ICONS: Record<PositionValue, string> = {
+ left: "cke cke-object-left",
+ center: "cke cke-object-center",
+ right: "cke cke-object-right",
+ "wrap-left": "cke cke-object-inline-left",
+ "wrap-right": "cke cke-object-inline-right"
+};
+
let lastMenuRequest = 0;
async function openContextMenu(
@@ -315,6 +349,7 @@ function getEmbedItems(embed: MenuEmbed): MenuItem<CommandNames>[] {
title: t("link_context_menu.include_size"),
uiIcon: "bx bx-expand-vertical"
}, sizeItems),
+ ...getPositionItems(embed),
{
title: t("link_context_menu.show_title"),
uiIcon: "bx bx-window-alt",
@@ -334,6 +369,31 @@ function getEmbedItems(embed: MenuEmbed): MenuItem<CommandNames>[] {
];
}
+/**
+ * The submenu that sets where the embed is placed in the text, with the icon of its position, for
+ * content that has positions.
+ */
+function getPositionItems(embed: MenuEmbed): MenuItem<CommandNames>[] {
+ const position = embed.state.position;
+ if (!position) {
+ return [];
+ }
+
+ const items = POSITION_GROUPS.flatMap((group): MenuItem<CommandNames>[] => [
+ { kind: "header", title: t(group.titleKey) },
+ ...group.positions.map(({ value, titleKey }): MenuItem<CommandNames> => ({
+ title: t(titleKey),
+ uiIcon: POSITION_ICONS[value],
+ checked: value === position,
+ handler: () => runEmbedCommand(embed, "contentEmbedPosition", { value })
+ }))
+ ]);
+ return [ submenuItem({
+ title: t("link_context_menu.include_position"),
+ uiIcon: POSITION_ICONS[position]
+ }, items) ];
+}
+
/** Runs `command` on the embed, which the commands act on once it is selected. */
function runEmbedCommand(
{ editor, element }: MenuEmbed,
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.css
index a8d104fa9c..c6c7909dbc 100644
--- a/apps/client/src/stylesheets/style.css
+++ b/apps/client/src/stylesheets/style.css
@@ -1333,11 +1333,11 @@ body.mobile .modal-content-with-sidebar > .modal-main > .modal-header > .modal-t
}
/* Includes in a series share flush edges, as link previews and collapsible blocks do. */
-.include-note + .include-note {
+.include-note:not([data-position^="wrap-"]) + .include-note:not([data-position^="wrap-"]) {
--_include-note-top-border-radius: 0px;
}
-.include-note:has(+ .include-note) {
+.include-note:not([data-position^="wrap-"]):has(+ .include-note:not([data-position^="wrap-"])) {
--_include-note-bottom-border-radius: 0px;
margin-bottom: 3px;
}
@@ -1499,6 +1499,53 @@ body.mobile .modal-content-with-sidebar > .modal-main > .modal-header > .modal-t
}
}
+.include-note {
+ clear: both;
+
+ &[data-position="left"] {
+ margin-right: auto;
+ margin-left: 0;
+ }
+
+ &[data-position="right"] {
+ margin-right: 0;
+ margin-left: auto;
+ }
+
+ &:is([data-position="wrap-left"], [data-position="wrap-right"]) {
+ /* No gap at full width, so that the margin box fits in the column. */
+ --_include-note-wrap-gap: clamp(0px, 100% - var(--include-note-width, 100%),
+ var(--ck-content-image-style-spacing, 1.5em));
+
+ clear: none;
+ max-width: 100%;
+ width: var(--include-note-width, 100%);
+ }
+
+ &[data-position="wrap-left"] {
+ float: left;
+ margin-right: var(--_include-note-wrap-gap);
+ }
+
+ &[data-position="wrap-right"] {
+ float: right;
+ margin-left: var(--_include-note-wrap-gap);
+ }
+}
+
+body.mobile .include-note[data-position] {
+ float: none;
+ clear: both;
+ margin-inline: 0;
+ width: auto;
+
+ > .ck-widget__resize-handles > :is(
+ .ck-widget__resize-handle_width, .ck-widget__resize-handle_corner
+ ) {
+ display: none;
+ }
+}
+
.include-note-content:not(:fullscreen) :is(
.rendered-content > img, .rendered-content > svg, .image-viewer-content > img,
.video-preview-wrapper:not(:fullscreen) > .video-preview
diff --git a/apps/client/src/translations/en-GB/translation.json b/apps/client/src/translations/en-GB/translation.json
index 3d96587e68..8b03e6a150 100644
--- a/apps/client/src/translations/en-GB/translation.json
+++ b/apps/client/src/translations/en-GB/translation.json
@@ -259,5 +259,8 @@
"text-color": "Text colour",
"background-color": "Background colour"
}
+ },
+ "link_context_menu": {
+ "align_center": "Align centre"
}
}
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index d126d6b2da..22c3db37d3 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3174,7 +3174,13 @@
"line_numbers_auto": "Auto",
"line_numbers_on": "On",
"line_numbers_off": "Off",
- "line_numbers_auto_description": "Follow the global setting"
+ "line_numbers_auto_description": "Follow the global setting",
+ "include_position": "Position",
+ "break_text": "Break text",
+ "wrap_text": "Wrap text",
+ "align_left": "Align left",
+ "align_center": "Align center",
+ "align_right": "Align right"
},
"electron_integration": {
"desktop-application": "Desktop Application",
@@ -4728,7 +4734,8 @@
"open-attachment": "Open attachment",
"jump-to-heading": "Jump to heading",
"jump-to-anchor": "Jump to anchor",
- "jump-to-block": "Jump to block"
+ "jump-to-block": "Jump to block",
+ "box-position": "Box position"
},
"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/client/src/widgets/type_widgets/canvas/CanvasEmbedTools.spec.tsx b/apps/client/src/widgets/type_widgets/canvas/CanvasEmbedTools.spec.tsx
index e367eb9a2c..f50e1c0553 100644
--- a/apps/client/src/widgets/type_widgets/canvas/CanvasEmbedTools.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/canvas/CanvasEmbedTools.spec.tsx
@@ -88,9 +88,10 @@ describe("CanvasEmbedTools", () => {
expect(getContentEmbedTools(document.createElement("figure"))).toBeNull();
expect(provider.hiddenToolbarItems).toEqual([
- "contentEmbedBoxSizeDropdown", "toggleContentEmbedTitle", "convertEmbedToLink"
+ "contentEmbedBoxSizeDropdown", "contentEmbedPositionDropdown",
+ "toggleContentEmbedTitle", "convertEmbedToLink"
]);
- expect(provider.hasEditableFlag).toBe(true);
+ expect([ provider.hasEditableFlag, provider.hasPositions ]).toEqual([ true, true ]);
const tools = provider.getTools();
const count = MAIN_TOOL_IDS.length;
expect(tools[0]).toEqual({
diff --git a/apps/client/src/widgets/type_widgets/canvas/CanvasEmbedTools.tsx b/apps/client/src/widgets/type_widgets/canvas/CanvasEmbedTools.tsx
index 2056782397..fcec644916 100644
--- a/apps/client/src/widgets/type_widgets/canvas/CanvasEmbedTools.tsx
+++ b/apps/client/src/widgets/type_widgets/canvas/CanvasEmbedTools.tsx
@@ -183,9 +183,11 @@ export function useExcalidrawTranslation() {
*/
export class CanvasTools implements ContentEmbedToolProvider {
readonly hiddenToolbarItems: readonly ContentEmbedToolbarItem[] = [
- "contentEmbedBoxSizeDropdown", "toggleContentEmbedTitle", "convertEmbedToLink"
+ "contentEmbedBoxSizeDropdown", "contentEmbedPositionDropdown", "toggleContentEmbedTitle",
+ "convertEmbedToLink"
];
readonly hasEditableFlag = true;
+ readonly hasPositions = true;
private api: ExcalidrawImperativeAPI | null = null;
private translate: Translate | null = null;
/** Whether the drawing can be edited, which adds the drawing tools and the history. */
diff --git a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.spec.tsx b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.spec.tsx
index 762d02202e..444502eb21 100644
--- a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.spec.tsx
@@ -509,6 +509,7 @@ describe("ReadOnlyText embeds of an unknown kind", () => {
describe("ReadOnlyText Mermaid diagrams", () => {
const html = `<pre data-box-size="small" data-display-mode="source" data-hide-title="true"`
+ ` data-trilium-block-id="b1" data-code-wrap-lines="true" data-code-line-numbers="false"`
+ + ` data-position="wrap-right"`
+ ` style="--include-note-height:12em;">`
+ `<code class="language-mermaid">graph TD;</code></pre>`
+ `<pre><code class="language-mermaid" data-trilium-display-mode="split"`
@@ -560,7 +561,8 @@ describe("ReadOnlyText Mermaid diagrams", () => {
options: { isFocused: false }, isInPage: true,
data: {
boxSize: "small", displayMode: "source", hideTitle: "true", language: "mermaid",
- triliumBlockId: "b1", codeWrapLines: "true", codeLineNumbers: "false"
+ triliumBlockId: "b1", codeWrapLines: "true", codeLineNumbers: "false",
+ position: "wrap-right"
},
height: "12em"
},
diff --git a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx
index c8a595f0b9..05461f84c7 100644
--- a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx
+++ b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx
@@ -285,7 +285,8 @@ function applySourceEmbeds(container: HTMLDivElement) {
const figure = document.createElement("figure");
figure.className = clsx("include-note", isCodeBlock && EXTENDED_CODE_BLOCK_CLASS);
const {
- boxSize, displayMode, codeWrapLines, codeLineNumbers, codeTabWidth, codeIndentWithTabs
+ boxSize, displayMode, position, codeWrapLines, codeLineNumbers, codeTabWidth,
+ codeIndentWithTabs
} = pre.dataset;
const defaultBoxSize = isCodeBlock ? "full" : "medium";
figure.dataset.boxSize = boxSize === "small" || boxSize === "medium" || boxSize === "full"
@@ -293,7 +294,7 @@ function applySourceEmbeds(container: HTMLDivElement) {
: defaultBoxSize;
figure.dataset.language = language;
const views = {
- displayMode, codeWrapLines, codeLineNumbers, codeTabWidth, codeIndentWithTabs
+ displayMode, position, codeWrapLines, codeLineNumbers, codeTabWidth, codeIndentWithTabs
};
for (const [ name, value ] of Object.entries(views)) {
if (value) {
diff --git a/apps/client/src/widgets/type_widgets/text/content_embed_tools.ts b/apps/client/src/widgets/type_widgets/text/content_embed_tools.ts
index 1bfddfee4c..c73c5f9d8d 100644
--- a/apps/client/src/widgets/type_widgets/text/content_embed_tools.ts
+++ b/apps/client/src/widgets/type_widgets/text/content_embed_tools.ts
@@ -40,8 +40,8 @@ export interface ContentEmbedTool {
/** An item of the embed toolbar that the content of an embed can hide. */
export type ContentEmbedToolbarItem =
- "contentEmbedBoxSizeDropdown" | "toggleContentEmbedTitle" | "convertEmbedToLink"
- | "toggleContentEmbedEditable";
+ "contentEmbedBoxSizeDropdown" | "contentEmbedPositionDropdown" | "toggleContentEmbedTitle"
+ | "convertEmbedToLink" | "toggleContentEmbedEditable";
/** The buttons that the content of an embed, such as a canvas drawing, adds to its toolbar. */
export interface ContentEmbedToolProvider {
@@ -70,6 +70,11 @@ export interface ContentEmbedToolProvider {
* of the embed then switch. The embed carries the mode as `data-display-mode`.
*/
hasDisplayModes?: boolean;
+ /**
+ * Whether the content can be positioned in the text, which the toolbar and the menu of the
+ * embed then set. The embed saves a position other than centered as `data-position`.
+ */
+ hasPositions?: boolean;
}
/**
diff --git a/apps/server/src/assets/help/help_content.json b/apps/server/src/assets/help/help_content.json
index 81b7f6da6d..69450ba45d 100644
--- a/apps/server/src/assets/help/help_content.json
+++ b/apps/server/src/assets/help/help_content.json
@@ -134,7 +134,7 @@
"_help_0Ofbk1aSuVRu": "<figure class=\"image image-style-align-right image_resized\" style=\"width:50.47%;\"><img style=\"aspect-ratio:880/553;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Images/Image%20references_image.png\" width=\"880\" height=\"553\"></figure><p>Image references are an easy way to embed the preview of another note type into a&nbsp;<a class=\"reference-link\" href=\"#root/_help_iPIMuisry3hd\">Text</a>&nbsp;note.</p><h2>Supported note types</h2><ul><li><a class=\"reference-link\" href=\"#root/_help_grjYqerjn243\">Canvas</a></li><li><a class=\"reference-link\" href=\"#root/_help_s1aBHPd79XYj\">Mermaid Diagrams</a></li><li><a class=\"reference-link\" href=\"#root/_help_gBbsAeiuUxI5\">Mind Map</a></li></ul><h2>Steps</h2><ol><li>Go to one of the supported notes (listed above) and look for the&nbsp;<span class=\"tn-icon bx bx-copy\"></span> button in the&nbsp;<a class=\"reference-link\" href=\"#root/_help_1P8QXI5edXNd\">Note buttons</a>&nbsp;area.</li><li>Go to a&nbsp;<a class=\"reference-link\" href=\"#root/_help_iPIMuisry3hd\">Text</a>&nbsp;note and use the Paste function to insert the reference to that note.</li></ol><h2>Interaction</h2><ul><li>Double-clicking an image reference from a text note will automatically open the target note.</li><li>Clicking an image reference while <kbd>Ctrl</kbd> is pressed will open the target note in a new tab.</li><li>Modifying the target note should also update the image reference. If that doesn't happen, consider&nbsp;<a class=\"reference-link\" href=\"#root/_help_s8alTXmpFR61\">Refreshing the application</a>.</li></ul>",
"_help_VRoP0g1uHHc2": "<figure class=\"image image-style-align-center image_resized\" style=\"width:76.29%;\"><img style=\"aspect-ratio:1479/865;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/In-editor%20AI%20assistant_image.png\" width=\"1479\" height=\"865\"></figure><p>The AI assistant works on the text you are already writing: select a passage and have it rewritten, translated or turned into a table, or ask for new content at the cursor. Unlike the <a href=\"#root/_help_LrKznOtw9cQD\">AI chat</a>, it does not open a conversation window, the result is previewed in place and only enters the note when you accept it.</p><h2>Requirements</h2><p>The assistant is only available once at least one provider is configured in&nbsp;<a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a>&nbsp;→ <em>AI / LLM</em>, with at least one model selected for it. Until then the toolbar entry is not shown at all.</p><h2>Accessing the AI assistant</h2><p>To access the AI assistant:</p><ul><li>Look for the&nbsp;<span class=\"tn-icon cke cke-trilium-ai\"></span> button in the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>. Press the button itself to enter the <em>Ask AI</em> mode or press the arrow key next to it to access the quick commands and the model selection. On a phone, the button has no arrow: tapping it opens the same menu at the bottom of the screen, with <em>Ask AI…</em> at its top, and a group such as <em>Translate</em> opens as a page of its own.</li><li>Look for <em>AI assistant</em> or any of the <em>AI</em>-prefixed quick commands in&nbsp;<a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>.</li><li>Press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>K</kbd>.</li><li>Select a text and choose the <em>AI assistant</em> option in the&nbsp;<a class=\"reference-link\" href=\"#root/_help_jcQVxzYybYgz\">Note contextual menu</a>.</li></ul><h2>What the assistant works on</h2><figure class=\"table\"><table><thead><tr><th>Situation</th><th>What is sent</th></tr></thead><tbody><tr><td>Text is selected</td><td>The selection.</td></tr><tr><td>Nothing is selected, and you pick a quick action</td><td>The paragraph the cursor is in.</td></tr><tr><td>Nothing is selected, and you type your own prompt</td><td>Nothing, the response is new content written at the cursor.</td></tr></tbody></table></figure><p>In all cases the assistant also sends the text before and after the target, so that the model can tell what it is writing into: asked to <em>Continue writing</em> or to summarize, a model that can only see the selected words is guessing at the document around them. This surrounding text is context only, it is never rewritten.</p><aside class=\"admonition important\"><p>That means a single run sends more than the passage you highlighted. See&nbsp;<a class=\"reference-link\" href=\"#root/_help_cRRrdZjgyhNc\">Privacy</a>&nbsp;for exactly what leaves your machine.</p></aside><h2>Quick actions</h2><p>The arrow beside the toolbar button opens a menu of ready-made instructions, grouped by what they do.</p><ul><li>The <em>Reformat</em> actions produce real Trilium content rather than plain text: <em>Diagram</em> inserts a Mermaid diagram, <em>Callout</em> an admonition, and <em>Collapsible</em> a collapsible block.</li><li>The <em>Translate</em> group lists the <a href=\"#root/_help_veGu4faJErEM\">content languages</a> you have enabled, or a predefined list if no content languages are set. It can be filled from within the editor, the last entry of the submenu opens the language configuration directly.</li></ul><p>Actions that need something to work on are greyed out when there is nothing to work on (for example an empty paragraph with no selection).</p><h2>Asking for something specific</h2><p>Choosing <em>Ask AI…</em> (<span class=\"tn-icon bx bx-message-square-dots\"></span>) opens a prompt where you can describe the change in your own words, for example: \"make this less formal\", \"add a row for 2024\", \"write an intro paragraph for this section\". Press <kbd>Enter</kbd> or the <span class=\"tn-icon cke cke-arrow-up\"></span> send button to run it.</p><p>Once a response arrives you can keep going in the same prompt, and the assistant treats it as a conversation rather than as a fresh request: after <em>Translate this to German</em>, asking for <em>make it shorter</em> shortens the German, not the original.</p><h2>Reviewing the result</h2><p>The response streams in as it is generated, and can be interrupted at any point by pressing the <em>Stop</em> (<span class=\"tn-icon cke cke-stop\"></span>) button; whatever arrived before that stays usable.</p><p>Nothing is written into the note until you say so. The review offers:</p><ul><li><em>Result</em>, which displays the response as it will be inserted.</li><li><em>Changes</em>, which displays an inline diff against the original, with insertions and deletions marked. When the model rewrote the passage rather than editing it, the review opens on <em>Result</em> instead: a diff of two texts with little in common is harder to read than the answer itself.</li><li><em>Try again</em> (<span class=\"tn-icon cke cke-refresh\"></span>), to re-run the same instruction.</li><li><em>Replace</em>, which substitutes the original passage</li><li><em>Insert below</em>, which keeps the original and adds the response after it.</li></ul><p>Trilium also reports the model that produced it, the tokens consumed and, for providers that report it, the price.</p><p>If you ask for a correction and there is nothing to correct, the assistant will indicate it instead of showing a blank diff.</p><h2>Choosing the model</h2><p>The bottom of the quick actions menu shows which model the assistant runs on, and lets you pick another from the models you selected in&nbsp;<a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a>&nbsp;→ <em>AI / LLM</em>, grouped by provider.</p><p>The model can also be changed while asking for something specific, or after the assistant has generated its response (i.e. if the response needs a better model).</p><p>This choice is separate from the model used by the chat, and is remembered across notes and devices. Left unset, the assistant follows the first configured provider.</p>",
"_help_mVEYwt20exhO": "<p><em>Quick actions</em> are a feature of the&nbsp;<a class=\"reference-link\" href=\"#root/_help_VRoP0g1uHHc2\">In-editor AI assistant</a>&nbsp;for&nbsp;<a class=\"reference-link\" href=\"#root/_help_iPIMuisry3hd\">Text</a>&nbsp;notes which automatically triggers an LLM suggestion based on a defined prompt. The built-in quick actions come with a predefined prompt, but it is also possible to define your own quick actions.</p><h2>Creating a custom quick action</h2><p>In the&nbsp;<a class=\"reference-link\" href=\"#root/_help_oPVyFC7WL2Lp\">Note Tree</a>: </p><ol><li>Right-click the note where you want to place the quick action.</li><li>Select <em>Insert child note</em>.</li><li>Select <em>More</em> → <em>AI Quick Action</em>. The entry appears only when AI is enabled.</li></ol><p>Afterwards, simply type in the content of the note the desired prompt. The text can be formatted in the same manner as a normal text note and it will be passed to the LLM as Markdown.</p><p>The title of the note will become the title of the quick action.</p><p>Of note:</p><ul><li><a class=\"reference-link\" href=\"#root/_help_6f9hih2hXXZk\">Code</a>&nbsp;notes work too.</li><li>An empty note is ignored.</li><li><a class=\"reference-link\" href=\"#root/_help_MKmLg5x6xkor\">Archived Notes</a>&nbsp;are also excluded.</li></ul><h2>Using a quick action</h2><p>Once a quick action is defined, the action will appear under the <em>Quick Actions</em> dropdown in a group called <em>Custom</em>.</p>",
- "_help_nBAXQFj20hS1": "<p>Text notes can \"include\" another note as a read-only widget or an interactive widget, depending on the type of note.</p><p>This can be useful for e.g. including a dynamically generated chart (from scripts &amp; \"render HTML\" note) or other more advanced use cases.</p><h2>Including a note</h2><p>In the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>, look for the&nbsp;<span class=\"tn-icon cke cke-trilium-note\"></span> button. There is also a keyboard shortcut defined for it but it is not allocated by default.</p><p>The <em>Include note</em> dialog opens with two rows: <em>Note</em>, where you search for the note to include, and <em>Box size</em> (see <em>Box sizes</em> below), a row of buttons each with a small drawing of the size, with a sentence under it describing the size chosen. Once a note is picked, press <em>Include note</em> or <kbd>Enter</kbd> to include it. Typing the title of a note that does not exist offers to create it.</p><p>An image note, a <a class=\"reference-link\" href=\"#root/_help_grjYqerjn243\">Canvas</a> or a <a class=\"reference-link\" href=\"#root/_help_s1aBHPd79XYj\">Mermaid Diagrams</a> note picked in the dialog is inserted as an image rather than included, so instead of the size buttons, the <em>Box size</em> row says so. In a text note, the image can be resized once it is in the text, and the dialog reminds you of that, as it reminds you that the size of an include can be changed later.</p><p>To include a note that is already linked, right-click a reference link to it in a text note being edited and select <em>Convert link to an included note</em>, at the end of the menu. The include gets the box size that suits the note, as one added from the button does.</p><p>An <a href=\"#root/_help_0vhv7lsOLy82\">attachment</a> can be included the same way, from the context menu of a link to it (see <em>Embedding an attachment</em> there).</p><p>A link to blocks of a text note is converted the same way, with <em>Convert link to note excerpt</em>, and the include then shows only those blocks. See <a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a>.</p><h2>Box sizes</h2><p>The box size sets how much of the included note is shown.</p><ul><li><em>Tiny</em> shows a single row instead of the content: the note's icon, its title with the path to the note above it, and buttons to act on the note. The included note is never rendered, so wherever the note is shown outside the editor, such as in print, in a tooltip or on a shared page, a <em>Tiny</em> include appears as a link to the included note.</li><li><em>Small</em> and <em>Medium</em> show the content in a box of limited height. Text scrolls inside the box, while a picture, a diagram or a video is scaled down to fit it.</li><li><em>Full</em> shows the whole content.</li><li><em>Expandable</em> shows only the title until its <span class=\"tn-icon bx bx-chevron-right\"></span> arrow is pressed. In a read-only note, a click anywhere on the title row other than its buttons and link expands or collapses it as well.</li></ul><p>A new include gets the size that suits what it shows:</p><ul><li><em>Tiny</em> for a note or an attachment that has no preview, such as a relation map or an archive.</li><li><em>Small</em> for audio.</li><li><em>Full</em> for a code note or a code file, such as a <code>.js</code>, <code>.py</code> or <code>.txt</code> attachment, and for an excerpt of the blocks of a text note.</li><li><em>Medium</em> for anything else.</li></ul><p>The <em>Include note</em> dialog selects that size among its <em>Box size</em> buttons once the note is picked, and you can choose another one there. To change the size later, select the include and use the <em>Box size</em> menu in its toolbar, or the <em>Size</em> submenu of its <em>More actions</em> menu. For an included code or Markdown note and an embedded code or Markdown file, the <em>Box size</em> menu is the <span class=\"tn-icon bx bx-move-vertical\"></span> button, whose tooltip names the current size.</p><h2>Resizing</h2><p>A <em>Small</em>, <em>Medium</em> or <em>Expandable</em> include can be resized to any width and height. A <em>Tiny</em> or <em>Full</em> include always fits its content.</p><ul><li>To resize an include, select it and drag the handle in its bottom-right corner. To change only the width or only the height, drag the middle of its right or bottom edge instead, where a touch screen shows a handle too. In right-to-left text, the handle is in the bottom-left corner and the width changes from the left edge.</li><li>Resizing works with a mouse, a pen or a finger.</li><li>While the height changes, moving the handle near the top or the bottom of the note scrolls the note.</li><li>An include narrower than the note is centered, so changing its width moves both of its sides. Making it as wide as the note returns it to the full width.</li><li>To cancel a resize, press <kbd>Esc</kbd> before releasing the handle.</li><li>To reset the size, double-click the corner handle, or double-tap it on a touch screen. Double-clicking the right or bottom edge resets only the width or the height.</li><li>Choosing a box size resets the height. Choosing <em>Tiny</em> or <em>Full</em> resets the width too.</li><li>While an <em>Expandable</em> include is collapsed, only its width can be changed.</li></ul><h2>Caption</h2><p>An include can have a caption, shown centered at the bottom of its box. The caption is part of the text note, so it can be formatted like the rest of the text, for example in bold or with a link.</p><ul><li>To add a caption, select the include, press the <span class=\"tn-icon cke cke-caption\"></span> <em>Toggle caption on</em> button in its toolbar and type the caption.</li><li>To remove the caption, press the same button again. Pressing it once more brings back the text it had, as long as the note stays open.</li><li>A <em>Tiny</em> include has no caption. Switching an include to <em>Tiny</em> removes its caption, and switching it back to a larger size restores the caption, as long as the note stays open.</li><li>An <em>Expandable</em> include shows its caption under the title while the content is collapsed, and under the content once it is expanded.</li></ul><h2>Title</h2><p>The title row of an include links to the included note and holds its buttons. To show only the content, select the include and press the <span class=\"tn-icon bx bx-window-alt\"></span> <em>Show title</em> button in its toolbar. Pressing it again shows the title.</p><ul><li>While the title is hidden, the <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> button in the toolbar of the include opens the menu of the included note.</li><li>A <em>Tiny</em> or <em>Expandable</em> include always shows its title, and its toolbar has no <em>Show title</em> button.</li></ul><h2>Opening an included note</h2><p>To open an included note in a new tab, press the <span class=\"tn-icon bx bx-link-external\"></span> <em>Open in new tab</em> button at the end of its title. An embedded attachment has the same button.</p><p>The <span class=\"tn-icon bx bx-dots-vertical-rounded\"></span> <em>More actions</em> button at the end of the title row opens the same menu as right-clicking anywhere on the title row: the other places to open the note in and, for an embedded attachment, the actions on the attachment.</p><p>In a note being edited, the menu also has the commands of the include's toolbar: the <em>Size</em> submenu, <em>Show title</em> and <em>Show caption</em>, each checked while it is in effect, and <em>Convert to link</em> at the end. A drawing canvas, a Mermaid diagram, an included text, code or Markdown note and an embedded code or Markdown file also have <em>Editable</em>, above <em>Size</em>. An included code or Markdown note, an embedded code or Markdown file and a Mermaid diagram also have the <em>Word wrap</em> and <em>Line numbers</em> submenus after <em>Editable</em> (see <em>Editing an include in place</em> below). A Mermaid diagram, an included Markdown note and an embedded Markdown file also have <em>Source view</em>, <em>Split view</em> and <em>Preview</em> after these submenus. For an embedded attachment they follow its first group of actions; for an included note they end the menu.</p><p>To show an include of size <em>Medium</em> or <em>Full</em> on the whole screen, press the <span class=\"tn-icon bx bx-fullscreen\"></span> <em>Fullscreen</em> button at the end of its title. An excerpt of the blocks of a note has an <span class=\"tn-icon bx bx-pencil\"></span> <em>Edit excerpt</em> button there instead; see <a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a>. To return, press <span class=\"tn-icon bx bx-exit\"></span> <em>Exit fullscreen</em> in the top-right corner, or <kbd>Esc</kbd>.</p><p>A <em>Tiny</em> include has these buttons instead, followed by the same <em>More actions</em> button:</p><ul><li>For a note, <span class=\"tn-icon bx bx-edit\"></span> <em>Quick edit</em> opens the note in&nbsp;<a class=\"reference-link\" href=\"#root/_help_ZjLYv08Rp3qC\">Quick edit</a>, and <span class=\"tn-icon bx bx-link-external\"></span> <em>Open in new tab</em> opens it in a new tab.</li><li>For an embedded attachment, <span class=\"tn-icon bx bx-file-find\"></span> <em>Open externally</em> opens the file in another application, and <span class=\"tn-icon bx bx-download\"></span> <em>Download</em> downloads it. The size of the file is shown under its title.</li></ul><h2>Converting an include to a link</h2><p>To replace an include with a link to the included note, select it and press the <span class=\"tn-icon cke cke-link\"></span> <em>Convert to link</em> button in its toolbar, or choose <em>Convert to link</em> at the end of its <em>More actions</em> menu. An embedded attachment turns into a link to the attachment the same way.</p><h2>Missing notes and attachments</h2><p>An include whose note or attachment no longer exists, for example because it was deleted, keeps its size and shows the <span class=\"tn-icon bx bx-error-alt\"></span> icon in place of the content, with the ID of the missing note or attachment. To remove the include, select it and press <kbd>Delete</kbd>.</p><p>Content added by a newer version of Trilium, which this version cannot show, appears the same way with the <span class=\"tn-icon bx bx-error\"></span> icon. Editing the note keeps that content unchanged, so it shows again once Trilium is updated.</p><h2>Included notes in the share functionality</h2><p>If a <a href=\"#root/_help_R9pX4DGra2Vt\">shared note</a> contains one or more included notes, they will be displayed in the content of the note as if they were part of the note itself. The caption of an include is shown under the included content. A <em>Tiny</em> include is shown as a link to the included note instead, and so is an include that would show a note already shown around it, such as a note that includes itself. The same goes for a printed or exported note.</p><p>For this to work, the included notes must also be shared. However, they can still be hidden from the note tree via <code>#shareHiddenFromTree</code>.</p><p>An include whose note or attachment is missing or not shared shows <em>This content is not available</em> in its place, and so does content added by a newer version of Trilium.</p><h2>Interactive notes</h2><p>Since v0.104.0, included notes might become interactive depending on their note type:</p><ul><li><a class=\"reference-link\" href=\"#root/_help_GTwFsgaA0lCt\">Collections</a>&nbsp;(e.g.&nbsp;<a class=\"reference-link\" href=\"#root/_help_81SGnPGMk7Xc\">Geo Map</a>) will render fully interactive, including creating new notes.</li><li><a class=\"reference-link\" href=\"#root/_help_m523cpzocqaD\">Saved Search</a>&nbsp;will also display the results.</li><li><a class=\"reference-link\" href=\"#root/_help_1vHRoWCEjj0L\">Web View</a>&nbsp;provides an interactive preview of the website.</li></ul><h2>Included images</h2><p>An included image, whether an image note or an image attachment, is shown in the image viewer, which zooms and pans it:</p><ul><li>To zoom, press the <span class=\"tn-icon bx bx-plus-circle\"></span> <em>Zoom in</em> and <span class=\"tn-icon bx bx-minus-circle\"></span> <em>Zoom out</em> buttons in the bottom-right corner of the image, or pinch on a touch screen. The percentage between them resets the zoom.</li><li>To zoom with the mouse wheel, click the image first. Until then, the mouse wheel scrolls the note.</li><li>To pan an image that is zoomed in, drag it. At its fitted size, dragging the image on a touch screen scrolls the note.</li><li>To return to the fitted size, double-click the image.</li></ul><p>In a <em>Small</em> or <em>Medium</em> box, the image is scaled down to fit the height of the box. In fullscreen, it fits the screen.</p><h2>Editing an include in place</h2><p>An included text note, an included code note and an embedded code file such as a <code>.js</code>, <code>.py</code> or <code>.txt</code> attachment can be edited without leaving the note that includes them. Until then, a code note or file is shown read-only in the code editor, where its code can be selected and copied, and its blocks folded and unfolded with the arrows in its gutter. Included Markdown can be edited too, see <em>Included Markdown</em> below.</p><ul><li>To edit, select the include and turn on the <span class=\"tn-icon bx bx-edit-alt\"></span> <em>Editable</em> button at the start of its toolbar, or check <em>Editable</em> in its <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu. Turn <em>Editable</em> off to stop editing.</li><li>While <em>Editable</em> is on, the arrow keys move the caret into the include and back out, as through the rest of the text. Entering from above or from the left puts the caret at the start of the include, and entering from below or from the right puts it at the end. A collapsed <em>Expandable</em> include is skipped.</li><li>While an included text note has the focus, the formatting toolbar applies to it. The notes it includes in turn stay read-only.</li><li>Code is edited in the same code editor as a <a class=\"reference-link\" href=\"#root/_help_6f9hih2hXXZk\">Code</a> note, with its theme, indentation and line wrapping settings.</li><li>Typing <code>/</code> in the code lists the <a class=\"reference-link\" href=\"#root/_help_IEgsWp5hHH35\">Code Snippets</a> of its language, as in a code note.</li><li>The toolbar of an included code note or an embedded code file also has the language and indentation menus of the&nbsp;<a class=\"reference-link\" href=\"#root/_help_AlJ73vBCjWDw\">Status bar</a>, between <em>Editable</em> and the <span class=\"tn-icon bx bx-move-vertical\"></span> <em>Box size</em> menu: <em>Change language mode</em>, which shows the current language, and <em>Change tab width</em>, which shows the current indentation. <em>Re-indent content to</em> converts the indentation of the code itself and saves it to the included note or file, whether <em>Editable</em> is on or off.<ul><li>For an included note, the menus change the note, as they do in its own tab.</li><li>For an embedded code file, the language and indentation settings change only how this include shows the file, and are saved with the note that includes it. The language replaces the one that the file name gives, and the <em>Use default</em> entries return to the indentation set in&nbsp;<a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Code Notes</em>. These settings leave the file itself unchanged, and other includes of it keep their own settings.</li></ul></li><li>The <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu of an included code or Markdown note, an embedded code or Markdown file and a <a href=\"#root/_help_CohkqWQC1iBv\">Mermaid diagram</a> has two more submenus after <em>Editable</em>, each with <em>Auto</em>, <em>On</em> and <em>Off</em>. They change how the code editor shows the source.<ul><li><em>Word wrap</em> wraps long lines instead of scrolling them. <em>Auto</em> follows the setting in <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Code Notes</em>. For an included note, it sets the <code>#wrapLines</code> label of the note, as the <em>Word wrap</em> submenu of its <a class=\"reference-link\" href=\"#root/_help_8YBEPzcpUgxw\">Note menu</a> does for a code note. For an embedded file or a Mermaid diagram, it changes only this include.</li><li><em>Line numbers</em> shows or hides the numbers at the start of each line. <em>Auto</em> follows the setting in <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Code Notes</em>. It changes only this include, for an included note as well.</li></ul></li><li>The changes are saved as you type, to the included note or to the attachment, as they would be in its own tab.</li><li>The changes made in the code editor of an include are part of the undo history of the note that includes it, together with the changes to its text, in the order they were made. This includes the source of included Markdown and of a <a href=\"#root/_help_CohkqWQC1iBv\">Mermaid diagram</a>, and the changes to a drawing canvas (see below).<ul><li><kbd>Ctrl</kbd>+<kbd>Z</kbd> undoes the last change of the note, and <kbd>Ctrl</kbd>+<kbd>Y</kbd> or <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Z</kbd> redoes it, whether the caret is in the text or in an include, and also while <em>Editable</em> is off. The <span class=\"tn-icon cke cke-undo\"></span> <em>Undo</em> and <span class=\"tn-icon cke cke-redo\"></span> <em>Redo</em> buttons of the formatting toolbar do the same. With the Vim key bindings, <code>u</code> and <kbd>Ctrl</kbd>+<kbd>R</kbd> in an include do the same too.</li><li>The focus moves to the change that was undone or redone: into the code editor or the drawing canvas of the include, or back to the text.</li><li>Undoing a change of an included note saves the included note again. Once the included note has been changed elsewhere, for example in another tab, its earlier changes can no longer be undone from here, and undo skips them.</li><li>An included text note keeps an undo history of its own.</li></ul></li><li>An include of <a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a> edits only the referenced blocks.</li><li>Editing is not available in a <a href=\"#root/_help_CoFPLs3dRlXc\">read-only note</a>, for an included note marked <code>#readOnly</code>, or for an attachment of another note.</li><li><a class=\"reference-link\" href=\"#root/_help_McngOG2jbUWX\">Search in note</a> finds the text of included text and code notes among the results of the note around them, and replaces it while <em>Editable</em> is on.</li></ul><h2>Included Markdown</h2><p>An included&nbsp;<a class=\"reference-link\" href=\"#root/_help_6RM1Q7ppFVoj\">Markdown</a>&nbsp;note and an embedded Markdown file, such as a <code>.md</code> attachment, are shown with the same three views as a Markdown note in its own tab (see&nbsp;<a class=\"reference-link\" href=\"#root/_help_SL5f1Auq7sVN\">Note types with split view</a>): <span class=\"tn-icon bx bx-code\"></span> <em>Source view</em>, <span class=\"tn-icon bx bxs-dock-left\"></span> <em>Split view</em> and <span class=\"tn-icon bx bx-show\"></span> <em>Preview</em>.</p><ul><li>To switch the view, press one of the three buttons in the title row of the include. In a note being edited, the toolbar of the include has the same buttons after <em>Editable</em>, and its <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu has them as <em>Source view</em>, <em>Split view</em> and <em>Preview</em>.</li><li>Until a view is chosen, the include shows the <em>Preview</em>, and the <em>Split view</em> while <em>Editable</em> is on.</li><li>To edit the Markdown, turn on <em>Editable</em> (see <em>Editing an include in place</em> above). The source is edited in the code editor of a Markdown note, and the preview follows the changes as you type. While <em>Editable</em> is off, the source can be read and copied but not changed.</li><li>The source has the slash commands and the <code>@</code> and <code>[[</code> note links of a <a class=\"reference-link\" href=\"#root/_help_6RM1Q7ppFVoj\">Markdown</a> note. A note created from the <code>@</code> or <code>[[</code> list goes under the included note, or for an embedded file under the note that includes it, and <code>/image</code> uploads the image to that same note.</li><li>The <em>Word wrap</em> and <em>Line numbers</em> submenus of the <em>More actions</em> menu change how the source shows, as for code (see <em>Editing an include in place</em> above).</li><li>As in a Markdown note, the preview scrolls along with the source and highlights the block where the cursor is, and <kbd>Ctrl</kbd>+<kbd>B</kbd>, <kbd>Ctrl</kbd>+<kbd>I</kbd>, <kbd>Ctrl</kbd>+<kbd>M</kbd> and <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>X</kbd> format the selection.</li><li>In a note being edited, the view is saved with the include, so two includes of the same note can show different views. In a <a href=\"#root/_help_CoFPLs3dRlXc\">read-only note</a>, the view can be changed too, until the note is opened again.</li><li>While the source shows, the include has the height of its box size, or the height it was resized to. A <em>Full</em> include fits its content instead.</li><li><a class=\"reference-link\" href=\"#root/_help_McngOG2jbUWX\">Search in note</a>&nbsp;searches the source while it shows, and the preview otherwise.</li></ul><h2>Drawing canvases</h2><p>A drawing canvas is an Excalidraw canvas, like the one of a <a class=\"reference-link\" href=\"#root/_help_grjYqerjn243\">Canvas</a> note, drawn directly in the text note. It is not a note of its own: the drawing is kept in a <code>Canvas.excalidraw</code> <a href=\"#root/_help_0vhv7lsOLy82\">attachment</a> of the text note and is saved together with the text.</p><ul><li>To insert a drawing canvas, open the <span class=\"tn-icon cke cke-plus\"></span> <em>Insert</em> menu of the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a> and choose <span class=\"tn-icon bx bx-pen\"></span> <em>Drawing canvas</em>, above <em>Mermaid diagram</em>. It is also available as <em>Drawing canvas</em> in the <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>. The canvas is added empty and editable, in a <em>Medium</em> box with its title hidden, and takes the focus, ready for drawing.</li><li>To draw or write over an image, select the image and press the <span class=\"tn-icon bx bxs-pen\"></span> <em>Convert image to a drawing canvas</em> button of its toolbar. The image is replaced by an editable drawing canvas in a <em>Medium</em> box, with its title hidden and the focus in it. The image sits at its original size in the middle of the canvas, zoomed so that all of it shows, and is locked so that it cannot be selected or moved by accident. While it is locked, the canvas can be zoomed in on the image but not zoomed out past it or scrolled beyond its edges. To move or resize the image anyway, right-click it and choose <em>Unlock</em>. The caption of the image is kept, but not its alignment or link. Only an image on its own line can be converted, not one inside a paragraph. Undo brings the image back.</li><li>An Excalidraw file (<code>.excalidraw</code>) attached with <em>Attach and embed file</em>, under the <span class=\"tn-icon cke cke-paper-clip\"></span><em>Attach file</em> button, becomes a drawing canvas too, in a <em>Medium</em> box titled with the file name. It starts with <em>Editable</em> off, so the drawing shows but cannot be changed until <em>Editable</em> is turned on (see below).</li><li>To draw on a canvas that does not have the focus, click it first. Until then, touch gestures scroll the note. The canvas then has the tools, menus and keyboard shortcuts of a Canvas note. The toolbars, the menus and the properties of the selected shapes show only while the canvas has the focus, so elsewhere the drawing reads like a picture in the text.</li><li>The mouse wheel and the touchpad scroll the note over a canvas too, as over the text. To zoom, use the zoom buttons of the canvas toolbar; to move around the drawing, use the <span class=\"tn-icon bx bxs-hand\"></span> <em>Hand</em> tool. In fullscreen, the mouse wheel moves and zooms the drawing instead.</li><li>The canvas toolbar replaces the Excalidraw menu: <em>Export image</em>, <em>Find on canvas</em>, <em>Library</em> and <em>Help</em> are at the end of its <span class=\"tn-icon bx bx-category\"></span> <em>More tools</em> menu. In fullscreen, the Excalidraw menu shows again.</li><li>The changes to the drawing are part of the undo history of the text note (see <em>Editing an include in place</em> above). <kbd>Ctrl</kbd>+<kbd>Z</kbd>, <kbd>Ctrl</kbd>+<kbd>Y</kbd> and the <span class=\"tn-icon bx bx-undo\"></span> <em>Undo</em> and <span class=\"tn-icon bx bx-redo\"></span> <em>Redo</em> buttons of the canvas toolbar undo and redo the last change of the note, in the drawing or in the text.</li><li>A new drawing has the background color of the note. A background chosen from the Excalidraw menu replaces it.</li><li>To protect a finished drawing from accidental changes, select it and turn off the <span class=\"tn-icon bx bx-edit-alt\"></span> <em>Editable</em> button at the start of its toolbar, or uncheck <em>Editable</em> in its <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu. The drawing then shows as a still picture, at the zoom and position it had, and can no longer be changed, zoomed or moved. To draw again, turn <em>Editable</em> back on.</li><li>The box sizes, resizing, the caption and the title work as for an included note, but the toolbar of a drawing leaves the box size, <em>Show title</em> and <em>Convert to link</em> to its <em>More actions</em> menu.</li><li>In the desktop layout, Excalidraw keeps its desktop interface however small the box is. In the mobile layout, a narrow or short box switches it to a compact interface. For more room, choose <em>Full</em>, or show the title and press <span class=\"tn-icon bx bx-fullscreen\"></span> <em>Fullscreen</em>.</li><li>Pictures added to the drawing are stored in the same attachment. A converted image is kept as an image attachment of the note instead, named with a generated code.</li><li>In a <a href=\"#root/_help_CoFPLs3dRlXc\">read-only note</a>, the drawing shows as a still picture too.</li><li>On a <a href=\"#root/_help_R9pX4DGra2Vt\">shared page</a>, the drawing is shown as a picture at its own size, whatever the size of its box, in light or dark colors to match the page. Each change to the drawing saves this picture as an SVG image attachment of the note, also named with a generated code.</li></ul><h3>Limitations</h3><ul><li>The Excalidraw shape library is not saved for a drawing canvas.</li><li>Outside the editor, for example in a tooltip, when printing or in the list of attachments, the drawing is shown as a picture.</li><li>A drawing has no picture for shared pages until its first change, except one converted from an image. Until then, for example for an attached <code>.excalidraw</code> file, a shared page shows a link to download the drawing instead.</li><li>In Safari, the picture of a drawing on a shared page follows the light or dark appearance of the system rather than the theme chosen on the page.</li><li>A copy of a drawing canvas pasted in the same note shares the drawing with the original, so a change to one shows in the other only after the note is opened again. A copy pasted in another note gets a drawing of its own.</li></ul>",
+ "_help_nBAXQFj20hS1": "<p>Text notes can \"include\" another note as a read-only widget or an interactive widget, depending on the type of note.</p><p>This can be useful for e.g. including a dynamically generated chart (from scripts &amp; \"render HTML\" note) or other more advanced use cases.</p><h2>Including a note</h2><p>In the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>, look for the&nbsp;<span class=\"tn-icon cke cke-trilium-note\"></span> button. There is also a keyboard shortcut defined for it but it is not allocated by default.</p><p>The <em>Include note</em> dialog opens with two rows: <em>Note</em>, where you search for the note to include, and <em>Box size</em> (see <em>Box sizes</em> below), a row of buttons each with a small drawing of the size, with a sentence under it describing the size chosen. Once a note is picked, press <em>Include note</em> or <kbd>Enter</kbd> to include it. Typing the title of a note that does not exist offers to create it.</p><p>An image note, a <a class=\"reference-link\" href=\"#root/_help_grjYqerjn243\">Canvas</a> or a <a class=\"reference-link\" href=\"#root/_help_s1aBHPd79XYj\">Mermaid Diagrams</a> note picked in the dialog is inserted as an image rather than included, so instead of the size buttons, the <em>Box size</em> row says so. In a text note, the image can be resized once it is in the text, and the dialog reminds you of that, as it reminds you that the size of an include can be changed later.</p><p>To include a note that is already linked, right-click a reference link to it in a text note being edited and select <em>Convert link to an included note</em>, at the end of the menu. The include gets the box size that suits the note, as one added from the button does.</p><p>An <a href=\"#root/_help_0vhv7lsOLy82\">attachment</a> can be included the same way, from the context menu of a link to it (see <em>Embedding an attachment</em> there).</p><p>A link to blocks of a text note is converted the same way, with <em>Convert link to note excerpt</em>, and the include then shows only those blocks. See <a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a>.</p><h2>Box sizes</h2><p>The box size sets how much of the included note is shown.</p><ul><li><em>Tiny</em> shows a single row instead of the content: the note's icon, its title with the path to the note above it, and buttons to act on the note. The included note is never rendered, so wherever the note is shown outside the editor, such as in print, in a tooltip or on a shared page, a <em>Tiny</em> include appears as a link to the included note.</li><li><em>Small</em> and <em>Medium</em> show the content in a box of limited height. Text scrolls inside the box, while a picture, a diagram or a video is scaled down to fit it.</li><li><em>Full</em> shows the whole content.</li><li><em>Expandable</em> shows only the title until its <span class=\"tn-icon bx bx-chevron-right\"></span> arrow is pressed. In a read-only note, a click anywhere on the title row other than its buttons and link expands or collapses it as well.</li></ul><p>A new include gets the size that suits what it shows:</p><ul><li><em>Tiny</em> for a note or an attachment that has no preview, such as a relation map or an archive.</li><li><em>Small</em> for audio.</li><li><em>Full</em> for a code note or a code file, such as a <code>.js</code>, <code>.py</code> or <code>.txt</code> attachment, and for an excerpt of the blocks of a text note.</li><li><em>Medium</em> for anything else.</li></ul><p>The <em>Include note</em> dialog selects that size among its <em>Box size</em> buttons once the note is picked, and you can choose another one there. To change the size later, select the include and use the <em>Box size</em> menu in its toolbar, or the <em>Size</em> submenu of its <em>More actions</em> menu. For an included code or Markdown note and an embedded code or Markdown file, the <em>Box size</em> menu is the <span class=\"tn-icon bx bx-move-vertical\"></span> button, whose tooltip names the current size.</p><h2>Resizing</h2><p>A <em>Small</em>, <em>Medium</em> or <em>Expandable</em> include can be resized to any width and height. A <em>Tiny</em> or <em>Full</em> include always fits its content.</p><ul><li>To resize an include, select it and drag the handle in its bottom-right corner. To change only the width or only the height, drag the middle of its right or bottom edge instead, where a touch screen shows a handle too. In right-to-left text, the handle is in the bottom-left corner and the width changes from the left edge.</li><li>Resizing works with a mouse, a pen or a finger.</li><li>While the height changes, moving the handle near the top or the bottom of the note scrolls the note.</li><li>An include narrower than the note is centered, so changing its width moves both of its sides. A drawing aligned to the left or the right keeps that side in place and has its handles on the other side (see <em>Positioning a drawing</em> below). Making an include as wide as the note returns it to the full width.</li><li>To cancel a resize, press <kbd>Esc</kbd> before releasing the handle.</li><li>To reset the size, double-click the corner handle, or double-tap it on a touch screen. Double-clicking the right or bottom edge resets only the width or the height.</li><li>Choosing a box size resets the height. Choosing <em>Tiny</em> or <em>Full</em> resets the width too.</li><li>While an <em>Expandable</em> include is collapsed, only its width can be changed.</li></ul><h2>Caption</h2><p>An include can have a caption, shown centered at the bottom of its box. The caption is part of the text note, so it can be formatted like the rest of the text, for example in bold or with a link.</p><ul><li>To add a caption, select the include, press the <span class=\"tn-icon cke cke-caption\"></span> <em>Toggle caption on</em> button in its toolbar and type the caption.</li><li>To remove the caption, press the same button again. Pressing it once more brings back the text it had, as long as the note stays open.</li><li>A <em>Tiny</em> include has no caption. Switching an include to <em>Tiny</em> removes its caption, and switching it back to a larger size restores the caption, as long as the note stays open.</li><li>An <em>Expandable</em> include shows its caption under the title while the content is collapsed, and under the content once it is expanded.</li></ul><h2>Title</h2><p>The title row of an include links to the included note and holds its buttons. To show only the content, select the include and press the <span class=\"tn-icon bx bx-window-alt\"></span> <em>Show title</em> button in its toolbar. Pressing it again shows the title.</p><ul><li>While the title is hidden, the <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> button in the toolbar of the include opens the menu of the included note.</li><li>A <em>Tiny</em> or <em>Expandable</em> include always shows its title, and its toolbar has no <em>Show title</em> button.</li></ul><h2>Opening an included note</h2><p>To open an included note in a new tab, press the <span class=\"tn-icon bx bx-link-external\"></span> <em>Open in new tab</em> button at the end of its title. An embedded attachment has the same button.</p><p>The <span class=\"tn-icon bx bx-dots-vertical-rounded\"></span> <em>More actions</em> button at the end of the title row opens the same menu as right-clicking anywhere on the title row: the other places to open the note in and, for an embedded attachment, the actions on the attachment.</p><p>In a note being edited, the menu also has the commands of the include's toolbar: the <em>Size</em> submenu, <em>Show title</em> and <em>Show caption</em>, each checked while it is in effect, and <em>Convert to link</em> at the end. A drawing canvas, a Mermaid diagram, an included text, code or Markdown note and an embedded code or Markdown file also have <em>Editable</em>, above <em>Size</em>. An included code or Markdown note, an embedded code or Markdown file and a Mermaid diagram also have the <em>Word wrap</em> and <em>Line numbers</em> submenus after <em>Editable</em> (see <em>Editing an include in place</em> below). A Mermaid diagram, an included Markdown note and an embedded Markdown file also have <em>Source view</em>, <em>Split view</em> and <em>Preview</em> after these submenus. For an embedded attachment they follow its first group of actions; for an included note they end the menu.</p><p>To show an include of size <em>Medium</em> or <em>Full</em> on the whole screen, press the <span class=\"tn-icon bx bx-fullscreen\"></span> <em>Fullscreen</em> button at the end of its title. An excerpt of the blocks of a note has an <span class=\"tn-icon bx bx-pencil\"></span> <em>Edit excerpt</em> button there instead; see <a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a>. To return, press <span class=\"tn-icon bx bx-exit\"></span> <em>Exit fullscreen</em> in the top-right corner, or <kbd>Esc</kbd>.</p><p>A <em>Tiny</em> include has these buttons instead, followed by the same <em>More actions</em> button:</p><ul><li>For a note, <span class=\"tn-icon bx bx-edit\"></span> <em>Quick edit</em> opens the note in&nbsp;<a class=\"reference-link\" href=\"#root/_help_ZjLYv08Rp3qC\">Quick edit</a>, and <span class=\"tn-icon bx bx-link-external\"></span> <em>Open in new tab</em> opens it in a new tab.</li><li>For an embedded attachment, <span class=\"tn-icon bx bx-file-find\"></span> <em>Open externally</em> opens the file in another application, and <span class=\"tn-icon bx bx-download\"></span> <em>Download</em> downloads it. The size of the file is shown under its title.</li></ul><h2>Converting an include to a link</h2><p>To replace an include with a link to the included note, select it and press the <span class=\"tn-icon cke cke-link\"></span> <em>Convert to link</em> button in its toolbar, or choose <em>Convert to link</em> at the end of its <em>More actions</em> menu. An embedded attachment turns into a link to the attachment the same way.</p><h2>Missing notes and attachments</h2><p>An include whose note or attachment no longer exists, for example because it was deleted, keeps its size and shows the <span class=\"tn-icon bx bx-error-alt\"></span> icon in place of the content, with the ID of the missing note or attachment. To remove the include, select it and press <kbd>Delete</kbd>.</p><p>Content added by a newer version of Trilium, which this version cannot show, appears the same way with the <span class=\"tn-icon bx bx-error\"></span> icon. Editing the note keeps that content unchanged, so it shows again once Trilium is updated.</p><h2>Included notes in the share functionality</h2><p>If a <a href=\"#root/_help_R9pX4DGra2Vt\">shared note</a> contains one or more included notes, they will be displayed in the content of the note as if they were part of the note itself. An include resized narrower than the note keeps its width, and a drawing its position. On a narrow screen, a drawing with a position other than <em>Align center</em> takes the full width. The caption of an include is shown under the included content. A <em>Tiny</em> include is shown as a link to the included note instead, and so is an include that would show a note already shown around it, such as a note that includes itself. The same goes for a printed or exported note.</p><p>For this to work, the included notes must also be shared. However, they can still be hidden from the note tree via <code>#shareHiddenFromTree</code>.</p><p>An include whose note or attachment is missing or not shared shows <em>This content is not available</em> in its place, and so does content added by a newer version of Trilium.</p><h2>Interactive notes</h2><p>Since v0.104.0, included notes might become interactive depending on their note type:</p><ul><li><a class=\"reference-link\" href=\"#root/_help_GTwFsgaA0lCt\">Collections</a>&nbsp;(e.g.&nbsp;<a class=\"reference-link\" href=\"#root/_help_81SGnPGMk7Xc\">Geo Map</a>) will render fully interactive, including creating new notes.</li><li><a class=\"reference-link\" href=\"#root/_help_m523cpzocqaD\">Saved Search</a>&nbsp;will also display the results.</li><li><a class=\"reference-link\" href=\"#root/_help_1vHRoWCEjj0L\">Web View</a>&nbsp;provides an interactive preview of the website.</li></ul><h2>Included images</h2><p>An included image, whether an image note or an image attachment, is shown in the image viewer, which zooms and pans it:</p><ul><li>To zoom, press the <span class=\"tn-icon bx bx-plus-circle\"></span> <em>Zoom in</em> and <span class=\"tn-icon bx bx-minus-circle\"></span> <em>Zoom out</em> buttons in the bottom-right corner of the image, or pinch on a touch screen. The percentage between them resets the zoom.</li><li>To zoom with the mouse wheel, click the image first. Until then, the mouse wheel scrolls the note.</li><li>To pan an image that is zoomed in, drag it. At its fitted size, dragging the image on a touch screen scrolls the note.</li><li>To return to the fitted size, double-click the image.</li></ul><p>In a <em>Small</em> or <em>Medium</em> box, the image is scaled down to fit the height of the box. In fullscreen, it fits the screen.</p><h2>Editing an include in place</h2><p>An included text note, an included code note and an embedded code file such as a <code>.js</code>, <code>.py</code> or <code>.txt</code> attachment can be edited without leaving the note that includes them. Until then, a code note or file is shown read-only in the code editor, where its code can be selected and copied, and its blocks folded and unfolded with the arrows in its gutter. Included Markdown can be edited too, see <em>Included Markdown</em> below.</p><ul><li>To edit, select the include and turn on the <span class=\"tn-icon bx bx-edit-alt\"></span> <em>Editable</em> button at the start of its toolbar, or check <em>Editable</em> in its <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu. Turn <em>Editable</em> off to stop editing.</li><li>While <em>Editable</em> is on, the arrow keys move the caret into the include and back out, as through the rest of the text. Entering from above or from the left puts the caret at the start of the include, and entering from below or from the right puts it at the end. A collapsed <em>Expandable</em> include is skipped.</li><li>While an included text note has the focus, the formatting toolbar applies to it. The notes it includes in turn stay read-only.</li><li>Code is edited in the same code editor as a <a class=\"reference-link\" href=\"#root/_help_6f9hih2hXXZk\">Code</a> note, with its theme, indentation and line wrapping settings.</li><li>Typing <code>/</code> in the code lists the <a class=\"reference-link\" href=\"#root/_help_IEgsWp5hHH35\">Code Snippets</a> of its language, as in a code note.</li><li>The toolbar of an included code note or an embedded code file also has the language and indentation menus of the&nbsp;<a class=\"reference-link\" href=\"#root/_help_AlJ73vBCjWDw\">Status bar</a>, between <em>Editable</em> and the <span class=\"tn-icon bx bx-move-vertical\"></span> <em>Box size</em> menu: <em>Change language mode</em>, which shows the current language, and <em>Change tab width</em>, which shows the current indentation. <em>Re-indent content to</em> converts the indentation of the code itself and saves it to the included note or file, whether <em>Editable</em> is on or off.<ul><li>For an included note, the menus change the note, as they do in its own tab.</li><li>For an embedded code file, the language and indentation settings change only how this include shows the file, and are saved with the note that includes it. The language replaces the one that the file name gives, and the <em>Use default</em> entries return to the indentation set in&nbsp;<a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Code Notes</em>. These settings leave the file itself unchanged, and other includes of it keep their own settings.</li></ul></li><li>The <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu of an included code or Markdown note, an embedded code or Markdown file and a <a href=\"#root/_help_CohkqWQC1iBv\">Mermaid diagram</a> has two more submenus after <em>Editable</em>, each with <em>Auto</em>, <em>On</em> and <em>Off</em>. They change how the code editor shows the source.<ul><li><em>Word wrap</em> wraps long lines instead of scrolling them. <em>Auto</em> follows the setting in <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Code Notes</em>. For an included note, it sets the <code>#wrapLines</code> label of the note, as the <em>Word wrap</em> submenu of its <a class=\"reference-link\" href=\"#root/_help_8YBEPzcpUgxw\">Note menu</a> does for a code note. For an embedded file or a Mermaid diagram, it changes only this include.</li><li><em>Line numbers</em> shows or hides the numbers at the start of each line. <em>Auto</em> follows the setting in <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Code Notes</em>. It changes only this include, for an included note as well.</li></ul></li><li>The changes are saved as you type, to the included note or to the attachment, as they would be in its own tab.</li><li>The changes made in the code editor of an include are part of the undo history of the note that includes it, together with the changes to its text, in the order they were made. This includes the source of included Markdown and of a <a href=\"#root/_help_CohkqWQC1iBv\">Mermaid diagram</a>, and the changes to a drawing canvas (see below).<ul><li><kbd>Ctrl</kbd>+<kbd>Z</kbd> undoes the last change of the note, and <kbd>Ctrl</kbd>+<kbd>Y</kbd> or <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Z</kbd> redoes it, whether the caret is in the text or in an include, and also while <em>Editable</em> is off. The <span class=\"tn-icon cke cke-undo\"></span> <em>Undo</em> and <span class=\"tn-icon cke cke-redo\"></span> <em>Redo</em> buttons of the formatting toolbar do the same. With the Vim key bindings, <code>u</code> and <kbd>Ctrl</kbd>+<kbd>R</kbd> in an include do the same too.</li><li>The focus moves to the change that was undone or redone: into the code editor or the drawing canvas of the include, or back to the text.</li><li>Undoing a change of an included note saves the included note again. Once the included note has been changed elsewhere, for example in another tab, its earlier changes can no longer be undone from here, and undo skips them.</li><li>An included text note keeps an undo history of its own.</li></ul></li><li>An include of <a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a> edits only the referenced blocks.</li><li>Editing is not available in a <a href=\"#root/_help_CoFPLs3dRlXc\">read-only note</a>, for an included note marked <code>#readOnly</code>, or for an attachment of another note.</li><li><a class=\"reference-link\" href=\"#root/_help_McngOG2jbUWX\">Search in note</a> finds the text of included text and code notes among the results of the note around them, and replaces it while <em>Editable</em> is on.</li></ul><h2>Included Markdown</h2><p>An included&nbsp;<a class=\"reference-link\" href=\"#root/_help_6RM1Q7ppFVoj\">Markdown</a>&nbsp;note and an embedded Markdown file, such as a <code>.md</code> attachment, are shown with the same three views as a Markdown note in its own tab (see&nbsp;<a class=\"reference-link\" href=\"#root/_help_SL5f1Auq7sVN\">Note types with split view</a>): <span class=\"tn-icon bx bx-code\"></span> <em>Source view</em>, <span class=\"tn-icon bx bxs-dock-left\"></span> <em>Split view</em> and <span class=\"tn-icon bx bx-show\"></span> <em>Preview</em>.</p><ul><li>To switch the view, press one of the three buttons in the title row of the include. In a note being edited, the toolbar of the include has the same buttons after <em>Editable</em>, and its <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu has them as <em>Source view</em>, <em>Split view</em> and <em>Preview</em>.</li><li>Until a view is chosen, the include shows the <em>Preview</em>, and the <em>Split view</em> while <em>Editable</em> is on.</li><li>To edit the Markdown, turn on <em>Editable</em> (see <em>Editing an include in place</em> above). The source is edited in the code editor of a Markdown note, and the preview follows the changes as you type. While <em>Editable</em> is off, the source can be read and copied but not changed.</li><li>The source has the slash commands and the <code>@</code> and <code>[[</code> note links of a <a class=\"reference-link\" href=\"#root/_help_6RM1Q7ppFVoj\">Markdown</a> note. A note created from the <code>@</code> or <code>[[</code> list goes under the included note, or for an embedded file under the note that includes it, and <code>/image</code> uploads the image to that same note.</li><li>The <em>Word wrap</em> and <em>Line numbers</em> submenus of the <em>More actions</em> menu change how the source shows, as for code (see <em>Editing an include in place</em> above).</li><li>As in a Markdown note, the preview scrolls along with the source and highlights the block where the cursor is, and <kbd>Ctrl</kbd>+<kbd>B</kbd>, <kbd>Ctrl</kbd>+<kbd>I</kbd>, <kbd>Ctrl</kbd>+<kbd>M</kbd> and <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>X</kbd> format the selection.</li><li>In a note being edited, the view is saved with the include, so two includes of the same note can show different views. In a <a href=\"#root/_help_CoFPLs3dRlXc\">read-only note</a>, the view can be changed too, until the note is opened again.</li><li>While the source shows, the include has the height of its box size, or the height it was resized to. A <em>Full</em> include fits its content instead.</li><li><a class=\"reference-link\" href=\"#root/_help_McngOG2jbUWX\">Search in note</a>&nbsp;searches the source while it shows, and the preview otherwise.</li></ul><h2>Drawing canvases</h2><p>A drawing canvas is an Excalidraw canvas, like the one of a <a class=\"reference-link\" href=\"#root/_help_grjYqerjn243\">Canvas</a> note, drawn directly in the text note. It is not a note of its own: the drawing is kept in a <code>Canvas.excalidraw</code> <a href=\"#root/_help_0vhv7lsOLy82\">attachment</a> of the text note and is saved together with the text.</p><ul><li>To insert a drawing canvas, open the <span class=\"tn-icon cke cke-plus\"></span> <em>Insert</em> menu of the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a> and choose <span class=\"tn-icon bx bx-pen\"></span> <em>Drawing canvas</em>, above <em>Mermaid diagram</em>. It is also available as <em>Drawing canvas</em> in the <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>. The canvas is added empty and editable, in a <em>Medium</em> box with its title hidden, and takes the focus, ready for drawing.</li><li>To draw or write over an image, select the image and press the <span class=\"tn-icon bx bxs-pen\"></span> <em>Convert image to a drawing canvas</em> button of its toolbar. The image is replaced by an editable drawing canvas in a <em>Medium</em> box, with its title hidden and the focus in it. The image sits at its original size in the middle of the canvas, zoomed so that all of it shows, and is locked so that it cannot be selected or moved by accident. While it is locked, the canvas can be zoomed in on the image but not zoomed out past it or scrolled beyond its edges. To move or resize the image anyway, right-click it and choose <em>Unlock</em>. The caption of the image is kept, but not its alignment or link. Only an image on its own line can be converted, not one inside a paragraph. Undo brings the image back.</li><li>An Excalidraw file (<code>.excalidraw</code>) attached with <em>Attach and embed file</em>, under the <span class=\"tn-icon cke cke-paper-clip\"></span><em>Attach file</em> button, becomes a drawing canvas too, in a <em>Medium</em> box titled with the file name. It starts with <em>Editable</em> off, so the drawing shows but cannot be changed until <em>Editable</em> is turned on (see below).</li><li>To draw on a canvas that does not have the focus, click it first. Until then, touch gestures scroll the note. The canvas then has the tools, menus and keyboard shortcuts of a Canvas note. The toolbars, the menus and the properties of the selected shapes show only while the canvas has the focus, so elsewhere the drawing reads like a picture in the text.</li><li>The mouse wheel and the touchpad scroll the note over a canvas too, as over the text. To zoom, use the zoom buttons of the canvas toolbar; to move around the drawing, use the <span class=\"tn-icon bx bxs-hand\"></span> <em>Hand</em> tool. In fullscreen, the mouse wheel moves and zooms the drawing instead.</li><li>The canvas toolbar replaces the Excalidraw menu: <em>Export image</em>, <em>Find on canvas</em>, <em>Library</em> and <em>Help</em> are at the end of its <span class=\"tn-icon bx bx-category\"></span> <em>More tools</em> menu. In fullscreen, the Excalidraw menu shows again.</li><li>The changes to the drawing are part of the undo history of the text note (see <em>Editing an include in place</em> above). <kbd>Ctrl</kbd>+<kbd>Z</kbd>, <kbd>Ctrl</kbd>+<kbd>Y</kbd> and the <span class=\"tn-icon bx bx-undo\"></span> <em>Undo</em> and <span class=\"tn-icon bx bx-redo\"></span> <em>Redo</em> buttons of the canvas toolbar undo and redo the last change of the note, in the drawing or in the text.</li><li>A new drawing has the background color of the note. A background chosen from the Excalidraw menu replaces it.</li><li>To protect a finished drawing from accidental changes, select it and turn off the <span class=\"tn-icon bx bx-edit-alt\"></span> <em>Editable</em> button at the start of its toolbar, or uncheck <em>Editable</em> in its <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu. The drawing then shows as a still picture, at the zoom and position it had, and can no longer be changed, zoomed or moved. To draw again, turn <em>Editable</em> back on.</li><li>The box sizes, resizing, the caption and the title work as for an included note, but the toolbar of a drawing leaves the box size, <em>Show title</em> and <em>Convert to link</em> to its <em>More actions</em> menu, which also sets its position (see <em>Positioning a drawing</em> below).</li><li>In the desktop layout, Excalidraw keeps its desktop interface however small the box is. In the mobile layout, a narrow or short box switches it to a compact interface. For more room, choose <em>Full</em>, or show the title and press <span class=\"tn-icon bx bx-fullscreen\"></span> <em>Fullscreen</em>.</li><li>Pictures added to the drawing are stored in the same attachment. A converted image is kept as an image attachment of the note instead, named with a generated code.</li><li>In a <a href=\"#root/_help_CoFPLs3dRlXc\">read-only note</a>, the drawing shows as a still picture too.</li><li>On a <a href=\"#root/_help_R9pX4DGra2Vt\">shared page</a>, the drawing is shown as a picture at its own size, up to the width its box was resized to, in light or dark colors to match the page. Each change to the drawing saves this picture as an SVG image attachment of the note, also named with a generated code.</li></ul><h3>Positioning a drawing</h3><p>A drawing can sit on lines of its own or have the text wrap around it, as an <a href=\"#root/_help_mT0HEkOsz6i1\">image</a> can.</p><ul><li>To change the position, select the drawing, open its <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu and choose an entry of its <em>Position</em> submenu:<ul><li>Under <em>Break text</em>, <span class=\"tn-icon cke cke-object-left\"></span> <em>Align left</em>, <span class=\"tn-icon cke cke-object-center\"></span> <em>Align center</em> and <span class=\"tn-icon cke cke-object-right\"></span> <em>Align right</em> place the drawing on lines of its own, at that side of the note. <em>Align center</em> is the default.</li><li>Under <em>Wrap text</em>, <span class=\"tn-icon cke cke-object-inline-left\"></span> <em>Align left</em> and <span class=\"tn-icon cke cke-object-inline-right\"></span> <em>Align right</em> place the drawing at that side and let the text run beside it.</li></ul></li><li>A drawing is inserted at the full width of the note, so a new position shows once the drawing is resized narrower (see <em>Resizing</em> above). The position is kept whatever the box size, and shows again when a <em>Small</em>, <em>Medium</em> or <em>Expandable</em> box is resized.</li><li>In the mobile layout, a drawing with a position other than <em>Align center</em> takes the full width, and only its height can be resized.</li></ul><h3>Limitations</h3><ul><li>The Excalidraw shape library is not saved for a drawing canvas.</li><li>Outside the editor, for example in a tooltip, when printing or in the list of attachments, the drawing is shown as a picture.</li><li>A drawing has no picture for shared pages until its first change, except one converted from an image. Until then, for example for an attached <code>.excalidraw</code> file, a shared page shows a link to download the drawing instead.</li><li>In Safari, the picture of a drawing on a shared page follows the light or dark appearance of the system rather than the theme chosen on the page.</li><li>A copy of a drawing canvas pasted in the same note shares the drawing with the original, so a change to one shows in the other only after the note is opened again. A copy pasted in another note gets a drawing of its own.</li></ul>",
"_help_CohkqWQC1iBv": "<p>Press the&nbsp;<span class=\"tn-icon cke cke-plus\"></span> button in the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>&nbsp;to reveal special inserable items and blocks such as symbols, Math expressions and separators.</p><h2>Bookmarks</h2><p>See the dedicated&nbsp;<a class=\"reference-link\" href=\"#root/_help_oSuaNgyyKnhu\">Anchors</a>&nbsp;section.</p><h2>New child note</h2><p>Choose <span class=\"tn-icon bx bx-subdirectory-right\"></span> <em>New child note</em> to create an empty child note of the current note and insert a link to it at the cursor. The new note opens in <a class=\"reference-link\" href=\"#root/_help_ZjLYv08Rp3qC\">Quick edit</a> with its title selected, so typing names it, and the link shows the new title. While the note is still empty, Quick edit offers the note types to turn it into.</p><p>The same action is available as <em>Create a new child note</em> in the <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>. A child note of a protected note is protected too.</p><h2>Emoji</h2><figure class=\"image image-style-align-right image_resized\" style=\"width:42.4%;\"><img style=\"aspect-ratio:366/410;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Insert%20buttons_plus.png\" width=\"366\" height=\"410\"></figure><p>This feature allows inserting Unicode emoji characters. Simply select a category and a desired emoji to insert it.</p><p>Emojis can also be searched by their English name and the skin tone can be selected via a combo box to the right.</p><p>There is also the possibility of inserting emojis directly by typing <code>:</code> followed by a name of an emoji, triggering the display of a list of emojis. Simply use the arrow keys to select one and press <kbd>Enter</kbd> or <kbd>Tab</kbd> to insert it.</p><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/1_Insert%20buttons_plus.png\" width=\"272\" height=\"187\"><h2>Symbols</h2><figure class=\"image image-style-align-right\"><img style=\"aspect-ratio:346/322;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Insert%20buttons_image.png\" width=\"346\" height=\"322\"></figure><p>Pressing the&nbsp;<span class=\"tn-icon cke cke-special-characters\"></span> button will reveal a popup window displaying a list of characters that are generally more difficult to insert directly from the keyboard, such as a subset of emojis, quotation characters, etc.</p><p>Interaction:</p><ul><li>Click on a character to insert it at the current cursor position.</li><li>The window can be dragged around by the top bar where the title is, to avoid it getting in the way of the text.</li><li>Click on the <em>Category</em> selector to filter the characters.</li></ul><h2>Multicolumn layout</h2><p>See the dedicated&nbsp;<a class=\"reference-link\" href=\"#root/_help_wYDzQ1fBFgfT\">Multicolumn layout</a>&nbsp;page.</p><h2>Extended code block</h2><p>Choose <span class=\"tn-icon bx bx-code-block\"></span> <em>Extended code block</em> to insert a code block that is edited as a code note. This entry is experimental and is shown only once it is turned on. See <em>Extended code blocks</em> in&nbsp;<a class=\"reference-link\" href=\"#root/_help_QxEyIjRBizuC\">Code blocks</a>.</p><h2>Math equations</h2><p>See the dedicated&nbsp;<a class=\"reference-link\" href=\"#root/_help_YfYAtQBcfo5V\">Math Equations</a>&nbsp;page.</p><h2>Drawing canvas</h2><p>Choose <span class=\"tn-icon bx bx-pen\"></span> <em>Drawing canvas</em> to draw on an Excalidraw canvas inside the text. See <em>Drawing canvases</em> in <a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a>.</p><h2>Mermaid diagram</h2><p>Press the&nbsp;<span class=\"tn-icon cke cke-trilium-mermaid-insert\"></span> button to create an inline Mermaid diagram. The arrow next to it lists a template for each kind of diagram. The diagram is also available as <em>Mermaid diagram</em> in the&nbsp;<a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>.</p><p>This feature is quite similar to the&nbsp;<a class=\"reference-link\" href=\"#root/_help_s1aBHPd79XYj\">Mermaid Diagrams</a>&nbsp;note types and is meant as an alternative to it for simple diagrams. For more complex diagrams, use the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a>&nbsp;feature for a dedicated Mermaid note.</p><figure class=\"image\"><img style=\"aspect-ratio:1174/358;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/2_Insert%20buttons_image.png\" width=\"1174\" height=\"358\"></figure><p>A diagram shows in a box like the one of an included note, so it can be resized, given another box size (<em>Small</em>, <em>Medium</em> or <em>Full</em>) from its <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu or shown in fullscreen, as described in&nbsp;<a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a>.</p><ul><li>The <span class=\"tn-icon bx bx-edit-alt\"></span> <em>Editable</em> button at the start of the diagram's toolbar decides whether its source can be changed. While it is off, the source still shows, but read-only.</li><li>The buttons next to it choose what the diagram shows, as for a Mermaid note: <span class=\"tn-icon bx bx-code\"></span> <em>Source view</em> for the Mermaid source alone, <span class=\"tn-icon bx bxs-dock-left\"></span> <em>Split view</em> for the source with the diagram next to it, and <span class=\"tn-icon bx bx-show\"></span> <em>Preview</em> for the diagram alone. Its <em>More actions</em> menu offers the same choice.</li><li>The <em>Word wrap</em> and <em>Line numbers</em> submenus of its <em>More actions</em> menu change how the source shows, each with <em>Auto</em>, <em>On</em> and <em>Off</em>, as for an included code note (see <em>Editing an include in place</em> in <a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a>).</li><li>A new diagram starts editable, in <em>Split view</em>. The diagram updates a moment after you stop typing. If the source has an error, the error shows over the last diagram that worked, which stays dimmed, as in a Mermaid note. On desktop, drag the divider between the source and the diagram to resize them.</li><li>A diagram without a chosen view shows the source next to the diagram while it is editable, and the diagram alone otherwise. In a read-only note, the source can never be changed. A read-only note and the AI chat show a diagram in the same box, in the view it was saved with, and with the zoom buttons over the diagram instead of in a toolbar. A <em>Medium</em> or <em>Full</em> diagram also has a <span class=\"tn-icon bx bx-fullscreen\"></span> <em>Fullscreen</em> button there, or over the source in the <em>Source</em> view.</li><li>To zoom, use the <span class=\"tn-icon bx bx-zoom-out\"></span> and <span class=\"tn-icon bx bx-zoom-in\"></span> buttons of the diagram's toolbar; the zoom level between them resets the zoom. In fullscreen, where the toolbar is hidden, the same buttons show over the diagram. Drag the diagram to move around it, and double-click it to reset the view. The mouse wheel scrolls the note until you click the diagram, and then zooms it.</li><li>While the source shows, the <span class=\"tn-icon bx bx-help-circle\"></span> <em>Mermaid syntax help</em> button at the end of the toolbar opens the help on&nbsp;<a class=\"reference-link\" href=\"#root/_help_s1aBHPd79XYj\">Mermaid Diagrams</a>, which links to the Mermaid syntax.</li><li>The changes made to the source of a diagram are part of the undo history of the text note, in the order they were made. <kbd>Ctrl</kbd>+<kbd>Z</kbd> and <kbd>Ctrl</kbd>+<kbd>Y</kbd> undo and redo them from the source as well as from the text, as described in <em>Editing an include in place</em> in <a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a>.</li></ul><p>The source of the diagram stays in the note as a Mermaid code block, so the diagram is exported to Markdown as a <code>mermaid</code> code block that other applications can show.</p><p>Diagrams created in earlier versions keep the view they were saved with, and open editable.</p><h2>Horizontal ruler</h2><p>This feature will display a horizontal line, generally useful to separate different sections of the text. To do so, press the&nbsp;<span class=\"tn-icon cke cke-horizontal-line\"></span> button in the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>.</p><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/1_Insert%20buttons_image.png\" width=\"502\" height=\"95\"><p>Alternatively, it's possible to insert a horizontal ruler by typing <code>---</code>.</p><h2>Page break</h2><figure class=\"image image-style-align-right\"><img style=\"aspect-ratio:371/79;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/3_Insert%20buttons_image.png\" width=\"371\" height=\"79\"></figure><p>Page breaks provide a way to force the next paragraph or block (table, image, etc.) to be displayed onto the next page when printing (either to a real printer to <a href=\"#root/_help_NRnIZmSMc5sj\">when exporting to PDF</a>).</p><p>Page breaks are marked in the editor with the words <em>Page break</em>, but they will not actually be shown when printed.</p><ul><li>To insert a page break, press the&nbsp;<span class=\"tn-icon cke cke-page-break\"></span> in the formatting toolbar.</li><li>To insert many page breaks at once, insert a page break first, click on it and press <kbd>Ctrl</kbd>+<kbd>C</kbd>. Then use <kbd>Ctrl</kbd>+<kbd>V</kbd>, to paste as many times as needed.</li></ul><h2>Date and time</h2><p>The <span class=\"tn-icon cke cke-trilium-date-time\"></span> button inserts the current date and time at the cursor, replacing the selected text if there is any. The inserted text takes the formatting of the text around it, so a date inserted inside bold text is bold too.</p><ul><li>To insert the date in the default format, press the button itself or press <kbd>Alt</kbd>+<kbd>T</kbd>.</li><li>To insert it in another format, press the arrow next to the button and pick a format from the list. Each entry shows the current date and time in that format: the default one, the date or the time alone, the date written out, and ISO 8601.</li><li>The same formats are offered by the <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>: type <code>/date</code>, <code>/time</code>, <code>/now</code> or <code>/today</code>. The <em>Insert date/time</em> entry uses the default format, and shows what it inserts underneath; the other entries show their output in the title.</li></ul><p>The default format can be changed in <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Text Notes</em> → <em>Editor</em> → <em>Date/time format</em>, using <a href=\"https://day.js.org/docs/en/display/format\">Day.js format tokens</a> (for example <code>DD.MM.YYYY HH:mm</code>).</p><h2>Icons</h2><p>Icons just like the ones for the <a href=\"#root/_help_p9kXRFAkwN4o\">note icon</a> can be inserted in text. For more information see&nbsp;<a class=\"reference-link\" href=\"#root/_help_hD8GawVuazff\">Icons</a>.</p>",
"_help_hD8GawVuazff": "<p>Icons just like the <a href=\"#root/_help_hD8GawVuazff\">note icons</a> can be inserted in the content of a note, including from any other <a href=\"#root/_help_gOKqSJgXLcIj\">custom icon packs</a>.</p><h2>Features</h2><ul><li>The icon can be formatted through the<a class=\"reference-link\" href=\"#root/_help_Gr6xFaF6ioJ5\">General formatting</a>&nbsp;tools of the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>:<ul><li>Foreground/icon color</li><li>Background color/highlight</li><li>Font size</li></ul></li><li>Custom&nbsp;<a class=\"reference-link\" href=\"#root/_help_gOKqSJgXLcIj\">Icon Packs</a>&nbsp;are also supported.<ul><li>For emojis, prefer the Emoji functionality from&nbsp;<a class=\"reference-link\" href=\"#root/_help_CohkqWQC1iBv\">Insert buttons</a>.</li></ul></li><li>When an icon is clicked a floating toolbar appears with the following functions:<ul><li><span class=\"tn-icon bx bx-sticker\"></span>&nbsp;which changes the icon.</li><li><span class=\"tn-icon bx bx-reflect-horizontal\"></span>&nbsp;which applies transforms: rotate (90 / 180 / 270) and flip horizontal/vertical. Only one transform can be used per icon.</li></ul></li></ul><h2>Usage</h2><ul><li>The in-app help/user guide makes use of these icons in order to illustrate buttons in the UI.</li><li>The&nbsp;<a class=\"reference-link\" href=\"#root/_help_GnhlmrATVqcH\">Microsoft OneNote</a>&nbsp;importer also makes use of them for the&nbsp;<a class=\"reference-link\" href=\"#root/_help_LpvyEIBIAAj7\">Tags</a>.</li></ul><h2>Inserting an icon</h2><p>There are two ways to insert an icon:</p><ul><li>Via the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>&nbsp;look for the&nbsp;<span class=\"tn-icon bx bx-plus\"></span> icon and then the&nbsp;<span class=\"tn-icon bx bx-sticker\"></span> icon.</li><li>Via&nbsp;<a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>, type <code>/icon</code>.</li></ul><p>An icon picker will appear, search for an icon and click it to insert it in the document.</p><h2>Finding notes by their icons</h2><p>An icon can be <a href=\"#root/_help_eIg8jdvaoNNd\">searched</a>. A note containing a&nbsp;<span class=\"tn-icon bx bx-star\"></span> icon can be found by searching for <code>star</code>, or its <code>iconClass</code> (<code>bx-star</code>).</p><p>To find the name of the icon, hover the mouse over an icon while in the icon picker.</p><h2>Markdown rendering</h2><p>When exporting to&nbsp;<a class=\"reference-link\" href=\"#root/_help_Oau6X9rCuegd\">Markdown</a>, the item will render as raw HTML representation of the icon as is used by Trilium:</p><pre><code class=\"language-text-html\">&lt;span class=\"tn-icon bx bx-star\"&gt;&lt;/span&gt;</code></pre>",
"_help_oiVPnW8QfnvS": "<h2>Trilium-specific shortcuts</h2><figure class=\"table\"><table><thead><tr><th>Action</th><th>PC</th><th>Mac</th></tr></thead><tbody><tr><td>Bring up inline formatting toolbar (arrow keys ←,→ to navigate, Enter to apply)</td><td>Alt+F10</td><td>⌥+F10</td></tr><tr><td>Bring up block formatting toolbar</td><td>Alt+F10</td><td>⌥+F10</td></tr><tr><td>Create <a href=\"#root/_help_QEAPj01N5f7w\">external link</a></td><td>Ctrl+K</td><td>⌘+K</td></tr><tr><td>Create <a href=\"#root/_help_QEAPj01N5f7w\">internal (note) link</a></td><td>Ctrl+L</td><td>⌘+L</td></tr><tr><td>Inserts current date and time at caret position</td><td>Alt+T</td><td>⌥+T</td></tr><tr><td>Increase paragraph indentation</td><td>Tab</td><td>⇥</td></tr><tr><td>Decrease paragraph indentation</td><td>Shift + Tab</td><td>⇧ + ⇥</td></tr><tr><td>Mark selected text as <a href=\"#root/_help_UYuUB1ZekNQU\">keyboard shortcut</a></td><td>Ctrl + Alt + K</td><td>⌘+ ⌥+ K</td></tr><tr><td>Insert&nbsp;<a class=\"reference-link\" href=\"#root/_help_YfYAtQBcfo5V\">Math Equations</a></td><td>Ctrl + M</td><td>⌘+ M</td></tr><tr><td>Move blocks (lists, paragraphs, etc.) up, or in a <a href=\"#root/_help_NdowYOC1GFKS\">table</a> the rows</td><td>Alt+↑</td><td>⌥+↑</td></tr><tr><td>Move blocks (lists, paragraphs, etc.) down, or in a <a href=\"#root/_help_NdowYOC1GFKS\">table</a> the rows</td><td>Alt+↓</td><td>⌥+↓</td></tr><tr><td>Move the selected content to another column of a <a class=\"reference-link\" href=\"#root/_help_wYDzQ1fBFgfT\">Multicolumn layout</a></td><td>Ctrl+←, Ctrl+→, Ctrl+Shift+Home, Ctrl+Shift+End</td><td>⌘+←, ⌘+→, ⌘+⇧+Home, ⌘+⇧+End</td></tr><tr><td>Move the current column of a multicolumn layout</td><td>Ctrl+Alt+←, Ctrl+Alt+→, Ctrl+Alt+Home, Ctrl+Alt+End</td><td>⌘+⌥+←, ⌘+⌥+→, ⌘+⌥+Home, ⌘+⌥+End</td></tr><tr><td>Add a column after or before the current one in a multicolumn layout</td><td>Ctrl+Enter, Ctrl+Shift+Enter</td><td>⌘+Enter, ⌘+⇧+Enter</td></tr><tr><td>Move the selected content to another tab in <a class=\"reference-link\" href=\"#root/_help_EK2ckIZ74tbT\">Content tabs</a></td><td>Ctrl+←, Ctrl+→, Ctrl+Shift+Home, Ctrl+Shift+End</td><td>⌘+←, ⌘+→, ⌘+⇧+Home, ⌘+⇧+End</td></tr><tr><td>Move the current tab of a tabs block</td><td>Ctrl+Alt+←, Ctrl+Alt+→, Ctrl+Alt+Home, Ctrl+Alt+End</td><td>⌘+⌥+←, ⌘+⌥+→, ⌘+⌥+Home, ⌘+⌥+End</td></tr><tr><td>Add a tab after or before the current one in a tabs block</td><td>Ctrl+Enter, Ctrl+Shift+Enter</td><td>⌘+Enter, ⌘+⇧+Enter</td></tr></tbody></table></figure><h2>Common shortcuts</h2><aside class=\"admonition tip\"><p>This section of keyboard shortcuts presents a subset of the keyboard shortcuts as supported by the editor technology we are using,&nbsp;<a class=\"reference-link\" href=\"#root/_help_MI26XDLSAlCD\">CKEditor</a>. The shortcuts were taken from the <a href=\"https://ckeditor.com/docs/ckeditor5/latest/features/accessibility.html#keyboard-shortcuts\">official documentation</a>. Note that not all the shortcuts in the original documentation are applicable (due to using a different configuration).</p></aside><h3>Content editing</h3><figure class=\"table\"><table><thead><tr><th>Action</th><th>PC</th><th>Mac</th></tr></thead><tbody><tr><td>Insert a hard break (a new paragraph)</td><td>Enter</td><td></td></tr><tr><td>Insert a soft break (a <code>&lt;br&gt;</code> element)</td><td>Shift+Enter</td><td>⇧Enter</td></tr><tr><td>Copy selected content</td><td>Ctrl+C</td><td>⌘C</td></tr><tr><td>Paste content</td><td>Ctrl+V</td><td>⌘V</td></tr><tr><td>Paste content as plain text</td><td>Ctrl+Shift+V</td><td>⌘⇧V</td></tr><tr><td>Undo</td><td>Ctrl+Z</td><td>⌘Z</td></tr><tr><td>Redo</td><td>Ctrl+Y, Ctrl+Shift+Z</td><td>⌘Y, ⌘⇧Z</td></tr><tr><td>Bold text</td><td>Ctrl+B</td><td>⌘B</td></tr><tr><td>Change text case</td><td>Shift+F3</td><td>⇧F3 (may require Fn)</td></tr><tr><td>Create link</td><td>Ctrl+K</td><td>⌘K</td></tr><tr><td>Move out of a link</td><td>←←, →→</td><td></td></tr><tr><td>Move out of an inline code style</td><td>←←, →→</td><td></td></tr><tr><td>Select all</td><td>Ctrl+A</td><td>⌘A</td></tr><tr><td>Find in the document</td><td>Ctrl+F</td><td>⌘F</td></tr><tr><td>Copy text formatting</td><td>Ctrl+Shift+C</td><td>⌘⇧C</td></tr><tr><td>Paste text formatting</td><td>Ctrl+Shift+V</td><td>⌘⇧V</td></tr><tr><td>Italic text</td><td>Ctrl+I</td><td>⌘I</td></tr><tr><td>Strikethrough text</td><td>Ctrl+Shift+X</td><td>⌘⇧X</td></tr><tr><td>Underline text</td><td>Ctrl+U</td><td>⌘U</td></tr><tr><td>Revert autoformatting action</td><td>Backspace</td><td></td></tr></tbody></table></figure><h3>Interacting with blocks</h3><p>Blocks are images, tables, blockquotes, annotations.</p><figure class=\"table\"><table><thead><tr><th>Action</th><th>PC</th><th>Mac</th></tr></thead><tbody><tr><td>Insert a new paragraph directly after a widget</td><td>Enter</td><td></td></tr><tr><td>Insert a new paragraph directly before a widget</td><td>Shift+Enter</td><td>⇧Enter</td></tr><tr><td>Move the caret to allow typing directly before a widget</td><td>↑, ←</td><td></td></tr><tr><td>Move the caret to allow typing directly after a widget</td><td>↓, →</td><td></td></tr><tr><td>After entering a nested editable, move the selection to the closest ancestor widget. For example: move from an image caption to the whole image widget.</td><td>Tab then Esc</td><td></td></tr></tbody></table></figure><p>Specifically for lists:</p><figure class=\"table\"><table><thead><tr><th>Action</th><th>PC</th><th>Mac</th></tr></thead><tbody><tr><td>Increase list item indent</td><td>⇥</td><td></td></tr><tr><td>Decrease list item indent</td><td>Shift+⇥</td><td>⇧⇥</td></tr></tbody></table></figure><p>In tables:</p><figure class=\"table\"><table><thead><tr><th>Action</th><th>PC</th><th>Mac</th></tr></thead><tbody><tr><td>Move the selection to the next cell</td><td>⇥</td><td></td></tr><tr><td>Move the selection to the previous cell</td><td>Shift+⇥</td><td>⇧⇥</td></tr><tr><td>Insert a new table row (when in the last cell of a table)</td><td>⇥</td><td></td></tr><tr><td>Navigate through the table</td><td>↑, →, ↓, ←</td><td></td></tr></tbody></table></figure><h3>General UI shortcuts</h3><figure class=\"table\"><table><thead><tr><th>Action</th><th>PC</th><th>Mac</th></tr></thead><tbody><tr><td>Close contextual balloons, dropdowns, and dialogs</td><td>Esc</td><td></td></tr><tr><td>Open the accessibility help dialog</td><td>Alt+0</td><td>⌥0</td></tr><tr><td>Move focus between form fields (inputs, buttons, etc.)</td><td>⇥, Shift+⇥</td><td>⇥, ⇧⇥</td></tr><tr><td>Move focus to the toolbar, navigate between toolbars</td><td>Alt+F10</td><td>⌥F10 (may require Fn)</td></tr><tr><td>Navigate through the toolbar or menu bar</td><td>↑, →, ↓, ←</td><td></td></tr><tr><td>Navigate to the next focusable field or an element outside the editor</td><td>Tab, Shift+Tab</td><td></td></tr><tr><td>Execute the currently focused button. Executing buttons that interact with the editor content moves the focus back to the content.</td><td>Enter, Space</td><td></td></tr><tr><td>Move focus in and out of an active dialog window</td><td>Ctrl+F6</td><td>⌘F6 (may require Fn)</td></tr></tbody></table></figure>",
diff --git a/docs/User Guide/User Guide/Note Types/Text/Include Note.md b/docs/User Guide/User Guide/Note Types/Text/Include Note.md
index d78201da18..4dc282272c 100644
--- a/docs/User Guide/User Guide/Note Types/Text/Include Note.md
+++ b/docs/User Guide/User Guide/Note Types/Text/Include Note.md
@@ -42,7 +42,7 @@ A _Small_, _Medium_ or _Expandable_ include can be resized to any width and heig
* To resize an include, select it and drag the handle in its bottom-right corner. To change only the width or only the height, drag the middle of its right or bottom edge instead, where a touch screen shows a handle too. In right-to-left text, the handle is in the bottom-left corner and the width changes from the left edge.
* Resizing works with a mouse, a pen or a finger.
* While the height changes, moving the handle near the top or the bottom of the note scrolls the note.
-* An include narrower than the note is centered, so changing its width moves both of its sides. Making it as wide as the note returns it to the full width.
+* An include narrower than the note is centered, so changing its width moves both of its sides. A drawing aligned to the left or the right keeps that side in place and has its handles on the other side (see _Positioning a drawing_ below). Making an include as wide as the note returns it to the full width.
* To cancel a resize, press <kbd>Esc</kbd> before releasing the handle.
* To reset the size, double-click the corner handle, or double-tap it on a touch screen. Double-clicking the right or bottom edge resets only the width or the height.
* Choosing a box size resets the height. Choosing _Tiny_ or _Full_ resets the width too.
@@ -91,7 +91,7 @@ Content added by a newer version of Trilium, which this version cannot show, app
## Included notes in the share functionality
-If a [shared note](../../Advanced%20Usage/Sharing.md) contains one or more included notes, they will be displayed in the content of the note as if they were part of the note itself. The caption of an include is shown under the included content. A _Tiny_ include is shown as a link to the included note instead, and so is an include that would show a note already shown around it, such as a note that includes itself. The same goes for a printed or exported note.
+If a [shared note](../../Advanced%20Usage/Sharing.md) contains one or more included notes, they will be displayed in the content of the note as if they were part of the note itself. An include resized narrower than the note keeps its width, and a drawing its position. On a narrow screen, a drawing with a position other than _Align center_ takes the full width. The caption of an include is shown under the included content. A _Tiny_ include is shown as a link to the included note instead, and so is an include that would show a note already shown around it, such as a note that includes itself. The same goes for a printed or exported note.
For this to work, the included notes must also be shared. However, they can still be hidden from the note tree via `#shareHiddenFromTree`.
@@ -168,11 +168,21 @@ A drawing canvas is an Excalidraw canvas, like the one of a <a class="reference-
* The changes to the drawing are part of the undo history of the text note (see _Editing an include in place_ above). <kbd>Ctrl</kbd>+<kbd>Z</kbd>, <kbd>Ctrl</kbd>+<kbd>Y</kbd> and the <span class="tn-icon bx bx-undo"></span> _Undo_ and <span class="tn-icon bx bx-redo"></span> _Redo_ buttons of the canvas toolbar undo and redo the last change of the note, in the drawing or in the text.
* A new drawing has the background color of the note. A background chosen from the Excalidraw menu replaces it.
* To protect a finished drawing from accidental changes, select it and turn off the <span class="tn-icon bx bx-edit-alt"></span> _Editable_ button at the start of its toolbar, or uncheck _Editable_ in its <span class="tn-icon cke cke-three-vertical-dots"></span> _More actions_ menu. The drawing then shows as a still picture, at the zoom and position it had, and can no longer be changed, zoomed or moved. To draw again, turn _Editable_ back on.
-* The box sizes, resizing, the caption and the title work as for an included note, but the toolbar of a drawing leaves the box size, _Show title_ and _Convert to link_ to its _More actions_ menu.
+* The box sizes, resizing, the caption and the title work as for an included note, but the toolbar of a drawing leaves the box size, _Show title_ and _Convert to link_ to its _More actions_ menu, which also sets its position (see _Positioning a drawing_ below).
* In the desktop layout, Excalidraw keeps its desktop interface however small the box is. In the mobile layout, a narrow or short box switches it to a compact interface. For more room, choose _Full_, or show the title and press <span class="tn-icon bx bx-fullscreen"></span> _Fullscreen_.
* Pictures added to the drawing are stored in the same attachment. A converted image is kept as an image attachment of the note instead, named with a generated code.
* In a [read-only note](../../Basic%20Concepts%20and%20Features/Notes/Read-Only%20Notes.md), the drawing shows as a still picture too.
-* On a [shared page](../../Advanced%20Usage/Sharing.md), the drawing is shown as a picture at its own size, whatever the size of its box, in light or dark colors to match the page. Each change to the drawing saves this picture as an SVG image attachment of the note, also named with a generated code.
+* On a [shared page](../../Advanced%20Usage/Sharing.md), the drawing is shown as a picture at its own size, up to the width its box was resized to, in light or dark colors to match the page. Each change to the drawing saves this picture as an SVG image attachment of the note, also named with a generated code.
+
+### Positioning a drawing
+
+A drawing can sit on lines of its own or have the text wrap around it, as an [image](Images.md) can.
+
+* To change the position, select the drawing, open its <span class="tn-icon cke cke-three-vertical-dots"></span> _More actions_ menu and choose an entry of its _Position_ submenu:
+ * Under _Break text_, <span class="tn-icon cke cke-object-left"></span> _Align left_, <span class="tn-icon cke cke-object-center"></span> _Align center_ and <span class="tn-icon cke cke-object-right"></span> _Align right_ place the drawing on lines of its own, at that side of the note. _Align center_ is the default.
+ * Under _Wrap text_, <span class="tn-icon cke cke-object-inline-left"></span> _Align left_ and <span class="tn-icon cke cke-object-inline-right"></span> _Align right_ place the drawing at that side and let the text run beside it.
+* A drawing is inserted at the full width of the note, so a new position shows once the drawing is resized narrower (see _Resizing_ above). The position is kept whatever the box size, and shows again when a _Small_, _Medium_ or _Expandable_ box is resized.
+* In the mobile layout, a drawing with a position other than _Align center_ takes the full width, and only its height can be resized.
### Limitations
diff --git a/packages/ckeditor5/src/augmentation.ts b/packages/ckeditor5/src/augmentation.ts
index 9188ff820a..2fa0b5f03a 100644
--- a/packages/ckeditor5/src/augmentation.ts
+++ b/packages/ckeditor5/src/augmentation.ts
@@ -51,8 +51,8 @@ declare global {
/** An item of the embed toolbar that the content of an embed can hide. */
type ContentEmbedToolbarItem =
- "contentEmbedBoxSizeDropdown" | "toggleContentEmbedTitle" | "convertEmbedToLink"
- | "toggleContentEmbedEditable";
+ "contentEmbedBoxSizeDropdown" | "contentEmbedPositionDropdown" | "toggleContentEmbedTitle"
+ | "convertEmbedToLink" | "toggleContentEmbedEditable";
/** The buttons that the content of an embed, such as a canvas drawing, adds to its toolbar. */
interface ContentEmbedToolProvider {
@@ -79,6 +79,11 @@ declare global {
* menu of the embed then switch. The embed carries the mode as `data-display-mode`.
*/
hasDisplayModes?: boolean;
+ /**
+ * Whether the content can be positioned in the text, which the toolbar and the menu of the
+ * embed then set. The embed saves a position other than centered as `data-position`.
+ */
+ hasPositions?: boolean;
}
}
diff --git a/packages/ckeditor5/src/index.ts b/packages/ckeditor5/src/index.ts
index 241ec5fb34..d2463a5ec7 100644
--- a/packages/ckeditor5/src/index.ts
+++ b/packages/ckeditor5/src/index.ts
@@ -18,7 +18,7 @@ export type { ImageEditingSourceConfig } from "./plugins/image_editing_source.js
export type { FileUploadData, FileUploadEvent } from "./plugins/file_upload/fileuploadediting.js";
export type { PasteTarget } from "./plugins/cuttonote.js";
export type {
- ContentEmbedCodeView, ContentEmbedState
+ ContentEmbedCodeView, ContentEmbedState, PositionValue
} from "./plugins/content_embed/content_embed.js";
export type { EmbedEdge } from "./plugins/content_embed/content_embed_caret.js";
export { default as EmbedHistory } from "./plugins/content_embed/embed_history.js";
diff --git a/packages/ckeditor5/src/plugins.ts b/packages/ckeditor5/src/plugins.ts
index 1a1231994d..d20d6701eb 100644
--- a/packages/ckeditor5/src/plugins.ts
+++ b/packages/ckeditor5/src/plugins.ts
@@ -65,6 +65,8 @@ import AdmonitionTypeDropdown from "./plugins/admonition/admonition_type_dropdow
import AdmonitionToolbar from "./plugins/admonition/admonition_toolbar.js";
import ContentEmbedBoxSizeDropdown
from "./plugins/content_embed/content_embed_box_size_dropdown.js";
+import ContentEmbedPositionDropdown
+ from "./plugins/content_embed/content_embed_position_dropdown.js";
import ContentEmbedToolbar from "./plugins/content_embed/content_embed_toolbar.js";
import ContentEmbedCaret from "./plugins/content_embed/content_embed_caret.js";
import ExtendedCodeBlock from "./plugins/content_embed/extended_code_block.js";
@@ -127,6 +129,7 @@ const TRILIUM_PLUGINS: typeof Plugin[] = [
AdmonitionTypeDropdown,
AdmonitionToolbar,
ContentEmbedBoxSizeDropdown,
+ ContentEmbedPositionDropdown,
ContentEmbedToolbar,
ContentEmbedCaret,
ExtendedCodeBlock,
diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed.spec.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed.spec.ts
index 8ce305cc73..b3c87ecc58 100644
--- a/packages/ckeditor5/src/plugins/content_embed/content_embed.spec.ts
+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed.spec.ts
@@ -37,6 +37,7 @@ import ContentEmbed, {
CONTENT_EMBED_MENU,
DISPLAY_MODE_BUTTONS,
DISPLAY_MODES,
+ POSITION_COMMAND_NAME,
TOGGLE_CAPTION_COMMAND_NAME,
TOGGLE_EDITABLE_COMMAND_NAME,
TOGGLE_TITLE_COMMAND_NAME
@@ -1013,7 +1014,9 @@ describe("ContentEmbed with attachments", () => {
const states = [ embed, note, tiny, unsized ]
.map((wrapper) => plugin.getEmbedStateAt(wrapper));
- const notEditable = { isEditable: false, isEditableToggleable: false, displayMode: null };
+ const notEditable = {
+ isEditable: false, isEditableToggleable: false, displayMode: null, position: null
+ };
expect(states).toEqual([ {
...notEditable, boxSize: "small", isTitleShown: true, isTitleToggleable: true,
hasCaption: false, isCaptionToggleable: true, isConvertibleToLink: true
@@ -1903,6 +1906,124 @@ describe("ContentEmbed display mode", () => {
});
});
+describe("ContentEmbed position", () => {
+ const WRAPPED = "<figure class=\"include-note\" data-attachment-id=\"a1\""
+ + " data-box-size=\"medium\" data-position=\"wrap-left\">&nbsp;</figure>";
+ let editor: ClassicEditor;
+ let getContentEmbedTools: ReturnType<typeof vi.fn>;
+
+ beforeEach(async () => {
+ getContentEmbedTools = vi.fn(() => ({ hasPositions: true }));
+ editor = await createTestEditor([ Essentials, Paragraph, Undo, Widget, ContentEmbed ], {
+ contentEmbed: { getTools: getContentEmbedTools }
+ });
+ });
+
+ function getCommand() {
+ const command = editor.commands.get(POSITION_COMMAND_NAME);
+ if (!command) {
+ throw new Error("Expected the position command.");
+ }
+ return command;
+ }
+
+ function getRenderedEmbed() {
+ const embed = editor.editing.view.getDomRoot()
+ ?.querySelector<HTMLElement>("figure.include-note");
+ if (!embed) {
+ throw new Error("Expected a rendered embed.");
+ }
+ return embed;
+ }
+
+ /** The position of the rendered embed, and the edge that its resize handles grow from. */
+ function getRendered() {
+ const embed = getRenderedEmbed();
+ const anchor = [ "left", "right" ]
+ .find((edge) => embed.classList.contains(`ck-widget_resize-anchor-${edge}`));
+ return [ embed.getAttribute("data-position"), anchor ?? null ];
+ }
+
+ it("loads and saves the position, and drops centered or an unknown one", () => {
+ editor.setData(WRAPPED);
+ expect(getModelData(editor.model, { withoutSelection: true }))
+ .toContain("position=\"wrap-left\"");
+ expect(editor.getData()).toBe(WRAPPED);
+ expect(getRendered()).toEqual([ "wrap-left", "left" ]);
+
+ for (const value of [ "center", "other" ]) {
+ editor.setData(WRAPPED.replace("wrap-left", value));
+ expect(getModelData(editor.model, { withoutSelection: true }), value)
+ .not.toContain("position");
+ expect(getRendered(), value).toEqual([ null, null ]);
+ }
+ });
+
+ it("sets the position as one undo step, keeping the content, and centered removes it", () => {
+ insertContentEmbed(editor, "n1", "medium");
+ const wrapper = getRenderedEmbed().querySelector(".include-note-wrapper");
+ expect([ getCommand().isEnabled, getCommand().value ]).toEqual([ true, "center" ]);
+ expect(getRendered()).toEqual([ null, null ]);
+
+ editor.execute(POSITION_COMMAND_NAME, { value: "wrap-right" });
+ expect(getCommand().value).toBe("wrap-right");
+ expect(getRendered()).toEqual([ "wrap-right", "right" ]);
+ expect(editor.getData()).toContain("data-position=\"wrap-right\"");
+
+ editor.execute(POSITION_COMMAND_NAME, { value: "left" });
+ expect(getRendered()).toEqual([ "left", "left" ]);
+ editor.execute(POSITION_COMMAND_NAME, { value: "right" });
+ expect(getRendered()).toEqual([ "right", "right" ]);
+
+ editor.execute(POSITION_COMMAND_NAME, { value: "center" });
+ expect(getCommand().value).toBe("center");
+ expect(getRendered()).toEqual([ null, null ]);
+ expect(editor.getData()).not.toContain("data-position");
+
+ editor.execute("undo");
+ expect(getCommand().value).toBe("right");
+ expect(getRenderedEmbed().querySelector(".include-note-wrapper")).toBe(wrapper);
+ });
+
+ it("works at every box size, and keeps the position through a change of it", () => {
+ insertContentEmbed(editor, "n1", "medium");
+ editor.execute(POSITION_COMMAND_NAME, { value: "wrap-left" });
+
+ for (const boxSize of BOX_SIZES) {
+ editor.execute(BOX_SIZE_COMMAND_NAME, { value: boxSize });
+ expect([ getCommand().isEnabled, getCommand().value ], boxSize)
+ .toEqual([ true, "wrap-left" ]);
+ expect(getRendered(), boxSize).toEqual([ "wrap-left", "left" ]);
+ }
+ });
+
+ it("is offered only for content that has positions", () => {
+ insertContentEmbed(editor, "n1", "medium");
+ const contentEmbed = editor.plugins.get(ContentEmbed);
+ expect(contentEmbed.getEmbedStateAt(getRenderedEmbed()))
+ .toMatchObject({ position: "center" });
+
+ getContentEmbedTools.mockReturnValue({ hasEditableFlag: true });
+ editor.ui.update();
+ expect([ getCommand().isEnabled, getCommand().value ]).toEqual([ false, null ]);
+ expect(contentEmbed.getEmbedStateAt(getRenderedEmbed())).toMatchObject({ position: null });
+ });
+
+ it("changes nothing when no embed is selected", () => {
+ editor.setData(WRAPPED + "<p>after</p>");
+ setModelData(editor.model, "<paragraph>foo[]bar</paragraph>");
+ const before = editor.getData();
+
+ // The decorated `Command#execute()` skips a disabled command, so the command is forced
+ // enabled to run `execute()` with no embed selected.
+ const command = getCommand();
+ command.isEnabled = true;
+ command.execute({ value: "right" });
+
+ expect(editor.getData()).toBe(before);
+ });
+});
+
describe("ContentEmbed resizing", () => {
const RESIZED = "<figure class=\"include-note\""
+ " style=\"--include-note-height:12.5em;--include-note-width:30em;\""
diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed.ts
index daf79738fe..ae5d102723 100644
--- a/packages/ckeditor5/src/plugins/content_embed/content_embed.ts
+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed.ts
@@ -33,7 +33,9 @@ import {
encodeBlockParameter, EXTENDED_CODE_BLOCK_CLASS, normalizeMimeTypeForCKEditor, parseBlockRange
} from '@triliumnext/commons';
import { getAttachmentId, getNoteId } from '../referencelink.js';
-import ResizableWidgets, { SIZE_ATTRIBUTES } from '../resizable_widgets/resizable_widgets.js';
+import ResizableWidgets, {
+ type ResizeAnchor, SIZE_ATTRIBUTES
+} from '../resizable_widgets/resizable_widgets.js';
import { restoreRendererFocusOnInput } from '../widget_utils.js';
import type { EmbedEdge } from './content_embed_caret.js';
import EmbedHistory from './embed_history.js';
@@ -52,6 +54,7 @@ export const TOGGLE_TITLE_COMMAND_NAME = 'toggleContentEmbedTitle';
export const TOGGLE_EDITABLE_COMMAND_NAME = 'toggleContentEmbedEditable';
export const CODE_VIEW_COMMAND_NAME = 'setContentEmbedCodeView';
export const CONTENT_EMBED_DISPLAY_MODE_COMMAND = 'contentEmbedDisplayMode';
+export const POSITION_COMMAND_NAME = 'contentEmbedPosition';
/** The toolbar separator between the Editable toggle and the display modes. */
export const CONTENT_EMBED_DISPLAY_MODE_SEPARATOR = 'contentEmbedDisplayModeSeparator';
/** The toolbar button that opens the context menu of an embed whose title is hidden. */
@@ -85,6 +88,17 @@ const DISPLAY_MODE_ICONS: Record<DisplayModeValue, string> = {
preview: showIcon
};
+/**
+ * Where an embed is placed in the text: on lines of its own, at the left, the center or the right
+ * ("Break text"), or with the text wrapped around it, at the left or the right ("Wrap text").
+ */
+export const POSITIONS = [ 'left', 'center', 'right', 'wrap-left', 'wrap-right' ] as const;
+
+export type PositionValue = typeof POSITIONS[number];
+
+/** The positions that an embed saves as `data-position`. Centered, the default, saves nothing. */
+const SAVED_POSITIONS: unknown[] = [ 'left', 'right', 'wrap-left', 'wrap-right' ];
+
/** The box sizes that can be resized. Tiny and Full fit their content. */
const RESIZABLE_BOX_SIZES: unknown[] = [ 'small', 'medium', 'expandable' ];
@@ -134,6 +148,8 @@ export interface ContentEmbedState {
/** What the content shows, for content that has display modes, otherwise `null`. */
displayMode: DisplayModeValue | null;
boxSize: BoxSizeValue | null;
+ /** Where the embed is placed in the text, for content that has positions, otherwise `null`. */
+ position: PositionValue | null;
/** Whether the title shows, which a Tiny or an Expandable embed always does. */
isTitleShown: boolean;
isTitleToggleable: boolean;
@@ -250,6 +266,7 @@ export default class ContentEmbed extends Plugin {
? getEmbedDisplayMode( editor, embed )
: null,
boxSize: embed.getAttribute( 'boxSize' ) as BoxSizeValue | undefined ?? null,
+ position: hasEmbedPositions( editor, embed ) ? getEmbedPosition( embed ) : null,
isTitleShown: !isTitleToggleable || !embed.getAttribute( 'hideTitle' ),
isTitleToggleable,
hasCaption: !!getCaption( embed ),
@@ -501,7 +518,7 @@ class ContentEmbedEditing extends Plugin {
propertyPrefix: '--include-note',
isWidthResizable: true,
isHeightResizable: true,
- isCentered: true,
+ getAnchor: getResizeAnchor,
heightTarget: '.include-note-content',
minWidth: MIN_EMBED_SIZE.width,
minHeight: MIN_EMBED_SIZE.height,
@@ -520,6 +537,7 @@ class ContentEmbedEditing extends Plugin {
commands.add( CODE_VIEW_COMMAND_NAME, new SetContentEmbedCodeViewCommand( editor ) );
commands.add(
CONTENT_EMBED_DISPLAY_MODE_COMMAND, new ContentEmbedDisplayModeCommand( editor ) );
+ commands.add( POSITION_COMMAND_NAME, new ContentEmbedPositionCommand( editor ) );
editor.model.document.registerPostFixer( writer => this.removeTinyCaptions( writer ) );
@@ -555,7 +573,7 @@ class ContentEmbedEditing extends Plugin {
// `FileUploadEditing` is uploading carries the upload attributes instead of its id.
allowAttributes: [
'noteId', 'block', 'attachmentId', 'boxSize', 'hideTitle', 'editable',
- 'displayMode', 'uploadId', 'uploadStatus', 'uploadFileName',
+ 'displayMode', 'position', 'uploadId', 'uploadStatus', 'uploadFileName',
...CODE_VIEW_ATTRIBUTES.map( ( [ setting ] ) => setting )
],
@@ -594,6 +612,7 @@ class ContentEmbedEditing extends Plugin {
boxSize: viewElement.getAttribute( 'data-box-size' ),
...getFlagsOfView( viewElement ),
...getDisplayModeOfView( viewElement ),
+ ...getPositionOfView( viewElement ),
...getCodeViewOfView( viewElement )
} );
},
@@ -612,6 +631,7 @@ class ContentEmbedEditing extends Plugin {
'data-box-size': modelElement.getAttribute( 'boxSize' ),
...getFlagAttributes( modelElement ),
...getDisplayModeAttributes( modelElement ),
+ ...getPositionAttributes( modelElement ),
...getCodeViewAttributes( modelElement )
} );
}
@@ -631,6 +651,7 @@ class ContentEmbedEditing extends Plugin {
'data-box-size': boxSize,
...getFlagAttributes( modelElement ),
...getDisplayModeAttributes( modelElement ),
+ ...getPositionAttributes( modelElement ),
...getCodeViewAttributes( modelElement )
} );
@@ -691,10 +712,10 @@ class ContentEmbedEditing extends Plugin {
// Marks the view of the embed without drawing the content again. Content with an
// editable mode reads `data-editable` from the embed, content with display modes
// `data-display-mode`, a code file the `data-code-*` attributes, and an extended code
- // block `data-language`.
+ // block `data-language`. The stylesheet places the embed by `data-position`.
const markedAttributes = [
...FLAG_ATTRIBUTES, DISPLAY_MODE_ATTRIBUTE, ...CODE_VIEW_ATTRIBUTES,
- [ 'language', 'data-language' ] as const
+ [ 'language', 'data-language' ] as const, [ 'position', 'data-position' ] as const
];
for ( const [ attribute, dataAttribute ] of markedAttributes ) {
dispatcher.on( `attribute:${ attribute }:contentEmbed`, ( _evt, data, api ) => {
@@ -1035,6 +1056,43 @@ export class ContentEmbedDisplayModeCommand extends Command {
}
}
+/**
+ * Sets where the selected embed is placed in the text, for content that has positions. Centered
+ * removes the position.
+ */
+export class ContentEmbedPositionCommand extends Command {
+ /** The position of the selected embed, or `null`. */
+ declare value: PositionValue | null;
+
+ constructor( editor: Editor ) {
+ super( editor );
+ // Content declares its positions once it renders, which changes nothing in the model.
+ this.listenTo( editor.ui, 'update', () => this.refresh(), { priority: 'high' } );
+ }
+
+ override refresh() {
+ const embed = getSelectedContentEmbed( this.editor );
+
+ this.isEnabled = !!embed && hasEmbedPositions( this.editor, embed );
+ this.value = embed && this.isEnabled ? getEmbedPosition( embed ) : null;
+ }
+
+ override execute( { value }: { value: PositionValue } ) {
+ const embed = getSelectedContentEmbed( this.editor );
+ if ( !embed ) {
+ return;
+ }
+
+ this.editor.model.change( writer => {
+ if ( SAVED_POSITIONS.includes( value ) ) {
+ writer.setAttribute( 'position', value, embed );
+ } else {
+ writer.removeAttribute( 'position', embed );
+ }
+ } );
+ }
+}
+
/**
* The model attribute to set for `language`, a MIME type: `language` for an extended code block,
* which always has one, otherwise `codeLanguage`, the language that a code file shows in.
@@ -1239,6 +1297,26 @@ export function toDisplayMode( value: unknown ): DisplayModeValue | null {
return DISPLAY_MODES.find( mode => mode === value ) ?? null;
}
+/** Whether the content of `embed` can be positioned, which its content type opts in to. */
+function hasEmbedPositions( editor: Editor, embed: ModelElement ) {
+ return !!getEmbedTools( editor, embed )?.hasPositions;
+}
+
+/** Where `embed` is placed in the text: its saved position, or centered. */
+function getEmbedPosition( embed: ModelElement ): PositionValue {
+ const position = embed.getAttribute( 'position' );
+ return SAVED_POSITIONS.includes( position ) ? position as PositionValue : 'center';
+}
+
+/** The edge of `embed` that stays in place while it is resized, as the stylesheet places it. */
+function getResizeAnchor( embed: ModelElement ): ResizeAnchor {
+ const position = getEmbedPosition( embed );
+ if ( position === 'left' || position === 'wrap-left' ) {
+ return 'left';
+ }
+ return position === 'right' || position === 'wrap-right' ? 'right' : 'center';
+}
+
/** Whether `embed` can have a caption. A Tiny embed has none. */
function isEmbedCaptionToggleable( editor: Editor, embed: ModelElement ) {
return embed.getAttribute( 'boxSize' ) !== 'tiny' && !isInlineSourceEmbed( embed )
@@ -1353,6 +1431,18 @@ export function getDisplayModeOfView(
return mode ? { displayMode: mode } : {};
}
+/** The `data-position` attribute of `element`, when it is not centered. */
+export function getPositionAttributes( element: ModelElement ): Record<string, string> {
+ const position = getEmbedPosition( element );
+ return position === 'center' ? {} : { 'data-position': position };
+}
+
+/** The position in the `data-position` attribute of a saved embed, when not centered. */
+export function getPositionOfView( viewElement: ViewElement ): { position?: PositionValue } {
+ const position = viewElement.getAttribute( 'data-position' );
+ return SAVED_POSITIONS.includes( position ) ? { position: position as PositionValue } : {};
+}
+
/** Whether the content of the selected embed, whose buttons are `tools`, hides `name`. */
export function isToolbarItemHidden(
tools: ContentEmbedToolProvider | null,
diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed_position_dropdown.spec.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed_position_dropdown.spec.ts
new file mode 100644
index 0000000000..59f150aee2
--- /dev/null
+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed_position_dropdown.spec.ts
@@ -0,0 +1,122 @@
+import {
+ type ClassicEditor, DropdownView, Essentials, Image, ImageStyle, type ModelElement, Paragraph,
+ Widget
+} from "ckeditor5";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+
+import { getListRow, getListRows, pickListRow } from "../../../test/dropdown-kit.js";
+import { createTestEditor } from "../../../test/editor-kit.js";
+import { POSITION_COMMAND_NAME } from "./content_embed.js";
+import ContentEmbedPositionDropdown, {
+ CONTENT_EMBED_POSITION_DROPDOWN
+} from "./content_embed_position_dropdown.js";
+
+describe("ContentEmbedPositionDropdown", () => {
+ let editor: ClassicEditor;
+ let tools: ContentEmbedToolProvider | null;
+
+ beforeEach(async () => {
+ tools = createTools();
+ editor = await createTestEditor([
+ Essentials, Paragraph, Widget, Image, ImageStyle, ContentEmbedPositionDropdown
+ ], {
+ contentEmbed: { getTools: () => tools }
+ });
+ });
+
+ function createDropdown() {
+ const dropdown = editor.ui.componentFactory.create(CONTENT_EMBED_POSITION_DROPDOWN);
+ if (!(dropdown instanceof DropdownView)) {
+ throw new Error("Expected the position dropdown.");
+ }
+ dropdown.render();
+ return dropdown;
+ }
+
+ function insertEmbed(): ModelElement {
+ let embed: ModelElement | null = null;
+ editor.model.change((writer) => {
+ const root = editor.model.document.getRoot();
+ if (!root) {
+ throw new Error("The editor has no root.");
+ }
+ embed = writer.createElement("contentEmbed", { noteId: "n1", boxSize: "medium" });
+ writer.insert(embed, root, 0);
+ writer.setSelection(embed, "on");
+ });
+ if (!embed) {
+ throw new Error("Expected an embed.");
+ }
+ return embed;
+ }
+
+ it("lists the positions under the way text runs around the embed, the current one on", () => {
+ const dropdown = createDropdown();
+ insertEmbed();
+
+ expect(dropdown.buttonView).toMatchObject({ label: "Box position", tooltip: true });
+ expect(getListRows(dropdown)).toStrictEqual([
+ "# Break text", "Align left", "Align center ✓", "Align right",
+ "# Wrap text", "Align left", "Align right"
+ ]);
+ });
+
+ it("shows the icons of the image positions", () => {
+ const dropdown = createDropdown();
+ insertEmbed();
+ const styles = editor.plugins.get("ImageStyleEditing").normalizedStyles ?? [];
+ const getStyleIcon = (name: string) => styles.find((style) => style.name === name)?.icon;
+
+ expect([
+ getListRow(dropdown, "Break text", "Align left").icon,
+ getListRow(dropdown, "Break text", "Align center").icon,
+ getListRow(dropdown, "Break text", "Align right").icon,
+ getListRow(dropdown, "Wrap text", "Align left").icon,
+ getListRow(dropdown, "Wrap text", "Align right").icon
+ ]).toEqual([
+ getStyleIcon("alignBlockLeft"), getStyleIcon("alignCenter"),
+ getStyleIcon("alignBlockRight"), getStyleIcon("alignLeft"), getStyleIcon("alignRight")
+ ]);
+ expect(dropdown.buttonView.icon).toBe(getStyleIcon("alignCenter"));
+ });
+
+ it("sets the position picked, shows it on its button and focuses the editor", () => {
+ const dropdown = createDropdown();
+ const embed = insertEmbed();
+ const focus = vi.spyOn(editor.editing.view, "focus");
+
+ pickListRow(dropdown, "Wrap text", "Align right");
+ expect(embed.getAttribute("position")).toBe("wrap-right");
+ expect(focus).toHaveBeenCalled();
+ expect(dropdown.buttonView.icon)
+ .toBe(getListRow(dropdown, "Wrap text", "Align right").icon);
+ expect(editor.commands.get(POSITION_COMMAND_NAME)?.value).toBe("wrap-right");
+ });
+
+ it("shows for content that has positions, unless the content hides it", () => {
+ const dropdown = createDropdown();
+ const isShown = () => !dropdown.element?.classList.contains("ck-hidden");
+ expect(isShown()).toBe(false);
+
+ insertEmbed();
+ expect([ isShown(), dropdown.isEnabled ]).toEqual([ true, true ]);
+
+ tools = createTools({ hiddenToolbarItems: [ CONTENT_EMBED_POSITION_DROPDOWN ] });
+ editor.ui.update();
+ expect(isShown()).toBe(false);
+
+ tools = null;
+ editor.ui.update();
+ expect([ isShown(), dropdown.isEnabled ]).toEqual([ false, false ]);
+ });
+});
+
+function createTools(options: Partial<ContentEmbedToolProvider> = {}): ContentEmbedToolProvider {
+ return {
+ hasPositions: true,
+ getTools: () => [],
+ execute: () => {},
+ subscribe: () => () => {},
+ ...options
+ };
+}
diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed_position_dropdown.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed_position_dropdown.ts
new file mode 100644
index 0000000000..db94b36272
--- /dev/null
+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed_position_dropdown.ts
@@ -0,0 +1,76 @@
+import {
+ type Command, IconObjectCenter, IconObjectInlineLeft, IconObjectInlineRight, IconObjectLeft,
+ IconObjectRight, Plugin
+} from "ckeditor5";
+
+import { createPositionDropdown } from "../position_dropdown.js";
+import ContentEmbed, { isToolbarItemHidden, POSITION_COMMAND_NAME } from "./content_embed.js";
+
+export const CONTENT_EMBED_POSITION_DROPDOWN = "contentEmbedPositionDropdown";
+
+/**
+ * The toolbar dropdown that sets where an embed is placed in the text, with the rows and icons of
+ * the image position dropdown. Shown for content that has positions and does not hide it.
+ */
+export default class ContentEmbedPositionDropdown extends Plugin {
+
+ static get requires() {
+ return [ ContentEmbed ] as const;
+ }
+
+ static get pluginName() {
+ return "ContentEmbedPositionDropdown" as const;
+ }
+
+ init() {
+ const editor = this.editor;
+ const t = editor.t;
+ const command = editor.commands.get(POSITION_COMMAND_NAME) as Command;
+ const contentEmbed = editor.plugins.get(ContentEmbed);
+
+ editor.ui.componentFactory.add(CONTENT_EMBED_POSITION_DROPDOWN, (locale) => {
+ const dropdown = createPositionDropdown(editor, locale, {
+ commandName: POSITION_COMMAND_NAME,
+ label: t("Box position"),
+ groups: [
+ {
+ label: t("Break text"),
+ rows: [
+ { value: "left", label: t("Align left"), icon: IconObjectLeft },
+ { value: "center", label: t("Align center"), icon: IconObjectCenter },
+ { value: "right", label: t("Align right"), icon: IconObjectRight }
+ ]
+ },
+ {
+ label: t("Wrap text"),
+ rows: [
+ {
+ value: "wrap-left", label: t("Align left"),
+ icon: IconObjectInlineLeft
+ },
+ {
+ value: "wrap-right", label: t("Align right"),
+ icon: IconObjectInlineRight
+ }
+ ]
+ }
+ ]
+ });
+ dropdown.bind("class").to(
+ command, "isEnabled", contentEmbed, "selectedEmbedTools",
+ (isEnabled, tools) => {
+ const isShown = isEnabled
+ && !isToolbarItemHidden(tools, CONTENT_EMBED_POSITION_DROPDOWN);
+ return isShown ? undefined : "ck-hidden";
+ }
+ );
+ return dropdown;
+ });
+ }
+}
+
+declare module "ckeditor5" {
+ interface PluginsMap {
+ [ ContentEmbedPositionDropdown.pluginName ]: ContentEmbedPositionDropdown;
+ }
+}
diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed_toolbar.spec.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed_toolbar.spec.ts
index 06db6b353b..c71414dd8c 100644
--- a/packages/ckeditor5/src/plugins/content_embed/content_embed_toolbar.spec.ts
+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed_toolbar.spec.ts
@@ -11,6 +11,7 @@ import ContentEmbed, {
TOGGLE_TITLE_COMMAND_NAME
} from "./content_embed.js";
import ContentEmbedBoxSizeDropdown from "./content_embed_box_size_dropdown.js";
+import ContentEmbedPositionDropdown from "./content_embed_position_dropdown.js";
import ContentEmbedToolbar from "./content_embed_toolbar.js";
import ContentEmbedTools, { CONTENT_EMBED_TOOLS } from "./content_embed_tools.js";
import ExtendedCodeBlock, { EXTENDED_CODE_BLOCK_COPY_BUTTON } from "./extended_code_block.js";
@@ -94,6 +95,7 @@ describe("ContentEmbedToolbar", () => {
expect(requires).toContain(WidgetToolbarRepository);
expect(requires).toContain(ContentEmbed);
expect(requires).toContain(ContentEmbedBoxSizeDropdown);
+ expect(requires).toContain(ContentEmbedPositionDropdown);
expect(requires).toContain(ContentEmbedTools);
expect(requires).toContain(ExtendedCodeBlock);
});
@@ -112,6 +114,7 @@ describe("ContentEmbedToolbar", () => {
CONTENT_EMBED_TOOLS,
EXTENDED_CODE_BLOCK_COPY_BUTTON,
"contentEmbedBoxSizeDropdown",
+ "contentEmbedPositionDropdown",
TOGGLE_TITLE_COMMAND_NAME,
TOGGLE_CAPTION_COMMAND_NAME,
CONVERT_EMBED_TO_LINK_COMMAND,
diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed_toolbar.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed_toolbar.ts
index 8970d7dcba..c1c6da08f2 100644
--- a/packages/ckeditor5/src/plugins/content_embed/content_embed_toolbar.ts
+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed_toolbar.ts
@@ -12,6 +12,9 @@ import ContentEmbed, {
import ContentEmbedBoxSizeDropdown, {
CONTENT_EMBED_BOX_SIZE_DROPDOWN
} from "./content_embed_box_size_dropdown.js";
+import ContentEmbedPositionDropdown, {
+ CONTENT_EMBED_POSITION_DROPDOWN
+} from "./content_embed_position_dropdown.js";
import ContentEmbedTools, { CONTENT_EMBED_TOOLS } from "./content_embed_tools.js";
import ExtendedCodeBlock, { EXTENDED_CODE_BLOCK_COPY_BUTTON } from "./extended_code_block.js";
@@ -19,8 +22,8 @@ export default class ContentEmbedToolbar extends Plugin {
static get requires() {
return [
- WidgetToolbarRepository, ContentEmbed, ContentEmbedBoxSizeDropdown, ContentEmbedTools,
- ExtendedCodeBlock
+ WidgetToolbarRepository, ContentEmbed, ContentEmbedBoxSizeDropdown,
+ ContentEmbedPositionDropdown, ContentEmbedTools, ExtendedCodeBlock
] as const;
}
@@ -36,6 +39,7 @@ export default class ContentEmbedToolbar extends Plugin {
CONTENT_EMBED_TOOLS,
EXTENDED_CODE_BLOCK_COPY_BUTTON,
CONTENT_EMBED_BOX_SIZE_DROPDOWN,
+ CONTENT_EMBED_POSITION_DROPDOWN,
TOGGLE_TITLE_COMMAND_NAME,
TOGGLE_CAPTION_COMMAND_NAME,
CONVERT_EMBED_TO_LINK_COMMAND,
diff --git a/packages/ckeditor5/src/plugins/content_embed/inline_source.spec.ts b/packages/ckeditor5/src/plugins/content_embed/inline_source.spec.ts
index 81cf618178..d844491f58 100644
--- a/packages/ckeditor5/src/plugins/content_embed/inline_source.spec.ts
+++ b/packages/ckeditor5/src/plugins/content_embed/inline_source.spec.ts
@@ -96,17 +96,20 @@ describe("ContentEmbedInlineSource", () => {
expect(getEmbed().getAttribute("displayMode")).toBe("source");
});
- it("keeps the box size, the flags and the size of the embed on the <pre>", () => {
+ it("keeps the box size, the flags, the position and the size of the embed on the <pre>", () => {
const html = `<pre style="--include-note-height:12em;" data-box-size="small"`
- + ` data-editable="true" data-hide-title="true"><code class="language-mermaid">x</code></pre>`;
+ + ` data-editable="true" data-hide-title="true" data-position="wrap-left">`
+ + `<code class="language-mermaid">x</code></pre>`;
editor.setData(html);
const embed = getEmbed();
expect(embed.getAttribute("boxSize")).toBe("small");
expect(embed.getAttribute("editable")).toBe(true);
+ expect(embed.getAttribute("position")).toBe("wrap-left");
expect(embed.getAttribute(SIZE_ATTRIBUTES.height)).toBe("12em");
expect(editor.getData()).toContain(`data-box-size="small"`);
expect(editor.getData()).toContain(`data-editable="true"`);
+ expect(editor.getData()).toContain(`data-position="wrap-left"`);
expect(editor.getData()).toContain("--include-note-height:12em");
});
diff --git a/packages/ckeditor5/src/plugins/content_embed/inline_source.ts b/packages/ckeditor5/src/plugins/content_embed/inline_source.ts
index f15761f20a..10d70f2d4c 100644
--- a/packages/ckeditor5/src/plugins/content_embed/inline_source.ts
+++ b/packages/ckeditor5/src/plugins/content_embed/inline_source.ts
@@ -21,6 +21,8 @@ import {
getCodeViewOfView,
getDisplayModeAttributes,
getDisplayModeOfView,
+ getPositionAttributes,
+ getPositionOfView,
INLINE_BOX_SIZES,
toDisplayMode
} from './content_embed.js';
@@ -66,8 +68,8 @@ const SIZE_PROPERTIES = [
* Embeds whose content lives in the note, as `<pre><code class="language-…">` code blocks: the
* diagrams of the languages in `contentEmbed.inlineLanguages`, and the extended code blocks, whose
* `<pre>` has the `EXTENDED_CODE_BLOCK_CLASS` class. The embed keeps the language and the source as
- * attributes, and is saved as the code block, with its box size, flags and size on the `<pre>`,
- * so that anything reading the note sees a plain code block.
+ * attributes, and is saved as the code block, with its box size, flags, position and size on the
+ * `<pre>`, so that anything reading the note sees a plain code block.
*
* The content renders through the host's `contentEmbed.loadInline()`, which receives an
* {@link InlineEmbedSource} rather than an ID.
@@ -193,6 +195,7 @@ export default class ContentEmbedInlineSource extends Plugin {
hideTitle: true,
...( isCodeBlock ? getCodeBlockModeOfView( pre ) : getModeOfSavedView( pre, code ) ),
...getFlagsOfView( pre ),
+ ...getPositionOfView( pre ),
...getSizesOfView( pre ),
...getCodeViewOfView( pre )
} );
@@ -264,7 +267,8 @@ function downcastData( editor: Editor, embed: ModelElement, api: DowncastConvers
const preAttributes: Record<string, string> = {
...( isExtendedCodeBlock( editor, embed ) ? { class: EXTENDED_CODE_BLOCK_CLASS } : {} ),
'data-box-size': embed.getAttribute( 'boxSize' ) as string,
- ...getDisplayModeAttributes( embed )
+ ...getDisplayModeAttributes( embed ),
+ ...getPositionAttributes( embed )
};
for ( const [ flag, dataAttribute ] of FLAG_ATTRIBUTES ) {
if ( embed.getAttribute( flag ) ) {
diff --git a/packages/ckeditor5/src/plugins/image_position.spec.ts b/packages/ckeditor5/src/plugins/image_position.spec.ts
index f4d5bc1c41..7509b62c4a 100644
--- a/packages/ckeditor5/src/plugins/image_position.spec.ts
+++ b/packages/ckeditor5/src/plugins/image_position.spec.ts
@@ -1,10 +1,10 @@
import {
- _setModelData as setModelData,
- ButtonView, type ClassicEditor, DropdownView, Essentials, Image, ImageStyle, ListItemGroupView, ListItemView,
- type ListView, Paragraph, type View
+ _setModelData as setModelData, type ClassicEditor, DropdownView, Essentials, Image, ImageStyle,
+ Paragraph
} from "ckeditor5";
import { describe, expect, it } from "vitest";
+import { getListRows as rows, pickListRow as pick } from "../../test/dropdown-kit.js";
import { createTestEditor } from "../../test/editor-kit.js";
import ImagePosition from "./image_position.js";
@@ -59,6 +59,9 @@ describe("ImagePosition", () => {
setModelData(editor.model, BLOCK_IMAGE);
expect(rows(dropdown)).toStrictEqual(["# Wrap text", "Align left", "Align right"]);
expect(dropdown.buttonView.icon).toBe(styleIcon(editor, "alignLeft"));
+
+ const { dropdown: empty } = await createEditor(["side"]);
+ expect([ rows(empty), empty.buttonView.icon ]).toStrictEqual([ [], undefined ]);
});
});
@@ -71,26 +74,3 @@ function getDropdown(editor: ClassicEditor) {
function styleIcon(editor: ClassicEditor, name: string) {
return editor.plugins.get("ImageStyleEditing").normalizedStyles?.find((style) => style.name === name)?.icon;
}
-
-/** The rows of the dropdown's list: a heading as `# label`, a row that is on with a check. */
-function rows(dropdown: DropdownView) {
- dropdown.isOpen = true;
- dropdown.isOpen = false;
- const text = (items: Iterable<View>): string[] => [ ...items ].flatMap((item) => {
- if (item instanceof ListItemGroupView) return [ `# ${item.label}`, ...text(item.items) ];
- const button = item instanceof ListItemView ? item.children.first : null;
- return button instanceof ButtonView ? [ button.isOn ? `${button.label} ✓` : button.label ?? "" ] : [];
- });
- return text((dropdown.listView as ListView).items);
-}
-
-function pick(dropdown: DropdownView, heading: string, label: string) {
- dropdown.isOpen = true;
- const group = [ ...(dropdown.listView as ListView).items ]
- .find((item): item is ListItemGroupView => item instanceof ListItemGroupView && item.label === heading);
- const button = [ ...group?.items ?? [] ]
- .map((item) => (item instanceof ListItemView ? item.children.first : null))
- .find((view): view is ButtonView => view instanceof ButtonView && view.label === label);
- if (!button) throw new Error(`expected "${label}" under "${heading}"`);
- button.fire("execute");
-}
diff --git a/packages/ckeditor5/src/plugins/image_position.ts b/packages/ckeditor5/src/plugins/image_position.ts
index 4a3bb07859..6efd35b423 100644
--- a/packages/ckeditor5/src/plugins/image_position.ts
+++ b/packages/ckeditor5/src/plugins/image_position.ts
@@ -1,20 +1,14 @@
-import {
- addListToDropdown, Collection, createDropdown, ImageStyleEditing, Plugin, UIModel
-} from "ckeditor5";
-import type {
- ButtonView, Command, ImageStyleOptionDefinition, ListDropdownButtonDefinition, ListDropdownItemDefinition,
- Locale
-} from "ckeditor5";
+import { ImageStyleEditing, Plugin } from "ckeditor5";
+import type { ImageStyleOptionDefinition, Locale } from "ckeditor5";
-import { openListAsMenu } from "./toolbar_group_menu.js";
+import { createPositionDropdown, type PositionGroup } from "./position_dropdown.js";
/**
* Registers `imagePosition`, one dropdown for the styles of an image, in place of CKEditor's
* separate style buttons and their "Wrap text" and "Block align" dropdowns, whose rows read the
- * same. The rows are grouped by how text runs around the image, as Word and Google Docs name it:
- * in line with it, broken above and below it ("Break text"), or wrapped around it ("Wrap text").
- * The button shows the icon of the current style. As a menu of `ToolbarGroupMenu`, as on a phone,
- * the rows are tiles under their headings.
+ * same. The rows are grouped by how text runs around the image: in line with it, broken above and
+ * below it ("Break text"), or wrapped around it ("Wrap text"). The button shows the icon of the
+ * current style.
*/
export default class ImagePosition extends Plugin {
@@ -33,8 +27,6 @@ export default class ImagePosition extends Plugin {
private createDropdown(locale: Locale) {
const editor = this.editor;
const t = editor.t;
- // Always registered: `ImageStyleEditing` adds it.
- const command = editor.commands.get("imageStyle") as Command;
// Set by `ImageStyleEditing.init()`, which runs first as a plugin this one requires.
const normalizedStyles = editor.plugins.get(ImageStyleEditing).normalizedStyles as ImageStyleOptionDefinition[];
const styles = new Map(normalizedStyles.map((style) => [style.name, style]));
@@ -48,51 +40,21 @@ export default class ImagePosition extends Plugin {
{ label: t("Wrap text"), rows: [["alignLeft", t("Align left")], ["alignRight", t("Align right")]] }
];
- const items = new Collection<ListDropdownItemDefinition>();
- for (const { label, rows } of groups) {
- const buttons = new Collection<ListDropdownButtonDefinition>();
- for (const [name, rowLabel] of rows) {
- const style = styles.get(name);
- if (style) {
- buttons.add(createRow(style, rowLabel, command));
- }
- }
- if (!buttons.length) {
- continue;
- }
- if (label) {
- items.add({ type: "group", label, items: buttons });
- } else {
- items.addMany(buttons);
- }
- }
-
- const dropdown = createDropdown(locale);
- addListToDropdown(dropdown, items, { role: "menu" });
- dropdown.buttonView.set({ label: t("Image position"), tooltip: true });
- dropdown.buttonView.bind("icon").to(command, "value", (value) => {
- const current = typeof value === "string" ? styles.get(value) : undefined;
- return (current ?? styles.get("inline") ?? styles.values().next().value)?.icon;
- });
- dropdown.bind("isEnabled").to(command);
- dropdown.on("execute", (evt) => {
- const { styleName } = evt.source as ButtonView & { styleName: string };
- editor.execute("imageStyle", { value: styleName });
- editor.editing.view.focus();
+ return createPositionDropdown(editor, locale, {
+ // Always registered: `ImageStyleEditing` adds it.
+ commandName: "imageStyle",
+ label: t("Image position"),
+ groups: groups.map(({ label, rows }): PositionGroup => ({
+ label,
+ rows: rows.flatMap(([name, rowLabel]) => {
+ const style = styles.get(name);
+ return style ? [{ value: name, label: rowLabel, icon: style.icon }] : [];
+ })
+ }))
});
- openListAsMenu(dropdown, { layout: "tiles" });
- return dropdown;
}
}
-function createRow(style: ImageStyleOptionDefinition, label: string, command: Command): ListDropdownButtonDefinition {
- const model = new UIModel({
- label, icon: style.icon, withText: true, role: "menuitemradio", styleName: style.name
- });
- model.bind("isOn").to(command, "value", (value) => value === style.name);
- return { type: "button", model };
-}
-
declare module "ckeditor5" {
interface PluginsMap {
[ImagePosition.pluginName]: ImagePosition;
diff --git a/packages/ckeditor5/src/plugins/position_dropdown.ts b/packages/ckeditor5/src/plugins/position_dropdown.ts
new file mode 100644
index 0000000000..7eb8122465
--- /dev/null
+++ b/packages/ckeditor5/src/plugins/position_dropdown.ts
@@ -0,0 +1,79 @@
+import { addListToDropdown, Collection, createDropdown, UIModel } from "ckeditor5";
+import type {
+ ButtonView, Command, DropdownView, Editor, ListDropdownButtonDefinition,
+ ListDropdownItemDefinition, Locale
+} from "ckeditor5";
+
+import { openListAsMenu } from "./toolbar_group_menu.js";
+
+/** A row of a position dropdown: the value that it runs the command with, its label and icon. */
+export interface PositionRow {
+ value: string;
+ label: string;
+ icon: string;
+}
+
+/** The rows under one heading of a position dropdown, or rows without a heading. */
+export interface PositionGroup {
+ label?: string;
+ rows: PositionRow[];
+}
+
+/**
+ * Creates a dropdown that runs `commandName` with the `value` of the row picked, as
+ * `{ value }`. The rows are grouped by how text runs around the object, as Word and Google Docs
+ * name it, and a group without rows is left out. The button shows the icon of the command's
+ * value, or of the first row. As a menu of `ToolbarGroupMenu`, as on a phone, the rows are tiles
+ * under their headings.
+ */
+export function createPositionDropdown(
+ editor: Editor,
+ locale: Locale,
+ { commandName, label, groups }: { commandName: string; label: string; groups: PositionGroup[] }
+): DropdownView {
+ const command = editor.commands.get(commandName) as Command;
+ const rows = groups.flatMap((group) => group.rows);
+
+ const items = new Collection<ListDropdownItemDefinition>();
+ for (const group of groups) {
+ const buttons = new Collection<ListDropdownButtonDefinition>();
+ for (const row of group.rows) {
+ buttons.add(createRow(row, command));
+ }
+ if (!buttons.length) {
+ continue;
+ }
+ if (group.label) {
+ items.add({ type: "group", label: group.label, items: buttons });
+ } else {
+ items.addMany(buttons);
+ }
+ }
+
+ const dropdown = createDropdown(locale);
+ addListToDropdown(dropdown, items, { role: "menu" });
+ dropdown.buttonView.set({ label, tooltip: true });
+ dropdown.buttonView.bind("icon").to(command, "value", (value) => {
+ return (rows.find((row) => row.value === value) ?? rows[0])?.icon;
+ });
+ dropdown.bind("isEnabled").to(command);
+ dropdown.on("execute", (evt) => {
+ const { positionValue } = evt.source as ButtonView & { positionValue: string };
+ editor.execute(commandName, { value: positionValue });
+ editor.editing.view.focus();
+ });
+ openListAsMenu(dropdown, { layout: "tiles" });
+ return dropdown;
+}
+
+function createRow(row: PositionRow, command: Command): ListDropdownButtonDefinition {
+ const model = new UIModel({
+ label: row.label,
+ icon: row.icon,
+ withText: true,
+ role: "menuitemradio",
+ positionValue: row.value
+ });
+ model.bind("isOn").to(command, "value", (value) => value === row.value);
+ return { type: "button", model };
+}
diff --git a/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.spec.ts b/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.spec.ts
index f326a83d4b..8bb7ab28e6 100644
--- a/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.spec.ts
+++ b/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.spec.ts
@@ -17,10 +17,11 @@ import ResizableWidgets, { type ResizableWidgetConfig } from "./resizable_widget
const STYLES = `
.ck.ck-editor__editable { width: 400px; padding: 0; font-size: 10px; }
- .test-box { width: var(--test-width, auto); }
+ .test-box { position: relative; width: var(--test-width, auto); }
.test-box-content { height: var(--test-height, 50px); }
.test-rtl .test-box { direction: rtl; }
.test-centered .test-box { margin-inline: auto; }
+ .test-box.ck-widget_resize-anchor-right { margin-left: auto; }
.test-scroller .ck.ck-editor__main { height: 150px; overflow-y: auto; }
.test-scroller .ck.ck-editor__editable { height: 1000px; }
`;
@@ -279,7 +280,7 @@ describe("ResizableWidgets", () => {
it("keeps the dragged edge of a centered widget under the pointer", async () => {
document.body.classList.add("test-centered");
- await createEditor({ isCentered: true });
+ await createEditor({ getAnchor: () => "center" });
editor.setData("<div class=\"test-box\"></div>");
const { left, right } = getBox().getBoundingClientRect();
@@ -292,6 +293,65 @@ describe("ResizableWidgets", () => {
expect(getSize()).toBe("<testBox customWidth=\"30em\"></testBox>");
});
+ it("grows a widget anchored to an edge from the other edge, with the handles", async () => {
+ await createEditor({
+ getAnchor: (element) => element.getAttribute("kind") === "right" ? "right" : "left"
+ });
+ editor.setData(RESIZED);
+ const box = editor.model.document.getRoot()?.getChild(0);
+ if (!box?.is("element")) {
+ throw new Error("Expected a box.");
+ }
+ /** The edges of the box that the width and corner handles are centered on. */
+ const getHandleEdges = () => {
+ const { left, right } = getBox().getBoundingClientRect();
+ return [ "width", "corner" ].map((name) => {
+ const handle = getHandle(name).getBoundingClientRect();
+ const center = Math.round(handle.left + handle.width / 2);
+ if (center === Math.round(left)) {
+ return "left";
+ }
+ return center === Math.round(right) && "right";
+ });
+ };
+ editor.model.change((writer) => writer.setSelection(box, "on"));
+ editor.editing.view.focus();
+ await expect.poll(() => getComputedStyle(getHandle("width")).display).toBe("block");
+
+ expect(getBox().classList.contains("ck-widget_resize-anchor-left")).toBe(true);
+ expect(getHandleEdges()).toEqual([ "right", "right" ]);
+ expect(getComputedStyle(getHandle("corner")).cursor).toBe("nwse-resize");
+ press(getHandle("width"));
+ move(150, 300);
+ release();
+ expect(getSize()).toBe("<testBox customHeight=\"8em\" customWidth=\"35em\"></testBox>");
+
+ editor.model.change((writer) => writer.setAttribute("kind", "right", box));
+ expect([ ...getBox().classList ]).toEqual(expect.arrayContaining([
+ "ck-widget_resizable", "ck-widget_resize-anchor-right"
+ ]));
+ expect(getBox().classList.contains("ck-widget_resize-anchor-left")).toBe(false);
+ expect(getHandleEdges()).toEqual([ "left", "left" ]);
+ expect(getComputedStyle(getHandle("corner")).cursor).toBe("nesw-resize");
+ press(getHandle("width"));
+ move(150, 300);
+ const { right } = getBox().getBoundingClientRect();
+ release();
+ expect(getSize())
+ .toBe("<testBox customHeight=\"8em\" customWidth=\"30em\" kind=\"right\"></testBox>");
+ expect(getBox().getBoundingClientRect().right).toBe(right);
+
+ // The edges are physical: right to left, a box anchored left still grows to the right.
+ document.body.classList.add("test-rtl");
+ editor.model.change((writer) => writer.removeAttribute("kind", box));
+ expect(getHandleEdges()).toEqual([ "right", "right" ]);
+ expect(getComputedStyle(getHandle("corner")).cursor).toBe("nwse-resize");
+ press(getHandle("width"));
+ move(150, 300);
+ release();
+ expect(getSize()).toBe("<testBox customHeight=\"8em\" customWidth=\"35em\"></testBox>");
+ });
+
it("cancels on Escape, pointercancel or lost capture, and ignores other pointers", async () => {
await createEditor();
editor.setData(RESIZED);
diff --git a/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.ts b/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.ts
index 98366fe299..1c7189735d 100644
--- a/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.ts
+++ b/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.ts
@@ -10,7 +10,11 @@ import {
WidgetToolbarRepository
} from "ckeditor5";
-import { type ResizeAxes, type ResizeSize, startResizeGesture } from "./resize_gesture.js";
+import {
+ type ResizeAnchor, type ResizeAxes, type ResizeSize, startResizeGesture
+} from "./resize_gesture.js";
+
+export type { ResizeAnchor } from "./resize_gesture.js";
/** How the widgets of a model element are resized. */
export interface ResizableWidgetConfig {
@@ -21,8 +25,11 @@ export interface ResizableWidgetConfig {
propertyPrefix: string;
isWidthResizable?: boolean;
isHeightResizable?: boolean;
- /** Whether the widget's stylesheet centers it, so that its width changes on both sides. */
- isCentered?: boolean;
+ /**
+ * The edge of `element` that stays in place while its width changes, as its stylesheet places
+ * the widget. The inline start by default. The handles go on the opposite edge.
+ */
+ getAnchor?: (element: ModelElement) => ResizeAnchor;
/** A selector for the element inside the widget whose height changes, or the widget. */
heightTarget?: string;
/** The smallest width, in `em`. */
@@ -48,6 +55,11 @@ const HANDLES: Record<string, ResizeAxes> = {
};
const RESIZABLE_CLASS = "ck-widget_resizable";
+/** The classes of a widget anchored to its left or right edge, which place its handles. */
+const ANCHOR_CLASSES = {
+ left: "ck-widget_resize-anchor-left",
+ right: "ck-widget_resize-anchor-right"
+} as const;
const RESIZING_CLASS = "ck-widget_resizing";
const TOOLBAR_LOCK = "ResizableWidgets";
const DEFAULT_MIN_SIZE = 2;
@@ -55,8 +67,9 @@ const DOUBLE_TAP_MS = 400;
const EM_PATTERN = /^\d+(\.\d+)?em$/;
/**
- * Lets the user resize widgets by dragging handles on their inline-end edge, bottom edge and
- * corner, with a mouse, a pen or a finger. Double-clicking a handle resets its size.
+ * Lets the user resize widgets by dragging handles on the edge opposite their anchor, their bottom
+ * edge and the corner between them, with a mouse, a pen or a finger. Double-clicking a handle
+ * resets its size.
*/
export default class ResizableWidgets extends Plugin {
@@ -103,10 +116,10 @@ export default class ResizableWidgets extends Plugin {
const subject = { element: item, viewElement, config };
const handles = this.createHandles(api.writer, subject, axes);
api.writer.insert(api.writer.createPositionAt(viewElement, "end"), handles);
- updateResizableClass(api.writer, viewElement, item, config);
+ updateWidgetClasses(api.writer, viewElement, item, config);
}, { priority: "low" });
- if (config.isResizable) {
+ if (config.isResizable || config.getAnchor) {
dispatcher.on<DowncastAttributeEvent>("attribute", (_evt, { item }, api) => {
if (!item.is("element", modelName)) {
return;
@@ -118,7 +131,7 @@ export default class ResizableWidgets extends Plugin {
return;
}
- updateResizableClass(api.writer, viewElement, item, config);
+ updateWidgetClasses(api.writer, viewElement, item, config);
}, { priority: "low" });
}
});
@@ -193,7 +206,7 @@ export default class ResizableWidgets extends Plugin {
handle,
axes,
widthTarget: targets.width,
- isCentered: !!config.isCentered,
+ anchor: config.getAnchor?.(element) ?? "start",
heightTarget: targets.height,
minWidth: toPixels(config.minWidth ?? DEFAULT_MIN_SIZE, targets.width),
minHeight: toPixels(config.minHeight ?? DEFAULT_MIN_SIZE, targets.height),
@@ -291,16 +304,30 @@ function getAxes(config: ResizableWidgetConfig) {
return axes;
}
-function updateResizableClass(
+/** Sets the resizable and anchor classes of the widget from the state of `element`. */
+function updateWidgetClasses(
writer: ViewDowncastWriter,
viewElement: ViewElement,
element: ModelElement,
config: ResizableWidgetConfig
) {
- if (config.isResizable?.(element) ?? true) {
- writer.addClass(RESIZABLE_CLASS, viewElement);
+ const anchor = config.getAnchor?.(element);
+ toggleClass(writer, viewElement, RESIZABLE_CLASS, config.isResizable?.(element) ?? true);
+ for (const [ name, className ] of Object.entries(ANCHOR_CLASSES)) {
+ toggleClass(writer, viewElement, className, name === anchor);
+ }
+}
+
+function toggleClass(
+ writer: ViewDowncastWriter,
+ viewElement: ViewElement,
+ className: string,
+ isSet: boolean
+) {
+ if (isSet) {
+ writer.addClass(className, viewElement);
} else {
- writer.removeClass(RESIZABLE_CLASS, viewElement);
+ writer.removeClass(className, viewElement);
}
}
diff --git a/packages/ckeditor5/src/plugins/resizable_widgets/resize_gesture.ts b/packages/ckeditor5/src/plugins/resizable_widgets/resize_gesture.ts
index 4f1ef79714..83ba58fc27 100644
--- a/packages/ckeditor5/src/plugins/resizable_widgets/resize_gesture.ts
+++ b/packages/ckeditor5/src/plugins/resizable_widgets/resize_gesture.ts
@@ -4,6 +4,12 @@ export interface ResizeAxes {
height: boolean;
}
+/**
+ * The edge of a widget that stays in place while its width changes: its inline start, its left or
+ * right edge, or neither for a centered widget, whose width changes on both sides.
+ */
+export type ResizeAnchor = "start" | "center" | "left" | "right";
+
/** A size in pixels. An axis that is left out does not change, and a `null` width is full. */
export interface ResizeSize {
width?: number | null;
@@ -16,8 +22,8 @@ export interface ResizeGestureOptions {
axes: ResizeAxes;
/** The element whose width changes. Its width is full once it reaches its parent's. */
widthTarget: HTMLElement;
- /** Whether the width target is centered, so that its width changes on both sides. */
- isCentered: boolean;
+ /** The edge of the width target that stays in place. */
+ anchor: ResizeAnchor;
/** The element whose height changes. */
heightTarget: HTMLElement;
/** The smallest width, in pixels. */
@@ -44,8 +50,8 @@ const AUTO_SCROLL_EDGE = 40;
const AUTO_SCROLL_STEP = 16;
/**
- * Resizes until the pointer pressed in `event` is released. The width grows towards the inline
- * end, or on both sides when centered, the height towards the bottom, and the scroll container
+ * Resizes until the pointer pressed in `event` is released. The width grows away from the anchor,
+ * or on both sides when centered, the height towards the bottom, and the scroll container
* scrolls near its edges. Returns a function that cancels the gesture as Escape does, while it is
* under way.
*/
@@ -55,8 +61,7 @@ export function startResizeGesture(event: PointerEvent, options: ResizeGestureOp
const startWidth = parseFloat(getComputedStyle(widthTarget).width);
const startHeight = parseFloat(getComputedStyle(heightTarget).height);
const maxWidth = getContainerWidth(widthTarget);
- const inlineDirection = getComputedStyle(widthTarget).direction === "rtl" ? -1 : 1;
- const widthFactor = inlineDirection * (options.isCentered ? 2 : 1);
+ const widthFactor = getWidthFactor(options.anchor, widthTarget);
const scroller = findScrollContainer(heightTarget);
const startScrollTop = scroller.scrollTop;
@@ -161,6 +166,19 @@ export function startResizeGesture(event: PointerEvent, options: ResizeGestureOp
};
}
+/** The change in width of `element` per pixel that the pointer moves to the right. */
+function getWidthFactor(anchor: ResizeAnchor, element: HTMLElement) {
+ if (anchor === "left") {
+ return 1;
+ }
+ if (anchor === "right") {
+ return -1;
+ }
+
+ const inlineDirection = getComputedStyle(element).direction === "rtl" ? -1 : 1;
+ return anchor === "center" ? 2 * inlineDirection : inlineDirection;
+}
+
/** The width inside the padding of the parent of `element`. */
function getContainerWidth(element: HTMLElement) {
const parent = element.parentElement ?? document.documentElement;
diff --git a/packages/ckeditor5/src/theme/resizable_widgets.css b/packages/ckeditor5/src/theme/resizable_widgets.css
index 259753fa93..d279add086 100644
--- a/packages/ckeditor5/src/theme/resizable_widgets.css
+++ b/packages/ckeditor5/src/theme/resizable_widgets.css
@@ -98,6 +98,28 @@
}
}
+.ck .ck-widget_resize-anchor-left > .ck-widget__resize-handles {
+ > :is(.ck-widget__resize-handle_width, .ck-widget__resize-handle_corner) {
+ inset-inline: auto;
+ right: var(--_offset);
+ }
+
+ > .ck-widget__resize-handle_corner {
+ cursor: nwse-resize;
+ }
+}
+
+.ck .ck-widget_resize-anchor-right > .ck-widget__resize-handles {
+ > :is(.ck-widget__resize-handle_width, .ck-widget__resize-handle_corner) {
+ inset-inline: auto;
+ left: var(--_offset);
+ }
+
+ > .ck-widget__resize-handle_corner {
+ cursor: nesw-resize;
+ }
+}
+
.ck .ck-widget_resizing iframe {
pointer-events: none;
}
diff --git a/packages/ckeditor5/test/dropdown-kit.ts b/packages/ckeditor5/test/dropdown-kit.ts
new file mode 100644
index 0000000000..914cf6019f
--- /dev/null
+++ b/packages/ckeditor5/test/dropdown-kit.ts
@@ -0,0 +1,38 @@
+import {
+ ButtonView, type DropdownView, ListItemGroupView, ListItemView, type ListView, type View
+} from "ckeditor5";
+
+/**
+ * The rows of the list of `dropdown`, which opens once to build it: a heading as `# label`, and a
+ * row that is on with a check.
+ */
+export function getListRows(dropdown: DropdownView) {
+ dropdown.isOpen = true;
+ dropdown.isOpen = false;
+ const text = (items: Iterable<View>): string[] => [ ...items ].flatMap((item) => {
+ if (item instanceof ListItemGroupView) return [ `# ${item.label}`, ...text(item.items) ];
+ const button = item instanceof ListItemView ? item.children.first : null;
+ if (!(button instanceof ButtonView)) return [];
+ return [ button.isOn ? `${button.label} ✓` : button.label ?? "" ];
+ });
+ return text((dropdown.listView as ListView).items);
+}
+
+/** The button of the row `label` under the heading `heading` of the list of `dropdown`. */
+export function getListRow(dropdown: DropdownView, heading: string, label: string) {
+ dropdown.isOpen = true;
+ const isHeading = (item: View): item is ListItemGroupView => {
+ return item instanceof ListItemGroupView && item.label === heading;
+ };
+ const group = [ ...(dropdown.listView as ListView).items ].find(isHeading);
+ const button = [ ...group?.items ?? [] ]
+ .map((item) => (item instanceof ListItemView ? item.children.first : null))
+ .find((view): view is ButtonView => view instanceof ButtonView && view.label === label);
+ if (!button) throw new Error(`expected "${label}" under "${heading}"`);
+ return button;
+}
+
+/** Runs the row `label` under the heading `heading` of the list of `dropdown`. */
+export function pickListRow(dropdown: DropdownView, heading: string, label: string) {
+ getListRow(dropdown, heading, label).fire("execute");
+}
diff --git a/packages/share-theme/src/content/content.css b/packages/share-theme/src/content/content.css
index 6f0ecd181b..e82b8fdcfa 100644
--- a/packages/share-theme/src/content/content.css
+++ b/packages/share-theme/src/content/content.css
@@ -345,7 +345,54 @@ body:not(.math-loaded) .math-tex {
/* An include with a caption: the included content, then the caption. */
.ck-content figure.include-note {
+ clear: both;
margin: 1em 0;
+
+ &:is([data-box-size="small"], [data-box-size="medium"], [data-box-size="expandable"]) {
+ margin-inline: auto;
+ max-width: 100%;
+ width: var(--include-note-width, auto);
+ }
+
+ &[data-position="left"] {
+ margin-right: auto;
+ margin-left: 0;
+ }
+
+ &[data-position="right"] {
+ margin-right: 0;
+ margin-left: auto;
+ }
+
+ &:is([data-position="wrap-left"], [data-position="wrap-right"]) {
+ /* No gap at full width, so that the margin box fits in the column. */
+ --_include-note-wrap-gap: clamp(0px, 100% - var(--include-note-width, 100%),
+ var(--ck-content-image-style-spacing, 1.5em));
+
+ clear: none;
+ margin-top: 0;
+ max-width: 100%;
+ width: var(--include-note-width, 100%);
+ }
+
+ &[data-position="wrap-left"] {
+ float: left;
+ margin-right: var(--_include-note-wrap-gap);
+ }
+
+ &[data-position="wrap-right"] {
+ float: right;
+ margin-left: var(--_include-note-wrap-gap);
+ }
+}
+
+@media (max-width: 48em) {
+ .ck-content figure.include-note[data-position] {
+ float: none;
+ clear: both;
+ margin: 1em 0;
+ width: auto;
+ }
}
.ck-content .include-note > figcaption {