@yasanchezz/vue-infinite-grid 0.1.1 → 0.1.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.
package/dist/VueGrid.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  declare const __VLS_export: <GridRow extends {
2
- id: string | number;
2
+ id: string;
3
3
  }>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
4
4
  props: import('vue').PublicProps & __VLS_PrettifyLocal<{
5
+ autoCalculatedRowsCount?: boolean;
5
6
  container?: (Element | null | undefined) | ((container: Element | null) => Element | null | undefined);
6
7
  rows: GridRow[];
7
8
  rowsCount: number;
@@ -1,2 +1,2 @@
1
- .infinite-grid[data-v-30c741e3]{overflow-anchor:none;align-content:start;display:grid;overflow:clip}.grid-row[data-v-30c741e3]{grid-column:1/-1;grid-template-columns:subgrid;display:grid}.content[data-v-30c741e3]{display:contents}.before[data-v-30c741e3],.after[data-v-30c741e3]{pointer-events:none;grid-column:1/-1}
1
+ .infinite-grid[data-v-66ef5b12]{overflow-anchor:none;align-content:start;display:grid;overflow:clip}.grid-row[data-v-66ef5b12]{grid-column:1/-1;grid-template-columns:subgrid;display:grid}.content[data-v-66ef5b12]{display:contents}.before[data-v-66ef5b12],.after[data-v-66ef5b12]{pointer-events:none;grid-column:1/-1}
2
2
  /*$vite$:1*/
@@ -7,6 +7,10 @@ var g = ["data-index"], _ = /*#__PURE__*/ ((e, t) => {
7
7
  })(/* @__PURE__ */ i({
8
8
  __name: "VueGrid",
9
9
  props: {
10
+ autoCalculatedRowsCount: {
11
+ type: Boolean,
12
+ default: !1
13
+ },
10
14
  container: {
11
15
  type: [null, Function],
12
16
  default: document.documentElement
@@ -16,110 +20,117 @@ var g = ["data-index"], _ = /*#__PURE__*/ ((e, t) => {
16
20
  height: {}
17
21
  },
18
22
  setup(i, { expose: _ }) {
19
- let v = t(() => new Map(i.rows.map((e) => [String(e.id), e]))), y = f([]), b = p("grid"), x = p("content"), S = t(() => i.container instanceof Function ? i.container(b.value) ?? document.documentElement : i.container ?? document.documentElement), C = t(() => S.value === document.documentElement || S.value === document.body ? window : S.value), w = /* @__PURE__ */ new Map(), T = i.height * Math.trunc(i.rowsCount / 5) || 1e3, E, D = 0;
23
+ let v = f([]), y = p("grid"), b = p("content"), x = t(() => i.container instanceof Function ? i.container(y.value) ?? document.documentElement : i.container ?? document.documentElement), S = t(() => x.value === document.documentElement || x.value === document.body ? window : x.value), C = /* @__PURE__ */ new Map(), w = i.height * Math.trunc(i.rowsCount / 5) || 1e3, T, E, D = i.rowsCount;
20
24
  function O() {
21
- let e = 0, t = b.value;
22
- for (; t instanceof HTMLElement && t != S.value;) e += t.offsetTop, t = t.offsetParent;
23
- D = e;
25
+ if (i.autoCalculatedRowsCount) {
26
+ let e = window.innerHeight + i.height, t = P - w;
27
+ D = t < e ? Math.ceil(e / t * D) : D;
28
+ }
24
29
  }
25
- let k = l({ height: "0px" }), A = 0;
26
- function j() {
27
- return A = i.rows.map((e) => w.get(e) ?? i.height).reduce((e, t) => e + t, 0), k.value.height = `${A}px`, A;
30
+ let k = 0;
31
+ function A() {
32
+ let e = 0, t = y.value;
33
+ for (; t instanceof HTMLElement && t != x.value;) e += t.offsetTop, t = t.offsetParent;
34
+ k = e;
28
35
  }
29
- let M = 0;
36
+ let j = l({ height: "0px" }), M = 0;
30
37
  function N() {
31
- M = y.value.map((e) => w.get(e) ?? i.height).reduce((e, t) => e + t, 0);
38
+ return M = i.rows.map((e) => C.get(e.id) ?? i.height).reduce((e, t) => e + t, 0), j.value.height = `${M}px`, M;
32
39
  }
33
- let P = l({ height: "0px" }), F = 0;
34
- function I() {
35
- let e = S.value.scrollTop - T - D, t = 0;
40
+ let P = 0;
41
+ function F() {
42
+ P = v.value.map((e) => C.get(e.id) ?? i.height).reduce((e, t) => e + t, 0);
43
+ }
44
+ let I = l({ height: "0px" }), L = 0;
45
+ function R() {
46
+ let e = x.value.scrollTop - w - k, t = 0;
36
47
  for (let n of i.rows) {
37
- let r = w.get(n) ?? i.height;
48
+ let r = C.get(n.id) ?? i.height;
38
49
  if (t + r > e) break;
39
50
  t += r;
40
51
  }
41
- let n = A - M, r = t > n ? n : t;
42
- return F = r, P.value.height = `${r}px`, r;
52
+ let n = M - P, r = t > n ? n : t;
53
+ return L = r, I.value.height = `${r}px`, r;
43
54
  }
44
- let L = l({ height: "0px" }), R = 0;
45
- function z() {
46
- R = A - F - M, L.value.height = `${R}px`;
55
+ let z = l({ height: "0px" }), B = 0;
56
+ function V() {
57
+ B = M - L - P, z.value.height = `${B}px`;
47
58
  }
48
- function B() {
49
- cancelAnimationFrame(E), E = requestAnimationFrame(() => {
50
- O(), N(), j(), I(), z();
59
+ function H() {
60
+ cancelAnimationFrame(T), T = requestAnimationFrame(() => {
61
+ A(), F(), N(), R(), V();
51
62
  let e = 0, t = 0;
52
63
  for (let [n, r] of i.rows.entries()) {
53
- let a = w.get(r) ?? i.height;
54
- if (e += a, !(e <= F)) {
64
+ let a = C.get(r.id) ?? i.height;
65
+ if (e += a, !(e <= L)) {
55
66
  t = n;
56
67
  break;
57
68
  }
58
69
  }
59
- let n = t + i.rowsCount > i.rows.length ? i.rows.slice(i.rows.length - i.rowsCount) : i.rows.slice(t, t + i.rowsCount);
60
- R || (n = i.rows.slice(i.rows.length - i.rowsCount)), n.at(0) !== y.value.at(0) && (y.value = n), N(), j(), z();
70
+ let n = t + D > i.rows.length ? i.rows.slice(i.rows.length - D) : i.rows.slice(t, t + D);
71
+ B || (n = i.rows.slice(i.rows.length - D)), (n.at(0) !== v.value.at(0) || n.length !== v.value.length) && (v.value = n), F(), N(), V();
61
72
  });
62
73
  }
63
- let V = new ResizeObserver((e) => {
74
+ let U = new ResizeObserver((e) => {
64
75
  for (let t of e) {
65
76
  let e = t.target, n = t.borderBoxSize.at(0)?.blockSize ?? i.height;
66
77
  if (e instanceof HTMLElement) {
67
- let t = e.dataset.index, r = t == null ? void 0 : v.value.get(t);
68
- r && w.set(r, n);
78
+ let t = e.dataset.index;
79
+ t != null && C.set(t, n);
69
80
  }
70
81
  }
71
82
  cancelAnimationFrame(E), E = requestAnimationFrame(() => {
72
- N(), j(), z();
83
+ F(), O(), H();
73
84
  });
74
- }), H = new MutationObserver((e) => {
75
- for (let t of e) t.addedNodes.values().filter((e) => e instanceof HTMLElement).forEach((e) => V.observe(e)), t.removedNodes.values().filter((e) => e instanceof HTMLElement).forEach((e) => V.unobserve(e));
85
+ }), W = new MutationObserver((e) => {
86
+ for (let t of e) t.addedNodes.values().filter((e) => e instanceof HTMLElement).forEach((e) => U.observe(e)), t.removedNodes.values().filter((e) => e instanceof HTMLElement).forEach((e) => U.unobserve(e));
76
87
  });
77
88
  return h(() => {
78
- H.disconnect(), x.value && H.observe(x.value, { childList: !0 });
79
- }), m(() => i.rows, B, { flush: "post" }), m(C, (e, t) => {
80
- t?.removeEventListener("scroll", B), e.addEventListener("scroll", B, { passive: !0 });
89
+ W.disconnect(), b.value && W.observe(b.value, { childList: !0 });
90
+ }), m(() => i.rows, H, { flush: "post" }), m(S, (e, t) => {
91
+ t?.removeEventListener("scroll", H), e.addEventListener("scroll", H, { passive: !0 });
81
92
  }, { immediate: !0 }), o(() => {
82
- B();
93
+ H();
83
94
  }), s(() => {
84
- C.value.removeEventListener("scroll", B);
95
+ S.value.removeEventListener("scroll", H);
85
96
  }), _({
86
97
  init() {
87
- O(), N(), j(), I(), z();
98
+ A(), F(), N(), R(), V();
88
99
  },
89
100
  scrollTo(e) {
90
101
  let t = 0;
91
102
  for (let n of i.rows) {
92
103
  if (n.id === e) break;
93
- t += w.get(n) ?? i.height;
104
+ t += C.get(n.id) ?? i.height;
94
105
  }
95
- S.value.scrollTo(0, t + D);
106
+ x.value.scrollTo(0, t + k);
96
107
  }
97
108
  }), (t, i) => (c(), n("div", {
98
109
  ref_key: "grid",
99
- ref: b,
110
+ ref: y,
100
111
  class: "infinite-grid",
101
- style: a(k.value)
112
+ style: a(j.value)
102
113
  }, [
103
114
  r("div", {
104
115
  class: "before",
105
- style: a(P.value)
116
+ style: a(I.value)
106
117
  }, null, 4),
107
118
  r("div", {
108
119
  ref_key: "content",
109
- ref: x,
120
+ ref: b,
110
121
  class: "content"
111
- }, [(c(!0), n(e, null, u(y.value, (e) => (c(), n("div", {
122
+ }, [(c(!0), n(e, null, u(v.value, (e) => (c(), n("div", {
112
123
  key: e.id,
113
124
  class: "grid-row",
114
125
  "data-index": e.id
115
126
  }, [d(t.$slots, "row", { row: e }, void 0, !0)], 8, g))), 128))], 512),
116
127
  r("div", {
117
128
  class: "after",
118
- style: a(L.value)
129
+ style: a(z.value)
119
130
  }, null, 4)
120
131
  ], 4));
121
132
  }
122
- }), [["__scopeId", "data-v-30c741e3"]]), v = { install(e) {
133
+ }), [["__scopeId", "data-v-66ef5b12"]]), v = { install(e) {
123
134
  e.component("VueGrid", _);
124
135
  } };
125
136
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yasanchezz/vue-infinite-grid",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"