PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.0
GenerateBlocks v2.0.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 / withImageLegacyMigration.js
generateblocks / src / hoc Last commit date
migrations 2 years ago index.js 1 year ago withButtonContainerLegacyMigration.js 2 years ago withButtonLegacyMigration.js 2 years ago withContainerLegacyMigration.js 2 years ago withDeviceType.js 3 years ago withDynamicTag.js 1 year ago withGridLegacyMigration.js 2 years ago withHeadlineLegacyMigration.js 2 years ago withHtmlAttributes.js 1 year ago withImageLegacyMigration.js 2 years ago withSetAttributes.js 2 years ago withStyles.js 1 year ago withUniqueId.js 2 years ago
withImageLegacyMigration.js
79 lines
1 import { useEffect } from '@wordpress/element';
2 import { getBlockType } from '@wordpress/blocks';
3 import { migrationPipe, updateBlockVersion } from './migrations/utils';
4 import migrateSpacing from './migrations/migrateSpacing';
5 import migrateBorders from './migrations/migrateBorders';
6 import { isEmpty } from 'lodash';
7
8 export const currentBlockVersion = 2;
9
10 /**
11 * Migrate our Image attributes.
12 *
13 * @param {Object} Props Function props.
14 * @param {Object} Props.attributes The block attributes.
15 * @param {Object} Props.defaults The block defaults.
16 * @param {string} Props.mode The migration mode.
17 * @return {Object} Updated attributes.
18 * @since 1.8.0
19 */
20 export function migrateImageAttributes( { attributes, defaults, mode } ) {
21 return migrationPipe(
22 attributes,
23 [
24 migrateSpacing( {
25 blockVersionLessThan: 2,
26 defaults,
27 attributesToMigrate: [
28 'paddingTop',
29 'paddingRight',
30 'paddingBottom',
31 'paddingLeft',
32 'marginTop',
33 'marginRight',
34 'marginBottom',
35 'marginLeft',
36 ],
37 } ),
38 migrateBorders( {
39 blockVersionLessThan: 2,
40 defaults,
41 attributesToMigrate: [
42 'borderSizeTop',
43 'borderSizeRight',
44 'borderSizeBottom',
45 'borderSizeLeft',
46 'borderRadiusTopRight',
47 'borderRadiusBottomRight',
48 'borderRadiusBottomLeft',
49 'borderRadiusTopLeft',
50 ],
51 } ),
52 updateBlockVersion( currentBlockVersion ),
53 ],
54 mode
55 );
56 }
57
58 export default ( WrappedComponent ) => {
59 return ( props ) => {
60 const {
61 attributes,
62 setAttributes,
63 } = props;
64
65 useEffect( () => {
66 const newAttributes = migrateImageAttributes( {
67 attributes,
68 defaults: getBlockType( 'generateblocks/image' )?.attributes,
69 } );
70
71 if ( ! isEmpty( newAttributes ) ) {
72 setAttributes( newAttributes );
73 }
74 }, [] );
75
76 return ( <WrappedComponent { ...props } /> );
77 };
78 };
79