@elementor/editor-controls 0.6.0 → 0.7.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.
@@ -3,13 +3,18 @@ import { imageSrcPropTypeUtil } from '@elementor/editor-props';
3
3
  import { UploadIcon } from '@elementor/icons';
4
4
  import { Button, Card, CardMedia, CardOverlay, CircularProgress, Stack } from '@elementor/ui';
5
5
  import { useWpMediaAttachment, useWpMediaFrame } from '@elementor/wp-media';
6
+ import { type ImageExtension } from '@elementor/wp-media';
6
7
  import { __ } from '@wordpress/i18n';
7
8
 
8
9
  import { useBoundProp } from '../bound-prop-context';
9
10
  import ControlActions from '../control-actions/control-actions';
10
11
  import { createControl } from '../create-control';
11
12
 
12
- export const ImageMediaControl = createControl( () => {
13
+ export type ImageMediaControlProps = {
14
+ allowedExtensions?: ImageExtension[];
15
+ };
16
+
17
+ export const ImageMediaControl = createControl( ( props: ImageMediaControlProps ) => {
13
18
  const { value, setValue } = useBoundProp( imageSrcPropTypeUtil );
14
19
  const { id, url } = value ?? {};
15
20
 
@@ -17,7 +22,8 @@ export const ImageMediaControl = createControl( () => {
17
22
  const src = attachment?.url ?? url?.value ?? null;
18
23
 
19
24
  const { open } = useWpMediaFrame( {
20
- types: [ 'image' ],
25
+ types: [ 'image', 'image/svg+xml' ],
26
+ allowedExtensions: props.allowedExtensions,
21
27
  multiple: false,
22
28
  selected: id?.value || null,
23
29
  onSelect: ( selectedAttachment ) => {
@@ -32,16 +38,18 @@ export const ImageMediaControl = createControl( () => {
32
38
  } );
33
39
 
34
40
  return (
35
- <Card variant="outlined">
36
- <CardMedia image={ src } sx={ { height: 150 } }>
37
- { isFetching ? (
38
- <Stack justifyContent="center" alignItems="center" width="100%" height="100%">
39
- <CircularProgress />
40
- </Stack>
41
- ) : null }
42
- </CardMedia>
43
- <CardOverlay>
44
- <ControlActions>
41
+ <ControlActions>
42
+ <Card variant="outlined">
43
+ <CardMedia image={ src } sx={ { height: 150 } }>
44
+ { isFetching ? (
45
+ <Stack justifyContent="center" alignItems="center" width="100%" height="100%">
46
+ <CircularProgress />
47
+ </Stack>
48
+ ) : (
49
+ <></>
50
+ ) }
51
+ </CardMedia>
52
+ <CardOverlay>
45
53
  <Stack gap={ 1 }>
46
54
  <Button
47
55
  size="tiny"
@@ -61,8 +69,8 @@ export const ImageMediaControl = createControl( () => {
61
69
  { __( 'Upload Image', 'elementor' ) }
62
70
  </Button>
63
71
  </Stack>
64
- </ControlActions>
65
- </CardOverlay>
66
- </Card>
72
+ </CardOverlay>
73
+ </Card>
74
+ </ControlActions>
67
75
  );
68
76
  } );
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { booleanPropTypeUtil, linkPropTypeUtil, type LinkPropValue, stringPropTypeUtil } from '@elementor/editor-props';
2
+ import { booleanPropTypeUtil, linkPropTypeUtil, type LinkPropValue, urlPropTypeUtil } from '@elementor/editor-props';
3
3
  import { MinusIcon, PlusIcon } from '@elementor/icons';
4
4
  import { useSessionStorage } from '@elementor/session';
5
5
  import { Collapse, Divider, Grid, IconButton, Stack, Switch } from '@elementor/ui';
@@ -69,7 +69,7 @@ export const LinkControl = createControl( ( props?: Props ) => {
69
69
  <AutocompleteControl
70
70
  allowCustomValues={ Object.keys( options ).length ? allowCustomValues : true }
71
71
  options={ options }
72
- propType={ stringPropTypeUtil }
72
+ propType={ urlPropTypeUtil }
73
73
  placeholder={ placeholder }
74
74
  />
75
75
  </PropKeyProvider>
@@ -1,50 +1,40 @@
1
1
  import * as React from 'react';
2
- import { linkedDimensionsPropTypeUtil, type LinkedDimensionsPropValue, type PropKey } from '@elementor/editor-props';
2
+ import { dimensionsPropTypeUtil, type PropKey, sizePropTypeUtil } from '@elementor/editor-props';
3
3
  import { DetachIcon, LinkIcon, SideBottomIcon, SideLeftIcon, SideRightIcon, SideTopIcon } from '@elementor/icons';
4
4
  import { Grid, Stack, ToggleButton } from '@elementor/ui';
5
5
  import { __ } from '@wordpress/i18n';
6
6
 
7
- import { PropKeyProvider, PropProvider, type SetValue, useBoundProp } from '../bound-prop-context';
7
+ import { PropKeyProvider, PropProvider, useBoundProp } from '../bound-prop-context';
8
8
  import { ControlLabel } from '../components/control-label';
9
9
  import { createControl } from '../create-control';
10
10
  import { SizeControl } from './size-control';
11
11
 
12
12
  export const LinkedDimensionsControl = createControl( ( { label }: { label: string } ) => {
13
- const { value, setValue, propType } = useBoundProp( linkedDimensionsPropTypeUtil );
14
- const { top, right, bottom, left, isLinked = true } = value || {};
13
+ const { value: dimensionsValue, setValue: setDimensionsValue, propType } = useBoundProp( dimensionsPropTypeUtil );
14
+ const { value: sizeValue, setValue: setSizeValue } = useBoundProp( sizePropTypeUtil );
15
15
 
16
- const setLinkedValue: SetValue< LinkedDimensionsPropValue[ 'value' ] > = ( newValue, _, meta ) => {
16
+ const isLinked = ! dimensionsValue && ! sizeValue ? true : !! sizeValue;
17
+
18
+ const onLinkToggle = () => {
17
19
  if ( ! isLinked ) {
18
- return setValue( newValue );
20
+ setSizeValue( dimensionsValue?.top?.value );
21
+ return;
19
22
  }
20
23
 
21
- const newDimension = newValue[ meta?.bind as keyof LinkedDimensionsPropValue[ 'value' ] ];
24
+ const value = sizeValue ? sizePropTypeUtil.create( sizeValue ) : null;
22
25
 
23
- setValue( {
24
- isLinked,
25
- top: newDimension,
26
- right: newDimension,
27
- bottom: newDimension,
28
- left: newDimension,
26
+ setDimensionsValue( {
27
+ top: value,
28
+ right: value,
29
+ bottom: value,
30
+ left: value,
29
31
  } );
30
32
  };
31
33
 
32
- const toggleLinked = () => {
33
- const updatedValue = {
34
- isLinked: ! isLinked,
35
- top,
36
- right: ! isLinked ? top : right,
37
- bottom: ! isLinked ? top : bottom,
38
- left: ! isLinked ? top : left,
39
- };
40
-
41
- setValue( updatedValue );
42
- };
43
-
44
34
  const LinkedIcon = isLinked ? LinkIcon : DetachIcon;
45
35
 
46
36
  return (
47
- <PropProvider propType={ propType } value={ value } setValue={ setLinkedValue }>
37
+ <PropProvider propType={ propType } value={ dimensionsValue } setValue={ setDimensionsValue }>
48
38
  <Stack direction="row" gap={ 2 } flexWrap="nowrap">
49
39
  <ControlLabel>{ label }</ControlLabel>
50
40
  <ToggleButton
@@ -53,7 +43,7 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
53
43
  value={ 'check' }
54
44
  selected={ isLinked }
55
45
  sx={ { marginLeft: 'auto' } }
56
- onChange={ toggleLinked }
46
+ onChange={ onLinkToggle }
57
47
  >
58
48
  <LinkedIcon fontSize={ 'tiny' } />
59
49
  </ToggleButton>
@@ -64,7 +54,11 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
64
54
  <ControlLabel>{ __( 'Top', 'elementor' ) }</ControlLabel>
65
55
  </Grid>
66
56
  <Grid item xs={ 12 }>
67
- <Control bind={ 'top' } startIcon={ <SideTopIcon fontSize={ 'tiny' } /> } />
57
+ <Control
58
+ bind={ 'top' }
59
+ startIcon={ <SideTopIcon fontSize={ 'tiny' } /> }
60
+ isLinked={ isLinked }
61
+ />
68
62
  </Grid>
69
63
  </Grid>
70
64
  <Grid container gap={ 1 } alignItems="center">
@@ -72,7 +66,11 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
72
66
  <ControlLabel>{ __( 'Right', 'elementor' ) }</ControlLabel>
73
67
  </Grid>
74
68
  <Grid item xs={ 12 }>
75
- <Control bind={ 'right' } startIcon={ <SideRightIcon fontSize={ 'tiny' } /> } />
69
+ <Control
70
+ bind={ 'right' }
71
+ startIcon={ <SideRightIcon fontSize={ 'tiny' } /> }
72
+ isLinked={ isLinked }
73
+ />
76
74
  </Grid>
77
75
  </Grid>
78
76
  </Stack>
@@ -82,7 +80,11 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
82
80
  <ControlLabel>{ __( 'Bottom', 'elementor' ) }</ControlLabel>
83
81
  </Grid>
84
82
  <Grid item xs={ 12 }>
85
- <Control bind={ 'bottom' } startIcon={ <SideBottomIcon fontSize={ 'tiny' } /> } />
83
+ <Control
84
+ bind={ 'bottom' }
85
+ startIcon={ <SideBottomIcon fontSize={ 'tiny' } /> }
86
+ isLinked={ isLinked }
87
+ />
86
88
  </Grid>
87
89
  </Grid>
88
90
  <Grid container gap={ 1 } alignItems="center">
@@ -90,7 +92,11 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
90
92
  <ControlLabel>{ __( 'Left', 'elementor' ) }</ControlLabel>
91
93
  </Grid>
92
94
  <Grid item xs={ 12 }>
93
- <Control bind={ 'left' } startIcon={ <SideLeftIcon fontSize={ 'tiny' } /> } />
95
+ <Control
96
+ bind={ 'left' }
97
+ startIcon={ <SideLeftIcon fontSize={ 'tiny' } /> }
98
+ isLinked={ isLinked }
99
+ />
94
100
  </Grid>
95
101
  </Grid>
96
102
  </Stack>
@@ -98,8 +104,14 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
98
104
  );
99
105
  } );
100
106
 
101
- const Control = ( { bind, startIcon }: { bind: PropKey; startIcon: React.ReactNode } ) => (
102
- <PropKeyProvider bind={ bind }>
103
- <SizeControl startIcon={ startIcon } />
104
- </PropKeyProvider>
105
- );
107
+ const Control = ( { bind, startIcon, isLinked }: { bind: PropKey; startIcon: React.ReactNode; isLinked: boolean } ) => {
108
+ if ( isLinked ) {
109
+ return <SizeControl startIcon={ startIcon } />;
110
+ }
111
+
112
+ return (
113
+ <PropKeyProvider bind={ bind }>
114
+ <SizeControl startIcon={ startIcon } />
115
+ </PropKeyProvider>
116
+ );
117
+ };
@@ -15,15 +15,17 @@ export const SelectControl = createControl( ( { options, onChange }: Props ) =>
15
15
  const { value, setValue } = useBoundProp( stringPropTypeUtil );
16
16
 
17
17
  const handleChange = ( event: SelectChangeEvent< StringPropValue[ 'value' ] > ) => {
18
- onChange?.( event.target.value, value );
19
- setValue( event.target.value );
18
+ const newValue = event.target.value || null;
19
+
20
+ onChange?.( newValue, value );
21
+ setValue( newValue );
20
22
  };
21
23
 
22
24
  return (
23
25
  <ControlActions>
24
26
  <Select displayEmpty size="tiny" value={ value ?? '' } onChange={ handleChange } fullWidth>
25
27
  { options.map( ( { label, ...props } ) => (
26
- <MenuItem key={ props.value } { ...props }>
28
+ <MenuItem key={ props.value } { ...props } value={ props.value ?? '' }>
27
29
  { label }
28
30
  </MenuItem>
29
31
  ) ) }