@elementor/editor-components 3.33.0-265 → 3.33.0-266

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.
@@ -3,13 +3,11 @@ import { useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { getElementLabel, type V1ElementData } from '@elementor/editor-elements';
4
4
  import { ThemeProvider } from '@elementor/editor-ui';
5
5
  import { StarIcon } from '@elementor/icons';
6
- import { __useDispatch as useDispatch } from '@elementor/store';
7
6
  import { Alert, Button, FormLabel, Grid, Popover, Snackbar, Stack, TextField, Typography } from '@elementor/ui';
8
- import { generateUniqueId } from '@elementor/utils';
9
7
  import { __ } from '@wordpress/i18n';
10
8
 
11
9
  import { useComponents } from '../../hooks/use-components';
12
- import { slice } from '../../store/store';
10
+ import { createUnpublishedComponent } from '../../store/create-unpublished-component';
13
11
  import { type ComponentFormValues } from '../../types';
14
12
  import { trackComponentEvent } from '../../utils/tracking';
15
13
  import { useForm } from './hooks/use-form';
@@ -19,7 +17,6 @@ import {
19
17
  type ContextMenuEventOptions,
20
18
  getComponentEventData,
21
19
  } from './utils/get-component-event-data';
22
- import { replaceElementWithComponent } from './utils/replace-element-with-component';
23
20
 
24
21
  type SaveAsComponentEventData = {
25
22
  element: V1ElementData;
@@ -43,8 +40,6 @@ export function CreateComponentForm() {
43
40
 
44
41
  const [ resultNotification, setResultNotification ] = useState< ResultNotification | null >( null );
45
42
 
46
- const dispatch = useDispatch();
47
-
48
43
  const eventData = useRef< ComponentEventData | null >( null );
49
44
 
50
45
  useEffect( () => {
@@ -74,26 +69,7 @@ export function CreateComponentForm() {
74
69
  throw new Error( `Can't save element as component: element not found` );
75
70
  }
76
71
 
77
- const uid = generateUniqueId( 'component' );
78
-
79
- dispatch(
80
- slice.actions.addUnpublished( {
81
- uid,
82
- name: values.componentName,
83
- elements: [ element.element ],
84
- } )
85
- );
86
-
87
- dispatch( slice.actions.addCreatedThisSession( uid ) );
88
-
89
- replaceElementWithComponent( element.element, { uid, name: values.componentName } );
90
-
91
- trackComponentEvent( {
92
- action: 'created',
93
- component_uid: uid,
94
- component_name: values.componentName,
95
- ...eventData.current,
96
- } );
72
+ const uid = createUnpublishedComponent( values.componentName, element.element, eventData.current );
97
73
 
98
74
  setResultNotification( {
99
75
  show: true,
@@ -7,6 +7,7 @@ import {
7
7
  type ElementView,
8
8
  type LegacyWindow,
9
9
  } from '@elementor/editor-canvas';
10
+ import { getCurrentDocument } from '@elementor/editor-documents';
10
11
  import { type NumberPropValue } from '@elementor/editor-props';
11
12
  import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';
12
13
  import { __ } from '@wordpress/i18n';
@@ -42,6 +43,12 @@ function createComponentView(
42
43
  legacyWindow = window as unknown as LegacyWindow & ExtendedWindow;
43
44
  eventsManagerConfig = this.legacyWindow.elementorCommon.eventsManager.config;
44
45
 
46
+ isComponentCurrentlyEdited() {
47
+ const currentDocument = getCurrentDocument();
48
+
49
+ return currentDocument?.id === this.getComponentId()?.value;
50
+ }
51
+
45
52
  afterSettingsResolve( settings: { [ key: string ]: unknown } ) {
46
53
  if ( settings.component ) {
47
54
  this.collection = this.legacyWindow.elementor.createBackboneElementsCollection( settings.component );
@@ -118,6 +125,10 @@ function createComponentView(
118
125
  }
119
126
 
120
127
  editComponent( { trigger, location, secondaryLocation }: ContextMenuEventData ) {
128
+ if ( this.isComponentCurrentlyEdited() ) {
129
+ return;
130
+ }
131
+
121
132
  this.switchDocument();
122
133
 
123
134
  const editorSettings = this.model.get( 'editor_settings' );
@@ -0,0 +1,40 @@
1
+ import { type V1ElementData } from '@elementor/editor-elements';
2
+ import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';
3
+ import { __dispatch as dispatch } from '@elementor/store';
4
+ import { generateUniqueId } from '@elementor/utils';
5
+
6
+ import { type ComponentEventData } from '../components/create-component-form/utils/get-component-event-data';
7
+ import { replaceElementWithComponent } from '../components/create-component-form/utils/replace-element-with-component';
8
+ import { trackComponentEvent } from '../utils/tracking';
9
+ import { slice } from './store';
10
+
11
+ export function createUnpublishedComponent(
12
+ name: string,
13
+ element: V1ElementData,
14
+ eventData: ComponentEventData | null
15
+ ) {
16
+ const uid = generateUniqueId( 'component' );
17
+ const componentBase = { uid, name };
18
+
19
+ dispatch(
20
+ slice.actions.addUnpublished( {
21
+ ...componentBase,
22
+ elements: [ element ],
23
+ } )
24
+ );
25
+
26
+ dispatch( slice.actions.addCreatedThisSession( uid ) );
27
+
28
+ replaceElementWithComponent( element, componentBase );
29
+
30
+ trackComponentEvent( {
31
+ action: 'created',
32
+ component_uid: uid,
33
+ component_name: name,
34
+ ...eventData,
35
+ } );
36
+
37
+ runCommand( 'document/save/auto' );
38
+
39
+ return uid;
40
+ }