@yasanchezz/vue-infinite-grid 0.1.0 → 0.1.1

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