virtua 0.48.1 → 0.48.3

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.
@@ -807,26 +807,11 @@ const createScroller = (store, isHorizontal) => {
807
807
  }
808
808
  });
809
809
  return {
810
- $observe(viewport) {
810
+ $observe(_, viewport) {
811
811
  viewportElement = viewport;
812
- const clean = store.$subscribe(UPDATE_SIZE_EVENT, () => {
813
- const viewportSize = store.$getViewportSize();
814
- if (viewportSize) {
815
- const prev = viewport[scrollOffsetKey];
816
- // Detect overflowed direction after the initial viewport measurement
817
- const dummy = getCurrentDocument(viewport).createElement("div");
818
- dummy.style.cssText = `visibility:hidden;min-${isHorizontal ? "width" : "height"}:${
819
- // Set larger value than the viewportSize to force overflow. And the value must take subpixels into account.
820
- viewportSize + 9}px`;
821
- viewport.appendChild(dummy);
822
- viewport[scrollOffsetKey] = 1;
823
- // It can be positive under some specific situations even if negative mode, so we use `<` for now.
824
- isNegative = viewport[scrollOffsetKey] < 1;
825
- viewport.removeChild(dummy);
826
- viewport[scrollOffsetKey] = prev;
827
- clean();
828
- }
829
- });
812
+ if (isHorizontal) {
813
+ isNegative = getComputedStyle(viewport).direction === "rtl";
814
+ }
830
815
  scrollObserver = createScrollObserver(store, viewport, isHorizontal, () => normalizeScrollOffset(viewport[scrollOffsetKey], isNegative), (jump, shift, isMomentumScrolling) => {
831
816
  // If we update scroll position while touching on iOS, the position will be reverted.
832
817
  // However iOS WebKit fires touch events only once at the beginning of momentum scrolling.
@@ -1021,9 +1006,9 @@ const createGridScroller = (rowStore, colStore) => {
1021
1006
  const rowScroller = createScroller(rowStore, false);
1022
1007
  const colScroller = createScroller(colStore, true);
1023
1008
  return {
1024
- $observe(viewportElement) {
1025
- rowScroller.$observe(viewportElement);
1026
- colScroller.$observe(viewportElement);
1009
+ $observe(container, viewport) {
1010
+ rowScroller.$observe(container, viewport);
1011
+ colScroller.$observe(container, viewport);
1027
1012
  },
1028
1013
  $dispose() {
1029
1014
  rowScroller.$dispose();
@@ -1388,9 +1373,10 @@ const Virtualizer = (props) => {
1388
1373
  scrollBy: scroller.$scrollBy,
1389
1374
  });
1390
1375
  }
1391
- const scrollable = props.scrollRef || containerRef.parentElement;
1376
+ const container = containerRef;
1377
+ const scrollable = props.scrollRef || container.parentElement;
1392
1378
  resizer.$observeRoot(scrollable);
1393
- scroller.$observe(scrollable);
1379
+ scroller.$observe(container, scrollable);
1394
1380
  onCleanup(() => {
1395
1381
  if (props.ref) {
1396
1382
  props.ref();
@@ -1415,7 +1401,6 @@ const Virtualizer = (props) => {
1415
1401
  store.$update(ACTION_ITEMS_LENGTH_CHANGE, [count, props.shift]);
1416
1402
  }
1417
1403
  });
1418
- const pushKey = !horizontal && isNegative() ? "unshift" : "push";
1419
1404
  const items = [];
1420
1405
  const indexes = [];
1421
1406
  if (props.keepMounted) {
@@ -1424,14 +1409,14 @@ const Virtualizer = (props) => {
1424
1409
  mounted.add(i);
1425
1410
  }
1426
1411
  sort([...mounted]).forEach((index) => {
1427
- items[pushKey](props.data[index]);
1428
- indexes[pushKey](index);
1412
+ items.push(props.data[index]);
1413
+ indexes.push(index);
1429
1414
  });
1430
1415
  }
1431
1416
  else {
1432
1417
  for (let [i, j] = range(); i <= j; i++) {
1433
- items[pushKey](props.data[i]);
1434
- indexes[pushKey](i);
1418
+ items.push(props.data[i]);
1419
+ indexes.push(i);
1435
1420
  }
1436
1421
  }
1437
1422
  return { _items: items, _indexes: indexes };
@@ -1580,10 +1565,9 @@ const WindowVirtualizer = (props) => {
1580
1565
  store.$update(ACTION_ITEMS_LENGTH_CHANGE, [count, props.shift]);
1581
1566
  }
1582
1567
  });
1583
- const pushKey = !horizontal && isNegative() ? "unshift" : "push";
1584
1568
  const items = [];
1585
1569
  for (let [i, j] = range(); i <= j; i++) {
1586
- items[pushKey](props.data[i]);
1570
+ items.push(props.data[i]);
1587
1571
  }
1588
1572
  return items;
1589
1573
  });