@elementor/editor-controls 4.2.0-874 → 4.2.0-876
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.js +64 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -16
- package/src/controls/query-filter-repeater-control.tsx +91 -12
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": "4.2.0-
|
|
4
|
+
"version": "4.2.0-876",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -40,23 +40,23 @@
|
|
|
40
40
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@elementor/editor-current-user": "4.2.0-
|
|
44
|
-
"@elementor/editor-elements": "4.2.0-
|
|
45
|
-
"@elementor/editor-props": "4.2.0-
|
|
46
|
-
"@elementor/editor-responsive": "4.2.0-
|
|
47
|
-
"@elementor/editor-ui": "4.2.0-
|
|
48
|
-
"@elementor/editor-v1-adapters": "4.2.0-
|
|
49
|
-
"@elementor/env": "4.2.0-
|
|
50
|
-
"@elementor/events": "4.2.0-
|
|
51
|
-
"@elementor/http-client": "4.2.0-
|
|
43
|
+
"@elementor/editor-current-user": "4.2.0-876",
|
|
44
|
+
"@elementor/editor-elements": "4.2.0-876",
|
|
45
|
+
"@elementor/editor-props": "4.2.0-876",
|
|
46
|
+
"@elementor/editor-responsive": "4.2.0-876",
|
|
47
|
+
"@elementor/editor-ui": "4.2.0-876",
|
|
48
|
+
"@elementor/editor-v1-adapters": "4.2.0-876",
|
|
49
|
+
"@elementor/env": "4.2.0-876",
|
|
50
|
+
"@elementor/events": "4.2.0-876",
|
|
51
|
+
"@elementor/http-client": "4.2.0-876",
|
|
52
52
|
"@elementor/icons": "~1.75.1",
|
|
53
|
-
"@elementor/locations": "4.2.0-
|
|
54
|
-
"@elementor/query": "4.2.0-
|
|
55
|
-
"@elementor/schema": "4.2.0-
|
|
56
|
-
"@elementor/session": "4.2.0-
|
|
53
|
+
"@elementor/locations": "4.2.0-876",
|
|
54
|
+
"@elementor/query": "4.2.0-876",
|
|
55
|
+
"@elementor/schema": "4.2.0-876",
|
|
56
|
+
"@elementor/session": "4.2.0-876",
|
|
57
57
|
"@elementor/ui": "1.37.5",
|
|
58
|
-
"@elementor/utils": "4.2.0-
|
|
59
|
-
"@elementor/wp-media": "4.2.0-
|
|
58
|
+
"@elementor/utils": "4.2.0-876",
|
|
59
|
+
"@elementor/wp-media": "4.2.0-876",
|
|
60
60
|
"@monaco-editor/react": "^4.7.0",
|
|
61
61
|
"@tiptap/extension-bold": "^3.11.1",
|
|
62
62
|
"@tiptap/extension-document": "^3.11.1",
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useMemo, useRef } from 'react';
|
|
3
|
+
import { useSelectedElementSettings } from '@elementor/editor-elements';
|
|
3
4
|
import {
|
|
4
5
|
type CreateOptions,
|
|
6
|
+
extractValue,
|
|
5
7
|
type PropKey,
|
|
6
8
|
queryFilterArrayPropTypeUtil,
|
|
7
9
|
type QueryFilterKeyConfig,
|
|
8
10
|
queryFilterPropTypeUtil,
|
|
9
11
|
type QueryFilterPropValue,
|
|
10
12
|
type QueryPropValue,
|
|
13
|
+
stringArrayPropTypeUtil,
|
|
11
14
|
stringPropTypeUtil,
|
|
12
15
|
} from '@elementor/editor-props';
|
|
13
16
|
import { PlusIcon } from '@elementor/icons';
|
|
@@ -24,6 +27,7 @@ import { PopoverContent } from '../components/popover-content';
|
|
|
24
27
|
import { PopoverGridContainer } from '../components/popover-grid-container';
|
|
25
28
|
import { RepeaterHeader } from '../components/repeater/repeater-header';
|
|
26
29
|
import { createControl } from '../create-control';
|
|
30
|
+
import { ChipsControl } from './chips-control';
|
|
27
31
|
import { QueryChipsControl } from './query-chips-control';
|
|
28
32
|
import { SelectControl, type SelectOption } from './select-control';
|
|
29
33
|
|
|
@@ -43,23 +47,30 @@ export const QueryFilterRepeaterControl = createControl(
|
|
|
43
47
|
}: QueryFilterRepeaterControlProps ) => {
|
|
44
48
|
const { propType, value, setValue } = useBoundProp( queryFilterArrayPropTypeUtil );
|
|
45
49
|
|
|
50
|
+
const { settings } = useSelectedElementSettings();
|
|
51
|
+
|
|
52
|
+
const visibleKeys = useMemo(
|
|
53
|
+
() => allowedKeys.filter( ( key ) => isKeyVisible( keyConfig[ key ]?.visibleWhen, settings ) ),
|
|
54
|
+
[ allowedKeys, keyConfig, settings ]
|
|
55
|
+
);
|
|
56
|
+
|
|
46
57
|
const usedKeys = useMemo( () => getUsedKeys( value ?? [] ), [ value ] );
|
|
47
58
|
const nextAvailableKey = useMemo(
|
|
48
|
-
() =>
|
|
49
|
-
[
|
|
59
|
+
() => visibleKeys.find( ( key ) => ! usedKeys.has( key ) ) ?? null,
|
|
60
|
+
[ visibleKeys, usedKeys ]
|
|
50
61
|
);
|
|
51
62
|
|
|
52
63
|
const getKeySelectOptions = useMemo(
|
|
53
64
|
() => ( currentKey: string | null ) =>
|
|
54
|
-
|
|
65
|
+
visibleKeys.map( ( itemKey ) => ( {
|
|
55
66
|
value: itemKey,
|
|
56
67
|
label: keyConfig[ itemKey ]?.label ?? itemKey,
|
|
57
68
|
disabled: itemKey !== currentKey && usedKeys.has( itemKey ),
|
|
58
69
|
} ) ),
|
|
59
|
-
[
|
|
70
|
+
[ visibleKeys, keyConfig, usedKeys ]
|
|
60
71
|
);
|
|
61
72
|
|
|
62
|
-
const initialFallback = useMemo( () => createItemForKey(
|
|
73
|
+
const initialFallback = useMemo( () => createItemForKey( visibleKeys[ 0 ] ?? '' ), [ visibleKeys ] );
|
|
63
74
|
|
|
64
75
|
return (
|
|
65
76
|
<PropProvider propType={ propType } value={ value } setValue={ setValue }>
|
|
@@ -133,7 +144,12 @@ const ItemLabel = ( { value, keyConfig }: ItemLabelProps ) => {
|
|
|
133
144
|
const itemKey = stringPropTypeUtil.extract( value?.value?.key );
|
|
134
145
|
const label = ( itemKey && keyConfig[ itemKey ]?.label ) || __( 'Item', 'elementor' );
|
|
135
146
|
const chipLabels = extractChipLabels( value?.value?.values );
|
|
136
|
-
const
|
|
147
|
+
const taxonomyLabels = extractTaxonomyLabels(
|
|
148
|
+
value?.value?.taxonomies,
|
|
149
|
+
itemKey ? keyConfig[ itemKey ] : undefined
|
|
150
|
+
);
|
|
151
|
+
const allLabels = [ ...chipLabels, ...taxonomyLabels ];
|
|
152
|
+
const suffix = allLabels.length > 0 ? `: ${ allLabels.join( ', ' ) }` : '';
|
|
137
153
|
|
|
138
154
|
return (
|
|
139
155
|
<Box component="span">
|
|
@@ -155,6 +171,11 @@ function extractChipLabels< T extends QueryArrayPropValue | undefined >( chipsPr
|
|
|
155
171
|
|
|
156
172
|
type FilterItemValue = NonNullable< QueryFilterPropValue[ 'value' ] >;
|
|
157
173
|
|
|
174
|
+
type SnapshotsByKey = Record<
|
|
175
|
+
string,
|
|
176
|
+
{ values?: FilterItemValue[ 'values' ] | null; taxonomies?: FilterItemValue[ 'taxonomies' ] | null }
|
|
177
|
+
>;
|
|
178
|
+
|
|
158
179
|
const ItemContent = ( {
|
|
159
180
|
keyConfig,
|
|
160
181
|
getKeySelectOptions,
|
|
@@ -166,7 +187,7 @@ const ItemContent = ( {
|
|
|
166
187
|
} ) => {
|
|
167
188
|
const propContext = useBoundProp( queryFilterPropTypeUtil );
|
|
168
189
|
|
|
169
|
-
const
|
|
190
|
+
const snapshotsByKeyRef = useRef< SnapshotsByKey >( {} );
|
|
170
191
|
|
|
171
192
|
const handleValueChange = ( nextValue: FilterItemValue, options?: CreateOptions, meta?: { bind?: PropKey } ) => {
|
|
172
193
|
if ( meta?.bind !== 'key' ) {
|
|
@@ -178,17 +199,28 @@ const ItemContent = ( {
|
|
|
178
199
|
const newKey = stringPropTypeUtil.extract( nextValue?.key );
|
|
179
200
|
|
|
180
201
|
if ( previousKey ) {
|
|
181
|
-
|
|
202
|
+
snapshotsByKeyRef.current[ previousKey ] = {
|
|
203
|
+
values: propContext.value?.values ?? null,
|
|
204
|
+
taxonomies: propContext.value?.taxonomies ?? null,
|
|
205
|
+
};
|
|
182
206
|
}
|
|
183
207
|
|
|
184
|
-
const
|
|
208
|
+
const restored = newKey ? snapshotsByKeyRef.current[ newKey ] : undefined;
|
|
185
209
|
|
|
186
|
-
propContext.setValue(
|
|
210
|
+
propContext.setValue(
|
|
211
|
+
{
|
|
212
|
+
...nextValue,
|
|
213
|
+
values: restored?.values ?? null,
|
|
214
|
+
taxonomies: restored?.taxonomies ?? null,
|
|
215
|
+
},
|
|
216
|
+
options,
|
|
217
|
+
meta
|
|
218
|
+
);
|
|
187
219
|
};
|
|
188
220
|
|
|
189
221
|
const currentKey = stringPropTypeUtil.extract( propContext.value?.key );
|
|
190
222
|
const currentKeyConfig = currentKey ? keyConfig[ currentKey ] : undefined;
|
|
191
|
-
const
|
|
223
|
+
const valueType = currentKeyConfig?.valueType ?? 'chips';
|
|
192
224
|
const keySelectOptions = useMemo( () => getKeySelectOptions( currentKey ), [ getKeySelectOptions, currentKey ] );
|
|
193
225
|
|
|
194
226
|
return (
|
|
@@ -204,7 +236,19 @@ const ItemContent = ( {
|
|
|
204
236
|
</PropKeyProvider>
|
|
205
237
|
</Grid>
|
|
206
238
|
</PopoverGridContainer>
|
|
207
|
-
{
|
|
239
|
+
{ valueType === 'taxonomies' && currentKeyConfig?.staticOptions && (
|
|
240
|
+
<PopoverGridContainer flexWrap="wrap">
|
|
241
|
+
<Grid item xs={ 12 }>
|
|
242
|
+
<ControlFormLabel>{ currentKeyConfig.label }</ControlFormLabel>
|
|
243
|
+
</Grid>
|
|
244
|
+
<Grid item xs={ 12 }>
|
|
245
|
+
<PropKeyProvider bind="taxonomies">
|
|
246
|
+
<ChipsControl options={ currentKeyConfig.staticOptions } />
|
|
247
|
+
</PropKeyProvider>
|
|
248
|
+
</Grid>
|
|
249
|
+
</PopoverGridContainer>
|
|
250
|
+
) }
|
|
251
|
+
{ valueType !== 'taxonomies' && currentKeyConfig?.queryEndpoint && (
|
|
208
252
|
<PopoverGridContainer flexWrap="wrap">
|
|
209
253
|
<Grid item xs={ 12 }>
|
|
210
254
|
<ControlFormLabel>{ currentKeyConfig.label }</ControlFormLabel>
|
|
@@ -227,10 +271,45 @@ const ItemContent = ( {
|
|
|
227
271
|
);
|
|
228
272
|
};
|
|
229
273
|
|
|
274
|
+
export function isKeyVisible(
|
|
275
|
+
rule: QueryFilterKeyConfig[ 'visibleWhen' ] | undefined,
|
|
276
|
+
settings: Record< string, unknown > | null
|
|
277
|
+
): boolean {
|
|
278
|
+
if ( ! rule ) {
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if ( ! settings ) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const extracted = stringPropTypeUtil.extract( extractValue( rule.path, settings ) );
|
|
287
|
+
|
|
288
|
+
return extracted !== null && rule.in.includes( extracted );
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function extractTaxonomyLabels(
|
|
292
|
+
taxonomiesProp: QueryFilterPropValue[ 'value' ][ 'taxonomies' ],
|
|
293
|
+
config: QueryFilterKeyConfig | undefined
|
|
294
|
+
): string[] {
|
|
295
|
+
const slugs = ( stringArrayPropTypeUtil.extract( taxonomiesProp ) ?? [] )
|
|
296
|
+
.map( ( item ) => stringPropTypeUtil.extract( item ) )
|
|
297
|
+
.filter( ( slug ): slug is string => !! slug );
|
|
298
|
+
|
|
299
|
+
if ( ! slugs.length ) {
|
|
300
|
+
return [];
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const options = config?.staticOptions ?? [];
|
|
304
|
+
|
|
305
|
+
return slugs.map( ( slug: string ) => options.find( ( opt ) => opt.value === slug )?.label ?? slug );
|
|
306
|
+
}
|
|
307
|
+
|
|
230
308
|
function createItemForKey( key: string ): QueryFilterPropValue {
|
|
231
309
|
return queryFilterPropTypeUtil.create( {
|
|
232
310
|
key: stringPropTypeUtil.create( key ),
|
|
233
311
|
values: null,
|
|
312
|
+
taxonomies: null,
|
|
234
313
|
} );
|
|
235
314
|
}
|
|
236
315
|
|