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;;;;;;AAmCM,SAAS,0CAA4C,KAA4B;IACtF,IAAI,iBACF,gBAAgB,iCAChB,uBAAuB,mBACvB,eAAe,EACf,uBAAuB,gBAAgB,EACvC,8BAA8B,uBAAuB,6BACrD,yBAAyB,YACzB,QAAQ,EACT,GAAG;IAEJ,IAAI,CAAC,CAAA,GAAA,yCAAc,KACjB,MAAM,IAAI,MAAM;IAGlB,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA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,CAAC;QAGrB,OAAO,GAAG,CAAC,KAAK,GAAG,EAAE;QAErB,KAAK,IAAI,SAAS,KAAK,UAAU,CAC/B,IAAI,CAAE,CAAA,MAAM,IAAI,KAAK,UAAU,iBAAiB,SAAS,CAAC,aAAa,GAAG,CAAC,KAAK,GAAG,CAAA;YACjF,IAAI,MAAM,IAAI,KAAK,QACjB,UAAU;iBAEV,0EAA0E;YAC1E,UAAU;;IAIlB;IAEA,KAAK,IAAI,QAAQ,aACf,UAAU;IAGZ,OAAO;gBACL;yBACA;uBACA;QACA,YAAY;eAAI;YAAiB;gBAAC,GAAG,IAAI;gBAAG,YAAY;YAAa;SAAE;IACzE;AACF","sources":["packages/react-stately/src/table/useTreeGridState.ts"],"sourcesContent":["/*\n * Copyright 2023 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 {CollectionBuilder} from '../collections/CollectionBuilder';\nimport {GridNode} from '../grid/GridCollection';\nimport {Key} from '@react-types/shared';\nimport {ReactElement, useMemo} from 'react';\nimport {TableCollection} from './TableCollection';\nimport {tableNestedRows} from '../flags/flags';\nimport {TableState, TableStateProps, useTableState} from './useTableState';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface TreeGridState<T> extends Omit<TableState<T>, 'expandedKeys'> {\n /** A set of keys for items that are expanded. */\n expandedKeys: 'all' | Set<Key>,\n /** Toggles the expanded state for a row by its key. */\n toggleKey(key: Key): void,\n /** The key map containing nodes representing the collection's tree grid structure. */\n keyMap: Map<Key, GridNode<T>>,\n /** The number of leaf columns provided by the user. */\n userColumnCount: number\n}\n\nexport interface TreeGridStateProps<T> extends Omit<TableStateProps<T>, 'collection'> {\n /** The currently expanded keys in the collection (controlled). */\n UNSTABLE_expandedKeys?: 'all' | Iterable<Key>,\n /** The initial expanded keys in the collection (uncontrolled). */\n UNSTABLE_defaultExpandedKeys?: 'all' | Iterable<Key>,\n /** Handler that is called when items are expanded or collapsed. */\n UNSTABLE_onExpandedChange?: (keys: Set<Key>) => any\n}\n\n/**\n * Provides state management for a tree grid component. Handles building a collection\n * of columns and rows from props. In addition, it tracks and manages expanded rows, row selection, and sort order changes.\n */\nexport function UNSTABLE_useTreeGridState<T extends object>(props: TreeGridStateProps<T>): TreeGridState<T> {\n let {\n selectionMode = 'none',\n showSelectionCheckboxes,\n showDragButtons,\n UNSTABLE_expandedKeys: propExpandedKeys,\n UNSTABLE_defaultExpandedKeys: propDefaultExpandedKeys,\n UNSTABLE_onExpandedChange,\n children\n } = props;\n\n if (!tableNestedRows()) {\n throw new Error('Feature flag for table nested rows must be enabled to use useTreeGridState.');\n }\n\n let [expandedKeys, setExpandedKeys] = useControlledState(\n propExpandedKeys ? convertExpanded(propExpandedKeys) : undefined,\n propDefaultExpandedKeys ? convertExpanded(propDefaultExpandedKeys) : new Set(),\n UNSTABLE_onExpandedChange\n );\n\n let context = useMemo(() => ({\n showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== 'none',\n showDragButtons: showDragButtons,\n selectionMode,\n columns: []\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }), [children, showSelectionCheckboxes, selectionMode, showDragButtons]);\n\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let nodes = useMemo(() => builder.build({children: children as ReactElement<any>[]}, context), [builder, children, context]);\n let treeGridCollection = useMemo(() => {\n return generateTreeGridCollection<T>(nodes, {showSelectionCheckboxes, showDragButtons, expandedKeys});\n }, [nodes, showSelectionCheckboxes, showDragButtons, expandedKeys]);\n\n let onToggle = (key: Key) => {\n setExpandedKeys(toggleKey(expandedKeys, key, treeGridCollection));\n };\n\n let collection = useMemo(() => {\n return new TableCollection(treeGridCollection.tableNodes, null, context);\n }, [context, treeGridCollection.tableNodes]);\n\n let tableState = useTableState({...props, collection});\n return {\n ...tableState,\n keyMap: treeGridCollection.keyMap,\n userColumnCount: treeGridCollection.userColumnCount,\n expandedKeys,\n toggleKey: onToggle,\n treeColumn: tableState.treeColumn ?? collection.rowHeaderColumnKeys.keys().next().value ?? null\n };\n}\n\nfunction toggleKey<T>(currentExpandedKeys: 'all' | Set<Key>, key: Key, collection: TreeGridCollection<T>): Set<Key> {\n let updatedExpandedKeys: Set<Key>;\n if (currentExpandedKeys === 'all') {\n updatedExpandedKeys = new Set(collection.flattenedRows.filter(row => row.props.UNSTABLE_childItems || row.props.children.length > collection.userColumnCount).map(row => row.key));\n updatedExpandedKeys.delete(key);\n } else {\n updatedExpandedKeys = new Set(currentExpandedKeys);\n if (updatedExpandedKeys.has(key)) {\n updatedExpandedKeys.delete(key);\n } else {\n updatedExpandedKeys.add(key);\n }\n }\n\n return updatedExpandedKeys;\n}\n\nfunction convertExpanded(expanded: 'all' | Iterable<Key>): 'all' | Set<Key> {\n if (!expanded) {\n return new Set<Key>();\n }\n\n return expanded === 'all'\n ? 'all'\n : new Set(expanded);\n}\n\ninterface TreeGridCollectionOptions {\n showSelectionCheckboxes?: boolean,\n showDragButtons?: boolean,\n expandedKeys: 'all' | Set<Key>\n}\n\ninterface TreeGridCollection<T> {\n keyMap: Map<Key, GridNode<T>>,\n tableNodes: GridNode<T>[],\n flattenedRows: GridNode<T>[],\n userColumnCount: number\n}\nfunction generateTreeGridCollection<T>(nodes, opts: TreeGridCollectionOptions): TreeGridCollection<T> {\n let {\n expandedKeys = new Set()\n } = opts;\n\n let body: GridNode<T> | null = null;\n let flattenedRows: GridNode<T>[] = [];\n let userColumnCount = 0;\n let originalColumns: GridNode<T>[] = [];\n let keyMap = new Map();\n\n let topLevelRows: GridNode<T>[] = [];\n let visit = (node: GridNode<T>) => {\n switch (node.type) {\n case 'body':\n body = node;\n keyMap.set(body.key, body);\n break;\n case 'column':\n if (!node.hasChildNodes) {\n userColumnCount++;\n }\n break;\n case 'item':\n topLevelRows.push(node);\n return;\n }\n\n for (let child of node.childNodes) {\n visit(child);\n }\n };\n\n for (let node of nodes) {\n if (node.type === 'column') {\n originalColumns.push(node);\n }\n visit(node);\n }\n\n // Update each grid node in the treegrid table with values specific to a treegrid structure. Also store a set of flattened row nodes for TableCollection to consume\n let visitNode = (node: GridNode<T>) => {\n if (node.type === 'item') {\n flattenedRows.push(node);\n }\n\n keyMap.set(node.key, node);\n\n for (let child of node.childNodes) {\n if (!(child.type === 'item' && expandedKeys !== 'all' && !expandedKeys.has(node.key))) {\n if (child.type === 'item') {\n visitNode(child);\n } else {\n // We enforce that the cells come before rows so can just reuse cell index\n visitNode(child);\n }\n }\n }\n };\n\n for (let node of topLevelRows) {\n visitNode(node as GridNode<T>);\n }\n\n return {\n keyMap,\n userColumnCount,\n flattenedRows,\n tableNodes: [...originalColumns, {...body!, childNodes: flattenedRows}]\n };\n}\n"],"names":[],"version":3,"file":"useTreeGridState.js.map"}
1
+ {"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAoCM,SAAS,0CACd,KAA4B;IAE5B,IAAI,iBACF,gBAAgB,iCAChB,uBAAuB,mBACvB,eAAe,EACf,uBAAuB,gBAAgB,EACvC,8BAA8B,uBAAuB,6BACrD,yBAAyB,YACzB,QAAQ,EACT,GAAG;IAEJ,IAAI,CAAC,CAAA,GAAA,yCAAc,KACjB,MAAM,IAAI,MAAM;IAGlB,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,yCAAiB,EACrD,mBAAmB,sCAAgB,oBAAoB,WACvD,0BAA0B,sCAAgB,2BAA2B,IAAI,OACzE;IAGF,IAAI,UAAU,CAAA,GAAA,cAAM,EAClB,IAAO,CAAA;YACL,yBAAyB,2BAA2B,kBAAkB;YACtE,iBAAiB;2BACjB;YACA,SAAS,EAAE;QACb,CAAA,GACA,uDAAuD;IACvD;QAAC;QAAU;QAAy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E;YAC1E,UAAU;;IAIlB;IAEA,KAAK,IAAI,QAAQ,aACf,UAAU;IAGZ,OAAO;gBACL;yBACA;uBACA;QACA,YAAY;eAAI;YAAiB;gBAAC,GAAG,IAAI;gBAAG,YAAY;YAAa;SAAE;IACzE;AACF","sources":["packages/react-stately/src/table/useTreeGridState.ts"],"sourcesContent":["/*\n * Copyright 2023 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 {CollectionBuilder} from '../collections/CollectionBuilder';\nimport {GridNode} from '../grid/GridCollection';\nimport {Key} from '@react-types/shared';\nimport {ReactElement, useMemo} from 'react';\nimport {TableCollection} from './TableCollection';\nimport {tableNestedRows} from '../flags/flags';\nimport {TableState, TableStateProps, useTableState} from './useTableState';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface TreeGridState<T> extends Omit<TableState<T>, 'expandedKeys'> {\n /** A set of keys for items that are expanded. */\n expandedKeys: 'all' | Set<Key>;\n /** Toggles the expanded state for a row by its key. */\n toggleKey(key: Key): void;\n /** The key map containing nodes representing the collection's tree grid structure. */\n keyMap: Map<Key, GridNode<T>>;\n /** The number of leaf columns provided by the user. */\n userColumnCount: number;\n}\n\nexport interface TreeGridStateProps<T> extends Omit<TableStateProps<T>, 'collection'> {\n /** The currently expanded keys in the collection (controlled). */\n UNSTABLE_expandedKeys?: 'all' | Iterable<Key>;\n /** The initial expanded keys in the collection (uncontrolled). */\n UNSTABLE_defaultExpandedKeys?: 'all' | Iterable<Key>;\n /** Handler that is called when items are expanded or collapsed. */\n UNSTABLE_onExpandedChange?: (keys: Set<Key>) => any;\n}\n\n/**\n * Provides state management for a tree grid component. Handles building a collection of columns and\n * rows from props. In addition, it tracks and manages expanded rows, row selection, and sort order\n * changes.\n */\nexport function UNSTABLE_useTreeGridState<T extends object>(\n props: TreeGridStateProps<T>\n): TreeGridState<T> {\n let {\n selectionMode = 'none',\n showSelectionCheckboxes,\n showDragButtons,\n UNSTABLE_expandedKeys: propExpandedKeys,\n UNSTABLE_defaultExpandedKeys: propDefaultExpandedKeys,\n UNSTABLE_onExpandedChange,\n children\n } = props;\n\n if (!tableNestedRows()) {\n throw new Error('Feature flag for table nested rows must be enabled to use useTreeGridState.');\n }\n\n let [expandedKeys, setExpandedKeys] = useControlledState(\n propExpandedKeys ? convertExpanded(propExpandedKeys) : undefined,\n propDefaultExpandedKeys ? convertExpanded(propDefaultExpandedKeys) : new Set(),\n UNSTABLE_onExpandedChange\n );\n\n let context = useMemo(\n () => ({\n showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== 'none',\n showDragButtons: showDragButtons,\n selectionMode,\n columns: []\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [children, showSelectionCheckboxes, selectionMode, showDragButtons]\n );\n\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let nodes = useMemo(\n () => builder.build({children: children as ReactElement<any>[]}, context),\n [builder, children, context]\n );\n let treeGridCollection = useMemo(() => {\n return generateTreeGridCollection<T>(nodes, {\n showSelectionCheckboxes,\n showDragButtons,\n expandedKeys\n });\n }, [nodes, showSelectionCheckboxes, showDragButtons, expandedKeys]);\n\n let onToggle = (key: Key) => {\n setExpandedKeys(toggleKey(expandedKeys, key, treeGridCollection));\n };\n\n let collection = useMemo(() => {\n return new TableCollection(treeGridCollection.tableNodes, null, context);\n }, [context, treeGridCollection.tableNodes]);\n\n let tableState = useTableState({...props, collection});\n return {\n ...tableState,\n keyMap: treeGridCollection.keyMap,\n userColumnCount: treeGridCollection.userColumnCount,\n expandedKeys,\n toggleKey: onToggle,\n treeColumn: tableState.treeColumn ?? collection.rowHeaderColumnKeys.keys().next().value ?? null\n };\n}\n\nfunction toggleKey<T>(\n currentExpandedKeys: 'all' | Set<Key>,\n key: Key,\n collection: TreeGridCollection<T>\n): Set<Key> {\n let updatedExpandedKeys: Set<Key>;\n if (currentExpandedKeys === 'all') {\n updatedExpandedKeys = new Set(\n collection.flattenedRows\n .filter(\n row =>\n row.props.UNSTABLE_childItems || row.props.children.length > collection.userColumnCount\n )\n .map(row => row.key)\n );\n updatedExpandedKeys.delete(key);\n } else {\n updatedExpandedKeys = new Set(currentExpandedKeys);\n if (updatedExpandedKeys.has(key)) {\n updatedExpandedKeys.delete(key);\n } else {\n updatedExpandedKeys.add(key);\n }\n }\n\n return updatedExpandedKeys;\n}\n\nfunction convertExpanded(expanded: 'all' | Iterable<Key>): 'all' | Set<Key> {\n if (!expanded) {\n return new Set<Key>();\n }\n\n return expanded === 'all' ? 'all' : new Set(expanded);\n}\n\ninterface TreeGridCollectionOptions {\n showSelectionCheckboxes?: boolean;\n showDragButtons?: boolean;\n expandedKeys: 'all' | Set<Key>;\n}\n\ninterface TreeGridCollection<T> {\n keyMap: Map<Key, GridNode<T>>;\n tableNodes: GridNode<T>[];\n flattenedRows: GridNode<T>[];\n userColumnCount: number;\n}\nfunction generateTreeGridCollection<T>(\n nodes,\n opts: TreeGridCollectionOptions\n): TreeGridCollection<T> {\n let {expandedKeys = new Set()} = opts;\n\n let body: GridNode<T> | null = null;\n let flattenedRows: GridNode<T>[] = [];\n let userColumnCount = 0;\n let originalColumns: GridNode<T>[] = [];\n let keyMap = new Map();\n\n let topLevelRows: GridNode<T>[] = [];\n let visit = (node: GridNode<T>) => {\n switch (node.type) {\n case 'body':\n body = node;\n keyMap.set(body.key, body);\n break;\n case 'column':\n if (!node.hasChildNodes) {\n userColumnCount++;\n }\n break;\n case 'item':\n topLevelRows.push(node);\n return;\n }\n\n for (let child of node.childNodes) {\n visit(child);\n }\n };\n\n for (let node of nodes) {\n if (node.type === 'column') {\n originalColumns.push(node);\n }\n visit(node);\n }\n\n // Update each grid node in the treegrid table with values specific to a treegrid structure. Also store a set of flattened row nodes for TableCollection to consume\n let visitNode = (node: GridNode<T>) => {\n if (node.type === 'item') {\n flattenedRows.push(node);\n }\n\n keyMap.set(node.key, node);\n\n for (let child of node.childNodes) {\n if (!(child.type === 'item' && expandedKeys !== 'all' && !expandedKeys.has(node.key))) {\n if (child.type === 'item') {\n visitNode(child);\n } else {\n // We enforce that the cells come before rows so can just reuse cell index\n visitNode(child);\n }\n }\n }\n };\n\n for (let node of topLevelRows) {\n visitNode(node as GridNode<T>);\n }\n\n return {\n keyMap,\n userColumnCount,\n flattenedRows,\n tableNodes: [...originalColumns, {...body!, childNodes: flattenedRows}]\n };\n}\n"],"names":[],"version":3,"file":"useTreeGridState.js.map"}
@@ -30,7 +30,8 @@ function $bf8c7a8ecaa85394$export$34dfa8a1622185a4(props) {
30
30
  showDragButtons: showDragButtons,
31
31
  selectionMode: selectionMode,
32
32
  columns: []
33
- }), [
33
+ }), // eslint-disable-next-line react-hooks/exhaustive-deps
34
+ [
34
35
  children,
35
36
  showSelectionCheckboxes,
36
37
  selectionMode,
@@ -1 +1 @@
1
- {"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAmCM,SAAS,0CAA4C,KAA4B;IACtF,IAAI,iBACF,gBAAgB,iCAChB,uBAAuB,mBACvB,eAAe,EACf,uBAAuB,gBAAgB,EACvC,8BAA8B,uBAAuB,6BACrD,yBAAyB,YACzB,QAAQ,EACT,GAAG;IAEJ,IAAI,CAAC,CAAA,GAAA,yCAAc,KACjB,MAAM,IAAI,MAAM;IAGlB,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,yCAAiB,EACrD,mBAAmB,sCAAgB,oBAAoB,WACvD,0BAA0B,sCAAgB,2BAA2B,IAAI,OACzE;IAGF,IAAI,UAAU,CAAA,GAAA,cAAM,EAAE,IAAO,CAAA;YAC3B,yBAAyB,2BAA2B,kBAAkB;YACtE,iBAAiB;2BACjB;YACA,SAAS,E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EA,KAAK,IAAI,QAAQ,aACf,UAAU;IAGZ,OAAO;gBACL;yBACA;uBACA;QACA,YAAY;eAAI;YAAiB;gBAAC,GAAG,IAAI;gBAAG,YAAY;YAAa;SAAE;IACzE;AACF","sources":["packages/react-stately/src/table/useTreeGridState.ts"],"sourcesContent":["/*\n * Copyright 2023 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 {CollectionBuilder} from '../collections/CollectionBuilder';\nimport {GridNode} from '../grid/GridCollection';\nimport {Key} from '@react-types/shared';\nimport {ReactElement, useMemo} from 'react';\nimport {TableCollection} from './TableCollection';\nimport {tableNestedRows} from '../flags/flags';\nimport {TableState, TableStateProps, useTableState} from './useTableState';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface TreeGridState<T> extends Omit<TableState<T>, 'expandedKeys'> {\n /** A set of keys for items that are expanded. */\n expandedKeys: 'all' | Set<Key>,\n /** Toggles the expanded state for a row by its key. */\n toggleKey(key: Key): void,\n /** The key map containing nodes representing the collection's tree grid structure. */\n keyMap: Map<Key, GridNode<T>>,\n /** The number of leaf columns provided by the user. */\n userColumnCount: number\n}\n\nexport interface TreeGridStateProps<T> extends Omit<TableStateProps<T>, 'collection'> {\n /** The currently expanded keys in the collection (controlled). */\n UNSTABLE_expandedKeys?: 'all' | Iterable<Key>,\n /** The initial expanded keys in the collection (uncontrolled). */\n UNSTABLE_defaultExpandedKeys?: 'all' | Iterable<Key>,\n /** Handler that is called when items are expanded or collapsed. */\n UNSTABLE_onExpandedChange?: (keys: Set<Key>) => any\n}\n\n/**\n * Provides state management for a tree grid component. Handles building a collection\n * of columns and rows from props. In addition, it tracks and manages expanded rows, row selection, and sort order changes.\n */\nexport function UNSTABLE_useTreeGridState<T extends object>(props: TreeGridStateProps<T>): TreeGridState<T> {\n let {\n selectionMode = 'none',\n showSelectionCheckboxes,\n showDragButtons,\n UNSTABLE_expandedKeys: propExpandedKeys,\n UNSTABLE_defaultExpandedKeys: propDefaultExpandedKeys,\n UNSTABLE_onExpandedChange,\n children\n } = props;\n\n if (!tableNestedRows()) {\n throw new Error('Feature flag for table nested rows must be enabled to use useTreeGridState.');\n }\n\n let [expandedKeys, setExpandedKeys] = useControlledState(\n propExpandedKeys ? convertExpanded(propExpandedKeys) : undefined,\n propDefaultExpandedKeys ? convertExpanded(propDefaultExpandedKeys) : new Set(),\n UNSTABLE_onExpandedChange\n );\n\n let context = useMemo(() => ({\n showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== 'none',\n showDragButtons: showDragButtons,\n selectionMode,\n columns: []\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }), [children, showSelectionCheckboxes, selectionMode, showDragButtons]);\n\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let nodes = useMemo(() => builder.build({children: children as ReactElement<any>[]}, context), [builder, children, context]);\n let treeGridCollection = useMemo(() => {\n return generateTreeGridCollection<T>(nodes, {showSelectionCheckboxes, showDragButtons, expandedKeys});\n }, [nodes, showSelectionCheckboxes, showDragButtons, expandedKeys]);\n\n let onToggle = (key: Key) => {\n setExpandedKeys(toggleKey(expandedKeys, key, treeGridCollection));\n };\n\n let collection = useMemo(() => {\n return new TableCollection(treeGridCollection.tableNodes, null, context);\n }, [context, treeGridCollection.tableNodes]);\n\n let tableState = useTableState({...props, collection});\n return {\n ...tableState,\n keyMap: treeGridCollection.keyMap,\n userColumnCount: treeGridCollection.userColumnCount,\n expandedKeys,\n toggleKey: onToggle,\n treeColumn: tableState.treeColumn ?? collection.rowHeaderColumnKeys.keys().next().value ?? null\n };\n}\n\nfunction toggleKey<T>(currentExpandedKeys: 'all' | Set<Key>, key: Key, collection: TreeGridCollection<T>): Set<Key> {\n let updatedExpandedKeys: Set<Key>;\n if (currentExpandedKeys === 'all') {\n updatedExpandedKeys = new Set(collection.flattenedRows.filter(row => row.props.UNSTABLE_childItems || row.props.children.length > collection.userColumnCount).map(row => row.key));\n updatedExpandedKeys.delete(key);\n } else {\n updatedExpandedKeys = new Set(currentExpandedKeys);\n if (updatedExpandedKeys.has(key)) {\n updatedExpandedKeys.delete(key);\n } else {\n updatedExpandedKeys.add(key);\n }\n }\n\n return updatedExpandedKeys;\n}\n\nfunction convertExpanded(expanded: 'all' | Iterable<Key>): 'all' | Set<Key> {\n if (!expanded) {\n return new Set<Key>();\n }\n\n return expanded === 'all'\n ? 'all'\n : new Set(expanded);\n}\n\ninterface TreeGridCollectionOptions {\n showSelectionCheckboxes?: boolean,\n showDragButtons?: boolean,\n expandedKeys: 'all' | Set<Key>\n}\n\ninterface TreeGridCollection<T> {\n keyMap: Map<Key, GridNode<T>>,\n tableNodes: GridNode<T>[],\n flattenedRows: GridNode<T>[],\n userColumnCount: number\n}\nfunction generateTreeGridCollection<T>(nodes, opts: TreeGridCollectionOptions): TreeGridCollection<T> {\n let {\n expandedKeys = new Set()\n } = opts;\n\n let body: GridNode<T> | null = null;\n let flattenedRows: GridNode<T>[] = [];\n let userColumnCount = 0;\n let originalColumns: GridNode<T>[] = [];\n let keyMap = new Map();\n\n let topLevelRows: GridNode<T>[] = [];\n let visit = (node: GridNode<T>) => {\n switch (node.type) {\n case 'body':\n body = node;\n keyMap.set(body.key, body);\n break;\n case 'column':\n if (!node.hasChildNodes) {\n userColumnCount++;\n }\n break;\n case 'item':\n topLevelRows.push(node);\n return;\n }\n\n for (let child of node.childNodes) {\n visit(child);\n }\n };\n\n for (let node of nodes) {\n if (node.type === 'column') {\n originalColumns.push(node);\n }\n visit(node);\n }\n\n // Update each grid node in the treegrid table with values specific to a treegrid structure. Also store a set of flattened row nodes for TableCollection to consume\n let visitNode = (node: GridNode<T>) => {\n if (node.type === 'item') {\n flattenedRows.push(node);\n }\n\n keyMap.set(node.key, node);\n\n for (let child of node.childNodes) {\n if (!(child.type === 'item' && expandedKeys !== 'all' && !expandedKeys.has(node.key))) {\n if (child.type === 'item') {\n visitNode(child);\n } else {\n // We enforce that the cells come before rows so can just reuse cell index\n visitNode(child);\n }\n }\n }\n };\n\n for (let node of topLevelRows) {\n visitNode(node as GridNode<T>);\n }\n\n return {\n keyMap,\n userColumnCount,\n flattenedRows,\n tableNodes: [...originalColumns, {...body!, childNodes: flattenedRows}]\n };\n}\n"],"names":[],"version":3,"file":"useTreeGridState.mjs.map"}
1
+ {"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAoCM,SAAS,0CACd,KAA4B;IAE5B,IAAI,iBACF,gBAAgB,iCAChB,uBAAuB,mBACvB,eAAe,EACf,uBAAuB,gBAAgB,EACvC,8BAA8B,uBAAuB,6BACrD,yBAAyB,YACzB,QAAQ,EACT,GAAG;IAEJ,IAAI,CAAC,CAAA,GAAA,yCAAc,KACjB,MAAM,IAAI,MAAM;IAGlB,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,yCAAiB,EACrD,mBAAmB,sCAAgB,oBAAoB,WACvD,0BAA0B,sCAAgB,2BAA2B,IAAI,OACzE;IAGF,IAAI,UAAU,CAAA,GAAA,cAAM,EAClB,IAAO,CAAA;YACL,yBAAyB,2BAA2B,kBAAkB;YACtE,iBAAiB;2BACjB;YACA,SAAS,EAAE;QACb,CAAA,GACA,uDAAuD;IACvD;QAAC;QAAU;QAAyB;QAAe;KAAgB;IAGrE,IAAI,UAAU,CAAA,GAAA,cAAM,EAAE,IAAM,IAAI,CAAA,GAAA,yCAAgB,KAAQ,EAAE;IAC1D,IAAI,QAAQ,CAAA,GAAA,cAAM,EAChB,IAAM,QAAQ,KAAK,CAAC;YAAC,UAAU;QAA+B,GAAG,UACjE;QAAC;QAAS;QAAU;KAAQ;IAE9B,IAAI,qBAAqB,CAAA,GAAA,cAAM,E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AC,eAAe,IAAI,OAAM,GAAG;IAEjC,IAAI,OAA2B;IAC/B,IAAI,gBAA+B,EAAE;IACrC,IAAI,kBAAkB;IACtB,IAAI,kBAAiC,EAAE;IACvC,IAAI,SAAS,IAAI;IAEjB,IAAI,eAA8B,EAAE;IACpC,IAAI,QAAQ,CAAC;QACX,OAAQ,KAAK,IAAI;YACf,KAAK;gBACH,OAAO;gBACP,OAAO,GAAG,CAAC,KAAK,GAAG,EAAE;gBACrB;YACF,KAAK;gBACH,IAAI,CAAC,KAAK,aAAa,EACrB;gBAEF;YACF,KAAK;gBACH,aAAa,IAAI,CAAC;gBAClB;QACJ;QAEA,KAAK,IAAI,SAAS,KAAK,UAAU,CAC/B,MAAM;IAEV;IAEA,KAAK,IAAI,QAAQ,MAAO;QACtB,IAAI,KAAK,IAAI,KAAK,UAChB,gBAAgB,IAAI,CAAC;QAEvB,MAAM;IACR;IAEA,mKAAmK;IACnK,IAAI,YAAY,CAAC;QACf,IAAI,KAAK,IAAI,KAAK,QAChB,cAAc,IAAI,CAAC;QAGrB,OAAO,GAAG,CAAC,KAAK,GAAG,EAAE;QAErB,KAAK,IAAI,SAAS,KAAK,UAAU,CAC/B,IAAI,CAAE,CAAA,MAAM,IAAI,KAAK,UAAU,iBAAiB,SAAS,CAAC,aAAa,GAAG,CAAC,KAAK,GAAG,CAAA;YACjF,IAAI,MAAM,IAAI,KAAK,QACjB,UAAU;iBAEV,0EAA0E;YAC1E,UAAU;;IAIlB;IAEA,KAAK,IAAI,QAAQ,aACf,UAAU;IAGZ,OAAO;gBACL;yBACA;uBACA;QACA,YAAY;eAAI;YAAiB;gBAAC,GAAG,IAAI;gBAAG,YAAY;YAAa;SAAE;IACzE;AACF","sources":["packages/react-stately/src/table/useTreeGridState.ts"],"sourcesContent":["/*\n * Copyright 2023 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 {CollectionBuilder} from '../collections/CollectionBuilder';\nimport {GridNode} from '../grid/GridCollection';\nimport {Key} from '@react-types/shared';\nimport {ReactElement, useMemo} from 'react';\nimport {TableCollection} from './TableCollection';\nimport {tableNestedRows} from '../flags/flags';\nimport {TableState, TableStateProps, useTableState} from './useTableState';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface TreeGridState<T> extends Omit<TableState<T>, 'expandedKeys'> {\n /** A set of keys for items that are expanded. */\n expandedKeys: 'all' | Set<Key>;\n /** Toggles the expanded state for a row by its key. */\n toggleKey(key: Key): void;\n /** The key map containing nodes representing the collection's tree grid structure. */\n keyMap: Map<Key, GridNode<T>>;\n /** The number of leaf columns provided by the user. */\n userColumnCount: number;\n}\n\nexport interface TreeGridStateProps<T> extends Omit<TableStateProps<T>, 'collection'> {\n /** The currently expanded keys in the collection (controlled). */\n UNSTABLE_expandedKeys?: 'all' | Iterable<Key>;\n /** The initial expanded keys in the collection (uncontrolled). */\n UNSTABLE_defaultExpandedKeys?: 'all' | Iterable<Key>;\n /** Handler that is called when items are expanded or collapsed. */\n UNSTABLE_onExpandedChange?: (keys: Set<Key>) => any;\n}\n\n/**\n * Provides state management for a tree grid component. Handles building a collection of columns and\n * rows from props. In addition, it tracks and manages expanded rows, row selection, and sort order\n * changes.\n */\nexport function UNSTABLE_useTreeGridState<T extends object>(\n props: TreeGridStateProps<T>\n): TreeGridState<T> {\n let {\n selectionMode = 'none',\n showSelectionCheckboxes,\n showDragButtons,\n UNSTABLE_expandedKeys: propExpandedKeys,\n UNSTABLE_defaultExpandedKeys: propDefaultExpandedKeys,\n UNSTABLE_onExpandedChange,\n children\n } = props;\n\n if (!tableNestedRows()) {\n throw new Error('Feature flag for table nested rows must be enabled to use useTreeGridState.');\n }\n\n let [expandedKeys, setExpandedKeys] = useControlledState(\n propExpandedKeys ? convertExpanded(propExpandedKeys) : undefined,\n propDefaultExpandedKeys ? convertExpanded(propDefaultExpandedKeys) : new Set(),\n UNSTABLE_onExpandedChange\n );\n\n let context = useMemo(\n () => ({\n showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== 'none',\n showDragButtons: showDragButtons,\n selectionMode,\n columns: []\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [children, showSelectionCheckboxes, selectionMode, showDragButtons]\n );\n\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let nodes = useMemo(\n () => builder.build({children: children as ReactElement<any>[]}, context),\n [builder, children, context]\n );\n let treeGridCollection = useMemo(() => {\n return generateTreeGridCollection<T>(nodes, {\n showSelectionCheckboxes,\n showDragButtons,\n expandedKeys\n });\n }, [nodes, showSelectionCheckboxes, showDragButtons, expandedKeys]);\n\n let onToggle = (key: Key) => {\n setExpandedKeys(toggleKey(expandedKeys, key, treeGridCollection));\n };\n\n let collection = useMemo(() => {\n return new TableCollection(treeGridCollection.tableNodes, null, context);\n }, [context, treeGridCollection.tableNodes]);\n\n let tableState = useTableState({...props, collection});\n return {\n ...tableState,\n keyMap: treeGridCollection.keyMap,\n userColumnCount: treeGridCollection.userColumnCount,\n expandedKeys,\n toggleKey: onToggle,\n treeColumn: tableState.treeColumn ?? collection.rowHeaderColumnKeys.keys().next().value ?? null\n };\n}\n\nfunction toggleKey<T>(\n currentExpandedKeys: 'all' | Set<Key>,\n key: Key,\n collection: TreeGridCollection<T>\n): Set<Key> {\n let updatedExpandedKeys: Set<Key>;\n if (currentExpandedKeys === 'all') {\n updatedExpandedKeys = new Set(\n collection.flattenedRows\n .filter(\n row =>\n row.props.UNSTABLE_childItems || row.props.children.length > collection.userColumnCount\n )\n .map(row => row.key)\n );\n updatedExpandedKeys.delete(key);\n } else {\n updatedExpandedKeys = new Set(currentExpandedKeys);\n if (updatedExpandedKeys.has(key)) {\n updatedExpandedKeys.delete(key);\n } else {\n updatedExpandedKeys.add(key);\n }\n }\n\n return updatedExpandedKeys;\n}\n\nfunction convertExpanded(expanded: 'all' | Iterable<Key>): 'all' | Set<Key> {\n if (!expanded) {\n return new Set<Key>();\n }\n\n return expanded === 'all' ? 'all' : new Set(expanded);\n}\n\ninterface TreeGridCollectionOptions {\n showSelectionCheckboxes?: boolean;\n showDragButtons?: boolean;\n expandedKeys: 'all' | Set<Key>;\n}\n\ninterface TreeGridCollection<T> {\n keyMap: Map<Key, GridNode<T>>;\n tableNodes: GridNode<T>[];\n flattenedRows: GridNode<T>[];\n userColumnCount: number;\n}\nfunction generateTreeGridCollection<T>(\n nodes,\n opts: TreeGridCollectionOptions\n): TreeGridCollection<T> {\n let {expandedKeys = new Set()} = opts;\n\n let body: GridNode<T> | null = null;\n let flattenedRows: GridNode<T>[] = [];\n let userColumnCount = 0;\n let originalColumns: GridNode<T>[] = [];\n let keyMap = new Map();\n\n let topLevelRows: GridNode<T>[] = [];\n let visit = (node: GridNode<T>) => {\n switch (node.type) {\n case 'body':\n body = node;\n keyMap.set(body.key, body);\n break;\n case 'column':\n if (!node.hasChildNodes) {\n userColumnCount++;\n }\n break;\n case 'item':\n topLevelRows.push(node);\n return;\n }\n\n for (let child of node.childNodes) {\n visit(child);\n }\n };\n\n for (let node of nodes) {\n if (node.type === 'column') {\n originalColumns.push(node);\n }\n visit(node);\n }\n\n // Update each grid node in the treegrid table with values specific to a treegrid structure. Also store a set of flattened row nodes for TableCollection to consume\n let visitNode = (node: GridNode<T>) => {\n if (node.type === 'item') {\n flattenedRows.push(node);\n }\n\n keyMap.set(node.key, node);\n\n for (let child of node.childNodes) {\n if (!(child.type === 'item' && expandedKeys !== 'all' && !expandedKeys.has(node.key))) {\n if (child.type === 'item') {\n visitNode(child);\n } else {\n // We enforce that the cells come before rows so can just reuse cell index\n visitNode(child);\n }\n }\n }\n };\n\n for (let node of topLevelRows) {\n visitNode(node as GridNode<T>);\n }\n\n return {\n keyMap,\n userColumnCount,\n flattenedRows,\n tableNodes: [...originalColumns, {...body!, childNodes: flattenedRows}]\n };\n}\n"],"names":[],"version":3,"file":"useTreeGridState.mjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AA+BM,SAAS,wCAAkC,KAA6B;IAC7E,IAAI,QAAQ,CAAA,GAAA,kDAAuB,EAAK;QACtC,GAAG,KAAK;QACR,mBAAmB,MAAM,iBAAiB,GAAI,CAAA;YAC5C,IAAI,OAAO,MACT,MAAM,iBAAiB,GAAG;QAE9B,IAAK;QACL,0BAA0B;QAC1B,oBAAoB,MAAM,kBAAkB,IAAI,6CAAuB,MAAM,UAAU,EAAE,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,UAAU;IAC5J;IAEA,IAAI,oBACF,gBAAgB,cAChB,UAAU,EACV,aAAa,kBAAkB,EAChC,GAAG;IAEJ,IAAI,kBAAkB,CAAA,GAAA,mBAAK,EAAE;IAC7B,CAAA,GAAA,sBAAQ,EAAE;QACR,0HAA0H;QAC1H,IAAI,cAAc;QAClB,IAAI,MAAM,WAAW,IAAI,QAAS,CAAA,iBAAiB,OAAO,IAAI,eAAe,QAAQ,CAAC,WAAW,OAAO,CAAC,YAAW,GAAI;YACtH,cAAc,6CAAuB,YAAY,MAAM,YAAY;YACnE,IAAI,eAAe,MACjB,uFAAuF;YACvF,iBAAiB,eAAe,CAAC;gBAAC;aAAY;QAElD;QAEA,2JAA2J;QAC3J,IAAI,eAAe,QAAQ,iBAAiB,UAAU,IAAI,QAAS,CAAC,iBAAiB,SAAS,IAAI,gBAAgB,gBAAgB,OAAO,EACvI,iBAAiB,aAAa,CAAC;QAEjC,gBAAgB,OAAO,GAAG;IAC5B;IAEA,OAAO;QACL,GAAG,KAAK;QACR,YAAY,MAAM,UAAU,IAAI;IAClC;AACF;AAEA,SAAS,6CAA0B,UAA2C,EAAE,YAAsB;IACpG,IAAI,cAA0B;IAC9B,IAAI,YAAY;QACd,cAAc,WAAW,WAAW;QACpC,uEAAuE;QACvE,MAAO,eAAe,QAAS,CAAA,aAAa,GAAG,CAAC,gBAAgB,WAAW,OAAO,CAAC,cAAc,OAAO,UAAS,KAAM,gBAAgB,WAAW,UAAU,GAC1J,cAAc,WAAW,WAAW,CAAC;QAEvC,oHAAoH;QACpH,IAAI,eAAe,QAAS,CAAA,aAAa,GAAG,CAAC,gBAAgB,WAAW,OAAO,CAAC,cAAc,OAAO,UAAS,KAAM,gBAAgB,WAAW,UAAU,IACvJ,cAAc,WAAW,WAAW;IAExC;IAEA,OAAO;AACT","sources":["packages/react-stately/src/tabs/useTabListState.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 {Collection, CollectionBase, CollectionStateBase, Key, Node, SingleSelection} from '@react-types/shared';\nimport {SingleSelectListState, useSingleSelectListState} from '../list/useSingleSelectListState';\nimport {useEffect, useRef} from 'react';\n\nexport interface TabListProps<T> extends CollectionBase<T>, Omit<SingleSelection, 'disallowEmptySelection' | 'selectedKey' | 'defaultSelectedKey' | 'onSelectionChange'> {\n /**\n * Whether the TabList is disabled.\n * Shows that a selection exists, but is not available in that circumstance.\n */\n isDisabled?: boolean,\n /** The currently selected key in the collection (controlled). */\n selectedKey?: Key,\n /** The initial selected keys in the collection (uncontrolled). */\n defaultSelectedKey?: Key,\n /** Handler that is called when the selection changes. */\n onSelectionChange?: (key: Key) => void\n}\n\nexport interface TabListStateOptions<T> extends Omit<TabListProps<T>, 'children'>, CollectionStateBase<T> {}\n\nexport interface TabListState<T> extends SingleSelectListState<T> {\n /** Whether the tab list is disabled. */\n isDisabled: boolean\n}\n\n/**\n * Provides state management for a Tabs component. Tabs include a TabList which tracks\n * which tab is currently selected and displays the content associated with that Tab in a TabPanel.\n */\nexport function useTabListState<T extends object>(props: TabListStateOptions<T>): TabListState<T> {\n let state = useSingleSelectListState<T>({\n ...props,\n onSelectionChange: props.onSelectionChange ? (key => {\n if (key != null) {\n props.onSelectionChange?.(key);\n }\n }) : undefined,\n suppressTextValueWarning: true,\n defaultSelectedKey: props.defaultSelectedKey ?? findDefaultSelectedKey(props.collection, props.disabledKeys ? new Set(props.disabledKeys) : new Set()) ?? undefined\n });\n\n let {\n selectionManager,\n collection,\n selectedKey: currentSelectedKey\n } = state;\n\n let lastSelectedKey = useRef(currentSelectedKey);\n useEffect(() => {\n // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)\n let selectedKey = currentSelectedKey;\n if (props.selectedKey == null && (selectionManager.isEmpty || selectedKey == null || !collection.getItem(selectedKey))) {\n selectedKey = findDefaultSelectedKey(collection, state.disabledKeys);\n if (selectedKey != null) {\n // directly set selection because replace/toggle selection won't consider disabled keys\n selectionManager.setSelectedKeys([selectedKey]);\n }\n }\n\n // If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.\n if (selectedKey != null && selectionManager.focusedKey == null || (!selectionManager.isFocused && selectedKey !== lastSelectedKey.current)) {\n selectionManager.setFocusedKey(selectedKey);\n }\n lastSelectedKey.current = selectedKey;\n });\n\n return {\n ...state,\n isDisabled: props.isDisabled || false\n };\n}\n\nfunction findDefaultSelectedKey<T>(collection: Collection<Node<T>> | undefined, disabledKeys: Set<Key>) {\n let selectedKey: Key | null = null;\n if (collection) {\n selectedKey = collection.getFirstKey();\n // loop over tabs until we find one that isn't disabled and select that\n while (selectedKey != null && (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) && selectedKey !== collection.getLastKey()) {\n selectedKey = collection.getKeyAfter(selectedKey);\n }\n // if this check is true, then every item is disabled, it makes more sense to default to the first key than the last\n if (selectedKey != null && (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) && selectedKey === collection.getLastKey()) {\n selectedKey = collection.getFirstKey();\n }\n }\n\n return selectedKey;\n}\n"],"names":[],"version":3,"file":"useTabListState.cjs.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AA6CM,SAAS,wCAAkC,KAA6B;IAC7E,IAAI,QAAQ,CAAA,GAAA,kDAAuB,EAAK;QACtC,GAAG,KAAK;QACR,mBAAmB,MAAM,iBAAiB,GACtC,CAAA;YACE,IAAI,OAAO,MACT,MAAM,iBAAiB,GAAG;QAE9B,IACA;QACJ,0BAA0B;QAC1B,oBACE,MAAM,kBAAkB,IACxB,6CACE,MAAM,UAAU,EAChB,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,UAEzD;IACJ;IAEA,IAAI,oBAAC,gBAAgB,cAAE,UAAU,EAAE,aAAa,kBAAkB,EAAC,GAAG;IAEtE,IAAI,kBAAkB,CAAA,GAAA,mBAAK,EAAE;IAC7B,CAAA,GAAA,sBAAQ,EAAE;QACR,0HAA0H;QAC1H,IAAI,cAAc;QAClB,IACE,MAAM,WAAW,IAAI,QACpB,CAAA,iBAAiB,OAAO,IAAI,eAAe,QAAQ,CAAC,WAAW,OAAO,CAAC,YAAW,GACnF;YACA,cAAc,6CAAuB,YAAY,MAAM,YAAY;YACnE,IAAI,eAAe,MACjB,uFAAuF;YACvF,iBAAiB,eAAe,CAAC;gBAAC;aAAY;QAElD;QAEA,2JAA2J;QAC3J,IACE,AAAC,eAAe,QAAQ,iBAAiB,UAAU,IAAI,QACtD,CAAC,iBAAiB,SAAS,IAAI,gBAAgB,gBAAgB,OAAO,EAEvE,iBAAiB,aAAa,CAAC;QAEjC,gBAAgB,OAAO,GAAG;IAC5B;IAEA,OAAO;QACL,GAAG,KAAK;QACR,YAAY,MAAM,UAAU,IAAI;IAClC;AACF;AAEA,SAAS,6CACP,UAA2C,EAC3C,YAAsB;IAEtB,IAAI,cAA0B;IAC9B,IAAI,YAAY;QACd,cAAc,WAAW,WAAW;QACpC,uEAAuE;QACvE,MACE,eAAe,QACd,CAAA,aAAa,GAAG,CAAC,gBAAgB,WAAW,OAAO,CAAC,cAAc,OAAO,UAAS,KACnF,gBAAgB,WAAW,UAAU,GAErC,cAAc,WAAW,WAAW,CAAC;QAEvC,oHAAoH;QACpH,IACE,eAAe,QACd,CAAA,aAAa,GAAG,CAAC,gBAAgB,WAAW,OAAO,CAAC,cAAc,OAAO,UAAS,KACnF,gBAAgB,WAAW,UAAU,IAErC,cAAc,WAAW,WAAW;IAExC;IAEA,OAAO;AACT","sources":["packages/react-stately/src/tabs/useTabListState.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 Collection,\n CollectionBase,\n CollectionStateBase,\n Key,\n Node,\n SingleSelection\n} from '@react-types/shared';\nimport {SingleSelectListState, useSingleSelectListState} from '../list/useSingleSelectListState';\nimport {useEffect, useRef} from 'react';\n\nexport interface TabListProps<T>\n extends\n CollectionBase<T>,\n Omit<\n SingleSelection,\n 'disallowEmptySelection' | 'selectedKey' | 'defaultSelectedKey' | 'onSelectionChange'\n > {\n /**\n * Whether the TabList is disabled.\n * Shows that a selection exists, but is not available in that circumstance.\n */\n isDisabled?: boolean;\n /** The currently selected key in the collection (controlled). */\n selectedKey?: Key;\n /** The initial selected keys in the collection (uncontrolled). */\n defaultSelectedKey?: Key;\n /** Handler that is called when the selection changes. */\n onSelectionChange?: (key: Key) => void;\n}\n\nexport interface TabListStateOptions<T>\n extends Omit<TabListProps<T>, 'children'>, CollectionStateBase<T> {}\n\nexport interface TabListState<T> extends SingleSelectListState<T> {\n /** Whether the tab list is disabled. */\n isDisabled: boolean;\n}\n\n/**\n * Provides state management for a Tabs component. Tabs include a TabList which tracks\n * which tab is currently selected and displays the content associated with that Tab in a TabPanel.\n */\nexport function useTabListState<T extends object>(props: TabListStateOptions<T>): TabListState<T> {\n let state = useSingleSelectListState<T>({\n ...props,\n onSelectionChange: props.onSelectionChange\n ? key => {\n if (key != null) {\n props.onSelectionChange?.(key);\n }\n }\n : undefined,\n suppressTextValueWarning: true,\n defaultSelectedKey:\n props.defaultSelectedKey ??\n findDefaultSelectedKey(\n props.collection,\n props.disabledKeys ? new Set(props.disabledKeys) : new Set()\n ) ??\n undefined\n });\n\n let {selectionManager, collection, selectedKey: currentSelectedKey} = state;\n\n let lastSelectedKey = useRef(currentSelectedKey);\n useEffect(() => {\n // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)\n let selectedKey = currentSelectedKey;\n if (\n props.selectedKey == null &&\n (selectionManager.isEmpty || selectedKey == null || !collection.getItem(selectedKey))\n ) {\n selectedKey = findDefaultSelectedKey(collection, state.disabledKeys);\n if (selectedKey != null) {\n // directly set selection because replace/toggle selection won't consider disabled keys\n selectionManager.setSelectedKeys([selectedKey]);\n }\n }\n\n // If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.\n if (\n (selectedKey != null && selectionManager.focusedKey == null) ||\n (!selectionManager.isFocused && selectedKey !== lastSelectedKey.current)\n ) {\n selectionManager.setFocusedKey(selectedKey);\n }\n lastSelectedKey.current = selectedKey;\n });\n\n return {\n ...state,\n isDisabled: props.isDisabled || false\n };\n}\n\nfunction findDefaultSelectedKey<T>(\n collection: Collection<Node<T>> | undefined,\n disabledKeys: Set<Key>\n) {\n let selectedKey: Key | null = null;\n if (collection) {\n selectedKey = collection.getFirstKey();\n // loop over tabs until we find one that isn't disabled and select that\n while (\n selectedKey != null &&\n (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) &&\n selectedKey !== collection.getLastKey()\n ) {\n selectedKey = collection.getKeyAfter(selectedKey);\n }\n // if this check is true, then every item is disabled, it makes more sense to default to the first key than the last\n if (\n selectedKey != null &&\n (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) &&\n selectedKey === collection.getLastKey()\n ) {\n selectedKey = collection.getFirstKey();\n }\n }\n\n return selectedKey;\n}\n"],"names":[],"version":3,"file":"useTabListState.cjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA+BM,SAAS,wCAAkC,KAA6B;QASvD,2BAAA;IARtB,IAAI,QAAQ,CAAA,GAAA,yCAAuB,EAAK;QACtC,GAAG,KAAK;QACR,mBAAmB,MAAM,iBAAiB,GAAI,CAAA;gBAE1C;YADF,IAAI,OAAO,OACT,2BAAA,MAAM,iBAAiB,cAAvB,+CAAA,8BAAA,OAA0B;QAE9B,IAAK;QACL,0BAA0B;QAC1B,oBAAoB,CAAA,OAAA,CAAA,4BAAA,MAAM,kBAAkB,cAAxB,uCAAA,4BAA4B,6CAAuB,MAAM,UAAU,EAAE,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,oBAA5H,kBAAA,OAAsI;IAC5J;IAEA,IAAI,oBACF,gBAAgB,cAChB,UAAU,EACV,aAAa,kBAAkB,EAChC,GAAG;IAEJ,IAAI,kBAAkB,CAAA,GAAA,aAAK,EAAE;IAC7B,CAAA,GAAA,gBAAQ,EAAE;QACR,0HAA0H;QAC1H,IAAI,cAAc;QAClB,IAAI,MAAM,WAAW,IAAI,QAAS,CAAA,iBAAiB,OAAO,IAAI,eAAe,QAAQ,CAAC,WAAW,OAAO,CAAC,YAAW,GAAI;YACtH,cAAc,6CAAuB,YAAY,MAAM,YAAY;YACnE,IAAI,eAAe,MACjB,uFAAuF;YACvF,iBAAiB,eAAe,CAAC;gBAAC;aAAY;QAElD;QAEA,2JAA2J;QAC3J,IAAI,eAAe,QAAQ,iBAAiB,UAAU,IAAI,QAAS,CAAC,iBAAiB,SAAS,IAAI,gBAAgB,gBAAgB,OAAO,EACvI,iBAAiB,aAAa,CAAC;QAEjC,gBAAgB,OAAO,GAAG;IAC5B;IAEA,OAAO;QACL,GAAG,KAAK;QACR,YAAY,MAAM,UAAU,IAAI;IAClC;AACF;AAEA,SAAS,6CAA0B,UAA2C,EAAE,YAAsB;IACpG,IAAI,cAA0B;IAC9B,IAAI,YAAY;YAGkD,2BAAA,qBAIH,4BAAA;QAN7D,cAAc,WAAW,WAAW;QACpC,uEAAuE;QACvE,MAAO,eAAe,QAAS,CAAA,aAAa,GAAG,CAAC,kBAAgB,sBAAA,WAAW,OAAO,CAAC,0BAAnB,2CAAA,4BAAA,oBAAiC,KAAK,cAAtC,gDAAA,0BAAwC,UAAU,CAAD,KAAM,gBAAgB,WAAW,UAAU,GAC1J,cAAc,WAAW,WAAW,CAAC;QAEvC,oHAAoH;QACpH,IAAI,eAAe,QAAS,CAAA,aAAa,GAAG,CAAC,kBAAgB,uBAAA,WAAW,OAAO,CAAC,0BAAnB,4CAAA,6BAAA,qBAAiC,KAAK,cAAtC,iDAAA,2BAAwC,UAAU,CAAD,KAAM,gBAAgB,WAAW,UAAU,IACvJ,cAAc,WAAW,WAAW;IAExC;IAEA,OAAO;AACT","sources":["packages/react-stately/src/tabs/useTabListState.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 {Collection, CollectionBase, CollectionStateBase, Key, Node, SingleSelection} from '@react-types/shared';\nimport {SingleSelectListState, useSingleSelectListState} from '../list/useSingleSelectListState';\nimport {useEffect, useRef} from 'react';\n\nexport interface TabListProps<T> extends CollectionBase<T>, Omit<SingleSelection, 'disallowEmptySelection' | 'selectedKey' | 'defaultSelectedKey' | 'onSelectionChange'> {\n /**\n * Whether the TabList is disabled.\n * Shows that a selection exists, but is not available in that circumstance.\n */\n isDisabled?: boolean,\n /** The currently selected key in the collection (controlled). */\n selectedKey?: Key,\n /** The initial selected keys in the collection (uncontrolled). */\n defaultSelectedKey?: Key,\n /** Handler that is called when the selection changes. */\n onSelectionChange?: (key: Key) => void\n}\n\nexport interface TabListStateOptions<T> extends Omit<TabListProps<T>, 'children'>, CollectionStateBase<T> {}\n\nexport interface TabListState<T> extends SingleSelectListState<T> {\n /** Whether the tab list is disabled. */\n isDisabled: boolean\n}\n\n/**\n * Provides state management for a Tabs component. Tabs include a TabList which tracks\n * which tab is currently selected and displays the content associated with that Tab in a TabPanel.\n */\nexport function useTabListState<T extends object>(props: TabListStateOptions<T>): TabListState<T> {\n let state = useSingleSelectListState<T>({\n ...props,\n onSelectionChange: props.onSelectionChange ? (key => {\n if (key != null) {\n props.onSelectionChange?.(key);\n }\n }) : undefined,\n suppressTextValueWarning: true,\n defaultSelectedKey: props.defaultSelectedKey ?? findDefaultSelectedKey(props.collection, props.disabledKeys ? new Set(props.disabledKeys) : new Set()) ?? undefined\n });\n\n let {\n selectionManager,\n collection,\n selectedKey: currentSelectedKey\n } = state;\n\n let lastSelectedKey = useRef(currentSelectedKey);\n useEffect(() => {\n // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)\n let selectedKey = currentSelectedKey;\n if (props.selectedKey == null && (selectionManager.isEmpty || selectedKey == null || !collection.getItem(selectedKey))) {\n selectedKey = findDefaultSelectedKey(collection, state.disabledKeys);\n if (selectedKey != null) {\n // directly set selection because replace/toggle selection won't consider disabled keys\n selectionManager.setSelectedKeys([selectedKey]);\n }\n }\n\n // If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.\n if (selectedKey != null && selectionManager.focusedKey == null || (!selectionManager.isFocused && selectedKey !== lastSelectedKey.current)) {\n selectionManager.setFocusedKey(selectedKey);\n }\n lastSelectedKey.current = selectedKey;\n });\n\n return {\n ...state,\n isDisabled: props.isDisabled || false\n };\n}\n\nfunction findDefaultSelectedKey<T>(collection: Collection<Node<T>> | undefined, disabledKeys: Set<Key>) {\n let selectedKey: Key | null = null;\n if (collection) {\n selectedKey = collection.getFirstKey();\n // loop over tabs until we find one that isn't disabled and select that\n while (selectedKey != null && (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) && selectedKey !== collection.getLastKey()) {\n selectedKey = collection.getKeyAfter(selectedKey);\n }\n // if this check is true, then every item is disabled, it makes more sense to default to the first key than the last\n if (selectedKey != null && (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) && selectedKey === collection.getLastKey()) {\n selectedKey = collection.getFirstKey();\n }\n }\n\n return selectedKey;\n}\n"],"names":[],"version":3,"file":"useTabListState.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA6CM,SAAS,wCAAkC,KAA6B;QAYzE,2BAAA;IAXJ,IAAI,QAAQ,CAAA,GAAA,yCAAuB,EAAK;QACtC,GAAG,KAAK;QACR,mBAAmB,MAAM,iBAAiB,GACtC,CAAA;gBAEI;YADF,IAAI,OAAO,OACT,2BAAA,MAAM,iBAAiB,cAAvB,+CAAA,8BAAA,OAA0B;QAE9B,IACA;QACJ,0BAA0B;QAC1B,oBACE,CAAA,OAAA,CAAA,4BAAA,MAAM,kBAAkB,cAAxB,uCAAA,4BACA,6CACE,MAAM,UAAU,EAChB,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,oBAHzD,kBAAA,OAKA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WAAW,WAAW;IAExC;IAEA,OAAO;AACT","sources":["packages/react-stately/src/tabs/useTabListState.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 Collection,\n CollectionBase,\n CollectionStateBase,\n Key,\n Node,\n SingleSelection\n} from '@react-types/shared';\nimport {SingleSelectListState, useSingleSelectListState} from '../list/useSingleSelectListState';\nimport {useEffect, useRef} from 'react';\n\nexport interface TabListProps<T>\n extends\n CollectionBase<T>,\n Omit<\n SingleSelection,\n 'disallowEmptySelection' | 'selectedKey' | 'defaultSelectedKey' | 'onSelectionChange'\n > {\n /**\n * Whether the TabList is disabled.\n * Shows that a selection exists, but is not available in that circumstance.\n */\n isDisabled?: boolean;\n /** The currently selected key in the collection (controlled). */\n selectedKey?: Key;\n /** The initial selected keys in the collection (uncontrolled). */\n defaultSelectedKey?: Key;\n /** Handler that is called when the selection changes. */\n onSelectionChange?: (key: Key) => void;\n}\n\nexport interface TabListStateOptions<T>\n extends Omit<TabListProps<T>, 'children'>, CollectionStateBase<T> {}\n\nexport interface TabListState<T> extends SingleSelectListState<T> {\n /** Whether the tab list is disabled. */\n isDisabled: boolean;\n}\n\n/**\n * Provides state management for a Tabs component. Tabs include a TabList which tracks\n * which tab is currently selected and displays the content associated with that Tab in a TabPanel.\n */\nexport function useTabListState<T extends object>(props: TabListStateOptions<T>): TabListState<T> {\n let state = useSingleSelectListState<T>({\n ...props,\n onSelectionChange: props.onSelectionChange\n ? key => {\n if (key != null) {\n props.onSelectionChange?.(key);\n }\n }\n : undefined,\n suppressTextValueWarning: true,\n defaultSelectedKey:\n props.defaultSelectedKey ??\n findDefaultSelectedKey(\n props.collection,\n props.disabledKeys ? new Set(props.disabledKeys) : new Set()\n ) ??\n undefined\n });\n\n let {selectionManager, collection, selectedKey: currentSelectedKey} = state;\n\n let lastSelectedKey = useRef(currentSelectedKey);\n useEffect(() => {\n // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)\n let selectedKey = currentSelectedKey;\n if (\n props.selectedKey == null &&\n (selectionManager.isEmpty || selectedKey == null || !collection.getItem(selectedKey))\n ) {\n selectedKey = findDefaultSelectedKey(collection, state.disabledKeys);\n if (selectedKey != null) {\n // directly set selection because replace/toggle selection won't consider disabled keys\n selectionManager.setSelectedKeys([selectedKey]);\n }\n }\n\n // If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.\n if (\n (selectedKey != null && selectionManager.focusedKey == null) ||\n (!selectionManager.isFocused && selectedKey !== lastSelectedKey.current)\n ) {\n selectionManager.setFocusedKey(selectedKey);\n }\n lastSelectedKey.current = selectedKey;\n });\n\n return {\n ...state,\n isDisabled: props.isDisabled || false\n };\n}\n\nfunction findDefaultSelectedKey<T>(\n collection: Collection<Node<T>> | undefined,\n disabledKeys: Set<Key>\n) {\n let selectedKey: Key | null = null;\n if (collection) {\n selectedKey = collection.getFirstKey();\n // loop over tabs until we find one that isn't disabled and select that\n while (\n selectedKey != null &&\n (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) &&\n selectedKey !== collection.getLastKey()\n ) {\n selectedKey = collection.getKeyAfter(selectedKey);\n }\n // if this check is true, then every item is disabled, it makes more sense to default to the first key than the last\n if (\n selectedKey != null &&\n (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) &&\n selectedKey === collection.getLastKey()\n ) {\n selectedKey = collection.getFirstKey();\n }\n }\n\n return selectedKey;\n}\n"],"names":[],"version":3,"file":"useTabListState.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;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WAAW,UAAU,GAC1J,cAAc,WAAW,WAAW,CAAC;QAEvC,oHAAoH;QACpH,IAAI,eAAe,QAAS,CAAA,aAAa,GAAG,CAAC,gBAAgB,WAAW,OAAO,CAAC,cAAc,OAAO,UAAS,KAAM,gBAAgB,WAAW,UAAU,IACvJ,cAAc,WAAW,WAAW;IAExC;IAEA,OAAO;AACT","sources":["packages/react-stately/src/tabs/useTabListState.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 {Collection, CollectionBase, CollectionStateBase, Key, Node, SingleSelection} from '@react-types/shared';\nimport {SingleSelectListState, useSingleSelectListState} from '../list/useSingleSelectListState';\nimport {useEffect, useRef} from 'react';\n\nexport interface TabListProps<T> extends CollectionBase<T>, Omit<SingleSelection, 'disallowEmptySelection' | 'selectedKey' | 'defaultSelectedKey' | 'onSelectionChange'> {\n /**\n * Whether the TabList is disabled.\n * Shows that a selection exists, but is not available in that circumstance.\n */\n isDisabled?: boolean,\n /** The currently selected key in the collection (controlled). */\n selectedKey?: Key,\n /** The initial selected keys in the collection (uncontrolled). */\n defaultSelectedKey?: Key,\n /** Handler that is called when the selection changes. */\n onSelectionChange?: (key: Key) => void\n}\n\nexport interface TabListStateOptions<T> extends Omit<TabListProps<T>, 'children'>, CollectionStateBase<T> {}\n\nexport interface TabListState<T> extends SingleSelectListState<T> {\n /** Whether the tab list is disabled. */\n isDisabled: boolean\n}\n\n/**\n * Provides state management for a Tabs component. Tabs include a TabList which tracks\n * which tab is currently selected and displays the content associated with that Tab in a TabPanel.\n */\nexport function useTabListState<T extends object>(props: TabListStateOptions<T>): TabListState<T> {\n let state = useSingleSelectListState<T>({\n ...props,\n onSelectionChange: props.onSelectionChange ? (key => {\n if (key != null) {\n props.onSelectionChange?.(key);\n }\n }) : undefined,\n suppressTextValueWarning: true,\n defaultSelectedKey: props.defaultSelectedKey ?? findDefaultSelectedKey(props.collection, props.disabledKeys ? new Set(props.disabledKeys) : new Set()) ?? undefined\n });\n\n let {\n selectionManager,\n collection,\n selectedKey: currentSelectedKey\n } = state;\n\n let lastSelectedKey = useRef(currentSelectedKey);\n useEffect(() => {\n // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)\n let selectedKey = currentSelectedKey;\n if (props.selectedKey == null && (selectionManager.isEmpty || selectedKey == null || !collection.getItem(selectedKey))) {\n selectedKey = findDefaultSelectedKey(collection, state.disabledKeys);\n if (selectedKey != null) {\n // directly set selection because replace/toggle selection won't consider disabled keys\n selectionManager.setSelectedKeys([selectedKey]);\n }\n }\n\n // If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.\n if (selectedKey != null && selectionManager.focusedKey == null || (!selectionManager.isFocused && selectedKey !== lastSelectedKey.current)) {\n selectionManager.setFocusedKey(selectedKey);\n }\n lastSelectedKey.current = selectedKey;\n });\n\n return {\n ...state,\n isDisabled: props.isDisabled || false\n };\n}\n\nfunction findDefaultSelectedKey<T>(collection: Collection<Node<T>> | undefined, disabledKeys: Set<Key>) {\n let selectedKey: Key | null = null;\n if (collection) {\n selectedKey = collection.getFirstKey();\n // loop over tabs until we find one that isn't disabled and select that\n while (selectedKey != null && (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) && selectedKey !== collection.getLastKey()) {\n selectedKey = collection.getKeyAfter(selectedKey);\n }\n // if this check is true, then every item is disabled, it makes more sense to default to the first key than the last\n if (selectedKey != null && (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) && selectedKey === collection.getLastKey()) {\n selectedKey = collection.getFirstKey();\n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A,aAAa,GAAG,CAAC,gBAAgB,WAAW,OAAO,CAAC,cAAc,OAAO,UAAS,KACnF,gBAAgB,WAAW,UAAU,GAErC,cAAc,WAAW,WAAW,CAAC;QAEvC,oHAAoH;QACpH,IACE,eAAe,QACd,CAAA,aAAa,GAAG,CAAC,gBAAgB,WAAW,OAAO,CAAC,cAAc,OAAO,UAAS,KACnF,gBAAgB,WAAW,UAAU,IAErC,cAAc,WAAW,WAAW;IAExC;IAEA,OAAO;AACT","sources":["packages/react-stately/src/tabs/useTabListState.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 Collection,\n CollectionBase,\n CollectionStateBase,\n Key,\n Node,\n SingleSelection\n} from '@react-types/shared';\nimport {SingleSelectListState, useSingleSelectListState} from '../list/useSingleSelectListState';\nimport {useEffect, useRef} from 'react';\n\nexport interface TabListProps<T>\n extends\n CollectionBase<T>,\n Omit<\n SingleSelection,\n 'disallowEmptySelection' | 'selectedKey' | 'defaultSelectedKey' | 'onSelectionChange'\n > {\n /**\n * Whether the TabList is disabled.\n * Shows that a selection exists, but is not available in that circumstance.\n */\n isDisabled?: boolean;\n /** The currently selected key in the collection (controlled). */\n selectedKey?: Key;\n /** The initial selected keys in the collection (uncontrolled). */\n defaultSelectedKey?: Key;\n /** Handler that is called when the selection changes. */\n onSelectionChange?: (key: Key) => void;\n}\n\nexport interface TabListStateOptions<T>\n extends Omit<TabListProps<T>, 'children'>, CollectionStateBase<T> {}\n\nexport interface TabListState<T> extends SingleSelectListState<T> {\n /** Whether the tab list is disabled. */\n isDisabled: boolean;\n}\n\n/**\n * Provides state management for a Tabs component. Tabs include a TabList which tracks\n * which tab is currently selected and displays the content associated with that Tab in a TabPanel.\n */\nexport function useTabListState<T extends object>(props: TabListStateOptions<T>): TabListState<T> {\n let state = useSingleSelectListState<T>({\n ...props,\n onSelectionChange: props.onSelectionChange\n ? key => {\n if (key != null) {\n props.onSelectionChange?.(key);\n }\n }\n : undefined,\n suppressTextValueWarning: true,\n defaultSelectedKey:\n props.defaultSelectedKey ??\n findDefaultSelectedKey(\n props.collection,\n props.disabledKeys ? new Set(props.disabledKeys) : new Set()\n ) ??\n undefined\n });\n\n let {selectionManager, collection, selectedKey: currentSelectedKey} = state;\n\n let lastSelectedKey = useRef(currentSelectedKey);\n useEffect(() => {\n // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)\n let selectedKey = currentSelectedKey;\n if (\n props.selectedKey == null &&\n (selectionManager.isEmpty || selectedKey == null || !collection.getItem(selectedKey))\n ) {\n selectedKey = findDefaultSelectedKey(collection, state.disabledKeys);\n if (selectedKey != null) {\n // directly set selection because replace/toggle selection won't consider disabled keys\n selectionManager.setSelectedKeys([selectedKey]);\n }\n }\n\n // If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.\n if (\n (selectedKey != null && selectionManager.focusedKey == null) ||\n (!selectionManager.isFocused && selectedKey !== lastSelectedKey.current)\n ) {\n selectionManager.setFocusedKey(selectedKey);\n }\n lastSelectedKey.current = selectedKey;\n });\n\n return {\n ...state,\n isDisabled: props.isDisabled || false\n };\n}\n\nfunction findDefaultSelectedKey<T>(\n collection: Collection<Node<T>> | undefined,\n disabledKeys: Set<Key>\n) {\n let selectedKey: Key | null = null;\n if (collection) {\n selectedKey = collection.getFirstKey();\n // loop over tabs until we find one that isn't disabled and select that\n while (\n selectedKey != null &&\n (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) &&\n selectedKey !== collection.getLastKey()\n ) {\n selectedKey = collection.getKeyAfter(selectedKey);\n }\n // if this check is true, then every item is disabled, it makes more sense to default to the first key than the last\n if (\n selectedKey != null &&\n (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) &&\n selectedKey === collection.getLastKey()\n ) {\n selectedKey = collection.getFirstKey();\n }\n }\n\n return selectedKey;\n}\n"],"names":[],"version":3,"file":"useTabListState.mjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAiDM,SAAS,0CAAiB,QAAyB,CAAC,CAAC;IAC1D,IAAI,oBAAC,mBAAmB,eAAG,UAAU,EAAC,GAAG;IACzC,IAAI,QAAQ,CAAA,GAAA,oBAAM,EAAE,IAAM,IAAI,0CAAc;8BAAC;wBAAkB;QAAU,IAAI;QAAC;QAAkB;KAAW;IAC3G,OAAO,0CAAc;AACvB;AAKO,SAAS,0CAAiB,KAAoB;IACnD,IAAI,YAAY,CAAA,GAAA,wBAAU,EAAE,CAAA,KAAM,MAAM,SAAS,CAAC,KAAK;QAAC;KAAM;IAC9D,IAAI,cAAc,CAAA,GAAA,wBAAU,EAAE,IAAM,MAAM,aAAa,EAAE;QAAC;KAAM;IAChE,IAAI,gBAAgB,CAAA,GAAA,2DAAmB,EAAE,WAAW,aAAa;IAEjE,OAAO;uBACL;QACA,KAAK,CAAC,SAAS,UAAY,MAAM,GAAG,CAAC,SAAS;QAC9C,OAAO,CAAA,MAAO,MAAM,KAAK,CAAC;QAC1B,UAAU,IAAM,MAAM,QAAQ;QAC9B,WAAW,IAAM,MAAM,SAAS;IAClC;AACF;AAKO,MAAM;IAQX,YAAY,OAAyB,CAAE;aAP/B,QAA0B,EAAE;aAC5B,gBAAiC,IAAI;QAG7C,kCAAkC,QAClC,gBAAkC,EAAE;QAGlC,IAAI,CAAC,gBAAgB,GAAG,SAAS,oBAAoB;QACrD,IAAI,CAAC,UAAU,GAAG,SAAS;IAC7B;IAEQ,kBAAkB,EAAc,EAAE,MAAmB,EAAQ;QACnE,IA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KAAK;IAGvB;IAEA,+CAA+C,GAC/C,YAAkB;QAChB,KAAK,IAAI,SAAS,IAAI,CAAC,aAAa,CAClC,IAAI,MAAM,KAAK,EACb,MAAM,KAAK,CAAC,MAAM;IAGxB;IAEA,QAAc;QACZ,IAAI,CAAC,KAAK,GAAG,EAAE;QACf,IAAI,CAAC,mBAAmB,CAAC;IAC3B;AACF;AAEA,MAAM;IAMJ,YAAY,QAAoB,EAAE,KAAa,CAAE;aAJzC,YAA2B;QAKjC,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,CAAC,QAAQ,GAAG;IAClB;IAEA,MAAM,KAAa,EAAQ;QACzB,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,CAAC,MAAM;IACb;IAEA,QAAc;QACZ,IAAI,IAAI,CAAC,OAAO,IAAI,MAClB;QAGF,aAAa,IAAI,CAAC,OAAO;QACzB,IAAI,CAAC,OAAO,GAAG;QACf,IAAI,CAAC,SAAS,IAAI,KAAK,GAAG,KAAK,IAAI,CAAC,SAAS;IAC/C;IAEA,SAAe;QACb,IAAI,IAAI,CAAC,SAAS,IAAI,GACpB;QAGF,IAAI,CAAC,SAAS,GAAG,KAAK,GAAG;QACzB,IAAI,CAAC,OAAO,GAAG,WAAW;YACxB,IAAI,CAAC,OAAO,GAAG;YACf,IAAI,CAAC,SAAS,GAAG;YACjB,IAAI,CAAC,QAAQ;QACf,GAAG,IAAI,CAAC,SAAS;IACnB;AACF","sources":["packages/react-stately/src/toast/useToastState.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, useMemo} from 'react';\n// Shim to support React 17 and below.\nimport {useSyncExternalStore} from 'use-sync-external-store/shim/index.js';\n\ntype ToastAction = 'add' | 'remove' | 'clear';\nexport interface ToastStateProps {\n /** The maximum number of toasts to display at a time. */\n maxVisibleToasts?: number,\n /** Function to wrap updates in (i.e. document.startViewTransition()). */\n wrapUpdate?: (fn: () => void, action: ToastAction) => void\n}\n\nexport interface ToastOptions {\n /** Handler that is called when the toast is closed, either by the user or after a timeout. */\n onClose?: () => void,\n /** A timeout to automatically close the toast after, in milliseconds. */\n timeout?: number\n}\n\nexport interface QueuedToast<T> extends ToastOptions {\n /** The content of the toast. */\n content: T,\n /** A unique key for the toast. */\n key: string,\n /** A timer for the toast, if a timeout was set. */\n timer?: Timer\n}\n\nexport interface ToastState<T> {\n /** Adds a new toast to the queue. */\n add(content: T, options?: ToastOptions): string,\n /**\n * Closes a toast.\n */\n close(key: string): void,\n /** Pauses the timers for all visible toasts. */\n pauseAll(): void,\n /** Resumes the timers for all visible toasts. */\n resumeAll(): void,\n /** The visible toasts. */\n visibleToasts: QueuedToast<T>[]\n}\n\n/**\n * Provides state management for a toast queue. Toasts display brief, temporary notifications\n * of actions, errors, or other events in an application.\n */\nexport function useToastState<T>(props: ToastStateProps = {}): ToastState<T> {\n let {maxVisibleToasts = 1, wrapUpdate} = props;\n let queue = useMemo(() => new ToastQueue<T>({maxVisibleToasts, wrapUpdate}), [maxVisibleToasts, wrapUpdate]);\n return useToastQueue(queue);\n}\n\n/**\n * Subscribes to a provided toast queue and provides methods to update it.\n */\nexport function useToastQueue<T>(queue: ToastQueue<T>): ToastState<T> {\n let subscribe = useCallback(fn => queue.subscribe(fn), [queue]);\n let getSnapshot = useCallback(() => queue.visibleToasts, [queue]);\n let visibleToasts = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n return {\n visibleToasts,\n add: (content, options) => queue.add(content, options),\n close: key => queue.close(key),\n pauseAll: () => queue.pauseAll(),\n resumeAll: () => queue.resumeAll()\n };\n}\n\n/**\n * A ToastQueue manages the order of toasts.\n */\nexport class ToastQueue<T> {\n private queue: QueuedToast<T>[] = [];\n private subscriptions: Set<() => void> = new Set();\n private maxVisibleToasts: number;\n private wrapUpdate?: (fn: () => void, action: ToastAction) => void;\n /** The currently visible toasts. */\n visibleToasts: QueuedToast<T>[] = [];\n\n constructor(options?: ToastStateProps) {\n this.maxVisibleToasts = options?.maxVisibleToasts ?? Infinity;\n this.wrapUpdate = options?.wrapUpdate;\n }\n\n private runWithWrapUpdate(fn: () => void, action: ToastAction): void {\n if (this.wrapUpdate) {\n this.wrapUpdate(fn, action);\n } else {\n fn();\n }\n }\n\n /** Subscribes to updates to the visible toasts. */\n subscribe(fn: () => void): () => void {\n this.subscriptions.add(fn);\n return () => this.subscriptions.delete(fn);\n }\n\n /** Adds a new toast to the queue. */\n add(content: T, options: ToastOptions = {}): string {\n let toastKey = '_' + Math.random().toString(36).slice(2);\n let toast: QueuedToast<T> = {\n ...options,\n content,\n key: toastKey,\n timer: options.timeout ? new Timer(() => this.close(toastKey), options.timeout) : undefined\n };\n\n this.queue.unshift(toast);\n\n this.updateVisibleToasts('add');\n return toastKey;\n }\n\n /**\n * Closes a toast.\n */\n close(key: string): void {\n let index = this.queue.findIndex(t => t.key === key);\n if (index >= 0) {\n this.queue[index].onClose?.();\n this.queue.splice(index, 1);\n }\n\n this.updateVisibleToasts('remove');\n }\n\n private updateVisibleToasts(action: ToastAction) {\n this.visibleToasts = this.queue.slice(0, this.maxVisibleToasts);\n\n this.runWithWrapUpdate(() => {\n for (let fn of this.subscriptions) {\n fn();\n }\n }, action);\n }\n\n /** Pauses the timers for all visible toasts. */\n pauseAll(): void {\n for (let toast of this.visibleToasts) {\n if (toast.timer) {\n toast.timer.pause();\n }\n }\n }\n\n /** Resumes the timers for all visible toasts. */\n resumeAll(): void {\n for (let toast of this.visibleToasts) {\n if (toast.timer) {\n toast.timer.resume();\n }\n }\n }\n\n clear(): void {\n this.queue = [];\n this.updateVisibleToasts('clear');\n }\n}\n\nclass Timer {\n private timerId;\n private startTime: number | null = null;\n private remaining: number;\n private callback: () => void;\n\n constructor(callback: () => void, delay: number) {\n this.remaining = delay;\n this.callback = callback;\n }\n\n reset(delay: number): void {\n this.remaining = delay;\n this.resume();\n }\n\n pause(): void {\n if (this.timerId == null) {\n return;\n }\n\n clearTimeout(this.timerId);\n this.timerId = null;\n this.remaining -= Date.now() - this.startTime!;\n }\n\n resume(): void {\n if (this.remaining <= 0) {\n return;\n }\n\n this.startTime = Date.now();\n this.timerId = setTimeout(() => {\n this.timerId = null;\n this.remaining = 0;\n this.callback();\n }, this.remaining);\n }\n}\n"],"names":[],"version":3,"file":"useToastState.cjs.map"}
1
+ {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAiDM,SAAS,0CAAiB,QAAyB,CAAC,CAAC;IAC1D,IAAI,oBAAC,mBAAmB,eAAG,UAAU,EAAC,GAAG;IACzC,IAAI,QAAQ,CAAA,GAAA,oBAAM,EAChB,IAAM,IAAI,0CAAc;8BAAC;wBAAkB;QAAU,IACrD;QAAC;QAAkB;KAAW;IAEhC,OAAO,0CAAc;AACvB;AAKO,SAAS,0CAAiB,KAAoB;IACnD,IAAI,YAAY,CAAA,GAAA,wBAAU,EAAE,CAAA,KAAM,MAAM,SAAS,CAAC,KAAK;QAAC;KAAM;IAC9D,IAAI,cAAc,CAAA,GAAA,wBAAU,EAAE,IAAM,MAAM,aAAa,EAAE;QAAC;KAAM;IAChE,IAAI,gBAAgB,CAAA,GAAA,2DAAmB,EAAE,WAAW,aAAa;IAEjE,OAAO;uBACL;QACA,KAAK,CAAC,SAAS,UAAY,MAAM,GAAG,CAAC,SAAS;QAC9C,OAAO,CAAA,MAAO,MAAM,KAAK,CAAC;QAC1B,UAAU,IAAM,MAAM,QAAQ;QAC9B,WAAW,IAAM,MAAM,SAAS;IAClC;AACF;AAKO,MAAM;IAQX,YAAY,OAAyB,CAAE;aAP/B,QAA0B,EAAE;aAC5B,gBAA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AC;YACrB,KAAK,IAAI,MAAM,IAAI,CAAC,aAAa,CAC/B;QAEJ,GAAG;IACL;IAEA,8CAA8C,GAC9C,WAAiB;QACf,KAAK,IAAI,SAAS,IAAI,CAAC,aAAa,CAClC,IAAI,MAAM,KAAK,EACb,MAAM,KAAK,CAAC,KAAK;IAGvB;IAEA,+CAA+C,GAC/C,YAAkB;QAChB,KAAK,IAAI,SAAS,IAAI,CAAC,aAAa,CAClC,IAAI,MAAM,KAAK,EACb,MAAM,KAAK,CAAC,MAAM;IAGxB;IAEA,QAAc;QACZ,IAAI,CAAC,KAAK,GAAG,EAAE;QACf,IAAI,CAAC,mBAAmB,CAAC;IAC3B;AACF;AAEA,MAAM;IAMJ,YAAY,QAAoB,EAAE,KAAa,CAAE;aAJzC,YAA2B;QAKjC,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,CAAC,QAAQ,GAAG;IAClB;IAEA,MAAM,KAAa,EAAQ;QACzB,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,CAAC,MAAM;IACb;IAEA,QAAc;QACZ,IAAI,IAAI,CAAC,OAAO,IAAI,MAClB;QAGF,aAAa,IAAI,CAAC,OAAO;QACzB,IAAI,CAAC,OAAO,GAAG;QACf,IAAI,CAAC,SAAS,IAAI,KAAK,GAAG,KAAK,IAAI,CAAC,SAAS;IAC/C;IAEA,SAAe;QACb,IAAI,IAAI,CAAC,SAAS,IAAI,GACpB;QAGF,IAAI,CAAC,SAAS,GAAG,KAAK,GAAG;QACzB,IAAI,CAAC,OAAO,GAAG,WAAW;YACxB,IAAI,CAAC,OAAO,GAAG;YACf,IAAI,CAAC,SAAS,GAAG;YACjB,IAAI,CAAC,QAAQ;QACf,GAAG,IAAI,CAAC,SAAS;IACnB;AACF","sources":["packages/react-stately/src/toast/useToastState.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, useMemo} from 'react';\n// Shim to support React 17 and below.\nimport {useSyncExternalStore} from 'use-sync-external-store/shim/index.js';\n\ntype ToastAction = 'add' | 'remove' | 'clear';\nexport interface ToastStateProps {\n /** The maximum number of toasts to display at a time. */\n maxVisibleToasts?: number;\n /** Function to wrap updates in (i.e. document.startViewTransition()). */\n wrapUpdate?: (fn: () => void, action: ToastAction) => void;\n}\n\nexport interface ToastOptions {\n /** Handler that is called when the toast is closed, either by the user or after a timeout. */\n onClose?: () => void;\n /** A timeout to automatically close the toast after, in milliseconds. */\n timeout?: number;\n}\n\nexport interface QueuedToast<T> extends ToastOptions {\n /** The content of the toast. */\n content: T;\n /** A unique key for the toast. */\n key: string;\n /** A timer for the toast, if a timeout was set. */\n timer?: Timer;\n}\n\nexport interface ToastState<T> {\n /** Adds a new toast to the queue. */\n add(content: T, options?: ToastOptions): string;\n /**\n * Closes a toast.\n */\n close(key: string): void;\n /** Pauses the timers for all visible toasts. */\n pauseAll(): void;\n /** Resumes the timers for all visible toasts. */\n resumeAll(): void;\n /** The visible toasts. */\n visibleToasts: QueuedToast<T>[];\n}\n\n/**\n * Provides state management for a toast queue. Toasts display brief, temporary notifications\n * of actions, errors, or other events in an application.\n */\nexport function useToastState<T>(props: ToastStateProps = {}): ToastState<T> {\n let {maxVisibleToasts = 1, wrapUpdate} = props;\n let queue = useMemo(\n () => new ToastQueue<T>({maxVisibleToasts, wrapUpdate}),\n [maxVisibleToasts, wrapUpdate]\n );\n return useToastQueue(queue);\n}\n\n/**\n * Subscribes to a provided toast queue and provides methods to update it.\n */\nexport function useToastQueue<T>(queue: ToastQueue<T>): ToastState<T> {\n let subscribe = useCallback(fn => queue.subscribe(fn), [queue]);\n let getSnapshot = useCallback(() => queue.visibleToasts, [queue]);\n let visibleToasts = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n return {\n visibleToasts,\n add: (content, options) => queue.add(content, options),\n close: key => queue.close(key),\n pauseAll: () => queue.pauseAll(),\n resumeAll: () => queue.resumeAll()\n };\n}\n\n/**\n * A ToastQueue manages the order of toasts.\n */\nexport class ToastQueue<T> {\n private queue: QueuedToast<T>[] = [];\n private subscriptions: Set<() => void> = new Set();\n private maxVisibleToasts: number;\n private wrapUpdate?: (fn: () => void, action: ToastAction) => void;\n /** The currently visible toasts. */\n visibleToasts: QueuedToast<T>[] = [];\n\n constructor(options?: ToastStateProps) {\n this.maxVisibleToasts = options?.maxVisibleToasts ?? Infinity;\n this.wrapUpdate = options?.wrapUpdate;\n }\n\n private runWithWrapUpdate(fn: () => void, action: ToastAction): void {\n if (this.wrapUpdate) {\n this.wrapUpdate(fn, action);\n } else {\n fn();\n }\n }\n\n /** Subscribes to updates to the visible toasts. */\n subscribe(fn: () => void): () => void {\n this.subscriptions.add(fn);\n return () => this.subscriptions.delete(fn);\n }\n\n /** Adds a new toast to the queue. */\n add(content: T, options: ToastOptions = {}): string {\n let toastKey = '_' + Math.random().toString(36).slice(2);\n let toast: QueuedToast<T> = {\n ...options,\n content,\n key: toastKey,\n timer: options.timeout ? new Timer(() => this.close(toastKey), options.timeout) : undefined\n };\n\n this.queue.unshift(toast);\n\n this.updateVisibleToasts('add');\n return toastKey;\n }\n\n /**\n * Closes a toast.\n */\n close(key: string): void {\n let index = this.queue.findIndex(t => t.key === key);\n if (index >= 0) {\n this.queue[index].onClose?.();\n this.queue.splice(index, 1);\n }\n\n this.updateVisibleToasts('remove');\n }\n\n private updateVisibleToasts(action: ToastAction) {\n this.visibleToasts = this.queue.slice(0, this.maxVisibleToasts);\n\n this.runWithWrapUpdate(() => {\n for (let fn of this.subscriptions) {\n fn();\n }\n }, action);\n }\n\n /** Pauses the timers for all visible toasts. */\n pauseAll(): void {\n for (let toast of this.visibleToasts) {\n if (toast.timer) {\n toast.timer.pause();\n }\n }\n }\n\n /** Resumes the timers for all visible toasts. */\n resumeAll(): void {\n for (let toast of this.visibleToasts) {\n if (toast.timer) {\n toast.timer.resume();\n }\n }\n }\n\n clear(): void {\n this.queue = [];\n this.updateVisibleToasts('clear');\n }\n}\n\nclass Timer {\n private timerId;\n private startTime: number | null = null;\n private remaining: number;\n private callback: () => void;\n\n constructor(callback: () => void, delay: number) {\n this.remaining = delay;\n this.callback = callback;\n }\n\n reset(delay: number): void {\n this.remaining = delay;\n this.resume();\n }\n\n pause(): void {\n if (this.timerId == null) {\n return;\n }\n\n clearTimeout(this.timerId);\n this.timerId = null;\n this.remaining -= Date.now() - this.startTime!;\n }\n\n resume(): void {\n if (this.remaining <= 0) {\n return;\n }\n\n this.startTime = Date.now();\n this.timerId = setTimeout(() => {\n this.timerId = null;\n this.remaining = 0;\n this.callback();\n }, this.remaining);\n }\n}\n"],"names":[],"version":3,"file":"useToastState.cjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAiDM,SAAS,0CAAiB,QAAyB,CAAC,CAAC;IAC1D,IAAI,oBAAC,mBAAmB,eAAG,UAAU,EAAC,GAAG;IACzC,IAAI,QAAQ,CAAA,GAAA,cAAM,EAAE,IAAM,IAAI,0CAAc;8BAAC;wBAAkB;QAAU,IAAI;QAAC;QAAkB;KAAW;IAC3G,OAAO,0CAAc;AACvB;AAKO,SAAS,0CAAiB,KAAoB;IACnD,IAAI,YAAY,CAAA,GAAA,kBAAU,EAAE,CAAA,KAAM,MAAM,SAAS,CAAC,KAAK;QAAC;KAAM;IAC9D,IAAI,cAAc,CAAA,GAAA,kBAAU,EAAE,IAAM,MAAM,aAAa,EAAE;QAAC;KAAM;IAChE,IAAI,gBAAgB,CAAA,GAAA,2BAAmB,EAAE,WAAW,aAAa;IAEjE,OAAO;uBACL;QACA,KAAK,CAAC,SAAS,UAAY,MAAM,GAAG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YACjB,IAAI,CAAC,QAAQ;QACf,GAAG,IAAI,CAAC,SAAS;IACnB;IA/BA,YAAY,QAAoB,EAAE,KAAa,CAAE;aAJzC,YAA2B;QAKjC,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,CAAC,QAAQ,GAAG;IAClB;AA6BF","sources":["packages/react-stately/src/toast/useToastState.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, useMemo} from 'react';\n// Shim to support React 17 and below.\nimport {useSyncExternalStore} from 'use-sync-external-store/shim/index.js';\n\ntype ToastAction = 'add' | 'remove' | 'clear';\nexport interface ToastStateProps {\n /** The maximum number of toasts to display at a time. */\n maxVisibleToasts?: number,\n /** Function to wrap updates in (i.e. document.startViewTransition()). */\n wrapUpdate?: (fn: () => void, action: ToastAction) => void\n}\n\nexport interface ToastOptions {\n /** Handler that is called when the toast is closed, either by the user or after a timeout. */\n onClose?: () => void,\n /** A timeout to automatically close the toast after, in milliseconds. */\n timeout?: number\n}\n\nexport interface QueuedToast<T> extends ToastOptions {\n /** The content of the toast. */\n content: T,\n /** A unique key for the toast. */\n key: string,\n /** A timer for the toast, if a timeout was set. */\n timer?: Timer\n}\n\nexport interface ToastState<T> {\n /** Adds a new toast to the queue. */\n add(content: T, options?: ToastOptions): string,\n /**\n * Closes a toast.\n */\n close(key: string): void,\n /** Pauses the timers for all visible toasts. */\n pauseAll(): void,\n /** Resumes the timers for all visible toasts. */\n resumeAll(): void,\n /** The visible toasts. */\n visibleToasts: QueuedToast<T>[]\n}\n\n/**\n * Provides state management for a toast queue. Toasts display brief, temporary notifications\n * of actions, errors, or other events in an application.\n */\nexport function useToastState<T>(props: ToastStateProps = {}): ToastState<T> {\n let {maxVisibleToasts = 1, wrapUpdate} = props;\n let queue = useMemo(() => new ToastQueue<T>({maxVisibleToasts, wrapUpdate}), [maxVisibleToasts, wrapUpdate]);\n return useToastQueue(queue);\n}\n\n/**\n * Subscribes to a provided toast queue and provides methods to update it.\n */\nexport function useToastQueue<T>(queue: ToastQueue<T>): ToastState<T> {\n let subscribe = useCallback(fn => queue.subscribe(fn), [queue]);\n let getSnapshot = useCallback(() => queue.visibleToasts, [queue]);\n let visibleToasts = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n return {\n visibleToasts,\n add: (content, options) => queue.add(content, options),\n close: key => queue.close(key),\n pauseAll: () => queue.pauseAll(),\n resumeAll: () => queue.resumeAll()\n };\n}\n\n/**\n * A ToastQueue manages the order of toasts.\n */\nexport class ToastQueue<T> {\n private queue: QueuedToast<T>[] = [];\n private subscriptions: Set<() => void> = new Set();\n private maxVisibleToasts: number;\n private wrapUpdate?: (fn: () => void, action: ToastAction) => void;\n /** The currently visible toasts. */\n visibleToasts: QueuedToast<T>[] = [];\n\n constructor(options?: ToastStateProps) {\n this.maxVisibleToasts = options?.maxVisibleToasts ?? Infinity;\n this.wrapUpdate = options?.wrapUpdate;\n }\n\n private runWithWrapUpdate(fn: () => void, action: ToastAction): void {\n if (this.wrapUpdate) {\n this.wrapUpdate(fn, action);\n } else {\n fn();\n }\n }\n\n /** Subscribes to updates to the visible toasts. */\n subscribe(fn: () => void): () => void {\n this.subscriptions.add(fn);\n return () => this.subscriptions.delete(fn);\n }\n\n /** Adds a new toast to the queue. */\n add(content: T, options: ToastOptions = {}): string {\n let toastKey = '_' + Math.random().toString(36).slice(2);\n let toast: QueuedToast<T> = {\n ...options,\n content,\n key: toastKey,\n timer: options.timeout ? new Timer(() => this.close(toastKey), options.timeout) : undefined\n };\n\n this.queue.unshift(toast);\n\n this.updateVisibleToasts('add');\n return toastKey;\n }\n\n /**\n * Closes a toast.\n */\n close(key: string): void {\n let index = this.queue.findIndex(t => t.key === key);\n if (index >= 0) {\n this.queue[index].onClose?.();\n this.queue.splice(index, 1);\n }\n\n this.updateVisibleToasts('remove');\n }\n\n private updateVisibleToasts(action: ToastAction) {\n this.visibleToasts = this.queue.slice(0, this.maxVisibleToasts);\n\n this.runWithWrapUpdate(() => {\n for (let fn of this.subscriptions) {\n fn();\n }\n }, action);\n }\n\n /** Pauses the timers for all visible toasts. */\n pauseAll(): void {\n for (let toast of this.visibleToasts) {\n if (toast.timer) {\n toast.timer.pause();\n }\n }\n }\n\n /** Resumes the timers for all visible toasts. */\n resumeAll(): void {\n for (let toast of this.visibleToasts) {\n if (toast.timer) {\n toast.timer.resume();\n }\n }\n }\n\n clear(): void {\n this.queue = [];\n this.updateVisibleToasts('clear');\n }\n}\n\nclass Timer {\n private timerId;\n private startTime: number | null = null;\n private remaining: number;\n private callback: () => void;\n\n constructor(callback: () => void, delay: number) {\n this.remaining = delay;\n this.callback = callback;\n }\n\n reset(delay: number): void {\n this.remaining = delay;\n this.resume();\n }\n\n pause(): void {\n if (this.timerId == null) {\n return;\n }\n\n clearTimeout(this.timerId);\n this.timerId = null;\n this.remaining -= Date.now() - this.startTime!;\n }\n\n resume(): void {\n if (this.remaining <= 0) {\n return;\n }\n\n this.startTime = Date.now();\n this.timerId = setTimeout(() => {\n this.timerId = null;\n this.remaining = 0;\n this.callback();\n }, this.remaining);\n }\n}\n"],"names":[],"version":3,"file":"useToastState.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAiDM,SAAS,0CAAiB,QAAyB,CAAC,CAAC;IAC1D,IAAI,oBAAC,mBAAmB,eAAG,UAAU,EAAC,GAAG;IACzC,IAAI,QAAQ,CAAA,GAAA,cAAM,EAChB,IAAM,IAAI,0CAAc;8BAAC;wBAAkB;QAAU,IACrD;QAAC;QAAkB;KAAW;IAEhC,OAAO,0CAAc;AACvB;AAKO,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,IAAI,CAAC,OAAO;QACzB,IAAI,CAAC,OAAO,GAAG;QACf,IAAI,CAAC,SAAS,IAAI,KAAK,GAAG,KAAK,IAAI,CAAC,SAAS;IAC/C;IAEA,SAAe;QACb,IAAI,IAAI,CAAC,SAAS,IAAI,GACpB;QAGF,IAAI,CAAC,SAAS,GAAG,KAAK,GAAG;QACzB,IAAI,CAAC,OAAO,GAAG,WAAW;YACxB,IAAI,CAAC,OAAO,GAAG;YACf,IAAI,CAAC,SAAS,GAAG;YACjB,IAAI,CAAC,QAAQ;QACf,GAAG,IAAI,CAAC,SAAS;IACnB;IA/BA,YAAY,QAAoB,EAAE,KAAa,CAAE;aAJzC,YAA2B;QAKjC,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,CAAC,QAAQ,GAAG;IAClB;AA6BF","sources":["packages/react-stately/src/toast/useToastState.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, useMemo} from 'react';\n// Shim to support React 17 and below.\nimport {useSyncExternalStore} from 'use-sync-external-store/shim/index.js';\n\ntype ToastAction = 'add' | 'remove' | 'clear';\nexport interface ToastStateProps {\n /** The maximum number of toasts to display at a time. */\n maxVisibleToasts?: number;\n /** Function to wrap updates in (i.e. document.startViewTransition()). */\n wrapUpdate?: (fn: () => void, action: ToastAction) => void;\n}\n\nexport interface ToastOptions {\n /** Handler that is called when the toast is closed, either by the user or after a timeout. */\n onClose?: () => void;\n /** A timeout to automatically close the toast after, in milliseconds. */\n timeout?: number;\n}\n\nexport interface QueuedToast<T> extends ToastOptions {\n /** The content of the toast. */\n content: T;\n /** A unique key for the toast. */\n key: string;\n /** A timer for the toast, if a timeout was set. */\n timer?: Timer;\n}\n\nexport interface ToastState<T> {\n /** Adds a new toast to the queue. */\n add(content: T, options?: ToastOptions): string;\n /**\n * Closes a toast.\n */\n close(key: string): void;\n /** Pauses the timers for all visible toasts. */\n pauseAll(): void;\n /** Resumes the timers for all visible toasts. */\n resumeAll(): void;\n /** The visible toasts. */\n visibleToasts: QueuedToast<T>[];\n}\n\n/**\n * Provides state management for a toast queue. Toasts display brief, temporary notifications\n * of actions, errors, or other events in an application.\n */\nexport function useToastState<T>(props: ToastStateProps = {}): ToastState<T> {\n let {maxVisibleToasts = 1, wrapUpdate} = props;\n let queue = useMemo(\n () => new ToastQueue<T>({maxVisibleToasts, wrapUpdate}),\n [maxVisibleToasts, wrapUpdate]\n );\n return useToastQueue(queue);\n}\n\n/**\n * Subscribes to a provided toast queue and provides methods to update it.\n */\nexport function useToastQueue<T>(queue: ToastQueue<T>): ToastState<T> {\n let subscribe = useCallback(fn => queue.subscribe(fn), [queue]);\n let getSnapshot = useCallback(() => queue.visibleToasts, [queue]);\n let visibleToasts = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n return {\n visibleToasts,\n add: (content, options) => queue.add(content, options),\n close: key => queue.close(key),\n pauseAll: () => queue.pauseAll(),\n resumeAll: () => queue.resumeAll()\n };\n}\n\n/**\n * A ToastQueue manages the order of toasts.\n */\nexport class ToastQueue<T> {\n private queue: QueuedToast<T>[] = [];\n private subscriptions: Set<() => void> = new Set();\n private maxVisibleToasts: number;\n private wrapUpdate?: (fn: () => void, action: ToastAction) => void;\n /** The currently visible toasts. */\n visibleToasts: QueuedToast<T>[] = [];\n\n constructor(options?: ToastStateProps) {\n this.maxVisibleToasts = options?.maxVisibleToasts ?? Infinity;\n this.wrapUpdate = options?.wrapUpdate;\n }\n\n private runWithWrapUpdate(fn: () => void, action: ToastAction): void {\n if (this.wrapUpdate) {\n this.wrapUpdate(fn, action);\n } else {\n fn();\n }\n }\n\n /** Subscribes to updates to the visible toasts. */\n subscribe(fn: () => void): () => void {\n this.subscriptions.add(fn);\n return () => this.subscriptions.delete(fn);\n }\n\n /** Adds a new toast to the queue. */\n add(content: T, options: ToastOptions = {}): string {\n let toastKey = '_' + Math.random().toString(36).slice(2);\n let toast: QueuedToast<T> = {\n ...options,\n content,\n key: toastKey,\n timer: options.timeout ? new Timer(() => this.close(toastKey), options.timeout) : undefined\n };\n\n this.queue.unshift(toast);\n\n this.updateVisibleToasts('add');\n return toastKey;\n }\n\n /**\n * Closes a toast.\n */\n close(key: string): void {\n let index = this.queue.findIndex(t => t.key === key);\n if (index >= 0) {\n this.queue[index].onClose?.();\n this.queue.splice(index, 1);\n }\n\n this.updateVisibleToasts('remove');\n }\n\n private updateVisibleToasts(action: ToastAction) {\n this.visibleToasts = this.queue.slice(0, this.maxVisibleToasts);\n\n this.runWithWrapUpdate(() => {\n for (let fn of this.subscriptions) {\n fn();\n }\n }, action);\n }\n\n /** Pauses the timers for all visible toasts. */\n pauseAll(): void {\n for (let toast of this.visibleToasts) {\n if (toast.timer) {\n toast.timer.pause();\n }\n }\n }\n\n /** Resumes the timers for all visible toasts. */\n resumeAll(): void {\n for (let toast of this.visibleToasts) {\n if (toast.timer) {\n toast.timer.resume();\n }\n }\n }\n\n clear(): void {\n this.queue = [];\n this.updateVisibleToasts('clear');\n }\n}\n\nclass Timer {\n private timerId;\n private startTime: number | null = null;\n private remaining: number;\n private callback: () => void;\n\n constructor(callback: () => void, delay: number) {\n this.remaining = delay;\n this.callback = callback;\n }\n\n reset(delay: number): void {\n this.remaining = delay;\n this.resume();\n }\n\n pause(): void {\n if (this.timerId == null) {\n return;\n }\n\n clearTimeout(this.timerId);\n this.timerId = null;\n this.remaining -= Date.now() - this.startTime!;\n }\n\n resume(): void {\n if (this.remaining <= 0) {\n return;\n }\n\n this.startTime = Date.now();\n this.timerId = setTimeout(() => {\n this.timerId = null;\n this.remaining = 0;\n this.callback();\n }, this.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,IAAI,CAAC,mBAAmB,CAAC;IAC3B;AACF;AAEA,MAAM;IAMJ,YAAY,QAAoB,EAAE,KAAa,CAAE;aAJzC,YAA2B;QAKjC,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,CAAC,QAAQ,GAAG;IAClB;IAEA,MAAM,KAAa,EAAQ;QACzB,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,CAAC,MAAM;IACb;IAEA,QAAc;QACZ,IAAI,IAAI,CAAC,OAAO,IAAI,MAClB;QAGF,aAAa,IAAI,CAAC,OAAO;QACzB,IAAI,CAAC,OAAO,GAAG;QACf,IAAI,CAAC,SAAS,IAAI,KAAK,GAAG,KAAK,IAAI,CAAC,SAAS;IAC/C;IAEA,SAAe;QACb,IAAI,IAAI,CAAC,SAAS,IAAI,GACpB;QAGF,IAAI,CAAC,SAAS,GAAG,KAAK,GAAG;QACzB,IAAI,CAAC,OAAO,GAAG,WAAW;YACxB,IAAI,CAAC,OAAO,GAAG;YACf,IAAI,CAAC,SAAS,GAAG;YACjB,IAAI,CAAC,QAAQ;QACf,GAAG,IAAI,CAAC,SAAS;IACnB;AACF","sources":["packages/react-stately/src/toast/useToastState.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, useMemo} from 'react';\n// Shim to support React 17 and below.\nimport {useSyncExternalStore} from 'use-sync-external-store/shim/index.js';\n\ntype ToastAction = 'add' | 'remove' | 'clear';\nexport interface ToastStateProps {\n /** The maximum number of toasts to display at a time. */\n maxVisibleToasts?: number,\n /** Function to wrap updates in (i.e. document.startViewTransition()). */\n wrapUpdate?: (fn: () => void, action: ToastAction) => void\n}\n\nexport interface ToastOptions {\n /** Handler that is called when the toast is closed, either by the user or after a timeout. */\n onClose?: () => void,\n /** A timeout to automatically close the toast after, in milliseconds. */\n timeout?: number\n}\n\nexport interface QueuedToast<T> extends ToastOptions {\n /** The content of the toast. */\n content: T,\n /** A unique key for the toast. */\n key: string,\n /** A timer for the toast, if a timeout was set. */\n timer?: Timer\n}\n\nexport interface ToastState<T> {\n /** Adds a new toast to the queue. */\n add(content: T, options?: ToastOptions): string,\n /**\n * Closes a toast.\n */\n close(key: string): void,\n /** Pauses the timers for all visible toasts. */\n pauseAll(): void,\n /** Resumes the timers for all visible toasts. */\n resumeAll(): void,\n /** The visible toasts. */\n visibleToasts: QueuedToast<T>[]\n}\n\n/**\n * Provides state management for a toast queue. Toasts display brief, temporary notifications\n * of actions, errors, or other events in an application.\n */\nexport function useToastState<T>(props: ToastStateProps = {}): ToastState<T> {\n let {maxVisibleToasts = 1, wrapUpdate} = props;\n let queue = useMemo(() => new ToastQueue<T>({maxVisibleToasts, wrapUpdate}), [maxVisibleToasts, wrapUpdate]);\n return useToastQueue(queue);\n}\n\n/**\n * Subscribes to a provided toast queue and provides methods to update it.\n */\nexport function useToastQueue<T>(queue: ToastQueue<T>): ToastState<T> {\n let subscribe = useCallback(fn => queue.subscribe(fn), [queue]);\n let getSnapshot = useCallback(() => queue.visibleToasts, [queue]);\n let visibleToasts = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n return {\n visibleToasts,\n add: (content, options) => queue.add(content, options),\n close: key => queue.close(key),\n pauseAll: () => queue.pauseAll(),\n resumeAll: () => queue.resumeAll()\n };\n}\n\n/**\n * A ToastQueue manages the order of toasts.\n */\nexport class ToastQueue<T> {\n private queue: QueuedToast<T>[] = [];\n private subscriptions: Set<() => void> = new Set();\n private maxVisibleToasts: number;\n private wrapUpdate?: (fn: () => void, action: ToastAction) => void;\n /** The currently visible toasts. */\n visibleToasts: QueuedToast<T>[] = [];\n\n constructor(options?: ToastStateProps) {\n this.maxVisibleToasts = options?.maxVisibleToasts ?? Infinity;\n this.wrapUpdate = options?.wrapUpdate;\n }\n\n private runWithWrapUpdate(fn: () => void, action: ToastAction): void {\n if (this.wrapUpdate) {\n this.wrapUpdate(fn, action);\n } else {\n fn();\n }\n }\n\n /** Subscribes to updates to the visible toasts. */\n subscribe(fn: () => void): () => void {\n this.subscriptions.add(fn);\n return () => this.subscriptions.delete(fn);\n }\n\n /** Adds a new toast to the queue. */\n add(content: T, options: ToastOptions = {}): string {\n let toastKey = '_' + Math.random().toString(36).slice(2);\n let toast: QueuedToast<T> = {\n ...options,\n content,\n key: toastKey,\n timer: options.timeout ? new Timer(() => this.close(toastKey), options.timeout) : undefined\n };\n\n this.queue.unshift(toast);\n\n this.updateVisibleToasts('add');\n return toastKey;\n }\n\n /**\n * Closes a toast.\n */\n close(key: string): void {\n let index = this.queue.findIndex(t => t.key === key);\n if (index >= 0) {\n this.queue[index].onClose?.();\n this.queue.splice(index, 1);\n }\n\n this.updateVisibleToasts('remove');\n }\n\n private updateVisibleToasts(action: ToastAction) {\n this.visibleToasts = this.queue.slice(0, this.maxVisibleToasts);\n\n this.runWithWrapUpdate(() => {\n for (let fn of this.subscriptions) {\n fn();\n }\n }, action);\n }\n\n /** Pauses the timers for all visible toasts. */\n pauseAll(): void {\n for (let toast of this.visibleToasts) {\n if (toast.timer) {\n toast.timer.pause();\n }\n }\n }\n\n /** Resumes the timers for all visible toasts. */\n resumeAll(): void {\n for (let toast of this.visibleToasts) {\n if (toast.timer) {\n toast.timer.resume();\n }\n }\n }\n\n clear(): void {\n this.queue = [];\n this.updateVisibleToasts('clear');\n }\n}\n\nclass Timer {\n private timerId;\n private startTime: number | null = null;\n private remaining: number;\n private callback: () => void;\n\n constructor(callback: () => void, delay: number) {\n this.remaining = delay;\n this.callback = callback;\n }\n\n reset(delay: number): void {\n this.remaining = delay;\n this.resume();\n }\n\n pause(): void {\n if (this.timerId == null) {\n return;\n }\n\n clearTimeout(this.timerId);\n this.timerId = null;\n this.remaining -= Date.now() - this.startTime!;\n }\n\n resume(): void {\n if (this.remaining <= 0) {\n return;\n }\n\n this.startTime = Date.now();\n this.timerId = setTimeout(() => {\n this.timerId = null;\n this.remaining = 0;\n this.callback();\n }, this.remaining);\n }\n}\n"],"names":[],"version":3,"file":"useToastState.mjs.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAiDM,SAAS,0CAAiB,QAAyB,CAAC,CAAC;IAC1D,IAAI,oBAAC,mBAAmB,eAAG,UAAU,EAAC,GAAG;IACzC,IAAI,QAAQ,CAAA,GAAA,cAAM,EAChB,IAAM,IAAI,0CAAc;8BAAC;wBAAkB;QAAU,IACrD;QAAC;QAAkB;KAAW;IAEhC,OAAO,0CAAc;AACvB;AAKO,SAAS,0CAAiB,KAAoB;IACnD,IAAI,YAAY,CAAA,GAAA,kBAAU,EAAE,CAAA,KAAM,MAAM,SAAS,CAAC,KAAK;QAAC;KAAM;IAC9D,IAAI,cAAc,CAAA,GAAA,kBAAU,EAAE,IAAM,MAAM,aAAa,EAAE;QAAC;KAAM;IAChE,IAAI,gBAAgB,CAAA,GAAA,2BAAmB,EAAE,WAAW,aAAa;IAEjE,OAAO;uBACL;QACA,KAAK,CAAC,SAAS,UAAY,MAAM,GAAG,CAAC,SAAS;QAC9C,OAAO,CAAA,MAAO,MAAM,KAAK,CAAC;QAC1B,UAAU,IAAM,MAAM,QAAQ;QAC9B,WAAW,IAAM,MAAM,SAAS;IAClC;AACF;AAKO,MAAM;IAQX,YAAY,OAAyB,CAAE;aAP/B,QAA0B,EAAE;aAC5B,gBAAiC,IAAI;QAG7C,kCAAkC,QAClC,gBAAkC,EAAE;QAGlC,IAAI,CAAC,gBAAgB,GAAG,SAAS,oBAAoB;QACrD,IAAI,CAAC,UAAU,GAAG,SAAS;IAC7B;IAEQ,kBAAkB,EAAc,EAAE,MAAmB,EAAQ;QACnE,IAAI,IAAI,CAAC,UAA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+CAA+C,GAC/C,YAAkB;QAChB,KAAK,IAAI,SAAS,IAAI,CAAC,aAAa,CAClC,IAAI,MAAM,KAAK,EACb,MAAM,KAAK,CAAC,MAAM;IAGxB;IAEA,QAAc;QACZ,IAAI,CAAC,KAAK,GAAG,EAAE;QACf,IAAI,CAAC,mBAAmB,CAAC;IAC3B;AACF;AAEA,MAAM;IAMJ,YAAY,QAAoB,EAAE,KAAa,CAAE;aAJzC,YAA2B;QAKjC,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,CAAC,QAAQ,GAAG;IAClB;IAEA,MAAM,KAAa,EAAQ;QACzB,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,CAAC,MAAM;IACb;IAEA,QAAc;QACZ,IAAI,IAAI,CAAC,OAAO,IAAI,MAClB;QAGF,aAAa,IAAI,CAAC,OAAO;QACzB,IAAI,CAAC,OAAO,GAAG;QACf,IAAI,CAAC,SAAS,IAAI,KAAK,GAAG,KAAK,IAAI,CAAC,SAAS;IAC/C;IAEA,SAAe;QACb,IAAI,IAAI,CAAC,SAAS,IAAI,GACpB;QAGF,IAAI,CAAC,SAAS,GAAG,KAAK,GAAG;QACzB,IAAI,CAAC,OAAO,GAAG,WAAW;YACxB,IAAI,CAAC,OAAO,GAAG;YACf,IAAI,CAAC,SAAS,GAAG;YACjB,IAAI,CAAC,QAAQ;QACf,GAAG,IAAI,CAAC,SAAS;IACnB;AACF","sources":["packages/react-stately/src/toast/useToastState.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, useMemo} from 'react';\n// Shim to support React 17 and below.\nimport {useSyncExternalStore} from 'use-sync-external-store/shim/index.js';\n\ntype ToastAction = 'add' | 'remove' | 'clear';\nexport interface ToastStateProps {\n /** The maximum number of toasts to display at a time. */\n maxVisibleToasts?: number;\n /** Function to wrap updates in (i.e. document.startViewTransition()). */\n wrapUpdate?: (fn: () => void, action: ToastAction) => void;\n}\n\nexport interface ToastOptions {\n /** Handler that is called when the toast is closed, either by the user or after a timeout. */\n onClose?: () => void;\n /** A timeout to automatically close the toast after, in milliseconds. */\n timeout?: number;\n}\n\nexport interface QueuedToast<T> extends ToastOptions {\n /** The content of the toast. */\n content: T;\n /** A unique key for the toast. */\n key: string;\n /** A timer for the toast, if a timeout was set. */\n timer?: Timer;\n}\n\nexport interface ToastState<T> {\n /** Adds a new toast to the queue. */\n add(content: T, options?: ToastOptions): string;\n /**\n * Closes a toast.\n */\n close(key: string): void;\n /** Pauses the timers for all visible toasts. */\n pauseAll(): void;\n /** Resumes the timers for all visible toasts. */\n resumeAll(): void;\n /** The visible toasts. */\n visibleToasts: QueuedToast<T>[];\n}\n\n/**\n * Provides state management for a toast queue. Toasts display brief, temporary notifications\n * of actions, errors, or other events in an application.\n */\nexport function useToastState<T>(props: ToastStateProps = {}): ToastState<T> {\n let {maxVisibleToasts = 1, wrapUpdate} = props;\n let queue = useMemo(\n () => new ToastQueue<T>({maxVisibleToasts, wrapUpdate}),\n [maxVisibleToasts, wrapUpdate]\n );\n return useToastQueue(queue);\n}\n\n/**\n * Subscribes to a provided toast queue and provides methods to update it.\n */\nexport function useToastQueue<T>(queue: ToastQueue<T>): ToastState<T> {\n let subscribe = useCallback(fn => queue.subscribe(fn), [queue]);\n let getSnapshot = useCallback(() => queue.visibleToasts, [queue]);\n let visibleToasts = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n return {\n visibleToasts,\n add: (content, options) => queue.add(content, options),\n close: key => queue.close(key),\n pauseAll: () => queue.pauseAll(),\n resumeAll: () => queue.resumeAll()\n };\n}\n\n/**\n * A ToastQueue manages the order of toasts.\n */\nexport class ToastQueue<T> {\n private queue: QueuedToast<T>[] = [];\n private subscriptions: Set<() => void> = new Set();\n private maxVisibleToasts: number;\n private wrapUpdate?: (fn: () => void, action: ToastAction) => void;\n /** The currently visible toasts. */\n visibleToasts: QueuedToast<T>[] = [];\n\n constructor(options?: ToastStateProps) {\n this.maxVisibleToasts = options?.maxVisibleToasts ?? Infinity;\n this.wrapUpdate = options?.wrapUpdate;\n }\n\n private runWithWrapUpdate(fn: () => void, action: ToastAction): void {\n if (this.wrapUpdate) {\n this.wrapUpdate(fn, action);\n } else {\n fn();\n }\n }\n\n /** Subscribes to updates to the visible toasts. */\n subscribe(fn: () => void): () => void {\n this.subscriptions.add(fn);\n return () => this.subscriptions.delete(fn);\n }\n\n /** Adds a new toast to the queue. */\n add(content: T, options: ToastOptions = {}): string {\n let toastKey = '_' + Math.random().toString(36).slice(2);\n let toast: QueuedToast<T> = {\n ...options,\n content,\n key: toastKey,\n timer: options.timeout ? new Timer(() => this.close(toastKey), options.timeout) : undefined\n };\n\n this.queue.unshift(toast);\n\n this.updateVisibleToasts('add');\n return toastKey;\n }\n\n /**\n * Closes a toast.\n */\n close(key: string): void {\n let index = this.queue.findIndex(t => t.key === key);\n if (index >= 0) {\n this.queue[index].onClose?.();\n this.queue.splice(index, 1);\n }\n\n this.updateVisibleToasts('remove');\n }\n\n private updateVisibleToasts(action: ToastAction) {\n this.visibleToasts = this.queue.slice(0, this.maxVisibleToasts);\n\n this.runWithWrapUpdate(() => {\n for (let fn of this.subscriptions) {\n fn();\n }\n }, action);\n }\n\n /** Pauses the timers for all visible toasts. */\n pauseAll(): void {\n for (let toast of this.visibleToasts) {\n if (toast.timer) {\n toast.timer.pause();\n }\n }\n }\n\n /** Resumes the timers for all visible toasts. */\n resumeAll(): void {\n for (let toast of this.visibleToasts) {\n if (toast.timer) {\n toast.timer.resume();\n }\n }\n }\n\n clear(): void {\n this.queue = [];\n this.updateVisibleToasts('clear');\n }\n}\n\nclass Timer {\n private timerId;\n private startTime: number | null = null;\n private remaining: number;\n private callback: () => void;\n\n constructor(callback: () => void, delay: number) {\n this.remaining = delay;\n this.callback = callback;\n }\n\n reset(delay: number): void {\n this.remaining = delay;\n this.resume();\n }\n\n pause(): void {\n if (this.timerId == null) {\n return;\n }\n\n clearTimeout(this.timerId);\n this.timerId = null;\n this.remaining -= Date.now() - this.startTime!;\n }\n\n resume(): void {\n if (this.remaining <= 0) {\n return;\n }\n\n this.startTime = Date.now();\n this.timerId = setTimeout(() => {\n this.timerId = null;\n this.remaining = 0;\n this.callback();\n }, this.remaining);\n }\n}\n"],"names":[],"version":3,"file":"useToastState.mjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAgDM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,iBAAC,gBAAgB,kCAAU,sBAAsB,cAAE,aAAa,OAAM,GAAG;IAC7E,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,4CAAiB,EACrD,CAAA,GAAA,oBAAM,EAAE,IAAM,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,WAAW;QAAC,MAAM,YAAY;KAAC,GAChG,CAAA,GAAA,oBAAM,EAAE,IAAM,MAAM,mBAAmB,GAAG,IAAI,IAAI,MAAM,mBAAmB,IAAI,IAAI,OAAO;QAAC,MAAM,mBAAmB;KAAC,GACrH,MAAM,iBAAiB;IAGzB,OAAO;uBACL;oBACA;sBACA;yBACA;QACA,WAAU,GAAG;YACX,IAAI;YACJ,IAAI,kBAAkB,YAAY;gBAChC,OAAO,IAAI,IAAI;gBACf,IAAI,KAAK,GAAG,CAAC,QAAS,CAAA,CAAC,0BAA0B,KAAK,IAAI,GAAG,CAAA,GAC3D,KAAK,MAAM,CAAC;qBAEZ,KAAK,GAAG,CAAC;YAEb,OACE,OAAO,IAAI,IAAI,aAAa,GAAG,CAAC,QAAQ,CAAC,yBAAyB,EAAE,GAAG;gBAAC;aAAI;YAG9E,gBAAgB;QAClB;QACA,aAAY,GAAG,EAAE,UAAU;YACzB,IAAI,eAAe,aAAa,GAAG,CAAC,MAClC,IAAI,CAAC,SAAS,CAAC;QAEnB;IACF;AACF","sources":["packages/react-stately/src/toggle/useToggleGroupState.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {Key} from '@react-types/shared';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo} from 'react';\n\nexport interface ToggleGroupProps {\n /**\n * Whether single or multiple selection is enabled.\n * @default 'single'\n */\n selectionMode?: 'single' | 'multiple',\n /** Whether the collection allows empty selection. */\n disallowEmptySelection?: boolean,\n /** The currently selected keys in the collection (controlled). */\n selectedKeys?: Iterable<Key>,\n /** The initial selected keys in the collection (uncontrolled). */\n defaultSelectedKeys?: Iterable<Key>,\n /** Handler that is called when the selection changes. */\n onSelectionChange?: (keys: Set<Key>) => void,\n /** Whether all items are disabled. */\n isDisabled?: boolean\n}\n\nexport interface ToggleGroupState {\n /** Whether single or multiple selection is enabled. */\n readonly selectionMode: 'single' | 'multiple',\n\n /** Whether all items are disabled. */\n readonly isDisabled: boolean,\n \n /** A set of keys for items that are selected. */\n readonly selectedKeys: Set<Key>,\n\n /** Toggles the selected state for an item by its key. */\n toggleKey(key: Key): void,\n\n /** Sets whether the given key is selected. */\n setSelected(key: Key, isSelected: boolean): void,\n\n /** Replaces the set of selected keys. */\n setSelectedKeys(keys: Set<Key>): void\n}\n\n/**\n * Manages state for a group of toggles.\n * It supports both single and multiple selected items.\n */\nexport function useToggleGroupState(props: ToggleGroupProps): ToggleGroupState {\n let {selectionMode = 'single', disallowEmptySelection, isDisabled = false} = props;\n let [selectedKeys, setSelectedKeys] = useControlledState(\n useMemo(() => props.selectedKeys ? new Set(props.selectedKeys) : undefined, [props.selectedKeys]),\n useMemo(() => props.defaultSelectedKeys ? new Set(props.defaultSelectedKeys) : new Set(), [props.defaultSelectedKeys]),\n props.onSelectionChange\n );\n\n return {\n selectionMode,\n isDisabled,\n selectedKeys,\n setSelectedKeys,\n toggleKey(key) {\n let keys: Set<Key>;\n if (selectionMode === 'multiple') {\n keys = new Set(selectedKeys);\n if (keys.has(key) && (!disallowEmptySelection || keys.size > 1)) {\n keys.delete(key);\n } else {\n keys.add(key);\n }\n } else {\n keys = new Set(selectedKeys.has(key) && !disallowEmptySelection ? [] : [key]);\n }\n \n setSelectedKeys(keys);\n },\n setSelected(key, isSelected) {\n if (isSelected !== selectedKeys.has(key)) {\n this.toggleKey(key);\n }\n }\n };\n}\n"],"names":[],"version":3,"file":"useToggleGroupState.cjs.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAiDM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,iBAAC,gBAAgB,kCAAU,sBAAsB,cAAE,aAAa,OAAM,GAAG;IAC7E,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,4CAAiB,EACrD,CAAA,GAAA,oBAAM,EACJ,IAAO,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,WAC1D;QAAC,MAAM,YAAY;KAAC,GAEtB,CAAA,GAAA,oBAAM,EACJ,IAAO,MAAM,mBAAmB,GAAG,IAAI,IAAI,MAAM,mBAAmB,IAAI,IAAI,OAC5E;QAAC,MAAM,mBAAmB;KAAC,GAE7B,MAAM,iBAAiB;IAGzB,OAAO;uBACL;oBACA;sBACA;yBACA;QACA,WAAU,GAAG;YACX,IAAI;YACJ,IAAI,kBAAkB,YAAY;gBAChC,OAAO,IAAI,IAAI;gBACf,IAAI,KAAK,GAAG,CAAC,QAAS,CAAA,CAAC,0BAA0B,KAAK,IAAI,GAAG,CAAA,GAC3D,KAAK,MAAM,CAAC;qBAEZ,KAAK,GAAG,CAAC;YAEb,OACE,OAAO,IAAI,IAAI,aAAa,GAAG,CAAC,QAAQ,CAAC,yBAAyB,EAAE,GAAG;gBAAC;aAAI;YAG9E,gBAAgB;QAClB;QACA,aAAY,GAAG,EAAE,UAAU;YACzB,IAAI,eAAe,aAAa,GAAG,CAAC,MAClC,IAAI,CAAC,SAAS,CAAC;QAEnB;IACF;AACF","sources":["packages/react-stately/src/toggle/useToggleGroupState.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {Key} from '@react-types/shared';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo} from 'react';\n\nexport interface ToggleGroupProps {\n /**\n * Whether single or multiple selection is enabled.\n *\n * @default 'single'\n */\n selectionMode?: 'single' | 'multiple';\n /** Whether the collection allows empty selection. */\n disallowEmptySelection?: boolean;\n /** The currently selected keys in the collection (controlled). */\n selectedKeys?: Iterable<Key>;\n /** The initial selected keys in the collection (uncontrolled). */\n defaultSelectedKeys?: Iterable<Key>;\n /** Handler that is called when the selection changes. */\n onSelectionChange?: (keys: Set<Key>) => void;\n /** Whether all items are disabled. */\n isDisabled?: boolean;\n}\n\nexport interface ToggleGroupState {\n /** Whether single or multiple selection is enabled. */\n readonly selectionMode: 'single' | 'multiple';\n\n /** Whether all items are disabled. */\n readonly isDisabled: boolean;\n\n /** A set of keys for items that are selected. */\n readonly selectedKeys: Set<Key>;\n\n /** Toggles the selected state for an item by its key. */\n toggleKey(key: Key): void;\n\n /** Sets whether the given key is selected. */\n setSelected(key: Key, isSelected: boolean): void;\n\n /** Replaces the set of selected keys. */\n setSelectedKeys(keys: Set<Key>): void;\n}\n\n/**\n * Manages state for a group of toggles.\n * It supports both single and multiple selected items.\n */\nexport function useToggleGroupState(props: ToggleGroupProps): ToggleGroupState {\n let {selectionMode = 'single', disallowEmptySelection, isDisabled = false} = props;\n let [selectedKeys, setSelectedKeys] = useControlledState(\n useMemo(\n () => (props.selectedKeys ? new Set(props.selectedKeys) : undefined),\n [props.selectedKeys]\n ),\n useMemo(\n () => (props.defaultSelectedKeys ? new Set(props.defaultSelectedKeys) : new Set()),\n [props.defaultSelectedKeys]\n ),\n props.onSelectionChange\n );\n\n return {\n selectionMode,\n isDisabled,\n selectedKeys,\n setSelectedKeys,\n toggleKey(key) {\n let keys: Set<Key>;\n if (selectionMode === 'multiple') {\n keys = new Set(selectedKeys);\n if (keys.has(key) && (!disallowEmptySelection || keys.size > 1)) {\n keys.delete(key);\n } else {\n keys.add(key);\n }\n } else {\n keys = new Set(selectedKeys.has(key) && !disallowEmptySelection ? [] : [key]);\n }\n\n setSelectedKeys(keys);\n },\n setSelected(key, isSelected) {\n if (isSelected !== selectedKeys.has(key)) {\n this.toggleKey(key);\n }\n }\n };\n}\n"],"names":[],"version":3,"file":"useToggleGroupState.cjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAgDM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,iBAAC,gBAAgB,kCAAU,sBAAsB,cAAE,aAAa,OAAM,GAAG;IAC7E,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,yCAAiB,EACrD,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,WAAW;QAAC,MAAM,YAAY;KAAC,GAChG,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,mBAAmB,GAAG,IAAI,IAAI,MAAM,mBAAmB,IAAI,IAAI,OAAO;QAAC,MAAM,mBAAmB;KAAC,GACrH,MAAM,iBAAiB;IAGzB,OAAO;uBACL;oBACA;sBACA;yBACA;QACA,WAAU,GAAG;YACX,IAAI;YACJ,IAAI,kBAAkB,YAAY;gBAChC,OAAO,IAAI,IAAI;gBACf,IAAI,KAAK,GAAG,CAAC,QAAS,CAAA,CAAC,0BAA0B,KAAK,IAAI,GAAG,CAAA,GAC3D,KAAK,MAAM,CAAC;qBAEZ,KAAK,GAAG,CAAC;YAEb,OACE,OAAO,IAAI,IAAI,aAAa,GAAG,CAAC,QAAQ,CAAC,yBAAyB,EAAE,GAAG;gBAAC;aAAI;YAG9E,gBAAgB;QAClB;QACA,aAAY,GAAG,EAAE,UAAU;YACzB,IAAI,eAAe,aAAa,GAAG,CAAC,MAClC,IAAI,CAAC,SAAS,CAAC;QAEnB;IACF;AACF","sources":["packages/react-stately/src/toggle/useToggleGroupState.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {Key} from '@react-types/shared';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo} from 'react';\n\nexport interface ToggleGroupProps {\n /**\n * Whether single or multiple selection is enabled.\n * @default 'single'\n */\n selectionMode?: 'single' | 'multiple',\n /** Whether the collection allows empty selection. */\n disallowEmptySelection?: boolean,\n /** The currently selected keys in the collection (controlled). */\n selectedKeys?: Iterable<Key>,\n /** The initial selected keys in the collection (uncontrolled). */\n defaultSelectedKeys?: Iterable<Key>,\n /** Handler that is called when the selection changes. */\n onSelectionChange?: (keys: Set<Key>) => void,\n /** Whether all items are disabled. */\n isDisabled?: boolean\n}\n\nexport interface ToggleGroupState {\n /** Whether single or multiple selection is enabled. */\n readonly selectionMode: 'single' | 'multiple',\n\n /** Whether all items are disabled. */\n readonly isDisabled: boolean,\n \n /** A set of keys for items that are selected. */\n readonly selectedKeys: Set<Key>,\n\n /** Toggles the selected state for an item by its key. */\n toggleKey(key: Key): void,\n\n /** Sets whether the given key is selected. */\n setSelected(key: Key, isSelected: boolean): void,\n\n /** Replaces the set of selected keys. */\n setSelectedKeys(keys: Set<Key>): void\n}\n\n/**\n * Manages state for a group of toggles.\n * It supports both single and multiple selected items.\n */\nexport function useToggleGroupState(props: ToggleGroupProps): ToggleGroupState {\n let {selectionMode = 'single', disallowEmptySelection, isDisabled = false} = props;\n let [selectedKeys, setSelectedKeys] = useControlledState(\n useMemo(() => props.selectedKeys ? new Set(props.selectedKeys) : undefined, [props.selectedKeys]),\n useMemo(() => props.defaultSelectedKeys ? new Set(props.defaultSelectedKeys) : new Set(), [props.defaultSelectedKeys]),\n props.onSelectionChange\n );\n\n return {\n selectionMode,\n isDisabled,\n selectedKeys,\n setSelectedKeys,\n toggleKey(key) {\n let keys: Set<Key>;\n if (selectionMode === 'multiple') {\n keys = new Set(selectedKeys);\n if (keys.has(key) && (!disallowEmptySelection || keys.size > 1)) {\n keys.delete(key);\n } else {\n keys.add(key);\n }\n } else {\n keys = new Set(selectedKeys.has(key) && !disallowEmptySelection ? [] : [key]);\n }\n \n setSelectedKeys(keys);\n },\n setSelected(key, isSelected) {\n if (isSelected !== selectedKeys.has(key)) {\n this.toggleKey(key);\n }\n }\n };\n}\n"],"names":[],"version":3,"file":"useToggleGroupState.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAiDM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,iBAAC,gBAAgB,kCAAU,sBAAsB,cAAE,aAAa,OAAM,GAAG;IAC7E,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,yCAAiB,EACrD,CAAA,GAAA,cAAM,EACJ,IAAO,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,WAC1D;QAAC,MAAM,YAAY;KAAC,GAEtB,CAAA,GAAA,cAAM,EACJ,IAAO,MAAM,mBAAmB,GAAG,IAAI,IAAI,MAAM,mBAAmB,IAAI,IAAI,OAC5E;QAAC,MAAM,mBAAmB;KAAC,GAE7B,MAAM,iBAAiB;IAGzB,OAAO;uBACL;oBACA;sBACA;yBACA;QACA,WAAU,GAAG;YACX,IAAI;YACJ,IAAI,kBAAkB,YAAY;gBAChC,OAAO,IAAI,IAAI;gBACf,IAAI,KAAK,GAAG,CAAC,QAAS,CAAA,CAAC,0BAA0B,KAAK,IAAI,GAAG,CAAA,GAC3D,KAAK,MAAM,CAAC;qBAEZ,KAAK,GAAG,CAAC;YAEb,OACE,OAAO,IAAI,IAAI,aAAa,GAAG,CAAC,QAAQ,CAAC,yBAAyB,EAAE,GAAG;gBAAC;aAAI;YAG9E,gBAAgB;QAClB;QACA,aAAY,GAAG,EAAE,UAAU;YACzB,IAAI,eAAe,aAAa,GAAG,CAAC,MAClC,IAAI,CAAC,SAAS,CAAC;QAEnB;IACF;AACF","sources":["packages/react-stately/src/toggle/useToggleGroupState.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {Key} from '@react-types/shared';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo} from 'react';\n\nexport interface ToggleGroupProps {\n /**\n * Whether single or multiple selection is enabled.\n *\n * @default 'single'\n */\n selectionMode?: 'single' | 'multiple';\n /** Whether the collection allows empty selection. */\n disallowEmptySelection?: boolean;\n /** The currently selected keys in the collection (controlled). */\n selectedKeys?: Iterable<Key>;\n /** The initial selected keys in the collection (uncontrolled). */\n defaultSelectedKeys?: Iterable<Key>;\n /** Handler that is called when the selection changes. */\n onSelectionChange?: (keys: Set<Key>) => void;\n /** Whether all items are disabled. */\n isDisabled?: boolean;\n}\n\nexport interface ToggleGroupState {\n /** Whether single or multiple selection is enabled. */\n readonly selectionMode: 'single' | 'multiple';\n\n /** Whether all items are disabled. */\n readonly isDisabled: boolean;\n\n /** A set of keys for items that are selected. */\n readonly selectedKeys: Set<Key>;\n\n /** Toggles the selected state for an item by its key. */\n toggleKey(key: Key): void;\n\n /** Sets whether the given key is selected. */\n setSelected(key: Key, isSelected: boolean): void;\n\n /** Replaces the set of selected keys. */\n setSelectedKeys(keys: Set<Key>): void;\n}\n\n/**\n * Manages state for a group of toggles.\n * It supports both single and multiple selected items.\n */\nexport function useToggleGroupState(props: ToggleGroupProps): ToggleGroupState {\n let {selectionMode = 'single', disallowEmptySelection, isDisabled = false} = props;\n let [selectedKeys, setSelectedKeys] = useControlledState(\n useMemo(\n () => (props.selectedKeys ? new Set(props.selectedKeys) : undefined),\n [props.selectedKeys]\n ),\n useMemo(\n () => (props.defaultSelectedKeys ? new Set(props.defaultSelectedKeys) : new Set()),\n [props.defaultSelectedKeys]\n ),\n props.onSelectionChange\n );\n\n return {\n selectionMode,\n isDisabled,\n selectedKeys,\n setSelectedKeys,\n toggleKey(key) {\n let keys: Set<Key>;\n if (selectionMode === 'multiple') {\n keys = new Set(selectedKeys);\n if (keys.has(key) && (!disallowEmptySelection || keys.size > 1)) {\n keys.delete(key);\n } else {\n keys.add(key);\n }\n } else {\n keys = new Set(selectedKeys.has(key) && !disallowEmptySelection ? [] : [key]);\n }\n\n setSelectedKeys(keys);\n },\n setSelected(key, isSelected) {\n if (isSelected !== selectedKeys.has(key)) {\n this.toggleKey(key);\n }\n }\n };\n}\n"],"names":[],"version":3,"file":"useToggleGroupState.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAgDM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,iBAAC,gBAAgB,kCAAU,sBAAsB,cAAE,aAAa,OAAM,GAAG;IAC7E,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,yCAAiB,EACrD,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,WAAW;QAAC,MAAM,YAAY;KAAC,GAChG,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,mBAAmB,GAAG,IAAI,IAAI,MAAM,mBAAmB,IAAI,IAAI,OAAO;QAAC,MAAM,mBAAmB;KAAC,GACrH,MAAM,iBAAiB;IAGzB,OAAO;uBACL;oBACA;sBACA;yBACA;QACA,WAAU,GAAG;YACX,IAAI;YACJ,IAAI,kBAAkB,YAAY;gBAChC,OAAO,IAAI,IAAI;gBACf,IAAI,KAAK,GAAG,CAAC,QAAS,CAAA,CAAC,0BAA0B,KAAK,IAAI,GAAG,CAAA,GAC3D,KAAK,MAAM,CAAC;qBAEZ,KAAK,GAAG,CAAC;YAEb,OACE,OAAO,IAAI,IAAI,aAAa,GAAG,CAAC,QAAQ,CAAC,yBAAyB,EAAE,GAAG;gBAAC;aAAI;YAG9E,gBAAgB;QAClB;QACA,aAAY,GAAG,EAAE,UAAU;YACzB,IAAI,eAAe,aAAa,GAAG,CAAC,MAClC,IAAI,CAAC,SAAS,CAAC;QAEnB;IACF;AACF","sources":["packages/react-stately/src/toggle/useToggleGroupState.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {Key} from '@react-types/shared';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo} from 'react';\n\nexport interface ToggleGroupProps {\n /**\n * Whether single or multiple selection is enabled.\n * @default 'single'\n */\n selectionMode?: 'single' | 'multiple',\n /** Whether the collection allows empty selection. */\n disallowEmptySelection?: boolean,\n /** The currently selected keys in the collection (controlled). */\n selectedKeys?: Iterable<Key>,\n /** The initial selected keys in the collection (uncontrolled). */\n defaultSelectedKeys?: Iterable<Key>,\n /** Handler that is called when the selection changes. */\n onSelectionChange?: (keys: Set<Key>) => void,\n /** Whether all items are disabled. */\n isDisabled?: boolean\n}\n\nexport interface ToggleGroupState {\n /** Whether single or multiple selection is enabled. */\n readonly selectionMode: 'single' | 'multiple',\n\n /** Whether all items are disabled. */\n readonly isDisabled: boolean,\n \n /** A set of keys for items that are selected. */\n readonly selectedKeys: Set<Key>,\n\n /** Toggles the selected state for an item by its key. */\n toggleKey(key: Key): void,\n\n /** Sets whether the given key is selected. */\n setSelected(key: Key, isSelected: boolean): void,\n\n /** Replaces the set of selected keys. */\n setSelectedKeys(keys: Set<Key>): void\n}\n\n/**\n * Manages state for a group of toggles.\n * It supports both single and multiple selected items.\n */\nexport function useToggleGroupState(props: ToggleGroupProps): ToggleGroupState {\n let {selectionMode = 'single', disallowEmptySelection, isDisabled = false} = props;\n let [selectedKeys, setSelectedKeys] = useControlledState(\n useMemo(() => props.selectedKeys ? new Set(props.selectedKeys) : undefined, [props.selectedKeys]),\n useMemo(() => props.defaultSelectedKeys ? new Set(props.defaultSelectedKeys) : new Set(), [props.defaultSelectedKeys]),\n props.onSelectionChange\n );\n\n return {\n selectionMode,\n isDisabled,\n selectedKeys,\n setSelectedKeys,\n toggleKey(key) {\n let keys: Set<Key>;\n if (selectionMode === 'multiple') {\n keys = new Set(selectedKeys);\n if (keys.has(key) && (!disallowEmptySelection || keys.size > 1)) {\n keys.delete(key);\n } else {\n keys.add(key);\n }\n } else {\n keys = new Set(selectedKeys.has(key) && !disallowEmptySelection ? [] : [key]);\n }\n \n setSelectedKeys(keys);\n },\n setSelected(key, isSelected) {\n if (isSelected !== selectedKeys.has(key)) {\n this.toggleKey(key);\n }\n }\n };\n}\n"],"names":[],"version":3,"file":"useToggleGroupState.mjs.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAiDM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,iBAAC,gBAAgB,kCAAU,sBAAsB,cAAE,aAAa,OAAM,GAAG;IAC7E,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,yCAAiB,EACrD,CAAA,GAAA,cAAM,EACJ,IAAO,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,WAC1D;QAAC,MAAM,YAAY;KAAC,GAEtB,CAAA,GAAA,cAAM,EACJ,IAAO,MAAM,mBAAmB,GAAG,IAAI,IAAI,MAAM,mBAAmB,IAAI,IAAI,OAC5E;QAAC,MAAM,mBAAmB;KAAC,GAE7B,MAAM,iBAAiB;IAGzB,OAAO;uBACL;oBACA;sBACA;yBACA;QACA,WAAU,GAAG;YACX,IAAI;YACJ,IAAI,kBAAkB,YAAY;gBAChC,OAAO,IAAI,IAAI;gBACf,IAAI,KAAK,GAAG,CAAC,QAAS,CAAA,CAAC,0BAA0B,KAAK,IAAI,GAAG,CAAA,GAC3D,KAAK,MAAM,CAAC;qBAEZ,KAAK,GAAG,CAAC;YAEb,OACE,OAAO,IAAI,IAAI,aAAa,GAAG,CAAC,QAAQ,CAAC,yBAAyB,EAAE,GAAG;gBAAC;aAAI;YAG9E,gBAAgB;QAClB;QACA,aAAY,GAAG,EAAE,UAAU;YACzB,IAAI,eAAe,aAAa,GAAG,CAAC,MAClC,IAAI,CAAC,SAAS,CAAC;QAEnB;IACF;AACF","sources":["packages/react-stately/src/toggle/useToggleGroupState.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {Key} from '@react-types/shared';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo} from 'react';\n\nexport interface ToggleGroupProps {\n /**\n * Whether single or multiple selection is enabled.\n *\n * @default 'single'\n */\n selectionMode?: 'single' | 'multiple';\n /** Whether the collection allows empty selection. */\n disallowEmptySelection?: boolean;\n /** The currently selected keys in the collection (controlled). */\n selectedKeys?: Iterable<Key>;\n /** The initial selected keys in the collection (uncontrolled). */\n defaultSelectedKeys?: Iterable<Key>;\n /** Handler that is called when the selection changes. */\n onSelectionChange?: (keys: Set<Key>) => void;\n /** Whether all items are disabled. */\n isDisabled?: boolean;\n}\n\nexport interface ToggleGroupState {\n /** Whether single or multiple selection is enabled. */\n readonly selectionMode: 'single' | 'multiple';\n\n /** Whether all items are disabled. */\n readonly isDisabled: boolean;\n\n /** A set of keys for items that are selected. */\n readonly selectedKeys: Set<Key>;\n\n /** Toggles the selected state for an item by its key. */\n toggleKey(key: Key): void;\n\n /** Sets whether the given key is selected. */\n setSelected(key: Key, isSelected: boolean): void;\n\n /** Replaces the set of selected keys. */\n setSelectedKeys(keys: Set<Key>): void;\n}\n\n/**\n * Manages state for a group of toggles.\n * It supports both single and multiple selected items.\n */\nexport function useToggleGroupState(props: ToggleGroupProps): ToggleGroupState {\n let {selectionMode = 'single', disallowEmptySelection, isDisabled = false} = props;\n let [selectedKeys, setSelectedKeys] = useControlledState(\n useMemo(\n () => (props.selectedKeys ? new Set(props.selectedKeys) : undefined),\n [props.selectedKeys]\n ),\n useMemo(\n () => (props.defaultSelectedKeys ? new Set(props.defaultSelectedKeys) : new Set()),\n [props.defaultSelectedKeys]\n ),\n props.onSelectionChange\n );\n\n return {\n selectionMode,\n isDisabled,\n selectedKeys,\n setSelectedKeys,\n toggleKey(key) {\n let keys: Set<Key>;\n if (selectionMode === 'multiple') {\n keys = new Set(selectedKeys);\n if (keys.has(key) && (!disallowEmptySelection || keys.size > 1)) {\n keys.delete(key);\n } else {\n keys.add(key);\n }\n } else {\n keys = new Set(selectedKeys.has(key) && !disallowEmptySelection ? [] : [key]);\n }\n\n setSelectedKeys(keys);\n },\n setSelected(key, isSelected) {\n if (isSelected !== selectedKeys.has(key)) {\n this.toggleKey(key);\n }\n }\n };\n}\n"],"names":[],"version":3,"file":"useToggleGroupState.mjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAiDM,SAAS,0CAAe,QAA4B,CAAC,CAAC;IAC3D,IAAI,cAAC,UAAU,EAAC,GAAG;IAEnB,8EAA8E;IAC9E,+FAA+F;IAC/F,IAAI,CAAC,YAAY,YAAY,GAAG,CAAA,GAAA,4CAAiB,EAAE,MAAM,UAAU,EAAE,MAAM,eAAe,IAAI,OAAO,MAAM,QAAQ;IACnH,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,qBAAO,EAAE;IAE9B,SAAS,eAAe,KAAK;QAC3B,IAAI,CAAC,YACH,YAAY;IAEhB;IAEA,SAAS;QACP,IAAI,CAAC,YACH,YAAY,CAAC;IAEjB;IAEA,OAAO;oBACL;QACA,iBAAiB,MAAM,eAAe,IAAI;QAC1C,aAAa;QACb,QAAQ;IACV;AACF","sources":["packages/react-stately/src/toggle/useToggleState.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, InputBase, Validation} from '@react-types/shared';\nimport {ReactNode, useState} from 'react';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface ToggleStateOptions extends InputBase {\n /**\n * Whether the element should be selected (uncontrolled).\n */\n defaultSelected?: boolean,\n /**\n * Whether the element should be selected (controlled).\n */\n isSelected?: boolean,\n /**\n * Handler that is called when the element's selection state changes.\n */\n onChange?: (isSelected: boolean) => void\n}\n\nexport interface ToggleProps extends ToggleStateOptions, Validation<boolean>, FocusableProps {\n /**\n * The label for the element.\n */\n children?: ReactNode,\n /**\n * The value of the input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefvalue).\n */\n value?: string\n}\n\nexport interface ToggleState {\n /** Whether the toggle is selected. */\n readonly isSelected: boolean,\n\n /** Whether the toggle is selected by default. */\n readonly defaultSelected: boolean,\n\n /** Updates selection state. */\n setSelected(isSelected: boolean): void,\n\n /** Toggle the selection state. */\n toggle(): void\n}\n\n/**\n * Provides state management for toggle components like checkboxes and switches.\n */\nexport function useToggleState(props: ToggleStateOptions = {}): ToggleState {\n let {isReadOnly} = props;\n\n // have to provide an empty function so useControlledState doesn't throw a fit\n // can't use useControlledState's prop calling because we need the event object from the change\n let [isSelected, setSelected] = useControlledState(props.isSelected, props.defaultSelected || false, props.onChange);\n let [initialValue] = useState(isSelected);\n\n function updateSelected(value) {\n if (!isReadOnly) {\n setSelected(value);\n }\n }\n\n function toggleState() {\n if (!isReadOnly) {\n setSelected(!isSelected);\n }\n }\n\n return {\n isSelected,\n defaultSelected: props.defaultSelected ?? initialValue,\n setSelected: updateSelected,\n toggle: toggleState\n };\n}\n"],"names":[],"version":3,"file":"useToggleState.cjs.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAkDM,SAAS,0CAAe,QAA4B,CAAC,CAAC;IAC3D,IAAI,cAAC,UAAU,EAAC,GAAG;IAEnB,8EAA8E;IAC9E,+FAA+F;IAC/F,IAAI,CAAC,YAAY,YAAY,GAAG,CAAA,GAAA,4CAAiB,EAC/C,MAAM,UAAU,EAChB,MAAM,eAAe,IAAI,OACzB,MAAM,QAAQ;IAEhB,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,qBAAO,EAAE;IAE9B,SAAS,eAAe,KAAK;QAC3B,IAAI,CAAC,YACH,YAAY;IAEhB;IAEA,SAAS;QACP,IAAI,CAAC,YACH,YAAY,CAAC;IAEjB;IAEA,OAAO;oBACL;QACA,iBAAiB,MAAM,eAAe,IAAI;QAC1C,aAAa;QACb,QAAQ;IACV;AACF","sources":["packages/react-stately/src/toggle/useToggleState.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, InputBase, Validation} from '@react-types/shared';\nimport {ReactNode, useState} from 'react';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface ToggleStateOptions extends InputBase {\n /**\n * Whether the element should be selected (uncontrolled).\n */\n defaultSelected?: boolean;\n /**\n * Whether the element should be selected (controlled).\n */\n isSelected?: boolean;\n /**\n * Handler that is called when the element's selection state changes.\n */\n onChange?: (isSelected: boolean) => void;\n}\n\nexport interface ToggleProps extends ToggleStateOptions, Validation<boolean>, FocusableProps {\n /**\n * The label for the element.\n */\n children?: ReactNode;\n /**\n * The value of the input element, used when submitting an HTML form. See\n * [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefvalue).\n */\n value?: string;\n}\n\nexport interface ToggleState {\n /** Whether the toggle is selected. */\n readonly isSelected: boolean;\n\n /** Whether the toggle is selected by default. */\n readonly defaultSelected: boolean;\n\n /** Updates selection state. */\n setSelected(isSelected: boolean): void;\n\n /** Toggle the selection state. */\n toggle(): void;\n}\n\n/**\n * Provides state management for toggle components like checkboxes and switches.\n */\nexport function useToggleState(props: ToggleStateOptions = {}): ToggleState {\n let {isReadOnly} = props;\n\n // have to provide an empty function so useControlledState doesn't throw a fit\n // can't use useControlledState's prop calling because we need the event object from the change\n let [isSelected, setSelected] = useControlledState(\n props.isSelected,\n props.defaultSelected || false,\n props.onChange\n );\n let [initialValue] = useState(isSelected);\n\n function updateSelected(value) {\n if (!isReadOnly) {\n setSelected(value);\n }\n }\n\n function toggleState() {\n if (!isReadOnly) {\n setSelected(!isSelected);\n }\n }\n\n return {\n isSelected,\n defaultSelected: props.defaultSelected ?? initialValue,\n setSelected: updateSelected,\n toggle: toggleState\n };\n}\n"],"names":[],"version":3,"file":"useToggleState.cjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAiDM,SAAS,0CAAe,QAA4B,CAAC,CAAC;IAC3D,IAAI,cAAC,UAAU,EAAC,GAAG;IAEnB,8EAA8E;IAC9E,+FAA+F;IAC/F,IAAI,CAAC,YAAY,YAAY,GAAG,CAAA,GAAA,yCAAiB,EAAE,MAAM,UAAU,EAAE,MAAM,eAAe,IAAI,OAAO,MAAM,QAAQ;IACnH,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAE9B,SAAS,eAAe,KAAK;QAC3B,IAAI,CAAC,YACH,YAAY;IAEhB;IAEA,SAAS;QACP,IAAI,CAAC,YACH,YAAY,CAAC;IAEjB;QAImB;IAFnB,OAAO;oBACL;QACA,iBAAiB,CAAA,yBAAA,MAAM,eAAe,cAArB,oCAAA,yBAAyB;QAC1C,aAAa;QACb,QAAQ;IACV;AACF","sources":["packages/react-stately/src/toggle/useToggleState.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, InputBase, Validation} from '@react-types/shared';\nimport {ReactNode, useState} from 'react';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface ToggleStateOptions extends InputBase {\n /**\n * Whether the element should be selected (uncontrolled).\n */\n defaultSelected?: boolean,\n /**\n * Whether the element should be selected (controlled).\n */\n isSelected?: boolean,\n /**\n * Handler that is called when the element's selection state changes.\n */\n onChange?: (isSelected: boolean) => void\n}\n\nexport interface ToggleProps extends ToggleStateOptions, Validation<boolean>, FocusableProps {\n /**\n * The label for the element.\n */\n children?: ReactNode,\n /**\n * The value of the input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefvalue).\n */\n value?: string\n}\n\nexport interface ToggleState {\n /** Whether the toggle is selected. */\n readonly isSelected: boolean,\n\n /** Whether the toggle is selected by default. */\n readonly defaultSelected: boolean,\n\n /** Updates selection state. */\n setSelected(isSelected: boolean): void,\n\n /** Toggle the selection state. */\n toggle(): void\n}\n\n/**\n * Provides state management for toggle components like checkboxes and switches.\n */\nexport function useToggleState(props: ToggleStateOptions = {}): ToggleState {\n let {isReadOnly} = props;\n\n // have to provide an empty function so useControlledState doesn't throw a fit\n // can't use useControlledState's prop calling because we need the event object from the change\n let [isSelected, setSelected] = useControlledState(props.isSelected, props.defaultSelected || false, props.onChange);\n let [initialValue] = useState(isSelected);\n\n function updateSelected(value) {\n if (!isReadOnly) {\n setSelected(value);\n }\n }\n\n function toggleState() {\n if (!isReadOnly) {\n setSelected(!isSelected);\n }\n }\n\n return {\n isSelected,\n defaultSelected: props.defaultSelected ?? initialValue,\n setSelected: updateSelected,\n toggle: toggleState\n };\n}\n"],"names":[],"version":3,"file":"useToggleState.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAkDM,SAAS,0CAAe,QAA4B,CAAC,CAAC;IAC3D,IAAI,cAAC,UAAU,EAAC,GAAG;IAEnB,8EAA8E;IAC9E,+FAA+F;IAC/F,IAAI,CAAC,YAAY,YAAY,GAAG,CAAA,GAAA,yCAAiB,EAC/C,MAAM,UAAU,EAChB,MAAM,eAAe,IAAI,OACzB,MAAM,QAAQ;IAEhB,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAE9B,SAAS,eAAe,KAAK;QAC3B,IAAI,CAAC,YACH,YAAY;IAEhB;IAEA,SAAS;QACP,IAAI,CAAC,YACH,YAAY,CAAC;IAEjB;QAImB;IAFnB,OAAO;oBACL;QACA,iBAAiB,CAAA,yBAAA,MAAM,eAAe,cAArB,oCAAA,yBAAyB;QAC1C,aAAa;QACb,QAAQ;IACV;AACF","sources":["packages/react-stately/src/toggle/useToggleState.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, InputBase, Validation} from '@react-types/shared';\nimport {ReactNode, useState} from 'react';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface ToggleStateOptions extends InputBase {\n /**\n * Whether the element should be selected (uncontrolled).\n */\n defaultSelected?: boolean;\n /**\n * Whether the element should be selected (controlled).\n */\n isSelected?: boolean;\n /**\n * Handler that is called when the element's selection state changes.\n */\n onChange?: (isSelected: boolean) => void;\n}\n\nexport interface ToggleProps extends ToggleStateOptions, Validation<boolean>, FocusableProps {\n /**\n * The label for the element.\n */\n children?: ReactNode;\n /**\n * The value of the input element, used when submitting an HTML form. See\n * [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefvalue).\n */\n value?: string;\n}\n\nexport interface ToggleState {\n /** Whether the toggle is selected. */\n readonly isSelected: boolean;\n\n /** Whether the toggle is selected by default. */\n readonly defaultSelected: boolean;\n\n /** Updates selection state. */\n setSelected(isSelected: boolean): void;\n\n /** Toggle the selection state. */\n toggle(): void;\n}\n\n/**\n * Provides state management for toggle components like checkboxes and switches.\n */\nexport function useToggleState(props: ToggleStateOptions = {}): ToggleState {\n let {isReadOnly} = props;\n\n // have to provide an empty function so useControlledState doesn't throw a fit\n // can't use useControlledState's prop calling because we need the event object from the change\n let [isSelected, setSelected] = useControlledState(\n props.isSelected,\n props.defaultSelected || false,\n props.onChange\n );\n let [initialValue] = useState(isSelected);\n\n function updateSelected(value) {\n if (!isReadOnly) {\n setSelected(value);\n }\n }\n\n function toggleState() {\n if (!isReadOnly) {\n setSelected(!isSelected);\n }\n }\n\n return {\n isSelected,\n defaultSelected: props.defaultSelected ?? initialValue,\n setSelected: updateSelected,\n toggle: toggleState\n };\n}\n"],"names":[],"version":3,"file":"useToggleState.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAiDM,SAAS,0CAAe,QAA4B,CAAC,CAAC;IAC3D,IAAI,cAAC,UAAU,EAAC,GAAG;IAEnB,8EAA8E;IAC9E,+FAA+F;IAC/F,IAAI,CAAC,YAAY,YAAY,GAAG,CAAA,GAAA,yCAAiB,EAAE,MAAM,UAAU,EAAE,MAAM,eAAe,IAAI,OAAO,MAAM,QAAQ;IACnH,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAE9B,SAAS,eAAe,KAAK;QAC3B,IAAI,CAAC,YACH,YAAY;IAEhB;IAEA,SAAS;QACP,IAAI,CAAC,YACH,YAAY,CAAC;IAEjB;IAEA,OAAO;oBACL;QACA,iBAAiB,MAAM,eAAe,IAAI;QAC1C,aAAa;QACb,QAAQ;IACV;AACF","sources":["packages/react-stately/src/toggle/useToggleState.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, InputBase, Validation} from '@react-types/shared';\nimport {ReactNode, useState} from 'react';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface ToggleStateOptions extends InputBase {\n /**\n * Whether the element should be selected (uncontrolled).\n */\n defaultSelected?: boolean,\n /**\n * Whether the element should be selected (controlled).\n */\n isSelected?: boolean,\n /**\n * Handler that is called when the element's selection state changes.\n */\n onChange?: (isSelected: boolean) => void\n}\n\nexport interface ToggleProps extends ToggleStateOptions, Validation<boolean>, FocusableProps {\n /**\n * The label for the element.\n */\n children?: ReactNode,\n /**\n * The value of the input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefvalue).\n */\n value?: string\n}\n\nexport interface ToggleState {\n /** Whether the toggle is selected. */\n readonly isSelected: boolean,\n\n /** Whether the toggle is selected by default. */\n readonly defaultSelected: boolean,\n\n /** Updates selection state. */\n setSelected(isSelected: boolean): void,\n\n /** Toggle the selection state. */\n toggle(): void\n}\n\n/**\n * Provides state management for toggle components like checkboxes and switches.\n */\nexport function useToggleState(props: ToggleStateOptions = {}): ToggleState {\n let {isReadOnly} = props;\n\n // have to provide an empty function so useControlledState doesn't throw a fit\n // can't use useControlledState's prop calling because we need the event object from the change\n let [isSelected, setSelected] = useControlledState(props.isSelected, props.defaultSelected || false, props.onChange);\n let [initialValue] = useState(isSelected);\n\n function updateSelected(value) {\n if (!isReadOnly) {\n setSelected(value);\n }\n }\n\n function toggleState() {\n if (!isReadOnly) {\n setSelected(!isSelected);\n }\n }\n\n return {\n isSelected,\n defaultSelected: props.defaultSelected ?? initialValue,\n setSelected: updateSelected,\n toggle: toggleState\n };\n}\n"],"names":[],"version":3,"file":"useToggleState.mjs.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAkDM,SAAS,0CAAe,QAA4B,CAAC,CAAC;IAC3D,IAAI,cAAC,UAAU,EAAC,GAAG;IAEnB,8EAA8E;IAC9E,+FAA+F;IAC/F,IAAI,CAAC,YAAY,YAAY,GAAG,CAAA,GAAA,yCAAiB,EAC/C,MAAM,UAAU,EAChB,MAAM,eAAe,IAAI,OACzB,MAAM,QAAQ;IAEhB,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAE9B,SAAS,eAAe,KAAK;QAC3B,IAAI,CAAC,YACH,YAAY;IAEhB;IAEA,SAAS;QACP,IAAI,CAAC,YACH,YAAY,CAAC;IAEjB;IAEA,OAAO;oBACL;QACA,iBAAiB,MAAM,eAAe,IAAI;QAC1C,aAAa;QACb,QAAQ;IACV;AACF","sources":["packages/react-stately/src/toggle/useToggleState.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, InputBase, Validation} from '@react-types/shared';\nimport {ReactNode, useState} from 'react';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface ToggleStateOptions extends InputBase {\n /**\n * Whether the element should be selected (uncontrolled).\n */\n defaultSelected?: boolean;\n /**\n * Whether the element should be selected (controlled).\n */\n isSelected?: boolean;\n /**\n * Handler that is called when the element's selection state changes.\n */\n onChange?: (isSelected: boolean) => void;\n}\n\nexport interface ToggleProps extends ToggleStateOptions, Validation<boolean>, FocusableProps {\n /**\n * The label for the element.\n */\n children?: ReactNode;\n /**\n * The value of the input element, used when submitting an HTML form. See\n * [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefvalue).\n */\n value?: string;\n}\n\nexport interface ToggleState {\n /** Whether the toggle is selected. */\n readonly isSelected: boolean;\n\n /** Whether the toggle is selected by default. */\n readonly defaultSelected: boolean;\n\n /** Updates selection state. */\n setSelected(isSelected: boolean): void;\n\n /** Toggle the selection state. */\n toggle(): void;\n}\n\n/**\n * Provides state management for toggle components like checkboxes and switches.\n */\nexport function useToggleState(props: ToggleStateOptions = {}): ToggleState {\n let {isReadOnly} = props;\n\n // have to provide an empty function so useControlledState doesn't throw a fit\n // can't use useControlledState's prop calling because we need the event object from the change\n let [isSelected, setSelected] = useControlledState(\n props.isSelected,\n props.defaultSelected || false,\n props.onChange\n );\n let [initialValue] = useState(isSelected);\n\n function updateSelected(value) {\n if (!isReadOnly) {\n setSelected(value);\n }\n }\n\n function toggleState() {\n if (!isReadOnly) {\n setSelected(!isSelected);\n }\n }\n\n return {\n isSelected,\n defaultSelected: props.defaultSelected ?? initialValue,\n setSelected: updateSelected,\n toggle: toggleState\n };\n}\n"],"names":[],"version":3,"file":"useToggleState.mjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;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AAI,2CAAqB;YACvB,aAAa;YACb,4CAAsB;QACxB;QACA,IAAI,sCAAgB;YAClB,IAAI,6CACF,aAAa;YAEf,8CAAwB,WAAW;gBACjC,OAAO,8BAAQ,CAAC,GAAG;gBACnB,8CAAwB;gBACxB,uCAAiB;YACnB,GAAG,KAAK,GAAG,CAAC,wCAAkB;QAChC;IACF;IAEA,IAAI,gBAAgB;QAClB;QACA;QACA,IAAI,CAAC,UAAU,CAAC,sCAAgB;YAC9B,IAAI,2CACF,aAAa;YAGf,4CAAsB,WAAW;gBAC/B,4CAAsB;gBACtB,uCAAiB;gBACjB;YACF,GAAG;QACL,OAAO,IAAI,CAAC,QACV;IAEJ;IAEA,CAAA,GAAA,sBAAQ,EAAE;QACR,cAAc,OAAO,GAAG;IAC1B,GAAG;QAAC;KAAM;IAGV,CAAA,GAAA,sBAAQ,EAAE;QACR,OAAO;YACL,IAAI,aAAa,OAAO,EACtB,aAAa,aAAa,OAAO;YAEnC,IAAI,UAAU,8BAAQ,CAAC,GAAG;YAC1B,IAAI,SACF,OAAO,8BAAQ,CAAC,GAAG;QAEvB;IACF,GAAG;QAAC;KAAG;IAEP,OAAO;gBACL;QACA,MAAM,CAAC;YACL,IAAI,CAAC,aAAa,QAAQ,KAAK,CAAC,aAAa,OAAO,EAClD;iBAEA;QAEJ;QACA,OAAO;IACT;AACF","sources":["packages/react-stately/src/tooltip/useTooltipTriggerState.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 {OverlayTriggerProps, useOverlayTriggerState} from '../overlays/useOverlayTriggerState';\nimport {useEffect, useMemo, useRef} from 'react';\n\nexport interface TooltipTriggerProps extends OverlayTriggerProps {\n /**\n * Whether the tooltip should be disabled, independent from the trigger.\n */\n isDisabled?: boolean,\n\n /**\n * The delay time for the tooltip to show up. [See guidelines](https://spectrum.adobe.com/page/tooltip/#Immediate-or-delayed-appearance).\n * @default 1500\n */\n delay?: number,\n\n /**\n * The delay time for the tooltip to close. [See guidelines](https://spectrum.adobe.com/page/tooltip/#Warmup-and-cooldown).\n * @default 500\n */\n closeDelay?: number,\n\n /**\n * By default, opens for both focus and hover. Can be made to open only for focus.\n * @default 'hover'\n */\n trigger?: 'hover' | 'focus',\n\n /**\n * Whether the tooltip should close when the trigger is pressed.\n * @default true\n */\n shouldCloseOnPress?: boolean\n}\n\nconst TOOLTIP_DELAY = 1500; // this seems to be a 1.5 second delay, check with design\nconst TOOLTIP_COOLDOWN = 500;\n\nexport interface TooltipTriggerState {\n /** Whether the tooltip is currently showing. */\n isOpen: boolean,\n /**\n * Shows the tooltip. By default, the tooltip becomes visible after a delay\n * depending on a global warmup timer. The `immediate` option shows the\n * tooltip immediately instead.\n */\n open(immediate?: boolean): void,\n /** Hides the tooltip. */\n close(immediate?: boolean): void\n}\n\nlet tooltips = {};\nlet tooltipId = 0;\nlet globalWarmedUp = false;\nlet globalWarmUpTimeout: ReturnType<typeof setTimeout> | null = null;\nlet globalCooldownTimeout: ReturnType<typeof setTimeout> | null = null;\n\n/**\n * Manages state for a tooltip trigger. Tracks whether the tooltip is open, and provides\n * methods to toggle this state. Ensures only one tooltip is open at a time and controls\n * the delay for showing a tooltip.\n */\nexport function useTooltipTriggerState(props: TooltipTriggerProps = {}): TooltipTriggerState {\n let {delay = TOOLTIP_DELAY, closeDelay = TOOLTIP_COOLDOWN} = props;\n let {isOpen, open, close} = useOverlayTriggerState(props);\n let id = useMemo(() => `${++tooltipId}`, []);\n let closeTimeout = useRef<ReturnType<typeof setTimeout> | null>(null);\n let closeCallback = useRef<() => void>(close);\n\n let ensureTooltipEntry = () => {\n tooltips[id] = hideTooltip;\n };\n\n let closeOpenTooltips = () => {\n for (let hideTooltipId in tooltips) {\n if (hideTooltipId !== id) {\n tooltips[hideTooltipId](true);\n delete tooltips[hideTooltipId];\n }\n }\n };\n\n let showTooltip = () => {\n if (closeTimeout.current) {\n clearTimeout(closeTimeout.current);\n }\n closeTimeout.current = null;\n closeOpenTooltips();\n ensureTooltipEntry();\n globalWarmedUp = true;\n open();\n if (globalWarmUpTimeout) {\n clearTimeout(globalWarmUpTimeout);\n globalWarmUpTimeout = null;\n }\n if (globalCooldownTimeout) {\n clearTimeout(globalCooldownTimeout);\n globalCooldownTimeout = null;\n }\n };\n\n let hideTooltip = (immediate?: boolean) => {\n if (immediate || closeDelay <= 0) {\n if (closeTimeout.current) {\n clearTimeout(closeTimeout.current);\n }\n closeTimeout.current = null;\n closeCallback.current();\n } else if (!closeTimeout.current) {\n closeTimeout.current = setTimeout(() => {\n closeTimeout.current = null;\n closeCallback.current();\n }, closeDelay);\n }\n\n if (globalWarmUpTimeout) {\n clearTimeout(globalWarmUpTimeout);\n globalWarmUpTimeout = null;\n }\n if (globalWarmedUp) {\n if (globalCooldownTimeout) {\n clearTimeout(globalCooldownTimeout);\n }\n globalCooldownTimeout = setTimeout(() => {\n delete tooltips[id];\n globalCooldownTimeout = null;\n globalWarmedUp = false;\n }, Math.max(TOOLTIP_COOLDOWN, closeDelay));\n }\n };\n\n let warmupTooltip = () => {\n closeOpenTooltips();\n ensureTooltipEntry();\n if (!isOpen && !globalWarmedUp) {\n if (globalWarmUpTimeout) {\n clearTimeout(globalWarmUpTimeout);\n }\n\n globalWarmUpTimeout = setTimeout(() => {\n globalWarmUpTimeout = null;\n globalWarmedUp = true;\n showTooltip();\n }, delay);\n } else if (!isOpen) {\n showTooltip();\n }\n };\n\n useEffect(() => {\n closeCallback.current = close;\n }, [close]);\n\n\n useEffect(() => {\n return () => {\n if (closeTimeout.current) {\n clearTimeout(closeTimeout.current);\n }\n let tooltip = tooltips[id];\n if (tooltip) {\n delete tooltips[id];\n }\n };\n }, [id]);\n\n return {\n isOpen,\n open: (immediate) => {\n if (!immediate && delay > 0 && !closeTimeout.current) {\n warmupTooltip();\n } else {\n showTooltip();\n }\n },\n close: hideTooltip\n };\n}\n"],"names":[],"version":3,"file":"useTooltipTriggerState.cjs.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AA0CD,MAAM,sCAAgB,MAAM,yDAAyD;AACrF,MAAM,yCAAmB;AAezB,IAAI,iCAAW,CAAC;AAChB,IAAI,kCAAY;AAChB,IAAI,uCAAiB;AACrB,IAAI,4CAA4D;AAChE,IAAI,8CAA8D;AAO3D,SAAS,0CAAuB,QAA6B,CAAC,CAAC;IACpE,IAAI,SAAC,QAAQ,iDAAe,aAAa,wCAAiB,GAAG;IAC7D,IAAI,UAAC,MAAM,QAAE,IAAI,SAAE,KAAK,EAAC,GAAG,CAAA,GAAA,gDAAqB,EAAE;IACnD,IAAI,KAAK,CAAA,GAAA,oBAAM,EAAE,IAAM,GAAG,EAAE,iCAAW,EAAE,EAAE;IAC3C,IAAI,eAAe,CAAA,GAAA,mBAAK,EAAwC;IAChE,IAAI,gBAAgB,CAAA,GAAA,mBAAK,EAAc;IAEvC,IAAI,qBAAqB;QACvB,8BAAQ,CAAC,GAAG,GAAG;IACjB;IAEA,IAAI,oBAAoB;QACtB,IAAK,IAAI,iBAAiB,+BACxB,IAAI,kBAAkB,IAAI;YACxB,8BAAQ,CAAC,cAAc,CAAC;YACxB,OAAO,8BAAQ,CAAC,cAAc;QAChC;IAEJ;IAEA,IAAI,cAAc;QAChB,IAAI,aAAa,OAAO,EACtB,aAAa,aAAa,OAAO;QAEnC,aAAa,OAAO,GAAG;QACvB;QACA;QACA,uCAAiB;QACjB;QACA,IAAI,2CAAqB;YACvB,aAAa;YACb,4CAAsB;QACxB;QACA,IAAI,6CAAuB;YACzB,aAAa;YACb,8CAAwB;QAC1B;IACF;IAEA,IAAI,cAAc,CAAC;QACjB,IAAI,aAAa,cAAc,GAAG;YAChC,IAAI,aAAa,OAAO,EACtB,aAAa,aAAa,OAAO;YAEnC,aAAa,OAAO,GAAG;YACvB,cAAc,OAAO;QACvB,OAAO,IAAI,CAAC,aAAa,OAAO,EAC9B,aAAa,OAAO,GAAG,WAAW;YAChC,aAAa,OAAO,GAAG;YACvB,cAAc,OAAO;QACvB,GAAG;QAGL,IAAI,2CAAqB;YACvB,aAAa;YACb,4CAAsB;QACxB;QACA,IAAI,sCAAgB;YAClB,IAAI,6CACF,aAAa;YAEf,8CAAwB,WACtB;gBACE,OAAO,8BAAQ,CAAC,GAAG;gBACnB,8CAAwB;gBACxB,uCAAiB;YACnB,GACA,KAAK,GAAG,CAAC,wCAAkB;QAE/B;IACF;IAEA,IAAI,gBAAgB;QAClB;QACA;QACA,IAAI,CAAC,UAAU,CAAC,sCAAgB;YAC9B,IAAI,2CACF,aAAa;YAGf,4CAAsB,WAAW;gBAC/B,4CAAsB;gBACtB,uCAAiB;gBACjB;YACF,GAAG;QACL,OAAO,IAAI,CAAC,QACV;IAEJ;IAEA,CAAA,GAAA,sBAAQ,EAAE;QACR,cAAc,OAAO,GAAG;IAC1B,GAAG;QAAC;KAAM;IAEV,CAAA,GAAA,sBAAQ,EAAE;QACR,OAAO;YACL,IAAI,aAAa,OAAO,EACtB,aAAa,aAAa,OAAO;YAEnC,IAAI,UAAU,8BAAQ,CAAC,GAAG;YAC1B,IAAI,SACF,OAAO,8BAAQ,CAAC,GAAG;QAEvB;IACF,GAAG;QAAC;KAAG;IAEP,OAAO;gBACL;QACA,MAAM,CAAA;YACJ,IAAI,CAAC,aAAa,QAAQ,KAAK,CAAC,aAAa,OAAO,EAClD;iBAEA;QAEJ;QACA,OAAO;IACT;AACF","sources":["packages/react-stately/src/tooltip/useTooltipTriggerState.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 {OverlayTriggerProps, useOverlayTriggerState} from '../overlays/useOverlayTriggerState';\nimport {useEffect, useMemo, useRef} from 'react';\n\nexport interface TooltipTriggerProps extends OverlayTriggerProps {\n /**\n * Whether the tooltip should be disabled, independent from the trigger.\n */\n isDisabled?: boolean;\n\n /**\n * The delay time for the tooltip to show up. [See\n * guidelines](https://spectrum.adobe.com/page/tooltip/#Immediate-or-delayed-appearance).\n *\n * @default 1500\n */\n delay?: number;\n\n /**\n * The delay time for the tooltip to close. [See\n * guidelines](https://spectrum.adobe.com/page/tooltip/#Warmup-and-cooldown).\n *\n * @default 500\n */\n closeDelay?: number;\n\n /**\n * By default, opens for both focus and hover. Can be made to open only for focus.\n *\n * @default 'hover'\n */\n trigger?: 'hover' | 'focus';\n\n /**\n * Whether the tooltip should close when the trigger is pressed.\n *\n * @default true\n */\n shouldCloseOnPress?: boolean;\n}\n\nconst TOOLTIP_DELAY = 1500; // this seems to be a 1.5 second delay, check with design\nconst TOOLTIP_COOLDOWN = 500;\n\nexport interface TooltipTriggerState {\n /** Whether the tooltip is currently showing. */\n isOpen: boolean;\n /**\n * Shows the tooltip. By default, the tooltip becomes visible after a delay\n * depending on a global warmup timer. The `immediate` option shows the\n * tooltip immediately instead.\n */\n open(immediate?: boolean): void;\n /** Hides the tooltip. */\n close(immediate?: boolean): void;\n}\n\nlet tooltips = {};\nlet tooltipId = 0;\nlet globalWarmedUp = false;\nlet globalWarmUpTimeout: ReturnType<typeof setTimeout> | null = null;\nlet globalCooldownTimeout: ReturnType<typeof setTimeout> | null = null;\n\n/**\n * Manages state for a tooltip trigger. Tracks whether the tooltip is open, and provides\n * methods to toggle this state. Ensures only one tooltip is open at a time and controls\n * the delay for showing a tooltip.\n */\nexport function useTooltipTriggerState(props: TooltipTriggerProps = {}): TooltipTriggerState {\n let {delay = TOOLTIP_DELAY, closeDelay = TOOLTIP_COOLDOWN} = props;\n let {isOpen, open, close} = useOverlayTriggerState(props);\n let id = useMemo(() => `${++tooltipId}`, []);\n let closeTimeout = useRef<ReturnType<typeof setTimeout> | null>(null);\n let closeCallback = useRef<() => void>(close);\n\n let ensureTooltipEntry = () => {\n tooltips[id] = hideTooltip;\n };\n\n let closeOpenTooltips = () => {\n for (let hideTooltipId in tooltips) {\n if (hideTooltipId !== id) {\n tooltips[hideTooltipId](true);\n delete tooltips[hideTooltipId];\n }\n }\n };\n\n let showTooltip = () => {\n if (closeTimeout.current) {\n clearTimeout(closeTimeout.current);\n }\n closeTimeout.current = null;\n closeOpenTooltips();\n ensureTooltipEntry();\n globalWarmedUp = true;\n open();\n if (globalWarmUpTimeout) {\n clearTimeout(globalWarmUpTimeout);\n globalWarmUpTimeout = null;\n }\n if (globalCooldownTimeout) {\n clearTimeout(globalCooldownTimeout);\n globalCooldownTimeout = null;\n }\n };\n\n let hideTooltip = (immediate?: boolean) => {\n if (immediate || closeDelay <= 0) {\n if (closeTimeout.current) {\n clearTimeout(closeTimeout.current);\n }\n closeTimeout.current = null;\n closeCallback.current();\n } else if (!closeTimeout.current) {\n closeTimeout.current = setTimeout(() => {\n closeTimeout.current = null;\n closeCallback.current();\n }, closeDelay);\n }\n\n if (globalWarmUpTimeout) {\n clearTimeout(globalWarmUpTimeout);\n globalWarmUpTimeout = null;\n }\n if (globalWarmedUp) {\n if (globalCooldownTimeout) {\n clearTimeout(globalCooldownTimeout);\n }\n globalCooldownTimeout = setTimeout(\n () => {\n delete tooltips[id];\n globalCooldownTimeout = null;\n globalWarmedUp = false;\n },\n Math.max(TOOLTIP_COOLDOWN, closeDelay)\n );\n }\n };\n\n let warmupTooltip = () => {\n closeOpenTooltips();\n ensureTooltipEntry();\n if (!isOpen && !globalWarmedUp) {\n if (globalWarmUpTimeout) {\n clearTimeout(globalWarmUpTimeout);\n }\n\n globalWarmUpTimeout = setTimeout(() => {\n globalWarmUpTimeout = null;\n globalWarmedUp = true;\n showTooltip();\n }, delay);\n } else if (!isOpen) {\n showTooltip();\n }\n };\n\n useEffect(() => {\n closeCallback.current = close;\n }, [close]);\n\n useEffect(() => {\n return () => {\n if (closeTimeout.current) {\n clearTimeout(closeTimeout.current);\n }\n let tooltip = tooltips[id];\n if (tooltip) {\n delete tooltips[id];\n }\n };\n }, [id]);\n\n return {\n isOpen,\n open: immediate => {\n if (!immediate && delay > 0 && !closeTimeout.current) {\n warmupTooltip();\n } else {\n showTooltip();\n }\n },\n close: hideTooltip\n };\n}\n"],"names":[],"version":3,"file":"useTooltipTriggerState.cjs.map"}