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 |