@elementor/editor-controls 0.6.1 → 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
 
@@ -18,6 +23,7 @@ export const ImageMediaControl = createControl( () => {
18
23
 
19
24
  const { open } = useWpMediaFrame( {
20
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,15 +1,10 @@
1
1
  import * as React from 'react';
2
- import {
3
- dimensionsPropTypeUtil,
4
- type DimensionsPropValue,
5
- type PropKey,
6
- sizePropTypeUtil,
7
- } from '@elementor/editor-props';
2
+ import { dimensionsPropTypeUtil, type PropKey, sizePropTypeUtil } from '@elementor/editor-props';
8
3
  import { DetachIcon, LinkIcon, SideBottomIcon, SideLeftIcon, SideRightIcon, SideTopIcon } from '@elementor/icons';
9
4
  import { Grid, Stack, ToggleButton } from '@elementor/ui';
10
5
  import { __ } from '@wordpress/i18n';
11
6
 
12
- import { PropKeyProvider, PropProvider, type SetValue, useBoundProp } from '../bound-prop-context';
7
+ import { PropKeyProvider, PropProvider, useBoundProp } from '../bound-prop-context';
13
8
  import { ControlLabel } from '../components/control-label';
14
9
  import { createControl } from '../create-control';
15
10
  import { SizeControl } from './size-control';
@@ -20,18 +15,9 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
20
15
 
21
16
  const isLinked = ! dimensionsValue && ! sizeValue ? true : !! sizeValue;
22
17
 
23
- const setValue: SetValue< DimensionsPropValue[ 'value' ] > = ( newValue ) => {
24
- if ( ! isLinked ) {
25
- setDimensionsValue( newValue );
26
- return;
27
- }
28
-
29
- setSizeValue( newValue.top );
30
- };
31
-
32
18
  const onLinkToggle = () => {
33
19
  if ( ! isLinked ) {
34
- setSizeValue( dimensionsValue?.top.value );
20
+ setSizeValue( dimensionsValue?.top?.value );
35
21
  return;
36
22
  }
37
23
 
@@ -48,7 +34,7 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
48
34
  const LinkedIcon = isLinked ? LinkIcon : DetachIcon;
49
35
 
50
36
  return (
51
- <PropProvider propType={ propType } value={ dimensionsValue } setValue={ setValue }>
37
+ <PropProvider propType={ propType } value={ dimensionsValue } setValue={ setDimensionsValue }>
52
38
  <Stack direction="row" gap={ 2 } flexWrap="nowrap">
53
39
  <ControlLabel>{ label }</ControlLabel>
54
40
  <ToggleButton
@@ -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
  ) ) }