-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [Block Conversion]: Show `group` option in `Group` blocks * add e2e test
- Loading branch information
1 parent
98327cd
commit 1168512
Showing
4 changed files
with
72 additions
and
60 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createBlock } from '@wordpress/blocks'; | ||
|
||
const transforms = { | ||
from: [ | ||
{ | ||
type: 'block', | ||
isMultiBlock: true, | ||
blocks: [ '*' ], | ||
__experimentalConvert( blocks ) { | ||
const alignments = [ 'wide', 'full' ]; | ||
|
||
// Determine the widest setting of all the blocks to be grouped | ||
const widestAlignment = blocks.reduce( | ||
( accumulator, block ) => { | ||
const { align } = block.attributes; | ||
return alignments.indexOf( align ) > | ||
alignments.indexOf( accumulator ) | ||
? align | ||
: accumulator; | ||
}, | ||
undefined | ||
); | ||
|
||
// Clone the Blocks to be Grouped | ||
// Failing to create new block references causes the original blocks | ||
// to be replaced in the switchToBlockType call thereby meaning they | ||
// are removed both from their original location and within the | ||
// new group block. | ||
const groupInnerBlocks = blocks.map( ( block ) => { | ||
return createBlock( | ||
block.name, | ||
block.attributes, | ||
block.innerBlocks | ||
); | ||
} ); | ||
|
||
return createBlock( | ||
'core/group', | ||
{ | ||
align: widestAlignment, | ||
}, | ||
groupInnerBlocks | ||
); | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
export default transforms; |
This file contains 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