@elementor/editor-editing-panel 4.1.0-823 → 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.mjs CHANGED
@@ -2155,7 +2155,10 @@ import { __ as __8 } from "@wordpress/i18n";
2155
2155
  import {
2156
2156
  extractValue,
2157
2157
  isDependency,
2158
- isDependencyMet
2158
+ isDependencyMet,
2159
+ isOverridable,
2160
+ isTransformable,
2161
+ rewrapOverridableValue
2159
2162
  } from "@elementor/editor-props";
2160
2163
  import { getSessionStorageItem as getSessionStorageItem2, removeSessionStorageItem, setSessionStorageItem as setSessionStorageItem2 } from "@elementor/session";
2161
2164
  function getElementSettingsWithDefaults(propsSchema, elementSettings) {
@@ -2212,10 +2215,14 @@ function getUpdatedValues(values, dependencies, propsSchema, elementValues, elem
2212
2215
  }
2213
2216
  if (!testDependencies.previousValues.isMet) {
2214
2217
  const savedValue = retrievePreviousValueFromStorage({ path: dependency, elementId });
2218
+ const currentValue = extractValue(path, combinedValues, [], {
2219
+ unwrapOverridableLeaf: false
2220
+ });
2215
2221
  removePreviousValueFromStorage({ path: dependency, elementId });
2222
+ const restored = isCompatibleSavedValue(savedValue, currentValue) ? savedValue : propType.default;
2216
2223
  return {
2217
2224
  ...newValues,
2218
- ...updateValue(path, savedValue ?? propType.default, combinedValues)
2225
+ ...updateValue(path, restored, combinedValues)
2219
2226
  };
2220
2227
  }
2221
2228
  return newValues;
@@ -2261,18 +2268,67 @@ function evaluatePropType(props) {
2261
2268
  }
2262
2269
  function updateValue(path, value, values) {
2263
2270
  const topPropKey = path[0];
2264
- const newValue = { ...values };
2265
- path.reduce((carry, key, index) => {
2266
- if (!carry) {
2267
- return null;
2271
+ const root = { ...values };
2272
+ let carry = root;
2273
+ for (let index = 0; index < path.length; index++) {
2274
+ const key = path[index];
2275
+ const isLeaf = index === path.length - 1;
2276
+ if (isLeaf) {
2277
+ carry[key] = mergeLeafValue(carry[key], value);
2278
+ break;
2268
2279
  }
2269
- if (index === path.length - 1) {
2270
- carry[key] = value ?? null;
2271
- return carry[key]?.value ?? carry.value;
2280
+ const next = cloneDescent(carry[key]);
2281
+ if (!next) {
2282
+ break;
2272
2283
  }
2273
- return carry[key]?.value ?? carry.value;
2274
- }, newValue);
2275
- return { [topPropKey]: newValue[topPropKey] ?? null };
2284
+ carry[key] = next.replacement;
2285
+ carry = next.descended;
2286
+ }
2287
+ return { [topPropKey]: root[topPropKey] ?? null };
2288
+ }
2289
+ function cloneDescent(child) {
2290
+ if (!child) {
2291
+ return null;
2292
+ }
2293
+ if (isOverridable(child)) {
2294
+ const origin = child.value.origin_value;
2295
+ if (!origin || !isTransformable(origin)) {
2296
+ return null;
2297
+ }
2298
+ const descended = { ...origin.value };
2299
+ const replacement = {
2300
+ ...child,
2301
+ value: {
2302
+ ...child.value,
2303
+ origin_value: { ...origin, value: descended }
2304
+ }
2305
+ };
2306
+ return { replacement, descended };
2307
+ }
2308
+ if (isTransformable(child)) {
2309
+ const descended = { ...child.value };
2310
+ const replacement = { ...child, value: descended };
2311
+ return { replacement, descended };
2312
+ }
2313
+ return null;
2314
+ }
2315
+ function isCompatibleSavedValue(saved, current) {
2316
+ if (!saved) {
2317
+ return false;
2318
+ }
2319
+ return isOverridable(saved) === isOverridable(current);
2320
+ }
2321
+ function mergeLeafValue(existing, incoming) {
2322
+ if (incoming === null) {
2323
+ return null;
2324
+ }
2325
+ if (incoming && isOverridable(incoming)) {
2326
+ return incoming;
2327
+ }
2328
+ if (existing && isOverridable(existing) && incoming) {
2329
+ return rewrapOverridableValue(existing, incoming);
2330
+ }
2331
+ return incoming;
2276
2332
  }
2277
2333
  function handleUnmetCondition(props) {
2278
2334
  const { failingDependencies, dependency, elementValues, defaultValue, elementId } = props;
@@ -2280,7 +2336,7 @@ function handleUnmetCondition(props) {
2280
2336
  (term) => "newValue" in term && !!term.newValue
2281
2337
  );
2282
2338
  const newValue = termWithNewValue?.newValue ?? null;
2283
- const currentValue = extractValue(dependency.split("."), elementValues) ?? defaultValue;
2339
+ const currentValue = extractValue(dependency.split("."), elementValues, [], { unwrapOverridableLeaf: false }) ?? defaultValue;
2284
2340
  savePreviousValueToStorage({
2285
2341
  path: dependency,
2286
2342
  elementId,
@@ -2510,7 +2566,7 @@ import { stylesRepository as stylesRepository7 } from "@elementor/editor-styles-
2510
2566
  // src/styles-inheritance/create-styles-inheritance.ts
2511
2567
  import {
2512
2568
  isEmpty,
2513
- isTransformable
2569
+ isTransformable as isTransformable2
2514
2570
  } from "@elementor/editor-props";
2515
2571
 
2516
2572
  // src/styles-inheritance/create-snapshots-manager.ts
@@ -2704,7 +2760,7 @@ function getValueByPath(value, path, filterPropType) {
2704
2760
  if (!currentScope) {
2705
2761
  return null;
2706
2762
  }
2707
- if (isTransformable(currentScope)) {
2763
+ if (isTransformable2(currentScope)) {
2708
2764
  return currentScope.value?.[key] ?? null;
2709
2765
  }
2710
2766
  if (typeof currentScope === "object") {
@@ -2714,7 +2770,7 @@ function getValueByPath(value, path, filterPropType) {
2714
2770
  }, value);
2715
2771
  }
2716
2772
  function shouldUseOriginalValue(filterPropType, value) {
2717
- return !!filterPropType && isTransformable(value) && filterPropType.key !== value.$$type;
2773
+ return !!filterPropType && isTransformable2(value) && filterPropType.key !== value.$$type;
2718
2774
  }
2719
2775
  var getFilterPropType = (propType, path) => {
2720
2776
  if (!propType || propType.kind !== "union") {
@@ -5878,7 +5934,7 @@ var filterByLicense = (tags) => {
5878
5934
  // src/dynamics/utils.ts
5879
5935
  import {
5880
5936
  createPropUtils,
5881
- isTransformable as isTransformable2
5937
+ isTransformable as isTransformable3
5882
5938
  } from "@elementor/editor-props";
5883
5939
  import { getElementorConfig as getElementorConfig2 } from "@elementor/editor-v1-adapters";
5884
5940
  import { z } from "@elementor/schema";
@@ -5900,7 +5956,7 @@ var getDynamicPropType = (propType) => {
5900
5956
  return dynamicPropType && isDynamicPropType(dynamicPropType) ? dynamicPropType : null;
5901
5957
  };
5902
5958
  var isDynamicPropValue = (prop) => {
5903
- return isTransformable2(prop) && prop.$$type === DYNAMIC_PROP_TYPE_KEY;
5959
+ return isTransformable3(prop) && prop.$$type === DYNAMIC_PROP_TYPE_KEY;
5904
5960
  };
5905
5961
  var supportsDynamic = (propType) => {
5906
5962
  return !!getDynamicPropType(propType);
@@ -6438,7 +6494,7 @@ function ControlsItemsStack({ items: items3 }) {
6438
6494
 
6439
6495
  // src/dynamics/dynamic-transformer.ts
6440
6496
  import { createTransformer } from "@elementor/editor-canvas";
6441
- import { isTransformable as isTransformable3 } from "@elementor/editor-props";
6497
+ import { isTransformable as isTransformable4 } from "@elementor/editor-props";
6442
6498
 
6443
6499
  // src/dynamics/errors.ts
6444
6500
  import { createError as createError2 } from "@elementor/utils";
@@ -6456,7 +6512,7 @@ var dynamicTransformer = createTransformer((value, { propType }) => {
6456
6512
  });
6457
6513
  function simpleTransform(props) {
6458
6514
  const transformed = Object.entries(props).map(([settingKey, settingValue]) => {
6459
- const value = isTransformable3(settingValue) ? settingValue.value : settingValue;
6515
+ const value = isTransformable4(settingValue) ? settingValue.value : settingValue;
6460
6516
  return [settingKey, value];
6461
6517
  });
6462
6518
  return Object.fromEntries(transformed);