Skip to content

Commit

Permalink
Apply widest alignment from blocks to be made reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Aug 5, 2021
1 parent 648f924 commit 17f3058
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/reusable-blocks/src/store/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ const controls = {
CONVERT_BLOCKS_TO_REUSABLE: createRegistryControl(
( registry ) =>
async function ( { clientIds, title } ) {
const blocks = registry
.select( 'core/block-editor' )
.getBlocksByClientId( clientIds );

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
);

const reusableBlock = {
title: title || __( 'Untitled Reusable block' ),
content: serialize(
Expand All @@ -106,6 +124,7 @@ const controls = {

const newBlock = createBlock( 'core/block', {
ref: updatedRecord.id,
align: widestAlignment,
} );
registry
.dispatch( blockEditorStore )
Expand Down

0 comments on commit 17f3058

Please sign in to comment.