react-anchorlist 0.3.4 → 0.3.5
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/hooks/useChatVirtualizer.d.ts.map +1 -1
- package/dist/hooks/useVirtualEngine.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +404 -397
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { jsx as J, jsxs as
|
|
2
|
-
import * as
|
|
3
|
-
import { useRef as
|
|
4
|
-
class
|
|
1
|
+
import { jsx as J, jsxs as ae } from "react/jsx-runtime";
|
|
2
|
+
import * as oe from "react";
|
|
3
|
+
import { useRef as m, useCallback as k, useState as X, useEffect as $, useLayoutEffect as Z, forwardRef as ge, useImperativeHandle as ve } from "react";
|
|
4
|
+
class Te {
|
|
5
5
|
constructor(e, t) {
|
|
6
6
|
this.defaultSize = t, this.sizes = e > 0 ? Array(e).fill(t) : [], this.offsets = e > 0 ? Array(e).fill(0) : [], e > 0 && this._recalcFrom(0);
|
|
7
7
|
}
|
|
@@ -48,7 +48,7 @@ class ve {
|
|
|
48
48
|
return this.sizes;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
class
|
|
51
|
+
class ye {
|
|
52
52
|
constructor() {
|
|
53
53
|
this.cache = /* @__PURE__ */ new Map();
|
|
54
54
|
}
|
|
@@ -75,240 +75,241 @@ class Te {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
function
|
|
79
|
-
if (
|
|
80
|
-
let t = 0, s =
|
|
78
|
+
function ue(a, e) {
|
|
79
|
+
if (a.length === 0) return 0;
|
|
80
|
+
let t = 0, s = a.length - 1;
|
|
81
81
|
for (; t < s; ) {
|
|
82
82
|
const c = t + s >> 1;
|
|
83
|
-
(
|
|
83
|
+
(a[c] ?? 0) < e ? t = c + 1 : s = c;
|
|
84
84
|
}
|
|
85
|
-
return Math.max(0, t > 0 && (
|
|
85
|
+
return Math.max(0, t > 0 && (a[t] ?? 0) > e ? t - 1 : t);
|
|
86
86
|
}
|
|
87
|
-
function
|
|
88
|
-
if (
|
|
89
|
-
let s = 0, c =
|
|
87
|
+
function Se(a, e, t) {
|
|
88
|
+
if (a.length === 0) return 0;
|
|
89
|
+
let s = 0, c = a.length - 1, n = 0;
|
|
90
90
|
for (; s <= c; ) {
|
|
91
91
|
const r = s + c >> 1;
|
|
92
|
-
(
|
|
92
|
+
(a[r] ?? 0) < t ? (n = r, s = r + 1) : c = r - 1;
|
|
93
93
|
}
|
|
94
94
|
return n;
|
|
95
95
|
}
|
|
96
|
-
function Ae(
|
|
97
|
-
const { firstVisible: e, lastVisible: t, itemCount: s, overscan: c } =
|
|
96
|
+
function Ae(a) {
|
|
97
|
+
const { firstVisible: e, lastVisible: t, itemCount: s, overscan: c } = a;
|
|
98
98
|
return s === 0 ? { start: 0, end: -1 } : {
|
|
99
99
|
start: Math.max(0, e - c),
|
|
100
100
|
end: Math.min(s - 1, t + c)
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
-
function
|
|
104
|
-
const c = s == null ? void 0 : s.reconcile, n =
|
|
105
|
-
return
|
|
106
|
-
(r,
|
|
107
|
-
const l =
|
|
108
|
-
if (!l || !
|
|
103
|
+
function ze(a, e, t, s) {
|
|
104
|
+
const c = s == null ? void 0 : s.reconcile, n = m(null);
|
|
105
|
+
return k(
|
|
106
|
+
(r, y) => {
|
|
107
|
+
const l = a.current, h = e.current;
|
|
108
|
+
if (!l || !h) return;
|
|
109
109
|
n.current !== null && (cancelAnimationFrame(n.current), n.current = null);
|
|
110
|
-
let
|
|
111
|
-
if (typeof r == "object" && r !== null ? (
|
|
110
|
+
let v, f;
|
|
111
|
+
if (typeof r == "object" && r !== null ? (v = r.index, f = {
|
|
112
112
|
align: r.align,
|
|
113
113
|
behavior: r.behavior,
|
|
114
114
|
offset: r.offset
|
|
115
|
-
}) : (
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
const F = (
|
|
119
|
-
var
|
|
120
|
-
const H = e.current, u =
|
|
115
|
+
}) : (v = r, f = y), !Number.isFinite(v)) return;
|
|
116
|
+
const p = Math.max(0, Math.min(Math.floor(v), h.count - 1));
|
|
117
|
+
h.getOffset(p), h.getSize(p);
|
|
118
|
+
const F = (f == null ? void 0 : f.align) ?? "start", M = (f == null ? void 0 : f.behavior) ?? "auto", K = (f == null ? void 0 : f.offset) ?? 0, i = () => {
|
|
119
|
+
var B;
|
|
120
|
+
const H = e.current, u = a.current;
|
|
121
121
|
if (!H || !u) return 0;
|
|
122
|
-
const
|
|
123
|
-
return F === "start" ?
|
|
124
|
-
}, E =
|
|
122
|
+
const A = ((B = t == null ? void 0 : t.current) == null ? void 0 : B.offsetTop) ?? 0, T = H.getOffset(p), w = H.getSize(p);
|
|
123
|
+
return F === "start" ? A + T + K : F === "center" ? A + T - u.clientHeight / 2 + w / 2 + K : A + T - u.clientHeight + w + K;
|
|
124
|
+
}, E = i();
|
|
125
125
|
((H, u) => {
|
|
126
126
|
typeof l.scrollTo == "function" ? l.scrollTo({ top: H, behavior: u }) : l.scrollTop = H;
|
|
127
|
-
})(Math.max(0, E),
|
|
128
|
-
const
|
|
129
|
-
let
|
|
130
|
-
const
|
|
127
|
+
})(Math.max(0, E), M);
|
|
128
|
+
const b = performance.now();
|
|
129
|
+
let S = 0;
|
|
130
|
+
const C = 12, j = 300, U = 1, L = () => {
|
|
131
131
|
n.current = null;
|
|
132
|
-
const H =
|
|
132
|
+
const H = a.current;
|
|
133
133
|
if (!H) return;
|
|
134
|
-
const u = Math.max(0,
|
|
135
|
-
|
|
134
|
+
const u = Math.max(0, i()), A = Math.abs(H.scrollTop - u), T = performance.now() - b >= j, w = S >= C;
|
|
135
|
+
A <= U || T || w || (typeof H.scrollTo == "function" ? H.scrollTo({ top: u, behavior: "auto" }) : H.scrollTop = u, S += 1, n.current = requestAnimationFrame(L));
|
|
136
136
|
};
|
|
137
|
-
n.current = requestAnimationFrame(
|
|
137
|
+
n.current = requestAnimationFrame(L);
|
|
138
138
|
},
|
|
139
|
-
[
|
|
139
|
+
[a, e, t, c]
|
|
140
140
|
);
|
|
141
141
|
}
|
|
142
|
-
function
|
|
143
|
-
var
|
|
144
|
-
const { items: e, getKey: t, estimatedItemSize: s, overscan: c, initialAlignment: n } =
|
|
145
|
-
l.current || (l.current = new
|
|
146
|
-
const
|
|
147
|
-
if (e.length !==
|
|
148
|
-
const o = l.current, d = e.map((V,
|
|
149
|
-
if (
|
|
142
|
+
function fe(a) {
|
|
143
|
+
var ie;
|
|
144
|
+
const { items: e, getKey: t, estimatedItemSize: s, overscan: c, initialAlignment: n } = a, r = m(null), y = m(null), l = m(null), h = m(new ye()), v = m([]), f = m(/* @__PURE__ */ new Map()), p = m(e.length), F = m(null), M = m(null), K = m(!1), i = m(0), E = m(0), g = m(null), b = m(!1), S = m(null), C = m(0), j = m(0), U = m(0), L = m(null), H = m(!1), u = m(!1), [, A] = X(0), T = k(() => A((o) => o + 1), []);
|
|
145
|
+
l.current || (l.current = new Te(e.length, s));
|
|
146
|
+
const w = e.length > 0 ? t(e[0], 0) : null, B = e.length > 0 ? t(e[e.length - 1], e.length - 1) : null;
|
|
147
|
+
if (e.length !== p.current || w !== F.current || B !== M.current) {
|
|
148
|
+
const o = l.current, d = e.map((V, W) => t(V, W)), x = v.current, I = x.length, P = d.length;
|
|
149
|
+
if (P === 0)
|
|
150
150
|
o.resize(0);
|
|
151
151
|
else if (I === 0)
|
|
152
|
-
o.resize(
|
|
153
|
-
else if (
|
|
154
|
-
const V =
|
|
155
|
-
x.length > 0 && V >= 0 && d[V] === x[0] ? o.prepend(V) : o.resize(
|
|
156
|
-
} else
|
|
157
|
-
const
|
|
158
|
-
d.forEach((V,
|
|
152
|
+
o.resize(P);
|
|
153
|
+
else if (P > I) {
|
|
154
|
+
const V = P - I;
|
|
155
|
+
x.length > 0 && V >= 0 && d[V] === x[0] ? o.prepend(V) : o.resize(P);
|
|
156
|
+
} else P < I, o.resize(P);
|
|
157
|
+
const R = /* @__PURE__ */ new Map();
|
|
158
|
+
d.forEach((V, W) => R.set(V, W)), f.current = R, h.current.applyToOffsetMap(o, R), v.current = d, p.current = e.length, F.current = w, M.current = B;
|
|
159
159
|
}
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
const z = k(() => {
|
|
161
|
+
L.current === null && (L.current = requestAnimationFrame(() => {
|
|
162
|
+
L.current = null;
|
|
163
163
|
const o = r.current;
|
|
164
164
|
if (!o) return;
|
|
165
|
-
const d =
|
|
166
|
-
Math.abs(d) < 0.01 || (
|
|
165
|
+
const d = C.current;
|
|
166
|
+
Math.abs(d) < 0.01 || (C.current = 0, j.current += d, U.current += d, o.scrollTop += d, i.current = o.scrollTop, H.current = !0, T());
|
|
167
167
|
}));
|
|
168
|
-
}, [
|
|
169
|
-
|
|
168
|
+
}, [T]);
|
|
169
|
+
$(() => {
|
|
170
170
|
const o = r.current;
|
|
171
171
|
if (!o) return;
|
|
172
172
|
const d = () => {
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
g.current === null && (g.current = requestAnimationFrame(() => {
|
|
174
|
+
g.current = null, i.current = o.scrollTop, E.current = o.clientHeight, H.current && (H.current = !1, j.current = 0, U.current = 0), T();
|
|
175
175
|
}));
|
|
176
176
|
};
|
|
177
177
|
return o.addEventListener("scroll", d, { passive: !0 }), () => {
|
|
178
|
-
o.removeEventListener("scroll", d),
|
|
178
|
+
o.removeEventListener("scroll", d), g.current !== null && (cancelAnimationFrame(g.current), g.current = null), L.current !== null && (cancelAnimationFrame(L.current), L.current = null);
|
|
179
179
|
};
|
|
180
|
-
}, [
|
|
180
|
+
}, [T]), $(() => {
|
|
181
181
|
const o = r.current;
|
|
182
182
|
if (!o) return;
|
|
183
|
-
E.current = o.clientHeight,
|
|
183
|
+
E.current = o.clientHeight, i.current = o.scrollTop;
|
|
184
184
|
const d = new ResizeObserver(([x]) => {
|
|
185
|
-
x && (E.current = x.contentRect.height,
|
|
185
|
+
x && (E.current = x.contentRect.height, T());
|
|
186
186
|
});
|
|
187
187
|
return d.observe(o), () => d.disconnect();
|
|
188
|
-
}, [
|
|
189
|
-
if (
|
|
188
|
+
}, [T]), Z(() => {
|
|
189
|
+
if (K.current || e.length === 0) return;
|
|
190
190
|
const o = r.current;
|
|
191
191
|
if (o) {
|
|
192
192
|
if (n === "bottom") {
|
|
193
|
-
o.scrollTop = o.scrollHeight,
|
|
193
|
+
o.scrollTop = o.scrollHeight, i.current = o.scrollTop, E.current = o.clientHeight, b.current = !0, S.current !== null && cancelAnimationFrame(S.current);
|
|
194
194
|
const d = performance.now();
|
|
195
195
|
let x = 0, I = o.scrollHeight;
|
|
196
|
-
const
|
|
197
|
-
if (!
|
|
198
|
-
|
|
196
|
+
const P = () => {
|
|
197
|
+
if (!b.current) {
|
|
198
|
+
S.current = null;
|
|
199
199
|
return;
|
|
200
200
|
}
|
|
201
|
-
const
|
|
202
|
-
I =
|
|
203
|
-
const
|
|
204
|
-
if (x >= 3 ||
|
|
205
|
-
|
|
201
|
+
const R = o.scrollHeight, V = Math.abs(R - I);
|
|
202
|
+
I = R, V < 1 ? x += 1 : x = 0, o.scrollTop = o.scrollHeight, i.current = o.scrollTop;
|
|
203
|
+
const W = performance.now() - d;
|
|
204
|
+
if (x >= 3 || W >= 500) {
|
|
205
|
+
b.current = !1, S.current = null;
|
|
206
206
|
return;
|
|
207
207
|
}
|
|
208
|
-
|
|
208
|
+
S.current = requestAnimationFrame(P);
|
|
209
209
|
};
|
|
210
|
-
|
|
210
|
+
S.current = requestAnimationFrame(P);
|
|
211
211
|
}
|
|
212
|
-
|
|
212
|
+
K.current = !0;
|
|
213
213
|
}
|
|
214
|
-
}, [n, e.length]),
|
|
215
|
-
e.length === 0 && (
|
|
214
|
+
}, [n, e.length]), $(() => {
|
|
215
|
+
e.length === 0 && (K.current = !1, b.current = !1, S.current !== null && (cancelAnimationFrame(S.current), S.current = null));
|
|
216
216
|
}, [e.length]);
|
|
217
|
-
const
|
|
218
|
-
var
|
|
217
|
+
const O = k((o, d) => {
|
|
218
|
+
var Q;
|
|
219
219
|
const x = l.current;
|
|
220
|
-
if (!x ||
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
if (
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
}, [
|
|
220
|
+
if (!x || h.current.get(o) === d) return;
|
|
221
|
+
h.current.set(o, d);
|
|
222
|
+
const P = f.current.get(o);
|
|
223
|
+
if (P === void 0) return;
|
|
224
|
+
const R = x.getSize(P), V = d - R, W = r.current;
|
|
225
|
+
W && !b.current && !u.current && V !== 0 && x.getOffset(P) + R + (((Q = y.current) == null ? void 0 : Q.offsetTop) ?? 0) < W.scrollTop && (C.current += V, z()), x.setSize(P, d) && T();
|
|
226
|
+
}, [z, T]), N = k(
|
|
227
227
|
(o, d = "auto") => {
|
|
228
228
|
var x;
|
|
229
229
|
(x = r.current) == null || x.scrollTo({ top: o, behavior: d });
|
|
230
230
|
},
|
|
231
231
|
[]
|
|
232
|
-
), G =
|
|
232
|
+
), G = ze(r, l, y, {
|
|
233
233
|
reconcile: !0
|
|
234
|
-
}),
|
|
235
|
-
var
|
|
234
|
+
}), q = k(() => {
|
|
235
|
+
var ne;
|
|
236
236
|
const o = r.current, d = l.current;
|
|
237
237
|
if (!o || !d || d.count === 0) return null;
|
|
238
|
-
const x = ((
|
|
239
|
-
for (let
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
key:
|
|
243
|
-
offsetWithinItem: I - d.getOffset(
|
|
238
|
+
const x = ((ne = y.current) == null ? void 0 : ne.offsetTop) ?? 0, I = Math.max(0, o.scrollTop - x), P = d.getOffsets(), R = ue(P, I), V = v.current[R] ?? null, W = [];
|
|
239
|
+
for (let Q = R; Q < Math.min(d.count, R + 6); Q++) {
|
|
240
|
+
const se = v.current[Q] ?? null;
|
|
241
|
+
se !== null && W.push({
|
|
242
|
+
key: se,
|
|
243
|
+
offsetWithinItem: I - d.getOffset(Q)
|
|
244
244
|
});
|
|
245
245
|
}
|
|
246
246
|
return {
|
|
247
247
|
key: V,
|
|
248
|
-
offsetWithinItem: I - d.getOffset(
|
|
249
|
-
candidates:
|
|
248
|
+
offsetWithinItem: I - d.getOffset(R),
|
|
249
|
+
candidates: W,
|
|
250
250
|
scrollTop: o.scrollTop,
|
|
251
251
|
scrollHeight: o.scrollHeight
|
|
252
252
|
};
|
|
253
|
-
}, []),
|
|
253
|
+
}, []), ee = k(
|
|
254
254
|
(o, d) => {
|
|
255
|
-
var
|
|
255
|
+
var R;
|
|
256
256
|
const x = l.current;
|
|
257
257
|
if (!x) return null;
|
|
258
|
-
const I =
|
|
259
|
-
return I === void 0 ? null : (((
|
|
258
|
+
const I = f.current.get(o);
|
|
259
|
+
return I === void 0 ? null : (((R = y.current) == null ? void 0 : R.offsetTop) ?? 0) + x.getOffset(I) + d;
|
|
260
260
|
},
|
|
261
261
|
[]
|
|
262
|
-
),
|
|
263
|
-
if (
|
|
264
|
-
const o =
|
|
262
|
+
), _ = l.current, me = _ ? _.totalSize() : 0, Y = r.current, te = (Y == null ? void 0 : Y.scrollTop) ?? i.current, ce = (Y == null ? void 0 : Y.clientHeight) ?? E.current, de = ((ie = y.current) == null ? void 0 : ie.offsetTop) ?? 0, le = Math.max(0, te - de), re = [];
|
|
263
|
+
if (_ && _.count > 0 && ce > 0) {
|
|
264
|
+
const o = _.getOffsets(), d = _.getSizes(), x = ue(o, le), I = Se(
|
|
265
265
|
o,
|
|
266
266
|
d,
|
|
267
|
-
|
|
268
|
-
),
|
|
267
|
+
le + ce
|
|
268
|
+
), P = Ae({
|
|
269
269
|
firstVisible: x,
|
|
270
270
|
lastVisible: I,
|
|
271
|
-
itemCount:
|
|
271
|
+
itemCount: _.count,
|
|
272
272
|
overscan: c
|
|
273
273
|
});
|
|
274
|
-
for (let
|
|
275
|
-
|
|
276
|
-
key:
|
|
277
|
-
index:
|
|
278
|
-
start:
|
|
279
|
-
size:
|
|
280
|
-
data: e[
|
|
274
|
+
for (let R = P.start; R <= P.end && R < e.length; R++)
|
|
275
|
+
re.push({
|
|
276
|
+
key: v.current[R] ?? t(e[R], R),
|
|
277
|
+
index: R,
|
|
278
|
+
start: _.getOffset(R),
|
|
279
|
+
size: _.getSize(R),
|
|
280
|
+
data: e[R]
|
|
281
281
|
});
|
|
282
|
-
} else if (
|
|
282
|
+
} else if (_ && _.count > 0) {
|
|
283
283
|
const o = Math.min(e.length, c * 2 + 1), d = n === "bottom" ? Math.max(0, e.length - o) : 0, x = d + o - 1;
|
|
284
284
|
for (let I = d; I <= x; I++)
|
|
285
|
-
|
|
286
|
-
key:
|
|
285
|
+
re.push({
|
|
286
|
+
key: v.current[I] ?? t(e[I], I),
|
|
287
287
|
index: I,
|
|
288
|
-
start:
|
|
289
|
-
size:
|
|
288
|
+
start: _.getOffset(I),
|
|
289
|
+
size: _.getSize(I),
|
|
290
290
|
data: e[I]
|
|
291
291
|
});
|
|
292
292
|
}
|
|
293
|
-
const
|
|
293
|
+
const pe = Y ? Y.scrollHeight - Y.scrollTop - Y.clientHeight : 1 / 0;
|
|
294
294
|
return {
|
|
295
295
|
scrollerRef: r,
|
|
296
|
-
innerRef:
|
|
297
|
-
virtualItems:
|
|
298
|
-
totalSize:
|
|
299
|
-
measureItem:
|
|
296
|
+
innerRef: y,
|
|
297
|
+
virtualItems: re,
|
|
298
|
+
totalSize: me,
|
|
299
|
+
measureItem: O,
|
|
300
300
|
scrollToIndex: G,
|
|
301
|
-
scrollToOffset:
|
|
302
|
-
captureAnchorSnapshot:
|
|
303
|
-
resolveAnchorTop:
|
|
304
|
-
isAtTop:
|
|
305
|
-
isAtBottom:
|
|
306
|
-
scrollTop:
|
|
301
|
+
scrollToOffset: N,
|
|
302
|
+
captureAnchorSnapshot: q,
|
|
303
|
+
resolveAnchorTop: ee,
|
|
304
|
+
isAtTop: te <= 1,
|
|
305
|
+
isAtBottom: pe <= 1,
|
|
306
|
+
scrollTop: te,
|
|
307
|
+
jumpSuppressedRef: u
|
|
307
308
|
};
|
|
308
309
|
}
|
|
309
|
-
function
|
|
310
|
+
function Re(a) {
|
|
310
311
|
var c;
|
|
311
|
-
const { snapshot: e, currentScrollHeight: t, resolveAnchorTop: s } =
|
|
312
|
+
const { snapshot: e, currentScrollHeight: t, resolveAnchorTop: s } = a;
|
|
312
313
|
if (e.key !== null) {
|
|
313
314
|
const n = s(e.key, e.offsetWithinItem);
|
|
314
315
|
if (n !== null) return n;
|
|
@@ -320,95 +321,95 @@ function ze(i) {
|
|
|
320
321
|
}
|
|
321
322
|
return e.scrollTop + (t - e.scrollHeight);
|
|
322
323
|
}
|
|
323
|
-
function
|
|
324
|
+
function xe(a) {
|
|
324
325
|
const {
|
|
325
326
|
scrollerRef: e,
|
|
326
327
|
itemCount: t,
|
|
327
328
|
captureAnchorSnapshot: s,
|
|
328
329
|
resolveAnchorTop: c,
|
|
329
330
|
onRestored: n
|
|
330
|
-
} =
|
|
331
|
+
} = a, r = m(null), y = m(!1), l = m({
|
|
331
332
|
first: null,
|
|
332
333
|
second: null,
|
|
333
334
|
timeout: null
|
|
334
|
-
}),
|
|
335
|
-
const { first:
|
|
336
|
-
|
|
337
|
-
}, []),
|
|
338
|
-
const
|
|
339
|
-
if (!
|
|
340
|
-
const
|
|
341
|
-
r.current =
|
|
335
|
+
}), h = k(() => {
|
|
336
|
+
const { first: f, second: p, timeout: F } = l.current;
|
|
337
|
+
f && cancelAnimationFrame(f), p && cancelAnimationFrame(p), F && clearTimeout(F), l.current = { first: null, second: null, timeout: null };
|
|
338
|
+
}, []), v = k(() => {
|
|
339
|
+
const f = e.current;
|
|
340
|
+
if (!f) return;
|
|
341
|
+
const p = s();
|
|
342
|
+
r.current = p ?? {
|
|
342
343
|
key: null,
|
|
343
344
|
offsetWithinItem: 0,
|
|
344
|
-
scrollTop:
|
|
345
|
-
scrollHeight:
|
|
346
|
-
},
|
|
345
|
+
scrollTop: f.scrollTop,
|
|
346
|
+
scrollHeight: f.scrollHeight
|
|
347
|
+
}, y.current = !0;
|
|
347
348
|
}, [e, s]);
|
|
348
349
|
return Z(() => {
|
|
349
|
-
if (!
|
|
350
|
-
const
|
|
351
|
-
if (!
|
|
352
|
-
|
|
350
|
+
if (!y.current) return;
|
|
351
|
+
const f = e.current, p = r.current;
|
|
352
|
+
if (!f || !p) return;
|
|
353
|
+
y.current = !1;
|
|
353
354
|
const F = () => {
|
|
354
|
-
const
|
|
355
|
-
snapshot:
|
|
356
|
-
currentScrollHeight:
|
|
355
|
+
const M = Re({
|
|
356
|
+
snapshot: p,
|
|
357
|
+
currentScrollHeight: f.scrollHeight,
|
|
357
358
|
resolveAnchorTop: c
|
|
358
359
|
});
|
|
359
|
-
Number.isFinite(
|
|
360
|
+
Number.isFinite(M) && Math.abs(f.scrollTop - M) > 1 && (f.scrollTop = M);
|
|
360
361
|
};
|
|
361
|
-
return
|
|
362
|
+
return h(), F(), n == null || n(), l.current.first = requestAnimationFrame(() => {
|
|
362
363
|
l.current.first = null, F(), l.current.second = requestAnimationFrame(() => {
|
|
363
364
|
l.current.second = null, F();
|
|
364
365
|
});
|
|
365
366
|
}), l.current.timeout = setTimeout(() => {
|
|
366
367
|
l.current.timeout = null, F();
|
|
367
|
-
}, 90), () =>
|
|
368
|
-
}, [t, e, c,
|
|
368
|
+
}, 90), () => h();
|
|
369
|
+
}, [t, e, c, h, n]), { prepareAnchor: v };
|
|
369
370
|
}
|
|
370
|
-
function
|
|
371
|
-
const { previous: e, distanceFromBottom: t, threshold: s, hysteresis: c } =
|
|
371
|
+
function Ie(a) {
|
|
372
|
+
const { previous: e, distanceFromBottom: t, threshold: s, hysteresis: c } = a;
|
|
372
373
|
if (!c) return t <= s;
|
|
373
374
|
const n = Math.max(0, c.enter), r = Math.max(n, c.leave);
|
|
374
375
|
return e ? t <= r : t <= n;
|
|
375
376
|
}
|
|
376
|
-
function
|
|
377
|
-
const t = typeof e == "number" ? e : e.threshold ?? 200, s = typeof e == "number" ? void 0 : e.hysteresis, [c, n] =
|
|
378
|
-
return
|
|
379
|
-
const l =
|
|
377
|
+
function Fe(a, e) {
|
|
378
|
+
const t = typeof e == "number" ? e : e.threshold ?? 200, s = typeof e == "number" ? void 0 : e.hysteresis, [c, n] = X(!0), r = m(null), y = m(!0);
|
|
379
|
+
return $(() => {
|
|
380
|
+
const l = a.current;
|
|
380
381
|
if (!l) return;
|
|
381
|
-
const
|
|
382
|
-
const
|
|
383
|
-
previous:
|
|
384
|
-
distanceFromBottom:
|
|
382
|
+
const h = () => {
|
|
383
|
+
const f = l.scrollHeight - l.scrollTop - l.clientHeight, p = Ie({
|
|
384
|
+
previous: y.current,
|
|
385
|
+
distanceFromBottom: f,
|
|
385
386
|
threshold: t,
|
|
386
387
|
hysteresis: s
|
|
387
388
|
});
|
|
388
|
-
|
|
389
|
-
},
|
|
390
|
-
r.current !== null && cancelAnimationFrame(r.current), r.current = requestAnimationFrame(
|
|
389
|
+
y.current = p, n(p);
|
|
390
|
+
}, v = () => {
|
|
391
|
+
r.current !== null && cancelAnimationFrame(r.current), r.current = requestAnimationFrame(h);
|
|
391
392
|
};
|
|
392
|
-
return l.addEventListener("scroll",
|
|
393
|
-
l.removeEventListener("scroll",
|
|
393
|
+
return l.addEventListener("scroll", v, { passive: !0 }), h(), () => {
|
|
394
|
+
l.removeEventListener("scroll", v), r.current !== null && cancelAnimationFrame(r.current);
|
|
394
395
|
};
|
|
395
|
-
}, [
|
|
396
|
+
}, [a, t, s == null ? void 0 : s.enter, s == null ? void 0 : s.leave]), c;
|
|
396
397
|
}
|
|
397
|
-
function
|
|
398
|
-
const { itemCount: e, firstKey: t, lastKey: s, isAtBottom: c, scrollToIndex: n, mode: r } =
|
|
398
|
+
function be(a) {
|
|
399
|
+
const { itemCount: e, firstKey: t, lastKey: s, isAtBottom: c, scrollToIndex: n, mode: r } = a, y = m(e), l = m(t), h = m(s);
|
|
399
400
|
Z(() => {
|
|
400
401
|
if (!r) {
|
|
401
|
-
|
|
402
|
+
y.current = e, l.current = t, h.current = s;
|
|
402
403
|
return;
|
|
403
404
|
}
|
|
404
|
-
const
|
|
405
|
-
e >
|
|
405
|
+
const v = y.current, f = l.current, p = h.current;
|
|
406
|
+
e > v && t === f && s !== p && c && e > 0 && n(e - 1, {
|
|
406
407
|
align: "end",
|
|
407
408
|
behavior: r === "smooth" ? "smooth" : "auto"
|
|
408
|
-
}),
|
|
409
|
+
}), y.current = e, l.current = t, h.current = s;
|
|
409
410
|
}, [e, t, s, c, n, r]);
|
|
410
411
|
}
|
|
411
|
-
function
|
|
412
|
+
function He(a) {
|
|
412
413
|
const {
|
|
413
414
|
items: e,
|
|
414
415
|
getKey: t,
|
|
@@ -416,128 +417,134 @@ function be(i) {
|
|
|
416
417
|
overscan: c = 20,
|
|
417
418
|
atBottomThreshold: n = 200,
|
|
418
419
|
atBottomHysteresis: r,
|
|
419
|
-
followOutput:
|
|
420
|
+
followOutput: y = "auto",
|
|
420
421
|
initialAlignment: l = "bottom",
|
|
421
|
-
scrollModifier:
|
|
422
|
-
onStartReached:
|
|
423
|
-
onEndReached:
|
|
424
|
-
startReachedThreshold:
|
|
422
|
+
scrollModifier: h = null,
|
|
423
|
+
onStartReached: v,
|
|
424
|
+
onEndReached: f,
|
|
425
|
+
startReachedThreshold: p = 300,
|
|
425
426
|
endReachedThreshold: F = 300,
|
|
426
|
-
scrollToMessageKey:
|
|
427
|
-
onScrollToMessageComplete:
|
|
428
|
-
} =
|
|
427
|
+
scrollToMessageKey: M,
|
|
428
|
+
onScrollToMessageComplete: K
|
|
429
|
+
} = a, i = fe({
|
|
429
430
|
items: e,
|
|
430
431
|
getKey: t,
|
|
431
432
|
estimatedItemSize: s,
|
|
432
433
|
overscan: c,
|
|
433
434
|
initialAlignment: l
|
|
434
|
-
}), E =
|
|
435
|
+
}), E = Fe(i.scrollerRef, {
|
|
435
436
|
threshold: n,
|
|
436
437
|
hysteresis: r ?? { enter: 80, leave: 160 }
|
|
437
|
-
}), [,
|
|
438
|
-
|
|
438
|
+
}), [, g] = X(0), b = m(null), S = k(() => {
|
|
439
|
+
g((z) => z + 1), b.current && clearTimeout(b.current), b.current = setTimeout(() => {
|
|
440
|
+
i.jumpSuppressedRef.current = !1, b.current = null;
|
|
441
|
+
}, 200);
|
|
442
|
+
}, [i.jumpSuppressedRef]), { prepareAnchor: C } = xe({
|
|
443
|
+
scrollerRef: i.scrollerRef,
|
|
439
444
|
itemCount: e.length,
|
|
440
|
-
captureAnchorSnapshot:
|
|
441
|
-
resolveAnchorTop:
|
|
442
|
-
onRestored:
|
|
443
|
-
}),
|
|
444
|
-
|
|
445
|
+
captureAnchorSnapshot: i.captureAnchorSnapshot,
|
|
446
|
+
resolveAnchorTop: i.resolveAnchorTop,
|
|
447
|
+
onRestored: S
|
|
448
|
+
}), j = k(() => {
|
|
449
|
+
i.jumpSuppressedRef.current = !0, C();
|
|
450
|
+
}, [C, i.jumpSuppressedRef]), U = e.length > 0 ? t(e[0], 0) : null, L = e.length > 0 ? t(e[e.length - 1], e.length - 1) : null;
|
|
451
|
+
be({
|
|
445
452
|
itemCount: e.length,
|
|
446
|
-
firstKey:
|
|
447
|
-
lastKey:
|
|
453
|
+
firstKey: U,
|
|
454
|
+
lastKey: L,
|
|
448
455
|
isAtBottom: E,
|
|
449
|
-
scrollToIndex:
|
|
450
|
-
mode:
|
|
456
|
+
scrollToIndex: i.scrollToIndex,
|
|
457
|
+
mode: y ?? !1
|
|
451
458
|
});
|
|
452
|
-
const
|
|
453
|
-
(
|
|
454
|
-
e.length !== 0 &&
|
|
459
|
+
const H = k(
|
|
460
|
+
(z = "auto") => {
|
|
461
|
+
e.length !== 0 && i.scrollToIndex(e.length - 1, { align: "end", behavior: z });
|
|
455
462
|
},
|
|
456
|
-
[e.length,
|
|
457
|
-
),
|
|
458
|
-
(
|
|
459
|
-
const
|
|
460
|
-
|
|
463
|
+
[e.length, i]
|
|
464
|
+
), u = k(
|
|
465
|
+
(z, O) => {
|
|
466
|
+
const N = e.findIndex((G, q) => t(G, q) === z);
|
|
467
|
+
N !== -1 && i.scrollToIndex(N, O);
|
|
461
468
|
},
|
|
462
|
-
[e, t,
|
|
463
|
-
),
|
|
469
|
+
[e, t, i]
|
|
470
|
+
), A = m(null);
|
|
464
471
|
Z(() => {
|
|
465
|
-
if (
|
|
466
|
-
if (
|
|
467
|
-
|
|
472
|
+
if (h && A.current !== h.id) {
|
|
473
|
+
if (A.current = h.id, h.type === "prepend") {
|
|
474
|
+
j();
|
|
468
475
|
return;
|
|
469
476
|
}
|
|
470
|
-
if (
|
|
471
|
-
if (
|
|
472
|
-
|
|
477
|
+
if (h.type === "append") {
|
|
478
|
+
if (h.ifAtBottomOnly && !E) return;
|
|
479
|
+
H(h.behavior ?? "auto");
|
|
473
480
|
return;
|
|
474
481
|
}
|
|
475
|
-
if (
|
|
476
|
-
E &&
|
|
482
|
+
if (h.type === "items-change") {
|
|
483
|
+
E && H("auto");
|
|
477
484
|
return;
|
|
478
485
|
}
|
|
479
|
-
|
|
480
|
-
align:
|
|
481
|
-
behavior:
|
|
486
|
+
u(h.key, {
|
|
487
|
+
align: h.align ?? "center",
|
|
488
|
+
behavior: h.behavior ?? "auto"
|
|
482
489
|
});
|
|
483
490
|
}
|
|
484
|
-
}, [
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
const
|
|
488
|
-
if (!
|
|
489
|
-
const
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
|
|
491
|
+
}, [h, E, j, H, u]);
|
|
492
|
+
const T = m(!1), w = m(l === "top");
|
|
493
|
+
$(() => {
|
|
494
|
+
const z = i.scrollerRef.current;
|
|
495
|
+
if (!z || !v) return;
|
|
496
|
+
const O = () => {
|
|
497
|
+
const N = z.scrollTop;
|
|
498
|
+
w.current || (z.scrollHeight <= z.clientHeight + p || N > p) && (w.current = !0), w.current && N <= p && !T.current && (T.current = !0, Promise.resolve(v()).finally(() => {
|
|
499
|
+
T.current = !1;
|
|
493
500
|
}));
|
|
494
501
|
};
|
|
495
|
-
return
|
|
496
|
-
}, [
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
const
|
|
500
|
-
if (!
|
|
501
|
-
const
|
|
502
|
-
|
|
503
|
-
|
|
502
|
+
return z.addEventListener("scroll", O, { passive: !0 }), O(), () => z.removeEventListener("scroll", O);
|
|
503
|
+
}, [i.scrollerRef, v, p, l]);
|
|
504
|
+
const B = m(!1);
|
|
505
|
+
$(() => {
|
|
506
|
+
const z = i.scrollerRef.current;
|
|
507
|
+
if (!z || !f) return;
|
|
508
|
+
const O = () => {
|
|
509
|
+
z.scrollHeight - z.scrollTop - z.clientHeight <= F && !B.current && (B.current = !0, Promise.resolve(f()).finally(() => {
|
|
510
|
+
B.current = !1;
|
|
504
511
|
}));
|
|
505
512
|
};
|
|
506
|
-
return
|
|
507
|
-
}, [
|
|
508
|
-
const
|
|
509
|
-
return
|
|
510
|
-
if (!
|
|
511
|
-
const
|
|
512
|
-
|
|
513
|
-
}, [
|
|
514
|
-
scrollerRef:
|
|
515
|
-
innerRef:
|
|
516
|
-
virtualItems:
|
|
517
|
-
totalSize:
|
|
518
|
-
measureItem:
|
|
519
|
-
scrollToIndex:
|
|
520
|
-
scrollToBottom:
|
|
521
|
-
scrollToKey:
|
|
513
|
+
return z.addEventListener("scroll", O, { passive: !0 }), () => z.removeEventListener("scroll", O);
|
|
514
|
+
}, [i.scrollerRef, f, F]);
|
|
515
|
+
const D = m(null);
|
|
516
|
+
return $(() => {
|
|
517
|
+
if (!M || D.current === M) return;
|
|
518
|
+
const z = e.findIndex((O, N) => t(O, N) === M);
|
|
519
|
+
z !== -1 && (D.current = M, i.scrollToIndex(z, { align: "center", behavior: "auto" }), K == null || K());
|
|
520
|
+
}, [M, e, t, i, K]), {
|
|
521
|
+
scrollerRef: i.scrollerRef,
|
|
522
|
+
innerRef: i.innerRef,
|
|
523
|
+
virtualItems: i.virtualItems,
|
|
524
|
+
totalSize: i.totalSize,
|
|
525
|
+
measureItem: i.measureItem,
|
|
526
|
+
scrollToIndex: i.scrollToIndex,
|
|
527
|
+
scrollToBottom: H,
|
|
528
|
+
scrollToKey: u,
|
|
522
529
|
isAtBottom: E,
|
|
523
|
-
prepareAnchor:
|
|
530
|
+
prepareAnchor: j
|
|
524
531
|
};
|
|
525
532
|
}
|
|
526
|
-
function
|
|
527
|
-
virtualItem:
|
|
533
|
+
function he({
|
|
534
|
+
virtualItem: a,
|
|
528
535
|
measureItem: e,
|
|
529
536
|
children: t
|
|
530
537
|
}) {
|
|
531
|
-
const s =
|
|
532
|
-
return
|
|
538
|
+
const s = m(null), c = m(!1);
|
|
539
|
+
return $(() => {
|
|
533
540
|
const n = s.current;
|
|
534
541
|
if (!n) return;
|
|
535
542
|
c.current = !1;
|
|
536
|
-
const r = new ResizeObserver(([
|
|
537
|
-
|
|
543
|
+
const r = new ResizeObserver(([y]) => {
|
|
544
|
+
y && (c.current = !0, e(a.key, y.contentRect.height));
|
|
538
545
|
});
|
|
539
546
|
return r.observe(n), () => r.disconnect();
|
|
540
|
-
}, [
|
|
547
|
+
}, [a.key, e]), /* @__PURE__ */ J(
|
|
541
548
|
"div",
|
|
542
549
|
{
|
|
543
550
|
ref: s,
|
|
@@ -545,92 +552,92 @@ function fe({
|
|
|
545
552
|
position: "absolute",
|
|
546
553
|
top: 0,
|
|
547
554
|
// transform instead of top: avoids reflow, uses GPU compositor layer
|
|
548
|
-
transform: `translateY(${
|
|
555
|
+
transform: `translateY(${a.start}px)`,
|
|
549
556
|
width: "100%",
|
|
550
557
|
// Only reserve estimated height before first measurement.
|
|
551
558
|
// After measurement, let the item take its natural height so
|
|
552
559
|
// ResizeObserver can accurately report the real size.
|
|
553
560
|
// Without this, items can never be smaller than estimatedItemSize,
|
|
554
561
|
// which distorts offsets and total height.
|
|
555
|
-
minHeight: c.current ? void 0 :
|
|
562
|
+
minHeight: c.current ? void 0 : a.size
|
|
556
563
|
},
|
|
557
564
|
children: t
|
|
558
565
|
}
|
|
559
566
|
);
|
|
560
567
|
}
|
|
561
|
-
function
|
|
568
|
+
function Me(a, e) {
|
|
562
569
|
const {
|
|
563
570
|
data: t,
|
|
564
571
|
itemContent: s,
|
|
565
572
|
computeItemKey: c,
|
|
566
573
|
estimatedItemSize: n = 80,
|
|
567
574
|
overscan: r = 20,
|
|
568
|
-
followOutput:
|
|
575
|
+
followOutput: y = "auto",
|
|
569
576
|
atBottomThreshold: l = 200,
|
|
570
|
-
atBottomHysteresis:
|
|
571
|
-
initialAlignment:
|
|
572
|
-
scrollModifier:
|
|
573
|
-
onStartReached:
|
|
577
|
+
atBottomHysteresis: h,
|
|
578
|
+
initialAlignment: v = "bottom",
|
|
579
|
+
scrollModifier: f,
|
|
580
|
+
onStartReached: p,
|
|
574
581
|
onEndReached: F,
|
|
575
|
-
startReachedThreshold:
|
|
576
|
-
endReachedThreshold:
|
|
577
|
-
scrollToMessageKey:
|
|
582
|
+
startReachedThreshold: M = 300,
|
|
583
|
+
endReachedThreshold: K = 300,
|
|
584
|
+
scrollToMessageKey: i,
|
|
578
585
|
onScrollToMessageComplete: E,
|
|
579
|
-
onAtBottomChange:
|
|
580
|
-
components:
|
|
581
|
-
className:
|
|
582
|
-
style:
|
|
583
|
-
} =
|
|
584
|
-
scrollerRef:
|
|
585
|
-
innerRef:
|
|
586
|
-
virtualItems:
|
|
586
|
+
onAtBottomChange: g,
|
|
587
|
+
components: b = {},
|
|
588
|
+
className: S,
|
|
589
|
+
style: C
|
|
590
|
+
} = a, {
|
|
591
|
+
scrollerRef: j,
|
|
592
|
+
innerRef: U,
|
|
593
|
+
virtualItems: L,
|
|
587
594
|
totalSize: H,
|
|
588
595
|
measureItem: u,
|
|
589
|
-
scrollToIndex:
|
|
590
|
-
scrollToBottom:
|
|
596
|
+
scrollToIndex: A,
|
|
597
|
+
scrollToBottom: T,
|
|
591
598
|
scrollToKey: w,
|
|
592
|
-
isAtBottom:
|
|
593
|
-
prepareAnchor:
|
|
594
|
-
} =
|
|
599
|
+
isAtBottom: B,
|
|
600
|
+
prepareAnchor: D
|
|
601
|
+
} = He({
|
|
595
602
|
items: t,
|
|
596
|
-
getKey: (
|
|
603
|
+
getKey: (q, ee) => c(ee, q),
|
|
597
604
|
estimatedItemSize: n,
|
|
598
605
|
overscan: r,
|
|
599
606
|
atBottomThreshold: l,
|
|
600
|
-
atBottomHysteresis:
|
|
601
|
-
followOutput:
|
|
602
|
-
initialAlignment:
|
|
603
|
-
scrollModifier:
|
|
604
|
-
onStartReached:
|
|
607
|
+
atBottomHysteresis: h,
|
|
608
|
+
followOutput: y,
|
|
609
|
+
initialAlignment: v,
|
|
610
|
+
scrollModifier: f,
|
|
611
|
+
onStartReached: p,
|
|
605
612
|
onEndReached: F,
|
|
606
|
-
startReachedThreshold:
|
|
607
|
-
endReachedThreshold:
|
|
608
|
-
scrollToMessageKey:
|
|
613
|
+
startReachedThreshold: M,
|
|
614
|
+
endReachedThreshold: K,
|
|
615
|
+
scrollToMessageKey: i,
|
|
609
616
|
onScrollToMessageComplete: E
|
|
610
|
-
}),
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
}, [
|
|
617
|
+
}), z = oe.useRef(B);
|
|
618
|
+
oe.useEffect(() => {
|
|
619
|
+
z.current !== B && (z.current = B, g == null || g(B));
|
|
620
|
+
}, [B, g]), ve(
|
|
614
621
|
e,
|
|
615
622
|
() => ({
|
|
616
|
-
scrollToBottom:
|
|
617
|
-
scrollToIndex:
|
|
623
|
+
scrollToBottom: T,
|
|
624
|
+
scrollToIndex: A,
|
|
618
625
|
scrollToKey: w,
|
|
619
626
|
getScrollTop: () => {
|
|
620
|
-
var
|
|
621
|
-
return ((
|
|
627
|
+
var q;
|
|
628
|
+
return ((q = j.current) == null ? void 0 : q.scrollTop) ?? 0;
|
|
622
629
|
},
|
|
623
|
-
isAtBottom: () =>
|
|
624
|
-
prepareAnchor:
|
|
630
|
+
isAtBottom: () => B,
|
|
631
|
+
prepareAnchor: D
|
|
625
632
|
}),
|
|
626
|
-
[
|
|
633
|
+
[T, A, w, j, B, D]
|
|
627
634
|
);
|
|
628
|
-
const { Header:
|
|
629
|
-
return t.length === 0 &&
|
|
635
|
+
const { Header: O, Footer: N, EmptyPlaceholder: G } = b;
|
|
636
|
+
return t.length === 0 && G ? /* @__PURE__ */ J(G, {}) : /* @__PURE__ */ ae(
|
|
630
637
|
"div",
|
|
631
638
|
{
|
|
632
|
-
ref:
|
|
633
|
-
className:
|
|
639
|
+
ref: j,
|
|
640
|
+
className: S,
|
|
634
641
|
style: {
|
|
635
642
|
overflow: "auto",
|
|
636
643
|
height: "100%",
|
|
@@ -639,60 +646,60 @@ function He(i, e) {
|
|
|
639
646
|
// the library prepend compensation logic.
|
|
640
647
|
overflowAnchor: "none",
|
|
641
648
|
overscrollBehaviorY: "contain",
|
|
642
|
-
...
|
|
649
|
+
...C
|
|
643
650
|
},
|
|
644
651
|
children: [
|
|
645
|
-
|
|
646
|
-
/* @__PURE__ */ J("div", { ref:
|
|
647
|
-
|
|
652
|
+
O && /* @__PURE__ */ J(O, {}),
|
|
653
|
+
/* @__PURE__ */ J("div", { ref: U, style: { height: H, position: "relative", width: "100%" }, children: L.map((q) => /* @__PURE__ */ J(
|
|
654
|
+
he,
|
|
648
655
|
{
|
|
649
|
-
virtualItem:
|
|
656
|
+
virtualItem: q,
|
|
650
657
|
measureItem: u,
|
|
651
|
-
children: s(
|
|
658
|
+
children: s(q.index, q.data)
|
|
652
659
|
},
|
|
653
|
-
|
|
660
|
+
q.key
|
|
654
661
|
)) }),
|
|
655
|
-
|
|
662
|
+
N && /* @__PURE__ */ J(N, {})
|
|
656
663
|
]
|
|
657
664
|
}
|
|
658
665
|
);
|
|
659
666
|
}
|
|
660
|
-
const Ke = ge(
|
|
661
|
-
function
|
|
662
|
-
data:
|
|
667
|
+
const Ke = ge(Me);
|
|
668
|
+
function Ee({
|
|
669
|
+
data: a,
|
|
663
670
|
itemContent: e,
|
|
664
671
|
computeItemKey: t,
|
|
665
672
|
estimatedItemSize: s = 60,
|
|
666
673
|
overscan: c = 20,
|
|
667
674
|
onEndReached: n,
|
|
668
675
|
endReachedThreshold: r = 300,
|
|
669
|
-
components:
|
|
676
|
+
components: y = {},
|
|
670
677
|
className: l,
|
|
671
|
-
style:
|
|
678
|
+
style: h
|
|
672
679
|
}) {
|
|
673
|
-
const { scrollerRef:
|
|
674
|
-
items:
|
|
675
|
-
getKey: (
|
|
680
|
+
const { scrollerRef: v, innerRef: f, virtualItems: p, totalSize: F, measureItem: M } = fe({
|
|
681
|
+
items: a,
|
|
682
|
+
getKey: (g, b) => t(b, g),
|
|
676
683
|
estimatedItemSize: s,
|
|
677
684
|
overscan: c,
|
|
678
685
|
initialAlignment: "top"
|
|
679
686
|
});
|
|
680
|
-
|
|
681
|
-
const
|
|
682
|
-
if (!
|
|
683
|
-
let
|
|
684
|
-
const
|
|
685
|
-
|
|
686
|
-
|
|
687
|
+
oe.useEffect(() => {
|
|
688
|
+
const g = v.current;
|
|
689
|
+
if (!g || !n) return;
|
|
690
|
+
let b = !1;
|
|
691
|
+
const S = () => {
|
|
692
|
+
g.scrollHeight - g.scrollTop - g.clientHeight <= r && !b && (b = !0, Promise.resolve(n()).finally(() => {
|
|
693
|
+
b = !1;
|
|
687
694
|
}));
|
|
688
695
|
};
|
|
689
|
-
return
|
|
690
|
-
}, [
|
|
691
|
-
const { Header:
|
|
692
|
-
return
|
|
696
|
+
return g.addEventListener("scroll", S, { passive: !0 }), () => g.removeEventListener("scroll", S);
|
|
697
|
+
}, [v, n, r]);
|
|
698
|
+
const { Header: K, Footer: i, EmptyPlaceholder: E } = y;
|
|
699
|
+
return a.length === 0 && E ? /* @__PURE__ */ J(E, {}) : /* @__PURE__ */ ae(
|
|
693
700
|
"div",
|
|
694
701
|
{
|
|
695
|
-
ref:
|
|
702
|
+
ref: v,
|
|
696
703
|
className: l,
|
|
697
704
|
style: {
|
|
698
705
|
overflow: "auto",
|
|
@@ -701,25 +708,25 @@ function Pe({
|
|
|
701
708
|
// Keep scrolling behavior deterministic when items are inserted above.
|
|
702
709
|
overflowAnchor: "none",
|
|
703
710
|
overscrollBehaviorY: "contain",
|
|
704
|
-
...
|
|
711
|
+
...h
|
|
705
712
|
},
|
|
706
713
|
children: [
|
|
707
|
-
|
|
708
|
-
/* @__PURE__ */ J("div", { ref:
|
|
709
|
-
|
|
714
|
+
K && /* @__PURE__ */ J(K, {}),
|
|
715
|
+
/* @__PURE__ */ J("div", { ref: f, style: { height: F, position: "relative", width: "100%" }, children: p.map((g) => /* @__PURE__ */ J(
|
|
716
|
+
he,
|
|
710
717
|
{
|
|
711
|
-
virtualItem:
|
|
712
|
-
measureItem:
|
|
713
|
-
children: e(
|
|
718
|
+
virtualItem: g,
|
|
719
|
+
measureItem: M,
|
|
720
|
+
children: e(g.index, g.data)
|
|
714
721
|
},
|
|
715
|
-
|
|
722
|
+
g.key
|
|
716
723
|
)) }),
|
|
717
|
-
|
|
724
|
+
i && /* @__PURE__ */ J(i, {})
|
|
718
725
|
]
|
|
719
726
|
}
|
|
720
727
|
);
|
|
721
728
|
}
|
|
722
|
-
function
|
|
729
|
+
function Be(a) {
|
|
723
730
|
const {
|
|
724
731
|
fetcher: e,
|
|
725
732
|
initialPage: t = 1,
|
|
@@ -727,77 +734,77 @@ function Ee(i) {
|
|
|
727
734
|
getKey: c,
|
|
728
735
|
onPageLoaded: n,
|
|
729
736
|
onError: r
|
|
730
|
-
} =
|
|
731
|
-
(u) => c ? u.filter((
|
|
732
|
-
const
|
|
733
|
-
return
|
|
737
|
+
} = a, [y, l] = X([]), [h, v] = X(t), [f, p] = X(!0), [F, M] = X(!1), [K, i] = X(!1), [E, g] = X(!1), b = m(/* @__PURE__ */ new Set()), S = m(!1), C = k(
|
|
738
|
+
(u) => c ? u.filter((A) => {
|
|
739
|
+
const T = c(A);
|
|
740
|
+
return b.current.has(T) ? !1 : (b.current.add(T), !0);
|
|
734
741
|
}) : u,
|
|
735
742
|
[c]
|
|
736
|
-
),
|
|
737
|
-
if (!(
|
|
738
|
-
|
|
743
|
+
), j = k(async () => {
|
|
744
|
+
if (!(S.current || !f)) {
|
|
745
|
+
S.current = !0, g(!0);
|
|
739
746
|
try {
|
|
740
|
-
const u =
|
|
747
|
+
const u = h + 1, A = await e(u), T = C(A.data);
|
|
741
748
|
l(
|
|
742
|
-
(w) => s === "prepend" ? [...
|
|
743
|
-
),
|
|
749
|
+
(w) => s === "prepend" ? [...T, ...w] : [...w, ...T]
|
|
750
|
+
), v(u), p(A.hasNextPage), M(A.hasPrevPage), n == null || n(u, T);
|
|
744
751
|
} catch (u) {
|
|
745
752
|
r == null || r(u instanceof Error ? u : new Error(String(u)));
|
|
746
753
|
} finally {
|
|
747
|
-
|
|
754
|
+
g(!1), S.current = !1;
|
|
748
755
|
}
|
|
749
756
|
}
|
|
750
|
-
}, [
|
|
751
|
-
if (!(
|
|
752
|
-
|
|
757
|
+
}, [h, f, e, C, s, n, r]), U = k(async () => {
|
|
758
|
+
if (!(S.current || !F)) {
|
|
759
|
+
S.current = !0, g(!0);
|
|
753
760
|
try {
|
|
754
|
-
const u =
|
|
755
|
-
l((w) => [...
|
|
761
|
+
const u = h - 1, A = await e(u), T = C(A.data);
|
|
762
|
+
l((w) => [...T, ...w]), v(u), M(A.hasPrevPage), p(A.hasNextPage), n == null || n(u, T);
|
|
756
763
|
} catch (u) {
|
|
757
764
|
r == null || r(u instanceof Error ? u : new Error(String(u)));
|
|
758
765
|
} finally {
|
|
759
|
-
|
|
766
|
+
g(!1), S.current = !1;
|
|
760
767
|
}
|
|
761
768
|
}
|
|
762
|
-
}, [
|
|
763
|
-
if (!
|
|
764
|
-
|
|
769
|
+
}, [h, F, e, C, n, r]), L = k(async () => {
|
|
770
|
+
if (!S.current) {
|
|
771
|
+
S.current = !0, i(!0);
|
|
765
772
|
try {
|
|
766
|
-
const u = await e(t),
|
|
773
|
+
const u = await e(t), A = u.data;
|
|
767
774
|
if (c) {
|
|
768
|
-
const
|
|
769
|
-
|
|
770
|
-
const
|
|
771
|
-
return s === "prepend" ? [...
|
|
775
|
+
const T = new Set(A.map(c));
|
|
776
|
+
A.forEach((w) => b.current.add(c(w))), l((w) => {
|
|
777
|
+
const B = w.filter((D) => !T.has(c(D)));
|
|
778
|
+
return s === "prepend" ? [...A, ...B] : [...B, ...A];
|
|
772
779
|
});
|
|
773
780
|
} else
|
|
774
|
-
l(
|
|
775
|
-
|
|
781
|
+
l(A);
|
|
782
|
+
v(t), p(u.hasNextPage), M(u.hasPrevPage), n == null || n(t, A);
|
|
776
783
|
} catch (u) {
|
|
777
784
|
r == null || r(u instanceof Error ? u : new Error(String(u)));
|
|
778
785
|
} finally {
|
|
779
|
-
|
|
786
|
+
i(!1), S.current = !1;
|
|
780
787
|
}
|
|
781
788
|
}
|
|
782
|
-
}, [e, t, c, s, n, r]), H =
|
|
783
|
-
l([]),
|
|
789
|
+
}, [e, t, c, s, n, r]), H = k(() => {
|
|
790
|
+
l([]), v(t), p(!0), M(!1), i(!1), g(!1), b.current.clear(), S.current = !1;
|
|
784
791
|
}, [t]);
|
|
785
792
|
return {
|
|
786
|
-
items:
|
|
787
|
-
loadNextPage:
|
|
788
|
-
loadPrevPage:
|
|
789
|
-
hasNextPage:
|
|
793
|
+
items: y,
|
|
794
|
+
loadNextPage: j,
|
|
795
|
+
loadPrevPage: U,
|
|
796
|
+
hasNextPage: f,
|
|
790
797
|
hasPrevPage: F,
|
|
791
|
-
loading:
|
|
798
|
+
loading: K,
|
|
792
799
|
loadingMore: E,
|
|
793
|
-
refresh:
|
|
800
|
+
refresh: L,
|
|
794
801
|
reset: H,
|
|
795
|
-
currentPage:
|
|
802
|
+
currentPage: h
|
|
796
803
|
};
|
|
797
804
|
}
|
|
798
805
|
export {
|
|
799
806
|
Ke as ChatVirtualList,
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
807
|
+
Ee as VirtualList,
|
|
808
|
+
He as useChatVirtualizer,
|
|
809
|
+
Be as usePagination
|
|
803
810
|
};
|