PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.6.0
GenerateBlocks v1.6.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 / hoc / withButtonLegacyMigration.js
generateblocks / src / hoc Last commit date
index.js 4 years ago withButtonContainerLegacyMigration.js 4 years ago withButtonLegacyMigration.js 4 years ago withContainerLegacyMigration.js 4 years ago withDocumentation.js 4 years ago withGridLegacyMigration.js 4 years ago withResponsiveTabs.js 4 years ago withUniqueId.js 4 years ago
withButtonLegacyMigration.js
69 lines
1 import { useEffect } from '@wordpress/element';
2 import wasBlockJustInserted from '../utils/was-block-just-inserted';
3 import isBlockVersionLessThan from '../utils/check-block-version';
4 import hasNumericValue from '../utils/has-numeric-value';
5
6 export default ( WrappedComponent ) => {
7 return ( props ) => {
8 const {
9 attributes,
10 setAttributes,
11 } = props;
12
13 const {
14 hasIcon,
15 icon,
16 hasUrl,
17 url,
18 blockVersion,
19 gradient,
20 } = attributes;
21
22 useEffect( () => {
23 if ( ! hasIcon && icon ) {
24 setAttributes( { hasIcon: true } );
25 }
26
27 if ( ! hasUrl ) {
28 setAttributes( { hasUrl: ( !! url ) } );
29 }
30
31 // Set our old defaults as static values.
32 // @since 1.4.0.
33 if ( ! wasBlockJustInserted( attributes ) && isBlockVersionLessThan( blockVersion, 2 ) ) {
34 const legacyDefaults = generateBlocksLegacyDefaults.v_1_4_0.button;
35
36 const newAttrs = {};
37 const items = [];
38
39 if ( gradient ) {
40 items.push(
41 'gradientDirection',
42 'gradientColorOne',
43 'gradientColorOneOpacity',
44 'gradientColorTwo',
45 'gradientColorTwoOpacity'
46 );
47 }
48
49 items.forEach( ( item ) => {
50 if ( ! hasNumericValue( attributes[ item ] ) ) {
51 newAttrs[ item ] = legacyDefaults[ item ];
52 }
53 } );
54
55 if ( Object.keys( newAttrs ).length > 0 ) {
56 setAttributes( newAttrs );
57 }
58 }
59
60 // Update block version flag if it's out of date.
61 if ( isBlockVersionLessThan( blockVersion, 2 ) ) {
62 setAttributes( { blockVersion: 2 } );
63 }
64 }, [] );
65
66 return ( <WrappedComponent { ...props } /> );
67 };
68 };
69