virtua 0.38.2 → 0.38.4

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.
@@ -5,10 +5,6 @@ import { Dynamic } from 'solid-js/web';
5
5
  const NULL = null;
6
6
  /** @internal */
7
7
  const { min, max, abs, floor } = Math;
8
- /** @internal */
9
- const values = Object.values;
10
- /** @internal */
11
- const timeout = setTimeout;
12
8
  /**
13
9
  * @internal
14
10
  */
@@ -27,26 +23,6 @@ const microtask = typeof queueMicrotask === "function"
27
23
  : (fn) => {
28
24
  Promise.resolve().then(fn);
29
25
  };
30
- /**
31
- * @internal
32
- */
33
- const debounce = (fn, ms) => {
34
- let id;
35
- const cancel = () => {
36
- if (id != NULL) {
37
- clearTimeout(id);
38
- }
39
- };
40
- const debouncedFn = () => {
41
- cancel();
42
- id = timeout(() => {
43
- id = NULL;
44
- fn();
45
- }, ms);
46
- };
47
- debouncedFn._cancel = cancel;
48
- return debouncedFn;
49
- };
50
26
  /**
51
27
  * @internal
52
28
  */
@@ -61,17 +37,6 @@ const once = (fn) => {
61
37
  return cache;
62
38
  };
63
39
  };
64
- /**
65
- * @internal
66
- */
67
- const getStyleNumber = (v) => {
68
- if (v) {
69
- return parseFloat(v);
70
- }
71
- else {
72
- return 0;
73
- }
74
- };
75
40
 
76
41
  /** @internal */
77
42
  const UNCACHED = -1;
@@ -553,14 +518,18 @@ const createVirtualStore = (elementsCount, itemSize = 40, overscan = 4, ssrCount
553
518
  break;
554
519
  }
555
520
  case ACTION_ITEMS_LENGTH_CHANGE: {
521
+ const atBottom = scrollOffset + viewportSize >= getTotalSize();
556
522
  if (payload[1]) {
557
523
  applyJump(updateCacheLength(cache, payload[0], true));
558
524
  _scrollMode = SCROLL_BY_SHIFT;
559
- mutated = UPDATE_VIRTUAL_STATE;
560
525
  }
561
526
  else {
562
527
  updateCacheLength(cache, payload[0]);
563
528
  }
529
+ // https://github.com/inokawa/virtua/issues/552
530
+ if (payload[1] || atBottom) {
531
+ mutated = UPDATE_VIRTUAL_STATE;
532
+ }
564
533
  break;
565
534
  }
566
535
  case ACTION_START_OFFSET_CHANGE: {
@@ -598,6 +567,24 @@ const createVirtualStore = (elementsCount, itemSize = 40, overscan = 4, ssrCount
598
567
  };
599
568
  };
600
569
 
570
+ const timeout = setTimeout;
571
+ const debounce = (fn, ms) => {
572
+ let id;
573
+ const cancel = () => {
574
+ if (id != NULL) {
575
+ clearTimeout(id);
576
+ }
577
+ };
578
+ const debouncedFn = () => {
579
+ cancel();
580
+ id = timeout(() => {
581
+ id = NULL;
582
+ fn();
583
+ }, ms);
584
+ };
585
+ debouncedFn._cancel = cancel;
586
+ return debouncedFn;
587
+ };
601
588
  /**
602
589
  * scrollLeft is negative value in rtl direction.
603
590
  *
@@ -984,27 +971,21 @@ const createWindowScroller = (store, isHorizontal) => {
984
971
  }
985
972
  const document = getCurrentDocument(containerElement);
986
973
  const window = getCurrentWindow(document);
974
+ const html = document.documentElement;
975
+ const getScrollbarSize = () => store.$getViewportSize() -
976
+ (isHorizontal ? html.clientWidth : html.clientHeight);
987
977
  scheduleImperativeScroll(() => {
988
- // Calculate target scroll position including container's offset from document
989
- const containerOffset = calcOffsetToViewport(containerElement, document.body, window, isHorizontal);
990
- // slight tech debt: this would otherwise need to be accounted for in store._getViewportSize in a way that's flexible for windowScroller
991
- const scrollbarHeight = window.innerHeight - document.documentElement.clientHeight;
992
- const scrollbarWidth = window.innerHeight - document.documentElement.clientWidth;
993
- const viewportAdjustment = align === "end" || align === "center"
994
- ? isHorizontal
995
- ? scrollbarWidth
996
- : scrollbarHeight
997
- : 0;
998
978
  return (offset +
999
- containerOffset +
979
+ // Calculate target scroll position including container's offset from document
980
+ calcOffsetToViewport(containerElement, document.body, window, isHorizontal) +
1000
981
  // store._getStartSpacerSize() +
1001
982
  store.$getItemOffset(index) +
1002
983
  (align === "end"
1003
984
  ? store.$getItemSize(index) -
1004
- (store.$getViewportSize() - viewportAdjustment)
985
+ (store.$getViewportSize() - getScrollbarSize())
1005
986
  : align === "center"
1006
987
  ? (store.$getItemSize(index) -
1007
- (store.$getViewportSize() - viewportAdjustment)) /
988
+ (store.$getViewportSize() - getScrollbarSize())) /
1008
989
  2
1009
990
  : 0));
1010
991
  }, smooth);