@elementor/editor-canvas 0.11.1 → 0.13.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.
Files changed (44) hide show
  1. package/.turbo/turbo-build.log +10 -10
  2. package/CHANGELOG.md +46 -0
  3. package/dist/index.d.mts +6 -1
  4. package/dist/index.d.ts +6 -1
  5. package/dist/index.js +406 -45
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +419 -46
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +11 -10
  10. package/src/__tests__/__mocks__/styles-schema.ts +72 -3
  11. package/src/__tests__/init-styles-renderer.test.ts +19 -5
  12. package/src/__tests__/mock-attachment-data.ts +15 -0
  13. package/src/__tests__/prop-types.ts +65 -0
  14. package/src/__tests__/settings-props-resolver.test.ts +193 -0
  15. package/src/__tests__/styles-prop-resolver.test.ts +59 -16
  16. package/src/index.ts +1 -0
  17. package/src/init-settings-transformers.ts +19 -0
  18. package/src/init-style-transformers.ts +13 -9
  19. package/src/init-styles-renderer.ts +9 -3
  20. package/src/init.tsx +8 -0
  21. package/src/legacy/create-element-type.ts +84 -0
  22. package/src/legacy/init-legacy-views.ts +22 -0
  23. package/src/legacy/types.ts +60 -0
  24. package/src/settings-transformers-registry.ts +3 -0
  25. package/src/style-commands/__tests__/paste-style.test.ts +554 -0
  26. package/src/style-commands/__tests__/reset-style.test.ts +153 -0
  27. package/src/style-commands/init-style-commands.ts +7 -0
  28. package/src/style-commands/paste-style.ts +53 -0
  29. package/src/style-commands/reset-style.ts +34 -0
  30. package/src/style-commands/undoable-actions/paste-element-style.ts +107 -0
  31. package/src/style-commands/undoable-actions/reset-element-style.ts +60 -0
  32. package/src/style-commands/utils.ts +62 -0
  33. package/src/transformers/settings/array-transformer.ts +5 -0
  34. package/src/transformers/settings/link-transformer.ts +14 -0
  35. package/src/transformers/{styles → shared}/image-src-transformer.ts +2 -2
  36. package/src/transformers/shared/image-transformer.ts +41 -0
  37. package/src/transformers/shared/plain-transformer.ts +5 -0
  38. package/src/transformers/styles/background-color-overlay-transformer.ts +13 -3
  39. package/src/transformers/styles/background-gradient-overlay-transformer.ts +16 -0
  40. package/src/transformers/styles/background-image-overlay-transformer.ts +6 -2
  41. package/src/transformers/styles/color-stop-transformer.ts +10 -0
  42. package/src/transformers/styles/image-attachment-transformer.ts +0 -15
  43. package/src/transformers/styles/image-transformer.ts +0 -34
  44. package/src/transformers/styles/primitive-transformer.ts +0 -3
@@ -0,0 +1,554 @@
1
+ import {
2
+ createMockElement,
3
+ createMockStyleDefinitionWithVariants,
4
+ dispatchCommandBefore,
5
+ mockHistoryManager,
6
+ } from 'test-utils';
7
+ import {
8
+ createElementStyle,
9
+ deleteElementStyle,
10
+ getElementStyles,
11
+ updateElementStyle,
12
+ } from '@elementor/editor-elements';
13
+ import { type StyleDefinition } from '@elementor/editor-styles';
14
+ import { LOCAL_STYLES_RESERVED_LABEL } from '@elementor/editor-styles-repository';
15
+
16
+ import { initPasteStyleCommand } from '../paste-style';
17
+ import { getClassesProp, getClipboardElements, isAtomicWidget } from '../utils';
18
+
19
+ jest.mock( '@elementor/editor-elements' );
20
+ jest.mock( '../utils', () => ( {
21
+ ...jest.requireActual( '../utils' ),
22
+ getClipboardElements: jest.fn(),
23
+ getClassesProp: jest.fn(),
24
+ isAtomicWidget: jest.fn(),
25
+ } ) );
26
+ jest.mock( '@elementor/editor-v1-adapters', () => ( {
27
+ ...jest.requireActual( '@elementor/editor-v1-adapters' ),
28
+ blockCommand: jest.fn(),
29
+ } ) );
30
+
31
+ describe( 'pasteStyles', () => {
32
+ const historyMock = mockHistoryManager();
33
+
34
+ beforeEach( () => {
35
+ initPasteStyleCommand();
36
+
37
+ jest.mocked( getClassesProp ).mockReturnValue( 'classes' );
38
+ jest.mocked( createElementStyle ).mockReturnValue( 's-new' );
39
+ jest.mocked( isAtomicWidget ).mockImplementation(
40
+ ( container ) => container?.model.get( 'widgetType' ) === 'atomic-widget'
41
+ );
42
+
43
+ historyMock.beforeEach();
44
+ } );
45
+
46
+ afterEach( () => {
47
+ historyMock.afterEach();
48
+ jest.resetAllMocks();
49
+ } );
50
+
51
+ it( 'should override existing props, add any unset props to the final style, and ignore any original props that have no conflicts', () => {
52
+ // Arrange.
53
+ const container = createMockElement( {
54
+ model: {
55
+ id: 'test-container',
56
+ widgetType: 'atomic-widget',
57
+ },
58
+ } );
59
+
60
+ jest.mocked( getElementStyles ).mockReturnValue( {
61
+ 's-1': createMockStyleDefinitionWithVariants( {
62
+ id: 's-1',
63
+ variants: [
64
+ {
65
+ meta: { breakpoint: null, state: null },
66
+ props: { a: 0, b: 1, c: 2 },
67
+ },
68
+ {
69
+ meta: { breakpoint: null, state: 'hover' },
70
+ props: { a: 1, b: 2 },
71
+ },
72
+ ],
73
+ } ),
74
+ } );
75
+
76
+ jest.mocked( getClipboardElements ).mockReturnValue( [
77
+ {
78
+ id: 'test-1',
79
+ elType: 'test-widget',
80
+ styles: {
81
+ 's-2': createMockStyleDefinitionWithVariants( {
82
+ id: 's-2',
83
+ variants: [
84
+ {
85
+ meta: { breakpoint: null, state: null },
86
+ props: { a: 1, c: 2 },
87
+ },
88
+ {
89
+ meta: { breakpoint: 'tablet', state: 'hover' },
90
+ props: { a: 3, b: 4 },
91
+ },
92
+ ],
93
+ } ),
94
+ },
95
+ },
96
+ ] );
97
+
98
+ // Act.
99
+ dispatchCommandBefore( 'document/elements/paste-style', { container } );
100
+
101
+ // Assert.
102
+ expect( updateElementStyle ).toHaveBeenCalledWith( {
103
+ elementId: 'test-container',
104
+ styleId: 's-1',
105
+ meta: {
106
+ breakpoint: null,
107
+ state: null,
108
+ },
109
+ props: {
110
+ a: 1,
111
+ c: 2,
112
+ },
113
+ } );
114
+
115
+ expect( updateElementStyle ).toHaveBeenCalledWith( {
116
+ elementId: 'test-container',
117
+ styleId: 's-1',
118
+ meta: {
119
+ breakpoint: 'tablet',
120
+ state: 'hover',
121
+ },
122
+ props: {
123
+ a: 3,
124
+ b: 4,
125
+ },
126
+ } );
127
+
128
+ // Act.
129
+ historyMock.instance.undo();
130
+
131
+ // Assert.
132
+ expect( createElementStyle ).toHaveBeenCalledWith( {
133
+ elementId: 'test-container',
134
+ styleId: 's-1',
135
+ label: LOCAL_STYLES_RESERVED_LABEL,
136
+ classesProp: 'classes',
137
+ meta: {
138
+ breakpoint: null,
139
+ state: null,
140
+ },
141
+ props: {
142
+ a: 0,
143
+ b: 1,
144
+ c: 2,
145
+ },
146
+ additionalVariants: [
147
+ {
148
+ meta: { breakpoint: null, state: 'hover' },
149
+ props: { a: 1, b: 2 },
150
+ },
151
+ ],
152
+ } );
153
+
154
+ expect( deleteElementStyle ).not.toHaveBeenCalled();
155
+ expect( createElementStyle ).toHaveBeenCalledTimes( 1 );
156
+ expect( updateElementStyle ).toHaveBeenCalledTimes( 2 );
157
+ } );
158
+
159
+ it( 'should create a new style if the container does not have its own local style', () => {
160
+ // Arrange.
161
+ const container = createMockElement( {
162
+ model: {
163
+ id: 'test-container',
164
+ widgetType: 'atomic-widget',
165
+ },
166
+ } );
167
+
168
+ jest.mocked( getElementStyles ).mockReturnValue( {} );
169
+
170
+ jest.mocked( getClipboardElements ).mockReturnValue( [
171
+ {
172
+ id: 'test-1',
173
+ elType: 'test-widget',
174
+ styles: {
175
+ 's-2': createMockStyleDefinitionWithVariants( {
176
+ id: 's-1',
177
+ variants: [
178
+ {
179
+ meta: { breakpoint: null, state: null },
180
+ props: { a: 0, b: 1 },
181
+ },
182
+ {
183
+ meta: { breakpoint: null, state: 'hover' },
184
+ props: { a: 1, b: 2 },
185
+ },
186
+ ],
187
+ } ),
188
+ },
189
+ },
190
+ ] );
191
+
192
+ // Act.
193
+ dispatchCommandBefore( 'document/elements/paste-style', { container } );
194
+
195
+ // Assert.
196
+ expect( createElementStyle ).toHaveBeenCalledWith( {
197
+ elementId: 'test-container',
198
+ label: LOCAL_STYLES_RESERVED_LABEL,
199
+ classesProp: 'classes',
200
+ meta: {
201
+ breakpoint: null,
202
+ state: null,
203
+ },
204
+ props: {
205
+ a: 0,
206
+ b: 1,
207
+ },
208
+ additionalVariants: [
209
+ {
210
+ meta: {
211
+ breakpoint: null,
212
+ state: 'hover',
213
+ },
214
+ props: {
215
+ a: 1,
216
+ b: 2,
217
+ },
218
+ },
219
+ ],
220
+ } );
221
+
222
+ // Act.
223
+ historyMock.instance.undo();
224
+
225
+ // Assert.
226
+ expect( deleteElementStyle ).toHaveBeenCalledWith( 'test-container', 's-new' );
227
+
228
+ expect( createElementStyle ).toHaveBeenCalledTimes( 1 );
229
+ } );
230
+
231
+ it( 'should not allow paste if the element is not atomic', () => {
232
+ // Arrange.
233
+ const container = createMockElement( {
234
+ model: {
235
+ id: 'test-container',
236
+ styles: {},
237
+ widgetType: 'non-atomic-widget',
238
+ },
239
+ } );
240
+ jest.mocked( getElementStyles ).mockReturnValue( {} );
241
+
242
+ jest.mocked( getClipboardElements ).mockReturnValue( [
243
+ {
244
+ id: 'test-1',
245
+ elType: 'test-widget',
246
+ styles: {
247
+ 's-2': createMockStyleDefinitionWithVariants( {
248
+ id: 's-2',
249
+ variants: [
250
+ {
251
+ meta: { breakpoint: null, state: null },
252
+ props: { a: 1, c: 2 },
253
+ },
254
+ {
255
+ meta: { breakpoint: 'tablet', state: 'hover' },
256
+ props: { a: 3, b: 4 },
257
+ },
258
+ ],
259
+ } ),
260
+ },
261
+ },
262
+ ] );
263
+
264
+ // Act.
265
+ dispatchCommandBefore( 'document/elements/paste-style', { container } );
266
+
267
+ // Assert.
268
+ expect( createElementStyle ).not.toHaveBeenCalled();
269
+ expect( updateElementStyle ).not.toHaveBeenCalled();
270
+ expect( deleteElementStyle ).not.toHaveBeenCalled();
271
+ } );
272
+
273
+ it( 'should take only one style def from the clipboard, regardless of how many containers and/or local styles are there', () => {
274
+ // Arrange.
275
+ const container = createMockElement( {
276
+ model: {
277
+ id: 'test-container',
278
+ widgetType: 'atomic-widget',
279
+ },
280
+ } );
281
+
282
+ jest.mocked( getElementStyles ).mockReturnValue( {
283
+ 's-1': createMockStyleDefinitionWithVariants( {
284
+ id: 's-1',
285
+ variants: [
286
+ {
287
+ meta: { breakpoint: null, state: null },
288
+ props: { a: 0, b: 1 },
289
+ },
290
+ {
291
+ meta: { breakpoint: null, state: 'hover' },
292
+ props: { a: 1, b: 2 },
293
+ },
294
+ ],
295
+ } ),
296
+ } );
297
+
298
+ jest.mocked( getClipboardElements ).mockReturnValue( [
299
+ {
300
+ id: 'test-1',
301
+ elType: 'test-widget',
302
+ styles: {
303
+ 's-2': createMockStyleDefinitionWithVariants( {
304
+ id: 's-2',
305
+ variants: [
306
+ {
307
+ meta: { breakpoint: null, state: null },
308
+ props: { a: 1, c: 2 },
309
+ },
310
+ ],
311
+ } ),
312
+ 's-3': createMockStyleDefinitionWithVariants( {
313
+ id: 's-3',
314
+ variants: [
315
+ {
316
+ meta: { breakpoint: null, state: null },
317
+ props: { a: 3, c: 4 },
318
+ },
319
+ ],
320
+ } ),
321
+ },
322
+ },
323
+ {
324
+ id: 'test-2',
325
+ elType: 'test-widget',
326
+ styles: {
327
+ 's-4': createMockStyleDefinitionWithVariants( {
328
+ id: 's-4',
329
+ variants: [
330
+ {
331
+ meta: { breakpoint: null, state: null },
332
+ props: { a: 4, c: 5 },
333
+ },
334
+ ],
335
+ } ),
336
+ },
337
+ },
338
+ ] );
339
+
340
+ // Act.
341
+ dispatchCommandBefore( 'document/elements/paste-style', { container } );
342
+
343
+ // Assert.
344
+ expect( updateElementStyle ).toHaveBeenCalledWith( {
345
+ elementId: 'test-container',
346
+ styleId: 's-1',
347
+ meta: {
348
+ breakpoint: null,
349
+ state: null,
350
+ },
351
+ props: {
352
+ a: 1,
353
+ c: 2,
354
+ },
355
+ } );
356
+
357
+ expect( updateElementStyle ).toHaveBeenCalledTimes( 1 );
358
+ } );
359
+
360
+ it( 'should ignore the command if the clipboard element has no styles', () => {
361
+ // Arrange.
362
+ const container = createMockElement( {
363
+ model: {
364
+ id: 'test-container',
365
+ widgetType: 'atomic-widget',
366
+ },
367
+ } );
368
+
369
+ jest.mocked( getClipboardElements ).mockReturnValue( [
370
+ {
371
+ id: 'test-1',
372
+ elType: 'test-widget',
373
+ styles: {},
374
+ },
375
+ ] );
376
+
377
+ // Act.
378
+ dispatchCommandBefore( 'document/elements/paste-style', { container } );
379
+
380
+ // Assert.
381
+ expect( createElementStyle ).not.toHaveBeenCalled();
382
+ expect( updateElementStyle ).not.toHaveBeenCalled();
383
+ expect( deleteElementStyle ).not.toHaveBeenCalled();
384
+ } );
385
+
386
+ it( 'should support multiple containers responsively - create/update styles, and ignore non atomic widgets', () => {
387
+ // Arrange.
388
+ const container1 = createMockElement( {
389
+ model: {
390
+ id: 'test-container-1',
391
+ widgetType: 'atomic-widget',
392
+ },
393
+ } );
394
+
395
+ const container2 = createMockElement( {
396
+ model: {
397
+ id: 'test-container-2',
398
+ widgetType: 'atomic-widget',
399
+ },
400
+ } );
401
+
402
+ const container3 = createMockElement( {
403
+ model: {
404
+ id: 'test-container-3',
405
+ widgetType: 'non-atomic-widget',
406
+ },
407
+ } );
408
+
409
+ jest.mocked( getElementStyles ).mockImplementation( ( containerId ) => {
410
+ switch ( containerId ) {
411
+ case 'test-container-1':
412
+ return {};
413
+ case 'test-container-2':
414
+ return {
415
+ 's-1': createMockStyleDefinitionWithVariants( {
416
+ id: 's-1',
417
+ variants: [
418
+ {
419
+ meta: { breakpoint: null, state: null },
420
+ props: { a: 0, b: 1 },
421
+ },
422
+ {
423
+ meta: { breakpoint: null, state: 'hover' },
424
+ props: { a: 1, b: 2 },
425
+ },
426
+ ],
427
+ } ),
428
+ } as Record< string, StyleDefinition >;
429
+ default:
430
+ return null;
431
+ }
432
+ } );
433
+
434
+ jest.mocked( getClipboardElements ).mockReturnValue( [
435
+ {
436
+ id: 'test-1',
437
+ elType: 'test-widget',
438
+ styles: {
439
+ 's-2': createMockStyleDefinitionWithVariants( {
440
+ id: 's-2',
441
+ variants: [
442
+ {
443
+ meta: { breakpoint: null, state: null },
444
+ props: { a: 0, b: 1 },
445
+ },
446
+ {
447
+ meta: { breakpoint: null, state: 'hover' },
448
+ props: { a: 1, b: 2 },
449
+ },
450
+ ],
451
+ } ),
452
+ },
453
+ },
454
+ ] );
455
+
456
+ // Act.
457
+ dispatchCommandBefore( 'document/elements/paste-style', {
458
+ containers: [ container1, container2, container3 ],
459
+ } );
460
+
461
+ // Assert.
462
+ expect( createElementStyle ).toHaveBeenCalledWith( {
463
+ elementId: 'test-container-1',
464
+ label: LOCAL_STYLES_RESERVED_LABEL,
465
+ classesProp: 'classes',
466
+ meta: {
467
+ breakpoint: null,
468
+ state: null,
469
+ },
470
+ props: {
471
+ a: 0,
472
+ b: 1,
473
+ },
474
+ additionalVariants: [
475
+ {
476
+ meta: {
477
+ breakpoint: null,
478
+ state: 'hover',
479
+ },
480
+ props: {
481
+ a: 1,
482
+ b: 2,
483
+ },
484
+ },
485
+ ],
486
+ } );
487
+
488
+ expect( updateElementStyle ).toHaveBeenCalledWith( {
489
+ elementId: 'test-container-2',
490
+ styleId: 's-1',
491
+ meta: {
492
+ breakpoint: null,
493
+ state: null,
494
+ },
495
+ props: {
496
+ a: 0,
497
+ b: 1,
498
+ },
499
+ } );
500
+
501
+ expect( updateElementStyle ).toHaveBeenCalledWith( {
502
+ elementId: 'test-container-2',
503
+ styleId: 's-1',
504
+ meta: {
505
+ breakpoint: null,
506
+ state: null,
507
+ },
508
+ props: {
509
+ a: 0,
510
+ b: 1,
511
+ },
512
+ } );
513
+
514
+ expect( createElementStyle ).toHaveBeenCalledTimes( 1 );
515
+ expect( updateElementStyle ).toHaveBeenCalledTimes( 2 );
516
+
517
+ // Act.
518
+ historyMock.instance.undo();
519
+
520
+ // Assert.
521
+ expect( deleteElementStyle ).toHaveBeenCalledWith( 'test-container-1', 's-new' );
522
+
523
+ expect( createElementStyle ).toHaveBeenCalledWith( {
524
+ elementId: 'test-container-2',
525
+ label: LOCAL_STYLES_RESERVED_LABEL,
526
+ classesProp: 'classes',
527
+ styleId: 's-1',
528
+ meta: {
529
+ breakpoint: null,
530
+ state: null,
531
+ },
532
+ props: {
533
+ a: 0,
534
+ b: 1,
535
+ },
536
+ additionalVariants: [
537
+ {
538
+ meta: {
539
+ breakpoint: null,
540
+ state: 'hover',
541
+ },
542
+ props: {
543
+ a: 1,
544
+ b: 2,
545
+ },
546
+ },
547
+ ],
548
+ } );
549
+
550
+ expect( deleteElementStyle ).toHaveBeenCalledTimes( 1 );
551
+ expect( createElementStyle ).toHaveBeenCalledTimes( 2 );
552
+ expect( updateElementStyle ).toHaveBeenCalledTimes( 2 );
553
+ } );
554
+ } );
@@ -0,0 +1,153 @@
1
+ import {
2
+ createMockElement,
3
+ createMockStyleDefinitionWithVariants,
4
+ dispatchCommandBefore,
5
+ mockHistoryManager,
6
+ } from 'test-utils';
7
+ import { createElementStyle, deleteElementStyle, getElementStyles } from '@elementor/editor-elements';
8
+ import { LOCAL_STYLES_RESERVED_LABEL } from '@elementor/editor-styles-repository';
9
+
10
+ import { initResetStyleCommand } from '../reset-style';
11
+ import { getClassesProp, hasAtomicWidgets, isAtomicWidget } from '../utils';
12
+
13
+ jest.mock( '@elementor/editor-elements' );
14
+
15
+ jest.mock( '../utils', () => ( {
16
+ ...jest.requireActual( '../utils' ),
17
+ getClassesProp: jest.fn(),
18
+ hasAtomicWidgets: jest.fn(),
19
+ isAtomicWidget: jest.fn(),
20
+ } ) );
21
+
22
+ jest.mock( '@elementor/editor-v1-adapters', () => ( {
23
+ ...jest.requireActual( '@elementor/editor-v1-adapters' ),
24
+ blockCommand: jest.fn(),
25
+ } ) );
26
+
27
+ describe( 'resetStyles', () => {
28
+ const historyMock = mockHistoryManager();
29
+
30
+ beforeEach( () => {
31
+ initResetStyleCommand();
32
+ historyMock.beforeEach();
33
+ } );
34
+
35
+ afterEach( () => {
36
+ historyMock.afterEach();
37
+ jest.resetAllMocks();
38
+ } );
39
+
40
+ it( 'should clear the existing local style', () => {
41
+ // Arrange.
42
+ const originalStyles = {
43
+ 's-1': createMockStyleDefinitionWithVariants( {
44
+ id: 's-1',
45
+ variants: [
46
+ {
47
+ meta: { breakpoint: null, state: null },
48
+ props: { a: 0, b: 1 },
49
+ },
50
+ {
51
+ meta: { breakpoint: null, state: 'hover' },
52
+ props: { a: 1, b: 2 },
53
+ },
54
+ ],
55
+ } ),
56
+ };
57
+ const container = createMockElement( {
58
+ model: {
59
+ id: 'test-container',
60
+ styles: originalStyles,
61
+ widgetType: 'test-widget',
62
+ },
63
+ } );
64
+
65
+ jest.mocked( getElementStyles ).mockReturnValue( originalStyles );
66
+ jest.mocked( getClassesProp ).mockReturnValue( 'classes' );
67
+ jest.mocked( hasAtomicWidgets ).mockReturnValue( true );
68
+ jest.mocked( isAtomicWidget ).mockReturnValue( true );
69
+
70
+ // Act.
71
+ dispatchCommandBefore( 'document/elements/reset-style', { container } );
72
+
73
+ // Assert.
74
+ expect( deleteElementStyle ).toHaveBeenCalledWith( 'test-container', 's-1' );
75
+ expect( historyMock.instance.get() ).not.toBeNull();
76
+
77
+ // Act.
78
+ historyMock.instance.undo();
79
+
80
+ // Assert.
81
+ expect( createElementStyle ).toHaveBeenCalledWith( {
82
+ elementId: 'test-container',
83
+ label: LOCAL_STYLES_RESERVED_LABEL,
84
+ classesProp: 'classes',
85
+ meta: {
86
+ breakpoint: null,
87
+ state: null,
88
+ },
89
+ props: {
90
+ a: 0,
91
+ b: 1,
92
+ },
93
+ additionalVariants: [
94
+ {
95
+ meta: {
96
+ breakpoint: null,
97
+ state: 'hover',
98
+ },
99
+ props: {
100
+ a: 1,
101
+ b: 2,
102
+ },
103
+ },
104
+ ],
105
+ styleId: 's-1',
106
+ } );
107
+ } );
108
+
109
+ it( 'should not do anything if the widget is not atomic', () => {
110
+ // Arrange.
111
+ const container = createMockElement( {
112
+ model: {
113
+ id: 'test-container',
114
+ widgetType: 'test-widget',
115
+ },
116
+ } );
117
+
118
+ jest.mocked( hasAtomicWidgets ).mockReturnValue( false );
119
+ jest.mocked( isAtomicWidget ).mockReturnValue( false );
120
+
121
+ // Act.
122
+ dispatchCommandBefore( 'document/elements/reset-style', { container } );
123
+
124
+ // Assert.
125
+ expect( deleteElementStyle ).not.toHaveBeenCalled();
126
+ expect( historyMock.instance.get() ).toBeNull();
127
+ } );
128
+
129
+ it( 'should not do anything if the widget is atomic but has no style', () => {
130
+ // Arrange.
131
+ const container = createMockElement( {
132
+ model: {
133
+ id: 'test-container',
134
+ widgetType: 'test-widget',
135
+ },
136
+ } );
137
+
138
+ jest.mocked( hasAtomicWidgets ).mockReturnValue( true );
139
+ jest.mocked( isAtomicWidget ).mockReturnValue( true );
140
+
141
+ // Act.
142
+ dispatchCommandBefore( 'document/elements/reset-style', { container } );
143
+
144
+ // Assert.
145
+ expect( deleteElementStyle ).not.toHaveBeenCalled();
146
+
147
+ // Act.
148
+ historyMock.instance.undo();
149
+
150
+ // Assert.
151
+ expect( createElementStyle ).not.toHaveBeenCalled();
152
+ } );
153
+ } );
@@ -0,0 +1,7 @@
1
+ import { initPasteStyleCommand } from './paste-style';
2
+ import { initResetStyleCommand } from './reset-style';
3
+
4
+ export function initStyleCommands() {
5
+ initPasteStyleCommand();
6
+ initResetStyleCommand();
7
+ }