@elementor/editor-elements 3.33.0-98 → 3.35.0-324
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 +204 -69
- package/dist/index.d.ts +204 -69
- package/dist/index.js +1163 -293
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1149 -291
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -5
- package/src/errors.ts +10 -0
- package/src/hooks/use-element-children.ts +12 -12
- package/src/hooks/use-element-editor-settings.ts +12 -0
- package/src/hooks/use-element-interactions.ts +25 -0
- package/src/hooks/use-element-setting.ts +1 -1
- package/src/hooks/use-selected-element.ts +2 -2
- package/src/index.ts +38 -20
- package/src/mcp/elements-tool.ts +345 -0
- package/src/mcp/handlers/common-style-utils.ts +23 -0
- package/src/mcp/handlers/create-element.ts +96 -0
- package/src/mcp/handlers/create-style.ts +42 -0
- package/src/mcp/handlers/delete-element.ts +17 -0
- package/src/mcp/handlers/delete-style.ts +22 -0
- package/src/mcp/handlers/deselect-element.ts +21 -0
- package/src/mcp/handlers/duplicate-element.ts +22 -0
- package/src/mcp/handlers/get-element-props.ts +28 -0
- package/src/mcp/handlers/get-element-schema.ts +17 -0
- package/src/mcp/handlers/get-selected.ts +5 -0
- package/src/mcp/handlers/get-styles.ts +26 -0
- package/src/mcp/handlers/list-available-types.ts +27 -0
- package/src/mcp/handlers/move-element.ts +30 -0
- package/src/mcp/handlers/select-element.ts +25 -0
- package/src/mcp/handlers/update-props.ts +22 -0
- package/src/mcp/handlers/update-styles.ts +45 -0
- package/src/mcp/index.ts +9 -0
- package/src/sync/delete-element.ts +8 -2
- package/src/sync/drop-element.ts +30 -0
- package/src/sync/duplicate-elements.ts +3 -4
- package/src/sync/get-current-document-container.ts +1 -1
- package/src/sync/get-element-editor-settings.ts +8 -0
- package/src/sync/get-element-interactions.ts +15 -0
- package/src/sync/get-element-label.ts +6 -1
- package/src/sync/get-element-type.ts +28 -0
- package/src/sync/get-elements.ts +1 -1
- package/src/sync/get-widgets-cache.ts +4 -3
- package/src/sync/move-element.ts +45 -0
- package/src/sync/move-elements.ts +127 -0
- package/src/sync/remove-elements.ts +11 -0
- package/src/sync/replace-element.ts +50 -12
- package/src/sync/types.ts +32 -3
- package/src/sync/update-element-editor-settings.ts +28 -0
- package/src/sync/update-element-interactions.ts +32 -0
- package/src/types.ts +16 -1
- package/src/hooks/use-element-type.ts +0 -35
|
@@ -1,31 +1,69 @@
|
|
|
1
|
+
import { ElementIndexNotFoundError, ElementNotFoundError, ElementParentNotFoundError } from '../errors';
|
|
1
2
|
import { createElement } from './create-element';
|
|
2
3
|
import { deleteElement } from './delete-element';
|
|
3
4
|
import { getContainer } from './get-container';
|
|
4
|
-
import { type
|
|
5
|
+
import { type V1ElementData, type V1ElementModelProps } from './types';
|
|
6
|
+
|
|
7
|
+
type ElementLocation = {
|
|
8
|
+
containerId: string;
|
|
9
|
+
index: number;
|
|
10
|
+
};
|
|
5
11
|
|
|
6
12
|
type ReplaceElementArgs = {
|
|
7
|
-
currentElement:
|
|
13
|
+
currentElement: V1ElementData;
|
|
8
14
|
newElement: Omit< V1ElementModelProps, 'id' >;
|
|
9
15
|
withHistory?: boolean;
|
|
10
16
|
};
|
|
11
17
|
|
|
12
18
|
export const replaceElement = ( { currentElement, newElement, withHistory = true }: ReplaceElementArgs ) => {
|
|
13
|
-
const
|
|
19
|
+
const { containerId, index } = getNewElementLocation( currentElement, newElement );
|
|
20
|
+
|
|
21
|
+
createElement( {
|
|
22
|
+
containerId,
|
|
23
|
+
model: newElement,
|
|
24
|
+
options: { at: index, useHistory: withHistory },
|
|
25
|
+
} );
|
|
26
|
+
|
|
27
|
+
deleteElement( { elementId: currentElement.id, options: { useHistory: withHistory } } );
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function getNewElementLocation(
|
|
31
|
+
currentElement: V1ElementData,
|
|
32
|
+
newElement: Omit< V1ElementModelProps, 'id' >
|
|
33
|
+
): ElementLocation {
|
|
34
|
+
let location: ElementLocation;
|
|
14
35
|
|
|
36
|
+
const currentElementContainer = getContainer( currentElement.id );
|
|
37
|
+
if ( ! currentElementContainer ) {
|
|
38
|
+
throw new ElementNotFoundError( { context: { elementId: currentElement.id } } );
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const parent = currentElementContainer.parent;
|
|
15
42
|
if ( ! parent ) {
|
|
16
|
-
throw new
|
|
43
|
+
throw new ElementParentNotFoundError( { context: { elementId: currentElement.id } } );
|
|
17
44
|
}
|
|
18
45
|
|
|
19
|
-
const elementIndex =
|
|
46
|
+
const elementIndex = currentElementContainer.view?._index ?? 0;
|
|
20
47
|
if ( elementIndex === undefined || elementIndex === -1 ) {
|
|
21
|
-
throw new
|
|
48
|
+
throw new ElementIndexNotFoundError( { context: { elementId: currentElement.id } } );
|
|
22
49
|
}
|
|
23
50
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
51
|
+
location = { containerId: parent.id, index: elementIndex };
|
|
52
|
+
|
|
53
|
+
// If the element is at document top level and is a widget, wrap it with an empty container
|
|
54
|
+
if ( parent.id === 'document' && newElement.elType === 'widget' ) {
|
|
55
|
+
location = createWrapperForWidget( parent.id, elementIndex );
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return location;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function createWrapperForWidget( parentId: string, elementIndex: number ): ElementLocation {
|
|
62
|
+
const container = createElement( {
|
|
63
|
+
containerId: parentId,
|
|
64
|
+
model: { elType: 'container' },
|
|
65
|
+
options: { at: elementIndex, useHistory: false },
|
|
28
66
|
} );
|
|
29
67
|
|
|
30
|
-
|
|
31
|
-
}
|
|
68
|
+
return { containerId: container.id, index: 0 };
|
|
69
|
+
}
|
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
|
|
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
|
-
}
|