@tanstack/virtual-core 3.0.0-beta.36 → 3.0.0-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/index.esm.js +20 -16
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.js +20 -16
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +20 -16
- package/build/lib/index.mjs.map +1 -1
- package/build/umd/index.development.js +20 -16
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +34 -24
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/virtual-core",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "3.0.0-beta.
|
|
4
|
+
"version": "3.0.0-beta.40",
|
|
5
5
|
"description": "Headless UI for virtualizing scrollable elements in TS/JS + Frameworks",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/tanstack/virtual#readme",
|
package/src/index.ts
CHANGED
|
@@ -296,7 +296,10 @@ export class Virtualizer<
|
|
|
296
296
|
scrollOffset: number
|
|
297
297
|
scrollDirection: ScrollDirection | null = null
|
|
298
298
|
private scrollAdjustments: number = 0
|
|
299
|
-
private measureElementCache: Record<
|
|
299
|
+
private measureElementCache: Record<
|
|
300
|
+
Key,
|
|
301
|
+
TItemElement & { __virtualizerSkipFirstNotSync?: boolean }
|
|
302
|
+
> = {}
|
|
300
303
|
private getResizeObserver = (() => {
|
|
301
304
|
let _ro: ResizeObserver | null = null
|
|
302
305
|
|
|
@@ -519,7 +522,7 @@ export class Virtualizer<
|
|
|
519
522
|
return rangeExtractor({
|
|
520
523
|
...range,
|
|
521
524
|
overscan,
|
|
522
|
-
count
|
|
525
|
+
count,
|
|
523
526
|
})
|
|
524
527
|
},
|
|
525
528
|
{
|
|
@@ -542,7 +545,7 @@ export class Virtualizer<
|
|
|
542
545
|
return parseInt(indexStr, 10)
|
|
543
546
|
}
|
|
544
547
|
|
|
545
|
-
private _measureElement = (node: TItemElement,
|
|
548
|
+
private _measureElement = (node: TItemElement, sync: boolean) => {
|
|
546
549
|
const index = this.indexFromElement(node)
|
|
547
550
|
|
|
548
551
|
const item = this.measurementsCache[index]
|
|
@@ -555,19 +558,24 @@ export class Virtualizer<
|
|
|
555
558
|
const ro = this.getResizeObserver()
|
|
556
559
|
|
|
557
560
|
if (!node.isConnected) {
|
|
558
|
-
|
|
559
|
-
|
|
561
|
+
ro?.unobserve(node)
|
|
562
|
+
if (node === prevNode) {
|
|
560
563
|
delete this.measureElementCache[item.key]
|
|
561
564
|
}
|
|
562
565
|
return
|
|
563
566
|
}
|
|
564
567
|
|
|
565
|
-
if (
|
|
568
|
+
if (prevNode !== node) {
|
|
566
569
|
if (prevNode) {
|
|
567
570
|
ro?.unobserve(prevNode)
|
|
568
571
|
}
|
|
569
|
-
this.measureElementCache[item.key] = node
|
|
570
572
|
ro?.observe(node)
|
|
573
|
+
this.measureElementCache[item.key] = node
|
|
574
|
+
} else {
|
|
575
|
+
if (!sync && !prevNode.__virtualizerSkipFirstNotSync) {
|
|
576
|
+
prevNode.__virtualizerSkipFirstNotSync = true
|
|
577
|
+
return
|
|
578
|
+
}
|
|
571
579
|
}
|
|
572
580
|
|
|
573
581
|
const measuredItemSize = this.options.measureElement(node, this)
|
|
@@ -626,13 +634,12 @@ export class Virtualizer<
|
|
|
626
634
|
)
|
|
627
635
|
|
|
628
636
|
getOffsetForAlignment = (toOffset: number, align: ScrollAlignment) => {
|
|
629
|
-
const offset = this.scrollOffset
|
|
630
637
|
const size = this.getSize()
|
|
631
638
|
|
|
632
639
|
if (align === 'auto') {
|
|
633
|
-
if (toOffset <=
|
|
640
|
+
if (toOffset <= this.scrollOffset) {
|
|
634
641
|
align = 'start'
|
|
635
|
-
} else if (toOffset >=
|
|
642
|
+
} else if (toOffset >= this.scrollOffset + size) {
|
|
636
643
|
align = 'end'
|
|
637
644
|
} else {
|
|
638
645
|
align = 'start'
|
|
@@ -640,13 +647,25 @@ export class Virtualizer<
|
|
|
640
647
|
}
|
|
641
648
|
|
|
642
649
|
if (align === 'start') {
|
|
643
|
-
|
|
650
|
+
toOffset = toOffset
|
|
644
651
|
} else if (align === 'end') {
|
|
645
|
-
|
|
652
|
+
toOffset = toOffset - size
|
|
646
653
|
} else if (align === 'center') {
|
|
647
|
-
|
|
654
|
+
toOffset = toOffset - size / 2
|
|
648
655
|
}
|
|
649
|
-
|
|
656
|
+
|
|
657
|
+
const scrollSizeProp = this.options.horizontal
|
|
658
|
+
? 'scrollWidth'
|
|
659
|
+
: 'scrollHeight'
|
|
660
|
+
const scrollSize = this.scrollElement
|
|
661
|
+
? 'document' in this.scrollElement
|
|
662
|
+
? this.scrollElement.document.documentElement[scrollSizeProp]
|
|
663
|
+
: this.scrollElement[scrollSizeProp]
|
|
664
|
+
: 0
|
|
665
|
+
|
|
666
|
+
const maxOffset = scrollSize - this.getSize()
|
|
667
|
+
|
|
668
|
+
return Math.max(Math.min(maxOffset, toOffset), 0)
|
|
650
669
|
}
|
|
651
670
|
|
|
652
671
|
scrollToOffset = (
|
|
@@ -724,16 +743,7 @@ export class Virtualizer<
|
|
|
724
743
|
? measurement.end + this.options.scrollPaddingEnd
|
|
725
744
|
: measurement.start - this.options.scrollPaddingStart
|
|
726
745
|
|
|
727
|
-
|
|
728
|
-
const scrollSize = this.scrollElement
|
|
729
|
-
? 'document' in this.scrollElement
|
|
730
|
-
? this.scrollElement.document.documentElement[sizeProp]
|
|
731
|
-
: this.scrollElement[sizeProp]
|
|
732
|
-
: 0
|
|
733
|
-
|
|
734
|
-
const maxOffset = scrollSize - this.getSize()
|
|
735
|
-
|
|
736
|
-
return Math.min(maxOffset, this.getOffsetForAlignment(toOffset, align))
|
|
746
|
+
return this.getOffsetForAlignment(toOffset, align)
|
|
737
747
|
}
|
|
738
748
|
|
|
739
749
|
const toOffset = getOffsetForIndexAndAlignment(measurement)
|