@elementor/editor-canvas 4.3.0-948 → 4.3.0-950
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 +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +47 -4
- package/dist/index.mjs +42 -0
- package/package.json +22 -21
- package/src/index.ts +1 -0
- package/src/mcp/tools/build-composition/tool.ts +49 -0
- package/src/mcp/tools/configure-element/tool.ts +3 -0
- package/src/utils/tracking.ts +14 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _elementor_editor_props from '@elementor/editor-props';
|
|
2
2
|
import { PropValue, Props, PropType, PropTypeKey, PropsSchema, AnyTransformable } from '@elementor/editor-props';
|
|
3
|
-
import { V1Element, V1ElementModelProps, V1ElementConfig } from '@elementor/editor-elements';
|
|
3
|
+
import { V1Element, V1ElementModelProps, V1ElementConfig, V1ElementData } from '@elementor/editor-elements';
|
|
4
4
|
import { TwingArrayLoader, TwingEnvironment } from '@elementor/twing';
|
|
5
5
|
import { Root } from 'react-dom/client';
|
|
6
6
|
import { StyleVariables, StyleDefinitionsMap, StyleDefinitionID, StyleDefinitionState } from '@elementor/editor-styles';
|
|
@@ -405,4 +405,10 @@ declare function useEscapeOnCanvas(canvasDocument: Document | null | undefined,
|
|
|
405
405
|
|
|
406
406
|
declare function doAfterRender(elementIds: string[], callback: (elementIds: string[]) => void): void;
|
|
407
407
|
|
|
408
|
-
|
|
408
|
+
type ElementAddedEvent = {
|
|
409
|
+
element: V1ElementData;
|
|
410
|
+
executedBy: 'mcp_tool' | 'user';
|
|
411
|
+
};
|
|
412
|
+
declare const ELEMENT_ADDED_EVENT = "elementor/canvas/element-added";
|
|
413
|
+
|
|
414
|
+
export { type AnyTransformer, BREAKPOINTS_SCHEMA_FULL_URI, BREAKPOINTS_SCHEMA_URI, type BackboneModel, type BackboneModelConstructor, type ContextMenuAction, type ContextMenuEventData, type ContextMenuGroup, type CreateNestedTemplatedElementTypeOptions, type CreateTemplatedElementTypeOptions, type CssConversionResult, DOCUMENT_STRUCTURE_URI, ELEMENT_ADDED_EVENT, type ElementAddedEvent, type ElementModel, ElementType, ElementView, GLOBAL_STYLES_IMPORTED_EVENT, type ImportedGlobalStylesPayload, type LegacyWindow, type MarionetteExtendable, type NamespacedRenderContext, type NestedTemplatedElementConfig, type NestedTemplatedElementViewClass, type PropsResolver, type RenderContext, type ReplacementSettings, SpotlightBackdrop, type StyleBlock, type StyleDeclarations, TemplatedElementView, type TransformerOptions, UnknownStyleStateError, UnknownStyleTypeError, WIDGET_SCHEMA_FULL_URI, WIDGET_SCHEMA_URI, canBeNestedTemplated, convertCssToAtomic, convertStyleBlocksToAtomic, createNestedTemplatedElementType, createNestedTemplatedElementView, createPropsResolver, createTemplatedElementView, createTransformer, createTransformersRegistry, doAfterRender, endDragElementFromPanel, formatGridTrackRepeat, init, isAtomicWidget, isGridTrackProperty, registerElementType, registerModelExtensions, settingsTransformersRegistry, startDragElementFromPanel, styleTransformersRegistry, stylesInheritanceTransformersRegistry, useCanvasDocument, useEscapeOnCanvas, waitForChildrenToComplete };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _elementor_editor_props from '@elementor/editor-props';
|
|
2
2
|
import { PropValue, Props, PropType, PropTypeKey, PropsSchema, AnyTransformable } from '@elementor/editor-props';
|
|
3
|
-
import { V1Element, V1ElementModelProps, V1ElementConfig } from '@elementor/editor-elements';
|
|
3
|
+
import { V1Element, V1ElementModelProps, V1ElementConfig, V1ElementData } from '@elementor/editor-elements';
|
|
4
4
|
import { TwingArrayLoader, TwingEnvironment } from '@elementor/twing';
|
|
5
5
|
import { Root } from 'react-dom/client';
|
|
6
6
|
import { StyleVariables, StyleDefinitionsMap, StyleDefinitionID, StyleDefinitionState } from '@elementor/editor-styles';
|
|
@@ -405,4 +405,10 @@ declare function useEscapeOnCanvas(canvasDocument: Document | null | undefined,
|
|
|
405
405
|
|
|
406
406
|
declare function doAfterRender(elementIds: string[], callback: (elementIds: string[]) => void): void;
|
|
407
407
|
|
|
408
|
-
|
|
408
|
+
type ElementAddedEvent = {
|
|
409
|
+
element: V1ElementData;
|
|
410
|
+
executedBy: 'mcp_tool' | 'user';
|
|
411
|
+
};
|
|
412
|
+
declare const ELEMENT_ADDED_EVENT = "elementor/canvas/element-added";
|
|
413
|
+
|
|
414
|
+
export { type AnyTransformer, BREAKPOINTS_SCHEMA_FULL_URI, BREAKPOINTS_SCHEMA_URI, type BackboneModel, type BackboneModelConstructor, type ContextMenuAction, type ContextMenuEventData, type ContextMenuGroup, type CreateNestedTemplatedElementTypeOptions, type CreateTemplatedElementTypeOptions, type CssConversionResult, DOCUMENT_STRUCTURE_URI, ELEMENT_ADDED_EVENT, type ElementAddedEvent, type ElementModel, ElementType, ElementView, GLOBAL_STYLES_IMPORTED_EVENT, type ImportedGlobalStylesPayload, type LegacyWindow, type MarionetteExtendable, type NamespacedRenderContext, type NestedTemplatedElementConfig, type NestedTemplatedElementViewClass, type PropsResolver, type RenderContext, type ReplacementSettings, SpotlightBackdrop, type StyleBlock, type StyleDeclarations, TemplatedElementView, type TransformerOptions, UnknownStyleStateError, UnknownStyleTypeError, WIDGET_SCHEMA_FULL_URI, WIDGET_SCHEMA_URI, canBeNestedTemplated, convertCssToAtomic, convertStyleBlocksToAtomic, createNestedTemplatedElementType, createNestedTemplatedElementView, createPropsResolver, createTemplatedElementView, createTransformer, createTransformersRegistry, doAfterRender, endDragElementFromPanel, formatGridTrackRepeat, init, isAtomicWidget, isGridTrackProperty, registerElementType, registerModelExtensions, settingsTransformersRegistry, startDragElementFromPanel, styleTransformersRegistry, stylesInheritanceTransformersRegistry, useCanvasDocument, useEscapeOnCanvas, waitForChildrenToComplete };
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(index_exports, {
|
|
|
33
33
|
BREAKPOINTS_SCHEMA_FULL_URI: () => BREAKPOINTS_SCHEMA_FULL_URI,
|
|
34
34
|
BREAKPOINTS_SCHEMA_URI: () => BREAKPOINTS_SCHEMA_URI,
|
|
35
35
|
DOCUMENT_STRUCTURE_URI: () => DOCUMENT_STRUCTURE_URI,
|
|
36
|
+
ELEMENT_ADDED_EVENT: () => ELEMENT_ADDED_EVENT,
|
|
36
37
|
GLOBAL_STYLES_IMPORTED_EVENT: () => GLOBAL_STYLES_IMPORTED_EVENT,
|
|
37
38
|
SpotlightBackdrop: () => SpotlightBackdrop,
|
|
38
39
|
UnknownStyleStateError: () => UnknownStyleStateError,
|
|
@@ -396,7 +397,7 @@ var convertCssToAtomic = async (style) => {
|
|
|
396
397
|
|
|
397
398
|
// src/init.tsx
|
|
398
399
|
var import_editor = require("@elementor/editor");
|
|
399
|
-
var
|
|
400
|
+
var import_editor_mcp6 = require("@elementor/editor-mcp");
|
|
400
401
|
|
|
401
402
|
// src/components/classes-rename.tsx
|
|
402
403
|
var import_react = require("react");
|
|
@@ -4656,6 +4657,7 @@ function getElementDisplayName(container) {
|
|
|
4656
4657
|
// src/mcp/tools/build-composition/tool.ts
|
|
4657
4658
|
var import_editor_documents3 = require("@elementor/editor-documents");
|
|
4658
4659
|
var import_editor_elements16 = require("@elementor/editor-elements");
|
|
4660
|
+
var import_editor_mcp3 = require("@elementor/editor-mcp");
|
|
4659
4661
|
|
|
4660
4662
|
// src/composition-builder/composition-builder.ts
|
|
4661
4663
|
var import_editor_elements15 = require("@elementor/editor-elements");
|
|
@@ -5161,6 +5163,12 @@ ${childTypeErrors.join("\n")}`);
|
|
|
5161
5163
|
}
|
|
5162
5164
|
};
|
|
5163
5165
|
|
|
5166
|
+
// src/utils/tracking.ts
|
|
5167
|
+
var import_events = require("@elementor/events");
|
|
5168
|
+
var trackCanvasEvent = (data) => {
|
|
5169
|
+
(0, import_events.trackEvent)(data);
|
|
5170
|
+
};
|
|
5171
|
+
|
|
5164
5172
|
// src/mcp/utils/get-composition-target-container.ts
|
|
5165
5173
|
var import_editor_documents2 = require("@elementor/editor-documents");
|
|
5166
5174
|
function getCompositionTargetContainer(documentContainer, documentType) {
|
|
@@ -5408,6 +5416,7 @@ function serializeWrapped(doc, rootElement, wrapperConfigId) {
|
|
|
5408
5416
|
}
|
|
5409
5417
|
|
|
5410
5418
|
// src/mcp/tools/build-composition/tool.ts
|
|
5419
|
+
var ELEMENT_ADDED_EVENT = "elementor/canvas/element-added";
|
|
5411
5420
|
var initBuildCompositionsTool = (reg) => {
|
|
5412
5421
|
const { addTool, resource } = reg;
|
|
5413
5422
|
resource(
|
|
@@ -5462,6 +5471,15 @@ var initBuildCompositionsTool = (reg) => {
|
|
|
5462
5471
|
const { configErrors, rootContainers: generatedRootContainers } = await compositionBuilder.build(targetContainer);
|
|
5463
5472
|
rootContainers.push(...generatedRootContainers);
|
|
5464
5473
|
generatedXML = new XMLSerializer().serializeToString(compositionBuilder.getXML());
|
|
5474
|
+
rootContainers.forEach((container) => {
|
|
5475
|
+
const elementData = container.model?.toJSON();
|
|
5476
|
+
if (elementData) {
|
|
5477
|
+
onElementAdded(elementData);
|
|
5478
|
+
}
|
|
5479
|
+
});
|
|
5480
|
+
Object.values(stylesConfig).forEach((styleValue) => {
|
|
5481
|
+
(0, import_editor_mcp3.dispatchMcpStylesAppliedEvent)({ styleValue });
|
|
5482
|
+
});
|
|
5465
5483
|
if (configErrors.length) {
|
|
5466
5484
|
errors.push(...configErrors.map((msg) => new Error(msg)));
|
|
5467
5485
|
}
|
|
@@ -5554,16 +5572,39 @@ function assertCompositionXmlUsesV4WidgetsOnly(xmlStructure) {
|
|
|
5554
5572
|
}
|
|
5555
5573
|
}
|
|
5556
5574
|
}
|
|
5575
|
+
function onElementAdded(element) {
|
|
5576
|
+
const elType = element.elType ?? "";
|
|
5577
|
+
const widgetType = element.widgetType ?? "";
|
|
5578
|
+
const elementName = elType === "widget" ? widgetType : elType;
|
|
5579
|
+
trackCanvasEvent({
|
|
5580
|
+
eventName: "add_element",
|
|
5581
|
+
executed_by: "mcp_tool",
|
|
5582
|
+
element_name: elementName,
|
|
5583
|
+
element_type: elType,
|
|
5584
|
+
widget_type: widgetType
|
|
5585
|
+
});
|
|
5586
|
+
const event = {
|
|
5587
|
+
element,
|
|
5588
|
+
executedBy: "mcp_tool"
|
|
5589
|
+
};
|
|
5590
|
+
window.dispatchEvent(new CustomEvent(ELEMENT_ADDED_EVENT, { detail: event }));
|
|
5591
|
+
if (element.elements?.length) {
|
|
5592
|
+
element.elements?.forEach((childElement) => {
|
|
5593
|
+
onElementAdded(childElement);
|
|
5594
|
+
});
|
|
5595
|
+
}
|
|
5596
|
+
}
|
|
5557
5597
|
|
|
5558
5598
|
// src/mcp/tools/configure-element/tool.ts
|
|
5559
5599
|
var import_editor_elements17 = require("@elementor/editor-elements");
|
|
5600
|
+
var import_editor_mcp5 = require("@elementor/editor-mcp");
|
|
5560
5601
|
var import_editor_props10 = require("@elementor/editor-props");
|
|
5561
5602
|
|
|
5562
5603
|
// src/mcp/tools/configure-element/prompt.ts
|
|
5563
|
-
var
|
|
5604
|
+
var import_editor_mcp4 = require("@elementor/editor-mcp");
|
|
5564
5605
|
var CONFIGURE_ELEMENT_GUIDE_URI = "elementor://canvas/tools/configure-element-guide";
|
|
5565
5606
|
var generatePrompt2 = () => {
|
|
5566
|
-
const configureElementToolPrompt = (0,
|
|
5607
|
+
const configureElementToolPrompt = (0, import_editor_mcp4.toolPrompts)("configure-element");
|
|
5567
5608
|
configureElementToolPrompt.description(`
|
|
5568
5609
|
Configure an existing element on the page.
|
|
5569
5610
|
|
|
@@ -5795,6 +5836,7 @@ async function applyStyleFromCss(opts) {
|
|
|
5795
5836
|
propertyValue: styleValue,
|
|
5796
5837
|
customCssWriteMode: "merge-with-stored"
|
|
5797
5838
|
});
|
|
5839
|
+
(0, import_editor_mcp5.dispatchMcpStylesAppliedEvent)({ styleValue });
|
|
5798
5840
|
} catch (error) {
|
|
5799
5841
|
throw new Error(
|
|
5800
5842
|
createUpdateErrorMessage({
|
|
@@ -6406,7 +6448,7 @@ function init() {
|
|
|
6406
6448
|
component: ClassesRename
|
|
6407
6449
|
});
|
|
6408
6450
|
initCanvasMcp(
|
|
6409
|
-
(0,
|
|
6451
|
+
(0, import_editor_mcp6.getMCPByDomain)("canvas", {
|
|
6410
6452
|
instructions: `Everything related to V4 ( Atomic ) canvas.
|
|
6411
6453
|
# Canvas workflow for new compositions
|
|
6412
6454
|
- Configure elements settings and styles
|
|
@@ -6557,6 +6599,7 @@ function hasDoAfterRender(view) {
|
|
|
6557
6599
|
BREAKPOINTS_SCHEMA_FULL_URI,
|
|
6558
6600
|
BREAKPOINTS_SCHEMA_URI,
|
|
6559
6601
|
DOCUMENT_STRUCTURE_URI,
|
|
6602
|
+
ELEMENT_ADDED_EVENT,
|
|
6560
6603
|
GLOBAL_STYLES_IMPORTED_EVENT,
|
|
6561
6604
|
SpotlightBackdrop,
|
|
6562
6605
|
UnknownStyleStateError,
|
package/dist/index.mjs
CHANGED
|
@@ -4630,6 +4630,7 @@ import {
|
|
|
4630
4630
|
getContainer as getContainer5,
|
|
4631
4631
|
getWidgetsCache as getWidgetsCache9
|
|
4632
4632
|
} from "@elementor/editor-elements";
|
|
4633
|
+
import { dispatchMcpStylesAppliedEvent } from "@elementor/editor-mcp";
|
|
4633
4634
|
|
|
4634
4635
|
// src/composition-builder/composition-builder.ts
|
|
4635
4636
|
import {
|
|
@@ -5147,6 +5148,12 @@ ${childTypeErrors.join("\n")}`);
|
|
|
5147
5148
|
}
|
|
5148
5149
|
};
|
|
5149
5150
|
|
|
5151
|
+
// src/utils/tracking.ts
|
|
5152
|
+
import { trackEvent } from "@elementor/events";
|
|
5153
|
+
var trackCanvasEvent = (data) => {
|
|
5154
|
+
trackEvent(data);
|
|
5155
|
+
};
|
|
5156
|
+
|
|
5150
5157
|
// src/mcp/utils/get-composition-target-container.ts
|
|
5151
5158
|
import { COMPONENT_DOCUMENT_TYPE } from "@elementor/editor-documents";
|
|
5152
5159
|
function getCompositionTargetContainer(documentContainer, documentType) {
|
|
@@ -5394,6 +5401,7 @@ function serializeWrapped(doc, rootElement, wrapperConfigId) {
|
|
|
5394
5401
|
}
|
|
5395
5402
|
|
|
5396
5403
|
// src/mcp/tools/build-composition/tool.ts
|
|
5404
|
+
var ELEMENT_ADDED_EVENT = "elementor/canvas/element-added";
|
|
5397
5405
|
var initBuildCompositionsTool = (reg) => {
|
|
5398
5406
|
const { addTool, resource } = reg;
|
|
5399
5407
|
resource(
|
|
@@ -5448,6 +5456,15 @@ var initBuildCompositionsTool = (reg) => {
|
|
|
5448
5456
|
const { configErrors, rootContainers: generatedRootContainers } = await compositionBuilder.build(targetContainer);
|
|
5449
5457
|
rootContainers.push(...generatedRootContainers);
|
|
5450
5458
|
generatedXML = new XMLSerializer().serializeToString(compositionBuilder.getXML());
|
|
5459
|
+
rootContainers.forEach((container) => {
|
|
5460
|
+
const elementData = container.model?.toJSON();
|
|
5461
|
+
if (elementData) {
|
|
5462
|
+
onElementAdded(elementData);
|
|
5463
|
+
}
|
|
5464
|
+
});
|
|
5465
|
+
Object.values(stylesConfig).forEach((styleValue) => {
|
|
5466
|
+
dispatchMcpStylesAppliedEvent({ styleValue });
|
|
5467
|
+
});
|
|
5451
5468
|
if (configErrors.length) {
|
|
5452
5469
|
errors.push(...configErrors.map((msg) => new Error(msg)));
|
|
5453
5470
|
}
|
|
@@ -5540,9 +5557,32 @@ function assertCompositionXmlUsesV4WidgetsOnly(xmlStructure) {
|
|
|
5540
5557
|
}
|
|
5541
5558
|
}
|
|
5542
5559
|
}
|
|
5560
|
+
function onElementAdded(element) {
|
|
5561
|
+
const elType = element.elType ?? "";
|
|
5562
|
+
const widgetType = element.widgetType ?? "";
|
|
5563
|
+
const elementName = elType === "widget" ? widgetType : elType;
|
|
5564
|
+
trackCanvasEvent({
|
|
5565
|
+
eventName: "add_element",
|
|
5566
|
+
executed_by: "mcp_tool",
|
|
5567
|
+
element_name: elementName,
|
|
5568
|
+
element_type: elType,
|
|
5569
|
+
widget_type: widgetType
|
|
5570
|
+
});
|
|
5571
|
+
const event = {
|
|
5572
|
+
element,
|
|
5573
|
+
executedBy: "mcp_tool"
|
|
5574
|
+
};
|
|
5575
|
+
window.dispatchEvent(new CustomEvent(ELEMENT_ADDED_EVENT, { detail: event }));
|
|
5576
|
+
if (element.elements?.length) {
|
|
5577
|
+
element.elements?.forEach((childElement) => {
|
|
5578
|
+
onElementAdded(childElement);
|
|
5579
|
+
});
|
|
5580
|
+
}
|
|
5581
|
+
}
|
|
5543
5582
|
|
|
5544
5583
|
// src/mcp/tools/configure-element/tool.ts
|
|
5545
5584
|
import { getContainer as getContainer6, getWidgetsCache as getWidgetsCache10 } from "@elementor/editor-elements";
|
|
5585
|
+
import { dispatchMcpStylesAppliedEvent as dispatchMcpStylesAppliedEvent2 } from "@elementor/editor-mcp";
|
|
5546
5586
|
import { Schema as Schema4 } from "@elementor/editor-props";
|
|
5547
5587
|
|
|
5548
5588
|
// src/mcp/tools/configure-element/prompt.ts
|
|
@@ -5781,6 +5821,7 @@ async function applyStyleFromCss(opts) {
|
|
|
5781
5821
|
propertyValue: styleValue,
|
|
5782
5822
|
customCssWriteMode: "merge-with-stored"
|
|
5783
5823
|
});
|
|
5824
|
+
dispatchMcpStylesAppliedEvent2({ styleValue });
|
|
5784
5825
|
} catch (error) {
|
|
5785
5826
|
throw new Error(
|
|
5786
5827
|
createUpdateErrorMessage({
|
|
@@ -6563,6 +6604,7 @@ export {
|
|
|
6563
6604
|
BREAKPOINTS_SCHEMA_FULL_URI,
|
|
6564
6605
|
BREAKPOINTS_SCHEMA_URI,
|
|
6565
6606
|
DOCUMENT_STRUCTURE_URI,
|
|
6607
|
+
ELEMENT_ADDED_EVENT,
|
|
6566
6608
|
GLOBAL_STYLES_IMPORTED_EVENT,
|
|
6567
6609
|
SpotlightBackdrop,
|
|
6568
6610
|
UnknownStyleStateError,
|
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.3.0-
|
|
4
|
+
"version": "4.3.0-950",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -37,28 +37,29 @@
|
|
|
37
37
|
"react-dom": "^18.3.1"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@elementor/editor": "4.3.0-
|
|
41
|
-
"
|
|
42
|
-
"@elementor/editor-
|
|
43
|
-
"@elementor/editor-
|
|
44
|
-
"@elementor/editor-
|
|
45
|
-
"@elementor/editor-
|
|
46
|
-
"@elementor/editor-
|
|
47
|
-
"@elementor/editor-
|
|
48
|
-
"@elementor/editor-
|
|
49
|
-
"@elementor/editor-
|
|
50
|
-
"@elementor/editor-styles": "4.3.0-
|
|
51
|
-
"@elementor/editor-
|
|
52
|
-
"@elementor/editor-
|
|
53
|
-
"@elementor/
|
|
54
|
-
"@elementor/http-client": "4.3.0-
|
|
55
|
-
"@elementor/schema": "4.3.0-
|
|
56
|
-
"@elementor/twing": "4.3.0-
|
|
40
|
+
"@elementor/editor": "4.3.0-950",
|
|
41
|
+
"@elementor/editor-controls": "4.3.0-950",
|
|
42
|
+
"@elementor/editor-documents": "4.3.0-950",
|
|
43
|
+
"@elementor/editor-elements": "4.3.0-950",
|
|
44
|
+
"@elementor/editor-interactions": "4.3.0-950",
|
|
45
|
+
"@elementor/editor-mcp": "4.3.0-950",
|
|
46
|
+
"@elementor/editor-notifications": "4.3.0-950",
|
|
47
|
+
"@elementor/editor-props": "4.3.0-950",
|
|
48
|
+
"@elementor/editor-responsive": "4.3.0-950",
|
|
49
|
+
"@elementor/editor-styles": "4.3.0-950",
|
|
50
|
+
"@elementor/editor-styles-repository": "4.3.0-950",
|
|
51
|
+
"@elementor/editor-ui": "4.3.0-950",
|
|
52
|
+
"@elementor/editor-v1-adapters": "4.3.0-950",
|
|
53
|
+
"@elementor/events": "4.3.0-950",
|
|
54
|
+
"@elementor/http-client": "4.3.0-950",
|
|
55
|
+
"@elementor/schema": "4.3.0-950",
|
|
56
|
+
"@elementor/twing": "4.3.0-950",
|
|
57
57
|
"@elementor/ui": "1.37.5",
|
|
58
|
-
"@elementor/utils": "4.3.0-
|
|
59
|
-
"@elementor/wp-media": "4.3.0-
|
|
58
|
+
"@elementor/utils": "4.3.0-950",
|
|
59
|
+
"@elementor/wp-media": "4.3.0-950",
|
|
60
60
|
"@floating-ui/react": "^0.27.5",
|
|
61
|
-
"@wordpress/i18n": "^5.13.0"
|
|
61
|
+
"@wordpress/i18n": "^5.13.0",
|
|
62
|
+
"dompurify": "^3.2.6"
|
|
62
63
|
},
|
|
63
64
|
"devDependencies": {
|
|
64
65
|
"tsup": "^8.3.5"
|
package/src/index.ts
CHANGED
|
@@ -44,3 +44,4 @@ export { UnknownStyleTypeError, UnknownStyleStateError } from './renderers/error
|
|
|
44
44
|
export { useCanvasDocument } from './hooks/use-canvas-document';
|
|
45
45
|
export { useEscapeOnCanvas } from './hooks/use-escape-on-canvas';
|
|
46
46
|
export { doAfterRender } from './utils/after-render';
|
|
47
|
+
export { ELEMENT_ADDED_EVENT, type ElementAddedEvent } from './mcp/tools/build-composition/tool';
|
|
@@ -5,10 +5,13 @@ import {
|
|
|
5
5
|
getContainer,
|
|
6
6
|
getWidgetsCache,
|
|
7
7
|
type V1Element,
|
|
8
|
+
type V1ElementData,
|
|
8
9
|
} from '@elementor/editor-elements';
|
|
9
10
|
import { type MCPRegistryEntry } from '@elementor/editor-mcp';
|
|
11
|
+
import { dispatchMcpStylesAppliedEvent } from '@elementor/editor-mcp';
|
|
10
12
|
|
|
11
13
|
import { CompositionBuilder } from '../../../composition-builder/composition-builder';
|
|
14
|
+
import { trackCanvasEvent } from '../../../utils/tracking';
|
|
12
15
|
import { AVAILABLE_WIDGETS_URI_V4 } from '../../resources/available-widgets-resource';
|
|
13
16
|
import { DYNAMIC_TAGS_URI } from '../../resources/dynamic-tags-resource';
|
|
14
17
|
import { BEST_PRACTICES_URI, WIDGET_SCHEMA_URI } from '../../resources/widgets-schema-resource';
|
|
@@ -19,6 +22,13 @@ import { BUILD_COMPOSITIONS_GUIDE_URI, generatePrompt } from './prompt';
|
|
|
19
22
|
import { inputSchema as schema, outputSchema } from './schema';
|
|
20
23
|
import { adaptLeafRootParams } from './xml-leaf-wrapper';
|
|
21
24
|
|
|
25
|
+
export type ElementAddedEvent = {
|
|
26
|
+
element: V1ElementData;
|
|
27
|
+
executedBy: 'mcp_tool' | 'user';
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const ELEMENT_ADDED_EVENT = 'elementor/canvas/element-added';
|
|
31
|
+
|
|
22
32
|
export const initBuildCompositionsTool = ( reg: MCPRegistryEntry ) => {
|
|
23
33
|
const { addTool, resource } = reg;
|
|
24
34
|
|
|
@@ -80,6 +90,18 @@ export const initBuildCompositionsTool = ( reg: MCPRegistryEntry ) => {
|
|
|
80
90
|
rootContainers.push( ...generatedRootContainers );
|
|
81
91
|
generatedXML = new XMLSerializer().serializeToString( compositionBuilder.getXML() );
|
|
82
92
|
|
|
93
|
+
rootContainers.forEach( ( container ) => {
|
|
94
|
+
const elementData = container.model?.toJSON();
|
|
95
|
+
|
|
96
|
+
if ( elementData ) {
|
|
97
|
+
onElementAdded( elementData as V1ElementData );
|
|
98
|
+
}
|
|
99
|
+
} );
|
|
100
|
+
|
|
101
|
+
Object.values( stylesConfig ).forEach( ( styleValue ) => {
|
|
102
|
+
dispatchMcpStylesAppliedEvent( { styleValue } );
|
|
103
|
+
} );
|
|
104
|
+
|
|
83
105
|
if ( configErrors.length ) {
|
|
84
106
|
errors.push( ...configErrors.map( ( msg ) => new Error( msg ) ) );
|
|
85
107
|
}
|
|
@@ -186,3 +208,30 @@ function assertCompositionXmlUsesV4WidgetsOnly( xmlStructure: string ) {
|
|
|
186
208
|
}
|
|
187
209
|
}
|
|
188
210
|
}
|
|
211
|
+
|
|
212
|
+
function onElementAdded( element: V1ElementData ) {
|
|
213
|
+
const elType = element.elType ?? '';
|
|
214
|
+
const widgetType = element.widgetType ?? '';
|
|
215
|
+
const elementName = elType === 'widget' ? widgetType : elType;
|
|
216
|
+
|
|
217
|
+
trackCanvasEvent( {
|
|
218
|
+
eventName: 'add_element',
|
|
219
|
+
executed_by: 'mcp_tool',
|
|
220
|
+
element_name: elementName,
|
|
221
|
+
element_type: elType,
|
|
222
|
+
widget_type: widgetType,
|
|
223
|
+
} );
|
|
224
|
+
|
|
225
|
+
const event: ElementAddedEvent = {
|
|
226
|
+
element,
|
|
227
|
+
executedBy: 'mcp_tool',
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
window.dispatchEvent( new CustomEvent( ELEMENT_ADDED_EVENT, { detail: event } ) );
|
|
231
|
+
|
|
232
|
+
if ( element.elements?.length ) {
|
|
233
|
+
element.elements?.forEach( ( childElement ) => {
|
|
234
|
+
onElementAdded( childElement );
|
|
235
|
+
} );
|
|
236
|
+
}
|
|
237
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getContainer, getWidgetsCache } from '@elementor/editor-elements';
|
|
2
2
|
import { type MCPRegistryEntry } from '@elementor/editor-mcp';
|
|
3
|
+
import { dispatchMcpStylesAppliedEvent } from '@elementor/editor-mcp';
|
|
3
4
|
import { type PropValue, Schema } from '@elementor/editor-props';
|
|
4
5
|
|
|
5
6
|
import { DYNAMIC_TAGS_URI } from '../../resources/dynamic-tags-resource';
|
|
@@ -115,6 +116,8 @@ async function applyStyleFromCss( opts: {
|
|
|
115
116
|
propertyValue: styleValue,
|
|
116
117
|
customCssWriteMode: 'merge-with-stored',
|
|
117
118
|
} );
|
|
119
|
+
|
|
120
|
+
dispatchMcpStylesAppliedEvent( { styleValue } );
|
|
118
121
|
} catch ( error ) {
|
|
119
122
|
throw new Error(
|
|
120
123
|
createUpdateErrorMessage( {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { trackEvent } from '@elementor/events';
|
|
2
|
+
|
|
3
|
+
type ElementEventData = {
|
|
4
|
+
eventName: 'add_element';
|
|
5
|
+
element_name: string;
|
|
6
|
+
element_type: string;
|
|
7
|
+
widget_type: string;
|
|
8
|
+
location?: string;
|
|
9
|
+
executed_by: 'user' | 'mcp_tool' | 'system';
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const trackCanvasEvent = ( data: ElementEventData ) => {
|
|
13
|
+
trackEvent( data );
|
|
14
|
+
};
|