@octanejs/aria 0.0.40 → 0.0.41

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 (416) hide show
  1. package/LICENSE-APACHE-2.0 +201 -0
  2. package/README.md +20 -7
  3. package/UPSTREAM.md +108 -0
  4. package/package.json +10 -6
  5. package/src/calendar/useCalendar.tsx +36 -0
  6. package/src/calendar/useCalendarBase.tsx +142 -0
  7. package/src/calendar/useCalendarCell.tsx +416 -0
  8. package/src/calendar/useCalendarGrid.tsx +202 -0
  9. package/src/calendar/useCalendarHeading.tsx +85 -0
  10. package/src/calendar/useCalendarMonthPicker.tsx +92 -0
  11. package/src/calendar/useCalendarYearPicker.tsx +127 -0
  12. package/src/calendar/useRangeCalendar.tsx +121 -0
  13. package/src/calendar/utils.tsx +183 -0
  14. package/src/color/useColorArea.tsx +599 -0
  15. package/src/color/useColorAreaGradient.tsx +157 -0
  16. package/src/color/useColorChannelField.tsx +53 -0
  17. package/src/color/useColorField.tsx +170 -0
  18. package/src/color/useColorSlider.tsx +177 -0
  19. package/src/color/useColorSwatch.tsx +83 -0
  20. package/src/color/useColorWheel.tsx +401 -0
  21. package/src/compat/react.ts +111 -0
  22. package/src/components/Calendar.tsx +842 -0
  23. package/src/components/ColorArea.tsx +120 -0
  24. package/src/components/ColorField.tsx +304 -0
  25. package/src/components/ColorPicker.tsx +86 -0
  26. package/src/components/ColorSlider.tsx +144 -0
  27. package/src/components/ColorSwatch.tsx +72 -0
  28. package/src/components/ColorSwatchPicker.tsx +176 -0
  29. package/src/components/ColorThumb.tsx +140 -0
  30. package/src/components/ColorWheel.tsx +163 -0
  31. package/src/components/DateField.tsx +580 -0
  32. package/src/components/DatePicker.tsx +386 -0
  33. package/src/components/DropZone.tsx +181 -0
  34. package/src/components/FileTrigger.tsx +96 -0
  35. package/src/components/GridLayout.tsx +33 -0
  36. package/src/components/HiddenDateInput.tsx +169 -0
  37. package/src/components/TableLayout.tsx +39 -0
  38. package/src/components/Toast.tsx +336 -0
  39. package/src/components/Virtualizer.tsx +219 -0
  40. package/src/components/index.ts +257 -7
  41. package/src/components/useDragAndDrop.tsx +221 -0
  42. package/src/components/utils.ts +12 -89
  43. package/src/datepicker/useDateField.tsx +272 -0
  44. package/src/datepicker/useDatePicker.tsx +229 -0
  45. package/src/datepicker/useDatePickerGroup.tsx +147 -0
  46. package/src/datepicker/useDateRangePicker.tsx +288 -0
  47. package/src/datepicker/useDateSegment.tsx +439 -0
  48. package/src/datepicker/useDisplayNames.tsx +53 -0
  49. package/src/dnd/DragManager.tsx +718 -0
  50. package/src/dnd/DragPreview.tsx +100 -0
  51. package/src/dnd/DropTargetKeyboardNavigation.tsx +317 -0
  52. package/src/dnd/ListDropTargetDelegate.tsx +215 -0
  53. package/src/dnd/constants.tsx +93 -0
  54. package/src/dnd/useAutoScroll.tsx +116 -0
  55. package/src/dnd/useClipboard.tsx +160 -0
  56. package/src/dnd/useDrag.tsx +437 -0
  57. package/src/dnd/useDraggableCollection.tsx +35 -0
  58. package/src/dnd/useDraggableItem.tsx +168 -0
  59. package/src/dnd/useDrop.tsx +518 -0
  60. package/src/dnd/useDropIndicator.tsx +129 -0
  61. package/src/dnd/useDroppableCollection.tsx +808 -0
  62. package/src/dnd/useDroppableItem.tsx +99 -0
  63. package/src/dnd/useVirtualDrop.tsx +52 -0
  64. package/src/dnd/utils.tsx +430 -0
  65. package/src/intl/calendar/ar-AE.json +14 -0
  66. package/src/intl/calendar/bg-BG.json +14 -0
  67. package/src/intl/calendar/cs-CZ.json +14 -0
  68. package/src/intl/calendar/da-DK.json +14 -0
  69. package/src/intl/calendar/de-DE.json +14 -0
  70. package/src/intl/calendar/el-GR.json +14 -0
  71. package/src/intl/calendar/en-US.json +14 -0
  72. package/src/intl/calendar/es-ES.json +14 -0
  73. package/src/intl/calendar/et-EE.json +14 -0
  74. package/src/intl/calendar/fi-FI.json +14 -0
  75. package/src/intl/calendar/fr-FR.json +14 -0
  76. package/src/intl/calendar/he-IL.json +14 -0
  77. package/src/intl/calendar/hr-HR.json +14 -0
  78. package/src/intl/calendar/hu-HU.json +14 -0
  79. package/src/intl/calendar/index.ts +73 -0
  80. package/src/intl/calendar/it-IT.json +14 -0
  81. package/src/intl/calendar/ja-JP.json +14 -0
  82. package/src/intl/calendar/ko-KR.json +14 -0
  83. package/src/intl/calendar/lt-LT.json +14 -0
  84. package/src/intl/calendar/lv-LV.json +14 -0
  85. package/src/intl/calendar/nb-NO.json +14 -0
  86. package/src/intl/calendar/nl-NL.json +14 -0
  87. package/src/intl/calendar/pl-PL.json +14 -0
  88. package/src/intl/calendar/pt-BR.json +14 -0
  89. package/src/intl/calendar/pt-PT.json +14 -0
  90. package/src/intl/calendar/ro-RO.json +14 -0
  91. package/src/intl/calendar/ru-RU.json +14 -0
  92. package/src/intl/calendar/sk-SK.json +14 -0
  93. package/src/intl/calendar/sl-SI.json +14 -0
  94. package/src/intl/calendar/sr-SP.json +14 -0
  95. package/src/intl/calendar/sv-SE.json +14 -0
  96. package/src/intl/calendar/tr-TR.json +14 -0
  97. package/src/intl/calendar/uk-UA.json +14 -0
  98. package/src/intl/calendar/zh-CN.json +14 -0
  99. package/src/intl/calendar/zh-TW.json +14 -0
  100. package/src/intl/color/ar-AE.json +8 -0
  101. package/src/intl/color/bg-BG.json +8 -0
  102. package/src/intl/color/cs-CZ.json +8 -0
  103. package/src/intl/color/da-DK.json +8 -0
  104. package/src/intl/color/de-DE.json +8 -0
  105. package/src/intl/color/el-GR.json +8 -0
  106. package/src/intl/color/en-US.json +8 -0
  107. package/src/intl/color/es-ES.json +8 -0
  108. package/src/intl/color/et-EE.json +8 -0
  109. package/src/intl/color/fi-FI.json +8 -0
  110. package/src/intl/color/fr-FR.json +8 -0
  111. package/src/intl/color/he-IL.json +8 -0
  112. package/src/intl/color/hr-HR.json +8 -0
  113. package/src/intl/color/hu-HU.json +8 -0
  114. package/src/intl/color/index.ts +73 -0
  115. package/src/intl/color/it-IT.json +8 -0
  116. package/src/intl/color/ja-JP.json +8 -0
  117. package/src/intl/color/ko-KR.json +8 -0
  118. package/src/intl/color/lt-LT.json +8 -0
  119. package/src/intl/color/lv-LV.json +8 -0
  120. package/src/intl/color/nb-NO.json +8 -0
  121. package/src/intl/color/nl-NL.json +8 -0
  122. package/src/intl/color/pl-PL.json +8 -0
  123. package/src/intl/color/pt-BR.json +8 -0
  124. package/src/intl/color/pt-PT.json +8 -0
  125. package/src/intl/color/ro-RO.json +8 -0
  126. package/src/intl/color/ru-RU.json +8 -0
  127. package/src/intl/color/sk-SK.json +8 -0
  128. package/src/intl/color/sl-SI.json +8 -0
  129. package/src/intl/color/sr-SP.json +8 -0
  130. package/src/intl/color/sv-SE.json +8 -0
  131. package/src/intl/color/tr-TR.json +8 -0
  132. package/src/intl/color/uk-UA.json +8 -0
  133. package/src/intl/color/zh-CN.json +8 -0
  134. package/src/intl/color/zh-TW.json +8 -0
  135. package/src/intl/datepicker/ar-AE.json +18 -0
  136. package/src/intl/datepicker/bg-BG.json +18 -0
  137. package/src/intl/datepicker/cs-CZ.json +18 -0
  138. package/src/intl/datepicker/da-DK.json +18 -0
  139. package/src/intl/datepicker/de-DE.json +18 -0
  140. package/src/intl/datepicker/el-GR.json +18 -0
  141. package/src/intl/datepicker/en-US.json +18 -0
  142. package/src/intl/datepicker/es-ES.json +18 -0
  143. package/src/intl/datepicker/et-EE.json +18 -0
  144. package/src/intl/datepicker/fi-FI.json +18 -0
  145. package/src/intl/datepicker/fr-FR.json +18 -0
  146. package/src/intl/datepicker/he-IL.json +18 -0
  147. package/src/intl/datepicker/hr-HR.json +18 -0
  148. package/src/intl/datepicker/hu-HU.json +18 -0
  149. package/src/intl/datepicker/index.ts +73 -0
  150. package/src/intl/datepicker/it-IT.json +18 -0
  151. package/src/intl/datepicker/ja-JP.json +18 -0
  152. package/src/intl/datepicker/ko-KR.json +18 -0
  153. package/src/intl/datepicker/lt-LT.json +18 -0
  154. package/src/intl/datepicker/lv-LV.json +18 -0
  155. package/src/intl/datepicker/nb-NO.json +18 -0
  156. package/src/intl/datepicker/nl-NL.json +18 -0
  157. package/src/intl/datepicker/pl-PL.json +18 -0
  158. package/src/intl/datepicker/pt-BR.json +18 -0
  159. package/src/intl/datepicker/pt-PT.json +18 -0
  160. package/src/intl/datepicker/ro-RO.json +18 -0
  161. package/src/intl/datepicker/ru-RU.json +18 -0
  162. package/src/intl/datepicker/sk-SK.json +18 -0
  163. package/src/intl/datepicker/sl-SI.json +18 -0
  164. package/src/intl/datepicker/sr-SP.json +18 -0
  165. package/src/intl/datepicker/sv-SE.json +18 -0
  166. package/src/intl/datepicker/tr-TR.json +18 -0
  167. package/src/intl/datepicker/uk-UA.json +18 -0
  168. package/src/intl/datepicker/zh-CN.json +18 -0
  169. package/src/intl/datepicker/zh-TW.json +18 -0
  170. package/src/intl/dnd/ar-AE.json +29 -0
  171. package/src/intl/dnd/bg-BG.json +29 -0
  172. package/src/intl/dnd/cs-CZ.json +29 -0
  173. package/src/intl/dnd/da-DK.json +29 -0
  174. package/src/intl/dnd/de-DE.json +29 -0
  175. package/src/intl/dnd/el-GR.json +29 -0
  176. package/src/intl/dnd/en-US.json +29 -0
  177. package/src/intl/dnd/es-ES.json +29 -0
  178. package/src/intl/dnd/et-EE.json +29 -0
  179. package/src/intl/dnd/fi-FI.json +29 -0
  180. package/src/intl/dnd/fr-FR.json +29 -0
  181. package/src/intl/dnd/he-IL.json +29 -0
  182. package/src/intl/dnd/hr-HR.json +29 -0
  183. package/src/intl/dnd/hu-HU.json +29 -0
  184. package/src/intl/dnd/index.ts +73 -0
  185. package/src/intl/dnd/it-IT.json +29 -0
  186. package/src/intl/dnd/ja-JP.json +29 -0
  187. package/src/intl/dnd/ko-KR.json +29 -0
  188. package/src/intl/dnd/lt-LT.json +29 -0
  189. package/src/intl/dnd/lv-LV.json +29 -0
  190. package/src/intl/dnd/nb-NO.json +29 -0
  191. package/src/intl/dnd/nl-NL.json +29 -0
  192. package/src/intl/dnd/pl-PL.json +29 -0
  193. package/src/intl/dnd/pt-BR.json +29 -0
  194. package/src/intl/dnd/pt-PT.json +29 -0
  195. package/src/intl/dnd/ro-RO.json +29 -0
  196. package/src/intl/dnd/ru-RU.json +29 -0
  197. package/src/intl/dnd/sk-SK.json +29 -0
  198. package/src/intl/dnd/sl-SI.json +29 -0
  199. package/src/intl/dnd/sr-SP.json +29 -0
  200. package/src/intl/dnd/sv-SE.json +29 -0
  201. package/src/intl/dnd/tr-TR.json +29 -0
  202. package/src/intl/dnd/uk-UA.json +29 -0
  203. package/src/intl/dnd/zh-CN.json +29 -0
  204. package/src/intl/dnd/zh-TW.json +29 -0
  205. package/src/intl/react-aria-components/ar-AE.json +6 -0
  206. package/src/intl/react-aria-components/bg-BG.json +6 -0
  207. package/src/intl/react-aria-components/cs-CZ.json +6 -0
  208. package/src/intl/react-aria-components/da-DK.json +6 -0
  209. package/src/intl/react-aria-components/de-DE.json +6 -0
  210. package/src/intl/react-aria-components/el-GR.json +6 -0
  211. package/src/intl/react-aria-components/en-US.json +6 -0
  212. package/src/intl/react-aria-components/es-ES.json +6 -0
  213. package/src/intl/react-aria-components/et-EE.json +6 -0
  214. package/src/intl/react-aria-components/fi-FI.json +6 -0
  215. package/src/intl/react-aria-components/fr-FR.json +6 -0
  216. package/src/intl/react-aria-components/he-IL.json +6 -0
  217. package/src/intl/react-aria-components/hr-HR.json +6 -0
  218. package/src/intl/react-aria-components/hu-HU.json +6 -0
  219. package/src/intl/react-aria-components/index.ts +73 -0
  220. package/src/intl/react-aria-components/it-IT.json +6 -0
  221. package/src/intl/react-aria-components/ja-JP.json +6 -0
  222. package/src/intl/react-aria-components/ko-KR.json +6 -0
  223. package/src/intl/react-aria-components/lt-LT.json +6 -0
  224. package/src/intl/react-aria-components/lv-LV.json +6 -0
  225. package/src/intl/react-aria-components/nb-NO.json +6 -0
  226. package/src/intl/react-aria-components/nl-NL.json +6 -0
  227. package/src/intl/react-aria-components/pl-PL.json +6 -0
  228. package/src/intl/react-aria-components/pt-BR.json +6 -0
  229. package/src/intl/react-aria-components/pt-PT.json +6 -0
  230. package/src/intl/react-aria-components/ro-RO.json +6 -0
  231. package/src/intl/react-aria-components/ru-RU.json +6 -0
  232. package/src/intl/react-aria-components/sk-SK.json +6 -0
  233. package/src/intl/react-aria-components/sl-SI.json +6 -0
  234. package/src/intl/react-aria-components/sr-SP.json +6 -0
  235. package/src/intl/react-aria-components/sv-SE.json +6 -0
  236. package/src/intl/react-aria-components/tr-TR.json +6 -0
  237. package/src/intl/react-aria-components/uk-UA.json +6 -0
  238. package/src/intl/react-aria-components/zh-CN.json +6 -0
  239. package/src/intl/react-aria-components/zh-TW.json +6 -0
  240. package/src/intl/stately-color/ar-AE.json +39 -0
  241. package/src/intl/stately-color/bg-BG.json +39 -0
  242. package/src/intl/stately-color/cs-CZ.json +39 -0
  243. package/src/intl/stately-color/da-DK.json +39 -0
  244. package/src/intl/stately-color/de-DE.json +39 -0
  245. package/src/intl/stately-color/el-GR.json +39 -0
  246. package/src/intl/stately-color/en-US.json +39 -0
  247. package/src/intl/stately-color/es-ES.json +39 -0
  248. package/src/intl/stately-color/et-EE.json +39 -0
  249. package/src/intl/stately-color/fi-FI.json +39 -0
  250. package/src/intl/stately-color/fr-FR.json +39 -0
  251. package/src/intl/stately-color/he-IL.json +39 -0
  252. package/src/intl/stately-color/hr-HR.json +39 -0
  253. package/src/intl/stately-color/hu-HU.json +39 -0
  254. package/src/intl/stately-color/index.ts +73 -0
  255. package/src/intl/stately-color/it-IT.json +39 -0
  256. package/src/intl/stately-color/ja-JP.json +39 -0
  257. package/src/intl/stately-color/ko-KR.json +39 -0
  258. package/src/intl/stately-color/lt-LT.json +39 -0
  259. package/src/intl/stately-color/lv-LV.json +39 -0
  260. package/src/intl/stately-color/nb-NO.json +39 -0
  261. package/src/intl/stately-color/nl-NL.json +39 -0
  262. package/src/intl/stately-color/pl-PL.json +39 -0
  263. package/src/intl/stately-color/pt-BR.json +39 -0
  264. package/src/intl/stately-color/pt-PT.json +39 -0
  265. package/src/intl/stately-color/ro-RO.json +39 -0
  266. package/src/intl/stately-color/ru-RU.json +39 -0
  267. package/src/intl/stately-color/sk-SK.json +39 -0
  268. package/src/intl/stately-color/sl-SI.json +39 -0
  269. package/src/intl/stately-color/sr-SP.json +39 -0
  270. package/src/intl/stately-color/sv-SE.json +39 -0
  271. package/src/intl/stately-color/tr-TR.json +39 -0
  272. package/src/intl/stately-color/uk-UA.json +39 -0
  273. package/src/intl/stately-color/zh-CN.json +39 -0
  274. package/src/intl/stately-color/zh-TW.json +39 -0
  275. package/src/intl/toast/ar-AE.json +4 -0
  276. package/src/intl/toast/bg-BG.json +4 -0
  277. package/src/intl/toast/cs-CZ.json +4 -0
  278. package/src/intl/toast/da-DK.json +4 -0
  279. package/src/intl/toast/de-DE.json +4 -0
  280. package/src/intl/toast/el-GR.json +4 -0
  281. package/src/intl/toast/en-US.json +4 -0
  282. package/src/intl/toast/es-ES.json +4 -0
  283. package/src/intl/toast/et-EE.json +4 -0
  284. package/src/intl/toast/fi-FI.json +4 -0
  285. package/src/intl/toast/fr-FR.json +4 -0
  286. package/src/intl/toast/he-IL.json +4 -0
  287. package/src/intl/toast/hr-HR.json +4 -0
  288. package/src/intl/toast/hu-HU.json +4 -0
  289. package/src/intl/toast/index.ts +73 -0
  290. package/src/intl/toast/it-IT.json +4 -0
  291. package/src/intl/toast/ja-JP.json +4 -0
  292. package/src/intl/toast/ko-KR.json +4 -0
  293. package/src/intl/toast/lt-LT.json +4 -0
  294. package/src/intl/toast/lv-LV.json +4 -0
  295. package/src/intl/toast/nb-NO.json +4 -0
  296. package/src/intl/toast/nl-NL.json +4 -0
  297. package/src/intl/toast/pl-PL.json +4 -0
  298. package/src/intl/toast/pt-BR.json +4 -0
  299. package/src/intl/toast/pt-PT.json +4 -0
  300. package/src/intl/toast/ro-RO.json +4 -0
  301. package/src/intl/toast/ru-RU.json +4 -0
  302. package/src/intl/toast/sk-SK.json +4 -0
  303. package/src/intl/toast/sl-SI.json +4 -0
  304. package/src/intl/toast/sr-SP.json +4 -0
  305. package/src/intl/toast/sv-SE.json +4 -0
  306. package/src/intl/toast/tr-TR.json +4 -0
  307. package/src/intl/toast/uk-UA.json +4 -0
  308. package/src/intl/toast/zh-CN.json +4 -0
  309. package/src/intl/toast/zh-TW.json +4 -0
  310. package/src/landmark/useLandmark.tsx +569 -0
  311. package/src/stately/calendar/types.tsx +239 -0
  312. package/src/stately/calendar/useCalendarState.tsx +527 -0
  313. package/src/stately/calendar/useRangeCalendarState.tsx +323 -0
  314. package/src/stately/calendar/utils.tsx +175 -0
  315. package/src/stately/color/Color.tsx +889 -0
  316. package/src/stately/color/types.tsx +82 -0
  317. package/src/stately/color/useColor.tsx +30 -0
  318. package/src/stately/color/useColorAreaState.tsx +255 -0
  319. package/src/stately/color/useColorChannelFieldState.tsx +86 -0
  320. package/src/stately/color/useColorFieldState.tsx +220 -0
  321. package/src/stately/color/useColorPickerState.tsx +31 -0
  322. package/src/stately/color/useColorSliderState.tsx +143 -0
  323. package/src/stately/color/useColorWheelState.tsx +225 -0
  324. package/src/stately/data/useAsyncList.tsx +382 -0
  325. package/src/stately/data/useListData.tsx +447 -0
  326. package/src/stately/data/useTreeData.tsx +603 -0
  327. package/src/stately/datepicker/IncompleteDate.tsx +427 -0
  328. package/src/stately/datepicker/placeholders.tsx +116 -0
  329. package/src/stately/datepicker/types.tsx +169 -0
  330. package/src/stately/datepicker/useDateFieldState.tsx +564 -0
  331. package/src/stately/datepicker/useDatePickerState.tsx +244 -0
  332. package/src/stately/datepicker/useDateRangePickerState.tsx +397 -0
  333. package/src/stately/datepicker/useTimeFieldState.tsx +123 -0
  334. package/src/stately/datepicker/utils.tsx +316 -0
  335. package/src/stately/dnd/useDraggableCollectionState.tsx +191 -0
  336. package/src/stately/dnd/useDroppableCollectionState.tsx +288 -0
  337. package/src/stately/layout/GridLayout.tsx +449 -0
  338. package/src/stately/layout/ListLayout.tsx +872 -0
  339. package/src/stately/layout/TableLayout.tsx +793 -0
  340. package/src/stately/layout/WaterfallLayout.tsx +399 -0
  341. package/src/stately/toast/useToastState.tsx +219 -0
  342. package/src/stately/virtualizer/Layout.tsx +105 -0
  343. package/src/stately/virtualizer/LayoutInfo.tsx +127 -0
  344. package/src/stately/virtualizer/OverscanManager.tsx +56 -0
  345. package/src/stately/virtualizer/Point.tsx +47 -0
  346. package/src/stately/virtualizer/Rect.tsx +194 -0
  347. package/src/stately/virtualizer/ReusableView.tsx +101 -0
  348. package/src/stately/virtualizer/Size.tsx +48 -0
  349. package/src/stately/virtualizer/Virtualizer.tsx +408 -0
  350. package/src/stately/virtualizer/types.tsx +48 -0
  351. package/src/stately/virtualizer/useVirtualizerState.tsx +138 -0
  352. package/src/stately/virtualizer/utils.tsx +32 -0
  353. package/src/textfield/useTextField.ts +3 -0
  354. package/src/toast/useToast.tsx +105 -0
  355. package/src/toast/useToastRegion.tsx +223 -0
  356. package/src/upstream-exports/react-aria/I18nProvider.tsx +17 -0
  357. package/src/upstream-exports/react-aria/ListDropTargetDelegate.tsx +15 -0
  358. package/src/upstream-exports/react-aria/PortalProvider.tsx +19 -0
  359. package/src/upstream-exports/react-aria/SSRProvider.tsx +15 -0
  360. package/src/upstream-exports/react-aria/VisuallyHidden.tsx +15 -0
  361. package/src/upstream-exports/react-aria/filterDOMProps.tsx +3 -0
  362. package/src/upstream-exports/react-aria/mergeProps.tsx +14 -0
  363. package/src/upstream-exports/react-aria/private/dnd/DragManager.tsx +3 -0
  364. package/src/upstream-exports/react-aria/private/interactions/PressResponder.tsx +3 -0
  365. package/src/upstream-exports/react-aria/private/utils/isFocusable.tsx +3 -0
  366. package/src/upstream-exports/react-aria/private/utils/shadowdom/DOMFunctions.tsx +8 -0
  367. package/src/upstream-exports/react-aria/private/utils/useId.tsx +3 -0
  368. package/src/upstream-exports/react-aria/private/utils/useLabels.tsx +3 -0
  369. package/src/upstream-exports/react-aria/private/virtualizer/ScrollView.tsx +3 -0
  370. package/src/upstream-exports/react-aria/private/virtualizer/VirtualizerItem.tsx +3 -0
  371. package/src/upstream-exports/react-aria/useButton.tsx +22 -0
  372. package/src/upstream-exports/react-aria/useCalendar.tsx +37 -0
  373. package/src/upstream-exports/react-aria/useClipboard.tsx +23 -0
  374. package/src/upstream-exports/react-aria/useColorArea.tsx +19 -0
  375. package/src/upstream-exports/react-aria/useColorField.tsx +20 -0
  376. package/src/upstream-exports/react-aria/useColorSlider.tsx +19 -0
  377. package/src/upstream-exports/react-aria/useColorSwatch.tsx +15 -0
  378. package/src/upstream-exports/react-aria/useColorWheel.tsx +19 -0
  379. package/src/upstream-exports/react-aria/useDateField.tsx +23 -0
  380. package/src/upstream-exports/react-aria/useDatePicker.tsx +17 -0
  381. package/src/upstream-exports/react-aria/useDateRangePicker.tsx +24 -0
  382. package/src/upstream-exports/react-aria/useDraggableCollection.tsx +31 -0
  383. package/src/upstream-exports/react-aria/useDrop.tsx +33 -0
  384. package/src/upstream-exports/react-aria/useDroppableCollection.tsx +47 -0
  385. package/src/upstream-exports/react-aria/useFocusRing.tsx +16 -0
  386. package/src/upstream-exports/react-aria/useHover.tsx +17 -0
  387. package/src/upstream-exports/react-aria/useLocalizedStringFormatter.tsx +19 -0
  388. package/src/upstream-exports/react-aria/useObjectRef.tsx +14 -0
  389. package/src/upstream-exports/react-aria/useRangeCalendar.tsx +38 -0
  390. package/src/upstream-exports/react-aria/useTimeField.tsx +23 -0
  391. package/src/upstream-exports/react-aria/useToast.tsx +18 -0
  392. package/src/upstream-exports/react-stately/Color.tsx +23 -0
  393. package/src/upstream-exports/react-stately/private/form/useFormValidationState.tsx +11 -0
  394. package/src/upstream-exports/react-stately/useCalendarState.tsx +24 -0
  395. package/src/upstream-exports/react-stately/useColorAreaState.tsx +24 -0
  396. package/src/upstream-exports/react-stately/useColorFieldState.tsx +22 -0
  397. package/src/upstream-exports/react-stately/useColorPickerState.tsx +25 -0
  398. package/src/upstream-exports/react-stately/useColorSliderState.tsx +25 -0
  399. package/src/upstream-exports/react-stately/useColorWheelState.tsx +24 -0
  400. package/src/upstream-exports/react-stately/useDateFieldState.tsx +29 -0
  401. package/src/upstream-exports/react-stately/useDatePickerState.tsx +25 -0
  402. package/src/upstream-exports/react-stately/useDateRangePickerState.tsx +26 -0
  403. package/src/upstream-exports/react-stately/useDraggableCollectionState.tsx +19 -0
  404. package/src/upstream-exports/react-stately/useDroppableCollectionState.tsx +19 -0
  405. package/src/upstream-exports/react-stately/useRangeCalendarState.tsx +27 -0
  406. package/src/upstream-exports/react-stately/useTimeFieldState.tsx +26 -0
  407. package/src/upstream-exports/react-stately/useToastState.tsx +21 -0
  408. package/src/upstream-exports/react-stately/useVirtualizerState.tsx +22 -0
  409. package/src/utils/useLoadMore.tsx +89 -0
  410. package/src/virtualizer/ScrollView.tsx +401 -0
  411. package/src/virtualizer/Virtualizer.tsx +147 -0
  412. package/src/virtualizer/VirtualizerItem.tsx +108 -0
  413. package/src/virtualizer/useVirtualizerItem.tsx +57 -0
  414. package/src/virtualizer/utils.tsx +105 -0
  415. package/LICENSE +0 -21
  416. package/src/components/useDragAndDrop.ts +0 -164
@@ -0,0 +1,437 @@
1
+ /** @jsxImportSource octane */
2
+ // Ported from adobe/react-spectrum@1c84a49a1faf50b571c84e00bcf9c60b22ddd03e (packages/react-aria/src/dnd/useDrag.ts).
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+ import { AriaButtonProps } from '../button/useButton';
16
+ import {
17
+ DragEndEvent,
18
+ DragItem,
19
+ DragMoveEvent,
20
+ DragPreviewRenderer,
21
+ DragStartEvent,
22
+ DropOperation,
23
+ PressEvent,
24
+ RefObject,
25
+ } from '@react-types/shared';
26
+ import {
27
+ DragEvent,
28
+ HTMLAttributes,
29
+ KeyboardEvent,
30
+ MouseEvent,
31
+ PointerEvent,
32
+ useEffect,
33
+ useRef,
34
+ useState,
35
+ } from '../compat/react';
36
+ import * as DragManager from './DragManager';
37
+ import { DROP_EFFECT_TO_DROP_OPERATION, DROP_OPERATION, EFFECT_ALLOWED } from './constants';
38
+ import { getEventTarget } from '../utils/shadowdom/DOMFunctions';
39
+ import {
40
+ globalDropEffect,
41
+ setGlobalAllowedDropOperations,
42
+ setGlobalDropEffect,
43
+ useDragModality,
44
+ writeToDataTransfer,
45
+ } from './utils';
46
+ import intlMessages from '../intl/dnd/index';
47
+ import { isVirtualClick, isVirtualPointerEvent } from '../utils/isVirtualEvent';
48
+ import { useDescription } from '../utils/useDescription';
49
+ import { useGlobalListeners } from '../utils/useGlobalListeners';
50
+ import { useLocalizedStringFormatter } from '../i18n/useLocalizedStringFormatter';
51
+
52
+ export interface DragOptions {
53
+ /** Handler that is called when a drag operation is started. */
54
+ onDragStart?: (e: DragStartEvent) => void;
55
+ /** Handler that is called when the drag is moved. */
56
+ onDragMove?: (e: DragMoveEvent) => void;
57
+ /**
58
+ * Handler that is called when the drag operation is ended, either as a result of a drop or a
59
+ * cancellation.
60
+ */
61
+ onDragEnd?: (e: DragEndEvent) => void;
62
+ /** A function that returns the items being dragged. */
63
+ getItems: () => DragItem[];
64
+ /** The ref of the element that will be rendered as the drag preview while dragging. */
65
+ preview?: RefObject<DragPreviewRenderer | null>;
66
+ /**
67
+ * Function that returns the drop operations that are allowed for the dragged items. If not
68
+ * provided, all drop operations are allowed.
69
+ */
70
+ getAllowedDropOperations?: () => DropOperation[];
71
+ /**
72
+ * Whether the item has an explicit focusable drag affordance to initiate accessible drag and drop
73
+ * mode. If true, the dragProps will omit these event handlers, and they will be applied to
74
+ * dragButtonProps instead.
75
+ */
76
+ hasDragButton?: boolean;
77
+ /**
78
+ * Whether the drag operation is disabled. If true, the element will not be draggable.
79
+ */
80
+ isDisabled?: boolean;
81
+ }
82
+
83
+ export interface DragResult {
84
+ /** Props for the draggable element. */
85
+ dragProps: HTMLAttributes<HTMLElement>;
86
+ /** Props for the explicit drag button affordance, if any. */
87
+ dragButtonProps: AriaButtonProps;
88
+ /** Whether the element is currently being dragged. */
89
+ isDragging: boolean;
90
+ }
91
+
92
+ const MESSAGES = {
93
+ keyboard: {
94
+ start: 'dragDescriptionKeyboard',
95
+ end: 'endDragKeyboard',
96
+ },
97
+ touch: {
98
+ start: 'dragDescriptionTouch',
99
+ end: 'endDragTouch',
100
+ },
101
+ virtual: {
102
+ start: 'dragDescriptionVirtual',
103
+ end: 'endDragVirtual',
104
+ },
105
+ };
106
+
107
+ /**
108
+ * Handles drag interactions for an element, with support for traditional mouse and touch
109
+ * based drag and drop, in addition to full parity for keyboard and screen reader users.
110
+ */
111
+ export function useDrag(options: DragOptions): DragResult {
112
+ let { hasDragButton, isDisabled } = options;
113
+ let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/dnd');
114
+ let state = useRef({
115
+ options,
116
+ x: 0,
117
+ y: 0,
118
+ }).current;
119
+ state.options = options;
120
+ let isDraggingRef = useRef<Element | null>(null);
121
+ let [isDragging, setDraggingState] = useState(false);
122
+ let setDragging = (element: Element | null) => {
123
+ isDraggingRef.current = element;
124
+ setDraggingState(!!element);
125
+ };
126
+ let { addGlobalListener, removeAllGlobalListeners } = useGlobalListeners();
127
+ let modalityOnPointerDown = useRef<string | null>(null);
128
+
129
+ let onDragStart = (e: DragEvent) => {
130
+ if (e.defaultPrevented) {
131
+ return;
132
+ }
133
+
134
+ // Prevent the drag event from propagating to any parent draggables
135
+ e.stopPropagation();
136
+
137
+ // If this drag was initiated by a mobile screen reader (e.g. VoiceOver or TalkBack), enter virtual dragging mode.
138
+ if (modalityOnPointerDown.current === 'virtual') {
139
+ e.preventDefault();
140
+ startDragging(getEventTarget(e) as HTMLElement);
141
+ modalityOnPointerDown.current = null;
142
+ return;
143
+ }
144
+
145
+ if (typeof options.onDragStart === 'function') {
146
+ options.onDragStart({
147
+ type: 'dragstart',
148
+ x: e.clientX,
149
+ y: e.clientY,
150
+ });
151
+ }
152
+
153
+ let items = options.getItems();
154
+ // Clear existing data (e.g. selected text on the page would be included in some browsers)
155
+ e.dataTransfer.clearData?.();
156
+ writeToDataTransfer(e.dataTransfer, items);
157
+
158
+ let allowed = DROP_OPERATION.all;
159
+ if (typeof options.getAllowedDropOperations === 'function') {
160
+ let allowedOperations = options.getAllowedDropOperations();
161
+ allowed = DROP_OPERATION.none;
162
+ for (let operation of allowedOperations) {
163
+ allowed |= DROP_OPERATION[operation] || DROP_OPERATION.none;
164
+ }
165
+ }
166
+
167
+ setGlobalAllowedDropOperations(allowed);
168
+ let effectAllowed = EFFECT_ALLOWED[allowed] || 'none';
169
+ e.dataTransfer.effectAllowed = effectAllowed === 'cancel' ? 'none' : effectAllowed;
170
+
171
+ // If there is a preview option, use it to render a custom preview image that will
172
+ // appear under the pointer while dragging. If not, the element itself is dragged by the browser.
173
+ if (typeof options.preview?.current === 'function') {
174
+ options.preview.current(items, (node, userX, userY) => {
175
+ if (!node) {
176
+ return;
177
+ }
178
+ // Compute the offset that the preview will appear under the mouse.
179
+ // If possible, this is based on the point the user clicked on the target.
180
+ // If the preview is much smaller, then just use the center point of the preview.
181
+ let size = node.getBoundingClientRect();
182
+ let rect = e.currentTarget.getBoundingClientRect();
183
+ let defaultX = e.clientX - rect.x;
184
+ let defaultY = e.clientY - rect.y;
185
+ if (defaultX > size.width || defaultY > size.height) {
186
+ defaultX = size.width / 2;
187
+ defaultY = size.height / 2;
188
+ }
189
+
190
+ // Start with default offsets.
191
+ let offsetX = defaultX;
192
+ let offsetY = defaultY;
193
+
194
+ // If the preview renderer supplied explicit offsets, use those.
195
+ if (typeof userX === 'number' && typeof userY === 'number') {
196
+ offsetX = userX;
197
+ offsetY = userY;
198
+ }
199
+
200
+ // Clamp the offset so it stays within the preview bounds. Browsers
201
+ // automatically clamp out-of-range values, but doing it ourselves
202
+ // prevents the visible "snap" that can occur when the browser adjusts
203
+ // them after the first drag update.
204
+ offsetX = Math.max(0, Math.min(offsetX, size.width));
205
+ offsetY = Math.max(0, Math.min(offsetY, size.height));
206
+
207
+ // Rounding height to an even number prevents blurry preview seen on some screens
208
+ let height = 2 * Math.round(size.height / 2);
209
+ node.style.height = `${height}px`;
210
+
211
+ e.dataTransfer.setDragImage(node, offsetX, offsetY);
212
+ });
213
+ }
214
+
215
+ // Enforce that drops are handled by useDrop.
216
+ addGlobalListener(
217
+ window,
218
+ 'drop',
219
+ (e) => {
220
+ e.preventDefault();
221
+ e.stopPropagation();
222
+ console.warn(
223
+ 'Drags initiated from the React Aria useDrag hook may only be dropped on a target created with useDrop. This ensures that a keyboard and screen reader accessible alternative is available.',
224
+ );
225
+ },
226
+ { once: true },
227
+ );
228
+ state.x = e.clientX;
229
+ state.y = e.clientY;
230
+
231
+ // Wait a frame before we set dragging to true so that the browser has time to
232
+ // render the preview image before we update the element that has been dragged.
233
+ let target = getEventTarget(e);
234
+ requestAnimationFrame(() => {
235
+ setDragging(target as Element);
236
+ });
237
+ };
238
+
239
+ let onDrag = (e: DragEvent) => {
240
+ // Prevent the drag event from propagating to any parent draggables
241
+ e.stopPropagation();
242
+
243
+ if (e.clientX === state.x && e.clientY === state.y) {
244
+ return;
245
+ }
246
+
247
+ if (typeof options.onDragMove === 'function') {
248
+ options.onDragMove({
249
+ type: 'dragmove',
250
+ x: e.clientX,
251
+ y: e.clientY,
252
+ });
253
+ }
254
+
255
+ state.x = e.clientX;
256
+ state.y = e.clientY;
257
+ };
258
+
259
+ let onDragEnd = (e: DragEvent) => {
260
+ // Prevent the drag event from propagating to any parent draggables
261
+ e.stopPropagation();
262
+
263
+ if (typeof options.onDragEnd === 'function') {
264
+ let event: DragEndEvent = {
265
+ type: 'dragend',
266
+ x: e.clientX,
267
+ y: e.clientY,
268
+ dropOperation: DROP_EFFECT_TO_DROP_OPERATION[e.dataTransfer.dropEffect],
269
+ };
270
+
271
+ // Chrome Android always returns none as its dropEffect so we use the drop effect set in useDrop via
272
+ // onDragEnter/onDragOver instead. https://bugs.chromium.org/p/chromium/issues/detail?id=1353951
273
+ if (globalDropEffect) {
274
+ event.dropOperation = DROP_EFFECT_TO_DROP_OPERATION[globalDropEffect];
275
+ }
276
+ options.onDragEnd(event);
277
+ }
278
+
279
+ setDragging(null);
280
+ removeAllGlobalListeners();
281
+ setGlobalAllowedDropOperations(DROP_OPERATION.none);
282
+ setGlobalDropEffect(undefined);
283
+ };
284
+
285
+ // If the dragged element is removed from the DOM via onDrop, onDragEnd won't fire: https://bugzilla.mozilla.org/show_bug.cgi?id=460801
286
+ // In this case, we need to manually call onDragEnd on cleanup
287
+
288
+ useEffect(() => {
289
+ return () => {
290
+ // Octane deletion cleanups run after DOM removal, while Activity hides disconnect
291
+ // effects with their DOM still connected. Only the former represents a removed drag target.
292
+ if (isDraggingRef.current && !isDraggingRef.current.isConnected) {
293
+ if (typeof state.options.onDragEnd === 'function') {
294
+ let event: DragEndEvent = {
295
+ type: 'dragend',
296
+ x: 0,
297
+ y: 0,
298
+ dropOperation: DROP_EFFECT_TO_DROP_OPERATION[globalDropEffect || 'none'],
299
+ };
300
+ state.options.onDragEnd(event);
301
+ }
302
+
303
+ setDragging(null);
304
+ setGlobalAllowedDropOperations(DROP_OPERATION.none);
305
+ setGlobalDropEffect(undefined);
306
+ }
307
+ };
308
+ }, [state]);
309
+
310
+ let onPress = (e: PressEvent) => {
311
+ if (e.pointerType !== 'keyboard' && e.pointerType !== 'virtual') {
312
+ return;
313
+ }
314
+
315
+ startDragging(e.target as HTMLElement);
316
+ };
317
+
318
+ let startDragging = (target: HTMLElement) => {
319
+ if (typeof state.options.onDragStart === 'function') {
320
+ let rect = target.getBoundingClientRect();
321
+ state.options.onDragStart({
322
+ type: 'dragstart',
323
+ x: rect.x + rect.width / 2,
324
+ y: rect.y + rect.height / 2,
325
+ });
326
+ }
327
+
328
+ DragManager.beginDragging(
329
+ {
330
+ element: target,
331
+ items: state.options.getItems(),
332
+ allowedDropOperations:
333
+ typeof state.options.getAllowedDropOperations === 'function'
334
+ ? state.options.getAllowedDropOperations()
335
+ : ['move', 'copy', 'link'],
336
+ onDragEnd(e) {
337
+ setDragging(null);
338
+ if (typeof state.options.onDragEnd === 'function') {
339
+ state.options.onDragEnd(e);
340
+ }
341
+ },
342
+ },
343
+ stringFormatter,
344
+ );
345
+
346
+ setDragging(target);
347
+ };
348
+
349
+ let modality = useDragModality();
350
+ let message = !isDragging
351
+ ? MESSAGES[modality as keyof typeof MESSAGES].start
352
+ : MESSAGES[modality as keyof typeof MESSAGES].end;
353
+
354
+ let descriptionProps = useDescription(stringFormatter.format(message));
355
+
356
+ let interactions: HTMLAttributes<HTMLElement> = {};
357
+ if (!hasDragButton) {
358
+ // If there's no separate button to trigger accessible drag and drop mode,
359
+ // then add event handlers to the draggable element itself to start dragging.
360
+ // For keyboard, we use the Enter key in a capturing listener to prevent other
361
+ // events such as selection from also occurring. We attempt to infer whether a
362
+ // pointer event (e.g. long press) came from a touch screen reader, and then initiate
363
+ // dragging in the native onDragStart listener above.
364
+
365
+ interactions = {
366
+ ...descriptionProps,
367
+ onPointerDown(e: PointerEvent<HTMLElement>) {
368
+ modalityOnPointerDown.current = isVirtualPointerEvent(e) ? 'virtual' : e.pointerType;
369
+
370
+ // Try to detect virtual drag passthrough gestures.
371
+ if (e.width < 1 && e.height < 1) {
372
+ // iOS VoiceOver.
373
+ modalityOnPointerDown.current = 'virtual';
374
+ } else {
375
+ let rect = e.currentTarget.getBoundingClientRect();
376
+ let offsetX = e.clientX - rect.x;
377
+ let offsetY = e.clientY - rect.y;
378
+ let centerX = rect.width / 2;
379
+ let centerY = rect.height / 2;
380
+
381
+ if (Math.abs(offsetX - centerX) <= 0.5 && Math.abs(offsetY - centerY) <= 0.5) {
382
+ // Android TalkBack.
383
+ modalityOnPointerDown.current = 'virtual';
384
+ } else {
385
+ modalityOnPointerDown.current = e.pointerType;
386
+ }
387
+ }
388
+ },
389
+ onKeyDownCapture(e: KeyboardEvent<HTMLElement>) {
390
+ if (getEventTarget(e) === e.currentTarget && e.key === 'Enter') {
391
+ e.preventDefault();
392
+ e.stopPropagation();
393
+ }
394
+ },
395
+ onKeyUpCapture(e: KeyboardEvent<HTMLElement>) {
396
+ if (getEventTarget(e) === e.currentTarget && e.key === 'Enter') {
397
+ e.preventDefault();
398
+ e.stopPropagation();
399
+ startDragging(getEventTarget(e) as HTMLElement);
400
+ }
401
+ },
402
+ onClick(e: MouseEvent<HTMLElement>) {
403
+ // Handle NVDA/JAWS in browse mode, and touch screen readers. In this case, no keyboard events are fired.
404
+ if (isVirtualClick(e) || modalityOnPointerDown.current === 'virtual') {
405
+ e.preventDefault();
406
+ e.stopPropagation();
407
+ startDragging(getEventTarget(e) as HTMLElement);
408
+ }
409
+ },
410
+ };
411
+ }
412
+
413
+ if (isDisabled) {
414
+ return {
415
+ dragProps: {
416
+ draggable: 'false',
417
+ },
418
+ dragButtonProps: {},
419
+ isDragging: false,
420
+ };
421
+ }
422
+
423
+ return {
424
+ dragProps: {
425
+ ...interactions,
426
+ draggable: 'true',
427
+ onDragStart,
428
+ onDrag,
429
+ onDragEnd,
430
+ },
431
+ dragButtonProps: {
432
+ ...descriptionProps,
433
+ onPress,
434
+ },
435
+ isDragging,
436
+ };
437
+ }
@@ -0,0 +1,35 @@
1
+ /** @jsxImportSource octane */
2
+ // Ported from adobe/react-spectrum@1c84a49a1faf50b571c84e00bcf9c60b22ddd03e (packages/react-aria/src/dnd/useDraggableCollection.ts).
3
+ /*
4
+ * Copyright 2022 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+ import { DraggableCollectionState } from '../upstream-exports/react-stately/useDraggableCollectionState';
16
+ import { globalDndState, setDraggingCollectionRef } from './utils';
17
+ import { RefObject } from '@react-types/shared';
18
+
19
+ export interface DraggableCollectionOptions {}
20
+
21
+ /**
22
+ * Handles drag interactions for a collection component, with support for traditional mouse and
23
+ * touch based drag and drop, in addition to full parity for keyboard and screen reader users.
24
+ */
25
+ export function useDraggableCollection(
26
+ props: DraggableCollectionOptions,
27
+ state: DraggableCollectionState,
28
+ ref: RefObject<HTMLElement | null>,
29
+ ): void {
30
+ // Update global DnD state if this keys within this collection are dragged
31
+ let { draggingCollectionRef } = globalDndState;
32
+ if (state.draggingKeys.size > 0 && draggingCollectionRef?.current !== ref.current) {
33
+ setDraggingCollectionRef(ref);
34
+ }
35
+ }
@@ -0,0 +1,168 @@
1
+ /** @jsxImportSource octane */
2
+ // Ported from adobe/react-spectrum@1c84a49a1faf50b571c84e00bcf9c60b22ddd03e (packages/react-aria/src/dnd/useDraggableItem.ts).
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+ import { AriaButtonProps } from '../button/useButton';
16
+ import {
17
+ clearGlobalDnDState,
18
+ isInternalDropOperation,
19
+ setDraggingKeys,
20
+ useDragModality,
21
+ } from './utils';
22
+ import { DraggableCollectionState } from '../upstream-exports/react-stately/useDraggableCollectionState';
23
+ import { HTMLAttributes, KeyboardEvent } from '../compat/react';
24
+ import intlMessages from '../intl/dnd/index';
25
+ import { Key } from '@react-types/shared';
26
+ import { useDescription } from '../utils/useDescription';
27
+ import { useDrag } from './useDrag';
28
+ import { useLocalizedStringFormatter } from '../i18n/useLocalizedStringFormatter';
29
+
30
+ export interface DraggableItemProps {
31
+ /** The key of the draggable item within the collection. */
32
+ key: Key;
33
+ /**
34
+ * Whether the item has an explicit focusable drag affordance to initiate accessible drag and drop
35
+ * mode. If true, the dragProps will omit these event handlers, and they will be applied to
36
+ * dragButtonProps instead.
37
+ */
38
+ hasDragButton?: boolean;
39
+ /**
40
+ * Whether the item has a primary action (e.g. Enter key or long press) that would conflict with
41
+ * initiating accessible drag and drop. If true, the Alt key must be held to start dragging with a
42
+ * keyboard, and long press is disabled until selection mode is entered. This should be passed
43
+ * from the associated collection item hook (e.g. useOption, useGridListItem, etc.).
44
+ */
45
+ hasAction?: boolean;
46
+ }
47
+
48
+ export interface DraggableItemResult {
49
+ /** Props for the draggable item. */
50
+ dragProps: HTMLAttributes<HTMLElement>;
51
+ /** Props for the explicit drag button affordance, if any. */
52
+ dragButtonProps: AriaButtonProps;
53
+ }
54
+
55
+ const MESSAGES = {
56
+ keyboard: {
57
+ selected: 'dragSelectedKeyboard',
58
+ notSelected: 'dragDescriptionKeyboard',
59
+ },
60
+ touch: {
61
+ selected: 'dragSelectedLongPress',
62
+ notSelected: 'dragDescriptionLongPress',
63
+ },
64
+ virtual: {
65
+ selected: 'dragDescriptionVirtual',
66
+ notSelected: 'dragDescriptionVirtual',
67
+ },
68
+ };
69
+
70
+ /**
71
+ * Handles drag interactions for an item within a draggable collection.
72
+ */
73
+ export function useDraggableItem(
74
+ props: DraggableItemProps,
75
+ state: DraggableCollectionState,
76
+ ): DraggableItemResult {
77
+ let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/dnd');
78
+ let isDisabled = state.isDisabled || state.selectionManager.isDisabled(props.key);
79
+ let { dragProps, dragButtonProps } = useDrag({
80
+ getItems() {
81
+ return state.getItems(props.key);
82
+ },
83
+ preview: state.preview,
84
+ getAllowedDropOperations: state.getAllowedDropOperations,
85
+ hasDragButton: props.hasDragButton,
86
+ onDragStart(e) {
87
+ state.startDrag(props.key, e);
88
+ // Track draggingKeys for useDroppableCollection's default onDrop handler and useDroppableCollectionState's default getDropOperation
89
+ setDraggingKeys(state.draggingKeys);
90
+ },
91
+ onDragMove(e) {
92
+ state.moveDrag(e);
93
+ },
94
+ onDragEnd(e) {
95
+ let { dropOperation } = e;
96
+ let isInternal = dropOperation === 'cancel' ? false : isInternalDropOperation();
97
+ state.endDrag({ ...e, keys: state.draggingKeys, isInternal });
98
+ clearGlobalDnDState();
99
+ },
100
+ });
101
+
102
+ let item = state.collection.getItem(props.key);
103
+ let numKeysForDrag = state.getKeysForDrag(props.key).size;
104
+ let isSelected = numKeysForDrag > 1 && state.selectionManager.isSelected(props.key);
105
+ let dragButtonLabel: string | undefined;
106
+ let description: string | undefined;
107
+
108
+ // Override description to include selected item count.
109
+ let modality = useDragModality();
110
+ if (!props.hasDragButton && state.selectionManager.selectionMode !== 'none') {
111
+ let msg = MESSAGES[modality as keyof typeof MESSAGES][isSelected ? 'selected' : 'notSelected'];
112
+ if (props.hasAction && modality === 'keyboard') {
113
+ msg += 'Alt';
114
+ }
115
+
116
+ if (isSelected) {
117
+ description = stringFormatter.format(msg, { count: numKeysForDrag });
118
+ } else {
119
+ description = stringFormatter.format(msg);
120
+ }
121
+
122
+ // Remove the onClick handler from useDrag. Long pressing will be required on touch devices,
123
+ // and NVDA/JAWS are always in forms mode within collection components.
124
+ delete dragProps.onClick;
125
+ } else {
126
+ if (isSelected) {
127
+ dragButtonLabel = stringFormatter.format('dragSelectedItems', { count: numKeysForDrag });
128
+ } else {
129
+ let itemText = state.collection.getTextValue?.(props.key) ?? item?.textValue ?? '';
130
+ dragButtonLabel = stringFormatter.format('dragItem', { itemText });
131
+ }
132
+ }
133
+
134
+ let descriptionProps = useDescription(description);
135
+ if (description) {
136
+ Object.assign(dragProps, descriptionProps);
137
+ }
138
+
139
+ if (!props.hasDragButton && props.hasAction) {
140
+ let { onKeyDownCapture, onKeyUpCapture } = dragProps;
141
+ if (modality === 'touch') {
142
+ // Remove long press description if an action is present, because in that case long pressing selects the item.
143
+ delete dragProps['aria-describedby'];
144
+ }
145
+
146
+ // Require Alt key if there is a conflicting action.
147
+ dragProps.onKeyDownCapture = (e: KeyboardEvent<HTMLElement>) => {
148
+ if (e.altKey) {
149
+ onKeyDownCapture?.(e);
150
+ }
151
+ };
152
+
153
+ dragProps.onKeyUpCapture = (e: KeyboardEvent<HTMLElement>) => {
154
+ if (e.altKey) {
155
+ onKeyUpCapture?.(e);
156
+ }
157
+ };
158
+ }
159
+
160
+ return {
161
+ dragProps: isDisabled ? {} : dragProps,
162
+ dragButtonProps: {
163
+ ...dragButtonProps,
164
+ isDisabled,
165
+ 'aria-label': dragButtonLabel,
166
+ },
167
+ };
168
+ }