@elementor/editor-elements 3.33.0-99 → 3.35.0-325

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.
Files changed (50) hide show
  1. package/dist/index.d.mts +200 -99
  2. package/dist/index.d.ts +200 -99
  3. package/dist/index.js +1161 -394
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +1158 -401
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +7 -5
  8. package/src/errors.ts +10 -0
  9. package/src/hooks/use-element-children.ts +12 -12
  10. package/src/hooks/use-element-editor-settings.ts +12 -0
  11. package/src/hooks/use-element-interactions.ts +25 -0
  12. package/src/hooks/use-element-setting.ts +1 -1
  13. package/src/hooks/use-selected-element.ts +2 -2
  14. package/src/index.ts +38 -27
  15. package/src/mcp/elements-tool.ts +345 -0
  16. package/src/mcp/handlers/common-style-utils.ts +23 -0
  17. package/src/mcp/handlers/create-element.ts +96 -0
  18. package/src/mcp/handlers/create-style.ts +42 -0
  19. package/src/mcp/handlers/delete-element.ts +17 -0
  20. package/src/mcp/handlers/delete-style.ts +22 -0
  21. package/src/mcp/handlers/deselect-element.ts +21 -0
  22. package/src/mcp/handlers/duplicate-element.ts +22 -0
  23. package/src/mcp/handlers/get-element-props.ts +28 -0
  24. package/src/mcp/handlers/get-element-schema.ts +17 -0
  25. package/src/mcp/handlers/get-selected.ts +5 -0
  26. package/src/mcp/handlers/get-styles.ts +26 -0
  27. package/src/mcp/handlers/list-available-types.ts +27 -0
  28. package/src/mcp/handlers/move-element.ts +30 -0
  29. package/src/mcp/handlers/select-element.ts +25 -0
  30. package/src/mcp/handlers/update-props.ts +22 -0
  31. package/src/mcp/handlers/update-styles.ts +45 -0
  32. package/src/mcp/index.ts +9 -0
  33. package/src/sync/delete-element.ts +8 -2
  34. package/src/sync/drop-element.ts +30 -0
  35. package/src/sync/duplicate-elements.ts +3 -4
  36. package/src/sync/get-current-document-container.ts +1 -1
  37. package/src/sync/get-element-editor-settings.ts +8 -0
  38. package/src/sync/get-element-interactions.ts +15 -0
  39. package/src/sync/get-element-label.ts +6 -1
  40. package/src/sync/get-element-type.ts +28 -0
  41. package/src/sync/get-elements.ts +1 -1
  42. package/src/sync/get-widgets-cache.ts +4 -3
  43. package/src/sync/move-elements.ts +9 -1
  44. package/src/sync/remove-elements.ts +11 -0
  45. package/src/sync/replace-element.ts +50 -12
  46. package/src/sync/types.ts +32 -3
  47. package/src/sync/update-element-editor-settings.ts +28 -0
  48. package/src/sync/update-element-interactions.ts +32 -0
  49. package/src/types.ts +16 -1
  50. package/src/hooks/use-element-type.ts +0 -35
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PropsSchema, PropValue, Props } from '@elementor/editor-props';
2
- import { StyleDefinitionID, StyleDefinition, StyleDefinitionVariant } from '@elementor/editor-styles';
2
+ import { ClassState, StyleDefinitionID, StyleDefinition, StyleDefinitionVariant } from '@elementor/editor-styles';
3
3
  import * as _elementor_editor_v1_adapters from '@elementor/editor-v1-adapters';
4
4
 
5
5
  type ElementID = string;
@@ -12,6 +12,7 @@ type ElementType = {
12
12
  controls: ControlItem[];
13
13
  propsSchema: PropsSchema;
14
14
  dependenciesPerTargetMapping?: Record<string, string[]>;
15
+ styleStates?: ClassState[];
15
16
  title: string;
16
17
  };
17
18
  type ControlsSection = {
@@ -36,9 +37,41 @@ type Control = {
36
37
  };
37
38
  };
38
39
  };
39
- type ControlItem = ControlsSection | Control;
40
+ type ElementControl = {
41
+ type: 'element-control';
42
+ value: {
43
+ type: string;
44
+ label?: string;
45
+ props: Record<string, unknown>;
46
+ meta?: {
47
+ layout?: ControlLayout;
48
+ topDivider?: boolean;
49
+ };
50
+ };
51
+ };
52
+ type ControlItem = ControlsSection | Control | ElementControl;
40
53
  type ControlLayout = 'full' | 'two-columns' | 'custom';
41
54
 
55
+ type ExtendedWindow = Window & {
56
+ elementor?: {
57
+ selection?: {
58
+ getElements: () => V1Element[];
59
+ };
60
+ widgetsCache?: Record<string, V1ElementConfig>;
61
+ documents?: {
62
+ getCurrent?: () => {
63
+ container: V1Element;
64
+ } | undefined;
65
+ getCurrentId?: () => number;
66
+ };
67
+ getContainer?: (id: string) => V1Element | undefined;
68
+ };
69
+ elementorCommon?: {
70
+ helpers?: {
71
+ getUniqueId?: () => string;
72
+ };
73
+ };
74
+ };
42
75
  type V1Element = {
43
76
  id: string;
44
77
  model: V1Model<V1ElementModelProps>;
@@ -56,17 +89,41 @@ type V1Element = {
56
89
  };
57
90
  parent?: V1Element;
58
91
  };
92
+ type ElementInteractions = {
93
+ version: number;
94
+ items: InteractionItem[];
95
+ };
96
+ type InteractionItem = {
97
+ interaction_id?: string;
98
+ animation: {
99
+ animation_type: string;
100
+ animation_id: string;
101
+ };
102
+ };
59
103
  type V1ElementModelProps = {
104
+ isLocked?: boolean;
60
105
  widgetType?: string;
61
106
  elType: string;
62
107
  id: string;
63
108
  styles?: Record<StyleDefinitionID, StyleDefinition>;
64
109
  elements?: V1Model<V1ElementModelProps>[];
65
110
  settings?: V1ElementSettingsProps;
111
+ editor_settings?: V1ElementEditorSettingsProps;
112
+ interactions?: string | ElementInteractions;
113
+ };
114
+ type V1ElementData = Omit<V1ElementModelProps, 'elements'> & {
115
+ elements?: V1ElementData[];
116
+ };
117
+ type V1ElementEditorSettingsProps = {
118
+ title?: string;
119
+ initial_position?: number;
120
+ component_uid?: string;
66
121
  };
67
122
  type V1ElementSettingsProps = Record<string, PropValue>;
68
- type V1ElementConfig = {
123
+ type V1ElementConfig<T = object> = {
69
124
  title: string;
125
+ widgetType?: string;
126
+ elType?: string;
70
127
  controls: object;
71
128
  atomic?: boolean;
72
129
  atomic_controls?: ControlItem[];
@@ -76,7 +133,8 @@ type V1ElementConfig = {
76
133
  twig_main_template?: string;
77
134
  base_styles?: Record<string, StyleDefinition>;
78
135
  base_styles_dictionary?: Record<string, string>;
79
- };
136
+ atomic_style_states?: ClassState[];
137
+ } & T;
80
138
  type V1Model<T> = {
81
139
  get: <K extends keyof T>(key: K) => T[K];
82
140
  set: <K extends keyof T>(key: K, value: T[K]) => void;
@@ -85,10 +143,18 @@ type V1Model<T> = {
85
143
  }) => T;
86
144
  };
87
145
 
146
+ type ElementModel = {
147
+ id: string;
148
+ };
149
+ type ElementChildren = Record<string, ElementModel[]>;
150
+ declare function useElementChildren<T extends ElementChildren>(elementId: ElementID, childrenTypes: Record<string, string>): T;
151
+
152
+ declare const useElementEditorSettings: (elementId: ElementID) => V1ElementEditorSettingsProps;
153
+
88
154
  declare const useElementSetting: <TValue>(elementId: ElementID, settingKey: string) => TValue | null;
89
155
  declare const useElementSettings: <TValue>(elementId: ElementID, settingKeys: string[]) => Record<string, TValue>;
90
156
 
91
- declare function useElementType(type?: string): ElementType | null;
157
+ declare function useParentElement(elementId: string | null): any;
92
158
 
93
159
  declare function useSelectedElement(): {
94
160
  element: null;
@@ -98,22 +164,14 @@ declare function useSelectedElement(): {
98
164
  elementType: ElementType;
99
165
  };
100
166
 
101
- declare function useParentElement(elementId: string | null): V1Element | null | undefined;
102
-
103
- type ElementModel = {
104
- id: string;
105
- };
106
- type ElementChildren = Record<string, ElementModel[]>;
107
- declare function useElementChildren<T extends ElementChildren>(elementId: ElementID, childrenTypes: (keyof T & string)[]): T;
108
-
109
- type Options$3 = {
167
+ type Options$4 = {
110
168
  useHistory?: boolean;
111
169
  at?: number;
112
170
  clone?: boolean;
113
171
  };
114
172
  type CreateElementParams = {
115
173
  containerId: string;
116
- options?: Options$3;
174
+ options?: Options$4;
117
175
  model?: Omit<V1ElementModelProps, 'settings' | 'id'> & {
118
176
  settings?: V1ElementSettingsProps;
119
177
  id?: string;
@@ -121,39 +179,45 @@ type CreateElementParams = {
121
179
  };
122
180
  declare function createElement({ containerId, model, options }: CreateElementParams): V1Element;
123
181
 
124
- type Options$2 = {
125
- useHistory?: boolean;
126
- at?: number;
127
- edit?: boolean;
128
- };
129
- type MoveElementParams = {
130
- elementId: string;
131
- targetContainerId: string;
132
- options?: Options$2;
133
- };
134
- declare function moveElement({ elementId, targetContainerId, options }: MoveElementParams): V1Element;
135
-
136
- type MoveElementsParams = {
137
- moves: MoveElementParams[];
182
+ type CreateNestedElementsParams = {
183
+ elements: CreateElementParams[];
138
184
  title: string;
139
185
  subtitle?: string;
140
186
  };
141
- type OriginalPosition = {
187
+ type CreatedElement = {
142
188
  elementId: string;
143
- originalContainerId: string;
144
- originalIndex: number;
189
+ model: V1ElementModelProps;
190
+ createParams: CreateElementParams;
145
191
  };
146
- type MovedElement = {
147
- elementId: string;
148
- originalPosition: OriginalPosition;
149
- move: MoveElementParams;
150
- element: V1Element;
192
+ type CreatedElementsResult = {
193
+ createdElements: CreatedElement[];
151
194
  };
152
- type MovedElementsResult = {
153
- movedElements: MovedElement[];
195
+
196
+ declare const createElements: ({ elements, title, subtitle, }: CreateNestedElementsParams) => CreatedElementsResult;
197
+
198
+ type Options$3 = {
199
+ useHistory?: boolean;
200
+ at?: number;
154
201
  };
202
+ declare function deleteElement({ elementId, options, }: {
203
+ elementId: string;
204
+ options?: Options$3;
205
+ }): Promise<void>;
155
206
 
156
- declare const moveElements: ({ moves: movesToMake, title, subtitle, }: MoveElementsParams) => MovedElementsResult;
207
+ type Options$2 = {
208
+ useHistory?: boolean;
209
+ at?: number;
210
+ scrollIntoView: boolean;
211
+ };
212
+ type DropElementParams = {
213
+ containerId: string;
214
+ options?: Options$2;
215
+ model?: Omit<V1ElementModelProps, 'settings' | 'id'> & {
216
+ settings?: V1ElementSettingsProps;
217
+ id?: string;
218
+ };
219
+ };
220
+ declare function dropElement({ containerId, model, options }: DropElementParams): V1Element;
157
221
 
158
222
  type Options$1 = {
159
223
  useHistory?: boolean;
@@ -166,27 +230,11 @@ type DuplicateElementParams = {
166
230
  };
167
231
  declare function duplicateElement({ elementId, options }: DuplicateElementParams): V1Element;
168
232
 
169
- type CreateNestedElementsParams = {
170
- elements: CreateElementParams[];
171
- title: string;
172
- subtitle?: string;
173
- };
174
- type CreatedElement = {
175
- elementId: string;
176
- model: V1ElementModelProps;
177
- createParams: CreateElementParams;
178
- };
179
- type CreatedElementsResult = {
180
- createdElements: CreatedElement[];
181
- };
182
-
183
- declare const createElements: ({ elements, title, subtitle, }: CreateNestedElementsParams) => CreatedElementsResult;
184
-
185
233
  type DuplicateElementsParams = {
186
234
  elementIds: string[];
187
235
  title: string;
188
236
  subtitle?: string;
189
- onCreate?: (duplicatedElements: DuplicatedElement[]) => DuplicatedElement[];
237
+ onCreate?: (duplicatedElements: DuplicatedElement[]) => void;
190
238
  };
191
239
  type DuplicatedElement = {
192
240
  id: string;
@@ -200,21 +248,77 @@ type DuplicatedElementsResult = {
200
248
  duplicatedElements: DuplicatedElement[];
201
249
  };
202
250
 
203
- declare const duplicateElements: ({ elementIds, title, subtitle, onCreate, }: DuplicateElementsParams) => DuplicatedElementsResult;
251
+ declare const duplicateElements: ({ elementIds, title, subtitle, }: DuplicateElementsParams) => DuplicatedElementsResult;
252
+
253
+ declare const generateElementId: () => string;
254
+
255
+ declare function getContainer(id: string): V1Element | null;
256
+ declare const selectElement: (elementId: string) => void;
257
+
258
+ declare function getCurrentDocumentContainer(): V1Element | null;
259
+
260
+ declare function getCurrentDocumentId(): number | null;
261
+
262
+ declare function getElementEditorSettings(elementId: ElementID): V1ElementEditorSettingsProps;
263
+
264
+ declare function getElementLabel(elementId?: ElementID): string;
265
+
266
+ declare const getElementSetting: <TValue>(elementId: ElementID, settingKey: string) => TValue | null;
267
+ declare const getElementSettings: <TValue>(elementId: ElementID, settingKey: string[]) => Record<string, TValue | null>;
268
+
269
+ declare const getElementStyles: (elementID: ElementID) => Record<string, StyleDefinition> | null;
270
+
271
+ declare function getElementType(type: string): ElementType | null;
272
+
273
+ declare function getElements(root?: ElementID): V1Element[];
274
+
275
+ declare function getSelectedElements(): Element[];
276
+
277
+ type WidgetsCache<T> = Record<string, T>;
278
+ declare function getWidgetsCache<T extends V1ElementConfig>(): WidgetsCache<T> | null;
204
279
 
205
280
  type Options = {
206
281
  useHistory?: boolean;
207
282
  at?: number;
283
+ edit?: boolean;
208
284
  };
209
- declare function deleteElement({ elementId, options }: {
285
+ type MoveElementParams = {
210
286
  elementId: string;
287
+ targetContainerId: string;
211
288
  options?: Options;
212
- }): void;
289
+ };
290
+ declare function moveElement({ elementId, targetContainerId, options }: MoveElementParams): V1Element;
291
+
292
+ type MoveElementsParams = {
293
+ moves: MoveElementParams[];
294
+ title: string;
295
+ subtitle?: string;
296
+ onMoveElements?: () => void;
297
+ onRestoreElements?: () => void;
298
+ };
299
+ type OriginalPosition = {
300
+ elementId: string;
301
+ originalContainerId: string;
302
+ originalIndex: number;
303
+ };
304
+ type MovedElement = {
305
+ elementId: string;
306
+ originalPosition: OriginalPosition;
307
+ move: MoveElementParams;
308
+ element: V1Element;
309
+ };
310
+ type MovedElementsResult = {
311
+ movedElements: MovedElement[];
312
+ };
313
+
314
+ declare const moveElements: ({ moves: movesToMake, title, subtitle, onMoveElements, onRestoreElements, }: MoveElementsParams) => MovedElementsResult;
213
315
 
214
316
  type RemoveNestedElementsParams = {
215
317
  elementIds: string[];
216
318
  title: string;
217
319
  subtitle?: string;
320
+ onRemoveElements?: () => void;
321
+ onRestoreElements?: () => void;
218
322
  };
219
323
  type RemovedElement = {
220
324
  elementId: string;
@@ -227,25 +331,19 @@ type RemovedElementsResult = {
227
331
  removedElements: RemovedElement[];
228
332
  };
229
333
 
230
- declare const removeElements: ({ elementIds, title, subtitle, }: RemoveNestedElementsParams) => RemovedElementsResult;
231
-
232
- declare function getContainer(id: string): V1Element | null;
233
- declare const selectElement: (elementId: string) => void;
234
-
235
- declare const getElementSetting: <TValue>(elementId: ElementID, settingKey: string) => TValue | null;
236
- declare const getElementSettings: <TValue>(elementId: ElementID, settingKey: string[]) => Record<string, TValue | null>;
334
+ declare const removeElements: ({ elementIds, title, subtitle, onRemoveElements, onRestoreElements, }: RemoveNestedElementsParams) => RemovedElementsResult;
237
335
 
238
- declare const getElementStyles: (elementID: ElementID) => Record<string, StyleDefinition> | null;
239
-
240
- declare function getElementLabel(elementId: ElementID): string;
241
-
242
- declare function getElements(root?: ElementID): V1Element[];
243
-
244
- declare function getCurrentDocumentId(): number | null;
245
-
246
- declare function getSelectedElements(): Element[];
336
+ type ReplaceElementArgs = {
337
+ currentElement: V1ElementData;
338
+ newElement: Omit<V1ElementModelProps, 'id'>;
339
+ withHistory?: boolean;
340
+ };
341
+ declare const replaceElement: ({ currentElement, newElement, withHistory }: ReplaceElementArgs) => void;
247
342
 
248
- declare function getWidgetsCache(): Record<string, V1ElementConfig> | null;
343
+ declare const updateElementEditorSettings: ({ elementId, settings, }: {
344
+ elementId: string;
345
+ settings: V1ElementModelProps["editor_settings"];
346
+ }) => void;
249
347
 
250
348
  type UpdateElementSettingsArgs = {
251
349
  id: ElementID;
@@ -254,14 +352,19 @@ type UpdateElementSettingsArgs = {
254
352
  };
255
353
  declare const updateElementSettings: ({ id, props, withHistory }: UpdateElementSettingsArgs) => void;
256
354
 
257
- declare const generateElementId: () => string;
258
-
259
- type ReplaceElementArgs = {
260
- currentElement: V1Element;
261
- newElement: Omit<V1ElementModelProps, 'id'>;
262
- withHistory?: boolean;
355
+ type LinkInLinkRestriction = {
356
+ shouldRestrict: true;
357
+ reason: 'ancestor' | 'descendant';
358
+ elementId: string | null;
359
+ } | {
360
+ shouldRestrict: false;
361
+ reason?: never;
362
+ elementId?: never;
263
363
  };
264
- declare const replaceElement: ({ currentElement, newElement, withHistory }: ReplaceElementArgs) => void;
364
+ declare function getLinkInLinkRestriction(elementId: string): LinkInLinkRestriction;
365
+ declare function getAnchoredDescendantId(elementId: string): string | null;
366
+ declare function getAnchoredAncestorId(elementId: string): string | null;
367
+ declare function isElementAnchored(elementId: string): boolean;
265
368
 
266
369
  declare const ELEMENT_STYLE_CHANGE_EVENT = "elementor/editor-v2/editor-elements/style";
267
370
  declare const styleRerenderEvents: (_elementor_editor_v1_adapters.CommandEventDescriptor | _elementor_editor_v1_adapters.WindowEventDescriptor)[];
@@ -282,6 +385,8 @@ declare function shouldCreateNewLocalStyle<T>(payload: {
282
385
  provider: T | null;
283
386
  } | null): boolean;
284
387
 
388
+ declare function deleteElementStyle(elementId: ElementID, styleId: StyleDefinitionID): void;
389
+
285
390
  type UpdateElementStyleArgs = {
286
391
  elementId: ElementID;
287
392
  styleId: StyleDefinition['id'];
@@ -291,20 +396,16 @@ type UpdateElementStyleArgs = {
291
396
  };
292
397
  declare function updateElementStyle(args: UpdateElementStyleArgs): void;
293
398
 
294
- declare function deleteElementStyle(elementId: ElementID, styleId: StyleDefinitionID): void;
399
+ declare const useElementInteractions: (elementId: ElementID) => ElementInteractions;
295
400
 
296
- type LinkInLinkRestriction = {
297
- shouldRestrict: true;
298
- reason: 'ancestor' | 'descendant';
299
- elementId: string | null;
300
- } | {
301
- shouldRestrict: false;
302
- reason?: never;
303
- elementId?: never;
304
- };
305
- declare function getLinkInLinkRestriction(elementId: string): LinkInLinkRestriction;
306
- declare function getAnchoredDescendantId(elementId: string): string | null;
307
- declare function getAnchoredAncestorId(elementId: string): string | null;
308
- declare function isElementAnchored(elementId: string): boolean;
401
+ declare function getElementInteractions(elementId: ElementID): ElementInteractions | undefined;
402
+
403
+ declare const updateElementInteractions: ({ elementId, interactions, }: {
404
+ elementId: string;
405
+ interactions: V1ElementModelProps["interactions"];
406
+ }) => void;
407
+ declare const playElementInteractions: (elementId: string, animationId: string) => void;
408
+
409
+ declare function initMcp(): void;
309
410
 
310
- export { type Control, type ControlItem, type ControlLayout, type ControlsSection, type CreateElementParams, type CreateElementStyleArgs, type DuplicateElementParams, type DuplicateElementsParams, type DuplicatedElement, type DuplicatedElementsResult, ELEMENT_STYLE_CHANGE_EVENT, type Element, type ElementChildren, type ElementID, type ElementType, type LinkInLinkRestriction, type MoveElementParams, type MoveElementsParams, type MovedElement, type MovedElementsResult, type UpdateElementSettingsArgs, type UpdateElementStyleArgs, type V1Element, type V1ElementConfig, type V1ElementModelProps, type V1ElementSettingsProps, createElement, createElementStyle, createElements, deleteElement, deleteElementStyle, duplicateElement, duplicateElements, generateElementId, getAnchoredAncestorId, getAnchoredDescendantId, getContainer, getCurrentDocumentId, getElementLabel, getElementSetting, getElementSettings, getElementStyles, getElements, getLinkInLinkRestriction, getSelectedElements, getWidgetsCache, isElementAnchored, moveElement, moveElements, removeElements, replaceElement, selectElement, shouldCreateNewLocalStyle, styleRerenderEvents, updateElementSettings, updateElementStyle, useElementChildren, useElementSetting, useElementSettings, useElementType, useParentElement, useSelectedElement };
411
+ export { type Control, type ControlItem, type ControlLayout, type ControlsSection, type CreateElementParams, type CreateElementStyleArgs, type DropElementParams, type DuplicateElementParams, type DuplicateElementsParams, type DuplicatedElement, type DuplicatedElementsResult, ELEMENT_STYLE_CHANGE_EVENT, type Element, type ElementChildren, type ElementControl, type ElementID, type ElementInteractions, type ElementModel, type ElementType, type ExtendedWindow, type InteractionItem, type LinkInLinkRestriction, type MoveElementParams, type MoveElementsParams, type MovedElement, type MovedElementsResult, type UpdateElementSettingsArgs, type UpdateElementStyleArgs, type V1Element, type V1ElementConfig, type V1ElementData, type V1ElementEditorSettingsProps, type V1ElementModelProps, type V1ElementSettingsProps, createElement, createElementStyle, createElements, deleteElement, deleteElementStyle, dropElement, duplicateElement, duplicateElements, generateElementId, getAnchoredAncestorId, getAnchoredDescendantId, getContainer, getCurrentDocumentContainer, getCurrentDocumentId, getElementEditorSettings, getElementInteractions, getElementLabel, getElementSetting, getElementSettings, getElementStyles, getElementType, getElements, getLinkInLinkRestriction, getSelectedElements, getWidgetsCache, initMcp as initElementsMcp, isElementAnchored, moveElement, moveElements, playElementInteractions, removeElements, replaceElement, selectElement, shouldCreateNewLocalStyle, styleRerenderEvents, updateElementEditorSettings, updateElementInteractions, updateElementSettings, updateElementStyle, useElementChildren, useElementEditorSettings, useElementInteractions, useElementSetting, useElementSettings, useParentElement, useSelectedElement };