From a2cc15843c315601feabfeb3bee8dedcac917b9f Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Thu, 19 May 2022 10:55:06 +1000 Subject: [PATCH] Try moving the default value to sit under the blockGap key in spacing, updated useCustomSides to support an object --- lib/block-supports/layout.php | 2 +- packages/block-editor/src/hooks/dimensions.js | 10 ++++++++-- packages/block-editor/src/layouts/flex.js | 2 +- packages/block-library/src/columns/block.json | 7 +++---- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index 6fe78cbbe6042..b3fca703fee59 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -185,7 +185,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { $gap_value = $gap_value && preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ? null : $gap_value; } - $fallback_gap_value = _wp_array_get( $block_type->supports, array( 'spacing', '__experimentalDefaultValues', 'blockGap' ), '0.5em' ); + $fallback_gap_value = _wp_array_get( $block_type->supports, array( 'spacing', 'blockGap', 'default' ), '0.5em' ); // If a block's block.json skips serialization for spacing or spacing.blockGap, // don't apply the user-defined value to the styles. diff --git a/packages/block-editor/src/hooks/dimensions.js b/packages/block-editor/src/hooks/dimensions.js index 9252844d8b576..bfca065c7fbed 100644 --- a/packages/block-editor/src/hooks/dimensions.js +++ b/packages/block-editor/src/hooks/dimensions.js @@ -162,7 +162,7 @@ const useIsDimensionsDisabled = ( props = {} ) => { * @param {string} blockName Block name. * @param {string} feature The feature custom sides relate to e.g. padding or margins. * - * @return {Object} Sides supporting custom margin. + * @return {string[]} Sides supporting custom margin. */ export function useCustomSides( blockName, feature ) { const support = getBlockSupport( blockName, SPACING_SUPPORT_KEY ); @@ -172,7 +172,13 @@ export function useCustomSides( blockName, feature ) { return; } - return support[ feature ]; + if ( Array.isArray( support[ feature ] ) ) { + return support[ feature ]; + } + + if ( support[ feature ]?.sides ) { + return support[ feature ].sides; + } } /** diff --git a/packages/block-editor/src/layouts/flex.js b/packages/block-editor/src/layouts/flex.js index 4b82f67d056d8..1c6a9d5e46328 100644 --- a/packages/block-editor/src/layouts/flex.js +++ b/packages/block-editor/src/layouts/flex.js @@ -113,8 +113,8 @@ export default { const fallbackValue = getBlockSupport( blockName, [ 'spacing', - '__experimentalDefaultValues', 'blockGap', + 'default', ] ) || '0.5em'; const hasBlockGapStylesSupport = blockGapSupport !== null; diff --git a/packages/block-library/src/columns/block.json b/packages/block-library/src/columns/block.json index 95b44634fa702..d655f4dd5be63 100644 --- a/packages/block-library/src/columns/block.json +++ b/packages/block-library/src/columns/block.json @@ -28,14 +28,13 @@ } }, "spacing": { - "blockGap": true, + "blockGap": { + "default": "2em" + }, "margin": [ "top", "bottom" ], "padding": true, "__experimentalDefaultControls": { "padding": true - }, - "__experimentalDefaultValues": { - "blockGap": "2em" } }, "__experimentalLayout": {