From 39a4e40de3b108436fa3cf3ef7bff4a8384786d7 Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Mon, 25 Nov 2024 12:16:28 +0530 Subject: [PATCH 1/2] Fix: Preserve Display Preview State in File Block --- packages/block-library/src/file/edit.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/file/edit.js b/packages/block-library/src/file/edit.js index 937eb3d28eb192..83b9e2f0ea50ce 100644 --- a/packages/block-library/src/file/edit.js +++ b/packages/block-library/src/file/edit.js @@ -128,12 +128,17 @@ function FileEdit( { attributes, isSelected, setAttributes, clientId } ) { } const isPdf = newMedia.url.endsWith( '.pdf' ); + const newDisplayPreview = + attributes.displayPreview !== undefined + ? attributes.displayPreview + : isPdf; + setAttributes( { href: newMedia.url, fileName: newMedia.title, textLinkHref: newMedia.url, id: newMedia.id, - displayPreview: isPdf ? true : undefined, + displayPreview: newDisplayPreview, previewHeight: isPdf ? 600 : undefined, fileId: `wp-block-file--media-${ clientId }`, blob: undefined, From 94bafe1984c2478249046ab461ce28d9cae1d4ae Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Mon, 25 Nov 2024 14:44:51 +0530 Subject: [PATCH 2/2] Fix: Retain PDF-related attributes when replacing files --- packages/block-library/src/file/edit.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/block-library/src/file/edit.js b/packages/block-library/src/file/edit.js index 83b9e2f0ea50ce..838b807507d314 100644 --- a/packages/block-library/src/file/edit.js +++ b/packages/block-library/src/file/edit.js @@ -128,20 +128,21 @@ function FileEdit( { attributes, isSelected, setAttributes, clientId } ) { } const isPdf = newMedia.url.endsWith( '.pdf' ); - const newDisplayPreview = - attributes.displayPreview !== undefined - ? attributes.displayPreview - : isPdf; + const pdfAttributes = { + displayPreview: isPdf + ? attributes.displayPreview ?? true + : undefined, + previewHeight: isPdf ? attributes.previewHeight ?? 600 : undefined, + }; setAttributes( { href: newMedia.url, fileName: newMedia.title, textLinkHref: newMedia.url, id: newMedia.id, - displayPreview: newDisplayPreview, - previewHeight: isPdf ? 600 : undefined, fileId: `wp-block-file--media-${ clientId }`, blob: undefined, + ...pdfAttributes, } ); setTemporaryURL(); }