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/media player: use full UI for full-detail attachments
Adorian Doran75c954d2cbb5
diff --git a/apps/client/src/services/content_renderer.spec.ts b/apps/client/src/services/content_renderer.spec.tsindex a8aa3cf0b7..2eff4cd441 100644--- a/apps/client/src/services/content_renderer.spec.ts+++ b/apps/client/src/services/content_renderer.spec.ts@@ -327,6 +327,16 @@ describe("getRenderedContent file rendering", () => {expect($renderedContent.find(".file-footer").length).toBe(0);});+ it("mounts the full media player when the caller gives the media a pane of its own", async () => {+ const note = buildNote({ title: "A", type: "file" });+ note.mime = "audio/mpeg";+ const { $renderedContent } = await getRenderedContent(note, { mediaEnvironment: "standalone" });+ expect(mediaPreviewComponent).toHaveBeenCalledWith(+ expect.objectContaining({ entity: note, environment: "standalone" }), expect.anything());+ // Unlike an embed, the full player leaves Download / Open to the footer below it.+ expect($renderedContent.find(".file-footer").length).toBe(1);+ });+it("keeps the footer for a media preview, and for the file types that have no player", async () => {const video = buildNote({ title: "V", type: "file" });video.mime = "video/mp4";diff --git a/apps/client/src/services/content_renderer.ts b/apps/client/src/services/content_renderer.tsindex 71ee7a210e..033d81c7e0 100644--- a/apps/client/src/services/content_renderer.ts+++ b/apps/client/src/services/content_renderer.ts@@ -57,11 +57,12 @@ export interface RenderOptions {/*** How audio/video renders. `preview` (the default) shows a click-to-load placeholder, so that a screen* full of media notes doesn't have every one of them streaming from the server at once; `embedded`- * mounts the full player straight away. `native` emits a plain `<audio>`/`<video>` element instead of- * the player, for the callers that serialize the rendered content into an HTML string or into a separate- * document (presentation, printing) — a mounted player would be dead markup there.+ * mounts the compact player straight away; `standalone` mounts the full one, for a host that gives the+ * media a pane of its own (the attachment full-detail view). `native` emits a plain `<audio>`/`<video>`+ * element instead of the player, for the callers that serialize the rendered content into an HTML string+ * or into a separate document (presentation, printing) — a mounted player would be dead markup there.*/- mediaEnvironment?: "preview" | "embedded" | "native";+ mediaEnvironment?: MediaEnvironment | "native";/*** If enabled, PDFs render with the pdf.js toolbar (zoom, page navigation, print, download).* Off by default so that lightweight previews (attachment list, tooltips, embeds) stay bare;@@ -382,7 +383,7 @@ async function renderFile(entity: FNote | FAttachment, type: string, $renderedCo/*** Mounts the Trilium media player for an audio/video note or attachment. In a `preview` it starts as a* placeholder and only loads the media once the user presses play (see {@link MediaPreview}); an `embedded`- * one loads straight away. Like every other mounted widget here, the embedding caller must tear it down via+ * or `standalone` one loads straight away. Like every other mounted widget here, the caller must tear it down via* {@link disposeInteractiveContent} — otherwise the Preact root leaks and its media keeps playing.*/async function renderMedia(entity: FNote | FAttachment, environment: MediaEnvironment, $content: JQuery<HTMLElement>) {diff --git a/apps/client/src/widgets/type_widgets/Attachment.tsx b/apps/client/src/widgets/type_widgets/Attachment.tsxindex b6f1acde31..e66a924c93 100644--- a/apps/client/src/widgets/type_widgets/Attachment.tsx+++ b/apps/client/src/widgets/type_widgets/Attachment.tsx@@ -169,8 +169,12 @@ function AttachmentInfo({ attachment, isFullDetail, ownerNote, noteContext, viewfunction refresh() {if (!isZoomableImage) {- // The full-detail view gets the pdf.js toolbar; list-view previews stay bare.- content_renderer.getRenderedContent(attachment, { pdfToolbar: !!isFullDetail })+ // The full-detail view has a pane to itself, so it gets the pdf.js toolbar and the full media+ // player; a list-view preview stays bare and click-to-play.+ content_renderer.getRenderedContent(attachment, {+ pdfToolbar: !!isFullDetail,+ mediaEnvironment: isFullDetail ? "standalone" : "preview"+ }).then(({ $renderedContent }) => {disposeContent();contentWrapper.current?.replaceChildren(...$renderedContent);diff --git a/apps/client/src/widgets/type_widgets/file/MediaPreview.spec.tsx b/apps/client/src/widgets/type_widgets/file/MediaPreview.spec.tsxindex b4017192ea..86cf873789 100644--- a/apps/client/src/widgets/type_widgets/file/MediaPreview.spec.tsx+++ b/apps/client/src/widgets/type_widgets/file/MediaPreview.spec.tsx@@ -111,7 +111,7 @@ describe("MediaPreview", () => {});describe("compact audio chrome", () => {- /** The compact chrome is worn everywhere but the note detail — an activated preview and an embed alike. */+ /** The compact chrome is worn everywhere but a standalone player — an activated preview and an embed alike. */const renderCompactAudio = async (environment: "preview" | "embedded") => {await act(async () => render(<MediaPreview entity={audioNote} environment={environment} />, container));if (environment === "preview") {@@ -142,7 +142,7 @@ describe("MediaPreview", () => {expect.objectContaining({ compact: true }), expect.anything());});- it("leaves the note detail with the full controls and the icon", async () => {+ it("leaves a standalone player with the full controls and the icon", async () => {await act(async () => render(<MediaPreview entity={audioNote} environment="standalone" />, container));expect(container.querySelector(".media-compact")).toBeNull();@@ -188,7 +188,7 @@ describe("MediaPreview", () => {expect(container.querySelector(".bx-fullscreen")).toBeNull();});- it("leaves the note detail with the full overlay", async () => {+ it("leaves a standalone player with the full overlay", async () => {await act(async () => render(<MediaPreview entity={videoNote} environment="standalone" />, container));expect(container.querySelector(".media-compact-row")).toBeNull();diff --git a/apps/client/src/widgets/type_widgets/file/media_environment.ts b/apps/client/src/widgets/type_widgets/file/media_environment.tsindex d4db6eb60d..f178672391 100644--- a/apps/client/src/widgets/type_widgets/file/media_environment.ts+++ b/apps/client/src/widgets/type_widgets/file/media_environment.ts@@ -1,7 +1,7 @@/**- * Where a media player is being rendered. The note detail is `standalone`; a note included in a text note- * or embedded in a canvas is `embedded`; a lightweight preview such as a collection tile or an attachment- * list is `preview`.+ * Where a media player is being rendered. A pane of its own — the note detail, or an attachment opened in+ * full detail — is `standalone`; a note included in a text note or embedded in a canvas is `embedded`; a+ * lightweight preview such as a collection tile or an attachment list is `preview`.*/export type MediaEnvironment = "standalone" | "embedded" | "preview";@@ -14,7 +14,7 @@ export function loadsEagerly(environment: MediaEnvironment): boolean {return environment !== "preview";}-/** How much a mounted player may buffer ahead: only the note detail is worth pre-loading in full. */+/** How much a mounted player may buffer ahead: only a player with a pane of its own is worth pre-loading in full. */export function preloadFor(environment: MediaEnvironment): "auto" | "metadata" {return environment === "standalone" ? "auto" : "metadata";}@@ -34,8 +34,8 @@ export function playerRootClasses(environment: MediaEnvironment): string {}/**- * Whether the player wears its compact chrome: only the note detail has room for the full control set, so- * everywhere else keeps just what a small host needs — play, seek, volume — and drops the rest.+ * Whether the player wears its compact chrome: only a player with a pane of its own has room for the full+ * control set, so everywhere else keeps just what a small host needs — play, seek, volume — and drops the rest.*/export function usesCompactControls(environment: MediaEnvironment): boolean {return environment !== "standalone";