From 89ad6085716eecf1648396b5d604ff661959c1cc Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Tue, 13 Sep 2022 12:20:38 +0800 Subject: [PATCH 1/3] Remove effect hook --- packages/block-library/src/group/edit.js | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/packages/block-library/src/group/edit.js b/packages/block-library/src/group/edit.js index 6f1b45462dd92..2eb98a3163758 100644 --- a/packages/block-library/src/group/edit.js +++ b/packages/block-library/src/group/edit.js @@ -1,8 +1,7 @@ /** * WordPress dependencies */ -import { useSelect, useDispatch } from '@wordpress/data'; -import { useEffect } from '@wordpress/element'; +import { useSelect } from '@wordpress/data'; import { InnerBlocks, useBlockProps, @@ -70,16 +69,6 @@ function GroupEdit( { attributes, setAttributes, clientId } ) { } ); - const { __unstableMarkNextChangeAsNotPersistent } = - useDispatch( blockEditorStore ); - const { type: layoutType = null } = layout; - useEffect( () => { - if ( layoutType ) { - __unstableMarkNextChangeAsNotPersistent(); - setAttributes( { layout: { ...layout, type: layoutType } } ); - } - }, [ layoutType ] ); - return ( <> From 654514f9156148f1b0a652314279cd0d62f38c2f Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Tue, 13 Sep 2022 12:35:00 +0800 Subject: [PATCH 2/3] Use the WP_Block instance for accessing block attributes --- lib/block-supports/layout.php | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index fea96ff149ae4..d2688368b52f6 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -262,23 +262,27 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support /** * Renders the layout config to the block wrapper. * - * @param string $block_content Rendered block content. - * @param array $block Block object. - * @return string Filtered block content. + * @param string $block_content Rendered block content. + * @param array $parsed_block The parsed block. + * @param WP_Block $block Instance of WP_Block for the block being rendered. + * @return string Filtered block content. */ -function gutenberg_render_layout_support_flag( $block_content, $block ) { - $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); +function gutenberg_render_layout_support_flag( $block_content, $parsed_block, $block ) { + $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block->name ); $support_layout = block_has_support( $block_type, array( '__experimentalLayout' ), false ); if ( ! $support_layout ) { return $block_content; } + // Use the WP_Block instance to access block attributes, since that class + // provides default attribute values, while the $parsed_block doesn't. + $attributes = $block->attributes; $block_gap = gutenberg_get_global_settings( array( 'spacing', 'blockGap' ) ); $global_layout_settings = gutenberg_get_global_settings( array( 'layout' ) ); $has_block_gap_support = isset( $block_gap ) ? null !== $block_gap : false; $default_block_layout = _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() ); - $used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $default_block_layout; + $used_layout = isset( $attributes['layout'] ) ? $attributes['layout'] : $default_block_layout; if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] ) { if ( ! $global_layout_settings ) { @@ -288,7 +292,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { $class_names = array(); $layout_definitions = _wp_array_get( $global_layout_settings, array( 'definitions' ), array() ); - $block_classname = wp_get_block_default_classname( $block['blockName'] ); + $block_classname = wp_get_block_default_classname( $block->name ); $container_class = wp_unique_id( 'wp-container-' ); $layout_classname = ''; @@ -309,15 +313,15 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { // removed in the 5.9 release (https://github.com/WordPress/gutenberg/issues/38719). It is // not intended to provide an extended set of classes to match all block layout attributes // here. - if ( ! empty( $block['attrs']['layout']['orientation'] ) ) { - $class_names[] = 'is-' . sanitize_title( $block['attrs']['layout']['orientation'] ); + if ( ! empty( $attributes['layout']['orientation'] ) ) { + $class_names[] = 'is-' . sanitize_title( $attributes['layout']['orientation'] ); } - if ( ! empty( $block['attrs']['layout']['justifyContent'] ) ) { - $class_names[] = 'is-content-justification-' . sanitize_title( $block['attrs']['layout']['justifyContent'] ); + if ( ! empty( $attributes['layout']['justifyContent'] ) ) { + $class_names[] = 'is-content-justification-' . sanitize_title( $attributes['layout']['justifyContent'] ); } - if ( ! empty( $block['attrs']['layout']['flexWrap'] ) && 'nowrap' === $block['attrs']['layout']['flexWrap'] ) { + if ( ! empty( $attributes['layout']['flexWrap'] ) && 'nowrap' === $attributes['layout']['flexWrap'] ) { $class_names[] = 'is-nowrap'; } @@ -336,7 +340,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { // Attribute-based Layout classnames are output in all cases. if ( ! current_theme_supports( 'disable-layout-styles' ) ) { - $gap_value = _wp_array_get( $block, array( 'attrs', 'style', 'spacing', 'blockGap' ) ); + $gap_value = _wp_array_get( $attributes, array( 'style', 'spacing', 'blockGap' ) ); // Skip if gap value contains unsupported characters. // Regex for CSS value borrowed from `safecss_filter_attr`, and used here // because we only want to match against the value, not the CSS attribute. @@ -349,7 +353,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { } $fallback_gap_value = _wp_array_get( $block_type->supports, array( 'spacing', 'blockGap', '__experimentalDefault' ), '0.5em' ); - $block_spacing = _wp_array_get( $block, array( 'attrs', 'style', 'spacing' ), null ); + $block_spacing = _wp_array_get( $attributes, array( 'style', 'spacing' ), null ); // If a block's block.json skips serialization for spacing or spacing.blockGap, // don't apply the user-defined value to the styles. @@ -384,7 +388,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { if ( function_exists( 'wp_render_layout_support_flag' ) ) { remove_filter( 'render_block', 'wp_render_layout_support_flag' ); } -add_filter( 'render_block', 'gutenberg_render_layout_support_flag', 10, 2 ); +add_filter( 'render_block', 'gutenberg_render_layout_support_flag', 10, 3 ); /** * For themes without theme.json file, make sure From 946e555e221737abd922146004dc42c1f96fe7fe Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Tue, 13 Sep 2022 13:45:34 +0800 Subject: [PATCH 3/3] Update alot of snapshots --- .../plugins/__snapshots__/cpt-locking.test.js.snap | 4 ++-- .../various/__snapshots__/block-grouping.test.js.snap | 10 +++++----- .../block-hierarchy-navigation.test.js.snap | 2 +- .../__snapshots__/inserting-blocks.test.js.snap | 2 +- .../keep-styles-on-block-transforms.test.js.snap | 2 +- .../__snapshots__/multi-block-selection.test.js.snap | 4 ++-- .../specs/editor/various/block-grouping.test.js | 4 ++-- .../specs/editor/various/multi-block-selection.test.js | 2 +- ...-be-created-using-the-block-inserter-1-chromium.txt | 2 +- ...-be-created-using-the-slash-inserter-1-chromium.txt | 2 +- ...nded-to-it-using-the-button-appender-1-chromium.txt | 2 +- ...-can-merge-into-group-with-Backspace-1-chromium.txt | 2 +- ...-can-merge-into-group-with-Backspace-2-chromium.txt | 2 +- 13 files changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/e2e-tests/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap b/packages/e2e-tests/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap index f12d66f3f2f33..0acc31727beeb 100644 --- a/packages/e2e-tests/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap +++ b/packages/e2e-tests/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap @@ -41,7 +41,7 @@ exports[`cpt locking template_lock all should not error when deleting the cotent `; exports[`cpt locking template_lock all unlocked group should allow blocks to be moved 1`] = ` -" +"

p1

@@ -55,7 +55,7 @@ exports[`cpt locking template_lock all unlocked group should allow blocks to be `; exports[`cpt locking template_lock all unlocked group should allow blocks to be removed 1`] = ` -" +"

diff --git a/packages/e2e-tests/specs/editor/various/__snapshots__/block-grouping.test.js.snap b/packages/e2e-tests/specs/editor/various/__snapshots__/block-grouping.test.js.snap index ff3a356078f28..f3c24c200b971 100644 --- a/packages/e2e-tests/specs/editor/various/__snapshots__/block-grouping.test.js.snap +++ b/packages/e2e-tests/specs/editor/various/__snapshots__/block-grouping.test.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Block Grouping Group creation creates a group from multiple blocks of different types via block transforms 1`] = ` -" +"

Group Heading

@@ -17,7 +17,7 @@ exports[`Block Grouping Group creation creates a group from multiple blocks of d `; exports[`Block Grouping Group creation creates a group from multiple blocks of the same type via block transforms 1`] = ` -" +"

First Paragraph

@@ -33,7 +33,7 @@ exports[`Block Grouping Group creation creates a group from multiple blocks of t `; exports[`Block Grouping Group creation creates a group from multiple blocks of the same type via options toolbar 1`] = ` -" +"

First Paragraph

@@ -49,7 +49,7 @@ exports[`Block Grouping Group creation creates a group from multiple blocks of t `; exports[`Block Grouping Group creation groups and ungroups multiple blocks of different types via options toolbar 1`] = ` -" +"

Group Heading

@@ -79,7 +79,7 @@ exports[`Block Grouping Group creation groups and ungroups multiple blocks of di `; exports[`Block Grouping Preserving selected blocks attributes preserves width alignment settings of selected blocks 1`] = ` -" +"

Group Heading

diff --git a/packages/e2e-tests/specs/editor/various/__snapshots__/block-hierarchy-navigation.test.js.snap b/packages/e2e-tests/specs/editor/various/__snapshots__/block-hierarchy-navigation.test.js.snap index 7a9abf86fc42b..eb52e25922a66 100644 --- a/packages/e2e-tests/specs/editor/various/__snapshots__/block-hierarchy-navigation.test.js.snap +++ b/packages/e2e-tests/specs/editor/various/__snapshots__/block-hierarchy-navigation.test.js.snap @@ -51,7 +51,7 @@ exports[`Navigating the block hierarchy should navigate using the list view side `; exports[`Navigating the block hierarchy should select the wrapper div for a group 1`] = ` -" +"

just a paragraph

diff --git a/packages/e2e-tests/specs/editor/various/__snapshots__/inserting-blocks.test.js.snap b/packages/e2e-tests/specs/editor/various/__snapshots__/inserting-blocks.test.js.snap index 42789fa855236..aa75e5d5ef89c 100644 --- a/packages/e2e-tests/specs/editor/various/__snapshots__/inserting-blocks.test.js.snap +++ b/packages/e2e-tests/specs/editor/various/__snapshots__/inserting-blocks.test.js.snap @@ -54,7 +54,7 @@ lines preserved[/myshortcode] `; exports[`Inserting blocks inserts a block in proper place after having clicked \`Browse All\` from block appender 1`] = ` -" +"

Paragraph inside group

diff --git a/packages/e2e-tests/specs/editor/various/__snapshots__/keep-styles-on-block-transforms.test.js.snap b/packages/e2e-tests/specs/editor/various/__snapshots__/keep-styles-on-block-transforms.test.js.snap index 126fda3cc96e3..8c437a88af075 100644 --- a/packages/e2e-tests/specs/editor/various/__snapshots__/keep-styles-on-block-transforms.test.js.snap +++ b/packages/e2e-tests/specs/editor/various/__snapshots__/keep-styles-on-block-transforms.test.js.snap @@ -21,7 +21,7 @@ exports[`Keep styles on block transforms Should keep the font size during a tran `; exports[`Keep styles on block transforms Should not include styles in the group block when grouping a block 1`] = ` -" +"

Line 1 to be made large

diff --git a/packages/e2e-tests/specs/editor/various/__snapshots__/multi-block-selection.test.js.snap b/packages/e2e-tests/specs/editor/various/__snapshots__/multi-block-selection.test.js.snap index 51e7f452082d8..01323a0b1c73b 100644 --- a/packages/e2e-tests/specs/editor/various/__snapshots__/multi-block-selection.test.js.snap +++ b/packages/e2e-tests/specs/editor/various/__snapshots__/multi-block-selection.test.js.snap @@ -251,7 +251,7 @@ exports[`Multi-block selection should preserve dragged selection on move 1`] = ` `; exports[`Multi-block selection should properly select multiple blocks if selected nested blocks belong to different parent 1`] = ` -" +"

first

@@ -261,7 +261,7 @@ exports[`Multi-block selection should properly select multiple blocks if selecte
- +

second

diff --git a/packages/e2e-tests/specs/editor/various/block-grouping.test.js b/packages/e2e-tests/specs/editor/various/block-grouping.test.js index dd51f31016c8d..7f12a9fccfeea 100644 --- a/packages/e2e-tests/specs/editor/various/block-grouping.test.js +++ b/packages/e2e-tests/specs/editor/various/block-grouping.test.js @@ -148,8 +148,8 @@ describe( 'Block Grouping', () => { await clickBlockToolbarButton( 'Options' ); await clickMenuItem( 'Group' ); expect( await getEditedPostContent() ).toMatchInlineSnapshot( ` - " -
+ " +

1

diff --git a/packages/e2e-tests/specs/editor/various/multi-block-selection.test.js b/packages/e2e-tests/specs/editor/various/multi-block-selection.test.js index a5954796bff9e..267d9ce7fb135 100644 --- a/packages/e2e-tests/specs/editor/various/multi-block-selection.test.js +++ b/packages/e2e-tests/specs/editor/various/multi-block-selection.test.js @@ -359,7 +359,7 @@ describe( 'Multi-block selection', () => { await page.mouse.up(); await page.keyboard.type( 'hi' ); expect( await getEditedPostContent() ).toMatchInlineSnapshot( ` - " + "

hih text in group

diff --git a/test/e2e/specs/editor/blocks/__snapshots__/Group-can-be-created-using-the-block-inserter-1-chromium.txt b/test/e2e/specs/editor/blocks/__snapshots__/Group-can-be-created-using-the-block-inserter-1-chromium.txt index d98255c8f1b6a..44774b1bf7680 100644 --- a/test/e2e/specs/editor/blocks/__snapshots__/Group-can-be-created-using-the-block-inserter-1-chromium.txt +++ b/test/e2e/specs/editor/blocks/__snapshots__/Group-can-be-created-using-the-block-inserter-1-chromium.txt @@ -1,3 +1,3 @@ - +
\ No newline at end of file diff --git a/test/e2e/specs/editor/blocks/__snapshots__/Group-can-be-created-using-the-slash-inserter-1-chromium.txt b/test/e2e/specs/editor/blocks/__snapshots__/Group-can-be-created-using-the-slash-inserter-1-chromium.txt index d98255c8f1b6a..44774b1bf7680 100644 --- a/test/e2e/specs/editor/blocks/__snapshots__/Group-can-be-created-using-the-slash-inserter-1-chromium.txt +++ b/test/e2e/specs/editor/blocks/__snapshots__/Group-can-be-created-using-the-slash-inserter-1-chromium.txt @@ -1,3 +1,3 @@ - +
\ No newline at end of file diff --git a/test/e2e/specs/editor/blocks/__snapshots__/Group-can-have-other-blocks-appended-to-it-using-the-button-appender-1-chromium.txt b/test/e2e/specs/editor/blocks/__snapshots__/Group-can-have-other-blocks-appended-to-it-using-the-button-appender-1-chromium.txt index 64b6642785081..09839ec996353 100644 --- a/test/e2e/specs/editor/blocks/__snapshots__/Group-can-have-other-blocks-appended-to-it-using-the-button-appender-1-chromium.txt +++ b/test/e2e/specs/editor/blocks/__snapshots__/Group-can-have-other-blocks-appended-to-it-using-the-button-appender-1-chromium.txt @@ -1,4 +1,4 @@ - +

Group Block with a Paragraph

diff --git a/test/e2e/specs/editor/blocks/__snapshots__/Group-can-merge-into-group-with-Backspace-1-chromium.txt b/test/e2e/specs/editor/blocks/__snapshots__/Group-can-merge-into-group-with-Backspace-1-chromium.txt index a7a6267ccc392..11f6c1766c3d1 100644 --- a/test/e2e/specs/editor/blocks/__snapshots__/Group-can-merge-into-group-with-Backspace-1-chromium.txt +++ b/test/e2e/specs/editor/blocks/__snapshots__/Group-can-merge-into-group-with-Backspace-1-chromium.txt @@ -1,4 +1,4 @@ - +

1

diff --git a/test/e2e/specs/editor/blocks/__snapshots__/Group-can-merge-into-group-with-Backspace-2-chromium.txt b/test/e2e/specs/editor/blocks/__snapshots__/Group-can-merge-into-group-with-Backspace-2-chromium.txt index d3ea494878214..b7bf710d8b9e9 100644 --- a/test/e2e/specs/editor/blocks/__snapshots__/Group-can-merge-into-group-with-Backspace-2-chromium.txt +++ b/test/e2e/specs/editor/blocks/__snapshots__/Group-can-merge-into-group-with-Backspace-2-chromium.txt @@ -1,4 +1,4 @@ - +

1