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