@elementor/editor-controls 0.31.0 → 0.32.0
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/CHANGELOG.md +17 -0
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +282 -178
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +233 -131
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/controls/aspect-ratio-control.tsx +121 -0
- package/src/controls/link-control.tsx +1 -1
- package/src/controls/switch-control.tsx +20 -0
- package/src/index.ts +2 -0
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": "0.
|
|
4
|
+
"version": "0.32.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@elementor/editor-current-user": "0.
|
|
43
|
+
"@elementor/editor-current-user": "0.5.0",
|
|
44
44
|
"@elementor/editor-elements": "0.8.4",
|
|
45
45
|
"@elementor/editor-props": "0.12.1",
|
|
46
|
-
"@elementor/editor-ui": "0.
|
|
46
|
+
"@elementor/editor-ui": "0.9.0",
|
|
47
47
|
"@elementor/editor-v1-adapters": "0.12.0",
|
|
48
48
|
"@elementor/env": "0.3.5",
|
|
49
49
|
"@elementor/http-client": "0.3.0",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@elementor/locations": "0.8.0",
|
|
52
52
|
"@elementor/query": "0.2.4",
|
|
53
53
|
"@elementor/session": "0.1.0",
|
|
54
|
-
"@elementor/ui": "1.34.
|
|
54
|
+
"@elementor/ui": "1.34.5",
|
|
55
55
|
"@elementor/utils": "0.4.0",
|
|
56
56
|
"@elementor/wp-media": "0.6.0",
|
|
57
57
|
"@tanstack/react-virtual": "3.13.3",
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { stringPropTypeUtil } from '@elementor/editor-props';
|
|
4
|
+
import { MenuListItem } from '@elementor/editor-ui';
|
|
5
|
+
import { Grid, Select, type SelectChangeEvent, Stack, TextField } from '@elementor/ui';
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
|
|
8
|
+
import { useBoundProp } from '../bound-prop-context';
|
|
9
|
+
import { ControlLabel } from '../components/control-label';
|
|
10
|
+
import { createControl } from '../create-control';
|
|
11
|
+
|
|
12
|
+
const RATIO_OPTIONS = [
|
|
13
|
+
{ label: __( 'Auto', 'elementor' ), value: 'auto' },
|
|
14
|
+
{ label: '1/1', value: '1/1' },
|
|
15
|
+
{ label: '4/3', value: '4/3' },
|
|
16
|
+
{ label: '3/4', value: '3/4' },
|
|
17
|
+
{ label: '16/9', value: '16/9' },
|
|
18
|
+
{ label: '9/16', value: '9/16' },
|
|
19
|
+
{ label: '3/2', value: '3/2' },
|
|
20
|
+
{ label: '2/3', value: '2/3' },
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const CUSTOM_RATIO = 'custom';
|
|
24
|
+
|
|
25
|
+
export const AspectRatioControl = createControl( ( { label }: { label: string } ) => {
|
|
26
|
+
const { value: aspectRatioValue, setValue: setAspectRatioValue } = useBoundProp( stringPropTypeUtil );
|
|
27
|
+
|
|
28
|
+
const isCustomSelected =
|
|
29
|
+
aspectRatioValue && ! RATIO_OPTIONS.some( ( option ) => option.value === aspectRatioValue );
|
|
30
|
+
const [ initialWidth, initialHeight ] = isCustomSelected ? aspectRatioValue.split( '/' ) : [ '', '' ];
|
|
31
|
+
|
|
32
|
+
const [ isCustom, setIsCustom ] = useState( isCustomSelected );
|
|
33
|
+
const [ customWidth, setCustomWidth ] = useState< string >( initialWidth );
|
|
34
|
+
const [ customHeight, setCustomHeight ] = useState< string >( initialHeight );
|
|
35
|
+
const [ selectedValue, setSelectedValue ] = useState< string >(
|
|
36
|
+
isCustomSelected ? CUSTOM_RATIO : aspectRatioValue || ''
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const handleSelectChange = ( event: SelectChangeEvent< string > ) => {
|
|
40
|
+
const newValue = event.target.value;
|
|
41
|
+
const isCustomRatio = newValue === CUSTOM_RATIO;
|
|
42
|
+
|
|
43
|
+
setIsCustom( isCustomRatio );
|
|
44
|
+
setSelectedValue( newValue );
|
|
45
|
+
|
|
46
|
+
if ( isCustomRatio ) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
setAspectRatioValue( newValue );
|
|
51
|
+
};
|
|
52
|
+
const handleCustomWidthChange = ( event: React.ChangeEvent< HTMLInputElement > ) => {
|
|
53
|
+
const newWidth = event.target.value;
|
|
54
|
+
setCustomWidth( newWidth );
|
|
55
|
+
|
|
56
|
+
if ( newWidth && customHeight ) {
|
|
57
|
+
setAspectRatioValue( `${ newWidth }/${ customHeight }` );
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const handleCustomHeightChange = ( event: React.ChangeEvent< HTMLInputElement > ) => {
|
|
62
|
+
const newHeight = event.target.value;
|
|
63
|
+
setCustomHeight( newHeight );
|
|
64
|
+
|
|
65
|
+
if ( customWidth && newHeight ) {
|
|
66
|
+
setAspectRatioValue( `${ customWidth }/${ newHeight }` );
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<Stack direction="column" gap={ 2 }>
|
|
72
|
+
<Grid container gap={ 2 } alignItems="center" flexWrap="nowrap">
|
|
73
|
+
<Grid item xs={ 6 }>
|
|
74
|
+
<ControlLabel>{ label }</ControlLabel>
|
|
75
|
+
</Grid>
|
|
76
|
+
<Grid item xs={ 6 }>
|
|
77
|
+
<Select
|
|
78
|
+
sx={ { overflow: 'hidden' } }
|
|
79
|
+
displayEmpty
|
|
80
|
+
size="tiny"
|
|
81
|
+
value={ selectedValue }
|
|
82
|
+
onChange={ handleSelectChange }
|
|
83
|
+
fullWidth
|
|
84
|
+
>
|
|
85
|
+
{ [ ...RATIO_OPTIONS, { label: __( 'Custom', 'elementor' ), value: CUSTOM_RATIO } ].map(
|
|
86
|
+
( { label: optionLabel, ...props } ) => (
|
|
87
|
+
<MenuListItem key={ props.value } { ...props } value={ props.value ?? '' }>
|
|
88
|
+
{ optionLabel }
|
|
89
|
+
</MenuListItem>
|
|
90
|
+
)
|
|
91
|
+
) }
|
|
92
|
+
</Select>
|
|
93
|
+
</Grid>
|
|
94
|
+
</Grid>
|
|
95
|
+
{ isCustom && (
|
|
96
|
+
<Grid container gap={ 2 } alignItems="center" flexWrap="nowrap">
|
|
97
|
+
<Grid item xs={ 6 }>
|
|
98
|
+
<TextField
|
|
99
|
+
size="tiny"
|
|
100
|
+
type="number"
|
|
101
|
+
fullWidth
|
|
102
|
+
value={ customWidth }
|
|
103
|
+
onChange={ handleCustomWidthChange }
|
|
104
|
+
placeholder={ __( 'Width', 'elementor' ) }
|
|
105
|
+
/>
|
|
106
|
+
</Grid>
|
|
107
|
+
<Grid item xs={ 6 }>
|
|
108
|
+
<TextField
|
|
109
|
+
size="tiny"
|
|
110
|
+
type="number"
|
|
111
|
+
fullWidth
|
|
112
|
+
value={ customHeight }
|
|
113
|
+
onChange={ handleCustomHeightChange }
|
|
114
|
+
placeholder={ __( 'Height', 'elementor' ) }
|
|
115
|
+
/>
|
|
116
|
+
</Grid>
|
|
117
|
+
</Grid>
|
|
118
|
+
) }
|
|
119
|
+
</Stack>
|
|
120
|
+
);
|
|
121
|
+
} );
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { booleanPropTypeUtil } from '@elementor/editor-props';
|
|
3
|
+
import { Switch } from '@elementor/ui';
|
|
4
|
+
|
|
5
|
+
import { useBoundProp } from '../bound-prop-context/use-bound-prop';
|
|
6
|
+
import { createControl } from '../create-control';
|
|
7
|
+
|
|
8
|
+
export const SwitchControl = createControl( () => {
|
|
9
|
+
const { value, setValue } = useBoundProp( booleanPropTypeUtil );
|
|
10
|
+
|
|
11
|
+
const handleChange = ( event: React.ChangeEvent< HTMLInputElement > ) => {
|
|
12
|
+
setValue( event.target.checked );
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<div style={ { display: 'flex', justifyContent: 'flex-end' } }>
|
|
17
|
+
<Switch checked={ !! value } onChange={ handleChange } size="small" />
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
} );
|
package/src/index.ts
CHANGED
|
@@ -15,8 +15,10 @@ export { FontFamilyControl } from './controls/font-family-control/font-family-co
|
|
|
15
15
|
export { UrlControl } from './controls/url-control';
|
|
16
16
|
export { LinkControl } from './controls/link-control';
|
|
17
17
|
export { GapControl } from './controls/gap-control';
|
|
18
|
+
export { AspectRatioControl } from './controls/aspect-ratio-control';
|
|
18
19
|
export { SvgMediaControl } from './controls/svg-media-control';
|
|
19
20
|
export { BackgroundControl } from './controls/background-control/background-control';
|
|
21
|
+
export { SwitchControl } from './controls/switch-control';
|
|
20
22
|
|
|
21
23
|
// components
|
|
22
24
|
export { ControlFormLabel } from './components/control-form-label';
|