@elementor/editor-canvas 0.3.0 → 0.4.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/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +18 -0
- package/dist/index.js +149 -123
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +147 -121
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/init-styles-renderer.test.ts +1 -1
- package/src/init-styles-renderer.ts +1 -1
- package/src/styles-renderer/__tests__/__mocks__/styles-schema.ts +733 -0
- package/src/styles-renderer/__tests__/index.test.ts +537 -72
- package/src/styles-renderer/get-styles-schema.ts +17 -0
- package/src/styles-renderer/multi-props.ts +26 -0
- package/src/styles-renderer/render.ts +10 -12
- package/src/styles-renderer/resolve.ts +99 -0
- package/src/styles-renderer/transformers/background-overlay-transformer.ts +3 -7
- package/src/styles-renderer/transformers/create-combine-array-transformer.ts +4 -15
- package/src/styles-renderer/transformers/create-corner-sizes-transformer.ts +33 -0
- package/src/styles-renderer/transformers/create-edge-sizes-transformer.ts +31 -0
- package/src/styles-renderer/transformers/gap-transformer.ts +20 -0
- package/src/styles-renderer/transformers/index.ts +18 -13
- package/src/styles-renderer/transformers/linked-dimensions-transformer.ts +13 -8
- package/src/styles-renderer/transformers/primitive-transformer.ts +7 -0
- package/src/styles-renderer/transformers/shadow-transformer.ts +5 -16
- package/src/styles-renderer/transformers/size-transformer.ts +3 -5
- package/src/styles-renderer/transformers/stroke-transformer.ts +3 -5
- package/src/styles-renderer/types.ts +3 -6
- package/src/styles-renderer/__tests__/__mocks__/style-definitions.ts +0 -171
- package/src/styles-renderer/transform.ts +0 -34
- package/src/styles-renderer/transformers/__tests__/background-overlay-transformer.test.ts +0 -46
- package/src/styles-renderer/transformers/__tests__/create-combine-array-transformer.test.ts +0 -61
- package/src/styles-renderer/transformers/__tests__/linked-dimensions-transformer.test.ts +0 -34
- package/src/styles-renderer/transformers/__tests__/shadow-transformer.test.ts +0 -127
- package/src/styles-renderer/transformers/__tests__/size-transformer.test.ts +0 -37
- package/src/styles-renderer/transformers/__tests__/stroke-transformer.test.ts +0 -59
- package/src/styles-renderer/transformers/border-radius-transformer.ts +0 -20
- package/src/styles-renderer/transformers/border-width-transformer.ts +0 -15
- package/src/styles-renderer/transformers/color-transformer.ts +0 -11
- package/src/styles-renderer/transformers/number-transformer.ts +0 -11
- package/src/styles-renderer/transformers/string-transformer.ts +0 -11
|
@@ -1,132 +1,597 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
/* eslint-disable testing-library/render-result-naming-convention */
|
|
2
|
+
import { createMockStyleDefinition } from 'test-utils';
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
backgroundImagePropTypeUtil,
|
|
5
|
+
backgroundOverlayPropTypeUtil,
|
|
6
|
+
borderRadiusPropTypeUtil,
|
|
7
|
+
borderWidthPropTypeUtil,
|
|
8
|
+
boxShadowPropTypeUtil,
|
|
9
|
+
colorPropTypeUtil,
|
|
10
|
+
gapPropTypeUtil,
|
|
11
|
+
linkedDimensionsPropTypeUtil,
|
|
12
|
+
shadowPropTypeUtil,
|
|
13
|
+
sizePropTypeUtil,
|
|
14
|
+
strokePropTypeUtil,
|
|
15
|
+
} from '@elementor/editor-props';
|
|
16
|
+
import type { BreakpointsMap } from '@elementor/editor-responsive';
|
|
17
|
+
import { type StyleDefinition } from '@elementor/editor-styles';
|
|
18
|
+
|
|
19
|
+
import { getStylesSchema } from '../get-styles-schema';
|
|
20
|
+
import render from '../render';
|
|
21
|
+
import transformers from '../transformers';
|
|
22
|
+
import { stylesSchemaMock } from './__mocks__/styles-schema';
|
|
23
|
+
|
|
24
|
+
jest.mock( '../get-styles-schema' );
|
|
25
|
+
|
|
26
|
+
describe( 'styles-renderer', () => {
|
|
27
|
+
beforeEach( () => {
|
|
28
|
+
jest.mocked( getStylesSchema ).mockReturnValue( stylesSchemaMock );
|
|
29
|
+
} );
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Prop Types
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
it( 'should transform stroke (including also size, number, string & color)', () => {
|
|
36
|
+
const styleDef = createMockStyleDefinition( {
|
|
37
|
+
id: 'test',
|
|
38
|
+
props: {
|
|
39
|
+
'text-stroke': strokePropTypeUtil.create( {
|
|
40
|
+
width: sizePropTypeUtil.create( {
|
|
41
|
+
size: 1,
|
|
42
|
+
unit: 'px',
|
|
43
|
+
} ),
|
|
44
|
+
color: colorPropTypeUtil.create( '#000000' ),
|
|
45
|
+
} ),
|
|
46
|
+
},
|
|
47
|
+
} );
|
|
48
|
+
|
|
49
|
+
const cssString = render( {
|
|
50
|
+
styles: [ styleDef ],
|
|
51
|
+
transformers,
|
|
52
|
+
breakpoints: mockBreakpoints,
|
|
53
|
+
} );
|
|
54
|
+
|
|
55
|
+
expect( cssString ).toBe( `<style data-style-id="test">.test{text-stroke:1px #000000;}</style>` );
|
|
56
|
+
} );
|
|
57
|
+
|
|
58
|
+
it( 'should transform box-shadow (including also shadow)', () => {
|
|
14
59
|
// Arrange.
|
|
15
|
-
const
|
|
60
|
+
const shadow = shadowPropTypeUtil.create( {
|
|
61
|
+
hOffset: sizePropTypeUtil.create( {
|
|
62
|
+
size: 1,
|
|
63
|
+
unit: 'px',
|
|
64
|
+
} ),
|
|
65
|
+
vOffset: sizePropTypeUtil.create( {
|
|
66
|
+
size: 1,
|
|
67
|
+
unit: 'px',
|
|
68
|
+
} ),
|
|
69
|
+
blur: sizePropTypeUtil.create( {
|
|
70
|
+
size: 1,
|
|
71
|
+
unit: 'px',
|
|
72
|
+
} ),
|
|
73
|
+
spread: sizePropTypeUtil.create( {
|
|
74
|
+
size: 1,
|
|
75
|
+
unit: 'px',
|
|
76
|
+
} ),
|
|
77
|
+
color: colorPropTypeUtil.create( '#000000' ),
|
|
78
|
+
} );
|
|
79
|
+
|
|
80
|
+
const shadowInset = shadowPropTypeUtil.create(
|
|
81
|
+
( prev ) => ( {
|
|
82
|
+
...prev,
|
|
83
|
+
position: 'inset',
|
|
84
|
+
} ),
|
|
85
|
+
{ base: shadow }
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const styleDef = createMockStyleDefinition( {
|
|
89
|
+
id: 'test',
|
|
90
|
+
props: {
|
|
91
|
+
'box-shadow': boxShadowPropTypeUtil.create( [ shadow, shadowInset ] ),
|
|
92
|
+
},
|
|
93
|
+
} );
|
|
16
94
|
|
|
17
95
|
// Act.
|
|
18
|
-
const cssString =
|
|
19
|
-
styles: [
|
|
20
|
-
transformers
|
|
96
|
+
const cssString = render( {
|
|
97
|
+
styles: [ styleDef ],
|
|
98
|
+
transformers,
|
|
21
99
|
breakpoints: mockBreakpoints,
|
|
22
100
|
} );
|
|
23
101
|
|
|
24
102
|
// Assert.
|
|
25
|
-
expect( cssString ).
|
|
103
|
+
expect( cssString ).toBe(
|
|
104
|
+
`<style data-style-id="test">.test{box-shadow:1px 1px 1px 1px #000000,1px 1px 1px 1px #000000 inset;}</style>`
|
|
105
|
+
);
|
|
26
106
|
} );
|
|
27
107
|
|
|
28
|
-
it( 'should
|
|
108
|
+
it( 'should transform linked-dimensions (including also size, number & string)', () => {
|
|
29
109
|
// Arrange.
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
110
|
+
const styleDef = createMockStyleDefinition( {
|
|
111
|
+
id: 'test',
|
|
112
|
+
props: {
|
|
113
|
+
padding: linkedDimensionsPropTypeUtil.create( {
|
|
114
|
+
top: sizePropTypeUtil.create( {
|
|
115
|
+
size: 10,
|
|
116
|
+
unit: 'px',
|
|
117
|
+
} ),
|
|
118
|
+
right: sizePropTypeUtil.create( {
|
|
119
|
+
size: 20,
|
|
120
|
+
unit: 'px',
|
|
121
|
+
} ),
|
|
122
|
+
bottom: sizePropTypeUtil.create( {
|
|
123
|
+
size: 30,
|
|
124
|
+
unit: 'px',
|
|
125
|
+
} ),
|
|
126
|
+
left: sizePropTypeUtil.create( {
|
|
127
|
+
size: 40,
|
|
128
|
+
unit: 'px',
|
|
129
|
+
} ),
|
|
130
|
+
} ),
|
|
131
|
+
},
|
|
132
|
+
} );
|
|
34
133
|
|
|
35
134
|
// Act.
|
|
36
|
-
const cssString =
|
|
37
|
-
styles: [
|
|
38
|
-
transformers
|
|
135
|
+
const cssString = render( {
|
|
136
|
+
styles: [ styleDef ],
|
|
137
|
+
transformers,
|
|
39
138
|
breakpoints: mockBreakpoints,
|
|
40
139
|
} );
|
|
41
140
|
|
|
42
141
|
// Assert.
|
|
43
|
-
expect( cssString ).
|
|
44
|
-
`<style data-style-id="
|
|
45
|
-
''
|
|
46
|
-
) }</style>`
|
|
142
|
+
expect( cssString ).toBe(
|
|
143
|
+
`<style data-style-id="test">.test{padding-top:10px;padding-right:20px;padding-bottom:30px;padding-left:40px;}</style>`
|
|
47
144
|
);
|
|
48
145
|
} );
|
|
49
146
|
|
|
50
|
-
it( 'should
|
|
147
|
+
it( 'should transform background-image (including also background-overlay & color)', () => {
|
|
51
148
|
// Arrange.
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
149
|
+
const styleDef = createMockStyleDefinition( {
|
|
150
|
+
id: 'test',
|
|
151
|
+
props: {
|
|
152
|
+
'background-image': backgroundImagePropTypeUtil.create( [
|
|
153
|
+
backgroundOverlayPropTypeUtil.create( {
|
|
154
|
+
color: colorPropTypeUtil.create( '#000' ),
|
|
155
|
+
} ),
|
|
156
|
+
|
|
157
|
+
backgroundOverlayPropTypeUtil.create( {
|
|
158
|
+
color: colorPropTypeUtil.create( '#FFF' ),
|
|
159
|
+
} ),
|
|
160
|
+
] ),
|
|
161
|
+
},
|
|
162
|
+
} );
|
|
163
|
+
|
|
164
|
+
// Act.
|
|
165
|
+
const cssString = render( {
|
|
166
|
+
styles: [ styleDef ],
|
|
167
|
+
transformers,
|
|
168
|
+
breakpoints: mockBreakpoints,
|
|
169
|
+
} );
|
|
170
|
+
|
|
171
|
+
// Assert.
|
|
172
|
+
expect( cssString ).toBe(
|
|
173
|
+
`<style data-style-id="test">.test{background-image:linear-gradient(#000,#000),linear-gradient(#FFF,#FFF);}</style>`
|
|
174
|
+
);
|
|
175
|
+
} );
|
|
56
176
|
|
|
177
|
+
it( 'should transform border-width (including also size, number & string)', () => {
|
|
178
|
+
// Arrange.
|
|
179
|
+
const styleDef = createMockStyleDefinition( {
|
|
180
|
+
id: 'test',
|
|
181
|
+
props: {
|
|
182
|
+
'border-width': borderWidthPropTypeUtil.create( {
|
|
183
|
+
top: sizePropTypeUtil.create( {
|
|
184
|
+
size: 10,
|
|
185
|
+
unit: 'px',
|
|
186
|
+
} ),
|
|
187
|
+
right: sizePropTypeUtil.create( {
|
|
188
|
+
size: 20,
|
|
189
|
+
unit: 'px',
|
|
190
|
+
} ),
|
|
191
|
+
bottom: sizePropTypeUtil.create( {
|
|
192
|
+
size: 30,
|
|
193
|
+
unit: 'px',
|
|
194
|
+
} ),
|
|
195
|
+
left: sizePropTypeUtil.create( {
|
|
196
|
+
size: 40,
|
|
197
|
+
unit: 'px',
|
|
198
|
+
} ),
|
|
199
|
+
} ),
|
|
200
|
+
},
|
|
201
|
+
} );
|
|
57
202
|
// Act.
|
|
58
|
-
const cssString =
|
|
59
|
-
styles: [
|
|
60
|
-
transformers
|
|
203
|
+
const cssString = render( {
|
|
204
|
+
styles: [ styleDef ],
|
|
205
|
+
transformers,
|
|
61
206
|
breakpoints: mockBreakpoints,
|
|
62
207
|
} );
|
|
63
208
|
|
|
64
209
|
// Assert.
|
|
65
|
-
expect( cssString ).
|
|
66
|
-
`<style data-style-id="
|
|
67
|
-
defaultStyleRule,
|
|
68
|
-
hoverStyleRule,
|
|
69
|
-
focusStyleRule,
|
|
70
|
-
].join( '' ) }</style>`
|
|
210
|
+
expect( cssString ).toBe(
|
|
211
|
+
`<style data-style-id="test">.test{border-top-width:10px;border-right-width:20px;border-bottom-width:30px;border-left-width:40px;}</style>`
|
|
71
212
|
);
|
|
72
213
|
} );
|
|
73
214
|
|
|
74
|
-
it( 'should
|
|
215
|
+
it( 'should transform border-radius (including also union, size, number & string)', () => {
|
|
75
216
|
// Arrange.
|
|
76
|
-
const
|
|
217
|
+
const styleDef = createMockStyleDefinition( {
|
|
218
|
+
id: 'test',
|
|
219
|
+
props: {
|
|
220
|
+
'border-radius': borderRadiusPropTypeUtil.create( {
|
|
221
|
+
'top-left': sizePropTypeUtil.create( {
|
|
222
|
+
size: 10,
|
|
223
|
+
unit: 'px',
|
|
224
|
+
} ),
|
|
225
|
+
'top-right': sizePropTypeUtil.create( {
|
|
226
|
+
size: 20,
|
|
227
|
+
unit: 'px',
|
|
228
|
+
} ),
|
|
229
|
+
'bottom-right': sizePropTypeUtil.create( {
|
|
230
|
+
size: 30,
|
|
231
|
+
unit: 'px',
|
|
232
|
+
} ),
|
|
233
|
+
'bottom-left': sizePropTypeUtil.create( {
|
|
234
|
+
size: 40,
|
|
235
|
+
unit: 'px',
|
|
236
|
+
} ),
|
|
237
|
+
} ),
|
|
238
|
+
},
|
|
239
|
+
} );
|
|
77
240
|
|
|
78
241
|
// Act.
|
|
79
|
-
const cssString =
|
|
80
|
-
styles: [
|
|
81
|
-
transformers
|
|
242
|
+
const cssString = render( {
|
|
243
|
+
styles: [ styleDef ],
|
|
244
|
+
transformers,
|
|
82
245
|
breakpoints: mockBreakpoints,
|
|
83
246
|
} );
|
|
84
247
|
|
|
85
248
|
// Assert.
|
|
86
|
-
expect(
|
|
87
|
-
|
|
88
|
-
`<style data-style-id="${ transformableStyleMock.id }">${ defaultStyleRule }</style>`
|
|
249
|
+
expect( cssString ).toBe(
|
|
250
|
+
`<style data-style-id="test">.test{border-top-left-radius:10px;border-top-right-radius:20px;border-bottom-right-radius:30px;border-bottom-left-radius:40px;}</style>`
|
|
89
251
|
);
|
|
90
252
|
} );
|
|
91
253
|
|
|
92
|
-
it( 'should
|
|
254
|
+
it( 'should transform gap (including also size, number & string)', () => {
|
|
255
|
+
// Arrange.
|
|
256
|
+
const styleDef = createMockStyleDefinition( {
|
|
257
|
+
id: 'test',
|
|
258
|
+
props: {
|
|
259
|
+
gap: gapPropTypeUtil.create( {
|
|
260
|
+
isLinked: true,
|
|
261
|
+
row: sizePropTypeUtil.create( {
|
|
262
|
+
size: 10,
|
|
263
|
+
unit: 'px',
|
|
264
|
+
} ),
|
|
265
|
+
column: sizePropTypeUtil.create( {
|
|
266
|
+
size: 20,
|
|
267
|
+
unit: 'px',
|
|
268
|
+
} ),
|
|
269
|
+
} ),
|
|
270
|
+
},
|
|
271
|
+
} );
|
|
272
|
+
|
|
273
|
+
// Act.
|
|
274
|
+
const cssString = render( {
|
|
275
|
+
styles: [ styleDef ],
|
|
276
|
+
transformers,
|
|
277
|
+
breakpoints: mockBreakpoints,
|
|
278
|
+
} );
|
|
279
|
+
|
|
280
|
+
// Assert.
|
|
281
|
+
expect( cssString ).toBe( `<style data-style-id="test">.test{column-gap:20px;row-gap:10px;}</style>` );
|
|
282
|
+
} );
|
|
283
|
+
/**
|
|
284
|
+
* Features
|
|
285
|
+
*/
|
|
286
|
+
|
|
287
|
+
it( 'should render media queries', () => {
|
|
93
288
|
// Arrange.
|
|
94
|
-
const
|
|
289
|
+
const styleDef: StyleDefinition = {
|
|
290
|
+
id: 'test',
|
|
291
|
+
type: 'class',
|
|
292
|
+
label: 'Test',
|
|
293
|
+
variants: [
|
|
294
|
+
{
|
|
295
|
+
meta: {
|
|
296
|
+
breakpoint: null,
|
|
297
|
+
state: null,
|
|
298
|
+
},
|
|
299
|
+
props: {
|
|
300
|
+
'font-size': sizePropTypeUtil.create( {
|
|
301
|
+
size: 24,
|
|
302
|
+
unit: 'px',
|
|
303
|
+
} ),
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
|
|
307
|
+
{
|
|
308
|
+
meta: {
|
|
309
|
+
breakpoint: 'tablet',
|
|
310
|
+
state: null,
|
|
311
|
+
},
|
|
312
|
+
props: {
|
|
313
|
+
'font-size': sizePropTypeUtil.create( {
|
|
314
|
+
size: 18,
|
|
315
|
+
unit: 'px',
|
|
316
|
+
} ),
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
|
|
320
|
+
{
|
|
321
|
+
meta: {
|
|
322
|
+
breakpoint: 'mobile',
|
|
323
|
+
state: null,
|
|
324
|
+
},
|
|
325
|
+
props: {
|
|
326
|
+
'font-size': sizePropTypeUtil.create( {
|
|
327
|
+
size: 12,
|
|
328
|
+
unit: 'px',
|
|
329
|
+
} ),
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
],
|
|
333
|
+
};
|
|
95
334
|
|
|
96
335
|
// Act.
|
|
97
|
-
const cssString =
|
|
98
|
-
styles: [
|
|
99
|
-
transformers
|
|
336
|
+
const cssString = render( {
|
|
337
|
+
styles: [ styleDef ],
|
|
338
|
+
transformers,
|
|
100
339
|
breakpoints: mockBreakpoints,
|
|
101
340
|
} );
|
|
102
341
|
|
|
103
342
|
// Assert.
|
|
104
|
-
|
|
105
|
-
|
|
343
|
+
const defaultStyle = '.test{font-size:24px;}';
|
|
344
|
+
const tabletStyle = '@media(max-width:992px){.test{font-size:18px;}}';
|
|
345
|
+
const mobileStyle = '@media(max-width:768px){.test{font-size:12px;}}';
|
|
346
|
+
|
|
347
|
+
expect( cssString ).toBe(
|
|
348
|
+
`<style data-style-id="test">${ defaultStyle }${ tabletStyle }${ mobileStyle }</style>`
|
|
106
349
|
);
|
|
107
350
|
} );
|
|
108
351
|
|
|
109
|
-
it( 'should
|
|
352
|
+
it( 'should render pseudo classes', () => {
|
|
110
353
|
// Arrange.
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
354
|
+
const styleDef: StyleDefinition = {
|
|
355
|
+
id: 'test',
|
|
356
|
+
type: 'class',
|
|
357
|
+
label: 'Test',
|
|
358
|
+
variants: [
|
|
359
|
+
{
|
|
360
|
+
meta: {
|
|
361
|
+
breakpoint: null,
|
|
362
|
+
state: null,
|
|
363
|
+
},
|
|
364
|
+
props: {
|
|
365
|
+
'font-size': sizePropTypeUtil.create( {
|
|
366
|
+
size: 24,
|
|
367
|
+
unit: 'px',
|
|
368
|
+
} ),
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
|
|
372
|
+
{
|
|
373
|
+
meta: {
|
|
374
|
+
breakpoint: null,
|
|
375
|
+
state: 'hover',
|
|
376
|
+
},
|
|
377
|
+
props: {
|
|
378
|
+
'font-size': sizePropTypeUtil.create( {
|
|
379
|
+
size: 18,
|
|
380
|
+
unit: 'px',
|
|
381
|
+
} ),
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
|
|
385
|
+
{
|
|
386
|
+
meta: {
|
|
387
|
+
breakpoint: 'mobile',
|
|
388
|
+
state: 'focus',
|
|
389
|
+
},
|
|
390
|
+
props: {
|
|
391
|
+
'font-size': sizePropTypeUtil.create( {
|
|
392
|
+
size: 12,
|
|
393
|
+
unit: 'px',
|
|
394
|
+
} ),
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
],
|
|
398
|
+
};
|
|
115
399
|
|
|
116
400
|
// Act.
|
|
117
|
-
const cssString =
|
|
118
|
-
styles: [
|
|
119
|
-
transformers
|
|
401
|
+
const cssString = render( {
|
|
402
|
+
styles: [ styleDef ],
|
|
403
|
+
transformers,
|
|
120
404
|
breakpoints: mockBreakpoints,
|
|
121
405
|
} );
|
|
122
406
|
|
|
123
407
|
// Assert.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
408
|
+
const defaultStyle = '.test{font-size:24px;}';
|
|
409
|
+
const hoverStyle = '.test:hover{font-size:18px;}';
|
|
410
|
+
const focusStyle = '@media(max-width:768px){.test:focus{font-size:12px;}}';
|
|
411
|
+
|
|
412
|
+
expect( cssString ).toBe(
|
|
413
|
+
`<style data-style-id="test">${ defaultStyle }${ hoverStyle }${ focusStyle }</style>`
|
|
130
414
|
);
|
|
131
415
|
} );
|
|
416
|
+
|
|
417
|
+
it( 'should skip disabled props', () => {
|
|
418
|
+
// Arrange.
|
|
419
|
+
const styleDef = createMockStyleDefinition( {
|
|
420
|
+
id: 'test',
|
|
421
|
+
props: {
|
|
422
|
+
'font-size': sizePropTypeUtil.create( {
|
|
423
|
+
size: 24,
|
|
424
|
+
unit: 'px',
|
|
425
|
+
} ),
|
|
426
|
+
padding: sizePropTypeUtil.create(
|
|
427
|
+
{
|
|
428
|
+
size: 24,
|
|
429
|
+
unit: 'px',
|
|
430
|
+
},
|
|
431
|
+
{ disabled: true }
|
|
432
|
+
),
|
|
433
|
+
},
|
|
434
|
+
} );
|
|
435
|
+
|
|
436
|
+
// Act.
|
|
437
|
+
const cssString = render( {
|
|
438
|
+
styles: [ styleDef ],
|
|
439
|
+
transformers,
|
|
440
|
+
breakpoints: mockBreakpoints,
|
|
441
|
+
} );
|
|
442
|
+
|
|
443
|
+
// Assert.
|
|
444
|
+
expect( cssString ).toBe( `<style data-style-id="test">.test{font-size:24px;}</style>` );
|
|
445
|
+
} );
|
|
446
|
+
|
|
447
|
+
it( 'should fallback to default value when there is no value', () => {
|
|
448
|
+
// Arrange.
|
|
449
|
+
const styleDef = createMockStyleDefinition( {
|
|
450
|
+
id: 'test',
|
|
451
|
+
props: {},
|
|
452
|
+
} );
|
|
453
|
+
|
|
454
|
+
jest.mocked( getStylesSchema ).mockReturnValue( {
|
|
455
|
+
overflow: {
|
|
456
|
+
kind: 'plain',
|
|
457
|
+
key: 'string',
|
|
458
|
+
default: {
|
|
459
|
+
$$type: 'string',
|
|
460
|
+
value: 'hidden',
|
|
461
|
+
},
|
|
462
|
+
settings: {},
|
|
463
|
+
meta: {},
|
|
464
|
+
},
|
|
465
|
+
} );
|
|
466
|
+
|
|
467
|
+
// Act.
|
|
468
|
+
const cssString = render( {
|
|
469
|
+
styles: [ styleDef ],
|
|
470
|
+
transformers,
|
|
471
|
+
breakpoints: mockBreakpoints,
|
|
472
|
+
} );
|
|
473
|
+
|
|
474
|
+
// Assert.
|
|
475
|
+
expect( cssString ).toBe( `<style data-style-id="test">.test{overflow:hidden;}</style>` );
|
|
476
|
+
} );
|
|
477
|
+
|
|
478
|
+
it( 'should skip props that are not in the schema', () => {
|
|
479
|
+
// Arrange.
|
|
480
|
+
const styleDef = createMockStyleDefinition( {
|
|
481
|
+
id: 'test',
|
|
482
|
+
props: {
|
|
483
|
+
'font-size': sizePropTypeUtil.create( {
|
|
484
|
+
size: 24,
|
|
485
|
+
unit: 'px',
|
|
486
|
+
} ),
|
|
487
|
+
'not-a-css-prop': sizePropTypeUtil.create( {
|
|
488
|
+
size: 24,
|
|
489
|
+
unit: 'px',
|
|
490
|
+
} ),
|
|
491
|
+
},
|
|
492
|
+
} );
|
|
493
|
+
|
|
494
|
+
// Act.
|
|
495
|
+
const cssString = render( {
|
|
496
|
+
styles: [ styleDef ],
|
|
497
|
+
transformers,
|
|
498
|
+
breakpoints: mockBreakpoints,
|
|
499
|
+
} );
|
|
500
|
+
|
|
501
|
+
// Assert.
|
|
502
|
+
expect( cssString ).toBe( `<style data-style-id="test">.test{font-size:24px;}</style>` );
|
|
503
|
+
} );
|
|
504
|
+
|
|
505
|
+
it( "should skip props that don't have a transformer", () => {
|
|
506
|
+
// Arrange.
|
|
507
|
+
const styleDef = createMockStyleDefinition( {
|
|
508
|
+
id: 'test',
|
|
509
|
+
props: {
|
|
510
|
+
'font-size': sizePropTypeUtil.create( {
|
|
511
|
+
size: 24,
|
|
512
|
+
unit: 'px',
|
|
513
|
+
} ),
|
|
514
|
+
padding: {
|
|
515
|
+
$$type: 'invalid',
|
|
516
|
+
value: 'invalid',
|
|
517
|
+
},
|
|
518
|
+
},
|
|
519
|
+
} );
|
|
520
|
+
|
|
521
|
+
// Act.
|
|
522
|
+
const cssString = render( {
|
|
523
|
+
styles: [ styleDef ],
|
|
524
|
+
transformers,
|
|
525
|
+
breakpoints: mockBreakpoints,
|
|
526
|
+
} );
|
|
527
|
+
|
|
528
|
+
// Assert.
|
|
529
|
+
expect( cssString ).toBe( `<style data-style-id="test">.test{font-size:24px;}</style>` );
|
|
530
|
+
} );
|
|
531
|
+
|
|
532
|
+
it( 'should skip props when their transformer throws an error', () => {
|
|
533
|
+
// Arrange.
|
|
534
|
+
const styleDef = createMockStyleDefinition( {
|
|
535
|
+
id: 'test',
|
|
536
|
+
props: {
|
|
537
|
+
'font-size': '24px',
|
|
538
|
+
padding: sizePropTypeUtil.create( {
|
|
539
|
+
size: 24,
|
|
540
|
+
unit: 'px',
|
|
541
|
+
} ),
|
|
542
|
+
},
|
|
543
|
+
} );
|
|
544
|
+
|
|
545
|
+
// Act.
|
|
546
|
+
const cssString = render( {
|
|
547
|
+
styles: [ styleDef ],
|
|
548
|
+
transformers: {
|
|
549
|
+
size: () => {
|
|
550
|
+
throw new Error( 'Test error' );
|
|
551
|
+
},
|
|
552
|
+
},
|
|
553
|
+
breakpoints: mockBreakpoints,
|
|
554
|
+
} );
|
|
555
|
+
|
|
556
|
+
// Assert.
|
|
557
|
+
expect( cssString ).toBe( `<style data-style-id="test">.test{font-size:24px;}</style>` );
|
|
558
|
+
} );
|
|
559
|
+
|
|
560
|
+
it( 'should consider 0 as valid value', () => {
|
|
561
|
+
// Arrange.
|
|
562
|
+
const styleDef = createMockStyleDefinition( {
|
|
563
|
+
id: 'test',
|
|
564
|
+
props: {
|
|
565
|
+
'font-size': sizePropTypeUtil.create( {
|
|
566
|
+
size: 0,
|
|
567
|
+
unit: 'px',
|
|
568
|
+
} ),
|
|
569
|
+
},
|
|
570
|
+
} );
|
|
571
|
+
|
|
572
|
+
// Act.
|
|
573
|
+
const cssString = render( {
|
|
574
|
+
styles: [ styleDef ],
|
|
575
|
+
transformers,
|
|
576
|
+
breakpoints: mockBreakpoints,
|
|
577
|
+
} );
|
|
578
|
+
|
|
579
|
+
// Assert.
|
|
580
|
+
expect( cssString ).toBe( `<style data-style-id="test">.test{font-size:0px;}</style>` );
|
|
581
|
+
} );
|
|
132
582
|
} );
|
|
583
|
+
|
|
584
|
+
const mockBreakpoints = {
|
|
585
|
+
tablet: {
|
|
586
|
+
id: 'tablet',
|
|
587
|
+
width: 992,
|
|
588
|
+
label: 'Tablet Portrait',
|
|
589
|
+
type: 'max-width',
|
|
590
|
+
},
|
|
591
|
+
mobile: {
|
|
592
|
+
id: 'mobile',
|
|
593
|
+
width: 768,
|
|
594
|
+
label: 'Mobile Portrait',
|
|
595
|
+
type: 'max-width',
|
|
596
|
+
},
|
|
597
|
+
} as BreakpointsMap;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type PropKey, type PropType } from '@elementor/editor-props';
|
|
2
|
+
|
|
3
|
+
type ExtendedWindow = Window & {
|
|
4
|
+
elementor?: {
|
|
5
|
+
config?: {
|
|
6
|
+
atomic?: {
|
|
7
|
+
styles_schema?: Record< PropKey, PropType >;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const getStylesSchema = () => {
|
|
14
|
+
const extendedWindow = window as unknown as ExtendedWindow;
|
|
15
|
+
|
|
16
|
+
return extendedWindow.elementor?.config?.atomic?.styles_schema ?? {};
|
|
17
|
+
};
|