@react-querybuilder/core 8.21.2 → 8.22.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/README.md +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +1399 -44
- package/dist/cjs/react-querybuilder_core.cjs.development.js +2244 -87
- package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +1399 -44
- package/dist/cjs/react-querybuilder_core.cjs.production.js +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.js.map +1 -1
- package/dist/formatQuery.js +47 -38
- package/dist/formatQuery.js.map +1 -1
- package/dist/formatQuery.mjs +47 -38
- package/dist/formatQuery.mjs.map +1 -1
- package/dist/parseCEL.js +6 -8
- package/dist/parseCEL.js.map +1 -1
- package/dist/parseCEL.mjs +6 -8
- package/dist/parseCEL.mjs.map +1 -1
- package/dist/parseCypher.js.map +1 -1
- package/dist/parseJSONata.js +2 -2
- package/dist/parseJSONata.js.map +1 -1
- package/dist/parseJSONata.mjs +1 -1
- package/dist/parseJsonLogic.js +3 -3
- package/dist/parseJsonLogic.js.map +1 -1
- package/dist/parseJsonLogic.mjs +3 -3
- package/dist/parseJsonLogic.mjs.map +1 -1
- package/dist/parseMongoDB.js +2 -2
- package/dist/parseMongoDB.mjs +2 -2
- package/dist/parseSPARQL.js +0 -1
- package/dist/parseSPARQL.js.map +1 -1
- package/dist/parseSPARQL.mjs +0 -1
- package/dist/parseSPARQL.mjs.map +1 -1
- package/dist/parseSQL.js +54 -62
- package/dist/parseSQL.js.map +1 -1
- package/dist/parseSQL.mjs +54 -62
- package/dist/parseSQL.mjs.map +1 -1
- package/dist/parseSpEL.js +3 -3
- package/dist/parseSpEL.js.map +1 -1
- package/dist/parseSpEL.mjs +3 -3
- package/dist/parseSpEL.mjs.map +1 -1
- package/dist/{prepareQueryObjects-C5dHLhnC.js → prepareQueryObjects-BnGL91Tt.js} +9 -5
- package/dist/{prepareQueryObjects-C5dHLhnC.js.map → prepareQueryObjects-BnGL91Tt.js.map} +1 -1
- package/dist/{prepareQueryObjects-9emVAGYG.mjs → prepareQueryObjects-ChINDIap.mjs} +9 -5
- package/dist/{prepareQueryObjects-9emVAGYG.mjs.map → prepareQueryObjects-ChINDIap.mjs.map} +1 -1
- package/dist/query-builder-layout.css +1 -1
- package/dist/query-builder-layout.css.map +1 -1
- package/dist/query-builder.css +1 -1
- package/dist/query-builder.css.map +1 -1
- package/dist/react-querybuilder_core.d.mts +1399 -44
- package/dist/react-querybuilder_core.legacy-esm.d.ts +1399 -44
- package/dist/react-querybuilder_core.legacy-esm.js +2266 -81
- package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
- package/dist/react-querybuilder_core.mjs +2202 -89
- package/dist/react-querybuilder_core.mjs.map +1 -1
- package/dist/react-querybuilder_core.production.d.mts +1399 -44
- package/dist/react-querybuilder_core.production.mjs +1 -1
- package/dist/react-querybuilder_core.production.mjs.map +1 -1
- package/dist/styles/_layout.scss +5 -2
- package/dist/{utils-CxWs-N47.mjs → utils-4k-j5FBa.mjs} +4 -2
- package/dist/utils-4k-j5FBa.mjs.map +1 -0
- package/dist/{utils-SchkzSCN.js → utils-C79dxwZb.js} +4 -2
- package/dist/utils-C79dxwZb.js.map +1 -0
- package/package.json +9 -8
- package/dist/utils-CxWs-N47.mjs.map +0 -1
- package/dist/utils-SchkzSCN.js.map +0 -1
|
@@ -2445,6 +2445,32 @@ type NLTranslationKey = "and" | "or" | "true" | "false" | "ruleSeparator" | "bet
|
|
|
2445
2445
|
*/
|
|
2446
2446
|
type NLTranslations = Partial<Record<NLTranslationKey, string>>;
|
|
2447
2447
|
//#endregion
|
|
2448
|
+
//#region src/types/history.d.ts
|
|
2449
|
+
/**
|
|
2450
|
+
* Options controlling how query changes are recorded for undo/redo.
|
|
2451
|
+
*
|
|
2452
|
+
* Shared by the `react-querybuilder/history` entry point and the
|
|
2453
|
+
* {@link index!QueryManager QueryManager} utility.
|
|
2454
|
+
*/
|
|
2455
|
+
interface QueryHistoryOptions {
|
|
2456
|
+
/**
|
|
2457
|
+
* Maximum number of undo steps to retain. Older entries are discarded.
|
|
2458
|
+
*
|
|
2459
|
+
* @default 50
|
|
2460
|
+
*/
|
|
2461
|
+
maxHistory?: number;
|
|
2462
|
+
/**
|
|
2463
|
+
* Consecutive changes to the same property of the same rule within this many milliseconds
|
|
2464
|
+
* are merged into a single undo step, so that (for example) typing a multi-character value
|
|
2465
|
+
* produces one history entry rather than one per keystroke.
|
|
2466
|
+
*
|
|
2467
|
+
* Set to `0` to record every change separately.
|
|
2468
|
+
*
|
|
2469
|
+
* @default 500
|
|
2470
|
+
*/
|
|
2471
|
+
coalesceMs?: number;
|
|
2472
|
+
}
|
|
2473
|
+
//#endregion
|
|
2448
2474
|
//#region src/types/queryBuilder.d.ts
|
|
2449
2475
|
/**
|
|
2450
2476
|
* Base interface for all rule subcomponents.
|
|
@@ -2536,6 +2562,18 @@ interface Classnames {
|
|
|
2536
2562
|
* Classnames applied to the `<span>` handle for dragging rules/groups.
|
|
2537
2563
|
*/
|
|
2538
2564
|
shiftActions: Classname;
|
|
2565
|
+
/**
|
|
2566
|
+
* Classname(s) to be applied to the undo/redo actions container.
|
|
2567
|
+
*/
|
|
2568
|
+
undoRedoActions: Classname;
|
|
2569
|
+
/**
|
|
2570
|
+
* Classname(s) to be applied to the "undo" button.
|
|
2571
|
+
*/
|
|
2572
|
+
undoAction: Classname;
|
|
2573
|
+
/**
|
|
2574
|
+
* Classname(s) to be applied to the "redo" button.
|
|
2575
|
+
*/
|
|
2576
|
+
redoAction: Classname;
|
|
2539
2577
|
/**
|
|
2540
2578
|
* Classnames applied to the `<span>` handle for dragging rules/groups.
|
|
2541
2579
|
*/
|
|
@@ -2710,6 +2748,8 @@ interface BaseTranslations<LabelType = string> {
|
|
|
2710
2748
|
cloneRuleGroup: BaseTranslationWithLabel<LabelType>;
|
|
2711
2749
|
shiftActionUp: BaseTranslationWithLabel<LabelType>;
|
|
2712
2750
|
shiftActionDown: BaseTranslationWithLabel<LabelType>;
|
|
2751
|
+
undo: BaseTranslationWithLabel<LabelType>;
|
|
2752
|
+
redo: BaseTranslationWithLabel<LabelType>;
|
|
2713
2753
|
dragHandle: BaseTranslationWithLabel<LabelType>;
|
|
2714
2754
|
lockRule: BaseTranslationWithLabel<LabelType>;
|
|
2715
2755
|
lockGroup: BaseTranslationWithLabel<LabelType>;
|
|
@@ -2749,6 +2789,18 @@ interface QueryBuilderFlags {
|
|
|
2749
2789
|
* @default true
|
|
2750
2790
|
*/
|
|
2751
2791
|
enableMountQueryChange?: boolean;
|
|
2792
|
+
/**
|
|
2793
|
+
* By default, when the last `QueryBuilder` component using a given `qbId` unmounts, its
|
|
2794
|
+
* query is removed from the internal Redux store. Set this to `true` to retain the query
|
|
2795
|
+
* state after unmount, which allows a subsequent `QueryBuilder` with the same `qbId` to
|
|
2796
|
+
* pick up where the previous one left off.
|
|
2797
|
+
*
|
|
2798
|
+
* Only meaningful in conjunction with an explicit `qbId` prop, since automatically generated
|
|
2799
|
+
* `qbId`s are never reused.
|
|
2800
|
+
*
|
|
2801
|
+
* @default false
|
|
2802
|
+
*/
|
|
2803
|
+
preserveQueryStateOnUnmount?: boolean;
|
|
2752
2804
|
/**
|
|
2753
2805
|
* Enables drag-and-drop features.
|
|
2754
2806
|
*
|
|
@@ -2780,6 +2832,16 @@ interface QueryBuilderFlags {
|
|
|
2780
2832
|
* @default false
|
|
2781
2833
|
*/
|
|
2782
2834
|
showShiftActions?: boolean;
|
|
2835
|
+
/**
|
|
2836
|
+
* Show the "Undo"/"Redo" actions in the header of the outermost group.
|
|
2837
|
+
*
|
|
2838
|
+
* Requires the `QueryBuilderHistory` component from `react-querybuilder/history`, which
|
|
2839
|
+
* provides the controls and records the history they navigate. Defaults to `true` when a
|
|
2840
|
+
* `QueryBuilderHistory` ancestor is present (pass `false` explicitly to opt out).
|
|
2841
|
+
*
|
|
2842
|
+
* @default false
|
|
2843
|
+
*/
|
|
2844
|
+
showUndoRedo?: boolean;
|
|
2783
2845
|
/**
|
|
2784
2846
|
* Show the "Clone rule" and "Clone group" buttons.
|
|
2785
2847
|
*
|
|
@@ -3018,6 +3080,9 @@ declare const standardClassnames: {
|
|
|
3018
3080
|
readonly valid: "queryBuilder-valid";
|
|
3019
3081
|
readonly invalid: "queryBuilder-invalid";
|
|
3020
3082
|
readonly shiftActions: "shiftActions";
|
|
3083
|
+
readonly undoRedoActions: "undoRedoActions";
|
|
3084
|
+
readonly undoAction: "undoRedoActions-undo";
|
|
3085
|
+
readonly redoAction: "undoRedoActions-redo";
|
|
3021
3086
|
readonly dndDragging: "dndDragging";
|
|
3022
3087
|
readonly dndOver: "dndOver";
|
|
3023
3088
|
readonly dndCopy: "dndCopy";
|
|
@@ -3078,6 +3143,9 @@ declare const TestID: {
|
|
|
3078
3143
|
readonly valueEditor: "value-editor";
|
|
3079
3144
|
readonly notToggle: "not-toggle";
|
|
3080
3145
|
readonly shiftActions: "shift-actions";
|
|
3146
|
+
readonly undoRedoActions: "undo-redo-actions";
|
|
3147
|
+
readonly undoAction: "undo-action";
|
|
3148
|
+
readonly redoAction: "redo-action";
|
|
3081
3149
|
readonly dragHandle: "drag-handle";
|
|
3082
3150
|
readonly lockRule: "lock-rule";
|
|
3083
3151
|
readonly lockGroup: "lock-group";
|
|
@@ -3116,6 +3184,19 @@ declare const rootPath: Path;
|
|
|
3116
3184
|
* @group Defaults
|
|
3117
3185
|
*/
|
|
3118
3186
|
declare const queryBuilderFlagDefaults: Required<QueryBuilderFlags>;
|
|
3187
|
+
/**
|
|
3188
|
+
* Default maximum number of undo steps retained by query history.
|
|
3189
|
+
*
|
|
3190
|
+
* @group Defaults
|
|
3191
|
+
*/
|
|
3192
|
+
declare const defaultMaxHistory = 50;
|
|
3193
|
+
/**
|
|
3194
|
+
* Default time window (in milliseconds) within which consecutive changes to the same
|
|
3195
|
+
* property of the same rule are coalesced into a single undo step.
|
|
3196
|
+
*
|
|
3197
|
+
* @group Defaults
|
|
3198
|
+
*/
|
|
3199
|
+
declare const defaultCoalesceMs = 500;
|
|
3119
3200
|
//#endregion
|
|
3120
3201
|
//#region src/utils/arrayUtils.d.ts
|
|
3121
3202
|
/**
|
|
@@ -3204,6 +3285,119 @@ declare function convertQuery(query: RuleGroupType): RuleGroupTypeIC;
|
|
|
3204
3285
|
*/
|
|
3205
3286
|
declare function convertQuery(query: RuleGroupTypeIC): RuleGroupType;
|
|
3206
3287
|
//#endregion
|
|
3288
|
+
//#region src/utils/deriveClassNames.d.ts
|
|
3289
|
+
/** Classname keys that have both a standard class and a `controlClassnames` entry. */
|
|
3290
|
+
type StandardClassnameKey = keyof typeof standardClassnames & keyof Classnames;
|
|
3291
|
+
/**
|
|
3292
|
+
* A classname applied only when `when` returns true for the current state.
|
|
3293
|
+
*
|
|
3294
|
+
* `key` is used to look up both the standard classname and the corresponding `controlClassnames`
|
|
3295
|
+
* entry. Set `standardOnly` when the standard class is conditional but no custom class
|
|
3296
|
+
* corresponds to it.
|
|
3297
|
+
*/
|
|
3298
|
+
interface ClassnameCondition<S> {
|
|
3299
|
+
key: StandardClassnameKey;
|
|
3300
|
+
when: (state: S) => boolean | undefined;
|
|
3301
|
+
standardOnly?: boolean;
|
|
3302
|
+
}
|
|
3303
|
+
/**
|
|
3304
|
+
* How one derived classname is composed: the `controlClassnames` keys that contribute to it (in
|
|
3305
|
+
* application order, after the standard classname), plus any state-dependent classes.
|
|
3306
|
+
*/
|
|
3307
|
+
interface ClassnameSpec<S> {
|
|
3308
|
+
sources: readonly (keyof Classnames)[];
|
|
3309
|
+
conditions?: readonly ClassnameCondition<S>[];
|
|
3310
|
+
}
|
|
3311
|
+
/** Keys of the `classNames` object returned for a rule. */
|
|
3312
|
+
type RuleClassnameKey = "shiftActions" | "dragHandle" | "fields" | "matchMode" | "matchThreshold" | "operators" | "valueSource" | "value" | "cloneRule" | "lockRule" | "muteRule" | "removeRule" | "valueListItem";
|
|
3313
|
+
/** Keys of the `classNames` object returned for a rule group. */
|
|
3314
|
+
type RuleGroupClassnameKey = "header" | "shiftActions" | "undoRedoActions" | "undoAction" | "redoAction" | "dragHandle" | "combinators" | "notToggle" | "addRule" | "addGroup" | "cloneGroup" | "lockGroup" | "muteGroup" | "removeGroup" | "body";
|
|
3315
|
+
/** Drag-and-drop state that can contribute conditional classnames. */
|
|
3316
|
+
interface DndClassNameState {
|
|
3317
|
+
isDragging?: boolean;
|
|
3318
|
+
isOver?: boolean;
|
|
3319
|
+
dropEffect?: "move" | "copy";
|
|
3320
|
+
groupItems?: boolean;
|
|
3321
|
+
dropNotAllowed?: boolean;
|
|
3322
|
+
}
|
|
3323
|
+
/** State that contributes conditional classnames to a rule's wrapper element. */
|
|
3324
|
+
interface RuleClassNameState extends DndClassNameState {
|
|
3325
|
+
disabled?: boolean;
|
|
3326
|
+
muted?: boolean;
|
|
3327
|
+
hasSubQuery?: boolean;
|
|
3328
|
+
}
|
|
3329
|
+
/** State that contributes conditional classnames to the query builder's wrapper element. */
|
|
3330
|
+
interface QueryBuilderClassNameState {
|
|
3331
|
+
disabled?: boolean;
|
|
3332
|
+
validationResult?: boolean | ValidationMap;
|
|
3333
|
+
}
|
|
3334
|
+
/** Options common to every classname derivation. */
|
|
3335
|
+
interface DeriveClassNamesOptions {
|
|
3336
|
+
/** The merged `controlClassnames` for the query builder. */
|
|
3337
|
+
classNames: Partial<Classnames> | undefined;
|
|
3338
|
+
/** When `true`, standard (`rule`, `ruleGroup-*`, etc.) classnames are omitted. */
|
|
3339
|
+
suppressStandardClassnames?: boolean;
|
|
3340
|
+
}
|
|
3341
|
+
/**
|
|
3342
|
+
* Classnames for each element rendered by a rule. This is the framework-agnostic core of the
|
|
3343
|
+
* `classNames` object returned by the `useRule` hook.
|
|
3344
|
+
*
|
|
3345
|
+
* @group Query Tools
|
|
3346
|
+
*/
|
|
3347
|
+
declare const deriveRuleClassNames: (options: DeriveClassNamesOptions) => Record<RuleClassnameKey, string>;
|
|
3348
|
+
/**
|
|
3349
|
+
* The classname for a single element of a rule, composed from the same table as
|
|
3350
|
+
* {@link deriveRuleClassNames}. Useful where only one is needed, such as the items of a
|
|
3351
|
+
* multi-value editor.
|
|
3352
|
+
*
|
|
3353
|
+
* @group Query Tools
|
|
3354
|
+
*/
|
|
3355
|
+
declare const deriveRuleClassName: (key: RuleClassnameKey, options: DeriveClassNamesOptions) => string;
|
|
3356
|
+
/**
|
|
3357
|
+
* Classnames for each element rendered by a rule group, including its conditionally-classed
|
|
3358
|
+
* `header`. This is the framework-agnostic core of the `classNames` object returned by the
|
|
3359
|
+
* `useRuleGroup` hook.
|
|
3360
|
+
*
|
|
3361
|
+
* @group Query Tools
|
|
3362
|
+
*/
|
|
3363
|
+
declare const deriveRuleGroupClassNames: (options: DeriveClassNamesOptions & DndClassNameState) => Record<RuleGroupClassnameKey, string>;
|
|
3364
|
+
/** Inputs common to every outer (wrapper) classname derivation. */
|
|
3365
|
+
interface OuterClassNameOptionsBase extends DeriveClassNamesOptions {
|
|
3366
|
+
/**
|
|
3367
|
+
* Classnames contributed by the rule or group itself and its configuration, applied first.
|
|
3368
|
+
* For a rule that is the rule/field/operator classnames; for a group, the group and combinator
|
|
3369
|
+
* classnames.
|
|
3370
|
+
*/
|
|
3371
|
+
leadingClassNames?: (Classname | null)[];
|
|
3372
|
+
/** Appended last, as produced by `getValidationClassNames`. */
|
|
3373
|
+
validationClassName?: Classname;
|
|
3374
|
+
}
|
|
3375
|
+
/** Inputs to {@link deriveRuleOuterClassName} and {@link deriveRuleGroupOuterClassName}. */
|
|
3376
|
+
interface OuterClassNameOptions extends OuterClassNameOptionsBase, RuleClassNameState {}
|
|
3377
|
+
/**
|
|
3378
|
+
* The outer (wrapper) classname for a rule, including every conditional state class.
|
|
3379
|
+
*
|
|
3380
|
+
* @group Query Tools
|
|
3381
|
+
*/
|
|
3382
|
+
declare const deriveRuleOuterClassName: (options: OuterClassNameOptions) => string;
|
|
3383
|
+
/**
|
|
3384
|
+
* The outer (wrapper) classname for a rule group, including every conditional state class.
|
|
3385
|
+
*
|
|
3386
|
+
* A group reflects fewer drag-and-drop states than a rule—`dndOver`, `dndCopy`,
|
|
3387
|
+
* `dndDropNotAllowed`, and `hasSubQuery` do not apply—so this is not interchangeable with
|
|
3388
|
+
* {@link deriveRuleOuterClassName}.
|
|
3389
|
+
*
|
|
3390
|
+
* @group Query Tools
|
|
3391
|
+
*/
|
|
3392
|
+
declare const deriveRuleGroupOuterClassName: (options: OuterClassNameOptions) => string;
|
|
3393
|
+
/**
|
|
3394
|
+
* The outer (wrapper) classname for the query builder itself, including the conditional
|
|
3395
|
+
* `disabled`, `valid`, and `invalid` state classes.
|
|
3396
|
+
*
|
|
3397
|
+
* @group Query Tools
|
|
3398
|
+
*/
|
|
3399
|
+
declare const deriveQueryBuilderClassNames: (options: OuterClassNameOptionsBase & QueryBuilderClassNameState) => string;
|
|
3400
|
+
//#endregion
|
|
3207
3401
|
//#region src/utils/defaultValidator.d.ts
|
|
3208
3402
|
/**
|
|
3209
3403
|
* This is an example validation function you can pass to {@link react-querybuilder!QueryBuilder QueryBuilder} in the
|
|
@@ -3212,6 +3406,229 @@ declare function convertQuery(query: RuleGroupTypeIC): RuleGroupType;
|
|
|
3212
3406
|
*/
|
|
3213
3407
|
declare const defaultValidator: QueryValidator;
|
|
3214
3408
|
//#endregion
|
|
3409
|
+
//#region src/utils/deriveRuleContext.d.ts
|
|
3410
|
+
/**
|
|
3411
|
+
* Functions used by {@link deriveRuleContext} to resolve a rule's configuration. Each corresponds
|
|
3412
|
+
* to the `QueryBuilder` prop (or `useQueryBuilderSetup` output) of the same name.
|
|
3413
|
+
*/
|
|
3414
|
+
interface RuleContextResolvers<F extends FullField = FullField> {
|
|
3415
|
+
fields: OptionList<F>;
|
|
3416
|
+
fieldMap: Partial<FullOptionRecord<FullField>>;
|
|
3417
|
+
getInputType: (field: string, operator: string, misc: {
|
|
3418
|
+
fieldData: F;
|
|
3419
|
+
}) => InputType | null;
|
|
3420
|
+
getMatchModes: (field: string, misc: {
|
|
3421
|
+
fieldData: F;
|
|
3422
|
+
}) => MatchModeOptions;
|
|
3423
|
+
getOperators: (field: string, misc: {
|
|
3424
|
+
fieldData: F;
|
|
3425
|
+
}) => OptionList<FullOperator>;
|
|
3426
|
+
getParameters: (field: string, operator: string, misc: {
|
|
3427
|
+
fieldData: F;
|
|
3428
|
+
}) => FlexibleOptionList<Option>;
|
|
3429
|
+
getValueEditorType: (field: string, operator: string, misc: {
|
|
3430
|
+
fieldData: F;
|
|
3431
|
+
}) => ValueEditorType;
|
|
3432
|
+
getValues: (field: string, operator: string, misc: {
|
|
3433
|
+
fieldData: F;
|
|
3434
|
+
}) => FlexibleOptionList<Option>;
|
|
3435
|
+
getValueSources: (field: string, operator: string, misc: {
|
|
3436
|
+
fieldData: F;
|
|
3437
|
+
}) => ValueSourceFullOptions;
|
|
3438
|
+
getSubQueryBuilderProps?: (field: string, misc: {
|
|
3439
|
+
fieldData: F;
|
|
3440
|
+
}) => Record<string, unknown>;
|
|
3441
|
+
}
|
|
3442
|
+
/**
|
|
3443
|
+
* Everything {@link deriveRuleContext} resolves for a single rule.
|
|
3444
|
+
*/
|
|
3445
|
+
interface RuleContext<F extends FullField = FullField> {
|
|
3446
|
+
fieldData: F;
|
|
3447
|
+
hideValueControls: boolean;
|
|
3448
|
+
inputType: InputType | null;
|
|
3449
|
+
matchModes: MatchModeOptions;
|
|
3450
|
+
operatorObject: FullOperator | undefined;
|
|
3451
|
+
operators: OptionList<FullOperator>;
|
|
3452
|
+
parameters: FlexibleOptionList<Option> | null;
|
|
3453
|
+
validationResult: boolean | ValidationResult;
|
|
3454
|
+
valueEditorType: ValueEditorType;
|
|
3455
|
+
values: FlexibleOptionList<Option>;
|
|
3456
|
+
valueSourceOptions: ValueSourceFullOptions;
|
|
3457
|
+
valueSources: ValueSources;
|
|
3458
|
+
subQueryBuilderProps: Record<string, unknown>;
|
|
3459
|
+
}
|
|
3460
|
+
/**
|
|
3461
|
+
* Resolves the field configuration for a rule's `field`, falling back to a minimal option object
|
|
3462
|
+
* when the field isn't present in the field map.
|
|
3463
|
+
*/
|
|
3464
|
+
declare const getFieldData: (field: string, fieldMap: Partial<FullOptionRecord<FullField>>) => FullField;
|
|
3465
|
+
/**
|
|
3466
|
+
* The input type for a rule. A field's own `inputType` takes precedence over `getInputType`.
|
|
3467
|
+
*/
|
|
3468
|
+
declare const getRuleInputType: <F extends FullField = FullField>(field: string, operator: string, fieldData: F, getInputType: RuleContextResolvers<F>["getInputType"]) => InputType | null;
|
|
3469
|
+
/**
|
|
3470
|
+
* Whether the value editor(s) should be hidden for an operator, based on its `arity`.
|
|
3471
|
+
*/
|
|
3472
|
+
declare const hideValueControlsForOperator: (operatorObject?: FullOperator) => boolean;
|
|
3473
|
+
/**
|
|
3474
|
+
* The subset of a rule that determines its configuration. Accepting only these properties (rather
|
|
3475
|
+
* than the whole rule) lets React callers keep granular memoization dependencies, so editing a
|
|
3476
|
+
* rule's `value` doesn't recompute its operators, value sources, or option lists.
|
|
3477
|
+
*/
|
|
3478
|
+
type RuleFacet = Pick<RuleType, "field" | "operator" | "valueSource">;
|
|
3479
|
+
/**
|
|
3480
|
+
* Value source options for a rule. A `valueSource` present on the rule but absent from the
|
|
3481
|
+
* configured list is appended, so the current selection is always representable.
|
|
3482
|
+
*/
|
|
3483
|
+
declare const getRuleValueSourceOptions: <F extends FullField = FullField>(rule: RuleFacet, fieldData: F, getValueSources: RuleContextResolvers<F>["getValueSources"]) => ValueSourceFullOptions;
|
|
3484
|
+
/**
|
|
3485
|
+
* Normalizes the result of `getParameters` to a non-empty list or `null`.
|
|
3486
|
+
*/
|
|
3487
|
+
declare const getParametersAsList: (parameters: FlexibleOptionList<Option>) => FlexibleOptionList<Option> | null;
|
|
3488
|
+
/**
|
|
3489
|
+
* The value editor type for a rule. `valueSource: "field"` always uses a select list, and
|
|
3490
|
+
* `valueSource: "parameter"` uses a (multi)select when parameters are available.
|
|
3491
|
+
*/
|
|
3492
|
+
declare const getRuleValueEditorType: <F extends FullField = FullField>(rule: RuleFacet, fieldData: F, parametersAsList: FlexibleOptionList<Option> | null, getValueEditorType: RuleContextResolvers<F>["getValueEditorType"]) => ValueEditorType;
|
|
3493
|
+
/**
|
|
3494
|
+
* The option list presented by a rule's value editor, resolved from its `valueSource`.
|
|
3495
|
+
*/
|
|
3496
|
+
declare const getRuleValues: <F extends FullField = FullField>(rule: RuleFacet, fieldData: F, fields: OptionList<F>, parametersAsList: FlexibleOptionList<Option> | null, getValues: RuleContextResolvers<F>["getValues"]) => FlexibleOptionList<Option>;
|
|
3497
|
+
/**
|
|
3498
|
+
* The validation result for a rule: the entry from a query-level {@link ValidationMap} if present,
|
|
3499
|
+
* otherwise the field's own `validator` result, otherwise `null`.
|
|
3500
|
+
*/
|
|
3501
|
+
declare const getRuleValidationResult: (rule: RuleType, fieldData: FullField, validationMap?: ValidationMap, id?: string) => boolean | ValidationResult;
|
|
3502
|
+
/**
|
|
3503
|
+
* Resolves everything about a single rule that depends on the field/operator configuration:
|
|
3504
|
+
* its field data, operators, value editor type, value list, value sources, match modes, and
|
|
3505
|
+
* validation result.
|
|
3506
|
+
*
|
|
3507
|
+
* This is the framework-agnostic core of the `useRule` hook, shared with
|
|
3508
|
+
* {@link QueryManager.getRuleContext} so that non-React implementations derive identical results.
|
|
3509
|
+
* It performs no memoization; callers are responsible for caching as appropriate.
|
|
3510
|
+
*
|
|
3511
|
+
* @group Query Tools
|
|
3512
|
+
*/
|
|
3513
|
+
declare const deriveRuleContext: <F extends FullField = FullField>(rule: RuleType, resolvers: RuleContextResolvers<F>, options?: {
|
|
3514
|
+
validationMap?: ValidationMap;
|
|
3515
|
+
id?: string;
|
|
3516
|
+
}) => RuleContext<F>;
|
|
3517
|
+
/**
|
|
3518
|
+
* Everything {@link deriveRuleGroupContext} resolves for a single rule group.
|
|
3519
|
+
*/
|
|
3520
|
+
interface RuleGroupContext<C extends FullCombinator = FullCombinator> {
|
|
3521
|
+
combinator: string;
|
|
3522
|
+
combinatorObject: C | undefined;
|
|
3523
|
+
combinators: FullOptionList<C>;
|
|
3524
|
+
/** The `className` of the selected combinator, or `null` for independent combinators. */
|
|
3525
|
+
combinatorBasedClassName: Classname | null;
|
|
3526
|
+
independentCombinators: boolean;
|
|
3527
|
+
validationResult: boolean | ValidationResult;
|
|
3528
|
+
}
|
|
3529
|
+
/**
|
|
3530
|
+
* The effective combinator for a group: its own `combinator` when it has one, otherwise the
|
|
3531
|
+
* first configured combinator (which is the case for groups with independent combinators).
|
|
3532
|
+
*
|
|
3533
|
+
* This intentionally covers only the current property-based API. The `RuleGroup` component
|
|
3534
|
+
* additionally falls back to its deprecated `combinator` prop; that fallback stays in the hook.
|
|
3535
|
+
*/
|
|
3536
|
+
declare const getRuleGroupCombinator: <C extends FullCombinator = FullCombinator>(ruleGroup: RuleGroupTypeAny, combinators: FullOptionList<C>) => string;
|
|
3537
|
+
/**
|
|
3538
|
+
* Resolves everything about a rule group that depends on the combinator configuration, plus its
|
|
3539
|
+
* validation result.
|
|
3540
|
+
*
|
|
3541
|
+
* Note that unlike {@link deriveRuleContext}, there is no field-level validator fallback—a
|
|
3542
|
+
* group's validation result comes only from the query-level {@link ValidationMap}.
|
|
3543
|
+
*
|
|
3544
|
+
* @group Query Tools
|
|
3545
|
+
*/
|
|
3546
|
+
declare const deriveRuleGroupContext: <C extends FullCombinator = FullCombinator>(ruleGroup: RuleGroupTypeAny, combinators: FullOptionList<C>, options?: {
|
|
3547
|
+
validationMap?: ValidationMap;
|
|
3548
|
+
id?: string;
|
|
3549
|
+
}) => RuleGroupContext<C>;
|
|
3550
|
+
//#endregion
|
|
3551
|
+
//#region src/utils/deriveValueEditor.d.ts
|
|
3552
|
+
/**
|
|
3553
|
+
* Whether an operator's value is a list of two bounds.
|
|
3554
|
+
*
|
|
3555
|
+
* @group Value Editors
|
|
3556
|
+
*/
|
|
3557
|
+
declare const isBetweenOperator: (operator: string) => boolean;
|
|
3558
|
+
/**
|
|
3559
|
+
* Determines whether a rule's `value` needs to be collapsed to a single element because it no
|
|
3560
|
+
* longer represents a list, and what it should become.
|
|
3561
|
+
*
|
|
3562
|
+
* This happens when the value is an array (or a comma-containing string in a `number` input,
|
|
3563
|
+
* which `<input type="number">` can't display) while the operator is not one of the multi-value
|
|
3564
|
+
* operators and the editor is not a multiselect—typically right after the operator changes from
|
|
3565
|
+
* `"in"` or `"between"` to something else.
|
|
3566
|
+
*
|
|
3567
|
+
* The React `useValueEditor` hook applies the result in an effect; other implementations may
|
|
3568
|
+
* apply it wherever is idiomatic.
|
|
3569
|
+
*
|
|
3570
|
+
* @group Value Editors
|
|
3571
|
+
*/
|
|
3572
|
+
declare const getValueEditorReset: ({ skipHook, type, operator, value, inputType }: {
|
|
3573
|
+
skipHook?: boolean;
|
|
3574
|
+
type?: string;
|
|
3575
|
+
operator: string;
|
|
3576
|
+
value: unknown;
|
|
3577
|
+
inputType?: InputType | null;
|
|
3578
|
+
}) => {
|
|
3579
|
+
reset: boolean;
|
|
3580
|
+
value: unknown;
|
|
3581
|
+
};
|
|
3582
|
+
/**
|
|
3583
|
+
* Produces the next value for a series of value editors when the editor at `index` changes.
|
|
3584
|
+
*
|
|
3585
|
+
* For `between`/`notBetween`, editing the first bound guarantees an array of at least two
|
|
3586
|
+
* elements, seeding the second from the first available option. The result is a comma-joined
|
|
3587
|
+
* string unless `listsAsArrays` is `true`.
|
|
3588
|
+
*
|
|
3589
|
+
* @group Value Editors
|
|
3590
|
+
*/
|
|
3591
|
+
declare const getMultiValueUpdate: ({ value, index, valueAsArray, operator, values, listsAsArrays, parseNumberMethod }: {
|
|
3592
|
+
value: unknown;
|
|
3593
|
+
index: number;
|
|
3594
|
+
valueAsArray: unknown[];
|
|
3595
|
+
operator: string;
|
|
3596
|
+
values?: any[];
|
|
3597
|
+
listsAsArrays?: boolean;
|
|
3598
|
+
parseNumberMethod?: ParseNumberMethod;
|
|
3599
|
+
}) => unknown;
|
|
3600
|
+
/**
|
|
3601
|
+
* Coerces a value to a `bigint`, falling back to the parsed number when it can't be represented
|
|
3602
|
+
* as one (an empty string or a decimal, for example).
|
|
3603
|
+
*
|
|
3604
|
+
* @group Value Editors
|
|
3605
|
+
*/
|
|
3606
|
+
declare const coerceBigIntValue: (value: unknown, parseNumberMethod?: ParseNumberMethod) => unknown;
|
|
3607
|
+
/**
|
|
3608
|
+
* The `type` attribute an `<input>` should use for a rule. `bigint` values and the `in`/`notIn`
|
|
3609
|
+
* operators (whose value is a comma-separated list) both require a text input.
|
|
3610
|
+
*
|
|
3611
|
+
* @group Value Editors
|
|
3612
|
+
*/
|
|
3613
|
+
declare const coerceInputType: (inputType: InputType | null | undefined, operator: string) => InputType;
|
|
3614
|
+
/**
|
|
3615
|
+
* Produces the next value for a value selector. Multiselect values are normalized to an array
|
|
3616
|
+
* first, then comma-joined unless `listsAsArrays` is `true`. Single-select values pass through.
|
|
3617
|
+
*
|
|
3618
|
+
* @group Value Editors
|
|
3619
|
+
*/
|
|
3620
|
+
declare const getValueSelectorUpdate: (value: string | string[], { multiple, listsAsArrays }?: {
|
|
3621
|
+
multiple?: boolean;
|
|
3622
|
+
listsAsArrays?: boolean;
|
|
3623
|
+
}) => string | string[];
|
|
3624
|
+
/**
|
|
3625
|
+
* Normalizes a value selector's current value for display. Multiselect values become an array of
|
|
3626
|
+
* strings so they match option names, which are always strings (e.g. `[42]` becomes `["42"]`).
|
|
3627
|
+
*
|
|
3628
|
+
* @group Value Editors
|
|
3629
|
+
*/
|
|
3630
|
+
declare const normalizeValueSelectorValue: (value: unknown, multiple?: boolean) => any;
|
|
3631
|
+
//#endregion
|
|
3215
3632
|
//#region src/utils/filterFieldsByComparator.d.ts
|
|
3216
3633
|
/**
|
|
3217
3634
|
* For a given {@link FullField}, returns the `fields` list filtered for
|
|
@@ -4155,7 +4572,7 @@ interface GetRuleDefaultValueOptions<F extends FullField = FullField> {
|
|
|
4155
4572
|
*
|
|
4156
4573
|
* @group Option Lists
|
|
4157
4574
|
*/
|
|
4158
|
-
declare const getRuleDefaultValue: <F extends FullField = FullField>(rule: RuleType, options: GetRuleDefaultValueOptions<F>) => unknown;
|
|
4575
|
+
declare const getRuleDefaultValue$1: <F extends FullField = FullField>(rule: RuleType, options: GetRuleDefaultValueOptions<F>) => unknown;
|
|
4159
4576
|
//#endregion
|
|
4160
4577
|
//#region src/utils/getValidationClassNames.d.ts
|
|
4161
4578
|
/**
|
|
@@ -4264,6 +4681,85 @@ declare const objectEntries: <Type extends Record<PropertyKey, unknown>>(value:
|
|
|
4264
4681
|
*/
|
|
4265
4682
|
declare const isUnsafeKey: (key: unknown) => boolean;
|
|
4266
4683
|
//#endregion
|
|
4684
|
+
//#region src/utils/optionResolvers.d.ts
|
|
4685
|
+
/**
|
|
4686
|
+
* Options shared by the resolvers below that produce a normalized option list.
|
|
4687
|
+
*/
|
|
4688
|
+
interface ResolveOptionListOptions {
|
|
4689
|
+
/**
|
|
4690
|
+
* Prepended as an empty placeholder option when `autoSelectOption` is `false`. Supplied by the
|
|
4691
|
+
* `translations` prop in React; omit it where translations don't apply.
|
|
4692
|
+
*/
|
|
4693
|
+
placeholder?: Placeholder;
|
|
4694
|
+
/** Properties applied to every option in the resulting list. */
|
|
4695
|
+
baseOption?: Record<string, unknown>;
|
|
4696
|
+
/** When `false`, an empty placeholder option is prepended. */
|
|
4697
|
+
autoSelectOption?: boolean;
|
|
4698
|
+
}
|
|
4699
|
+
/**
|
|
4700
|
+
* Resolves the operator list for a field, applying the same precedence as the `QueryBuilder`
|
|
4701
|
+
* component: the field's own `operators`, then the `getOperators` callback, then the
|
|
4702
|
+
* query-level operator list.
|
|
4703
|
+
*
|
|
4704
|
+
* @group Option Lists
|
|
4705
|
+
*/
|
|
4706
|
+
declare const resolveOperatorList: <F extends FullField = FullField, O extends FullOperator = FullOperator>({ field, fieldData, getOperators, operators, placeholder, baseOption, autoSelectOption }: {
|
|
4707
|
+
field: string;
|
|
4708
|
+
fieldData: F;
|
|
4709
|
+
getOperators?: (field: string, misc: {
|
|
4710
|
+
fieldData: F;
|
|
4711
|
+
}) => FlexibleOptionList<O> | null;
|
|
4712
|
+
operators: FullOptionList<O>;
|
|
4713
|
+
} & ResolveOptionListOptions) => FullOptionList<O>;
|
|
4714
|
+
/**
|
|
4715
|
+
* Resolves the default operator for a field, applying the same precedence as the `QueryBuilder`
|
|
4716
|
+
* component: the field's own `defaultOperator`, then the `getDefaultOperator` option (a string or
|
|
4717
|
+
* a function), then the first available operator.
|
|
4718
|
+
*
|
|
4719
|
+
* @group Option Lists
|
|
4720
|
+
*/
|
|
4721
|
+
declare const resolveDefaultOperator: <F extends FullField = FullField>({ field, fieldData, getDefaultOperator, getOperators }: {
|
|
4722
|
+
field: string;
|
|
4723
|
+
fieldData: F;
|
|
4724
|
+
getDefaultOperator?: string | ((field: string, misc: {
|
|
4725
|
+
fieldData: F;
|
|
4726
|
+
}) => string);
|
|
4727
|
+
/** Produces the operator list for the field, i.e. {@link resolveOperatorList} already bound. */
|
|
4728
|
+
getOperators: (field: string, misc: {
|
|
4729
|
+
fieldData: F;
|
|
4730
|
+
}) => FullOptionList<FullOperator>;
|
|
4731
|
+
}) => string;
|
|
4732
|
+
/**
|
|
4733
|
+
* Resolves the value editor type for a field/operator pair, applying the same precedence as the
|
|
4734
|
+
* `QueryBuilder` component: the field's own `valueEditorType` (a string or a function of the
|
|
4735
|
+
* operator), then the `getValueEditorType` callback, then `"text"`.
|
|
4736
|
+
*
|
|
4737
|
+
* @group Option Lists
|
|
4738
|
+
*/
|
|
4739
|
+
declare const resolveValueEditorType: <F extends FullField = FullField>({ field, operator, fieldData, getValueEditorType }: {
|
|
4740
|
+
field: string;
|
|
4741
|
+
operator: string;
|
|
4742
|
+
fieldData: F;
|
|
4743
|
+
getValueEditorType?: (field: string, operator: string, misc: {
|
|
4744
|
+
fieldData: F;
|
|
4745
|
+
}) => ValueEditorType;
|
|
4746
|
+
}) => ValueEditorType;
|
|
4747
|
+
/**
|
|
4748
|
+
* Resolves the value option list for a field/operator pair, applying the same precedence as the
|
|
4749
|
+
* `QueryBuilder` component: the field's own `values`, then the `getValues` callback, then an
|
|
4750
|
+
* empty list.
|
|
4751
|
+
*
|
|
4752
|
+
* @group Option Lists
|
|
4753
|
+
*/
|
|
4754
|
+
declare const resolveValueList: <F extends FullField = FullField>({ field, operator, fieldData, getValues, placeholder, baseOption, autoSelectOption }: {
|
|
4755
|
+
field: string;
|
|
4756
|
+
operator: string;
|
|
4757
|
+
fieldData: F;
|
|
4758
|
+
getValues?: (field: string, operator: string, misc: {
|
|
4759
|
+
fieldData: F;
|
|
4760
|
+
}) => FlexibleOptionList<Option> | null;
|
|
4761
|
+
} & ResolveOptionListOptions) => FullOptionList<Option>;
|
|
4762
|
+
//#endregion
|
|
4267
4763
|
//#region src/utils/optGroupUtils.d.ts
|
|
4268
4764
|
/**
|
|
4269
4765
|
* Converts an {@link Option} or {@link ValueOption} (i.e., {@link BaseOption})
|
|
@@ -4456,6 +4952,29 @@ declare const getCommonAncestorPath: (path1: Path, path2: Path) => Path;
|
|
|
4456
4952
|
* or disabled by an ancestor group.
|
|
4457
4953
|
*/
|
|
4458
4954
|
declare const pathIsDisabled: (path: Path, query: RuleGroupTypeAny) => boolean;
|
|
4955
|
+
/**
|
|
4956
|
+
* Determines if the rule or group at the specified path is disabled by `disabledPaths`—the array
|
|
4957
|
+
* form of the `QueryBuilder` `disabled` prop, which disables nodes by position rather than by a
|
|
4958
|
+
* `disabled` property on the node itself. A path is disabled if it appears in `disabledPaths` or
|
|
4959
|
+
* descends from a path that does.
|
|
4960
|
+
*
|
|
4961
|
+
* @group Paths
|
|
4962
|
+
*/
|
|
4963
|
+
declare const pathIsDisabledByPaths: (path: Path, disabledPaths?: Path[]) => boolean;
|
|
4964
|
+
/** The path of a child rule or group, and whether it is disabled. */ interface PathInfo {
|
|
4965
|
+
path: Path;
|
|
4966
|
+
disabled: boolean;
|
|
4967
|
+
}
|
|
4968
|
+
/**
|
|
4969
|
+
* Builds the {@link PathInfo} for each child of a group at `path`. A child is disabled if its
|
|
4970
|
+
* parent is disabled or if its own path appears in `disabledPaths`.
|
|
4971
|
+
*
|
|
4972
|
+
* @group Paths
|
|
4973
|
+
*/
|
|
4974
|
+
declare const derivePathInfo: (path: Path, childCount: number, { disabled, disabledPaths }?: {
|
|
4975
|
+
disabled?: boolean;
|
|
4976
|
+
disabledPaths?: Path[];
|
|
4977
|
+
}) => PathInfo[];
|
|
4459
4978
|
//#endregion
|
|
4460
4979
|
//#region src/utils/preferProp.d.ts
|
|
4461
4980
|
/**
|
|
@@ -4494,39 +5013,232 @@ declare const prepareRuleGroup: <RG extends RuleGroupTypeAny>(queryObject: RG, {
|
|
|
4494
5013
|
* Ensures that a rule or group is valid. See {@link prepareRule} and {@link prepareRuleGroup}.
|
|
4495
5014
|
*/
|
|
4496
5015
|
declare const prepareRuleOrGroup: (rg: RuleGroupTypeAny | RuleType, { idGenerator }?: PreparerOptions) => RuleGroupType | RuleGroupTypeIC | RuleType;
|
|
5016
|
+
/**
|
|
5017
|
+
* Resolves the query a query builder should render from the available sources, in precedence
|
|
5018
|
+
* order: the controlled `query`, then whatever is already in the store, then the uncontrolled
|
|
5019
|
+
* `defaultQuery`, then a freshly created empty group.
|
|
5020
|
+
*
|
|
5021
|
+
* The result is prepared with {@link prepareRuleGroup} unless it already has an `id`, which is
|
|
5022
|
+
* taken to mean it has been prepared before—most often because the caller is passing back the
|
|
5023
|
+
* object it received from `onQueryChange`.
|
|
5024
|
+
*
|
|
5025
|
+
* @group Query Tools
|
|
5026
|
+
*/
|
|
5027
|
+
declare const resolveCandidateQuery: <RG extends RuleGroupTypeAny>(sources: {
|
|
5028
|
+
query?: RG;
|
|
5029
|
+
storeQuery?: RG;
|
|
5030
|
+
defaultQuery?: RG;
|
|
5031
|
+
fallbackQuery: RG;
|
|
5032
|
+
}, options?: {
|
|
5033
|
+
idGenerator?: () => string;
|
|
5034
|
+
}) => RG;
|
|
4497
5035
|
//#endregion
|
|
4498
|
-
//#region src/utils/
|
|
5036
|
+
//#region src/utils/queryActions.d.ts
|
|
4499
5037
|
/**
|
|
4500
|
-
*
|
|
5038
|
+
* Confirmation callbacks invoked before a mutation is applied. Their return values are
|
|
5039
|
+
* interpreted differently depending on the operation:
|
|
5040
|
+
*
|
|
5041
|
+
* - `onAddRule`/`onAddGroup` may return `true` to proceed, a falsy value to cancel, or a
|
|
5042
|
+
* _replacement rule/group_ to add instead of the one provided.
|
|
5043
|
+
* - `onMoveRule`/`onMoveGroup`/`onGroupRule`/`onGroupGroup` may return `true` to proceed, a
|
|
5044
|
+
* falsy value to cancel, or a _replacement query_ to apply instead of the computed one.
|
|
5045
|
+
* - `onRemove` is boolean only.
|
|
4501
5046
|
*
|
|
4502
5047
|
* @group Query Tools
|
|
4503
5048
|
*/
|
|
4504
|
-
interface
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
5049
|
+
interface QueryActionCallbacks {
|
|
5050
|
+
onAddRule?: (rule: RuleType, parentPath: Path, query: any, context?: any) => RuleType | boolean;
|
|
5051
|
+
onAddGroup?: (ruleGroup: any, parentPath: Path, query: any, context?: any) => RuleGroupTypeAny | boolean;
|
|
5052
|
+
onRemove?: (ruleOrGroup: any, path: Path, query: any, context?: any) => boolean;
|
|
5053
|
+
onMoveRule?: (...args: any[]) => RuleGroupTypeAny | boolean;
|
|
5054
|
+
onMoveGroup?: (...args: any[]) => RuleGroupTypeAny | boolean;
|
|
5055
|
+
onGroupRule?: (...args: any[]) => RuleGroupTypeAny | boolean;
|
|
5056
|
+
onGroupGroup?: (...args: any[]) => RuleGroupTypeAny | boolean;
|
|
5057
|
+
}
|
|
5058
|
+
/**
|
|
5059
|
+
* Configuration for {@link createQueryActions}.
|
|
5060
|
+
*
|
|
5061
|
+
* @group Query Tools
|
|
5062
|
+
*/
|
|
5063
|
+
interface QueryActionsConfig extends QueryActionCallbacks {
|
|
5064
|
+
/** Identifier included in every log payload. */
|
|
5065
|
+
qbId?: string;
|
|
4511
5066
|
combinators?: OptionList;
|
|
5067
|
+
idGenerator?: () => string;
|
|
5068
|
+
/** The maximum depth at which groups may be added. Defaults to `Infinity`. */
|
|
5069
|
+
maxLevels?: number;
|
|
5070
|
+
/** Abort every mutation, as though the entire query were disabled. */
|
|
5071
|
+
queryDisabled?: boolean;
|
|
4512
5072
|
/**
|
|
4513
|
-
*
|
|
4514
|
-
*
|
|
4515
|
-
* if the parent group is not empty. This option will supersede `combinators`.
|
|
5073
|
+
* Honor `disabled` properties within the query. Defaults to `true`, matching the
|
|
5074
|
+
* `QueryBuilder` component; a node's own `disabled` property can always be changed.
|
|
4516
5075
|
*/
|
|
4517
|
-
|
|
5076
|
+
respectDisabled?: boolean;
|
|
4518
5077
|
/**
|
|
4519
|
-
*
|
|
5078
|
+
* Paths disabled by position rather than by a `disabled` property on the node itself, mirroring
|
|
5079
|
+
* the array form of the `QueryBuilder` `disabled` prop. Honored only when `respectDisabled` is
|
|
5080
|
+
* `true`; as with the `disabled` property, a node's own `disabled` can always be changed.
|
|
4520
5081
|
*/
|
|
4521
|
-
|
|
5082
|
+
disabledPaths?: Path[];
|
|
5083
|
+
resetOnFieldChange?: boolean;
|
|
5084
|
+
resetOnOperatorChange?: boolean;
|
|
5085
|
+
getRuleDefaultOperator?: (field: string) => string;
|
|
5086
|
+
getValueSources?: (field: string, operator: string) => ValueSourceFullOptions;
|
|
5087
|
+
getRuleDefaultValue?: (rule: RuleType) => any;
|
|
5088
|
+
getMatchModes?: (field: string) => MatchModeOptions;
|
|
5089
|
+
/** Receives a structured event for every action, applied or aborted. */
|
|
5090
|
+
onLog?: (payload: Record<string, any>) => void;
|
|
4522
5091
|
}
|
|
4523
|
-
|
|
4524
|
-
|
|
5092
|
+
/**
|
|
5093
|
+
* The six mutations a query builder performs. Each takes the current query and returns the next
|
|
5094
|
+
* one, or `undefined` when the mutation was aborted—because the target is disabled, a
|
|
5095
|
+
* confirmation callback declined, or a depth limit was reached.
|
|
5096
|
+
*
|
|
5097
|
+
* @group Query Tools
|
|
5098
|
+
*/
|
|
5099
|
+
interface QueryActionHandlers {
|
|
5100
|
+
addRule: (query: any, rule: RuleType, parentPath: Path, context?: any) => any;
|
|
5101
|
+
addGroup: (query: any, ruleGroup: any, parentPath: Path, context?: any) => any;
|
|
5102
|
+
propChange: (query: any, prop: UpdateableProperties, value: any, path: Path) => any;
|
|
5103
|
+
removeRuleOrGroup: (query: any, path: Path, context?: any) => any;
|
|
5104
|
+
moveRule: (query: any, oldPath: Path, newPath: Path | "up" | "down", clone?: boolean, context?: any) => any;
|
|
5105
|
+
groupRule: (query: any, sourcePath: Path, targetPath: Path, clone?: boolean, context?: any) => any;
|
|
4525
5106
|
}
|
|
4526
5107
|
/**
|
|
4527
|
-
*
|
|
5108
|
+
* Builds the query builder's six mutation handlers as pure functions of the current query.
|
|
4528
5109
|
*
|
|
4529
|
-
*
|
|
5110
|
+
* This is the framework-agnostic core of the action handlers in `useQueryBuilderSchema`. It owns
|
|
5111
|
+
* the policy that surrounds the query tools—disabled gating, the confirmation callback protocol,
|
|
5112
|
+
* `maxLevels`, and debug logging—so an implementation only has to supply its own storage: read
|
|
5113
|
+
* the current query, call the action, and apply a non-`undefined` result.
|
|
5114
|
+
*
|
|
5115
|
+
* @group Query Tools
|
|
5116
|
+
*/
|
|
5117
|
+
declare const createQueryActions: (config?: QueryActionsConfig) => QueryActionHandlers;
|
|
5118
|
+
//#endregion
|
|
5119
|
+
//#region src/utils/queryTools.d.ts
|
|
5120
|
+
/**
|
|
5121
|
+
* Why a query tool returned the query unmodified. Query tools never throw; when they cannot
|
|
5122
|
+
* carry out an operation they return the original query and report the reason through
|
|
5123
|
+
* {@link AbortOptions.onAbort}.
|
|
5124
|
+
*
|
|
5125
|
+
* `"same-location"` and `"no-change"` describe operations that were valid but had nothing to
|
|
5126
|
+
* do, so they are not errors. Every other reason indicates a target that could not be used.
|
|
5127
|
+
*
|
|
5128
|
+
* @group Query Tools
|
|
5129
|
+
*/
|
|
5130
|
+
type AbortReason = "target-not-found" | "parent-not-found" | "parent-not-a-group" | "destination-not-found" | "root-not-allowed" | "not-a-combinator-slot" | "same-location" | "no-change" | "target-disabled" | "parent-disabled" | "max-levels-exceeded";
|
|
5131
|
+
/**
|
|
5132
|
+
* Details about an aborted query tool operation.
|
|
5133
|
+
*
|
|
5134
|
+
* @group Query Tools
|
|
5135
|
+
*/
|
|
5136
|
+
interface AbortInfo {
|
|
5137
|
+
/** Why the operation was aborted. */
|
|
5138
|
+
reason: AbortReason;
|
|
5139
|
+
/** The query tool that aborted. */
|
|
5140
|
+
operation: "add" | "remove" | "update" | "move" | "insert" | "group";
|
|
5141
|
+
/** The path or `id` that could not be used, when the reason relates to a specific target. */
|
|
5142
|
+
pathOrID?: Path | string;
|
|
5143
|
+
}
|
|
5144
|
+
/**
|
|
5145
|
+
* Options that block a mutation before it is attempted.
|
|
5146
|
+
*
|
|
5147
|
+
* `disabled` is a property of the query itself, so honoring it is a matter of data integrity
|
|
5148
|
+
* rather than presentation: a query saved with a locked rule should stay locked when it is
|
|
5149
|
+
* loaded again. It is opt-in here only to preserve the existing behavior of the standalone
|
|
5150
|
+
* query tools; {@link QueryManager} enables it by default.
|
|
5151
|
+
*
|
|
5152
|
+
* @group Query Tools
|
|
5153
|
+
*/
|
|
5154
|
+
interface GuardOptions {
|
|
5155
|
+
/**
|
|
5156
|
+
* Abort when the target (or its parent, for `add`/`insert`) is disabled, either directly or
|
|
5157
|
+
* by descending from a disabled group. Defaults to `false`.
|
|
5158
|
+
*
|
|
5159
|
+
* Updating a rule or group's own `disabled` property is always permitted, since it is the
|
|
5160
|
+
* only way to re-enable it.
|
|
5161
|
+
*/
|
|
5162
|
+
respectDisabled?: boolean;
|
|
5163
|
+
/**
|
|
5164
|
+
* Paths that are disabled without the corresponding rule or group carrying a `disabled`
|
|
5165
|
+
* property, mirroring the array form of the `QueryBuilder` `disabled` prop. A path is treated
|
|
5166
|
+
* as disabled if it appears here or descends from a path that does.
|
|
5167
|
+
*
|
|
5168
|
+
* Like the `disabled` property, this is only honored when `respectDisabled` is `true`, and
|
|
5169
|
+
* updating a rule or group's own `disabled` property is still permitted.
|
|
5170
|
+
*/
|
|
5171
|
+
disabledPaths?: Path[];
|
|
5172
|
+
/** Abort every mutation, as though the entire query were disabled. Defaults to `false`. */
|
|
5173
|
+
queryDisabled?: boolean;
|
|
5174
|
+
/**
|
|
5175
|
+
* The maximum depth at which a group may be added. A group whose parent path is already this
|
|
5176
|
+
* deep is rejected by `add` and `insert`. Rules are unaffected. Defaults to `Infinity`.
|
|
5177
|
+
*/
|
|
5178
|
+
maxLevels?: number;
|
|
5179
|
+
}
|
|
5180
|
+
/**
|
|
5181
|
+
* Options for reporting aborted query tool operations.
|
|
5182
|
+
*
|
|
5183
|
+
* @group Query Tools
|
|
5184
|
+
*/
|
|
5185
|
+
interface AbortOptions extends GuardOptions {
|
|
5186
|
+
/**
|
|
5187
|
+
* Called when the operation returns the query unmodified, with the reason why. Query tools
|
|
5188
|
+
* never throw, so this is the only way to distinguish "the target was invalid" from
|
|
5189
|
+
* "the operation had nothing to do".
|
|
5190
|
+
*/
|
|
5191
|
+
onAbort?: (info: AbortInfo) => void;
|
|
5192
|
+
}
|
|
5193
|
+
/**
|
|
5194
|
+
* Whether a mutation targeting `pathOrID` is blocked by the given guards, and why.
|
|
5195
|
+
* Returns `null` when the mutation may proceed.
|
|
5196
|
+
*
|
|
5197
|
+
* Exported so that callers which run their own logic before mutating—such as a UI layer that
|
|
5198
|
+
* invokes a confirmation callback—can apply the same rules without duplicating them.
|
|
5199
|
+
*
|
|
5200
|
+
* @group Query Tools
|
|
5201
|
+
*/
|
|
5202
|
+
declare const getGuardAbortReason: (query: RuleGroupTypeAny, pathOrID: Path | string | undefined, guards?: GuardOptions, { asParent }?: {
|
|
5203
|
+
asParent?: boolean;
|
|
5204
|
+
}) => AbortReason | null;
|
|
5205
|
+
/**
|
|
5206
|
+
* Whether adding a group beneath `parentPath` would exceed `maxLevels`.
|
|
5207
|
+
*
|
|
5208
|
+
* @group Query Tools
|
|
5209
|
+
*/
|
|
5210
|
+
declare const exceedsMaxLevels: (parentPath: Path | undefined, { maxLevels }?: GuardOptions) => boolean;
|
|
5211
|
+
/**
|
|
5212
|
+
* Options for {@link add}.
|
|
5213
|
+
*
|
|
5214
|
+
* @group Query Tools
|
|
5215
|
+
*/
|
|
5216
|
+
interface AddOptions extends AbortOptions {
|
|
5217
|
+
/**
|
|
5218
|
+
* If the query extends `RuleGroupTypeIC` (i.e. the query has independent
|
|
5219
|
+
* combinators), then the first combinator in this list will be inserted
|
|
5220
|
+
* before the new rule/group if the parent group is not empty. This option
|
|
5221
|
+
* is overridden by `combinatorPreceding`.
|
|
5222
|
+
*/
|
|
5223
|
+
combinators?: OptionList;
|
|
5224
|
+
/**
|
|
5225
|
+
* If the query extends `RuleGroupTypeIC` (i.e. the query has independent
|
|
5226
|
+
* combinators), then this combinator will be inserted before the new rule/group
|
|
5227
|
+
* if the parent group is not empty. This option will supersede `combinators`.
|
|
5228
|
+
*/
|
|
5229
|
+
combinatorPreceding?: string;
|
|
5230
|
+
/**
|
|
5231
|
+
* ID generator.
|
|
5232
|
+
*/
|
|
5233
|
+
idGenerator?: () => string;
|
|
5234
|
+
}
|
|
5235
|
+
interface AddMethod {
|
|
5236
|
+
<RG extends RuleGroupTypeAny>(query: RG, ruleOrGroup: RG | RuleType, parentPathOrID: Path | string, options?: AddOptions): RG;
|
|
5237
|
+
}
|
|
5238
|
+
/**
|
|
5239
|
+
* Adds a rule or group to a query without mutating the original query.
|
|
5240
|
+
*
|
|
5241
|
+
* @returns A new query with the rule or group added.
|
|
4530
5242
|
*
|
|
4531
5243
|
* @group Query Tools
|
|
4532
5244
|
*/
|
|
@@ -4544,7 +5256,7 @@ declare const addInPlace: AddMethod;
|
|
|
4544
5256
|
*
|
|
4545
5257
|
* @group Query Tools
|
|
4546
5258
|
*/
|
|
4547
|
-
interface UpdateOptions {
|
|
5259
|
+
interface UpdateOptions extends AbortOptions {
|
|
4548
5260
|
/**
|
|
4549
5261
|
* When updating the `field` of a rule, the rule's `operator`, `value`, and `valueSource`
|
|
4550
5262
|
* will be reset to their respective defaults. Defaults to `true`.
|
|
@@ -4610,8 +5322,14 @@ declare const update: UpdateMethod;
|
|
|
4610
5322
|
* @group Query Tools
|
|
4611
5323
|
*/
|
|
4612
5324
|
declare const updateInPlace: UpdateMethod;
|
|
5325
|
+
/**
|
|
5326
|
+
* Options for {@link remove}.
|
|
5327
|
+
*
|
|
5328
|
+
* @group Query Tools
|
|
5329
|
+
*/
|
|
5330
|
+
interface RemoveOptions extends AbortOptions {}
|
|
4613
5331
|
interface RemoveMethod {
|
|
4614
|
-
<RG extends RuleGroupTypeAny>(query: RG, pathOrID: Path | string): RG;
|
|
5332
|
+
<RG extends RuleGroupTypeAny>(query: RG, pathOrID: Path | string, options?: RemoveOptions): RG;
|
|
4615
5333
|
}
|
|
4616
5334
|
/**
|
|
4617
5335
|
* Removes a rule or group from a query without mutating the original query.
|
|
@@ -4634,7 +5352,7 @@ declare const removeInPlace: RemoveMethod;
|
|
|
4634
5352
|
*
|
|
4635
5353
|
* @group Query Tools
|
|
4636
5354
|
*/
|
|
4637
|
-
interface MoveOptions {
|
|
5355
|
+
interface MoveOptions extends AbortOptions {
|
|
4638
5356
|
/**
|
|
4639
5357
|
* When `true`, the source rule/group will not be removed from its original path.
|
|
4640
5358
|
*/
|
|
@@ -4676,7 +5394,7 @@ declare const moveInPlace: MoveMethod;
|
|
|
4676
5394
|
*
|
|
4677
5395
|
* @group Query Tools
|
|
4678
5396
|
*/
|
|
4679
|
-
interface InsertOptions {
|
|
5397
|
+
interface InsertOptions extends AbortOptions {
|
|
4680
5398
|
/**
|
|
4681
5399
|
* If the query extends `RuleGroupTypeIC` (i.e. the query has independent
|
|
4682
5400
|
* combinators), then the first combinator in this list will be inserted
|
|
@@ -4733,7 +5451,7 @@ declare const insertInPlace: InsertMethod;
|
|
|
4733
5451
|
*
|
|
4734
5452
|
* @group Query Tools
|
|
4735
5453
|
*/
|
|
4736
|
-
interface GroupOptions {
|
|
5454
|
+
interface GroupOptions extends AbortOptions {
|
|
4737
5455
|
/**
|
|
4738
5456
|
* When `true`, the source rule/group will not be removed from its original path.
|
|
4739
5457
|
*/
|
|
@@ -4773,24 +5491,6 @@ declare const group: GroupMethod;
|
|
|
4773
5491
|
*/
|
|
4774
5492
|
declare const groupInPlace: GroupMethod;
|
|
4775
5493
|
//#endregion
|
|
4776
|
-
//#region src/utils/regenerateIDs.d.ts
|
|
4777
|
-
/**
|
|
4778
|
-
* Options object for {@link regenerateID}/{@link regenerateIDs}.
|
|
4779
|
-
*/
|
|
4780
|
-
interface RegenerateIdOptions {
|
|
4781
|
-
idGenerator?: () => string;
|
|
4782
|
-
}
|
|
4783
|
-
/**
|
|
4784
|
-
* Generates a new `id` property for a rule.
|
|
4785
|
-
*/
|
|
4786
|
-
declare const regenerateID: <R extends RuleType>(rule: R, { idGenerator }?: RegenerateIdOptions) => SetRequired<R, "id">;
|
|
4787
|
-
/**
|
|
4788
|
-
* Recursively generates new `id` properties for a rule group and all its rules and subgroups.
|
|
4789
|
-
*/
|
|
4790
|
-
declare const regenerateIDs: <RG>(subject: RG, { idGenerator }?: RegenerateIdOptions) => RG & {
|
|
4791
|
-
id: string;
|
|
4792
|
-
};
|
|
4793
|
-
//#endregion
|
|
4794
5494
|
//#region src/utils/transformQuery.d.ts
|
|
4795
5495
|
/**
|
|
4796
5496
|
* Options object for {@link index!transformQuery transformQuery}.
|
|
@@ -4904,5 +5604,660 @@ declare function transformQuery(query: RuleGroupType, options?: TransformQueryOp
|
|
|
4904
5604
|
*/
|
|
4905
5605
|
declare function transformQuery(query: RuleGroupTypeIC, options?: TransformQueryOptions<RuleGroupTypeIC>): any;
|
|
4906
5606
|
//#endregion
|
|
4907
|
-
|
|
5607
|
+
//#region src/utils/QueryManager.d.ts
|
|
5608
|
+
/**
|
|
5609
|
+
* Abort reasons that {@link QueryManager}'s `strict` mode treats as errors. The remaining
|
|
5610
|
+
* reasons—`"same-location"` and `"no-change"`—describe valid operations that had nothing to do,
|
|
5611
|
+
* so they are reported to `onInvalidTarget` but never throw.
|
|
5612
|
+
*
|
|
5613
|
+
* @group Query Tools
|
|
5614
|
+
*/
|
|
5615
|
+
declare const strictAbortReasons: readonly AbortReason[];
|
|
5616
|
+
/**
|
|
5617
|
+
* Thrown by {@link QueryManager} methods in `strict` mode when an operation cannot be carried
|
|
5618
|
+
* out because its target could not be used.
|
|
5619
|
+
*
|
|
5620
|
+
* @group Query Tools
|
|
5621
|
+
*/
|
|
5622
|
+
declare class QueryManagerError extends Error {
|
|
5623
|
+
/** Why the operation was aborted. */
|
|
5624
|
+
readonly code: AbortReason;
|
|
5625
|
+
/** Full details about the aborted operation. */
|
|
5626
|
+
readonly info: AbortInfo;
|
|
5627
|
+
constructor(info: AbortInfo);
|
|
5628
|
+
}
|
|
5629
|
+
/**
|
|
5630
|
+
* Per-call overrides for {@link QueryManager}'s abort handling. Every mutating method accepts
|
|
5631
|
+
* these alongside the options of the query tool it delegates to.
|
|
5632
|
+
*
|
|
5633
|
+
* @group Query Tools
|
|
5634
|
+
*/
|
|
5635
|
+
interface StrictOptions {
|
|
5636
|
+
/**
|
|
5637
|
+
* Throw a {@link QueryManagerError} when an operation is aborted for one of the
|
|
5638
|
+
* {@link strictAbortReasons}. Overrides the manager's own `strict` option.
|
|
5639
|
+
*/
|
|
5640
|
+
strict?: boolean;
|
|
5641
|
+
/**
|
|
5642
|
+
* Called whenever an operation is aborted, including for the non-error reasons
|
|
5643
|
+
* `"same-location"` and `"no-change"`. Runs before any `strict` throw, so an operation can be
|
|
5644
|
+
* both observed and enforced. Overrides the manager's own `onInvalidTarget` option.
|
|
5645
|
+
*/
|
|
5646
|
+
onInvalidTarget?: (info: AbortInfo) => void;
|
|
5647
|
+
}
|
|
5648
|
+
/**
|
|
5649
|
+
* Options for {@link QueryManager}. Mirrors the subset of
|
|
5650
|
+
* {@link react-querybuilder!QueryBuilder QueryBuilder} props that affect query
|
|
5651
|
+
* _structure_ rather than rendering, so the same configuration objects can drive both.
|
|
5652
|
+
*
|
|
5653
|
+
* @group Query Tools
|
|
5654
|
+
*/
|
|
5655
|
+
interface QueryManagerOptions<F extends FullField = FullField, O extends FullOperator = FullOperator, C extends FullCombinator = FullCombinator> {
|
|
5656
|
+
/** The fields available for rules. Accepts the same shapes as the `fields` prop. */
|
|
5657
|
+
fields?: FlexibleOptionListProp<F> | BaseOptionMap<F>;
|
|
5658
|
+
/** The operators available for rules. Accepts the same shapes as the `operators` prop. */
|
|
5659
|
+
operators?: FlexibleOptionListProp<O> | BaseOptionMap<O>;
|
|
5660
|
+
/** The combinators available for groups. Defaults to `defaultCombinators`. */
|
|
5661
|
+
combinators?: FlexibleOptionListProp<C> | BaseOptionMap<C>;
|
|
5662
|
+
/** Properties applied to every field in `fields`. */
|
|
5663
|
+
baseField?: Record<string, unknown>;
|
|
5664
|
+
/** Properties applied to every operator in `operators`. */
|
|
5665
|
+
baseOperator?: Record<string, unknown>;
|
|
5666
|
+
/** Properties applied to every combinator in `combinators`. */
|
|
5667
|
+
baseCombinator?: Record<string, unknown>;
|
|
5668
|
+
/** When `false`, an empty placeholder option is prepended to the field list. */
|
|
5669
|
+
autoSelectField?: boolean;
|
|
5670
|
+
/** When `false`, an empty placeholder option is prepended to each operator list. */
|
|
5671
|
+
autoSelectOperator?: boolean;
|
|
5672
|
+
/** When `false`, an empty placeholder option is prepended to each value list. */
|
|
5673
|
+
autoSelectValue?: boolean;
|
|
5674
|
+
/** The default `field` for rules created by {@link QueryManager.createRule}. */
|
|
5675
|
+
getDefaultField?: string | ((fieldsData: FullOptionList<F>) => string);
|
|
5676
|
+
/** The default `operator` for a given field. */
|
|
5677
|
+
getDefaultOperator?: string | ((field: string, misc: {
|
|
5678
|
+
fieldData: F;
|
|
5679
|
+
}) => string);
|
|
5680
|
+
/** Overrides the computed default `value` for a new rule. */
|
|
5681
|
+
getDefaultValue?: (rule: RuleType, misc: {
|
|
5682
|
+
fieldData: F;
|
|
5683
|
+
}) => unknown;
|
|
5684
|
+
/** The operators available for a given field. */
|
|
5685
|
+
getOperators?: (field: string, misc: {
|
|
5686
|
+
fieldData: F;
|
|
5687
|
+
}) => FlexibleOptionList<O> | null;
|
|
5688
|
+
/** The value editor type for a given field/operator, which informs the default value. */
|
|
5689
|
+
getValueEditorType?: (field: string, operator: string, misc: {
|
|
5690
|
+
fieldData: F;
|
|
5691
|
+
}) => ValueEditorType;
|
|
5692
|
+
/** The value list for a given field/operator, which informs the default value. */
|
|
5693
|
+
getValues?: (field: string, operator: string, misc: {
|
|
5694
|
+
fieldData: F;
|
|
5695
|
+
}) => FlexibleOptionList<Option>;
|
|
5696
|
+
/** The valid value sources for a given field/operator. */
|
|
5697
|
+
getValueSources?: (field: string, operator: string, misc: {
|
|
5698
|
+
fieldData: F;
|
|
5699
|
+
}) => ValueSources | ValueSourceFlexibleOptions;
|
|
5700
|
+
/** The valid match modes for a given field. */
|
|
5701
|
+
getMatchModes?: (field: string, misc: {
|
|
5702
|
+
fieldData: F;
|
|
5703
|
+
}) => boolean | MatchMode[] | FlexibleOption<MatchMode>[];
|
|
5704
|
+
/** The named parameters available for a given field/operator. */
|
|
5705
|
+
getParameters?: (field: string, operator: string, misc: {
|
|
5706
|
+
fieldData: F;
|
|
5707
|
+
}) => FlexibleOptionList<Option> | null;
|
|
5708
|
+
/** When `true`, multi-value defaults are arrays instead of comma-joined strings. */
|
|
5709
|
+
listsAsArrays?: boolean;
|
|
5710
|
+
/** When `true`, groups created by {@link QueryManager.createRuleGroup} contain one new rule. */
|
|
5711
|
+
addRuleToNewGroups?: boolean;
|
|
5712
|
+
/**
|
|
5713
|
+
* When updating a rule's `field`, reset its `operator`, `value`, and `valueSource` to their
|
|
5714
|
+
* defaults. Defaults to `true`, matching the `QueryBuilder` prop of the same name.
|
|
5715
|
+
*/
|
|
5716
|
+
resetOnFieldChange?: boolean;
|
|
5717
|
+
/**
|
|
5718
|
+
* When updating a rule's `operator`, reset its `value` to the default. Defaults to `false`,
|
|
5719
|
+
* matching the `QueryBuilder` prop of the same name.
|
|
5720
|
+
*/
|
|
5721
|
+
resetOnOperatorChange?: boolean;
|
|
5722
|
+
/**
|
|
5723
|
+
* The maximum depth at which groups may be added. As with the `QueryBuilder` prop of the same
|
|
5724
|
+
* name, a non-positive value means unlimited. Defaults to `Infinity`.
|
|
5725
|
+
*/
|
|
5726
|
+
maxLevels?: number;
|
|
5727
|
+
/**
|
|
5728
|
+
* Honor `disabled` properties within the query, so mutations targeting a disabled rule or
|
|
5729
|
+
* group (or a descendant of a disabled group) are aborted. Updating a node's own `disabled`
|
|
5730
|
+
* property is always permitted. Defaults to `true`, matching the `QueryBuilder` component;
|
|
5731
|
+
* pass `false` to mutate freely regardless of the property.
|
|
5732
|
+
*/
|
|
5733
|
+
respectDisabled?: boolean;
|
|
5734
|
+
/**
|
|
5735
|
+
* Paths that are disabled without the corresponding rule or group carrying a `disabled`
|
|
5736
|
+
* property. This mirrors the array form of the `QueryBuilder` `disabled` prop
|
|
5737
|
+
* (e.g. `disabled={[[2]]}`), which disables nodes by position rather than by data.
|
|
5738
|
+
*
|
|
5739
|
+
* A path is treated as disabled if it appears here or descends from a path that does. Honored
|
|
5740
|
+
* only when `respectDisabled` is `true`; as with the `disabled` property, a node's own
|
|
5741
|
+
* `disabled` can always be changed so it is never permanently locked.
|
|
5742
|
+
*/
|
|
5743
|
+
disabledPaths?: Path[];
|
|
5744
|
+
/** Abort every mutation, as though the entire query were disabled. Defaults to `false`. */
|
|
5745
|
+
queryDisabled?: boolean;
|
|
5746
|
+
/** The input type for a given field/operator, surfaced by {@link QueryManager.getRuleContext}. */
|
|
5747
|
+
getInputType?: (field: string, operator: string, misc: {
|
|
5748
|
+
fieldData: F;
|
|
5749
|
+
}) => InputType | null;
|
|
5750
|
+
/** Extra props for a subquery builder, surfaced by {@link QueryManager.getRuleContext}. */
|
|
5751
|
+
getSubQueryBuilderProps?: (field: string, misc: {
|
|
5752
|
+
fieldData: F;
|
|
5753
|
+
}) => Record<string, unknown>;
|
|
5754
|
+
/**
|
|
5755
|
+
* Enables undo/redo recording. Pass `true` for the defaults, or an object to configure
|
|
5756
|
+
* `maxHistory` and/or `coalesceMs`. Disabled by default, so instances that never undo
|
|
5757
|
+
* retain no extra references.
|
|
5758
|
+
*/
|
|
5759
|
+
history?: boolean | QueryHistoryOptions;
|
|
5760
|
+
/**
|
|
5761
|
+
* Throw a {@link QueryManagerError} when a mutation is aborted because its target could not
|
|
5762
|
+
* be used. Disabled by default, in which case such mutations are silent no-ops. Can be
|
|
5763
|
+
* overridden per call.
|
|
5764
|
+
*/
|
|
5765
|
+
strict?: boolean;
|
|
5766
|
+
/**
|
|
5767
|
+
* Called whenever a mutation is aborted, including for the non-error reasons
|
|
5768
|
+
* `"same-location"` and `"no-change"`. Can be overridden per call.
|
|
5769
|
+
*/
|
|
5770
|
+
onInvalidTarget?: (info: AbortInfo) => void;
|
|
5771
|
+
/** Validates the query. Defaults to {@link defaultValidator}. */
|
|
5772
|
+
validator?: QueryValidator;
|
|
5773
|
+
/** Generates `id` properties for new rules and groups. Defaults to {@link generateID}. */
|
|
5774
|
+
idGenerator?: () => string;
|
|
5775
|
+
/**
|
|
5776
|
+
* Clock used to time history coalescing. Defaults to `Date.now`.
|
|
5777
|
+
*
|
|
5778
|
+
* @internal Test seam. Exists so that history recording can be compared against the
|
|
5779
|
+
* `react-querybuilder/history` implementation without depending on wall-clock timing.
|
|
5780
|
+
*/
|
|
5781
|
+
now?: () => number;
|
|
5782
|
+
}
|
|
5783
|
+
/**
|
|
5784
|
+
* A single rule or group encountered by {@link QueryManager.walk}, along with where it was found.
|
|
5785
|
+
*
|
|
5786
|
+
* @group Query Tools
|
|
5787
|
+
*/
|
|
5788
|
+
interface QueryNode<RG extends RuleGroupTypeAny = RuleGroupType> {
|
|
5789
|
+
/** The rule or group itself. */
|
|
5790
|
+
node: RG | RuleType;
|
|
5791
|
+
/** The {@link Path} of `node` within the query. The root group's path is `[]`. */
|
|
5792
|
+
path: Path;
|
|
5793
|
+
/** The group containing `node`, or `null` for the root group. */
|
|
5794
|
+
parent: RG | null;
|
|
5795
|
+
}
|
|
5796
|
+
/**
|
|
5797
|
+
* Options for {@link QueryManager.walk} and its derivatives.
|
|
5798
|
+
*
|
|
5799
|
+
* @group Query Tools
|
|
5800
|
+
*/
|
|
5801
|
+
interface WalkOptions {
|
|
5802
|
+
/**
|
|
5803
|
+
* Traverse only the subtree rooted at this path or `id` instead of the whole query. The node
|
|
5804
|
+
* itself is visited first. When the path or `id` can't be resolved, nothing is visited.
|
|
5805
|
+
*/
|
|
5806
|
+
from?: Path | string;
|
|
5807
|
+
/** Visit only rules. Groups are still traversed, just not yielded (except as `parent`). */
|
|
5808
|
+
rulesOnly?: boolean;
|
|
5809
|
+
/** Visit only groups. */
|
|
5810
|
+
groupsOnly?: boolean;
|
|
5811
|
+
}
|
|
5812
|
+
/**
|
|
5813
|
+
* Coerces the result of a conditional query type back into something assignable to
|
|
5814
|
+
* {@link QueryManager}'s `RG` parameter, which TypeScript cannot verify on its own.
|
|
5815
|
+
*/
|
|
5816
|
+
type AsRuleGroup<T> = T extends RuleGroupTypeAny ? T : RuleGroupTypeAny;
|
|
5817
|
+
/**
|
|
5818
|
+
* Stateful wrapper around the {@link add}/{@link remove}/{@link update}/{@link move}/
|
|
5819
|
+
* {@link insert}/{@link group} query tools, plus rule/group factories, {@link defaultValidator
|
|
5820
|
+
* validation}, and {@link formatQuery formatting}.
|
|
5821
|
+
*
|
|
5822
|
+
* The query is held internally, so each method takes the same arguments as its `queryTools`
|
|
5823
|
+
* counterpart minus the leading `query` parameter, and returns the manager itself for chaining.
|
|
5824
|
+
* Mutations use the non-`InPlace` tools, so a query previously handed out by
|
|
5825
|
+
* {@link QueryManager.getQuery} is never modified.
|
|
5826
|
+
*
|
|
5827
|
+
* ```ts
|
|
5828
|
+
* const q = new QueryManager(undefined, { fields });
|
|
5829
|
+
* q.add(q.createRule()).add({ field: 'firstName', operator: '=', value: 'Steve' });
|
|
5830
|
+
* q.format('sql');
|
|
5831
|
+
* ```
|
|
5832
|
+
*
|
|
5833
|
+
* Like the underlying query tools, methods are a no-op when the target path or `id` can't be
|
|
5834
|
+
* resolved (including attempts to remove the root group). By default nothing is thrown; pass
|
|
5835
|
+
* `strict: true` to raise a {@link QueryManagerError} instead, or `onInvalidTarget` to observe
|
|
5836
|
+
* aborted operations without changing control flow.
|
|
5837
|
+
*
|
|
5838
|
+
* @group Query Tools
|
|
5839
|
+
*/
|
|
5840
|
+
declare class QueryManager<RG extends RuleGroupTypeAny = RuleGroupType, F extends FullField = FullField, O extends FullOperator = FullOperator, C extends FullCombinator = FullCombinator> {
|
|
5841
|
+
#private;
|
|
5842
|
+
constructor(query?: RG, options?: QueryManagerOptions<F, O, C>);
|
|
5843
|
+
/**
|
|
5844
|
+
* The current query. The returned object is frozen and structurally shared, so it is safe to
|
|
5845
|
+
* retain and compare by reference to detect changes.
|
|
5846
|
+
*
|
|
5847
|
+
* Like {@link QueryManager.subscribe}, this method is bound to the instance, so it can be
|
|
5848
|
+
* passed as a bare reference (e.g. as the `getSnapshot` argument to `useSyncExternalStore`).
|
|
5849
|
+
*/
|
|
5850
|
+
getQuery: () => RG;
|
|
5851
|
+
/** Replaces the current query, ensuring every rule and group has an `id`. */
|
|
5852
|
+
setQuery(query: RG): this;
|
|
5853
|
+
/**
|
|
5854
|
+
* Creates a rule using the configured fields, operators, and defaults. The rule is not added
|
|
5855
|
+
* to the query—pass it to {@link QueryManager.add} or {@link QueryManager.insert}.
|
|
5856
|
+
*/
|
|
5857
|
+
createRule(): RuleType;
|
|
5858
|
+
/**
|
|
5859
|
+
* Creates a group. Pass `true` for a group with independent combinators. The group is not
|
|
5860
|
+
* added to the query—pass it to {@link QueryManager.add} or {@link QueryManager.insert}.
|
|
5861
|
+
*/
|
|
5862
|
+
createRuleGroup(independentCombinators?: boolean): RG;
|
|
5863
|
+
/**
|
|
5864
|
+
* Adds a rule or group to the end of the group at `parentPathOrID`, which defaults to the
|
|
5865
|
+
* root group.
|
|
5866
|
+
*/
|
|
5867
|
+
add(ruleOrGroup: RG | RuleType, parentPathOrID?: Path | string, options?: AddOptions & StrictOptions): this;
|
|
5868
|
+
/** Removes the rule or group at the given path or `id`. The root group cannot be removed. */
|
|
5869
|
+
remove(pathOrID: Path | string, options?: RemoveOptions & StrictOptions): this;
|
|
5870
|
+
/** Updates a single property of the rule or group at the given path or `id`. */
|
|
5871
|
+
update(prop: UpdateableProperties, value: unknown, pathOrID: Path | string, options?: UpdateOptions & StrictOptions): this;
|
|
5872
|
+
/** Updates multiple properties using parallel arrays of names and values. */
|
|
5873
|
+
update(props: UpdateableProperties[], values: unknown[], pathOrID: Path | string, options?: UpdateOptions & StrictOptions): this;
|
|
5874
|
+
/** Updates multiple properties using a map of names to values. */
|
|
5875
|
+
update(props: UpdateValueMap, pathOrID: Path | string, options?: UpdateOptions & StrictOptions): this;
|
|
5876
|
+
/** Moves the rule or group at `oldPathOrID` to `newPath`, or shifts it `'up'`/`'down'`. */
|
|
5877
|
+
move(oldPathOrID: Path | string, newPath: Path | "up" | "down", options?: MoveOptions & StrictOptions): this;
|
|
5878
|
+
/**
|
|
5879
|
+
* Inserts a rule or group at the given path. Unlike the other methods, this accepts a path
|
|
5880
|
+
* only—inserting _at_ an `id` would be ambiguous.
|
|
5881
|
+
*/
|
|
5882
|
+
insert(ruleOrGroup: RG | RuleType, path: Path, options?: InsertOptions & StrictOptions): this;
|
|
5883
|
+
/**
|
|
5884
|
+
* Creates a new group at `targetPathOrID` containing the rules/groups currently at
|
|
5885
|
+
* `targetPathOrID` and `sourcePathOrID`.
|
|
5886
|
+
*/
|
|
5887
|
+
group(sourcePathOrID: Path | string, targetPathOrID: Path | string, options?: GroupOptions & StrictOptions): this;
|
|
5888
|
+
/**
|
|
5889
|
+
* Creates an independent manager with the same configuration and the current query.
|
|
5890
|
+
*
|
|
5891
|
+
* Subscribers and history are _not_ carried over: the clone starts with no listeners and an
|
|
5892
|
+
* empty undo stack. Because every mutation produces a new query object, the two managers
|
|
5893
|
+
* share the initial query safely and diverge from the first change.
|
|
5894
|
+
*
|
|
5895
|
+
* Pass `{ regenerateIDs: true }` to give every rule and group in the clone a new `id`, which
|
|
5896
|
+
* is useful when both queries will be used together (e.g. inserted into the same tree).
|
|
5897
|
+
*/
|
|
5898
|
+
clone(options?: {
|
|
5899
|
+
regenerateIDs?: boolean;
|
|
5900
|
+
}): QueryManager<RG, F, O, C>;
|
|
5901
|
+
/**
|
|
5902
|
+
* Registers a listener called after every change to the query, and returns a function that
|
|
5903
|
+
* unregisters it. Mutations that resolve to a no-op do not notify, and a
|
|
5904
|
+
* {@link QueryManager.batch batch} notifies once no matter how many changes it contains.
|
|
5905
|
+
*
|
|
5906
|
+
* Together with {@link QueryManager.getQuery}, this satisfies React's `useSyncExternalStore`
|
|
5907
|
+
* contract. Both methods are bound to the instance, so they are stable references across
|
|
5908
|
+
* renders and can be passed directly:
|
|
5909
|
+
*
|
|
5910
|
+
* ```ts
|
|
5911
|
+
* const query = useSyncExternalStore(q.subscribe, q.getQuery);
|
|
5912
|
+
* ```
|
|
5913
|
+
*
|
|
5914
|
+
* In React, prefer the `useQueryManager` hook from `react-querybuilder`, which wraps this.
|
|
5915
|
+
*/
|
|
5916
|
+
subscribe: (listener: () => void) => (() => void);
|
|
5917
|
+
/**
|
|
5918
|
+
* Runs `fn`, deferring history recording and subscriber notification until it returns. The
|
|
5919
|
+
* whole batch becomes a single undo step and triggers a single notification, or neither if
|
|
5920
|
+
* the query ends up unchanged.
|
|
5921
|
+
*
|
|
5922
|
+
* Batches may be nested; only the outermost one commits. If `fn` throws, the query and its
|
|
5923
|
+
* history are restored to their pre-batch state and the error propagates, so a batch either
|
|
5924
|
+
* applies completely or not at all.
|
|
5925
|
+
*
|
|
5926
|
+
* {@link QueryManager.undo}, {@link QueryManager.redo}, and {@link QueryManager.clearHistory}
|
|
5927
|
+
* may be called inside a batch; their notifications are deferred like everything else. Because
|
|
5928
|
+
* they manage the history stacks themselves, a batch containing one of them records no entry of
|
|
5929
|
+
* its own, leaving the stacks exactly as those methods left them.
|
|
5930
|
+
*/
|
|
5931
|
+
batch(fn: () => void): this;
|
|
5932
|
+
/** Whether there is a previous query to restore. Always `false` unless `history` is enabled. */
|
|
5933
|
+
canUndo(): boolean;
|
|
5934
|
+
/** Whether there is an undone query to restore. Always `false` unless `history` is enabled. */
|
|
5935
|
+
canRedo(): boolean;
|
|
5936
|
+
/** Restores the previous query. No-op when {@link QueryManager.canUndo} is `false`. */
|
|
5937
|
+
undo(): this;
|
|
5938
|
+
/** Restores the most recently undone query. No-op when {@link QueryManager.canRedo} is `false`. */
|
|
5939
|
+
redo(): this;
|
|
5940
|
+
/** Discards all undo/redo history without changing the current query. */
|
|
5941
|
+
clearHistory(): this;
|
|
5942
|
+
/**
|
|
5943
|
+
* The recorded history: `past` oldest first, `future` newest first. Both are copies, so
|
|
5944
|
+
* mutating them does not affect the manager.
|
|
5945
|
+
*/
|
|
5946
|
+
getHistory(): {
|
|
5947
|
+
past: RG[];
|
|
5948
|
+
future: RG[];
|
|
5949
|
+
};
|
|
5950
|
+
/**
|
|
5951
|
+
* Validates the current query with the configured validator.
|
|
5952
|
+
*
|
|
5953
|
+
* The result is cached until the query changes, so a custom `validator` with side effects (or
|
|
5954
|
+
* one that depends on anything other than the query) may run fewer times than expected.
|
|
5955
|
+
*/
|
|
5956
|
+
validate(): boolean | ValidationMap;
|
|
5957
|
+
/** Generates a JSON string from the current query. */
|
|
5958
|
+
format(): string;
|
|
5959
|
+
/** Generates a result based on the provided rule group processor. */
|
|
5960
|
+
format<TResult = unknown>(options: FormatQueryOptions & {
|
|
5961
|
+
ruleGroupProcessor: RuleGroupProcessor<TResult>;
|
|
5962
|
+
}): TResult;
|
|
5963
|
+
/** Generates a {@link ParameterizedSQL} object from the current query. */
|
|
5964
|
+
format(options: "parameterized" | (FormatQueryOptions & {
|
|
5965
|
+
format: "parameterized";
|
|
5966
|
+
})): ParameterizedSQL;
|
|
5967
|
+
/** Generates a {@link ParameterizedNamedSQL} object from the current query. */
|
|
5968
|
+
format(options: "parameterized_named" | (FormatQueryOptions & {
|
|
5969
|
+
format: "parameterized_named";
|
|
5970
|
+
})): ParameterizedNamedSQL;
|
|
5971
|
+
/** Generates a JsonLogic object from the current query. */
|
|
5972
|
+
format(options: "jsonlogic" | (FormatQueryOptions & {
|
|
5973
|
+
format: "jsonlogic";
|
|
5974
|
+
})): RQBJsonLogic;
|
|
5975
|
+
/** Generates an ElasticSearch query object from the current query. */
|
|
5976
|
+
format(options: "elasticsearch" | (FormatQueryOptions & {
|
|
5977
|
+
format: "elasticsearch";
|
|
5978
|
+
})): Record<string, any>;
|
|
5979
|
+
/** Generates a MongoDB query object from the current query. */
|
|
5980
|
+
format(options: "mongodb_query" | (FormatQueryOptions & {
|
|
5981
|
+
format: "mongodb_query";
|
|
5982
|
+
})): Record<string, any>;
|
|
5983
|
+
/** Generates a Prisma ORM query object from the current query. */
|
|
5984
|
+
format(options: "prisma" | (FormatQueryOptions & {
|
|
5985
|
+
format: "prisma";
|
|
5986
|
+
})): Record<string, any>;
|
|
5987
|
+
/** Generates a Drizzle ORM query object from the current query. */
|
|
5988
|
+
format(options: "drizzle" | (FormatQueryOptions & {
|
|
5989
|
+
format: "drizzle";
|
|
5990
|
+
})): ReturnType<typeof defaultRuleGroupProcessorDrizzle>;
|
|
5991
|
+
/** Generates a TanStack DB query object from the current query. */
|
|
5992
|
+
format(options: "tanstack_db" | (FormatQueryOptions & {
|
|
5993
|
+
format: "tanstack_db";
|
|
5994
|
+
})): ReturnType<typeof defaultRuleGroupProcessorTanStackDB>;
|
|
5995
|
+
/** Generates a Sequelize ORM query object from the current query. */
|
|
5996
|
+
format(options: "sequelize" | (FormatQueryOptions & {
|
|
5997
|
+
format: "sequelize";
|
|
5998
|
+
})): ReturnType<typeof defaultRuleGroupProcessorSequelize>;
|
|
5999
|
+
/** Generates a diagnostics result from the current query. */
|
|
6000
|
+
format(options: "diagnostics" | (FormatQueryOptions & {
|
|
6001
|
+
format: "diagnostics";
|
|
6002
|
+
})): DiagnosticsResult;
|
|
6003
|
+
/** Generates a query string in the requested format. */
|
|
6004
|
+
format(options: Exclude<ExportFormat, ExportObjectFormats>): string;
|
|
6005
|
+
/** Generates a query string in the requested format. */
|
|
6006
|
+
format(options: FormatQueryOptions & {
|
|
6007
|
+
format: Exclude<ExportFormat, ExportObjectFormats>;
|
|
6008
|
+
}): string;
|
|
6009
|
+
/** Generates a query string in the requested format. */
|
|
6010
|
+
format(options: FormatQueryOptions): string;
|
|
6011
|
+
/**
|
|
6012
|
+
* Yields every rule and group in the query, depth-first in pre-order, starting with the root
|
|
6013
|
+
* group itself. Combinator strings in independent-combinator groups are skipped.
|
|
6014
|
+
*
|
|
6015
|
+
* ```ts
|
|
6016
|
+
* for (const { node, path, parent } of qm.walk({ rulesOnly: true })) {
|
|
6017
|
+
* console.log(path, node.field);
|
|
6018
|
+
* }
|
|
6019
|
+
* ```
|
|
6020
|
+
*
|
|
6021
|
+
* Traversal operates on the query as it was when iteration began, so mutating the manager
|
|
6022
|
+
* mid-iteration does not affect a walk already in progress. Because generators are lazy, that
|
|
6023
|
+
* happens on the first iteration step rather than when `walk` is called.
|
|
6024
|
+
*
|
|
6025
|
+
* @yields Every rule and group in the query, subject to `options`.
|
|
6026
|
+
*/
|
|
6027
|
+
walk(options?: WalkOptions): Generator<QueryNode<RG>>;
|
|
6028
|
+
/** Yields every rule in the query. Shorthand for `walk({ ...options, rulesOnly: true })`. */
|
|
6029
|
+
rules(options?: Omit<WalkOptions, "rulesOnly" | "groupsOnly">): Generator<QueryNode<RG>>;
|
|
6030
|
+
/**
|
|
6031
|
+
* Yields every group in the query, including the root group. Shorthand for
|
|
6032
|
+
* `walk({ ...options, groupsOnly: true })`.
|
|
6033
|
+
*/
|
|
6034
|
+
groups(options?: Omit<WalkOptions, "rulesOnly" | "groupsOnly">): Generator<QueryNode<RG>>;
|
|
6035
|
+
/** Returns the first node matching `predicate`, or `null` if there is none. */
|
|
6036
|
+
find(predicate: (entry: QueryNode<RG>) => boolean, options?: WalkOptions): QueryNode<RG> | null;
|
|
6037
|
+
/** Returns every node matching `predicate`. */
|
|
6038
|
+
filter(predicate: (entry: QueryNode<RG>) => boolean, options?: WalkOptions): QueryNode<RG>[];
|
|
6039
|
+
/** Equivalent to {@link QueryManager.walk} with no options, enabling `for...of` and spread. */
|
|
6040
|
+
[Symbol.iterator](): Generator<QueryNode<RG>>;
|
|
6041
|
+
/**
|
|
6042
|
+
* Returns the rule or group at the given path, or `null` if the path can't be resolved.
|
|
6043
|
+
*
|
|
6044
|
+
* Unlike the standalone {@link findPath}, which can return `undefined` for an out-of-range
|
|
6045
|
+
* index, unresolvable paths are always normalized to `null` here.
|
|
6046
|
+
*/
|
|
6047
|
+
findPath(path: Path): FindPathReturnType;
|
|
6048
|
+
/**
|
|
6049
|
+
* Returns the rule or group with the given `id`, or `null` if there is none. Backed by an
|
|
6050
|
+
* index built once per query, so repeated lookups are constant time.
|
|
6051
|
+
*/
|
|
6052
|
+
findID(id: string): FindPathReturnType;
|
|
6053
|
+
/**
|
|
6054
|
+
* Returns the {@link Path} of the rule or group with the given `id`, or `null` if there is
|
|
6055
|
+
* none. Backed by an index built once per query, so repeated lookups are constant time.
|
|
6056
|
+
*/
|
|
6057
|
+
getPathOfID(id: string): Path | null;
|
|
6058
|
+
/**
|
|
6059
|
+
* Determines whether the rule or group at the given path is disabled, either itself or by an
|
|
6060
|
+
* ancestor group.
|
|
6061
|
+
*/
|
|
6062
|
+
pathIsDisabled(path: Path): boolean;
|
|
6063
|
+
/** Returns the rule or group at the given path or `id`, or `null` if it can't be resolved. */
|
|
6064
|
+
getNode(pathOrID: Path | string): FindPathReturnType;
|
|
6065
|
+
/**
|
|
6066
|
+
* Returns the rule at the given path or `id`, or `null` if it can't be resolved _or_ resolves
|
|
6067
|
+
* to a group.
|
|
6068
|
+
*/
|
|
6069
|
+
getRule(pathOrID: Path | string): RuleType | null;
|
|
6070
|
+
/**
|
|
6071
|
+
* Returns the group at the given path or `id`, or `null` if it can't be resolved _or_
|
|
6072
|
+
* resolves to a rule.
|
|
6073
|
+
*/
|
|
6074
|
+
getGroup(pathOrID: Path | string): RG | null;
|
|
6075
|
+
/**
|
|
6076
|
+
* Returns the group containing the rule or group at the given path or `id`. Returns `null`
|
|
6077
|
+
* for the root group, which has no parent, and when the target can't be resolved.
|
|
6078
|
+
*/
|
|
6079
|
+
getParent(pathOrID: Path | string): RG | null;
|
|
6080
|
+
/**
|
|
6081
|
+
* The normalized field list, as the `QueryBuilder` component would render it. Needed to
|
|
6082
|
+
* populate a field selector.
|
|
6083
|
+
*/
|
|
6084
|
+
getFields(): FullOptionList<F>;
|
|
6085
|
+
/**
|
|
6086
|
+
* The normalized combinator list, as the `QueryBuilder` component would render it. Needed to
|
|
6087
|
+
* populate a combinator selector.
|
|
6088
|
+
*/
|
|
6089
|
+
getCombinators(): FullOptionList<C>;
|
|
6090
|
+
/**
|
|
6091
|
+
* The field configuration for a field name. When the field isn't configured, returns the same
|
|
6092
|
+
* minimal fallback (`{ name, value, label }`, all set to the field name) that
|
|
6093
|
+
* {@link QueryManager.getRuleContext} reports as `fieldData`, so both access paths agree.
|
|
6094
|
+
*/
|
|
6095
|
+
getFieldData(field: string): F;
|
|
6096
|
+
/** The operator list for a field, mirroring `QueryBuilder`'s precedence. */
|
|
6097
|
+
getOperators(field: string): FullOptionList<O>;
|
|
6098
|
+
/** The value sources available for a field/operator pair. */
|
|
6099
|
+
getValueSources(field: string, operator: string): ValueSourceFullOptions;
|
|
6100
|
+
/** The match modes available for a field. */
|
|
6101
|
+
getMatchModes(field: string): MatchModeOptions;
|
|
6102
|
+
/** The value option list for a field/operator pair. */
|
|
6103
|
+
getValues(field: string, operator: string): FullOptionList<Option>;
|
|
6104
|
+
/** The value editor type for a field/operator pair. */
|
|
6105
|
+
getValueEditorType(field: string, operator: string): ValueEditorType;
|
|
6106
|
+
/**
|
|
6107
|
+
* Resolves everything about a rule that depends on the field/operator configuration—field data,
|
|
6108
|
+
* operators, value editor type, value list, value sources, match modes, and validation result.
|
|
6109
|
+
* Returns `null` when the target can't be resolved or isn't a rule.
|
|
6110
|
+
*
|
|
6111
|
+
* This is the same derivation the `useRule` hook performs, so a non-React implementation can
|
|
6112
|
+
* render a rule without reimplementing the configuration precedence rules.
|
|
6113
|
+
*/
|
|
6114
|
+
getRuleContext(pathOrID: Path | string): RuleContext<F> | null;
|
|
6115
|
+
/**
|
|
6116
|
+
* Resolves everything about a rule group that depends on the combinator configuration, plus its
|
|
6117
|
+
* validation result. Returns `null` when the target can't be resolved or isn't a group.
|
|
6118
|
+
*
|
|
6119
|
+
* This is the same derivation the `useRuleGroup` hook performs.
|
|
6120
|
+
*/
|
|
6121
|
+
getRuleGroupContext(pathOrID?: Path | string): RuleGroupContext<C> | null;
|
|
6122
|
+
/** Whether the current query uses independent combinators. */
|
|
6123
|
+
isIC(): boolean;
|
|
6124
|
+
/**
|
|
6125
|
+
* Returns the signature describing how the current query differs from `other`, as used by
|
|
6126
|
+
* this manager's history coalescing.
|
|
6127
|
+
*/
|
|
6128
|
+
signatureOf(other: RuleGroupTypeAny): string;
|
|
6129
|
+
/** Generates a {@link DiagnosticsResult}. Shorthand for `format('diagnostics')`. */
|
|
6130
|
+
diagnostics(): DiagnosticsResult;
|
|
6131
|
+
/**
|
|
6132
|
+
* Returns the current query, so `JSON.stringify(queryManager)` produces the same output as
|
|
6133
|
+
* `JSON.stringify(queryManager.getQuery())`.
|
|
6134
|
+
*/
|
|
6135
|
+
toJSON(): RG;
|
|
6136
|
+
/**
|
|
6137
|
+
* Returns a new manager with the same configuration and the current query converted to use
|
|
6138
|
+
* independent combinators. Idempotent, and never modifies this manager. As with
|
|
6139
|
+
* {@link QueryManager.clone}, subscribers and history are not carried over.
|
|
6140
|
+
*/
|
|
6141
|
+
toIC(): QueryManager<AsRuleGroup<ToRuleGroupTypeIC<RG>>, F, O, C>;
|
|
6142
|
+
/**
|
|
6143
|
+
* Returns a new manager with the same configuration and the current query converted to use a
|
|
6144
|
+
* single combinator per group. Idempotent, and never modifies this manager. As with
|
|
6145
|
+
* {@link QueryManager.clone}, subscribers and history are not carried over.
|
|
6146
|
+
*/
|
|
6147
|
+
fromIC(): QueryManager<AsRuleGroup<ToRuleGroupType<RG>>, F, O, C>;
|
|
6148
|
+
/**
|
|
6149
|
+
* Runs {@link transformQuery} against the current query and returns its result.
|
|
6150
|
+
*
|
|
6151
|
+
* Unlike {@link QueryManager.toIC}/{@link QueryManager.fromIC}, this returns the raw
|
|
6152
|
+
* transformed value rather than a new manager, since `transformQuery` can produce arbitrary
|
|
6153
|
+
* shapes that are no longer valid queries. This manager is never modified.
|
|
6154
|
+
*/
|
|
6155
|
+
transform<T = any>(options?: TransformQueryOptions<RG>): T;
|
|
6156
|
+
}
|
|
6157
|
+
//#endregion
|
|
6158
|
+
//#region src/utils/regenerateIDs.d.ts
|
|
6159
|
+
/**
|
|
6160
|
+
* Options object for {@link regenerateID}/{@link regenerateIDs}.
|
|
6161
|
+
*/
|
|
6162
|
+
interface RegenerateIdOptions {
|
|
6163
|
+
idGenerator?: () => string;
|
|
6164
|
+
}
|
|
6165
|
+
/**
|
|
6166
|
+
* Generates a new `id` property for a rule.
|
|
6167
|
+
*/
|
|
6168
|
+
declare const regenerateID: <R extends RuleType>(rule: R, { idGenerator }?: RegenerateIdOptions) => SetRequired<R, "id">;
|
|
6169
|
+
/**
|
|
6170
|
+
* Recursively generates new `id` properties for a rule group and all its rules and subgroups.
|
|
6171
|
+
*/
|
|
6172
|
+
declare const regenerateIDs: <RG>(subject: RG, { idGenerator }?: RegenerateIdOptions) => RG & {
|
|
6173
|
+
id: string;
|
|
6174
|
+
};
|
|
6175
|
+
//#endregion
|
|
6176
|
+
//#region src/utils/ruleFactory.d.ts
|
|
6177
|
+
/**
|
|
6178
|
+
* Everything {@link createRule} needs to produce a new rule. Each member corresponds to the
|
|
6179
|
+
* `QueryBuilder` prop (or `useQueryBuilderSetup` output) of the same name.
|
|
6180
|
+
*/
|
|
6181
|
+
interface CreateRuleOptions<F extends FullField = FullField> {
|
|
6182
|
+
fields: FullOptionList<F>;
|
|
6183
|
+
getDefaultField?: string | ((fieldsData: FullOptionList<F>) => string);
|
|
6184
|
+
/** Produces the default operator for a field, i.e. `resolveDefaultOperator` already bound. */
|
|
6185
|
+
getRuleDefaultOperator: (field: string) => string;
|
|
6186
|
+
/** Produces the value sources for a field/operator pair. */
|
|
6187
|
+
getValueSources: (field: string, operator: string, misc: {
|
|
6188
|
+
fieldData: F;
|
|
6189
|
+
}) => ValueSourceFullOptions;
|
|
6190
|
+
/** Produces the match modes for a field. */
|
|
6191
|
+
getMatchModes: (field: string, misc: {
|
|
6192
|
+
fieldData: F;
|
|
6193
|
+
}) => MatchModeOptions;
|
|
6194
|
+
/** Produces the default `value` for an otherwise-complete rule. */
|
|
6195
|
+
getRuleDefaultValue: (rule: RuleType) => unknown;
|
|
6196
|
+
idGenerator?: () => string;
|
|
6197
|
+
}
|
|
6198
|
+
/**
|
|
6199
|
+
* Creates a rule from the given configuration, applying the same precedence as the
|
|
6200
|
+
* `QueryBuilder` component. The `value` is computed in a second pass, once `field`, `operator`,
|
|
6201
|
+
* and `valueSource` are known, since the default value depends on all three.
|
|
6202
|
+
*
|
|
6203
|
+
* @group Query Tools
|
|
6204
|
+
*/
|
|
6205
|
+
declare const createRule: <F extends FullField = FullField>({ fields, getDefaultField, getRuleDefaultOperator, getValueSources, getMatchModes, getRuleDefaultValue, idGenerator }: CreateRuleOptions<F>) => RuleType;
|
|
6206
|
+
/**
|
|
6207
|
+
* Everything {@link createRuleGroup} needs to produce a new group.
|
|
6208
|
+
*/
|
|
6209
|
+
interface CreateRuleGroupOptions<C extends FullCombinator = FullCombinator> {
|
|
6210
|
+
combinators: FullOptionList<C>;
|
|
6211
|
+
/** When `true`, the new group contains one new rule. */
|
|
6212
|
+
addRuleToNewGroups?: boolean;
|
|
6213
|
+
/** Produces that rule, i.e. {@link createRule} already bound. */
|
|
6214
|
+
createRule: () => RuleType;
|
|
6215
|
+
idGenerator?: () => string;
|
|
6216
|
+
}
|
|
6217
|
+
/**
|
|
6218
|
+
* Creates a group from the given configuration. Pass `true` for `independentCombinators` to omit
|
|
6219
|
+
* the `combinator` property.
|
|
6220
|
+
*
|
|
6221
|
+
* The group's own `id` is generated _before_ any contained rule's, matching the order the
|
|
6222
|
+
* `QueryBuilder` component has always used. This is observable when `idGenerator` is
|
|
6223
|
+
* deterministic, as it often is in tests.
|
|
6224
|
+
*
|
|
6225
|
+
* @group Query Tools
|
|
6226
|
+
*/
|
|
6227
|
+
declare const createRuleGroup: <C extends FullCombinator = FullCombinator>({ combinators, addRuleToNewGroups, createRule: createRuleMain, idGenerator }: CreateRuleGroupOptions<C>, independentCombinators?: boolean) => RuleGroupTypeAny;
|
|
6228
|
+
//#endregion
|
|
6229
|
+
//#region src/utils/signature.d.ts
|
|
6230
|
+
/**
|
|
6231
|
+
* Signature returned when a change alters the _shape_ of the query—rules or groups added,
|
|
6232
|
+
* removed, moved, or reordered—rather than the properties of a single node. Structural changes
|
|
6233
|
+
* never coalesce with each other, so each one produces its own history entry.
|
|
6234
|
+
*/
|
|
6235
|
+
declare const structuralSignature = "~structural";
|
|
6236
|
+
/**
|
|
6237
|
+
* Signature returned when two queries differ by reference only, with no observable difference
|
|
6238
|
+
* in their properties.
|
|
6239
|
+
*/
|
|
6240
|
+
declare const unchangedSignature = "";
|
|
6241
|
+
/**
|
|
6242
|
+
* Describes _what changed_ between two versions of a query as a short string, so that
|
|
6243
|
+
* consecutive edits to the same property of the same rule (e.g. typing in a value editor) can
|
|
6244
|
+
* be recognized and coalesced into a single history entry.
|
|
6245
|
+
*
|
|
6246
|
+
* Returns {@link structuralSignature} for changes to the shape of the query, {@link unchangedSignature} when the
|
|
6247
|
+
* two queries differ by reference only, and `"<id>:<props>"` otherwise.
|
|
6248
|
+
*
|
|
6249
|
+
* The walk prunes on reference equality, so it costs O(depth) rather than O(size) for the
|
|
6250
|
+
* single-node edits that make up the overwhelming majority of changes.
|
|
6251
|
+
*
|
|
6252
|
+
* Note that this relies on the structural sharing that Immer—and therefore every query
|
|
6253
|
+
* produced by RQB's own update functions—guarantees: nodes that did not change keep their
|
|
6254
|
+
* identity. A query that has been wholly rebuilt (deep-cloned, round-tripped through JSON,
|
|
6255
|
+
* re-parsed from a string) shares no identity with its predecessor, so it is reported as
|
|
6256
|
+
* {@link structuralSignature} and will not coalesce. That is a graceful degradation—every change simply
|
|
6257
|
+
* gets its own history entry—but controlled components that clone the query on every change
|
|
6258
|
+
* will not benefit from coalescing.
|
|
6259
|
+
*/
|
|
6260
|
+
declare const signatureOf: (prev: RuleGroupTypeAny, next: RuleGroupTypeAny) => string;
|
|
6261
|
+
//#endregion
|
|
6262
|
+
export { AbortInfo, AbortOptions, AbortReason, AccessibleDescriptionGenerator, ActionElementEventHandler, AddMethod, AddOptions, Arity, BaseFullOption, BaseOption, BaseOptionMap, BaseTranslation, BaseTranslationWithLabel, BaseTranslationWithPlaceholders, BaseTranslations, BaseTranslationsFull, Classname, ClassnameCondition, ClassnameSpec, Classnames, Combinator, CombinatorByValue, CommonRuleAndGroupProperties, CommonRuleSubComponentProps, ConstituentWordOrder, ConstituentWordOrderString, CreateRuleGroupOptions, CreateRuleOptions, DefaultCombinator, DefaultCombinatorExtended, DefaultCombinatorName, DefaultCombinatorNameExtended, DefaultCombinators, DefaultCombinatorsExtended, DefaultMatchModes, DefaultOperator, DefaultOperatorName, DefaultOperators, DefaultRuleGroupArray, DefaultRuleGroupICArray, DefaultRuleGroupType, DefaultRuleGroupTypeAny, DefaultRuleGroupTypeIC, DefaultRuleOrGroupArray, DefaultRuleType, DeriveClassNamesOptions, DiagnosticEntry, DiagnosticsFieldSummaryEntry, DiagnosticsResult, DiagnosticsStats, DndClassNameState, DndDropTargetType, DragCollection, DraggedItem, DropCollection, DropEffect, DropResult, ExportFormat, ExportObjectFormats, ExportOperatorMap, ExpressionNode, Field, FieldByValue, FindPathReturnType, FlexibleOption, FlexibleOptionGroup, FlexibleOptionList, FlexibleOptionListProp, FormatQueryFinalOptions, FormatQueryOptions, FormatQueryValidateRule, FullCombinator, FullField, FullOperator, FullOption, FullOptionList, FullOptionMap, FullOptionRecord, GenericizeRuleGroupType, GetOptionIdentifierType, GetOptionType, GetRuleDefaultValueOptions, GetRuleGroupType, GetRuleTypeFromGroupWithFieldAndOperator, GroupMethod, GroupOptions, GroupVariantCondition, GuardOptions, InputType, InsertMethod, InsertOptions, type JsonLogicAll, type JsonLogicAnd, type JsonLogicDoubleNegation, type JsonLogicEqual, type JsonLogicGreaterThan, type JsonLogicGreaterThanOrEqual, type JsonLogicInArray, type JsonLogicInString, type JsonLogicLessThan, type JsonLogicLessThanOrEqual, type JsonLogicNegation, type JsonLogicNone, type JsonLogicNotEqual, type JsonLogicOr, type JsonLogicReservedOperations, type JsonLogicRulesLogic, type JsonLogicSome, type JsonLogicStrictEqual, type JsonLogicStrictNotEqual, type JsonLogicVar, LogType, MatchConfig, MatchMode, MatchModeOptions, MoveMethod, MoveOptions, NLTranslationKey, NLTranslations, NameLabelPair, Operator, OperatorByValue, Option, OptionGroup, OptionList, OuterClassNameOptions, OuterClassNameOptionsBase, ParameterizedNamedSQL, ParameterizedSQL, ParseNumberMethod, ParseNumberOptions, ParseNumbersPropConfig, Path, PathInfo, Placeholder, PrepareOptionListParams, PreparedOptionList, PreparerOptions, QueryActionCallbacks, QueryActionHandlers, QueryActions, QueryActionsConfig, QueryBuilderClassNameState, QueryBuilderFlags, QueryHistoryOptions, QueryManager, QueryManagerError, QueryManagerOptions, QueryNode, QueryValidator, RQBJsonLogic, RQBJsonLogicEndsWith, RQBJsonLogicStartsWith, RQBJsonLogicVar, RegenerateIdOptions, RemoveMethod, RemoveNullability, RemoveOptions, ResolveOptionListOptions, RuleClassNameState, RuleClassnameKey, RuleContext, RuleContextResolvers, RuleDiagnosticsResult, RuleFacet, RuleGroupArray, RuleGroupClassnameKey, RuleGroupContext, RuleGroupDiagnosticsArray, RuleGroupDiagnosticsResult, RuleGroupICArray, RuleGroupICDiagnosticsArray, RuleGroupICDiagnosticsResult, RuleGroupProcessor, RuleGroupType, RuleGroupTypeAny, RuleGroupTypeIC, RuleOrGroupArray, RuleProcessor, RuleType, RuleValidator, SQLPreset, StrictOptions, StringUnionToFlexibleOptionArray, StringUnionToFullOptionArray, TestID, ToFlexibleOption, ToFullOption, ToRuleGroupType, ToRuleGroupTypeIC, TransformQueryOptions, UpdateMethod, UpdateOptions, UpdateValueMap, UpdateableProperties, ValidationMap, ValidationResult, ValueChangeEventHandler, ValueEditorType, ValueOption, ValueProcessor, ValueProcessorByRule, ValueProcessorLegacy, ValueProcessorOptions, ValueSource, ValueSourceFlexibleOptions, ValueSourceFullOptions, ValueSources, WalkOptions, WithRequired, WithUnknownIndex, add, addInPlace, betweenOperators, bigIntJsonParseReviver, bigIntJsonStringifyReplacer, celCombinatorMap, clsx, coerceBigIntValue, coerceInputType, convertFromIC, convertQuery, convertToIC, createQueryActions, createRule, createRuleGroup, cypherCombinatorMap, defaultCELValueProcessor, defaultCoalesceMs, defaultCombinatorLabelMap, defaultCombinators, defaultCombinatorsExtended, defaultControlClassnames, defaultExportOperatorMap, defaultJoinChar, defaultMatchModes, defaultMaxHistory, defaultMongoDBValueProcessor, defaultNLTranslations, defaultOperatorLabelMap, defaultOperatorNegationMap, defaultOperatorProcessorNL, defaultOperatorProcessorSQL, defaultOperators, defaultPlaceholderFieldGroupLabel, defaultPlaceholderFieldLabel, defaultPlaceholderFieldName, defaultPlaceholderLabel, defaultPlaceholderName, defaultPlaceholderOperatorGroupLabel, defaultPlaceholderOperatorLabel, defaultPlaceholderOperatorName, defaultPlaceholderValueGroupLabel, defaultPlaceholderValueLabel, defaultPlaceholderValueName, defaultRuleGroupProcessorCEL, defaultRuleGroupProcessorCypher, defaultRuleGroupProcessorDiagnostics, defaultRuleGroupProcessorDrizzle, defaultRuleGroupProcessorElasticSearch, defaultRuleGroupProcessorGremlin, defaultRuleGroupProcessorJSONata, defaultRuleGroupProcessorJsonLogic, defaultRuleGroupProcessorLDAP, defaultRuleGroupProcessorMongoDB, defaultRuleGroupProcessorMongoDBQuery, defaultRuleGroupProcessorNL, defaultRuleGroupProcessorParameterized, defaultRuleGroupProcessorPrisma, defaultRuleGroupProcessorSPARQL, defaultRuleGroupProcessorSQL, defaultRuleGroupProcessorSequelize, defaultRuleGroupProcessorSpEL, defaultRuleGroupProcessorTanStackDB, defaultRuleProcessorCEL, defaultRuleProcessorCypher, defaultRuleProcessorDrizzle, defaultRuleProcessorElasticSearch, defaultRuleProcessorGremlin, defaultRuleProcessorJSONata, defaultRuleProcessorJsonLogic, defaultRuleProcessorLDAP, defaultRuleProcessorMongoDB, defaultRuleProcessorMongoDBQuery, defaultRuleProcessorNL, defaultRuleProcessorParameterized, defaultRuleProcessorPrisma, defaultRuleProcessorSPARQL, defaultRuleProcessorSQL, defaultRuleProcessorSequelize, defaultRuleProcessorSpEL, defaultRuleProcessorTanStackDB, defaultSpELValueProcessor, defaultTranslations, defaultValidator, defaultValueProcessor, defaultValueProcessorByRule, defaultValueProcessorCELByRule, defaultValueProcessorMongoDBByRule, defaultValueProcessorNL, defaultValueProcessorSpELByRule, derivePathInfo, deriveQueryBuilderClassNames, deriveRuleClassName, deriveRuleClassNames, deriveRuleContext, deriveRuleGroupClassNames, deriveRuleGroupContext, deriveRuleGroupOuterClassName, deriveRuleOuterClassName, exceedsMaxLevels, filterFieldsByComparator, findID, findPath, formatQuery, formatQueryOptionPresets, generateAccessibleDescription, generateID, getCommonAncestorPath, getFieldData, getFirstOption, getGuardAbortReason, getLikeWildcards, getMatchModesUtil, getMultiValueUpdate, getNLTranslataion, getOption, getParametersAsList, getParentPath, getParseNumberMethod, getPathOfID, getQuoteFieldNamesWithArray, getQuotedFieldName, getRuleDefaultValue$1 as getRuleDefaultValue, getRuleGroupCombinator, getRuleInputType, getRuleValidationResult, getRuleValueEditorType, getRuleValueSourceOptions, getRuleValues, getSQLConcat, getSubqueryElementAlias, getValidationClassNames, getValueEditorReset, getValueSelectorUpdate, getValueSourcesUtil, group, groupInPlace, groupInvalidReasons, hideValueControlsForOperator, inOperators, insert, insertInPlace, isAncestor, isBetweenOperator, isFlexibleOptionArray, isFlexibleOptionGroupArray, isFullOptionArray, isFullOptionGroupArray, isOptionGroupArray, isPojo, isRuleGroup, isRuleGroupType, isRuleGroupTypeIC, isRuleOrGroupValid, isRuleType, isUnsafeKey, isValidValue, isValidationResult, isValueProcessorLegacy, joinWith, jsonLogicAdditionalOperators, lc, mapSQLOperator, mergeAnyTranslation, mergeAnyTranslations, mergeClassnames, mongoDbFallback, mongoOperators, move, moveInPlace, normalizeConstituentWordOrder, normalizeValueSelectorValue, nullFreeArray, nullOperators, nullOrUndefinedOrEmpty, numericRegex, numerifyValues, objectEntries, objectKeys, parseNumber, pathIsDisabled, pathIsDisabledByPaths, pathsAreEqual, preferAnyProp, preferFlagProps, preferProp, prepareOptionList, prepareRule, prepareRuleGroup, prepareRuleOrGroup, prismaFallback, prismaOperators, processMatchMode, queryBuilderFlagDefaults, regenerateID, regenerateIDs, relationalOperators, remove, removeInPlace, resolveCandidateQuery, resolveDefaultOperator, resolveOperatorList, resolveValueEditorType, resolveValueList, rootPath, shouldRenderAsNumber, signatureOf, sparqlVar, splitBy, sqlDialectPresets, standardClassnames, strictAbortReasons, stripParamPrefix, structuralSignature, subqueryElementAliasBase, substringOperators, toArray, toFlatOptionArray, toFullOption, toFullOptionList, toFullOptionMap, transformQuery, trimIfString, unchangedSignature, uniqByIdentifier, uniqByName, uniqOptGroups, uniqOptList, update, updateInPlace, uuidV4regex, withParamPrefix, wrapLikeFragment };
|
|
4908
6263
|
//# sourceMappingURL=react-querybuilder_core.cjs.production.d.ts.map
|