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