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