@elementor/editor-elements 3.33.0-99 → 3.34.2

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 (51) hide show
  1. package/dist/index.d.mts +274 -119
  2. package/dist/index.d.ts +274 -119
  3. package/dist/index.js +1158 -394
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +1141 -387
  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-element.ts +5 -15
  36. package/src/sync/duplicate-elements.ts +11 -5
  37. package/src/sync/get-current-document-container.ts +1 -1
  38. package/src/sync/get-element-editor-settings.ts +8 -0
  39. package/src/sync/get-element-interactions.ts +15 -0
  40. package/src/sync/get-element-label.ts +6 -1
  41. package/src/sync/get-element-type.ts +28 -0
  42. package/src/sync/get-elements.ts +1 -1
  43. package/src/sync/get-widgets-cache.ts +4 -3
  44. package/src/sync/move-elements.ts +9 -1
  45. package/src/sync/remove-elements.ts +11 -0
  46. package/src/sync/replace-element.ts +50 -12
  47. package/src/sync/types.ts +32 -3
  48. package/src/sync/update-element-editor-settings.ts +28 -0
  49. package/src/sync/update-element-interactions.ts +32 -0
  50. package/src/types.ts +16 -1
  51. package/src/hooks/use-element-type.ts +0 -35
package/src/sync/types.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type PropsSchema, type PropValue } from '@elementor/editor-props';
2
- import { type StyleDefinition, type StyleDefinitionID } from '@elementor/editor-styles';
2
+ import { type ClassState, type StyleDefinition, type StyleDefinitionID } from '@elementor/editor-styles';
3
3
 
4
4
  import { type ControlItem } from '../types';
5
5
 
@@ -44,19 +44,47 @@ export type V1Element = {
44
44
  parent?: V1Element;
45
45
  };
46
46
 
47
+ export type ElementInteractions = {
48
+ version: number;
49
+ items: InteractionItem[];
50
+ };
51
+
52
+ export type InteractionItem = {
53
+ interaction_id?: string;
54
+ animation: {
55
+ animation_type: string;
56
+ animation_id: string;
57
+ };
58
+ };
59
+
47
60
  export type V1ElementModelProps = {
61
+ isLocked?: boolean;
48
62
  widgetType?: string;
49
63
  elType: string;
50
64
  id: string;
51
65
  styles?: Record< StyleDefinitionID, StyleDefinition >;
52
66
  elements?: V1Model< V1ElementModelProps >[];
53
67
  settings?: V1ElementSettingsProps;
68
+ editor_settings?: V1ElementEditorSettingsProps;
69
+ interactions?: string | ElementInteractions;
70
+ };
71
+
72
+ export type V1ElementData = Omit< V1ElementModelProps, 'elements' > & {
73
+ elements?: V1ElementData[];
74
+ };
75
+
76
+ export type V1ElementEditorSettingsProps = {
77
+ title?: string;
78
+ initial_position?: number;
79
+ component_uid?: string;
54
80
  };
55
81
 
56
82
  export type V1ElementSettingsProps = Record< string, PropValue >;
57
83
 
58
- export type V1ElementConfig = {
84
+ export type V1ElementConfig< T = object > = {
59
85
  title: string;
86
+ widgetType?: string;
87
+ elType?: string;
60
88
  controls: object;
61
89
  atomic?: boolean;
62
90
  atomic_controls?: ControlItem[];
@@ -66,7 +94,8 @@ export type V1ElementConfig = {
66
94
  twig_main_template?: string;
67
95
  base_styles?: Record< string, StyleDefinition >;
68
96
  base_styles_dictionary?: Record< string, string >;
69
- };
97
+ atomic_style_states?: ClassState[];
98
+ } & T;
70
99
 
71
100
  type V1Model< T > = {
72
101
  get: < K extends keyof T >( key: K ) => T[ K ];
@@ -0,0 +1,28 @@
1
+ import { __privateRunCommandSync as runCommandSync } from '@elementor/editor-v1-adapters';
2
+
3
+ import { type V1ElementModelProps } from '..';
4
+ import { getContainer } from './get-container';
5
+
6
+ export const updateElementEditorSettings = ( {
7
+ elementId,
8
+ settings,
9
+ }: {
10
+ elementId: string;
11
+ settings: V1ElementModelProps[ 'editor_settings' ];
12
+ } ) => {
13
+ const element = getContainer( elementId );
14
+
15
+ if ( ! element ) {
16
+ throw new Error( `Element with id ${ elementId } not found` );
17
+ }
18
+
19
+ const editorSettings = element.model.get( 'editor_settings' ) ?? {};
20
+
21
+ element.model.set( 'editor_settings', { ...editorSettings, ...settings } );
22
+
23
+ setDocumentModifiedStatus( true );
24
+ };
25
+
26
+ function setDocumentModifiedStatus( status: boolean ) {
27
+ runCommandSync( 'document/save/set-is-modified', { status }, { internal: true } );
28
+ }
@@ -0,0 +1,32 @@
1
+ import { __privateRunCommandSync as runCommandSync } from '@elementor/editor-v1-adapters';
2
+
3
+ import { type V1ElementModelProps } from '..';
4
+ import { getContainer } from './get-container';
5
+
6
+ export const updateElementInteractions = ( {
7
+ elementId,
8
+ interactions,
9
+ }: {
10
+ elementId: string;
11
+ interactions: V1ElementModelProps[ 'interactions' ];
12
+ } ) => {
13
+ const element = getContainer( elementId );
14
+
15
+ if ( ! element ) {
16
+ throw new Error( `Element with id ${ elementId } not found` );
17
+ }
18
+
19
+ element.model.set( 'interactions', interactions );
20
+
21
+ window.dispatchEvent( new CustomEvent( 'elementor/element/update_interactions' ) );
22
+
23
+ setDocumentModifiedStatus( true );
24
+ };
25
+
26
+ export const playElementInteractions = ( elementId: string, animationId: string ) => {
27
+ window.top?.dispatchEvent( new CustomEvent( 'atomic/play_interactions', { detail: { elementId, animationId } } ) );
28
+ };
29
+
30
+ function setDocumentModifiedStatus( status: boolean ) {
31
+ runCommandSync( 'document/save/set-is-modified', { status }, { internal: true } );
32
+ }
package/src/types.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type PropsSchema } from '@elementor/editor-props';
2
+ import { type ClassState } from '@elementor/editor-styles';
2
3
 
3
4
  export type ElementID = string;
4
5
 
@@ -12,6 +13,7 @@ export type ElementType = {
12
13
  controls: ControlItem[];
13
14
  propsSchema: PropsSchema;
14
15
  dependenciesPerTargetMapping?: Record< string, string[] >;
16
+ styleStates?: ClassState[];
15
17
  title: string;
16
18
  };
17
19
 
@@ -39,6 +41,19 @@ export type Control = {
39
41
  };
40
42
  };
41
43
 
42
- export type ControlItem = ControlsSection | Control;
44
+ export type ElementControl = {
45
+ type: 'element-control';
46
+ value: {
47
+ type: string;
48
+ label?: string;
49
+ props: Record< string, unknown >;
50
+ meta?: {
51
+ layout?: ControlLayout;
52
+ topDivider?: boolean;
53
+ };
54
+ };
55
+ };
56
+
57
+ export type ControlItem = ControlsSection | Control | ElementControl;
43
58
 
44
59
  export type ControlLayout = 'full' | 'two-columns' | 'custom';
@@ -1,35 +0,0 @@
1
- import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';
2
-
3
- import { getWidgetsCache } from '../sync/get-widgets-cache';
4
- import { type ElementType } from '../types';
5
-
6
- export function useElementType( type?: string ) {
7
- return useListenTo(
8
- commandEndEvent( 'editor/documents/load' ),
9
- (): ElementType | null => {
10
- if ( ! type ) {
11
- return null;
12
- }
13
-
14
- const widgetsCache = getWidgetsCache();
15
- const elementType = widgetsCache?.[ type ];
16
-
17
- if ( ! elementType?.atomic_controls ) {
18
- return null;
19
- }
20
-
21
- if ( ! elementType?.atomic_props_schema ) {
22
- return null;
23
- }
24
-
25
- return {
26
- key: type,
27
- controls: elementType.atomic_controls,
28
- propsSchema: elementType.atomic_props_schema,
29
- dependenciesPerTargetMapping: elementType.dependencies_per_target_mapping ?? {},
30
- title: elementType.title,
31
- };
32
- },
33
- [ type ]
34
- );
35
- }