Transforms: Allow multiple transforms per block type#66258
Open
dougwollison wants to merge 2 commits intoWordPress:trunkfrom
Open
Transforms: Allow multiple transforms per block type#66258dougwollison wants to merge 2 commits intoWordPress:trunkfrom
dougwollison wants to merge 2 commits intoWordPress:trunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
- Block transform options now based on valid block transforms, not block types with valid transforms. - Alternative transforms, separate from the default one(s), designated by specifying a name, title, and optional icon. - Includes tranforming directly to variations that opt-in with 'switcher' scope; only listed the default transform for a block is applicable.
3ee7ec8 to
d83c9c8
Compare
Contributor
Author
|
Resycned branch and fixed the block-switcher test fail I somehow missed. Updated test to include the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
This PR enables the transform menu/command to offer multiple transformations for the same block, either eligible variations (via a new "switcher" scope), or named transforms that suit more niche use cases.
Why?
Transforming directly into a desired block variation can be considered a QoL enhancement, but also because some custom block variations may be too specific to count as the active one compared to other variations. For example, a custom Group block variation may apply alignment/style changes, and be independent of the layout settings. At best you can transform it to the desired layout, then select the variation from the transform menu, only for the original to show as still active.
Some more complex blocks could warrant offering multiple transformation results regardless of the source block, particularly if they split/wrap the source block in other blocks. For example, a custom List Grid block that offers transforming the selection into a grid of either Snippet Item blocks or Profile Item blocks.
How?
The
getBlockTransformItemsselector now returns items based on valid block transformations, not block types with valid transformations, and includes the specific transformation to use. By default, the results will be the same; however, additional items can be listed by one of two means:nameattribute (and optional title/icon overrides), and will be listed alongside the default one.The "default" transformation is, as before, the highest priority valid transformation candidate (named ones are not considered).
When selected, the transformation is applied via the new
getBlockTransformationResults()utility, which abstracts the results half ofswitchToBlockType().In addition,
switchToBlockType()now supports a variation argument; it will apply the variation to the transformation results if it exists.Testing Instructions
Open the editor to a page.
Select a paragraph block and open the block switcher. The block variation "Plain Quote" will appear as an option. Selecting it should wrap it in a Quote block with the Plain style already applied.
Insert a heading above the paragraph, then select it plus any number of blocks after it. Open the block switcher, the "Columns" transform will appear, but also the "Heading + Content Columns" transform as well. Selecting the latter should create a 2 column layout with the heading in the first and the remaining blocks in the second.
Screenshots or screencast
The Plain Quote variation transform in action.
chrome_CdlzQt7GqO.mp4
The Heading + Content Columns alternative transform in action.
chrome_fOOKBXNZYS.mp4