@elementor/editor-elements 4.0.0-manual → 4.1.0-685
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 +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +7 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
- package/src/index.ts +0 -1
- package/src/sync/delete-element.ts +3 -3
- package/src/sync/replace-element.ts +6 -6
- package/src/sync/types.ts +2 -0
- package/src/hooks/use-element-interactions.ts +0 -25
|
@@ -2,7 +2,7 @@ import { ElementIndexNotFoundError, ElementNotFoundError, ElementParentNotFoundE
|
|
|
2
2
|
import { createElement } from './create-element';
|
|
3
3
|
import { deleteElement } from './delete-element';
|
|
4
4
|
import { getContainer } from './get-container';
|
|
5
|
-
import { type V1Element, type
|
|
5
|
+
import { type V1Element, type V1ElementModelProps } from './types';
|
|
6
6
|
|
|
7
7
|
type ElementLocation = {
|
|
8
8
|
container: V1Element;
|
|
@@ -10,16 +10,16 @@ type ElementLocation = {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
type ReplaceElementArgs = {
|
|
13
|
-
|
|
13
|
+
currentElementId: string;
|
|
14
14
|
newElement: Omit< V1ElementModelProps, 'id' >;
|
|
15
15
|
withHistory?: boolean;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
export const replaceElement =
|
|
19
|
-
const currentElementContainer = getContainer(
|
|
18
|
+
export const replaceElement = ( { currentElementId, newElement, withHistory = true }: ReplaceElementArgs ) => {
|
|
19
|
+
const currentElementContainer = getContainer( currentElementId );
|
|
20
20
|
|
|
21
21
|
if ( ! currentElementContainer ) {
|
|
22
|
-
throw new ElementNotFoundError( { context: { elementId:
|
|
22
|
+
throw new ElementNotFoundError( { context: { elementId: currentElementId } } );
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const { container, index } = getNewElementContainer( currentElementContainer, newElement );
|
|
@@ -30,7 +30,7 @@ export const replaceElement = async ( { currentElement, newElement, withHistory
|
|
|
30
30
|
options: { at: index, useHistory: withHistory },
|
|
31
31
|
} );
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
deleteElement( { container: currentElementContainer, options: { useHistory: withHistory } } );
|
|
34
34
|
|
|
35
35
|
return newElementInstance;
|
|
36
36
|
};
|
package/src/sync/types.ts
CHANGED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
2
|
-
import { __privateUseListenTo as useListenTo, windowEvent } from '@elementor/editor-v1-adapters';
|
|
3
|
-
|
|
4
|
-
import { getElementInteractions } from '../sync/get-element-interactions';
|
|
5
|
-
import { type ElementInteractions } from '../sync/types';
|
|
6
|
-
import { type ElementID } from '../types';
|
|
7
|
-
|
|
8
|
-
export const useElementInteractions = ( elementId: ElementID ) => {
|
|
9
|
-
const [ interactions, setInteractions ] = useState< ElementInteractions >( () => {
|
|
10
|
-
const initial = getElementInteractions( elementId );
|
|
11
|
-
|
|
12
|
-
return initial ?? { version: 1, items: [] };
|
|
13
|
-
} );
|
|
14
|
-
|
|
15
|
-
useListenTo(
|
|
16
|
-
windowEvent( 'elementor/element/update_interactions' ),
|
|
17
|
-
() => {
|
|
18
|
-
const newInteractions = getElementInteractions( elementId );
|
|
19
|
-
setInteractions( newInteractions ?? { version: 1, items: [] } );
|
|
20
|
-
},
|
|
21
|
-
[ elementId ]
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
return interactions;
|
|
25
|
-
};
|