PluginProbe
BeyondWords – AI audio for publishers / 4.7.0
BeyondWords – AI audio for publishers v4.7.0
7.1.0 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.7.0 All 43 releases
speechkit / src / Component / Post / BlockAttributes / addControls.js

addControls.js in BeyondWords – AI audio for publishers 4.7.0, at src/Component/Post/BlockAttributes/addControls.js

120 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * WordPress Dependencies
3 */
4 import { __ } from '@wordpress/i18n';
5 import { InspectorControls, BlockControls } from '@wordpress/block-editor';
6 import {
7 PanelBody,
8 PanelRow,
9 TextControl,
10 ToggleControl,
11 ToolbarButton,
12 ToolbarGroup,
13 } from '@wordpress/components';
14 import { createHigherOrderComponent } from '@wordpress/compose';
15 import { useEffect } from '@wordpress/element';
16 import { addFilter } from '@wordpress/hooks';
17
18 /**
19 * External dependencies
20 */
21 import getBlockMarkerAttribute from './helpers/getBlockMarkerAttribute';
22
23 /**
24 * Internal dependencies
25 */
26 import BlockAttributesCheck from './check';
27
28 /**
29 * Add BeyondWords controls to Gutenberg Blocks.
30 *
31 * @param {Function} BlockEdit Block edit component.
32 *
33 * @return {Function} BlockEdit Modified block edit component.
34 */
35 const withBeyondwordsBlockControls = createHigherOrderComponent(
36 ( BlockEdit ) => {
37 return ( props ) => {
38 const { attributes, setAttributes } = props;
39
40 useEffect( () => {
41 setAttributes( {
42 beyondwordsMarker: getBlockMarkerAttribute( attributes )
43 } );
44 }, [] );
45
46 const { beyondwordsAudio, beyondwordsMarker } = attributes;
47
48 const icon = !! beyondwordsAudio
49 ? 'controls-volumeon'
50 : 'controls-volumeoff';
51
52 const buttonLabel = !! beyondwordsAudio
53 ? __( 'Disable audio processing', 'speechkit' )
54 : __( 'Enable audio processing', 'speechkit' );
55
56 const toggleLabel = !! beyondwordsAudio
57 ? __( 'Audio processing enabled', 'speechkit' )
58 : __( 'Audio processing disabled', 'speechkit' );
59
60 const toggleBeyondwordsAudio = () =>
61 setAttributes( { beyondwordsAudio: ! beyondwordsAudio } );
62
63 return (
64 <>
65 <BlockEdit { ...props } />
66
67 <BlockAttributesCheck>
68 <InspectorControls>
69 <PanelBody
70 icon="controls-volumeon"
71 title={ __( 'BeyondWords', 'speechkit' ) }
72 initialOpen={ true }
73 >
74 <PanelRow>
75 <ToggleControl
76 label={ toggleLabel }
77 checked={ !! beyondwordsAudio }
78 onChange={ toggleBeyondwordsAudio }
79 />
80 </PanelRow>
81 { !! beyondwordsAudio && (
82 <PanelRow>
83 <TextControl
84 label={ __(
85 'Segment marker',
86 'speechkit'
87 ) }
88 value={ beyondwordsMarker }
89 disabled
90 readOnly
91 />
92 </PanelRow>
93 ) }
94 </PanelBody>
95 </InspectorControls>
96
97 <BlockControls>
98 <ToolbarGroup>
99 <ToolbarButton
100 icon={ icon }
101 label={ buttonLabel }
102 className="components-toolbar__control"
103 onClick={ toggleBeyondwordsAudio }
104 />
105 </ToolbarGroup>
106 </BlockControls>
107 </BlockAttributesCheck>
108 </>
109 );
110 };
111 },
112 'withBeyondwordsBlockControls'
113 );
114
115 addFilter(
116 'editor.BlockEdit',
117 'beyondwords/block-controls',
118 withBeyondwordsBlockControls
119 );
120