@tanstack/virtual-core 3.0.0-beta.39 → 3.0.0-beta.41
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.d.ts +2 -2
- package/build/lib/index.esm.js +34 -27
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.js +34 -27
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +34 -27
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/utils.d.ts +2 -2
- package/build/lib/utils.esm.js +4 -1
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +4 -1
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs +4 -1
- package/build/lib/utils.mjs.map +1 -1
- package/build/umd/index.development.js +38 -28
- 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 +19 -11
- package/src/utils.ts +9 -5
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
|
|
|
@@ -435,8 +438,6 @@ export class Virtualizer<
|
|
|
435
438
|
}, this.options.scrollingDelay)
|
|
436
439
|
}),
|
|
437
440
|
)
|
|
438
|
-
} else if (!this.isScrolling) {
|
|
439
|
-
this.calculateRange()
|
|
440
441
|
}
|
|
441
442
|
}
|
|
442
443
|
|
|
@@ -487,7 +488,7 @@ export class Virtualizer<
|
|
|
487
488
|
|
|
488
489
|
calculateRange = memo(
|
|
489
490
|
() => [this.getMeasurements(), this.getSize(), this.scrollOffset],
|
|
490
|
-
(measurements, outerSize, scrollOffset) => {
|
|
491
|
+
(measurements, outerSize, scrollOffset, [flush = true]: [boolean?]) => {
|
|
491
492
|
const range = calculateRange({
|
|
492
493
|
measurements,
|
|
493
494
|
outerSize,
|
|
@@ -498,7 +499,9 @@ export class Virtualizer<
|
|
|
498
499
|
range.endIndex !== this.range.endIndex
|
|
499
500
|
) {
|
|
500
501
|
this.range = range
|
|
501
|
-
|
|
502
|
+
if (flush) {
|
|
503
|
+
this.notify()
|
|
504
|
+
}
|
|
502
505
|
}
|
|
503
506
|
return this.range
|
|
504
507
|
},
|
|
@@ -511,7 +514,7 @@ export class Virtualizer<
|
|
|
511
514
|
private getIndexes = memo(
|
|
512
515
|
() => [
|
|
513
516
|
this.options.rangeExtractor,
|
|
514
|
-
this.
|
|
517
|
+
this.calculateRange(false),
|
|
515
518
|
this.options.overscan,
|
|
516
519
|
this.options.count,
|
|
517
520
|
],
|
|
@@ -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)
|
package/src/utils.ts
CHANGED
|
@@ -2,19 +2,23 @@ export type NoInfer<A extends any> = [A][A extends any ? 0 : never]
|
|
|
2
2
|
|
|
3
3
|
export type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
|
|
4
4
|
|
|
5
|
-
export function memo<
|
|
5
|
+
export function memo<
|
|
6
|
+
TDeps extends readonly any[],
|
|
7
|
+
TResult,
|
|
8
|
+
FArgs extends readonly any[],
|
|
9
|
+
>(
|
|
6
10
|
getDeps: () => [...TDeps],
|
|
7
|
-
fn: (...args:
|
|
11
|
+
fn: (...args: [...TDeps, FArgs]) => TResult,
|
|
8
12
|
opts: {
|
|
9
13
|
key: any
|
|
10
14
|
debug?: () => any
|
|
11
15
|
onChange?: (result: TResult) => void
|
|
12
16
|
},
|
|
13
|
-
)
|
|
17
|
+
) {
|
|
14
18
|
let deps: any[] = []
|
|
15
19
|
let result: TResult | undefined
|
|
16
20
|
|
|
17
|
-
return () => {
|
|
21
|
+
return (...fArgs: FArgs): TResult => {
|
|
18
22
|
let depTime: number
|
|
19
23
|
if (opts.key && opts.debug?.()) depTime = Date.now()
|
|
20
24
|
|
|
@@ -33,7 +37,7 @@ export function memo<TDeps extends readonly any[], TResult>(
|
|
|
33
37
|
let resultTime: number
|
|
34
38
|
if (opts.key && opts.debug?.()) resultTime = Date.now()
|
|
35
39
|
|
|
36
|
-
result = fn(...newDeps)
|
|
40
|
+
result = fn(...newDeps, fArgs)
|
|
37
41
|
opts?.onChange?.(result)
|
|
38
42
|
|
|
39
43
|
if (opts.key && opts.debug?.()) {
|