@elementor/editor-interactions 4.0.0-667 → 4.0.0-668
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 +150 -51
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +157 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -11
- package/src/commands/get-clipboard-elements.ts +11 -0
- package/src/commands/paste-interactions.ts +136 -0
- package/src/init.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-interactions",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-668",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Elementor Team",
|
|
6
6
|
"homepage": "https://elementor.com/",
|
|
@@ -39,18 +39,18 @@
|
|
|
39
39
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@elementor/editor-controls": "4.0.0-
|
|
43
|
-
"@elementor/editor-elements": "4.0.0-
|
|
44
|
-
"@elementor/editor-mcp": "4.0.0-
|
|
45
|
-
"@elementor/editor-props": "4.0.0-
|
|
46
|
-
"@elementor/editor-responsive": "4.0.0-
|
|
47
|
-
"@elementor/editor-ui": "4.0.0-
|
|
48
|
-
"@elementor/editor-v1-adapters": "4.0.0-
|
|
42
|
+
"@elementor/editor-controls": "4.0.0-668",
|
|
43
|
+
"@elementor/editor-elements": "4.0.0-668",
|
|
44
|
+
"@elementor/editor-mcp": "4.0.0-668",
|
|
45
|
+
"@elementor/editor-props": "4.0.0-668",
|
|
46
|
+
"@elementor/editor-responsive": "4.0.0-668",
|
|
47
|
+
"@elementor/editor-ui": "4.0.0-668",
|
|
48
|
+
"@elementor/editor-v1-adapters": "4.0.0-668",
|
|
49
49
|
"@elementor/icons": "^1.68.0",
|
|
50
|
-
"@elementor/schema": "4.0.0-
|
|
51
|
-
"@elementor/session": "4.0.0-
|
|
50
|
+
"@elementor/schema": "4.0.0-668",
|
|
51
|
+
"@elementor/session": "4.0.0-668",
|
|
52
52
|
"@elementor/ui": "1.36.17",
|
|
53
|
-
"@elementor/utils": "4.0.0-
|
|
53
|
+
"@elementor/utils": "4.0.0-668",
|
|
54
54
|
"@wordpress/i18n": "^5.13.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { V1ElementModelProps } from '@elementor/editor-elements';
|
|
2
|
+
|
|
3
|
+
export function getClipboardElements( storageKey: string = 'clipboard' ): V1ElementModelProps[] | undefined {
|
|
4
|
+
try {
|
|
5
|
+
const storedData = JSON.parse( localStorage.getItem( 'elementor' ) ?? '{}' );
|
|
6
|
+
|
|
7
|
+
return storedData[ storageKey ]?.elements as V1ElementModelProps[] | undefined;
|
|
8
|
+
} catch {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getContainer,
|
|
3
|
+
getElementInteractions,
|
|
4
|
+
getElementLabel,
|
|
5
|
+
getWidgetsCache,
|
|
6
|
+
updateElementInteractions,
|
|
7
|
+
type V1Element,
|
|
8
|
+
type V1ElementModelProps,
|
|
9
|
+
} from '@elementor/editor-elements';
|
|
10
|
+
import {
|
|
11
|
+
__privateListenTo as listenTo,
|
|
12
|
+
type CommandEvent,
|
|
13
|
+
commandStartEvent,
|
|
14
|
+
undoable,
|
|
15
|
+
} from '@elementor/editor-v1-adapters';
|
|
16
|
+
import { __ } from '@wordpress/i18n';
|
|
17
|
+
|
|
18
|
+
import type { ElementInteractions } from '../types';
|
|
19
|
+
import { createString } from '../utils/prop-value-utils';
|
|
20
|
+
import { generateTempInteractionId } from '../utils/temp-id-utils';
|
|
21
|
+
import { getClipboardElements } from './get-clipboard-elements';
|
|
22
|
+
|
|
23
|
+
function isAtomicContainer( container: V1Element ): boolean {
|
|
24
|
+
const type = container?.model.get( 'widgetType' ) || container?.model.get( 'elType' );
|
|
25
|
+
const widgetsCache = getWidgetsCache();
|
|
26
|
+
const elementConfig = widgetsCache?.[ type ];
|
|
27
|
+
|
|
28
|
+
return Boolean( elementConfig?.atomic_props_schema );
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type PasteInteractionsCommandArgs = {
|
|
32
|
+
container?: V1Element;
|
|
33
|
+
containers?: V1Element[];
|
|
34
|
+
storageKey?: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type PasteInteractionsPayload = {
|
|
38
|
+
containers: V1Element[];
|
|
39
|
+
newInteractions: ElementInteractions;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function getTitleForContainers( containers: V1Element[] ): string {
|
|
43
|
+
return containers.length > 1 ? __( 'Elements', 'elementor' ) : getElementLabel( containers[ 0 ].id );
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function normalizeClipboardInteractions( raw: V1ElementModelProps[ 'interactions' ] ): ElementInteractions | null {
|
|
47
|
+
if ( ! raw ) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const parsed: ElementInteractions = typeof raw === 'string' ? ( JSON.parse( raw ) as ElementInteractions ) : raw;
|
|
52
|
+
|
|
53
|
+
if ( ! parsed?.items?.length ) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return { version: parsed.version ?? 1, items: parsed.items };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function regenerateInteractionIds( interactions: ElementInteractions ): ElementInteractions {
|
|
61
|
+
const cloned = structuredClone( interactions ) as ElementInteractions;
|
|
62
|
+
|
|
63
|
+
cloned.items?.forEach( ( item ) => {
|
|
64
|
+
if ( item.$$type === 'interaction-item' && item.value ) {
|
|
65
|
+
item.value.interaction_id = createString( generateTempInteractionId() );
|
|
66
|
+
}
|
|
67
|
+
} );
|
|
68
|
+
|
|
69
|
+
return cloned;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function initPasteInteractionsCommand() {
|
|
73
|
+
const undoablePasteInteractions = undoable(
|
|
74
|
+
{
|
|
75
|
+
do: ( { containers, newInteractions }: PasteInteractionsPayload ) => {
|
|
76
|
+
const pasted = regenerateInteractionIds( newInteractions );
|
|
77
|
+
|
|
78
|
+
return containers.map( ( container ) => {
|
|
79
|
+
const elementId = container.id;
|
|
80
|
+
const previous = getElementInteractions( elementId );
|
|
81
|
+
|
|
82
|
+
updateElementInteractions( {
|
|
83
|
+
elementId,
|
|
84
|
+
interactions: pasted,
|
|
85
|
+
} );
|
|
86
|
+
|
|
87
|
+
return { elementId, previous: previous ?? { version: 1, items: [] } };
|
|
88
|
+
} );
|
|
89
|
+
},
|
|
90
|
+
undo: ( _: PasteInteractionsPayload, revertData ) => {
|
|
91
|
+
revertData.forEach( ( { elementId, previous } ) => {
|
|
92
|
+
updateElementInteractions( {
|
|
93
|
+
elementId,
|
|
94
|
+
interactions: previous.items?.length ? previous : undefined,
|
|
95
|
+
} );
|
|
96
|
+
} );
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
title: ( { containers } ) => getTitleForContainers( containers ),
|
|
101
|
+
subtitle: __( 'Interactions Pasted', 'elementor' ),
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
listenTo( commandStartEvent( 'document/elements/paste-interactions' ), ( e ) => {
|
|
106
|
+
const args = ( e as CommandEvent ).args as PasteInteractionsCommandArgs;
|
|
107
|
+
const containers = args.containers ?? ( args.container ? [ args.container ] : [] );
|
|
108
|
+
const storageKey = args.storageKey ?? 'clipboard';
|
|
109
|
+
|
|
110
|
+
if ( ! containers.length ) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const clipboardElements = getClipboardElements( storageKey );
|
|
115
|
+
const [ clipboardElement ] = clipboardElements ?? [];
|
|
116
|
+
|
|
117
|
+
if ( ! clipboardElement ) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const newInteractions = normalizeClipboardInteractions( clipboardElement.interactions );
|
|
122
|
+
|
|
123
|
+
if ( ! newInteractions ) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const existingContainers = containers.filter( ( c ) => getContainer( c.id ) ) as V1Element[];
|
|
128
|
+
const validContainers = existingContainers.filter( isAtomicContainer );
|
|
129
|
+
|
|
130
|
+
if ( ! validContainers.length ) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
undoablePasteInteractions( { containers: validContainers, newInteractions } );
|
|
135
|
+
} );
|
|
136
|
+
}
|
package/src/init.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { initPasteInteractionsCommand } from './commands/paste-interactions';
|
|
1
2
|
import { Direction } from './components/controls/direction';
|
|
2
3
|
import { Easing } from './components/controls/easing';
|
|
3
4
|
import { Effect } from './components/controls/effect';
|
|
@@ -15,6 +16,7 @@ export function init() {
|
|
|
15
16
|
interactionsRepository.register( documentElementsInteractionsProvider );
|
|
16
17
|
|
|
17
18
|
initCleanInteractionIdsOnDuplicate();
|
|
19
|
+
initPasteInteractionsCommand();
|
|
18
20
|
|
|
19
21
|
registerInteractionsControl( {
|
|
20
22
|
type: 'trigger',
|