PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.2.1
GenerateBlocks v2.2.1
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 / settings.js
generateblocks / src Last commit date
block-context 2 years ago blocks 6 months ago components 6 months ago dynamic-tags 1 year ago editor 6 months ago editor-sidebar 6 months ago extend 1 year ago hoc 1 year ago hooks 1 year ago pattern-library 1 year ago settings 1 year ago shared 1 year ago store 1 year ago utils 1 year ago _common.scss 1 year ago blocks.js 2 years ago dashboard.js 1 year ago dashboard.scss 1 year ago editor-sidebar.js 2 years ago editor.js 1 year ago packages.scss 1 year ago pattern-library.js 2 years ago settings.js 1 year ago settings.scss 1 year ago
settings.js
264 lines
1 /**
2 * WordPress dependencies
3 */
4 import {
5 __,
6 } from '@wordpress/i18n';
7
8 import {
9 BaseControl,
10 Button,
11 PanelBody,
12 PanelRow,
13 Placeholder,
14 Spinner,
15 ToggleControl,
16 SelectControl,
17 TextControl,
18 } from '@wordpress/components';
19
20 import {
21 Fragment,
22 useEffect,
23 useState,
24 } from '@wordpress/element';
25
26 import apiFetch from '@wordpress/api-fetch';
27
28 import {
29 applyFilters,
30 } from '@wordpress/hooks';
31
32 /**
33 * Internal dependencies
34 */
35 import compatibleRender from '@utils/compatible-render';
36 import './settings/blocks-version';
37
38 import './settings.scss';
39
40 function Settings() {
41 const [ isAPILoaded, setIsAPILoaded ] = useState( false );
42 const [ isAPISaving, setIsAPISaving ] = useState( false );
43 const [ isRegeneratingCSS, setIsRegeneratingCSS ] = useState( false );
44 const [ settings, setSettings ] = useState( generateBlocksSettings.settings );
45
46 useEffect( () => {
47 setIsAPILoaded( true );
48 }, [] );
49
50 function getSetting( name, defaultVal ) {
51 let result = defaultVal;
52
53 if ( 'undefined' !== typeof settings[ name ] ) {
54 result = settings[ name ];
55 }
56
57 return result;
58 }
59
60 function updateSettings( e ) {
61 setIsAPISaving( true );
62 const message = e.target.nextElementSibling;
63
64 apiFetch( {
65 path: '/generateblocks/v1/settings',
66 method: 'POST',
67 data: {
68 settings,
69 },
70 } ).then( ( result ) => {
71 setIsAPISaving( false );
72 message.classList.add( 'gblocks-action-message--show' );
73 message.textContent = result.response;
74
75 if ( ! result.success || ! result.response ) {
76 message.classList.add( 'gblocks-action-message--error' );
77 } else {
78 setTimeout( function() {
79 message.classList.remove( 'gblocks-action-message--show' );
80 }, 3000 );
81 }
82 } );
83 }
84
85 if ( ! isAPILoaded ) {
86 return (
87 <Placeholder className="gblocks-settings-placeholder">
88 <Spinner />
89 </Placeholder>
90 );
91 }
92
93 return (
94 <Fragment>
95 <div className="generateblocks-settings-main">
96 { applyFilters( 'generateblocks.dashboard.beforeSettings', '', this ) }
97
98 <PanelBody
99 title={ __( 'Settings', 'generateblocks' ) }
100 >
101 <div className="gblocks-dashboard-panel-row-wrapper">
102 <PanelRow className="gblocks-container-width">
103 <div className="gblocks-units">px</div>
104
105 <TextControl
106 type="number"
107 label={ __( 'Global max-width', 'generateblocks' ) }
108 help={ !! generateBlocksSettings.gpContainerWidth
109 ? __( 'The global max-width is set by GeneratePress in the Customizer.', 'generateblocks' )
110 : __( 'The global max-width value you can use in your blocks.', 'generateblocks' )
111 }
112 disabled={ !! generateBlocksSettings.gpContainerWidth }
113 value={ generateBlocksSettings.gpContainerWidth || getSetting( 'container_width' ) }
114 onChange={ ( value ) => {
115 setSettings( {
116 ...settings,
117 container_width: value,
118 } );
119 } }
120 />
121
122 { !! generateBlocksSettings.gpContainerWidthLink &&
123 <a href={ generateBlocksSettings.gpContainerWidthLink } target="_blank" rel="noopener noreferrer" style={ { fontSize: '12px' } }>
124 { __( 'Go to option →', 'generateblocks' ) }
125 </a>
126 }
127 </PanelRow>
128
129 <PanelRow className="gblocks-css-print-method">
130 <SelectControl
131 label={ __( 'CSS Print Method', 'generateblocks' ) }
132 help={ __( 'Generating your CSS in external files is better for overall performance.', 'generateblocks' ) }
133 value={ getSetting( 'css_print_method' ) }
134 options={ [
135 { label: __( 'External File', 'generateblocks' ), value: 'file' },
136 { label: __( 'Inline Embedding', 'generateblocks' ), value: 'inline' },
137 ] }
138 onChange={ ( value ) => {
139 setSettings( {
140 ...settings,
141 css_print_method: value,
142 } );
143 } }
144 />
145 </PanelRow>
146
147 { 'file' === getSetting( 'css_print_method' ) &&
148 <PanelRow>
149 <BaseControl
150 id="gblocks-regenerate-css"
151 className="gblocks-regenerate-css"
152 help={ __( 'Force your external CSS files to regenerate next time their page is loaded.', 'generateblocks' ) }
153 >
154 <div className="gblocks-action-button">
155 <Button
156 isSecondary
157 onClick={ ( e ) => {
158 setIsRegeneratingCSS( true );
159 const message = e.target.nextElementSibling;
160
161 apiFetch( {
162 path: '/generateblocks/v1/regenerate_css_files',
163 method: 'POST',
164 } ).then( ( result ) => {
165 setIsRegeneratingCSS( false );
166 message.classList.add( 'gblocks-action-message--show' );
167 message.textContent = result.response;
168
169 if ( ! result.success || ! result.response ) {
170 message.classList.add( 'gblocks-action-message--error' );
171 } else {
172 setTimeout( function() {
173 message.classList.remove( 'gblocks-action-message--show' );
174 }, 3000 );
175 }
176 } );
177 } }
178 >
179 { isRegeneratingCSS && <Spinner /> }
180 { ! isRegeneratingCSS && __( 'Regenerate CSS Files', 'generateblocks' ) }
181 </Button>
182
183 <span className="gblocks-action-message"></span>
184 </div>
185 </BaseControl>
186 </PanelRow>
187 }
188
189 { !! generateBlocksSettings.useV1Blocks && (
190 <>
191 <PanelRow>
192 <ToggleControl
193 label={ __( 'Sync Responsive Previews', 'generateblocks' ) }
194 help={ __( 'Sync our responsive preview controls with the editor responsive previews.', 'generateblocks' ) }
195 checked={ getSetting( 'sync_responsive_previews' ) }
196 onChange={ ( value ) => {
197 setSettings( {
198 ...settings,
199 sync_responsive_previews: value,
200 } );
201 } }
202 />
203 </PanelRow>
204
205 <PanelRow>
206 <ToggleControl
207 label={ __( 'Disable Google Fonts', 'generateblocks' ) }
208 help={ __( 'Prevent Google Fonts from being called on your website and remove them from the font family lists.', 'generateblocks' ) }
209 checked={ getSetting( 'disable_google_fonts' ) }
210 onChange={ ( value ) => {
211 setSettings( {
212 ...settings,
213 disable_google_fonts: value,
214 } );
215 } }
216 />
217 </PanelRow>
218 </>
219 ) }
220
221 { applyFilters(
222 'generateblocks.dashboard.settings',
223 '',
224 {
225 settings,
226 setSettings,
227 }
228 ) }
229
230 <div className="gblocks-action-button">
231 <Button
232 isPrimary
233 disabled={ isAPISaving }
234 onClick={ ( e ) => updateSettings( e ) }
235 >
236 { isAPISaving && <Spinner /> }
237 { ! isAPISaving && __( 'Save', 'generateblocks' ) }
238 </Button>
239
240 <span className="gblocks-action-message"></span>
241 </div>
242 </div>
243 </PanelBody>
244
245 { applyFilters(
246 'generateblocks.dashboard.afterSettings',
247 '',
248 {
249 setSettings,
250 settings,
251 }
252 ) }
253 </div>
254 </Fragment>
255 );
256 }
257
258 window.addEventListener( 'DOMContentLoaded', () => {
259 compatibleRender(
260 document.getElementById( 'gblocks-block-default-settings' ),
261 <Settings />
262 );
263 } );
264