@elementor/editor-controls 0.4.1 → 0.6.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 +29 -0
- package/dist/index.d.mts +64 -23
- package/dist/index.d.ts +64 -23
- package/dist/index.js +609 -643
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +565 -599
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
- package/src/bound-prop-context/errors.ts +16 -0
- package/src/bound-prop-context/index.ts +3 -0
- package/src/bound-prop-context/prop-context.tsx +57 -0
- package/src/bound-prop-context/prop-key-context.tsx +110 -0
- package/src/bound-prop-context/use-bound-prop.ts +70 -0
- package/src/components/repeater.tsx +8 -15
- package/src/controls/autocomplete-control.tsx +181 -0
- package/src/controls/background-control/background-control.tsx +19 -42
- package/src/controls/background-control/background-overlay/background-overlay-repeater-control.tsx +64 -50
- package/src/controls/box-shadow-repeater-control.tsx +75 -139
- package/src/controls/color-control.tsx +16 -20
- package/src/controls/equal-unequal-sizes-control.tsx +65 -139
- package/src/controls/gap-control.tsx +20 -25
- package/src/controls/image-control.tsx +19 -34
- package/src/controls/image-media-control.tsx +1 -1
- package/src/controls/link-control.tsx +89 -60
- package/src/controls/linked-dimensions-control.tsx +25 -54
- package/src/controls/number-control.tsx +1 -1
- package/src/controls/stroke-control.tsx +18 -48
- package/src/controls/url-control.tsx +4 -9
- package/src/index.ts +4 -2
- package/src/bound-prop-context.tsx +0 -67
package/src/controls/background-control/background-overlay/background-overlay-repeater-control.tsx
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
backgroundColorOverlayPropTypeUtil,
|
|
4
|
+
backgroundImageOverlayPropTypeUtil,
|
|
4
5
|
type BackgroundOverlayItemPropValue,
|
|
5
6
|
backgroundOverlayPropTypeUtil,
|
|
6
|
-
type
|
|
7
|
-
type PropValue,
|
|
7
|
+
type PropKey,
|
|
8
8
|
} from '@elementor/editor-props';
|
|
9
9
|
import { Grid, Stack, UnstableColorIndicator } from '@elementor/ui';
|
|
10
|
+
import { useWpMediaAttachment } from '@elementor/wp-media';
|
|
10
11
|
import { __ } from '@wordpress/i18n';
|
|
11
12
|
|
|
12
|
-
import {
|
|
13
|
+
import { PropKeyProvider, PropProvider, useBoundProp } from '../../../bound-prop-context';
|
|
13
14
|
import { ControlLabel } from '../../../components/control-label';
|
|
14
15
|
import { Repeater } from '../../../components/repeater';
|
|
15
16
|
import { createControl } from '../../../create-control';
|
|
16
17
|
import { ColorControl } from '../../color-control';
|
|
17
|
-
|
|
18
|
-
type SetContextValue = ( v: PropValue ) => void;
|
|
18
|
+
import { ImageMediaControl } from '../../image-media-control';
|
|
19
19
|
|
|
20
20
|
const initialBackgroundOverlay: BackgroundOverlayItemPropValue = {
|
|
21
21
|
$$type: 'background-color-overlay',
|
|
@@ -23,24 +23,22 @@ const initialBackgroundOverlay: BackgroundOverlayItemPropValue = {
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
export const BackgroundOverlayRepeaterControl = createControl( () => {
|
|
26
|
-
const { value: overlayValues, setValue } = useBoundProp( backgroundOverlayPropTypeUtil );
|
|
27
|
-
|
|
28
|
-
const setColorOverlay = ( newValue: BackgroundOverlayPropValue[ 'value' ] ) => {
|
|
29
|
-
setValue( newValue );
|
|
30
|
-
};
|
|
26
|
+
const { propType, value: overlayValues, setValue } = useBoundProp( backgroundOverlayPropTypeUtil );
|
|
31
27
|
|
|
32
28
|
return (
|
|
33
|
-
<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
29
|
+
<PropProvider propType={ propType } value={ overlayValues } setValue={ setValue }>
|
|
30
|
+
<Repeater
|
|
31
|
+
values={ overlayValues ?? [] }
|
|
32
|
+
setValues={ setValue }
|
|
33
|
+
label={ __( 'Overlay', 'elementor' ) }
|
|
34
|
+
itemSettings={ {
|
|
35
|
+
Icon: ItemIcon,
|
|
36
|
+
Label: ItemLabel,
|
|
37
|
+
Content: ItemContent,
|
|
38
|
+
initialValues: initialBackgroundOverlay,
|
|
39
|
+
} }
|
|
40
|
+
/>
|
|
41
|
+
</PropProvider>
|
|
44
42
|
);
|
|
45
43
|
} );
|
|
46
44
|
|
|
@@ -48,42 +46,58 @@ const ItemIcon = ( { value }: { value: BackgroundOverlayItemPropValue } ) => (
|
|
|
48
46
|
<UnstableColorIndicator size="inherit" component="span" value={ value.value } />
|
|
49
47
|
);
|
|
50
48
|
|
|
51
|
-
const ItemContent = ( {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
value: newValue.value,
|
|
62
|
-
} );
|
|
63
|
-
};
|
|
49
|
+
const ItemContent = ( { bind }: { bind: PropKey } ) => {
|
|
50
|
+
return (
|
|
51
|
+
<PropKeyProvider bind={ bind }>
|
|
52
|
+
<Content />
|
|
53
|
+
</PropKeyProvider>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const Content = () => {
|
|
58
|
+
const propContext = useBoundProp( backgroundImageOverlayPropTypeUtil );
|
|
64
59
|
|
|
65
60
|
return (
|
|
66
61
|
<Stack gap={ 1.5 }>
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
setValue={ setBackgroundColorOverlay as SetContextValue }
|
|
71
|
-
>
|
|
72
|
-
<Grid container spacing={ 1 } alignItems="center">
|
|
73
|
-
<Grid item xs={ 12 }>
|
|
74
|
-
<ControlLabel>{ __( 'Color', 'elementor' ) }</ControlLabel>
|
|
75
|
-
</Grid>
|
|
76
|
-
<Grid item xs={ 12 }>
|
|
77
|
-
<ColorControl />
|
|
78
|
-
</Grid>
|
|
62
|
+
<Grid container spacing={ 1 } alignItems="center">
|
|
63
|
+
<Grid item xs={ 12 }>
|
|
64
|
+
<ControlLabel>{ __( 'Color', 'elementor' ) }</ControlLabel>
|
|
79
65
|
</Grid>
|
|
80
|
-
|
|
66
|
+
<Grid item xs={ 12 }>
|
|
67
|
+
<ColorControl propTypeUtil={ backgroundColorOverlayPropTypeUtil } />
|
|
68
|
+
</Grid>
|
|
69
|
+
</Grid>
|
|
70
|
+
<PropProvider { ...propContext }>
|
|
71
|
+
<PropKeyProvider bind={ 'image-src' }>
|
|
72
|
+
<Grid container spacing={ 1 } alignItems="center">
|
|
73
|
+
<Grid item xs={ 12 }>
|
|
74
|
+
<ImageMediaControl />
|
|
75
|
+
</Grid>
|
|
76
|
+
</Grid>
|
|
77
|
+
</PropKeyProvider>
|
|
78
|
+
</PropProvider>
|
|
81
79
|
</Stack>
|
|
82
80
|
);
|
|
83
81
|
};
|
|
84
82
|
|
|
85
83
|
const ItemLabel = ( { value }: { value: BackgroundOverlayItemPropValue } ) => {
|
|
86
|
-
const
|
|
84
|
+
const type = value.$$type;
|
|
85
|
+
|
|
86
|
+
if ( type === 'background-color-overlay' ) {
|
|
87
|
+
return <ItemLabelColor value={ value } />;
|
|
88
|
+
}
|
|
89
|
+
if ( type === 'background-image-overlay' ) {
|
|
90
|
+
return <ItemLabelImage value={ value } />;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const ItemLabelColor = ( { value }: { value: BackgroundOverlayItemPropValue } ) => {
|
|
95
|
+
return <span>{ value.value }</span>;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const ItemLabelImage = ( { value }: { value: BackgroundOverlayItemPropValue } ) => {
|
|
99
|
+
const { data: attachment } = useWpMediaAttachment( value?.value[ 'image-src' ]?.value.id.value || null );
|
|
100
|
+
const imageTitle = attachment?.title || null;
|
|
87
101
|
|
|
88
|
-
return <span>{
|
|
102
|
+
return <span>{ imageTitle }</span>;
|
|
89
103
|
};
|
|
@@ -1,41 +1,32 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
boxShadowPropTypeUtil,
|
|
4
|
-
type BoxShadowPropValue,
|
|
5
|
-
type PropValue,
|
|
6
|
-
type ShadowPropValue,
|
|
7
|
-
} from '@elementor/editor-props';
|
|
2
|
+
import { boxShadowPropTypeUtil, type PropKey, shadowPropTypeUtil, type ShadowPropValue } from '@elementor/editor-props';
|
|
8
3
|
import { Grid, Stack, Typography, UnstableColorIndicator } from '@elementor/ui';
|
|
9
4
|
import { __ } from '@wordpress/i18n';
|
|
10
5
|
|
|
11
|
-
import {
|
|
6
|
+
import { PropKeyProvider, PropProvider, useBoundProp } from '../bound-prop-context';
|
|
12
7
|
import { Repeater } from '../components/repeater';
|
|
13
8
|
import { createControl } from '../create-control';
|
|
14
9
|
import { ColorControl } from './color-control';
|
|
15
10
|
import { SelectControl } from './select-control';
|
|
16
11
|
import { SizeControl } from './size-control';
|
|
17
12
|
|
|
18
|
-
type SetContextValue = ( v: PropValue ) => void;
|
|
19
|
-
|
|
20
13
|
export const BoxShadowRepeaterControl = createControl( () => {
|
|
21
|
-
const { value
|
|
22
|
-
|
|
23
|
-
const setBoxShadow = ( newValue: BoxShadowPropValue[ 'value' ] ) => {
|
|
24
|
-
setValue( newValue );
|
|
25
|
-
};
|
|
14
|
+
const { propType, value, setValue } = useBoundProp( boxShadowPropTypeUtil );
|
|
26
15
|
|
|
27
16
|
return (
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
17
|
+
<PropProvider propType={ propType } value={ value } setValue={ setValue }>
|
|
18
|
+
<Repeater
|
|
19
|
+
values={ value ?? [] }
|
|
20
|
+
setValues={ setValue }
|
|
21
|
+
label={ __( 'Box shadow', 'elementor' ) }
|
|
22
|
+
itemSettings={ {
|
|
23
|
+
Icon: ItemIcon,
|
|
24
|
+
Label: ItemLabel,
|
|
25
|
+
Content: ItemContent,
|
|
26
|
+
initialValues: initialShadow,
|
|
27
|
+
} }
|
|
28
|
+
/>
|
|
29
|
+
</PropProvider>
|
|
39
30
|
);
|
|
40
31
|
} );
|
|
41
32
|
|
|
@@ -43,125 +34,70 @@ const ItemIcon = ( { value }: { value: ShadowPropValue } ) => (
|
|
|
43
34
|
<UnstableColorIndicator size="inherit" component="span" value={ value.value.color.value } />
|
|
44
35
|
);
|
|
45
36
|
|
|
46
|
-
const ItemContent = ( {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
} ) => {
|
|
55
|
-
const
|
|
56
|
-
setValue( {
|
|
57
|
-
$$type: 'shadow',
|
|
58
|
-
value: newValue,
|
|
59
|
-
} );
|
|
60
|
-
};
|
|
37
|
+
const ItemContent = ( { anchorEl, bind }: { anchorEl: HTMLElement | null; bind: PropKey } ) => {
|
|
38
|
+
return (
|
|
39
|
+
<PropKeyProvider bind={ bind }>
|
|
40
|
+
<Content anchorEl={ anchorEl } />
|
|
41
|
+
</PropKeyProvider>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const Content = ( { anchorEl }: { anchorEl: HTMLElement | null } ) => {
|
|
46
|
+
const { propType, value, setValue } = useBoundProp( shadowPropTypeUtil );
|
|
61
47
|
|
|
62
48
|
return (
|
|
63
|
-
<
|
|
64
|
-
<
|
|
65
|
-
<
|
|
66
|
-
bind="color"
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
horizontal: 'right',
|
|
80
|
-
},
|
|
81
|
-
transformOrigin: {
|
|
82
|
-
vertical: 'top',
|
|
83
|
-
horizontal: -10,
|
|
49
|
+
<PropProvider propType={ propType } value={ value } setValue={ setValue }>
|
|
50
|
+
<Stack gap={ 1.5 }>
|
|
51
|
+
<Grid container gap={ 2 } flexWrap="nowrap">
|
|
52
|
+
<Control bind="color" label={ __( 'Color', 'elementor' ) }>
|
|
53
|
+
<ColorControl
|
|
54
|
+
slotProps={ {
|
|
55
|
+
colorPicker: {
|
|
56
|
+
anchorEl,
|
|
57
|
+
anchorOrigin: {
|
|
58
|
+
vertical: 'top',
|
|
59
|
+
horizontal: 'right',
|
|
60
|
+
},
|
|
61
|
+
transformOrigin: {
|
|
62
|
+
vertical: 'top',
|
|
63
|
+
horizontal: -10,
|
|
64
|
+
},
|
|
84
65
|
},
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
>
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
</Control>
|
|
116
|
-
<Control
|
|
117
|
-
bind="vOffset"
|
|
118
|
-
label={ __( 'Vertical', 'elementor' ) }
|
|
119
|
-
value={ value.value.vOffset }
|
|
120
|
-
setValue={ ( v: ShadowPropValue[ 'value' ][ 'vOffset' ] ) =>
|
|
121
|
-
setShadow( { ...value.value, vOffset: v } )
|
|
122
|
-
}
|
|
123
|
-
>
|
|
124
|
-
<SizeControl />
|
|
125
|
-
</Control>
|
|
126
|
-
</Grid>
|
|
127
|
-
<Grid container gap={ 2 } flexWrap="nowrap">
|
|
128
|
-
<Control
|
|
129
|
-
bind="blur"
|
|
130
|
-
value={ value.value.blur }
|
|
131
|
-
label={ __( 'Blur', 'elementor' ) }
|
|
132
|
-
setValue={ ( v: ShadowPropValue[ 'value' ][ 'blur' ] ) => setShadow( { ...value.value, blur: v } ) }
|
|
133
|
-
>
|
|
134
|
-
<SizeControl />
|
|
135
|
-
</Control>
|
|
136
|
-
<Control
|
|
137
|
-
bind="spread"
|
|
138
|
-
label={ __( 'Spread', 'elementor' ) }
|
|
139
|
-
value={ value.value.spread }
|
|
140
|
-
setValue={ ( v: ShadowPropValue[ 'value' ][ 'spread' ] ) =>
|
|
141
|
-
setShadow( { ...value.value, spread: v } )
|
|
142
|
-
}
|
|
143
|
-
>
|
|
144
|
-
<SizeControl />
|
|
145
|
-
</Control>
|
|
146
|
-
</Grid>
|
|
147
|
-
</Stack>
|
|
66
|
+
} }
|
|
67
|
+
/>
|
|
68
|
+
</Control>
|
|
69
|
+
<Control bind="position" label={ __( 'Position', 'elementor' ) }>
|
|
70
|
+
<SelectControl
|
|
71
|
+
options={ [
|
|
72
|
+
{ label: __( 'Inset', 'elementor' ), value: 'inset' },
|
|
73
|
+
{ label: __( 'Outset', 'elementor' ), value: '' },
|
|
74
|
+
] }
|
|
75
|
+
/>
|
|
76
|
+
</Control>
|
|
77
|
+
</Grid>
|
|
78
|
+
<Grid container gap={ 2 } flexWrap="nowrap">
|
|
79
|
+
<Control bind="hOffset" label={ __( 'Horizontal', 'elementor' ) }>
|
|
80
|
+
<SizeControl />
|
|
81
|
+
</Control>
|
|
82
|
+
<Control bind="vOffset" label={ __( 'Vertical', 'elementor' ) }>
|
|
83
|
+
<SizeControl />
|
|
84
|
+
</Control>
|
|
85
|
+
</Grid>
|
|
86
|
+
<Grid container gap={ 2 } flexWrap="nowrap">
|
|
87
|
+
<Control bind="blur" label={ __( 'Blur', 'elementor' ) }>
|
|
88
|
+
<SizeControl />
|
|
89
|
+
</Control>
|
|
90
|
+
<Control bind="spread" label={ __( 'Spread', 'elementor' ) }>
|
|
91
|
+
<SizeControl />
|
|
92
|
+
</Control>
|
|
93
|
+
</Grid>
|
|
94
|
+
</Stack>
|
|
95
|
+
</PropProvider>
|
|
148
96
|
);
|
|
149
97
|
};
|
|
150
98
|
|
|
151
|
-
const Control =
|
|
152
|
-
|
|
153
|
-
setValue,
|
|
154
|
-
label,
|
|
155
|
-
bind,
|
|
156
|
-
children,
|
|
157
|
-
}: {
|
|
158
|
-
value: T;
|
|
159
|
-
bind: string;
|
|
160
|
-
label: string;
|
|
161
|
-
children: React.ReactNode;
|
|
162
|
-
setValue: ( v: T ) => void;
|
|
163
|
-
} ) => (
|
|
164
|
-
<BoundPropProvider value={ value } setValue={ setValue as SetContextValue } bind={ bind }>
|
|
99
|
+
const Control = ( { label, bind, children }: { bind: string; label: string; children: React.ReactNode } ) => (
|
|
100
|
+
<PropKeyProvider bind={ bind }>
|
|
165
101
|
<Grid item xs={ 6 }>
|
|
166
102
|
<Grid container gap={ 1 } alignItems="center">
|
|
167
103
|
<Grid item xs={ 12 }>
|
|
@@ -174,7 +110,7 @@ const Control = < T extends PropValue >( {
|
|
|
174
110
|
</Grid>
|
|
175
111
|
</Grid>
|
|
176
112
|
</Grid>
|
|
177
|
-
</
|
|
113
|
+
</PropKeyProvider>
|
|
178
114
|
);
|
|
179
115
|
|
|
180
116
|
const ItemLabel = ( { value }: { value: ShadowPropValue } ) => {
|
|
@@ -1,29 +1,25 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { colorPropTypeUtil } from '@elementor/editor-props';
|
|
2
|
+
import { colorPropTypeUtil, type PropTypeUtil } from '@elementor/editor-props';
|
|
3
3
|
import { UnstableColorField, type UnstableColorFieldProps } from '@elementor/ui';
|
|
4
4
|
|
|
5
5
|
import { useBoundProp } from '../bound-prop-context';
|
|
6
6
|
import ControlActions from '../control-actions/control-actions';
|
|
7
7
|
import { createControl } from '../create-control';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
type Props = Partial< Omit< UnstableColorFieldProps, 'value' | 'onChange' > > & {
|
|
10
|
+
propTypeUtil?: PropTypeUtil< string, string >;
|
|
11
|
+
};
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
13
|
+
export const ColorControl = createControl( ( { propTypeUtil = colorPropTypeUtil, ...props }: Props ) => {
|
|
14
|
+
const { value, setValue } = useBoundProp( propTypeUtil );
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
);
|
|
16
|
+
const handleChange = ( selectedColor: string ) => {
|
|
17
|
+
setValue( selectedColor );
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<ControlActions>
|
|
22
|
+
<UnstableColorField size="tiny" { ...props } value={ value ?? '' } onChange={ handleChange } fullWidth />
|
|
23
|
+
</ControlActions>
|
|
24
|
+
);
|
|
25
|
+
} );
|