From ec6d12b2364c170f808389e87b0f69040f416b5b Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 16 Jun 2023 15:39:35 +1000 Subject: [PATCH 1/9] Add text columns typography block support from https://github.com/WordPress/gutenberg/pull/33587 --- src/wp-includes/block-supports/typography.php | 8 ++++++++ src/wp-includes/class-wp-theme-json.php | 3 +++ tests/phpunit/tests/theme/wpThemeJson.php | 7 ++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/block-supports/typography.php b/src/wp-includes/block-supports/typography.php index d90b6abb78311..2f1de99b9e9e9 100644 --- a/src/wp-includes/block-supports/typography.php +++ b/src/wp-includes/block-supports/typography.php @@ -30,6 +30,7 @@ function wp_register_typography_support( $block_type ) { $has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false ); $has_letter_spacing_support = _wp_array_get( $typography_supports, array( '__experimentalLetterSpacing' ), false ); $has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false ); + $has_text_columns_support = _wp_array_get( $typography_supports, array( 'textColumns' ), false ); $has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false ); $has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false ); @@ -39,6 +40,7 @@ function wp_register_typography_support( $block_type ) { || $has_font_weight_support || $has_letter_spacing_support || $has_line_height_support + || $has_text_columns_support || $has_text_decoration_support || $has_text_transform_support; @@ -98,6 +100,7 @@ function wp_apply_typography_support( $block_type, $block_attributes ) { $has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false ); $has_letter_spacing_support = _wp_array_get( $typography_supports, array( '__experimentalLetterSpacing' ), false ); $has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false ); + $has_text_columns_support = _wp_array_get( $typography_supports, array( 'textColumns' ), false ); $has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false ); $has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false ); @@ -107,6 +110,7 @@ function wp_apply_typography_support( $block_type, $block_attributes ) { $should_skip_font_style = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontStyle' ); $should_skip_font_weight = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontWeight' ); $should_skip_line_height = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'lineHeight' ); + $should_skip_text_columns = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textColumns' ); $should_skip_text_decoration = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textDecoration' ); $should_skip_text_transform = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textTransform' ); $should_skip_letter_spacing = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'letterSpacing' ); @@ -162,6 +166,10 @@ function wp_apply_typography_support( $block_type, $block_attributes ) { $typography_block_styles['lineHeight'] = _wp_array_get( $block_attributes, array( 'style', 'typography', 'lineHeight' ) ); } + if ( $has_text_columns_support && ! $should_skip_text_columns && isset( $block_attributes['style']['typography']['textColumns'] ) ) { + $typography_block_styles['textColumns'] = _wp_array_get( $block_attributes, array( 'style', 'typography', 'textColumns' ), null ); + } + if ( $has_text_decoration_support && ! $should_skip_text_decoration && diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 74f3971bf267a..5f703d96c15b9 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -228,6 +228,7 @@ class WP_Theme_JSON { 'border-left-width' => array( 'border', 'left', 'width' ), 'border-left-style' => array( 'border', 'left', 'style' ), 'color' => array( 'color', 'text' ), + 'column-count' => array( 'typography', 'textColumns' ), 'font-family' => array( 'typography', 'fontFamily' ), 'font-size' => array( 'typography', 'fontSize' ), 'font-style' => array( 'typography', 'fontStyle' ), @@ -395,6 +396,7 @@ class WP_Theme_JSON { 'fontWeight' => null, 'letterSpacing' => null, 'lineHeight' => null, + 'textColumns' => null, 'textDecoration' => null, 'textTransform' => null, ), @@ -455,6 +457,7 @@ class WP_Theme_JSON { 'fontWeight' => null, 'letterSpacing' => null, 'lineHeight' => null, + 'textColumns' => null, 'textDecoration' => null, 'textTransform' => null, ), diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index 8b54960ccfba8..d23d360081c12 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -594,6 +594,11 @@ public function test_get_stylesheet() { ), ), ), + 'core/post-excerpt' => array( + 'typography' => array( + 'textColumns' => 2, + ), + ), 'core/image' => array( 'border' => array( 'radius' => array( @@ -620,7 +625,7 @@ public function test_get_stylesheet() { ); $variables = "body{--wp--preset--color--grey: grey;--wp--preset--gradient--custom-gradient: linear-gradient(135deg,rgba(0,0,0) 0%,rgb(0,0,0) 100%);--wp--preset--duotone--custom-duotone: url('#wp-duotone-custom-duotone');--wp--preset--font-family--small: 14px;--wp--preset--font-family--big: 41px;}.wp-block-group{--wp--custom--base-font: 16;--wp--custom--line-height--small: 1.2;--wp--custom--line-height--medium: 1.4;--wp--custom--line-height--large: 1.8;}"; - $styles = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }body{color: var(--wp--preset--color--grey);}a:where(:not(.wp-element-button)){background-color: #333;color: #111;}.wp-element-button, .wp-block-button__link{box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.66);}.wp-block-group{background: var(--wp--preset--gradient--custom-gradient);border-radius: 10px;padding: 24px;}.wp-block-group a:where(:not(.wp-element-button)){color: #111;}.wp-block-heading{color: #123456;}.wp-block-heading a:where(:not(.wp-element-button)){background-color: #333;color: #111;font-size: 60px;}.wp-block-post-date{color: #123456;}.wp-block-post-date a:where(:not(.wp-element-button)){background-color: #777;color: #555;}.wp-block-image{margin-bottom: 30px;}.wp-block-image img, .wp-block-image .components-placeholder{filter: var(--wp--preset--duotone--custom-duotone);}.wp-block-image img, .wp-block-image .wp-block-image__crop-area{border-top-left-radius: 10px;border-bottom-right-radius: 1em;}'; + $styles = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }body{color: var(--wp--preset--color--grey);}a:where(:not(.wp-element-button)){background-color: #333;color: #111;}.wp-element-button, .wp-block-button__link{box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.66);}.wp-block-group{background: var(--wp--preset--gradient--custom-gradient);border-radius: 10px;padding: 24px;}.wp-block-group a:where(:not(.wp-element-button)){color: #111;}.wp-block-heading{color: #123456;}.wp-block-heading a:where(:not(.wp-element-button)){background-color: #333;color: #111;font-size: 60px;}.wp-block-post-date{color: #123456;}.wp-block-post-date a:where(:not(.wp-element-button)){background-color: #777;color: #555;}.wp-block-post-excerpt{column-count: 2;}.wp-block-image{margin-bottom: 30px;}.wp-block-image img, .wp-block-image .components-placeholder{filter: var(--wp--preset--duotone--custom-duotone);}.wp-block-image img, .wp-block-image .wp-block-image__crop-area{border-top-left-radius: 10px;border-bottom-right-radius: 1em;}'; $presets = '.has-grey-color{color: var(--wp--preset--color--grey) !important;}.has-grey-background-color{background-color: var(--wp--preset--color--grey) !important;}.has-grey-border-color{border-color: var(--wp--preset--color--grey) !important;}.has-custom-gradient-gradient-background{background: var(--wp--preset--gradient--custom-gradient) !important;}.has-small-font-family{font-family: var(--wp--preset--font-family--small) !important;}.has-big-font-family{font-family: var(--wp--preset--font-family--big) !important;}'; $all = $variables . $styles . $presets; $this->assertSame( $all, $theme_json->get_stylesheet() ); From afe96ab2b32fad82210a99fcc63594413ed53476 Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 16 Jun 2023 15:47:28 +1000 Subject: [PATCH 2/9] El LINTO DEL DIABLO! --- tests/phpunit/tests/theme/wpThemeJson.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index d23d360081c12..6fcdc11f65b5e 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -547,7 +547,7 @@ public function test_get_stylesheet() { ), ), 'blocks' => array( - 'core/group' => array( + 'core/group' => array( 'color' => array( 'gradient' => 'var:preset|gradient|custom-gradient', ), @@ -565,7 +565,7 @@ public function test_get_stylesheet() { 'padding' => '24px', ), ), - 'core/heading' => array( + 'core/heading' => array( 'color' => array( 'text' => '#123456', ), @@ -581,7 +581,7 @@ public function test_get_stylesheet() { ), ), ), - 'core/post-date' => array( + 'core/post-date' => array( 'color' => array( 'text' => '#123456', ), @@ -599,7 +599,7 @@ public function test_get_stylesheet() { 'textColumns' => 2, ), ), - 'core/image' => array( + 'core/image' => array( 'border' => array( 'radius' => array( 'topLeft' => '10px', From afa3a59ce1173c1d18e1dd4391897adfae627806 Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 16 Jun 2023 16:53:57 +1000 Subject: [PATCH 3/9] Add ticket no for tests --- tests/phpunit/tests/theme/wpThemeJson.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index 6fcdc11f65b5e..a4d29539d9b9e 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -475,6 +475,7 @@ public function test_get_stylesheet_renders_enabled_protected_properties() { * @ticket 53175 * @ticket 54336 * @ticket 56611 + * @ticket 58549 */ public function test_get_stylesheet() { $theme_json = new WP_Theme_JSON( From 1a66deebb51947649a38c623062eddbf380d2c29 Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 16 Jun 2023 16:55:40 +1000 Subject: [PATCH 4/9] Add since annotation --- src/wp-includes/block-supports/typography.php | 1 + src/wp-includes/class-wp-theme-json.php | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/wp-includes/block-supports/typography.php b/src/wp-includes/block-supports/typography.php index 2f1de99b9e9e9..ce6a72130d561 100644 --- a/src/wp-includes/block-supports/typography.php +++ b/src/wp-includes/block-supports/typography.php @@ -74,6 +74,7 @@ function wp_register_typography_support( $block_type ) { * * @since 5.6.0 * @since 6.1.0 Used the style engine to generate CSS and classnames. + * @since 6.3.0 Added support for text-columns. * @access private * * @param WP_Block_Type $block_type Block type. diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 5f703d96c15b9..ff375d9f3e4e7 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -335,6 +335,8 @@ class WP_Theme_JSON { * @since 6.1.0 Added `layout.definitions` and `useRootPaddingAwareAlignments`. * @since 6.2.0 Added `dimensions.minHeight`, 'shadow.presets', 'shadow.defaultPresets', * `position.fixed` and `position.sticky`. + * @since 6.3.0 Added support for `typography.textColumns`. + * * @var array */ const VALID_SETTINGS = array( @@ -413,6 +415,7 @@ class WP_Theme_JSON { * added new property `shadow`, * updated `blockGap` to be allowed at any level. * @since 6.2.0 Added `outline`, and `minHeight` properties. + * @since 6.3.0 Added support for `typography.textColumns`. * * @var array */ From 3380152ef3b4988edf0c84906d608719dc2c2d47 Mon Sep 17 00:00:00 2001 From: ramon Date: Wed, 21 Jun 2023 10:20:04 +1000 Subject: [PATCH 5/9] Added annotation --- src/wp-includes/block-supports/typography.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wp-includes/block-supports/typography.php b/src/wp-includes/block-supports/typography.php index ce6a72130d561..78c8b0a2ffd0d 100644 --- a/src/wp-includes/block-supports/typography.php +++ b/src/wp-includes/block-supports/typography.php @@ -10,6 +10,7 @@ * Registers the style and typography block attributes for block types that support it. * * @since 5.6.0 + * @since 6.3.0 Added support for text-columns. * @access private * * @param WP_Block_Type $block_type Block Type. From 6218f5324e87033f3076a685f371aae76ab0abc1 Mon Sep 17 00:00:00 2001 From: ramon Date: Wed, 21 Jun 2023 12:40:19 +1000 Subject: [PATCH 6/9] Added style engine changes from https://github.com/WordPress/gutenberg/pull/46566 --- src/wp-includes/style-engine/class-wp-style-engine.php | 7 +++++++ tests/phpunit/tests/style-engine/styleEngine.php | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/style-engine/class-wp-style-engine.php b/src/wp-includes/style-engine/class-wp-style-engine.php index de8d00467e744..3ec84aba6bc10 100644 --- a/src/wp-includes/style-engine/class-wp-style-engine.php +++ b/src/wp-includes/style-engine/class-wp-style-engine.php @@ -21,6 +21,7 @@ * * @access private * @since 6.1.0 + * @since 6.3.0 Added support for text-columns. */ #[AllowDynamicProperties] final class WP_Style_Engine { @@ -217,6 +218,12 @@ final class WP_Style_Engine { ), 'path' => array( 'typography', 'lineHeight' ), ), + 'textColumns' => array( + 'property_keys' => array( + 'default' => 'column-count', + ), + 'path' => array( 'typography', 'textColumns' ), + ), 'textDecoration' => array( 'property_keys' => array( 'default' => 'text-decoration', diff --git a/tests/phpunit/tests/style-engine/styleEngine.php b/tests/phpunit/tests/style-engine/styleEngine.php index 616c332095eb0..27d55a09d42eb 100644 --- a/tests/phpunit/tests/style-engine/styleEngine.php +++ b/tests/phpunit/tests/style-engine/styleEngine.php @@ -25,6 +25,7 @@ public function tear_down() { * Tests generating block styles and classnames based on various manifestations of the $block_styles argument. * * @ticket 56467 + * @ticket 58549 * * @covers ::wp_style_engine_get_styles * @@ -189,6 +190,7 @@ public function data_wp_style_engine_get_styles() { 'fontStyle' => 'italic', 'fontWeight' => '800', 'lineHeight' => '1.3', + 'textColumns' => '2', 'textDecoration' => 'underline', 'textTransform' => 'uppercase', 'letterSpacing' => '2', @@ -196,7 +198,7 @@ public function data_wp_style_engine_get_styles() { ), 'options' => null, 'expected_output' => array( - 'css' => 'font-size:clamp(2em, 2vw, 4em);font-family:Roboto,Oxygen-Sans,Ubuntu,sans-serif;font-style:italic;font-weight:800;line-height:1.3;text-decoration:underline;text-transform:uppercase;letter-spacing:2;', + 'css' => 'font-size:clamp(2em, 2vw, 4em);font-family:Roboto,Oxygen-Sans,Ubuntu,sans-serif;font-style:italic;font-weight:800;line-height:1.3;column-count:2;text-decoration:underline;text-transform:uppercase;letter-spacing:2;', 'declarations' => array( 'font-size' => 'clamp(2em, 2vw, 4em)', 'font-family' => 'Roboto,Oxygen-Sans,Ubuntu,sans-serif', From e3a95f2aeffa0e76315c1aa196b724ffad8b465d Mon Sep 17 00:00:00 2001 From: ramon Date: Wed, 21 Jun 2023 13:06:45 +1000 Subject: [PATCH 7/9] Updated tests --- tests/phpunit/tests/style-engine/styleEngine.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/phpunit/tests/style-engine/styleEngine.php b/tests/phpunit/tests/style-engine/styleEngine.php index 27d55a09d42eb..ae0e95ea5be2f 100644 --- a/tests/phpunit/tests/style-engine/styleEngine.php +++ b/tests/phpunit/tests/style-engine/styleEngine.php @@ -205,6 +205,7 @@ public function data_wp_style_engine_get_styles() { 'font-style' => 'italic', 'font-weight' => '800', 'line-height' => '1.3', + 'textColumns' => '2', 'text-decoration' => 'underline', 'text-transform' => 'uppercase', 'letter-spacing' => '2', From ed54b9e4bfb4e31c2640d5efd52d87fcfc389cdb Mon Sep 17 00:00:00 2001 From: ramon Date: Wed, 21 Jun 2023 15:53:43 +1000 Subject: [PATCH 8/9] I'll get it right one day --- tests/phpunit/tests/style-engine/styleEngine.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/style-engine/styleEngine.php b/tests/phpunit/tests/style-engine/styleEngine.php index ae0e95ea5be2f..60335386cbda8 100644 --- a/tests/phpunit/tests/style-engine/styleEngine.php +++ b/tests/phpunit/tests/style-engine/styleEngine.php @@ -205,7 +205,7 @@ public function data_wp_style_engine_get_styles() { 'font-style' => 'italic', 'font-weight' => '800', 'line-height' => '1.3', - 'textColumns' => '2', + 'column-count' => '2', 'text-decoration' => 'underline', 'text-transform' => 'uppercase', 'letter-spacing' => '2', From da4cbb20da7ab859e543813a22818781e8c6595e Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Thu, 22 Jun 2023 17:43:56 +1000 Subject: [PATCH 9/9] Add since for properties_metadata --- src/wp-includes/class-wp-theme-json.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index ff375d9f3e4e7..8df2a40188732 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -201,6 +201,7 @@ class WP_Theme_JSON { * `--wp--style--root--padding-*`, and `box-shadow` properties, * removed the `--wp--style--block-gap` property. * @since 6.2.0 Added `outline-*`, and `min-height` properties. + * @since 6.3.0 Added `column-count` property. * * @var array */