/** * WordPress Dependencies */ import { __ } from '@wordpress/i18n'; import { InspectorControls, BlockControls } from '@wordpress/block-editor'; import { PanelBody, PanelRow, ToggleControl, ToolbarButton, ToolbarGroup, } from '@wordpress/components'; import { createHigherOrderComponent } from '@wordpress/compose'; import { addFilter } from '@wordpress/hooks'; /** * Internal dependencies */ import { isBeyondwordsSupportedBlock } from './isBeyondwordsSupportedBlock'; /** * Add BeyondWords controls to Gutenberg Blocks. * * @since 6.0.1 Skip internal/UI blocks to prevent breaking the block inserter. * * @param {Function} BlockEdit Block edit component. * * @return {Function} BlockEdit Modified block edit component. */ const withBeyondwordsBlockControls = createHigherOrderComponent( ( BlockEdit ) => { return ( props ) => { const { name } = props; // Skip blocks that shouldn't have controls // Do this check BEFORE accessing attributes to avoid unnecessary processing if ( ! isBeyondwordsSupportedBlock( name ) ) { return ; } const { attributes, setAttributes } = props; const { beyondwordsAudio } = attributes; const icon = !! beyondwordsAudio ? 'controls-volumeon' : 'controls-volumeoff'; const buttonLabel = !! beyondwordsAudio ? __( 'Disable audio processing', 'speechkit' ) : __( 'Enable audio processing', 'speechkit' ); const toggleLabel = !! beyondwordsAudio ? __( 'Audio processing enabled', 'speechkit' ) : __( 'Audio processing disabled', 'speechkit' ); const toggleBeyondwordsAudio = () => { setAttributes( { beyondwordsAudio: ! beyondwordsAudio } ); }; return ( <> ); }; }, 'withBeyondwordsBlockControls' ); addFilter( 'editor.BlockEdit', 'beyondwords/block-controls', withBeyondwordsBlockControls );