Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/text editor/transclusion: mark excerpts with a badge
Adorian Doran41b45301cf1b
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex f7bd220663..470a895bd8 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -4600,6 +4600,8 @@"copy_other": "Copy reference to these {{count}} blocks","broken": "Broken reference","not_found": "A referenced block could not be found. It might have been deleted.",- "untitled": "Block"+ "untitled": "Block",+ "excerpt": "Excerpt",+ "excerpt_description": "You are currently seeing just a fragment of this note. Press the {{icon}} button to open the entire note in a new tab."}}diff --git a/apps/client/src/widgets/layout/NoteBadges.css b/apps/client/src/widgets/layout/NoteBadges.cssindex aa8d8d6f96..efd8c3e207 100644--- a/apps/client/src/widgets/layout/NoteBadges.css+++ b/apps/client/src/widgets/layout/NoteBadges.css@@ -24,6 +24,10 @@&.doc-url-badge {--color: var(--badge-doc-url-background-color);}&.execute-badge {--color: var(--badge-execute-background-color);}&.snippet-badge {--color: var(--badge-snippet-background-color);}+ &.excerpt-badge {+ --color: var(--main-border-color);+ color: var(--main-text-color);+ }&.save-status-badge {--default-opacity: 0.4;opacity: var(--default-opacity);diff --git a/apps/client/src/widgets/type_widgets/text/ContentEmbed.spec.tsx b/apps/client/src/widgets/type_widgets/text/ContentEmbed.spec.tsxindex b917842615..815f7f839a 100644--- a/apps/client/src/widgets/type_widgets/text/ContentEmbed.spec.tsx+++ b/apps/client/src/widgets/type_widgets/text/ContentEmbed.spec.tsx@@ -21,7 +21,9 @@ const {removeIndividualBinding: vi.fn()}));-vi.mock("../../../services/i18n", () => ({ t: (key: string) => key }));+vi.mock("../../../services/i18n", () => ({+ t: (key: string, options?: { icon?: string }) => (options?.icon ? `${key} ${options.icon}` : key)+}));vi.mock("../../../components/app_context", () => ({default: { tabManager: { openTabWithNoteWithHoisting }, triggerCommand }}));@@ -257,6 +259,27 @@ describe("ContentEmbed", () => {.toHaveBeenCalledWith("owner", { below: menu }, ATTACHMENT_SCOPE);});+ it("marks an excerpt, with the icon of the button that opens the whole note", () => {+ renderBox({ viewScope: { block: "blockA:blockB" } });+ const badge = container.querySelector<HTMLElement>(".include-note-badges > .excerpt-badge");+ expect(badge?.textContent).toBe("block_reference.excerpt");+ expect(titleRow()).toContain("include-note-badges");++ const tooltip = badge ? Tooltip.getInstance(badge) : null;+ act(() => tooltip?.show());+ const tooltipText = document.querySelector(".tooltip-inner");+ expect(tooltipText?.textContent?.trim()).toBe("block_reference.excerpt_description");+ expect(tooltipText?.querySelector(".bx.bx-link-external")).not.toBeNull();+ expect(button("include-note-open").className).toContain("bx-link-external");+ act(() => tooltip?.hide());++ for (const viewScope of [ undefined, ATTACHMENT_SCOPE ]) {+ act(() => render(null, container));+ renderBox({ viewScope });+ expect(container.querySelector(".excerpt-badge")).toBeNull();+ }+ });+it("gives its content the screen, and takes it back from the overlay button", async () => {const warn = vi.spyOn(console, "warn").mockImplementation(() => {});const exitFullscreen = vi.fn<() => Promise<void>>(async () => {});diff --git a/apps/client/src/widgets/type_widgets/text/ContentEmbed.tsx b/apps/client/src/widgets/type_widgets/text/ContentEmbed.tsxindex 0f0284a09c..8261d66d3a 100644--- a/apps/client/src/widgets/type_widgets/text/ContentEmbed.tsx+++ b/apps/client/src/widgets/type_widgets/text/ContentEmbed.tsx@@ -10,6 +10,7 @@ import { t } from "../../../services/i18n";import type { ViewScope } from "../../../services/link";import { removeIndividualBinding } from "../../../services/shortcuts";import ActionButton from "../../react/ActionButton";+import { Badge } from "../../react/Badge";import { useFocusWithin } from "../../react/hooks";import Icon from "../../react/Icon";import OverlayControlGroup, { OverlayControlButton } from "../../react/OverlayControlGroup";@@ -99,7 +100,9 @@ export default function ContentEmbed({)}<ContentEmbedTitle title={title} />{/* The content of the embed puts badges here, such as its save status. */}- <div className="note-badges include-note-badges" />+ <div className="note-badges include-note-badges">+ {viewScope?.block && <ExcerptBadge />}+ </div><ContentEmbedActionButtonclassName="include-note-open"action={getOpenInNewTabAction(notePath, viewScope)}@@ -206,7 +209,7 @@ export function getNoteActions(notePath: string): ContentEmbedAction[] {function getOpenInNewTabAction(notePath: string, viewScope?: ViewScope): ContentEmbedAction {return {title: t("common.open_in_new_tab"),- icon: "bx bx-link-external",+ icon: OPEN_IN_NEW_TAB_ICON,run: async () => {await appContext.tabManager.openTabWithNoteWithHoisting(notePath, {viewScope,@@ -217,6 +220,22 @@ function getOpenInNewTabAction(notePath: string, viewScope?: ViewScope): Content};}+const OPEN_IN_NEW_TAB_ICON = "bx bx-link-external";++/** Marks an embed that shows only some blocks of its note, a block reference. */+function ExcerptBadge() {+ return (+ <Badge+ className="excerpt-badge"+ icon="bx bx-crop"+ text={t("block_reference.excerpt")}+ tooltip={t("block_reference.excerpt_description", {+ icon: `<span class="${OPEN_IN_NEW_TAB_ICON}"></span>`+ })}+ />+ );+}+const FOCUSABLE_SELECTOR = "[tabindex], a[href], iframe, webview, "+ ":is(button, input, select, textarea):not(:disabled)";diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Block references.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Block references.htmlindex 776341ecd1..b30f331aa5 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Block references.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Block references.html@@ -22,8 +22,11 @@<h2>Including the referenced blocks</h2><p>To show the referenced blocks inside another note, right-click the linkin a note being edited and select <em>Convert link to an included note</em>.- The include shows only the referenced blocks, not the rest of the note.- Converting the include back to a link keeps the reference.</p>+ The include shows only the referenced blocks, not the rest of the note,+ and marks them with an <em>Excerpt</em> badge in its title. To see the whole+ note, press the <span class="tn-icon bx bx-link-external"></span> button+ in the same title, which opens the note in a new tab. Converting the include+ back to a link keeps the reference.</p><p>To edit the referenced blocks without leaving the note, turn on <em>Editable</em> inthe toolbar of the include, as for any <a class="reference-link" href="#root/_help_nBAXQFj20hS1">Include Note</a>.The changes are saved to the referenced blocks, and the rest of the notediff --git a/docs/User Guide/User Guide/Note Types/Text/Block references.md b/docs/User Guide/User Guide/Note Types/Text/Block references.mdindex 0e46a37970..c590092165 100644--- a/docs/User Guide/User Guide/Note Types/Text/Block references.md+++ b/docs/User Guide/User Guide/Note Types/Text/Block references.md@@ -16,7 +16,7 @@ Clicking a block reference opens the note, scrolls to the referenced blocks and## Including the referenced blocks-To show the referenced blocks inside another note, right-click the link in a note being edited and select _Convert link to an included note_. The include shows only the referenced blocks, not the rest of the note. Converting the include back to a link keeps the reference.+To show the referenced blocks inside another note, right-click the link in a note being edited and select _Convert link to an included note_. The include shows only the referenced blocks, not the rest of the note, and marks them with an _Excerpt_ badge in its title. To see the whole note, press the <span class="tn-icon bx bx-link-external"></span> button in the same title, which opens the note in a new tab. Converting the include back to a link keeps the reference.To edit the referenced blocks without leaving the note, turn on _Editable_ in the toolbar of the include, as for any <a class="reference-link" href="Include%20Note.md">Include Note</a>. The changes are saved to the referenced blocks, and the rest of the note stays as it is.