@elementor/editor-controls 3.35.0-348 → 3.35.0-350

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": "3.35.0-348",
4
+ "version": "3.35.0-350",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -40,22 +40,22 @@
40
40
  "dev": "tsup --config=../../tsup.dev.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@elementor/editor-current-user": "3.35.0-348",
44
- "@elementor/editor-elements": "3.35.0-348",
45
- "@elementor/editor-props": "3.35.0-348",
46
- "@elementor/editor-responsive": "3.35.0-348",
47
- "@elementor/editor-ui": "3.35.0-348",
48
- "@elementor/editor-v1-adapters": "3.35.0-348",
49
- "@elementor/env": "3.35.0-348",
50
- "@elementor/http-client": "3.35.0-348",
43
+ "@elementor/editor-current-user": "3.35.0-350",
44
+ "@elementor/editor-elements": "3.35.0-350",
45
+ "@elementor/editor-props": "3.35.0-350",
46
+ "@elementor/editor-responsive": "3.35.0-350",
47
+ "@elementor/editor-ui": "3.35.0-350",
48
+ "@elementor/editor-v1-adapters": "3.35.0-350",
49
+ "@elementor/env": "3.35.0-350",
50
+ "@elementor/http-client": "3.35.0-350",
51
51
  "@elementor/icons": "^1.62.0",
52
- "@elementor/locations": "3.35.0-348",
53
- "@elementor/mixpanel": "3.35.0-348",
54
- "@elementor/query": "3.35.0-348",
55
- "@elementor/session": "3.35.0-348",
52
+ "@elementor/locations": "3.35.0-350",
53
+ "@elementor/mixpanel": "3.35.0-350",
54
+ "@elementor/query": "3.35.0-350",
55
+ "@elementor/session": "3.35.0-350",
56
56
  "@elementor/ui": "1.36.17",
57
- "@elementor/utils": "3.35.0-348",
58
- "@elementor/wp-media": "3.35.0-348",
57
+ "@elementor/utils": "3.35.0-350",
58
+ "@elementor/wp-media": "3.35.0-350",
59
59
  "@wordpress/i18n": "^5.13.0",
60
60
  "@monaco-editor/react": "^4.7.0",
61
61
  "dayjs": "^1.11.18",
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
- import { type RefObject, useRef } from 'react';
2
+ import { type RefObject, useLayoutEffect, useRef, useState } from 'react';
3
3
  import { dimensionsPropTypeUtil, type PropKey, sizePropTypeUtil } from '@elementor/editor-props';
4
+ import { useActiveBreakpoint } from '@elementor/editor-responsive';
4
5
  import { DetachIcon, LinkIcon, SideBottomIcon, SideLeftIcon, SideRightIcon, SideTopIcon } from '@elementor/icons';
5
6
  import { Grid, Stack, Tooltip } from '@elementor/ui';
6
7
  import { __ } from '@wordpress/i18n';
@@ -12,25 +13,18 @@ import { StyledToggleButton } from '../components/control-toggle-button-group';
12
13
  import { type ExtendedOption } from '../utils/size-control';
13
14
  import { SizeControl } from './size-control';
14
15
 
15
- export const LinkedDimensionsControl = ( {
16
- label,
17
- isSiteRtl = false,
18
- extendedOptions,
19
- min,
20
- }: {
16
+ type Props = {
21
17
  label: string;
22
18
  isSiteRtl?: boolean;
23
19
  extendedOptions?: ExtendedOption[];
24
20
  min?: number;
25
- } ) => {
26
- const {
27
- value: sizeValue,
28
- setValue: setSizeValue,
29
- disabled: sizeDisabled,
30
- placeholder: sizePlaceholder,
31
- } = useBoundProp( sizePropTypeUtil );
21
+ };
22
+
23
+ export const LinkedDimensionsControl = ( { label, isSiteRtl = false, extendedOptions, min }: Props ) => {
32
24
  const gridRowRefs: RefObject< HTMLDivElement >[] = [ useRef( null ), useRef( null ) ];
33
25
 
26
+ const { disabled: sizeDisabled, placeholder: sizePlaceholder } = useBoundProp( sizePropTypeUtil );
27
+
34
28
  const {
35
29
  value: dimensionsValue,
36
30
  setValue: setDimensionsValue,
@@ -39,25 +33,67 @@ export const LinkedDimensionsControl = ( {
39
33
  disabled: dimensionsDisabled,
40
34
  } = useBoundProp( dimensionsPropTypeUtil );
41
35
 
42
- const hasUserValues = !! ( dimensionsValue || sizeValue );
36
+ const { value: masterValue, placeholder: masterPlaceholder, setValue: setMasterValue } = useBoundProp();
37
+
43
38
  const hasPlaceholders = !! ( sizePlaceholder || dimensionsPlaceholder );
44
39
 
45
- const isLinked =
46
- ( ! hasUserValues && ! hasPlaceholders ) || ( hasPlaceholders ? !! sizePlaceholder : !! sizeValue );
40
+ const inferIsLinked = () => {
41
+ if ( dimensionsPropTypeUtil.isValid( masterValue ) ) {
42
+ return false;
43
+ }
44
+
45
+ if ( dimensionsPropTypeUtil.isValid( masterPlaceholder ) ) {
46
+ return false;
47
+ }
48
+
49
+ return true;
50
+ };
51
+
52
+ const [ isLinked, setIsLinked ] = useState( () => inferIsLinked() );
53
+
54
+ const activeBreakpoint = useActiveBreakpoint();
55
+
56
+ useLayoutEffect( () => {
57
+ setIsLinked( inferIsLinked );
58
+ // eslint-disable-next-line react-hooks/exhaustive-deps
59
+ }, [ activeBreakpoint ] );
60
+
47
61
  const onLinkToggle = () => {
48
- if ( ! isLinked ) {
49
- setSizeValue( dimensionsValue[ 'block-start' ]?.value ?? null );
62
+ setIsLinked( ( prev ) => ! prev );
63
+
64
+ if ( ! dimensionsPropTypeUtil.isValid( masterValue ) ) {
65
+ const value = masterValue ? masterValue : null;
66
+
67
+ if ( ! value ) {
68
+ setMasterValue( null );
69
+ return;
70
+ }
71
+
72
+ setMasterValue(
73
+ dimensionsPropTypeUtil.create( {
74
+ 'block-start': value,
75
+ 'block-end': value,
76
+ 'inline-start': value,
77
+ 'inline-end': value,
78
+ } )
79
+ );
80
+
50
81
  return;
51
82
  }
52
83
 
53
- const value = sizeValue ? sizePropTypeUtil.create( sizeValue ) : null;
84
+ const sizeValue =
85
+ dimensionsValue?.[ 'block-start' ] ??
86
+ dimensionsValue?.[ 'inline-end' ] ??
87
+ dimensionsValue?.[ 'block-end' ] ??
88
+ dimensionsValue?.[ 'inline-start' ] ??
89
+ null;
54
90
 
55
- setDimensionsValue( {
56
- 'block-start': value,
57
- 'block-end': value,
58
- 'inline-start': value,
59
- 'inline-end': value,
60
- } );
91
+ if ( ! sizeValue ) {
92
+ setMasterValue( null );
93
+ return;
94
+ }
95
+
96
+ setMasterValue( sizeValue );
61
97
  };
62
98
 
63
99
  const tooltipLabel = label.toLowerCase();
@@ -70,14 +106,16 @@ export const LinkedDimensionsControl = ( {
70
106
 
71
107
  const disabled = sizeDisabled || dimensionsDisabled;
72
108
 
109
+ const propProviderProps = {
110
+ propType,
111
+ value: dimensionsValue,
112
+ placeholder: dimensionsPlaceholder,
113
+ setValue: setDimensionsValue,
114
+ isDisabled: () => dimensionsDisabled,
115
+ };
116
+
73
117
  return (
74
- <PropProvider
75
- propType={ propType }
76
- value={ dimensionsValue }
77
- setValue={ setDimensionsValue }
78
- placeholder={ dimensionsPlaceholder }
79
- isDisabled={ () => disabled }
80
- >
118
+ <PropProvider { ...propProviderProps }>
81
119
  <Stack direction="row" gap={ 2 } flexWrap="nowrap">
82
120
  <ControlFormLabel>{ label }</ControlFormLabel>
83
121
  <Tooltip title={ isLinked ? unlinkedLabel : linkedLabel } placement="top">
@@ -97,7 +97,6 @@ export const SizeControl = createControl(
97
97
  enablePropTypeUnits = false,
98
98
  id,
99
99
  ariaLabel,
100
- isRepeaterControl = false,
101
100
  }: Omit< SizeControlProps, 'variant' > & { variant?: SizeVariant } ) => {
102
101
  const {
103
102
  value: sizeValue,
@@ -107,6 +106,7 @@ export const SizeControl = createControl(
107
106
  placeholder: externalPlaceholder,
108
107
  propType,
109
108
  } = useBoundProp( sizePropTypeUtil );
109
+
110
110
  const actualDefaultUnit = defaultUnit ?? externalPlaceholder?.unit ?? defaultSelectedUnit[ variant ];
111
111
  const activeBreakpoint = useActiveBreakpoint();
112
112
  const actualExtendedOptions = useSizeExtendedOptions( extendedOptions || [], disableCustom ?? false );
@@ -169,46 +169,14 @@ export const SizeControl = createControl(
169
169
  }
170
170
  };
171
171
 
172
- const handleLinkedSizeControlChanges = () => {
173
- const newState = createStateFromSizeProp(
174
- sizeValue,
175
- state.unit === 'custom' ? state.unit : actualDefaultUnit,
176
- '',
177
- state.custom
178
- );
179
- const currentUnitType = isUnitExtendedOption( state.unit ) ? 'custom' : 'numeric';
180
- const mergedStates = {
181
- ...state,
182
- unit: newState.unit ?? state.unit,
183
- [ currentUnitType ]: newState[ currentUnitType ],
184
- };
185
-
186
- if ( mergedStates.unit !== 'auto' && areStatesEqual( state, mergedStates ) ) {
187
- return;
172
+ const maybeClosePopup = React.useCallback( () => {
173
+ if ( popupState && popupState.isOpen ) {
174
+ popupState.close();
188
175
  }
189
-
190
- if ( state.unit === newState.unit ) {
191
- setState( mergedStates );
192
-
193
- return;
194
- }
195
-
196
- setState( newState );
197
- };
176
+ }, [ popupState ] );
198
177
 
199
178
  useEffect( () => {
200
- if ( ! isRepeaterControl ) {
201
- handleLinkedSizeControlChanges();
202
- }
203
- // eslint-disable-next-line react-hooks/exhaustive-deps
204
- }, [ sizeValue ] );
205
-
206
- useEffect( () => {
207
- const newState = createStateFromSizeProp( sizeValue, actualDefaultUnit, '', state.custom );
208
-
209
- if ( activeBreakpoint && ! areStatesEqual( newState, state ) ) {
210
- setState( newState );
211
- }
179
+ maybeClosePopup();
212
180
  // eslint-disable-next-line react-hooks/exhaustive-deps
213
181
  }, [ activeBreakpoint ] );
214
182
 
@@ -317,15 +285,3 @@ function extractValueFromState( state: State | null, allowEmpty: boolean = false
317
285
  unit,
318
286
  };
319
287
  }
320
-
321
- function areStatesEqual( state1: State, state2: State ): boolean {
322
- if ( state1.unit !== state2.unit || state1.custom !== state2.custom ) {
323
- return false;
324
- }
325
-
326
- if ( isUnitExtendedOption( state1.unit ) ) {
327
- return state1.custom === state2.custom;
328
- }
329
-
330
- return state1.numeric === state2.numeric || ( isNaN( state1.numeric ) && isNaN( state2.numeric ) );
331
- }