PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.5.3
GenerateBlocks v1.5.3
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 / withGridLegacyMigration.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
withGridLegacyMigration.js
44 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 useEffect( () => {
14 if ( ! attributes.isDynamic ) {
15 setAttributes( { isDynamic: true } );
16 }
17
18 // Set our old defaults as static values.
19 // @since 1.4.0.
20 if ( ! wasBlockJustInserted( attributes ) && isBlockVersionLessThan( attributes.blockVersion, 2 ) ) {
21 const legacyDefaults = generateBlocksLegacyDefaults.v_1_4_0.gridContainer;
22
23 const newAttrs = {};
24
25 const hasGlobalStyle = attributes.useGlobalStyle && attributes.globalStyleId;
26
27 if ( ! hasGlobalStyle && ! hasNumericValue( attributes.horizontalGap ) ) {
28 newAttrs.horizontalGap = legacyDefaults.horizontalGap;
29 }
30
31 if ( Object.keys( newAttrs ).length > 0 ) {
32 setAttributes( newAttrs );
33 }
34 }
35
36 if ( isBlockVersionLessThan( attributes.blockVersion, 2 ) ) {
37 setAttributes( { blockVersion: 2 } );
38 }
39 }, [] );
40
41 return ( <WrappedComponent { ...props } /> );
42 };
43 };
44