react-window 2.2.2-alpha.1 → 2.2.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.
@@ -1,6 +1,6 @@
1
1
  import { jsx as P } from "react/jsx-runtime";
2
2
  import { useState as H, useLayoutEffect as se, useEffect as J, useMemo as L, useRef as K, useCallback as U, memo as le, useImperativeHandle as ce, createElement as X } from "react";
3
- function ge(e) {
3
+ function xe(e) {
4
4
  let t = e;
5
5
  for (; t; ) {
6
6
  if (t.dir)
@@ -12,7 +12,7 @@ function ge(e) {
12
12
  function ve(e, t) {
13
13
  const [s, r] = H(t === "rtl");
14
14
  return se(() => {
15
- e && (t || r(ge(e)));
15
+ e && (t || r(xe(e)));
16
16
  }, [t, e]), s;
17
17
  }
18
18
  const q = typeof window < "u" ? se : J;
@@ -28,7 +28,7 @@ function oe(e) {
28
28
  }
29
29
  }
30
30
  }
31
- function be({
31
+ function Ie({
32
32
  box: e,
33
33
  defaultHeight: t,
34
34
  defaultWidth: s,
@@ -50,12 +50,12 @@ function be({
50
50
  return q(() => {
51
51
  if (n === null || a)
52
52
  return;
53
- const u = new ResizeObserver((b) => {
54
- for (const w of b) {
55
- const { contentRect: I, target: x } = w;
56
- n === x && d((m) => m.height === I.height && m.width === I.width ? m : {
57
- height: I.height,
58
- width: I.width
53
+ const u = new ResizeObserver((I) => {
54
+ for (const m of I) {
55
+ const { contentRect: b, target: g } = m;
56
+ n === g && d((w) => w.height === b.height && w.width === b.width ? w : {
57
+ height: b.height,
58
+ width: b.width
59
59
  });
60
60
  }
61
61
  });
@@ -79,7 +79,7 @@ function ae(e) {
79
79
  }, [e]), U((s) => t.current?.(s), [t]);
80
80
  }
81
81
  let F = null;
82
- function Ie(e = !1) {
82
+ function be(e = !1) {
83
83
  if (F === null || e) {
84
84
  const t = document.createElement("div"), s = t.style;
85
85
  s.width = "50px", s.height = "50px", s.overflow = "scroll", s.direction = "rtl";
@@ -95,7 +95,7 @@ function Z({
95
95
  scrollOffset: r
96
96
  }) {
97
97
  if (t === "horizontal" && s)
98
- switch (Ie()) {
98
+ switch (be()) {
99
99
  case "negative":
100
100
  return -r;
101
101
  case "positive-descending": {
@@ -140,7 +140,7 @@ function fe({
140
140
  return t * n;
141
141
  }
142
142
  }
143
- function me({
143
+ function we({
144
144
  align: e,
145
145
  cachedBounds: t,
146
146
  index: s,
@@ -149,6 +149,10 @@ function me({
149
149
  containerScrollOffset: o,
150
150
  containerSize: i
151
151
  }) {
152
+ if (s < 0 || s >= r)
153
+ throw RangeError(`Invalid index specified: ${s}`, {
154
+ cause: `Index ${s} is not within the range of 0 - ${r - 1}`
155
+ });
152
156
  const f = fe({
153
157
  cachedBounds: t,
154
158
  itemCount: r,
@@ -200,7 +204,7 @@ function ie({
200
204
  stopIndexOverscan: c
201
205
  };
202
206
  }
203
- function we({
207
+ function me({
204
208
  itemCount: e,
205
209
  itemProps: t,
206
210
  itemSize: s
@@ -257,7 +261,7 @@ function Oe({
257
261
  itemSize: s
258
262
  }) {
259
263
  return L(
260
- () => we({
264
+ () => me({
261
265
  itemCount: e,
262
266
  itemProps: t,
263
267
  itemSize: s
@@ -307,15 +311,15 @@ function ee({
307
311
  stopIndexOverscan: -1
308
312
  }), {
309
313
  startIndexVisible: u,
310
- startIndexOverscan: b,
311
- stopIndexVisible: w,
312
- stopIndexOverscan: I
314
+ startIndexOverscan: I,
315
+ stopIndexVisible: m,
316
+ stopIndexOverscan: b
313
317
  } = {
314
318
  startIndexVisible: Math.min(o - 1, d.startIndexVisible),
315
319
  startIndexOverscan: Math.min(o - 1, d.startIndexOverscan),
316
320
  stopIndexVisible: Math.min(o - 1, d.stopIndexVisible),
317
321
  stopIndexOverscan: Math.min(o - 1, d.stopIndexOverscan)
318
- }, { height: x = s, width: m = s } = be({
322
+ }, { height: g = s, width: w = s } = Ie({
319
323
  defaultHeight: r === "vertical" ? s : void 0,
320
324
  defaultWidth: r === "horizontal" ? s : void 0,
321
325
  element: e,
@@ -324,13 +328,13 @@ function ee({
324
328
  }), y = K({
325
329
  height: 0,
326
330
  width: 0
327
- }), E = r === "vertical" ? x : m, h = ye({ containerSize: E, itemSize: f });
331
+ }), V = r === "vertical" ? g : w, h = ye({ containerSize: V, itemSize: f });
328
332
  se(() => {
329
333
  if (typeof l == "function") {
330
334
  const p = y.current;
331
- (p.height !== x || p.width !== m) && (l({ height: x, width: m }, { ...p }), p.height = x, p.width = m);
335
+ (p.height !== g || p.width !== w) && (l({ height: g, width: w }, { ...p }), p.height = g, p.width = w);
332
336
  }
333
- }, [x, l, m]);
337
+ }, [g, l, w]);
334
338
  const z = Oe({
335
339
  itemCount: o,
336
340
  itemProps: i,
@@ -356,7 +360,7 @@ function ee({
356
360
  return ie({
357
361
  cachedBounds: z,
358
362
  containerScrollOffset: T,
359
- containerSize: E,
363
+ containerSize: V,
360
364
  itemCount: o,
361
365
  overscanCount: c
362
366
  });
@@ -364,7 +368,7 @@ function ee({
364
368
  [
365
369
  z,
366
370
  e,
367
- E,
371
+ V,
368
372
  r,
369
373
  n,
370
374
  o,
@@ -379,15 +383,15 @@ function ee({
379
383
  return;
380
384
  const p = () => {
381
385
  a((T) => {
382
- const { scrollLeft: R, scrollTop: v } = e, g = Z({
386
+ const { scrollLeft: R, scrollTop: v } = e, x = Z({
383
387
  containerElement: e,
384
388
  direction: r,
385
389
  isRtl: n,
386
390
  scrollOffset: r === "vertical" ? v : R
387
391
  }), A = ie({
388
392
  cachedBounds: z,
389
- containerScrollOffset: g,
390
- containerSize: E,
393
+ containerScrollOffset: x,
394
+ containerSize: V,
391
395
  itemCount: o,
392
396
  overscanCount: c
393
397
  });
@@ -400,7 +404,7 @@ function ee({
400
404
  }, [
401
405
  z,
402
406
  e,
403
- E,
407
+ V,
404
408
  r,
405
409
  o,
406
410
  c
@@ -411,11 +415,11 @@ function ee({
411
415
  containerScrollOffset: T,
412
416
  index: R
413
417
  }) => {
414
- let v = me({
418
+ let v = we({
415
419
  align: p,
416
420
  cachedBounds: z,
417
421
  containerScrollOffset: T,
418
- containerSize: E,
422
+ containerSize: V,
419
423
  index: R,
420
424
  itemCount: o,
421
425
  itemSize: h
@@ -427,8 +431,8 @@ function ee({
427
431
  isRtl: n,
428
432
  scrollOffset: v
429
433
  }), typeof e.scrollTo != "function") {
430
- const g = W(v);
431
- Y(d, g) || a(g);
434
+ const x = W(v);
435
+ Y(d, x) || a(x);
432
436
  }
433
437
  return v;
434
438
  }
@@ -438,10 +442,10 @@ function ee({
438
442
  getCellBounds: k,
439
443
  getEstimatedSize: S,
440
444
  scrollToIndex: O,
441
- startIndexOverscan: b,
445
+ startIndexOverscan: I,
442
446
  startIndexVisible: u,
443
- stopIndexOverscan: I,
444
- stopIndexVisible: w
447
+ stopIndexOverscan: b,
448
+ stopIndexVisible: m
445
449
  };
446
450
  }
447
451
  function de(e) {
@@ -459,7 +463,7 @@ function ue(e, t) {
459
463
  } = t;
460
464
  return Y(s, o) && Y(r, i) && Y(n, f);
461
465
  }
462
- function Ve({
466
+ function Ee({
463
467
  cellComponent: e,
464
468
  cellProps: t,
465
469
  children: s,
@@ -473,13 +477,13 @@ function Ve({
473
477
  onCellsRendered: d,
474
478
  onResize: a,
475
479
  overscanCount: u = 3,
476
- rowCount: b,
477
- rowHeight: w,
478
- style: I,
479
- tagName: x = "div",
480
- ...m
480
+ rowCount: I,
481
+ rowHeight: m,
482
+ style: b,
483
+ tagName: g = "div",
484
+ ...w
481
485
  }) {
482
- const y = de(t), E = L(
486
+ const y = de(t), V = L(
483
487
  () => le(e, ue),
484
488
  [e]
485
489
  ), [h, z] = H(null), k = ve(h, l), {
@@ -492,7 +496,7 @@ function Ve({
492
496
  stopIndexVisible: v
493
497
  } = ee({
494
498
  containerElement: h,
495
- containerStyle: I,
499
+ containerStyle: b,
496
500
  defaultContainerSize: f,
497
501
  direction: "horizontal",
498
502
  isRtl: k,
@@ -502,7 +506,7 @@ function Ve({
502
506
  onResize: a,
503
507
  overscanCount: u
504
508
  }), {
505
- getCellBounds: g,
509
+ getCellBounds: x,
506
510
  getEstimatedSize: A,
507
511
  startIndexOverscan: M,
508
512
  startIndexVisible: re,
@@ -511,12 +515,12 @@ function Ve({
511
515
  stopIndexVisible: ne
512
516
  } = ee({
513
517
  containerElement: h,
514
- containerStyle: I,
518
+ containerStyle: b,
515
519
  defaultContainerSize: i,
516
520
  direction: "vertical",
517
- itemCount: b,
521
+ itemCount: I,
518
522
  itemProps: y,
519
- itemSize: w,
523
+ itemSize: m,
520
524
  onResize: a,
521
525
  overscanCount: u
522
526
  });
@@ -528,16 +532,16 @@ function Ve({
528
532
  },
529
533
  scrollToCell({
530
534
  behavior: B = "auto",
531
- columnAlign: V = "auto",
535
+ columnAlign: E = "auto",
532
536
  columnIndex: j,
533
537
  rowAlign: D = "auto",
534
538
  rowIndex: G
535
539
  }) {
536
540
  const N = T({
537
- align: V,
541
+ align: E,
538
542
  containerScrollOffset: h?.scrollLeft ?? 0,
539
543
  index: j
540
- }), xe = Q({
544
+ }), ge = Q({
541
545
  align: D,
542
546
  containerScrollOffset: h?.scrollTop ?? 0,
543
547
  index: G
@@ -545,12 +549,12 @@ function Ve({
545
549
  typeof h?.scrollTo == "function" && h.scrollTo({
546
550
  behavior: B,
547
551
  left: N,
548
- top: xe
552
+ top: ge
549
553
  });
550
554
  },
551
555
  scrollToColumn({
552
556
  align: B = "auto",
553
- behavior: V = "auto",
557
+ behavior: E = "auto",
554
558
  index: j
555
559
  }) {
556
560
  const D = T({
@@ -559,13 +563,13 @@ function Ve({
559
563
  index: j
560
564
  });
561
565
  typeof h?.scrollTo == "function" && h.scrollTo({
562
- behavior: V,
566
+ behavior: E,
563
567
  left: D
564
568
  });
565
569
  },
566
570
  scrollToRow({
567
571
  align: B = "auto",
568
- behavior: V = "auto",
572
+ behavior: E = "auto",
569
573
  index: j
570
574
  }) {
571
575
  const D = Q({
@@ -574,7 +578,7 @@ function Ve({
574
578
  index: j
575
579
  });
576
580
  typeof h?.scrollTo == "function" && h.scrollTo({
577
- behavior: V,
581
+ behavior: E,
578
582
  top: D
579
583
  });
580
584
  }
@@ -608,14 +612,14 @@ function Ve({
608
612
  ]);
609
613
  const he = L(() => {
610
614
  const B = [];
611
- if (n > 0 && b > 0)
612
- for (let V = M; V <= _; V++) {
613
- const j = g(V), D = [];
615
+ if (n > 0 && I > 0)
616
+ for (let E = M; E <= _; E++) {
617
+ const j = x(E), D = [];
614
618
  for (let G = O; G <= R; G++) {
615
619
  const N = S(G);
616
620
  D.push(
617
621
  /* @__PURE__ */ X(
618
- E,
622
+ V,
619
623
  {
620
624
  ...y,
621
625
  ariaAttributes: {
@@ -624,7 +628,7 @@ function Ve({
624
628
  },
625
629
  columnIndex: G,
626
630
  key: G,
627
- rowIndex: V,
631
+ rowIndex: E,
628
632
  style: {
629
633
  position: "absolute",
630
634
  left: k ? void 0 : 0,
@@ -638,20 +642,20 @@ function Ve({
638
642
  );
639
643
  }
640
644
  B.push(
641
- /* @__PURE__ */ P("div", { role: "row", "aria-rowindex": V + 1, children: D }, V)
645
+ /* @__PURE__ */ P("div", { role: "row", "aria-rowindex": E + 1, children: D }, E)
642
646
  );
643
647
  }
644
648
  return B;
645
649
  }, [
646
- E,
650
+ V,
647
651
  y,
648
652
  n,
649
653
  O,
650
654
  R,
651
655
  S,
652
- g,
656
+ x,
653
657
  k,
654
- b,
658
+ I,
655
659
  M,
656
660
  _
657
661
  ]), pe = /* @__PURE__ */ P(
@@ -666,12 +670,12 @@ function Ve({
666
670
  }
667
671
  );
668
672
  return X(
669
- x,
673
+ g,
670
674
  {
671
675
  "aria-colcount": n,
672
- "aria-rowcount": b,
676
+ "aria-rowcount": I,
673
677
  role: "grid",
674
- ...m,
678
+ ...w,
675
679
  className: r,
676
680
  dir: l,
677
681
  ref: z,
@@ -683,7 +687,7 @@ function Ve({
683
687
  maxWidth: "100%",
684
688
  flexGrow: 1,
685
689
  overflow: "auto",
686
- ...I
690
+ ...b
687
691
  }
688
692
  },
689
693
  he,
@@ -691,7 +695,7 @@ function Ve({
691
695
  pe
692
696
  );
693
697
  }
694
- const Ee = H, Re = K;
698
+ const Ve = H, Re = K;
695
699
  function ze(e) {
696
700
  return e != null && typeof e == "object" && "getAverageRowHeight" in e && typeof e.getAverageRowHeight == "function";
697
701
  }
@@ -710,12 +714,12 @@ function Ae({
710
714
  rowProps: d,
711
715
  tagName: a = "div",
712
716
  style: u,
713
- ...b
717
+ ...I
714
718
  }) {
715
- const w = de(d), I = L(
719
+ const m = de(d), b = L(
716
720
  () => le(f, ue),
717
721
  [f]
718
- ), [x, m] = H(null), y = ze(c), E = L(() => y ? (v) => c.getRowHeight(v) ?? c.getAverageRowHeight() : c, [y, c]), {
722
+ ), [g, w] = H(null), y = ze(c), V = L(() => y ? (v) => c.getRowHeight(v) ?? c.getAverageRowHeight() : c, [y, c]), {
719
723
  getCellBounds: h,
720
724
  getEstimatedSize: z,
721
725
  scrollToIndex: k,
@@ -724,13 +728,13 @@ function Ae({
724
728
  stopIndexOverscan: O,
725
729
  stopIndexVisible: p
726
730
  } = ee({
727
- containerElement: x,
731
+ containerElement: g,
728
732
  containerStyle: u,
729
733
  defaultContainerSize: s,
730
734
  direction: "vertical",
731
735
  itemCount: l,
732
- itemProps: w,
733
- itemSize: E,
736
+ itemProps: m,
737
+ itemSize: V,
734
738
  onResize: n,
735
739
  overscanCount: i
736
740
  });
@@ -738,38 +742,38 @@ function Ae({
738
742
  r,
739
743
  () => ({
740
744
  get element() {
741
- return x;
745
+ return g;
742
746
  },
743
747
  scrollToRow({
744
748
  align: v = "auto",
745
- behavior: g = "auto",
749
+ behavior: x = "auto",
746
750
  index: A
747
751
  }) {
748
752
  const M = k({
749
753
  align: v,
750
- containerScrollOffset: x?.scrollTop ?? 0,
754
+ containerScrollOffset: g?.scrollTop ?? 0,
751
755
  index: A
752
756
  });
753
- typeof x?.scrollTo == "function" && x.scrollTo({
754
- behavior: g,
757
+ typeof g?.scrollTo == "function" && g.scrollTo({
758
+ behavior: x,
755
759
  top: M
756
760
  });
757
761
  }
758
762
  }),
759
- [x, k]
763
+ [g, k]
760
764
  ), q(() => {
761
- if (!x)
765
+ if (!g)
762
766
  return;
763
- const v = Array.from(x.children).filter((g, A) => {
764
- if (g.hasAttribute("aria-hidden"))
767
+ const v = Array.from(g.children).filter((x, A) => {
768
+ if (x.hasAttribute("aria-hidden"))
765
769
  return !1;
766
770
  const M = `${S + A}`;
767
- return g.setAttribute(te, M), !0;
771
+ return x.setAttribute(te, M), !0;
768
772
  });
769
773
  if (y)
770
774
  return c.observeRowElements(v);
771
775
  }, [
772
- x,
776
+ g,
773
777
  y,
774
778
  c,
775
779
  S,
@@ -795,20 +799,20 @@ function Ae({
795
799
  const T = L(() => {
796
800
  const v = [];
797
801
  if (l > 0)
798
- for (let g = S; g <= O; g++) {
799
- const A = h(g);
802
+ for (let x = S; x <= O; x++) {
803
+ const A = h(x);
800
804
  v.push(
801
805
  /* @__PURE__ */ X(
802
- I,
806
+ b,
803
807
  {
804
- ...w,
808
+ ...m,
805
809
  ariaAttributes: {
806
- "aria-posinset": g + 1,
810
+ "aria-posinset": x + 1,
807
811
  "aria-setsize": l,
808
812
  role: "listitem"
809
813
  },
810
- key: g,
811
- index: g,
814
+ key: x,
815
+ index: x,
812
816
  style: {
813
817
  position: "absolute",
814
818
  left: 0,
@@ -824,11 +828,11 @@ function Ae({
824
828
  }
825
829
  return v;
826
830
  }, [
827
- I,
831
+ b,
828
832
  h,
829
833
  y,
830
834
  l,
831
- w,
835
+ m,
832
836
  S,
833
837
  O
834
838
  ]), R = /* @__PURE__ */ P(
@@ -846,9 +850,9 @@ function Ae({
846
850
  a,
847
851
  {
848
852
  role: "list",
849
- ...b,
853
+ ...I,
850
854
  className: t,
851
- ref: m,
855
+ ref: w,
852
856
  style: {
853
857
  position: "relative",
854
858
  maxHeight: "100%",
@@ -886,25 +890,25 @@ function ke({
886
890
  },
887
891
  [e, n]
888
892
  ), f = U((a, u) => {
889
- r((b) => {
890
- if (b.map.get(a) === u)
891
- return b;
892
- const w = new Map(b.map);
893
- return w.set(a, u), {
894
- ...b,
895
- map: w
893
+ r((I) => {
894
+ if (I.map.get(a) === u)
895
+ return I;
896
+ const m = new Map(I.map);
897
+ return m.set(a, u), {
898
+ ...I,
899
+ map: m
896
900
  };
897
901
  });
898
902
  }, []), l = ae(
899
903
  (a) => {
900
904
  a.length !== 0 && a.forEach((u) => {
901
- const { borderBoxSize: b, target: w } = u, I = w.getAttribute(te);
905
+ const { borderBoxSize: I, target: m } = u, b = m.getAttribute(te);
902
906
  $(
903
- I !== null,
907
+ b !== null,
904
908
  `Invalid ${te} attribute value`
905
909
  );
906
- const x = parseInt(I), { blockSize: m } = b[0];
907
- m && f(x, m);
910
+ const g = parseInt(b), { blockSize: w } = I[0];
911
+ w && f(g, w);
908
912
  });
909
913
  }
910
914
  ), [c] = H(
@@ -939,11 +943,11 @@ function $e(e = !1) {
939
943
  return C;
940
944
  }
941
945
  export {
942
- Ve as Grid,
946
+ Ee as Grid,
943
947
  Ae as List,
944
948
  $e as getScrollbarSize,
945
949
  ke as useDynamicRowHeight,
946
- Ee as useGridCallbackRef,
950
+ Ve as useGridCallbackRef,
947
951
  Re as useGridRef,
948
952
  Le as useListCallbackRef,
949
953
  Me as useListRef