PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.8.3
GenerateBlocks v1.8.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 / migrations / utils.js
generateblocks / src / hoc / migrations Last commit date
migrateBorders.js 2 years ago migrateGlobalStyleAttrs.js 2 years ago migrateIconPadding.js 2 years ago migrateSizing.js 2 years ago migrateSpacing.js 2 years ago migrateTypography.js 2 years ago migratingIconSizing.js 2 years ago utils.js 2 years ago
utils.js
59 lines
1 import { isEmpty } from 'lodash';
2 import isBlockVersionLessThan from '../../utils/check-block-version';
3
4 function migrationPipe( existingAttributes, callbacks = [], mode ) {
5 return callbacks.reduce( ( resultAttrs, callback ) => {
6 const result = callback( resultAttrs, existingAttributes, mode );
7 return Object.assign( {}, result );
8 }, {} );
9 }
10
11 function updateBlockVersion( newBlockVersion ) {
12 return function( attrs, existingAttrs, mode ) {
13 if ( 'css' === mode ) {
14 return attrs;
15 }
16
17 if ( isBlockVersionLessThan( existingAttrs.blockVersion, newBlockVersion ) ) {
18 attrs.blockVersion = newBlockVersion;
19 }
20
21 return attrs;
22 };
23 }
24
25 function addToAttrsObject( { attrs = {}, attributeName, existingAttrs = {}, newAttrs = {}, oldAttrs = {} } ) {
26 if ( isEmpty( newAttrs ) ) {
27 return attrs;
28 }
29
30 return {
31 ...attrs,
32 [ attributeName ]: {
33 ...existingAttrs,
34 ...attrs[ attributeName ],
35 ...newAttrs,
36 },
37 ...oldAttrs,
38 };
39 }
40
41 function setIsDynamic( attrs, existingAttrs, mode ) {
42 if ( 'css' === mode ) {
43 return attrs;
44 }
45
46 if ( ! existingAttrs.isDynamic ) {
47 attrs.isDynamic = true;
48 }
49
50 return attrs;
51 }
52
53 export {
54 migrationPipe,
55 updateBlockVersion,
56 addToAttrsObject,
57 setIsDynamic,
58 };
59