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