UNPKG

react-querybuilder

Version:

React Query Builder component for constructing queries and filters, with utilities for executing them in various database and evaluation contexts

181 lines (180 loc) 6.13 kB
import type { OptionList, Path, RuleGroupTypeAny, RuleType, UpdateableProperties, ValueSources } from "../types/index.noReact.mjs"; /** * Options for {@link add}. * * @group Query Tools */ export interface AddOptions { /** * If the query extends `RuleGroupTypeIC` (i.e. the query has independent * combinators), then the first combinator in this list will be inserted * before the new rule/group if the parent group is not empty. This option * is overridden by `combinatorPreceding`. */ combinators?: OptionList; /** * If the query extends `RuleGroupTypeIC` (i.e. the query has independent * combinators), then this combinator will be inserted before the new rule/group * if the parent group is not empty. This option will supersede `combinators`. */ combinatorPreceding?: string; /** * ID generator. */ idGenerator?: () => string; } /** * Adds a rule or group to a query. * @returns The new query with the rule or group added. * * @group Query Tools */ export declare const add: <RG extends RuleGroupTypeAny>(query: RG, ruleOrGroup: RG | RuleType, parentPath: Path, { combinators, combinatorPreceding, idGenerator }?: AddOptions) => RG; /** * Options for {@link update}. * * @group Query Tools */ export interface UpdateOptions { /** * When updating the `field` of a rule, the rule's `operator`, `value`, and `valueSource` * will be reset to their respective defaults. Defaults to `true`. */ resetOnFieldChange?: boolean; /** * When updating the `operator` of a rule, the rule's `value` and `valueSource` * will be reset to their respective defaults. Defaults to `false`. */ resetOnOperatorChange?: boolean; /** * Determines the default operator name for a given field. */ getRuleDefaultOperator?: (field: string) => string; /** * Determines the valid value sources for a given field and operator. */ getValueSources?: (field: string, operator: string) => ValueSources; /** * Gets the default value for a given rule, in case the value needs to be reset. */ getRuleDefaultValue?: (rule: RuleType) => any; } /** * Updates a property of a rule or group within a query. * @returns The new query with the rule or group property updated. * * @group Query Tools */ export declare const update: <RG extends RuleGroupTypeAny>(query: RG, prop: UpdateableProperties, value: any, path: Path, { resetOnFieldChange, resetOnOperatorChange, getRuleDefaultOperator, getValueSources, getRuleDefaultValue }?: UpdateOptions) => RG; /** * Removes a rule or group from a query. * @returns The new query with the rule or group removed. * * @group Query Tools */ export declare const remove: <RG extends RuleGroupTypeAny>(query: RG, path: Path) => RG; /** * Options for {@link move}. * * @group Query Tools */ export interface MoveOptions { /** * When `true`, the source rule/group will not be removed from its original path. */ clone?: boolean; /** * If the query extends `RuleGroupTypeIC` (i.e. the query is using independent * combinators), then the first combinator in this list will be inserted before * the rule/group if necessary. */ combinators?: OptionList; /** * ID generator. */ idGenerator?: () => string; } /** * Moves a rule or group from one path to another. In the options parameter, pass * `{ clone: true }` to copy instead of move. * @returns The new query with the rule or group moved or cloned. * * @group Query Tools */ export declare const move: <RG extends RuleGroupTypeAny>(query: RG, oldPath: Path, newPath: Path | "up" | "down", { clone, combinators, idGenerator }?: MoveOptions) => RG; /** * Options for {@link insert}. * * @group Query Tools */ export interface InsertOptions { /** * If the query extends `RuleGroupTypeIC` (i.e. the query has independent * combinators), then the first combinator in this list will be inserted * before the new rule/group if the parent group is not empty. This option * is overridden by `combinatorPreceding`. */ combinators?: OptionList; /** * If the query extends `RuleGroupTypeIC` (i.e. the query has independent * combinators), then this combinator will be inserted before the new rule/group * if the parent group is not empty and the new rule/group is not the first in the * group (`path.at(-1) > 0`). This option will supersede `combinators`. */ combinatorPreceding?: string; /** * If the query extends `RuleGroupTypeIC` (i.e. the query has independent * combinators), then this combinator will be inserted after the new rule/group * if the parent group is not empty and the new rule/group is the first in the * group (`path.at(-1) === 0`). This option will supersede `combinators`. */ combinatorSucceeding?: string; /** * ID generator. * * @default generateID */ idGenerator?: () => string; /** * When `true`, the new rule/group will replace the rule/group at `path`. */ replace?: boolean; } /** * Inserts a rule or group into a query. * @returns The new query with the rule or group inserted. * * @group Query Tools */ export declare const insert: <RG extends RuleGroupTypeAny>(query: RG, ruleOrGroup: RG | RuleType, path: number[], { combinators, combinatorPreceding, combinatorSucceeding, idGenerator, replace }?: InsertOptions) => RG; /** * Options for {@link group}. * * @group Query Tools */ export interface GroupOptions { /** * When `true`, the source rule/group will not be removed from its original path. */ clone?: boolean; /** * If the query extends `RuleGroupTypeIC` (i.e. the query is using independent * combinators), then the first combinator in this list will be inserted between * the two rules/groups. */ combinators?: OptionList; /** * ID generator. */ idGenerator?: () => string; } /** * Creates a new group at a target path with its `rules` array containing the current * objects at the target path and the source path. In the options parameter, pass * `{ clone: true }` to copy the source rule/group instead of move. * * @returns The new query with the rules or groups grouped. * * @group Query Tools */ export declare const group: <RG extends RuleGroupTypeAny>(query: RG, sourcePath: Path, targetPath: Path, { clone, combinators, idGenerator }?: GroupOptions) => RG;