Created
June 27, 2019 10:38
-
-
Save jorgefilipecosta/40efacc3f573b666afd89df461a83b69 to your computer and use it in GitHub Desktop.
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
( 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