@elementor/editor-controls 3.32.0-84 → 3.32.0-87
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/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1359 -1514
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1157 -1316
- package/dist/index.mjs.map +1 -1
- package/package.json +14 -14
- package/src/components/unstable-repeater/context/repeater-context.tsx +1 -1
- package/src/components/unstable-repeater/items/edit-item-popover.tsx +2 -4
- package/src/components/unstable-repeater/items/item.tsx +10 -1
- package/src/controls/box-shadow-repeater-control.tsx +30 -26
- package/src/controls/filter-control/configs.ts +49 -0
- package/src/controls/filter-control/context/filter-config-context.tsx +49 -0
- package/src/controls/filter-control/{drop-shadow-item-content.tsx → drop-shadow/drop-shadow-item-content.tsx} +11 -14
- package/src/controls/filter-control/filter-content.tsx +78 -0
- package/src/controls/filter-control/filter-icon.tsx +21 -0
- package/src/controls/filter-control/filter-label.tsx +13 -0
- package/src/controls/filter-control/filter-repeater-control.tsx +93 -0
- package/src/controls/filter-control/single-size/single-size-item-content.tsx +48 -0
- package/src/controls/filter-control/single-size/single-size-item-label.tsx +30 -0
- package/src/controls/filter-control/utils.ts +130 -0
- package/src/controls/size-control.tsx +1 -1
- package/src/index.ts +1 -1
- package/src/controls/filter-repeater-control.tsx +0 -322
- /package/src/controls/filter-control/{drop-shadow-item-label.tsx → drop-shadow/drop-shadow-item-label.tsx} +0 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { DropShadowFilterPropValue, PropType, SizePropValue, UnionPropType } from '@elementor/editor-props';
|
|
2
|
+
import { __ } from '@wordpress/i18n';
|
|
3
|
+
|
|
4
|
+
import { type FilterFunction, type FilterFunctionGroup, FILTERS_BY_GROUP } from './configs';
|
|
5
|
+
|
|
6
|
+
const AMOUNT_VALUE_NAME = __( 'Amount', 'elementor' );
|
|
7
|
+
|
|
8
|
+
type SingleArgFilterFuncPropType = PropType & {
|
|
9
|
+
shape: {
|
|
10
|
+
size?: PropType;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type DropShadowFuncPropType = PropType & {
|
|
15
|
+
shape: {
|
|
16
|
+
color: PropType;
|
|
17
|
+
xAxis: PropType;
|
|
18
|
+
yAxis: PropType;
|
|
19
|
+
blur: PropType;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type CssFilterFuncPropType = PropType & {
|
|
24
|
+
shape: {
|
|
25
|
+
args: {
|
|
26
|
+
prop_types: {
|
|
27
|
+
[ K in FilterFunctionGroup ]: SingleArgFilterFuncPropType | DropShadowFuncPropType;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type DefaultValue = { size: SizePropValue } | DropShadowFilterPropValue[ 'value' ];
|
|
34
|
+
|
|
35
|
+
type CssFilterFuncValue = ReturnType< typeof createDefaultValue >;
|
|
36
|
+
|
|
37
|
+
export type FilterConfigEntry = {
|
|
38
|
+
name: string;
|
|
39
|
+
valueName: string;
|
|
40
|
+
filterFunctionGroup: FilterFunctionGroup;
|
|
41
|
+
defaultValue: CssFilterFuncValue;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type FilterConfigMap = Record< FilterFunction, FilterConfigEntry >;
|
|
45
|
+
|
|
46
|
+
const DEFAULT_FACTORIES: Partial< Record< FilterFunction, ( propType: PropType ) => DefaultValue > > = {
|
|
47
|
+
'drop-shadow': ( propType: PropType ) => buildDropShadowDefault( propType as DropShadowFuncPropType ),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export function buildFilterConfig( cssFilterPropType: PropType ): FilterConfigMap {
|
|
51
|
+
function createEntry(
|
|
52
|
+
filterFunctionGroup: FilterFunctionGroup,
|
|
53
|
+
filterFunction: FilterFunction,
|
|
54
|
+
{ name, valueName }: { name: string; valueName?: string }
|
|
55
|
+
): [ FilterFunction, FilterConfigEntry ] {
|
|
56
|
+
const propType = extractPropType( cssFilterPropType as CssFilterFuncPropType, filterFunctionGroup );
|
|
57
|
+
|
|
58
|
+
const value =
|
|
59
|
+
DEFAULT_FACTORIES[ filterFunction ]?.( propType ) ??
|
|
60
|
+
buildSizeDefault( propType as SingleArgFilterFuncPropType );
|
|
61
|
+
|
|
62
|
+
const defaultValue = createDefaultValue( {
|
|
63
|
+
filterFunction,
|
|
64
|
+
filterFunctionGroup,
|
|
65
|
+
value,
|
|
66
|
+
} );
|
|
67
|
+
|
|
68
|
+
return [
|
|
69
|
+
filterFunction,
|
|
70
|
+
{
|
|
71
|
+
name,
|
|
72
|
+
valueName: valueName ?? AMOUNT_VALUE_NAME,
|
|
73
|
+
defaultValue,
|
|
74
|
+
filterFunctionGroup,
|
|
75
|
+
},
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const entries = Object.entries( FILTERS_BY_GROUP ).flatMap( ( [ filterFunctionGroup, group ] ) =>
|
|
80
|
+
Object.entries( group ).map( ( [ filterFunction, meta ] ) =>
|
|
81
|
+
createEntry( filterFunctionGroup as FilterFunctionGroup, filterFunction as FilterFunction, meta )
|
|
82
|
+
)
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
return Object.fromEntries( entries ) as FilterConfigMap;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
type DefaultBuilderArgs = {
|
|
89
|
+
filterFunction: FilterFunction;
|
|
90
|
+
filterFunctionGroup: FilterFunctionGroup;
|
|
91
|
+
value: DefaultValue;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
function createDefaultValue( { filterFunction, filterFunctionGroup, value }: DefaultBuilderArgs ) {
|
|
95
|
+
return {
|
|
96
|
+
$$type: 'css-filter-func',
|
|
97
|
+
value: {
|
|
98
|
+
func: { $$type: 'string', value: filterFunction },
|
|
99
|
+
args: {
|
|
100
|
+
$$type: filterFunctionGroup,
|
|
101
|
+
value,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function buildSizeDefault( propType: SingleArgFilterFuncPropType ): DefaultValue {
|
|
108
|
+
const sizePropType = propType?.shape?.size;
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
size: sizePropType?.default as SizePropValue,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function buildDropShadowDefault( propType: DropShadowFuncPropType ): DefaultValue {
|
|
116
|
+
const dropShadowPropType = propType.shape;
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
blur: dropShadowPropType?.blur?.default,
|
|
120
|
+
xAxis: dropShadowPropType?.xAxis?.default,
|
|
121
|
+
yAxis: dropShadowPropType?.yAxis?.default,
|
|
122
|
+
color:
|
|
123
|
+
dropShadowPropType?.color?.default ??
|
|
124
|
+
( dropShadowPropType?.color as UnionPropType ).prop_types.color.default,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function extractPropType( propType: CssFilterFuncPropType, filterFunctionGroup: FilterFunctionGroup ) {
|
|
129
|
+
return propType.shape?.args?.prop_types[ filterFunctionGroup ];
|
|
130
|
+
}
|
|
@@ -220,7 +220,7 @@ export const SizeControl = createControl(
|
|
|
220
220
|
popupState={ popupState }
|
|
221
221
|
min={ min }
|
|
222
222
|
/>
|
|
223
|
-
{ anchorRef?.current && (
|
|
223
|
+
{ anchorRef?.current && popupState.isOpen && (
|
|
224
224
|
<TextFieldPopover
|
|
225
225
|
popupState={ popupState }
|
|
226
226
|
anchorRef={ anchorRef }
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { TextAreaControl } from './controls/text-area-control';
|
|
|
5
5
|
export { SizeControl } from './controls/size-control';
|
|
6
6
|
export { StrokeControl } from './controls/stroke-control';
|
|
7
7
|
export { BoxShadowRepeaterControl } from './controls/box-shadow-repeater-control';
|
|
8
|
-
export { FilterRepeaterControl } from './controls/filter-repeater-control';
|
|
8
|
+
export { FilterRepeaterControl } from './controls/filter-control/filter-repeater-control';
|
|
9
9
|
export { SelectControl } from './controls/select-control';
|
|
10
10
|
export { ColorControl } from './controls/color-control';
|
|
11
11
|
export { ToggleControl } from './controls/toggle-control';
|
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { useRef } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
type CreateOptions,
|
|
5
|
-
cssFilterFunctionPropUtil,
|
|
6
|
-
type FilterItemPropValue,
|
|
7
|
-
filterPropTypeUtil,
|
|
8
|
-
type PropKey,
|
|
9
|
-
type SizePropValue,
|
|
10
|
-
} from '@elementor/editor-props';
|
|
11
|
-
import { backdropFilterPropTypeUtil } from '@elementor/editor-props';
|
|
12
|
-
import { Box, Grid, styled, UnstableColorIndicator } from '@elementor/ui';
|
|
13
|
-
import { __ } from '@wordpress/i18n';
|
|
14
|
-
|
|
15
|
-
import { PropKeyProvider, PropProvider, useBoundProp } from '../bound-prop-context';
|
|
16
|
-
import { ControlFormLabel } from '../components/control-form-label';
|
|
17
|
-
import { PopoverContent } from '../components/popover-content';
|
|
18
|
-
import { PopoverGridContainer } from '../components/popover-grid-container';
|
|
19
|
-
import { type CollectionPropUtil, Repeater } from '../components/repeater';
|
|
20
|
-
import { createControl } from '../create-control';
|
|
21
|
-
import { type LengthUnit, lengthUnits, type Unit } from '../utils/size-control';
|
|
22
|
-
import { DropShadowItemContent } from './filter-control/drop-shadow-item-content';
|
|
23
|
-
import { DropShadowItemLabel } from './filter-control/drop-shadow-item-label';
|
|
24
|
-
import { SelectControl } from './select-control';
|
|
25
|
-
import { SizeControl, type SizeControlProps } from './size-control';
|
|
26
|
-
|
|
27
|
-
type FilterType = FilterItemPropValue[ 'value' ][ 'func' ];
|
|
28
|
-
|
|
29
|
-
const DEFAULT_FILTER = 'blur';
|
|
30
|
-
|
|
31
|
-
type FilterItemConfig = {
|
|
32
|
-
defaultValue: FilterItemPropValue;
|
|
33
|
-
name: string;
|
|
34
|
-
valueName: string;
|
|
35
|
-
units?: Exclude< SizePropValue[ 'value' ][ 'unit' ], 'custom' | 'auto' >[];
|
|
36
|
-
sizeVariant?: SizeControlProps[ 'variant' ];
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const filterConfig: Record< string, FilterItemConfig > = {
|
|
40
|
-
blur: {
|
|
41
|
-
defaultValue: {
|
|
42
|
-
$$type: 'css-filter-func',
|
|
43
|
-
value: {
|
|
44
|
-
func: { $$type: 'string', value: 'blur' },
|
|
45
|
-
args: { $$type: 'size', value: { size: 0, unit: 'px' } },
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
name: __( 'Blur', 'elementor' ),
|
|
49
|
-
valueName: __( 'Radius', 'elementor' ),
|
|
50
|
-
units: lengthUnits.filter( ( unit ) => unit !== '%' ),
|
|
51
|
-
},
|
|
52
|
-
brightness: {
|
|
53
|
-
defaultValue: {
|
|
54
|
-
$$type: 'css-filter-func',
|
|
55
|
-
value: {
|
|
56
|
-
func: { $$type: 'string', value: 'brightness' },
|
|
57
|
-
args: { $$type: 'size', value: { size: 100, unit: '%' } },
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
name: __( 'Brightness', 'elementor' ),
|
|
61
|
-
valueName: __( 'Amount', 'elementor' ),
|
|
62
|
-
units: [ '%' ],
|
|
63
|
-
},
|
|
64
|
-
contrast: {
|
|
65
|
-
defaultValue: {
|
|
66
|
-
$$type: 'css-filter-func',
|
|
67
|
-
value: {
|
|
68
|
-
func: { $$type: 'string', value: 'contrast' },
|
|
69
|
-
args: { $$type: 'size', value: { size: 100, unit: '%' } },
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
name: __( 'Contrast', 'elementor' ),
|
|
73
|
-
valueName: __( 'Amount', 'elementor' ),
|
|
74
|
-
units: [ '%' ],
|
|
75
|
-
},
|
|
76
|
-
'hue-rotate': {
|
|
77
|
-
defaultValue: {
|
|
78
|
-
$$type: 'css-filter-func',
|
|
79
|
-
value: {
|
|
80
|
-
func: { $$type: 'string', value: 'hue-rotate' },
|
|
81
|
-
args: { $$type: 'size', value: { size: 0, unit: 'deg' } },
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
name: __( 'Hue Rotate', 'elementor' ),
|
|
85
|
-
valueName: __( 'Angle', 'elementor' ),
|
|
86
|
-
units: [ 'deg', 'rad', 'grad', 'turn' ],
|
|
87
|
-
},
|
|
88
|
-
saturate: {
|
|
89
|
-
defaultValue: {
|
|
90
|
-
$$type: 'css-filter-func',
|
|
91
|
-
value: {
|
|
92
|
-
func: { $$type: 'string', value: 'saturate' },
|
|
93
|
-
args: { $$type: 'size', value: { size: 100, unit: '%' } },
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
name: __( 'Saturate', 'elementor' ),
|
|
97
|
-
valueName: __( 'Amount', 'elementor' ),
|
|
98
|
-
units: [ '%' ],
|
|
99
|
-
},
|
|
100
|
-
grayscale: {
|
|
101
|
-
defaultValue: {
|
|
102
|
-
$$type: 'css-filter-func',
|
|
103
|
-
value: {
|
|
104
|
-
func: { $$type: 'string', value: 'grayscale' },
|
|
105
|
-
args: { $$type: 'size', value: { size: 0, unit: '%' } },
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
name: __( 'Grayscale', 'elementor' ),
|
|
109
|
-
valueName: __( 'Amount', 'elementor' ),
|
|
110
|
-
units: [ '%' ],
|
|
111
|
-
},
|
|
112
|
-
invert: {
|
|
113
|
-
defaultValue: {
|
|
114
|
-
$$type: 'css-filter-func',
|
|
115
|
-
value: {
|
|
116
|
-
func: { $$type: 'string', value: 'invert' },
|
|
117
|
-
args: { $$type: 'size', value: { size: 0, unit: '%' } },
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
name: __( 'Invert', 'elementor' ),
|
|
121
|
-
valueName: __( 'Amount', 'elementor' ),
|
|
122
|
-
units: [ '%' ],
|
|
123
|
-
},
|
|
124
|
-
sepia: {
|
|
125
|
-
defaultValue: {
|
|
126
|
-
$$type: 'css-filter-func',
|
|
127
|
-
value: {
|
|
128
|
-
func: { $$type: 'string', value: 'sepia' },
|
|
129
|
-
args: { $$type: 'size', value: { size: 0, unit: '%' } },
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
name: __( 'Sepia', 'elementor' ),
|
|
133
|
-
valueName: __( 'Amount', 'elementor' ),
|
|
134
|
-
units: [ '%' ],
|
|
135
|
-
},
|
|
136
|
-
'drop-shadow': {
|
|
137
|
-
defaultValue: {
|
|
138
|
-
$$type: 'css-filter-func',
|
|
139
|
-
value: {
|
|
140
|
-
func: { $$type: 'string', value: 'drop-shadow' },
|
|
141
|
-
args: {
|
|
142
|
-
$$type: 'drop-shadow',
|
|
143
|
-
value: {
|
|
144
|
-
xAxis: { $$type: 'size', value: { size: 0, unit: 'px' } },
|
|
145
|
-
yAxis: { $$type: 'size', value: { size: 0, unit: 'px' } },
|
|
146
|
-
blur: { $$type: 'size', value: { size: 10, unit: 'px' } },
|
|
147
|
-
color: { $$type: 'color', value: 'rgba(0, 0, 0, 1)' },
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
name: __( 'Drop shadow', 'elementor' ),
|
|
153
|
-
valueName: __( 'Drop-shadow', 'elementor' ),
|
|
154
|
-
units: lengthUnits.filter( ( unit ) => unit !== '%' ),
|
|
155
|
-
},
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
const filterKeys = Object.keys( filterConfig );
|
|
159
|
-
|
|
160
|
-
const isSingleSize = ( key: string ): boolean => {
|
|
161
|
-
return ! [ 'drop-shadow' ].includes( key );
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
export const FilterRepeaterControl = createControl( ( { filterPropName = 'filter' }: { filterPropName?: string } ) => {
|
|
165
|
-
const [ propUtil, label ] =
|
|
166
|
-
filterPropName === 'backdrop-filter'
|
|
167
|
-
? [ backdropFilterPropTypeUtil, __( 'Backdrop Filters', 'elementor' ) ]
|
|
168
|
-
: [ filterPropTypeUtil, __( 'Filters', 'elementor' ) ];
|
|
169
|
-
const { propType, value: filterValues, setValue, disabled } = useBoundProp( propUtil );
|
|
170
|
-
|
|
171
|
-
return (
|
|
172
|
-
<PropProvider propType={ propType } value={ filterValues } setValue={ setValue }>
|
|
173
|
-
<Repeater
|
|
174
|
-
openOnAdd
|
|
175
|
-
disabled={ disabled }
|
|
176
|
-
values={ filterValues ?? [] }
|
|
177
|
-
setValues={ setValue }
|
|
178
|
-
label={ label }
|
|
179
|
-
collectionPropUtil={ propUtil }
|
|
180
|
-
itemSettings={ {
|
|
181
|
-
Icon: ItemIcon,
|
|
182
|
-
Label: ItemLabel,
|
|
183
|
-
Content: ItemContent,
|
|
184
|
-
initialValues: filterConfig[ DEFAULT_FILTER ].defaultValue,
|
|
185
|
-
} }
|
|
186
|
-
/>
|
|
187
|
-
</PropProvider>
|
|
188
|
-
);
|
|
189
|
-
} );
|
|
190
|
-
|
|
191
|
-
const StyledUnstableColorIndicator = styled( UnstableColorIndicator )( ( { theme } ) => ( {
|
|
192
|
-
borderRadius: `${ theme.shape.borderRadius / 2 }px`,
|
|
193
|
-
} ) );
|
|
194
|
-
|
|
195
|
-
const ItemIcon = ( { value }: { value: FilterItemPropValue } ) => {
|
|
196
|
-
return isSingleSize( value.value.func.value ?? '' ) ? (
|
|
197
|
-
<></>
|
|
198
|
-
) : (
|
|
199
|
-
<StyledUnstableColorIndicator size="inherit" component="span" value={ value.value.args.value.color.value } />
|
|
200
|
-
);
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const ItemLabel = ( { value }: { value: FilterItemPropValue } ) => {
|
|
204
|
-
return isSingleSize( value.value.func.value ?? '' ) ? (
|
|
205
|
-
<SingleSizeItemLabel value={ value } />
|
|
206
|
-
) : (
|
|
207
|
-
<DropShadowItemLabel value={ value } />
|
|
208
|
-
);
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
const SingleSizeItemLabel = ( { value }: { value: FilterItemPropValue } ) => {
|
|
212
|
-
const { func, args } = value.value;
|
|
213
|
-
const defaultUnit =
|
|
214
|
-
( filterConfig[ func.value ?? '' ].defaultValue.value.args as SizePropValue ).value.unit ?? lengthUnits[ 0 ];
|
|
215
|
-
const { unit, size } = ( args as SizePropValue ).value ?? { unit: defaultUnit, size: 0 };
|
|
216
|
-
|
|
217
|
-
const label = (
|
|
218
|
-
<Box component="span" style={ { textTransform: 'capitalize' } }>
|
|
219
|
-
{ func.value ?? '' }:
|
|
220
|
-
</Box>
|
|
221
|
-
);
|
|
222
|
-
|
|
223
|
-
return (
|
|
224
|
-
<Box component="span">
|
|
225
|
-
{ label }
|
|
226
|
-
{ unit !== 'custom' ? ` ${ size ?? 0 }${ unit ?? defaultUnit }` : size }
|
|
227
|
-
</Box>
|
|
228
|
-
);
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const ItemContent = ( {
|
|
232
|
-
bind,
|
|
233
|
-
collectionPropUtil,
|
|
234
|
-
anchorEl,
|
|
235
|
-
}: {
|
|
236
|
-
bind: PropKey;
|
|
237
|
-
collectionPropUtil?: CollectionPropUtil< FilterItemPropValue >;
|
|
238
|
-
anchorEl?: HTMLElement | null;
|
|
239
|
-
} ) => {
|
|
240
|
-
const { value: filterValues = [] } = useBoundProp( collectionPropUtil ?? filterPropTypeUtil );
|
|
241
|
-
const itemIndex = parseInt( bind, 10 );
|
|
242
|
-
const item = filterValues?.[ itemIndex ];
|
|
243
|
-
return item ? (
|
|
244
|
-
<PropKeyProvider bind={ bind }>
|
|
245
|
-
<PropContent item={ item } anchorEl={ anchorEl } />
|
|
246
|
-
</PropKeyProvider>
|
|
247
|
-
) : null;
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
const PropContent = ( { item, anchorEl }: { item: FilterItemPropValue; anchorEl?: HTMLElement | null } ) => {
|
|
251
|
-
const propContext = useBoundProp( cssFilterFunctionPropUtil );
|
|
252
|
-
|
|
253
|
-
const handleValueChange = (
|
|
254
|
-
changedValue: FilterItemPropValue[ 'value' ],
|
|
255
|
-
options?: CreateOptions,
|
|
256
|
-
meta?: { bind?: PropKey }
|
|
257
|
-
) => {
|
|
258
|
-
let newValue = structuredClone( changedValue );
|
|
259
|
-
const newFuncName = newValue?.func.value ?? '';
|
|
260
|
-
if ( meta?.bind === 'func' ) {
|
|
261
|
-
newValue = structuredClone( filterConfig[ newFuncName ].defaultValue.value );
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if ( ! newValue.args ) {
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
propContext.setValue( newValue );
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
return (
|
|
271
|
-
<PropProvider { ...propContext } setValue={ handleValueChange }>
|
|
272
|
-
<PopoverContent p={ 1.5 }>
|
|
273
|
-
<PopoverGridContainer>
|
|
274
|
-
<Grid item xs={ 6 }>
|
|
275
|
-
<ControlFormLabel>{ __( 'Filter', 'elementor' ) }</ControlFormLabel>
|
|
276
|
-
</Grid>
|
|
277
|
-
<Grid item xs={ 6 }>
|
|
278
|
-
<PropKeyProvider bind="func">
|
|
279
|
-
<SelectControl
|
|
280
|
-
options={ filterKeys.map( ( filterKey ) => ( {
|
|
281
|
-
label: filterConfig[ filterKey ].name,
|
|
282
|
-
value: filterKey,
|
|
283
|
-
} ) ) }
|
|
284
|
-
/>
|
|
285
|
-
</PropKeyProvider>
|
|
286
|
-
</Grid>
|
|
287
|
-
</PopoverGridContainer>
|
|
288
|
-
<PropKeyProvider bind="args">
|
|
289
|
-
<Content filterType={ item?.value.func } anchorEl={ anchorEl } />
|
|
290
|
-
</PropKeyProvider>
|
|
291
|
-
</PopoverContent>
|
|
292
|
-
</PropProvider>
|
|
293
|
-
);
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
const Content = ( { filterType, anchorEl }: { filterType: FilterType; anchorEl?: HTMLElement | null } ) => {
|
|
297
|
-
const filterName = filterType?.value || DEFAULT_FILTER;
|
|
298
|
-
const filterItemConfig = filterConfig[ filterName ];
|
|
299
|
-
const { units = [] } = filterItemConfig;
|
|
300
|
-
|
|
301
|
-
return isSingleSize( filterName ) ? (
|
|
302
|
-
<SingleSizeItemContent filterType={ filterName } />
|
|
303
|
-
) : (
|
|
304
|
-
<DropShadowItemContent units={ units as LengthUnit[] } anchorEl={ anchorEl } />
|
|
305
|
-
);
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
const SingleSizeItemContent = ( { filterType }: { filterType: string } ) => {
|
|
309
|
-
const { valueName, defaultValue, units } = filterConfig[ filterType ];
|
|
310
|
-
const rowRef = useRef< HTMLDivElement >( null );
|
|
311
|
-
const defaultUnit = ( defaultValue.value.args as SizePropValue ).value.unit;
|
|
312
|
-
return (
|
|
313
|
-
<PopoverGridContainer ref={ rowRef }>
|
|
314
|
-
<Grid item xs={ 6 }>
|
|
315
|
-
<ControlFormLabel>{ valueName }</ControlFormLabel>
|
|
316
|
-
</Grid>
|
|
317
|
-
<Grid item xs={ 6 }>
|
|
318
|
-
<SizeControl anchorRef={ rowRef } units={ units as LengthUnit[] } defaultUnit={ defaultUnit as Unit } />
|
|
319
|
-
</Grid>
|
|
320
|
-
</PopoverGridContainer>
|
|
321
|
-
);
|
|
322
|
-
};
|
|
File without changes
|