@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.js +24 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -16
- package/src/controls/size-control/hooks/use-size-value.ts +2 -2
- package/src/controls/size-control/unstable-size-control.tsx +19 -1
- package/src/controls/size-control/utils/resolve-size-value.ts +14 -0
- package/src/controls/size-control.tsx +5 -5
package/dist/index.js
CHANGED
|
@@ -1658,17 +1658,17 @@ var SizeControl = createControl(
|
|
|
1658
1658
|
const actualUnits = resolveUnits(propType, enablePropTypeUnits, variant, units2, actualExtendedOptions);
|
|
1659
1659
|
const popupState = (0, import_ui17.usePopupState)({ variant: "popover" });
|
|
1660
1660
|
const memorizedExternalState = (0, import_react16.useMemo)(
|
|
1661
|
-
() => createStateFromSizeProp(sizeValue, actualDefaultUnit),
|
|
1661
|
+
() => sizeValue ? createStateFromSizeProp(sizeValue, actualDefaultUnit) : null,
|
|
1662
1662
|
[sizeValue, actualDefaultUnit]
|
|
1663
1663
|
);
|
|
1664
1664
|
const [state, setState] = useSyncExternalState({
|
|
1665
1665
|
external: memorizedExternalState,
|
|
1666
1666
|
setExternal: (newState, options, meta) => setSizeValue(extractValueFromState(newState), options, meta),
|
|
1667
1667
|
persistWhen: (newState) => !!extractValueFromState(newState),
|
|
1668
|
-
fallback: (
|
|
1669
|
-
unit:
|
|
1670
|
-
numeric:
|
|
1671
|
-
custom:
|
|
1668
|
+
fallback: (prevState) => ({
|
|
1669
|
+
unit: prevState?.unit && !isUnitExtendedOption(prevState.unit) ? prevState.unit : actualDefaultUnit,
|
|
1670
|
+
numeric: DEFAULT_SIZE,
|
|
1671
|
+
custom: ""
|
|
1672
1672
|
})
|
|
1673
1673
|
});
|
|
1674
1674
|
const { size: controlSize = DEFAULT_SIZE, unit: controlUnit = actualDefaultUnit } = extractValueFromState(state, true) || {};
|
|
@@ -3664,6 +3664,13 @@ var createDefaultSizeValue = (units2, defaultUnit) => {
|
|
|
3664
3664
|
}
|
|
3665
3665
|
return { size: DEFAULT_SIZE2, unit };
|
|
3666
3666
|
};
|
|
3667
|
+
var createEmptySizeValue = (previousValue, units2, defaultUnit) => {
|
|
3668
|
+
const previousUnit = previousValue?.unit;
|
|
3669
|
+
if (!previousUnit || isExtendedUnit(previousUnit) || !units2.includes(previousUnit)) {
|
|
3670
|
+
return createDefaultSizeValue(units2, defaultUnit);
|
|
3671
|
+
}
|
|
3672
|
+
return { size: DEFAULT_SIZE2, unit: previousUnit };
|
|
3673
|
+
};
|
|
3667
3674
|
var resolveFallbackUnit = (unit, units2, defaultUnit) => {
|
|
3668
3675
|
if (units2.includes(unit)) {
|
|
3669
3676
|
return unit;
|
|
@@ -3718,7 +3725,7 @@ var useSizeValue = ({
|
|
|
3718
3725
|
}
|
|
3719
3726
|
},
|
|
3720
3727
|
persistWhen: (next) => hasChanged(next, resolvedValue),
|
|
3721
|
-
fallback: () =>
|
|
3728
|
+
fallback: (previousValue) => createEmptySizeValue(previousValue, units2, defaultUnit)
|
|
3722
3729
|
});
|
|
3723
3730
|
const [unit, setUnit] = useUnitSync({
|
|
3724
3731
|
sizeValue,
|
|
@@ -4154,16 +4161,19 @@ var UnstableSizeControl = createControl(
|
|
|
4154
4161
|
restoreValue
|
|
4155
4162
|
} = useBoundProp(import_editor_props21.sizePropTypeUtil);
|
|
4156
4163
|
const lastNonAutoValue = (0, import_react40.useRef)(null);
|
|
4157
|
-
const
|
|
4164
|
+
const clearedUnit = (0, import_react40.useRef)(null);
|
|
4165
|
+
const { sizeValue: resolvedSizeValue, placeholder } = resolveBoundPropValue(
|
|
4158
4166
|
value ?? lastNonAutoValue.current,
|
|
4159
4167
|
boundPropPlaceholder,
|
|
4160
4168
|
propPlaceholder
|
|
4161
4169
|
);
|
|
4170
|
+
const sizeValue = applyClearedUnit(resolvedSizeValue, value, clearedUnit.current);
|
|
4162
4171
|
const units2 = getSizeUnits(propType, variant);
|
|
4163
4172
|
const defaultUnit = getDefaultUnit(propType);
|
|
4164
4173
|
const handleBlur = () => {
|
|
4165
4174
|
const isRequired = propType.settings.required;
|
|
4166
4175
|
if (shouldNullifyValue(value) && !isRequired) {
|
|
4176
|
+
clearedUnit.current = value?.unit ?? null;
|
|
4167
4177
|
setValue(null);
|
|
4168
4178
|
}
|
|
4169
4179
|
if (isRequired) {
|
|
@@ -4171,6 +4181,7 @@ var UnstableSizeControl = createControl(
|
|
|
4171
4181
|
}
|
|
4172
4182
|
};
|
|
4173
4183
|
const handleChange = (newValue, options, meta) => {
|
|
4184
|
+
clearedUnit.current = null;
|
|
4174
4185
|
if (isTransitioningFromExtendedUnit(newValue, value)) {
|
|
4175
4186
|
lastNonAutoValue.current = newValue;
|
|
4176
4187
|
setValue(null);
|
|
@@ -4204,6 +4215,12 @@ var UnstableSizeControl = createControl(
|
|
|
4204
4215
|
);
|
|
4205
4216
|
}
|
|
4206
4217
|
);
|
|
4218
|
+
var applyClearedUnit = (resolvedValue, boundValue, clearedUnit) => {
|
|
4219
|
+
if (boundValue || !resolvedValue || !clearedUnit) {
|
|
4220
|
+
return resolvedValue;
|
|
4221
|
+
}
|
|
4222
|
+
return { ...resolvedValue, unit: clearedUnit };
|
|
4223
|
+
};
|
|
4207
4224
|
var isTransitioningFromExtendedUnit = (nextValue, previousValue) => {
|
|
4208
4225
|
return !isExtendedUnit(nextValue.unit) && isExtendedUnit(previousValue?.unit) && nextValue.size === "";
|
|
4209
4226
|
};
|