@elementor/editor-elements 3.33.0-261 → 3.33.0-263

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.
@@ -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 V1Element, type V1ElementModelProps } from './types';
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: V1Element;
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: V1Element,
31
+ currentElement: V1ElementData,
31
32
  newElement: Omit< V1ElementModelProps, 'id' >
32
33
  ): ElementLocation {
33
34
  let location: ElementLocation;
34
35
 
35
- const parent = getContainer( currentElement.id )?.parent;
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 Error( `Parent not found for element ${ currentElement.id }. Cannot replace element.` );
43
+ throw new ElementParentNotFoundError( { context: { elementId: currentElement.id } } );
38
44
  }
39
45
 
40
- const elementIndex = currentElement.view?._index ?? 0;
46
+ const elementIndex = currentElementContainer.view?._index ?? 0;
41
47
  if ( elementIndex === undefined || elementIndex === -1 ) {
42
- throw new Error( `Element ${ currentElement.id } not found in parent container. Cannot replace element.` );
48
+ throw new ElementIndexNotFoundError( { context: { elementId: currentElement.id } } );
43
49
  }
44
50
 
45
51
  location = { containerId: parent.id, index: elementIndex };