@elementor/editor-canvas 4.1.0-695 → 4.1.0-696
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.js
CHANGED
|
@@ -3009,6 +3009,7 @@ function extractElementData(element) {
|
|
|
3009
3009
|
}
|
|
3010
3010
|
|
|
3011
3011
|
// src/mcp/tools/build-composition/tool.ts
|
|
3012
|
+
var import_editor_documents3 = require("@elementor/editor-documents");
|
|
3012
3013
|
var import_editor_elements10 = require("@elementor/editor-elements");
|
|
3013
3014
|
|
|
3014
3015
|
// src/composition-builder/composition-builder.ts
|
|
@@ -3423,6 +3424,16 @@ var CompositionBuilder = class _CompositionBuilder {
|
|
|
3423
3424
|
}
|
|
3424
3425
|
};
|
|
3425
3426
|
|
|
3427
|
+
// src/mcp/utils/get-composition-target-container.ts
|
|
3428
|
+
var import_editor_documents2 = require("@elementor/editor-documents");
|
|
3429
|
+
function getCompositionTargetContainer(documentContainer, documentType) {
|
|
3430
|
+
const firstChild = documentContainer.children?.[0];
|
|
3431
|
+
if (documentType === import_editor_documents2.COMPONENT_DOCUMENT_TYPE && firstChild) {
|
|
3432
|
+
return firstChild;
|
|
3433
|
+
}
|
|
3434
|
+
return documentContainer;
|
|
3435
|
+
}
|
|
3436
|
+
|
|
3426
3437
|
// src/mcp/tools/build-composition/prompt.ts
|
|
3427
3438
|
var import_editor_mcp2 = require("@elementor/editor-mcp");
|
|
3428
3439
|
var generatePrompt = () => {
|
|
@@ -3618,6 +3629,8 @@ var initBuildCompositionsTool = (reg) => {
|
|
|
3618
3629
|
const errors = [];
|
|
3619
3630
|
const rootContainers = [];
|
|
3620
3631
|
const documentContainer = (0, import_editor_elements10.getContainer)("document");
|
|
3632
|
+
const currentDocument = (0, import_editor_documents3.getCurrentDocument)();
|
|
3633
|
+
const targetContainer = getCompositionTargetContainer(documentContainer, currentDocument?.type.value);
|
|
3621
3634
|
try {
|
|
3622
3635
|
const compositionBuilder = CompositionBuilder.fromXMLString(xmlStructure, {
|
|
3623
3636
|
createElement: import_editor_elements10.createElement,
|
|
@@ -3630,7 +3643,7 @@ var initBuildCompositionsTool = (reg) => {
|
|
|
3630
3643
|
configErrors,
|
|
3631
3644
|
invalidStyles,
|
|
3632
3645
|
rootContainers: generatedRootContainers
|
|
3633
|
-
} = compositionBuilder.build(
|
|
3646
|
+
} = compositionBuilder.build(targetContainer);
|
|
3634
3647
|
rootContainers.push(...generatedRootContainers);
|
|
3635
3648
|
generatedXML = new XMLSerializer().serializeToString(compositionBuilder.getXML());
|
|
3636
3649
|
if (configErrors.length) {
|
package/dist/index.mjs
CHANGED
|
@@ -2979,6 +2979,7 @@ function extractElementData(element) {
|
|
|
2979
2979
|
}
|
|
2980
2980
|
|
|
2981
2981
|
// src/mcp/tools/build-composition/tool.ts
|
|
2982
|
+
import { getCurrentDocument } from "@elementor/editor-documents";
|
|
2982
2983
|
import {
|
|
2983
2984
|
createElement as createElement8,
|
|
2984
2985
|
deleteElement,
|
|
@@ -3409,6 +3410,16 @@ var CompositionBuilder = class _CompositionBuilder {
|
|
|
3409
3410
|
}
|
|
3410
3411
|
};
|
|
3411
3412
|
|
|
3413
|
+
// src/mcp/utils/get-composition-target-container.ts
|
|
3414
|
+
import { COMPONENT_DOCUMENT_TYPE } from "@elementor/editor-documents";
|
|
3415
|
+
function getCompositionTargetContainer(documentContainer, documentType) {
|
|
3416
|
+
const firstChild = documentContainer.children?.[0];
|
|
3417
|
+
if (documentType === COMPONENT_DOCUMENT_TYPE && firstChild) {
|
|
3418
|
+
return firstChild;
|
|
3419
|
+
}
|
|
3420
|
+
return documentContainer;
|
|
3421
|
+
}
|
|
3422
|
+
|
|
3412
3423
|
// src/mcp/tools/build-composition/prompt.ts
|
|
3413
3424
|
import { toolPrompts } from "@elementor/editor-mcp";
|
|
3414
3425
|
var generatePrompt = () => {
|
|
@@ -3604,6 +3615,8 @@ var initBuildCompositionsTool = (reg) => {
|
|
|
3604
3615
|
const errors = [];
|
|
3605
3616
|
const rootContainers = [];
|
|
3606
3617
|
const documentContainer = getContainer3("document");
|
|
3618
|
+
const currentDocument = getCurrentDocument();
|
|
3619
|
+
const targetContainer = getCompositionTargetContainer(documentContainer, currentDocument?.type.value);
|
|
3607
3620
|
try {
|
|
3608
3621
|
const compositionBuilder = CompositionBuilder.fromXMLString(xmlStructure, {
|
|
3609
3622
|
createElement: createElement8,
|
|
@@ -3616,7 +3629,7 @@ var initBuildCompositionsTool = (reg) => {
|
|
|
3616
3629
|
configErrors,
|
|
3617
3630
|
invalidStyles,
|
|
3618
3631
|
rootContainers: generatedRootContainers
|
|
3619
|
-
} = compositionBuilder.build(
|
|
3632
|
+
} = compositionBuilder.build(targetContainer);
|
|
3620
3633
|
rootContainers.push(...generatedRootContainers);
|
|
3621
3634
|
generatedXML = new XMLSerializer().serializeToString(compositionBuilder.getXML());
|
|
3622
3635
|
if (configErrors.length) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-canvas",
|
|
3
3
|
"description": "Elementor Editor Canvas",
|
|
4
|
-
"version": "4.1.0-
|
|
4
|
+
"version": "4.1.0-696",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -37,24 +37,24 @@
|
|
|
37
37
|
"react-dom": "^18.3.1"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@elementor/editor": "4.1.0-
|
|
41
|
-
"@elementor/editor-controls": "4.1.0-
|
|
42
|
-
"@elementor/editor-documents": "4.1.0-
|
|
43
|
-
"@elementor/editor-elements": "4.1.0-
|
|
44
|
-
"@elementor/editor-interactions": "4.1.0-
|
|
45
|
-
"@elementor/editor-mcp": "4.1.0-
|
|
46
|
-
"@elementor/editor-notifications": "4.1.0-
|
|
47
|
-
"@elementor/editor-props": "4.1.0-
|
|
48
|
-
"@elementor/editor-responsive": "4.1.0-
|
|
49
|
-
"@elementor/editor-styles": "4.1.0-
|
|
50
|
-
"@elementor/editor-styles-repository": "4.1.0-
|
|
51
|
-
"@elementor/editor-ui": "4.1.0-
|
|
52
|
-
"@elementor/editor-v1-adapters": "4.1.0-
|
|
53
|
-
"@elementor/schema": "4.1.0-
|
|
54
|
-
"@elementor/twing": "4.1.0-
|
|
40
|
+
"@elementor/editor": "4.1.0-696",
|
|
41
|
+
"@elementor/editor-controls": "4.1.0-696",
|
|
42
|
+
"@elementor/editor-documents": "4.1.0-696",
|
|
43
|
+
"@elementor/editor-elements": "4.1.0-696",
|
|
44
|
+
"@elementor/editor-interactions": "4.1.0-696",
|
|
45
|
+
"@elementor/editor-mcp": "4.1.0-696",
|
|
46
|
+
"@elementor/editor-notifications": "4.1.0-696",
|
|
47
|
+
"@elementor/editor-props": "4.1.0-696",
|
|
48
|
+
"@elementor/editor-responsive": "4.1.0-696",
|
|
49
|
+
"@elementor/editor-styles": "4.1.0-696",
|
|
50
|
+
"@elementor/editor-styles-repository": "4.1.0-696",
|
|
51
|
+
"@elementor/editor-ui": "4.1.0-696",
|
|
52
|
+
"@elementor/editor-v1-adapters": "4.1.0-696",
|
|
53
|
+
"@elementor/schema": "4.1.0-696",
|
|
54
|
+
"@elementor/twing": "4.1.0-696",
|
|
55
55
|
"@elementor/ui": "1.36.17",
|
|
56
|
-
"@elementor/utils": "4.1.0-
|
|
57
|
-
"@elementor/wp-media": "4.1.0-
|
|
56
|
+
"@elementor/utils": "4.1.0-696",
|
|
57
|
+
"@elementor/wp-media": "4.1.0-696",
|
|
58
58
|
"@floating-ui/react": "^0.27.5",
|
|
59
59
|
"@wordpress/i18n": "^5.13.0"
|
|
60
60
|
},
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getCurrentDocument } from '@elementor/editor-documents';
|
|
1
2
|
import {
|
|
2
3
|
createElement,
|
|
3
4
|
deleteElement,
|
|
@@ -10,6 +11,7 @@ import { type MCPRegistryEntry } from '@elementor/editor-mcp';
|
|
|
10
11
|
import { CompositionBuilder } from '../../../composition-builder/composition-builder';
|
|
11
12
|
import { BEST_PRACTICES_URI, STYLE_SCHEMA_URI, WIDGET_SCHEMA_URI } from '../../resources/widgets-schema-resource';
|
|
12
13
|
import { doUpdateElementProperty } from '../../utils/do-update-element-property';
|
|
14
|
+
import { getCompositionTargetContainer } from '../../utils/get-composition-target-container';
|
|
13
15
|
import { generatePrompt } from './prompt';
|
|
14
16
|
import { inputSchema as schema, outputSchema } from './schema';
|
|
15
17
|
|
|
@@ -37,6 +39,8 @@ export const initBuildCompositionsTool = ( reg: MCPRegistryEntry ) => {
|
|
|
37
39
|
const errors: Error[] = [];
|
|
38
40
|
const rootContainers: V1Element[] = [];
|
|
39
41
|
const documentContainer = getContainer( 'document' ) as unknown as V1Element;
|
|
42
|
+
const currentDocument = getCurrentDocument();
|
|
43
|
+
const targetContainer = getCompositionTargetContainer( documentContainer, currentDocument?.type.value );
|
|
40
44
|
try {
|
|
41
45
|
const compositionBuilder = CompositionBuilder.fromXMLString( xmlStructure, {
|
|
42
46
|
createElement,
|
|
@@ -50,7 +54,7 @@ export const initBuildCompositionsTool = ( reg: MCPRegistryEntry ) => {
|
|
|
50
54
|
configErrors,
|
|
51
55
|
invalidStyles,
|
|
52
56
|
rootContainers: generatedRootContainers,
|
|
53
|
-
} = compositionBuilder.build(
|
|
57
|
+
} = compositionBuilder.build( targetContainer );
|
|
54
58
|
|
|
55
59
|
rootContainers.push( ...generatedRootContainers );
|
|
56
60
|
generatedXML = new XMLSerializer().serializeToString( compositionBuilder.getXML() );
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type V1Element } from '@elementor/editor-elements';
|
|
2
|
+
|
|
3
|
+
import { getCompositionTargetContainer } from '../get-composition-target-container';
|
|
4
|
+
|
|
5
|
+
const createMockContainer = ( id: string, children?: V1Element[] ): V1Element =>
|
|
6
|
+
( {
|
|
7
|
+
id,
|
|
8
|
+
model: { get: jest.fn(), set: jest.fn(), toJSON: jest.fn() },
|
|
9
|
+
settings: { get: jest.fn(), set: jest.fn(), toJSON: jest.fn() },
|
|
10
|
+
children,
|
|
11
|
+
} ) as unknown as V1Element;
|
|
12
|
+
|
|
13
|
+
describe( 'getCompositionTargetContainer', () => {
|
|
14
|
+
it( 'should return first child when document type is elementor_component', () => {
|
|
15
|
+
// Arrange
|
|
16
|
+
const firstChild = createMockContainer( 'child-1' );
|
|
17
|
+
const documentContainer = createMockContainer( 'document', [ firstChild ] );
|
|
18
|
+
|
|
19
|
+
// Act
|
|
20
|
+
const result = getCompositionTargetContainer( documentContainer, 'elementor_component' );
|
|
21
|
+
|
|
22
|
+
// Assert
|
|
23
|
+
expect( result ).toBe( firstChild );
|
|
24
|
+
} );
|
|
25
|
+
|
|
26
|
+
it( 'should return document container when document type is not a component', () => {
|
|
27
|
+
// Arrange
|
|
28
|
+
const firstChild = createMockContainer( 'child-1' );
|
|
29
|
+
const documentContainer = createMockContainer( 'document', [ firstChild ] );
|
|
30
|
+
|
|
31
|
+
// Act
|
|
32
|
+
const result = getCompositionTargetContainer( documentContainer, 'page' );
|
|
33
|
+
|
|
34
|
+
// Assert
|
|
35
|
+
expect( result ).toBe( documentContainer );
|
|
36
|
+
} );
|
|
37
|
+
|
|
38
|
+
it( 'should return document container when document type is undefined', () => {
|
|
39
|
+
// Arrange
|
|
40
|
+
const documentContainer = createMockContainer( 'document' );
|
|
41
|
+
|
|
42
|
+
// Act
|
|
43
|
+
const result = getCompositionTargetContainer( documentContainer, undefined );
|
|
44
|
+
|
|
45
|
+
// Assert
|
|
46
|
+
expect( result ).toBe( documentContainer );
|
|
47
|
+
} );
|
|
48
|
+
|
|
49
|
+
it( 'should return document container when component has no children', () => {
|
|
50
|
+
// Arrange
|
|
51
|
+
const documentContainer = createMockContainer( 'document' );
|
|
52
|
+
|
|
53
|
+
// Act
|
|
54
|
+
const result = getCompositionTargetContainer( documentContainer, 'elementor_component' );
|
|
55
|
+
|
|
56
|
+
// Assert
|
|
57
|
+
expect( result ).toBe( documentContainer );
|
|
58
|
+
} );
|
|
59
|
+
} );
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { COMPONENT_DOCUMENT_TYPE } from '@elementor/editor-documents';
|
|
2
|
+
import { type V1Element } from '@elementor/editor-elements';
|
|
3
|
+
|
|
4
|
+
export function getCompositionTargetContainer(
|
|
5
|
+
documentContainer: V1Element,
|
|
6
|
+
documentType: string | undefined
|
|
7
|
+
): V1Element {
|
|
8
|
+
const firstChild = documentContainer.children?.[ 0 ];
|
|
9
|
+
|
|
10
|
+
if ( documentType === COMPONENT_DOCUMENT_TYPE && firstChild ) {
|
|
11
|
+
return firstChild;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return documentContainer;
|
|
15
|
+
}
|