-
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.
Transform multiple selected blocks to Columns block (#25829)
* Transform multiple selected blocks to Columns block * use the new function from blocks API * createBlocksFromInnerBlocksTemplate unit tests * add e2e tests * change selection shortcuts in tests
- Loading branch information
1 parent
8be738a
commit ed07732
Showing
11 changed files
with
243 additions
and
61 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
23 changes: 4 additions & 19 deletions
23
packages/block-editor/src/components/inserter/hooks/use-block-types-state.js
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
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,39 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
createBlock, | ||
createBlocksFromInnerBlocksTemplate, | ||
} from '@wordpress/blocks'; | ||
|
||
const MAXIMUM_SELECTED_BLOCKS = 6; | ||
|
||
const transforms = { | ||
from: [ | ||
{ | ||
type: 'block', | ||
isMultiBlock: true, | ||
blocks: [ '*' ], | ||
__experimentalConvert: ( blocks ) => { | ||
const columnWidth = +( 100 / blocks.length ).toFixed( 2 ); | ||
const innerBlocksTemplate = blocks.map( | ||
( { name, attributes, innerBlocks } ) => [ | ||
'core/column', | ||
{ width: `${ columnWidth }%` }, | ||
[ [ name, { ...attributes }, innerBlocks ] ], | ||
] | ||
); | ||
return createBlock( | ||
'core/columns', | ||
{}, | ||
createBlocksFromInnerBlocksTemplate( innerBlocksTemplate ) | ||
); | ||
}, | ||
isMatch: ( { length: selectedBlocksLength } ) => | ||
selectedBlocksLength > 1 && | ||
selectedBlocksLength <= MAXIMUM_SELECTED_BLOCKS, | ||
}, | ||
], | ||
}; | ||
|
||
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
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
Oops, something went wrong.