From f54495a3e9c32aad635a7813b6712ba6e05ec70b Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Wed, 25 May 2022 11:49:45 -0300 Subject: [PATCH 1/3] Adding the code existing in a previous version of this file, inside this loop: https://github.com/WordPress/gutenberg/blob/9c1c67bba4ba0dc7b241639719c567a364a8ea05/lib/compat/wordpress-6.0/class-wp-theme-json-6-0.php#L320 --- .../wordpress-6.1/class-wp-theme-json-6-1.php | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php b/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php index 0331616fb1b9e..27882ad3e9e04 100644 --- a/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php +++ b/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php @@ -226,7 +226,51 @@ public function get_styles_for_block( $block_metadata ) { $selector = $block_metadata['selector']; $settings = _wp_array_get( $this->theme_json, array( 'settings' ) ); $declarations = static::compute_style_properties( $node, $settings ); - $block_rules = static::to_ruleset( $selector, $declarations ); + $block_rules = ''; + + // 1. Separate the ones who use the general selector + // and the ones who use the duotone selector. + $declarations_duotone = array(); + foreach ( $declarations as $index => $declaration ) { + if ( 'filter' === $declaration['name'] ) { + unset( $declarations[ $index ] ); + $declarations_duotone[] = $declaration; + } + } + + /* + * Reset default browser margin on the root body element. + * This is set on the root selector **before** generating the ruleset + * from the `theme.json`. This is to ensure that if the `theme.json` declares + * `margin` in its `spacing` declaration for the `body` element then these + * user-generated values take precedence in the CSS cascade. + * @link https://github.com/WordPress/gutenberg/issues/36147. + */ + if ( static::ROOT_BLOCK_SELECTOR === $selector ) { + $block_rules .= 'body { margin: 0; }'; + } + + // 2. Generate the rules that use the general selector. + $block_rules .= static::to_ruleset( $selector, $declarations ); + + // 3. Generate the rules that use the duotone selector. + if ( isset( $block_metadata['duotone'] ) && ! empty( $declarations_duotone ) ) { + $selector_duotone = static::scope_selector( $block_metadata['selector'], $block_metadata['duotone'] ); + $block_rules .= static::to_ruleset( $selector_duotone, $declarations_duotone ); + } + + if ( static::ROOT_BLOCK_SELECTOR === $selector ) { + $block_rules .= '.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }'; + $block_rules .= '.wp-site-blocks > .alignright { float: right; margin-left: 2em; }'; + $block_rules .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }'; + + $has_block_gap_support = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'blockGap' ) ) !== null; + if ( $has_block_gap_support ) { + $block_rules .= '.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }'; + $block_rules .= '.wp-site-blocks > * + * { margin-block-start: var( --wp--style--block-gap ); }'; + } + } + return $block_rules; } } From 4814f9516e2b7fa21796ffbe0b8de208a0a37eea Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Wed, 25 May 2022 19:13:02 -0300 Subject: [PATCH 2/3] Avoid repeating code --- .../wordpress-6.1/class-wp-theme-json-6-1.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php b/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php index 27882ad3e9e04..5c616a2dcefa8 100644 --- a/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php +++ b/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php @@ -273,4 +273,32 @@ public function get_styles_for_block( $block_metadata ) { return $block_rules; } + + /** + * Converts each style section into a list of rulesets + * containing the block styles to be appended to the stylesheet. + * + * See glossary at https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax + * + * For each section this creates a new ruleset such as: + * + * block-selector { + * style-property-one: value; + * } + * + * @param array $style_nodes Nodes with styles. + * @return string The new stylesheet. + */ + protected function get_block_classes( $style_nodes ) { + $block_rules = ''; + + foreach ( $style_nodes as $metadata ) { + if ( null === $metadata['selector'] ) { + continue; + } + $block_rules.= static::get_styles_for_block( $metadata ); + } + + return $block_rules; + } } From eb1fa18f7788c4ddfbfb8921ef9bdc69b0f5a39e Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 9 Jun 2022 09:27:25 -0300 Subject: [PATCH 3/3] linting --- lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php b/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php index 5c616a2dcefa8..55716b3cf58fa 100644 --- a/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php +++ b/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php @@ -273,7 +273,7 @@ public function get_styles_for_block( $block_metadata ) { return $block_rules; } - + /** * Converts each style section into a list of rulesets * containing the block styles to be appended to the stylesheet. @@ -296,9 +296,9 @@ protected function get_block_classes( $style_nodes ) { if ( null === $metadata['selector'] ) { continue; } - $block_rules.= static::get_styles_for_block( $metadata ); + $block_rules .= static::get_styles_for_block( $metadata ); } - + return $block_rules; } }