Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgefilipecosta/40efacc3f573b666afd89df461a83b69 to your computer and use it in GitHub Desktop.
Save jorgefilipecosta/40efacc3f573b666afd89df461a83b69 to your computer and use it in GitHub Desktop.
( function() {
var registerBlockType = wp.blocks.registerBlockType;
var el = wp.element.createElement;
var InnerBlocks = wp.editor.InnerBlocks;
var withSelect = wp.data.withSelect;
var dataSelector = withSelect( function( select, ownProps ) {
var getBlockOrder = select( 'core/block-editor' ).getBlockOrder;
return {
isFirstBlock: getBlockOrder().indexOf( ownProps.clientId ) === 0,
};
} );
var list1 = [ 'core/image', 'core/list' ];
var list2 = [ 'core/gallery', 'core/video' ];
registerBlockType( 'acme/container', {
title: 'Container',
icon: 'carrot',
category: 'common',
edit: dataSelector( function( props ) {
return el( 'div', { style: { outline: '1px solid gray', padding: 5 } },
el( InnerBlocks, {
allowedBlocks: props.isFirstBlock ? list1 : list2,
} )
);
} ),
save() {
return el( 'div', { style: { outline: '1px solid gray', padding: 5 } },
el( InnerBlocks.Content )
);
},
} );
} )();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment