@elementor/editor-elements 4.4.0-beta3 → 4.4.1

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.
@@ -6,6 +6,7 @@ type Options = {
6
6
  useHistory?: boolean;
7
7
  at?: number;
8
8
  clone?: boolean;
9
+ origin?: string;
9
10
  };
10
11
 
11
12
  export type CreateElementParams = {
@@ -10,6 +10,7 @@ type CreateElementsParams = {
10
10
  elements: CreateElementParams[];
11
11
  title: string;
12
12
  subtitle?: string;
13
+ origin?: string;
13
14
  };
14
15
 
15
16
  type CreatedElement = {
@@ -31,6 +32,7 @@ export const createElements = ( {
31
32
  elements,
32
33
  title,
33
34
  subtitle = __( 'Item added', 'elementor' ),
35
+ origin,
34
36
  }: CreateElementsParams ): CreatedElementsResult => {
35
37
  const undoableCreate = undoable(
36
38
  {
@@ -47,7 +49,7 @@ export const createElements = ( {
47
49
  const element = createElement( {
48
50
  container: parentContainer,
49
51
  ...elementParams,
50
- options: { ...options, useHistory: false },
52
+ options: { ...options, useHistory: false, origin },
51
53
  } );
52
54
 
53
55
  createdElements.push( {
@@ -69,7 +71,7 @@ export const createElements = ( {
69
71
  if ( freshContainer ) {
70
72
  deleteElement( {
71
73
  container: freshContainer,
72
- options: { useHistory: false },
74
+ options: { useHistory: false, origin },
73
75
  } );
74
76
 
75
77
  return;
@@ -91,7 +93,7 @@ export const createElements = ( {
91
93
  const element = createElement( {
92
94
  container: freshParent,
93
95
  model,
94
- options: { ...options, useHistory: false },
96
+ options: { ...options, useHistory: false, origin },
95
97
  } );
96
98
 
97
99
  newElements.push( {
@@ -5,6 +5,7 @@ import { type V1Element } from './types';
5
5
  type Options = {
6
6
  useHistory?: boolean;
7
7
  at?: number;
8
+ origin?: string;
8
9
  };
9
10
 
10
11
  type DeleteElementParams = {
@@ -6,6 +6,7 @@ type Options = {
6
6
  useHistory?: boolean;
7
7
  at?: number;
8
8
  clone?: boolean;
9
+ origin?: string;
9
10
  };
10
11
 
11
12
  export type DuplicateElementParams = {
@@ -14,6 +14,7 @@ type DuplicateElementsParams = {
14
14
  subtitle?: string;
15
15
  onDuplicateElements?: () => void;
16
16
  onRestoreElements?: () => void;
17
+ origin?: string;
17
18
  };
18
19
 
19
20
  type DuplicatedElement = {
@@ -37,6 +38,7 @@ export const duplicateElements = ( {
37
38
  subtitle = __( 'Item duplicated', 'elementor' ),
38
39
  onDuplicateElements,
39
40
  onRestoreElements,
41
+ origin,
40
42
  }: DuplicateElementsParams ): DuplicatedElementsResult => {
41
43
  const undoableDuplicate = undoable(
42
44
  {
@@ -53,7 +55,7 @@ export const duplicateElements = ( {
53
55
 
54
56
  const duplicatedElement = duplicateElement( {
55
57
  element: originalContainer,
56
- options: { useHistory: false },
58
+ options: { useHistory: false, origin },
57
59
  } );
58
60
 
59
61
  if ( ! duplicatedElement.parent ) {
@@ -81,7 +83,7 @@ export const duplicateElements = ( {
81
83
  if ( freshContainer ) {
82
84
  deleteElement( {
83
85
  container: freshContainer,
84
- options: { useHistory: false },
86
+ options: { useHistory: false, origin },
85
87
  } );
86
88
 
87
89
  return;
@@ -104,7 +106,7 @@ export const duplicateElements = ( {
104
106
  const createdElement = createElement( {
105
107
  container: freshParent,
106
108
  model,
107
- options: { useHistory: false, clone: false, at },
109
+ options: { useHistory: false, clone: false, at, origin },
108
110
  } );
109
111
 
110
112
  duplicatedElements.push( {
@@ -0,0 +1,41 @@
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
+ }
@@ -6,6 +6,7 @@ type Options = {
6
6
  useHistory?: boolean;
7
7
  at?: number;
8
8
  edit?: boolean;
9
+ origin?: string;
9
10
  };
10
11
 
11
12
  export type MoveElementParams = {
@@ -23,6 +23,7 @@ type MoveElementsParams = {
23
23
  subtitle?: string;
24
24
  onMoveElements?: () => void;
25
25
  onRestoreElements?: () => void;
26
+ origin?: string;
26
27
  };
27
28
 
28
29
  type MovedElement = {
@@ -48,6 +49,7 @@ export const moveElements = ( {
48
49
  subtitle = __( 'Elements moved', 'elementor' ),
49
50
  onMoveElements,
50
51
  onRestoreElements,
52
+ origin,
51
53
  }: MoveElementsParams ): MovedElementsResult => {
52
54
  const undoableMove = undoable(
53
55
  {
@@ -77,7 +79,7 @@ export const moveElements = ( {
77
79
  const newElement = moveElement( {
78
80
  element: sourceElement,
79
81
  targetContainer: target,
80
- options: { ...options, useHistory: false },
82
+ options: { ...options, useHistory: false, origin },
81
83
  } );
82
84
 
83
85
  movedElements.push( {
@@ -114,6 +116,7 @@ export const moveElements = ( {
114
116
  options: {
115
117
  useHistory: false,
116
118
  at: originalIndex >= 0 ? originalIndex : undefined,
119
+ origin,
117
120
  },
118
121
  } );
119
122
  } );
@@ -144,7 +147,7 @@ export const moveElements = ( {
144
147
  const newElement = moveElement( {
145
148
  element: freshElement,
146
149
  targetContainer: freshTarget,
147
- options: { ...options, useHistory: false },
150
+ options: { ...options, useHistory: false, origin },
148
151
  } );
149
152
 
150
153
  newMovedElements.push( {
@@ -0,0 +1,55 @@
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
+ }
@@ -13,6 +13,7 @@ type RemoveElementsParams = {
13
13
  subtitle?: string;
14
14
  onRemoveElements?: () => void;
15
15
  onRestoreElements?: () => void;
16
+ origin?: string;
16
17
  };
17
18
 
18
19
  type RemovedElement = {
@@ -34,6 +35,7 @@ export const removeElements = ( {
34
35
  subtitle = __( 'Item removed', 'elementor' ),
35
36
  onRemoveElements,
36
37
  onRestoreElements,
38
+ origin,
37
39
  }: RemoveElementsParams ): RemovedElementsResult => {
38
40
  const undoableRemove = undoable(
39
41
  {
@@ -60,7 +62,7 @@ export const removeElements = ( {
60
62
  removedElements.forEach( ( { container } ) => {
61
63
  deleteElement( {
62
64
  container,
63
- options: { useHistory: false },
65
+ options: { useHistory: false, origin },
64
66
  } );
65
67
  } );
66
68
 
@@ -76,7 +78,7 @@ export const removeElements = ( {
76
78
  createElement( {
77
79
  container: freshParent,
78
80
  model,
79
- options: { useHistory: false, at },
81
+ options: { useHistory: false, at, origin },
80
82
  } );
81
83
 
82
84
  return;
@@ -100,7 +102,7 @@ export const removeElements = ( {
100
102
  if ( freshContainer && freshParent ) {
101
103
  deleteElement( {
102
104
  container: freshContainer,
103
- options: { useHistory: false },
105
+ options: { useHistory: false, origin },
104
106
  } );
105
107
 
106
108
  newRemovedElements.push( {
package/src/sync/types.ts CHANGED
@@ -174,6 +174,15 @@ 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 >;
177
186
  };
178
187
 
179
188
  export type V1ElementData = Omit< V1ElementModelProps, 'elements' > & {