@elementor/editor-controls 0.6.0 → 0.6.1

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": "0.6.0",
4
+ "version": "0.6.1",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -40,12 +40,12 @@
40
40
  "dev": "tsup --config=../../tsup.dev.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@elementor/editor-props": "0.7.0",
43
+ "@elementor/editor-props": "0.7.1",
44
44
  "@elementor/icons": "^1.20.0",
45
45
  "@elementor/session": "0.1.0",
46
46
  "@elementor/ui": "^1.22.0",
47
47
  "@elementor/utils": "0.3.0",
48
- "@elementor/wp-media": "0.2.3",
48
+ "@elementor/wp-media": "0.3.0",
49
49
  "@wordpress/i18n": "^5.13.0"
50
50
  },
51
51
  "peerDependencies": {
@@ -99,7 +99,7 @@ export function EqualUnequalSizesControl< TMultiPropType extends string, TPropVa
99
99
  </Grid>
100
100
  <Grid item xs={ 6 }>
101
101
  <Stack direction="row" alignItems="center" gap={ 1 }>
102
- <SizeControl placeholder={ __( 'MIXED', 'elementor' ) } />
102
+ <SizeControl placeholder={ __( 'Mixed', 'elementor' ) } />
103
103
  <ToggleButton
104
104
  size={ 'tiny' }
105
105
  value={ 'check' }
@@ -17,7 +17,7 @@ export const ImageMediaControl = createControl( () => {
17
17
  const src = attachment?.url ?? url?.value ?? null;
18
18
 
19
19
  const { open } = useWpMediaFrame( {
20
- types: [ 'image' ],
20
+ types: [ 'image', 'image/svg+xml' ],
21
21
  multiple: false,
22
22
  selected: id?.value || null,
23
23
  onSelect: ( selectedAttachment ) => {
@@ -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,5 +1,10 @@
1
1
  import * as React from 'react';
2
- import { linkedDimensionsPropTypeUtil, type LinkedDimensionsPropValue, type PropKey } from '@elementor/editor-props';
2
+ import {
3
+ dimensionsPropTypeUtil,
4
+ type DimensionsPropValue,
5
+ type PropKey,
6
+ sizePropTypeUtil,
7
+ } from '@elementor/editor-props';
3
8
  import { DetachIcon, LinkIcon, SideBottomIcon, SideLeftIcon, SideRightIcon, SideTopIcon } from '@elementor/icons';
4
9
  import { Grid, Stack, ToggleButton } from '@elementor/ui';
5
10
  import { __ } from '@wordpress/i18n';
@@ -10,41 +15,40 @@ import { createControl } from '../create-control';
10
15
  import { SizeControl } from './size-control';
11
16
 
12
17
  export const LinkedDimensionsControl = createControl( ( { label }: { label: string } ) => {
13
- const { value, setValue, propType } = useBoundProp( linkedDimensionsPropTypeUtil );
14
- const { top, right, bottom, left, isLinked = true } = value || {};
18
+ const { value: dimensionsValue, setValue: setDimensionsValue, propType } = useBoundProp( dimensionsPropTypeUtil );
19
+ const { value: sizeValue, setValue: setSizeValue } = useBoundProp( sizePropTypeUtil );
15
20
 
16
- const setLinkedValue: SetValue< LinkedDimensionsPropValue[ 'value' ] > = ( newValue, _, meta ) => {
21
+ const isLinked = ! dimensionsValue && ! sizeValue ? true : !! sizeValue;
22
+
23
+ const setValue: SetValue< DimensionsPropValue[ 'value' ] > = ( newValue ) => {
17
24
  if ( ! isLinked ) {
18
- return setValue( newValue );
25
+ setDimensionsValue( newValue );
26
+ return;
19
27
  }
20
28
 
21
- const newDimension = newValue[ meta?.bind as keyof LinkedDimensionsPropValue[ 'value' ] ];
22
-
23
- setValue( {
24
- isLinked,
25
- top: newDimension,
26
- right: newDimension,
27
- bottom: newDimension,
28
- left: newDimension,
29
- } );
29
+ setSizeValue( newValue.top );
30
30
  };
31
31
 
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
- };
32
+ const onLinkToggle = () => {
33
+ if ( ! isLinked ) {
34
+ setSizeValue( dimensionsValue?.top.value );
35
+ return;
36
+ }
37
+
38
+ const value = sizeValue ? sizePropTypeUtil.create( sizeValue ) : null;
40
39
 
41
- setValue( updatedValue );
40
+ setDimensionsValue( {
41
+ top: value,
42
+ right: value,
43
+ bottom: value,
44
+ left: value,
45
+ } );
42
46
  };
43
47
 
44
48
  const LinkedIcon = isLinked ? LinkIcon : DetachIcon;
45
49
 
46
50
  return (
47
- <PropProvider propType={ propType } value={ value } setValue={ setLinkedValue }>
51
+ <PropProvider propType={ propType } value={ dimensionsValue } setValue={ setValue }>
48
52
  <Stack direction="row" gap={ 2 } flexWrap="nowrap">
49
53
  <ControlLabel>{ label }</ControlLabel>
50
54
  <ToggleButton
@@ -53,7 +57,7 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
53
57
  value={ 'check' }
54
58
  selected={ isLinked }
55
59
  sx={ { marginLeft: 'auto' } }
56
- onChange={ toggleLinked }
60
+ onChange={ onLinkToggle }
57
61
  >
58
62
  <LinkedIcon fontSize={ 'tiny' } />
59
63
  </ToggleButton>
@@ -64,7 +68,11 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
64
68
  <ControlLabel>{ __( 'Top', 'elementor' ) }</ControlLabel>
65
69
  </Grid>
66
70
  <Grid item xs={ 12 }>
67
- <Control bind={ 'top' } startIcon={ <SideTopIcon fontSize={ 'tiny' } /> } />
71
+ <Control
72
+ bind={ 'top' }
73
+ startIcon={ <SideTopIcon fontSize={ 'tiny' } /> }
74
+ isLinked={ isLinked }
75
+ />
68
76
  </Grid>
69
77
  </Grid>
70
78
  <Grid container gap={ 1 } alignItems="center">
@@ -72,7 +80,11 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
72
80
  <ControlLabel>{ __( 'Right', 'elementor' ) }</ControlLabel>
73
81
  </Grid>
74
82
  <Grid item xs={ 12 }>
75
- <Control bind={ 'right' } startIcon={ <SideRightIcon fontSize={ 'tiny' } /> } />
83
+ <Control
84
+ bind={ 'right' }
85
+ startIcon={ <SideRightIcon fontSize={ 'tiny' } /> }
86
+ isLinked={ isLinked }
87
+ />
76
88
  </Grid>
77
89
  </Grid>
78
90
  </Stack>
@@ -82,7 +94,11 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
82
94
  <ControlLabel>{ __( 'Bottom', 'elementor' ) }</ControlLabel>
83
95
  </Grid>
84
96
  <Grid item xs={ 12 }>
85
- <Control bind={ 'bottom' } startIcon={ <SideBottomIcon fontSize={ 'tiny' } /> } />
97
+ <Control
98
+ bind={ 'bottom' }
99
+ startIcon={ <SideBottomIcon fontSize={ 'tiny' } /> }
100
+ isLinked={ isLinked }
101
+ />
86
102
  </Grid>
87
103
  </Grid>
88
104
  <Grid container gap={ 1 } alignItems="center">
@@ -90,7 +106,11 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
90
106
  <ControlLabel>{ __( 'Left', 'elementor' ) }</ControlLabel>
91
107
  </Grid>
92
108
  <Grid item xs={ 12 }>
93
- <Control bind={ 'left' } startIcon={ <SideLeftIcon fontSize={ 'tiny' } /> } />
109
+ <Control
110
+ bind={ 'left' }
111
+ startIcon={ <SideLeftIcon fontSize={ 'tiny' } /> }
112
+ isLinked={ isLinked }
113
+ />
94
114
  </Grid>
95
115
  </Grid>
96
116
  </Stack>
@@ -98,8 +118,14 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
98
118
  );
99
119
  } );
100
120
 
101
- const Control = ( { bind, startIcon }: { bind: PropKey; startIcon: React.ReactNode } ) => (
102
- <PropKeyProvider bind={ bind }>
103
- <SizeControl startIcon={ startIcon } />
104
- </PropKeyProvider>
105
- );
121
+ const Control = ( { bind, startIcon, isLinked }: { bind: PropKey; startIcon: React.ReactNode; isLinked: boolean } ) => {
122
+ if ( isLinked ) {
123
+ return <SizeControl startIcon={ startIcon } />;
124
+ }
125
+
126
+ return (
127
+ <PropKeyProvider bind={ bind }>
128
+ <SizeControl startIcon={ startIcon } />
129
+ </PropKeyProvider>
130
+ );
131
+ };