Skip to content

Commit 4098a50

Browse files
committed
fix: add typography deprecation for font size
1 parent 17ae06e commit 4098a50

File tree

19 files changed

+496
-21
lines changed

19 files changed

+496
-21
lines changed

src/block-components/typography/attributes.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { deprecatedAddAttributes } from './deprecated'
22

33
const typographyAttributes = {
4-
fontSize: {
5-
stkResponsive: true,
6-
type: 'string',
7-
default: '',
8-
stkUnits: 'px',
9-
},
104
lineHeight: {
115
stkResponsive: true,
126
type: 'number',
@@ -104,4 +98,18 @@ export const addAttributes = ( attrObject, selector = '.stk-content', options =
10498
versionDeprecated: '',
10599
attrNameTemplate,
106100
} )
101+
102+
attrObject.add( {
103+
attributes: {
104+
fontSize: {
105+
stkResponsive: true,
106+
type: 'string',
107+
default: '',
108+
stkUnits: 'px',
109+
},
110+
},
111+
versionAdded: '3.15.3',
112+
versionDeprecated: '',
113+
attrNameTemplate,
114+
} )
107115
}

src/block-components/typography/deprecated.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ export const deprecatedAddAttributes = ( attrObject, options ) => {
2222
versionDeprecated: '3.12.0',
2323
attrNameTemplate,
2424
} )
25+
26+
attrObject.add( {
27+
attributes: {
28+
fontSize: {
29+
stkResponsive: true,
30+
type: 'number',
31+
default: '',
32+
stkUnits: 'px',
33+
},
34+
},
35+
versionAdded: '3.0.0',
36+
versionDeprecated: '3.15.3',
37+
attrNameTemplate,
38+
} )
2539
}
2640

2741
export const deprecateTypographyGradientColor = {
@@ -96,3 +110,27 @@ export const deprecateTypographyShadowColor = {
96110
return newAttributes
97111
},
98112
}
113+
114+
export const deprecateTypographyFontSize = {
115+
isEligible: attrNameTemplate => attributes => {
116+
const getAttrName = getAttrNameFunction( attrNameTemplate )
117+
const getAttribute = _attrName => attributes[ getAttrName( _attrName ) ]
118+
119+
const fontSize = getAttribute( 'fontSize' )
120+
121+
return typeof fontSize === 'number'
122+
},
123+
migrate: attrNameTemplate => attributes => {
124+
const getAttrName = getAttrNameFunction( attrNameTemplate )
125+
const getAttribute = _attrName => attributes[ getAttrName( _attrName ) ]
126+
127+
const fontSize = getAttribute( 'fontSize' )
128+
129+
const newAttributes = {
130+
...attributes,
131+
[ getAttrName( 'fontSize' ) ]: String( fontSize ),
132+
}
133+
134+
return newAttributes
135+
},
136+
}

src/block-components/typography/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ import {
2828
memo,
2929
} from '@wordpress/element'
3030

31-
export { deprecateTypographyGradientColor, deprecateTypographyShadowColor } from './deprecated'
31+
export {
32+
deprecateTypographyGradientColor, deprecateTypographyShadowColor, deprecateTypographyFontSize,
33+
} from './deprecated'
3234

3335
export const Typography = memo( forwardRef( ( props, ref ) => {
3436
const {

src/block/button/deprecated.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,31 @@ import {
66
deprecateBlockBackgroundColorOpacity, deprecateButtonGradientColor,
77
deprecateContainerBackgroundColorOpacity, deprecateShadowColor,
88
deprecateContainerShadowColor, deprecateBlockShadowColor,
9+
deprecateTypographyFontSize,
910
} from '~stackable/block-components'
1011

1112
const deprecated = [
13+
{
14+
// Support the change of type for fontSize
15+
attributes: attributes( '3.15.2' ),
16+
save: withVersion( '3.15.2' )( Save ),
17+
isEligible: attributes => {
18+
return deprecateTypographyFontSize.isEligible( 'button%s' )( attributes )
19+
},
20+
migrate: attributes => {
21+
let newAttributes = { ...attributes }
22+
23+
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
24+
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
25+
newAttributes = deprecateShadowColor.migrate( 'button%s' )( newAttributes )
26+
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
27+
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
28+
newAttributes = deprecateButtonGradientColor.migrate( 'button%s' )( newAttributes )
29+
newAttributes = deprecateTypographyFontSize.migrate( 'button%s' )( newAttributes )
30+
31+
return newAttributes
32+
},
33+
},
1234
{
1335
// Support the new shadow color.
1436
attributes: attributes( '3.12.11' ),

src/block/count-up/deprecated.js

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

1010
const deprecated = [
11+
{
12+
// Support the change of type for fontSize
13+
attributes: attributes( '3.15.2' ),
14+
save: withVersion( '3.15.2' )( Save ),
15+
isEligible: attributes => {
16+
return deprecateTypographyFontSize.isEligible( '%s' )( attributes )
17+
},
18+
migrate: attributes => {
19+
let newAttributes = { ...attributes }
20+
21+
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
22+
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
23+
newAttributes = deprecateTypographyGradientColor.migrate( '%s' )( newAttributes )
24+
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
25+
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
26+
newAttributes = deprecateTypographyShadowColor.migrate( '%s' )( newAttributes )
27+
newAttributes = deprecateTypographyFontSize.migrate( '%s' )( newAttributes )
28+
29+
return newAttributes
30+
},
31+
},
1132
{
1233
// Support the new shadow color.
1334
attributes: attributes( '3.12.11' ),

src/block/countdown/deprecated.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
11
import {
22
deprecateBlockBackgroundColorOpacity, deprecateContainerBackgroundColorOpacity, deprecateTypographyGradientColor,
3-
deprecateBlockShadowColor, deprecateContainerShadowColor,
3+
deprecateBlockShadowColor, deprecateContainerShadowColor, deprecateTypographyFontSize,
44
} from '~stackable/block-components'
55
import { Save } from './save'
66
import { attributes } from './schema'
77

88
import { withVersion } from '~stackable/higher-order'
99

1010
const deprecated = [
11+
{
12+
// Support the change of type for fontSize
13+
attributes: attributes( '3.15.2' ),
14+
save: withVersion( '3.15.2' )( Save ),
15+
isEligible: attributes => {
16+
const hasDigitFontSize = deprecateTypographyFontSize.isEligible( 'digit%s' )( attributes )
17+
const hasLabelFontSize = deprecateTypographyFontSize.isEligible( 'label%s' )( attributes )
18+
const hasMessageFontSize = deprecateTypographyFontSize.isEligible( 'message%s' )( attributes )
19+
const isNotV4 = attributes.version < 2 || typeof attributes.version === 'undefined'
20+
21+
return hasDigitFontSize || hasLabelFontSize || hasMessageFontSize || isNotV4
22+
},
23+
migrate: attributes => {
24+
let newAttributes = { ...attributes }
25+
26+
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
27+
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
28+
newAttributes = deprecateTypographyGradientColor.migrate( 'digit%s' )( newAttributes )
29+
newAttributes = deprecateTypographyGradientColor.migrate( 'label%s' )( newAttributes )
30+
newAttributes = deprecateTypographyGradientColor.migrate( 'message%s' )( newAttributes )
31+
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
32+
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
33+
newAttributes = deprecateTypographyFontSize.migrate( 'digit%s' )( newAttributes )
34+
newAttributes = deprecateTypographyFontSize.migrate( 'label%s' )( newAttributes )
35+
newAttributes = deprecateTypographyFontSize.migrate( 'message%s' )( newAttributes )
36+
37+
return newAttributes
38+
},
39+
},
1140
{
1241
// Support the new shadow color.
1342
attributes: attributes( '3.12.11' ),

src/block/heading/deprecated.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { withVersion } from '~stackable/higher-order'
1111
import compareVersions from 'compare-versions'
1212
import {
1313
deprecateBlockBackgroundColorOpacity, deprecateContainerBackgroundColorOpacity, deprecateTypographyGradientColor, getResponsiveClasses,
14-
deprecateBlockShadowColor, deprecateContainerShadowColor, deprecateTypographyShadowColor,
14+
deprecateBlockShadowColor, deprecateContainerShadowColor, deprecateTypographyShadowColor, deprecateTypographyFontSize,
1515
} from '~stackable/block-components'
1616

1717
/**
@@ -34,6 +34,27 @@ addFilter( 'stackable.heading.save.blockClassNames', 'stackable/3.6.1', ( output
3434
} )
3535

3636
const deprecated = [
37+
{
38+
// Support the change of type for fontSize
39+
attributes: attributes( '3.15.2' ),
40+
save: withVersion( '3.15.2' )( Save ),
41+
isEligible: attributes => {
42+
return deprecateTypographyFontSize.isEligible( '%s' )( attributes )
43+
},
44+
migrate: attributes => {
45+
let newAttributes = { ...attributes }
46+
47+
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
48+
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
49+
newAttributes = deprecateTypographyGradientColor.migrate( '%s' )( newAttributes )
50+
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
51+
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
52+
newAttributes = deprecateTypographyShadowColor.migrate( '%s' )( newAttributes )
53+
newAttributes = deprecateTypographyFontSize.migrate( '%s' )( newAttributes )
54+
55+
return newAttributes
56+
},
57+
},
3758
{
3859
// Support the new shadow color.
3960
attributes: attributes( '3.12.11' ),

src/block/icon-list-item/deprecated.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,28 @@ import { Save } from './save'
22
import { attributes } from './schema'
33

44
import { withVersion } from '~stackable/higher-order'
5-
import { deprecateBlockShadowColor, deprecateContainerShadowColor } from '~stackable/block-components'
5+
import {
6+
deprecateBlockShadowColor, deprecateContainerShadowColor, deprecateTypographyFontSize,
7+
} from '~stackable/block-components'
68

79
const deprecated = [
10+
{
11+
// Support the change of type for fontSize
12+
attributes: attributes( '3.15.2' ),
13+
save: withVersion( '3.15.2' )( Save ),
14+
isEligible: attributes => {
15+
return deprecateTypographyFontSize.isEligible( '%s' )( attributes )
16+
},
17+
migrate: attributes => {
18+
let newAttributes = { ...attributes }
19+
20+
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
21+
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
22+
newAttributes = deprecateTypographyFontSize.migrate( '%s' )( newAttributes )
23+
24+
return newAttributes
25+
},
26+
},
827
{
928
// Support the new shadow color.
1029
attributes: attributes( '3.12.11' ),

src/block/icon-list/deprecated/index.js

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

@@ -68,6 +68,66 @@ const getEquivalentIconSize = iconSize => {
6868
}
6969

7070
const deprecated = [
71+
{
72+
// Support the new shadow color.
73+
attributes: attributes( '3.15.2' ),
74+
save: withVersion( '3.15.2' )( Save ),
75+
isEligible: attributes => {
76+
return deprecateTypographyFontSize.isEligible( '%s' )( attributes )
77+
},
78+
supports: {
79+
anchor: true,
80+
spacing: true,
81+
__unstablePasteTextInline: true,
82+
__experimentalSelector: 'ol,ul',
83+
__experimentalOnMerge: true,
84+
},
85+
migrate: ( attributes, innerBlocks ) => {
86+
let newAttributes = { ...attributes }
87+
const {
88+
text, icons, iconSize, ordered, iconGap,
89+
} = attributes
90+
91+
const _iconSize = iconSize ? iconSize : 1
92+
const _iconGap = iconGap ? iconGap : 0
93+
94+
newAttributes = {
95+
...newAttributes,
96+
listFullWidth: false,
97+
iconVerticalAlignment: 'baseline',
98+
iconGap: _iconGap + 4, // Our gap is smaller now.
99+
iconSize: ordered
100+
? getEquivalentFontSize( _iconSize )
101+
: getEquivalentIconSize( _iconSize ),
102+
}
103+
104+
if ( ! text ) {
105+
const block = createBlock( 'stackable/icon-list-item' )
106+
innerBlocks = [ block ]
107+
} else {
108+
const contents = textToArray( text )
109+
const blocks = contents.map( ( content, index ) => {
110+
const newBlock = createBlock( 'stackable/icon-list-item', {
111+
text: content,
112+
icon: getUniqueIcon( icons, index ),
113+
} )
114+
newBlock.attributes.uniqueId = createUniqueClass( newBlock.clientId )
115+
116+
return newBlock
117+
} )
118+
innerBlocks = blocks
119+
}
120+
121+
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
122+
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
123+
newAttributes = deprecateTypographyGradientColor.migrate( '%s' )( newAttributes )
124+
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
125+
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
126+
newAttributes = deprecateTypographyFontSize.migrate( '%s' )( newAttributes )
127+
128+
return [ newAttributes, innerBlocks ]
129+
},
130+
},
71131
{
72132
// Support the new shadow color.
73133
attributes: attributes( '3.12.11' ),

src/block/image/deprecated.js

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

1010
import { RichText } from '@wordpress/block-editor'
@@ -59,6 +59,27 @@ addFilter( 'stackable.image.save.wrapper', 'stackable/image-caption-wrapper', (
5959
} )
6060

6161
const deprecated = [
62+
{
63+
// Support the change of type for fontSize
64+
attributes: attributes( '3.15.2' ),
65+
save: withVersion( '3.15.2' )( Save ),
66+
isEligible: attributes => {
67+
return deprecateTypographyFontSize.isEligible( 'figcaption%s' )( attributes )
68+
},
69+
migrate: attributes => {
70+
let newAttributes = { ...attributes }
71+
72+
newAttributes = deprecationImageOverlayOpacity.migrate( newAttributes )
73+
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
74+
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
75+
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
76+
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
77+
newAttributes = deprecateShadowColor.migrate( 'image%s' )( newAttributes )
78+
newAttributes = deprecateTypographyFontSize.migrate( 'figcaption%s' )( newAttributes )
79+
80+
return newAttributes
81+
},
82+
},
6283
{
6384
// Support the new shadow color.
6485
attributes: attributes( '3.12.11' ),

0 commit comments

Comments
 (0)