@elementor/editor-controls 4.5.0-1154 → 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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@elementor/editor-controls",
3
3
  "description": "This package contains the controls model and utils for the Elementor editor",
4
- "version": "4.5.0-1154",
4
+ "version": "4.5.0-1155",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -40,23 +40,23 @@
40
40
  "dev": "tsup --config=../../tsup.dev.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@elementor/editor-current-user": "4.5.0-1154",
44
- "@elementor/editor-elements": "4.5.0-1154",
45
- "@elementor/editor-props": "4.5.0-1154",
46
- "@elementor/editor-responsive": "4.5.0-1154",
47
- "@elementor/editor-ui": "4.5.0-1154",
48
- "@elementor/editor-v1-adapters": "4.5.0-1154",
49
- "@elementor/env": "4.5.0-1154",
50
- "@elementor/events": "4.5.0-1154",
51
- "@elementor/http-client": "4.5.0-1154",
43
+ "@elementor/editor-current-user": "4.5.0-1155",
44
+ "@elementor/editor-elements": "4.5.0-1155",
45
+ "@elementor/editor-props": "4.5.0-1155",
46
+ "@elementor/editor-responsive": "4.5.0-1155",
47
+ "@elementor/editor-ui": "4.5.0-1155",
48
+ "@elementor/editor-v1-adapters": "4.5.0-1155",
49
+ "@elementor/env": "4.5.0-1155",
50
+ "@elementor/events": "4.5.0-1155",
51
+ "@elementor/http-client": "4.5.0-1155",
52
52
  "@elementor/icons": "~1.78.1",
53
- "@elementor/locations": "4.5.0-1154",
54
- "@elementor/query": "4.5.0-1154",
55
- "@elementor/schema": "4.5.0-1154",
56
- "@elementor/session": "4.5.0-1154",
53
+ "@elementor/locations": "4.5.0-1155",
54
+ "@elementor/query": "4.5.0-1155",
55
+ "@elementor/schema": "4.5.0-1155",
56
+ "@elementor/session": "4.5.0-1155",
57
57
  "@elementor/ui": "1.41.4",
58
- "@elementor/utils": "4.5.0-1154",
59
- "@elementor/wp-media": "4.5.0-1154",
58
+ "@elementor/utils": "4.5.0-1155",
59
+ "@elementor/wp-media": "4.5.0-1155",
60
60
  "@monaco-editor/react": "^4.7.0",
61
61
  "@tanstack/react-virtual": "^3.13.3",
62
62
  "@tiptap/extension-bold": "^3.11.1",
@@ -4,7 +4,7 @@ import { type SizePropValue } from '@elementor/editor-props';
4
4
  import { useSyncExternalState } from '../../../hooks/use-sync-external-state';
5
5
  import { type SetSizeValue } from '../types';
6
6
  import { isExtendedUnit } from '../utils/is-extended-unit';
7
- import { createDefaultSizeValue, resolveSizeOnUnitChange, resolveSizeValue } from '../utils/resolve-size-value';
7
+ import { createEmptySizeValue, resolveSizeOnUnitChange, resolveSizeValue } from '../utils/resolve-size-value';
8
8
  import { useUnitSync } from './use-unit-sync';
9
9
 
10
10
  type SizeValue = SizePropValue[ 'value' ];
@@ -36,7 +36,7 @@ export const useSizeValue = < T extends SizeValue, U extends SizeValue[ 'unit' ]
36
36
  }
37
37
  },
38
38
  persistWhen: ( next ) => hasChanged( next, resolvedValue ),
39
- fallback: () => createDefaultSizeValue( units, defaultUnit ),
39
+ fallback: ( previousValue ) => createEmptySizeValue( previousValue, units, defaultUnit ),
40
40
  } );
41
41
 
42
42
  const [ unit, setUnit ] = useUnitSync( {
@@ -33,13 +33,16 @@ export const UnstableSizeControl = createControl(
33
33
  restoreValue,
34
34
  } = useBoundProp( sizePropTypeUtil );
35
35
  const lastNonAutoValue = useRef< SizePropValue[ 'value' ] | null >( null );
36
+ const clearedUnit = useRef< SizePropValue[ 'value' ][ 'unit' ] | null >( null );
36
37
 
37
- const { sizeValue, placeholder } = resolveBoundPropValue(
38
+ const { sizeValue: resolvedSizeValue, placeholder } = resolveBoundPropValue(
38
39
  value ?? lastNonAutoValue.current,
39
40
  boundPropPlaceholder,
40
41
  propPlaceholder
41
42
  );
42
43
 
44
+ const sizeValue = applyClearedUnit( resolvedSizeValue, value, clearedUnit.current );
45
+
43
46
  const units = getSizeUnits( propType, variant );
44
47
  const defaultUnit = getDefaultUnit( propType );
45
48
 
@@ -47,6 +50,7 @@ export const UnstableSizeControl = createControl(
47
50
  const isRequired = propType.settings.required;
48
51
 
49
52
  if ( shouldNullifyValue( value ) && ! isRequired ) {
53
+ clearedUnit.current = value?.unit ?? null;
50
54
  setValue( null );
51
55
  }
52
56
 
@@ -56,6 +60,8 @@ export const UnstableSizeControl = createControl(
56
60
  };
57
61
 
58
62
  const handleChange = ( newValue: SizePropValue[ 'value' ], options?: CreateOptions, meta?: SetValueMeta ) => {
63
+ clearedUnit.current = null;
64
+
59
65
  if ( isTransitioningFromExtendedUnit( newValue, value ) ) {
60
66
  lastNonAutoValue.current = newValue;
61
67
 
@@ -93,6 +99,18 @@ export const UnstableSizeControl = createControl(
93
99
  }
94
100
  );
95
101
 
102
+ const applyClearedUnit = (
103
+ resolvedValue: SizePropValue[ 'value' ] | null,
104
+ boundValue: SizePropValue[ 'value' ] | null,
105
+ clearedUnit: SizePropValue[ 'value' ][ 'unit' ] | null
106
+ ): SizePropValue[ 'value' ] | null => {
107
+ if ( boundValue || ! resolvedValue || ! clearedUnit ) {
108
+ return resolvedValue;
109
+ }
110
+
111
+ return { ...resolvedValue, unit: clearedUnit } as SizePropValue[ 'value' ];
112
+ };
113
+
96
114
  const isTransitioningFromExtendedUnit = (
97
115
  nextValue: SizePropValue[ 'value' ],
98
116
  previousValue: SizePropValue[ 'value' ]
@@ -60,6 +60,20 @@ export const createDefaultSizeValue = < T extends SizeValue >( units: SizeUnit[]
60
60
  return { size: DEFAULT_SIZE, unit } as T;
61
61
  };
62
62
 
63
+ export const createEmptySizeValue = < T extends SizeValue >(
64
+ previousValue: T | null,
65
+ units: SizeUnit[],
66
+ defaultUnit?: SizeUnit
67
+ ): T => {
68
+ const previousUnit = previousValue?.unit;
69
+
70
+ if ( ! previousUnit || isExtendedUnit( previousUnit ) || ! units.includes( previousUnit ) ) {
71
+ return createDefaultSizeValue< T >( units, defaultUnit );
72
+ }
73
+
74
+ return { size: DEFAULT_SIZE, unit: previousUnit } as T;
75
+ };
76
+
63
77
  const resolveFallbackUnit = < TUnit extends SizeUnit >(
64
78
  unit: TUnit,
65
79
  units: readonly TUnit[],
@@ -116,7 +116,7 @@ export const SizeControl = createControl(
116
116
  const popupState = usePopupState( { variant: 'popover' } );
117
117
 
118
118
  const memorizedExternalState = useMemo(
119
- () => createStateFromSizeProp( sizeValue, actualDefaultUnit ),
119
+ () => ( sizeValue ? createStateFromSizeProp( sizeValue, actualDefaultUnit ) : null ),
120
120
  [ sizeValue, actualDefaultUnit ]
121
121
  );
122
122
 
@@ -125,10 +125,10 @@ export const SizeControl = createControl(
125
125
  setExternal: ( newState: State | null, options, meta ) =>
126
126
  setSizeValue( extractValueFromState( newState ), options, meta ),
127
127
  persistWhen: ( newState ) => !! extractValueFromState( newState ),
128
- fallback: ( newState ) => ( {
129
- unit: newState?.unit ?? actualDefaultUnit,
130
- numeric: newState?.numeric ?? DEFAULT_SIZE,
131
- custom: newState?.custom ?? '',
128
+ fallback: ( prevState ) => ( {
129
+ unit: prevState?.unit && ! isUnitExtendedOption( prevState.unit ) ? prevState.unit : actualDefaultUnit,
130
+ numeric: DEFAULT_SIZE,
131
+ custom: '',
132
132
  } ),
133
133
  } );
134
134