@tanstack/react-virtual
Advanced tools
Comparing version 3.0.0-beta.28 to 3.0.0-beta.29
@@ -294,6 +294,6 @@ /** | ||
this._didMount = () => { | ||
const ro = this.getResizeObserver(); | ||
Object.values(this.measureElementCache).forEach(node => ro == null ? void 0 : ro.observe(node)); | ||
return () => { | ||
var _this$getResizeObserv; | ||
(_this$getResizeObserv = this.getResizeObserver()) == null ? void 0 : _this$getResizeObserv.disconnect(); | ||
this.measureElementCache = {}; | ||
ro == null ? void 0 : ro.disconnect(); | ||
this.cleanup(); | ||
@@ -300,0 +300,0 @@ }; |
@@ -31,3 +31,3 @@ /** | ||
* @license MIT | ||
*/const o=e=>e,l=e=>{const t=Math.max(e.startIndex-e.overscan,0),s=Math.min(e.endIndex+e.overscan,e.count-1),n=[];for(let e=t;e<=s;e++)n.push(e);return n},r=(e,t)=>{const s=new ResizeObserver((e=>{var s,n;t({width:null==(s=e[0])?void 0:s.contentRect.width,height:null==(n=e[0])?void 0:n.contentRect.height})}));if(e.scrollElement)return t(e.scrollElement.getBoundingClientRect()),s.observe(e.scrollElement),()=>{s.unobserve(e.scrollElement)}},a=(e,t)=>{const s=((e,t)=>{let s={height:-1,width:-1};return n=>{(e.options.horizontal?n.width!==s.width:n.height!==s.height)&&t(n),s=n}})(e,t),n=()=>s({width:e.scrollElement.innerWidth,height:e.scrollElement.innerHeight});if(e.scrollElement)return n(),e.scrollElement.addEventListener("resize",n,{capture:!1,passive:!0}),()=>{e.scrollElement.removeEventListener("resize",n)}},c={element:["scrollLeft","scrollTop"],window:["scrollX","scrollY"]},h=e=>(t,s)=>{if(!t.scrollElement)return;const n=c[e][0],i=c[e][1];let o=t.scrollElement[n],l=t.scrollElement[i];const r=()=>{const e=t.scrollElement[t.options.horizontal?n:i];s(Math.max(0,e-t.options.scrollMargin))};r();const a=e=>{const s=e.currentTarget,a=s[n],c=s[i];(t.options.horizontal?o-a:l-c)&&r(),o=a,l=c};return t.scrollElement.addEventListener("scroll",a,{capture:!1,passive:!0}),()=>{t.scrollElement.removeEventListener("scroll",a)}},u=h("element"),d=h("window"),m=(e,t)=>Math.round(e.getBoundingClientRect()[t.options.horizontal?"width":"height"]),f=(e,t,s)=>{var n;let{adjustments:i,behavior:o,sync:l}=t;const r=(l?e:e+s.options.scrollMargin)+(i??0);null==(n=s.scrollElement)||null==n.scrollTo||n.scrollTo({[s.options.horizontal?"left":"top"]:r,behavior:o})},g=(e,t,s)=>{var n;let{adjustments:i,behavior:o,sync:l}=t;const r=(l?e:e+s.options.scrollMargin)+(i??0);null==(n=s.scrollElement)||null==n.scrollTo||n.scrollTo({[s.options.horizontal?"left":"top"]:r,behavior:o})};class p{constructor(e){var t=this;this.unsubs=[],this.scrollElement=null,this.isScrolling=!1,this.isScrollingTimeoutId=null,this.measurementsCache=[],this.itemMeasurementsCache={},this.pendingMeasuredCacheIndexes=[],this.scrollAdjustments=0,this.measureElementCache={},this.pendingScrollToIndexCallback=null,this.getResizeObserver=(()=>{let e=null;return()=>e||("undefined"!=typeof ResizeObserver?e=new ResizeObserver((e=>{e.forEach((e=>{this._measureElement(e.target,!1)}))})):null)})(),this.range={startIndex:0,endIndex:0},this.setOptions=e=>{Object.entries(e).forEach((t=>{let[s,n]=t;void 0===n&&delete e[s]})),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:o,rangeExtractor:l,onChange:()=>{},measureElement:m,initialRect:{width:0,height:0},scrollMargin:0,scrollingDelay:150,indexAttribute:"data-index",...e}},this.notify=()=>{var e,t;null==(e=(t=this.options).onChange)||e.call(t,this)},this.cleanup=()=>{this.unsubs.filter(Boolean).forEach((e=>e())),this.unsubs=[],this.scrollElement=null},this._didMount=()=>()=>{var e;null==(e=this.getResizeObserver())||e.disconnect(),this.measureElementCache={},this.cleanup()},this._willUpdate=()=>{var e;null==(e=this.pendingScrollToIndexCallback)||e.call(this);const t=this.options.getScrollElement();this.scrollElement!==t?(this.cleanup(),this.scrollElement=t,this._scrollToOffset(this.scrollOffset,{adjustments:void 0,behavior:void 0,sync:!0}),this.unsubs.push(this.options.observeElementRect(this,(e=>{this.scrollRect=e,this.calculateRange()}))),this.unsubs.push(this.options.observeElementOffset(this,(e=>{null!==this.isScrollingTimeoutId&&(clearTimeout(this.isScrollingTimeoutId),this.isScrollingTimeoutId=null),this.scrollOffset!==e?(this.scrollOffset=e,this.isScrolling=!0,this.scrollAdjustments=0,this.isScrollingTimeoutId=setTimeout((()=>{this.isScrollingTimeoutId=null,this.isScrolling=!1,this.notify()}),this.options.scrollingDelay)):(this.isScrolling=!1,this.scrollAdjustments=0),this.calculateRange()})))):this.isScrolling||this.calculateRange()},this.getSize=()=>this.scrollRect[this.options.horizontal?"width":"height"],this.getMeasurements=i((()=>[this.options.count,this.options.paddingStart,this.options.getItemKey,this.itemMeasurementsCache]),((e,t,s,n)=>{const i=this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[];const o=this.measurementsCache.slice(0,i);for(let l=i;l<e;l++){const e=s(l),i=n[e],r=o[l-1]?o[l-1].end:t,a="number"==typeof i?i:this.options.estimateSize(l),c=r+a;o[l]={index:l,start:r,size:a,end:c,key:e}}return this.measurementsCache=o,o}),{key:!1,debug:()=>this.options.debug}),this.calculateRange=i((()=>[this.getMeasurements(),this.getSize(),this.scrollOffset]),((e,t,s)=>{const n=function(e){let{measurements:t,outerSize:s,scrollOffset:n}=e;const i=t.length-1,o=((e,t,s,n)=>{for(;e<=t;){const i=(e+t)/2|0,o=s(i);if(o<n)e=i+1;else{if(!(o>n))return i;t=i-1}}return e>0?e-1:0})(0,i,(e=>t[e].start),n);let l=o;for(;l<i&&t[l].end<n+s;)l++;return{startIndex:o,endIndex:l}}({measurements:e,outerSize:t,scrollOffset:s});return n.startIndex===this.range.startIndex&&n.endIndex===this.range.endIndex||(this.range=n,this.notify()),this.range}),{key:!1,debug:()=>this.options.debug}),this.getIndexes=i((()=>[this.options.rangeExtractor,this.range,this.options.overscan,this.options.count]),((e,t,s,n)=>e({...t,overscan:s,count:n})),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=e=>{const t=this.options.indexAttribute,s=e.getAttribute(t);return s?parseInt(s,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this._measureElement=(e,t)=>{const s=this.indexFromElement(e),n=this.measurementsCache[s];if(!n)return;const i=this.measureElementCache[n.key],o=this.getResizeObserver();if(!e.isConnected)return void(i&&(null==o||o.unobserve(i),delete this.measureElementCache[n.key]));i&&i===e||(i&&(null==o||o.unobserve(i)),this.measureElementCache[n.key]=e,null==o||o.observe(e));const l=this.options.measureElement(e,this),r=l-(this.itemMeasurementsCache[n.key]??n.size);0!==r&&(n.start<this.scrollOffset&&this.isScrolling&&this._scrollToOffset(this.scrollOffset,{adjustments:this.scrollAdjustments+=r,behavior:void 0,sync:!1}),this.pendingMeasuredCacheIndexes.push(s),this.itemMeasurementsCache={...this.itemMeasurementsCache,[n.key]:l},this.notify())},this.measureElement=e=>{e&&this._measureElement(e,!0)},this.getVirtualItems=i((()=>[this.getIndexes(),this.getMeasurements()]),((e,t)=>{const s=[];for(let n=0,i=e.length;n<i;n++){const i=t[e[n]];s.push(i)}return s}),{key:!1,debug:()=>this.options.debug}),this.scrollToOffset=function(e,s){let{align:n="start",behavior:i}=void 0===s?{}:s;const o=t.scrollOffset,l=t.getSize();"auto"===n&&(n=e<=o?"start":e>=o+l?"end":"start");const r={adjustments:void 0,behavior:i,sync:!1};"start"===n?t._scrollToOffset(e,r):"end"===n?t._scrollToOffset(e-l,r):"center"===n&&t._scrollToOffset(e-l/2,r)},this.scrollToIndex=function(e,s){let{align:n="auto",...i}=void 0===s?{}:s;t.pendingScrollToIndexCallback=null;const o=t.getMeasurements(),l=t.scrollOffset,r=t.getSize(),{count:a}=t.options,c=o[Math.max(0,Math.min(e,a-1))];if(!c)return;if("auto"===n)if(c.end>=l+r-t.options.scrollPaddingEnd)n="end";else{if(!(c.start<=l+t.options.scrollPaddingStart))return;n="start"}const h="end"===n?c.end+t.options.scrollPaddingEnd:c.start-t.options.scrollPaddingStart;t.scrollToOffset(h,{align:n,...i});if(Object.keys(t.measureElementCache).length>0){const s=()=>"number"==typeof t.itemMeasurementsCache[t.options.getItemKey(e)];s()||(t.pendingScrollToIndexCallback=()=>{s()&&(t.pendingScrollToIndexCallback=null,t.scrollToIndex(e,{align:n,...i}))})}},this.getTotalSize=()=>{var e;return((null==(e=this.getMeasurements()[this.options.count-1])?void 0:e.end)||this.options.paddingStart)+this.options.paddingEnd},this._scrollToOffset=(e,t)=>{let{adjustments:s,behavior:n,sync:i}=t;this.options.scrollToFn(e,{behavior:n,sync:i,adjustments:s},this)},this.measure=()=>{this.itemMeasurementsCache={},this.notify()},this.setOptions(e),this.scrollRect=this.options.initialRect,this.scrollOffset=this.options.initialOffset,this.calculateRange()}}const b="undefined"!=typeof window?n.useLayoutEffect:n.useEffect;function v(e){const t=n.useReducer((()=>({})),{})[1],s={...e,onChange:s=>{t(),null==e.onChange||e.onChange(s)}},[i]=n.useState((()=>new p(s)));return i.setOptions(s),n.useEffect((()=>i._didMount()),[]),b((()=>i._willUpdate())),i}e.Virtualizer=p,e.defaultKeyExtractor=o,e.defaultRangeExtractor=l,e.elementScroll=g,e.measureElement=m,e.memo=i,e.observeElementOffset=u,e.observeElementRect=r,e.observeWindowOffset=d,e.observeWindowRect=a,e.useVirtualizer=function(e){return v({observeElementRect:r,observeElementOffset:u,scrollToFn:g,...e})},e.useWindowVirtualizer=function(e){return v({getScrollElement:()=>"undefined"!=typeof window?window:null,observeElementRect:a,observeElementOffset:d,scrollToFn:f,...e})},e.windowScroll=f,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
*/const o=e=>e,l=e=>{const t=Math.max(e.startIndex-e.overscan,0),s=Math.min(e.endIndex+e.overscan,e.count-1),n=[];for(let e=t;e<=s;e++)n.push(e);return n},r=(e,t)=>{const s=new ResizeObserver((e=>{var s,n;t({width:null==(s=e[0])?void 0:s.contentRect.width,height:null==(n=e[0])?void 0:n.contentRect.height})}));if(e.scrollElement)return t(e.scrollElement.getBoundingClientRect()),s.observe(e.scrollElement),()=>{s.unobserve(e.scrollElement)}},a=(e,t)=>{const s=((e,t)=>{let s={height:-1,width:-1};return n=>{(e.options.horizontal?n.width!==s.width:n.height!==s.height)&&t(n),s=n}})(e,t),n=()=>s({width:e.scrollElement.innerWidth,height:e.scrollElement.innerHeight});if(e.scrollElement)return n(),e.scrollElement.addEventListener("resize",n,{capture:!1,passive:!0}),()=>{e.scrollElement.removeEventListener("resize",n)}},c={element:["scrollLeft","scrollTop"],window:["scrollX","scrollY"]},h=e=>(t,s)=>{if(!t.scrollElement)return;const n=c[e][0],i=c[e][1];let o=t.scrollElement[n],l=t.scrollElement[i];const r=()=>{const e=t.scrollElement[t.options.horizontal?n:i];s(Math.max(0,e-t.options.scrollMargin))};r();const a=e=>{const s=e.currentTarget,a=s[n],c=s[i];(t.options.horizontal?o-a:l-c)&&r(),o=a,l=c};return t.scrollElement.addEventListener("scroll",a,{capture:!1,passive:!0}),()=>{t.scrollElement.removeEventListener("scroll",a)}},u=h("element"),d=h("window"),m=(e,t)=>Math.round(e.getBoundingClientRect()[t.options.horizontal?"width":"height"]),f=(e,t,s)=>{var n;let{adjustments:i,behavior:o,sync:l}=t;const r=(l?e:e+s.options.scrollMargin)+(i??0);null==(n=s.scrollElement)||null==n.scrollTo||n.scrollTo({[s.options.horizontal?"left":"top"]:r,behavior:o})},g=(e,t,s)=>{var n;let{adjustments:i,behavior:o,sync:l}=t;const r=(l?e:e+s.options.scrollMargin)+(i??0);null==(n=s.scrollElement)||null==n.scrollTo||n.scrollTo({[s.options.horizontal?"left":"top"]:r,behavior:o})};class p{constructor(e){var t=this;this.unsubs=[],this.scrollElement=null,this.isScrolling=!1,this.isScrollingTimeoutId=null,this.measurementsCache=[],this.itemMeasurementsCache={},this.pendingMeasuredCacheIndexes=[],this.scrollAdjustments=0,this.measureElementCache={},this.pendingScrollToIndexCallback=null,this.getResizeObserver=(()=>{let e=null;return()=>e||("undefined"!=typeof ResizeObserver?e=new ResizeObserver((e=>{e.forEach((e=>{this._measureElement(e.target,!1)}))})):null)})(),this.range={startIndex:0,endIndex:0},this.setOptions=e=>{Object.entries(e).forEach((t=>{let[s,n]=t;void 0===n&&delete e[s]})),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:o,rangeExtractor:l,onChange:()=>{},measureElement:m,initialRect:{width:0,height:0},scrollMargin:0,scrollingDelay:150,indexAttribute:"data-index",...e}},this.notify=()=>{var e,t;null==(e=(t=this.options).onChange)||e.call(t,this)},this.cleanup=()=>{this.unsubs.filter(Boolean).forEach((e=>e())),this.unsubs=[],this.scrollElement=null},this._didMount=()=>{const e=this.getResizeObserver();return Object.values(this.measureElementCache).forEach((t=>null==e?void 0:e.observe(t))),()=>{null==e||e.disconnect(),this.cleanup()}},this._willUpdate=()=>{var e;null==(e=this.pendingScrollToIndexCallback)||e.call(this);const t=this.options.getScrollElement();this.scrollElement!==t?(this.cleanup(),this.scrollElement=t,this._scrollToOffset(this.scrollOffset,{adjustments:void 0,behavior:void 0,sync:!0}),this.unsubs.push(this.options.observeElementRect(this,(e=>{this.scrollRect=e,this.calculateRange()}))),this.unsubs.push(this.options.observeElementOffset(this,(e=>{null!==this.isScrollingTimeoutId&&(clearTimeout(this.isScrollingTimeoutId),this.isScrollingTimeoutId=null),this.scrollOffset!==e?(this.scrollOffset=e,this.isScrolling=!0,this.scrollAdjustments=0,this.isScrollingTimeoutId=setTimeout((()=>{this.isScrollingTimeoutId=null,this.isScrolling=!1,this.notify()}),this.options.scrollingDelay)):(this.isScrolling=!1,this.scrollAdjustments=0),this.calculateRange()})))):this.isScrolling||this.calculateRange()},this.getSize=()=>this.scrollRect[this.options.horizontal?"width":"height"],this.getMeasurements=i((()=>[this.options.count,this.options.paddingStart,this.options.getItemKey,this.itemMeasurementsCache]),((e,t,s,n)=>{const i=this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[];const o=this.measurementsCache.slice(0,i);for(let l=i;l<e;l++){const e=s(l),i=n[e],r=o[l-1]?o[l-1].end:t,a="number"==typeof i?i:this.options.estimateSize(l),c=r+a;o[l]={index:l,start:r,size:a,end:c,key:e}}return this.measurementsCache=o,o}),{key:!1,debug:()=>this.options.debug}),this.calculateRange=i((()=>[this.getMeasurements(),this.getSize(),this.scrollOffset]),((e,t,s)=>{const n=function(e){let{measurements:t,outerSize:s,scrollOffset:n}=e;const i=t.length-1,o=((e,t,s,n)=>{for(;e<=t;){const i=(e+t)/2|0,o=s(i);if(o<n)e=i+1;else{if(!(o>n))return i;t=i-1}}return e>0?e-1:0})(0,i,(e=>t[e].start),n);let l=o;for(;l<i&&t[l].end<n+s;)l++;return{startIndex:o,endIndex:l}}({measurements:e,outerSize:t,scrollOffset:s});return n.startIndex===this.range.startIndex&&n.endIndex===this.range.endIndex||(this.range=n,this.notify()),this.range}),{key:!1,debug:()=>this.options.debug}),this.getIndexes=i((()=>[this.options.rangeExtractor,this.range,this.options.overscan,this.options.count]),((e,t,s,n)=>e({...t,overscan:s,count:n})),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=e=>{const t=this.options.indexAttribute,s=e.getAttribute(t);return s?parseInt(s,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this._measureElement=(e,t)=>{const s=this.indexFromElement(e),n=this.measurementsCache[s];if(!n)return;const i=this.measureElementCache[n.key],o=this.getResizeObserver();if(!e.isConnected)return void(i&&(null==o||o.unobserve(i),delete this.measureElementCache[n.key]));i&&i===e||(i&&(null==o||o.unobserve(i)),this.measureElementCache[n.key]=e,null==o||o.observe(e));const l=this.options.measureElement(e,this),r=l-(this.itemMeasurementsCache[n.key]??n.size);0!==r&&(n.start<this.scrollOffset&&this.isScrolling&&this._scrollToOffset(this.scrollOffset,{adjustments:this.scrollAdjustments+=r,behavior:void 0,sync:!1}),this.pendingMeasuredCacheIndexes.push(s),this.itemMeasurementsCache={...this.itemMeasurementsCache,[n.key]:l},this.notify())},this.measureElement=e=>{e&&this._measureElement(e,!0)},this.getVirtualItems=i((()=>[this.getIndexes(),this.getMeasurements()]),((e,t)=>{const s=[];for(let n=0,i=e.length;n<i;n++){const i=t[e[n]];s.push(i)}return s}),{key:!1,debug:()=>this.options.debug}),this.scrollToOffset=function(e,s){let{align:n="start",behavior:i}=void 0===s?{}:s;const o=t.scrollOffset,l=t.getSize();"auto"===n&&(n=e<=o?"start":e>=o+l?"end":"start");const r={adjustments:void 0,behavior:i,sync:!1};"start"===n?t._scrollToOffset(e,r):"end"===n?t._scrollToOffset(e-l,r):"center"===n&&t._scrollToOffset(e-l/2,r)},this.scrollToIndex=function(e,s){let{align:n="auto",...i}=void 0===s?{}:s;t.pendingScrollToIndexCallback=null;const o=t.getMeasurements(),l=t.scrollOffset,r=t.getSize(),{count:a}=t.options,c=o[Math.max(0,Math.min(e,a-1))];if(!c)return;if("auto"===n)if(c.end>=l+r-t.options.scrollPaddingEnd)n="end";else{if(!(c.start<=l+t.options.scrollPaddingStart))return;n="start"}const h="end"===n?c.end+t.options.scrollPaddingEnd:c.start-t.options.scrollPaddingStart;t.scrollToOffset(h,{align:n,...i});if(Object.keys(t.measureElementCache).length>0){const s=()=>"number"==typeof t.itemMeasurementsCache[t.options.getItemKey(e)];s()||(t.pendingScrollToIndexCallback=()=>{s()&&(t.pendingScrollToIndexCallback=null,t.scrollToIndex(e,{align:n,...i}))})}},this.getTotalSize=()=>{var e;return((null==(e=this.getMeasurements()[this.options.count-1])?void 0:e.end)||this.options.paddingStart)+this.options.paddingEnd},this._scrollToOffset=(e,t)=>{let{adjustments:s,behavior:n,sync:i}=t;this.options.scrollToFn(e,{behavior:n,sync:i,adjustments:s},this)},this.measure=()=>{this.itemMeasurementsCache={},this.notify()},this.setOptions(e),this.scrollRect=this.options.initialRect,this.scrollOffset=this.options.initialOffset,this.calculateRange()}}const b="undefined"!=typeof window?n.useLayoutEffect:n.useEffect;function v(e){const t=n.useReducer((()=>({})),{})[1],s={...e,onChange:s=>{t(),null==e.onChange||e.onChange(s)}},[i]=n.useState((()=>new p(s)));return i.setOptions(s),n.useEffect((()=>i._didMount()),[]),b((()=>i._willUpdate())),i}e.Virtualizer=p,e.defaultKeyExtractor=o,e.defaultRangeExtractor=l,e.elementScroll=g,e.measureElement=m,e.memo=i,e.observeElementOffset=u,e.observeElementRect=r,e.observeWindowOffset=d,e.observeWindowRect=a,e.useVirtualizer=function(e){return v({observeElementRect:r,observeElementOffset:u,scrollToFn:g,...e})},e.useWindowVirtualizer=function(e){return v({getScrollElement:()=>"undefined"!=typeof window?window:null,observeElementRect:a,observeElementOffset:d,scrollToFn:f,...e})},e.windowScroll=f,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.production.js.map |
{ | ||
"name": "@tanstack/react-virtual", | ||
"author": "Tanner Linsley", | ||
"version": "3.0.0-beta.28", | ||
"version": "3.0.0-beta.29", | ||
"description": "Headless UI for virtualizing scrollable elements in React", | ||
@@ -53,3 +53,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"@tanstack/virtual-core": "3.0.0-beta.28" | ||
"@tanstack/virtual-core": "3.0.0-beta.29" | ||
}, | ||
@@ -56,0 +56,0 @@ "peerDependencies": { |
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
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
136255
+ Added@tanstack/virtual-core@3.0.0-beta.29(transitive)
- Removed@tanstack/virtual-core@3.0.0-beta.28(transitive)