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 |