@elementor/editor-canvas 3.35.0-471 → 3.35.0-473
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/dist/index.js +41 -12
- package/dist/index.mjs +37 -8
- package/package.json +18 -18
- package/src/style-commands/__tests__/paste-style.test.ts +703 -470
- package/src/style-commands/paste-style.ts +47 -10
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { type V1Element } from '@elementor/editor-elements';
|
|
1
|
+
import { getContainer, getElementSetting, updateElementSettings, type V1Element } from '@elementor/editor-elements';
|
|
2
|
+
import { classesPropTypeUtil, type ClassesPropValue } from '@elementor/editor-props';
|
|
3
|
+
import { type StyleDefinition } from '@elementor/editor-styles';
|
|
2
4
|
import {
|
|
3
5
|
__privateListenTo as listenTo,
|
|
4
6
|
blockCommand,
|
|
@@ -7,7 +9,7 @@ import {
|
|
|
7
9
|
} from '@elementor/editor-v1-adapters';
|
|
8
10
|
|
|
9
11
|
import { undoablePasteElementStyle } from './undoable-actions/paste-element-style';
|
|
10
|
-
import { type ContainerArgs, getClipboardElements, hasAtomicWidgets, isAtomicWidget } from './utils';
|
|
12
|
+
import { type ContainerArgs, getClassesProp, getClipboardElements, hasAtomicWidgets, isAtomicWidget } from './utils';
|
|
11
13
|
|
|
12
14
|
type PasteStylesCommandArgs = ContainerArgs & {
|
|
13
15
|
storageKey?: string;
|
|
@@ -26,28 +28,63 @@ export function initPasteStyleCommand() {
|
|
|
26
28
|
);
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
function pasteStyles( args: PasteStylesCommandArgs,
|
|
31
|
+
function pasteStyles( args: PasteStylesCommandArgs, pasteLocalStyle: ReturnType< typeof undoablePasteElementStyle > ) {
|
|
30
32
|
const { containers = [ args.container ], storageKey } = args;
|
|
31
33
|
|
|
34
|
+
const atomicContainers = containers.filter( isAtomicWidget ) as V1Element[];
|
|
35
|
+
|
|
36
|
+
if ( ! atomicContainers.length ) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
32
40
|
const clipboardElements = getClipboardElements( storageKey );
|
|
33
41
|
const [ clipboardElement ] = clipboardElements ?? [];
|
|
34
42
|
|
|
35
|
-
|
|
43
|
+
const clipboardContainer = getContainer( clipboardElement.id );
|
|
44
|
+
if ( ! clipboardElement || ! clipboardContainer || ! isAtomicWidget( clipboardContainer ) ) {
|
|
36
45
|
return;
|
|
37
46
|
}
|
|
38
47
|
|
|
39
48
|
const elementStyles = clipboardElement.styles;
|
|
40
49
|
const elementStyle = Object.values( elementStyles ?? {} )[ 0 ]; // we currently support only one local style
|
|
41
50
|
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
const classesSetting = getClassesWithoutLocalStyle( clipboardContainer, elementStyle );
|
|
52
|
+
if ( classesSetting.length ) {
|
|
53
|
+
pasteClasses( atomicContainers, classesSetting );
|
|
44
54
|
}
|
|
45
55
|
|
|
46
|
-
|
|
56
|
+
if ( elementStyle ) {
|
|
57
|
+
pasteLocalStyle( { containers: atomicContainers, newStyle: elementStyle } );
|
|
58
|
+
}
|
|
59
|
+
}
|
|
47
60
|
|
|
48
|
-
|
|
49
|
-
|
|
61
|
+
function getClassesWithoutLocalStyle( clipboardContainer: V1Element, style: StyleDefinition | null ): string[] {
|
|
62
|
+
const classesProp = getClassesProp( clipboardContainer );
|
|
63
|
+
|
|
64
|
+
if ( ! classesProp ) {
|
|
65
|
+
return [];
|
|
50
66
|
}
|
|
51
67
|
|
|
52
|
-
|
|
68
|
+
const classesSetting = getElementSetting< ClassesPropValue >( clipboardContainer.id, classesProp );
|
|
69
|
+
|
|
70
|
+
return classesSetting?.value.filter( ( styleId ) => styleId !== style?.id ) ?? [];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function pasteClasses( containers: V1Element[], classes: string[] ) {
|
|
74
|
+
containers.forEach( ( container ) => {
|
|
75
|
+
const classesProp = getClassesProp( container );
|
|
76
|
+
if ( ! classesProp ) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const classesSetting = getElementSetting< ClassesPropValue >( container.id, classesProp );
|
|
81
|
+
const currentClasses = classesPropTypeUtil.extract( classesSetting ) ?? [];
|
|
82
|
+
|
|
83
|
+
const newClasses = classesPropTypeUtil.create( Array.from( new Set( [ ...classes, ...currentClasses ] ) ) );
|
|
84
|
+
|
|
85
|
+
updateElementSettings( {
|
|
86
|
+
id: container.id,
|
|
87
|
+
props: { [ classesProp ]: newClasses },
|
|
88
|
+
} );
|
|
89
|
+
} );
|
|
53
90
|
}
|