@yasanchezz/vue-infinite-grid 0.1.7 → 0.1.9

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
@@ -12,7 +12,7 @@ declare const __VLS_export: <GridRow extends {
12
12
  } ? P : {});
13
13
  expose: (exposed: import('vue').ShallowUnwrapRef<{
14
14
  init(): void;
15
- scrollTo(id: string): Promise<Element | null>;
15
+ scrollTo(id: string): Promise<HTMLElement>;
16
16
  }>) => void;
17
17
  attrs: any;
18
18
  slots: {
@@ -1,2 +1,2 @@
1
- .infinite-grid[data-v-581d3de4]{overflow-anchor:none;align-content:start;display:grid;overflow:clip}.grid-row[data-v-581d3de4]{grid-column:1/-1;grid-template-columns:subgrid;display:grid}.content[data-v-581d3de4]{display:contents}.before[data-v-581d3de4],.after[data-v-581d3de4]{pointer-events:none;grid-column:1/-1}
1
+ .infinite-grid[data-v-923e3f26]{overflow-anchor:none;align-content:start;display:grid;overflow:clip}.grid-row[data-v-923e3f26]{grid-column:1/-1;grid-template-columns:subgrid;display:grid}.content[data-v-923e3f26]{display:contents}.before[data-v-923e3f26],.after[data-v-923e3f26]{pointer-events:none;grid-column:1/-1}
2
2
  /*$vite$:1*/
@@ -1,6 +1,6 @@
1
- import { Fragment as e, computed as t, createElementBlock as n, createElementVNode as r, defineComponent as i, nextTick as a, normalizeStyle as o, onMounted as s, onUnmounted as c, openBlock as l, ref as u, renderList as d, renderSlot as f, shallowRef as p, useTemplateRef as m, watch as h, watchEffect as g } from "vue";
1
+ import { Fragment as e, computed as t, createElementBlock as n, createElementVNode as r, defineComponent as i, normalizeStyle as a, onMounted as o, onUnmounted as s, openBlock as c, ref as l, renderList as u, renderSlot as d, shallowRef as f, useTemplateRef as p, watch as m, watchEffect as h } from "vue";
2
2
  //#region src/VueGrid.vue?vue&type=script&setup=true&lang.ts
3
- var _ = ["data-index"], v = /*#__PURE__*/ ((e, t) => {
3
+ var g = ["data-index"], _ = /*#__PURE__*/ ((e, t) => {
4
4
  let n = e.__vccOpts || e;
5
5
  for (let [e, r] of t) n[e] = r;
6
6
  return n;
@@ -19,119 +19,129 @@ var _ = ["data-index"], v = /*#__PURE__*/ ((e, t) => {
19
19
  rowsCount: {},
20
20
  height: {}
21
21
  },
22
- setup(i, { expose: v }) {
23
- let y = p([]), b = m("grid"), x = m("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, O = i.rowsCount;
24
- function k() {
22
+ setup(i, { expose: _ }) {
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;
24
+ function O() {
25
25
  if (i.autoCalculatedRowsCount) {
26
- let e = window.innerHeight + i.height, t = F - T, n = t < e ? Math.ceil(e / t * O) : O;
27
- O = n < i.rowsCount ? i.rowsCount : n;
26
+ let e = window.innerHeight + i.height, t = P - w, n = t < e ? Math.ceil(e / t * D) : D;
27
+ D = n < i.rowsCount ? i.rowsCount : n;
28
28
  }
29
29
  }
30
- let A = 0;
31
- function j() {
32
- let e = 0, t = b.value;
33
- for (; t instanceof HTMLElement && t != S.value;) e += t.offsetTop, t = t.offsetParent;
34
- A = e;
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;
35
35
  }
36
- let M = u({ height: "0px" }), N = 0;
37
- function P() {
38
- return N = i.rows.map((e) => w.get(e.id) ?? i.height).reduce((e, t) => e + t, 0), M.value.height = `${N}px`, N;
36
+ let j = l({ height: "0px" }), M = 0;
37
+ function N() {
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;
39
39
  }
40
- let F = 0;
41
- function I() {
42
- F = y.value.map((e) => w.get(e.id) ?? i.height).reduce((e, t) => e + 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
43
  }
44
- let L = u({ height: "0px" }), R = 0;
45
- function z() {
46
- let e = S.value.scrollTop - T - A, t = 0;
44
+ let I = l({ height: "0px" }), L = 0;
45
+ function R() {
46
+ let e = x.value.scrollTop - w - k, t = 0;
47
47
  for (let n of i.rows) {
48
- let r = w.get(n.id) ?? i.height;
48
+ let r = C.get(n.id) ?? i.height;
49
49
  if (t + r > e) break;
50
50
  t += r;
51
51
  }
52
- let n = N - F, r = t > n ? n : t;
53
- return R = r, L.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;
54
54
  }
55
- let B = u({ height: "0px" }), V = 0;
56
- function H() {
57
- V = N - R - F, B.value.height = `${V}px`;
55
+ let z = l({ height: "0px" }), B = 0;
56
+ function V() {
57
+ B = M - L - P, z.value.height = `${B}px`;
58
58
  }
59
- function U() {
60
- cancelAnimationFrame(E), E = requestAnimationFrame(() => {
61
- j(), I(), P(), z(), H();
59
+ function H() {
60
+ cancelAnimationFrame(T), T = requestAnimationFrame(() => {
61
+ A(), F(), N(), R(), V();
62
62
  let e = 0, t = 0;
63
63
  for (let [n, r] of i.rows.entries()) {
64
- let a = w.get(r.id) ?? i.height;
65
- if (e += a, !(e <= R)) {
64
+ let a = C.get(r.id) ?? i.height;
65
+ if (e += a, !(e <= L)) {
66
66
  t = n;
67
67
  break;
68
68
  }
69
69
  }
70
- let n = t + O > i.rows.length ? i.rows.slice(i.rows.length - O) : i.rows.slice(t, t + O);
71
- V || (n = i.rows.slice(i.rows.length - O)), (n.at(0) !== y.value.at(0) || n.length !== y.value.length) && (y.value = n), I(), P(), H();
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();
72
72
  });
73
73
  }
74
- let W = new ResizeObserver((e) => {
74
+ let U = new ResizeObserver((e) => {
75
75
  for (let t of e) {
76
76
  let e = t.target, n = t.borderBoxSize.at(0)?.blockSize ?? i.height;
77
77
  if (e instanceof HTMLElement) {
78
78
  let t = e.dataset.index;
79
- t != null && w.set(t, n);
79
+ t != null && C.set(t, n);
80
80
  }
81
81
  }
82
- cancelAnimationFrame(D), D = requestAnimationFrame(() => {
83
- I(), k(), U();
82
+ cancelAnimationFrame(E), E = requestAnimationFrame(() => {
83
+ F(), O(), H();
84
84
  });
85
- }), G = new MutationObserver((e) => {
86
- for (let t of e) t.addedNodes.values().filter((e) => e instanceof HTMLElement).forEach((e) => W.observe(e)), t.removedNodes.values().filter((e) => e instanceof HTMLElement).forEach((e) => W.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));
87
87
  });
88
- return g(() => {
89
- G.disconnect(), x.value && G.observe(x.value, { childList: !0 });
90
- }), h(() => i.rows, U, { flush: "post" }), h(C, (e, t) => {
91
- t?.removeEventListener("scroll", U), e.addEventListener("scroll", U, { passive: !0 });
92
- }, { immediate: !0 }), s(() => {
93
- U();
94
- }), c(() => {
95
- C.value.removeEventListener("scroll", U);
96
- }), v({
88
+ return h(() => {
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 });
92
+ }, { immediate: !0 }), o(() => {
93
+ H();
94
+ }), s(() => {
95
+ S.value.removeEventListener("scroll", H);
96
+ }), _({
97
97
  init() {
98
- I(), k(), U();
98
+ F(), O(), H();
99
99
  },
100
100
  async scrollTo(e) {
101
101
  let t = 0;
102
102
  for (let n of i.rows) {
103
103
  if (n.id === e) break;
104
- t += w.get(n.id) ?? i.height;
104
+ t += C.get(n.id) ?? i.height;
105
105
  }
106
- return S.value.scrollTo(0, t + A), await a(), S.value.querySelector(`[data-index="${e}"]`);
106
+ return x.value.scrollTo(0, t + k), new Promise((t) => {
107
+ let n = x.value.querySelector(`[data-index="${e}"]`);
108
+ if (n instanceof HTMLElement) return t(n);
109
+ let r = new MutationObserver((n) => {
110
+ let i = n.flatMap((e) => Array.from(e.addedNodes)).filter((e) => e instanceof HTMLElement).find((t) => t.dataset.index === e);
111
+ i && (t(i), r.disconnect());
112
+ });
113
+ h(() => {
114
+ r.disconnect(), b.value && r.observe(b.value, { childList: !0 });
115
+ }), s(() => r.disconnect());
116
+ });
107
117
  }
108
- }), (t, i) => (l(), n("div", {
118
+ }), (t, i) => (c(), n("div", {
109
119
  ref_key: "grid",
110
- ref: b,
120
+ ref: y,
111
121
  class: "infinite-grid",
112
- style: o(M.value)
122
+ style: a(j.value)
113
123
  }, [
114
124
  r("div", {
115
125
  class: "before",
116
- style: o(L.value)
126
+ style: a(I.value)
117
127
  }, null, 4),
118
128
  r("div", {
119
129
  ref_key: "content",
120
- ref: x,
130
+ ref: b,
121
131
  class: "content"
122
- }, [(l(!0), n(e, null, d(y.value, (e) => (l(), n("div", {
132
+ }, [(c(!0), n(e, null, u(v.value, (e) => (c(), n("div", {
123
133
  key: e.id,
124
134
  class: "grid-row",
125
135
  "data-index": e.id
126
- }, [f(t.$slots, "row", { row: e }, void 0, !0)], 8, _))), 128))], 512),
136
+ }, [d(t.$slots, "row", { row: e }, void 0, !0)], 8, g))), 128))], 512),
127
137
  r("div", {
128
138
  class: "after",
129
- style: o(B.value)
139
+ style: a(z.value)
130
140
  }, null, 4)
131
141
  ], 4));
132
142
  }
133
- }), [["__scopeId", "data-v-581d3de4"]]), y = { install(e) {
134
- e.component("VueGrid", v);
143
+ }), [["__scopeId", "data-v-923e3f26"]]), v = { install(e) {
144
+ e.component("VueGrid", _);
135
145
  } };
136
146
  //#endregion
137
- export { y as default };
147
+ export { v as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yasanchezz/vue-infinite-grid",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"