@elementor/editor-components 3.35.0-385 → 3.35.0-387

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-385",
4
+ "version": "3.35.0-387",
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-385",
44
- "@elementor/editor-canvas": "3.35.0-385",
45
- "@elementor/editor-controls": "3.35.0-385",
46
- "@elementor/editor-documents": "3.35.0-385",
47
- "@elementor/editor-editing-panel": "3.35.0-385",
48
- "@elementor/editor-elements": "3.35.0-385",
49
- "@elementor/editor-elements-panel": "3.35.0-385",
50
- "@elementor/editor-mcp": "3.35.0-385",
51
- "@elementor/editor-panels": "3.35.0-385",
52
- "@elementor/editor-props": "3.35.0-385",
53
- "@elementor/editor-styles-repository": "3.35.0-385",
54
- "@elementor/editor-ui": "3.35.0-385",
55
- "@elementor/editor-v1-adapters": "3.35.0-385",
56
- "@elementor/http-client": "3.35.0-385",
43
+ "@elementor/editor": "3.35.0-387",
44
+ "@elementor/editor-canvas": "3.35.0-387",
45
+ "@elementor/editor-controls": "3.35.0-387",
46
+ "@elementor/editor-documents": "3.35.0-387",
47
+ "@elementor/editor-editing-panel": "3.35.0-387",
48
+ "@elementor/editor-elements": "3.35.0-387",
49
+ "@elementor/editor-elements-panel": "3.35.0-387",
50
+ "@elementor/editor-mcp": "3.35.0-387",
51
+ "@elementor/editor-panels": "3.35.0-387",
52
+ "@elementor/editor-props": "3.35.0-387",
53
+ "@elementor/editor-styles-repository": "3.35.0-387",
54
+ "@elementor/editor-ui": "3.35.0-387",
55
+ "@elementor/editor-v1-adapters": "3.35.0-387",
56
+ "@elementor/http-client": "3.35.0-387",
57
57
  "@elementor/icons": "^1.63.0",
58
- "@elementor/mixpanel": "3.35.0-385",
59
- "@elementor/query": "3.35.0-385",
60
- "@elementor/schema": "3.35.0-385",
61
- "@elementor/store": "3.35.0-385",
58
+ "@elementor/mixpanel": "3.35.0-387",
59
+ "@elementor/query": "3.35.0-387",
60
+ "@elementor/schema": "3.35.0-387",
61
+ "@elementor/store": "3.35.0-387",
62
62
  "@elementor/ui": "1.36.17",
63
- "@elementor/utils": "3.35.0-385",
63
+ "@elementor/utils": "3.35.0-387",
64
64
  "@wordpress/i18n": "^5.13.0",
65
- "@elementor/editor-notifications": "3.35.0-385",
66
- "@elementor/editor-current-user": "3.35.0-385"
65
+ "@elementor/editor-notifications": "3.35.0-387",
66
+ "@elementor/editor-current-user": "3.35.0-387"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "react": "^18.3.1",
@@ -35,7 +35,7 @@ type ContextMenuGroup = {
35
35
  actions: ContextMenuAction[];
36
36
  };
37
37
 
38
- export const TYPE = 'e-component';
38
+ export const COMPONENT_WIDGET_TYPE = 'e-component';
39
39
 
40
40
  const updateGroups = ( groups: ContextMenuGroup[], config: ContextMenuGroupConfig ): ContextMenuGroup[] => {
41
41
  const disableMap = new Map( Object.entries( config.disable ?? {} ) );
@@ -0,0 +1,118 @@
1
+ import { getContainer, updateElementSettings, type V1Element } from '@elementor/editor-elements';
2
+ import { registerDataHook } from '@elementor/editor-v1-adapters';
3
+ import { generateUniqueId } from '@elementor/utils';
4
+
5
+ import { componentInstanceOverridePropTypeUtil } from '../prop-types/component-instance-override-prop-type';
6
+ import { componentInstanceOverridesPropTypeUtil } from '../prop-types/component-instance-overrides-prop-type';
7
+ import {
8
+ componentInstancePropTypeUtil,
9
+ type ComponentInstancePropValue,
10
+ } from '../prop-types/component-instance-prop-type';
11
+ import { type ComponentOverride } from '../types';
12
+ import { isComponentInstance } from '../utils/is-component-instance';
13
+
14
+ export function initRegenerateOverrideKeys() {
15
+ registerDataHook( 'after', 'document/elements/duplicate', ( _args, result: V1Element | V1Element[] ) => {
16
+ regenerateOverrideKeysForContainers( result );
17
+ } );
18
+
19
+ registerDataHook( 'after', 'document/elements/paste', ( _args, result: V1Element | V1Element[] ) => {
20
+ regenerateOverrideKeysForContainers( result );
21
+ } );
22
+
23
+ registerDataHook( 'after', 'document/elements/import', ( _args, result: V1Element | V1Element[] ) => {
24
+ regenerateOverrideKeysForContainers( result );
25
+ } );
26
+ }
27
+
28
+ export function regenerateOverrideKeysForContainers( result: V1Element | V1Element[] ) {
29
+ const containers = Array.isArray( result ) ? result : [ result ];
30
+
31
+ containers.forEach( ( container ) => {
32
+ regenerateOverrideKeysRecursive( container.id );
33
+ } );
34
+ }
35
+
36
+ function regenerateOverrideKeysRecursive( elementId: string ) {
37
+ const container = getContainer( elementId );
38
+
39
+ if ( ! container ) {
40
+ return;
41
+ }
42
+
43
+ getAllElements( container ).forEach( regenerateOverrideKeys );
44
+ }
45
+
46
+ function getAllElements( container: V1Element ): V1Element[] {
47
+ const children = ( container.children ?? [] ).flatMap( getAllElements ) ?? [];
48
+
49
+ return [ container, ...children ];
50
+ }
51
+
52
+ function regenerateOverrideKeys( element: V1Element ) {
53
+ if ( ! isComponentInstance( element.model.toJSON() ) ) {
54
+ return;
55
+ }
56
+
57
+ const settings = element.settings?.toJSON() ?? {};
58
+
59
+ if ( ! hasOverrides( settings ) ) {
60
+ return;
61
+ }
62
+
63
+ const componentInstance = settings.component_instance;
64
+ const overrides = componentInstance.value.overrides;
65
+
66
+ const newOverrides = overrides.value.map( ( override: ComponentOverride ) => {
67
+ if ( ! componentInstanceOverridePropTypeUtil.isValid( override ) ) {
68
+ return override;
69
+ }
70
+
71
+ return {
72
+ ...override,
73
+ value: {
74
+ ...override.value,
75
+ override_key: generateUniqueId( 'prop' ),
76
+ },
77
+ };
78
+ } );
79
+
80
+ const newComponentInstance = {
81
+ ...componentInstance,
82
+ value: {
83
+ ...componentInstance.value,
84
+ overrides: {
85
+ ...overrides,
86
+ value: newOverrides,
87
+ },
88
+ },
89
+ };
90
+
91
+ updateElementSettings( {
92
+ id: element.id,
93
+ props: { component_instance: newComponentInstance },
94
+ withHistory: false,
95
+ } );
96
+ }
97
+
98
+ function hasOverrides( settings: Record< string, unknown > ): settings is {
99
+ component_instance: NonNullable< ComponentInstancePropValue > & {
100
+ value: { overrides: { $$type: string; value: ComponentOverride[] } };
101
+ };
102
+ } {
103
+ if ( ! componentInstancePropTypeUtil.isValid( settings?.component_instance ) ) {
104
+ return false;
105
+ }
106
+
107
+ const componentInstance = componentInstancePropTypeUtil.extract( settings?.component_instance );
108
+
109
+ const overrides = componentInstance?.overrides;
110
+
111
+ if ( ! componentInstanceOverridesPropTypeUtil.isValid( overrides ) ) {
112
+ return false;
113
+ }
114
+
115
+ const overridesValue = overrides?.value;
116
+
117
+ return !! overridesValue?.length;
118
+ }
package/src/init.ts CHANGED
@@ -33,7 +33,8 @@ import { openEditModeDialog } from './components/in-edit-mode';
33
33
  import { InstanceEditingPanel } from './components/instance-editing-panel/instance-editing-panel';
34
34
  import { OverridablePropControl } from './components/overridable-props/overridable-prop-control';
35
35
  import { OverridablePropIndicator } from './components/overridable-props/overridable-prop-indicator';
36
- import { createComponentType, TYPE } from './create-component-type';
36
+ import { COMPONENT_WIDGET_TYPE, createComponentType } from './create-component-type';
37
+ import { initRegenerateOverrideKeys } from './hooks/regenerate-override-keys';
37
38
  import { initMcp } from './mcp';
38
39
  import { PopulateStore } from './populate-store';
39
40
  import { componentOverridablePropTypeUtil } from './prop-types/component-overridable-prop-type';
@@ -51,7 +52,7 @@ export function init() {
51
52
  registerSlice( slice );
52
53
  registerPanel( componentPropertiesPanel );
53
54
 
54
- registerElementType( TYPE, ( options: CreateTemplatedElementTypeOptions ) =>
55
+ registerElementType( COMPONENT_WIDGET_TYPE, ( options: CreateTemplatedElementTypeOptions ) =>
55
56
  createComponentType( { ...options, showLockedByModal: openEditModeDialog } )
56
57
  );
57
58
 
@@ -125,5 +126,7 @@ export function init() {
125
126
  settingsTransformersRegistry.register( 'overridable', componentOverridableTransformer );
126
127
  settingsTransformersRegistry.register( 'override', componentOverrideTransformer );
127
128
 
129
+ initRegenerateOverrideKeys();
130
+
128
131
  initMcp();
129
132
  }
@@ -13,6 +13,6 @@ export const componentInstanceOverridePropTypeUtil = createPropUtils(
13
13
  } )
14
14
  );
15
15
 
16
- export type ComponentInstanceOverridePropValue = z.infer<
17
- typeof componentInstanceOverridePropTypeUtil.schema
18
- >[ 'value' ];
16
+ export type ComponentInstanceOverrideProp = z.infer< typeof componentInstanceOverridePropTypeUtil.schema >;
17
+
18
+ export type ComponentInstanceOverridePropValue = ComponentInstanceOverrideProp[ 'value' ];
package/src/types.ts CHANGED
@@ -2,6 +2,11 @@ import { type V1ElementData } from '@elementor/editor-elements';
2
2
  import { type PropValue, type TransformablePropValue } from '@elementor/editor-props';
3
3
  import type { StyleDefinition } from '@elementor/editor-styles';
4
4
 
5
+ import {
6
+ type ComponentInstanceOverrideProp,
7
+ type ComponentInstanceOverridePropValue,
8
+ } from './prop-types/component-instance-override-prop-type';
9
+
5
10
  export type ComponentFormValues = {
6
11
  componentName: string;
7
12
  };
@@ -77,16 +82,9 @@ export type ComponentInstancePropValue< TComponentId extends number | string = n
77
82
 
78
83
  type ComponentOverrides = TransformablePropValue< 'overrides', ComponentOverride[] >;
79
84
 
80
- type ComponentOverride = TransformablePropValue< 'override', ComponentOverridePropValue >;
85
+ export type ComponentOverride = ComponentInstanceOverrideProp;
81
86
 
82
- export type ComponentOverridePropValue = {
83
- override_key: string;
84
- override_value: TransformablePropValue< string >;
85
- schema_source: {
86
- type: string;
87
- id: number;
88
- };
89
- };
87
+ export type ComponentOverridePropValue = ComponentInstanceOverridePropValue;
90
88
 
91
89
  export type ComponentOverridable = {
92
90
  override_key: string;
@@ -1,14 +1,14 @@
1
1
  import { type V1ElementData } from '@elementor/editor-elements';
2
2
 
3
- import { TYPE } from '../create-component-type';
4
3
  import { type ComponentInstancePropValue } from '../types';
5
4
  import { getComponentDocumentData } from './component-document-data';
5
+ import { isComponentInstance } from './is-component-instance';
6
6
 
7
7
  export const getComponentIds = async ( elements: V1ElementData[] ) => {
8
8
  const components = elements.map( async ( { widgetType, elType, elements: childElements, settings } ) => {
9
9
  const ids: number[] = [];
10
10
 
11
- const isComponent = [ widgetType, elType ].includes( TYPE );
11
+ const isComponent = isComponentInstance( { widgetType, elType } );
12
12
 
13
13
  if ( isComponent ) {
14
14
  const componentId = ( settings?.component_instance as ComponentInstancePropValue< number > )?.value
@@ -0,0 +1,7 @@
1
+ import { type V1ElementModelProps } from '@elementor/editor-elements';
2
+
3
+ import { COMPONENT_WIDGET_TYPE } from '../create-component-type';
4
+
5
+ export function isComponentInstance( elementModel: Partial< V1ElementModelProps > ) {
6
+ return [ elementModel.widgetType, elementModel.elType ].includes( COMPONENT_WIDGET_TYPE );
7
+ }