@elementor/editor-components 4.0.0-506 → 4.0.0-509

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": "4.0.0-506",
4
+ "version": "4.0.0-509",
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": "4.0.0-506",
44
- "@elementor/editor-canvas": "4.0.0-506",
45
- "@elementor/editor-controls": "4.0.0-506",
46
- "@elementor/editor-documents": "4.0.0-506",
47
- "@elementor/editor-editing-panel": "4.0.0-506",
48
- "@elementor/editor-elements": "4.0.0-506",
49
- "@elementor/editor-elements-panel": "4.0.0-506",
50
- "@elementor/editor-mcp": "4.0.0-506",
51
- "@elementor/editor-panels": "4.0.0-506",
52
- "@elementor/editor-props": "4.0.0-506",
53
- "@elementor/editor-styles-repository": "4.0.0-506",
54
- "@elementor/editor-ui": "4.0.0-506",
55
- "@elementor/editor-v1-adapters": "4.0.0-506",
56
- "@elementor/http-client": "4.0.0-506",
43
+ "@elementor/editor": "4.0.0-509",
44
+ "@elementor/editor-canvas": "4.0.0-509",
45
+ "@elementor/editor-controls": "4.0.0-509",
46
+ "@elementor/editor-documents": "4.0.0-509",
47
+ "@elementor/editor-editing-panel": "4.0.0-509",
48
+ "@elementor/editor-elements": "4.0.0-509",
49
+ "@elementor/editor-elements-panel": "4.0.0-509",
50
+ "@elementor/editor-mcp": "4.0.0-509",
51
+ "@elementor/editor-panels": "4.0.0-509",
52
+ "@elementor/editor-props": "4.0.0-509",
53
+ "@elementor/editor-styles-repository": "4.0.0-509",
54
+ "@elementor/editor-ui": "4.0.0-509",
55
+ "@elementor/editor-v1-adapters": "4.0.0-509",
56
+ "@elementor/http-client": "4.0.0-509",
57
57
  "@elementor/icons": "^1.63.0",
58
- "@elementor/mixpanel": "4.0.0-506",
59
- "@elementor/query": "4.0.0-506",
60
- "@elementor/schema": "4.0.0-506",
61
- "@elementor/store": "4.0.0-506",
58
+ "@elementor/mixpanel": "4.0.0-509",
59
+ "@elementor/query": "4.0.0-509",
60
+ "@elementor/schema": "4.0.0-509",
61
+ "@elementor/store": "4.0.0-509",
62
62
  "@elementor/ui": "1.36.17",
63
- "@elementor/utils": "4.0.0-506",
63
+ "@elementor/utils": "4.0.0-509",
64
64
  "@wordpress/i18n": "^5.13.0",
65
- "@elementor/editor-notifications": "4.0.0-506",
66
- "@elementor/editor-current-user": "4.0.0-506"
65
+ "@elementor/editor-notifications": "4.0.0-509",
66
+ "@elementor/editor-current-user": "4.0.0-509"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "react": "^18.3.1",
@@ -69,7 +69,7 @@ export function InstanceEditingPanel() {
69
69
  ) : (
70
70
  <Stack direction="column" alignItems="stretch">
71
71
  { groups.map( ( group ) => (
72
- <React.Fragment key={ group.id }>
72
+ <React.Fragment key={ group.id + componentInstanceId }>
73
73
  <OverridePropsGroup
74
74
  group={ group }
75
75
  props={ overridableProps.props }
@@ -36,6 +36,7 @@ import { getPropTypeForComponentOverride } from '../../utils/get-prop-type-for-c
36
36
  import { resolveOverridePropValue } from '../../utils/resolve-override-prop-value';
37
37
  import { ControlLabel } from '../control-label';
38
38
  import { OverrideControlInnerElementNotFoundError } from '../errors';
39
+ import { useResolvedOriginValue } from './use-resolved-origin-value';
39
40
 
40
41
  type Props = {
41
42
  overridableProp: OverridableProp;
@@ -61,6 +62,10 @@ function OverrideControl( { overridableProp, overrides }: Props ) {
61
62
  );
62
63
  const controlReplacements = getControlReplacements();
63
64
 
65
+ const matchingOverride = getMatchingOverride( overrides, overridableProp.overrideKey );
66
+
67
+ const recursiveOriginValue = useResolvedOriginValue( matchingOverride, overridableProp );
68
+
64
69
  const propType = getPropTypeForComponentOverride( overridableProp );
65
70
 
66
71
  if ( ! propType ) {
@@ -79,9 +84,8 @@ function OverrideControl( { overridableProp, overrides }: Props ) {
79
84
  throw new Error( 'Component ID is required' );
80
85
  }
81
86
 
82
- const matchingOverride = getMatchingOverride( overrides, overridableProp.overrideKey );
83
-
84
- const propValue = matchingOverride ? resolveOverridePropValue( matchingOverride ) : overridableProp.originValue;
87
+ const resolvedOverrideValue = matchingOverride ? resolveOverridePropValue( matchingOverride ) : null;
88
+ const propValue = resolvedOverrideValue ?? recursiveOriginValue ?? overridableProp.originValue;
85
89
 
86
90
  const value = {
87
91
  [ overridableProp.overrideKey ]: propValue,
@@ -180,7 +184,7 @@ function getMatchingOverride(
180
184
  overrides: ComponentInstanceOverridesPropValue,
181
185
  overrideKey: string
182
186
  ): ComponentInstanceOverride | null {
183
- return (
187
+ const result =
184
188
  overrides?.find( ( override ) => {
185
189
  const overridableValue = componentOverridablePropTypeUtil.extract( override );
186
190
  let comparedOverrideKey = null;
@@ -193,8 +197,9 @@ function getMatchingOverride(
193
197
  }
194
198
 
195
199
  return comparedOverrideKey === overrideKey;
196
- } ) ?? null
197
- );
200
+ } ) ?? null;
201
+
202
+ return result;
198
203
  }
199
204
 
200
205
  function createOverrideValue( {
@@ -0,0 +1,132 @@
1
+ import { type PropValue } from '@elementor/editor-props';
2
+ import { __useSelector as useSelector } from '@elementor/store';
3
+
4
+ import { componentInstanceOverridePropTypeUtil } from '../../prop-types/component-instance-override-prop-type';
5
+ import { type ComponentInstanceOverride } from '../../prop-types/component-instance-overrides-prop-type';
6
+ import { componentOverridablePropTypeUtil } from '../../prop-types/component-overridable-prop-type';
7
+ import { selectData } from '../../store/store';
8
+ import { type OverridableProp, type PublishedComponent } from '../../types';
9
+
10
+ export function useResolvedOriginValue( override: ComponentInstanceOverride | null, overridableProp: OverridableProp ) {
11
+ const components = useSelector( selectData );
12
+
13
+ return resolveOriginValue( components, override, overridableProp );
14
+ }
15
+
16
+ function resolveOriginValue(
17
+ components: PublishedComponent[],
18
+ matchingOverride: ComponentInstanceOverride | null,
19
+ overridableProp: OverridableProp
20
+ ): PropValue {
21
+ const { originValue: fallbackOriginValue, originPropFields } = overridableProp;
22
+
23
+ if ( hasValue( fallbackOriginValue ) ) {
24
+ return fallbackOriginValue;
25
+ }
26
+
27
+ if ( matchingOverride ) {
28
+ const result = getOriginFromOverride( components, matchingOverride );
29
+
30
+ if ( hasValue( result ) ) {
31
+ return result;
32
+ }
33
+ }
34
+
35
+ const { elementId, propKey } = originPropFields ?? {};
36
+
37
+ if ( elementId && propKey ) {
38
+ return findOriginValueByElementId( components, elementId, propKey );
39
+ }
40
+
41
+ return null;
42
+ }
43
+
44
+ function getOriginFromOverride( components: PublishedComponent[], override: ComponentInstanceOverride ): PropValue {
45
+ const overridableValue = componentOverridablePropTypeUtil.extract( override );
46
+ const innerOverride = overridableValue
47
+ ? componentInstanceOverridePropTypeUtil.extract( overridableValue.origin_value )
48
+ : componentInstanceOverridePropTypeUtil.extract( override );
49
+
50
+ if ( ! innerOverride ) {
51
+ return null;
52
+ }
53
+
54
+ const { schema_source: schemaSource, override_key: overrideKey, override_value: overrideValue } = innerOverride;
55
+ const componentId = schemaSource?.id;
56
+
57
+ if ( ! componentId || ! overrideKey ) {
58
+ return null;
59
+ }
60
+
61
+ const prop = getOverridableProp( components, componentId, overrideKey );
62
+
63
+ if ( hasValue( prop?.originValue ) ) {
64
+ return prop.originValue;
65
+ }
66
+
67
+ if ( prop?.originPropFields?.elementId ) {
68
+ const targetPropKey = prop.originPropFields.propKey ?? prop.propKey;
69
+ const result = findOriginValueByElementId( components, prop.originPropFields.elementId, targetPropKey );
70
+
71
+ if ( hasValue( result ) ) {
72
+ return result;
73
+ }
74
+ }
75
+
76
+ const nestedOverridable = componentOverridablePropTypeUtil.extract( overrideValue );
77
+
78
+ if ( nestedOverridable ) {
79
+ return getOriginFromOverride( components, componentOverridablePropTypeUtil.create( nestedOverridable ) );
80
+ }
81
+
82
+ return null;
83
+ }
84
+
85
+ function findOriginValueByElementId(
86
+ components: PublishedComponent[],
87
+ targetElementId: string,
88
+ targetPropKey: string,
89
+ visited: Set< number > = new Set()
90
+ ): PropValue {
91
+ for ( const component of components ) {
92
+ if ( visited.has( component.id ) ) {
93
+ continue;
94
+ }
95
+ visited.add( component.id );
96
+
97
+ const matchingProp = Object.values( component.overridableProps?.props ?? {} ).find(
98
+ ( { elementId, propKey } ) => elementId === targetElementId && propKey === targetPropKey
99
+ );
100
+
101
+ if ( ! matchingProp ) {
102
+ continue;
103
+ }
104
+
105
+ if ( hasValue( matchingProp.originValue ) ) {
106
+ return matchingProp.originValue;
107
+ }
108
+
109
+ if ( matchingProp.originPropFields?.elementId ) {
110
+ const innerPropKey = matchingProp.originPropFields.propKey ?? targetPropKey;
111
+
112
+ return findOriginValueByElementId(
113
+ components,
114
+ matchingProp.originPropFields.elementId,
115
+ innerPropKey,
116
+ visited
117
+ );
118
+ }
119
+ }
120
+
121
+ return null;
122
+ }
123
+
124
+ function hasValue< T >( value: T | null | undefined ): value is T {
125
+ return value !== null && value !== undefined;
126
+ }
127
+
128
+ function getOverridableProp( components: PublishedComponent[], componentId: number, overrideKey: string ) {
129
+ const component = components.find( ( { id } ) => id === componentId );
130
+
131
+ return component?.overridableProps?.props?.[ overrideKey ];
132
+ }
@@ -121,13 +121,6 @@ export const slice = createSlice( {
121
121
 
122
122
  component.overridableProps = payload.overridableProps;
123
123
  },
124
- clearOverridableProps: ( state, { payload }: PayloadAction< { componentId: ComponentId } > ) => {
125
- const component = state.data.find( ( comp ) => comp.id === payload.componentId );
126
-
127
- if ( component ) {
128
- component.overridableProps = undefined;
129
- }
130
- },
131
124
  rename: ( state, { payload }: PayloadAction< { componentUid: string; name: string } > ) => {
132
125
  const component = state.data.find( ( comp ) => comp.uid === payload.componentUid );
133
126
 
@@ -157,7 +150,7 @@ export const slice = createSlice( {
157
150
  },
158
151
  } );
159
152
 
160
- const selectData = ( state: ComponentsSlice ) => state[ SLICE_NAME ].data;
153
+ export const selectData = ( state: ComponentsSlice ) => state[ SLICE_NAME ].data;
161
154
  export const selectArchivedThisSession = ( state: ComponentsSlice ) => state[ SLICE_NAME ].archivedThisSession;
162
155
  const selectLoadStatus = ( state: ComponentsSlice ) => state[ SLICE_NAME ].loadStatus;
163
156
  const selectStylesDefinitions = ( state: ComponentsSlice ) => state[ SLICE_NAME ].styles ?? {};
@@ -3,7 +3,7 @@ import { type V1ElementData } from '@elementor/editor-elements';
3
3
 
4
4
  import { apiClient } from '../api';
5
5
  import { type DocumentSaveStatus } from '../types';
6
- import { invalidateComponentCache } from '../utils/component-document-data';
6
+ import { invalidateComponentDocumentData } from '../utils/component-document-data';
7
7
  import { getComponentDocuments } from '../utils/get-component-documents';
8
8
 
9
9
  type Options = {
@@ -26,5 +26,5 @@ export async function publishDraftComponentsInPageBeforeSave( { status, elements
26
26
 
27
27
  await apiClient.updateStatuses( draftIds, 'publish' );
28
28
 
29
- draftIds.forEach( ( id ) => invalidateComponentCache( id ) );
29
+ draftIds.forEach( ( id ) => invalidateComponentDocumentData( id ) );
30
30
  }
@@ -1,7 +1,4 @@
1
1
  import { type Document, getV1DocumentsManager } from '@elementor/editor-documents';
2
- import { __dispatch as dispatch } from '@elementor/store';
3
-
4
- import { slice } from '../store/store';
5
2
 
6
3
  type ComponentDocumentData = Document;
7
4
 
@@ -15,10 +12,8 @@ export const getComponentDocumentData = async ( id: number ) => {
15
12
  }
16
13
  };
17
14
 
18
- export const invalidateComponentCache = ( id: number ) => {
15
+ export const invalidateComponentDocumentData = ( id: number ) => {
19
16
  const documentManager = getV1DocumentsManager();
20
17
 
21
18
  documentManager.invalidateCache( id );
22
- dispatch( slice.actions.removeStyles( { id } ) );
23
- dispatch( slice.actions.clearOverridableProps( { componentId: id } ) );
24
19
  };
@@ -1,18 +1,15 @@
1
1
  import { getCurrentDocumentContainer, selectElement } from '@elementor/editor-elements';
2
2
  import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';
3
3
 
4
- import { invalidateComponentCache } from './component-document-data';
5
4
  import { expandNavigator } from './expand-navigator';
6
5
 
7
6
  export async function switchToComponent(
8
- componentId: number,
7
+ componentId: number | string,
9
8
  componentInstanceId?: string | null,
10
9
  element?: HTMLElement | null
11
10
  ) {
12
11
  const selector = getSelector( element, componentInstanceId );
13
12
 
14
- invalidateComponentCache( componentId );
15
-
16
13
  await runCommand( 'editor/documents/switch', {
17
14
  id: componentId,
18
15
  selector,