@elementor/editor-elements 3.33.0-261 → 3.33.0-262
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.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +16 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
- package/src/errors.ts +10 -0
- package/src/sync/replace-element.ts +13 -7
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { ElementIndexNotFoundError, ElementNotFoundError, ElementParentNotFoundError } from '../errors';
|
|
1
2
|
import { createElement } from './create-element';
|
|
2
3
|
import { deleteElement } from './delete-element';
|
|
3
4
|
import { getContainer } from './get-container';
|
|
4
|
-
import { type
|
|
5
|
+
import { type V1ElementData, type V1ElementModelProps } from './types';
|
|
5
6
|
|
|
6
7
|
type ElementLocation = {
|
|
7
8
|
containerId: string;
|
|
@@ -9,7 +10,7 @@ type ElementLocation = {
|
|
|
9
10
|
};
|
|
10
11
|
|
|
11
12
|
type ReplaceElementArgs = {
|
|
12
|
-
currentElement:
|
|
13
|
+
currentElement: V1ElementData;
|
|
13
14
|
newElement: Omit< V1ElementModelProps, 'id' >;
|
|
14
15
|
withHistory?: boolean;
|
|
15
16
|
};
|
|
@@ -27,19 +28,24 @@ export const replaceElement = ( { currentElement, newElement, withHistory = true
|
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
function getNewElementLocation(
|
|
30
|
-
currentElement:
|
|
31
|
+
currentElement: V1ElementData,
|
|
31
32
|
newElement: Omit< V1ElementModelProps, 'id' >
|
|
32
33
|
): ElementLocation {
|
|
33
34
|
let location: ElementLocation;
|
|
34
35
|
|
|
35
|
-
const
|
|
36
|
+
const currentElementContainer = getContainer( currentElement.id );
|
|
37
|
+
if ( ! currentElementContainer ) {
|
|
38
|
+
throw new ElementNotFoundError( { context: { elementId: currentElement.id } } );
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const parent = currentElementContainer.parent;
|
|
36
42
|
if ( ! parent ) {
|
|
37
|
-
throw new
|
|
43
|
+
throw new ElementParentNotFoundError( { context: { elementId: currentElement.id } } );
|
|
38
44
|
}
|
|
39
45
|
|
|
40
|
-
const elementIndex =
|
|
46
|
+
const elementIndex = currentElementContainer.view?._index ?? 0;
|
|
41
47
|
if ( elementIndex === undefined || elementIndex === -1 ) {
|
|
42
|
-
throw new
|
|
48
|
+
throw new ElementIndexNotFoundError( { context: { elementId: currentElement.id } } );
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
location = { containerId: parent.id, index: elementIndex };
|