PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.9.0
GenerateBlocks v1.9.0
2.4.1 2.4.0 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 3 years ago css 3 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 2 years ago markformat.js 5 years ago save.js 4 years ago transforms.js 2 years ago
edit.js
110 lines
1 import './markformat';
2 import { applyFilters } from '@wordpress/hooks';
3 import BlockControls from './components/BlockControls';
4 import { Fragment, useEffect, useRef } 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 isBlockPreview = false,
54 } = attributes;
55
56 const ref = useRef( null );
57 const deviceType = getDeviceType();
58
59 useEffect( () => {
60 if ( ! hasIcon && icon ) {
61 setAttributes( { hasIcon: true } );
62 }
63 }, [] );
64
65 return (
66 <Fragment>
67 <BlockControls
68 attributes={ attributes }
69 setAttributes={ setAttributes }
70 context={ context }
71 />
72
73 <GenerateBlocksInspectorControls
74 attributes={ attributes }
75 setAttributes={ setAttributes }
76 >
77 { applyFilters( 'generateblocks.editor.settingsPanel', undefined, { ...props, device: deviceType } ) }
78 </GenerateBlocksInspectorControls>
79
80 <InspectorAdvancedControls
81 anchor={ anchor }
82 setAttributes={ setAttributes }
83 attributes={ attributes }
84 />
85
86 <ComponentCSS { ...props } deviceType={ deviceType } />
87
88 <GoogleFontLink
89 fontFamily={ typography.fontFamily }
90 googleFont={ googleFont }
91 googleFontVariants={ googleFontVariants }
92 isBlockPreview={ isBlockPreview }
93 />
94
95 { applyFilters( 'generateblocks.editor.beforeHeadlineElement', '', props ) }
96
97 <ContentRenderer { ...props } onSplit={ onSplit } headlineRef={ ref } />
98 </Fragment>
99 );
100 };
101
102 export default compose(
103 withSetAttributes,
104 withDeviceType,
105 withBlockContext,
106 withDynamicContent,
107 withUniqueId,
108 withHeadlineLegacyMigration
109 )( HeadlineEdit );
110