@elementor/editor-canvas 4.3.0-991 → 4.3.0-993
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 +251 -409
- package/dist/index.mjs +122 -282
- package/package.json +20 -20
- package/src/mcp/resources/__tests__/available-widgets-resource.test.ts +76 -0
- package/src/mcp/resources/__tests__/widgets-schema-resource.test.ts +79 -76
- package/src/mcp/resources/available-widgets-resource.ts +31 -40
- package/src/mcp/resources/widgets-schema-resource.ts +35 -150
- package/src/mcp/resources/build-llm-guidance.ts +0 -110
package/dist/index.mjs
CHANGED
|
@@ -2,178 +2,37 @@
|
|
|
2
2
|
import { v1ReadyEvent } from "@elementor/editor-v1-adapters";
|
|
3
3
|
|
|
4
4
|
// src/mcp/resources/widgets-schema-resource.ts
|
|
5
|
-
import { getWidgetsCache as getWidgetsCache2 } from "@elementor/editor-elements";
|
|
6
5
|
import { ResourceTemplate } from "@elementor/editor-mcp";
|
|
7
|
-
import {
|
|
8
|
-
Schema
|
|
9
|
-
} from "@elementor/editor-props";
|
|
10
|
-
|
|
11
|
-
// src/mcp/utils/element-data-util.ts
|
|
12
|
-
import { getWidgetsCache } from "@elementor/editor-elements";
|
|
13
|
-
function hasV3Controls(controls) {
|
|
14
|
-
return typeof controls === "object" && controls !== null && Object.keys(controls).length > 0;
|
|
15
|
-
}
|
|
16
|
-
function isWidgetAvailableForLLM(config) {
|
|
17
|
-
if (!config) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
if (config.meta?.llm_support === false) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
if (config.title === "Component") {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
if (config.atomic_props_schema) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
return hasV3Controls(config.controls);
|
|
30
|
-
}
|
|
31
|
-
function getWidgetVersion(config) {
|
|
32
|
-
return config?.atomic_props_schema ? "v4" : "v3";
|
|
33
|
-
}
|
|
34
|
-
function getAvailableWidgets() {
|
|
35
|
-
const cache = getWidgetsCache() ?? {};
|
|
36
|
-
return Object.keys(cache).filter((widgetType) => isWidgetAvailableForLLM(cache[widgetType])).sort().map((widgetType) => {
|
|
37
|
-
const config = cache[widgetType];
|
|
38
|
-
const description = typeof config?.meta?.description === "string" ? config.meta.description : void 0;
|
|
39
|
-
return {
|
|
40
|
-
type: widgetType,
|
|
41
|
-
version: getWidgetVersion(config),
|
|
42
|
-
...description && { description }
|
|
43
|
-
};
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// src/composition-builder/utils/required-default-child-tags.ts
|
|
48
|
-
function getRequiredDefaultChildTemplates(elementConfig) {
|
|
49
|
-
const defaultChildren = elementConfig?.default_children;
|
|
50
|
-
if (!Array.isArray(defaultChildren)) {
|
|
51
|
-
return [];
|
|
52
|
-
}
|
|
53
|
-
return defaultChildren.filter((child) => child?.meta?.required ?? false);
|
|
54
|
-
}
|
|
55
|
-
function getRequiredDefaultChildTypes(elementConfig) {
|
|
56
|
-
return getRequiredDefaultChildTemplates(elementConfig).map((child) => child.widgetType ?? child.elType ?? "").filter((type) => Boolean(type));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// src/mcp/resources/build-llm-guidance.ts
|
|
60
|
-
var DEFAULT_STYLES_INSTRUCTION = "These are the default styles applied to the widget. Override only when necessary.";
|
|
61
|
-
var DEFAULT_SETTINGS_INSTRUCTION = "These are the default settings applied to the widget. Omit them from elementConfig unless the user explicitly asks to change them.";
|
|
62
|
-
var BASE_SETTING_PROP_HINT = "Has a widget default \u2014 omit unless user explicitly requests a change. See llm_guidance.default_settings.";
|
|
63
|
-
function mergeInstructions(existing, additional) {
|
|
64
|
-
if (typeof existing === "string" && existing.length > 0) {
|
|
65
|
-
return `${existing} ${additional}`;
|
|
66
|
-
}
|
|
67
|
-
return additional;
|
|
68
|
-
}
|
|
69
|
-
function enrichPropertiesWithBaseSettingsHints(properties, baseSettingsKeys) {
|
|
70
|
-
if (!baseSettingsKeys.length) {
|
|
71
|
-
return properties;
|
|
72
|
-
}
|
|
73
|
-
const enriched = { ...properties };
|
|
74
|
-
for (const key of baseSettingsKeys) {
|
|
75
|
-
const propSchema = enriched[key];
|
|
76
|
-
if (!propSchema) {
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
enriched[key] = {
|
|
80
|
-
...propSchema,
|
|
81
|
-
description: propSchema.description ? `${propSchema.description} ${BASE_SETTING_PROP_HINT}` : BASE_SETTING_PROP_HINT
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
return enriched;
|
|
85
|
-
}
|
|
86
|
-
function buildLlmGuidance(widgetData, widgetType, allWidgets) {
|
|
87
|
-
const defaultStyles = {};
|
|
88
|
-
const baseStyleSchema = widgetData?.base_styles;
|
|
89
|
-
if (baseStyleSchema) {
|
|
90
|
-
Object.values(baseStyleSchema).forEach((stylePropType) => {
|
|
91
|
-
stylePropType.variants.forEach((variant) => {
|
|
92
|
-
Object.assign(defaultStyles, variant.props);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
const baseSettings = widgetData?.base_settings ?? {};
|
|
97
|
-
const hasDefaultStyles = Object.keys(defaultStyles).length > 0;
|
|
98
|
-
const hasDefaultSettings = Object.keys(baseSettings).length > 0;
|
|
99
|
-
const llmGuidance = {
|
|
100
|
-
can_have_children: !!widgetData?.meta?.is_container
|
|
101
|
-
};
|
|
102
|
-
if (hasDefaultStyles) {
|
|
103
|
-
llmGuidance.instructions = DEFAULT_STYLES_INSTRUCTION;
|
|
104
|
-
llmGuidance.default_styles = defaultStyles;
|
|
105
|
-
}
|
|
106
|
-
if (hasDefaultSettings) {
|
|
107
|
-
llmGuidance.instructions = mergeInstructions(llmGuidance.instructions, DEFAULT_SETTINGS_INSTRUCTION);
|
|
108
|
-
llmGuidance.default_settings = baseSettings;
|
|
109
|
-
}
|
|
110
|
-
const allowedChildTypes = widgetData.allowed_child_types;
|
|
111
|
-
const allowedParents = Object.entries(allWidgets).filter(([, parentConfig]) => parentConfig.allowed_child_types?.includes(widgetType)).map(([parentType]) => parentType);
|
|
112
|
-
if (allowedChildTypes?.length || allowedParents.length) {
|
|
113
|
-
llmGuidance.nesting = {
|
|
114
|
-
...allowedChildTypes?.length ? { allowed_child_types: allowedChildTypes } : {},
|
|
115
|
-
...allowedParents.length ? { allowed_parents: allowedParents } : {}
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
const requiredDirectChildTags = getRequiredDefaultChildTypes(widgetData);
|
|
119
|
-
if (requiredDirectChildTags.length) {
|
|
120
|
-
llmGuidance.required_direct_children = requiredDirectChildTags;
|
|
121
|
-
}
|
|
122
|
-
return llmGuidance;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// src/mcp/resources/widgets-schema-resource.ts
|
|
126
|
-
var V3_LAYOUT_CONTROL_TYPES = /* @__PURE__ */ new Set(["section", "tab", "tabs"]);
|
|
127
|
-
function extractV3ControlsMetadata(controls) {
|
|
128
|
-
if (!hasV3Controls(controls)) {
|
|
129
|
-
return {};
|
|
130
|
-
}
|
|
131
|
-
const result = {};
|
|
132
|
-
for (const [controlKey, raw] of Object.entries(controls)) {
|
|
133
|
-
if (!raw || typeof raw !== "object") {
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
const control = raw;
|
|
137
|
-
const controlType = typeof control.type === "string" ? control.type : void 0;
|
|
138
|
-
if (controlType && V3_LAYOUT_CONTROL_TYPES.has(controlType)) {
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
const entry = {};
|
|
142
|
-
if (Object.prototype.hasOwnProperty.call(control, "default")) {
|
|
143
|
-
entry.default = control.default;
|
|
144
|
-
}
|
|
145
|
-
if (controlType) {
|
|
146
|
-
entry.type = controlType;
|
|
147
|
-
}
|
|
148
|
-
if (Object.prototype.hasOwnProperty.call(control, "options") && control.options !== void 0) {
|
|
149
|
-
const options = control.options;
|
|
150
|
-
if (options && typeof options === "object" && !Array.isArray(options)) {
|
|
151
|
-
entry.options = Object.keys(options);
|
|
152
|
-
} else {
|
|
153
|
-
entry.options = options;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
result[controlKey] = entry;
|
|
157
|
-
}
|
|
158
|
-
return result;
|
|
159
|
-
}
|
|
6
|
+
import { httpService } from "@elementor/http-client";
|
|
160
7
|
var CANVAS_SERVER_NAME = "editor-canvas";
|
|
161
8
|
var WIDGET_SCHEMA_URI = "elementor://widgets/schema/{widgetType}";
|
|
162
9
|
var WIDGET_SCHEMA_FULL_URI = `${CANVAS_SERVER_NAME}_${WIDGET_SCHEMA_URI}`;
|
|
163
10
|
var BEST_PRACTICES_URI = "elementor://style/best-practices";
|
|
164
11
|
var BEST_PRACTICES_FULL_URI = `${CANVAS_SERVER_NAME}_${BEST_PRACTICES_URI}`;
|
|
12
|
+
var MCP_PROXY_URL = "elementor/v1/mcp-proxy";
|
|
13
|
+
var listWidgetTypes = async () => {
|
|
14
|
+
const { data } = await httpService().post(MCP_PROXY_URL, {
|
|
15
|
+
tool: "list-widgets",
|
|
16
|
+
input: {}
|
|
17
|
+
});
|
|
18
|
+
return (data.data ?? []).map((widget) => widget.type);
|
|
19
|
+
};
|
|
20
|
+
var fetchWidgetSchema = async (widgetType) => {
|
|
21
|
+
const { data } = await httpService().post(MCP_PROXY_URL, {
|
|
22
|
+
tool: "get-widget-schema",
|
|
23
|
+
input: { widget_type: widgetType }
|
|
24
|
+
});
|
|
25
|
+
return data.data ?? {};
|
|
26
|
+
};
|
|
165
27
|
var initWidgetsSchemaResource = (reg) => {
|
|
166
28
|
const { resource } = reg;
|
|
167
29
|
resource(
|
|
168
30
|
"widget-schema-by-type",
|
|
169
31
|
new ResourceTemplate(WIDGET_SCHEMA_URI, {
|
|
170
|
-
list: () => {
|
|
171
|
-
const
|
|
172
|
-
const availableWidgets = Object.keys(cache).filter(
|
|
173
|
-
(widgetType) => isWidgetAvailableForLLM(cache[widgetType])
|
|
174
|
-
);
|
|
32
|
+
list: async () => {
|
|
33
|
+
const widgetTypes = await listWidgetTypes();
|
|
175
34
|
return {
|
|
176
|
-
resources:
|
|
35
|
+
resources: widgetTypes.map((widgetType) => ({
|
|
177
36
|
uri: `elementor://widgets/schema/${widgetType}`,
|
|
178
37
|
name: "Widget schema for " + widgetType
|
|
179
38
|
}))
|
|
@@ -185,52 +44,16 @@ var initWidgetsSchemaResource = (reg) => {
|
|
|
185
44
|
},
|
|
186
45
|
async (uri, variables) => {
|
|
187
46
|
const widgetType = typeof variables.widgetType === "string" ? variables.widgetType : variables.widgetType?.[0];
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
throw new Error(`No prop schema found for element type: ${widgetType}`);
|
|
47
|
+
if (!widgetType) {
|
|
48
|
+
throw new Error("No widget type provided.");
|
|
191
49
|
}
|
|
192
|
-
const
|
|
193
|
-
if (!propSchema) {
|
|
194
|
-
if (!hasV3Controls(widgetData.controls)) {
|
|
195
|
-
throw new Error(`No prop schema found for element type: ${widgetType}`);
|
|
196
|
-
}
|
|
197
|
-
const controlMetadata = extractV3ControlsMetadata(widgetData.controls);
|
|
198
|
-
return {
|
|
199
|
-
contents: [
|
|
200
|
-
{
|
|
201
|
-
uri: uri.toString(),
|
|
202
|
-
mimeType: "application/json",
|
|
203
|
-
text: JSON.stringify({
|
|
204
|
-
widget_version: "v3",
|
|
205
|
-
message: "This widget exists in the editor but has no atomic props schema (V4). Use control_metadata as non-authoritative hints from legacy controls.",
|
|
206
|
-
fields_note: "All settings are optional; there is no JSON schema for this widget type.",
|
|
207
|
-
properties: controlMetadata
|
|
208
|
-
})
|
|
209
|
-
}
|
|
210
|
-
]
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
const baseSettingsKeys = Object.keys(widgetData?.base_settings ?? {});
|
|
214
|
-
const asJson = enrichPropertiesWithBaseSettingsHints(
|
|
215
|
-
Object.fromEntries(
|
|
216
|
-
Object.entries(propSchema).filter(([key, propType]) => Schema.isPropKeyConfigurable(key, propType)).map(([key, propType]) => [key, Schema.propTypeToJsonSchema(propType)])
|
|
217
|
-
),
|
|
218
|
-
baseSettingsKeys
|
|
219
|
-
);
|
|
220
|
-
const description = typeof widgetData?.meta?.description === "string" ? widgetData.meta.description : void 0;
|
|
221
|
-
const allWidgets = getWidgetsCache2() || {};
|
|
222
|
-
const llmGuidance = buildLlmGuidance(widgetData, widgetType, allWidgets);
|
|
50
|
+
const schema2 = await fetchWidgetSchema(widgetType);
|
|
223
51
|
return {
|
|
224
52
|
contents: [
|
|
225
53
|
{
|
|
226
54
|
uri: uri.toString(),
|
|
227
55
|
mimeType: "application/json",
|
|
228
|
-
text: JSON.stringify(
|
|
229
|
-
type: "object",
|
|
230
|
-
properties: asJson,
|
|
231
|
-
description,
|
|
232
|
-
llm_guidance: llmGuidance
|
|
233
|
-
})
|
|
56
|
+
text: JSON.stringify(schema2)
|
|
234
57
|
}
|
|
235
58
|
]
|
|
236
59
|
};
|
|
@@ -285,11 +108,11 @@ var initBreakpointsResource = (reg) => {
|
|
|
285
108
|
};
|
|
286
109
|
|
|
287
110
|
// src/mcp/utils/convert-css-to-atomic.ts
|
|
288
|
-
import { httpService } from "@elementor/http-client";
|
|
111
|
+
import { httpService as httpService2 } from "@elementor/http-client";
|
|
289
112
|
var CSS_TO_ATOMIC_URL = "elementor/v1/css-to-atomic";
|
|
290
113
|
var SINGLE_BLOCK_KEY = "default";
|
|
291
114
|
var convertBlocks = async (blocks) => {
|
|
292
|
-
const { data } = await
|
|
115
|
+
const { data } = await httpService2().post(
|
|
293
116
|
CSS_TO_ATOMIC_URL,
|
|
294
117
|
{ blocks }
|
|
295
118
|
);
|
|
@@ -2732,7 +2555,7 @@ function initStyleTransformers() {
|
|
|
2732
2555
|
}
|
|
2733
2556
|
|
|
2734
2557
|
// src/legacy/init-legacy-views.ts
|
|
2735
|
-
import { getWidgetsCache
|
|
2558
|
+
import { getWidgetsCache } from "@elementor/editor-elements";
|
|
2736
2559
|
import { __privateIsReady as isV1Ready, __privateListenTo, v1ReadyEvent as v1ReadyEvent2 } from "@elementor/editor-v1-adapters";
|
|
2737
2560
|
|
|
2738
2561
|
// src/renderers/create-dom-renderer.ts
|
|
@@ -4048,7 +3871,7 @@ function registerElementType(type, elementTypeGenerator) {
|
|
|
4048
3871
|
}
|
|
4049
3872
|
function initLegacyViews() {
|
|
4050
3873
|
__privateListenTo(v1ReadyEvent2(), () => {
|
|
4051
|
-
const widgetsCache =
|
|
3874
|
+
const widgetsCache = getWidgetsCache() ?? {};
|
|
4052
3875
|
const renderer = createDomRenderer();
|
|
4053
3876
|
registerProPromotionTypes(widgetsCache);
|
|
4054
3877
|
Object.keys(widgetsCache).forEach((type) => {
|
|
@@ -4057,7 +3880,7 @@ function initLegacyViews() {
|
|
|
4057
3880
|
});
|
|
4058
3881
|
}
|
|
4059
3882
|
function registerElementInLegacyManager(type, renderer) {
|
|
4060
|
-
const element = (
|
|
3883
|
+
const element = (getWidgetsCache() ?? {})[type];
|
|
4061
3884
|
if (!element?.atomic) {
|
|
4062
3885
|
return;
|
|
4063
3886
|
}
|
|
@@ -4139,43 +3962,41 @@ function initTabsModelExtensions() {
|
|
|
4139
3962
|
}
|
|
4140
3963
|
|
|
4141
3964
|
// src/mcp/canvas-mcp.ts
|
|
4142
|
-
import { Schema as
|
|
3965
|
+
import { Schema as Schema4 } from "@elementor/editor-props";
|
|
4143
3966
|
|
|
4144
3967
|
// src/mcp/resources/available-widgets-resource.ts
|
|
4145
|
-
import {
|
|
3968
|
+
import { httpService as httpService3 } from "@elementor/http-client";
|
|
3969
|
+
var MCP_PROXY_URL2 = "elementor/v1/mcp-proxy";
|
|
4146
3970
|
var AVAILABLE_WIDGETS_URI = "elementor://context/available-widgets";
|
|
4147
3971
|
var AVAILABLE_WIDGETS_URI_V4 = "elementor://context/available-widgets/v4";
|
|
4148
|
-
var
|
|
4149
|
-
const {
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
...buildContents(AVAILABLE_WIDGETS_URI)
|
|
4166
|
-
});
|
|
4167
|
-
sendResourceUpdated({
|
|
4168
|
-
uri: AVAILABLE_WIDGETS_URI_V4,
|
|
4169
|
-
...buildContents(AVAILABLE_WIDGETS_URI_V4, (w) => w.version === "v4")
|
|
4170
|
-
});
|
|
3972
|
+
var fetchWidgets = async (version) => {
|
|
3973
|
+
const { data } = await httpService3().post(MCP_PROXY_URL2, {
|
|
3974
|
+
tool: "list-widgets",
|
|
3975
|
+
input: version ? { version } : {}
|
|
3976
|
+
});
|
|
3977
|
+
return data.data ?? [];
|
|
3978
|
+
};
|
|
3979
|
+
var buildContents = async (uri, version) => {
|
|
3980
|
+
const widgets = await fetchWidgets(version);
|
|
3981
|
+
return {
|
|
3982
|
+
contents: [
|
|
3983
|
+
{
|
|
3984
|
+
uri,
|
|
3985
|
+
mimeType: "application/json",
|
|
3986
|
+
text: JSON.stringify(widgets, null, 2)
|
|
3987
|
+
}
|
|
3988
|
+
]
|
|
4171
3989
|
};
|
|
3990
|
+
};
|
|
3991
|
+
var initAvailableWidgetsResource = (reg) => {
|
|
3992
|
+
const { resource } = reg;
|
|
4172
3993
|
resource(
|
|
4173
3994
|
"available-widgets-v4",
|
|
4174
3995
|
AVAILABLE_WIDGETS_URI_V4,
|
|
4175
3996
|
{
|
|
4176
3997
|
description: "All registered v4 version widgets"
|
|
4177
3998
|
},
|
|
4178
|
-
async () => buildContents(AVAILABLE_WIDGETS_URI_V4,
|
|
3999
|
+
async () => buildContents(AVAILABLE_WIDGETS_URI_V4, "v4")
|
|
4179
4000
|
);
|
|
4180
4001
|
resource(
|
|
4181
4002
|
"available-widgets",
|
|
@@ -4185,22 +4006,11 @@ var initAvailableWidgetsResource = (reg) => {
|
|
|
4185
4006
|
},
|
|
4186
4007
|
async () => buildContents(AVAILABLE_WIDGETS_URI)
|
|
4187
4008
|
);
|
|
4188
|
-
const eventName = v1ReadyEvent3().name;
|
|
4189
|
-
const onV1Ready = () => {
|
|
4190
|
-
const widgets = getAvailableWidgets();
|
|
4191
|
-
if (widgets.length === 0) {
|
|
4192
|
-
return;
|
|
4193
|
-
}
|
|
4194
|
-
window.removeEventListener(eventName, onV1Ready);
|
|
4195
|
-
notifyResourcesUpdated();
|
|
4196
|
-
};
|
|
4197
|
-
window.addEventListener(eventName, onV1Ready);
|
|
4198
|
-
onV1Ready();
|
|
4199
4009
|
};
|
|
4200
4010
|
|
|
4201
4011
|
// src/mcp/resources/best-practices-resource.ts
|
|
4202
|
-
import { httpService as
|
|
4203
|
-
var
|
|
4012
|
+
import { httpService as httpService4 } from "@elementor/http-client";
|
|
4013
|
+
var MCP_PROXY_URL3 = "elementor/v1/mcp-proxy";
|
|
4204
4014
|
var BEST_PRACTICES_URI2 = "elementor://style/best-practices";
|
|
4205
4015
|
var initBestPracticesResource = (reg) => {
|
|
4206
4016
|
const { resource } = reg;
|
|
@@ -4212,7 +4022,7 @@ var initBestPracticesResource = (reg) => {
|
|
|
4212
4022
|
mimeType: "text/markdown"
|
|
4213
4023
|
},
|
|
4214
4024
|
async (uri) => {
|
|
4215
|
-
const { data } = await
|
|
4025
|
+
const { data } = await httpService4().get(MCP_PROXY_URL3, {
|
|
4216
4026
|
params: { uri: uri.href }
|
|
4217
4027
|
});
|
|
4218
4028
|
return {
|
|
@@ -4230,7 +4040,7 @@ var initBestPracticesResource = (reg) => {
|
|
|
4230
4040
|
|
|
4231
4041
|
// src/mcp/resources/document-structure-resource.ts
|
|
4232
4042
|
import {
|
|
4233
|
-
getWidgetsCache as
|
|
4043
|
+
getWidgetsCache as getWidgetsCache2
|
|
4234
4044
|
} from "@elementor/editor-elements";
|
|
4235
4045
|
import { __privateListenTo as listenTo, commandEndEvent as commandEndEvent4 } from "@elementor/editor-v1-adapters";
|
|
4236
4046
|
var DOCUMENT_STRUCTURE_URI = "elementor://document/structure";
|
|
@@ -4296,7 +4106,7 @@ function resolveElementVersion(element) {
|
|
|
4296
4106
|
return "v4";
|
|
4297
4107
|
}
|
|
4298
4108
|
const widgetType = element.model?.attributes?.widgetType;
|
|
4299
|
-
if (widgetType &&
|
|
4109
|
+
if (widgetType && getWidgetsCache2()?.[widgetType]?.atomic_props_schema) {
|
|
4300
4110
|
return "v4";
|
|
4301
4111
|
}
|
|
4302
4112
|
return "v3";
|
|
@@ -4323,11 +4133,11 @@ function extractElementData(element) {
|
|
|
4323
4133
|
}
|
|
4324
4134
|
|
|
4325
4135
|
// src/mcp/resources/dynamic-tags-resource.ts
|
|
4326
|
-
import { httpService as
|
|
4136
|
+
import { httpService as httpService5 } from "@elementor/http-client";
|
|
4327
4137
|
var DYNAMIC_TAGS_URI = "elementor://dynamic-tags";
|
|
4328
|
-
var
|
|
4138
|
+
var MCP_PROXY_URL4 = "elementor/v1/mcp-proxy";
|
|
4329
4139
|
var fetchDynamicTags = async () => {
|
|
4330
|
-
const { data } = await
|
|
4140
|
+
const { data } = await httpService5().post(MCP_PROXY_URL4, {
|
|
4331
4141
|
tool: "list-dynamic-tags",
|
|
4332
4142
|
input: {}
|
|
4333
4143
|
});
|
|
@@ -4527,7 +4337,7 @@ var initGeneralContextResource = (reg) => {
|
|
|
4527
4337
|
};
|
|
4528
4338
|
|
|
4529
4339
|
// src/mcp/resources/selected-element-resource.ts
|
|
4530
|
-
import { getContainer as getContainer3, getSelectedElements, getWidgetsCache as
|
|
4340
|
+
import { getContainer as getContainer3, getSelectedElements, getWidgetsCache as getWidgetsCache3 } from "@elementor/editor-elements";
|
|
4531
4341
|
import {
|
|
4532
4342
|
__privateListenTo as listenTo4,
|
|
4533
4343
|
commandEndEvent as commandEndEvent7
|
|
@@ -4628,7 +4438,7 @@ function resolveElementVersion2(container, widgetType) {
|
|
|
4628
4438
|
if (container.model?.config?.atomic) {
|
|
4629
4439
|
return "v4";
|
|
4630
4440
|
}
|
|
4631
|
-
if (widgetType &&
|
|
4441
|
+
if (widgetType && getWidgetsCache3()?.[widgetType]?.atomic_props_schema) {
|
|
4632
4442
|
return "v4";
|
|
4633
4443
|
}
|
|
4634
4444
|
return "v3";
|
|
@@ -4638,7 +4448,7 @@ function getElementProperties(container, widgetType) {
|
|
|
4638
4448
|
if (!settings || typeof settings !== "object") {
|
|
4639
4449
|
return null;
|
|
4640
4450
|
}
|
|
4641
|
-
const widgetConfig = widgetType ?
|
|
4451
|
+
const widgetConfig = widgetType ? getWidgetsCache3()?.[widgetType] : null;
|
|
4642
4452
|
const controls = widgetConfig?.controls;
|
|
4643
4453
|
const filtered = {};
|
|
4644
4454
|
for (const [key, value] of Object.entries(settings)) {
|
|
@@ -4681,7 +4491,7 @@ import {
|
|
|
4681
4491
|
createElement as createElement13,
|
|
4682
4492
|
deleteElement as deleteElement2,
|
|
4683
4493
|
getContainer as getContainer5,
|
|
4684
|
-
getWidgetsCache as
|
|
4494
|
+
getWidgetsCache as getWidgetsCache8
|
|
4685
4495
|
} from "@elementor/editor-elements";
|
|
4686
4496
|
import { dispatchMcpStylesAppliedEvent } from "@elementor/editor-mcp";
|
|
4687
4497
|
|
|
@@ -4691,18 +4501,18 @@ import {
|
|
|
4691
4501
|
deleteElement,
|
|
4692
4502
|
generateElementId as generateElementId2,
|
|
4693
4503
|
getContainer as getContainer4,
|
|
4694
|
-
getWidgetsCache as
|
|
4504
|
+
getWidgetsCache as getWidgetsCache6
|
|
4695
4505
|
} from "@elementor/editor-elements";
|
|
4696
4506
|
|
|
4697
4507
|
// src/mcp/utils/do-update-element-property.ts
|
|
4698
4508
|
import {
|
|
4699
4509
|
createElementStyle,
|
|
4700
4510
|
getElementStyles,
|
|
4701
|
-
getWidgetsCache as
|
|
4511
|
+
getWidgetsCache as getWidgetsCache5,
|
|
4702
4512
|
updateElementSettings,
|
|
4703
4513
|
updateElementStyle
|
|
4704
4514
|
} from "@elementor/editor-elements";
|
|
4705
|
-
import { getPropSchemaFromCache as getPropSchemaFromCache2, Schema
|
|
4515
|
+
import { getPropSchemaFromCache as getPropSchemaFromCache2, Schema } from "@elementor/editor-props";
|
|
4706
4516
|
import { getStylesSchema as getStylesSchema2, getVariantByMeta } from "@elementor/editor-styles";
|
|
4707
4517
|
import { __privateRunCommandSync as runCommandSync2 } from "@elementor/editor-v1-adapters";
|
|
4708
4518
|
|
|
@@ -4721,7 +4531,7 @@ var readStoredCustomCssText = (raw) => {
|
|
|
4721
4531
|
};
|
|
4722
4532
|
|
|
4723
4533
|
// src/mcp/utils/resolve-canonical-prop-name.ts
|
|
4724
|
-
import { getWidgetsCache as
|
|
4534
|
+
import { getWidgetsCache as getWidgetsCache4 } from "@elementor/editor-elements";
|
|
4725
4535
|
function buildAliasToCanonicalMap(schema2) {
|
|
4726
4536
|
const aliasToCanonical = {};
|
|
4727
4537
|
for (const [canonical, propType] of Object.entries(schema2)) {
|
|
@@ -4738,14 +4548,14 @@ function buildAliasToCanonicalMap(schema2) {
|
|
|
4738
4548
|
return aliasToCanonical;
|
|
4739
4549
|
}
|
|
4740
4550
|
function resolveCanonicalPropName(elementType, propertyName) {
|
|
4741
|
-
const schema2 =
|
|
4551
|
+
const schema2 = getWidgetsCache4()?.[elementType]?.atomic_props_schema;
|
|
4742
4552
|
if (!schema2 || schema2[propertyName]) {
|
|
4743
4553
|
return propertyName;
|
|
4744
4554
|
}
|
|
4745
4555
|
return buildAliasToCanonicalMap(schema2)[propertyName] ?? propertyName;
|
|
4746
4556
|
}
|
|
4747
4557
|
function resolveCanonicalPropKeys(elementType, props) {
|
|
4748
|
-
const schema2 =
|
|
4558
|
+
const schema2 = getWidgetsCache4()?.[elementType]?.atomic_props_schema;
|
|
4749
4559
|
if (!schema2) {
|
|
4750
4560
|
return { ...props };
|
|
4751
4561
|
}
|
|
@@ -4841,7 +4651,7 @@ var LOCAL_STYLE_META = {
|
|
|
4841
4651
|
};
|
|
4842
4652
|
function resolvePropValue(value, forceKey) {
|
|
4843
4653
|
const Utils = window.elementorV2.editorVariables.Utils;
|
|
4844
|
-
return
|
|
4654
|
+
return Schema.adjustLlmPropValueSchema(value, {
|
|
4845
4655
|
forceKey,
|
|
4846
4656
|
transformers: {
|
|
4847
4657
|
...Utils.globalVariablesLLMResolvers,
|
|
@@ -4939,7 +4749,7 @@ var doUpdateElementProperty = (params) => {
|
|
|
4939
4749
|
}
|
|
4940
4750
|
return;
|
|
4941
4751
|
}
|
|
4942
|
-
const elementPropSchema =
|
|
4752
|
+
const elementPropSchema = getWidgetsCache5()?.[elementType]?.atomic_props_schema;
|
|
4943
4753
|
if (!elementPropSchema) {
|
|
4944
4754
|
throw new Error(`No prop schema found for element type: ${elementType}`);
|
|
4945
4755
|
}
|
|
@@ -4953,7 +4763,7 @@ var doUpdateElementProperty = (params) => {
|
|
|
4953
4763
|
}
|
|
4954
4764
|
const propKey = elementPropSchema[propertyName].key;
|
|
4955
4765
|
const value = resolvePropValue(propertyValue, propKey);
|
|
4956
|
-
const { valid, jsonSchema } =
|
|
4766
|
+
const { valid, jsonSchema } = Schema.validatePropValue(elementPropSchema[propertyName], propertyValue);
|
|
4957
4767
|
if (!valid) {
|
|
4958
4768
|
throw new Error(
|
|
4959
4769
|
`Invalid PropValue for elementId: ${elementId}. PropKey: ${propKey}, PropValue: ${JSON.stringify(
|
|
@@ -4972,6 +4782,15 @@ Expected Schema: ${jsonSchema}`
|
|
|
4972
4782
|
runCommandSync2("document/save/set-is-modified", { status: true }, { internal: true });
|
|
4973
4783
|
};
|
|
4974
4784
|
|
|
4785
|
+
// src/composition-builder/utils/required-default-child-tags.ts
|
|
4786
|
+
function getRequiredDefaultChildTemplates(elementConfig) {
|
|
4787
|
+
const defaultChildren = elementConfig?.default_children;
|
|
4788
|
+
if (!Array.isArray(defaultChildren)) {
|
|
4789
|
+
return [];
|
|
4790
|
+
}
|
|
4791
|
+
return defaultChildren.filter((child) => child?.meta?.required ?? false);
|
|
4792
|
+
}
|
|
4793
|
+
|
|
4975
4794
|
// src/composition-builder/utils/required-children-enforcer.ts
|
|
4976
4795
|
var REQUIRED_CHILD_SCHEMA_HINT = "Use the widget schema resource; under llm_guidance.required_direct_children for V4 widgets.";
|
|
4977
4796
|
var RequiredChildrenEnforcer = class {
|
|
@@ -5022,7 +4841,7 @@ var CompositionBuilder = class _CompositionBuilder {
|
|
|
5022
4841
|
api = {
|
|
5023
4842
|
createElement: createElement12,
|
|
5024
4843
|
deleteElement,
|
|
5025
|
-
getWidgetsCache:
|
|
4844
|
+
getWidgetsCache: getWidgetsCache6,
|
|
5026
4845
|
generateElementId: generateElementId2,
|
|
5027
4846
|
getContainer: getContainer4,
|
|
5028
4847
|
doUpdateElementProperty
|
|
@@ -5275,6 +5094,27 @@ var trackCanvasEvent = (data) => {
|
|
|
5275
5094
|
trackEvent(data);
|
|
5276
5095
|
};
|
|
5277
5096
|
|
|
5097
|
+
// src/mcp/utils/element-data-util.ts
|
|
5098
|
+
import { getWidgetsCache as getWidgetsCache7 } from "@elementor/editor-elements";
|
|
5099
|
+
function hasV3Controls(controls) {
|
|
5100
|
+
return typeof controls === "object" && controls !== null && Object.keys(controls).length > 0;
|
|
5101
|
+
}
|
|
5102
|
+
function isWidgetAvailableForLLM(config) {
|
|
5103
|
+
if (!config) {
|
|
5104
|
+
return false;
|
|
5105
|
+
}
|
|
5106
|
+
if (config.meta?.llm_support === false) {
|
|
5107
|
+
return false;
|
|
5108
|
+
}
|
|
5109
|
+
if (config.title === "Component") {
|
|
5110
|
+
return false;
|
|
5111
|
+
}
|
|
5112
|
+
if (config.atomic_props_schema) {
|
|
5113
|
+
return true;
|
|
5114
|
+
}
|
|
5115
|
+
return hasV3Controls(config.controls);
|
|
5116
|
+
}
|
|
5117
|
+
|
|
5278
5118
|
// src/mcp/utils/get-composition-target-container.ts
|
|
5279
5119
|
import { COMPONENT_DOCUMENT_TYPE } from "@elementor/editor-documents";
|
|
5280
5120
|
function getCompositionTargetContainer(documentContainer, documentType) {
|
|
@@ -5557,7 +5397,7 @@ var initBuildCompositionsTool = (reg) => {
|
|
|
5557
5397
|
const { xmlStructure, elementConfig, stylesConfig } = adaptLeafRootParams({
|
|
5558
5398
|
...rawParams,
|
|
5559
5399
|
stylesConfig: convertedStyles,
|
|
5560
|
-
widgetsCache:
|
|
5400
|
+
widgetsCache: getWidgetsCache8() ?? {}
|
|
5561
5401
|
});
|
|
5562
5402
|
let generatedXML = "";
|
|
5563
5403
|
const errors = [];
|
|
@@ -5569,7 +5409,7 @@ var initBuildCompositionsTool = (reg) => {
|
|
|
5569
5409
|
const compositionBuilder = CompositionBuilder.fromXMLString(xmlStructure, {
|
|
5570
5410
|
createElement: createElement13,
|
|
5571
5411
|
deleteElement: deleteElement2,
|
|
5572
|
-
getWidgetsCache:
|
|
5412
|
+
getWidgetsCache: getWidgetsCache8
|
|
5573
5413
|
});
|
|
5574
5414
|
compositionBuilder.setElementConfig(elementConfig);
|
|
5575
5415
|
compositionBuilder.setStylesConfig(stylesConfig);
|
|
@@ -5670,7 +5510,7 @@ function assertCompositionXmlUsesV4WidgetsOnly(xmlStructure) {
|
|
|
5670
5510
|
if (doc.querySelector("parsererror")) {
|
|
5671
5511
|
throw new Error("Failed to parse XML string: " + doc);
|
|
5672
5512
|
}
|
|
5673
|
-
const widgetsCache =
|
|
5513
|
+
const widgetsCache = getWidgetsCache8() ?? {};
|
|
5674
5514
|
for (const node of doc.querySelectorAll("*")) {
|
|
5675
5515
|
const type = node.tagName;
|
|
5676
5516
|
const widgetData = widgetsCache[type];
|
|
@@ -5709,9 +5549,9 @@ function onElementAdded(element) {
|
|
|
5709
5549
|
}
|
|
5710
5550
|
|
|
5711
5551
|
// src/mcp/tools/configure-element/tool.ts
|
|
5712
|
-
import { getContainer as getContainer6, getWidgetsCache as
|
|
5552
|
+
import { getContainer as getContainer6, getWidgetsCache as getWidgetsCache9 } from "@elementor/editor-elements";
|
|
5713
5553
|
import { dispatchMcpStylesAppliedEvent as dispatchMcpStylesAppliedEvent2 } from "@elementor/editor-mcp";
|
|
5714
|
-
import { Schema as
|
|
5554
|
+
import { Schema as Schema2 } from "@elementor/editor-props";
|
|
5715
5555
|
|
|
5716
5556
|
// src/mcp/tools/configure-element/prompt.ts
|
|
5717
5557
|
import { toolPrompts as toolPrompts2 } from "@elementor/editor-mcp";
|
|
@@ -5878,7 +5718,7 @@ var initConfigureElementTool = (reg) => {
|
|
|
5878
5718
|
{ description: "Dynamic tags catalog", uri: DYNAMIC_TAGS_URI }
|
|
5879
5719
|
],
|
|
5880
5720
|
handler: async ({ elementId, propertiesToChange, elementType, style }) => {
|
|
5881
|
-
const widgetData =
|
|
5721
|
+
const widgetData = getWidgetsCache9()?.[elementType];
|
|
5882
5722
|
if (!widgetData) {
|
|
5883
5723
|
throw new Error(
|
|
5884
5724
|
`Unknown element type: ${elementType}. Check the available-widgets resource for valid types.`
|
|
@@ -5900,7 +5740,7 @@ var initConfigureElementTool = (reg) => {
|
|
|
5900
5740
|
const propertiesToUpdate = resolveCanonicalPropKeys(elementType, propertiesToChange);
|
|
5901
5741
|
const toUpdate = Object.entries(propertiesToUpdate);
|
|
5902
5742
|
for (const [propertyName, propertyValue] of toUpdate) {
|
|
5903
|
-
if (!
|
|
5743
|
+
if (!Schema2.isPropKeyConfigurable(propertyName)) {
|
|
5904
5744
|
throw new Error(`Not allowed to update ${propertyName}`);
|
|
5905
5745
|
}
|
|
5906
5746
|
try {
|
|
@@ -5977,9 +5817,9 @@ Provide styling as raw CSS via the "style" parameter (a flat map of CSS property
|
|
|
5977
5817
|
|
|
5978
5818
|
// src/mcp/tools/create-element/tool.ts
|
|
5979
5819
|
import { getCurrentDocument as getCurrentDocument2 } from "@elementor/editor-documents";
|
|
5980
|
-
import { httpService as
|
|
5820
|
+
import { httpService as httpService6 } from "@elementor/http-client";
|
|
5981
5821
|
import { z as z3 } from "@elementor/schema";
|
|
5982
|
-
var
|
|
5822
|
+
var MCP_PROXY_URL5 = "elementor/v1/mcp-proxy";
|
|
5983
5823
|
var initCreateElementTool = (reg) => {
|
|
5984
5824
|
const { addTool } = reg;
|
|
5985
5825
|
addTool({
|
|
@@ -5999,7 +5839,7 @@ var initCreateElementTool = (reg) => {
|
|
|
5999
5839
|
if (!document2?.id) {
|
|
6000
5840
|
throw new Error("No active document found.");
|
|
6001
5841
|
}
|
|
6002
|
-
const { data } = await
|
|
5842
|
+
const { data } = await httpService6().post(MCP_PROXY_URL5, {
|
|
6003
5843
|
tool: "create-element",
|
|
6004
5844
|
input: {
|
|
6005
5845
|
parent_id: parentId ?? "document",
|
|
@@ -6017,8 +5857,8 @@ var initCreateElementTool = (reg) => {
|
|
|
6017
5857
|
};
|
|
6018
5858
|
|
|
6019
5859
|
// src/mcp/tools/get-element-config/tool.ts
|
|
6020
|
-
import { getContainer as getContainer7, getElementStyles as getElementStyles2, getWidgetsCache as
|
|
6021
|
-
import { Schema as
|
|
5860
|
+
import { getContainer as getContainer7, getElementStyles as getElementStyles2, getWidgetsCache as getWidgetsCache10 } from "@elementor/editor-elements";
|
|
5861
|
+
import { Schema as Schema3 } from "@elementor/editor-props";
|
|
6022
5862
|
import { z as z4 } from "@elementor/schema";
|
|
6023
5863
|
var schema = {
|
|
6024
5864
|
elementId: z4.string()
|
|
@@ -6057,7 +5897,7 @@ var initGetElementConfigTool = (reg) => {
|
|
|
6057
5897
|
throw new Error(`Element with ID ${elementId} not found.`);
|
|
6058
5898
|
}
|
|
6059
5899
|
const elementType = element.model.get("widgetType") || element.model.get("elType") || "";
|
|
6060
|
-
const widgetData =
|
|
5900
|
+
const widgetData = getWidgetsCache10()?.[elementType];
|
|
6061
5901
|
if (!widgetData) {
|
|
6062
5902
|
throw new Error(
|
|
6063
5903
|
`Unknown element type: ${elementType}. Check the available-widgets resource for valid types.`
|
|
@@ -6069,13 +5909,13 @@ var initGetElementConfigTool = (reg) => {
|
|
|
6069
5909
|
);
|
|
6070
5910
|
}
|
|
6071
5911
|
const elementRawSettings = element.settings;
|
|
6072
|
-
const propSchema =
|
|
5912
|
+
const propSchema = getWidgetsCache10()?.[elementType]?.atomic_props_schema;
|
|
6073
5913
|
if (!elementRawSettings || !propSchema) {
|
|
6074
5914
|
throw new Error(`No settings or prop schema found for element ID: ${elementId}`);
|
|
6075
5915
|
}
|
|
6076
5916
|
const propValues = {};
|
|
6077
5917
|
const stylePropValues = {};
|
|
6078
|
-
|
|
5918
|
+
Schema3.configurableKeys(propSchema).forEach((key) => {
|
|
6079
5919
|
propValues[key] = structuredClone(elementRawSettings.get(key));
|
|
6080
5920
|
});
|
|
6081
5921
|
const elementStyles = getElementStyles2(elementId) || {};
|
|
@@ -6111,7 +5951,7 @@ var initGetElementConfigTool = (reg) => {
|
|
|
6111
5951
|
|
|
6112
5952
|
// src/mcp/canvas-mcp.ts
|
|
6113
5953
|
var initCanvasMcp = (reg) => {
|
|
6114
|
-
|
|
5954
|
+
Schema4.setDynamicTagNamesResolver(getDynamicTagNamesByCategories);
|
|
6115
5955
|
initWidgetsSchemaResource(reg);
|
|
6116
5956
|
initAvailableWidgetsResource(reg);
|
|
6117
5957
|
initDocumentStructureResource(reg);
|
|
@@ -6332,7 +6172,7 @@ import {
|
|
|
6332
6172
|
} from "@elementor/editor-v1-adapters";
|
|
6333
6173
|
|
|
6334
6174
|
// src/utils/command-utils.ts
|
|
6335
|
-
import { getElementLabel as getElementLabel2, getWidgetsCache as
|
|
6175
|
+
import { getElementLabel as getElementLabel2, getWidgetsCache as getWidgetsCache11 } from "@elementor/editor-elements";
|
|
6336
6176
|
import { CLASSES_PROP_KEY } from "@elementor/editor-props";
|
|
6337
6177
|
import { __ as __5 } from "@wordpress/i18n";
|
|
6338
6178
|
function hasAtomicWidgets(args) {
|
|
@@ -6357,7 +6197,7 @@ function getClassesProp(container) {
|
|
|
6357
6197
|
}
|
|
6358
6198
|
function getContainerSchema(container) {
|
|
6359
6199
|
const type = container?.model.get("widgetType") || container?.model.get("elType");
|
|
6360
|
-
const widgetsCache =
|
|
6200
|
+
const widgetsCache = getWidgetsCache11();
|
|
6361
6201
|
const elementType = widgetsCache?.[type];
|
|
6362
6202
|
return elementType?.atomic_props_schema ?? null;
|
|
6363
6203
|
}
|