components
3 years ago
css
3 years ago
variations
3 years ago
attributes.js
3 years ago
block-controls.js
3 years ago
block.js
3 years ago
deprecated.js
5 years ago
edit.js
3 years ago
editor.scss
3 years ago
migrate-sizing.js
3 years ago
migrate-sizing.js
53 lines
| 1 | export default function MigrateSizing( { attributes, setAttributes } ) { |
| 2 | const sizingAttributes = {}; |
| 3 | const oldAttributes = {}; |
| 4 | |
| 5 | // Only migrate these if we're an active Grid item. |
| 6 | if ( attributes.isGrid ) { |
| 7 | if ( attributes.width ) { |
| 8 | sizingAttributes.width = attributes.width + '%'; |
| 9 | oldAttributes.width = ''; |
| 10 | } |
| 11 | |
| 12 | if ( attributes.widthTablet || attributes.autoWidthTablet ) { |
| 13 | sizingAttributes.widthTablet = attributes.autoWidthTablet ? 'auto' : attributes.widthTablet + '%'; |
| 14 | oldAttributes.widthTablet = ''; |
| 15 | oldAttributes.autoWidthTablet = false; |
| 16 | } |
| 17 | |
| 18 | if ( attributes.widthMobile || attributes.autoWidthMobile ) { |
| 19 | sizingAttributes.widthMobile = attributes.autoWidthMobile ? 'auto' : attributes.widthMobile + '%'; |
| 20 | oldAttributes.widthMobile = ''; |
| 21 | oldAttributes.autoWidthMobile = false; |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | if ( attributes.minHeight ) { |
| 26 | sizingAttributes.minHeight = attributes.minHeight + attributes.minHeightUnit; |
| 27 | oldAttributes.minHeight = false; |
| 28 | oldAttributes.minHeightUnit = 'px'; |
| 29 | } |
| 30 | |
| 31 | if ( attributes.minHeightTablet ) { |
| 32 | sizingAttributes.minHeightTablet = attributes.minHeightTablet + attributes.minHeightUnitTablet; |
| 33 | oldAttributes.minHeightTablet = false; |
| 34 | oldAttributes.minHeightUnitTablet = 'px'; |
| 35 | } |
| 36 | |
| 37 | if ( attributes.minHeightMobile ) { |
| 38 | sizingAttributes.minHeightMobile = attributes.minHeightMobile + attributes.minHeightUnitMobile; |
| 39 | oldAttributes.minHeightMobile = false; |
| 40 | oldAttributes.minHeightUnitMobile = 'px'; |
| 41 | } |
| 42 | |
| 43 | if ( Object.keys( oldAttributes ).length || Object.keys( sizingAttributes ).length ) { |
| 44 | setAttributes( { |
| 45 | ...oldAttributes, |
| 46 | sizing: { |
| 47 | ...attributes.sizing, |
| 48 | ...sizingAttributes, |
| 49 | }, |
| 50 | } ); |
| 51 | } |
| 52 | } |
| 53 |