@wordpress/global-styles-engine 1.15.1 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/core/merge.cjs +22 -17
- package/build/core/merge.cjs.map +2 -2
- package/build/core/render.cjs +16 -8
- package/build/core/render.cjs.map +2 -2
- package/build/settings/get-style.cjs +17 -1
- package/build/settings/get-style.cjs.map +2 -2
- package/build/settings/set-style.cjs +2 -1
- package/build/settings/set-style.cjs.map +2 -2
- package/build/style-state-back-compat.cjs +94 -0
- package/build/style-state-back-compat.cjs.map +7 -0
- package/build-module/core/merge.mjs +22 -17
- package/build-module/core/merge.mjs.map +2 -2
- package/build-module/core/render.mjs +16 -8
- package/build-module/core/render.mjs.map +2 -2
- package/build-module/settings/get-style.mjs +17 -1
- package/build-module/settings/get-style.mjs.map +2 -2
- package/build-module/settings/set-style.mjs +2 -1
- package/build-module/settings/set-style.mjs.map +2 -2
- package/build-module/style-state-back-compat.mjs +68 -0
- package/build-module/style-state-back-compat.mjs.map +7 -0
- package/build-types/core/merge.d.ts.map +1 -1
- package/build-types/core/render.d.ts.map +1 -1
- package/build-types/settings/get-style.d.ts.map +1 -1
- package/build-types/settings/set-style.d.ts.map +1 -1
- package/build-types/style-state-back-compat.d.ts +28 -0
- package/build-types/style-state-back-compat.d.ts.map +1 -0
- package/package.json +6 -6
- package/src/core/merge.ts +25 -19
- package/src/core/render.tsx +18 -8
- package/src/settings/get-style.ts +23 -1
- package/src/settings/set-style.ts +2 -1
- package/src/style-state-back-compat.ts +137 -0
- package/src/test/render.test.ts +47 -8
- package/src/test/style-state-back-compat.test.ts +170 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { normalizeStyleStateAliases } from '../style-state-back-compat';
|
|
5
|
+
import type { GlobalStylesConfig } from '../types';
|
|
6
|
+
|
|
7
|
+
describe( 'normalizeStyleStateAliases', () => {
|
|
8
|
+
it( 'normalizes legacy responsive style state keys', () => {
|
|
9
|
+
const config = {
|
|
10
|
+
styles: {
|
|
11
|
+
mobile: {
|
|
12
|
+
color: { text: 'blue' },
|
|
13
|
+
},
|
|
14
|
+
tablet: {
|
|
15
|
+
color: { text: 'red' },
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
} as unknown as GlobalStylesConfig;
|
|
19
|
+
|
|
20
|
+
expect( normalizeStyleStateAliases( config ) ).toEqual( {
|
|
21
|
+
styles: {
|
|
22
|
+
'@mobile': {
|
|
23
|
+
color: { text: 'blue' },
|
|
24
|
+
},
|
|
25
|
+
'@tablet': {
|
|
26
|
+
color: { text: 'red' },
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
} );
|
|
30
|
+
} );
|
|
31
|
+
|
|
32
|
+
it( 'prefers canonical responsive style state keys', () => {
|
|
33
|
+
const config = {
|
|
34
|
+
styles: {
|
|
35
|
+
'@mobile': {
|
|
36
|
+
color: { text: 'green' },
|
|
37
|
+
},
|
|
38
|
+
mobile: {
|
|
39
|
+
color: { text: 'blue' },
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
} as unknown as GlobalStylesConfig;
|
|
43
|
+
|
|
44
|
+
expect( normalizeStyleStateAliases( config ) ).toEqual( {
|
|
45
|
+
styles: {
|
|
46
|
+
'@mobile': {
|
|
47
|
+
color: { text: 'green' },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
} );
|
|
51
|
+
} );
|
|
52
|
+
|
|
53
|
+
it( 'normalizes legacy custom style state keys', () => {
|
|
54
|
+
const config = {
|
|
55
|
+
styles: {
|
|
56
|
+
blocks: {
|
|
57
|
+
'core/navigation-link': {
|
|
58
|
+
'@current': {
|
|
59
|
+
color: { text: 'blue' },
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
} as unknown as GlobalStylesConfig;
|
|
65
|
+
|
|
66
|
+
expect( normalizeStyleStateAliases( config ) ).toEqual( {
|
|
67
|
+
styles: {
|
|
68
|
+
blocks: {
|
|
69
|
+
'core/navigation-link': {
|
|
70
|
+
'-current': {
|
|
71
|
+
color: { text: 'blue' },
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
} );
|
|
77
|
+
} );
|
|
78
|
+
|
|
79
|
+
it( 'normalizes nested style nodes', () => {
|
|
80
|
+
const config = {
|
|
81
|
+
styles: {
|
|
82
|
+
blocks: {
|
|
83
|
+
'core/button': {
|
|
84
|
+
variations: {
|
|
85
|
+
outline: {
|
|
86
|
+
mobile: {
|
|
87
|
+
color: { text: 'blue' },
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
elements: {
|
|
92
|
+
button: {
|
|
93
|
+
tablet: {
|
|
94
|
+
color: { text: 'red' },
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
} as unknown as GlobalStylesConfig;
|
|
102
|
+
|
|
103
|
+
expect( normalizeStyleStateAliases( config ) ).toEqual( {
|
|
104
|
+
styles: {
|
|
105
|
+
blocks: {
|
|
106
|
+
'core/button': {
|
|
107
|
+
variations: {
|
|
108
|
+
outline: {
|
|
109
|
+
'@mobile': {
|
|
110
|
+
color: { text: 'blue' },
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
elements: {
|
|
115
|
+
button: {
|
|
116
|
+
'@tablet': {
|
|
117
|
+
color: { text: 'red' },
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
} );
|
|
125
|
+
} );
|
|
126
|
+
|
|
127
|
+
it( 'returns the original config when no aliases are present', () => {
|
|
128
|
+
const config = {
|
|
129
|
+
styles: {
|
|
130
|
+
blocks: {
|
|
131
|
+
'core/button': {
|
|
132
|
+
'@mobile': {
|
|
133
|
+
color: { text: 'blue' },
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
} as unknown as GlobalStylesConfig;
|
|
139
|
+
|
|
140
|
+
expect( normalizeStyleStateAliases( config ) ).toBe( config );
|
|
141
|
+
} );
|
|
142
|
+
|
|
143
|
+
it( 'returns the original config outside the Gutenberg plugin', () => {
|
|
144
|
+
const config = {
|
|
145
|
+
styles: {
|
|
146
|
+
blocks: {
|
|
147
|
+
'core/button': {
|
|
148
|
+
mobile: {
|
|
149
|
+
color: { text: 'blue' },
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
} as unknown as GlobalStylesConfig;
|
|
155
|
+
/* eslint-disable @wordpress/wp-global-usage */
|
|
156
|
+
const testGlobalThis = globalThis as typeof globalThis & {
|
|
157
|
+
IS_GUTENBERG_PLUGIN?: boolean;
|
|
158
|
+
};
|
|
159
|
+
const isGutenbergPlugin = testGlobalThis.IS_GUTENBERG_PLUGIN;
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
testGlobalThis.IS_GUTENBERG_PLUGIN = false;
|
|
163
|
+
|
|
164
|
+
expect( normalizeStyleStateAliases( config ) ).toBe( config );
|
|
165
|
+
} finally {
|
|
166
|
+
testGlobalThis.IS_GUTENBERG_PLUGIN = isGutenbergPlugin;
|
|
167
|
+
}
|
|
168
|
+
/* eslint-enable @wordpress/wp-global-usage */
|
|
169
|
+
} );
|
|
170
|
+
} );
|