@elementor/editor-components 4.2.0-915 → 4.2.0-917
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 +47 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -55
- package/dist/index.mjs.map +1 -1
- package/package.json +24 -24
- package/src/utils/detach-component-instance/detach-component-instance.ts +69 -45
- package/src/utils/detach-component-instance/resolve-overridable-settings.ts +3 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-components",
|
|
3
3
|
"description": "Elementor editor components",
|
|
4
|
-
"version": "4.2.0-
|
|
4
|
+
"version": "4.2.0-917",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -40,32 +40,32 @@
|
|
|
40
40
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@elementor/editor": "4.2.0-
|
|
44
|
-
"@elementor/editor-canvas": "4.2.0-
|
|
45
|
-
"@elementor/editor-controls": "4.2.0-
|
|
46
|
-
"@elementor/editor-documents": "4.2.0-
|
|
47
|
-
"@elementor/editor-editing-panel": "4.2.0-
|
|
48
|
-
"@elementor/editor-elements": "4.2.0-
|
|
49
|
-
"@elementor/editor-elements-panel": "4.2.0-
|
|
50
|
-
"@elementor/editor-global-classes": "4.2.0-
|
|
51
|
-
"@elementor/editor-mcp": "4.2.0-
|
|
52
|
-
"@elementor/editor-templates": "4.2.0-
|
|
53
|
-
"@elementor/editor-panels": "4.2.0-
|
|
54
|
-
"@elementor/editor-props": "4.2.0-
|
|
55
|
-
"@elementor/editor-styles-repository": "4.2.0-
|
|
56
|
-
"@elementor/editor-ui": "4.2.0-
|
|
57
|
-
"@elementor/editor-v1-adapters": "4.2.0-
|
|
58
|
-
"@elementor/http-client": "4.2.0-
|
|
43
|
+
"@elementor/editor": "4.2.0-917",
|
|
44
|
+
"@elementor/editor-canvas": "4.2.0-917",
|
|
45
|
+
"@elementor/editor-controls": "4.2.0-917",
|
|
46
|
+
"@elementor/editor-documents": "4.2.0-917",
|
|
47
|
+
"@elementor/editor-editing-panel": "4.2.0-917",
|
|
48
|
+
"@elementor/editor-elements": "4.2.0-917",
|
|
49
|
+
"@elementor/editor-elements-panel": "4.2.0-917",
|
|
50
|
+
"@elementor/editor-global-classes": "4.2.0-917",
|
|
51
|
+
"@elementor/editor-mcp": "4.2.0-917",
|
|
52
|
+
"@elementor/editor-templates": "4.2.0-917",
|
|
53
|
+
"@elementor/editor-panels": "4.2.0-917",
|
|
54
|
+
"@elementor/editor-props": "4.2.0-917",
|
|
55
|
+
"@elementor/editor-styles-repository": "4.2.0-917",
|
|
56
|
+
"@elementor/editor-ui": "4.2.0-917",
|
|
57
|
+
"@elementor/editor-v1-adapters": "4.2.0-917",
|
|
58
|
+
"@elementor/http-client": "4.2.0-917",
|
|
59
59
|
"@elementor/icons": "~1.75.1",
|
|
60
|
-
"@elementor/events": "4.2.0-
|
|
61
|
-
"@elementor/query": "4.2.0-
|
|
62
|
-
"@elementor/schema": "4.2.0-
|
|
63
|
-
"@elementor/store": "4.2.0-
|
|
60
|
+
"@elementor/events": "4.2.0-917",
|
|
61
|
+
"@elementor/query": "4.2.0-917",
|
|
62
|
+
"@elementor/schema": "4.2.0-917",
|
|
63
|
+
"@elementor/store": "4.2.0-917",
|
|
64
64
|
"@elementor/ui": "1.37.5",
|
|
65
|
-
"@elementor/utils": "4.2.0-
|
|
65
|
+
"@elementor/utils": "4.2.0-917",
|
|
66
66
|
"@wordpress/i18n": "^5.13.0",
|
|
67
|
-
"@elementor/editor-notifications": "4.2.0-
|
|
68
|
-
"@elementor/editor-current-user": "4.2.0-
|
|
67
|
+
"@elementor/editor-notifications": "4.2.0-917",
|
|
68
|
+
"@elementor/editor-current-user": "4.2.0-917"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"react": "^18.3.1",
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { doAfterRender } from '@elementor/editor-canvas';
|
|
2
|
+
import {
|
|
3
|
+
getContainer,
|
|
4
|
+
replaceElement,
|
|
5
|
+
selectElement,
|
|
6
|
+
type V1Element,
|
|
7
|
+
type V1ElementModelProps,
|
|
8
|
+
} from '@elementor/editor-elements';
|
|
2
9
|
import { undoable } from '@elementor/editor-v1-adapters';
|
|
3
|
-
import {
|
|
10
|
+
import { __getState as getState } from '@elementor/store';
|
|
4
11
|
import { __ } from '@wordpress/i18n';
|
|
5
12
|
|
|
6
13
|
import { componentInstanceOverridesPropTypeUtil } from '../../prop-types/component-instance-overrides-prop-type';
|
|
@@ -8,8 +15,7 @@ import {
|
|
|
8
15
|
type ComponentInstanceProp,
|
|
9
16
|
componentInstancePropTypeUtil,
|
|
10
17
|
} from '../../prop-types/component-instance-prop-type';
|
|
11
|
-
import { selectComponent
|
|
12
|
-
import { type OverridableProps } from '../../types';
|
|
18
|
+
import { selectComponent } from '../../store/store';
|
|
13
19
|
import { getComponentDocumentData } from '../component-document-data';
|
|
14
20
|
import { trackComponentEvent } from '../tracking';
|
|
15
21
|
import { resolveDetachedInstance } from './resolve-detached-instance';
|
|
@@ -27,11 +33,26 @@ type DetachParams = {
|
|
|
27
33
|
type DoReturn = {
|
|
28
34
|
detachedElement: V1Element;
|
|
29
35
|
detachedInstanceElementData: V1ElementModelProps;
|
|
30
|
-
editedComponentOnDetach: number | null;
|
|
31
|
-
overridablePropsBeforeDetach: OverridableProps | null;
|
|
32
36
|
originalInstanceModel: V1ElementModelProps;
|
|
37
|
+
actionId: number;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type DetachEventData = {
|
|
41
|
+
detachedInstanceId: string;
|
|
42
|
+
detachActionId: number;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
type UndoDetachEventData = {
|
|
46
|
+
restoredInstanceId: string;
|
|
47
|
+
detachActionId: number;
|
|
33
48
|
};
|
|
34
49
|
|
|
50
|
+
type RedoDetachEventData = DetachEventData;
|
|
51
|
+
|
|
52
|
+
const DETACH_EVENT = 'elementor/components/detach-instance';
|
|
53
|
+
const DETACH_UNDO_EVENT = 'elementor/components/undo-detach-instance';
|
|
54
|
+
const DETACH_REDO_EVENT = 'elementor/components/redo-detach-instance';
|
|
55
|
+
|
|
35
56
|
export async function detachComponentInstance( {
|
|
36
57
|
instanceId,
|
|
37
58
|
componentId,
|
|
@@ -64,20 +85,29 @@ export async function detachComponentInstance( {
|
|
|
64
85
|
overrides
|
|
65
86
|
) as V1ElementModelProps;
|
|
66
87
|
|
|
67
|
-
const editedComponentOnDetach = selectCurrentComponentId( getState() );
|
|
68
|
-
// We need to store the overridable props of the current component before detach to restore them on undo.
|
|
69
|
-
const overridablePropsBeforeDetach = editedComponentOnDetach
|
|
70
|
-
? selectOverridableProps( getState(), editedComponentOnDetach ) ?? null
|
|
71
|
-
: null;
|
|
72
|
-
|
|
73
88
|
const originalInstanceModel = instanceContainer.model.toJSON();
|
|
74
89
|
|
|
90
|
+
const actionId = new Date().getTime();
|
|
91
|
+
|
|
92
|
+
// We should fire the event *before* replacing the element, so it will happen before delete event is fired.
|
|
93
|
+
// As we do overridable props cleanup for both events.
|
|
94
|
+
window.dispatchEvent(
|
|
95
|
+
new CustomEvent( DETACH_EVENT, {
|
|
96
|
+
detail: {
|
|
97
|
+
detachedInstanceId: instanceId,
|
|
98
|
+
detachActionId: actionId,
|
|
99
|
+
} as DetachEventData,
|
|
100
|
+
} )
|
|
101
|
+
);
|
|
102
|
+
|
|
75
103
|
const detachedElement = replaceElement( {
|
|
76
104
|
currentElementId: instanceId,
|
|
77
105
|
newElement: detachedInstanceElementData,
|
|
78
106
|
withHistory: false,
|
|
79
107
|
} );
|
|
80
108
|
|
|
109
|
+
selectElement( detachedElement.id );
|
|
110
|
+
|
|
81
111
|
const componentUid = selectComponent( getState(), componentId )?.uid;
|
|
82
112
|
trackComponentEvent( {
|
|
83
113
|
action: 'detached',
|
|
@@ -92,50 +122,35 @@ export async function detachComponentInstance( {
|
|
|
92
122
|
return {
|
|
93
123
|
detachedElement,
|
|
94
124
|
detachedInstanceElementData,
|
|
95
|
-
editedComponentOnDetach,
|
|
96
|
-
overridablePropsBeforeDetach,
|
|
97
125
|
originalInstanceModel,
|
|
126
|
+
actionId,
|
|
98
127
|
};
|
|
99
128
|
},
|
|
100
|
-
undo: (
|
|
101
|
-
_: undefined,
|
|
102
|
-
{
|
|
103
|
-
detachedElement,
|
|
104
|
-
originalInstanceModel,
|
|
105
|
-
overridablePropsBeforeDetach,
|
|
106
|
-
editedComponentOnDetach,
|
|
107
|
-
}: DoReturn
|
|
108
|
-
): V1Element => {
|
|
129
|
+
undo: ( _: undefined, { detachedElement, originalInstanceModel, actionId }: DoReturn ): V1Element => {
|
|
109
130
|
const restoredInstance = replaceElement( {
|
|
110
131
|
currentElementId: detachedElement.id,
|
|
111
132
|
newElement: originalInstanceModel,
|
|
112
133
|
withHistory: false,
|
|
113
134
|
} );
|
|
114
135
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
);
|
|
127
|
-
}
|
|
136
|
+
window.dispatchEvent(
|
|
137
|
+
new CustomEvent( DETACH_UNDO_EVENT, {
|
|
138
|
+
detail: {
|
|
139
|
+
restoredInstanceId: restoredInstance.id,
|
|
140
|
+
detachActionId: actionId,
|
|
141
|
+
} as UndoDetachEventData,
|
|
142
|
+
} )
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
// Wait for the instance to be restored
|
|
146
|
+
doAfterRender( [ restoredInstance.id ], () => {
|
|
147
|
+
selectElement( restoredInstance.id );
|
|
148
|
+
} );
|
|
128
149
|
|
|
129
150
|
return restoredInstance;
|
|
130
151
|
},
|
|
131
152
|
redo: ( _: undefined, doReturn: DoReturn, restoredInstance: V1Element ) => {
|
|
132
|
-
const { detachedInstanceElementData } = doReturn;
|
|
133
|
-
|
|
134
|
-
const editedComponentOnDetach = selectCurrentComponentId( getState() );
|
|
135
|
-
// We need to store the overridable props of the current component before detach to restore them on undo.
|
|
136
|
-
const overridablePropsBeforeDetach = editedComponentOnDetach
|
|
137
|
-
? selectOverridableProps( getState(), editedComponentOnDetach ) ?? null
|
|
138
|
-
: null;
|
|
153
|
+
const { detachedInstanceElementData, actionId } = doReturn;
|
|
139
154
|
|
|
140
155
|
const detachedElement = replaceElement( {
|
|
141
156
|
currentElementId: restoredInstance.id,
|
|
@@ -143,11 +158,20 @@ export async function detachComponentInstance( {
|
|
|
143
158
|
withHistory: false,
|
|
144
159
|
} );
|
|
145
160
|
|
|
161
|
+
window.dispatchEvent(
|
|
162
|
+
new CustomEvent( DETACH_REDO_EVENT, {
|
|
163
|
+
detail: {
|
|
164
|
+
detachedInstanceId: detachedElement.id,
|
|
165
|
+
detachActionId: actionId,
|
|
166
|
+
} as RedoDetachEventData,
|
|
167
|
+
} )
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
selectElement( detachedElement.id );
|
|
171
|
+
|
|
146
172
|
return {
|
|
147
173
|
...doReturn,
|
|
148
174
|
detachedElement,
|
|
149
|
-
editedComponentOnDetach,
|
|
150
|
-
overridablePropsBeforeDetach,
|
|
151
175
|
};
|
|
152
176
|
},
|
|
153
177
|
},
|
|
@@ -97,10 +97,11 @@ function resolvePropValue(
|
|
|
97
97
|
return resolveOverridableOverride( matchingOverride, originValue );
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
// for regular props, when there's a matching override, return the matching override value
|
|
100
|
+
// for regular props, when there's a non null matching override, return the matching override value,
|
|
101
|
+
// otherwise return the origin value
|
|
101
102
|
const matchingOverrideValue = componentInstanceOverridePropTypeUtil.extract( matchingOverride )
|
|
102
103
|
?.override_value as PropValue | null;
|
|
103
|
-
return matchingOverrideValue;
|
|
104
|
+
return matchingOverrideValue ?? originValue;
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
function resolveOverridableOverride(
|