From b641bf4f56f870d24d955df4712a55f633eb421f Mon Sep 17 00:00:00 2001 From: Carolina Nymark Date: Mon, 2 Oct 2023 13:04:28 +0200 Subject: [PATCH 1/2] Add a default value to the ImageFill block attribute --- packages/block-library/src/media-text/block.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/media-text/block.json b/packages/block-library/src/media-text/block.json index cdeb4ce13e8f51..93ef8588aadc10 100644 --- a/packages/block-library/src/media-text/block.json +++ b/packages/block-library/src/media-text/block.json @@ -85,7 +85,8 @@ "type": "string" }, "imageFill": { - "type": "boolean" + "type": "boolean", + "default": false }, "focalPoint": { "type": "object" From 0a57ff09d2b34bd882343565524b36b405a2bbe7 Mon Sep 17 00:00:00 2001 From: Carolina Nymark Date: Tue, 3 Oct 2023 07:45:56 +0200 Subject: [PATCH 2/2] Try to add a deprecation and update fixtures --- .../src/media-text/deprecated.js | 142 +++++++++++++++++- .../fixtures/blocks/core__media-text.json | 3 +- .../core__media-text__image-alt-no-align.json | 3 +- 3 files changed, 143 insertions(+), 5 deletions(-) diff --git a/packages/block-library/src/media-text/deprecated.js b/packages/block-library/src/media-text/deprecated.js index d03659022b95b4..ed0e6bb4352f84 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,14 @@ const v6Attributes = { }, }; +//v7 adds allowedBlocks. +const v7Attributes = { + ...v6Attributes, + allowedBlocks: { + type: 'array', + }, +}; + const v4ToV5Supports = { anchor: true, align: [ 'wide', 'full' ], @@ -237,6 +245,134 @@ const v6Supports = { }, }; +//v7 adds color: heading: true. +const v7Supports = { + ...v6Supports, + color: { + gradients: true, + heading: true, + link: true, + __experimentalDefaultControls: { + background: true, + text: true, + }, + }, +}; + +// Version where the imageFill default value is undefined. +// See: https://github.com/WordPress/gutenberg/pull/54965 +const v7 = { + attributes: v7Attributes, + supports: v7Supports, + 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 = classnames( { + [ `wp-image-${ mediaId }` ]: mediaId && mediaType === 'image', + [ `size-${ mediaSizeSlug }` ]: mediaId && mediaType === 'image', + } ); + + let image = ( + { + ); + + if ( href ) { + image = ( + + { image } + + ); + } + + const mediaTypeRenders = { + image: () => image, + video: () =>