PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.8.2
GenerateBlocks v1.8.2
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / blocks / headline / edit.js
generateblocks / src / blocks / headline Last commit date
components 2 years ago css 2 years ago attributes.js 3 years ago block.js 2 years ago deprecated.js 3 years ago edit.js 2 years ago editor.scss 2 years ago element-icons.js 4 years ago markformat.js 4 years ago save.js 4 years ago transforms.js 3 years ago
edit.js
123 lines
1 import './markformat';
2 import { applyFilters } from '@wordpress/hooks';
3 import BlockControls from './components/BlockControls';
4 import { Fragment, useEffect, useRef, useState } from '@wordpress/element';
5 import InspectorAdvancedControls from './components/InspectorAdvancedControls';
6 import GoogleFontLink from '../../components/google-font-link';
7 import ComponentCSS from './components/ComponentCSS';
8 import { createBlock } from '@wordpress/blocks';
9 import { compose } from '@wordpress/compose';
10 import { withDeviceType, withUniqueId } from '../../hoc';
11 import withDynamicContent from '../../extend/dynamic-content/hoc/withDynamicContent';
12 import HeadlineContentRenderer from './components/HeadlineContentRenderer';
13 import { withBlockContext } from '../../block-context';
14 import GenerateBlocksInspectorControls from '../../extend/inspector-control';
15 import withHeadlineLegacyMigration from '../../hoc/withHeadlineLegacyMigration';
16 import getDeviceType from '../../utils/get-device-type';
17 import withSetAttributes from '../../hoc/withSetAttributes';
18
19 const onSplit = ( attributes, clientId ) => ( ( value, isOriginal ) => {
20 let block;
21
22 if ( isOriginal || value ) {
23 block = createBlock( 'generateblocks/headline', {
24 ...attributes,
25 content: value,
26 } );
27 } else {
28 block = createBlock( 'core/paragraph' );
29 }
30
31 if ( isOriginal ) {
32 block.clientId = clientId;
33 }
34
35 return block;
36 } );
37
38 const HeadlineEdit = ( props ) => {
39 const {
40 attributes,
41 setAttributes,
42 ContentRenderer = HeadlineContentRenderer,
43 context,
44 } = props;
45
46 const {
47 anchor,
48 typography,
49 googleFont,
50 googleFontVariants,
51 icon,
52 hasIcon,
53 element,
54 isBlockPreview = false,
55 } = attributes;
56
57 const ref = useRef( null );
58 const [ computedStyles, setComputedStyles ] = useState( {} );
59 const deviceType = getDeviceType();
60
61 useEffect( () => {
62 if ( ! hasIcon && icon ) {
63 setAttributes( { hasIcon: true } );
64 }
65 }, [] );
66
67 useEffect( () => {
68 const computedHeadlineStyles = getComputedStyle( ref.current );
69
70 setComputedStyles( {
71 marginTop: parseInt( computedHeadlineStyles.marginTop ) || '',
72 marginBottom: parseInt( computedHeadlineStyles.marginBottom ) || '',
73 fontSize: parseInt( computedHeadlineStyles.fontSize ) || '',
74 } );
75 }, [ element ] );
76
77 return (
78 <Fragment>
79 <BlockControls
80 attributes={ attributes }
81 setAttributes={ setAttributes }
82 context={ context }
83 />
84
85 <GenerateBlocksInspectorControls
86 attributes={ attributes }
87 setAttributes={ setAttributes }
88 computedStyles={ computedStyles }
89 >
90 { applyFilters( 'generateblocks.editor.settingsPanel', undefined, { ...props, device: deviceType } ) }
91 </GenerateBlocksInspectorControls>
92
93 <InspectorAdvancedControls
94 anchor={ anchor }
95 setAttributes={ setAttributes }
96 attributes={ attributes }
97 />
98
99 <ComponentCSS { ...props } deviceType={ deviceType } />
100
101 <GoogleFontLink
102 fontFamily={ typography.fontFamily }
103 googleFont={ googleFont }
104 googleFontVariants={ googleFontVariants }
105 isBlockPreview={ isBlockPreview }
106 />
107
108 { applyFilters( 'generateblocks.editor.beforeHeadlineElement', '', props ) }
109
110 <ContentRenderer { ...props } onSplit={ onSplit } headlineRef={ ref } />
111 </Fragment>
112 );
113 };
114
115 export default compose(
116 withSetAttributes,
117 withDeviceType,
118 withBlockContext,
119 withDynamicContent,
120 withUniqueId,
121 withHeadlineLegacyMigration
122 )( HeadlineEdit );
123