@elementor/editor-controls 3.35.0-386 → 3.35.0-388
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.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +163 -169
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -95
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
- package/src/controls/equal-unequal-sizes-control.tsx +57 -58
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-
|
|
4
|
+
"version": "3.35.0-388",
|
|
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-
|
|
44
|
-
"@elementor/editor-elements": "3.35.0-
|
|
45
|
-
"@elementor/editor-props": "3.35.0-
|
|
46
|
-
"@elementor/editor-responsive": "3.35.0-
|
|
47
|
-
"@elementor/editor-ui": "3.35.0-
|
|
48
|
-
"@elementor/editor-v1-adapters": "3.35.0-
|
|
49
|
-
"@elementor/env": "3.35.0-
|
|
50
|
-
"@elementor/http-client": "3.35.0-
|
|
43
|
+
"@elementor/editor-current-user": "3.35.0-388",
|
|
44
|
+
"@elementor/editor-elements": "3.35.0-388",
|
|
45
|
+
"@elementor/editor-props": "3.35.0-388",
|
|
46
|
+
"@elementor/editor-responsive": "3.35.0-388",
|
|
47
|
+
"@elementor/editor-ui": "3.35.0-388",
|
|
48
|
+
"@elementor/editor-v1-adapters": "3.35.0-388",
|
|
49
|
+
"@elementor/env": "3.35.0-388",
|
|
50
|
+
"@elementor/http-client": "3.35.0-388",
|
|
51
51
|
"@elementor/icons": "^1.63.0",
|
|
52
|
-
"@elementor/locations": "3.35.0-
|
|
53
|
-
"@elementor/mixpanel": "3.35.0-
|
|
54
|
-
"@elementor/query": "3.35.0-
|
|
55
|
-
"@elementor/session": "3.35.0-
|
|
52
|
+
"@elementor/locations": "3.35.0-388",
|
|
53
|
+
"@elementor/mixpanel": "3.35.0-388",
|
|
54
|
+
"@elementor/query": "3.35.0-388",
|
|
55
|
+
"@elementor/session": "3.35.0-388",
|
|
56
56
|
"@elementor/ui": "1.36.17",
|
|
57
|
-
"@elementor/utils": "3.35.0-
|
|
58
|
-
"@elementor/wp-media": "3.35.0-
|
|
57
|
+
"@elementor/utils": "3.35.0-388",
|
|
58
|
+
"@elementor/wp-media": "3.35.0-388",
|
|
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,
|
|
4
|
-
import { bindPopover, bindToggle, Grid, Popover, Stack,
|
|
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,
|
|
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
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
|
79
|
-
const newMappedValues = {
|
|
80
|
-
...( multiSizeValue ?? splitEqualValue() ),
|
|
81
|
-
...newValue,
|
|
82
|
-
};
|
|
63
|
+
const isShowingGeneralIndicator = ! popupState.isOpen;
|
|
83
64
|
|
|
84
|
-
|
|
65
|
+
const derivedValue = getMultiSizeValues( masterValue ) as unknown as TPropValue;
|
|
66
|
+
const derivedPlaceholder = getMultiSizeValues( masterPlaceholder ) as unknown as TPropValue;
|
|
85
67
|
|
|
86
|
-
|
|
87
|
-
|
|
68
|
+
const isEqualValues = ( values: ReturnType< typeof multiSizePropTypeUtil.create > ) => {
|
|
69
|
+
if ( ! values ) {
|
|
70
|
+
return true;
|
|
88
71
|
}
|
|
89
72
|
|
|
90
|
-
|
|
91
|
-
};
|
|
73
|
+
const propValue: MultiSizePropValue = {};
|
|
92
74
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
75
|
+
items.forEach( ( item ) => {
|
|
76
|
+
propValue[ item.bind ] = values?.value?.[ item.bind ] ?? null;
|
|
77
|
+
} );
|
|
97
78
|
|
|
98
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
<
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
<
|
|
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
|
-
</
|
|
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={
|
|
155
|
-
|
|
152
|
+
value={ derivedValue }
|
|
153
|
+
placeholder={ derivedPlaceholder }
|
|
154
|
+
setValue={ applyMultiSizeValue }
|
|
156
155
|
isDisabled={ () => multiSizeDisabled }
|
|
157
156
|
>
|
|
158
157
|
<PopoverContent p={ 1.5 }>
|