From 7e5f7b8fae8f4e0a2c9c7de6810faca0115732a3 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 17 Mar 2021 18:39:55 +1000 Subject: [PATCH 01/21] Add border color, style and width support --- lib/block-supports/border.php | 89 ++++++-- lib/class-wp-theme-json.php | 4 + lib/experimental-default-theme.json | 5 +- lib/global-styles.php | 1 + .../components/border-style-control/index.js | 64 ++++++ .../border-style-control/style.scss | 14 ++ packages/block-editor/src/components/index.js | 1 + .../block-editor/src/hooks/border-color.js | 197 ++++++++++++++++++ .../block-editor/src/hooks/border-style.js | 70 +++++++ .../block-editor/src/hooks/border-width.js | 79 +++++++ packages/block-editor/src/hooks/border.js | 33 ++- packages/block-editor/src/hooks/index.js | 1 + packages/block-editor/src/hooks/test/style.js | 10 +- packages/block-editor/src/style.scss | 1 + phpunit/class-wp-theme-json-test.php | 10 +- 15 files changed, 544 insertions(+), 35 deletions(-) create mode 100644 packages/block-editor/src/components/border-style-control/index.js create mode 100644 packages/block-editor/src/components/border-style-control/style.scss create mode 100644 packages/block-editor/src/hooks/border-color.js create mode 100644 packages/block-editor/src/hooks/border-style.js create mode 100644 packages/block-editor/src/hooks/border-width.js diff --git a/lib/block-supports/border.php b/lib/block-supports/border.php index feecb788443a29..8af61efbd63492 100644 --- a/lib/block-supports/border.php +++ b/lib/block-supports/border.php @@ -6,26 +6,36 @@ */ /** - * Registers the style attribute used by the border feature if needed for block types that - * support borders. + * Registers the style attribute used by the border feature if needed for block + * types that support borders. * * @param WP_Block_Type $block_type Block Type. */ function gutenberg_register_border_support( $block_type ) { - // Determine border related features supported. - // Border width, style etc can be added in the future. - $has_border_radius_support = gutenberg_has_border_support( $block_type, 'radius' ); + // Determine if any border related features are supported. + $has_border_color_support = gutenberg_has_border_support( $block_type, 'color' ); + $has_border_support = + gutenberg_has_border_support( $block_type, 'radius' ) || + gutenberg_has_border_support( $block_type, 'style' ) || + gutenberg_has_border_support( $block_type, 'width' ) || + $has_border_color_support; // Setup attributes and styles within that if needed. if ( ! $block_type->attributes ) { $block_type->attributes = array(); } - if ( $has_border_radius_support && ! array_key_exists( 'style', $block_type->attributes ) ) { + if ( $has_border_support && ! array_key_exists( 'style', $block_type->attributes ) ) { $block_type->attributes['style'] = array( 'type' => 'object', ); } + + if ( $has_border_color_support && ! array_key_exists( 'borderColor', $block_type->attributes ) ) { + $block_type->attributes['borderColor'] = array( + 'type' => 'string', + ); + } } /** @@ -38,20 +48,14 @@ function gutenberg_register_border_support( $block_type ) { * @return array Border CSS classes and inline styles. */ function gutenberg_apply_border_support( $block_type, $block_attributes ) { - $border_support = _wp_array_get( $block_type->supports, array( '__experimentalBorder' ), false ); - - if ( - is_array( $border_support ) && - array_key_exists( '__experimentalSkipSerialization', $border_support ) && - $border_support['__experimentalSkipSerialization'] - ) { + if ( gutenberg_skip_border_serialization( $block_type ) ) { return array(); } - // Arrays used to ease addition of further border related features in future. - $styles = array(); + $classes = array(); + $styles = array(); - // Border Radius. + // Border radius. if ( gutenberg_has_border_support( $block_type, 'radius' ) ) { if ( isset( $block_attributes['style']['border']['radius'] ) ) { $border_radius = intval( $block_attributes['style']['border']['radius'] ); @@ -59,11 +63,46 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) { } } - // Border width, style etc can be added here. + // Border style. + if ( gutenberg_has_border_support( $block_type, 'style' ) ) { + if ( isset( $block_attributes['style']['border']['style'] ) ) { + $border_style = $block_attributes['style']['border']['style']; + $styles[] = sprintf( 'border-style: %s;', $border_style ); + } + } + + // Border width. + if ( gutenberg_has_border_support( $block_type, 'width' ) ) { + if ( isset( $block_attributes['style']['border']['width'] ) ) { + $border_width = intval( $block_attributes['style']['border']['width'] ); + $styles[] = sprintf( 'border-width: %dpx;', $border_width ); + } + } + + // Border color. + if ( gutenberg_has_border_support( $block_type, 'color' ) ) { + $has_named_border_color = array_key_exists( 'borderColor', $block_attributes ); + $has_custom_border_color = isset( $block_attributes['style']['border']['color'] ); + + if ( $has_named_border_color || $has_custom_border_color ) { + $classes[] = 'has-border-color'; + } + + if ( $has_named_border_color ) { + $classes[] = sprintf( 'has-%s-border-color', $block_attributes['borderColor'] ); + } elseif ( $has_custom_border_color ) { + $border_color = $block_attributes['style']['border']['color']; + $styles[] = sprintf( 'border-color: %s;', $border_color ); + } + } // Collect classes and styles. $attributes = array(); + if ( ! empty( $classes ) ) { + $attributes['class'] = implode( ' ', $classes ); + } + if ( ! empty( $styles ) ) { $attributes['style'] = implode( ' ', $styles ); } @@ -71,6 +110,22 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) { return $attributes; } +/** + * Checks whether serialization of the current block's border properties should + * occur. + * + * @param WP_Block_type $block_type Block type. + * + * @return boolean + */ +function gutenberg_skip_border_serialization( $block_type ) { + $border_support = _wp_array_get( $block_type->supports, array( '__experimentalBorder' ), false ); + + return is_array( $border_support ) && + array_key_exists( '__experimentalSkipSerialization', $border_support ) && + $border_support['__experimentalSkipSerialization']; +} + /** * Checks whether the current block type supports the feature requested. * diff --git a/lib/class-wp-theme-json.php b/lib/class-wp-theme-json.php index 35da7df75b79a4..efb809de4b924c 100644 --- a/lib/class-wp-theme-json.php +++ b/lib/class-wp-theme-json.php @@ -198,6 +198,10 @@ class WP_Theme_JSON { 'class_suffix' => 'background-color', 'property_name' => 'background-color', ), + array( + 'class_suffix' => 'border-color', + 'property_name' => 'border-color', + ), ), ), array( diff --git a/lib/experimental-default-theme.json b/lib/experimental-default-theme.json index da910ca84747a7..dea9d96966d34e 100644 --- a/lib/experimental-default-theme.json +++ b/lib/experimental-default-theme.json @@ -171,7 +171,10 @@ "units": [ "px", "em", "rem", "vh", "vw" ] }, "border": { - "customRadius": false + "customColor": false, + "customRadius": false, + "customStyle": false, + "customWidth": false } } } diff --git a/lib/global-styles.php b/lib/global-styles.php index 9a935de29145eb..d5ef3e0f7b242c 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -356,6 +356,7 @@ function gutenberg_global_styles_include_support_for_wp_variables( $allow_css, $ $allowed_preset_attributes = array( 'background', 'background-color', + 'border-color', 'color', 'font-family', 'font-size', diff --git a/packages/block-editor/src/components/border-style-control/index.js b/packages/block-editor/src/components/border-style-control/index.js new file mode 100644 index 00000000000000..ee2ad2482cd3c4 --- /dev/null +++ b/packages/block-editor/src/components/border-style-control/index.js @@ -0,0 +1,64 @@ +/** + * WordPress dependencies + */ +import { CustomSelectControl } from '@wordpress/components'; +import { __ } from '@wordpress/i18n'; + +const DEFAULT_STYLE = { + key: 'default', + name: __( 'Default' ), + style: { borderStyle: undefined }, +}; + +const BORDER_STYLES = [ + DEFAULT_STYLE, + { + key: 'none', + name: __( 'None' ), + style: { borderStyle: 'none' }, + }, + { + key: 'solid', + name: __( 'Solid' ), + style: { borderStyle: 'solid' }, + }, + { + key: 'dashed', + name: __( 'Dashed' ), + style: { borderStyle: 'dashed' }, + }, + { + key: 'dotted', + name: __( 'Dotted' ), + style: { borderStyle: 'dotted' }, + }, +]; + +/** + * Control to display border style options. + * + * @param {Object} props Component props. + * @param {Object} props.onChange Handler for changing border style selection. + * @param {Object} props.value Currently selected border style value. + * + * @return {WPElement} Custom border style select control. + */ +export default function BorderStyleControl( { onChange, value } ) { + const style = BORDER_STYLES.find( ( option ) => option.key === value ); + + return ( +
+ ); +} diff --git a/packages/block-editor/src/components/border-style-control/style.scss b/packages/block-editor/src/components/border-style-control/style.scss new file mode 100644 index 00000000000000..827f31bca718c5 --- /dev/null +++ b/packages/block-editor/src/components/border-style-control/style.scss @@ -0,0 +1,14 @@ +.components-border-style-control__select { + margin-bottom: 24px; + + button { + width: 100%; + } + + ul { + li, + li:last-child { + margin: 6px; + } + } +} diff --git a/packages/block-editor/src/components/index.js b/packages/block-editor/src/components/index.js index ac7471317acbe4..dc88ae5a36deb3 100644 --- a/packages/block-editor/src/components/index.js +++ b/packages/block-editor/src/components/index.js @@ -32,6 +32,7 @@ export { BlockVerticalAlignmentToolbar, BlockVerticalAlignmentControl, } from './block-vertical-alignment-control'; +export { default as __experimentalBorderStyleControl } from './border-style-control'; export { default as ButtonBlockerAppender } from './button-block-appender'; export { default as ColorPalette } from './color-palette'; export { default as ColorPaletteControl } from './color-palette/control'; diff --git a/packages/block-editor/src/hooks/border-color.js b/packages/block-editor/src/hooks/border-color.js new file mode 100644 index 00000000000000..c9ab4f4fead23d --- /dev/null +++ b/packages/block-editor/src/hooks/border-color.js @@ -0,0 +1,197 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + +/** + * WordPress dependencies + */ +import { addFilter } from '@wordpress/hooks'; +import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks'; +import { __ } from '@wordpress/i18n'; + +/** + * Internal dependencies + */ +import ColorGradientControl from '../components/colors-gradients/control'; +import { + getColorClassName, + getColorObjectByColorValue, +} from '../components/colors'; +import useEditorFeature from '../components/use-editor-feature'; +import { BORDER_SUPPORT_KEY } from './border'; +import { cleanEmptyObject } from './utils'; + +const BORDER_COLOR_SUPPORT_KEY = 'color'; +const EMPTY_ARRAY = []; + +/** + * Inspector control panel containing the border color related configuration. + * + * There is deliberate overlap between the colors and borders block supports + * relating to border color. It can be argued the border color controls could + * be included within either, or both, the colors and borders panels in the + * inspector controls. If they share the same block attributes it should not + * matter. + * + * @param {Object} props Block properties. + * @return {WPElement} Border color edit element. + */ +export function BorderColorEdit( props ) { + const { + attributes: { borderColor, style }, + setAttributes, + } = props; + const colors = useEditorFeature( 'color.palette' ) || EMPTY_ARRAY; + + const disableCustomColors = ! useEditorFeature( 'color.custom' ); + const disableCustomGradients = ! useEditorFeature( 'color.customGradient' ); + + if ( useIsBorderColorDisabled( props ) ) { + return null; + } + + const onChangeColor = ( value ) => { + const colorObject = getColorObjectByColorValue( colors, value ); + const newStyle = { + ...style, + border: { + ...style?.border, + color: colorObject?.slug ? undefined : value, + }, + }; + + const newNamedColor = colorObject?.slug ? colorObject.slug : undefined; + + setAttributes( { + style: cleanEmptyObject( newStyle ), + borderColor: newNamedColor, + } ); + }; + + return ( +pullquote
before block supports
pullquote
before block supports
pullquote
before block supports
+++ { ! RichText.isEmpty( citation ) && ( + + ) } +
++-+ setAttributes( { + value: nextValue, } ) } - > + aria-label={ __( 'Pullquote text' ) } + placeholder={ + // translators: placeholder text used for the quote + __( 'Add quote' ) + } + textAlign="center" + /> + { shouldShowCitation && ( + identifier="citation" + value={ citation } + aria-label={ __( 'Pullquote citation text' ) } + placeholder={ + // translators: placeholder text used for the citation + __( 'Add citation' ) + } + onChange={ ( nextCitation ) => setAttributes( { - value: nextValue, + citation: nextCitation, } ) } - aria-label={ __( 'Pullquote text' ) } - placeholder={ - // translators: placeholder text used for the quote - __( 'Add quote' ) - } + className="wp-block-pullquote__citation" + __unstableMobileNoFocusOnMount textAlign="center" + __unstableOnSplitAtEnd={ () => + insertBlocksAfter( createBlock( 'core/paragraph' ) ) + } /> - { ( ! RichText.isEmpty( citation ) || isSelected ) && ( - - setAttributes( { - citation: nextCitation, - } ) - } - className="wp-block-pullquote__citation" - __unstableMobileNoFocusOnMount - textAlign="center" - __unstableOnSplitAtEnd={ () => - insertBlocksAfter( - createBlock( 'core/paragraph' ) - ) - } - /> - ) } -
++ diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-3.serialized.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-3.serialized.html index 786f15f7b4293e..96cea0add22c10 100644 --- a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-3.serialized.html +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-3.serialized.html @@ -1,3 +1,3 @@ - -- { ! RichText.isEmpty( citation ) && ( + { shouldShowCitation && ( ) } + + pullquote
diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.html new file mode 100644 index 00000000000000..2c92a8f99a50aa --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.html @@ -0,0 +1,3 @@ + + pullquote
+ diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.json b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.json new file mode 100644 index 00000000000000..dc06d9259d7005 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.json @@ -0,0 +1,15 @@ +[ + { + "clientId": "_clientId_0", + "name": "core/pullquote", + "isValid": true, + "attributes": { + "value": " pullquote
before block supportspullquote
", + "citation": "before block supports", + "customMainColor": "#cd2653", + "textColor": "secondary" + }, + "innerBlocks": [], + "originalContent": "" + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.parsed.json b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.parsed.json new file mode 100644 index 00000000000000..7943fb0c2070b4 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.parsed.json @@ -0,0 +1,23 @@ +[ + { + "blockName": "core/pullquote", + "attrs": { + "mainColor": "accent", + "textColor": "secondary" + }, + "innerBlocks": [], + "innerHTML": "\n pullquote
before block supports\n", + "innerContent": [ + "\n pullquote
before block supports\n" + ] + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n", + "innerContent": [ + "\n" + ] + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.serialized.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.serialized.html new file mode 100644 index 00000000000000..42fa1edc40f0d1 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.serialized.html @@ -0,0 +1,3 @@ + + pullquote
before block supports+ diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.html index 473e6ecefd480d..b3a09d2c22939b 100644 --- a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.html +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.html @@ -1,3 +1,3 @@ - - pullquote
before block supports+ + Pullquote custom color
my citationdiff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.json b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.json index a5e6479043d1a5..0faf80886779d3 100644 --- a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.json +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.json @@ -5,12 +5,17 @@ "isValid": true, "attributes": { "value": " Pullquote custom color
before block supportsPullquote custom color
", - "citation": "my citation", - "customMainColor": "#2207d0", - "textColor": "subtle-background", - "className": "has-background is-style-default" + "citation": "before block supports", + "backgroundColor": "blue", + "textColor": "white", + "style": { + "border": { + "color": "#2207d0" + } + }, + "className": "is-style-default" }, "innerBlocks": [], - "originalContent": "" + "originalContent": " Pullquote custom color
my citation" } ] diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.parsed.json b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.parsed.json index 56004374d15637..5a2208c2278bd0 100644 --- a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.parsed.json +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.parsed.json @@ -2,14 +2,19 @@ { "blockName": "core/pullquote", "attrs": { - "customMainColor": "#2207d0", - "textColor": "subtle-background", - "className": "has-background is-style-default" + "backgroundColor": "blue", + "textColor": "white", + "style": { + "border": { + "color": "#2207d0" + } + }, + "className": "is-style-default" }, "innerBlocks": [], - "innerHTML": "\n Pullquote custom color
before block supports\n", + "innerHTML": "\n Pullquote custom color
my citation\n", "innerContent": [ - "\n Pullquote custom color
before block supports\n" + "\n Pullquote custom color
my citation\n" ] }, { diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.serialized.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.serialized.html index 473e6ecefd480d..b3a09d2c22939b 100644 --- a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.serialized.html +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.serialized.html @@ -1,3 +1,3 @@ - - Pullquote custom color
before block supports+ + Pullquote custom color
my citationdiff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.html new file mode 100644 index 00000000000000..473e6ecefd480d --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.html @@ -0,0 +1,3 @@ + + Pullquote custom color
before block supports+ diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.json b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.json new file mode 100644 index 00000000000000..99bf149d1ace59 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.json @@ -0,0 +1,20 @@ +[ + { + "clientId": "_clientId_0", + "name": "core/pullquote", + "isValid": true, + "attributes": { + "className": "has-background is-style-default", + "style": { + "border": { + "color": "#2207d0" + } + }, + "value": " Pullquote custom color
my citationPullquote custom color
", + "citation": "my citation", + "textColor": "subtle-background" + }, + "innerBlocks": [], + "originalContent": "" + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.parsed.json b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.parsed.json new file mode 100644 index 00000000000000..56004374d15637 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.parsed.json @@ -0,0 +1,24 @@ +[ + { + "blockName": "core/pullquote", + "attrs": { + "customMainColor": "#2207d0", + "textColor": "subtle-background", + "className": "has-background is-style-default" + }, + "innerBlocks": [], + "innerHTML": "\n Pullquote custom color
my citation\n", + "innerContent": [ + "\n Pullquote custom color
my citation\n" + ] + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n", + "innerContent": [ + "\n" + ] + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.serialized.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.serialized.html new file mode 100644 index 00000000000000..c628534e1bc5f6 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.serialized.html @@ -0,0 +1,3 @@ + + Pullquote custom color
my citation+ From 6a9ccab865670c75d2bc79603d9d54fdf5b9ae87 Mon Sep 17 00:00:00 2001 From: ramonjd Pullquote custom color
my citationDate: Wed, 14 Apr 2021 21:28:46 +1000 Subject: [PATCH 13/21] Reverting the deprecated save function to ensure it's 1:1 with the previous save version --- packages/block-library/src/pullquote/deprecated.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/block-library/src/pullquote/deprecated.js b/packages/block-library/src/pullquote/deprecated.js index 3b42383f49e871..dc478e65c2a7d6 100644 --- a/packages/block-library/src/pullquote/deprecated.js +++ b/packages/block-library/src/pullquote/deprecated.js @@ -145,12 +145,7 @@ const deprecated = [ Date: Wed, 14 Apr 2021 21:55:15 +1000 Subject: [PATCH 14/21] Removed block attributes from block.json that block supports injects Removed comments Regenerated fixtures --- .../block-library/src/pullquote/block.json | 9 ------ .../block-library/src/pullquote/deprecated.js | 30 ++----------------- .../blocks/core__pullquote__deprecated-4.html | 4 +-- .../blocks/core__pullquote__deprecated-4.json | 8 +++-- .../core__pullquote__deprecated-4.parsed.json | 9 +++--- ...e__pullquote__deprecated-4.serialized.html | 4 +-- .../blocks/core__pullquote__main-color.json | 6 ++-- ...ore__pullquote__main-color.serialized.html | 2 +- ...__pullquote__main-color__deprecated-4.html | 4 +-- ...__pullquote__main-color__deprecated-4.json | 14 ++++----- ...uote__main-color__deprecated-4.parsed.json | 10 +++---- ...__main-color__deprecated-4.serialized.html | 4 +-- 12 files changed, 37 insertions(+), 67 deletions(-) diff --git a/packages/block-library/src/pullquote/block.json b/packages/block-library/src/pullquote/block.json index 9e769f16ca3b87..80a3fc95b9550f 100644 --- a/packages/block-library/src/pullquote/block.json +++ b/packages/block-library/src/pullquote/block.json @@ -15,17 +15,8 @@ "selector": "cite", "default": "" }, - "backgroundColor": { - "type": "string" - }, - "borderColor": { - "type": "string" - }, "textColor": { "type": "string" - }, - "style": { - "type": "object" } }, "supports": { diff --git a/packages/block-library/src/pullquote/deprecated.js b/packages/block-library/src/pullquote/deprecated.js index dc478e65c2a7d6..b888da645d0c6c 100644 --- a/packages/block-library/src/pullquote/deprecated.js +++ b/packages/block-library/src/pullquote/deprecated.js @@ -60,30 +60,6 @@ function parseBorderColor( styleString ) { // TODO: this is ripe for a bit of a clean up according to the example in https://developer.wordpress.org/block-editor/reference-guides/block-api/block-deprecation/#example const deprecated = [ - /* This deprecation adds block support. `mainColor` attribute is no longer available - - TODO: remove the following comments. Just here for development convenience. - - Deprecation fixtures: - - // Solid color style: mainColor is the background color - // Default style: mainColor is the border color - - Solid color style: - -- - - Solid color style with custom background and text colors: - - pullquote
before block supports- - - Default: - - pullquote
before block supports- - */ { attributes: { ...blockAttributes, @@ -173,21 +149,21 @@ const deprecated = [ const isSolidColorStyle = includes( className, SOLID_COLOR_CLASS ); const style = {}; - // Set style.border.color if a deprecated block has a default style and a `customMainColor` attribute. + // Block supports: Set style.border.color if a deprecated block has a default style and a `customMainColor` attribute. if ( ! isSolidColorStyle && customMainColor ) { style.border = { color: customMainColor, }; } - // Set style.color.background if a deprecated block has a solid style and a `customMainColor` attribute. + // Block supports: Set style.color.background if a deprecated block has a solid style and a `customMainColor` attribute. if ( isSolidColorStyle && customMainColor ) { style.color = { background: customMainColor, }; } - // Set style.color.text if a deprecated block has a `customTextColor` attribute. + // Block supports: Set style.color.text if a deprecated block has a `customTextColor` attribute. if ( customTextColor ) { style.color = { ...style?.color, diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.html index 2c92a8f99a50aa..becc245752441e 100644 --- a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.html +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.html @@ -1,3 +1,3 @@ - - pullquote
before block supports+ + pullquote
before block supportsdiff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.json b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.json index dc06d9259d7005..454283cd423a15 100644 --- a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.json +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.json @@ -4,12 +4,14 @@ "name": "core/pullquote", "isValid": true, "attributes": { + "className": "has-background has-black-background-color is-style-solid-color", + "backgroundColor": "black", + "style": {}, "value": " pullquote
before block supportspullquote
", "citation": "before block supports", - "customMainColor": "#cd2653", - "textColor": "secondary" + "textColor": "white" }, "innerBlocks": [], - "originalContent": "" + "originalContent": " pullquote
before block supports" } ] diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.parsed.json b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.parsed.json index 7943fb0c2070b4..f7ba9deaea6383 100644 --- a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.parsed.json +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.parsed.json @@ -2,13 +2,14 @@ { "blockName": "core/pullquote", "attrs": { - "mainColor": "accent", - "textColor": "secondary" + "mainColor": "black", + "textColor": "white", + "className": "is-style-solid-color" }, "innerBlocks": [], - "innerHTML": "\n pullquote
before block supports\n", + "innerHTML": "\n pullquote
before block supports\n", "innerContent": [ - "\n pullquote
before block supports\n" + "\n pullquote
before block supports\n" ] }, { diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.serialized.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.serialized.html index 42fa1edc40f0d1..e88883be243e06 100644 --- a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.serialized.html +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.serialized.html @@ -1,3 +1,3 @@ - - pullquote
before block supports+ + pullquote
before block supportsdiff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.json b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.json index 0faf80886779d3..aa9faa4d7b6a69 100644 --- a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.json +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.json @@ -6,14 +6,14 @@ "attributes": { "value": " pullquote
before block supportsPullquote custom color
", "citation": "before block supports", - "backgroundColor": "blue", "textColor": "white", + "className": "is-style-default", + "backgroundColor": "blue", "style": { "border": { "color": "#2207d0" } - }, - "className": "is-style-default" + } }, "innerBlocks": [], "originalContent": "" diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.serialized.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.serialized.html index b3a09d2c22939b..8cb5047d1c7414 100644 --- a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.serialized.html +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.serialized.html @@ -1,3 +1,3 @@ - + Pullquote custom color
before block supportsdiff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.html index 473e6ecefd480d..999c7fffaac58f 100644 --- a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.html +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.html @@ -1,3 +1,3 @@ - - Pullquote custom color
before block supports+ + Pullquote custom color
my citationdiff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.json b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.json index 99bf149d1ace59..7ba1cdebd13c3c 100644 --- a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.json +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.json @@ -4,17 +4,17 @@ "name": "core/pullquote", "isValid": true, "attributes": { - "className": "has-background is-style-default", + "className": "has-background is-style-solid-color", "style": { - "border": { - "color": "#2207d0" + "color": { + "background": "#48ba90", + "text": "#1567eb" } }, - "value": " pullquote
before block supportsPullquote custom color
", - "citation": "my citation", - "textColor": "subtle-background" + "value": "pullquote
", + "citation": "before block supports" }, "innerBlocks": [], - "originalContent": "" + "originalContent": " Pullquote custom color
my citation" } ] diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.parsed.json b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.parsed.json index 56004374d15637..5a938647a657d6 100644 --- a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.parsed.json +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.parsed.json @@ -2,14 +2,14 @@ { "blockName": "core/pullquote", "attrs": { - "customMainColor": "#2207d0", - "textColor": "subtle-background", - "className": "has-background is-style-default" + "customMainColor": "#48ba90", + "customTextColor": "#1567eb", + "className": "has-background is-style-solid-color" }, "innerBlocks": [], - "innerHTML": "\n pullquote
before block supports\n", + "innerHTML": "\n Pullquote custom color
my citation\n", "innerContent": [ - "\n pullquote
before block supports\n" + "\n Pullquote custom color
my citation\n" ] }, { diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.serialized.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.serialized.html index c628534e1bc5f6..37bf3083dd79ea 100644 --- a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.serialized.html +++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.serialized.html @@ -1,3 +1,3 @@ - - pullquote
before block supports+ + Pullquote custom color
my citationFrom 1ebb84e5585febbc48981f7ec54eb6add90456b7 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 14 Apr 2021 18:57:08 +1000 Subject: [PATCH 15/21] Use gutenberg_block_has_support and unnest support checks --- lib/block-supports/border.php | 61 +++++++++++++---------------------- 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/lib/block-supports/border.php b/lib/block-supports/border.php index ee5b2dfbc03602..8ad249ff95d33c 100644 --- a/lib/block-supports/border.php +++ b/lib/block-supports/border.php @@ -13,11 +13,11 @@ */ function gutenberg_register_border_support( $block_type ) { // Determine if any border related features are supported. - $has_border_color_support = gutenberg_has_border_support( $block_type, 'color' ); + $has_border_color_support = gutenberg_block_has_support( $block_type, array( '__experimentalBorder', 'color' ) ); $has_border_support = - gutenberg_has_border_support( $block_type, 'radius' ) || - gutenberg_has_border_support( $block_type, 'style' ) || - gutenberg_has_border_support( $block_type, 'width' ) || + gutenberg_block_has_support( $block_type, array( '__experimentalBorder', 'radius' ) ) || + gutenberg_block_has_support( $block_type, array( '__experimentalBorder', 'style' ) ) || + gutenberg_block_has_support( $block_type, array( '__experimentalBorder', 'width' ) ) || $has_border_color_support; // Setup attributes and styles within that if needed. @@ -56,31 +56,34 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) { $styles = array(); // Border radius. - if ( gutenberg_has_border_support( $block_type, 'radius' ) ) { - if ( isset( $block_attributes['style']['border']['radius'] ) ) { - $border_radius = (int) $block_attributes['style']['border']['radius']; - $styles[] = sprintf( 'border-radius: %dpx;', $border_radius ); - } + if ( + gutenberg_block_has_support( $block_type, array( '__experimentalBorder', 'radius' ) ) && + isset( $block_attributes['style']['border']['radius'] ) + ) { + $border_radius = (int) $block_attributes['style']['border']['radius']; + $styles[] = sprintf( 'border-radius: %dpx;', $border_radius ); } // Border style. - if ( gutenberg_has_border_support( $block_type, 'style' ) ) { - if ( isset( $block_attributes['style']['border']['style'] ) ) { - $border_style = $block_attributes['style']['border']['style']; - $styles[] = sprintf( 'border-style: %s;', $border_style ); - } + if ( + gutenberg_block_has_support( $block_type, array( '__experimentalBorder', 'style' ) ) && + isset( $block_attributes['style']['border']['style'] ) + ) { + $border_style = $block_attributes['style']['border']['style']; + $styles[] = sprintf( 'border-style: %s;', $border_style ); } // Border width. - if ( gutenberg_has_border_support( $block_type, 'width' ) ) { - if ( isset( $block_attributes['style']['border']['width'] ) ) { - $border_width = intval( $block_attributes['style']['border']['width'] ); - $styles[] = sprintf( 'border-width: %dpx;', $border_width ); - } + if ( + gutenberg_block_has_support( $block_type, array( '__experimentalBorder', 'width' ) ) && + isset( $block_attributes['style']['border']['width'] ) + ) { + $border_width = intval( $block_attributes['style']['border']['width'] ); + $styles[] = sprintf( 'border-width: %dpx;', $border_width ); } // Border color. - if ( gutenberg_has_border_support( $block_type, 'color' ) ) { + if ( gutenberg_block_has_support( $block_type, array( '__experimentalBorder', 'color' ) ) ) { $has_named_border_color = array_key_exists( 'borderColor', $block_attributes ); $has_custom_border_color = isset( $block_attributes['style']['border']['color'] ); @@ -126,24 +129,6 @@ function gutenberg_skip_border_serialization( $block_type ) { $border_support['__experimentalSkipSerialization']; } -/** - * Checks whether the current block type supports the feature requested. - * - * @param WP_Block_Type $block_type Block type to check for support. - * @param string $feature Name of the feature to check support for. - * @param mixed $default Fallback value for feature support, defaults to false. - * - * @return boolean Whether or not the feature is supported. - */ -function gutenberg_has_border_support( $block_type, $feature, $default = false ) { - $block_support = false; - if ( property_exists( $block_type, 'supports' ) ) { - $block_support = _wp_array_get( $block_type->supports, array( '__experimentalBorder' ), $default ); - } - - return true === $block_support || ( is_array( $block_support ) && _wp_array_get( $block_support, array( $feature ), false ) ); -} - // Register the block support. WP_Block_Supports::get_instance()->register( 'border', From a7e2e657b94551078aa75b78e44870949e4e1191 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 14 Apr 2021 18:57:44 +1000 Subject: [PATCH 16/21] Refactor to handle disabled/support checks in root border hook --- .../block-editor/src/hooks/border-color.js | 25 ++---- .../block-editor/src/hooks/border-radius.js | 17 ---- .../block-editor/src/hooks/border-style.js | 17 ---- .../block-editor/src/hooks/border-width.js | 17 ---- packages/block-editor/src/hooks/border.js | 87 +++++++++++-------- 5 files changed, 54 insertions(+), 109 deletions(-) diff --git a/packages/block-editor/src/hooks/border-color.js b/packages/block-editor/src/hooks/border-color.js index 25088245b4e253..511983d35fab1c 100644 --- a/packages/block-editor/src/hooks/border-color.js +++ b/packages/block-editor/src/hooks/border-color.js @@ -20,7 +20,7 @@ import { getColorObjectByAttributeValues, } from '../components/colors'; import useEditorFeature from '../components/use-editor-feature'; -import { hasBorderFeatureSupport, shouldSkipSerialization } from './border'; +import { hasBorderSupport, shouldSkipSerialization } from './border'; import { cleanEmptyObject } from './utils'; // Defining empty array here instead of inline avoids unnecessary re-renders of @@ -49,10 +49,6 @@ export function BorderColorEdit( props ) { const disableCustomColors = ! useEditorFeature( 'color.custom' ); const disableCustomGradients = ! useEditorFeature( 'color.customGradient' ); - if ( useIsBorderColorDisabled( props ) ) { - return null; - } - const onChangeColor = ( value ) => { const colorObject = getColorObjectByColorValue( colors, value ); const newStyle = { @@ -85,17 +81,6 @@ export function BorderColorEdit( props ) { ); } -/** - * Custom hook that checks if border color settings have been disabled. - * - * @param {string} name The name of the block. - * @return {boolean} Whether border color setting is disabled. - */ -export function useIsBorderColorDisabled( { name: blockName } = {} ) { - const isDisabled = ! useEditorFeature( 'border.customColor' ); - return ! hasBorderFeatureSupport( 'color', blockName ) || isDisabled; -} - /** * Filters registered block settings, extending attributes to include * `borderColor` if needed. @@ -104,7 +89,7 @@ export function useIsBorderColorDisabled( { name: blockName } = {} ) { * @return {Object} Updated block settings. */ function addAttributes( settings ) { - if ( ! hasBorderFeatureSupport( 'color', settings ) ) { + if ( ! hasBorderSupport( settings, 'color' ) ) { return settings; } @@ -135,7 +120,7 @@ function addAttributes( settings ) { */ function addSaveProps( props, blockType, attributes ) { if ( - ! hasBorderFeatureSupport( 'color', blockType ) || + ! hasBorderSupport( blockType, 'color' ) || shouldSkipSerialization( blockType ) ) { return props; @@ -165,7 +150,7 @@ function addSaveProps( props, blockType, attributes ) { */ function addEditProps( settings ) { if ( - ! hasBorderFeatureSupport( 'color', settings ) || + ! hasBorderSupport( settings, 'color' ) || shouldSkipSerialization( settings ) ) { return settings; @@ -199,7 +184,7 @@ export const withBorderColorPaletteStyles = createHigherOrderComponent( const colors = useEditorFeature( 'color.palette' ) || EMPTY_ARRAY; if ( - ! hasBorderFeatureSupport( 'color', name ) || + ! hasBorderSupport( name, 'color' ) || shouldSkipSerialization( name ) ) { return pullquote
before block supports; diff --git a/packages/block-editor/src/hooks/border-radius.js b/packages/block-editor/src/hooks/border-radius.js index fc074809e2706c..50e9dece97eaf6 100644 --- a/packages/block-editor/src/hooks/border-radius.js +++ b/packages/block-editor/src/hooks/border-radius.js @@ -7,8 +7,6 @@ import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ -import useEditorFeature from '../components/use-editor-feature'; -import { hasBorderFeatureSupport } from './border'; import { cleanEmptyObject } from './utils'; const MIN_BORDER_RADIUS_VALUE = 0; @@ -26,10 +24,6 @@ export function BorderRadiusEdit( props ) { setAttributes, } = props; - if ( useIsBorderRadiusDisabled( props ) ) { - return null; - } - const onChange = ( newRadius ) => { let newStyle = { ...style, @@ -58,14 +52,3 @@ export function BorderRadiusEdit( props ) { /> ); } - -/** - * Custom hook that checks if border radius settings have been disabled. - * - * @param {string} name The name of the block. - * @return {boolean} Whether border radius setting is disabled. - */ -export function useIsBorderRadiusDisabled( { name: blockName } = {} ) { - const isDisabled = ! useEditorFeature( 'border.customRadius' ); - return ! hasBorderFeatureSupport( 'radius', blockName ) || isDisabled; -} diff --git a/packages/block-editor/src/hooks/border-style.js b/packages/block-editor/src/hooks/border-style.js index 2af46c5b9ee6fa..9f1b1e49b21433 100644 --- a/packages/block-editor/src/hooks/border-style.js +++ b/packages/block-editor/src/hooks/border-style.js @@ -2,8 +2,6 @@ * Internal dependencies */ import BorderStyleControl from '../components/border-style-control'; -import useEditorFeature from '../components/use-editor-feature'; -import { hasBorderFeatureSupport } from './border'; import { cleanEmptyObject } from './utils'; /** @@ -18,10 +16,6 @@ export const BorderStyleEdit = ( props ) => { setAttributes, } = props; - if ( useIsBorderStyleDisabled( props ) ) { - return null; - } - const onChange = ( newBorderStyle ) => { const newStyleAttributes = { ...style, @@ -41,14 +35,3 @@ export const BorderStyleEdit = ( props ) => { /> ); }; - -/** - * Custom hook that checks if border style settings have been disabled. - * - * @param {string} blockName The name of the block to determine support scope. - * @return {boolean} Whether or not border style is disabled. - */ -export const useIsBorderStyleDisabled = ( { name: blockName } = {} ) => { - const isDisabled = ! useEditorFeature( 'border.customStyle' ); - return ! hasBorderFeatureSupport( 'style', blockName ) || isDisabled; -}; diff --git a/packages/block-editor/src/hooks/border-width.js b/packages/block-editor/src/hooks/border-width.js index be8afd3b1d0662..24e25f6a063850 100644 --- a/packages/block-editor/src/hooks/border-width.js +++ b/packages/block-editor/src/hooks/border-width.js @@ -7,8 +7,6 @@ import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ -import useEditorFeature from '../components/use-editor-feature'; -import { hasBorderFeatureSupport } from './border'; import { cleanEmptyObject } from './utils'; const MIN_BORDER_WIDTH = 0; @@ -26,10 +24,6 @@ export const BorderWidthEdit = ( props ) => { setAttributes, } = props; - if ( useIsBorderWidthDisabled( props ) ) { - return null; - } - const onChange = ( newWidth ) => { const newStyle = { ...style, @@ -54,14 +48,3 @@ export const BorderWidthEdit = ( props ) => { /> ); }; - -/** - * Custom hook that checks if border width settings have been disabled. - * - * @param {string} blockName The name of the block to determine support scope. - * @return {boolean} Whether or not border width is disabled. - */ -export const useIsBorderWidthDisabled = ( { name: blockName } = {} ) => { - const isDisabled = ! useEditorFeature( 'border.customWidth' ); - return ! hasBorderFeatureSupport( 'width', blockName ) || isDisabled; -}; diff --git a/packages/block-editor/src/hooks/border.js b/packages/block-editor/src/hooks/border.js index 39f8dfdf5cc6ee..9b4aa499f54cdd 100644 --- a/packages/block-editor/src/hooks/border.js +++ b/packages/block-editor/src/hooks/border.js @@ -10,10 +10,11 @@ import { __ } from '@wordpress/i18n'; * Internal dependencies */ import InspectorControls from '../components/inspector-controls'; -import { BorderColorEdit, useIsBorderColorDisabled } from './border-color'; -import { BorderRadiusEdit, useIsBorderRadiusDisabled } from './border-radius'; -import { BorderStyleEdit, useIsBorderStyleDisabled } from './border-style'; -import { BorderWidthEdit, useIsBorderWidthDisabled } from './border-width'; +import useEditorFeature from '../components/use-editor-feature'; +import { BorderColorEdit } from './border-color'; +import { BorderRadiusEdit } from './border-radius'; +import { BorderStyleEdit } from './border-style'; +import { BorderWidthEdit } from './border-width'; export const BORDER_SUPPORT_KEY = '__experimentalBorder'; @@ -21,6 +22,22 @@ export function BorderPanel( props ) { const isDisabled = useIsBorderDisabled( props ); const isSupported = hasBorderSupport( props.name ); + const isColorSupported = + useEditorFeature( 'border.customColor' ) && + hasBorderSupport( props.name, 'color' ); + + const isRadiusSupported = + useEditorFeature( 'border.customRadius' ) && + hasBorderSupport( props.name, 'radius' ); + + const isStyleSupported = + useEditorFeature( 'border.customStyle' ) && + hasBorderSupport( props.name, 'style' ); + + const isWidthSupported = + useEditorFeature( 'border.customWidth' ) && + hasBorderSupport( props.name, 'width' ); + if ( isDisabled || ! isSupported ) { return null; } @@ -28,10 +45,10 @@ export function BorderPanel( props ) { return ( ); @@ -40,35 +57,31 @@ export function BorderPanel( props ) { /** * Determine whether there is block support for border properties. * - * @param {string} blockName Block name. - * @return {boolean} Whether there is support. + * @param {string} blockName Block name. + * @param {string} feature Border feature to check support for. + * @return {boolean} Whether there is support. */ -export function hasBorderSupport( blockName ) { +export function hasBorderSupport( blockName, feature = 'any' ) { if ( Platform.OS !== 'web' ) { return false; } const support = getBlockSupport( blockName, BORDER_SUPPORT_KEY ); - return !! ( - true === support || - support?.color || - support?.radius || - support?.width || - support?.style - ); -} + if ( support === true ) { + return true; + } -/** - * Determines if there a specific border feature is supported. - * - * @param {string} feature Name of the border feature e.g.`radius` - * @param {string|Object} blockType Block name or block type object. - * @return {boolean} Whether the border feature is supported. - */ -export function hasBorderFeatureSupport( feature, blockType ) { - const support = getBlockSupport( blockType, BORDER_SUPPORT_KEY ); - return !! ( true === support || ( support && support[ feature ] ) ); + if ( feature === 'any' ) { + return !! ( + support?.color || + support?.radius || + support?.width || + support?.style + ); + } + + return !! support?.[ feature ]; } /** @@ -84,18 +97,16 @@ export function shouldSkipSerialization( blockType ) { } /** - * Determines whether there is any block support for borders e.g. border radius, - * style, width etc. + * Determines if all border support features have been disabled. * - * @param {Object} props Block properties. - * @return {boolean} If border support is completely disabled. + * @return {boolean} If border support is completely disabled. */ -const useIsBorderDisabled = ( props = {} ) => { +const useIsBorderDisabled = () => { const configs = [ - useIsBorderColorDisabled( props ), - useIsBorderRadiusDisabled( props ), - useIsBorderStyleDisabled( props ), - useIsBorderWidthDisabled( props ), + ! useEditorFeature( 'border.customColor' ), + ! useEditorFeature( 'border.customRadius' ), + ! useEditorFeature( 'border.customStyle' ), + ! useEditorFeature( 'border.customWidth' ), ]; return configs.every( Boolean ); From 9692633c98025285319589917195cb98daa7487e Mon Sep 17 00:00:00 2001 From: Ramon - - - - + { isStyleSupported && } + { isWidthSupported && } + { isRadiusSupported && } + { isColorSupported && } Date: Thu, 15 Apr 2021 11:34:42 +1000 Subject: [PATCH 17/21] Reverting border supports to false This was for testing purposes only and shouldn't have been committed. --- lib/experimental-default-theme.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/experimental-default-theme.json b/lib/experimental-default-theme.json index 47b33f25af7c13..dea9d96966d34e 100644 --- a/lib/experimental-default-theme.json +++ b/lib/experimental-default-theme.json @@ -171,10 +171,10 @@ "units": [ "px", "em", "rem", "vh", "vw" ] }, "border": { - "customColor": true, - "customRadius": true, - "customStyle": true, - "customWidth": true + "customColor": false, + "customRadius": false, + "customStyle": false, + "customWidth": false } } } From 61d131cf99a91d29c7526b5ec3fc94bd42b2fb80 Mon Sep 17 00:00:00 2001 From: ramonjd Date: Thu, 15 Apr 2021 11:46:00 +1000 Subject: [PATCH 18/21] Adding explicit border support for pullquote --- lib/experimental-default-theme.json | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/experimental-default-theme.json b/lib/experimental-default-theme.json index 47b33f25af7c13..088be16ac71e5c 100644 --- a/lib/experimental-default-theme.json +++ b/lib/experimental-default-theme.json @@ -1,5 +1,13 @@ { "settings": { + "core/pullquote": { + "border": { + "customColor": true, + "customRadius": true, + "customStyle": true, + "customWidth": true + } + }, "defaults": { "color": { "palette": [ @@ -171,10 +179,10 @@ "units": [ "px", "em", "rem", "vh", "vw" ] }, "border": { - "customColor": true, - "customRadius": true, - "customStyle": true, - "customWidth": true + "customColor": false, + "customRadius": false, + "customStyle": false, + "customWidth": false } } } From e02bd0ff195a93fbdb9537c9650ce0e795a3483e Mon Sep 17 00:00:00 2001 From: ramonjd Date: Thu, 15 Apr 2021 12:47:32 +1000 Subject: [PATCH 19/21] Removed unused deps --- packages/block-library/src/pullquote/save.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/block-library/src/pullquote/save.js b/packages/block-library/src/pullquote/save.js index 1d286bd20c12b4..ebf20a218bb189 100644 --- a/packages/block-library/src/pullquote/save.js +++ b/packages/block-library/src/pullquote/save.js @@ -1,14 +1,7 @@ -/** - * External dependencies - */ -import classnames from 'classnames'; -import { includes } from 'lodash'; - /** * WordPress dependencies */ import { - getColorClassName, RichText, useBlockProps, } from '@wordpress/block-editor'; @@ -16,7 +9,6 @@ import { /** * Internal dependencies */ -import { SOLID_COLOR_CLASS } from './shared'; export default function save( { attributes } ) { const { value, citation } = attributes; From 6428aaa49b809decafdc017bc11b2da2467e59b2 Mon Sep 17 00:00:00 2001 From: ramonjd Date: Thu, 15 Apr 2021 13:04:59 +1000 Subject: [PATCH 20/21] Overriding auto prettier formatting so the prettier linter doesn't complain :D --- packages/block-library/src/pullquote/save.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/block-library/src/pullquote/save.js b/packages/block-library/src/pullquote/save.js index ebf20a218bb189..bfbed9a2c58378 100644 --- a/packages/block-library/src/pullquote/save.js +++ b/packages/block-library/src/pullquote/save.js @@ -1,10 +1,7 @@ /** * WordPress dependencies */ -import { - RichText, - useBlockProps, -} from '@wordpress/block-editor'; +import { RichText, useBlockProps } from '@wordpress/block-editor'; /** * Internal dependencies From 3fbe8157f375c2cc183f2bf529b6e679e945ea79 Mon Sep 17 00:00:00 2001 From: ramonjd Date: Thu, 15 Apr 2021 13:11:41 +1000 Subject: [PATCH 21/21] Removed unnecessary comment block --- packages/block-library/src/pullquote/save.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/block-library/src/pullquote/save.js b/packages/block-library/src/pullquote/save.js index bfbed9a2c58378..83d291d87ec5fb 100644 --- a/packages/block-library/src/pullquote/save.js +++ b/packages/block-library/src/pullquote/save.js @@ -3,10 +3,6 @@ */ import { RichText, useBlockProps } from '@wordpress/block-editor'; -/** - * Internal dependencies - */ - export default function save( { attributes } ) { const { value, citation } = attributes; const shouldShowCitation = ! RichText.isEmpty( citation );