@@ -1,45 +1,133 @@
1−module React.Virtuoso (virtuosoImpl, virtuosoWithData, virtuosoWithCount) where
1+module React.Virtuoso
5+ , ScrollSeekConfiguration
14+ , scrollerRefToHTMLElement
15+ , scrollerRefToWindow
3−import Data.Function.Uncurried (Fn2)
20+import Data.Function.Uncurried (Fn2, Fn3)
21+import Data.Maybe (Maybe(..))
4import Data.Unit (Unit)
22import Data.Unit (Unit)
5−import Effect.Uncurried (EffectFn1)
23+import Effect (Effect)
24+import Effect.Uncurried (EffectFn1, EffectFn2, EffectFn3, runEffectFn1, runEffectFn2)
6import Prim.Row (class Union)
25import Prim.Row (class Union)
7import React.Basic (JSX, ReactComponent)
26import React.Basic (JSX, ReactComponent)
27+import React.Basic.Hooks (ReactChildren)
28+import React.Basic as React
8import React.Basic.DOM (CSS)
29import React.Basic.DOM (CSS)
30+import Unsafe.Coerce (unsafeCoerce)
31+import Web.HTML (HTMLElement, Window)
10foreign import virtuosoImpl ∷ ∀ p. ReactComponent p
33foreign import virtuosoImpl ∷ ∀ p. ReactComponent p
12−type VirtuosoPropsWithTotalCount
35+foreign import data VirtuosoInstance :: Type
14− , totalCount ∷ Int
37+scrollToIndex :: { smooth :: Boolean } -> Int -> VirtuosoInstance -> Effect Unit
15− , itemContent ∷ Int → JSX
38+scrollToIndex options idx inst =
16− , useWindowScroll ∷ Boolean
39+ runEffectFn2 (unsafeCoerce inst).scrollToIndex idx options
18−
41+type VirtuosoProps ctx item =
19−type VirtuosoPropsWithData a
20− = ( style ∷ CSS
42+ ( style ∷ CSS
21− , data ∷ Array a
43+ , data ∷ Array item
22− , itemContent ∷ Fn2 Int a JSX
44+ , endReached ∷ EffectFn1 Int Unit
23− , useWindowScroll ∷ Boolean
45+ , initialTopMostItemIndex :: Int
46+ , alignToBottom :: Boolean
24− , endReached ∷ EffectFn1 Int Unit
47+ , atBottomStateChange :: EffectFn1 Boolean Unit
25− )
48+ , atBottomThreshold :: Int
26−
49+ , atTopStateChange :: EffectFn1 Boolean Unit
27−virtuosoWithCount ∷
50+ , atTopThreshold :: Int
28− ∀ p p_.
51+ , components :: Components ctx
29− Union p p_ VirtuosoPropsWithTotalCount ⇒
52+ -- , computeItemKey
30− ReactComponent
53+ , context :: ctx
31− { totalCount ∷ Int
54+ , customScrollParent :: HTMLElement
32− , itemContent ∷ Int → JSX
55+ , defaultItemHeight :: Number
33− | p
56+ , endReached :: EffectFn1 Int Unit
34− }
57+ , firstItemIndex :: Int
35−virtuosoWithCount = virtuosoImpl
58+ , fixedItemHeight :: Number
36−
59+ , followOutput :: FollowOutput
37−virtuosoWithData ∷
60+ , headerFooterTag :: String
38− ∀ item p p_.
61+ , increaseViewportBy :: { bottom :: Number, top :: Number }
39− Union p p_ (VirtuosoPropsWithData item) ⇒
62+ , initialItemCount :: Int
40− ReactComponent
63+ , initialScrollTop :: Number
41− { data ∷ Array item
64+ -- , initialTopMostItemIndex::
42− , itemContent ∷ Fn2 Int item JSX
65+ , isScrolling :: EffectFn1 Boolean Unit
43− | p
66+ , itemContent ∷ Fn3 Int item ctx JSX
44− }
67+ , itemSize ∷ EffectFn2 HTMLElement String Number
68+ , itemsRendered :: EffectFn1 (Array { data :: item }) Unit
69+ , overscan :: { main :: Number, reverse :: Number }
70+ , rangeChanged :: EffectFn1 ListRange Unit
71+ , scrollSeekConfiguration :: ScrollSeekConfiguration
72+ , scrollerRef :: EffectFn1 ScrollerRef Unit
73+ , startReached :: EffectFn1 Int Unit
74+ , topItemCount :: Int
76+ , totalListHeightChanged :: EffectFn1 Number Unit
77+ , useWindowScroll ∷ Boolean
80+foreign import data Components :: Type -> Type
82+type AllComponents ctx =
83+ ( "EmptyPlaceholder" :: ReactComponent { context :: ctx }
84+ , "Footer" :: ReactComponent { context :: ctx }
85+ , "Group" :: ReactComponent { style :: CSS, children :: ReactChildren JSX, context :: ctx }
86+ , "Header" :: ReactComponent { context :: ctx }
87+ , "Item" :: ReactComponent { context :: ctx }
90+components :: forall ctx r r_. Union r r_ (AllComponents ctx) => { | r } -> Components ctx
91+components = unsafeCoerce
93+type ScrollSeekConfiguration =
94+ { change :: EffectFn2 Number ListRange Unit
95+ , enter :: EffectFn2 Number ListRange Boolean
96+ , exit :: EffectFn2 Number ListRange Boolean
99+foreign import data ScrollerRef :: Type
100+foreign import scrollerRefToWindowImpl :: forall a. (a -> Maybe a) -> (Maybe a) -> ScrollerRef -> Effect (Maybe Window)
102+scrollerRefToWindow ∷ ScrollerRef → Effect (Maybe Window)
103+scrollerRefToWindow = scrollerRefToWindowImpl Just Nothing
105+foreign import scrollerRefToHTMLElementImpl :: forall a. (a -> Maybe a) -> (Maybe a) -> ScrollerRef -> Effect (Maybe HTMLElement)
107+scrollerRefToHTMLElement ∷ ScrollerRef → Effect (Maybe Window)
108+scrollerRefToHTMLElement = scrollerRefToWindowImpl Just Nothing
110+type ListRange = { startIndex :: Int, endIndex :: Int }
112+foreign import data FollowOutput :: Type
114+followOutputTrue :: FollowOutput
115+followOutputTrue = unsafeCoerce true
117+followOutputFalse :: FollowOutput
118+followOutputFalse = unsafeCoerce false
120+followOutputSmooth :: FollowOutput
121+followOutputSmooth = unsafeCoerce "smooth"
123+followOutputAuto :: FollowOutput
124+followOutputAuto = unsafeCoerce "auto"
128+ . Union p p_ (VirtuosoProps ctx item)
45−virtuosoWithData = virtuosoImpl
133+virtuoso = virtuosoImpl