PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.9.0
GenerateBlocks v1.9.0
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 3 years ago
index.js
44 lines
1 import { createElement } from '@wordpress/element';
2 import { useSelect } from '@wordpress/data';
3 import classnames from 'classnames';
4 import { store as blockEditorStore } from '@wordpress/block-editor';
5
6 export default function RootElement( { name, clientId, align, children } ) {
7 const {
8 getBlockRootClientId,
9 } = useSelect( ( select ) => select( 'core/block-editor' ), [] );
10
11 const supportsLayout = useSelect( ( select ) => {
12 const {
13 getSettings,
14 } = select( blockEditorStore );
15
16 return getSettings().supportsLayout || false;
17 }, [] );
18
19 const blockName = name.toString().replace( '/', '-' );
20
21 const blockProps = {
22 className: classnames( {
23 'wp-block': true,
24 'gb-is-root-block': true,
25 [ `gb-root-block-${ blockName }` ]: true,
26 [ `align${ align }` ]: supportsLayout,
27 } ),
28 'data-align': align && ! supportsLayout ? align : null,
29 'data-block': clientId,
30 };
31
32 const parentBlock = getBlockRootClientId( clientId );
33
34 if ( parentBlock ) {
35 return children;
36 }
37
38 return createElement(
39 'div',
40 blockProps,
41 children
42 );
43 }
44