PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.2
GenerateBlocks v2.0.2
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 1 year ago
index.js
51 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 import { applyFilters } from '@wordpress/hooks';
6
7 export default function RootElement( {
8 name,
9 clientId,
10 align,
11 children,
12 isBlockPreview,
13 } ) {
14 const {
15 getBlockRootClientId,
16 } = useSelect( ( select ) => select( 'core/block-editor' ), [] );
17
18 const supportsLayout = useSelect( ( select ) => {
19 const {
20 getSettings,
21 } = select( blockEditorStore );
22
23 return getSettings().supportsLayout || false;
24 }, [] );
25
26 const blockName = name.toString().replace( '/', '-' );
27
28 const blockProps = {
29 className: classnames( {
30 'wp-block': true,
31 'gb-is-root-block': true,
32 [ `gb-root-block-${ blockName }` ]: true,
33 [ `align${ align }` ]: supportsLayout,
34 } ),
35 'data-align': align && ! supportsLayout ? align : null,
36 'data-block': clientId,
37 };
38
39 const parentBlockId = getBlockRootClientId( clientId );
40
41 if ( applyFilters( 'generateblocks.rootElement.disable', parentBlockId || isBlockPreview, { name } ) ) {
42 return children;
43 }
44
45 return createElement(
46 'div',
47 blockProps,
48 children
49 );
50 }
51