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

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/dist/index.js CHANGED
@@ -2200,10 +2200,14 @@ function getUpdatedValues(values, dependencies, propsSchema, elementValues, elem
2200
2200
  }
2201
2201
  if (!testDependencies.previousValues.isMet) {
2202
2202
  const savedValue = retrievePreviousValueFromStorage({ path: dependency, elementId });
2203
+ const currentValue = (0, import_editor_props5.extractValue)(path, combinedValues, [], {
2204
+ unwrapOverridableLeaf: false
2205
+ });
2203
2206
  removePreviousValueFromStorage({ path: dependency, elementId });
2207
+ const restored = isCompatibleSavedValue(savedValue, currentValue) ? savedValue : propType.default;
2204
2208
  return {
2205
2209
  ...newValues,
2206
- ...updateValue(path, savedValue ?? propType.default, combinedValues)
2210
+ ...updateValue(path, restored, combinedValues)
2207
2211
  };
2208
2212
  }
2209
2213
  return newValues;
@@ -2249,18 +2253,67 @@ function evaluatePropType(props) {
2249
2253
  }
2250
2254
  function updateValue(path, value, values) {
2251
2255
  const topPropKey = path[0];
2252
- const newValue = { ...values };
2253
- path.reduce((carry, key, index) => {
2254
- if (!carry) {
2255
- return null;
2256
+ const root = { ...values };
2257
+ let carry = root;
2258
+ for (let index = 0; index < path.length; index++) {
2259
+ const key = path[index];
2260
+ const isLeaf = index === path.length - 1;
2261
+ if (isLeaf) {
2262
+ carry[key] = mergeLeafValue(carry[key], value);
2263
+ break;
2256
2264
  }
2257
- if (index === path.length - 1) {
2258
- carry[key] = value ?? null;
2259
- return carry[key]?.value ?? carry.value;
2265
+ const next = cloneDescent(carry[key]);
2266
+ if (!next) {
2267
+ break;
2268
+ }
2269
+ carry[key] = next.replacement;
2270
+ carry = next.descended;
2271
+ }
2272
+ return { [topPropKey]: root[topPropKey] ?? null };
2273
+ }
2274
+ function cloneDescent(child) {
2275
+ if (!child) {
2276
+ return null;
2277
+ }
2278
+ if ((0, import_editor_props5.isOverridable)(child)) {
2279
+ const origin = child.value.origin_value;
2280
+ if (!origin || !(0, import_editor_props5.isTransformable)(origin)) {
2281
+ return null;
2260
2282
  }
2261
- return carry[key]?.value ?? carry.value;
2262
- }, newValue);
2263
- return { [topPropKey]: newValue[topPropKey] ?? null };
2283
+ const descended = { ...origin.value };
2284
+ const replacement = {
2285
+ ...child,
2286
+ value: {
2287
+ ...child.value,
2288
+ origin_value: { ...origin, value: descended }
2289
+ }
2290
+ };
2291
+ return { replacement, descended };
2292
+ }
2293
+ if ((0, import_editor_props5.isTransformable)(child)) {
2294
+ const descended = { ...child.value };
2295
+ const replacement = { ...child, value: descended };
2296
+ return { replacement, descended };
2297
+ }
2298
+ return null;
2299
+ }
2300
+ function isCompatibleSavedValue(saved, current) {
2301
+ if (!saved) {
2302
+ return false;
2303
+ }
2304
+ return (0, import_editor_props5.isOverridable)(saved) === (0, import_editor_props5.isOverridable)(current);
2305
+ }
2306
+ function mergeLeafValue(existing, incoming) {
2307
+ if (incoming === null) {
2308
+ return null;
2309
+ }
2310
+ if (incoming && (0, import_editor_props5.isOverridable)(incoming)) {
2311
+ return incoming;
2312
+ }
2313
+ if (existing && (0, import_editor_props5.isOverridable)(existing) && incoming) {
2314
+ return (0, import_editor_props5.rewrapOverridableValue)(existing, incoming);
2315
+ }
2316
+ return incoming;
2264
2317
  }
2265
2318
  function handleUnmetCondition(props) {
2266
2319
  const { failingDependencies, dependency, elementValues, defaultValue, elementId } = props;
@@ -2268,7 +2321,7 @@ function handleUnmetCondition(props) {
2268
2321
  (term) => "newValue" in term && !!term.newValue
2269
2322
  );
2270
2323
  const newValue = termWithNewValue?.newValue ?? null;
2271
- const currentValue = (0, import_editor_props5.extractValue)(dependency.split("."), elementValues) ?? defaultValue;
2324
+ const currentValue = (0, import_editor_props5.extractValue)(dependency.split("."), elementValues, [], { unwrapOverridableLeaf: false }) ?? defaultValue;
2272
2325
  savePreviousValueToStorage({
2273
2326
  path: dependency,
2274
2327
  elementId,