@octanejs/aria 0.0.39 → 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,408 @@
1
+ /** @jsxImportSource octane */
2
+ // Ported from adobe/react-spectrum@1c84a49a1faf50b571c84e00bcf9c60b22ddd03e (packages/react-stately/src/virtualizer/Virtualizer.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 { ChildView, ReusableView, RootView } from './ReusableView';
16
+ import { Collection, Key } from '@react-types/shared';
17
+ import {
18
+ InvalidationContext,
19
+ Mutable,
20
+ VirtualizerDelegate,
21
+ VirtualizerRenderOptions,
22
+ } from './types';
23
+ import { isSetEqual } from './utils';
24
+ import { Layout } from './Layout';
25
+ import { LayoutInfo } from './LayoutInfo';
26
+ import { OverscanManager } from './OverscanManager';
27
+ import { Point } from './Point';
28
+ import { Rect } from './Rect';
29
+ import { Size } from './Size';
30
+
31
+ interface VirtualizerOptions<T extends object, V> {
32
+ delegate: VirtualizerDelegate<T, V>;
33
+ collection: Collection<T>;
34
+ layout: Layout<T>;
35
+ }
36
+
37
+ /**
38
+ * The Virtualizer class renders a scrollable collection of data using customizable layouts.
39
+ * It supports very large collections by only rendering visible views to the DOM, reusing
40
+ * them as you scroll. Virtualizer can present any type of view, including non-item views
41
+ * such as section headers and footers.
42
+ *
43
+ * Virtualizer uses `Layout` objects to compute what views should be visible, and how
44
+ * to position and style them. This means that virtualizer can have its items arranged in
45
+ * a stack, a grid, a circle, or any other layout you can think of. The layout can be changed
46
+ * dynamically at runtime as well.
47
+ *
48
+ * Layouts produce information on what views should appear in the virtualizer, but do not create the
49
+ * views themselves directly. It is the responsibility of the `VirtualizerDelegate` object to render
50
+ * elements for each layout info. The virtualizer manages a set of `ReusableView` objects, which are
51
+ * reused as the user scrolls by swapping their content with cached elements returned by the
52
+ * delegate.
53
+ */
54
+ export class Virtualizer<T extends object, V> {
55
+ /**
56
+ * The virtualizer delegate. The delegate is used by the virtualizer
57
+ * to create and configure views.
58
+ */
59
+ delegate: VirtualizerDelegate<T, V>;
60
+
61
+ /** The current content of the virtualizer. */
62
+ readonly collection: Collection<T>;
63
+ /** The layout object that determines the visible views. */
64
+ readonly layout: Layout<T>;
65
+ /** The size of the scrollable content. */
66
+ readonly contentSize: Size;
67
+ /** The currently visible rectangle. */
68
+ readonly visibleRect: Rect;
69
+ /** The size of the virtualizer scroll view. */
70
+ readonly size: Size;
71
+ /** The set of persisted keys that are always present in the DOM, even if not currently in view. */
72
+ readonly persistedKeys: Set<Key>;
73
+
74
+ private _visibleViews: Map<Key, ChildView<T, V>>;
75
+ private _renderedContent: WeakMap<T, V>;
76
+ private _rootView: RootView<T, V>;
77
+ private _isScrolling: boolean;
78
+ private _invalidationContext: InvalidationContext;
79
+ private _overscanManager: OverscanManager;
80
+
81
+ constructor(options: VirtualizerOptions<T, V>) {
82
+ this.delegate = options.delegate;
83
+ this.collection = options.collection;
84
+ this.layout = options.layout;
85
+ this.contentSize = new Size();
86
+ this.visibleRect = new Rect();
87
+ this.size = new Size();
88
+ this.persistedKeys = new Set();
89
+ this._visibleViews = new Map();
90
+ this._renderedContent = new WeakMap();
91
+ this._rootView = new RootView(this);
92
+ this._isScrolling = false;
93
+ this._invalidationContext = {};
94
+ this._overscanManager = new OverscanManager();
95
+ }
96
+
97
+ /** Returns whether the given key, or an ancestor, is persisted. */
98
+ isPersistedKey(key: Key): boolean {
99
+ // Quick check if the key is directly in the set of persisted keys.
100
+ if (this.persistedKeys.has(key)) {
101
+ return true;
102
+ }
103
+
104
+ // If not, check if the key is an ancestor of any of the persisted keys.
105
+ for (let k of this.persistedKeys) {
106
+ while (k != null) {
107
+ let layoutInfo = this.layout.getLayoutInfo(k);
108
+ if (!layoutInfo || layoutInfo.parentKey == null) {
109
+ break;
110
+ }
111
+
112
+ k = layoutInfo.parentKey;
113
+
114
+ if (k === key) {
115
+ return true;
116
+ }
117
+ }
118
+ }
119
+
120
+ return false;
121
+ }
122
+
123
+ private getParentView(layoutInfo: LayoutInfo): ReusableView<T, V> | undefined {
124
+ return layoutInfo.parentKey != null
125
+ ? this._visibleViews.get(layoutInfo.parentKey)
126
+ : this._rootView;
127
+ }
128
+
129
+ private getReusableView(layoutInfo: LayoutInfo): ChildView<T, V> {
130
+ let parentView = this.getParentView(layoutInfo)!;
131
+ let view = parentView.getReusableView(layoutInfo.type);
132
+ view.layoutInfo = layoutInfo;
133
+ this._renderView(view);
134
+ return view;
135
+ }
136
+
137
+ private _renderView(reusableView: ReusableView<T, V>) {
138
+ if (reusableView.layoutInfo) {
139
+ let { type, key, content } = reusableView.layoutInfo;
140
+ reusableView.content = content || this.collection.getItem(key);
141
+ reusableView.rendered = this._renderContent(type, reusableView.content);
142
+ }
143
+ }
144
+
145
+ private _renderContent(type: string, content: T | null) {
146
+ let cached = content != null ? this._renderedContent.get(content) : null;
147
+ if (cached != null) {
148
+ return cached;
149
+ }
150
+
151
+ let rendered = this.delegate.renderView(type, content);
152
+ if (content) {
153
+ this._renderedContent.set(content, rendered);
154
+ }
155
+ return rendered;
156
+ }
157
+
158
+ /**
159
+ * Returns the key for the item view currently at the given point.
160
+ */
161
+ keyAtPoint(point: Point): Key | null {
162
+ let rect = new Rect(point.x, point.y, 1, 1);
163
+ let layoutInfos = rect.area === 0 ? [] : this.layout.getVisibleLayoutInfos(rect);
164
+
165
+ // Layout may return multiple layout infos in the case of
166
+ // persisted keys, so find the first one that actually intersects.
167
+ for (let layoutInfo of layoutInfos) {
168
+ if (layoutInfo.rect.intersects(rect)) {
169
+ return layoutInfo.key;
170
+ }
171
+ }
172
+
173
+ return null;
174
+ }
175
+
176
+ private relayout(context: InvalidationContext = {}) {
177
+ // Update the layout
178
+ this.layout.update(context);
179
+ (this as Mutable<this>).contentSize = this.layout.getContentSize();
180
+
181
+ // Constrain scroll position.
182
+ // If the content changed, scroll to the top.
183
+ let visibleRect = this.visibleRect;
184
+ let contentOffsetX = context.contentChanged ? 0 : visibleRect.x;
185
+ let contentOffsetY = context.contentChanged ? 0 : visibleRect.y;
186
+ contentOffsetX = Math.max(
187
+ 0,
188
+ Math.min(this.contentSize.width - visibleRect.width, contentOffsetX),
189
+ );
190
+ contentOffsetY = Math.max(
191
+ 0,
192
+ Math.min(this.contentSize.height - visibleRect.height, contentOffsetY),
193
+ );
194
+
195
+ if (contentOffsetX !== visibleRect.x || contentOffsetY !== visibleRect.y) {
196
+ // If the offset changed, trigger a new re-render.
197
+ let rect = new Rect(contentOffsetX, contentOffsetY, visibleRect.width, visibleRect.height);
198
+ this.delegate.setVisibleRect(rect);
199
+ } else {
200
+ this.updateSubviews();
201
+ }
202
+ }
203
+
204
+ getVisibleLayoutInfos(): Map<Key, LayoutInfo> {
205
+ let isTestEnv = process.env.NODE_ENV === 'test' && !process.env.VIRT_ON;
206
+ let isClientWidthMocked =
207
+ isTestEnv &&
208
+ typeof HTMLElement !== 'undefined' &&
209
+ Object.getOwnPropertyNames(HTMLElement.prototype).includes('clientWidth');
210
+ let isClientHeightMocked =
211
+ isTestEnv &&
212
+ typeof HTMLElement !== 'undefined' &&
213
+ Object.getOwnPropertyNames(HTMLElement.prototype).includes('clientHeight');
214
+
215
+ let rect: Rect;
216
+ if (isTestEnv && !(isClientWidthMocked && isClientHeightMocked)) {
217
+ rect = new Rect(0, 0, this.contentSize.width, this.contentSize.height);
218
+ } else {
219
+ rect = this._overscanManager.getOverscannedRect();
220
+ }
221
+ let layoutInfos = this.layout.getVisibleLayoutInfos(rect);
222
+ let map = new Map();
223
+ for (let layoutInfo of layoutInfos) {
224
+ map.set(layoutInfo.key, layoutInfo);
225
+ }
226
+
227
+ return map;
228
+ }
229
+
230
+ private updateSubviews() {
231
+ let visibleLayoutInfos = this.getVisibleLayoutInfos();
232
+
233
+ let removed = new Set<ChildView<T, V>>();
234
+ for (let [key, view] of this._visibleViews) {
235
+ let layoutInfo = visibleLayoutInfos.get(key);
236
+ // If a view's parent changed, treat it as a delete and re-create in the new parent.
237
+ if (!layoutInfo || view.parent !== this.getParentView(layoutInfo)) {
238
+ this._visibleViews.delete(key);
239
+ view.parent.reuseChild(view);
240
+ removed.add(view); // Defer removing in case we reuse this view.
241
+ }
242
+ }
243
+
244
+ for (let [key, layoutInfo] of visibleLayoutInfos) {
245
+ let view = this._visibleViews.get(key);
246
+ if (!view) {
247
+ view = this.getReusableView(layoutInfo);
248
+ view.parent.children.add(view);
249
+ this._visibleViews.set(key, view);
250
+ removed.delete(view);
251
+ } else {
252
+ view.layoutInfo = layoutInfo;
253
+
254
+ let item = this.collection.getItem(layoutInfo.key);
255
+ if (view.content !== item) {
256
+ if (view.content != null) {
257
+ this._renderedContent.delete(view.content);
258
+ }
259
+ this._renderView(view);
260
+ }
261
+ }
262
+ }
263
+
264
+ // The remaining views in `removed` were not reused to render new items.
265
+ // They should be removed from the DOM. We also clear the reusable view queue
266
+ // here since there's no point holding onto views that have been removed.
267
+ // Doing so hurts performance in the future when reusing elements due to FIFO order.
268
+ for (let view of removed) {
269
+ view.parent.children.delete(view);
270
+ view.parent.reusableViews.clear();
271
+ }
272
+
273
+ // Reordering DOM nodes is costly, so we defer this until scrolling stops.
274
+ // DOM order does not affect visual order (due to absolute positioning),
275
+ // but does matter for assistive technology users.
276
+ if (!this._isScrolling) {
277
+ // Layout infos must be in topological order (parents before children).
278
+ for (let key of visibleLayoutInfos.keys()) {
279
+ let view = this._visibleViews.get(key)!;
280
+ view.parent.children.delete(view);
281
+ view.parent.children.add(view);
282
+ }
283
+ }
284
+ }
285
+
286
+ /** Performs layout and updates visible views as needed. */
287
+ render(opts: VirtualizerRenderOptions<T>): ReusableView<T, V>[] {
288
+ let mutableThis: Mutable<this> = this;
289
+ let needsLayout = false;
290
+ let offsetChanged = false;
291
+ let sizeChanged = false;
292
+ let itemSizeChanged = false;
293
+ let layoutOptionsChanged = false;
294
+ let needsUpdate = false;
295
+
296
+ if (opts.collection !== this.collection) {
297
+ mutableThis.collection = opts.collection;
298
+ needsLayout = true;
299
+ }
300
+
301
+ if (opts.layout !== this.layout || this.layout.virtualizer !== this) {
302
+ if (this.layout) {
303
+ this.layout.virtualizer = null;
304
+ }
305
+
306
+ opts.layout.virtualizer = this;
307
+ mutableThis.layout = opts.layout;
308
+ needsLayout = true;
309
+ }
310
+
311
+ if (opts.persistedKeys && !isSetEqual(opts.persistedKeys, this.persistedKeys)) {
312
+ mutableThis.persistedKeys = opts.persistedKeys;
313
+ needsUpdate = true;
314
+ }
315
+
316
+ if (!this.visibleRect.equals(opts.visibleRect) || !this.size.equals(opts.size)) {
317
+ this._overscanManager.setVisibleRect(opts.visibleRect);
318
+
319
+ // Create a rectangle using the scroll position and layout size of the scroll view. This is not the same
320
+ // as the visibleRect, whose width and height may change during window scrolling.
321
+ let oldRect = new Rect(
322
+ this.visibleRect.x,
323
+ this.visibleRect.y,
324
+ this.size.width,
325
+ this.size.height,
326
+ );
327
+ let newRect = new Rect(
328
+ opts.visibleRect.x,
329
+ opts.visibleRect.y,
330
+ opts.size.width,
331
+ opts.size.height,
332
+ );
333
+ let shouldInvalidate = this.layout.shouldInvalidate(newRect, oldRect);
334
+
335
+ if (shouldInvalidate) {
336
+ offsetChanged = !opts.visibleRect.pointEquals(this.visibleRect);
337
+ sizeChanged = !this.size.equals(opts.size);
338
+ needsLayout = true;
339
+ } else {
340
+ needsUpdate = true;
341
+ }
342
+
343
+ mutableThis.visibleRect = opts.visibleRect;
344
+ mutableThis.size = opts.size;
345
+ }
346
+
347
+ if (opts.invalidationContext !== this._invalidationContext) {
348
+ if (opts.invalidationContext) {
349
+ sizeChanged ||= opts.invalidationContext.sizeChanged || false;
350
+ offsetChanged ||= opts.invalidationContext.offsetChanged || false;
351
+ itemSizeChanged ||= opts.invalidationContext.itemSizeChanged || false;
352
+ layoutOptionsChanged ||=
353
+ opts.invalidationContext.layoutOptions != null &&
354
+ this._invalidationContext.layoutOptions != null &&
355
+ opts.invalidationContext.layoutOptions !== this._invalidationContext.layoutOptions &&
356
+ this.layout.shouldInvalidateLayoutOptions(
357
+ opts.invalidationContext.layoutOptions,
358
+ this._invalidationContext.layoutOptions,
359
+ );
360
+ needsLayout ||= itemSizeChanged || sizeChanged || offsetChanged || layoutOptionsChanged;
361
+ }
362
+ this._invalidationContext = opts.invalidationContext;
363
+ }
364
+
365
+ if (opts.isScrolling !== this._isScrolling) {
366
+ this._isScrolling = opts.isScrolling;
367
+ if (!opts.isScrolling) {
368
+ // Update to fix the DOM order after scrolling.
369
+ needsUpdate = true;
370
+ }
371
+ }
372
+
373
+ if (needsLayout) {
374
+ this.relayout({
375
+ offsetChanged,
376
+ sizeChanged,
377
+ itemSizeChanged,
378
+ layoutOptionsChanged,
379
+ layoutOptions: this._invalidationContext.layoutOptions,
380
+ });
381
+ } else if (needsUpdate) {
382
+ this.updateSubviews();
383
+ }
384
+
385
+ return Array.from(this._rootView.children);
386
+ }
387
+
388
+ getVisibleView(key: Key): ReusableView<T, V> | undefined {
389
+ return this._visibleViews.get(key);
390
+ }
391
+
392
+ invalidate(context: InvalidationContext): void {
393
+ this.delegate.invalidate(context);
394
+ }
395
+
396
+ updateItemSize(key: Key, size: Size): void {
397
+ if (!this.layout.updateItemSize) {
398
+ return;
399
+ }
400
+
401
+ let changed = this.layout.updateItemSize(key, size);
402
+ if (changed) {
403
+ this.invalidate({
404
+ itemSizeChanged: true,
405
+ });
406
+ }
407
+ }
408
+ }
@@ -0,0 +1,48 @@
1
+ /** @jsxImportSource octane */
2
+ // Ported from adobe/react-spectrum@1c84a49a1faf50b571c84e00bcf9c60b22ddd03e (packages/react-stately/src/virtualizer/types.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 { Collection, Key } from '@react-types/shared';
16
+ import { Layout } from './Layout';
17
+ import { Rect } from './Rect';
18
+ import { Size } from './Size';
19
+
20
+ export interface InvalidationContext<O = any> {
21
+ contentChanged?: boolean;
22
+ offsetChanged?: boolean;
23
+ sizeChanged?: boolean;
24
+ itemSizeChanged?: boolean;
25
+ layoutOptionsChanged?: boolean;
26
+ layoutOptions?: O;
27
+ }
28
+
29
+ export interface VirtualizerDelegate<T extends object, V> {
30
+ setVisibleRect(rect: Rect): void;
31
+ renderView(type: string, content: T | null): V;
32
+ invalidate(ctx: InvalidationContext): void;
33
+ }
34
+
35
+ export interface VirtualizerRenderOptions<T extends object, O = any> {
36
+ layout: Layout<T>;
37
+ collection: Collection<T>;
38
+ persistedKeys?: Set<Key> | null;
39
+ visibleRect: Rect;
40
+ size: Size;
41
+ invalidationContext: InvalidationContext;
42
+ isScrolling: boolean;
43
+ layoutOptions?: O;
44
+ }
45
+
46
+ export type Mutable<T> = {
47
+ -readonly [P in keyof T]: T[P];
48
+ };
@@ -0,0 +1,138 @@
1
+ /** @jsxImportSource octane */
2
+ // Ported from adobe/react-spectrum@1c84a49a1faf50b571c84e00bcf9c60b22ddd03e (packages/react-stately/src/virtualizer/useVirtualizerState.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 { Collection, Key } from '@react-types/shared';
16
+ import { InvalidationContext } from './types';
17
+ import { Layout } from './Layout';
18
+ import React, { useCallback, useMemo, useRef, useState } from '../../compat/react';
19
+ import { Rect } from './Rect';
20
+ import { ReusableView } from './ReusableView';
21
+ import { Size } from './Size';
22
+ import { Virtualizer } from './Virtualizer';
23
+
24
+ // During SSR, React emits a warning when calling useLayoutEffect.
25
+ // Since neither useLayoutEffect nor useEffect run on the server,
26
+ // we can suppress this by replace it with a noop on the server.
27
+ export const useLayoutEffect: typeof React.useLayoutEffect =
28
+ typeof document !== 'undefined' ? React.useLayoutEffect : () => {};
29
+
30
+ interface VirtualizerProps<T extends object, V, O> {
31
+ renderView(type: string, content: T | null): V;
32
+ layout: Layout<T>;
33
+ collection: Collection<T>;
34
+ onVisibleRectChange(rect: Rect): void;
35
+ persistedKeys?: Set<Key> | null;
36
+ layoutOptions?: O;
37
+ allowsWindowScrolling?: boolean;
38
+ }
39
+
40
+ export interface VirtualizerState<T extends object, V> {
41
+ visibleViews: ReusableView<T, V>[];
42
+ setVisibleRect: (rect: Rect) => void;
43
+ size: Size;
44
+ setSize: (size: Size) => void;
45
+ contentSize: Size;
46
+ virtualizer: Virtualizer<T, V>;
47
+ isScrolling: boolean;
48
+ startScrolling: () => void;
49
+ endScrolling: () => void;
50
+ }
51
+
52
+ export function useVirtualizerState<T extends object, V, O = any>(
53
+ opts: VirtualizerProps<T, V, O>,
54
+ ): VirtualizerState<T, V> {
55
+ let [visibleRect, setVisibleRect] = useState(new Rect(0, 0, 0, 0));
56
+ let [size, setSize] = useState(new Size());
57
+ let [isScrolling, setScrolling] = useState(false);
58
+ let [invalidationContext, setInvalidationContext] = useState<InvalidationContext>({});
59
+ let visibleRectChanged = useRef(false);
60
+ let [virtualizer] = useState(
61
+ () =>
62
+ new Virtualizer<T, V>({
63
+ collection: opts.collection,
64
+ layout: opts.layout,
65
+ delegate: {
66
+ setVisibleRect(rect) {
67
+ setVisibleRect(rect);
68
+ visibleRectChanged.current = true;
69
+ },
70
+ // TODO: should changing these invalidate the entire cache?
71
+ renderView: opts.renderView,
72
+ invalidate: setInvalidationContext,
73
+ },
74
+ }),
75
+ );
76
+
77
+ // onVisibleRectChange must be called from an effect, not during render.
78
+ useLayoutEffect(() => {
79
+ if (visibleRectChanged.current) {
80
+ visibleRectChanged.current = false;
81
+ opts.onVisibleRectChange(visibleRect);
82
+ }
83
+ });
84
+
85
+ let mergedInvalidationContext = useMemo(() => {
86
+ if (opts.layoutOptions != null) {
87
+ return { ...invalidationContext, layoutOptions: opts.layoutOptions };
88
+ }
89
+ return invalidationContext;
90
+ }, [invalidationContext, opts.layoutOptions]);
91
+
92
+ let visibleViews = virtualizer.render({
93
+ layout: opts.layout,
94
+ collection: opts.collection,
95
+ persistedKeys: opts.persistedKeys,
96
+ layoutOptions: opts.layoutOptions,
97
+ visibleRect,
98
+ size: opts.allowsWindowScrolling ? size : visibleRect,
99
+ invalidationContext: mergedInvalidationContext,
100
+ isScrolling,
101
+ });
102
+
103
+ let contentSize = virtualizer.contentSize;
104
+
105
+ let startScrolling = useCallback(() => {
106
+ setScrolling(true);
107
+ }, []);
108
+ let endScrolling = useCallback(() => {
109
+ setScrolling(false);
110
+ }, []);
111
+
112
+ let state = useMemo(
113
+ () => ({
114
+ virtualizer,
115
+ visibleViews,
116
+ setVisibleRect,
117
+ size,
118
+ setSize,
119
+ contentSize,
120
+ isScrolling,
121
+ startScrolling,
122
+ endScrolling,
123
+ }),
124
+ [
125
+ virtualizer,
126
+ visibleViews,
127
+ setVisibleRect,
128
+ size,
129
+ setSize,
130
+ contentSize,
131
+ isScrolling,
132
+ startScrolling,
133
+ endScrolling,
134
+ ],
135
+ );
136
+
137
+ return state;
138
+ }
@@ -0,0 +1,32 @@
1
+ /** @jsxImportSource octane */
2
+ // Ported from adobe/react-spectrum@1c84a49a1faf50b571c84e00bcf9c60b22ddd03e (packages/react-stately/src/virtualizer/utils.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
+ /** Returns whether two sets are equal. */
16
+ export function isSetEqual<T>(a: Set<T>, b: Set<T>): boolean {
17
+ if (a === b) {
18
+ return true;
19
+ }
20
+
21
+ if (a.size !== b.size) {
22
+ return false;
23
+ }
24
+
25
+ for (let key of a) {
26
+ if (!b.has(key)) {
27
+ return false;
28
+ }
29
+ }
30
+
31
+ return true;
32
+ }
@@ -179,6 +179,9 @@ export function useTextField(...args: any[]): TextFieldAria {
179
179
  subSlot(slot, 'field'),
180
180
  );
181
181
  let domProps = filterDOMProps(props, { labelable: true });
182
+ // `onChange` above is the public value callback consumed by useControlledState,
183
+ // not a native DOM commit handler. Octane wires per-edit updates through onInput.
184
+ delete domProps.onChange;
182
185
 
183
186
  const inputOnlyProps = {
184
187
  type,