@elementor/editor-controls 0.12.1 → 0.14.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 +24 -0
- package/dist/index.d.mts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +497 -304
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +452 -252
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/components/repeater.tsx +84 -28
- package/src/components/sortable.tsx +108 -0
- package/src/controls/background-control/background-overlay/background-image-overlay/background-image-overlay-repeat.tsx +1 -1
- package/src/controls/background-control/background-overlay/background-image-overlay/background-image-overlay-size.tsx +8 -2
- package/src/controls/font-family-control.tsx +2 -2
- package/src/controls/gap-control.tsx +1 -1
- package/src/controls/image-control.tsx +1 -1
- package/src/controls/image-media-control.tsx +1 -1
- package/src/controls/link-control.tsx +2 -13
- package/src/controls/linked-dimensions-control.tsx +108 -88
- package/src/controls/size-control.tsx +91 -26
- package/src/controls/svg-media-control.tsx +2 -2
- package/src/index.ts +1 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { sizePropTypeUtil } from '@elementor/editor-props';
|
|
2
|
+
import { sizePropTypeUtil, stringPropTypeUtil } from '@elementor/editor-props';
|
|
3
3
|
import { InputAdornment } from '@elementor/ui';
|
|
4
4
|
|
|
5
5
|
import { useBoundProp } from '../bound-prop-context';
|
|
@@ -8,6 +8,7 @@ import ControlActions from '../control-actions/control-actions';
|
|
|
8
8
|
import { createControl } from '../create-control';
|
|
9
9
|
import { useSyncExternalState } from '../hooks/use-sync-external-state';
|
|
10
10
|
|
|
11
|
+
export type ExtendedValue = 'auto';
|
|
11
12
|
export type Unit = 'px' | '%' | 'em' | 'rem' | 'vw' | 'vh';
|
|
12
13
|
|
|
13
14
|
const defaultUnits: Unit[] = [ 'px', '%', 'em', 'rem', 'vw', 'vh' ];
|
|
@@ -19,34 +20,98 @@ type SizeControlProps = {
|
|
|
19
20
|
placeholder?: string;
|
|
20
21
|
startIcon?: React.ReactNode;
|
|
21
22
|
units?: Unit[];
|
|
23
|
+
extendedValues?: ExtendedValue[];
|
|
22
24
|
};
|
|
23
25
|
|
|
24
|
-
export const SizeControl = createControl(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
26
|
+
export const SizeControl = createControl(
|
|
27
|
+
( { units = defaultUnits, extendedValues = [], placeholder, startIcon }: SizeControlProps ) => {
|
|
28
|
+
const { value: sizeValue, setValue: setSizeValue } = useBoundProp( sizePropTypeUtil );
|
|
29
|
+
|
|
30
|
+
const [ state, setState ] = useSyncExternalState( {
|
|
31
|
+
external: sizeValue,
|
|
32
|
+
setExternal: setSizeValue,
|
|
33
|
+
persistWhen: ( controlValue ) => !! controlValue?.size || controlValue?.size === 0,
|
|
34
|
+
fallback: ( controlValue ) => ( { unit: controlValue?.unit || defaultUnit, size: defaultSize } ),
|
|
35
|
+
} );
|
|
36
|
+
|
|
37
|
+
const handleUnitChange = ( unit: Unit ) => {
|
|
38
|
+
setState( ( prev ) => ( {
|
|
39
|
+
size: prev?.size ?? defaultSize,
|
|
40
|
+
unit,
|
|
41
|
+
} ) );
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const handleSizeChange = ( event: React.ChangeEvent< HTMLInputElement > ) => {
|
|
45
|
+
const { value: size } = event.target;
|
|
46
|
+
|
|
47
|
+
setState( ( prev ) => ( {
|
|
48
|
+
...prev,
|
|
49
|
+
size: size || size === '0' ? parseFloat( size ) : defaultSize,
|
|
50
|
+
} ) );
|
|
51
|
+
};
|
|
40
52
|
|
|
41
|
-
|
|
42
|
-
|
|
53
|
+
const inputProps = {
|
|
54
|
+
size: state.size,
|
|
55
|
+
unit: state.unit,
|
|
56
|
+
placeholder,
|
|
57
|
+
startIcon,
|
|
58
|
+
units,
|
|
59
|
+
extendedValues,
|
|
60
|
+
handleSizeChange,
|
|
61
|
+
handleUnitChange,
|
|
62
|
+
};
|
|
43
63
|
|
|
44
|
-
|
|
45
|
-
...
|
|
46
|
-
|
|
47
|
-
}
|
|
64
|
+
if ( extendedValues?.length ) {
|
|
65
|
+
return <ExtendedSizeInput { ...inputProps } />;
|
|
66
|
+
}
|
|
67
|
+
return <SizeInput { ...inputProps } />;
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const ExtendedSizeInput = ( props: SizeInputProps ) => {
|
|
72
|
+
const { value: stringValue, setValue: setStringValue } = useBoundProp( stringPropTypeUtil );
|
|
73
|
+
const { extendedValues = [] } = props;
|
|
74
|
+
|
|
75
|
+
const unit = ( stringValue ?? props.unit ) as Unit;
|
|
76
|
+
|
|
77
|
+
const handleUnitChange = ( newUnit: Unit ) => {
|
|
78
|
+
if ( extendedValues.includes( newUnit as ExtendedValue ) ) {
|
|
79
|
+
setStringValue( newUnit );
|
|
80
|
+
} else {
|
|
81
|
+
props.handleUnitChange( newUnit );
|
|
82
|
+
}
|
|
48
83
|
};
|
|
49
84
|
|
|
85
|
+
return (
|
|
86
|
+
<SizeInput
|
|
87
|
+
{ ...props }
|
|
88
|
+
units={ [ ...props.units, ...( extendedValues as unknown as Unit[] ) ] }
|
|
89
|
+
handleUnitChange={ handleUnitChange }
|
|
90
|
+
unit={ unit }
|
|
91
|
+
/>
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
type SizeInputProps = {
|
|
96
|
+
unit: Unit;
|
|
97
|
+
size: number;
|
|
98
|
+
placeholder?: string;
|
|
99
|
+
startIcon?: React.ReactNode;
|
|
100
|
+
units: Unit[];
|
|
101
|
+
extendedValues?: ExtendedValue[];
|
|
102
|
+
handleUnitChange: ( unit: Unit ) => void;
|
|
103
|
+
handleSizeChange: ( event: React.ChangeEvent< HTMLInputElement > ) => void;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const SizeInput = ( {
|
|
107
|
+
units,
|
|
108
|
+
handleUnitChange,
|
|
109
|
+
handleSizeChange,
|
|
110
|
+
placeholder,
|
|
111
|
+
startIcon,
|
|
112
|
+
size,
|
|
113
|
+
unit,
|
|
114
|
+
}: SizeInputProps ) => {
|
|
50
115
|
return (
|
|
51
116
|
<ControlActions>
|
|
52
117
|
<TextFieldInnerSelection
|
|
@@ -54,7 +119,7 @@ export const SizeControl = createControl( ( { units = defaultUnits, placeholder,
|
|
|
54
119
|
<SelectionEndAdornment
|
|
55
120
|
options={ units }
|
|
56
121
|
onClick={ handleUnitChange }
|
|
57
|
-
value={
|
|
122
|
+
value={ unit ?? defaultUnit }
|
|
58
123
|
/>
|
|
59
124
|
}
|
|
60
125
|
placeholder={ placeholder }
|
|
@@ -62,9 +127,9 @@ export const SizeControl = createControl( ( { units = defaultUnits, placeholder,
|
|
|
62
127
|
startIcon ? <InputAdornment position="start">{ startIcon }</InputAdornment> : undefined
|
|
63
128
|
}
|
|
64
129
|
type="number"
|
|
65
|
-
value={ Number.isNaN(
|
|
130
|
+
value={ Number.isNaN( size ) ? '' : size }
|
|
66
131
|
onChange={ handleSizeChange }
|
|
67
132
|
/>
|
|
68
133
|
</ControlActions>
|
|
69
134
|
);
|
|
70
|
-
}
|
|
135
|
+
};
|
|
@@ -58,7 +58,7 @@ export const SvgMediaControl = createControl( () => {
|
|
|
58
58
|
|
|
59
59
|
return (
|
|
60
60
|
<Stack gap={ 1 }>
|
|
61
|
-
<ControlLabel> { __( '
|
|
61
|
+
<ControlLabel> { __( 'SVG', 'elementor' ) } </ControlLabel>
|
|
62
62
|
<ControlActions>
|
|
63
63
|
<StyledCard variant="outlined">
|
|
64
64
|
<StyledCardMediaContainer>
|
|
@@ -96,7 +96,7 @@ export const SvgMediaControl = createControl( () => {
|
|
|
96
96
|
startIcon={ <UploadIcon /> }
|
|
97
97
|
onClick={ () => open( { mode: 'upload' } ) }
|
|
98
98
|
>
|
|
99
|
-
{ __( 'Upload
|
|
99
|
+
{ __( 'Upload', 'elementor' ) }
|
|
100
100
|
</Button>
|
|
101
101
|
</Stack>
|
|
102
102
|
</CardOverlay>
|
package/src/index.ts
CHANGED
|
@@ -29,6 +29,7 @@ export type { EqualUnequalItems } from './controls/equal-unequal-sizes-control';
|
|
|
29
29
|
export type { ControlActionsItems } from './control-actions/control-actions-context';
|
|
30
30
|
export type { PropProviderProps } from './bound-prop-context';
|
|
31
31
|
export type { SetValue } from './bound-prop-context/prop-context';
|
|
32
|
+
export type { ExtendedValue } from './controls/size-control';
|
|
32
33
|
|
|
33
34
|
// providers
|
|
34
35
|
export { createControlReplacement, ControlReplacementProvider } from './create-control-replacement';
|