/** * WordPress dependencies */ import { __, } from '@wordpress/i18n'; import { BaseControl, Button, PanelBody, PanelRow, Placeholder, Spinner, ToggleControl, SelectControl, TextControl, } from '@wordpress/components'; import { Fragment, useEffect, useState, } from '@wordpress/element'; import apiFetch from '@wordpress/api-fetch'; import { applyFilters, } from '@wordpress/hooks'; /** * Internal dependencies */ import compatibleRender from '@utils/compatible-render'; import './settings/blocks-version'; import './settings.scss'; function Settings() { const [ isAPILoaded, setIsAPILoaded ] = useState( false ); const [ isAPISaving, setIsAPISaving ] = useState( false ); const [ isRegeneratingCSS, setIsRegeneratingCSS ] = useState( false ); const [ settings, setSettings ] = useState( generateBlocksSettings.settings ); useEffect( () => { setIsAPILoaded( true ); }, [] ); function getSetting( name, defaultVal ) { let result = defaultVal; if ( 'undefined' !== typeof settings[ name ] ) { result = settings[ name ]; } return result; } function updateSettings( e ) { setIsAPISaving( true ); const message = e.target.nextElementSibling; apiFetch( { path: '/generateblocks/v1/settings', method: 'POST', data: { settings, }, } ).then( ( result ) => { setIsAPISaving( false ); message.classList.add( 'gblocks-action-message--show' ); message.textContent = result.response; if ( ! result.success || ! result.response ) { message.classList.add( 'gblocks-action-message--error' ); } else { setTimeout( function() { message.classList.remove( 'gblocks-action-message--show' ); }, 3000 ); } } ); } if ( ! isAPILoaded ) { return ( ); } return (
{ applyFilters( 'generateblocks.dashboard.beforeSettings', '', this ) }
px
{ setSettings( { ...settings, container_width: value, } ); } } /> { !! generateBlocksSettings.gpContainerWidthLink && { __( 'Go to option →', 'generateblocks' ) } }
{ setSettings( { ...settings, css_print_method: value, } ); } } /> { 'file' === getSetting( 'css_print_method' ) &&
} { !! generateBlocksSettings.useV1Blocks && ( <> { setSettings( { ...settings, sync_responsive_previews: value, } ); } } /> { setSettings( { ...settings, disable_google_fonts: value, } ); } } /> ) } { applyFilters( 'generateblocks.dashboard.settings', '', { settings, setSettings, } ) }
{ applyFilters( 'generateblocks.dashboard.afterSettings', '', { setSettings, settings, } ) }
); } window.addEventListener( 'DOMContentLoaded', () => { compatibleRender( document.getElementById( 'gblocks-block-default-settings' ), ); } );