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