@tanstack/react-virtual
Advanced tools
Comparing version 3.0.0-beta.21 to 3.0.0-beta.22
@@ -225,7 +225,20 @@ /** | ||
this.measureElementCache = {}; | ||
this.ro = new ResizeObserver(entries => { | ||
entries.forEach(entry => { | ||
this._measureElement(entry.target, false); | ||
}); | ||
}); | ||
this.getResizeObserver = (() => { | ||
let _ro = null; | ||
return () => { | ||
if (_ro) { | ||
return _ro; | ||
} else if (typeof ResizeObserver !== 'undefined') { | ||
return _ro = new ResizeObserver(entries => { | ||
entries.forEach(entry => { | ||
this._measureElement(entry.target, false); | ||
}); | ||
}); | ||
} else { | ||
return null; | ||
} | ||
}; | ||
})(); | ||
this.range = { | ||
@@ -280,3 +293,5 @@ startIndex: 0, | ||
return () => { | ||
this.ro.disconnect(); | ||
var _this$getResizeObserv; | ||
(_this$getResizeObserv = this.getResizeObserver()) == null ? void 0 : _this$getResizeObserv.disconnect(); | ||
this.measureElementCache = {}; | ||
@@ -410,9 +425,9 @@ this.cleanup(); | ||
const key = String(item.key); | ||
const prevNode = this.measureElementCache[key]; | ||
const prevNode = this.measureElementCache[item.key]; | ||
const ro = this.getResizeObserver(); | ||
if (!node.isConnected) { | ||
if (prevNode) { | ||
this.ro.unobserve(prevNode); | ||
delete this.measureElementCache[key]; | ||
ro == null ? void 0 : ro.unobserve(prevNode); | ||
delete this.measureElementCache[item.key]; | ||
} | ||
@@ -425,7 +440,7 @@ | ||
if (prevNode) { | ||
this.ro.unobserve(prevNode); | ||
ro == null ? void 0 : ro.unobserve(prevNode); | ||
} | ||
this.measureElementCache[key] = node; | ||
this.ro.observe(node); | ||
this.measureElementCache[item.key] = node; | ||
ro == null ? void 0 : ro.observe(node); | ||
} | ||
@@ -432,0 +447,0 @@ |
@@ -223,7 +223,20 @@ /** | ||
this.measureElementCache = {}; | ||
this.ro = new ResizeObserver(entries => { | ||
entries.forEach(entry => { | ||
this._measureElement(entry.target, false); | ||
}); | ||
}); | ||
this.getResizeObserver = (() => { | ||
let _ro = null; | ||
return () => { | ||
if (_ro) { | ||
return _ro; | ||
} else if (typeof ResizeObserver !== 'undefined') { | ||
return _ro = new ResizeObserver(entries => { | ||
entries.forEach(entry => { | ||
this._measureElement(entry.target, false); | ||
}); | ||
}); | ||
} else { | ||
return null; | ||
} | ||
}; | ||
})(); | ||
this.range = { | ||
@@ -278,3 +291,5 @@ startIndex: 0, | ||
return () => { | ||
this.ro.disconnect(); | ||
var _this$getResizeObserv; | ||
(_this$getResizeObserv = this.getResizeObserver()) == null ? void 0 : _this$getResizeObserv.disconnect(); | ||
this.measureElementCache = {}; | ||
@@ -408,9 +423,9 @@ this.cleanup(); | ||
const key = String(item.key); | ||
const prevNode = this.measureElementCache[key]; | ||
const prevNode = this.measureElementCache[item.key]; | ||
const ro = this.getResizeObserver(); | ||
if (!node.isConnected) { | ||
if (prevNode) { | ||
this.ro.unobserve(prevNode); | ||
delete this.measureElementCache[key]; | ||
ro == null ? void 0 : ro.unobserve(prevNode); | ||
delete this.measureElementCache[item.key]; | ||
} | ||
@@ -423,7 +438,7 @@ | ||
if (prevNode) { | ||
this.ro.unobserve(prevNode); | ||
ro == null ? void 0 : ro.unobserve(prevNode); | ||
} | ||
this.measureElementCache[key] = node; | ||
this.ro.observe(node); | ||
this.measureElementCache[item.key] = node; | ||
ro == null ? void 0 : ro.observe(node); | ||
} | ||
@@ -430,0 +445,0 @@ |
@@ -14,7 +14,7 @@ { | ||
"name": "virtual-core/build/esm/index.js", | ||
"uid": "de4e-14" | ||
"uid": "07ec-14" | ||
}, | ||
{ | ||
"name": "react-virtual/src/index.tsx", | ||
"uid": "de4e-16" | ||
"uid": "07ec-16" | ||
} | ||
@@ -29,20 +29,20 @@ ] | ||
"nodeParts": { | ||
"de4e-14": { | ||
"renderedLength": 18637, | ||
"gzipLength": 4322, | ||
"07ec-14": { | ||
"renderedLength": 19140, | ||
"gzipLength": 4400, | ||
"brotliLength": 0, | ||
"mainUid": "de4e-13" | ||
"mainUid": "07ec-13" | ||
}, | ||
"de4e-16": { | ||
"07ec-16": { | ||
"renderedLength": 1281, | ||
"gzipLength": 441, | ||
"brotliLength": 0, | ||
"mainUid": "de4e-15" | ||
"mainUid": "07ec-15" | ||
} | ||
}, | ||
"nodeMetas": { | ||
"de4e-13": { | ||
"07ec-13": { | ||
"id": "/packages/virtual-core/build/esm/index.js", | ||
"moduleParts": { | ||
"index.production.js": "de4e-14" | ||
"index.production.js": "07ec-14" | ||
}, | ||
@@ -52,17 +52,17 @@ "imported": [], | ||
{ | ||
"uid": "de4e-15" | ||
"uid": "07ec-15" | ||
} | ||
] | ||
}, | ||
"de4e-15": { | ||
"07ec-15": { | ||
"id": "/packages/react-virtual/src/index.tsx", | ||
"moduleParts": { | ||
"index.production.js": "de4e-16" | ||
"index.production.js": "07ec-16" | ||
}, | ||
"imported": [ | ||
{ | ||
"uid": "de4e-17" | ||
"uid": "07ec-17" | ||
}, | ||
{ | ||
"uid": "de4e-13" | ||
"uid": "07ec-13" | ||
} | ||
@@ -73,3 +73,3 @@ ], | ||
}, | ||
"de4e-17": { | ||
"07ec-17": { | ||
"id": "react", | ||
@@ -80,3 +80,3 @@ "moduleParts": {}, | ||
{ | ||
"uid": "de4e-15" | ||
"uid": "07ec-15" | ||
} | ||
@@ -83,0 +83,0 @@ ], |
@@ -247,7 +247,20 @@ /** | ||
this.measureElementCache = {}; | ||
this.ro = new ResizeObserver(entries => { | ||
entries.forEach(entry => { | ||
this._measureElement(entry.target, false); | ||
}); | ||
}); | ||
this.getResizeObserver = (() => { | ||
let _ro = null; | ||
return () => { | ||
if (_ro) { | ||
return _ro; | ||
} else if (typeof ResizeObserver !== 'undefined') { | ||
return _ro = new ResizeObserver(entries => { | ||
entries.forEach(entry => { | ||
this._measureElement(entry.target, false); | ||
}); | ||
}); | ||
} else { | ||
return null; | ||
} | ||
}; | ||
})(); | ||
this.range = { | ||
@@ -302,3 +315,5 @@ startIndex: 0, | ||
return () => { | ||
this.ro.disconnect(); | ||
var _this$getResizeObserv; | ||
(_this$getResizeObserv = this.getResizeObserver()) == null ? void 0 : _this$getResizeObserv.disconnect(); | ||
this.measureElementCache = {}; | ||
@@ -432,9 +447,9 @@ this.cleanup(); | ||
const key = String(item.key); | ||
const prevNode = this.measureElementCache[key]; | ||
const prevNode = this.measureElementCache[item.key]; | ||
const ro = this.getResizeObserver(); | ||
if (!node.isConnected) { | ||
if (prevNode) { | ||
this.ro.unobserve(prevNode); | ||
delete this.measureElementCache[key]; | ||
ro == null ? void 0 : ro.unobserve(prevNode); | ||
delete this.measureElementCache[item.key]; | ||
} | ||
@@ -447,7 +462,7 @@ | ||
if (prevNode) { | ||
this.ro.unobserve(prevNode); | ||
ro == null ? void 0 : ro.unobserve(prevNode); | ||
} | ||
this.measureElementCache[key] = node; | ||
this.ro.observe(node); | ||
this.measureElementCache[item.key] = node; | ||
ro == null ? void 0 : ro.observe(node); | ||
} | ||
@@ -454,0 +469,0 @@ |
@@ -21,3 +21,3 @@ /** | ||
* @license MIT | ||
*/function o(e,t,s){let n,o=[];return()=>{let i;s.key&&null!=s.debug&&s.debug()&&(i=Date.now());const l=e();if(!(l.length!==o.length||l.some(((e,t)=>o[t]!==e))))return n;let r;if(o=l,s.key&&null!=s.debug&&s.debug()&&(r=Date.now()),n=t(...l),null==s||null==s.onChange||s.onChange(n),s.key&&null!=s.debug&&s.debug()){const e=Math.round(100*(Date.now()-i))/100,t=Math.round(100*(Date.now()-r))/100,n=t/16,o=(e,t)=>{for(e=String(e);e.length<t;)e=" "+e;return e};console.info("%c⏱ "+o(t,5)+" /"+o(e,5)+" ms","\n font-size: .6rem;\n font-weight: bold;\n color: hsl("+Math.max(0,Math.min(120-120*n,120))+"deg 100% 31%);",null==s?void 0:s.key)}return n}}const i=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)}},c=(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)}},h={element:["scrollLeft","scrollTop"],window:["scrollX","scrollY"]},a=e=>(t,s)=>{if(!t.scrollElement)return;const n=h[e][0],o=h[e][1];let i=t.scrollElement[n],l=t.scrollElement[o];const r=()=>{const e=t.scrollElement[t.options.horizontal?n:o];s(Math.max(0,e-t.options.scrollMargin))};r();const c=e=>{const s=e.currentTarget,c=s[n],h=s[o];(t.options.horizontal?i-c:l-h)&&r(),i=c,l=h};return t.scrollElement.addEventListener("scroll",c,{capture:!1,passive:!0}),()=>{t.scrollElement.removeEventListener("scroll",c)}},u=a("element"),d=a("window"),m=(e,t)=>Math.round(e.getBoundingClientRect()[t.options.horizontal?"width":"height"]),f=(e,t,s)=>{var n;let{canSmooth:o,sync:i}=t;const l=i?e:e+s.options.scrollMargin;null==(n=s.scrollElement)||null==n.scrollTo||n.scrollTo({[s.options.horizontal?"left":"top"]:l,behavior:o?"smooth":void 0})},g=(e,t,s)=>{var n;let{canSmooth:o,sync:i}=t;const l=i?e:e+s.options.scrollMargin;null==(n=s.scrollElement)||null==n.scrollTo||n.scrollTo({[s.options.horizontal?"left":"top"]:l,behavior:o?"smooth":void 0})};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.scrollDelta=0,this.measureElementCache={},this.ro=new ResizeObserver((e=>{e.forEach((e=>{this._measureElement(e.target,!1)}))})),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:i,rangeExtractor:l,enableSmoothScroll:!0,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=()=>()=>{this.ro.disconnect(),this.measureElementCache={},this.cleanup()},this._willUpdate=()=>{const e=this.options.getScrollElement();this.scrollElement!==e?(this.cleanup(),this.scrollElement=e,this._scrollToOffset(this.scrollOffset,{canSmooth:!1,sync:!0,requested:!1}),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.scrollDelta=0,this.isScrollingTimeoutId=setTimeout((()=>{this.isScrollingTimeoutId=null,this.isScrolling=!1,this.notify()}),this.options.scrollingDelay)):(this.isScrolling=!1,this.scrollDelta=0),this.calculateRange()})))):this.isScrolling||this.calculateRange()},this.getSize=()=>this.scrollRect[this.options.horizontal?"width":"height"],this.getMeasurements=o((()=>[this.options.count,this.options.paddingStart,this.options.getItemKey,this.itemMeasurementsCache]),((e,t,s,n)=>{const o=this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[];const i=this.measurementsCache.slice(0,o);for(let l=o;l<e;l++){const e=s(l),o=n[e],r=i[l-1]?i[l-1].end:t,c="number"==typeof o?o:this.options.estimateSize(l),h=r+c;i[l]={index:l,start:r,size:c,end:h,key:e}}return this.measurementsCache=i,i}),{key:!1,debug:()=>this.options.debug}),this.calculateRange=o((()=>[this.getMeasurements(),this.getSize(),this.scrollOffset]),((e,t,s)=>{const n=function(e){let{measurements:t,outerSize:s,scrollOffset:n}=e;const o=t.length-1,i=((e,t,s,n)=>{for(;e<=t;){const o=(e+t)/2|0,i=s(o);if(i<n)e=o+1;else{if(!(i>n))return o;t=o-1}}return e>0?e-1:0})(0,o,(e=>t[e].start),n);let l=i;for(;l<o&&t[l].end<n+s;)l++;return{startIndex:i,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=o((()=>[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)=>{var s;const n=this.indexFromElement(e),o=this.measurementsCache[n];if(!o)return;const i=String(o.key),l=this.measureElementCache[i];if(!e.isConnected)return void(l&&(this.ro.unobserve(l),delete this.measureElementCache[i]));l&&l===e||(l&&this.ro.unobserve(l),this.measureElementCache[i]=e,this.ro.observe(e));const r=this.options.measureElement(e,this),c=null!=(s=this.itemMeasurementsCache[o.key])?s:o.size;r!==c&&(o.start<this.scrollOffset&&void 0===this.destinationOffset&&(this.scrollDelta+=r-c,this._scrollToOffset(this.scrollOffset+this.scrollDelta,{canSmooth:!1,sync:!1,requested:!1})),this.pendingMeasuredCacheIndexes.push(n),this.itemMeasurementsCache={...this.itemMeasurementsCache,[o.key]:r},this.notify())},this.measureElement=e=>{e&&this._measureElement(e,!0)},this.getVirtualItems=o((()=>[this.getIndexes(),this.getMeasurements()]),((e,t)=>{const s=[];for(let n=0,o=e.length;n<o;n++){const o=t[e[n]];s.push(o)}return s}),{key:!1,debug:()=>this.options.debug}),this.scrollToOffset=function(e,s){let{align:n="start",smoothScroll:o=t.options.enableSmoothScroll}=void 0===s?{}:s;const i=t.scrollOffset,l=t.getSize();"auto"===n&&(n=e<=i?"start":e>=i+l?"end":"start");const r={canSmooth:o,sync:!1,requested:!0};"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",smoothScroll:o=t.options.enableSmoothScroll,...i}=void 0===s?{}:s;const l=t.getMeasurements(),r=t.scrollOffset,c=t.getSize(),{count:h}=t.options,a=l[Math.max(0,Math.min(e,h-1))];if(!a)return;if("auto"===n)if(a.end>=r+c-t.options.scrollPaddingEnd)n="end";else{if(!(a.start<=r+t.options.scrollPaddingStart))return;n="start"}const u="end"===n?a.end+t.options.scrollPaddingEnd:a.start-t.options.scrollPaddingStart;t.scrollToOffset(u,{align:n,smoothScroll:o,...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 s,{requested:n,canSmooth:o,sync:i}=t;clearTimeout(this.scrollCheckFrame),n&&(this.destinationOffset=e),this.options.scrollToFn(e,{canSmooth:o,sync:i},this);const l=()=>{let e=this.scrollOffset;this.scrollCheckFrame=s=setTimeout((()=>{this.scrollCheckFrame===s&&(this.scrollOffset!==e?(e=this.scrollOffset,l()):this.destinationOffset=void 0)}),100)};l()},this.measure=()=>{this.itemMeasurementsCache={},this.notify()},this.setOptions(e),this.scrollRect=this.options.initialRect,this.scrollOffset=this.options.initialOffset,this.calculateRange()}}const E="undefined"!=typeof window?n.useLayoutEffect:n.useEffect;function b(e){const t=n.useReducer((()=>({})),{})[1],s={...e,onChange:s=>{t(),null==e.onChange||e.onChange(s)}},[o]=n.useState((()=>new p(s)));return o.setOptions(s),n.useEffect((()=>o._didMount()),[]),E((()=>o._willUpdate())),o}e.Virtualizer=p,e.defaultKeyExtractor=i,e.defaultRangeExtractor=l,e.elementScroll=g,e.measureElement=m,e.memo=o,e.observeElementOffset=u,e.observeElementRect=r,e.observeWindowOffset=d,e.observeWindowRect=c,e.useVirtualizer=function(e){return b({observeElementRect:r,observeElementOffset:u,scrollToFn:g,...e})},e.useWindowVirtualizer=function(e){return b({getScrollElement:()=>"undefined"!=typeof window?window:null,observeElementRect:c,observeElementOffset:d,scrollToFn:f,...e})},e.windowScroll=f,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
*/function o(e,t,s){let n,o=[];return()=>{let i;s.key&&null!=s.debug&&s.debug()&&(i=Date.now());const l=e();if(!(l.length!==o.length||l.some(((e,t)=>o[t]!==e))))return n;let r;if(o=l,s.key&&null!=s.debug&&s.debug()&&(r=Date.now()),n=t(...l),null==s||null==s.onChange||s.onChange(n),s.key&&null!=s.debug&&s.debug()){const e=Math.round(100*(Date.now()-i))/100,t=Math.round(100*(Date.now()-r))/100,n=t/16,o=(e,t)=>{for(e=String(e);e.length<t;)e=" "+e;return e};console.info("%c⏱ "+o(t,5)+" /"+o(e,5)+" ms","\n font-size: .6rem;\n font-weight: bold;\n color: hsl("+Math.max(0,Math.min(120-120*n,120))+"deg 100% 31%);",null==s?void 0:s.key)}return n}}const i=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)}},c=(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)}},h={element:["scrollLeft","scrollTop"],window:["scrollX","scrollY"]},a=e=>(t,s)=>{if(!t.scrollElement)return;const n=h[e][0],o=h[e][1];let i=t.scrollElement[n],l=t.scrollElement[o];const r=()=>{const e=t.scrollElement[t.options.horizontal?n:o];s(Math.max(0,e-t.options.scrollMargin))};r();const c=e=>{const s=e.currentTarget,c=s[n],h=s[o];(t.options.horizontal?i-c:l-h)&&r(),i=c,l=h};return t.scrollElement.addEventListener("scroll",c,{capture:!1,passive:!0}),()=>{t.scrollElement.removeEventListener("scroll",c)}},u=a("element"),d=a("window"),m=(e,t)=>Math.round(e.getBoundingClientRect()[t.options.horizontal?"width":"height"]),f=(e,t,s)=>{var n;let{canSmooth:o,sync:i}=t;const l=i?e:e+s.options.scrollMargin;null==(n=s.scrollElement)||null==n.scrollTo||n.scrollTo({[s.options.horizontal?"left":"top"]:l,behavior:o?"smooth":void 0})},g=(e,t,s)=>{var n;let{canSmooth:o,sync:i}=t;const l=i?e:e+s.options.scrollMargin;null==(n=s.scrollElement)||null==n.scrollTo||n.scrollTo({[s.options.horizontal?"left":"top"]:l,behavior:o?"smooth":void 0})};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.scrollDelta=0,this.measureElementCache={},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:i,rangeExtractor:l,enableSmoothScroll:!0,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=()=>{const e=this.options.getScrollElement();this.scrollElement!==e?(this.cleanup(),this.scrollElement=e,this._scrollToOffset(this.scrollOffset,{canSmooth:!1,sync:!0,requested:!1}),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.scrollDelta=0,this.isScrollingTimeoutId=setTimeout((()=>{this.isScrollingTimeoutId=null,this.isScrolling=!1,this.notify()}),this.options.scrollingDelay)):(this.isScrolling=!1,this.scrollDelta=0),this.calculateRange()})))):this.isScrolling||this.calculateRange()},this.getSize=()=>this.scrollRect[this.options.horizontal?"width":"height"],this.getMeasurements=o((()=>[this.options.count,this.options.paddingStart,this.options.getItemKey,this.itemMeasurementsCache]),((e,t,s,n)=>{const o=this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[];const i=this.measurementsCache.slice(0,o);for(let l=o;l<e;l++){const e=s(l),o=n[e],r=i[l-1]?i[l-1].end:t,c="number"==typeof o?o:this.options.estimateSize(l),h=r+c;i[l]={index:l,start:r,size:c,end:h,key:e}}return this.measurementsCache=i,i}),{key:!1,debug:()=>this.options.debug}),this.calculateRange=o((()=>[this.getMeasurements(),this.getSize(),this.scrollOffset]),((e,t,s)=>{const n=function(e){let{measurements:t,outerSize:s,scrollOffset:n}=e;const o=t.length-1,i=((e,t,s,n)=>{for(;e<=t;){const o=(e+t)/2|0,i=s(o);if(i<n)e=o+1;else{if(!(i>n))return o;t=o-1}}return e>0?e-1:0})(0,o,(e=>t[e].start),n);let l=i;for(;l<o&&t[l].end<n+s;)l++;return{startIndex:i,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=o((()=>[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)=>{var s;const n=this.indexFromElement(e),o=this.measurementsCache[n];if(!o)return;const i=this.measureElementCache[o.key],l=this.getResizeObserver();if(!e.isConnected)return void(i&&(null==l||l.unobserve(i),delete this.measureElementCache[o.key]));i&&i===e||(i&&(null==l||l.unobserve(i)),this.measureElementCache[o.key]=e,null==l||l.observe(e));const r=this.options.measureElement(e,this),c=null!=(s=this.itemMeasurementsCache[o.key])?s:o.size;r!==c&&(o.start<this.scrollOffset&&void 0===this.destinationOffset&&(this.scrollDelta+=r-c,this._scrollToOffset(this.scrollOffset+this.scrollDelta,{canSmooth:!1,sync:!1,requested:!1})),this.pendingMeasuredCacheIndexes.push(n),this.itemMeasurementsCache={...this.itemMeasurementsCache,[o.key]:r},this.notify())},this.measureElement=e=>{e&&this._measureElement(e,!0)},this.getVirtualItems=o((()=>[this.getIndexes(),this.getMeasurements()]),((e,t)=>{const s=[];for(let n=0,o=e.length;n<o;n++){const o=t[e[n]];s.push(o)}return s}),{key:!1,debug:()=>this.options.debug}),this.scrollToOffset=function(e,s){let{align:n="start",smoothScroll:o=t.options.enableSmoothScroll}=void 0===s?{}:s;const i=t.scrollOffset,l=t.getSize();"auto"===n&&(n=e<=i?"start":e>=i+l?"end":"start");const r={canSmooth:o,sync:!1,requested:!0};"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",smoothScroll:o=t.options.enableSmoothScroll,...i}=void 0===s?{}:s;const l=t.getMeasurements(),r=t.scrollOffset,c=t.getSize(),{count:h}=t.options,a=l[Math.max(0,Math.min(e,h-1))];if(!a)return;if("auto"===n)if(a.end>=r+c-t.options.scrollPaddingEnd)n="end";else{if(!(a.start<=r+t.options.scrollPaddingStart))return;n="start"}const u="end"===n?a.end+t.options.scrollPaddingEnd:a.start-t.options.scrollPaddingStart;t.scrollToOffset(u,{align:n,smoothScroll:o,...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 s,{requested:n,canSmooth:o,sync:i}=t;clearTimeout(this.scrollCheckFrame),n&&(this.destinationOffset=e),this.options.scrollToFn(e,{canSmooth:o,sync:i},this);const l=()=>{let e=this.scrollOffset;this.scrollCheckFrame=s=setTimeout((()=>{this.scrollCheckFrame===s&&(this.scrollOffset!==e?(e=this.scrollOffset,l()):this.destinationOffset=void 0)}),100)};l()},this.measure=()=>{this.itemMeasurementsCache={},this.notify()},this.setOptions(e),this.scrollRect=this.options.initialRect,this.scrollOffset=this.options.initialOffset,this.calculateRange()}}const E="undefined"!=typeof window?n.useLayoutEffect:n.useEffect;function b(e){const t=n.useReducer((()=>({})),{})[1],s={...e,onChange:s=>{t(),null==e.onChange||e.onChange(s)}},[o]=n.useState((()=>new p(s)));return o.setOptions(s),n.useEffect((()=>o._didMount()),[]),E((()=>o._willUpdate())),o}e.Virtualizer=p,e.defaultKeyExtractor=i,e.defaultRangeExtractor=l,e.elementScroll=g,e.measureElement=m,e.memo=o,e.observeElementOffset=u,e.observeElementRect=r,e.observeWindowOffset=d,e.observeWindowRect=c,e.useVirtualizer=function(e){return b({observeElementRect:r,observeElementOffset:u,scrollToFn:g,...e})},e.useWindowVirtualizer=function(e){return b({getScrollElement:()=>"undefined"!=typeof window?window:null,observeElementRect:c,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.21", | ||
"version": "3.0.0-beta.22", | ||
"description": "Headless UI for virtualizing scrollable elements in React", | ||
@@ -40,3 +40,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"@tanstack/virtual-core": "3.0.0-beta.21" | ||
"@tanstack/virtual-core": "3.0.0-beta.22" | ||
}, | ||
@@ -43,0 +43,0 @@ "peerDependencies": { |
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
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
348607
2118
+ Added@tanstack/virtual-core@3.0.0-beta.22(transitive)
- Removed@tanstack/virtual-core@3.0.0-beta.21(transitive)