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