react-virtuoso
Advanced tools
Comparing version 0.4.3 to 0.4.4
@@ -1134,3 +1134,10 @@ 'use strict'; | ||
const list$ = combineLatest(viewportHeight$.subscribe, scrollTop$.subscribe, topListHeight$.subscribe, listHeight$.subscribe, footerHeight$.subscribe, minListIndex$.subscribe, totalCount$.subscribe, offsetList$.subscribe).pipe(scan(listScanner(overscan), [])); | ||
const endReached$ = list$.pipe(map(items => items.length ? items[items.length - 1].index : 0), scan((prev, current) => Math.max(prev, current), 0)); | ||
const endReached$ = subject(0); | ||
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); | ||
} | ||
}); | ||
const listOffset$ = combineLatest(list$.subscribe, scrollTop$.subscribe, topListHeight$.subscribe).pipe(map(([items, scrollTop, topListHeight]) => getListTop(items) - scrollTop - topListHeight)); | ||
@@ -1137,0 +1144,0 @@ scrollTop$.pipe(skip(1), mapTo(true)).subscribe(isScrolling$.next); |
@@ -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,t){let r=t;return(t,n)=>{n(r=e(r,t))}}function d(...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 p{constructor(){this.level=0}rebalance(){return this}adjust(){return this}remove(){return this}find(){}findWith(){}findMax(){return-Infinity}findMaxValue(){}insert(e,t){return new v({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 g=new p;Object.freeze(g);class m extends Error{constructor(e){super(`Unreachable case: ${e}`)}}class v{constructor({key:e,value:t,level:r,left:n=g,right:i=g}){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 m(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 v({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 y{constructor(e){this.root=e}static empty(){return new y(g)}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 y(this.root.insert(e,t))}remove(e){return new y(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 x{static create(){return new x(y.empty())}constructor(e){this.rangeTree=e;let t=y.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 x(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 x(n)}insertException(e,t){return this.empty()?new x(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=y.empty();return e.forEach(e=>{const r=this.offsetOf(e);t=t.insert(r,e)}),new b(t)}}class b{constructor(e){this.tree=e}findMaxValue(e){return this.tree.findMaxValue(e)}empty(){return this.tree.empty()}}class k{transpose(e){return e.map(e=>({groupIndex:0,index:e.index,offset:e.offset,size:e.size,transposedIndex:e.index,type:"item"}))}}class w{constructor(e){this.count=e.reduce((e,t)=>e+t+1,0);let t=y.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 I(e){let t,r=e=>{t&&t(e)},n=!1;return i=>{t=i,n||(e.subscribe(r),n=!0)}}function E(e){return e.next}const M=e=>e.length>0?e[0].offset:0,C=([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),p=o(0),g=o(),m=o(t),v=o(),y=o(),b=o(!1);let z=x.create();const W=o([]);r&&(z=z.insert(0,0,r));const H=o(z);r||g.pipe(d(H.subscribe,W.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&&H.next(n)});let R=new k;v.subscribe(e=>{R=new w(e),m.next(R.totalCount()),W.next(R.groupIndices())});const T=l(H.subscribe,m.subscribe).pipe(u(C)),V=l(T.subscribe,p.subscribe).pipe(u(([e,t])=>e+t)),S=l(H.subscribe,W.subscribe).pipe(u(([e,t])=>e.getOffsets(t))),N=o([]);l(H.subscribe,y.subscribe,m.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(N.next),l(H.subscribe,S.subscribe,s.subscribe).pipe(c(e=>!e[1].empty()&&!e[0].empty()),d(N.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(N.next);const j=N.pipe(u(e=>e.reduce((e,t)=>e+t.size,0))),L=N.pipe(u(e=>e.length&&e[e.length-1].index+1)),O=l(n.subscribe,s.subscribe,j.subscribe,i.subscribe,p.subscribe,L.subscribe,m.subscribe,H.subscribe).pipe(f((e=>(t,[r,n,i,s,o,l,u,a])=>{const h=t.length;if(0===u)return 0===h?t:[];const c=M(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),[])),A=O.pipe(u(e=>e.length?e[e.length-1].index:0),f((e,t)=>Math.max(e,t),0)),P=l(O.subscribe,s.subscribe,j.subscribe).pipe(u(([e,t,r])=>M(e)-t-r));return s.pipe(h(1),a(!0)).subscribe(b.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(b.next),{groupCounts:E(v),itemHeights:E(g),footerHeight:E(p),listHeight:E(i),viewportHeight:E(n),scrollTop:E(s),topItemCount:E(y),totalCount:E(m),list:I(O),topList:I(N),listOffset:I(P),totalHeight:I(V),endReached:I(A),isScrolling:I(b),stickyItems:I(W)}},W=(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 H(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"},T=({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:{...R,...n},tabIndex:0},e)},V=({list:e,transform:n="",render:s})=>{const{stickyItems:o}=t.useContext(i),l=H(e,[]),u=H(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))))},S=()=>{const e=H(t.useContext(i).totalHeight,0);return r.createElement("div",{style:{height:`${e}px`,position:"absolute",top:0}}," ")},N=({footer:e})=>{const n=W(t.useContext(i).footerHeight);return r.createElement("footer",{ref:n},e())},j={top:0,position:"sticky",height:"100%",overflow:"hidden",WebkitBackfaceVisibility:"hidden"},L=({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=H(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=W(u,()=>{},e=>{o||p(e.children)}),m=W(a,e=>{""===e.style.position&&(e.style.position="-webkit-sticky")}),v=`translateY(${d}px)`,y=`translateY(${-d}px)`;return r.createElement(T,{style:e},r.createElement("div",{style:j,ref:m},r.createElement("div",{style:{transform:v}},r.createElement("div",{ref:g},r.createElement(V,{list:f,transform:y,render:s}),r.createElement(V,{list:c,render:s}),n&&r.createElement(N,{footer:n})))),r.createElement(S,null))},O=({contextValue:e,style:t,item:n,footer:s,itemHeight:o})=>r.createElement(i.Provider,{value:e},r.createElement(L,{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=z(e)}static getDerivedStateFromProps(e,t){return t.endReached(e.endReached),t.isScrolling(e.scrollingStateChange),t.groupCounts(e.groupCounts),null}render(){return r.createElement(O,{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=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 r.createElement(O,{contextValue:this.state,style:this.props.style,item:this.itemRenderer,footer:this.props.footer,itemHeight:this.props.itemHeight})}},exports.VirtuosoPresentation=O; | ||
"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; | ||
//# 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 a=t(void 0);function u(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:u(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:u(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:u(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,t){let r=t;return(t,i)=>{i(r=e(r,t))}}function y(...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 x{constructor(){this.level=0}rebalance(){return this}adjust(){return this}remove(){return this}find(){}findWith(){}findMax(){return-Infinity}findMaxValue(){}insert(e,t){return new w({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 b=new x;Object.freeze(b);class k extends Error{constructor(e){super(`Unreachable case: ${e}`)}}class w{constructor({key:e,value:t,level:r,left:i=b,right:n=b}){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 k(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 w({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 I{constructor(e){this.root=e}static empty(){return new I(b)}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 I(this.root.insert(e,t))}remove(e){return new I(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 E{static create(){return new E(I.empty())}constructor(e){this.rangeTree=e;let t=I.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 E(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 E(i)}insertException(e,t){return this.empty()?new E(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:a}}of n){let n=o,u=l;if(o<e&&(u+=Math.floor((e-o)/a),n+=(u-l)*a),u<r&&(n+=(r-u)*a,u=r),isNaN(a))return s.push({index:u,size:0,offset:n}),s;h=Math.min(h,i);for(let e=u;e<=h&&!(n>t);e++)s.push({index:e,size:a,offset:n}),n+=a}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=I.empty();return e.forEach(e=>{const r=this.offsetOf(e);t=t.insert(r,e)}),new M(t)}}class M{constructor(e){this.tree=e}findMaxValue(e){return this.tree.findMaxValue(e)}empty(){return this.tree.empty()}}class z{transpose(e){return e.map(e=>({groupIndex:0,index:e.index,offset:e.offset,size:e.size,transposedIndex:e.index,type:"item"}))}}class W{constructor(e){this.count=e.reduce((e,t)=>e+t+1,0);let t=I.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 H(e){let t,r=e=>{t&&t(e)},i=!1;return n=>{t=n,i||(e.subscribe(r),i=!0)}}function T(e){return e.next}const R=e=>e.length>0?e[0].offset:0,V=([e,t])=>e.total(t-1),S=({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),a=c(),u=c(),x=c(!1);let b=E.create();const k=c([]);r&&(b=b.insert(0,0,r));const w=c(b);r||l.pipe(y(w.subscribe,k.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&&w.next(i)});let I=new z;a.subscribe(e=>{I=new W(e),h.next(I.totalCount()),k.next(I.groupIndices())});const M=f(w.subscribe,h.subscribe).pipe(d(V)),S=f(M.subscribe,o.subscribe).pipe(d(([e,t])=>e+t)),C=f(w.subscribe,k.subscribe).pipe(d(([e,t])=>e.getOffsets(t))),N=c([]);f(w.subscribe,u.subscribe,h.subscribe).pipe(m(e=>e[1]>0),d(([e,t,r])=>{const i=Math.max(0,Math.min(t-1,r));return I.transpose(e.indexRange(0,i))})).subscribe(N.next),f(w.subscribe,C.subscribe,s.subscribe).pipe(m(e=>!e[1].empty()&&!e[0].empty()),y(N.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 I.transpose([s])})).subscribe(N.next);const O=N.pipe(d(e=>e.reduce((e,t)=>e+t.size,0))),j=N.pipe(d(e=>e.length&&e[e.length-1].index+1)),L=f(i.subscribe,s.subscribe,O.subscribe,n.subscribe,o.subscribe,j.subscribe,h.subscribe,w.subscribe).pipe(v((e=>(t,[r,i,n,s,o,l,h,a])=>{const u=t.length;if(0===h)return 0===u?t:[];const c=R(t),f=c-i+s-o-n,d=Math.max(h-1,0),p=u>0&&(t[0].index<l||t[u-1].index>d);if(f<r||p){const t=Math.max(i+n,n),s=i+r+2*e-1,o=I.transpose(a.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 I.transpose(a.range(t,s,l,d))}return t})(e),[])),A=L.pipe(d(e=>e.length?e[e.length-1].index:0),v((e,t)=>Math.max(e,t),0)),$=f(L.subscribe,s.subscribe,O.subscribe).pipe(d(([e,t,r])=>R(e)-t-r));return s.pipe(g(1),p(!0)).subscribe(x.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(x.next),{groupCounts:T(a),itemHeights:T(l),footerHeight:T(o),listHeight:T(n),viewportHeight:T(i),scrollTop:T(s),topItemCount:T(u),totalCount:T(h),list:H(L),topList:H(N),listOffset:H($),totalHeight:H(S),endReached:H(A),isScrolling:H(x),stickyItems:H(k)}},C=(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 N(e,t){const[r,s]=i(t);return n(()=>{e(s)},[]),r}const O={height:"40rem",overflowY:"auto",WebkitOverflowScrolling:"touch",position:"relative",outline:"none"},j=({children:t,style:i})=>{const{scrollTop:n}=s(a),l=r(null),h=o(e=>{n(e.target.scrollTop)},[]),u=o(e=>{e?(e.addEventListener("scroll",h,{passive:!0}),l.current=e):l.current.removeEventListener("scroll",h)},[]);return e.createElement("div",{ref:u,style:{...O,...i},tabIndex:0},t)},L=({list:t,transform:r="",render:i})=>{const{stickyItems:n}=s(a),l=N(t,[]),h=N(n,[]),u=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:u(t.index)},i(t))))},A=()=>{const t=N(s(a).totalHeight,0);return e.createElement("div",{style:{height:`${t}px`,position:"absolute",top:0}}," ")},$=({footer:t})=>{const r=C(s(a).footerHeight);return e.createElement("footer",{ref:r},t())},D={top:0,position:"sticky",height:"100%",overflow:"hidden",WebkitBackfaceVisibility:"hidden"},F=({style:t,footer:r,item:i,fixedItemHeight:n})=>{const{itemHeights:l,listHeight:h,viewportHeight:u,listOffset:c,list:f,topList:d}=s(a),p=N(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=C(h,()=>{},e=>{n||g(e.children)}),v=C(u,e=>{""===e.style.position&&(e.style.position="-webkit-sticky")}),y=`translateY(${p}px)`,x=`translateY(${-p}px)`;return e.createElement(j,{style:t},e.createElement("div",{style:D,ref:v},e.createElement("div",{style:{transform:y}},e.createElement("div",{ref:m},e.createElement(L,{list:d,transform:x,render:i}),e.createElement(L,{list:f,render:i}),r&&e.createElement($,{footer:r})))),e.createElement(A,null))},P=({contextValue:t,style:r,item:i,footer:n,itemHeight:s})=>e.createElement(a.Provider,{value:t},e.createElement(F,{style:r||{},item:i,footer:n,fixedItemHeight:void 0!==s}));class U extends l{constructor(e){super(e),this.itemRenderer=(e=>this.props.item(e.index)),this.state=S(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(P,{contextValue:this.state,style:this.props.style,item:this.itemRenderer,footer:this.props.footer,itemHeight:this.props.itemHeight})}}class Y 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=S(e)}static getDerivedStateFromProps(e,t){return t.endReached(e.endReached),t.isScrolling(e.scrollingStateChange),t.groupCounts(e.groupCounts),null}render(){return e.createElement(P,{contextValue:this.state,style:this.props.style,item:this.itemRender,footer:this.props.footer,itemHeight:this.props.itemHeight})}}export{Y as GroupedVirtuoso,U as Virtuoso,P 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)).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}; | ||
//# sourceMappingURL=react-virtuoso.es.production.js.map |
@@ -1135,3 +1135,10 @@ (function (global, factory) { | ||
const list$ = combineLatest(viewportHeight$.subscribe, scrollTop$.subscribe, topListHeight$.subscribe, listHeight$.subscribe, footerHeight$.subscribe, minListIndex$.subscribe, totalCount$.subscribe, offsetList$.subscribe).pipe(scan(listScanner(overscan), [])); | ||
const endReached$ = list$.pipe(map(items => items.length ? items[items.length - 1].index : 0), scan((prev, current) => Math.max(prev, current), 0)); | ||
const endReached$ = subject(0); | ||
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); | ||
} | ||
}); | ||
const listOffset$ = combineLatest(list$.subscribe, scrollTop$.subscribe, topListHeight$.subscribe).pipe(map(([items, scrollTop, topListHeight]) => getListTop(items) - scrollTop - topListHeight)); | ||
@@ -1138,0 +1145,0 @@ scrollTop$.pipe(skip(1), mapTo(true)).subscribe(isScrolling$.next); |
@@ -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,t){let r=t;return(t,n)=>{n(r=e(r,t))}}function d(...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 p{constructor(){this.level=0}rebalance(){return this}adjust(){return this}remove(){return this}find(){}findWith(){}findMax(){return-Infinity}findMaxValue(){}insert(e,t){return new v({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 g=new p;Object.freeze(g);class m extends Error{constructor(e){super(`Unreachable case: ${e}`)}}class v{constructor({key:e,value:t,level:r,left:n=g,right:i=g}){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 m(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 v({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 y{constructor(e){this.root=e}static empty(){return new y(g)}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 y(this.root.insert(e,t))}remove(e){return new y(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 x{static create(){return new x(y.empty())}constructor(e){this.rangeTree=e;let t=y.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 x(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 x(n)}insertException(e,t){return this.empty()?new x(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=y.empty();return e.forEach(e=>{const r=this.offsetOf(e);t=t.insert(r,e)}),new b(t)}}class b{constructor(e){this.tree=e}findMaxValue(e){return this.tree.findMaxValue(e)}empty(){return this.tree.empty()}}class k{transpose(e){return e.map(e=>({groupIndex:0,index:e.index,offset:e.offset,size:e.size,transposedIndex:e.index,type:"item"}))}}class w{constructor(e){this.count=e.reduce((e,t)=>e+t+1,0);let t=y.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 I(e){let t,r=e=>{t&&t(e)},n=!1;return i=>{t=i,n||(e.subscribe(r),n=!0)}}function E(e){return e.next}const M=e=>e.length>0?e[0].offset:0,z=([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),p=o(0),g=o(),m=o(t),v=o(),y=o(),b=o(!1);let C=x.create();const W=o([]);r&&(C=C.insert(0,0,r));const R=o(C);r||g.pipe(d(R.subscribe,W.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&&R.next(n)});let H=new k;v.subscribe(e=>{H=new w(e),m.next(H.totalCount()),W.next(H.groupIndices())});const T=l(R.subscribe,m.subscribe).pipe(u(z)),V=l(T.subscribe,p.subscribe).pipe(u(([e,t])=>e+t)),S=l(R.subscribe,W.subscribe).pipe(u(([e,t])=>e.getOffsets(t))),N=o([]);l(R.subscribe,y.subscribe,m.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(N.next),l(R.subscribe,S.subscribe,s.subscribe).pipe(c(e=>!e[1].empty()&&!e[0].empty()),d(N.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(N.next);const O=N.pipe(u(e=>e.reduce((e,t)=>e+t.size,0))),j=N.pipe(u(e=>e.length&&e[e.length-1].index+1)),L=l(n.subscribe,s.subscribe,O.subscribe,i.subscribe,p.subscribe,j.subscribe,m.subscribe,R.subscribe).pipe(f((e=>(t,[r,n,i,s,o,l,u,a])=>{const h=t.length;if(0===u)return 0===h?t:[];const c=M(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),[])),P=L.pipe(u(e=>e.length?e[e.length-1].index:0),f((e,t)=>Math.max(e,t),0)),A=l(L.subscribe,s.subscribe,O.subscribe).pipe(u(([e,t,r])=>M(e)-t-r));return s.pipe(h(1),a(!0)).subscribe(b.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(b.next),{groupCounts:E(v),itemHeights:E(g),footerHeight:E(p),listHeight:E(i),viewportHeight:E(n),scrollTop:E(s),topItemCount:E(y),totalCount:E(m),list:I(L),topList:I(N),listOffset:I(A),totalHeight:I(V),endReached:I(P),isScrolling:I(b),stickyItems:I(W)}},W=(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 R(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"},T=({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:{...H,...r},tabIndex:0},e)},V=({list:e,transform:r="",render:s})=>{const{stickyItems:o}=t.useContext(i),l=R(e,[]),u=R(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))))},S=()=>{const e=R(t.useContext(i).totalHeight,0);return n.createElement("div",{style:{height:`${e}px`,position:"absolute",top:0}}," ")},N=({footer:e})=>{const r=W(t.useContext(i).footerHeight);return n.createElement("footer",{ref:r},e())},O={top:0,position:"sticky",height:"100%",overflow:"hidden",WebkitBackfaceVisibility:"hidden"},j=({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=R(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=W(u,()=>{},e=>{o||p(e.children)}),m=W(a,e=>{""===e.style.position&&(e.style.position="-webkit-sticky")}),v=`translateY(${d}px)`,y=`translateY(${-d}px)`;return n.createElement(T,{style:e},n.createElement("div",{style:O,ref:m},n.createElement("div",{style:{transform:v}},n.createElement("div",{ref:g},n.createElement(V,{list:f,transform:y,render:s}),n.createElement(V,{list:c,render:s}),r&&n.createElement(N,{footer:r})))),n.createElement(S,null))},L=({contextValue:e,style:t,item:r,footer:s,itemHeight:o})=>n.createElement(i.Provider,{value:e},n.createElement(j,{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=C(e)}static getDerivedStateFromProps(e,t){return t.endReached(e.endReached),t.isScrolling(e.scrollingStateChange),t.groupCounts(e.groupCounts),null}render(){return n.createElement(L,{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=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 n.createElement(L,{contextValue:this.state,style:this.props.style,item:this.itemRenderer,footer:this.props.footer,itemHeight:this.props.itemHeight})}},e.VirtuosoPresentation=L}); | ||
!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}); | ||
//# sourceMappingURL=react-virtuoso.umd.production.js.map |
{ | ||
"name": "react-virtuoso", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"homepage": "https://virtuoso.dev", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
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
506001
28
2933
1