GhostQueryBuilder reference
Package: @ghostvue/vue. Status: experimental (stability policy).
Headless editor for a saved, grouped filter: a tree of conditions and nested AND/OR groups with NOT on a whole group, built from GhostSelect, GhostRadioGroup, GhostCheckbox, GhostInput, GhostNumberInput and GhostDatePicker. Edits change only the draft; Apply validates it and emits a frozen, JSON-serializable expression with an increasing revision, and an invalid draft keeps the last applied expression. Restored filters keep unknown or retired fields in place with an explanation until the user repairs or removes them. Ships choice, yes/no, date, text and number value editors that offer only the operators of their field type, with "From" and "To" controls for ranges, and the `value` slot for app-supplied editors. `0` and `false` are ordinary values, and a cleared input removes the value.
Generated from the component manifest. Edit the manifest or Vue source, then rebuild the docs.
Props
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
applyDefault | boolean | false | No | When the default expression has no blocking issue, it is also the initial applied expression at revision `1`. No `apply` event is emitted. |
createId | ((kind: 'group' | 'rule') => string) | — | No | Mints ids for nodes the user adds. Never called during setup, so a random or counter id is SSR-safe. A returned duplicate is a development error and is replaced. |
defaultExpression | unknown | — | No | Initial draft, read once at setup through `validateQueryExpression`. Malformed input starts an empty draft and warns in development. |
disabled | boolean | false | No | Disables every control. Programmatic `restore`, `reset`, `clear` and `apply` still work. |
fields | Fields | — | Yes | Consumer-owned schema. Reactive: a change revalidates the draft and never changes the applied expression. |
maxDepth | number | 3 | No | Nesting levels the user can create, counting the root as 1. |
messages | Partial<GhostQueryBuilderMessages> | — | No | Reactive overrides for every component-owned string. Omitted entries use the English defaults. |
readonly | boolean | false | No | Renders the draft as static text with no form controls and no add or remove actions. `disabled` takes precedence. |
Emits
| Name | Payload | Description |
|---|---|---|
apply | GhostQueryApplyEvent<Fields> | After every successful Apply, including a programmatic one, a restore with `apply: true` and an Apply of an unchanged draft. The expression is a fresh, frozen, deep copy; `revision` increases by one each time. A failed Apply emits nothing. |
Models
None declared.
Slots
| Name | Description |
|---|---|
actions | Renders after the root group, typically Apply, Reset and the app's Save button. |
empty | Renders inside an empty root group, before its Add condition button. |
value | Replaces the value editor of every rule that has a usable field and an operator that takes a value. |
Slot props: actions
None declared.
Slot props: empty
None declared.
Slot props: value
None declared.
Exposed members
| Name | Type | Description |
|---|---|---|
applied | { readonly version: 1; readonly root: { readonly kind: 'group'; readonly id: string; readonly combinator: 'and' | 'or'; readonly not: boolean; readonly children: readonly (any | GhostQueryDeepReadonly<import('./ghost-query-builder').GhostQueryRuleForField<Fields[number]>>)[]; }; } | null | Last applied expression, or `null` before the first Apply. |
appliedIssues | readonly GhostQueryIssue[] | Issues found when `applied` is revalidated against the current `fields`. |
apply | (options?: { focus?: boolean; }) => GhostQueryApplyResult<Fields> | Validates the draft. Success replaces the applied expression and emits `apply`. Failure keeps it, shows every issue and, unless `focus: false`, focuses the first invalid control. |
clear | () => void | Replaces the draft with an empty root group, keeping the root id. Does not apply. |
dirty | boolean | `true` when the draft differs from `applied` (or from an empty root when nothing is applied). |
draft | { readonly version: 1; readonly root: { readonly kind: 'group'; readonly id: string; readonly combinator: 'and' | 'or'; readonly not: boolean; readonly children: readonly ({ readonly kind: 'rule'; readonly id: string; readonly field: string | null; readonly operator: string | null; readonly value?: string | number | boolean | readonly string[] | { readonly start: string; readonly end: string; } | { readonly min: number; readonly max: number; } | { readonly start: string | null; readonly end: string | null; } | { readonly min: number | null; readonly max: number | null; } | { readonly kind: 'stored'; readonly raw: unknown; }; } | any)[]; }; } | Current draft. Read-only; edit through the UI or `restore`. |
issues | readonly GhostQueryIssue[] | Current blocking issues of the draft, in document order, whether or not they are displayed yet. |
reset | () => void | Replaces the draft with the applied expression, else the last restored or default input, else an empty root. |
restore | (input: unknown, options?: { apply?: boolean; }) => GhostQueryRestoreResult | Replaces the draft with a parsed expression. With `apply: true` it then applies without moving focus. Malformed input changes nothing. |
revision | number | Revision of `applied`; `0` before the first Apply. |
Parts and data attributes
| Attribute | Value | Description |
|---|---|---|
data-part | root | The element with role="group" named by the consumer's aria-label or aria-labelledby. Consumer class, style and attributes land here. |
data-part | group | Every group, the root group included. Nested groups have role="group" named by their group-name heading. |
data-part | group-header | Header of a group: its name, the Match radio group, the NOT checkbox and Remove group. |
data-part | group-name | Visible heading that names a nested group, such as "Group 2: Any condition (OR)". |
data-part | combinator | The Match label and its All/Any GhostRadioGroup; in read-only mode, the root's combinator text. |
data-part | not | The label wrapping the NOT GhostCheckbox; in read-only mode, the root's NOT text. |
data-part | children | The <ul> of a group's conditions and nested groups. Each item is an <li>. |
data-part | connector | Visible AND/OR text between the items of a group, aria-hidden because the group name states it. |
data-part | rule | A condition: role="group" named "Condition N", holding the field, operator and value parts and its remove button. |
data-part | field | Wrapper of a condition's Field GhostSelect, its label and its issue; static text in read-only mode. Its popup, and the Operator popup, are portaled to <body> and carry the class ghost-query-builder-listbox. |
data-part | operator | Wrapper of a condition's Operator GhostSelect, or the operator as static text for an unavailable field or in read-only mode. |
data-part | value | Wrapper of a condition's value editor (the `value` slot or the built-in editor), its label and its issue; static text in read-only mode or for an unavailable field. A range editor holds a role="group" named by the Value label with "From" and "To" labels and controls. Date popups are portaled to <body> and carry the class ghost-query-builder-calendar; choice popups carry ghost-query-builder-listbox. |
data-part | value-text | Text of a retained value the built-in editor cannot show in its control, such as a restored unparseable date or a value kept across an operator change. It is part of the control's description and disappears once an edit replaces the value. |
data-part | label | Visible Field, Operator and Value label of a condition's control, and the From and To labels of a range editor, referenced by the control's aria-labelledby. |
data-part | remove | Native button that removes a condition or a nested group. Its name includes the position and a summary. |
data-part | add-rule | Native button that appends a condition to a group and focuses its Field control. |
data-part | add-group | Native button that appends a group with one condition. Absent at maxDepth. |
data-part | issue | Text of a shown issue, rendered next to its control and referenced by that control's aria-describedby. |
data-part | empty | Default content inside an empty root group (messages.emptyRoot), replaced by the `empty` slot. |
data-part | status | Visually hidden polite status region that announces additions, removals, Apply results and restore results. It starts empty. |
data-combinator | and, or | On groups: the group's combinator. |
data-negated | present | Present on groups with NOT turned on. |
data-depth | 1, 2, 3 | On groups and rules: nesting level, counting the root group as 1. Restored filters can be deeper than maxDepth. |
data-invalid | present | Present on rules and groups that have a shown issue. |
data-retired | present | Present on a rule whose stored field is unknown, retired, duplicated or set up incorrectly. |
data-disabled | present | Present on the root while disabled. |
data-readonly | present | Present on the root while read-only (and not disabled). |
CSS variables
None declared.
Accessibility
Role: group. APG pattern: https://www.w3.org/WAI/ARIA/apg/patterns/.
Required ARIA attributes: aria-label, aria-labelledby.
Keyboard
Verification
Each category is reviewed separately. Automated keyboard and axe results do not attest manual or assistive-technology review.
| Category | Status | Evidence |
|---|---|---|
| Automated keyboard | Passed | Every declared key maps to a Chromium browser test that CI runs and requires to pass on every commit. |
| Manual interaction | Not reviewed | No review recorded. |
| Assistive technology | Not reviewed | No review recorded. |
Examples
query-builder/custom-editor
A `value` slot editor for the Assignee field proposes typed values and reports half-typed text as pending, which blocks Apply; other fields keep the built-in editor.
query-builder/issue-triage
Apply `Open AND (High priority OR Overdue)` to five sample issues, save the applied filter separately, and reopen it with the same matching IDs. A saved filter with a retired Severity rule blocks Apply until it is repaired, the Assignee field uses a custom person picker, and a slower, older search never replaces newer results.
query-builder/text-filter
Build `Title contains "crash" AND (Assignee is missing OR Reporter equals "ana")` with the keyboard, apply it, and see the applied expression and revision. An empty text value blocks Apply and focus moves to it.