@enact/ui 3.4.9-experimental-3 → 3.4.9-experimental-7

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 (464) hide show
  1. package/{build/A11yDecorator → A11yDecorator}/A11yDecorator.d.ts +0 -0
  2. package/A11yDecorator/A11yDecorator.js +79 -75
  3. package/A11yDecorator/tests/A11yDecorator-specs.js +90 -128
  4. package/AnnounceDecorator/Announce.js +136 -80
  5. package/{build/AnnounceDecorator → AnnounceDecorator}/AnnounceDecorator.d.ts +0 -0
  6. package/AnnounceDecorator/AnnounceDecorator.js +68 -53
  7. package/AnnounceDecorator/tests/Announce-specs.js +29 -35
  8. package/AnnounceDecorator/tests/AnnounceDecorator-specs.js +34 -36
  9. package/AnnounceDecorator/tests/useAnnounce-specs.js +56 -63
  10. package/AnnounceDecorator/useAnnounce.js +29 -18
  11. package/{build/BodyText → BodyText}/BodyText.d.ts +0 -0
  12. package/BodyText/BodyText.js +108 -96
  13. package/{build/BodyText → BodyText}/BodyText.module.css +0 -0
  14. package/BodyText/tests/BodyText-specs.js +67 -76
  15. package/{build/Button → Button}/Button.d.ts +0 -0
  16. package/Button/Button.js +236 -215
  17. package/{build/Button → Button}/Button.module.css +0 -0
  18. package/CHANGELOG.md +18 -0
  19. package/{build/Cancelable → Cancelable}/Cancelable.d.ts +0 -0
  20. package/Cancelable/Cancelable.js +213 -184
  21. package/Cancelable/cancelHandler.js +36 -29
  22. package/Cancelable/modalHandler.js +35 -23
  23. package/Cancelable/tests/Cancelable-specs.js +289 -381
  24. package/{build/Changeable → Changeable}/Changeable.d.ts +0 -0
  25. package/Changeable/Changeable.js +137 -161
  26. package/Changeable/tests/Changeable-specs.js +262 -327
  27. package/{build/ComponentOverride → ComponentOverride}/ComponentOverride.d.ts +0 -0
  28. package/ComponentOverride/ComponentOverride.js +21 -24
  29. package/FloatingLayer/FloatingLayer.js +310 -261
  30. package/FloatingLayer/FloatingLayerDecorator.js +150 -99
  31. package/FloatingLayer/Scrim.js +167 -99
  32. package/{build/FloatingLayer → FloatingLayer}/Scrim.module.css +0 -0
  33. package/FloatingLayer/index.js +39 -12
  34. package/FloatingLayer/tests/FloatingLayer-specs.js +24 -27
  35. package/FloatingLayer/tests/Scrim-specs.js +21 -24
  36. package/FloatingLayer/useFloatingLayer.js +46 -18
  37. package/{build/ForwardRef → ForwardRef}/ForwardRef.d.ts +0 -0
  38. package/ForwardRef/ForwardRef.js +35 -34
  39. package/{build/GridListImageItem → GridListImageItem}/GridListImageItem.d.ts +0 -0
  40. package/GridListImageItem/GridListImageItem.js +244 -212
  41. package/{build/GridListImageItem → GridListImageItem}/GridListImageItem.module.css +0 -0
  42. package/{build/Group → Group}/Group.d.ts +0 -0
  43. package/Group/Group.js +186 -168
  44. package/Group/GroupItem.js +83 -79
  45. package/Group/tests/Group-specs.js +128 -164
  46. package/{build/Heading → Heading}/Heading.d.ts +0 -0
  47. package/Heading/Heading.js +146 -128
  48. package/{build/Heading → Heading}/Heading.module.css +0 -0
  49. package/Heading/tests/Heading-specs.js +46 -54
  50. package/{build/Icon → Icon}/Icon.d.ts +0 -0
  51. package/Icon/Icon.js +200 -189
  52. package/{build/Icon → Icon}/Icon.module.css +0 -0
  53. package/Icon/tests/Icon-specs.js +92 -126
  54. package/{build/IconButton → IconButton}/IconButton.d.ts +0 -0
  55. package/IconButton/IconButton.js +213 -181
  56. package/{build/IconButton → IconButton}/IconButton.module.css +0 -0
  57. package/{build/Image → Image}/Image.d.ts +0 -0
  58. package/Image/Image.js +186 -151
  59. package/{build/Image → Image}/Image.module.css +0 -0
  60. package/Image/tests/Image-specs.js +49 -51
  61. package/{build/ImageItem → ImageItem}/ImageItem.d.ts +0 -0
  62. package/ImageItem/ImageItem.js +165 -149
  63. package/{build/ImageItem → ImageItem}/ImageItem.module.css +0 -0
  64. package/ImageItem/tests/ImageItem-specs.js +128 -161
  65. package/{build/Item → Item}/Item.d.ts +0 -0
  66. package/Item/Item.js +131 -121
  67. package/{build/Item → Item}/Item.module.css +0 -0
  68. package/Item/tests/Item-specs.js +71 -88
  69. package/{build/LabeledIcon → LabeledIcon}/LabeledIcon.d.ts +0 -0
  70. package/LabeledIcon/LabeledIcon.js +235 -216
  71. package/{build/LabeledIcon → LabeledIcon}/LabeledIcon.module.css +0 -0
  72. package/LabeledIcon/tests/LabeledIcon-specs.js +49 -58
  73. package/Layout/Cell.js +181 -146
  74. package/{build/Layout → Layout}/Layout.d.ts +0 -0
  75. package/Layout/Layout.js +193 -282
  76. package/{build/Layout → Layout}/Layout.module.css +0 -0
  77. package/Layout/tests/Layout-specs.js +102 -109
  78. package/{build/Marquee → Marquee}/Marquee.module.css +0 -0
  79. package/Marquee/MarqueeBase.js +275 -240
  80. package/Marquee/MarqueeController.js +327 -292
  81. package/Marquee/MarqueeDecorator.js +990 -898
  82. package/{build/Marquee → Marquee}/index.d.ts +0 -0
  83. package/Marquee/index.js +39 -14
  84. package/Marquee/tests/Marquee-specs.js +274 -382
  85. package/{build/Measurable → Measurable}/Measurable.d.ts +0 -0
  86. package/Measurable/Measurable.js +133 -100
  87. package/{build/Media → Media}/Media.d.ts +0 -0
  88. package/Media/Media.js +317 -254
  89. package/Placeholder/PlaceholderControllerDecorator.js +188 -133
  90. package/Placeholder/PlaceholderDecorator.js +147 -95
  91. package/{build/Placeholder → Placeholder}/index.d.ts +0 -0
  92. package/Placeholder/index.js +27 -9
  93. package/{build/ProgressBar → ProgressBar}/ProgressBar.d.ts +0 -0
  94. package/ProgressBar/ProgressBar.js +183 -173
  95. package/{build/ProgressBar → ProgressBar}/ProgressBar.module.css +0 -0
  96. package/ProgressBar/tests/ProgressBar-specs.js +80 -109
  97. package/RadioDecorator/RadioControllerDecorator.js +104 -54
  98. package/{build/RadioDecorator → RadioDecorator}/RadioDecorator.d.ts +0 -0
  99. package/RadioDecorator/RadioDecorator.js +176 -117
  100. package/RadioDecorator/tests/RadioDecorator-specs.js +155 -166
  101. package/{build/Repeater → Repeater}/Repeater.d.ts +0 -0
  102. package/Repeater/Repeater.js +157 -133
  103. package/Repeater/tests/Repeater-specs.js +136 -155
  104. package/{build/Resizable → Resizable}/Resizable.d.ts +0 -0
  105. package/Resizable/Resizable.js +145 -101
  106. package/Routable/Link.js +65 -61
  107. package/{build/Routable → Routable}/Routable.d.ts +0 -0
  108. package/Routable/Routable.js +148 -109
  109. package/Routable/Route.js +37 -27
  110. package/Routable/Router.js +236 -171
  111. package/Routable/tests/Router-specs.js +194 -196
  112. package/Routable/util.js +78 -68
  113. package/Scrollable/ScrollAnimator.js +138 -112
  114. package/Scrollable/ScrollThumb.js +52 -42
  115. package/{build/Scrollable → Scrollable}/ScrollThumb.module.css +0 -0
  116. package/{build/Scrollable → Scrollable}/Scrollable.d.ts +0 -0
  117. package/Scrollable/Scrollable.js +1591 -1443
  118. package/{build/Scrollable → Scrollable}/Scrollable.module.css +0 -0
  119. package/Scrollable/ScrollableNative.js +1599 -1445
  120. package/Scrollable/Scrollbar.js +312 -221
  121. package/{build/Scrollable → Scrollable}/Scrollbar.module.css +0 -0
  122. package/{build/Scroller → Scroller}/Scroller.d.ts +0 -0
  123. package/Scroller/Scroller.js +249 -242
  124. package/{build/Scroller → Scroller}/Scroller.module.css +0 -0
  125. package/Scroller/ScrollerBasic.js +311 -230
  126. package/{build/Scroller → Scroller}/UiScroller.module.css +0 -0
  127. package/Scroller/UiScrollerBase.js +253 -184
  128. package/{build/Skinnable → Skinnable}/Skinnable.d.ts +0 -0
  129. package/Skinnable/Skinnable.js +182 -172
  130. package/Skinnable/tests/Skinnable-specs.js +388 -416
  131. package/Skinnable/tests/useSkins-specs.js +290 -281
  132. package/Skinnable/tests/util-specs.js +107 -113
  133. package/Skinnable/useSkins.js +51 -28
  134. package/Skinnable/util.js +80 -75
  135. package/Slider/Knob.js +85 -71
  136. package/Slider/PositionDecorator.js +232 -162
  137. package/{build/Slider → Slider}/Slider.d.ts +0 -0
  138. package/Slider/Slider.js +331 -312
  139. package/{build/Slider → Slider}/Slider.module.css +0 -0
  140. package/Slider/utils.js +16 -11
  141. package/{build/SlotItem → SlotItem}/SlotItem.d.ts +0 -0
  142. package/SlotItem/SlotItem.js +199 -179
  143. package/{build/SlotItem → SlotItem}/SlotItem.module.css +0 -0
  144. package/{build/Slottable → Slottable}/Slottable.d.ts +0 -0
  145. package/Slottable/Slottable.js +62 -48
  146. package/Slottable/tests/Slottable-specs.js +232 -284
  147. package/Slottable/tests/useSlots-specs.js +277 -313
  148. package/Slottable/useSlots.js +113 -90
  149. package/{build/Spinner → Spinner}/Spinner.d.ts +0 -0
  150. package/Spinner/Spinner.js +213 -178
  151. package/{build/Spinner → Spinner}/Spinner.module.css +0 -0
  152. package/Spinner/tests/Spinner-specs.js +61 -77
  153. package/{build/ToggleIcon → ToggleIcon}/ToggleIcon.d.ts +0 -0
  154. package/ToggleIcon/ToggleIcon.js +134 -123
  155. package/{build/ToggleIcon → ToggleIcon}/ToggleIcon.module.css +0 -0
  156. package/ToggleIcon/tests/ToggleIcon-specs.js +52 -71
  157. package/{build/ToggleItem → ToggleItem}/ToggleItem.d.ts +0 -0
  158. package/ToggleItem/ToggleItem.js +263 -264
  159. package/{build/ToggleItem → ToggleItem}/ToggleItem.module.css +0 -0
  160. package/ToggleItem/tests/ToggleItem-specs.js +87 -87
  161. package/Toggleable/Toggle.js +70 -43
  162. package/{build/Toggleable → Toggleable}/Toggleable.d.ts +0 -0
  163. package/Toggleable/Toggleable.js +219 -244
  164. package/Toggleable/tests/Toggleable-specs.js +416 -549
  165. package/Toggleable/useToggle.js +50 -24
  166. package/Touchable/ClickAllow.js +67 -49
  167. package/Touchable/Drag.js +199 -170
  168. package/Touchable/Flick.js +152 -122
  169. package/Touchable/Hold.js +259 -214
  170. package/{build/Touchable → Touchable}/Touchable.d.ts +0 -0
  171. package/Touchable/Touchable.js +643 -651
  172. package/Touchable/config.js +63 -44
  173. package/Touchable/state.js +31 -14
  174. package/Touchable/tests/Touchable-specs.js +462 -526
  175. package/{build/Transition → Transition}/Transition.d.ts +0 -0
  176. package/Transition/Transition.js +606 -553
  177. package/{build/Transition → Transition}/Transition.module.css +0 -0
  178. package/Transition/tests/Transition-specs.js +123 -138
  179. package/ViewManager/Arranger.js +82 -40
  180. package/ViewManager/TransitionGroup.js +502 -419
  181. package/ViewManager/View.js +383 -298
  182. package/{build/ViewManager → ViewManager}/ViewManager.d.ts +0 -0
  183. package/ViewManager/ViewManager.js +352 -296
  184. package/ViewManager/tests/View-specs.js +176 -275
  185. package/ViewManager/tests/ViewManager-specs.js +524 -471
  186. package/ViewManager/tests/test-utils.js +44 -23
  187. package/{build/VirtualList → VirtualList}/UiVirtualList.module.css +0 -0
  188. package/VirtualList/UiVirtualListBase.js +1381 -1171
  189. package/{build/VirtualList → VirtualList}/VirtualList.d.ts +0 -0
  190. package/VirtualList/VirtualList.js +541 -537
  191. package/{build/VirtualList → VirtualList}/VirtualList.module.css +0 -0
  192. package/VirtualList/VirtualListBase.js +37 -10
  193. package/VirtualList/VirtualListBasic.js +1468 -1241
  194. package/VirtualList/tests/VirtualList-specs.js +314 -345
  195. package/{build/index.d.ts → index.d.ts} +0 -0
  196. package/index.js +1 -0
  197. package/{build/internal → internal}/IdProvider/IdProvider.d.ts +0 -0
  198. package/internal/IdProvider/IdProvider.js +76 -54
  199. package/internal/IdProvider/Provider.js +67 -41
  200. package/internal/IdProvider/tests/useId-specs.js +64 -78
  201. package/internal/IdProvider/useId.js +27 -15
  202. package/{build/internal → internal}/Pure/Pure.d.ts +0 -0
  203. package/internal/Pure/Pure.js +98 -65
  204. package/{build/internal → internal}/localized-fonts/localized-fonts.d.ts +0 -0
  205. package/internal/localized-fonts/localized-fonts.js +179 -159
  206. package/{build/internal → internal}/selection/selection.d.ts +0 -0
  207. package/internal/selection/selection.js +49 -40
  208. package/internal/selection/tests/selection-specs.js +158 -253
  209. package/{build/internal → internal}/validators/validators.d.ts +0 -0
  210. package/internal/validators/validators.js +103 -55
  211. package/package.json +2 -2
  212. package/resolution/ResolutionDecorator.js +150 -97
  213. package/{build/resolution → resolution}/index.d.ts +0 -0
  214. package/resolution/index.js +39 -7
  215. package/resolution/resolution.js +232 -183
  216. package/resolution/tests/ResolutionDecorator-specs.js +42 -48
  217. package/resolution/tests/resolution-specs.js +90 -91
  218. package/useControlledState/tests/useControlledState-specs.js +100 -76
  219. package/{build/useControlledState → useControlledState}/useControlledState.d.ts +0 -0
  220. package/useControlledState/useControlledState.js +56 -38
  221. package/useScroll/ScrollAnimator.js +138 -112
  222. package/useScroll/Scrollbar.js +199 -175
  223. package/{build/useScroll → useScroll}/Scrollbar.module.css +0 -0
  224. package/useScroll/ScrollbarTrack.js +46 -28
  225. package/{build/useScroll → useScroll}/ScrollbarTrack.module.css +0 -0
  226. package/{build/useScroll → useScroll}/useScroll.d.ts +0 -0
  227. package/useScroll/useScroll.js +1714 -1627
  228. package/{build/useScroll → useScroll}/useScroll.module.css +0 -0
  229. package/useScroll/utilDOM.js +62 -55
  230. package/useScroll/utilEvent.js +33 -28
  231. package/BodyText/BodyText.module.less +0 -11
  232. package/Button/Button.module.less +0 -57
  233. package/FloatingLayer/Scrim.module.less +0 -8
  234. package/GridListImageItem/GridListImageItem.module.less +0 -33
  235. package/Heading/Heading.module.less +0 -20
  236. package/Icon/Icon.module.less +0 -38
  237. package/IconButton/IconButton.module.less +0 -18
  238. package/Image/Image.module.less +0 -21
  239. package/ImageItem/ImageItem.module.less +0 -29
  240. package/Item/Item.module.less +0 -14
  241. package/LabeledIcon/LabeledIcon.module.less +0 -45
  242. package/Layout/Layout.module.less +0 -84
  243. package/Marquee/Marquee.module.less +0 -49
  244. package/ProgressBar/ProgressBar.module.less +0 -114
  245. package/Scrollable/ScrollThumb.module.less +0 -46
  246. package/Scrollable/Scrollable.module.less +0 -42
  247. package/Scrollable/Scrollbar.module.less +0 -35
  248. package/Scroller/Scroller.module.less +0 -10
  249. package/Scroller/UiScroller.module.less +0 -10
  250. package/Slider/Slider.module.less +0 -20
  251. package/SlotItem/SlotItem.module.less +0 -19
  252. package/Spinner/Spinner.module.less +0 -52
  253. package/ToggleIcon/ToggleIcon.module.less +0 -14
  254. package/ToggleItem/ToggleItem.module.less +0 -9
  255. package/Transition/Transition.module.less +0 -179
  256. package/VirtualList/UiVirtualList.module.less +0 -31
  257. package/VirtualList/VirtualList.module.less +0 -39
  258. package/build/A11yDecorator/A11yDecorator.js +0 -129
  259. package/build/A11yDecorator/package.json +0 -3
  260. package/build/A11yDecorator/tests/A11yDecorator-specs.js +0 -90
  261. package/build/AnnounceDecorator/Announce.js +0 -172
  262. package/build/AnnounceDecorator/AnnounceDecorator.js +0 -121
  263. package/build/AnnounceDecorator/package.json +0 -3
  264. package/build/AnnounceDecorator/tests/Announce-specs.js +0 -29
  265. package/build/AnnounceDecorator/tests/AnnounceDecorator-specs.js +0 -34
  266. package/build/AnnounceDecorator/tests/useAnnounce-specs.js +0 -56
  267. package/build/AnnounceDecorator/useAnnounce.js +0 -61
  268. package/build/BodyText/BodyText.js +0 -139
  269. package/build/BodyText/package.json +0 -3
  270. package/build/BodyText/tests/BodyText-specs.js +0 -67
  271. package/build/Button/Button.js +0 -283
  272. package/build/Button/package.json +0 -3
  273. package/build/CHANGELOG.md +0 -1089
  274. package/build/Cancelable/Cancelable.js +0 -271
  275. package/build/Cancelable/cancelHandler.js +0 -79
  276. package/build/Cancelable/modalHandler.js +0 -68
  277. package/build/Cancelable/package.json +0 -3
  278. package/build/Cancelable/tests/Cancelable-specs.js +0 -289
  279. package/build/Changeable/Changeable.js +0 -172
  280. package/build/Changeable/package.json +0 -3
  281. package/build/Changeable/tests/Changeable-specs.js +0 -262
  282. package/build/ComponentOverride/ComponentOverride.js +0 -68
  283. package/build/ComponentOverride/package.json +0 -3
  284. package/build/FloatingLayer/FloatingLayer.js +0 -339
  285. package/build/FloatingLayer/FloatingLayerDecorator.js +0 -174
  286. package/build/FloatingLayer/Scrim.js +0 -199
  287. package/build/FloatingLayer/index.js +0 -49
  288. package/build/FloatingLayer/tests/FloatingLayer-specs.js +0 -29
  289. package/build/FloatingLayer/tests/Scrim-specs.js +0 -26
  290. package/build/FloatingLayer/useFloatingLayer.js +0 -53
  291. package/build/ForwardRef/ForwardRef.js +0 -68
  292. package/build/ForwardRef/package.json +0 -3
  293. package/build/GridListImageItem/GridListImageItem.js +0 -257
  294. package/build/GridListImageItem/package.json +0 -3
  295. package/build/Group/Group.js +0 -217
  296. package/build/Group/GroupItem.js +0 -109
  297. package/build/Group/package.json +0 -3
  298. package/build/Group/tests/Group-specs.js +0 -128
  299. package/build/Heading/Heading.js +0 -158
  300. package/build/Heading/package.json +0 -3
  301. package/build/Heading/tests/Heading-specs.js +0 -46
  302. package/build/Icon/Icon.js +0 -234
  303. package/build/Icon/package.json +0 -3
  304. package/build/Icon/tests/Icon-specs.js +0 -92
  305. package/build/IconButton/IconButton.js +0 -252
  306. package/build/IconButton/package.json +0 -3
  307. package/build/Image/Image.js +0 -219
  308. package/build/Image/package.json +0 -3
  309. package/build/Image/tests/Image-specs.js +0 -55
  310. package/build/ImageItem/ImageItem.js +0 -180
  311. package/build/ImageItem/package.json +0 -3
  312. package/build/ImageItem/tests/ImageItem-specs.js +0 -133
  313. package/build/Item/Item.js +0 -166
  314. package/build/Item/package.json +0 -3
  315. package/build/Item/tests/Item-specs.js +0 -77
  316. package/build/LabeledIcon/LabeledIcon.js +0 -287
  317. package/build/LabeledIcon/package.json +0 -3
  318. package/build/LabeledIcon/tests/LabeledIcon-specs.js +0 -49
  319. package/build/Layout/Cell.js +0 -215
  320. package/build/Layout/Layout.js +0 -316
  321. package/build/Layout/package.json +0 -3
  322. package/build/Layout/tests/Layout-specs.js +0 -102
  323. package/build/Marquee/MarqueeBase.js +0 -307
  324. package/build/Marquee/MarqueeController.js +0 -346
  325. package/build/Marquee/MarqueeDecorator.js +0 -1029
  326. package/build/Marquee/index.js +0 -65
  327. package/build/Marquee/package.json +0 -3
  328. package/build/Marquee/tests/Marquee-specs.js +0 -275
  329. package/build/Measurable/Measurable.js +0 -163
  330. package/build/Measurable/package.json +0 -3
  331. package/build/Media/Media.js +0 -389
  332. package/build/Media/package.json +0 -3
  333. package/build/Placeholder/PlaceholderControllerDecorator.js +0 -210
  334. package/build/Placeholder/PlaceholderDecorator.js +0 -171
  335. package/build/Placeholder/index.js +0 -37
  336. package/build/Placeholder/package.json +0 -3
  337. package/build/ProgressBar/ProgressBar.js +0 -200
  338. package/build/ProgressBar/package.json +0 -3
  339. package/build/ProgressBar/tests/ProgressBar-specs.js +0 -80
  340. package/build/README.md +0 -45
  341. package/build/RadioDecorator/RadioControllerDecorator.js +0 -117
  342. package/build/RadioDecorator/RadioDecorator.js +0 -199
  343. package/build/RadioDecorator/package.json +0 -3
  344. package/build/RadioDecorator/tests/RadioDecorator-specs.js +0 -155
  345. package/build/Repeater/Repeater.js +0 -190
  346. package/build/Repeater/package.json +0 -3
  347. package/build/Repeater/tests/Repeater-specs.js +0 -141
  348. package/build/Resizable/Resizable.js +0 -179
  349. package/build/Resizable/package.json +0 -3
  350. package/build/Routable/Link.js +0 -78
  351. package/build/Routable/Routable.js +0 -170
  352. package/build/Routable/Route.js +0 -68
  353. package/build/Routable/Router.js +0 -248
  354. package/build/Routable/package.json +0 -3
  355. package/build/Routable/tests/Router-specs.js +0 -200
  356. package/build/Routable/util.js +0 -90
  357. package/build/Scrollable/ScrollAnimator.js +0 -146
  358. package/build/Scrollable/ScrollThumb.js +0 -63
  359. package/build/Scrollable/Scrollable.js +0 -1612
  360. package/build/Scrollable/ScrollableNative.js +0 -1619
  361. package/build/Scrollable/Scrollbar.js +0 -344
  362. package/build/Scrollable/package.json +0 -3
  363. package/build/Scroller/Scroller.js +0 -291
  364. package/build/Scroller/ScrollerBasic.js +0 -322
  365. package/build/Scroller/UiScrollerBase.js +0 -414
  366. package/build/Scroller/package.json +0 -3
  367. package/build/Skinnable/Skinnable.js +0 -224
  368. package/build/Skinnable/package.json +0 -3
  369. package/build/Skinnable/tests/Skinnable-specs.js +0 -388
  370. package/build/Skinnable/tests/useSkins-specs.js +0 -290
  371. package/build/Skinnable/tests/util-specs.js +0 -120
  372. package/build/Skinnable/useSkins.js +0 -134
  373. package/build/Skinnable/util.js +0 -106
  374. package/build/Slider/Knob.js +0 -100
  375. package/build/Slider/PositionDecorator.js +0 -234
  376. package/build/Slider/Slider.js +0 -380
  377. package/build/Slider/package.json +0 -3
  378. package/build/Slider/utils.js +0 -18
  379. package/build/SlotItem/SlotItem.js +0 -245
  380. package/build/SlotItem/package.json +0 -3
  381. package/build/Slottable/Slottable.js +0 -95
  382. package/build/Slottable/package.json +0 -3
  383. package/build/Slottable/tests/Slottable-specs.js +0 -238
  384. package/build/Slottable/tests/useSlots-specs.js +0 -282
  385. package/build/Slottable/useSlots.js +0 -183
  386. package/build/Spinner/Spinner.js +0 -247
  387. package/build/Spinner/package.json +0 -3
  388. package/build/Spinner/tests/Spinner-specs.js +0 -61
  389. package/build/ToggleIcon/ToggleIcon.js +0 -181
  390. package/build/ToggleIcon/package.json +0 -3
  391. package/build/ToggleIcon/tests/ToggleIcon-specs.js +0 -58
  392. package/build/ToggleItem/ToggleItem.js +0 -306
  393. package/build/ToggleItem/package.json +0 -3
  394. package/build/ToggleItem/tests/ToggleItem-specs.js +0 -100
  395. package/build/Toggleable/Toggle.js +0 -74
  396. package/build/Toggleable/Toggleable.js +0 -250
  397. package/build/Toggleable/package.json +0 -3
  398. package/build/Toggleable/tests/Toggleable-specs.js +0 -421
  399. package/build/Toggleable/useToggle.js +0 -91
  400. package/build/Touchable/ClickAllow.js +0 -78
  401. package/build/Touchable/Drag.js +0 -206
  402. package/build/Touchable/Flick.js +0 -156
  403. package/build/Touchable/Hold.js +0 -262
  404. package/build/Touchable/Touchable.js +0 -661
  405. package/build/Touchable/config.js +0 -147
  406. package/build/Touchable/package.json +0 -3
  407. package/build/Touchable/state.js +0 -36
  408. package/build/Touchable/tests/Touchable-specs.js +0 -470
  409. package/build/Transition/Transition.js +0 -634
  410. package/build/Transition/package.json +0 -3
  411. package/build/Transition/tests/Transition-specs.js +0 -123
  412. package/build/ViewManager/Arranger.js +0 -181
  413. package/build/ViewManager/TransitionGroup.js +0 -547
  414. package/build/ViewManager/View.js +0 -403
  415. package/build/ViewManager/ViewManager.js +0 -386
  416. package/build/ViewManager/package.json +0 -3
  417. package/build/ViewManager/tests/View-specs.js +0 -182
  418. package/build/ViewManager/tests/ViewManager-specs.js +0 -524
  419. package/build/ViewManager/tests/test-utils.js +0 -47
  420. package/build/VirtualList/UiVirtualListBase.js +0 -1566
  421. package/build/VirtualList/VirtualList.js +0 -582
  422. package/build/VirtualList/VirtualListBase.js +0 -37
  423. package/build/VirtualList/VirtualListBasic.js +0 -1503
  424. package/build/VirtualList/package.json +0 -3
  425. package/build/VirtualList/tests/VirtualList-specs.js +0 -314
  426. package/build/index.js +0 -2
  427. package/build/internal/IdProvider/IdProvider.js +0 -99
  428. package/build/internal/IdProvider/Provider.js +0 -67
  429. package/build/internal/IdProvider/package.json +0 -3
  430. package/build/internal/IdProvider/tests/useId-specs.js +0 -64
  431. package/build/internal/IdProvider/useId.js +0 -58
  432. package/build/internal/Pure/Pure.js +0 -133
  433. package/build/internal/Pure/package.json +0 -3
  434. package/build/internal/localized-fonts/localized-fonts.js +0 -272
  435. package/build/internal/localized-fonts/package.json +0 -3
  436. package/build/internal/selection/package.json +0 -3
  437. package/build/internal/selection/selection.js +0 -78
  438. package/build/internal/selection/tests/selection-specs.js +0 -158
  439. package/build/internal/validators/package.json +0 -4
  440. package/build/internal/validators/validators.js +0 -163
  441. package/build/package-lock.json +0 -234
  442. package/build/package.json +0 -39
  443. package/build/resolution/ResolutionDecorator.js +0 -183
  444. package/build/resolution/index.js +0 -47
  445. package/build/resolution/package.json +0 -3
  446. package/build/resolution/resolution.js +0 -529
  447. package/build/resolution/tests/ResolutionDecorator-specs.js +0 -42
  448. package/build/resolution/tests/resolution-specs.js +0 -90
  449. package/build/styles/core.less +0 -91
  450. package/build/styles/mixins.less +0 -444
  451. package/build/styles/variables.less +0 -7
  452. package/build/useControlledState/package.json +0 -3
  453. package/build/useControlledState/tests/useControlledState-specs.js +0 -100
  454. package/build/useControlledState/useControlledState.js +0 -68
  455. package/build/useScroll/ScrollAnimator.js +0 -146
  456. package/build/useScroll/Scrollbar.js +0 -238
  457. package/build/useScroll/ScrollbarTrack.js +0 -62
  458. package/build/useScroll/package.json +0 -3
  459. package/build/useScroll/useScroll.js +0 -1730
  460. package/build/useScroll/utilDOM.js +0 -65
  461. package/build/useScroll/utilEvent.js +0 -39
  462. package/useScroll/Scrollbar.module.less +0 -37
  463. package/useScroll/ScrollbarTrack.module.less +0 -48
  464. package/useScroll/useScroll.module.less +0 -44
@@ -1,16 +1,77 @@
1
- import classNames from 'classnames';
2
- import EnactPropTypes from '@enact/core/internal/prop-types';
3
- import {forward} from '@enact/core/handle';
4
- import {platform} from '@enact/core/platform';
5
- import {clamp} from '@enact/core/util';
6
- import PropTypes from 'prop-types';
7
- import equals from 'ramda/src/equals';
8
- import React, {Component} from 'react';
1
+ "use strict";
9
2
 
10
- import css from './VirtualList.module.less';
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.VirtualListBasic = exports.itemSizesShape = exports.gridListItemSizeShape = exports["default"] = void 0;
7
+
8
+ var _classnames = _interopRequireDefault(require("classnames"));
9
+
10
+ var _propTypes = _interopRequireDefault(require("@enact/core/internal/prop-types"));
11
+
12
+ var _handle = require("@enact/core/handle");
13
+
14
+ var _platform = require("@enact/core/platform");
15
+
16
+ var _util = require("@enact/core/util");
17
+
18
+ var _propTypes2 = _interopRequireDefault(require("prop-types"));
19
+
20
+ var _equals = _interopRequireDefault(require("ramda/src/equals"));
21
+
22
+ var _react = _interopRequireWildcard(require("react"));
23
+
24
+ var _VirtualListModule = _interopRequireDefault(require("./VirtualList.module.css"));
25
+
26
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
27
+
28
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
+
30
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
31
+
32
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
33
+
34
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
35
+
36
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
37
+
38
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
39
+
40
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
41
+
42
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
43
+
44
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
45
+
46
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
47
+
48
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
11
49
 
12
- const nop = () => {};
50
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
13
51
 
52
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
53
+
54
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
55
+
56
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
57
+
58
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
59
+
60
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
61
+
62
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
63
+
64
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
65
+
66
+ function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
67
+
68
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
69
+
70
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
71
+
72
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
73
+
74
+ var nop = function nop() {};
14
75
  /**
15
76
  * The shape for the grid list item size
16
77
  * in a list for [VirtualGridList]{@link ui/VirtualList.VirtualGridList}.
@@ -21,11 +82,12 @@ const nop = () => {};
21
82
  * @property {Number} minHeight The minimum height of the grid list item.
22
83
  * @public
23
84
  */
24
- const gridListItemSizeShape = PropTypes.shape({
25
- minHeight: PropTypes.number.isRequired,
26
- minWidth: PropTypes.number.isRequired
27
- });
28
85
 
86
+
87
+ var gridListItemSizeShape = _propTypes2["default"].shape({
88
+ minHeight: _propTypes2["default"].number.isRequired,
89
+ minWidth: _propTypes2["default"].number.isRequired
90
+ });
29
91
  /**
30
92
  * The shape for the list different item size
31
93
  * in a list for [VirtualList]{@link ui/VirtualList.VirtualList}.
@@ -36,11 +98,14 @@ const gridListItemSizeShape = PropTypes.shape({
36
98
  * @property {Number[]} size An array of the list item size. If it is not defined, the list items will render with the `minSize` size.
37
99
  * @public
38
100
  */
39
- const itemSizesShape = PropTypes.shape({
40
- minSize: PropTypes.number.isRequired,
41
- size: PropTypes.arrayOf(PropTypes.number)
42
- });
43
101
 
102
+
103
+ exports.gridListItemSizeShape = gridListItemSizeShape;
104
+
105
+ var itemSizesShape = _propTypes2["default"].shape({
106
+ minSize: _propTypes2["default"].number.isRequired,
107
+ size: _propTypes2["default"].arrayOf(_propTypes2["default"].number)
108
+ });
44
109
  /**
45
110
  * A basic base component for
46
111
  * [VirtualList]{@link ui/VirtualList.VirtualList} and [VirtualGridList]{@link ui/VirtualList.VirtualGridList}.
@@ -50,1227 +115,1389 @@ const itemSizesShape = PropTypes.shape({
50
115
  * @ui
51
116
  * @public
52
117
  */
53
- class VirtualListBasic extends Component {
54
- displayName = 'ui:VirtualListBasic';
55
-
56
- static propTypes = /** @lends ui/VirtualList.VirtualListBasic.prototype */ {
57
- /**
58
- * The rendering function called for each item in the list.
59
- *
60
- * > **Note**: The list does **not** always render a component whenever its render function is called
61
- * due to performance optimization.
62
- *
63
- * Example:
64
- * ```
65
- * renderItem = ({index, ...rest}) => {
66
- *
67
- * return (
68
- * <MyComponent index={index} {...rest} />
69
- * );
70
- * }
71
- * ```
72
- *
73
- * @type {Function}
74
- * @param {Object} event
75
- * @param {Number} event.data-index It is required for `Spotlight` 5-way navigation. Pass to the root element in the component.
76
- * @param {Number} event.index The index number of the component to render
77
- *
78
- * @required
79
- * @public
80
- */
81
- itemRenderer: PropTypes.func.isRequired,
82
-
83
- /**
84
- * The size of an item for the list; valid values are either a number for `VirtualList`
85
- * or an object that has `minWidth` and `minHeight` for `VirtualGridList`.
86
- *
87
- * @type {Number|ui/VirtualList.gridListItemSizeShape}
88
- * @required
89
- * @private
90
- */
91
- itemSize: PropTypes.oneOfType([
92
- PropTypes.number,
93
- gridListItemSizeShape
94
- ]).isRequired,
95
-
96
- /**
97
- * Callback method of scrollTo.
98
- * Normally, useScroll should set this value.
99
- *
100
- * @type {Function}
101
- * @private
102
- */
103
- cbScrollTo: PropTypes.func,
104
-
105
- /**
106
- * Additional props included in the object passed to the `itemRenderer` callback.
107
- *
108
- * @type {Object}
109
- * @public
110
- */
111
- childProps: PropTypes.object,
112
-
113
- /**
114
- * Client size of the list; valid values are an object that has `clientWidth` and `clientHeight`.
115
- *
116
- * @type {Object}
117
- * @property {Number} clientHeight The client height of the list.
118
- * @property {Number} clientWidth The client width of the list.
119
- * @public
120
- */
121
- clientSize: PropTypes.shape({
122
- clientHeight: PropTypes.number.isRequired,
123
- clientWidth: PropTypes.number.isRequired
124
- }),
125
-
126
- /**
127
- * Disable voice control feature of component.
128
- *
129
- * @type {Boolean}
130
- * @public
131
- */
132
- 'data-webos-voice-disabled': PropTypes.bool,
133
-
134
- /**
135
- * Activates the component for voice control.
136
- *
137
- * @type {Boolean}
138
- * @public
139
- */
140
- 'data-webos-voice-focused': PropTypes.bool,
141
-
142
- /**
143
- * The voice control group label.
144
- *
145
- * @type {String}
146
- * @public
147
- */
148
- 'data-webos-voice-group-label': PropTypes.string,
149
-
150
- /**
151
- * The number of items of data the list contains.
152
- *
153
- * @type {Number}
154
- * @default 0
155
- * @public
156
- */
157
- dataSize: PropTypes.number,
158
-
159
- /**
160
- * The layout direction of the list.
161
- *
162
- * Valid values are:
163
- * * `'horizontal'`, and
164
- * * `'vertical'`.
165
- *
166
- * @type {String}
167
- * @default 'vertical'
168
- * @public
169
- */
170
- direction: PropTypes.oneOf(['horizontal', 'vertical']),
171
-
172
- /**
173
- * Called to get the scroll affordance from themed component.
174
- *
175
- * @type {Function}
176
- * @private
177
- */
178
- getAffordance: PropTypes.func,
179
-
180
- /**
181
- * Called to get the props for list items.
182
- *
183
- * @type {Function}
184
- * @private
185
- */
186
- getComponentProps: PropTypes.func,
187
-
188
- /**
189
- * Ref for items
190
- *
191
- * @type {Object}
192
- * @private
193
- */
194
- itemRefs: PropTypes.object,
195
-
196
- /**
197
- * The array for individually sized items.
198
- *
199
- * @type {Number[]}
200
- * @private
201
- */
202
- itemSizes: PropTypes.arrayOf(PropTypes.number),
203
-
204
- /**
205
- * Called when the range of items has updated.
206
- *
207
- * Event payload includes the `firstIndex` and `lastIndex` of the list.
208
- *
209
- * @type {Function}
210
- * @private
211
- */
212
- onUpdateItems: PropTypes.func,
213
-
214
- /**
215
- * Number of spare DOM node.
216
- * `3` is good for the default value experimentally and
217
- * this value is highly recommended not to be changed by developers.
218
- *
219
- * @type {Number}
220
- * @default 3
221
- * @private
222
- */
223
- overhang: PropTypes.number,
224
-
225
- /**
226
- * When `true`, the list will scroll by page. Otherwise the list will scroll by item.
227
- *
228
- * @type {Boolean}
229
- * @default false
230
- * @private
231
- */
232
- pageScroll: PropTypes.bool,
233
-
234
- /**
235
- * The render function for the placeholder elements.
236
- *
237
- * @type {Function}
238
- * @required
239
- * @private
240
- */
241
- placeholderRenderer: PropTypes.func,
242
-
243
- /**
244
- * The ARIA role for the list.
245
- *
246
- * @type {String}
247
- * @default 'list'
248
- * @public
249
- */
250
- role: PropTypes.string,
251
-
252
- /**
253
- * `true` if RTL, `false` if LTR.
254
- *
255
- * @type {Boolean}
256
- * @private
257
- */
258
- rtl: PropTypes.bool,
259
-
260
- /**
261
- * Ref for scroll content
262
- *
263
- * @type {Object|Function}}
264
- * @private
265
- */
266
- scrollContentRef: EnactPropTypes.ref,
267
-
268
- /**
269
- * Specifies how to scroll.
270
- *
271
- * Valid values are:
272
- * * `'translate'`,
273
- * * `'native'`.
274
- *
275
- * @type {String}
276
- * @default 'translate'
277
- * @public
278
- */
279
- scrollMode: PropTypes.string,
280
-
281
- /**
282
- * The spacing between items.
283
- *
284
- * @type {Number}
285
- * @default 0
286
- * @public
287
- */
288
- spacing: PropTypes.number,
289
-
290
- /**
291
- * Called to execute additional logic in a themed component when updating states and bounds.
292
- *
293
- * @type {Function}
294
- * @private
295
- */
296
- updateStatesAndBounds: PropTypes.func
297
- };
298
-
299
- static defaultProps = {
300
- cbScrollTo: nop,
301
- dataSize: 0,
302
- direction: 'vertical',
303
- getAffordance: () => (0),
304
- overhang: 3,
305
- pageScroll: false,
306
- scrollMode: 'translate',
307
- spacing: 0
308
- };
309
-
310
- constructor (props) {
311
- let nextState = null;
312
-
313
- super(props);
314
-
315
- this.contentRef = React.createRef();
316
- this.itemContainerRefs = [];
317
-
318
- if (props.clientSize) {
319
- this.calculateMetrics(props);
320
- nextState = this.getStatesAndUpdateBounds(props);
321
- }
322
-
323
- this.state = {
324
- firstIndex: 0,
325
- numOfItems: 0,
326
- prevChildProps: null,
327
- prevFirstIndex: 0,
328
- updateFrom: 0,
329
- updateTo: 0,
330
- ...nextState
331
- };
332
- }
333
-
334
- static getDerivedStateFromProps (props, state) {
335
- const
336
- shouldInvalidate = (
337
- state.prevFirstIndex === state.firstIndex ||
338
- state.prevChildProps !== props.childProps
339
- ),
340
- diff = state.firstIndex - state.prevFirstIndex,
341
- updateTo = (-state.numOfItems >= diff || diff > 0 || shouldInvalidate) ? state.firstIndex + state.numOfItems : state.prevFirstIndex,
342
- updateFrom = (0 >= diff || diff >= state.numOfItems || shouldInvalidate) ? state.firstIndex : state.prevFirstIndex + state.numOfItems,
343
- nextUpdateFromAndTo = (state.updateFrom !== updateFrom || state.updateTo !== updateTo) ? {updateFrom, updateTo} : null;
344
-
345
- return {
346
- ...nextUpdateFromAndTo,
347
- prevChildProps: props.childProps,
348
- prevFirstIndex: state.firstIndex
349
- };
350
- }
351
-
352
- // Calculate metrics for VirtualList after the 1st render to know client W/H.
353
- componentDidMount () {
354
- if (!this.props.clientSize) {
355
- this.calculateMetrics(this.props);
356
- // eslint-disable-next-line react/no-did-mount-set-state
357
- this.setState(this.getStatesAndUpdateBounds(this.props));
358
- } else {
359
- this.emitUpdateItems();
360
- }
361
-
362
- if (this.props.itemSizes) {
363
- this.adjustItemPositionWithItemSize();
364
- } else {
365
- this.setContainerSize();
366
- }
367
- }
368
-
369
- componentDidUpdate (prevProps, prevState) {
370
- let deferScrollTo = false;
371
- const {firstIndex, numOfItems} = this.state;
372
-
373
- this.shouldUpdateBounds = false;
374
-
375
- // TODO: remove `this.hasDataSizeChanged` and fix useScroll
376
- this.hasDataSizeChanged = (prevProps.dataSize !== this.props.dataSize);
377
-
378
- if (prevState.firstIndex !== firstIndex || prevState.numOfItems !== numOfItems) {
379
- this.emitUpdateItems();
380
- }
381
-
382
- // When an item expands or shrinks,
383
- // we need to calculate the item position again and
384
- // the item needs to scroll into view if the item does not show fully.
385
- if (this.props.itemSizes) {
386
- if (this.itemPositions.length > this.props.itemSizes.length) {
387
- // The item with `this.props.itemSizes.length` index is not rendered yet.
388
- // So the item could scroll into view after it rendered.
389
- // To do it, `this.props.itemSizes.length` value is cached in `this.indexToScrollIntoView`.
390
- this.indexToScrollIntoView = this.props.itemSizes.length;
391
-
392
- this.itemPositions = [...this.itemPositions.slice(0, this.props.itemSizes.length)];
393
- this.adjustItemPositionWithItemSize();
394
- } else {
395
- const {indexToScrollIntoView} = this;
396
-
397
- this.adjustItemPositionWithItemSize();
398
-
399
- if (indexToScrollIntoView !== -1) {
400
- // Currently we support expandable items in only vertical VirtualList.
401
- // So the top and bottom of the boundaries are checked.
402
- const
403
- scrollBounds = {top: this.scrollPosition, bottom: this.scrollPosition + this.scrollBounds.clientHeight},
404
- itemBounds = {top: this.getGridPosition(indexToScrollIntoView).primaryPosition, bottom: this.getItemBottomPosition(indexToScrollIntoView)};
405
-
406
- if (itemBounds.top < scrollBounds.top) {
407
- this.props.cbScrollTo({
408
- index: indexToScrollIntoView,
409
- stickTo: 'start',
410
- animate: true
411
- });
412
- } else if (itemBounds.bottom > scrollBounds.bottom) {
413
- this.props.cbScrollTo({
414
- index: indexToScrollIntoView,
415
- stickTo: 'end',
416
- animate: true
417
- });
418
- }
419
- }
420
-
421
- this.indexToScrollIntoView = -1;
422
- }
423
- }
424
-
425
- if (
426
- prevProps.direction !== this.props.direction ||
427
- prevProps.overhang !== this.props.overhang ||
428
- prevProps.spacing !== this.props.spacing ||
429
- !equals(prevProps.itemSize, this.props.itemSize)
430
- ) {
431
- const {x, y} = this.getXY(this.scrollPosition, 0);
432
-
433
- this.calculateMetrics(this.props);
434
- // eslint-disable-next-line react/no-did-update-set-state
435
- this.setState(this.getStatesAndUpdateBounds(this.props));
436
- this.setContainerSize();
437
-
438
- const {clientHeight, clientWidth, scrollHeight, scrollWidth} = this.scrollBounds;
439
- const xMax = scrollWidth - clientWidth;
440
- const yMax = scrollHeight - clientHeight;
441
-
442
- this.updateScrollPosition({
443
- x: xMax > x ? x : xMax,
444
- y: yMax > y ? y : yMax
445
- });
446
-
447
- deferScrollTo = true;
448
- } else if (this.hasDataSizeChanged) {
449
- const newState = this.getStatesAndUpdateBounds(this.props, this.state.firstIndex);
450
- // eslint-disable-next-line react/no-did-update-set-state
451
- this.setState(newState);
452
- this.setContainerSize();
453
-
454
- deferScrollTo = true;
455
- } else if (prevProps.rtl !== this.props.rtl) {
456
- this.updateScrollPosition(this.getXY(this.scrollPosition, 0));
457
- }
458
-
459
- const maxPos = this.isPrimaryDirectionVertical ? this.scrollBounds.maxTop : this.scrollBounds.maxLeft;
460
- let currentPos = this.scrollPosition;
461
-
462
- if (this.props.scrollMode === 'native' && this.scrollToPositionTarget >= 0) {
463
- currentPos = this.scrollToPositionTarget;
464
- }
465
-
466
- if (!deferScrollTo && currentPos > maxPos) {
467
- this.props.cbScrollTo({position: (this.isPrimaryDirectionVertical) ? {y: maxPos} : {x: maxPos}, animate: false});
468
- this.scrollToPositionTarget = -1;
469
- }
470
- }
471
-
472
- scrollBounds = {
473
- clientWidth: 0,
474
- clientHeight: 0,
475
- scrollWidth: 0,
476
- scrollHeight: 0,
477
- maxLeft: 0,
478
- maxTop: 0
479
- };
480
-
481
- moreInfo = {
482
- firstVisibleIndex: null,
483
- lastVisibleIndex: null
484
- };
485
-
486
- primary = null;
487
- secondary = null;
488
-
489
- isPrimaryDirectionVertical = true;
490
- isItemSized = false;
491
-
492
- shouldUpdateBounds = false;
493
-
494
- dimensionToExtent = 0;
495
- threshold = 0;
496
- maxFirstIndex = 0;
497
- curDataSize = 0;
498
- hasDataSizeChanged = false;
499
- cc = [];
500
- scrollPosition = 0;
501
- scrollPositionTarget = 0;
502
- scrollToPositionTarget = -1;
503
-
504
- // For individually sized item
505
- itemPositions = [];
506
- indexToScrollIntoView = -1;
507
-
508
- updateScrollPosition = ({x, y}, rtl = this.props.rtl) => {
509
- if (this.props.scrollMode === 'native') {
510
- this.scrollToPosition(x, y, rtl);
511
- } else {
512
- this.setScrollPositionTarget (x, y);
513
- this.setScrollPosition(x, y, rtl);
514
- }
515
- };
516
-
517
- isVertical = () => this.isPrimaryDirectionVertical;
518
-
519
- isHorizontal = () => !this.isPrimaryDirectionVertical;
520
-
521
- getScrollBounds = () => this.scrollBounds;
522
-
523
- getMoreInfo = () => this.moreInfo;
524
-
525
- getGridPosition (index) {
526
- const
527
- {dataSize, itemSizes} = this.props,
528
- {dimensionToExtent, itemPositions, primary, secondary} = this,
529
- secondaryPosition = (index % dimensionToExtent) * secondary.gridSize,
530
- extent = Math.floor(index / dimensionToExtent);
531
- let primaryPosition;
532
-
533
- if (itemSizes && typeof itemSizes[index] !== 'undefined' && dataSize > index) {
534
- const firstIndexInExtent = extent * dimensionToExtent;
535
-
536
- if (!itemPositions[firstIndexInExtent]) {
537
- // Cache individually sized item positions
538
- for (let i = itemPositions.length; i <= index; i++) {
539
- this.calculateAndCacheItemPosition(i);
540
- }
541
- }
542
-
543
- if (itemPositions[firstIndexInExtent]) {
544
- primaryPosition = itemPositions[firstIndexInExtent].position;
545
- } else {
546
- primaryPosition = extent * primary.gridSize;
547
- }
548
- } else {
549
- primaryPosition = extent * primary.gridSize;
550
- }
551
-
552
- return {primaryPosition, secondaryPosition};
553
- }
554
-
555
- // For individually sized item
556
- getItemBottomPosition = (index) => {
557
- const
558
- itemPosition = this.itemPositions[index],
559
- itemSize = this.props.itemSizes[index];
560
-
561
- if (itemPosition && (itemSize || itemSize === 0)) {
562
- return itemPosition.position + itemSize;
563
- } else {
564
- return index * this.primary.gridSize - this.props.spacing;
565
- }
566
- };
567
-
568
- // For individually sized item
569
- getItemTopPositionFromPreviousItemBottomPosition = (index, spacing) => {
570
- return index === 0 ? 0 : this.getItemBottomPosition(index - 1) + spacing;
571
- };
572
-
573
- getItemPosition = (index, stickTo = 'start', optionalOffset = 0) => {
574
- const {isPrimaryDirectionVertical, primary, scrollBounds} = this;
575
- const maxPos = isPrimaryDirectionVertical ? scrollBounds.maxTop : scrollBounds.maxLeft;
576
- const position = this.getGridPosition(index);
577
- let offset = 0;
578
-
579
- if (stickTo === 'start') {
580
- offset = optionalOffset;
581
- } else if (this.props.itemSizes) {
582
- offset = primary.clientSize - this.props.itemSizes[index] - optionalOffset;
583
- } else {
584
- offset = primary.clientSize - primary.itemSize - optionalOffset;
585
- }
586
-
587
- position.primaryPosition = clamp(0, maxPos, position.primaryPosition - offset);
588
-
589
- return this.gridPositionToItemPosition(position);
590
- };
591
-
592
- gridPositionToItemPosition = ({primaryPosition, secondaryPosition}) =>
593
- (this.isPrimaryDirectionVertical ? {left: secondaryPosition, top: primaryPosition} : {left: primaryPosition, top: secondaryPosition});
594
-
595
- getXY = (primaryPosition, secondaryPosition) => (this.isPrimaryDirectionVertical ? {x: secondaryPosition, y: primaryPosition} : {x: primaryPosition, y: secondaryPosition});
596
-
597
- getClientSize = (node) => ({
598
- clientWidth: node.clientWidth,
599
- clientHeight: node.clientHeight
600
- });
601
-
602
- emitUpdateItems () {
603
- const {dataSize} = this.props;
604
- const {firstIndex, numOfItems} = this.state;
605
-
606
- forward('onUpdateItems', {
607
- firstIndex: firstIndex,
608
- lastIndex: Math.min(firstIndex + numOfItems, dataSize)
609
- }, this.props);
610
- }
611
-
612
- calculateMetrics (props) {
613
- const
614
- {clientSize, direction, itemSize, overhang, scrollMode, spacing} = props,
615
- node = this.props.scrollContentRef.current;
616
-
617
- if (!clientSize && !node) {
618
- return;
619
- }
620
-
621
- const
622
- {clientWidth, clientHeight} = clientSize || this.getClientSize(node),
623
- heightInfo = {
624
- clientSize: clientHeight,
625
- minItemSize: itemSize.minHeight || null,
626
- itemSize: itemSize
627
- },
628
- widthInfo = {
629
- clientSize: clientWidth,
630
- minItemSize: itemSize.minWidth || null,
631
- itemSize: itemSize
632
- };
633
- let primary, secondary, dimensionToExtent, thresholdBase;
634
-
635
- this.isPrimaryDirectionVertical = (direction === 'vertical');
636
-
637
- if (this.isPrimaryDirectionVertical) {
638
- primary = heightInfo;
639
- secondary = widthInfo;
640
- } else {
641
- primary = widthInfo;
642
- secondary = heightInfo;
643
- }
644
- dimensionToExtent = 1;
645
-
646
- this.isItemSized = (primary.minItemSize && secondary.minItemSize);
647
-
648
- if (this.isItemSized) {
649
- // the number of columns is the ratio of the available width plus the spacing
650
- // by the minimum item width plus the spacing
651
- dimensionToExtent = Math.max(Math.floor((secondary.clientSize + spacing) / (secondary.minItemSize + spacing)), 1);
652
- // the actual item width is a ratio of the remaining width after all columns
653
- // and spacing are accounted for and the number of columns that we know we should have
654
- secondary.itemSize = Math.floor((secondary.clientSize - (spacing * (dimensionToExtent - 1))) / dimensionToExtent);
655
- // the actual item height is related to the item width
656
- primary.itemSize = Math.floor(primary.minItemSize * (secondary.itemSize / secondary.minItemSize));
657
- }
658
-
659
- primary.gridSize = primary.itemSize + spacing;
660
- secondary.gridSize = secondary.itemSize + spacing;
661
- thresholdBase = primary.gridSize * Math.ceil(overhang / 2);
662
-
663
- this.threshold = {min: -Infinity, max: thresholdBase, base: thresholdBase};
664
- this.dimensionToExtent = dimensionToExtent;
665
-
666
- this.primary = primary;
667
- this.secondary = secondary;
668
-
669
- // reset
670
- this.scrollPosition = 0;
671
- this.scrollToPositionTarget = -1;
672
- if (scrollMode === 'translate' && this.contentRef.current) {
673
- this.contentRef.current.style.transform = null;
674
- } else if (scrollMode === 'native' && node) {
675
- node.style.scrollBehavior = null;
676
- this.updateScrollPosition(this.getXY(this.scrollPosition, 0));
677
- node.style.scrollBehavior = 'smooth';
678
- }
679
- }
680
-
681
- getStatesAndUpdateBounds = (props, firstIndex = 0) => {
682
- const
683
- {dataSize, overhang, updateStatesAndBounds} = props,
684
- {dimensionToExtent, primary, moreInfo, scrollPosition} = this,
685
- numOfItems = Math.min(dataSize, dimensionToExtent * (Math.ceil(primary.clientSize / primary.gridSize) + overhang)),
686
- wasFirstIndexMax = ((this.maxFirstIndex < moreInfo.firstVisibleIndex - dimensionToExtent) && (firstIndex === this.maxFirstIndex)),
687
- dataSizeDiff = dataSize - this.curDataSize;
688
- let newFirstIndex = firstIndex;
689
-
690
- // When calling setState() except in didScroll(), `shouldUpdateBounds` should be `true`
691
- // so that setState() in didScroll() could be called to override state.
692
- // Before calling setState() except in didScroll(), getStatesAndUpdateBounds() is always called.
693
- // So `shouldUpdateBounds` is true here.
694
- this.shouldUpdateBounds = true;
695
-
696
- this.maxFirstIndex = Math.ceil((dataSize - numOfItems) / dimensionToExtent) * dimensionToExtent;
697
- this.curDataSize = dataSize;
698
-
699
- // reset children
700
- this.cc = [];
701
- this.itemPositions = []; // For individually sized item
702
- this.calculateScrollBounds(props);
703
- this.updateMoreInfo(dataSize, scrollPosition);
704
-
705
- if (!(updateStatesAndBounds && updateStatesAndBounds({
706
- cbScrollTo: props.cbScrollTo,
707
- numOfItems,
708
- dataSize,
709
- moreInfo
710
- }))) {
711
- newFirstIndex = this.calculateFirstIndex(props, wasFirstIndexMax, dataSizeDiff, firstIndex);
712
- }
713
-
714
- return {
715
- firstIndex: Math.min(newFirstIndex, this.maxFirstIndex),
716
- numOfItems: numOfItems
717
- };
718
- };
719
-
720
- calculateFirstIndex (props, wasFirstIndexMax, dataSizeDiff, firstIndex) {
721
- const
722
- {overhang} = props,
723
- {dimensionToExtent, isPrimaryDirectionVertical, maxFirstIndex, primary, scrollBounds, scrollPosition, threshold} = this,
724
- {gridSize} = primary;
725
- let newFirstIndex = firstIndex;
726
-
727
- if (wasFirstIndexMax && dataSizeDiff > 0) { // If dataSize increased from bottom, we need adjust firstIndex
728
- // If this is a gridlist and dataSizeDiff is smaller than 1 line, we are adjusting firstIndex without threshold change.
729
- if (dimensionToExtent > 1 && dataSizeDiff < dimensionToExtent) {
730
- newFirstIndex = maxFirstIndex;
731
- } else { // For other bottom adding case, we need to update firstIndex and threshold.
732
- const
733
- maxPos = isPrimaryDirectionVertical ? scrollBounds.maxTop : scrollBounds.maxLeft,
734
- maxOfMin = maxPos - threshold.base,
735
- numOfUpperLine = Math.floor(overhang / 2),
736
- firstIndexFromPosition = Math.floor(scrollPosition / gridSize),
737
- expectedFirstIndex = Math.max(0, firstIndexFromPosition - numOfUpperLine);
738
-
739
- // To navigate with 5way, we need to adjust firstIndex to the next line
740
- // since at the bottom we have num of overhang lines for upper side but none for bottom side
741
- // So we add numOfUpperLine at the top and rest lines at the bottom
742
- newFirstIndex = Math.min(maxFirstIndex, expectedFirstIndex * dimensionToExtent);
743
-
744
- // We need to update threshold also since we moved the firstIndex
745
- threshold.max = Math.min(maxPos, threshold.max + gridSize);
746
- threshold.min = Math.min(maxOfMin, threshold.max - gridSize);
747
- }
748
- } else { // Other cases, we can keep the min value between firstIndex and maxFirstIndex. No need to change threshold
749
- newFirstIndex = Math.min(firstIndex, maxFirstIndex);
750
- }
751
-
752
- return newFirstIndex;
753
- }
754
-
755
- calculateScrollBounds (props) {
756
- const
757
- {clientSize} = props,
758
- node = this.props.scrollContentRef.current;
759
-
760
- if (!clientSize && !node) {
761
- return;
762
- }
763
-
764
- const
765
- {scrollBounds, isPrimaryDirectionVertical} = this,
766
- {clientWidth, clientHeight} = clientSize || this.getClientSize(node);
767
- let maxPos;
768
-
769
- scrollBounds.clientWidth = clientWidth;
770
- scrollBounds.clientHeight = clientHeight;
771
- scrollBounds.scrollWidth = this.getScrollWidth();
772
- scrollBounds.scrollHeight = this.getScrollHeight();
773
- scrollBounds.maxLeft = Math.max(0, scrollBounds.scrollWidth - clientWidth);
774
- scrollBounds.maxTop = Math.max(0, scrollBounds.scrollHeight - clientHeight);
775
-
776
- // correct position
777
- maxPos = isPrimaryDirectionVertical ? scrollBounds.maxTop : scrollBounds.maxLeft;
778
-
779
- this.syncThreshold(maxPos);
780
- }
781
-
782
- setContainerSize = () => {
783
- if (this.contentRef.current) {
784
- this.contentRef.current.style.width = this.scrollBounds.scrollWidth + (this.isPrimaryDirectionVertical ? -1 : 0) + 'px';
785
- this.contentRef.current.style.height = this.scrollBounds.scrollHeight + (this.isPrimaryDirectionVertical ? 0 : -1) + 'px';
786
- }
787
- };
788
-
789
- updateMoreInfo (dataSize, primaryPosition) {
790
- const
791
- {dimensionToExtent, moreInfo} = this,
792
- {itemSize, gridSize, clientSize} = this.primary;
793
-
794
- if (dataSize <= 0) {
795
- moreInfo.firstVisibleIndex = null;
796
- moreInfo.lastVisibleIndex = null;
797
- } else if (this.props.itemSizes) {
798
- const {firstIndex, numOfItems} = this.state;
799
- const {isPrimaryDirectionVertical, scrollBounds: {clientWidth, clientHeight}, scrollPosition} = this;
800
- const size = isPrimaryDirectionVertical ? clientHeight : clientWidth;
801
-
802
- let firstVisibleIndex = null, lastVisibleIndex = null;
803
-
804
- for (let i = firstIndex; i < firstIndex + numOfItems; i++) {
805
- if (scrollPosition <= this.getItemBottomPosition(i)) {
806
- firstVisibleIndex = i;
807
- break;
808
- }
809
- }
810
-
811
- for (let i = firstIndex + numOfItems - 1; i >= firstIndex; i--) {
812
- if (scrollPosition + size >= this.getItemBottomPosition(i) - this.props.itemSizes[i]) {
813
- lastVisibleIndex = i;
814
- break;
815
- }
816
- }
817
-
818
- if (firstVisibleIndex > lastVisibleIndex) {
819
- firstVisibleIndex = null;
820
- lastVisibleIndex = null;
821
- }
822
-
823
- moreInfo.firstVisibleIndex = firstVisibleIndex;
824
- moreInfo.lastVisibleIndex = lastVisibleIndex;
825
- } else {
826
- moreInfo.firstVisibleIndex = (Math.floor((primaryPosition - itemSize) / gridSize) + 1) * dimensionToExtent;
827
- moreInfo.lastVisibleIndex = Math.min(dataSize - 1, Math.ceil((primaryPosition + clientSize) / gridSize) * dimensionToExtent - 1);
828
- }
829
- }
830
-
831
- syncThreshold (maxPos) {
832
- const {threshold} = this;
833
-
834
- if (threshold.max > maxPos) {
835
- if (maxPos < threshold.base) {
836
- threshold.max = threshold.base;
837
- threshold.min = -Infinity;
838
- } else {
839
- threshold.max = maxPos;
840
- threshold.min = maxPos - threshold.base;
841
- }
842
- }
843
- }
844
-
845
- // scrollMode 'native' only
846
- scrollToPosition (x, y, rtl = this.props.rtl) {
847
- if (this.props.scrollContentRef.current && this.props.scrollContentRef.current.scrollTo) {
848
- if (rtl) {
849
- x = (platform.ios || platform.safari) ? -x : this.scrollBounds.maxLeft - x;
850
- }
851
-
852
- this.props.scrollContentRef.current.scrollTo(x, y);
853
- }
854
- }
855
-
856
- // scrollMode 'native' only
857
- setScrollToPositionTarget (x, y) {
858
- if (this.isPrimaryDirectionVertical) {
859
- this.scrollToPositionTarget = y;
860
- } else {
861
- this.scrollToPositionTarget = x;
862
- }
863
- }
864
-
865
- // scrollMode 'translate' only
866
- setScrollPositionTarget (x, y) {
867
- // The `x`, `y` as parameters in scrollToPosition() are the position when stopping scrolling.
868
- // But the `x`, `y` as parameters in setScrollPosition() are the position between current position and the position stopping scrolling.
869
- // To know the position when stopping scrolling properly, `x` and `y` are passed and cached in `this.scrollPositionTarget`.
870
- if (this.isPrimaryDirectionVertical) {
871
- this.scrollPositionTarget = y;
872
- } else {
873
- this.scrollPositionTarget = x;
874
- }
875
- }
876
-
877
- // scrollMode 'translate' only
878
- setScrollPosition (x, y, rtl = this.props.rtl) {
879
- if (this.contentRef.current) {
880
- this.contentRef.current.style.transform = `translate3d(${rtl ? x : -x}px, -${y}px, 0)`;
881
- this.didScroll(x, y);
882
- }
883
- }
884
-
885
- didScroll (x, y) {
886
- const
887
- {dataSize, spacing, itemSizes} = this.props,
888
- {firstIndex} = this.state,
889
- {isPrimaryDirectionVertical, threshold, dimensionToExtent, maxFirstIndex, scrollBounds, itemPositions} = this,
890
- {clientSize, gridSize} = this.primary,
891
- maxPos = isPrimaryDirectionVertical ? scrollBounds.maxTop : scrollBounds.maxLeft;
892
- let newFirstIndex = firstIndex, index, pos, size, itemPosition;
893
-
894
- if (isPrimaryDirectionVertical) {
895
- pos = y;
896
- } else {
897
- pos = x;
898
- }
899
-
900
- if (pos > threshold.max || pos < threshold.min) {
901
- let newThresholdMin = -Infinity, newThresholdMax = Infinity;
902
-
903
- if (this.props.itemSizes) {
904
- const overhangBefore = Math.floor(this.props.overhang / 2);
905
- let firstRenderedIndex = -1;
906
-
907
- // find an item which is known as placed the first rendered item's position
908
- for (index = 0; index < dataSize; index += dimensionToExtent) {
909
- itemPosition = itemPositions[index];
910
- size = itemSizes[index];
911
- if (itemPosition && size && itemPosition.position + size >= pos && itemPosition.position <= pos + clientSize) {
912
- firstRenderedIndex = index;
913
- break;
914
- }
915
- }
916
-
917
- // found an item which is visible within a current viewport
918
- if (index < dataSize) {
919
- if (itemPosition.position <= pos) {
920
- newFirstIndex = firstRenderedIndex - overhangBefore * dimensionToExtent;
921
- newThresholdMin = itemPosition.position;
922
- newThresholdMax = newThresholdMin + size + spacing;
923
- } else {
924
- const diffToFirstIndex = Math.ceil((itemPosition.position - pos) / gridSize);
925
- newFirstIndex = firstRenderedIndex - (diffToFirstIndex + overhangBefore) * dimensionToExtent;
926
- newThresholdMin = itemPosition.position - diffToFirstIndex * gridSize;
927
- newThresholdMax = newThresholdMin + gridSize;
928
- }
929
- } else { // calculate the first index based on assuming that all items have minimal size
930
- const firstExtent = Math.max(
931
- 0,
932
- Math.min(
933
- Math.floor(maxFirstIndex / dimensionToExtent),
934
- Math.floor((pos - gridSize * overhangBefore) / gridSize)
935
- )
936
- );
937
-
938
- newFirstIndex = firstExtent * dimensionToExtent;
939
- newThresholdMin = (firstExtent + overhangBefore) * gridSize;
940
- newThresholdMax = newThresholdMin + gridSize;
941
- }
942
-
943
- newFirstIndex = Math.max(0, Math.min(maxFirstIndex, newFirstIndex));
944
- } else {
945
- const
946
- overhangBefore = Math.floor(this.props.overhang / 2),
947
- firstExtent = Math.max(
948
- 0,
949
- Math.min(
950
- Math.floor(maxFirstIndex / dimensionToExtent),
951
- Math.floor((pos - gridSize * overhangBefore) / gridSize)
952
- )
953
- );
954
-
955
- newFirstIndex = firstExtent * dimensionToExtent;
956
- newThresholdMin = (firstExtent + overhangBefore) * gridSize;
957
- newThresholdMax = newThresholdMin + gridSize;
958
- }
959
-
960
- threshold.min = newFirstIndex === 0 ? -Infinity : newThresholdMin;
961
- threshold.max = newFirstIndex === maxFirstIndex ? Infinity : newThresholdMax;
962
- }
963
-
964
- this.syncThreshold(maxPos);
965
- this.scrollPosition = pos;
966
- this.updateMoreInfo(dataSize, pos);
967
-
968
- if (this.shouldUpdateBounds || firstIndex !== newFirstIndex) {
969
- this.setState({firstIndex: newFirstIndex});
970
- }
971
- }
972
-
973
- // For individually sized item
974
- calculateAndCacheItemPosition (index) {
975
- const {itemSizes} = this.props;
976
-
977
- if (!this.itemPositions[index] && itemSizes[index]) {
978
- const
979
- {spacing} = this.props,
980
- position = this.getItemTopPositionFromPreviousItemBottomPosition(index, spacing);
981
-
982
- this.itemPositions[index] = {position};
983
- }
984
- }
985
-
986
- // For individually sized item
987
- applyItemPositionToDOMElement (index) {
988
- const
989
- {direction, rtl} = this.props,
990
- {numOfItems} = this.state,
991
- {itemPositions} = this,
992
- childNode = this.itemContainerRefs[index % numOfItems];
993
-
994
- if (childNode && itemPositions[index]) {
995
- const position = itemPositions[index].position;
996
- if (direction === 'vertical') {
997
- childNode.style.transform = `translate3d(0, ${position}px, 0)`;
998
- } else {
999
- childNode.style.transform = `translate3d(${position * (rtl ? -1 : 1)}px, 0, 0)`;
1000
- }
1001
- }
1002
- }
1003
-
1004
- // For individually sized item
1005
- updateThresholdWithItemPosition () {
1006
- const
1007
- {overhang} = this.props,
1008
- {firstIndex} = this.state,
1009
- {maxFirstIndex} = this,
1010
- numOfUpperLine = Math.floor(overhang / 2);
1011
-
1012
- this.threshold.min = firstIndex === 0 ? -Infinity : this.getItemBottomPosition(firstIndex + numOfUpperLine);
1013
- this.threshold.max = firstIndex === maxFirstIndex ? Infinity : this.getItemBottomPosition(firstIndex + (numOfUpperLine + 1));
1014
- }
1015
-
1016
- // For individually sized item
1017
- updateScrollBoundsWithItemPositions () {
1018
- const
1019
- {dataSize, itemSizes, spacing} = this.props,
1020
- {firstIndex, numOfItems} = this.state,
1021
- {isPrimaryDirectionVertical, itemPositions} = this,
1022
- scrollBoundsDimension = isPrimaryDirectionVertical ? 'scrollHeight' : 'scrollWidth';
1023
-
1024
- if (itemPositions.length === dataSize) { // all item sizes are known
1025
- this.scrollBounds[scrollBoundsDimension] =
1026
- itemSizes.reduce((acc, cur) => acc + cur, 0) + (dataSize - 1) * spacing;
1027
- } else {
1028
- for (let index = firstIndex + numOfItems - 1; index < dataSize; index++) {
1029
- const nextInfo = itemPositions[index + 1];
1030
- if (!nextInfo) {
1031
- const endPosition = this.getItemBottomPosition(index);
1032
- if (endPosition > this.scrollBounds[scrollBoundsDimension]) {
1033
- this.scrollBounds[scrollBoundsDimension] = endPosition;
1034
- }
1035
-
1036
- break;
1037
- }
1038
- }
1039
- }
1040
-
1041
- this.scrollBounds.maxTop = Math.max(0, this.scrollBounds.scrollHeight - this.scrollBounds.clientHeight);
1042
- }
1043
-
1044
- // For individually sized item
1045
- adjustItemPositionWithItemSize () {
1046
- if (this.cc.length) {
1047
- const
1048
- {dataSize} = this.props,
1049
- {firstIndex, numOfItems} = this.state,
1050
- lastIndex = firstIndex + numOfItems - 1;
1051
-
1052
- // Cache individually sized item positions
1053
- // and adjust item DOM element positions
1054
- for (let index = firstIndex; index <= lastIndex; index++) {
1055
- this.calculateAndCacheItemPosition(index);
1056
- this.applyItemPositionToDOMElement(index);
1057
- }
1058
-
1059
- // Update threshold based on this.itemPositions
1060
- this.updateThresholdWithItemPosition();
1061
-
1062
- // Update scroll bounds based on this.itemPositions
1063
- this.updateScrollBoundsWithItemPositions();
1064
-
1065
- // Set container size based on this.scrollbounds
1066
- this.setContainerSize();
1067
-
1068
- // Update moreInfo based on this.itemPositions
1069
- this.updateMoreInfo(dataSize, this.scrollPosition);
1070
- }
1071
- }
1072
-
1073
- composeStyle (width, height, primaryPosition, secondaryPosition) {
1074
- const
1075
- {x, y} = this.getXY(primaryPosition, secondaryPosition),
1076
- style = {
1077
- /* FIXME: RTL / this calculation only works for Chrome */
1078
- transform: `translate3d(${this.props.rtl ? -x : x}px, ${y}px, 0)`
1079
- };
1080
-
1081
- if (this.isItemSized) {
1082
- style.width = width;
1083
- style.height = height;
1084
- }
1085
-
1086
- return style;
1087
- }
1088
-
1089
- applyStyleToNewNode = (index, ...rest) => {
1090
- const
1091
- {childProps, itemRefs, itemRenderer, getComponentProps} = this.props,
1092
- key = index % this.state.numOfItems,
1093
- componentProps = getComponentProps && getComponentProps(index) || {},
1094
- itemContainerRef = (ref) => {
1095
- if (ref === null) {
1096
- itemRefs.current[key] = ref;
1097
- } else {
1098
- const itemNode = ref.children[0];
1099
-
1100
- itemRefs.current[key] = (parseInt(itemNode.dataset.index) === index) ?
1101
- itemNode :
1102
- ref.querySelector(`[data-index="${index}"]`);
1103
-
1104
- this.itemContainerRefs[key] = ref;
1105
- }
1106
- };
1107
-
1108
- this.cc[key] = (
1109
- <div className={css.listItem} key={key} ref={itemContainerRef} style={this.composeStyle(...rest)}>
1110
- {itemRenderer({...childProps, ...componentProps, index})}
1111
- </div>
1112
- );
1113
- };
1114
-
1115
- applyStyleToHideNode = (index) => {
1116
- const
1117
- {itemRefs} = this.props,
1118
- key = index % this.state.numOfItems,
1119
- itemContainerRef = () => (itemRefs.current[key] = null);
1120
-
1121
- this.cc[key] = <div key={key} ref={itemContainerRef} style={{display: 'none'}} />;
1122
- };
1123
-
1124
- positionItems () {
1125
- const
1126
- {dataSize, itemSizes} = this.props,
1127
- {firstIndex, numOfItems} = this.state,
1128
- {cc, isPrimaryDirectionVertical, dimensionToExtent, primary, secondary, itemPositions} = this;
1129
- let
1130
- hideTo = 0,
1131
- updateFrom = cc.length ? this.state.updateFrom : firstIndex,
1132
- updateTo = cc.length ? this.state.updateTo : firstIndex + numOfItems;
1133
-
1134
- if (updateFrom >= updateTo) {
1135
- return;
1136
- } else if (updateTo > dataSize) {
1137
- hideTo = updateTo;
1138
- updateTo = dataSize;
1139
- }
1140
-
1141
- let
1142
- width, height,
1143
- {primaryPosition, secondaryPosition} = this.getGridPosition(updateFrom);
1144
-
1145
- width = (isPrimaryDirectionVertical ? secondary.itemSize : primary.itemSize) + 'px';
1146
- height = (isPrimaryDirectionVertical ? primary.itemSize : secondary.itemSize) + 'px';
1147
-
1148
- // positioning items
1149
- for (let i = updateFrom, j = updateFrom % dimensionToExtent; i < updateTo; i++) {
1150
- this.applyStyleToNewNode(i, width, height, primaryPosition, secondaryPosition);
1151
-
1152
- if (++j === dimensionToExtent) {
1153
- secondaryPosition = 0;
1154
-
1155
- if (this.props.itemSizes) {
1156
- if (itemPositions[i + 1] || itemPositions[i + 1] === 0) {
1157
- primaryPosition = itemPositions[i + 1].position;
1158
- } else if (itemSizes[i]) {
1159
- primaryPosition += itemSizes[i] + this.props.spacing;
1160
- } else {
1161
- primaryPosition += primary.gridSize;
1162
- }
1163
- } else {
1164
- primaryPosition += primary.gridSize;
1165
- }
1166
-
1167
- j = 0;
1168
- } else {
1169
- secondaryPosition += secondary.gridSize;
1170
- }
1171
- }
1172
-
1173
- for (let i = updateTo; i < hideTo; i++) {
1174
- this.applyStyleToHideNode(i);
1175
- }
1176
- }
1177
-
1178
- getScrollHeight = () => (this.isPrimaryDirectionVertical ? this.getVirtualScrollDimension() + this.props.getAffordance() : this.scrollBounds.clientHeight);
1179
-
1180
- getScrollWidth = () => (this.isPrimaryDirectionVertical ? this.scrollBounds.clientWidth : this.getVirtualScrollDimension());
1181
-
1182
- getVirtualScrollDimension = () => {
1183
- if (this.props.itemSizes) {
1184
- return this.props.itemSizes.reduce((total, size, index) => (total + size + (index > 0 ? this.props.spacing : 0)), 0);
1185
- } else {
1186
- const
1187
- {dimensionToExtent, primary, curDataSize} = this,
1188
- {spacing} = this.props;
1189
-
1190
- return (Math.ceil(curDataSize / dimensionToExtent) * primary.gridSize) - spacing;
1191
- }
1192
- };
1193
-
1194
- syncClientSize = () => {
1195
- const
1196
- {props} = this,
1197
- node = this.props.scrollContentRef.current;
1198
-
1199
- if (!props.clientSize && !node) {
1200
- return false;
1201
- }
1202
-
1203
- const
1204
- {clientWidth, clientHeight} = props.clientSize || this.getClientSize(node),
1205
- {scrollBounds} = this;
1206
-
1207
- if (clientWidth !== scrollBounds.clientWidth || clientHeight !== scrollBounds.clientHeight) {
1208
- this.calculateMetrics(props);
1209
- this.setState(this.getStatesAndUpdateBounds(props));
1210
- this.setContainerSize();
1211
- return true;
1212
- }
1213
-
1214
- return false;
1215
- };
1216
-
1217
- // render
1218
-
1219
- render () {
1220
- const
1221
- {className, 'data-webos-voice-focused': voiceFocused, 'data-webos-voice-group-label': voiceGroupLabel, 'data-webos-voice-disabled': voiceDisabled, placeholderRenderer, role, style, scrollMode, ...rest} = this.props,
1222
- {cc, isPrimaryDirectionVertical, primary} = this,
1223
- scrollModeNative = scrollMode === 'native',
1224
- containerClasses = classNames(
1225
- css.virtualList,
1226
- isPrimaryDirectionVertical ? css.vertical : css.horizontal,
1227
- {[css.native]: scrollModeNative},
1228
- className
1229
- ),
1230
- contentClasses = scrollModeNative ? null : css.content;
1231
-
1232
- delete rest.cbScrollTo;
1233
- delete rest.childProps;
1234
- delete rest.clientSize;
1235
- delete rest.dataSize;
1236
- delete rest.direction;
1237
- delete rest.getAffordance;
1238
- delete rest.getComponentProps;
1239
- delete rest.isHorizontalScrollbarVisible;
1240
- delete rest.isVerticalScrollbarVisible;
1241
- delete rest.itemRefs;
1242
- delete rest.itemRenderer;
1243
- delete rest.itemSize;
1244
- delete rest.itemSizes;
1245
- delete rest.onUpdate;
1246
- delete rest.onUpdateItems;
1247
- delete rest.overhang;
1248
- delete rest.pageScroll;
1249
- delete rest.rtl;
1250
- delete rest.scrollContainerContainsDangerously;
1251
- delete rest.scrollContentRef;
1252
- delete rest.scrollMode;
1253
- delete rest.setThemeScrollContentHandle;
1254
- delete rest.spacing;
1255
- delete rest.updateStatesAndBounds;
1256
-
1257
- if (primary) {
1258
- this.positionItems();
1259
- }
1260
-
1261
- return (
1262
- <div className={containerClasses} data-webos-voice-focused={voiceFocused} data-webos-voice-group-label={voiceGroupLabel} data-webos-voice-disabled={voiceDisabled} ref={this.props.scrollContentRef} style={style}>
1263
- <div {...rest} className={contentClasses} ref={this.contentRef} role={role}>
1264
- {[...cc, placeholderRenderer && placeholderRenderer(primary)]}
1265
- </div>
1266
- </div>
1267
- );
1268
- }
1269
- }
1270
-
1271
- export default VirtualListBasic;
1272
- export {
1273
- gridListItemSizeShape,
1274
- itemSizesShape,
1275
- VirtualListBasic
118
+
119
+
120
+ exports.itemSizesShape = itemSizesShape;
121
+
122
+ var VirtualListBasic = /*#__PURE__*/function (_Component) {
123
+ _inherits(VirtualListBasic, _Component);
124
+
125
+ var _super = _createSuper(VirtualListBasic);
126
+
127
+ function VirtualListBasic(_props) {
128
+ var _this;
129
+
130
+ _classCallCheck(this, VirtualListBasic);
131
+
132
+ var nextState = null;
133
+ _this = _super.call(this, _props);
134
+ _this.displayName = 'ui:VirtualListBasic';
135
+ _this.scrollBounds = {
136
+ clientWidth: 0,
137
+ clientHeight: 0,
138
+ scrollWidth: 0,
139
+ scrollHeight: 0,
140
+ maxLeft: 0,
141
+ maxTop: 0
142
+ };
143
+ _this.moreInfo = {
144
+ firstVisibleIndex: null,
145
+ lastVisibleIndex: null
146
+ };
147
+ _this.primary = null;
148
+ _this.secondary = null;
149
+ _this.isPrimaryDirectionVertical = true;
150
+ _this.isItemSized = false;
151
+ _this.shouldUpdateBounds = false;
152
+ _this.dimensionToExtent = 0;
153
+ _this.threshold = 0;
154
+ _this.maxFirstIndex = 0;
155
+ _this.curDataSize = 0;
156
+ _this.hasDataSizeChanged = false;
157
+ _this.cc = [];
158
+ _this.scrollPosition = 0;
159
+ _this.scrollPositionTarget = 0;
160
+ _this.scrollToPositionTarget = -1;
161
+ _this.itemPositions = [];
162
+ _this.indexToScrollIntoView = -1;
163
+
164
+ _this.updateScrollPosition = function (_ref) {
165
+ var x = _ref.x,
166
+ y = _ref.y;
167
+ var rtl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _this.props.rtl;
168
+
169
+ if (_this.props.scrollMode === 'native') {
170
+ _this.scrollToPosition(x, y, rtl);
171
+ } else {
172
+ _this.setScrollPositionTarget(x, y);
173
+
174
+ _this.setScrollPosition(x, y, rtl);
175
+ }
176
+ };
177
+
178
+ _this.isVertical = function () {
179
+ return _this.isPrimaryDirectionVertical;
180
+ };
181
+
182
+ _this.isHorizontal = function () {
183
+ return !_this.isPrimaryDirectionVertical;
184
+ };
185
+
186
+ _this.getScrollBounds = function () {
187
+ return _this.scrollBounds;
188
+ };
189
+
190
+ _this.getMoreInfo = function () {
191
+ return _this.moreInfo;
192
+ };
193
+
194
+ _this.getItemBottomPosition = function (index) {
195
+ var itemPosition = _this.itemPositions[index],
196
+ itemSize = _this.props.itemSizes[index];
197
+
198
+ if (itemPosition && (itemSize || itemSize === 0)) {
199
+ return itemPosition.position + itemSize;
200
+ } else {
201
+ return index * _this.primary.gridSize - _this.props.spacing;
202
+ }
203
+ };
204
+
205
+ _this.getItemTopPositionFromPreviousItemBottomPosition = function (index, spacing) {
206
+ return index === 0 ? 0 : _this.getItemBottomPosition(index - 1) + spacing;
207
+ };
208
+
209
+ _this.getItemPosition = function (index) {
210
+ var stickTo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'start';
211
+ var optionalOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
212
+
213
+ var _assertThisInitialize = _assertThisInitialized(_this),
214
+ isPrimaryDirectionVertical = _assertThisInitialize.isPrimaryDirectionVertical,
215
+ primary = _assertThisInitialize.primary,
216
+ scrollBounds = _assertThisInitialize.scrollBounds;
217
+
218
+ var maxPos = isPrimaryDirectionVertical ? scrollBounds.maxTop : scrollBounds.maxLeft;
219
+
220
+ var position = _this.getGridPosition(index);
221
+
222
+ var offset = 0;
223
+
224
+ if (stickTo === 'start') {
225
+ offset = optionalOffset;
226
+ } else if (_this.props.itemSizes) {
227
+ offset = primary.clientSize - _this.props.itemSizes[index] - optionalOffset;
228
+ } else {
229
+ offset = primary.clientSize - primary.itemSize - optionalOffset;
230
+ }
231
+
232
+ position.primaryPosition = (0, _util.clamp)(0, maxPos, position.primaryPosition - offset);
233
+ return _this.gridPositionToItemPosition(position);
234
+ };
235
+
236
+ _this.gridPositionToItemPosition = function (_ref2) {
237
+ var primaryPosition = _ref2.primaryPosition,
238
+ secondaryPosition = _ref2.secondaryPosition;
239
+ return _this.isPrimaryDirectionVertical ? {
240
+ left: secondaryPosition,
241
+ top: primaryPosition
242
+ } : {
243
+ left: primaryPosition,
244
+ top: secondaryPosition
245
+ };
246
+ };
247
+
248
+ _this.getXY = function (primaryPosition, secondaryPosition) {
249
+ return _this.isPrimaryDirectionVertical ? {
250
+ x: secondaryPosition,
251
+ y: primaryPosition
252
+ } : {
253
+ x: primaryPosition,
254
+ y: secondaryPosition
255
+ };
256
+ };
257
+
258
+ _this.getClientSize = function (node) {
259
+ return {
260
+ clientWidth: node.clientWidth,
261
+ clientHeight: node.clientHeight
262
+ };
263
+ };
264
+
265
+ _this.getStatesAndUpdateBounds = function (props) {
266
+ var firstIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
267
+
268
+ var dataSize = props.dataSize,
269
+ overhang = props.overhang,
270
+ updateStatesAndBounds = props.updateStatesAndBounds,
271
+ _assertThisInitialize2 = _assertThisInitialized(_this),
272
+ dimensionToExtent = _assertThisInitialize2.dimensionToExtent,
273
+ primary = _assertThisInitialize2.primary,
274
+ moreInfo = _assertThisInitialize2.moreInfo,
275
+ scrollPosition = _assertThisInitialize2.scrollPosition,
276
+ numOfItems = Math.min(dataSize, dimensionToExtent * (Math.ceil(primary.clientSize / primary.gridSize) + overhang)),
277
+ wasFirstIndexMax = _this.maxFirstIndex < moreInfo.firstVisibleIndex - dimensionToExtent && firstIndex === _this.maxFirstIndex,
278
+ dataSizeDiff = dataSize - _this.curDataSize;
279
+
280
+ var newFirstIndex = firstIndex; // When calling setState() except in didScroll(), `shouldUpdateBounds` should be `true`
281
+ // so that setState() in didScroll() could be called to override state.
282
+ // Before calling setState() except in didScroll(), getStatesAndUpdateBounds() is always called.
283
+ // So `shouldUpdateBounds` is true here.
284
+
285
+ _this.shouldUpdateBounds = true;
286
+ _this.maxFirstIndex = Math.ceil((dataSize - numOfItems) / dimensionToExtent) * dimensionToExtent;
287
+ _this.curDataSize = dataSize; // reset children
288
+
289
+ _this.cc = [];
290
+ _this.itemPositions = []; // For individually sized item
291
+
292
+ _this.calculateScrollBounds(props);
293
+
294
+ _this.updateMoreInfo(dataSize, scrollPosition);
295
+
296
+ if (!(updateStatesAndBounds && updateStatesAndBounds({
297
+ cbScrollTo: props.cbScrollTo,
298
+ numOfItems: numOfItems,
299
+ dataSize: dataSize,
300
+ moreInfo: moreInfo
301
+ }))) {
302
+ newFirstIndex = _this.calculateFirstIndex(props, wasFirstIndexMax, dataSizeDiff, firstIndex);
303
+ }
304
+
305
+ return {
306
+ firstIndex: Math.min(newFirstIndex, _this.maxFirstIndex),
307
+ numOfItems: numOfItems
308
+ };
309
+ };
310
+
311
+ _this.setContainerSize = function () {
312
+ if (_this.contentRef.current) {
313
+ _this.contentRef.current.style.width = _this.scrollBounds.scrollWidth + (_this.isPrimaryDirectionVertical ? -1 : 0) + 'px';
314
+ _this.contentRef.current.style.height = _this.scrollBounds.scrollHeight + (_this.isPrimaryDirectionVertical ? 0 : -1) + 'px';
315
+ }
316
+ };
317
+
318
+ _this.applyStyleToNewNode = function (index) {
319
+ var _this2;
320
+
321
+ var _this$props = _this.props,
322
+ childProps = _this$props.childProps,
323
+ itemRefs = _this$props.itemRefs,
324
+ itemRenderer = _this$props.itemRenderer,
325
+ getComponentProps = _this$props.getComponentProps,
326
+ key = index % _this.state.numOfItems,
327
+ componentProps = getComponentProps && getComponentProps(index) || {},
328
+ itemContainerRef = function itemContainerRef(ref) {
329
+ if (ref === null) {
330
+ itemRefs.current[key] = ref;
331
+ } else {
332
+ var itemNode = ref.children[0];
333
+ itemRefs.current[key] = parseInt(itemNode.dataset.index) === index ? itemNode : ref.querySelector("[data-index=\"".concat(index, "\"]"));
334
+ _this.itemContainerRefs[key] = ref;
335
+ }
336
+ };
337
+
338
+ for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
339
+ rest[_key - 1] = arguments[_key];
340
+ }
341
+
342
+ _this.cc[key] = /*#__PURE__*/_react["default"].createElement("div", {
343
+ className: _VirtualListModule["default"].listItem,
344
+ key: key,
345
+ ref: itemContainerRef,
346
+ style: (_this2 = _this).composeStyle.apply(_this2, rest)
347
+ }, itemRenderer(_objectSpread(_objectSpread(_objectSpread({}, childProps), componentProps), {}, {
348
+ index: index
349
+ })));
350
+ };
351
+
352
+ _this.applyStyleToHideNode = function (index) {
353
+ var itemRefs = _this.props.itemRefs,
354
+ key = index % _this.state.numOfItems,
355
+ itemContainerRef = function itemContainerRef() {
356
+ return itemRefs.current[key] = null;
357
+ };
358
+
359
+ _this.cc[key] = /*#__PURE__*/_react["default"].createElement("div", {
360
+ key: key,
361
+ ref: itemContainerRef,
362
+ style: {
363
+ display: 'none'
364
+ }
365
+ });
366
+ };
367
+
368
+ _this.getScrollHeight = function () {
369
+ return _this.isPrimaryDirectionVertical ? _this.getVirtualScrollDimension() + _this.props.getAffordance() : _this.scrollBounds.clientHeight;
370
+ };
371
+
372
+ _this.getScrollWidth = function () {
373
+ return _this.isPrimaryDirectionVertical ? _this.scrollBounds.clientWidth : _this.getVirtualScrollDimension();
374
+ };
375
+
376
+ _this.getVirtualScrollDimension = function () {
377
+ if (_this.props.itemSizes) {
378
+ return _this.props.itemSizes.reduce(function (total, size, index) {
379
+ return total + size + (index > 0 ? _this.props.spacing : 0);
380
+ }, 0);
381
+ } else {
382
+ var _assertThisInitialize3 = _assertThisInitialized(_this),
383
+ dimensionToExtent = _assertThisInitialize3.dimensionToExtent,
384
+ primary = _assertThisInitialize3.primary,
385
+ curDataSize = _assertThisInitialize3.curDataSize,
386
+ spacing = _this.props.spacing;
387
+
388
+ return Math.ceil(curDataSize / dimensionToExtent) * primary.gridSize - spacing;
389
+ }
390
+ };
391
+
392
+ _this.syncClientSize = function () {
393
+ var _assertThisInitialize4 = _assertThisInitialized(_this),
394
+ props = _assertThisInitialize4.props,
395
+ node = _this.props.scrollContentRef.current;
396
+
397
+ if (!props.clientSize && !node) {
398
+ return false;
399
+ }
400
+
401
+ var _ref3 = props.clientSize || _this.getClientSize(node),
402
+ clientWidth = _ref3.clientWidth,
403
+ clientHeight = _ref3.clientHeight,
404
+ _assertThisInitialize5 = _assertThisInitialized(_this),
405
+ scrollBounds = _assertThisInitialize5.scrollBounds;
406
+
407
+ if (clientWidth !== scrollBounds.clientWidth || clientHeight !== scrollBounds.clientHeight) {
408
+ _this.calculateMetrics(props);
409
+
410
+ _this.setState(_this.getStatesAndUpdateBounds(props));
411
+
412
+ _this.setContainerSize();
413
+
414
+ return true;
415
+ }
416
+
417
+ return false;
418
+ };
419
+
420
+ _this.contentRef = /*#__PURE__*/_react["default"].createRef();
421
+ _this.itemContainerRefs = [];
422
+
423
+ if (_props.clientSize) {
424
+ _this.calculateMetrics(_props);
425
+
426
+ nextState = _this.getStatesAndUpdateBounds(_props);
427
+ }
428
+
429
+ _this.state = _objectSpread({
430
+ firstIndex: 0,
431
+ numOfItems: 0,
432
+ prevChildProps: null,
433
+ prevFirstIndex: 0,
434
+ updateFrom: 0,
435
+ updateTo: 0
436
+ }, nextState);
437
+ return _this;
438
+ }
439
+
440
+ _createClass(VirtualListBasic, [{
441
+ key: "componentDidMount",
442
+ // Calculate metrics for VirtualList after the 1st render to know client W/H.
443
+ value: function componentDidMount() {
444
+ if (!this.props.clientSize) {
445
+ this.calculateMetrics(this.props); // eslint-disable-next-line react/no-did-mount-set-state
446
+
447
+ this.setState(this.getStatesAndUpdateBounds(this.props));
448
+ } else {
449
+ this.emitUpdateItems();
450
+ }
451
+
452
+ if (this.props.itemSizes) {
453
+ this.adjustItemPositionWithItemSize();
454
+ } else {
455
+ this.setContainerSize();
456
+ }
457
+ }
458
+ }, {
459
+ key: "componentDidUpdate",
460
+ value: function componentDidUpdate(prevProps, prevState) {
461
+ var deferScrollTo = false;
462
+ var _this$state = this.state,
463
+ firstIndex = _this$state.firstIndex,
464
+ numOfItems = _this$state.numOfItems;
465
+ this.shouldUpdateBounds = false; // TODO: remove `this.hasDataSizeChanged` and fix useScroll
466
+
467
+ this.hasDataSizeChanged = prevProps.dataSize !== this.props.dataSize;
468
+
469
+ if (prevState.firstIndex !== firstIndex || prevState.numOfItems !== numOfItems) {
470
+ this.emitUpdateItems();
471
+ } // When an item expands or shrinks,
472
+ // we need to calculate the item position again and
473
+ // the item needs to scroll into view if the item does not show fully.
474
+
475
+
476
+ if (this.props.itemSizes) {
477
+ if (this.itemPositions.length > this.props.itemSizes.length) {
478
+ // The item with `this.props.itemSizes.length` index is not rendered yet.
479
+ // So the item could scroll into view after it rendered.
480
+ // To do it, `this.props.itemSizes.length` value is cached in `this.indexToScrollIntoView`.
481
+ this.indexToScrollIntoView = this.props.itemSizes.length;
482
+ this.itemPositions = _toConsumableArray(this.itemPositions.slice(0, this.props.itemSizes.length));
483
+ this.adjustItemPositionWithItemSize();
484
+ } else {
485
+ var indexToScrollIntoView = this.indexToScrollIntoView;
486
+ this.adjustItemPositionWithItemSize();
487
+
488
+ if (indexToScrollIntoView !== -1) {
489
+ // Currently we support expandable items in only vertical VirtualList.
490
+ // So the top and bottom of the boundaries are checked.
491
+ var scrollBounds = {
492
+ top: this.scrollPosition,
493
+ bottom: this.scrollPosition + this.scrollBounds.clientHeight
494
+ },
495
+ itemBounds = {
496
+ top: this.getGridPosition(indexToScrollIntoView).primaryPosition,
497
+ bottom: this.getItemBottomPosition(indexToScrollIntoView)
498
+ };
499
+
500
+ if (itemBounds.top < scrollBounds.top) {
501
+ this.props.cbScrollTo({
502
+ index: indexToScrollIntoView,
503
+ stickTo: 'start',
504
+ animate: true
505
+ });
506
+ } else if (itemBounds.bottom > scrollBounds.bottom) {
507
+ this.props.cbScrollTo({
508
+ index: indexToScrollIntoView,
509
+ stickTo: 'end',
510
+ animate: true
511
+ });
512
+ }
513
+ }
514
+
515
+ this.indexToScrollIntoView = -1;
516
+ }
517
+ }
518
+
519
+ if (prevProps.direction !== this.props.direction || prevProps.overhang !== this.props.overhang || prevProps.spacing !== this.props.spacing || !(0, _equals["default"])(prevProps.itemSize, this.props.itemSize)) {
520
+ var _this$getXY = this.getXY(this.scrollPosition, 0),
521
+ x = _this$getXY.x,
522
+ y = _this$getXY.y;
523
+
524
+ this.calculateMetrics(this.props); // eslint-disable-next-line react/no-did-update-set-state
525
+
526
+ this.setState(this.getStatesAndUpdateBounds(this.props));
527
+ this.setContainerSize();
528
+ var _this$scrollBounds = this.scrollBounds,
529
+ clientHeight = _this$scrollBounds.clientHeight,
530
+ clientWidth = _this$scrollBounds.clientWidth,
531
+ scrollHeight = _this$scrollBounds.scrollHeight,
532
+ scrollWidth = _this$scrollBounds.scrollWidth;
533
+ var xMax = scrollWidth - clientWidth;
534
+ var yMax = scrollHeight - clientHeight;
535
+ this.updateScrollPosition({
536
+ x: xMax > x ? x : xMax,
537
+ y: yMax > y ? y : yMax
538
+ });
539
+ deferScrollTo = true;
540
+ } else if (this.hasDataSizeChanged) {
541
+ var newState = this.getStatesAndUpdateBounds(this.props, this.state.firstIndex); // eslint-disable-next-line react/no-did-update-set-state
542
+
543
+ this.setState(newState);
544
+ this.setContainerSize();
545
+ deferScrollTo = true;
546
+ } else if (prevProps.rtl !== this.props.rtl) {
547
+ this.updateScrollPosition(this.getXY(this.scrollPosition, 0));
548
+ }
549
+
550
+ var maxPos = this.isPrimaryDirectionVertical ? this.scrollBounds.maxTop : this.scrollBounds.maxLeft;
551
+ var currentPos = this.scrollPosition;
552
+
553
+ if (this.props.scrollMode === 'native' && this.scrollToPositionTarget >= 0) {
554
+ currentPos = this.scrollToPositionTarget;
555
+ }
556
+
557
+ if (!deferScrollTo && currentPos > maxPos) {
558
+ this.props.cbScrollTo({
559
+ position: this.isPrimaryDirectionVertical ? {
560
+ y: maxPos
561
+ } : {
562
+ x: maxPos
563
+ },
564
+ animate: false
565
+ });
566
+ this.scrollToPositionTarget = -1;
567
+ }
568
+ }
569
+ }, {
570
+ key: "getGridPosition",
571
+ value: function getGridPosition(index) {
572
+ var _this$props2 = this.props,
573
+ dataSize = _this$props2.dataSize,
574
+ itemSizes = _this$props2.itemSizes,
575
+ dimensionToExtent = this.dimensionToExtent,
576
+ itemPositions = this.itemPositions,
577
+ primary = this.primary,
578
+ secondary = this.secondary,
579
+ secondaryPosition = index % dimensionToExtent * secondary.gridSize,
580
+ extent = Math.floor(index / dimensionToExtent);
581
+ var primaryPosition;
582
+
583
+ if (itemSizes && typeof itemSizes[index] !== 'undefined' && dataSize > index) {
584
+ var firstIndexInExtent = extent * dimensionToExtent;
585
+
586
+ if (!itemPositions[firstIndexInExtent]) {
587
+ // Cache individually sized item positions
588
+ for (var i = itemPositions.length; i <= index; i++) {
589
+ this.calculateAndCacheItemPosition(i);
590
+ }
591
+ }
592
+
593
+ if (itemPositions[firstIndexInExtent]) {
594
+ primaryPosition = itemPositions[firstIndexInExtent].position;
595
+ } else {
596
+ primaryPosition = extent * primary.gridSize;
597
+ }
598
+ } else {
599
+ primaryPosition = extent * primary.gridSize;
600
+ }
601
+
602
+ return {
603
+ primaryPosition: primaryPosition,
604
+ secondaryPosition: secondaryPosition
605
+ };
606
+ } // For individually sized item
607
+
608
+ }, {
609
+ key: "emitUpdateItems",
610
+ value: function emitUpdateItems() {
611
+ var dataSize = this.props.dataSize;
612
+ var _this$state2 = this.state,
613
+ firstIndex = _this$state2.firstIndex,
614
+ numOfItems = _this$state2.numOfItems;
615
+ (0, _handle.forward)('onUpdateItems', {
616
+ firstIndex: firstIndex,
617
+ lastIndex: Math.min(firstIndex + numOfItems, dataSize)
618
+ }, this.props);
619
+ }
620
+ }, {
621
+ key: "calculateMetrics",
622
+ value: function calculateMetrics(props) {
623
+ var clientSize = props.clientSize,
624
+ direction = props.direction,
625
+ itemSize = props.itemSize,
626
+ overhang = props.overhang,
627
+ scrollMode = props.scrollMode,
628
+ spacing = props.spacing,
629
+ node = this.props.scrollContentRef.current;
630
+
631
+ if (!clientSize && !node) {
632
+ return;
633
+ }
634
+
635
+ var _ref4 = clientSize || this.getClientSize(node),
636
+ clientWidth = _ref4.clientWidth,
637
+ clientHeight = _ref4.clientHeight,
638
+ heightInfo = {
639
+ clientSize: clientHeight,
640
+ minItemSize: itemSize.minHeight || null,
641
+ itemSize: itemSize
642
+ },
643
+ widthInfo = {
644
+ clientSize: clientWidth,
645
+ minItemSize: itemSize.minWidth || null,
646
+ itemSize: itemSize
647
+ };
648
+
649
+ var primary, secondary, dimensionToExtent, thresholdBase;
650
+ this.isPrimaryDirectionVertical = direction === 'vertical';
651
+
652
+ if (this.isPrimaryDirectionVertical) {
653
+ primary = heightInfo;
654
+ secondary = widthInfo;
655
+ } else {
656
+ primary = widthInfo;
657
+ secondary = heightInfo;
658
+ }
659
+
660
+ dimensionToExtent = 1;
661
+ this.isItemSized = primary.minItemSize && secondary.minItemSize;
662
+
663
+ if (this.isItemSized) {
664
+ // the number of columns is the ratio of the available width plus the spacing
665
+ // by the minimum item width plus the spacing
666
+ dimensionToExtent = Math.max(Math.floor((secondary.clientSize + spacing) / (secondary.minItemSize + spacing)), 1); // the actual item width is a ratio of the remaining width after all columns
667
+ // and spacing are accounted for and the number of columns that we know we should have
668
+
669
+ secondary.itemSize = Math.floor((secondary.clientSize - spacing * (dimensionToExtent - 1)) / dimensionToExtent); // the actual item height is related to the item width
670
+
671
+ primary.itemSize = Math.floor(primary.minItemSize * (secondary.itemSize / secondary.minItemSize));
672
+ }
673
+
674
+ primary.gridSize = primary.itemSize + spacing;
675
+ secondary.gridSize = secondary.itemSize + spacing;
676
+ thresholdBase = primary.gridSize * Math.ceil(overhang / 2);
677
+ this.threshold = {
678
+ min: -Infinity,
679
+ max: thresholdBase,
680
+ base: thresholdBase
681
+ };
682
+ this.dimensionToExtent = dimensionToExtent;
683
+ this.primary = primary;
684
+ this.secondary = secondary; // reset
685
+
686
+ this.scrollPosition = 0;
687
+ this.scrollToPositionTarget = -1;
688
+
689
+ if (scrollMode === 'translate' && this.contentRef.current) {
690
+ this.contentRef.current.style.transform = null;
691
+ } else if (scrollMode === 'native' && node) {
692
+ node.style.scrollBehavior = null;
693
+ this.updateScrollPosition(this.getXY(this.scrollPosition, 0));
694
+ node.style.scrollBehavior = 'smooth';
695
+ }
696
+ }
697
+ }, {
698
+ key: "calculateFirstIndex",
699
+ value: function calculateFirstIndex(props, wasFirstIndexMax, dataSizeDiff, firstIndex) {
700
+ var overhang = props.overhang,
701
+ dimensionToExtent = this.dimensionToExtent,
702
+ isPrimaryDirectionVertical = this.isPrimaryDirectionVertical,
703
+ maxFirstIndex = this.maxFirstIndex,
704
+ primary = this.primary,
705
+ scrollBounds = this.scrollBounds,
706
+ scrollPosition = this.scrollPosition,
707
+ threshold = this.threshold,
708
+ gridSize = primary.gridSize;
709
+ var newFirstIndex = firstIndex;
710
+
711
+ if (wasFirstIndexMax && dataSizeDiff > 0) {
712
+ // If dataSize increased from bottom, we need adjust firstIndex
713
+ // If this is a gridlist and dataSizeDiff is smaller than 1 line, we are adjusting firstIndex without threshold change.
714
+ if (dimensionToExtent > 1 && dataSizeDiff < dimensionToExtent) {
715
+ newFirstIndex = maxFirstIndex;
716
+ } else {
717
+ // For other bottom adding case, we need to update firstIndex and threshold.
718
+ var maxPos = isPrimaryDirectionVertical ? scrollBounds.maxTop : scrollBounds.maxLeft,
719
+ maxOfMin = maxPos - threshold.base,
720
+ numOfUpperLine = Math.floor(overhang / 2),
721
+ firstIndexFromPosition = Math.floor(scrollPosition / gridSize),
722
+ expectedFirstIndex = Math.max(0, firstIndexFromPosition - numOfUpperLine); // To navigate with 5way, we need to adjust firstIndex to the next line
723
+ // since at the bottom we have num of overhang lines for upper side but none for bottom side
724
+ // So we add numOfUpperLine at the top and rest lines at the bottom
725
+
726
+ newFirstIndex = Math.min(maxFirstIndex, expectedFirstIndex * dimensionToExtent); // We need to update threshold also since we moved the firstIndex
727
+
728
+ threshold.max = Math.min(maxPos, threshold.max + gridSize);
729
+ threshold.min = Math.min(maxOfMin, threshold.max - gridSize);
730
+ }
731
+ } else {
732
+ // Other cases, we can keep the min value between firstIndex and maxFirstIndex. No need to change threshold
733
+ newFirstIndex = Math.min(firstIndex, maxFirstIndex);
734
+ }
735
+
736
+ return newFirstIndex;
737
+ }
738
+ }, {
739
+ key: "calculateScrollBounds",
740
+ value: function calculateScrollBounds(props) {
741
+ var clientSize = props.clientSize,
742
+ node = this.props.scrollContentRef.current;
743
+
744
+ if (!clientSize && !node) {
745
+ return;
746
+ }
747
+
748
+ var scrollBounds = this.scrollBounds,
749
+ isPrimaryDirectionVertical = this.isPrimaryDirectionVertical,
750
+ _ref5 = clientSize || this.getClientSize(node),
751
+ clientWidth = _ref5.clientWidth,
752
+ clientHeight = _ref5.clientHeight;
753
+
754
+ var maxPos;
755
+ scrollBounds.clientWidth = clientWidth;
756
+ scrollBounds.clientHeight = clientHeight;
757
+ scrollBounds.scrollWidth = this.getScrollWidth();
758
+ scrollBounds.scrollHeight = this.getScrollHeight();
759
+ scrollBounds.maxLeft = Math.max(0, scrollBounds.scrollWidth - clientWidth);
760
+ scrollBounds.maxTop = Math.max(0, scrollBounds.scrollHeight - clientHeight); // correct position
761
+
762
+ maxPos = isPrimaryDirectionVertical ? scrollBounds.maxTop : scrollBounds.maxLeft;
763
+ this.syncThreshold(maxPos);
764
+ }
765
+ }, {
766
+ key: "updateMoreInfo",
767
+ value: function updateMoreInfo(dataSize, primaryPosition) {
768
+ var dimensionToExtent = this.dimensionToExtent,
769
+ moreInfo = this.moreInfo,
770
+ _this$primary = this.primary,
771
+ itemSize = _this$primary.itemSize,
772
+ gridSize = _this$primary.gridSize,
773
+ clientSize = _this$primary.clientSize;
774
+
775
+ if (dataSize <= 0) {
776
+ moreInfo.firstVisibleIndex = null;
777
+ moreInfo.lastVisibleIndex = null;
778
+ } else if (this.props.itemSizes) {
779
+ var _this$state3 = this.state,
780
+ firstIndex = _this$state3.firstIndex,
781
+ numOfItems = _this$state3.numOfItems;
782
+ var isPrimaryDirectionVertical = this.isPrimaryDirectionVertical,
783
+ _this$scrollBounds2 = this.scrollBounds,
784
+ clientWidth = _this$scrollBounds2.clientWidth,
785
+ clientHeight = _this$scrollBounds2.clientHeight,
786
+ scrollPosition = this.scrollPosition;
787
+ var size = isPrimaryDirectionVertical ? clientHeight : clientWidth;
788
+ var firstVisibleIndex = null,
789
+ lastVisibleIndex = null;
790
+
791
+ for (var i = firstIndex; i < firstIndex + numOfItems; i++) {
792
+ if (scrollPosition <= this.getItemBottomPosition(i)) {
793
+ firstVisibleIndex = i;
794
+ break;
795
+ }
796
+ }
797
+
798
+ for (var _i = firstIndex + numOfItems - 1; _i >= firstIndex; _i--) {
799
+ if (scrollPosition + size >= this.getItemBottomPosition(_i) - this.props.itemSizes[_i]) {
800
+ lastVisibleIndex = _i;
801
+ break;
802
+ }
803
+ }
804
+
805
+ if (firstVisibleIndex > lastVisibleIndex) {
806
+ firstVisibleIndex = null;
807
+ lastVisibleIndex = null;
808
+ }
809
+
810
+ moreInfo.firstVisibleIndex = firstVisibleIndex;
811
+ moreInfo.lastVisibleIndex = lastVisibleIndex;
812
+ } else {
813
+ moreInfo.firstVisibleIndex = (Math.floor((primaryPosition - itemSize) / gridSize) + 1) * dimensionToExtent;
814
+ moreInfo.lastVisibleIndex = Math.min(dataSize - 1, Math.ceil((primaryPosition + clientSize) / gridSize) * dimensionToExtent - 1);
815
+ }
816
+ }
817
+ }, {
818
+ key: "syncThreshold",
819
+ value: function syncThreshold(maxPos) {
820
+ var threshold = this.threshold;
821
+
822
+ if (threshold.max > maxPos) {
823
+ if (maxPos < threshold.base) {
824
+ threshold.max = threshold.base;
825
+ threshold.min = -Infinity;
826
+ } else {
827
+ threshold.max = maxPos;
828
+ threshold.min = maxPos - threshold.base;
829
+ }
830
+ }
831
+ } // scrollMode 'native' only
832
+
833
+ }, {
834
+ key: "scrollToPosition",
835
+ value: function scrollToPosition(x, y) {
836
+ var rtl = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.props.rtl;
837
+
838
+ if (this.props.scrollContentRef.current && this.props.scrollContentRef.current.scrollTo) {
839
+ if (rtl) {
840
+ x = _platform.platform.ios || _platform.platform.safari ? -x : this.scrollBounds.maxLeft - x;
841
+ }
842
+
843
+ this.props.scrollContentRef.current.scrollTo(x, y);
844
+ }
845
+ } // scrollMode 'native' only
846
+
847
+ }, {
848
+ key: "setScrollToPositionTarget",
849
+ value: function setScrollToPositionTarget(x, y) {
850
+ if (this.isPrimaryDirectionVertical) {
851
+ this.scrollToPositionTarget = y;
852
+ } else {
853
+ this.scrollToPositionTarget = x;
854
+ }
855
+ } // scrollMode 'translate' only
856
+
857
+ }, {
858
+ key: "setScrollPositionTarget",
859
+ value: function setScrollPositionTarget(x, y) {
860
+ // The `x`, `y` as parameters in scrollToPosition() are the position when stopping scrolling.
861
+ // But the `x`, `y` as parameters in setScrollPosition() are the position between current position and the position stopping scrolling.
862
+ // To know the position when stopping scrolling properly, `x` and `y` are passed and cached in `this.scrollPositionTarget`.
863
+ if (this.isPrimaryDirectionVertical) {
864
+ this.scrollPositionTarget = y;
865
+ } else {
866
+ this.scrollPositionTarget = x;
867
+ }
868
+ } // scrollMode 'translate' only
869
+
870
+ }, {
871
+ key: "setScrollPosition",
872
+ value: function setScrollPosition(x, y) {
873
+ var rtl = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.props.rtl;
874
+
875
+ if (this.contentRef.current) {
876
+ this.contentRef.current.style.transform = "translate3d(".concat(rtl ? x : -x, "px, -").concat(y, "px, 0)");
877
+ this.didScroll(x, y);
878
+ }
879
+ }
880
+ }, {
881
+ key: "didScroll",
882
+ value: function didScroll(x, y) {
883
+ var _this$props3 = this.props,
884
+ dataSize = _this$props3.dataSize,
885
+ spacing = _this$props3.spacing,
886
+ itemSizes = _this$props3.itemSizes,
887
+ firstIndex = this.state.firstIndex,
888
+ isPrimaryDirectionVertical = this.isPrimaryDirectionVertical,
889
+ threshold = this.threshold,
890
+ dimensionToExtent = this.dimensionToExtent,
891
+ maxFirstIndex = this.maxFirstIndex,
892
+ scrollBounds = this.scrollBounds,
893
+ itemPositions = this.itemPositions,
894
+ _this$primary2 = this.primary,
895
+ clientSize = _this$primary2.clientSize,
896
+ gridSize = _this$primary2.gridSize,
897
+ maxPos = isPrimaryDirectionVertical ? scrollBounds.maxTop : scrollBounds.maxLeft;
898
+ var newFirstIndex = firstIndex,
899
+ index,
900
+ pos,
901
+ size,
902
+ itemPosition;
903
+
904
+ if (isPrimaryDirectionVertical) {
905
+ pos = y;
906
+ } else {
907
+ pos = x;
908
+ }
909
+
910
+ if (pos > threshold.max || pos < threshold.min) {
911
+ var newThresholdMin = -Infinity,
912
+ newThresholdMax = Infinity;
913
+
914
+ if (this.props.itemSizes) {
915
+ var overhangBefore = Math.floor(this.props.overhang / 2);
916
+ var firstRenderedIndex = -1; // find an item which is known as placed the first rendered item's position
917
+
918
+ for (index = 0; index < dataSize; index += dimensionToExtent) {
919
+ itemPosition = itemPositions[index];
920
+ size = itemSizes[index];
921
+
922
+ if (itemPosition && size && itemPosition.position + size >= pos && itemPosition.position <= pos + clientSize) {
923
+ firstRenderedIndex = index;
924
+ break;
925
+ }
926
+ } // found an item which is visible within a current viewport
927
+
928
+
929
+ if (index < dataSize) {
930
+ if (itemPosition.position <= pos) {
931
+ newFirstIndex = firstRenderedIndex - overhangBefore * dimensionToExtent;
932
+ newThresholdMin = itemPosition.position;
933
+ newThresholdMax = newThresholdMin + size + spacing;
934
+ } else {
935
+ var diffToFirstIndex = Math.ceil((itemPosition.position - pos) / gridSize);
936
+ newFirstIndex = firstRenderedIndex - (diffToFirstIndex + overhangBefore) * dimensionToExtent;
937
+ newThresholdMin = itemPosition.position - diffToFirstIndex * gridSize;
938
+ newThresholdMax = newThresholdMin + gridSize;
939
+ }
940
+ } else {
941
+ // calculate the first index based on assuming that all items have minimal size
942
+ var firstExtent = Math.max(0, Math.min(Math.floor(maxFirstIndex / dimensionToExtent), Math.floor((pos - gridSize * overhangBefore) / gridSize)));
943
+ newFirstIndex = firstExtent * dimensionToExtent;
944
+ newThresholdMin = (firstExtent + overhangBefore) * gridSize;
945
+ newThresholdMax = newThresholdMin + gridSize;
946
+ }
947
+
948
+ newFirstIndex = Math.max(0, Math.min(maxFirstIndex, newFirstIndex));
949
+ } else {
950
+ var _overhangBefore = Math.floor(this.props.overhang / 2),
951
+ _firstExtent = Math.max(0, Math.min(Math.floor(maxFirstIndex / dimensionToExtent), Math.floor((pos - gridSize * _overhangBefore) / gridSize)));
952
+
953
+ newFirstIndex = _firstExtent * dimensionToExtent;
954
+ newThresholdMin = (_firstExtent + _overhangBefore) * gridSize;
955
+ newThresholdMax = newThresholdMin + gridSize;
956
+ }
957
+
958
+ threshold.min = newFirstIndex === 0 ? -Infinity : newThresholdMin;
959
+ threshold.max = newFirstIndex === maxFirstIndex ? Infinity : newThresholdMax;
960
+ }
961
+
962
+ this.syncThreshold(maxPos);
963
+ this.scrollPosition = pos;
964
+ this.updateMoreInfo(dataSize, pos);
965
+
966
+ if (this.shouldUpdateBounds || firstIndex !== newFirstIndex) {
967
+ this.setState({
968
+ firstIndex: newFirstIndex
969
+ });
970
+ }
971
+ } // For individually sized item
972
+
973
+ }, {
974
+ key: "calculateAndCacheItemPosition",
975
+ value: function calculateAndCacheItemPosition(index) {
976
+ var itemSizes = this.props.itemSizes;
977
+
978
+ if (!this.itemPositions[index] && itemSizes[index]) {
979
+ var spacing = this.props.spacing,
980
+ position = this.getItemTopPositionFromPreviousItemBottomPosition(index, spacing);
981
+ this.itemPositions[index] = {
982
+ position: position
983
+ };
984
+ }
985
+ } // For individually sized item
986
+
987
+ }, {
988
+ key: "applyItemPositionToDOMElement",
989
+ value: function applyItemPositionToDOMElement(index) {
990
+ var _this$props4 = this.props,
991
+ direction = _this$props4.direction,
992
+ rtl = _this$props4.rtl,
993
+ numOfItems = this.state.numOfItems,
994
+ itemPositions = this.itemPositions,
995
+ childNode = this.itemContainerRefs[index % numOfItems];
996
+
997
+ if (childNode && itemPositions[index]) {
998
+ var position = itemPositions[index].position;
999
+
1000
+ if (direction === 'vertical') {
1001
+ childNode.style.transform = "translate3d(0, ".concat(position, "px, 0)");
1002
+ } else {
1003
+ childNode.style.transform = "translate3d(".concat(position * (rtl ? -1 : 1), "px, 0, 0)");
1004
+ }
1005
+ }
1006
+ } // For individually sized item
1007
+
1008
+ }, {
1009
+ key: "updateThresholdWithItemPosition",
1010
+ value: function updateThresholdWithItemPosition() {
1011
+ var overhang = this.props.overhang,
1012
+ firstIndex = this.state.firstIndex,
1013
+ maxFirstIndex = this.maxFirstIndex,
1014
+ numOfUpperLine = Math.floor(overhang / 2);
1015
+ this.threshold.min = firstIndex === 0 ? -Infinity : this.getItemBottomPosition(firstIndex + numOfUpperLine);
1016
+ this.threshold.max = firstIndex === maxFirstIndex ? Infinity : this.getItemBottomPosition(firstIndex + (numOfUpperLine + 1));
1017
+ } // For individually sized item
1018
+
1019
+ }, {
1020
+ key: "updateScrollBoundsWithItemPositions",
1021
+ value: function updateScrollBoundsWithItemPositions() {
1022
+ var _this$props5 = this.props,
1023
+ dataSize = _this$props5.dataSize,
1024
+ itemSizes = _this$props5.itemSizes,
1025
+ spacing = _this$props5.spacing,
1026
+ _this$state4 = this.state,
1027
+ firstIndex = _this$state4.firstIndex,
1028
+ numOfItems = _this$state4.numOfItems,
1029
+ isPrimaryDirectionVertical = this.isPrimaryDirectionVertical,
1030
+ itemPositions = this.itemPositions,
1031
+ scrollBoundsDimension = isPrimaryDirectionVertical ? 'scrollHeight' : 'scrollWidth';
1032
+
1033
+ if (itemPositions.length === dataSize) {
1034
+ // all item sizes are known
1035
+ this.scrollBounds[scrollBoundsDimension] = itemSizes.reduce(function (acc, cur) {
1036
+ return acc + cur;
1037
+ }, 0) + (dataSize - 1) * spacing;
1038
+ } else {
1039
+ for (var index = firstIndex + numOfItems - 1; index < dataSize; index++) {
1040
+ var nextInfo = itemPositions[index + 1];
1041
+
1042
+ if (!nextInfo) {
1043
+ var endPosition = this.getItemBottomPosition(index);
1044
+
1045
+ if (endPosition > this.scrollBounds[scrollBoundsDimension]) {
1046
+ this.scrollBounds[scrollBoundsDimension] = endPosition;
1047
+ }
1048
+
1049
+ break;
1050
+ }
1051
+ }
1052
+ }
1053
+
1054
+ this.scrollBounds.maxTop = Math.max(0, this.scrollBounds.scrollHeight - this.scrollBounds.clientHeight);
1055
+ } // For individually sized item
1056
+
1057
+ }, {
1058
+ key: "adjustItemPositionWithItemSize",
1059
+ value: function adjustItemPositionWithItemSize() {
1060
+ if (this.cc.length) {
1061
+ var dataSize = this.props.dataSize,
1062
+ _this$state5 = this.state,
1063
+ firstIndex = _this$state5.firstIndex,
1064
+ numOfItems = _this$state5.numOfItems,
1065
+ lastIndex = firstIndex + numOfItems - 1; // Cache individually sized item positions
1066
+ // and adjust item DOM element positions
1067
+
1068
+ for (var index = firstIndex; index <= lastIndex; index++) {
1069
+ this.calculateAndCacheItemPosition(index);
1070
+ this.applyItemPositionToDOMElement(index);
1071
+ } // Update threshold based on this.itemPositions
1072
+
1073
+
1074
+ this.updateThresholdWithItemPosition(); // Update scroll bounds based on this.itemPositions
1075
+
1076
+ this.updateScrollBoundsWithItemPositions(); // Set container size based on this.scrollbounds
1077
+
1078
+ this.setContainerSize(); // Update moreInfo based on this.itemPositions
1079
+
1080
+ this.updateMoreInfo(dataSize, this.scrollPosition);
1081
+ }
1082
+ }
1083
+ }, {
1084
+ key: "composeStyle",
1085
+ value: function composeStyle(width, height, primaryPosition, secondaryPosition) {
1086
+ var _this$getXY2 = this.getXY(primaryPosition, secondaryPosition),
1087
+ x = _this$getXY2.x,
1088
+ y = _this$getXY2.y,
1089
+ style = {
1090
+ /* FIXME: RTL / this calculation only works for Chrome */
1091
+ transform: "translate3d(".concat(this.props.rtl ? -x : x, "px, ").concat(y, "px, 0)")
1092
+ };
1093
+
1094
+ if (this.isItemSized) {
1095
+ style.width = width;
1096
+ style.height = height;
1097
+ }
1098
+
1099
+ return style;
1100
+ }
1101
+ }, {
1102
+ key: "positionItems",
1103
+ value: function positionItems() {
1104
+ var _this$props6 = this.props,
1105
+ dataSize = _this$props6.dataSize,
1106
+ itemSizes = _this$props6.itemSizes,
1107
+ _this$state6 = this.state,
1108
+ firstIndex = _this$state6.firstIndex,
1109
+ numOfItems = _this$state6.numOfItems,
1110
+ cc = this.cc,
1111
+ isPrimaryDirectionVertical = this.isPrimaryDirectionVertical,
1112
+ dimensionToExtent = this.dimensionToExtent,
1113
+ primary = this.primary,
1114
+ secondary = this.secondary,
1115
+ itemPositions = this.itemPositions;
1116
+ var hideTo = 0,
1117
+ updateFrom = cc.length ? this.state.updateFrom : firstIndex,
1118
+ updateTo = cc.length ? this.state.updateTo : firstIndex + numOfItems;
1119
+
1120
+ if (updateFrom >= updateTo) {
1121
+ return;
1122
+ } else if (updateTo > dataSize) {
1123
+ hideTo = updateTo;
1124
+ updateTo = dataSize;
1125
+ }
1126
+
1127
+ var width,
1128
+ height,
1129
+ _this$getGridPosition = this.getGridPosition(updateFrom),
1130
+ primaryPosition = _this$getGridPosition.primaryPosition,
1131
+ secondaryPosition = _this$getGridPosition.secondaryPosition;
1132
+
1133
+ width = (isPrimaryDirectionVertical ? secondary.itemSize : primary.itemSize) + 'px';
1134
+ height = (isPrimaryDirectionVertical ? primary.itemSize : secondary.itemSize) + 'px'; // positioning items
1135
+
1136
+ for (var i = updateFrom, j = updateFrom % dimensionToExtent; i < updateTo; i++) {
1137
+ this.applyStyleToNewNode(i, width, height, primaryPosition, secondaryPosition);
1138
+
1139
+ if (++j === dimensionToExtent) {
1140
+ secondaryPosition = 0;
1141
+
1142
+ if (this.props.itemSizes) {
1143
+ if (itemPositions[i + 1] || itemPositions[i + 1] === 0) {
1144
+ primaryPosition = itemPositions[i + 1].position;
1145
+ } else if (itemSizes[i]) {
1146
+ primaryPosition += itemSizes[i] + this.props.spacing;
1147
+ } else {
1148
+ primaryPosition += primary.gridSize;
1149
+ }
1150
+ } else {
1151
+ primaryPosition += primary.gridSize;
1152
+ }
1153
+
1154
+ j = 0;
1155
+ } else {
1156
+ secondaryPosition += secondary.gridSize;
1157
+ }
1158
+ }
1159
+
1160
+ for (var _i2 = updateTo; _i2 < hideTo; _i2++) {
1161
+ this.applyStyleToHideNode(_i2);
1162
+ }
1163
+ }
1164
+ }, {
1165
+ key: "render",
1166
+ // render
1167
+ value: function render() {
1168
+ var _this$props7 = this.props,
1169
+ className = _this$props7.className,
1170
+ voiceFocused = _this$props7['data-webos-voice-focused'],
1171
+ voiceGroupLabel = _this$props7['data-webos-voice-group-label'],
1172
+ voiceDisabled = _this$props7['data-webos-voice-disabled'],
1173
+ placeholderRenderer = _this$props7.placeholderRenderer,
1174
+ role = _this$props7.role,
1175
+ style = _this$props7.style,
1176
+ scrollMode = _this$props7.scrollMode,
1177
+ rest = _objectWithoutProperties(_this$props7, ["className", "data-webos-voice-focused", "data-webos-voice-group-label", "data-webos-voice-disabled", "placeholderRenderer", "role", "style", "scrollMode"]),
1178
+ cc = this.cc,
1179
+ isPrimaryDirectionVertical = this.isPrimaryDirectionVertical,
1180
+ primary = this.primary,
1181
+ scrollModeNative = scrollMode === 'native',
1182
+ containerClasses = (0, _classnames["default"])(_VirtualListModule["default"].virtualList, isPrimaryDirectionVertical ? _VirtualListModule["default"].vertical : _VirtualListModule["default"].horizontal, _defineProperty({}, _VirtualListModule["default"]["native"], scrollModeNative), className),
1183
+ contentClasses = scrollModeNative ? null : _VirtualListModule["default"].content;
1184
+
1185
+ delete rest.cbScrollTo;
1186
+ delete rest.childProps;
1187
+ delete rest.clientSize;
1188
+ delete rest.dataSize;
1189
+ delete rest.direction;
1190
+ delete rest.getAffordance;
1191
+ delete rest.getComponentProps;
1192
+ delete rest.isHorizontalScrollbarVisible;
1193
+ delete rest.isVerticalScrollbarVisible;
1194
+ delete rest.itemRefs;
1195
+ delete rest.itemRenderer;
1196
+ delete rest.itemSize;
1197
+ delete rest.itemSizes;
1198
+ delete rest.onUpdate;
1199
+ delete rest.onUpdateItems;
1200
+ delete rest.overhang;
1201
+ delete rest.pageScroll;
1202
+ delete rest.rtl;
1203
+ delete rest.scrollContainerContainsDangerously;
1204
+ delete rest.scrollContentRef;
1205
+ delete rest.scrollMode;
1206
+ delete rest.setThemeScrollContentHandle;
1207
+ delete rest.spacing;
1208
+ delete rest.updateStatesAndBounds;
1209
+
1210
+ if (primary) {
1211
+ this.positionItems();
1212
+ }
1213
+
1214
+ return /*#__PURE__*/_react["default"].createElement("div", {
1215
+ className: containerClasses,
1216
+ "data-webos-voice-focused": voiceFocused,
1217
+ "data-webos-voice-group-label": voiceGroupLabel,
1218
+ "data-webos-voice-disabled": voiceDisabled,
1219
+ ref: this.props.scrollContentRef,
1220
+ style: style
1221
+ }, /*#__PURE__*/_react["default"].createElement("div", Object.assign({}, rest, {
1222
+ className: contentClasses,
1223
+ ref: this.contentRef,
1224
+ role: role
1225
+ }), [].concat(_toConsumableArray(cc), [placeholderRenderer && placeholderRenderer(primary)])));
1226
+ }
1227
+ }], [{
1228
+ key: "getDerivedStateFromProps",
1229
+ value: function getDerivedStateFromProps(props, state) {
1230
+ var shouldInvalidate = state.prevFirstIndex === state.firstIndex || state.prevChildProps !== props.childProps,
1231
+ diff = state.firstIndex - state.prevFirstIndex,
1232
+ updateTo = -state.numOfItems >= diff || diff > 0 || shouldInvalidate ? state.firstIndex + state.numOfItems : state.prevFirstIndex,
1233
+ updateFrom = 0 >= diff || diff >= state.numOfItems || shouldInvalidate ? state.firstIndex : state.prevFirstIndex + state.numOfItems,
1234
+ nextUpdateFromAndTo = state.updateFrom !== updateFrom || state.updateTo !== updateTo ? {
1235
+ updateFrom: updateFrom,
1236
+ updateTo: updateTo
1237
+ } : null;
1238
+ return _objectSpread(_objectSpread({}, nextUpdateFromAndTo), {}, {
1239
+ prevChildProps: props.childProps,
1240
+ prevFirstIndex: state.firstIndex
1241
+ });
1242
+ }
1243
+ }]);
1244
+
1245
+ return VirtualListBasic;
1246
+ }(_react.Component);
1247
+
1248
+ exports.VirtualListBasic = VirtualListBasic;
1249
+ VirtualListBasic.propTypes =
1250
+ /** @lends ui/VirtualList.VirtualListBasic.prototype */
1251
+ {
1252
+ /**
1253
+ * The rendering function called for each item in the list.
1254
+ *
1255
+ * > **Note**: The list does **not** always render a component whenever its render function is called
1256
+ * due to performance optimization.
1257
+ *
1258
+ * Example:
1259
+ * ```
1260
+ * renderItem = ({index, ...rest}) => {
1261
+ *
1262
+ * return (
1263
+ * <MyComponent index={index} {...rest} />
1264
+ * );
1265
+ * }
1266
+ * ```
1267
+ *
1268
+ * @type {Function}
1269
+ * @param {Object} event
1270
+ * @param {Number} event.data-index It is required for `Spotlight` 5-way navigation. Pass to the root element in the component.
1271
+ * @param {Number} event.index The index number of the component to render
1272
+ *
1273
+ * @required
1274
+ * @public
1275
+ */
1276
+ itemRenderer: _propTypes2["default"].func.isRequired,
1277
+
1278
+ /**
1279
+ * The size of an item for the list; valid values are either a number for `VirtualList`
1280
+ * or an object that has `minWidth` and `minHeight` for `VirtualGridList`.
1281
+ *
1282
+ * @type {Number|ui/VirtualList.gridListItemSizeShape}
1283
+ * @required
1284
+ * @private
1285
+ */
1286
+ itemSize: _propTypes2["default"].oneOfType([_propTypes2["default"].number, gridListItemSizeShape]).isRequired,
1287
+
1288
+ /**
1289
+ * Callback method of scrollTo.
1290
+ * Normally, useScroll should set this value.
1291
+ *
1292
+ * @type {Function}
1293
+ * @private
1294
+ */
1295
+ cbScrollTo: _propTypes2["default"].func,
1296
+
1297
+ /**
1298
+ * Additional props included in the object passed to the `itemRenderer` callback.
1299
+ *
1300
+ * @type {Object}
1301
+ * @public
1302
+ */
1303
+ childProps: _propTypes2["default"].object,
1304
+
1305
+ /**
1306
+ * Client size of the list; valid values are an object that has `clientWidth` and `clientHeight`.
1307
+ *
1308
+ * @type {Object}
1309
+ * @property {Number} clientHeight The client height of the list.
1310
+ * @property {Number} clientWidth The client width of the list.
1311
+ * @public
1312
+ */
1313
+ clientSize: _propTypes2["default"].shape({
1314
+ clientHeight: _propTypes2["default"].number.isRequired,
1315
+ clientWidth: _propTypes2["default"].number.isRequired
1316
+ }),
1317
+
1318
+ /**
1319
+ * Disable voice control feature of component.
1320
+ *
1321
+ * @type {Boolean}
1322
+ * @public
1323
+ */
1324
+ 'data-webos-voice-disabled': _propTypes2["default"].bool,
1325
+
1326
+ /**
1327
+ * Activates the component for voice control.
1328
+ *
1329
+ * @type {Boolean}
1330
+ * @public
1331
+ */
1332
+ 'data-webos-voice-focused': _propTypes2["default"].bool,
1333
+
1334
+ /**
1335
+ * The voice control group label.
1336
+ *
1337
+ * @type {String}
1338
+ * @public
1339
+ */
1340
+ 'data-webos-voice-group-label': _propTypes2["default"].string,
1341
+
1342
+ /**
1343
+ * The number of items of data the list contains.
1344
+ *
1345
+ * @type {Number}
1346
+ * @default 0
1347
+ * @public
1348
+ */
1349
+ dataSize: _propTypes2["default"].number,
1350
+
1351
+ /**
1352
+ * The layout direction of the list.
1353
+ *
1354
+ * Valid values are:
1355
+ * * `'horizontal'`, and
1356
+ * * `'vertical'`.
1357
+ *
1358
+ * @type {String}
1359
+ * @default 'vertical'
1360
+ * @public
1361
+ */
1362
+ direction: _propTypes2["default"].oneOf(['horizontal', 'vertical']),
1363
+
1364
+ /**
1365
+ * Called to get the scroll affordance from themed component.
1366
+ *
1367
+ * @type {Function}
1368
+ * @private
1369
+ */
1370
+ getAffordance: _propTypes2["default"].func,
1371
+
1372
+ /**
1373
+ * Called to get the props for list items.
1374
+ *
1375
+ * @type {Function}
1376
+ * @private
1377
+ */
1378
+ getComponentProps: _propTypes2["default"].func,
1379
+
1380
+ /**
1381
+ * Ref for items
1382
+ *
1383
+ * @type {Object}
1384
+ * @private
1385
+ */
1386
+ itemRefs: _propTypes2["default"].object,
1387
+
1388
+ /**
1389
+ * The array for individually sized items.
1390
+ *
1391
+ * @type {Number[]}
1392
+ * @private
1393
+ */
1394
+ itemSizes: _propTypes2["default"].arrayOf(_propTypes2["default"].number),
1395
+
1396
+ /**
1397
+ * Called when the range of items has updated.
1398
+ *
1399
+ * Event payload includes the `firstIndex` and `lastIndex` of the list.
1400
+ *
1401
+ * @type {Function}
1402
+ * @private
1403
+ */
1404
+ onUpdateItems: _propTypes2["default"].func,
1405
+
1406
+ /**
1407
+ * Number of spare DOM node.
1408
+ * `3` is good for the default value experimentally and
1409
+ * this value is highly recommended not to be changed by developers.
1410
+ *
1411
+ * @type {Number}
1412
+ * @default 3
1413
+ * @private
1414
+ */
1415
+ overhang: _propTypes2["default"].number,
1416
+
1417
+ /**
1418
+ * When `true`, the list will scroll by page. Otherwise the list will scroll by item.
1419
+ *
1420
+ * @type {Boolean}
1421
+ * @default false
1422
+ * @private
1423
+ */
1424
+ pageScroll: _propTypes2["default"].bool,
1425
+
1426
+ /**
1427
+ * The render function for the placeholder elements.
1428
+ *
1429
+ * @type {Function}
1430
+ * @required
1431
+ * @private
1432
+ */
1433
+ placeholderRenderer: _propTypes2["default"].func,
1434
+
1435
+ /**
1436
+ * The ARIA role for the list.
1437
+ *
1438
+ * @type {String}
1439
+ * @default 'list'
1440
+ * @public
1441
+ */
1442
+ role: _propTypes2["default"].string,
1443
+
1444
+ /**
1445
+ * `true` if RTL, `false` if LTR.
1446
+ *
1447
+ * @type {Boolean}
1448
+ * @private
1449
+ */
1450
+ rtl: _propTypes2["default"].bool,
1451
+
1452
+ /**
1453
+ * Ref for scroll content
1454
+ *
1455
+ * @type {Object|Function}}
1456
+ * @private
1457
+ */
1458
+ scrollContentRef: _propTypes["default"].ref,
1459
+
1460
+ /**
1461
+ * Specifies how to scroll.
1462
+ *
1463
+ * Valid values are:
1464
+ * * `'translate'`,
1465
+ * * `'native'`.
1466
+ *
1467
+ * @type {String}
1468
+ * @default 'translate'
1469
+ * @public
1470
+ */
1471
+ scrollMode: _propTypes2["default"].string,
1472
+
1473
+ /**
1474
+ * The spacing between items.
1475
+ *
1476
+ * @type {Number}
1477
+ * @default 0
1478
+ * @public
1479
+ */
1480
+ spacing: _propTypes2["default"].number,
1481
+
1482
+ /**
1483
+ * Called to execute additional logic in a themed component when updating states and bounds.
1484
+ *
1485
+ * @type {Function}
1486
+ * @private
1487
+ */
1488
+ updateStatesAndBounds: _propTypes2["default"].func
1489
+ };
1490
+ VirtualListBasic.defaultProps = {
1491
+ cbScrollTo: nop,
1492
+ dataSize: 0,
1493
+ direction: 'vertical',
1494
+ getAffordance: function getAffordance() {
1495
+ return 0;
1496
+ },
1497
+ overhang: 3,
1498
+ pageScroll: false,
1499
+ scrollMode: 'translate',
1500
+ spacing: 0
1276
1501
  };
1502
+ var _default = VirtualListBasic;
1503
+ exports["default"] = _default;