react-stately 3.46.0 → 3.47.0

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 (496) hide show
  1. package/dist/exports/Color.cjs.map +1 -1
  2. package/dist/exports/Color.js.map +1 -1
  3. package/dist/exports/Color.mjs.map +1 -1
  4. package/dist/exports/index.cjs.map +1 -1
  5. package/dist/exports/index.js.map +1 -1
  6. package/dist/exports/index.mjs.map +1 -1
  7. package/dist/exports/private/autocomplete/useAutocompleteState.cjs.map +1 -1
  8. package/dist/exports/private/autocomplete/useAutocompleteState.js.map +1 -1
  9. package/dist/exports/private/autocomplete/useAutocompleteState.mjs.map +1 -1
  10. package/dist/exports/private/collections/getChildNodes.cjs.map +1 -1
  11. package/dist/exports/private/collections/getChildNodes.js.map +1 -1
  12. package/dist/exports/private/collections/getChildNodes.mjs.map +1 -1
  13. package/dist/exports/private/flags/flags.cjs.map +1 -1
  14. package/dist/exports/private/flags/flags.js.map +1 -1
  15. package/dist/exports/private/flags/flags.mjs.map +1 -1
  16. package/dist/exports/private/form/useFormValidationState.cjs.map +1 -1
  17. package/dist/exports/private/form/useFormValidationState.js.map +1 -1
  18. package/dist/exports/private/form/useFormValidationState.mjs.map +1 -1
  19. package/dist/exports/private/grid/GridCollection.cjs.map +1 -1
  20. package/dist/exports/private/grid/GridCollection.js.map +1 -1
  21. package/dist/exports/private/grid/GridCollection.mjs.map +1 -1
  22. package/dist/exports/private/steplist/useStepListState.cjs.map +1 -1
  23. package/dist/exports/private/steplist/useStepListState.js.map +1 -1
  24. package/dist/exports/private/steplist/useStepListState.mjs.map +1 -1
  25. package/dist/exports/private/table/TableCollection.cjs.map +1 -1
  26. package/dist/exports/private/table/TableCollection.js.map +1 -1
  27. package/dist/exports/private/table/TableCollection.mjs.map +1 -1
  28. package/dist/exports/private/table/useTreeGridState.cjs.map +1 -1
  29. package/dist/exports/private/table/useTreeGridState.js.map +1 -1
  30. package/dist/exports/private/table/useTreeGridState.mjs.map +1 -1
  31. package/dist/exports/useAsyncList.cjs.map +1 -1
  32. package/dist/exports/useAsyncList.js.map +1 -1
  33. package/dist/exports/useAsyncList.mjs.map +1 -1
  34. package/dist/exports/useCalendarState.cjs.map +1 -1
  35. package/dist/exports/useCalendarState.js.map +1 -1
  36. package/dist/exports/useCalendarState.mjs.map +1 -1
  37. package/dist/exports/useColorAreaState.cjs.map +1 -1
  38. package/dist/exports/useColorAreaState.js.map +1 -1
  39. package/dist/exports/useColorAreaState.mjs.map +1 -1
  40. package/dist/exports/useColorFieldState.cjs.map +1 -1
  41. package/dist/exports/useColorFieldState.js.map +1 -1
  42. package/dist/exports/useColorFieldState.mjs.map +1 -1
  43. package/dist/exports/useColorPickerState.cjs.map +1 -1
  44. package/dist/exports/useColorPickerState.js.map +1 -1
  45. package/dist/exports/useColorPickerState.mjs.map +1 -1
  46. package/dist/exports/useColorSliderState.cjs.map +1 -1
  47. package/dist/exports/useColorSliderState.js.map +1 -1
  48. package/dist/exports/useColorSliderState.mjs.map +1 -1
  49. package/dist/exports/useColorWheelState.cjs.map +1 -1
  50. package/dist/exports/useColorWheelState.js.map +1 -1
  51. package/dist/exports/useColorWheelState.mjs.map +1 -1
  52. package/dist/exports/useComboBoxState.cjs +1 -1
  53. package/dist/exports/useComboBoxState.cjs.map +1 -1
  54. package/dist/exports/useComboBoxState.js +1 -1
  55. package/dist/exports/useComboBoxState.js.map +1 -1
  56. package/dist/exports/useComboBoxState.mjs +1 -1
  57. package/dist/exports/useComboBoxState.mjs.map +1 -1
  58. package/dist/exports/useDateFieldState.cjs.map +1 -1
  59. package/dist/exports/useDateFieldState.js.map +1 -1
  60. package/dist/exports/useDateFieldState.mjs.map +1 -1
  61. package/dist/exports/useDatePickerState.cjs.map +1 -1
  62. package/dist/exports/useDatePickerState.js.map +1 -1
  63. package/dist/exports/useDatePickerState.mjs.map +1 -1
  64. package/dist/exports/useDateRangePickerState.cjs.map +1 -1
  65. package/dist/exports/useDateRangePickerState.js.map +1 -1
  66. package/dist/exports/useDateRangePickerState.mjs.map +1 -1
  67. package/dist/exports/useDisclosureGroupState.cjs.map +1 -1
  68. package/dist/exports/useDisclosureGroupState.js.map +1 -1
  69. package/dist/exports/useDisclosureGroupState.mjs.map +1 -1
  70. package/dist/exports/useDraggableCollectionState.cjs.map +1 -1
  71. package/dist/exports/useDraggableCollectionState.js.map +1 -1
  72. package/dist/exports/useDraggableCollectionState.mjs.map +1 -1
  73. package/dist/exports/useDroppableCollectionState.cjs.map +1 -1
  74. package/dist/exports/useDroppableCollectionState.js.map +1 -1
  75. package/dist/exports/useDroppableCollectionState.mjs.map +1 -1
  76. package/dist/exports/useMenuTriggerState.cjs.map +1 -1
  77. package/dist/exports/useMenuTriggerState.js.map +1 -1
  78. package/dist/exports/useMenuTriggerState.mjs.map +1 -1
  79. package/dist/exports/useMultipleSelectionState.cjs.map +1 -1
  80. package/dist/exports/useMultipleSelectionState.js.map +1 -1
  81. package/dist/exports/useMultipleSelectionState.mjs.map +1 -1
  82. package/dist/exports/useOverlayTriggerState.cjs.map +1 -1
  83. package/dist/exports/useOverlayTriggerState.js.map +1 -1
  84. package/dist/exports/useOverlayTriggerState.mjs.map +1 -1
  85. package/dist/exports/useRangeCalendarState.cjs.map +1 -1
  86. package/dist/exports/useRangeCalendarState.js.map +1 -1
  87. package/dist/exports/useRangeCalendarState.mjs.map +1 -1
  88. package/dist/exports/useSelectState.cjs.map +1 -1
  89. package/dist/exports/useSelectState.js.map +1 -1
  90. package/dist/exports/useSelectState.mjs.map +1 -1
  91. package/dist/exports/useSingleSelectListState.cjs.map +1 -1
  92. package/dist/exports/useSingleSelectListState.js.map +1 -1
  93. package/dist/exports/useSingleSelectListState.mjs.map +1 -1
  94. package/dist/exports/useTableState.cjs.map +1 -1
  95. package/dist/exports/useTableState.js.map +1 -1
  96. package/dist/exports/useTableState.mjs.map +1 -1
  97. package/dist/exports/useTimeFieldState.cjs.map +1 -1
  98. package/dist/exports/useTimeFieldState.js.map +1 -1
  99. package/dist/exports/useTimeFieldState.mjs.map +1 -1
  100. package/dist/exports/useToastState.cjs.map +1 -1
  101. package/dist/exports/useToastState.js.map +1 -1
  102. package/dist/exports/useToastState.mjs.map +1 -1
  103. package/dist/private/autocomplete/useAutocompleteState.cjs.map +1 -1
  104. package/dist/private/autocomplete/useAutocompleteState.js.map +1 -1
  105. package/dist/private/autocomplete/useAutocompleteState.mjs.map +1 -1
  106. package/dist/private/calendar/useCalendarState.cjs +82 -30
  107. package/dist/private/calendar/useCalendarState.cjs.map +1 -1
  108. package/dist/private/calendar/useCalendarState.js +85 -32
  109. package/dist/private/calendar/useCalendarState.js.map +1 -1
  110. package/dist/private/calendar/useCalendarState.mjs +84 -32
  111. package/dist/private/calendar/useCalendarState.mjs.map +1 -1
  112. package/dist/private/calendar/useRangeCalendarState.cjs +53 -40
  113. package/dist/private/calendar/useRangeCalendarState.cjs.map +1 -1
  114. package/dist/private/calendar/useRangeCalendarState.js +55 -43
  115. package/dist/private/calendar/useRangeCalendarState.js.map +1 -1
  116. package/dist/private/calendar/useRangeCalendarState.mjs +55 -42
  117. package/dist/private/calendar/useRangeCalendarState.mjs.map +1 -1
  118. package/dist/private/calendar/utils.cjs +6 -1
  119. package/dist/private/calendar/utils.cjs.map +1 -1
  120. package/dist/private/calendar/utils.js +6 -2
  121. package/dist/private/calendar/utils.js.map +1 -1
  122. package/dist/private/calendar/utils.mjs +6 -2
  123. package/dist/private/calendar/utils.mjs.map +1 -1
  124. package/dist/private/checkbox/useCheckboxGroupState.cjs.map +1 -1
  125. package/dist/private/checkbox/useCheckboxGroupState.js.map +1 -1
  126. package/dist/private/checkbox/useCheckboxGroupState.mjs.map +1 -1
  127. package/dist/private/collections/CollectionBuilder.cjs.map +1 -1
  128. package/dist/private/collections/CollectionBuilder.js.map +1 -1
  129. package/dist/private/collections/CollectionBuilder.mjs.map +1 -1
  130. package/dist/private/collections/Item.cjs +1 -0
  131. package/dist/private/collections/Item.cjs.map +1 -1
  132. package/dist/private/collections/Item.js +1 -0
  133. package/dist/private/collections/Item.js.map +1 -1
  134. package/dist/private/collections/Item.mjs +1 -0
  135. package/dist/private/collections/Item.mjs.map +1 -1
  136. package/dist/private/collections/Section.cjs +1 -0
  137. package/dist/private/collections/Section.cjs.map +1 -1
  138. package/dist/private/collections/Section.js +1 -0
  139. package/dist/private/collections/Section.js.map +1 -1
  140. package/dist/private/collections/Section.mjs +1 -0
  141. package/dist/private/collections/Section.mjs.map +1 -1
  142. package/dist/private/collections/getChildNodes.cjs.map +1 -1
  143. package/dist/private/collections/getChildNodes.js.map +1 -1
  144. package/dist/private/collections/getChildNodes.mjs.map +1 -1
  145. package/dist/private/collections/useCollection.cjs.map +1 -1
  146. package/dist/private/collections/useCollection.js.map +1 -1
  147. package/dist/private/collections/useCollection.mjs.map +1 -1
  148. package/dist/private/color/Color.cjs +15 -9
  149. package/dist/private/color/Color.cjs.map +1 -1
  150. package/dist/private/color/Color.js +15 -9
  151. package/dist/private/color/Color.js.map +1 -1
  152. package/dist/private/color/Color.mjs +15 -9
  153. package/dist/private/color/Color.mjs.map +1 -1
  154. package/dist/private/color/useColorAreaState.cjs.map +1 -1
  155. package/dist/private/color/useColorAreaState.js.map +1 -1
  156. package/dist/private/color/useColorAreaState.mjs.map +1 -1
  157. package/dist/private/color/useColorChannelFieldState.cjs.map +1 -1
  158. package/dist/private/color/useColorChannelFieldState.js.map +1 -1
  159. package/dist/private/color/useColorChannelFieldState.mjs.map +1 -1
  160. package/dist/private/color/useColorFieldState.cjs.map +1 -1
  161. package/dist/private/color/useColorFieldState.js.map +1 -1
  162. package/dist/private/color/useColorFieldState.mjs.map +1 -1
  163. package/dist/private/color/useColorPickerState.cjs.map +1 -1
  164. package/dist/private/color/useColorPickerState.js.map +1 -1
  165. package/dist/private/color/useColorPickerState.mjs.map +1 -1
  166. package/dist/private/color/useColorSliderState.cjs +5 -3
  167. package/dist/private/color/useColorSliderState.cjs.map +1 -1
  168. package/dist/private/color/useColorSliderState.js +5 -3
  169. package/dist/private/color/useColorSliderState.js.map +1 -1
  170. package/dist/private/color/useColorSliderState.mjs +5 -3
  171. package/dist/private/color/useColorSliderState.mjs.map +1 -1
  172. package/dist/private/color/useColorWheelState.cjs.map +1 -1
  173. package/dist/private/color/useColorWheelState.js.map +1 -1
  174. package/dist/private/color/useColorWheelState.mjs.map +1 -1
  175. package/dist/private/combobox/useComboBoxState.cjs +8 -2
  176. package/dist/private/combobox/useComboBoxState.cjs.map +1 -1
  177. package/dist/private/combobox/useComboBoxState.js +8 -2
  178. package/dist/private/combobox/useComboBoxState.js.map +1 -1
  179. package/dist/private/combobox/useComboBoxState.mjs +8 -2
  180. package/dist/private/combobox/useComboBoxState.mjs.map +1 -1
  181. package/dist/private/data/useAsyncList.cjs.map +1 -1
  182. package/dist/private/data/useAsyncList.js.map +1 -1
  183. package/dist/private/data/useAsyncList.mjs.map +1 -1
  184. package/dist/private/data/useListData.cjs.map +1 -1
  185. package/dist/private/data/useListData.js.map +1 -1
  186. package/dist/private/data/useListData.mjs.map +1 -1
  187. package/dist/private/data/useTreeData.cjs.map +1 -1
  188. package/dist/private/data/useTreeData.js.map +1 -1
  189. package/dist/private/data/useTreeData.mjs.map +1 -1
  190. package/dist/private/datepicker/IncompleteDate.cjs +8 -2
  191. package/dist/private/datepicker/IncompleteDate.cjs.map +1 -1
  192. package/dist/private/datepicker/IncompleteDate.js +8 -2
  193. package/dist/private/datepicker/IncompleteDate.js.map +1 -1
  194. package/dist/private/datepicker/IncompleteDate.mjs +8 -2
  195. package/dist/private/datepicker/IncompleteDate.mjs.map +1 -1
  196. package/dist/private/datepicker/placeholders.cjs +5 -0
  197. package/dist/private/datepicker/placeholders.cjs.map +1 -1
  198. package/dist/private/datepicker/placeholders.js +5 -0
  199. package/dist/private/datepicker/placeholders.js.map +1 -1
  200. package/dist/private/datepicker/placeholders.mjs +5 -0
  201. package/dist/private/datepicker/placeholders.mjs.map +1 -1
  202. package/dist/private/datepicker/useDateFieldState.cjs.map +1 -1
  203. package/dist/private/datepicker/useDateFieldState.js.map +1 -1
  204. package/dist/private/datepicker/useDateFieldState.mjs.map +1 -1
  205. package/dist/private/datepicker/useDatePickerState.cjs.map +1 -1
  206. package/dist/private/datepicker/useDatePickerState.js.map +1 -1
  207. package/dist/private/datepicker/useDatePickerState.mjs.map +1 -1
  208. package/dist/private/datepicker/useDateRangePickerState.cjs +1 -1
  209. package/dist/private/datepicker/useDateRangePickerState.cjs.map +1 -1
  210. package/dist/private/datepicker/useDateRangePickerState.js +1 -1
  211. package/dist/private/datepicker/useDateRangePickerState.js.map +1 -1
  212. package/dist/private/datepicker/useDateRangePickerState.mjs +1 -1
  213. package/dist/private/datepicker/useDateRangePickerState.mjs.map +1 -1
  214. package/dist/private/datepicker/useTimeFieldState.cjs.map +1 -1
  215. package/dist/private/datepicker/useTimeFieldState.js.map +1 -1
  216. package/dist/private/datepicker/useTimeFieldState.mjs.map +1 -1
  217. package/dist/private/datepicker/utils.cjs +2 -2
  218. package/dist/private/datepicker/utils.cjs.map +1 -1
  219. package/dist/private/datepicker/utils.js +2 -2
  220. package/dist/private/datepicker/utils.js.map +1 -1
  221. package/dist/private/datepicker/utils.mjs +2 -2
  222. package/dist/private/datepicker/utils.mjs.map +1 -1
  223. package/dist/private/disclosure/useDisclosureGroupState.cjs.map +1 -1
  224. package/dist/private/disclosure/useDisclosureGroupState.js.map +1 -1
  225. package/dist/private/disclosure/useDisclosureGroupState.mjs.map +1 -1
  226. package/dist/private/disclosure/useDisclosureState.cjs.map +1 -1
  227. package/dist/private/disclosure/useDisclosureState.js.map +1 -1
  228. package/dist/private/disclosure/useDisclosureState.mjs.map +1 -1
  229. package/dist/private/dnd/useDraggableCollectionState.cjs.map +1 -1
  230. package/dist/private/dnd/useDraggableCollectionState.js.map +1 -1
  231. package/dist/private/dnd/useDraggableCollectionState.mjs.map +1 -1
  232. package/dist/private/dnd/useDroppableCollectionState.cjs.map +1 -1
  233. package/dist/private/dnd/useDroppableCollectionState.js.map +1 -1
  234. package/dist/private/dnd/useDroppableCollectionState.mjs.map +1 -1
  235. package/dist/private/form/useFormValidationState.cjs.map +1 -1
  236. package/dist/private/form/useFormValidationState.js.map +1 -1
  237. package/dist/private/form/useFormValidationState.mjs.map +1 -1
  238. package/dist/private/grid/GridCollection.cjs.map +1 -1
  239. package/dist/private/grid/GridCollection.js.map +1 -1
  240. package/dist/private/grid/GridCollection.mjs.map +1 -1
  241. package/dist/private/grid/useGridState.cjs.map +1 -1
  242. package/dist/private/grid/useGridState.js.map +1 -1
  243. package/dist/private/grid/useGridState.mjs.map +1 -1
  244. package/dist/private/layout/GridLayout.cjs +8 -3
  245. package/dist/private/layout/GridLayout.cjs.map +1 -1
  246. package/dist/private/layout/GridLayout.js +8 -3
  247. package/dist/private/layout/GridLayout.js.map +1 -1
  248. package/dist/private/layout/GridLayout.mjs +8 -3
  249. package/dist/private/layout/GridLayout.mjs.map +1 -1
  250. package/dist/private/layout/ListLayout.cjs +1 -1
  251. package/dist/private/layout/ListLayout.cjs.map +1 -1
  252. package/dist/private/layout/ListLayout.js +2 -1
  253. package/dist/private/layout/ListLayout.js.map +1 -1
  254. package/dist/private/layout/ListLayout.mjs +1 -1
  255. package/dist/private/layout/ListLayout.mjs.map +1 -1
  256. package/dist/private/layout/TableLayout.cjs +60 -35
  257. package/dist/private/layout/TableLayout.cjs.map +1 -1
  258. package/dist/private/layout/TableLayout.js +65 -38
  259. package/dist/private/layout/TableLayout.js.map +1 -1
  260. package/dist/private/layout/TableLayout.mjs +61 -36
  261. package/dist/private/layout/TableLayout.mjs.map +1 -1
  262. package/dist/private/layout/WaterfallLayout.cjs.map +1 -1
  263. package/dist/private/layout/WaterfallLayout.js.map +1 -1
  264. package/dist/private/layout/WaterfallLayout.mjs.map +1 -1
  265. package/dist/private/list/ListCollection.cjs.map +1 -1
  266. package/dist/private/list/ListCollection.js.map +1 -1
  267. package/dist/private/list/ListCollection.mjs.map +1 -1
  268. package/dist/private/list/useListState.cjs.map +1 -1
  269. package/dist/private/list/useListState.js.map +1 -1
  270. package/dist/private/list/useListState.mjs.map +1 -1
  271. package/dist/private/list/useSingleSelectListState.cjs.map +1 -1
  272. package/dist/private/list/useSingleSelectListState.js.map +1 -1
  273. package/dist/private/list/useSingleSelectListState.mjs.map +1 -1
  274. package/dist/private/menu/useMenuTriggerState.cjs.map +1 -1
  275. package/dist/private/menu/useMenuTriggerState.js.map +1 -1
  276. package/dist/private/menu/useMenuTriggerState.mjs.map +1 -1
  277. package/dist/private/menu/useSubmenuTriggerState.cjs.map +1 -1
  278. package/dist/private/menu/useSubmenuTriggerState.js.map +1 -1
  279. package/dist/private/menu/useSubmenuTriggerState.mjs.map +1 -1
  280. package/dist/private/numberfield/useNumberFieldState.cjs +13 -1
  281. package/dist/private/numberfield/useNumberFieldState.cjs.map +1 -1
  282. package/dist/private/numberfield/useNumberFieldState.js +13 -1
  283. package/dist/private/numberfield/useNumberFieldState.js.map +1 -1
  284. package/dist/private/numberfield/useNumberFieldState.mjs +13 -1
  285. package/dist/private/numberfield/useNumberFieldState.mjs.map +1 -1
  286. package/dist/private/overlays/useOverlayTriggerState.cjs.map +1 -1
  287. package/dist/private/overlays/useOverlayTriggerState.js.map +1 -1
  288. package/dist/private/overlays/useOverlayTriggerState.mjs.map +1 -1
  289. package/dist/private/radio/useRadioGroupState.cjs.map +1 -1
  290. package/dist/private/radio/useRadioGroupState.js.map +1 -1
  291. package/dist/private/radio/useRadioGroupState.mjs.map +1 -1
  292. package/dist/private/searchfield/useSearchFieldState.cjs.map +1 -1
  293. package/dist/private/searchfield/useSearchFieldState.js.map +1 -1
  294. package/dist/private/searchfield/useSearchFieldState.mjs.map +1 -1
  295. package/dist/private/select/useSelectState.cjs.map +1 -1
  296. package/dist/private/select/useSelectState.js.map +1 -1
  297. package/dist/private/select/useSelectState.mjs.map +1 -1
  298. package/dist/private/selection/SelectionManager.cjs +2 -1
  299. package/dist/private/selection/SelectionManager.cjs.map +1 -1
  300. package/dist/private/selection/SelectionManager.js +3 -2
  301. package/dist/private/selection/SelectionManager.js.map +1 -1
  302. package/dist/private/selection/SelectionManager.mjs +2 -1
  303. package/dist/private/selection/SelectionManager.mjs.map +1 -1
  304. package/dist/private/selection/useMultipleSelectionState.cjs.map +1 -1
  305. package/dist/private/selection/useMultipleSelectionState.js.map +1 -1
  306. package/dist/private/selection/useMultipleSelectionState.mjs.map +1 -1
  307. package/dist/private/slider/useSliderState.cjs +22 -2
  308. package/dist/private/slider/useSliderState.cjs.map +1 -1
  309. package/dist/private/slider/useSliderState.js +22 -2
  310. package/dist/private/slider/useSliderState.js.map +1 -1
  311. package/dist/private/slider/useSliderState.mjs +22 -2
  312. package/dist/private/slider/useSliderState.mjs.map +1 -1
  313. package/dist/private/steplist/useStepListState.cjs.map +1 -1
  314. package/dist/private/steplist/useStepListState.js.map +1 -1
  315. package/dist/private/steplist/useStepListState.mjs.map +1 -1
  316. package/dist/private/table/Cell.cjs +2 -1
  317. package/dist/private/table/Cell.cjs.map +1 -1
  318. package/dist/private/table/Cell.js +2 -1
  319. package/dist/private/table/Cell.js.map +1 -1
  320. package/dist/private/table/Cell.mjs +2 -1
  321. package/dist/private/table/Cell.mjs.map +1 -1
  322. package/dist/private/table/Column.cjs +1 -0
  323. package/dist/private/table/Column.cjs.map +1 -1
  324. package/dist/private/table/Column.js +1 -0
  325. package/dist/private/table/Column.js.map +1 -1
  326. package/dist/private/table/Column.mjs +1 -0
  327. package/dist/private/table/Column.mjs.map +1 -1
  328. package/dist/private/table/Row.cjs +2 -1
  329. package/dist/private/table/Row.cjs.map +1 -1
  330. package/dist/private/table/Row.js +2 -1
  331. package/dist/private/table/Row.js.map +1 -1
  332. package/dist/private/table/Row.mjs +2 -1
  333. package/dist/private/table/Row.mjs.map +1 -1
  334. package/dist/private/table/TableBody.cjs +4 -2
  335. package/dist/private/table/TableBody.cjs.map +1 -1
  336. package/dist/private/table/TableBody.js +4 -2
  337. package/dist/private/table/TableBody.js.map +1 -1
  338. package/dist/private/table/TableBody.mjs +4 -2
  339. package/dist/private/table/TableBody.mjs.map +1 -1
  340. package/dist/private/table/TableCollection.cjs +1 -1
  341. package/dist/private/table/TableCollection.cjs.map +1 -1
  342. package/dist/private/table/TableCollection.js +1 -1
  343. package/dist/private/table/TableCollection.js.map +1 -1
  344. package/dist/private/table/TableCollection.mjs +1 -1
  345. package/dist/private/table/TableCollection.mjs.map +1 -1
  346. package/dist/private/table/TableColumnLayout.cjs +4 -1
  347. package/dist/private/table/TableColumnLayout.cjs.map +1 -1
  348. package/dist/private/table/TableColumnLayout.js +4 -1
  349. package/dist/private/table/TableColumnLayout.js.map +1 -1
  350. package/dist/private/table/TableColumnLayout.mjs +4 -1
  351. package/dist/private/table/TableColumnLayout.mjs.map +1 -1
  352. package/dist/private/table/TableHeader.cjs +4 -2
  353. package/dist/private/table/TableHeader.cjs.map +1 -1
  354. package/dist/private/table/TableHeader.js +4 -2
  355. package/dist/private/table/TableHeader.js.map +1 -1
  356. package/dist/private/table/TableHeader.mjs +4 -2
  357. package/dist/private/table/TableHeader.mjs.map +1 -1
  358. package/dist/private/table/TableUtils.cjs +1 -1
  359. package/dist/private/table/TableUtils.cjs.map +1 -1
  360. package/dist/private/table/TableUtils.js +1 -1
  361. package/dist/private/table/TableUtils.js.map +1 -1
  362. package/dist/private/table/TableUtils.mjs +1 -1
  363. package/dist/private/table/TableUtils.mjs.map +1 -1
  364. package/dist/private/table/useTableColumnResizeState.cjs.map +1 -1
  365. package/dist/private/table/useTableColumnResizeState.js.map +1 -1
  366. package/dist/private/table/useTableColumnResizeState.mjs.map +1 -1
  367. package/dist/private/table/useTableState.cjs +2 -1
  368. package/dist/private/table/useTableState.cjs.map +1 -1
  369. package/dist/private/table/useTableState.js +2 -1
  370. package/dist/private/table/useTableState.js.map +1 -1
  371. package/dist/private/table/useTableState.mjs +2 -1
  372. package/dist/private/table/useTableState.mjs.map +1 -1
  373. package/dist/private/table/useTreeGridState.cjs +2 -1
  374. package/dist/private/table/useTreeGridState.cjs.map +1 -1
  375. package/dist/private/table/useTreeGridState.js +2 -1
  376. package/dist/private/table/useTreeGridState.js.map +1 -1
  377. package/dist/private/table/useTreeGridState.mjs +2 -1
  378. package/dist/private/table/useTreeGridState.mjs.map +1 -1
  379. package/dist/private/tabs/useTabListState.cjs.map +1 -1
  380. package/dist/private/tabs/useTabListState.js.map +1 -1
  381. package/dist/private/tabs/useTabListState.mjs.map +1 -1
  382. package/dist/private/toast/useToastState.cjs.map +1 -1
  383. package/dist/private/toast/useToastState.js.map +1 -1
  384. package/dist/private/toast/useToastState.mjs.map +1 -1
  385. package/dist/private/toggle/useToggleGroupState.cjs.map +1 -1
  386. package/dist/private/toggle/useToggleGroupState.js.map +1 -1
  387. package/dist/private/toggle/useToggleGroupState.mjs.map +1 -1
  388. package/dist/private/toggle/useToggleState.cjs.map +1 -1
  389. package/dist/private/toggle/useToggleState.js.map +1 -1
  390. package/dist/private/toggle/useToggleState.mjs.map +1 -1
  391. package/dist/private/tooltip/useTooltipTriggerState.cjs.map +1 -1
  392. package/dist/private/tooltip/useTooltipTriggerState.js.map +1 -1
  393. package/dist/private/tooltip/useTooltipTriggerState.mjs.map +1 -1
  394. package/dist/private/tree/TreeCollection.cjs.map +1 -1
  395. package/dist/private/tree/TreeCollection.js.map +1 -1
  396. package/dist/private/tree/TreeCollection.mjs.map +1 -1
  397. package/dist/private/tree/useTreeState.cjs.map +1 -1
  398. package/dist/private/tree/useTreeState.js.map +1 -1
  399. package/dist/private/tree/useTreeState.mjs.map +1 -1
  400. package/dist/private/utils/number.cjs +2 -1
  401. package/dist/private/utils/number.cjs.map +1 -1
  402. package/dist/private/utils/number.js +2 -1
  403. package/dist/private/utils/number.js.map +1 -1
  404. package/dist/private/utils/number.mjs +2 -1
  405. package/dist/private/utils/number.mjs.map +1 -1
  406. package/dist/private/utils/useControlledState.cjs.map +1 -1
  407. package/dist/private/utils/useControlledState.js.map +1 -1
  408. package/dist/private/utils/useControlledState.mjs.map +1 -1
  409. package/dist/private/virtualizer/Layout.cjs.map +1 -1
  410. package/dist/private/virtualizer/Layout.js.map +1 -1
  411. package/dist/private/virtualizer/Layout.mjs.map +1 -1
  412. package/dist/private/virtualizer/LayoutInfo.cjs +4 -2
  413. package/dist/private/virtualizer/LayoutInfo.cjs.map +1 -1
  414. package/dist/private/virtualizer/LayoutInfo.js +4 -2
  415. package/dist/private/virtualizer/LayoutInfo.js.map +1 -1
  416. package/dist/private/virtualizer/LayoutInfo.mjs +4 -2
  417. package/dist/private/virtualizer/LayoutInfo.mjs.map +1 -1
  418. package/dist/private/virtualizer/Rect.cjs +4 -0
  419. package/dist/private/virtualizer/Rect.cjs.map +1 -1
  420. package/dist/private/virtualizer/Rect.js +4 -0
  421. package/dist/private/virtualizer/Rect.js.map +1 -1
  422. package/dist/private/virtualizer/Rect.mjs +4 -0
  423. package/dist/private/virtualizer/Rect.mjs.map +1 -1
  424. package/dist/private/virtualizer/ReusableView.cjs.map +1 -1
  425. package/dist/private/virtualizer/ReusableView.js.map +1 -1
  426. package/dist/private/virtualizer/ReusableView.mjs.map +1 -1
  427. package/dist/private/virtualizer/Size.cjs.map +1 -1
  428. package/dist/private/virtualizer/Size.js.map +1 -1
  429. package/dist/private/virtualizer/Size.mjs.map +1 -1
  430. package/dist/private/virtualizer/Virtualizer.cjs +4 -4
  431. package/dist/private/virtualizer/Virtualizer.cjs.map +1 -1
  432. package/dist/private/virtualizer/Virtualizer.js +4 -4
  433. package/dist/private/virtualizer/Virtualizer.js.map +1 -1
  434. package/dist/private/virtualizer/Virtualizer.mjs +4 -4
  435. package/dist/private/virtualizer/Virtualizer.mjs.map +1 -1
  436. package/dist/private/virtualizer/useVirtualizerState.cjs.map +1 -1
  437. package/dist/private/virtualizer/useVirtualizerState.js.map +1 -1
  438. package/dist/private/virtualizer/useVirtualizerState.mjs.map +1 -1
  439. package/dist/types/exports/useCalendarState.d.ts +1 -1
  440. package/dist/types/src/autocomplete/useAutocompleteState.d.ts +4 -1
  441. package/dist/types/src/calendar/types.d.ts +50 -14
  442. package/dist/types/src/calendar/useCalendarState.d.ts +20 -6
  443. package/dist/types/src/calendar/useRangeCalendarState.d.ts +14 -5
  444. package/dist/types/src/calendar/utils.d.ts +1 -0
  445. package/dist/types/src/checkbox/useCheckboxGroupState.d.ts +1 -0
  446. package/dist/types/src/collections/useCollection.d.ts +1 -1
  447. package/dist/types/src/color/useColorAreaState.d.ts +21 -8
  448. package/dist/types/src/color/useColorFieldState.d.ts +2 -3
  449. package/dist/types/src/color/useColorSliderState.d.ts +4 -1
  450. package/dist/types/src/color/useColorWheelState.d.ts +5 -1
  451. package/dist/types/src/combobox/useComboBoxState.d.ts +19 -6
  452. package/dist/types/src/data/useAsyncList.d.ts +2 -2
  453. package/dist/types/src/data/useListData.d.ts +13 -1
  454. package/dist/types/src/data/useTreeData.d.ts +11 -0
  455. package/dist/types/src/datepicker/IncompleteDate.d.ts +11 -5
  456. package/dist/types/src/datepicker/types.d.ts +37 -11
  457. package/dist/types/src/datepicker/useDateFieldState.d.ts +13 -4
  458. package/dist/types/src/datepicker/useDatePickerState.d.ts +10 -4
  459. package/dist/types/src/datepicker/useDateRangePickerState.d.ts +12 -3
  460. package/dist/types/src/dnd/useDraggableCollectionState.d.ts +4 -1
  461. package/dist/types/src/form/useFormValidationState.d.ts +4 -1
  462. package/dist/types/src/grid/GridCollection.d.ts +2 -1
  463. package/dist/types/src/grid/useGridState.d.ts +7 -3
  464. package/dist/types/src/layout/GridLayout.d.ts +18 -2
  465. package/dist/types/src/layout/ListLayout.d.ts +34 -12
  466. package/dist/types/src/layout/TableLayout.d.ts +11 -4
  467. package/dist/types/src/layout/WaterfallLayout.d.ts +9 -2
  468. package/dist/types/src/list/useListState.d.ts +2 -2
  469. package/dist/types/src/menu/useMenuTriggerState.d.ts +3 -1
  470. package/dist/types/src/menu/useSubmenuTriggerState.d.ts +2 -2
  471. package/dist/types/src/numberfield/useNumberFieldState.d.ts +15 -11
  472. package/dist/types/src/radio/useRadioGroupState.d.ts +4 -1
  473. package/dist/types/src/select/useSelectState.d.ts +13 -2
  474. package/dist/types/src/selection/types.d.ts +4 -1
  475. package/dist/types/src/selection/useMultipleSelectionState.d.ts +2 -0
  476. package/dist/types/src/slider/useSliderState.d.ts +22 -2
  477. package/dist/types/src/table/Column.d.ts +4 -1
  478. package/dist/types/src/table/Row.d.ts +5 -3
  479. package/dist/types/src/table/TableBody.d.ts +3 -2
  480. package/dist/types/src/table/TableCollection.d.ts +4 -1
  481. package/dist/types/src/table/TableColumnLayout.d.ts +4 -1
  482. package/dist/types/src/table/TableHeader.d.ts +7 -3
  483. package/dist/types/src/table/TableUtils.d.ts +19 -16
  484. package/dist/types/src/table/useTableColumnResizeState.d.ts +5 -3
  485. package/dist/types/src/table/useTableState.d.ts +15 -6
  486. package/dist/types/src/table/useTreeGridState.d.ts +3 -2
  487. package/dist/types/src/toggle/useToggleGroupState.d.ts +1 -0
  488. package/dist/types/src/toggle/useToggleState.d.ts +2 -1
  489. package/dist/types/src/tooltip/useTooltipTriggerState.d.ts +8 -2
  490. package/dist/types/src/tree/useTreeState.d.ts +1 -1
  491. package/dist/types/src/utils/number.d.ts +2 -1
  492. package/dist/types/src/virtualizer/Layout.d.ts +5 -2
  493. package/dist/types/src/virtualizer/LayoutInfo.d.ts +10 -3
  494. package/dist/types/src/virtualizer/Rect.d.ts +4 -0
  495. package/dist/types/src/virtualizer/Virtualizer.d.ts +5 -4
  496. package/package.json +8 -7
@@ -1 +1 @@
1
- {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAsFM,SAAS,0CACd,KAA8B;IAE9B,IAAI,YACF,QAAQ,YACR,QAAQ,QACR,IAAI,iBACJ,aAAa,SACb,KAAK,gBACL,eAAe,eACf,QAAQ,UACR,MAAM,cACN,UAAU,cACV,UAAU,kBACV,iBAAiB,QAClB,GAAG;IAEJ,IAAI,UAAU,MACZ,QAAQ;IAGV,IAAI,YAAY,CAAA,GAAA,kBAAU,EAAE,CAAA;QAC1B,OAAO,SAAS,a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AM,gBACL,aAAa,aAAa,MAAM,aACjC,CAAA,GAAA,yCAAc,EAAE,aAAa,UAAU,UAAU,aAAa,eAC9D,6CAAuB,KAAK,aAAa,cAAc,QAAO,GAE/D;QAAC;QAAY;QAAY;QAAU;QAAU;QAAW;KAAY;IAEvE,IAAI,WAAW,CAAC,QAAkB,aAAa,oBAAoB,CAAC,OAAO,UAAU;IAErF,OAAO;QACL,GAAG,UAAU;kBACb;mBACA;wBACA;mBACA;wBACA;sBACA;sBACA;kBACA;kBACA;QACA,aAAa;QACb,oBAAoB,MAAM,gBAAgB,eAAe;wBACzD;uBACA;oBACA;gBACA;IACF;AACF;AAEA,SAAS,6CAAuB,QAAmB,EAAE,MAAc,EAAE,MAAc;IACjF,IAAI,SAAS,aAAa,MAAM,SAAS,SAAS,SAAS;IAE3D,4BAA4B;IAC5B,IAAI,SAAS,MAAM,KAAK,SAAS,MAAM,GAAG;QACxC,MAAM,gBAAgB,OAAO,QAAQ,GAAG,KAAK,CAAC;QAC9C,MAAM,gBAAgB,OAAO,QAAQ,GAAG,KAAK,CAAC;QAC9C,MAAM,sBAAsB,AAAC,aAAa,CAAC,EAAE,IAAI,aAAa,CAAC,EAAE,CAAC,MAAM,IAAK;QAC7E,MAAM,sBAAsB,AAAC,aAAa,CAAC,EAAE,IAAI,aAAa,CAAC,EAAE,CAAC,MAAM,IAAK;QAC7E,MAAM,aAAa,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,qBAAqB;QAE9D,4DAA4D;QAC5D,SAAS,KAAK,KAAK,CAAC,SAAS;QAC7B,SAAS,KAAK,KAAK,CAAC,SAAS;QAE7B,2FAA2F;QAC3F,SAAS,aAAa,MAAM,SAAS,SAAS,SAAS;QAEvD,+CAA+C;QAC/C,UAAU;IACZ;IAEA,OAAO;AACT","sources":["packages/react-stately/src/numberfield/useNumberFieldState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, snapValueToStep} from '../utils/number';\n\nimport {FocusableProps, HelpTextProps, InputBase, LabelableProps, RangeInputBase, TextInputBase, Validation, ValueBase} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {NumberFormatter, NumberParser} from '@internationalized/number';\nimport {useCallback, useMemo, useState} from 'react';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface NumberFieldProps extends InputBase, Validation<number>, FocusableProps, TextInputBase, ValueBase<number>, RangeInputBase<number>, LabelableProps, HelpTextProps {\n /**\n * Formatting options for the value displayed in the number field.\n * This also affects what characters are allowed to be typed by the user.\n */\n formatOptions?: Intl.NumberFormatOptions,\n /**\n * Controls the behavior of the number field when the user blurs the field after editing.\n * 'snap' will clamp the value to the min/max values, and snap to the nearest step value.\n * 'validate' will not clamp the value, and will validate that the value is within the min/max range and on a valid step.\n * @default 'snap'\n */\n commitBehavior?: 'snap' | 'validate'\n}\n\nexport interface NumberFieldState extends FormValidationState {\n /**\n * The current text value of the input. Updated as the user types,\n * and formatted according to `formatOptions` on blur.\n */\n inputValue: string,\n /**\n * The currently parsed number value, or NaN if a valid number could not be parsed.\n * Updated based on the `inputValue` as the user types.\n */\n numberValue: number,\n /** The default value of the input. */\n defaultNumberValue: number,\n /** The minimum value of the number field. */\n minValue?: number,\n /** The maximum value of the number field. */\n maxValue?: number,\n /** Whether the current value can be incremented according to the maximum value and step. */\n canIncrement: boolean,\n /** Whether the current value can be decremented according to the minimum value and step. */\n canDecrement: boolean,\n /**\n * Validates a user input string according to the current locale and format options.\n * Values can be partially entered, and may be valid even if they cannot currently be parsed to a number.\n * Can be used to implement validation as a user types.\n */\n validate(value: string): boolean,\n /** Sets the current text value of the input. */\n setInputValue(val: string): void,\n /** Sets the number value. */\n setNumberValue(val: number): void,\n /**\n * Commits the current input value. The value is parsed to a number, clamped according\n * to the minimum and maximum values of the field, and snapped to the nearest step value.\n * This will fire the `onChange` prop with the new value, and if uncontrolled, update the `numberValue`.\n * Typically this is called when the field is blurred.\n * @param value - The value to commit. If not provided, the current input value is used.\n */\n commit(value?: string): void,\n /** Increments the current input value to the next step boundary, and fires `onChange`. */\n increment(): void,\n /** Decrements the current input value to the next step boundary, and fires `onChange`. */\n decrement(): void,\n /** Sets the current value to the `maxValue` if any, and fires `onChange`. */\n incrementToMax(): void,\n /** Sets the current value to the `minValue` if any, and fires `onChange`. */\n decrementToMin(): void\n}\n\nexport interface NumberFieldStateOptions extends NumberFieldProps {\n /**\n * The locale that should be used for parsing.\n * @default 'en-US'\n */\n locale: string\n}\n\n/**\n * Provides state management for a number field component. Number fields allow users to enter a number,\n * and increment or decrement the value using stepper buttons.\n */\nexport function useNumberFieldState(\n props: NumberFieldStateOptions\n): NumberFieldState {\n let {\n minValue,\n maxValue,\n step,\n formatOptions,\n value,\n defaultValue = NaN,\n onChange,\n locale,\n isDisabled,\n isReadOnly,\n commitBehavior = 'snap'\n } = props;\n\n if (value === null) {\n value = NaN;\n }\n\n let snapValue = useCallback(value => {\n return step === undefined || isNaN(step)\n ? clamp(value, minValue, maxValue)\n : snapValueToStep(value, minValue, maxValue, step);\n }, [step, minValue, maxValue]);\n\n if (value !== undefined && !isNaN(value) && commitBehavior === 'snap') {\n value = snapValue(value);\n }\n\n if (!isNaN(defaultValue) && commitBehavior === 'snap') {\n defaultValue = snapValue(defaultValue);\n }\n\n let [numberValue, setNumberValue] = useControlledState<number>(value, isNaN(defaultValue) ? NaN : defaultValue, onChange);\n let [initialValue] = useState(numberValue);\n let [inputValue, setInputValue] = useState(() => isNaN(numberValue) ? '' : new NumberFormatter(locale, formatOptions).format(numberValue));\n\n let numberParser = useMemo(() => new NumberParser(locale, formatOptions), [locale, formatOptions]);\n let numberingSystem = useMemo(() => numberParser.getNumberingSystem(inputValue), [numberParser, inputValue]);\n let formatter = useMemo(() => new NumberFormatter(locale, {...formatOptions, numberingSystem}), [locale, formatOptions, numberingSystem]);\n let intlOptions = useMemo(() => formatter.resolvedOptions(), [formatter]);\n let format = useCallback((value: number) => (isNaN(value) || value === null) ? '' : formatter.format(value), [formatter]);\n\n let validation = useFormValidationState({\n ...props,\n value: numberValue\n });\n\n let clampStep = (step !== undefined && !isNaN(step)) ? step : 1;\n if (intlOptions.style === 'percent' && (step === undefined || isNaN(step))) {\n clampStep = 0.01;\n }\n\n // Update the input value when the number value or format options change. This is done\n // in a useEffect so that the controlled behavior is correct and we only update the\n // textfield after prop changes.\n let [prevValue, setPrevValue] = useState(numberValue);\n let [prevLocale, setPrevLocale] = useState(locale);\n let [prevFormatOptions, setPrevFormatOptions] = useState(formatOptions);\n if (!Object.is(numberValue, prevValue) || locale !== prevLocale || formatOptions !== prevFormatOptions) {\n setInputValue(format(numberValue));\n setPrevValue(numberValue);\n setPrevLocale(locale);\n setPrevFormatOptions(formatOptions);\n }\n\n let parsedValue = useMemo(() => numberParser.parse(inputValue), [numberParser, inputValue]);\n let commit = (overrideValue?: string) => {\n let newInputValue = overrideValue === undefined ? inputValue : overrideValue;\n let newParsedValue = parsedValue;\n if (overrideValue !== undefined) {\n newParsedValue = numberParser.parse(newInputValue);\n }\n // Set to empty state if input value is empty\n if (!newInputValue.length) {\n setNumberValue(NaN);\n setInputValue(value === undefined ? '' : format(numberValue));\n return;\n }\n\n // if it failed to parse, then reset input to formatted version of current number\n if (isNaN(newParsedValue)) {\n setInputValue(format(numberValue));\n return;\n }\n\n // Clamp to min and max, round to the nearest step, and round to specified number of digits\n let clampedValue = commitBehavior === 'snap' ? snapValue(newParsedValue) : newParsedValue;\n clampedValue = numberParser.parse(format(clampedValue));\n let shouldValidate = clampedValue !== numberValue;\n setNumberValue(clampedValue);\n\n // in a controlled state, the numberValue won't change, so we won't go back to our old input without help\n setInputValue(format(value === undefined ? clampedValue : numberValue));\n if (shouldValidate) {\n validation.commitValidation();\n }\n };\n\n let safeNextStep = (operation: '+' | '-', minMax: number = 0) => {\n let prev = parsedValue;\n\n if (isNaN(prev)) {\n // if the input is empty, start from the min/max value when incrementing/decrementing,\n // or zero if there is no min/max value defined.\n let newValue = isNaN(minMax) ? 0 : minMax;\n return snapValueToStep(newValue, minValue, maxValue, clampStep);\n } else {\n // otherwise, first snap the current value to the nearest step. if it moves in the direction\n // we're going, use that value, otherwise add the step and snap that value.\n let newValue = snapValueToStep(prev, minValue, maxValue, clampStep);\n if ((operation === '+' && newValue > prev) || (operation === '-' && newValue < prev)) {\n return newValue;\n }\n\n return snapValueToStep(\n handleDecimalOperation(operation, prev, clampStep),\n minValue,\n maxValue,\n clampStep\n );\n }\n };\n\n let increment = () => {\n let newValue = safeNextStep('+', minValue);\n\n // if we've arrived at the same value that was previously in the state, the\n // input value should be updated to match\n // ex type 4, press increment, highlight the number in the input, type 4 again, press increment\n // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input\n if (newValue === numberValue) {\n setInputValue(format(newValue));\n }\n\n setNumberValue(newValue);\n validation.commitValidation();\n };\n\n let decrement = () => {\n let newValue = safeNextStep('-', maxValue);\n\n if (newValue === numberValue) {\n setInputValue(format(newValue));\n }\n\n setNumberValue(newValue);\n validation.commitValidation();\n };\n\n let incrementToMax = () => {\n if (maxValue != null) {\n setNumberValue(snapValueToStep(maxValue, minValue, maxValue, clampStep));\n validation.commitValidation();\n }\n };\n\n let decrementToMin = () => {\n if (minValue != null) {\n setNumberValue(minValue);\n validation.commitValidation();\n }\n };\n\n let canIncrement = useMemo(() => (\n !isDisabled &&\n !isReadOnly &&\n (\n isNaN(parsedValue) ||\n (maxValue === undefined || isNaN(maxValue)) ||\n snapValueToStep(parsedValue, minValue, maxValue, clampStep) > parsedValue ||\n handleDecimalOperation('+', parsedValue, clampStep) <= maxValue\n )\n ), [isDisabled, isReadOnly, minValue, maxValue, clampStep, parsedValue]);\n\n let canDecrement = useMemo(() => (\n !isDisabled &&\n !isReadOnly &&\n (\n isNaN(parsedValue) ||\n (minValue === undefined || isNaN(minValue)) ||\n snapValueToStep(parsedValue, minValue, maxValue, clampStep) < parsedValue ||\n handleDecimalOperation('-', parsedValue, clampStep) >= minValue\n )\n ), [isDisabled, isReadOnly, minValue, maxValue, clampStep, parsedValue]);\n\n let validate = (value: string) => numberParser.isValidPartialNumber(value, minValue, maxValue);\n\n return {\n ...validation,\n validate,\n increment,\n incrementToMax,\n decrement,\n decrementToMin,\n canIncrement,\n canDecrement,\n minValue,\n maxValue,\n numberValue: parsedValue,\n defaultNumberValue: isNaN(defaultValue) ? initialValue : defaultValue,\n setNumberValue,\n setInputValue,\n inputValue,\n commit\n };\n}\n\nfunction handleDecimalOperation(operator: '-' | '+', value1: number, value2: number): number {\n let result = operator === '+' ? value1 + value2 : value1 - value2;\n\n // Check if we have decimals\n if (value1 % 1 !== 0 || value2 % 1 !== 0) {\n const value1Decimal = value1.toString().split('.');\n const value2Decimal = value2.toString().split('.');\n const value1DecimalLength = (value1Decimal[1] && value1Decimal[1].length) || 0;\n const value2DecimalLength = (value2Decimal[1] && value2Decimal[1].length) || 0;\n const multiplier = Math.pow(10, Math.max(value1DecimalLength, value2DecimalLength));\n\n // Transform the decimals to integers based on the precision\n value1 = Math.round(value1 * multiplier);\n value2 = Math.round(value2 * multiplier);\n\n // Perform the operation on integers values to make sure we don't get a fancy decimal value\n result = operator === '+' ? value1 + value2 : value1 - value2;\n\n // Transform the integer result back to decimal\n result /= multiplier;\n }\n\n return result;\n}\n"],"names":[],"version":3,"file":"useNumberFieldState.js.map"}
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA4GM,SAAS,0CAAoB,KAA8B;IAChE,IAAI,YACF,QAAQ,YACR,QAAQ,QACR,IAAI,iBACJ,aAAa,SACb,KAAK,gBACL,eA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AAC,EAAE,IAAI,aAAa,CAAC,EAAE,CAAC,MAAM,IAAK;QAC7E,MAAM,sBAAsB,AAAC,aAAa,CAAC,EAAE,IAAI,aAAa,CAAC,EAAE,CAAC,MAAM,IAAK;QAC7E,MAAM,aAAa,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,qBAAqB;QAE9D,4DAA4D;QAC5D,SAAS,KAAK,KAAK,CAAC,SAAS;QAC7B,SAAS,KAAK,KAAK,CAAC,SAAS;QAE7B,2FAA2F;QAC3F,SAAS,aAAa,MAAM,SAAS,SAAS,SAAS;QAEvD,+CAA+C;QAC/C,UAAU;IACZ;IAEA,OAAO;AACT","sources":["packages/react-stately/src/numberfield/useNumberFieldState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, snapValueToStep} from '../utils/number';\n\nimport {\n FocusableProps,\n HelpTextProps,\n InputBase,\n LabelableProps,\n RangeInputBase,\n TextInputBase,\n Validation,\n ValueBase\n} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {NumberFormatter, NumberParser} from '@internationalized/number';\nimport {useCallback, useMemo, useState} from 'react';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface NumberFieldProps\n extends\n InputBase,\n Validation<number>,\n FocusableProps,\n TextInputBase,\n ValueBase<number>,\n RangeInputBase<number>,\n LabelableProps,\n HelpTextProps {\n /**\n * Formatting options for the value displayed in the number field.\n * This also affects what characters are allowed to be typed by the user.\n */\n formatOptions?: Intl.NumberFormatOptions;\n /**\n * Controls the behavior of the number field when the user blurs the field after editing. 'snap'\n * will clamp the value to the min/max values, and snap to the nearest step value. 'validate' will\n * not clamp the value, and will validate that the value is within the min/max range and on a\n * valid step.\n *\n * @default 'snap'\n */\n commitBehavior?: 'snap' | 'validate';\n}\n\nexport interface NumberFieldState extends FormValidationState {\n /**\n * The current text value of the input. Updated as the user types,\n * and formatted according to `formatOptions` on blur.\n */\n inputValue: string;\n /**\n * The currently parsed number value, or NaN if a valid number could not be parsed.\n * Updated based on the `inputValue` as the user types.\n */\n numberValue: number;\n /** The default value of the input. */\n defaultNumberValue: number;\n /** The minimum value of the number field. */\n minValue?: number;\n /** The maximum value of the number field. */\n maxValue?: number;\n /** Whether the current value can be incremented according to the maximum value and step. */\n canIncrement: boolean;\n /** Whether the current value can be decremented according to the minimum value and step. */\n canDecrement: boolean;\n /**\n * Validates a user input string according to the current locale and format options. Values can be\n * partially entered, and may be valid even if they cannot currently be parsed to a number. Can be\n * used to implement validation as a user types.\n */\n validate(value: string): boolean;\n /** Sets the current text value of the input. */\n setInputValue(val: string): void;\n /** Sets the number value. */\n setNumberValue(val: number): void;\n /**\n * Commits the current input value. The value is parsed to a number, clamped according to the\n * minimum and maximum values of the field, and snapped to the nearest step value. This will fire\n * the `onChange` prop with the new value, and if uncontrolled, update the `numberValue`.\n * Typically this is called when the field is blurred.\n *\n * @param value - The value to commit. If not provided, the current input value is used.\n */\n commit(value?: string): void;\n /** Increments the current input value to the next step boundary, and fires `onChange`. */\n increment(): void;\n /** Decrements the current input value to the next step boundary, and fires `onChange`. */\n decrement(): void;\n /** Sets the current value to the `maxValue` if any, and fires `onChange`. */\n incrementToMax(): void;\n /** Sets the current value to the `minValue` if any, and fires `onChange`. */\n decrementToMin(): void;\n}\n\nexport interface NumberFieldStateOptions extends NumberFieldProps {\n /**\n * The locale that should be used for parsing.\n *\n * @default 'en-US'\n */\n locale: string;\n}\n\n/**\n * Provides state management for a number field component. Number fields allow users to enter a\n * number, and increment or decrement the value using stepper buttons.\n */\nexport function useNumberFieldState(props: NumberFieldStateOptions): NumberFieldState {\n let {\n minValue,\n maxValue,\n step,\n formatOptions,\n value,\n defaultValue = NaN,\n onChange,\n locale,\n isDisabled,\n isReadOnly,\n commitBehavior = 'snap'\n } = props;\n\n if (value === null) {\n value = NaN;\n }\n\n let snapValue = useCallback(\n value => {\n return step === undefined || isNaN(step)\n ? clamp(value, minValue, maxValue)\n : snapValueToStep(value, minValue, maxValue, step);\n },\n [step, minValue, maxValue]\n );\n\n if (value !== undefined && !isNaN(value) && commitBehavior === 'snap') {\n value = snapValue(value);\n }\n\n if (!isNaN(defaultValue) && commitBehavior === 'snap') {\n defaultValue = snapValue(defaultValue);\n }\n\n let [numberValue, setNumberValue] = useControlledState<number>(\n value,\n isNaN(defaultValue) ? NaN : defaultValue,\n onChange\n );\n let [initialValue] = useState(numberValue);\n let [inputValue, setInputValue] = useState(() =>\n isNaN(numberValue) ? '' : new NumberFormatter(locale, formatOptions).format(numberValue)\n );\n\n let numberParser = useMemo(\n () => new NumberParser(locale, formatOptions),\n [locale, formatOptions]\n );\n let numberingSystem = useMemo(\n () => numberParser.getNumberingSystem(inputValue),\n [numberParser, inputValue]\n );\n let formatter = useMemo(\n () => new NumberFormatter(locale, {...formatOptions, numberingSystem}),\n [locale, formatOptions, numberingSystem]\n );\n let intlOptions = useMemo(() => formatter.resolvedOptions(), [formatter]);\n let format = useCallback(\n (value: number) => (isNaN(value) || value === null ? '' : formatter.format(value)),\n [formatter]\n );\n\n let validation = useFormValidationState({\n ...props,\n value: numberValue\n });\n\n let clampStep = step !== undefined && !isNaN(step) ? step : 1;\n if (intlOptions.style === 'percent' && (step === undefined || isNaN(step))) {\n clampStep = 0.01;\n }\n\n // Update the input value when the number value or format options change. This is done\n // in a useEffect so that the controlled behavior is correct and we only update the\n // textfield after prop changes.\n let [prevValue, setPrevValue] = useState(numberValue);\n let [prevLocale, setPrevLocale] = useState(locale);\n let [prevFormatOptions, setPrevFormatOptions] = useState(formatOptions);\n if (\n !Object.is(numberValue, prevValue) ||\n locale !== prevLocale ||\n !isEqualFormatOptions(formatOptions, prevFormatOptions)\n ) {\n setInputValue(format(numberValue));\n setPrevValue(numberValue);\n setPrevLocale(locale);\n setPrevFormatOptions(formatOptions);\n }\n\n let parsedValue = useMemo(() => numberParser.parse(inputValue), [numberParser, inputValue]);\n let commit = (overrideValue?: string) => {\n let newInputValue = overrideValue === undefined ? inputValue : overrideValue;\n let newParsedValue = parsedValue;\n if (overrideValue !== undefined) {\n newParsedValue = numberParser.parse(newInputValue);\n }\n // Set to empty state if input value is empty\n if (!newInputValue.length) {\n setNumberValue(NaN);\n setInputValue(value === undefined ? '' : format(numberValue));\n return;\n }\n\n // if it failed to parse, then reset input to formatted version of current number\n if (isNaN(newParsedValue)) {\n setInputValue(format(numberValue));\n return;\n }\n\n // Clamp to min and max, round to the nearest step, and round to specified number of digits\n let clampedValue = commitBehavior === 'snap' ? snapValue(newParsedValue) : newParsedValue;\n clampedValue = numberParser.parse(format(clampedValue));\n let shouldValidate = clampedValue !== numberValue;\n setNumberValue(clampedValue);\n\n // in a controlled state, the numberValue won't change, so we won't go back to our old input without help\n setInputValue(format(value === undefined ? clampedValue : numberValue));\n if (shouldValidate) {\n validation.commitValidation();\n }\n };\n\n let safeNextStep = (operation: '+' | '-', minMax: number = 0) => {\n let prev = parsedValue;\n\n if (isNaN(prev)) {\n // if the input is empty, start from the min/max value when incrementing/decrementing,\n // or zero if there is no min/max value defined.\n let newValue = isNaN(minMax) ? 0 : minMax;\n return snapValueToStep(newValue, minValue, maxValue, clampStep);\n } else {\n // otherwise, first snap the current value to the nearest step. if it moves in the direction\n // we're going, use that value, otherwise add the step and snap that value.\n let newValue = snapValueToStep(prev, minValue, maxValue, clampStep);\n if ((operation === '+' && newValue > prev) || (operation === '-' && newValue < prev)) {\n return newValue;\n }\n\n return snapValueToStep(\n handleDecimalOperation(operation, prev, clampStep),\n minValue,\n maxValue,\n clampStep\n );\n }\n };\n\n let increment = () => {\n let newValue = safeNextStep('+', minValue);\n\n // if we've arrived at the same value that was previously in the state, the\n // input value should be updated to match\n // ex type 4, press increment, highlight the number in the input, type 4 again, press increment\n // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input\n if (newValue === numberValue) {\n setInputValue(format(newValue));\n }\n\n setNumberValue(newValue);\n validation.commitValidation();\n };\n\n let decrement = () => {\n let newValue = safeNextStep('-', maxValue);\n\n if (newValue === numberValue) {\n setInputValue(format(newValue));\n }\n\n setNumberValue(newValue);\n validation.commitValidation();\n };\n\n let incrementToMax = () => {\n if (maxValue != null) {\n setNumberValue(snapValueToStep(maxValue, minValue, maxValue, clampStep));\n validation.commitValidation();\n }\n };\n\n let decrementToMin = () => {\n if (minValue != null) {\n setNumberValue(minValue);\n validation.commitValidation();\n }\n };\n\n let canIncrement = useMemo(\n () =>\n !isDisabled &&\n !isReadOnly &&\n (isNaN(parsedValue) ||\n maxValue === undefined ||\n isNaN(maxValue) ||\n snapValueToStep(parsedValue, minValue, maxValue, clampStep) > parsedValue ||\n handleDecimalOperation('+', parsedValue, clampStep) <= maxValue),\n [isDisabled, isReadOnly, minValue, maxValue, clampStep, parsedValue]\n );\n\n let canDecrement = useMemo(\n () =>\n !isDisabled &&\n !isReadOnly &&\n (isNaN(parsedValue) ||\n minValue === undefined ||\n isNaN(minValue) ||\n snapValueToStep(parsedValue, minValue, maxValue, clampStep) < parsedValue ||\n handleDecimalOperation('-', parsedValue, clampStep) >= minValue),\n [isDisabled, isReadOnly, minValue, maxValue, clampStep, parsedValue]\n );\n\n let validate = (value: string) => numberParser.isValidPartialNumber(value, minValue, maxValue);\n\n return {\n ...validation,\n validate,\n increment,\n incrementToMax,\n decrement,\n decrementToMin,\n canIncrement,\n canDecrement,\n minValue,\n maxValue,\n numberValue: parsedValue,\n defaultNumberValue: isNaN(defaultValue) ? initialValue : defaultValue,\n setNumberValue,\n setInputValue,\n inputValue,\n commit\n };\n}\n\n// Shallow equality is sufficient here because all values in Intl.NumberFormatOptions are primitives.\nfunction isEqualFormatOptions(\n a: Intl.NumberFormatOptions | undefined,\n b: Intl.NumberFormatOptions | undefined\n) {\n if (a === b) {\n return true;\n }\n if (!a || !b) {\n return false;\n }\n let aKeys = Object.keys(a);\n let bKeys = Object.keys(b);\n if (aKeys.length !== bKeys.length) {\n return false;\n }\n for (let key of aKeys) {\n if (b[key] !== a[key]) {\n return false;\n }\n }\n return true;\n}\n\nfunction handleDecimalOperation(operator: '-' | '+', value1: number, value2: number): number {\n let result = operator === '+' ? value1 + value2 : value1 - value2;\n\n // Check if we have decimals\n if (value1 % 1 !== 0 || value2 % 1 !== 0) {\n const value1Decimal = value1.toString().split('.');\n const value2Decimal = value2.toString().split('.');\n const value1DecimalLength = (value1Decimal[1] && value1Decimal[1].length) || 0;\n const value2DecimalLength = (value2Decimal[1] && value2Decimal[1].length) || 0;\n const multiplier = Math.pow(10, Math.max(value1DecimalLength, value2DecimalLength));\n\n // Transform the decimals to integers based on the precision\n value1 = Math.round(value1 * multiplier);\n value2 = Math.round(value2 * multiplier);\n\n // Perform the operation on integers values to make sure we don't get a fancy decimal value\n result = operator === '+' ? value1 + value2 : value1 - value2;\n\n // Transform the integer result back to decimal\n result /= multiplier;\n }\n\n return result;\n}\n"],"names":[],"version":3,"file":"useNumberFieldState.js.map"}
@@ -68,7 +68,7 @@ function $3d0ee518c6f3d04f$export$7f629e9dc1ecf37c(props) {
68
68
  let [prevValue, setPrevValue] = (0, $5YoJg$useState)(numberValue);
69
69
  let [prevLocale, setPrevLocale] = (0, $5YoJg$useState)(locale);
70
70
  let [prevFormatOptions, setPrevFormatOptions] = (0, $5YoJg$useState)(formatOptions);
71
- if (!Object.is(numberValue, prevValue) || locale !== prevLocale || formatOptions !== prevFormatOptions) {
71
+ if (!Object.is(numberValue, prevValue) || locale !== prevLocale || !$3d0ee518c6f3d04f$var$isEqualFormatOptions(formatOptions, prevFormatOptions)) {
72
72
  setInputValue(format(numberValue));
73
73
  setPrevValue(numberValue);
74
74
  setPrevLocale(locale);
@@ -181,6 +181,18 @@ function $3d0ee518c6f3d04f$export$7f629e9dc1ecf37c(props) {
181
181
  commit: commit
182
182
  };
183
183
  }
184
+ // Shallow equality is sufficient here because all values in Intl.NumberFormatOptions are primitives.
185
+ function $3d0ee518c6f3d04f$var$isEqualFormatOptions(a, b) {
186
+ if (a === b) return true;
187
+ if (!a || !b) return false;
188
+ let aKeys = Object.keys(a);
189
+ let bKeys = Object.keys(b);
190
+ if (aKeys.length !== bKeys.length) return false;
191
+ for (let key of aKeys){
192
+ if (b[key] !== a[key]) return false;
193
+ }
194
+ return true;
195
+ }
184
196
  function $3d0ee518c6f3d04f$var$handleDecimalOperation(operator, value1, value2) {
185
197
  let result = operator === '+' ? value1 + value2 : value1 - value2;
186
198
  // Check if we have decimals
@@ -1 +1 @@
1
- {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAsFM,SAAS,0CACd,KAA8B;IAE9B,IAAI,YACF,QAAQ,YACR,QAAQ,QACR,IAAI,iBACJ,aAAa,SACb,KAAK,gBACL,eAAe,eACf,QAAQ,UACR,MAAM,cACN,UAAU,cACV,UAAU,kBACV,iBAAiB,QAClB,GAAG;IAEJ,IAAI,UAAU,MACZ,QAAQ;IAGV,IAAI,YAAY,CAAA,GAAA,kBAAU,EAAE,CAAA;QAC1B,OAAO,SAAS,aAAa,MAAM,QAC/B,CAAA,GAAA,yCAAI,EAAE,OAAO,UAAU,YACvB,CAAA,GAAA,yCAAc,EAAE,OAAO,UAAU,UAAU;IACjD,GAAG;QAAC;QAAM;QAAU;KAAS;IAE7B,IAAI,UAAU,aAAa,CAAC,MAAM,UAAU,mBAAmB,QAC7D,QAAQ,UAAU;IAGpB,IAAI,CAAC,MAAM,iBAAiB,mBAAmB,QAC7C,eAAe,UAAU;IAG3B,IAAI,CAAC,aAAa,eAAe,GAAG,CAAA,GAAA,yCAAiB,EAAU,OAAO,MAAM,gBAAgB,MAAM,cAAc;IAChH,IAAI,CAAC,aAAa,GAAG,CAA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,SAAS,6CAAuB,QAAmB,EAAE,MAAc,EAAE,MAAc;IACjF,IAAI,SAAS,aAAa,MAAM,SAAS,SAAS,SAAS;IAE3D,4BAA4B;IAC5B,IAAI,SAAS,MAAM,KAAK,SAAS,MAAM,GAAG;QACxC,MAAM,gBAAgB,OAAO,QAAQ,GAAG,KAAK,CAAC;QAC9C,MAAM,gBAAgB,OAAO,QAAQ,GAAG,KAAK,CAAC;QAC9C,MAAM,sBAAsB,AAAC,aAAa,CAAC,EAAE,IAAI,aAAa,CAAC,EAAE,CAAC,MAAM,IAAK;QAC7E,MAAM,sBAAsB,AAAC,aAAa,CAAC,EAAE,IAAI,aAAa,CAAC,EAAE,CAAC,MAAM,IAAK;QAC7E,MAAM,aAAa,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,qBAAqB;QAE9D,4DAA4D;QAC5D,SAAS,KAAK,KAAK,CAAC,SAAS;QAC7B,SAAS,KAAK,KAAK,CAAC,SAAS;QAE7B,2FAA2F;QAC3F,SAAS,aAAa,MAAM,SAAS,SAAS,SAAS;QAEvD,+CAA+C;QAC/C,UAAU;IACZ;IAEA,OAAO;AACT","sources":["packages/react-stately/src/numberfield/useNumberFieldState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, snapValueToStep} from '../utils/number';\n\nimport {FocusableProps, HelpTextProps, InputBase, LabelableProps, RangeInputBase, TextInputBase, Validation, ValueBase} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {NumberFormatter, NumberParser} from '@internationalized/number';\nimport {useCallback, useMemo, useState} from 'react';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface NumberFieldProps extends InputBase, Validation<number>, FocusableProps, TextInputBase, ValueBase<number>, RangeInputBase<number>, LabelableProps, HelpTextProps {\n /**\n * Formatting options for the value displayed in the number field.\n * This also affects what characters are allowed to be typed by the user.\n */\n formatOptions?: Intl.NumberFormatOptions,\n /**\n * Controls the behavior of the number field when the user blurs the field after editing.\n * 'snap' will clamp the value to the min/max values, and snap to the nearest step value.\n * 'validate' will not clamp the value, and will validate that the value is within the min/max range and on a valid step.\n * @default 'snap'\n */\n commitBehavior?: 'snap' | 'validate'\n}\n\nexport interface NumberFieldState extends FormValidationState {\n /**\n * The current text value of the input. Updated as the user types,\n * and formatted according to `formatOptions` on blur.\n */\n inputValue: string,\n /**\n * The currently parsed number value, or NaN if a valid number could not be parsed.\n * Updated based on the `inputValue` as the user types.\n */\n numberValue: number,\n /** The default value of the input. */\n defaultNumberValue: number,\n /** The minimum value of the number field. */\n minValue?: number,\n /** The maximum value of the number field. */\n maxValue?: number,\n /** Whether the current value can be incremented according to the maximum value and step. */\n canIncrement: boolean,\n /** Whether the current value can be decremented according to the minimum value and step. */\n canDecrement: boolean,\n /**\n * Validates a user input string according to the current locale and format options.\n * Values can be partially entered, and may be valid even if they cannot currently be parsed to a number.\n * Can be used to implement validation as a user types.\n */\n validate(value: string): boolean,\n /** Sets the current text value of the input. */\n setInputValue(val: string): void,\n /** Sets the number value. */\n setNumberValue(val: number): void,\n /**\n * Commits the current input value. The value is parsed to a number, clamped according\n * to the minimum and maximum values of the field, and snapped to the nearest step value.\n * This will fire the `onChange` prop with the new value, and if uncontrolled, update the `numberValue`.\n * Typically this is called when the field is blurred.\n * @param value - The value to commit. If not provided, the current input value is used.\n */\n commit(value?: string): void,\n /** Increments the current input value to the next step boundary, and fires `onChange`. */\n increment(): void,\n /** Decrements the current input value to the next step boundary, and fires `onChange`. */\n decrement(): void,\n /** Sets the current value to the `maxValue` if any, and fires `onChange`. */\n incrementToMax(): void,\n /** Sets the current value to the `minValue` if any, and fires `onChange`. */\n decrementToMin(): void\n}\n\nexport interface NumberFieldStateOptions extends NumberFieldProps {\n /**\n * The locale that should be used for parsing.\n * @default 'en-US'\n */\n locale: string\n}\n\n/**\n * Provides state management for a number field component. Number fields allow users to enter a number,\n * and increment or decrement the value using stepper buttons.\n */\nexport function useNumberFieldState(\n props: NumberFieldStateOptions\n): NumberFieldState {\n let {\n minValue,\n maxValue,\n step,\n formatOptions,\n value,\n defaultValue = NaN,\n onChange,\n locale,\n isDisabled,\n isReadOnly,\n commitBehavior = 'snap'\n } = props;\n\n if (value === null) {\n value = NaN;\n }\n\n let snapValue = useCallback(value => {\n return step === undefined || isNaN(step)\n ? clamp(value, minValue, maxValue)\n : snapValueToStep(value, minValue, maxValue, step);\n }, [step, minValue, maxValue]);\n\n if (value !== undefined && !isNaN(value) && commitBehavior === 'snap') {\n value = snapValue(value);\n }\n\n if (!isNaN(defaultValue) && commitBehavior === 'snap') {\n defaultValue = snapValue(defaultValue);\n }\n\n let [numberValue, setNumberValue] = useControlledState<number>(value, isNaN(defaultValue) ? NaN : defaultValue, onChange);\n let [initialValue] = useState(numberValue);\n let [inputValue, setInputValue] = useState(() => isNaN(numberValue) ? '' : new NumberFormatter(locale, formatOptions).format(numberValue));\n\n let numberParser = useMemo(() => new NumberParser(locale, formatOptions), [locale, formatOptions]);\n let numberingSystem = useMemo(() => numberParser.getNumberingSystem(inputValue), [numberParser, inputValue]);\n let formatter = useMemo(() => new NumberFormatter(locale, {...formatOptions, numberingSystem}), [locale, formatOptions, numberingSystem]);\n let intlOptions = useMemo(() => formatter.resolvedOptions(), [formatter]);\n let format = useCallback((value: number) => (isNaN(value) || value === null) ? '' : formatter.format(value), [formatter]);\n\n let validation = useFormValidationState({\n ...props,\n value: numberValue\n });\n\n let clampStep = (step !== undefined && !isNaN(step)) ? step : 1;\n if (intlOptions.style === 'percent' && (step === undefined || isNaN(step))) {\n clampStep = 0.01;\n }\n\n // Update the input value when the number value or format options change. This is done\n // in a useEffect so that the controlled behavior is correct and we only update the\n // textfield after prop changes.\n let [prevValue, setPrevValue] = useState(numberValue);\n let [prevLocale, setPrevLocale] = useState(locale);\n let [prevFormatOptions, setPrevFormatOptions] = useState(formatOptions);\n if (!Object.is(numberValue, prevValue) || locale !== prevLocale || formatOptions !== prevFormatOptions) {\n setInputValue(format(numberValue));\n setPrevValue(numberValue);\n setPrevLocale(locale);\n setPrevFormatOptions(formatOptions);\n }\n\n let parsedValue = useMemo(() => numberParser.parse(inputValue), [numberParser, inputValue]);\n let commit = (overrideValue?: string) => {\n let newInputValue = overrideValue === undefined ? inputValue : overrideValue;\n let newParsedValue = parsedValue;\n if (overrideValue !== undefined) {\n newParsedValue = numberParser.parse(newInputValue);\n }\n // Set to empty state if input value is empty\n if (!newInputValue.length) {\n setNumberValue(NaN);\n setInputValue(value === undefined ? '' : format(numberValue));\n return;\n }\n\n // if it failed to parse, then reset input to formatted version of current number\n if (isNaN(newParsedValue)) {\n setInputValue(format(numberValue));\n return;\n }\n\n // Clamp to min and max, round to the nearest step, and round to specified number of digits\n let clampedValue = commitBehavior === 'snap' ? snapValue(newParsedValue) : newParsedValue;\n clampedValue = numberParser.parse(format(clampedValue));\n let shouldValidate = clampedValue !== numberValue;\n setNumberValue(clampedValue);\n\n // in a controlled state, the numberValue won't change, so we won't go back to our old input without help\n setInputValue(format(value === undefined ? clampedValue : numberValue));\n if (shouldValidate) {\n validation.commitValidation();\n }\n };\n\n let safeNextStep = (operation: '+' | '-', minMax: number = 0) => {\n let prev = parsedValue;\n\n if (isNaN(prev)) {\n // if the input is empty, start from the min/max value when incrementing/decrementing,\n // or zero if there is no min/max value defined.\n let newValue = isNaN(minMax) ? 0 : minMax;\n return snapValueToStep(newValue, minValue, maxValue, clampStep);\n } else {\n // otherwise, first snap the current value to the nearest step. if it moves in the direction\n // we're going, use that value, otherwise add the step and snap that value.\n let newValue = snapValueToStep(prev, minValue, maxValue, clampStep);\n if ((operation === '+' && newValue > prev) || (operation === '-' && newValue < prev)) {\n return newValue;\n }\n\n return snapValueToStep(\n handleDecimalOperation(operation, prev, clampStep),\n minValue,\n maxValue,\n clampStep\n );\n }\n };\n\n let increment = () => {\n let newValue = safeNextStep('+', minValue);\n\n // if we've arrived at the same value that was previously in the state, the\n // input value should be updated to match\n // ex type 4, press increment, highlight the number in the input, type 4 again, press increment\n // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input\n if (newValue === numberValue) {\n setInputValue(format(newValue));\n }\n\n setNumberValue(newValue);\n validation.commitValidation();\n };\n\n let decrement = () => {\n let newValue = safeNextStep('-', maxValue);\n\n if (newValue === numberValue) {\n setInputValue(format(newValue));\n }\n\n setNumberValue(newValue);\n validation.commitValidation();\n };\n\n let incrementToMax = () => {\n if (maxValue != null) {\n setNumberValue(snapValueToStep(maxValue, minValue, maxValue, clampStep));\n validation.commitValidation();\n }\n };\n\n let decrementToMin = () => {\n if (minValue != null) {\n setNumberValue(minValue);\n validation.commitValidation();\n }\n };\n\n let canIncrement = useMemo(() => (\n !isDisabled &&\n !isReadOnly &&\n (\n isNaN(parsedValue) ||\n (maxValue === undefined || isNaN(maxValue)) ||\n snapValueToStep(parsedValue, minValue, maxValue, clampStep) > parsedValue ||\n handleDecimalOperation('+', parsedValue, clampStep) <= maxValue\n )\n ), [isDisabled, isReadOnly, minValue, maxValue, clampStep, parsedValue]);\n\n let canDecrement = useMemo(() => (\n !isDisabled &&\n !isReadOnly &&\n (\n isNaN(parsedValue) ||\n (minValue === undefined || isNaN(minValue)) ||\n snapValueToStep(parsedValue, minValue, maxValue, clampStep) < parsedValue ||\n handleDecimalOperation('-', parsedValue, clampStep) >= minValue\n )\n ), [isDisabled, isReadOnly, minValue, maxValue, clampStep, parsedValue]);\n\n let validate = (value: string) => numberParser.isValidPartialNumber(value, minValue, maxValue);\n\n return {\n ...validation,\n validate,\n increment,\n incrementToMax,\n decrement,\n decrementToMin,\n canIncrement,\n canDecrement,\n minValue,\n maxValue,\n numberValue: parsedValue,\n defaultNumberValue: isNaN(defaultValue) ? initialValue : defaultValue,\n setNumberValue,\n setInputValue,\n inputValue,\n commit\n };\n}\n\nfunction handleDecimalOperation(operator: '-' | '+', value1: number, value2: number): number {\n let result = operator === '+' ? value1 + value2 : value1 - value2;\n\n // Check if we have decimals\n if (value1 % 1 !== 0 || value2 % 1 !== 0) {\n const value1Decimal = value1.toString().split('.');\n const value2Decimal = value2.toString().split('.');\n const value1DecimalLength = (value1Decimal[1] && value1Decimal[1].length) || 0;\n const value2DecimalLength = (value2Decimal[1] && value2Decimal[1].length) || 0;\n const multiplier = Math.pow(10, Math.max(value1DecimalLength, value2DecimalLength));\n\n // Transform the decimals to integers based on the precision\n value1 = Math.round(value1 * multiplier);\n value2 = Math.round(value2 * multiplier);\n\n // Perform the operation on integers values to make sure we don't get a fancy decimal value\n result = operator === '+' ? value1 + value2 : value1 - value2;\n\n // Transform the integer result back to decimal\n result /= multiplier;\n }\n\n return result;\n}\n"],"names":[],"version":3,"file":"useNumberFieldState.mjs.map"}
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA4GM,SAAS,0CAAoB,KAA8B;IAChE,IAAI,YACF,QAAQ,YACR,QAAQ,QACR,IAAI,iBACJ,aAAa,SACb,KAAK,gBACL,eAAe,eACf,QAAQ,UACR,MAAM,cACN,UAAU,cACV,UAAU,kBACV,iBAAiB,QAClB,GAAG;IAEJ,IAAI,UAAU,MACZ,QAAQ;IAGV,IAAI,YAAY,CAAA,GAAA,kBAAU,EACxB,CAAA;QACE,OAAO,SAAS,aAAa,MAAM,QAC/B,CAAA,GAAA,yCAAI,EAAE,OAAO,UAAU,YACvB,CAAA,GAAA,yCAAc,EAAE,OAAO,UAAU,UAAU;IACjD,GACA;QAAC;QAAM;QAAU;KAAS;IAG5B,IAAI,UAAU,aAAa,CAAC,MAAM,UAAU,mBAAmB,QAC7D,QAAQ,UAAU;IAGpB,IAAI,CA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AAO;AACT","sources":["packages/react-stately/src/numberfield/useNumberFieldState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, snapValueToStep} from '../utils/number';\n\nimport {\n FocusableProps,\n HelpTextProps,\n InputBase,\n LabelableProps,\n RangeInputBase,\n TextInputBase,\n Validation,\n ValueBase\n} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {NumberFormatter, NumberParser} from '@internationalized/number';\nimport {useCallback, useMemo, useState} from 'react';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface NumberFieldProps\n extends\n InputBase,\n Validation<number>,\n FocusableProps,\n TextInputBase,\n ValueBase<number>,\n RangeInputBase<number>,\n LabelableProps,\n HelpTextProps {\n /**\n * Formatting options for the value displayed in the number field.\n * This also affects what characters are allowed to be typed by the user.\n */\n formatOptions?: Intl.NumberFormatOptions;\n /**\n * Controls the behavior of the number field when the user blurs the field after editing. 'snap'\n * will clamp the value to the min/max values, and snap to the nearest step value. 'validate' will\n * not clamp the value, and will validate that the value is within the min/max range and on a\n * valid step.\n *\n * @default 'snap'\n */\n commitBehavior?: 'snap' | 'validate';\n}\n\nexport interface NumberFieldState extends FormValidationState {\n /**\n * The current text value of the input. Updated as the user types,\n * and formatted according to `formatOptions` on blur.\n */\n inputValue: string;\n /**\n * The currently parsed number value, or NaN if a valid number could not be parsed.\n * Updated based on the `inputValue` as the user types.\n */\n numberValue: number;\n /** The default value of the input. */\n defaultNumberValue: number;\n /** The minimum value of the number field. */\n minValue?: number;\n /** The maximum value of the number field. */\n maxValue?: number;\n /** Whether the current value can be incremented according to the maximum value and step. */\n canIncrement: boolean;\n /** Whether the current value can be decremented according to the minimum value and step. */\n canDecrement: boolean;\n /**\n * Validates a user input string according to the current locale and format options. Values can be\n * partially entered, and may be valid even if they cannot currently be parsed to a number. Can be\n * used to implement validation as a user types.\n */\n validate(value: string): boolean;\n /** Sets the current text value of the input. */\n setInputValue(val: string): void;\n /** Sets the number value. */\n setNumberValue(val: number): void;\n /**\n * Commits the current input value. The value is parsed to a number, clamped according to the\n * minimum and maximum values of the field, and snapped to the nearest step value. This will fire\n * the `onChange` prop with the new value, and if uncontrolled, update the `numberValue`.\n * Typically this is called when the field is blurred.\n *\n * @param value - The value to commit. If not provided, the current input value is used.\n */\n commit(value?: string): void;\n /** Increments the current input value to the next step boundary, and fires `onChange`. */\n increment(): void;\n /** Decrements the current input value to the next step boundary, and fires `onChange`. */\n decrement(): void;\n /** Sets the current value to the `maxValue` if any, and fires `onChange`. */\n incrementToMax(): void;\n /** Sets the current value to the `minValue` if any, and fires `onChange`. */\n decrementToMin(): void;\n}\n\nexport interface NumberFieldStateOptions extends NumberFieldProps {\n /**\n * The locale that should be used for parsing.\n *\n * @default 'en-US'\n */\n locale: string;\n}\n\n/**\n * Provides state management for a number field component. Number fields allow users to enter a\n * number, and increment or decrement the value using stepper buttons.\n */\nexport function useNumberFieldState(props: NumberFieldStateOptions): NumberFieldState {\n let {\n minValue,\n maxValue,\n step,\n formatOptions,\n value,\n defaultValue = NaN,\n onChange,\n locale,\n isDisabled,\n isReadOnly,\n commitBehavior = 'snap'\n } = props;\n\n if (value === null) {\n value = NaN;\n }\n\n let snapValue = useCallback(\n value => {\n return step === undefined || isNaN(step)\n ? clamp(value, minValue, maxValue)\n : snapValueToStep(value, minValue, maxValue, step);\n },\n [step, minValue, maxValue]\n );\n\n if (value !== undefined && !isNaN(value) && commitBehavior === 'snap') {\n value = snapValue(value);\n }\n\n if (!isNaN(defaultValue) && commitBehavior === 'snap') {\n defaultValue = snapValue(defaultValue);\n }\n\n let [numberValue, setNumberValue] = useControlledState<number>(\n value,\n isNaN(defaultValue) ? NaN : defaultValue,\n onChange\n );\n let [initialValue] = useState(numberValue);\n let [inputValue, setInputValue] = useState(() =>\n isNaN(numberValue) ? '' : new NumberFormatter(locale, formatOptions).format(numberValue)\n );\n\n let numberParser = useMemo(\n () => new NumberParser(locale, formatOptions),\n [locale, formatOptions]\n );\n let numberingSystem = useMemo(\n () => numberParser.getNumberingSystem(inputValue),\n [numberParser, inputValue]\n );\n let formatter = useMemo(\n () => new NumberFormatter(locale, {...formatOptions, numberingSystem}),\n [locale, formatOptions, numberingSystem]\n );\n let intlOptions = useMemo(() => formatter.resolvedOptions(), [formatter]);\n let format = useCallback(\n (value: number) => (isNaN(value) || value === null ? '' : formatter.format(value)),\n [formatter]\n );\n\n let validation = useFormValidationState({\n ...props,\n value: numberValue\n });\n\n let clampStep = step !== undefined && !isNaN(step) ? step : 1;\n if (intlOptions.style === 'percent' && (step === undefined || isNaN(step))) {\n clampStep = 0.01;\n }\n\n // Update the input value when the number value or format options change. This is done\n // in a useEffect so that the controlled behavior is correct and we only update the\n // textfield after prop changes.\n let [prevValue, setPrevValue] = useState(numberValue);\n let [prevLocale, setPrevLocale] = useState(locale);\n let [prevFormatOptions, setPrevFormatOptions] = useState(formatOptions);\n if (\n !Object.is(numberValue, prevValue) ||\n locale !== prevLocale ||\n !isEqualFormatOptions(formatOptions, prevFormatOptions)\n ) {\n setInputValue(format(numberValue));\n setPrevValue(numberValue);\n setPrevLocale(locale);\n setPrevFormatOptions(formatOptions);\n }\n\n let parsedValue = useMemo(() => numberParser.parse(inputValue), [numberParser, inputValue]);\n let commit = (overrideValue?: string) => {\n let newInputValue = overrideValue === undefined ? inputValue : overrideValue;\n let newParsedValue = parsedValue;\n if (overrideValue !== undefined) {\n newParsedValue = numberParser.parse(newInputValue);\n }\n // Set to empty state if input value is empty\n if (!newInputValue.length) {\n setNumberValue(NaN);\n setInputValue(value === undefined ? '' : format(numberValue));\n return;\n }\n\n // if it failed to parse, then reset input to formatted version of current number\n if (isNaN(newParsedValue)) {\n setInputValue(format(numberValue));\n return;\n }\n\n // Clamp to min and max, round to the nearest step, and round to specified number of digits\n let clampedValue = commitBehavior === 'snap' ? snapValue(newParsedValue) : newParsedValue;\n clampedValue = numberParser.parse(format(clampedValue));\n let shouldValidate = clampedValue !== numberValue;\n setNumberValue(clampedValue);\n\n // in a controlled state, the numberValue won't change, so we won't go back to our old input without help\n setInputValue(format(value === undefined ? clampedValue : numberValue));\n if (shouldValidate) {\n validation.commitValidation();\n }\n };\n\n let safeNextStep = (operation: '+' | '-', minMax: number = 0) => {\n let prev = parsedValue;\n\n if (isNaN(prev)) {\n // if the input is empty, start from the min/max value when incrementing/decrementing,\n // or zero if there is no min/max value defined.\n let newValue = isNaN(minMax) ? 0 : minMax;\n return snapValueToStep(newValue, minValue, maxValue, clampStep);\n } else {\n // otherwise, first snap the current value to the nearest step. if it moves in the direction\n // we're going, use that value, otherwise add the step and snap that value.\n let newValue = snapValueToStep(prev, minValue, maxValue, clampStep);\n if ((operation === '+' && newValue > prev) || (operation === '-' && newValue < prev)) {\n return newValue;\n }\n\n return snapValueToStep(\n handleDecimalOperation(operation, prev, clampStep),\n minValue,\n maxValue,\n clampStep\n );\n }\n };\n\n let increment = () => {\n let newValue = safeNextStep('+', minValue);\n\n // if we've arrived at the same value that was previously in the state, the\n // input value should be updated to match\n // ex type 4, press increment, highlight the number in the input, type 4 again, press increment\n // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input\n if (newValue === numberValue) {\n setInputValue(format(newValue));\n }\n\n setNumberValue(newValue);\n validation.commitValidation();\n };\n\n let decrement = () => {\n let newValue = safeNextStep('-', maxValue);\n\n if (newValue === numberValue) {\n setInputValue(format(newValue));\n }\n\n setNumberValue(newValue);\n validation.commitValidation();\n };\n\n let incrementToMax = () => {\n if (maxValue != null) {\n setNumberValue(snapValueToStep(maxValue, minValue, maxValue, clampStep));\n validation.commitValidation();\n }\n };\n\n let decrementToMin = () => {\n if (minValue != null) {\n setNumberValue(minValue);\n validation.commitValidation();\n }\n };\n\n let canIncrement = useMemo(\n () =>\n !isDisabled &&\n !isReadOnly &&\n (isNaN(parsedValue) ||\n maxValue === undefined ||\n isNaN(maxValue) ||\n snapValueToStep(parsedValue, minValue, maxValue, clampStep) > parsedValue ||\n handleDecimalOperation('+', parsedValue, clampStep) <= maxValue),\n [isDisabled, isReadOnly, minValue, maxValue, clampStep, parsedValue]\n );\n\n let canDecrement = useMemo(\n () =>\n !isDisabled &&\n !isReadOnly &&\n (isNaN(parsedValue) ||\n minValue === undefined ||\n isNaN(minValue) ||\n snapValueToStep(parsedValue, minValue, maxValue, clampStep) < parsedValue ||\n handleDecimalOperation('-', parsedValue, clampStep) >= minValue),\n [isDisabled, isReadOnly, minValue, maxValue, clampStep, parsedValue]\n );\n\n let validate = (value: string) => numberParser.isValidPartialNumber(value, minValue, maxValue);\n\n return {\n ...validation,\n validate,\n increment,\n incrementToMax,\n decrement,\n decrementToMin,\n canIncrement,\n canDecrement,\n minValue,\n maxValue,\n numberValue: parsedValue,\n defaultNumberValue: isNaN(defaultValue) ? initialValue : defaultValue,\n setNumberValue,\n setInputValue,\n inputValue,\n commit\n };\n}\n\n// Shallow equality is sufficient here because all values in Intl.NumberFormatOptions are primitives.\nfunction isEqualFormatOptions(\n a: Intl.NumberFormatOptions | undefined,\n b: Intl.NumberFormatOptions | undefined\n) {\n if (a === b) {\n return true;\n }\n if (!a || !b) {\n return false;\n }\n let aKeys = Object.keys(a);\n let bKeys = Object.keys(b);\n if (aKeys.length !== bKeys.length) {\n return false;\n }\n for (let key of aKeys) {\n if (b[key] !== a[key]) {\n return false;\n }\n }\n return true;\n}\n\nfunction handleDecimalOperation(operator: '-' | '+', value1: number, value2: number): number {\n let result = operator === '+' ? value1 + value2 : value1 - value2;\n\n // Check if we have decimals\n if (value1 % 1 !== 0 || value2 % 1 !== 0) {\n const value1Decimal = value1.toString().split('.');\n const value2Decimal = value2.toString().split('.');\n const value1DecimalLength = (value1Decimal[1] && value1Decimal[1].length) || 0;\n const value2DecimalLength = (value2Decimal[1] && value2Decimal[1].length) || 0;\n const multiplier = Math.pow(10, Math.max(value1DecimalLength, value2DecimalLength));\n\n // Transform the decimals to integers based on the precision\n value1 = Math.round(value1 * multiplier);\n value2 = Math.round(value2 * multiplier);\n\n // Perform the operation on integers values to make sure we don't get a fancy decimal value\n result = operator === '+' ? value1 + value2 : value1 - value2;\n\n // Transform the integer result back to decimal\n result /= multiplier;\n }\n\n return result;\n}\n"],"names":[],"version":3,"file":"useNumberFieldState.mjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AA+BM,SAAS,0CAAuB,KAA0B;IAC/D,IAAI,CAAC,QAAQ,QAAQ,GAAG,CAAA,GAAA,4CAAiB,EAAE,MAAM,MAAM,EAAE,MAAM,WAAW,IAAI,OAAO,MAAM,YAAY;IAEvG,MAAM,OAAO,CAAA,GAAA,wBAAU,EAAE;QACvB,QAAQ;IACV,GAAG;QAAC;KAAQ;IAEZ,MAAM,QAAQ,CAAA,GAAA,wBAAU,EAAE;QACxB,QAAQ;IACV,GAAG;QAAC;KAAQ;IAEZ,MAAM,SAAS,CAAA,GAAA,wBAAU,EAAE;QACzB,QAAQ,CAAC;IACX,GAAG;QAAC;QAAS;KAAO;IAEpB,OAAO;gBACL;iBACA;cACA;eACA;gBACA;IACF;AACF","sources":["packages/react-stately/src/overlays/useOverlayTriggerState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {useCallback} from 'react';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface OverlayTriggerProps {\n /** Whether the overlay is open by default (controlled). */\n isOpen?: boolean,\n /** Whether the overlay is open by default (uncontrolled). */\n defaultOpen?: boolean,\n /** Handler that is called when the overlay's open state changes. */\n onOpenChange?: (isOpen: boolean) => void\n}\n\nexport interface OverlayTriggerState {\n /** Whether the overlay is currently open. */\n readonly isOpen: boolean,\n /** Sets whether the overlay is open. */\n setOpen(isOpen: boolean): void,\n /** Opens the overlay. */\n open(): void,\n /** Closes the overlay. */\n close(): void,\n /** Toggles the overlay's visibility. */\n toggle(): void\n}\n\n/**\n * Manages state for an overlay trigger. Tracks whether the overlay is open, and provides\n * methods to toggle this state.\n */\nexport function useOverlayTriggerState(props: OverlayTriggerProps): OverlayTriggerState {\n let [isOpen, setOpen] = useControlledState(props.isOpen, props.defaultOpen || false, props.onOpenChange);\n\n const open = useCallback(() => {\n setOpen(true);\n }, [setOpen]);\n\n const close = useCallback(() => {\n setOpen(false);\n }, [setOpen]);\n\n const toggle = useCallback(() => {\n setOpen(!isOpen);\n }, [setOpen, isOpen]);\n\n return {\n isOpen,\n setOpen,\n open,\n close,\n toggle\n };\n}\n"],"names":[],"version":3,"file":"useOverlayTriggerState.cjs.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AA+BM,SAAS,0CAAuB,KAA0B;IAC/D,IAAI,CAAC,QAAQ,QAAQ,GAAG,CAAA,GAAA,4CAAiB,EACvC,MAAM,MAAM,EACZ,MAAM,WAAW,IAAI,OACrB,MAAM,YAAY;IAGpB,MAAM,OAAO,CAAA,GAAA,wBAAU,EAAE;QACvB,QAAQ;IACV,GAAG;QAAC;KAAQ;IAEZ,MAAM,QAAQ,CAAA,GAAA,wBAAU,EAAE;QACxB,QAAQ;IACV,GAAG;QAAC;KAAQ;IAEZ,MAAM,SAAS,CAAA,GAAA,wBAAU,EAAE;QACzB,QAAQ,CAAC;IACX,GAAG;QAAC;QAAS;KAAO;IAEpB,OAAO;gBACL;iBACA;cACA;eACA;gBACA;IACF;AACF","sources":["packages/react-stately/src/overlays/useOverlayTriggerState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {useCallback} from 'react';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface OverlayTriggerProps {\n /** Whether the overlay is open by default (controlled). */\n isOpen?: boolean;\n /** Whether the overlay is open by default (uncontrolled). */\n defaultOpen?: boolean;\n /** Handler that is called when the overlay's open state changes. */\n onOpenChange?: (isOpen: boolean) => void;\n}\n\nexport interface OverlayTriggerState {\n /** Whether the overlay is currently open. */\n readonly isOpen: boolean;\n /** Sets whether the overlay is open. */\n setOpen(isOpen: boolean): void;\n /** Opens the overlay. */\n open(): void;\n /** Closes the overlay. */\n close(): void;\n /** Toggles the overlay's visibility. */\n toggle(): void;\n}\n\n/**\n * Manages state for an overlay trigger. Tracks whether the overlay is open, and provides\n * methods to toggle this state.\n */\nexport function useOverlayTriggerState(props: OverlayTriggerProps): OverlayTriggerState {\n let [isOpen, setOpen] = useControlledState(\n props.isOpen,\n props.defaultOpen || false,\n props.onOpenChange\n );\n\n const open = useCallback(() => {\n setOpen(true);\n }, [setOpen]);\n\n const close = useCallback(() => {\n setOpen(false);\n }, [setOpen]);\n\n const toggle = useCallback(() => {\n setOpen(!isOpen);\n }, [setOpen, isOpen]);\n\n return {\n isOpen,\n setOpen,\n open,\n close,\n toggle\n };\n}\n"],"names":[],"version":3,"file":"useOverlayTriggerState.cjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA+BM,SAAS,0CAAuB,KAA0B;IAC/D,IAAI,CAAC,QAAQ,QAAQ,GAAG,CAAA,GAAA,yCAAiB,EAAE,MAAM,MAAM,EAAE,MAAM,WAAW,IAAI,OAAO,MAAM,YAAY;IAEvG,MAAM,OAAO,CAAA,GAAA,kBAAU,EAAE;QACvB,QAAQ;IACV,GAAG;QAAC;KAAQ;IAEZ,MAAM,QAAQ,CAAA,GAAA,kBAAU,EAAE;QACxB,QAAQ;IACV,GAAG;QAAC;KAAQ;IAEZ,MAAM,SAAS,CAAA,GAAA,kBAAU,EAAE;QACzB,QAAQ,CAAC;IACX,GAAG;QAAC;QAAS;KAAO;IAEpB,OAAO;gBACL;iBACA;cACA;eACA;gBACA;IACF;AACF","sources":["packages/react-stately/src/overlays/useOverlayTriggerState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {useCallback} from 'react';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface OverlayTriggerProps {\n /** Whether the overlay is open by default (controlled). */\n isOpen?: boolean,\n /** Whether the overlay is open by default (uncontrolled). */\n defaultOpen?: boolean,\n /** Handler that is called when the overlay's open state changes. */\n onOpenChange?: (isOpen: boolean) => void\n}\n\nexport interface OverlayTriggerState {\n /** Whether the overlay is currently open. */\n readonly isOpen: boolean,\n /** Sets whether the overlay is open. */\n setOpen(isOpen: boolean): void,\n /** Opens the overlay. */\n open(): void,\n /** Closes the overlay. */\n close(): void,\n /** Toggles the overlay's visibility. */\n toggle(): void\n}\n\n/**\n * Manages state for an overlay trigger. Tracks whether the overlay is open, and provides\n * methods to toggle this state.\n */\nexport function useOverlayTriggerState(props: OverlayTriggerProps): OverlayTriggerState {\n let [isOpen, setOpen] = useControlledState(props.isOpen, props.defaultOpen || false, props.onOpenChange);\n\n const open = useCallback(() => {\n setOpen(true);\n }, [setOpen]);\n\n const close = useCallback(() => {\n setOpen(false);\n }, [setOpen]);\n\n const toggle = useCallback(() => {\n setOpen(!isOpen);\n }, [setOpen, isOpen]);\n\n return {\n isOpen,\n setOpen,\n open,\n close,\n toggle\n };\n}\n"],"names":[],"version":3,"file":"useOverlayTriggerState.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA+BM,SAAS,0CAAuB,KAA0B;IAC/D,IAAI,CAAC,QAAQ,QAAQ,GAAG,CAAA,GAAA,yCAAiB,EACvC,MAAM,MAAM,EACZ,MAAM,WAAW,IAAI,OACrB,MAAM,YAAY;IAGpB,MAAM,OAAO,CAAA,GAAA,kBAAU,EAAE;QACvB,QAAQ;IACV,GAAG;QAAC;KAAQ;IAEZ,MAAM,QAAQ,CAAA,GAAA,kBAAU,EAAE;QACxB,QAAQ;IACV,GAAG;QAAC;KAAQ;IAEZ,MAAM,SAAS,CAAA,GAAA,kBAAU,EAAE;QACzB,QAAQ,CAAC;IACX,GAAG;QAAC;QAAS;KAAO;IAEpB,OAAO;gBACL;iBACA;cACA;eACA;gBACA;IACF;AACF","sources":["packages/react-stately/src/overlays/useOverlayTriggerState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {useCallback} from 'react';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface OverlayTriggerProps {\n /** Whether the overlay is open by default (controlled). */\n isOpen?: boolean;\n /** Whether the overlay is open by default (uncontrolled). */\n defaultOpen?: boolean;\n /** Handler that is called when the overlay's open state changes. */\n onOpenChange?: (isOpen: boolean) => void;\n}\n\nexport interface OverlayTriggerState {\n /** Whether the overlay is currently open. */\n readonly isOpen: boolean;\n /** Sets whether the overlay is open. */\n setOpen(isOpen: boolean): void;\n /** Opens the overlay. */\n open(): void;\n /** Closes the overlay. */\n close(): void;\n /** Toggles the overlay's visibility. */\n toggle(): void;\n}\n\n/**\n * Manages state for an overlay trigger. Tracks whether the overlay is open, and provides\n * methods to toggle this state.\n */\nexport function useOverlayTriggerState(props: OverlayTriggerProps): OverlayTriggerState {\n let [isOpen, setOpen] = useControlledState(\n props.isOpen,\n props.defaultOpen || false,\n props.onOpenChange\n );\n\n const open = useCallback(() => {\n setOpen(true);\n }, [setOpen]);\n\n const close = useCallback(() => {\n setOpen(false);\n }, [setOpen]);\n\n const toggle = useCallback(() => {\n setOpen(!isOpen);\n }, [setOpen, isOpen]);\n\n return {\n isOpen,\n setOpen,\n open,\n close,\n toggle\n };\n}\n"],"names":[],"version":3,"file":"useOverlayTriggerState.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA+BM,SAAS,0CAAuB,KAA0B;IAC/D,IAAI,CAAC,QAAQ,QAAQ,GAAG,CAAA,GAAA,yCAAiB,EAAE,MAAM,MAAM,EAAE,MAAM,WAAW,IAAI,OAAO,MAAM,YAAY;IAEvG,MAAM,OAAO,CAAA,GAAA,kBAAU,EAAE;QACvB,QAAQ;IACV,GAAG;QAAC;KAAQ;IAEZ,MAAM,QAAQ,CAAA,GAAA,kBAAU,EAAE;QACxB,QAAQ;IACV,GAAG;QAAC;KAAQ;IAEZ,MAAM,SAAS,CAAA,GAAA,kBAAU,EAAE;QACzB,QAAQ,CAAC;IACX,GAAG;QAAC;QAAS;KAAO;IAEpB,OAAO;gBACL;iBACA;cACA;eACA;gBACA;IACF;AACF","sources":["packages/react-stately/src/overlays/useOverlayTriggerState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {useCallback} from 'react';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface OverlayTriggerProps {\n /** Whether the overlay is open by default (controlled). */\n isOpen?: boolean,\n /** Whether the overlay is open by default (uncontrolled). */\n defaultOpen?: boolean,\n /** Handler that is called when the overlay's open state changes. */\n onOpenChange?: (isOpen: boolean) => void\n}\n\nexport interface OverlayTriggerState {\n /** Whether the overlay is currently open. */\n readonly isOpen: boolean,\n /** Sets whether the overlay is open. */\n setOpen(isOpen: boolean): void,\n /** Opens the overlay. */\n open(): void,\n /** Closes the overlay. */\n close(): void,\n /** Toggles the overlay's visibility. */\n toggle(): void\n}\n\n/**\n * Manages state for an overlay trigger. Tracks whether the overlay is open, and provides\n * methods to toggle this state.\n */\nexport function useOverlayTriggerState(props: OverlayTriggerProps): OverlayTriggerState {\n let [isOpen, setOpen] = useControlledState(props.isOpen, props.defaultOpen || false, props.onOpenChange);\n\n const open = useCallback(() => {\n setOpen(true);\n }, [setOpen]);\n\n const close = useCallback(() => {\n setOpen(false);\n }, [setOpen]);\n\n const toggle = useCallback(() => {\n setOpen(!isOpen);\n }, [setOpen, isOpen]);\n\n return {\n isOpen,\n setOpen,\n open,\n close,\n toggle\n };\n}\n"],"names":[],"version":3,"file":"useOverlayTriggerState.mjs.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA+BM,SAAS,0CAAuB,KAA0B;IAC/D,IAAI,CAAC,QAAQ,QAAQ,GAAG,CAAA,GAAA,yCAAiB,EACvC,MAAM,MAAM,EACZ,MAAM,WAAW,IAAI,OACrB,MAAM,YAAY;IAGpB,MAAM,OAAO,CAAA,GAAA,kBAAU,EAAE;QACvB,QAAQ;IACV,GAAG;QAAC;KAAQ;IAEZ,MAAM,QAAQ,CAAA,GAAA,kBAAU,EAAE;QACxB,QAAQ;IACV,GAAG;QAAC;KAAQ;IAEZ,MAAM,SAAS,CAAA,GAAA,kBAAU,EAAE;QACzB,QAAQ,CAAC;IACX,GAAG;QAAC;QAAS;KAAO;IAEpB,OAAO;gBACL;iBACA;cACA;eACA;gBACA;IACF;AACF","sources":["packages/react-stately/src/overlays/useOverlayTriggerState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {useCallback} from 'react';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface OverlayTriggerProps {\n /** Whether the overlay is open by default (controlled). */\n isOpen?: boolean;\n /** Whether the overlay is open by default (uncontrolled). */\n defaultOpen?: boolean;\n /** Handler that is called when the overlay's open state changes. */\n onOpenChange?: (isOpen: boolean) => void;\n}\n\nexport interface OverlayTriggerState {\n /** Whether the overlay is currently open. */\n readonly isOpen: boolean;\n /** Sets whether the overlay is open. */\n setOpen(isOpen: boolean): void;\n /** Opens the overlay. */\n open(): void;\n /** Closes the overlay. */\n close(): void;\n /** Toggles the overlay's visibility. */\n toggle(): void;\n}\n\n/**\n * Manages state for an overlay trigger. Tracks whether the overlay is open, and provides\n * methods to toggle this state.\n */\nexport function useOverlayTriggerState(props: OverlayTriggerProps): OverlayTriggerState {\n let [isOpen, setOpen] = useControlledState(\n props.isOpen,\n props.defaultOpen || false,\n props.onOpenChange\n );\n\n const open = useCallback(() => {\n setOpen(true);\n }, [setOpen]);\n\n const close = useCallback(() => {\n setOpen(false);\n }, [setOpen]);\n\n const toggle = useCallback(() => {\n setOpen(!isOpen);\n }, [setOpen, isOpen]);\n\n return {\n isOpen,\n setOpen,\n open,\n close,\n toggle\n };\n}\n"],"names":[],"version":3,"file":"useOverlayTriggerState.mjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAyDD,IAAI,iCAAW,KAAK,KAAK,CAAC,KAAK,MAAM,KAAK;AAC1C,IAAI,0BAAI;AAMD,SAAS,0CAAmB,KAAsB;IACvD,mGAAmG;IACnG,IAAI,OAAO,CAAA,GAAA,oBAAM,EAAE,IAAM,MAAM,IAAI,IAAI,CAAC,YAAY,EAAE,+BAAS,CAAC,EAAE,EAAE,yBAAG,EAAE;QAAC,MAAM,IAAI;KAAC;IACrF,IAAI,CAAC,eAAe,YAAY,GAAG,CAAA,GAAA,4CAAiB,EAAE,MAAM,KAAK,EAAE,MAAM,YAAY,IAAI,MAAM,MAAM,QAAQ;IAC7G,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,qBAAO,EAAE;IAC9B,IAAI,CAAC,kBAAkB,oBAAoB,GAAG,CAAA,GAAA,qBAAO,EAAiB;IAEtE,IAAI,aAAa,CAAA,GAAA,gDAAqB,EAAE;QACtC,GAAG,KAAK;QACR,OAAO;IACT;IAEA,IAAI,mBAAmB,CAAC;QACtB,IAAI,CAAC,MAAM,UAAU,IAAI,CAAC,MAAM,UAAU,EAAE;YAC1C,YAAY;YACZ,WAAW,gBAAgB;QAC7B;IACF;IAEA,IAAI,YAAY,WAAW,iBAAiB,CAAC,SAAS;IAEtD,OAAO;QACL,GAAG,UAAU;cACb;QACA,eAAe;QACf,sBAAsB,MAAM,KAAK,KAAK,YAAY,eAAe,MAAM,YAAY,IAAI;0BACvF;0BACA;6BACA;QACA,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,iBAAiB,MAAM,eAAe,IAAK,CAAA,YAAY,YAAY,IAAG;mBACtE;IACF;AACF","sources":["packages/react-stately/src/radio/useRadioGroupState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusEvents, HelpTextProps, InputBase, InputDOMProps, LabelableProps, Orientation, Validation, ValidationState, ValueBase} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport interface RadioGroupProps extends ValueBase<string|null, string>, InputBase, Pick<InputDOMProps, 'name'>, Validation<string>, LabelableProps, HelpTextProps, FocusEvents {\n /**\n * The axis the Radio Button(s) should align with.\n * @default 'vertical'\n */\n orientation?: Orientation\n}\n\nexport interface RadioGroupState extends FormValidationState {\n /**\n * The name for the group, used for native form submission.\n * @deprecated\n * @private\n */\n readonly name: string,\n\n /** Whether the radio group is disabled. */\n readonly isDisabled: boolean,\n\n /** Whether the radio group is read only. */\n readonly isReadOnly: boolean,\n\n /** Whether the radio group is required. */\n readonly isRequired: boolean,\n\n /**\n * Whether the radio group is valid or invalid.\n * @deprecated Use `isInvalid` instead.\n */\n readonly validationState: ValidationState | null,\n\n /** Whether the radio group is invalid. */\n readonly isInvalid: boolean,\n\n /** The currently selected value. */\n readonly selectedValue: string | null,\n\n /** The default selected value. */\n readonly defaultSelectedValue: string | null,\n\n /** Sets the selected value. */\n setSelectedValue(value: string | null): void,\n\n /** The value of the last focused radio. */\n readonly lastFocusedValue: string | null,\n\n /** Sets the last focused value. */\n setLastFocusedValue(value: string | null): void\n}\n\nlet instance = Math.round(Math.random() * 10000000000);\nlet i = 0;\n\n/**\n * Provides state management for a radio group component. Provides a name for the group,\n * and manages selection and focus state.\n */\nexport function useRadioGroupState(props: RadioGroupProps): RadioGroupState {\n // Preserved here for backward compatibility. React Aria now generates the name instead of stately.\n let name = useMemo(() => props.name || `radio-group-${instance}-${++i}`, [props.name]);\n let [selectedValue, setSelected] = useControlledState(props.value, props.defaultValue ?? null, props.onChange);\n let [initialValue] = useState(selectedValue);\n let [lastFocusedValue, setLastFocusedValue] = useState<string | null>(null);\n\n let validation = useFormValidationState({\n ...props,\n value: selectedValue\n });\n\n let setSelectedValue = (value) => {\n if (!props.isReadOnly && !props.isDisabled) {\n setSelected(value);\n validation.commitValidation();\n }\n };\n\n let isInvalid = validation.displayValidation.isInvalid;\n\n return {\n ...validation,\n name,\n selectedValue: selectedValue,\n defaultSelectedValue: props.value !== undefined ? initialValue : props.defaultValue ?? null,\n setSelectedValue,\n lastFocusedValue,\n setLastFocusedValue,\n isDisabled: props.isDisabled || false,\n isReadOnly: props.isReadOnly || false,\n isRequired: props.isRequired || false,\n validationState: props.validationState || (isInvalid ? 'invalid' : null),\n isInvalid\n };\n}\n"],"names":[],"version":3,"file":"useRadioGroupState.cjs.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AA8ED,IAAI,iCAAW,KAAK,KAAK,CAAC,KAAK,MAAM,KAAK;AAC1C,IAAI,0BAAI;AAMD,SAAS,0CAAmB,KAAsB;IACvD,mGAAmG;IACnG,IAAI,OAAO,CAAA,GAAA,oBAAM,EAAE,IAAM,MAAM,IAAI,IAAI,CAAC,YAAY,EAAE,+BAAS,CAAC,EAAE,EAAE,yBAAG,EAAE;QAAC,MAAM,IAAI;KAAC;IACrF,IAAI,CAAC,eAAe,YAAY,GAAG,CAAA,GAAA,4CAAiB,EAClD,MAAM,KAAK,EACX,MAAM,YAAY,IAAI,MACtB,MAAM,QAAQ;IAEhB,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,qBAAO,EAAE;IAC9B,IAAI,CAAC,kBAAkB,oBAAoB,GAAG,CAAA,GAAA,qBAAO,EAAiB;IAEtE,IAAI,aAAa,CAAA,GAAA,gDAAqB,EAAE;QACtC,GAAG,KAAK;QACR,OAAO;IACT;IAEA,IAAI,mBAAmB,CAAA;QACrB,IAAI,CAAC,MAAM,UAAU,IAAI,CAAC,MAAM,UAAU,EAAE;YAC1C,YAAY;YACZ,WAAW,gBAAgB;QAC7B;IACF;IAEA,IAAI,YAAY,WAAW,iBAAiB,CAAC,SAAS;IAEtD,OAAO;QACL,GAAG,UAAU;cACb;QACA,eAAe;QACf,sBAAsB,MAAM,KAAK,KAAK,YAAY,eAAgB,MAAM,YAAY,IAAI;0BACxF;0BACA;6BACA;QACA,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,iBAAiB,MAAM,eAAe,IAAK,CAAA,YAAY,YAAY,IAAG;mBACtE;IACF;AACF","sources":["packages/react-stately/src/radio/useRadioGroupState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n FocusEvents,\n HelpTextProps,\n InputBase,\n InputDOMProps,\n LabelableProps,\n Orientation,\n Validation,\n ValidationState,\n ValueBase\n} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport interface RadioGroupProps\n extends\n ValueBase<string | null, string>,\n InputBase,\n Pick<InputDOMProps, 'name'>,\n Validation<string>,\n LabelableProps,\n HelpTextProps,\n FocusEvents {\n /**\n * The axis the Radio Button(s) should align with.\n *\n * @default 'vertical'\n */\n orientation?: Orientation;\n}\n\nexport interface RadioGroupState extends FormValidationState {\n /**\n * The name for the group, used for native form submission.\n *\n * @private\n * @deprecated\n */\n readonly name: string;\n\n /** Whether the radio group is disabled. */\n readonly isDisabled: boolean;\n\n /** Whether the radio group is read only. */\n readonly isReadOnly: boolean;\n\n /** Whether the radio group is required. */\n readonly isRequired: boolean;\n\n /**\n * Whether the radio group is valid or invalid.\n *\n * @deprecated Use `isInvalid` instead.\n */\n readonly validationState: ValidationState | null;\n\n /** Whether the radio group is invalid. */\n readonly isInvalid: boolean;\n\n /** The currently selected value. */\n readonly selectedValue: string | null;\n\n /** The default selected value. */\n readonly defaultSelectedValue: string | null;\n\n /** Sets the selected value. */\n setSelectedValue(value: string | null): void;\n\n /** The value of the last focused radio. */\n readonly lastFocusedValue: string | null;\n\n /** Sets the last focused value. */\n setLastFocusedValue(value: string | null): void;\n}\n\nlet instance = Math.round(Math.random() * 10000000000);\nlet i = 0;\n\n/**\n * Provides state management for a radio group component. Provides a name for the group,\n * and manages selection and focus state.\n */\nexport function useRadioGroupState(props: RadioGroupProps): RadioGroupState {\n // Preserved here for backward compatibility. React Aria now generates the name instead of stately.\n let name = useMemo(() => props.name || `radio-group-${instance}-${++i}`, [props.name]);\n let [selectedValue, setSelected] = useControlledState(\n props.value,\n props.defaultValue ?? null,\n props.onChange\n );\n let [initialValue] = useState(selectedValue);\n let [lastFocusedValue, setLastFocusedValue] = useState<string | null>(null);\n\n let validation = useFormValidationState({\n ...props,\n value: selectedValue\n });\n\n let setSelectedValue = value => {\n if (!props.isReadOnly && !props.isDisabled) {\n setSelected(value);\n validation.commitValidation();\n }\n };\n\n let isInvalid = validation.displayValidation.isInvalid;\n\n return {\n ...validation,\n name,\n selectedValue: selectedValue,\n defaultSelectedValue: props.value !== undefined ? initialValue : (props.defaultValue ?? null),\n setSelectedValue,\n lastFocusedValue,\n setLastFocusedValue,\n isDisabled: props.isDisabled || false,\n isReadOnly: props.isReadOnly || false,\n isRequired: props.isRequired || false,\n validationState: props.validationState || (isInvalid ? 'invalid' : null),\n isInvalid\n };\n}\n"],"names":[],"version":3,"file":"useRadioGroupState.cjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAyDD,IAAI,iCAAW,KAAK,KAAK,CAAC,KAAK,MAAM,KAAK;AAC1C,IAAI,0BAAI;AAMD,SAAS,0CAAmB,KAAsB;IACvD,mGAAmG;IACnG,IAAI,OAAO,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,IAAI,IAAI,CAAC,YAAY,EAAE,+BAAS,CAAC,EAAE,EAAE,yBAAG,EAAE;QAAC,MAAM,IAAI;KAAC;QAClB;IAAnE,IAAI,CAAC,eAAe,YAAY,GAAG,CAAA,GAAA,yCAAiB,EAAE,MAAM,KAAK,EAAE,CAAA,sBAAA,MAAM,YAAY,cAAlB,iCAAA,sBAAsB,MAAM,MAAM,QAAQ;IAC7G,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAC9B,IAAI,CAAC,kBAAkB,oBAAoB,GAAG,CAAA,GAAA,eAAO,EAAiB;IAEtE,IAAI,aAAa,CAAA,GAAA,yCAAqB,EAAE;QACtC,GAAG,KAAK;QACR,OAAO;IACT;IAEA,IAAI,mBAAmB,CAAC;QACtB,IAAI,CAAC,MAAM,UAAU,IAAI,CAAC,MAAM,UAAU,EAAE;YAC1C,YAAY;YACZ,WAAW,gBAAgB;QAC7B;IACF;IAEA,IAAI,YAAY,WAAW,iBAAiB,CAAC,SAAS;QAMa;IAJnE,OAAO;QACL,GAAG,UAAU;cACb;QACA,eAAe;QACf,sBAAsB,MAAM,KAAK,KAAK,YAAY,eAAe,CAAA,uBAAA,MAAM,YAAY,cAAlB,kCAAA,uBAAsB;0BACvF;0BACA;6BACA;QACA,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,iBAAiB,MAAM,eAAe,IAAK,CAAA,YAAY,YAAY,IAAG;mBACtE;IACF;AACF","sources":["packages/react-stately/src/radio/useRadioGroupState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusEvents, HelpTextProps, InputBase, InputDOMProps, LabelableProps, Orientation, Validation, ValidationState, ValueBase} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport interface RadioGroupProps extends ValueBase<string|null, string>, InputBase, Pick<InputDOMProps, 'name'>, Validation<string>, LabelableProps, HelpTextProps, FocusEvents {\n /**\n * The axis the Radio Button(s) should align with.\n * @default 'vertical'\n */\n orientation?: Orientation\n}\n\nexport interface RadioGroupState extends FormValidationState {\n /**\n * The name for the group, used for native form submission.\n * @deprecated\n * @private\n */\n readonly name: string,\n\n /** Whether the radio group is disabled. */\n readonly isDisabled: boolean,\n\n /** Whether the radio group is read only. */\n readonly isReadOnly: boolean,\n\n /** Whether the radio group is required. */\n readonly isRequired: boolean,\n\n /**\n * Whether the radio group is valid or invalid.\n * @deprecated Use `isInvalid` instead.\n */\n readonly validationState: ValidationState | null,\n\n /** Whether the radio group is invalid. */\n readonly isInvalid: boolean,\n\n /** The currently selected value. */\n readonly selectedValue: string | null,\n\n /** The default selected value. */\n readonly defaultSelectedValue: string | null,\n\n /** Sets the selected value. */\n setSelectedValue(value: string | null): void,\n\n /** The value of the last focused radio. */\n readonly lastFocusedValue: string | null,\n\n /** Sets the last focused value. */\n setLastFocusedValue(value: string | null): void\n}\n\nlet instance = Math.round(Math.random() * 10000000000);\nlet i = 0;\n\n/**\n * Provides state management for a radio group component. Provides a name for the group,\n * and manages selection and focus state.\n */\nexport function useRadioGroupState(props: RadioGroupProps): RadioGroupState {\n // Preserved here for backward compatibility. React Aria now generates the name instead of stately.\n let name = useMemo(() => props.name || `radio-group-${instance}-${++i}`, [props.name]);\n let [selectedValue, setSelected] = useControlledState(props.value, props.defaultValue ?? null, props.onChange);\n let [initialValue] = useState(selectedValue);\n let [lastFocusedValue, setLastFocusedValue] = useState<string | null>(null);\n\n let validation = useFormValidationState({\n ...props,\n value: selectedValue\n });\n\n let setSelectedValue = (value) => {\n if (!props.isReadOnly && !props.isDisabled) {\n setSelected(value);\n validation.commitValidation();\n }\n };\n\n let isInvalid = validation.displayValidation.isInvalid;\n\n return {\n ...validation,\n name,\n selectedValue: selectedValue,\n defaultSelectedValue: props.value !== undefined ? initialValue : props.defaultValue ?? null,\n setSelectedValue,\n lastFocusedValue,\n setLastFocusedValue,\n isDisabled: props.isDisabled || false,\n isReadOnly: props.isReadOnly || false,\n isRequired: props.isRequired || false,\n validationState: props.validationState || (isInvalid ? 'invalid' : null),\n isInvalid\n };\n}\n"],"names":[],"version":3,"file":"useRadioGroupState.js.map"}
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AA8ED,IAAI,iCAAW,KAAK,KAAK,CAAC,KAAK,MAAM,KAAK;AAC1C,IAAI,0BAAI;AAMD,SAAS,0CAAmB,KAAsB;IACvD,mGAAmG;IACnG,IAAI,OAAO,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,IAAI,IAAI,CAAC,YAAY,EAAE,+BAAS,CAAC,EAAE,EAAE,yBAAG,EAAE;QAAC,MAAM,IAAI;KAAC;QAGnF;IAFF,IAAI,CAAC,eAAe,YAAY,GAAG,CAAA,GAAA,yCAAiB,EAClD,MAAM,KAAK,EACX,CAAA,sBAAA,MAAM,YAAY,cAAlB,iCAAA,sBAAsB,MACtB,MAAM,QAAQ;IAEhB,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAC9B,IAAI,CAAC,kBAAkB,oBAAoB,GAAG,CAAA,GAAA,eAAO,EAAiB;IAEtE,IAAI,aAAa,CAAA,GAAA,yCAAqB,EAAE;QACtC,GAAG,KAAK;QACR,OAAO;IACT;IAEA,IAAI,mBAAmB,CAAA;QACrB,IAAI,CAAC,MAAM,UAAU,IAAI,CAAC,MAAM,UAAU,EAAE;YAC1C,YAAY;YACZ,WAAW,gBAAgB;QAC7B;IACF;IAEA,IAAI,YAAY,WAAW,iBAAiB,CAAC,SAAS;QAMc;IAJpE,OAAO;QACL,GAAG,UAAU;cACb;QACA,eAAe;QACf,sBAAsB,MAAM,KAAK,KAAK,YAAY,eAAgB,CAAA,uBAAA,MAAM,YAAY,cAAlB,kCAAA,uBAAsB;0BACxF;0BACA;6BACA;QACA,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,iBAAiB,MAAM,eAAe,IAAK,CAAA,YAAY,YAAY,IAAG;mBACtE;IACF;AACF","sources":["packages/react-stately/src/radio/useRadioGroupState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n FocusEvents,\n HelpTextProps,\n InputBase,\n InputDOMProps,\n LabelableProps,\n Orientation,\n Validation,\n ValidationState,\n ValueBase\n} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport interface RadioGroupProps\n extends\n ValueBase<string | null, string>,\n InputBase,\n Pick<InputDOMProps, 'name'>,\n Validation<string>,\n LabelableProps,\n HelpTextProps,\n FocusEvents {\n /**\n * The axis the Radio Button(s) should align with.\n *\n * @default 'vertical'\n */\n orientation?: Orientation;\n}\n\nexport interface RadioGroupState extends FormValidationState {\n /**\n * The name for the group, used for native form submission.\n *\n * @private\n * @deprecated\n */\n readonly name: string;\n\n /** Whether the radio group is disabled. */\n readonly isDisabled: boolean;\n\n /** Whether the radio group is read only. */\n readonly isReadOnly: boolean;\n\n /** Whether the radio group is required. */\n readonly isRequired: boolean;\n\n /**\n * Whether the radio group is valid or invalid.\n *\n * @deprecated Use `isInvalid` instead.\n */\n readonly validationState: ValidationState | null;\n\n /** Whether the radio group is invalid. */\n readonly isInvalid: boolean;\n\n /** The currently selected value. */\n readonly selectedValue: string | null;\n\n /** The default selected value. */\n readonly defaultSelectedValue: string | null;\n\n /** Sets the selected value. */\n setSelectedValue(value: string | null): void;\n\n /** The value of the last focused radio. */\n readonly lastFocusedValue: string | null;\n\n /** Sets the last focused value. */\n setLastFocusedValue(value: string | null): void;\n}\n\nlet instance = Math.round(Math.random() * 10000000000);\nlet i = 0;\n\n/**\n * Provides state management for a radio group component. Provides a name for the group,\n * and manages selection and focus state.\n */\nexport function useRadioGroupState(props: RadioGroupProps): RadioGroupState {\n // Preserved here for backward compatibility. React Aria now generates the name instead of stately.\n let name = useMemo(() => props.name || `radio-group-${instance}-${++i}`, [props.name]);\n let [selectedValue, setSelected] = useControlledState(\n props.value,\n props.defaultValue ?? null,\n props.onChange\n );\n let [initialValue] = useState(selectedValue);\n let [lastFocusedValue, setLastFocusedValue] = useState<string | null>(null);\n\n let validation = useFormValidationState({\n ...props,\n value: selectedValue\n });\n\n let setSelectedValue = value => {\n if (!props.isReadOnly && !props.isDisabled) {\n setSelected(value);\n validation.commitValidation();\n }\n };\n\n let isInvalid = validation.displayValidation.isInvalid;\n\n return {\n ...validation,\n name,\n selectedValue: selectedValue,\n defaultSelectedValue: props.value !== undefined ? initialValue : (props.defaultValue ?? null),\n setSelectedValue,\n lastFocusedValue,\n setLastFocusedValue,\n isDisabled: props.isDisabled || false,\n isReadOnly: props.isReadOnly || false,\n isRequired: props.isRequired || false,\n validationState: props.validationState || (isInvalid ? 'invalid' : null),\n isInvalid\n };\n}\n"],"names":[],"version":3,"file":"useRadioGroupState.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAyDD,IAAI,iCAAW,KAAK,KAAK,CAAC,KAAK,MAAM,KAAK;AAC1C,IAAI,0BAAI;AAMD,SAAS,0CAAmB,KAAsB;IACvD,mGAAmG;IACnG,IAAI,OAAO,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,IAAI,IAAI,CAAC,YAAY,EAAE,+BAAS,CAAC,EAAE,EAAE,yBAAG,EAAE;QAAC,MAAM,IAAI;KAAC;IACrF,IAAI,CAAC,eAAe,YAAY,GAAG,CAAA,GAAA,yCAAiB,EAAE,MAAM,KAAK,EAAE,MAAM,YAAY,IAAI,MAAM,MAAM,QAAQ;IAC7G,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAC9B,IAAI,CAAC,kBAAkB,oBAAoB,GAAG,CAAA,GAAA,eAAO,EAAiB;IAEtE,IAAI,aAAa,CAAA,GAAA,yCAAqB,EAAE;QACtC,GAAG,KAAK;QACR,OAAO;IACT;IAEA,IAAI,mBAAmB,CAAC;QACtB,IAAI,CAAC,MAAM,UAAU,IAAI,CAAC,MAAM,UAAU,EAAE;YAC1C,YAAY;YACZ,WAAW,gBAAgB;QAC7B;IACF;IAEA,IAAI,YAAY,WAAW,iBAAiB,CAAC,SAAS;IAEtD,OAAO;QACL,GAAG,UAAU;cACb;QACA,eAAe;QACf,sBAAsB,MAAM,KAAK,KAAK,YAAY,eAAe,MAAM,YAAY,IAAI;0BACvF;0BACA;6BACA;QACA,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,iBAAiB,MAAM,eAAe,IAAK,CAAA,YAAY,YAAY,IAAG;mBACtE;IACF;AACF","sources":["packages/react-stately/src/radio/useRadioGroupState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusEvents, HelpTextProps, InputBase, InputDOMProps, LabelableProps, Orientation, Validation, ValidationState, ValueBase} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport interface RadioGroupProps extends ValueBase<string|null, string>, InputBase, Pick<InputDOMProps, 'name'>, Validation<string>, LabelableProps, HelpTextProps, FocusEvents {\n /**\n * The axis the Radio Button(s) should align with.\n * @default 'vertical'\n */\n orientation?: Orientation\n}\n\nexport interface RadioGroupState extends FormValidationState {\n /**\n * The name for the group, used for native form submission.\n * @deprecated\n * @private\n */\n readonly name: string,\n\n /** Whether the radio group is disabled. */\n readonly isDisabled: boolean,\n\n /** Whether the radio group is read only. */\n readonly isReadOnly: boolean,\n\n /** Whether the radio group is required. */\n readonly isRequired: boolean,\n\n /**\n * Whether the radio group is valid or invalid.\n * @deprecated Use `isInvalid` instead.\n */\n readonly validationState: ValidationState | null,\n\n /** Whether the radio group is invalid. */\n readonly isInvalid: boolean,\n\n /** The currently selected value. */\n readonly selectedValue: string | null,\n\n /** The default selected value. */\n readonly defaultSelectedValue: string | null,\n\n /** Sets the selected value. */\n setSelectedValue(value: string | null): void,\n\n /** The value of the last focused radio. */\n readonly lastFocusedValue: string | null,\n\n /** Sets the last focused value. */\n setLastFocusedValue(value: string | null): void\n}\n\nlet instance = Math.round(Math.random() * 10000000000);\nlet i = 0;\n\n/**\n * Provides state management for a radio group component. Provides a name for the group,\n * and manages selection and focus state.\n */\nexport function useRadioGroupState(props: RadioGroupProps): RadioGroupState {\n // Preserved here for backward compatibility. React Aria now generates the name instead of stately.\n let name = useMemo(() => props.name || `radio-group-${instance}-${++i}`, [props.name]);\n let [selectedValue, setSelected] = useControlledState(props.value, props.defaultValue ?? null, props.onChange);\n let [initialValue] = useState(selectedValue);\n let [lastFocusedValue, setLastFocusedValue] = useState<string | null>(null);\n\n let validation = useFormValidationState({\n ...props,\n value: selectedValue\n });\n\n let setSelectedValue = (value) => {\n if (!props.isReadOnly && !props.isDisabled) {\n setSelected(value);\n validation.commitValidation();\n }\n };\n\n let isInvalid = validation.displayValidation.isInvalid;\n\n return {\n ...validation,\n name,\n selectedValue: selectedValue,\n defaultSelectedValue: props.value !== undefined ? initialValue : props.defaultValue ?? null,\n setSelectedValue,\n lastFocusedValue,\n setLastFocusedValue,\n isDisabled: props.isDisabled || false,\n isReadOnly: props.isReadOnly || false,\n isRequired: props.isRequired || false,\n validationState: props.validationState || (isInvalid ? 'invalid' : null),\n isInvalid\n };\n}\n"],"names":[],"version":3,"file":"useRadioGroupState.mjs.map"}
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AA8ED,IAAI,iCAAW,KAAK,KAAK,CAAC,KAAK,MAAM,KAAK;AAC1C,IAAI,0BAAI;AAMD,SAAS,0CAAmB,KAAsB;IACvD,mGAAmG;IACnG,IAAI,OAAO,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,IAAI,IAAI,CAAC,YAAY,EAAE,+BAAS,CAAC,EAAE,EAAE,yBAAG,EAAE;QAAC,MAAM,IAAI;KAAC;IACrF,IAAI,CAAC,eAAe,YAAY,GAAG,CAAA,GAAA,yCAAiB,EAClD,MAAM,KAAK,EACX,MAAM,YAAY,IAAI,MACtB,MAAM,QAAQ;IAEhB,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAC9B,IAAI,CAAC,kBAAkB,oBAAoB,GAAG,CAAA,GAAA,eAAO,EAAiB;IAEtE,IAAI,aAAa,CAAA,GAAA,yCAAqB,EAAE;QACtC,GAAG,KAAK;QACR,OAAO;IACT;IAEA,IAAI,mBAAmB,CAAA;QACrB,IAAI,CAAC,MAAM,UAAU,IAAI,CAAC,MAAM,UAAU,EAAE;YAC1C,YAAY;YACZ,WAAW,gBAAgB;QAC7B;IACF;IAEA,IAAI,YAAY,WAAW,iBAAiB,CAAC,SAAS;IAEtD,OAAO;QACL,GAAG,UAAU;cACb;QACA,eAAe;QACf,sBAAsB,MAAM,KAAK,KAAK,YAAY,eAAgB,MAAM,YAAY,IAAI;0BACxF;0BACA;6BACA;QACA,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,iBAAiB,MAAM,eAAe,IAAK,CAAA,YAAY,YAAY,IAAG;mBACtE;IACF;AACF","sources":["packages/react-stately/src/radio/useRadioGroupState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n FocusEvents,\n HelpTextProps,\n InputBase,\n InputDOMProps,\n LabelableProps,\n Orientation,\n Validation,\n ValidationState,\n ValueBase\n} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport interface RadioGroupProps\n extends\n ValueBase<string | null, string>,\n InputBase,\n Pick<InputDOMProps, 'name'>,\n Validation<string>,\n LabelableProps,\n HelpTextProps,\n FocusEvents {\n /**\n * The axis the Radio Button(s) should align with.\n *\n * @default 'vertical'\n */\n orientation?: Orientation;\n}\n\nexport interface RadioGroupState extends FormValidationState {\n /**\n * The name for the group, used for native form submission.\n *\n * @private\n * @deprecated\n */\n readonly name: string;\n\n /** Whether the radio group is disabled. */\n readonly isDisabled: boolean;\n\n /** Whether the radio group is read only. */\n readonly isReadOnly: boolean;\n\n /** Whether the radio group is required. */\n readonly isRequired: boolean;\n\n /**\n * Whether the radio group is valid or invalid.\n *\n * @deprecated Use `isInvalid` instead.\n */\n readonly validationState: ValidationState | null;\n\n /** Whether the radio group is invalid. */\n readonly isInvalid: boolean;\n\n /** The currently selected value. */\n readonly selectedValue: string | null;\n\n /** The default selected value. */\n readonly defaultSelectedValue: string | null;\n\n /** Sets the selected value. */\n setSelectedValue(value: string | null): void;\n\n /** The value of the last focused radio. */\n readonly lastFocusedValue: string | null;\n\n /** Sets the last focused value. */\n setLastFocusedValue(value: string | null): void;\n}\n\nlet instance = Math.round(Math.random() * 10000000000);\nlet i = 0;\n\n/**\n * Provides state management for a radio group component. Provides a name for the group,\n * and manages selection and focus state.\n */\nexport function useRadioGroupState(props: RadioGroupProps): RadioGroupState {\n // Preserved here for backward compatibility. React Aria now generates the name instead of stately.\n let name = useMemo(() => props.name || `radio-group-${instance}-${++i}`, [props.name]);\n let [selectedValue, setSelected] = useControlledState(\n props.value,\n props.defaultValue ?? null,\n props.onChange\n );\n let [initialValue] = useState(selectedValue);\n let [lastFocusedValue, setLastFocusedValue] = useState<string | null>(null);\n\n let validation = useFormValidationState({\n ...props,\n value: selectedValue\n });\n\n let setSelectedValue = value => {\n if (!props.isReadOnly && !props.isDisabled) {\n setSelected(value);\n validation.commitValidation();\n }\n };\n\n let isInvalid = validation.displayValidation.isInvalid;\n\n return {\n ...validation,\n name,\n selectedValue: selectedValue,\n defaultSelectedValue: props.value !== undefined ? initialValue : (props.defaultValue ?? null),\n setSelectedValue,\n lastFocusedValue,\n setLastFocusedValue,\n isDisabled: props.isDisabled || false,\n isReadOnly: props.isReadOnly || false,\n isRequired: props.isRequired || false,\n validationState: props.validationState || (isInvalid ? 'invalid' : null),\n isInvalid\n };\n}\n"],"names":[],"version":3,"file":"useRadioGroupState.mjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AA2BM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,4CAAiB,EAAE,+BAAS,MAAM,KAAK,GAAG,+BAAS,MAAM,YAAY,KAAK,IAAI,MAAM,QAAQ;IAEpH,OAAO;eACL;kBACA;IACF;AACF;AAEA,SAAS,+BAAS,GAAG;IACnB,IAAI,OAAO,MACT;IAGF,OAAO,IAAI,QAAQ;AACrB","sources":["packages/react-stately/src/searchfield/useSearchFieldState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusableProps, HelpTextProps, InputBase, LabelableProps, TextInputBase, Validation, ValueBase} from '@react-types/shared';\nimport {useControlledState} from '../utils/useControlledState';\n\n// Copied here to avoid depending on @react-aria/textfield from stately.\nexport interface TextFieldProps<T = HTMLInputElement> extends InputBase, Validation<string>, HelpTextProps, FocusableProps<T>, TextInputBase, ValueBase<string>, LabelableProps {}\n\nexport interface SearchFieldProps extends TextFieldProps {\n /** Handler that is called when the SearchField is submitted. */\n onSubmit?: (value: string) => void,\n\n /** Handler that is called when the clear button is pressed. */\n onClear?: () => void\n}\n\nexport interface SearchFieldState {\n /** The current value of the search field. */\n readonly value: string,\n\n /** Sets the value of the search field. */\n setValue(value: string): void\n}\n\n/**\n * Provides state management for a search field.\n */\nexport function useSearchFieldState(props: SearchFieldProps): SearchFieldState {\n let [value, setValue] = useControlledState(toString(props.value), toString(props.defaultValue) || '', props.onChange);\n\n return {\n value,\n setValue\n };\n}\n\nfunction toString(val) {\n if (val == null) {\n return;\n }\n\n return val.toString();\n}\n"],"names":[],"version":3,"file":"useSearchFieldState.cjs.map"}
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AA2CM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,4CAAiB,EACvC,+BAAS,MAAM,KAAK,GACpB,+BAAS,MAAM,YAAY,KAAK,IAChC,MAAM,QAAQ;IAGhB,OAAO;eACL;kBACA;IACF;AACF;AAEA,SAAS,+BAAS,GAAG;IACnB,IAAI,OAAO,MACT;IAGF,OAAO,IAAI,QAAQ;AACrB","sources":["packages/react-stately/src/searchfield/useSearchFieldState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n FocusableProps,\n HelpTextProps,\n InputBase,\n LabelableProps,\n TextInputBase,\n Validation,\n ValueBase\n} from '@react-types/shared';\nimport {useControlledState} from '../utils/useControlledState';\n\n// Copied here to avoid depending on @react-aria/textfield from stately.\nexport interface TextFieldProps<T = HTMLInputElement>\n extends\n InputBase,\n Validation<string>,\n HelpTextProps,\n FocusableProps<T>,\n TextInputBase,\n ValueBase<string>,\n LabelableProps {}\n\nexport interface SearchFieldProps extends TextFieldProps {\n /** Handler that is called when the SearchField is submitted. */\n onSubmit?: (value: string) => void;\n\n /** Handler that is called when the clear button is pressed. */\n onClear?: () => void;\n}\n\nexport interface SearchFieldState {\n /** The current value of the search field. */\n readonly value: string;\n\n /** Sets the value of the search field. */\n setValue(value: string): void;\n}\n\n/**\n * Provides state management for a search field.\n */\nexport function useSearchFieldState(props: SearchFieldProps): SearchFieldState {\n let [value, setValue] = useControlledState(\n toString(props.value),\n toString(props.defaultValue) || '',\n props.onChange\n );\n\n return {\n value,\n setValue\n };\n}\n\nfunction toString(val) {\n if (val == null) {\n return;\n }\n\n return val.toString();\n}\n"],"names":[],"version":3,"file":"useSearchFieldState.cjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC;AA2BM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,yCAAiB,EAAE,+BAAS,MAAM,KAAK,GAAG,+BAAS,MAAM,YAAY,KAAK,IAAI,MAAM,QAAQ;IAEpH,OAAO;eACL;kBACA;IACF;AACF;AAEA,SAAS,+BAAS,GAAG;IACnB,IAAI,OAAO,MACT;IAGF,OAAO,IAAI,QAAQ;AACrB","sources":["packages/react-stately/src/searchfield/useSearchFieldState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusableProps, HelpTextProps, InputBase, LabelableProps, TextInputBase, Validation, ValueBase} from '@react-types/shared';\nimport {useControlledState} from '../utils/useControlledState';\n\n// Copied here to avoid depending on @react-aria/textfield from stately.\nexport interface TextFieldProps<T = HTMLInputElement> extends InputBase, Validation<string>, HelpTextProps, FocusableProps<T>, TextInputBase, ValueBase<string>, LabelableProps {}\n\nexport interface SearchFieldProps extends TextFieldProps {\n /** Handler that is called when the SearchField is submitted. */\n onSubmit?: (value: string) => void,\n\n /** Handler that is called when the clear button is pressed. */\n onClear?: () => void\n}\n\nexport interface SearchFieldState {\n /** The current value of the search field. */\n readonly value: string,\n\n /** Sets the value of the search field. */\n setValue(value: string): void\n}\n\n/**\n * Provides state management for a search field.\n */\nexport function useSearchFieldState(props: SearchFieldProps): SearchFieldState {\n let [value, setValue] = useControlledState(toString(props.value), toString(props.defaultValue) || '', props.onChange);\n\n return {\n value,\n setValue\n };\n}\n\nfunction toString(val) {\n if (val == null) {\n return;\n }\n\n return val.toString();\n}\n"],"names":[],"version":3,"file":"useSearchFieldState.js.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC;AA2CM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,yCAAiB,EACvC,+BAAS,MAAM,KAAK,GACpB,+BAAS,MAAM,YAAY,KAAK,IAChC,MAAM,QAAQ;IAGhB,OAAO;eACL;kBACA;IACF;AACF;AAEA,SAAS,+BAAS,GAAG;IACnB,IAAI,OAAO,MACT;IAGF,OAAO,IAAI,QAAQ;AACrB","sources":["packages/react-stately/src/searchfield/useSearchFieldState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n FocusableProps,\n HelpTextProps,\n InputBase,\n LabelableProps,\n TextInputBase,\n Validation,\n ValueBase\n} from '@react-types/shared';\nimport {useControlledState} from '../utils/useControlledState';\n\n// Copied here to avoid depending on @react-aria/textfield from stately.\nexport interface TextFieldProps<T = HTMLInputElement>\n extends\n InputBase,\n Validation<string>,\n HelpTextProps,\n FocusableProps<T>,\n TextInputBase,\n ValueBase<string>,\n LabelableProps {}\n\nexport interface SearchFieldProps extends TextFieldProps {\n /** Handler that is called when the SearchField is submitted. */\n onSubmit?: (value: string) => void;\n\n /** Handler that is called when the clear button is pressed. */\n onClear?: () => void;\n}\n\nexport interface SearchFieldState {\n /** The current value of the search field. */\n readonly value: string;\n\n /** Sets the value of the search field. */\n setValue(value: string): void;\n}\n\n/**\n * Provides state management for a search field.\n */\nexport function useSearchFieldState(props: SearchFieldProps): SearchFieldState {\n let [value, setValue] = useControlledState(\n toString(props.value),\n toString(props.defaultValue) || '',\n props.onChange\n );\n\n return {\n value,\n setValue\n };\n}\n\nfunction toString(val) {\n if (val == null) {\n return;\n }\n\n return val.toString();\n}\n"],"names":[],"version":3,"file":"useSearchFieldState.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC;AA2BM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,yCAAiB,EAAE,+BAAS,MAAM,KAAK,GAAG,+BAAS,MAAM,YAAY,KAAK,IAAI,MAAM,QAAQ;IAEpH,OAAO;eACL;kBACA;IACF;AACF;AAEA,SAAS,+BAAS,GAAG;IACnB,IAAI,OAAO,MACT;IAGF,OAAO,IAAI,QAAQ;AACrB","sources":["packages/react-stately/src/searchfield/useSearchFieldState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusableProps, HelpTextProps, InputBase, LabelableProps, TextInputBase, Validation, ValueBase} from '@react-types/shared';\nimport {useControlledState} from '../utils/useControlledState';\n\n// Copied here to avoid depending on @react-aria/textfield from stately.\nexport interface TextFieldProps<T = HTMLInputElement> extends InputBase, Validation<string>, HelpTextProps, FocusableProps<T>, TextInputBase, ValueBase<string>, LabelableProps {}\n\nexport interface SearchFieldProps extends TextFieldProps {\n /** Handler that is called when the SearchField is submitted. */\n onSubmit?: (value: string) => void,\n\n /** Handler that is called when the clear button is pressed. */\n onClear?: () => void\n}\n\nexport interface SearchFieldState {\n /** The current value of the search field. */\n readonly value: string,\n\n /** Sets the value of the search field. */\n setValue(value: string): void\n}\n\n/**\n * Provides state management for a search field.\n */\nexport function useSearchFieldState(props: SearchFieldProps): SearchFieldState {\n let [value, setValue] = useControlledState(toString(props.value), toString(props.defaultValue) || '', props.onChange);\n\n return {\n value,\n setValue\n };\n}\n\nfunction toString(val) {\n if (val == null) {\n return;\n }\n\n return val.toString();\n}\n"],"names":[],"version":3,"file":"useSearchFieldState.mjs.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC;AA2CM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,yCAAiB,EACvC,+BAAS,MAAM,KAAK,GACpB,+BAAS,MAAM,YAAY,KAAK,IAChC,MAAM,QAAQ;IAGhB,OAAO;eACL;kBACA;IACF;AACF;AAEA,SAAS,+BAAS,GAAG;IACnB,IAAI,OAAO,MACT;IAGF,OAAO,IAAI,QAAQ;AACrB","sources":["packages/react-stately/src/searchfield/useSearchFieldState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n FocusableProps,\n HelpTextProps,\n InputBase,\n LabelableProps,\n TextInputBase,\n Validation,\n ValueBase\n} from '@react-types/shared';\nimport {useControlledState} from '../utils/useControlledState';\n\n// Copied here to avoid depending on @react-aria/textfield from stately.\nexport interface TextFieldProps<T = HTMLInputElement>\n extends\n InputBase,\n Validation<string>,\n HelpTextProps,\n FocusableProps<T>,\n TextInputBase,\n ValueBase<string>,\n LabelableProps {}\n\nexport interface SearchFieldProps extends TextFieldProps {\n /** Handler that is called when the SearchField is submitted. */\n onSubmit?: (value: string) => void;\n\n /** Handler that is called when the clear button is pressed. */\n onClear?: () => void;\n}\n\nexport interface SearchFieldState {\n /** The current value of the search field. */\n readonly value: string;\n\n /** Sets the value of the search field. */\n setValue(value: string): void;\n}\n\n/**\n * Provides state management for a search field.\n */\nexport function useSearchFieldState(props: SearchFieldProps): SearchFieldState {\n let [value, setValue] = useControlledState(\n toString(props.value),\n toString(props.defaultValue) || '',\n props.onChange\n );\n\n return {\n value,\n setValue\n };\n}\n\nfunction toString(val) {\n if (val == null) {\n return;\n }\n\n return val.toString();\n}\n"],"names":[],"version":3,"file":"useSearchFieldState.mjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA2GM,SAAS,0CAAqE,KAA+B;IAClH,IAAI,iBACF,gBAAgB,+BAChB,sBAAsB,kBAAkB,UACzC,GAAG;IACJ,IAAI,eAAe,CAAA,GAAA,gDAAqB,EAAE;IAC1C,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,qBAAO,EAAwB;IACvE,IAAI,eAAe,CAAA,GAAA,oBAAM,EAAE;QACzB,OAAO,MAAM,YAAY,KAAK,YAAY,MAAM,YAAY,GAAI,kBAAkB,WAAW,MAAM,kBAAkB,IAAI,OAAO,EAAE;IACpI,GAAG;QAAC,MAAM,YAAY;QAAE,MAAM,kBAAkB;QAAE;KAAc;IAChE,IAAI,QAAQ,CAAA,GAAA,oBAAM,EAAE;QAClB,OAAO,MAAM,KAAK,KAAK,YAAY,MAAM,KAAK,GAAI,kBAAkB,WAAW,MAAM,WAAW,GAAG;IACrG,GAAG;QAAC,MAAM,KAAK;QAAE,MAAM,WAAW;QAAE;KAAc;IAClD,IAAI,CAAC,iBAAiB,mBAAmB,GAAG,CAAA,GAAA,4CAAiB,EAA+B,OAAO,cAAc,MAAM,QAAQ;IAC/H,8FAA8F;IAC9F,IAAI,eAAe,kBAAkB,YAAY,MAAM,OAAO,CAAC,mBAAmB,eAAe,CAAC,EAAE,GAAG;IACvG,IAAI,WAAW,CAAC;QACd,IAAI,kBAAkB,UAAU;YAC9B,IAAI,MAAM,MAAM,OAAO,CAAC,SAAS,KAAK,CAAC,EAAE,IAAI,OAAO;YACpD,mBAAmB;YACnB,IAAI,QAAQ,cACV,MAAM,iBAAiB,GAAG;QAE9B,OAAO;YACL,IAAI,OAAc,EAAE;YACpB,IAAI,MAAM,OA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Aa,CAAC,EAAE,IAAI;uBAClC;QACA,oBAAoB,MAAM,kBAAkB,IAAK,CAAA,MAAM,aAAa,KAAK,WAAW,eAAsB,IAAG;uBAC7G;QACA,MAAK,gBAAsC,IAAI;YAC7C,yCAAyC;YACzC,IAAI,UAAU,UAAU,CAAC,IAAI,KAAK,KAAK,MAAM,qBAAqB,EAAE;gBAClE,iBAAiB;gBACjB,aAAa,IAAI;YACnB;QACF;QACA,QAAO,gBAAsC,IAAI;YAC/C,IAAI,UAAU,UAAU,CAAC,IAAI,KAAK,KAAK,MAAM,qBAAqB,EAAE;gBAClE,iBAAiB;gBACjB,aAAa,MAAM;YACrB;QACF;mBACA;oBACA;IACF;AACF;AAEA,SAAS,mCAAa,KAAqC;IACzD,IAAI,UAAU,WACZ,OAAO;IAET,IAAI,UAAU,MACZ,OAAO,EAAE;IAEX,OAAO,MAAM,OAAO,CAAC,SAAS,QAAQ;QAAC;KAAM;AAC/C","sources":["packages/react-stately/src/select/useSelectState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CollectionBase, CollectionStateBase, FocusableProps, FocusStrategy, HelpTextProps, InputBase, Key, LabelableProps, Node, Selection, TextInputBase, Validation, ValueBase} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {ListState, useListState} from '../list/useListState';\nimport {OverlayTriggerState, useOverlayTriggerState} from '../overlays/useOverlayTriggerState';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport type SelectionMode = 'single' | 'multiple';\nexport type ValueType<M extends SelectionMode> = M extends 'single' ? Key | null : readonly Key[];\nexport type ChangeValueType<M extends SelectionMode> = M extends 'single' ? Key | null : Key[];\ntype ValidationType<M extends SelectionMode> = M extends 'single' ? Key : Key[];\n\nexport interface SelectProps<T, M extends SelectionMode = 'single'> extends CollectionBase<T>, Omit<InputBase, 'isReadOnly'>, ValueBase<ValueType<M>, ChangeValueType<M>>, Validation<ValidationType<M>>, HelpTextProps, LabelableProps, TextInputBase, FocusableProps {\n /**\n * Whether single or multiple selection is enabled.\n * @default 'single'\n */\n selectionMode?: M,\n /**\n * The currently selected key in the collection (controlled).\n * @deprecated\n */\n selectedKey?: Key | null,\n /**\n * The initial selected key in the collection (uncontrolled).\n * @deprecated\n */\n defaultSelectedKey?: Key | null,\n /**\n * Handler that is called when the selection changes.\n * @deprecated\n */\n onSelectionChange?: (key: Key | null) => void,\n /** Sets the open state of the menu. */\n isOpen?: boolean,\n /** Sets the default open state of the menu. */\n defaultOpen?: boolean,\n /** Method that is called when the open state of the menu changes. */\n onOpenChange?: (isOpen: boolean) => void,\n /** Whether the Select should close when an item is selected. Defaults to true if selectionMode is single, false otherwise. */\n shouldCloseOnSelect?: boolean,\n /** Whether the select should be allowed to be open when the collection is empty. */\n allowsEmptyCollection?: boolean\n}\n\nexport interface SelectStateOptions<T, M extends SelectionMode = 'single'> extends Omit<SelectProps<T, M>, 'children'>, CollectionStateBase<T> {}\n\nexport interface SelectState<T, M extends SelectionMode = 'single'> extends ListState<T>, OverlayTriggerState, FormValidationState {\n /**\n * The key for the first selected item.\n * @deprecated\n */\n readonly selectedKey: Key | null,\n\n /**\n * The default selected key.\n * @deprecated\n */\n readonly defaultSelectedKey: Key | null,\n\n /**\n * Sets the selected key.\n * @deprecated\n */\n setSelectedKey(key: Key | null): void,\n\n /** The current select value. */\n readonly value: ValueType<M>,\n\n /** The default select value. */\n readonly defaultValue: ValueType<M>,\n\n /** Sets the select value. */\n setValue(value: Key | readonly Key[] | null): void,\n\n /**\n * The value of the first selected item.\n * @deprecated\n */\n readonly selectedItem: Node<T> | null,\n\n /** The value of the selected items. */\n readonly selectedItems: Node<T>[],\n\n /** Whether the select is currently focused. */\n readonly isFocused: boolean,\n\n /** Sets whether the select is focused. */\n setFocused(isFocused: boolean): void,\n\n /** Controls which item will be auto focused when the menu opens. */\n readonly focusStrategy: FocusStrategy | null,\n\n /** Opens the menu. */\n open(focusStrategy?: FocusStrategy | null): void,\n\n /** Toggles the menu. */\n toggle(focusStrategy?: FocusStrategy | null): void\n}\n\n/**\n * Provides state management for a select component. Handles building a collection\n * of items from props, handles the open state for the popup menu, and manages\n * multiple selection state.\n */\nexport function useSelectState<T extends object, M extends SelectionMode = 'single'>(props: SelectStateOptions<T, M>): SelectState<T, M> {\n let {\n selectionMode = 'single' as M,\n shouldCloseOnSelect = selectionMode === 'single'\n } = props;\n let triggerState = useOverlayTriggerState(props);\n let [focusStrategy, setFocusStrategy] = useState<FocusStrategy | null>(null);\n let defaultValue = useMemo(() => {\n return props.defaultValue !== undefined ? props.defaultValue : (selectionMode === 'single' ? props.defaultSelectedKey ?? null : []) as ValueType<M>;\n }, [props.defaultValue, props.defaultSelectedKey, selectionMode]);\n let value = useMemo(() => {\n return props.value !== undefined ? props.value : (selectionMode === 'single' ? props.selectedKey : undefined) as ValueType<M>;\n }, [props.value, props.selectedKey, selectionMode]);\n let [controlledValue, setControlledValue] = useControlledState<Key | readonly Key[] | null>(value, defaultValue, props.onChange as any);\n // Only display the first selected item if in single selection mode but the value is an array.\n let displayValue = selectionMode === 'single' && Array.isArray(controlledValue) ? controlledValue[0] : controlledValue;\n let setValue = (value: Key | Key[] | null) => {\n if (selectionMode === 'single') {\n let key = Array.isArray(value) ? value[0] ?? null : value;\n setControlledValue(key);\n if (key !== displayValue) {\n props.onSelectionChange?.(key);\n }\n } else {\n let keys: Key[] = [];\n if (Array.isArray(value)) {\n keys = value;\n } else if (value != null) {\n keys = [value];\n }\n\n setControlledValue(keys);\n }\n };\n\n let listState = useListState({\n ...props,\n selectionMode,\n disallowEmptySelection: selectionMode === 'single',\n allowDuplicateSelectionEvents: true,\n selectedKeys: useMemo(() => convertValue(displayValue), [displayValue]),\n onSelectionChange: (keys: Selection) => {\n // impossible, but TS doesn't know that\n if (keys === 'all') {\n return;\n }\n\n if (selectionMode === 'single') {\n let key = keys.values().next().value ?? null;\n setValue(key);\n } else {\n setValue([...keys]);\n }\n if (shouldCloseOnSelect) {\n triggerState.close();\n }\n\n validationState.commitValidation();\n }\n });\n\n let selectedKey = listState.selectionManager.firstSelectedKey;\n let selectedItems = useMemo(() => {\n return [...listState.selectionManager.selectedKeys].map(key => listState.collection.getItem(key)).filter(item => item != null);\n }, [listState.selectionManager.selectedKeys, listState.collection]);\n\n let validationState = useFormValidationState({\n ...props,\n value: Array.isArray(displayValue) && displayValue.length === 0 ? null : displayValue as any\n });\n\n let [isFocused, setFocused] = useState(false);\n let [initialValue] = useState(displayValue);\n\n return {\n ...validationState,\n ...listState,\n ...triggerState,\n value: displayValue as ValueType<M>,\n defaultValue: defaultValue ?? initialValue as ValueType<M>,\n setValue,\n selectedKey,\n setSelectedKey: setValue,\n selectedItem: selectedItems[0] ?? null,\n selectedItems,\n defaultSelectedKey: props.defaultSelectedKey ?? (props.selectionMode === 'single' ? initialValue as Key : null),\n focusStrategy,\n open(focusStrategy: FocusStrategy | null = null) {\n // Don't open if the collection is empty.\n if (listState.collection.size !== 0 || props.allowsEmptyCollection) {\n setFocusStrategy(focusStrategy);\n triggerState.open();\n }\n },\n toggle(focusStrategy: FocusStrategy | null = null) {\n if (listState.collection.size !== 0 || props.allowsEmptyCollection) {\n setFocusStrategy(focusStrategy);\n triggerState.toggle();\n }\n },\n isFocused,\n setFocused\n };\n}\n\nfunction convertValue(value: Key | Key[] | null | undefined) {\n if (value === undefined) {\n return undefined;\n }\n if (value === null) {\n return [];\n }\n return Array.isArray(value) ? value : [value];\n}\n"],"names":[],"version":3,"file":"useSelectState.cjs.map"}
1
+ {"mappings":";;;;;;;;;;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UAAU,CAAC,IAAI,KAAK,KAAK,MAAM,qBAAqB,EAAE;gBAClE,iBAAiB;gBACjB,aAAa,IAAI;YACnB;QACF;QACA,QAAO,gBAAsC,IAAI;YAC/C,IAAI,UAAU,UAAU,CAAC,IAAI,KAAK,KAAK,MAAM,qBAAqB,EAAE;gBAClE,iBAAiB;gBACjB,aAAa,MAAM;YACrB;QACF;mBACA;oBACA;IACF;AACF;AAEA,SAAS,mCAAa,KAAqC;IACzD,IAAI,UAAU,WACZ,OAAO;IAET,IAAI,UAAU,MACZ,OAAO,EAAE;IAEX,OAAO,MAAM,OAAO,CAAC,SAAS,QAAQ;QAAC;KAAM;AAC/C","sources":["packages/react-stately/src/select/useSelectState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n CollectionBase,\n CollectionStateBase,\n FocusableProps,\n FocusStrategy,\n HelpTextProps,\n InputBase,\n Key,\n LabelableProps,\n Node,\n Selection,\n TextInputBase,\n Validation,\n ValueBase\n} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {ListState, useListState} from '../list/useListState';\nimport {OverlayTriggerState, useOverlayTriggerState} from '../overlays/useOverlayTriggerState';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport type SelectionMode = 'single' | 'multiple';\nexport type ValueType<M extends SelectionMode> = M extends 'single' ? Key | null : readonly Key[];\nexport type ChangeValueType<M extends SelectionMode> = M extends 'single' ? Key | null : Key[];\ntype ValidationType<M extends SelectionMode> = M extends 'single' ? Key : Key[];\n\nexport interface SelectProps<T, M extends SelectionMode = 'single'>\n extends\n CollectionBase<T>,\n Omit<InputBase, 'isReadOnly'>,\n ValueBase<ValueType<M>, ChangeValueType<M>>,\n Validation<ValidationType<M>>,\n HelpTextProps,\n LabelableProps,\n TextInputBase,\n FocusableProps {\n /**\n * Whether single or multiple selection is enabled.\n *\n * @default 'single'\n */\n selectionMode?: M;\n /**\n * The currently selected key in the collection (controlled).\n *\n * @deprecated\n */\n selectedKey?: Key | null;\n /**\n * The initial selected key in the collection (uncontrolled).\n *\n * @deprecated\n */\n defaultSelectedKey?: Key | null;\n /**\n * Handler that is called when the selection changes.\n *\n * @deprecated\n */\n onSelectionChange?: (key: Key | null) => void;\n /** Sets the open state of the menu. */\n isOpen?: boolean;\n /** Sets the default open state of the menu. */\n defaultOpen?: boolean;\n /** Method that is called when the open state of the menu changes. */\n onOpenChange?: (isOpen: boolean) => void;\n /**\n * Whether the Select should close when an item is selected. Defaults to true if selectionMode is\n * single, false otherwise.\n */\n shouldCloseOnSelect?: boolean;\n /** Whether the select should be allowed to be open when the collection is empty. */\n allowsEmptyCollection?: boolean;\n}\n\nexport interface SelectStateOptions<T, M extends SelectionMode = 'single'>\n extends Omit<SelectProps<T, M>, 'children'>, CollectionStateBase<T> {}\n\nexport interface SelectState<T, M extends SelectionMode = 'single'>\n extends ListState<T>, OverlayTriggerState, FormValidationState {\n /**\n * The key for the first selected item.\n *\n * @deprecated\n */\n readonly selectedKey: Key | null;\n\n /**\n * The default selected key.\n *\n * @deprecated\n */\n readonly defaultSelectedKey: Key | null;\n\n /**\n * Sets the selected key.\n *\n * @deprecated\n */\n setSelectedKey(key: Key | null): void;\n\n /** The current select value. */\n readonly value: ValueType<M>;\n\n /** The default select value. */\n readonly defaultValue: ValueType<M>;\n\n /** Sets the select value. */\n setValue(value: Key | readonly Key[] | null): void;\n\n /**\n * The value of the first selected item.\n *\n * @deprecated\n */\n readonly selectedItem: Node<T> | null;\n\n /** The value of the selected items. */\n readonly selectedItems: Node<T>[];\n\n /** Whether the select is currently focused. */\n readonly isFocused: boolean;\n\n /** Sets whether the select is focused. */\n setFocused(isFocused: boolean): void;\n\n /** Controls which item will be auto focused when the menu opens. */\n readonly focusStrategy: FocusStrategy | null;\n\n /** Opens the menu. */\n open(focusStrategy?: FocusStrategy | null): void;\n\n /** Toggles the menu. */\n toggle(focusStrategy?: FocusStrategy | null): void;\n}\n\n/**\n * Provides state management for a select component. Handles building a collection\n * of items from props, handles the open state for the popup menu, and manages\n * multiple selection state.\n */\nexport function useSelectState<T, M extends SelectionMode = 'single'>(\n props: SelectStateOptions<T, M>\n): SelectState<T, M> {\n let {selectionMode = 'single' as M, shouldCloseOnSelect = selectionMode === 'single'} = props;\n let triggerState = useOverlayTriggerState(props);\n let [focusStrategy, setFocusStrategy] = useState<FocusStrategy | null>(null);\n let defaultValue = useMemo(() => {\n return props.defaultValue !== undefined\n ? props.defaultValue\n : ((selectionMode === 'single' ? (props.defaultSelectedKey ?? null) : []) as ValueType<M>);\n }, [props.defaultValue, props.defaultSelectedKey, selectionMode]);\n let value = useMemo(() => {\n return props.value !== undefined\n ? props.value\n : ((selectionMode === 'single' ? props.selectedKey : undefined) as ValueType<M>);\n }, [props.value, props.selectedKey, selectionMode]);\n let [controlledValue, setControlledValue] = useControlledState<Key | readonly Key[] | null>(\n value,\n defaultValue,\n props.onChange as any\n );\n // Only display the first selected item if in single selection mode but the value is an array.\n let displayValue =\n selectionMode === 'single' && Array.isArray(controlledValue)\n ? controlledValue[0]\n : controlledValue;\n let setValue = (value: Key | Key[] | null) => {\n if (selectionMode === 'single') {\n let key = Array.isArray(value) ? (value[0] ?? null) : value;\n setControlledValue(key);\n if (key !== displayValue) {\n props.onSelectionChange?.(key);\n }\n } else {\n let keys: Key[] = [];\n if (Array.isArray(value)) {\n keys = value;\n } else if (value != null) {\n keys = [value];\n }\n\n setControlledValue(keys);\n }\n };\n\n let listState = useListState({\n ...props,\n selectionMode,\n disallowEmptySelection: selectionMode === 'single',\n allowDuplicateSelectionEvents: true,\n selectedKeys: useMemo(() => convertValue(displayValue), [displayValue]),\n onSelectionChange: (keys: Selection) => {\n // impossible, but TS doesn't know that\n if (keys === 'all') {\n return;\n }\n\n if (selectionMode === 'single') {\n let key = keys.values().next().value ?? null;\n setValue(key);\n } else {\n setValue([...keys]);\n }\n if (shouldCloseOnSelect) {\n triggerState.close();\n }\n\n validationState.commitValidation();\n }\n });\n\n let selectedKey = listState.selectionManager.firstSelectedKey;\n let selectedItems = useMemo(() => {\n return [...listState.selectionManager.selectedKeys]\n .map(key => listState.collection.getItem(key))\n .filter(item => item != null);\n }, [listState.selectionManager.selectedKeys, listState.collection]);\n\n let validationState = useFormValidationState({\n ...props,\n value: Array.isArray(displayValue) && displayValue.length === 0 ? null : (displayValue as any)\n });\n\n let [isFocused, setFocused] = useState(false);\n let [initialValue] = useState(displayValue);\n\n return {\n ...validationState,\n ...listState,\n ...triggerState,\n value: displayValue as ValueType<M>,\n defaultValue: defaultValue ?? (initialValue as ValueType<M>),\n setValue,\n selectedKey,\n setSelectedKey: setValue,\n selectedItem: selectedItems[0] ?? null,\n selectedItems,\n defaultSelectedKey:\n props.defaultSelectedKey ?? (props.selectionMode === 'single' ? (initialValue as Key) : null),\n focusStrategy,\n open(focusStrategy: FocusStrategy | null = null) {\n // Don't open if the collection is empty.\n if (listState.collection.size !== 0 || props.allowsEmptyCollection) {\n setFocusStrategy(focusStrategy);\n triggerState.open();\n }\n },\n toggle(focusStrategy: FocusStrategy | null = null) {\n if (listState.collection.size !== 0 || props.allowsEmptyCollection) {\n setFocusStrategy(focusStrategy);\n triggerState.toggle();\n }\n },\n isFocused,\n setFocused\n };\n}\n\nfunction convertValue(value: Key | Key[] | null | undefined) {\n if (value === undefined) {\n return undefined;\n }\n if (value === null) {\n return [];\n }\n return Array.isArray(value) ? value : [value];\n}\n"],"names":[],"version":3,"file":"useSelectState.cjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC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AAhB,6BAAA,kBAAoB;uBAClC;QACA,oBAAoB,CAAA,4BAAA,MAAM,kBAAkB,cAAxB,uCAAA,4BAA6B,MAAM,aAAa,KAAK,WAAW,eAAsB;uBAC1G;QACA,MAAK,gBAAsC,IAAI;YAC7C,yCAAyC;YACzC,IAAI,UAAU,UAAU,CAAC,IAAI,KAAK,KAAK,MAAM,qBAAqB,EAAE;gBAClE,iBAAiB;gBACjB,aAAa,IAAI;YACnB;QACF;QACA,QAAO,gBAAsC,IAAI;YAC/C,IAAI,UAAU,UAAU,CAAC,IAAI,KAAK,KAAK,MAAM,qBAAqB,EAAE;gBAClE,iBAAiB;gBACjB,aAAa,MAAM;YACrB;QACF;mBACA;oBACA;IACF;AACF;AAEA,SAAS,mCAAa,KAAqC;IACzD,IAAI,UAAU,WACZ,OAAO;IAET,IAAI,UAAU,MACZ,OAAO,EAAE;IAEX,OAAO,MAAM,OAAO,CAAC,SAAS,QAAQ;QAAC;KAAM;AAC/C","sources":["packages/react-stately/src/select/useSelectState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CollectionBase, CollectionStateBase, FocusableProps, FocusStrategy, HelpTextProps, InputBase, Key, LabelableProps, Node, Selection, TextInputBase, Validation, ValueBase} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {ListState, useListState} from '../list/useListState';\nimport {OverlayTriggerState, useOverlayTriggerState} from '../overlays/useOverlayTriggerState';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport type SelectionMode = 'single' | 'multiple';\nexport type ValueType<M extends SelectionMode> = M extends 'single' ? Key | null : readonly Key[];\nexport type ChangeValueType<M extends SelectionMode> = M extends 'single' ? Key | null : Key[];\ntype ValidationType<M extends SelectionMode> = M extends 'single' ? Key : Key[];\n\nexport interface SelectProps<T, M extends SelectionMode = 'single'> extends CollectionBase<T>, Omit<InputBase, 'isReadOnly'>, ValueBase<ValueType<M>, ChangeValueType<M>>, Validation<ValidationType<M>>, HelpTextProps, LabelableProps, TextInputBase, FocusableProps {\n /**\n * Whether single or multiple selection is enabled.\n * @default 'single'\n */\n selectionMode?: M,\n /**\n * The currently selected key in the collection (controlled).\n * @deprecated\n */\n selectedKey?: Key | null,\n /**\n * The initial selected key in the collection (uncontrolled).\n * @deprecated\n */\n defaultSelectedKey?: Key | null,\n /**\n * Handler that is called when the selection changes.\n * @deprecated\n */\n onSelectionChange?: (key: Key | null) => void,\n /** Sets the open state of the menu. */\n isOpen?: boolean,\n /** Sets the default open state of the menu. */\n defaultOpen?: boolean,\n /** Method that is called when the open state of the menu changes. */\n onOpenChange?: (isOpen: boolean) => void,\n /** Whether the Select should close when an item is selected. Defaults to true if selectionMode is single, false otherwise. */\n shouldCloseOnSelect?: boolean,\n /** Whether the select should be allowed to be open when the collection is empty. */\n allowsEmptyCollection?: boolean\n}\n\nexport interface SelectStateOptions<T, M extends SelectionMode = 'single'> extends Omit<SelectProps<T, M>, 'children'>, CollectionStateBase<T> {}\n\nexport interface SelectState<T, M extends SelectionMode = 'single'> extends ListState<T>, OverlayTriggerState, FormValidationState {\n /**\n * The key for the first selected item.\n * @deprecated\n */\n readonly selectedKey: Key | null,\n\n /**\n * The default selected key.\n * @deprecated\n */\n readonly defaultSelectedKey: Key | null,\n\n /**\n * Sets the selected key.\n * @deprecated\n */\n setSelectedKey(key: Key | null): void,\n\n /** The current select value. */\n readonly value: ValueType<M>,\n\n /** The default select value. */\n readonly defaultValue: ValueType<M>,\n\n /** Sets the select value. */\n setValue(value: Key | readonly Key[] | null): void,\n\n /**\n * The value of the first selected item.\n * @deprecated\n */\n readonly selectedItem: Node<T> | null,\n\n /** The value of the selected items. */\n readonly selectedItems: Node<T>[],\n\n /** Whether the select is currently focused. */\n readonly isFocused: boolean,\n\n /** Sets whether the select is focused. */\n setFocused(isFocused: boolean): void,\n\n /** Controls which item will be auto focused when the menu opens. */\n readonly focusStrategy: FocusStrategy | null,\n\n /** Opens the menu. */\n open(focusStrategy?: FocusStrategy | null): void,\n\n /** Toggles the menu. */\n toggle(focusStrategy?: FocusStrategy | null): void\n}\n\n/**\n * Provides state management for a select component. Handles building a collection\n * of items from props, handles the open state for the popup menu, and manages\n * multiple selection state.\n */\nexport function useSelectState<T extends object, M extends SelectionMode = 'single'>(props: SelectStateOptions<T, M>): SelectState<T, M> {\n let {\n selectionMode = 'single' as M,\n shouldCloseOnSelect = selectionMode === 'single'\n } = props;\n let triggerState = useOverlayTriggerState(props);\n let [focusStrategy, setFocusStrategy] = useState<FocusStrategy | null>(null);\n let defaultValue = useMemo(() => {\n return props.defaultValue !== undefined ? props.defaultValue : (selectionMode === 'single' ? props.defaultSelectedKey ?? null : []) as ValueType<M>;\n }, [props.defaultValue, props.defaultSelectedKey, selectionMode]);\n let value = useMemo(() => {\n return props.value !== undefined ? props.value : (selectionMode === 'single' ? props.selectedKey : undefined) as ValueType<M>;\n }, [props.value, props.selectedKey, selectionMode]);\n let [controlledValue, setControlledValue] = useControlledState<Key | readonly Key[] | null>(value, defaultValue, props.onChange as any);\n // Only display the first selected item if in single selection mode but the value is an array.\n let displayValue = selectionMode === 'single' && Array.isArray(controlledValue) ? controlledValue[0] : controlledValue;\n let setValue = (value: Key | Key[] | null) => {\n if (selectionMode === 'single') {\n let key = Array.isArray(value) ? value[0] ?? null : value;\n setControlledValue(key);\n if (key !== displayValue) {\n props.onSelectionChange?.(key);\n }\n } else {\n let keys: Key[] = [];\n if (Array.isArray(value)) {\n keys = value;\n } else if (value != null) {\n keys = [value];\n }\n\n setControlledValue(keys);\n }\n };\n\n let listState = useListState({\n ...props,\n selectionMode,\n disallowEmptySelection: selectionMode === 'single',\n allowDuplicateSelectionEvents: true,\n selectedKeys: useMemo(() => convertValue(displayValue), [displayValue]),\n onSelectionChange: (keys: Selection) => {\n // impossible, but TS doesn't know that\n if (keys === 'all') {\n return;\n }\n\n if (selectionMode === 'single') {\n let key = keys.values().next().value ?? null;\n setValue(key);\n } else {\n setValue([...keys]);\n }\n if (shouldCloseOnSelect) {\n triggerState.close();\n }\n\n validationState.commitValidation();\n }\n });\n\n let selectedKey = listState.selectionManager.firstSelectedKey;\n let selectedItems = useMemo(() => {\n return [...listState.selectionManager.selectedKeys].map(key => listState.collection.getItem(key)).filter(item => item != null);\n }, [listState.selectionManager.selectedKeys, listState.collection]);\n\n let validationState = useFormValidationState({\n ...props,\n value: Array.isArray(displayValue) && displayValue.length === 0 ? null : displayValue as any\n });\n\n let [isFocused, setFocused] = useState(false);\n let [initialValue] = useState(displayValue);\n\n return {\n ...validationState,\n ...listState,\n ...triggerState,\n value: displayValue as ValueType<M>,\n defaultValue: defaultValue ?? initialValue as ValueType<M>,\n setValue,\n selectedKey,\n setSelectedKey: setValue,\n selectedItem: selectedItems[0] ?? null,\n selectedItems,\n defaultSelectedKey: props.defaultSelectedKey ?? (props.selectionMode === 'single' ? initialValue as Key : null),\n focusStrategy,\n open(focusStrategy: FocusStrategy | null = null) {\n // Don't open if the collection is empty.\n if (listState.collection.size !== 0 || props.allowsEmptyCollection) {\n setFocusStrategy(focusStrategy);\n triggerState.open();\n }\n },\n toggle(focusStrategy: FocusStrategy | null = null) {\n if (listState.collection.size !== 0 || props.allowsEmptyCollection) {\n setFocusStrategy(focusStrategy);\n triggerState.toggle();\n }\n },\n isFocused,\n setFocused\n };\n}\n\nfunction convertValue(value: Key | Key[] | null | undefined) {\n if (value === undefined) {\n return undefined;\n }\n if (value === null) {\n return [];\n }\n return Array.isArray(value) ? value : [value];\n}\n"],"names":[],"version":3,"file":"useSelectState.js.map"}
1
+ {"m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CAAA,kBAAA,aAAa,CAAC,EAAE,cAAhB,6BAAA,kBAAoB;uBAClC;QACA,oBACE,CAAA,4BAAA,MAAM,kBAAkB,cAAxB,uCAAA,4BAA6B,MAAM,aAAa,KAAK,WAAY,eAAuB;uBAC1F;QACA,MAAK,gBAAsC,IAAI;YAC7C,yCAAyC;YACzC,IAAI,UAAU,UAAU,CAAC,IAAI,KAAK,KAAK,MAAM,qBAAqB,EAAE;gBAClE,iBAAiB;gBACjB,aAAa,IAAI;YACnB;QACF;QACA,QAAO,gBAAsC,IAAI;YAC/C,IAAI,UAAU,UAAU,CAAC,IAAI,KAAK,KAAK,MAAM,qBAAqB,EAAE;gBAClE,iBAAiB;gBACjB,aAAa,MAAM;YACrB;QACF;mBACA;oBACA;IACF;AACF;AAEA,SAAS,mCAAa,KAAqC;IACzD,IAAI,UAAU,WACZ,OAAO;IAET,IAAI,UAAU,MACZ,OAAO,EAAE;IAEX,OAAO,MAAM,OAAO,CAAC,SAAS,QAAQ;QAAC;KAAM;AAC/C","sources":["packages/react-stately/src/select/useSelectState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n CollectionBase,\n CollectionStateBase,\n FocusableProps,\n FocusStrategy,\n HelpTextProps,\n InputBase,\n Key,\n LabelableProps,\n Node,\n Selection,\n TextInputBase,\n Validation,\n ValueBase\n} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {ListState, useListState} from '../list/useListState';\nimport {OverlayTriggerState, useOverlayTriggerState} from '../overlays/useOverlayTriggerState';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport type SelectionMode = 'single' | 'multiple';\nexport type ValueType<M extends SelectionMode> = M extends 'single' ? Key | null : readonly Key[];\nexport type ChangeValueType<M extends SelectionMode> = M extends 'single' ? Key | null : Key[];\ntype ValidationType<M extends SelectionMode> = M extends 'single' ? Key : Key[];\n\nexport interface SelectProps<T, M extends SelectionMode = 'single'>\n extends\n CollectionBase<T>,\n Omit<InputBase, 'isReadOnly'>,\n ValueBase<ValueType<M>, ChangeValueType<M>>,\n Validation<ValidationType<M>>,\n HelpTextProps,\n LabelableProps,\n TextInputBase,\n FocusableProps {\n /**\n * Whether single or multiple selection is enabled.\n *\n * @default 'single'\n */\n selectionMode?: M;\n /**\n * The currently selected key in the collection (controlled).\n *\n * @deprecated\n */\n selectedKey?: Key | null;\n /**\n * The initial selected key in the collection (uncontrolled).\n *\n * @deprecated\n */\n defaultSelectedKey?: Key | null;\n /**\n * Handler that is called when the selection changes.\n *\n * @deprecated\n */\n onSelectionChange?: (key: Key | null) => void;\n /** Sets the open state of the menu. */\n isOpen?: boolean;\n /** Sets the default open state of the menu. */\n defaultOpen?: boolean;\n /** Method that is called when the open state of the menu changes. */\n onOpenChange?: (isOpen: boolean) => void;\n /**\n * Whether the Select should close when an item is selected. Defaults to true if selectionMode is\n * single, false otherwise.\n */\n shouldCloseOnSelect?: boolean;\n /** Whether the select should be allowed to be open when the collection is empty. */\n allowsEmptyCollection?: boolean;\n}\n\nexport interface SelectStateOptions<T, M extends SelectionMode = 'single'>\n extends Omit<SelectProps<T, M>, 'children'>, CollectionStateBase<T> {}\n\nexport interface SelectState<T, M extends SelectionMode = 'single'>\n extends ListState<T>, OverlayTriggerState, FormValidationState {\n /**\n * The key for the first selected item.\n *\n * @deprecated\n */\n readonly selectedKey: Key | null;\n\n /**\n * The default selected key.\n *\n * @deprecated\n */\n readonly defaultSelectedKey: Key | null;\n\n /**\n * Sets the selected key.\n *\n * @deprecated\n */\n setSelectedKey(key: Key | null): void;\n\n /** The current select value. */\n readonly value: ValueType<M>;\n\n /** The default select value. */\n readonly defaultValue: ValueType<M>;\n\n /** Sets the select value. */\n setValue(value: Key | readonly Key[] | null): void;\n\n /**\n * The value of the first selected item.\n *\n * @deprecated\n */\n readonly selectedItem: Node<T> | null;\n\n /** The value of the selected items. */\n readonly selectedItems: Node<T>[];\n\n /** Whether the select is currently focused. */\n readonly isFocused: boolean;\n\n /** Sets whether the select is focused. */\n setFocused(isFocused: boolean): void;\n\n /** Controls which item will be auto focused when the menu opens. */\n readonly focusStrategy: FocusStrategy | null;\n\n /** Opens the menu. */\n open(focusStrategy?: FocusStrategy | null): void;\n\n /** Toggles the menu. */\n toggle(focusStrategy?: FocusStrategy | null): void;\n}\n\n/**\n * Provides state management for a select component. Handles building a collection\n * of items from props, handles the open state for the popup menu, and manages\n * multiple selection state.\n */\nexport function useSelectState<T, M extends SelectionMode = 'single'>(\n props: SelectStateOptions<T, M>\n): SelectState<T, M> {\n let {selectionMode = 'single' as M, shouldCloseOnSelect = selectionMode === 'single'} = props;\n let triggerState = useOverlayTriggerState(props);\n let [focusStrategy, setFocusStrategy] = useState<FocusStrategy | null>(null);\n let defaultValue = useMemo(() => {\n return props.defaultValue !== undefined\n ? props.defaultValue\n : ((selectionMode === 'single' ? (props.defaultSelectedKey ?? null) : []) as ValueType<M>);\n }, [props.defaultValue, props.defaultSelectedKey, selectionMode]);\n let value = useMemo(() => {\n return props.value !== undefined\n ? props.value\n : ((selectionMode === 'single' ? props.selectedKey : undefined) as ValueType<M>);\n }, [props.value, props.selectedKey, selectionMode]);\n let [controlledValue, setControlledValue] = useControlledState<Key | readonly Key[] | null>(\n value,\n defaultValue,\n props.onChange as any\n );\n // Only display the first selected item if in single selection mode but the value is an array.\n let displayValue =\n selectionMode === 'single' && Array.isArray(controlledValue)\n ? controlledValue[0]\n : controlledValue;\n let setValue = (value: Key | Key[] | null) => {\n if (selectionMode === 'single') {\n let key = Array.isArray(value) ? (value[0] ?? null) : value;\n setControlledValue(key);\n if (key !== displayValue) {\n props.onSelectionChange?.(key);\n }\n } else {\n let keys: Key[] = [];\n if (Array.isArray(value)) {\n keys = value;\n } else if (value != null) {\n keys = [value];\n }\n\n setControlledValue(keys);\n }\n };\n\n let listState = useListState({\n ...props,\n selectionMode,\n disallowEmptySelection: selectionMode === 'single',\n allowDuplicateSelectionEvents: true,\n selectedKeys: useMemo(() => convertValue(displayValue), [displayValue]),\n onSelectionChange: (keys: Selection) => {\n // impossible, but TS doesn't know that\n if (keys === 'all') {\n return;\n }\n\n if (selectionMode === 'single') {\n let key = keys.values().next().value ?? null;\n setValue(key);\n } else {\n setValue([...keys]);\n }\n if (shouldCloseOnSelect) {\n triggerState.close();\n }\n\n validationState.commitValidation();\n }\n });\n\n let selectedKey = listState.selectionManager.firstSelectedKey;\n let selectedItems = useMemo(() => {\n return [...listState.selectionManager.selectedKeys]\n .map(key => listState.collection.getItem(key))\n .filter(item => item != null);\n }, [listState.selectionManager.selectedKeys, listState.collection]);\n\n let validationState = useFormValidationState({\n ...props,\n value: Array.isArray(displayValue) && displayValue.length === 0 ? null : (displayValue as any)\n });\n\n let [isFocused, setFocused] = useState(false);\n let [initialValue] = useState(displayValue);\n\n return {\n ...validationState,\n ...listState,\n ...triggerState,\n value: displayValue as ValueType<M>,\n defaultValue: defaultValue ?? (initialValue as ValueType<M>),\n setValue,\n selectedKey,\n setSelectedKey: setValue,\n selectedItem: selectedItems[0] ?? null,\n selectedItems,\n defaultSelectedKey:\n props.defaultSelectedKey ?? (props.selectionMode === 'single' ? (initialValue as Key) : null),\n focusStrategy,\n open(focusStrategy: FocusStrategy | null = null) {\n // Don't open if the collection is empty.\n if (listState.collection.size !== 0 || props.allowsEmptyCollection) {\n setFocusStrategy(focusStrategy);\n triggerState.open();\n }\n },\n toggle(focusStrategy: FocusStrategy | null = null) {\n if (listState.collection.size !== 0 || props.allowsEmptyCollection) {\n setFocusStrategy(focusStrategy);\n triggerState.toggle();\n }\n },\n isFocused,\n setFocused\n };\n}\n\nfunction convertValue(value: Key | Key[] | null | undefined) {\n if (value === undefined) {\n return undefined;\n }\n if (value === null) {\n return [];\n }\n return Array.isArray(value) ? value : [value];\n}\n"],"names":[],"version":3,"file":"useSelectState.js.map"}