react-virtuoso
Advanced tools
Comparing version 0.4.4 to 0.4.5
@@ -1136,6 +1136,8 @@ 'use strict'; | ||
let currentEndIndex = 0; | ||
list$.pipe(map(items => items.length ? items[items.length - 1].index : 0)).subscribe(endIndex => { | ||
if (currentEndIndex < endIndex) { | ||
currentEndIndex = endIndex; | ||
endReached$.next(endIndex); | ||
list$.pipe(map(items => items.length ? items[items.length - 1].index : 0)).pipe(withLatestFrom(totalCount$.subscribe)).subscribe(([endIndex, totalCount]) => { | ||
if (endIndex == totalCount - 1) { | ||
if (currentEndIndex !== endIndex) { | ||
currentEndIndex = endIndex; | ||
endReached$.next(endIndex); | ||
} | ||
} | ||
@@ -1142,0 +1144,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=require("react"),r=e(t),n=e(require("resize-observer-polyfill"));const i=t.createContext(void 0);function s(e){return function(...t){const r=function(...e){return 0===e.length?(e,t)=>t(e):1===e.length?e[0]:(t,r)=>{let n=e=>r(e);e.slice().reverse().forEach(e=>{const t=n;n=(r=>e(r,t))}),n(t)}}(...t);return function(e,t){const r=r=>e(e=>t(e,r));return{subscribe:r,pipe:s(r)}}(e,r)}}function o(e){let t=[],r=e;const n=e=>(t.push(e),void 0!==r&&e(r),()=>{t=t.filter(t=>t!==e)});return{next:e=>{e!==r&&(r=e,t.forEach(t=>t(e)))},subscribe:n,pipe:s(n),subscribers:t}}function l(...e){const t=Array(e.length).fill(!1),r=Array(e.length);let n=[];const i=e=>{t.every(e=>e)&&e.forEach(e=>e(r))};e.forEach((e,s)=>{e(e=>{t[s]=!0,r[s]=e,i(n)})});const o=e=>(n.push(e),i([e]),()=>{n=n.filter(t=>t!==e)});return{subscribe:o,pipe:s(o)}}function u(e){return(t,r)=>{r(e(t))}}function a(e){return(t,r)=>r(e)}function h(e){return(t,r)=>{e>0?e--:r(t)}}function c(e){return(t,r)=>{e(t)&&r(t)}}function f(...e){const t=Array(e.length).fill(!1),r=Array(e.length);return e.forEach((e,n)=>{e(e=>{r[n]=e,t[n]=!0})}),(e,n)=>{t.every(e=>e)&&n([e,...r])}}class d{constructor(){this.level=0}rebalance(){return this}adjust(){return this}remove(){return this}find(){}findWith(){}findMax(){return-Infinity}findMaxValue(){}insert(e,t){return new m({key:e,value:t,level:1})}walkWithin(){return[]}walk(){return[]}ranges(){return[]}rangesWithin(){return[]}empty(){return!0}isSingle(){return!0}isInvariant(){return!0}keys(){return[]}}const p=new d;Object.freeze(p);class g extends Error{constructor(e){super(`Unreachable case: ${e}`)}}class m{constructor({key:e,value:t,level:r,left:n=p,right:i=p}){this.key=e,this.value=t,this.level=r,this.left=n,this.right=i}remove(e){const{left:t,right:r}=this;if(e===this.key){if(t.empty())return r;if(r.empty())return t;{const[e,r]=t.last();return this.clone({key:e,value:r,left:t.deleteLast()}).adjust()}}return e<this.key?this.clone({left:t.remove(e)}).adjust():this.clone({right:r.remove(e)}).adjust()}empty(){return!1}find(e){return e===this.key?this.value:e<this.key?this.left.find(e):this.right.find(e)}findWith(e){const t=e(this.value);switch(t){case-1:return this.left.findWith(e);case 0:return[this.key,this.value];case 1:return this.right.findWith(e);default:throw new g(t)}}findMax(e){if(this.key===e)return e;if(this.key<e){const t=this.right.findMax(e);return-Infinity===t?this.key:t}return this.left.findMax(e)}findMaxValue(e){if(this.key===e)return this.value;if(this.key<e){const t=this.right.findMaxValue(e);return void 0===t?this.value:t}return this.left.findMaxValue(e)}insert(e,t){return e===this.key?this.clone({key:e,value:t}):e<this.key?this.clone({left:this.left.insert(e,t)}).rebalance():this.clone({right:this.right.insert(e,t)}).rebalance()}walkWithin(e,t){const{key:r,value:n}=this;let i=[];return r>e&&(i=i.concat(this.left.walkWithin(e,t))),r>=e&&r<=t&&i.push({key:r,value:n}),r<=t&&(i=i.concat(this.right.walkWithin(e,t))),i}walk(){return[...this.left.walk(),{key:this.key,value:this.value},...this.right.walk()]}last(){return this.right.empty()?[this.key,this.value]:this.right.last()}deleteLast(){return this.right.empty()?this.left:this.clone({right:this.right.deleteLast()}).adjust()}clone(e){return new m({key:void 0!==e.key?e.key:this.key,value:void 0!==e.value?e.value:this.value,level:void 0!==e.level?e.level:this.level,left:void 0!==e.left?e.left:this.left,right:void 0!==e.right?e.right:this.right})}isSingle(){return this.level>this.right.level}rebalance(){return this.skew().split()}adjust(){const{left:e,right:t,level:r}=this;if(t.level>=r-1&&e.level>=r-1)return this;if(r>t.level+1){if(e.isSingle())return this.clone({level:r-1}).skew();if(e.empty()||e.right.empty())throw new Error("Unexpected empty nodes");return e.right.clone({left:e.clone({right:e.right.left}),right:this.clone({left:e.right.right,level:r-1}),level:r})}if(this.isSingle())return this.clone({level:r-1}).split();if(t.empty()||t.left.empty())throw new Error("Unexpected empty nodes");{const e=t.left,n=e.isSingle()?t.level-1:t.level;return e.clone({left:this.clone({right:e.left,level:r-1}),right:t.clone({left:e.right,level:n}).split(),level:e.level+1})}}isInvariant(){const{left:e,right:t,level:r}=this;return r===e.level+1&&((r===t.level||r===t.level+1)&&(!(!t.empty()&&r<=t.right.level)&&(e.isInvariant()&&t.isInvariant())))}keys(){return[...this.left.keys(),this.key,...this.right.keys()]}ranges(){return this.toRanges(this.walk())}rangesWithin(e,t){return this.toRanges(this.walkWithin(e,t))}toRanges(e){if(0===e.length)return[];const t=e[0];let{key:r,value:n}=t;const i=[];for(let t=1;t<=e.length;t++){let s=e[t],o=s?s.key-1:Infinity;i.push({start:r,end:o,value:n}),s&&(r=s.key,n=s.value)}return i}split(){const{right:e,level:t}=this;return e.empty()||e.right.empty()||e.level!=t||e.right.level!=t?this:e.clone({left:this.clone({right:e.left}),level:t+1})}skew(){const{left:e}=this;return e.empty()||e.level!==this.level?this:e.clone({right:this.clone({left:e.right})})}}class v{constructor(e){this.root=e}static empty(){return new v(p)}find(e){return this.root.find(e)}findMax(e){return this.root.findMax(e)}findMaxValue(e){if(this.empty())throw new Error("Searching for max value in an empty tree");return this.root.findMaxValue(e)}findWith(e){return this.root.findWith(e)}insert(e,t){return new v(this.root.insert(e,t))}remove(e){return new v(this.root.remove(e))}empty(){return this.root.empty()}keys(){return this.root.keys()}walk(){return this.root.walk()}walkWithin(e,t){let r=this.root.findMax(e);return this.root.walkWithin(r,t)}ranges(){return this.root.ranges()}rangesWithin(e,t){let r=this.root.findMax(e);return this.root.rangesWithin(r,t)}isInvariant(){return this.root.isInvariant()}}class y{static create(){return new y(v.empty())}constructor(e){this.rangeTree=e;let t=v.empty(),r=0;for(const{start:n,end:i,value:s}of e.ranges())t=t.insert(r,{startIndex:n,endIndex:i,size:s}),Infinity!==i&&(r+=(i-n+1)*s);this.offsetTree=t}empty(){return this.rangeTree.empty()}insert(e,t,r){let n=this.rangeTree;if(n.empty())return new y(n.insert(0,r));const i=n.rangesWithin(e-1,t+1);if(i.some(n=>n.start===e&&(n.end===t||Infinity===n.end)&&n.value===r))return this;let s=!1,o=!1;for(const{start:e,end:l,value:u}of i)s?(t>=e||r===u)&&(n=n.remove(e)):(o=u!==r,s=!0),l>t&&t>=e&&(u===r||isNaN(u)||(n=n.insert(t+1,u)));return o&&(n=n.insert(e,r)),n===this.rangeTree?this:new y(n)}insertException(e,t){return this.empty()?new y(this.rangeTree.insert(1,NaN).insert(e,t)):this.insert(e,e,t)}offsetOf(e){if(this.offsetTree.empty())return 0;const t=this.offsetTree.findWith(t=>t.startIndex>e?-1:t.endIndex<e?1:0);if(t){const[r,{startIndex:n,size:i}]=t;return r+(e-n)*i}throw new Error(`Requested offset outside of the known ones, index: ${e}`)}itemAt(e){const t=this.rangeTree.findMaxValue(e);return{index:e,size:t,offset:NaN}}indexRange(e,t){if(0===t)return[];if(this.rangeTree.empty())return[{index:0,size:0,offset:NaN}];const r=this.rangeTree.rangesWithin(e,t),n=[];for(const i of r){const r=Math.max(e,i.start),s=void 0===i.end?Infinity:i.end,o=Math.min(t,s);for(let e=r;e<=o;e++)n.push({index:e,size:i.value,offset:NaN})}return n}range(e,t,r=0,n=Infinity){if(this.offsetTree.empty())return[{index:0,size:0,offset:0}];const i=this.offsetTree.rangesWithin(e,t),s=[];for(let{start:o,value:{startIndex:l,endIndex:u,size:a}}of i){let i=o,h=l;if(o<e&&(h+=Math.floor((e-o)/a),i+=(h-l)*a),h<r&&(i+=(r-h)*a,h=r),isNaN(a))return s.push({index:h,size:0,offset:i}),s;u=Math.min(u,n);for(let e=h;e<=u&&!(i>t);e++)s.push({index:e,size:a,offset:i}),i+=a}return s}total(e){const t=this.rangeTree.rangesWithin(0,e);let r=0;for(let{start:n,end:i,value:s}of t)i=Math.min(i,e),r+=(i-n+1)*s;return r}getOffsets(e){let t=v.empty();return e.forEach(e=>{const r=this.offsetOf(e);t=t.insert(r,e)}),new x(t)}}class x{constructor(e){this.tree=e}findMaxValue(e){return this.tree.findMaxValue(e)}empty(){return this.tree.empty()}}class b{transpose(e){return e.map(e=>({groupIndex:0,index:e.index,offset:e.offset,size:e.size,transposedIndex:e.index,type:"item"}))}}class k{constructor(e){this.count=e.reduce((e,t)=>e+t+1,0);let t=v.empty(),r=0,n=0;for(let i of e)t=t.insert(n,[r,n]),r++,n+=i+1;this.tree=t}totalCount(){return this.count}transpose(e){return e.map(e=>{const t=this.tree.find(e.index);if(t)return{groupIndex:t[0],index:e.index,offset:e.offset,size:e.size,type:"group"};const[r]=this.tree.findMaxValue(e.index);return{groupIndex:r,index:e.index,offset:e.offset,size:e.size,transposedIndex:e.index-r-1,type:"item"}})}groupIndices(){return this.tree.keys()}}function w(e){let t,r=e=>{t&&t(e)},n=!1;return i=>{t=i,n||(e.subscribe(r),n=!0)}}function I(e){return e.next}const E=e=>e.length>0?e[0].offset:0,M=([e,t])=>e.total(t-1),C=({overscan:e=0,totalCount:t=0,itemHeight:r})=>{const n=o(0),i=o(0),s=o(0),d=o(0),p=o(),g=o(t),m=o(),v=o(),x=o(!1);let C=y.create();const z=o([]);r&&(C=C.insert(0,0,r));const W=o(C);r||p.pipe(f(W.subscribe,z.subscribe)).subscribe(([e,t,r])=>{let n=t;for(let{start:t,end:r,size:i}of e)n=n.insert(t,r,i);n!==t&&W.next(n)});let H=new b;m.subscribe(e=>{H=new k(e),g.next(H.totalCount()),z.next(H.groupIndices())});const R=l(W.subscribe,g.subscribe).pipe(u(M)),T=l(R.subscribe,d.subscribe).pipe(u(([e,t])=>e+t)),V=l(W.subscribe,z.subscribe).pipe(u(([e,t])=>e.getOffsets(t))),S=o([]);l(W.subscribe,v.subscribe,g.subscribe).pipe(c(e=>e[1]>0),u(([e,t,r])=>{const n=Math.max(0,Math.min(t-1,r));return H.transpose(e.indexRange(0,n))})).subscribe(S.next),l(W.subscribe,V.subscribe,s.subscribe).pipe(c(e=>!e[1].empty()&&!e[0].empty()),f(S.subscribe),u(([[e,t,r],n])=>{const i=t.findMaxValue(r);if(1===n.length&&n[0].index===i)return n;const s=e.itemAt(i);return H.transpose([s])})).subscribe(S.next);const N=S.pipe(u(e=>e.reduce((e,t)=>e+t.size,0))),j=S.pipe(u(e=>e.length&&e[e.length-1].index+1)),L=l(n.subscribe,s.subscribe,N.subscribe,i.subscribe,d.subscribe,j.subscribe,g.subscribe,W.subscribe).pipe(function(e,t){let r=t;return(t,n)=>{n(r=e(r,t))}}((e=>(t,[r,n,i,s,o,l,u,a])=>{const h=t.length;if(0===u)return 0===h?t:[];const c=E(t),f=c-n+s-o-i,d=Math.max(u-1,0),p=h>0&&(t[0].index<l||t[h-1].index>d);if(f<r||p){const t=Math.max(n+i,i),s=n+r+2*e-1,o=H.transpose(a.range(t,s,l,d));return o}if(c>n+i){const t=Math.max(n+i-2*e,i),s=n+r-1;return H.transpose(a.range(t,s,l,d))}return t})(e),[])),O=o(0);let A=0;L.pipe(u(e=>e.length?e[e.length-1].index:0)).subscribe(e=>{A<e&&(A=e,O.next(e))});const P=l(L.subscribe,s.subscribe,N.subscribe).pipe(u(([e,t,r])=>E(e)-t-r));return s.pipe(h(1),a(!0)).subscribe(x.next),s.pipe(h(1),a(!1),function(e){let t,r;return(n,i)=>{t=n,r&&clearTimeout(r),r=setTimeout(()=>{i(t)},e)}}(200)).subscribe(x.next),{groupCounts:I(m),itemHeights:I(p),footerHeight:I(d),listHeight:I(i),viewportHeight:I(n),scrollTop:I(s),topItemCount:I(v),totalCount:I(g),list:w(L),topList:w(S),listOffset:w(P),totalHeight:w(T),endReached:w(O),isScrolling:w(x),stickyItems:w(z)}},z=(e,r,i)=>{const s=t.useRef(null),o=t.useRef(0),l=new n(t=>{const r=t[0].contentRect.height;o.current!==r&&(o.current=r,i&&i(t[0].target),e(r))});return e=>{e?(l.observe(e),r&&r(e),s.current=e):(l.unobserve(s.current),s.current=null)}};function W(e,r){const[n,i]=t.useState(r);return t.useLayoutEffect(()=>{e(i)},[]),n}const H={height:"40rem",overflowY:"auto",WebkitOverflowScrolling:"touch",position:"relative",outline:"none"},R=({children:e,style:n})=>{const{scrollTop:s}=t.useContext(i),o=t.useRef(null),l=t.useCallback(e=>{s(e.target.scrollTop)},[]),u=t.useCallback(e=>{e?(e.addEventListener("scroll",l,{passive:!0}),o.current=e):o.current.removeEventListener("scroll",l)},[]);return r.createElement("div",{ref:u,style:{...H,...n},tabIndex:0},e)},T=({list:e,transform:n="",render:s})=>{const{stickyItems:o}=t.useContext(i),l=W(e,[]),u=W(o,[]),a=t.useCallback(e=>{const t=u.some(t=>t===e),r={transform:n,zIndex:t?2:void 0,position:t?"relative":void 0};return r},[u,n]);return 0===l.length?null:r.createElement(r.Fragment,null,l.map(e=>r.createElement("div",{key:e.index,"data-index":e.index,"data-known-size":e.size,style:a(e.index)},s(e))))},V=()=>{const e=W(t.useContext(i).totalHeight,0);return r.createElement("div",{style:{height:`${e}px`,position:"absolute",top:0}}," ")},S=({footer:e})=>{const n=z(t.useContext(i).footerHeight);return r.createElement("footer",{ref:n},e())},N={top:0,position:"sticky",height:"100%",overflow:"hidden",WebkitBackfaceVisibility:"hidden"},j=({style:e,footer:n,item:s,fixedItemHeight:o})=>{const{itemHeights:l,listHeight:u,viewportHeight:a,listOffset:h,list:c,topList:f}=t.useContext(i),d=W(h,0),p=t.useCallback(e=>{const t=[];for(var r=0,n=e.length;r<n;r++){let n=e.item(r);if(!n||"DIV"!==n.tagName)continue;const i=parseInt(n.dataset.index),s=n.offsetHeight;0===t.length||t[t.length-1].size!==s?t.push({start:i,end:i,size:s}):t[t.length-1].end++}t.length>0&&l(t)},[]),g=z(u,()=>{},e=>{o||p(e.children)}),m=z(a,e=>{""===e.style.position&&(e.style.position="-webkit-sticky")}),v=`translateY(${d}px)`,y=`translateY(${-d}px)`;return r.createElement(R,{style:e},r.createElement("div",{style:N,ref:m},r.createElement("div",{style:{transform:v}},r.createElement("div",{ref:g},r.createElement(T,{list:f,transform:y,render:s}),r.createElement(T,{list:c,render:s}),n&&r.createElement(S,{footer:n})))),r.createElement(V,null))},L=({contextValue:e,style:t,item:n,footer:s,itemHeight:o})=>r.createElement(i.Provider,{value:e},r.createElement(j,{style:t||{},item:n,footer:s,fixedItemHeight:void 0!==o}));exports.GroupedVirtuoso=class extends t.PureComponent{constructor(e){super(e),this.itemRender=(e=>"group"==e.type?this.props.group(e.groupIndex):this.props.item(e.transposedIndex,e.groupIndex)),this.state=C(e)}static getDerivedStateFromProps(e,t){return t.endReached(e.endReached),t.isScrolling(e.scrollingStateChange),t.groupCounts(e.groupCounts),null}render(){return r.createElement(L,{contextValue:this.state,style:this.props.style,item:this.itemRender,footer:this.props.footer,itemHeight:this.props.itemHeight})}},exports.Virtuoso=class extends t.PureComponent{constructor(e){super(e),this.itemRenderer=(e=>this.props.item(e.index)),this.state=C(e)}static getDerivedStateFromProps(e,t){return t.isScrolling(e.scrollingStateChange),t.endReached(e.endReached),t.topItemCount(e.topItems||0),t.totalCount(e.totalCount),null}render(){return r.createElement(L,{contextValue:this.state,style:this.props.style,item:this.itemRenderer,footer:this.props.footer,itemHeight:this.props.itemHeight})}},exports.VirtuosoPresentation=L; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=require("react"),r=e(t),n=e(require("resize-observer-polyfill"));const i=t.createContext(void 0);function s(e){return function(...t){const r=function(...e){return 0===e.length?(e,t)=>t(e):1===e.length?e[0]:(t,r)=>{let n=e=>r(e);e.slice().reverse().forEach(e=>{const t=n;n=(r=>e(r,t))}),n(t)}}(...t);return function(e,t){const r=r=>e(e=>t(e,r));return{subscribe:r,pipe:s(r)}}(e,r)}}function o(e){let t=[],r=e;const n=e=>(t.push(e),void 0!==r&&e(r),()=>{t=t.filter(t=>t!==e)});return{next:e=>{e!==r&&(r=e,t.forEach(t=>t(e)))},subscribe:n,pipe:s(n),subscribers:t}}function l(...e){const t=Array(e.length).fill(!1),r=Array(e.length);let n=[];const i=e=>{t.every(e=>e)&&e.forEach(e=>e(r))};e.forEach((e,s)=>{e(e=>{t[s]=!0,r[s]=e,i(n)})});const o=e=>(n.push(e),i([e]),()=>{n=n.filter(t=>t!==e)});return{subscribe:o,pipe:s(o)}}function u(e){return(t,r)=>{r(e(t))}}function a(e){return(t,r)=>r(e)}function h(e){return(t,r)=>{e>0?e--:r(t)}}function c(e){return(t,r)=>{e(t)&&r(t)}}function f(...e){const t=Array(e.length).fill(!1),r=Array(e.length);return e.forEach((e,n)=>{e(e=>{r[n]=e,t[n]=!0})}),(e,n)=>{t.every(e=>e)&&n([e,...r])}}class d{constructor(){this.level=0}rebalance(){return this}adjust(){return this}remove(){return this}find(){}findWith(){}findMax(){return-Infinity}findMaxValue(){}insert(e,t){return new m({key:e,value:t,level:1})}walkWithin(){return[]}walk(){return[]}ranges(){return[]}rangesWithin(){return[]}empty(){return!0}isSingle(){return!0}isInvariant(){return!0}keys(){return[]}}const p=new d;Object.freeze(p);class g extends Error{constructor(e){super(`Unreachable case: ${e}`)}}class m{constructor({key:e,value:t,level:r,left:n=p,right:i=p}){this.key=e,this.value=t,this.level=r,this.left=n,this.right=i}remove(e){const{left:t,right:r}=this;if(e===this.key){if(t.empty())return r;if(r.empty())return t;{const[e,r]=t.last();return this.clone({key:e,value:r,left:t.deleteLast()}).adjust()}}return e<this.key?this.clone({left:t.remove(e)}).adjust():this.clone({right:r.remove(e)}).adjust()}empty(){return!1}find(e){return e===this.key?this.value:e<this.key?this.left.find(e):this.right.find(e)}findWith(e){const t=e(this.value);switch(t){case-1:return this.left.findWith(e);case 0:return[this.key,this.value];case 1:return this.right.findWith(e);default:throw new g(t)}}findMax(e){if(this.key===e)return e;if(this.key<e){const t=this.right.findMax(e);return-Infinity===t?this.key:t}return this.left.findMax(e)}findMaxValue(e){if(this.key===e)return this.value;if(this.key<e){const t=this.right.findMaxValue(e);return void 0===t?this.value:t}return this.left.findMaxValue(e)}insert(e,t){return e===this.key?this.clone({key:e,value:t}):e<this.key?this.clone({left:this.left.insert(e,t)}).rebalance():this.clone({right:this.right.insert(e,t)}).rebalance()}walkWithin(e,t){const{key:r,value:n}=this;let i=[];return r>e&&(i=i.concat(this.left.walkWithin(e,t))),r>=e&&r<=t&&i.push({key:r,value:n}),r<=t&&(i=i.concat(this.right.walkWithin(e,t))),i}walk(){return[...this.left.walk(),{key:this.key,value:this.value},...this.right.walk()]}last(){return this.right.empty()?[this.key,this.value]:this.right.last()}deleteLast(){return this.right.empty()?this.left:this.clone({right:this.right.deleteLast()}).adjust()}clone(e){return new m({key:void 0!==e.key?e.key:this.key,value:void 0!==e.value?e.value:this.value,level:void 0!==e.level?e.level:this.level,left:void 0!==e.left?e.left:this.left,right:void 0!==e.right?e.right:this.right})}isSingle(){return this.level>this.right.level}rebalance(){return this.skew().split()}adjust(){const{left:e,right:t,level:r}=this;if(t.level>=r-1&&e.level>=r-1)return this;if(r>t.level+1){if(e.isSingle())return this.clone({level:r-1}).skew();if(e.empty()||e.right.empty())throw new Error("Unexpected empty nodes");return e.right.clone({left:e.clone({right:e.right.left}),right:this.clone({left:e.right.right,level:r-1}),level:r})}if(this.isSingle())return this.clone({level:r-1}).split();if(t.empty()||t.left.empty())throw new Error("Unexpected empty nodes");{const e=t.left,n=e.isSingle()?t.level-1:t.level;return e.clone({left:this.clone({right:e.left,level:r-1}),right:t.clone({left:e.right,level:n}).split(),level:e.level+1})}}isInvariant(){const{left:e,right:t,level:r}=this;return r===e.level+1&&((r===t.level||r===t.level+1)&&(!(!t.empty()&&r<=t.right.level)&&(e.isInvariant()&&t.isInvariant())))}keys(){return[...this.left.keys(),this.key,...this.right.keys()]}ranges(){return this.toRanges(this.walk())}rangesWithin(e,t){return this.toRanges(this.walkWithin(e,t))}toRanges(e){if(0===e.length)return[];const t=e[0];let{key:r,value:n}=t;const i=[];for(let t=1;t<=e.length;t++){let s=e[t],o=s?s.key-1:Infinity;i.push({start:r,end:o,value:n}),s&&(r=s.key,n=s.value)}return i}split(){const{right:e,level:t}=this;return e.empty()||e.right.empty()||e.level!=t||e.right.level!=t?this:e.clone({left:this.clone({right:e.left}),level:t+1})}skew(){const{left:e}=this;return e.empty()||e.level!==this.level?this:e.clone({right:this.clone({left:e.right})})}}class v{constructor(e){this.root=e}static empty(){return new v(p)}find(e){return this.root.find(e)}findMax(e){return this.root.findMax(e)}findMaxValue(e){if(this.empty())throw new Error("Searching for max value in an empty tree");return this.root.findMaxValue(e)}findWith(e){return this.root.findWith(e)}insert(e,t){return new v(this.root.insert(e,t))}remove(e){return new v(this.root.remove(e))}empty(){return this.root.empty()}keys(){return this.root.keys()}walk(){return this.root.walk()}walkWithin(e,t){let r=this.root.findMax(e);return this.root.walkWithin(r,t)}ranges(){return this.root.ranges()}rangesWithin(e,t){let r=this.root.findMax(e);return this.root.rangesWithin(r,t)}isInvariant(){return this.root.isInvariant()}}class y{static create(){return new y(v.empty())}constructor(e){this.rangeTree=e;let t=v.empty(),r=0;for(const{start:n,end:i,value:s}of e.ranges())t=t.insert(r,{startIndex:n,endIndex:i,size:s}),Infinity!==i&&(r+=(i-n+1)*s);this.offsetTree=t}empty(){return this.rangeTree.empty()}insert(e,t,r){let n=this.rangeTree;if(n.empty())return new y(n.insert(0,r));const i=n.rangesWithin(e-1,t+1);if(i.some(n=>n.start===e&&(n.end===t||Infinity===n.end)&&n.value===r))return this;let s=!1,o=!1;for(const{start:e,end:l,value:u}of i)s?(t>=e||r===u)&&(n=n.remove(e)):(o=u!==r,s=!0),l>t&&t>=e&&(u===r||isNaN(u)||(n=n.insert(t+1,u)));return o&&(n=n.insert(e,r)),n===this.rangeTree?this:new y(n)}insertException(e,t){return this.empty()?new y(this.rangeTree.insert(1,NaN).insert(e,t)):this.insert(e,e,t)}offsetOf(e){if(this.offsetTree.empty())return 0;const t=this.offsetTree.findWith(t=>t.startIndex>e?-1:t.endIndex<e?1:0);if(t){const[r,{startIndex:n,size:i}]=t;return r+(e-n)*i}throw new Error(`Requested offset outside of the known ones, index: ${e}`)}itemAt(e){const t=this.rangeTree.findMaxValue(e);return{index:e,size:t,offset:NaN}}indexRange(e,t){if(0===t)return[];if(this.rangeTree.empty())return[{index:0,size:0,offset:NaN}];const r=this.rangeTree.rangesWithin(e,t),n=[];for(const i of r){const r=Math.max(e,i.start),s=void 0===i.end?Infinity:i.end,o=Math.min(t,s);for(let e=r;e<=o;e++)n.push({index:e,size:i.value,offset:NaN})}return n}range(e,t,r=0,n=Infinity){if(this.offsetTree.empty())return[{index:0,size:0,offset:0}];const i=this.offsetTree.rangesWithin(e,t),s=[];for(let{start:o,value:{startIndex:l,endIndex:u,size:a}}of i){let i=o,h=l;if(o<e&&(h+=Math.floor((e-o)/a),i+=(h-l)*a),h<r&&(i+=(r-h)*a,h=r),isNaN(a))return s.push({index:h,size:0,offset:i}),s;u=Math.min(u,n);for(let e=h;e<=u&&!(i>t);e++)s.push({index:e,size:a,offset:i}),i+=a}return s}total(e){const t=this.rangeTree.rangesWithin(0,e);let r=0;for(let{start:n,end:i,value:s}of t)i=Math.min(i,e),r+=(i-n+1)*s;return r}getOffsets(e){let t=v.empty();return e.forEach(e=>{const r=this.offsetOf(e);t=t.insert(r,e)}),new x(t)}}class x{constructor(e){this.tree=e}findMaxValue(e){return this.tree.findMaxValue(e)}empty(){return this.tree.empty()}}class b{transpose(e){return e.map(e=>({groupIndex:0,index:e.index,offset:e.offset,size:e.size,transposedIndex:e.index,type:"item"}))}}class k{constructor(e){this.count=e.reduce((e,t)=>e+t+1,0);let t=v.empty(),r=0,n=0;for(let i of e)t=t.insert(n,[r,n]),r++,n+=i+1;this.tree=t}totalCount(){return this.count}transpose(e){return e.map(e=>{const t=this.tree.find(e.index);if(t)return{groupIndex:t[0],index:e.index,offset:e.offset,size:e.size,type:"group"};const[r]=this.tree.findMaxValue(e.index);return{groupIndex:r,index:e.index,offset:e.offset,size:e.size,transposedIndex:e.index-r-1,type:"item"}})}groupIndices(){return this.tree.keys()}}function w(e){let t,r=e=>{t&&t(e)},n=!1;return i=>{t=i,n||(e.subscribe(r),n=!0)}}function I(e){return e.next}const E=e=>e.length>0?e[0].offset:0,M=([e,t])=>e.total(t-1),C=({overscan:e=0,totalCount:t=0,itemHeight:r})=>{const n=o(0),i=o(0),s=o(0),d=o(0),p=o(),g=o(t),m=o(),v=o(),x=o(!1);let C=y.create();const z=o([]);r&&(C=C.insert(0,0,r));const W=o(C);r||p.pipe(f(W.subscribe,z.subscribe)).subscribe(([e,t,r])=>{let n=t;for(let{start:t,end:r,size:i}of e)n=n.insert(t,r,i);n!==t&&W.next(n)});let H=new b;m.subscribe(e=>{H=new k(e),g.next(H.totalCount()),z.next(H.groupIndices())});const R=l(W.subscribe,g.subscribe).pipe(u(M)),T=l(R.subscribe,d.subscribe).pipe(u(([e,t])=>e+t)),V=l(W.subscribe,z.subscribe).pipe(u(([e,t])=>e.getOffsets(t))),S=o([]);l(W.subscribe,v.subscribe,g.subscribe).pipe(c(e=>e[1]>0),u(([e,t,r])=>{const n=Math.max(0,Math.min(t-1,r));return H.transpose(e.indexRange(0,n))})).subscribe(S.next),l(W.subscribe,V.subscribe,s.subscribe).pipe(c(e=>!e[1].empty()&&!e[0].empty()),f(S.subscribe),u(([[e,t,r],n])=>{const i=t.findMaxValue(r);if(1===n.length&&n[0].index===i)return n;const s=e.itemAt(i);return H.transpose([s])})).subscribe(S.next);const N=S.pipe(u(e=>e.reduce((e,t)=>e+t.size,0))),j=S.pipe(u(e=>e.length&&e[e.length-1].index+1)),L=l(n.subscribe,s.subscribe,N.subscribe,i.subscribe,d.subscribe,j.subscribe,g.subscribe,W.subscribe).pipe(function(e,t){let r=t;return(t,n)=>{n(r=e(r,t))}}((e=>(t,[r,n,i,s,o,l,u,a])=>{const h=t.length;if(0===u)return 0===h?t:[];const c=E(t),f=c-n+s-o-i,d=Math.max(u-1,0),p=h>0&&(t[0].index<l||t[h-1].index>d);if(f<r||p){const t=Math.max(n+i,i),s=n+r+2*e-1,o=H.transpose(a.range(t,s,l,d));return o}if(c>n+i){const t=Math.max(n+i-2*e,i),s=n+r-1;return H.transpose(a.range(t,s,l,d))}return t})(e),[])),O=o(0);let A=0;L.pipe(u(e=>e.length?e[e.length-1].index:0)).pipe(f(g.subscribe)).subscribe(([e,t])=>{e==t-1&&A!==e&&(A=e,O.next(e))});const P=l(L.subscribe,s.subscribe,N.subscribe).pipe(u(([e,t,r])=>E(e)-t-r));return s.pipe(h(1),a(!0)).subscribe(x.next),s.pipe(h(1),a(!1),function(e){let t,r;return(n,i)=>{t=n,r&&clearTimeout(r),r=setTimeout(()=>{i(t)},e)}}(200)).subscribe(x.next),{groupCounts:I(m),itemHeights:I(p),footerHeight:I(d),listHeight:I(i),viewportHeight:I(n),scrollTop:I(s),topItemCount:I(v),totalCount:I(g),list:w(L),topList:w(S),listOffset:w(P),totalHeight:w(T),endReached:w(O),isScrolling:w(x),stickyItems:w(z)}},z=(e,r,i)=>{const s=t.useRef(null),o=t.useRef(0),l=new n(t=>{const r=t[0].contentRect.height;o.current!==r&&(o.current=r,i&&i(t[0].target),e(r))});return e=>{e?(l.observe(e),r&&r(e),s.current=e):(l.unobserve(s.current),s.current=null)}};function W(e,r){const[n,i]=t.useState(r);return t.useLayoutEffect(()=>{e(i)},[]),n}const H={height:"40rem",overflowY:"auto",WebkitOverflowScrolling:"touch",position:"relative",outline:"none"},R=({children:e,style:n})=>{const{scrollTop:s}=t.useContext(i),o=t.useRef(null),l=t.useCallback(e=>{s(e.target.scrollTop)},[]),u=t.useCallback(e=>{e?(e.addEventListener("scroll",l,{passive:!0}),o.current=e):o.current.removeEventListener("scroll",l)},[]);return r.createElement("div",{ref:u,style:{...H,...n},tabIndex:0},e)},T=({list:e,transform:n="",render:s})=>{const{stickyItems:o}=t.useContext(i),l=W(e,[]),u=W(o,[]),a=t.useCallback(e=>{const t=u.some(t=>t===e),r={transform:n,zIndex:t?2:void 0,position:t?"relative":void 0};return r},[u,n]);return 0===l.length?null:r.createElement(r.Fragment,null,l.map(e=>r.createElement("div",{key:e.index,"data-index":e.index,"data-known-size":e.size,style:a(e.index)},s(e))))},V=()=>{const e=W(t.useContext(i).totalHeight,0);return r.createElement("div",{style:{height:`${e}px`,position:"absolute",top:0}}," ")},S=({footer:e})=>{const n=z(t.useContext(i).footerHeight);return r.createElement("footer",{ref:n},e())},N={top:0,position:"sticky",height:"100%",overflow:"hidden",WebkitBackfaceVisibility:"hidden"},j=({style:e,footer:n,item:s,fixedItemHeight:o})=>{const{itemHeights:l,listHeight:u,viewportHeight:a,listOffset:h,list:c,topList:f}=t.useContext(i),d=W(h,0),p=t.useCallback(e=>{const t=[];for(var r=0,n=e.length;r<n;r++){let n=e.item(r);if(!n||"DIV"!==n.tagName)continue;const i=parseInt(n.dataset.index),s=n.offsetHeight;0===t.length||t[t.length-1].size!==s?t.push({start:i,end:i,size:s}):t[t.length-1].end++}t.length>0&&l(t)},[]),g=z(u,()=>{},e=>{o||p(e.children)}),m=z(a,e=>{""===e.style.position&&(e.style.position="-webkit-sticky")}),v=`translateY(${d}px)`,y=`translateY(${-d}px)`;return r.createElement(R,{style:e},r.createElement("div",{style:N,ref:m},r.createElement("div",{style:{transform:v}},r.createElement("div",{ref:g},r.createElement(T,{list:f,transform:y,render:s}),r.createElement(T,{list:c,render:s}),n&&r.createElement(S,{footer:n})))),r.createElement(V,null))},L=({contextValue:e,style:t,item:n,footer:s,itemHeight:o})=>r.createElement(i.Provider,{value:e},r.createElement(j,{style:t||{},item:n,footer:s,fixedItemHeight:void 0!==o}));exports.GroupedVirtuoso=class extends t.PureComponent{constructor(e){super(e),this.itemRender=(e=>"group"==e.type?this.props.group(e.groupIndex):this.props.item(e.transposedIndex,e.groupIndex)),this.state=C(e)}static getDerivedStateFromProps(e,t){return t.endReached(e.endReached),t.isScrolling(e.scrollingStateChange),t.groupCounts(e.groupCounts),null}render(){return r.createElement(L,{contextValue:this.state,style:this.props.style,item:this.itemRender,footer:this.props.footer,itemHeight:this.props.itemHeight})}},exports.Virtuoso=class extends t.PureComponent{constructor(e){super(e),this.itemRenderer=(e=>this.props.item(e.index)),this.state=C(e)}static getDerivedStateFromProps(e,t){return t.isScrolling(e.scrollingStateChange),t.endReached(e.endReached),t.topItemCount(e.topItems||0),t.totalCount(e.totalCount),null}render(){return r.createElement(L,{contextValue:this.state,style:this.props.style,item:this.itemRenderer,footer:this.props.footer,itemHeight:this.props.itemHeight})}},exports.VirtuosoPresentation=L; | ||
//# sourceMappingURL=react-virtuoso.cjs.production.js.map |
@@ -1,2 +0,2 @@ | ||
import e,{createContext as t,useRef as r,useState as i,useLayoutEffect as n,useContext as s,useCallback as o,PureComponent as l}from"react";import h from"resize-observer-polyfill";const u=t(void 0);function a(e){return function(...t){const r=function(...e){return 0===e.length?(e,t)=>t(e):1===e.length?e[0]:(t,r)=>{let i=e=>r(e);e.slice().reverse().forEach(e=>{const t=i;i=(r=>e(r,t))}),i(t)}}(...t);return function(e,t){const r=r=>e(e=>t(e,r));return{subscribe:r,pipe:a(r)}}(e,r)}}function c(e){let t=[],r=e;const i=e=>(t.push(e),void 0!==r&&e(r),()=>{t=t.filter(t=>t!==e)});return{next:e=>{e!==r&&(r=e,t.forEach(t=>t(e)))},subscribe:i,pipe:a(i),subscribers:t}}function f(...e){const t=Array(e.length).fill(!1),r=Array(e.length);let i=[];const n=e=>{t.every(e=>e)&&e.forEach(e=>e(r))};e.forEach((e,s)=>{e(e=>{t[s]=!0,r[s]=e,n(i)})});const s=e=>(i.push(e),n([e]),()=>{i=i.filter(t=>t!==e)});return{subscribe:s,pipe:a(s)}}function d(e){return(t,r)=>{r(e(t))}}function p(e){return(t,r)=>r(e)}function g(e){return(t,r)=>{e>0?e--:r(t)}}function m(e){return(t,r)=>{e(t)&&r(t)}}function v(...e){const t=Array(e.length).fill(!1),r=Array(e.length);return e.forEach((e,i)=>{e(e=>{r[i]=e,t[i]=!0})}),(e,i)=>{t.every(e=>e)&&i([e,...r])}}class y{constructor(){this.level=0}rebalance(){return this}adjust(){return this}remove(){return this}find(){}findWith(){}findMax(){return-Infinity}findMaxValue(){}insert(e,t){return new k({key:e,value:t,level:1})}walkWithin(){return[]}walk(){return[]}ranges(){return[]}rangesWithin(){return[]}empty(){return!0}isSingle(){return!0}isInvariant(){return!0}keys(){return[]}}const x=new y;Object.freeze(x);class b extends Error{constructor(e){super(`Unreachable case: ${e}`)}}class k{constructor({key:e,value:t,level:r,left:i=x,right:n=x}){this.key=e,this.value=t,this.level=r,this.left=i,this.right=n}remove(e){const{left:t,right:r}=this;if(e===this.key){if(t.empty())return r;if(r.empty())return t;{const[e,r]=t.last();return this.clone({key:e,value:r,left:t.deleteLast()}).adjust()}}return e<this.key?this.clone({left:t.remove(e)}).adjust():this.clone({right:r.remove(e)}).adjust()}empty(){return!1}find(e){return e===this.key?this.value:e<this.key?this.left.find(e):this.right.find(e)}findWith(e){const t=e(this.value);switch(t){case-1:return this.left.findWith(e);case 0:return[this.key,this.value];case 1:return this.right.findWith(e);default:throw new b(t)}}findMax(e){if(this.key===e)return e;if(this.key<e){const t=this.right.findMax(e);return-Infinity===t?this.key:t}return this.left.findMax(e)}findMaxValue(e){if(this.key===e)return this.value;if(this.key<e){const t=this.right.findMaxValue(e);return void 0===t?this.value:t}return this.left.findMaxValue(e)}insert(e,t){return e===this.key?this.clone({key:e,value:t}):e<this.key?this.clone({left:this.left.insert(e,t)}).rebalance():this.clone({right:this.right.insert(e,t)}).rebalance()}walkWithin(e,t){const{key:r,value:i}=this;let n=[];return r>e&&(n=n.concat(this.left.walkWithin(e,t))),r>=e&&r<=t&&n.push({key:r,value:i}),r<=t&&(n=n.concat(this.right.walkWithin(e,t))),n}walk(){return[...this.left.walk(),{key:this.key,value:this.value},...this.right.walk()]}last(){return this.right.empty()?[this.key,this.value]:this.right.last()}deleteLast(){return this.right.empty()?this.left:this.clone({right:this.right.deleteLast()}).adjust()}clone(e){return new k({key:void 0!==e.key?e.key:this.key,value:void 0!==e.value?e.value:this.value,level:void 0!==e.level?e.level:this.level,left:void 0!==e.left?e.left:this.left,right:void 0!==e.right?e.right:this.right})}isSingle(){return this.level>this.right.level}rebalance(){return this.skew().split()}adjust(){const{left:e,right:t,level:r}=this;if(t.level>=r-1&&e.level>=r-1)return this;if(r>t.level+1){if(e.isSingle())return this.clone({level:r-1}).skew();if(e.empty()||e.right.empty())throw new Error("Unexpected empty nodes");return e.right.clone({left:e.clone({right:e.right.left}),right:this.clone({left:e.right.right,level:r-1}),level:r})}if(this.isSingle())return this.clone({level:r-1}).split();if(t.empty()||t.left.empty())throw new Error("Unexpected empty nodes");{const e=t.left,i=e.isSingle()?t.level-1:t.level;return e.clone({left:this.clone({right:e.left,level:r-1}),right:t.clone({left:e.right,level:i}).split(),level:e.level+1})}}isInvariant(){const{left:e,right:t,level:r}=this;return r===e.level+1&&((r===t.level||r===t.level+1)&&(!(!t.empty()&&r<=t.right.level)&&(e.isInvariant()&&t.isInvariant())))}keys(){return[...this.left.keys(),this.key,...this.right.keys()]}ranges(){return this.toRanges(this.walk())}rangesWithin(e,t){return this.toRanges(this.walkWithin(e,t))}toRanges(e){if(0===e.length)return[];const t=e[0];let{key:r,value:i}=t;const n=[];for(let t=1;t<=e.length;t++){let s=e[t],o=s?s.key-1:Infinity;n.push({start:r,end:o,value:i}),s&&(r=s.key,i=s.value)}return n}split(){const{right:e,level:t}=this;return e.empty()||e.right.empty()||e.level!=t||e.right.level!=t?this:e.clone({left:this.clone({right:e.left}),level:t+1})}skew(){const{left:e}=this;return e.empty()||e.level!==this.level?this:e.clone({right:this.clone({left:e.right})})}}class w{constructor(e){this.root=e}static empty(){return new w(x)}find(e){return this.root.find(e)}findMax(e){return this.root.findMax(e)}findMaxValue(e){if(this.empty())throw new Error("Searching for max value in an empty tree");return this.root.findMaxValue(e)}findWith(e){return this.root.findWith(e)}insert(e,t){return new w(this.root.insert(e,t))}remove(e){return new w(this.root.remove(e))}empty(){return this.root.empty()}keys(){return this.root.keys()}walk(){return this.root.walk()}walkWithin(e,t){let r=this.root.findMax(e);return this.root.walkWithin(r,t)}ranges(){return this.root.ranges()}rangesWithin(e,t){let r=this.root.findMax(e);return this.root.rangesWithin(r,t)}isInvariant(){return this.root.isInvariant()}}class I{static create(){return new I(w.empty())}constructor(e){this.rangeTree=e;let t=w.empty(),r=0;for(const{start:i,end:n,value:s}of e.ranges())t=t.insert(r,{startIndex:i,endIndex:n,size:s}),Infinity!==n&&(r+=(n-i+1)*s);this.offsetTree=t}empty(){return this.rangeTree.empty()}insert(e,t,r){let i=this.rangeTree;if(i.empty())return new I(i.insert(0,r));const n=i.rangesWithin(e-1,t+1);if(n.some(i=>i.start===e&&(i.end===t||Infinity===i.end)&&i.value===r))return this;let s=!1,o=!1;for(const{start:e,end:l,value:h}of n)s?(t>=e||r===h)&&(i=i.remove(e)):(o=h!==r,s=!0),l>t&&t>=e&&(h===r||isNaN(h)||(i=i.insert(t+1,h)));return o&&(i=i.insert(e,r)),i===this.rangeTree?this:new I(i)}insertException(e,t){return this.empty()?new I(this.rangeTree.insert(1,NaN).insert(e,t)):this.insert(e,e,t)}offsetOf(e){if(this.offsetTree.empty())return 0;const t=this.offsetTree.findWith(t=>t.startIndex>e?-1:t.endIndex<e?1:0);if(t){const[r,{startIndex:i,size:n}]=t;return r+(e-i)*n}throw new Error(`Requested offset outside of the known ones, index: ${e}`)}itemAt(e){const t=this.rangeTree.findMaxValue(e);return{index:e,size:t,offset:NaN}}indexRange(e,t){if(0===t)return[];if(this.rangeTree.empty())return[{index:0,size:0,offset:NaN}];const r=this.rangeTree.rangesWithin(e,t),i=[];for(const n of r){const r=Math.max(e,n.start),s=void 0===n.end?Infinity:n.end,o=Math.min(t,s);for(let e=r;e<=o;e++)i.push({index:e,size:n.value,offset:NaN})}return i}range(e,t,r=0,i=Infinity){if(this.offsetTree.empty())return[{index:0,size:0,offset:0}];const n=this.offsetTree.rangesWithin(e,t),s=[];for(let{start:o,value:{startIndex:l,endIndex:h,size:u}}of n){let n=o,a=l;if(o<e&&(a+=Math.floor((e-o)/u),n+=(a-l)*u),a<r&&(n+=(r-a)*u,a=r),isNaN(u))return s.push({index:a,size:0,offset:n}),s;h=Math.min(h,i);for(let e=a;e<=h&&!(n>t);e++)s.push({index:e,size:u,offset:n}),n+=u}return s}total(e){const t=this.rangeTree.rangesWithin(0,e);let r=0;for(let{start:i,end:n,value:s}of t)n=Math.min(n,e),r+=(n-i+1)*s;return r}getOffsets(e){let t=w.empty();return e.forEach(e=>{const r=this.offsetOf(e);t=t.insert(r,e)}),new E(t)}}class E{constructor(e){this.tree=e}findMaxValue(e){return this.tree.findMaxValue(e)}empty(){return this.tree.empty()}}class M{transpose(e){return e.map(e=>({groupIndex:0,index:e.index,offset:e.offset,size:e.size,transposedIndex:e.index,type:"item"}))}}class z{constructor(e){this.count=e.reduce((e,t)=>e+t+1,0);let t=w.empty(),r=0,i=0;for(let n of e)t=t.insert(i,[r,i]),r++,i+=n+1;this.tree=t}totalCount(){return this.count}transpose(e){return e.map(e=>{const t=this.tree.find(e.index);if(t)return{groupIndex:t[0],index:e.index,offset:e.offset,size:e.size,type:"group"};const[r]=this.tree.findMaxValue(e.index);return{groupIndex:r,index:e.index,offset:e.offset,size:e.size,transposedIndex:e.index-r-1,type:"item"}})}groupIndices(){return this.tree.keys()}}function W(e){let t,r=e=>{t&&t(e)},i=!1;return n=>{t=n,i||(e.subscribe(r),i=!0)}}function H(e){return e.next}const T=e=>e.length>0?e[0].offset:0,R=([e,t])=>e.total(t-1),V=({overscan:e=0,totalCount:t=0,itemHeight:r})=>{const i=c(0),n=c(0),s=c(0),o=c(0),l=c(),h=c(t),u=c(),a=c(),y=c(!1);let x=I.create();const b=c([]);r&&(x=x.insert(0,0,r));const k=c(x);r||l.pipe(v(k.subscribe,b.subscribe)).subscribe(([e,t,r])=>{let i=t;for(let{start:t,end:r,size:n}of e)i=i.insert(t,r,n);i!==t&&k.next(i)});let w=new M;u.subscribe(e=>{w=new z(e),h.next(w.totalCount()),b.next(w.groupIndices())});const E=f(k.subscribe,h.subscribe).pipe(d(R)),V=f(E.subscribe,o.subscribe).pipe(d(([e,t])=>e+t)),S=f(k.subscribe,b.subscribe).pipe(d(([e,t])=>e.getOffsets(t))),C=c([]);f(k.subscribe,a.subscribe,h.subscribe).pipe(m(e=>e[1]>0),d(([e,t,r])=>{const i=Math.max(0,Math.min(t-1,r));return w.transpose(e.indexRange(0,i))})).subscribe(C.next),f(k.subscribe,S.subscribe,s.subscribe).pipe(m(e=>!e[1].empty()&&!e[0].empty()),v(C.subscribe),d(([[e,t,r],i])=>{const n=t.findMaxValue(r);if(1===i.length&&i[0].index===n)return i;const s=e.itemAt(n);return w.transpose([s])})).subscribe(C.next);const N=C.pipe(d(e=>e.reduce((e,t)=>e+t.size,0))),O=C.pipe(d(e=>e.length&&e[e.length-1].index+1)),j=f(i.subscribe,s.subscribe,N.subscribe,n.subscribe,o.subscribe,O.subscribe,h.subscribe,k.subscribe).pipe(function(e,t){let r=t;return(t,i)=>{i(r=e(r,t))}}((e=>(t,[r,i,n,s,o,l,h,u])=>{const a=t.length;if(0===h)return 0===a?t:[];const c=T(t),f=c-i+s-o-n,d=Math.max(h-1,0),p=a>0&&(t[0].index<l||t[a-1].index>d);if(f<r||p){const t=Math.max(i+n,n),s=i+r+2*e-1,o=w.transpose(u.range(t,s,l,d));return o}if(c>i+n){const t=Math.max(i+n-2*e,n),s=i+r-1;return w.transpose(u.range(t,s,l,d))}return t})(e),[])),L=c(0);let A=0;j.pipe(d(e=>e.length?e[e.length-1].index:0)).subscribe(e=>{A<e&&(A=e,L.next(e))});const $=f(j.subscribe,s.subscribe,N.subscribe).pipe(d(([e,t,r])=>T(e)-t-r));return s.pipe(g(1),p(!0)).subscribe(y.next),s.pipe(g(1),p(!1),function(e){let t,r;return(i,n)=>{t=i,r&&clearTimeout(r),r=setTimeout(()=>{n(t)},e)}}(200)).subscribe(y.next),{groupCounts:H(u),itemHeights:H(l),footerHeight:H(o),listHeight:H(n),viewportHeight:H(i),scrollTop:H(s),topItemCount:H(a),totalCount:H(h),list:W(j),topList:W(C),listOffset:W($),totalHeight:W(V),endReached:W(L),isScrolling:W(y),stickyItems:W(b)}},S=(e,t,i)=>{const n=r(null),s=r(0),o=new h(t=>{const r=t[0].contentRect.height;s.current!==r&&(s.current=r,i&&i(t[0].target),e(r))});return e=>{e?(o.observe(e),t&&t(e),n.current=e):(o.unobserve(n.current),n.current=null)}};function C(e,t){const[r,s]=i(t);return n(()=>{e(s)},[]),r}const N={height:"40rem",overflowY:"auto",WebkitOverflowScrolling:"touch",position:"relative",outline:"none"},O=({children:t,style:i})=>{const{scrollTop:n}=s(u),l=r(null),h=o(e=>{n(e.target.scrollTop)},[]),a=o(e=>{e?(e.addEventListener("scroll",h,{passive:!0}),l.current=e):l.current.removeEventListener("scroll",h)},[]);return e.createElement("div",{ref:a,style:{...N,...i},tabIndex:0},t)},j=({list:t,transform:r="",render:i})=>{const{stickyItems:n}=s(u),l=C(t,[]),h=C(n,[]),a=o(e=>{const t=h.some(t=>t===e),i={transform:r,zIndex:t?2:void 0,position:t?"relative":void 0};return i},[h,r]);return 0===l.length?null:e.createElement(e.Fragment,null,l.map(t=>e.createElement("div",{key:t.index,"data-index":t.index,"data-known-size":t.size,style:a(t.index)},i(t))))},L=()=>{const t=C(s(u).totalHeight,0);return e.createElement("div",{style:{height:`${t}px`,position:"absolute",top:0}}," ")},A=({footer:t})=>{const r=S(s(u).footerHeight);return e.createElement("footer",{ref:r},t())},$={top:0,position:"sticky",height:"100%",overflow:"hidden",WebkitBackfaceVisibility:"hidden"},D=({style:t,footer:r,item:i,fixedItemHeight:n})=>{const{itemHeights:l,listHeight:h,viewportHeight:a,listOffset:c,list:f,topList:d}=s(u),p=C(c,0),g=o(e=>{const t=[];for(var r=0,i=e.length;r<i;r++){let i=e.item(r);if(!i||"DIV"!==i.tagName)continue;const n=parseInt(i.dataset.index),s=i.offsetHeight;0===t.length||t[t.length-1].size!==s?t.push({start:n,end:n,size:s}):t[t.length-1].end++}t.length>0&&l(t)},[]),m=S(h,()=>{},e=>{n||g(e.children)}),v=S(a,e=>{""===e.style.position&&(e.style.position="-webkit-sticky")}),y=`translateY(${p}px)`,x=`translateY(${-p}px)`;return e.createElement(O,{style:t},e.createElement("div",{style:$,ref:v},e.createElement("div",{style:{transform:y}},e.createElement("div",{ref:m},e.createElement(j,{list:d,transform:x,render:i}),e.createElement(j,{list:f,render:i}),r&&e.createElement(A,{footer:r})))),e.createElement(L,null))},F=({contextValue:t,style:r,item:i,footer:n,itemHeight:s})=>e.createElement(u.Provider,{value:t},e.createElement(D,{style:r||{},item:i,footer:n,fixedItemHeight:void 0!==s}));class P extends l{constructor(e){super(e),this.itemRenderer=(e=>this.props.item(e.index)),this.state=V(e)}static getDerivedStateFromProps(e,t){return t.isScrolling(e.scrollingStateChange),t.endReached(e.endReached),t.topItemCount(e.topItems||0),t.totalCount(e.totalCount),null}render(){return e.createElement(F,{contextValue:this.state,style:this.props.style,item:this.itemRenderer,footer:this.props.footer,itemHeight:this.props.itemHeight})}}class U extends l{constructor(e){super(e),this.itemRender=(e=>"group"==e.type?this.props.group(e.groupIndex):this.props.item(e.transposedIndex,e.groupIndex)),this.state=V(e)}static getDerivedStateFromProps(e,t){return t.endReached(e.endReached),t.isScrolling(e.scrollingStateChange),t.groupCounts(e.groupCounts),null}render(){return e.createElement(F,{contextValue:this.state,style:this.props.style,item:this.itemRender,footer:this.props.footer,itemHeight:this.props.itemHeight})}}export{U as GroupedVirtuoso,P as Virtuoso,F as VirtuosoPresentation}; | ||
import e,{createContext as t,useRef as r,useState as i,useLayoutEffect as n,useContext as s,useCallback as o,PureComponent as l}from"react";import h from"resize-observer-polyfill";const u=t(void 0);function a(e){return function(...t){const r=function(...e){return 0===e.length?(e,t)=>t(e):1===e.length?e[0]:(t,r)=>{let i=e=>r(e);e.slice().reverse().forEach(e=>{const t=i;i=(r=>e(r,t))}),i(t)}}(...t);return function(e,t){const r=r=>e(e=>t(e,r));return{subscribe:r,pipe:a(r)}}(e,r)}}function c(e){let t=[],r=e;const i=e=>(t.push(e),void 0!==r&&e(r),()=>{t=t.filter(t=>t!==e)});return{next:e=>{e!==r&&(r=e,t.forEach(t=>t(e)))},subscribe:i,pipe:a(i),subscribers:t}}function f(...e){const t=Array(e.length).fill(!1),r=Array(e.length);let i=[];const n=e=>{t.every(e=>e)&&e.forEach(e=>e(r))};e.forEach((e,s)=>{e(e=>{t[s]=!0,r[s]=e,n(i)})});const s=e=>(i.push(e),n([e]),()=>{i=i.filter(t=>t!==e)});return{subscribe:s,pipe:a(s)}}function d(e){return(t,r)=>{r(e(t))}}function p(e){return(t,r)=>r(e)}function g(e){return(t,r)=>{e>0?e--:r(t)}}function m(e){return(t,r)=>{e(t)&&r(t)}}function v(...e){const t=Array(e.length).fill(!1),r=Array(e.length);return e.forEach((e,i)=>{e(e=>{r[i]=e,t[i]=!0})}),(e,i)=>{t.every(e=>e)&&i([e,...r])}}class y{constructor(){this.level=0}rebalance(){return this}adjust(){return this}remove(){return this}find(){}findWith(){}findMax(){return-Infinity}findMaxValue(){}insert(e,t){return new k({key:e,value:t,level:1})}walkWithin(){return[]}walk(){return[]}ranges(){return[]}rangesWithin(){return[]}empty(){return!0}isSingle(){return!0}isInvariant(){return!0}keys(){return[]}}const x=new y;Object.freeze(x);class b extends Error{constructor(e){super(`Unreachable case: ${e}`)}}class k{constructor({key:e,value:t,level:r,left:i=x,right:n=x}){this.key=e,this.value=t,this.level=r,this.left=i,this.right=n}remove(e){const{left:t,right:r}=this;if(e===this.key){if(t.empty())return r;if(r.empty())return t;{const[e,r]=t.last();return this.clone({key:e,value:r,left:t.deleteLast()}).adjust()}}return e<this.key?this.clone({left:t.remove(e)}).adjust():this.clone({right:r.remove(e)}).adjust()}empty(){return!1}find(e){return e===this.key?this.value:e<this.key?this.left.find(e):this.right.find(e)}findWith(e){const t=e(this.value);switch(t){case-1:return this.left.findWith(e);case 0:return[this.key,this.value];case 1:return this.right.findWith(e);default:throw new b(t)}}findMax(e){if(this.key===e)return e;if(this.key<e){const t=this.right.findMax(e);return-Infinity===t?this.key:t}return this.left.findMax(e)}findMaxValue(e){if(this.key===e)return this.value;if(this.key<e){const t=this.right.findMaxValue(e);return void 0===t?this.value:t}return this.left.findMaxValue(e)}insert(e,t){return e===this.key?this.clone({key:e,value:t}):e<this.key?this.clone({left:this.left.insert(e,t)}).rebalance():this.clone({right:this.right.insert(e,t)}).rebalance()}walkWithin(e,t){const{key:r,value:i}=this;let n=[];return r>e&&(n=n.concat(this.left.walkWithin(e,t))),r>=e&&r<=t&&n.push({key:r,value:i}),r<=t&&(n=n.concat(this.right.walkWithin(e,t))),n}walk(){return[...this.left.walk(),{key:this.key,value:this.value},...this.right.walk()]}last(){return this.right.empty()?[this.key,this.value]:this.right.last()}deleteLast(){return this.right.empty()?this.left:this.clone({right:this.right.deleteLast()}).adjust()}clone(e){return new k({key:void 0!==e.key?e.key:this.key,value:void 0!==e.value?e.value:this.value,level:void 0!==e.level?e.level:this.level,left:void 0!==e.left?e.left:this.left,right:void 0!==e.right?e.right:this.right})}isSingle(){return this.level>this.right.level}rebalance(){return this.skew().split()}adjust(){const{left:e,right:t,level:r}=this;if(t.level>=r-1&&e.level>=r-1)return this;if(r>t.level+1){if(e.isSingle())return this.clone({level:r-1}).skew();if(e.empty()||e.right.empty())throw new Error("Unexpected empty nodes");return e.right.clone({left:e.clone({right:e.right.left}),right:this.clone({left:e.right.right,level:r-1}),level:r})}if(this.isSingle())return this.clone({level:r-1}).split();if(t.empty()||t.left.empty())throw new Error("Unexpected empty nodes");{const e=t.left,i=e.isSingle()?t.level-1:t.level;return e.clone({left:this.clone({right:e.left,level:r-1}),right:t.clone({left:e.right,level:i}).split(),level:e.level+1})}}isInvariant(){const{left:e,right:t,level:r}=this;return r===e.level+1&&((r===t.level||r===t.level+1)&&(!(!t.empty()&&r<=t.right.level)&&(e.isInvariant()&&t.isInvariant())))}keys(){return[...this.left.keys(),this.key,...this.right.keys()]}ranges(){return this.toRanges(this.walk())}rangesWithin(e,t){return this.toRanges(this.walkWithin(e,t))}toRanges(e){if(0===e.length)return[];const t=e[0];let{key:r,value:i}=t;const n=[];for(let t=1;t<=e.length;t++){let s=e[t],o=s?s.key-1:Infinity;n.push({start:r,end:o,value:i}),s&&(r=s.key,i=s.value)}return n}split(){const{right:e,level:t}=this;return e.empty()||e.right.empty()||e.level!=t||e.right.level!=t?this:e.clone({left:this.clone({right:e.left}),level:t+1})}skew(){const{left:e}=this;return e.empty()||e.level!==this.level?this:e.clone({right:this.clone({left:e.right})})}}class w{constructor(e){this.root=e}static empty(){return new w(x)}find(e){return this.root.find(e)}findMax(e){return this.root.findMax(e)}findMaxValue(e){if(this.empty())throw new Error("Searching for max value in an empty tree");return this.root.findMaxValue(e)}findWith(e){return this.root.findWith(e)}insert(e,t){return new w(this.root.insert(e,t))}remove(e){return new w(this.root.remove(e))}empty(){return this.root.empty()}keys(){return this.root.keys()}walk(){return this.root.walk()}walkWithin(e,t){let r=this.root.findMax(e);return this.root.walkWithin(r,t)}ranges(){return this.root.ranges()}rangesWithin(e,t){let r=this.root.findMax(e);return this.root.rangesWithin(r,t)}isInvariant(){return this.root.isInvariant()}}class I{static create(){return new I(w.empty())}constructor(e){this.rangeTree=e;let t=w.empty(),r=0;for(const{start:i,end:n,value:s}of e.ranges())t=t.insert(r,{startIndex:i,endIndex:n,size:s}),Infinity!==n&&(r+=(n-i+1)*s);this.offsetTree=t}empty(){return this.rangeTree.empty()}insert(e,t,r){let i=this.rangeTree;if(i.empty())return new I(i.insert(0,r));const n=i.rangesWithin(e-1,t+1);if(n.some(i=>i.start===e&&(i.end===t||Infinity===i.end)&&i.value===r))return this;let s=!1,o=!1;for(const{start:e,end:l,value:h}of n)s?(t>=e||r===h)&&(i=i.remove(e)):(o=h!==r,s=!0),l>t&&t>=e&&(h===r||isNaN(h)||(i=i.insert(t+1,h)));return o&&(i=i.insert(e,r)),i===this.rangeTree?this:new I(i)}insertException(e,t){return this.empty()?new I(this.rangeTree.insert(1,NaN).insert(e,t)):this.insert(e,e,t)}offsetOf(e){if(this.offsetTree.empty())return 0;const t=this.offsetTree.findWith(t=>t.startIndex>e?-1:t.endIndex<e?1:0);if(t){const[r,{startIndex:i,size:n}]=t;return r+(e-i)*n}throw new Error(`Requested offset outside of the known ones, index: ${e}`)}itemAt(e){const t=this.rangeTree.findMaxValue(e);return{index:e,size:t,offset:NaN}}indexRange(e,t){if(0===t)return[];if(this.rangeTree.empty())return[{index:0,size:0,offset:NaN}];const r=this.rangeTree.rangesWithin(e,t),i=[];for(const n of r){const r=Math.max(e,n.start),s=void 0===n.end?Infinity:n.end,o=Math.min(t,s);for(let e=r;e<=o;e++)i.push({index:e,size:n.value,offset:NaN})}return i}range(e,t,r=0,i=Infinity){if(this.offsetTree.empty())return[{index:0,size:0,offset:0}];const n=this.offsetTree.rangesWithin(e,t),s=[];for(let{start:o,value:{startIndex:l,endIndex:h,size:u}}of n){let n=o,a=l;if(o<e&&(a+=Math.floor((e-o)/u),n+=(a-l)*u),a<r&&(n+=(r-a)*u,a=r),isNaN(u))return s.push({index:a,size:0,offset:n}),s;h=Math.min(h,i);for(let e=a;e<=h&&!(n>t);e++)s.push({index:e,size:u,offset:n}),n+=u}return s}total(e){const t=this.rangeTree.rangesWithin(0,e);let r=0;for(let{start:i,end:n,value:s}of t)n=Math.min(n,e),r+=(n-i+1)*s;return r}getOffsets(e){let t=w.empty();return e.forEach(e=>{const r=this.offsetOf(e);t=t.insert(r,e)}),new E(t)}}class E{constructor(e){this.tree=e}findMaxValue(e){return this.tree.findMaxValue(e)}empty(){return this.tree.empty()}}class M{transpose(e){return e.map(e=>({groupIndex:0,index:e.index,offset:e.offset,size:e.size,transposedIndex:e.index,type:"item"}))}}class z{constructor(e){this.count=e.reduce((e,t)=>e+t+1,0);let t=w.empty(),r=0,i=0;for(let n of e)t=t.insert(i,[r,i]),r++,i+=n+1;this.tree=t}totalCount(){return this.count}transpose(e){return e.map(e=>{const t=this.tree.find(e.index);if(t)return{groupIndex:t[0],index:e.index,offset:e.offset,size:e.size,type:"group"};const[r]=this.tree.findMaxValue(e.index);return{groupIndex:r,index:e.index,offset:e.offset,size:e.size,transposedIndex:e.index-r-1,type:"item"}})}groupIndices(){return this.tree.keys()}}function W(e){let t,r=e=>{t&&t(e)},i=!1;return n=>{t=n,i||(e.subscribe(r),i=!0)}}function H(e){return e.next}const T=e=>e.length>0?e[0].offset:0,R=([e,t])=>e.total(t-1),V=({overscan:e=0,totalCount:t=0,itemHeight:r})=>{const i=c(0),n=c(0),s=c(0),o=c(0),l=c(),h=c(t),u=c(),a=c(),y=c(!1);let x=I.create();const b=c([]);r&&(x=x.insert(0,0,r));const k=c(x);r||l.pipe(v(k.subscribe,b.subscribe)).subscribe(([e,t,r])=>{let i=t;for(let{start:t,end:r,size:n}of e)i=i.insert(t,r,n);i!==t&&k.next(i)});let w=new M;u.subscribe(e=>{w=new z(e),h.next(w.totalCount()),b.next(w.groupIndices())});const E=f(k.subscribe,h.subscribe).pipe(d(R)),V=f(E.subscribe,o.subscribe).pipe(d(([e,t])=>e+t)),S=f(k.subscribe,b.subscribe).pipe(d(([e,t])=>e.getOffsets(t))),C=c([]);f(k.subscribe,a.subscribe,h.subscribe).pipe(m(e=>e[1]>0),d(([e,t,r])=>{const i=Math.max(0,Math.min(t-1,r));return w.transpose(e.indexRange(0,i))})).subscribe(C.next),f(k.subscribe,S.subscribe,s.subscribe).pipe(m(e=>!e[1].empty()&&!e[0].empty()),v(C.subscribe),d(([[e,t,r],i])=>{const n=t.findMaxValue(r);if(1===i.length&&i[0].index===n)return i;const s=e.itemAt(n);return w.transpose([s])})).subscribe(C.next);const N=C.pipe(d(e=>e.reduce((e,t)=>e+t.size,0))),O=C.pipe(d(e=>e.length&&e[e.length-1].index+1)),j=f(i.subscribe,s.subscribe,N.subscribe,n.subscribe,o.subscribe,O.subscribe,h.subscribe,k.subscribe).pipe(function(e,t){let r=t;return(t,i)=>{i(r=e(r,t))}}((e=>(t,[r,i,n,s,o,l,h,u])=>{const a=t.length;if(0===h)return 0===a?t:[];const c=T(t),f=c-i+s-o-n,d=Math.max(h-1,0),p=a>0&&(t[0].index<l||t[a-1].index>d);if(f<r||p){const t=Math.max(i+n,n),s=i+r+2*e-1,o=w.transpose(u.range(t,s,l,d));return o}if(c>i+n){const t=Math.max(i+n-2*e,n),s=i+r-1;return w.transpose(u.range(t,s,l,d))}return t})(e),[])),L=c(0);let A=0;j.pipe(d(e=>e.length?e[e.length-1].index:0)).pipe(v(h.subscribe)).subscribe(([e,t])=>{e==t-1&&A!==e&&(A=e,L.next(e))});const $=f(j.subscribe,s.subscribe,N.subscribe).pipe(d(([e,t,r])=>T(e)-t-r));return s.pipe(g(1),p(!0)).subscribe(y.next),s.pipe(g(1),p(!1),function(e){let t,r;return(i,n)=>{t=i,r&&clearTimeout(r),r=setTimeout(()=>{n(t)},e)}}(200)).subscribe(y.next),{groupCounts:H(u),itemHeights:H(l),footerHeight:H(o),listHeight:H(n),viewportHeight:H(i),scrollTop:H(s),topItemCount:H(a),totalCount:H(h),list:W(j),topList:W(C),listOffset:W($),totalHeight:W(V),endReached:W(L),isScrolling:W(y),stickyItems:W(b)}},S=(e,t,i)=>{const n=r(null),s=r(0),o=new h(t=>{const r=t[0].contentRect.height;s.current!==r&&(s.current=r,i&&i(t[0].target),e(r))});return e=>{e?(o.observe(e),t&&t(e),n.current=e):(o.unobserve(n.current),n.current=null)}};function C(e,t){const[r,s]=i(t);return n(()=>{e(s)},[]),r}const N={height:"40rem",overflowY:"auto",WebkitOverflowScrolling:"touch",position:"relative",outline:"none"},O=({children:t,style:i})=>{const{scrollTop:n}=s(u),l=r(null),h=o(e=>{n(e.target.scrollTop)},[]),a=o(e=>{e?(e.addEventListener("scroll",h,{passive:!0}),l.current=e):l.current.removeEventListener("scroll",h)},[]);return e.createElement("div",{ref:a,style:{...N,...i},tabIndex:0},t)},j=({list:t,transform:r="",render:i})=>{const{stickyItems:n}=s(u),l=C(t,[]),h=C(n,[]),a=o(e=>{const t=h.some(t=>t===e),i={transform:r,zIndex:t?2:void 0,position:t?"relative":void 0};return i},[h,r]);return 0===l.length?null:e.createElement(e.Fragment,null,l.map(t=>e.createElement("div",{key:t.index,"data-index":t.index,"data-known-size":t.size,style:a(t.index)},i(t))))},L=()=>{const t=C(s(u).totalHeight,0);return e.createElement("div",{style:{height:`${t}px`,position:"absolute",top:0}}," ")},A=({footer:t})=>{const r=S(s(u).footerHeight);return e.createElement("footer",{ref:r},t())},$={top:0,position:"sticky",height:"100%",overflow:"hidden",WebkitBackfaceVisibility:"hidden"},D=({style:t,footer:r,item:i,fixedItemHeight:n})=>{const{itemHeights:l,listHeight:h,viewportHeight:a,listOffset:c,list:f,topList:d}=s(u),p=C(c,0),g=o(e=>{const t=[];for(var r=0,i=e.length;r<i;r++){let i=e.item(r);if(!i||"DIV"!==i.tagName)continue;const n=parseInt(i.dataset.index),s=i.offsetHeight;0===t.length||t[t.length-1].size!==s?t.push({start:n,end:n,size:s}):t[t.length-1].end++}t.length>0&&l(t)},[]),m=S(h,()=>{},e=>{n||g(e.children)}),v=S(a,e=>{""===e.style.position&&(e.style.position="-webkit-sticky")}),y=`translateY(${p}px)`,x=`translateY(${-p}px)`;return e.createElement(O,{style:t},e.createElement("div",{style:$,ref:v},e.createElement("div",{style:{transform:y}},e.createElement("div",{ref:m},e.createElement(j,{list:d,transform:x,render:i}),e.createElement(j,{list:f,render:i}),r&&e.createElement(A,{footer:r})))),e.createElement(L,null))},F=({contextValue:t,style:r,item:i,footer:n,itemHeight:s})=>e.createElement(u.Provider,{value:t},e.createElement(D,{style:r||{},item:i,footer:n,fixedItemHeight:void 0!==s}));class P extends l{constructor(e){super(e),this.itemRenderer=(e=>this.props.item(e.index)),this.state=V(e)}static getDerivedStateFromProps(e,t){return t.isScrolling(e.scrollingStateChange),t.endReached(e.endReached),t.topItemCount(e.topItems||0),t.totalCount(e.totalCount),null}render(){return e.createElement(F,{contextValue:this.state,style:this.props.style,item:this.itemRenderer,footer:this.props.footer,itemHeight:this.props.itemHeight})}}class U extends l{constructor(e){super(e),this.itemRender=(e=>"group"==e.type?this.props.group(e.groupIndex):this.props.item(e.transposedIndex,e.groupIndex)),this.state=V(e)}static getDerivedStateFromProps(e,t){return t.endReached(e.endReached),t.isScrolling(e.scrollingStateChange),t.groupCounts(e.groupCounts),null}render(){return e.createElement(F,{contextValue:this.state,style:this.props.style,item:this.itemRender,footer:this.props.footer,itemHeight:this.props.itemHeight})}}export{U as GroupedVirtuoso,P as Virtuoso,F as VirtuosoPresentation}; | ||
//# sourceMappingURL=react-virtuoso.es.production.js.map |
@@ -1137,6 +1137,8 @@ (function (global, factory) { | ||
let currentEndIndex = 0; | ||
list$.pipe(map(items => items.length ? items[items.length - 1].index : 0)).subscribe(endIndex => { | ||
if (currentEndIndex < endIndex) { | ||
currentEndIndex = endIndex; | ||
endReached$.next(endIndex); | ||
list$.pipe(map(items => items.length ? items[items.length - 1].index : 0)).pipe(withLatestFrom(totalCount$.subscribe)).subscribe(([endIndex, totalCount]) => { | ||
if (endIndex == totalCount - 1) { | ||
if (currentEndIndex !== endIndex) { | ||
currentEndIndex = endIndex; | ||
endReached$.next(endIndex); | ||
} | ||
} | ||
@@ -1143,0 +1145,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("resize-observer-polyfill")):"function"==typeof define&&define.amd?define(["exports","react","resize-observer-polyfill"],t):(e=e||self,t(e["react-virtuoso"]={},e.React,e.ResizeObserver))}(this,function(e,t,r){"use strict";var n="default"in t?t.default:t;r=r&&r.hasOwnProperty("default")?r.default:r;const i=t.createContext(void 0);function s(e){return function(...t){const r=function(...e){return 0===e.length?(e,t)=>t(e):1===e.length?e[0]:(t,r)=>{let n=e=>r(e);e.slice().reverse().forEach(e=>{const t=n;n=(r=>e(r,t))}),n(t)}}(...t);return function(e,t){const r=r=>e(e=>t(e,r));return{subscribe:r,pipe:s(r)}}(e,r)}}function o(e){let t=[],r=e;const n=e=>(t.push(e),void 0!==r&&e(r),()=>{t=t.filter(t=>t!==e)});return{next:e=>{e!==r&&(r=e,t.forEach(t=>t(e)))},subscribe:n,pipe:s(n),subscribers:t}}function l(...e){const t=Array(e.length).fill(!1),r=Array(e.length);let n=[];const i=e=>{t.every(e=>e)&&e.forEach(e=>e(r))};e.forEach((e,s)=>{e(e=>{t[s]=!0,r[s]=e,i(n)})});const o=e=>(n.push(e),i([e]),()=>{n=n.filter(t=>t!==e)});return{subscribe:o,pipe:s(o)}}function u(e){return(t,r)=>{r(e(t))}}function a(e){return(t,r)=>r(e)}function h(e){return(t,r)=>{e>0?e--:r(t)}}function c(e){return(t,r)=>{e(t)&&r(t)}}function f(...e){const t=Array(e.length).fill(!1),r=Array(e.length);return e.forEach((e,n)=>{e(e=>{r[n]=e,t[n]=!0})}),(e,n)=>{t.every(e=>e)&&n([e,...r])}}class d{constructor(){this.level=0}rebalance(){return this}adjust(){return this}remove(){return this}find(){}findWith(){}findMax(){return-Infinity}findMaxValue(){}insert(e,t){return new m({key:e,value:t,level:1})}walkWithin(){return[]}walk(){return[]}ranges(){return[]}rangesWithin(){return[]}empty(){return!0}isSingle(){return!0}isInvariant(){return!0}keys(){return[]}}const p=new d;Object.freeze(p);class g extends Error{constructor(e){super(`Unreachable case: ${e}`)}}class m{constructor({key:e,value:t,level:r,left:n=p,right:i=p}){this.key=e,this.value=t,this.level=r,this.left=n,this.right=i}remove(e){const{left:t,right:r}=this;if(e===this.key){if(t.empty())return r;if(r.empty())return t;{const[e,r]=t.last();return this.clone({key:e,value:r,left:t.deleteLast()}).adjust()}}return e<this.key?this.clone({left:t.remove(e)}).adjust():this.clone({right:r.remove(e)}).adjust()}empty(){return!1}find(e){return e===this.key?this.value:e<this.key?this.left.find(e):this.right.find(e)}findWith(e){const t=e(this.value);switch(t){case-1:return this.left.findWith(e);case 0:return[this.key,this.value];case 1:return this.right.findWith(e);default:throw new g(t)}}findMax(e){if(this.key===e)return e;if(this.key<e){const t=this.right.findMax(e);return-Infinity===t?this.key:t}return this.left.findMax(e)}findMaxValue(e){if(this.key===e)return this.value;if(this.key<e){const t=this.right.findMaxValue(e);return void 0===t?this.value:t}return this.left.findMaxValue(e)}insert(e,t){return e===this.key?this.clone({key:e,value:t}):e<this.key?this.clone({left:this.left.insert(e,t)}).rebalance():this.clone({right:this.right.insert(e,t)}).rebalance()}walkWithin(e,t){const{key:r,value:n}=this;let i=[];return r>e&&(i=i.concat(this.left.walkWithin(e,t))),r>=e&&r<=t&&i.push({key:r,value:n}),r<=t&&(i=i.concat(this.right.walkWithin(e,t))),i}walk(){return[...this.left.walk(),{key:this.key,value:this.value},...this.right.walk()]}last(){return this.right.empty()?[this.key,this.value]:this.right.last()}deleteLast(){return this.right.empty()?this.left:this.clone({right:this.right.deleteLast()}).adjust()}clone(e){return new m({key:void 0!==e.key?e.key:this.key,value:void 0!==e.value?e.value:this.value,level:void 0!==e.level?e.level:this.level,left:void 0!==e.left?e.left:this.left,right:void 0!==e.right?e.right:this.right})}isSingle(){return this.level>this.right.level}rebalance(){return this.skew().split()}adjust(){const{left:e,right:t,level:r}=this;if(t.level>=r-1&&e.level>=r-1)return this;if(r>t.level+1){if(e.isSingle())return this.clone({level:r-1}).skew();if(e.empty()||e.right.empty())throw new Error("Unexpected empty nodes");return e.right.clone({left:e.clone({right:e.right.left}),right:this.clone({left:e.right.right,level:r-1}),level:r})}if(this.isSingle())return this.clone({level:r-1}).split();if(t.empty()||t.left.empty())throw new Error("Unexpected empty nodes");{const e=t.left,n=e.isSingle()?t.level-1:t.level;return e.clone({left:this.clone({right:e.left,level:r-1}),right:t.clone({left:e.right,level:n}).split(),level:e.level+1})}}isInvariant(){const{left:e,right:t,level:r}=this;return r===e.level+1&&((r===t.level||r===t.level+1)&&(!(!t.empty()&&r<=t.right.level)&&(e.isInvariant()&&t.isInvariant())))}keys(){return[...this.left.keys(),this.key,...this.right.keys()]}ranges(){return this.toRanges(this.walk())}rangesWithin(e,t){return this.toRanges(this.walkWithin(e,t))}toRanges(e){if(0===e.length)return[];const t=e[0];let{key:r,value:n}=t;const i=[];for(let t=1;t<=e.length;t++){let s=e[t],o=s?s.key-1:Infinity;i.push({start:r,end:o,value:n}),s&&(r=s.key,n=s.value)}return i}split(){const{right:e,level:t}=this;return e.empty()||e.right.empty()||e.level!=t||e.right.level!=t?this:e.clone({left:this.clone({right:e.left}),level:t+1})}skew(){const{left:e}=this;return e.empty()||e.level!==this.level?this:e.clone({right:this.clone({left:e.right})})}}class v{constructor(e){this.root=e}static empty(){return new v(p)}find(e){return this.root.find(e)}findMax(e){return this.root.findMax(e)}findMaxValue(e){if(this.empty())throw new Error("Searching for max value in an empty tree");return this.root.findMaxValue(e)}findWith(e){return this.root.findWith(e)}insert(e,t){return new v(this.root.insert(e,t))}remove(e){return new v(this.root.remove(e))}empty(){return this.root.empty()}keys(){return this.root.keys()}walk(){return this.root.walk()}walkWithin(e,t){let r=this.root.findMax(e);return this.root.walkWithin(r,t)}ranges(){return this.root.ranges()}rangesWithin(e,t){let r=this.root.findMax(e);return this.root.rangesWithin(r,t)}isInvariant(){return this.root.isInvariant()}}class y{static create(){return new y(v.empty())}constructor(e){this.rangeTree=e;let t=v.empty(),r=0;for(const{start:n,end:i,value:s}of e.ranges())t=t.insert(r,{startIndex:n,endIndex:i,size:s}),Infinity!==i&&(r+=(i-n+1)*s);this.offsetTree=t}empty(){return this.rangeTree.empty()}insert(e,t,r){let n=this.rangeTree;if(n.empty())return new y(n.insert(0,r));const i=n.rangesWithin(e-1,t+1);if(i.some(n=>n.start===e&&(n.end===t||Infinity===n.end)&&n.value===r))return this;let s=!1,o=!1;for(const{start:e,end:l,value:u}of i)s?(t>=e||r===u)&&(n=n.remove(e)):(o=u!==r,s=!0),l>t&&t>=e&&(u===r||isNaN(u)||(n=n.insert(t+1,u)));return o&&(n=n.insert(e,r)),n===this.rangeTree?this:new y(n)}insertException(e,t){return this.empty()?new y(this.rangeTree.insert(1,NaN).insert(e,t)):this.insert(e,e,t)}offsetOf(e){if(this.offsetTree.empty())return 0;const t=this.offsetTree.findWith(t=>t.startIndex>e?-1:t.endIndex<e?1:0);if(t){const[r,{startIndex:n,size:i}]=t;return r+(e-n)*i}throw new Error(`Requested offset outside of the known ones, index: ${e}`)}itemAt(e){const t=this.rangeTree.findMaxValue(e);return{index:e,size:t,offset:NaN}}indexRange(e,t){if(0===t)return[];if(this.rangeTree.empty())return[{index:0,size:0,offset:NaN}];const r=this.rangeTree.rangesWithin(e,t),n=[];for(const i of r){const r=Math.max(e,i.start),s=void 0===i.end?Infinity:i.end,o=Math.min(t,s);for(let e=r;e<=o;e++)n.push({index:e,size:i.value,offset:NaN})}return n}range(e,t,r=0,n=Infinity){if(this.offsetTree.empty())return[{index:0,size:0,offset:0}];const i=this.offsetTree.rangesWithin(e,t),s=[];for(let{start:o,value:{startIndex:l,endIndex:u,size:a}}of i){let i=o,h=l;if(o<e&&(h+=Math.floor((e-o)/a),i+=(h-l)*a),h<r&&(i+=(r-h)*a,h=r),isNaN(a))return s.push({index:h,size:0,offset:i}),s;u=Math.min(u,n);for(let e=h;e<=u&&!(i>t);e++)s.push({index:e,size:a,offset:i}),i+=a}return s}total(e){const t=this.rangeTree.rangesWithin(0,e);let r=0;for(let{start:n,end:i,value:s}of t)i=Math.min(i,e),r+=(i-n+1)*s;return r}getOffsets(e){let t=v.empty();return e.forEach(e=>{const r=this.offsetOf(e);t=t.insert(r,e)}),new x(t)}}class x{constructor(e){this.tree=e}findMaxValue(e){return this.tree.findMaxValue(e)}empty(){return this.tree.empty()}}class b{transpose(e){return e.map(e=>({groupIndex:0,index:e.index,offset:e.offset,size:e.size,transposedIndex:e.index,type:"item"}))}}class k{constructor(e){this.count=e.reduce((e,t)=>e+t+1,0);let t=v.empty(),r=0,n=0;for(let i of e)t=t.insert(n,[r,n]),r++,n+=i+1;this.tree=t}totalCount(){return this.count}transpose(e){return e.map(e=>{const t=this.tree.find(e.index);if(t)return{groupIndex:t[0],index:e.index,offset:e.offset,size:e.size,type:"group"};const[r]=this.tree.findMaxValue(e.index);return{groupIndex:r,index:e.index,offset:e.offset,size:e.size,transposedIndex:e.index-r-1,type:"item"}})}groupIndices(){return this.tree.keys()}}function w(e){let t,r=e=>{t&&t(e)},n=!1;return i=>{t=i,n||(e.subscribe(r),n=!0)}}function I(e){return e.next}const E=e=>e.length>0?e[0].offset:0,M=([e,t])=>e.total(t-1),z=({overscan:e=0,totalCount:t=0,itemHeight:r})=>{const n=o(0),i=o(0),s=o(0),d=o(0),p=o(),g=o(t),m=o(),v=o(),x=o(!1);let z=y.create();const C=o([]);r&&(z=z.insert(0,0,r));const W=o(z);r||p.pipe(f(W.subscribe,C.subscribe)).subscribe(([e,t,r])=>{let n=t;for(let{start:t,end:r,size:i}of e)n=n.insert(t,r,i);n!==t&&W.next(n)});let R=new b;m.subscribe(e=>{R=new k(e),g.next(R.totalCount()),C.next(R.groupIndices())});const H=l(W.subscribe,g.subscribe).pipe(u(M)),T=l(H.subscribe,d.subscribe).pipe(u(([e,t])=>e+t)),V=l(W.subscribe,C.subscribe).pipe(u(([e,t])=>e.getOffsets(t))),S=o([]);l(W.subscribe,v.subscribe,g.subscribe).pipe(c(e=>e[1]>0),u(([e,t,r])=>{const n=Math.max(0,Math.min(t-1,r));return R.transpose(e.indexRange(0,n))})).subscribe(S.next),l(W.subscribe,V.subscribe,s.subscribe).pipe(c(e=>!e[1].empty()&&!e[0].empty()),f(S.subscribe),u(([[e,t,r],n])=>{const i=t.findMaxValue(r);if(1===n.length&&n[0].index===i)return n;const s=e.itemAt(i);return R.transpose([s])})).subscribe(S.next);const N=S.pipe(u(e=>e.reduce((e,t)=>e+t.size,0))),O=S.pipe(u(e=>e.length&&e[e.length-1].index+1)),j=l(n.subscribe,s.subscribe,N.subscribe,i.subscribe,d.subscribe,O.subscribe,g.subscribe,W.subscribe).pipe(function(e,t){let r=t;return(t,n)=>{n(r=e(r,t))}}((e=>(t,[r,n,i,s,o,l,u,a])=>{const h=t.length;if(0===u)return 0===h?t:[];const c=E(t),f=c-n+s-o-i,d=Math.max(u-1,0),p=h>0&&(t[0].index<l||t[h-1].index>d);if(f<r||p){const t=Math.max(n+i,i),s=n+r+2*e-1,o=R.transpose(a.range(t,s,l,d));return o}if(c>n+i){const t=Math.max(n+i-2*e,i),s=n+r-1;return R.transpose(a.range(t,s,l,d))}return t})(e),[])),L=o(0);let P=0;j.pipe(u(e=>e.length?e[e.length-1].index:0)).subscribe(e=>{P<e&&(P=e,L.next(e))});const A=l(j.subscribe,s.subscribe,N.subscribe).pipe(u(([e,t,r])=>E(e)-t-r));return s.pipe(h(1),a(!0)).subscribe(x.next),s.pipe(h(1),a(!1),function(e){let t,r;return(n,i)=>{t=n,r&&clearTimeout(r),r=setTimeout(()=>{i(t)},e)}}(200)).subscribe(x.next),{groupCounts:I(m),itemHeights:I(p),footerHeight:I(d),listHeight:I(i),viewportHeight:I(n),scrollTop:I(s),topItemCount:I(v),totalCount:I(g),list:w(j),topList:w(S),listOffset:w(A),totalHeight:w(T),endReached:w(L),isScrolling:w(x),stickyItems:w(C)}},C=(e,n,i)=>{const s=t.useRef(null),o=t.useRef(0),l=new r(t=>{const r=t[0].contentRect.height;o.current!==r&&(o.current=r,i&&i(t[0].target),e(r))});return e=>{e?(l.observe(e),n&&n(e),s.current=e):(l.unobserve(s.current),s.current=null)}};function W(e,r){const[n,i]=t.useState(r);return t.useLayoutEffect(()=>{e(i)},[]),n}const R={height:"40rem",overflowY:"auto",WebkitOverflowScrolling:"touch",position:"relative",outline:"none"},H=({children:e,style:r})=>{const{scrollTop:s}=t.useContext(i),o=t.useRef(null),l=t.useCallback(e=>{s(e.target.scrollTop)},[]),u=t.useCallback(e=>{e?(e.addEventListener("scroll",l,{passive:!0}),o.current=e):o.current.removeEventListener("scroll",l)},[]);return n.createElement("div",{ref:u,style:{...R,...r},tabIndex:0},e)},T=({list:e,transform:r="",render:s})=>{const{stickyItems:o}=t.useContext(i),l=W(e,[]),u=W(o,[]),a=t.useCallback(e=>{const t=u.some(t=>t===e),n={transform:r,zIndex:t?2:void 0,position:t?"relative":void 0};return n},[u,r]);return 0===l.length?null:n.createElement(n.Fragment,null,l.map(e=>n.createElement("div",{key:e.index,"data-index":e.index,"data-known-size":e.size,style:a(e.index)},s(e))))},V=()=>{const e=W(t.useContext(i).totalHeight,0);return n.createElement("div",{style:{height:`${e}px`,position:"absolute",top:0}}," ")},S=({footer:e})=>{const r=C(t.useContext(i).footerHeight);return n.createElement("footer",{ref:r},e())},N={top:0,position:"sticky",height:"100%",overflow:"hidden",WebkitBackfaceVisibility:"hidden"},O=({style:e,footer:r,item:s,fixedItemHeight:o})=>{const{itemHeights:l,listHeight:u,viewportHeight:a,listOffset:h,list:c,topList:f}=t.useContext(i),d=W(h,0),p=t.useCallback(e=>{const t=[];for(var r=0,n=e.length;r<n;r++){let n=e.item(r);if(!n||"DIV"!==n.tagName)continue;const i=parseInt(n.dataset.index),s=n.offsetHeight;0===t.length||t[t.length-1].size!==s?t.push({start:i,end:i,size:s}):t[t.length-1].end++}t.length>0&&l(t)},[]),g=C(u,()=>{},e=>{o||p(e.children)}),m=C(a,e=>{""===e.style.position&&(e.style.position="-webkit-sticky")}),v=`translateY(${d}px)`,y=`translateY(${-d}px)`;return n.createElement(H,{style:e},n.createElement("div",{style:N,ref:m},n.createElement("div",{style:{transform:v}},n.createElement("div",{ref:g},n.createElement(T,{list:f,transform:y,render:s}),n.createElement(T,{list:c,render:s}),r&&n.createElement(S,{footer:r})))),n.createElement(V,null))},j=({contextValue:e,style:t,item:r,footer:s,itemHeight:o})=>n.createElement(i.Provider,{value:e},n.createElement(O,{style:t||{},item:r,footer:s,fixedItemHeight:void 0!==o}));e.GroupedVirtuoso=class extends t.PureComponent{constructor(e){super(e),this.itemRender=(e=>"group"==e.type?this.props.group(e.groupIndex):this.props.item(e.transposedIndex,e.groupIndex)),this.state=z(e)}static getDerivedStateFromProps(e,t){return t.endReached(e.endReached),t.isScrolling(e.scrollingStateChange),t.groupCounts(e.groupCounts),null}render(){return n.createElement(j,{contextValue:this.state,style:this.props.style,item:this.itemRender,footer:this.props.footer,itemHeight:this.props.itemHeight})}},e.Virtuoso=class extends t.PureComponent{constructor(e){super(e),this.itemRenderer=(e=>this.props.item(e.index)),this.state=z(e)}static getDerivedStateFromProps(e,t){return t.isScrolling(e.scrollingStateChange),t.endReached(e.endReached),t.topItemCount(e.topItems||0),t.totalCount(e.totalCount),null}render(){return n.createElement(j,{contextValue:this.state,style:this.props.style,item:this.itemRenderer,footer:this.props.footer,itemHeight:this.props.itemHeight})}},e.VirtuosoPresentation=j}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("resize-observer-polyfill")):"function"==typeof define&&define.amd?define(["exports","react","resize-observer-polyfill"],t):(e=e||self,t(e["react-virtuoso"]={},e.React,e.ResizeObserver))}(this,function(e,t,r){"use strict";var n="default"in t?t.default:t;r=r&&r.hasOwnProperty("default")?r.default:r;const i=t.createContext(void 0);function s(e){return function(...t){const r=function(...e){return 0===e.length?(e,t)=>t(e):1===e.length?e[0]:(t,r)=>{let n=e=>r(e);e.slice().reverse().forEach(e=>{const t=n;n=(r=>e(r,t))}),n(t)}}(...t);return function(e,t){const r=r=>e(e=>t(e,r));return{subscribe:r,pipe:s(r)}}(e,r)}}function o(e){let t=[],r=e;const n=e=>(t.push(e),void 0!==r&&e(r),()=>{t=t.filter(t=>t!==e)});return{next:e=>{e!==r&&(r=e,t.forEach(t=>t(e)))},subscribe:n,pipe:s(n),subscribers:t}}function l(...e){const t=Array(e.length).fill(!1),r=Array(e.length);let n=[];const i=e=>{t.every(e=>e)&&e.forEach(e=>e(r))};e.forEach((e,s)=>{e(e=>{t[s]=!0,r[s]=e,i(n)})});const o=e=>(n.push(e),i([e]),()=>{n=n.filter(t=>t!==e)});return{subscribe:o,pipe:s(o)}}function u(e){return(t,r)=>{r(e(t))}}function a(e){return(t,r)=>r(e)}function h(e){return(t,r)=>{e>0?e--:r(t)}}function c(e){return(t,r)=>{e(t)&&r(t)}}function f(...e){const t=Array(e.length).fill(!1),r=Array(e.length);return e.forEach((e,n)=>{e(e=>{r[n]=e,t[n]=!0})}),(e,n)=>{t.every(e=>e)&&n([e,...r])}}class d{constructor(){this.level=0}rebalance(){return this}adjust(){return this}remove(){return this}find(){}findWith(){}findMax(){return-Infinity}findMaxValue(){}insert(e,t){return new m({key:e,value:t,level:1})}walkWithin(){return[]}walk(){return[]}ranges(){return[]}rangesWithin(){return[]}empty(){return!0}isSingle(){return!0}isInvariant(){return!0}keys(){return[]}}const p=new d;Object.freeze(p);class g extends Error{constructor(e){super(`Unreachable case: ${e}`)}}class m{constructor({key:e,value:t,level:r,left:n=p,right:i=p}){this.key=e,this.value=t,this.level=r,this.left=n,this.right=i}remove(e){const{left:t,right:r}=this;if(e===this.key){if(t.empty())return r;if(r.empty())return t;{const[e,r]=t.last();return this.clone({key:e,value:r,left:t.deleteLast()}).adjust()}}return e<this.key?this.clone({left:t.remove(e)}).adjust():this.clone({right:r.remove(e)}).adjust()}empty(){return!1}find(e){return e===this.key?this.value:e<this.key?this.left.find(e):this.right.find(e)}findWith(e){const t=e(this.value);switch(t){case-1:return this.left.findWith(e);case 0:return[this.key,this.value];case 1:return this.right.findWith(e);default:throw new g(t)}}findMax(e){if(this.key===e)return e;if(this.key<e){const t=this.right.findMax(e);return-Infinity===t?this.key:t}return this.left.findMax(e)}findMaxValue(e){if(this.key===e)return this.value;if(this.key<e){const t=this.right.findMaxValue(e);return void 0===t?this.value:t}return this.left.findMaxValue(e)}insert(e,t){return e===this.key?this.clone({key:e,value:t}):e<this.key?this.clone({left:this.left.insert(e,t)}).rebalance():this.clone({right:this.right.insert(e,t)}).rebalance()}walkWithin(e,t){const{key:r,value:n}=this;let i=[];return r>e&&(i=i.concat(this.left.walkWithin(e,t))),r>=e&&r<=t&&i.push({key:r,value:n}),r<=t&&(i=i.concat(this.right.walkWithin(e,t))),i}walk(){return[...this.left.walk(),{key:this.key,value:this.value},...this.right.walk()]}last(){return this.right.empty()?[this.key,this.value]:this.right.last()}deleteLast(){return this.right.empty()?this.left:this.clone({right:this.right.deleteLast()}).adjust()}clone(e){return new m({key:void 0!==e.key?e.key:this.key,value:void 0!==e.value?e.value:this.value,level:void 0!==e.level?e.level:this.level,left:void 0!==e.left?e.left:this.left,right:void 0!==e.right?e.right:this.right})}isSingle(){return this.level>this.right.level}rebalance(){return this.skew().split()}adjust(){const{left:e,right:t,level:r}=this;if(t.level>=r-1&&e.level>=r-1)return this;if(r>t.level+1){if(e.isSingle())return this.clone({level:r-1}).skew();if(e.empty()||e.right.empty())throw new Error("Unexpected empty nodes");return e.right.clone({left:e.clone({right:e.right.left}),right:this.clone({left:e.right.right,level:r-1}),level:r})}if(this.isSingle())return this.clone({level:r-1}).split();if(t.empty()||t.left.empty())throw new Error("Unexpected empty nodes");{const e=t.left,n=e.isSingle()?t.level-1:t.level;return e.clone({left:this.clone({right:e.left,level:r-1}),right:t.clone({left:e.right,level:n}).split(),level:e.level+1})}}isInvariant(){const{left:e,right:t,level:r}=this;return r===e.level+1&&((r===t.level||r===t.level+1)&&(!(!t.empty()&&r<=t.right.level)&&(e.isInvariant()&&t.isInvariant())))}keys(){return[...this.left.keys(),this.key,...this.right.keys()]}ranges(){return this.toRanges(this.walk())}rangesWithin(e,t){return this.toRanges(this.walkWithin(e,t))}toRanges(e){if(0===e.length)return[];const t=e[0];let{key:r,value:n}=t;const i=[];for(let t=1;t<=e.length;t++){let s=e[t],o=s?s.key-1:Infinity;i.push({start:r,end:o,value:n}),s&&(r=s.key,n=s.value)}return i}split(){const{right:e,level:t}=this;return e.empty()||e.right.empty()||e.level!=t||e.right.level!=t?this:e.clone({left:this.clone({right:e.left}),level:t+1})}skew(){const{left:e}=this;return e.empty()||e.level!==this.level?this:e.clone({right:this.clone({left:e.right})})}}class v{constructor(e){this.root=e}static empty(){return new v(p)}find(e){return this.root.find(e)}findMax(e){return this.root.findMax(e)}findMaxValue(e){if(this.empty())throw new Error("Searching for max value in an empty tree");return this.root.findMaxValue(e)}findWith(e){return this.root.findWith(e)}insert(e,t){return new v(this.root.insert(e,t))}remove(e){return new v(this.root.remove(e))}empty(){return this.root.empty()}keys(){return this.root.keys()}walk(){return this.root.walk()}walkWithin(e,t){let r=this.root.findMax(e);return this.root.walkWithin(r,t)}ranges(){return this.root.ranges()}rangesWithin(e,t){let r=this.root.findMax(e);return this.root.rangesWithin(r,t)}isInvariant(){return this.root.isInvariant()}}class y{static create(){return new y(v.empty())}constructor(e){this.rangeTree=e;let t=v.empty(),r=0;for(const{start:n,end:i,value:s}of e.ranges())t=t.insert(r,{startIndex:n,endIndex:i,size:s}),Infinity!==i&&(r+=(i-n+1)*s);this.offsetTree=t}empty(){return this.rangeTree.empty()}insert(e,t,r){let n=this.rangeTree;if(n.empty())return new y(n.insert(0,r));const i=n.rangesWithin(e-1,t+1);if(i.some(n=>n.start===e&&(n.end===t||Infinity===n.end)&&n.value===r))return this;let s=!1,o=!1;for(const{start:e,end:l,value:u}of i)s?(t>=e||r===u)&&(n=n.remove(e)):(o=u!==r,s=!0),l>t&&t>=e&&(u===r||isNaN(u)||(n=n.insert(t+1,u)));return o&&(n=n.insert(e,r)),n===this.rangeTree?this:new y(n)}insertException(e,t){return this.empty()?new y(this.rangeTree.insert(1,NaN).insert(e,t)):this.insert(e,e,t)}offsetOf(e){if(this.offsetTree.empty())return 0;const t=this.offsetTree.findWith(t=>t.startIndex>e?-1:t.endIndex<e?1:0);if(t){const[r,{startIndex:n,size:i}]=t;return r+(e-n)*i}throw new Error(`Requested offset outside of the known ones, index: ${e}`)}itemAt(e){const t=this.rangeTree.findMaxValue(e);return{index:e,size:t,offset:NaN}}indexRange(e,t){if(0===t)return[];if(this.rangeTree.empty())return[{index:0,size:0,offset:NaN}];const r=this.rangeTree.rangesWithin(e,t),n=[];for(const i of r){const r=Math.max(e,i.start),s=void 0===i.end?Infinity:i.end,o=Math.min(t,s);for(let e=r;e<=o;e++)n.push({index:e,size:i.value,offset:NaN})}return n}range(e,t,r=0,n=Infinity){if(this.offsetTree.empty())return[{index:0,size:0,offset:0}];const i=this.offsetTree.rangesWithin(e,t),s=[];for(let{start:o,value:{startIndex:l,endIndex:u,size:a}}of i){let i=o,h=l;if(o<e&&(h+=Math.floor((e-o)/a),i+=(h-l)*a),h<r&&(i+=(r-h)*a,h=r),isNaN(a))return s.push({index:h,size:0,offset:i}),s;u=Math.min(u,n);for(let e=h;e<=u&&!(i>t);e++)s.push({index:e,size:a,offset:i}),i+=a}return s}total(e){const t=this.rangeTree.rangesWithin(0,e);let r=0;for(let{start:n,end:i,value:s}of t)i=Math.min(i,e),r+=(i-n+1)*s;return r}getOffsets(e){let t=v.empty();return e.forEach(e=>{const r=this.offsetOf(e);t=t.insert(r,e)}),new x(t)}}class x{constructor(e){this.tree=e}findMaxValue(e){return this.tree.findMaxValue(e)}empty(){return this.tree.empty()}}class b{transpose(e){return e.map(e=>({groupIndex:0,index:e.index,offset:e.offset,size:e.size,transposedIndex:e.index,type:"item"}))}}class k{constructor(e){this.count=e.reduce((e,t)=>e+t+1,0);let t=v.empty(),r=0,n=0;for(let i of e)t=t.insert(n,[r,n]),r++,n+=i+1;this.tree=t}totalCount(){return this.count}transpose(e){return e.map(e=>{const t=this.tree.find(e.index);if(t)return{groupIndex:t[0],index:e.index,offset:e.offset,size:e.size,type:"group"};const[r]=this.tree.findMaxValue(e.index);return{groupIndex:r,index:e.index,offset:e.offset,size:e.size,transposedIndex:e.index-r-1,type:"item"}})}groupIndices(){return this.tree.keys()}}function w(e){let t,r=e=>{t&&t(e)},n=!1;return i=>{t=i,n||(e.subscribe(r),n=!0)}}function I(e){return e.next}const E=e=>e.length>0?e[0].offset:0,M=([e,t])=>e.total(t-1),z=({overscan:e=0,totalCount:t=0,itemHeight:r})=>{const n=o(0),i=o(0),s=o(0),d=o(0),p=o(),g=o(t),m=o(),v=o(),x=o(!1);let z=y.create();const C=o([]);r&&(z=z.insert(0,0,r));const W=o(z);r||p.pipe(f(W.subscribe,C.subscribe)).subscribe(([e,t,r])=>{let n=t;for(let{start:t,end:r,size:i}of e)n=n.insert(t,r,i);n!==t&&W.next(n)});let R=new b;m.subscribe(e=>{R=new k(e),g.next(R.totalCount()),C.next(R.groupIndices())});const H=l(W.subscribe,g.subscribe).pipe(u(M)),T=l(H.subscribe,d.subscribe).pipe(u(([e,t])=>e+t)),V=l(W.subscribe,C.subscribe).pipe(u(([e,t])=>e.getOffsets(t))),S=o([]);l(W.subscribe,v.subscribe,g.subscribe).pipe(c(e=>e[1]>0),u(([e,t,r])=>{const n=Math.max(0,Math.min(t-1,r));return R.transpose(e.indexRange(0,n))})).subscribe(S.next),l(W.subscribe,V.subscribe,s.subscribe).pipe(c(e=>!e[1].empty()&&!e[0].empty()),f(S.subscribe),u(([[e,t,r],n])=>{const i=t.findMaxValue(r);if(1===n.length&&n[0].index===i)return n;const s=e.itemAt(i);return R.transpose([s])})).subscribe(S.next);const N=S.pipe(u(e=>e.reduce((e,t)=>e+t.size,0))),O=S.pipe(u(e=>e.length&&e[e.length-1].index+1)),j=l(n.subscribe,s.subscribe,N.subscribe,i.subscribe,d.subscribe,O.subscribe,g.subscribe,W.subscribe).pipe(function(e,t){let r=t;return(t,n)=>{n(r=e(r,t))}}((e=>(t,[r,n,i,s,o,l,u,a])=>{const h=t.length;if(0===u)return 0===h?t:[];const c=E(t),f=c-n+s-o-i,d=Math.max(u-1,0),p=h>0&&(t[0].index<l||t[h-1].index>d);if(f<r||p){const t=Math.max(n+i,i),s=n+r+2*e-1,o=R.transpose(a.range(t,s,l,d));return o}if(c>n+i){const t=Math.max(n+i-2*e,i),s=n+r-1;return R.transpose(a.range(t,s,l,d))}return t})(e),[])),L=o(0);let P=0;j.pipe(u(e=>e.length?e[e.length-1].index:0)).pipe(f(g.subscribe)).subscribe(([e,t])=>{e==t-1&&P!==e&&(P=e,L.next(e))});const A=l(j.subscribe,s.subscribe,N.subscribe).pipe(u(([e,t,r])=>E(e)-t-r));return s.pipe(h(1),a(!0)).subscribe(x.next),s.pipe(h(1),a(!1),function(e){let t,r;return(n,i)=>{t=n,r&&clearTimeout(r),r=setTimeout(()=>{i(t)},e)}}(200)).subscribe(x.next),{groupCounts:I(m),itemHeights:I(p),footerHeight:I(d),listHeight:I(i),viewportHeight:I(n),scrollTop:I(s),topItemCount:I(v),totalCount:I(g),list:w(j),topList:w(S),listOffset:w(A),totalHeight:w(T),endReached:w(L),isScrolling:w(x),stickyItems:w(C)}},C=(e,n,i)=>{const s=t.useRef(null),o=t.useRef(0),l=new r(t=>{const r=t[0].contentRect.height;o.current!==r&&(o.current=r,i&&i(t[0].target),e(r))});return e=>{e?(l.observe(e),n&&n(e),s.current=e):(l.unobserve(s.current),s.current=null)}};function W(e,r){const[n,i]=t.useState(r);return t.useLayoutEffect(()=>{e(i)},[]),n}const R={height:"40rem",overflowY:"auto",WebkitOverflowScrolling:"touch",position:"relative",outline:"none"},H=({children:e,style:r})=>{const{scrollTop:s}=t.useContext(i),o=t.useRef(null),l=t.useCallback(e=>{s(e.target.scrollTop)},[]),u=t.useCallback(e=>{e?(e.addEventListener("scroll",l,{passive:!0}),o.current=e):o.current.removeEventListener("scroll",l)},[]);return n.createElement("div",{ref:u,style:{...R,...r},tabIndex:0},e)},T=({list:e,transform:r="",render:s})=>{const{stickyItems:o}=t.useContext(i),l=W(e,[]),u=W(o,[]),a=t.useCallback(e=>{const t=u.some(t=>t===e),n={transform:r,zIndex:t?2:void 0,position:t?"relative":void 0};return n},[u,r]);return 0===l.length?null:n.createElement(n.Fragment,null,l.map(e=>n.createElement("div",{key:e.index,"data-index":e.index,"data-known-size":e.size,style:a(e.index)},s(e))))},V=()=>{const e=W(t.useContext(i).totalHeight,0);return n.createElement("div",{style:{height:`${e}px`,position:"absolute",top:0}}," ")},S=({footer:e})=>{const r=C(t.useContext(i).footerHeight);return n.createElement("footer",{ref:r},e())},N={top:0,position:"sticky",height:"100%",overflow:"hidden",WebkitBackfaceVisibility:"hidden"},O=({style:e,footer:r,item:s,fixedItemHeight:o})=>{const{itemHeights:l,listHeight:u,viewportHeight:a,listOffset:h,list:c,topList:f}=t.useContext(i),d=W(h,0),p=t.useCallback(e=>{const t=[];for(var r=0,n=e.length;r<n;r++){let n=e.item(r);if(!n||"DIV"!==n.tagName)continue;const i=parseInt(n.dataset.index),s=n.offsetHeight;0===t.length||t[t.length-1].size!==s?t.push({start:i,end:i,size:s}):t[t.length-1].end++}t.length>0&&l(t)},[]),g=C(u,()=>{},e=>{o||p(e.children)}),m=C(a,e=>{""===e.style.position&&(e.style.position="-webkit-sticky")}),v=`translateY(${d}px)`,y=`translateY(${-d}px)`;return n.createElement(H,{style:e},n.createElement("div",{style:N,ref:m},n.createElement("div",{style:{transform:v}},n.createElement("div",{ref:g},n.createElement(T,{list:f,transform:y,render:s}),n.createElement(T,{list:c,render:s}),r&&n.createElement(S,{footer:r})))),n.createElement(V,null))},j=({contextValue:e,style:t,item:r,footer:s,itemHeight:o})=>n.createElement(i.Provider,{value:e},n.createElement(O,{style:t||{},item:r,footer:s,fixedItemHeight:void 0!==o}));e.GroupedVirtuoso=class extends t.PureComponent{constructor(e){super(e),this.itemRender=(e=>"group"==e.type?this.props.group(e.groupIndex):this.props.item(e.transposedIndex,e.groupIndex)),this.state=z(e)}static getDerivedStateFromProps(e,t){return t.endReached(e.endReached),t.isScrolling(e.scrollingStateChange),t.groupCounts(e.groupCounts),null}render(){return n.createElement(j,{contextValue:this.state,style:this.props.style,item:this.itemRender,footer:this.props.footer,itemHeight:this.props.itemHeight})}},e.Virtuoso=class extends t.PureComponent{constructor(e){super(e),this.itemRenderer=(e=>this.props.item(e.index)),this.state=z(e)}static getDerivedStateFromProps(e,t){return t.isScrolling(e.scrollingStateChange),t.endReached(e.endReached),t.topItemCount(e.topItems||0),t.totalCount(e.totalCount),null}render(){return n.createElement(j,{contextValue:this.state,style:this.props.style,item:this.itemRenderer,footer:this.props.footer,itemHeight:this.props.itemHeight})}},e.VirtuosoPresentation=j}); | ||
//# sourceMappingURL=react-virtuoso.umd.production.js.map |
{ | ||
"name": "react-virtuoso", | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"homepage": "https://virtuoso.dev", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -13,3 +13,3 @@ <img src="https://user-images.githubusercontent.com/13347/57673110-85aab180-7623-11e9-97b4-27bbdcf8cf40.png" width="292"> | ||
To see live examples, check the [storybook](//virtuoso.dev). | ||
To see live examples, check the [website](//virtuoso.dev). | ||
@@ -52,12 +52,12 @@ ## Get Started | ||
return ( | ||
<Virtuoso | ||
style={{ height: '300px', width: '500px' }} | ||
totalCount={100} | ||
item={index => <div>Item {index}</div>} | ||
footer={() => <div>-- end reached --</div>} | ||
/> | ||
<Virtuoso | ||
style={{ height: '300px', width: '500px' }} | ||
totalCount={100} | ||
item={index => <div>Item {index}</div>} | ||
footer={() => <div>-- end reached --</div>} | ||
/> | ||
) | ||
``` | ||
Check the [footer](//virtuoso.dev/?path=/story/features-overview--footer), [load more](//virtuoso.dev/?path=/story/scenarios--press-to-load-more) and [endless scrolling](//virtuoso.dev/?path=/story/scenarios--endless-scrolling) examples for practical applications of the footer. | ||
Check the [footer](//virtuoso.dev/footer), [load more](//virtuoso.dev/press-to-load-more) and [endless scrolling](//virtuoso.dev/endless-scrolling) examples for practical applications of the footer. | ||
@@ -70,24 +70,24 @@ ### Pinned Items | ||
return ( | ||
<Virtuoso | ||
style={{ height: '500px', width: '500px' }} | ||
topItems={2} | ||
totalCount={100000} | ||
item={index => <div>Item {index}</div>} | ||
/> | ||
) | ||
<Virtuoso | ||
style={{ height: '500px', width: '500px' }} | ||
topItems={2} | ||
totalCount={100000} | ||
item={index => <div>Item {index}</div>} | ||
/> | ||
) | ||
``` | ||
Check the [fixed top items](//virtuoso.dev/?path=/story/features-overview--fixed-top-items) example for a live version of the above. | ||
Check the [fixed top items](//virtuoso.dev/top-items) example for a live version of the above. | ||
### Grouping | ||
The package exports two components - `Virtuoso` and `GroupedVirtuoso`. | ||
The package exports two components - `Virtuoso` and `GroupedVirtuoso`. | ||
The grouped component is similar to the flat one, with the following differences: | ||
* Instead of `totalCount`, the component accepts `groupedCounts: number[]`, which specifies the amount of items in each group. | ||
- Instead of `totalCount`, the component accepts `groupedCounts: number[]`, which specifies the amount of items in each group. | ||
For example, passing `[20, 30]` will cause the component to render two groups with 20 and 30 items respectively; | ||
* In addition the `item` render prop, the component requires an additional `group` render prop, | ||
- In addition the `item` render prop, the component requires an additional `group` render prop, | ||
which renders the group header. The property receives the zero-based group index as a parameter; | ||
* The `item` render prop gets called with an additional second parameter, `groupIndex: number`. | ||
- The `item` render prop gets called with an additional second parameter, `groupIndex: number`. | ||
@@ -105,4 +105,12 @@ ```jsx | ||
groupCounts={groupCounts} | ||
group={ index => <div>Group {index * 10} - {index * 10 + 10}</div> } | ||
item={ (index, groupIndex) => <div>Item {index} from group {groupIndex}</div> } | ||
group={index => ( | ||
<div> | ||
Group {index * 10} - {index * 10 + 10} | ||
</div> | ||
)} | ||
item={(index, groupIndex) => ( | ||
<div> | ||
Item {index} from group {groupIndex} | ||
</div> | ||
)} | ||
/> | ||
@@ -112,7 +120,7 @@ ) | ||
Check the | ||
[grouped numbers](//virtuoso.dev/?path=/story/grouping--grouped-numbers), | ||
[grouped by first letter](//virtuoso.dev/?path=/story/grouping--grouped-by-first-letter) and | ||
[groups with load on demand](//virtuoso.dev/?path=/story/grouping--groups-with-load-on-demand) | ||
examples for working examples. | ||
Check the | ||
[grouped numbers](//virtuoso.dev/grouped-numbers), | ||
[grouped by first letter](//virtuoso.dev/grouped-by-first-letter) and | ||
[groups with load on demand](//virtuoso.dev/grouped-with-load-on-demand) | ||
examples for working examples. | ||
@@ -158,3 +166,3 @@ ## Tweaking Performance | ||
Gets called when the user scrolls to the end of the list. | ||
Receives the last item index as an argument. Can be used to implement [endless scrolling](//virtuoso.dev/?path=/story/scenarios--endless-scrolling). | ||
Receives the last item index as an argument. Can be used to implement [endless scrolling](//virtuoso.dev/endless-scrolling). | ||
@@ -161,0 +169,0 @@ ### `scrollingStateChange?: (isScrolling: boolean) => void` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
3385002
31
27404
237