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 / extend / dynamic-content / InspectorControls.js
generateblocks / src / extend / dynamic-content Last commit date
components 4 years ago hoc 4 years ago hooks 4 years ago inspector-controls 4 years ago utils 4 years ago DynamicRenderer.js 4 years ago InspectorControls.js 4 years ago attributes.js 4 years ago
InspectorControls.js
199 lines
1 import { InspectorControls } from '@wordpress/block-editor';
2 import { __ } from '@wordpress/i18n';
3 import { ToggleControl } from '@wordpress/components';
4 import { useEffect } from '@wordpress/element';
5 import PanelArea from '../../components/panel-area';
6 import DynamicSourceControl from './inspector-controls/DynamicSourceControl';
7 import ContentTypeControl from './inspector-controls/ContentTypeControl';
8 import LinkTypeControl from './inspector-controls/LinkTypeControl';
9 import PostDateControl from './inspector-controls/PostDateControl';
10 import PostMetaControl from './inspector-controls/PostMetaControl';
11 import AuthorMetaControl from './inspector-controls/AuthorMetaControl';
12 import CommentsControl from './inspector-controls/CommentsControl';
13 import TermsControl from './inspector-controls/TermsControl';
14 import ExcerptControl from './inspector-controls/ExcerptControl';
15 import getIcon from '../../utils/get-icon';
16
17 export default ( { context, attributes, setAttributes, name } ) => {
18 const {
19 postType,
20 postId,
21 useDynamicData,
22 dynamicSource,
23 dynamicContentType,
24 dateType,
25 dateReplacePublished,
26 metaFieldName,
27 noCommentsText,
28 singleCommentText,
29 multipleCommentsText,
30 termTaxonomy,
31 termSeparator,
32 dynamicLinkType,
33 linkMetaFieldName,
34 linkMetaFieldType,
35 isPagination,
36 isQueryLoopItem,
37 isCaption,
38 excerptLength,
39 useDefaultMoreLink,
40 customMoreLinkText,
41 dynamicLinkRemoveIfEmpty,
42 } = attributes;
43
44 const currentPostType = dynamicSource === 'current-post' ? context.postType : postType;
45 const currentPostId = dynamicSource === 'current-post' ? context.postId : postId;
46 const isInQueryLoop = 'undefined' !== typeof context[ 'generateblocks/queryId' ];
47
48 useEffect( () => {
49 if (
50 'generateblocks/container' === name &&
51 useDynamicData &&
52 '' !== dynamicContentType &&
53 ( isQueryLoopItem || isInQueryLoop )
54 ) {
55 setAttributes( {
56 bgImageInline: true,
57 } );
58 }
59 }, [
60 dynamicContentType,
61 isQueryLoopItem,
62 ] );
63
64 useEffect( () => {
65 if (
66 'generateblocks/headline' === name &&
67 isCaption &&
68 useDynamicData
69 ) {
70 if ( context[ 'generateblocks/mediaId' ] ) {
71 setAttributes( {
72 postId: context[ 'generateblocks/mediaId' ],
73 postType: 'attachment',
74 dynamicSource: 'current-post',
75 dynamicContentType: dynamicContentType || 'caption',
76 } );
77 } else {
78 setAttributes( {
79 postId: '',
80 postType: 'post',
81 dynamicSource: 'current-post',
82 dynamicContentType: dynamicContentType || 'caption',
83 } );
84 }
85 }
86 }, [
87 isCaption,
88 context[ 'generateblocks/mediaId' ],
89 useDynamicData,
90 dynamicContentType,
91 ] );
92
93 return (
94 <InspectorControls>
95 <PanelArea
96 id={ 'dynamicDataControls' }
97 title={ __( 'Dynamic Data', 'generateblocks' ) }
98 initialOpen={ false }
99 icon={ getIcon( 'dynamic' ) }
100 className="gblocks-panel-label"
101 >
102 <ToggleControl
103 label={ __( 'Enable Dynamic Data', 'generateblocks' ) }
104 checked={ useDynamicData }
105 onChange={ ( value ) => {
106 setAttributes( { useDynamicData: value } );
107 } }
108 />
109
110 { useDynamicData &&
111 <>
112 <DynamicSourceControl
113 dynamicSource={ dynamicSource }
114 postType={ postType }
115 postId={ postId }
116 setAttributes={ setAttributes }
117 dynamicContentType={ dynamicContentType }
118 />
119
120 <ContentTypeControl
121 dynamicContentType={ dynamicContentType }
122 setAttributes={ setAttributes }
123 name={ name }
124 isCaption={ isCaption }
125 />
126
127 <PostDateControl
128 isActive={ 'post-date' === dynamicContentType }
129 dateType={ dateType }
130 dateReplacePublished={ dateReplacePublished }
131 setAttributes={ setAttributes }
132 />
133
134 <PostMetaControl
135 isActive={ 'post-meta' === dynamicContentType }
136 postType={ currentPostType }
137 postId={ currentPostId }
138 metaFieldName={ metaFieldName }
139 setAttributes={ setAttributes }
140 />
141
142 <AuthorMetaControl
143 isActive={ 'author-meta' === dynamicContentType }
144 postType={ currentPostType }
145 postId={ currentPostId }
146 metaFieldName={ metaFieldName }
147 setAttributes={ setAttributes }
148 />
149
150 <CommentsControl
151 isActive={ 'comments-number' === dynamicContentType }
152 noCommentsText={ noCommentsText }
153 singleCommentText={ singleCommentText }
154 multipleCommentsText={ multipleCommentsText }
155 setAttributes={ setAttributes }
156 />
157
158 <TermsControl
159 isActive={ 'terms' === dynamicContentType }
160 postType={ currentPostType }
161 termTaxonomy={ termTaxonomy }
162 termSeparator={ termSeparator }
163 setAttributes={ setAttributes }
164 name={ name }
165 />
166
167 <ExcerptControl
168 isActive={ 'post-excerpt' === dynamicContentType }
169 excerptLength={ excerptLength }
170 useDefaultMoreLink={ useDefaultMoreLink }
171 customMoreLinkText={ customMoreLinkText }
172 setAttributes={ setAttributes }
173 attributes={ attributes }
174 />
175
176 <LinkTypeControl
177 isActive={
178 'generateblocks/container' !== name ||
179 (
180 'generateblocks/container' === name &&
181 'undefined' !== typeof attributes.url
182 )
183 }
184 linkType={ dynamicLinkType }
185 dynamicLinkRemoveIfEmpty={ dynamicLinkRemoveIfEmpty }
186 dynamicContentType={ dynamicContentType }
187 linkMetaFieldName={ linkMetaFieldName }
188 linkMetaFieldType={ linkMetaFieldType }
189 isPagination={ isPagination }
190 setAttributes={ setAttributes }
191 name={ name }
192 />
193 </>
194 }
195 </PanelArea>
196 </InspectorControls>
197 );
198 };
199