Skip to content

Commit 4a68153

Browse files
committed
fix: add block height deprecations
1 parent 4098a50 commit 4a68153

File tree

51 files changed

+1250
-69
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1250
-69
lines changed

src/block-components/block-div/deprecated.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { deprecationBackgrounColorOpacity, deprecateShadowColor } from '../helpers'
1+
import {
2+
deprecationBackgrounColorOpacity, deprecateShadowColor, deprecateSizeControlHeight,
3+
} from '../helpers'
24

35
import { addFilter } from '@wordpress/hooks'
46
import { semverCompare } from '~stackable/util'
@@ -38,3 +40,12 @@ export const deprecateBlockShadowColor = {
3840
return deprecateShadowColor.migrate( 'block%s' )( attributes )
3941
},
4042
}
43+
44+
export const deprecateBlockHeight = {
45+
isEligible: attributes => {
46+
return deprecateSizeControlHeight.isEligible( 'block%s' )( attributes )
47+
},
48+
migrate: attributes => {
49+
return deprecateSizeControlHeight.migrate( 'block%s' )( attributes )
50+
},
51+
}

src/block-components/block-div/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import { CustomAttributes } from '../custom-attributes'
1818
import { version as VERSION } from 'stackable'
1919

2020
export { useUniqueId }
21-
export { deprecateBlockBackgroundColorOpacity, deprecateBlockShadowColor } from './deprecated'
21+
export {
22+
deprecateBlockBackgroundColorOpacity, deprecateBlockShadowColor, deprecateBlockHeight,
23+
} from './deprecated'
2224

2325
export const BlockDiv = memo( props => {
2426
const {

src/block-components/helpers/size/attributes.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1+
import { deprecatedAddAttributes } from './deprecated'
2+
13
export const sizeAttributes = {
2-
height: {
3-
stkResponsive: true,
4-
stkUnits: 'px',
5-
type: 'string',
6-
default: '',
7-
},
84
width: {
95
stkResponsive: true,
106
stkUnits: 'px',
@@ -37,10 +33,26 @@ export const sizeAttributes = {
3733
}
3834

3935
export const addSizeAttributes = ( attrObject, attrNameTemplate = '%s' ) => {
36+
deprecatedAddAttributes( attrObject, attrNameTemplate )
37+
4038
attrObject.add( {
4139
attributes: sizeAttributes,
4240
attrNameTemplate,
4341
versionAdded: '3.0.0',
4442
versionDeprecated: '',
4543
} )
44+
45+
attrObject.add( {
46+
attributes: {
47+
height: {
48+
stkResponsive: true,
49+
stkUnits: 'px',
50+
type: 'string',
51+
default: '',
52+
},
53+
},
54+
attrNameTemplate,
55+
versionAdded: '3.15.3',
56+
versionDeprecated: '',
57+
} )
4658
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { getAttrNameFunction } from '~stackable/util'
2+
3+
export const deprecatedAddAttributes = ( attrObject, attrNameTemplate = '%s' ) => {
4+
attrObject.add( {
5+
attributes: {
6+
height: {
7+
stkResponsive: true,
8+
stkUnits: 'px',
9+
type: 'number',
10+
default: '',
11+
},
12+
},
13+
attrNameTemplate,
14+
versionAdded: '3.0.0',
15+
versionDeprecated: '3.15.3',
16+
} )
17+
}
18+
19+
export const deprecateSizeControlHeight = {
20+
isEligible: attrNameTemplate => attributes => {
21+
const getAttrName = getAttrNameFunction( attrNameTemplate )
22+
const getAttribute = _attrName => attributes[ getAttrName( _attrName ) ]
23+
24+
const height = getAttribute( 'height' )
25+
26+
return typeof height === 'number'
27+
},
28+
migrate: attrNameTemplate => attributes => {
29+
const getAttrName = getAttrNameFunction( attrNameTemplate )
30+
const getAttribute = _attrName => attributes[ getAttrName( _attrName ) ]
31+
32+
const height = getAttribute( 'height' )
33+
34+
const newAttributes = {
35+
...attributes,
36+
[ getAttrName( 'height' ) ]: String( height ),
37+
}
38+
39+
return newAttributes
40+
},
41+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './attributes'
22
export * from './style'
33
export * from './edit'
4+
export { deprecateSizeControlHeight } from './deprecated'

src/block/accordion/deprecated.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,29 @@ import { attributes } from './schema'
44
import { withVersion } from '~stackable/higher-order'
55
import {
66
deprecateBlockBackgroundColorOpacity, deprecateContainerBackgroundColorOpacity,
7-
deprecateBlockShadowColor, deprecateContainerShadowColor,
7+
deprecateBlockShadowColor, deprecateContainerShadowColor, deprecateBlockHeight,
88
} from '~stackable/block-components'
99

1010
const deprecated = [
11+
{
12+
// Support the change of type for block height
13+
attributes: attributes( '3.15.2' ),
14+
save: withVersion( '3.15.2' )( Save ),
15+
isEligible: attributes => {
16+
return deprecateBlockHeight.isEligible( attributes )
17+
},
18+
migrate: attributes => {
19+
let newAttributes = { ...attributes }
20+
21+
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
22+
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
23+
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
24+
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
25+
newAttributes = deprecateBlockHeight.migrate( newAttributes )
26+
27+
return newAttributes
28+
},
29+
},
1130
{
1231
// Support the new shadow color.
1332
attributes: attributes( '3.12.11' ),

src/block/blockquote/deprecated.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,34 @@ import { attributes } from './schema'
44
import { withVersion } from '~stackable/higher-order'
55
import {
66
deprecateBlockBackgroundColorOpacity, deprecateContainerBackgroundColorOpacity,
7-
deprecateBlockShadowColor, deprecateContainerShadowColor,
7+
deprecateBlockShadowColor, deprecateContainerShadowColor, deprecateBlockHeight,
88
} from '~stackable/block-components'
99

1010
const deprecated = [
11+
{
12+
// Support the change of type for block height
13+
attributes: attributes( '3.15.2' ),
14+
save: withVersion( '3.15.2' )( Save ),
15+
isEligible: attributes => {
16+
const isNotV4 = attributes.version < 2 || typeof attributes.version === 'undefined'
17+
const hasNumberBlockHeight = deprecateBlockHeight.isEligible( attributes )
18+
return isNotV4 || hasNumberBlockHeight
19+
},
20+
migrate: attributes => {
21+
let newAttributes = {
22+
...attributes,
23+
version: 2,
24+
}
25+
26+
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
27+
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
28+
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
29+
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
30+
newAttributes = deprecateBlockHeight.migrate( newAttributes )
31+
32+
return newAttributes
33+
},
34+
},
1135
{
1236
// Support the new shadow color.
1337
attributes: attributes( '3.12.11' ),

src/block/button-group/deprecated/index.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,29 @@ import { attributes } from '../schema'
66
import { withVersion } from '~stackable/higher-order'
77
import {
88
deprecateBlockBackgroundColorOpacity, deprecateContainerBackgroundColorOpacity,
9-
deprecateBlockShadowColor, deprecateContainerShadowColor,
9+
deprecateBlockShadowColor, deprecateContainerShadowColor, deprecateBlockHeight,
1010
} from '~stackable/block-components'
1111

1212
const deprecated = [
13+
{
14+
// Support the change of type for block height
15+
attributes: attributes( '3.15.2' ),
16+
save: withVersion( '3.15.2' )( Save ),
17+
isEligible: attributes => {
18+
return deprecateBlockHeight.isEligible( attributes )
19+
},
20+
migrate: attributes => {
21+
let newAttributes = { ...attributes }
22+
23+
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
24+
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
25+
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
26+
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
27+
newAttributes = deprecateBlockHeight.migrate( newAttributes )
28+
29+
return newAttributes
30+
},
31+
},
1332
{
1433
// Support the new shadow color.
1534
attributes: attributes( '3.12.11' ),

src/block/button/deprecated.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
deprecateBlockBackgroundColorOpacity, deprecateButtonGradientColor,
77
deprecateContainerBackgroundColorOpacity, deprecateShadowColor,
88
deprecateContainerShadowColor, deprecateBlockShadowColor,
9-
deprecateTypographyFontSize,
9+
deprecateTypographyFontSize, deprecateBlockHeight,
1010
} from '~stackable/block-components'
1111

1212
const deprecated = [
@@ -15,7 +15,9 @@ const deprecated = [
1515
attributes: attributes( '3.15.2' ),
1616
save: withVersion( '3.15.2' )( Save ),
1717
isEligible: attributes => {
18-
return deprecateTypographyFontSize.isEligible( 'button%s' )( attributes )
18+
const hasNumberFontSize = deprecateTypographyFontSize.isEligible( '%s' )( attributes )
19+
const hasNumberBlockHeight = deprecateBlockHeight.isEligible( attributes )
20+
return hasNumberFontSize || hasNumberBlockHeight
1921
},
2022
migrate: attributes => {
2123
let newAttributes = { ...attributes }
@@ -27,6 +29,7 @@ const deprecated = [
2729
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
2830
newAttributes = deprecateButtonGradientColor.migrate( 'button%s' )( newAttributes )
2931
newAttributes = deprecateTypographyFontSize.migrate( 'button%s' )( newAttributes )
32+
newAttributes = deprecateBlockHeight.migrate( newAttributes )
3033

3134
return newAttributes
3235
},

src/block/call-to-action/deprecated.js

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { attributes } from './schema'
1010
import { withVersion } from '~stackable/higher-order'
1111
import {
1212
deprecateBlockBackgroundColorOpacity, deprecateContainerBackgroundColorOpacity,
13-
deprecateBlockShadowColor, deprecateContainerShadowColor, deprecateShadowColor,
13+
deprecateBlockShadowColor, deprecateContainerShadowColor, deprecateShadowColor, deprecateBlockHeight,
1414
} from '~stackable/block-components'
1515
import compareVersions from 'compare-versions'
1616

@@ -35,6 +35,77 @@ addFilter( 'stackable.call-to-action.save.innerClassNames', 'stackable/3.8.0', (
3535
} )
3636

3737
const deprecated = [
38+
{
39+
// Support the change of type for block height
40+
attributes: attributes( '3.15.2' ),
41+
save: withVersion( '3.15.2' )( Save ),
42+
isEligible: attributes => {
43+
const isNotV4 = attributes.version < 2 || typeof attributes.version === 'undefined'
44+
const hasNumberBlockHeight = deprecateBlockHeight.isEligible( attributes )
45+
return isNotV4 || hasNumberBlockHeight
46+
},
47+
migrate: ( attributes, innerBlocks ) => {
48+
const isNotV4 = attributes.version < 2 || typeof attributes.version === 'undefined'
49+
50+
let newAttributes = {
51+
...attributes,
52+
}
53+
54+
if ( isNotV4 ) {
55+
newAttributes = {
56+
...newAttributes,
57+
version: 2,
58+
}
59+
60+
// Update the vertical align into flexbox
61+
const hasOldVerticalAlign = !! attributes.containerVerticalAlign // Column only, this was changed to flexbox
62+
63+
if ( hasOldVerticalAlign ) {
64+
newAttributes = {
65+
...newAttributes,
66+
containerVerticalAlign: '',
67+
innerBlockAlign: attributes.containerVerticalAlign,
68+
}
69+
}
70+
71+
// If the inner blocks are horizontal, adjust to accomodate the new
72+
// column gap, it will modify blocks because people used block
73+
// margins before instead of a proper column gap.
74+
if ( attributes.innerBlockOrientation === 'horizontal' ) {
75+
innerBlocks.forEach( ( block, index ) => {
76+
if ( index ) {
77+
if ( ! block.attributes.blockMargin ) {
78+
block.attributes.blockMargin = {
79+
top: '',
80+
right: '',
81+
bottom: '',
82+
left: '',
83+
}
84+
}
85+
if ( block.attributes.blockMargin.left === '' ) {
86+
block.attributes.blockMargin.left = 24
87+
}
88+
}
89+
} )
90+
91+
newAttributes = {
92+
...newAttributes,
93+
innerBlockColumnGap: 0,
94+
}
95+
}
96+
}
97+
98+
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
99+
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
100+
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
101+
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
102+
newAttributes = deprecateShadowColor.migrate( 'topSeparator%s' )( newAttributes )
103+
newAttributes = deprecateShadowColor.migrate( 'bottomSeparator%s' )( newAttributes )
104+
newAttributes = deprecateBlockHeight.migrate( newAttributes )
105+
106+
return [ newAttributes, innerBlocks ]
107+
},
108+
},
38109
{
39110
// Support the new shadow color.
40111
attributes: attributes( '3.12.11' ),

0 commit comments

Comments
 (0)