@react-querybuilder/antd 8.8.3 → 8.9.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/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/react-querybuilder_antd.cjs.development.d.ts +2770 -0
- package/dist/cjs/react-querybuilder_antd.cjs.development.js +520 -962
- package/dist/cjs/react-querybuilder_antd.cjs.development.js.map +1 -1
- package/dist/cjs/react-querybuilder_antd.cjs.production.d.ts +2770 -0
- package/dist/cjs/react-querybuilder_antd.cjs.production.js +1 -2
- package/dist/cjs/react-querybuilder_antd.cjs.production.js.map +1 -1
- package/dist/react-querybuilder_antd.d.mts +2770 -0
- package/dist/react-querybuilder_antd.legacy-esm.d.ts +2770 -0
- package/dist/react-querybuilder_antd.legacy-esm.js +655 -1010
- package/dist/react-querybuilder_antd.legacy-esm.js.map +1 -1
- package/dist/react-querybuilder_antd.mjs +496 -937
- package/dist/react-querybuilder_antd.mjs.map +1 -1
- package/dist/react-querybuilder_antd.production.d.mts +2770 -0
- package/dist/react-querybuilder_antd.production.mjs +1 -2
- package/dist/react-querybuilder_antd.production.mjs.map +1 -1
- package/package.json +14 -14
- package/dist/types/AntDActionElement.d.ts +0 -14
- package/dist/types/AntDDragHandle.d.ts +0 -14
- package/dist/types/AntDNotToggle.d.ts +0 -12
- package/dist/types/AntDShiftActions.d.ts +0 -6
- package/dist/types/AntDValueEditor.d.ts +0 -12
- package/dist/types/AntDValueSelector.d.ts +0 -12
- package/dist/types/dayjs.d.ts +0 -45
- package/dist/types/index.d.ts +0 -19
- package/dist/types-esm/AntDActionElement.d.mts +0 -14
- package/dist/types-esm/AntDDragHandle.d.mts +0 -14
- package/dist/types-esm/AntDNotToggle.d.mts +0 -12
- package/dist/types-esm/AntDShiftActions.d.mts +0 -6
- package/dist/types-esm/AntDValueEditor.d.mts +0 -12
- package/dist/types-esm/AntDValueSelector.d.mts +0 -12
- package/dist/types-esm/dayjs.d.mts +0 -45
- package/dist/types-esm/index.d.mts +0 -19
|
@@ -0,0 +1,2770 @@
|
|
|
1
|
+
import { HolderOutlined } from "@ant-design/icons";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { ComponentPropsWithRef, ComponentPropsWithoutRef, ComponentType, ForwardRefExoticComponent, MouseEvent, ReactNode, Ref, RefAttributes } from "react";
|
|
4
|
+
import { Button, Select, Switch } from "antd";
|
|
5
|
+
|
|
6
|
+
//#region ../core/src/types/type-fest/is-equal.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
Returns a boolean for whether the two given types are equal.
|
|
10
|
+
|
|
11
|
+
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
12
|
+
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
13
|
+
|
|
14
|
+
Use-cases:
|
|
15
|
+
- If you want to make a conditional branch based on the result of a comparison of two types.
|
|
16
|
+
|
|
17
|
+
@example
|
|
18
|
+
```
|
|
19
|
+
import type {IsEqual} from 'type-fest';
|
|
20
|
+
|
|
21
|
+
// This type returns a boolean for whether the given array includes the given item.
|
|
22
|
+
// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
|
|
23
|
+
type Includes<Value extends readonly any[], Item> =
|
|
24
|
+
Value extends readonly [Value[0], ...infer rest]
|
|
25
|
+
? IsEqual<Value[0], Item> extends true
|
|
26
|
+
? true
|
|
27
|
+
: Includes<rest, Item>
|
|
28
|
+
: false;
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
@group type-fest
|
|
32
|
+
*/
|
|
33
|
+
type IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region ../core/src/types/type-fest/is-never.d.ts
|
|
36
|
+
/**
|
|
37
|
+
Returns a boolean for whether the given type is `never`.
|
|
38
|
+
|
|
39
|
+
@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
|
|
40
|
+
@link https://stackoverflow.com/a/53984913/10292952
|
|
41
|
+
@link https://www.zhenghao.io/posts/ts-never
|
|
42
|
+
|
|
43
|
+
Useful in type utilities, such as checking if something does not occur.
|
|
44
|
+
|
|
45
|
+
@example
|
|
46
|
+
```
|
|
47
|
+
import type {IsNever, And} from 'type-fest';
|
|
48
|
+
|
|
49
|
+
// https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
|
|
50
|
+
type AreStringsEqual<A extends string, B extends string> =
|
|
51
|
+
And<
|
|
52
|
+
IsNever<Exclude<A, B>> extends true ? true : false,
|
|
53
|
+
IsNever<Exclude<B, A>> extends true ? true : false
|
|
54
|
+
>;
|
|
55
|
+
|
|
56
|
+
type EndIfEqual<I extends string, O extends string> =
|
|
57
|
+
AreStringsEqual<I, O> extends true
|
|
58
|
+
? never
|
|
59
|
+
: void;
|
|
60
|
+
|
|
61
|
+
function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
|
|
62
|
+
if (input === output) {
|
|
63
|
+
process.exit(0);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
endIfEqual('abc', 'abc');
|
|
68
|
+
//=> never
|
|
69
|
+
|
|
70
|
+
endIfEqual('abc', '123');
|
|
71
|
+
//=> void
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
@group type-fest
|
|
75
|
+
*/
|
|
76
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region ../core/src/types/type-fest/if-never.d.ts
|
|
79
|
+
/**
|
|
80
|
+
An if-else-like type that resolves depending on whether the given type is `never`.
|
|
81
|
+
|
|
82
|
+
@see {@link IsNever}
|
|
83
|
+
|
|
84
|
+
@example
|
|
85
|
+
```
|
|
86
|
+
import type {IfNever} from 'type-fest';
|
|
87
|
+
|
|
88
|
+
type ShouldBeTrue = IfNever<never>;
|
|
89
|
+
//=> true
|
|
90
|
+
|
|
91
|
+
type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
|
|
92
|
+
//=> 'bar'
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
@group type-fest
|
|
96
|
+
*/
|
|
97
|
+
type IfNever$1<T, TypeIfNever = true, TypeIfNotNever = false> = (IsNever<T> extends true ? TypeIfNever : TypeIfNotNever);
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region ../core/src/types/type-fest/unknown-array.d.ts
|
|
100
|
+
/**
|
|
101
|
+
Represents an array with `unknown` value.
|
|
102
|
+
|
|
103
|
+
Use case: You want a type that all arrays can be assigned to, but you don't care about the value.
|
|
104
|
+
|
|
105
|
+
@example
|
|
106
|
+
```
|
|
107
|
+
import type {UnknownArray} from 'type-fest';
|
|
108
|
+
|
|
109
|
+
type IsArray<T> = T extends UnknownArray ? true : false;
|
|
110
|
+
|
|
111
|
+
type A = IsArray<['foo']>;
|
|
112
|
+
//=> true
|
|
113
|
+
|
|
114
|
+
type B = IsArray<readonly number[]>;
|
|
115
|
+
//=> true
|
|
116
|
+
|
|
117
|
+
type C = IsArray<string>;
|
|
118
|
+
//=> false
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
@group type-fest
|
|
122
|
+
*/
|
|
123
|
+
type UnknownArray = readonly unknown[];
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region ../core/src/types/type-fest/internal/array.d.ts
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
Returns whether the given array `T` is readonly.
|
|
129
|
+
|
|
130
|
+
@group type-fest
|
|
131
|
+
*/
|
|
132
|
+
type IsArrayReadonly<T extends UnknownArray> = IfNever$1<T, false, T extends unknown[] ? false : true>;
|
|
133
|
+
/**
|
|
134
|
+
An if-else-like type that resolves depending on whether the given array is readonly.
|
|
135
|
+
|
|
136
|
+
@see {@link IsArrayReadonly}
|
|
137
|
+
|
|
138
|
+
@example
|
|
139
|
+
```
|
|
140
|
+
import type {ArrayTail} from 'type-fest';
|
|
141
|
+
|
|
142
|
+
type ReadonlyPreservingArrayTail<TArray extends readonly unknown[]> =
|
|
143
|
+
ArrayTail<TArray> extends infer Tail
|
|
144
|
+
? IfArrayReadonly<TArray, Readonly<Tail>, Tail>
|
|
145
|
+
: never;
|
|
146
|
+
|
|
147
|
+
type ReadonlyTail = ReadonlyPreservingArrayTail<readonly [string, number, boolean]>;
|
|
148
|
+
//=> readonly [number, boolean]
|
|
149
|
+
|
|
150
|
+
type NonReadonlyTail = ReadonlyPreservingArrayTail<[string, number, boolean]>;
|
|
151
|
+
//=> [number, boolean]
|
|
152
|
+
|
|
153
|
+
type ShouldBeTrue = IfArrayReadonly<readonly unknown[]>;
|
|
154
|
+
//=> true
|
|
155
|
+
|
|
156
|
+
type ShouldBeBar = IfArrayReadonly<unknown[], 'foo', 'bar'>;
|
|
157
|
+
//=> 'bar'
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
@group type-fest
|
|
161
|
+
*/
|
|
162
|
+
type IfArrayReadonly<T extends UnknownArray, TypeIfArrayReadonly = true, TypeIfNotArrayReadonly = false> = IsArrayReadonly<T> extends infer Result ? Result extends true ? TypeIfArrayReadonly : TypeIfNotArrayReadonly : never;
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region ../core/src/types/type-fest/is-any.d.ts
|
|
165
|
+
type NoInfer<T> = T extends infer U ? U : never;
|
|
166
|
+
/**
|
|
167
|
+
Returns a boolean for whether the given type is `any`.
|
|
168
|
+
|
|
169
|
+
@link https://stackoverflow.com/a/49928360/1490091
|
|
170
|
+
|
|
171
|
+
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
172
|
+
|
|
173
|
+
@example
|
|
174
|
+
```
|
|
175
|
+
import type {IsAny} from 'type-fest';
|
|
176
|
+
|
|
177
|
+
const typedObject = {a: 1, b: 2} as const;
|
|
178
|
+
const anyObject: any = {a: 1, b: 2};
|
|
179
|
+
|
|
180
|
+
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
|
|
181
|
+
return obj[key];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const typedA = get(typedObject, 'a');
|
|
185
|
+
//=> 1
|
|
186
|
+
|
|
187
|
+
const anyA = get(anyObject, 'a');
|
|
188
|
+
//=> any
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
@group type-fest
|
|
192
|
+
*/
|
|
193
|
+
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region ../core/src/types/type-fest/simplify.d.ts
|
|
196
|
+
/**
|
|
197
|
+
Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
198
|
+
|
|
199
|
+
@example
|
|
200
|
+
```
|
|
201
|
+
import type {Simplify} from 'type-fest';
|
|
202
|
+
|
|
203
|
+
type PositionProps = {
|
|
204
|
+
top: number;
|
|
205
|
+
left: number;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
type SizeProps = {
|
|
209
|
+
width: number;
|
|
210
|
+
height: number;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
214
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
218
|
+
|
|
219
|
+
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
220
|
+
|
|
221
|
+
@example
|
|
222
|
+
```
|
|
223
|
+
import type {Simplify} from 'type-fest';
|
|
224
|
+
|
|
225
|
+
interface SomeInterface {
|
|
226
|
+
foo: number;
|
|
227
|
+
bar?: string;
|
|
228
|
+
baz: number | undefined;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
type SomeType = {
|
|
232
|
+
foo: number;
|
|
233
|
+
bar?: string;
|
|
234
|
+
baz: number | undefined;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
238
|
+
const someType: SomeType = literal;
|
|
239
|
+
const someInterface: SomeInterface = literal;
|
|
240
|
+
|
|
241
|
+
function fn(object: Record<string, unknown>): void {}
|
|
242
|
+
|
|
243
|
+
fn(literal); // Good: literal object type is sealed
|
|
244
|
+
fn(someType); // Good: type is sealed
|
|
245
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
246
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
250
|
+
@see SimplifyDeep
|
|
251
|
+
|
|
252
|
+
@group type-fest
|
|
253
|
+
*/
|
|
254
|
+
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region ../core/src/types/type-fest/union-to-intersection.d.ts
|
|
257
|
+
/**
|
|
258
|
+
Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
259
|
+
|
|
260
|
+
Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
|
|
261
|
+
|
|
262
|
+
@example
|
|
263
|
+
```
|
|
264
|
+
import type {UnionToIntersection} from 'type-fest';
|
|
265
|
+
|
|
266
|
+
type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
|
|
267
|
+
|
|
268
|
+
type Intersection = UnionToIntersection<Union>;
|
|
269
|
+
//=> {the(): void; great(arg: string): void; escape: boolean};
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
A more applicable example which could make its way into your library code follows.
|
|
273
|
+
|
|
274
|
+
@example
|
|
275
|
+
```
|
|
276
|
+
import type {UnionToIntersection} from 'type-fest';
|
|
277
|
+
|
|
278
|
+
class CommandOne {
|
|
279
|
+
commands: {
|
|
280
|
+
a1: () => undefined,
|
|
281
|
+
b1: () => undefined,
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
class CommandTwo {
|
|
286
|
+
commands: {
|
|
287
|
+
a2: (argA: string) => undefined,
|
|
288
|
+
b2: (argB: string) => undefined,
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
|
|
293
|
+
type Union = typeof union;
|
|
294
|
+
//=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
|
|
295
|
+
|
|
296
|
+
type Intersection = UnionToIntersection<Union>;
|
|
297
|
+
//=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
@group type-fest
|
|
301
|
+
*/
|
|
302
|
+
type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection & Union : never;
|
|
303
|
+
//#endregion
|
|
304
|
+
//#region ../core/src/types/type-fest/keys-of-union.d.ts
|
|
305
|
+
/**
|
|
306
|
+
Create a union of all keys from a given type, even those exclusive to specific union members.
|
|
307
|
+
|
|
308
|
+
Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
|
|
309
|
+
|
|
310
|
+
@link https://stackoverflow.com/a/49402091
|
|
311
|
+
|
|
312
|
+
@example
|
|
313
|
+
```
|
|
314
|
+
import type {KeysOfUnion} from 'type-fest';
|
|
315
|
+
|
|
316
|
+
type A = {
|
|
317
|
+
common: string;
|
|
318
|
+
a: number;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
type B = {
|
|
322
|
+
common: string;
|
|
323
|
+
b: string;
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
type C = {
|
|
327
|
+
common: string;
|
|
328
|
+
c: boolean;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
type Union = A | B | C;
|
|
332
|
+
|
|
333
|
+
type CommonKeys = keyof Union;
|
|
334
|
+
//=> 'common'
|
|
335
|
+
|
|
336
|
+
type AllKeys = KeysOfUnion<Union>;
|
|
337
|
+
//=> 'common' | 'a' | 'b' | 'c'
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
@group type-fest
|
|
341
|
+
*/
|
|
342
|
+
type KeysOfUnion<ObjectType> = keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
|
|
343
|
+
//#endregion
|
|
344
|
+
//#region ../core/src/types/type-fest/optional-keys-of.d.ts
|
|
345
|
+
/**
|
|
346
|
+
Extract all optional keys from the given type.
|
|
347
|
+
|
|
348
|
+
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
349
|
+
|
|
350
|
+
@example
|
|
351
|
+
```
|
|
352
|
+
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
353
|
+
|
|
354
|
+
interface User {
|
|
355
|
+
name: string;
|
|
356
|
+
surname: string;
|
|
357
|
+
|
|
358
|
+
luckyNumber?: number;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
362
|
+
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
363
|
+
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
const update1: UpdateOperation<User> = {
|
|
367
|
+
name: 'Alice'
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
const update2: UpdateOperation<User> = {
|
|
371
|
+
name: 'Bob',
|
|
372
|
+
luckyNumber: REMOVE_FIELD
|
|
373
|
+
};
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
@group type-fest
|
|
377
|
+
*/
|
|
378
|
+
type OptionalKeysOf<BaseType extends object> = BaseType extends unknown ? (keyof { [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never }) & (keyof BaseType) : never;
|
|
379
|
+
//#endregion
|
|
380
|
+
//#region ../core/src/types/type-fest/required-keys-of.d.ts
|
|
381
|
+
/**
|
|
382
|
+
Extract all required keys from the given type.
|
|
383
|
+
|
|
384
|
+
This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
|
|
385
|
+
|
|
386
|
+
@example
|
|
387
|
+
```
|
|
388
|
+
import type {RequiredKeysOf} from 'type-fest';
|
|
389
|
+
|
|
390
|
+
declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
|
|
391
|
+
|
|
392
|
+
interface User {
|
|
393
|
+
name: string;
|
|
394
|
+
surname: string;
|
|
395
|
+
|
|
396
|
+
luckyNumber?: number;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
400
|
+
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
@group type-fest
|
|
404
|
+
*/
|
|
405
|
+
type RequiredKeysOf<BaseType extends object> = BaseType extends unknown ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>> : never;
|
|
406
|
+
//#endregion
|
|
407
|
+
//#region ../core/src/types/type-fest/omit-index-signature.d.ts
|
|
408
|
+
/**
|
|
409
|
+
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
410
|
+
|
|
411
|
+
This is the counterpart of `PickIndexSignature`.
|
|
412
|
+
|
|
413
|
+
Use-cases:
|
|
414
|
+
- Remove overly permissive signatures from third-party types.
|
|
415
|
+
|
|
416
|
+
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
417
|
+
|
|
418
|
+
It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
|
|
419
|
+
|
|
420
|
+
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
421
|
+
|
|
422
|
+
```
|
|
423
|
+
const indexed: Record<string, unknown> = {}; // Allowed
|
|
424
|
+
|
|
425
|
+
const keyed: Record<'foo', unknown> = {}; // Error
|
|
426
|
+
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
|
|
430
|
+
|
|
431
|
+
```
|
|
432
|
+
type Indexed = {} extends Record<string, unknown>
|
|
433
|
+
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
434
|
+
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
435
|
+
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
436
|
+
|
|
437
|
+
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
438
|
+
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
|
439
|
+
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
|
440
|
+
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
|
|
444
|
+
|
|
445
|
+
```
|
|
446
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
447
|
+
|
|
448
|
+
type OmitIndexSignature<ObjectType> = {
|
|
449
|
+
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
450
|
+
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
451
|
+
};
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
455
|
+
|
|
456
|
+
```
|
|
457
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
458
|
+
|
|
459
|
+
type OmitIndexSignature<ObjectType> = {
|
|
460
|
+
[KeyType in keyof ObjectType
|
|
461
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
462
|
+
as {} extends Record<KeyType, unknown>
|
|
463
|
+
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
464
|
+
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
465
|
+
]: ObjectType[KeyType];
|
|
466
|
+
};
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
|
|
470
|
+
|
|
471
|
+
@example
|
|
472
|
+
```
|
|
473
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
474
|
+
|
|
475
|
+
interface Example {
|
|
476
|
+
// These index signatures will be removed.
|
|
477
|
+
[x: string]: any
|
|
478
|
+
[x: number]: any
|
|
479
|
+
[x: symbol]: any
|
|
480
|
+
[x: `head-${string}`]: string
|
|
481
|
+
[x: `${string}-tail`]: string
|
|
482
|
+
[x: `head-${string}-tail`]: string
|
|
483
|
+
[x: `${bigint}`]: string
|
|
484
|
+
[x: `embedded-${number}`]: string
|
|
485
|
+
|
|
486
|
+
// These explicitly defined keys will remain.
|
|
487
|
+
foo: 'bar';
|
|
488
|
+
qux?: 'baz';
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
492
|
+
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
@see PickIndexSignature
|
|
496
|
+
|
|
497
|
+
@group type-fest
|
|
498
|
+
*/
|
|
499
|
+
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
500
|
+
//#endregion
|
|
501
|
+
//#region ../core/src/types/type-fest/pick-index-signature.d.ts
|
|
502
|
+
/**
|
|
503
|
+
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
504
|
+
|
|
505
|
+
This is the counterpart of `OmitIndexSignature`.
|
|
506
|
+
|
|
507
|
+
@example
|
|
508
|
+
```
|
|
509
|
+
import type {PickIndexSignature} from 'type-fest';
|
|
510
|
+
|
|
511
|
+
declare const symbolKey: unique symbol;
|
|
512
|
+
|
|
513
|
+
type Example = {
|
|
514
|
+
// These index signatures will remain.
|
|
515
|
+
[x: string]: unknown;
|
|
516
|
+
[x: number]: unknown;
|
|
517
|
+
[x: symbol]: unknown;
|
|
518
|
+
[x: `head-${string}`]: string;
|
|
519
|
+
[x: `${string}-tail`]: string;
|
|
520
|
+
[x: `head-${string}-tail`]: string;
|
|
521
|
+
[x: `${bigint}`]: string;
|
|
522
|
+
[x: `embedded-${number}`]: string;
|
|
523
|
+
|
|
524
|
+
// These explicitly defined keys will be removed.
|
|
525
|
+
['kebab-case-key']: string;
|
|
526
|
+
[symbolKey]: string;
|
|
527
|
+
foo: 'bar';
|
|
528
|
+
qux?: 'baz';
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
532
|
+
// {
|
|
533
|
+
// [x: string]: unknown;
|
|
534
|
+
// [x: number]: unknown;
|
|
535
|
+
// [x: symbol]: unknown;
|
|
536
|
+
// [x: `head-${string}`]: string;
|
|
537
|
+
// [x: `${string}-tail`]: string;
|
|
538
|
+
// [x: `head-${string}-tail`]: string;
|
|
539
|
+
// [x: `${bigint}`]: string;
|
|
540
|
+
// [x: `embedded-${number}`]: string;
|
|
541
|
+
// }
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
@see OmitIndexSignature
|
|
545
|
+
|
|
546
|
+
@group type-fest
|
|
547
|
+
*/
|
|
548
|
+
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
549
|
+
//#endregion
|
|
550
|
+
//#region ../core/src/types/type-fest/merge.d.ts
|
|
551
|
+
type SimpleMerge<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source;
|
|
552
|
+
/**
|
|
553
|
+
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
554
|
+
|
|
555
|
+
@example
|
|
556
|
+
```
|
|
557
|
+
import type {Merge} from 'type-fest';
|
|
558
|
+
|
|
559
|
+
interface Foo {
|
|
560
|
+
[x: string]: unknown;
|
|
561
|
+
[x: number]: unknown;
|
|
562
|
+
foo: string;
|
|
563
|
+
bar: symbol;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
type Bar = {
|
|
567
|
+
[x: number]: number;
|
|
568
|
+
[x: symbol]: unknown;
|
|
569
|
+
bar: Date;
|
|
570
|
+
baz: boolean;
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
export type FooBar = Merge<Foo, Bar>;
|
|
574
|
+
// => {
|
|
575
|
+
// [x: string]: unknown;
|
|
576
|
+
// [x: number]: number;
|
|
577
|
+
// [x: symbol]: unknown;
|
|
578
|
+
// foo: string;
|
|
579
|
+
// bar: Date;
|
|
580
|
+
// baz: boolean;
|
|
581
|
+
// }
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
@group type-fest
|
|
585
|
+
*/
|
|
586
|
+
type Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
587
|
+
//#endregion
|
|
588
|
+
//#region ../core/src/types/type-fest/if-any.d.ts
|
|
589
|
+
/**
|
|
590
|
+
An if-else-like type that resolves depending on whether the given type is `any`.
|
|
591
|
+
|
|
592
|
+
@see {@link IsAny}
|
|
593
|
+
|
|
594
|
+
@example
|
|
595
|
+
```
|
|
596
|
+
import type {IfAny} from 'type-fest';
|
|
597
|
+
|
|
598
|
+
type ShouldBeTrue = IfAny<any>;
|
|
599
|
+
//=> true
|
|
600
|
+
|
|
601
|
+
type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
|
|
602
|
+
//=> 'bar'
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
@group type-fest
|
|
606
|
+
*/
|
|
607
|
+
type IfAny$1<T, TypeIfAny = true, TypeIfNotAny = false> = (IsAny<T> extends true ? TypeIfAny : TypeIfNotAny);
|
|
608
|
+
//#endregion
|
|
609
|
+
//#region ../core/src/types/type-fest/internal/type.d.ts
|
|
610
|
+
/**
|
|
611
|
+
An if-else-like type that resolves depending on whether the given type is `any` or `never`.
|
|
612
|
+
|
|
613
|
+
@example
|
|
614
|
+
```
|
|
615
|
+
// When `T` is a NOT `any` or `never` (like `string`) => Returns `IfNotAnyOrNever` branch
|
|
616
|
+
type A = IfNotAnyOrNever<string, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
617
|
+
//=> 'VALID'
|
|
618
|
+
|
|
619
|
+
// When `T` is `any` => Returns `IfAny` branch
|
|
620
|
+
type B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
621
|
+
//=> 'IS_ANY'
|
|
622
|
+
|
|
623
|
+
// When `T` is `never` => Returns `IfNever` branch
|
|
624
|
+
type C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
625
|
+
//=> 'IS_NEVER'
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
@group type-fest
|
|
629
|
+
*/
|
|
630
|
+
type IfNotAnyOrNever<T, IfNotAnyOrNever, IfAny = any, IfNever = never> = IsAny<T> extends true ? IfAny : IsNever<T> extends true ? IfNever : IfNotAnyOrNever;
|
|
631
|
+
//#endregion
|
|
632
|
+
//#region ../core/src/types/type-fest/internal/object.d.ts
|
|
633
|
+
/**
|
|
634
|
+
Works similar to the built-in `Pick` utility type, except for the following differences:
|
|
635
|
+
- Distributes over union types and allows picking keys from any member of the union type.
|
|
636
|
+
- Primitives types are returned as-is.
|
|
637
|
+
- Picks all keys if `Keys` is `any`.
|
|
638
|
+
- Doesn't pick `number` from a `string` index signature.
|
|
639
|
+
|
|
640
|
+
@example
|
|
641
|
+
```
|
|
642
|
+
type ImageUpload = {
|
|
643
|
+
url: string;
|
|
644
|
+
size: number;
|
|
645
|
+
thumbnailUrl: string;
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
type VideoUpload = {
|
|
649
|
+
url: string;
|
|
650
|
+
duration: number;
|
|
651
|
+
encodingFormat: string;
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
// Distributes over union types and allows picking keys from any member of the union type
|
|
655
|
+
type MediaDisplay = HomomorphicPick<ImageUpload | VideoUpload, "url" | "size" | "duration">;
|
|
656
|
+
//=> {url: string; size: number} | {url: string; duration: number}
|
|
657
|
+
|
|
658
|
+
// Primitive types are returned as-is
|
|
659
|
+
type Primitive = HomomorphicPick<string | number, 'toUpperCase' | 'toString'>;
|
|
660
|
+
//=> string | number
|
|
661
|
+
|
|
662
|
+
// Picks all keys if `Keys` is `any`
|
|
663
|
+
type Any = HomomorphicPick<{a: 1; b: 2} | {c: 3}, any>;
|
|
664
|
+
//=> {a: 1; b: 2} | {c: 3}
|
|
665
|
+
|
|
666
|
+
// Doesn't pick `number` from a `string` index signature
|
|
667
|
+
type IndexSignature = HomomorphicPick<{[k: string]: unknown}, number>;
|
|
668
|
+
//=> {}
|
|
669
|
+
|
|
670
|
+
@group type-fest
|
|
671
|
+
*/
|
|
672
|
+
type HomomorphicPick<T, Keys extends KeysOfUnion<T>> = { [P in keyof T as Extract<P, Keys>]: T[P] };
|
|
673
|
+
/**
|
|
674
|
+
Merges user specified options with default options.
|
|
675
|
+
|
|
676
|
+
@example
|
|
677
|
+
```
|
|
678
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
679
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
680
|
+
type SpecifiedOptions = {leavesOnly: true};
|
|
681
|
+
|
|
682
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
683
|
+
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
@example
|
|
687
|
+
```
|
|
688
|
+
// Complains if default values are not provided for optional options
|
|
689
|
+
|
|
690
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
691
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
692
|
+
type SpecifiedOptions = {};
|
|
693
|
+
|
|
694
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
695
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
696
|
+
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
@example
|
|
700
|
+
```
|
|
701
|
+
// Complains if an option's default type does not conform to the expected type
|
|
702
|
+
|
|
703
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
704
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
705
|
+
type SpecifiedOptions = {};
|
|
706
|
+
|
|
707
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
708
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
709
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
710
|
+
```
|
|
711
|
+
|
|
712
|
+
@example
|
|
713
|
+
```
|
|
714
|
+
// Complains if an option's specified type does not conform to the expected type
|
|
715
|
+
|
|
716
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
717
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
718
|
+
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
719
|
+
|
|
720
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
721
|
+
// ~~~~~~~~~~~~~~~~
|
|
722
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
723
|
+
```
|
|
724
|
+
|
|
725
|
+
@group type-fest
|
|
726
|
+
*/
|
|
727
|
+
type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = IfAny$1<SpecifiedOptions, Defaults, IfNever$1<SpecifiedOptions, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? Extract<SpecifiedOptions[Key], undefined> extends never ? Key : never : Key]: SpecifiedOptions[Key] }> & Required<Options>>>>;
|
|
728
|
+
//#endregion
|
|
729
|
+
//#region ../core/src/types/type-fest/except.d.ts
|
|
730
|
+
/**
|
|
731
|
+
Filter out keys from an object.
|
|
732
|
+
|
|
733
|
+
Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
734
|
+
Returns `never` if `Key` extends `Exclude`.
|
|
735
|
+
Returns `Key` otherwise.
|
|
736
|
+
|
|
737
|
+
@example
|
|
738
|
+
```
|
|
739
|
+
type Filtered = Filter<'foo', 'foo'>;
|
|
740
|
+
//=> never
|
|
741
|
+
```
|
|
742
|
+
|
|
743
|
+
@example
|
|
744
|
+
```
|
|
745
|
+
type Filtered = Filter<'bar', string>;
|
|
746
|
+
//=> never
|
|
747
|
+
```
|
|
748
|
+
|
|
749
|
+
@example
|
|
750
|
+
```
|
|
751
|
+
type Filtered = Filter<'bar', 'foo'>;
|
|
752
|
+
//=> 'bar'
|
|
753
|
+
```
|
|
754
|
+
|
|
755
|
+
@see {Except}
|
|
756
|
+
*/
|
|
757
|
+
type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
|
|
758
|
+
type ExceptOptions = {
|
|
759
|
+
/**
|
|
760
|
+
Disallow assigning non-specified properties.
|
|
761
|
+
|
|
762
|
+
Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
|
|
763
|
+
|
|
764
|
+
@default false
|
|
765
|
+
*/
|
|
766
|
+
requireExactProps?: boolean;
|
|
767
|
+
};
|
|
768
|
+
type DefaultExceptOptions = {
|
|
769
|
+
requireExactProps: false;
|
|
770
|
+
};
|
|
771
|
+
/**
|
|
772
|
+
Create a type from an object type without certain keys.
|
|
773
|
+
|
|
774
|
+
We recommend setting the `requireExactProps` option to `true`.
|
|
775
|
+
|
|
776
|
+
This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
|
|
777
|
+
|
|
778
|
+
This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
|
|
779
|
+
|
|
780
|
+
@example
|
|
781
|
+
```
|
|
782
|
+
import type {Except} from 'type-fest';
|
|
783
|
+
|
|
784
|
+
type Foo = {
|
|
785
|
+
a: number;
|
|
786
|
+
b: string;
|
|
787
|
+
};
|
|
788
|
+
|
|
789
|
+
type FooWithoutA = Except<Foo, 'a'>;
|
|
790
|
+
//=> {b: string}
|
|
791
|
+
|
|
792
|
+
const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
|
|
793
|
+
//=> errors: 'a' does not exist in type '{ b: string; }'
|
|
794
|
+
|
|
795
|
+
type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
796
|
+
//=> {a: number} & Partial<Record<"b", never>>
|
|
797
|
+
|
|
798
|
+
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
799
|
+
//=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
|
|
800
|
+
|
|
801
|
+
// The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.
|
|
802
|
+
|
|
803
|
+
// Consider the following example:
|
|
804
|
+
|
|
805
|
+
type UserData = {
|
|
806
|
+
[metadata: string]: string;
|
|
807
|
+
email: string;
|
|
808
|
+
name: string;
|
|
809
|
+
role: 'admin' | 'user';
|
|
810
|
+
};
|
|
811
|
+
|
|
812
|
+
// `Omit` clearly doesn't behave as expected in this case:
|
|
813
|
+
type PostPayload = Omit<UserData, 'email'>;
|
|
814
|
+
//=> type PostPayload = { [x: string]: string; [x: number]: string; }
|
|
815
|
+
|
|
816
|
+
// In situations like this, `Except` works better.
|
|
817
|
+
// It simply removes the `email` key while preserving all the other keys.
|
|
818
|
+
type PostPayload = Except<UserData, 'email'>;
|
|
819
|
+
//=> type PostPayload = { [x: string]: string; name: string; role: 'admin' | 'user'; }
|
|
820
|
+
```
|
|
821
|
+
|
|
822
|
+
@group type-fest
|
|
823
|
+
*/
|
|
824
|
+
type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
|
|
825
|
+
type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = { [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType] } & (Options["requireExactProps"] extends true ? Partial<Record<KeysType, never>> : {});
|
|
826
|
+
//#endregion
|
|
827
|
+
//#region ../core/src/types/type-fest/require-at-least-one.d.ts
|
|
828
|
+
/**
|
|
829
|
+
Create a type that requires at least one of the given keys. The remaining keys are kept as is.
|
|
830
|
+
|
|
831
|
+
@example
|
|
832
|
+
```
|
|
833
|
+
import type {RequireAtLeastOne} from 'type-fest';
|
|
834
|
+
|
|
835
|
+
type Responder = {
|
|
836
|
+
text?: () => string;
|
|
837
|
+
json?: () => string;
|
|
838
|
+
secure?: boolean;
|
|
839
|
+
};
|
|
840
|
+
|
|
841
|
+
const responder: RequireAtLeastOne<Responder, 'text' | 'json'> = {
|
|
842
|
+
json: () => '{"message": "ok"}',
|
|
843
|
+
secure: true
|
|
844
|
+
};
|
|
845
|
+
```
|
|
846
|
+
|
|
847
|
+
@group type-fest
|
|
848
|
+
*/
|
|
849
|
+
type RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = IfNotAnyOrNever<ObjectType, IfNever$1<KeysType, never, _RequireAtLeastOne<ObjectType, IfAny$1<KeysType, keyof ObjectType, KeysType>>>>;
|
|
850
|
+
type _RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType> = { [Key in KeysType]-?: Required<Pick<ObjectType, Key>> & Partial<Pick<ObjectType, Exclude<KeysType, Key>>> }[KeysType] & Except<ObjectType, KeysType>;
|
|
851
|
+
//#endregion
|
|
852
|
+
//#region ../core/src/types/type-fest/set-non-nullable.d.ts
|
|
853
|
+
/**
|
|
854
|
+
Create a type that makes the given keys non-nullable, where the remaining keys are kept as is.
|
|
855
|
+
|
|
856
|
+
If no keys are given, all keys will be made non-nullable.
|
|
857
|
+
|
|
858
|
+
Use-case: You want to define a single model where the only thing that changes is whether or not some or all of the keys are non-nullable.
|
|
859
|
+
|
|
860
|
+
@example
|
|
861
|
+
```
|
|
862
|
+
import type {SetNonNullable} from 'type-fest';
|
|
863
|
+
|
|
864
|
+
type Foo = {
|
|
865
|
+
a: number | null;
|
|
866
|
+
b: string | undefined;
|
|
867
|
+
c?: boolean | null;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
type SomeNonNullable = SetNonNullable<Foo, 'b' | 'c'>;
|
|
871
|
+
// type SomeNonNullable = {
|
|
872
|
+
// a: number | null;
|
|
873
|
+
// b: string; // Can no longer be undefined.
|
|
874
|
+
// c?: boolean; // Can no longer be null, but is still optional.
|
|
875
|
+
// }
|
|
876
|
+
|
|
877
|
+
type AllNonNullable = SetNonNullable<Foo>;
|
|
878
|
+
// type AllNonNullable = {
|
|
879
|
+
// a: number; // Can no longer be null.
|
|
880
|
+
// b: string; // Can no longer be undefined.
|
|
881
|
+
// c?: boolean; // Can no longer be null, but is still optional.
|
|
882
|
+
// }
|
|
883
|
+
```
|
|
884
|
+
|
|
885
|
+
@group type-fest
|
|
886
|
+
*/
|
|
887
|
+
type SetNonNullable<BaseType, Keys extends keyof BaseType = keyof BaseType> = { [Key in keyof BaseType]: Key extends Keys ? NonNullable<BaseType[Key]> : BaseType[Key] };
|
|
888
|
+
//#endregion
|
|
889
|
+
//#region ../core/src/types/type-fest/set-required.d.ts
|
|
890
|
+
/**
|
|
891
|
+
Create a type that makes the given keys required. The remaining keys are kept as is. The sister of the `SetOptional` type.
|
|
892
|
+
|
|
893
|
+
Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are required.
|
|
894
|
+
|
|
895
|
+
@example
|
|
896
|
+
```
|
|
897
|
+
import type {SetRequired} from 'type-fest';
|
|
898
|
+
|
|
899
|
+
type Foo = {
|
|
900
|
+
a?: number;
|
|
901
|
+
b: string;
|
|
902
|
+
c?: boolean;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
type SomeRequired = SetRequired<Foo, 'b' | 'c'>;
|
|
906
|
+
// type SomeRequired = {
|
|
907
|
+
// a?: number;
|
|
908
|
+
// b: string; // Was already required and still is.
|
|
909
|
+
// c: boolean; // Is now required.
|
|
910
|
+
// }
|
|
911
|
+
|
|
912
|
+
// Set specific indices in an array to be required.
|
|
913
|
+
type ArrayExample = SetRequired<[number?, number?, number?], 0 | 1>;
|
|
914
|
+
//=> [number, number, number?]
|
|
915
|
+
```
|
|
916
|
+
|
|
917
|
+
@group type-fest
|
|
918
|
+
*/
|
|
919
|
+
type SetRequired<BaseType, Keys extends keyof BaseType> = BaseType extends UnknownArray ? SetArrayRequired<BaseType, Keys> extends infer ResultantArray ? IfArrayReadonly<BaseType, Readonly<ResultantArray>, ResultantArray> : never : Simplify<Except<BaseType, Keys> & Required<HomomorphicPick<BaseType, Keys>>>;
|
|
920
|
+
/**
|
|
921
|
+
Remove the optional modifier from the specified keys in an array.
|
|
922
|
+
*/
|
|
923
|
+
type SetArrayRequired<TArray extends UnknownArray, Keys, Counter extends any[] = [], Accumulator extends UnknownArray = []> = TArray extends unknown ? keyof TArray & `${number}` extends never ? [...Accumulator, ...TArray] : TArray extends readonly [(infer First)?, ...infer Rest] ? "0" extends OptionalKeysOf<TArray> ? `${Counter["length"]}` extends `${Keys & (string | number)}` ? SetArrayRequired<Rest, Keys, [...Counter, any], [...Accumulator, First]> : [...Accumulator, ...TArray] : SetArrayRequired<Rest, Keys, [...Counter, any], [...Accumulator, TArray[0]]> : never : never;
|
|
924
|
+
//#endregion
|
|
925
|
+
//#region ../core/src/types/options.d.ts
|
|
926
|
+
type StringUnionToFullOptionArray<Op extends string> = Array<Op extends unknown ? FullOption<Op> : never>;
|
|
927
|
+
/**
|
|
928
|
+
* Extracts the type of the identifying property from a {@link Option},
|
|
929
|
+
* {@link ValueOption}, or {@link FullOption}.
|
|
930
|
+
*
|
|
931
|
+
* @group Option Lists
|
|
932
|
+
*/
|
|
933
|
+
type GetOptionIdentifierType<Opt extends BaseOption> = Opt extends Option<infer NameType> | ValueOption<infer NameType> ? NameType : string;
|
|
934
|
+
/**
|
|
935
|
+
* Adds an `unknown` index property to an interface.
|
|
936
|
+
*/
|
|
937
|
+
type WithUnknownIndex<T> = T & {
|
|
938
|
+
[key: string]: unknown;
|
|
939
|
+
};
|
|
940
|
+
/**
|
|
941
|
+
* Do not use this type directly; use {@link Option}, {@link ValueOption},
|
|
942
|
+
* or {@link FullOption} instead. For specific option types, you can use
|
|
943
|
+
* {@link FullField}, {@link FullOperator}, or {@link FullCombinator},
|
|
944
|
+
* all of which extend {@link FullOption}.
|
|
945
|
+
*
|
|
946
|
+
* @group Option Lists
|
|
947
|
+
*/
|
|
948
|
+
interface BaseOption<N extends string = string> {
|
|
949
|
+
name?: N;
|
|
950
|
+
value?: N;
|
|
951
|
+
label: string;
|
|
952
|
+
disabled?: boolean;
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* A generic option. Used directly in {@link OptionList} or
|
|
956
|
+
* as the child element of an {@link OptionGroup}.
|
|
957
|
+
*
|
|
958
|
+
* @group Option Lists
|
|
959
|
+
*/
|
|
960
|
+
type Option<N extends string = string> = Simplify<WithUnknownIndex<SetRequired<BaseOption<N>, "name">>>;
|
|
961
|
+
/**
|
|
962
|
+
* Like {@link Option} but requiring `value` instead of `name`.
|
|
963
|
+
*
|
|
964
|
+
* @group Option Lists
|
|
965
|
+
*/
|
|
966
|
+
type ValueOption<N extends string = string> = Simplify<WithUnknownIndex<SetRequired<BaseOption<N>, "value">>>;
|
|
967
|
+
/**
|
|
968
|
+
* A generic {@link Option} with either a `name` or `value` as its primary identifier.
|
|
969
|
+
* {@link OptionList}-type props on the {@link QueryBuilder} component accept this type,
|
|
970
|
+
* but corresponding props passed down to subcomponents will always be translated
|
|
971
|
+
* to {@link FullOption} first.
|
|
972
|
+
*
|
|
973
|
+
* @group Option Lists
|
|
974
|
+
*/
|
|
975
|
+
type FlexibleOption<N extends string = string> = Simplify<WithUnknownIndex<RequireAtLeastOne<BaseOption<N>, "name" | "value">>>;
|
|
976
|
+
/**
|
|
977
|
+
* Utility type to turn an {@link Option}, {@link ValueOption}, or {@link BaseOption}
|
|
978
|
+
* into a {@link FlexibleOption}.
|
|
979
|
+
*
|
|
980
|
+
* @group Option Lists
|
|
981
|
+
*/
|
|
982
|
+
type ToFlexibleOption<Opt extends BaseOption | string> = WithUnknownIndex<RequireAtLeastOne<Opt extends string ? FlexibleOption<Opt> : Opt, "name" | "value">>;
|
|
983
|
+
/**
|
|
984
|
+
* A generic {@link Option} requiring both `name` _and_ `value` properties.
|
|
985
|
+
* Props that extend {@link OptionList} accept {@link BaseOption}, but
|
|
986
|
+
* corresponding props sent to subcomponents will always be translated to this
|
|
987
|
+
* type first to ensure both `name` and `value` are available.
|
|
988
|
+
*
|
|
989
|
+
* NOTE: Do not extend from this type directly. Use {@link BaseFullOption}
|
|
990
|
+
* (optionally wrapped in {@link WithUnknownIndex}) instead, otherwise
|
|
991
|
+
* the `unknown` index property will cause issues. See {@link Option} and
|
|
992
|
+
* {@link ValueOption} for examples.
|
|
993
|
+
*
|
|
994
|
+
* @group Option Lists
|
|
995
|
+
*/
|
|
996
|
+
type FullOption<N extends string = string> = Simplify<WithUnknownIndex<SetRequired<BaseOption<N>, "name" | "value">>>;
|
|
997
|
+
/**
|
|
998
|
+
* This type is identical to {@link FullOption} but without the `unknown` index
|
|
999
|
+
* property. Extend from this type instead of {@link FullOption} directly.
|
|
1000
|
+
*
|
|
1001
|
+
* @group Option Lists
|
|
1002
|
+
*/
|
|
1003
|
+
type BaseFullOption<N extends string = string> = Simplify<SetRequired<BaseOption<N>, "name" | "value">>;
|
|
1004
|
+
/**
|
|
1005
|
+
* Utility type to turn an {@link Option}, {@link ValueOption} or
|
|
1006
|
+
* {@link BaseOption} into a {@link FullOption}.
|
|
1007
|
+
*
|
|
1008
|
+
* @group Option Lists
|
|
1009
|
+
*/
|
|
1010
|
+
type ToFullOption<Opt extends BaseOption> = Opt extends BaseFullOption ? Opt : Opt extends BaseOption<infer IdentifierType> ? WithUnknownIndex<Opt & FullOption<IdentifierType>> : never;
|
|
1011
|
+
/**
|
|
1012
|
+
* A group of {@link Option}s, usually within an {@link OptionList}.
|
|
1013
|
+
*
|
|
1014
|
+
* @group Option Lists
|
|
1015
|
+
*/
|
|
1016
|
+
interface OptionGroup<Opt extends BaseOption = FlexibleOption> {
|
|
1017
|
+
label: string;
|
|
1018
|
+
options: WithUnknownIndex<Opt>[];
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* A group of {@link BaseOption}s, usually within a {@link FlexibleOptionList}.
|
|
1022
|
+
*
|
|
1023
|
+
* @group Option Lists
|
|
1024
|
+
*/
|
|
1025
|
+
type FlexibleOptionGroup<Opt extends BaseOption | string = BaseOption> = {
|
|
1026
|
+
label: string;
|
|
1027
|
+
options: (Opt extends BaseFullOption ? Opt : ToFlexibleOption<Opt>)[];
|
|
1028
|
+
};
|
|
1029
|
+
/**
|
|
1030
|
+
* Either an array of {@link Option}s or an array of {@link OptionGroup}s.
|
|
1031
|
+
*
|
|
1032
|
+
* @group Option Lists
|
|
1033
|
+
*/
|
|
1034
|
+
type OptionList<Opt extends Option = Option> = Opt[] | OptionGroup<Opt>[];
|
|
1035
|
+
/**
|
|
1036
|
+
* An array of options or option groups, like {@link OptionList} but the option type
|
|
1037
|
+
* may use either `name` or `value` as the primary identifier.
|
|
1038
|
+
*
|
|
1039
|
+
* @group Option Lists
|
|
1040
|
+
*/
|
|
1041
|
+
type FlexibleOptionList<Opt extends BaseOption> = ToFlexibleOption<Opt>[] | FlexibleOptionGroup<ToFlexibleOption<Opt>>[];
|
|
1042
|
+
/**
|
|
1043
|
+
* An array of options or option groups, like {@link OptionList} but the option type
|
|
1044
|
+
* may use either `name` or `value` as the primary identifier.
|
|
1045
|
+
*
|
|
1046
|
+
* @group Option Lists
|
|
1047
|
+
*/
|
|
1048
|
+
type FlexibleOptionListProp<Opt extends BaseOption> = (ToFlexibleOption<Opt> | GetOptionIdentifierType<Opt>)[] | FlexibleOptionGroup<ToFlexibleOption<Opt> | GetOptionIdentifierType<Opt>>[];
|
|
1049
|
+
/**
|
|
1050
|
+
* An array of options or option groups, like {@link OptionList}, but using
|
|
1051
|
+
* {@link FullOption} instead of {@link Option}. This means that every member is
|
|
1052
|
+
* guaranteed to have both `name` and `value`.
|
|
1053
|
+
*
|
|
1054
|
+
* @group Option Lists
|
|
1055
|
+
*/
|
|
1056
|
+
type FullOptionList<Opt extends BaseOption> = Opt extends BaseFullOption ? Opt[] | OptionGroup<Opt>[] : ToFullOption<Opt>[] | OptionGroup<ToFullOption<Opt>>[];
|
|
1057
|
+
/**
|
|
1058
|
+
* Map of option identifiers to their respective {@link Option}.
|
|
1059
|
+
*
|
|
1060
|
+
* @group Option Lists
|
|
1061
|
+
*/
|
|
1062
|
+
type BaseOptionMap<V extends BaseOption = BaseOption, K extends string = GetOptionIdentifierType<V>> = { [k in K]?: ToFlexibleOption<V> };
|
|
1063
|
+
//#endregion
|
|
1064
|
+
//#region ../core/src/types/ruleGroups.d.ts
|
|
1065
|
+
/**
|
|
1066
|
+
* Properties common to both rules and groups.
|
|
1067
|
+
*/
|
|
1068
|
+
interface CommonRuleAndGroupProperties {
|
|
1069
|
+
path?: Path;
|
|
1070
|
+
id?: string;
|
|
1071
|
+
disabled?: boolean;
|
|
1072
|
+
}
|
|
1073
|
+
/**
|
|
1074
|
+
* The main rule type. The `field`, `operator`, and `value` properties
|
|
1075
|
+
* can be narrowed with generics.
|
|
1076
|
+
*/
|
|
1077
|
+
interface RuleType<F extends string = string, O extends string = string, V = any, C extends string = string> extends CommonRuleAndGroupProperties {
|
|
1078
|
+
field: F;
|
|
1079
|
+
operator: O;
|
|
1080
|
+
value: V;
|
|
1081
|
+
valueSource?: ValueSource;
|
|
1082
|
+
match?: MatchConfig;
|
|
1083
|
+
/**
|
|
1084
|
+
* Only used when adding a rule to a query that uses independent combinators.
|
|
1085
|
+
*/
|
|
1086
|
+
combinatorPreceding?: C;
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* The main rule group type. This type is used for query definitions as well as
|
|
1090
|
+
* all sub-groups of queries.
|
|
1091
|
+
*/
|
|
1092
|
+
interface RuleGroupType<R extends RuleType = RuleType, C extends string = string> extends CommonRuleAndGroupProperties {
|
|
1093
|
+
combinator: C;
|
|
1094
|
+
rules: RuleGroupArray<RuleGroupType<R, C>, R>;
|
|
1095
|
+
not?: boolean;
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* The type of the `rules` array in a {@link RuleGroupType}.
|
|
1099
|
+
*/
|
|
1100
|
+
type RuleGroupArray<RG extends RuleGroupType = RuleGroupType, R extends RuleType = RuleType> = (R | RG)[];
|
|
1101
|
+
//#endregion
|
|
1102
|
+
//#region ../core/src/types/ruleGroupsIC.utils.d.ts
|
|
1103
|
+
type MAXIMUM_ALLOWED_BOUNDARY = 80;
|
|
1104
|
+
type MappedTuple<Tuple extends Array<unknown>, Result extends Array<unknown> = [], Count extends ReadonlyArray<number> = []> = Count["length"] extends MAXIMUM_ALLOWED_BOUNDARY ? Result : Tuple extends [] ? [] : Result extends [] ? MappedTuple<Tuple, Tuple, [...Count, 1]> : MappedTuple<Tuple, Result | [...Result, ...Tuple], [...Count, 1]>;
|
|
1105
|
+
//#endregion
|
|
1106
|
+
//#region ../core/src/types/ruleGroupsIC.d.ts
|
|
1107
|
+
/**
|
|
1108
|
+
* The main rule group interface when using independent combinators. This type is used
|
|
1109
|
+
* for query definitions as well as all sub-groups of queries.
|
|
1110
|
+
*/
|
|
1111
|
+
interface RuleGroupTypeIC<R extends RuleType = RuleType, C extends string = string> extends Except<RuleGroupType<R, C>, "combinator" | "rules"> {
|
|
1112
|
+
combinator?: undefined;
|
|
1113
|
+
rules: RuleGroupICArray<RuleGroupTypeIC<R, C>, R, C>;
|
|
1114
|
+
/**
|
|
1115
|
+
* Only used when adding a rule to a query that uses independent combinators
|
|
1116
|
+
*/
|
|
1117
|
+
combinatorPreceding?: C;
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* Shorthand for "either {@link RuleGroupType} or {@link RuleGroupTypeIC}".
|
|
1121
|
+
*/
|
|
1122
|
+
type RuleGroupTypeAny<R extends RuleType = RuleType, C extends string = string> = RuleGroupType<R, C> | RuleGroupTypeIC<R, C>;
|
|
1123
|
+
/**
|
|
1124
|
+
* The type of the `rules` array in a {@link RuleGroupTypeIC}.
|
|
1125
|
+
*/
|
|
1126
|
+
type RuleGroupICArray<RG extends RuleGroupTypeIC = RuleGroupTypeIC, R extends RuleType = RuleType, C extends string = string> = [R | RG] | [R | RG, ...MappedTuple<[C, R | RG]>] | ((R | RG)[] & {
|
|
1127
|
+
length: 0;
|
|
1128
|
+
});
|
|
1129
|
+
/**
|
|
1130
|
+
* Shorthand for "either {@link RuleGroupArray} or {@link RuleGroupICArray}".
|
|
1131
|
+
*/
|
|
1132
|
+
type RuleOrGroupArray = RuleGroupArray | RuleGroupICArray;
|
|
1133
|
+
/**
|
|
1134
|
+
* Converts a narrowed rule group type to its most generic form.
|
|
1135
|
+
*/
|
|
1136
|
+
type GenericizeRuleGroupType<RG> = RG extends RuleGroupType ? RuleGroupType : RuleGroupTypeIC;
|
|
1137
|
+
//#endregion
|
|
1138
|
+
//#region ../core/src/types/validation.d.ts
|
|
1139
|
+
/**
|
|
1140
|
+
* Object with a `valid` boolean value and optional `reasons`.
|
|
1141
|
+
*/
|
|
1142
|
+
interface ValidationResult {
|
|
1143
|
+
valid: boolean;
|
|
1144
|
+
reasons?: any[];
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Map of rule/group `id` to its respective {@link ValidationResult}.
|
|
1148
|
+
*/
|
|
1149
|
+
type ValidationMap = Record<string, boolean | ValidationResult>;
|
|
1150
|
+
/**
|
|
1151
|
+
* Function that validates a query.
|
|
1152
|
+
*/
|
|
1153
|
+
type QueryValidator = (query: RuleGroupTypeAny) => boolean | ValidationMap;
|
|
1154
|
+
/**
|
|
1155
|
+
* Function that validates a rule.
|
|
1156
|
+
*/
|
|
1157
|
+
type RuleValidator = (rule: RuleType) => boolean | ValidationResult;
|
|
1158
|
+
//#endregion
|
|
1159
|
+
//#region ../core/src/types/basic.d.ts
|
|
1160
|
+
/**
|
|
1161
|
+
* @see https://react-querybuilder.js.org/docs/tips/path
|
|
1162
|
+
*/
|
|
1163
|
+
type Path = number[];
|
|
1164
|
+
/**
|
|
1165
|
+
* String of classnames, array of classname strings, or object where the
|
|
1166
|
+
* keys are classnames and those with truthy values will be included.
|
|
1167
|
+
* Suitable for passing to the `clsx` package.
|
|
1168
|
+
*/
|
|
1169
|
+
type Classname = string | string[] | Record<string, any>;
|
|
1170
|
+
/**
|
|
1171
|
+
* A source for the `value` property of a rule.
|
|
1172
|
+
*/
|
|
1173
|
+
type ValueSource = "value" | "field";
|
|
1174
|
+
/**
|
|
1175
|
+
* Type of {@link ValueEditor} that will be displayed.
|
|
1176
|
+
*/
|
|
1177
|
+
type ValueEditorType = "text" | "select" | "checkbox" | "radio" | "textarea" | "switch" | "multiselect" | null;
|
|
1178
|
+
/**
|
|
1179
|
+
* A valid array of potential value sources.
|
|
1180
|
+
*
|
|
1181
|
+
* @see {@link ValueSource}
|
|
1182
|
+
*/
|
|
1183
|
+
type ValueSources = ["value"] | ["value", "field"] | ["field", "value"] | ["field"];
|
|
1184
|
+
type ValueSourceFlexibleOptions = ToFlexibleOptionArrays<ValueSources>;
|
|
1185
|
+
type ValueSourceFullOptions = ToOptionArrays<ValueSources>;
|
|
1186
|
+
type ToOptionArrays<Sources extends readonly string[]> = Sources extends unknown ? { [K in keyof Sources]: {
|
|
1187
|
+
name: Sources[K];
|
|
1188
|
+
value: Sources[K];
|
|
1189
|
+
label: string;
|
|
1190
|
+
} } : never;
|
|
1191
|
+
type ToFlexibleOptionArrays<Sources extends readonly string[]> = Sources extends unknown ? { [K in keyof Sources]: FlexibleOption<Sources[K]> } : never;
|
|
1192
|
+
type WithOptionalClassName<T> = T & {
|
|
1193
|
+
className?: Classname;
|
|
1194
|
+
};
|
|
1195
|
+
/**
|
|
1196
|
+
* HTML5 input types
|
|
1197
|
+
*/
|
|
1198
|
+
type InputType = "button" | "checkbox" | "color" | "date" | "datetime-local" | "email" | "file" | "hidden" | "image" | "month" | "number" | "password" | "radio" | "range" | "reset" | "search" | "submit" | "tel" | "text" | "time" | "url" | "week" | "bigint" | (string & {});
|
|
1199
|
+
/**
|
|
1200
|
+
* Quantification mode describing how many elements of the value array must pass
|
|
1201
|
+
* the filter for the rule itself to pass.
|
|
1202
|
+
*
|
|
1203
|
+
* For "atLeast", "atMost", and "exactly", the threshold value will be converted to
|
|
1204
|
+
* a percentage if the number is less than 1. Non-numeric values and numbers less
|
|
1205
|
+
* than 0 will be ignored.
|
|
1206
|
+
*/
|
|
1207
|
+
interface MatchConfig {
|
|
1208
|
+
mode: MatchMode;
|
|
1209
|
+
threshold?: number | null | undefined;
|
|
1210
|
+
}
|
|
1211
|
+
type MatchMode = "all" | "some" | "none" | "atLeast" | "atMost" | "exactly";
|
|
1212
|
+
type MatchModeOptions = StringUnionToFullOptionArray<MatchMode>;
|
|
1213
|
+
type ActionElementEventHandler = (event?: any, context?: any) => void;
|
|
1214
|
+
type ValueChangeEventHandler = (value?: any, context?: any) => void;
|
|
1215
|
+
/**
|
|
1216
|
+
* Base for all Field types/interfaces.
|
|
1217
|
+
*/
|
|
1218
|
+
interface BaseFullField<FieldName extends string = string, OperatorName extends string = string, ValueName extends string = string, OperatorObj extends FullOption = FullOption<OperatorName>, ValueObj extends FullOption = FullOption<ValueName>> extends WithOptionalClassName<BaseFullOption<FieldName>> {
|
|
1219
|
+
id?: string;
|
|
1220
|
+
operators?: FlexibleOptionList<OperatorObj> | OperatorName[] | FlexibleOption<OperatorName>[] | (OperatorName | FlexibleOption<OperatorName>)[];
|
|
1221
|
+
valueEditorType?: ValueEditorType | ((operator: OperatorName) => ValueEditorType);
|
|
1222
|
+
valueSources?: ValueSources | ValueSourceFlexibleOptions | ((operator: OperatorName) => ValueSources | ValueSourceFlexibleOptions);
|
|
1223
|
+
inputType?: InputType | null;
|
|
1224
|
+
values?: FlexibleOptionList<ValueObj>;
|
|
1225
|
+
matchModes?: boolean | MatchMode[] | FlexibleOption<MatchMode>[];
|
|
1226
|
+
/** Properties of items in the value. */
|
|
1227
|
+
subproperties?: FlexibleOptionList<FullField>;
|
|
1228
|
+
defaultOperator?: OperatorName;
|
|
1229
|
+
defaultValue?: any;
|
|
1230
|
+
placeholder?: string;
|
|
1231
|
+
validator?: RuleValidator;
|
|
1232
|
+
comparator?: string | ((f: FullField, operator: string) => boolean);
|
|
1233
|
+
}
|
|
1234
|
+
/**
|
|
1235
|
+
* Full field definition used in the `fields` prop of {@link QueryBuilder}.
|
|
1236
|
+
* This type requires both `name` and `value`, but the `fields` prop itself
|
|
1237
|
+
* can use a {@link FlexibleOption} where only one of `name` or `value` is
|
|
1238
|
+
* required (along with `label`), or {@link Field} where only `name` and
|
|
1239
|
+
* `label` are required.
|
|
1240
|
+
*
|
|
1241
|
+
* The `name`/`value`, `operators`, and `values` properties of this interface
|
|
1242
|
+
* can be narrowed with generics.
|
|
1243
|
+
*
|
|
1244
|
+
* @group Option Lists
|
|
1245
|
+
*/
|
|
1246
|
+
type FullField<FieldName extends string = string, OperatorName extends string = string, ValueName extends string = string, OperatorObj extends FullOption = FullOption<OperatorName>, ValueObj extends FullOption = FullOption<ValueName>> = Simplify<FullOption<FieldName> & BaseFullField<FieldName, OperatorName, ValueName, OperatorObj, ValueObj>>;
|
|
1247
|
+
/**
|
|
1248
|
+
* Allowed values of the {@link FullOperator} property `arity`. A value of `"unary"` or
|
|
1249
|
+
* a number less than two will cause the default {@link ValueEditor} to render `null`.
|
|
1250
|
+
*/
|
|
1251
|
+
type Arity = number | "unary" | "binary" | "ternary";
|
|
1252
|
+
/**
|
|
1253
|
+
* Full operator definition used in the `operators`/`getOperators` props of
|
|
1254
|
+
* {@link QueryBuilder}. This type requires both `name` and `value`, but the
|
|
1255
|
+
* `operators`/`getOperators` props themselves can use a {@link FlexibleOption}
|
|
1256
|
+
* where only one of `name` or `value` is required, or {@link FullOperator} where
|
|
1257
|
+
* only `name` is required.
|
|
1258
|
+
*
|
|
1259
|
+
* The `name`/`value` properties of this interface can be narrowed with generics.
|
|
1260
|
+
*
|
|
1261
|
+
* @group Option Lists
|
|
1262
|
+
*/
|
|
1263
|
+
interface FullOperator<N extends string = string> extends WithOptionalClassName<FullOption<N>> {
|
|
1264
|
+
arity?: Arity;
|
|
1265
|
+
}
|
|
1266
|
+
/**
|
|
1267
|
+
* Full combinator definition used in the `combinators` prop of {@link QueryBuilder}.
|
|
1268
|
+
* This type requires both `name` and `value`, but the `combinators` prop itself
|
|
1269
|
+
* can use a {@link FlexibleOption} where only one of `name` or `value` is required,
|
|
1270
|
+
* or {@link Combinator} where only `name` is required.
|
|
1271
|
+
*
|
|
1272
|
+
* The `name`/`value` properties of this interface can be narrowed with generics.
|
|
1273
|
+
*
|
|
1274
|
+
* @group Option Lists
|
|
1275
|
+
*/
|
|
1276
|
+
type FullCombinator<N extends string = string> = WithOptionalClassName<FullOption<N>>;
|
|
1277
|
+
type ParseNumberMethodName = "enhanced" | "native" | "strict";
|
|
1278
|
+
/**
|
|
1279
|
+
* Parsing algorithms used by {@link parseNumber}.
|
|
1280
|
+
*/
|
|
1281
|
+
|
|
1282
|
+
type ParseNumbersModerationLevel = "-limited" | "";
|
|
1283
|
+
/**
|
|
1284
|
+
* Options for the `parseNumbers` prop of {@link QueryBuilder}.
|
|
1285
|
+
*/
|
|
1286
|
+
type ParseNumbersPropConfig = boolean | `${ParseNumberMethodName}${ParseNumbersModerationLevel}`;
|
|
1287
|
+
/**
|
|
1288
|
+
* Signature of `accessibleDescriptionGenerator` prop, used by {@link QueryBuilder} to generate
|
|
1289
|
+
* accessible descriptions for each {@link RuleGroup}.
|
|
1290
|
+
*/
|
|
1291
|
+
type AccessibleDescriptionGenerator = (props: {
|
|
1292
|
+
path: Path;
|
|
1293
|
+
qbId: string;
|
|
1294
|
+
}) => string;
|
|
1295
|
+
//#endregion
|
|
1296
|
+
//#region ../core/src/types/dnd.d.ts
|
|
1297
|
+
type DropEffect = "move" | "copy";
|
|
1298
|
+
//#endregion
|
|
1299
|
+
//#region ../core/src/types/props.d.ts
|
|
1300
|
+
/**
|
|
1301
|
+
* Base interface for all rule subcomponents.
|
|
1302
|
+
*
|
|
1303
|
+
* @group Props
|
|
1304
|
+
*/
|
|
1305
|
+
interface CommonRuleSubComponentProps {
|
|
1306
|
+
rule: RuleType;
|
|
1307
|
+
}
|
|
1308
|
+
/**
|
|
1309
|
+
* Classnames applied to each component.
|
|
1310
|
+
*
|
|
1311
|
+
* @group Props
|
|
1312
|
+
*/
|
|
1313
|
+
interface Classnames {
|
|
1314
|
+
/**
|
|
1315
|
+
* Classnames applied to the root `<div>` element.
|
|
1316
|
+
*/
|
|
1317
|
+
queryBuilder: Classname;
|
|
1318
|
+
/**
|
|
1319
|
+
* Classnames applied to the `<div>` containing the RuleGroup.
|
|
1320
|
+
*/
|
|
1321
|
+
ruleGroup: Classname;
|
|
1322
|
+
/**
|
|
1323
|
+
* Classnames applied to the `<div>` containing the RuleGroup header controls.
|
|
1324
|
+
*/
|
|
1325
|
+
header: Classname;
|
|
1326
|
+
/**
|
|
1327
|
+
* Classnames applied to the `<div>` containing the RuleGroup child rules/groups.
|
|
1328
|
+
*/
|
|
1329
|
+
body: Classname;
|
|
1330
|
+
/**
|
|
1331
|
+
* Classnames applied to the `<select>` control for combinators.
|
|
1332
|
+
*/
|
|
1333
|
+
combinators: Classname;
|
|
1334
|
+
/**
|
|
1335
|
+
* Classnames applied to the `<button>` to add a Rule.
|
|
1336
|
+
*/
|
|
1337
|
+
addRule: Classname;
|
|
1338
|
+
/**
|
|
1339
|
+
* Classnames applied to the `<button>` to add a RuleGroup.
|
|
1340
|
+
*/
|
|
1341
|
+
addGroup: Classname;
|
|
1342
|
+
/**
|
|
1343
|
+
* Classnames applied to the `<button>` to clone a Rule.
|
|
1344
|
+
*/
|
|
1345
|
+
cloneRule: Classname;
|
|
1346
|
+
/**
|
|
1347
|
+
* Classnames applied to the `<button>` to clone a RuleGroup.
|
|
1348
|
+
*/
|
|
1349
|
+
cloneGroup: Classname;
|
|
1350
|
+
/**
|
|
1351
|
+
* Classnames applied to the `<button>` to remove a RuleGroup.
|
|
1352
|
+
*/
|
|
1353
|
+
removeGroup: Classname;
|
|
1354
|
+
/**
|
|
1355
|
+
* Classnames applied to the `<div>` containing the Rule.
|
|
1356
|
+
*/
|
|
1357
|
+
rule: Classname;
|
|
1358
|
+
/**
|
|
1359
|
+
* Classnames applied to the `<select>` control for fields.
|
|
1360
|
+
*/
|
|
1361
|
+
fields: Classname;
|
|
1362
|
+
/**
|
|
1363
|
+
* Classnames applied to the `<select>` control for match modes.
|
|
1364
|
+
*/
|
|
1365
|
+
matchMode: Classname;
|
|
1366
|
+
/**
|
|
1367
|
+
* Classnames applied to the `<input>` for match thresholds.
|
|
1368
|
+
*/
|
|
1369
|
+
matchThreshold: Classname;
|
|
1370
|
+
/**
|
|
1371
|
+
* Classnames applied to the `<select>` control for operators.
|
|
1372
|
+
*/
|
|
1373
|
+
operators: Classname;
|
|
1374
|
+
/**
|
|
1375
|
+
* Classnames applied to the `<input>` for the rule value.
|
|
1376
|
+
*/
|
|
1377
|
+
value: Classname;
|
|
1378
|
+
/**
|
|
1379
|
+
* Classnames applied to the `<button>` to remove a Rule.
|
|
1380
|
+
*/
|
|
1381
|
+
removeRule: Classname;
|
|
1382
|
+
/**
|
|
1383
|
+
* Classnames applied to the `<label>` on the "not" toggle.
|
|
1384
|
+
*/
|
|
1385
|
+
notToggle: Classname;
|
|
1386
|
+
/**
|
|
1387
|
+
* Classnames applied to the `<span>` handle for dragging rules/groups.
|
|
1388
|
+
*/
|
|
1389
|
+
shiftActions: Classname;
|
|
1390
|
+
/**
|
|
1391
|
+
* Classnames applied to the `<span>` handle for dragging rules/groups.
|
|
1392
|
+
*/
|
|
1393
|
+
dragHandle: Classname;
|
|
1394
|
+
/**
|
|
1395
|
+
* Classnames applied to the `<button>` to lock/disable a Rule.
|
|
1396
|
+
*/
|
|
1397
|
+
lockRule: Classname;
|
|
1398
|
+
/**
|
|
1399
|
+
* Classnames applied to the `<button>` to lock/disable a RuleGroup.
|
|
1400
|
+
*/
|
|
1401
|
+
lockGroup: Classname;
|
|
1402
|
+
/**
|
|
1403
|
+
* Classnames applied to the `<select>` control for value sources.
|
|
1404
|
+
*/
|
|
1405
|
+
valueSource: Classname;
|
|
1406
|
+
/**
|
|
1407
|
+
* Classnames applied to all action elements.
|
|
1408
|
+
*/
|
|
1409
|
+
actionElement: Classname;
|
|
1410
|
+
/**
|
|
1411
|
+
* Classnames applied to all select elements.
|
|
1412
|
+
*/
|
|
1413
|
+
valueSelector: Classname;
|
|
1414
|
+
/**
|
|
1415
|
+
* Classname(s) applied to inline combinator elements.
|
|
1416
|
+
*/
|
|
1417
|
+
betweenRules: Classname;
|
|
1418
|
+
/**
|
|
1419
|
+
* Classname(s) applied to valid rules and groups.
|
|
1420
|
+
*/
|
|
1421
|
+
valid: Classname;
|
|
1422
|
+
/**
|
|
1423
|
+
* Classname(s) applied to invalid rules and groups.
|
|
1424
|
+
*/
|
|
1425
|
+
invalid: Classname;
|
|
1426
|
+
/**
|
|
1427
|
+
* Classname(s) applied to rules and groups while being dragged.
|
|
1428
|
+
*/
|
|
1429
|
+
dndDragging: Classname;
|
|
1430
|
+
/**
|
|
1431
|
+
* Classname(s) applied to rules and groups hovered over by a dragged element.
|
|
1432
|
+
*/
|
|
1433
|
+
dndOver: Classname;
|
|
1434
|
+
/**
|
|
1435
|
+
* Classname(s) applied to rules and groups hovered over by a dragged element
|
|
1436
|
+
* when the drop effect is "copy" (modifier key is pressed).
|
|
1437
|
+
*/
|
|
1438
|
+
dndCopy: Classname;
|
|
1439
|
+
/**
|
|
1440
|
+
* Classname(s) applied to rules and groups hovered over by a dragged element
|
|
1441
|
+
* when the Ctrl key is pressed, indicating the items will form a new group.
|
|
1442
|
+
*/
|
|
1443
|
+
dndGroup: Classname;
|
|
1444
|
+
/**
|
|
1445
|
+
* Classname(s) applied to rules and groups that cannot accept a drop from
|
|
1446
|
+
* the dragged element hovering over it.
|
|
1447
|
+
*/
|
|
1448
|
+
dndDropNotAllowed: Classname;
|
|
1449
|
+
/**
|
|
1450
|
+
* Classname(s) applied to disabled elements.
|
|
1451
|
+
*/
|
|
1452
|
+
disabled: Classname;
|
|
1453
|
+
/**
|
|
1454
|
+
* Classname(s) applied to each element in a series of value editors.
|
|
1455
|
+
*/
|
|
1456
|
+
valueListItem: Classname;
|
|
1457
|
+
/**
|
|
1458
|
+
* Not applied, but see CSS styles.
|
|
1459
|
+
*/
|
|
1460
|
+
branches: Classname;
|
|
1461
|
+
/**
|
|
1462
|
+
* Classname(s) rules that render a subquery.
|
|
1463
|
+
*/
|
|
1464
|
+
hasSubQuery: Classname;
|
|
1465
|
+
}
|
|
1466
|
+
/**
|
|
1467
|
+
* Functions included in the `actions` prop passed to every subcomponent.
|
|
1468
|
+
*
|
|
1469
|
+
* @group Props
|
|
1470
|
+
*/
|
|
1471
|
+
interface QueryActions {
|
|
1472
|
+
onGroupAdd(group: RuleGroupTypeAny, parentPath: Path, context?: any): void;
|
|
1473
|
+
onGroupRemove(path: Path): void;
|
|
1474
|
+
onPropChange(prop: Exclude<keyof RuleType | keyof RuleGroupType, "id" | "path">, value: any, path: Path, context?: any): void;
|
|
1475
|
+
onRuleAdd(rule: RuleType, parentPath: Path, context?: any): void;
|
|
1476
|
+
onRuleRemove(path: Path): void;
|
|
1477
|
+
moveRule(oldPath: Path, newPath: Path | "up" | "down", clone?: boolean, context?: any): void;
|
|
1478
|
+
groupRule(sourcePath: Path, targetPath: Path, clone?: boolean, context?: any): void;
|
|
1479
|
+
}
|
|
1480
|
+
//#endregion
|
|
1481
|
+
//#region ../core/src/utils/queryTools.d.ts
|
|
1482
|
+
/**
|
|
1483
|
+
* Options for {@link move}.
|
|
1484
|
+
*
|
|
1485
|
+
* @group Query Tools
|
|
1486
|
+
*/
|
|
1487
|
+
interface MoveOptions {
|
|
1488
|
+
/**
|
|
1489
|
+
* When `true`, the source rule/group will not be removed from its original path.
|
|
1490
|
+
*/
|
|
1491
|
+
clone?: boolean;
|
|
1492
|
+
/**
|
|
1493
|
+
* If the query extends `RuleGroupTypeIC` (i.e. the query is using independent
|
|
1494
|
+
* combinators), then the first combinator in this list will be inserted before
|
|
1495
|
+
* the rule/group if necessary.
|
|
1496
|
+
*/
|
|
1497
|
+
combinators?: OptionList;
|
|
1498
|
+
/**
|
|
1499
|
+
* ID generator.
|
|
1500
|
+
*/
|
|
1501
|
+
idGenerator?: () => string;
|
|
1502
|
+
}
|
|
1503
|
+
/**
|
|
1504
|
+
* Options for {@link group}.
|
|
1505
|
+
*
|
|
1506
|
+
* @group Query Tools
|
|
1507
|
+
*/
|
|
1508
|
+
interface GroupOptions {
|
|
1509
|
+
/**
|
|
1510
|
+
* When `true`, the source rule/group will not be removed from its original path.
|
|
1511
|
+
*/
|
|
1512
|
+
clone?: boolean;
|
|
1513
|
+
/**
|
|
1514
|
+
* If the query extends `RuleGroupTypeIC` (i.e. the query is using independent
|
|
1515
|
+
* combinators), then the first combinator in this list will be inserted between
|
|
1516
|
+
* the two rules/groups.
|
|
1517
|
+
*/
|
|
1518
|
+
combinators?: OptionList;
|
|
1519
|
+
/**
|
|
1520
|
+
* ID generator.
|
|
1521
|
+
*/
|
|
1522
|
+
idGenerator?: () => string;
|
|
1523
|
+
}
|
|
1524
|
+
//#endregion
|
|
1525
|
+
//#region ../react-querybuilder/src/components/RuleGroup.d.ts
|
|
1526
|
+
interface UseRuleGroup extends RuleGroupProps {
|
|
1527
|
+
addGroup: ActionElementEventHandler;
|
|
1528
|
+
addRule: ActionElementEventHandler;
|
|
1529
|
+
accessibleDescription: string;
|
|
1530
|
+
classNames: Pick<{ [k in keyof Classnames]: string }, "header" | "shiftActions" | "dragHandle" | "combinators" | "notToggle" | "addRule" | "addGroup" | "cloneGroup" | "lockGroup" | "removeGroup" | "body">;
|
|
1531
|
+
cloneGroup: ActionElementEventHandler;
|
|
1532
|
+
onCombinatorChange: ValueChangeEventHandler;
|
|
1533
|
+
onGroupAdd: (group: RuleGroupTypeAny, parentPath: Path, context?: any) => void;
|
|
1534
|
+
onIndependentCombinatorChange: (value: any, index: number, context?: any) => void;
|
|
1535
|
+
onNotToggleChange: (checked: boolean, context?: any) => void;
|
|
1536
|
+
outerClassName: string;
|
|
1537
|
+
pathsMemo: {
|
|
1538
|
+
path: Path;
|
|
1539
|
+
disabled: boolean;
|
|
1540
|
+
}[];
|
|
1541
|
+
removeGroup: ActionElementEventHandler;
|
|
1542
|
+
ruleGroup: RuleGroupType | RuleGroupTypeIC;
|
|
1543
|
+
shiftGroupDown: (event?: MouseEvent, context?: any) => void;
|
|
1544
|
+
shiftGroupUp: (event?: MouseEvent, context?: any) => void;
|
|
1545
|
+
toggleLockGroup: ActionElementEventHandler;
|
|
1546
|
+
validationClassName: string;
|
|
1547
|
+
validationResult: boolean | ValidationResult;
|
|
1548
|
+
}
|
|
1549
|
+
//#endregion
|
|
1550
|
+
//#region ../react-querybuilder/src/types/props.d.ts
|
|
1551
|
+
/**
|
|
1552
|
+
* Base interface for all subcomponents.
|
|
1553
|
+
*
|
|
1554
|
+
* @group Props
|
|
1555
|
+
*/
|
|
1556
|
+
interface CommonSubComponentProps<F extends FullOption = FullField, O extends string = string> {
|
|
1557
|
+
/**
|
|
1558
|
+
* CSS classNames to be applied.
|
|
1559
|
+
*
|
|
1560
|
+
* This is `string` and not {@link Classname} because the {@link Rule}
|
|
1561
|
+
* and {@link RuleGroup} components run `clsx()` to produce the `className`
|
|
1562
|
+
* that gets passed to each subcomponent.
|
|
1563
|
+
*/
|
|
1564
|
+
className?: string;
|
|
1565
|
+
/**
|
|
1566
|
+
* Path to this subcomponent's rule/group within the query.
|
|
1567
|
+
*/
|
|
1568
|
+
path: Path;
|
|
1569
|
+
/**
|
|
1570
|
+
* The level of the current group. Always equal to `path.length`.
|
|
1571
|
+
*/
|
|
1572
|
+
level: number;
|
|
1573
|
+
/**
|
|
1574
|
+
* The title/tooltip for this control.
|
|
1575
|
+
*/
|
|
1576
|
+
title?: string;
|
|
1577
|
+
/**
|
|
1578
|
+
* Disables the control.
|
|
1579
|
+
*/
|
|
1580
|
+
disabled?: boolean;
|
|
1581
|
+
/**
|
|
1582
|
+
* Container for custom props that are passed to all components.
|
|
1583
|
+
*/
|
|
1584
|
+
context?: any;
|
|
1585
|
+
/**
|
|
1586
|
+
* Validation result of the parent rule/group.
|
|
1587
|
+
*/
|
|
1588
|
+
validation?: boolean | ValidationResult;
|
|
1589
|
+
/**
|
|
1590
|
+
* Test ID for this component.
|
|
1591
|
+
*/
|
|
1592
|
+
testID?: string;
|
|
1593
|
+
/**
|
|
1594
|
+
* All subcomponents receive the configuration schema as a prop.
|
|
1595
|
+
*/
|
|
1596
|
+
schema: Schema<F, O>;
|
|
1597
|
+
}
|
|
1598
|
+
/**
|
|
1599
|
+
* Base interface for selectors and editors.
|
|
1600
|
+
*
|
|
1601
|
+
* @group Props
|
|
1602
|
+
*/
|
|
1603
|
+
interface SelectorOrEditorProps<F extends FullOption = FullField, O extends string = string> extends CommonSubComponentProps<F, O> {
|
|
1604
|
+
value?: string;
|
|
1605
|
+
handleOnChange(value: any): void;
|
|
1606
|
+
}
|
|
1607
|
+
/**
|
|
1608
|
+
* Base interface for selector components.
|
|
1609
|
+
*/
|
|
1610
|
+
interface BaseSelectorProps<OptType extends Option> extends SelectorOrEditorProps<ToFullOption<OptType>> {
|
|
1611
|
+
options: FullOptionList<OptType>;
|
|
1612
|
+
}
|
|
1613
|
+
/**
|
|
1614
|
+
* Props for all `value` selector components.
|
|
1615
|
+
*
|
|
1616
|
+
* @group Props
|
|
1617
|
+
*/
|
|
1618
|
+
interface ValueSelectorProps<OptType extends Option = FullOption> extends BaseSelectorProps<OptType> {
|
|
1619
|
+
multiple?: boolean;
|
|
1620
|
+
listsAsArrays?: boolean;
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Props for `combinatorSelector` components.
|
|
1624
|
+
*
|
|
1625
|
+
* @group Props
|
|
1626
|
+
*/
|
|
1627
|
+
interface CombinatorSelectorProps extends BaseSelectorProps<FullOption> {
|
|
1628
|
+
options: FullOptionList<FullCombinator>;
|
|
1629
|
+
rules: RuleOrGroupArray;
|
|
1630
|
+
ruleGroup: RuleGroupTypeAny;
|
|
1631
|
+
}
|
|
1632
|
+
/**
|
|
1633
|
+
* Props for `fieldSelector` components.
|
|
1634
|
+
*
|
|
1635
|
+
* @group Props
|
|
1636
|
+
*/
|
|
1637
|
+
interface FieldSelectorProps<F extends FullField = FullField> extends BaseSelectorProps<F>, CommonRuleSubComponentProps {
|
|
1638
|
+
operator?: F extends FullField<string, infer OperatorName> ? OperatorName : string;
|
|
1639
|
+
}
|
|
1640
|
+
/**
|
|
1641
|
+
* Props for `matchModeEditor` components.
|
|
1642
|
+
*
|
|
1643
|
+
* @group Props
|
|
1644
|
+
*/
|
|
1645
|
+
interface MatchModeEditorProps extends BaseSelectorProps<FullOption>, CommonRuleSubComponentProps {
|
|
1646
|
+
match: MatchConfig;
|
|
1647
|
+
selectorComponent?: ComponentType<ValueSelectorProps>;
|
|
1648
|
+
numericEditorComponent?: ComponentType<ValueEditorProps>;
|
|
1649
|
+
classNames: {
|
|
1650
|
+
matchMode: string;
|
|
1651
|
+
matchThreshold: string;
|
|
1652
|
+
};
|
|
1653
|
+
options: FullOptionList<FullOption<MatchMode>>;
|
|
1654
|
+
field: string;
|
|
1655
|
+
fieldData: FullField;
|
|
1656
|
+
}
|
|
1657
|
+
/**
|
|
1658
|
+
* Props for `operatorSelector` components.
|
|
1659
|
+
*
|
|
1660
|
+
* @group Props
|
|
1661
|
+
*/
|
|
1662
|
+
interface OperatorSelectorProps extends BaseSelectorProps<FullOption>, CommonRuleSubComponentProps {
|
|
1663
|
+
options: FullOptionList<FullOperator>;
|
|
1664
|
+
field: string;
|
|
1665
|
+
fieldData: FullField;
|
|
1666
|
+
}
|
|
1667
|
+
/**
|
|
1668
|
+
* Props for `valueSourceSelector` components.
|
|
1669
|
+
*
|
|
1670
|
+
* @group Props
|
|
1671
|
+
*/
|
|
1672
|
+
interface ValueSourceSelectorProps extends BaseSelectorProps<FullOption>, CommonRuleSubComponentProps {
|
|
1673
|
+
options: FullOptionList<FullOption<ValueSource>>;
|
|
1674
|
+
field: string;
|
|
1675
|
+
fieldData: FullField;
|
|
1676
|
+
}
|
|
1677
|
+
/**
|
|
1678
|
+
* Utility type representing props for selector components
|
|
1679
|
+
* that could potentially be any of the standard selector types.
|
|
1680
|
+
*
|
|
1681
|
+
* @group Props
|
|
1682
|
+
*/
|
|
1683
|
+
type VersatileSelectorProps = ValueSelectorProps & Partial<FieldSelectorProps> & Partial<OperatorSelectorProps> & Partial<CombinatorSelectorProps>;
|
|
1684
|
+
/**
|
|
1685
|
+
* A translation for a component with `title` and `label`.
|
|
1686
|
+
*
|
|
1687
|
+
* @group Props
|
|
1688
|
+
*/
|
|
1689
|
+
interface TranslationWithLabel extends Translation {
|
|
1690
|
+
label?: ReactNode;
|
|
1691
|
+
}
|
|
1692
|
+
/**
|
|
1693
|
+
* A translation for a component with `title` only.
|
|
1694
|
+
*
|
|
1695
|
+
* @group Props
|
|
1696
|
+
*/
|
|
1697
|
+
interface Translation {
|
|
1698
|
+
title?: string;
|
|
1699
|
+
}
|
|
1700
|
+
/**
|
|
1701
|
+
* Placeholder strings for option lists.
|
|
1702
|
+
*
|
|
1703
|
+
* @group Props
|
|
1704
|
+
*/
|
|
1705
|
+
interface Placeholder {
|
|
1706
|
+
/**
|
|
1707
|
+
* Value for the placeholder field option if autoSelectField is false,
|
|
1708
|
+
* or the placeholder operator option if autoSelectOperator is false.
|
|
1709
|
+
*/
|
|
1710
|
+
placeholderName?: string;
|
|
1711
|
+
/**
|
|
1712
|
+
* Label for the placeholder field option if autoSelectField is false,
|
|
1713
|
+
* or the placeholder operator option if autoSelectOperator is false.
|
|
1714
|
+
*/
|
|
1715
|
+
placeholderLabel?: string;
|
|
1716
|
+
/**
|
|
1717
|
+
* Label for the placeholder field optgroup if autoSelectField is false,
|
|
1718
|
+
* or the placeholder operator optgroup if autoSelectOperator is false.
|
|
1719
|
+
*/
|
|
1720
|
+
placeholderGroupLabel?: string;
|
|
1721
|
+
}
|
|
1722
|
+
/**
|
|
1723
|
+
* A translation for a component with `title` and a placeholder.
|
|
1724
|
+
*
|
|
1725
|
+
* @group Props
|
|
1726
|
+
*/
|
|
1727
|
+
interface TranslationWithPlaceholders extends Translation, Placeholder {}
|
|
1728
|
+
/**
|
|
1729
|
+
* The shape of the `translations` prop.
|
|
1730
|
+
*
|
|
1731
|
+
* @group Props
|
|
1732
|
+
*/
|
|
1733
|
+
interface Translations {
|
|
1734
|
+
fields: TranslationWithPlaceholders;
|
|
1735
|
+
operators: TranslationWithPlaceholders;
|
|
1736
|
+
values: TranslationWithPlaceholders;
|
|
1737
|
+
matchMode: Translation;
|
|
1738
|
+
matchThreshold: Translation;
|
|
1739
|
+
value: Translation;
|
|
1740
|
+
removeRule: TranslationWithLabel;
|
|
1741
|
+
removeGroup: TranslationWithLabel;
|
|
1742
|
+
addRule: TranslationWithLabel;
|
|
1743
|
+
addGroup: TranslationWithLabel;
|
|
1744
|
+
combinators: Translation;
|
|
1745
|
+
notToggle: TranslationWithLabel;
|
|
1746
|
+
cloneRule: TranslationWithLabel;
|
|
1747
|
+
cloneRuleGroup: TranslationWithLabel;
|
|
1748
|
+
shiftActionUp: TranslationWithLabel;
|
|
1749
|
+
shiftActionDown: TranslationWithLabel;
|
|
1750
|
+
dragHandle: TranslationWithLabel;
|
|
1751
|
+
lockRule: TranslationWithLabel;
|
|
1752
|
+
lockGroup: TranslationWithLabel;
|
|
1753
|
+
lockRuleDisabled: TranslationWithLabel;
|
|
1754
|
+
lockGroupDisabled: TranslationWithLabel;
|
|
1755
|
+
valueSourceSelector: Translation;
|
|
1756
|
+
}
|
|
1757
|
+
/**
|
|
1758
|
+
* Props passed to every action component (rendered as `<button>` by default).
|
|
1759
|
+
*
|
|
1760
|
+
* @group Props
|
|
1761
|
+
*/
|
|
1762
|
+
interface ActionProps extends CommonSubComponentProps {
|
|
1763
|
+
/** Visible text. */
|
|
1764
|
+
label?: ReactNode;
|
|
1765
|
+
/**
|
|
1766
|
+
* Triggers the action, e.g. the addition of a new rule or group. The second parameter
|
|
1767
|
+
* will be forwarded to the `onAddRule` or `onAddGroup` callback if appropriate.
|
|
1768
|
+
*/
|
|
1769
|
+
handleOnClick(e?: MouseEvent, context?: any): void;
|
|
1770
|
+
/**
|
|
1771
|
+
* Translation which overrides the regular `label`/`title` props when
|
|
1772
|
+
* the element is disabled.
|
|
1773
|
+
*/
|
|
1774
|
+
disabledTranslation?: TranslationWithLabel;
|
|
1775
|
+
/**
|
|
1776
|
+
* The {@link RuleType} or {@link RuleGroupType}/{@link RuleGroupTypeIC}
|
|
1777
|
+
* associated with this element.
|
|
1778
|
+
*/
|
|
1779
|
+
ruleOrGroup: RuleGroupTypeAny | RuleType;
|
|
1780
|
+
/**
|
|
1781
|
+
* Rules in this group (if the action element is for a group).
|
|
1782
|
+
*/
|
|
1783
|
+
rules?: RuleOrGroupArray;
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* Props for `notToggle` components.
|
|
1787
|
+
*
|
|
1788
|
+
* @group Props
|
|
1789
|
+
*/
|
|
1790
|
+
interface NotToggleProps extends CommonSubComponentProps {
|
|
1791
|
+
checked?: boolean;
|
|
1792
|
+
handleOnChange(checked: boolean): void;
|
|
1793
|
+
label?: ReactNode;
|
|
1794
|
+
ruleGroup: RuleGroupTypeAny;
|
|
1795
|
+
}
|
|
1796
|
+
/**
|
|
1797
|
+
* Props passed to `shiftActions` components.
|
|
1798
|
+
*
|
|
1799
|
+
* @group Props
|
|
1800
|
+
*/
|
|
1801
|
+
interface ShiftActionsProps extends CommonSubComponentProps {
|
|
1802
|
+
/**
|
|
1803
|
+
* Visible text for "shift up"/"shift down" elements.
|
|
1804
|
+
*/
|
|
1805
|
+
labels?: {
|
|
1806
|
+
shiftUp?: ReactNode;
|
|
1807
|
+
shiftDown?: ReactNode;
|
|
1808
|
+
};
|
|
1809
|
+
/**
|
|
1810
|
+
* Tooltips for "shift up"/"shift down" elements.
|
|
1811
|
+
*/
|
|
1812
|
+
titles?: {
|
|
1813
|
+
shiftUp?: string;
|
|
1814
|
+
shiftDown?: string;
|
|
1815
|
+
};
|
|
1816
|
+
/**
|
|
1817
|
+
* The {@link RuleType} or {@link RuleGroupType}/{@link RuleGroupTypeIC}
|
|
1818
|
+
* associated with this element.
|
|
1819
|
+
*/
|
|
1820
|
+
ruleOrGroup: RuleGroupTypeAny | RuleType;
|
|
1821
|
+
/**
|
|
1822
|
+
* Method to shift the rule/group up one place.
|
|
1823
|
+
*/
|
|
1824
|
+
shiftUp?: () => void;
|
|
1825
|
+
/**
|
|
1826
|
+
* Method to shift the rule/group down one place.
|
|
1827
|
+
*/
|
|
1828
|
+
shiftDown?: () => void;
|
|
1829
|
+
/**
|
|
1830
|
+
* Whether shifting the rule/group up is disallowed.
|
|
1831
|
+
*/
|
|
1832
|
+
shiftUpDisabled?: boolean;
|
|
1833
|
+
/**
|
|
1834
|
+
* Whether shifting the rule/group down is disallowed.
|
|
1835
|
+
*/
|
|
1836
|
+
shiftDownDisabled?: boolean;
|
|
1837
|
+
}
|
|
1838
|
+
/**
|
|
1839
|
+
* Props for `dragHandle` components.
|
|
1840
|
+
*
|
|
1841
|
+
* @group Props
|
|
1842
|
+
*/
|
|
1843
|
+
interface DragHandleProps extends CommonSubComponentProps {
|
|
1844
|
+
label?: ReactNode;
|
|
1845
|
+
ruleOrGroup: RuleGroupTypeAny | RuleType;
|
|
1846
|
+
}
|
|
1847
|
+
/**
|
|
1848
|
+
* Props passed to `inlineCombinator` components.
|
|
1849
|
+
*
|
|
1850
|
+
* @group Props
|
|
1851
|
+
*/
|
|
1852
|
+
interface InlineCombinatorProps extends CombinatorSelectorProps {
|
|
1853
|
+
component: ComponentType<CombinatorSelectorProps>;
|
|
1854
|
+
}
|
|
1855
|
+
/**
|
|
1856
|
+
* Props passed to `valueEditor` components.
|
|
1857
|
+
*
|
|
1858
|
+
* @group Props
|
|
1859
|
+
*/
|
|
1860
|
+
interface ValueEditorProps<F extends FullField = FullField, O extends string = string> extends SelectorOrEditorProps<F, O>, CommonRuleSubComponentProps {
|
|
1861
|
+
field: GetOptionIdentifierType<F>;
|
|
1862
|
+
operator: O;
|
|
1863
|
+
value?: any;
|
|
1864
|
+
valueSource: ValueSource;
|
|
1865
|
+
/** The entire {@link FullField} object. */
|
|
1866
|
+
fieldData: F;
|
|
1867
|
+
type?: ValueEditorType;
|
|
1868
|
+
inputType?: InputType | null;
|
|
1869
|
+
values?: any[];
|
|
1870
|
+
listsAsArrays?: boolean;
|
|
1871
|
+
parseNumbers?: ParseNumbersPropConfig;
|
|
1872
|
+
separator?: ReactNode;
|
|
1873
|
+
selectorComponent?: ComponentType<ValueSelectorProps>;
|
|
1874
|
+
/**
|
|
1875
|
+
* Only pass `true` if the {@link useValueEditor} hook has already run
|
|
1876
|
+
* in a parent/ancestor component. See usage in the compatibility packages.
|
|
1877
|
+
*/
|
|
1878
|
+
skipHook?: boolean;
|
|
1879
|
+
schema: Schema<F, O>;
|
|
1880
|
+
}
|
|
1881
|
+
/**
|
|
1882
|
+
* All subcomponents.
|
|
1883
|
+
*
|
|
1884
|
+
* @group Props
|
|
1885
|
+
*/
|
|
1886
|
+
type Controls<F extends FullField, O extends string> = Required<SetNonNullable<ControlElementsProp<F, O>, keyof ControlElementsProp<F, O>>>;
|
|
1887
|
+
/**
|
|
1888
|
+
* Subcomponents.
|
|
1889
|
+
*
|
|
1890
|
+
* @group Props
|
|
1891
|
+
*/
|
|
1892
|
+
type ControlElementsProp<F extends FullField, O extends string> = Partial<{
|
|
1893
|
+
/**
|
|
1894
|
+
* Default component for all button-type controls.
|
|
1895
|
+
*
|
|
1896
|
+
* @default ActionElement
|
|
1897
|
+
*/
|
|
1898
|
+
actionElement: ComponentType<ActionProps>;
|
|
1899
|
+
/**
|
|
1900
|
+
* Adds a sub-group to the current group.
|
|
1901
|
+
*
|
|
1902
|
+
* @default ActionElement
|
|
1903
|
+
*/
|
|
1904
|
+
addGroupAction: ComponentType<ActionProps> | null;
|
|
1905
|
+
/**
|
|
1906
|
+
* Adds a rule to the current group.
|
|
1907
|
+
*
|
|
1908
|
+
* @default ActionElement
|
|
1909
|
+
*/
|
|
1910
|
+
addRuleAction: ComponentType<ActionProps> | null;
|
|
1911
|
+
/**
|
|
1912
|
+
* Clones the current group.
|
|
1913
|
+
*
|
|
1914
|
+
* @default ActionElement
|
|
1915
|
+
*/
|
|
1916
|
+
cloneGroupAction: ComponentType<ActionProps> | null;
|
|
1917
|
+
/**
|
|
1918
|
+
* Clones the current rule.
|
|
1919
|
+
*
|
|
1920
|
+
* @default ActionElement
|
|
1921
|
+
*/
|
|
1922
|
+
cloneRuleAction: ComponentType<ActionProps> | null;
|
|
1923
|
+
/**
|
|
1924
|
+
* Selects the `combinator` property for the current group, or the current independent combinator value.
|
|
1925
|
+
*
|
|
1926
|
+
* @default ValueSelector
|
|
1927
|
+
*/
|
|
1928
|
+
combinatorSelector: ComponentType<CombinatorSelectorProps> | null;
|
|
1929
|
+
/**
|
|
1930
|
+
* Provides a draggable handle for reordering rules and groups.
|
|
1931
|
+
*
|
|
1932
|
+
* @default DragHandle
|
|
1933
|
+
*/
|
|
1934
|
+
dragHandle: ForwardRefExoticComponent<DragHandleProps & RefAttributes<HTMLElement>> | null;
|
|
1935
|
+
/**
|
|
1936
|
+
* Selects the `field` property for the current rule.
|
|
1937
|
+
*
|
|
1938
|
+
* @default ValueSelector
|
|
1939
|
+
*/
|
|
1940
|
+
fieldSelector: ComponentType<FieldSelectorProps<F>> | null;
|
|
1941
|
+
/**
|
|
1942
|
+
* A small wrapper around the `combinatorSelector` component.
|
|
1943
|
+
*
|
|
1944
|
+
* @default InlineCombinator
|
|
1945
|
+
*/
|
|
1946
|
+
inlineCombinator: ComponentType<InlineCombinatorProps> | null;
|
|
1947
|
+
/**
|
|
1948
|
+
* Locks the current group (sets the `disabled` property to `true`).
|
|
1949
|
+
*
|
|
1950
|
+
* @default ActionElement
|
|
1951
|
+
*/
|
|
1952
|
+
lockGroupAction: ComponentType<ActionProps> | null;
|
|
1953
|
+
/**
|
|
1954
|
+
* Locks the current rule (sets the `disabled` property to `true`).
|
|
1955
|
+
*
|
|
1956
|
+
* @default ActionElement
|
|
1957
|
+
*/
|
|
1958
|
+
lockRuleAction: ComponentType<ActionProps> | null;
|
|
1959
|
+
/**
|
|
1960
|
+
* Selects the `match` property for the current rule.
|
|
1961
|
+
*
|
|
1962
|
+
* @default MatchModeEditor
|
|
1963
|
+
*/
|
|
1964
|
+
matchModeEditor: ComponentType<MatchModeEditorProps> | null;
|
|
1965
|
+
/**
|
|
1966
|
+
* Toggles the `not` property of the current group between `true` and `false`.
|
|
1967
|
+
*
|
|
1968
|
+
* @default NotToggle
|
|
1969
|
+
*/
|
|
1970
|
+
notToggle: ComponentType<NotToggleProps> | null;
|
|
1971
|
+
/**
|
|
1972
|
+
* Selects the `operator` property for the current rule.
|
|
1973
|
+
*
|
|
1974
|
+
* @default ValueSelector
|
|
1975
|
+
*/
|
|
1976
|
+
operatorSelector: ComponentType<OperatorSelectorProps> | null;
|
|
1977
|
+
/**
|
|
1978
|
+
* Removes the current group from its parent group's `rules` array.
|
|
1979
|
+
*
|
|
1980
|
+
* @default ActionElement
|
|
1981
|
+
*/
|
|
1982
|
+
removeGroupAction: ComponentType<ActionProps> | null;
|
|
1983
|
+
/**
|
|
1984
|
+
* Removes the current rule from its parent group's `rules` array.
|
|
1985
|
+
*
|
|
1986
|
+
* @default ActionElement
|
|
1987
|
+
*/
|
|
1988
|
+
removeRuleAction: ComponentType<ActionProps> | null;
|
|
1989
|
+
/**
|
|
1990
|
+
* Rule layout component.
|
|
1991
|
+
*
|
|
1992
|
+
* @default Rule
|
|
1993
|
+
*/
|
|
1994
|
+
rule: ComponentType<RuleProps>;
|
|
1995
|
+
/**
|
|
1996
|
+
* Rule group layout component.
|
|
1997
|
+
*
|
|
1998
|
+
* @default RuleGroup
|
|
1999
|
+
*/
|
|
2000
|
+
ruleGroup: ComponentType<RuleGroupProps<F, O>>;
|
|
2001
|
+
/**
|
|
2002
|
+
* Rule group body components.
|
|
2003
|
+
*
|
|
2004
|
+
* @default RuleGroupBodyComponents
|
|
2005
|
+
*/
|
|
2006
|
+
ruleGroupBodyElements: ComponentType<RuleGroupProps & UseRuleGroup>;
|
|
2007
|
+
/**
|
|
2008
|
+
* Rule group header components.
|
|
2009
|
+
*
|
|
2010
|
+
* @default RuleGroupHeaderComponents
|
|
2011
|
+
*/
|
|
2012
|
+
ruleGroupHeaderElements: ComponentType<RuleGroupProps & UseRuleGroup>;
|
|
2013
|
+
/**
|
|
2014
|
+
* Shifts the current rule/group up or down in the query hierarchy.
|
|
2015
|
+
*
|
|
2016
|
+
* @default ShiftActions
|
|
2017
|
+
*/
|
|
2018
|
+
shiftActions: ComponentType<ShiftActionsProps> | null;
|
|
2019
|
+
/**
|
|
2020
|
+
* Updates the `value` property for the current rule.
|
|
2021
|
+
*
|
|
2022
|
+
* @default ValueEditor
|
|
2023
|
+
*/
|
|
2024
|
+
valueEditor: ComponentType<ValueEditorProps<F, O>> | null;
|
|
2025
|
+
/**
|
|
2026
|
+
* Default component for all value selector controls.
|
|
2027
|
+
*
|
|
2028
|
+
* @default ValueSelector
|
|
2029
|
+
*/
|
|
2030
|
+
valueSelector: ComponentType<ValueSelectorProps>;
|
|
2031
|
+
/**
|
|
2032
|
+
* Selects the `valueSource` property for the current rule.
|
|
2033
|
+
*
|
|
2034
|
+
* @default ValueSelector
|
|
2035
|
+
*/
|
|
2036
|
+
valueSourceSelector: ComponentType<ValueSourceSelectorProps> | null;
|
|
2037
|
+
}>;
|
|
2038
|
+
/**
|
|
2039
|
+
* Configuration options passed in the `schema` prop from
|
|
2040
|
+
* {@link QueryBuilder} to each subcomponent.
|
|
2041
|
+
*
|
|
2042
|
+
* @group Props
|
|
2043
|
+
*/
|
|
2044
|
+
interface Schema<F extends FullField, O extends string> {
|
|
2045
|
+
qbId: string;
|
|
2046
|
+
fields: FullOptionList<F>;
|
|
2047
|
+
fieldMap: Partial<Record<GetOptionIdentifierType<F>, F>>;
|
|
2048
|
+
classNames: Classnames;
|
|
2049
|
+
combinators: FullOptionList<FullCombinator>;
|
|
2050
|
+
controls: Controls<F, O>;
|
|
2051
|
+
createRule(): RuleType;
|
|
2052
|
+
createRuleGroup(ic?: boolean): RuleGroupTypeAny;
|
|
2053
|
+
dispatchQuery(query: RuleGroupTypeAny): void;
|
|
2054
|
+
getQuery(): RuleGroupTypeAny;
|
|
2055
|
+
getOperators(field: string, meta: {
|
|
2056
|
+
fieldData: F;
|
|
2057
|
+
}): FullOptionList<FullOperator>;
|
|
2058
|
+
getValueEditorType(field: string, operator: string, meta: {
|
|
2059
|
+
fieldData: F;
|
|
2060
|
+
}): ValueEditorType;
|
|
2061
|
+
getValueEditorSeparator(field: string, operator: string, meta: {
|
|
2062
|
+
fieldData: F;
|
|
2063
|
+
}): ReactNode;
|
|
2064
|
+
getValueSources(field: string, operator: string, meta: {
|
|
2065
|
+
fieldData: F;
|
|
2066
|
+
}): ValueSourceFullOptions;
|
|
2067
|
+
getInputType(field: string, operator: string, meta: {
|
|
2068
|
+
fieldData: F;
|
|
2069
|
+
}): InputType | null;
|
|
2070
|
+
getValues(field: string, operator: string, meta: {
|
|
2071
|
+
fieldData: F;
|
|
2072
|
+
}): FullOptionList<Option>;
|
|
2073
|
+
getMatchModes(field: string, misc: {
|
|
2074
|
+
fieldData: F;
|
|
2075
|
+
}): MatchModeOptions;
|
|
2076
|
+
getSubQueryBuilderProps(field: GetOptionIdentifierType<F>, misc: {
|
|
2077
|
+
fieldData: F;
|
|
2078
|
+
}): QueryBuilderProps<RuleGroupTypeAny, FullOption, FullOption, FullOption>;
|
|
2079
|
+
getRuleClassname(rule: RuleType, misc: {
|
|
2080
|
+
fieldData: F;
|
|
2081
|
+
}): Classname;
|
|
2082
|
+
getRuleGroupClassname(ruleGroup: RuleGroupTypeAny): Classname;
|
|
2083
|
+
accessibleDescriptionGenerator: AccessibleDescriptionGenerator;
|
|
2084
|
+
showCombinatorsBetweenRules: boolean;
|
|
2085
|
+
showNotToggle: boolean;
|
|
2086
|
+
showShiftActions: boolean;
|
|
2087
|
+
showCloneButtons: boolean;
|
|
2088
|
+
showLockButtons: boolean;
|
|
2089
|
+
autoSelectField: boolean;
|
|
2090
|
+
autoSelectOperator: boolean;
|
|
2091
|
+
autoSelectValue: boolean;
|
|
2092
|
+
addRuleToNewGroups: boolean;
|
|
2093
|
+
enableDragAndDrop: boolean;
|
|
2094
|
+
validationMap: ValidationMap;
|
|
2095
|
+
independentCombinators: boolean;
|
|
2096
|
+
listsAsArrays: boolean;
|
|
2097
|
+
parseNumbers: ParseNumbersPropConfig;
|
|
2098
|
+
disabledPaths: Path[];
|
|
2099
|
+
suppressStandardClassnames: boolean;
|
|
2100
|
+
maxLevels: number;
|
|
2101
|
+
}
|
|
2102
|
+
/**
|
|
2103
|
+
* Common props between {@link Rule} and {@link RuleGroup}.
|
|
2104
|
+
*/
|
|
2105
|
+
interface CommonRuleAndGroupProps<F extends FullField = FullField, O extends string = string> {
|
|
2106
|
+
id?: string;
|
|
2107
|
+
path: Path;
|
|
2108
|
+
parentDisabled?: boolean;
|
|
2109
|
+
translations: Translations;
|
|
2110
|
+
schema: Schema<F, O>;
|
|
2111
|
+
actions: QueryActions;
|
|
2112
|
+
disabled?: boolean;
|
|
2113
|
+
shiftUpDisabled?: boolean;
|
|
2114
|
+
shiftDownDisabled?: boolean;
|
|
2115
|
+
context?: any;
|
|
2116
|
+
}
|
|
2117
|
+
/**
|
|
2118
|
+
* Return type of {@link @react-querybuilder/dnd!useRuleGroupDnD} hook.
|
|
2119
|
+
*/
|
|
2120
|
+
interface UseRuleGroupDnD {
|
|
2121
|
+
isDragging: boolean;
|
|
2122
|
+
dragMonitorId: string | symbol;
|
|
2123
|
+
isOver: boolean;
|
|
2124
|
+
dropMonitorId: string | symbol;
|
|
2125
|
+
previewRef: Ref<HTMLDivElement>;
|
|
2126
|
+
dragRef: Ref<HTMLSpanElement>;
|
|
2127
|
+
dropRef: Ref<HTMLDivElement>;
|
|
2128
|
+
/** `"move"` by default; `"copy"` if the modifier key is pressed. */
|
|
2129
|
+
dropEffect?: DropEffect;
|
|
2130
|
+
/** True if the dragged and hovered items should form a new group. */
|
|
2131
|
+
groupItems?: boolean;
|
|
2132
|
+
dropNotAllowed?: boolean;
|
|
2133
|
+
}
|
|
2134
|
+
/**
|
|
2135
|
+
* {@link RuleGroup} props.
|
|
2136
|
+
*
|
|
2137
|
+
* @group Props
|
|
2138
|
+
*/
|
|
2139
|
+
interface RuleGroupProps<F extends FullOption = FullOption, O extends string = string> extends CommonRuleAndGroupProps<F, O>, Partial<UseRuleGroupDnD> {
|
|
2140
|
+
ruleGroup: RuleGroupTypeAny<RuleType<GetOptionIdentifierType<F>, O>>;
|
|
2141
|
+
/**
|
|
2142
|
+
* @deprecated Use the `combinator` property of the `ruleGroup` prop instead
|
|
2143
|
+
*/
|
|
2144
|
+
combinator?: string;
|
|
2145
|
+
/**
|
|
2146
|
+
* @deprecated Use the `rules` property of the `ruleGroup` prop instead
|
|
2147
|
+
*/
|
|
2148
|
+
rules?: RuleOrGroupArray;
|
|
2149
|
+
/**
|
|
2150
|
+
* @deprecated Use the `not` property of the `ruleGroup` prop instead
|
|
2151
|
+
*/
|
|
2152
|
+
not?: boolean;
|
|
2153
|
+
}
|
|
2154
|
+
/**
|
|
2155
|
+
* Return type of {@link @react-querybuilder/dnd!useRuleDnD} hook.
|
|
2156
|
+
*/
|
|
2157
|
+
interface UseRuleDnD {
|
|
2158
|
+
isDragging: boolean;
|
|
2159
|
+
dragMonitorId: string | symbol;
|
|
2160
|
+
isOver: boolean;
|
|
2161
|
+
dropMonitorId: string | symbol;
|
|
2162
|
+
dragRef: Ref<HTMLSpanElement>;
|
|
2163
|
+
dndRef: Ref<HTMLDivElement>;
|
|
2164
|
+
/** `"move"` by default; `"copy"` if the modifier key is pressed. */
|
|
2165
|
+
dropEffect?: DropEffect;
|
|
2166
|
+
/** True if the dragged and hovered items should form a new group. */
|
|
2167
|
+
groupItems?: boolean;
|
|
2168
|
+
dropNotAllowed?: boolean;
|
|
2169
|
+
}
|
|
2170
|
+
/**
|
|
2171
|
+
* {@link Rule} props.
|
|
2172
|
+
*
|
|
2173
|
+
* @group Props
|
|
2174
|
+
*/
|
|
2175
|
+
interface RuleProps<F extends string = string, O extends string = string> extends CommonRuleAndGroupProps<FullOption<F>, O>, Partial<UseRuleDnD> {
|
|
2176
|
+
rule: RuleType<F, O>;
|
|
2177
|
+
/**
|
|
2178
|
+
* @deprecated Use the `field` property of the `rule` prop instead
|
|
2179
|
+
*/
|
|
2180
|
+
field?: string;
|
|
2181
|
+
/**
|
|
2182
|
+
* @deprecated Use the `operator` property of the `rule` prop instead
|
|
2183
|
+
*/
|
|
2184
|
+
operator?: string;
|
|
2185
|
+
/**
|
|
2186
|
+
* @deprecated Use the `value` property of the `rule` prop instead
|
|
2187
|
+
*/
|
|
2188
|
+
value?: any;
|
|
2189
|
+
/**
|
|
2190
|
+
* @deprecated Use the `valueSource` property of the `rule` prop instead
|
|
2191
|
+
*/
|
|
2192
|
+
valueSource?: ValueSource;
|
|
2193
|
+
}
|
|
2194
|
+
/**
|
|
2195
|
+
* Props passed down through context from a {@link QueryBuilderContextProvider}.
|
|
2196
|
+
*
|
|
2197
|
+
* @group Props
|
|
2198
|
+
*/
|
|
2199
|
+
interface QueryBuilderContextProps<F extends FullField, O extends string> {
|
|
2200
|
+
/**
|
|
2201
|
+
* Defines replacement components.
|
|
2202
|
+
*/
|
|
2203
|
+
controlElements?: ControlElementsProp<F, O>;
|
|
2204
|
+
/**
|
|
2205
|
+
* Set to `false` to avoid calling the `onQueryChange` callback
|
|
2206
|
+
* when the component mounts.
|
|
2207
|
+
*
|
|
2208
|
+
* @default true
|
|
2209
|
+
*/
|
|
2210
|
+
enableMountQueryChange?: boolean;
|
|
2211
|
+
/**
|
|
2212
|
+
* This can be used to assign specific CSS classes to various controls
|
|
2213
|
+
* that are rendered by {@link QueryBuilder}.
|
|
2214
|
+
*/
|
|
2215
|
+
controlClassnames?: Partial<Classnames>;
|
|
2216
|
+
/**
|
|
2217
|
+
* This can be used to override translatable texts applied to the various
|
|
2218
|
+
* controls that are rendered by {@link QueryBuilder}.
|
|
2219
|
+
*/
|
|
2220
|
+
translations?: Partial<Translations>;
|
|
2221
|
+
/**
|
|
2222
|
+
* Enables drag-and-drop features.
|
|
2223
|
+
*
|
|
2224
|
+
* @default false
|
|
2225
|
+
*/
|
|
2226
|
+
enableDragAndDrop?: boolean;
|
|
2227
|
+
/**
|
|
2228
|
+
* Enables debug logging for {@link QueryBuilder} (and React DnD when applicable).
|
|
2229
|
+
*
|
|
2230
|
+
* @default false
|
|
2231
|
+
*/
|
|
2232
|
+
debugMode?: boolean;
|
|
2233
|
+
}
|
|
2234
|
+
/**
|
|
2235
|
+
* @group Props
|
|
2236
|
+
*/
|
|
2237
|
+
interface QueryBuilderContextProviderProps extends QueryBuilderContextProps<FullField, string> {
|
|
2238
|
+
children?: ReactNode;
|
|
2239
|
+
}
|
|
2240
|
+
/**
|
|
2241
|
+
* @group Components
|
|
2242
|
+
*/
|
|
2243
|
+
type QueryBuilderContextProvider<ExtraProps extends object = Record<string, any>> = ComponentType<QueryBuilderContextProviderProps & ExtraProps>;
|
|
2244
|
+
/**
|
|
2245
|
+
* Props for {@link QueryBuilder}.
|
|
2246
|
+
*
|
|
2247
|
+
* Notes:
|
|
2248
|
+
* - Only one of `query` or `defaultQuery` should be provided. If `query` is present,
|
|
2249
|
+
* then `defaultQuery` should be undefined and vice versa.
|
|
2250
|
+
* - If rendered initially with a `query` prop, then `query` must be defined in every
|
|
2251
|
+
* subsequent render or warnings will be logged (in non-production modes only).
|
|
2252
|
+
*
|
|
2253
|
+
* @typeParam RG - The type of the query object, inferred from either the `query` or `defaultQuery` prop.
|
|
2254
|
+
* Must extend {@link RuleGroupType} or {@link RuleGroupTypeIC}.
|
|
2255
|
+
* @typeParam F - The field type (see {@link Field}).
|
|
2256
|
+
* @typeParam O - The operator type (see {@link Operator}).
|
|
2257
|
+
* @typeParam C - The combinator type (see {@link Combinator}).
|
|
2258
|
+
*
|
|
2259
|
+
* @group Props
|
|
2260
|
+
*/
|
|
2261
|
+
type QueryBuilderProps<RG extends RuleGroupTypeAny, F extends FullField, O extends FullOperator, C extends FullCombinator> = RG extends RuleGroupType<infer R> | RuleGroupTypeIC<infer R> ? QueryBuilderContextProps<F, GetOptionIdentifierType<O>> & {
|
|
2262
|
+
/**
|
|
2263
|
+
* Initial query object for uncontrolled components.
|
|
2264
|
+
*/
|
|
2265
|
+
defaultQuery?: RG;
|
|
2266
|
+
/**
|
|
2267
|
+
* Query object for controlled components.
|
|
2268
|
+
*/
|
|
2269
|
+
query?: RG;
|
|
2270
|
+
/**
|
|
2271
|
+
* List of valid {@link FullField}s.
|
|
2272
|
+
*
|
|
2273
|
+
* @default []
|
|
2274
|
+
*/
|
|
2275
|
+
fields?: FlexibleOptionListProp<F> | BaseOptionMap<F>;
|
|
2276
|
+
/**
|
|
2277
|
+
* List of valid {@link FullOperator}s.
|
|
2278
|
+
*
|
|
2279
|
+
* @see {@link DefaultOperatorName}
|
|
2280
|
+
*
|
|
2281
|
+
* @default
|
|
2282
|
+
* [
|
|
2283
|
+
* { name: '=', label: '=' },
|
|
2284
|
+
* { name: '!=', label: '!=' },
|
|
2285
|
+
* { name: '<', label: '<' },
|
|
2286
|
+
* { name: '>', label: '>' },
|
|
2287
|
+
* { name: '<=', label: '<=' },
|
|
2288
|
+
* { name: '>=', label: '>=' },
|
|
2289
|
+
* { name: 'contains', label: 'contains' },
|
|
2290
|
+
* { name: 'beginsWith', label: 'begins with' },
|
|
2291
|
+
* { name: 'endsWith', label: 'ends with' },
|
|
2292
|
+
* { name: 'doesNotContain', label: 'does not contain' },
|
|
2293
|
+
* { name: 'doesNotBeginWith', label: 'does not begin with' },
|
|
2294
|
+
* { name: 'doesNotEndWith', label: 'does not end with' },
|
|
2295
|
+
* { name: 'null', label: 'is null' },
|
|
2296
|
+
* { name: 'notNull', label: 'is not null' },
|
|
2297
|
+
* { name: 'in', label: 'in' },
|
|
2298
|
+
* { name: 'notIn', label: 'not in' },
|
|
2299
|
+
* { name: 'between', label: 'between' },
|
|
2300
|
+
* { name: 'notBetween', label: 'not between' },
|
|
2301
|
+
* ]
|
|
2302
|
+
*/
|
|
2303
|
+
operators?: FlexibleOptionListProp<O>;
|
|
2304
|
+
/**
|
|
2305
|
+
* List of valid {@link FullCombinator}s.
|
|
2306
|
+
*
|
|
2307
|
+
* @see {@link DefaultCombinatorName}
|
|
2308
|
+
*
|
|
2309
|
+
* @default
|
|
2310
|
+
* [
|
|
2311
|
+
* {name: 'and', label: 'AND'},
|
|
2312
|
+
* {name: 'or', label: 'OR'},
|
|
2313
|
+
* ]
|
|
2314
|
+
*/
|
|
2315
|
+
combinators?: FlexibleOptionListProp<C>;
|
|
2316
|
+
/**
|
|
2317
|
+
* Default properties applied to all objects in the `fields` prop. Properties on
|
|
2318
|
+
* individual field definitions will override these.
|
|
2319
|
+
*/
|
|
2320
|
+
baseField?: Record<string, unknown>;
|
|
2321
|
+
/**
|
|
2322
|
+
* Default properties applied to all objects in the `operators` prop. Properties on
|
|
2323
|
+
* individual operator definitions will override these.
|
|
2324
|
+
*/
|
|
2325
|
+
baseOperator?: Record<string, unknown>;
|
|
2326
|
+
/**
|
|
2327
|
+
* Default properties applied to all objects in the `combinators` prop. Properties on
|
|
2328
|
+
* individual combinator definitions will override these.
|
|
2329
|
+
*/
|
|
2330
|
+
baseCombinator?: Record<string, unknown>;
|
|
2331
|
+
/**
|
|
2332
|
+
* The default `field` value for new rules. This can be the field `name`
|
|
2333
|
+
* itself or a function that returns a valid {@link FullField} `name` given
|
|
2334
|
+
* the `fields` list.
|
|
2335
|
+
*/
|
|
2336
|
+
getDefaultField?: GetOptionIdentifierType<F> | ((fieldsData: FullOptionList<F>) => string);
|
|
2337
|
+
/**
|
|
2338
|
+
* The default `operator` value for new rules. This can be the operator
|
|
2339
|
+
* `name` or a function that returns a valid {@link FullOperator} `name` for
|
|
2340
|
+
* a given field name.
|
|
2341
|
+
*/
|
|
2342
|
+
getDefaultOperator?: GetOptionIdentifierType<O> | ((field: GetOptionIdentifierType<F>, misc: {
|
|
2343
|
+
fieldData: F;
|
|
2344
|
+
}) => string);
|
|
2345
|
+
/**
|
|
2346
|
+
* Returns the default `value` for new rules.
|
|
2347
|
+
*/
|
|
2348
|
+
getDefaultValue?(rule: R, misc: {
|
|
2349
|
+
fieldData: F;
|
|
2350
|
+
}): any;
|
|
2351
|
+
/**
|
|
2352
|
+
* This function should return the list of allowed {@link FullOperator}s
|
|
2353
|
+
* for the given {@link FullField} `name`. If `null` is returned, the
|
|
2354
|
+
* {@link DefaultOperator}s are used.
|
|
2355
|
+
*/
|
|
2356
|
+
getOperators?(field: GetOptionIdentifierType<F>, misc: {
|
|
2357
|
+
fieldData: F;
|
|
2358
|
+
}): FlexibleOptionListProp<FullOperator> | null;
|
|
2359
|
+
/**
|
|
2360
|
+
* This function should return the type of {@link ValueEditor} (see
|
|
2361
|
+
* {@link ValueEditorType}) for the given field `name` and operator `name`.
|
|
2362
|
+
*/
|
|
2363
|
+
getValueEditorType?(field: GetOptionIdentifierType<F>, operator: GetOptionIdentifierType<O>, misc: {
|
|
2364
|
+
fieldData: F;
|
|
2365
|
+
}): ValueEditorType;
|
|
2366
|
+
/**
|
|
2367
|
+
* This function should return the separator element for a given field
|
|
2368
|
+
* `name` and operator `name`. The element can be any valid React element,
|
|
2369
|
+
* including a bare string (e.g., "and" or "to") or an HTML element like
|
|
2370
|
+
* `<span />`. It will be placed in between value editors when multiple
|
|
2371
|
+
* editors are rendered, such as when the `operator` is `"between"`.
|
|
2372
|
+
*/
|
|
2373
|
+
getValueEditorSeparator?(field: GetOptionIdentifierType<F>, operator: GetOptionIdentifierType<O>, misc: {
|
|
2374
|
+
fieldData: F;
|
|
2375
|
+
}): ReactNode;
|
|
2376
|
+
/**
|
|
2377
|
+
* This function should return the list of valid {@link ValueSources}
|
|
2378
|
+
* for a given field `name` and operator `name`. The return value must
|
|
2379
|
+
* be an array that includes at least one valid {@link ValueSource}
|
|
2380
|
+
* (i.e. `["value"]`, `["field"]`, `["value", "field"]`, or
|
|
2381
|
+
* `["field", "value"]`).
|
|
2382
|
+
*/
|
|
2383
|
+
getValueSources?(field: GetOptionIdentifierType<F>, operator: GetOptionIdentifierType<O>, misc: {
|
|
2384
|
+
fieldData: F;
|
|
2385
|
+
}): ValueSources | ValueSourceFlexibleOptions;
|
|
2386
|
+
/**
|
|
2387
|
+
* This function should return the `type` of `<input />`
|
|
2388
|
+
* for the given field `name` and operator `name` (only applicable when
|
|
2389
|
+
* `getValueEditorType` returns `"text"` or a falsy value). If no
|
|
2390
|
+
* function is provided, `"text"` is used as the default.
|
|
2391
|
+
*/
|
|
2392
|
+
getInputType?(field: GetOptionIdentifierType<F>, operator: GetOptionIdentifierType<O>, misc: {
|
|
2393
|
+
fieldData: F;
|
|
2394
|
+
}): InputType | null;
|
|
2395
|
+
/**
|
|
2396
|
+
* This function should return the list of allowed values for the
|
|
2397
|
+
* given field `name` and operator `name` (only applicable when
|
|
2398
|
+
* `getValueEditorType` returns `"select"` or `"radio"`). If no
|
|
2399
|
+
* function is provided, an empty array is used as the default.
|
|
2400
|
+
*/
|
|
2401
|
+
getValues?(field: GetOptionIdentifierType<F>, operator: GetOptionIdentifierType<O>, misc: {
|
|
2402
|
+
fieldData: F;
|
|
2403
|
+
}): FlexibleOptionListProp<Option>;
|
|
2404
|
+
/**
|
|
2405
|
+
* This function should return the list of valid {@link MatchMode}s or
|
|
2406
|
+
* {@link MatchConfig}s for a given field `name`. The return value must
|
|
2407
|
+
* be an array that includes at least one valid {@link MatchMode}, or `true`
|
|
2408
|
+
* to indicate that all match modes are allowed. Any other return value
|
|
2409
|
+
* will be ignored (no match modes will be allowed).
|
|
2410
|
+
*/
|
|
2411
|
+
getMatchModes?(field: GetOptionIdentifierType<F>, misc: {
|
|
2412
|
+
fieldData: F;
|
|
2413
|
+
}): boolean | MatchMode[] | FlexibleOption<MatchMode>[];
|
|
2414
|
+
/**
|
|
2415
|
+
* This function should return any props that a subquery (see {@link MatchMode})
|
|
2416
|
+
* should override from the props provided to this query builder. Note that certain
|
|
2417
|
+
* props like `query`, `onQueryChange`, and `enableDragAndDrop` will be ignored.
|
|
2418
|
+
*/
|
|
2419
|
+
getSubQueryBuilderProps?(field: GetOptionIdentifierType<F>, misc: {
|
|
2420
|
+
fieldData: F;
|
|
2421
|
+
}): QueryBuilderProps<GenericizeRuleGroupType<RG>, FullOption, FullOption, FullOption>;
|
|
2422
|
+
/**
|
|
2423
|
+
* The return value of this function will be used to apply classnames to the
|
|
2424
|
+
* outer `<div>` of the given {@link Rule}.
|
|
2425
|
+
*/
|
|
2426
|
+
getRuleClassname?(rule: R, misc: {
|
|
2427
|
+
fieldData: F;
|
|
2428
|
+
}): Classname;
|
|
2429
|
+
/**
|
|
2430
|
+
* The return value of this function will be used to apply classnames to the
|
|
2431
|
+
* outer `<div>` of the given {@link RuleGroup}.
|
|
2432
|
+
*/
|
|
2433
|
+
getRuleGroupClassname?(ruleGroup: RG): Classname;
|
|
2434
|
+
/**
|
|
2435
|
+
* This callback is invoked before a new rule is added. The function should either manipulate
|
|
2436
|
+
* the rule and return the new object, return `true` to allow the addition to proceed as normal,
|
|
2437
|
+
* or return `false` to cancel the addition of the rule.
|
|
2438
|
+
*/
|
|
2439
|
+
onAddRule?(rule: R, parentPath: Path, query: RG, context?: any): RuleType | boolean;
|
|
2440
|
+
/**
|
|
2441
|
+
* This callback is invoked before a new group is added. The function should either manipulate
|
|
2442
|
+
* the group and return the new object, return `true` to allow the addition to proceed as normal,
|
|
2443
|
+
* or return `false` to cancel the addition of the group.
|
|
2444
|
+
*/
|
|
2445
|
+
onAddGroup?(ruleGroup: RG, parentPath: Path, query: RG, context?: any): RG | boolean;
|
|
2446
|
+
/**
|
|
2447
|
+
* This callback is invoked before a rule is moved or shifted. The function should return
|
|
2448
|
+
* `true` to allow the move/shift to proceed as normal, `false` to cancel the move/shift, or
|
|
2449
|
+
* a new query object (presumably based on `query` or `nextQuery`) which will become the new
|
|
2450
|
+
* query state.
|
|
2451
|
+
*/
|
|
2452
|
+
onMoveRule?(rule: R, fromPath: Path, toPath: Path | "up" | "down", query: RG, nextQuery: RG, options: MoveOptions, context?: any): RG | boolean;
|
|
2453
|
+
/**
|
|
2454
|
+
* This callback is invoked before a group is moved or shifted. The function should return
|
|
2455
|
+
* `true` to allow the move/shift to proceed as normal, `false` to cancel the move/shift, or
|
|
2456
|
+
* a new query object (presumably based on `query` or `nextQuery`) which will become the new
|
|
2457
|
+
* query state.
|
|
2458
|
+
*/
|
|
2459
|
+
onMoveGroup?(ruleGroup: RG, fromPath: Path, toPath: Path | "up" | "down", query: RG, nextQuery: RG, options: MoveOptions, context?: any): RG | boolean;
|
|
2460
|
+
/**
|
|
2461
|
+
* This callback is invoked before a rule is grouped with another object. The function should
|
|
2462
|
+
* return `true` to allow the grouping to proceed as normal, `false` to cancel the grouping,
|
|
2463
|
+
* or a new query object (presumably based on `query` or `nextQuery`) which will become the new
|
|
2464
|
+
* query state.
|
|
2465
|
+
*/
|
|
2466
|
+
onGroupRule?(rule: R, fromPath: Path, toPath: Path, query: RG, nextQuery: RG, options: GroupOptions, context?: any): RG | boolean;
|
|
2467
|
+
/**
|
|
2468
|
+
* This callback is invoked before a group is grouped with another object. The function should
|
|
2469
|
+
* return `true` to allow the grouping to proceed as normal, `false` to cancel the grouping,
|
|
2470
|
+
* or a new query object (presumably based on `query` or `nextQuery`) which will become the new
|
|
2471
|
+
* query state.
|
|
2472
|
+
*/
|
|
2473
|
+
onGroupGroup?(ruleGroup: RG, fromPath: Path, toPath: Path, query: RG, nextQuery: RG, options: GroupOptions, context?: any): RG | boolean;
|
|
2474
|
+
/**
|
|
2475
|
+
* This callback is invoked before a rule or group is removed. The function should return
|
|
2476
|
+
* `true` if the rule or group should be removed or `false` if it should not be removed.
|
|
2477
|
+
*/
|
|
2478
|
+
onRemove?(ruleOrGroup: R | RG, path: Path, query: RG, context?: any): boolean;
|
|
2479
|
+
/**
|
|
2480
|
+
* This callback is invoked anytime the query state is updated.
|
|
2481
|
+
*/
|
|
2482
|
+
onQueryChange?(query: RG): void;
|
|
2483
|
+
/**
|
|
2484
|
+
* Each log object will be passed to this function when `debugMode` is `true`.
|
|
2485
|
+
*
|
|
2486
|
+
* @default console.log
|
|
2487
|
+
*/
|
|
2488
|
+
onLog?(obj: any): void;
|
|
2489
|
+
/**
|
|
2490
|
+
* Show group combinator selectors in the body of the group, between each child rule/group,
|
|
2491
|
+
* instead of in the group header.
|
|
2492
|
+
*
|
|
2493
|
+
* @default false
|
|
2494
|
+
*/
|
|
2495
|
+
showCombinatorsBetweenRules?: boolean;
|
|
2496
|
+
/**
|
|
2497
|
+
* @deprecated As of v7, this prop is ignored. To enable independent combinators, use
|
|
2498
|
+
* {@link RuleGroupTypeIC} for the `query` or `defaultQuery` prop. The query builder
|
|
2499
|
+
* will detect the query type and behave accordingly.
|
|
2500
|
+
*/
|
|
2501
|
+
independentCombinators?: boolean;
|
|
2502
|
+
/**
|
|
2503
|
+
* Show the "not" (aka inversion) toggle for rule groups.
|
|
2504
|
+
*
|
|
2505
|
+
* @default false
|
|
2506
|
+
*/
|
|
2507
|
+
showNotToggle?: boolean;
|
|
2508
|
+
/**
|
|
2509
|
+
* Show the "Shift up"/"Shift down" actions.
|
|
2510
|
+
*
|
|
2511
|
+
* @default false
|
|
2512
|
+
*/
|
|
2513
|
+
showShiftActions?: boolean;
|
|
2514
|
+
/**
|
|
2515
|
+
* Show the "Clone rule" and "Clone group" buttons.
|
|
2516
|
+
*
|
|
2517
|
+
* @default false
|
|
2518
|
+
*/
|
|
2519
|
+
showCloneButtons?: boolean;
|
|
2520
|
+
/**
|
|
2521
|
+
* Show the "Lock rule" and "Lock group" buttons.
|
|
2522
|
+
*
|
|
2523
|
+
* @default false
|
|
2524
|
+
*/
|
|
2525
|
+
showLockButtons?: boolean;
|
|
2526
|
+
/**
|
|
2527
|
+
* Reset the `operator` and `value` when the `field` changes.
|
|
2528
|
+
*
|
|
2529
|
+
* @default true
|
|
2530
|
+
*/
|
|
2531
|
+
resetOnFieldChange?: boolean;
|
|
2532
|
+
/**
|
|
2533
|
+
* Reset the `value` when the `operator` changes.
|
|
2534
|
+
*
|
|
2535
|
+
* @default false
|
|
2536
|
+
*/
|
|
2537
|
+
resetOnOperatorChange?: boolean;
|
|
2538
|
+
/**
|
|
2539
|
+
* Select the first field in the array automatically.
|
|
2540
|
+
*
|
|
2541
|
+
* @default true
|
|
2542
|
+
*/
|
|
2543
|
+
autoSelectField?: boolean;
|
|
2544
|
+
/**
|
|
2545
|
+
* Select the first operator in the array automatically.
|
|
2546
|
+
*
|
|
2547
|
+
* @default true
|
|
2548
|
+
*/
|
|
2549
|
+
autoSelectOperator?: boolean;
|
|
2550
|
+
/**
|
|
2551
|
+
* Select the first value in the array automatically. Only applicable when the value editor renders a select list.
|
|
2552
|
+
*
|
|
2553
|
+
* @default false
|
|
2554
|
+
*/
|
|
2555
|
+
autoSelectValue?: boolean;
|
|
2556
|
+
/**
|
|
2557
|
+
* Adds a new default rule automatically to each new group.
|
|
2558
|
+
*
|
|
2559
|
+
* @default false
|
|
2560
|
+
*/
|
|
2561
|
+
addRuleToNewGroups?: boolean;
|
|
2562
|
+
/**
|
|
2563
|
+
* Store list-type values as native arrays instead of comma-separated strings.
|
|
2564
|
+
*
|
|
2565
|
+
* @default false
|
|
2566
|
+
*/
|
|
2567
|
+
listsAsArrays?: boolean;
|
|
2568
|
+
/**
|
|
2569
|
+
* Store values as numbers whenever possible.
|
|
2570
|
+
*
|
|
2571
|
+
* _**TIP: Try `"strict-limited"` first.**_
|
|
2572
|
+
*
|
|
2573
|
+
* Options include `true`, `false`, `"enhanced"`, `"native"`, and `"strict"`. The `string` options
|
|
2574
|
+
* can be suffixed with `"-limited"`.
|
|
2575
|
+
*
|
|
2576
|
+
* - `false` avoids numeric parsing
|
|
2577
|
+
* - `true` or `"strict"` parses values using `numeric-quantity`, bailing out (returning the original
|
|
2578
|
+
* string) when trailing invalid characters are present
|
|
2579
|
+
* - `"enhanced"` is the same as `true`/`"strict"`, but ignores trailing invalid characters (CAUTION:
|
|
2580
|
+
* this can lead to information loss)
|
|
2581
|
+
* - `"native"` parses values using `parseFloat`, returning `NaN` when parsing fails
|
|
2582
|
+
*
|
|
2583
|
+
* When the value is `true` or a string without the "-limited" suffix, the default {@link ValueEditor}
|
|
2584
|
+
* will attempt to parse *all* inputs as numbers. **CAUTION: This can lead to unexpected behavior.**
|
|
2585
|
+
*
|
|
2586
|
+
* When the value is a string with the "-limited" suffix, the default {@link ValueEditor} will
|
|
2587
|
+
* only attempt to parse inputs as numbers when the `inputType` is `"number"`.
|
|
2588
|
+
*
|
|
2589
|
+
* @default false
|
|
2590
|
+
*/
|
|
2591
|
+
parseNumbers?: ParseNumbersPropConfig;
|
|
2592
|
+
/**
|
|
2593
|
+
* Disables the entire query builder if true, or the rules and groups at
|
|
2594
|
+
* the specified paths (as well as all child rules/groups and subcomponents)
|
|
2595
|
+
* if an array of paths is provided. If the root path is specified (`disabled={[[]]}`),
|
|
2596
|
+
* no changes to the query are allowed.
|
|
2597
|
+
*
|
|
2598
|
+
* @default false
|
|
2599
|
+
*/
|
|
2600
|
+
disabled?: boolean | Path[];
|
|
2601
|
+
/**
|
|
2602
|
+
* Query validation function.
|
|
2603
|
+
*/
|
|
2604
|
+
validator?: QueryValidator;
|
|
2605
|
+
/**
|
|
2606
|
+
* `id` generator function. Should always produce a unique/random value.
|
|
2607
|
+
*
|
|
2608
|
+
* @default crypto.randomUUID
|
|
2609
|
+
*/
|
|
2610
|
+
idGenerator?: () => string;
|
|
2611
|
+
/**
|
|
2612
|
+
* Generator function for the `title` attribute applied to the outermost `<div>` of each
|
|
2613
|
+
* rule group. As this is intended to help with accessibility, the text output from this
|
|
2614
|
+
* function should be meaningful, descriptive, and unique within the page.
|
|
2615
|
+
*/
|
|
2616
|
+
accessibleDescriptionGenerator?: AccessibleDescriptionGenerator;
|
|
2617
|
+
/**
|
|
2618
|
+
* Prevent _any_ assignment of standard classes to elements. This includes conditional
|
|
2619
|
+
* and event-based classes for validation, drag-and-drop, etc.
|
|
2620
|
+
*/
|
|
2621
|
+
suppressStandardClassnames?: boolean;
|
|
2622
|
+
/**
|
|
2623
|
+
* Maximum number of levels deep the query is allowed to go. The minimum is 1; values
|
|
2624
|
+
* less than 1 will be ignored.
|
|
2625
|
+
*/
|
|
2626
|
+
maxLevels?: number;
|
|
2627
|
+
/**
|
|
2628
|
+
* Container for custom props that are passed to all components.
|
|
2629
|
+
*/
|
|
2630
|
+
context?: any;
|
|
2631
|
+
} : never;
|
|
2632
|
+
//#endregion
|
|
2633
|
+
//#region src/AntDActionElement.d.ts
|
|
2634
|
+
type RemoveDataIndexKeys<T> = { [K in keyof T as `data-${string}` extends K ? never : K]: T[K] };
|
|
2635
|
+
/**
|
|
2636
|
+
* @group Props
|
|
2637
|
+
*/
|
|
2638
|
+
interface AntDActionProps extends ActionProps, RemoveDataIndexKeys<ComponentPropsWithoutRef<typeof Button>> {}
|
|
2639
|
+
/**
|
|
2640
|
+
* @group Components
|
|
2641
|
+
*/
|
|
2642
|
+
declare const AntDActionElement: ({
|
|
2643
|
+
className,
|
|
2644
|
+
handleOnClick,
|
|
2645
|
+
label,
|
|
2646
|
+
title,
|
|
2647
|
+
disabled,
|
|
2648
|
+
disabledTranslation,
|
|
2649
|
+
testID: _testID,
|
|
2650
|
+
level: _level,
|
|
2651
|
+
path: _path,
|
|
2652
|
+
context: _context,
|
|
2653
|
+
validation: _validation,
|
|
2654
|
+
ruleOrGroup: _ruleOrGroup,
|
|
2655
|
+
schema: _schema,
|
|
2656
|
+
...extraProps
|
|
2657
|
+
}: AntDActionProps) => React.JSX.Element;
|
|
2658
|
+
//#endregion
|
|
2659
|
+
//#region src/AntDDragHandle.d.ts
|
|
2660
|
+
/**
|
|
2661
|
+
* @group Props
|
|
2662
|
+
*/
|
|
2663
|
+
type AntDDragHandleProps = DragHandleProps & {
|
|
2664
|
+
label?: any;
|
|
2665
|
+
} & ComponentPropsWithRef<typeof HolderOutlined>;
|
|
2666
|
+
/**
|
|
2667
|
+
* @group Components
|
|
2668
|
+
*/
|
|
2669
|
+
declare const AntDDragHandle: React.ForwardRefExoticComponent<Omit<AntDDragHandleProps, "ref"> & React.RefAttributes<HTMLSpanElement>>;
|
|
2670
|
+
//#endregion
|
|
2671
|
+
//#region src/AntDNotToggle.d.ts
|
|
2672
|
+
/**
|
|
2673
|
+
* @group Props
|
|
2674
|
+
*/
|
|
2675
|
+
interface AntDNotToggleProps extends NotToggleProps, ComponentPropsWithoutRef<typeof Switch> {}
|
|
2676
|
+
/**
|
|
2677
|
+
* @group Components
|
|
2678
|
+
*/
|
|
2679
|
+
declare const AntDNotToggle: ({
|
|
2680
|
+
className,
|
|
2681
|
+
handleOnChange,
|
|
2682
|
+
label,
|
|
2683
|
+
checked,
|
|
2684
|
+
title,
|
|
2685
|
+
disabled,
|
|
2686
|
+
path: _path,
|
|
2687
|
+
context: _context,
|
|
2688
|
+
validation: _validation,
|
|
2689
|
+
testID: _testID,
|
|
2690
|
+
schema: _schema,
|
|
2691
|
+
ruleGroup: _ruleGroup,
|
|
2692
|
+
...extraProps
|
|
2693
|
+
}: AntDNotToggleProps) => React.JSX.Element;
|
|
2694
|
+
//#endregion
|
|
2695
|
+
//#region src/AntDShiftActions.d.ts
|
|
2696
|
+
/**
|
|
2697
|
+
* @group Components
|
|
2698
|
+
*/
|
|
2699
|
+
declare const AntDShiftActions: ({
|
|
2700
|
+
shiftUp,
|
|
2701
|
+
shiftDown,
|
|
2702
|
+
shiftUpDisabled,
|
|
2703
|
+
shiftDownDisabled,
|
|
2704
|
+
disabled,
|
|
2705
|
+
className,
|
|
2706
|
+
labels,
|
|
2707
|
+
titles,
|
|
2708
|
+
testID
|
|
2709
|
+
}: ShiftActionsProps) => React.JSX.Element;
|
|
2710
|
+
//#endregion
|
|
2711
|
+
//#region src/AntDValueEditor.d.ts
|
|
2712
|
+
/**
|
|
2713
|
+
* @group Props
|
|
2714
|
+
*/
|
|
2715
|
+
interface AntDValueEditorProps extends ValueEditorProps {
|
|
2716
|
+
extraProps?: Record<string, unknown>;
|
|
2717
|
+
}
|
|
2718
|
+
/**
|
|
2719
|
+
* @group Components
|
|
2720
|
+
*/
|
|
2721
|
+
declare const AntDValueEditor: (allProps: AntDValueEditorProps) => React.JSX.Element | null;
|
|
2722
|
+
//#endregion
|
|
2723
|
+
//#region src/AntDValueSelector.d.ts
|
|
2724
|
+
/**
|
|
2725
|
+
* @group Props
|
|
2726
|
+
*/
|
|
2727
|
+
type AntDValueSelectorProps = VersatileSelectorProps & Omit<ComponentPropsWithoutRef<typeof Select>, "onChange" | "defaultValue">;
|
|
2728
|
+
/**
|
|
2729
|
+
* @group Components
|
|
2730
|
+
*/
|
|
2731
|
+
declare const AntDValueSelector: ({
|
|
2732
|
+
className,
|
|
2733
|
+
handleOnChange,
|
|
2734
|
+
options,
|
|
2735
|
+
value,
|
|
2736
|
+
title,
|
|
2737
|
+
disabled,
|
|
2738
|
+
multiple,
|
|
2739
|
+
listsAsArrays,
|
|
2740
|
+
testID: _testID,
|
|
2741
|
+
rule: _rule,
|
|
2742
|
+
ruleGroup: _ruleGroup,
|
|
2743
|
+
rules: _rules,
|
|
2744
|
+
level: _level,
|
|
2745
|
+
path: _path,
|
|
2746
|
+
context: _context,
|
|
2747
|
+
validation: _validation,
|
|
2748
|
+
operator: _operator,
|
|
2749
|
+
field: _field,
|
|
2750
|
+
fieldData: _fieldData,
|
|
2751
|
+
schema: _schema,
|
|
2752
|
+
...extraProps
|
|
2753
|
+
}: AntDValueSelectorProps) => React.JSX.Element;
|
|
2754
|
+
//#endregion
|
|
2755
|
+
//#region src/index.d.ts
|
|
2756
|
+
/**
|
|
2757
|
+
* @group Props
|
|
2758
|
+
*/
|
|
2759
|
+
declare const antdControlElements: ControlElementsProp<FullField, string>;
|
|
2760
|
+
/**
|
|
2761
|
+
* @group Props
|
|
2762
|
+
*/
|
|
2763
|
+
declare const antdTranslations: Partial<Translations>;
|
|
2764
|
+
/**
|
|
2765
|
+
* @group Components
|
|
2766
|
+
*/
|
|
2767
|
+
declare const QueryBuilderAntD: QueryBuilderContextProvider;
|
|
2768
|
+
//#endregion
|
|
2769
|
+
export { AntDActionElement, AntDActionProps, AntDDragHandle, AntDDragHandleProps, AntDNotToggle, AntDNotToggleProps, AntDShiftActions, AntDValueEditor, AntDValueEditorProps, AntDValueSelector, AntDValueSelectorProps, QueryBuilderAntD, antdControlElements, antdTranslations };
|
|
2770
|
+
//# sourceMappingURL=react-querybuilder_antd.d.mts.map
|