@elementor/editor-components 3.33.0-290 → 3.33.0-292

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.
@@ -19,9 +19,11 @@ export const createComponentModel = ( component: ComponentInstanceParams ): Omit
19
19
  elType: 'widget',
20
20
  widgetType: 'e-component',
21
21
  settings: {
22
- component: {
23
- $$type: 'component-id',
24
- value: component.id ?? component.uid,
22
+ component_instance: {
23
+ $$type: 'component-instance',
24
+ value: {
25
+ component_id: component.id ?? component.uid,
26
+ },
25
27
  },
26
28
  },
27
29
  editor_settings: {
@@ -8,12 +8,11 @@ import {
8
8
  type LegacyWindow,
9
9
  } from '@elementor/editor-canvas';
10
10
  import { getCurrentDocument } from '@elementor/editor-documents';
11
- import { type NumberPropValue } from '@elementor/editor-props';
12
11
  import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';
13
12
  import { __ } from '@wordpress/i18n';
14
13
 
15
14
  import { apiClient } from './api';
16
- import { type ExtendedWindow } from './types';
15
+ import { type ComponentInstancePropValue, type ExtendedWindow } from './types';
17
16
  import { trackComponentEvent } from './utils/tracking';
18
17
 
19
18
  type ContextMenuEventData = { location: string; secondaryLocation: string; trigger: string };
@@ -46,16 +45,18 @@ function createComponentView(
46
45
  isComponentCurrentlyEdited() {
47
46
  const currentDocument = getCurrentDocument();
48
47
 
49
- return currentDocument?.id === this.getComponentId()?.value;
48
+ return currentDocument?.id === this.getComponentId();
50
49
  }
51
50
 
52
51
  afterSettingsResolve( settings: { [ key: string ]: unknown } ) {
53
- if ( settings.component ) {
54
- this.collection = this.legacyWindow.elementor.createBackboneElementsCollection( settings.component );
52
+ if ( settings.component_instance ) {
53
+ this.collection = this.legacyWindow.elementor.createBackboneElementsCollection(
54
+ settings.component_instance
55
+ );
55
56
 
56
57
  this.collection.models.forEach( setInactiveRecursively );
57
58
 
58
- settings.component = '<template data-children-placeholder></template>';
59
+ settings.component_instance = '<template data-children-placeholder></template>';
59
60
  }
60
61
 
61
62
  return settings;
@@ -79,12 +80,16 @@ function createComponentView(
79
80
  }
80
81
 
81
82
  getComponentId() {
82
- return this.options?.model?.get( 'settings' )?.get( 'component' ) as NumberPropValue;
83
+ const componentInstance = (
84
+ this.options?.model?.get( 'settings' )?.get( 'component_instance' ) as ComponentInstancePropValue
85
+ )?.value;
86
+
87
+ return componentInstance.component_id;
83
88
  }
84
89
 
85
90
  getContextMenuGroups() {
86
91
  const filteredGroups = super.getContextMenuGroups().filter( ( group ) => group.name !== 'save' );
87
- const componentId = this.getComponentId()?.value as number;
92
+ const componentId = this.getComponentId();
88
93
  if ( ! componentId ) {
89
94
  return filteredGroups;
90
95
  }
@@ -108,15 +113,16 @@ function createComponentView(
108
113
  }
109
114
 
110
115
  async switchDocument() {
116
+ //todo: handle unpublished
111
117
  const { isAllowedToSwitchDocument, lockedBy } = await apiClient.getComponentLockStatus(
112
- this.getComponentId()?.value as number
118
+ this.getComponentId() as number
113
119
  );
114
120
 
115
121
  if ( ! isAllowedToSwitchDocument ) {
116
122
  options.showLockedByModal?.( lockedBy || '' );
117
123
  } else {
118
124
  runCommand( 'editor/documents/switch', {
119
- id: this.getComponentId()?.value as number,
125
+ id: this.getComponentId(),
120
126
  mode: 'autosave',
121
127
  selector: `[data-id="${ this.model.get( 'id' ) }"]`,
122
128
  shouldScroll: false,
@@ -165,7 +171,7 @@ function createComponentView(
165
171
  attributes() {
166
172
  return {
167
173
  ...super.attributes(),
168
- 'data-elementor-id': this.getComponentId().value,
174
+ 'data-elementor-id': this.getComponentId(),
169
175
  };
170
176
  }
171
177
  };
package/src/init.ts CHANGED
@@ -12,7 +12,7 @@ import { __privateListenTo as listenTo, commandStartEvent, registerDataHook } fr
12
12
  import { __registerSlice as registerSlice } from '@elementor/store';
13
13
  import { __ } from '@wordpress/i18n';
14
14
 
15
- import { componentIdTransformer } from './component-id-transformer';
15
+ import { componentInstanceTransformer } from './component-instance-transformer';
16
16
  import { Components } from './components/components-tab/components';
17
17
  import { CreateComponentForm } from './components/create-component-form/create-component-form';
18
18
  import { EditComponent } from './components/edit-component/edit-component';
@@ -81,5 +81,5 @@ export function init() {
81
81
  loadComponentsStyles( ( config?.elements as V1ElementData[] ) ?? [] );
82
82
  } );
83
83
 
84
- settingsTransformersRegistry.register( 'component-id', componentIdTransformer );
84
+ settingsTransformersRegistry.register( 'component-instance', componentInstanceTransformer );
85
85
  }
@@ -1,10 +1,14 @@
1
1
  import { updateElementSettings, type V1ElementData } from '@elementor/editor-elements';
2
- import { type TransformablePropValue } from '@elementor/editor-props';
3
2
  import { __dispatch as dispatch, __getState as getState } from '@elementor/store';
4
3
 
5
4
  import { apiClient } from '../api';
6
5
  import { selectUnpublishedComponents, slice } from '../store/store';
7
- import { type Container, type DocumentSaveStatus, type UnpublishedComponent } from '../types';
6
+ import {
7
+ type ComponentInstancePropValue,
8
+ type Container,
9
+ type DocumentSaveStatus,
10
+ type UnpublishedComponent,
11
+ } from '../types';
8
12
 
9
13
  export async function createComponentsBeforeSave( {
10
14
  container,
@@ -80,8 +84,9 @@ function shouldUpdateElement(
80
84
  uidToComponentId: Map< string, number >
81
85
  ): { shouldUpdate: true; newComponentId: number } | { shouldUpdate: false; newComponentId: null } {
82
86
  if ( element.widgetType === 'e-component' ) {
83
- const currentComponentId = ( element.settings?.component as TransformablePropValue< 'component-id', string > )
84
- ?.value;
87
+ const currentComponentId = ( element.settings?.component_instance as ComponentInstancePropValue< string > )
88
+ ?.value?.component_id;
89
+
85
90
  if ( currentComponentId && uidToComponentId.has( currentComponentId ) ) {
86
91
  return { shouldUpdate: true, newComponentId: uidToComponentId.get( currentComponentId ) as number };
87
92
  }
@@ -93,9 +98,9 @@ function updateElementComponentId( elementId: string, componentId: number ): voi
93
98
  updateElementSettings( {
94
99
  id: elementId,
95
100
  props: {
96
- component: {
97
- $$type: 'component-id',
98
- value: componentId,
101
+ component_instance: {
102
+ $$type: 'component-instance',
103
+ value: { component_id: componentId },
99
104
  },
100
105
  },
101
106
  withHistory: false,
package/src/types.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type V1ElementData } from '@elementor/editor-elements';
2
+ import { type TransformablePropValue } from '@elementor/editor-props';
2
3
  import type { StyleDefinition } from '@elementor/editor-styles';
3
4
 
4
5
  export type ComponentFormValues = {
@@ -46,3 +47,17 @@ export type Container = {
46
47
  };
47
48
  };
48
49
  };
50
+
51
+ export type ComponentInstancePropValue< TComponentId extends number | string = number | string > =
52
+ TransformablePropValue<
53
+ 'component-instance',
54
+ {
55
+ component_id: TComponentId;
56
+ overrides?: ComponentOverride[];
57
+ }
58
+ >;
59
+
60
+ type ComponentOverride = {
61
+ override_key: string;
62
+ value: TransformablePropValue< string >;
63
+ };
@@ -9,7 +9,7 @@ type ComponentDocumentData = {
9
9
  revisions: { current_id: number };
10
10
  };
11
11
 
12
- type ComponentIdTransformerWindow = Window & {
12
+ type ComponentInstanceTransformerWindow = Window & {
13
13
  elementor?: {
14
14
  documents?: {
15
15
  request: ( id: number ) => Promise< ComponentDocumentData >;
@@ -35,7 +35,7 @@ export const invalidateComponentDocumentData = ( id: number ) => {
35
35
  };
36
36
 
37
37
  function getDocumentsManager() {
38
- const extendedWindow = window as unknown as ComponentIdTransformerWindow;
38
+ const extendedWindow = window as unknown as ComponentInstanceTransformerWindow;
39
39
 
40
40
  const documentManager = extendedWindow.elementor?.documents;
41
41
 
@@ -1,5 +1,6 @@
1
1
  import { type V1ElementData } from '@elementor/editor-elements';
2
- import { isTransformable } from '@elementor/editor-props';
2
+
3
+ import { type ComponentInstancePropValue } from '../types';
3
4
 
4
5
  export const getComponentIds = ( elements: V1ElementData[] ) => {
5
6
  const result = elements.flatMap( ( element ) => {
@@ -7,8 +8,13 @@ export const getComponentIds = ( elements: V1ElementData[] ) => {
7
8
 
8
9
  const type = element.widgetType || element.elType;
9
10
 
10
- if ( type === 'e-component' && element.settings?.component && isTransformable( element.settings?.component ) ) {
11
- ids.push( element.settings.component.value );
11
+ if ( type === 'e-component' ) {
12
+ const componentId = ( element.settings?.component_instance as ComponentInstancePropValue< number > )?.value
13
+ ?.component_id;
14
+
15
+ if ( Boolean( componentId ) ) {
16
+ ids.push( componentId );
17
+ }
12
18
  }
13
19
 
14
20
  if ( element.elements ) {