PluginProbe
BeyondWords – AI audio for publishers / 7.0.0
BeyondWords – AI audio for publishers v7.0.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 / editor / components / settings-panel / content-section.js

content-section.js in BeyondWords – AI audio for publishers 7.0.0, at src/editor/components/settings-panel/content-section.js

88 lines 2.3 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 { PanelBody, SelectControl } from '@wordpress/components';
6 import { useEntityProp } from '@wordpress/core-data';
7 import { useSelect } from '@wordpress/data';
8 import { decodeEntities } from '@wordpress/html-entities';
9
10 /**
11 * Internal dependencies
12 */
13 import {
14 getSourceOptions,
15 normalizeSource,
16 sourceIncludesScript,
17 projectDefaultOption,
18 } from './helpers';
19 import GenerateAudio from '../generate-audio';
20 import Stack from '../stack';
21
22 export function ContentSection() {
23 const postType = useSelect(
24 ( select ) => select( 'core/editor' ).getCurrentPostType(),
25 []
26 );
27
28 const scriptTemplates = useSelect(
29 ( select ) => select( 'beyondwords/settings' ).getScriptTemplates(),
30 []
31 );
32
33 // `useEntityProp` yields undefined meta until the post entity record is hydrated.
34 const [ rawMeta, setMeta ] = useEntityProp( 'postType', postType, 'meta' );
35 const meta = rawMeta ?? {};
36
37 const source = normalizeSource( meta.beyondwords_source );
38 const scriptTemplateId = meta.beyondwords_script_template_id || '';
39
40 const setSource = ( value ) => {
41 setMeta( { ...meta, beyondwords_source: value } );
42 };
43
44 const setScriptTemplateId = ( value ) => {
45 setMeta( { ...meta, beyondwords_script_template_id: value } );
46 };
47
48 const hasScriptTemplates = ( scriptTemplates ?? [] ).length > 0;
49
50 const scriptTemplateOptions = [
51 projectDefaultOption(),
52 ...( scriptTemplates ?? [] ).map( ( template ) => ( {
53 label: decodeEntities( template.name ?? template.slug ?? '' ),
54 value: String( template.id ),
55 } ) ),
56 ];
57
58 return (
59 <PanelBody title={ __( 'Content', 'speechkit' ) } initialOpen={ true }>
60 <Stack>
61 <GenerateAudio />
62 <SelectControl
63 className="beyondwords--source"
64 label={ __( 'Source', 'speechkit' ) }
65 options={ getSourceOptions() }
66 value={ source }
67 onChange={ setSource }
68 __nextHasNoMarginBottom
69 __next40pxDefaultSize
70 />
71 { sourceIncludesScript( source ) && hasScriptTemplates && (
72 <SelectControl
73 className="beyondwords--script-template"
74 label={ __( 'Script template', 'speechkit' ) }
75 options={ scriptTemplateOptions }
76 value={ scriptTemplateId }
77 onChange={ setScriptTemplateId }
78 __nextHasNoMarginBottom
79 __next40pxDefaultSize
80 />
81 ) }
82 </Stack>
83 </PanelBody>
84 );
85 }
86
87 export default ContentSection;
88