An open source design system that's fully customizable and agent ready
TypeScript
fix(core): PowerSearch reads a date-only value as one day in one zone, and edits it there (#9655)
Xinzi Zhou40c6e418c05b
diff --git a/.changeset/powersearch-date-zone.md b/.changeset/powersearch-date-zone.mdnew file mode 100644index 0000000000..6302a4c94e--- /dev/null+++ b/.changeset/powersearch-date-zone.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] PowerSearch: a date-only `date_absolute` value (`isDateOnly` unset or `true`) reads as one day in one zone — on the token, in the accessible label and announcements, and in the edit popover's date editor — and the editor writes the day picked. Before, the token showed the device's day, the label showed a date and a time in `timezoneID`, and the editor read and wrote the UTC day without receiving `timezoneID`, so west of UTC a filter opened on the day after the one its token showed and re-picking that day moved the value a day earlier. Now a date-only value (`isDateOnly` unset or true) is a calendar day in `timezoneID`, else the UTC day: the token shows that day; the accessible label and `formatFilterValue` show that day with no time of day (UTC midnight March 9 in Los Angeles read "Mar 8, 2024, 4:00 PM" and reads "Mar 9, 2024"); the editor opens on it; and a picked day stores as that zone's midnight — with `timezoneID` set this is a different instant from the UTC midnight stored before, so a caller that derived the day from the instant's UTC date reads it in `timezoneID` instead, and a value the old editor stored as UTC midnight under a `timezoneID` west of UTC now reads the day before in the editor on every device, and on the token for a viewer at or east of UTC (UTC midnight March 9 under `America/Los_Angeles` reads March 8 everywhere; a Los Angeles viewer's token and the label already did), the day it would have stored — re-save such values, or read them as UTC days; with `timezoneID` unset no stored value changes. Each absolute `date_range` part is read and written as a calendar day the same way in the range editor. An operator with `isDateOnly: false` is untouched: its token, label and editor read as before. In the sheet presentation the rows and the value step read and write the same day. The exported `PowerSearchToken` and a `components` Token override receive `timezoneID` (a new optional prop on `PowerSearchTokenProps`), and `PowerSearchToken` shows that day too, where it showed the label's date and time. A `[fix]`, not a breaking change: the released popover read one value in three zones, so nothing valid relied on how a day was stored, and `timezoneID` is documented for date formatting. A `components` Editor override and `PowerSearchFilterEditor` receive `timezoneID`.++@imdreamrunnerdiff --git a/docs/specs/components/PowerSearch/PowerSearch.spec.md b/docs/specs/components/PowerSearch/PowerSearch.spec.mdindex 352c475e13..62c368b5d9 100644--- a/docs/specs/components/PowerSearch/PowerSearch.spec.md+++ b/docs/specs/components/PowerSearch/PowerSearch.spec.md@@ -14,6 +14,7 @@ verified_by:[packages/core/src/PowerSearch/PowerSearch.test.tsx,packages/core/src/PowerSearch/PowerSearchEditPopover.test.tsx,+ packages/core/src/PowerSearch/PowerSearchDateZone.test.tsx,packages/core/src/PowerSearch/formatFilterValue.test.ts,packages/core/src/PowerSearch/PowerSearchBottomSheet.test.tsx,packages/core/src/PowerSearch/PowerSearch.ssr.test.tsx,@@ -114,8 +115,7 @@ present-tense implementation gap note.which the first removed index is. It ships as a `[fix]` patch release.- DEC-3 changes nothing in the `popover` presentation. Its Clear all is FR23's(DEC-4), which the sheet presentation's matches, and its date-only days are- FR25's (DEC-5), which the sheet presentation's match (FR25's gap note names- what both still do). Where its handling of+ FR25's (DEC-5), which the sheet presentation's match. Where its handling ofa value whose operator sets `isDateOnly: false` still differs from the sheetpresentation's (the known gap in Open questions), bringing it to the sheet'sbehavior changes what the stable presentation reports through `onChange`, so@@ -134,9 +134,7 @@ present-tense implementation gap note.in three zones (the token in the viewer's zone, the label in `timezoneID`with a time of day, the editor on the UTC day), so no consumer can validlyrely on how a day is stored or read, and `timezoneID` is documented for- date formatting, so honoring it restores that contract. Implementation gap:- the shipped popover still reads the three zones; the sheet presentation's- tokens and rows read the device's day and its value step the UTC day.+ date formatting, so honoring it restores that contract.Consumer migration instructions belong in consumer docs and release notes.@@ -227,34 +225,34 @@ popover, rendered when `experimental` is omitted or 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.-| 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 | `experimental.presentation` selects the surface. `popover`, the value when `experimental` or the option is omitted, is the tokenizer field with its typeahead and editor popover, unchanged except as FR19 (no mount announcement) states. `bottom-sheet` is the trigger and sheet flow of FR11–FR21 on every device. `adaptive` 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`). 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. The popover's token does not read dates this way yet (FR25's implementation gap). 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. Implementation gap: the trigger's token reads a `date_absolute` value as the popover presentation's token does, as its day in the device's zone with no time, not in `timezoneID` (FR25's gap), nor as a date and time for a value whose operator sets `isDateOnly: false`. |-| 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. Implementation gap: a row reads a `date_absolute` value as the trigger's token does, as its day in the device's zone with no time, not in `timezoneID` (FR25's gap), nor as a date and time for a value whose operator sets `isDateOnly: false`. |-| 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 sheet passes no `experimental` option down to them; 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. The popover presentation's date editors do not follow these zones yet (FR25's implementation gap). `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 UTC day whatever `timezoneID` is (FR25's gap), not through an inline Calendar; a value whose operator sets `isDateOnly: false` edits a date only and stores its midnight. |-| 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 outside this row: in the popover presentation its token, label and editor keep their released reading (the known gap in Open questions); the sheet presentation's rule for it is FR11, FR12 and FR17's. | DEC-5; `timezoneID` prop contract; `component:DateInput` (a calendar-day control) | Current contract. Implementation gap: the popover presentation reads one date-only value in three zones — its token in the viewer's zone, its accessible label in `timezoneID` with a time of day, its editor on the UTC day — and the sheet presentation's trigger tokens and rows read the device's day, as the popover's token does, and its value step the UTC day; the exported `PowerSearchToken` reads the label's `timezoneID` date and time; a `components` Token or Editor override and `PowerSearchFilterEditor` receive no `timezoneID`. |+| 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 | `experimental.presentation` selects the surface. `popover`, the value when `experimental` or the option is omitted, is the tokenizer field with its typeahead and editor popover, unchanged except as FR19 (no mount announcement) states. `bottom-sheet` is the trigger and sheet flow of FR11–FR21 on every device. `adaptive` 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`). 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. Implementation gap: the trigger's token reads a `date_absolute` value whose operator sets `isDateOnly: false` as the popover presentation's token does, as its day in the device's zone with no time, not as a date and time in `timezoneID`. |+| 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. Implementation gap: a row reads a `date_absolute` value whose operator sets `isDateOnly: false` as the trigger's token does, as its day in the device's zone with no time, not as a date and time in `timezoneID`. |+| 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 sheet passes no `experimental` option down to them; 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 a date only and stores its midnight. |+| 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 outside this row: in the popover presentation its token, label and editor keep their released reading (the known gap in Open questions); the sheet presentation's rule for it is FR11, FR12 and FR17's. | DEC-5; `timezoneID` prop contract; `component:DateInput` (a calendar-day control) | Current contract. |### Allowed variation@@ -517,18 +515,18 @@ mark implementation and focused real-Chromium verification as pending.## Verification map-| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |-| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------- |-| FR1–FR3, FR7 | PowerSearch unit tests plus real-Chromium geometry assertions | 399/400, 720/721, wide outer surface, narrow viewport, LTR/RTL, collision | Removing either clamp, capping the main menu, or allowing viewport overflow fails. | `audit:PowerSearch/layout` |-| 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` |-| 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` |-| FR25 | PowerSearch date-zone tests under four host zones (UTC, Los Angeles, Tokyo, Honolulu) with `timezoneID` set to each zone and unset: token text, the removal announcement that carries the accessible label, the editor's opening day, the stored instant after a pick, a round trip that moves the day and back, a `components` Editor override and `PowerSearchFilterEditor` receiving the zone, range parts read and written, and an `isDateOnly: false` value kept on its released reading; plus the formatter's unit tests (implementation gap: not yet in the tree) | a Los Angeles evening instant with `timezoneID` set and unset, a pick across the US daylight-time change, a `date_range` of two instants | The token and the editor show different days for one value, a re-picked day moves the instant, or a day shows a time | `audit:PowerSearch/interaction` |-| FR10–FR21, AR4–AR6, PR5 | Focused PowerSearch sheet tests with the compact-touch query stubbed both ways, plus real-engine touch evidence | default popover, forced sheet, adaptive both ways (server markup and hydration as the popover field on a coarse-pointer client, then the trigger, no recoverable error, focus on the body; with `hasAutoFocus`, the autofocused input's focus ending on the trigger with no `onBlur` or `onFocus` to the caller), trigger name, Filters/Add filter/value steps, each value type, list value through the Tokenizer sheet, Clear all, read-only, disabled while open, focus after each step, focus after an `adaptive` switch from the trigger, the input, a removed control, an open editor popover, and from outside the field, a field inside an open Dialog announcing the count, Clear all, and in-sheet messages inside that Dialog and never on the page body, StrictMode result count, in-sheet live region while a sheet is open (added, removed, count, empty results), Clear all announced only after the dialog's exit, row, token and Removed text sharing one formatter, a date-only value as its day in `timezoneID`, else the UTC day, and a date-and-time value in `timezoneID`, else the viewer's zone, on all three (UTC, Tokyo, Honolulu, unset), summaries and relative-date labels and values from the catalog, the row and Removed through one reorderable message, an unmatched relative-date value as stored, a filter the config no longer knows listed and removable, a cleared number unstaged, choice rows as radios and checkboxes with `aria-checked`, a stale read-only filter as a plain row, a removal next to a nested row focusing that row's remove action, a list value joined by the locale's narrow conjunction list in English, Simplified Chinese, Japanese, and German, an empty-result message spoken once per query from its rendered element, a controlled update that removes the edited field moving focus from the replaced body to Cancel and announcing the unavailable state in the sheet while the step is open and never from a step beneath another or retained closed, Apply and Cancel after a controlled update removed the edited filter focusing the nearest row, else Add filter, a row's trailing remove action focusing the next row's remove action, a one-tap `empty`-valued filter added from its field row and removed from its row, Clear all behind its confirmation keeping read-only filters and leaving Filters open, a dismissed step revealing the step beneath with focus restored to it, Add filter opening with its search unfocused and a touch drag on the rows blurring a focused search, a stale filter's step titled as its row reads (raw keys for what is gone, the field's label when the field remains), Cancel from creation after the opening field was removed focusing the Add filter sheet's first control, a removed focused Filters row, a removed Clear all, and a dropped focused field row each handing focus to the nearest remaining row or the sheet's first control, element counts at rest and with each of the Filters, Add filter and value sheets open, and with the Tokenizer's list-value sheet stacked above the value step, under fine and coarse pointers, nothing of the flow in the DOM at rest before a press and after the exit, a nested filter edited and created through the built-in nested editor (its sub-filter rows wrapping inside a 390 and a 414 px sheet; its root operator picker absent on a mixed field, the Operator group in its place), a nested-only field and its suggestion offered, a suggestion's operator checked over the field's default, the Operator group outside a caller's Editor override on a mixed field, a count changed during the exit spoken with Clear all's message as one catalog message after the close, a radio group's arrow keys, Home, and End moving and checking, Space and Enter checking a focused radio row and toggling a checkbox row, right-to-left layout with the row chevrons mirrored in RTL (`design:bidirectionality/DR4`) | A field without `experimental` changes beyond what FR19 states, a value commits before the step confirms, Clear all removes a read-only filter, the trigger carries native `disabled`, focus lands elsewhere, an announcement reaches a channel outside the modal that holds the field at that moment, or the popover bundle carries the sheets. | `audit:PowerSearch/sheet` |-| Record structure | `scripts/check-knowledge.mjs` | Component-contract schema and current-authority dependency | Missing or invalid metadata and sections fail repository validation. | `audit:PowerSearch/knowledge` |+| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |+| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------- |+| FR1–FR3, FR7 | PowerSearch unit tests plus real-Chromium geometry assertions | 399/400, 720/721, wide outer surface, narrow viewport, LTR/RTL, collision | Removing either clamp, capping the main menu, or allowing viewport overflow fails. | `audit:PowerSearch/layout` |+| 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` |+| 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` |+| FR25 | PowerSearch date-zone tests under four host zones (UTC, Los Angeles, Tokyo, Honolulu) with `timezoneID` set to each zone and unset: token text, the removal announcement that carries the accessible label, the editor's opening day, the stored instant after a pick, a round trip that moves the day and back, a `components` Editor override and `PowerSearchFilterEditor` receiving the zone, range parts read and written, and an `isDateOnly: false` value kept on its released reading; plus the formatter's unit tests | a Los Angeles evening instant with `timezoneID` set and unset, a pick across the US daylight-time change, a `date_range` of two instants | The token and the editor show different days for one value, a re-picked day moves the instant, or a day shows a time | `audit:PowerSearch/interaction` |+| FR10–FR21, AR4–AR6, PR5 | Focused PowerSearch sheet tests with the compact-touch query stubbed both ways, plus real-engine touch evidence | default popover, forced sheet, adaptive both ways (server markup and hydration as the popover field on a coarse-pointer client, then the trigger, no recoverable error, focus on the body; with `hasAutoFocus`, the autofocused input's focus ending on the trigger with no `onBlur` or `onFocus` to the caller), trigger name, Filters/Add filter/value steps, each value type, list value through the Tokenizer sheet, Clear all, read-only, disabled while open, focus after each step, focus after an `adaptive` switch from the trigger, the input, a removed control, an open editor popover, and from outside the field, a field inside an open Dialog announcing the count, Clear all, and in-sheet messages inside that Dialog and never on the page body, StrictMode result count, in-sheet live region while a sheet is open (added, removed, count, empty results), Clear all announced only after the dialog's exit, row, token and Removed text sharing one formatter, a date-only value as its day in `timezoneID`, else the UTC day, and a date-and-time value in `timezoneID`, else the viewer's zone, on all three (UTC, Tokyo, Honolulu, unset), summaries and relative-date labels and values from the catalog, the row and Removed through one reorderable message, an unmatched relative-date value as stored, a filter the config no longer knows listed and removable, a cleared number unstaged, choice rows as radios and checkboxes with `aria-checked`, a stale read-only filter as a plain row, a removal next to a nested row focusing that row's remove action, a list value joined by the locale's narrow conjunction list in English, Simplified Chinese, Japanese, and German, an empty-result message spoken once per query from its rendered element, a controlled update that removes the edited field moving focus from the replaced body to Cancel and announcing the unavailable state in the sheet while the step is open and never from a step beneath another or retained closed, Apply and Cancel after a controlled update removed the edited filter focusing the nearest row, else Add filter, a row's trailing remove action focusing the next row's remove action, a one-tap `empty`-valued filter added from its field row and removed from its row, Clear all behind its confirmation keeping read-only filters and leaving Filters open, a dismissed step revealing the step beneath with focus restored to it, Add filter opening with its search unfocused and a touch drag on the rows blurring a focused search, a stale filter's step titled as its row reads (raw keys for what is gone, the field's label when the field remains), Cancel from creation after the opening field was removed focusing the Add filter sheet's first control, a removed focused Filters row, a removed Clear all, and a dropped focused field row each handing focus to the nearest remaining row or the sheet's first control, element counts at rest and with each of the Filters, Add filter and value sheets open, and with the Tokenizer's list-value sheet stacked above the value step, under fine and coarse pointers, nothing of the flow in the DOM at rest before a press and after the exit, a nested filter edited and created through the built-in nested editor (its sub-filter rows wrapping inside a 390 and a 414 px sheet; its root operator picker absent on a mixed field, the Operator group in its place), a nested-only field and its suggestion offered, a suggestion's operator checked over the field's default, the Operator group outside a caller's Editor override on a mixed field, a count changed during the exit spoken with Clear all's message as one catalog message after the close, a radio group's arrow keys, Home, and End moving and checking, Space and Enter checking a focused radio row and toggling a checkbox row, right-to-left layout with the row chevrons mirrored in RTL (`design:bidirectionality/DR4`) | A field without `experimental` changes beyond what FR19 states, a value commits before the step confirms, Clear all removes a read-only filter, the trigger carries native `disabled`, focus lands elsewhere, an announcement reaches a channel outside the modal that holds the field at that moment, or the popover bundle carries the sheets. | `audit:PowerSearch/sheet` |+| Record structure | `scripts/check-knowledge.mjs` | Component-contract schema and current-authority dependency | Missing or invalid metadata and sections fail repository validation. | `audit:PowerSearch/knowledge` |Current-source Chromium evidence establishes the geometry gap, not implementationcompletion:@@ -662,9 +660,8 @@ read and write a date-only `date_absolute` value, and each absolute part of aset, else the UTC day; a value whose operator sets `isDateOnly: false` is aninstant with a time of day, read and written in `timezoneID`, else the viewer'szone (FR11, FR12, FR17). The `popover` presentation reads a date-only value-the same way (FR25, DEC-5; FR25's gap note names what both still do); the-known gap below lists where its handling of an `isDateOnly: false` value-differs by contract.+the same way (FR25, DEC-5); the known gap below lists where its handling of an+`isDateOnly: false` value still differs.### DEC-4 — Clear all keeps read-only filtersdiff --git a/packages/core/api-report.md b/packages/core/api-report.mdindex bbbdb53f33..722ccccdc3 100644--- a/packages/core/api-report.md+++ b/packages/core/api-report.md@@ -1856,6 +1856,7 @@ component PowerSearchToken(props: PowerSearchTokenProps)prop onClick?: () => voidprop onRemove?: () => voidprop operator: PowerSearchOperator+ prop timezoneID?: stringcomponent ProgressBar(props: ProgressBarProps)prop data-testid?: stringprop formatValueLabel?: (value: number, max: number) => string = (value, max) => `${Math.round((value / max) * 100)}%`diff --git a/packages/core/src/PowerSearch/PowerSearch.doc.mjs b/packages/core/src/PowerSearch/PowerSearch.doc.mjsindex 2f31796810..3714e51ce8 100644--- a/packages/core/src/PowerSearch/PowerSearch.doc.mjs+++ b/packages/core/src/PowerSearch/PowerSearch.doc.mjs@@ -141,7 +141,8 @@ export const docs = {{name: 'timezoneID',type: 'string',- description: 'Timezone ID for date formatting (e.g. "America/New_York").',+ description:+ 'IANA zone a date-only date_absolute value, and each absolute part of a date_range, is read and written in: the day shows, edits and stores (as that midnight) in it; unset, a day is its UTC day. A date_absolute with isDateOnly: false formats its label in it. E.g. "America/New_York".',},{name: 'handleRef',@@ -448,7 +449,8 @@ export const docsZh = {{name: 'timezoneID',type: 'string',- description: '用于日期格式化的时区 ID(例如 "America/New_York")。',+ description:+ '仅日期的 date_absolute 值及 date_range 的每个绝对端点读写所用的 IANA 时区:该日在此时区显示、编辑并以其午夜存储;未设置时为 UTC 日。isDateOnly: false 的 date_absolute 值的标签也在此时区格式化。例如 "America/New_York"。',},{name: 'handleRef',@@ -569,7 +571,8 @@ export const docsDense = {'Max ranked results for a non-empty query; excludes value editors.',menuWidth: 'Main field/search menu width in pixels.',popoverSaveButtonLabel: 'Label for save button in edit popover.',- timezoneID: 'Timezone ID for date formatting (e.g. "America/New_York").',+ timezoneID:+ 'IANA zone a date-only value reads and writes in; unset, its UTC day.',handleRef:'Imperative handle w/ focusTypeahead() + blurTypeahead() methods.',endContent:diff --git a/packages/core/src/PowerSearch/PowerSearch.tsx b/packages/core/src/PowerSearch/PowerSearch.tsxindex b8e281cf75..db55054d30 100644--- a/packages/core/src/PowerSearch/PowerSearch.tsx+++ b/packages/core/src/PowerSearch/PowerSearch.tsx@@ -378,7 +378,13 @@ export interface PowerSearchProps extends Omit<maxSearchResults?: number;/** Label for the save button in edit popover. @default 'Apply' */popoverSaveButtonLabel?: string;- /** Timezone ID for date formatting. */+ /**+ * IANA zone a date-only `date_absolute` value, and each absolute part of a+ * `date_range`, is read and written in: the token, the label and the editor+ * show its day there, and a picked day stores as that midnight. Unset, a+ * day is its UTC day. A `date_absolute` with `isDateOnly: false` formats+ * its label in it.+ */timezoneID?: string;/*** Controls how tokens overflow when the container is too narrow.@@ -713,11 +719,14 @@ export function PowerSearch({10,),locale,+ undefined,+ undefined,+ timezoneID,): null;return {label, value, full: value != null ? `${label} ${value}` : label};},- [config, maxTokenLength, t, locale],+ [config, maxTokenLength, t, locale, timezoneID],);// The built-in token being edited. A token from a `components` override// names itself, so its editor keeps the plain popover.@@ -1090,6 +1099,7 @@ export function PowerSearch({onClick={handleClick}onRemove={handleRemove}isDisabled={isDisabled}+ timezoneID={timezoneID}/>);}@@ -1166,6 +1176,7 @@ export function PowerSearch({);},[+ timezoneID,filters,config,configProp,@@ -1260,6 +1271,7 @@ export function PowerSearch({onCancel={handlePopoverCancel}saveButtonLabel={popoverSaveButtonLabel}isReadOnly={isReadOnly}+ timezoneID={timezoneID}/>);}@@ -1275,9 +1287,11 @@ export function PowerSearch({saveButtonLabel={popoverSaveButtonLabel}maxMenuItems={maxOperatorMenuItems}isReadOnly={isReadOnly}+ timezoneID={timezoneID}/>);}, [+ timezoneID,popoverPartialFilter,popoverState,EditorOverride,@@ -1574,6 +1588,7 @@ export function PowerSearch({isDisabled={isDisabled}hasClear={hasClear}maxOperatorMenuItems={maxOperatorMenuItems}+ timezoneID={timezoneID}maxSearchResults={maxSearchResults}saveButtonLabel={popoverSaveButtonLabelFromProps}components={componentOverrides}diff --git a/packages/core/src/PowerSearch/PowerSearchBottomSheet.test.tsx b/packages/core/src/PowerSearch/PowerSearchBottomSheet.test.tsxindex cf7779b69d..d64bd8a46f 100644--- a/packages/core/src/PowerSearch/PowerSearchBottomSheet.test.tsx+++ b/packages/core/src/PowerSearch/PowerSearchBottomSheet.test.tsx@@ -3509,13 +3509,14 @@ describe('PowerSearch value step (FR14–FR16)', () => {tapRow('Status');// The same props, with the same meaning, as the popover passes: the// caller's config, the partial filter, the mode, the save label, the- // read-only flag, and the two callbacks; no sheet-only `timezoneID`.+ // read-only flag, the field's zone, and the two callbacks.expect(seenProps).toHaveBeenLastCalledWith({config,filter: {field: 'status', operator: 'is', value: undefined},mode: 'create',saveButtonLabel: 'Keep',isReadOnly: false,+ timezoneID: 'Asia/Tokyo',onSave: expect.any(Function),onCancel: expect.any(Function),});@@ -4333,6 +4334,64 @@ describe('PowerSearch sheet value types (FR17)', () => {expect(input).toHaveValue('March 10, 2024');});+ it.each([+ ['Asia/Tokyo', 'March 10, 2024', '2024-03-10T15:00:00Z'],+ ['Pacific/Honolulu', 'March 9, 2024', '2024-03-11T10:00:00Z'],+ [undefined, 'March 10, 2024', '2024-03-11T00:00:00Z'],+ ])(+ "date_absolute: the value step's date input opens on the day in timezoneID %s and stores a picked day as that zone's midnight",+ (timezoneID, opensOn, storedAfterPickingMarch11) => {+ const dateFilter: PowerSearchFilter = {+ field: 'created',+ operator: 'after',+ // 2024-03-10T03:00:00Z: March 10 in Tokyo, March 9 in Honolulu.+ value: {type: 'date_absolute', unixSeconds: 1710039600},+ };+ const {onChange} = setupValues({filters: [dateFilter], timezoneID});+ openEditFlow(/^Created is after/);+ const input = within(sheet()).getByRole('combobox', {name: 'Date'});+ expect(input).toHaveValue(opensOn);+ fireEvent.change(input, {target: {value: '03/11/2024'}});+ fireEvent.blur(input);+ apply();+ expect(onChange).toHaveBeenCalledWith(+ [+ {+ field: 'created',+ operator: 'after',+ value: {+ type: 'date_absolute',+ unixSeconds: Date.parse(storedAfterPickingMarch11) / 1000,+ },+ },+ ],+ 'edit',+ 0,+ );+ },+ );++ it("date_absolute: a components Editor override in the value step receives the field's timezoneID (FR14, FR25)", () => {+ const seen: (string | undefined)[] = [];+ function Editor(props: PowerSearchEditorProps) {+ seen.push(props.timezoneID);+ return <div>custom editor</div>;+ }+ const dateFilter: PowerSearchFilter = {+ field: 'created',+ operator: 'after',+ value: {type: 'date_absolute', unixSeconds: 1710039600},+ };+ setupValues({+ filters: [dateFilter],+ timezoneID: 'Asia/Tokyo',+ components: {date_absolute: {Editor}},+ });+ openEditFlow(/^Created is after/);+ expect(within(sheet()).getByText('custom editor')).toBeTruthy();+ expect(seen).toContain('Asia/Tokyo');+ });+it('date_relative: rows stage a single relative value', () => {const {onChange} = setupValues();openAddFlow();@@ -4538,18 +4597,17 @@ describe('PowerSearch sheet value text', () => {},);- it('reads a date into the editor as the popover presentation does (FR17)', () => {+ it('reads a date into the editor as the popover presentation does (FR17, FR25)', () => {setup({config: valueTypesConfig,filters: [dateFilter],timezoneID: 'Pacific/Honolulu',});openEditFlow(/^Created is after/);- // Both presentations' date editors read the instant's UTC day; the- // token and row may name a neighbouring day in an off-UTC zone (the- // record's known gap).+ // Both presentations' date editors read the instant's day in+ // `timezoneID`, the day the token and the row name.expect(within(sheet()).getByRole('combobox', {name: 'Date'})).toHaveValue(- 'March 10, 2024',+ 'March 9, 2024',);});diff --git a/packages/core/src/PowerSearch/PowerSearchBottomSheet.tsx b/packages/core/src/PowerSearch/PowerSearchBottomSheet.tsxindex c1b3dca268..285dc9b1db 100644--- a/packages/core/src/PowerSearch/PowerSearchBottomSheet.tsx+++ b/packages/core/src/PowerSearch/PowerSearchBottomSheet.tsx@@ -195,6 +195,8 @@ export interface PowerSearchBottomSheetProps {isDisabled: boolean;hasClear: boolean;maxOperatorMenuItems?: number;+ /** The zone a date-only value is read and written in; see PowerSearch. */+ timezoneID?: string;maxSearchResults: number;/** The caller's confirm label; the step picks a default per mode. */saveButtonLabel?: string;@@ -716,6 +718,7 @@ function SheetValueEditor({fieldLabel,isDisabled,maxMenuItems,+ timezoneID,editors,}: {operatorValue: OperatorValue;@@ -726,6 +729,7 @@ function SheetValueEditor({fieldLabel: string;isDisabled: boolean;maxMenuItems?: number;+ timezoneID?: string;editors: PowerSearchSheetEditors;}) {const {buildRelativeDateOptions, PowerSearchValueEditor} = editors;@@ -807,6 +811,7 @@ function SheetValueEditor({isDisabled={isDisabled}presentation="bottom-sheet"fieldLabel={fieldLabel}+ timezoneID={timezoneID}/></div>);@@ -837,6 +842,7 @@ export function PowerSearchBottomSheet({isDisabled,hasClear,maxOperatorMenuItems,+ timezoneID,maxSearchResults,saveButtonLabel: saveButtonLabelFromProps,components: componentOverrides,@@ -1350,10 +1356,11 @@ export function PowerSearchBottomSheet({locale,t,formatList,+ timezoneID,);return {label, value};},- [config, editors, formatList, locale, t],+ [config, editors, formatList, locale, t, timezoneID],);const describeFilter = useCallback((filter: PowerSearchFilter): string => {@@ -2004,6 +2011,7 @@ export function PowerSearchBottomSheet({onOperatorChange={() => {}}onPartialFilterChange={handleNestedDraftChange}maxMenuItems={maxOperatorMenuItems}+ timezoneID={timezoneID}isReadOnly={isEditorDisabled}xstyle={styles.nestedEditorContainer}/>@@ -2018,6 +2026,7 @@ export function PowerSearchBottomSheet({fieldLabel={draftField.label}isDisabled={isEditorDisabled}maxMenuItems={maxOperatorMenuItems}+ timezoneID={timezoneID}editors={editors}/>));@@ -2421,6 +2430,7 @@ export function PowerSearchBottomSheet({onCancel={returnFromValue}saveButtonLabel={saveButtonLabel}isReadOnly={isEditorDisabled}+ timezoneID={timezoneID}/></div>) : (diff --git a/packages/core/src/PowerSearch/PowerSearchDateZone.test.tsx b/packages/core/src/PowerSearch/PowerSearchDateZone.test.tsxnew file mode 100644index 0000000000..acc1cde534--- /dev/null+++ b/packages/core/src/PowerSearch/PowerSearchDateZone.test.tsx@@ -0,0 +1,585 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file PowerSearchDateZone.test.tsx+ * @input The real PowerSearch with `date_absolute` and `date_range` filters,+ * rendered under several host zones and `timezoneID` values+ * @output Assertions that the token text, the accessible label and the+ * popover editor read one value as one day, and that an edit writes the day+ * the person picked in that zone+ * @position Regression coverage for the PowerSearch date zone contract+ */++import {afterAll, afterEach, beforeAll, describe, expect, it, vi} from 'vitest';+import {act, fireEvent, render, screen, waitFor} from '@testing-library/react';+import React, {useState} from 'react';+import {PowerSearch} from './PowerSearch';+import {PowerSearchFilterEditor} from './PowerSearchFilterEditor';+import {PowerSearchToken} from './PowerSearchToken';+import type {+ PowerSearchConfig,+ PowerSearchEditorProps,+ PowerSearchFilter,+ PowerSearchTokenProps,+} from './types';++const originalMatches = HTMLElement.prototype.matches;+const popoverOpenState = new WeakMap<HTMLElement, boolean>();++beforeAll(() => {+ HTMLElement.prototype.showPopover = vi.fn(function (this: HTMLElement) {+ popoverOpenState.set(this, true);+ });+ HTMLElement.prototype.hidePopover = vi.fn(function (this: HTMLElement) {+ popoverOpenState.set(this, false);+ });+ HTMLElement.prototype.matches = function (+ this: HTMLElement,+ selector: string,+ ) {+ if (selector === ':popover-open') {+ return popoverOpenState.get(this) ?? false;+ }+ return originalMatches.call(this, selector);+ } as typeof HTMLElement.prototype.matches;+ // A real frame, not a synchronous call: the announcer records the frame+ // id after scheduling, so a callback that runs inside the call would leave+ // a stale pending frame behind.+ let frameId = 0;+ vi.stubGlobal('requestAnimationFrame', (cb: FrameRequestCallback) => {+ setTimeout(() => cb(performance.now()), 0);+ return ++frameId;+ });+ vi.stubGlobal('cancelAnimationFrame', () => {});+});++afterAll(() => {+ HTMLElement.prototype.matches = originalMatches;+ vi.unstubAllGlobals();+});++const originalTZ = process.env.TZ;+afterEach(() => {+ if (originalTZ === undefined) {+ delete process.env.TZ;+ } else {+ process.env.TZ = originalTZ;+ }+});++const config: PowerSearchConfig = {+ name: 'dates',+ fields: [+ {+ key: 'due',+ label: 'Due',+ operators: [+ {+ key: 'on',+ label: 'on',+ value: {type: 'date_absolute', isDateOnly: true},+ },+ ],+ },+ {+ key: 'day',+ label: 'Day',+ operators: [{key: 'on', label: 'on', value: {type: 'date_absolute'}}],+ },+ {+ key: 'at',+ label: 'At',+ operators: [+ {+ key: 'on',+ label: 'on',+ value: {type: 'date_absolute', isDateOnly: false},+ },+ ],+ },+ {+ key: 'win',+ label: 'Win',+ operators: [{key: 'in', label: 'in', value: {type: 'date_range'}}],+ },+ ],+};++const HOST_ZONES = [+ 'UTC',+ 'America/Los_Angeles',+ 'Asia/Tokyo',+ 'Pacific/Honolulu',+] as const;++function tokenFor(label: string): HTMLElement {+ const button = screen+ .getAllByRole('button')+ .find(+ b =>+ (b.textContent ?? '').startsWith(`${label}:`) &&+ !/remove/i.test(b.getAttribute('aria-label') ?? ''),+ );+ if (!button) {+ throw new Error(`token for ${label} not found`);+ }+ return button;+}++function tokenText(label: string): string {+ return (tokenFor(label).parentElement?.textContent ?? '')+ .replace(/\s+/g, ' ')+ .trim();+}++function openEditor(label: string): HTMLInputElement {+ act(() => {+ fireEvent.click(tokenFor(label));+ });+ const input = document.querySelector<HTMLInputElement>('[popover] input');+ if (!input) {+ throw new Error('editor input not found');+ }+ return input;+}++function apply(): void {+ const button = Array.from(+ document.querySelectorAll<HTMLButtonElement>('[popover] button'),+ ).find(b => b.textContent === 'Apply');+ if (!button) {+ throw new Error('Apply not found');+ }+ act(() => {+ fireEvent.click(button);+ });+}++function renderOne(+ filter: PowerSearchFilter,+ timezoneID: string | undefined,+ onChange = vi.fn(),+) {+ render(+ <PowerSearch+ config={config}+ filters={[filter]}+ onChange={onChange}+ label="Search"+ timezoneID={timezoneID}+ />,+ );+ return onChange;+}++// 2024-03-09 19:00 in Los Angeles, 2024-03-10 03:00Z, 2024-03-10 12:00 in Tokyo.+const EVENING_LA = Date.parse('2024-03-10T03:00:00Z') / 1000;+const UTC_MIDNIGHT = Date.parse('2024-03-09T00:00:00Z') / 1000;+const LA_MIDNIGHT = Date.parse('2024-03-09T08:00:00Z') / 1000;++describe('PowerSearch date zone', () => {+ describe('a date-only value with timezoneID is one day in that zone everywhere', () => {+ it.each(HOST_ZONES)('under host zone %s', hostZone => {+ process.env.TZ = hostZone;+ renderOne(+ {+ field: 'due',+ operator: 'on',+ value: {type: 'date_absolute', unixSeconds: EVENING_LA},+ },+ 'America/Los_Angeles',+ );+ expect(tokenText('Due')).toBe('Due: onMar 9, 2024');+ expect(openEditor('Due').value).toBe('March 9, 2024');+ });++ it.each(HOST_ZONES)(+ 'under host zone %s, the accessible label names the same day with no time',+ async hostZone => {+ process.env.TZ = hostZone;+ const onChange = renderOne(+ {+ field: 'due',+ operator: 'on',+ value: {type: 'date_absolute', unixSeconds: EVENING_LA},+ },+ 'America/Los_Angeles',+ );+ const remove = screen.getByRole('button', {name: /^Remove /});+ act(() => {+ fireEvent.click(remove);+ });+ expect(onChange).toHaveBeenCalledWith([], 'remove', 0);+ await waitFor(() => {+ const announced = Array.from(document.querySelectorAll('[aria-live]'))+ .map(region => region.textContent ?? '')+ .join(' ');+ expect(announced).toContain('Removed Due: on Mar 9, 2024');+ expect(announced).not.toMatch(/\d:\d\d/);+ });+ },+ );++ it.each(HOST_ZONES)('under host zone %s, in Tokyo', hostZone => {+ process.env.TZ = hostZone;+ renderOne(+ {+ field: 'due',+ operator: 'on',+ value: {type: 'date_absolute', unixSeconds: EVENING_LA},+ },+ 'Asia/Tokyo',+ );+ expect(tokenText('Due')).toBe('Due: onMar 10, 2024');+ expect(openEditor('Due').value).toBe('March 10, 2024');+ });+ });++ describe('a date-only value with no timezoneID is its UTC day everywhere', () => {+ it.each(HOST_ZONES)('under host zone %s', hostZone => {+ process.env.TZ = hostZone;+ renderOne(+ {+ field: 'day',+ operator: 'on',+ value: {type: 'date_absolute', unixSeconds: UTC_MIDNIGHT},+ },+ undefined,+ );+ expect(tokenText('Day')).toBe('Day: onMar 9, 2024');+ expect(openEditor('Day').value).toBe('March 9, 2024');+ });+ });++ describe("saving a date-only value stores that zone's midnight", () => {+ // March 11 2024 is the first Monday of US daylight time, so the Los+ // Angeles midnight is UTC-7 where March 9 was UTC-8.+ it.each([+ ['America/Los_Angeles', Date.parse('2024-03-11T07:00:00Z') / 1000],+ ['Asia/Tokyo', Date.parse('2024-03-10T15:00:00Z') / 1000],+ ['Pacific/Honolulu', Date.parse('2024-03-11T10:00:00Z') / 1000],+ ['UTC', Date.parse('2024-03-11T00:00:00Z') / 1000],+ [undefined, Date.parse('2024-03-11T00:00:00Z') / 1000],+ ] as const)('timezoneID %s', (timezoneID, expected) => {+ process.env.TZ = 'Asia/Tokyo';+ const onChange = renderOne(+ {+ field: 'due',+ operator: 'on',+ value: {type: 'date_absolute', unixSeconds: EVENING_LA},+ },+ timezoneID,+ );+ const input = openEditor('Due');+ fireEvent.change(input, {target: {value: '03/11/2024'}});+ fireEvent.blur(input);+ apply();+ expect(onChange).toHaveBeenLastCalledWith(+ [+ {+ field: 'due',+ operator: 'on',+ value: {type: 'date_absolute', unixSeconds: expected},+ },+ ],+ 'edit',+ 0,+ );+ });+ });++ it('a date-only round trip through the editor keeps its day in a western zone', () => {+ process.env.TZ = 'America/Los_Angeles';+ const onChange = vi.fn();+ function Harness() {+ const [filters, setFilters] = useState<PowerSearchFilter[]>([+ {+ field: 'due',+ operator: 'on',+ value: {type: 'date_absolute', unixSeconds: LA_MIDNIGHT},+ },+ ]);+ return (+ <PowerSearch+ config={config}+ filters={filters}+ onChange={next => {+ onChange(next);+ setFilters([...next]);+ }}+ label="Search"+ timezoneID="America/Los_Angeles"+ />+ );+ }+ render(<Harness />);+ expect(tokenText('Due')).toBe('Due: onMar 9, 2024');+ // Move the day, then pick the first day again: the token shows each day+ // picked, and the instant comes back to where it started.+ let input = openEditor('Due');+ expect(input.value).toBe('March 9, 2024');+ fireEvent.change(input, {target: {value: '03/12/2024'}});+ fireEvent.blur(input);+ apply();+ expect(tokenText('Due')).toBe('Due: onMar 12, 2024');+ input = openEditor('Due');+ expect(input.value).toBe('March 12, 2024');+ fireEvent.change(input, {target: {value: '03/09/2024'}});+ fireEvent.blur(input);+ apply();+ expect(onChange).toHaveBeenLastCalledWith([+ {+ field: 'due',+ operator: 'on',+ value: {type: 'date_absolute', unixSeconds: LA_MIDNIGHT},+ },+ ]);+ expect(tokenText('Due')).toBe('Due: onMar 9, 2024');+ });++ describe("a caller's editor receives the zone", () => {+ it('passes timezoneID to a components Editor override', () => {+ process.env.TZ = 'UTC';+ const seen: (string | undefined)[] = [];+ function Editor(props: PowerSearchEditorProps) {+ seen.push(props.timezoneID);+ return <div>custom editor</div>;+ }+ render(+ <PowerSearch+ config={config}+ filters={[+ {+ field: 'due',+ operator: 'on',+ value: {type: 'date_absolute', unixSeconds: EVENING_LA},+ },+ ]}+ onChange={vi.fn()}+ label="Search"+ timezoneID="America/Los_Angeles"+ components={{date_absolute: {Editor}}}+ />,+ );+ act(() => {+ fireEvent.click(tokenFor('Due'));+ });+ expect(seen).toContain('America/Los_Angeles');+ });++ it('passes timezoneID to a components Token override, and the exported PowerSearchToken reads the zone day', () => {+ process.env.TZ = 'Asia/Tokyo';+ const seen: (string | undefined)[] = [];+ function Token(props: PowerSearchTokenProps) {+ seen.push(props.timezoneID);+ return <PowerSearchToken {...props} />;+ }+ render(+ <PowerSearch+ config={config}+ filters={[+ {+ field: 'due',+ operator: 'on',+ value: {type: 'date_absolute', unixSeconds: EVENING_LA},+ },+ ]}+ onChange={vi.fn()}+ label="Search"+ timezoneID="America/Los_Angeles"+ components={{date_absolute: {Token}}}+ />,+ );+ expect(seen).toContain('America/Los_Angeles');+ // EVENING_LA is March 10 in Tokyo and UTC; PowerSearchToken shows the+ // Los Angeles day with no time, as the built-in token does.+ expect(screen.getByText('Mar 9, 2024')).toBeTruthy();+ });++ it("PowerSearchToken keeps an isDateOnly: false value in the viewer's zone with its time", () => {+ process.env.TZ = 'America/Los_Angeles';+ function Token(props: PowerSearchTokenProps) {+ return <PowerSearchToken {...props} />;+ }+ render(+ <PowerSearch+ config={config}+ filters={[+ {+ field: 'at',+ operator: 'on',+ value: {type: 'date_absolute', unixSeconds: EVENING_LA},+ },+ ]}+ onChange={vi.fn()}+ label="Search"+ timezoneID="Asia/Tokyo"+ components={{date_absolute: {Token}}}+ />,+ );+ // 7:00 PM March 9 in Los Angeles, as it read before timezoneID reached+ // the token; the Tokyo reading would be March 10, 12:00 PM.+ expect(screen.getByText('Mar 9, 2024, 7:00 PM')).toBeTruthy();+ });++ it('PowerSearchFilterEditor opens its date editor on the day in timezoneID', () => {+ process.env.TZ = 'UTC';+ render(+ <PowerSearchFilterEditor+ config={config}+ filter={{+ field: 'due',+ operator: 'on',+ value: {type: 'date_absolute', unixSeconds: EVENING_LA},+ }}+ mode="edit"+ onSave={vi.fn()}+ onCancel={vi.fn()}+ timezoneID="America/Los_Angeles"+ />,+ );+ const input = document.querySelector<HTMLInputElement>('input');+ expect(input?.value).toBe('March 9, 2024');+ });+ });++ it('leaves a value with a time of day (isDateOnly: false) on its released reading', async () => {+ // Not a calendar day, so outside the zone rule: the token keeps the+ // device's day, the label its date and time in timezoneID, and the editor+ // the UTC day — as before, until that value has its own rule.+ process.env.TZ = 'America/Los_Angeles';+ const onChange = renderOne(+ {+ field: 'at',+ operator: 'on',+ value: {type: 'date_absolute', unixSeconds: EVENING_LA},+ },+ 'Asia/Tokyo',+ );+ expect(tokenText('At')).toBe('At: onMar 9, 2024');+ const remove = screen.getByRole('button', {name: /^Remove /});+ act(() => {+ fireEvent.click(remove);+ });+ expect(onChange).toHaveBeenCalledWith([], 'remove', 0);+ await waitFor(() => {+ const announced = Array.from(document.querySelectorAll('[aria-live]'))+ .map(region => region.textContent ?? '')+ .join(' ');+ expect(announced).toContain('Removed At: on Mar 10, 2024, 12:00 PM');+ });+ });++ it('opens a value with a time of day (isDateOnly: false) on the UTC day, as before', () => {+ process.env.TZ = 'America/Los_Angeles';+ renderOne(+ {+ field: 'at',+ operator: 'on',+ value: {type: 'date_absolute', unixSeconds: EVENING_LA},+ },+ 'America/Los_Angeles',+ );+ expect(openEditor('At').value).toBe('March 10, 2024');+ });++ describe('range parts are calendar days in the same zone', () => {+ it('reads and writes them in timezoneID', () => {+ process.env.TZ = 'UTC';+ const onChange = renderOne(+ {+ field: 'win',+ operator: 'in',+ value: {+ type: 'date_range',+ value: {+ start: {type: 'ABSOLUTE', unixSeconds: EVENING_LA},+ end: {type: 'ABSOLUTE', unixSeconds: EVENING_LA + 86400},+ },+ },+ },+ 'America/Los_Angeles',+ );+ act(() => {+ fireEvent.click(tokenFor('Win'));+ });+ const rangeText = Array.from(+ document.querySelectorAll<HTMLElement>('[popover] button'),+ )+ .map(b => b.textContent ?? '')+ .find(text => /Mar \d+, 2024/.test(text));+ expect(rangeText).toBe('Mar 9, 2024 – Mar 10, 2024');+ // Picking March 11–12 in the calendar stores each day's Los Angeles+ // midnight (daylight time from March 10, so UTC-7).+ const openCalendar = Array.from(+ document.querySelectorAll<HTMLButtonElement>('[popover] button'),+ ).find(b => b.getAttribute('aria-label') === 'Open calendar');+ if (!openCalendar) {+ throw new Error('Open calendar not found');+ }+ fireEvent.click(openCalendar);+ const day = (iso: string) => {+ const button = document.querySelector<HTMLButtonElement>(+ `button[data-date="${iso}"]`,+ );+ if (!button) {+ throw new Error(`day ${iso} not found`);+ }+ return button;+ };+ fireEvent.click(day('2024-03-11'));+ fireEvent.click(day('2024-03-12'));+ apply();+ expect(onChange).toHaveBeenLastCalledWith(+ [+ {+ field: 'win',+ operator: 'in',+ value: {+ type: 'date_range',+ value: {+ start: {+ type: 'ABSOLUTE',+ unixSeconds: Date.parse('2024-03-11T07:00:00Z') / 1000,+ },+ end: {+ type: 'ABSOLUTE',+ unixSeconds: Date.parse('2024-03-12T07:00:00Z') / 1000,+ },+ },+ },+ },+ ],+ 'edit',+ 0,+ );+ });++ it('reads them as UTC days with no timezoneID', () => {+ process.env.TZ = 'America/Los_Angeles';+ renderOne(+ {+ field: 'win',+ operator: 'in',+ value: {+ type: 'date_range',+ value: {+ start: {type: 'ABSOLUTE', unixSeconds: UTC_MIDNIGHT},+ end: {type: 'ABSOLUTE', unixSeconds: UTC_MIDNIGHT + 86400},+ },+ },+ },+ undefined,+ );+ act(() => {+ fireEvent.click(tokenFor('Win'));+ });+ const rangeText = Array.from(+ document.querySelectorAll<HTMLElement>('[popover] button'),+ )+ .map(b => b.textContent ?? '')+ .find(text => /Mar \d+, 2024/.test(text));+ expect(rangeText).toBe('Mar 9, 2024 – Mar 10, 2024');+ });+ });+});diff --git a/packages/core/src/PowerSearch/PowerSearchEditPopover.tsx b/packages/core/src/PowerSearch/PowerSearchEditPopover.tsxindex bcf7cd54d9..50121c65a8 100644--- a/packages/core/src/PowerSearch/PowerSearchEditPopover.tsx+++ b/packages/core/src/PowerSearch/PowerSearchEditPopover.tsx@@ -118,6 +118,7 @@ export interface PowerSearchEditPopoverProps {saveButtonLabel?: string;/** Max suggestions in string and entity value typeaheads. */maxMenuItems?: number;+ timezoneID?: string;/** Whether the filter is read-only. */isReadOnly?: boolean;}@@ -261,6 +262,7 @@ interface NestedSubFilterRowProps {subFilter: EditablePartialFilter;onChange: (subFilter: EditablePartialFilter) => void;maxMenuItems?: number;+ timezoneID?: string;isReadOnly: boolean;}@@ -269,6 +271,7 @@ function NestedSubFilterRow({subFilter,onChange,maxMenuItems,+ timezoneID,isReadOnly,}: NestedSubFilterRowProps) {const t = useComponentTranslator();@@ -373,6 +376,7 @@ function NestedSubFilterRow({onChange={handleValueChange}config={config}maxMenuItems={maxMenuItems}+ timezoneID={timezoneID}isDisabled={isReadOnly}/></div>@@ -392,6 +396,7 @@ export interface NestedEditorProps {onOperatorChange: (operatorKey: string) => void;onPartialFilterChange: (filter: PartialFilter) => void;maxMenuItems?: number;+ timezoneID?: string;isReadOnly: boolean;/** Styles for the editor's tree root (the sheet makes it a query container). */xstyle?: stylex.StyleXStyles;@@ -418,6 +423,7 @@ export function NestedEditor({onOperatorChange,onPartialFilterChange,maxMenuItems,+ timezoneID,isReadOnly,xstyle,hasRootOperatorPicker = true,@@ -542,6 +548,7 @@ export function NestedEditor({subFilter={sf}onChange={updated => handleUpdate(itemPath, updated)}maxMenuItems={maxMenuItems}+ timezoneID={timezoneID}isReadOnly={isReadOnly}/>),@@ -569,6 +576,7 @@ export function NestedEditor({subFilter={sf}onChange={updated => handleUpdate(itemPath, updated)}maxMenuItems={maxMenuItems}+ timezoneID={timezoneID}isReadOnly={isReadOnly}/>),@@ -687,6 +695,7 @@ export function PowerSearchEditPopover({onCancel,saveButtonLabel: saveButtonLabelFromProps,maxMenuItems,+ timezoneID,isReadOnly = false,}: PowerSearchEditPopoverProps) {const t = useComponentTranslator();@@ -870,6 +879,7 @@ export function PowerSearchEditPopover({onOperatorChange={handleOperatorChange}onPartialFilterChange={setPartialFilter}maxMenuItems={maxMenuItems}+ timezoneID={timezoneID}isReadOnly={isReadOnly}/></VStack>@@ -944,6 +954,7 @@ export function PowerSearchEditPopover({onEnter={handleSave}config={config}maxMenuItems={maxMenuItems}+ timezoneID={timezoneID}isDisabled={isReadOnly}/>)}diff --git a/packages/core/src/PowerSearch/PowerSearchFilterEditor.tsx b/packages/core/src/PowerSearch/PowerSearchFilterEditor.tsxindex 81572617da..daeb1d4bea 100644--- a/packages/core/src/PowerSearch/PowerSearchFilterEditor.tsx+++ b/packages/core/src/PowerSearch/PowerSearchFilterEditor.tsx@@ -30,6 +30,7 @@ export function PowerSearchFilterEditor({onCancel,saveButtonLabel,isReadOnly,+ timezoneID,}: PowerSearchEditorProps) {const config = useInternalConfig(configProp);@@ -43,6 +44,7 @@ export function PowerSearchFilterEditor({onCancel={onCancel}saveButtonLabel={saveButtonLabel}isReadOnly={isReadOnly}+ timezoneID={timezoneID}/>);}diff --git a/packages/core/src/PowerSearch/PowerSearchToken.tsx b/packages/core/src/PowerSearch/PowerSearchToken.tsxindex 9d21dfd06d..d7b798389d 100644--- a/packages/core/src/PowerSearch/PowerSearchToken.tsx+++ b/packages/core/src/PowerSearch/PowerSearchToken.tsx@@ -42,6 +42,7 @@ export function PowerSearchToken({onClick,onRemove,isDisabled,+ timezoneID,}: PowerSearchTokenProps) {const config = useInternalConfig(configProp);const t = useComponentTranslator();@@ -59,6 +60,11 @@ export function PowerSearchToken({10,);+ // A value with a time of day keeps its reading in the viewer's zone; only+ // a calendar day reads in `timezoneID`.+ const isDateTime =+ operator.value.type === 'date_absolute' &&+ operator.value.isDateOnly === false;const valueStr = formatFilterValue(config,operator.value,@@ -66,6 +72,7 @@ export function PowerSearchToken({adjustedMaxLength,t,locale,+ isDateTime ? undefined : timezoneID,);const valueContent = valueStr ? (diff --git a/packages/core/src/PowerSearch/PowerSearchValueEditor.tsx b/packages/core/src/PowerSearch/PowerSearchValueEditor.tsxindex 4c54976981..2759e54485 100644--- a/packages/core/src/PowerSearch/PowerSearchValueEditor.tsx+++ b/packages/core/src/PowerSearch/PowerSearchValueEditor.tsx@@ -42,6 +42,11 @@ import {type NumberInputCommitDecision,} from '../NumberInput/numberInputCommit';import {DateInput} from '../DateInput';+import {+ isoDateToUnixSeconds,+ resolveDateZone,+ unixSecondsToISODate,+} from './powerSearchDateZone';import {DateRangeInput, type DateRange} from '../DateRangeInput';import {resolveDateTimeRangePart} from './resolveDateTimeRangePart';import {TimeInput} from '../TimeInput';@@ -122,10 +127,9 @@ function enumItemsToSearchableItems(function dateRangePartToISO(part: DateTimeRangePart,nowSeconds: number,+ zone: string | undefined,): ISODateString {- return new Date(resolveDateTimeRangePart(part, nowSeconds) * 1000)- .toISOString()- .split('T')[0] as ISODateString;+ return unixSecondsToISODate(resolveDateTimeRangePart(part, nowSeconds), zone);}// =============================================================================@@ -501,37 +505,46 @@ function TimeEditor({}function DateAbsoluteEditor({+ operatorValue,filterValue,onChange,isDisabled,presentation,+ timezoneID,}: {operatorValue: OperatorValue & {type: 'date_absolute'};filterValue: FilterValue | undefined;onChange: (value: FilterValue) => void;isDisabled?: boolean;presentation: EditorPresentation;+ timezoneID?: string;}) {const t = useComponentTranslator();- // Convert unixSeconds to ISO date string for the date input- const currentValue = useMemo(() => {- if (filterValue?.type !== 'date_absolute') {- return undefined;- }- const date = new Date(filterValue.unixSeconds * 1000);- return date.toISOString().split('T')[0] as ISODateString;- }, [filterValue]);+ // A date-only value edits in the zone the token and the label use. An+ // `isDateOnly: false` value edits its UTC day.+ const zone =+ operatorValue.isDateOnly === false+ ? 'UTC'+ : resolveDateZone(timezoneID, true);+ const unixSeconds =+ filterValue?.type === 'date_absolute' ? filterValue.unixSeconds : undefined;return (<DateInputlabel={t('@astryx.powersearch.valueEditor.date')}isLabelHiddenisDisabled={isDisabled}- value={currentValue}+ value={+ unixSeconds == null+ ? undefined+ : unixSecondsToISODate(unixSeconds, zone)+ }onChange={value => {if (value != null) {- const unixSeconds = Math.floor(new Date(value).getTime() / 1000);- onChange({type: 'date_absolute', unixSeconds});+ onChange({+ type: 'date_absolute',+ unixSeconds: isoDateToUnixSeconds(value, zone),+ });}}}width={presentation === 'bottom-sheet' ? '100%' : undefined}@@ -644,14 +657,18 @@ function DateRangeEditor({onChange,isDisabled,presentation,+ timezoneID,}: {operatorValue: OperatorValue & {type: 'date_range'};filterValue: FilterValue | undefined;onChange: (value: FilterValue) => void;isDisabled?: boolean;presentation: EditorPresentation;+ timezoneID?: string;}) {const t = useComponentTranslator();+ // A range part is a calendar day, read and written as a date-only value is.+ const zone = resolveDateZone(timezoneID, true);const currentValue = useMemo<DateRange | null>(() => {if (filterValue?.type !== 'date_range') {return null;@@ -659,10 +676,10 @@ function DateRangeEditor({const {start, end} = filterValue.value;const nowSeconds = Date.now() / 1000;return {- start: dateRangePartToISO(start, nowSeconds),- end: dateRangePartToISO(end, nowSeconds),+ start: dateRangePartToISO(start, nowSeconds, zone),+ end: dateRangePartToISO(end, nowSeconds, zone),};- }, [filterValue]);+ }, [filterValue, zone]);const handleChange = useCallback((range: DateRange | null) => {@@ -674,16 +691,16 @@ function DateRangeEditor({value: {start: {type: 'ABSOLUTE',- unixSeconds: Date.parse(`${range.start}T00:00:00Z`) / 1000,+ unixSeconds: isoDateToUnixSeconds(range.start, zone),},end: {type: 'ABSOLUTE',- unixSeconds: Date.parse(`${range.end}T00:00:00Z`) / 1000,+ unixSeconds: isoDateToUnixSeconds(range.end, zone),},},});},- [onChange],+ [onChange, zone],);const handleKeyDown = useCallback((event: KeyboardEvent<HTMLDivElement>) => {@@ -924,6 +941,7 @@ export function PowerSearchValueEditor({onUnstage,presentation = 'popover',fieldLabel,+ timezoneID,}: PowerSearchValueEditorProps) {switch (operatorValue.type) {case 'empty':@@ -1000,6 +1018,7 @@ export function PowerSearchValueEditor({operatorValue={operatorValue}filterValue={filterValue}onChange={onChange}+ timezoneID={timezoneID}/>);@@ -1021,6 +1040,7 @@ export function PowerSearchValueEditor({operatorValue={operatorValue}filterValue={filterValue}onChange={onChange}+ timezoneID={timezoneID}/>);diff --git a/packages/core/src/PowerSearch/formatFilterValue.test.ts b/packages/core/src/PowerSearch/formatFilterValue.test.tsindex 70330ba4f3..1ae214a088 100644--- a/packages/core/src/PowerSearch/formatFilterValue.test.ts+++ b/packages/core/src/PowerSearch/formatFilterValue.test.ts@@ -274,10 +274,30 @@ describe('formatFilterValue', () => {),).toBe('date range');});+ it('reads a date-only value as its day in the zone, with no time, and a time-of-day value with its time', () => {+ // 2024-03-10T03:00:00Z: March 10 in Tokyo, March 9 in Los Angeles.+ const unixSeconds = Date.parse('2024-03-10T03:00:00Z') / 1000;+ expect(formatDateAbsolute(unixSeconds, 'en-US', 'Asia/Tokyo')).toBe(+ 'Mar 10, 2024',+ );+ expect(+ formatDateAbsolute(unixSeconds, 'en-US', 'America/Los_Angeles'),+ ).toBe('Mar 9, 2024');+ expect(formatDateAbsolute(unixSeconds, 'en-US', undefined)).toBe(+ 'Mar 10, 2024',+ );+ expect(+ formatDateAbsolute(unixSeconds, 'en-US', 'America/Los_Angeles', false),+ ).toBe('Mar 9, 2024, 7:00 PM');+ });+it('keeps Gregorian years for locales that default to another calendar', () => {const unixSeconds = Date.parse('2026-08-22T12:00:00Z') / 1000;for (const value of [formatDateAbsolute(unixSeconds, 'th-TH', 'UTC'),+ formatDateAbsolute(unixSeconds, 'th-TH', undefined),+ formatDateAbsolute(unixSeconds, 'th-TH', 'UTC', false),+ formatDateAbsolute(unixSeconds, 'th-TH', undefined, false),formatDateAbsoluteCompact(unixSeconds, 'th-TH'),]) {expect(value).toContain('2026');diff --git a/packages/core/src/PowerSearch/formatFilterValue.ts b/packages/core/src/PowerSearch/formatFilterValue.tsindex 9d9d2b07b2..88000e79d3 100644--- a/packages/core/src/PowerSearch/formatFilterValue.ts+++ b/packages/core/src/PowerSearch/formatFilterValue.ts@@ -16,6 +16,7 @@ import type {Locale, TranslatorFn} from '../i18n';import {truncateCharacters} from '../utils/characters';import {registerEnglishFallback} from '../i18n/englishFallback';import english from '../i18n/generated-english/PowerSearch/formatFilterValue.generated';+import {resolveDateZone} from './powerSearchDateZone';registerEnglishFallback(english);@@ -53,29 +54,43 @@ export function formatSharedNumber(return new Intl.NumberFormat(locale, options).format(value);}+/**+ * The one reading of a calendar-day `date_absolute` value: its day in the+ * zone `resolveDateZone` names. The token text and the accessible label share+ * it; the editors read the same zone through `resolveDateZone`, so a value+ * never reads as two days in one field. A value whose operator sets+ * `isDateOnly: false` is not a calendar day: it keeps its date and time in+ * `timezoneID`, else the viewer's zone.+ */export function formatDateAbsolute(unixSeconds: number,locale: Locale,- timezoneID?: string,+ timezoneID: string | undefined,+ isDateOnly = true,): string {- const options: Intl.DateTimeFormatOptions = {- year: 'numeric',- month: 'short',- day: 'numeric',- hour: 'numeric',- minute: '2-digit',- ...(timezoneID ? {timeZone: timezoneID} : {}),- calendar: 'gregory',- };+ const options: Intl.DateTimeFormatOptions = isDateOnly+ ? {+ year: 'numeric',+ month: 'short',+ day: 'numeric',+ timeZone: resolveDateZone(timezoneID, true),+ calendar: 'gregory',+ }+ : {+ year: 'numeric',+ month: 'short',+ day: 'numeric',+ hour: 'numeric',+ minute: '2-digit',+ timeZone: resolveDateZone(timezoneID, false),+ calendar: 'gregory',+ };return new Intl.DateTimeFormat(locale, options).format(unixSeconds * 1000);}/**- * Compact date-only rendering (no time-of-day) for the token pill's inline- * value display, which has less room than the editor's full summary. Kept- * separate from {@link formatDateAbsolute} rather than reusing it with- * different options threaded through a param, since the two callers want- * genuinely different shapes, not a parameterization of the same one.+ * The released token text for a value with a time of day: its day in the+ * viewer's zone, as the token has always shown it.*/export function formatDateAbsoluteCompact(unixSeconds: number,@@ -205,7 +220,13 @@ export function formatFilterValue(case 'date_absolute':return truncate(- formatDateAbsolute(filterValue.unixSeconds, locale, timezoneID),+ formatDateAbsolute(+ filterValue.unixSeconds,+ locale,+ timezoneID,+ operatorValue.type !== 'date_absolute' ||+ operatorValue.isDateOnly !== false,+ ),maxLength,);diff --git a/packages/core/src/PowerSearch/formatTokenValue.ts b/packages/core/src/PowerSearch/formatTokenValue.tsindex 6a4846e2bf..499c05b294 100644--- a/packages/core/src/PowerSearch/formatTokenValue.ts+++ b/packages/core/src/PowerSearch/formatTokenValue.ts@@ -15,6 +15,7 @@ import type {OperatorValue, FilterValue, EnumItem} from './types';import type {Locale, TranslatorFn} from '../i18n';import {truncateCharacters} from '../utils/characters';import {+ formatDateAbsolute,formatDateAbsoluteCompact,formatSharedNumber,} from './formatFilterValue';@@ -119,6 +120,7 @@ export function formatTokenValueText(locale: Locale,t?: TranslatorFn,formatList?: ListFormatFn,+ timezoneID?: string,): string | null {switch (filterValue.type) {case 'empty':@@ -176,8 +178,13 @@ export function formatTokenValueText(return filterValue.value;case 'date_absolute':+ // A date-only value reads in the zone its editor uses. An+ // `isDateOnly: false` value reads its day in the viewer's zone.return truncateString(- formatDateAbsoluteCompact(filterValue.unixSeconds, locale),+ operatorValue.type === 'date_absolute' &&+ operatorValue.isDateOnly === false+ ? formatDateAbsoluteCompact(filterValue.unixSeconds, locale)+ : formatDateAbsolute(filterValue.unixSeconds, locale, timezoneID),maxLength,);diff --git a/packages/core/src/PowerSearch/powerSearchDateZone.ts b/packages/core/src/PowerSearch/powerSearchDateZone.tsnew file mode 100644index 0000000000..9b1ebdbb93--- /dev/null+++ b/packages/core/src/PowerSearch/powerSearchDateZone.ts@@ -0,0 +1,64 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file powerSearchDateZone.ts+ * @input A `date_absolute` or range part's `unixSeconds`, the operator's+ * `isDateOnly`, and the PowerSearch `timezoneID`+ * @output The one zone every reading of such a value uses, and the+ * conversions between an instant and the calendar day shown in that zone+ * @position Shared by the token text, the accessible label, and the value+ * editors, so a value reads as the same day everywhere in one field+ */++import type {ISODateString} from '../utils/dateTypes';+import {+ plainDateFromDate,+ plainDateFromInstant,+ plainDateFromISO,+ plainDateToDate,+ plainDateToInstant,+ plainDateToISO,+} from '../utils/plainDate';++/**+ * The zone a date value is read and written in. A calendar day is stored as+ * midnight in `timezoneID`. With no `timezoneID` the day is the UTC day, so+ * a value written before a zone was given keeps its day. A value with a time+ * of day shows in `timezoneID`, else in the viewer's zone. `undefined` names+ * the viewer's zone, because `Intl` and `Date` default to it.+ */+export function resolveDateZone(+ timezoneID: string | undefined,+ isDateOnly: boolean,+): string | undefined {+ // An empty string is no zone, as the formatter always read it.+ if (timezoneID) {+ return timezoneID;+ }+ return isDateOnly ? 'UTC' : undefined;+}++export function unixSecondsToISODate(+ unixSeconds: number,+ zone: string | undefined,+): ISODateString {+ const instant = unixSeconds * 1000;++ return plainDateToISO(+ zone == null+ ? plainDateFromDate(new Date(instant))+ : plainDateFromInstant(instant, zone),+ );+}++export function isoDateToUnixSeconds(+ date: ISODateString,+ zone: string | undefined,+): number {+ const plain = plainDateFromISO(date);+ const instant =+ zone == null+ ? plainDateToDate(plain).getTime()+ : plainDateToInstant(plain, zone);+ return Math.floor(instant / 1000);+}diff --git a/packages/core/src/PowerSearch/types.ts b/packages/core/src/PowerSearch/types.tsindex 736193144d..a4007b4450 100644--- a/packages/core/src/PowerSearch/types.ts+++ b/packages/core/src/PowerSearch/types.ts@@ -407,6 +407,8 @@ export interface PowerSearchTokenProps {readonly onClick?: () => void;readonly onRemove?: () => void;readonly isDisabled?: boolean;+ /** The zone the field reads date values in; see PowerSearch `timezoneID`. */+ readonly timezoneID?: string;}/**