New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enables Block Grouping/UnGrouping using core/group #14908
Conversation
packages/editor/src/components/convert-to-group-buttons/convert-button.js
Outdated
Show resolved
Hide resolved
|
@kjellr Might I trouble you for suitable icons for
|
|
I really dig this. Impressive work for what you call "rudimentary". My very first instinct was: this should be in the switcher. The action is the same as when you create a quote — select multiple blocks, use switcher, choose quote. Group should be there. At the same time, I would love to see a ⌘G shortcut for grouping blocks together, and this would be more discoverable if it sits in the More menu with a shortcut tip on the right. To echo Matías, I could support having this work in both places, just for that reason. But I would also suggest that if we can only have one, or if we need to start small, I would put this in the block switcher first. |
Some light research suggests a fairly standard representation of "grouped" and "ungrouped" elements is the common representation of this idea. Here's Keynote and Sketch: Oddly enough, Material doesn't have icons like these. ¯_(ツ)_/¯ The "layers" icons seem to be the closest: We could also do something custom, along the lines of: If you want to plug something in while we think about it, here are the svgs for the bottom option: |
c17e571
to
2b6f334
Compare
As provided here #14908 (comment)
UpdateI have updated this PR to include support for grouping via
Important note: as it stands the The keyboard shortcut follows the convention from Google Docs @kjellr I've added the Group icon as provided. We're also missing "UnGroup" but this isn't currently possible as the 📺 ScreencastYou can watch a screencast here. Feedback RequiredI'm looking for guidance on how we could implement wildcard block transforms via
|
Another update 🙈This commit has modified the logic around Block transformations logic to enable wildcard Block transforms. The following is a high level summary:
The last item, in particular, will need some experienced 👀 on it. I suspect we may need to restore the test but with extra logic to account for wildcard. Also, this entire commit may be better being pulled into its own separate PR (although that could make manual testing quite tricky). ScreenshotsYou can now Group multiple different Block types together via:
|
|
Good progress.
Yes, this is something that we would like to do. This is the first transform that is applicable regardless of the block types involved. |
|
@aduth Thanks for the approving review! 🎉
I've created follow-on tasks as issues and noted these in your comments.
I will add this to the Core Editor meeting notes. I may not be able to attend due to family commitments. In which case it would be great if you could bring this up. |
Accidentally got lost during renaming of “UnGroup” to “Ungroup”!
Enables the ability register a given block as the block which handles “grouping” interactions within the editor. Related #14908
|
Can't wait to see this live. So excited about it! I've started working with groups in the past few days, and something like this will be amazing. |
|
This is a cool feature, thank you. Some thoughts: Perhaps I like the option to group under "More options" button on the block toolbar, but Transform to -> Group seems odd because intuitively transform should change the current block to something else. Ideally, instead of More options -> Group there could be More options -> Wrap that then allows to choose from any blocks whose InnerBlocks allow all currently selected blocks, Less ideally, I can register transforms for the Edit: Also More options -> Unwrap would be something that can't be easily done right now. |
…uping" interactions (#15774) * Adds grouping interaction to state Enables the ability register a given block as the block which handles “grouping” interactions within the editor. Related #14908 * Registers grouping block * Auto updated README * Adds test for get/set Grouping block * Update documentation with clearer descriptions * Adds reducer and selector tests * Updates “Blog” for correct “Block” in docs
@ktmn You are welcome. Glad you like it. 😄
Agreed, which is why I've added the ability to register your own Block as the Block to be used for "Grouping" #15774 This doesn't completely cover the use-case you outline. However, it will (once this PR is completed #16278) allow you to define (in code) which Block is actually used for the act of "Grouping". In theory, you'll then be able to register your own Block with Also, I'd advise that if you have a feature request you raise an Issue in this repo. This will ensure it is given visibility, as it was only by chance that I came across your comment on this PR. |
* Experiment with rudity mentory mechanic to allow Block Grouping Tried a few approaches via `insertBlock/removeBlocks` and even `replaceBlocks` but nothing preserved the undo history apart from this rather brute force method. * Migrate to `core/group` due to renaming of container Block from `core/section` * Adds conditionals to hide Group btn if selection is only a single `core/group` Block * Adds transform and updates Group button implementation to mirror Adds a `from` transform to the `core/group` Block. Currently this only works for `core/paragraph` but will need to work for all Block types. Updates the convert button to utilise `switchToBlockType` which invokes the same functionality as used in Block transform thereby unifiying the two methods of grouping. * Adds and applies Group icon As provided here WordPress#14908 (comment) * Adds editor shortcut for Grouping Blocks * Add test to check for blocks before attempting replace * Adds wildcard Block transforms A major update to the transforms logic to enable wildcard Block transforms. * Pass Block names into transform callback function - enables dynamic Block creation in wildcard transforms (see `core/group`) * Add edge cases to Block transformation logic to account for specifying `*` (all) Block types as valid for a transformation * Remove unwanted test that checks all Blocks are of the same type before allowing a transform on a Multi Block selection * Reinstate missing createBlock dep after rebase * Fix to avoid allowing single Group Block to be Grouped * Update to use more appropriate logical negation operator for comparison Addresses WordPress#14908 (comment) * Extracts key transform test logic into dedicated methods Previously hard coded values and difficult to follow logic were making the `switchToBlockType` overly complex. Extracted to well name methods to improve readability and allow to further refactoring. * Extract method to test for wildcard block transforms DRYs up code by extracting a function to test for the presence of a wildcard block transform * Moves logic to allow for wildcard transform into central transform checking method Previously test to allow wildcard transform to be valid were manually added as edge cases in conditions in predicate functions. This update centralises all logic to test whether a given transform is possible but including the logic that allows wildcard transforms within the main method `isPossibleTransformForSource` which determines whether a given transform is possible. * Adds UnGrouping mechanic * Adds UnGroup Icon * Adds e2e test to cover basic grouping for single and multiple blocks * Fix edge case with test to detect a single group container Block * Adds UnGroup keyboard shortcut * Adds more e2e test coverage Includes testing grouping via transforms, options menu and keyboard shortcuts * Adds check for group block availability before displaying grouping UI Also adds e2e tests to cover this. * Updates misnamned components Addresses WordPress#14908 (comment) * Updates to preserve widest width alignment of child block on group container Previously if one of the child blocks being grouped had a width alignment (eg: wide or full) then the group block did not respect this. This meant that layouts weren’t preserved when grouping. Adds functionality and tests to ensure that when a group is created the widest alignment setting of the child blocks is set on the group block. * Updates to DRY out tests * Updates to simplify test setup Previously API calls were cleaning up blocks. This can be removed because all posts are auto removed before each test is run. Addresses WordPress#14908 (comment) * Updates to simplify test assertion Addresses WordPress#14908 (comment) * Combines test cases to simplify and reduce number of test required Addresses WordPress#14908 (comment) * Updates to combine test for grouping and ungrouping via options menu Addresses WordPress#14908 (comment) * Adds keyboard shortcut to global keyboard shortcuts modal * Ensure correct case for group shortcut (ie: lower) * Add shortcut to Block settings menu dropdown items * Adds translation context to Group actions in menus Addresses WordPress#14908 (comment) * Update Block Transforms fixtures to show all Blocks can transform to Group Block * Updates Keyboard Shortcut test snapshot to include Group/UnGroup * Fix to ensure Group block accounted for * Fix Block deletion test failure via keyboard workaround Due to the addition of the “Group” item into the Block Options toolbar the “Remove Block” item had been removed outside the viewable portion of the Popover (not the popover has a restricted height and allows scrolling to see the additional items if there is insufficient space to display them all). Pupeteer isn’t able to click on items that are not visible. The simplest work around is to us the keyboard to select the “Remove Block” menu item rather. Trying to scroll a div within Pupeteer is fraught with problems and inconsistencies. * Fixes Remove Block button helper to be more resilient to change Previously we relied on the number of tab stops to locate the correct button in the menu. This change uses the actual text of the button to identify it and uses an assertion to ensure that the correct button is explicitly required. * Rename function to better convey intent Addresses WordPress#14908 (comment) * Fixes to catch transforms which are invalid for blocks of different types A check was accidentally removed in `b2af0f2611e2a2bc66c62959dbf483abcbe103a9` which allowed multiple blocks of different types to be considered valid even if they were not. Adds conditional to ensure that unless the transform is a wildcard then we test that all the blocks are of the same type as the first block’s type before considering the transform to be valid. * Removes redundant snapshots * Fixes Transforms test to not over-test Group transforms Previously we tested every block transforming into the Group Block. This was unwanted overhead. Fixed to only test 1 single Block transforming into Group. Removed redundant snapshots as a result of removing it. * Fixes e2e test by reinstating helper lost during rebase * Fix to make Group transform snapshot tests more resilient to change Now explicity selects paragraph and image blocks to test the Group transform rather than simply testing the first block that transform into a Group. This ensures that if the order of transforms changes in the fixtures the test won’t be accidentally invalidated. Resolves: WordPress#14908 * Updates to DRY out test and reduce test redundancy and performance Through use of smarter filtering we can get away with a single `it.each()` block which improves perf and removes redundant tests. Addresses WordPress#14908 (comment) * Adds unit tests to cover new conditionals added for wildcard blocks transforms * Fixes capitalisation of UnGroup to Ungroup Resolves WordPress#14908 (comment) * Updates doc block to reflect possible nullable return type Addresses WordPress#14908 (comment) * Updates Readme with doc update * Updates to remove unwanted comments * Updates capitalisatoin of “wildcard” Addresses WordPress#14908 (comment) * Update comment with more context for future maintainers Addresses WordPress#14908 (comment) * Updates to remove unwanted level of context on the translation Co-Authored-By: Andrew Duthie <andrew@andrewduthie.com> * Adds tests to cover isWildcardBlockTransform * Adds tests for isContainerGroupBlock function Note these test will need updating when we land WordPress#15774 * Fixes logic around multi blocks of same type and adds tests Prevously we had 1 function attempting to test for multiple block selection and checking that the selection was all of the same block type. This caused bugs within `switchToBlockType` because the logic was confusing. For example, if a selection isn’t a multi block then we don’t need to test that all the blocks are the same. Separated the two functions and updated conditions in switchToBlockType to reflect this. Added unit tests to cover two new functions. * Adds new generator based API signature to Block transforms Previously the transforms function was pased two arguments 1. attributes 2. innerblocks This wasn’t extensible and more advanced transformations require more information about the block (eg: name). To avoid bloating the signature, a progressive enhancement approach is applied whereby if a generator function is passed as the transform then we pass the entire block object to the generator. This is opt-in only and is backwards compatible with all existing transform functions. * Adds new apply option method to transform API Previously we were modifying the existing transform function to conform to the requirements of a new API (ie: receiving the entire block object rather than the individual arguments). It was decided that introducing a new `apply` option and soft deprecating the old transform option would be preferable. The apply option if provided now takes precedence over the transform option. This is fully backwards compatible. See https://wordpress.slack.com/archives/C02QB2JS7/p1559567845087000 * Updates Block Reg docs to cover wildcard transforms * Updates changelog to document wildcards and transform apply option * Fix linting error introduce in rebase * Fixes test util to avoid infinite loops Previously if the button wasn’t found then the loop would continue forever looking for the button. This would have caused timeouts. Limits the loop to the number of buttons in the document. Also bails out immediately having found the button. Resolves WordPress#14908 (comment) * Renames apply to convert to avoid confusion with Func.apply To avoid potential confusion and overlap with Function.apply, rename to `convert`. Slack discussion: https://wordpress.slack.com/archives/C02QB2JS7/p1559593099150300?thread_ts=1559571243.134500&cid=C02QB2JS7 MDN Function apply docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply Resolves: WordPress#14908 (comment) * Fixes unecessary additional var introduced during debugging * Fix convert API to match established patterns for consistency Previously `convert` always passed an array of block objects even if there was only a single block. This is inconsistent with the implementation of the existing `transform` method which passes only a block’s attributes/innerBlocks pair when it is not a multi block. To retain consistency with the existing `isMultiBlock` paradiagm this updates the API of `convert` to pass a single block object when not in multiblock mode. * Fixes error in docs Co-Authored-By: Andrew Duthie <andrew@andrewduthie.com> * Fixes doc blocks to match coding style Resolves WordPress#14908 (comment) * Fixes icon size and color in dropdown for Group/Ungroup * Updates to remove keyboard shortcuts Following a discussion it was not possible to achieve a consensus on which shortcuts was most suitable (or indeed whether keyboard shortcuts for this were even a good idea). As a result this has been descoped from this PR and will be addressed elsewhere. Once merged I will push a new placeholder PR with the foundation for shortcuts in place and others can then amend it. * Updates snapshot to account for removing keyboard shortcuts * Removes e2e tests covering keyboard shortcuts * Fixes unwanted check introduced during debugging Test for existence of transform is not required and was introduced during debugging. Can be removed. * Updates to collapse spaces in doc blocks Co-Authored-By: Andrew Duthie <andrew@andrewduthie.com> * Fixes isWildcardBlockTransform to test for Array-ness Resolves WordPress#14908 (comment) * Fixes incorrect capitalisation of “UnGroup” to “Ungroup” Addresses WordPress#14908 (comment) * Updates to remove redundant isMultiBlockSelection util function Addresses WordPress#14908 (comment) * Reinstate missing Ungroup icon Accidentally got lost during renaming of “UnGroup” to “Ungroup”!
…uping" interactions (WordPress#15774) * Adds grouping interaction to state Enables the ability register a given block as the block which handles “grouping” interactions within the editor. Related WordPress#14908 * Registers grouping block * Auto updated README * Adds test for get/set Grouping block * Update documentation with clearer descriptions * Adds reducer and selector tests * Updates “Blog” for correct “Block” in docs
* Experiment with rudity mentory mechanic to allow Block Grouping Tried a few approaches via `insertBlock/removeBlocks` and even `replaceBlocks` but nothing preserved the undo history apart from this rather brute force method. * Migrate to `core/group` due to renaming of container Block from `core/section` * Adds conditionals to hide Group btn if selection is only a single `core/group` Block * Adds transform and updates Group button implementation to mirror Adds a `from` transform to the `core/group` Block. Currently this only works for `core/paragraph` but will need to work for all Block types. Updates the convert button to utilise `switchToBlockType` which invokes the same functionality as used in Block transform thereby unifiying the two methods of grouping. * Adds and applies Group icon As provided here WordPress#14908 (comment) * Adds editor shortcut for Grouping Blocks * Add test to check for blocks before attempting replace * Adds wildcard Block transforms A major update to the transforms logic to enable wildcard Block transforms. * Pass Block names into transform callback function - enables dynamic Block creation in wildcard transforms (see `core/group`) * Add edge cases to Block transformation logic to account for specifying `*` (all) Block types as valid for a transformation * Remove unwanted test that checks all Blocks are of the same type before allowing a transform on a Multi Block selection * Reinstate missing createBlock dep after rebase * Fix to avoid allowing single Group Block to be Grouped * Update to use more appropriate logical negation operator for comparison Addresses WordPress#14908 (comment) * Extracts key transform test logic into dedicated methods Previously hard coded values and difficult to follow logic were making the `switchToBlockType` overly complex. Extracted to well name methods to improve readability and allow to further refactoring. * Extract method to test for wildcard block transforms DRYs up code by extracting a function to test for the presence of a wildcard block transform * Moves logic to allow for wildcard transform into central transform checking method Previously test to allow wildcard transform to be valid were manually added as edge cases in conditions in predicate functions. This update centralises all logic to test whether a given transform is possible but including the logic that allows wildcard transforms within the main method `isPossibleTransformForSource` which determines whether a given transform is possible. * Adds UnGrouping mechanic * Adds UnGroup Icon * Adds e2e test to cover basic grouping for single and multiple blocks * Fix edge case with test to detect a single group container Block * Adds UnGroup keyboard shortcut * Adds more e2e test coverage Includes testing grouping via transforms, options menu and keyboard shortcuts * Adds check for group block availability before displaying grouping UI Also adds e2e tests to cover this. * Updates misnamned components Addresses WordPress#14908 (comment) * Updates to preserve widest width alignment of child block on group container Previously if one of the child blocks being grouped had a width alignment (eg: wide or full) then the group block did not respect this. This meant that layouts weren’t preserved when grouping. Adds functionality and tests to ensure that when a group is created the widest alignment setting of the child blocks is set on the group block. * Updates to DRY out tests * Updates to simplify test setup Previously API calls were cleaning up blocks. This can be removed because all posts are auto removed before each test is run. Addresses WordPress#14908 (comment) * Updates to simplify test assertion Addresses WordPress#14908 (comment) * Combines test cases to simplify and reduce number of test required Addresses WordPress#14908 (comment) * Updates to combine test for grouping and ungrouping via options menu Addresses WordPress#14908 (comment) * Adds keyboard shortcut to global keyboard shortcuts modal * Ensure correct case for group shortcut (ie: lower) * Add shortcut to Block settings menu dropdown items * Adds translation context to Group actions in menus Addresses WordPress#14908 (comment) * Update Block Transforms fixtures to show all Blocks can transform to Group Block * Updates Keyboard Shortcut test snapshot to include Group/UnGroup * Fix to ensure Group block accounted for * Fix Block deletion test failure via keyboard workaround Due to the addition of the “Group” item into the Block Options toolbar the “Remove Block” item had been removed outside the viewable portion of the Popover (not the popover has a restricted height and allows scrolling to see the additional items if there is insufficient space to display them all). Pupeteer isn’t able to click on items that are not visible. The simplest work around is to us the keyboard to select the “Remove Block” menu item rather. Trying to scroll a div within Pupeteer is fraught with problems and inconsistencies. * Fixes Remove Block button helper to be more resilient to change Previously we relied on the number of tab stops to locate the correct button in the menu. This change uses the actual text of the button to identify it and uses an assertion to ensure that the correct button is explicitly required. * Rename function to better convey intent Addresses WordPress#14908 (comment) * Fixes to catch transforms which are invalid for blocks of different types A check was accidentally removed in `b2af0f2611e2a2bc66c62959dbf483abcbe103a9` which allowed multiple blocks of different types to be considered valid even if they were not. Adds conditional to ensure that unless the transform is a wildcard then we test that all the blocks are of the same type as the first block’s type before considering the transform to be valid. * Removes redundant snapshots * Fixes Transforms test to not over-test Group transforms Previously we tested every block transforming into the Group Block. This was unwanted overhead. Fixed to only test 1 single Block transforming into Group. Removed redundant snapshots as a result of removing it. * Fixes e2e test by reinstating helper lost during rebase * Fix to make Group transform snapshot tests more resilient to change Now explicity selects paragraph and image blocks to test the Group transform rather than simply testing the first block that transform into a Group. This ensures that if the order of transforms changes in the fixtures the test won’t be accidentally invalidated. Resolves: WordPress#14908 * Updates to DRY out test and reduce test redundancy and performance Through use of smarter filtering we can get away with a single `it.each()` block which improves perf and removes redundant tests. Addresses WordPress#14908 (comment) * Adds unit tests to cover new conditionals added for wildcard blocks transforms * Fixes capitalisation of UnGroup to Ungroup Resolves WordPress#14908 (comment) * Updates doc block to reflect possible nullable return type Addresses WordPress#14908 (comment) * Updates Readme with doc update * Updates to remove unwanted comments * Updates capitalisatoin of “wildcard” Addresses WordPress#14908 (comment) * Update comment with more context for future maintainers Addresses WordPress#14908 (comment) * Updates to remove unwanted level of context on the translation Co-Authored-By: Andrew Duthie <andrew@andrewduthie.com> * Adds tests to cover isWildcardBlockTransform * Adds tests for isContainerGroupBlock function Note these test will need updating when we land WordPress#15774 * Fixes logic around multi blocks of same type and adds tests Prevously we had 1 function attempting to test for multiple block selection and checking that the selection was all of the same block type. This caused bugs within `switchToBlockType` because the logic was confusing. For example, if a selection isn’t a multi block then we don’t need to test that all the blocks are the same. Separated the two functions and updated conditions in switchToBlockType to reflect this. Added unit tests to cover two new functions. * Adds new generator based API signature to Block transforms Previously the transforms function was pased two arguments 1. attributes 2. innerblocks This wasn’t extensible and more advanced transformations require more information about the block (eg: name). To avoid bloating the signature, a progressive enhancement approach is applied whereby if a generator function is passed as the transform then we pass the entire block object to the generator. This is opt-in only and is backwards compatible with all existing transform functions. * Adds new apply option method to transform API Previously we were modifying the existing transform function to conform to the requirements of a new API (ie: receiving the entire block object rather than the individual arguments). It was decided that introducing a new `apply` option and soft deprecating the old transform option would be preferable. The apply option if provided now takes precedence over the transform option. This is fully backwards compatible. See https://wordpress.slack.com/archives/C02QB2JS7/p1559567845087000 * Updates Block Reg docs to cover wildcard transforms * Updates changelog to document wildcards and transform apply option * Fix linting error introduce in rebase * Fixes test util to avoid infinite loops Previously if the button wasn’t found then the loop would continue forever looking for the button. This would have caused timeouts. Limits the loop to the number of buttons in the document. Also bails out immediately having found the button. Resolves WordPress#14908 (comment) * Renames apply to convert to avoid confusion with Func.apply To avoid potential confusion and overlap with Function.apply, rename to `convert`. Slack discussion: https://wordpress.slack.com/archives/C02QB2JS7/p1559593099150300?thread_ts=1559571243.134500&cid=C02QB2JS7 MDN Function apply docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply Resolves: WordPress#14908 (comment) * Fixes unecessary additional var introduced during debugging * Fix convert API to match established patterns for consistency Previously `convert` always passed an array of block objects even if there was only a single block. This is inconsistent with the implementation of the existing `transform` method which passes only a block’s attributes/innerBlocks pair when it is not a multi block. To retain consistency with the existing `isMultiBlock` paradiagm this updates the API of `convert` to pass a single block object when not in multiblock mode. * Fixes error in docs Co-Authored-By: Andrew Duthie <andrew@andrewduthie.com> * Fixes doc blocks to match coding style Resolves WordPress#14908 (comment) * Fixes icon size and color in dropdown for Group/Ungroup * Updates to remove keyboard shortcuts Following a discussion it was not possible to achieve a consensus on which shortcuts was most suitable (or indeed whether keyboard shortcuts for this were even a good idea). As a result this has been descoped from this PR and will be addressed elsewhere. Once merged I will push a new placeholder PR with the foundation for shortcuts in place and others can then amend it. * Updates snapshot to account for removing keyboard shortcuts * Removes e2e tests covering keyboard shortcuts * Fixes unwanted check introduced during debugging Test for existence of transform is not required and was introduced during debugging. Can be removed. * Updates to collapse spaces in doc blocks Co-Authored-By: Andrew Duthie <andrew@andrewduthie.com> * Fixes isWildcardBlockTransform to test for Array-ness Resolves WordPress#14908 (comment) * Fixes incorrect capitalisation of “UnGroup” to “Ungroup” Addresses WordPress#14908 (comment) * Updates to remove redundant isMultiBlockSelection util function Addresses WordPress#14908 (comment) * Reinstate missing Ungroup icon Accidentally got lost during renaming of “UnGroup” to “Ungroup”!
…uping" interactions (WordPress#15774) * Adds grouping interaction to state Enables the ability register a given block as the block which handles “grouping” interactions within the editor. Related WordPress#14908 * Registers grouping block * Auto updated README * Adds test for get/set Grouping block * Update documentation with clearer descriptions * Adds reducer and selector tests * Updates “Blog” for correct “Block” in docs
* Experiment with rudity mentory mechanic to allow Block Grouping Tried a few approaches via `insertBlock/removeBlocks` and even `replaceBlocks` but nothing preserved the undo history apart from this rather brute force method. * Migrate to `core/group` due to renaming of container Block from `core/section` * Adds conditionals to hide Group btn if selection is only a single `core/group` Block * Adds transform and updates Group button implementation to mirror Adds a `from` transform to the `core/group` Block. Currently this only works for `core/paragraph` but will need to work for all Block types. Updates the convert button to utilise `switchToBlockType` which invokes the same functionality as used in Block transform thereby unifiying the two methods of grouping. * Adds and applies Group icon As provided here WordPress#14908 (comment) * Adds editor shortcut for Grouping Blocks * Add test to check for blocks before attempting replace * Adds wildcard Block transforms A major update to the transforms logic to enable wildcard Block transforms. * Pass Block names into transform callback function - enables dynamic Block creation in wildcard transforms (see `core/group`) * Add edge cases to Block transformation logic to account for specifying `*` (all) Block types as valid for a transformation * Remove unwanted test that checks all Blocks are of the same type before allowing a transform on a Multi Block selection * Reinstate missing createBlock dep after rebase * Fix to avoid allowing single Group Block to be Grouped * Update to use more appropriate logical negation operator for comparison Addresses WordPress#14908 (comment) * Extracts key transform test logic into dedicated methods Previously hard coded values and difficult to follow logic were making the `switchToBlockType` overly complex. Extracted to well name methods to improve readability and allow to further refactoring. * Extract method to test for wildcard block transforms DRYs up code by extracting a function to test for the presence of a wildcard block transform * Moves logic to allow for wildcard transform into central transform checking method Previously test to allow wildcard transform to be valid were manually added as edge cases in conditions in predicate functions. This update centralises all logic to test whether a given transform is possible but including the logic that allows wildcard transforms within the main method `isPossibleTransformForSource` which determines whether a given transform is possible. * Adds UnGrouping mechanic * Adds UnGroup Icon * Adds e2e test to cover basic grouping for single and multiple blocks * Fix edge case with test to detect a single group container Block * Adds UnGroup keyboard shortcut * Adds more e2e test coverage Includes testing grouping via transforms, options menu and keyboard shortcuts * Adds check for group block availability before displaying grouping UI Also adds e2e tests to cover this. * Updates misnamned components Addresses WordPress#14908 (comment) * Updates to preserve widest width alignment of child block on group container Previously if one of the child blocks being grouped had a width alignment (eg: wide or full) then the group block did not respect this. This meant that layouts weren’t preserved when grouping. Adds functionality and tests to ensure that when a group is created the widest alignment setting of the child blocks is set on the group block. * Updates to DRY out tests * Updates to simplify test setup Previously API calls were cleaning up blocks. This can be removed because all posts are auto removed before each test is run. Addresses WordPress#14908 (comment) * Updates to simplify test assertion Addresses WordPress#14908 (comment) * Combines test cases to simplify and reduce number of test required Addresses WordPress#14908 (comment) * Updates to combine test for grouping and ungrouping via options menu Addresses WordPress#14908 (comment) * Adds keyboard shortcut to global keyboard shortcuts modal * Ensure correct case for group shortcut (ie: lower) * Add shortcut to Block settings menu dropdown items * Adds translation context to Group actions in menus Addresses WordPress#14908 (comment) * Update Block Transforms fixtures to show all Blocks can transform to Group Block * Updates Keyboard Shortcut test snapshot to include Group/UnGroup * Fix to ensure Group block accounted for * Fix Block deletion test failure via keyboard workaround Due to the addition of the “Group” item into the Block Options toolbar the “Remove Block” item had been removed outside the viewable portion of the Popover (not the popover has a restricted height and allows scrolling to see the additional items if there is insufficient space to display them all). Pupeteer isn’t able to click on items that are not visible. The simplest work around is to us the keyboard to select the “Remove Block” menu item rather. Trying to scroll a div within Pupeteer is fraught with problems and inconsistencies. * Fixes Remove Block button helper to be more resilient to change Previously we relied on the number of tab stops to locate the correct button in the menu. This change uses the actual text of the button to identify it and uses an assertion to ensure that the correct button is explicitly required. * Rename function to better convey intent Addresses WordPress#14908 (comment) * Fixes to catch transforms which are invalid for blocks of different types A check was accidentally removed in `b2af0f2611e2a2bc66c62959dbf483abcbe103a9` which allowed multiple blocks of different types to be considered valid even if they were not. Adds conditional to ensure that unless the transform is a wildcard then we test that all the blocks are of the same type as the first block’s type before considering the transform to be valid. * Removes redundant snapshots * Fixes Transforms test to not over-test Group transforms Previously we tested every block transforming into the Group Block. This was unwanted overhead. Fixed to only test 1 single Block transforming into Group. Removed redundant snapshots as a result of removing it. * Fixes e2e test by reinstating helper lost during rebase * Fix to make Group transform snapshot tests more resilient to change Now explicity selects paragraph and image blocks to test the Group transform rather than simply testing the first block that transform into a Group. This ensures that if the order of transforms changes in the fixtures the test won’t be accidentally invalidated. Resolves: WordPress#14908 * Updates to DRY out test and reduce test redundancy and performance Through use of smarter filtering we can get away with a single `it.each()` block which improves perf and removes redundant tests. Addresses WordPress#14908 (comment) * Adds unit tests to cover new conditionals added for wildcard blocks transforms * Fixes capitalisation of UnGroup to Ungroup Resolves WordPress#14908 (comment) * Updates doc block to reflect possible nullable return type Addresses WordPress#14908 (comment) * Updates Readme with doc update * Updates to remove unwanted comments * Updates capitalisatoin of “wildcard” Addresses WordPress#14908 (comment) * Update comment with more context for future maintainers Addresses WordPress#14908 (comment) * Updates to remove unwanted level of context on the translation Co-Authored-By: Andrew Duthie <andrew@andrewduthie.com> * Adds tests to cover isWildcardBlockTransform * Adds tests for isContainerGroupBlock function Note these test will need updating when we land WordPress#15774 * Fixes logic around multi blocks of same type and adds tests Prevously we had 1 function attempting to test for multiple block selection and checking that the selection was all of the same block type. This caused bugs within `switchToBlockType` because the logic was confusing. For example, if a selection isn’t a multi block then we don’t need to test that all the blocks are the same. Separated the two functions and updated conditions in switchToBlockType to reflect this. Added unit tests to cover two new functions. * Adds new generator based API signature to Block transforms Previously the transforms function was pased two arguments 1. attributes 2. innerblocks This wasn’t extensible and more advanced transformations require more information about the block (eg: name). To avoid bloating the signature, a progressive enhancement approach is applied whereby if a generator function is passed as the transform then we pass the entire block object to the generator. This is opt-in only and is backwards compatible with all existing transform functions. * Adds new apply option method to transform API Previously we were modifying the existing transform function to conform to the requirements of a new API (ie: receiving the entire block object rather than the individual arguments). It was decided that introducing a new `apply` option and soft deprecating the old transform option would be preferable. The apply option if provided now takes precedence over the transform option. This is fully backwards compatible. See https://wordpress.slack.com/archives/C02QB2JS7/p1559567845087000 * Updates Block Reg docs to cover wildcard transforms * Updates changelog to document wildcards and transform apply option * Fix linting error introduce in rebase * Fixes test util to avoid infinite loops Previously if the button wasn’t found then the loop would continue forever looking for the button. This would have caused timeouts. Limits the loop to the number of buttons in the document. Also bails out immediately having found the button. Resolves WordPress#14908 (comment) * Renames apply to convert to avoid confusion with Func.apply To avoid potential confusion and overlap with Function.apply, rename to `convert`. Slack discussion: https://wordpress.slack.com/archives/C02QB2JS7/p1559593099150300?thread_ts=1559571243.134500&cid=C02QB2JS7 MDN Function apply docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply Resolves: WordPress#14908 (comment) * Fixes unecessary additional var introduced during debugging * Fix convert API to match established patterns for consistency Previously `convert` always passed an array of block objects even if there was only a single block. This is inconsistent with the implementation of the existing `transform` method which passes only a block’s attributes/innerBlocks pair when it is not a multi block. To retain consistency with the existing `isMultiBlock` paradiagm this updates the API of `convert` to pass a single block object when not in multiblock mode. * Fixes error in docs Co-Authored-By: Andrew Duthie <andrew@andrewduthie.com> * Fixes doc blocks to match coding style Resolves WordPress#14908 (comment) * Fixes icon size and color in dropdown for Group/Ungroup * Updates to remove keyboard shortcuts Following a discussion it was not possible to achieve a consensus on which shortcuts was most suitable (or indeed whether keyboard shortcuts for this were even a good idea). As a result this has been descoped from this PR and will be addressed elsewhere. Once merged I will push a new placeholder PR with the foundation for shortcuts in place and others can then amend it. * Updates snapshot to account for removing keyboard shortcuts * Removes e2e tests covering keyboard shortcuts * Fixes unwanted check introduced during debugging Test for existence of transform is not required and was introduced during debugging. Can be removed. * Updates to collapse spaces in doc blocks Co-Authored-By: Andrew Duthie <andrew@andrewduthie.com> * Fixes isWildcardBlockTransform to test for Array-ness Resolves WordPress#14908 (comment) * Fixes incorrect capitalisation of “UnGroup” to “Ungroup” Addresses WordPress#14908 (comment) * Updates to remove redundant isMultiBlockSelection util function Addresses WordPress#14908 (comment) * Reinstate missing Ungroup icon Accidentally got lost during renaming of “UnGroup” to “Ungroup”!
…uping" interactions (WordPress#15774) * Adds grouping interaction to state Enables the ability register a given block as the block which handles “grouping” interactions within the editor. Related WordPress#14908 * Registers grouping block * Auto updated README * Adds test for get/set Grouping block * Update documentation with clearer descriptions * Adds reducer and selector tests * Updates “Blog” for correct “Block” in docs






This is an experiment for one direction we might take for the abilityProvides the ability to group other Blocks within thecore/groupBlock as per suggestion here.Closes #14601
Screenshots
📺 Here is a screencast of this in action.
Todos
transformsdefinitions. Probably start herecore/groupis not availablecore/groupis not availablealignwidths of Blocks being grouped are respected and the appropriate width alignment set on thecore/groupso that layout is preserved when grouping.