@elementor/editor-controls 3.35.0-387 → 3.35.0-389

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-387",
4
+ "version": "3.35.0-389",
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-387",
44
- "@elementor/editor-elements": "3.35.0-387",
45
- "@elementor/editor-props": "3.35.0-387",
46
- "@elementor/editor-responsive": "3.35.0-387",
47
- "@elementor/editor-ui": "3.35.0-387",
48
- "@elementor/editor-v1-adapters": "3.35.0-387",
49
- "@elementor/env": "3.35.0-387",
50
- "@elementor/http-client": "3.35.0-387",
43
+ "@elementor/editor-current-user": "3.35.0-389",
44
+ "@elementor/editor-elements": "3.35.0-389",
45
+ "@elementor/editor-props": "3.35.0-389",
46
+ "@elementor/editor-responsive": "3.35.0-389",
47
+ "@elementor/editor-ui": "3.35.0-389",
48
+ "@elementor/editor-v1-adapters": "3.35.0-389",
49
+ "@elementor/env": "3.35.0-389",
50
+ "@elementor/http-client": "3.35.0-389",
51
51
  "@elementor/icons": "^1.63.0",
52
- "@elementor/locations": "3.35.0-387",
53
- "@elementor/mixpanel": "3.35.0-387",
54
- "@elementor/query": "3.35.0-387",
55
- "@elementor/session": "3.35.0-387",
52
+ "@elementor/locations": "3.35.0-389",
53
+ "@elementor/mixpanel": "3.35.0-389",
54
+ "@elementor/query": "3.35.0-389",
55
+ "@elementor/session": "3.35.0-389",
56
56
  "@elementor/ui": "1.36.17",
57
- "@elementor/utils": "3.35.0-387",
58
- "@elementor/wp-media": "3.35.0-387",
57
+ "@elementor/utils": "3.35.0-389",
58
+ "@elementor/wp-media": "3.35.0-389",
59
59
  "@wordpress/i18n": "^5.13.0",
60
60
  "@monaco-editor/react": "^4.7.0",
61
61
  "dayjs": "^1.11.18",
@@ -1,17 +1,18 @@
1
1
  import * as React from 'react';
2
2
  import { type ReactNode, type RefObject, useId, useRef } from 'react';
3
- import { type PropKey, type PropTypeUtil, sizePropTypeUtil, type SizePropValue } from '@elementor/editor-props';
4
- import { bindPopover, bindToggle, Grid, Popover, Stack, ToggleButton, Tooltip, usePopupState } from '@elementor/ui';
3
+ import { type PropKey, type PropTypeUtil, type PropValue } from '@elementor/editor-props';
4
+ import { bindPopover, bindToggle, Box, Grid, Popover, Stack, Tooltip, usePopupState } from '@elementor/ui';
5
5
  import { __ } from '@wordpress/i18n';
6
6
 
7
7
  import { PropKeyProvider, PropProvider, useBoundProp } from '../bound-prop-context';
8
8
  import { ControlFormLabel } from '../components/control-form-label';
9
9
  import { ControlLabel } from '../components/control-label';
10
+ import { StyledToggleButton } from '../components/control-toggle-button-group';
10
11
  import { PopoverContent } from '../components/popover-content';
11
12
  import { PopoverGridContainer } from '../components/popover-grid-container';
12
13
  import { SizeControl } from './size-control';
13
14
 
14
- type MultiSizePropValue = Record< PropKey, SizePropValue >;
15
+ type MultiSizePropValue = Record< PropKey, PropValue >;
15
16
 
16
17
  type Item = {
17
18
  icon: ReactNode;
@@ -29,20 +30,6 @@ type Props< TMultiPropType extends string, TPropValue extends MultiSizePropValue
29
30
  multiSizePropTypeUtil: PropTypeUtil< TMultiPropType, TPropValue >;
30
31
  };
31
32
 
32
- const isEqualSizes = ( propValue: MultiSizePropValue, items: EqualUnequalItems ) => {
33
- const values = Object.values( propValue );
34
-
35
- if ( values.length !== items.length ) {
36
- return false;
37
- }
38
-
39
- const [ firstValue, ...restValues ] = values;
40
-
41
- return restValues.every(
42
- ( value ) => value?.value?.size === firstValue?.value?.size && value?.value?.unit === firstValue?.value?.unit
43
- );
44
- };
45
-
46
33
  export function EqualUnequalSizesControl< TMultiPropType extends string, TPropValue extends MultiSizePropValue >( {
47
34
  label,
48
35
  icon,
@@ -53,54 +40,59 @@ export function EqualUnequalSizesControl< TMultiPropType extends string, TPropVa
53
40
  const popupId = useId();
54
41
  const popupState = usePopupState( { variant: 'popover', popupId } );
55
42
 
56
- const {
57
- propType: multiSizePropType,
58
- value: multiSizeValue,
59
- setValue: setMultiSizeValue,
60
- disabled: multiSizeDisabled,
61
- } = useBoundProp( multiSizePropTypeUtil );
62
-
63
- const { value: sizeValue, setValue: setSizeValue } = useBoundProp( sizePropTypeUtil );
64
-
65
43
  const rowRefs: RefObject< HTMLDivElement >[] = [ useRef( null ), useRef( null ) ];
66
44
 
67
- const splitEqualValue = () => {
68
- if ( ! sizeValue ) {
69
- return null;
45
+ const { propType: multiSizePropType, disabled: multiSizeDisabled } = useBoundProp( multiSizePropTypeUtil );
46
+ const { value: masterValue, setValue: setMasterValue, placeholder: masterPlaceholder } = useBoundProp();
47
+
48
+ const getMultiSizeValues = ( sourceValue: PropValue ) => {
49
+ if ( multiSizePropTypeUtil.isValid( sourceValue ) ) {
50
+ return sourceValue.value;
70
51
  }
71
52
 
72
- return items.reduce< TPropValue >(
73
- ( acc, { bind } ) => ( { ...acc, [ bind ]: sizePropTypeUtil.create( sizeValue ) } ),
74
- {} as TPropValue
75
- );
53
+ const propValue: MultiSizePropValue = {};
54
+
55
+ items.forEach( ( item ) => {
56
+ propValue[ item.bind ] = sourceValue;
57
+ } );
58
+
59
+ const derived = multiSizePropTypeUtil.create( propValue as unknown as TPropValue );
60
+ return derived?.value;
76
61
  };
77
62
 
78
- const setNestedProp = ( newValue: TPropValue ) => {
79
- const newMappedValues = {
80
- ...( multiSizeValue ?? splitEqualValue() ),
81
- ...newValue,
82
- };
63
+ const isShowingGeneralIndicator = ! popupState.isOpen;
83
64
 
84
- const isEqual = isEqualSizes( newMappedValues, items );
65
+ const derivedValue = getMultiSizeValues( masterValue ) as unknown as TPropValue;
66
+ const derivedPlaceholder = getMultiSizeValues( masterPlaceholder ) as unknown as TPropValue;
85
67
 
86
- if ( isEqual ) {
87
- return setSizeValue( Object.values( newMappedValues )[ 0 ]?.value );
68
+ const isEqualValues = ( values: ReturnType< typeof multiSizePropTypeUtil.create > ) => {
69
+ if ( ! values ) {
70
+ return true;
88
71
  }
89
72
 
90
- setMultiSizeValue( newMappedValues );
91
- };
73
+ const propValue: MultiSizePropValue = {};
92
74
 
93
- const getMultiSizeValues = () => {
94
- if ( multiSizeValue ) {
95
- return multiSizeValue;
96
- }
75
+ items.forEach( ( item ) => {
76
+ propValue[ item.bind ] = values?.value?.[ item.bind ] ?? null;
77
+ } );
97
78
 
98
- return splitEqualValue() ?? null;
79
+ const allValues = Object.values( propValue ).map( ( value ) => JSON.stringify( value ) );
80
+ return allValues.every( ( value ) => value === allValues[ 0 ] );
99
81
  };
100
82
 
101
- const isShowingGeneralIndicator = ! popupState.isOpen;
83
+ const isMixedPlaceholder = ! masterValue && ! isEqualValues( multiSizePropTypeUtil.create( derivedPlaceholder ) );
84
+ const isMixed = isMixedPlaceholder || ! isEqualValues( multiSizePropTypeUtil.create( derivedValue ) );
85
+
86
+ const applyMultiSizeValue = ( newValue: TPropValue ) => {
87
+ const newPropValue = multiSizePropTypeUtil.create( newValue );
102
88
 
103
- const isMixed = !! multiSizeValue;
89
+ if ( isEqualValues( newPropValue ) ) {
90
+ setMasterValue( Object.values( newValue )?.pop() ?? null );
91
+ return;
92
+ }
93
+
94
+ setMasterValue( newPropValue );
95
+ };
104
96
 
105
97
  return (
106
98
  <>
@@ -112,27 +104,33 @@ export function EqualUnequalSizesControl< TMultiPropType extends string, TPropVa
112
104
  <ControlLabel>{ label }</ControlLabel>
113
105
  ) }
114
106
  </Grid>
107
+
115
108
  <Grid item xs={ 6 }>
116
109
  <Stack direction="row" alignItems="center" gap={ 1 }>
117
- <SizeControl
118
- placeholder={ isMixed ? __( 'Mixed', 'elementor' ) : undefined }
119
- anchorRef={ rowRefs[ 0 ] }
120
- />
110
+ <Box flexGrow={ 1 }>
111
+ <SizeControl
112
+ placeholder={ isMixed ? __( 'Mixed', 'elementor' ) : undefined }
113
+ enablePropTypeUnits={ ! isMixed || ! isMixedPlaceholder }
114
+ anchorRef={ rowRefs[ 0 ] }
115
+ />
116
+ </Box>
121
117
  <Tooltip title={ tooltipLabel } placement="top">
122
- <ToggleButton
118
+ <StyledToggleButton
123
119
  size={ 'tiny' }
124
120
  value={ 'check' }
125
121
  sx={ { marginLeft: 'auto' } }
126
122
  { ...bindToggle( popupState ) }
127
123
  selected={ popupState.isOpen }
124
+ isPlaceholder={ isMixedPlaceholder }
128
125
  aria-label={ tooltipLabel }
129
126
  >
130
127
  { icon }
131
- </ToggleButton>
128
+ </StyledToggleButton>
132
129
  </Tooltip>
133
130
  </Stack>
134
131
  </Grid>
135
132
  </Grid>
133
+
136
134
  <Popover
137
135
  disablePortal
138
136
  disableScrollLock
@@ -151,8 +149,9 @@ export function EqualUnequalSizesControl< TMultiPropType extends string, TPropVa
151
149
  >
152
150
  <PropProvider
153
151
  propType={ multiSizePropType }
154
- value={ getMultiSizeValues() }
155
- setValue={ setNestedProp }
152
+ value={ derivedValue }
153
+ placeholder={ derivedPlaceholder }
154
+ setValue={ applyMultiSizeValue }
156
155
  isDisabled={ () => multiSizeDisabled }
157
156
  >
158
157
  <PopoverContent p={ 1.5 }>