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