Skip to content

Build your personal knowledge base with Trilium Notes

client/text editor/include notes: create a new "Tiny" include widget layout

Adorian Doran2b816ed5d1e8
diff --git a/apps/client/src/services/attachment_actions.ts b/apps/client/src/services/attachment_actions.ts
index a0bd50b883..51a9d19efe 100644
--- a/apps/client/src/services/attachment_actions.ts
+++ b/apps/client/src/services/attachment_actions.ts
@@ -42,12 +42,7 @@ export function getAttachmentActionGroups(
return [
[
- {
- title: t("attachments_actions.open_externally"),
- tooltip: t("attachments_actions.open_externally_title"),
- icon: "bx bx-file-find",
- run: () => open.openAttachmentExternally(attachmentId, mime)
- },
+ getOpenExternallyAction(attachment),
{
title: t("attachments_actions.open_custom"),
tooltip: t("attachments_actions.open_custom_title"),
@@ -57,11 +52,7 @@ export function getAttachmentActionGroups(
: t("attachments_actions.open_custom_client_only"),
run: () => open.openAttachmentCustom(attachmentId, mime)
},
- {
- title: t("attachments_actions.download"),
- icon: "bx bx-download",
- run: () => open.downloadAttachment(attachmentId)
- },
+ getDownloadAction(attachment),
...(copyReference ? [ {
title: t("attachments_actions.copy_link_to_clipboard"),
icon: "bx bx-copy",
@@ -70,10 +61,12 @@ export function getAttachmentActionGroups(
...(supportsOcr(attachment) ? [ {
title: t("ocr.view_extracted_text"),
icon: "bx bx-text",
- run: () => appContext.triggerCommand("showOcrTextDialog", {
- textUrl: `ocr/attachments/${attachmentId}/text`,
- processUrl: `ocr/process-attachment/${attachmentId}`
- })
+ run: () => {
+ appContext.triggerCommand("showOcrTextDialog", {
+ textUrl: `ocr/attachments/${attachmentId}/text`,
+ processUrl: `ocr/process-attachment/${attachmentId}`
+ });
+ }
} ] : [])
],
[
@@ -113,6 +106,23 @@ export function getAttachmentActionGroups(
];
}
+export function getOpenExternallyAction({ attachmentId, mime }: FAttachment): AttachmentAction {
+ return {
+ title: t("attachments_actions.open_externally"),
+ tooltip: t("attachments_actions.open_externally_title"),
+ icon: "bx bx-file-find",
+ run: () => open.openAttachmentExternally(attachmentId, mime)
+ };
+}
+
+export function getDownloadAction({ attachmentId }: FAttachment): AttachmentAction {
+ return {
+ title: t("attachments_actions.download"),
+ icon: "bx bx-download",
+ run: () => open.downloadAttachment(attachmentId)
+ };
+}
+
/** Whether the attachment is an ordinary file, previewed and linked like one. */
export function isFileLikeAttachment(attachment: FAttachment) {
return attachment.role === "file" || attachment.role === "importSource";
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.css
index 3a7b05f629..c134e78395 100644
--- a/apps/client/src/stylesheets/style.css
+++ b/apps/client/src/stylesheets/style.css
@@ -1606,6 +1606,52 @@ body.mobile .modal-content-with-sidebar > .modal-main > .modal-header > .modal-t
transform: rotate(90deg);
}
+/* The selector must outrank the `display` that the icon pack sets on its own class. */
+.include-note-title-row > .include-note-icon {
+ --size: calc(1em + 12px);
+
+ display: flex;
+ flex-shrink: 0;
+ justify-content: center;
+ align-items: center;
+ margin-inline-end: 4px;
+ border-radius: 50%;
+ width: var(--size);
+ height: var(--size);
+ background: var(--note-list-view-large-icon-background, var(--main-background-color));
+ font-size: 1.2em;
+ color: var(--note-list-view-large-icon-color, var(--muted-text-color));
+}
+
+/* The glyph and its circle differ by a whole, even number of pixels. */
+@supports (width: round(1px, 1px)) {
+ .include-note-title-row > .include-note-icon {
+ font-size: round(1.2em, 1px);
+ }
+}
+
+.include-note-heading {
+ display: flex;
+ flex-direction: column;
+ flex-grow: 1;
+ min-width: 0;
+
+ /* The note path from createLink() goes above the title. */
+ .include-note-title > span {
+ flex-direction: column-reverse;
+ align-items: flex-start;
+ gap: 0;
+ }
+
+ small {
+ font-size: .7em;
+ font-weight: 500;
+ line-height: 1;
+ letter-spacing: .5pt;
+ opacity: .5;
+ }
+}
+
.include-note-content {
border-top: 2px solid var(--main-background-color);
padding: .75rem 1rem;
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 83510d31f8..ed4f3b2805 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -340,7 +340,8 @@
"box_size_medium": "medium (~ 30 lines)",
"box_size_full": "full (box shows complete text)",
"box_size_expandable": "expandable (collapsed by default)",
- "button_include": "Include note"
+ "button_include": "Include note",
+ "box_size_tiny": "tiny (a single row with the title and the actions)"
},
"info": {
"modalTitle": "Info message",
@@ -4405,7 +4406,8 @@
"sort": "Sort",
"ascending": "Ascending",
"descending": "Descending",
- "some-rows-were-sorted-together-because-merged-cells-tie-them-to-each-other": "Some rows were sorted together because merged cells tie them to each other"
+ "some-rows-were-sorted-together-because-merged-cells-tie-them-to-each-other": "Some rows were sorted together because merged cells tie them to each other",
+ "tiny": "Tiny"
},
"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/dialogs/include_note.tsx b/apps/client/src/widgets/dialogs/include_note.tsx
index c03a4e4327..bb58b1c201 100644
--- a/apps/client/src/widgets/dialogs/include_note.tsx
+++ b/apps/client/src/widgets/dialogs/include_note.tsx
@@ -66,6 +66,7 @@ export default function IncludeNoteDialog() {
name="include-note-box-size"
currentValue={boxSize} onChange={setBoxSize}
values={[
+ { label: t("include_note.box_size_tiny"), value: "tiny" },
{ label: t("include_note.box_size_small"), value: "small" },
{ label: t("include_note.box_size_medium"), value: "medium" },
{ label: t("include_note.box_size_full"), value: "full" },
diff --git a/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx b/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx
index eb4d26b67d..85dbdee1ec 100644
--- a/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx
+++ b/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx
@@ -10,7 +10,7 @@ import type { AiNoteLocation } from "./ai_assistant_stream";
import { useAiMenuFooter, useAiQuickActions } from "./ai_quick_actions";
import { buildConfig, BuildEditorOptions } from "./config";
-export type BoxSize = "small" | "medium" | "full" | "expandable";
+export type BoxSize = "tiny" | "small" | "medium" | "full" | "expandable";
export interface CKEditorApi {
/** returns true if user selected some text, false if there's no selection */
diff --git a/apps/client/src/widgets/type_widgets/text/IncludeNote.spec.tsx b/apps/client/src/widgets/type_widgets/text/IncludeNote.spec.tsx
index 2bd9a6599d..6879591839 100644
--- a/apps/client/src/widgets/type_widgets/text/IncludeNote.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/text/IncludeNote.spec.tsx
@@ -5,22 +5,29 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
const {
openTabWithNoteWithHoisting,
+ triggerCommand,
openContextMenu,
disposeInteractiveContent
} = vi.hoisted(() => ({
openTabWithNoteWithHoisting: vi.fn(),
+ triggerCommand: vi.fn(),
openContextMenu: vi.fn(),
disposeInteractiveContent: vi.fn()
}));
vi.mock("../../../services/i18n", () => ({ t: (key: string) => key }));
vi.mock("../../../components/app_context", () => ({
- default: { tabManager: { openTabWithNoteWithHoisting } }
+ default: { tabManager: { openTabWithNoteWithHoisting }, triggerCommand }
}));
vi.mock("../../../menus/link_context_menu", () => ({ default: { openContextMenu } }));
vi.mock("../../../services/content_renderer", () => ({ default: { disposeInteractiveContent } }));
-import IncludeNote, { type IncludeNoteProps } from "./IncludeNote";
+import IncludeNote, {
+ getNoteActions,
+ type IncludeNoteProps,
+ TinyIncludeNote,
+ type TinyIncludeNoteProps
+} from "./IncludeNote";
const ATTACHMENT_SCOPE = { viewMode: "attachments", attachmentId: "att1" } as const;
@@ -62,6 +69,18 @@ function renderBox(props: Partial<IncludeNoteProps> = {}) {
return boxProps;
}
+function renderTinyBox(props: Partial<TinyIncludeNoteProps> = {}) {
+ const boxProps: TinyIncludeNoteProps = {
+ icon: "bx bx-note",
+ title: element(`<span><a href="#root/noteA">Note A</a></span>`),
+ notePath: "noteA",
+ actions: [],
+ ...props
+ };
+ act(() => render(<TinyIncludeNote {...boxProps} />, container));
+ return boxProps;
+}
+
/** The include-note-* class of each element in the title row, in order. */
function titleRow() {
return [ ...container.querySelectorAll(".include-note-title-row > *") ]
@@ -242,3 +261,66 @@ describe("IncludeNote", () => {
expect(container.querySelector(".include-note-fullscreen-controls")).toBeNull();
});
});
+
+describe("TinyIncludeNote", () => {
+ it("lays out a single row: icon, title and description, actions, menu", () => {
+ const run = vi.fn();
+ const { title } = renderTinyBox({
+ icon: "bx bx-file",
+ description: "2 KiB",
+ notePath: "owner",
+ viewScope: ATTACHMENT_SCOPE,
+ actions: [
+ { title: "Download", icon: "bx bx-download", run },
+ { title: "Other", icon: "bx bx-cog", run: vi.fn() }
+ ]
+ });
+
+ expect(titleRow()).toEqual([
+ "include-note-icon", "include-note-heading",
+ "include-note-action", "include-note-action", "include-note-menu"
+ ]);
+ expect(container.querySelector(".include-note-content")).toBeNull();
+ expect(container.querySelector(".include-note-icon")?.className).toContain("bx-file");
+ expect([ ...container.querySelector("h4.include-note-title")?.childNodes ?? [] ])
+ .toEqual([ title ]);
+ expect(container.querySelector(".include-note-heading > small.include-note-description")
+ ?.textContent).toBe("2 KiB");
+
+ const download = container.querySelector<HTMLButtonElement>("button.include-note-action");
+ expect(download?.className).toContain("bx-download");
+ if (!download) return;
+ expect(tooltipOf(download)).toBe("Download");
+ expect(click(download).isStopped).toBe(true);
+ expect(run).toHaveBeenCalledOnce();
+
+ const { event, isStopped } = click(button("include-note-menu"));
+ expect(isStopped).toBe(true);
+ expect(openContextMenu).toHaveBeenCalledWith("owner", event, ATTACHMENT_SCOPE);
+ });
+
+ it("leaves out the description line when there is none", () => {
+ renderTinyBox();
+ expect(container.querySelector(".include-note-description")).toBeNull();
+ });
+});
+
+describe("getNoteActions", () => {
+ it("quick edits the note, or opens it in a new tab", async () => {
+ const [ quickEdit, open ] = getNoteActions("noteA");
+ expect([ quickEdit.title, quickEdit.icon ])
+ .toEqual([ "link_context_menu.open_note_in_popup", "bx bx-edit" ]);
+ expect([ open.title, open.icon ])
+ .toEqual([ "common.open_in_new_tab", "bx bx-link-external" ]);
+
+ await quickEdit.run();
+ expect(triggerCommand).toHaveBeenCalledWith("openInPopup", { noteIdOrPath: "noteA" });
+
+ await open.run();
+ expect(openTabWithNoteWithHoisting).toHaveBeenCalledWith("noteA", {
+ viewScope: undefined,
+ activate: true,
+ placement: "afterCurrent"
+ });
+ });
+});
diff --git a/apps/client/src/widgets/type_widgets/text/IncludeNote.tsx b/apps/client/src/widgets/type_widgets/text/IncludeNote.tsx
index de31689706..1672ca889c 100644
--- a/apps/client/src/widgets/type_widgets/text/IncludeNote.tsx
+++ b/apps/client/src/widgets/type_widgets/text/IncludeNote.tsx
@@ -7,8 +7,16 @@ import content_renderer from "../../../services/content_renderer";
import { t } from "../../../services/i18n";
import type { ViewScope } from "../../../services/link";
import ActionButton from "../../react/ActionButton";
+import Icon from "../../react/Icon";
import OverlayControlGroup, { OverlayControlButton } from "../../react/OverlayControlGroup";
+/** An action on the included note or attachment, offered as a button in the title row. */
+export interface IncludeNoteAction {
+ title: string;
+ icon: string;
+ run: () => void | Promise<void>;
+}
+
export interface IncludeNoteProps {
boxSize?: string;
/** The link to the included note or attachment, shown as the title. */
@@ -23,20 +31,28 @@ export interface IncludeNoteProps {
isFullscreenOffered?: boolean;
}
+export interface TinyIncludeNoteProps {
+ icon: string;
+ /** The link to the included note or attachment, shown as the title. */
+ title: HTMLElement;
+ /** A line under the title, such as the size of an attachment. */
+ description?: string;
+ /** The note the "More actions" menu acts on. */
+ notePath: string;
+ viewScope?: ViewScope;
+ /** The buttons before the "More actions" menu. */
+ actions: IncludeNoteAction[];
+}
+
/** The title row and the content of an included note or embedded attachment. */
export default function IncludeNote({
boxSize, title, content, contentType, notePath, viewScope, isFullscreenOffered
}: IncludeNoteProps) {
- const titleRef = useRef<HTMLHeadingElement>(null);
const contentRef = useRef<HTMLDivElement>(null);
const [ isExpanded, setIsExpanded ] = useState(false);
const isExpandable = boxSize === "expandable";
const hasFullscreen = !!isFullscreenOffered && (boxSize === "medium" || boxSize === "full");
- useLayoutEffect(() => {
- titleRef.current?.replaceChildren(title);
- }, [ title ]);
-
useLayoutEffect(() => {
contentRef.current?.append(content);
return () => {
@@ -60,19 +76,10 @@ export default function IncludeNote({
}}
/>
)}
- <h4 ref={titleRef} className="include-note-title" />
- <ActionButton
+ <IncludeNoteTitle title={title} />
+ <IncludeNoteActionButton
className="include-note-open"
- icon="bx bx-link-external"
- text={t("common.open_in_new_tab")}
- onClick={(e) => {
- e.stopPropagation();
- void appContext.tabManager.openTabWithNoteWithHoisting(notePath, {
- viewScope,
- activate: true,
- placement: "afterCurrent"
- });
- }}
+ action={getOpenInNewTabAction(notePath, viewScope)}
/>
{hasFullscreen && (
<ActionButton
@@ -87,15 +94,7 @@ export default function IncludeNote({
}}
/>
)}
- <ActionButton
- className="include-note-menu"
- icon="bx bx-dots-vertical-rounded"
- text={t("common.more_actions")}
- onClick={(e) => {
- e.stopPropagation();
- void linkContextMenu.openContextMenu(notePath, e, viewScope);
- }}
- />
+ <MoreActionsButton notePath={notePath} viewScope={viewScope} />
</div>
<div
ref={contentRef}
@@ -125,3 +124,95 @@ export default function IncludeNote({
</>
);
}
+
+/** A tiny include: a single row with an icon, the title and the actions, and no content. */
+export function TinyIncludeNote({
+ icon, title, description, notePath, viewScope, actions
+}: TinyIncludeNoteProps) {
+ return (
+ <div className="include-note-title-row">
+ <Icon className="include-note-icon" icon={icon} />
+ <div className="include-note-heading">
+ <IncludeNoteTitle title={title} />
+ {description && <small className="include-note-description">{description}</small>}
+ </div>
+ {actions.map((action) => (
+ <IncludeNoteActionButton
+ key={action.title}
+ className="include-note-action"
+ action={action}
+ />
+ ))}
+ <MoreActionsButton notePath={notePath} viewScope={viewScope} />
+ </div>
+ );
+}
+
+/** The buttons of a tiny include of a note: "Quick edit" and "Open in new tab". */
+export function getNoteActions(notePath: string): IncludeNoteAction[] {
+ return [
+ {
+ title: t("link_context_menu.open_note_in_popup"),
+ icon: "bx bx-edit",
+ run: () => {
+ appContext.triggerCommand("openInPopup", { noteIdOrPath: notePath });
+ }
+ },
+ getOpenInNewTabAction(notePath)
+ ];
+}
+
+function getOpenInNewTabAction(notePath: string, viewScope?: ViewScope): IncludeNoteAction {
+ return {
+ title: t("common.open_in_new_tab"),
+ icon: "bx bx-link-external",
+ run: async () => {
+ await appContext.tabManager.openTabWithNoteWithHoisting(notePath, {
+ viewScope,
+ activate: true,
+ placement: "afterCurrent"
+ });
+ }
+ };
+}
+
+function IncludeNoteTitle({ title }: { title: HTMLElement }) {
+ const titleRef = useRef<HTMLHeadingElement>(null);
+
+ useLayoutEffect(() => {
+ titleRef.current?.replaceChildren(title);
+ }, [ title ]);
+
+ return <h4 ref={titleRef} className="include-note-title" />;
+}
+
+function IncludeNoteActionButton({ className, action }: {
+ className: string;
+ action: IncludeNoteAction;
+}) {
+ return (
+ <ActionButton
+ className={className}
+ icon={action.icon}
+ text={action.title}
+ onClick={(e) => {
+ e.stopPropagation();
+ void action.run();
+ }}
+ />
+ );
+}
+
+function MoreActionsButton({ notePath, viewScope }: { notePath: string; viewScope?: ViewScope }) {
+ return (
+ <ActionButton
+ className="include-note-menu"
+ icon="bx bx-dots-vertical-rounded"
+ text={t("common.more_actions")}
+ onClick={(e) => {
+ e.stopPropagation();
+ void linkContextMenu.openContextMenu(notePath, e, viewScope);
+ }}
+ />
+ );
+}
diff --git a/apps/client/src/widgets/type_widgets/text/utils.spec.ts b/apps/client/src/widgets/type_widgets/text/utils.spec.ts
index 2f1aef56a6..44ad019c34 100644
--- a/apps/client/src/widgets/type_widgets/text/utils.spec.ts
+++ b/apps/client/src/widgets/type_widgets/text/utils.spec.ts
@@ -1,3 +1,4 @@
+import { attachmentIcon } from "@triliumnext/commons";
import type { VNode } from "preact";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
@@ -17,12 +18,27 @@ vi.mock("../../../services/content_renderer", () => ({
mountInteractiveWidget: vi.fn()
}
}));
-vi.mock("./IncludeNote", () => ({ default: () => null }));
+vi.mock("./IncludeNote", () => ({
+ default: () => null,
+ TinyIncludeNote: () => null,
+ getNoteActions: vi.fn()
+}));
+vi.mock("../../../services/attachment_actions", () => ({
+ getOpenExternallyAction: vi.fn(),
+ getDownloadAction: vi.fn()
+}));
+import { getDownloadAction, getOpenExternallyAction } from "../../../services/attachment_actions";
import content_renderer from "../../../services/content_renderer";
import froca from "../../../services/froca";
import link from "../../../services/link";
-import IncludeNote, { type IncludeNoteProps } from "./IncludeNote";
+import IncludeNote, {
+ getNoteActions,
+ type IncludeNoteAction,
+ type IncludeNoteProps,
+ TinyIncludeNote,
+ type TinyIncludeNoteProps
+} from "./IncludeNote";
import {
getAttachmentHref,
loadIncludedAttachment,
@@ -30,8 +46,14 @@ import {
watchIncludedNotes
} from "./utils";
-const note = { noteId: "noteY" } as unknown as FNote;
-const attachment = { attachmentId: "att1", ownerId: "owner" } as unknown as FAttachment;
+const note = { noteId: "noteY", getIcon: () => "bx bx-note" } as unknown as FNote;
+const attachment = {
+ attachmentId: "att1",
+ ownerId: "owner",
+ role: "file",
+ mime: "application/pdf",
+ contentLength: 2048
+} as unknown as FAttachment;
const ATTACHMENT_SCOPE = { viewMode: "attachments", attachmentId: "att1" };
let title: HTMLElement;
@@ -48,13 +70,17 @@ beforeEach(() => {
.mockResolvedValue({ $renderedContent: $(content), type: "pdf" } as never);
});
+function action(title: string): IncludeNoteAction {
+ return { title, icon: `bx bx-${title}`, run: vi.fn() };
+}
+
/** The include box mounted last, and the element it was mounted in. */
function lastMount() {
const call = vi.mocked(content_renderer.mountInteractiveWidget).mock.lastCall;
if (!call) {
throw new Error("Expected a mounted include box.");
}
- const vnode = call[0] as VNode<IncludeNoteProps>;
+ const vnode = call[0] as VNode<IncludeNoteProps & TinyIncludeNoteProps>;
return { type: vnode.type, props: vnode.props, container: call[1] };
}
@@ -99,6 +125,32 @@ describe("loadIncludedNote", () => {
expect(link.createLink).not.toHaveBeenCalled();
expect(content_renderer.mountInteractiveWidget).not.toHaveBeenCalled();
});
+
+ it("mounts a tiny box with the note's path, without rendering the note", async () => {
+ const actions = [ action("edit"), action("open") ];
+ vi.mocked(getNoteActions).mockReturnValue(actions);
+ const section = document.createElement("section");
+ section.className = "include-note";
+ section.dataset.boxSize = "tiny";
+
+ await loadIncludedNote("noteY", $(section));
+
+ expect(link.createLink).toHaveBeenCalledWith("noteY", {
+ showTooltip: false,
+ showNotePath: true
+ });
+ expect(content_renderer.getRenderedContent).not.toHaveBeenCalled();
+ expect(getNoteActions).toHaveBeenCalledWith("noteY");
+ const mount = lastMount();
+ expect(mount.type).toBe(TinyIncludeNote);
+ expect(mount.container.parentElement).toBe(section);
+ expect(mount.props).toEqual({
+ icon: "bx bx-note",
+ title,
+ notePath: "noteY",
+ actions
+ });
+ });
});
describe("loadIncludedAttachment", () => {
@@ -137,6 +189,34 @@ describe("loadIncludedAttachment", () => {
expect(link.createLink).not.toHaveBeenCalled();
expect(content_renderer.mountInteractiveWidget).not.toHaveBeenCalled();
});
+
+ it("mounts a tiny box with the size of the attachment, and its file actions", async () => {
+ const [ openExternally, download ] = [ action("open-externally"), action("download") ];
+ vi.mocked(getOpenExternallyAction).mockReturnValue(openExternally);
+ vi.mocked(getDownloadAction).mockReturnValue(download);
+ const wrapper = createWrapper();
+
+ await loadIncludedAttachment("att1", $(wrapper), "tiny");
+
+ expect(link.createLink).toHaveBeenCalledWith("owner", {
+ showTooltip: false,
+ viewScope: ATTACHMENT_SCOPE
+ });
+ expect(content_renderer.getRenderedContent).not.toHaveBeenCalled();
+ expect(getOpenExternallyAction).toHaveBeenCalledWith(attachment);
+ expect(getDownloadAction).toHaveBeenCalledWith(attachment);
+ const mount = lastMount();
+ expect(mount.type).toBe(TinyIncludeNote);
+ expect(mount.container).toBe(wrapper);
+ expect(mount.props).toEqual({
+ icon: attachmentIcon("file", "application/pdf"),
+ title,
+ description: "2 KiB",
+ notePath: "owner",
+ viewScope: ATTACHMENT_SCOPE,
+ actions: [ openExternally, download ]
+ });
+ });
});
describe("the element an include box is mounted in", () => {
diff --git a/apps/client/src/widgets/type_widgets/text/utils.ts b/apps/client/src/widgets/type_widgets/text/utils.ts
index b010fa64ca..a80f5ac9d8 100644
--- a/apps/client/src/widgets/type_widgets/text/utils.ts
+++ b/apps/client/src/widgets/type_widgets/text/utils.ts
@@ -1,3 +1,4 @@
+import { attachmentIcon } from "@triliumnext/commons";
import { h } from "preact";
import appContext from "../../../components/app_context";
@@ -5,12 +6,33 @@ import content_renderer from "../../../services/content_renderer";
import froca from "../../../services/froca";
import link, { ViewScope } from "../../../services/link";
import utils from "../../../services/utils";
-import IncludeNote, { type IncludeNoteProps } from "./IncludeNote";
+import IncludeNote, { getNoteActions, TinyIncludeNote } from "./IncludeNote";
+/**
+ * Fills an include box with a note. Without a box size of its own, the box takes the one of its
+ * section.
+ */
export async function loadIncludedNote(noteId: string, $el: JQuery<HTMLElement>, boxSize?: string) {
const note = await froca.getNote(noteId);
if (!note) return;
+ const el = $el[0];
+ const size = boxSize ?? getSectionBoxSize(el);
+ if (size === "tiny") {
+ const $link = await link.createLink(note.noteId, {
+ showTooltip: false,
+ showNotePath: true
+ });
+ const box = h(TinyIncludeNote, {
+ icon: note.getIcon(),
+ title: $link[0],
+ notePath: note.noteId,
+ actions: getNoteActions(note.noteId)
+ });
+ await content_renderer.mountInteractiveWidget(box, getWrapper(el));
+ return;
+ }
+
const $link = await link.createLink(note.noteId, {
showTooltip: false,
showNoteIcon: true
@@ -24,16 +46,20 @@ export async function loadIncludedNote(noteId: string, $el: JQuery<HTMLElement>,
mediaEnvironment: "embedded"
});
- await mountIncludeNote($el[0], {
- boxSize,
+ const box = h(IncludeNote, {
+ boxSize: size,
title: $link[0],
content: $renderedContent[0],
contentType: type,
notePath: note.noteId
});
+ await content_renderer.mountInteractiveWidget(box, getWrapper(el));
}
-/** Fills an include box with an embedded attachment, under a title linking to it. */
+/**
+ * Fills an include box with an embedded attachment, under a title linking to it. Without a box
+ * size of its own, the box takes the one of its section.
+ */
export async function loadIncludedAttachment(
attachmentId: string,
$el: JQuery<HTMLElement>,
@@ -42,7 +68,27 @@ export async function loadIncludedAttachment(
const attachment = await froca.getAttachment(attachmentId, true);
if (!attachment) return;
+ const el = $el[0];
+ const size = boxSize ?? getSectionBoxSize(el);
const viewScope: ViewScope = { viewMode: "attachments", attachmentId };
+ if (size === "tiny") {
+ // `attachment_actions` is imported on demand: it imports the image compression dialog.
+ const [ $link, { getDownloadAction, getOpenExternallyAction } ] = await Promise.all([
+ link.createLink(attachment.ownerId, { showTooltip: false, viewScope }),
+ import("../../../services/attachment_actions")
+ ]);
+ const box = h(TinyIncludeNote, {
+ icon: attachmentIcon(attachment.role, attachment.mime),
+ title: $link[0],
+ description: utils.formatSize(attachment.contentLength),
+ notePath: attachment.ownerId,
+ viewScope,
+ actions: [ getOpenExternallyAction(attachment), getDownloadAction(attachment) ]
+ });
+ await content_renderer.mountInteractiveWidget(box, getWrapper(el));
+ return;
+ }
+
const $link = await link.createLink(attachment.ownerId, {
showTooltip: false,
showNoteIcon: true,
@@ -53,8 +99,8 @@ export async function loadIncludedAttachment(
{ interactive: true, mediaEnvironment: "embedded" }
);
- await mountIncludeNote($el[0], {
- boxSize,
+ const box = h(IncludeNote, {
+ boxSize: size,
title: $link[0],
content: $renderedContent[0],
contentType: type,
@@ -62,20 +108,17 @@ export async function loadIncludedAttachment(
viewScope,
isFullscreenOffered: true
});
+ await content_renderer.mountInteractiveWidget(box, getWrapper(el));
}
-/**
- * Mounts an include box in `el`: the `.include-note-wrapper` the editor renders, or a
- * `section.include-note`, whose wrapper is reused or created. Without a box size of its own, the
- * box takes the one of its section.
- */
-async function mountIncludeNote(el: HTMLElement, props: IncludeNoteProps) {
- const boxSize = props.boxSize
- ?? el.closest<HTMLElement>("section.include-note")?.dataset.boxSize;
- const box = h(IncludeNote, { ...props, boxSize });
- await content_renderer.mountInteractiveWidget(box, getWrapper(el));
+function getSectionBoxSize(el: HTMLElement) {
+ return el.closest<HTMLElement>("section.include-note")?.dataset.boxSize;
}
+/**
+ * The element an include box is mounted in: `el` when it is the `.include-note-wrapper` the
+ * editor renders, otherwise the wrapper of the `section.include-note`, reused or created.
+ */
function getWrapper(el: HTMLElement) {
if (el.classList.contains("include-note-wrapper")) {
return el;
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Attachments.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Attachments.html
index f49dda3c5c..5b61fc7fd1 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Attachments.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Attachments.html
@@ -79,6 +79,9 @@
select the embed and use the box size menu in its toolbar.</li>
<li>To open the attachment 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 the embed's title.</li>
+ <li>An embed of size <em>Tiny</em> shows only the title of the attachment and
+ its size, in a single row. Its buttons are <span class="tn-icon bx bx-file-find"></span> <em>Open externally</em> and <span
+ class="tn-icon bx bx-download"></span> <em>Download</em>.</li>
<li>To show an embed 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. To return, press <span class="tn-icon bx bx-exit"></span> <em>Exit fullscreen</em> in
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Include Note.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Include Note.html
index 354bf0169f..2e4b4839f6 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Include Note.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Include Note.html
@@ -9,6 +9,21 @@
by default.</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>
+<h2>Box sizes</h2>
+<p>The box size sets how much of the included note is shown. Choose it in
+ the dialog that includes the note, or later by selecting the include and
+ using the <em>Box size</em> menu in its toolbar. The size chosen in the dialog
+ becomes the default for the next include.</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.</li>
+ <li><em>Small</em> and <em>Medium</em> show the content in a box of limited height,
+ which scrolls.</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.</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>
@@ -16,6 +31,16 @@
at the end of the title row opens the same menu as right-clicking the title:
the other places to open the note in and, for an embedded attachment, the
actions on the attachment.</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>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
diff --git a/docs/User Guide/User Guide/Basic Concepts and Features/Notes/Attachments.md b/docs/User Guide/User Guide/Basic Concepts and Features/Notes/Attachments.md
index 242f912a48..e3ebc62f92 100644
--- a/docs/User Guide/User Guide/Basic Concepts and Features/Notes/Attachments.md
+++ b/docs/User Guide/User Guide/Basic Concepts and Features/Notes/Attachments.md
@@ -43,6 +43,7 @@ An attachment can be shown in the text instead of linked, the way <a class="ref
* To embed an attachment that is already linked, right-click a link to it in a text note being edited and select _Convert link to an embed_, at the end of the menu.
* An embed takes the default box size of included notes. To change its size, select the embed and use the box size menu in its toolbar.
* To open the attachment in a new tab, press the <span class="tn-icon bx bx-link-external"></span> _Open in new tab_ button at the end of the embed's title.
+* An embed of size _Tiny_ shows only the title of the attachment and its size, in a single row. Its buttons are <span class="tn-icon bx bx-file-find"></span> _Open externally_ and <span class="tn-icon bx bx-download"></span> _Download_.
* To show an embed of size _Medium_ or _Full_ on the whole screen, press the <span class="tn-icon bx bx-fullscreen"></span> _Fullscreen_ button at the end of its title. To return, press <span class="tn-icon bx bx-exit"></span> _Exit fullscreen_ in the top-right corner, or <kbd>Esc</kbd>.
* To turn the embed back into a link, select it and press the <span class="tn-icon cke cke-link"></span> _Convert to link_ button in its toolbar. _Convert to link_ also ends the menu that right-clicking the title of the embed or pressing its <span class="tn-icon bx bx-dots-vertical-rounded"></span> _More actions_ button opens.
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 b44e5b3735..f44d02bddd 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
@@ -9,12 +9,26 @@ In the <a class="reference-link" href="Formatting%20toolbar.md">Formatting tool
An [attachment](../../Basic%20Concepts%20and%20Features/Notes/Attachments.md) can be included the same way, from the context menu of a link to it (see _Embedding an attachment_ there).
+## Box sizes
+
+The box size sets how much of the included note is shown. Choose it in the dialog that includes the note, or later by selecting the include and using the _Box size_ menu in its toolbar. The size chosen in the dialog becomes the default for the next include.
+
+* _Tiny_ 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.
+* _Small_ and _Medium_ show the content in a box of limited height, which scrolls.
+* _Full_ shows the whole content.
+* _Expandable_ shows only the title until its <span class="tn-icon bx bx-chevron-right"></span> arrow is pressed.
+
## Opening an included note
To open an included note in a new tab, press the <span class="tn-icon bx bx-link-external"></span> _Open in new tab_ button at the end of its title. An embedded attachment has the same button.
The <span class="tn-icon bx bx-dots-vertical-rounded"></span> _More actions_ button at the end of the title row opens the same menu as right-clicking the title: the other places to open the note in and, for an embedded attachment, the actions on the attachment.
+A _Tiny_ include has these buttons instead, followed by the same _More actions_ button:
+
+* For a note, <span class="tn-icon bx bx-edit"></span> _Quick edit_ opens the note in <a class="reference-link" href="../../Basic%20Concepts%20and%20Features/Navigation/Quick%20edit.md">Quick edit</a>, and <span class="tn-icon bx bx-link-external"></span> _Open in new tab_ opens it in a new tab.
+* For an embedded attachment, <span class="tn-icon bx bx-file-find"></span> _Open externally_ opens the file in another application, and <span class="tn-icon bx bx-download"></span> _Download_ downloads it. The size of the file is shown under its title.
+
## 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.
diff --git a/packages/ckeditor5/src/plugins/include_note_box_size_dropdown.spec.ts b/packages/ckeditor5/src/plugins/include_note_box_size_dropdown.spec.ts
index 3511e94d4e..d11d2233ba 100644
--- a/packages/ckeditor5/src/plugins/include_note_box_size_dropdown.spec.ts
+++ b/packages/ckeditor5/src/plugins/include_note_box_size_dropdown.spec.ts
@@ -86,7 +86,7 @@ describe("IncludeNoteBoxSizeDropdown", () => {
// Extend schema temporarily by bypassing schema checks for test
const includeNote = writer.createElement("includeNote", {
noteId: "test-note",
- boxSize: "tiny"
+ boxSize: "huge"
});
writer.insert(includeNote, root, 0);
writer.setSelection(includeNote, "on");
@@ -97,11 +97,11 @@ describe("IncludeNoteBoxSizeDropdown", () => {
};
const command = editor.commands.get(BOX_SIZE_COMMAND_NAME) as { value: string | null };
- // "tiny" is not in BOX_SIZES, so label falls back to the raw value
- if (command.value === "tiny") {
- expect(dropdownView.buttonView.label).toBe("tiny");
+ // "huge" is not in BOX_SIZES, so label falls back to the raw value
+ if (command.value === "huge") {
+ expect(dropdownView.buttonView.label).toBe("huge");
} else {
- // If schema rejected "tiny", value is null -> label is "Box size"
+ // If schema rejected "huge", value is null -> label is "Box size"
expect(dropdownView.buttonView.label).toBe("Box size");
}
});
diff --git a/packages/ckeditor5/src/plugins/includenote.ts b/packages/ckeditor5/src/plugins/includenote.ts
index fc5f713ade..deb3a205af 100644
--- a/packages/ckeditor5/src/plugins/includenote.ts
+++ b/packages/ckeditor5/src/plugins/includenote.ts
@@ -18,7 +18,7 @@ export const BOX_SIZE_COMMAND_NAME = 'includeNoteBoxSize';
export const EMBED_ATTACHMENT_LINK_COMMAND = 'embedAttachmentLink';
export const CONVERT_EMBED_TO_LINK_COMMAND = 'convertEmbedToLink';
-export const BOX_SIZES = [ 'small', 'medium', 'full', 'expandable' ] as const;
+export const BOX_SIZES = [ 'tiny', 'small', 'medium', 'full', 'expandable' ] as const;
export type BoxSizeValue = typeof BOX_SIZES[number];
@@ -34,6 +34,8 @@ export type BoxSizeValue = typeof BOX_SIZES[number];
*/
export function getBoxSizeLabel(t: (message: string) => string, size: BoxSizeValue): string {
switch (size) {
+ case 'tiny':
+ return t('Tiny');
case 'small':
return t('Small');
case 'medium':
diff --git a/packages/commons/src/lib/options_interface.ts b/packages/commons/src/lib/options_interface.ts
index 0fa24a5971..8e0ab1e645 100644
--- a/packages/commons/src/lib/options_interface.ts
+++ b/packages/commons/src/lib/options_interface.ts
@@ -317,7 +317,7 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActi
experimentalFeatures: string;
// Include note settings
- includeNoteDefaultBoxSize: "small" | "medium" | "full" | "expandable";
+ includeNoteDefaultBoxSize: "tiny" | "small" | "medium" | "full" | "expandable";
// AI / LLM
/** Whether the AI/LLM features (chat sidebar, LLM chat notes) are enabled. */