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