PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.5.3
GenerateBlocks v1.5.3
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / components / root-element / index.js
generateblocks / src / components / root-element Last commit date
index.js 4 years ago
index.js
35 lines
1 import { createElement } from '@wordpress/element';
2 import { useSelect } from '@wordpress/data';
3 import classnames from 'classnames';
4
5 export default function RootElement( { name, clientId, align, children } ) {
6 const {
7 getBlockRootClientId,
8 } = useSelect( ( select ) => select( 'core/block-editor' ), [] );
9
10 const blockName = name.toString().replace( '/', '-' );
11
12 const blockProps = {
13 className: classnames( {
14 'wp-block': true,
15 'block-editor-block-list__block': true,
16 'gb-is-root-block': true,
17 [ `gb-root-block-${ blockName }` ]: true,
18 } ),
19 'data-align': align ? align : null,
20 'data-block': clientId,
21 };
22
23 const parentBlock = getBlockRootClientId( clientId );
24
25 if ( parentBlock ) {
26 return children;
27 }
28
29 return createElement(
30 'div',
31 blockProps,
32 children
33 );
34 }
35