Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Aug 6, 2021
1 parent 43c83ed commit 1d8353a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/block-library/src/pattern/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,27 @@ const PatternEdit = ( { attributes, clientId, isSelected } ) => {
attributes.slug
)
);
const isInnerBlockSelected = useSelect( ( select) => {
const {
getBlock,
hasSelectedInnerBlock,
} = select( blockEditorStore );
const isInnerBlockSelected = useSelect( ( select ) => {
const { getBlock, hasSelectedInnerBlock } = select( blockEditorStore );

const block = getBlock( clientId );
const hasInnerBlocks = !! ( block && block.innerBlocks.length );
return hasInnerBlocks && hasSelectedInnerBlock( clientId, true );
} );
const { replaceBlocks, replaceInnerBlocks, __unstableMarkNextChangeAsNotPersistent } = useDispatch( blockEditorStore );
const {
replaceBlocks,
replaceInnerBlocks,
__unstableMarkNextChangeAsNotPersistent,
} = useDispatch( blockEditorStore );

// Run this effect when the block, or any of its InnerBlocks are selected.
// This replaces the Pattern block wrapper with the content of the pattern.
// This change won't be saved unless further changes are made to the InnerBlocks.
useEffect( () => {
if ( ( isSelected || isInnerBlockSelected ) && selectedPattern?.blocks ) {
if (
( isSelected || isInnerBlockSelected ) &&
selectedPattern?.blocks
) {
__unstableMarkNextChangeAsNotPersistent();
replaceBlocks( clientId, selectedPattern.blocks );
}
Expand Down

0 comments on commit 1d8353a

Please sign in to comment.