@elementor/editor-components 3.35.0-418 → 3.35.0-420

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@elementor/editor-components",
3
3
  "description": "Elementor editor components",
4
- "version": "3.35.0-418",
4
+ "version": "3.35.0-420",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -40,30 +40,30 @@
40
40
  "dev": "tsup --config=../../tsup.dev.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@elementor/editor": "3.35.0-418",
44
- "@elementor/editor-canvas": "3.35.0-418",
45
- "@elementor/editor-controls": "3.35.0-418",
46
- "@elementor/editor-documents": "3.35.0-418",
47
- "@elementor/editor-editing-panel": "3.35.0-418",
48
- "@elementor/editor-elements": "3.35.0-418",
49
- "@elementor/editor-elements-panel": "3.35.0-418",
50
- "@elementor/editor-mcp": "3.35.0-418",
51
- "@elementor/editor-panels": "3.35.0-418",
52
- "@elementor/editor-props": "3.35.0-418",
53
- "@elementor/editor-styles-repository": "3.35.0-418",
54
- "@elementor/editor-ui": "3.35.0-418",
55
- "@elementor/editor-v1-adapters": "3.35.0-418",
56
- "@elementor/http-client": "3.35.0-418",
43
+ "@elementor/editor": "3.35.0-420",
44
+ "@elementor/editor-canvas": "3.35.0-420",
45
+ "@elementor/editor-controls": "3.35.0-420",
46
+ "@elementor/editor-documents": "3.35.0-420",
47
+ "@elementor/editor-editing-panel": "3.35.0-420",
48
+ "@elementor/editor-elements": "3.35.0-420",
49
+ "@elementor/editor-elements-panel": "3.35.0-420",
50
+ "@elementor/editor-mcp": "3.35.0-420",
51
+ "@elementor/editor-panels": "3.35.0-420",
52
+ "@elementor/editor-props": "3.35.0-420",
53
+ "@elementor/editor-styles-repository": "3.35.0-420",
54
+ "@elementor/editor-ui": "3.35.0-420",
55
+ "@elementor/editor-v1-adapters": "3.35.0-420",
56
+ "@elementor/http-client": "3.35.0-420",
57
57
  "@elementor/icons": "^1.63.0",
58
- "@elementor/mixpanel": "3.35.0-418",
59
- "@elementor/query": "3.35.0-418",
60
- "@elementor/schema": "3.35.0-418",
61
- "@elementor/store": "3.35.0-418",
58
+ "@elementor/mixpanel": "3.35.0-420",
59
+ "@elementor/query": "3.35.0-420",
60
+ "@elementor/schema": "3.35.0-420",
61
+ "@elementor/store": "3.35.0-420",
62
62
  "@elementor/ui": "1.36.17",
63
- "@elementor/utils": "3.35.0-418",
63
+ "@elementor/utils": "3.35.0-420",
64
64
  "@wordpress/i18n": "^5.13.0",
65
- "@elementor/editor-notifications": "3.35.0-418",
66
- "@elementor/editor-current-user": "3.35.0-418"
65
+ "@elementor/editor-notifications": "3.35.0-420",
66
+ "@elementor/editor-current-user": "3.35.0-420"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "react": "^18.3.1",
@@ -1,18 +1,10 @@
1
- import { createTransformer, RenderContext } from '@elementor/editor-canvas';
1
+ import { createTransformer } from '@elementor/editor-canvas';
2
2
  import { __getState as getState } from '@elementor/store';
3
3
 
4
4
  import { type ComponentInstanceOverrideProp } from './prop-types/component-instance-override-prop-type';
5
5
  import { selectUnpublishedComponents } from './store/store';
6
6
  import { getComponentDocumentData } from './utils/component-document-data';
7
7
 
8
- type ComponentInstanceContext = {
9
- overrides?: Record< string, unknown >;
10
- };
11
-
12
- export const componentInstanceContext = new RenderContext< ComponentInstanceContext >( 'component-instance', {
13
- overrides: {},
14
- } );
15
-
16
8
  export const componentInstanceTransformer = createTransformer(
17
9
  async ( {
18
10
  component_id: id,
@@ -1,14 +1,13 @@
1
- import { createTransformer, settingsTransformersRegistry } from '@elementor/editor-canvas';
1
+ import { createTransformer, settingsTransformersRegistry, type TransformerOptions } from '@elementor/editor-canvas';
2
2
  import { type PropValue, type TransformablePropValue } from '@elementor/editor-props';
3
3
 
4
- import { componentInstanceContext } from './component-instance-transformer';
5
4
  import { type ComponentOverridable } from './types';
6
5
 
7
6
  export const componentOverridableTransformer = createTransformer(
8
- ( value: ComponentOverridable, options: { key: string } ) => {
9
- const { overrides } = componentInstanceContext.get();
7
+ ( value: ComponentOverridable, options: TransformerOptions ) => {
8
+ const { overrides } = options.renderContext ?? {};
10
9
 
11
- const overrideValue = overrides?.[ value.override_key ];
10
+ const overrideValue = overrides?.[ value.override_key as keyof typeof overrides ];
12
11
 
13
12
  if ( overrideValue ) {
14
13
  const isOverride = isOriginValueOverride( value.origin_value );
@@ -4,13 +4,16 @@ import { getElementLabel, type V1ElementData } from '@elementor/editor-elements'
4
4
  import { notify } from '@elementor/editor-notifications';
5
5
  import { Form as FormElement, ThemeProvider } from '@elementor/editor-ui';
6
6
  import { StarIcon } from '@elementor/icons';
7
+ import { __getState as getState } from '@elementor/store';
7
8
  import { Alert, Button, FormLabel, Grid, Popover, Snackbar, Stack, TextField, Typography } from '@elementor/ui';
8
9
  import { __ } from '@wordpress/i18n';
9
10
 
10
11
  import { useComponents } from '../../hooks/use-components';
11
12
  import { findNonAtomicElementsInElement } from '../../prevent-non-atomic-nesting';
12
13
  import { createUnpublishedComponent } from '../../store/actions/create-unpublished-component';
13
- import { type ComponentFormValues } from '../../types';
14
+ import { selectComponentByUid } from '../../store/store';
15
+ import { type ComponentFormValues, type PublishedComponent } from '../../types';
16
+ import { switchToComponent } from '../../utils/switch-to-component';
14
17
  import { trackComponentEvent } from '../../utils/tracking';
15
18
  import { useForm } from './hooks/use-form';
16
19
  import { createBaseComponentSchema, createSubmitComponentSchema } from './utils/component-form-schema';
@@ -79,13 +82,25 @@ export function CreateComponentForm() {
79
82
  };
80
83
  }, [] );
81
84
 
82
- const handleSave = ( values: ComponentFormValues ) => {
85
+ const handleSave = async ( values: ComponentFormValues ) => {
83
86
  try {
84
87
  if ( ! element ) {
85
88
  throw new Error( `Can't save element as component: element not found` );
86
89
  }
87
90
 
88
- const uid = createUnpublishedComponent( values.componentName, element.element, eventData.current );
91
+ const { uid, instanceId } = await createUnpublishedComponent(
92
+ values.componentName,
93
+ element.element,
94
+ eventData.current
95
+ );
96
+
97
+ const publishedComponentId = ( selectComponentByUid( getState(), uid ) as PublishedComponent )?.id;
98
+
99
+ if ( publishedComponentId ) {
100
+ switchToComponent( publishedComponentId, instanceId );
101
+ } else {
102
+ throw new Error( 'Failed to find published component' );
103
+ }
89
104
 
90
105
  setResultNotification( {
91
106
  show: true,
@@ -9,8 +9,8 @@ type ComponentInstanceParams = {
9
9
  overridableProps?: OverridableProps;
10
10
  };
11
11
 
12
- export const replaceElementWithComponent = ( element: V1ElementData, component: ComponentInstanceParams ) => {
13
- replaceElement( {
12
+ export const replaceElementWithComponent = async ( element: V1ElementData, component: ComponentInstanceParams ) => {
13
+ return await replaceElement( {
14
14
  currentElement: element,
15
15
  newElement: createComponentModel( component ),
16
16
  withHistory: false,
@@ -7,6 +7,8 @@ import {
7
7
  type ElementType,
8
8
  type ElementView,
9
9
  type LegacyWindow,
10
+ type NamespacedRenderContext,
11
+ type RenderContext,
10
12
  } from '@elementor/editor-canvas';
11
13
  import { getCurrentDocument } from '@elementor/editor-documents';
12
14
  import { __getState as getState } from '@elementor/store';
@@ -15,7 +17,7 @@ import { __ } from '@wordpress/i18n';
15
17
  import { apiClient } from './api';
16
18
  import { type ComponentInstanceProp } from './prop-types/component-instance-prop-type';
17
19
  import { type ComponentsSlice, selectComponentByUid } from './store/store';
18
- import { type ExtendedWindow } from './types';
20
+ import { type ComponentRenderContext, type ExtendedWindow } from './types';
19
21
  import { switchToComponent } from './utils/switch-to-component';
20
22
  import { trackComponentEvent } from './utils/tracking';
21
23
 
@@ -104,6 +106,7 @@ function createComponentView(
104
106
  return class extends createTemplatedElementView( options ) {
105
107
  legacyWindow = window as unknown as LegacyWindow & ExtendedWindow;
106
108
  eventsManagerConfig = this.legacyWindow.elementorCommon.eventsManager.config;
109
+ #componentRenderContext: ComponentRenderContext | undefined;
107
110
 
108
111
  isComponentCurrentlyEdited() {
109
112
  const currentDocument = getCurrentDocument();
@@ -111,6 +114,36 @@ function createComponentView(
111
114
  return currentDocument?.id === this.getComponentId();
112
115
  }
113
116
 
117
+ getRenderContext(): NamespacedRenderContext | undefined {
118
+ const namespaceKey = this.getNamespaceKey();
119
+ const parentContext = this._parent?.getRenderContext?.();
120
+ const parentComponentContext = parentContext?.[ namespaceKey ];
121
+
122
+ if ( ! this.#componentRenderContext ) {
123
+ return parentContext;
124
+ }
125
+
126
+ const ownOverrides = this.#componentRenderContext.overrides ?? {};
127
+ const parentOverrides = parentComponentContext?.overrides ?? {};
128
+
129
+ return {
130
+ ...parentContext,
131
+ [ namespaceKey ]: {
132
+ overrides: {
133
+ ...parentOverrides,
134
+ ...ownOverrides,
135
+ },
136
+ },
137
+ };
138
+ }
139
+
140
+ getResolverRenderContext(): RenderContext | undefined {
141
+ const namespaceKey = this.getNamespaceKey();
142
+ const context = this.getRenderContext();
143
+
144
+ return context?.[ namespaceKey ];
145
+ }
146
+
114
147
  afterSettingsResolve( settings: { [ key: string ]: unknown } ) {
115
148
  const componentInstance = settings.component_instance as
116
149
  | {
@@ -120,6 +153,10 @@ function createComponentView(
120
153
  | undefined;
121
154
 
122
155
  if ( componentInstance ) {
156
+ this.#componentRenderContext = {
157
+ overrides: componentInstance.overrides ?? {},
158
+ };
159
+
123
160
  this.collection = this.legacyWindow.elementor.createBackboneElementsCollection(
124
161
  componentInstance.elements
125
162
  );
@@ -9,7 +9,7 @@ import { type OverridableProps } from '../../types';
9
9
  import { trackComponentEvent } from '../../utils/tracking';
10
10
  import { slice } from '../store';
11
11
 
12
- export function createUnpublishedComponent(
12
+ export async function createUnpublishedComponent(
13
13
  name: string,
14
14
  element: V1ElementData,
15
15
  eventData: ComponentEventData | null,
@@ -28,7 +28,7 @@ export function createUnpublishedComponent(
28
28
 
29
29
  dispatch( slice.actions.addCreatedThisSession( generatedUid ) );
30
30
 
31
- replaceElementWithComponent( element, componentBase );
31
+ const componentInstance = await replaceElementWithComponent( element, componentBase );
32
32
 
33
33
  trackComponentEvent( {
34
34
  action: 'created',
@@ -37,7 +37,7 @@ export function createUnpublishedComponent(
37
37
  ...eventData,
38
38
  } );
39
39
 
40
- runCommand( 'document/save/auto' );
40
+ await runCommand( 'document/save/auto' );
41
41
 
42
- return generatedUid;
42
+ return { uid: generatedUid, instanceId: componentInstance.id };
43
43
  }
package/src/types.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type RenderContext } from '@elementor/editor-canvas';
1
2
  import { type V1ElementData } from '@elementor/editor-elements';
2
3
  import { type PropValue, type TransformablePropValue } from '@elementor/editor-props';
3
4
  import type { StyleDefinition } from '@elementor/editor-styles';
@@ -74,6 +75,10 @@ export type ComponentOverridable = {
74
75
  origin_value: TransformablePropValue< string >;
75
76
  };
76
77
 
78
+ export type ComponentRenderContext = RenderContext< {
79
+ overrides?: Record< string, unknown >;
80
+ } >;
81
+
77
82
  export type UpdatedComponentName = {
78
83
  componentId: number;
79
84
  title: string;