@elementor/editor-components 4.2.0-916 → 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/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-916",
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-916",
44
- "@elementor/editor-canvas": "4.2.0-916",
45
- "@elementor/editor-controls": "4.2.0-916",
46
- "@elementor/editor-documents": "4.2.0-916",
47
- "@elementor/editor-editing-panel": "4.2.0-916",
48
- "@elementor/editor-elements": "4.2.0-916",
49
- "@elementor/editor-elements-panel": "4.2.0-916",
50
- "@elementor/editor-global-classes": "4.2.0-916",
51
- "@elementor/editor-mcp": "4.2.0-916",
52
- "@elementor/editor-templates": "4.2.0-916",
53
- "@elementor/editor-panels": "4.2.0-916",
54
- "@elementor/editor-props": "4.2.0-916",
55
- "@elementor/editor-styles-repository": "4.2.0-916",
56
- "@elementor/editor-ui": "4.2.0-916",
57
- "@elementor/editor-v1-adapters": "4.2.0-916",
58
- "@elementor/http-client": "4.2.0-916",
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-916",
61
- "@elementor/query": "4.2.0-916",
62
- "@elementor/schema": "4.2.0-916",
63
- "@elementor/store": "4.2.0-916",
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-916",
65
+ "@elementor/utils": "4.2.0-917",
66
66
  "@wordpress/i18n": "^5.13.0",
67
- "@elementor/editor-notifications": "4.2.0-916",
68
- "@elementor/editor-current-user": "4.2.0-916"
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",
@@ -7,7 +7,7 @@ import {
7
7
  type V1ElementModelProps,
8
8
  } from '@elementor/editor-elements';
9
9
  import { undoable } from '@elementor/editor-v1-adapters';
10
- import { __dispatch as dispatch, __getState as getState } from '@elementor/store';
10
+ import { __getState as getState } from '@elementor/store';
11
11
  import { __ } from '@wordpress/i18n';
12
12
 
13
13
  import { componentInstanceOverridesPropTypeUtil } from '../../prop-types/component-instance-overrides-prop-type';
@@ -15,8 +15,7 @@ import {
15
15
  type ComponentInstanceProp,
16
16
  componentInstancePropTypeUtil,
17
17
  } from '../../prop-types/component-instance-prop-type';
18
- import { selectComponent, selectCurrentComponentId, selectOverridableProps, slice } from '../../store/store';
19
- import { type OverridableProps } from '../../types';
18
+ import { selectComponent } from '../../store/store';
20
19
  import { getComponentDocumentData } from '../component-document-data';
21
20
  import { trackComponentEvent } from '../tracking';
22
21
  import { resolveDetachedInstance } from './resolve-detached-instance';
@@ -34,11 +33,26 @@ type DetachParams = {
34
33
  type DoReturn = {
35
34
  detachedElement: V1Element;
36
35
  detachedInstanceElementData: V1ElementModelProps;
37
- editedComponentOnDetach: number | null;
38
- overridablePropsBeforeDetach: OverridableProps | null;
39
36
  originalInstanceModel: V1ElementModelProps;
37
+ actionId: number;
40
38
  };
41
39
 
40
+ type DetachEventData = {
41
+ detachedInstanceId: string;
42
+ detachActionId: number;
43
+ };
44
+
45
+ type UndoDetachEventData = {
46
+ restoredInstanceId: string;
47
+ detachActionId: number;
48
+ };
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
+
42
56
  export async function detachComponentInstance( {
43
57
  instanceId,
44
58
  componentId,
@@ -71,14 +85,21 @@ export async function detachComponentInstance( {
71
85
  overrides
72
86
  ) as V1ElementModelProps;
73
87
 
74
- const editedComponentOnDetach = selectCurrentComponentId( getState() );
75
- // We need to store the overridable props of the current component before detach to restore them on undo.
76
- const overridablePropsBeforeDetach = editedComponentOnDetach
77
- ? selectOverridableProps( getState(), editedComponentOnDetach ) ?? null
78
- : null;
79
-
80
88
  const originalInstanceModel = instanceContainer.model.toJSON();
81
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
+
82
103
  const detachedElement = replaceElement( {
83
104
  currentElementId: instanceId,
84
105
  newElement: detachedInstanceElementData,
@@ -101,39 +122,25 @@ export async function detachComponentInstance( {
101
122
  return {
102
123
  detachedElement,
103
124
  detachedInstanceElementData,
104
- editedComponentOnDetach,
105
- overridablePropsBeforeDetach,
106
125
  originalInstanceModel,
126
+ actionId,
107
127
  };
108
128
  },
109
- undo: (
110
- _: undefined,
111
- {
112
- detachedElement,
113
- originalInstanceModel,
114
- overridablePropsBeforeDetach,
115
- editedComponentOnDetach,
116
- }: DoReturn
117
- ): V1Element => {
129
+ undo: ( _: undefined, { detachedElement, originalInstanceModel, actionId }: DoReturn ): V1Element => {
118
130
  const restoredInstance = replaceElement( {
119
131
  currentElementId: detachedElement.id,
120
132
  newElement: originalInstanceModel,
121
133
  withHistory: false,
122
134
  } );
123
135
 
124
- const currentComponentId = selectCurrentComponentId( getState() );
125
- if (
126
- currentComponentId &&
127
- currentComponentId === editedComponentOnDetach &&
128
- overridablePropsBeforeDetach
129
- ) {
130
- dispatch(
131
- slice.actions.setOverridableProps( {
132
- componentId: currentComponentId,
133
- overridableProps: overridablePropsBeforeDetach,
134
- } )
135
- );
136
- }
136
+ window.dispatchEvent(
137
+ new CustomEvent( DETACH_UNDO_EVENT, {
138
+ detail: {
139
+ restoredInstanceId: restoredInstance.id,
140
+ detachActionId: actionId,
141
+ } as UndoDetachEventData,
142
+ } )
143
+ );
137
144
 
138
145
  // Wait for the instance to be restored
139
146
  doAfterRender( [ restoredInstance.id ], () => {
@@ -143,13 +150,7 @@ export async function detachComponentInstance( {
143
150
  return restoredInstance;
144
151
  },
145
152
  redo: ( _: undefined, doReturn: DoReturn, restoredInstance: V1Element ) => {
146
- const { detachedInstanceElementData } = doReturn;
147
-
148
- const editedComponentOnDetach = selectCurrentComponentId( getState() );
149
- // We need to store the overridable props of the current component before detach to restore them on undo.
150
- const overridablePropsBeforeDetach = editedComponentOnDetach
151
- ? selectOverridableProps( getState(), editedComponentOnDetach ) ?? null
152
- : null;
153
+ const { detachedInstanceElementData, actionId } = doReturn;
153
154
 
154
155
  const detachedElement = replaceElement( {
155
156
  currentElementId: restoredInstance.id,
@@ -157,13 +158,20 @@ export async function detachComponentInstance( {
157
158
  withHistory: false,
158
159
  } );
159
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
+
160
170
  selectElement( detachedElement.id );
161
171
 
162
172
  return {
163
173
  ...doReturn,
164
174
  detachedElement,
165
- editedComponentOnDetach,
166
- overridablePropsBeforeDetach,
167
175
  };
168
176
  },
169
177
  },