From ff41b60c9245e6a966c1323a77edc5ca0a7e6456 Mon Sep 17 00:00:00 2001 From: Gary Date: Thu, 15 Apr 2021 15:22:31 +1000 Subject: [PATCH 01/12] Re-implement #24233. --- lib/blocks.php | 2 +- packages/block-library/src/file/block.json | 6 ++ packages/block-library/src/file/edit.js | 79 ++++++++++++++++++- packages/block-library/src/file/editor.scss | 25 ++++++ packages/block-library/src/file/frontend.js | 6 ++ packages/block-library/src/file/index.php | 38 +++++++++ packages/block-library/src/file/inspector.js | 42 +++++++++- packages/block-library/src/file/save.js | 21 +++++ packages/block-library/src/file/style.scss | 4 + packages/block-library/src/file/utils.js | 71 +++++++++++++++++ .../blocks/core__file__pdf-preview.html | 3 + .../blocks/core__file__pdf-preview.json | 18 +++++ .../core__file__pdf-preview.parsed.json | 24 ++++++ .../core__file__pdf-preview.serialized.html | 3 + 14 files changed, 339 insertions(+), 3 deletions(-) create mode 100644 packages/block-library/src/file/frontend.js create mode 100644 packages/block-library/src/file/index.php create mode 100644 packages/block-library/src/file/utils.js create mode 100644 packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.html create mode 100644 packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.json create mode 100644 packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.parsed.json create mode 100644 packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.serialized.html diff --git a/lib/blocks.php b/lib/blocks.php index d22df17405c67..bf62b0a8148d3 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -21,7 +21,6 @@ function gutenberg_reregister_core_block_types() { 'code', 'column', 'columns', - 'file', 'gallery', 'group', 'heading', @@ -53,6 +52,7 @@ function gutenberg_reregister_core_block_types() { 'calendar.php' => 'core/calendar', 'categories.php' => 'core/categories', 'cover.php' => 'core/cover', + 'file.php' => 'core/file', 'latest-comments.php' => 'core/latest-comments', 'latest-posts.php' => 'core/latest-posts', 'legacy-widget.php' => 'core/legacy-widget', diff --git a/packages/block-library/src/file/block.json b/packages/block-library/src/file/block.json index ec42e3e31bf87..a6898e405223c 100644 --- a/packages/block-library/src/file/block.json +++ b/packages/block-library/src/file/block.json @@ -34,6 +34,12 @@ "type": "string", "source": "html", "selector": "a[download]" + }, + "displayPreview": { + "type": "boolean" + }, + "previewHeight": { + "type": "number" } }, "supports": { diff --git a/packages/block-library/src/file/edit.js b/packages/block-library/src/file/edit.js index 766de08b98990..1cc07e47b2075 100644 --- a/packages/block-library/src/file/edit.js +++ b/packages/block-library/src/file/edit.js @@ -10,6 +10,7 @@ import { getBlobByURL, isBlobURL, revokeBlobURL } from '@wordpress/blob'; import { __unstableGetAnimateClassName as getAnimateClassName, withNotices, + ResizableBox, ToolbarButton, } from '@wordpress/components'; import { useSelect, useDispatch } from '@wordpress/data'; @@ -33,6 +34,10 @@ import { store as noticesStore } from '@wordpress/notices'; * Internal dependencies */ import FileBlockInspector from './inspector'; +import { browserSupportsPdfs } from './utils'; + +export const MIN_PREVIEW_HEIGHT = 200; +export const MAX_PREVIEW_HEIGHT = 2000; function ClipboardToolbarButton( { text, disabled } ) { const { createNotice } = useDispatch( noticesStore ); @@ -54,7 +59,13 @@ function ClipboardToolbarButton( { text, disabled } ) { ); } -function FileEdit( { attributes, setAttributes, noticeUI, noticeOperations } ) { +function FileEdit( { + attributes, + isSelected, + setAttributes, + noticeUI, + noticeOperations, +} ) { const { id, fileName, @@ -63,6 +74,8 @@ function FileEdit( { attributes, setAttributes, noticeUI, noticeOperations } ) { textLinkTarget, showDownloadButton, downloadButtonText, + displayPreview, + previewHeight, } = attributes; const [ hasError, setHasError ] = useState( false ); const { media, mediaUpload } = useSelect( @@ -76,6 +89,8 @@ function FileEdit( { attributes, setAttributes, noticeUI, noticeOperations } ) { [ id ] ); + const { toggleSelection } = useDispatch( blockEditorStore ); + useEffect( () => { // Upload a file drag-and-dropped into the editor if ( isBlobURL( href ) ) { @@ -101,11 +116,14 @@ function FileEdit( { attributes, setAttributes, noticeUI, noticeOperations } ) { function onSelectFile( newMedia ) { if ( newMedia && newMedia.url ) { setHasError( false ); + const isPdf = newMedia.url.endsWith( '.pdf' ); setAttributes( { href: newMedia.url, fileName: newMedia.title, textLinkHref: newMedia.url, id: newMedia.id, + displayPreview: isPdf ? true : undefined, + previewHeight: isPdf ? 800 : undefined, } ); } } @@ -138,6 +156,25 @@ function FileEdit( { attributes, setAttributes, noticeUI, noticeOperations } ) { } ); } + function changeDisplayPreview( newValue ) { + setAttributes( { displayPreview: newValue } ); + } + + function handleOnResizeStop( event, direction, elt, delta ) { + toggleSelection( true ); + + const newHeight = parseInt( previewHeight + delta.height, 10 ); + setAttributes( { previewHeight: newHeight } ); + } + + function changePreviewHeight( newValue ) { + const newHeight = Math.max( + parseInt( newValue, 10 ), + MIN_PREVIEW_HEIGHT + ); + setAttributes( { previewHeight: newHeight } ); + } + const attachmentPage = media && media.link; const blockProps = useBlockProps( { @@ -149,6 +186,8 @@ function FileEdit( { attributes, setAttributes, noticeUI, noticeOperations } ) { ), } ); + const displayPreviewInEditor = browserSupportsPdfs() && displayPreview; + if ( ! href || hasError ) { return (
@@ -179,6 +218,10 @@ function FileEdit( { attributes, setAttributes, noticeUI, noticeOperations } ) { changeLinkDestinationOption, changeOpenInNewWindow, changeShowDownloadButton, + displayPreview, + changeDisplayPreview, + previewHeight, + changePreviewHeight, } } /> @@ -195,6 +238,40 @@ function FileEdit( { attributes, setAttributes, noticeUI, noticeOperations } ) { />
+ { displayPreviewInEditor && ( + toggleSelection( false ) } + onResizeStop={ handleOnResizeStop } + showHandle={ isSelected } + > + + { ! isSelected && ( +
+ ) } + + ) }
&, + .wp-block[data-align="right"] > & { + // Stop file block from collapsing when floated. + height: auto; + } + display: flex; + flex-wrap: wrap; justify-content: space-between; align-items: center; margin-bottom: 0; + .components-resizable-box__container { + margin-bottom: 1em; + } + + .wp-block-file__preview { + margin-bottom: 1em; + width: 100%; + height: 100%; + } + + .wp-block-file__preview-overlay { + position: absolute; + top: 0; + right: 0; + bottom: 0; + left: 0; + } + .wp-block-file__content-wrapper { flex-grow: 1; } diff --git a/packages/block-library/src/file/frontend.js b/packages/block-library/src/file/frontend.js new file mode 100644 index 0000000000000..820fdb507ad8e --- /dev/null +++ b/packages/block-library/src/file/frontend.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { hidePdfEmbedsOnUnsupportedBrowsers } from './utils'; + +hidePdfEmbedsOnUnsupportedBrowsers(); diff --git a/packages/block-library/src/file/index.php b/packages/block-library/src/file/index.php new file mode 100644 index 0000000000000..f08cacc142ea7 --- /dev/null +++ b/packages/block-library/src/file/index.php @@ -0,0 +1,38 @@ +queue, true ) ) { + wp_enqueue_script( 'wp-block-library-file', plugins_url( 'file/frontend.js', __FILE__ ) ); + } + } + + return $content; +} + +/** + * Registers the `core/file` block on server. + */ +function register_block_core_file() { + register_block_type_from_metadata( + __DIR__ . '/file', + array( + 'render_callback' => 'render_block_core_file', + ) + ); +} +add_action( 'init', 'register_block_core_file' ); diff --git a/packages/block-library/src/file/inspector.js b/packages/block-library/src/file/inspector.js index 52d8e676376f9..8ad320c680a57 100644 --- a/packages/block-library/src/file/inspector.js +++ b/packages/block-library/src/file/inspector.js @@ -2,9 +2,19 @@ * WordPress dependencies */ import { __ } from '@wordpress/i18n'; -import { PanelBody, SelectControl, ToggleControl } from '@wordpress/components'; +import { + PanelBody, + RangeControl, + SelectControl, + ToggleControl, +} from '@wordpress/components'; import { InspectorControls } from '@wordpress/block-editor'; +/** + * Internal dependencies + */ +import { MIN_PREVIEW_HEIGHT, MAX_PREVIEW_HEIGHT } from './edit'; + export default function FileBlockInspector( { hrefs, openInNewWindow, @@ -12,6 +22,10 @@ export default function FileBlockInspector( { changeLinkDestinationOption, changeOpenInNewWindow, changeShowDownloadButton, + displayPreview, + changeDisplayPreview, + previewHeight, + changePreviewHeight, } ) { const { href, textLinkHref, attachmentPage } = hrefs; @@ -26,6 +40,32 @@ export default function FileBlockInspector( { return ( <> + { href.endsWith( '.pdf' ) && ( + + + + + ) } + { displayPreview && ( + <> + + + ) } { ! RichText.isEmpty( fileName ) && ( -1 ) { + return false; + } + + // Android tablets are the noteable exception. + if ( window.navigator.userAgent.indexOf( 'Android' ) > -1 ) { + return false; + } + + // iPad pretends to be a Mac. + if ( + window.navigator.userAgent.indexOf( 'Macintosh' ) > -1 && + window.navigator.maxTouchPoints && + window.navigator.maxTouchPoints > 2 + ) { + return false; + } + + // IE only supports PDFs when there's an ActiveX object available for it. + if ( + !! ( window.ActiveXObject || 'ActiveXObject' in window ) && + ! ( + createActiveXObject( 'AcroPDF.PDF' ) || + createActiveXObject( 'PDF.PdfCtrl' ) + ) + ) { + return false; + } + + return true; +}; + +/** + * Helper function for creating ActiveX objects, catching any errors that are thrown + * when it's generated. + * + * @param {string} type The name of the ActiveX object to create. + * @return {window.ActiveXObject|undefined} The generated ActiveXObject, or null if it failed. + */ +const createActiveXObject = function ( type ) { + let ax; + try { + ax = new window.ActiveXObject( type ); + } catch ( e ) { + ax = undefined; + } + return ax; +}; + +/** + * Hides all .wp-block-file__embed elements on the document. This function is only intended + * to be run on the front-end, it may have weird side effects running in the block editor. + */ +export const hidePdfEmbedsOnUnsupportedBrowsers = function () { + if ( ! browserSupportsPdfs() ) { + const embeds = document.getElementsByClassName( + 'wp-block-file__embed' + ); + Array.prototype.forEach.call( embeds, function ( embed ) { + embed.style.display = 'none'; + } ); + } +}; diff --git a/packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.html b/packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.html new file mode 100644 index 0000000000000..3188d9ae405c9 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.html @@ -0,0 +1,3 @@ + + + diff --git a/packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.json b/packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.json new file mode 100644 index 0000000000000..343acaabb0f2a --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.json @@ -0,0 +1,18 @@ +[ + { + "clientId": "_clientId_0", + "name": "core/file", + "isValid": true, + "attributes": { + "href": "http://localhost:8888/wp-content/uploads/2021/04/yolo.pdf", + "fileName": "yolo", + "textLinkHref": "http://localhost:8888/wp-content/uploads/2021/04/yolo.pdf", + "showDownloadButton": true, + "downloadButtonText": "Download", + "displayPreview": true, + "previewHeight": 370 + }, + "innerBlocks": [], + "originalContent": "" + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.parsed.json b/packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.parsed.json new file mode 100644 index 0000000000000..62502cdebd80e --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.parsed.json @@ -0,0 +1,24 @@ +[ + { + "blockName": "core/file", + "attrs": { + "href": "http://localhost:8888/wp-content/uploads/2021/04/yolo.pdf", + "displayPreview": true, + "previewHeight": 370 + }, + "innerBlocks": [], + "innerHTML": "\n\n", + "innerContent": [ + "\n\n" + ] + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n", + "innerContent": [ + "\n" + ] + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.serialized.html b/packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.serialized.html new file mode 100644 index 0000000000000..3188d9ae405c9 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.serialized.html @@ -0,0 +1,3 @@ + + + From a1fc013c67ef36fb2cba635fd39174d6c2d76bec Mon Sep 17 00:00:00 2001 From: Gary Date: Thu, 15 Apr 2021 15:46:16 +1000 Subject: [PATCH 02/12] Linting. --- lib/blocks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/blocks.php b/lib/blocks.php index bf62b0a8148d3..a595998b3d186 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -52,7 +52,7 @@ function gutenberg_reregister_core_block_types() { 'calendar.php' => 'core/calendar', 'categories.php' => 'core/categories', 'cover.php' => 'core/cover', - 'file.php' => 'core/file', + 'file.php' => 'core/file', 'latest-comments.php' => 'core/latest-comments', 'latest-posts.php' => 'core/latest-posts', 'legacy-widget.php' => 'core/legacy-widget', From 7db1432fd43a5f857f5b5facf494744c91ec63e3 Mon Sep 17 00:00:00 2001 From: Gary Date: Fri, 16 Apr 2021 14:41:13 +1000 Subject: [PATCH 03/12] Build the final frontend.js file from the transpiled version, not the src version. --- webpack.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webpack.config.js b/webpack.config.js index bdd9a59dc6b42..e4c3fe298b095 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -92,7 +92,7 @@ const createEntrypoints = () => { return { ...entries, - [ blockName ]: scriptPath, + [ blockName ]: `./packages/block-library/build-module/${ blockName }/frontend.js`, }; }, {} ); From 42f09913c1ec83196f3e6e37f995d8dc0da51c14 Mon Sep 17 00:00:00 2001 From: Gary Date: Mon, 19 Apr 2021 13:41:54 +1000 Subject: [PATCH 04/12] Rearrange the webpack config for determining block frontend entrypoints. --- webpack.config.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index e4c3fe298b095..e319703d77d5a 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -67,9 +67,9 @@ const stylesTransform = ( content ) => { /* * Matches a block's name in paths in the form - * src//frontend.js + * build-module//frontend.js */ -const blockNameRegex = new RegExp( /(?<=src\/).*(?=(\/frontend))/g ); +const blockNameRegex = new RegExp( /(?<=build-module\/).*(?=(\/frontend))/g ); const createEntrypoints = () => { /* @@ -80,7 +80,7 @@ const createEntrypoints = () => { * Returns an empty array if no files were found. */ const scriptPaths = fastGlob.sync( - './packages/block-library/src/**/frontend.js' + './packages/block-library/build-module/**/frontend.js' ); /* @@ -92,7 +92,7 @@ const createEntrypoints = () => { return { ...entries, - [ blockName ]: `./packages/block-library/build-module/${ blockName }/frontend.js`, + [ blockName ]: scriptPath, }; }, {} ); From c75befeffff6f460c40aa0576feedfc63f8f75e8 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Mon, 19 Apr 2021 13:58:43 +1000 Subject: [PATCH 05/12] Use `wp_script_is()` instead of manually checking the scripts queue. Co-authored-by: Nik Tsekouras --- packages/block-library/src/file/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/file/index.php b/packages/block-library/src/file/index.php index f08cacc142ea7..212bd31228f20 100644 --- a/packages/block-library/src/file/index.php +++ b/packages/block-library/src/file/index.php @@ -16,7 +16,7 @@ function render_block_core_file( $attributes, $content ) { if ( ! empty( $attributes['displayPreview'] ) ) { // Check if it's already enqueued, so we don't add the inline script multiple times. - if ( ! in_array( 'wp-block-library-file', wp_scripts()->queue, true ) ) { + if ( ! wp_script_is( 'wp-block-library-file' ) ) { wp_enqueue_script( 'wp-block-library-file', plugins_url( 'file/frontend.js', __FILE__ ) ); } } From a9bb5ea9446f29ca2f21f219ae9e37afd366cd15 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Mon, 19 Apr 2021 14:00:26 +1000 Subject: [PATCH 06/12] Force the `displayPreview` flag to be boolean when toggling the setting. Co-authored-by: Nik Tsekouras --- packages/block-library/src/file/inspector.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/file/inspector.js b/packages/block-library/src/file/inspector.js index 8ad320c680a57..1a5cb78095a82 100644 --- a/packages/block-library/src/file/inspector.js +++ b/packages/block-library/src/file/inspector.js @@ -51,7 +51,7 @@ export default function FileBlockInspector( { ) : null } - checked={ displayPreview } + checked={ !! displayPreview } onChange={ changeDisplayPreview } /> Date: Mon, 19 Apr 2021 14:09:04 +1000 Subject: [PATCH 07/12] Fix a few potential errors. --- packages/block-library/src/file/block.json | 3 ++- packages/block-library/src/file/save.js | 14 +++++++++----- packages/block-library/src/file/utils.js | 8 ++++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/block-library/src/file/block.json b/packages/block-library/src/file/block.json index a6898e405223c..5135e6b4af853 100644 --- a/packages/block-library/src/file/block.json +++ b/packages/block-library/src/file/block.json @@ -39,7 +39,8 @@ "type": "boolean" }, "previewHeight": { - "type": "number" + "type": "number", + "default": 800 } }, "supports": { diff --git a/packages/block-library/src/file/save.js b/packages/block-library/src/file/save.js index 8d453e85098ea..b7c202d7ef123 100644 --- a/packages/block-library/src/file/save.js +++ b/packages/block-library/src/file/save.js @@ -16,6 +16,14 @@ export default function save( { attributes } ) { previewHeight, } = attributes; + const embedLabel = RichText.isEmpty( fileName ) + ? __( 'PDF embed' ) + : sprintf( + /* translators: %s: filename. */ + __( 'Embed of %s.' ), + fileName + ); + return ( href && (
@@ -29,11 +37,7 @@ export default function save( { attributes } ) { width: '100%', height: `${ previewHeight }px`, } } - aria-label={ sprintf( - /* translators: %s: filename. */ - __( 'Embed of %s.' ), - fileName - ) } + aria-label={ embedLabel } /> ) } diff --git a/packages/block-library/src/file/utils.js b/packages/block-library/src/file/utils.js index cb92787717f5c..e1eed7a2d2808 100644 --- a/packages/block-library/src/file/utils.js +++ b/packages/block-library/src/file/utils.js @@ -4,7 +4,7 @@ * * @return {boolean} Whether or not the browser supports inline PDFs. */ -export const browserSupportsPdfs = function () { +export const browserSupportsPdfs = () => { // Most mobile devices include "Mobi" in their UA. if ( window.navigator.userAgent.indexOf( 'Mobi' ) > -1 ) { return false; @@ -45,7 +45,7 @@ export const browserSupportsPdfs = function () { * @param {string} type The name of the ActiveX object to create. * @return {window.ActiveXObject|undefined} The generated ActiveXObject, or null if it failed. */ -const createActiveXObject = function ( type ) { +const createActiveXObject = ( type ) => { let ax; try { ax = new window.ActiveXObject( type ); @@ -59,12 +59,12 @@ const createActiveXObject = function ( type ) { * Hides all .wp-block-file__embed elements on the document. This function is only intended * to be run on the front-end, it may have weird side effects running in the block editor. */ -export const hidePdfEmbedsOnUnsupportedBrowsers = function () { +export const hidePdfEmbedsOnUnsupportedBrowsers = () => { if ( ! browserSupportsPdfs() ) { const embeds = document.getElementsByClassName( 'wp-block-file__embed' ); - Array.prototype.forEach.call( embeds, function ( embed ) { + Array.from( embeds ).forEach( ( embed ) => { embed.style.display = 'none'; } ); } From e56b133bb7bdd340a207bc3ce35026fe06c26053 Mon Sep 17 00:00:00 2001 From: Gary Date: Mon, 19 Apr 2021 16:12:25 +1000 Subject: [PATCH 08/12] Update fixtures. --- packages/e2e-tests/fixtures/blocks/core__file__new-window.json | 3 ++- .../fixtures/blocks/core__file__no-download-button.json | 3 ++- .../e2e-tests/fixtures/blocks/core__file__no-text-link.json | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/e2e-tests/fixtures/blocks/core__file__new-window.json b/packages/e2e-tests/fixtures/blocks/core__file__new-window.json index 7fd72e9787e65..e151e4def2598 100644 --- a/packages/e2e-tests/fixtures/blocks/core__file__new-window.json +++ b/packages/e2e-tests/fixtures/blocks/core__file__new-window.json @@ -9,7 +9,8 @@ "textLinkHref": "http://localhost:8888/wp-content/uploads/2018/05/keycodes.js", "textLinkTarget": "_blank", "showDownloadButton": true, - "downloadButtonText": "Download" + "downloadButtonText": "Download", + "previewHeight": 800 }, "innerBlocks": [], "originalContent": "" diff --git a/packages/e2e-tests/fixtures/blocks/core__file__no-download-button.json b/packages/e2e-tests/fixtures/blocks/core__file__no-download-button.json index 8f9eca5221419..88055cf897320 100644 --- a/packages/e2e-tests/fixtures/blocks/core__file__no-download-button.json +++ b/packages/e2e-tests/fixtures/blocks/core__file__no-download-button.json @@ -8,7 +8,8 @@ "fileName": "lkjfijwef", "textLinkHref": "http://localhost:8888/wp-content/uploads/2018/05/keycodes.js", "showDownloadButton": false, - "downloadButtonText": "" + "downloadButtonText": "", + "previewHeight": 800 }, "innerBlocks": [], "originalContent": "" diff --git a/packages/e2e-tests/fixtures/blocks/core__file__no-text-link.json b/packages/e2e-tests/fixtures/blocks/core__file__no-text-link.json index cd5f1a47c8475..f40734c03a79f 100644 --- a/packages/e2e-tests/fixtures/blocks/core__file__no-text-link.json +++ b/packages/e2e-tests/fixtures/blocks/core__file__no-text-link.json @@ -7,7 +7,8 @@ "href": "http://localhost:8888/wp-content/uploads/2018/05/keycodes.js", "fileName": "", "showDownloadButton": true, - "downloadButtonText": "Download" + "downloadButtonText": "Download", + "previewHeight": 800 }, "innerBlocks": [], "originalContent": "" From c7f3b38b4597df9ad763e3cb2a23e9b9bc6b60af Mon Sep 17 00:00:00 2001 From: Gary Date: Tue, 20 Apr 2021 15:02:06 +1000 Subject: [PATCH 09/12] A couple of minor fixes. --- packages/block-library/src/file/save.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/file/save.js b/packages/block-library/src/file/save.js index b7c202d7ef123..82d9267f00e13 100644 --- a/packages/block-library/src/file/save.js +++ b/packages/block-library/src/file/save.js @@ -16,7 +16,7 @@ export default function save( { attributes } ) { previewHeight, } = attributes; - const embedLabel = RichText.isEmpty( fileName ) + const pdfEmbedLabel = RichText.isEmpty( fileName ) ? __( 'PDF embed' ) : sprintf( /* translators: %s: filename. */ @@ -37,7 +37,7 @@ export default function save( { attributes } ) { width: '100%', height: `${ previewHeight }px`, } } - aria-label={ embedLabel } + aria-label={ pdfEmbedLabel } /> ) } @@ -45,7 +45,9 @@ export default function save( { attributes } ) { From 7bee495da188f1afb0a3b2961cf97ade249350b0 Mon Sep 17 00:00:00 2001 From: Gary Date: Wed, 21 Apr 2021 09:34:53 +1000 Subject: [PATCH 10/12] Make the default height a little shorter. --- packages/block-library/src/file/block.json | 2 +- packages/e2e-tests/fixtures/blocks/core__file__new-window.json | 2 +- .../fixtures/blocks/core__file__no-download-button.json | 2 +- .../e2e-tests/fixtures/blocks/core__file__no-text-link.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/file/block.json b/packages/block-library/src/file/block.json index 5135e6b4af853..530d856fa7087 100644 --- a/packages/block-library/src/file/block.json +++ b/packages/block-library/src/file/block.json @@ -40,7 +40,7 @@ }, "previewHeight": { "type": "number", - "default": 800 + "default": 600 } }, "supports": { diff --git a/packages/e2e-tests/fixtures/blocks/core__file__new-window.json b/packages/e2e-tests/fixtures/blocks/core__file__new-window.json index e151e4def2598..a304521d4125d 100644 --- a/packages/e2e-tests/fixtures/blocks/core__file__new-window.json +++ b/packages/e2e-tests/fixtures/blocks/core__file__new-window.json @@ -10,7 +10,7 @@ "textLinkTarget": "_blank", "showDownloadButton": true, "downloadButtonText": "Download", - "previewHeight": 800 + "previewHeight": 600 }, "innerBlocks": [], "originalContent": "" diff --git a/packages/e2e-tests/fixtures/blocks/core__file__no-download-button.json b/packages/e2e-tests/fixtures/blocks/core__file__no-download-button.json index 88055cf897320..82ece486ddfec 100644 --- a/packages/e2e-tests/fixtures/blocks/core__file__no-download-button.json +++ b/packages/e2e-tests/fixtures/blocks/core__file__no-download-button.json @@ -9,7 +9,7 @@ "textLinkHref": "http://localhost:8888/wp-content/uploads/2018/05/keycodes.js", "showDownloadButton": false, "downloadButtonText": "", - "previewHeight": 800 + "previewHeight": 600 }, "innerBlocks": [], "originalContent": "" diff --git a/packages/e2e-tests/fixtures/blocks/core__file__no-text-link.json b/packages/e2e-tests/fixtures/blocks/core__file__no-text-link.json index f40734c03a79f..4f69ade5ee8ba 100644 --- a/packages/e2e-tests/fixtures/blocks/core__file__no-text-link.json +++ b/packages/e2e-tests/fixtures/blocks/core__file__no-text-link.json @@ -8,7 +8,7 @@ "fileName": "", "showDownloadButton": true, "downloadButtonText": "Download", - "previewHeight": 800 + "previewHeight": 600 }, "innerBlocks": [], "originalContent": "" From fd00c936ffb2941f16ab912aaa5b2e4c2be11b1d Mon Sep 17 00:00:00 2001 From: Gary Date: Wed, 21 Apr 2021 14:21:16 +1000 Subject: [PATCH 11/12] Fixing fixture file for fixed file (block) fixtures. --- .../fixtures/blocks/core__file__pdf-preview.parsed.json | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.parsed.json b/packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.parsed.json index 62502cdebd80e..5d42872aa618a 100644 --- a/packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.parsed.json +++ b/packages/e2e-tests/fixtures/blocks/core__file__pdf-preview.parsed.json @@ -11,14 +11,5 @@ "innerContent": [ "\n\n" ] - }, - { - "blockName": null, - "attrs": {}, - "innerBlocks": [], - "innerHTML": "\n", - "innerContent": [ - "\n" - ] } ] From 23f3b34b69680f0d04bb77d412dada578da49d3d Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Wed, 21 Apr 2021 18:02:56 +1000 Subject: [PATCH 12/12] Update the default height missed in 7bee495. Co-authored-by: Nik Tsekouras --- packages/block-library/src/file/edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/file/edit.js b/packages/block-library/src/file/edit.js index 1cc07e47b2075..ad76a1c86f55c 100644 --- a/packages/block-library/src/file/edit.js +++ b/packages/block-library/src/file/edit.js @@ -123,7 +123,7 @@ function FileEdit( { textLinkHref: newMedia.url, id: newMedia.id, displayPreview: isPdf ? true : undefined, - previewHeight: isPdf ? 800 : undefined, + previewHeight: isPdf ? 600 : undefined, } ); } }