-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathdeprecated.js
More file actions
129 lines (115 loc) · 4.46 KB
/
deprecated.js
File metadata and controls
129 lines (115 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* Internal Dependencies
*/
import { Save } from './save'
import { attributes } from './schema'
/**
* External dependencies
*/
import { withVersion } from '~stackable/higher-order'
import compareVersions from 'compare-versions'
import {
deprecateBlockBackgroundColorOpacity, deprecateContainerBackgroundColorOpacity, deprecateTypographyGradientColor, getResponsiveClasses,
deprecateBlockShadowColor, deprecateContainerShadowColor, deprecateTypographyShadowColor,
} from '~stackable/block-components'
/**
* WordPress dependencies
*/
import { addFilter } from '@wordpress/hooks'
// Version 3.13.9 Deprecations
addFilter( 'stackable.heading.save.blockClassNames', 'stackable/3.13.9', ( output, props ) => {
if ( compareVersions( props.version, '3.13.9' ) >= 0 ) { // Current version is greater than or equal to 3.13.9
return output
}
const responsiveClass = getResponsiveClasses( props.attributes )
return [
props.className,
'stk-block-heading',
responsiveClass,
'stk-block-heading--v2',
]
} )
// Version 3.6.1 Deprecations
addFilter( 'stackable.heading.save.blockClassNames', 'stackable/3.6.1', ( output, props ) => {
if ( compareVersions( props.version, '3.6.1' ) === 1 ) { // Current version is greater than 3.6.1
return output
}
const responsiveClass = getResponsiveClasses( props.attributes )
return [
props.className,
'stk-block-heading',
responsiveClass,
]
} )
const deprecated = [
{
// Support the new shadow color.
attributes: attributes( '3.12.11' ),
save: withVersion( '3.12.11' )( Save ),
isEligible: attributes => {
const hasBlockShadow = deprecateBlockShadowColor.isEligible( attributes )
const hasContainerShadow = deprecateContainerShadowColor.isEligible( attributes )
const hasTextShadow = deprecateTypographyShadowColor.isEligible( '%s' )( attributes )
return hasBlockShadow || hasContainerShadow || hasTextShadow
},
migrate: attributes => {
let newAttributes = { ...attributes }
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateTypographyGradientColor.migrate( '%s' )( newAttributes )
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
newAttributes = deprecateTypographyShadowColor.migrate( '%s' )( newAttributes )
return newAttributes
},
},
// Support the new combined opacity and color.
{
attributes: attributes( '3.11.9' ),
save: withVersion( '3.11.9' )( Save ),
isEligible: attributes => {
const hasContainerOpacity = deprecateContainerBackgroundColorOpacity.isEligible( attributes )
const hasBlockOpacity = deprecateBlockBackgroundColorOpacity.isEligible( attributes )
const hasTextGradient = deprecateTypographyGradientColor.isEligible( '%s' )( attributes )
return hasContainerOpacity || hasBlockOpacity || hasTextGradient
},
migrate: attributes => {
let newAttributes = { ...attributes }
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateTypographyGradientColor.migrate( '%s' )( newAttributes )
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
newAttributes = deprecateTypographyShadowColor.migrate( '%s' )( newAttributes )
return newAttributes
},
},
// Support new margin-top/bottom classes.
{
attributes: attributes( '3.7.9' ),
save: withVersion( '3.7.9' )( Save ),
migrate: attributes => {
let newAttributes = deprecateContainerBackgroundColorOpacity.migrate( attributes )
newAttributes = deprecateTypographyGradientColor.migrate( '%s' )( newAttributes )
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
newAttributes = deprecateTypographyShadowColor.migrate( '%s' )( newAttributes )
return deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
},
},
{
attributes: attributes( '3.5.0' ),
save: withVersion( '3.5.0' )( Save ),
migrate: attributes => {
const {
textRemoveTextMargins: _textRemoveTextMargins,
...newAttributes
} = attributes
return {
...newAttributes,
useThemeTextMargins: attributes.textRemoveTextMargins ? false : true,
}
},
},
]
export default deprecated