From 77e6030809cbb2f729ff23f26d4611c4dfd3d7d4 Mon Sep 17 00:00:00 2001 From: yogeshbhutkar Date: Wed, 22 Jan 2025 10:28:11 +0530 Subject: [PATCH 1/6] SpacerControls: Set default height to '0px' when no value is provided --- packages/block-library/src/spacer/controls.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/spacer/controls.js b/packages/block-library/src/spacer/controls.js index b5f73a259419d..a80488346ad26 100644 --- a/packages/block-library/src/spacer/controls.js +++ b/packages/block-library/src/spacer/controls.js @@ -140,7 +140,7 @@ export default function SpacerControls( { label={ __( 'Height' ) } value={ height } onChange={ ( nextHeight ) => - setAttributes( { height: nextHeight } ) + setAttributes( { height: nextHeight ?? '0px' } ) } isResizing={ isResizing } /> From 3be288e0c5bcec7a66298ffc2bf6fef025a0284b Mon Sep 17 00:00:00 2001 From: yogeshbhutkar Date: Thu, 23 Jan 2025 15:46:59 +0530 Subject: [PATCH 2/6] SpacerControls: Set height to an empty string when no value is provided --- packages/block-library/src/spacer/controls.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/spacer/controls.js b/packages/block-library/src/spacer/controls.js index a80488346ad26..486c3065914ac 100644 --- a/packages/block-library/src/spacer/controls.js +++ b/packages/block-library/src/spacer/controls.js @@ -140,7 +140,7 @@ export default function SpacerControls( { label={ __( 'Height' ) } value={ height } onChange={ ( nextHeight ) => - setAttributes( { height: nextHeight ?? '0px' } ) + setAttributes( { height: nextHeight ?? '' } ) } isResizing={ isResizing } /> From 24f958df6ff40d9b1c00b8d2d1c4ad45400cfb0f Mon Sep 17 00:00:00 2001 From: yogeshbhutkar Date: Tue, 28 Jan 2025 15:45:53 +0530 Subject: [PATCH 3/6] fix: deprecation logic to add height if height & width missing --- packages/block-library/src/spacer/controls.js | 2 +- .../block-library/src/spacer/deprecated.js | 80 ++++++++++++------- 2 files changed, 51 insertions(+), 31 deletions(-) diff --git a/packages/block-library/src/spacer/controls.js b/packages/block-library/src/spacer/controls.js index 486c3065914ac..b5f73a259419d 100644 --- a/packages/block-library/src/spacer/controls.js +++ b/packages/block-library/src/spacer/controls.js @@ -140,7 +140,7 @@ export default function SpacerControls( { label={ __( 'Height' ) } value={ height } onChange={ ( nextHeight ) => - setAttributes( { height: nextHeight ?? '' } ) + setAttributes( { height: nextHeight } ) } isResizing={ isResizing } /> diff --git a/packages/block-library/src/spacer/deprecated.js b/packages/block-library/src/spacer/deprecated.js index 79ecc09fe1185..b630d88592135 100644 --- a/packages/block-library/src/spacer/deprecated.js +++ b/packages/block-library/src/spacer/deprecated.js @@ -3,39 +3,59 @@ */ import { useBlockProps } from '@wordpress/block-editor'; -const deprecated = [ - { - attributes: { - height: { - type: 'number', - default: 100, - }, - width: { - type: 'number', - }, +const deprecatedSave = ( { attributes } ) => { + return ( +
+ ); +}; + +const v2 = { + attributes: { + height: { + type: 'string', }, - migrate( attributes ) { - const { height, width } = attributes; - return { - ...attributes, - width: width !== undefined ? `${ width }px` : undefined, - height: height !== undefined ? `${ height }px` : undefined, - }; + }, + isEligible( { height, width } ) { + return height === undefined && width === undefined; + }, + migrate( attributes ) { + return { + ...attributes, + height: '', + }; + }, + save: deprecatedSave, +}; + +const v1 = { + attributes: { + height: { + type: 'number', + default: 100, }, - save( { attributes } ) { - return ( -
- ); + width: { + type: 'number', }, }, -]; + migrate( attributes ) { + const { height, width } = attributes; + return { + ...attributes, + width: width !== undefined ? `${ width }px` : undefined, + height: `${ height }px`, + }; + }, + save: deprecatedSave, +}; + +const deprecated = [ v2, v1 ]; export default deprecated; From 625fcd84bba6e49b9ae1bf998d19584c4e665ae1 Mon Sep 17 00:00:00 2001 From: yogeshbhutkar Date: Tue, 28 Jan 2025 16:02:19 +0530 Subject: [PATCH 4/6] refactor: minimize verbosity while exporting deprecations --- packages/block-library/src/spacer/deprecated.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/block-library/src/spacer/deprecated.js b/packages/block-library/src/spacer/deprecated.js index b630d88592135..0cf4cddb817dd 100644 --- a/packages/block-library/src/spacer/deprecated.js +++ b/packages/block-library/src/spacer/deprecated.js @@ -56,6 +56,4 @@ const v1 = { save: deprecatedSave, }; -const deprecated = [ v2, v1 ]; - -export default deprecated; +export default [ v2, v1 ]; From 237025cdeeb342b711440b128c3b97c5edb2044c Mon Sep 17 00:00:00 2001 From: yogeshbhutkar Date: Tue, 28 Jan 2025 16:37:29 +0530 Subject: [PATCH 5/6] fix: add width property to spacer deprecation schema for v2 --- packages/block-library/src/spacer/deprecated.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/block-library/src/spacer/deprecated.js b/packages/block-library/src/spacer/deprecated.js index 0cf4cddb817dd..543cd7f248edf 100644 --- a/packages/block-library/src/spacer/deprecated.js +++ b/packages/block-library/src/spacer/deprecated.js @@ -22,6 +22,9 @@ const v2 = { height: { type: 'string', }, + width: { + type: 'string', + }, }, isEligible( { height, width } ) { return height === undefined && width === undefined; From 378a1da35fe7053249886f8afd8aeafc55f8a312 Mon Sep 17 00:00:00 2001 From: yogeshbhutkar Date: Wed, 29 Jan 2025 12:52:01 +0530 Subject: [PATCH 6/6] fix: set height to an empty string when nextHeight is null or undefined --- packages/block-library/src/spacer/controls.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/spacer/controls.js b/packages/block-library/src/spacer/controls.js index b5f73a259419d..486c3065914ac 100644 --- a/packages/block-library/src/spacer/controls.js +++ b/packages/block-library/src/spacer/controls.js @@ -140,7 +140,7 @@ export default function SpacerControls( { label={ __( 'Height' ) } value={ height } onChange={ ( nextHeight ) => - setAttributes( { height: nextHeight } ) + setAttributes( { height: nextHeight ?? '' } ) } isResizing={ isResizing } />