Skip to content

Commit

Permalink
Switch to using innerblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Jul 14, 2021
1 parent 5f0d4bb commit 1182dfb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/block-library/src/pattern/edit.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';
import {
store as blockEditorStore,
BlockList,
BlockEditorProvider,
InnerBlocks,
} from '@wordpress/block-editor';

const PatternEdit = ( { attributes } ) => {
const PatternEdit = ( { attributes, clientId } ) => {
const selectedPattern = useSelect( ( select ) =>
select( blockEditorStore ).__experimentalGetParsedPattern( attributes.slug )
);

return (
<BlockEditorProvider value={ selectedPattern.blocks }>
<BlockList />
</BlockEditorProvider>
select( blockEditorStore ).__experimentalGetParsedPattern(
attributes.slug
)
);
const { replaceInnerBlocks } = useDispatch( blockEditorStore );
replaceInnerBlocks( clientId, selectedPattern.blocks );
return <InnerBlocks />;
};

export default PatternEdit;
8 changes: 8 additions & 0 deletions packages/block-library/src/pattern/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
Expand All @@ -9,4 +14,7 @@ export { metadata, name };

export const settings = {
edit: PatternEdit,
save: () => {
return <InnerBlocks.Content />;
},
};

0 comments on commit 1182dfb

Please sign in to comment.