An open source design system that's fully customizable and agent ready
TypeScript
feat(PowerSearch): the sheet presentation edits a draft that Done applies, and asks before discarding a changed one (#9895)
Xinzi Zhou4b856700394a
diff --git a/.changeset/powersearch-presentation-stable.md b/.changeset/powersearch-presentation-stable.mdindex c85e656840..1f5269f4d3 100644--- a/.changeset/powersearch-presentation-stable.md+++ b/.changeset/powersearch-presentation-stable.md@@ -2,8 +2,8 @@'@astryxdesign/core': patch----[feat] PowerSearch gains a touch surface through a new `presentation` prop, `'popover' | 'bottom-sheet' | 'adaptive'`, typed by the new exported `PowerSearchPresentation`, with `'adaptive'` the default. `bottom-sheet` makes the whole field one trigger showing display-only filter tokens, and moves filter editing into a flow of tall modal sheets that stack: each step opens above the one that led to it, and dismissing a step reveals the one beneath, so no sheet has a Back action. A Filters sheet lists the active filters as rows that edit a filter, each with a trailing remove button, under a fixed header with Add filter and over a fixed footer with Clear all and Done; with no filter it shows one centered Add filter. Clear all asks for confirmation, removes the editable filters, keeps read-only ones, and leaves Filters open. An Add filter sheet lists the fields grouped (searchable from eight fields), or the content search with the field typeahead's suggestions listed inline, and leaves its search unfocused until tapped; a field whose only operator takes no value adds at once. A value step stages operator → value and confirms from its footer, the editor on the sheet's surface, or in muted sections beside the operator choice. Closed vocabularies are full-width rows, numbers stage as typed, and `string_list` / `entity_list` values edit through the Tokenizer's own sheet presentation titled with the field label. `adaptive` uses the sheet on compact coarse-pointer screens and the popover otherwise, resolved the same way Selector resolves it. The sheet flow loads on demand, only when a field presents it. New `@astryx.powersearch.sheet.*` catalog keys for the sheets' strings; no new theming target.+[feat] PowerSearch gains a touch surface through a new `presentation` prop, `'popover' | 'bottom-sheet' | 'adaptive'`, typed by the new exported `PowerSearchPresentation`, with `'adaptive'` the default. `bottom-sheet` makes the whole field one trigger showing display-only filter tokens, and moves filter editing into a flow of tall modal sheets that stack: each step opens above the one that led to it, and dismissing a step reveals the one beneath, so no sheet has a Back action. A Filters sheet lists the active filters as rows that edit a filter, each with a trailing remove button, under a fixed header with Add filter and over a fixed footer with Clear all and Done; with no filter it shows one centered Add filter. The flow edits a draft of the filter list: adding, editing and removing a filter, and Clear all, change the draft, and Done applies it by calling `onChange` once per edit, in order, each with the list after that edit; a swipe, scrim or Escape close of a changed draft asks before discarding it, and a clean one closes directly. Clear all asks for confirmation, removes the editable filters, keeps read-only ones, and leaves Filters open. An Add filter sheet lists the fields grouped (searchable from eight fields), or the content search with the field typeahead's suggestions listed inline, and leaves its search unfocused until tapped; a field whose only operator takes no value adds at once. A value step stages operator → value and confirms from its footer, the editor on the sheet's surface, or in muted sections beside the operator choice. Closed vocabularies are full-width rows, numbers stage as typed, and `string_list` / `entity_list` values edit through the Tokenizer's own sheet presentation titled with the field label. `adaptive` uses the sheet on compact coarse-pointer screens and the popover otherwise, resolved the same way Selector resolves it. The sheet flow loads on demand, only when a field presents it. New `@astryx.powersearch.sheet.*` catalog keys for the sheets' strings; no new theming target.-The API change is additive: the prop is new and optional, and no existing prop, type or export is removed or narrowed. The behavior changes only on compact coarse-pointer screens (phones), which is what `'adaptive'` is for: there a PowerSearch with no `presentation` shows the trigger and the sheet flow, a filter reaches `onChange` when its value step confirms, and `menuWidth` and `tokenOverflowBehavior` have no surface, with a development warning that names them. With a mouse or trackpad, on a screen that is not compact, in the server render and while hydrating, nothing changes. Pass `presentation="popover"` to keep the previous behavior on every device. Shipping this default in a patch is a product decision of the engineering owner, agreed with the owner of the compatibility policy.+The API change is additive: the prop is new and optional, and no existing prop, type or export is removed or narrowed. The behavior changes only on compact coarse-pointer screens (phones), which is what `'adaptive'` is for: there a PowerSearch with no `presentation` shows the trigger and the sheet flow, a filter reaches `onChange` when Done applies the sheet's draft, and `menuWidth` and `tokenOverflowBehavior` have no surface, with a development warning that names them. With a mouse or trackpad, on a screen that is not compact, in the server render and while hydrating, nothing changes. Pass `presentation="popover"` to keep the previous behavior on every device. Shipping this default in a patch is a product decision of the engineering owner, agreed with the owner of the compatibility policy.@imdreamrunnerdiff --git a/docs/specs/components/PowerSearch/PowerSearch.spec.md b/docs/specs/components/PowerSearch/PowerSearch.spec.mdindex a5e71996b7..859c53c397 100644--- a/docs/specs/components/PowerSearch/PowerSearch.spec.md+++ b/docs/specs/components/PowerSearch/PowerSearch.spec.md@@ -242,35 +242,37 @@ popover, rendered when `presentation` resolves to `popover`. Theeditor popover does not render in the `bottom-sheet` presentation, whose surfaceFR10–FR21 govern. FR25 governs a date-only value in both, and FR26 a date-and-time value.-| ID | Invariant | Basis | Status |-| ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| FR1 | In the `popover` presentation, the filter-editor popover MUST have a rendered border-box width no greater than 720 CSS px. | Owner direction; legibility issue demonstrated by wide PowerSearch adopters | Accepted contract; implementation pending |-| FR2 | In the `popover` presentation, before viewport collision handling, the editor's preferred width MUST be the outer PowerSearch width clamped to the inclusive 400–720 CSS px range. The 400 px floor MUST yield when the available viewport width cannot fit it. | Existing 400 px editing floor plus `component:PowerSearch/DEC-1` | Accepted contract; implementation pending |-| FR3 | In the `popover` presentation, when the 720 CSS px cap does not make the editor narrower than the outer PowerSearch, including when the 400 px floor is active, the editor MUST preserve current logical-start alignment to the outer PowerSearch. | Compatibility requirement | Accepted contract; implementation pending |-| FR4 | In the `popover` presentation, when the 720 CSS px cap makes the editor narrower, PowerSearch MUST resolve one stable opening control for that open: the inner typeahead input for the add path, or the actual activated token/control for the edit path. | Owner direction plus current composition analysis | Accepted contract; implementation pending |-| FR5 | In the `popover` presentation, for a capped editor, PowerSearch MUST compare the opening control's border-box distance from the outer PowerSearch's physical left and right edges, select the nearer outer edge, and align the editor to that edge. Equal distances MUST fall back to the outer PowerSearch's logical-start edge. The result MUST depend on control geometry, not pointer coordinates or pointer/keyboard modality. | `component:PowerSearch/DEC-2` | Accepted contract; implementation pending |-| FR6 | In the `popover` presentation, opening-control identity and the selected edge MUST be latched for the open lifetime. Reopening from a control on the opposite side MUST recalculate both; movement after open MUST NOT move the editor. | Stable interaction and performance requirement | Accepted contract; implementation pending |-| FR7 | In the `popover` presentation, width and preferred-edge selection MUST still yield to the layer runtime's viewport collision handling so the editor remains horizontally visible within the runtime's existing safe area. | `architecture:layer-runtime` | Accepted contract; implementation pending |-| FR8 | In the `popover` presentation, the width and alignment change MUST NOT alter editor content, field/operator/value state, vertical placement, focus movement, selection, dismissal, or screen-reader semantics. | Compatibility and accessibility requirement | Accepted contract; implementation pending |-| FR9 | In the `popover` presentation, the opening-control descriptor owned by `component:Tokenizer/DEC-1` and consumed by PowerSearch MUST remain package-internal. PowerSearch MUST NOT add a public width, maximum-width, input-ref, or positioning prop for this behavior. | `component:Tokenizer/DEC-1`, `architecture:public-component-api`, and `component:PowerSearch/DEC-1` | Accepted contract; implementation pending |-| FR10 | `presentation` selects the surface. `adaptive`, the value when `presentation` is omitted, resolves to `bottom-sheet` on compact coarse-pointer screens and to `popover` otherwise, through the same shared resolution the selection controls use (`component:Selector/FR4`); with a fine pointer or on a screen that is not compact it renders exactly the `popover` presentation. `popover` is the tokenizer field with its typeahead and editor popover on every device, unchanged except as FR19 (no mount announcement) states. `bottom-sheet` is the trigger and sheet flow of FR11–FR21 on every device. That resolution answers `popover` on the server and during the hydrating render, so an `adaptive` field server-renders as, and hydrates without a mismatch as, the popover presentation's tokenizer field; on a compact coarse-pointer screen the first client render after hydration swaps it to the trigger. Focus follows the resolution rule below: before any interaction nothing in the field has focus and nothing moves, except that with `hasAutoFocus` the server markup's `autofocus` has focused the combobox input, and the swap then moves focus to the trigger within the same visit — the caller is told of neither a blur nor a new focus. The two closed fields share the field's wrapper, border, and minimum height for the size, and show the same tokens, but their row counts may differ: the popover field's editable tokens each carry a 16 px remove control the trigger's display-only tokens do not (FR11), so the trigger's tokens can wrap into fewer rows (seven filters in a 326 px field take seven rows editable and six as display-only tokens), and the popover field also carries its inline combobox input after the tokens, which may take a row of its own — the swap then changes the field's height by those rows (none on the measured story at 390 px, one token row at 414 px). A resolution change while the flow is open takes effect after it closes and focus has returned to the trigger (the focus the close reports, FR11) — the presentation hold `architecture:layer-runtime/INV14` assigns to the layer runtime; INV14 gap: the runtime does not yet provide one (its record names INV14 as ownership not yet met), so until it does the field keeps its own hold, to be replaced by the runtime's when it exists; when the new presentation is `popover`, focus then moves to the tokenizer's combobox input as the same visit — no `onBlur` and no second `onFocus` reaches the caller. A resolution change while the flow is closed takes effect at once; when focus is anywhere inside the closed field — the trigger, the combobox input, a token or its remove control, the clear control, or an interactive `endContent` — and the focused element does not survive the switch, focus moves to the other presentation's primary control (the combobox input, or the trigger) as a continuation of the same visit — no `onBlur` and no `onFocus` reaches the caller for the hand-off; when the focused element survives, or focus is outside the field, focus stays where it is. When the switch to the sheet presentation happens while the popover presentation's editor popover is open, the popover and its focused control unmount with the tokenizer field, and focus moves to the trigger. Focus never lands on the page body. | DEC-3; touch-flow evidence | Current contract; verified by focused sheet tests and real-engine touch evidence. |-| FR11 | In the sheet presentation the field's control is one trigger: a button with `aria-haspopup="dialog"` and `aria-expanded`, whose accessible name is the field label followed by the trigger's visible text — the placeholder while no filter exists, otherwise the text of the filter tokens — so the name contains what is visible and exposes the selected filters. The tokens are display-only — each is the token's static structure (`component:Token/FR2`): no remove control, no click of its own, no inner control inside the trigger button — and the tokens, the placeholder, and the empty space around them belong to the trigger: a tap on any of them opens the flow. Tokens wrap onto further lines; the trigger does not reserve a row of its own once a token exists. The trigger's tokens are the popover presentation's tokens, the same component and the same words for a value, and a `date_absolute` value reads as the sheet's date editor shows it (FR17): a date-only value as its day in `timezoneID`, else the UTC day, and a value whose operator sets `isDateOnly: false` as its date and time in `timezoneID`, else the viewer's zone. A `components[type].Token` override renders on the trigger in place of PowerSearch's token, receiving the props the popover presentation hands it — `config`, `filter`, `field`, `operator`, `maxLength`, `isDisabled` — with `onClick` and `onRemove` undefined, as the popover hands them for a read-only filter: the trigger's tokens are display-only, and the override formats its own value. `startIcon` renders in the trigger's lane. The result count and `endContent` render in the field's end lane, outside the trigger button and after it: an interactive `endContent` keeps its own tab stop, its own taps, and its own accessible name, and a tap on it does not open the flow, so a caller's control is never nested inside the component's button and the end lane's text is not part of the trigger's name. `size` sizes the trigger field and its tokens as it sizes the tokenizer field; `statusVariant` places `status.message` as the popover presentation places it; `hasAutoFocus` focuses the trigger on mount. `onFocus` fires when focus enters the field from outside and `onBlur` when it leaves the field: opening the flow moves focus into a sheet, outside the field, so `onBlur` fires, and the close that returns focus to the trigger fires `onFocus` — as the popover presentation fires them around its editor. While disabled the trigger stays focusable with `aria-disabled="true"`, never carries the native `disabled` attribute, does not open, and shows `disabledMessage` as the field does (`spec:AST-085/FR1`, `FR2`). When the component becomes disabled with the flow open, every open sheet of the flow closes and focus moves to the trigger, the destination this record names (`spec:AST-085/FR4`). | DEC-3; touch-flow evidence; `spec:AST-085`; WCAG 2.5.3 | Current contract; verified by focused sheet tests and real-engine touch evidence. |-| FR12 | Opening the flow from a field with at least one filter, or from a read-only field, shows the Filters sheet, a tall modal sheet named "Filters". Its header — a heading and, while the field is interactive and at least one filter exists, an Add filter button at the medium size whose hit area is at least 44 px tall — and its footer — Done and, while `hasClear` is set, the field is interactive, and at least one editable filter exists, Clear all — stay fixed while only the rows between them scroll, the scroll viewport reaching the sheet's edge so its scrollbar does too, with the rows' text on the header's inset. One row per filter shows "{field label} {operator label}" (one catalog message, so a locale can reorder it) and, in bold, the value as the trigger's token shows it — the same formatter, so the same words, with the token's width budget lifted: the row never truncates a single value and never collapses a list to its "{n} items" count — with the token's summaries resolved from the catalog (`@astryx.powersearch.valueEditor.dateRange`, `itemsCount`, `filtersCount`, ICU plurals): an `integer` or `float` value reads as the token's own text (`String(value)`: `2.3456`, `1e+21`, `1e-7`, and `0` for negative zero) wherever the locale writes numbers with the token's numerals — Latin digits and a `.` decimal mark — and elsewhere with the locale's digits and decimal mark, no grouping and no rounding; a `string_list`, `enum_list`, or `entity_list` value reads as all of its items joined by the locale's narrow conjunction list (`Intl.ListFormat`, `{type: 'conjunction', style: 'narrow'}` — "Open, Closed" in English, "高、中" in Simplified Chinese and Japanese, "A, B und C" in German); a date-only `date_absolute` value reads as its day in `timezoneID`, else the UTC day, with no time, and one whose operator sets `isDateOnly: false` as its date and time in `timezoneID`, else the viewer's zone, a `date_range` as "date range", a `nested` value as "{n} filters", and a `date_relative` value as the value step's choice row reads it ("3 days ago", FR20) when a choice matches the stored value, otherwise as stored. A row's label and value are one catalog message, "{label} {value}", the same message the removal announcement of AR6 uses, with the value segment bold. A filter the field can edit is a row button that opens the value step on it, with a trailing remove action — an icon button at the medium size named "Remove {field label} filter", its hit area at least 44 px square, that commits `onChange(rest, 'remove', index)` without opening the step — except that a filter whose operator takes an `empty` value (a one-tap boolean filter) is a row whose tap removes it, with the same trailing remove action, since it has no value to edit; a read-only filter, or every filter while the field is read-only, is a plain row with no remove action, as the popover gives such a token no remove control. A `nested` filter's row is a row button like any other; its step edits the group with the popover presentation's built-in nested editor (FR14). An editable filter whose field or operator the config no longer has — which the trigger still shows as a token — lists as a row button reading the field's label when the config still has the field and the raw key for whatever is gone — "{field key} {operator key}" when both are, "{field label} {operator key}" when only the operator is — that opens the step's "This filter is no longer available" state (FR14), its trailing remove action still the removal path; it is a plain row while the filter, or the field, is read-only. With no filter the body is one empty state: a heading "No filters applied", a line of guidance, and, while the field is interactive, a centered primary Add filter action that is then the sheet's only Add filter (the header shows none), so the single thing to do is the only visible action. Done closes the flow. Clear all opens a confirmation above the sheet — a dialog titled "Clear all filters?" with "Clear filters" and "Keep filters" — and only confirming commits `onChange(kept, 'remove', <index of the first removed filter>)`, where `kept` is the read-only filters in their order: read-only filters are the consumer's, not the person's, so Clear all leaves them in place, as the popover presentation's Clear all does (FR23); the Filters sheet stays open for further editing and focus returns to it (FR16). After the flow closes focus returns to the trigger. | DEC-3; touch-flow evidence; the read-only filter contract (`isReadOnly`, FR22); DEC-4 | Current contract; verified by focused sheet tests and real-engine touch evidence. |-| FR13 | Add filter — from the Filters sheet's Add filter action, or directly when an interactive field with no filter opens — is a tall modal sheet named "Add filter" opened above the Filters sheet, which stays open beneath it (FR15a), so the sheet has no Back action: dismissing it — Escape, a scrim tap, a swipe — reveals Filters again, or closes the flow when Add filter was the entry point, in which case its fixed footer holds Done. Its header — the heading and, when one shows, the search field — stays fixed while the rows scroll. Without a content-search field it lists the visible fields grouped by `group`, each group a named list: the ungrouped fields first, under the heading "General", then each group under its name in order of first appearance, each a row button with the field's icon, a trailing chevron — or, for a field whose only operator takes an `empty` value, a trailing plus, since choosing it adds the filter at once (FR15) — and, once the field count reaches eight, a "Search filters" field above the list that matches labels and `typeaheadAliases` case-insensitively, caps a non-empty query's matches at `maxSearchResults`, and shows the empty state "No filters match your search" when nothing matches. With a `contentSearchFieldKey` whose default operator takes a `string` value it shows instead a "Search" searchbox using `placeholder`, with the same suggestions the popover presentation's typeahead offers listed inline as row buttons ("Search results"): fields, field-and-operator pairs, value matches, and a leading free-text item for the content field; Enter commits the first suggestion, ArrowDown and ArrowUp move between the search and the rows — arrow movement across independently focusable controls, recorded here as this record's exception to `spec:AST-020/FR15`, which adopts arrow keys for a single composite only: the searchbox-to-list continuity is what the popover presentation's combobox gives the same suggestions, and the rows stay in the Tab order as well — an IME-composing Enter does nothing, and a query with no suggestion shows the empty state "No results found" — the searchbox's `aria-controls` names the results list, or that message while nothing lists, so it always names an element; the field list's "No filters match your search" likewise shows only for a non-empty query that matches nothing, never for a config with no field. Each of the two is a compact empty state with a search icon, that title, and the description "Try a different search.", mounted only while the Add filter sheet is the open one. Neither search field takes focus when the sheet opens: the sheet opens with focus on its panel and the software keyboard stays down until the person taps the search; a direct vertical touch drag on the rows while a search field has focus blurs it, so the keyboard leaves and the rows can be read. A suggestion that carries a value commits `onChange([...filters, filter], 'add', filters.length)`, announces `Added {label}` inside the Filters sheet (AR6), and shows Filters as FR15a states; any other suggestion or field row opens the value step with that field and operator, above Add filter. Every visible field lists, a field whose every operator is `nested` included: the value step edits every operator's value (FR14). | DEC-3; touch-flow evidence; current typeahead source | Current contract; verified by focused sheet tests and real-engine touch evidence. |-| FR14 | The value step is a tall modal sheet that edits every operator's value, opened above the sheet that led to it — Filters for an edit, Add filter for a creation — which stays open beneath it (FR15a); its title is the dialog's name (AR5), and for a filter whose field or operator the config no longer has it reads as the Filters row does (FR12): the field's label when the config still has the field, the raw key for whatever is gone. Its header and footer stay fixed while the body scrolls. When the field offers more than one operator the body starts with an "Operator" radio group whose options read "{field label} {operator label}" and list the field's operators, with the operator the step opened with checked — the filter's operator while editing, and while creating the operator the suggestion named (FR13) or else the field's default operator, else its first; otherwise there is no group and the title is "{field label} {operator label}" naming that operator. When no operator label applies the title is the field label. The body below the group is the editor for the checked operator's value type: the sheet-native controls of FR17, or for a `nested` value the popover presentation's built-in nested editor — the sub-filter tree with its Add action, each sub-filter's field, operator, and value controls, and removal — rendered as the popover renders it, with one difference: the step's Operator group takes the place of the editor's root group-operator picker, which is not shown, and the tree root reads the checked operator's label; a sub-filter's controls are the popover editor's own, in their default presentation (a Selector's menu, the Tokenizer's inline field), not the sheet's choice rows (FR17) or Tokenizer sheet (FR21), which govern the step's top-level value only, because the nested editor renders its controls in their `popover` presentations; the tree is its own width container, so below 400 CSS px its rows wrap instead of overflowing the sheet, as they wrap in a narrow popover. A group is created and edited the same way in both presentations; switching the operator swaps the body. A value chosen in the body is staged, not committed: no `onChange` fires until the footer confirms it. Changing the operator keeps a staged value only when the new operator reads the same value type; an `empty` operator stages `{type: 'empty'}`. The body's sections sit on the sheet's surface when the editor is the body's only section; when the body has more than one section — the Operator group above the editor — each section is a muted container, so the grouping reads without a frame around a lone editor. The footer holds Cancel and the confirm action — `popoverSaveButtonLabel` when given, otherwise "Add filter" while creating and "Apply" while editing — disabled until the staged value is complete; the step has no Remove action: a filter is removed from its Filters row (FR12). When `components[type].Editor` is set for the checked operator's value type it replaces the body below the Operator group and the footer — the group stays outside it, so switching operators still swaps the body — receiving the props the popover presentation hands it, with the same meaning: the caller's `config`, the partial `filter`, `mode`, `saveButtonLabel`, `isReadOnly`, `timezoneID` (FR25), `onSave`, and `onCancel`, and nothing the popover does not pass; `onSave(filter)` commits it, `onSave(null)` removes the filter while editing and returns to Filters unchanged while creating. A controlled update that removes the field or operator being edited replaces the body with "This filter is no longer available", announced from its rendered element inside the sheet while the step is the open one (AR6), and keeps Cancel as the way out, the filter's trailing remove action on its Filters row being the removal path (FR12); when focus was on a control of the replaced body it moves to Cancel, so it never falls to the page body inside the open sheet (FR16). | DEC-3; touch-flow evidence | Current contract; verified by focused sheet tests and real-engine touch evidence. |-| FR15 | Confirming a created filter commits `onChange([...filters, filter], 'add', filters.length)`; choosing a field whose only operator takes an `empty` value commits that filter the same way from the Add filter row, with no value step. Tapping an editable Filters row opens the value step on that filter in edit mode; Apply commits `onChange(updated, 'edit', index)`; the row's trailing remove action, or a tap on an `empty`-valued filter's row, commits `onChange(rest, 'remove', index)`, where `index` is the filter's position at commit time: a controlled parent that reorders or clones its filters while the step is open is followed by object identity, then by a structurally equal filter in the original slot, then by a unique structural match; when the target is gone or ambiguous nothing is committed and the step closes back to Filters, focus landing as FR16 states for a row that no longer exists. Every commit shows the Filters sheet as FR15a states. While the field is read-only, or disabled, no commit happens. | DEC-3; touch-flow evidence | Current contract; verified by focused sheet tests and real-engine touch evidence. |-| FR15a | The steps stack: each step opens above the sheet that led to it, which stays open — receded and blocked as a covered sheet of the stack (`component:BottomSheet` FR5, FR6) — so the stack is Filters alone; Filters under Add filter; Filters under the value step for an edit; Filters under Add filter under the value step for a creation; or, when Add filter was the entry point, Add filter alone and then Add filter under the value step. No sheet of the flow carries a Back action: a dismissal — Escape, a scrim tap, a swipe, a platform close request — reaches only the top sheet (`component:BottomSheet` FR7), closes it, and reveals the sheet beneath, which takes focus back as FR16 states; dismissing the bottom sheet of the stack closes the flow. Cancel on the value step is that dismissal. A commit closes the step that made it: an edit's commit reveals Filters beneath the value step; a creation's commit, from the value step or from an Add filter row or suggestion that commits directly, closes Add filter, and the value step above it, together and shows Filters, so the person sees the filter just added: Filters is revealed when it is open beneath them; after a direct entry it opens in the same update that closes them — BottomSheet's same-update replace (`component:BottomSheet` FR10) when Add filter alone closes, and the stack's ordinary closes and open (`component:BottomSheet` FR5–FR9) when the value step closes with it. A creating `Editor` override's `onSave(null)` (FR14) shows Filters the same way. The flow therefore has one direction forward (open a step above) and one back (close the top step): no dismissal replaces a step, and Filters opens as other sheets close only when a creation ends after a direct entry. | DEC-3; `component:BottomSheet` FR5–FR9 | Current contract; verified by focused sheet tests and real-engine touch evidence. |-| FR16 | Focus follows the step: after a commit from the value step while creating, the value step and Add filter close and focus lands on the Filters header's Add filter, ready for the next filter; after a content-search suggestion or an `empty`-valued field row commits a filter directly, that filter's row; after Apply or Cancel from editing, the edited filter's row — followed across a controlled reorder or clone, and, when a controlled update removed it or left two filters it could be, the nearest remaining row that is a button around its former position (the following one on a tie), else Add filter; after a row's trailing remove action, or a caller's `Editor` override's `onSave(null)` while editing, which closes the value step, the trailing remove action of the nearest remaining row that has one (the following one on a tie) — a plain row, a read-only filter's, has none and is passed over — so a run of removals needs no re-aiming, else Add filter when no such row remains; after Cancel from creation, Add filter is revealed with focus on the field row that opened the step, or on the content search when a suggestion opened it — and when a controlled update has removed that field, or the content-search field itself, the Add filter sheet's first control: its search field when one shows, else its first field row; after Add filter is dismissed, the Filters header's Add filter, or the empty state's; after a caller's `Editor` override calls `onSave(null)` while creating, the same (the flow returns to Filters unchanged, FR14); after a confirmed Clear all, the Filters sheet's first remaining control — a kept read-only filter's row has none, so Add filter — with the sheet still open; after Keep filters, Escape, or a scrim tap dismisses the confirmation, Clear all (`component:Dialog` AR2); and, as one rule for the Filters and Add filter sheets, when a controlled update unmounts the control that holds focus — a filter's row or its remove action, a dropped field's row, Clear all gone with the last editable filter — the nearest remaining row that is a button, counted among the button rows by the removed one's index (the following one, else the last) — a plain row (a read-only filter, or every filter while the field is read-only) is passed over — else the sheet's first control (the Add filter sheet's search field, Add filter in the Filters header or empty state), else the sheet's panel, so focus never lands on the page body inside the open sheet; when a controlled update replaces the value step's body with the unavailable state while focus was on one of its controls, Cancel (FR14); after the flow closes, the trigger. A sheet that opens takes focus on its panel, not on a control, except where this row names one; the Add filter sheet's search fields never take it on open (FR13). | DEC-3; touch-flow evidence | Current contract; verified by focused sheet tests and real-engine touch evidence. |-| FR17 | The value step edits every value type with the same editor the popover presentation uses (`nested` through its built-in nested editor, FR14), with four sheet-native differences: `enum`, `enum_list`, and `date_relative` render as full-width choice rows with a trailing indicator instead of a dropdown that would stack a second layer on the sheet — `radio` rows in a `radiogroup` named by the field label for `enum` and `date_relative` (a tap selects the row; the group is one tab stop — the checked row, else the first — and the arrow keys move focus and check the row they land on, wrapping, Home and End move to and check the first and last row, and Space or Enter checks the focused row — `spec:AST-020/FR15`), `checkbox` rows in a `group` named by the field label for `enum_list` (a tap toggles the row; each row is its own tab stop, toggled with Space or Enter), each carrying its state as `aria-checked`, as the Tokenizer's sheet rows do; `integer` and `float` stage every parseable keystroke, so the confirm action enables while the person is still typing, and unstage when the field is cleared or stops parsing, so it disables again over an empty field; a `string_list` or `entity_list` value edits through the Tokenizer's own sheet presentation (`component:Tokenizer/FR16–FR24`), its trigger showing the staged tokens in the step and its sheet titled with the field label; and a `date_absolute` value with `isDateOnly` unset or `true`, and a `date_range` value, edit through an inline Calendar on the sheet's surface — no popover opens from a sheet — reading a stored instant as its day in `timezoneID`, else the UTC day, and writing a picked day as that day's midnight in the same zone, the day the trigger's token and the Filters row show (FR11, FR12); a `date_absolute` value with `isDateOnly: false` edits through a date-and-time input, sized for touch, that reads and writes the wall-clock time in `timezoneID`, else the viewer's zone. `maxOperatorMenuItems` caps the string and entity suggestions as in the popover presentation. | DEC-3; touch-flow evidence; current value editors | Current contract; verified by focused sheet tests and real-engine touch evidence. Implementation gap: a date-only `date_absolute` value and a `date_range` value edit through the popover presentation's date fields in their sheet presentation — which read and write the day in `timezoneID`, else the UTC day, as this row states — not through an inline Calendar; a value whose operator sets `isDateOnly: false` edits through the popover presentation's date picker and time field in their sheet presentation, which read and write the wall-clock time this row names, not through one date-and-time input. |-| FR18 | Every list in the sheets derives synchronously from the config — the field list, its search, the content-search suggestions, and the choice rows — so no sheet shows an empty state before results arrive: "No filters match your search" and "No results found" render only for a non-empty query whose synchronous result set is empty, and only while their sheet is the open one; a sheet that is open beneath another, or closed with its body retained, renders and announces no empty-result or unavailable message (AR6). The value typeaheads and tokenizers inside the value step own their own pending states. | DEC-3; `architecture:react-component-runtime/INV1` | Current contract; verified by focused sheet tests and real-engine touch evidence. |-| FR19 | The result count renders at the end of the field in both presentations and is announced only when it changes after mount; the first render announces nothing, including under StrictMode's effect replay. The announcement takes the route `spec:AST-086/FR14` names for where the field is at that moment: inside the open sheet's dialog while a sheet of the flow is open (AR6), otherwise inside the nearest open native modal that holds the field (a Dialog, a modal Drawer), and the shared polite channel only when no modal does — never a channel the record names itself. | Current popover behavior; `architecture:react-component-runtime/INV3` | Current contract; verified by focused sheet tests and real-engine touch evidence. |-| FR20 | Every string the sheets introduce comes from the `@astryx.powersearch.*` catalog, reusing the existing editor keys where their meaning fits (Cancel, Apply, Operator, Value, Values, Entities, the placeholders, the result count). Content the popover presentation already renders keeps its source — field, operator, and value text from the config and its formatters — except that every label the sheets render for a generated choice comes from the catalog as one ICU message with a plural: the relative-date choice rows (`@astryx.powersearch.sheet.relative{Days,Weeks,Months}{Ago,FromNow}`, the same choices and, in English, the same words as the popover's editor lists) and the value summaries of FR12. | DEC-3; catalog contract | Current contract; verified by focused sheet tests and real-engine touch evidence. |-| FR21 | A `string_list` or `entity_list` value inside the value step opens the Tokenizer's sheet above the value step, one more sheet of the same stack (FR15a). Escape, a scrim tap, and a swipe dismiss only that topmost sheet; closing it returns focus to its trigger inside the value step; the value step keeps its staged state. | DEC-3; `family:overlay-dismissal`; `component:Tokenizer/FR18` | Current contract; verified by focused sheet tests and real-engine touch evidence. |-| FR22 | In the `popover` presentation, a read-only field (`isReadOnly`) MUST NOT remove a filter: it shows no Clear all, no token has a remove control, and Backspace on an empty input removes nothing. | The `isReadOnly` prop docs: "Prevent adding, editing, or removing filters." | Current contract |-| FR23 | In the `popover` presentation, Clear all MUST remove every editable filter and keep every read-only filter: it commits `onChange(<the read-only filters>, 'remove', <index of the first removed filter>)` and announces "Editable filters removed" while a read-only filter remains, otherwise "All filters removed". The clear control MUST render only while `hasClear` is set, the field is neither read-only nor disabled, and at least one editable filter exists. Backspace on an empty input MUST NOT remove a read-only filter; its token has no remove control. | DEC-4; a read-only filter's token has no remove control (current source) | Current contract |-| FR24 | In the popover presentation, a built-in filter token (no `components` Token override) that opens its editor is named by its visible text (field, operator and value); `aria-haspopup="dialog"`, `aria-expanded` is true while its editor is open, and the editor is a dialog named by the token's visible text. Its remove button is named by the remove word and the same visible text. | `spec:AST-020` FR1; WCAG 2.5.3 and 4.1.2; `component:Token/FR10` | Current contract. |-| FR25 | In both presentations a `date_absolute` value whose operator has `isDateOnly` unset or `true`, and each `ABSOLUTE` part of a `date_range` value, is a calendar day: the day its `unixSeconds` falls on in `timezoneID` when the prop is set, else the UTC day. The built-in token's text, the filter's accessible label and every announcement that names the value, the Filters row of the sheet presentation, and the date editor of either presentation all read that one day, with no time of day, so one value is never two days in one field; a `components[type].Token` override formats its own value (FR11) and receives `timezoneID` in its props, as the exported `PowerSearchToken` (the default token) does and reads, and a `components[type].Editor` override and `PowerSearchFilterEditor` receive `timezoneID` in their props so they can read the same day. A day picked in an editor is stored as that day's midnight in the same zone — `timezoneID`'s midnight, else UTC midnight — and the editor reopens on the day it stored, so an edit that keeps the day keeps the instant. Nothing about a value is rewritten by rendering or reopening: a value stored before `timezoneID` was given reads as its day in the zone now given. A `date_range` whose part is `NOW` or `RELATIVE` reads that part resolved to an instant first, then as its day. A value whose operator sets `isDateOnly: false` is an instant, not a calendar day: FR26 governs it. | DEC-5; `timezoneID` prop contract; `component:DateInput` (a calendar-day control) | Current contract. |-| FR26 | A `date_absolute` value whose operator has `isDateOnly: false` is an instant with a time of day. In both presentations its token shows its date and time and the sheet's Filters row shows the same, and its editor reads the stored instant's wall-clock time and stores the wall-clock time entered as the instant it names, both in `timezoneID` when the prop is set, else the viewer's zone — the zone the viewer reads a clock in — so the time typed is the time shown. In the popover presentation that editor is a date picker beside a time field; the sheet presentation's control is FR17's. A `components[type].Editor` override and `PowerSearchFilterEditor` receive `timezoneID` in their props so they can read the same time. A `date_absolute` whose operator has `isDateOnly` unset or `true` keeps its date-only picker and shows no time (FR25). | DEC-6; `OperatorValue.isDateOnly` contract; `component:DateInput`; `component:TimeInput` | Current contract. |+| ID | Invariant | Basis | Status |+| ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| FR1 | In the `popover` presentation, the filter-editor popover MUST have a rendered border-box width no greater than 720 CSS px. | Owner direction; legibility issue demonstrated by wide PowerSearch adopters | Accepted contract; implementation pending |+| FR2 | In the `popover` presentation, before viewport collision handling, the editor's preferred width MUST be the outer PowerSearch width clamped to the inclusive 400–720 CSS px range. The 400 px floor MUST yield when the available viewport width cannot fit it. | Existing 400 px editing floor plus `component:PowerSearch/DEC-1` | Accepted contract; implementation pending |+| FR3 | In the `popover` presentation, when the 720 CSS px cap does not make the editor narrower than the outer PowerSearch, including when the 400 px floor is active, the editor MUST preserve current logical-start alignment to the outer PowerSearch. | Compatibility requirement | Accepted contract; implementation pending |+| FR4 | In the `popover` presentation, when the 720 CSS px cap makes the editor narrower, PowerSearch MUST resolve one stable opening control for that open: the inner typeahead input for the add path, or the actual activated token/control for the edit path. | Owner direction plus current composition analysis | Accepted contract; implementation pending |+| FR5 | In the `popover` presentation, for a capped editor, PowerSearch MUST compare the opening control's border-box distance from the outer PowerSearch's physical left and right edges, select the nearer outer edge, and align the editor to that edge. Equal distances MUST fall back to the outer PowerSearch's logical-start edge. The result MUST depend on control geometry, not pointer coordinates or pointer/keyboard modality. | `component:PowerSearch/DEC-2` | Accepted contract; implementation pending |+| FR6 | In the `popover` presentation, opening-control identity and the selected edge MUST be latched for the open lifetime. Reopening from a control on the opposite side MUST recalculate both; movement after open MUST NOT move the editor. | Stable interaction and performance requirement | Accepted contract; implementation pending |+| FR7 | In the `popover` presentation, width and preferred-edge selection MUST still yield to the layer runtime's viewport collision handling so the editor remains horizontally visible within the runtime's existing safe area. | `architecture:layer-runtime` | Accepted contract; implementation pending |+| FR8 | In the `popover` presentation, the width and alignment change MUST NOT alter editor content, field/operator/value state, vertical placement, focus movement, selection, dismissal, or screen-reader semantics. | Compatibility and accessibility requirement | Accepted contract; implementation pending |+| FR9 | In the `popover` presentation, the opening-control descriptor owned by `component:Tokenizer/DEC-1` and consumed by PowerSearch MUST remain package-internal. PowerSearch MUST NOT add a public width, maximum-width, input-ref, or positioning prop for this behavior. | `component:Tokenizer/DEC-1`, `architecture:public-component-api`, and `component:PowerSearch/DEC-1` | Accepted contract; implementation pending |+| FR10 | `presentation` selects the surface. `adaptive`, the value when `presentation` is omitted, resolves to `bottom-sheet` on compact coarse-pointer screens and to `popover` otherwise, through the same shared resolution the selection controls use (`component:Selector/FR4`); with a fine pointer or on a screen that is not compact it renders exactly the `popover` presentation. `popover` is the tokenizer field with its typeahead and editor popover on every device, unchanged except as FR19 (no mount announcement) states. `bottom-sheet` is the trigger and sheet flow of FR11–FR21 on every device. That resolution answers `popover` on the server and during the hydrating render, so an `adaptive` field server-renders as, and hydrates without a mismatch as, the popover presentation's tokenizer field; on a compact coarse-pointer screen the first client render after hydration swaps it to the trigger. Focus follows the resolution rule below: before any interaction nothing in the field has focus and nothing moves, except that with `hasAutoFocus` the server markup's `autofocus` has focused the combobox input, and the swap then moves focus to the trigger within the same visit — the caller is told of neither a blur nor a new focus. The two closed fields share the field's wrapper, border, and minimum height for the size, and show the same tokens, but their row counts may differ: the popover field's editable tokens each carry a 16 px remove control the trigger's display-only tokens do not (FR11), so the trigger's tokens can wrap into fewer rows (seven filters in a 326 px field take seven rows editable and six as display-only tokens), and the popover field also carries its inline combobox input after the tokens, which may take a row of its own — the swap then changes the field's height by those rows (none on the measured story at 390 px, one token row at 414 px). A resolution change while the flow is open takes effect after it closes and focus has returned to the trigger (the focus the close reports, FR11) — the presentation hold `architecture:layer-runtime/INV14` assigns to the layer runtime; INV14 gap: the runtime does not yet provide one (its record names INV14 as ownership not yet met), so until it does the field keeps its own hold, to be replaced by the runtime's when it exists; when the new presentation is `popover`, focus then moves to the tokenizer's combobox input as the same visit — no `onBlur` and no second `onFocus` reaches the caller. A resolution change while the flow is closed takes effect at once; when focus is anywhere inside the closed field — the trigger, the combobox input, a token or its remove control, the clear control, or an interactive `endContent` — and the focused element does not survive the switch, focus moves to the other presentation's primary control (the combobox input, or the trigger) as a continuation of the same visit — no `onBlur` and no `onFocus` reaches the caller for the hand-off; when the focused element survives, or focus is outside the field, focus stays where it is. When the switch to the sheet presentation happens while the popover presentation's editor popover is open, the popover and its focused control unmount with the tokenizer field, and focus moves to the trigger. Focus never lands on the page body. | DEC-3; touch-flow evidence | Current contract; verified by focused sheet tests and real-engine touch evidence. |+| FR11 | In the sheet presentation the field's control is one trigger: a button with `aria-haspopup="dialog"` and `aria-expanded`, whose accessible name is the field label followed by the trigger's visible text — the placeholder while no filter exists, otherwise the text of the filter tokens — so the name contains what is visible and exposes the selected filters. The tokens are display-only — each is the token's static structure (`component:Token/FR2`): no remove control, no click of its own, no inner control inside the trigger button — and the tokens, the placeholder, and the empty space around them belong to the trigger: a tap on any of them opens the flow. Tokens wrap onto further lines; the trigger does not reserve a row of its own once a token exists. The trigger's tokens are the popover presentation's tokens, the same component and the same words for a value, and a `date_absolute` value reads as the sheet's date editor shows it (FR17): a date-only value as its day in `timezoneID`, else the UTC day, and a value whose operator sets `isDateOnly: false` as its date and time in `timezoneID`, else the viewer's zone. A `components[type].Token` override renders on the trigger in place of PowerSearch's token, receiving the props the popover presentation hands it — `config`, `filter`, `field`, `operator`, `maxLength`, `isDisabled` — with `onClick` and `onRemove` undefined, as the popover hands them for a read-only filter: the trigger's tokens are display-only, and the override formats its own value. `startIcon` renders in the trigger's lane. The result count and `endContent` render in the field's end lane, outside the trigger button and after it: an interactive `endContent` keeps its own tab stop, its own taps, and its own accessible name, and a tap on it does not open the flow, so a caller's control is never nested inside the component's button and the end lane's text is not part of the trigger's name. `size` sizes the trigger field and its tokens as it sizes the tokenizer field; `statusVariant` places `status.message` as the popover presentation places it; `hasAutoFocus` focuses the trigger on mount. `onFocus` fires when focus enters the field from outside and `onBlur` when it leaves the field: opening the flow moves focus into a sheet, outside the field, so `onBlur` fires, and the close that returns focus to the trigger fires `onFocus` — as the popover presentation fires them around its editor. While disabled the trigger stays focusable with `aria-disabled="true"`, never carries the native `disabled` attribute, does not open, and shows `disabledMessage` as the field does (`spec:AST-085/FR1`, `FR2`). When the component becomes disabled with the flow open, every open sheet of the flow closes and focus moves to the trigger, the destination this record names (`spec:AST-085/FR4`). | DEC-3; touch-flow evidence; `spec:AST-085`; WCAG 2.5.3 | Current contract; verified by focused sheet tests and real-engine touch evidence. |+| FR12 | Opening the flow from a field with at least one filter, or from a read-only field, shows the Filters sheet, a tall modal sheet named "Filters". Its header — a heading and, while the field is interactive and at least one filter exists, an Add filter button at the medium size whose hit area is at least 44 px tall — and its footer — Done, which applies the sheet's draft (FR15b), and, while `hasClear` is set, the field is interactive, and at least one editable filter exists, Clear all — stay fixed while only the rows between them scroll, the scroll viewport reaching the sheet's edge so its scrollbar does too, with the rows' text on the header's inset. One row per filter shows "{field label} {operator label}" (one catalog message, so a locale can reorder it) and, in bold, the value as the trigger's token shows it — the same formatter, so the same words, with the token's width budget lifted: the row never truncates a single value and never collapses a list to its "{n} items" count — with the token's summaries resolved from the catalog (`@astryx.powersearch.valueEditor.dateRange`, `itemsCount`, `filtersCount`, ICU plurals): an `integer` or `float` value reads as the token's own text (`String(value)`: `2.3456`, `1e+21`, `1e-7`, and `0` for negative zero) wherever the locale writes numbers with the token's numerals — Latin digits and a `.` decimal mark — and elsewhere with the locale's digits and decimal mark, no grouping and no rounding; a `string_list`, `enum_list`, or `entity_list` value reads as all of its items joined by the locale's narrow conjunction list (`Intl.ListFormat`, `{type: 'conjunction', style: 'narrow'}` — "Open, Closed" in English, "高、中" in Simplified Chinese and Japanese, "A, B und C" in German); a date-only `date_absolute` value reads as its day in `timezoneID`, else the UTC day, with no time, and one whose operator sets `isDateOnly: false` as its date and time in `timezoneID`, else the viewer's zone, a `date_range` as "date range", a `nested` value as "{n} filters", and a `date_relative` value as the value step's choice row reads it ("3 days ago", FR20) when a choice matches the stored value, otherwise as stored. A row's label and value are one catalog message, "{label} {value}", the same message the removal announcement of AR6 uses, with the value segment bold. A filter the field can edit is a row button that opens the value step on it, with a trailing remove action — an icon button at the medium size named "Remove {field label} filter", its hit area at least 44 px square, that removes it from the draft (FR15b) without opening the step — except that a filter whose operator takes an `empty` value (a one-tap boolean filter) is a row whose tap removes it, with the same trailing remove action, since it has no value to edit; a read-only filter, or every filter while the field is read-only, is a plain row with no remove action, as the popover gives such a token no remove control. A `nested` filter's row is a row button like any other; its step edits the group with the popover presentation's built-in nested editor (FR14). An editable filter whose field or operator the config no longer has — which the trigger still shows as a token — lists as a row button reading the field's label when the config still has the field and the raw key for whatever is gone — "{field key} {operator key}" when both are, "{field label} {operator key}" when only the operator is — that opens the step's "This filter is no longer available" state (FR14), its trailing remove action still the removal path; it is a plain row while the filter, or the field, is read-only. With no filter in the draft the body is one empty state: a heading — "No filters applied" while the field has none, "No filters" while the draft is empty but the field's filters are still applied (Done replaces them) — a line of guidance, and, while the field is interactive, a centered primary Add filter action that is then the sheet's only Add filter (the header shows none), so the single thing to do is the only visible action; the footer stays, with Done alone, while the draft differs from the applied filters (an emptied draft still has removals to apply), and is absent otherwise. Done closes the flow. Clear all opens a confirmation above the sheet — a dialog titled "Clear all filters?" with "Clear filters" and "Keep filters" — and only confirming removes the editable filters from the draft, recorded as `('remove', <index of the first removed filter>)` with `kept`, the read-only filters in their order, as the list (FR15b): read-only filters are the consumer's, not the person's, so Clear all leaves them in place, as the popover presentation's Clear all does (FR23); the Filters sheet stays open for further editing and focus returns to it (FR16). After the flow closes focus returns to the trigger. | DEC-3; touch-flow evidence; the read-only filter contract (`isReadOnly`, FR22); DEC-4 | Current contract; verified by focused sheet tests and real-engine touch evidence. |+| FR13 | Add filter — from the Filters sheet's Add filter action, or directly when an interactive field with no filter opens — is a tall modal sheet named "Add filter" opened above the Filters sheet, which stays open beneath it (FR15a), so the sheet has no Back action: dismissing it — Escape, a scrim tap, a swipe — reveals Filters again, or closes the flow when Add filter was the entry point, in which case its fixed footer holds Done. Its header — the heading and, when one shows, the search field — stays fixed while the rows scroll. Without a content-search field it lists the visible fields grouped by `group`, each group a named list: the ungrouped fields first, under the heading "General", then each group under its name in order of first appearance, each a row button with the field's icon, a trailing chevron — or, for a field whose only operator takes an `empty` value, a trailing plus, since choosing it adds the filter at once (FR15) — and, once the field count reaches eight, a "Search filters" field above the list that matches labels and `typeaheadAliases` case-insensitively, caps a non-empty query's matches at `maxSearchResults`, and shows the empty state "No filters match your search" when nothing matches. With a `contentSearchFieldKey` whose default operator takes a `string` value it shows instead a "Search" searchbox using `placeholder`, with the same suggestions the popover presentation's typeahead offers listed inline as row buttons ("Search results"): fields, field-and-operator pairs, value matches, and a leading free-text item for the content field; Enter commits the first suggestion, ArrowDown and ArrowUp move between the search and the rows — arrow movement across independently focusable controls, recorded here as this record's exception to `spec:AST-020/FR15`, which adopts arrow keys for a single composite only: the searchbox-to-list continuity is what the popover presentation's combobox gives the same suggestions, and the rows stay in the Tab order as well — an IME-composing Enter does nothing, and a query with no suggestion shows the empty state "No results found" — the searchbox's `aria-controls` names the results list, or that message while nothing lists, so it always names an element; the field list's "No filters match your search" likewise shows only for a non-empty query that matches nothing, never for a config with no field. Each of the two is a compact empty state with a search icon, that title, and the description "Try a different search.", mounted only while the Add filter sheet is the open one. Neither search field takes focus when the sheet opens: the sheet opens with focus on its panel and the software keyboard stays down until the person taps the search; a direct vertical touch drag on the rows while a search field has focus blurs it, so the keyboard leaves and the rows can be read. A suggestion that carries a value adds the filter to the draft (FR15b), recorded as `('add', draft.length)`, announces `Added {label}` inside the Filters sheet (AR6), and shows Filters as FR15a states; any other suggestion or field row opens the value step with that field and operator, above Add filter. Every visible field lists, a field whose every operator is `nested` included: the value step edits every operator's value (FR14). | DEC-3; touch-flow evidence; current typeahead source | Current contract; verified by focused sheet tests and real-engine touch evidence. |+| FR14 | The value step is a tall modal sheet that edits every operator's value, opened above the sheet that led to it — Filters for an edit, Add filter for a creation — which stays open beneath it (FR15a); its title is the dialog's name (AR5), and for a filter whose field or operator the config no longer has it reads as the Filters row does (FR12): the field's label when the config still has the field, the raw key for whatever is gone. Its header and footer stay fixed while the body scrolls. When the field offers more than one operator the body starts with an "Operator" radio group whose options read "{field label} {operator label}" and list the field's operators, with the operator the step opened with checked — the filter's operator while editing, and while creating the operator the suggestion named (FR13) or else the field's default operator, else its first; otherwise there is no group and the title is "{field label} {operator label}" naming that operator. When no operator label applies the title is the field label. The body below the group is the editor for the checked operator's value type: the sheet-native controls of FR17, or for a `nested` value the popover presentation's built-in nested editor — the sub-filter tree with its Add action, each sub-filter's field, operator, and value controls, and removal — rendered as the popover renders it, with one difference: the step's Operator group takes the place of the editor's root group-operator picker, which is not shown, and the tree root reads the checked operator's label; a sub-filter's controls are the popover editor's own, in their default presentation (a Selector's menu, the Tokenizer's inline field), not the sheet's choice rows (FR17) or Tokenizer sheet (FR21), which govern the step's top-level value only, because the nested editor renders its controls in their `popover` presentations; the tree is its own width container, so below 400 CSS px its rows wrap instead of overflowing the sheet, as they wrap in a narrow popover. A group is created and edited the same way in both presentations; switching the operator swaps the body. A value chosen in the body is staged, not committed: no `onChange` fires until the footer confirms it. Changing the operator keeps a staged value only when the new operator reads the same value type; an `empty` operator stages `{type: 'empty'}`. The body's sections sit on the sheet's surface when the editor is the body's only section; when the body has more than one section — the Operator group above the editor — each section is a muted container, so the grouping reads without a frame around a lone editor. The footer holds Cancel and the confirm action — `popoverSaveButtonLabel` when given, otherwise "Add filter" while creating and "Apply" while editing — disabled until the staged value is complete; the step has no Remove action: a filter is removed from its Filters row (FR12). When `components[type].Editor` is set for the checked operator's value type it replaces the body below the Operator group and the footer — the group stays outside it, so switching operators still swaps the body — receiving the props the popover presentation hands it, with the same meaning: the caller's `config`, the partial `filter`, `mode`, `saveButtonLabel`, `isReadOnly`, `timezoneID` (FR25), `onSave`, and `onCancel`, and nothing the popover does not pass; `onSave(filter)` commits it, `onSave(null)` removes the filter while editing and returns to Filters unchanged while creating. A controlled update that removes the field or operator being edited replaces the body with "This filter is no longer available", announced from its rendered element inside the sheet while the step is the open one (AR6), and keeps Cancel as the way out, the filter's trailing remove action on its Filters row being the removal path (FR12); when focus was on a control of the replaced body it moves to Cancel, so it never falls to the page body inside the open sheet (FR16). | DEC-3; touch-flow evidence | Current contract; verified by focused sheet tests and real-engine touch evidence. |+| FR15 | Confirming a created filter adds it to the draft (FR15b), recorded as `('add', draft.length)` with the list after it; choosing a field whose only operator takes an `empty` value adds that filter the same way from the Add filter row, with no value step. Tapping an editable Filters row opens the value step on that filter in edit mode; Apply writes the edited filter into the draft at its index, recorded as `('edit', index)`; the row's trailing remove action, or a tap on an `empty`-valued filter's row, removes it from the draft, recorded as `('remove', index)`, where `index` is the filter's position in the draft at that edit. The draft is the flow's own list: a controlled parent's change to `filters` while the flow is open does not reach the open sheets; Done replays the draft's edits onto the field's latest filters (FR15b), and a dismissal leaves the change in place, so it shows on the next open. Every edit shows the Filters sheet as FR15a states. While the field is read-only, or disabled, no edit happens. | DEC-3; DEC-7; touch-flow evidence | Current contract; verified by focused sheet tests. |+| FR15a | The steps stack: each step opens above the sheet that led to it, which stays open — receded and blocked as a covered sheet of the stack (`component:BottomSheet` FR5, FR6) — so the stack is Filters alone; Filters under Add filter; Filters under the value step for an edit; Filters under Add filter under the value step for a creation; or, when Add filter was the entry point, Add filter alone and then Add filter under the value step. No sheet of the flow carries a Back action: a dismissal — Escape, a scrim tap, a swipe, a platform close request — reaches only the top sheet (`component:BottomSheet` FR7), closes it, and reveals the sheet beneath, which takes focus back as FR16 states; dismissing the bottom sheet of the stack closes the flow. Cancel on the value step is that dismissal. A commit closes the step that made it: an edit's commit reveals Filters beneath the value step; a creation's commit, from the value step or from an Add filter row or suggestion that commits directly, closes Add filter, and the value step above it, together and shows Filters, so the person sees the filter just added: Filters is revealed when it is open beneath them; after a direct entry it opens in the same update that closes them — BottomSheet's same-update replace (`component:BottomSheet` FR10) when Add filter alone closes, and the stack's ordinary closes and open (`component:BottomSheet` FR5–FR9) when the value step closes with it. A creating `Editor` override's `onSave(null)` (FR14) shows Filters the same way. The flow therefore has one direction forward (open a step above) and one back (close the top step): no dismissal replaces a step, and Filters opens as other sheets close only when a creation ends after a direct entry. | DEC-3; `component:BottomSheet` FR5–FR9 | Current contract; verified by focused sheet tests and real-engine touch evidence. |+| FR15b | One open flow edits one draft of the filter list, which starts as `filters` when the flow opens. Every add, edit and removal (FR15) and Clear all (FR23, DEC-4) changes the draft, and the rows, the empty state and Clear all follow it; `onChange` is not called. Done applies the draft: it replays the recorded edits, in order, onto the field's latest `filters` — an add appends its filter; an edit replaces the first filter matching the one it edited (by field, operator, value and read-only flag); a removal drops the filters it removed — and calls `onChange` once per edit with the list after it and that edit's `changeType` and the `index` in that list, the calls a popover session makes, so a filter the parent added while the flow was open survives; an edit or removal whose target the parent removed meanwhile is skipped; then the flow closes; a draft that equals the filters at open (same filters, in order, by field, operator, value and read-only flag, whatever the order of a value's keys) reports nothing and closes. Done is in the Filters footer and in Add filter's footer when Add filter is the entry point. The field's result count follows the applied filters, so it changes on Done, not on an edit. | DEC-7 | Current contract; verified by focused sheet tests. |+| FR15c | A dismissal of the flow's bottom sheet — Escape, a scrim tap, a swipe, a platform close request on Filters, or on Add filter when it is the entry point — closes the flow directly while the draft equals the filters at open. While the draft differs, it opens the discard confirmation inside the sheet (`SheetConfirmation`, the shape `component:Tokenizer` FR27 states): title "Discard changes?", description "Your changes to the filters haven't been applied.", the destructive Discard changes first in reading order and the safe Keep editing focused first; its scrim and Escape take the safe action. Keep editing closes the confirmation, keeps the draft, and returns focus to the sheet's first control — the Filters header's Add filter, else the sheet's panel; Discard changes closes the flow with no `onChange`, and the next open starts from the applied filters. A dismissal of a step above the bottom sheet reveals the step beneath (FR15a) and asks nothing: the draft is still open. | DEC-7; `component:Tokenizer` FR27 | Current contract; verified by focused sheet tests. |+| FR16 | Focus follows the step: after a commit from the value step while creating, the value step and Add filter close and focus lands on the Filters header's Add filter, ready for the next filter; after a content-search suggestion or an `empty`-valued field row commits a filter directly, that filter's row; after Apply or Cancel from editing, the edited filter's row; after a row's trailing remove action, or a caller's `Editor` override's `onSave(null)` while editing, which closes the value step, the trailing remove action of the nearest remaining row that has one (the following one on a tie) — a plain row, a read-only filter's, has none and is passed over — so a run of removals needs no re-aiming, else Add filter when no such row remains; after Cancel from creation, Add filter is revealed with focus on the field row that opened the step, or on the content search when a suggestion opened it — and when a controlled update has removed that field, or the content-search field itself, the Add filter sheet's first control: its search field when one shows, else its first field row; after Add filter is dismissed, the Filters header's Add filter, or the empty state's; after a caller's `Editor` override calls `onSave(null)` while creating, the same (the flow returns to Filters unchanged, FR14); after a confirmed Clear all, the Filters sheet's first remaining control — a kept read-only filter's row has none, so Add filter — with the sheet still open; after Keep filters, Escape, or a scrim tap dismisses the confirmation, Clear all (`component:Dialog` AR2); and, as one rule for the Filters and Add filter sheets, when a controlled update unmounts the control that holds focus — a filter's row or its remove action, a dropped field's row, Clear all gone with the last editable filter — the nearest remaining row that is a button, counted among the button rows by the removed one's index (the following one, else the last) — a plain row (a read-only filter, or every filter while the field is read-only) is passed over — else the sheet's first control (the Add filter sheet's search field, Add filter in the Filters header or empty state), else the sheet's panel, so focus never lands on the page body inside the open sheet; when a controlled update replaces the value step's body with the unavailable state while focus was on one of its controls, Cancel (FR14); after the flow closes, the trigger. A sheet that opens takes focus on its panel, not on a control, except where this row names one; the Add filter sheet's search fields never take it on open (FR13). | DEC-3; touch-flow evidence | Current contract; verified by focused sheet tests and real-engine touch evidence. |+| FR17 | The value step edits every value type with the same editor the popover presentation uses (`nested` through its built-in nested editor, FR14), with four sheet-native differences: `enum`, `enum_list`, and `date_relative` render as full-width choice rows with a trailing indicator instead of a dropdown that would stack a second layer on the sheet — `radio` rows in a `radiogroup` named by the field label for `enum` and `date_relative` (a tap selects the row; the group is one tab stop — the checked row, else the first — and the arrow keys move focus and check the row they land on, wrapping, Home and End move to and check the first and last row, and Space or Enter checks the focused row — `spec:AST-020/FR15`), `checkbox` rows in a `group` named by the field label for `enum_list` (a tap toggles the row; each row is its own tab stop, toggled with Space or Enter), each carrying its state as `aria-checked`, as the Tokenizer's sheet rows do; `integer` and `float` stage every parseable keystroke, so the confirm action enables while the person is still typing, and unstage when the field is cleared or stops parsing, so it disables again over an empty field; a `string_list` or `entity_list` value edits through the Tokenizer's own sheet presentation (`component:Tokenizer/FR16–FR24`), its trigger showing the staged tokens in the step and its sheet titled with the field label; and a `date_absolute` value with `isDateOnly` unset or `true`, and a `date_range` value, edit through an inline Calendar on the sheet's surface — no popover opens from a sheet — reading a stored instant as its day in `timezoneID`, else the UTC day, and writing a picked day as that day's midnight in the same zone, the day the trigger's token and the Filters row show (FR11, FR12); a `date_absolute` value with `isDateOnly: false` edits through a date-and-time input, sized for touch, that reads and writes the wall-clock time in `timezoneID`, else the viewer's zone. `maxOperatorMenuItems` caps the string and entity suggestions as in the popover presentation. | DEC-3; touch-flow evidence; current value editors | Current contract; verified by focused sheet tests and real-engine touch evidence. Implementation gap: a date-only `date_absolute` value and a `date_range` value edit through the popover presentation's date fields in their sheet presentation — which read and write the day in `timezoneID`, else the UTC day, as this row states — not through an inline Calendar; a value whose operator sets `isDateOnly: false` edits through the popover presentation's date picker and time field in their sheet presentation, which read and write the wall-clock time this row names, not through one date-and-time input. |+| FR18 | Every list in the sheets derives synchronously from the config — the field list, its search, the content-search suggestions, and the choice rows — so no sheet shows an empty state before results arrive: "No filters match your search" and "No results found" render only for a non-empty query whose synchronous result set is empty, and only while their sheet is the open one; a sheet that is open beneath another, or closed with its body retained, renders and announces no empty-result or unavailable message (AR6). The value typeaheads and tokenizers inside the value step own their own pending states. | DEC-3; `architecture:react-component-runtime/INV1` | Current contract; verified by focused sheet tests and real-engine touch evidence. |+| FR19 | The result count renders at the end of the field in both presentations and is announced only when it changes after mount; the first render announces nothing, including under StrictMode's effect replay. The announcement takes the route `spec:AST-086/FR14` names for where the field is at that moment: inside the open sheet's dialog while a sheet of the flow is open (AR6), otherwise inside the nearest open native modal that holds the field (a Dialog, a modal Drawer), and the shared polite channel only when no modal does — never a channel the record names itself. | Current popover behavior; `architecture:react-component-runtime/INV3` | Current contract; verified by focused sheet tests and real-engine touch evidence. |+| FR20 | Every string the sheets introduce comes from the `@astryx.powersearch.*` catalog, reusing the existing editor keys where their meaning fits (Cancel, Apply, Operator, Value, Values, Entities, the placeholders, the result count). Content the popover presentation already renders keeps its source — field, operator, and value text from the config and its formatters — except that every label the sheets render for a generated choice comes from the catalog as one ICU message with a plural: the relative-date choice rows (`@astryx.powersearch.sheet.relative{Days,Weeks,Months}{Ago,FromNow}`, the same choices and, in English, the same words as the popover's editor lists) and the value summaries of FR12. | DEC-3; catalog contract | Current contract; verified by focused sheet tests and real-engine touch evidence. |+| FR21 | A `string_list` or `entity_list` value inside the value step opens the Tokenizer's sheet above the value step, one more sheet of the same stack (FR15a). Escape, a scrim tap, and a swipe dismiss only that topmost sheet; closing it returns focus to its trigger inside the value step; the value step keeps its staged state. | DEC-3; `family:overlay-dismissal`; `component:Tokenizer/FR18` | Current contract; verified by focused sheet tests and real-engine touch evidence. |+| FR22 | In the `popover` presentation, a read-only field (`isReadOnly`) MUST NOT remove a filter: it shows no Clear all, no token has a remove control, and Backspace on an empty input removes nothing. | The `isReadOnly` prop docs: "Prevent adding, editing, or removing filters." | Current contract |+| FR23 | In the `popover` presentation, Clear all MUST remove every editable filter and keep every read-only filter: it commits `onChange(<the read-only filters>, 'remove', <index of the first removed filter>)` and announces "Editable filters removed" while a read-only filter remains, otherwise "All filters removed". The clear control MUST render only while `hasClear` is set, the field is neither read-only nor disabled, and at least one editable filter exists. Backspace on an empty input MUST NOT remove a read-only filter; its token has no remove control. | DEC-4; a read-only filter's token has no remove control (current source) | Current contract |+| FR24 | In the popover presentation, a built-in filter token (no `components` Token override) that opens its editor is named by its visible text (field, operator and value); `aria-haspopup="dialog"`, `aria-expanded` is true while its editor is open, and the editor is a dialog named by the token's visible text. Its remove button is named by the remove word and the same visible text. | `spec:AST-020` FR1; WCAG 2.5.3 and 4.1.2; `component:Token/FR10` | Current contract. |+| FR25 | In both presentations a `date_absolute` value whose operator has `isDateOnly` unset or `true`, and each `ABSOLUTE` part of a `date_range` value, is a calendar day: the day its `unixSeconds` falls on in `timezoneID` when the prop is set, else the UTC day. The built-in token's text, the filter's accessible label and every announcement that names the value, the Filters row of the sheet presentation, and the date editor of either presentation all read that one day, with no time of day, so one value is never two days in one field; a `components[type].Token` override formats its own value (FR11) and receives `timezoneID` in its props, as the exported `PowerSearchToken` (the default token) does and reads, and a `components[type].Editor` override and `PowerSearchFilterEditor` receive `timezoneID` in their props so they can read the same day. A day picked in an editor is stored as that day's midnight in the same zone — `timezoneID`'s midnight, else UTC midnight — and the editor reopens on the day it stored, so an edit that keeps the day keeps the instant. Nothing about a value is rewritten by rendering or reopening: a value stored before `timezoneID` was given reads as its day in the zone now given. A `date_range` whose part is `NOW` or `RELATIVE` reads that part resolved to an instant first, then as its day. A value whose operator sets `isDateOnly: false` is an instant, not a calendar day: FR26 governs it. | DEC-5; `timezoneID` prop contract; `component:DateInput` (a calendar-day control) | Current contract. |+| FR26 | A `date_absolute` value whose operator has `isDateOnly: false` is an instant with a time of day. In both presentations its token shows its date and time and the sheet's Filters row shows the same, and its editor reads the stored instant's wall-clock time and stores the wall-clock time entered as the instant it names, both in `timezoneID` when the prop is set, else the viewer's zone — the zone the viewer reads a clock in — so the time typed is the time shown. In the popover presentation that editor is a date picker beside a time field; the sheet presentation's control is FR17's. A `components[type].Editor` override and `PowerSearchFilterEditor` receive `timezoneID` in their props so they can read the same time. A `date_absolute` whose operator has `isDateOnly` unset or `true` keeps its date-only picker and shows no time (FR25). | DEC-6; `OperatorValue.isDateOnly` contract; `component:DateInput`; `component:TimeInput` | Current contract. |### Allowed variation@@ -306,24 +308,24 @@ FR10–FR21 govern. FR25 governs a date-only value in both, and FR26 a date-and-### Representative states-| State | Required invariant | Allowed variation |-| ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------- |-| Outer PowerSearch narrower than 400 px | Editor prefers 400 px and logical-start alignment to the outer surface, but yields to available viewport width. | Layer runtime may shift or shrink it to remain visible. |-| Outer PowerSearch from 400 through 720 px | Editor matches the outer surface and remains logical-start aligned. | Existing vertical collision behavior may flip. |-| Wider than 720 px; add from inner input near left | Editor is 720 px wide and prefers the outer surface's physical left edge. | Viewport collision handling may shift it. |-| Wider than 720 px; add from inner input near right | Editor is 720 px wide and prefers the outer surface's physical right edge. | Viewport collision handling may shift it. |-| Wider than 720 px; edit a token/control near either end | Editor is 720 px wide and prefers the outer edge nearest that activated control. | Custom token markup may vary; identity remains exact. |-| Wider than 720 px; opening control is equidistant | Editor is 720 px wide and uses the outer surface's logical-start edge. | Direction determines the physical start edge. |-| Pointer, keyboard, or programmatic activation | The same stable opening control produces the same preferred edge regardless of activation modality. | Focus behavior remains unchanged. |-| Reopen from a control on the opposite side | Opening-control identity and preferred edge are recalculated for the new open, then remain latched until close. | Later layout changes do not move the open editor. |-| Sheet presentation, closed | The trigger shows the tokens or placeholder, `aria-expanded="false"`; its name is the label plus the visible text. | Token wrapping and placeholder text may vary. |-| Sheet presentation, Filters | One tall modal sheet named "Filters": fixed header with Add filter, rows with trailing remove actions scrolling between it and the fixed footer's Done and Clear all; with no filter, the centered Add filter is the only action. | Row count and the empty state's guidance text may vary. |-| Sheet presentation, Add filter | Above Filters: fixed header with an unfocused search when one shows, grouped field rows (the ungrouped ones under "General") or the content search's inline suggestions, and a compact empty state when a search matches nothing; no Back — a dismissal reveals Filters. | Field search appears from eight fields. |-| Sheet presentation, value step | Above the sheet that led to it: title, operator radios when needed, the staged editor on the sheet surface (or in muted sections with the operator group), Cancel and the confirm action; no Remove. | Editor per value type follows FR17. |-| Sheet presentation, Clear all | A confirmation dialog above Filters; confirming removes the editable filters, keeps read-only ones, and leaves Filters open with focus on it. | The confirmation's wording may vary. |-| Sheet presentation, list value | The Tokenizer's sheet opens above the step, titled with the field label, as the top sheet of the stack under its one scrim; Escape closes it alone. | One backdrop per stack, dismissal at the top sheet (`component:BottomSheet` FR6, FR7). |-| Sheet presentation, disabled while open | The flow closes; focus returns to the trigger; the trigger stays focusable. | Exit motion may vary. |-| Sheet presentation, `adaptive` resolution | The surface follows the shared compact-touch query while closed; an open flow keeps its presentation until it closes. | The query is shared, not PowerSearch-owned. |+| State | Required invariant | Allowed variation |+| ------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |+| Outer PowerSearch narrower than 400 px | Editor prefers 400 px and logical-start alignment to the outer surface, but yields to available viewport width. | Layer runtime may shift or shrink it to remain visible. |+| Outer PowerSearch from 400 through 720 px | Editor matches the outer surface and remains logical-start aligned. | Existing vertical collision behavior may flip. |+| Wider than 720 px; add from inner input near left | Editor is 720 px wide and prefers the outer surface's physical left edge. | Viewport collision handling may shift it. |+| Wider than 720 px; add from inner input near right | Editor is 720 px wide and prefers the outer surface's physical right edge. | Viewport collision handling may shift it. |+| Wider than 720 px; edit a token/control near either end | Editor is 720 px wide and prefers the outer edge nearest that activated control. | Custom token markup may vary; identity remains exact. |+| Wider than 720 px; opening control is equidistant | Editor is 720 px wide and uses the outer surface's logical-start edge. | Direction determines the physical start edge. |+| Pointer, keyboard, or programmatic activation | The same stable opening control produces the same preferred edge regardless of activation modality. | Focus behavior remains unchanged. |+| Reopen from a control on the opposite side | Opening-control identity and preferred edge are recalculated for the new open, then remain latched until close. | Later layout changes do not move the open editor. |+| Sheet presentation, closed | The trigger shows the tokens or placeholder, `aria-expanded="false"`; its name is the label plus the visible text. | Token wrapping and placeholder text may vary. |+| Sheet presentation, Filters | One tall modal sheet named "Filters": fixed header with Add filter, rows with trailing remove actions scrolling between it and the fixed footer's Done, which applies the draft, and Clear all; with no filter, the centered Add filter is the only action, Done staying while the draft has removals to apply. | Row count and the empty state's guidance text may vary. |+| Sheet presentation, Add filter | Above Filters: fixed header with an unfocused search when one shows, grouped field rows (the ungrouped ones under "General") or the content search's inline suggestions, and a compact empty state when a search matches nothing; no Back — a dismissal reveals Filters. | Field search appears from eight fields. |+| Sheet presentation, value step | Above the sheet that led to it: title, operator radios when needed, the staged editor on the sheet surface (or in muted sections with the operator group), Cancel and the confirm action; no Remove. | Editor per value type follows FR17. |+| Sheet presentation, Clear all | A confirmation dialog above Filters; confirming removes the editable filters, keeps read-only ones, and leaves Filters open with focus on it. | The confirmation's wording may vary. |+| Sheet presentation, list value | The Tokenizer's sheet opens above the step, titled with the field label, as the top sheet of the stack under its one scrim; Escape closes it alone. | One backdrop per stack, dismissal at the top sheet (`component:BottomSheet` FR6, FR7). |+| Sheet presentation, disabled while open | The flow closes; focus returns to the trigger; the trigger stays focusable. | Exit motion may vary. |+| Sheet presentation, `adaptive` resolution | The surface follows the shared compact-touch query while closed; an open flow keeps its presentation until it closes. | The query is shared, not PowerSearch-owned. |### Transformation and precedence order@@ -433,12 +435,11 @@ FR10–FR21 govern. FR25 governs a date-only value in both, and FR26 a date-and-outside it does not. Clear all announces "Editable filters removed" while aread-only filter remains, otherwise "All filters removed", inside the Filterssheet once its confirmation dialog has closed — not before, since the- confirmation is the top modal until then and hides the sheet's region — and a- result count that changes in the same commit is spoken with it as one catalog- message per wording, "Editable filters removed. {result count}" or "All- filters removed. {result count}", so a locale orders and punctuates the pair;- while the flow is closed the result count takes the route `spec:AST-086/FR14`- names for the field's position (FR19). Focus moves as FR16 states and returns+ confirmation is the top modal until then and hides the sheet's region. The+ result count follows the applied filters, which change on Done (FR15b), so+ no count changes with an edit inside the flow; after Done, while the flow is+ closed, the changed count takes the route `spec:AST-086/FR14` names for the+ field's position (FR19). Focus moves as FR16 states and returnsto the trigger after the flow closes.## Design relationships@@ -535,6 +536,7 @@ mark implementation and focused real-Chromium verification as pending.| FR4–FR6, FR9 | Opening-path tests plus real-Chromium geometry assertions | Add from inner input; edit actual left/right/equidistant token/control; pointer/keyboard; reopen opposite side | Using pointer coordinates, modality, wrapper-only identity, stale identity, or public props fails. | `audit:PowerSearch/interaction` || PR1–PR4 | Instrumented unit tests plus first-frame real-Chromium capture | Open, close, reopen opposite side; hidden placement commit; first painted frame | Render-time reads, repeated reads, observers, pointer tracking, or a default-position flash fails. | `audit:PowerSearch/performance` || FR8, AR1–AR3 | Existing PowerSearch/editor suites plus focused browser checks | Pointer and keyboard edit, apply, cancel, Escape, light dismiss, focus return, selection, semantics | Focus, semantics, selection, dismissal, or reachability changes fail. | `audit:PowerSearch/accessibility` |+| FR15b, FR15c | Focused sheet tests: no `onChange` before Done, Done's replay in order, an unchanged draft's silent close, clean and changed-draft dismissal with Keep editing and Discard changes, read-only filters kept through Clear all and Done, and the popover presentation's at-once reports || FR22 | PowerSearch and Tokenizer unit tests | A read-only field with a filter: no Clear all, no token remove control, Backspace on the empty input | A read-only field removes a filter through Backspace, Clear all, or a token control. | `audit:PowerSearch/interaction` || FR23 | PowerSearch and Tokenizer unit tests | Clear all with a read-only filter before two editable ones; every filter read-only; Backspace with a read-only last filter; the words with and without a read-only filter left | A read-only filter is removed, Clear all reports an index other than the first removed one, Clear all shows with no editable filter, or its words say every filter went while one remains. | `audit:PowerSearch/interaction` || FR24 | `PowerSearchTokenNaming.test.tsx`; real-Chromium accessibility tree of a popover token | Popover token with a value, read-only token, editor open and closed, a verb-last remove word | A token named without its value, a missing or stale `aria-expanded`, an unnamed or non-dialog editor, or a remove name that loses its locale's word order fails. | `audit:PowerSearch/accessibility` |@@ -631,7 +633,9 @@ Calendar in `timezoneID`, else UTC, and a value with a time of day on adate-and-time control in `timezoneID`, else the viewer's zone; every other valuetype uses the editor the popover presentation uses. Clear all asks forconfirmation, removes the filters the person can edit, keeps read-only ones, and-leaves Filters open. Seven details the flow fixes: a date-only value with no+leaves Filters open. The flow edits a draft that Done applies, and a dismissal+with a changed draft asks before discarding it (FR15b, FR15c, DEC-7). Seven+details the flow fixes: a date-only value with no`timezoneID` is its UTC day; a field whose every operator is `nested` lists,edited through the built-in nested editor; every string comes from the catalog(FR20); the empty results of Add filter's searches carry Core's titles (FR13);@@ -674,8 +678,9 @@ resolution changes (FR10); the Tokenizer's own `adaptive` trigger records thesame exception.The sheet presentation's Clear all keeps read-only filters, which are the-consumer's, and reports `remove` at the first removed index, as the popover-presentation's Clear all does (FR23, DEC-4). Its date editors, tokens and rows+consumer's, and records a `remove` at the first removed index in the draft,+which Done reports, as the popover presentation's Clear all reports it at once+(FR23, DEC-4, FR15b). Its date editors, tokens and rowsread and write a date-only `date_absolute` value, and each absolute part of a`date_range`, as one day in one zone, its day in `timezoneID` when the prop isset, else the UTC day; a value whose operator sets `isDateOnly: false` is an@@ -692,7 +697,8 @@ A read-only filter is non-removable by contract: it has no remove control, andno key or bulk action removes it either. "All filters" in Clear all thereforemeans every removable filter, and a Clear all that removes a read-only filteris a defect. Clear all removes the editable filters, keeps the read-only ones,-and reports `remove` at the first removed index. Backspace on an empty input+and reports `remove` at the first removed index — at once in the popover+presentation, on Done in the sheet presentation (FR15b). Backspace on an empty inputremoves nothing when the last filter is read-only (FR23). Rejected: a Clear allthat also removes read-only filters (a filter the person cannot remove alonewould go with the rest).@@ -739,6 +745,38 @@ instant (a wall-clock time typed by the person would then name a differenthour than the one they read on their clock). Rejected: a time on the token forevery `date_absolute` value (a calendar day has no time to show).+### DEC-7 — The sheet edits a draft that Done applies, and asks before discarding a changed one++**Reference:** `component:PowerSearch/DEC-7`+**Decider:** `imdreamrunner`, 2026-11-04, with the designer's confirmation++The sheet presentation holds a draft of the filter list from open: adding,+editing and removing a filter, and Clear all, change the draft, and the field's+`onChange` is called only when Done applies it (FR15b). A dismissal with a+changed draft asks before discarding it, through the confirmation Tokenizer's+sheet uses (FR15c). The save model is the one `component:Tokenizer` DEC-4+states for its sheet, so the two sheets a PowerSearch flow stacks — the filter+list and a list value's Tokenizer — commit the same way: with an explicit+action, never under the finger. Done reports the draft through the public+`onChange(filters, changeType, index)` by replaying the recorded edits in+order onto the field's latest `filters`, each call carrying the list after that+edit: a consumer receives the calls a popover session makes, with real change+types and indexes; one that keeps only the last call's list ends on the applied+list, since every call carries the whole list; and a filter the parent added+while the flow was open — a read-only one above all — survives, since the+replay starts from the list that holds it. An edit or removal whose target the+parent removed meanwhile is skipped, with nothing reported for it. Rejected: one call for the whole draft (the public `changeType`+has no value for a batch, and inventing one is an API change; a consumer that+switches on the type would receive a type it does not know). Rejected: replaying+only the net edits (a consumer that logs or reacts per change would see an+edit history that never happened). Rejected: applying the draft on every+dismissal (a swipe or a scrim tap would then commit by accident, which is what+the confirmation exists to prevent). Rejected: showing a controlled parent's+`filters` change inside the open flow (the draft is the flow's own list; the+change takes part on Done and shows on the next open). Rejected: replaying the+draft's own lists as recorded (a filter the parent added while the flow was+open would be replaced on Done).+## Open questions- Known gap, pre-existing in the popover presentation, againstdiff --git a/packages/core/locales/en.json b/packages/core/locales/en.jsonindex cea2e91f83..63d5c996ee 100644--- a/packages/core/locales/en.json+++ b/packages/core/locales/en.json@@ -267,6 +267,10 @@"defaultMessage": "No filters applied","description": "Heading of the PowerSearch Filters sheet empty state when no filter is active (experimental bottom-sheet presentation). Neutral tone."},+ "@astryx.powersearch.sheet.noFiltersInDraft": {+ "defaultMessage": "No filters",+ "description": "Heading of the PowerSearch Filters sheet empty state while the sheet's draft is empty but the field still has applied filters, which Done replaces. Must not say the filters are applied or removed yet. Neutral tone."+ },"@astryx.powersearch.sheet.noFiltersDescription": {"defaultMessage": "Add a filter to narrow your results and find what you need faster.","description": "Guidance line under the PowerSearch Filters sheet empty state, above its Add filter action. One short sentence."@@ -293,7 +297,23 @@},"@astryx.powersearch.sheet.done": {"defaultMessage": "Done",- "description": "Primary button label in the PowerSearch Filters sheet footer that closes the sheet. Short; marks the end of the filtering task."+ "description": "Primary button label in the PowerSearch Filters sheet footer that commits the sheet's filter draft and closes the sheet. Short; marks the end of the filtering task."+ },+ "@astryx.powersearch.sheet.discardTitle": {+ "defaultMessage": "Discard changes?",+ "description": "Title of the confirmation dialog shown when someone tries to dismiss the PowerSearch filter sheet after changing its filter draft. A question."+ },+ "@astryx.powersearch.sheet.discardDescription": {+ "defaultMessage": "Your changes to the filters haven't been applied.",+ "description": "Body of the dirty-dismiss confirmation inside the PowerSearch filter sheet. Done applies the draft; a dismissal would drop it."+ },+ "@astryx.powersearch.sheet.keepEditing": {+ "defaultMessage": "Keep editing",+ "description": "Label of the safe cancel action in the PowerSearch dirty-dismiss confirmation. It closes the confirmation and returns to the unchanged draft."+ },+ "@astryx.powersearch.sheet.discardConfirm": {+ "defaultMessage": "Discard changes",+ "description": "Label of the destructive action in the PowerSearch dirty-dismiss confirmation. It closes the sheet without applying its filter draft."},"@astryx.powersearch.sheet.search": {"defaultMessage": "Search",@@ -367,14 +387,6 @@"defaultMessage": "{label} {value}","description": "A Filters row's \"field operator\" text joined with its value, as the removal announcement reads it (for example \"Status is Open\"). Translators may reorder the two parts."},- "@astryx.powersearch.sheet.filtersClearedWithCount": {- "defaultMessage": "All filters removed. {resultCount}",- "description": "Polite screen-reader announcement after Clear all in the PowerSearch touch sheet when the result count changed with it; resultCount is the field's already formatted result count (for example \"240 results\"). Live-region text, never shown on screen."- },- "@astryx.powersearch.sheet.editableFiltersClearedWithCount": {- "defaultMessage": "Editable filters removed. {resultCount}",- "description": "Polite screen-reader announcement after Clear all in the PowerSearch touch sheet removes the editable filters, keeps read-only ones, and the result count changed with it; resultCount is the field's already formatted result count (for example \"240 results\"). Live-region text, never shown on screen."- },"@astryx.alertDialog.cancel": {"defaultMessage": "Cancel","description": "Button label on the secondary/dismiss button of an AlertDialog (modal confirmation). Imperative verb; consumers usually override with task-specific text."diff --git a/packages/core/src/PowerSearch/PowerSearch.doc.mjs b/packages/core/src/PowerSearch/PowerSearch.doc.mjsindex 63a79fb61a..fbc32150d1 100644--- a/packages/core/src/PowerSearch/PowerSearch.doc.mjs+++ b/packages/core/src/PowerSearch/PowerSearch.doc.mjs@@ -211,7 +211,7 @@ export const docs = {name: 'presentation',type: "'popover' | 'bottom-sheet' | 'adaptive'",description:- 'How the field presents filter editing. adaptive (the default) uses the bottom sheet on compact touch screens and the popover otherwise, resolved the same way Selector resolves it; the server render and the hydrating render are the popover. popover is the tokenizer field with its typeahead and the editor popover on every device. bottom-sheet makes the whole field, on every device, one trigger showing display-only filter tokens: it opens a Filters sheet listing the filters as rows that edit or remove a filter, with Add filter, Done, and Clear all (which asks first and keeps read-only filters); an Add filter sheet with the fields (or the content search with inline suggestions) opens above it, and a value step that stages operator → value and confirms from its footer opens above that. Dismissing a step reveals the one beneath. List values edit through the Tokenizer\'s own sheet. In the sheet presentation menuWidth and tokenOverflowBehavior have no surface to act on and warn in development. Pass presentation="popover" to keep the tokenizer field and the editor popover on every device.',+ 'How the field presents filter editing. adaptive (the default) uses the bottom sheet on compact touch screens and the popover otherwise, resolved the same way Selector resolves it; the server render and the hydrating render are the popover. popover is the tokenizer field with its typeahead and the editor popover on every device. bottom-sheet makes the whole field, on every device, one trigger showing display-only filter tokens: it opens a Filters sheet listing the filters as rows that edit or remove a filter, with Add filter, Done, and Clear all (which asks first and keeps read-only filters); an Add filter sheet with the fields (or the content search with inline suggestions) opens above it, and a value step that stages operator → value and confirms from its footer opens above that. Dismissing a step reveals the one beneath. The flow edits a draft: adding, editing and removing filters and Clear all change the draft, and onChange is called when Done applies it, once per edit in order; dismissing the flow with a changed draft asks before discarding it. List values edit through the Tokenizer\'s own sheet. In the sheet presentation menuWidth and tokenOverflowBehavior have no surface to act on and warn in development. Pass presentation="popover" to keep the tokenizer field and the editor popover on every device.',default: "'adaptive'",},],@@ -484,7 +484,7 @@ export const docsZh = {name: 'presentation',type: "'popover' | 'bottom-sheet' | 'adaptive'",description:- '字段如何呈现筛选编辑。adaptive(默认)在紧凑触摸屏上使用底部面板,其他情况使用 popover,解析方式与 Selector 相同;服务端渲染和水合期间的渲染均为 popover。popover 在所有设备上为带有预输入和编辑弹出层的标记字段。bottom-sheet 在所有设备上将整个字段变为一个显示只读筛选标记的触发按钮——点按后打开列出筛选项的「筛选」面板,每行可编辑或移除筛选(含添加筛选、完成、全部清除;全部清除会先确认,并保留只读筛选);列出字段(或带内联建议的内容搜索)的「添加筛选」面板在其上方打开,按运算符 → 值暂存并在底部确认的取值步骤再在其上方打开。关闭某一步会露出下方的那一步。列表值通过 Tokenizer 自身的面板编辑。在底部面板呈现中,menuWidth 和 tokenOverflowBehavior 没有作用对象,并会在开发环境中发出警告。传入 presentation="popover" 可在所有设备上保留标记字段和编辑弹出层。',+ '字段如何呈现筛选编辑。adaptive(默认)在紧凑触摸屏上使用底部面板,其他情况使用 popover,解析方式与 Selector 相同;服务端渲染和水合期间的渲染均为 popover。popover 在所有设备上为带有预输入和编辑弹出层的标记字段。bottom-sheet 在所有设备上将整个字段变为一个显示只读筛选标记的触发按钮——点按后打开列出筛选项的「筛选」面板,每行可编辑或移除筛选(含添加筛选、完成、全部清除;全部清除会先确认,并保留只读筛选);列出字段(或带内联建议的内容搜索)的「添加筛选」面板在其上方打开,按运算符 → 值暂存并在底部确认的取值步骤再在其上方打开。关闭某一步会露出下方的那一步。整个流程编辑的是草稿:添加、编辑、移除筛选和全部清除都只改动草稿,点按「完成」应用草稿时才按编辑顺序逐次触发 onChange;草稿有改动时关闭流程会先询问是否放弃。列表值通过 Tokenizer 自身的面板编辑。在底部面板呈现中,menuWidth 和 tokenOverflowBehavior 没有作用对象,并会在开发环境中发出警告。传入 presentation="popover" 可在所有设备上保留标记字段和编辑弹出层。',default: "'adaptive'",},],diff --git a/packages/core/src/PowerSearch/PowerSearch.tsx b/packages/core/src/PowerSearch/PowerSearch.tsxindex 5d413620ef..0378272bf3 100644--- a/packages/core/src/PowerSearch/PowerSearch.tsx+++ b/packages/core/src/PowerSearch/PowerSearch.tsx@@ -430,8 +430,10 @@ export interface PowerSearchProps extends Omit<* above it with the fields (or the content search with inline* suggestions), and a value step opens above that, stages operator →* value, and confirms from its footer. Dismissing a step reveals the- * one beneath. Suited to compact touch screens, where the editor- * popover competes with the software keyboard.+ * one beneath. The flow edits a draft: `onChange` is called when Done+ * applies it, once per edit in order, and a dismissal with a changed+ * draft asks before discarding it. Suited to compact touch screens,+ * where the editor popover competes with the software keyboard.* - `'adaptive'`: the bottom sheet on compact coarse-pointer screens,* otherwise the popover — the same resolution Selector uses. The server* render and the hydrating render are the popover.diff --git a/packages/core/src/PowerSearch/PowerSearchBottomSheet.test.tsx b/packages/core/src/PowerSearch/PowerSearchBottomSheet.test.tsxindex 719dda1c77..c20d089321 100644--- a/packages/core/src/PowerSearch/PowerSearchBottomSheet.test.tsx+++ b/packages/core/src/PowerSearch/PowerSearchBottomSheet.test.tsx@@ -38,6 +38,7 @@ import React, {createRef, StrictMode, useState} from 'react';import {act} from '@testing-library/react';import {PowerSearch, type PowerSearchProps} from './PowerSearch';import type {+ PowerSearchChangeType,PowerSearchConfig,PowerSearchEditorProps,PowerSearchFilter,@@ -228,8 +229,6 @@ const peopleSource: SearchSource = {const REORDERED: Overrides = {en: {'@astryx.powersearch.sheet.labelValue': '{value} ({label})',- '@astryx.powersearch.sheet.filtersClearedWithCount':- '{resultCount} — all filters removed',},};@@ -493,6 +492,12 @@ function addFilter(): void {fireEvent.click(matches[matches.length - 1]);}+/** Done in the current sheet: commits the draft and closes the flow. */+function done(): void {+ const matches = within(sheet()).getAllByRole('button', {name: 'Done'});+ fireEvent.click(matches[matches.length - 1]);+}+/** The Clear all confirmation, open above the Filters sheet. */function clearConfirmation(): HTMLElement {return screen.getByRole('alertdialog', {name: 'Clear all filters?'});@@ -1055,7 +1060,7 @@ describe('PowerSearch sheet trigger (FR11)', () => {const filtersSheet = screen.getByRole('dialog', {name: 'Filters'});await waitFor(() =>expect(modalLiveRegion(filtersSheet)).toHaveTextContent(- 'All filters removed. 240 results',+ 'All filters removed',),);expect(modalLiveRegion(host)?.textContent ?? '').not.toContain(@@ -1365,15 +1370,19 @@ describe('PowerSearch sheet trigger (FR11)', () => {expect(modalLiveRegion(filtersDialog)?.textContent ?? '').not.toMatch(/All filters removed|240 results/,);- // Confirmed, the outcome and the count that changed with it are one- // announcement in the still-open Filters sheet.+ // Confirmed, the outcome is announced in the still-open Filters sheet.+ // The count follows the applied filters, which change on Done, so it+ // is not part of the message.confirmClearAll();expect(isSheetOpen()).toBe(true);await waitFor(() =>expect(modalLiveRegion(filtersDialog)).toHaveTextContent(- 'All filters removed. 240 results',+ 'All filters removed',),);+ expect(modalLiveRegion(filtersDialog)?.textContent ?? '').not.toContain(+ '240 results',+ );expect(sharedLiveRegion()?.textContent ?? '').toBe('');} finally {spy.mockRestore();@@ -1448,8 +1457,12 @@ describe('PowerSearch Filters sheet (FR12)', () => {const {onChange} = setup({filters: [authorFilter, openFilter]});openSheet();fireEvent.click(removeButton('Status'));- expect(onChange).toHaveBeenCalledWith([authorFilter], 'remove', 1);+ // The draft drops the row; the field hears about it on Done.+ expect(onChange).not.toHaveBeenCalled();expect(sheet()).toHaveAttribute('aria-label', 'Filters');+ expect(within(sheet()).queryByText('Status is Open')).toBeNull();+ done();+ expect(onChange).toHaveBeenCalledWith([authorFilter], 'remove', 1);});it('removes a one-tap filter with a tap on its row or its remove action, not a checked indicator (FR12)', () => {@@ -1458,19 +1471,31 @@ describe('PowerSearch Filters sheet (FR12)', () => {operator: 'isTrue',value: {type: 'empty'},};- const {onChange} = setup({filters: [unassigned]});+ const {onChange, unmount} = setup({filters: [unassigned]});openSheet();const remove = removeButton('Unassigned');expect(remove.querySelector('svg')).toBeTruthy();expect(within(sheet()).queryByRole('checkbox')).toBeNull();tapRow('Unassigned is true');- expect(onChange).toHaveBeenLastCalledWith([], 'remove', 0);+ // The draft drops the row at once; the field hears about it on Done.+ expect(onChange).not.toHaveBeenCalled();expect(sheet()).toHaveAttribute('aria-label', 'Filters');- fireEvent.click(remove);- expect(onChange).toHaveBeenCalledTimes(2);+ expect(within(sheet()).queryByText('Unassigned is true')).toBeNull();+ done();+ expect(onChange).toHaveBeenCalledTimes(1);+ expect(onChange).toHaveBeenLastCalledWith([], 'remove', 0);+ unmount();+ // The trailing remove action removes the same way.+ const second = setup({filters: [unassigned]});+ openSheet();+ fireEvent.click(removeButton('Unassigned'));+ expect(second.onChange).not.toHaveBeenCalled();+ done();+ expect(second.onChange).toHaveBeenCalledTimes(1);+ expect(second.onChange).toHaveBeenLastCalledWith([], 'remove', 0);});- it('shows one centered Add filter and no header action, Done or Clear all when no filter is applied (FR12)', () => {+ it('shows one centered Add filter and no header action or Clear all when no filter is applied; Done stays while the emptied draft has removals to apply (FR12)', () => {function EmptyStateHarness() {const [filters, setFilters] = useState<ReadonlyArray<PowerSearchFilter>>([openFilter,@@ -1488,16 +1513,18 @@ describe('PowerSearch Filters sheet (FR12)', () => {openSheet();fireEvent.click(removeButton('Status'));expect(- within(sheet()).getByRole('heading', {name: 'No filters applied'}),+ within(sheet()).getByRole('heading', {name: 'No filters'}),).toBeTruthy();const addActions = within(sheet()).getAllByRole('button', {name: 'Add filter',});expect(addActions).toHaveLength(1);expect(addActions[0]).toHaveAttribute('data-variant', 'primary');- // After the last removal, focus lands on that one action.+ // After the last removal, focus lands on that one action. Done stays,+ // since the emptied draft still has removals to apply; Clear all goes+ // with the last removable filter.expect(addActions[0]).toHaveFocus();- expect(within(sheet()).queryByRole('button', {name: 'Done'})).toBeNull();+ expect(within(sheet()).getByRole('button', {name: 'Done'})).toBeTruthy();expect(within(sheet()).queryByRole('button', {name: 'Clear all'}),).toBeNull();@@ -1583,7 +1610,7 @@ describe('PowerSearch Filters sheet (FR12)', () => {expect(trigger()).toHaveFocus();});- it('clears editable filters behind a confirmation, keeps Filters open, and focuses Add filter (FR12, FR16)', () => {+ it('clears editable filters behind a confirmation, keeps Filters open, and focuses Add filter (FR12, FR16)', async () => {const onChange = vi.fn();function Harness() {const [filters, setFilters] = useState<ReadonlyArray<PowerSearchFilter>>([@@ -1617,18 +1644,27 @@ describe('PowerSearch Filters sheet (FR12)', () => {within(confirmation).getByRole('button', {name: 'Keep filters'}),).toHaveFocus();confirmClearAll();- expect(onChange).toHaveBeenCalledWith([], 'remove', 0);+ // The clear empties the draft; the field keeps its filters until Done.+ expect(onChange).not.toHaveBeenCalled();expect(screen.queryByRole('alertdialog', {name: 'Clear all filters?'}),).toBeNull();expect(isSheetOpen()).toBe(true);+ // The emptied draft's heading does not call the filters removed: they+ // are applied until Done.expect(- within(sheet()).getByRole('heading', {name: 'No filters applied'}),+ within(sheet()).getByRole('heading', {name: 'No filters'}),).toBeTruthy();+ expect(+ within(sheet()).queryByRole('heading', {name: 'No filters applied'}),+ ).toBeNull();expect(within(sheet()).getByRole('button', {name: 'Add filter'}),).toHaveFocus();- expect(within(field()).queryByText('Open')).toBeNull();+ expect(within(field()).getByText('Open')).toBeTruthy();+ done();+ expect(onChange).toHaveBeenCalledWith([], 'remove', 0);+ await waitFor(() => expect(within(field()).queryByText('Open')).toBeNull());});it('keeps read-only filters on Clear all, reporting the first removed index (FR12)', () => {@@ -1637,8 +1673,10 @@ describe('PowerSearch Filters sheet (FR12)', () => {openSheet();fireEvent.click(within(sheet()).getByRole('button', {name: 'Clear all'}));confirmClearAll();- expect(onChange).toHaveBeenCalledWith([pinned], 'remove', 1);+ expect(onChange).not.toHaveBeenCalled();expect(isSheetOpen()).toBe(true);+ done();+ expect(onChange).toHaveBeenCalledWith([pinned], 'remove', 1);});it('returns to Filters unchanged when the confirmation is dismissed or kept (FR12)', () => {@@ -1716,8 +1754,8 @@ describe('PowerSearch Filters sheet (FR12)', () => {config={config}filters={filters}isDisabled={isDisabled}- // The commit that queues focus on Add filter also disables the- // field, which closes the flow before that focus lands.+ // Done's report disables the field, which closes the flow+ // wherever it was.onChange={next => {setFilters(next);setIsDisabled(true);@@ -1733,6 +1771,8 @@ describe('PowerSearch Filters sheet (FR12)', () => {tapRow('Status');tapRow('Closed');addFilter();+ expect(isSheetOpen()).toBe(true);+ done();expect(isSheetOpen()).toBe(false);// Reopened before the closing sheets finish their exit, so the flow is// still mounted.@@ -1834,13 +1874,16 @@ describe('PowerSearch Filters sheet (FR12)', () => {// The value step finishes its exit before the removal.settleSheets();fireEvent.click(removeButton('Mixed'));- expect(onChange).toHaveBeenCalledWith([openFilter], 'remove', 1);const filtersDialog = sheet();await waitFor(() =>expect(modalLiveRegion(filtersDialog)).toHaveTextContent('Removed Mixed all of 1 filter',),);+ expect(onChange).not.toHaveBeenCalled();+ expect(onChange).not.toHaveBeenCalled();+ done();+ expect(onChange).toHaveBeenCalledWith([openFilter], 'remove', 1);unmount();// Read-only field: a plain row.render(<Harness readOnly />);@@ -1962,6 +2005,7 @@ describe('PowerSearch Filters sheet (FR12)', () => {);expect(primary()).toBeEnabled();fireEvent.click(primary());+ done();expect(onChange).toHaveBeenCalledWith([{@@ -2090,16 +2134,17 @@ describe('PowerSearch Filters sheet (FR12)', () => {// the first group's.fireEvent.click(rows()[1]);expect(subField()).toEqual(['Author']);- // Saving writes this group, unchanged, at its own index.+ // Apply writes this group, unchanged, into the draft at its own index.fireEvent.click(within(sheet()).getByRole('button', {name: 'Apply'}));- expect(onChange).toHaveBeenCalledWith(- [statusGroup, authorGroup],- 'edit',- 1,- );+ expect(onChange).not.toHaveBeenCalled();// And reopening the first group again shows the first group's content.fireEvent.click(rows()[0]);expect(subField()).toEqual(['Status']);+ fireEvent.click(within(sheet()).getByRole('button', {name: 'Cancel'}));+ settleSheets();+ // A draft equal to the filters at open reports nothing on Done.+ done();+ expect(onChange).not.toHaveBeenCalled();});it('mounts nothing of the flow at rest: the trigger alone before a press and again after the exit (INV7)', async () => {@@ -2121,7 +2166,7 @@ describe('PowerSearch Filters sheet (FR12)', () => {expect(screen.queryByRole('heading', {name: 'Filters'})).toBeNull();});- it('returns focus to the nearest row when Apply or Cancel finds the edited filter gone after a controlled update (FR15, FR16)', () => {+ it('keeps the edited filter in the open draft when a controlled update removes it behind the flow; Apply and Cancel return to its row (FR15, FR16)', () => {const third: PowerSearchFilter = {field: 'status',operator: 'is',@@ -2137,7 +2182,8 @@ describe('PowerSearch Filters sheet (FR12)', () => {/>);}- // Apply: the edited (middle) filter is removed while its step is open.+ // An outside removal of the edited (middle) filter does not reach the+ // open draft: Apply and Cancel find the filter where the step left it.const {rerender, unmount} = render(<Harness filters={[openFilter, authorFilter, third]} />,);@@ -2147,18 +2193,16 @@ describe('PowerSearch Filters sheet (FR12)', () => {expect(within(sheet()).getByRole('heading', {name: 'Filters'}),).toBeTruthy();- // Nothing was written, and focus is on the row that followed it.expect(- within(sheet()).getByRole('button', {name: 'Status is Closed'}),+ within(sheet()).getByRole('button', {name: 'Author is Ada'}),).toHaveFocus();unmount();- // Cancel, with no row left: Add filter.const second = render(<Harness filters={[authorFilter]} />);openEditFlow('Author is Ada');second.rerender(<Harness filters={[]} />);fireEvent.click(within(sheet()).getByRole('button', {name: 'Cancel'}));expect(- within(sheet()).getByRole('button', {name: 'Add filter'}),+ within(sheet()).getByRole('button', {name: 'Author is Ada'}),).toHaveFocus();});@@ -2218,7 +2262,7 @@ describe('PowerSearch Filters sheet (FR12)', () => {).toHaveFocus();});- describe('a controlled update that removes the focused control (FR16)', () => {+ describe('a draft edit that removes the focused control (FR16)', () => {const third: PowerSearchFilter = {field: 'status',operator: 'is',@@ -2245,25 +2289,28 @@ describe('PowerSearch Filters sheet (FR12)', () => {}it('moves focus from a removed Filters row to the nearest remaining row by index', () => {- const {rerender} = render(- <Harness filters={[openFilter, authorFilter, third]} />,- );+ render(<Harness filters={[openFilter, authorFilter, third]} />);openSheet();- within(sheet()).getByRole('button', {name: 'Author is Ada'}).focus();- // The focused (middle) row is removed by the parent.- rerender(<Harness filters={[openFilter, third]} />);- expect(- within(sheet()).getByRole('button', {name: 'Status is Closed'}),- ).toHaveFocus();+ // The focused (middle) row is removed by its own trailing action.+ const authorRemove = removeButton('Author');+ authorRemove.focus();+ fireEvent.click(authorRemove);+ // The next row's own remove action, so a run of removals stays on+ // the same control.+ const removes = () =>+ within(sheet()).getAllByRole('button', {name: 'Remove Status filter'});+ expect(removes()).toHaveLength(2);+ expect(removes()[1]).toHaveFocus();// The focused (now last) row is removed: the new last row takes focus.- within(sheet()).getByRole('button', {name: 'Status is Closed'}).focus();- rerender(<Harness filters={[openFilter]} />);+ fireEvent.click(removes()[1]);+ expect(removes()).toHaveLength(1);+ expect(removes()[0]).toHaveFocus();expect(within(sheet()).getByRole('button', {name: 'Status is Open'}),- ).toHaveFocus();+ ).toBeTruthy();});- it('keeps focus on the same filter when the parent reorders the filters (FR12, FR16)', () => {+ it('leaves the open draft, its rows and focus untouched when the parent reorders or removes filters behind the flow (FR12, FR16)', () => {const {rerender} = render(<Harness filters={[openFilter, authorFilter, third]} />,);@@ -2272,42 +2319,19 @@ describe('PowerSearch Filters sheet (FR12)', () => {name: 'Author is Ada',});authorRow.focus();- // Same objects, new order: the row moves, its element stays.rerender(<Harness filters={[third, openFilter, authorFilter]} />);- expect(within(sheet()).getByRole('button', {name: 'Author is Ada'})).toBe(- authorRow,- );- expect(authorRow).toHaveFocus();- // Cloned objects, new order: the row is matched by its signature.- rerender(- <Harness filters={[{...authorFilter}, {...third}, {...openFilter}]} />,- );+ rerender(<Harness filters={[third]} />);+ expect(+ within(sheet())+ .getAllByRole('listitem')+ .map(row => row.textContent?.replace(/Remove.*$/, '').trim()),+ ).toEqual(['Status is Open', 'Author is Ada', 'Status is Closed']);expect(within(sheet()).getByRole('button', {name: 'Author is Ada'})).toBe(authorRow,);expect(authorRow).toHaveFocus();});- it('keeps focus on the same filter when the parent removes a filter above it (FR12, FR16)', () => {- const {rerender} = render(- <Harness filters={[openFilter, authorFilter, third]} />,- );- openSheet();- const authorRow = within(sheet()).getByRole('button', {- name: 'Author is Ada',- });- authorRow.focus();- rerender(<Harness filters={[authorFilter, third]} />);- expect(authorRow).toHaveFocus();- expect(within(sheet()).getByRole('button', {name: 'Author is Ada'})).toBe(- authorRow,- );- // Not the row at the old index.- expect(- within(sheet()).getByRole('button', {name: 'Status is Closed'}),- ).not.toHaveFocus();- });-it('counts rows in one index space — plain read-only rows above the removed row are not counted (FR16)', () => {const readOnlyFirst: PowerSearchFilter = {...openFilter,@@ -2318,25 +2342,27 @@ describe('PowerSearch Filters sheet (FR12)', () => {operator: 'is',value: {type: 'string', value: 'Grace'},};- const {rerender} = render(+ render(<Harness filters={[readOnlyFirst, authorFilter, third, fourth]} />,);openSheet();// Row 0 is plain (read-only); the focused Author row is button row 0.- within(sheet()).getByRole('button', {name: 'Author is Ada'}).focus();- rerender(<Harness filters={[readOnlyFirst, third, fourth]} />);+ const authorRemove = within(sheet()).getAllByRole('button', {+ name: 'Remove Author filter',+ })[0];+ authorRemove.focus();+ fireEvent.click(authorRemove);// The row that followed it — not one row too far (counting the plain// row would land on "Author is Grace").- expect(- within(sheet()).getByRole('button', {name: 'Status is Closed'}),- ).toHaveFocus();+ expect(removeButton('Status')).toHaveFocus();});it('moves focus from Clear all, gone with the last filter, to Add filter', () => {- const {rerender} = render(<Harness filters={[openFilter]} hasClear />);+ render(<Harness filters={[openFilter]} hasClear />);openSheet();within(sheet()).getByRole('button', {name: 'Clear all'}).focus();- rerender(<Harness filters={[]} hasClear />);+ fireEvent.click(within(sheet()).getByRole('button', {name: 'Clear all'}));+ confirmClearAll();expect(within(sheet()).queryByRole('button', {name: 'Clear all'}),).toBeNull();@@ -2508,6 +2534,7 @@ describe('PowerSearch Filters sheet (FR12)', () => {onCancel: expect.any(Function),});fireEvent.click(within(sheet()).getByRole('button', {name: 'Save group'}));+ done();expect(onChange).toHaveBeenCalledWith([saved], 'edit', 0);});@@ -2698,7 +2725,7 @@ describe('PowerSearch Add filter (FR13)', () => {operator: 'isTrue',value: {type: 'empty'},};- expect(onChange).toHaveBeenCalledWith([openFilter, unassigned], 'add', 1);+ expect(onChange).not.toHaveBeenCalled();const filtersDialog = sheet();expect(filtersDialog).toHaveAttribute('aria-label', 'Filters');expect(@@ -2711,6 +2738,8 @@ describe('PowerSearch Add filter (FR13)', () => {'Added Unassigned is true',),);+ done();+ expect(onChange).toHaveBeenCalledWith([openFilter, unassigned], 'add', 1);} finally {spy.mockRestore();}@@ -2874,6 +2903,7 @@ describe('PowerSearch value step (FR14–FR16)', () => {expect(choice('Closed')).toBeChecked();expect(onChange).not.toHaveBeenCalled();addFilter();+ done();expect(onChange).toHaveBeenCalledTimes(1);expect(onChange).toHaveBeenCalledWith([@@ -2965,6 +2995,7 @@ describe('PowerSearch value step (FR14–FR16)', () => {);expect(onChange).not.toHaveBeenCalled();addFilter();+ done();expect(onChange).toHaveBeenCalledWith([{field: 'status', operator: 'isEmpty', value: {type: 'empty'}}],'add',@@ -2988,6 +3019,7 @@ describe('PowerSearch value step (FR14–FR16)', () => {);tapRow('Open');addFilter();+ done();expect(onChange).toHaveBeenCalledWith([{@@ -3030,6 +3062,7 @@ describe('PowerSearch value step (FR14–FR16)', () => {}),).toBeNull();addFilter();+ done();expect(onChange).toHaveBeenCalledWith([{field: 'status', operator: 'isEmpty', value: {type: 'empty'}}],'add',@@ -3157,6 +3190,7 @@ describe('PowerSearch value step (FR14–FR16)', () => {expect(choice('Urgent')).not.toBeChecked();fireEvent.click(choice('Urgent'));addFilter();+ done();expect(onChange).toHaveBeenCalledWith([{@@ -3191,6 +3225,7 @@ describe('PowerSearch value step (FR14–FR16)', () => {tapRow('Closed');expect(onChange).not.toHaveBeenCalled();apply();+ done();expect(onChange).toHaveBeenCalledTimes(1);expect(onChange).toHaveBeenCalledWith([@@ -3326,13 +3361,13 @@ describe('PowerSearch value step (FR14–FR16)', () => {render(<Harness />);openSheet();fireEvent.click(removeButton('Status'));- expect(within(sheet()).getByText('No filters applied')).toBeTruthy();+ expect(within(sheet()).getByText('No filters')).toBeTruthy();expect(within(sheet()).getByRole('button', {name: 'Add filter'}),).toHaveFocus();});- it('follows the original filter when controlled props reorder it', () => {+ it("edits the draft while controlled props change behind the open flow: the rows keep the draft's order, and Done replays the edit onto the latest filters", () => {const onChange = vi.fn();const {rerender} = render(<PowerSearch@@ -3353,6 +3388,10 @@ describe('PowerSearch value step (FR14–FR16)', () => {);tapRow('Closed');apply();+ expect(onChange).not.toHaveBeenCalled();+ // Done replays the edit onto the latest filters, where the parent's+ // reorder put Status second.+ done();expect(onChange).toHaveBeenCalledWith([authorFilter,@@ -3446,7 +3485,7 @@ describe('PowerSearch value step (FR14–FR16)', () => {// The value step finishes its exit before the removal.settleSheets();fireEvent.click(removeButton('legacy'));- expect(onChange).toHaveBeenCalledWith([openFilter], 'remove', 1);+ expect(onChange).not.toHaveBeenCalled();const filtersDialog = sheet();expect(within(filtersDialog).queryByRole('button', {name: 'legacy was'}),@@ -3456,6 +3495,8 @@ describe('PowerSearch value step (FR14–FR16)', () => {'Removed legacy was',),);+ done();+ expect(onChange).toHaveBeenCalledWith([openFilter], 'remove', 1);} finally {spy.mockRestore();}@@ -3548,6 +3589,7 @@ describe('PowerSearch value step (FR14–FR16)', () => {onCancel: expect.any(Function),});fireEvent.click(screen.getByRole('button', {name: 'Custom save'}));+ done();expect(onChange).toHaveBeenCalledWith([savedFilter], 'add', 0);});@@ -3578,6 +3620,253 @@ describe('PowerSearch value step (FR14–FR16)', () => {// Stacked steps (FR15a)// =============================================================================+describe('PowerSearch sheet draft, Done and dismissal (FR15, FR15b, FR15c, FR22)', () => {+ it('holds a draft: add, remove, edit and Clear all change the rows and nothing reaches onChange before Done; Done replays the edits in order with the list after each (FR15, FR15b)', () => {+ const {onChange} = setup({filters: [openFilter, authorFilter]});+ openSheet();+ // Remove Author, then add Status is Closed through Add filter.+ fireEvent.click(removeButton('Author'));+ openAddFlow();+ tapRow('Status');+ tapRow('Closed');+ addFilter();+ expect(onChange).not.toHaveBeenCalled();+ const closed: PowerSearchFilter = {+ field: 'status',+ operator: 'is',+ value: {type: 'enum', value: 'closed'},+ };+ expect(+ within(sheet())+ .getAllByRole('listitem')+ .map(row => row.textContent?.replace(/Remove.*$/, '').trim()),+ ).toEqual(['Status is Open', 'Status is Closed']);+ done();+ expect(onChange).toHaveBeenCalledTimes(2);+ expect(onChange).toHaveBeenNthCalledWith(1, [openFilter], 'remove', 1);+ expect(onChange).toHaveBeenNthCalledWith(2, [openFilter, closed], 'add', 1);+ expect(isSheetOpen()).toBe(false);+ });++ it('Done with an unchanged draft reports nothing and closes (FR15b)', () => {+ const {onChange} = setup({filters: [openFilter]});+ openSheet();+ done();+ expect(onChange).not.toHaveBeenCalled();+ expect(isSheetOpen()).toBe(false);+ });++ it('a swipe, scrim or Escape dismissal closes directly while the draft equals the filters at open (FR15c)', () => {+ const {onChange} = setup({filters: [openFilter]});+ openSheet();+ fireEvent.keyDown(sheet(), {key: 'Escape'});+ expect(screen.queryByRole('alertdialog')).toBeNull();+ expect(isSheetOpen()).toBe(false);+ expect(onChange).not.toHaveBeenCalled();+ });++ it('a dismissal with a changed draft asks first: Keep editing returns focus to Add filter with the draft intact; Discard changes closes without a report, and the next open starts from the applied filters (FR15c)', async () => {+ const spy = mockModalDialogs();+ try {+ const {onChange} = setup({filters: [openFilter, authorFilter]});+ openSheet();+ fireEvent.click(removeButton('Author'));+ fireEvent.keyDown(sheet(), {key: 'Escape'});+ const confirmation = await screen.findByRole('alertdialog', {+ name: 'Discard changes?',+ });+ expect(confirmation).toHaveTextContent(+ "Your changes to the filters haven't been applied.",+ );+ const [destructive, safe] = within(confirmation).getAllByRole('button');+ expect(destructive).toHaveAccessibleName('Discard changes');+ expect(safe).toHaveAccessibleName('Keep editing');+ expect(safe).toHaveFocus();+ expect(isSheetOpen()).toBe(true);+ // Keep editing: the confirmation goes, the draft stands, focus lands+ // on the Filters sheet's first control.+ fireEvent.click(safe);+ await waitFor(() => expect(screen.queryByRole('alertdialog')).toBeNull());+ expect(isSheetOpen()).toBe(true);+ expect(+ within(sheet()).queryByRole('button', {name: 'Author is Ada'}),+ ).toBeNull();+ expect(+ within(sheet()).getByRole('button', {name: 'Add filter'}),+ ).toHaveFocus();+ expect(onChange).not.toHaveBeenCalled();+ // Discard changes: closes, reports nothing; the applied filters stand.+ fireEvent.keyDown(sheet(), {key: 'Escape'});+ fireEvent.click(+ within(+ await screen.findByRole('alertdialog', {name: 'Discard changes?'}),+ ).getByRole('button', {name: 'Discard changes'}),+ );+ expect(isSheetOpen()).toBe(false);+ expect(onChange).not.toHaveBeenCalled();+ expect(within(field()).getByText('Ada')).toBeTruthy();+ settleSheets();+ openSheet();+ expect(+ within(sheet()).getByRole('button', {name: 'Author is Ada'}),+ ).toBeTruthy();+ } finally {+ spy.mockRestore();+ }+ });++ it('dismissing Add filter opened as the entry point with a changed draft asks the same way (FR15c)', async () => {+ const spy = mockModalDialogs();+ try {+ const {onChange} = setup();+ openSheet();+ expect(+ within(sheet()).getByRole('heading', {name: 'Add filter'}),+ ).toBeTruthy();+ tapRow('Status');+ tapRow('Closed');+ addFilter();+ // The add landed in Filters, which is now the bottom of the stack.+ fireEvent.keyDown(sheet(), {key: 'Escape'});+ expect(+ await screen.findByRole('alertdialog', {name: 'Discard changes?'}),+ ).toBeTruthy();+ expect(onChange).not.toHaveBeenCalled();+ } finally {+ spy.mockRestore();+ }+ });++ it('keeps read-only filters in the draft: Clear all removes only editable ones, and Done reports the kept list (FR22)', () => {+ const pinned: PowerSearchFilter = {...openFilter, isReadOnly: true};+ const {onChange} = setup({filters: [authorFilter, pinned]});+ openSheet();+ expect(+ within(sheet()).queryByRole('button', {name: 'Remove Status filter'}),+ ).toBeNull();+ fireEvent.click(within(sheet()).getByRole('button', {name: 'Clear all'}));+ confirmClearAll();+ expect(within(sheet()).getAllByRole('listitem')).toHaveLength(1);+ expect(within(sheet()).getByText(/^Status/)).toBeTruthy();+ expect(onChange).not.toHaveBeenCalled();+ done();+ expect(onChange).toHaveBeenCalledTimes(1);+ expect(onChange).toHaveBeenCalledWith([pinned], 'remove', 0);+ });++ it('judges an unchanged draft by filter signature, whatever the order of a value\'s keys: no "Discard changes?" and nothing reported (FR15b)', () => {+ const reordered: PowerSearchFilter = {+ field: 'status',+ operator: 'is',+ value: {value: 'open', type: 'enum'},+ };+ const {onChange} = setup({filters: [reordered]});+ openSheet();+ // Edit the filter to the same value, which the editor writes with its+ // keys in its own order.+ tapRow('Status is Open');+ apply();+ settleSheets();+ expect(onChange).not.toHaveBeenCalled();+ fireEvent.keyDown(sheet(), {key: 'Escape'});+ expect(screen.queryByRole('alertdialog')).toBeNull();+ expect(isSheetOpen()).toBe(false);+ expect(onChange).not.toHaveBeenCalled();+ });++ it("Done replays the edits onto the field's latest filters: a read-only filter the parent added while the flow was open survives, an edit finds its filter by signature, and a removal whose target the parent removed is skipped (FR15b, DEC-7)", () => {+ const pinned: PowerSearchFilter = {+ field: 'author',+ operator: 'is',+ value: {type: 'string', value: 'Grace'},+ isReadOnly: true,+ };+ const third: PowerSearchFilter = {+ field: 'author',+ operator: 'is',+ value: {type: 'string', value: 'Linus'},+ };+ const calls: [+ ReadonlyArray<PowerSearchFilter>,+ PowerSearchChangeType,+ number,+ ][] = [];+ function Harness() {+ const [filters, setFilters] = useState<ReadonlyArray<PowerSearchFilter>>([+ openFilter,+ authorFilter,+ third,+ ]);+ return (+ <>+ <button+ type="button"+ onClick={() => setFilters(current => [pinned, ...current])}>+ Pin+ </button>+ <button+ type="button"+ onClick={() =>+ setFilters(current => current.filter(f => f !== third))+ }>+ Drop third+ </button>+ <PowerSearch+ config={config}+ filters={filters}+ onChange={(next, type, index) => {+ calls.push([next, type, index]);+ setFilters(next);+ }}+ presentation="bottom-sheet"+ />+ </>+ );+ }+ render(<Harness />);+ openSheet();+ // Draft: remove Ada, edit Status is Open → Closed, remove Linus.+ const authorRemoves = () =>+ within(sheet()).getAllByRole('button', {name: 'Remove Author filter'});+ fireEvent.click(authorRemoves()[0]);+ tapRow('Status is Open');+ tapRow('Closed');+ apply();+ settleSheets();+ fireEvent.click(authorRemoves()[0]);+ // Meanwhile the parent pins a read-only filter and drops the third one.+ fireEvent.click(screen.getByRole('button', {name: 'Pin'}));+ fireEvent.click(screen.getByRole('button', {name: 'Drop third'}));+ expect(calls).toHaveLength(0);+ done();+ const edited: PowerSearchFilter = {+ field: 'status',+ operator: 'is',+ value: {type: 'enum', value: 'closed'},+ };+ // Replayed onto [pinned, open, Ada]: remove Ada (index 2), edit Status+ // is Open at index 1; Linus's removal is skipped, the parent dropped it.+ expect(calls).toEqual([+ [[pinned, openFilter], 'remove', 2],+ [[pinned, edited], 'edit', 1],+ ]);+ });++ it('the popover presentation is unchanged: a token removal reports at once, with no draft and no Done (desktop)', async () => {+ const {onChange} = setup({+ presentation: 'popover',+ filters: [openFilter, authorFilter],+ });+ fireEvent.click(+ screen.getAllByRole('button', {name: 'Remove Status: is Open'})[0],+ );+ expect(onChange).toHaveBeenCalledTimes(1);+ expect(onChange).toHaveBeenCalledWith([authorFilter], 'remove', 0);+ expect(screen.queryByRole('button', {name: 'Done'})).toBeNull();+ expect(screen.queryByRole('alertdialog')).toBeNull();+ });+});+describe('PowerSearch step sheets (retained stack, FR15a)', () => {// Dismissing the top step closes only that sheet, so the prior step returns// through the stack's reveal motion instead of reopening above the current@@ -3963,6 +4252,12 @@ describe('PowerSearch content search (FR13)', () => {fireEvent.click(within(sheet()).getByRole('button', {name: '"release notes"'}),);+ await waitFor(() => expect(isSheetOpen()).toBe(true));+ expect(+ within(sheet()).getByRole('heading', {name: 'Filters'}),+ ).toBeTruthy();+ expect(onChange).not.toHaveBeenCalled();+ done();expect(onChange).toHaveBeenCalledWith([openFilter,@@ -3975,10 +4270,6 @@ describe('PowerSearch content search (FR13)', () => {'add',1,);- await waitFor(() => expect(isSheetOpen()).toBe(true));- expect(- within(sheet()).getByRole('heading', {name: 'Filters'}),- ).toBeTruthy();});it('adds a value suggestion from Enter and announces it inside the Filters sheet (AR6; AST-086 FR14)', async () => {@@ -3993,6 +4284,18 @@ describe('PowerSearch content search (FR13)', () => {).toBeTruthy();fireEvent.keyDown(input, {key: 'Enter'});// The first suggestion is the free-text content item.+ expect(onChange).not.toHaveBeenCalled();+ // The announcement lands in the Filters sheet the flow moved to, the+ // dialog that stays open, not on the page body behind the modal.+ const filtersDialog = sheet();+ expect(filtersDialog).toHaveAttribute('aria-label', 'Filters');+ await waitFor(() =>+ expect(modalLiveRegion(filtersDialog)).toHaveTextContent(+ 'Added "status clo"',+ ),+ );+ expect(sharedLiveRegion()?.textContent ?? '').toBe('');+ done();expect(onChange).toHaveBeenCalledWith([{@@ -4004,16 +4307,6 @@ describe('PowerSearch content search (FR13)', () => {'add',0,);- // The announcement lands in the Filters sheet the flow moved to, the- // dialog that stays open, not on the page body behind the modal.- const filtersDialog = sheet();- expect(filtersDialog).toHaveAttribute('aria-label', 'Filters');- await waitFor(() =>- expect(modalLiveRegion(filtersDialog)).toHaveTextContent(- 'Added "status clo"',- ),- );- expect(sharedLiveRegion()?.textContent ?? '').toBe('');} finally {spy.mockRestore();}@@ -4168,6 +4461,7 @@ describe('PowerSearch sheet value types (FR17)', () => {target: {value: 'hello'},});addFilter();+ done();expect(onChange).toHaveBeenCalledWith([{@@ -4194,6 +4488,7 @@ describe('PowerSearch sheet value types (FR17)', () => {});fireEvent.click(option);addFilter();+ done();expect(onChange).toHaveBeenCalledWith([{@@ -4246,6 +4541,7 @@ describe('PowerSearch sheet value types (FR17)', () => {within(sheet()).getByRole('heading', {name: 'ID is any of'}),).toBeTruthy();addFilter();+ done();expect(onChange).toHaveBeenCalledWith([{@@ -4272,6 +4568,7 @@ describe('PowerSearch sheet value types (FR17)', () => {).toBeEnabled();fireEvent.blur(input);addFilter();+ done();expect(onChange).toHaveBeenCalledWith([{field: 'lines', operator: 'gt', value: {type: 'integer', value: 12}}],'add',@@ -4326,6 +4623,7 @@ describe('PowerSearch sheet value types (FR17)', () => {fireEvent.input(input, {target: {value: '2.5'}});fireEvent.blur(input);addFilter();+ done();expect(onChange).toHaveBeenCalledWith([{field: 'cost', operator: 'gt', value: {type: 'float', value: 2.5}}],'add',@@ -4381,6 +4679,7 @@ describe('PowerSearch sheet value types (FR17)', () => {fireEvent.change(input, {target: {value: '03/11/2024'}});fireEvent.blur(input);apply();+ done();expect(onChange).toHaveBeenCalledWith([{@@ -4443,6 +4742,7 @@ describe('PowerSearch sheet value types (FR17)', () => {fireEvent.change(time, {target: {value: '8:30 PM'}});fireEvent.blur(time);apply();+ done();expect(onChange).toHaveBeenCalledWith([{@@ -4469,6 +4769,7 @@ describe('PowerSearch sheet value types (FR17)', () => {tapRow('7 days ago');expect(choice('7 days ago')).toBeChecked();addFilter();+ done();expect(onChange).toHaveBeenCalledWith([{@@ -4523,6 +4824,7 @@ describe('PowerSearch sheet value types (FR17)', () => {expect(screen.queryByRole('dialog', {name: 'Assignee'})).toBeNull(),);addFilter();+ done();expect(onChange).toHaveBeenCalledWith([{@@ -4547,6 +4849,7 @@ describe('PowerSearch sheet value types (FR17)', () => {target: {value: 'teal'},});addFilter();+ done();expect(onChange).toHaveBeenCalledWith([{@@ -4819,7 +5122,7 @@ describe('PowerSearch sheet value text', () => {}});- it('announces Clear all and a changed count through one catalog message a locale can reorder (INV1a)', async () => {+ it('announces Clear all as its outcome alone: the result count follows the applied filters, which change on Done (AR6)', async () => {const spy = mockModalDialogs();try {function Harness() {@@ -4845,9 +5148,12 @@ describe('PowerSearch sheet value text', () => {confirmClearAll();await waitFor(() =>expect(modalLiveRegion(filtersDialog)?.textContent ?? '').toContain(- '240 results — all filters removed',+ 'All filters removed',),);+ expect(modalLiveRegion(filtersDialog)?.textContent ?? '').not.toContain(+ '240 results',+ );} finally {spy.mockRestore();}diff --git a/packages/core/src/PowerSearch/PowerSearchBottomSheet.tsx b/packages/core/src/PowerSearch/PowerSearchBottomSheet.tsxindex fe2cb46880..21516898dc 100644--- a/packages/core/src/PowerSearch/PowerSearchBottomSheet.tsx+++ b/packages/core/src/PowerSearch/PowerSearchBottomSheet.tsx@@ -181,7 +181,13 @@ export interface PowerSearchBottomSheetProps {config: InternalConfig;/** The caller's config, handed to Editor overrides as they expect it. */configProp: PowerSearchConfig;+ /** The committed filters; the draft the sheet edits starts from them. */filters: ReadonlyArray<PowerSearchFilter>;+ /**+ * The field's `onChange`. Done replays the draft's edits through it, in+ * order, each with the list as it stood after that edit; nothing is+ * reported before Done.+ */onChange: (filters: ReadonlyArray<PowerSearchFilter>,changeType: PowerSearchChangeType,@@ -208,6 +214,116 @@ export interface PowerSearchBottomSheetProps {// Styles// =============================================================================+/** One edit of the draft: the list before it, the list after it, and how it was reported. */+interface DraftEdit {+ before: ReadonlyArray<PowerSearchFilter>;+ after: ReadonlyArray<PowerSearchFilter>;+ changeType: PowerSearchChangeType;+ index: number;+}++// Whether two filter lists hold the same filters in the same order, by the+// key-order-insensitive signature the sheet matches filters with.+function hasSameFilters(+ a: ReadonlyArray<PowerSearchFilter>,+ b: ReadonlyArray<PowerSearchFilter>,+): boolean {+ return (+ a.length === b.length &&+ a.every(+ (filter, index) =>+ b[index] != null &&+ filterSignature(filter) === filterSignature(b[index]),+ )+ );+}++// The filters `before` holds that `after` does not, as a multiset by+// signature, in `before` order.+function removedFilters(+ before: ReadonlyArray<PowerSearchFilter>,+ after: ReadonlyArray<PowerSearchFilter>,+): PowerSearchFilter[] {+ const remaining = new Map<string, number>();+ for (const filter of after) {+ const signature = filterSignature(filter);+ remaining.set(signature, (remaining.get(signature) ?? 0) + 1);+ }+ return before.filter(filter => {+ const signature = filterSignature(filter);+ const count = remaining.get(signature) ?? 0;+ if (count > 0) {+ remaining.set(signature, count - 1);+ return false;+ }+ return true;+ });+}++/**+ * Replays the draft's edits onto `base`, the field's latest filters, and+ * reports each through `report` with the list after it. An add appends; an+ * edit replaces the first filter matching the one it edited; a removal drops+ * the filters it removed, by signature. An edit or removal whose target is+ * not in the base list is skipped: the parent removed it meanwhile.+ */+export function replayDraftEdits(+ base: ReadonlyArray<PowerSearchFilter>,+ edits: ReadonlyArray<DraftEdit>,+ report: (+ filters: ReadonlyArray<PowerSearchFilter>,+ changeType: PowerSearchChangeType,+ index: number,+ ) => void,+): ReadonlyArray<PowerSearchFilter> {+ let current = base;+ for (const edit of edits) {+ if (edit.changeType === 'add') {+ const added = edit.after[edit.index];+ if (added == null) {+ continue;+ }+ current = [...current, added];+ report(current, 'add', current.length - 1);+ } else if (edit.changeType === 'edit') {+ const original = edit.before[edit.index];+ const updated = edit.after[edit.index];+ if (original == null || updated == null) {+ continue;+ }+ const signature = filterSignature(original);+ const index = current.findIndex(+ filter => filterSignature(filter) === signature,+ );+ if (index === -1) {+ continue;+ }+ current = current.map((filter, i) => (i === index ? updated : filter));+ report(current, 'edit', index);+ } else {+ const removed = removedFilters(edit.before, edit.after).map(+ filterSignature,+ );+ const indexes: number[] = [];+ for (const signature of removed) {+ const index = current.findIndex(+ (filter, i) =>+ !indexes.includes(i) && filterSignature(filter) === signature,+ );+ if (index !== -1) {+ indexes.push(index);+ }+ }+ if (indexes.length === 0) {+ continue;+ }+ current = current.filter((_, i) => !indexes.includes(i));+ report(current, 'remove', Math.min(...indexes));+ }+ }+ return current;+}+// The trailing plus a field row shows when choosing it adds the filter at// once, and the Add filter actions' glyph. Core's default icon set has no plus.function PlusIcon(props: SVGProps<SVGSVGElement>) {@@ -834,8 +950,8 @@ export function PowerSearchBottomSheet({resultCountText,config,configProp,- filters,- onChange,+ filters: committedFilters,+ onChange: onCommit,searchSource,placeholder,isReadOnly,@@ -854,6 +970,35 @@ export function PowerSearchBottomSheet({const formatList = useListFormatter();const isInteractive = !isDisabled && !isReadOnly;+ // ---- draft ----+ // One open flow edits one draft of the filter list; `onChange` waits for+ // Done, and a dismissal with a changed draft asks first.+ const [filtersAtOpen, setFiltersAtOpen] = useState(() => committedFilters);+ const [filters, setFilters] = useState(() => committedFilters);+ // The draft as of the last edit, for the edit log's `before` lists.+ const draftRef = useRef(filters);+ const draftEditsRef = useRef<DraftEdit[]>([]);+ const onChange = useCallback(+ (+ next: ReadonlyArray<PowerSearchFilter>,+ changeType: PowerSearchChangeType,+ index: number,+ ) => {+ draftEditsRef.current.push({+ before: draftRef.current,+ after: next,+ changeType,+ index,+ });+ draftRef.current = next;+ setFilters(next);+ },+ [],+ );+ const isDraftDirty = !hasSameFilters(filtersAtOpen, filters);+ const [isDiscardConfirmationOpen, setIsDiscardConfirmationOpen] =+ useState(false);+const contentSearchFieldKey = config.config.contentSearchFieldKey;const contentSearchOperator =contentSearchFieldKey == null@@ -961,9 +1106,6 @@ export function PowerSearchBottomSheet({const [contentQuery, setContentQuery] = useState('');const [isClearConfirmationOpen, setIsClearConfirmationOpen] = useState(false);const clearAllButtonRef = useRef<HTMLButtonElement>(null);- // Set while Clear all commits, so the result count that changes in that- // commit is spoken with Clear all's outcome, as one message.- const isClearingRef = useRef(false);// `useAnnounce` delivers inside the open Astryx modal that encloses its// caller, and this component renders above the@@ -990,13 +1132,21 @@ export function PowerSearchBottomSheet({if (isOpen !== wasOpen) {setWasOpen(isOpen);if (isOpen) {+ // A fresh draft from the committed filters; the entry step is judged+ // against them, not the previous session's draft.+ setFiltersAtOpen(committedFilters);+ setFilters(committedFilters);+ draftRef.current = committedFilters;+ draftEditsRef.current = [];+ const startsOnAddFilter = committedFilters.length === 0 && isInteractive;setFieldQuery('');setContentQuery('');- setStep(isEntryAddFilter ? 'fields' : 'manage');- setFieldPickerOrigin(isEntryAddFilter ? 'trigger' : 'manage');+ setStep(startsOnAddFilter ? 'fields' : 'manage');+ setFieldPickerOrigin(startsOnAddFilter ? 'trigger' : 'manage');} else {setStep(null);setIsClearConfirmationOpen(false);+ setIsDiscardConfirmationOpen(false);}}@@ -1005,6 +1155,33 @@ export function PowerSearchBottomSheet({setStep(null);onOpenChange(false);}, [onOpenChange]);+ // Done replays each edit in order onto the field's latest filters, so a+ // consumer gets the calls a popover session makes and keeps a filter it+ // added meanwhile.+ const commitAndClose = useCallback(() => {+ if (isDraftDirty) {+ replayDraftEdits(committedFilters, draftEditsRef.current, onCommit);+ }+ draftEditsRef.current = [];+ closeFlow();+ }, [closeFlow, committedFilters, isDraftDirty, onCommit]);+ const requestDismiss = useCallback(() => {+ if (isDraftDirty) {+ setIsDiscardConfirmationOpen(true);+ } else {+ closeFlow();+ }+ }, [closeFlow, isDraftDirty]);+ const closeDiscardConfirmation = () => {+ // eslint-disable-next-line @eslint-react/dom-no-flush-sync -- the confirmation must be gone before focus moves back into the sheet+ flushSync(() => setIsDiscardConfirmationOpen(false));+ const target =+ stepRef.current === 'manage'+ ? (managerAddButtonRef.current ??+ manageSheetRef.current?.closest<HTMLElement>('[tabindex="-1"]'))+ : fieldsSheetRef.current?.closest<HTMLElement>('[tabindex="-1"]');+ target?.focus({preventScroll: true});+ };// Whether a Filters row is a button: the field interactive and the// filter not read-only. The row opens the value step — the editor for its@@ -1279,17 +1456,8 @@ export function PowerSearchBottomSheet({// is quiet then, so the change is spoken here, inside the dialog. Only a// change after the flow opened is spoken.const announcedResultCountRef = useRef(resultCountText);- // The latest result count, for Clear all's handler to read after its- // commit has flushed.- const latestResultCountRef = useRef(resultCountText);- useLayoutEffect(() => {- latestResultCountRef.current = resultCountText;- }, [resultCountText]);useEffect(() => {- if (- isClearingRef.current ||- resultCountText === announcedResultCountRef.current- ) {+ if (resultCountText === announcedResultCountRef.current) {return;}announcedResultCountRef.current = resultCountText;@@ -1630,52 +1798,31 @@ export function PowerSearchBottomSheet({// confirmation must be gone before focus moves into the sheet and the// outcome is routed into the sheet's region, so its close is flushed// first. The outcome is "Editable filters removed" while a read-only filter- // remains, otherwise "All filters removed", joined with a result count that- // changed in the same commit as one catalog message; focus moves to the- // sheet's first remaining control: a kept read-only row has none, so Add- // filter.+ // remains, otherwise "All filters removed"; the result count follows the+ // applied filters, which change on Done, so none changes here. Focus moves+ // to the sheet's first remaining control: a kept read-only row has none,+ // so Add filter.const closeClearConfirmation = (confirmed: boolean) => {const kept = filters.filter(filter => filter.isReadOnly);const firstRemovedIndex = filters.findIndex(filter => !filter.isReadOnly);const isClearing = confirmed && isInteractive && firstRemovedIndex >= 0;- isClearingRef.current = isClearing;- try {- // eslint-disable-next-line @eslint-react/dom-no-flush-sync -- the confirmation must be gone before focus moves into the sheet and the words are routed into it- flushSync(() => {- setIsClearConfirmationOpen(false);- if (isClearing) {- onChange(kept, 'remove', firstRemovedIndex);- }- });- } finally {- isClearingRef.current = false;- }+ // eslint-disable-next-line @eslint-react/dom-no-flush-sync -- the confirmation must be gone before focus moves into the sheet and the words are routed into it+ flushSync(() => {+ setIsClearConfirmationOpen(false);+ if (isClearing) {+ onChange(kept, 'remove', firstRemovedIndex);+ }+ });if (!isClearing) {clearAllButtonRef.current?.focus();return;}managerAddButtonRef.current?.focus({preventScroll: true});- const resultCount = latestResultCountRef.current;- const changedCount =- resultCount !== announcedResultCountRef.current ? resultCount : null;- announcedResultCountRef.current = resultCount;- if (kept.length > 0) {- announce(- changedCount == null- ? t('@astryx.powersearch.editableFiltersRemoved')- : t('@astryx.powersearch.sheet.editableFiltersClearedWithCount', {- resultCount: changedCount,- }),- );- } else {- announce(- changedCount == null- ? t('@astryx.powersearch.allFiltersRemoved')- : t('@astryx.powersearch.sheet.filtersClearedWithCount', {- resultCount: changedCount,- }),- );- }+ announce(+ kept.length > 0+ ? t('@astryx.powersearch.editableFiltersRemoved')+ : t('@astryx.powersearch.allFiltersRemoved'),+ );};const handleOperatorSelect = useCallback((operator: PowerSearchOperator) => {@@ -1776,10 +1923,10 @@ export function PowerSearchBottomSheet({const handleManageOpenChange = useCallback((isSheetOpen: boolean) => {if (!isSheetOpen && stepRef.current === 'manage') {- closeFlow();+ requestDismiss();}},- [closeFlow],+ [requestDismiss],);const handleFieldsOpenChange = useCallback((isSheetOpen: boolean) => {@@ -1787,13 +1934,13 @@ export function PowerSearchBottomSheet({return;}if (fieldPickerOrigin === 'trigger') {- closeFlow();+ requestDismiss();return;}queueManagerAddFocus();setStep('manage');},- [closeFlow, fieldPickerOrigin, queueManagerAddFocus],+ [fieldPickerOrigin, queueManagerAddFocus, requestDismiss],);const handleValueOpenChange = useCallback((isSheetOpen: boolean) => {@@ -2076,7 +2223,11 @@ export function PowerSearchBottomSheet({// is spoken in this sheet when it appears.isManageSheetOpen && (<EmptyState- title={t('@astryx.powersearch.sheet.noFilters')}+ title={t(+ isDraftDirty+ ? '@astryx.powersearch.sheet.noFiltersInDraft'+ : '@astryx.powersearch.sheet.noFilters',+ )}description={t('@astryx.powersearch.sheet.noFiltersDescription',)}@@ -2157,7 +2308,10 @@ export function PowerSearchBottomSheet({)}</div></div>- {filterRows.length > 0 && (+ {/* The footer stays while the draft differs from the applied+ filters: an emptied draft still needs Done to apply the+ removals. */}+ {(filterRows.length > 0 || isDraftDirty) && (<div {...stylex.props(styles.footer, styles.fixedFooter)}>{isClearAllShown && (<Button@@ -2178,7 +2332,7 @@ export function PowerSearchBottomSheet({? styles.footerEqualAction: [styles.footerSoleAction, styles.touchHitArea]}- onClick={closeFlow}+ onClick={commitAndClose}width={isClearAllShown ? undefined : '100%'}/></div>@@ -2373,7 +2527,7 @@ export function PowerSearchBottomSheet({variant="primary"width="100%"xstyle={styles.touchAction}- onClick={closeFlow}+ onClick={commitAndClose}/></div>)}@@ -2518,6 +2672,25 @@ export function PowerSearchBottomSheet({onAction={() => closeClearConfirmation(true)}/>)}+ {isDiscardConfirmationOpen && (+ <SheetConfirmation+ isOpen+ onOpenChange={isConfirmationOpen => {+ if (!isConfirmationOpen) {+ closeDiscardConfirmation();+ }+ }}+ title={t('@astryx.powersearch.sheet.discardTitle')}+ description={t('@astryx.powersearch.sheet.discardDescription')}+ actionLabel={t('@astryx.powersearch.sheet.discardConfirm')}+ cancelLabel={t('@astryx.powersearch.sheet.keepEditing')}+ onAction={() => {+ setIsDiscardConfirmationOpen(false);+ draftEditsRef.current = [];+ closeFlow();+ }}+ />+ )}</>);}