@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.
@@ -0,0 +1,13 @@
1
+ import { getMCPByDomain } from '@elementor/editor-mcp';
2
+
3
+ import { initInteractionsSchemaResource } from './resources/interactions-schema-resource';
4
+ import { initManageElementInteractionTool } from './tools/manage-element-interaction-tool';
5
+
6
+ export const initMcpInteractions = () => {
7
+ const reg = getMCPByDomain( 'interactions', {
8
+ instructions:
9
+ '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.',
10
+ } );
11
+ initInteractionsSchemaResource( reg );
12
+ initManageElementInteractionTool( reg );
13
+ };
@@ -0,0 +1,63 @@
1
+ import { type MCPRegistryEntry } from '@elementor/editor-mcp';
2
+
3
+ import { EASING_OPTIONS } from '../../components/controls/easing';
4
+ import { BASE_TRIGGERS, TRIGGER_OPTIONS } from '../../components/controls/trigger';
5
+ import { MAX_INTERACTIONS_PER_ELEMENT } from '../constants';
6
+
7
+ export const INTERACTIONS_SCHEMA_URI = 'elementor://interactions/schema';
8
+
9
+ const schema = {
10
+ triggers: BASE_TRIGGERS.map( ( key ) => ( {
11
+ value: key,
12
+ label: TRIGGER_OPTIONS[ key as keyof typeof TRIGGER_OPTIONS ] ?? key,
13
+ } ) ),
14
+ effects: [
15
+ { value: 'fade', label: 'Fade' },
16
+ { value: 'slide', label: 'Slide' },
17
+ { value: 'scale', label: 'Scale' },
18
+ ],
19
+ effectTypes: [
20
+ { value: 'in', label: 'In' },
21
+ { value: 'out', label: 'Out' },
22
+ ],
23
+ directions: [
24
+ { value: 'top', label: 'Top', note: '' },
25
+ { value: 'bottom', label: 'Bottom', note: '' },
26
+ { value: 'left', label: 'Left', note: '' },
27
+ { value: 'right', label: 'Right', note: '' },
28
+ { value: '', label: 'None', note: 'Slide animation must have a direction' },
29
+ ],
30
+ easings: Object.entries( EASING_OPTIONS ).map( ( [ value, label ] ) => ( { value, label } ) ),
31
+ timing: {
32
+ duration: { min: 0, max: 10000, unit: 'ms', description: 'Animation duration in milliseconds' },
33
+ delay: { min: 0, max: 10000, unit: 'ms', description: 'Animation delay in milliseconds' },
34
+ },
35
+ excludedBreakpoints: {
36
+ type: 'string[]',
37
+ description: 'List of breakpoint IDs on which this interaction is disabled. Omit to enable on all breakpoints.',
38
+ },
39
+ maxInteractionsPerElement: MAX_INTERACTIONS_PER_ELEMENT,
40
+ };
41
+
42
+ export const initInteractionsSchemaResource = ( reg: MCPRegistryEntry ) => {
43
+ const { resource } = reg;
44
+
45
+ resource(
46
+ 'interactions-schema',
47
+ INTERACTIONS_SCHEMA_URI,
48
+ {
49
+ description:
50
+ 'Schema describing all available options for element interactions (triggers, effects, easings, timing, breakpoints, etc.).',
51
+ },
52
+ async () => {
53
+ return {
54
+ contents: [
55
+ {
56
+ uri: INTERACTIONS_SCHEMA_URI,
57
+ text: JSON.stringify( schema, null, 2 ),
58
+ },
59
+ ],
60
+ };
61
+ }
62
+ );
63
+ };
@@ -0,0 +1,234 @@
1
+ import { updateElementInteractions } from '@elementor/editor-elements';
2
+ import { type MCPRegistryEntry } from '@elementor/editor-mcp';
3
+ import { z } from '@elementor/schema';
4
+
5
+ import { DEFAULT_VALUES } from '../../components/interaction-details';
6
+ import { interactionsRepository } from '../../interactions-repository';
7
+ import { type ElementInteractions } from '../../types';
8
+ import {
9
+ createInteractionItem,
10
+ extractExcludedBreakpoints,
11
+ extractSize,
12
+ extractString,
13
+ } from '../../utils/prop-value-utils';
14
+ import { generateTempInteractionId } from '../../utils/temp-id-utils';
15
+ import { MAX_INTERACTIONS_PER_ELEMENT } from '../constants';
16
+ import { INTERACTIONS_SCHEMA_URI } from '../resources/interactions-schema-resource';
17
+
18
+ const EMPTY_INTERACTIONS: ElementInteractions = {
19
+ version: 1,
20
+ items: [],
21
+ };
22
+
23
+ export const initManageElementInteractionTool = ( reg: MCPRegistryEntry ) => {
24
+ const { addTool } = reg;
25
+
26
+ addTool( {
27
+ name: 'manage-element-interaction',
28
+ description: `Read or manage interactions (animations) on an element. Always call with action=get first to see existing interactions before making changes.
29
+
30
+ Actions:
31
+ - get: Read the current interactions on the element.
32
+ - add: Add a new interaction (max ${ MAX_INTERACTIONS_PER_ELEMENT } per element).
33
+ - update: Update an existing interaction by its interactionId.
34
+ - delete: Remove a specific interaction by its interactionId.
35
+ - clear: Remove all interactions from the element.
36
+
37
+ For add/update, provide: trigger, effect, effectType, direction (empty string for non-slide effects), duration, delay, easing.
38
+ Use excludedBreakpoints to disable the animation on specific responsive breakpoints (e.g. ["mobile", "tablet"]).`,
39
+ schema: {
40
+ elementId: z.string().describe( 'The ID of the element to read or modify interactions on' ),
41
+ action: z
42
+ .enum( [ 'get', 'add', 'update', 'delete', 'clear' ] )
43
+ .describe( 'Operation to perform. Use "get" first to inspect existing interactions.' ),
44
+ interactionId: z
45
+ .string()
46
+ .optional()
47
+ .describe( 'Interaction ID — required for update and delete. Obtain from a prior "get" call.' ),
48
+ trigger: z.enum( [ 'load', 'scrollIn' ] ).optional().describe( 'Event that triggers the animation' ),
49
+ effect: z.enum( [ 'fade', 'slide', 'scale' ] ).optional().describe( 'Animation effect type' ),
50
+ effectType: z.enum( [ 'in', 'out' ] ).optional().describe( 'Whether the animation plays in or out' ),
51
+ direction: z
52
+ .enum( [ 'top', 'bottom', 'left', 'right', '' ] )
53
+ .optional()
54
+ .describe( 'Direction for slide effect. Use empty string for fade/scale.' ),
55
+ duration: z.number().min( 0 ).max( 10000 ).optional().describe( 'Animation duration in milliseconds' ),
56
+ delay: z.number().min( 0 ).max( 10000 ).optional().describe( 'Animation delay in milliseconds' ),
57
+ easing: z.string().optional().describe( 'Easing function. See interactions schema for options.' ),
58
+ excludedBreakpoints: z
59
+ .array( z.string() )
60
+ .optional()
61
+ .describe(
62
+ 'Breakpoint IDs on which this interaction is disabled (e.g. ["mobile", "tablet"]). Omit to enable on all breakpoints.'
63
+ ),
64
+ },
65
+ requiredResources: [
66
+ { uri: INTERACTIONS_SCHEMA_URI, description: 'Interactions schema with all available options' },
67
+ ],
68
+ isDestructive: true,
69
+ handler: ( input ) => {
70
+ const {
71
+ elementId,
72
+ action,
73
+ interactionId,
74
+ trigger,
75
+ effect,
76
+ effectType,
77
+ direction,
78
+ duration,
79
+ delay,
80
+ easing,
81
+ excludedBreakpoints,
82
+ } = input;
83
+
84
+ const allInteractions = interactionsRepository.all();
85
+ const elementData = allInteractions.find( ( data ) => data.elementId === elementId );
86
+ const currentInteractions: ElementInteractions = elementData?.interactions ?? EMPTY_INTERACTIONS;
87
+
88
+ if ( action === 'get' ) {
89
+ const summary = currentInteractions.items.map( ( item ) => {
90
+ const { value } = item;
91
+ const animValue = value.animation.value;
92
+ const timingValue = animValue.timing_config.value;
93
+ const configValue = animValue.config.value;
94
+
95
+ return {
96
+ id: extractString( value.interaction_id ),
97
+ trigger: extractString( value.trigger ),
98
+ effect: extractString( animValue.effect ),
99
+ effectType: extractString( animValue.type ),
100
+ direction: extractString( animValue.direction ),
101
+ duration: extractSize( timingValue.duration ),
102
+ delay: extractSize( timingValue.delay ),
103
+ easing: extractString( configValue.easing ),
104
+ excludedBreakpoints: extractExcludedBreakpoints( value.breakpoints ),
105
+ };
106
+ } );
107
+
108
+ return JSON.stringify( {
109
+ elementId,
110
+ interactions: summary,
111
+ count: summary.length,
112
+ } );
113
+ }
114
+
115
+ let updatedItems = [ ...currentInteractions.items ];
116
+
117
+ switch ( action ) {
118
+ case 'add': {
119
+ if ( updatedItems.length >= MAX_INTERACTIONS_PER_ELEMENT ) {
120
+ throw new Error(
121
+ `Cannot add more than ${ MAX_INTERACTIONS_PER_ELEMENT } interactions per element. Current count: ${ updatedItems.length }. Delete an existing interaction first.`
122
+ );
123
+ }
124
+
125
+ const newItem = createInteractionItem( {
126
+ interactionId: generateTempInteractionId(),
127
+ trigger: trigger ?? DEFAULT_VALUES.trigger,
128
+ effect: effect ?? DEFAULT_VALUES.effect,
129
+ type: effectType ?? DEFAULT_VALUES.type,
130
+ direction: direction ?? DEFAULT_VALUES.direction,
131
+ duration: duration ?? DEFAULT_VALUES.duration,
132
+ delay: delay ?? DEFAULT_VALUES.delay,
133
+ replay: DEFAULT_VALUES.replay,
134
+ easing: easing ?? DEFAULT_VALUES.easing,
135
+ excludedBreakpoints,
136
+ } );
137
+
138
+ updatedItems = [ ...updatedItems, newItem ];
139
+ break;
140
+ }
141
+
142
+ case 'update': {
143
+ if ( ! interactionId ) {
144
+ throw new Error( 'interactionId is required for the update action.' );
145
+ }
146
+
147
+ const itemIndex = updatedItems.findIndex(
148
+ ( item ) => extractString( item.value.interaction_id ) === interactionId
149
+ );
150
+
151
+ if ( itemIndex === -1 ) {
152
+ throw new Error(
153
+ `Interaction with ID "${ interactionId }" not found on element "${ elementId }".`
154
+ );
155
+ }
156
+
157
+ const existingItem = updatedItems[ itemIndex ];
158
+ const existingValue = existingItem.value;
159
+ const existingAnimation = existingValue.animation.value;
160
+ const existingTiming = existingAnimation.timing_config.value;
161
+ const existingConfig = existingAnimation.config.value;
162
+ const existingExcludedBreakpoints = extractExcludedBreakpoints( existingValue.breakpoints );
163
+
164
+ const updatedItem = createInteractionItem( {
165
+ interactionId,
166
+ trigger: trigger ?? extractString( existingValue.trigger ),
167
+ effect: effect ?? extractString( existingAnimation.effect ),
168
+ type: effectType ?? extractString( existingAnimation.type ),
169
+ direction: direction !== undefined ? direction : extractString( existingAnimation.direction ),
170
+ duration:
171
+ duration !== undefined ? duration : ( extractSize( existingTiming.duration ) as number ),
172
+ delay: delay !== undefined ? delay : ( extractSize( existingTiming.delay ) as number ),
173
+ replay: existingConfig.replay?.value ?? DEFAULT_VALUES.replay,
174
+ easing: easing ?? extractString( existingConfig.easing ),
175
+ excludedBreakpoints:
176
+ excludedBreakpoints !== undefined ? excludedBreakpoints : existingExcludedBreakpoints,
177
+ } );
178
+
179
+ updatedItems = [
180
+ ...updatedItems.slice( 0, itemIndex ),
181
+ updatedItem,
182
+ ...updatedItems.slice( itemIndex + 1 ),
183
+ ];
184
+ break;
185
+ }
186
+
187
+ case 'delete': {
188
+ if ( ! interactionId ) {
189
+ throw new Error( 'interactionId is required for the delete action.' );
190
+ }
191
+
192
+ const beforeCount = updatedItems.length;
193
+ updatedItems = updatedItems.filter(
194
+ ( item ) => extractString( item.value.interaction_id ) !== interactionId
195
+ );
196
+
197
+ if ( updatedItems.length === beforeCount ) {
198
+ throw new Error(
199
+ `Interaction with ID "${ interactionId }" not found on element "${ elementId }".`
200
+ );
201
+ }
202
+ break;
203
+ }
204
+
205
+ case 'clear': {
206
+ updatedItems = [];
207
+ break;
208
+ }
209
+ }
210
+
211
+ const updatedInteractions: ElementInteractions = {
212
+ ...currentInteractions,
213
+ items: updatedItems,
214
+ };
215
+
216
+ try {
217
+ updateElementInteractions( { elementId, interactions: updatedInteractions } );
218
+ } catch ( error ) {
219
+ throw new Error(
220
+ `Failed to update interactions for element "${ elementId }": ${
221
+ error instanceof Error ? error.message : 'Unknown error'
222
+ }`
223
+ );
224
+ }
225
+
226
+ return JSON.stringify( {
227
+ success: true,
228
+ action,
229
+ elementId,
230
+ interactionCount: updatedItems.length,
231
+ } );
232
+ },
233
+ } );
234
+ };