@yasanchezz/vue-infinite-grid 0.1.6 → 0.1.8
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 +1 -1
- package/dist/vue-infinite-grid.css +1 -1
- package/dist/vue-infinite-grid.js +71 -63
- package/package.json +1 -1
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<
|
|
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-
|
|
1
|
+
.infinite-grid[data-v-81b89b0e]{overflow-anchor:none;align-content:start;display:grid;overflow:clip}.grid-row[data-v-81b89b0e]{grid-column:1/-1;grid-template-columns:subgrid;display:grid}.content[data-v-81b89b0e]{display:contents}.before[data-v-81b89b0e],.after[data-v-81b89b0e]{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,
|
|
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
|
|
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,127 @@ var _ = ["data-index"], v = /*#__PURE__*/ ((e, t) => {
|
|
|
19
19
|
rowsCount: {},
|
|
20
20
|
height: {}
|
|
21
21
|
},
|
|
22
|
-
setup(i, { expose:
|
|
23
|
-
let
|
|
24
|
-
function
|
|
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 =
|
|
27
|
-
|
|
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
|
|
31
|
-
function
|
|
32
|
-
let e = 0, t =
|
|
33
|
-
for (; t instanceof HTMLElement && t !=
|
|
34
|
-
|
|
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
|
|
37
|
-
function
|
|
38
|
-
return
|
|
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
|
|
41
|
-
function
|
|
42
|
-
|
|
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
|
|
45
|
-
function
|
|
46
|
-
let e =
|
|
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 =
|
|
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 =
|
|
53
|
-
return
|
|
52
|
+
let n = M - P, r = t > n ? n : t;
|
|
53
|
+
return L = r, I.value.height = `${r}px`, r;
|
|
54
54
|
}
|
|
55
|
-
let
|
|
56
|
-
function
|
|
57
|
-
|
|
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
|
|
60
|
-
cancelAnimationFrame(
|
|
61
|
-
|
|
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 =
|
|
65
|
-
if (e += a, !(e <=
|
|
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 +
|
|
71
|
-
|
|
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
|
|
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 &&
|
|
79
|
+
t != null && C.set(t, n);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
cancelAnimationFrame(
|
|
83
|
-
|
|
82
|
+
cancelAnimationFrame(E), E = requestAnimationFrame(() => {
|
|
83
|
+
F(), O(), H();
|
|
84
84
|
});
|
|
85
|
-
}),
|
|
86
|
-
for (let t of e) t.addedNodes.values().filter((e) => e instanceof HTMLElement).forEach((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
|
|
89
|
-
|
|
90
|
-
}),
|
|
91
|
-
t?.removeEventListener("scroll",
|
|
92
|
-
}, { immediate: !0 }),
|
|
93
|
-
|
|
94
|
-
}),
|
|
95
|
-
|
|
96
|
-
}),
|
|
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
|
-
|
|
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 +=
|
|
104
|
+
t += C.get(n.id) ?? i.height;
|
|
105
105
|
}
|
|
106
|
-
return
|
|
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
|
+
y.value && r.observe(y.value), s(() => r.disconnect());
|
|
114
|
+
});
|
|
107
115
|
}
|
|
108
|
-
}), (t, i) => (
|
|
116
|
+
}), (t, i) => (c(), n("div", {
|
|
109
117
|
ref_key: "grid",
|
|
110
|
-
ref:
|
|
118
|
+
ref: y,
|
|
111
119
|
class: "infinite-grid",
|
|
112
|
-
style:
|
|
120
|
+
style: a(j.value)
|
|
113
121
|
}, [
|
|
114
122
|
r("div", {
|
|
115
123
|
class: "before",
|
|
116
|
-
style:
|
|
124
|
+
style: a(I.value)
|
|
117
125
|
}, null, 4),
|
|
118
126
|
r("div", {
|
|
119
127
|
ref_key: "content",
|
|
120
|
-
ref:
|
|
128
|
+
ref: b,
|
|
121
129
|
class: "content"
|
|
122
|
-
}, [(
|
|
130
|
+
}, [(c(!0), n(e, null, u(v.value, (e) => (c(), n("div", {
|
|
123
131
|
key: e.id,
|
|
124
132
|
class: "grid-row",
|
|
125
133
|
"data-index": e.id
|
|
126
|
-
}, [
|
|
134
|
+
}, [d(t.$slots, "row", { row: e }, void 0, !0)], 8, g))), 128))], 512),
|
|
127
135
|
r("div", {
|
|
128
136
|
class: "after",
|
|
129
|
-
style:
|
|
137
|
+
style: a(z.value)
|
|
130
138
|
}, null, 4)
|
|
131
139
|
], 4));
|
|
132
140
|
}
|
|
133
|
-
}), [["__scopeId", "data-v-
|
|
134
|
-
e.component("VueGrid",
|
|
141
|
+
}), [["__scopeId", "data-v-81b89b0e"]]), v = { install(e) {
|
|
142
|
+
e.component("VueGrid", _);
|
|
135
143
|
} };
|
|
136
144
|
//#endregion
|
|
137
|
-
export {
|
|
145
|
+
export { v as default };
|