@elementor/editor-elements 4.4.1 → 4.4.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.
- package/dist/index.d.mts +5 -35
- package/dist/index.d.ts +5 -35
- package/dist/index.js +22 -105
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -98
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +0 -7
- package/src/sync/create-element.ts +0 -1
- package/src/sync/create-elements.ts +3 -5
- package/src/sync/delete-element.ts +0 -1
- package/src/sync/duplicate-element.ts +0 -1
- package/src/sync/duplicate-elements.ts +3 -5
- package/src/sync/move-element.ts +0 -1
- package/src/sync/move-elements.ts +2 -5
- package/src/sync/remove-elements.ts +3 -5
- package/src/sync/types.ts +0 -9
- package/src/sync/get-element-widget-markers.ts +0 -41
- package/src/sync/regenerate-local-style-ids.ts +0 -55
|
@@ -10,7 +10,6 @@ type CreateElementsParams = {
|
|
|
10
10
|
elements: CreateElementParams[];
|
|
11
11
|
title: string;
|
|
12
12
|
subtitle?: string;
|
|
13
|
-
origin?: string;
|
|
14
13
|
};
|
|
15
14
|
|
|
16
15
|
type CreatedElement = {
|
|
@@ -32,7 +31,6 @@ export const createElements = ( {
|
|
|
32
31
|
elements,
|
|
33
32
|
title,
|
|
34
33
|
subtitle = __( 'Item added', 'elementor' ),
|
|
35
|
-
origin,
|
|
36
34
|
}: CreateElementsParams ): CreatedElementsResult => {
|
|
37
35
|
const undoableCreate = undoable(
|
|
38
36
|
{
|
|
@@ -49,7 +47,7 @@ export const createElements = ( {
|
|
|
49
47
|
const element = createElement( {
|
|
50
48
|
container: parentContainer,
|
|
51
49
|
...elementParams,
|
|
52
|
-
options: { ...options, useHistory: false
|
|
50
|
+
options: { ...options, useHistory: false },
|
|
53
51
|
} );
|
|
54
52
|
|
|
55
53
|
createdElements.push( {
|
|
@@ -71,7 +69,7 @@ export const createElements = ( {
|
|
|
71
69
|
if ( freshContainer ) {
|
|
72
70
|
deleteElement( {
|
|
73
71
|
container: freshContainer,
|
|
74
|
-
options: { useHistory: false
|
|
72
|
+
options: { useHistory: false },
|
|
75
73
|
} );
|
|
76
74
|
|
|
77
75
|
return;
|
|
@@ -93,7 +91,7 @@ export const createElements = ( {
|
|
|
93
91
|
const element = createElement( {
|
|
94
92
|
container: freshParent,
|
|
95
93
|
model,
|
|
96
|
-
options: { ...options, useHistory: false
|
|
94
|
+
options: { ...options, useHistory: false },
|
|
97
95
|
} );
|
|
98
96
|
|
|
99
97
|
newElements.push( {
|
|
@@ -14,7 +14,6 @@ type DuplicateElementsParams = {
|
|
|
14
14
|
subtitle?: string;
|
|
15
15
|
onDuplicateElements?: () => void;
|
|
16
16
|
onRestoreElements?: () => void;
|
|
17
|
-
origin?: string;
|
|
18
17
|
};
|
|
19
18
|
|
|
20
19
|
type DuplicatedElement = {
|
|
@@ -38,7 +37,6 @@ export const duplicateElements = ( {
|
|
|
38
37
|
subtitle = __( 'Item duplicated', 'elementor' ),
|
|
39
38
|
onDuplicateElements,
|
|
40
39
|
onRestoreElements,
|
|
41
|
-
origin,
|
|
42
40
|
}: DuplicateElementsParams ): DuplicatedElementsResult => {
|
|
43
41
|
const undoableDuplicate = undoable(
|
|
44
42
|
{
|
|
@@ -55,7 +53,7 @@ export const duplicateElements = ( {
|
|
|
55
53
|
|
|
56
54
|
const duplicatedElement = duplicateElement( {
|
|
57
55
|
element: originalContainer,
|
|
58
|
-
options: { useHistory: false
|
|
56
|
+
options: { useHistory: false },
|
|
59
57
|
} );
|
|
60
58
|
|
|
61
59
|
if ( ! duplicatedElement.parent ) {
|
|
@@ -83,7 +81,7 @@ export const duplicateElements = ( {
|
|
|
83
81
|
if ( freshContainer ) {
|
|
84
82
|
deleteElement( {
|
|
85
83
|
container: freshContainer,
|
|
86
|
-
options: { useHistory: false
|
|
84
|
+
options: { useHistory: false },
|
|
87
85
|
} );
|
|
88
86
|
|
|
89
87
|
return;
|
|
@@ -106,7 +104,7 @@ export const duplicateElements = ( {
|
|
|
106
104
|
const createdElement = createElement( {
|
|
107
105
|
container: freshParent,
|
|
108
106
|
model,
|
|
109
|
-
options: { useHistory: false, clone: false, at
|
|
107
|
+
options: { useHistory: false, clone: false, at },
|
|
110
108
|
} );
|
|
111
109
|
|
|
112
110
|
duplicatedElements.push( {
|
package/src/sync/move-element.ts
CHANGED
|
@@ -23,7 +23,6 @@ type MoveElementsParams = {
|
|
|
23
23
|
subtitle?: string;
|
|
24
24
|
onMoveElements?: () => void;
|
|
25
25
|
onRestoreElements?: () => void;
|
|
26
|
-
origin?: string;
|
|
27
26
|
};
|
|
28
27
|
|
|
29
28
|
type MovedElement = {
|
|
@@ -49,7 +48,6 @@ export const moveElements = ( {
|
|
|
49
48
|
subtitle = __( 'Elements moved', 'elementor' ),
|
|
50
49
|
onMoveElements,
|
|
51
50
|
onRestoreElements,
|
|
52
|
-
origin,
|
|
53
51
|
}: MoveElementsParams ): MovedElementsResult => {
|
|
54
52
|
const undoableMove = undoable(
|
|
55
53
|
{
|
|
@@ -79,7 +77,7 @@ export const moveElements = ( {
|
|
|
79
77
|
const newElement = moveElement( {
|
|
80
78
|
element: sourceElement,
|
|
81
79
|
targetContainer: target,
|
|
82
|
-
options: { ...options, useHistory: false
|
|
80
|
+
options: { ...options, useHistory: false },
|
|
83
81
|
} );
|
|
84
82
|
|
|
85
83
|
movedElements.push( {
|
|
@@ -116,7 +114,6 @@ export const moveElements = ( {
|
|
|
116
114
|
options: {
|
|
117
115
|
useHistory: false,
|
|
118
116
|
at: originalIndex >= 0 ? originalIndex : undefined,
|
|
119
|
-
origin,
|
|
120
117
|
},
|
|
121
118
|
} );
|
|
122
119
|
} );
|
|
@@ -147,7 +144,7 @@ export const moveElements = ( {
|
|
|
147
144
|
const newElement = moveElement( {
|
|
148
145
|
element: freshElement,
|
|
149
146
|
targetContainer: freshTarget,
|
|
150
|
-
options: { ...options, useHistory: false
|
|
147
|
+
options: { ...options, useHistory: false },
|
|
151
148
|
} );
|
|
152
149
|
|
|
153
150
|
newMovedElements.push( {
|
|
@@ -13,7 +13,6 @@ type RemoveElementsParams = {
|
|
|
13
13
|
subtitle?: string;
|
|
14
14
|
onRemoveElements?: () => void;
|
|
15
15
|
onRestoreElements?: () => void;
|
|
16
|
-
origin?: string;
|
|
17
16
|
};
|
|
18
17
|
|
|
19
18
|
type RemovedElement = {
|
|
@@ -35,7 +34,6 @@ export const removeElements = ( {
|
|
|
35
34
|
subtitle = __( 'Item removed', 'elementor' ),
|
|
36
35
|
onRemoveElements,
|
|
37
36
|
onRestoreElements,
|
|
38
|
-
origin,
|
|
39
37
|
}: RemoveElementsParams ): RemovedElementsResult => {
|
|
40
38
|
const undoableRemove = undoable(
|
|
41
39
|
{
|
|
@@ -62,7 +60,7 @@ export const removeElements = ( {
|
|
|
62
60
|
removedElements.forEach( ( { container } ) => {
|
|
63
61
|
deleteElement( {
|
|
64
62
|
container,
|
|
65
|
-
options: { useHistory: false
|
|
63
|
+
options: { useHistory: false },
|
|
66
64
|
} );
|
|
67
65
|
} );
|
|
68
66
|
|
|
@@ -78,7 +76,7 @@ export const removeElements = ( {
|
|
|
78
76
|
createElement( {
|
|
79
77
|
container: freshParent,
|
|
80
78
|
model,
|
|
81
|
-
options: { useHistory: false, at
|
|
79
|
+
options: { useHistory: false, at },
|
|
82
80
|
} );
|
|
83
81
|
|
|
84
82
|
return;
|
|
@@ -102,7 +100,7 @@ export const removeElements = ( {
|
|
|
102
100
|
if ( freshContainer && freshParent ) {
|
|
103
101
|
deleteElement( {
|
|
104
102
|
container: freshContainer,
|
|
105
|
-
options: { useHistory: false
|
|
103
|
+
options: { useHistory: false },
|
|
106
104
|
} );
|
|
107
105
|
|
|
108
106
|
newRemovedElements.push( {
|
package/src/sync/types.ts
CHANGED
|
@@ -174,15 +174,6 @@ export type V1ElementModelProps = {
|
|
|
174
174
|
isGlobal?: boolean;
|
|
175
175
|
skipDefaultChildren?: boolean;
|
|
176
176
|
hydrateDefaultChildren?: boolean;
|
|
177
|
-
widget?: V1ElementWidgetMarker;
|
|
178
|
-
part?: string;
|
|
179
|
-
slot?: boolean;
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
export type V1ElementWidgetMarker = {
|
|
183
|
-
id: string;
|
|
184
|
-
version: number;
|
|
185
|
-
values?: Record< string, unknown >;
|
|
186
177
|
};
|
|
187
178
|
|
|
188
179
|
export type V1ElementData = Omit< V1ElementModelProps, 'elements' > & {
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { z } from '@elementor/schema';
|
|
2
|
-
|
|
3
|
-
import { type V1Element, type V1ElementWidgetMarker } from './types';
|
|
4
|
-
|
|
5
|
-
const WIDGET_ID_PATTERN = /^[a-z0-9-]+\/[a-z0-9-]+$/;
|
|
6
|
-
const PART_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
7
|
-
const MIN_VERSION = 1;
|
|
8
|
-
|
|
9
|
-
export const WIDGET_MARKER_KEYS = {
|
|
10
|
-
widget: 'widget',
|
|
11
|
-
part: 'part',
|
|
12
|
-
slot: 'slot',
|
|
13
|
-
} as const;
|
|
14
|
-
|
|
15
|
-
const widgetMarkerSchema = z.object( {
|
|
16
|
-
id: z.string().regex( WIDGET_ID_PATTERN ),
|
|
17
|
-
version: z.number().int().min( MIN_VERSION ),
|
|
18
|
-
values: z.record( z.unknown() ).optional(),
|
|
19
|
-
} );
|
|
20
|
-
|
|
21
|
-
const partSchema = z.string().regex( PART_PATTERN );
|
|
22
|
-
|
|
23
|
-
export function getContainerWidgetMarker( container: V1Element | null ): Required< V1ElementWidgetMarker > | null {
|
|
24
|
-
const result = widgetMarkerSchema.safeParse( container?.model.get( WIDGET_MARKER_KEYS.widget ) );
|
|
25
|
-
|
|
26
|
-
if ( ! result.success ) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return { ...result.data, values: result.data.values ?? {} };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function getContainerPart( container: V1Element | null ): string | null {
|
|
34
|
-
const result = partSchema.safeParse( container?.model.get( WIDGET_MARKER_KEYS.part ) );
|
|
35
|
-
|
|
36
|
-
return result.success ? result.data : null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function isContainerSlot( container: V1Element | null ): boolean {
|
|
40
|
-
return true === container?.model.get( WIDGET_MARKER_KEYS.slot ) && null !== getContainerPart( container );
|
|
41
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { classesPropTypeUtil, type ClassesPropValue, type PropValue } from '@elementor/editor-props';
|
|
2
|
-
import { type StyleDefinition, type StyleDefinitionID } from '@elementor/editor-styles';
|
|
3
|
-
|
|
4
|
-
import { generateElementId } from './generate-element-id';
|
|
5
|
-
import { type V1ElementData, type V1ElementSettingsProps } from './types';
|
|
6
|
-
|
|
7
|
-
// Ts version for atomic-widgets/assets/js/editor/utils/regenerate-local-style-ids.js
|
|
8
|
-
export function regenerateLocalStyleIds( element: V1ElementData ): {
|
|
9
|
-
styles: Record< StyleDefinitionID, StyleDefinition > | undefined;
|
|
10
|
-
settings: V1ElementSettingsProps | undefined;
|
|
11
|
-
} {
|
|
12
|
-
const originalStyles = element.styles;
|
|
13
|
-
|
|
14
|
-
if ( ! originalStyles || Object.keys( originalStyles ).length === 0 ) {
|
|
15
|
-
return { styles: undefined, settings: undefined };
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const newStyles: Record< string, StyleDefinition > = {};
|
|
19
|
-
const styleIdMapping: Record< string, string > = {};
|
|
20
|
-
|
|
21
|
-
for ( const [ originalStyleId, style ] of Object.entries( originalStyles ) ) {
|
|
22
|
-
const newStyleId = generateLocalStyleId( element.id );
|
|
23
|
-
|
|
24
|
-
newStyles[ newStyleId ] = { ...style, id: newStyleId };
|
|
25
|
-
styleIdMapping[ originalStyleId ] = newStyleId;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const settings = element.settings;
|
|
29
|
-
if ( ! settings || Object.keys( settings ).length === 0 ) {
|
|
30
|
-
return { styles: newStyles, settings: undefined };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const updatedSettings = { ...settings };
|
|
34
|
-
|
|
35
|
-
for ( const [ propKey, propValue ] of Object.entries( updatedSettings ) ) {
|
|
36
|
-
if ( isClassesProp( propValue ) && propValue.value.length > 0 ) {
|
|
37
|
-
const updatedClasses = propValue.value.map( ( classId ) => styleIdMapping[ classId ] ?? classId );
|
|
38
|
-
|
|
39
|
-
updatedSettings[ propKey ] = classesPropTypeUtil.create( updatedClasses );
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
styles: newStyles,
|
|
45
|
-
settings: updatedSettings,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function isClassesProp( prop: PropValue ): prop is ClassesPropValue {
|
|
50
|
-
return classesPropTypeUtil.isValid( prop );
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function generateLocalStyleId( elementId: string ): string {
|
|
54
|
-
return `e-${ elementId }-${ generateElementId() }`;
|
|
55
|
-
}
|