API Reference

This reference covers the stable surface used by the web docs and examples.

Core types

TypeDescription
FieldSchemaField name, label, type, values, default operator, and default value.
FilterRuleA single rule with field, operator, value, and optional not.
FilterGroupA group with combinator, optional not, and nested children (rules and groups).
FilterGroupICInline-combinator group where combinators sit between children.
FilterAlias for the root FilterGroup.
FilterICAlias for the root FilterGroupIC.
ValidationResult{ valid, errors } after schema validation.
MutationAdapterAdapter that dispatches mutations to standard or IC tree functions.

Core helpers

HelperDescription
createFilterCreate an empty filter group.
createRule / createGroupCreate a rule or group with generated or provided id.
addRule, removeRule, updateRule, moveRule, cloneRuleMutate rules immutably.
addGroup, removeGroup, updateGroup, cloneGroupMutate nested groups immutably.
negateRule, negateGroupToggle not on a rule or group.
validateCheck fields, operators, values, combinators, and groups.
toJSON, fromJSONSerialize filters for storage and URLs.
traverse, walk, findById, findParent, getPath, flattenRulesTree traversal utilities.
mapTree, updateByIdImmutable tree mapping and updates.
isFilterGroup, isFilterRule, isLockedType guards and lock check.
generateIdDefault ID generator.

IC tree helpers

HelperDescription
addRuleIC, removeRuleIC, updateRuleIC, moveRuleIC, cloneRuleICIC tree rule mutations.
addGroupIC, removeGroupIC, updateGroupIC, cloneGroupICIC tree group mutations.
setCombinatorICSet the combinator between two children.
convertToIC, convertFromICConvert between standard and IC tree types.
isFilterGroupICType guard for FilterGroupIC.
icMutationAdapterMutation adapter for IC trees.
standardMutationAdapterMutation adapter for standard trees.

DSL and SQL helpers

HelperDescription
formatDSLConvert a Filter into text DSL.
parseDSLParse text into a Filter (throws on error).
tryParseDSLParse text, returning { filter, errors } instead of throwing.
tokenize / parseTokenize and parse DSL into an AST.
filterToAst / astToFilterConvert between Filter and AST.
getDslCompletionsBuild completion items for DSL editors.

Query exporters

ExportSub-pathOutput
toSQL@x-filter/core/sql{ sql, params }
toJsonLogic@x-filter/core/jsonlogicJsonLogic object
toMongoQuery@x-filter/core/mongodbMongoDB query object
toElasticQuery@x-filter/core/elasticsearchElasticsearch query object

toJsonLogic, toMongoQuery, and toElasticQuery are also re-exported from the main entry point.

React hooks

HookDescription
useFilterBuilderControlled/uncontrolled mutation helpers for filters.
useFilterBuilderOrchestratorOrchestrate builder state, DSL, validation, and history in one hook.
useFilterViewModelBuild accessible view models for adapter rendering.
useFilterValidationValidate filters against schema, returning errors keyed by node id.
useFilterUrlSyncEncode and decode filters through URL search params.
useFilterHistoryUndo/redo history for filter state.
useFilterPresetsSave, load, and delete filter presets.
useFilterKeyboardNavARIA tree keyboard navigation with roving tabindex.
useDslEditorManage DSL draft text, commits, and parse errors.
useDslEditorInteractionInteraction helpers for the DSL token editor (completion, cursor).
useReorderContractShared move and drop rules for nested groups.
useIsMobileResponsive breakpoint hook (defaults to 640px, SSR-safe).

React utilities

ExportDescription
enUS, zhCN, jaJP, localesBuilt-in locale packs for i18n.
parseFilterInputParse JSON or DSL strings into a Filter.
findSchemaField, findOperator, getFieldOperatorsSchema lookup helpers.
resolveLabels, resolveRuleRender, resolveGroupRenderRender decision helpers.
getDefaultRuleUpdatesForFieldGet default operator/value updates when field changes.
dslToTokenChips, foldPendingIntoDslDSL token chip utilities.
asArrayValue, asPairValue, asStringValue, parseNumberInput, updatePairValueValue coercion helpers.

Adapter components

AntdFilterBuilder and ShadcnFilterBuilder share the same prop contract:

type FilterBuilderProps = {
  schema: FieldSchema[];
  value?: Filter;
  defaultValue?: Filter;
  onChange?: (filter: Filter) => void;
  errors?: Record<string, ValidationError[]>;
  dsl?: boolean;
  dnd?: boolean;
  mode?: 'standard' | 'ic';
  labels?: FilterBuilderLabels;
  readOnly?: boolean;
  slots?: FilterBuilderSlots;
  classNames?: FilterBuilderClassNames;
};

Atomic components

Both adapters export composable atomic components for custom layouts:

AntdShadcnPurpose
AntdFilterGroupShadcnFilterGroupRender a group block
AntdFilterRuleShadcnFilterRuleRender a rule row
AntdFieldSelectorShadcnFieldSelectorField dropdown
AntdOperatorSelectorShadcnOperatorSelectorOperator dropdown
AntdCombinatorSelectorShadcnCombinatorSelectorCombinator (AND/OR) selector
AntdValueEditorShadcnValueEditorValue input editor
AntdNotToggleShadcnNotToggleNOT toggle
AntdDslEditorShadcnDslEditorDSL text editor
ShadcnDslTokenInputDSL token chip input (shadcn only)
AntdCompletionMenuShadcnCompletionMenuDSL autocomplete menu
AntdImportFilterDialogShadcnImportFilterDialogImport JSON/DSL dialog
ShadcnPresetBarPreset save/load bar (shadcn only)
ShadcnInlineCombinatorInline combinator for IC mode (shadcn only)
SortableFilterContextSortableFilterContextDnD context provider
SortableFilterItemSortableFilterItemDnD sortable item wrapper