@elementor/editor-editing-panel 4.1.0-824 → 4.1.0-826

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementor/editor-editing-panel",
3
- "version": "4.1.0-824",
3
+ "version": "4.1.0-826",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,31 +39,31 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor": "4.1.0-824",
43
- "@elementor/editor-canvas": "4.1.0-824",
44
- "@elementor/editor-controls": "4.1.0-824",
45
- "@elementor/editor-documents": "4.1.0-824",
46
- "@elementor/editor-elements": "4.1.0-824",
47
- "@elementor/editor-interactions": "4.1.0-824",
48
- "@elementor/editor-notifications": "4.1.0-824",
49
- "@elementor/editor-panels": "4.1.0-824",
50
- "@elementor/editor-props": "4.1.0-824",
51
- "@elementor/editor-responsive": "4.1.0-824",
52
- "@elementor/editor-styles": "4.1.0-824",
53
- "@elementor/editor-styles-repository": "4.1.0-824",
54
- "@elementor/editor-ui": "4.1.0-824",
55
- "@elementor/editor-v1-adapters": "4.1.0-824",
56
- "@elementor/http-client": "4.1.0-824",
42
+ "@elementor/editor": "4.1.0-826",
43
+ "@elementor/editor-canvas": "4.1.0-826",
44
+ "@elementor/editor-controls": "4.1.0-826",
45
+ "@elementor/editor-documents": "4.1.0-826",
46
+ "@elementor/editor-elements": "4.1.0-826",
47
+ "@elementor/editor-interactions": "4.1.0-826",
48
+ "@elementor/editor-notifications": "4.1.0-826",
49
+ "@elementor/editor-panels": "4.1.0-826",
50
+ "@elementor/editor-props": "4.1.0-826",
51
+ "@elementor/editor-responsive": "4.1.0-826",
52
+ "@elementor/editor-styles": "4.1.0-826",
53
+ "@elementor/editor-styles-repository": "4.1.0-826",
54
+ "@elementor/editor-ui": "4.1.0-826",
55
+ "@elementor/editor-v1-adapters": "4.1.0-826",
56
+ "@elementor/http-client": "4.1.0-826",
57
57
  "@elementor/icons": "^1.68.0",
58
- "@elementor/editor-variables": "4.1.0-824",
59
- "@elementor/locations": "4.1.0-824",
60
- "@elementor/menus": "4.1.0-824",
61
- "@elementor/query": "4.1.0-824",
62
- "@elementor/schema": "4.1.0-824",
63
- "@elementor/session": "4.1.0-824",
58
+ "@elementor/editor-variables": "4.1.0-826",
59
+ "@elementor/locations": "4.1.0-826",
60
+ "@elementor/menus": "4.1.0-826",
61
+ "@elementor/query": "4.1.0-826",
62
+ "@elementor/schema": "4.1.0-826",
63
+ "@elementor/session": "4.1.0-826",
64
64
  "@elementor/ui": "1.37.5",
65
- "@elementor/utils": "4.1.0-824",
66
- "@elementor/wp-media": "4.1.0-824",
65
+ "@elementor/utils": "4.1.0-826",
66
+ "@elementor/wp-media": "4.1.0-826",
67
67
  "@wordpress/i18n": "^5.13.0"
68
68
  },
69
69
  "peerDependencies": {
@@ -4,9 +4,12 @@ import {
4
4
  extractValue,
5
5
  isDependency,
6
6
  isDependencyMet,
7
+ isOverridable,
8
+ isTransformable,
7
9
  type Props,
8
10
  type PropsSchema,
9
11
  type PropType,
12
+ rewrapOverridableValue,
10
13
  type TransformablePropValue,
11
14
  } from '@elementor/editor-props';
12
15
  import { getSessionStorageItem, removeSessionStorageItem, setSessionStorageItem } from '@elementor/session';
@@ -94,12 +97,19 @@ export function getUpdatedValues(
94
97
 
95
98
  if ( ! testDependencies.previousValues.isMet ) {
96
99
  const savedValue = retrievePreviousValueFromStorage< Value >( { path: dependency, elementId } );
100
+ const currentValue = extractValue( path, combinedValues, [], {
101
+ unwrapOverridableLeaf: false,
102
+ } ) as Value;
97
103
 
98
104
  removePreviousValueFromStorage( { path: dependency, elementId } );
99
105
 
106
+ const restored = isCompatibleSavedValue( savedValue, currentValue )
107
+ ? savedValue
108
+ : ( propType.default as Value );
109
+
100
110
  return {
101
111
  ...newValues,
102
- ...updateValue( path, savedValue ?? ( propType.default as Value ), combinedValues ),
112
+ ...updateValue( path, restored, combinedValues ),
103
113
  };
104
114
  }
105
115
 
@@ -165,23 +175,88 @@ function evaluatePropType( props: {
165
175
 
166
176
  function updateValue( path: string[], value: Value, values: Values ) {
167
177
  const topPropKey = path[ 0 ];
168
- const newValue: Values = { ...values };
178
+ const root: Values = { ...values };
169
179
 
170
- path.reduce( ( carry: Values | null, key, index ) => {
171
- if ( ! carry ) {
172
- return null;
180
+ let carry: Values = root;
181
+
182
+ for ( let index = 0; index < path.length; index++ ) {
183
+ const key = path[ index ];
184
+ const isLeaf = index === path.length - 1;
185
+
186
+ if ( isLeaf ) {
187
+ carry[ key ] = mergeLeafValue( carry[ key ], value );
188
+ break;
173
189
  }
174
190
 
175
- if ( index === path.length - 1 ) {
176
- carry[ key ] = value ?? null;
191
+ const next = cloneDescent( carry[ key ] );
177
192
 
178
- return ( carry[ key ]?.value as Values ) ?? carry.value;
193
+ if ( ! next ) {
194
+ break;
179
195
  }
180
196
 
181
- return ( carry[ key ]?.value as Values ) ?? carry.value;
182
- }, newValue );
197
+ carry[ key ] = next.replacement;
198
+ carry = next.descended;
199
+ }
200
+
201
+ return { [ topPropKey ]: root[ topPropKey ] ?? null };
202
+ }
203
+
204
+ function cloneDescent( child: Value ): { replacement: Value; descended: Values } | null {
205
+ if ( ! child ) {
206
+ return null;
207
+ }
208
+
209
+ if ( isOverridable( child ) ) {
210
+ const origin = child.value.origin_value;
211
+
212
+ if ( ! origin || ! isTransformable( origin ) ) {
213
+ return null;
214
+ }
215
+
216
+ const descended: Values = { ...( origin.value as Values ) };
217
+ const replacement: Value = {
218
+ ...child,
219
+ value: {
220
+ ...child.value,
221
+ origin_value: { ...origin, value: descended },
222
+ },
223
+ };
224
+
225
+ return { replacement, descended };
226
+ }
227
+
228
+ if ( isTransformable( child ) ) {
229
+ const descended: Values = { ...( child.value as Values ) };
230
+ const replacement: Value = { ...child, value: descended };
231
+
232
+ return { replacement, descended };
233
+ }
234
+
235
+ return null;
236
+ }
237
+
238
+ function isCompatibleSavedValue( saved: Value | null, current: Value ): saved is Value {
239
+ if ( ! saved ) {
240
+ return false;
241
+ }
242
+
243
+ return isOverridable( saved ) === isOverridable( current );
244
+ }
245
+
246
+ function mergeLeafValue( existing: Value, incoming: Value ) {
247
+ if ( incoming === null ) {
248
+ return null;
249
+ }
250
+
251
+ if ( incoming && isOverridable( incoming ) ) {
252
+ return incoming;
253
+ }
254
+
255
+ if ( existing && isOverridable( existing ) && incoming ) {
256
+ return rewrapOverridableValue( existing, incoming );
257
+ }
183
258
 
184
- return { [ topPropKey ]: newValue[ topPropKey ] ?? null };
259
+ return incoming;
185
260
  }
186
261
 
187
262
  function handleUnmetCondition( props: {
@@ -196,7 +271,8 @@ function handleUnmetCondition( props: {
196
271
  ( term ): term is Dependency => 'newValue' in term && !! term.newValue
197
272
  ) as Dependency | undefined;
198
273
  const newValue = termWithNewValue?.newValue ?? null;
199
- const currentValue = extractValue( dependency.split( '.' ), elementValues ) ?? defaultValue;
274
+ const currentValue =
275
+ extractValue( dependency.split( '.' ), elementValues, [], { unwrapOverridableLeaf: false } ) ?? defaultValue;
200
276
 
201
277
  savePreviousValueToStorage( {
202
278
  path: dependency,