@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,793 @@
1
+ /** @jsxImportSource octane */
2
+ // Ported from adobe/react-spectrum@1c84a49a1faf50b571c84e00bcf9c60b22ddd03e (packages/react-stately/src/layout/TableLayout.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 { DropTarget, ItemDropTarget, Key } from '@react-types/shared';
16
+ import { getChildNodes } from '../collections/getChildNodes';
17
+ import { GridNode } from '../grid/GridCollection';
18
+ import { InvalidationContext } from '../virtualizer/types';
19
+ import { LayoutInfo } from '../virtualizer/LayoutInfo';
20
+ import { LayoutNode, ListLayout, ListLayoutOptions } from './ListLayout';
21
+ import { Point } from '../virtualizer/Point';
22
+ import { Rect } from '../virtualizer/Rect';
23
+ import { Size } from '../virtualizer/Size';
24
+ import { ITableCollection as TableCollection } from '../table/TableCollection';
25
+ import { TableColumnLayout } from '../table/TableColumnLayout';
26
+
27
+ export interface TableLayoutProps extends Omit<
28
+ ListLayoutOptions,
29
+ | 'orientation'
30
+ | 'rowSize'
31
+ | 'estimatedRowSize'
32
+ | 'headingSize'
33
+ | 'estimatedHeadingSize'
34
+ | 'loaderSize'
35
+ > {
36
+ /**
37
+ * The fixed height of a row in px.
38
+ *
39
+ * @default 48
40
+ */
41
+ rowHeight?: number;
42
+ /**
43
+ * The estimated height of a row, when row heights are variable.
44
+ */
45
+ estimatedRowHeight?: number;
46
+ /**
47
+ * The fixed height of a section header in px.
48
+ *
49
+ * @default 48
50
+ */
51
+ headingHeight?: number;
52
+ /**
53
+ * The estimated height of a section header, when the height is variable.
54
+ */
55
+ estimatedHeadingHeight?: number;
56
+ /**
57
+ * The fixed height of a loader element in px. This loader is specifically for "load more"
58
+ * elements rendered when loading more rows at the root level or inside nested row/sections.
59
+ *
60
+ * @default 48
61
+ */
62
+ loaderHeight?: number;
63
+ columnWidths?: Map<Key, number>;
64
+ }
65
+
66
+ const DEFAULT_ROW_HEIGHT = 48;
67
+
68
+ /**
69
+ * TableLayout is a virtualizer Layout implementation that arranges
70
+ * items in rows and columns.
71
+ */
72
+ export class TableLayout<T, O extends TableLayoutProps = TableLayoutProps> extends ListLayout<
73
+ T,
74
+ O
75
+ > {
76
+ protected lastCollection: TableCollection<T> | null = null;
77
+ private columnWidths: Map<Key, number> = new Map();
78
+ private stickyColumnIndices: number[];
79
+ private lastPersistedKeys: Set<Key> | null = null;
80
+ private persistedIndices: Map<Key, number[]> = new Map();
81
+
82
+ constructor(options?: TableLayoutProps) {
83
+ super(options);
84
+ this.stickyColumnIndices = [];
85
+ }
86
+
87
+ // Backward compatibility for subclassing.
88
+ protected get collection(): TableCollection<T> {
89
+ return this.virtualizer!.collection as TableCollection<T>;
90
+ }
91
+
92
+ // Preserve the old rowHeight/other "height" properties since Table doesn't support a "horizontal" orientation
93
+ protected get rowHeight(): number | null {
94
+ return super.rowHeight;
95
+ }
96
+
97
+ protected get estimatedRowHeight(): number | null {
98
+ return super.estimatedRowHeight;
99
+ }
100
+
101
+ protected get headingHeight(): number | null {
102
+ return super.headingHeight;
103
+ }
104
+
105
+ protected get estimatedHeadingHeight(): number | null {
106
+ return super.estimatedHeadingHeight;
107
+ }
108
+
109
+ protected get loaderHeight(): number | null {
110
+ return super.loaderHeight;
111
+ }
112
+
113
+ private columnsChanged(
114
+ newCollection: TableCollection<T>,
115
+ oldCollection: TableCollection<T> | null,
116
+ ) {
117
+ return (
118
+ !oldCollection ||
119
+ (newCollection.columns !== oldCollection.columns &&
120
+ newCollection.columns.length !== oldCollection.columns.length) ||
121
+ newCollection.columns.some(
122
+ (c, i) =>
123
+ c.key !== oldCollection.columns[i].key ||
124
+ c.props.width !== oldCollection.columns[i].props.width ||
125
+ c.props.minWidth !== oldCollection.columns[i].props.minWidth ||
126
+ c.props.maxWidth !== oldCollection.columns[i].props.maxWidth,
127
+ )
128
+ );
129
+ }
130
+
131
+ shouldInvalidateLayoutOptions(newOptions: O, oldOptions: O): boolean {
132
+ return (
133
+ newOptions.columnWidths !== oldOptions.columnWidths ||
134
+ super.shouldInvalidateLayoutOptions(newOptions, oldOptions)
135
+ );
136
+ }
137
+
138
+ update(invalidationContext: InvalidationContext<O>): void {
139
+ let newCollection = this.virtualizer!.collection as TableCollection<T>;
140
+
141
+ // If columnWidths were provided via layoutOptions, update those.
142
+ // Otherwise, calculate column widths ourselves.
143
+ if (invalidationContext.layoutOptions?.columnWidths) {
144
+ for (const [key, val] of invalidationContext.layoutOptions.columnWidths) {
145
+ if (this.columnWidths.get(key) !== val) {
146
+ this.columnWidths = invalidationContext.layoutOptions.columnWidths;
147
+ invalidationContext.sizeChanged = true;
148
+ break;
149
+ }
150
+ }
151
+ } else if (
152
+ invalidationContext.sizeChanged ||
153
+ this.columnsChanged(newCollection, this.lastCollection)
154
+ ) {
155
+ let columnLayout = new TableColumnLayout({});
156
+ this.columnWidths = columnLayout.buildColumnWidths(
157
+ this.virtualizer!.size.width - this.padding * 2,
158
+ newCollection,
159
+ new Map(),
160
+ );
161
+ invalidationContext.sizeChanged = true;
162
+ }
163
+
164
+ super.update(invalidationContext);
165
+ }
166
+
167
+ protected buildCollection(): LayoutNode[] {
168
+ this.stickyColumnIndices = [];
169
+
170
+ let collection = this.virtualizer!.collection as TableCollection<T>;
171
+ for (let column of collection.columns) {
172
+ // The selection cell and any other sticky columns always need to be visible.
173
+ // In addition, row headers need to be in the DOM for accessibility labeling.
174
+ if (this.isStickyColumn(column) || collection.rowHeaderColumnKeys.has(column.key)) {
175
+ this.stickyColumnIndices.push(column.index);
176
+ }
177
+ }
178
+
179
+ let layoutNodes: LayoutNode[] = [];
180
+ let y = 0;
181
+ let width = 0;
182
+
183
+ if (!collection.head) {
184
+ let header = this.buildTableHeader();
185
+ this.layoutNodes.set(header.layoutInfo.key, header);
186
+ let body = this.buildBody(header.layoutInfo.rect.maxY + this.gap);
187
+ body.layoutInfo.rect.width = Math.max(
188
+ header.layoutInfo.rect.width,
189
+ body.layoutInfo.rect.width,
190
+ );
191
+ y = body.layoutInfo.rect.maxY;
192
+ width = body.layoutInfo.rect.width;
193
+ layoutNodes = [header, body];
194
+ } else {
195
+ for (let node of collection) {
196
+ switch (node.type) {
197
+ case 'tableheader': {
198
+ let header = this.buildTableHeader();
199
+ y = header.layoutInfo.rect.maxY + this.gap;
200
+ width = Math.max(width, header.layoutInfo.rect.width);
201
+ this.layoutNodes.set(header.layoutInfo.key, header);
202
+ layoutNodes.push(header);
203
+ break;
204
+ }
205
+ case 'tablebody':
206
+ case 'tablefooter': {
207
+ let body = this.buildRowGroup(y, node);
208
+ y = body.layoutInfo.rect.maxY + this.gap;
209
+ width = Math.max(width, body.layoutInfo.rect.width);
210
+ this.layoutNodes.set(body.layoutInfo.key, body);
211
+ layoutNodes.push(body);
212
+ break;
213
+ }
214
+ }
215
+ }
216
+
217
+ if (y > 0) {
218
+ y -= this.gap;
219
+ }
220
+
221
+ for (let layoutNode of layoutNodes) {
222
+ layoutNode.layoutInfo.rect.width = width;
223
+ }
224
+ }
225
+
226
+ this.lastPersistedKeys = null;
227
+ this.contentSize = new Size(width + this.padding * 2, y + this.padding);
228
+ return layoutNodes;
229
+ }
230
+
231
+ protected buildTableHeader(): LayoutNode {
232
+ let collection = this.virtualizer!.collection as TableCollection<T>;
233
+ let rect = new Rect(this.padding, this.padding, 0, 0);
234
+ let layoutInfo = new LayoutInfo('header', collection.head?.key ?? 'header', rect);
235
+ layoutInfo.isSticky = true;
236
+ layoutInfo.zIndex = 1;
237
+
238
+ let y = this.padding;
239
+ let width = 0;
240
+ let children: LayoutNode[] = [];
241
+ for (let headerRow of collection.headerRows) {
242
+ let layoutNode = this.buildChild(headerRow, this.padding, y, layoutInfo.key);
243
+ layoutNode.layoutInfo.parentKey = layoutInfo.key;
244
+ y = layoutNode.layoutInfo.rect.maxY;
245
+ width = Math.max(width, layoutNode.layoutInfo.rect.width);
246
+ layoutNode.index = children.length;
247
+ children.push(layoutNode);
248
+ }
249
+
250
+ rect.width = width;
251
+ rect.height = y - this.padding;
252
+
253
+ return {
254
+ layoutInfo,
255
+ children,
256
+ validRect: layoutInfo.rect,
257
+ node: collection.head,
258
+ };
259
+ }
260
+
261
+ protected buildHeaderRow(headerRow: GridNode<T>, x: number, y: number): LayoutNode {
262
+ let rect = new Rect(x, y, 0, 0);
263
+ let row = new LayoutInfo('headerrow', headerRow.key, rect);
264
+
265
+ let height = 0;
266
+ let columns: LayoutNode[] = [];
267
+ for (let cell of getChildNodes(headerRow, this.virtualizer!.collection)) {
268
+ let layoutNode = this.buildChild(cell, x, y, row.key);
269
+ layoutNode.layoutInfo.parentKey = row.key;
270
+ x = layoutNode.layoutInfo.rect.maxX;
271
+ height = Math.max(height, layoutNode.layoutInfo.rect.height);
272
+ layoutNode.index = columns.length;
273
+ columns.push(layoutNode);
274
+ }
275
+ for (let [i, layout] of columns.entries()) {
276
+ layout.layoutInfo.zIndex = columns.length - i + 1;
277
+ }
278
+
279
+ this.setChildHeights(columns, height);
280
+
281
+ rect.height = height;
282
+ rect.width = x - rect.x;
283
+
284
+ return {
285
+ layoutInfo: row,
286
+ children: columns,
287
+ validRect: rect,
288
+ node: headerRow,
289
+ };
290
+ }
291
+
292
+ private setChildHeights(children: LayoutNode[], height: number) {
293
+ for (let child of children) {
294
+ if (child.layoutInfo.rect.height !== height) {
295
+ // Need to copy the layout info before we mutate it.
296
+ child.layoutInfo = child.layoutInfo.copy();
297
+ child.layoutInfo.rect.height = height;
298
+ }
299
+ }
300
+ }
301
+
302
+ // used to get the column widths when rendering to the DOM
303
+ private getRenderedColumnWidth(node: GridNode<T>) {
304
+ let collection = this.virtualizer!.collection as TableCollection<T>;
305
+ let colSpan = node.colSpan ?? 1;
306
+ let colIndex = node.colIndex ?? node.index;
307
+ let width = 0;
308
+ for (let i = colIndex; i < colIndex + colSpan; i++) {
309
+ let column = collection.columns[i];
310
+ if (column?.key != null) {
311
+ width += this.columnWidths.get(column.key) ?? 0;
312
+ }
313
+ }
314
+
315
+ return width;
316
+ }
317
+
318
+ private getEstimatedHeight(
319
+ node: GridNode<T>,
320
+ width: number,
321
+ height: number | null,
322
+ estimatedHeight: number | null,
323
+ ) {
324
+ let isEstimated = false;
325
+
326
+ // If no explicit height is available, use an estimated height.
327
+ if (height == null) {
328
+ // If a previous version of this layout info exists, reuse its height.
329
+ // Mark as estimated if the size of the overall collection view changed,
330
+ // or the content of the item changed.
331
+ let previousLayoutNode = this.layoutNodes.get(node.key);
332
+ if (previousLayoutNode) {
333
+ height = previousLayoutNode.layoutInfo.rect.height;
334
+ isEstimated =
335
+ node !== previousLayoutNode.node ||
336
+ width !== previousLayoutNode.layoutInfo.rect.width ||
337
+ previousLayoutNode.layoutInfo.estimatedSize;
338
+ } else {
339
+ height = estimatedHeight ?? DEFAULT_ROW_HEIGHT;
340
+ isEstimated = true;
341
+ }
342
+ }
343
+
344
+ return { height, isEstimated };
345
+ }
346
+
347
+ protected getEstimatedRowHeight(): number {
348
+ return this.rowHeight ?? this.estimatedRowHeight ?? DEFAULT_ROW_HEIGHT;
349
+ }
350
+
351
+ protected buildColumn(node: GridNode<T>, x: number, y: number): LayoutNode {
352
+ let width = this.getRenderedColumnWidth(node);
353
+ let { height, isEstimated } = this.getEstimatedHeight(
354
+ node,
355
+ width,
356
+ this.headingHeight ?? this.rowHeight,
357
+ this.estimatedHeadingHeight ?? this.estimatedRowHeight,
358
+ );
359
+ let rect = new Rect(x, y, width, height);
360
+ let layoutInfo = new LayoutInfo(node.type, node.key, rect);
361
+ layoutInfo.isSticky = this.isStickyColumn(node);
362
+ layoutInfo.zIndex = layoutInfo.isSticky ? 2 : 1;
363
+ layoutInfo.estimatedSize = isEstimated;
364
+
365
+ return {
366
+ layoutInfo,
367
+ children: [],
368
+ validRect: layoutInfo.rect,
369
+ node,
370
+ };
371
+ }
372
+
373
+ // For subclasses.
374
+ // eslint-disable-next-line
375
+ protected isStickyColumn(node: GridNode<T>) {
376
+ return false;
377
+ }
378
+
379
+ protected buildBody(y: number): LayoutNode {
380
+ let collection = this.virtualizer!.collection as TableCollection<T>;
381
+ return this.buildRowGroup(y, collection.body);
382
+ }
383
+
384
+ protected buildRowGroup(y: number, node: GridNode<T>): LayoutNode {
385
+ let collection = this.virtualizer!.collection as TableCollection<T>;
386
+ let rect = new Rect(this.padding, y, 0, 0);
387
+ let layoutInfo = new LayoutInfo('rowgroup', node.key, rect);
388
+
389
+ let startY = y;
390
+ let width = 0;
391
+ let children: LayoutNode[] = [];
392
+ let rowHeight = this.getEstimatedRowHeight() + this.gap;
393
+ let childNodes = getChildNodes(node, collection);
394
+ for (let node of childNodes) {
395
+ // Skip rows outside the valid rectangle unless they are already cached.
396
+ if (
397
+ (y + rowHeight < this.requestedRect.y && !this.isValid(node, y)) ||
398
+ (y > this.requestedRect.maxY && node.type !== 'loader')
399
+ ) {
400
+ y += rowHeight;
401
+ continue;
402
+ }
403
+
404
+ let layoutNode = this.buildChild(node, this.padding, y, layoutInfo.key);
405
+ layoutNode.layoutInfo.parentKey = layoutInfo.key;
406
+ layoutNode.index = children.length;
407
+ y = layoutNode.layoutInfo.rect.maxY + this.gap;
408
+ width = Math.max(width, layoutNode.layoutInfo.rect.width);
409
+ children.push(layoutNode);
410
+ }
411
+
412
+ // Make sure that the table body gets a height if empty or performing initial load
413
+ let isEmptyOrLoading = collection?.size === 0;
414
+ if (isEmptyOrLoading) {
415
+ y = this.virtualizer!.size.height;
416
+ } else {
417
+ y -= this.gap;
418
+ }
419
+
420
+ rect.width = width;
421
+ rect.height = y - startY;
422
+
423
+ return {
424
+ layoutInfo,
425
+ children,
426
+ validRect: layoutInfo.rect.intersection(this.requestedRect),
427
+ node,
428
+ };
429
+ }
430
+
431
+ protected buildLoader(node: GridNode<T>, x: number, y: number): LayoutNode {
432
+ let layoutNode = super.buildLoader(node, x, y);
433
+ let collection = this.virtualizer!.collection as TableCollection<T>;
434
+
435
+ // use the same approach as buildRow to get the proper width of the loader, otherwise
436
+ // we get a outdated loader width
437
+ layoutNode.layoutInfo.rect.width = this.layoutNodes.get(
438
+ collection.head?.key ?? 'header',
439
+ )!.layoutInfo.rect.width;
440
+ layoutNode.validRect = layoutNode.layoutInfo.rect.intersection(this.requestedRect);
441
+ return layoutNode;
442
+ }
443
+
444
+ protected buildNode(node: GridNode<T>, x: number, y: number): LayoutNode {
445
+ switch (node.type) {
446
+ case 'headerrow':
447
+ return this.buildHeaderRow(node, x, y);
448
+ case 'item':
449
+ return this.buildRow(node, x, y);
450
+ case 'column':
451
+ case 'placeholder':
452
+ return this.buildColumn(node, x, y);
453
+ case 'cell':
454
+ return this.buildCell(node, x, y);
455
+ case 'loader':
456
+ return this.buildLoader(node, x, y);
457
+ default:
458
+ throw new Error('Unknown node type ' + node.type);
459
+ }
460
+ }
461
+
462
+ protected buildRow(node: GridNode<T>, x: number, y: number): LayoutNode {
463
+ let collection = this.virtualizer!.collection as TableCollection<T>;
464
+ let rect = new Rect(x, y, 0, 0);
465
+ let layoutInfo = new LayoutInfo('row', node.key, rect);
466
+
467
+ let children: LayoutNode[] = [];
468
+ let height = 0;
469
+ for (let child of getChildNodes(node, collection)) {
470
+ if (child.type === 'cell') {
471
+ if (x > this.requestedRect.maxX) {
472
+ // Adjust existing cached layoutInfo to ensure that it is out of view.
473
+ // This can happen due to column resizing.
474
+ let layoutNode = this.layoutNodes.get(child.key);
475
+ if (layoutNode) {
476
+ layoutNode.layoutInfo.rect.x = x;
477
+ x += layoutNode.layoutInfo.rect.width;
478
+ } else {
479
+ break;
480
+ }
481
+ } else {
482
+ let layoutNode = this.buildChild(child, x, y, layoutInfo.key);
483
+ x = layoutNode.layoutInfo.rect.maxX;
484
+ height = Math.max(height, layoutNode.layoutInfo.rect.height);
485
+ layoutNode.index = children.length;
486
+ children.push(layoutNode);
487
+ }
488
+ }
489
+ }
490
+
491
+ this.setChildHeights(children, height);
492
+
493
+ rect.width = this.layoutNodes.get(collection.head?.key ?? 'header')!.layoutInfo.rect.width;
494
+ rect.height = height;
495
+
496
+ return {
497
+ layoutInfo,
498
+ children,
499
+ validRect: rect.intersection(this.requestedRect),
500
+ node,
501
+ };
502
+ }
503
+
504
+ protected buildCell(node: GridNode<T>, x: number, y: number): LayoutNode {
505
+ let width = this.getRenderedColumnWidth(node);
506
+ let { height, isEstimated } = this.getEstimatedHeight(
507
+ node,
508
+ width,
509
+ this.rowHeight,
510
+ this.estimatedRowHeight,
511
+ );
512
+ let rect = new Rect(x, y, width, height);
513
+ let layoutInfo = new LayoutInfo(node.type, node.key, rect);
514
+ layoutInfo.isSticky = this.isStickyColumn(node);
515
+ layoutInfo.zIndex = layoutInfo.isSticky ? 2 : 1;
516
+ layoutInfo.estimatedSize = isEstimated;
517
+
518
+ return {
519
+ layoutInfo,
520
+ children: [],
521
+ validRect: rect,
522
+ node,
523
+ };
524
+ }
525
+
526
+ getVisibleLayoutInfos(rect: Rect): LayoutInfo[] {
527
+ // Adjust rect to keep number of visible rows consistent.
528
+ // (only if height > 1 for getDropTargetFromPoint)
529
+ if (rect.height > 1) {
530
+ let rowHeight = this.getEstimatedRowHeight();
531
+ rect.y = Math.floor(rect.y / rowHeight) * rowHeight;
532
+ rect.height = Math.ceil(rect.height / rowHeight) * rowHeight;
533
+ }
534
+
535
+ // If layout hasn't yet been done for the requested rect, union the
536
+ // new rect with the existing valid rect, and recompute.
537
+ this.layoutIfNeeded(rect);
538
+
539
+ let res: LayoutInfo[] = [];
540
+
541
+ this.buildPersistedIndices();
542
+ for (let node of this.rootNodes) {
543
+ res.push(node.layoutInfo);
544
+ this.addVisibleLayoutInfos(res, node, rect);
545
+ }
546
+
547
+ return res;
548
+ }
549
+
550
+ private addVisibleLayoutInfos(res: LayoutInfo[], node: LayoutNode, rect: Rect) {
551
+ if (!node.children || node.children.length === 0) {
552
+ return;
553
+ }
554
+
555
+ switch (node.layoutInfo.type) {
556
+ case 'header': {
557
+ for (let child of node.children) {
558
+ res.push(child.layoutInfo);
559
+ this.addVisibleLayoutInfos(res, child, rect);
560
+ }
561
+ break;
562
+ }
563
+ case 'rowgroup': {
564
+ let firstVisibleRow = this.binarySearch(node.children, rect.topLeft, 'y');
565
+ let lastVisibleRow = this.binarySearch(node.children, rect.bottomRight, 'y');
566
+
567
+ // Add persisted rows before the visible rows.
568
+ let persistedRowIndices = this.persistedIndices.get(node.layoutInfo.key);
569
+ let persistIndex = 0;
570
+ while (
571
+ persistedRowIndices &&
572
+ persistIndex < persistedRowIndices.length &&
573
+ persistedRowIndices[persistIndex] < firstVisibleRow
574
+ ) {
575
+ let idx = persistedRowIndices[persistIndex];
576
+ if (idx < node.children.length) {
577
+ res.push(node.children[idx].layoutInfo);
578
+ this.addVisibleLayoutInfos(res, node.children[idx], rect);
579
+ }
580
+ persistIndex++;
581
+ }
582
+
583
+ for (let i = firstVisibleRow; i <= lastVisibleRow; i++) {
584
+ // Skip persisted rows that overlap with visible cells.
585
+ while (
586
+ persistedRowIndices &&
587
+ persistIndex < persistedRowIndices.length &&
588
+ persistedRowIndices[persistIndex] < i
589
+ ) {
590
+ persistIndex++;
591
+ }
592
+
593
+ res.push(node.children[i].layoutInfo);
594
+ this.addVisibleLayoutInfos(res, node.children[i], rect);
595
+ }
596
+
597
+ // Add persisted rows after the visible rows.
598
+ while (persistedRowIndices && persistIndex < persistedRowIndices.length) {
599
+ let idx = persistedRowIndices[persistIndex++];
600
+ if (idx < node.children.length) {
601
+ res.push(node.children[idx].layoutInfo);
602
+ this.addVisibleLayoutInfos(res, node.children[idx], rect);
603
+ }
604
+ }
605
+
606
+ // Always include loading sentinel even when virtualized, we assume it is always the last child for now
607
+ let lastRow = node.children.at(-1);
608
+ if (lastRow?.layoutInfo.type === 'loader') {
609
+ res.push(lastRow.layoutInfo);
610
+ }
611
+ break;
612
+ }
613
+ case 'headerrow':
614
+ case 'row': {
615
+ let firstVisibleCell = this.binarySearch(node.children, rect.topLeft, 'x');
616
+ let lastVisibleCell = this.binarySearch(node.children, rect.topRight, 'x');
617
+ let stickyIndex = 0;
618
+
619
+ // Add persisted/sticky cells before the visible cells.
620
+ let persistedCellIndices =
621
+ this.persistedIndices.get(node.layoutInfo.key) || this.stickyColumnIndices;
622
+ while (
623
+ stickyIndex < persistedCellIndices.length &&
624
+ persistedCellIndices[stickyIndex] < firstVisibleCell
625
+ ) {
626
+ let idx = persistedCellIndices[stickyIndex];
627
+ if (idx < node.children.length) {
628
+ res.push(node.children[idx].layoutInfo);
629
+ }
630
+ stickyIndex++;
631
+ }
632
+
633
+ for (let i = firstVisibleCell; i <= lastVisibleCell; i++) {
634
+ // Skip sticky cells that overlap with visible cells.
635
+ while (
636
+ stickyIndex < persistedCellIndices.length &&
637
+ persistedCellIndices[stickyIndex] < i
638
+ ) {
639
+ stickyIndex++;
640
+ }
641
+
642
+ res.push(node.children[i].layoutInfo);
643
+ }
644
+
645
+ // Add any remaining sticky cells after the visible cells.
646
+ while (stickyIndex < persistedCellIndices.length) {
647
+ let idx = persistedCellIndices[stickyIndex++];
648
+ if (idx < node.children.length) {
649
+ res.push(node.children[idx].layoutInfo);
650
+ }
651
+ }
652
+ break;
653
+ }
654
+ default:
655
+ throw new Error('Unknown node type ' + node.layoutInfo.type);
656
+ }
657
+ }
658
+
659
+ private binarySearch(items: LayoutNode[], point: Point, axis: 'x' | 'y') {
660
+ let low = 0;
661
+ let high = items.length - 1;
662
+ while (low <= high) {
663
+ let mid = (low + high) >> 1;
664
+ let item = items[mid];
665
+
666
+ if (
667
+ (axis === 'x' && item.layoutInfo.rect.maxX <= point.x) ||
668
+ (axis === 'y' && item.layoutInfo.rect.maxY <= point.y)
669
+ ) {
670
+ low = mid + 1;
671
+ } else if (
672
+ (axis === 'x' && item.layoutInfo.rect.x > point.x) ||
673
+ (axis === 'y' && item.layoutInfo.rect.y > point.y)
674
+ ) {
675
+ high = mid - 1;
676
+ } else {
677
+ return mid;
678
+ }
679
+ }
680
+
681
+ return Math.max(0, Math.min(items.length - 1, low));
682
+ }
683
+
684
+ private buildPersistedIndices() {
685
+ if (this.virtualizer!.persistedKeys === this.lastPersistedKeys) {
686
+ return;
687
+ }
688
+
689
+ this.lastPersistedKeys = this.virtualizer!.persistedKeys;
690
+ this.persistedIndices.clear();
691
+
692
+ // Build a map of parentKey => indices of children to persist.
693
+ for (let key of this.virtualizer!.persistedKeys) {
694
+ let layoutInfo = this.layoutNodes.get(key)?.layoutInfo;
695
+
696
+ // Walk up ancestors so parents are also persisted if children are.
697
+ while (layoutInfo && layoutInfo.parentKey) {
698
+ let collectionNode = this.virtualizer!.collection.getItem(layoutInfo.key);
699
+ let indices = this.persistedIndices.get(layoutInfo.parentKey);
700
+ if (!indices) {
701
+ // stickyColumnIndices are always persisted along with any cells from persistedKeys.
702
+ indices =
703
+ collectionNode?.type === 'cell' || collectionNode?.type === 'column'
704
+ ? [...this.stickyColumnIndices]
705
+ : [];
706
+ this.persistedIndices.set(layoutInfo.parentKey, indices);
707
+ }
708
+
709
+ let index = this.layoutNodes.get(layoutInfo.key)?.index;
710
+ if (index != null && !indices.includes(index)) {
711
+ indices.push(index);
712
+ }
713
+
714
+ layoutInfo = this.layoutNodes.get(layoutInfo.parentKey)?.layoutInfo;
715
+ }
716
+ }
717
+
718
+ for (let indices of this.persistedIndices.values()) {
719
+ indices.sort((a, b) => a - b);
720
+ }
721
+ }
722
+
723
+ getDropTargetFromPoint(
724
+ x: number,
725
+ y: number,
726
+ isValidDropTarget: (target: DropTarget) => boolean,
727
+ ): DropTarget | null {
728
+ x += this.virtualizer!.visibleRect.x;
729
+ y += this.virtualizer!.visibleRect.y;
730
+
731
+ // Find the closest item within on either side of the point using the gap width.
732
+ let searchRect = new Rect(x, Math.max(0, y - this.gap), 1, Math.max(1, this.gap * 2));
733
+ let candidates = this.getVisibleLayoutInfos(searchRect);
734
+ let key: Key | null = null;
735
+ let minDistance = Infinity;
736
+ for (let candidate of candidates) {
737
+ // Ignore items outside the search rect, e.g. persisted keys.
738
+ if (candidate.type !== 'row' || !candidate.rect.intersects(searchRect)) {
739
+ continue;
740
+ }
741
+
742
+ let yDist = Math.abs(candidate.rect.y - y);
743
+ let maxYDist = Math.abs(candidate.rect.maxY - y);
744
+ let dist = Math.min(yDist, maxYDist);
745
+ if (dist < minDistance) {
746
+ minDistance = dist;
747
+ key = candidate.key;
748
+ }
749
+ }
750
+
751
+ if (key == null || this.virtualizer!.collection.size === 0) {
752
+ return { type: 'root' };
753
+ }
754
+
755
+ let layoutInfo = this.getLayoutInfo(key);
756
+ if (!layoutInfo) {
757
+ return null;
758
+ }
759
+
760
+ let rect = layoutInfo.rect;
761
+ let target: DropTarget = {
762
+ type: 'item',
763
+ key: layoutInfo.key,
764
+ dropPosition: 'on',
765
+ };
766
+
767
+ // If dropping on the item isn't accepted, try the target before or after depending on the y position.
768
+ // Otherwise, if dropping on the item is accepted, still try the before/after positions if within 10px
769
+ // of the top or bottom of the item.
770
+ if (!isValidDropTarget(target)) {
771
+ if (
772
+ y <= rect.y + rect.height / 2 &&
773
+ isValidDropTarget({ ...target, dropPosition: 'before' })
774
+ ) {
775
+ target.dropPosition = 'before';
776
+ } else if (isValidDropTarget({ ...target, dropPosition: 'after' })) {
777
+ target.dropPosition = 'after';
778
+ }
779
+ } else if (y <= rect.y + 10 && isValidDropTarget({ ...target, dropPosition: 'before' })) {
780
+ target.dropPosition = 'before';
781
+ } else if (y >= rect.maxY - 10 && isValidDropTarget({ ...target, dropPosition: 'after' })) {
782
+ target.dropPosition = 'after';
783
+ }
784
+
785
+ return target;
786
+ }
787
+
788
+ getDropTargetLayoutInfo(target: ItemDropTarget): LayoutInfo {
789
+ let layoutInfo = super.getDropTargetLayoutInfo(target);
790
+ layoutInfo.parentKey = this.virtualizer!.collection.getItem(target.key)?.parentKey ?? null;
791
+ return layoutInfo;
792
+ }
793
+ }