From 793d32601834d6acf7280a61f7d060ddd3aa2429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Gomes?= Date: Wed, 4 Sep 2024 15:13:08 +0100 Subject: [PATCH] Media & Text: don't use background-image (#64981) * media-text block: don't use background-image * Add PR link to deprecated.js for future reference * Fix PHP indentation * Fix inconsistencies in some fixtures after markup changes * Update PHP tests to match new expected render * Add back old fixtures as new deprecated fixtures * Improve deprecation comment wording in styles Co-authored-by: Nik Tsekouras * Remove 'not contains' checks from PHP tests * Rename new CSS class to is-image-fill-element --------- Co-authored-by: sgomes Co-authored-by: ntsekouras Co-authored-by: skorasaurus --- .../src/media-text/deprecated.js | 162 +++++++++++++++++- packages/block-library/src/media-text/edit.js | 10 +- .../block-library/src/media-text/editor.scss | 4 +- .../src/media-text/image-fill.js | 11 ++ .../block-library/src/media-text/index.php | 96 ++++++----- .../src/media-text/media-container.js | 41 +++-- .../src/media-text/media-container.native.js | 2 - packages/block-library/src/media-text/save.js | 22 +-- .../block-library/src/media-text/style.scss | 21 +++ .../src/media-text/test/image-fill.js | 19 ++ .../src/media-text/test/media-container.js | 24 --- .../blocks/render-block-media-text-test.php | 28 ++- ..._media-text__deprecated-v5.serialized.html | 2 +- ...v7-image-fill-no-focal-point-selected.html | 13 ++ ...v7-image-fill-no-focal-point-selected.json | 29 ++++ ...e-fill-no-focal-point-selected.parsed.json | 29 ++++ ...ll-no-focal-point-selected.serialized.html | 5 + ...-image-fill-with-focal-point-selected.html | 13 ++ ...-image-fill-with-focal-point-selected.json | 33 ++++ ...fill-with-focal-point-selected.parsed.json | 33 ++++ ...-with-focal-point-selected.serialized.html | 5 + .../core__media-text__deprecated-v7.html | 13 ++ .../core__media-text__deprecated-v7.json | 30 ++++ ...ore__media-text__deprecated-v7.parsed.json | 29 ++++ ..._media-text__deprecated-v7.serialized.html | 5 + ...t__image-fill-no-focal-point-selected.html | 9 +- ...t__image-fill-no-focal-point-selected.json | 5 +- ...e-fill-no-focal-point-selected.parsed.json | 5 +- ...ll-no-focal-point-selected.serialized.html | 2 +- ..._image-fill-with-focal-point-selected.html | 9 +- ..._image-fill-with-focal-point-selected.json | 5 +- ...fill-with-focal-point-selected.parsed.json | 5 +- ...-with-focal-point-selected.serialized.html | 2 +- 33 files changed, 575 insertions(+), 146 deletions(-) create mode 100644 packages/block-library/src/media-text/image-fill.js create mode 100644 packages/block-library/src/media-text/test/image-fill.js delete mode 100644 packages/block-library/src/media-text/test/media-container.js create mode 100644 test/integration/fixtures/blocks/core__media-text__deprecated-v7-image-fill-no-focal-point-selected.html create mode 100644 test/integration/fixtures/blocks/core__media-text__deprecated-v7-image-fill-no-focal-point-selected.json create mode 100644 test/integration/fixtures/blocks/core__media-text__deprecated-v7-image-fill-no-focal-point-selected.parsed.json create mode 100644 test/integration/fixtures/blocks/core__media-text__deprecated-v7-image-fill-no-focal-point-selected.serialized.html create mode 100644 test/integration/fixtures/blocks/core__media-text__deprecated-v7-image-fill-with-focal-point-selected.html create mode 100644 test/integration/fixtures/blocks/core__media-text__deprecated-v7-image-fill-with-focal-point-selected.json create mode 100644 test/integration/fixtures/blocks/core__media-text__deprecated-v7-image-fill-with-focal-point-selected.parsed.json create mode 100644 test/integration/fixtures/blocks/core__media-text__deprecated-v7-image-fill-with-focal-point-selected.serialized.html create mode 100644 test/integration/fixtures/blocks/core__media-text__deprecated-v7.html create mode 100644 test/integration/fixtures/blocks/core__media-text__deprecated-v7.json create mode 100644 test/integration/fixtures/blocks/core__media-text__deprecated-v7.parsed.json create mode 100644 test/integration/fixtures/blocks/core__media-text__deprecated-v7.serialized.html diff --git a/packages/block-library/src/media-text/deprecated.js b/packages/block-library/src/media-text/deprecated.js index 1cd1472f876c05..54c6f863311ffe 100644 --- a/packages/block-library/src/media-text/deprecated.js +++ b/packages/block-library/src/media-text/deprecated.js @@ -30,7 +30,7 @@ const v1ToV5ImageFillStyles = ( url, focalPoint ) => { : {}; }; -const v6ImageFillStyles = ( url, focalPoint ) => { +const v6ToV7ImageFillStyles = ( url, focalPoint ) => { return url ? { backgroundImage: `url(${ url })`, @@ -198,6 +198,20 @@ const v6Attributes = { }, }; +const v7Attributes = { + ...v6Attributes, + align: { + type: 'string', + // v7 changed the default for the `align` attribute. + default: 'none', + }, + // New attribute. + useFeaturedImage: { + type: 'boolean', + default: false, + }, +}; + const v4ToV5Supports = { anchor: true, align: [ 'wide', 'full' ], @@ -237,6 +251,148 @@ const v6Supports = { }, }; +const v7Supports = { + ...v6Supports, + __experimentalBorder: { + color: true, + radius: true, + style: true, + width: true, + __experimentalDefaultControls: { + color: true, + radius: true, + style: true, + width: true, + }, + }, + color: { + gradients: true, + heading: true, + link: true, + __experimentalDefaultControls: { + background: true, + text: true, + }, + }, + interactivity: { + clientNavigation: true, + }, +}; + +// Version with 'none' as the default alignment. +// See: https://github.com/WordPress/gutenberg/pull/64981 +const v7 = { + attributes: v7Attributes, + supports: v7Supports, + usesContext: [ 'postId', 'postType' ], + save( { attributes } ) { + const { + isStackedOnMobile, + mediaAlt, + mediaPosition, + mediaType, + mediaUrl, + mediaWidth, + mediaId, + verticalAlignment, + imageFill, + focalPoint, + linkClass, + href, + linkTarget, + rel, + } = attributes; + const mediaSizeSlug = + attributes.mediaSizeSlug || DEFAULT_MEDIA_SIZE_SLUG; + const newRel = ! rel ? undefined : rel; + + const imageClasses = clsx( { + [ `wp-image-${ mediaId }` ]: mediaId && mediaType === 'image', + [ `size-${ mediaSizeSlug }` ]: mediaId && mediaType === 'image', + } ); + + let image = mediaUrl ? ( + { + ) : null; + + if ( href ) { + image = ( + + { image } + + ); + } + + const mediaTypeRenders = { + image: () => image, + video: () =>