@elementor/editor-interactions 4.0.0-607 → 4.0.0-619

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