virtua 0.1.4 → 0.1.6
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.
- package/lib/core/scroller.d.ts +3 -1
- package/lib/core/store.d.ts +3 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +1 -1
- package/lib/index.mjs.map +1 -1
- package/lib/react/List.d.ts +14 -14
- package/package.json +16 -16
package/lib/core/scroller.d.ts
CHANGED
|
@@ -9,7 +9,9 @@ export type Scroller = {
|
|
|
9
9
|
_initItem: (itemElement: HTMLElement, index: number) => () => void;
|
|
10
10
|
_getScrollPosition: () => number;
|
|
11
11
|
_getScrollDirection: () => ScrollDirection;
|
|
12
|
+
_getActualScrollSize: () => number;
|
|
12
13
|
_updateScrollPosition: (offset: number, diff?: boolean) => void;
|
|
14
|
+
_scrollTo: (index: number, getCurrentOffset: () => number) => void;
|
|
13
15
|
};
|
|
14
|
-
export declare const createScroller: (store: VirtualStore,
|
|
16
|
+
export declare const createScroller: (store: VirtualStore, notifyStop: () => void) => Scroller;
|
|
15
17
|
export {};
|
package/lib/core/store.d.ts
CHANGED
|
@@ -27,10 +27,12 @@ export type VirtualStore = {
|
|
|
27
27
|
_getScrollSize(): number;
|
|
28
28
|
_getItemCount(): number;
|
|
29
29
|
_getJump(): ScrollJump;
|
|
30
|
+
_isHorizontal(): boolean;
|
|
31
|
+
_isRtl(): boolean;
|
|
30
32
|
_getItemIndexForScrollTo(offset: number): number;
|
|
31
33
|
_waitForScrollDestinationItemsMeasured(): Promise<void>;
|
|
32
34
|
_subscribe(cb: () => void): () => void;
|
|
33
35
|
_update(action: Actions): void;
|
|
34
36
|
};
|
|
35
|
-
export declare const createVirtualStore: (itemCount: number, itemSize: number, isHorizontal: boolean
|
|
37
|
+
export declare const createVirtualStore: (itemCount: number, itemSize: number, isHorizontal: boolean, isRtl: boolean) => VirtualStore;
|
|
36
38
|
export {};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { List } from "./react/List";
|
|
2
|
-
export type { ListProps, ListHandle,
|
|
2
|
+
export type { ListProps, ListHandle, CustomItemComponent, CustomItemComponentProps, CustomWindowComponent, CustomWindowComponentProps, } from "./react/List";
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
var e=require("react/jsx-runtime"),t=require("react"),r=require("use-sync-external-store/shim");const n=Math.min,o=Math.max,l=Math.abs,i=(e,t)=>Array.from({length:e},((e,r)=>t(r))),s=(e,t)=>{const r=e.t[t];return-1===r?e.o:r},c=(e,t,r)=>{let l=0;if(r>=0)for(;t<e.l-1;){const n=s(e,t);if(l+=n,t++,l>=r){l-n/2>=r&&t--;break}}else for(;t>0;){t--;const n=s(e,t);if(l-=n,l<=r){l+n/2<r&&t++;break}}return n(o(t,0),e.l-1)},u=(e,t,r,n)=>c(e,r,t-n),_=c,d=(e,t)=>{if(!e.l)return 0;if(e.i>=t)return e.u[t];let r=e.u[e.i];for(let n=e.i;n<=t&&(e.u[n]=r,n!==t);n++)r+=s(e,n);return e.i=t,r},a=(e,t,r)=>{var o;return{o:t,l:e,i:null!==(o=r&&n(r.i,e-1))&&void 0!==o?o:0,t:i(e,(e=>{var t;return null!==(t=r&&r.t[e])&&void 0!==t?t:-1})),u:i(e,(e=>{var t;return 0===e?0:null!==(t=r&&r.u[e])&&void 0!==t?t:-1}))}},f="undefined"!=typeof window?t.useLayoutEffect:t.useEffect,h=(e,t)=>r.useSyncExternalStore(e,t,t),m=t.memo((({_:r,h:n,m:o,g:l,p:i})=>{const s=t.useRef(null),c=h(o.S,(()=>o.v(l))),u=h(o.S,(()=>o.I(l)));return f((()=>n.T(s.current,l)),[l]),e.jsx(i,{ref:s,style:t.useMemo((()=>{const e=o.M(),t=o.O(),r={margin:"0",padding:"0",position:"absolute",[e?"height":"width"]:"100%",[e?"top":t?"right":"left"]:0,[e?t?"right":"left":"top"]:c};return e&&(r.display="flex"),u&&(r.visibility="hidden"),r}),[c,u]),children:r})})),g=t.forwardRef((({children:r,style:n,scrollSize:o,horizontal:l,rtl:i},s)=>e.jsx("div",{ref:s,style:n,children:e.jsx("div",{style:t.useMemo((()=>{const e=l?o:"100%",t=l?"100%":o;return{position:"absolute",top:0,[i?"right":"left"]:0,width:e,height:t,minWidth:e,minHeight:t}}),[o]),children:r})}))),p=({_:r,R:n,m:o,p:l,P:i})=>{const s=h(o.S,o.k),c=h(o.S,o.q),u=s>=c?s:c,_=o.M();return e.jsx(l,{ref:n,scrollSize:u,horizontal:_,rtl:o.O(),style:t.useMemo((()=>({overflow:_?"auto hidden":"hidden auto",position:"relative",contain:"strict",width:"100%",height:"100%",padding:0,margin:0,...i})),[i]),children:r})},w=t.forwardRef((({children:r,itemSize:i=40,overscan:c=6,horizontal:w,rtl:y,endThreshold:S=0,style:v,element:I=g,itemElement:z="div",onEndReached:x},b)=>{const T=t.useMemo((()=>{const e=[];return t.Children.forEach(r,(t=>{(e=>null==e||"boolean"==typeof e)(t)||e.push(t)})),e}),[r]),M=T.length,O=t.useRef(),R=O.current||(O.current=((e,t,r,o)=>{const l=new Set,i={H:0,W:0,j:0,A:a(e,t),D:[]},c=()=>r?i.W:i.j;let f;return{F:()=>i.H,U:()=>_(i.A,i.H,c()),I:e=>-1===i.A.t[e],C:e=>((e,t,r)=>{for(let n=t;n<=r;n++)if(-1===e.t[n])return!0;return!1})(i.A,e,_(i.A,e,c())),v:e=>d(i.A,e),q:()=>c(),k:()=>(e=>{if(!e.l)return 0;const t=e.l-1;if(e.i>=t)return e.u[t]+s(e,t);let r=e.u[e.i];for(let n=e.i;n<=t;n++)e.u[n]=r,r+=s(e,n);return e.i=t,r})(i.A),J:()=>i.A.l,L:()=>i.D,M:()=>r,O:()=>o,V:e=>u(i.A,e,0,0),B:()=>(f&&f[1](),new Promise(((e,t)=>{f=[()=>{Promise.resolve().then((()=>{e(),f=void 0}))},t]}))),S:e=>(l.add(e),()=>{l.delete(e)}),G(e){((e,t,r)=>{switch(t.K){case 0:return e.A.l!==t.l&&(e.A=a(t.l,r,e.A),!0);case 1:{const r=t.N.filter((([t,r])=>e.A.t[t]!==r));if(!r.length)return!1;const o=[];return r.forEach((([t,r])=>{o.push([t,r-s(e.A,t)]),((e,t,r)=>{e.t[t]=r,e.i=n(t,e.i)})(e.A,t,r)})),e.D=o,!0}case 2:return(e.W!==t.X||e.j!==t.Y)&&(e.W=t.X,e.j=t.Y,!0);case 3:{const r=e.H,n=d(e.A,r);return n!==t.Z&&(e.H=u(e.A,t.Z,r,n))!==r}}})(i,e,t)&&(l.forEach((e=>{e()})),f&&1===e.K&&f[0]())}}})(M,i,!!w,!!y)),P=h(R.S,R.F),k=h(R.S,R.U),q=h(R.S,R.L),E=t.useRef(null),H=t.useRef(-1),[W,j]=t.useState(new Set),A=t.useRef(),D=A.current||(A.current=((e,t)=>{let r,n,o,i=-1,s=0,c=!1;const u=e.M(),_=e.O(),d=u?"scrollLeft":"scrollTop",a=new WeakMap,f=()=>o||(o=new ResizeObserver((t=>{const r=[];for(const o of t)if(o.target===n)e.G({K:2,X:o.contentRect.width,Y:o.contentRect.height});else{const e=a.get(o.target);null!=e&&r.push([e,o.contentRect[u?"width":"height"]])}r.length&&(e.G({K:1,N:r}),c=!0)}))),h=()=>n?e.M()?n.scrollWidth:n.scrollHeight:0,m=(e,t)=>{if(n){if(_){if(null==r){const e=n[d];n[d]=1,r=0===n[d],n[d]=e}r&&(e*=-1)}t?n[d]+=e:(n[d]=e,s=3)}};return{$(r){n=r;const o=f(),u=()=>{let t=r[d];_&&(t=l(t)),i!==t&&(0!==s&&c?c=!1:3!==s&&(s=i>t?2:1),e.G({K:3,Z:i=t}))},a=(()=>{let e=null;const r=()=>{null!=e&&clearTimeout(e)},n=()=>{r(),e=setTimeout((()=>{e=null,u(),s=0,t()}),300)};return n.ee=r,n})(),h=()=>{u(),a()};return o.observe(r),r.addEventListener("scroll",h),()=>{o.disconnect(),r.removeEventListener("scroll",h),a.ee()}},T(e,t){const r=f();return a.set(e,t),r.observe(e),()=>{a.delete(e),r.unobserve(e)}},te:()=>n?n[d]:0,re:()=>s,ne:h,oe:m,le:async(t,r)=>{const n=()=>{let t=r();const n=h(),o=e.q();return n-(t+o)<=0&&(t=n-o),t};if(e.C(t)){do{e.G({K:3,Z:n()});try{await e.B()}catch(e){return}}while(e.C(t));m(n())}else{const t=n();m(t),e.G({K:3,Z:t})}}}})(R,(()=>{j(new Set)}))),F=n(M,R.J());f((()=>{R.G({K:0,l:M})}),[M]),f((()=>D.$(E.current)),[]),f((()=>{if(!q.length)return;const e=D.re();if(2===e){const e=q.reduce(((e,[,t])=>e+t),0);e&&D.oe(e,!0)}else if(3===e){const e=0===P,t=k-(F-1)==0,r=q.reduce(((r,[n,o])=>(n<P?e||(r+=o):!e&&t&&(r+=o),r)),0);r&&D.oe(r,!0)}}),[q]),t.useEffect((()=>{x&&(H.current>F&&(H.current=-1),F-1-k<=S&&H.current<F&&(H.current=F,x()))}),[k]),t.useImperativeHandle(b,(()=>({get scrollOffset(){return D.te()},get scrollSize(){return D.ne()},scrollToIndex(e){e=o(n(e,F-1),0),D.le(e,(()=>R.v(e)))},scrollToOffset(e){e=o(e,0),D.le(R.V(e),(()=>e))}})),[F]);const U=o(P-c,0),C=n(k+c,F-1),J=t.useMemo((()=>{const t=[];for(let e=U;e<=C;e++)W.add(e);return W.forEach((r=>{const n=T[r];t.push(e.jsx(m,{h:D,m:R,g:r,p:z,_:n},(null==n?void 0:n.key)||r))})),t}),[T,W,U,C]);return e.jsx(p,{R:E,m:R,p:I,P:v,_:J})}));exports.List=w;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/src/core/utils.ts","../src/src/core/cache.ts","../src/src/react/useIsomorphicLayoutEffect.ts","../src/src/react/useSyncExternalStore.ts","../src/src/react/List.tsx","../src/src/core/store.ts","../src/src/core/scroller.ts"],"sourcesContent":["export const min = Math.min;\nexport const max = Math.max;\nexport const abs = Math.abs;\n\nexport const range = <T>(length: number, cb: (i: number) => T): T[] =>\n Array.from({ length }, (_, i) => cb(i));\n\nexport const debounce = <T extends (...args: any[]) => void>(\n fn: T,\n ms: number\n) => {\n let id: NodeJS.Timeout | null = null;\n\n const cancel = () => {\n if (id != null) {\n clearTimeout(id);\n }\n };\n const debouncedFn = () => {\n cancel();\n id = setTimeout(() => {\n id = null;\n fn();\n }, ms);\n };\n debouncedFn._cancel = cancel;\n return debouncedFn;\n};\n","import type { DeepReadonly, Writeable } from \"./types\";\nimport { max, min, range } from \"./utils\";\n\nexport const UNCACHED = -1;\n\nexport type Cache = DeepReadonly<{\n _defaultItemSize: number;\n _length: number;\n _sizes: number[];\n _measuredOffsetIndex: number;\n _offsets: number[];\n}>;\n\nexport const getItemSize = (cache: Cache, index: number): number => {\n const size = cache._sizes[index]!;\n return size === UNCACHED ? cache._defaultItemSize : size;\n};\n\nexport const setItemSize = (\n cache: Writeable<Cache>,\n index: number,\n size: number\n) => {\n cache._sizes[index] = size;\n // mark as dirty\n cache._measuredOffsetIndex = min(index, cache._measuredOffsetIndex);\n};\n\nexport const computeTotalSize = (cache: Writeable<Cache>): number => {\n if (!cache._length) return 0;\n const lastIndex = cache._length - 1;\n if (cache._measuredOffsetIndex >= lastIndex) {\n return cache._offsets[lastIndex]! + getItemSize(cache, lastIndex);\n }\n\n let top = cache._offsets[cache._measuredOffsetIndex]!;\n for (let i = cache._measuredOffsetIndex; i <= lastIndex; i++) {\n cache._offsets[i] = top;\n top += getItemSize(cache, i);\n }\n\n cache._measuredOffsetIndex = lastIndex;\n return top;\n};\n\nconst findIndex = (cache: Cache, i: number, distance: number): number => {\n let sum = 0;\n if (distance >= 0) {\n // search forward\n while (i < cache._length - 1) {\n const h = getItemSize(cache, i);\n sum += h;\n i++;\n if (sum >= distance) {\n if (sum - h / 2 >= distance) {\n i--;\n }\n break;\n }\n }\n } else {\n // search backward\n while (i > 0) {\n i--;\n const h = getItemSize(cache, i);\n sum -= h;\n if (sum <= distance) {\n if (sum + h / 2 < distance) {\n i++;\n }\n break;\n }\n }\n }\n\n return min(max(i, 0), cache._length - 1);\n};\n\nexport const findStartIndexWithOffset = (\n cache: Cache,\n offset: number,\n prevStartIndex: number,\n prevOffset: number\n): number => {\n return findIndex(cache, prevStartIndex, offset - prevOffset);\n};\n\nexport const findEndIndex = findIndex;\n\nexport const hasUnmeasuredItemsInRange = (\n cache: Cache,\n startIndex: number,\n endIndex: number\n): boolean => {\n for (let i = startIndex; i <= endIndex; i++) {\n if (cache._sizes[i] === UNCACHED) {\n return true;\n }\n }\n return false;\n};\n\nexport const computeStartOffset = (\n cache: Writeable<Cache>,\n index: number\n): number => {\n if (!cache._length) return 0;\n if (cache._measuredOffsetIndex >= index) {\n return cache._offsets[index]!;\n }\n\n let top = cache._offsets[cache._measuredOffsetIndex]!;\n for (let i = cache._measuredOffsetIndex; i <= index; i++) {\n cache._offsets[i] = top;\n if (i === index) {\n break;\n }\n top += getItemSize(cache, i);\n }\n cache._measuredOffsetIndex = index;\n return top;\n};\n\nexport const resetCache = (\n length: number,\n itemSize: number,\n cache?: Cache\n): Cache => {\n return {\n _defaultItemSize: itemSize,\n _length: length,\n _measuredOffsetIndex:\n (cache && min(cache._measuredOffsetIndex, length - 1)) ?? 0,\n _sizes: range(length, (i) => (cache && cache._sizes[i]) ?? UNCACHED),\n _offsets: range(length, (i) =>\n i === 0\n ? 0 // first offset must be 0\n : (cache && cache._offsets[i]) ?? UNCACHED\n ),\n };\n};\n","import { useEffect, useLayoutEffect } from \"react\";\n\n// https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85\nexport const useIsomorphicLayoutEffect =\n typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n","import { useSyncExternalStore as _useSyncExternalStore } from \"use-sync-external-store/shim\";\n\nexport const useSyncExternalStore = <T>(\n subscibe: (onStoreChange: () => void) => () => void,\n getSnapShot: () => T\n): T => {\n return _useSyncExternalStore(subscibe, getSnapShot, getSnapShot);\n};\n","import {\n Children,\n memo,\n useRef,\n useMemo,\n CSSProperties,\n ReactElement,\n forwardRef,\n useImperativeHandle,\n ReactNode,\n useEffect,\n RefObject,\n} from \"react\";\nimport {\n HANDLE_SCROLL,\n UPDATE_CACHE_LENGTH,\n VirtualStore,\n createVirtualStore,\n} from \"../core/store\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore\";\nimport { max, min } from \"../core/utils\";\nimport {\n createScroller,\n Scroller,\n SCROLL_MANUAL,\n SCROLL_UP,\n} from \"../core/scroller\";\n\nconst INITIAL_END_REACHED_INDEX = -1;\n\ntype ItemProps = {\n _children: ReactNode;\n _handle: Scroller;\n _store: VirtualStore;\n _index: number;\n _element: \"div\";\n _isHorizontal: boolean | undefined;\n _isRtl: boolean | undefined;\n};\n\nconst Item = memo(\n ({\n _children: children,\n _handle: handle,\n _store: store,\n _index: index,\n _element: Element,\n _isHorizontal: isHorizontal,\n _isRtl: isRtl,\n }: ItemProps): ReactElement => {\n const ref = useRef<HTMLDivElement>(null);\n\n const offset = useSyncExternalStore(store._subscribe, () =>\n store._getItemOffset(index)\n );\n const hide = useSyncExternalStore(store._subscribe, () =>\n store._isUnmeasuredItem(index)\n );\n\n // The index may be changed if elements are inserted to or removed from the start of props.children\n useIsomorphicLayoutEffect(\n () => handle._initItem(ref.current!, index),\n [index]\n );\n\n return (\n <Element\n ref={ref}\n style={useMemo<CSSProperties>(() => {\n const style: CSSProperties = {\n margin: \"0\",\n padding: \"0\",\n position: \"absolute\",\n [isHorizontal ? \"height\" : \"width\"]: \"100%\",\n [isHorizontal ? \"top\" : isRtl ? \"right\" : \"left\"]: 0,\n [isHorizontal ? (isRtl ? \"right\" : \"left\") : \"top\"]: offset,\n // willChange: \"transform\",\n };\n if (isHorizontal) {\n style.display = \"flex\";\n }\n if (hide) {\n style.visibility = \"hidden\";\n }\n return style;\n }, [offset, isHorizontal, isRtl, hide])}\n >\n {children}\n </Element>\n );\n }\n);\n\nconst isInvalidElement = <T extends ReactNode>(\n e: T\n): e is Extract<T, null | undefined | boolean> =>\n e == null || typeof e === \"boolean\";\n\nconst Window = ({\n _children: children,\n _ref: ref,\n _element: Element,\n _style: style,\n _isHorizontal: isHorizontal,\n}: {\n _children: ReactNode;\n _ref: RefObject<HTMLDivElement>;\n _element: \"div\";\n _style: CSSProperties | undefined;\n _isHorizontal: boolean | undefined;\n}) => {\n return (\n <Element\n ref={ref}\n style={useMemo<CSSProperties>(\n () => ({\n overflow: isHorizontal ? \"auto hidden\" : \"hidden auto\",\n position: \"relative\",\n contain: \"strict\",\n // transform: \"translate3d(0px, 0px, 0px)\",\n // willChange: \"scroll-position\",\n // backfaceVisibility: \"hidden\",\n width: \"100%\",\n height: \"100%\",\n padding: 0,\n margin: 0,\n ...style,\n }),\n [isHorizontal, style]\n )}\n >\n {children}\n </Element>\n );\n};\n\nconst Inner = ({\n _children: children,\n _store: store,\n _element: Element,\n _style: style,\n _isHorizontal: isHorizontal,\n _isRtl: isRtl,\n}: {\n _children: ReactNode;\n _store: VirtualStore;\n _element: \"div\";\n _style: CSSProperties | undefined;\n _isHorizontal: boolean | undefined;\n _isRtl: boolean | undefined;\n}) => {\n const scrollSize = useSyncExternalStore(\n store._subscribe,\n store._getScrollSize\n );\n const viewportSize = useSyncExternalStore(\n store._subscribe,\n store._getViewportSize\n );\n\n return (\n <Element\n style={useMemo<CSSProperties>(() => {\n const clampedScrollSize =\n scrollSize >= viewportSize ? scrollSize : viewportSize;\n const width = isHorizontal ? clampedScrollSize : \"100%\";\n const height = isHorizontal ? \"100%\" : clampedScrollSize;\n return {\n position: \"absolute\",\n top: 0,\n [isRtl ? \"right\" : \"left\"]: 0,\n width,\n height,\n minWidth: width,\n minHeight: height,\n ...style,\n };\n }, [scrollSize, viewportSize, style, isHorizontal, isRtl])}\n >\n {children}\n </Element>\n );\n};\n\nexport interface CustomComponentProps {\n style: CSSProperties;\n children: ReactNode;\n}\n\nexport type CustomComponent = React.ForwardRefExoticComponent<\n React.PropsWithoutRef<CustomComponentProps> & React.RefAttributes<any>\n>;\n\ntype CustomElementType = keyof JSX.IntrinsicElements | CustomComponent;\n\n/**\n * Methods of {@link List}.\n */\nexport interface ListHandle {\n /**\n * Get current scrollTop or scrollLeft.\n */\n scrollOffset: number;\n /**\n * Get current scrollHeight or scrollWidth.\n */\n scrollSize: number;\n /**\n * Scroll to the item specified by index.\n * @param index index of item\n */\n scrollToIndex(index: number): void;\n /**\n * Scroll to the item specified by offset.\n * @param offset offset from start\n */\n scrollToOffset(offset: number): void;\n}\n\n/**\n * Props of {@link List}.\n */\nexport interface ListProps {\n /**\n * Elements rendered by this component.\n */\n children: ReactNode;\n /**\n * Item size hint for unmeasured items. It's recommended to specify this prop if item sizes are fixed and known, or much larger than the defaultValue. It will help to reduce scroll jump when items are measured.\n * @defaultValue 40\n */\n itemSize?: number;\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 6\n */\n overscan?: number;\n /**\n * If true, rendered as a horizontally scrollable list. Otherwise rendered as a vertically scrollable list.\n */\n horizontal?: boolean;\n /**\n * You have to set true if you use this component under `direction: rtl` style.\n */\n rtl?: boolean;\n /**\n * Number of items to be the margin from the end of the scroll. See also {@link onEndReached}.\n * @defaultValue 0\n */\n endThreshold?: number;\n /**\n * Inline style prop to override style of scrollable element.\n */\n style?: CSSProperties;\n /**\n * Inline style prop to override style of inner element.\n */\n innerStyle?: CSSProperties;\n /**\n * Customized element type for scrollable element.\n * @defaultValue \"div\"\n */\n element?: CustomElementType;\n /**\n * Customized element type for inner element.\n * @defaultValue \"div\"\n */\n innerElement?: CustomElementType;\n /**\n * Customized element type for item element.\n * @defaultValue \"div\"\n */\n itemElement?: CustomElementType;\n /**\n * Callback invoked when scrolling reached to the end. The margin from the end is specified by {@link endThreshold}.\n */\n onEndReached?: () => void;\n}\n\n/**\n * Virtualized list component. See {@link ListProps} and {@link ListHandle}.\n */\nexport const List = forwardRef<ListHandle, ListProps>(\n (\n {\n children,\n itemSize = 40,\n overscan = 6,\n horizontal: isHorizontal,\n rtl: isRtl,\n endThreshold = 0,\n style: styleProp,\n innerStyle: innerStyleProp,\n element = \"div\",\n innerElement = \"div\",\n itemElement = \"div\",\n onEndReached,\n },\n ref\n ): ReactElement => {\n // memoize element count\n const rawCount = useMemo(() => {\n let i = 0;\n Children.forEach(children, (e) => {\n if (isInvalidElement(e)) {\n return;\n }\n i++;\n });\n return i;\n }, [children]);\n\n // https://github.com/facebook/react/issues/25191#issuecomment-1237456448\n const storeRef = useRef<VirtualStore | undefined>();\n const store =\n storeRef.current ||\n (storeRef.current = createVirtualStore(rawCount, itemSize, isHorizontal));\n const startIndex = useSyncExternalStore(\n store._subscribe,\n store._getStartIndex\n );\n const endIndex = useSyncExternalStore(store._subscribe, store._getEndIndex);\n const jump = useSyncExternalStore(store._subscribe, store._getJump);\n const scrollRef = useRef<HTMLDivElement>(null);\n const onEndReachedCalledIndex = useRef<number>(INITIAL_END_REACHED_INDEX);\n\n const handleRef = useRef<Scroller>();\n const handle =\n handleRef.current ||\n (handleRef.current = createScroller(store, isHorizontal, isRtl));\n\n // The elements length and cached items length are different just after element is added/removed.\n const count = min(rawCount, store._getItemCount());\n\n const startIndexWithMargin = max(startIndex - overscan, 0);\n const endIndexWithMargin = min(endIndex + overscan, count - 1);\n\n // So update cache length. Updating state in render will cause warn so use useEffect for now.\n useIsomorphicLayoutEffect(() => {\n store._update({\n _type: UPDATE_CACHE_LENGTH,\n _length: rawCount,\n });\n }, [rawCount]);\n\n useIsomorphicLayoutEffect(() => handle._initRoot(scrollRef.current!), []);\n\n useIsomorphicLayoutEffect(() => {\n if (!jump.length) return;\n\n // Compensate scroll jump\n const scrollDirection = handle._getScrollDirection();\n if (scrollDirection === SCROLL_UP) {\n const diff = jump.reduce((acc, [, j]) => acc + j, 0);\n if (diff) {\n handle._updateScrollPosition(diff, true);\n }\n } else if (scrollDirection === SCROLL_MANUAL) {\n const isStartInView = startIndex === 0;\n const isEndInView = endIndex - (count - 1) === 0;\n const diff = jump.reduce((acc, [index, j]) => {\n if (index < startIndex) {\n // Keep start if scroll position is not stuck to the start\n if (!isStartInView) {\n acc += j;\n }\n } else {\n // Keep end if scroll position is stuck to the end\n if (!isStartInView && isEndInView) {\n acc += j;\n }\n }\n return acc;\n }, 0);\n if (diff) {\n handle._updateScrollPosition(diff, true);\n }\n } else {\n // NOP\n }\n }, [jump]);\n\n useEffect(() => {\n if (!onEndReached) return;\n\n if (onEndReachedCalledIndex.current > count) {\n // Probably items have been refreshed, so reset index\n onEndReachedCalledIndex.current = INITIAL_END_REACHED_INDEX;\n }\n\n const endMargin = count - 1 - endIndex;\n if (\n endMargin <= endThreshold &&\n onEndReachedCalledIndex.current < count\n ) {\n onEndReachedCalledIndex.current = count;\n onEndReached();\n }\n }, [endIndex]);\n\n useImperativeHandle(\n ref,\n () => {\n const getScrollSize = (): number => {\n const el = scrollRef.current;\n if (!el) return 0;\n // Use element's scrollHeight/scrollWidth instead of stored scrollSize.\n // This is because stored size may differ from the actual size, for example when a new item is added and not yet measured.\n return isHorizontal ? el.scrollWidth : el.scrollHeight;\n };\n const scrollTo = async (\n index: number,\n getCurrentOffset: () => number\n ) => {\n const getOffset = (): number => {\n let offset = getCurrentOffset();\n const scrollSize = getScrollSize();\n const viewportSize = store._getViewportSize();\n if (scrollSize - (offset + viewportSize) <= 0) {\n // Adjust if the offset is over the end, to get correct startIndex.\n offset = scrollSize - viewportSize;\n }\n return offset;\n };\n\n if (store._hasUnmeasuredItemsInRange(index)) {\n do {\n // In order to scroll to the correct position, mount the items and measure their sizes before scrolling.\n store._update({\n _type: HANDLE_SCROLL,\n _offset: getOffset(),\n });\n try {\n // Wait for the scroll destination items to be measured.\n await store._waitForScrollDestinationItemsMeasured();\n } catch (e) {\n // canceled\n return;\n }\n } while (store._hasUnmeasuredItemsInRange(index));\n\n // Scroll with the updated value\n handle._updateScrollPosition(getOffset());\n } else {\n const offset = getOffset();\n handle._updateScrollPosition(offset);\n // Sync viewport to scroll destination\n store._update({ _type: HANDLE_SCROLL, _offset: offset });\n }\n };\n\n return {\n get scrollOffset() {\n return handle._getScrollPosition();\n },\n get scrollSize() {\n return getScrollSize();\n },\n scrollToIndex(index) {\n index = max(min(index, count - 1), 0);\n\n scrollTo(index, () => store._getItemOffset(index));\n },\n scrollToOffset(offset) {\n offset = max(offset, 0);\n\n scrollTo(store._getItemIndexForScrollTo(offset), () => offset);\n },\n };\n },\n [count]\n );\n\n const items = useMemo(() => {\n let i = -1;\n const elements: ReactElement[] = [];\n Children.forEach(children, (e) => {\n if (isInvalidElement(e)) {\n return;\n }\n i++;\n if (i < startIndexWithMargin || i > endIndexWithMargin) {\n return;\n }\n elements.push(\n <Item\n key={(e as { key?: ReactElement[\"key\"] })?.key || i}\n _handle={handle}\n _store={store}\n _index={i}\n _element={itemElement as \"div\"}\n _isHorizontal={isHorizontal}\n _isRtl={isRtl}\n _children={e}\n />\n );\n });\n return elements;\n }, [children, startIndexWithMargin, endIndexWithMargin]);\n\n return (\n <Window\n _ref={scrollRef}\n _isHorizontal={isHorizontal}\n _element={element as \"div\"}\n _style={styleProp}\n _children={\n <Inner\n _store={store}\n _element={innerElement as \"div\"}\n _style={innerStyleProp}\n _isHorizontal={isHorizontal}\n _isRtl={isRtl}\n _children={items}\n />\n }\n />\n );\n }\n);\n","import {\n findStartIndexWithOffset,\n resetCache,\n getItemSize,\n computeTotalSize,\n findEndIndex,\n computeStartOffset,\n Cache,\n UNCACHED,\n setItemSize,\n hasUnmeasuredItemsInRange,\n} from \"./cache\";\nimport type { Writeable } from \"./types\";\n\nexport const UPDATE_CACHE_LENGTH = 0;\nexport const UPDATE_ITEM_SIZES = 1;\nexport const UPDATE_VIEWPORT_SIZE = 2;\nexport const HANDLE_SCROLL = 3;\n\nexport type ScrollJump = Readonly<[index: number, sizeDiff: number][]>;\n\ntype State = {\n _startIndex: number;\n _viewportWidth: number;\n _viewportHeight: number;\n _cache: Cache;\n _jump: ScrollJump;\n};\n\ntype Actions =\n | { _type: typeof UPDATE_CACHE_LENGTH; _length: number }\n | {\n _type: typeof UPDATE_ITEM_SIZES;\n _entries: [index: number, size: number][];\n }\n | { _type: typeof UPDATE_VIEWPORT_SIZE; _width: number; _height: number }\n | { _type: typeof HANDLE_SCROLL; _offset: number };\n\nconst mutate = (state: State, action: Actions, itemSize: number): boolean => {\n switch (action._type) {\n case UPDATE_CACHE_LENGTH: {\n if (state._cache._length === action._length) return false;\n state._cache = resetCache(action._length, itemSize, state._cache);\n return true;\n }\n case UPDATE_ITEM_SIZES: {\n const updated = action._entries.filter(\n ([index, size]) => state._cache._sizes[index] !== size\n );\n // Skip if all items are cached and not updated\n if (!updated.length) {\n return false;\n }\n\n const jump: [index: number, sizeDiff: number][] = [];\n updated.forEach(([index, size]) => {\n jump.push([index, size - getItemSize(state._cache, index)]);\n setItemSize(state._cache as Writeable<Cache>, index, size);\n });\n state._jump = jump;\n return true;\n }\n case UPDATE_VIEWPORT_SIZE: {\n if (\n state._viewportWidth === action._width &&\n state._viewportHeight === action._height\n ) {\n return false;\n }\n state._viewportWidth = action._width;\n state._viewportHeight = action._height;\n return true;\n }\n case HANDLE_SCROLL: {\n const prevStartIndex = state._startIndex;\n const prevOffset = computeStartOffset(\n state._cache as Writeable<Cache>,\n prevStartIndex\n );\n if (prevOffset === action._offset) {\n return false;\n }\n return (\n (state._startIndex = findStartIndexWithOffset(\n state._cache,\n action._offset,\n prevStartIndex,\n prevOffset\n )) !== prevStartIndex\n );\n }\n }\n};\n\nexport type VirtualStore = {\n _getStartIndex(): number;\n _getEndIndex(): number;\n _isUnmeasuredItem(index: number): boolean;\n _hasUnmeasuredItemsInRange(startIndex: number): boolean;\n _getItemOffset(index: number): number;\n _getViewportSize(): number;\n _getScrollSize(): number;\n _getItemCount(): number;\n _getJump(): ScrollJump;\n _getItemIndexForScrollTo(offset: number): number;\n _waitForScrollDestinationItemsMeasured(): Promise<void>;\n _subscribe(cb: () => void): () => void;\n _update(action: Actions): void;\n};\n\nexport const createVirtualStore = (\n itemCount: number,\n itemSize: number,\n isHorizontal: boolean | undefined\n): VirtualStore => {\n const subscribers = new Set<() => void>();\n const state: Readonly<State> = {\n _startIndex: 0,\n _viewportWidth: 0,\n _viewportHeight: 0,\n _cache: resetCache(itemCount, itemSize),\n _jump: [],\n };\n const getViewportSize = (): number =>\n isHorizontal ? state._viewportWidth : state._viewportHeight;\n\n let scrollToQueue: [() => void, () => void] | undefined;\n\n return {\n _getStartIndex() {\n return state._startIndex;\n },\n _getEndIndex() {\n return findEndIndex(state._cache, state._startIndex, getViewportSize());\n },\n _isUnmeasuredItem(index) {\n return state._cache._sizes[index] === UNCACHED;\n },\n _hasUnmeasuredItemsInRange(startIndex) {\n return hasUnmeasuredItemsInRange(\n state._cache,\n startIndex,\n findEndIndex(state._cache, startIndex, getViewportSize())\n );\n },\n _getItemOffset(index) {\n return computeStartOffset(state._cache as Writeable<Cache>, index);\n },\n _getViewportSize() {\n return getViewportSize();\n },\n _getScrollSize() {\n return computeTotalSize(state._cache as Writeable<Cache>);\n },\n _getItemCount() {\n return state._cache._length;\n },\n _getJump() {\n return state._jump;\n },\n _getItemIndexForScrollTo(offset) {\n return findStartIndexWithOffset(state._cache, offset, 0, 0);\n },\n _waitForScrollDestinationItemsMeasured() {\n if (scrollToQueue) {\n // Cancel waiting scrollTo\n scrollToQueue[1]();\n }\n // The measurement will be done asynchronously and the timing is not predictable so we use promise.\n // For example, ResizeObserver may not fire when window is not visible.\n return new Promise((resolve, reject) => {\n scrollToQueue = [\n () => {\n // HACK: It should be resolved in the next microtask that is after React's render\n Promise.resolve().then(() => {\n resolve();\n scrollToQueue = undefined;\n });\n },\n reject,\n ];\n });\n },\n _subscribe(cb) {\n subscribers.add(cb);\n return () => {\n subscribers.delete(cb);\n };\n },\n _update(action) {\n const mutated = mutate(state, action, itemSize);\n if (mutated) {\n subscribers.forEach((cb) => {\n cb();\n });\n if (scrollToQueue && action._type === UPDATE_ITEM_SIZES) {\n scrollToQueue[0]();\n }\n }\n },\n };\n};\n","import {\n HANDLE_SCROLL,\n UPDATE_ITEM_SIZES,\n UPDATE_VIEWPORT_SIZE,\n VirtualStore,\n} from \"./store\";\nimport { abs, debounce } from \"./utils\";\n\nexport const SCROLL_STOP = 0;\nexport const SCROLL_DOWN = 1;\nexport const SCROLL_UP = 2;\nexport const SCROLL_MANUAL = 3;\ntype ScrollDirection =\n | typeof SCROLL_STOP\n | typeof SCROLL_DOWN\n | typeof SCROLL_UP\n | typeof SCROLL_MANUAL;\n\nexport type Scroller = {\n _initRoot: (rootElement: HTMLElement) => () => void;\n _initItem: (itemElement: HTMLElement, index: number) => () => void;\n _getScrollPosition: () => number;\n _getScrollDirection: () => ScrollDirection;\n _updateScrollPosition: (offset: number, diff?: boolean) => void;\n};\n\nexport const createScroller = (\n store: VirtualStore,\n isHorizontal: boolean | undefined,\n isRtl: boolean | undefined\n): Scroller => {\n let prevOffset = -1;\n let scrollDirection: ScrollDirection = SCROLL_STOP;\n let resized = false;\n let isNegativeOffset: boolean | undefined;\n let rootElement: HTMLElement | undefined;\n let _ro: ResizeObserver | undefined;\n const scrollToKey = isHorizontal ? \"scrollLeft\" : \"scrollTop\";\n const mountedIndexes = new WeakMap<Element, number>();\n const getResizeObserver = (): ResizeObserver => {\n // Initialize ResizeObserver lazily for SSR\n return (\n _ro ||\n (_ro = new ResizeObserver((entries) => {\n // https://www.w3.org/TR/resize-observer/#intro\n const resizes: [index: number, size: number][] = [];\n for (const entry of entries) {\n if (entry.target === rootElement) {\n store._update({\n _type: UPDATE_VIEWPORT_SIZE,\n _width: entry.contentRect.width,\n _height: entry.contentRect.height,\n });\n } else {\n const index = mountedIndexes.get(entry.target);\n if (index != null) {\n resizes.push([\n index,\n entry.contentRect[isHorizontal ? \"width\" : \"height\"],\n ]);\n }\n }\n }\n\n if (resizes.length) {\n store._update({\n _type: UPDATE_ITEM_SIZES,\n _entries: resizes,\n });\n resized = true;\n }\n }))\n );\n };\n\n return {\n _initRoot(root) {\n rootElement = root;\n const ro = getResizeObserver();\n\n const syncViewportToScrollPosition = () => {\n let offset = root[scrollToKey];\n if (isRtl) {\n // The scroll position may be negative value in rtl direction.\n // https://github.com/othree/jquery.rtl-scroll-type\n offset = abs(offset);\n }\n if (prevOffset === offset) {\n return;\n }\n // Skip scroll direction detection just after resizing because it may result in the opposite direction.\n // Scroll events are dispatched enough so it's ok to skip some of them.\n if (scrollDirection === SCROLL_STOP || !resized) {\n // Ignore until manual scrolling\n if (scrollDirection !== SCROLL_MANUAL) {\n scrollDirection = prevOffset > offset ? SCROLL_UP : SCROLL_DOWN;\n }\n } else {\n resized = false;\n }\n store._update({\n _type: HANDLE_SCROLL,\n _offset: (prevOffset = offset),\n });\n };\n\n const onScrollStopped = debounce(() => {\n // Check scroll position once just after scrolling stopped\n syncViewportToScrollPosition();\n scrollDirection = SCROLL_STOP;\n }, 300);\n\n const onScroll = () => {\n syncViewportToScrollPosition();\n onScrollStopped();\n };\n\n ro.observe(root);\n root.addEventListener(\"scroll\", onScroll);\n\n return () => {\n ro.disconnect();\n root.removeEventListener(\"scroll\", onScroll);\n onScrollStopped._cancel();\n };\n },\n _initItem(el, i) {\n const ro = getResizeObserver();\n mountedIndexes.set(el, i);\n ro.observe(el);\n return () => {\n mountedIndexes.delete(el);\n ro.unobserve(el);\n };\n },\n _getScrollPosition() {\n if (!rootElement) return 0;\n return rootElement[scrollToKey];\n },\n _getScrollDirection() {\n return scrollDirection;\n },\n _updateScrollPosition(offset, diff) {\n if (!rootElement) return;\n if (isRtl) {\n if (isNegativeOffset == null) {\n // Assume offset type in rtl direction.\n // The scroll position is negative in spec however its not in some browsers, for example Chrome earlier than v85.\n // https://github.com/othree/jquery.rtl-scroll-type\n const prev = rootElement[scrollToKey];\n rootElement[scrollToKey] = 1;\n isNegativeOffset = rootElement[scrollToKey] === 0;\n rootElement[scrollToKey] = prev;\n }\n if (isNegativeOffset) {\n offset *= -1;\n }\n }\n if (diff) {\n rootElement[scrollToKey] += offset;\n } else {\n rootElement[scrollToKey] = offset;\n scrollDirection = SCROLL_MANUAL;\n }\n },\n };\n};\n"],"names":["min","Math","max","abs","range","length","cb","Array","from","_","i","getItemSize","cache","index","size","_sizes","_defaultItemSize","findIndex","distance","sum","_length","h","findStartIndexWithOffset","offset","prevStartIndex","prevOffset","findEndIndex","computeStartOffset","_measuredOffsetIndex","_offsets","top","resetCache","itemSize","_a","useIsomorphicLayoutEffect","window","useLayoutEffect","useEffect","useSyncExternalStore","subscibe","getSnapShot","_useSyncExternalStore","Item","memo","_children","children","_handle","handle","_store","store","_index","_element","Element","_isHorizontal","isHorizontal","_isRtl","isRtl","ref","useRef","_subscribe","_getItemOffset","hide","_isUnmeasuredItem","_initItem","current","_jsx","style","useMemo","margin","padding","position","display","visibility","isInvalidElement","e","Window","_ref","_style","overflow","contain","width","height","Inner","scrollSize","_getScrollSize","viewportSize","_getViewportSize","clampedScrollSize","minWidth","minHeight","List","forwardRef","overscan","horizontal","rtl","endThreshold","styleProp","innerStyle","innerStyleProp","element","innerElement","itemElement","onEndReached","rawCount","Children","forEach","storeRef","createVirtualStore","itemCount","subscribers","Set","state","_startIndex","_viewportWidth","_viewportHeight","_cache","_jump","getViewportSize","scrollToQueue","_getStartIndex","_getEndIndex","_hasUnmeasuredItemsInRange","startIndex","hasUnmeasuredItemsInRange","endIndex","lastIndex","computeTotalSize","_getItemCount","_getJump","_getItemIndexForScrollTo","_waitForScrollDestinationItemsMeasured","Promise","resolve","reject","then","undefined","add","delete","_update","action","mutate","_type","updated","_entries","filter","jump","push","setItemSize","_width","_height","_offset","scrollRef","onEndReachedCalledIndex","handleRef","createScroller","isNegativeOffset","rootElement","_ro","scrollDirection","resized","scrollToKey","mountedIndexes","WeakMap","getResizeObserver","ResizeObserver","entries","resizes","entry","target","contentRect","get","_initRoot","root","ro","syncViewportToScrollPosition","onScrollStopped","debounce","id","cancel","clearTimeout","debouncedFn","setTimeout","_cancel","onScroll","observe","addEventListener","disconnect","removeEventListener","el","set","unobserve","_getScrollPosition","_getScrollDirection","_updateScrollPosition","diff","prev","count","startIndexWithMargin","endIndexWithMargin","reduce","acc","j","isStartInView","isEndInView","useImperativeHandle","getScrollSize","scrollWidth","scrollHeight","scrollTo","async","getCurrentOffset","getOffset","scrollOffset","scrollToIndex","scrollToOffset","items","elements","key","jsx"],"mappings":"8IAAO,MAAMA,EAAMC,KAAKD,IACXE,EAAMD,KAAKC,IACXC,EAAMF,KAAKE,IAEXC,EAAQA,CAAIC,EAAgBC,IACvCC,MAAMC,KAAK,CAAEH,WAAU,CAACI,EAAGC,IAAMJ,EAAGI,KCQzBC,EAAcA,CAACC,EAAcC,KACxC,MAAMC,EAAOF,EAAMG,EAAOF,GAC1B,OAZsB,IAYfC,EAAoBF,EAAMI,EAAmBF,CAAI,EA8BpDG,EAAYA,CAACL,EAAcF,EAAWQ,KAC1C,IAAIC,EAAM,EACV,GAAID,GAAY,EAEd,KAAOR,EAAIE,EAAMQ,EAAU,GAAG,CAC5B,MAAMC,EAAIV,EAAYC,EAAOF,GAG7B,GAFAS,GAAOE,EACPX,IACIS,GAAOD,EAAU,CACfC,EAAME,EAAI,GAAKH,GACjBR,IAEF,KACD,CACF,MAGD,KAAOA,EAAI,GAAG,CACZA,IACA,MAAMW,EAAIV,EAAYC,EAAOF,GAE7B,GADAS,GAAOE,EACHF,GAAOD,EAAU,CACfC,EAAME,EAAI,EAAIH,GAChBR,IAEF,KACD,CACF,CAGH,OAAOV,EAAIE,EAAIQ,EAAG,GAAIE,EAAMQ,EAAU,EAAE,EAG7BE,EAA2BA,CACtCV,EACAW,EACAC,EACAC,IAEOR,EAAUL,EAAOY,EAAgBD,EAASE,GAGtCC,EAAeT,EAefU,EAAqBA,CAChCf,EACAC,KAEA,IAAKD,EAAMQ,EAAS,OAA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sBjC,OArBAhH,EAAAA,SAASC,QAAQ5D,GAAW6B,IACtBD,EAAiBC,KAGrBhE,IACIA,EAAI2L,GAAwB3L,EAAI4L,GAGpCkB,EAAStE,KACPjF,EAAAA,IAACvB,EAEC,CAAAI,EAASC,EACTC,EAAQC,EACRC,EAAQxC,EACRyC,EAAUkD,EACVhD,EAAeC,EACfC,EAAQC,EACRZ,EAAW8B,IAPLA,eAAAA,EAAqC+I,MAAO/M,IASrD,IAEI8M,CAAQ,GACd,CAAC3K,EAAUwJ,EAAsBC,IAEpC,OACErI,MAACU,EAAM,CACLC,EAAM2E,EACNlG,EAAeC,EACfH,EAAUgD,EACVtB,EAAQmB,EACRpD,EACEqB,EAAAyJ,IAACxI,EAAK,CACJlC,EAAQC,EACRE,EAAUiD,EACVvB,EAAQqB,EACR7C,EAAeC,EACfC,EAAQC,EACRZ,EAAW2K,KAGf"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/src/core/utils.ts","../src/src/core/cache.ts","../src/src/react/useIsomorphicLayoutEffect.ts","../src/src/react/useSyncExternalStore.ts","../src/src/react/List.tsx","../src/src/core/store.ts","../src/src/core/scroller.ts"],"sourcesContent":["export const min = Math.min;\nexport const max = Math.max;\nexport const abs = Math.abs;\n\nexport const range = <T>(length: number, cb: (i: number) => T): T[] =>\n Array.from({ length }, (_, i) => cb(i));\n\nexport const debounce = <T extends (...args: any[]) => void>(\n fn: T,\n ms: number\n) => {\n let id: NodeJS.Timeout | null = null;\n\n const cancel = () => {\n if (id != null) {\n clearTimeout(id);\n }\n };\n const debouncedFn = () => {\n cancel();\n id = setTimeout(() => {\n id = null;\n fn();\n }, ms);\n };\n debouncedFn._cancel = cancel;\n return debouncedFn;\n};\n","import type { DeepReadonly, Writeable } from \"./types\";\nimport { max, min, range } from \"./utils\";\n\nexport const UNCACHED = -1;\n\nexport type Cache = DeepReadonly<{\n _defaultItemSize: number;\n _length: number;\n _sizes: number[];\n _measuredOffsetIndex: number;\n _offsets: number[];\n}>;\n\nexport const getItemSize = (cache: Cache, index: number): number => {\n const size = cache._sizes[index]!;\n return size === UNCACHED ? cache._defaultItemSize : size;\n};\n\nexport const setItemSize = (\n cache: Writeable<Cache>,\n index: number,\n size: number\n) => {\n cache._sizes[index] = size;\n // mark as dirty\n cache._measuredOffsetIndex = min(index, cache._measuredOffsetIndex);\n};\n\nexport const computeTotalSize = (cache: Writeable<Cache>): number => {\n if (!cache._length) return 0;\n const lastIndex = cache._length - 1;\n if (cache._measuredOffsetIndex >= lastIndex) {\n return cache._offsets[lastIndex]! + getItemSize(cache, lastIndex);\n }\n\n let top = cache._offsets[cache._measuredOffsetIndex]!;\n for (let i = cache._measuredOffsetIndex; i <= lastIndex; i++) {\n cache._offsets[i] = top;\n top += getItemSize(cache, i);\n }\n\n cache._measuredOffsetIndex = lastIndex;\n return top;\n};\n\nconst findIndex = (cache: Cache, i: number, distance: number): number => {\n let sum = 0;\n if (distance >= 0) {\n // search forward\n while (i < cache._length - 1) {\n const h = getItemSize(cache, i);\n sum += h;\n i++;\n if (sum >= distance) {\n if (sum - h / 2 >= distance) {\n i--;\n }\n break;\n }\n }\n } else {\n // search backward\n while (i > 0) {\n i--;\n const h = getItemSize(cache, i);\n sum -= h;\n if (sum <= distance) {\n if (sum + h / 2 < distance) {\n i++;\n }\n break;\n }\n }\n }\n\n return min(max(i, 0), cache._length - 1);\n};\n\nexport const findStartIndexWithOffset = (\n cache: Cache,\n offset: number,\n prevStartIndex: number,\n prevOffset: number\n): number => {\n return findIndex(cache, prevStartIndex, offset - prevOffset);\n};\n\nexport const findEndIndex = findIndex;\n\nexport const hasUnmeasuredItemsInRange = (\n cache: Cache,\n startIndex: number,\n endIndex: number\n): boolean => {\n for (let i = startIndex; i <= endIndex; i++) {\n if (cache._sizes[i] === UNCACHED) {\n return true;\n }\n }\n return false;\n};\n\nexport const computeStartOffset = (\n cache: Writeable<Cache>,\n index: number\n): number => {\n if (!cache._length) return 0;\n if (cache._measuredOffsetIndex >= index) {\n return cache._offsets[index]!;\n }\n\n let top = cache._offsets[cache._measuredOffsetIndex]!;\n for (let i = cache._measuredOffsetIndex; i <= index; i++) {\n cache._offsets[i] = top;\n if (i === index) {\n break;\n }\n top += getItemSize(cache, i);\n }\n cache._measuredOffsetIndex = index;\n return top;\n};\n\nexport const resetCache = (\n length: number,\n itemSize: number,\n cache?: Cache\n): Cache => {\n return {\n _defaultItemSize: itemSize,\n _length: length,\n _measuredOffsetIndex:\n (cache && min(cache._measuredOffsetIndex, length - 1)) ?? 0,\n _sizes: range(length, (i) => (cache && cache._sizes[i]) ?? UNCACHED),\n _offsets: range(length, (i) =>\n i === 0\n ? 0 // first offset must be 0\n : (cache && cache._offsets[i]) ?? UNCACHED\n ),\n };\n};\n","import { useEffect, useLayoutEffect } from \"react\";\n\n// https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85\nexport const useIsomorphicLayoutEffect =\n typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n","import { useSyncExternalStore as _useSyncExternalStore } from \"use-sync-external-store/shim\";\n\nexport const useSyncExternalStore = <T>(\n subscibe: (onStoreChange: () => void) => () => void,\n getSnapShot: () => T\n): T => {\n return _useSyncExternalStore(subscibe, getSnapShot, getSnapShot);\n};\n","import {\n Children,\n memo,\n useRef,\n useMemo,\n CSSProperties,\n ReactElement,\n forwardRef,\n useImperativeHandle,\n ReactNode,\n useEffect,\n RefObject,\n useState,\n} from \"react\";\nimport {\n UPDATE_CACHE_LENGTH,\n VirtualStore,\n createVirtualStore,\n} from \"../core/store\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore\";\nimport { max, min } from \"../core/utils\";\nimport {\n createScroller,\n Scroller,\n SCROLL_MANUAL,\n SCROLL_UP,\n} from \"../core/scroller\";\n\nconst INITIAL_END_REACHED_INDEX = -1;\n\ntype ItemProps = {\n _children: ReactNode;\n _scroller: Scroller;\n _store: VirtualStore;\n _index: number;\n _element: \"div\";\n};\n\nconst Item = memo(\n ({\n _children: children,\n _scroller: scroller,\n _store: store,\n _index: index,\n _element: Element,\n }: ItemProps): ReactElement => {\n const ref = useRef<HTMLDivElement>(null);\n\n const offset = useSyncExternalStore(store._subscribe, () =>\n store._getItemOffset(index)\n );\n const hide = useSyncExternalStore(store._subscribe, () =>\n store._isUnmeasuredItem(index)\n );\n\n // The index may be changed if elements are inserted to or removed from the start of props.children\n useIsomorphicLayoutEffect(\n () => scroller._initItem(ref.current!, index),\n [index]\n );\n\n return (\n <Element\n ref={ref}\n style={useMemo<CSSProperties>(() => {\n const isHorizontal = store._isHorizontal();\n const isRtl = store._isRtl();\n const style: CSSProperties = {\n margin: \"0\",\n padding: \"0\",\n position: \"absolute\",\n [isHorizontal ? \"height\" : \"width\"]: \"100%\",\n [isHorizontal ? \"top\" : isRtl ? \"right\" : \"left\"]: 0,\n [isHorizontal ? (isRtl ? \"right\" : \"left\") : \"top\"]: offset,\n // willChange: \"transform\",\n };\n if (isHorizontal) {\n style.display = \"flex\";\n }\n if (hide) {\n style.visibility = \"hidden\";\n }\n return style;\n }, [offset, hide])}\n >\n {children}\n </Element>\n );\n }\n);\n\nconst isInvalidElement = <T extends ReactNode>(\n e: T\n): e is Extract<T, null | undefined | boolean> =>\n e == null || typeof e === \"boolean\";\n\nexport interface CustomWindowComponentProps {\n children: ReactNode;\n style: CSSProperties;\n scrollSize: number;\n horizontal: boolean;\n rtl: boolean;\n}\n\nconst DefaultWindow = forwardRef<any, CustomWindowComponentProps>(\n ({ children, style, scrollSize, horizontal, rtl }, ref): ReactElement => {\n return (\n <div ref={ref} style={style}>\n <div\n style={useMemo<CSSProperties>(() => {\n const width = horizontal ? scrollSize : \"100%\";\n const height = horizontal ? \"100%\" : scrollSize;\n return {\n position: \"absolute\",\n top: 0,\n [rtl ? \"right\" : \"left\"]: 0,\n width,\n height,\n minWidth: width,\n minHeight: height,\n };\n }, [scrollSize])}\n >\n {children}\n </div>\n </div>\n );\n }\n);\n\nexport type CustomWindowComponent = typeof DefaultWindow;\n\nconst Window = ({\n _children: children,\n _ref: ref,\n _store: store,\n _element: Element,\n _style: style,\n}: {\n _children: ReactNode;\n _ref: RefObject<HTMLDivElement>;\n _store: VirtualStore;\n _element: CustomWindowComponent;\n _style: CSSProperties | undefined;\n}) => {\n const scrollSize = useSyncExternalStore(\n store._subscribe,\n store._getScrollSize\n );\n const viewportSize = useSyncExternalStore(\n store._subscribe,\n store._getViewportSize\n );\n const clampedScrollSize =\n scrollSize >= viewportSize ? scrollSize : viewportSize;\n\n const horizontal = store._isHorizontal();\n return (\n <Element\n ref={ref}\n scrollSize={clampedScrollSize}\n horizontal={horizontal}\n rtl={store._isRtl()}\n style={useMemo<CSSProperties>(\n () => ({\n overflow: horizontal ? \"auto hidden\" : \"hidden auto\",\n position: \"relative\",\n contain: \"strict\",\n // transform: \"translate3d(0px, 0px, 0px)\",\n // willChange: \"scroll-position\",\n // backfaceVisibility: \"hidden\",\n width: \"100%\",\n height: \"100%\",\n padding: 0,\n margin: 0,\n ...style,\n }),\n [style]\n )}\n >\n {children}\n </Element>\n );\n};\n\nexport interface CustomItemComponentProps {\n style: CSSProperties;\n children: ReactNode;\n}\n\nexport type CustomItemComponent = React.ForwardRefExoticComponent<\n React.PropsWithoutRef<CustomItemComponentProps> & React.RefAttributes<any>\n>;\n\ntype CustomItemComponentOrElement =\n | keyof JSX.IntrinsicElements\n | CustomItemComponent;\n\n/**\n * Methods of {@link List}.\n */\nexport interface ListHandle {\n /**\n * Get current scrollTop or scrollLeft.\n */\n scrollOffset: number;\n /**\n * Get current scrollHeight or scrollWidth.\n */\n scrollSize: number;\n /**\n * Scroll to the item specified by index.\n * @param index index of item\n */\n scrollToIndex(index: number): void;\n /**\n * Scroll to the item specified by offset.\n * @param offset offset from start\n */\n scrollToOffset(offset: number): void;\n}\n\n/**\n * Props of {@link List}.\n */\nexport interface ListProps {\n /**\n * Elements rendered by this component.\n */\n children: ReactNode;\n /**\n * Item size hint for unmeasured items. It's recommended to specify this prop if item sizes are fixed and known, or much larger than the defaultValue. It will help to reduce scroll jump when items are measured.\n * @defaultValue 40\n */\n itemSize?: number;\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 6\n */\n overscan?: number;\n /**\n * If true, rendered as a horizontally scrollable list. Otherwise rendered as a vertically scrollable list.\n */\n horizontal?: boolean;\n /**\n * You have to set true if you use this component under `direction: rtl` style.\n */\n rtl?: boolean;\n /**\n * Number of items to be the margin from the end of the scroll. See also {@link onEndReached}.\n * @defaultValue 0\n */\n endThreshold?: number;\n /**\n * Inline style prop to override style of scrollable element.\n */\n style?: CSSProperties;\n /**\n * Customized element type for scrollable element.\n * @defaultValue \"div\"\n */\n element?: CustomWindowComponent;\n /**\n * Customized element type for item element.\n * @defaultValue \"div\"\n */\n itemElement?: CustomItemComponentOrElement;\n /**\n * Callback invoked when scrolling reached to the end. The margin from the end is specified by {@link endThreshold}.\n */\n onEndReached?: () => void;\n}\n\n/**\n * Virtualized list component. See {@link ListProps} and {@link ListHandle}.\n */\nexport const List = forwardRef<ListHandle, ListProps>(\n (\n {\n children,\n itemSize: itemSizeProp = 40,\n overscan = 6,\n horizontal: horizontalProp,\n rtl: rtlProp,\n endThreshold = 0,\n style: styleProp,\n element = DefaultWindow,\n itemElement = \"div\",\n onEndReached,\n },\n ref\n ): ReactElement => {\n // Memoize element array\n const elements = useMemo(() => {\n const arr: ReactNode[] = [];\n Children.forEach(children, (e) => {\n if (isInvalidElement(e)) {\n return;\n }\n arr.push(e);\n });\n return arr;\n }, [children]);\n const elementsCount = elements.length;\n\n // https://github.com/facebook/react/issues/25191#issuecomment-1237456448\n const storeRef = useRef<VirtualStore | undefined>();\n const store =\n storeRef.current ||\n (storeRef.current = createVirtualStore(\n elementsCount,\n itemSizeProp,\n !!horizontalProp,\n !!rtlProp\n ));\n const startIndex = useSyncExternalStore(\n store._subscribe,\n store._getStartIndex\n );\n const endIndex = useSyncExternalStore(store._subscribe, store._getEndIndex);\n const jump = useSyncExternalStore(store._subscribe, store._getJump);\n const rootRef = useRef<HTMLDivElement>(null);\n const onEndReachedCalledIndex = useRef<number>(INITIAL_END_REACHED_INDEX);\n\n const [mountedIndexes, reset] = useState<Set<number>>(new Set<number>());\n const scrollerRef = useRef<Scroller>();\n const scroller =\n scrollerRef.current ||\n (scrollerRef.current = createScroller(store, () => {\n reset(new Set());\n }));\n\n // The elements length and cached items length are different just after element is added/removed.\n const count = min(elementsCount, store._getItemCount());\n\n // So update cache length. Updating state in render will cause warn so use useEffect for now.\n useIsomorphicLayoutEffect(() => {\n store._update({\n _type: UPDATE_CACHE_LENGTH,\n _length: elementsCount,\n });\n }, [elementsCount]);\n\n useIsomorphicLayoutEffect(() => scroller._initRoot(rootRef.current!), []);\n\n useIsomorphicLayoutEffect(() => {\n if (!jump.length) return;\n\n // Compensate scroll jump\n const scrollDirection = scroller._getScrollDirection();\n if (scrollDirection === SCROLL_UP) {\n const diff = jump.reduce((acc, [, j]) => acc + j, 0);\n if (diff) {\n scroller._updateScrollPosition(diff, true);\n }\n } else if (scrollDirection === SCROLL_MANUAL) {\n const isStartInView = startIndex === 0;\n const isEndInView = endIndex - (count - 1) === 0;\n const diff = jump.reduce((acc, [index, j]) => {\n if (index < startIndex) {\n // Keep start if scroll position is not stuck to the start\n if (!isStartInView) {\n acc += j;\n }\n } else {\n // Keep end if scroll position is stuck to the end\n if (!isStartInView && isEndInView) {\n acc += j;\n }\n }\n return acc;\n }, 0);\n if (diff) {\n scroller._updateScrollPosition(diff, true);\n }\n } else {\n // NOP\n }\n }, [jump]);\n\n useEffect(() => {\n if (!onEndReached) return;\n\n if (onEndReachedCalledIndex.current > count) {\n // Probably items have been refreshed, so reset index\n onEndReachedCalledIndex.current = INITIAL_END_REACHED_INDEX;\n }\n\n const endMargin = count - 1 - endIndex;\n if (\n endMargin <= endThreshold &&\n onEndReachedCalledIndex.current < count\n ) {\n onEndReachedCalledIndex.current = count;\n onEndReached();\n }\n }, [endIndex]);\n\n useImperativeHandle(\n ref,\n () => {\n return {\n get scrollOffset() {\n return scroller._getScrollPosition();\n },\n get scrollSize() {\n return scroller._getActualScrollSize();\n },\n scrollToIndex(index) {\n index = max(min(index, count - 1), 0);\n\n scroller._scrollTo(index, () => store._getItemOffset(index));\n },\n scrollToOffset(offset) {\n offset = max(offset, 0);\n\n scroller._scrollTo(\n store._getItemIndexForScrollTo(offset),\n () => offset\n );\n },\n };\n },\n [count]\n );\n\n const startIndexWithMargin = max(startIndex - overscan, 0);\n const endIndexWithMargin = min(endIndex + overscan, count - 1);\n const items = useMemo(() => {\n const res: ReactElement[] = [];\n for (let i = startIndexWithMargin; i <= endIndexWithMargin; i++) {\n // https://github.com/sergi/virtual-list/commit/8e7e06dc63568334c1ab809ea83c1be36572e9ed\n mountedIndexes.add(i);\n }\n mountedIndexes.forEach((i) => {\n const e = elements[i];\n res.push(\n <Item\n key={(e as { key?: ReactElement[\"key\"] })?.key || i}\n _scroller={scroller}\n _store={store}\n _index={i}\n _element={itemElement as \"div\"}\n _children={e}\n />\n );\n });\n return res;\n }, [elements, mountedIndexes, startIndexWithMargin, endIndexWithMargin]);\n\n return (\n <Window\n _ref={rootRef}\n _store={store}\n _element={element}\n _style={styleProp}\n _children={items}\n />\n );\n }\n);\n","import {\n findStartIndexWithOffset,\n resetCache,\n getItemSize,\n computeTotalSize,\n findEndIndex,\n computeStartOffset,\n Cache,\n UNCACHED,\n setItemSize,\n hasUnmeasuredItemsInRange,\n} from \"./cache\";\nimport type { Writeable } from \"./types\";\n\nexport const UPDATE_CACHE_LENGTH = 0;\nexport const UPDATE_ITEM_SIZES = 1;\nexport const UPDATE_VIEWPORT_SIZE = 2;\nexport const HANDLE_SCROLL = 3;\n\nexport type ScrollJump = Readonly<[index: number, sizeDiff: number][]>;\n\ntype State = {\n _startIndex: number;\n _viewportWidth: number;\n _viewportHeight: number;\n _cache: Cache;\n _jump: ScrollJump;\n};\n\ntype Actions =\n | { _type: typeof UPDATE_CACHE_LENGTH; _length: number }\n | {\n _type: typeof UPDATE_ITEM_SIZES;\n _entries: [index: number, size: number][];\n }\n | { _type: typeof UPDATE_VIEWPORT_SIZE; _width: number; _height: number }\n | { _type: typeof HANDLE_SCROLL; _offset: number };\n\nconst mutate = (state: State, action: Actions, itemSize: number): boolean => {\n switch (action._type) {\n case UPDATE_CACHE_LENGTH: {\n if (state._cache._length === action._length) return false;\n state._cache = resetCache(action._length, itemSize, state._cache);\n return true;\n }\n case UPDATE_ITEM_SIZES: {\n const updated = action._entries.filter(\n ([index, size]) => state._cache._sizes[index] !== size\n );\n // Skip if all items are cached and not updated\n if (!updated.length) {\n return false;\n }\n\n const jump: [index: number, sizeDiff: number][] = [];\n updated.forEach(([index, size]) => {\n jump.push([index, size - getItemSize(state._cache, index)]);\n setItemSize(state._cache as Writeable<Cache>, index, size);\n });\n state._jump = jump;\n return true;\n }\n case UPDATE_VIEWPORT_SIZE: {\n if (\n state._viewportWidth === action._width &&\n state._viewportHeight === action._height\n ) {\n return false;\n }\n state._viewportWidth = action._width;\n state._viewportHeight = action._height;\n return true;\n }\n case HANDLE_SCROLL: {\n const prevStartIndex = state._startIndex;\n const prevOffset = computeStartOffset(\n state._cache as Writeable<Cache>,\n prevStartIndex\n );\n if (prevOffset === action._offset) {\n return false;\n }\n return (\n (state._startIndex = findStartIndexWithOffset(\n state._cache,\n action._offset,\n prevStartIndex,\n prevOffset\n )) !== prevStartIndex\n );\n }\n }\n};\n\nexport type VirtualStore = {\n _getStartIndex(): number;\n _getEndIndex(): number;\n _isUnmeasuredItem(index: number): boolean;\n _hasUnmeasuredItemsInRange(startIndex: number): boolean;\n _getItemOffset(index: number): number;\n _getViewportSize(): number;\n _getScrollSize(): number;\n _getItemCount(): number;\n _getJump(): ScrollJump;\n _isHorizontal(): boolean;\n _isRtl(): boolean;\n _getItemIndexForScrollTo(offset: number): number;\n _waitForScrollDestinationItemsMeasured(): Promise<void>;\n _subscribe(cb: () => void): () => void;\n _update(action: Actions): void;\n};\n\nexport const createVirtualStore = (\n itemCount: number,\n itemSize: number,\n isHorizontal: boolean,\n isRtl: boolean\n): VirtualStore => {\n const subscribers = new Set<() => void>();\n const state: Readonly<State> = {\n _startIndex: 0,\n _viewportWidth: 0,\n _viewportHeight: 0,\n _cache: resetCache(itemCount, itemSize),\n _jump: [],\n };\n const getViewportSize = (): number =>\n isHorizontal ? state._viewportWidth : state._viewportHeight;\n\n let scrollToQueue: [() => void, () => void] | undefined;\n\n return {\n _getStartIndex() {\n return state._startIndex;\n },\n _getEndIndex() {\n return findEndIndex(state._cache, state._startIndex, getViewportSize());\n },\n _isUnmeasuredItem(index) {\n return state._cache._sizes[index] === UNCACHED;\n },\n _hasUnmeasuredItemsInRange(startIndex) {\n return hasUnmeasuredItemsInRange(\n state._cache,\n startIndex,\n findEndIndex(state._cache, startIndex, getViewportSize())\n );\n },\n _getItemOffset(index) {\n return computeStartOffset(state._cache as Writeable<Cache>, index);\n },\n _getViewportSize() {\n return getViewportSize();\n },\n _getScrollSize() {\n return computeTotalSize(state._cache as Writeable<Cache>);\n },\n _getItemCount() {\n return state._cache._length;\n },\n _getJump() {\n return state._jump;\n },\n _isHorizontal() {\n return isHorizontal;\n },\n _isRtl() {\n return isRtl;\n },\n _getItemIndexForScrollTo(offset) {\n return findStartIndexWithOffset(state._cache, offset, 0, 0);\n },\n _waitForScrollDestinationItemsMeasured() {\n if (scrollToQueue) {\n // Cancel waiting scrollTo\n scrollToQueue[1]();\n }\n // The measurement will be done asynchronously and the timing is not predictable so we use promise.\n // For example, ResizeObserver may not fire when window is not visible.\n return new Promise((resolve, reject) => {\n scrollToQueue = [\n () => {\n // HACK: It should be resolved in the next microtask that is after React's render\n Promise.resolve().then(() => {\n resolve();\n scrollToQueue = undefined;\n });\n },\n reject,\n ];\n });\n },\n _subscribe(cb) {\n subscribers.add(cb);\n return () => {\n subscribers.delete(cb);\n };\n },\n _update(action) {\n const mutated = mutate(state, action, itemSize);\n if (mutated) {\n subscribers.forEach((cb) => {\n cb();\n });\n if (scrollToQueue && action._type === UPDATE_ITEM_SIZES) {\n scrollToQueue[0]();\n }\n }\n },\n };\n};\n","import {\n HANDLE_SCROLL,\n UPDATE_ITEM_SIZES,\n UPDATE_VIEWPORT_SIZE,\n VirtualStore,\n} from \"./store\";\nimport { abs, debounce } from \"./utils\";\n\nexport const SCROLL_STOP = 0;\nexport const SCROLL_DOWN = 1;\nexport const SCROLL_UP = 2;\nexport const SCROLL_MANUAL = 3;\ntype ScrollDirection =\n | typeof SCROLL_STOP\n | typeof SCROLL_DOWN\n | typeof SCROLL_UP\n | typeof SCROLL_MANUAL;\n\nexport type Scroller = {\n _initRoot: (rootElement: HTMLElement) => () => void;\n _initItem: (itemElement: HTMLElement, index: number) => () => void;\n _getScrollPosition: () => number;\n _getScrollDirection: () => ScrollDirection;\n _getActualScrollSize: () => number;\n _updateScrollPosition: (offset: number, diff?: boolean) => void;\n _scrollTo: (index: number, getCurrentOffset: () => number) => void;\n};\n\nexport const createScroller = (\n store: VirtualStore,\n notifyStop: () => void\n): Scroller => {\n let prevOffset = -1;\n let scrollDirection: ScrollDirection = SCROLL_STOP;\n let resized = false;\n let isNegativeOffset: boolean | undefined;\n let rootElement: HTMLElement | undefined;\n let _ro: ResizeObserver | undefined;\n const isHorizontal = store._isHorizontal();\n const isRtl = store._isRtl();\n const scrollToKey = isHorizontal ? \"scrollLeft\" : \"scrollTop\";\n const mountedIndexes = new WeakMap<Element, number>();\n const getResizeObserver = (): ResizeObserver => {\n // Initialize ResizeObserver lazily for SSR\n return (\n _ro ||\n (_ro = new ResizeObserver((entries) => {\n // https://www.w3.org/TR/resize-observer/#intro\n const resizes: [index: number, size: number][] = [];\n for (const entry of entries) {\n if (entry.target === rootElement) {\n store._update({\n _type: UPDATE_VIEWPORT_SIZE,\n _width: entry.contentRect.width,\n _height: entry.contentRect.height,\n });\n } else {\n const index = mountedIndexes.get(entry.target);\n if (index != null) {\n resizes.push([\n index,\n entry.contentRect[isHorizontal ? \"width\" : \"height\"],\n ]);\n }\n }\n }\n\n if (resizes.length) {\n store._update({\n _type: UPDATE_ITEM_SIZES,\n _entries: resizes,\n });\n resized = true;\n }\n }))\n );\n };\n const getActualScrollSize = (): number => {\n if (!rootElement) return 0;\n // Use element's scrollHeight/scrollWidth instead of stored scrollSize.\n // This is because stored size may differ from the actual size, for example when a new item is added and not yet measured.\n return store._isHorizontal()\n ? rootElement.scrollWidth\n : rootElement.scrollHeight;\n };\n const updateScrollPosition = (offset: number, diff?: boolean) => {\n if (!rootElement) return;\n if (isRtl) {\n if (isNegativeOffset == null) {\n // Assume offset type in rtl direction.\n // The scroll position is negative in spec however its not in some browsers, for example Chrome earlier than v85.\n // https://github.com/othree/jquery.rtl-scroll-type\n const prev = rootElement[scrollToKey];\n rootElement[scrollToKey] = 1;\n isNegativeOffset = rootElement[scrollToKey] === 0;\n rootElement[scrollToKey] = prev;\n }\n if (isNegativeOffset) {\n offset *= -1;\n }\n }\n if (diff) {\n rootElement[scrollToKey] += offset;\n } else {\n rootElement[scrollToKey] = offset;\n scrollDirection = SCROLL_MANUAL;\n }\n };\n const scrollTo = async (index: number, getCurrentOffset: () => number) => {\n const getOffset = (): number => {\n let offset = getCurrentOffset();\n const scrollSize = getActualScrollSize();\n const viewportSize = store._getViewportSize();\n if (scrollSize - (offset + viewportSize) <= 0) {\n // Adjust if the offset is over the end, to get correct startIndex.\n offset = scrollSize - viewportSize;\n }\n return offset;\n };\n\n if (store._hasUnmeasuredItemsInRange(index)) {\n do {\n // In order to scroll to the correct position, mount the items and measure their sizes before scrolling.\n store._update({\n _type: HANDLE_SCROLL,\n _offset: getOffset(),\n });\n try {\n // Wait for the scroll destination items to be measured.\n await store._waitForScrollDestinationItemsMeasured();\n } catch (e) {\n // canceled\n return;\n }\n } while (store._hasUnmeasuredItemsInRange(index));\n\n // Scroll with the updated value\n updateScrollPosition(getOffset());\n } else {\n const offset = getOffset();\n updateScrollPosition(offset);\n // Sync viewport to scroll destination\n store._update({ _type: HANDLE_SCROLL, _offset: offset });\n }\n };\n\n return {\n _initRoot(root) {\n rootElement = root;\n const ro = getResizeObserver();\n\n const syncViewportToScrollPosition = () => {\n let offset = root[scrollToKey];\n if (isRtl) {\n // The scroll position may be negative value in rtl direction.\n // https://github.com/othree/jquery.rtl-scroll-type\n offset = abs(offset);\n }\n if (prevOffset === offset) {\n return;\n }\n // Skip scroll direction detection just after resizing because it may result in the opposite direction.\n // Scroll events are dispatched enough so it's ok to skip some of them.\n if (scrollDirection === SCROLL_STOP || !resized) {\n // Ignore until manual scrolling\n if (scrollDirection !== SCROLL_MANUAL) {\n scrollDirection = prevOffset > offset ? SCROLL_UP : SCROLL_DOWN;\n }\n } else {\n resized = false;\n }\n store._update({\n _type: HANDLE_SCROLL,\n _offset: (prevOffset = offset),\n });\n };\n\n const onScrollStopped = debounce(() => {\n // Check scroll position once just after scrolling stopped\n syncViewportToScrollPosition();\n scrollDirection = SCROLL_STOP;\n notifyStop();\n }, 300);\n\n const onScroll = () => {\n syncViewportToScrollPosition();\n onScrollStopped();\n };\n\n ro.observe(root);\n root.addEventListener(\"scroll\", onScroll);\n\n return () => {\n ro.disconnect();\n root.removeEventListener(\"scroll\", onScroll);\n onScrollStopped._cancel();\n };\n },\n _initItem(el, i) {\n const ro = getResizeObserver();\n mountedIndexes.set(el, i);\n ro.observe(el);\n return () => {\n mountedIndexes.delete(el);\n ro.unobserve(el);\n };\n },\n _getScrollPosition() {\n if (!rootElement) return 0;\n return rootElement[scrollToKey];\n },\n _getScrollDirection() {\n return scrollDirection;\n },\n _getActualScrollSize: getActualScrollSize,\n _updateScrollPosition: updateScrollPosition,\n _scrollTo: scrollTo,\n };\n};\n"],"names":["min","Math","max","abs","range","length","cb","Array","from","_","i","getItemSize","cache","index","size","_sizes","_defaultItemSize","findIndex","distance","sum","_length","h","findStartIndexWithOffset","offset","prevStartIndex","prevOffset","findEndIndex","computeStartOffset","_measuredOffsetIndex","_offsets","top","resetCache","itemSize","_a","useIsomorphicLayoutEffect","window","useLayoutEffect","useEffect","useSyncExternalStore","subscibe","getSnapShot","_useSyncExternalStore","Item","memo","_children","children","_scroller","scroller","_store","store","_index","_element","Element","ref","useRef","_subscribe","_getItemOffset","hide","_isUnmeasuredItem","_initItem","current","_jsx","style","useMemo","isHorizontal","_isHorizontal","isRtl","_isRtl","margin","padding","position","display","visibility","DefaultWindow","forwardRef","scrollSize","horizontal","rtl","jsx","width","height","minWidth","minHeight","Window","_ref","_style","_getScrollSize","viewportSize","_getViewportSize","clampedScrollSize","overflow","contain","List","itemSizeProp","overscan","horizontalProp","rtlProp","endThreshold","styleProp","element","itemElement","onEndReached","elements","arr","Children","forEach","e","isInvalidElement","push","elementsCount","storeRef","createVirtualStore","itemCount","subscribers","Set","state","_startIndex","_viewportWidth","_viewportHeight","_cache","_jump","getViewportSize","scrollToQueue","_getStartIndex","_getEndIndex","_hasUnmeasuredItemsInRange","startIndex","hasUnmeasuredItemsInRange","endIndex","lastIndex","computeTotalSize","_getItemCount","_getJump","_getItemIndexForScrollTo","_waitForScrollDestinationItemsMeasured","Promise","resolve","reject","then","undefined","add","delete","_update","action","mutate","_type","updated","_entries","filter","jump","setItemSize","_width","_height","_offset","rootRef","onEndReachedCalledIndex","mountedIndexes","reset","useState","scrollerRef","createScroller","notifyStop","isNegativeOffset","rootElement","_ro","scrollDirection","resized","scrollToKey","WeakMap","getResizeObserver","ResizeObserver","entries","resizes","entry","target","contentRect","get","getActualScrollSize","scrollWidth","scrollHeight","updateScrollPosition","diff","prev","_initRoot","root","ro","syncViewportToScrollPosition","onScrollStopped","debounce","id","cancel","clearTimeout","debouncedFn","setTimeout","_cancel","onScroll","observe","addEventListener","disconnect","removeEventListener","el","set","unobserve","_getScrollPosition","_getScrollDirection","_getActualScrollSize","_updateScrollPosition","_scrollTo","async","getCurrentOffset","getOffset","count","reduce","acc","j","isStartInView","isEndInView","useImperativeHandle","scrollOffset","scrollToIndex","scrollToOffset","startIndexWithMargin","endInd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AAS/F,IACtB,MAAMgG,EAAIJ,EAAS5F,GACnBsN,EAAIpH,KACF/C,MAACnB,GAECI,EAAWC,EACXC,EAAQC,EACRC,EAAQxC,EACRyC,EAAUiD,EACVxD,EAAW8D,IALLA,aAAC,EAADA,EAAqCuH,MAAOvN,GAOrD,IAEIsN,CAAG,GACT,CAAC1H,EAAUsD,EAAgBiE,EAAsBC,IAEpD,OACEjK,EAACiB,IAAAK,EACC,CAAAC,EAAMsE,EACN1G,EAAQC,EACRE,EAAUgD,EACVd,EAAQa,EACRtD,EAAWmL,GACX"}
|
package/lib/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as e}from"react/jsx-runtime";import{useLayoutEffect as t,useEffect as r,memo as n,useRef as o,useMemo as
|
|
1
|
+
import{jsx as e}from"react/jsx-runtime";import{useLayoutEffect as t,useEffect as r,memo as n,useRef as o,useMemo as l,forwardRef as i,Children as s,useState as c,useImperativeHandle as u}from"react";import{useSyncExternalStore as _}from"use-sync-external-store/shim/index.js";const d=Math.min,f=Math.max,a=Math.abs,h=(e,t)=>Array.from({length:e},((e,r)=>t(r))),m=(e,t)=>{const r=e.t[t];return-1===r?e.o:r},g=(e,t,r)=>{let n=0;if(r>=0)for(;t<e.l-1;){const o=m(e,t);if(n+=o,t++,n>=r){n-o/2>=r&&t--;break}}else for(;t>0;){t--;const o=m(e,t);if(n-=o,n<=r){n+o/2<r&&t++;break}}return d(f(t,0),e.l-1)},p=(e,t,r,n)=>g(e,r,t-n),y=g,S=(e,t)=>{if(!e.l)return 0;if(e.i>=t)return e.u[t];let r=e.u[e.i];for(let n=e.i;n<=t&&(e.u[n]=r,n!==t);n++)r+=m(e,n);return e.i=t,r},w=(e,t,r)=>{var n;return{o:t,l:e,i:null!==(n=r&&d(r.i,e-1))&&void 0!==n?n:0,t:h(e,(e=>{var t;return null!==(t=r&&r.t[e])&&void 0!==t?t:-1})),u:h(e,(e=>{var t;return 0===e?0:null!==(t=r&&r.u[e])&&void 0!==t?t:-1}))}},v="undefined"!=typeof window?t:r,I=(e,t)=>_(e,t,t),x=/*#__PURE__*/n((({_:t,h:r,m:n,g:i,p:s})=>{const c=o(null),u=I(n.S,(()=>n.v(i))),_=I(n.S,(()=>n.I(i)));return v((()=>r.T(c.current,i)),[i]),e(s,{ref:c,style:l((()=>{const e=n.M(),t=n.O(),r={margin:"0",padding:"0",position:"absolute",[e?"height":"width"]:"100%",[e?"top":t?"right":"left"]:0,[e?t?"right":"left":"top"]:u};return e&&(r.display="flex"),_&&(r.visibility="hidden"),r}),[u,_]),children:t})})),z=/*#__PURE__*/i((({children:t,style:r,scrollSize:n,horizontal:o,rtl:i},s)=>e("div",{ref:s,style:r,children:e("div",{style:l((()=>{const e=o?n:"100%",t=o?"100%":n;return{position:"absolute",top:0,[i?"right":"left"]:0,width:e,height:t,minWidth:e,minHeight:t}}),[n]),children:t})}))),b=({_:t,R:r,m:n,p:o,P:i})=>{const s=I(n.S,n.j),c=I(n.S,n.k),u=s>=c?s:c,_=n.M();return e(o,{ref:r,scrollSize:u,horizontal:_,rtl:n.O(),style:l((()=>({overflow:_?"auto hidden":"hidden auto",position:"relative",contain:"strict",width:"100%",height:"100%",padding:0,margin:0,...i})),[i]),children:t})},T=/*#__PURE__*/i((({children:t,itemSize:n=40,overscan:i=6,horizontal:_,rtl:h,endThreshold:g=0,style:T,element:M=z,itemElement:O="div",onEndReached:R},E)=>{const P=l((()=>{const e=[];return s.forEach(t,(t=>{(e=>null==e||"boolean"==typeof e)(t)||e.push(t)})),e}),[t]),j=P.length,k=o(),H=k.current||(k.current=((e,t,r,n)=>{const o=new Set,l={H:0,W:0,A:0,D:w(e,t),F:[]},i=()=>r?l.W:l.A;let s;return{U:()=>l.H,C:()=>y(l.D,l.H,i()),I:e=>-1===l.D.t[e],J:e=>((e,t,r)=>{for(let n=t;n<=r;n++)if(-1===e.t[n])return!0;return!1})(l.D,e,y(l.D,e,i())),v:e=>S(l.D,e),k:()=>i(),j:()=>(e=>{if(!e.l)return 0;const t=e.l-1;if(e.i>=t)return e.u[t]+m(e,t);let r=e.u[e.i];for(let n=e.i;n<=t;n++)e.u[n]=r,r+=m(e,n);return e.i=t,r})(l.D),L:()=>l.D.l,V:()=>l.F,M:()=>r,O:()=>n,q:e=>p(l.D,e,0,0),B:()=>(s&&s[1](),new Promise(((e,t)=>{s=[()=>{Promise.resolve().then((()=>{e(),s=void 0}))},t]}))),S:e=>(o.add(e),()=>{o.delete(e)}),G(e){((e,t,r)=>{switch(t.K){case 0:return e.D.l!==t.l&&(e.D=w(t.l,r,e.D),!0);case 1:{const r=t.N.filter((([t,r])=>e.D.t[t]!==r));if(!r.length)return!1;const n=[];return r.forEach((([t,r])=>{n.push([t,r-m(e.D,t)]),((e,t,r)=>{e.t[t]=r,e.i=d(t,e.i)})(e.D,t,r)})),e.F=n,!0}case 2:return(e.W!==t.X||e.A!==t.Y)&&(e.W=t.X,e.A=t.Y,!0);case 3:{const r=e.H,n=S(e.D,r);return n!==t.Z&&(e.H=p(e.D,t.Z,r,n))!==r}}})(l,e,t)&&(o.forEach((e=>{e()})),s&&1===e.K&&s[0]())}}})(j,n,!!_,!!h)),W=I(H.S,H.U),A=I(H.S,H.C),D=I(H.S,H.V),F=o(null),U=o(-1),[C,J]=c(new Set),L=o(),V=L.current||(L.current=((e,t)=>{let r,n,o,l=-1,i=0,s=!1;const c=e.M(),u=e.O(),_=c?"scrollLeft":"scrollTop",d=new WeakMap,f=()=>o||(o=new ResizeObserver((t=>{const r=[];for(const o of t)if(o.target===n)e.G({K:2,X:o.contentRect.width,Y:o.contentRect.height});else{const e=d.get(o.target);null!=e&&r.push([e,o.contentRect[c?"width":"height"]])}r.length&&(e.G({K:1,N:r}),s=!0)}))),h=()=>n?e.M()?n.scrollWidth:n.scrollHeight:0,m=(e,t)=>{if(n){if(u){if(null==r){const e=n[_];n[_]=1,r=0===n[_],n[_]=e}r&&(e*=-1)}t?n[_]+=e:(n[_]=e,i=3)}};return{$(r){n=r;const o=f(),c=()=>{let t=r[_];u&&(t=a(t)),l!==t&&(0!==i&&s?s=!1:3!==i&&(i=l>t?2:1),e.G({K:3,Z:l=t}))},d=(()=>{let e=null;const r=()=>{null!=e&&clearTimeout(e)},n=()=>{r(),e=setTimeout((()=>{e=null,c(),i=0,t()}),300)};return n.ee=r,n})(),h=()=>{c(),d()};return o.observe(r),r.addEventListener("scroll",h),()=>{o.disconnect(),r.removeEventListener("scroll",h),d.ee()}},T(e,t){const r=f();return d.set(e,t),r.observe(e),()=>{d.delete(e),r.unobserve(e)}},te:()=>n?n[_]:0,re:()=>i,ne:h,oe:m,le:async(t,r)=>{const n=()=>{let t=r();const n=h(),o=e.k();return n-(t+o)<=0&&(t=n-o),t};if(e.J(t)){do{e.G({K:3,Z:n()});try{await e.B()}catch(e){return}}while(e.J(t));m(n())}else{const t=n();m(t),e.G({K:3,Z:t})}}}})(H,(()=>{J(new Set)}))),q=d(j,H.L());v((()=>{H.G({K:0,l:j})}),[j]),v((()=>V.$(F.current)),[]),v((()=>{if(!D.length)return;const e=V.re();if(2===e){const e=D.reduce(((e,[,t])=>e+t),0);e&&V.oe(e,!0)}else if(3===e){const e=0===W,t=A-(q-1)==0,r=D.reduce(((r,[n,o])=>(n<W?e||(r+=o):!e&&t&&(r+=o),r)),0);r&&V.oe(r,!0)}}),[D]),r((()=>{R&&(U.current>q&&(U.current=-1),q-1-A<=g&&U.current<q&&(U.current=q,R()))}),[A]),u(E,(()=>({get scrollOffset(){return V.te()},get scrollSize(){return V.ne()},scrollToIndex(e){e=f(d(e,q-1),0),V.le(e,(()=>H.v(e)))},scrollToOffset(e){e=f(e,0),V.le(H.q(e),(()=>e))}})),[q]);const B=f(W-i,0),G=d(A+i,q-1),K=l((()=>{const t=[];for(let e=B;e<=G;e++)C.add(e);return C.forEach((r=>{const n=P[r];t.push(e(x,{h:V,m:H,g:r,p:O,_:n},(null==n?void 0:n.key)||r))})),t}),[P,C,B,G]);return e(b,{R:F,m:H,p:M,P:T,_:K})}));export{T as List};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/lib/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/src/core/utils.ts","../src/src/core/cache.ts","../src/src/react/useIsomorphicLayoutEffect.ts","../src/src/react/useSyncExternalStore.ts","../src/src/react/List.tsx","../src/src/core/store.ts","../src/src/core/scroller.ts"],"sourcesContent":["export const min = Math.min;\nexport const max = Math.max;\nexport const abs = Math.abs;\n\nexport const range = <T>(length: number, cb: (i: number) => T): T[] =>\n Array.from({ length }, (_, i) => cb(i));\n\nexport const debounce = <T extends (...args: any[]) => void>(\n fn: T,\n ms: number\n) => {\n let id: NodeJS.Timeout | null = null;\n\n const cancel = () => {\n if (id != null) {\n clearTimeout(id);\n }\n };\n const debouncedFn = () => {\n cancel();\n id = setTimeout(() => {\n id = null;\n fn();\n }, ms);\n };\n debouncedFn._cancel = cancel;\n return debouncedFn;\n};\n","import type { DeepReadonly, Writeable } from \"./types\";\nimport { max, min, range } from \"./utils\";\n\nexport const UNCACHED = -1;\n\nexport type Cache = DeepReadonly<{\n _defaultItemSize: number;\n _length: number;\n _sizes: number[];\n _measuredOffsetIndex: number;\n _offsets: number[];\n}>;\n\nexport const getItemSize = (cache: Cache, index: number): number => {\n const size = cache._sizes[index]!;\n return size === UNCACHED ? cache._defaultItemSize : size;\n};\n\nexport const setItemSize = (\n cache: Writeable<Cache>,\n index: number,\n size: number\n) => {\n cache._sizes[index] = size;\n // mark as dirty\n cache._measuredOffsetIndex = min(index, cache._measuredOffsetIndex);\n};\n\nexport const computeTotalSize = (cache: Writeable<Cache>): number => {\n if (!cache._length) return 0;\n const lastIndex = cache._length - 1;\n if (cache._measuredOffsetIndex >= lastIndex) {\n return cache._offsets[lastIndex]! + getItemSize(cache, lastIndex);\n }\n\n let top = cache._offsets[cache._measuredOffsetIndex]!;\n for (let i = cache._measuredOffsetIndex; i <= lastIndex; i++) {\n cache._offsets[i] = top;\n top += getItemSize(cache, i);\n }\n\n cache._measuredOffsetIndex = lastIndex;\n return top;\n};\n\nconst findIndex = (cache: Cache, i: number, distance: number): number => {\n let sum = 0;\n if (distance >= 0) {\n // search forward\n while (i < cache._length - 1) {\n const h = getItemSize(cache, i);\n sum += h;\n i++;\n if (sum >= distance) {\n if (sum - h / 2 >= distance) {\n i--;\n }\n break;\n }\n }\n } else {\n // search backward\n while (i > 0) {\n i--;\n const h = getItemSize(cache, i);\n sum -= h;\n if (sum <= distance) {\n if (sum + h / 2 < distance) {\n i++;\n }\n break;\n }\n }\n }\n\n return min(max(i, 0), cache._length - 1);\n};\n\nexport const findStartIndexWithOffset = (\n cache: Cache,\n offset: number,\n prevStartIndex: number,\n prevOffset: number\n): number => {\n return findIndex(cache, prevStartIndex, offset - prevOffset);\n};\n\nexport const findEndIndex = findIndex;\n\nexport const hasUnmeasuredItemsInRange = (\n cache: Cache,\n startIndex: number,\n endIndex: number\n): boolean => {\n for (let i = startIndex; i <= endIndex; i++) {\n if (cache._sizes[i] === UNCACHED) {\n return true;\n }\n }\n return false;\n};\n\nexport const computeStartOffset = (\n cache: Writeable<Cache>,\n index: number\n): number => {\n if (!cache._length) return 0;\n if (cache._measuredOffsetIndex >= index) {\n return cache._offsets[index]!;\n }\n\n let top = cache._offsets[cache._measuredOffsetIndex]!;\n for (let i = cache._measuredOffsetIndex; i <= index; i++) {\n cache._offsets[i] = top;\n if (i === index) {\n break;\n }\n top += getItemSize(cache, i);\n }\n cache._measuredOffsetIndex = index;\n return top;\n};\n\nexport const resetCache = (\n length: number,\n itemSize: number,\n cache?: Cache\n): Cache => {\n return {\n _defaultItemSize: itemSize,\n _length: length,\n _measuredOffsetIndex:\n (cache && min(cache._measuredOffsetIndex, length - 1)) ?? 0,\n _sizes: range(length, (i) => (cache && cache._sizes[i]) ?? UNCACHED),\n _offsets: range(length, (i) =>\n i === 0\n ? 0 // first offset must be 0\n : (cache && cache._offsets[i]) ?? UNCACHED\n ),\n };\n};\n","import { useEffect, useLayoutEffect } from \"react\";\n\n// https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85\nexport const useIsomorphicLayoutEffect =\n typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n","import { useSyncExternalStore as _useSyncExternalStore } from \"use-sync-external-store/shim\";\n\nexport const useSyncExternalStore = <T>(\n subscibe: (onStoreChange: () => void) => () => void,\n getSnapShot: () => T\n): T => {\n return _useSyncExternalStore(subscibe, getSnapShot, getSnapShot);\n};\n","import {\n Children,\n memo,\n useRef,\n useMemo,\n CSSProperties,\n ReactElement,\n forwardRef,\n useImperativeHandle,\n ReactNode,\n useEffect,\n RefObject,\n} from \"react\";\nimport {\n HANDLE_SCROLL,\n UPDATE_CACHE_LENGTH,\n VirtualStore,\n createVirtualStore,\n} from \"../core/store\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore\";\nimport { max, min } from \"../core/utils\";\nimport {\n createScroller,\n Scroller,\n SCROLL_MANUAL,\n SCROLL_UP,\n} from \"../core/scroller\";\n\nconst INITIAL_END_REACHED_INDEX = -1;\n\ntype ItemProps = {\n _children: ReactNode;\n _handle: Scroller;\n _store: VirtualStore;\n _index: number;\n _element: \"div\";\n _isHorizontal: boolean | undefined;\n _isRtl: boolean | undefined;\n};\n\nconst Item = memo(\n ({\n _children: children,\n _handle: handle,\n _store: store,\n _index: index,\n _element: Element,\n _isHorizontal: isHorizontal,\n _isRtl: isRtl,\n }: ItemProps): ReactElement => {\n const ref = useRef<HTMLDivElement>(null);\n\n const offset = useSyncExternalStore(store._subscribe, () =>\n store._getItemOffset(index)\n );\n const hide = useSyncExternalStore(store._subscribe, () =>\n store._isUnmeasuredItem(index)\n );\n\n // The index may be changed if elements are inserted to or removed from the start of props.children\n useIsomorphicLayoutEffect(\n () => handle._initItem(ref.current!, index),\n [index]\n );\n\n return (\n <Element\n ref={ref}\n style={useMemo<CSSProperties>(() => {\n const style: CSSProperties = {\n margin: \"0\",\n padding: \"0\",\n position: \"absolute\",\n [isHorizontal ? \"height\" : \"width\"]: \"100%\",\n [isHorizontal ? \"top\" : isRtl ? \"right\" : \"left\"]: 0,\n [isHorizontal ? (isRtl ? \"right\" : \"left\") : \"top\"]: offset,\n // willChange: \"transform\",\n };\n if (isHorizontal) {\n style.display = \"flex\";\n }\n if (hide) {\n style.visibility = \"hidden\";\n }\n return style;\n }, [offset, isHorizontal, isRtl, hide])}\n >\n {children}\n </Element>\n );\n }\n);\n\nconst isInvalidElement = <T extends ReactNode>(\n e: T\n): e is Extract<T, null | undefined | boolean> =>\n e == null || typeof e === \"boolean\";\n\nconst Window = ({\n _children: children,\n _ref: ref,\n _element: Element,\n _style: style,\n _isHorizontal: isHorizontal,\n}: {\n _children: ReactNode;\n _ref: RefObject<HTMLDivElement>;\n _element: \"div\";\n _style: CSSProperties | undefined;\n _isHorizontal: boolean | undefined;\n}) => {\n return (\n <Element\n ref={ref}\n style={useMemo<CSSProperties>(\n () => ({\n overflow: isHorizontal ? \"auto hidden\" : \"hidden auto\",\n position: \"relative\",\n contain: \"strict\",\n // transform: \"translate3d(0px, 0px, 0px)\",\n // willChange: \"scroll-position\",\n // backfaceVisibility: \"hidden\",\n width: \"100%\",\n height: \"100%\",\n padding: 0,\n margin: 0,\n ...style,\n }),\n [isHorizontal, style]\n )}\n >\n {children}\n </Element>\n );\n};\n\nconst Inner = ({\n _children: children,\n _store: store,\n _element: Element,\n _style: style,\n _isHorizontal: isHorizontal,\n _isRtl: isRtl,\n}: {\n _children: ReactNode;\n _store: VirtualStore;\n _element: \"div\";\n _style: CSSProperties | undefined;\n _isHorizontal: boolean | undefined;\n _isRtl: boolean | undefined;\n}) => {\n const scrollSize = useSyncExternalStore(\n store._subscribe,\n store._getScrollSize\n );\n const viewportSize = useSyncExternalStore(\n store._subscribe,\n store._getViewportSize\n );\n\n return (\n <Element\n style={useMemo<CSSProperties>(() => {\n const clampedScrollSize =\n scrollSize >= viewportSize ? scrollSize : viewportSize;\n const width = isHorizontal ? clampedScrollSize : \"100%\";\n const height = isHorizontal ? \"100%\" : clampedScrollSize;\n return {\n position: \"absolute\",\n top: 0,\n [isRtl ? \"right\" : \"left\"]: 0,\n width,\n height,\n minWidth: width,\n minHeight: height,\n ...style,\n };\n }, [scrollSize, viewportSize, style, isHorizontal, isRtl])}\n >\n {children}\n </Element>\n );\n};\n\nexport interface CustomComponentProps {\n style: CSSProperties;\n children: ReactNode;\n}\n\nexport type CustomComponent = React.ForwardRefExoticComponent<\n React.PropsWithoutRef<CustomComponentProps> & React.RefAttributes<any>\n>;\n\ntype CustomElementType = keyof JSX.IntrinsicElements | CustomComponent;\n\n/**\n * Methods of {@link List}.\n */\nexport interface ListHandle {\n /**\n * Get current scrollTop or scrollLeft.\n */\n scrollOffset: number;\n /**\n * Get current scrollHeight or scrollWidth.\n */\n scrollSize: number;\n /**\n * Scroll to the item specified by index.\n * @param index index of item\n */\n scrollToIndex(index: number): void;\n /**\n * Scroll to the item specified by offset.\n * @param offset offset from start\n */\n scrollToOffset(offset: number): void;\n}\n\n/**\n * Props of {@link List}.\n */\nexport interface ListProps {\n /**\n * Elements rendered by this component.\n */\n children: ReactNode;\n /**\n * Item size hint for unmeasured items. It's recommended to specify this prop if item sizes are fixed and known, or much larger than the defaultValue. It will help to reduce scroll jump when items are measured.\n * @defaultValue 40\n */\n itemSize?: number;\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 6\n */\n overscan?: number;\n /**\n * If true, rendered as a horizontally scrollable list. Otherwise rendered as a vertically scrollable list.\n */\n horizontal?: boolean;\n /**\n * You have to set true if you use this component under `direction: rtl` style.\n */\n rtl?: boolean;\n /**\n * Number of items to be the margin from the end of the scroll. See also {@link onEndReached}.\n * @defaultValue 0\n */\n endThreshold?: number;\n /**\n * Inline style prop to override style of scrollable element.\n */\n style?: CSSProperties;\n /**\n * Inline style prop to override style of inner element.\n */\n innerStyle?: CSSProperties;\n /**\n * Customized element type for scrollable element.\n * @defaultValue \"div\"\n */\n element?: CustomElementType;\n /**\n * Customized element type for inner element.\n * @defaultValue \"div\"\n */\n innerElement?: CustomElementType;\n /**\n * Customized element type for item element.\n * @defaultValue \"div\"\n */\n itemElement?: CustomElementType;\n /**\n * Callback invoked when scrolling reached to the end. The margin from the end is specified by {@link endThreshold}.\n */\n onEndReached?: () => void;\n}\n\n/**\n * Virtualized list component. See {@link ListProps} and {@link ListHandle}.\n */\nexport const List = forwardRef<ListHandle, ListProps>(\n (\n {\n children,\n itemSize = 40,\n overscan = 6,\n horizontal: isHorizontal,\n rtl: isRtl,\n endThreshold = 0,\n style: styleProp,\n innerStyle: innerStyleProp,\n element = \"div\",\n innerElement = \"div\",\n itemElement = \"div\",\n onEndReached,\n },\n ref\n ): ReactElement => {\n // memoize element count\n const rawCount = useMemo(() => {\n let i = 0;\n Children.forEach(children, (e) => {\n if (isInvalidElement(e)) {\n return;\n }\n i++;\n });\n return i;\n }, [children]);\n\n // https://github.com/facebook/react/issues/25191#issuecomment-1237456448\n const storeRef = useRef<VirtualStore | undefined>();\n const store =\n storeRef.current ||\n (storeRef.current = createVirtualStore(rawCount, itemSize, isHorizontal));\n const startIndex = useSyncExternalStore(\n store._subscribe,\n store._getStartIndex\n );\n const endIndex = useSyncExternalStore(store._subscribe, store._getEndIndex);\n const jump = useSyncExternalStore(store._subscribe, store._getJump);\n const scrollRef = useRef<HTMLDivElement>(null);\n const onEndReachedCalledIndex = useRef<number>(INITIAL_END_REACHED_INDEX);\n\n const handleRef = useRef<Scroller>();\n const handle =\n handleRef.current ||\n (handleRef.current = createScroller(store, isHorizontal, isRtl));\n\n // The elements length and cached items length are different just after element is added/removed.\n const count = min(rawCount, store._getItemCount());\n\n const startIndexWithMargin = max(startIndex - overscan, 0);\n const endIndexWithMargin = min(endIndex + overscan, count - 1);\n\n // So update cache length. Updating state in render will cause warn so use useEffect for now.\n useIsomorphicLayoutEffect(() => {\n store._update({\n _type: UPDATE_CACHE_LENGTH,\n _length: rawCount,\n });\n }, [rawCount]);\n\n useIsomorphicLayoutEffect(() => handle._initRoot(scrollRef.current!), []);\n\n useIsomorphicLayoutEffect(() => {\n if (!jump.length) return;\n\n // Compensate scroll jump\n const scrollDirection = handle._getScrollDirection();\n if (scrollDirection === SCROLL_UP) {\n const diff = jump.reduce((acc, [, j]) => acc + j, 0);\n if (diff) {\n handle._updateScrollPosition(diff, true);\n }\n } else if (scrollDirection === SCROLL_MANUAL) {\n const isStartInView = startIndex === 0;\n const isEndInView = endIndex - (count - 1) === 0;\n const diff = jump.reduce((acc, [index, j]) => {\n if (index < startIndex) {\n // Keep start if scroll position is not stuck to the start\n if (!isStartInView) {\n acc += j;\n }\n } else {\n // Keep end if scroll position is stuck to the end\n if (!isStartInView && isEndInView) {\n acc += j;\n }\n }\n return acc;\n }, 0);\n if (diff) {\n handle._updateScrollPosition(diff, true);\n }\n } else {\n // NOP\n }\n }, [jump]);\n\n useEffect(() => {\n if (!onEndReached) return;\n\n if (onEndReachedCalledIndex.current > count) {\n // Probably items have been refreshed, so reset index\n onEndReachedCalledIndex.current = INITIAL_END_REACHED_INDEX;\n }\n\n const endMargin = count - 1 - endIndex;\n if (\n endMargin <= endThreshold &&\n onEndReachedCalledIndex.current < count\n ) {\n onEndReachedCalledIndex.current = count;\n onEndReached();\n }\n }, [endIndex]);\n\n useImperativeHandle(\n ref,\n () => {\n const getScrollSize = (): number => {\n const el = scrollRef.current;\n if (!el) return 0;\n // Use element's scrollHeight/scrollWidth instead of stored scrollSize.\n // This is because stored size may differ from the actual size, for example when a new item is added and not yet measured.\n return isHorizontal ? el.scrollWidth : el.scrollHeight;\n };\n const scrollTo = async (\n index: number,\n getCurrentOffset: () => number\n ) => {\n const getOffset = (): number => {\n let offset = getCurrentOffset();\n const scrollSize = getScrollSize();\n const viewportSize = store._getViewportSize();\n if (scrollSize - (offset + viewportSize) <= 0) {\n // Adjust if the offset is over the end, to get correct startIndex.\n offset = scrollSize - viewportSize;\n }\n return offset;\n };\n\n if (store._hasUnmeasuredItemsInRange(index)) {\n do {\n // In order to scroll to the correct position, mount the items and measure their sizes before scrolling.\n store._update({\n _type: HANDLE_SCROLL,\n _offset: getOffset(),\n });\n try {\n // Wait for the scroll destination items to be measured.\n await store._waitForScrollDestinationItemsMeasured();\n } catch (e) {\n // canceled\n return;\n }\n } while (store._hasUnmeasuredItemsInRange(index));\n\n // Scroll with the updated value\n handle._updateScrollPosition(getOffset());\n } else {\n const offset = getOffset();\n handle._updateScrollPosition(offset);\n // Sync viewport to scroll destination\n store._update({ _type: HANDLE_SCROLL, _offset: offset });\n }\n };\n\n return {\n get scrollOffset() {\n return handle._getScrollPosition();\n },\n get scrollSize() {\n return getScrollSize();\n },\n scrollToIndex(index) {\n index = max(min(index, count - 1), 0);\n\n scrollTo(index, () => store._getItemOffset(index));\n },\n scrollToOffset(offset) {\n offset = max(offset, 0);\n\n scrollTo(store._getItemIndexForScrollTo(offset), () => offset);\n },\n };\n },\n [count]\n );\n\n const items = useMemo(() => {\n let i = -1;\n const elements: ReactElement[] = [];\n Children.forEach(children, (e) => {\n if (isInvalidElement(e)) {\n return;\n }\n i++;\n if (i < startIndexWithMargin || i > endIndexWithMargin) {\n return;\n }\n elements.push(\n <Item\n key={(e as { key?: ReactElement[\"key\"] })?.key || i}\n _handle={handle}\n _store={store}\n _index={i}\n _element={itemElement as \"div\"}\n _isHorizontal={isHorizontal}\n _isRtl={isRtl}\n _children={e}\n />\n );\n });\n return elements;\n }, [children, startIndexWithMargin, endIndexWithMargin]);\n\n return (\n <Window\n _ref={scrollRef}\n _isHorizontal={isHorizontal}\n _element={element as \"div\"}\n _style={styleProp}\n _children={\n <Inner\n _store={store}\n _element={innerElement as \"div\"}\n _style={innerStyleProp}\n _isHorizontal={isHorizontal}\n _isRtl={isRtl}\n _children={items}\n />\n }\n />\n );\n }\n);\n","import {\n findStartIndexWithOffset,\n resetCache,\n getItemSize,\n computeTotalSize,\n findEndIndex,\n computeStartOffset,\n Cache,\n UNCACHED,\n setItemSize,\n hasUnmeasuredItemsInRange,\n} from \"./cache\";\nimport type { Writeable } from \"./types\";\n\nexport const UPDATE_CACHE_LENGTH = 0;\nexport const UPDATE_ITEM_SIZES = 1;\nexport const UPDATE_VIEWPORT_SIZE = 2;\nexport const HANDLE_SCROLL = 3;\n\nexport type ScrollJump = Readonly<[index: number, sizeDiff: number][]>;\n\ntype State = {\n _startIndex: number;\n _viewportWidth: number;\n _viewportHeight: number;\n _cache: Cache;\n _jump: ScrollJump;\n};\n\ntype Actions =\n | { _type: typeof UPDATE_CACHE_LENGTH; _length: number }\n | {\n _type: typeof UPDATE_ITEM_SIZES;\n _entries: [index: number, size: number][];\n }\n | { _type: typeof UPDATE_VIEWPORT_SIZE; _width: number; _height: number }\n | { _type: typeof HANDLE_SCROLL; _offset: number };\n\nconst mutate = (state: State, action: Actions, itemSize: number): boolean => {\n switch (action._type) {\n case UPDATE_CACHE_LENGTH: {\n if (state._cache._length === action._length) return false;\n state._cache = resetCache(action._length, itemSize, state._cache);\n return true;\n }\n case UPDATE_ITEM_SIZES: {\n const updated = action._entries.filter(\n ([index, size]) => state._cache._sizes[index] !== size\n );\n // Skip if all items are cached and not updated\n if (!updated.length) {\n return false;\n }\n\n const jump: [index: number, sizeDiff: number][] = [];\n updated.forEach(([index, size]) => {\n jump.push([index, size - getItemSize(state._cache, index)]);\n setItemSize(state._cache as Writeable<Cache>, index, size);\n });\n state._jump = jump;\n return true;\n }\n case UPDATE_VIEWPORT_SIZE: {\n if (\n state._viewportWidth === action._width &&\n state._viewportHeight === action._height\n ) {\n return false;\n }\n state._viewportWidth = action._width;\n state._viewportHeight = action._height;\n return true;\n }\n case HANDLE_SCROLL: {\n const prevStartIndex = state._startIndex;\n const prevOffset = computeStartOffset(\n state._cache as Writeable<Cache>,\n prevStartIndex\n );\n if (prevOffset === action._offset) {\n return false;\n }\n return (\n (state._startIndex = findStartIndexWithOffset(\n state._cache,\n action._offset,\n prevStartIndex,\n prevOffset\n )) !== prevStartIndex\n );\n }\n }\n};\n\nexport type VirtualStore = {\n _getStartIndex(): number;\n _getEndIndex(): number;\n _isUnmeasuredItem(index: number): boolean;\n _hasUnmeasuredItemsInRange(startIndex: number): boolean;\n _getItemOffset(index: number): number;\n _getViewportSize(): number;\n _getScrollSize(): number;\n _getItemCount(): number;\n _getJump(): ScrollJump;\n _getItemIndexForScrollTo(offset: number): number;\n _waitForScrollDestinationItemsMeasured(): Promise<void>;\n _subscribe(cb: () => void): () => void;\n _update(action: Actions): void;\n};\n\nexport const createVirtualStore = (\n itemCount: number,\n itemSize: number,\n isHorizontal: boolean | undefined\n): VirtualStore => {\n const subscribers = new Set<() => void>();\n const state: Readonly<State> = {\n _startIndex: 0,\n _viewportWidth: 0,\n _viewportHeight: 0,\n _cache: resetCache(itemCount, itemSize),\n _jump: [],\n };\n const getViewportSize = (): number =>\n isHorizontal ? state._viewportWidth : state._viewportHeight;\n\n let scrollToQueue: [() => void, () => void] | undefined;\n\n return {\n _getStartIndex() {\n return state._startIndex;\n },\n _getEndIndex() {\n return findEndIndex(state._cache, state._startIndex, getViewportSize());\n },\n _isUnmeasuredItem(index) {\n return state._cache._sizes[index] === UNCACHED;\n },\n _hasUnmeasuredItemsInRange(startIndex) {\n return hasUnmeasuredItemsInRange(\n state._cache,\n startIndex,\n findEndIndex(state._cache, startIndex, getViewportSize())\n );\n },\n _getItemOffset(index) {\n return computeStartOffset(state._cache as Writeable<Cache>, index);\n },\n _getViewportSize() {\n return getViewportSize();\n },\n _getScrollSize() {\n return computeTotalSize(state._cache as Writeable<Cache>);\n },\n _getItemCount() {\n return state._cache._length;\n },\n _getJump() {\n return state._jump;\n },\n _getItemIndexForScrollTo(offset) {\n return findStartIndexWithOffset(state._cache, offset, 0, 0);\n },\n _waitForScrollDestinationItemsMeasured() {\n if (scrollToQueue) {\n // Cancel waiting scrollTo\n scrollToQueue[1]();\n }\n // The measurement will be done asynchronously and the timing is not predictable so we use promise.\n // For example, ResizeObserver may not fire when window is not visible.\n return new Promise((resolve, reject) => {\n scrollToQueue = [\n () => {\n // HACK: It should be resolved in the next microtask that is after React's render\n Promise.resolve().then(() => {\n resolve();\n scrollToQueue = undefined;\n });\n },\n reject,\n ];\n });\n },\n _subscribe(cb) {\n subscribers.add(cb);\n return () => {\n subscribers.delete(cb);\n };\n },\n _update(action) {\n const mutated = mutate(state, action, itemSize);\n if (mutated) {\n subscribers.forEach((cb) => {\n cb();\n });\n if (scrollToQueue && action._type === UPDATE_ITEM_SIZES) {\n scrollToQueue[0]();\n }\n }\n },\n };\n};\n","import {\n HANDLE_SCROLL,\n UPDATE_ITEM_SIZES,\n UPDATE_VIEWPORT_SIZE,\n VirtualStore,\n} from \"./store\";\nimport { abs, debounce } from \"./utils\";\n\nexport const SCROLL_STOP = 0;\nexport const SCROLL_DOWN = 1;\nexport const SCROLL_UP = 2;\nexport const SCROLL_MANUAL = 3;\ntype ScrollDirection =\n | typeof SCROLL_STOP\n | typeof SCROLL_DOWN\n | typeof SCROLL_UP\n | typeof SCROLL_MANUAL;\n\nexport type Scroller = {\n _initRoot: (rootElement: HTMLElement) => () => void;\n _initItem: (itemElement: HTMLElement, index: number) => () => void;\n _getScrollPosition: () => number;\n _getScrollDirection: () => ScrollDirection;\n _updateScrollPosition: (offset: number, diff?: boolean) => void;\n};\n\nexport const createScroller = (\n store: VirtualStore,\n isHorizontal: boolean | undefined,\n isRtl: boolean | undefined\n): Scroller => {\n let prevOffset = -1;\n let scrollDirection: ScrollDirection = SCROLL_STOP;\n let resized = false;\n let isNegativeOffset: boolean | undefined;\n let rootElement: HTMLElement | undefined;\n let _ro: ResizeObserver | undefined;\n const scrollToKey = isHorizontal ? \"scrollLeft\" : \"scrollTop\";\n const mountedIndexes = new WeakMap<Element, number>();\n const getResizeObserver = (): ResizeObserver => {\n // Initialize ResizeObserver lazily for SSR\n return (\n _ro ||\n (_ro = new ResizeObserver((entries) => {\n // https://www.w3.org/TR/resize-observer/#intro\n const resizes: [index: number, size: number][] = [];\n for (const entry of entries) {\n if (entry.target === rootElement) {\n store._update({\n _type: UPDATE_VIEWPORT_SIZE,\n _width: entry.contentRect.width,\n _height: entry.contentRect.height,\n });\n } else {\n const index = mountedIndexes.get(entry.target);\n if (index != null) {\n resizes.push([\n index,\n entry.contentRect[isHorizontal ? \"width\" : \"height\"],\n ]);\n }\n }\n }\n\n if (resizes.length) {\n store._update({\n _type: UPDATE_ITEM_SIZES,\n _entries: resizes,\n });\n resized = true;\n }\n }))\n );\n };\n\n return {\n _initRoot(root) {\n rootElement = root;\n const ro = getResizeObserver();\n\n const syncViewportToScrollPosition = () => {\n let offset = root[scrollToKey];\n if (isRtl) {\n // The scroll position may be negative value in rtl direction.\n // https://github.com/othree/jquery.rtl-scroll-type\n offset = abs(offset);\n }\n if (prevOffset === offset) {\n return;\n }\n // Skip scroll direction detection just after resizing because it may result in the opposite direction.\n // Scroll events are dispatched enough so it's ok to skip some of them.\n if (scrollDirection === SCROLL_STOP || !resized) {\n // Ignore until manual scrolling\n if (scrollDirection !== SCROLL_MANUAL) {\n scrollDirection = prevOffset > offset ? SCROLL_UP : SCROLL_DOWN;\n }\n } else {\n resized = false;\n }\n store._update({\n _type: HANDLE_SCROLL,\n _offset: (prevOffset = offset),\n });\n };\n\n const onScrollStopped = debounce(() => {\n // Check scroll position once just after scrolling stopped\n syncViewportToScrollPosition();\n scrollDirection = SCROLL_STOP;\n }, 300);\n\n const onScroll = () => {\n syncViewportToScrollPosition();\n onScrollStopped();\n };\n\n ro.observe(root);\n root.addEventListener(\"scroll\", onScroll);\n\n return () => {\n ro.disconnect();\n root.removeEventListener(\"scroll\", onScroll);\n onScrollStopped._cancel();\n };\n },\n _initItem(el, i) {\n const ro = getResizeObserver();\n mountedIndexes.set(el, i);\n ro.observe(el);\n return () => {\n mountedIndexes.delete(el);\n ro.unobserve(el);\n };\n },\n _getScrollPosition() {\n if (!rootElement) return 0;\n return rootElement[scrollToKey];\n },\n _getScrollDirection() {\n return scrollDirection;\n },\n _updateScrollPosition(offset, diff) {\n if (!rootElement) return;\n if (isRtl) {\n if (isNegativeOffset == null) {\n // Assume offset type in rtl direction.\n // The scroll position is negative in spec however its not in some browsers, for example Chrome earlier than v85.\n // https://github.com/othree/jquery.rtl-scroll-type\n const prev = rootElement[scrollToKey];\n rootElement[scrollToKey] = 1;\n isNegativeOffset = rootElement[scrollToKey] === 0;\n rootElement[scrollToKey] = prev;\n }\n if (isNegativeOffset) {\n offset *= -1;\n }\n }\n if (diff) {\n rootElement[scrollToKey] += offset;\n } else {\n rootElement[scrollToKey] = offset;\n scrollDirection = SCROLL_MANUAL;\n }\n },\n };\n};\n"],"names":["min","Math","max","abs","range","length","cb","Array","from","_","i","getItemSize","cache","index","size","_sizes","_defaultItemSize","findIndex","distance","sum","_length","h","findStartIndexWithOffset","offset","prevStartIndex","prevOffset","findEndIndex","computeStartOffset","_measuredOffsetIndex","_offsets","top","resetCache","itemSize","_a","useIsomorphicLayoutEffect","window","useLayoutEffect","useEffect","useSyncExternalStore","subscibe","getSnapShot","_useSyncExternalStore","Item","memo","_children","children","_handle","handle","_store","store","_index","_element","Element","_isHorizontal","isHorizontal","_isRtl","isRtl","ref","useRef","_subscribe","_getItemOffset","hide","_isUnmeasuredItem","_initItem","current","_jsx","style","useMemo","margin","padding","position","display","visibility","isInvalidElement","e","Window","_ref","_style","overflow","contain","width","height","Inner","scrollSize","_getScrollSize","viewportSize","_getViewportSize","clampedScrollSize","minWidth","minHeight","List","forwardRef","overscan","horizontal","rtl","endThreshold","styleProp","innerStyle","innerStyleProp","element","innerElement","itemElement","onEndReached","rawCount","Children","forEach","storeRef","createVirtualStore","itemCount","subscribers","Set","state","_startIndex","_viewportWidth","_viewportHeight","_cache","_jump","getViewportSize","scrollToQueue","_getStartIndex","_getEndIndex","_hasUnmeasuredItemsInRange","startIndex","hasUnmeasuredItemsInRange","endIndex","lastIndex","computeTotalSize","_getItemCount","_getJump","_getItemIndexForScrollTo","_waitForScrollDestinationItemsMeasured","Promise","resolve","reject","then","undefined","add","delete","_update","action","mutate","_type","updated","_entries","filter","jump","push","setItemSize","_width","_height","_offset","scrollRef","onEndReachedCalledIndex","handleRef","createScroller","isNegativeOffset","rootElement","_ro","scrollDirection","resized","scrollToKey","mountedIndexes","WeakMap","getResizeObserver","ResizeObserver","entries","resizes","entry","target","contentRect","get","_initRoot","root","ro","syncViewportToScrollPosition","onScrollStopped","debounce","id","cancel","clearTimeout","debouncedFn","setTimeout","_cancel","onScroll","observe","addEventListener","disconnect","removeEventListener","el","set","unobserve","_getScrollPosition","_getScrollDirection","_updateScrollPosition","diff","prev","count","startIndexWithMargin","endIndexWithMargin","reduce","acc","j","isStartInView","isEndInView","useImperativeHandle","getScrollSize","scrollWidth","scrollHeight","scrollTo","async","getCurrentOffset","getOffset","scrollOffset","scrollToIndex","scrollToOffset","items","elements","key"],"mappings":"sQAAO,MAAMA,EAAMC,KAAKD,IACXE,EAAMD,KAAKC,IACXC,EAAMF,KAAKE,IAEXC,EAAQA,CAAIC,EAAgBC,IACvCC,MAAMC,KAAK,CAAEH,WAAU,CAACI,EAAGC,IAAMJ,EAAGI,KCQzBC,EAAcA,CAACC,EAAcC,KACxC,MAAMC,EAAOF,EAAMG,EAAOF,GAC1B,OAZsB,IAYfC,EAAoBF,EAAMI,EAAmBF,CAAI,EA8BpDG,EAAYA,CAACL,EAAcF,EAAWQ,KAC1C,IAAIC,EAAM,EACV,GAAID,GAAY,EAEd,KAAOR,EAAIE,EAAMQ,EAAU,GAAG,CAC5B,MAAMC,EAAIV,EAAYC,EAAOF,GAG7B,GAFAS,GAAOE,EACPX,IACIS,GAAOD,EAAU,CACfC,EAAME,EAAI,GAAKH,GACjBR,IAEF,KACD,CACF,MAGD,KAAOA,EAAI,GAAG,CACZA,IACA,MAAMW,EAAIV,EAAYC,EAAOF,GAE7B,GADAS,GAAOE,EACHF,GAAOD,EAAU,CACfC,EAAME,EAAI,EAAIH,GAChBR,IAEF,KACD,C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GACxD,EACF,GAEH,CAAC6K,IAGH,MAAMmB,EAAQpJ,GAAQ,KACpB,IAAIzD,GAAK,EACT,MAAM8M,EAA2B,GAsBjC,OArBAhH,EAASC,QAAQ5D,GAAW6B,IACtBD,EAAiBC,KAGrBhE,IACIA,EAAI2L,GAAwB3L,EAAI4L,GAGpCkB,EAAStE,KACPjF,EAACvB,EAEC,CAAAI,EAASC,EACTC,EAAQC,EACRC,EAAQxC,EACRyC,EAAUkD,EACVhD,EAAeC,EACfC,EAAQC,EACRZ,EAAW8B,IAPLA,eAAAA,EAAqC+I,MAAO/M,IASrD,IAEI8M,CAAQ,GACd,CAAC3K,EAAUwJ,EAAsBC,IAEpC,OACErI,EAACU,EAAM,CACLC,EAAM2E,EACNlG,EAAeC,EACfH,EAAUgD,EACVtB,EAAQmB,EACRpD,EACEqB,EAACiB,EAAK,CACJlC,EAAQC,EACRE,EAAUiD,EACVvB,EAAQqB,EACR7C,EAAeC,EACfC,EAAQC,EACRZ,EAAW2K,KAGf"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/src/core/utils.ts","../src/src/core/cache.ts","../src/src/react/useIsomorphicLayoutEffect.ts","../src/src/react/useSyncExternalStore.ts","../src/src/react/List.tsx","../src/src/core/store.ts","../src/src/core/scroller.ts"],"sourcesContent":["export const min = Math.min;\nexport const max = Math.max;\nexport const abs = Math.abs;\n\nexport const range = <T>(length: number, cb: (i: number) => T): T[] =>\n Array.from({ length }, (_, i) => cb(i));\n\nexport const debounce = <T extends (...args: any[]) => void>(\n fn: T,\n ms: number\n) => {\n let id: NodeJS.Timeout | null = null;\n\n const cancel = () => {\n if (id != null) {\n clearTimeout(id);\n }\n };\n const debouncedFn = () => {\n cancel();\n id = setTimeout(() => {\n id = null;\n fn();\n }, ms);\n };\n debouncedFn._cancel = cancel;\n return debouncedFn;\n};\n","import type { DeepReadonly, Writeable } from \"./types\";\nimport { max, min, range } from \"./utils\";\n\nexport const UNCACHED = -1;\n\nexport type Cache = DeepReadonly<{\n _defaultItemSize: number;\n _length: number;\n _sizes: number[];\n _measuredOffsetIndex: number;\n _offsets: number[];\n}>;\n\nexport const getItemSize = (cache: Cache, index: number): number => {\n const size = cache._sizes[index]!;\n return size === UNCACHED ? cache._defaultItemSize : size;\n};\n\nexport const setItemSize = (\n cache: Writeable<Cache>,\n index: number,\n size: number\n) => {\n cache._sizes[index] = size;\n // mark as dirty\n cache._measuredOffsetIndex = min(index, cache._measuredOffsetIndex);\n};\n\nexport const computeTotalSize = (cache: Writeable<Cache>): number => {\n if (!cache._length) return 0;\n const lastIndex = cache._length - 1;\n if (cache._measuredOffsetIndex >= lastIndex) {\n return cache._offsets[lastIndex]! + getItemSize(cache, lastIndex);\n }\n\n let top = cache._offsets[cache._measuredOffsetIndex]!;\n for (let i = cache._measuredOffsetIndex; i <= lastIndex; i++) {\n cache._offsets[i] = top;\n top += getItemSize(cache, i);\n }\n\n cache._measuredOffsetIndex = lastIndex;\n return top;\n};\n\nconst findIndex = (cache: Cache, i: number, distance: number): number => {\n let sum = 0;\n if (distance >= 0) {\n // search forward\n while (i < cache._length - 1) {\n const h = getItemSize(cache, i);\n sum += h;\n i++;\n if (sum >= distance) {\n if (sum - h / 2 >= distance) {\n i--;\n }\n break;\n }\n }\n } else {\n // search backward\n while (i > 0) {\n i--;\n const h = getItemSize(cache, i);\n sum -= h;\n if (sum <= distance) {\n if (sum + h / 2 < distance) {\n i++;\n }\n break;\n }\n }\n }\n\n return min(max(i, 0), cache._length - 1);\n};\n\nexport const findStartIndexWithOffset = (\n cache: Cache,\n offset: number,\n prevStartIndex: number,\n prevOffset: number\n): number => {\n return findIndex(cache, prevStartIndex, offset - prevOffset);\n};\n\nexport const findEndIndex = findIndex;\n\nexport const hasUnmeasuredItemsInRange = (\n cache: Cache,\n startIndex: number,\n endIndex: number\n): boolean => {\n for (let i = startIndex; i <= endIndex; i++) {\n if (cache._sizes[i] === UNCACHED) {\n return true;\n }\n }\n return false;\n};\n\nexport const computeStartOffset = (\n cache: Writeable<Cache>,\n index: number\n): number => {\n if (!cache._length) return 0;\n if (cache._measuredOffsetIndex >= index) {\n return cache._offsets[index]!;\n }\n\n let top = cache._offsets[cache._measuredOffsetIndex]!;\n for (let i = cache._measuredOffsetIndex; i <= index; i++) {\n cache._offsets[i] = top;\n if (i === index) {\n break;\n }\n top += getItemSize(cache, i);\n }\n cache._measuredOffsetIndex = index;\n return top;\n};\n\nexport const resetCache = (\n length: number,\n itemSize: number,\n cache?: Cache\n): Cache => {\n return {\n _defaultItemSize: itemSize,\n _length: length,\n _measuredOffsetIndex:\n (cache && min(cache._measuredOffsetIndex, length - 1)) ?? 0,\n _sizes: range(length, (i) => (cache && cache._sizes[i]) ?? UNCACHED),\n _offsets: range(length, (i) =>\n i === 0\n ? 0 // first offset must be 0\n : (cache && cache._offsets[i]) ?? UNCACHED\n ),\n };\n};\n","import { useEffect, useLayoutEffect } from \"react\";\n\n// https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85\nexport const useIsomorphicLayoutEffect =\n typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n","import { useSyncExternalStore as _useSyncExternalStore } from \"use-sync-external-store/shim\";\n\nexport const useSyncExternalStore = <T>(\n subscibe: (onStoreChange: () => void) => () => void,\n getSnapShot: () => T\n): T => {\n return _useSyncExternalStore(subscibe, getSnapShot, getSnapShot);\n};\n","import {\n Children,\n memo,\n useRef,\n useMemo,\n CSSProperties,\n ReactElement,\n forwardRef,\n useImperativeHandle,\n ReactNode,\n useEffect,\n RefObject,\n useState,\n} from \"react\";\nimport {\n UPDATE_CACHE_LENGTH,\n VirtualStore,\n createVirtualStore,\n} from \"../core/store\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore\";\nimport { max, min } from \"../core/utils\";\nimport {\n createScroller,\n Scroller,\n SCROLL_MANUAL,\n SCROLL_UP,\n} from \"../core/scroller\";\n\nconst INITIAL_END_REACHED_INDEX = -1;\n\ntype ItemProps = {\n _children: ReactNode;\n _scroller: Scroller;\n _store: VirtualStore;\n _index: number;\n _element: \"div\";\n};\n\nconst Item = memo(\n ({\n _children: children,\n _scroller: scroller,\n _store: store,\n _index: index,\n _element: Element,\n }: ItemProps): ReactElement => {\n const ref = useRef<HTMLDivElement>(null);\n\n const offset = useSyncExternalStore(store._subscribe, () =>\n store._getItemOffset(index)\n );\n const hide = useSyncExternalStore(store._subscribe, () =>\n store._isUnmeasuredItem(index)\n );\n\n // The index may be changed if elements are inserted to or removed from the start of props.children\n useIsomorphicLayoutEffect(\n () => scroller._initItem(ref.current!, index),\n [index]\n );\n\n return (\n <Element\n ref={ref}\n style={useMemo<CSSProperties>(() => {\n const isHorizontal = store._isHorizontal();\n const isRtl = store._isRtl();\n const style: CSSProperties = {\n margin: \"0\",\n padding: \"0\",\n position: \"absolute\",\n [isHorizontal ? \"height\" : \"width\"]: \"100%\",\n [isHorizontal ? \"top\" : isRtl ? \"right\" : \"left\"]: 0,\n [isHorizontal ? (isRtl ? \"right\" : \"left\") : \"top\"]: offset,\n // willChange: \"transform\",\n };\n if (isHorizontal) {\n style.display = \"flex\";\n }\n if (hide) {\n style.visibility = \"hidden\";\n }\n return style;\n }, [offset, hide])}\n >\n {children}\n </Element>\n );\n }\n);\n\nconst isInvalidElement = <T extends ReactNode>(\n e: T\n): e is Extract<T, null | undefined | boolean> =>\n e == null || typeof e === \"boolean\";\n\nexport interface CustomWindowComponentProps {\n children: ReactNode;\n style: CSSProperties;\n scrollSize: number;\n horizontal: boolean;\n rtl: boolean;\n}\n\nconst DefaultWindow = forwardRef<any, CustomWindowComponentProps>(\n ({ children, style, scrollSize, horizontal, rtl }, ref): ReactElement => {\n return (\n <div ref={ref} style={style}>\n <div\n style={useMemo<CSSProperties>(() => {\n const width = horizontal ? scrollSize : \"100%\";\n const height = horizontal ? \"100%\" : scrollSize;\n return {\n position: \"absolute\",\n top: 0,\n [rtl ? \"right\" : \"left\"]: 0,\n width,\n height,\n minWidth: width,\n minHeight: height,\n };\n }, [scrollSize])}\n >\n {children}\n </div>\n </div>\n );\n }\n);\n\nexport type CustomWindowComponent = typeof DefaultWindow;\n\nconst Window = ({\n _children: children,\n _ref: ref,\n _store: store,\n _element: Element,\n _style: style,\n}: {\n _children: ReactNode;\n _ref: RefObject<HTMLDivElement>;\n _store: VirtualStore;\n _element: CustomWindowComponent;\n _style: CSSProperties | undefined;\n}) => {\n const scrollSize = useSyncExternalStore(\n store._subscribe,\n store._getScrollSize\n );\n const viewportSize = useSyncExternalStore(\n store._subscribe,\n store._getViewportSize\n );\n const clampedScrollSize =\n scrollSize >= viewportSize ? scrollSize : viewportSize;\n\n const horizontal = store._isHorizontal();\n return (\n <Element\n ref={ref}\n scrollSize={clampedScrollSize}\n horizontal={horizontal}\n rtl={store._isRtl()}\n style={useMemo<CSSProperties>(\n () => ({\n overflow: horizontal ? \"auto hidden\" : \"hidden auto\",\n position: \"relative\",\n contain: \"strict\",\n // transform: \"translate3d(0px, 0px, 0px)\",\n // willChange: \"scroll-position\",\n // backfaceVisibility: \"hidden\",\n width: \"100%\",\n height: \"100%\",\n padding: 0,\n margin: 0,\n ...style,\n }),\n [style]\n )}\n >\n {children}\n </Element>\n );\n};\n\nexport interface CustomItemComponentProps {\n style: CSSProperties;\n children: ReactNode;\n}\n\nexport type CustomItemComponent = React.ForwardRefExoticComponent<\n React.PropsWithoutRef<CustomItemComponentProps> & React.RefAttributes<any>\n>;\n\ntype CustomItemComponentOrElement =\n | keyof JSX.IntrinsicElements\n | CustomItemComponent;\n\n/**\n * Methods of {@link List}.\n */\nexport interface ListHandle {\n /**\n * Get current scrollTop or scrollLeft.\n */\n scrollOffset: number;\n /**\n * Get current scrollHeight or scrollWidth.\n */\n scrollSize: number;\n /**\n * Scroll to the item specified by index.\n * @param index index of item\n */\n scrollToIndex(index: number): void;\n /**\n * Scroll to the item specified by offset.\n * @param offset offset from start\n */\n scrollToOffset(offset: number): void;\n}\n\n/**\n * Props of {@link List}.\n */\nexport interface ListProps {\n /**\n * Elements rendered by this component.\n */\n children: ReactNode;\n /**\n * Item size hint for unmeasured items. It's recommended to specify this prop if item sizes are fixed and known, or much larger than the defaultValue. It will help to reduce scroll jump when items are measured.\n * @defaultValue 40\n */\n itemSize?: number;\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 6\n */\n overscan?: number;\n /**\n * If true, rendered as a horizontally scrollable list. Otherwise rendered as a vertically scrollable list.\n */\n horizontal?: boolean;\n /**\n * You have to set true if you use this component under `direction: rtl` style.\n */\n rtl?: boolean;\n /**\n * Number of items to be the margin from the end of the scroll. See also {@link onEndReached}.\n * @defaultValue 0\n */\n endThreshold?: number;\n /**\n * Inline style prop to override style of scrollable element.\n */\n style?: CSSProperties;\n /**\n * Customized element type for scrollable element.\n * @defaultValue \"div\"\n */\n element?: CustomWindowComponent;\n /**\n * Customized element type for item element.\n * @defaultValue \"div\"\n */\n itemElement?: CustomItemComponentOrElement;\n /**\n * Callback invoked when scrolling reached to the end. The margin from the end is specified by {@link endThreshold}.\n */\n onEndReached?: () => void;\n}\n\n/**\n * Virtualized list component. See {@link ListProps} and {@link ListHandle}.\n */\nexport const List = forwardRef<ListHandle, ListProps>(\n (\n {\n children,\n itemSize: itemSizeProp = 40,\n overscan = 6,\n horizontal: horizontalProp,\n rtl: rtlProp,\n endThreshold = 0,\n style: styleProp,\n element = DefaultWindow,\n itemElement = \"div\",\n onEndReached,\n },\n ref\n ): ReactElement => {\n // Memoize element array\n const elements = useMemo(() => {\n const arr: ReactNode[] = [];\n Children.forEach(children, (e) => {\n if (isInvalidElement(e)) {\n return;\n }\n arr.push(e);\n });\n return arr;\n }, [children]);\n const elementsCount = elements.length;\n\n // https://github.com/facebook/react/issues/25191#issuecomment-1237456448\n const storeRef = useRef<VirtualStore | undefined>();\n const store =\n storeRef.current ||\n (storeRef.current = createVirtualStore(\n elementsCount,\n itemSizeProp,\n !!horizontalProp,\n !!rtlProp\n ));\n const startIndex = useSyncExternalStore(\n store._subscribe,\n store._getStartIndex\n );\n const endIndex = useSyncExternalStore(store._subscribe, store._getEndIndex);\n const jump = useSyncExternalStore(store._subscribe, store._getJump);\n const rootRef = useRef<HTMLDivElement>(null);\n const onEndReachedCalledIndex = useRef<number>(INITIAL_END_REACHED_INDEX);\n\n const [mountedIndexes, reset] = useState<Set<number>>(new Set<number>());\n const scrollerRef = useRef<Scroller>();\n const scroller =\n scrollerRef.current ||\n (scrollerRef.current = createScroller(store, () => {\n reset(new Set());\n }));\n\n // The elements length and cached items length are different just after element is added/removed.\n const count = min(elementsCount, store._getItemCount());\n\n // So update cache length. Updating state in render will cause warn so use useEffect for now.\n useIsomorphicLayoutEffect(() => {\n store._update({\n _type: UPDATE_CACHE_LENGTH,\n _length: elementsCount,\n });\n }, [elementsCount]);\n\n useIsomorphicLayoutEffect(() => scroller._initRoot(rootRef.current!), []);\n\n useIsomorphicLayoutEffect(() => {\n if (!jump.length) return;\n\n // Compensate scroll jump\n const scrollDirection = scroller._getScrollDirection();\n if (scrollDirection === SCROLL_UP) {\n const diff = jump.reduce((acc, [, j]) => acc + j, 0);\n if (diff) {\n scroller._updateScrollPosition(diff, true);\n }\n } else if (scrollDirection === SCROLL_MANUAL) {\n const isStartInView = startIndex === 0;\n const isEndInView = endIndex - (count - 1) === 0;\n const diff = jump.reduce((acc, [index, j]) => {\n if (index < startIndex) {\n // Keep start if scroll position is not stuck to the start\n if (!isStartInView) {\n acc += j;\n }\n } else {\n // Keep end if scroll position is stuck to the end\n if (!isStartInView && isEndInView) {\n acc += j;\n }\n }\n return acc;\n }, 0);\n if (diff) {\n scroller._updateScrollPosition(diff, true);\n }\n } else {\n // NOP\n }\n }, [jump]);\n\n useEffect(() => {\n if (!onEndReached) return;\n\n if (onEndReachedCalledIndex.current > count) {\n // Probably items have been refreshed, so reset index\n onEndReachedCalledIndex.current = INITIAL_END_REACHED_INDEX;\n }\n\n const endMargin = count - 1 - endIndex;\n if (\n endMargin <= endThreshold &&\n onEndReachedCalledIndex.current < count\n ) {\n onEndReachedCalledIndex.current = count;\n onEndReached();\n }\n }, [endIndex]);\n\n useImperativeHandle(\n ref,\n () => {\n return {\n get scrollOffset() {\n return scroller._getScrollPosition();\n },\n get scrollSize() {\n return scroller._getActualScrollSize();\n },\n scrollToIndex(index) {\n index = max(min(index, count - 1), 0);\n\n scroller._scrollTo(index, () => store._getItemOffset(index));\n },\n scrollToOffset(offset) {\n offset = max(offset, 0);\n\n scroller._scrollTo(\n store._getItemIndexForScrollTo(offset),\n () => offset\n );\n },\n };\n },\n [count]\n );\n\n const startIndexWithMargin = max(startIndex - overscan, 0);\n const endIndexWithMargin = min(endIndex + overscan, count - 1);\n const items = useMemo(() => {\n const res: ReactElement[] = [];\n for (let i = startIndexWithMargin; i <= endIndexWithMargin; i++) {\n // https://github.com/sergi/virtual-list/commit/8e7e06dc63568334c1ab809ea83c1be36572e9ed\n mountedIndexes.add(i);\n }\n mountedIndexes.forEach((i) => {\n const e = elements[i];\n res.push(\n <Item\n key={(e as { key?: ReactElement[\"key\"] })?.key || i}\n _scroller={scroller}\n _store={store}\n _index={i}\n _element={itemElement as \"div\"}\n _children={e}\n />\n );\n });\n return res;\n }, [elements, mountedIndexes, startIndexWithMargin, endIndexWithMargin]);\n\n return (\n <Window\n _ref={rootRef}\n _store={store}\n _element={element}\n _style={styleProp}\n _children={items}\n />\n );\n }\n);\n","import {\n findStartIndexWithOffset,\n resetCache,\n getItemSize,\n computeTotalSize,\n findEndIndex,\n computeStartOffset,\n Cache,\n UNCACHED,\n setItemSize,\n hasUnmeasuredItemsInRange,\n} from \"./cache\";\nimport type { Writeable } from \"./types\";\n\nexport const UPDATE_CACHE_LENGTH = 0;\nexport const UPDATE_ITEM_SIZES = 1;\nexport const UPDATE_VIEWPORT_SIZE = 2;\nexport const HANDLE_SCROLL = 3;\n\nexport type ScrollJump = Readonly<[index: number, sizeDiff: number][]>;\n\ntype State = {\n _startIndex: number;\n _viewportWidth: number;\n _viewportHeight: number;\n _cache: Cache;\n _jump: ScrollJump;\n};\n\ntype Actions =\n | { _type: typeof UPDATE_CACHE_LENGTH; _length: number }\n | {\n _type: typeof UPDATE_ITEM_SIZES;\n _entries: [index: number, size: number][];\n }\n | { _type: typeof UPDATE_VIEWPORT_SIZE; _width: number; _height: number }\n | { _type: typeof HANDLE_SCROLL; _offset: number };\n\nconst mutate = (state: State, action: Actions, itemSize: number): boolean => {\n switch (action._type) {\n case UPDATE_CACHE_LENGTH: {\n if (state._cache._length === action._length) return false;\n state._cache = resetCache(action._length, itemSize, state._cache);\n return true;\n }\n case UPDATE_ITEM_SIZES: {\n const updated = action._entries.filter(\n ([index, size]) => state._cache._sizes[index] !== size\n );\n // Skip if all items are cached and not updated\n if (!updated.length) {\n return false;\n }\n\n const jump: [index: number, sizeDiff: number][] = [];\n updated.forEach(([index, size]) => {\n jump.push([index, size - getItemSize(state._cache, index)]);\n setItemSize(state._cache as Writeable<Cache>, index, size);\n });\n state._jump = jump;\n return true;\n }\n case UPDATE_VIEWPORT_SIZE: {\n if (\n state._viewportWidth === action._width &&\n state._viewportHeight === action._height\n ) {\n return false;\n }\n state._viewportWidth = action._width;\n state._viewportHeight = action._height;\n return true;\n }\n case HANDLE_SCROLL: {\n const prevStartIndex = state._startIndex;\n const prevOffset = computeStartOffset(\n state._cache as Writeable<Cache>,\n prevStartIndex\n );\n if (prevOffset === action._offset) {\n return false;\n }\n return (\n (state._startIndex = findStartIndexWithOffset(\n state._cache,\n action._offset,\n prevStartIndex,\n prevOffset\n )) !== prevStartIndex\n );\n }\n }\n};\n\nexport type VirtualStore = {\n _getStartIndex(): number;\n _getEndIndex(): number;\n _isUnmeasuredItem(index: number): boolean;\n _hasUnmeasuredItemsInRange(startIndex: number): boolean;\n _getItemOffset(index: number): number;\n _getViewportSize(): number;\n _getScrollSize(): number;\n _getItemCount(): number;\n _getJump(): ScrollJump;\n _isHorizontal(): boolean;\n _isRtl(): boolean;\n _getItemIndexForScrollTo(offset: number): number;\n _waitForScrollDestinationItemsMeasured(): Promise<void>;\n _subscribe(cb: () => void): () => void;\n _update(action: Actions): void;\n};\n\nexport const createVirtualStore = (\n itemCount: number,\n itemSize: number,\n isHorizontal: boolean,\n isRtl: boolean\n): VirtualStore => {\n const subscribers = new Set<() => void>();\n const state: Readonly<State> = {\n _startIndex: 0,\n _viewportWidth: 0,\n _viewportHeight: 0,\n _cache: resetCache(itemCount, itemSize),\n _jump: [],\n };\n const getViewportSize = (): number =>\n isHorizontal ? state._viewportWidth : state._viewportHeight;\n\n let scrollToQueue: [() => void, () => void] | undefined;\n\n return {\n _getStartIndex() {\n return state._startIndex;\n },\n _getEndIndex() {\n return findEndIndex(state._cache, state._startIndex, getViewportSize());\n },\n _isUnmeasuredItem(index) {\n return state._cache._sizes[index] === UNCACHED;\n },\n _hasUnmeasuredItemsInRange(startIndex) {\n return hasUnmeasuredItemsInRange(\n state._cache,\n startIndex,\n findEndIndex(state._cache, startIndex, getViewportSize())\n );\n },\n _getItemOffset(index) {\n return computeStartOffset(state._cache as Writeable<Cache>, index);\n },\n _getViewportSize() {\n return getViewportSize();\n },\n _getScrollSize() {\n return computeTotalSize(state._cache as Writeable<Cache>);\n },\n _getItemCount() {\n return state._cache._length;\n },\n _getJump() {\n return state._jump;\n },\n _isHorizontal() {\n return isHorizontal;\n },\n _isRtl() {\n return isRtl;\n },\n _getItemIndexForScrollTo(offset) {\n return findStartIndexWithOffset(state._cache, offset, 0, 0);\n },\n _waitForScrollDestinationItemsMeasured() {\n if (scrollToQueue) {\n // Cancel waiting scrollTo\n scrollToQueue[1]();\n }\n // The measurement will be done asynchronously and the timing is not predictable so we use promise.\n // For example, ResizeObserver may not fire when window is not visible.\n return new Promise((resolve, reject) => {\n scrollToQueue = [\n () => {\n // HACK: It should be resolved in the next microtask that is after React's render\n Promise.resolve().then(() => {\n resolve();\n scrollToQueue = undefined;\n });\n },\n reject,\n ];\n });\n },\n _subscribe(cb) {\n subscribers.add(cb);\n return () => {\n subscribers.delete(cb);\n };\n },\n _update(action) {\n const mutated = mutate(state, action, itemSize);\n if (mutated) {\n subscribers.forEach((cb) => {\n cb();\n });\n if (scrollToQueue && action._type === UPDATE_ITEM_SIZES) {\n scrollToQueue[0]();\n }\n }\n },\n };\n};\n","import {\n HANDLE_SCROLL,\n UPDATE_ITEM_SIZES,\n UPDATE_VIEWPORT_SIZE,\n VirtualStore,\n} from \"./store\";\nimport { abs, debounce } from \"./utils\";\n\nexport const SCROLL_STOP = 0;\nexport const SCROLL_DOWN = 1;\nexport const SCROLL_UP = 2;\nexport const SCROLL_MANUAL = 3;\ntype ScrollDirection =\n | typeof SCROLL_STOP\n | typeof SCROLL_DOWN\n | typeof SCROLL_UP\n | typeof SCROLL_MANUAL;\n\nexport type Scroller = {\n _initRoot: (rootElement: HTMLElement) => () => void;\n _initItem: (itemElement: HTMLElement, index: number) => () => void;\n _getScrollPosition: () => number;\n _getScrollDirection: () => ScrollDirection;\n _getActualScrollSize: () => number;\n _updateScrollPosition: (offset: number, diff?: boolean) => void;\n _scrollTo: (index: number, getCurrentOffset: () => number) => void;\n};\n\nexport const createScroller = (\n store: VirtualStore,\n notifyStop: () => void\n): Scroller => {\n let prevOffset = -1;\n let scrollDirection: ScrollDirection = SCROLL_STOP;\n let resized = false;\n let isNegativeOffset: boolean | undefined;\n let rootElement: HTMLElement | undefined;\n let _ro: ResizeObserver | undefined;\n const isHorizontal = store._isHorizontal();\n const isRtl = store._isRtl();\n const scrollToKey = isHorizontal ? \"scrollLeft\" : \"scrollTop\";\n const mountedIndexes = new WeakMap<Element, number>();\n const getResizeObserver = (): ResizeObserver => {\n // Initialize ResizeObserver lazily for SSR\n return (\n _ro ||\n (_ro = new ResizeObserver((entries) => {\n // https://www.w3.org/TR/resize-observer/#intro\n const resizes: [index: number, size: number][] = [];\n for (const entry of entries) {\n if (entry.target === rootElement) {\n store._update({\n _type: UPDATE_VIEWPORT_SIZE,\n _width: entry.contentRect.width,\n _height: entry.contentRect.height,\n });\n } else {\n const index = mountedIndexes.get(entry.target);\n if (index != null) {\n resizes.push([\n index,\n entry.contentRect[isHorizontal ? \"width\" : \"height\"],\n ]);\n }\n }\n }\n\n if (resizes.length) {\n store._update({\n _type: UPDATE_ITEM_SIZES,\n _entries: resizes,\n });\n resized = true;\n }\n }))\n );\n };\n const getActualScrollSize = (): number => {\n if (!rootElement) return 0;\n // Use element's scrollHeight/scrollWidth instead of stored scrollSize.\n // This is because stored size may differ from the actual size, for example when a new item is added and not yet measured.\n return store._isHorizontal()\n ? rootElement.scrollWidth\n : rootElement.scrollHeight;\n };\n const updateScrollPosition = (offset: number, diff?: boolean) => {\n if (!rootElement) return;\n if (isRtl) {\n if (isNegativeOffset == null) {\n // Assume offset type in rtl direction.\n // The scroll position is negative in spec however its not in some browsers, for example Chrome earlier than v85.\n // https://github.com/othree/jquery.rtl-scroll-type\n const prev = rootElement[scrollToKey];\n rootElement[scrollToKey] = 1;\n isNegativeOffset = rootElement[scrollToKey] === 0;\n rootElement[scrollToKey] = prev;\n }\n if (isNegativeOffset) {\n offset *= -1;\n }\n }\n if (diff) {\n rootElement[scrollToKey] += offset;\n } else {\n rootElement[scrollToKey] = offset;\n scrollDirection = SCROLL_MANUAL;\n }\n };\n const scrollTo = async (index: number, getCurrentOffset: () => number) => {\n const getOffset = (): number => {\n let offset = getCurrentOffset();\n const scrollSize = getActualScrollSize();\n const viewportSize = store._getViewportSize();\n if (scrollSize - (offset + viewportSize) <= 0) {\n // Adjust if the offset is over the end, to get correct startIndex.\n offset = scrollSize - viewportSize;\n }\n return offset;\n };\n\n if (store._hasUnmeasuredItemsInRange(index)) {\n do {\n // In order to scroll to the correct position, mount the items and measure their sizes before scrolling.\n store._update({\n _type: HANDLE_SCROLL,\n _offset: getOffset(),\n });\n try {\n // Wait for the scroll destination items to be measured.\n await store._waitForScrollDestinationItemsMeasured();\n } catch (e) {\n // canceled\n return;\n }\n } while (store._hasUnmeasuredItemsInRange(index));\n\n // Scroll with the updated value\n updateScrollPosition(getOffset());\n } else {\n const offset = getOffset();\n updateScrollPosition(offset);\n // Sync viewport to scroll destination\n store._update({ _type: HANDLE_SCROLL, _offset: offset });\n }\n };\n\n return {\n _initRoot(root) {\n rootElement = root;\n const ro = getResizeObserver();\n\n const syncViewportToScrollPosition = () => {\n let offset = root[scrollToKey];\n if (isRtl) {\n // The scroll position may be negative value in rtl direction.\n // https://github.com/othree/jquery.rtl-scroll-type\n offset = abs(offset);\n }\n if (prevOffset === offset) {\n return;\n }\n // Skip scroll direction detection just after resizing because it may result in the opposite direction.\n // Scroll events are dispatched enough so it's ok to skip some of them.\n if (scrollDirection === SCROLL_STOP || !resized) {\n // Ignore until manual scrolling\n if (scrollDirection !== SCROLL_MANUAL) {\n scrollDirection = prevOffset > offset ? SCROLL_UP : SCROLL_DOWN;\n }\n } else {\n resized = false;\n }\n store._update({\n _type: HANDLE_SCROLL,\n _offset: (prevOffset = offset),\n });\n };\n\n const onScrollStopped = debounce(() => {\n // Check scroll position once just after scrolling stopped\n syncViewportToScrollPosition();\n scrollDirection = SCROLL_STOP;\n notifyStop();\n }, 300);\n\n const onScroll = () => {\n syncViewportToScrollPosition();\n onScrollStopped();\n };\n\n ro.observe(root);\n root.addEventListener(\"scroll\", onScroll);\n\n return () => {\n ro.disconnect();\n root.removeEventListener(\"scroll\", onScroll);\n onScrollStopped._cancel();\n };\n },\n _initItem(el, i) {\n const ro = getResizeObserver();\n mountedIndexes.set(el, i);\n ro.observe(el);\n return () => {\n mountedIndexes.delete(el);\n ro.unobserve(el);\n };\n },\n _getScrollPosition() {\n if (!rootElement) return 0;\n return rootElement[scrollToKey];\n },\n _getScrollDirection() {\n return scrollDirection;\n },\n _getActualScrollSize: getActualScrollSize,\n _updateScrollPosition: updateScrollPosition,\n _scrollTo: scrollTo,\n };\n};\n"],"names":["min","Math","max","abs","range","length","cb","Array","from","_","i","getItemSize","cache","index","size","_sizes","_defaultItemSize","findIndex","distance","sum","_length","h","findStartIndexWithOffset","offset","prevStartIndex","prevOffset","findEndIndex","computeStartOffset","_measuredOffsetIndex","_offsets","top","resetCache","itemSize","_a","useIsomorphicLayoutEffect","window","useLayoutEffect","useEffect","useSyncExternalStore","subscibe","getSnapShot","_useSyncExternalStore","Item","memo","_children","children","_scroller","scroller","_store","store","_index","_element","Element","ref","useRef","_subscribe","_getItemOffset","hide","_isUnmeasuredItem","_initItem","current","_jsx","style","useMemo","isHorizontal","_isHorizontal","isRtl","_isRtl","margin","padding","position","display","visibility","DefaultWindow","forwardRef","scrollSize","horizontal","rtl","width","height","minWidth","minHeight","Window","_ref","_style","_getScrollSize","viewportSize","_getViewportSize","clampedScrollSize","overflow","contain","List","itemSizeProp","overscan","horizontalProp","rtlProp","endThreshold","styleProp","element","itemElement","onEndReached","elements","arr","Children","forEach","e","isInvalidElement","push","elementsCount","storeRef","createVirtualStore","itemCount","subscribers","Set","state","_startIndex","_viewportWidth","_viewportHeight","_cache","_jump","getViewportSize","scrollToQueue","_getStartIndex","_getEndIndex","_hasUnmeasuredItemsInRange","startIndex","hasUnmeasuredItemsInRange","endIndex","lastIndex","computeTotalSize","_getItemCount","_getJump","_getItemIndexForScrollTo","_waitForScrollDestinationItemsMeasured","Promise","resolve","reject","then","undefined","add","delete","_update","action","mutate","_type","updated","_entries","filter","jump","setItemSize","_width","_height","_offset","rootRef","onEndReachedCalledIndex","mountedIndexes","reset","useState","scrollerRef","createScroller","notifyStop","isNegativeOffset","rootElement","_ro","scrollDirection","resized","scrollToKey","WeakMap","getResizeObserver","ResizeObserver","entries","resizes","entry","target","contentRect","get","getActualScrollSize","scrollWidth","scrollHeight","updateScrollPosition","diff","prev","_initRoot","root","ro","syncViewportToScrollPosition","onScrollStopped","debounce","id","cancel","clearTimeout","debouncedFn","setTimeout","_cancel","onScroll","observe","addEventListener","disconnect","removeEventListener","el","set","unobserve","_getScrollPosition","_getScrollDirection","_getActualScrollSize","_updateScrollPosition","_scrollTo","async","getCurrentOffset","getOffset","count","reduce","acc","j","isStartInView","isEndInView","useImperativeHandle","scrollOffset","scrollToIndex","scrollToOffset","startIndexWithMargin","endIndexWithMargin","items","res","key"],"mappings":"oRAAO,MAAMA,EAAMC,KAAKD,IACXE,EAAMD,KAAKC,IACXC,EAAMF,KAAKE,IAEXC,EAAQA,CAAIC,EAAgBC,IACvCC,MAAMC,KAAK,CAAEH,WAAU,CAACI,EAAGC,IAAMJ,EAAGI,KCQzBC,EAAcA,CAACC,EAAcC,KACxC,MAAMC,EAAOF,EAAMG,EAAOF,GAC1B,OAZsB,IAYfC,EAAoBF,EAAMI,EAAmBF,CAAI,EA8BpDG,EAAYA,CAACL,EAAcF,EAAWQ,KAC1C,IAAIC,EAAM,EACV,GAAID,GAAY,EAEd,KAAOR,EAAIE,EAAMQ,EAAU,GAAG,CAC5B,MAAMC,EAAIV,EAAYC,EAAOF,GAG7B,GAFAS,GAAOE,EACPX,IACIS,GAAOD,EAAU,CACfC,EAAME,EAAI,GAAKH,GACjBR,IAEF,KACD,CACF,MAGD,KAAOA,EAAI,GAAG,CACZA,IACA,MAAMW,EAAIV,EAAYC,EAAOF,GAE7B,GADAS,GAAOE,EACHF,GAAOD,EAAU,CACfC,EAAME,EAAI,EAAIH,GAChBR,IAEF,KACD,CACF,CAGH,OAAOV,EAAIE,EAAIQ,EAAG,GAAIE,EAAMQ,EAAU,EAAE,EAG7BE,EAA2BA,CACtCV,EACAW,EACAC,EACAC,IAEOR,EAAUL,EAAOY,EAAgBD,EAASE,GAGtCC,EAAeT,EAefU,EAAqBA,CAChCf,EACAC,KAEA,IAAKD,EAAMQ,EAAS,OAAO,EAC3B,GAAIR,EAAMgB,GAAwBf,EAChC,OAAOD,EAAMiB,EAAShB,GAGxB,IAAIiB,EAAMlB,EAAMiB,EAASjB,EAAMgB,GAC/B,IAAK,IAAIlB,EAAIE,EAAMgB,EAAsBlB,GAAKG,IAC5CD,EAAMiB,EAASnB,GAAKoB,EAChBpB,IAAMG,GAFyCH,IAKnDoB,GAAOnB,E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GAECI,EAAWC,EACXC,EAAQC,EACRC,EAAQxC,EACRyC,EAAUgD,EACVvD,EAAW6D,IALLA,aAAC,EAADA,EAAqCuH,MAAOtN,GAOrD,IAEIqN,CAAG,GACT,CAAC1H,EAAUsD,EAAgBiE,EAAsBC,IAEpD,OACEhK,EAACqB,EACC,CAAAC,EAAMsE,EACNzG,EAAQC,EACRE,EAAU+C,EACVd,EAAQa,EACRrD,EAAWkL,GACX"}
|
package/lib/react/List.d.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { CSSProperties, ReactNode } from "react";
|
|
2
|
-
export interface
|
|
2
|
+
export interface CustomWindowComponentProps {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
style: CSSProperties;
|
|
5
|
+
scrollSize: number;
|
|
6
|
+
horizontal: boolean;
|
|
7
|
+
rtl: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare const DefaultWindow: import("react").ForwardRefExoticComponent<CustomWindowComponentProps & import("react").RefAttributes<any>>;
|
|
10
|
+
export type CustomWindowComponent = typeof DefaultWindow;
|
|
11
|
+
export interface CustomItemComponentProps {
|
|
3
12
|
style: CSSProperties;
|
|
4
13
|
children: ReactNode;
|
|
5
14
|
}
|
|
6
|
-
export type
|
|
7
|
-
type
|
|
15
|
+
export type CustomItemComponent = React.ForwardRefExoticComponent<React.PropsWithoutRef<CustomItemComponentProps> & React.RefAttributes<any>>;
|
|
16
|
+
type CustomItemComponentOrElement = keyof JSX.IntrinsicElements | CustomItemComponent;
|
|
8
17
|
/**
|
|
9
18
|
* Methods of {@link List}.
|
|
10
19
|
*/
|
|
@@ -63,25 +72,16 @@ export interface ListProps {
|
|
|
63
72
|
* Inline style prop to override style of scrollable element.
|
|
64
73
|
*/
|
|
65
74
|
style?: CSSProperties;
|
|
66
|
-
/**
|
|
67
|
-
* Inline style prop to override style of inner element.
|
|
68
|
-
*/
|
|
69
|
-
innerStyle?: CSSProperties;
|
|
70
75
|
/**
|
|
71
76
|
* Customized element type for scrollable element.
|
|
72
77
|
* @defaultValue "div"
|
|
73
78
|
*/
|
|
74
|
-
element?:
|
|
75
|
-
/**
|
|
76
|
-
* Customized element type for inner element.
|
|
77
|
-
* @defaultValue "div"
|
|
78
|
-
*/
|
|
79
|
-
innerElement?: CustomElementType;
|
|
79
|
+
element?: CustomWindowComponent;
|
|
80
80
|
/**
|
|
81
81
|
* Customized element type for item element.
|
|
82
82
|
* @defaultValue "div"
|
|
83
83
|
*/
|
|
84
|
-
itemElement?:
|
|
84
|
+
itemElement?: CustomItemComponentOrElement;
|
|
85
85
|
/**
|
|
86
86
|
* Callback invoked when scrolling reached to the end. The margin from the end is specified by {@link endThreshold}.
|
|
87
87
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "virtua",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Simple, fast, small and flexible virtual list component for React.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
@@ -31,13 +31,14 @@
|
|
|
31
31
|
"@emotion/styled": "11.10.6",
|
|
32
32
|
"@faker-js/faker": "7.6.0",
|
|
33
33
|
"@mui/material": "5.11.15",
|
|
34
|
-
"@rollup/plugin-babel": "
|
|
35
|
-
"@rollup/plugin-typescript": "
|
|
36
|
-
"@storybook/addon-docs": "7.0.
|
|
37
|
-
"@storybook/react": "7.0.
|
|
38
|
-
"@storybook/react-webpack5": "^7.0.
|
|
39
|
-
"@storybook/test-runner": "
|
|
40
|
-
"@
|
|
34
|
+
"@rollup/plugin-babel": "6.0.3",
|
|
35
|
+
"@rollup/plugin-typescript": "11.1.0",
|
|
36
|
+
"@storybook/addon-docs": "7.0.2",
|
|
37
|
+
"@storybook/react": "7.0.2",
|
|
38
|
+
"@storybook/react-webpack5": "^7.0.2",
|
|
39
|
+
"@storybook/test-runner": "0.10.0-next.13",
|
|
40
|
+
"@tanstack/react-virtual": "3.0.0-alpha.0",
|
|
41
|
+
"@testing-library/react": "14.0.0",
|
|
41
42
|
"@types/react": "18.0.32",
|
|
42
43
|
"@types/react-virtualized": "9.21.21",
|
|
43
44
|
"@types/react-window": "1.8.5",
|
|
@@ -45,8 +46,8 @@
|
|
|
45
46
|
"@typescript-eslint/parser": "5.55.0",
|
|
46
47
|
"babel-plugin-replace-import-extensions": "1.0.1",
|
|
47
48
|
"concurrently": "7.2.2",
|
|
48
|
-
"esbuild": "0.15
|
|
49
|
-
"esbuild-loader": "
|
|
49
|
+
"esbuild": "0.17.15",
|
|
50
|
+
"esbuild-loader": "3.0.1",
|
|
50
51
|
"eslint": "8.36.0",
|
|
51
52
|
"eslint-plugin-react-hooks": "4.6.0",
|
|
52
53
|
"jest": "29.0.2",
|
|
@@ -57,18 +58,17 @@
|
|
|
57
58
|
"react-cool-virtual": "0.7.0",
|
|
58
59
|
"react-dom": "18.2.0",
|
|
59
60
|
"react-is": "18.2.0",
|
|
60
|
-
"react-virtual": "2.10.4",
|
|
61
61
|
"react-virtualized": "9.22.3",
|
|
62
|
-
"react-virtuoso": "4.
|
|
62
|
+
"react-virtuoso": "4.2.0",
|
|
63
63
|
"react-window": "1.8.8",
|
|
64
64
|
"rimraf": "3.0.2",
|
|
65
|
-
"rollup": "
|
|
65
|
+
"rollup": "3.20.2",
|
|
66
66
|
"rollup-plugin-terser": "7.0.2",
|
|
67
|
-
"storybook": "^7.0.
|
|
67
|
+
"storybook": "^7.0.2",
|
|
68
68
|
"ts-jest": "29.0.5",
|
|
69
|
-
"typedoc": "0.23.
|
|
69
|
+
"typedoc": "0.23.28",
|
|
70
70
|
"typedoc-plugin-markdown": "3.14.0",
|
|
71
|
-
"typescript": "5.0.
|
|
71
|
+
"typescript": "5.0.4",
|
|
72
72
|
"wait-on": "6.0.1"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|