PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.0
GenerateBlocks v2.0.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 / blocks / container / components / ContainerContentRenderer.js
generateblocks / src / blocks / container / components Last commit date
BlockAppender.js 3 years ago BlockControls.js 2 years ago ComponentCSS.js 1 year ago ContainerContentRenderer.js 2 years ago GridItem.js 4 years ago InspectorAdvancedControls.js 2 years ago LegacyLayoutControls.js 3 years ago ShapeDividers.js 4 years ago TagName.js 3 years ago
ContainerContentRenderer.js
132 lines
1 import RootElement from '../../../components/root-element';
2 import GridItem from './GridItem';
3 import { applyFilters, doAction } from '@wordpress/hooks';
4 import { useBlockProps, store as blockEditorStore, useInnerBlocksProps } from '@wordpress/block-editor';
5 import ShapeDividers from './ShapeDividers';
6 import classnames from 'classnames';
7 import { useInnerBlocksCount } from '../../../hooks';
8 import { useSelect } from '@wordpress/data';
9 import ComponentCSS from './ComponentCSS';
10 import getBackgroundImageUrl from '../../../utils/get-background-image-url';
11 import BlockAppender from './BlockAppender';
12
13 export default function ContainerContentRenderer( props ) {
14 const {
15 attributes,
16 clientId,
17 name,
18 filterTagName,
19 allShapes,
20 deviceType,
21 containerRef,
22 } = props;
23
24 const {
25 uniqueId,
26 className,
27 anchor,
28 tagName,
29 backgroundColor,
30 isGrid,
31 bgOptions,
32 bgImageInline,
33 bgImage,
34 align,
35 isBlockPreview = false,
36 useInnerContainer,
37 templateLock,
38 } = attributes;
39
40 const TagName = filterTagName( applyFilters( 'generateblocks.frontend.containerTagName', tagName, attributes ) );
41 const innerBlocksCount = useInnerBlocksCount( clientId );
42 const hasChildBlocks = 0 < innerBlocksCount;
43 const supportsLayout = useSelect( ( select ) => {
44 const {
45 getSettings,
46 } = select( blockEditorStore );
47
48 return getSettings().supportsLayout || false;
49 }, [] );
50
51 let hasStyling = (
52 !! backgroundColor ||
53 !! bgImage ||
54 attributes.borderSizeTop ||
55 attributes.borderSizeRight ||
56 attributes.borderSizeBottom ||
57 attributes.borderSizeLeft
58 );
59
60 hasStyling = applyFilters( 'generateblocks.editor.containerHasStyling', hasStyling, props );
61
62 let htmlAttributes = {
63 className: classnames( {
64 'gb-container': true,
65 [ `gb-container-${ uniqueId }` ]: true,
66 [ `${ className }` ]: undefined !== className,
67 'gb-container-empty': ! hasChildBlocks && ! isBlockPreview,
68 'gb-container-visual-guides': ! hasChildBlocks && ! hasStyling && ! props.isSelected && ! isBlockPreview,
69 [ `align${ align }` ]: supportsLayout,
70 } ),
71 id: anchor ? anchor : null,
72 'data-align': align && ! supportsLayout ? align : null,
73 ref: containerRef,
74 };
75
76 const backgroundUrl = getBackgroundImageUrl( props );
77
78 if ( bgImageInline && backgroundUrl ) {
79 let imageAttributeName = 'background-image';
80
81 if ( 'element' !== bgOptions.selector ) {
82 imageAttributeName = '--' + imageAttributeName;
83 }
84
85 htmlAttributes.style = {
86 [ imageAttributeName ]: 'url(' + backgroundUrl + ')',
87 };
88 }
89
90 htmlAttributes = applyFilters(
91 'generateblocks.frontend.htmlAttributes',
92 htmlAttributes,
93 'generateblocks/container',
94 attributes
95 );
96
97 const blockProps = useBlockProps( htmlAttributes );
98
99 const innerBlocksProps = useInnerBlocksProps(
100 ! useInnerContainer
101 ? blockProps
102 : { className: 'gb-inside-container' },
103 {
104 templateLock: applyFilters( 'generateblocks.editor.containerTemplateLock', templateLock || false, props ),
105 renderAppender: () => <BlockAppender clientId={ clientId } isSelected={ props.isSelected } attributes={ attributes } />,
106 }
107 );
108
109 doAction( 'generateblocks.editor.renderBlock', { ...props, ref: containerRef } );
110 const containerBlockProps = useInnerContainer ? blockProps : innerBlocksProps;
111
112 return (
113 <>
114 <ComponentCSS { ...props } deviceType={ deviceType } />
115
116 <RootElement name={ name } clientId={ clientId } align={ align }>
117 <GridItem isGrid={ isGrid } uniqueId={ uniqueId }>
118 <TagName { ...containerBlockProps }>
119 <>
120 { useInnerContainer
121 ? <div { ...innerBlocksProps }>{ innerBlocksProps.children }</div>
122 : innerBlocksProps.children
123 }
124 <ShapeDividers attributes={ attributes } allShapes={ allShapes } />
125 </>
126 </TagName>
127 </GridItem>
128 </RootElement>
129 </>
130 );
131 }
132