@elementor/editor-controls 4.5.0-1153 → 4.5.0-1155

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
@@ -1531,17 +1531,17 @@ var SizeControl = createControl(
1531
1531
  const actualUnits = resolveUnits(propType, enablePropTypeUnits, variant, units2, actualExtendedOptions);
1532
1532
  const popupState = usePopupState2({ variant: "popover" });
1533
1533
  const memorizedExternalState = useMemo2(
1534
- () => createStateFromSizeProp(sizeValue, actualDefaultUnit),
1534
+ () => sizeValue ? createStateFromSizeProp(sizeValue, actualDefaultUnit) : null,
1535
1535
  [sizeValue, actualDefaultUnit]
1536
1536
  );
1537
1537
  const [state, setState] = useSyncExternalState({
1538
1538
  external: memorizedExternalState,
1539
1539
  setExternal: (newState, options, meta) => setSizeValue(extractValueFromState(newState), options, meta),
1540
1540
  persistWhen: (newState) => !!extractValueFromState(newState),
1541
- fallback: (newState) => ({
1542
- unit: newState?.unit ?? actualDefaultUnit,
1543
- numeric: newState?.numeric ?? DEFAULT_SIZE,
1544
- custom: newState?.custom ?? ""
1541
+ fallback: (prevState) => ({
1542
+ unit: prevState?.unit && !isUnitExtendedOption(prevState.unit) ? prevState.unit : actualDefaultUnit,
1543
+ numeric: DEFAULT_SIZE,
1544
+ custom: ""
1545
1545
  })
1546
1546
  });
1547
1547
  const { size: controlSize = DEFAULT_SIZE, unit: controlUnit = actualDefaultUnit } = extractValueFromState(state, true) || {};
@@ -3566,6 +3566,13 @@ var createDefaultSizeValue = (units2, defaultUnit) => {
3566
3566
  }
3567
3567
  return { size: DEFAULT_SIZE2, unit };
3568
3568
  };
3569
+ var createEmptySizeValue = (previousValue, units2, defaultUnit) => {
3570
+ const previousUnit = previousValue?.unit;
3571
+ if (!previousUnit || isExtendedUnit(previousUnit) || !units2.includes(previousUnit)) {
3572
+ return createDefaultSizeValue(units2, defaultUnit);
3573
+ }
3574
+ return { size: DEFAULT_SIZE2, unit: previousUnit };
3575
+ };
3569
3576
  var resolveFallbackUnit = (unit, units2, defaultUnit) => {
3570
3577
  if (units2.includes(unit)) {
3571
3578
  return unit;
@@ -3620,7 +3627,7 @@ var useSizeValue = ({
3620
3627
  }
3621
3628
  },
3622
3629
  persistWhen: (next) => hasChanged(next, resolvedValue),
3623
- fallback: () => createDefaultSizeValue(units2, defaultUnit)
3630
+ fallback: (previousValue) => createEmptySizeValue(previousValue, units2, defaultUnit)
3624
3631
  });
3625
3632
  const [unit, setUnit] = useUnitSync({
3626
3633
  sizeValue,
@@ -4056,16 +4063,19 @@ var UnstableSizeControl = createControl(
4056
4063
  restoreValue
4057
4064
  } = useBoundProp(sizePropTypeUtil4);
4058
4065
  const lastNonAutoValue = useRef13(null);
4059
- const { sizeValue, placeholder } = resolveBoundPropValue(
4066
+ const clearedUnit = useRef13(null);
4067
+ const { sizeValue: resolvedSizeValue, placeholder } = resolveBoundPropValue(
4060
4068
  value ?? lastNonAutoValue.current,
4061
4069
  boundPropPlaceholder,
4062
4070
  propPlaceholder
4063
4071
  );
4072
+ const sizeValue = applyClearedUnit(resolvedSizeValue, value, clearedUnit.current);
4064
4073
  const units2 = getSizeUnits(propType, variant);
4065
4074
  const defaultUnit = getDefaultUnit(propType);
4066
4075
  const handleBlur = () => {
4067
4076
  const isRequired = propType.settings.required;
4068
4077
  if (shouldNullifyValue(value) && !isRequired) {
4078
+ clearedUnit.current = value?.unit ?? null;
4069
4079
  setValue(null);
4070
4080
  }
4071
4081
  if (isRequired) {
@@ -4073,6 +4083,7 @@ var UnstableSizeControl = createControl(
4073
4083
  }
4074
4084
  };
4075
4085
  const handleChange = (newValue, options, meta) => {
4086
+ clearedUnit.current = null;
4076
4087
  if (isTransitioningFromExtendedUnit(newValue, value)) {
4077
4088
  lastNonAutoValue.current = newValue;
4078
4089
  setValue(null);
@@ -4106,6 +4117,12 @@ var UnstableSizeControl = createControl(
4106
4117
  );
4107
4118
  }
4108
4119
  );
4120
+ var applyClearedUnit = (resolvedValue, boundValue, clearedUnit) => {
4121
+ if (boundValue || !resolvedValue || !clearedUnit) {
4122
+ return resolvedValue;
4123
+ }
4124
+ return { ...resolvedValue, unit: clearedUnit };
4125
+ };
4109
4126
  var isTransitioningFromExtendedUnit = (nextValue, previousValue) => {
4110
4127
  return !isExtendedUnit(nextValue.unit) && isExtendedUnit(previousValue?.unit) && nextValue.size === "";
4111
4128
  };