@astryxdesign/core 0.7.7 → 0.7.8-canary.0588a13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (798) hide show
  1. package/dist/AlertDialog/AlertDialog.d.ts +4 -1
  2. package/dist/AlertDialog/AlertDialog.d.ts.map +1 -1
  3. package/dist/AlertDialog/AlertDialog.js +46 -6
  4. package/dist/AppShell/AppShell.d.ts.map +1 -1
  5. package/dist/AppShell/AppShell.js +11 -3
  6. package/dist/BottomSheet/BottomSheet.d.ts.map +1 -1
  7. package/dist/BottomSheet/BottomSheet.js +1 -0
  8. package/dist/BottomSheet/BottomSheetPanel.d.ts +1 -1
  9. package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
  10. package/dist/BottomSheet/BottomSheetPanel.js +55 -18
  11. package/dist/BottomSheet/BottomSheetSwitcher.d.ts.map +1 -1
  12. package/dist/BottomSheet/BottomSheetSwitcher.js +5 -0
  13. package/dist/BottomSheet/bottomSheetStack.js +1 -1
  14. package/dist/BottomSheet/useSheetGestures.d.ts +3 -1
  15. package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -1
  16. package/dist/BottomSheet/useSheetGestures.js +16 -1
  17. package/dist/Button/Button.d.ts.map +1 -1
  18. package/dist/Button/Button.js +17 -1
  19. package/dist/Calendar/Calendar.d.ts.map +1 -1
  20. package/dist/Calendar/Calendar.js +18 -22
  21. package/dist/Calendar/getWeekdayHeaderNames.d.ts +16 -0
  22. package/dist/Calendar/getWeekdayHeaderNames.d.ts.map +1 -0
  23. package/dist/Calendar/getWeekdayHeaderNames.js +70 -0
  24. package/dist/Calendar/hooks/useCalendarDays.d.ts.map +1 -1
  25. package/dist/Calendar/hooks/useCalendarDays.js +2 -10
  26. package/dist/Calendar/{standaloneShortWeekdayNames.generated.d.ts → weekdayHeaderNames.generated.d.ts} +14 -14
  27. package/dist/Calendar/weekdayHeaderNames.generated.d.ts.map +1 -0
  28. package/dist/Calendar/{standaloneShortWeekdayNames.generated.js → weekdayHeaderNames.generated.js} +12 -12
  29. package/dist/Carousel/Carousel.d.ts.map +1 -1
  30. package/dist/Carousel/Carousel.js +2 -0
  31. package/dist/Chat/ChatComposerInput.d.ts.map +1 -1
  32. package/dist/Chat/ChatComposerInput.js +6 -1
  33. package/dist/Chat/ChatMessageList.d.ts.map +1 -1
  34. package/dist/Chat/ChatMessageList.js +2 -1
  35. package/dist/Chat/useChatDictation.d.ts.map +1 -1
  36. package/dist/Chat/useChatDictation.js +2 -0
  37. package/dist/Chat/useChatNewMessages.js +1 -1
  38. package/dist/Chat/useChatStreamScroll.d.ts.map +1 -1
  39. package/dist/Chat/useChatStreamScroll.js +2 -0
  40. package/dist/Chat/useSpeechRecognition.d.ts.map +1 -1
  41. package/dist/Chat/useSpeechRecognition.js +3 -0
  42. package/dist/Chat/useTriggerMenu.js +1 -1
  43. package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
  44. package/dist/CheckboxInput/CheckboxInput.js +17 -12
  45. package/dist/CheckboxList/CheckboxList.d.ts +20 -2
  46. package/dist/CheckboxList/CheckboxList.d.ts.map +1 -1
  47. package/dist/CheckboxList/CheckboxList.js +12 -4
  48. package/dist/CheckboxList/CheckboxListContext.d.ts +7 -0
  49. package/dist/CheckboxList/CheckboxListContext.d.ts.map +1 -1
  50. package/dist/CheckboxList/CheckboxListContext.js +2 -1
  51. package/dist/CheckboxList/CheckboxListItem.d.ts.map +1 -1
  52. package/dist/CheckboxList/CheckboxListItem.js +14 -2
  53. package/dist/CheckboxList/requiredGroup.d.ts +22 -0
  54. package/dist/CheckboxList/requiredGroup.d.ts.map +1 -0
  55. package/dist/CheckboxList/requiredGroup.js +52 -0
  56. package/dist/CodeBlock/CodeBlock.d.ts +10 -1
  57. package/dist/CodeBlock/CodeBlock.d.ts.map +1 -1
  58. package/dist/CodeBlock/CodeBlock.js +28 -11
  59. package/dist/CommandPalette/CommandPalette.d.ts.map +1 -1
  60. package/dist/CommandPalette/CommandPalette.js +2 -0
  61. package/dist/CommandPalette/CommandPaletteItem.d.ts.map +1 -1
  62. package/dist/CommandPalette/CommandPaletteItem.js +2 -0
  63. package/dist/ComplexSelector/ComplexSelector.d.ts +4 -1
  64. package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
  65. package/dist/ComplexSelector/ComplexSelector.js +14 -4
  66. package/dist/ContextMenu/ContextMenu.js +2 -2
  67. package/dist/DateInput/MonthScroller.d.ts.map +1 -1
  68. package/dist/DateInput/MonthScroller.js +5 -2
  69. package/dist/DateInput/PickerWheel.d.ts +19 -0
  70. package/dist/DateInput/PickerWheel.d.ts.map +1 -0
  71. package/dist/DateInput/PickerWheel.js +646 -0
  72. package/dist/DateInput/TouchDateField.d.ts.map +1 -1
  73. package/dist/DateInput/TouchDateField.js +9 -30
  74. package/dist/DateInput/Wheel.d.ts +18 -37
  75. package/dist/DateInput/Wheel.d.ts.map +1 -1
  76. package/dist/DateInput/Wheel.js +133 -120
  77. package/dist/DateInput/datePickerTouch.d.ts +13 -0
  78. package/dist/DateInput/datePickerTouch.d.ts.map +1 -0
  79. package/dist/DateInput/datePickerTouch.js +14 -0
  80. package/dist/DateInput/useOwnScrollGesture.d.ts +10 -0
  81. package/dist/DateInput/useOwnScrollGesture.d.ts.map +1 -1
  82. package/dist/DateInput/useOwnScrollGesture.js +16 -3
  83. package/dist/DateInput/usePointerDragScroll.d.ts.map +1 -1
  84. package/dist/DateInput/usePointerDragScroll.js +2 -0
  85. package/dist/DateInput/useScrollSettle.d.ts.map +1 -1
  86. package/dist/DateInput/useScrollSettle.js +3 -0
  87. package/dist/DateInput/useWheelListbox.d.ts +59 -0
  88. package/dist/DateInput/useWheelListbox.d.ts.map +1 -0
  89. package/dist/DateInput/useWheelListbox.js +88 -0
  90. package/dist/DateInput/wheelOptions.d.ts +94 -0
  91. package/dist/DateInput/wheelOptions.d.ts.map +1 -0
  92. package/dist/DateInput/wheelOptions.js +110 -0
  93. package/dist/DateInput/wheelPhysics.d.ts +127 -0
  94. package/dist/DateInput/wheelPhysics.d.ts.map +1 -0
  95. package/dist/DateInput/wheelPhysics.js +341 -0
  96. package/dist/DateInput/wheelStrip.d.ts +92 -0
  97. package/dist/DateInput/wheelStrip.d.ts.map +1 -0
  98. package/dist/DateInput/wheelStrip.js +258 -0
  99. package/dist/DateTimeInput/TouchDateTimeField.d.ts.map +1 -1
  100. package/dist/DateTimeInput/TouchDateTimeField.js +70 -127
  101. package/dist/Dialog/Dialog.d.ts.map +1 -1
  102. package/dist/Dialog/Dialog.js +9 -32
  103. package/dist/Drawer/useDrawerDialogPresence.d.ts.map +1 -1
  104. package/dist/Drawer/useDrawerDialogPresence.js +3 -0
  105. package/dist/DropdownMenu/useMenuOverflow.d.ts.map +1 -1
  106. package/dist/DropdownMenu/useMenuOverflow.js +5 -0
  107. package/dist/Field/Field.js +2 -2
  108. package/dist/FieldStatus/useFieldStatusAnnouncement.d.ts.map +1 -1
  109. package/dist/FieldStatus/useFieldStatusAnnouncement.js +1 -0
  110. package/dist/FormLayout/FormLayout.d.ts +5 -1
  111. package/dist/FormLayout/FormLayout.d.ts.map +1 -1
  112. package/dist/HoverCard/HoverCard.d.ts +6 -4
  113. package/dist/HoverCard/HoverCard.d.ts.map +1 -1
  114. package/dist/HoverCard/HoverCard.js +48 -3
  115. package/dist/HoverCard/useHoverCard.d.ts +5 -4
  116. package/dist/HoverCard/useHoverCard.d.ts.map +1 -1
  117. package/dist/HoverCard/useHoverCard.js +26 -34
  118. package/dist/Icon/Icon.d.ts +5 -1
  119. package/dist/Icon/Icon.d.ts.map +1 -1
  120. package/dist/Icon/Icon.js +20 -3
  121. package/dist/InfoTip/InfoTip.d.ts +5 -5
  122. package/dist/InfoTip/InfoTip.d.ts.map +1 -1
  123. package/dist/InfoTip/InfoTip.js +58 -19
  124. package/dist/Item/useSwipeAction.d.ts.map +1 -1
  125. package/dist/Item/useSwipeAction.js +3 -0
  126. package/dist/Layer/modalOutlet.d.ts.map +1 -1
  127. package/dist/Layer/modalOutlet.js +2 -0
  128. package/dist/Layer/outsidePress.d.ts.map +1 -1
  129. package/dist/Layer/outsidePress.js +1 -0
  130. package/dist/Layer/useLayer.d.ts.map +1 -1
  131. package/dist/Layer/useLayer.js +4 -1
  132. package/dist/Layer/useLayerDismissal.d.ts.map +1 -1
  133. package/dist/Layer/useLayerDismissal.js +3 -0
  134. package/dist/Layer/useTouchTrigger.d.ts +13 -7
  135. package/dist/Layer/useTouchTrigger.d.ts.map +1 -1
  136. package/dist/Layer/useTouchTrigger.js +20 -6
  137. package/dist/Layout/index.d.ts +1 -1
  138. package/dist/Layout/index.d.ts.map +1 -1
  139. package/dist/Layout/index.js +1 -1
  140. package/dist/Layout/layoutReset.js +1 -1
  141. package/dist/Layout/overlayPaddingReset.stylex.d.ts +68 -0
  142. package/dist/Layout/overlayPaddingReset.stylex.d.ts.map +1 -0
  143. package/dist/Layout/overlayPaddingReset.stylex.js +72 -0
  144. package/dist/Layout/padding.stylex.d.ts +5 -129
  145. package/dist/Layout/padding.stylex.d.ts.map +1 -1
  146. package/dist/Layout/padding.stylex.js +9 -143
  147. package/dist/Layout/paddingStyles.stylex.d.ts +83 -0
  148. package/dist/Layout/paddingStyles.stylex.d.ts.map +1 -0
  149. package/dist/Layout/paddingStyles.stylex.js +99 -0
  150. package/dist/Lightbox/Lightbox.d.ts.map +1 -1
  151. package/dist/Lightbox/Lightbox.js +20 -1
  152. package/dist/MobileNav/MobileNav.d.ts +3 -2
  153. package/dist/MobileNav/MobileNav.d.ts.map +1 -1
  154. package/dist/MobileNav/MobileNav.js +10 -26
  155. package/dist/MultiSelector/MultiSelector.d.ts.map +1 -1
  156. package/dist/MultiSelector/MultiSelector.js +2 -1
  157. package/dist/NumberInput/NumberInput.d.ts.map +1 -1
  158. package/dist/NumberInput/NumberInput.js +2 -1
  159. package/dist/Outline/useOutlineFromDOM.d.ts.map +1 -1
  160. package/dist/Outline/useOutlineFromDOM.js +3 -0
  161. package/dist/Outline/useScrollSpy.d.ts.map +1 -1
  162. package/dist/Outline/useScrollSpy.js +3 -0
  163. package/dist/OverflowList/OverflowList.d.ts.map +1 -1
  164. package/dist/OverflowList/OverflowList.js +3 -0
  165. package/dist/Overlay/Overlay.d.ts.map +1 -1
  166. package/dist/Overlay/Overlay.js +7 -2
  167. package/dist/Popover/Popover.d.ts.map +1 -1
  168. package/dist/Popover/Popover.js +6 -0
  169. package/dist/Popover/usePopover.js +2 -2
  170. package/dist/PowerSearch/PowerSearch.d.ts +41 -4
  171. package/dist/PowerSearch/PowerSearch.d.ts.map +1 -1
  172. package/dist/PowerSearch/PowerSearch.js +441 -134
  173. package/dist/PowerSearch/PowerSearchBottomSheet.d.ts +125 -0
  174. package/dist/PowerSearch/PowerSearchBottomSheet.d.ts.map +1 -0
  175. package/dist/PowerSearch/PowerSearchBottomSheet.js +2041 -0
  176. package/dist/PowerSearch/PowerSearchEditPopover.d.ts +35 -2
  177. package/dist/PowerSearch/PowerSearchEditPopover.d.ts.map +1 -1
  178. package/dist/PowerSearch/PowerSearchEditPopover.js +43 -10
  179. package/dist/PowerSearch/PowerSearchFilterEditor.d.ts +1 -1
  180. package/dist/PowerSearch/PowerSearchFilterEditor.d.ts.map +1 -1
  181. package/dist/PowerSearch/PowerSearchFilterEditor.js +4 -2
  182. package/dist/PowerSearch/PowerSearchToken.d.ts +1 -1
  183. package/dist/PowerSearch/PowerSearchToken.d.ts.map +1 -1
  184. package/dist/PowerSearch/PowerSearchToken.js +3 -2
  185. package/dist/PowerSearch/PowerSearchValueEditor.d.ts +38 -3
  186. package/dist/PowerSearch/PowerSearchValueEditor.d.ts.map +1 -1
  187. package/dist/PowerSearch/PowerSearchValueEditor.js +273 -86
  188. package/dist/PowerSearch/formatFilterValue.d.ts +14 -7
  189. package/dist/PowerSearch/formatFilterValue.d.ts.map +1 -1
  190. package/dist/PowerSearch/formatFilterValue.js +31 -23
  191. package/dist/PowerSearch/formatTokenValue.d.ts +28 -0
  192. package/dist/PowerSearch/formatTokenValue.d.ts.map +1 -0
  193. package/dist/PowerSearch/formatTokenValue.js +161 -0
  194. package/dist/PowerSearch/index.d.ts +1 -1
  195. package/dist/PowerSearch/index.d.ts.map +1 -1
  196. package/dist/PowerSearch/powerSearchDateZone.d.ts +25 -0
  197. package/dist/PowerSearch/powerSearchDateZone.d.ts.map +1 -0
  198. package/dist/PowerSearch/powerSearchDateZone.js +57 -0
  199. package/dist/PowerSearch/powerSearchSheetUtils.d.ts +65 -0
  200. package/dist/PowerSearch/powerSearchSheetUtils.d.ts.map +1 -0
  201. package/dist/PowerSearch/powerSearchSheetUtils.js +168 -0
  202. package/dist/PowerSearch/types.d.ts +8 -1
  203. package/dist/PowerSearch/types.d.ts.map +1 -1
  204. package/dist/ProgressBar/ProgressBarTouch.d.ts.map +1 -1
  205. package/dist/ProgressBar/ProgressBarTouch.js +2 -0
  206. package/dist/RadioList/RadioList.d.ts.map +1 -1
  207. package/dist/RadioList/RadioList.js +3 -2
  208. package/dist/RadioList/RadioListItem.d.ts +1 -1
  209. package/dist/RadioList/RadioListItem.d.ts.map +1 -1
  210. package/dist/RadioList/RadioListItem.js +5 -3
  211. package/dist/Resizable/ResizeHandle.d.ts +2 -1
  212. package/dist/Resizable/ResizeHandle.d.ts.map +1 -1
  213. package/dist/Resizable/ResizeHandle.js +116 -92
  214. package/dist/Resizable/createResizable.d.ts +199 -0
  215. package/dist/Resizable/createResizable.d.ts.map +1 -0
  216. package/dist/Resizable/createResizable.js +733 -0
  217. package/dist/Resizable/separatorAttributes.d.ts +45 -0
  218. package/dist/Resizable/separatorAttributes.d.ts.map +1 -0
  219. package/dist/Resizable/separatorAttributes.js +35 -0
  220. package/dist/Resizable/useResizable.d.ts +3 -3
  221. package/dist/Resizable/useResizable.d.ts.map +1 -1
  222. package/dist/Resizable/useResizable.js +252 -459
  223. package/dist/SegmentedControl/useSegmentedSelectionMotion.d.ts.map +1 -1
  224. package/dist/SegmentedControl/useSegmentedSelectionMotion.js +3 -3
  225. package/dist/SelectableCard/SelectableCard.d.ts +2 -0
  226. package/dist/SelectableCard/SelectableCard.d.ts.map +1 -1
  227. package/dist/SelectableCard/SelectableCard.js +36 -11
  228. package/dist/SelectableCard/selectableCardInput.d.ts +12 -0
  229. package/dist/SelectableCard/selectableCardInput.d.ts.map +1 -0
  230. package/dist/SelectableCard/selectableCardInput.js +20 -0
  231. package/dist/Selector/Selector.d.ts.map +1 -1
  232. package/dist/Selector/Selector.js +7 -9
  233. package/dist/SideNav/SideNav.d.ts.map +1 -1
  234. package/dist/SideNav/SideNav.js +36 -5
  235. package/dist/Slider/Slider.d.ts.map +1 -1
  236. package/dist/Slider/Slider.js +16 -11
  237. package/dist/Slider/sliderTouchController.js +2 -2
  238. package/dist/Spinner/Spinner.d.ts +1 -1
  239. package/dist/Spinner/Spinner.d.ts.map +1 -1
  240. package/dist/Spinner/Spinner.js +60 -58
  241. package/dist/Stepper/Stepper.d.ts.map +1 -1
  242. package/dist/Stepper/Stepper.js +10 -15
  243. package/dist/Switch/Switch.d.ts.map +1 -1
  244. package/dist/Switch/Switch.js +4 -10
  245. package/dist/Switch/useSwitchTouch.js +4 -4
  246. package/dist/Table/BaseTable.d.ts.map +1 -1
  247. package/dist/Table/BaseTable.js +29 -8
  248. package/dist/Table/plugins/columnResize/useTableColumnResize.d.ts.map +1 -1
  249. package/dist/Table/plugins/columnResize/useTableColumnResize.js +3 -1
  250. package/dist/Table/plugins/filtering/useTableFiltering.d.ts.map +1 -1
  251. package/dist/Table/plugins/filtering/useTableFiltering.js +2 -1
  252. package/dist/Table/plugins/rowExpansion/useTableRowExpansion.d.ts +12 -0
  253. package/dist/Table/plugins/rowExpansion/useTableRowExpansion.d.ts.map +1 -1
  254. package/dist/Table/plugins/rowExpansion/useTableRowExpansion.js +17 -3
  255. package/dist/Table/plugins/stickyColumns/useTableStickyColumns.d.ts.map +1 -1
  256. package/dist/Table/plugins/stickyColumns/useTableStickyColumns.js +2 -0
  257. package/dist/Table/plugins/tree/useTableTreeData.d.ts +11 -0
  258. package/dist/Table/plugins/tree/useTableTreeData.d.ts.map +1 -1
  259. package/dist/Table/plugins/tree/useTableTreeData.js +27 -14
  260. package/dist/TextArea/TextArea.d.ts.map +1 -1
  261. package/dist/TextArea/TextArea.js +2 -1
  262. package/dist/TextInput/TextInput.d.ts +2 -2
  263. package/dist/TextInput/TextInput.d.ts.map +1 -1
  264. package/dist/TextInput/TextInput.js +12 -8
  265. package/dist/TimeInput/TimeInput.d.ts.map +1 -1
  266. package/dist/TimeInput/TimeInput.js +2 -0
  267. package/dist/TimeInput/TimeWheels.d.ts +32 -0
  268. package/dist/TimeInput/TimeWheels.d.ts.map +1 -0
  269. package/dist/TimeInput/TimeWheels.js +144 -0
  270. package/dist/TimeInput/TouchTimeField.d.ts.map +1 -1
  271. package/dist/TimeInput/TouchTimeField.js +63 -116
  272. package/dist/TimeInput/timeWheelRules.d.ts +124 -0
  273. package/dist/TimeInput/timeWheelRules.d.ts.map +1 -0
  274. package/dist/TimeInput/timeWheelRules.js +277 -0
  275. package/dist/Timer/Timer.d.ts.map +1 -1
  276. package/dist/Timer/Timer.js +2 -0
  277. package/dist/Timestamp/Timestamp.js +1 -1
  278. package/dist/Timestamp/formatInstant.d.ts.map +1 -1
  279. package/dist/Timestamp/formatInstant.js +1 -23
  280. package/dist/Toast/Toast.d.ts +11 -1
  281. package/dist/Toast/Toast.d.ts.map +1 -1
  282. package/dist/Toast/Toast.js +25 -15
  283. package/dist/Toast/ToastViewport.d.ts.map +1 -1
  284. package/dist/Toast/ToastViewport.js +97 -34
  285. package/dist/Toast/types.d.ts +9 -3
  286. package/dist/Toast/types.d.ts.map +1 -1
  287. package/dist/Toast/useToast.d.ts.map +1 -1
  288. package/dist/Toast/useToast.js +1 -0
  289. package/dist/Tokenizer/Tokenizer.d.ts +44 -46
  290. package/dist/Tokenizer/Tokenizer.d.ts.map +1 -1
  291. package/dist/Tokenizer/Tokenizer.js +20 -21
  292. package/dist/Tokenizer/TokenizerBottomSheet.d.ts +1 -1
  293. package/dist/Tokenizer/TokenizerBottomSheet.js +12 -18
  294. package/dist/Tokenizer/index.d.ts +1 -1
  295. package/dist/Tokenizer/index.d.ts.map +1 -1
  296. package/dist/Tooltip/Tooltip.d.ts +2 -23
  297. package/dist/Tooltip/Tooltip.d.ts.map +1 -1
  298. package/dist/Tooltip/Tooltip.js +5 -29
  299. package/dist/Tooltip/useTooltip.d.ts +23 -30
  300. package/dist/Tooltip/useTooltip.d.ts.map +1 -1
  301. package/dist/Tooltip/useTooltip.js +200 -108
  302. package/dist/Typeahead/BaseTypeahead.d.ts.map +1 -1
  303. package/dist/Typeahead/BaseTypeahead.js +27 -18
  304. package/dist/Typeahead/TypeaheadItem.d.ts +2 -1
  305. package/dist/Typeahead/TypeaheadItem.d.ts.map +1 -1
  306. package/dist/animator/createAnimator.d.ts +98 -0
  307. package/dist/animator/createAnimator.d.ts.map +1 -0
  308. package/dist/animator/createAnimator.js +259 -0
  309. package/dist/astryx.css +53 -8
  310. package/dist/gestures/GestureHost.d.ts +16 -1
  311. package/dist/gestures/GestureHost.d.ts.map +1 -1
  312. package/dist/gestures/GestureHost.js +4 -1
  313. package/dist/gestures/PressTracker.d.ts.map +1 -1
  314. package/dist/gestures/PressTracker.js +4 -3
  315. package/dist/hooks/ModalAnnounceProvider.d.ts.map +1 -1
  316. package/dist/hooks/ModalAnnounceProvider.js +1 -0
  317. package/dist/hooks/actionGroupTracker.d.ts +4 -1
  318. package/dist/hooks/actionGroupTracker.d.ts.map +1 -1
  319. package/dist/hooks/actionGroupTracker.js +18 -7
  320. package/dist/hooks/index.d.ts +1 -0
  321. package/dist/hooks/index.d.ts.map +1 -1
  322. package/dist/hooks/index.js +1 -0
  323. package/dist/hooks/longPressDetector.d.ts +66 -0
  324. package/dist/hooks/longPressDetector.d.ts.map +1 -0
  325. package/dist/hooks/longPressDetector.js +200 -0
  326. package/dist/hooks/pressGroupContext.d.ts +6 -0
  327. package/dist/hooks/pressGroupContext.d.ts.map +1 -0
  328. package/dist/hooks/pressGroupContext.js +20 -0
  329. package/dist/hooks/rootScrollStyles.d.ts +48 -0
  330. package/dist/hooks/rootScrollStyles.d.ts.map +1 -0
  331. package/dist/hooks/rootScrollStyles.js +207 -0
  332. package/dist/hooks/scrollLockTouchGuard.d.ts +13 -0
  333. package/dist/hooks/scrollLockTouchGuard.d.ts.map +1 -0
  334. package/dist/hooks/scrollLockTouchGuard.js +117 -0
  335. package/dist/hooks/scrollbarGutter.d.ts +4 -4
  336. package/dist/hooks/scrollbarGutter.d.ts.map +1 -1
  337. package/dist/hooks/scrollbarGutter.js +36 -23
  338. package/dist/hooks/useActionGroupTracking.d.ts +53 -0
  339. package/dist/hooks/useActionGroupTracking.d.ts.map +1 -0
  340. package/dist/hooks/useActionGroupTracking.js +174 -0
  341. package/dist/hooks/useAnimator.d.ts +41 -0
  342. package/dist/hooks/useAnimator.d.ts.map +1 -0
  343. package/dist/hooks/useAnimator.js +70 -0
  344. package/dist/hooks/useAnnounceRenderedText.d.ts.map +1 -1
  345. package/dist/hooks/useAnnounceRenderedText.js +1 -0
  346. package/dist/hooks/useAttachment.d.ts +1 -1
  347. package/dist/hooks/useAttachment.js +1 -1
  348. package/dist/hooks/useAutoMediaMode.d.ts.map +1 -1
  349. package/dist/hooks/useAutoMediaMode.js +1 -0
  350. package/dist/hooks/useBusyAnnouncement.d.ts.map +1 -1
  351. package/dist/hooks/useBusyAnnouncement.js +2 -0
  352. package/dist/hooks/useDevWarning.d.ts.map +1 -1
  353. package/dist/hooks/useDevWarning.js +2 -0
  354. package/dist/hooks/useFocusTrap.d.ts.map +1 -1
  355. package/dist/hooks/useFocusTrap.js +2 -0
  356. package/dist/hooks/useGridFocus.d.ts +8 -5
  357. package/dist/hooks/useGridFocus.d.ts.map +1 -1
  358. package/dist/hooks/useGridFocus.js +4 -3
  359. package/dist/hooks/useHotkeys.d.ts.map +1 -1
  360. package/dist/hooks/useHotkeys.js +3 -0
  361. package/dist/hooks/useImageMode.d.ts.map +1 -1
  362. package/dist/hooks/useImageMode.js +3 -0
  363. package/dist/hooks/useInputStatusIcon.d.ts +1 -1
  364. package/dist/hooks/useInputStatusIcon.d.ts.map +1 -1
  365. package/dist/hooks/useInputStatusIcon.js +2 -2
  366. package/dist/hooks/useIsomorphicLayoutEffect.d.ts +2 -2
  367. package/dist/hooks/useIsomorphicLayoutEffect.d.ts.map +1 -1
  368. package/dist/hooks/useKeyboardHint.js +1 -1
  369. package/dist/hooks/useLongPress.d.ts +8 -9
  370. package/dist/hooks/useLongPress.d.ts.map +1 -1
  371. package/dist/hooks/useLongPress.js +23 -106
  372. package/dist/hooks/useMenuHover.d.ts.map +1 -1
  373. package/dist/hooks/useMenuHover.js +2 -0
  374. package/dist/hooks/useMenuPress.d.ts.map +1 -1
  375. package/dist/hooks/useMenuPress.js +3 -0
  376. package/dist/hooks/useOverflow.d.ts.map +1 -1
  377. package/dist/hooks/useOverflow.js +2 -1
  378. package/dist/hooks/usePressFeedback.d.ts.map +1 -1
  379. package/dist/hooks/usePressFeedback.js +1 -0
  380. package/dist/hooks/useResolvedRequired.d.ts +3 -0
  381. package/dist/hooks/useResolvedRequired.d.ts.map +1 -1
  382. package/dist/hooks/useResolvedRequired.js +3 -0
  383. package/dist/hooks/useScrollLock.d.ts +8 -9
  384. package/dist/hooks/useScrollLock.d.ts.map +1 -1
  385. package/dist/hooks/useScrollLock.js +50 -48
  386. package/dist/hooks/useScrollableArea.d.ts.map +1 -1
  387. package/dist/hooks/useScrollableArea.js +5 -0
  388. package/dist/hooks/useStreamingText.d.ts.map +1 -1
  389. package/dist/hooks/useStreamingText.js +3 -0
  390. package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.d.ts +8 -0
  391. package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.d.ts.map +1 -0
  392. package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.js +45 -0
  393. package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.d.ts.map +1 -1
  394. package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.js +6 -0
  395. package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.d.ts +8 -0
  396. package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.d.ts.map +1 -0
  397. package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.js +14 -0
  398. package/dist/i18n/generated-english/Resizable/createResizable.generated.d.ts +8 -0
  399. package/dist/i18n/generated-english/Resizable/createResizable.generated.d.ts.map +1 -0
  400. package/dist/i18n/generated-english/Resizable/createResizable.generated.js +13 -0
  401. package/dist/i18n/generated-english/Table/plugins/rowExpansion/useTableRowExpansion.generated.d.ts.map +1 -1
  402. package/dist/i18n/generated-english/Table/plugins/rowExpansion/useTableRowExpansion.generated.js +3 -1
  403. package/dist/i18n/generated-english/Table/plugins/tree/useTableTreeData.generated.d.ts.map +1 -1
  404. package/dist/i18n/generated-english/Table/plugins/tree/useTableTreeData.generated.js +3 -1
  405. package/dist/i18n/generated-english/TimeInput/TimeWheels.generated.d.ts +8 -0
  406. package/dist/i18n/generated-english/TimeInput/TimeWheels.generated.d.ts.map +1 -0
  407. package/dist/i18n/generated-english/TimeInput/TimeWheels.generated.js +17 -0
  408. package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
  409. package/dist/i18n/generated-locales/en.generated.js +37 -0
  410. package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
  411. package/dist/i18n/generated-locales/pseudo.generated.js +37 -0
  412. package/dist/index.d.ts +1 -0
  413. package/dist/index.d.ts.map +1 -1
  414. package/dist/index.js +4 -0
  415. package/dist/internal/indicatorPress.stylex.d.ts +20 -0
  416. package/dist/internal/indicatorPress.stylex.d.ts.map +1 -0
  417. package/dist/internal/indicatorPress.stylex.js +26 -0
  418. package/dist/internal/selectable-card.d.ts +21 -0
  419. package/dist/internal/selectable-card.d.ts.map +1 -0
  420. package/dist/internal/selectable-card.js +20 -0
  421. package/dist/internal/sheetDraft.d.ts +2 -2
  422. package/dist/internal/sheetDraft.js +2 -2
  423. package/dist/keyboard/index.d.ts +17 -0
  424. package/dist/keyboard/index.d.ts.map +1 -0
  425. package/dist/keyboard/index.js +19 -0
  426. package/dist/keyboard/keyboardHeight.d.ts +149 -0
  427. package/dist/keyboard/keyboardHeight.d.ts.map +1 -0
  428. package/dist/keyboard/keyboardHeight.js +432 -0
  429. package/dist/keyboard/keyboardLayoutGuide.d.ts +59 -0
  430. package/dist/keyboard/keyboardLayoutGuide.d.ts.map +1 -0
  431. package/dist/keyboard/keyboardLayoutGuide.js +207 -0
  432. package/dist/keyboard/keyboardModel.d.ts +93 -0
  433. package/dist/keyboard/keyboardModel.d.ts.map +1 -0
  434. package/dist/keyboard/keyboardModel.js +220 -0
  435. package/dist/keyboard/rideKeyboard.d.ts +42 -0
  436. package/dist/keyboard/rideKeyboard.d.ts.map +1 -0
  437. package/dist/keyboard/rideKeyboard.js +77 -0
  438. package/dist/keyboard/useMobileKeyboard.d.ts +61 -0
  439. package/dist/keyboard/useMobileKeyboard.d.ts.map +1 -0
  440. package/dist/keyboard/useMobileKeyboard.js +699 -0
  441. package/dist/motion/android/index.d.ts +16 -0
  442. package/dist/motion/android/index.d.ts.map +1 -0
  443. package/dist/motion/android/index.js +18 -0
  444. package/dist/motion/android/keyboard.d.ts +83 -0
  445. package/dist/motion/android/keyboard.d.ts.map +1 -0
  446. package/dist/motion/android/keyboard.js +96 -0
  447. package/dist/motion/animatedLayout.d.ts +8 -0
  448. package/dist/motion/animatedLayout.d.ts.map +1 -1
  449. package/dist/motion/animatedLayout.js +246 -53
  450. package/dist/motion/animator.d.ts +14 -14
  451. package/dist/motion/animator.d.ts.map +1 -1
  452. package/dist/motion/animator.js +45 -26
  453. package/dist/motion/frameBlock.d.ts +14 -0
  454. package/dist/motion/frameBlock.d.ts.map +1 -0
  455. package/dist/motion/frameBlock.js +16 -0
  456. package/dist/motion/progress.d.ts +88 -0
  457. package/dist/motion/progress.d.ts.map +1 -0
  458. package/dist/motion/progress.js +128 -0
  459. package/dist/motion/reducedMotion.d.ts.map +1 -1
  460. package/dist/motion/reducedMotion.js +3 -1
  461. package/dist/motion/uikit/alert.d.ts +41 -0
  462. package/dist/motion/uikit/alert.d.ts.map +1 -0
  463. package/dist/motion/uikit/alert.js +43 -0
  464. package/dist/motion/uikit/datePicker.d.ts +58 -0
  465. package/dist/motion/uikit/datePicker.d.ts.map +1 -0
  466. package/dist/motion/uikit/datePicker.js +60 -0
  467. package/dist/motion/uikit/index.d.ts +6 -4
  468. package/dist/motion/uikit/index.d.ts.map +1 -1
  469. package/dist/motion/uikit/index.js +6 -4
  470. package/dist/motion/uikit/picker.d.ts +96 -0
  471. package/dist/motion/uikit/picker.d.ts.map +1 -0
  472. package/dist/motion/uikit/picker.js +117 -0
  473. package/dist/privateAttributes/pressGroupItem.stylex.d.ts +22 -0
  474. package/dist/privateAttributes/pressGroupItem.stylex.d.ts.map +1 -0
  475. package/dist/privateAttributes/pressGroupItem.stylex.js +36 -0
  476. package/dist/privateAttributes/reducedMotion.stylex.d.ts +23 -0
  477. package/dist/privateAttributes/reducedMotion.stylex.d.ts.map +1 -0
  478. package/dist/privateAttributes/reducedMotion.stylex.js +40 -0
  479. package/dist/theme/Theme.d.ts.map +1 -1
  480. package/dist/theme/Theme.js +29 -4
  481. package/dist/theme/generateThemeRules.d.ts.map +1 -1
  482. package/dist/theme/generateThemeRules.js +14 -13
  483. package/dist/theme/motionKnobs.d.ts +4 -3
  484. package/dist/theme/motionKnobs.d.ts.map +1 -1
  485. package/dist/theme/motionKnobs.js +3 -2
  486. package/dist/theme/themeMotion.d.ts +6 -0
  487. package/dist/theme/themeMotion.d.ts.map +1 -1
  488. package/dist/theme/themeMotion.js +15 -2
  489. package/dist/theme/tokens.stylex.d.ts +3 -0
  490. package/dist/theme/tokens.stylex.d.ts.map +1 -1
  491. package/dist/theme/tokens.stylex.js +4 -1
  492. package/dist/utils/dateParser.d.ts.map +1 -1
  493. package/dist/utils/dateParser.js +12 -0
  494. package/dist/utils/disabledInteraction.d.ts +10 -2
  495. package/dist/utils/disabledInteraction.d.ts.map +1 -1
  496. package/dist/utils/disabledInteraction.js +16 -2
  497. package/dist/utils/focusReturn.d.ts +22 -25
  498. package/dist/utils/focusReturn.d.ts.map +1 -1
  499. package/dist/utils/focusReturn.js +36 -29
  500. package/dist/utils/index.d.ts +1 -1
  501. package/dist/utils/index.d.ts.map +1 -1
  502. package/dist/utils/index.js +1 -1
  503. package/dist/utils/interactionModality.d.ts.map +1 -1
  504. package/dist/utils/interactionModality.js +4 -0
  505. package/dist/utils/interactionOverlay.stylex.d.ts +6 -4
  506. package/dist/utils/interactionOverlay.stylex.d.ts.map +1 -1
  507. package/dist/utils/interactionOverlay.stylex.js +6 -4
  508. package/dist/utils/isFocusDetached.d.ts +27 -0
  509. package/dist/utils/isFocusDetached.d.ts.map +1 -0
  510. package/dist/utils/isFocusDetached.js +32 -0
  511. package/dist/utils/layoutViewport.d.ts +25 -0
  512. package/dist/utils/layoutViewport.d.ts.map +1 -0
  513. package/dist/utils/layoutViewport.js +102 -0
  514. package/dist/utils/plainDate.d.ts +31 -0
  515. package/dist/utils/plainDate.d.ts.map +1 -1
  516. package/dist/utils/plainDate.js +68 -4
  517. package/dist/utils/pressFeedback.d.ts +6 -0
  518. package/dist/utils/pressFeedback.d.ts.map +1 -1
  519. package/dist/utils/pressFeedback.js +97 -18
  520. package/dist/utils/pressGesture.d.ts +4 -2
  521. package/dist/utils/pressGesture.d.ts.map +1 -1
  522. package/dist/utils/pressGesture.js +3 -1
  523. package/dist/utils/selectionLock.d.ts +10 -1
  524. package/dist/utils/selectionLock.d.ts.map +1 -1
  525. package/dist/utils/selectionLock.js +31 -5
  526. package/dist/utils/sharedMutationObserver.d.ts +2 -1
  527. package/dist/utils/sharedMutationObserver.d.ts.map +1 -1
  528. package/dist/utils/sharedMutationObserver.js +2 -1
  529. package/dist/utils/timeParser.d.ts +2 -1
  530. package/dist/utils/timeParser.d.ts.map +1 -1
  531. package/dist/utils/timeParser.js +29 -3
  532. package/dist/utils/triggerFocus.d.ts +36 -0
  533. package/dist/utils/triggerFocus.d.ts.map +1 -0
  534. package/dist/utils/triggerFocus.js +65 -0
  535. package/locales/en.json +148 -0
  536. package/locales/pseudo.json +111 -0
  537. package/package.json +14 -9
  538. package/src/AlertDialog/AlertDialog.doc.mjs +2 -2
  539. package/src/AlertDialog/AlertDialog.tsx +46 -5
  540. package/src/AppShell/AppShell.tsx +13 -4
  541. package/src/BottomSheet/BottomSheet.doc.mjs +1 -1
  542. package/src/BottomSheet/BottomSheet.tsx +1 -0
  543. package/src/BottomSheet/BottomSheetPanel.tsx +80 -16
  544. package/src/BottomSheet/BottomSheetSwitcher.doc.mjs +5 -0
  545. package/src/BottomSheet/BottomSheetSwitcher.tsx +5 -0
  546. package/src/BottomSheet/bottomSheetStack.ts +1 -1
  547. package/src/BottomSheet/useSheetGestures.ts +16 -1
  548. package/src/Button/Button.tsx +26 -4
  549. package/src/Calendar/Calendar.tsx +40 -32
  550. package/src/Calendar/getWeekdayHeaderNames.ts +88 -0
  551. package/src/Calendar/hooks/useCalendarDays.ts +5 -10
  552. package/src/Calendar/{standaloneShortWeekdayNames.generated.ts → weekdayHeaderNames.generated.ts} +14 -14
  553. package/src/Carousel/Carousel.tsx +1 -0
  554. package/src/Chat/ChatComposerInput.tsx +4 -7
  555. package/src/Chat/ChatMessageList.tsx +2 -1
  556. package/src/Chat/useChatDictation.ts +1 -0
  557. package/src/Chat/useChatNewMessages.ts +1 -1
  558. package/src/Chat/useChatStreamScroll.ts +2 -0
  559. package/src/Chat/useSpeechRecognition.ts +2 -0
  560. package/src/Chat/useTriggerMenu.tsx +1 -1
  561. package/src/CheckboxInput/CheckboxInput.doc.mjs +18 -0
  562. package/src/CheckboxInput/CheckboxInput.tsx +38 -15
  563. package/src/CheckboxList/CheckboxList.doc.mjs +14 -0
  564. package/src/CheckboxList/CheckboxList.tsx +43 -2
  565. package/src/CheckboxList/CheckboxListContext.tsx +9 -1
  566. package/src/CheckboxList/CheckboxListItem.tsx +23 -2
  567. package/src/CheckboxList/requiredGroup.ts +77 -0
  568. package/src/CodeBlock/CodeBlock.doc.mjs +9 -1
  569. package/src/CodeBlock/CodeBlock.tsx +41 -4
  570. package/src/CommandPalette/CommandPalette.tsx +1 -0
  571. package/src/CommandPalette/CommandPaletteItem.tsx +1 -0
  572. package/src/ComplexSelector/ComplexSelector.tsx +20 -5
  573. package/src/ContextMenu/ContextMenu.tsx +2 -2
  574. package/src/DateInput/MonthScroller.tsx +8 -2
  575. package/src/DateInput/PickerWheel.tsx +796 -0
  576. package/src/DateInput/TouchDateField.tsx +6 -32
  577. package/src/DateInput/Wheel.tsx +188 -171
  578. package/src/DateInput/datePickerTouch.ts +15 -0
  579. package/src/DateInput/useOwnScrollGesture.ts +25 -3
  580. package/src/DateInput/usePointerDragScroll.ts +1 -0
  581. package/src/DateInput/useScrollSettle.ts +2 -0
  582. package/src/DateInput/useWheelListbox.ts +112 -0
  583. package/src/DateInput/wheelOptions.ts +184 -0
  584. package/src/DateInput/wheelPhysics.ts +406 -0
  585. package/src/DateInput/wheelStrip.ts +341 -0
  586. package/src/DateTimeInput/TouchDateTimeField.tsx +100 -189
  587. package/src/Dialog/Dialog.tsx +12 -32
  588. package/src/Drawer/useDrawerDialogPresence.ts +2 -0
  589. package/src/DropdownMenu/useMenuOverflow.ts +3 -0
  590. package/src/Field/Field.tsx +2 -2
  591. package/src/FieldStatus/useFieldStatusAnnouncement.ts +1 -0
  592. package/src/FormLayout/FormLayout.doc.mjs +181 -46
  593. package/src/FormLayout/FormLayout.tsx +5 -1
  594. package/src/HoverCard/HoverCard.doc.mjs +10 -8
  595. package/src/HoverCard/HoverCard.tsx +58 -6
  596. package/src/HoverCard/useHoverCard.doc.mjs +178 -36
  597. package/src/HoverCard/useHoverCard.tsx +55 -55
  598. package/src/Icon/Icon.doc.mjs +51 -10
  599. package/src/Icon/Icon.tsx +31 -8
  600. package/src/IconButton/IconButton.doc.mjs +141 -21
  601. package/src/InfoTip/InfoTip.tsx +72 -16
  602. package/src/Item/useSwipeAction.ts +2 -0
  603. package/src/Layer/modalOutlet.ts +2 -0
  604. package/src/Layer/outsidePress.ts +1 -0
  605. package/src/Layer/useLayer.tsx +3 -1
  606. package/src/Layer/useLayerDismissal.ts +2 -0
  607. package/src/Layer/useTouchTrigger.ts +19 -6
  608. package/src/Layout/index.ts +1 -1
  609. package/src/Layout/layoutReset.ts +1 -1
  610. package/src/Layout/overlayPaddingReset.stylex.ts +73 -0
  611. package/src/Layout/padding.stylex.ts +9 -133
  612. package/src/Layout/paddingStyles.stylex.ts +87 -0
  613. package/src/Lightbox/Lightbox.tsx +20 -1
  614. package/src/Lightbox/useLightbox.doc.mjs +167 -0
  615. package/src/MobileNav/MobileNav.tsx +10 -31
  616. package/src/MultiSelector/MultiSelector.tsx +2 -7
  617. package/src/NumberInput/NumberInput.tsx +2 -7
  618. package/src/Outline/useOutlineFromDOM.ts +2 -0
  619. package/src/Outline/useScrollSpy.ts +2 -0
  620. package/src/OverflowList/OverflowList.tsx +2 -0
  621. package/src/Overlay/Overlay.tsx +7 -2
  622. package/src/Popover/Popover.tsx +4 -0
  623. package/src/Popover/usePopover.tsx +2 -2
  624. package/src/PowerSearch/PowerSearch.doc.mjs +60 -8
  625. package/src/PowerSearch/PowerSearch.tsx +622 -157
  626. package/src/PowerSearch/PowerSearchBottomSheet.tsx +2700 -0
  627. package/src/PowerSearch/PowerSearchEditPopover.tsx +65 -9
  628. package/src/PowerSearch/PowerSearchFilterEditor.tsx +2 -0
  629. package/src/PowerSearch/PowerSearchToken.tsx +2 -0
  630. package/src/PowerSearch/PowerSearchValueEditor.tsx +340 -59
  631. package/src/PowerSearch/formatFilterValue.ts +49 -27
  632. package/src/PowerSearch/formatTokenValue.ts +220 -0
  633. package/src/PowerSearch/index.ts +5 -1
  634. package/src/PowerSearch/powerSearchDateZone.ts +95 -0
  635. package/src/PowerSearch/powerSearchSheetUtils.ts +224 -0
  636. package/src/PowerSearch/types.ts +8 -1
  637. package/src/ProgressBar/ProgressBarTouch.ts +2 -0
  638. package/src/RadioList/RadioList.tsx +3 -2
  639. package/src/RadioList/RadioListItem.tsx +5 -3
  640. package/src/Resizable/Resizable.doc.mjs +5 -4
  641. package/src/Resizable/ResizeHandle.tsx +187 -135
  642. package/src/Resizable/createResizable.ts +1046 -0
  643. package/src/Resizable/separatorAttributes.ts +73 -0
  644. package/src/Resizable/useResizable.ts +292 -623
  645. package/src/SegmentedControl/useSegmentedSelectionMotion.ts +6 -3
  646. package/src/SelectableCard/SelectableCard.tsx +39 -10
  647. package/src/SelectableCard/selectableCardInput.ts +30 -0
  648. package/src/Selector/Selector.tsx +7 -19
  649. package/src/SideNav/SideNav.tsx +41 -5
  650. package/src/Slider/Slider.tsx +20 -11
  651. package/src/Slider/sliderTouchController.ts +2 -2
  652. package/src/Spinner/Spinner.tsx +77 -63
  653. package/src/Stepper/Stepper.tsx +10 -27
  654. package/src/Switch/Switch.tsx +2 -6
  655. package/src/Switch/useSwitchTouch.ts +4 -4
  656. package/src/Table/BaseTable.tsx +46 -12
  657. package/src/Table/plugins/columnResize/useTableColumnResize.tsx +2 -1
  658. package/src/Table/plugins/filtering/useTableFiltering.tsx +1 -0
  659. package/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx +31 -7
  660. package/src/Table/plugins/stickyColumns/useTableStickyColumns.tsx +2 -0
  661. package/src/Table/plugins/tree/useTableTreeData.tsx +43 -20
  662. package/src/Table/useTableRowExpansion.doc.mjs +9 -0
  663. package/src/Table/useTableTreeData.doc.mjs +15 -3
  664. package/src/TextArea/TextArea.tsx +2 -7
  665. package/src/TextInput/TextInput.tsx +13 -17
  666. package/src/TimeInput/TimeInput.tsx +2 -0
  667. package/src/TimeInput/TimeWheels.tsx +218 -0
  668. package/src/TimeInput/TouchTimeField.tsx +93 -155
  669. package/src/TimeInput/timeWheelRules.ts +352 -0
  670. package/src/Timer/Timer.tsx +1 -0
  671. package/src/Timestamp/Timestamp.tsx +1 -1
  672. package/src/Timestamp/formatInstant.ts +1 -33
  673. package/src/Toast/Toast.doc.mjs +4 -3
  674. package/src/Toast/Toast.tsx +52 -32
  675. package/src/Toast/ToastViewport.tsx +123 -35
  676. package/src/Toast/types.ts +9 -3
  677. package/src/Toast/useToast.tsx +1 -0
  678. package/src/Tokenizer/Tokenizer.doc.mjs +10 -10
  679. package/src/Tokenizer/Tokenizer.tsx +61 -62
  680. package/src/Tokenizer/TokenizerBottomSheet.tsx +17 -23
  681. package/src/Tokenizer/index.ts +1 -0
  682. package/src/Tooltip/Tooltip.tsx +6 -42
  683. package/src/Tooltip/useTooltip.doc.mjs +24 -0
  684. package/src/Tooltip/useTooltip.tsx +243 -134
  685. package/src/Typeahead/BaseTypeahead.tsx +27 -17
  686. package/src/Typeahead/TypeaheadItem.doc.mjs +6 -3
  687. package/src/Typeahead/TypeaheadItem.tsx +2 -1
  688. package/src/animator/createAnimator.doc.mjs +153 -0
  689. package/src/animator/createAnimator.ts +324 -0
  690. package/src/gestures/GestureHost.ts +6 -5
  691. package/src/gestures/PressTracker.ts +4 -3
  692. package/src/gestures/README.md +10 -4
  693. package/src/hooks/ModalAnnounceProvider.tsx +1 -0
  694. package/src/hooks/actionGroupTracker.ts +25 -9
  695. package/src/hooks/index.ts +2 -0
  696. package/src/hooks/longPressDetector.ts +273 -0
  697. package/src/hooks/pressGroupContext.ts +21 -0
  698. package/src/hooks/rootScrollStyles.ts +247 -0
  699. package/src/hooks/scrollLockTouchGuard.ts +149 -0
  700. package/src/hooks/scrollbarGutter.ts +41 -26
  701. package/src/hooks/useActionGroupTracking.ts +224 -0
  702. package/src/hooks/useAnimator.doc.mjs +109 -0
  703. package/src/hooks/useAnimator.ts +67 -0
  704. package/src/hooks/useAnnounceRenderedText.ts +1 -0
  705. package/src/hooks/useAttachment.ts +1 -1
  706. package/src/hooks/useAutoMediaMode.ts +1 -0
  707. package/src/hooks/useBusyAnnouncement.ts +2 -0
  708. package/src/hooks/useDevWarning.ts +2 -0
  709. package/src/hooks/useFocusTrap.ts +2 -0
  710. package/src/hooks/useGridFocus.doc.mjs +6 -6
  711. package/src/hooks/useGridFocus.ts +10 -7
  712. package/src/hooks/useHotkeys.ts +2 -0
  713. package/src/hooks/useImageMode.ts +2 -0
  714. package/src/hooks/useInputStatusIcon.tsx +3 -2
  715. package/src/hooks/useKeyboardHint.tsx +1 -1
  716. package/src/hooks/useLongPress.doc.mjs +2 -2
  717. package/src/hooks/useLongPress.ts +32 -122
  718. package/src/hooks/useMenuHover.ts +1 -0
  719. package/src/hooks/useMenuPress.ts +2 -0
  720. package/src/hooks/useOverflow.ts +2 -1
  721. package/src/hooks/usePressFeedback.ts +1 -0
  722. package/src/hooks/useResolvedRequired.ts +3 -0
  723. package/src/hooks/useScrollLock.doc.mjs +51 -12
  724. package/src/hooks/useScrollLock.ts +53 -60
  725. package/src/hooks/useScrollableArea.ts +4 -0
  726. package/src/hooks/useStreamingText.ts +2 -0
  727. package/src/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.ts +46 -0
  728. package/src/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.ts +6 -0
  729. package/src/i18n/generated-english/PowerSearch/formatTokenValue.generated.ts +15 -0
  730. package/src/i18n/generated-english/Resizable/createResizable.generated.ts +14 -0
  731. package/src/i18n/generated-english/Table/plugins/rowExpansion/useTableRowExpansion.generated.ts +3 -1
  732. package/src/i18n/generated-english/Table/plugins/tree/useTableTreeData.generated.ts +3 -1
  733. package/src/i18n/generated-english/TimeInput/TimeWheels.generated.ts +18 -0
  734. package/src/i18n/generated-locales/en.generated.ts +47 -0
  735. package/src/i18n/generated-locales/pseudo.generated.ts +48 -0
  736. package/src/index.ts +13 -0
  737. package/src/internal/indicatorPress.stylex.ts +24 -0
  738. package/src/internal/selectable-card.ts +21 -0
  739. package/src/internal/sheetDraft.ts +2 -2
  740. package/src/keyboard/README.md +197 -0
  741. package/src/keyboard/index.ts +48 -0
  742. package/src/keyboard/keyboardHeight.ts +543 -0
  743. package/src/keyboard/keyboardLayoutGuide.ts +266 -0
  744. package/src/keyboard/keyboardModel.ts +301 -0
  745. package/src/keyboard/rideKeyboard.ts +100 -0
  746. package/src/keyboard/useMobileKeyboard.ts +866 -0
  747. package/src/motion/MEASUREMENTS.md +28 -0
  748. package/src/motion/README.md +12 -5
  749. package/src/motion/android/index.ts +18 -0
  750. package/src/motion/android/keyboard.ts +96 -0
  751. package/src/motion/animatedLayout.ts +323 -60
  752. package/src/motion/animator.ts +66 -37
  753. package/src/motion/frameBlock.ts +16 -0
  754. package/src/motion/progress.ts +155 -0
  755. package/src/motion/reducedMotion.ts +3 -1
  756. package/src/motion/uikit/alert.ts +43 -0
  757. package/src/motion/uikit/datePicker.ts +60 -0
  758. package/src/motion/uikit/index.ts +6 -4
  759. package/src/motion/uikit/picker.ts +116 -0
  760. package/src/privateAttributes/pressGroupItem.stylex.ts +44 -0
  761. package/src/privateAttributes/reducedMotion.stylex.ts +45 -0
  762. package/src/theme/Theme.tsx +37 -3
  763. package/src/theme/generateThemeRules.ts +14 -12
  764. package/src/theme/motionKnobs.ts +4 -3
  765. package/src/theme/themeMotion.ts +17 -2
  766. package/src/theme/tokens.stylex.ts +2 -0
  767. package/src/utils/dateParser.ts +16 -0
  768. package/src/utils/disabledInteraction.ts +23 -2
  769. package/src/utils/focusReturn.ts +38 -31
  770. package/src/utils/index.ts +1 -1
  771. package/src/utils/interactionModality.ts +4 -0
  772. package/src/utils/interactionOverlay.stylex.ts +6 -4
  773. package/src/utils/isFocusDetached.ts +34 -0
  774. package/src/utils/layoutViewport.ts +104 -0
  775. package/src/utils/plainDate.ts +80 -4
  776. package/src/utils/pressFeedback.ts +126 -30
  777. package/src/utils/pressGesture.ts +4 -2
  778. package/src/utils/selectionLock.ts +40 -6
  779. package/src/utils/sharedMutationObserver.ts +2 -1
  780. package/src/utils/timeParser.ts +40 -3
  781. package/src/utils/triggerFocus.ts +80 -0
  782. package/dist/BottomSheet/useMobileKeyboard.d.ts +0 -21
  783. package/dist/BottomSheet/useMobileKeyboard.d.ts.map +0 -1
  784. package/dist/BottomSheet/useMobileKeyboard.js +0 -407
  785. package/dist/Calendar/getStandaloneShortWeekdayNames.d.ts +0 -14
  786. package/dist/Calendar/getStandaloneShortWeekdayNames.d.ts.map +0 -1
  787. package/dist/Calendar/getStandaloneShortWeekdayNames.js +0 -26
  788. package/dist/Calendar/standaloneShortWeekdayNames.generated.d.ts.map +0 -1
  789. package/dist/Layer/usePressPin.d.ts +0 -93
  790. package/dist/Layer/usePressPin.d.ts.map +0 -1
  791. package/dist/Layer/usePressPin.js +0 -363
  792. package/dist/internal/touch-sheet.d.ts +0 -21
  793. package/dist/internal/touch-sheet.d.ts.map +0 -1
  794. package/dist/internal/touch-sheet.js +0 -19
  795. package/src/BottomSheet/useMobileKeyboard.ts +0 -538
  796. package/src/Calendar/getStandaloneShortWeekdayNames.ts +0 -38
  797. package/src/Layer/usePressPin.ts +0 -510
  798. package/src/internal/touch-sheet.ts +0 -21
@@ -0,0 +1,2700 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @file PowerSearchBottomSheet.tsx
7
+ * @input The field's InternalConfig, filters, onChange, the field typeahead
8
+ * source, and the sheet options PowerSearch forwards; BottomSheet,
9
+ * Button, EmptyState, Heading, Icon, IconButton, Indicator, List,
10
+ * RadioList, Text, TextInput, PowerSearchValueEditor, the internal sheet
11
+ * confirmation and search-drag owners, i18n
12
+ * @output Exports PowerSearchBottomSheet — the touch surface of
13
+ * `PowerSearch presentation="bottom-sheet"`: a Filters sheet
14
+ * with editable rows and trailing remove actions, Add filter in its fixed
15
+ * header and Clear all / Done in its fixed footer, an Add filter sheet with
16
+ * grouped field rows or the content search with inline suggestions, and a
17
+ * value step that stages field → operator → value and confirms from its
18
+ * footer
19
+ * @position Internal presentation surface of PowerSearch. Loaded on demand by
20
+ * PowerSearch.tsx so the popover presentation never carries it. The
21
+ * trigger lives in PowerSearch.tsx.
22
+ *
23
+ * The three steps are sibling standalone BottomSheets that stack: each step
24
+ * opens above the sheet that led to it, which stays open beneath as a covered
25
+ * sheet, so no sheet needs a Back action. A dismissal closes only the top
26
+ * sheet and reveals the step beneath; dismissing the bottom sheet ends the
27
+ * flow. A list value's Tokenizer opens its own sheet above the value step, as
28
+ * the top sheet of the stack.
29
+ *
30
+ * The sheets pad their own content (`padding={0}` on BottomSheet). The
31
+ * Filters and Add filter sheets keep their header and footer fixed around a
32
+ * scroll viewport that reaches the sheet edge; its content publishes the
33
+ * padding as container padding so `edge="bleed"` lists run edge to edge with
34
+ * row text on the header's inset. The sheets are pinned tall: the field list
35
+ * resizes as it is searched and the editor changes with the operator, and
36
+ * only a fully expanded tall sheet gives mobile-keyboard accommodation.
37
+ *
38
+ * SYNC: When modified, update:
39
+ * - /packages/core/src/PowerSearch/PowerSearch.tsx (the trigger and the lazy host)
40
+ * - /docs/specs/components/PowerSearch/PowerSearch.spec.md (FR10–FR21, AR4–AR6, PR5)
41
+ */
42
+
43
+ import React, {
44
+ useCallback,
45
+ useEffect,
46
+ useId,
47
+ useLayoutEffect,
48
+ useMemo,
49
+ useRef,
50
+ useState,
51
+ type ReactNode,
52
+ type RefObject,
53
+ type SVGProps,
54
+ } from 'react';
55
+ import {flushSync} from 'react-dom';
56
+ import * as stylex from '@stylexjs/stylex';
57
+ import {BottomSheet} from '../BottomSheet/BottomSheet';
58
+ import {Button} from '../Button/Button';
59
+ import {EmptyState} from '../EmptyState/EmptyState';
60
+ import {Heading} from '../Heading/Heading';
61
+ import {Icon} from '../Icon/Icon';
62
+ import {IconButton} from '../IconButton/IconButton';
63
+ import {CheckboxIndicator} from '../Indicator/CheckboxIndicator';
64
+ import {RadioIndicator} from '../Indicator/RadioIndicator';
65
+ import {focusOutlineStyles} from '../utils/focusOutline.stylex';
66
+ import {isRenderable} from '../utils/isRenderable';
67
+ import {containerPaddingInlineVarStyles} from '../Layout/padding.stylex';
68
+ import {List} from '../List/List';
69
+ import {ListItem} from '../List/ListItem';
70
+ import {RadioList} from '../RadioList/RadioList';
71
+ import {RadioListItem} from '../RadioList/RadioListItem';
72
+ import {Text} from '../Text/Text';
73
+ import {TextInput} from '../TextInput/TextInput';
74
+ import type {SearchSource} from '../Typeahead/types';
75
+ import {useAnnounce, type AnnounceFn} from '../hooks/useAnnounce';
76
+ import type {TranslatorFn} from '../i18n';
77
+ import {useListFormatter} from '../i18n/useListFormatter';
78
+ import {useLocale} from '../i18n/useLocale';
79
+ import {SheetConfirmation} from '../internal/SheetConfirmation';
80
+ import {useDismissSearchOnTouchDrag} from '../internal/useDismissSearchOnTouchDrag';
81
+ import {
82
+ colorVars,
83
+ fontWeightVars,
84
+ radiusVars,
85
+ spacingVars,
86
+ } from '../theme/tokens.stylex';
87
+ import {isImeKeyEvent} from '../utils/ime';
88
+ import {rtlStyles} from '../utils/rtlStyles';
89
+ import {formatTokenValueText} from './formatTokenValue';
90
+
91
+ function resolveRelativeDateLabel(
92
+ operatorValue: OperatorValue & {type: 'date_relative'},
93
+ value: string,
94
+ t: TranslatorFn,
95
+ buildRelativeDateOptions: PowerSearchSheetEditors['buildRelativeDateOptions'],
96
+ ): string {
97
+ return (
98
+ buildRelativeDateOptions(operatorValue, t).find(
99
+ option => option.value === value,
100
+ )?.label ?? value
101
+ );
102
+ }
103
+
104
+ // A placeholder the Filters row formats `labelValue` with, then splits on, so
105
+ // the value segment can render bold inside the catalog's ordering. A private
106
+ // use code point: never part of a label or value.
107
+ const ROW_VALUE_SLOT = '\uE000';
108
+ import type {
109
+ buildRelativeDateOptions,
110
+ PowerSearchValueEditor,
111
+ } from './PowerSearchValueEditor';
112
+ import type {NestedEditor} from './PowerSearchEditPopover';
113
+ import {useAnnounceRenderedText} from '../hooks/useAnnounceRenderedText';
114
+ import {useInternalListFocus} from '../hooks/useListFocus';
115
+ import {useMergedRefs} from '../hooks/useMergedRefs';
116
+ import {groupItems} from '../utils/groupItems';
117
+ import {
118
+ createSheetSuggestionSource,
119
+ fieldMatchesQuery,
120
+ createFilterIdentities,
121
+ filterSignature,
122
+ isSupportedOperator,
123
+ nearestEditableIndex,
124
+ resolveFilterIdentityIndex,
125
+ } from './powerSearchSheetUtils';
126
+ import {resolveOperatorLabel} from './resolveOperatorLabel';
127
+ import type {InternalConfig} from './useInternalConfig';
128
+ import type {
129
+ FilterValue,
130
+ OperatorValue,
131
+ PartialFilter,
132
+ PowerSearchChangeType,
133
+ PowerSearchComponents,
134
+ PowerSearchConfig,
135
+ PowerSearchField,
136
+ PowerSearchFilter,
137
+ PowerSearchItem,
138
+ PowerSearchOperator,
139
+ } from './types';
140
+ import {
141
+ registerEnglishFallback,
142
+ useComponentTranslator,
143
+ } from '../i18n/useComponentTranslator';
144
+ import english from '../i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated';
145
+
146
+ registerEnglishFallback(english);
147
+
148
+ // =============================================================================
149
+ // Props
150
+ // =============================================================================
151
+
152
+ /**
153
+ * The popover presentation's editors, which the value step reuses. They come
154
+ * from PowerSearch.tsx, whose module graph already loads them for the popover
155
+ * presentation. Imported here, they and every component they reach would join
156
+ * this lazily imported graph, whose modules must import Core directly and
157
+ * never through a barrel.
158
+ */
159
+ export interface PowerSearchSheetEditors {
160
+ NestedEditor: typeof NestedEditor;
161
+ PowerSearchValueEditor: typeof PowerSearchValueEditor;
162
+ buildRelativeDateOptions: typeof buildRelativeDateOptions;
163
+ }
164
+
165
+ export interface PowerSearchBottomSheetProps {
166
+ /** Whether the flow is open; the trigger in PowerSearch.tsx owns it. */
167
+ isOpen: boolean;
168
+ onOpenChange: (isOpen: boolean) => void;
169
+ /**
170
+ * The trigger: where focus returns when the flow closes, whichever step
171
+ * closed it and however it opened (a tap on a token included).
172
+ */
173
+ finalFocusRef: RefObject<HTMLElement | null>;
174
+ /**
175
+ * The field's formatted result count, announced from inside the open
176
+ * sheet's dialog when it changes while the flow is open. `useAnnounce`
177
+ * routes a message by where its caller is, so the owner above the sheets
178
+ * cannot reach the dialog's region.
179
+ */
180
+ resultCountText?: string | null;
181
+ config: InternalConfig;
182
+ /** The caller's config, handed to Editor overrides as they expect it. */
183
+ configProp: PowerSearchConfig;
184
+ /** The committed filters; the draft the sheet edits starts from them. */
185
+ filters: ReadonlyArray<PowerSearchFilter>;
186
+ /**
187
+ * The field's `onChange`. Done replays the draft's edits through it, in
188
+ * order, onto the field's latest filters, each call carrying that list
189
+ * with the edit applied; nothing is reported before Done, and nothing when
190
+ * the field is read-only or disabled at Done.
191
+ */
192
+ onChange: (
193
+ filters: ReadonlyArray<PowerSearchFilter>,
194
+ changeType: PowerSearchChangeType,
195
+ index: number,
196
+ ) => void;
197
+ /** The field typeahead source; the content search lists its suggestions. */
198
+ searchSource: SearchSource<PowerSearchItem>;
199
+ /** Placeholder of the content search. */
200
+ placeholder: string;
201
+ isReadOnly: boolean;
202
+ isDisabled: boolean;
203
+ hasClear: boolean;
204
+ maxOperatorMenuItems?: number;
205
+ /** The zone a date-only value is read and written in; see PowerSearch. */
206
+ timezoneID?: string;
207
+ maxSearchResults: number;
208
+ /** The caller's confirm label; the step picks a default per mode. */
209
+ saveButtonLabel?: string;
210
+ components?: PowerSearchComponents;
211
+ editors: PowerSearchSheetEditors;
212
+ }
213
+
214
+ // =============================================================================
215
+ // Styles
216
+ // =============================================================================
217
+
218
+ /** One edit of the draft: the draft before and after it, and its type and index in the draft; Done replays it onto the field's latest filters. */
219
+ interface DraftEdit {
220
+ before: ReadonlyArray<PowerSearchFilter>;
221
+ after: ReadonlyArray<PowerSearchFilter>;
222
+ changeType: PowerSearchChangeType;
223
+ index: number;
224
+ }
225
+
226
+ // Whether two filter lists hold the same filters in the same order, by the
227
+ // key-order-insensitive signature the sheet matches filters with.
228
+ function hasSameFilters(
229
+ a: ReadonlyArray<PowerSearchFilter>,
230
+ b: ReadonlyArray<PowerSearchFilter>,
231
+ ): boolean {
232
+ return (
233
+ a.length === b.length &&
234
+ a.every(
235
+ (filter, index) =>
236
+ b[index] != null &&
237
+ filterSignature(filter) === filterSignature(b[index]),
238
+ )
239
+ );
240
+ }
241
+
242
+ // The filters `before` holds that `after` does not, as a multiset by
243
+ // signature, in `before` order.
244
+ function removedFilters(
245
+ before: ReadonlyArray<PowerSearchFilter>,
246
+ after: ReadonlyArray<PowerSearchFilter>,
247
+ ): PowerSearchFilter[] {
248
+ const remaining = new Map<string, number>();
249
+ for (const filter of after) {
250
+ const signature = filterSignature(filter);
251
+ remaining.set(signature, (remaining.get(signature) ?? 0) + 1);
252
+ }
253
+ return before.filter(filter => {
254
+ const signature = filterSignature(filter);
255
+ const count = remaining.get(signature) ?? 0;
256
+ if (count > 0) {
257
+ remaining.set(signature, count - 1);
258
+ return false;
259
+ }
260
+ return true;
261
+ });
262
+ }
263
+
264
+ /**
265
+ * Replays the draft's edits onto `base`, the field's latest filters, and
266
+ * reports each through `report` with the list after it. An add appends; an
267
+ * edit replaces the first filter matching the one it edited; a removal drops
268
+ * the filters it removed, by signature. An edit or removal whose target is
269
+ * not in the base list is skipped: the parent removed it meanwhile.
270
+ */
271
+ export function replayDraftEdits(
272
+ base: ReadonlyArray<PowerSearchFilter>,
273
+ edits: ReadonlyArray<DraftEdit>,
274
+ report: (
275
+ filters: ReadonlyArray<PowerSearchFilter>,
276
+ changeType: PowerSearchChangeType,
277
+ index: number,
278
+ ) => void,
279
+ ): ReadonlyArray<PowerSearchFilter> {
280
+ let current = base;
281
+ for (const edit of edits) {
282
+ if (edit.changeType === 'add') {
283
+ const added = edit.after[edit.index];
284
+ if (added == null) {
285
+ continue;
286
+ }
287
+ current = [...current, added];
288
+ report(current, 'add', current.length - 1);
289
+ } else if (edit.changeType === 'edit') {
290
+ const original = edit.before[edit.index];
291
+ const updated = edit.after[edit.index];
292
+ if (original == null || updated == null) {
293
+ continue;
294
+ }
295
+ const signature = filterSignature(original);
296
+ const index = current.findIndex(
297
+ filter => filterSignature(filter) === signature,
298
+ );
299
+ if (index === -1) {
300
+ continue;
301
+ }
302
+ current = current.map((filter, i) => (i === index ? updated : filter));
303
+ report(current, 'edit', index);
304
+ } else {
305
+ const removed = removedFilters(edit.before, edit.after).map(
306
+ filterSignature,
307
+ );
308
+ const indexes: number[] = [];
309
+ for (const signature of removed) {
310
+ const index = current.findIndex(
311
+ (filter, i) =>
312
+ !indexes.includes(i) && filterSignature(filter) === signature,
313
+ );
314
+ if (index !== -1) {
315
+ indexes.push(index);
316
+ }
317
+ }
318
+ if (indexes.length === 0) {
319
+ continue;
320
+ }
321
+ current = current.filter((_, i) => !indexes.includes(i));
322
+ report(current, 'remove', Math.min(...indexes));
323
+ }
324
+ }
325
+ return current;
326
+ }
327
+
328
+ // The trailing plus a field row shows when choosing it adds the filter at
329
+ // once, and the Add filter actions' glyph. Core's default icon set has no plus.
330
+ function PlusIcon(props: SVGProps<SVGSVGElement>) {
331
+ return (
332
+ <svg
333
+ viewBox="0 0 24 24"
334
+ fill="none"
335
+ stroke="currentColor"
336
+ strokeWidth={1.5}
337
+ strokeLinecap="round"
338
+ strokeLinejoin="round"
339
+ {...props}>
340
+ <path d="M5 12h14" />
341
+ <path d="M12 5v14" />
342
+ </svg>
343
+ );
344
+ }
345
+
346
+ const styles = stylex.create({
347
+ // 44px touch targets for every sheet action, without resizing inputs.
348
+ touchAction: {
349
+ minHeight: 44,
350
+ },
351
+ // A sheet action drawn smaller than 44px keeps its drawn size and grows
352
+ // only its hit area to 44px, under a coarse pointer. The custom properties
353
+ // carry the media condition because StyleX allows plain values inside a
354
+ // pseudo-element. On a fine pointer the overlay is not generated, so it
355
+ // never takes hover from the action's own content.
356
+ touchHitArea: {
357
+ '--_power-search-sheet-hit-inset': {
358
+ default: '0px',
359
+ '@media (pointer: coarse)': 'min(0px, calc((100% - 44px) / 2))',
360
+ },
361
+ '--_power-search-sheet-hit-content': {
362
+ default: 'none',
363
+ '@media (pointer: coarse)': '""',
364
+ },
365
+ '::after': {
366
+ content: 'var(--_power-search-sheet-hit-content)',
367
+ position: 'absolute',
368
+ inset: 'var(--_power-search-sheet-hit-inset)',
369
+ },
370
+ },
371
+ // Scopes the sticky header's and footer's layer to this sheet's content:
372
+ // the List rows are `position: relative` and come after the header, so
373
+ // without a layer of its own the header is painted under the rows that
374
+ // scroll beneath it. Isolating the content keeps that z-index inside it, so
375
+ // the sheet's grab handle (z-index 1 on the panel, outside this wrapper)
376
+ // still paints above.
377
+ sheet: {
378
+ display: 'flex',
379
+ flexDirection: 'column',
380
+ minHeight: '100%',
381
+ isolation: 'isolate',
382
+ },
383
+ // The Filters and Add filter sheets fill the panel and scroll only their
384
+ // viewport, so the header and footer stay fixed.
385
+ sheetWithFixedFooter: {
386
+ height: '100%',
387
+ overflow: 'hidden',
388
+ },
389
+ header: {
390
+ position: 'sticky',
391
+ insetBlockStart: 0,
392
+ // Above the rows that scroll under it, within the isolated sheet content.
393
+ zIndex: 1,
394
+ display: 'flex',
395
+ flexDirection: 'column',
396
+ gap: spacingVars['--spacing-3'],
397
+ // Clears the sheet's floating grab handle.
398
+ paddingBlockStart: spacingVars['--spacing-6'],
399
+ paddingBlockEnd: spacingVars['--spacing-3'],
400
+ paddingInline: spacingVars['--spacing-4'],
401
+ backgroundColor: colorVars['--color-background-surface'],
402
+ },
403
+ headerRow: {
404
+ display: 'flex',
405
+ alignItems: 'center',
406
+ gap: spacingVars['--spacing-2'],
407
+ },
408
+ headerText: {
409
+ minWidth: 0,
410
+ flexGrow: 1,
411
+ display: 'flex',
412
+ flexDirection: 'column',
413
+ },
414
+ // The body pads the sheet's content and publishes that inline padding as
415
+ // the container padding its lists read: with `edge="bleed"` their rows run
416
+ // edge to edge (full-bleed dividers) while row text keeps this inset, so
417
+ // row text, group headings and the sheet title share one edge.
418
+ body: {
419
+ flexGrow: 1,
420
+ display: 'flex',
421
+ flexDirection: 'column',
422
+ gap: spacingVars['--spacing-4'],
423
+ paddingInline: spacingVars['--spacing-4'],
424
+ paddingBlockEnd: spacingVars['--spacing-4'],
425
+ },
426
+ // The viewport reaches the sheet edge, so its scrollbar does too; the
427
+ // content inside it carries the body's padding.
428
+ scrollViewport: {
429
+ flexGrow: 1,
430
+ minHeight: 0,
431
+ overflowY: 'auto',
432
+ overscrollBehaviorY: 'contain',
433
+ },
434
+ scrollContent: {
435
+ minHeight: '100%',
436
+ display: 'flex',
437
+ flexDirection: 'column',
438
+ gap: spacingVars['--spacing-4'],
439
+ paddingInline: spacingVars['--spacing-4'],
440
+ paddingBlockEnd: spacingVars['--spacing-4'],
441
+ },
442
+ footer: {
443
+ position: 'sticky',
444
+ insetBlockEnd: 0,
445
+ zIndex: 1,
446
+ display: 'flex',
447
+ alignItems: 'center',
448
+ justifyContent: 'space-between',
449
+ gap: spacingVars['--spacing-2'],
450
+ paddingBlock: spacingVars['--spacing-3'],
451
+ paddingInline: spacingVars['--spacing-4'],
452
+ backgroundColor: colorVars['--color-background-surface'],
453
+ },
454
+ fixedFooter: {
455
+ position: 'relative',
456
+ insetBlockEnd: 'auto',
457
+ flexShrink: 0,
458
+ },
459
+ footerEqualAction: {
460
+ flexGrow: 1,
461
+ flexBasis: 0,
462
+ minWidth: 0,
463
+ minHeight: 44,
464
+ },
465
+ footerSoleAction: {
466
+ flexGrow: 1,
467
+ },
468
+ empty: {
469
+ paddingBlock: spacingVars['--spacing-6'],
470
+ textAlign: 'center',
471
+ },
472
+ emptyState: {
473
+ flexGrow: 1,
474
+ display: 'flex',
475
+ alignItems: 'center',
476
+ justifyContent: 'center',
477
+ },
478
+ // With more than one section in the value step, each section is a muted
479
+ // container. Its inline padding is published as container padding, so
480
+ // choice rows run edge to edge inside the section.
481
+ controlSection: {
482
+ padding: spacingVars['--spacing-3'],
483
+ borderRadius: radiusVars['--radius-container'],
484
+ backgroundColor: colorVars['--color-background-muted'],
485
+ },
486
+ // The operator radios put their indicator at the row's end, as the choice
487
+ // rows do.
488
+ trailingControlRow: {
489
+ flexDirection: 'row-reverse',
490
+ },
491
+ // The built-in nested editor's sub-filter rows collapse from one line to
492
+ // wrapped lines under a container query on the popover's own container;
493
+ // the sheet renders no such container, so the editor's tree root is the
494
+ // query container here, and at phone widths the rows wrap instead of
495
+ // running past the sheet's edge.
496
+ nestedEditorContainer: {
497
+ containerType: 'inline-size',
498
+ overflow: 'hidden',
499
+ },
500
+ rowValue: {
501
+ fontWeight: fontWeightVars['--font-weight-bold'],
502
+ },
503
+ // Choice rows run edge to edge on the inset of the surface that holds them,
504
+ // the body or a muted section, with no dividers: the group reaches into
505
+ // that padding and each row pads back out to it.
506
+ choiceList: {
507
+ display: 'flex',
508
+ flexDirection: 'column',
509
+ marginInlineStart: 'calc(-1 * var(--container-padding-inline-start, 0px))',
510
+ marginInlineEnd: 'calc(-1 * var(--container-padding-inline-end, 0px))',
511
+ width:
512
+ 'calc(100% + var(--container-padding-inline-start, 0px) + var(--container-padding-inline-end, 0px))',
513
+ },
514
+ choiceRow: {
515
+ display: 'flex',
516
+ alignItems: 'center',
517
+ gap: spacingVars['--spacing-3'],
518
+ width: '100%',
519
+ minHeight: 44,
520
+ paddingBlock: spacingVars['--spacing-3'],
521
+ paddingInlineStart: 'var(--container-padding-inline-start, 0px)',
522
+ paddingInlineEnd: 'var(--container-padding-inline-end, 0px)',
523
+ borderWidth: 0,
524
+ borderRadius: 0,
525
+ backgroundColor: 'transparent',
526
+ color: colorVars['--color-text-primary'],
527
+ fontFamily: 'inherit',
528
+ textAlign: 'start',
529
+ cursor: {
530
+ default: 'pointer',
531
+ ':is([aria-disabled="true"])': 'default',
532
+ },
533
+ },
534
+ // An aria-disabled row gets no system disabled paint in forced colors;
535
+ // GrayText is the platform's disabled affordance there.
536
+ choiceRowDisabled: {
537
+ color: {
538
+ default: colorVars['--color-text-secondary'],
539
+ '@media (forced-colors: active)': 'GrayText',
540
+ },
541
+ },
542
+ choiceIcon: {
543
+ display: 'inline-flex',
544
+ flexShrink: 0,
545
+ },
546
+ choiceLabel: {
547
+ flexGrow: 1,
548
+ minWidth: 0,
549
+ },
550
+ editorInput: {
551
+ paddingBlockStart: spacingVars['--spacing-1'],
552
+ },
553
+ });
554
+
555
+ // =============================================================================
556
+ // Draft state
557
+ // =============================================================================
558
+
559
+ type SheetStep = 'manage' | 'fields' | 'value';
560
+
561
+ type PendingSheetFocus =
562
+ | {readonly type: 'manager-add'}
563
+ | {readonly type: 'content-search'}
564
+ | {
565
+ readonly type: 'manager-filter';
566
+ readonly sourceFilter: PowerSearchFilter;
567
+ readonly sourceSignature: string;
568
+ readonly preferredIndex: number;
569
+ /**
570
+ * After a removal, focus goes to the row's trailing remove action, so a
571
+ * run of removals needs no re-aiming; otherwise to the row.
572
+ */
573
+ readonly part?: 'remove';
574
+ }
575
+ | {readonly type: 'field'; readonly fieldKey: string};
576
+
577
+ interface FilterDraft {
578
+ readonly mode: 'create' | 'edit';
579
+ /**
580
+ * Counts the value steps opened in this flow. Part of the editor's `key`:
581
+ * the step's sheet stays mounted between openings, and an editor that
582
+ * reads its filter on mount (the built-in nested editor, a caller's
583
+ * override) must remount per opened filter, not per field and operator —
584
+ * two groups on one field would otherwise share one editor's state.
585
+ */
586
+ readonly generation: number;
587
+ /** Control within the Add filter sheet that launched this draft. */
588
+ readonly returnFocus?: 'field' | 'content-search';
589
+ /** Index in `filters` when edit mode opened. */
590
+ readonly filterIndex?: number;
591
+ /** Original controlled filter identity, used to follow immutable reorders. */
592
+ readonly sourceFilter?: PowerSearchFilter;
593
+ /** Structural snapshot, used when controlled parents clone their values. */
594
+ readonly sourceSignature?: string;
595
+ readonly field: string;
596
+ readonly operator?: string;
597
+ readonly value?: FilterValue;
598
+ }
599
+
600
+ function resolveDraftFilterIndex(
601
+ filters: ReadonlyArray<PowerSearchFilter>,
602
+ draft: FilterDraft,
603
+ ): number | null {
604
+ if (
605
+ draft.mode !== 'edit' ||
606
+ draft.filterIndex == null ||
607
+ draft.sourceFilter == null ||
608
+ draft.sourceSignature == null
609
+ ) {
610
+ return null;
611
+ }
612
+ return resolveFilterIdentityIndex(
613
+ filters,
614
+ draft.sourceFilter,
615
+ draft.sourceSignature,
616
+ draft.filterIndex,
617
+ );
618
+ }
619
+
620
+ // Below this many fields a search box is noise: the whole list is on screen.
621
+ const SEARCHABLE_FIELD_COUNT = 8;
622
+ // Empty-query browsing keeps the popover presentation's safety ceiling.
623
+ const MAX_BROWSE_MENU_ITEMS = 1000;
624
+
625
+ // =============================================================================
626
+ // Choice rows (enum, enum_list, date_relative)
627
+ // =============================================================================
628
+
629
+ /**
630
+ * Rendered inside a step's BottomSheet so that `useAnnounce` resolves the
631
+ * sheet's dialog as the enclosing modal; publishes that
632
+ * dialog's `announce` to the flow above through `onAnnounceChange` while
633
+ * mounted. Renders nothing.
634
+ */
635
+ function SheetAnnouncer({
636
+ onAnnounceChange,
637
+ }: {
638
+ onAnnounceChange: (announce: AnnounceFn | null) => void;
639
+ }) {
640
+ const announce = useAnnounce();
641
+ // Hands this dialog's announce function up; the cleanup withdraws it when
642
+ // the step changes or the flow closes.
643
+ useEffect(() => {
644
+ onAnnounceChange(announce);
645
+ return () => {
646
+ onAnnounceChange(null);
647
+ };
648
+ }, [announce, onAnnounceChange]);
649
+ return null;
650
+ }
651
+
652
+ /**
653
+ * The value step's "This filter is no longer available" message, rendered
654
+ * inside the step's dialog. The shared own-content module reads the rendered
655
+ * text and speaks it once per opened filter while the step is the open one.
656
+ * Called from inside the sheet's dialog, `useAnnounce` routes it into the
657
+ * dialog. The message is plain text, not an EmptyState, so nothing announces
658
+ * it a second time.
659
+ */
660
+ function SheetEmptyMessage({
661
+ id,
662
+ message,
663
+ occasion,
664
+ isShown,
665
+ }: {
666
+ id?: string;
667
+ message: string;
668
+ occasion: string;
669
+ /**
670
+ * Whether the message's step is the open one. A sheet beneath another, or
671
+ * closed with its body retained, speaks nothing, and the hook re-arms so
672
+ * the same occasion is spoken again when the step reopens on it.
673
+ */
674
+ isShown: boolean;
675
+ }) {
676
+ const ref = useRef<HTMLDivElement>(null);
677
+ useAnnounceRenderedText(ref, isShown, occasion);
678
+ return (
679
+ <div ref={ref} id={id} {...stylex.props(styles.empty)}>
680
+ <Text type="supporting" color="secondary">
681
+ {message}
682
+ </Text>
683
+ </div>
684
+ );
685
+ }
686
+
687
+ interface ChoiceItem {
688
+ readonly value: string;
689
+ readonly label: string;
690
+ readonly icon?: ReactNode;
691
+ }
692
+
693
+ // A radio group's one tab stop: the checked row, else the first.
694
+ function radioTabStopOrder(list: HTMLElement): ReadonlyArray<HTMLElement> {
695
+ const rows = Array.from(list.querySelectorAll<HTMLElement>('[role="radio"]'));
696
+ const checked = rows.find(row => row.getAttribute('aria-checked') === 'true');
697
+ return checked == null
698
+ ? rows
699
+ : [checked, ...rows.filter(row => row !== checked)];
700
+ }
701
+
702
+ /**
703
+ * Closed vocabularies render as full-width rows with a trailing check instead
704
+ * of the popover presentation's Selector or Tokenizer: a dropdown layer inside
705
+ * a sheet stacks a second overlay on a surface the person is already inside.
706
+ */
707
+ function ChoiceRows({
708
+ items,
709
+ selected,
710
+ isDisabled,
711
+ isMultiple,
712
+ label,
713
+ onToggle,
714
+ }: {
715
+ items: ReadonlyArray<ChoiceItem>;
716
+ selected: ReadonlySet<string>;
717
+ isDisabled?: boolean;
718
+ /** `enum_list`: checkbox rows that toggle. Otherwise radio rows. */
719
+ isMultiple: boolean;
720
+ /** The group's accessible name: the field label. */
721
+ label: string;
722
+ onToggle: (value: string, isSelected: boolean) => void;
723
+ }) {
724
+ // The rows carry their state as state, not as a name suffix: `radio` rows
725
+ // in a `radiogroup` for a single choice, `checkbox` rows in a `group` for
726
+ // `enum_list`, each with `aria-checked`, as the Tokenizer's sheet rows do.
727
+ // Disabled rows stay focusable with `aria-disabled`.
728
+ //
729
+ // Keyboard: a radio group is one tab stop — the checked row, else the
730
+ // first — and the arrow keys move focus and check the row they land on,
731
+ // wrapping; Home and End move to and check the first and last row. The
732
+ // shared list focus owns the tab stop and the moves; a row that takes focus
733
+ // from an arrow, Home or End is checked here. Space and Enter check the
734
+ // focused radio row and toggle a checkbox row: each row is a native
735
+ // `button`, whose activation fires `onClick` for both keys. A checkbox row
736
+ // is its own tab stop.
737
+ const isKeyMoveRef = useRef(false);
738
+ const {listRef, handleKeyDown, handleFocus} =
739
+ useInternalListFocus<HTMLDivElement>({
740
+ itemSelector: '[role="radio"]',
741
+ orientation: 'both',
742
+ hasRovingTabIndex: !isMultiple,
743
+ tabStopOrder: radioTabStopOrder,
744
+ });
745
+ const handleRadioKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
746
+ isKeyMoveRef.current = true;
747
+ try {
748
+ handleKeyDown(event);
749
+ } finally {
750
+ isKeyMoveRef.current = false;
751
+ }
752
+ };
753
+ const handleRadioFocus = (event: React.FocusEvent<HTMLDivElement>) => {
754
+ handleFocus(event);
755
+ if (!isKeyMoveRef.current || isDisabled) {
756
+ return;
757
+ }
758
+ const value = (event.target as HTMLElement).closest<HTMLElement>(
759
+ '[role="radio"]',
760
+ )?.dataset.value;
761
+ if (value != null && !selected.has(value)) {
762
+ onToggle(value, false);
763
+ }
764
+ };
765
+ return (
766
+ <div
767
+ ref={listRef}
768
+ role={isMultiple ? 'group' : 'radiogroup'}
769
+ aria-label={label}
770
+ onKeyDown={isMultiple ? undefined : handleRadioKeyDown}
771
+ onFocus={isMultiple ? undefined : handleRadioFocus}
772
+ {...stylex.props(styles.choiceList)}>
773
+ {items.map(item => {
774
+ const isSelected = selected.has(item.value);
775
+ return (
776
+ <button
777
+ key={item.value}
778
+ type="button"
779
+ role={isMultiple ? 'checkbox' : 'radio'}
780
+ aria-checked={isSelected}
781
+ aria-disabled={isDisabled || undefined}
782
+ data-value={item.value}
783
+ onClick={() => {
784
+ if (!isDisabled) {
785
+ onToggle(item.value, isSelected);
786
+ }
787
+ }}
788
+ {...stylex.props(
789
+ focusOutlineStyles.focusVisible,
790
+ styles.choiceRow,
791
+ isDisabled && styles.choiceRowDisabled,
792
+ )}>
793
+ {isRenderable(item.icon) && (
794
+ <span aria-hidden="true" {...stylex.props(styles.choiceIcon)}>
795
+ {item.icon}
796
+ </span>
797
+ )}
798
+ <Text
799
+ type="body"
800
+ color={isDisabled ? 'inherit' : undefined}
801
+ xstyle={styles.choiceLabel}>
802
+ {item.label}
803
+ </Text>
804
+ {isMultiple ? (
805
+ <CheckboxIndicator
806
+ state={isSelected ? 'checked' : 'unchecked'}
807
+ size="md"
808
+ isDisabled={isDisabled}
809
+ />
810
+ ) : (
811
+ <RadioIndicator
812
+ state={isSelected ? 'checked' : 'unchecked'}
813
+ size="md"
814
+ isDisabled={isDisabled}
815
+ />
816
+ )}
817
+ </button>
818
+ );
819
+ })}
820
+ </div>
821
+ );
822
+ }
823
+
824
+ /**
825
+ * The value control for one filter inside the value step. Closed vocabularies
826
+ * are rows here; every other type is the popover presentation's own editor in
827
+ * its sheet presentation.
828
+ */
829
+ function SheetValueEditor({
830
+ operatorValue,
831
+ filterValue,
832
+ onChange,
833
+ onUnstage,
834
+ config,
835
+ fieldLabel,
836
+ isDisabled,
837
+ maxMenuItems,
838
+ timezoneID,
839
+ editors,
840
+ }: {
841
+ operatorValue: OperatorValue;
842
+ filterValue: FilterValue | undefined;
843
+ onChange: (value: FilterValue) => void;
844
+ onUnstage: () => void;
845
+ config: InternalConfig;
846
+ fieldLabel: string;
847
+ isDisabled: boolean;
848
+ maxMenuItems?: number;
849
+ timezoneID?: string;
850
+ editors: PowerSearchSheetEditors;
851
+ }) {
852
+ const {buildRelativeDateOptions, PowerSearchValueEditor} = editors;
853
+ const t = useComponentTranslator();
854
+ const selectedValues = useMemo<ReadonlySet<string>>(() => {
855
+ if (filterValue?.type === 'enum' || filterValue?.type === 'date_relative') {
856
+ return new Set([filterValue.value]);
857
+ }
858
+ if (filterValue?.type === 'enum_list') {
859
+ return new Set(filterValue.value);
860
+ }
861
+ return new Set();
862
+ }, [filterValue]);
863
+
864
+ switch (operatorValue.type) {
865
+ case 'empty':
866
+ case 'nested':
867
+ return null;
868
+ case 'enum':
869
+ return (
870
+ <ChoiceRows
871
+ items={operatorValue.values}
872
+ selected={selectedValues}
873
+ isDisabled={isDisabled}
874
+ isMultiple={false}
875
+ label={fieldLabel}
876
+ onToggle={value => onChange({type: 'enum', value})}
877
+ />
878
+ );
879
+ case 'enum_list':
880
+ return (
881
+ <ChoiceRows
882
+ items={operatorValue.values}
883
+ selected={selectedValues}
884
+ isDisabled={isDisabled}
885
+ isMultiple
886
+ label={fieldLabel}
887
+ onToggle={(value, isSelected) => {
888
+ const existing =
889
+ filterValue?.type === 'enum_list' ? filterValue.value : [];
890
+ onChange({
891
+ type: 'enum_list',
892
+ value: isSelected
893
+ ? existing.filter(v => v !== value)
894
+ : [...existing, value],
895
+ });
896
+ }}
897
+ />
898
+ );
899
+ case 'date_relative':
900
+ return (
901
+ <ChoiceRows
902
+ items={buildRelativeDateOptions(operatorValue, t)}
903
+ selected={selectedValues}
904
+ isDisabled={isDisabled}
905
+ isMultiple={false}
906
+ label={fieldLabel}
907
+ onToggle={value => onChange({type: 'date_relative', value})}
908
+ />
909
+ );
910
+ case 'string':
911
+ case 'string_list':
912
+ case 'integer':
913
+ case 'float':
914
+ case 'time':
915
+ case 'date_absolute':
916
+ case 'date_range':
917
+ case 'entity_list':
918
+ case 'custom':
919
+ return (
920
+ <div {...stylex.props(styles.editorInput)}>
921
+ <PowerSearchValueEditor
922
+ operatorValue={operatorValue}
923
+ filterValue={filterValue}
924
+ onChange={onChange}
925
+ onUnstage={onUnstage}
926
+ config={config}
927
+ maxMenuItems={maxMenuItems}
928
+ isDisabled={isDisabled}
929
+ presentation="bottom-sheet"
930
+ fieldLabel={fieldLabel}
931
+ timezoneID={timezoneID}
932
+ />
933
+ </div>
934
+ );
935
+ }
936
+ }
937
+
938
+ // =============================================================================
939
+ // Component
940
+ // =============================================================================
941
+
942
+ /**
943
+ * The sheet flow of PowerSearch's touch presentation: Filters, Add filter,
944
+ * and the value step, as standalone sheets that stack, each open beneath the
945
+ * step it led to.
946
+ */
947
+ export function PowerSearchBottomSheet({
948
+ isOpen,
949
+ onOpenChange,
950
+ finalFocusRef,
951
+ resultCountText,
952
+ config,
953
+ configProp,
954
+ filters: committedFilters,
955
+ onChange: onCommit,
956
+ searchSource,
957
+ placeholder,
958
+ isReadOnly,
959
+ isDisabled,
960
+ hasClear,
961
+ maxOperatorMenuItems,
962
+ timezoneID,
963
+ maxSearchResults,
964
+ saveButtonLabel: saveButtonLabelFromProps,
965
+ components: componentOverrides,
966
+ editors,
967
+ }: PowerSearchBottomSheetProps) {
968
+ const {NestedEditor} = editors;
969
+ const t = useComponentTranslator();
970
+ const locale = useLocale();
971
+ const formatList = useListFormatter();
972
+ const isInteractive = !isDisabled && !isReadOnly;
973
+
974
+ // ---- draft ----
975
+ // One open flow edits one draft of the filter list; `onChange` waits for
976
+ // Done, and a dismissal with a changed draft asks first.
977
+ const [filtersAtOpen, setFiltersAtOpen] = useState(() => committedFilters);
978
+ const [filters, setFilters] = useState(() => committedFilters);
979
+ // The draft as of the last edit, for the edit log's `before` lists.
980
+ const draftRef = useRef(filters);
981
+ const draftEditsRef = useRef<DraftEdit[]>([]);
982
+ const onChange = useCallback(
983
+ (
984
+ next: ReadonlyArray<PowerSearchFilter>,
985
+ changeType: PowerSearchChangeType,
986
+ index: number,
987
+ ) => {
988
+ draftEditsRef.current.push({
989
+ before: draftRef.current,
990
+ after: next,
991
+ changeType,
992
+ index,
993
+ });
994
+ draftRef.current = next;
995
+ setFilters(next);
996
+ },
997
+ [],
998
+ );
999
+ const isDraftDirty = !hasSameFilters(filtersAtOpen, filters);
1000
+ const [isDiscardConfirmationOpen, setIsDiscardConfirmationOpen] =
1001
+ useState(false);
1002
+
1003
+ const contentSearchFieldKey = config.config.contentSearchFieldKey;
1004
+ const contentSearchOperator =
1005
+ contentSearchFieldKey == null
1006
+ ? undefined
1007
+ : config.getDefaultOperator(contentSearchFieldKey);
1008
+ const hasContentSearch = contentSearchOperator?.value.type === 'string';
1009
+ const suggestionSource = useMemo(
1010
+ () => createSheetSuggestionSource(config, searchSource),
1011
+ [config, searchSource],
1012
+ );
1013
+
1014
+ const contentResultsId = useId();
1015
+ const managerAddButtonRef = useRef<HTMLButtonElement>(null);
1016
+ const contentSearchRef = useRef<HTMLDivElement>(null);
1017
+ const fieldSearchRef = useRef<HTMLDivElement>(null);
1018
+ // The Add filter sheet's panel: the fallback focus target when the control
1019
+ // a step came from is gone — its first focusable control, which is the
1020
+ // search field when one shows, else the first field row.
1021
+ const fieldsSheetRef = useRef<HTMLDivElement>(null);
1022
+ // The content search and its suggestion rows are one vertical list for the
1023
+ // arrow keys: ArrowDown from the searchbox reaches the first suggestion,
1024
+ // ArrowUp from the first suggestion returns to the searchbox, and the ends
1025
+ // do not wrap. Home and End stay with the searchbox's caret.
1026
+ const contentListFocus = useInternalListFocus<HTMLDivElement>({
1027
+ itemSelector: `[role="searchbox"], [id="${contentResultsId}"] button`,
1028
+ wrap: false,
1029
+ hasHomeEnd: false,
1030
+ });
1031
+ const fieldsSheetCallbackRef = useMergedRefs(
1032
+ fieldsSheetRef,
1033
+ contentListFocus.listRef,
1034
+ );
1035
+ const handleContentListKeyDown = (event: React.KeyboardEvent) => {
1036
+ if (!isImeKeyEvent(event.nativeEvent)) {
1037
+ contentListFocus.handleKeyDown(event);
1038
+ }
1039
+ };
1040
+ const manageSheetRef = useRef<HTMLDivElement>(null);
1041
+ // Where focus was inside the Filters or Add filter sheet, read on every
1042
+ // focus change there, so a controlled update that unmounts the focused
1043
+ // control (a filter's row, a dropped field's row, Clear all after the last
1044
+ // filter) can put focus on the nearest remaining row by that index, else
1045
+ // the sheet's first control, else the sheet panel. A removed element
1046
+ // fires no blur, so the position is what the effect below reads.
1047
+ const lastSheetFocusRef = useRef<{
1048
+ sheet: 'manage' | 'fields';
1049
+ rowIndex: number | null;
1050
+ } | null>(null);
1051
+ // One index space for the record and the recovery: rows that are buttons
1052
+ // (a plain read-only row is passed over, as the removal and Apply/Cancel
1053
+ // rules pass it over), in document order.
1054
+ const buttonRowsOf = (panel: HTMLElement): HTMLElement[] =>
1055
+ Array.from(panel.querySelectorAll<HTMLLIElement>('li'))
1056
+ .map(row => row.querySelector<HTMLElement>('button'))
1057
+ .filter((button): button is HTMLElement => button != null);
1058
+ const noteSheetFocus = useCallback(
1059
+ (sheet: 'manage' | 'fields') => (event: React.FocusEvent) => {
1060
+ const row = (event.target as HTMLElement).closest('li');
1061
+ const button = row?.querySelector<HTMLElement>('button') ?? null;
1062
+ const rowIndex =
1063
+ button == null
1064
+ ? -1
1065
+ : buttonRowsOf(event.currentTarget as HTMLElement).indexOf(button);
1066
+ lastSheetFocusRef.current = {
1067
+ sheet,
1068
+ rowIndex: rowIndex === -1 ? null : rowIndex,
1069
+ };
1070
+ },
1071
+ [],
1072
+ );
1073
+ const managerRowsRef = useRef(new Map<number, HTMLLIElement>());
1074
+ const fieldRowsRef = useRef(new Map<string, HTMLLIElement>());
1075
+ const latestFiltersRef = useRef(filters);
1076
+ const pendingSheetFocusRef = useRef<PendingSheetFocus | null>(null);
1077
+ const pendingMutationFocusRef = useRef(false);
1078
+
1079
+ // The step an open starts on: Add filter directly when an interactive field
1080
+ // has nothing to manage yet, otherwise Filters. Neither search field takes
1081
+ // focus on open, so the software keyboard stays down until the person taps
1082
+ // the search. Add filter opened directly is the flow's entry point: no
1083
+ // Filters sheet beneath it, and Done in its footer.
1084
+ const isEntryAddFilter = filters.length === 0 && isInteractive;
1085
+ const [step, setStep] = useState<SheetStep | null>(() =>
1086
+ isOpen ? (isEntryAddFilter ? 'fields' : 'manage') : null,
1087
+ );
1088
+ const [fieldPickerOrigin, setFieldPickerOrigin] = useState<
1089
+ 'manage' | 'trigger'
1090
+ >(() => (isOpen && isEntryAddFilter ? 'trigger' : 'manage'));
1091
+ // The current step, read by the sheets' close reports and by a removal that
1092
+ // decides where to speak.
1093
+ const stepRef = useRef(step);
1094
+ useLayoutEffect(() => {
1095
+ stepRef.current = step;
1096
+ }, [step]);
1097
+ // The draft outlives a step change on purpose: a closing value step stays
1098
+ // presented through its exit, and clearing the draft with the step would
1099
+ // blank that sheet mid-transition.
1100
+ const [draft, setDraft] = useState<FilterDraft | null>(null);
1101
+ const draftGenerationRef = useRef(0);
1102
+ const nextDraftGeneration = useCallback(() => {
1103
+ draftGenerationRef.current += 1;
1104
+ return draftGenerationRef.current;
1105
+ }, []);
1106
+ const [fieldQuery, setFieldQuery] = useState('');
1107
+ const [contentQuery, setContentQuery] = useState('');
1108
+ const [isClearConfirmationOpen, setIsClearConfirmationOpen] = useState(false);
1109
+ const clearAllButtonRef = useRef<HTMLButtonElement>(null);
1110
+
1111
+ // `useAnnounce` delivers inside the open Astryx modal that encloses its
1112
+ // caller, and this component renders above the
1113
+ // sheets, so it cannot call the hook itself. Each step's body renders a
1114
+ // `SheetAnnouncer` inside its BottomSheet, which publishes the dialog's own
1115
+ // `announce` here while that step is the active one; the effects below
1116
+ // speak through it, so every message about a sheet's content is delivered
1117
+ // in that sheet's dialog.
1118
+ const announceRef = useRef<AnnounceFn | null>(null);
1119
+ const handleAnnounceChange = useCallback((next: AnnounceFn | null) => {
1120
+ announceRef.current = next;
1121
+ }, []);
1122
+ const announce = useCallback((message: string) => {
1123
+ announceRef.current?.(message);
1124
+ }, []);
1125
+ const pendingAnnouncementRef = useRef<string | null>(null);
1126
+
1127
+ // The controlled `isOpen` opens and closes the flow; the step follows it in
1128
+ // the render that sees the change, not an effect, so the entry step's sheet
1129
+ // opens in the same commit as the flow (React's adjust-state-on-
1130
+ // prop-change pattern). Closing from outside — the field became disabled —
1131
+ // ends the flow wherever it was, the Clear all confirmation included.
1132
+ const [wasOpen, setWasOpen] = useState(isOpen);
1133
+ if (isOpen !== wasOpen) {
1134
+ setWasOpen(isOpen);
1135
+ if (isOpen) {
1136
+ // A fresh draft from the committed filters; the entry step is judged
1137
+ // against them, not the previous session's draft.
1138
+ setFiltersAtOpen(committedFilters);
1139
+ setFilters(committedFilters);
1140
+ draftRef.current = committedFilters;
1141
+ draftEditsRef.current = [];
1142
+ const startsOnAddFilter = committedFilters.length === 0 && isInteractive;
1143
+ setFieldQuery('');
1144
+ setContentQuery('');
1145
+ setStep(startsOnAddFilter ? 'fields' : 'manage');
1146
+ setFieldPickerOrigin(startsOnAddFilter ? 'trigger' : 'manage');
1147
+ } else {
1148
+ setStep(null);
1149
+ setIsClearConfirmationOpen(false);
1150
+ setIsDiscardConfirmationOpen(false);
1151
+ }
1152
+ }
1153
+
1154
+ const closeFlow = useCallback(() => {
1155
+ pendingSheetFocusRef.current = null;
1156
+ setStep(null);
1157
+ onOpenChange(false);
1158
+ }, [onOpenChange]);
1159
+ // Done replays each edit in order onto the field's latest filters, so a
1160
+ // consumer gets the calls a popover session makes and keeps a filter it
1161
+ // added meanwhile.
1162
+ const commitAndClose = useCallback(() => {
1163
+ // A field that became read-only while the flow was open reports nothing.
1164
+ if (isDraftDirty && isInteractive) {
1165
+ replayDraftEdits(committedFilters, draftEditsRef.current, onCommit);
1166
+ }
1167
+ draftEditsRef.current = [];
1168
+ closeFlow();
1169
+ }, [closeFlow, committedFilters, isDraftDirty, isInteractive, onCommit]);
1170
+ const requestDismiss = useCallback(() => {
1171
+ if (isDraftDirty) {
1172
+ setIsDiscardConfirmationOpen(true);
1173
+ } else {
1174
+ closeFlow();
1175
+ }
1176
+ }, [closeFlow, isDraftDirty]);
1177
+ const closeDiscardConfirmation = () => {
1178
+ // eslint-disable-next-line @eslint-react/dom-no-flush-sync -- the confirmation must be gone before focus moves back into the sheet
1179
+ flushSync(() => setIsDiscardConfirmationOpen(false));
1180
+ const target =
1181
+ stepRef.current === 'manage'
1182
+ ? (managerAddButtonRef.current ??
1183
+ manageSheetRef.current?.closest<HTMLElement>('[tabindex="-1"]'))
1184
+ : fieldsSheetRef.current?.closest<HTMLElement>('[tabindex="-1"]');
1185
+ target?.focus({preventScroll: true});
1186
+ };
1187
+
1188
+ // Whether a Filters row is a button: the field interactive and the
1189
+ // filter not read-only. The row opens the value step — the editor for its
1190
+ // operator's value type, the built-in nested editor for a `nested` one, or
1191
+ // for a filter the config no longer knows the unavailable state — and its
1192
+ // trailing remove action removes it, as the popover's token has its × for
1193
+ // it.
1194
+ const isRowButton = useCallback(
1195
+ (filter: PowerSearchFilter): boolean => !filter.isReadOnly && isInteractive,
1196
+ [isInteractive],
1197
+ );
1198
+
1199
+ // ------------------------------------------------------------------ focus --
1200
+
1201
+ // The control a step change named also becomes where the closing step
1202
+ // sheets return focus when their exit ends: a closing sheet that held focus
1203
+ // keeps it until then, and BottomSheet then returns it, so the named control
1204
+ // receives it even when the first move could not land. With no control
1205
+ // named, the closing steps return focus as the flow does.
1206
+ const stepReturnTargetRef = useRef<HTMLElement | null>(null);
1207
+ const stepFinalFocusRef = useMemo<React.RefObject<HTMLElement | null>>(
1208
+ () => ({
1209
+ get current() {
1210
+ return stepReturnTargetRef.current ?? finalFocusRef.current;
1211
+ },
1212
+ }),
1213
+ [finalFocusRef],
1214
+ );
1215
+ const placeFocus = (element: HTMLElement | null | undefined) => {
1216
+ if (element == null) {
1217
+ return;
1218
+ }
1219
+ stepReturnTargetRef.current = element;
1220
+ element.focus({preventScroll: true});
1221
+ };
1222
+ const focusPendingSheetTarget = useCallback(() => {
1223
+ const target = pendingSheetFocusRef.current;
1224
+ if (target == null) {
1225
+ return;
1226
+ }
1227
+ pendingSheetFocusRef.current = null;
1228
+ if (target.type === 'manager-add') {
1229
+ placeFocus(managerAddButtonRef.current);
1230
+ return;
1231
+ }
1232
+ // Add filter's fallback: a controlled update may have removed the field
1233
+ // whose row opened the step, or the content-search field itself; the
1234
+ // sheet's first focusable control then takes focus — the search field
1235
+ // when one shows, else the first field row.
1236
+ const firstFieldsControl = () => {
1237
+ const panel = fieldsSheetRef.current;
1238
+ return (
1239
+ panel?.querySelector<HTMLElement>('input') ??
1240
+ panel?.querySelector<HTMLElement>('li button') ??
1241
+ panel?.querySelector<HTMLElement>('button') ??
1242
+ null
1243
+ );
1244
+ };
1245
+ if (target.type === 'content-search') {
1246
+ placeFocus(
1247
+ contentSearchRef.current?.querySelector<HTMLInputElement>('input') ??
1248
+ firstFieldsControl(),
1249
+ );
1250
+ return;
1251
+ }
1252
+ if (target.type === 'field') {
1253
+ placeFocus(
1254
+ fieldRowsRef.current
1255
+ .get(target.fieldKey)
1256
+ ?.querySelector<HTMLButtonElement>('button') ?? firstFieldsControl(),
1257
+ );
1258
+ return;
1259
+ }
1260
+ // The row the step came from, followed across a controlled reorder or
1261
+ // clone; when a controlled update removed it, or left two filters it
1262
+ // could be, the nearest remaining row that is a button, as after a
1263
+ // removal; else Add filter.
1264
+ const index =
1265
+ resolveFilterIdentityIndex(
1266
+ latestFiltersRef.current,
1267
+ target.sourceFilter,
1268
+ target.sourceSignature,
1269
+ target.preferredIndex,
1270
+ ) ??
1271
+ nearestEditableIndex(
1272
+ latestFiltersRef.current,
1273
+ target.preferredIndex,
1274
+ isRowButton,
1275
+ );
1276
+ const row = index == null ? null : managerRowsRef.current.get(index);
1277
+ const rowButton =
1278
+ target.part === 'remove'
1279
+ ? (row?.querySelector<HTMLButtonElement>('[data-sheet-remove]') ??
1280
+ row?.querySelector<HTMLButtonElement>('button'))
1281
+ : row?.querySelector<HTMLButtonElement>('button');
1282
+ placeFocus(rowButton ?? managerAddButtonRef.current);
1283
+ }, [isRowButton]);
1284
+
1285
+ // A controlled update that unmounts the focused control of the Filters or
1286
+ // Add filter sheet leaves focus on the page body inside the open modal.
1287
+ // Read before paint on every commit of an open step: when focus is no
1288
+ // longer inside the sheet's dialog, the nearest remaining row by the last
1289
+ // focused index takes it, else the sheet's first control, else its panel.
1290
+ // The pending-target effects below run after and win when a step
1291
+ // change named a control.
1292
+ useLayoutEffect(() => {
1293
+ const last = lastSheetFocusRef.current;
1294
+ if (step !== 'manage' && step !== 'fields') {
1295
+ return;
1296
+ }
1297
+ if (last == null || last.sheet !== step) {
1298
+ return;
1299
+ }
1300
+ const panel =
1301
+ step === 'manage' ? manageSheetRef.current : fieldsSheetRef.current;
1302
+ const dialog = panel?.closest('dialog');
1303
+ const active = document.activeElement;
1304
+ if (
1305
+ panel == null ||
1306
+ dialog == null ||
1307
+ (active != null && active !== document.body && dialog.contains(active))
1308
+ ) {
1309
+ return;
1310
+ }
1311
+ const rowButtons = buttonRowsOf(panel);
1312
+ let target: HTMLElement | null = null;
1313
+ if (last.rowIndex != null && rowButtons.length > 0) {
1314
+ // The following button row, else the last.
1315
+ target = rowButtons[Math.min(last.rowIndex, rowButtons.length - 1)];
1316
+ }
1317
+ target ??=
1318
+ panel.querySelector<HTMLElement>('input') ??
1319
+ rowButtons[0] ??
1320
+ panel.querySelector<HTMLElement>('button') ??
1321
+ null;
1322
+ if (target != null) {
1323
+ target.focus({preventScroll: true});
1324
+ } else {
1325
+ const focusable = dialog.querySelector<HTMLElement>('[tabindex="-1"]');
1326
+ (focusable ?? dialog).focus({preventScroll: true});
1327
+ }
1328
+ });
1329
+
1330
+ // Both Effects move focus inside the entering sheet — the external system
1331
+ // is the document's focus — to the control the step named. They run after
1332
+ // the entering sheet's own
1333
+ // panel focus (child effects commit first), so the intended control wins,
1334
+ // and they acquire nothing, so they need no cleanup. The filters effect is
1335
+ // declared first so a mutation that lands in the same commit as the step
1336
+ // change resolves its row against the new filters.
1337
+ useEffect(() => {
1338
+ latestFiltersRef.current = filters;
1339
+ if (step === 'manage' && pendingMutationFocusRef.current) {
1340
+ pendingMutationFocusRef.current = false;
1341
+ focusPendingSheetTarget();
1342
+ }
1343
+ }, [filters, focusPendingSheetTarget, step]);
1344
+
1345
+ // A target still pending when the flow closes, such as a commit that
1346
+ // disabled the field, never carries into the next open.
1347
+ useEffect(() => {
1348
+ if (step == null) {
1349
+ stepReturnTargetRef.current = null;
1350
+ pendingSheetFocusRef.current = null;
1351
+ return;
1352
+ }
1353
+ // A step that opens starts with no named return target; a return to
1354
+ // Filters keeps the one its commit, or its removal, has just named.
1355
+ if (step !== 'manage') {
1356
+ stepReturnTargetRef.current = null;
1357
+ }
1358
+ focusPendingSheetTarget();
1359
+ }, [focusPendingSheetTarget, step]);
1360
+
1361
+ // An announcement queued by a step change — a suggestion or a removal that
1362
+ // changed the filters — is spoken in the commit that shows the next step,
1363
+ // so it lands in that step's dialog region rather than the one about to
1364
+ // close. It synchronizes the live region named above and acquires nothing.
1365
+ useEffect(() => {
1366
+ const message = pendingAnnouncementRef.current;
1367
+ if (step != null && message != null) {
1368
+ pendingAnnouncementRef.current = null;
1369
+ announce(message);
1370
+ }
1371
+ }, [announce, step]);
1372
+
1373
+ // ----------------------------------------------------------------- fields --
1374
+
1375
+ // Every visible field lists: the value step edits every operator's value,
1376
+ // `nested` through the popover's built-in editor.
1377
+ const fields = useMemo(() => config.getVisibleFields(), [config]);
1378
+
1379
+ const normalizedFieldQuery = fieldQuery.trim().toLowerCase();
1380
+ const matchingFields = useMemo(() => {
1381
+ const matches = fields.filter(field =>
1382
+ fieldMatchesQuery(field, normalizedFieldQuery),
1383
+ );
1384
+ return normalizedFieldQuery === ''
1385
+ ? matches
1386
+ : matches.slice(0, maxSearchResults);
1387
+ }, [fields, maxSearchResults, normalizedFieldQuery]);
1388
+
1389
+ // Ungrouped fields first, then each group in first-appearance order — the
1390
+ // same grouping the popover presentation's field suggestions use
1391
+ // (`groupItems` with `ungroupedFirst`), so the two presentations
1392
+ // list a config's fields in one order.
1393
+ const groupedFields = useMemo(
1394
+ () =>
1395
+ matchingFields.length === 0
1396
+ ? []
1397
+ : groupItems(
1398
+ matchingFields.map(field => ({
1399
+ id: field.key,
1400
+ label: field.label,
1401
+ auxiliaryData: {group: field.group},
1402
+ field,
1403
+ })),
1404
+ {ungroupedFirst: true},
1405
+ ).map(
1406
+ group =>
1407
+ [
1408
+ group.heading ?? '',
1409
+ group.items.map(item => item.field),
1410
+ ] as const,
1411
+ ),
1412
+ [matchingFields],
1413
+ );
1414
+
1415
+ const isFieldSearchShown = fields.length >= SEARCHABLE_FIELD_COUNT;
1416
+
1417
+ // A field whose only operator takes an `empty` value is a one-tap filter:
1418
+ // its row adds it with no value step, and shows a plus, not a chevron.
1419
+ const isImmediateAddField = useCallback(
1420
+ (field: PowerSearchField): boolean => {
1421
+ const operators = config.getVisibleOperators(field.key);
1422
+ return operators.length === 1 && operators[0].value.type === 'empty';
1423
+ },
1424
+ [config],
1425
+ );
1426
+
1427
+ // The steps stack: each opens above the sheet that led to it, which stays
1428
+ // open beneath. Add filter entered directly has no Filters sheet beneath.
1429
+ const isFieldPickerDirectEntry = fieldPickerOrigin === 'trigger';
1430
+ const isManageSheetOpen =
1431
+ step === 'manage' ||
1432
+ (step === 'fields' && !isFieldPickerDirectEntry) ||
1433
+ (step === 'value' && (draft?.mode === 'edit' || !isFieldPickerDirectEntry));
1434
+ const isFieldsSheetOpen =
1435
+ step === 'fields' || (step === 'value' && draft?.mode === 'create');
1436
+
1437
+ // The suggestions derive synchronously from the config, so a list never
1438
+ // waits on a request: an empty list means an empty result, not a pending
1439
+ // one. They stay listed while the value step covers Add filter.
1440
+ const contentResults = useMemo(() => {
1441
+ if (!isFieldsSheetOpen || !hasContentSearch || !isInteractive) {
1442
+ return [];
1443
+ }
1444
+ const results =
1445
+ contentQuery.trim() === ''
1446
+ ? suggestionSource.bootstrap()
1447
+ : suggestionSource.search(contentQuery);
1448
+ return results.slice(0, MAX_BROWSE_MENU_ITEMS);
1449
+ }, [
1450
+ contentQuery,
1451
+ hasContentSearch,
1452
+ isFieldsSheetOpen,
1453
+ isInteractive,
1454
+ suggestionSource,
1455
+ ]);
1456
+
1457
+ // The field's result count, while a sheet is open: the owner's own Effect
1458
+ // is quiet then, so the change is spoken here, inside the dialog. Only a
1459
+ // change after the flow opened is spoken.
1460
+ const announcedResultCountRef = useRef(resultCountText);
1461
+ useEffect(() => {
1462
+ if (resultCountText === announcedResultCountRef.current) {
1463
+ return;
1464
+ }
1465
+ announcedResultCountRef.current = resultCountText;
1466
+ if (step != null && resultCountText != null) {
1467
+ announce(resultCountText);
1468
+ }
1469
+ }, [announce, resultCountText, step]);
1470
+
1471
+ // ------------------------------------------------------------------ draft --
1472
+
1473
+ const draftField = draft ? config.getField(draft.field) : undefined;
1474
+ const draftOperator =
1475
+ draft?.operator != null
1476
+ ? config.getOperator(draft.field, draft.operator)
1477
+ : undefined;
1478
+ const draftOperators = useMemo(
1479
+ () => (draft ? config.getVisibleOperators(draft.field) : []),
1480
+ [config, draft],
1481
+ );
1482
+
1483
+ // The two parts of a Filters row's text for `filter`: "{field} {operator}"
1484
+ // as one catalog message, and the value as the popover presentation's
1485
+ // token shows it — the same function, so the same words and the same zone
1486
+ // handling, before the token's width budget. The rows render these, and
1487
+ // the removal announcement joins them, so the three can never
1488
+ // disagree.
1489
+ const describeFilterParts = useCallback(
1490
+ (filter: PowerSearchFilter): {label: string; value: string | null} => {
1491
+ const field = config.getField(filter.field);
1492
+ const operator = config.getOperator(filter.field, filter.operator);
1493
+ // A filter whose field or operator the config no longer has still
1494
+ // lists, by its raw keys, as its token does on the trigger; its row
1495
+ // opens the unavailable step, and its trailing remove action removes
1496
+ // it.
1497
+ const fieldLabel = field?.label ?? filter.field;
1498
+ const operatorLabel =
1499
+ operator == null ? filter.operator : resolveOperatorLabel(operator, t);
1500
+ const label = operatorLabel
1501
+ ? t('@astryx.powersearch.sheet.fieldOperator', {
1502
+ field: fieldLabel,
1503
+ operator: operatorLabel,
1504
+ })
1505
+ : fieldLabel;
1506
+ if (operator == null) {
1507
+ return {label, value: null};
1508
+ }
1509
+ // A relative-date value is stored as a key (`3d_ago`); the row reads it
1510
+ // as the value step's choice row does ("3 days ago"), through the
1511
+ // catalog's relative-date messages, so the sheet agrees with itself. The popover token
1512
+ // shows the stored key (a known gap of the record).
1513
+ const value =
1514
+ operator.value.type === 'date_relative' &&
1515
+ filter.value.type === 'date_relative'
1516
+ ? resolveRelativeDateLabel(
1517
+ operator.value,
1518
+ filter.value.value,
1519
+ t,
1520
+ editors.buildRelativeDateOptions,
1521
+ )
1522
+ : formatTokenValueText(
1523
+ operator.value,
1524
+ filter.value,
1525
+ Number.MAX_SAFE_INTEGER,
1526
+ locale,
1527
+ t,
1528
+ formatList,
1529
+ timezoneID,
1530
+ );
1531
+ return {label, value};
1532
+ },
1533
+ [config, editors, formatList, locale, t, timezoneID],
1534
+ );
1535
+ const describeFilter = useCallback(
1536
+ (filter: PowerSearchFilter): string => {
1537
+ const parts = describeFilterParts(filter);
1538
+ return parts.value
1539
+ ? t('@astryx.powersearch.sheet.labelValue', {
1540
+ label: parts.label,
1541
+ value: parts.value,
1542
+ })
1543
+ : parts.label;
1544
+ },
1545
+ [describeFilterParts, t],
1546
+ );
1547
+
1548
+ const openFieldList = useCallback(() => {
1549
+ if (!isInteractive) {
1550
+ return;
1551
+ }
1552
+ setFieldPickerOrigin('manage');
1553
+ setFieldQuery('');
1554
+ setContentQuery('');
1555
+ pendingSheetFocusRef.current = null;
1556
+ setStep('fields');
1557
+ }, [isInteractive]);
1558
+
1559
+ const queueManagerAddFocus = useCallback(() => {
1560
+ pendingSheetFocusRef.current = {type: 'manager-add'};
1561
+ }, []);
1562
+
1563
+ const commitSavedFilter = useCallback(
1564
+ (next: FilterDraft, filter: PowerSearchFilter) => {
1565
+ if (!isInteractive) {
1566
+ queueManagerAddFocus();
1567
+ setStep('manage');
1568
+ return;
1569
+ }
1570
+ if (next.mode === 'edit') {
1571
+ const filterIndex = resolveDraftFilterIndex(filters, next);
1572
+ const currentFilter =
1573
+ filterIndex == null ? undefined : filters[filterIndex];
1574
+ if (
1575
+ filterIndex == null ||
1576
+ currentFilter == null ||
1577
+ currentFilter.isReadOnly
1578
+ ) {
1579
+ // A controlled update removed the edited filter, or left two it
1580
+ // could be, or made it read-only: nothing is written, and focus
1581
+ // returns to the nearest row that is a button around where it was,
1582
+ // else Add filter.
1583
+ pendingSheetFocusRef.current =
1584
+ next.sourceFilter != null &&
1585
+ next.sourceSignature != null &&
1586
+ next.filterIndex != null
1587
+ ? {
1588
+ type: 'manager-filter',
1589
+ sourceFilter: next.sourceFilter,
1590
+ sourceSignature: next.sourceSignature,
1591
+ preferredIndex: next.filterIndex,
1592
+ }
1593
+ : {type: 'manager-add'};
1594
+ setStep('manage');
1595
+ return;
1596
+ }
1597
+ pendingSheetFocusRef.current = {
1598
+ type: 'manager-filter',
1599
+ sourceFilter: filter,
1600
+ sourceSignature: filterSignature(filter),
1601
+ preferredIndex: filterIndex,
1602
+ };
1603
+ const updated = [...filters];
1604
+ updated[filterIndex] = filter;
1605
+ onChange(updated, 'edit', filterIndex);
1606
+ } else {
1607
+ queueManagerAddFocus();
1608
+ onChange([...filters, filter], 'add', filters.length);
1609
+ }
1610
+ setStep('manage');
1611
+ },
1612
+ [filters, isInteractive, onChange, queueManagerAddFocus],
1613
+ );
1614
+
1615
+ // Opening a new filter can come from a field row or a content-search
1616
+ // suggestion. The origin is kept so Cancel returns to the control the person
1617
+ // came from.
1618
+ const openCreateEditor = useCallback(
1619
+ (
1620
+ field: PowerSearchField,
1621
+ operator: PowerSearchOperator,
1622
+ returnFocus: 'field' | 'content-search' = 'field',
1623
+ ) => {
1624
+ setDraft({
1625
+ mode: 'create',
1626
+ generation: nextDraftGeneration(),
1627
+ returnFocus,
1628
+ field: field.key,
1629
+ operator: operator.key,
1630
+ value: operator.value.type === 'empty' ? {type: 'empty'} : undefined,
1631
+ });
1632
+ pendingSheetFocusRef.current = null;
1633
+ setStep('value');
1634
+ },
1635
+ [nextDraftGeneration],
1636
+ );
1637
+
1638
+ const handleFieldSelect = useCallback(
1639
+ (field: PowerSearchField) => {
1640
+ if (!isInteractive) {
1641
+ return;
1642
+ }
1643
+ // A one-tap filter has nothing to stage: choosing its field adds it
1644
+ // and returns to Filters.
1645
+ if (isImmediateAddField(field)) {
1646
+ const [operator] = config.getVisibleOperators(field.key);
1647
+ const nextFilter: PowerSearchFilter = {
1648
+ field: field.key,
1649
+ operator: operator.key,
1650
+ value: {type: 'empty'},
1651
+ };
1652
+ pendingSheetFocusRef.current = {
1653
+ type: 'manager-filter',
1654
+ sourceFilter: nextFilter,
1655
+ sourceSignature: filterSignature(nextFilter),
1656
+ preferredIndex: filters.length,
1657
+ };
1658
+ pendingMutationFocusRef.current = true;
1659
+ onChange([...filters, nextFilter], 'add', filters.length);
1660
+ pendingAnnouncementRef.current = t('@astryx.tokenizer.tokenAdded', {
1661
+ label: describeFilter(nextFilter),
1662
+ });
1663
+ setStep('manage');
1664
+ return;
1665
+ }
1666
+ const operator =
1667
+ config.getDefaultOperator(field.key) ?? field.operators[0];
1668
+ if (operator == null) {
1669
+ return;
1670
+ }
1671
+ openCreateEditor(field, operator);
1672
+ },
1673
+ [
1674
+ config,
1675
+ describeFilter,
1676
+ filters,
1677
+ isImmediateAddField,
1678
+ isInteractive,
1679
+ onChange,
1680
+ openCreateEditor,
1681
+ t,
1682
+ ],
1683
+ );
1684
+
1685
+ const handleContentSuggestionSelect = useCallback(
1686
+ (item: PowerSearchItem | null) => {
1687
+ if (!isInteractive || item?.auxiliaryData == null) {
1688
+ return;
1689
+ }
1690
+ const {fieldKey, filterValue, operatorKey} = item.auxiliaryData;
1691
+ const field = config.getField(fieldKey);
1692
+ const operator =
1693
+ operatorKey == null
1694
+ ? config.getDefaultOperator(fieldKey)
1695
+ : config.getOperator(fieldKey, operatorKey);
1696
+ if (field == null || operator == null) {
1697
+ return;
1698
+ }
1699
+ setContentQuery('');
1700
+ if (filterValue != null) {
1701
+ const nextFilter: PowerSearchFilter = {
1702
+ field: field.key,
1703
+ operator: operator.key,
1704
+ value: filterValue,
1705
+ };
1706
+ pendingSheetFocusRef.current = {
1707
+ type: 'manager-filter',
1708
+ sourceFilter: nextFilter,
1709
+ sourceSignature: filterSignature(nextFilter),
1710
+ preferredIndex: filters.length,
1711
+ };
1712
+ pendingMutationFocusRef.current = true;
1713
+ onChange([...filters, nextFilter], 'add', filters.length);
1714
+ // The same announcement the popover presentation's typeahead add
1715
+ // makes, so assistive technology hears one phrase for one outcome;
1716
+ // spoken once the Filters sheet is the open dialog.
1717
+ pendingAnnouncementRef.current = t('@astryx.tokenizer.tokenAdded', {
1718
+ label: item.label,
1719
+ });
1720
+ setStep('manage');
1721
+ return;
1722
+ }
1723
+ openCreateEditor(field, operator, 'content-search');
1724
+ },
1725
+ [config, filters, isInteractive, onChange, openCreateEditor, t],
1726
+ );
1727
+
1728
+ const handleFilterEdit = useCallback(
1729
+ (index: number) => {
1730
+ const filter = filters[index];
1731
+ if (!isInteractive || filter == null || filter.isReadOnly) {
1732
+ return;
1733
+ }
1734
+ setDraft({
1735
+ mode: 'edit',
1736
+ generation: nextDraftGeneration(),
1737
+ filterIndex: index,
1738
+ sourceFilter: filter,
1739
+ sourceSignature: filterSignature(filter),
1740
+ field: filter.field,
1741
+ operator: filter.operator,
1742
+ value: filter.value,
1743
+ });
1744
+ pendingSheetFocusRef.current = null;
1745
+ setStep('value');
1746
+ },
1747
+ [filters, isInteractive, nextDraftGeneration],
1748
+ );
1749
+
1750
+ const handleRemoveFilter = useCallback(
1751
+ (index: number) => {
1752
+ const filter = filters[index];
1753
+ if (!isInteractive || filter == null || filter.isReadOnly) {
1754
+ return;
1755
+ }
1756
+ const nextFilters = filters.filter((_, i) => i !== index);
1757
+ const nextIndex = nearestEditableIndex(nextFilters, index, isRowButton);
1758
+ if (nextIndex == null) {
1759
+ pendingSheetFocusRef.current = {type: 'manager-add'};
1760
+ } else {
1761
+ const nextFilter = nextFilters[nextIndex];
1762
+ pendingSheetFocusRef.current = {
1763
+ type: 'manager-filter',
1764
+ sourceFilter: nextFilter,
1765
+ sourceSignature: filterSignature(nextFilter),
1766
+ preferredIndex: nextIndex,
1767
+ part: 'remove',
1768
+ };
1769
+ }
1770
+ pendingMutationFocusRef.current = true;
1771
+ onChange(nextFilters, 'remove', index);
1772
+ // The popover presentation's token × announces the same phrase. A
1773
+ // removal from a Filters row stays in that sheet and speaks at once; a
1774
+ // caller's Editor that removes while returning to Filters speaks once
1775
+ // the Filters sheet is the open dialog.
1776
+ const message = t('@astryx.tokenizer.tokenRemoved', {
1777
+ label: describeFilter(filter),
1778
+ });
1779
+ if (stepRef.current === 'manage') {
1780
+ announce(message);
1781
+ } else {
1782
+ pendingAnnouncementRef.current = message;
1783
+ }
1784
+ },
1785
+ [
1786
+ announce,
1787
+ describeFilter,
1788
+ filters,
1789
+ isInteractive,
1790
+ isRowButton,
1791
+ onChange,
1792
+ t,
1793
+ ],
1794
+ );
1795
+
1796
+ // Closing Clear all's confirmation. Kept, focus returns to Clear all.
1797
+ // Confirmed, Clear all removes the filters the person can edit and keeps
1798
+ // read-only ones, which are the consumer's: one `remove` at the first
1799
+ // removed index. The Filters sheet stays open for further editing. The
1800
+ // confirmation must be gone before focus moves into the sheet and the
1801
+ // outcome is routed into the sheet's region, so its close is flushed
1802
+ // first. The outcome is "Editable filters removed" while a read-only filter
1803
+ // remains, otherwise "All filters removed"; the result count follows the
1804
+ // applied filters, which change on Done, so none changes here. Focus moves
1805
+ // to the sheet's first remaining control: a kept read-only row has none,
1806
+ // so Add filter.
1807
+ const closeClearConfirmation = (confirmed: boolean) => {
1808
+ const kept = filters.filter(filter => filter.isReadOnly);
1809
+ const firstRemovedIndex = filters.findIndex(filter => !filter.isReadOnly);
1810
+ const isClearing = confirmed && isInteractive && firstRemovedIndex >= 0;
1811
+ // eslint-disable-next-line @eslint-react/dom-no-flush-sync -- the confirmation must be gone before focus moves into the sheet and the words are routed into it
1812
+ flushSync(() => {
1813
+ setIsClearConfirmationOpen(false);
1814
+ if (isClearing) {
1815
+ onChange(kept, 'remove', firstRemovedIndex);
1816
+ }
1817
+ });
1818
+ if (!isClearing) {
1819
+ clearAllButtonRef.current?.focus();
1820
+ return;
1821
+ }
1822
+ managerAddButtonRef.current?.focus({preventScroll: true});
1823
+ announce(
1824
+ kept.length > 0
1825
+ ? t('@astryx.powersearch.editableFiltersRemoved')
1826
+ : t('@astryx.powersearch.allFiltersRemoved'),
1827
+ );
1828
+ };
1829
+
1830
+ const handleOperatorSelect = useCallback((operator: PowerSearchOperator) => {
1831
+ setDraft(current => {
1832
+ if (current == null) {
1833
+ return current;
1834
+ }
1835
+ // A value survives an operator change only when the new operator
1836
+ // reads the same value type.
1837
+ const keepsValue =
1838
+ current.value != null && current.value.type === operator.value.type;
1839
+ return {
1840
+ ...current,
1841
+ operator: operator.key,
1842
+ value:
1843
+ operator.value.type === 'empty'
1844
+ ? {type: 'empty'}
1845
+ : keepsValue
1846
+ ? current.value
1847
+ : undefined,
1848
+ };
1849
+ });
1850
+ }, []);
1851
+
1852
+ const handleDraftValueChange = useCallback((value: FilterValue) => {
1853
+ setDraft(current => (current == null ? current : {...current, value}));
1854
+ }, []);
1855
+ // The number input's draft was cleared or stopped parsing: nothing stands
1856
+ // to confirm, so the confirm action disables again.
1857
+ const handleDraftUnstage = useCallback(() => {
1858
+ setDraft(current =>
1859
+ current == null ? current : {...current, value: undefined},
1860
+ );
1861
+ }, []);
1862
+
1863
+ const handleSave = useCallback(() => {
1864
+ if (draft?.value == null || draft.operator == null) {
1865
+ return;
1866
+ }
1867
+ commitSavedFilter(draft, {
1868
+ field: draft.field,
1869
+ operator: draft.operator,
1870
+ value: draft.value,
1871
+ });
1872
+ }, [commitSavedFilter, draft]);
1873
+
1874
+ const returnFromValue = useCallback(() => {
1875
+ if (draft == null) {
1876
+ queueManagerAddFocus();
1877
+ setStep('manage');
1878
+ return;
1879
+ }
1880
+ if (
1881
+ draft.mode === 'edit' &&
1882
+ draft.sourceFilter != null &&
1883
+ draft.sourceSignature != null &&
1884
+ draft.filterIndex != null
1885
+ ) {
1886
+ pendingSheetFocusRef.current = {
1887
+ type: 'manager-filter',
1888
+ sourceFilter: draft.sourceFilter,
1889
+ sourceSignature: draft.sourceSignature,
1890
+ preferredIndex:
1891
+ resolveDraftFilterIndex(filters, draft) ?? draft.filterIndex,
1892
+ };
1893
+ setStep('manage');
1894
+ return;
1895
+ }
1896
+ if (draft.returnFocus === 'content-search') {
1897
+ pendingSheetFocusRef.current = {type: 'content-search'};
1898
+ setStep('fields');
1899
+ return;
1900
+ }
1901
+ pendingSheetFocusRef.current = {type: 'field', fieldKey: draft.field};
1902
+ setStep('fields');
1903
+ }, [draft, filters, queueManagerAddFocus]);
1904
+
1905
+ const handleRemove = useCallback(() => {
1906
+ if (draft?.mode !== 'edit') {
1907
+ return;
1908
+ }
1909
+ const filterIndex = resolveDraftFilterIndex(filters, draft);
1910
+ if (filterIndex == null || filters[filterIndex]?.isReadOnly) {
1911
+ queueManagerAddFocus();
1912
+ setStep('manage');
1913
+ return;
1914
+ }
1915
+ handleRemoveFilter(filterIndex);
1916
+ setStep('manage');
1917
+ }, [draft, filters, handleRemoveFilter, queueManagerAddFocus]);
1918
+
1919
+ // Each step sheet is controlled by `step`; a sheet only ever asks to close
1920
+ // (a dismissal its `purpose` allows: Escape, the scrim, a swipe, a platform
1921
+ // close request), which only the top sheet of the stack receives. Closing
1922
+ // the top step reveals the step beneath it; closing the bottom one ends the
1923
+ // flow. A stale report from a step that is no longer current is ignored.
1924
+ // Every step change goes through the handlers above.
1925
+ const handleManageOpenChange = useCallback(
1926
+ (isSheetOpen: boolean) => {
1927
+ if (!isSheetOpen && stepRef.current === 'manage') {
1928
+ requestDismiss();
1929
+ }
1930
+ },
1931
+ [requestDismiss],
1932
+ );
1933
+ const handleFieldsOpenChange = useCallback(
1934
+ (isSheetOpen: boolean) => {
1935
+ if (isSheetOpen || stepRef.current !== 'fields') {
1936
+ return;
1937
+ }
1938
+ if (fieldPickerOrigin === 'trigger') {
1939
+ requestDismiss();
1940
+ return;
1941
+ }
1942
+ queueManagerAddFocus();
1943
+ setStep('manage');
1944
+ },
1945
+ [fieldPickerOrigin, queueManagerAddFocus, requestDismiss],
1946
+ );
1947
+ const handleValueOpenChange = useCallback(
1948
+ (isSheetOpen: boolean) => {
1949
+ if (!isSheetOpen && stepRef.current === 'value') {
1950
+ returnFromValue();
1951
+ }
1952
+ },
1953
+ [returnFromValue],
1954
+ );
1955
+
1956
+ // ---------------------------------------------------------------- render --
1957
+
1958
+ // Rows are keyed by filter identity, not position: a parent's reorder or a
1959
+ // removal above the focused row then moves elements instead of remounting
1960
+ // them, and focus stays on the same filter. Only a filter that is
1961
+ // itself removed loses its element, and the re-home effect above takes
1962
+ // over.
1963
+ const [filterIdentities] = useState(createFilterIdentities);
1964
+ const filterIds = filterIdentities.next(filters);
1965
+ const filterRows = filters.map((filter, index) => {
1966
+ const {label, value} = describeFilterParts(filter);
1967
+ const isEditable = isRowButton(filter);
1968
+ // The row reads from the same catalog message the removal announcement
1969
+ // uses (`labelValue`), so a locale that reorders it reorders both: the
1970
+ // message is formatted with a placeholder for the value, and the text
1971
+ // either side of that placeholder wraps the bold value.
1972
+ let displayLabel: ReactNode = label;
1973
+ if (value) {
1974
+ const [before, after] = t('@astryx.powersearch.sheet.labelValue', {
1975
+ label,
1976
+ value: ROW_VALUE_SLOT,
1977
+ }).split(ROW_VALUE_SLOT);
1978
+ displayLabel = (
1979
+ <>
1980
+ {before}
1981
+ <span {...stylex.props(styles.rowValue)}>{value}</span>
1982
+ {after}
1983
+ </>
1984
+ );
1985
+ }
1986
+ return {
1987
+ displayLabel,
1988
+ filter,
1989
+ index,
1990
+ isEditable,
1991
+ key: `filter-${filterIds[index]}`,
1992
+ };
1993
+ });
1994
+
1995
+ const hasRemovableFilter = filters.some(filter => !filter.isReadOnly);
1996
+ const isClearAllShown = hasClear && isInteractive && hasRemovableFilter;
1997
+
1998
+ const EditorOverride =
1999
+ draftOperator != null
2000
+ ? componentOverrides?.[draftOperator.value.type]?.Editor
2001
+ : undefined;
2002
+
2003
+ const draftOperatorLabel =
2004
+ draftOperator == null ? '' : resolveOperatorLabel(draftOperator, t);
2005
+ // The title names the filter's own operator when the step offers no
2006
+ // Operator group: one visible operator, or an operator the config no longer
2007
+ // lists as visible. The step then never shows another operator's name.
2008
+ const showsOperatorGroup =
2009
+ draftOperators.length > 1 &&
2010
+ draftOperator != null &&
2011
+ draftOperators.includes(draftOperator);
2012
+ // The title — the dialog's name — reads the field and operator as
2013
+ // the Filters row does: by their labels, or, for a filter whose field or
2014
+ // operator the config no longer has, by the raw keys the row shows.
2015
+ const editorTitle =
2016
+ draft == null
2017
+ ? t('@astryx.powersearch.sheet.addFilter')
2018
+ : draftField == null || (draftOperator == null && draft.operator != null)
2019
+ ? t('@astryx.powersearch.sheet.fieldOperator', {
2020
+ field: draftField?.label ?? draft.field,
2021
+ operator:
2022
+ draftOperatorLabel !== ''
2023
+ ? draftOperatorLabel
2024
+ : (draft.operator ?? ''),
2025
+ }).trim()
2026
+ : !showsOperatorGroup && draftOperatorLabel !== ''
2027
+ ? t('@astryx.powersearch.sheet.fieldOperator', {
2028
+ field: draftField.label,
2029
+ operator: draftOperatorLabel,
2030
+ })
2031
+ : draftField.label;
2032
+ const saveButtonLabel =
2033
+ saveButtonLabelFromProps ??
2034
+ (draft?.mode === 'edit'
2035
+ ? t('@astryx.powersearch.editor.apply')
2036
+ : t('@astryx.powersearch.sheet.addFilter'));
2037
+
2038
+ // Every sheet body: padded, and publishing that padding to its lists.
2039
+ const bodyProps = stylex.props(
2040
+ styles.body,
2041
+ containerPaddingInlineVarStyles[4],
2042
+ );
2043
+ const scrollContentProps = stylex.props(
2044
+ styles.scrollContent,
2045
+ containerPaddingInlineVarStyles[4],
2046
+ );
2047
+ const controlSectionProps = stylex.props(
2048
+ styles.controlSection,
2049
+ containerPaddingInlineVarStyles[3],
2050
+ );
2051
+
2052
+ // A vertical touch drag on the Add filter rows moves focus off a focused
2053
+ // search to the sheet, so the software keyboard leaves and the rows can be
2054
+ // read.
2055
+ const fieldPickerDragProps = useDismissSearchOnTouchDrag(
2056
+ () => [
2057
+ contentSearchRef.current?.querySelector('input'),
2058
+ fieldSearchRef.current?.querySelector('input'),
2059
+ ],
2060
+ () => fieldsSheetRef.current?.closest<HTMLElement>('[tabindex="-1"]'),
2061
+ );
2062
+
2063
+ const isEditorDisabled = isDisabled || isReadOnly;
2064
+ const isSaveDisabled =
2065
+ isEditorDisabled || draft?.operator == null || draft.value == null;
2066
+ // The step has something to edit when the field and operator still exist
2067
+ // (a controlled config update can remove either). A caller's `Editor`
2068
+ // override replaces the body for its value type with the props the popover
2069
+ // hands it; otherwise a `nested` value takes the popover's built-in
2070
+ // NestedEditor and every other type the sheet's own control.
2071
+ const isDraftRenderable =
2072
+ draft != null && draftField != null && draftOperator != null;
2073
+ const isDraftNested =
2074
+ isDraftRenderable && !isSupportedOperator(draftOperator);
2075
+ // A controlled config update that removes the field or operator being
2076
+ // edited replaces the step's body with the unavailable state while focus
2077
+ // may be on one of the body's controls, which unmount without a blur. Focus
2078
+ // then moves to Cancel, the way back to the Filters row whose remove action
2079
+ // is the removal path, so it never falls to the page body inside the open
2080
+ // sheet. The message itself is announced by its rendered element.
2081
+ const cancelButtonRef = useRef<HTMLButtonElement>(null);
2082
+ const wasDraftRenderableRef = useRef(isDraftRenderable);
2083
+ useLayoutEffect(() => {
2084
+ const becameUnavailable =
2085
+ wasDraftRenderableRef.current && !isDraftRenderable && draft != null;
2086
+ wasDraftRenderableRef.current = isDraftRenderable;
2087
+ if (!becameUnavailable || step !== 'value') {
2088
+ return;
2089
+ }
2090
+ const active = document.activeElement;
2091
+ const dialog = cancelButtonRef.current?.closest('dialog');
2092
+ if (dialog != null && active != null && dialog.contains(active)) {
2093
+ return;
2094
+ }
2095
+ cancelButtonRef.current?.focus();
2096
+ }, [draft, isDraftRenderable, step]);
2097
+ // The operator group stays outside either editor, so switching operators
2098
+ // swaps the body — a `nested` operator beside a plain one included.
2099
+ const operatorGroup = isDraftRenderable && showsOperatorGroup && (
2100
+ <RadioList
2101
+ label={t('@astryx.powersearch.editor.operator')}
2102
+ isLabelHidden
2103
+ value={draft.operator ?? ''}
2104
+ onChange={operatorKey => {
2105
+ const operator = draftOperators.find(
2106
+ candidate => candidate.key === operatorKey,
2107
+ );
2108
+ if (operator != null) {
2109
+ handleOperatorSelect(operator);
2110
+ }
2111
+ }}
2112
+ isDisabled={isEditorDisabled}>
2113
+ {draftOperators.map(operator => (
2114
+ <RadioListItem
2115
+ key={operator.key}
2116
+ label={t('@astryx.powersearch.sheet.fieldOperator', {
2117
+ field: draftField.label,
2118
+ operator: resolveOperatorLabel(operator, t),
2119
+ })}
2120
+ value={operator.key}
2121
+ xstyle={styles.trailingControlRow}
2122
+ />
2123
+ ))}
2124
+ </RadioList>
2125
+ );
2126
+ // The step's Operator group owns the operator choice, so the built-in
2127
+ // nested editor's root operator picker is hidden and its root shows the
2128
+ // checked operator's label.
2129
+ const nestedOperatorOptions = useMemo(
2130
+ () =>
2131
+ draftOperator == null
2132
+ ? []
2133
+ : [
2134
+ {
2135
+ value: draftOperator.key,
2136
+ label: resolveOperatorLabel(draftOperator, t),
2137
+ },
2138
+ ],
2139
+ [draftOperator, t],
2140
+ );
2141
+ const handleNestedDraftChange = useCallback((next: PartialFilter) => {
2142
+ setDraft(current =>
2143
+ current == null ? current : {...current, value: next.value},
2144
+ );
2145
+ }, []);
2146
+
2147
+ const valueEditor =
2148
+ isDraftRenderable &&
2149
+ (isDraftNested ? (
2150
+ <NestedEditor
2151
+ key={`${draft.generation}-${draft.field}-${draft.operator}`}
2152
+ config={config}
2153
+ partialFilter={{
2154
+ field: draft.field,
2155
+ operator: draft.operator,
2156
+ value: draft.value,
2157
+ }}
2158
+ operatorOptions={nestedOperatorOptions}
2159
+ hasRootOperatorPicker={false}
2160
+ onOperatorChange={() => {}}
2161
+ onPartialFilterChange={handleNestedDraftChange}
2162
+ maxMenuItems={maxOperatorMenuItems}
2163
+ timezoneID={timezoneID}
2164
+ isReadOnly={isEditorDisabled}
2165
+ xstyle={styles.nestedEditorContainer}
2166
+ />
2167
+ ) : (
2168
+ <SheetValueEditor
2169
+ key={`${draft.generation}-${draft.field}-${draft.operator}`}
2170
+ operatorValue={draftOperator.value}
2171
+ filterValue={draft.value}
2172
+ onChange={handleDraftValueChange}
2173
+ onUnstage={handleDraftUnstage}
2174
+ config={config}
2175
+ fieldLabel={draftField.label}
2176
+ isDisabled={isEditorDisabled}
2177
+ maxMenuItems={maxOperatorMenuItems}
2178
+ timezoneID={timezoneID}
2179
+ editors={editors}
2180
+ />
2181
+ ));
2182
+
2183
+ return (
2184
+ <>
2185
+ <BottomSheet
2186
+ isOpen={isManageSheetOpen}
2187
+ onOpenChange={handleManageOpenChange}
2188
+ finalFocusRef={finalFocusRef}
2189
+ label={t('@astryx.powersearch.sheet.filtersTitle')}
2190
+ height="tall"
2191
+ padding={0}>
2192
+ <div
2193
+ ref={manageSheetRef}
2194
+ onFocus={noteSheetFocus('manage')}
2195
+ {...stylex.props(styles.sheet, styles.sheetWithFixedFooter)}>
2196
+ {step === 'manage' && (
2197
+ <SheetAnnouncer onAnnounceChange={handleAnnounceChange} />
2198
+ )}
2199
+ <div {...stylex.props(styles.header)}>
2200
+ <div {...stylex.props(styles.headerRow)}>
2201
+ <div {...stylex.props(styles.headerText)}>
2202
+ <Heading level={3}>
2203
+ {t('@astryx.powersearch.sheet.filtersTitle')}
2204
+ </Heading>
2205
+ </div>
2206
+ {isInteractive && filterRows.length > 0 && (
2207
+ <Button
2208
+ ref={managerAddButtonRef}
2209
+ label={t('@astryx.powersearch.sheet.addFilter')}
2210
+ icon={<Icon icon={PlusIcon} size="sm" />}
2211
+ isIconOnly
2212
+ variant="secondary"
2213
+ size="md"
2214
+ xstyle={styles.touchHitArea}
2215
+ onClick={openFieldList}
2216
+ />
2217
+ )}
2218
+ </div>
2219
+ </div>
2220
+ <div {...stylex.props(styles.scrollViewport)}>
2221
+ <div {...scrollContentProps}>
2222
+ {filterRows.length === 0 ? (
2223
+ // With no filter the single thing to do is the only visible
2224
+ // action. Mounted only while the sheet is open, so its text
2225
+ // is spoken in this sheet when it appears.
2226
+ isManageSheetOpen && (
2227
+ <EmptyState
2228
+ title={t(
2229
+ isDraftDirty
2230
+ ? '@astryx.powersearch.sheet.noFiltersInDraft'
2231
+ : '@astryx.powersearch.sheet.noFilters',
2232
+ )}
2233
+ description={t(
2234
+ '@astryx.powersearch.sheet.noFiltersDescription',
2235
+ )}
2236
+ headingLevel={4}
2237
+ icon={<Icon icon="funnel" size="lg" color="secondary" />}
2238
+ xstyle={styles.emptyState}
2239
+ actions={
2240
+ isInteractive ? (
2241
+ <Button
2242
+ ref={managerAddButtonRef}
2243
+ label={t('@astryx.powersearch.sheet.addFilter')}
2244
+ icon={<Icon icon={PlusIcon} size="sm" />}
2245
+ variant="primary"
2246
+ size="lg"
2247
+ xstyle={styles.touchHitArea}
2248
+ onClick={openFieldList}
2249
+ />
2250
+ ) : undefined
2251
+ }
2252
+ />
2253
+ )
2254
+ ) : (
2255
+ <List hasDividers density="spacious" edge="bleed">
2256
+ {filterRows.map(row => {
2257
+ const operator = config.getOperator(
2258
+ row.filter.field,
2259
+ row.filter.operator,
2260
+ );
2261
+ const fieldLabel =
2262
+ config.getField(row.filter.field)?.label ??
2263
+ row.filter.field;
2264
+ // A one-tap filter has no value to edit: its row removes
2265
+ // it.
2266
+ const isOneTap = operator?.value.type === 'empty';
2267
+ const removeLabel = t(
2268
+ '@astryx.powersearch.sheet.removeFilter',
2269
+ {field: fieldLabel},
2270
+ );
2271
+ return (
2272
+ <ListItem
2273
+ key={row.key}
2274
+ ref={node => {
2275
+ if (node == null) {
2276
+ managerRowsRef.current.delete(row.index);
2277
+ } else {
2278
+ managerRowsRef.current.set(row.index, node);
2279
+ }
2280
+ }}
2281
+ label={row.displayLabel}
2282
+ onClick={
2283
+ row.isEditable
2284
+ ? isOneTap
2285
+ ? () => handleRemoveFilter(row.index)
2286
+ : () => handleFilterEdit(row.index)
2287
+ : undefined
2288
+ }
2289
+ endContent={
2290
+ row.isEditable ? (
2291
+ <IconButton
2292
+ data-sheet-remove=""
2293
+ label={removeLabel}
2294
+ tooltip={removeLabel}
2295
+ icon={<Icon icon="close" size="sm" />}
2296
+ variant="ghost"
2297
+ size="md"
2298
+ xstyle={styles.touchHitArea}
2299
+ onClick={event => {
2300
+ event.stopPropagation();
2301
+ handleRemoveFilter(row.index);
2302
+ }}
2303
+ />
2304
+ ) : undefined
2305
+ }
2306
+ />
2307
+ );
2308
+ })}
2309
+ </List>
2310
+ )}
2311
+ </div>
2312
+ </div>
2313
+ {/* The footer stays while the draft differs from the applied
2314
+ filters: an emptied draft still needs Done to apply the
2315
+ removals. */}
2316
+ {(filterRows.length > 0 || isDraftDirty) && (
2317
+ <div {...stylex.props(styles.footer, styles.fixedFooter)}>
2318
+ {isClearAllShown && (
2319
+ <Button
2320
+ ref={clearAllButtonRef}
2321
+ label={t('@astryx.powersearch.sheet.clearAll')}
2322
+ variant="secondary"
2323
+ size="lg"
2324
+ xstyle={styles.footerEqualAction}
2325
+ onClick={() => setIsClearConfirmationOpen(true)}
2326
+ />
2327
+ )}
2328
+ <Button
2329
+ label={t('@astryx.powersearch.sheet.done')}
2330
+ variant="primary"
2331
+ size="lg"
2332
+ xstyle={
2333
+ isClearAllShown
2334
+ ? styles.footerEqualAction
2335
+ : [styles.footerSoleAction, styles.touchHitArea]
2336
+ }
2337
+ onClick={commitAndClose}
2338
+ width={isClearAllShown ? undefined : '100%'}
2339
+ />
2340
+ </div>
2341
+ )}
2342
+ </div>
2343
+ </BottomSheet>
2344
+
2345
+ <BottomSheet
2346
+ isOpen={isFieldsSheetOpen}
2347
+ onOpenChange={handleFieldsOpenChange}
2348
+ finalFocusRef={stepFinalFocusRef}
2349
+ label={t('@astryx.powersearch.sheet.addFilter')}
2350
+ height="tall"
2351
+ padding={0}>
2352
+ <div
2353
+ ref={fieldsSheetCallbackRef}
2354
+ onFocus={noteSheetFocus('fields')}
2355
+ onKeyDown={hasContentSearch ? handleContentListKeyDown : undefined}
2356
+ {...stylex.props(styles.sheet, styles.sheetWithFixedFooter)}>
2357
+ {step === 'fields' && (
2358
+ <SheetAnnouncer onAnnounceChange={handleAnnounceChange} />
2359
+ )}
2360
+ <div {...stylex.props(styles.header)}>
2361
+ <div {...stylex.props(styles.headerRow)}>
2362
+ <div {...stylex.props(styles.headerText)}>
2363
+ <Heading level={3}>
2364
+ {t('@astryx.powersearch.sheet.addFilter')}
2365
+ </Heading>
2366
+ </div>
2367
+ </div>
2368
+ {hasContentSearch ? (
2369
+ <div ref={contentSearchRef}>
2370
+ <TextInput
2371
+ label={t('@astryx.powersearch.sheet.search')}
2372
+ isLabelHidden
2373
+ role="searchbox"
2374
+ aria-controls={contentResultsId}
2375
+ value={contentQuery}
2376
+ onChange={setContentQuery}
2377
+ onKeyDown={event => {
2378
+ if (isImeKeyEvent(event.nativeEvent)) {
2379
+ return;
2380
+ }
2381
+ if (event.key === 'Enter' && contentResults[0] != null) {
2382
+ event.preventDefault();
2383
+ handleContentSuggestionSelect(contentResults[0]);
2384
+ }
2385
+ }}
2386
+ placeholder={placeholder}
2387
+ hasClear
2388
+ startIcon={<Icon icon="search" size="sm" color="secondary" />}
2389
+ isDisabled={!isInteractive}
2390
+ size="lg"
2391
+ width="100%"
2392
+ />
2393
+ </div>
2394
+ ) : isFieldSearchShown ? (
2395
+ <div ref={fieldSearchRef}>
2396
+ <TextInput
2397
+ label={t('@astryx.powersearch.sheet.searchFields')}
2398
+ isLabelHidden
2399
+ placeholder={t(
2400
+ '@astryx.powersearch.sheet.searchFieldsPlaceholder',
2401
+ )}
2402
+ value={fieldQuery}
2403
+ onChange={setFieldQuery}
2404
+ startIcon={<Icon icon="search" size="sm" color="secondary" />}
2405
+ isDisabled={!isInteractive}
2406
+ size="lg"
2407
+ width="100%"
2408
+ />
2409
+ </div>
2410
+ ) : null}
2411
+ </div>
2412
+ <div
2413
+ {...stylex.props(styles.scrollViewport)}
2414
+ {...fieldPickerDragProps}>
2415
+ <div {...scrollContentProps}>
2416
+ {hasContentSearch ? (
2417
+ contentResults.length > 0 ? (
2418
+ <List
2419
+ id={contentResultsId}
2420
+ aria-label={t('@astryx.powersearch.sheet.searchResults')}
2421
+ hasDividers
2422
+ density="spacious"
2423
+ edge="bleed">
2424
+ {contentResults.map(item => (
2425
+ <ListItem
2426
+ key={item.id}
2427
+ label={item.label}
2428
+ isDisabled={!isInteractive}
2429
+ onClick={() => handleContentSuggestionSelect(item)}
2430
+ />
2431
+ ))}
2432
+ </List>
2433
+ ) : contentQuery.trim() !== '' ? (
2434
+ // The searchbox's `aria-controls` target while nothing
2435
+ // lists. The empty state mounts only while this step is the
2436
+ // open one and is spoken from its rendered text, once per
2437
+ // query that matches nothing.
2438
+ <div id={contentResultsId}>
2439
+ {step === 'fields' && (
2440
+ <EmptyState
2441
+ key={contentQuery}
2442
+ icon={
2443
+ <Icon icon="search" size="lg" color="secondary" />
2444
+ }
2445
+ title={t('@astryx.powersearch.sheet.noResults')}
2446
+ description={t(
2447
+ '@astryx.powersearch.sheet.tryDifferentSearch',
2448
+ )}
2449
+ headingLevel={4}
2450
+ isCompact
2451
+ xstyle={styles.emptyState}
2452
+ />
2453
+ )}
2454
+ </div>
2455
+ ) : (
2456
+ // An empty query with no bootstrap suggestion: the results
2457
+ // region exists, empty, so the searchbox's `aria-controls`
2458
+ // always names an element in the document.
2459
+ <div id={contentResultsId} />
2460
+ )
2461
+ ) : groupedFields.length === 0 ? (
2462
+ // A search outcome: only a non-empty query that matches
2463
+ // nothing shows it; a config with no field lists nothing.
2464
+ normalizedFieldQuery !== '' &&
2465
+ step === 'fields' && (
2466
+ <EmptyState
2467
+ key={normalizedFieldQuery}
2468
+ icon={<Icon icon="search" size="lg" color="secondary" />}
2469
+ title={t('@astryx.powersearch.sheet.noMatchingFields')}
2470
+ description={t(
2471
+ '@astryx.powersearch.sheet.tryDifferentSearch',
2472
+ )}
2473
+ headingLevel={4}
2474
+ isCompact
2475
+ xstyle={styles.emptyState}
2476
+ />
2477
+ )
2478
+ ) : (
2479
+ groupedFields.map(([group, groupFields]) => (
2480
+ <List
2481
+ key={group}
2482
+ hasDividers
2483
+ density="spacious"
2484
+ header={
2485
+ <Heading level={4}>
2486
+ {group === ''
2487
+ ? t('@astryx.powersearch.sheet.ungroupedFields')
2488
+ : group}
2489
+ </Heading>
2490
+ }
2491
+ edge="bleed">
2492
+ {groupFields.map(field => (
2493
+ <ListItem
2494
+ key={field.key}
2495
+ ref={node => {
2496
+ if (node == null) {
2497
+ fieldRowsRef.current.delete(field.key);
2498
+ } else {
2499
+ fieldRowsRef.current.set(field.key, node);
2500
+ }
2501
+ }}
2502
+ label={field.label}
2503
+ isDisabled={!isInteractive}
2504
+ startContent={field.icon}
2505
+ endContent={
2506
+ isImmediateAddField(field) ? (
2507
+ <Icon icon={PlusIcon} size="sm" color="secondary" />
2508
+ ) : (
2509
+ <Icon
2510
+ icon="chevronRight"
2511
+ size="sm"
2512
+ color="secondary"
2513
+ xstyle={rtlStyles.mirror}
2514
+ />
2515
+ )
2516
+ }
2517
+ onClick={() => handleFieldSelect(field)}
2518
+ />
2519
+ ))}
2520
+ </List>
2521
+ ))
2522
+ )}
2523
+ </div>
2524
+ </div>
2525
+ {isFieldPickerDirectEntry && (
2526
+ <div {...stylex.props(styles.footer, styles.fixedFooter)}>
2527
+ <Button
2528
+ label={t('@astryx.powersearch.sheet.done')}
2529
+ variant="primary"
2530
+ width="100%"
2531
+ xstyle={styles.touchAction}
2532
+ onClick={commitAndClose}
2533
+ />
2534
+ </div>
2535
+ )}
2536
+ </div>
2537
+ </BottomSheet>
2538
+
2539
+ <BottomSheet
2540
+ isOpen={step === 'value'}
2541
+ onOpenChange={handleValueOpenChange}
2542
+ finalFocusRef={stepFinalFocusRef}
2543
+ label={editorTitle}
2544
+ height="tall"
2545
+ padding={0}
2546
+ purpose="info">
2547
+ <div {...stylex.props(styles.sheet)}>
2548
+ <div {...stylex.props(styles.header)}>
2549
+ <div {...stylex.props(styles.headerRow)}>
2550
+ <div {...stylex.props(styles.headerText)}>
2551
+ <Heading level={3} maxLines={1}>
2552
+ {editorTitle}
2553
+ </Heading>
2554
+ </div>
2555
+ </div>
2556
+ </div>
2557
+ {isDraftRenderable && EditorOverride != null ? (
2558
+ <div {...bodyProps}>
2559
+ {step === 'value' && (
2560
+ <SheetAnnouncer onAnnounceChange={handleAnnounceChange} />
2561
+ )}
2562
+ {operatorGroup && (
2563
+ <div {...controlSectionProps}>{operatorGroup}</div>
2564
+ )}
2565
+ <EditorOverride
2566
+ key={`${draft.generation}-${draft.field}-${draft.operator}`}
2567
+ config={configProp}
2568
+ filter={{
2569
+ field: draft.field,
2570
+ operator: draft.operator,
2571
+ value: draft.value,
2572
+ }}
2573
+ mode={draft.mode}
2574
+ onSave={saved => {
2575
+ if (saved == null) {
2576
+ if (draft.mode === 'edit') {
2577
+ handleRemove();
2578
+ } else {
2579
+ queueManagerAddFocus();
2580
+ setStep('manage');
2581
+ }
2582
+ return;
2583
+ }
2584
+ commitSavedFilter(draft, saved);
2585
+ }}
2586
+ onCancel={returnFromValue}
2587
+ saveButtonLabel={saveButtonLabel}
2588
+ isReadOnly={isEditorDisabled}
2589
+ timezoneID={timezoneID}
2590
+ />
2591
+ </div>
2592
+ ) : (
2593
+ <>
2594
+ <div {...bodyProps}>
2595
+ {step === 'value' && (
2596
+ <SheetAnnouncer onAnnounceChange={handleAnnounceChange} />
2597
+ )}
2598
+ {isDraftRenderable ? (
2599
+ // A lone editor sits on the sheet's surface; with the
2600
+ // Operator group above it, each section is a muted
2601
+ // container.
2602
+ operatorGroup ? (
2603
+ <>
2604
+ <div {...controlSectionProps}>{operatorGroup}</div>
2605
+ <div {...controlSectionProps}>{valueEditor}</div>
2606
+ </>
2607
+ ) : (
2608
+ valueEditor
2609
+ )
2610
+ ) : (
2611
+ // A controlled config update removed the field or operator
2612
+ // being edited: say so (the element's rendered text is
2613
+ // announced, once per opened filter, while this step is the
2614
+ // open one) and keep a way out.
2615
+ draft != null && (
2616
+ <SheetEmptyMessage
2617
+ message={t('@astryx.powersearch.sheet.filterUnavailable')}
2618
+ occasion={String(draft.generation)}
2619
+ isShown={step === 'value'}
2620
+ />
2621
+ )
2622
+ )}
2623
+ </div>
2624
+ <div {...stylex.props(styles.footer)}>
2625
+ {isReadOnly ? (
2626
+ <Button
2627
+ ref={cancelButtonRef}
2628
+ label={t('@astryx.powersearch.editor.cancel')}
2629
+ variant="secondary"
2630
+ width="100%"
2631
+ xstyle={[styles.footerSoleAction, styles.touchHitArea]}
2632
+ onClick={returnFromValue}
2633
+ />
2634
+ ) : (
2635
+ <>
2636
+ <Button
2637
+ ref={cancelButtonRef}
2638
+ label={t('@astryx.powersearch.editor.cancel')}
2639
+ variant="secondary"
2640
+ size="lg"
2641
+ xstyle={styles.footerEqualAction}
2642
+ onClick={returnFromValue}
2643
+ />
2644
+ {isDraftRenderable && (
2645
+ <Button
2646
+ label={saveButtonLabel}
2647
+ variant="primary"
2648
+ size="lg"
2649
+ isDisabled={isSaveDisabled}
2650
+ xstyle={styles.footerEqualAction}
2651
+ onClick={handleSave}
2652
+ />
2653
+ )}
2654
+ </>
2655
+ )}
2656
+ </div>
2657
+ </>
2658
+ )}
2659
+ </div>
2660
+ </BottomSheet>
2661
+
2662
+ {isClearConfirmationOpen && (
2663
+ <SheetConfirmation
2664
+ isOpen
2665
+ onOpenChange={isConfirmationOpen => {
2666
+ if (!isConfirmationOpen) {
2667
+ closeClearConfirmation(false);
2668
+ }
2669
+ }}
2670
+ title={t('@astryx.powersearch.sheet.clearAllTitle')}
2671
+ description={t('@astryx.powersearch.sheet.clearAllDescription')}
2672
+ actionLabel={t('@astryx.powersearch.sheet.clearAllConfirm')}
2673
+ cancelLabel={t('@astryx.powersearch.sheet.clearAllCancel')}
2674
+ onAction={() => closeClearConfirmation(true)}
2675
+ />
2676
+ )}
2677
+ {isDiscardConfirmationOpen && (
2678
+ <SheetConfirmation
2679
+ isOpen
2680
+ onOpenChange={isConfirmationOpen => {
2681
+ if (!isConfirmationOpen) {
2682
+ closeDiscardConfirmation();
2683
+ }
2684
+ }}
2685
+ title={t('@astryx.powersearch.sheet.discardTitle')}
2686
+ description={t('@astryx.powersearch.sheet.discardDescription')}
2687
+ actionLabel={t('@astryx.powersearch.sheet.discardConfirm')}
2688
+ cancelLabel={t('@astryx.powersearch.sheet.keepEditing')}
2689
+ onAction={() => {
2690
+ setIsDiscardConfirmationOpen(false);
2691
+ draftEditsRef.current = [];
2692
+ closeFlow();
2693
+ }}
2694
+ />
2695
+ )}
2696
+ </>
2697
+ );
2698
+ }
2699
+
2700
+ PowerSearchBottomSheet.displayName = 'PowerSearchBottomSheet';