PluginProbe
BeyondWords – AI audio for publishers / 4.5.0
BeyondWords – AI audio for publishers v4.5.0
7.2.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 All 44 releases
speechkit / src / Component / Post / BlockAttributes / addControls.js

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

121 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 console.log('!!! useEffect');
42 setAttributes( {
43 beyondwordsMarker: getBlockMarkerAttribute( attributes )
44 } );
45 }, [] );
46
47 const { beyondwordsAudio, beyondwordsMarker } = attributes;
48
49 const icon = !! beyondwordsAudio
50 ? 'controls-volumeon'
51 : 'controls-volumeoff';
52
53 const buttonLabel = !! beyondwordsAudio
54 ? __( 'Disable audio processing', 'speechkit' )
55 : __( 'Enable audio processing', 'speechkit' );
56
57 const toggleLabel = !! beyondwordsAudio
58 ? __( 'Audio processing enabled', 'speechkit' )
59 : __( 'Audio processing disabled', 'speechkit' );
60
61 const toggleBeyondwordsAudio = () =>
62 setAttributes( { beyondwordsAudio: ! beyondwordsAudio } );
63
64 return (
65 <>
66 <BlockEdit { ...props } />
67
68 <BlockAttributesCheck>
69 <InspectorControls>
70 <PanelBody
71 icon="controls-volumeon"
72 title={ __( 'BeyondWords', 'speechkit' ) }
73 initialOpen={ true }
74 >
75 <PanelRow>
76 <ToggleControl
77 label={ toggleLabel }
78 checked={ !! beyondwordsAudio }
79 onChange={ toggleBeyondwordsAudio }
80 />
81 </PanelRow>
82 { !! beyondwordsAudio && (
83 <PanelRow>
84 <TextControl
85 label={ __(
86 'Segment marker',
87 'speechkit'
88 ) }
89 value={ beyondwordsMarker }
90 disabled
91 readOnly
92 />
93 </PanelRow>
94 ) }
95 </PanelBody>
96 </InspectorControls>
97
98 <BlockControls>
99 <ToolbarGroup>
100 <ToolbarButton
101 icon={ icon }
102 label={ buttonLabel }
103 className="components-toolbar__control"
104 onClick={ toggleBeyondwordsAudio }
105 />
106 </ToolbarGroup>
107 </BlockControls>
108 </BlockAttributesCheck>
109 </>
110 );
111 };
112 },
113 'withBeyondwordsBlockControls'
114 );
115
116 addFilter(
117 'editor.BlockEdit',
118 'beyondwords/block-controls',
119 withBeyondwordsBlockControls
120 );
121