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