@elementor/editor-interactions 4.0.0-607 → 4.0.0-609
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 +254 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +254 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -9
- package/src/init.ts +3 -0
- package/src/mcp/constants.ts +1 -0
- package/src/mcp/index.ts +13 -0
- package/src/mcp/resources/interactions-schema-resource.ts +63 -0
- package/src/mcp/tools/manage-element-interaction-tool.ts +234 -0
package/dist/index.js
CHANGED
|
@@ -1387,6 +1387,259 @@ function cleanInteractionIds(elementId) {
|
|
|
1387
1387
|
container.model.set("interactions", updatedInteractions);
|
|
1388
1388
|
}
|
|
1389
1389
|
|
|
1390
|
+
// src/mcp/index.ts
|
|
1391
|
+
var import_editor_mcp = require("@elementor/editor-mcp");
|
|
1392
|
+
|
|
1393
|
+
// src/mcp/constants.ts
|
|
1394
|
+
var MAX_INTERACTIONS_PER_ELEMENT = 5;
|
|
1395
|
+
|
|
1396
|
+
// src/mcp/resources/interactions-schema-resource.ts
|
|
1397
|
+
var INTERACTIONS_SCHEMA_URI = "elementor://interactions/schema";
|
|
1398
|
+
var schema = {
|
|
1399
|
+
triggers: BASE_TRIGGERS.map((key) => ({
|
|
1400
|
+
value: key,
|
|
1401
|
+
label: TRIGGER_OPTIONS[key] ?? key
|
|
1402
|
+
})),
|
|
1403
|
+
effects: [
|
|
1404
|
+
{ value: "fade", label: "Fade" },
|
|
1405
|
+
{ value: "slide", label: "Slide" },
|
|
1406
|
+
{ value: "scale", label: "Scale" }
|
|
1407
|
+
],
|
|
1408
|
+
effectTypes: [
|
|
1409
|
+
{ value: "in", label: "In" },
|
|
1410
|
+
{ value: "out", label: "Out" }
|
|
1411
|
+
],
|
|
1412
|
+
directions: [
|
|
1413
|
+
{ value: "top", label: "Top", note: "" },
|
|
1414
|
+
{ value: "bottom", label: "Bottom", note: "" },
|
|
1415
|
+
{ value: "left", label: "Left", note: "" },
|
|
1416
|
+
{ value: "right", label: "Right", note: "" },
|
|
1417
|
+
{ value: "", label: "None", note: "Slide animation must have a direction" }
|
|
1418
|
+
],
|
|
1419
|
+
easings: Object.entries(EASING_OPTIONS).map(([value, label]) => ({ value, label })),
|
|
1420
|
+
timing: {
|
|
1421
|
+
duration: { min: 0, max: 1e4, unit: "ms", description: "Animation duration in milliseconds" },
|
|
1422
|
+
delay: { min: 0, max: 1e4, unit: "ms", description: "Animation delay in milliseconds" }
|
|
1423
|
+
},
|
|
1424
|
+
excludedBreakpoints: {
|
|
1425
|
+
type: "string[]",
|
|
1426
|
+
description: "List of breakpoint IDs on which this interaction is disabled. Omit to enable on all breakpoints."
|
|
1427
|
+
},
|
|
1428
|
+
maxInteractionsPerElement: MAX_INTERACTIONS_PER_ELEMENT
|
|
1429
|
+
};
|
|
1430
|
+
var initInteractionsSchemaResource = (reg) => {
|
|
1431
|
+
const { resource } = reg;
|
|
1432
|
+
resource(
|
|
1433
|
+
"interactions-schema",
|
|
1434
|
+
INTERACTIONS_SCHEMA_URI,
|
|
1435
|
+
{
|
|
1436
|
+
description: "Schema describing all available options for element interactions (triggers, effects, easings, timing, breakpoints, etc.)."
|
|
1437
|
+
},
|
|
1438
|
+
async () => {
|
|
1439
|
+
return {
|
|
1440
|
+
contents: [
|
|
1441
|
+
{
|
|
1442
|
+
uri: INTERACTIONS_SCHEMA_URI,
|
|
1443
|
+
text: JSON.stringify(schema, null, 2)
|
|
1444
|
+
}
|
|
1445
|
+
]
|
|
1446
|
+
};
|
|
1447
|
+
}
|
|
1448
|
+
);
|
|
1449
|
+
};
|
|
1450
|
+
|
|
1451
|
+
// src/mcp/tools/manage-element-interaction-tool.ts
|
|
1452
|
+
var import_editor_elements5 = require("@elementor/editor-elements");
|
|
1453
|
+
var import_schema = require("@elementor/schema");
|
|
1454
|
+
var EMPTY_INTERACTIONS = {
|
|
1455
|
+
version: 1,
|
|
1456
|
+
items: []
|
|
1457
|
+
};
|
|
1458
|
+
var initManageElementInteractionTool = (reg) => {
|
|
1459
|
+
const { addTool } = reg;
|
|
1460
|
+
addTool({
|
|
1461
|
+
name: "manage-element-interaction",
|
|
1462
|
+
description: `Read or manage interactions (animations) on an element. Always call with action=get first to see existing interactions before making changes.
|
|
1463
|
+
|
|
1464
|
+
Actions:
|
|
1465
|
+
- get: Read the current interactions on the element.
|
|
1466
|
+
- add: Add a new interaction (max ${MAX_INTERACTIONS_PER_ELEMENT} per element).
|
|
1467
|
+
- update: Update an existing interaction by its interactionId.
|
|
1468
|
+
- delete: Remove a specific interaction by its interactionId.
|
|
1469
|
+
- clear: Remove all interactions from the element.
|
|
1470
|
+
|
|
1471
|
+
For add/update, provide: trigger, effect, effectType, direction (empty string for non-slide effects), duration, delay, easing.
|
|
1472
|
+
Use excludedBreakpoints to disable the animation on specific responsive breakpoints (e.g. ["mobile", "tablet"]).`,
|
|
1473
|
+
schema: {
|
|
1474
|
+
elementId: import_schema.z.string().describe("The ID of the element to read or modify interactions on"),
|
|
1475
|
+
action: import_schema.z.enum(["get", "add", "update", "delete", "clear"]).describe('Operation to perform. Use "get" first to inspect existing interactions.'),
|
|
1476
|
+
interactionId: import_schema.z.string().optional().describe('Interaction ID \u2014 required for update and delete. Obtain from a prior "get" call.'),
|
|
1477
|
+
trigger: import_schema.z.enum(["load", "scrollIn"]).optional().describe("Event that triggers the animation"),
|
|
1478
|
+
effect: import_schema.z.enum(["fade", "slide", "scale"]).optional().describe("Animation effect type"),
|
|
1479
|
+
effectType: import_schema.z.enum(["in", "out"]).optional().describe("Whether the animation plays in or out"),
|
|
1480
|
+
direction: import_schema.z.enum(["top", "bottom", "left", "right", ""]).optional().describe("Direction for slide effect. Use empty string for fade/scale."),
|
|
1481
|
+
duration: import_schema.z.number().min(0).max(1e4).optional().describe("Animation duration in milliseconds"),
|
|
1482
|
+
delay: import_schema.z.number().min(0).max(1e4).optional().describe("Animation delay in milliseconds"),
|
|
1483
|
+
easing: import_schema.z.string().optional().describe("Easing function. See interactions schema for options."),
|
|
1484
|
+
excludedBreakpoints: import_schema.z.array(import_schema.z.string()).optional().describe(
|
|
1485
|
+
'Breakpoint IDs on which this interaction is disabled (e.g. ["mobile", "tablet"]). Omit to enable on all breakpoints.'
|
|
1486
|
+
)
|
|
1487
|
+
},
|
|
1488
|
+
requiredResources: [
|
|
1489
|
+
{ uri: INTERACTIONS_SCHEMA_URI, description: "Interactions schema with all available options" }
|
|
1490
|
+
],
|
|
1491
|
+
isDestructive: true,
|
|
1492
|
+
handler: (input) => {
|
|
1493
|
+
const {
|
|
1494
|
+
elementId,
|
|
1495
|
+
action,
|
|
1496
|
+
interactionId,
|
|
1497
|
+
trigger,
|
|
1498
|
+
effect,
|
|
1499
|
+
effectType,
|
|
1500
|
+
direction,
|
|
1501
|
+
duration,
|
|
1502
|
+
delay,
|
|
1503
|
+
easing,
|
|
1504
|
+
excludedBreakpoints
|
|
1505
|
+
} = input;
|
|
1506
|
+
const allInteractions = interactionsRepository.all();
|
|
1507
|
+
const elementData = allInteractions.find((data) => data.elementId === elementId);
|
|
1508
|
+
const currentInteractions = elementData?.interactions ?? EMPTY_INTERACTIONS;
|
|
1509
|
+
if (action === "get") {
|
|
1510
|
+
const summary = currentInteractions.items.map((item) => {
|
|
1511
|
+
const { value } = item;
|
|
1512
|
+
const animValue = value.animation.value;
|
|
1513
|
+
const timingValue = animValue.timing_config.value;
|
|
1514
|
+
const configValue = animValue.config.value;
|
|
1515
|
+
return {
|
|
1516
|
+
id: extractString(value.interaction_id),
|
|
1517
|
+
trigger: extractString(value.trigger),
|
|
1518
|
+
effect: extractString(animValue.effect),
|
|
1519
|
+
effectType: extractString(animValue.type),
|
|
1520
|
+
direction: extractString(animValue.direction),
|
|
1521
|
+
duration: extractSize(timingValue.duration),
|
|
1522
|
+
delay: extractSize(timingValue.delay),
|
|
1523
|
+
easing: extractString(configValue.easing),
|
|
1524
|
+
excludedBreakpoints: extractExcludedBreakpoints(value.breakpoints)
|
|
1525
|
+
};
|
|
1526
|
+
});
|
|
1527
|
+
return JSON.stringify({
|
|
1528
|
+
elementId,
|
|
1529
|
+
interactions: summary,
|
|
1530
|
+
count: summary.length
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1533
|
+
let updatedItems = [...currentInteractions.items];
|
|
1534
|
+
switch (action) {
|
|
1535
|
+
case "add": {
|
|
1536
|
+
if (updatedItems.length >= MAX_INTERACTIONS_PER_ELEMENT) {
|
|
1537
|
+
throw new Error(
|
|
1538
|
+
`Cannot add more than ${MAX_INTERACTIONS_PER_ELEMENT} interactions per element. Current count: ${updatedItems.length}. Delete an existing interaction first.`
|
|
1539
|
+
);
|
|
1540
|
+
}
|
|
1541
|
+
const newItem = createInteractionItem({
|
|
1542
|
+
interactionId: generateTempInteractionId(),
|
|
1543
|
+
trigger: trigger ?? DEFAULT_VALUES.trigger,
|
|
1544
|
+
effect: effect ?? DEFAULT_VALUES.effect,
|
|
1545
|
+
type: effectType ?? DEFAULT_VALUES.type,
|
|
1546
|
+
direction: direction ?? DEFAULT_VALUES.direction,
|
|
1547
|
+
duration: duration ?? DEFAULT_VALUES.duration,
|
|
1548
|
+
delay: delay ?? DEFAULT_VALUES.delay,
|
|
1549
|
+
replay: DEFAULT_VALUES.replay,
|
|
1550
|
+
easing: easing ?? DEFAULT_VALUES.easing,
|
|
1551
|
+
excludedBreakpoints
|
|
1552
|
+
});
|
|
1553
|
+
updatedItems = [...updatedItems, newItem];
|
|
1554
|
+
break;
|
|
1555
|
+
}
|
|
1556
|
+
case "update": {
|
|
1557
|
+
if (!interactionId) {
|
|
1558
|
+
throw new Error("interactionId is required for the update action.");
|
|
1559
|
+
}
|
|
1560
|
+
const itemIndex = updatedItems.findIndex(
|
|
1561
|
+
(item) => extractString(item.value.interaction_id) === interactionId
|
|
1562
|
+
);
|
|
1563
|
+
if (itemIndex === -1) {
|
|
1564
|
+
throw new Error(
|
|
1565
|
+
`Interaction with ID "${interactionId}" not found on element "${elementId}".`
|
|
1566
|
+
);
|
|
1567
|
+
}
|
|
1568
|
+
const existingItem = updatedItems[itemIndex];
|
|
1569
|
+
const existingValue = existingItem.value;
|
|
1570
|
+
const existingAnimation = existingValue.animation.value;
|
|
1571
|
+
const existingTiming = existingAnimation.timing_config.value;
|
|
1572
|
+
const existingConfig = existingAnimation.config.value;
|
|
1573
|
+
const existingExcludedBreakpoints = extractExcludedBreakpoints(existingValue.breakpoints);
|
|
1574
|
+
const updatedItem = createInteractionItem({
|
|
1575
|
+
interactionId,
|
|
1576
|
+
trigger: trigger ?? extractString(existingValue.trigger),
|
|
1577
|
+
effect: effect ?? extractString(existingAnimation.effect),
|
|
1578
|
+
type: effectType ?? extractString(existingAnimation.type),
|
|
1579
|
+
direction: direction !== void 0 ? direction : extractString(existingAnimation.direction),
|
|
1580
|
+
duration: duration !== void 0 ? duration : extractSize(existingTiming.duration),
|
|
1581
|
+
delay: delay !== void 0 ? delay : extractSize(existingTiming.delay),
|
|
1582
|
+
replay: existingConfig.replay?.value ?? DEFAULT_VALUES.replay,
|
|
1583
|
+
easing: easing ?? extractString(existingConfig.easing),
|
|
1584
|
+
excludedBreakpoints: excludedBreakpoints !== void 0 ? excludedBreakpoints : existingExcludedBreakpoints
|
|
1585
|
+
});
|
|
1586
|
+
updatedItems = [
|
|
1587
|
+
...updatedItems.slice(0, itemIndex),
|
|
1588
|
+
updatedItem,
|
|
1589
|
+
...updatedItems.slice(itemIndex + 1)
|
|
1590
|
+
];
|
|
1591
|
+
break;
|
|
1592
|
+
}
|
|
1593
|
+
case "delete": {
|
|
1594
|
+
if (!interactionId) {
|
|
1595
|
+
throw new Error("interactionId is required for the delete action.");
|
|
1596
|
+
}
|
|
1597
|
+
const beforeCount = updatedItems.length;
|
|
1598
|
+
updatedItems = updatedItems.filter(
|
|
1599
|
+
(item) => extractString(item.value.interaction_id) !== interactionId
|
|
1600
|
+
);
|
|
1601
|
+
if (updatedItems.length === beforeCount) {
|
|
1602
|
+
throw new Error(
|
|
1603
|
+
`Interaction with ID "${interactionId}" not found on element "${elementId}".`
|
|
1604
|
+
);
|
|
1605
|
+
}
|
|
1606
|
+
break;
|
|
1607
|
+
}
|
|
1608
|
+
case "clear": {
|
|
1609
|
+
updatedItems = [];
|
|
1610
|
+
break;
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
const updatedInteractions = {
|
|
1614
|
+
...currentInteractions,
|
|
1615
|
+
items: updatedItems
|
|
1616
|
+
};
|
|
1617
|
+
try {
|
|
1618
|
+
(0, import_editor_elements5.updateElementInteractions)({ elementId, interactions: updatedInteractions });
|
|
1619
|
+
} catch (error) {
|
|
1620
|
+
throw new Error(
|
|
1621
|
+
`Failed to update interactions for element "${elementId}": ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1622
|
+
);
|
|
1623
|
+
}
|
|
1624
|
+
return JSON.stringify({
|
|
1625
|
+
success: true,
|
|
1626
|
+
action,
|
|
1627
|
+
elementId,
|
|
1628
|
+
interactionCount: updatedItems.length
|
|
1629
|
+
});
|
|
1630
|
+
}
|
|
1631
|
+
});
|
|
1632
|
+
};
|
|
1633
|
+
|
|
1634
|
+
// src/mcp/index.ts
|
|
1635
|
+
var initMcpInteractions = () => {
|
|
1636
|
+
const reg = (0, import_editor_mcp.getMCPByDomain)("interactions", {
|
|
1637
|
+
instructions: "MCP server for managing element interactions and animations. Use this to add, modify, or remove animations and motion effects triggered by user events such as page load or scroll-into-view."
|
|
1638
|
+
});
|
|
1639
|
+
initInteractionsSchemaResource(reg);
|
|
1640
|
+
initManageElementInteractionTool(reg);
|
|
1641
|
+
};
|
|
1642
|
+
|
|
1390
1643
|
// src/init.ts
|
|
1391
1644
|
function init() {
|
|
1392
1645
|
try {
|
|
@@ -1422,6 +1675,7 @@ function init() {
|
|
|
1422
1675
|
component: Effect,
|
|
1423
1676
|
options: ["fade", "slide", "scale"]
|
|
1424
1677
|
});
|
|
1678
|
+
initMcpInteractions();
|
|
1425
1679
|
} catch (error) {
|
|
1426
1680
|
throw error;
|
|
1427
1681
|
}
|