@elementor/editor-elements 3.35.0-325 → 3.35.0-327
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 +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +6 -617
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -616
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
- package/src/index.ts +0 -2
- package/src/link-restriction.ts +8 -10
- package/src/mcp/elements-tool.ts +0 -345
- package/src/mcp/handlers/common-style-utils.ts +0 -23
- package/src/mcp/handlers/create-element.ts +0 -96
- package/src/mcp/handlers/create-style.ts +0 -42
- package/src/mcp/handlers/delete-element.ts +0 -17
- package/src/mcp/handlers/delete-style.ts +0 -22
- package/src/mcp/handlers/deselect-element.ts +0 -21
- package/src/mcp/handlers/duplicate-element.ts +0 -22
- package/src/mcp/handlers/get-element-props.ts +0 -28
- package/src/mcp/handlers/get-element-schema.ts +0 -17
- package/src/mcp/handlers/get-selected.ts +0 -5
- package/src/mcp/handlers/get-styles.ts +0 -26
- package/src/mcp/handlers/list-available-types.ts +0 -27
- package/src/mcp/handlers/move-element.ts +0 -30
- package/src/mcp/handlers/select-element.ts +0 -25
- package/src/mcp/handlers/update-props.ts +0 -22
- package/src/mcp/handlers/update-styles.ts +0 -45
- package/src/mcp/index.ts +0 -9
package/dist/index.js
CHANGED
|
@@ -46,7 +46,6 @@ __export(index_exports, {
|
|
|
46
46
|
getLinkInLinkRestriction: () => getLinkInLinkRestriction,
|
|
47
47
|
getSelectedElements: () => getSelectedElements,
|
|
48
48
|
getWidgetsCache: () => getWidgetsCache,
|
|
49
|
-
initElementsMcp: () => initMcp,
|
|
50
49
|
isElementAnchored: () => isElementAnchored,
|
|
51
50
|
moveElement: () => moveElement,
|
|
52
51
|
moveElements: () => moveElements,
|
|
@@ -788,6 +787,7 @@ var updateElementSettings = ({ id, props, withHistory = true }) => {
|
|
|
788
787
|
};
|
|
789
788
|
|
|
790
789
|
// src/link-restriction.ts
|
|
790
|
+
var ANCHOR_SELECTOR = "a, [data-action-link]";
|
|
791
791
|
function getLinkInLinkRestriction(elementId) {
|
|
792
792
|
const anchoredDescendantId = getAnchoredDescendantId(elementId);
|
|
793
793
|
if (anchoredDescendantId) {
|
|
@@ -814,7 +814,7 @@ function getAnchoredDescendantId(elementId) {
|
|
|
814
814
|
if (!element) {
|
|
815
815
|
return null;
|
|
816
816
|
}
|
|
817
|
-
for (const childAnchorElement of Array.from(element.querySelectorAll(
|
|
817
|
+
for (const childAnchorElement of Array.from(element.querySelectorAll(ANCHOR_SELECTOR))) {
|
|
818
818
|
const childElementId = findElementIdOf(childAnchorElement);
|
|
819
819
|
if (childElementId !== elementId) {
|
|
820
820
|
return childElementId;
|
|
@@ -827,7 +827,7 @@ function getAnchoredAncestorId(elementId) {
|
|
|
827
827
|
if (!element || element.parentElement === null) {
|
|
828
828
|
return null;
|
|
829
829
|
}
|
|
830
|
-
const parentAnchor = element.parentElement.closest(
|
|
830
|
+
const parentAnchor = element.parentElement.closest(ANCHOR_SELECTOR);
|
|
831
831
|
return parentAnchor ? findElementIdOf(parentAnchor) : null;
|
|
832
832
|
}
|
|
833
833
|
function isElementAnchored(elementId) {
|
|
@@ -835,17 +835,17 @@ function isElementAnchored(elementId) {
|
|
|
835
835
|
if (!element) {
|
|
836
836
|
return false;
|
|
837
837
|
}
|
|
838
|
-
if (
|
|
838
|
+
if (element.matches(ANCHOR_SELECTOR)) {
|
|
839
839
|
return true;
|
|
840
840
|
}
|
|
841
841
|
return doesElementContainAnchor(element);
|
|
842
842
|
}
|
|
843
843
|
function doesElementContainAnchor(element) {
|
|
844
|
-
for (const child of element.children) {
|
|
844
|
+
for (const child of Array.from(element.children)) {
|
|
845
845
|
if (isElementorElement(child)) {
|
|
846
846
|
continue;
|
|
847
847
|
}
|
|
848
|
-
if (
|
|
848
|
+
if (child.matches(ANCHOR_SELECTOR)) {
|
|
849
849
|
return true;
|
|
850
850
|
}
|
|
851
851
|
if (doesElementContainAnchor(child)) {
|
|
@@ -864,9 +864,6 @@ function getElementDOM(id) {
|
|
|
864
864
|
return null;
|
|
865
865
|
}
|
|
866
866
|
}
|
|
867
|
-
function isAnchorTag(tagName) {
|
|
868
|
-
return tagName.toLowerCase() === "a";
|
|
869
|
-
}
|
|
870
867
|
function isElementorElement(element) {
|
|
871
868
|
return element.hasAttribute("data-id");
|
|
872
869
|
}
|
|
@@ -1076,613 +1073,6 @@ var playElementInteractions = (elementId, animationId) => {
|
|
|
1076
1073
|
function setDocumentModifiedStatus2(status) {
|
|
1077
1074
|
(0, import_editor_v1_adapters19.__privateRunCommandSync)("document/save/set-is-modified", { status }, { internal: true });
|
|
1078
1075
|
}
|
|
1079
|
-
|
|
1080
|
-
// src/mcp/index.ts
|
|
1081
|
-
var import_editor_mcp2 = require("@elementor/editor-mcp");
|
|
1082
|
-
|
|
1083
|
-
// src/mcp/elements-tool.ts
|
|
1084
|
-
var import_editor_mcp = require("@elementor/editor-mcp");
|
|
1085
|
-
var import_schema = require("@elementor/schema");
|
|
1086
|
-
|
|
1087
|
-
// src/mcp/handlers/create-element.ts
|
|
1088
|
-
function handleCreateElement({
|
|
1089
|
-
elementType,
|
|
1090
|
-
containerId,
|
|
1091
|
-
props = {},
|
|
1092
|
-
styles
|
|
1093
|
-
}) {
|
|
1094
|
-
let container = containerId === "document" ? getCurrentDocumentContainer() : getContainer(containerId);
|
|
1095
|
-
if (!container) {
|
|
1096
|
-
if (containerId === "document") {
|
|
1097
|
-
throw new Error("Document container not found. Please ensure the editor is initialized.");
|
|
1098
|
-
}
|
|
1099
|
-
throw new Error(`Container with ID "${containerId}" not found`);
|
|
1100
|
-
}
|
|
1101
|
-
const containerElType = container.model.get("elType");
|
|
1102
|
-
const isDocument = container.id === "document" || containerElType === "document";
|
|
1103
|
-
if (isDocument) {
|
|
1104
|
-
const containerModel = {
|
|
1105
|
-
elType: "e-div-block"
|
|
1106
|
-
};
|
|
1107
|
-
const createdContainer = createElement({
|
|
1108
|
-
containerId: container.id,
|
|
1109
|
-
model: containerModel,
|
|
1110
|
-
options: { useHistory: true }
|
|
1111
|
-
});
|
|
1112
|
-
createElementStyle({
|
|
1113
|
-
elementId: createdContainer.id,
|
|
1114
|
-
classesProp: "classes",
|
|
1115
|
-
label: "local",
|
|
1116
|
-
meta: { breakpoint: "desktop", state: null },
|
|
1117
|
-
props: {
|
|
1118
|
-
display: { $$type: "string", value: "flex" },
|
|
1119
|
-
"flex-direction": { $$type: "string", value: "row" },
|
|
1120
|
-
"flex-wrap": { $$type: "string", value: "wrap" }
|
|
1121
|
-
}
|
|
1122
|
-
});
|
|
1123
|
-
container = getContainer(createdContainer.id);
|
|
1124
|
-
if (!container) {
|
|
1125
|
-
throw new Error("Failed to create container for widget. Cannot create widgets directly in the document.");
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
const actualContainerId = container.id;
|
|
1129
|
-
const elementTypeData = getElementType(elementType);
|
|
1130
|
-
if (!elementTypeData) {
|
|
1131
|
-
throw new Error(`Element type "${elementType}" not found or is not atomic`);
|
|
1132
|
-
}
|
|
1133
|
-
const model = {
|
|
1134
|
-
widgetType: elementType,
|
|
1135
|
-
elType: "widget",
|
|
1136
|
-
settings: props
|
|
1137
|
-
};
|
|
1138
|
-
const createdElement = createElement({
|
|
1139
|
-
containerId: actualContainerId,
|
|
1140
|
-
model,
|
|
1141
|
-
options: { useHistory: true }
|
|
1142
|
-
});
|
|
1143
|
-
if (styles) {
|
|
1144
|
-
createElementStyle({
|
|
1145
|
-
elementId: createdElement.id,
|
|
1146
|
-
classesProp: "classes",
|
|
1147
|
-
label: "local",
|
|
1148
|
-
meta: { breakpoint: "desktop", state: null },
|
|
1149
|
-
props: styles
|
|
1150
|
-
});
|
|
1151
|
-
}
|
|
1152
|
-
return {
|
|
1153
|
-
elementId: createdElement.id,
|
|
1154
|
-
type: elementType
|
|
1155
|
-
};
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
// src/mcp/handlers/common-style-utils.ts
|
|
1159
|
-
var VALID_BREAKPOINTS = [
|
|
1160
|
-
"widescreen",
|
|
1161
|
-
"desktop",
|
|
1162
|
-
"laptop",
|
|
1163
|
-
"tablet_extra",
|
|
1164
|
-
"tablet",
|
|
1165
|
-
"mobile_extra",
|
|
1166
|
-
"mobile"
|
|
1167
|
-
];
|
|
1168
|
-
function resolveBreakpointId(breakpoint) {
|
|
1169
|
-
if (breakpoint === null) {
|
|
1170
|
-
return null;
|
|
1171
|
-
}
|
|
1172
|
-
if (VALID_BREAKPOINTS.includes(breakpoint)) {
|
|
1173
|
-
return breakpoint;
|
|
1174
|
-
}
|
|
1175
|
-
return "desktop";
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
// src/mcp/handlers/create-style.ts
|
|
1179
|
-
function handleCreateStyle({
|
|
1180
|
-
elementId,
|
|
1181
|
-
styleId,
|
|
1182
|
-
classesProp = "classes",
|
|
1183
|
-
label = "local",
|
|
1184
|
-
styles,
|
|
1185
|
-
breakpoint = "desktop",
|
|
1186
|
-
state = null,
|
|
1187
|
-
customCss = null
|
|
1188
|
-
}) {
|
|
1189
|
-
const resolvedBreakpoint = resolveBreakpointId(breakpoint);
|
|
1190
|
-
const resolvedState = state === null || state === void 0 ? null : state;
|
|
1191
|
-
const createdStyleId = createElementStyle({
|
|
1192
|
-
styleId,
|
|
1193
|
-
elementId,
|
|
1194
|
-
classesProp,
|
|
1195
|
-
label,
|
|
1196
|
-
meta: { breakpoint: resolvedBreakpoint, state: resolvedState },
|
|
1197
|
-
props: styles,
|
|
1198
|
-
custom_css: customCss
|
|
1199
|
-
});
|
|
1200
|
-
return { styleId: createdStyleId };
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
// src/mcp/handlers/delete-element.ts
|
|
1204
|
-
function handleDeleteElement(elementId) {
|
|
1205
|
-
const container = getContainer(elementId);
|
|
1206
|
-
if (!container) {
|
|
1207
|
-
throw new Error(`Element with ID "${elementId}" not found`);
|
|
1208
|
-
}
|
|
1209
|
-
deleteElement({
|
|
1210
|
-
elementId,
|
|
1211
|
-
options: { useHistory: true }
|
|
1212
|
-
});
|
|
1213
|
-
return { success: true };
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
// src/mcp/handlers/delete-style.ts
|
|
1217
|
-
function handleDeleteStyle({ elementId, styleId }) {
|
|
1218
|
-
const elementStyles = getElementStyles(elementId);
|
|
1219
|
-
if (!elementStyles) {
|
|
1220
|
-
throw new Error(`Element with ID "${elementId}" has no styles.`);
|
|
1221
|
-
}
|
|
1222
|
-
const resolvedStyleId = styleId || Object.keys(elementStyles)[0];
|
|
1223
|
-
if (!resolvedStyleId) {
|
|
1224
|
-
throw new Error(`Element with ID "${elementId}" has no styles to delete.`);
|
|
1225
|
-
}
|
|
1226
|
-
deleteElementStyle(elementId, resolvedStyleId);
|
|
1227
|
-
return { success: true };
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
// src/mcp/handlers/deselect-element.ts
|
|
1231
|
-
var import_editor_v1_adapters20 = require("@elementor/editor-v1-adapters");
|
|
1232
|
-
function handleDeselectElement(elementId) {
|
|
1233
|
-
const container = getContainer(elementId);
|
|
1234
|
-
if (!container) {
|
|
1235
|
-
throw new Error(`Element with ID "${elementId}" not found`);
|
|
1236
|
-
}
|
|
1237
|
-
(0, import_editor_v1_adapters20.__privateRunCommand)("document/elements/deselect", { container });
|
|
1238
|
-
return { success: true };
|
|
1239
|
-
}
|
|
1240
|
-
function handleDeselectAllElements() {
|
|
1241
|
-
(0, import_editor_v1_adapters20.__privateRunCommand)("document/elements/deselect-all", {});
|
|
1242
|
-
return { success: true };
|
|
1243
|
-
}
|
|
1244
|
-
|
|
1245
|
-
// src/mcp/handlers/duplicate-element.ts
|
|
1246
|
-
function handleDuplicateElement(elementId) {
|
|
1247
|
-
const container = getContainer(elementId);
|
|
1248
|
-
if (!container) {
|
|
1249
|
-
throw new Error(`Element with ID "${elementId}" not found`);
|
|
1250
|
-
}
|
|
1251
|
-
const duplicatedElement = duplicateElement({
|
|
1252
|
-
elementId,
|
|
1253
|
-
options: { useHistory: true }
|
|
1254
|
-
});
|
|
1255
|
-
const type = duplicatedElement.model.get("widgetType") || duplicatedElement.model.get("elType") || "";
|
|
1256
|
-
return {
|
|
1257
|
-
elementId: duplicatedElement.id,
|
|
1258
|
-
type
|
|
1259
|
-
};
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
|
-
// src/mcp/handlers/get-element-props.ts
|
|
1263
|
-
function handleGetElementProps(elementId) {
|
|
1264
|
-
const container = getContainer(elementId);
|
|
1265
|
-
if (!container) {
|
|
1266
|
-
throw new Error(`Element with ID "${elementId}" not found`);
|
|
1267
|
-
}
|
|
1268
|
-
const type = container.model.get("widgetType") || container.model.get("elType");
|
|
1269
|
-
if (!type) {
|
|
1270
|
-
throw new Error(`Element with ID "${elementId}" has no type`);
|
|
1271
|
-
}
|
|
1272
|
-
const elementType = getElementType(type);
|
|
1273
|
-
if (!elementType) {
|
|
1274
|
-
throw new Error(`Element type "${type}" is not atomic`);
|
|
1275
|
-
}
|
|
1276
|
-
const propsSchema = elementType.propsSchema;
|
|
1277
|
-
const propKeys = Object.keys(propsSchema);
|
|
1278
|
-
return getElementSettings(elementId, propKeys);
|
|
1279
|
-
}
|
|
1280
|
-
|
|
1281
|
-
// src/mcp/handlers/get-element-schema.ts
|
|
1282
|
-
var import_editor_styles3 = require("@elementor/editor-styles");
|
|
1283
|
-
function handleGetElementSchema(elementType) {
|
|
1284
|
-
const elementTypeData = getElementType(elementType);
|
|
1285
|
-
if (!elementTypeData) {
|
|
1286
|
-
throw new Error(`Element type "${elementType}" not found or is not atomic`);
|
|
1287
|
-
}
|
|
1288
|
-
return { ...elementTypeData, stylesSchema: (0, import_editor_styles3.getStylesSchema)() };
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
// src/mcp/handlers/get-selected.ts
|
|
1292
|
-
function handleGetSelected() {
|
|
1293
|
-
return getSelectedElements();
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
// src/mcp/handlers/get-styles.ts
|
|
1297
|
-
function handleGetStyles(elementId) {
|
|
1298
|
-
const styles = getElementStyles(elementId);
|
|
1299
|
-
if (!styles) {
|
|
1300
|
-
return null;
|
|
1301
|
-
}
|
|
1302
|
-
return Object.fromEntries(
|
|
1303
|
-
Object.entries(styles).map(([id, style]) => [
|
|
1304
|
-
id,
|
|
1305
|
-
{
|
|
1306
|
-
id: style.id,
|
|
1307
|
-
label: style.label,
|
|
1308
|
-
type: style.type,
|
|
1309
|
-
variants: style.variants.map((variant) => ({
|
|
1310
|
-
meta: variant.meta,
|
|
1311
|
-
props: variant.props,
|
|
1312
|
-
custom_css: variant.custom_css
|
|
1313
|
-
}))
|
|
1314
|
-
}
|
|
1315
|
-
])
|
|
1316
|
-
);
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
|
-
// src/mcp/handlers/list-available-types.ts
|
|
1320
|
-
function handleListAvailableTypes() {
|
|
1321
|
-
const widgetsCache = getWidgetsCache();
|
|
1322
|
-
if (!widgetsCache) {
|
|
1323
|
-
return [];
|
|
1324
|
-
}
|
|
1325
|
-
const availableTypes = [];
|
|
1326
|
-
Object.entries(widgetsCache).forEach(([type, config]) => {
|
|
1327
|
-
if (config?.atomic_controls && config?.atomic_props_schema) {
|
|
1328
|
-
availableTypes.push({
|
|
1329
|
-
type,
|
|
1330
|
-
title: config.title || type
|
|
1331
|
-
});
|
|
1332
|
-
}
|
|
1333
|
-
});
|
|
1334
|
-
return availableTypes;
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
// src/mcp/handlers/move-element.ts
|
|
1338
|
-
function handleMoveElement({
|
|
1339
|
-
elementId,
|
|
1340
|
-
targetContainerId
|
|
1341
|
-
}) {
|
|
1342
|
-
const container = getContainer(elementId);
|
|
1343
|
-
if (!container) {
|
|
1344
|
-
throw new Error(`Element with ID "${elementId}" not found`);
|
|
1345
|
-
}
|
|
1346
|
-
const targetContainer = getContainer(targetContainerId);
|
|
1347
|
-
if (!targetContainer) {
|
|
1348
|
-
throw new Error(`Target container with ID "${targetContainerId}" not found`);
|
|
1349
|
-
}
|
|
1350
|
-
moveElement({
|
|
1351
|
-
elementId,
|
|
1352
|
-
targetContainerId,
|
|
1353
|
-
options: { useHistory: true }
|
|
1354
|
-
});
|
|
1355
|
-
return { success: true };
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
// src/mcp/handlers/select-element.ts
|
|
1359
|
-
function handleSelectElement(elementId) {
|
|
1360
|
-
const container = getContainer(elementId);
|
|
1361
|
-
if (!container) {
|
|
1362
|
-
throw new Error(`Element with ID "${elementId}" not found`);
|
|
1363
|
-
}
|
|
1364
|
-
selectElement(elementId);
|
|
1365
|
-
return { success: true };
|
|
1366
|
-
}
|
|
1367
|
-
function handleSelectMultipleElements(elementIds) {
|
|
1368
|
-
elementIds.forEach((elementId) => {
|
|
1369
|
-
const container = getContainer(elementId);
|
|
1370
|
-
if (container) {
|
|
1371
|
-
selectElement(elementId);
|
|
1372
|
-
}
|
|
1373
|
-
});
|
|
1374
|
-
return { success: true };
|
|
1375
|
-
}
|
|
1376
|
-
|
|
1377
|
-
// src/mcp/handlers/update-props.ts
|
|
1378
|
-
function handleUpdateProps({ elementId, props }) {
|
|
1379
|
-
const container = getContainer(elementId);
|
|
1380
|
-
if (!container) {
|
|
1381
|
-
throw new Error(`Element with ID "${elementId}" not found`);
|
|
1382
|
-
}
|
|
1383
|
-
updateElementSettings({
|
|
1384
|
-
id: elementId,
|
|
1385
|
-
props,
|
|
1386
|
-
withHistory: true
|
|
1387
|
-
});
|
|
1388
|
-
return { success: true };
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1391
|
-
// src/mcp/handlers/update-styles.ts
|
|
1392
|
-
function handleUpdateStyles({
|
|
1393
|
-
elementId,
|
|
1394
|
-
styleId,
|
|
1395
|
-
styles,
|
|
1396
|
-
breakpoint = "desktop",
|
|
1397
|
-
state = null
|
|
1398
|
-
}) {
|
|
1399
|
-
const resolvedBreakpoint = resolveBreakpointId(breakpoint);
|
|
1400
|
-
const resolvedState = state === null || state === void 0 ? null : state;
|
|
1401
|
-
const elementStyles = getElementStyles(elementId);
|
|
1402
|
-
if (!elementStyles) {
|
|
1403
|
-
throw new Error(`Element with ID "${elementId}" has no styles. Create a style first.`);
|
|
1404
|
-
}
|
|
1405
|
-
const resolvedStyleId = styleId || Object.keys(elementStyles)[0];
|
|
1406
|
-
if (!resolvedStyleId) {
|
|
1407
|
-
throw new Error(`Element with ID "${elementId}" has no styles. Create a style first.`);
|
|
1408
|
-
}
|
|
1409
|
-
updateElementStyle({
|
|
1410
|
-
elementId,
|
|
1411
|
-
styleId: resolvedStyleId,
|
|
1412
|
-
meta: { breakpoint: resolvedBreakpoint, state: resolvedState },
|
|
1413
|
-
props: styles
|
|
1414
|
-
});
|
|
1415
|
-
return { success: true };
|
|
1416
|
-
}
|
|
1417
|
-
|
|
1418
|
-
// src/mcp/elements-tool.ts
|
|
1419
|
-
var actionEnum = import_schema.z.enum([
|
|
1420
|
-
"get-element-schema",
|
|
1421
|
-
"get-element-props",
|
|
1422
|
-
"create-element",
|
|
1423
|
-
"update-props",
|
|
1424
|
-
"create-style",
|
|
1425
|
-
"get-styles",
|
|
1426
|
-
"update-styles",
|
|
1427
|
-
"delete-style",
|
|
1428
|
-
"delete",
|
|
1429
|
-
"duplicate",
|
|
1430
|
-
"move",
|
|
1431
|
-
"select",
|
|
1432
|
-
"deselect",
|
|
1433
|
-
"deselect-all",
|
|
1434
|
-
"get-selected",
|
|
1435
|
-
"list-available-types"
|
|
1436
|
-
]);
|
|
1437
|
-
var schema = {
|
|
1438
|
-
action: actionEnum.describe("The element operation to perform."),
|
|
1439
|
-
elementId: import_schema.z.string().optional().describe("The ID of the target element"),
|
|
1440
|
-
elementIds: import_schema.z.array(import_schema.z.string()).optional().describe("Array of element IDs for multi-element operations"),
|
|
1441
|
-
elementType: import_schema.z.string().optional().describe(
|
|
1442
|
-
"The type of element to create. Must be an atomic element type (required for create-element and get-element-schema actions)"
|
|
1443
|
-
),
|
|
1444
|
-
props: import_schema.z.record(import_schema.z.any()).optional().describe("Props object for creating or updating an element. Must match the element type's propsSchema."),
|
|
1445
|
-
containerId: import_schema.z.string().optional().describe(
|
|
1446
|
-
'Parent container ID for element creation or move operations. Use "document" if parent is the document root.'
|
|
1447
|
-
),
|
|
1448
|
-
targetContainerId: import_schema.z.string().optional().describe("Target container ID for move operations"),
|
|
1449
|
-
styles: import_schema.z.record(import_schema.z.any()).optional().describe(
|
|
1450
|
-
"Styles object for creating or updating element styles. Must match the element type's stylesSchema."
|
|
1451
|
-
),
|
|
1452
|
-
styleId: import_schema.z.string().optional().describe(
|
|
1453
|
-
"Style definition ID for style operations. If not provided, the first available style will be used (for update/delete)."
|
|
1454
|
-
),
|
|
1455
|
-
breakpoint: import_schema.z.string().optional().describe('Breakpoint for style operations (e.g., "desktop", "tablet", "mobile"). Defaults to "desktop".'),
|
|
1456
|
-
state: import_schema.z.string().optional().describe('State for style operations (e.g., "hover", "active", or null). Defaults to null.'),
|
|
1457
|
-
classesProp: import_schema.z.string().optional().describe('Classes property name for create-style action. Defaults to "classes".'),
|
|
1458
|
-
label: import_schema.z.string().optional().describe('Label for create-style action. Defaults to "local".'),
|
|
1459
|
-
custom_css: import_schema.z.object({ raw: import_schema.z.string() }).optional().describe("Custom CSS object with raw CSS string for create-style action.")
|
|
1460
|
-
};
|
|
1461
|
-
function routeAction(params) {
|
|
1462
|
-
try {
|
|
1463
|
-
switch (params.action) {
|
|
1464
|
-
case "get-element-schema":
|
|
1465
|
-
if (!params.elementType) {
|
|
1466
|
-
throw new Error("elementType is required for get-element-schema action");
|
|
1467
|
-
}
|
|
1468
|
-
return handleGetElementSchema(params.elementType);
|
|
1469
|
-
case "get-element-props":
|
|
1470
|
-
if (!params.elementId) {
|
|
1471
|
-
throw new Error("elementId is required for get-element-props action");
|
|
1472
|
-
}
|
|
1473
|
-
return handleGetElementProps(params.elementId);
|
|
1474
|
-
case "create-element":
|
|
1475
|
-
if (!params.elementType) {
|
|
1476
|
-
throw new Error("elementType is required for create-element action");
|
|
1477
|
-
}
|
|
1478
|
-
if (!params.containerId) {
|
|
1479
|
-
throw new Error("containerId is required for create-element action");
|
|
1480
|
-
}
|
|
1481
|
-
return handleCreateElement({
|
|
1482
|
-
elementType: params.elementType,
|
|
1483
|
-
containerId: params.containerId,
|
|
1484
|
-
props: params.props,
|
|
1485
|
-
styles: params.styles
|
|
1486
|
-
});
|
|
1487
|
-
case "update-props":
|
|
1488
|
-
if (!params.elementId) {
|
|
1489
|
-
throw new Error("elementId is required for update-props action");
|
|
1490
|
-
}
|
|
1491
|
-
if (!params.props) {
|
|
1492
|
-
throw new Error("props is required for update-props action");
|
|
1493
|
-
}
|
|
1494
|
-
return handleUpdateProps({
|
|
1495
|
-
elementId: params.elementId,
|
|
1496
|
-
props: params.props
|
|
1497
|
-
});
|
|
1498
|
-
case "create-style":
|
|
1499
|
-
if (!params.elementId) {
|
|
1500
|
-
throw new Error("elementId is required for create-style action");
|
|
1501
|
-
}
|
|
1502
|
-
if (!params.styles) {
|
|
1503
|
-
throw new Error("styles is required for create-style action");
|
|
1504
|
-
}
|
|
1505
|
-
return handleCreateStyle({
|
|
1506
|
-
elementId: params.elementId,
|
|
1507
|
-
styleId: params.styleId,
|
|
1508
|
-
classesProp: params.classesProp,
|
|
1509
|
-
label: params.label,
|
|
1510
|
-
styles: params.styles,
|
|
1511
|
-
breakpoint: params.breakpoint,
|
|
1512
|
-
state: params.state,
|
|
1513
|
-
customCss: params.custom_css
|
|
1514
|
-
});
|
|
1515
|
-
case "get-styles":
|
|
1516
|
-
if (!params.elementId) {
|
|
1517
|
-
throw new Error("elementId is required for get-styles action");
|
|
1518
|
-
}
|
|
1519
|
-
return handleGetStyles(params.elementId);
|
|
1520
|
-
case "update-styles":
|
|
1521
|
-
if (!params.elementId) {
|
|
1522
|
-
throw new Error("elementId is required for update-styles action");
|
|
1523
|
-
}
|
|
1524
|
-
if (!params.styles) {
|
|
1525
|
-
throw new Error("styles is required for update-styles action");
|
|
1526
|
-
}
|
|
1527
|
-
return handleUpdateStyles({
|
|
1528
|
-
elementId: params.elementId,
|
|
1529
|
-
styleId: params.styleId,
|
|
1530
|
-
styles: params.styles,
|
|
1531
|
-
breakpoint: params.breakpoint,
|
|
1532
|
-
state: params.state
|
|
1533
|
-
});
|
|
1534
|
-
case "delete-style":
|
|
1535
|
-
if (!params.elementId) {
|
|
1536
|
-
throw new Error("elementId is required for delete-style action");
|
|
1537
|
-
}
|
|
1538
|
-
return handleDeleteStyle({
|
|
1539
|
-
elementId: params.elementId,
|
|
1540
|
-
styleId: params.styleId
|
|
1541
|
-
});
|
|
1542
|
-
case "delete":
|
|
1543
|
-
if (!params.elementId) {
|
|
1544
|
-
throw new Error("elementId is required for delete action");
|
|
1545
|
-
}
|
|
1546
|
-
return handleDeleteElement(params.elementId);
|
|
1547
|
-
case "duplicate":
|
|
1548
|
-
if (!params.elementId) {
|
|
1549
|
-
throw new Error("elementId is required for duplicate action");
|
|
1550
|
-
}
|
|
1551
|
-
return handleDuplicateElement(params.elementId);
|
|
1552
|
-
case "move":
|
|
1553
|
-
if (!params.elementId) {
|
|
1554
|
-
throw new Error("elementId is required for move action");
|
|
1555
|
-
}
|
|
1556
|
-
if (!params.targetContainerId) {
|
|
1557
|
-
throw new Error("targetContainerId is required for move action");
|
|
1558
|
-
}
|
|
1559
|
-
return handleMoveElement({
|
|
1560
|
-
elementId: params.elementId,
|
|
1561
|
-
targetContainerId: params.targetContainerId
|
|
1562
|
-
});
|
|
1563
|
-
case "select":
|
|
1564
|
-
if (params.elementIds && params.elementIds.length > 0) {
|
|
1565
|
-
return handleSelectMultipleElements(params.elementIds);
|
|
1566
|
-
}
|
|
1567
|
-
if (!params.elementId) {
|
|
1568
|
-
throw new Error("elementId or elementIds is required for select action");
|
|
1569
|
-
}
|
|
1570
|
-
return handleSelectElement(params.elementId);
|
|
1571
|
-
case "deselect":
|
|
1572
|
-
if (!params.elementId) {
|
|
1573
|
-
throw new Error("elementId is required for deselect action");
|
|
1574
|
-
}
|
|
1575
|
-
return handleDeselectElement(params.elementId);
|
|
1576
|
-
case "deselect-all":
|
|
1577
|
-
return handleDeselectAllElements();
|
|
1578
|
-
case "get-selected":
|
|
1579
|
-
return handleGetSelected();
|
|
1580
|
-
case "list-available-types":
|
|
1581
|
-
return handleListAvailableTypes();
|
|
1582
|
-
default:
|
|
1583
|
-
throw new Error(`Unknown action: ${params.action}`);
|
|
1584
|
-
}
|
|
1585
|
-
} catch (error) {
|
|
1586
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1587
|
-
throw new Error(`Failed to execute action "${params.action}": ${errorMessage}`);
|
|
1588
|
-
}
|
|
1589
|
-
}
|
|
1590
|
-
function initElementsTool() {
|
|
1591
|
-
(0, import_editor_mcp.getMCPByDomain)("elements").addTool({
|
|
1592
|
-
name: "elements",
|
|
1593
|
-
schema,
|
|
1594
|
-
description: `This tool manages individual Elementor atomic elements (v4).
|
|
1595
|
-
|
|
1596
|
-
**When to use this tool:**
|
|
1597
|
-
|
|
1598
|
-
Use this tool to create, update, delete, duplicate, move, and select individual atomic elements, as well as retrieve their schemas and current props.
|
|
1599
|
-
|
|
1600
|
-
**Available actions:**
|
|
1601
|
-
|
|
1602
|
-
- \`list-available-types\`: List all available atomic element types.
|
|
1603
|
-
- \`get-element-schema\`: Get the propsSchema and controls for an element type. Required before creating elements of a new type.
|
|
1604
|
-
- \`get-element-props\`: Get the current prop values for an existing element.
|
|
1605
|
-
- \`create-element\`: Create a new atomic element with specified props and styles (Important to match props and styles by the schema, use get-element-schema to get the schema first).
|
|
1606
|
-
- \`update-props\`: Update props for an existing element.
|
|
1607
|
-
- \`create-style\`: Create a new style definition for an element.
|
|
1608
|
-
- \`get-styles\`: Get all style definitions for an element.
|
|
1609
|
-
- \`update-styles\`: Update styles for an existing element's style variant.
|
|
1610
|
-
- \`delete-style\`: Delete a style definition from an element.
|
|
1611
|
-
- \`delete\`: Delete an element.
|
|
1612
|
-
- \`duplicate\`: Duplicate an existing element.
|
|
1613
|
-
- \`move\`: Move an element to a different container.
|
|
1614
|
-
- \`select\`: Select one or more elements.
|
|
1615
|
-
- \`deselect\`: Deselect a specific element.
|
|
1616
|
-
- \`deselect-all\`: Deselect all selected elements.
|
|
1617
|
-
- \`get-selected\`: Get currently selected elements.
|
|
1618
|
-
|
|
1619
|
-
**Constraints:**
|
|
1620
|
-
|
|
1621
|
-
- Before creating an element of a certain type for the first time, you MUST call \`get-element-schema\` to retrieve its schema.
|
|
1622
|
-
- You can only update props for existing elements.
|
|
1623
|
-
- All props must match the element type's propsSchema keys.
|
|
1624
|
-
- Element types must be atomic (have atomic_controls and atomic_props_schema).
|
|
1625
|
-
- Container IDs must exist and be valid before create/move operations.
|
|
1626
|
-
|
|
1627
|
-
** Must do with every operation **
|
|
1628
|
-
As of the user can ask in multiple ways the creation of the element, you need to first get the list of available types with "list-available-types" action.
|
|
1629
|
-
After getting it, convert to the most relevant type that the user requested and if this is not clear, request for user input.
|
|
1630
|
-
After finding out the proper type, get the schema for it with "get-element-schema" action.
|
|
1631
|
-
|
|
1632
|
-
** Styles and Settings propUtils **
|
|
1633
|
-
Getting the schema is important as it introduces the propUtils for the styles and settings.
|
|
1634
|
-
You can use the propUtils to create, update, delete, and get the values of the styles and settings.
|
|
1635
|
-
Settings exists in the result of the get-element-schema action -> propsSchema.
|
|
1636
|
-
Styles exists in the result of the get-element-schema action -> stylesSchema.
|
|
1637
|
-
|
|
1638
|
-
**Examples:**
|
|
1639
|
-
|
|
1640
|
-
Get schema for heading element:
|
|
1641
|
-
\`\`\`json
|
|
1642
|
-
{ "action": "get-element-schema", "elementType": "e-heading" }
|
|
1643
|
-
\`\`\`
|
|
1644
|
-
|
|
1645
|
-
Create a heading element:
|
|
1646
|
-
\`\`\`json
|
|
1647
|
-
{ "action": "create-element", "elementType": "e-heading", "containerId": "document", "props": { "title": { $$type: "string", "value": "Hello World" } } }
|
|
1648
|
-
\`\`\`
|
|
1649
|
-
|
|
1650
|
-
Update element props:
|
|
1651
|
-
\`\`\`json
|
|
1652
|
-
{ "action": "update-props", "elementId": "abc123", "props": { "title": "Updated Title" } }
|
|
1653
|
-
\`\`\`
|
|
1654
|
-
|
|
1655
|
-
Create element style:
|
|
1656
|
-
\`\`\`json
|
|
1657
|
-
{ "action": "create-style", "elementId": "abc123", "styles": { "padding": "20px", "margin": "10px" } }
|
|
1658
|
-
\`\`\`
|
|
1659
|
-
|
|
1660
|
-
Get element styles:
|
|
1661
|
-
\`\`\`json
|
|
1662
|
-
{ "action": "get-styles", "elementId": "abc123" }
|
|
1663
|
-
\`\`\`
|
|
1664
|
-
|
|
1665
|
-
Update element styles:
|
|
1666
|
-
\`\`\`json
|
|
1667
|
-
{ "action": "update-styles", "elementId": "abc123", "styles": { "padding": "20px", "margin": "10px" } }
|
|
1668
|
-
\`\`\`
|
|
1669
|
-
|
|
1670
|
-
Delete element style:
|
|
1671
|
-
\`\`\`json
|
|
1672
|
-
{ "action": "delete-style", "elementId": "abc123", "styleId": "style-id-123" }
|
|
1673
|
-
\`\`\``,
|
|
1674
|
-
handler: async (params) => {
|
|
1675
|
-
return routeAction(params);
|
|
1676
|
-
}
|
|
1677
|
-
});
|
|
1678
|
-
}
|
|
1679
|
-
|
|
1680
|
-
// src/mcp/index.ts
|
|
1681
|
-
function initMcp() {
|
|
1682
|
-
const { setMCPDescription } = (0, import_editor_mcp2.getMCPByDomain)("elements");
|
|
1683
|
-
setMCPDescription("Tools for managing atomic elements in Elementor v4 editor");
|
|
1684
|
-
initElementsTool();
|
|
1685
|
-
}
|
|
1686
1076
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1687
1077
|
0 && (module.exports = {
|
|
1688
1078
|
ELEMENT_STYLE_CHANGE_EVENT,
|
|
@@ -1711,7 +1101,6 @@ function initMcp() {
|
|
|
1711
1101
|
getLinkInLinkRestriction,
|
|
1712
1102
|
getSelectedElements,
|
|
1713
1103
|
getWidgetsCache,
|
|
1714
|
-
initElementsMcp,
|
|
1715
1104
|
isElementAnchored,
|
|
1716
1105
|
moveElement,
|
|
1717
1106
|
moveElements,
|