@yasanchezz/vue-infinite-grid 0.2.3 → 0.2.4
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 -4
- package/dist/types.d.ts +4 -0
- package/dist/utils.d.ts +2 -0
- package/dist/vue-infinite-grid.css +1 -1
- package/dist/vue-infinite-grid.js +125 -102
- package/package.json +1 -1
package/dist/VueGrid.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
sticky?: boolean;
|
|
4
|
-
}>(__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<{
|
|
1
|
+
import { TableRow } from './types';
|
|
2
|
+
declare const __VLS_export: <GridRow extends TableRow>(__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<{
|
|
5
3
|
props: import('vue').PublicProps & __VLS_PrettifyLocal<{
|
|
6
4
|
container?: (Element | null | undefined) | ((container: Element | null) => Element | null | undefined);
|
|
7
5
|
rowInitialHeight: number;
|
package/dist/types.d.ts
ADDED
package/dist/utils.d.ts
ADDED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
@layer VueGrid{.infinite-grid[data-v-
|
|
1
|
+
@layer VueGrid{.infinite-grid[data-v-d94c77db]{overflow-anchor:none;align-content:start;width:max-content;display:grid;overflow:clip}.grid-row[data-v-d94c77db]{grid-column:1/-1;grid-template-columns:subgrid;display:grid}.grid-row--sticky[data-v-d94c77db]{position:sticky;top:0}.content[data-v-d94c77db]{display:contents}.before[data-v-d94c77db],.after[data-v-d94c77db]{pointer-events:none;grid-column:1/-1}}
|
|
2
2
|
/*$vite$:1*/
|
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
import { Fragment as e, computed as t, createElementBlock as n, createElementVNode as r, defineComponent as i, normalizeClass as a, normalizeStyle as o, onMounted as s, onUnmounted as
|
|
1
|
+
import { Fragment as e, computed as t, createElementBlock as n, createElementVNode as r, defineComponent as i, normalizeClass as a, normalizeStyle as o, onMounted as s, onUnmounted as ee, openBlock as c, ref as l, renderList as te, renderSlot as ne, shallowRef as re, useTemplateRef as u, watch as d, watchEffect as f } from "vue";
|
|
2
|
+
//#region src/utils.ts
|
|
3
|
+
function ie(e, t) {
|
|
4
|
+
let n = 0, r = e.length;
|
|
5
|
+
for (; n < r;) {
|
|
6
|
+
let i = n + r >>> 1;
|
|
7
|
+
e[i] < t ? n = i + 1 : r = i;
|
|
8
|
+
}
|
|
9
|
+
return n;
|
|
10
|
+
}
|
|
11
|
+
function ae(e, t) {
|
|
12
|
+
if (e.length !== t.length) return !1;
|
|
13
|
+
for (let [n, r] of e.entries()) if (r !== t[n]) return !1;
|
|
14
|
+
return !0;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
2
17
|
//#region src/VueGrid.vue?vue&type=script&setup=true&lang.ts
|
|
3
|
-
var
|
|
18
|
+
var p = ["data-index"], m = /*#__PURE__*/ ((e, t) => {
|
|
4
19
|
let n = e.__vccOpts || e;
|
|
5
20
|
for (let [e, r] of t) n[e] = r;
|
|
6
21
|
return n;
|
|
@@ -20,163 +35,171 @@ var h = ["data-index"], g = /*#__PURE__*/ ((e, t) => {
|
|
|
20
35
|
},
|
|
21
36
|
rowsOffset: { default: 0 }
|
|
22
37
|
},
|
|
23
|
-
setup(i, { expose:
|
|
24
|
-
let
|
|
25
|
-
function
|
|
26
|
-
|
|
38
|
+
setup(i, { expose: m }) {
|
|
39
|
+
let h = re([]), g = u("grid"), _ = u("content"), v = t(() => i.rows.map((e, t) => e.sticky ? t : void 0).filter((e) => e != null)), y = t(() => i.container instanceof Function ? i.container(g.value) ?? document.documentElement : i.container ?? document.documentElement), b = t(() => y.value === document.documentElement || y.value === document.body ? window : y.value), x = /* @__PURE__ */ new Map(), S = i.rowsOffset || i.rowInitialHeight * Math.trunc(i.rowsCount / 5) || 1e3, C, w, T = /* @__PURE__ */ new Map();
|
|
40
|
+
function E() {
|
|
41
|
+
T = new Map(i.rows.map((e, t) => [e.id, t]));
|
|
27
42
|
}
|
|
28
|
-
let
|
|
29
|
-
function
|
|
30
|
-
|
|
43
|
+
let D = new Float32Array(i.rows.length);
|
|
44
|
+
function O() {
|
|
45
|
+
D = new Float32Array(i.rows.map((e) => x.get(e.id) ?? i.rowInitialHeight));
|
|
31
46
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
let n =
|
|
35
|
-
n != null && (
|
|
47
|
+
function oe(e, t) {
|
|
48
|
+
x.set(e, t);
|
|
49
|
+
let n = T.get(e);
|
|
50
|
+
n != null && (D[n] = t);
|
|
36
51
|
}
|
|
37
|
-
function
|
|
38
|
-
return
|
|
52
|
+
function k(e) {
|
|
53
|
+
return D.at(e) ?? i.rowInitialHeight;
|
|
39
54
|
}
|
|
40
|
-
let
|
|
41
|
-
function
|
|
55
|
+
let A = i.rowsCount;
|
|
56
|
+
function j() {
|
|
42
57
|
if (i.rowsCountAutoCalculated) {
|
|
43
|
-
let e = window.innerHeight + i.rowInitialHeight, t =
|
|
44
|
-
|
|
58
|
+
let e = window.innerHeight + i.rowInitialHeight, t = L - S, n = t < e ? Math.ceil(e / t * A) : A;
|
|
59
|
+
A = Number.isFinite(n) && n >= i.rowsCount ? n : i.rowsCount;
|
|
45
60
|
}
|
|
46
61
|
}
|
|
47
|
-
let
|
|
48
|
-
function
|
|
49
|
-
let e = 0, t =
|
|
50
|
-
for (; t instanceof HTMLElement && t !=
|
|
51
|
-
|
|
62
|
+
let M = 0;
|
|
63
|
+
function N() {
|
|
64
|
+
let e = 0, t = g.value;
|
|
65
|
+
for (; t instanceof HTMLElement && t != y.value;) e += t.offsetTop, t = t.offsetParent;
|
|
66
|
+
M = e;
|
|
52
67
|
}
|
|
53
|
-
let
|
|
54
|
-
function
|
|
55
|
-
|
|
68
|
+
let P = l({ height: "0px" }), F = 0;
|
|
69
|
+
function I() {
|
|
70
|
+
F = D.reduce((e, t) => e + t, 0), P.value.height = `${F}px`;
|
|
56
71
|
}
|
|
57
|
-
let
|
|
58
|
-
function
|
|
59
|
-
|
|
72
|
+
let L = 0, R = 0, z = A;
|
|
73
|
+
function B() {
|
|
74
|
+
L = D.slice(R, z).reduce((e, t) => e + t, 0);
|
|
60
75
|
}
|
|
61
|
-
let
|
|
62
|
-
function
|
|
63
|
-
let e =
|
|
76
|
+
let V = l({ height: "0px" }), H = 0;
|
|
77
|
+
function U() {
|
|
78
|
+
let e = y.value.scrollTop - S - M, t = 0;
|
|
64
79
|
for (let n of i.rows.keys()) {
|
|
65
|
-
let r =
|
|
80
|
+
let r = k(n);
|
|
66
81
|
if (t + r > e) break;
|
|
67
82
|
t += r;
|
|
68
83
|
}
|
|
69
|
-
let n =
|
|
70
|
-
|
|
84
|
+
let n = F - L;
|
|
85
|
+
H = t > n ? n : t;
|
|
71
86
|
}
|
|
72
|
-
let
|
|
73
|
-
function
|
|
74
|
-
let e =
|
|
75
|
-
e = e < 0 ? 0 : e,
|
|
87
|
+
let W = 0;
|
|
88
|
+
function G() {
|
|
89
|
+
let e = H - W;
|
|
90
|
+
e = e < 0 ? 0 : e, V.value.height = `${e}px`;
|
|
76
91
|
}
|
|
77
|
-
let
|
|
78
|
-
function
|
|
79
|
-
|
|
92
|
+
let K = l({ height: "0px" }), q = 0;
|
|
93
|
+
function J() {
|
|
94
|
+
q = F - H - L, K.value.height = `${q}px`;
|
|
80
95
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
83
|
-
let e = 0, t = 0
|
|
84
|
-
for (let
|
|
85
|
-
let
|
|
86
|
-
if (e +=
|
|
87
|
-
t =
|
|
96
|
+
function se() {
|
|
97
|
+
N(), B(), I(), U(), G(), J();
|
|
98
|
+
let e = 0, t = 0;
|
|
99
|
+
for (let n of i.rows.keys()) {
|
|
100
|
+
let r = k(n);
|
|
101
|
+
if (e += r, e > H) {
|
|
102
|
+
t = n;
|
|
88
103
|
break;
|
|
89
104
|
}
|
|
90
|
-
o.sticky && (n = o, r = a, K = i);
|
|
91
105
|
}
|
|
92
|
-
[
|
|
93
|
-
let
|
|
94
|
-
|
|
106
|
+
[R, z] = t + A > i.rows.length || !q ? [i.rows.length - A, i.rows.length] : [t, t + A], R < 0 && (R = 0);
|
|
107
|
+
let n = ie(v.value, R), r = v.value.slice(0, n), a = r.map((e) => i.rows.at(e)).filter((e) => e != null);
|
|
108
|
+
W = r.reduce((e, t) => e + k(t), 0);
|
|
109
|
+
let o = i.rows.slice(R, z), s = a.concat(o);
|
|
110
|
+
ae(s, h.value) || (h.value = s), B(), I(), U(), G(), J();
|
|
95
111
|
}
|
|
96
|
-
function
|
|
97
|
-
cancelAnimationFrame(
|
|
112
|
+
function Y() {
|
|
113
|
+
cancelAnimationFrame(C), C = requestAnimationFrame(se);
|
|
98
114
|
}
|
|
99
|
-
let
|
|
115
|
+
let X = new ResizeObserver((e) => {
|
|
100
116
|
for (let t of e) {
|
|
101
117
|
let e = t.target, n = t.borderBoxSize.at(0)?.blockSize ?? i.rowInitialHeight;
|
|
102
118
|
if (e instanceof HTMLElement) {
|
|
103
119
|
let t = e.dataset.index;
|
|
104
|
-
t != null &&
|
|
120
|
+
t != null && oe(t, n);
|
|
105
121
|
}
|
|
106
122
|
}
|
|
107
|
-
cancelAnimationFrame(
|
|
108
|
-
|
|
123
|
+
cancelAnimationFrame(w), w = requestAnimationFrame(() => {
|
|
124
|
+
B(), j(), Y();
|
|
109
125
|
});
|
|
110
|
-
}),
|
|
111
|
-
for (let t of e) t.addedNodes.values().filter((e) => e instanceof HTMLElement).forEach((e) =>
|
|
126
|
+
}), Z = new MutationObserver((e) => {
|
|
127
|
+
for (let t of e) t.addedNodes.values().filter((e) => e instanceof HTMLElement).forEach((e) => X.observe(e)), t.removedNodes.values().filter((e) => e instanceof HTMLElement).forEach((e) => X.unobserve(e));
|
|
112
128
|
});
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}),
|
|
116
|
-
|
|
117
|
-
}, { flush: "post" }),
|
|
118
|
-
|
|
119
|
-
}, { immediate: !0 })
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
129
|
+
f(() => {
|
|
130
|
+
Z.disconnect(), _.value && Z.observe(_.value, { childList: !0 });
|
|
131
|
+
}), d(() => i.rows, () => {
|
|
132
|
+
E(), O(), Y();
|
|
133
|
+
}, { flush: "post" }), d(b, (e, t, n) => {
|
|
134
|
+
e.addEventListener("scroll", Y, { passive: !0 }), n(() => e.removeEventListener("scroll", Y));
|
|
135
|
+
}, { immediate: !0 });
|
|
136
|
+
let Q = /* @__PURE__ */ new Set();
|
|
137
|
+
function $(e) {
|
|
138
|
+
let t = _.value?.querySelector(`[data-index="${CSS.escape(e)}"]`);
|
|
139
|
+
return t instanceof HTMLElement ? t : null;
|
|
140
|
+
}
|
|
141
|
+
s(() => {
|
|
142
|
+
E(), O(), Y();
|
|
143
|
+
}), ee(() => {
|
|
144
|
+
cancelAnimationFrame(C), cancelAnimationFrame(w), X.disconnect(), Z.disconnect(), Q.forEach((e) => e()), x.clear(), T.clear(), D = /* @__PURE__ */ new Float32Array();
|
|
145
|
+
}), m({
|
|
124
146
|
init() {
|
|
125
|
-
|
|
147
|
+
B(), j(), Y();
|
|
126
148
|
},
|
|
127
149
|
async scrollTo(e) {
|
|
128
|
-
let t =
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
150
|
+
let t = T.get(e);
|
|
151
|
+
if (t == null) throw Error(`VueGrid: row with id "${e}" not found`);
|
|
152
|
+
let n = D.subarray(0, t).reduce((e, t) => e + t, 0);
|
|
153
|
+
return y.value.scrollTo(0, n + M), new Promise((t, n) => {
|
|
154
|
+
let r = $(e);
|
|
155
|
+
if (r) return t(r);
|
|
156
|
+
if (!_.value) return n(/* @__PURE__ */ Error("VueGrid: component is not mounted"));
|
|
157
|
+
let i = new MutationObserver(() => {
|
|
158
|
+
let n = $(e);
|
|
159
|
+
n && (a(), t(n));
|
|
160
|
+
}), a = () => {
|
|
161
|
+
i.disconnect(), Q.delete(o);
|
|
162
|
+
}, o = () => {
|
|
163
|
+
a(), n(/* @__PURE__ */ Error("VueGrid: component was unmounted before the row was rendered"));
|
|
164
|
+
};
|
|
165
|
+
Q.add(o), i.observe(_.value, { childList: !0 });
|
|
143
166
|
});
|
|
144
167
|
}
|
|
145
168
|
});
|
|
146
|
-
function
|
|
169
|
+
function ce(e) {
|
|
147
170
|
let t = "grid-row";
|
|
148
171
|
return {
|
|
149
172
|
[t]: !0,
|
|
150
173
|
[`${t}--sticky`]: e.sticky
|
|
151
174
|
};
|
|
152
175
|
}
|
|
153
|
-
return (t, i) => (
|
|
176
|
+
return (t, i) => (c(), n("div", {
|
|
154
177
|
ref_key: "grid",
|
|
155
|
-
ref:
|
|
178
|
+
ref: g,
|
|
156
179
|
class: "infinite-grid",
|
|
157
|
-
style: o(
|
|
180
|
+
style: o(P.value)
|
|
158
181
|
}, [
|
|
159
182
|
r("div", {
|
|
160
183
|
class: "before",
|
|
161
|
-
style: o(
|
|
184
|
+
style: o(V.value)
|
|
162
185
|
}, null, 4),
|
|
163
186
|
r("div", {
|
|
164
187
|
ref_key: "content",
|
|
165
|
-
ref:
|
|
188
|
+
ref: _,
|
|
166
189
|
class: "content"
|
|
167
|
-
}, [(
|
|
190
|
+
}, [(c(!0), n(e, null, te(h.value, (e) => (c(), n("div", {
|
|
168
191
|
key: e.id,
|
|
169
|
-
class: a(
|
|
192
|
+
class: a(ce(e)),
|
|
170
193
|
"data-index": e.id
|
|
171
|
-
}, [
|
|
194
|
+
}, [ne(t.$slots, "row", { row: e }, void 0, !0)], 10, p))), 128))], 512),
|
|
172
195
|
r("div", {
|
|
173
196
|
class: "after",
|
|
174
|
-
style: o(
|
|
197
|
+
style: o(K.value)
|
|
175
198
|
}, null, 4)
|
|
176
199
|
], 4));
|
|
177
200
|
}
|
|
178
|
-
}), [["__scopeId", "data-v-
|
|
179
|
-
e.component("VueGrid",
|
|
201
|
+
}), [["__scopeId", "data-v-d94c77db"]]), h = { install(e) {
|
|
202
|
+
e.component("VueGrid", m);
|
|
180
203
|
} };
|
|
181
204
|
//#endregion
|
|
182
|
-
export {
|
|
205
|
+
export { m as VueGrid, h as default };
|