diff --git a/packages/block-editor/src/hooks/border.js b/packages/block-editor/src/hooks/border.js index 30c16339c27fe8..4c7fe9ca7367f5 100644 --- a/packages/block-editor/src/hooks/border.js +++ b/packages/block-editor/src/hooks/border.js @@ -57,10 +57,7 @@ export function BorderPanel( props ) { return null; } - const defaultBorderControls = getBlockSupport( props.name, [ - BORDER_SUPPORT_KEY, - '__experimentalDefaultControls', - ] ); + const defaultBorderControls = getDefaultBorderControls( props.name ); const createResetAllFilter = ( borderAttribute, @@ -213,3 +210,29 @@ export function removeBorderAttribute( style, attribute ) { }, } ); } + +/** + * Returns an object containing default controls. A control key with a `true` value + * means that the control will be shown in the panel by default. + * + * @param {string|Object} blockType Block name or block type object. + * + * @return {Object} Default controls key/value pairs. + */ +export function getDefaultBorderControls( blockType ) { + const defaultBorderControls = getBlockSupport( blockType, [ + BORDER_SUPPORT_KEY, + '__experimentalDefaultControls', + ] ); + + if ( defaultBorderControls === 'all' ) { + return { + color: true, + radius: true, + width: true, + style: true, + }; + } + + return defaultBorderControls; +} diff --git a/packages/block-editor/src/hooks/color.js b/packages/block-editor/src/hooks/color.js index fcbd79e92596b5..18aa20ea77a64f 100644 --- a/packages/block-editor/src/hooks/color.js +++ b/packages/block-editor/src/hooks/color.js @@ -489,10 +489,7 @@ export function ColorEdit( props ) { const enableContrastChecking = Platform.OS === 'web' && ! gradient && ! style?.color?.gradient; - const defaultColorControls = getBlockSupport( props.name, [ - COLOR_SUPPORT_KEY, - '__experimentalDefaultControls', - ] ); + const defaultColorControls = getDefaultColorControls( props.name ); return ( ( newAttributes ) => ( { ...newAttributes, @@ -196,3 +193,28 @@ export function useIsDimensionsSupportValid( blockName, feature ) { return true; } + +/** + * Returns an object containing default controls. A control key with a `true` value + * means that the control will be shown in the panel by default. + * + * @param {string|Object} blockType Block name or block type object. + * + * @return {Object} Default controls key/value pairs. + */ +export function getDefaultDimensionsControls( blockType ) { + const defaultDimensionsControls = getBlockSupport( blockType, [ + SPACING_SUPPORT_KEY, + '__experimentalDefaultControls', + ] ); + + if ( defaultDimensionsControls === 'all' ) { + return { + padding: true, + margin: true, + blockGap: true, + }; + } + + return defaultDimensionsControls; +} diff --git a/packages/block-editor/src/hooks/typography.js b/packages/block-editor/src/hooks/typography.js index c3959b8a1b3cd5..4cb43356cd746b 100644 --- a/packages/block-editor/src/hooks/typography.js +++ b/packages/block-editor/src/hooks/typography.js @@ -94,10 +94,7 @@ export function TypographyPanel( props ) { if ( isDisabled || ! isSupported ) return null; - const defaultControls = getBlockSupport( props.name, [ - TYPOGRAPHY_SUPPORT_KEY, - '__experimentalDefaultControls', - ] ); + const defaultControls = getDefaultTypographyControls( props.name ); const createResetAllFilter = ( attribute ) => ( newAttributes ) => ( { ...newAttributes, @@ -250,3 +247,32 @@ function useIsTypographyDisabled( props = {} ) { return configs.filter( Boolean ).length === configs.length; } + +/** + * Returns an object containing default controls. A control key with a `true` value + * means that the control will be shown in the panel by default. + * + * @param {string|Object} blockType Block name or block type object. + * + * @return {Object} Default controls key/value pairs. + */ +export function getDefaultTypographyControls( blockType ) { + const defaultTypographyControls = getBlockSupport( blockType, [ + TYPOGRAPHY_SUPPORT_KEY, + '__experimentalDefaultControls', + ] ); + + if ( defaultTypographyControls === 'all' ) { + return { + fontFamily: true, + fontSize: true, + fontAppearance: true, + lineHeight: true, + textDecoration: true, + textTransform: true, + letterSpacing: true, + }; + } + + return defaultTypographyControls; +}