@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,808 @@
1
+ /** @jsxImportSource octane */
2
+ // Ported from adobe/react-spectrum@1c84a49a1faf50b571c84e00bcf9c60b22ddd03e (packages/react-aria/src/dnd/useDroppableCollection.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 {
16
+ clearGlobalDnDState,
17
+ DIRECTORY_DRAG_TYPE,
18
+ droppableCollectionMap,
19
+ getTypes,
20
+ globalDndState,
21
+ isInternalDropOperation,
22
+ setDropCollectionRef,
23
+ } from './utils';
24
+ import {
25
+ Collection,
26
+ DropEvent,
27
+ DropOperation,
28
+ DroppableCollectionDropEvent,
29
+ DroppableCollectionProps,
30
+ DropPosition,
31
+ DropTarget,
32
+ DropTargetDelegate,
33
+ Key,
34
+ KeyboardDelegate,
35
+ Node,
36
+ RefObject,
37
+ } from '@react-types/shared';
38
+ import * as DragManager from './DragManager';
39
+ import { DroppableCollectionState } from '../upstream-exports/react-stately/useDroppableCollectionState';
40
+ import { HTMLAttributes, useCallback, useEffect, useRef } from '../compat/react';
41
+ import { mergeProps } from '../utils/mergeProps';
42
+ import { navigate } from './DropTargetKeyboardNavigation';
43
+ import { setInteractionModality } from '../interactions/useFocusVisible';
44
+ import { useAutoScroll } from './useAutoScroll';
45
+ import { useDrop } from './useDrop';
46
+ import { useId } from '../utils/useId';
47
+ import { useLayoutEffect } from '../utils/useLayoutEffect';
48
+ import { useLocale } from '../i18n/I18nProvider';
49
+
50
+ export interface DroppableCollectionOptions extends DroppableCollectionProps {
51
+ /** A delegate object that implements behavior for keyboard focus movement. */
52
+ keyboardDelegate: KeyboardDelegate;
53
+ /** A delegate object that provides drop targets for pointer coordinates within the collection. */
54
+ dropTargetDelegate: DropTargetDelegate;
55
+ /** A custom keyboard event handler for drop targets. */
56
+ onKeyDown?: (e: KeyboardEvent) => void;
57
+ }
58
+
59
+ export interface DroppableCollectionResult {
60
+ /** Props for the collection element. */
61
+ collectionProps: HTMLAttributes<HTMLElement>;
62
+ }
63
+
64
+ interface DroppingState {
65
+ collection: Collection<Node<unknown>>;
66
+ focusedKey: Key | null;
67
+ selectedKeys: Set<Key>;
68
+ target: DropTarget;
69
+ draggingKeys: Set<Key | null | undefined>;
70
+ isInternal: boolean;
71
+ timeout: ReturnType<typeof setTimeout> | undefined;
72
+ }
73
+
74
+ /**
75
+ * Handles drop interactions for a collection component, with support for traditional mouse and
76
+ * touch based drag and drop, in addition to full parity for keyboard and screen reader users.
77
+ */
78
+ export function useDroppableCollection(
79
+ props: DroppableCollectionOptions,
80
+ state: DroppableCollectionState,
81
+ ref: RefObject<HTMLElement | null>,
82
+ ): DroppableCollectionResult {
83
+ let localState = useRef<{
84
+ props: DroppableCollectionOptions;
85
+ state: DroppableCollectionState;
86
+ nextTarget: DropTarget | null;
87
+ dropOperation: DropOperation | null;
88
+ }>({
89
+ props,
90
+ state,
91
+ nextTarget: null,
92
+ dropOperation: null,
93
+ }).current;
94
+ localState.props = props;
95
+ localState.state = state;
96
+
97
+ let defaultOnDrop = useCallback(
98
+ async (e: DroppableCollectionDropEvent) => {
99
+ let {
100
+ onInsert,
101
+ onRootDrop,
102
+ onItemDrop,
103
+ onReorder,
104
+ onMove,
105
+ acceptedDragTypes = 'all',
106
+ shouldAcceptItemDrop,
107
+ } = localState.props;
108
+
109
+ let { draggingKeys } = globalDndState;
110
+ let isInternal = isInternalDropOperation(ref);
111
+ let { target, dropOperation, items } = e;
112
+
113
+ let filteredItems = items;
114
+ if (acceptedDragTypes !== 'all' || shouldAcceptItemDrop) {
115
+ filteredItems = items.filter((item) => {
116
+ let itemTypes: Set<string | symbol>;
117
+ if (item.kind === 'directory') {
118
+ itemTypes = new Set([DIRECTORY_DRAG_TYPE]);
119
+ } else {
120
+ itemTypes = item.kind === 'file' ? new Set([item.type]) : item.types;
121
+ }
122
+
123
+ if (
124
+ acceptedDragTypes === 'all' ||
125
+ acceptedDragTypes.some((type) => itemTypes.has(type))
126
+ ) {
127
+ // If we are performing a on item drop, check if the item in question accepts the dropped item since the item may have heavier restrictions
128
+ // than the droppable collection itself
129
+ if (target.type === 'item' && target.dropPosition === 'on' && shouldAcceptItemDrop) {
130
+ return shouldAcceptItemDrop(target, itemTypes);
131
+ }
132
+ return true;
133
+ }
134
+
135
+ return false;
136
+ });
137
+ }
138
+
139
+ if (filteredItems.length > 0) {
140
+ if (target.type === 'root' && onRootDrop) {
141
+ await onRootDrop({ items: filteredItems, dropOperation });
142
+ }
143
+
144
+ if (target.type === 'item') {
145
+ if (target.dropPosition === 'on' && onItemDrop) {
146
+ await onItemDrop({ items: filteredItems, dropOperation, isInternal, target });
147
+ }
148
+
149
+ if (onMove && isInternal) {
150
+ await onMove({ keys: draggingKeys, dropOperation, target });
151
+ }
152
+
153
+ if (target.dropPosition !== 'on') {
154
+ if (!isInternal && onInsert) {
155
+ await onInsert({ items: filteredItems, dropOperation, target });
156
+ }
157
+
158
+ if (isInternal && onReorder) {
159
+ await onReorder({ keys: draggingKeys, dropOperation, target });
160
+ }
161
+ }
162
+ }
163
+ }
164
+ },
165
+ [localState, ref],
166
+ );
167
+
168
+ let autoScroll = useAutoScroll(ref);
169
+ let { dropProps } = useDrop({
170
+ ref,
171
+ onDropEnter() {
172
+ if (localState.nextTarget != null) {
173
+ state.setTarget(localState.nextTarget);
174
+ }
175
+ },
176
+ onDropMove(e) {
177
+ if (localState.nextTarget != null) {
178
+ state.setTarget(localState.nextTarget);
179
+ }
180
+ autoScroll.move(e.x, e.y);
181
+ },
182
+ getDropOperationForPoint(types, allowedOperations, x, y) {
183
+ let { draggingKeys, dropCollectionRef } = globalDndState;
184
+ let isInternal = isInternalDropOperation(ref);
185
+ let isValidDropTarget = (target: DropTarget) =>
186
+ state.getDropOperation({ target, types, allowedOperations, isInternal, draggingKeys }) !==
187
+ 'cancel';
188
+ let target = props.dropTargetDelegate.getDropTargetFromPoint(x, y, isValidDropTarget);
189
+ if (!target) {
190
+ localState.dropOperation = 'cancel';
191
+ localState.nextTarget = null;
192
+ return 'cancel';
193
+ }
194
+
195
+ localState.dropOperation = state.getDropOperation({
196
+ target,
197
+ types,
198
+ allowedOperations,
199
+ isInternal,
200
+ draggingKeys,
201
+ });
202
+
203
+ // If the target doesn't accept the drop, see if the root accepts it instead.
204
+ if (localState.dropOperation === 'cancel') {
205
+ let rootTarget: DropTarget = { type: 'root' };
206
+ let dropOperation = state.getDropOperation({
207
+ target: rootTarget,
208
+ types,
209
+ allowedOperations,
210
+ isInternal,
211
+ draggingKeys,
212
+ });
213
+ if (dropOperation !== 'cancel') {
214
+ target = rootTarget;
215
+ localState.dropOperation = dropOperation;
216
+ }
217
+ }
218
+
219
+ // Only set dropCollectionRef if there is a valid drop target since we cleanup dropCollectionRef in onDropExit
220
+ // which only runs when leaving a valid drop target or if the dropEffect become none (mouse dnd only).
221
+ if (
222
+ target &&
223
+ localState.dropOperation !== 'cancel' &&
224
+ ref?.current !== dropCollectionRef?.current
225
+ ) {
226
+ setDropCollectionRef(ref);
227
+ }
228
+ localState.nextTarget = localState.dropOperation === 'cancel' ? null : target;
229
+ return localState.dropOperation;
230
+ },
231
+ onDropExit() {
232
+ setDropCollectionRef(undefined);
233
+ state.setTarget(null);
234
+ autoScroll.stop();
235
+ },
236
+ onDropActivate(e) {
237
+ if (state.target?.type === 'item' && typeof props.onDropActivate === 'function') {
238
+ props.onDropActivate({
239
+ type: 'dropactivate',
240
+ x: e.x, // todo
241
+ y: e.y,
242
+ target: state.target,
243
+ });
244
+ }
245
+ },
246
+ onDrop(e) {
247
+ setDropCollectionRef(ref);
248
+ if (state.target) {
249
+ onDrop(e, state.target);
250
+ }
251
+
252
+ // If there wasn't a collection being tracked as a dragged collection, then we are in a case where a non RSP drag is dropped on a
253
+ // RSP collection and thus we don't need to preserve the global DnD state for onDragEnd
254
+ let { draggingCollectionRef } = globalDndState;
255
+ if (draggingCollectionRef == null) {
256
+ clearGlobalDnDState();
257
+ }
258
+ },
259
+ });
260
+
261
+ let droppingState = useRef<DroppingState | null>(null);
262
+ let updateFocusAfterDrop = useCallback(() => {
263
+ let { state } = localState;
264
+ if (droppingState.current) {
265
+ let {
266
+ target,
267
+ collection: prevCollection,
268
+ selectedKeys: prevSelectedKeys,
269
+ focusedKey: prevFocusedKey,
270
+ isInternal,
271
+ draggingKeys,
272
+ } = droppingState.current;
273
+
274
+ // If an insert occurs during a drop, we want to immediately select these items to give
275
+ // feedback to the user that a drop occurred. Only do this if the selection didn't change
276
+ // since the drop started so we don't override if the user or application did something.
277
+ if (
278
+ state.collection.size > prevCollection.size &&
279
+ state.selectionManager.isSelectionEqual(prevSelectedKeys)
280
+ ) {
281
+ let newKeys = new Set<Key>();
282
+ let key = state.collection.getFirstKey();
283
+ while (key != null) {
284
+ let item = state.collection.getItem(key);
285
+ if (item?.type === 'item' && !prevCollection.getItem(item.key)) {
286
+ newKeys.add(item.key);
287
+ }
288
+
289
+ if (
290
+ item?.hasChildNodes &&
291
+ state.collection.getItem(item.lastChildKey!)?.type === 'item'
292
+ ) {
293
+ key = item.firstChildKey!;
294
+ } else {
295
+ key = state.collection.getKeyAfter(key);
296
+ }
297
+ }
298
+
299
+ state.selectionManager.setSelectedKeys(newKeys);
300
+
301
+ // If the focused item didn't change since the drop occurred, also focus the first
302
+ // inserted item. If selection is disabled, then also show the focus ring so there
303
+ // is some indication that items were added.
304
+ if (state.selectionManager.focusedKey === prevFocusedKey) {
305
+ let first: Key | null | undefined = newKeys.keys().next().value;
306
+ if (first != null) {
307
+ let item = state.collection.getItem(first);
308
+ let dropTarget = droppingState.current.target;
309
+ let isParentRowExpanded = (state.collection as any).expandedKeys
310
+ ? (state.collection as any).expandedKeys.has(item?.parentKey)
311
+ : false;
312
+ // If this is a cell, focus the parent row.
313
+ // eslint-disable-next-line max-depth
314
+ if (
315
+ item &&
316
+ (item?.type === 'cell' ||
317
+ (dropTarget.type === 'item' &&
318
+ dropTarget.dropPosition === 'on' &&
319
+ !isParentRowExpanded))
320
+ ) {
321
+ first = item.parentKey;
322
+ }
323
+
324
+ // eslint-disable-next-line max-depth
325
+ if (first != null) {
326
+ state.selectionManager.setFocusedKey(first);
327
+ }
328
+
329
+ // eslint-disable-next-line max-depth
330
+ if (state.selectionManager.selectionMode === 'none') {
331
+ setInteractionModality('keyboard');
332
+ }
333
+ }
334
+ }
335
+ } else if (
336
+ prevFocusedKey != null &&
337
+ state.selectionManager.focusedKey === prevFocusedKey &&
338
+ isInternal &&
339
+ target.type === 'item' &&
340
+ target.dropPosition !== 'on' &&
341
+ draggingKeys.has(state.collection.getItem(prevFocusedKey)?.parentKey)
342
+ ) {
343
+ // Focus row instead of cell when reordering.
344
+ state.selectionManager.setFocusedKey(
345
+ state.collection.getItem(prevFocusedKey)?.parentKey ?? null,
346
+ );
347
+ setInteractionModality('keyboard');
348
+ } else if (
349
+ state.selectionManager.focusedKey === prevFocusedKey &&
350
+ target.type === 'item' &&
351
+ target.dropPosition === 'on' &&
352
+ state.collection.getItem(target.key) != null
353
+ ) {
354
+ // If focus didn't move already (e.g. due to an insert), and the user dropped on an item,
355
+ // focus that item and show the focus ring to give the user feedback that the drop occurred.
356
+ // Also show the focus ring if the focused key is not selected, e.g. in case of a reorder.
357
+ state.selectionManager.setFocusedKey(target.key);
358
+ setInteractionModality('keyboard');
359
+ } else if (
360
+ state.selectionManager.focusedKey != null &&
361
+ !state.selectionManager.isSelected(state.selectionManager.focusedKey)
362
+ ) {
363
+ setInteractionModality('keyboard');
364
+ }
365
+
366
+ state.selectionManager.setFocused(true);
367
+ }
368
+ }, [localState]);
369
+
370
+ let onDrop = useCallback(
371
+ (e: DropEvent, target: DropTarget) => {
372
+ let { state } = localState;
373
+
374
+ // Save some state of the collection/selection before the drop occurs so we can compare later.
375
+ droppingState.current = {
376
+ timeout: undefined,
377
+ focusedKey: state.selectionManager.focusedKey,
378
+ collection: state.collection,
379
+ selectedKeys: state.selectionManager.selectedKeys,
380
+ draggingKeys: globalDndState.draggingKeys,
381
+ isInternal: isInternalDropOperation(ref),
382
+ target,
383
+ };
384
+
385
+ let onDropFn = localState.props.onDrop || defaultOnDrop;
386
+ onDropFn({
387
+ type: 'drop',
388
+ x: e.x, // todo
389
+ y: e.y,
390
+ target,
391
+ items: e.items,
392
+ dropOperation: e.dropOperation,
393
+ });
394
+
395
+ // Wait for a short time period after the onDrop is called to allow the data to be read asynchronously
396
+ // and for React to re-render. If the collection didn't already change during this time (handled below),
397
+ // update the focused key here.
398
+ droppingState.current.timeout = setTimeout(() => {
399
+ updateFocusAfterDrop();
400
+ droppingState.current = null;
401
+ }, 50);
402
+ },
403
+ [localState, defaultOnDrop, ref, updateFocusAfterDrop],
404
+ );
405
+
406
+ useEffect(() => {
407
+ return () => {
408
+ if (droppingState.current) {
409
+ clearTimeout(droppingState.current.timeout);
410
+ }
411
+ };
412
+ }, []);
413
+
414
+ useLayoutEffect(() => {
415
+ // If the collection changed after a drop, update the focused key.
416
+ if (droppingState.current && state.collection !== droppingState.current.collection) {
417
+ updateFocusAfterDrop();
418
+ }
419
+ });
420
+
421
+ let { direction } = useLocale();
422
+ useEffect(() => {
423
+ if (!ref.current) {
424
+ return;
425
+ }
426
+
427
+ let getNextTarget = (
428
+ target: DropTarget | null | undefined,
429
+ wrap = true,
430
+ key: 'left' | 'right' | 'up' | 'down' = 'down',
431
+ ) => {
432
+ return navigate(
433
+ localState.props.keyboardDelegate,
434
+ localState.state.collection,
435
+ target,
436
+ key,
437
+ direction === 'rtl',
438
+ wrap,
439
+ );
440
+ };
441
+
442
+ let getPreviousTarget = (target: DropTarget | null | undefined, wrap = true) => {
443
+ return getNextTarget(target, wrap, 'up');
444
+ };
445
+
446
+ let nextValidTarget = (
447
+ target: DropTarget | null | undefined,
448
+ types: Set<string>,
449
+ allowedDropOperations: DropOperation[],
450
+ getNextTarget: (target: DropTarget | null | undefined, wrap: boolean) => DropTarget | null,
451
+ wrap = true,
452
+ ): DropTarget | null => {
453
+ let seenRoot = 0;
454
+ let operation: DropOperation;
455
+ let { draggingKeys } = globalDndState;
456
+ let isInternal = isInternalDropOperation(ref);
457
+ do {
458
+ let nextTarget = getNextTarget(target, wrap);
459
+ if (!nextTarget) {
460
+ return null;
461
+ }
462
+ target = nextTarget;
463
+ operation = localState.state.getDropOperation({
464
+ target: nextTarget,
465
+ types,
466
+ allowedOperations: allowedDropOperations,
467
+ isInternal,
468
+ draggingKeys,
469
+ });
470
+ if (target.type === 'root') {
471
+ seenRoot++;
472
+ }
473
+ } while (operation === 'cancel' && !localState.state.isDropTarget(target) && seenRoot < 2);
474
+
475
+ if (operation === 'cancel') {
476
+ return null;
477
+ }
478
+
479
+ return target;
480
+ };
481
+
482
+ return DragManager.registerDropTarget({
483
+ element: ref.current,
484
+ preventFocusOnDrop: true,
485
+ getDropOperation(types, allowedOperations) {
486
+ if (localState.state.target) {
487
+ let { draggingKeys } = globalDndState;
488
+ let isInternal = isInternalDropOperation(ref);
489
+ return localState.state.getDropOperation({
490
+ target: localState.state.target,
491
+ types,
492
+ allowedOperations,
493
+ isInternal,
494
+ draggingKeys,
495
+ });
496
+ }
497
+
498
+ // Check if any of the targets accept the drop.
499
+ // TODO: should we have a faster way of doing this or e.g. for pagination?
500
+ let target = nextValidTarget(null, types, allowedOperations, getNextTarget);
501
+ return target ? 'move' : 'cancel';
502
+ },
503
+ onDropEnter(e, drag) {
504
+ let types = getTypes(drag.items);
505
+ let selectionManager = localState.state.selectionManager;
506
+ let target: DropTarget | null = null;
507
+ // Update the drop collection ref tracker for useDroppableItem's getDropOperation isInternal check
508
+ setDropCollectionRef(ref);
509
+
510
+ // When entering the droppable collection for the first time, the default drop target
511
+ // is after the focused key.
512
+ let key: Key | null | undefined = selectionManager.focusedKey;
513
+ let dropPosition: DropPosition = 'after';
514
+
515
+ // If the focused key is a cell, get the parent item instead.
516
+ // For now, we assume that individual cells cannot be dropped on.
517
+ let item = key != null ? localState.state.collection.getItem(key) : null;
518
+ if (item?.type === 'cell') {
519
+ key = item.parentKey;
520
+ }
521
+
522
+ // If the focused item is also selected, the default drop target is after the last selected item.
523
+ // But if the focused key is the first selected item, then default to before the first selected item.
524
+ // This is to make reordering lists slightly easier. If you select top down, we assume you want to
525
+ // move the items down. If you select bottom up, we assume you want to move the items up.
526
+ if (key != null && selectionManager.isSelected(key)) {
527
+ if (selectionManager.selectedKeys.size > 1 && selectionManager.firstSelectedKey === key) {
528
+ dropPosition = 'before';
529
+ } else {
530
+ key = selectionManager.lastSelectedKey;
531
+ }
532
+ }
533
+
534
+ if (key != null) {
535
+ target = {
536
+ type: 'item',
537
+ key,
538
+ dropPosition,
539
+ };
540
+
541
+ let { draggingKeys } = globalDndState;
542
+ let isInternal = isInternalDropOperation(ref);
543
+ // If the default target is not valid, find the next one that is.
544
+ if (
545
+ localState.state.getDropOperation({
546
+ target,
547
+ types,
548
+ allowedOperations: drag.allowedDropOperations,
549
+ isInternal,
550
+ draggingKeys,
551
+ }) === 'cancel'
552
+ ) {
553
+ target =
554
+ nextValidTarget(target, types, drag.allowedDropOperations, getNextTarget, false) ??
555
+ nextValidTarget(target, types, drag.allowedDropOperations, getPreviousTarget, false);
556
+ }
557
+ }
558
+
559
+ // If no focused key, then start from the root.
560
+ if (!target) {
561
+ target = nextValidTarget(null, types, drag.allowedDropOperations, getNextTarget);
562
+ }
563
+
564
+ localState.state.setTarget(target);
565
+ },
566
+ onDropExit() {
567
+ setDropCollectionRef(undefined);
568
+ localState.state.setTarget(null);
569
+ },
570
+ onDropTargetEnter(target) {
571
+ localState.state.setTarget(target);
572
+ },
573
+ onDropActivate(e, target) {
574
+ if (
575
+ target?.type === 'item' &&
576
+ target?.dropPosition === 'on' &&
577
+ typeof localState.props.onDropActivate === 'function'
578
+ ) {
579
+ localState.props.onDropActivate({
580
+ type: 'dropactivate',
581
+ x: e.x, // todo
582
+ y: e.y,
583
+ target,
584
+ });
585
+ }
586
+ },
587
+ onDrop(e, target) {
588
+ setDropCollectionRef(ref);
589
+ if (localState.state.target) {
590
+ onDrop(e, target || localState.state.target);
591
+ }
592
+ },
593
+ onKeyDown(e, drag) {
594
+ let { keyboardDelegate } = localState.props;
595
+ let types = getTypes(drag.items);
596
+ switch (e.key) {
597
+ case 'ArrowDown': {
598
+ if (keyboardDelegate.getKeyBelow) {
599
+ let target = nextValidTarget(
600
+ localState.state.target,
601
+ types,
602
+ drag.allowedDropOperations,
603
+ (target, wrap) => getNextTarget(target, wrap, 'down'),
604
+ );
605
+ localState.state.setTarget(target);
606
+ }
607
+ break;
608
+ }
609
+ case 'ArrowUp': {
610
+ if (keyboardDelegate.getKeyAbove) {
611
+ let target = nextValidTarget(
612
+ localState.state.target,
613
+ types,
614
+ drag.allowedDropOperations,
615
+ (target, wrap) => getNextTarget(target, wrap, 'up'),
616
+ );
617
+ localState.state.setTarget(target);
618
+ }
619
+ break;
620
+ }
621
+ case 'ArrowLeft': {
622
+ if (keyboardDelegate.getKeyLeftOf) {
623
+ let target = nextValidTarget(
624
+ localState.state.target,
625
+ types,
626
+ drag.allowedDropOperations,
627
+ (target, wrap) => getNextTarget(target, wrap, 'left'),
628
+ );
629
+ localState.state.setTarget(target);
630
+ }
631
+ break;
632
+ }
633
+ case 'ArrowRight': {
634
+ if (keyboardDelegate.getKeyRightOf) {
635
+ let target = nextValidTarget(
636
+ localState.state.target,
637
+ types,
638
+ drag.allowedDropOperations,
639
+ (target, wrap) => getNextTarget(target, wrap, 'right'),
640
+ );
641
+ localState.state.setTarget(target);
642
+ }
643
+ break;
644
+ }
645
+ case 'Home': {
646
+ if (keyboardDelegate.getFirstKey) {
647
+ let target = nextValidTarget(null, types, drag.allowedDropOperations, getNextTarget);
648
+ localState.state.setTarget(target);
649
+ }
650
+ break;
651
+ }
652
+ case 'End': {
653
+ if (keyboardDelegate.getLastKey) {
654
+ let target = nextValidTarget(
655
+ null,
656
+ types,
657
+ drag.allowedDropOperations,
658
+ getPreviousTarget,
659
+ );
660
+ localState.state.setTarget(target);
661
+ }
662
+ break;
663
+ }
664
+ case 'PageDown': {
665
+ if (keyboardDelegate.getKeyPageBelow) {
666
+ let target = localState.state.target;
667
+ if (!target) {
668
+ target = nextValidTarget(null, types, drag.allowedDropOperations, getNextTarget);
669
+ } else {
670
+ // If on the root, go to the item a page below the top. Otherwise a page below the current item.
671
+ let targetKey = keyboardDelegate.getFirstKey?.();
672
+ if (target.type === 'item') {
673
+ targetKey = target.key;
674
+ }
675
+ let nextKey: Key | null = null;
676
+ if (targetKey != null) {
677
+ nextKey = keyboardDelegate.getKeyPageBelow(targetKey);
678
+ }
679
+ let dropPosition = target.type === 'item' ? target.dropPosition : 'after';
680
+
681
+ // If there is no next key, or we are starting on the last key, jump to the last possible position.
682
+ if (
683
+ nextKey == null ||
684
+ (target.type === 'item' && target.key === keyboardDelegate.getLastKey?.())
685
+ ) {
686
+ nextKey = keyboardDelegate.getLastKey?.() ?? null;
687
+ dropPosition = 'after';
688
+ }
689
+
690
+ if (nextKey == null) {
691
+ break;
692
+ }
693
+ target = {
694
+ type: 'item',
695
+ key: nextKey,
696
+ dropPosition,
697
+ };
698
+
699
+ // If the target does not accept the drop, find the next valid target.
700
+ // If no next valid target, find the previous valid target.
701
+ let { draggingCollectionRef, draggingKeys } = globalDndState;
702
+ let isInternal = draggingCollectionRef?.current === ref?.current;
703
+ let operation = localState.state.getDropOperation({
704
+ target,
705
+ types,
706
+ allowedOperations: drag.allowedDropOperations,
707
+ isInternal,
708
+ draggingKeys,
709
+ });
710
+ if (operation === 'cancel') {
711
+ target =
712
+ nextValidTarget(
713
+ target,
714
+ types,
715
+ drag.allowedDropOperations,
716
+ getNextTarget,
717
+ false,
718
+ ) ??
719
+ nextValidTarget(
720
+ target,
721
+ types,
722
+ drag.allowedDropOperations,
723
+ getPreviousTarget,
724
+ false,
725
+ );
726
+ }
727
+ }
728
+
729
+ localState.state.setTarget(target ?? localState.state.target);
730
+ }
731
+ break;
732
+ }
733
+ case 'PageUp': {
734
+ if (!keyboardDelegate.getKeyPageAbove) {
735
+ break;
736
+ }
737
+
738
+ let target = localState.state.target;
739
+ if (!target) {
740
+ target = nextValidTarget(null, types, drag.allowedDropOperations, getPreviousTarget);
741
+ } else if (target.type === 'item') {
742
+ // If at the top already, switch to the root. Otherwise navigate a page up.
743
+ if (target.key === keyboardDelegate.getFirstKey?.()) {
744
+ target = {
745
+ type: 'root',
746
+ };
747
+ } else {
748
+ let nextKey: Key | null | undefined = keyboardDelegate.getKeyPageAbove(target.key);
749
+ let dropPosition = target.dropPosition;
750
+ if (nextKey == null) {
751
+ nextKey = keyboardDelegate.getFirstKey?.();
752
+ dropPosition = 'before';
753
+ }
754
+
755
+ if (nextKey == null) {
756
+ break;
757
+ }
758
+ target = {
759
+ type: 'item',
760
+ key: nextKey,
761
+ dropPosition,
762
+ };
763
+ }
764
+
765
+ // If the target does not accept the drop, find the previous valid target.
766
+ // If no next valid target, find the next valid target.
767
+ let { draggingKeys } = globalDndState;
768
+ let isInternal = isInternalDropOperation(ref);
769
+ let operation = localState.state.getDropOperation({
770
+ target,
771
+ types,
772
+ allowedOperations: drag.allowedDropOperations,
773
+ isInternal,
774
+ draggingKeys,
775
+ });
776
+ if (operation === 'cancel') {
777
+ target =
778
+ nextValidTarget(
779
+ target,
780
+ types,
781
+ drag.allowedDropOperations,
782
+ getPreviousTarget,
783
+ false,
784
+ ) ??
785
+ nextValidTarget(target, types, drag.allowedDropOperations, getNextTarget, false);
786
+ }
787
+ }
788
+
789
+ localState.state.setTarget(target ?? localState.state.target);
790
+ break;
791
+ }
792
+ }
793
+ localState.props.onKeyDown?.(e);
794
+ },
795
+ });
796
+ }, [localState, ref, onDrop, direction]);
797
+
798
+ let id = useId();
799
+ droppableCollectionMap.set(state, { id, ref });
800
+ return {
801
+ collectionProps: mergeProps(dropProps, {
802
+ id,
803
+ // Remove description from collection element. If dropping on the entire collection,
804
+ // there should be a drop indicator that has this description, so no need to double announce.
805
+ 'aria-describedby': null,
806
+ }),
807
+ };
808
+ }