@elementor/editor-elements 4.4.0-1112 → 4.4.0-1114
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 +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +53 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +3 -1
- package/src/sync/clone-element-tree.ts +24 -0
- package/src/sync/get-elements.ts +12 -3
- package/src/sync/get-host-document-container.ts +13 -0
- package/src/sync/get-host-document-id.ts +11 -0
- package/src/sync/resolve-element.ts +1 -1
- package/src/sync/types.ts +11 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-elements",
|
|
3
3
|
"description": "This package contains the elements model for the Elementor editor",
|
|
4
|
-
"version": "4.4.0-
|
|
4
|
+
"version": "4.4.0-1114",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@elementor/editor-mcp": "4.4.0-
|
|
44
|
-
"@elementor/editor-props": "4.4.0-
|
|
45
|
-
"@elementor/editor-styles": "4.4.0-
|
|
46
|
-
"@elementor/editor-v1-adapters": "4.4.0-
|
|
47
|
-
"@elementor/schema": "4.4.0-
|
|
48
|
-
"@elementor/session": "4.4.0-
|
|
49
|
-
"@elementor/utils": "4.4.0-
|
|
43
|
+
"@elementor/editor-mcp": "4.4.0-1114",
|
|
44
|
+
"@elementor/editor-props": "4.4.0-1114",
|
|
45
|
+
"@elementor/editor-styles": "4.4.0-1114",
|
|
46
|
+
"@elementor/editor-v1-adapters": "4.4.0-1114",
|
|
47
|
+
"@elementor/schema": "4.4.0-1114",
|
|
48
|
+
"@elementor/session": "4.4.0-1114",
|
|
49
|
+
"@elementor/utils": "4.4.0-1114",
|
|
50
50
|
"@wordpress/i18n": "^3.1.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -35,6 +35,7 @@ export {
|
|
|
35
35
|
type DuplicatedElementsResult,
|
|
36
36
|
type DuplicateElementsParams,
|
|
37
37
|
} from './sync/duplicate-elements';
|
|
38
|
+
export { cloneElementTree } from './sync/clone-element-tree';
|
|
38
39
|
export { generateElementId } from './sync/generate-element-id';
|
|
39
40
|
export { getContainer, selectElement } from './sync/get-container';
|
|
40
41
|
export { getPreviewElementDOM } from './sync/get-preview-element-dom';
|
|
@@ -54,7 +55,8 @@ export {
|
|
|
54
55
|
getElementChildren as getElementChildrenWithFallback,
|
|
55
56
|
type ModelResult,
|
|
56
57
|
} from './sync/model-utils';
|
|
57
|
-
export { getElements } from './sync/get-elements';
|
|
58
|
+
export { getElements, getHostDocumentElements } from './sync/get-elements';
|
|
59
|
+
export { getHostDocumentId } from './sync/get-host-document-id';
|
|
58
60
|
export { getSelectedElements } from './sync/get-selected-elements';
|
|
59
61
|
export { getWidgetsCache } from './sync/get-widgets-cache';
|
|
60
62
|
export { moveElement, type MoveElementParams } from './sync/move-element';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { generateElementId } from './generate-element-id';
|
|
2
|
+
import { type BackboneModel, type V1ElementModelProps, type V1ElementSettingsProps } from './types';
|
|
3
|
+
|
|
4
|
+
type CloneableElement = Partial< V1ElementModelProps > | BackboneModel;
|
|
5
|
+
|
|
6
|
+
function isBackboneModel( item: CloneableElement ): item is BackboneModel {
|
|
7
|
+
return 'toJSON' in item && 'get' in item;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function cloneElementTree( item: CloneableElement ): V1ElementModelProps {
|
|
11
|
+
const source = isBackboneModel( item ) ? ( item.toJSON() as Partial< V1ElementModelProps > ) : item;
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
...source,
|
|
15
|
+
id: generateElementId(),
|
|
16
|
+
settings: {
|
|
17
|
+
...( source.settings ?? {} ),
|
|
18
|
+
_element_id: '',
|
|
19
|
+
} as V1ElementSettingsProps,
|
|
20
|
+
elements: ( source.elements ?? [] ).map( ( child ) =>
|
|
21
|
+
cloneElementTree( child as Partial< V1ElementModelProps > )
|
|
22
|
+
),
|
|
23
|
+
} as unknown as V1ElementModelProps;
|
|
24
|
+
}
|
package/src/sync/get-elements.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { type ElementID } from '../types';
|
|
2
2
|
import { getContainer } from './get-container';
|
|
3
3
|
import { getCurrentDocumentContainer } from './get-current-document-container';
|
|
4
|
+
import { getHostDocumentContainer } from './get-host-document-container';
|
|
4
5
|
import { type V1Element } from './types';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
const container = root ? getContainer( root ) : getCurrentDocumentContainer();
|
|
8
|
-
|
|
7
|
+
function collectElements( container: V1Element | null ): V1Element[] {
|
|
9
8
|
if ( ! container ) {
|
|
10
9
|
return [];
|
|
11
10
|
}
|
|
@@ -16,3 +15,13 @@ export function getElements( root?: ElementID ): V1Element[] {
|
|
|
16
15
|
|
|
17
16
|
return [ container, ...children ];
|
|
18
17
|
}
|
|
18
|
+
|
|
19
|
+
export function getElements( root?: ElementID ): V1Element[] {
|
|
20
|
+
const container = root ? getContainer( root ) : getCurrentDocumentContainer();
|
|
21
|
+
|
|
22
|
+
return collectElements( container );
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function getHostDocumentElements(): V1Element[] {
|
|
26
|
+
return collectElements( getHostDocumentContainer() );
|
|
27
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getHostDocumentId } from './get-host-document-id';
|
|
2
|
+
import { type ExtendedWindow, type V1Element } from './types';
|
|
3
|
+
|
|
4
|
+
export function getHostDocumentContainer(): V1Element | null {
|
|
5
|
+
const extendedWindow = window as unknown as ExtendedWindow;
|
|
6
|
+
const hostId = getHostDocumentId();
|
|
7
|
+
|
|
8
|
+
if ( ! hostId ) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return extendedWindow.elementor?.documents?.get?.( hostId )?.container ?? null;
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ExtendedWindow } from './types';
|
|
2
|
+
|
|
3
|
+
export function getHostDocumentId() {
|
|
4
|
+
const extendedWindow = window as unknown as ExtendedWindow;
|
|
5
|
+
|
|
6
|
+
try {
|
|
7
|
+
return extendedWindow.elementor?.documents?.getInitialId?.() ?? null;
|
|
8
|
+
} catch {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -40,7 +40,7 @@ export function findModelInDocument( id: string ): BackboneModel | null {
|
|
|
40
40
|
export function addModelToParent(
|
|
41
41
|
parentId: string,
|
|
42
42
|
childData: V1ElementModelProps,
|
|
43
|
-
options?: { at?: number }
|
|
43
|
+
options?: { at?: number; clone?: boolean }
|
|
44
44
|
): boolean {
|
|
45
45
|
return getDocumentUtils()?.addModelToParent?.( parentId, childData, options ) ?? false;
|
|
46
46
|
}
|
package/src/sync/types.ts
CHANGED
|
@@ -10,7 +10,11 @@ export type ExtendedWindow = Window & {
|
|
|
10
10
|
get?: ( name: string ) => {
|
|
11
11
|
utils?: {
|
|
12
12
|
findModelById?: ( id: string, collection?: unknown ) => BackboneModel | null;
|
|
13
|
-
addModelToParent?: (
|
|
13
|
+
addModelToParent?: (
|
|
14
|
+
parentId: string,
|
|
15
|
+
childData: unknown,
|
|
16
|
+
options?: { at?: number; clone?: boolean }
|
|
17
|
+
) => boolean;
|
|
14
18
|
removeModelFromParent?: ( parentId: string, childId: string ) => boolean;
|
|
15
19
|
};
|
|
16
20
|
};
|
|
@@ -28,6 +32,12 @@ export type ExtendedWindow = Window & {
|
|
|
28
32
|
}
|
|
29
33
|
| undefined;
|
|
30
34
|
getCurrentId?: () => number;
|
|
35
|
+
getInitialId?: () => number;
|
|
36
|
+
get?: ( id: number ) =>
|
|
37
|
+
| {
|
|
38
|
+
container: V1Element;
|
|
39
|
+
}
|
|
40
|
+
| undefined;
|
|
31
41
|
};
|
|
32
42
|
getContainer?: ( id: string ) => V1Element | undefined;
|
|
33
43
|
getPreviewContainer?: () => V1Element | undefined;
|