@glhrmoura/vue-virtualize 0.2.1 → 0.2.2

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/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { shallowRef as Xe, ref as _, toValue as l, watch as Te, onBeforeUnmount as Ce, computed as T, defineComponent as ve, openBlock as V, createBlock as ce, resolveDynamicComponent as ue, normalizeStyle as W, withCtx as de, renderSlot as Z, createElementBlock as B, Fragment as ne, renderList as ie, unref as N, mergeProps as we, createElementVNode as Ee, toDisplayString as Oe, createTextVNode as Ye } from "vue";
1
+ import { shallowRef as Xe, ref as _, toValue as l, watch as Te, onBeforeUnmount as Ce, computed as T, defineComponent as we, openBlock as V, createBlock as ce, resolveDynamicComponent as ue, normalizeStyle as W, withCtx as de, renderSlot as Z, createElementBlock as B, Fragment as ne, renderList as ie, unref as N, mergeProps as ve, createElementVNode as Ee, toDisplayString as Oe, createTextVNode as Ye } from "vue";
2
2
  function he(e) {
3
3
  return !Number.isFinite(e) || e < 0 ? 0 : e;
4
4
  }
@@ -170,18 +170,18 @@ class nt {
170
170
  const o = this.laneLength(r);
171
171
  if (o <= 0) continue;
172
172
  const d = Qe(o, t, (c) => {
173
- const v = this.ordinalIndex(r, c);
174
- return this.getItemOffset(v) + this.getItemSize(v);
173
+ const w = this.ordinalIndex(r, c);
174
+ return this.getItemOffset(w) + this.getItemSize(w);
175
175
  }), O = et(
176
176
  o,
177
177
  i,
178
178
  (c) => this.getItemOffset(this.ordinalIndex(r, c))
179
179
  ), E = Math.max(0, Math.min(d, O) - this.overscan), p = Math.min(o - 1, Math.max(d, O) + this.overscan);
180
180
  for (let c = E; c <= p; c += 1) {
181
- const v = this.ordinalIndex(r, c), k = this.getItemOffset(v), L = this.getItemSize(v);
181
+ const w = this.ordinalIndex(r, c), k = this.getItemOffset(w), L = this.getItemSize(w);
182
182
  n.push({
183
- index: v,
184
- key: this.getItemKey(v),
183
+ index: w,
184
+ key: this.getItemKey(w),
185
185
  start: k,
186
186
  size: L,
187
187
  end: k + L,
@@ -301,7 +301,7 @@ function dt(e, t) {
301
301
  }
302
302
  function ge(e) {
303
303
  const t = new nt(), i = Xe([]), n = _(0), r = _(0), o = _(0), d = _(!1), O = (s) => e.estimateSize(s);
304
- let E = null, p = !1, c = null, v = null, k = 0, L = 0, m = 0, b = l(e.revision), w = l(e.count), S = e.getItemKey?.(0) ?? 0, y = !1, h = "";
304
+ let E = null, p = !1, c = null, w = null, k = 0, L = 0, m = 0, b = l(e.revision), v = l(e.count), S = e.getItemKey?.(0) ?? 0, y = !1, h = "";
305
305
  const C = /* @__PURE__ */ new Map(), M = /* @__PURE__ */ new Map(), H = [];
306
306
  function Q() {
307
307
  const s = l(e.container);
@@ -370,7 +370,7 @@ function ge(e) {
370
370
  function F() {
371
371
  const s = l(e.revision);
372
372
  Object.is(s, b) || (b = s, t.clearMeasurements());
373
- const a = l(e.count), f = e.getItemKey?.(0) ?? 0, g = I() && w > 0 && a > w && f !== S, z = I() && w > 0 && a > w && f === S, R = g || z ? a - w : 0, K = I() && t.getViewportSize() > 0 && t.getScrollOffset() + t.getViewportSize() >= t.getTotalSize() - 64;
373
+ const a = l(e.count), f = e.getItemKey?.(0) ?? 0, g = I() && v > 0 && a > v && f !== S, z = I() && v > 0 && a > v && f === S, R = g || z ? a - v : 0, K = I() && t.getViewportSize() > 0 && t.getScrollOffset() + t.getViewportSize() >= t.getTotalSize() - 64;
374
374
  g && R > 0 && t.shiftMeasurements(R);
375
375
  const D = Q(), pe = ye(D), De = l(e.viewportInset) ?? 0, P = Math.max(0, (pe > 0 ? pe : x()) - De), Pe = l(e.itemSize);
376
376
  if (t.setOptions({
@@ -395,7 +395,7 @@ function ge(e) {
395
395
  let se = !1;
396
396
  I() && !y && G > 0 && P > 0 ? (y = !0, t.setScrollOffset(q), Y(D, q, G, P, "auto"), se = !0) : z && K ? (t.setScrollOffset(q), Y(D, q, G, P, "auto"), se = !0) : g && R > 0 && (Y(D, t.getScrollOffset(), G, P, "auto"), se = !0), !se && u() && D ? t.setScrollOffset(
397
397
  J(re(D, G, P), G, P)
398
- ) : t.getScrollOffset() > q && (t.setScrollOffset(q), Y(D, q, G, P, "auto")), w = a, S = f;
398
+ ) : t.getScrollOffset() > q && (t.setScrollOffset(q), Y(D, q, G, P, "auto")), v = a, S = f;
399
399
  const be = t.getVirtualItems();
400
400
  dt(i.value, be) || (i.value = be), n.value !== G && (n.value = G);
401
401
  const me = t.getScrollOffset();
@@ -438,7 +438,7 @@ function ge(e) {
438
438
  t.getScrollOffset() > 0 ? Y(s, t.getScrollOffset(), g, f, "auto") : t.setScrollOffset(re(s, g, f)), s.addEventListener("scroll", A, { passive: !0 }), typeof ResizeObserver < "u" && (c = new ResizeObserver(() => F()), c.observe(s));
439
439
  }
440
440
  function Ge() {
441
- return !U() || typeof ResizeObserver > "u" ? null : (v || (v = new ResizeObserver((s) => {
441
+ return !U() || typeof ResizeObserver > "u" ? null : (w || (w = new ResizeObserver((s) => {
442
442
  const a = $();
443
443
  let f = !1;
444
444
  if (!d.value) {
@@ -452,7 +452,7 @@ function ge(e) {
452
452
  }
453
453
  f && F();
454
454
  }
455
- })), v);
455
+ })), w);
456
456
  }
457
457
  function ze() {
458
458
  if (k = 0, d.value) return;
@@ -504,7 +504,7 @@ function ge(e) {
504
504
  },
505
505
  { flush: "post", immediate: !0 }
506
506
  ), Ce(() => {
507
- fe(), v?.disconnect(), ut(k), typeof window < "u" && window.clearTimeout(L), C.clear(), M.clear(), H.length = 0;
507
+ fe(), w?.disconnect(), ut(k), typeof window < "u" && window.clearTimeout(L), C.clear(), M.clear(), H.length = 0;
508
508
  }), {
509
509
  virtualItems: T(() => i.value),
510
510
  totalSize: T(() => n.value),
@@ -606,13 +606,13 @@ function mt(e) {
606
606
  windowScroll: e.windowScroll,
607
607
  scrollMargin: e.scrollMargin
608
608
  }), d = T(() => {
609
- const m = l(e.items), b = t.value, w = [];
609
+ const m = l(e.items), b = t.value, v = [];
610
610
  for (const S of r.virtualItems.value)
611
611
  for (const y of o.virtualItems.value) {
612
612
  const h = S.index * b + y.index;
613
613
  if (h >= m.length) continue;
614
614
  const C = m[h];
615
- w.push({
615
+ v.push({
616
616
  index: h,
617
617
  key: e.getItemKey?.(C, h) ?? h,
618
618
  item: C,
@@ -620,42 +620,42 @@ function mt(e) {
620
620
  column: y
621
621
  });
622
622
  }
623
- return w;
623
+ return v;
624
624
  });
625
625
  function O(m, b) {
626
- const w = l(e.items);
627
- if (!w.length) return;
628
- const S = Math.min(Math.max(m, 0), w.length - 1), y = t.value;
626
+ const v = l(e.items);
627
+ if (!v.length) return;
628
+ const S = Math.min(Math.max(m, 0), v.length - 1), y = t.value;
629
629
  r.scrollToIndex(Math.floor(S / y), b), o.scrollToIndex(S % y, b);
630
630
  }
631
631
  function E(m, b = "auto") {
632
632
  m.top !== void 0 && r.scrollToOffset(m.top, b), m.left !== void 0 && o.scrollToOffset(m.left, b);
633
633
  }
634
634
  function p(m, b) {
635
- const w = Math.max(n.get(m) ?? 0, b);
636
- w <= 0 || w === n.get(m) || (n.set(m, w), r.measure(m, w));
635
+ const v = Math.max(n.get(m) ?? 0, b);
636
+ v <= 0 || v === n.get(m) || (n.set(m, v), r.measure(m, v));
637
637
  }
638
638
  let c = null;
639
- const v = /* @__PURE__ */ new Map();
639
+ const w = /* @__PURE__ */ new Map();
640
640
  function k() {
641
641
  return !U() || typeof ResizeObserver > "u" ? null : (c || (c = new ResizeObserver((m) => {
642
642
  for (const b of m) {
643
- const w = v.get(b.target);
644
- if (w === void 0) continue;
643
+ const v = w.get(b.target);
644
+ if (v === void 0) continue;
645
645
  const y = b.borderBoxSize?.[0]?.blockSize ?? b.contentRect.height;
646
- y > 0 && p(w, y);
646
+ y > 0 && p(v, y);
647
647
  }
648
648
  })), c);
649
649
  }
650
650
  function L(m, b) {
651
- const w = Ve(m), S = k();
652
- if (!w) return;
653
- v.set(w, b), S?.observe(w);
654
- const y = w.getBoundingClientRect().height;
651
+ const v = Ve(m), S = k();
652
+ if (!v) return;
653
+ w.set(v, b), S?.observe(v);
654
+ const y = v.getBoundingClientRect().height;
655
655
  y > 0 && p(b, y);
656
656
  }
657
657
  return Ce(() => {
658
- c?.disconnect(), v.clear();
658
+ c?.disconnect(), w.clear();
659
659
  }), {
660
660
  virtualRows: r.virtualItems,
661
661
  virtualColumns: o.virtualItems,
@@ -691,15 +691,15 @@ function ht(e) {
691
691
  const o = l(e.columns);
692
692
  let d = 0;
693
693
  const O = o.map((c) => {
694
- const v = c.width ?? c.minWidth ?? 160, k = {
694
+ const w = c.width ?? c.minWidth ?? 160, k = {
695
695
  ...c,
696
696
  start: d,
697
- size: v,
698
- end: d + v,
697
+ size: w,
698
+ end: d + w,
699
699
  pinOffset: 0,
700
700
  stickyStyle: {}
701
701
  };
702
- return d += v, k;
702
+ return d += w, k;
703
703
  });
704
704
  let E = 0;
705
705
  for (const c of O)
@@ -710,12 +710,12 @@ function ht(e) {
710
710
  }, E += c.size);
711
711
  let p = 0;
712
712
  for (let c = O.length - 1; c >= 0; c -= 1) {
713
- const v = O[c];
714
- !v || v.pin !== "end" || (v.pinOffset = p, v.stickyStyle = {
713
+ const w = O[c];
714
+ !w || w.pin !== "end" || (w.pinOffset = p, w.stickyStyle = {
715
715
  position: "sticky",
716
716
  right: `${p}px`,
717
717
  zIndex: 2
718
- }, p += v.size);
718
+ }, p += w.size);
719
719
  }
720
720
  return O;
721
721
  }), n = T(() => {
@@ -770,20 +770,27 @@ function gt(e, t) {
770
770
  height: t ? "100%" : `${i}px`
771
771
  };
772
772
  }
773
- function vt(e, t, i) {
774
- return {
773
+ function wt(e, t, i, n) {
774
+ const r = n?.fixed ?? !1;
775
+ return t ? {
775
776
  position: "absolute",
776
777
  top: 0,
777
778
  left: 0,
778
- width: t ? i === void 0 ? void 0 : `${i}px` : "100%",
779
- height: t ? "100%" : i === void 0 ? void 0 : `${i}px`,
780
- transform: t ? `translateX(${e}px)` : `translateY(${e}px)`,
781
- contain: "layout style",
779
+ height: "100%",
780
+ transform: `translateX(${e}px)`,
782
781
  boxSizing: "border-box",
783
- overflow: "hidden"
782
+ ...r && i !== void 0 ? { width: `${i}px`, overflow: "hidden", contain: "layout style" } : {}
783
+ } : {
784
+ position: "absolute",
785
+ top: 0,
786
+ left: 0,
787
+ width: "100%",
788
+ transform: `translateY(${e}px)`,
789
+ boxSizing: "border-box",
790
+ ...r && i !== void 0 ? { height: `${i}px`, overflow: "hidden", contain: "layout style" } : {}
784
791
  };
785
792
  }
786
- const zt = /* @__PURE__ */ ve({
793
+ const zt = /* @__PURE__ */ we({
787
794
  __name: "VirtualList",
788
795
  props: {
789
796
  items: {},
@@ -806,7 +813,7 @@ const zt = /* @__PURE__ */ ve({
806
813
  },
807
814
  emits: ["visibleRangeChange", "scrollEnd"],
808
815
  setup(e, { expose: t, emit: i }) {
809
- const n = e, r = i, o = _(null), { virtualItems: d, totalSize: O, scrollAdjust: E, scrollToIndex: p, scrollToOffset: c, measure: v, measureElement: k } = $e({
816
+ const n = e, r = i, o = _(null), { virtualItems: d, totalSize: O, scrollAdjust: E, scrollToIndex: p, scrollToOffset: c, measure: w, measureElement: k } = $e({
810
817
  items: () => n.items,
811
818
  estimateSize: (S, y) => {
812
819
  const h = n.estimateSize;
@@ -839,9 +846,11 @@ const zt = /* @__PURE__ */ ve({
839
846
  })
840
847
  ), m = T(() => gt(O.value, n.horizontal));
841
848
  function b(S, y) {
842
- return vt(S, n.horizontal, y);
849
+ return wt(S, n.horizontal, y, {
850
+ fixed: typeof n.estimateSize == "number"
851
+ });
843
852
  }
844
- function w(S) {
853
+ function v(S) {
845
854
  return (y) => {
846
855
  k(y, S);
847
856
  };
@@ -849,7 +858,7 @@ const zt = /* @__PURE__ */ ve({
849
858
  return t({
850
859
  scrollToIndex: p,
851
860
  scrollToOffset: c,
852
- measure: v
861
+ measure: w
853
862
  }), (S, y) => (V(), ce(ue(e.tag), {
854
863
  ref_key: "container",
855
864
  ref: o,
@@ -863,10 +872,10 @@ const zt = /* @__PURE__ */ ve({
863
872
  "data-virtual-spacer": "",
864
873
  style: W(m.value)
865
874
  }, [
866
- (V(!0), B(ne, null, ie(N(d), (h) => (V(), ce(ue(e.itemTag), we({
875
+ (V(!0), B(ne, null, ie(N(d), (h) => (V(), ce(ue(e.itemTag), ve({
867
876
  key: h.key,
868
877
  ref_for: !0,
869
- ref: w(h.index),
878
+ ref: v(h.index),
870
879
  role: "listitem",
871
880
  "data-index": h.index,
872
881
  "data-key": String(h.key),
@@ -890,7 +899,7 @@ const zt = /* @__PURE__ */ ve({
890
899
  _: 3
891
900
  }, 8, ["style"]));
892
901
  }
893
- }), wt = ["data-index", "data-key"], xt = /* @__PURE__ */ ve({
902
+ }), vt = ["data-index", "data-key"], xt = /* @__PURE__ */ we({
894
903
  __name: "VirtualGrid",
895
904
  props: {
896
905
  items: {},
@@ -919,7 +928,7 @@ const zt = /* @__PURE__ */ ve({
919
928
  totalHeight: E,
920
929
  scrollAdjustX: p,
921
930
  scrollAdjustY: c,
922
- scrollToIndex: v,
931
+ scrollToIndex: w,
923
932
  scrollToOffset: k,
924
933
  measureRow: L,
925
934
  measureRowElement: m
@@ -951,7 +960,7 @@ const zt = /* @__PURE__ */ ve({
951
960
  horizontal: !1,
952
961
  windowScroll: n.windowScroll
953
962
  })
954
- ), w = T(() => ({
963
+ ), v = T(() => ({
955
964
  position: "relative",
956
965
  width: `${X(O.value)}px`,
957
966
  height: `${X(E.value)}px`
@@ -975,7 +984,7 @@ const zt = /* @__PURE__ */ ve({
975
984
  };
976
985
  }
977
986
  return t({
978
- scrollToIndex: v,
987
+ scrollToIndex: w,
979
988
  scrollToOffset: k,
980
989
  measureRow: L
981
990
  }), (h, C) => (V(), ce(ue(e.tag), {
@@ -989,9 +998,9 @@ const zt = /* @__PURE__ */ ve({
989
998
  e.items.length ? (V(), B("div", {
990
999
  key: 1,
991
1000
  "data-virtual-spacer": "",
992
- style: W(w.value)
1001
+ style: W(v.value)
993
1002
  }, [
994
- (V(!0), B(ne, null, ie(N(d), (M) => (V(), B("div", we({
1003
+ (V(!0), B(ne, null, ie(N(d), (M) => (V(), B("div", ve({
995
1004
  key: M.key,
996
1005
  ref_for: !0,
997
1006
  ref: S(M.row.index),
@@ -1008,13 +1017,13 @@ const zt = /* @__PURE__ */ ve({
1008
1017
  row: M.row,
1009
1018
  column: M.column
1010
1019
  })
1011
- ], 16, wt))), 128))
1020
+ ], 16, vt))), 128))
1012
1021
  ], 4)) : Z(h.$slots, "empty", {}, void 0, void 0, 0)
1013
1022
  ]),
1014
1023
  _: 3
1015
1024
  }, 8, ["style"]));
1016
1025
  }
1017
- }), St = ["data-index", "data-key", "aria-rowindex"], pt = /* @__PURE__ */ ve({
1026
+ }), St = ["data-index", "data-key", "aria-rowindex"], pt = /* @__PURE__ */ we({
1018
1027
  __name: "VirtualTable",
1019
1028
  props: {
1020
1029
  rows: {},
@@ -1038,12 +1047,12 @@ const zt = /* @__PURE__ */ ve({
1038
1047
  virtualRows: E,
1039
1048
  columns: p,
1040
1049
  totalWidth: c,
1041
- totalHeight: v,
1050
+ totalHeight: w,
1042
1051
  scrollAdjust: k,
1043
1052
  scrollToIndex: L,
1044
1053
  scrollToOffset: m,
1045
1054
  measure: b,
1046
- measureElement: w
1055
+ measureElement: v
1047
1056
  } = ht({
1048
1057
  rows: () => n.rows,
1049
1058
  columns: () => n.columns,
@@ -1091,7 +1100,7 @@ const zt = /* @__PURE__ */ ve({
1091
1100
  width: `${c.value}px`
1092
1101
  })), C = T(() => ({
1093
1102
  position: "relative",
1094
- height: `${X(v.value)}px`,
1103
+ height: `${X(w.value)}px`,
1095
1104
  width: `${X(c.value)}px`
1096
1105
  }));
1097
1106
  function M(u) {
@@ -1120,7 +1129,7 @@ const zt = /* @__PURE__ */ ve({
1120
1129
  }
1121
1130
  function Q(u) {
1122
1131
  return (I) => {
1123
- w(I, u);
1132
+ v(I, u);
1124
1133
  };
1125
1134
  }
1126
1135
  function $(u, I, x) {
@@ -1161,7 +1170,7 @@ const zt = /* @__PURE__ */ ve({
1161
1170
  role: "rowgroup",
1162
1171
  style: W(C.value)
1163
1172
  }, [
1164
- (V(!0), B(ne, null, ie(N(E), (x) => (V(), B("div", we({
1173
+ (V(!0), B(ne, null, ie(N(E), (x) => (V(), B("div", ve({
1165
1174
  key: x.key,
1166
1175
  ref_for: !0,
1167
1176
  ref: Q(x.index),