react-anchorlist 0.2.0 → 0.2.3
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 +79 -79
- 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/useFollowOutput.d.ts +7 -3
- package/dist/hooks/useFollowOutput.d.ts.map +1 -1
- package/dist/hooks/useScrollAnchor.d.ts +4 -3
- package/dist/hooks/useScrollAnchor.d.ts.map +1 -1
- package/dist/hooks/useScrollToIndex.d.ts +7 -2
- package/dist/hooks/useScrollToIndex.d.ts.map +1 -1
- package/dist/hooks/useVirtualEngine.d.ts +7 -7
- package/dist/hooks/useVirtualEngine.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +373 -331
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import * as
|
|
3
|
-
import { useCallback as
|
|
4
|
-
class
|
|
1
|
+
import { jsx as B, jsxs as $ } from "react/jsx-runtime";
|
|
2
|
+
import * as U from "react";
|
|
3
|
+
import { useCallback as L, useRef as y, useState as V, useEffect as N, useLayoutEffect as D, forwardRef as Q, useImperativeHandle as W } from "react";
|
|
4
|
+
class X {
|
|
5
5
|
constructor(e, t) {
|
|
6
6
|
this.defaultSize = t, this.sizes = e > 0 ? Array(e).fill(t) : [], this.offsets = e > 0 ? Array(e).fill(0) : [], e > 0 && this._recalcFrom(0);
|
|
7
7
|
}
|
|
@@ -48,7 +48,7 @@ class J {
|
|
|
48
48
|
return this.sizes;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
class
|
|
51
|
+
class Z {
|
|
52
52
|
constructor() {
|
|
53
53
|
this.cache = /* @__PURE__ */ new Map();
|
|
54
54
|
}
|
|
@@ -69,271 +69,310 @@ class Q {
|
|
|
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 [n,
|
|
73
|
-
const
|
|
74
|
-
|
|
72
|
+
for (const [n, i] of this.cache) {
|
|
73
|
+
const r = t.get(n);
|
|
74
|
+
r !== void 0 && e.setSize(r, i);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
function
|
|
78
|
+
function ee(l, e) {
|
|
79
79
|
if (l.length === 0) return 0;
|
|
80
80
|
let t = 0, n = l.length - 1;
|
|
81
81
|
for (; t < n; ) {
|
|
82
|
-
const
|
|
83
|
-
(l[
|
|
82
|
+
const i = t + n >> 1;
|
|
83
|
+
(l[i] ?? 0) < e ? t = i + 1 : n = i;
|
|
84
84
|
}
|
|
85
85
|
return Math.max(0, t > 0 && (l[t] ?? 0) > e ? t - 1 : t);
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function te(l, e, t) {
|
|
88
88
|
if (l.length === 0) return 0;
|
|
89
89
|
for (let n = l.length - 1; n >= 0; n--)
|
|
90
90
|
if ((l[n] ?? 0) < t) return n;
|
|
91
91
|
return 0;
|
|
92
92
|
}
|
|
93
|
-
function
|
|
94
|
-
const { firstVisible: e, lastVisible: t, itemCount: n, overscan:
|
|
93
|
+
function re(l) {
|
|
94
|
+
const { firstVisible: e, lastVisible: t, itemCount: n, overscan: i } = l;
|
|
95
95
|
return n === 0 ? { start: 0, end: -1 } : {
|
|
96
|
-
start: Math.max(0, e -
|
|
97
|
-
end: Math.min(n - 1, t +
|
|
96
|
+
start: Math.max(0, e - i),
|
|
97
|
+
end: Math.min(n - 1, t + i)
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
|
-
function
|
|
101
|
-
return
|
|
102
|
-
(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
let
|
|
107
|
-
|
|
100
|
+
function ne(l, e, t) {
|
|
101
|
+
return L(
|
|
102
|
+
(n, i) => {
|
|
103
|
+
var K;
|
|
104
|
+
const r = l.current, o = e.current;
|
|
105
|
+
if (!r || !o) return;
|
|
106
|
+
let m, s;
|
|
107
|
+
if (typeof n == "object" && n !== null ? (m = n.index, s = {
|
|
108
|
+
align: n.align,
|
|
109
|
+
behavior: n.behavior,
|
|
110
|
+
offset: n.offset
|
|
111
|
+
}) : (m = n, s = i), !Number.isFinite(m)) return;
|
|
112
|
+
const d = Math.max(0, Math.min(Math.floor(m), o.count - 1)), f = ((K = t == null ? void 0 : t.current) == null ? void 0 : K.offsetTop) ?? 0, A = o.getOffset(d), T = o.getSize(d), R = (s == null ? void 0 : s.align) ?? "start", u = (s == null ? void 0 : s.behavior) ?? "auto", H = (s == null ? void 0 : s.offset) ?? 0;
|
|
113
|
+
let v;
|
|
114
|
+
R === "start" ? v = f + A + H : R === "center" ? v = f + A - r.clientHeight / 2 + T / 2 + H : v = f + A - r.clientHeight + T + H, r.scrollTo({ top: Math.max(0, v), behavior: u });
|
|
108
115
|
},
|
|
109
|
-
[l, e]
|
|
116
|
+
[l, e, t]
|
|
110
117
|
);
|
|
111
118
|
}
|
|
112
|
-
function
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
function G(l) {
|
|
120
|
+
var q;
|
|
121
|
+
const { items: e, getKey: t, estimatedItemSize: n, overscan: i, initialAlignment: r } = l, o = y(null), m = y(null), s = y(null), d = y(new Z()), f = y([]), A = y(!1), T = y(0), R = y(0), u = y(null), [, H] = V(0), v = L(() => H((a) => a + 1), []);
|
|
122
|
+
s.current || (s.current = new X(e.length, n));
|
|
123
|
+
const K = y(e.length);
|
|
124
|
+
if (e.length !== K.current || e.some((a, h) => {
|
|
125
|
+
const z = t(a, h);
|
|
126
|
+
return f.current[h] !== z;
|
|
119
127
|
})) {
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
128
|
+
const a = s.current, h = e.map((O, Y) => t(O, Y)), z = f.current, k = z.length, E = h.length;
|
|
129
|
+
E === 0 ? a.resize(0) : k === 0 ? a.resize(E) : E > k ? z.length > 0 && h[E - k] === z[0] ? a.prepend(E - k) : a.resize(E) : E < k && a.resize(E);
|
|
130
|
+
const M = /* @__PURE__ */ new Map();
|
|
131
|
+
h.forEach((O, Y) => M.set(O, Y)), d.current.applyToOffsetMap(a, M), f.current = h, K.current = e.length;
|
|
124
132
|
}
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
if (!
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
133
|
+
N(() => {
|
|
134
|
+
const a = o.current;
|
|
135
|
+
if (!a) return;
|
|
136
|
+
const h = () => {
|
|
137
|
+
u.current === null && (u.current = requestAnimationFrame(() => {
|
|
138
|
+
u.current = null, T.current = a.scrollTop, R.current = a.clientHeight, v();
|
|
131
139
|
}));
|
|
132
140
|
};
|
|
133
|
-
return
|
|
134
|
-
|
|
141
|
+
return a.addEventListener("scroll", h, { passive: !0 }), () => {
|
|
142
|
+
a.removeEventListener("scroll", h), u.current !== null && (cancelAnimationFrame(u.current), u.current = null);
|
|
135
143
|
};
|
|
136
|
-
}, [
|
|
137
|
-
const
|
|
138
|
-
if (!
|
|
139
|
-
R.current =
|
|
140
|
-
const
|
|
141
|
-
|
|
144
|
+
}, [v]), N(() => {
|
|
145
|
+
const a = o.current;
|
|
146
|
+
if (!a) return;
|
|
147
|
+
R.current = a.clientHeight, T.current = a.scrollTop;
|
|
148
|
+
const h = new ResizeObserver(([z]) => {
|
|
149
|
+
z && (R.current = z.contentRect.height, v());
|
|
142
150
|
});
|
|
143
|
-
return
|
|
144
|
-
}, [
|
|
145
|
-
if (
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
}, [
|
|
149
|
-
e.length === 0 && (
|
|
151
|
+
return h.observe(a), () => h.disconnect();
|
|
152
|
+
}, [v]), D(() => {
|
|
153
|
+
if (A.current || e.length === 0) return;
|
|
154
|
+
const a = o.current;
|
|
155
|
+
a && (r === "bottom" && (a.scrollTop = a.scrollHeight, T.current = a.scrollTop), A.current = !0);
|
|
156
|
+
}, [r, e.length]), N(() => {
|
|
157
|
+
e.length === 0 && (A.current = !1);
|
|
150
158
|
}, [e.length]);
|
|
151
|
-
const
|
|
152
|
-
const
|
|
153
|
-
if (!
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
}, [
|
|
159
|
-
(
|
|
160
|
-
var
|
|
161
|
-
(
|
|
159
|
+
const F = L((a, h) => {
|
|
160
|
+
const z = s.current;
|
|
161
|
+
if (!z || d.current.get(a) === h) return;
|
|
162
|
+
d.current.set(a, h);
|
|
163
|
+
const E = f.current.indexOf(a);
|
|
164
|
+
if (E === -1) return;
|
|
165
|
+
z.setSize(E, h) && v();
|
|
166
|
+
}, [v]), I = L(
|
|
167
|
+
(a, h = "auto") => {
|
|
168
|
+
var z;
|
|
169
|
+
(z = o.current) == null || z.scrollTo({ top: a, behavior: h });
|
|
162
170
|
},
|
|
163
171
|
[]
|
|
164
|
-
),
|
|
165
|
-
let
|
|
166
|
-
if (
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
+
), C = ne(o, s, m), b = s.current, _ = b ? b.totalSize() : 0, w = o.current, p = (w == null ? void 0 : w.scrollTop) ?? T.current, c = (w == null ? void 0 : w.clientHeight) ?? R.current, g = ((q = m.current) == null ? void 0 : q.offsetTop) ?? 0, x = Math.max(0, p - g);
|
|
173
|
+
let P = [];
|
|
174
|
+
if (b && b.count > 0 && c > 0) {
|
|
175
|
+
const a = b.getOffsets(), h = b.getSizes(), z = ee(a, x), k = te(
|
|
176
|
+
a,
|
|
177
|
+
h,
|
|
178
|
+
x + c
|
|
179
|
+
), E = re({
|
|
180
|
+
firstVisible: z,
|
|
181
|
+
lastVisible: k,
|
|
182
|
+
itemCount: b.count,
|
|
183
|
+
overscan: i
|
|
172
184
|
});
|
|
173
|
-
for (let
|
|
174
|
-
|
|
175
|
-
key:
|
|
176
|
-
index:
|
|
177
|
-
start:
|
|
178
|
-
size:
|
|
179
|
-
data: e[
|
|
185
|
+
for (let M = E.start; M <= E.end && M < e.length; M++)
|
|
186
|
+
P.push({
|
|
187
|
+
key: f.current[M] ?? t(e[M], M),
|
|
188
|
+
index: M,
|
|
189
|
+
start: b.getOffset(M),
|
|
190
|
+
size: b.getSize(M),
|
|
191
|
+
data: e[M]
|
|
180
192
|
});
|
|
181
|
-
} else if (
|
|
182
|
-
const
|
|
183
|
-
for (let
|
|
184
|
-
|
|
185
|
-
key:
|
|
186
|
-
index:
|
|
187
|
-
start:
|
|
188
|
-
size:
|
|
189
|
-
data: e[
|
|
193
|
+
} else if (b && b.count > 0) {
|
|
194
|
+
const a = Math.min(e.length - 1, i * 2);
|
|
195
|
+
for (let h = 0; h <= a; h++)
|
|
196
|
+
P.push({
|
|
197
|
+
key: f.current[h] ?? t(e[h], h),
|
|
198
|
+
index: h,
|
|
199
|
+
start: b.getOffset(h),
|
|
200
|
+
size: b.getSize(h),
|
|
201
|
+
data: e[h]
|
|
190
202
|
});
|
|
191
203
|
}
|
|
192
|
-
const
|
|
204
|
+
const j = w ? w.scrollHeight - w.scrollTop - w.clientHeight : 1 / 0;
|
|
193
205
|
return {
|
|
194
206
|
scrollerRef: o,
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
207
|
+
innerRef: m,
|
|
208
|
+
virtualItems: P,
|
|
209
|
+
totalSize: _,
|
|
210
|
+
measureItem: F,
|
|
211
|
+
scrollToIndex: C,
|
|
212
|
+
scrollToOffset: I,
|
|
213
|
+
isAtTop: p <= 1,
|
|
214
|
+
isAtBottom: j <= 1,
|
|
215
|
+
scrollTop: p
|
|
203
216
|
};
|
|
204
217
|
}
|
|
205
|
-
function
|
|
206
|
-
const t =
|
|
207
|
-
|
|
208
|
-
|
|
218
|
+
function se(l, e) {
|
|
219
|
+
const t = y(0), n = y(0), i = y(!1), r = y({
|
|
220
|
+
first: null,
|
|
221
|
+
second: null,
|
|
222
|
+
timeout: null
|
|
223
|
+
}), o = L(() => {
|
|
224
|
+
const { first: s, second: d, timeout: f } = r.current;
|
|
225
|
+
s && cancelAnimationFrame(s), d && cancelAnimationFrame(d), f && clearTimeout(f), r.current = { first: null, second: null, timeout: null };
|
|
226
|
+
}, []), m = L(() => {
|
|
227
|
+
const s = l.current;
|
|
228
|
+
s && (t.current = s.scrollTop, n.current = s.scrollHeight, i.current = !0);
|
|
209
229
|
}, [l]);
|
|
210
|
-
return
|
|
211
|
-
if (!
|
|
212
|
-
const
|
|
213
|
-
if (!
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
230
|
+
return D(() => {
|
|
231
|
+
if (!i.current) return;
|
|
232
|
+
const s = l.current;
|
|
233
|
+
if (!s) return;
|
|
234
|
+
i.current = !1;
|
|
235
|
+
const d = () => {
|
|
236
|
+
const f = t.current + (s.scrollHeight - n.current);
|
|
237
|
+
Number.isFinite(f) && Math.abs(s.scrollTop - f) > 1 && (s.scrollTop = f);
|
|
238
|
+
};
|
|
239
|
+
return o(), d(), r.current.first = requestAnimationFrame(() => {
|
|
240
|
+
r.current.first = null, d(), r.current.second = requestAnimationFrame(() => {
|
|
241
|
+
r.current.second = null, d();
|
|
242
|
+
});
|
|
243
|
+
}), r.current.timeout = setTimeout(() => {
|
|
244
|
+
r.current.timeout = null, d();
|
|
245
|
+
}, 90), () => o();
|
|
246
|
+
}, [e, l, o]), { prepareAnchor: m };
|
|
217
247
|
}
|
|
218
|
-
function
|
|
219
|
-
const [t, n] =
|
|
220
|
-
return
|
|
221
|
-
const
|
|
222
|
-
if (!
|
|
248
|
+
function oe(l, e) {
|
|
249
|
+
const [t, n] = V(!0), i = y(null);
|
|
250
|
+
return N(() => {
|
|
251
|
+
const r = l.current;
|
|
252
|
+
if (!r) return;
|
|
223
253
|
const o = () => {
|
|
224
|
-
const
|
|
225
|
-
n(
|
|
254
|
+
const s = r.scrollHeight - r.scrollTop - r.clientHeight;
|
|
255
|
+
n(s <= e);
|
|
226
256
|
}, m = () => {
|
|
227
|
-
|
|
257
|
+
i.current !== null && cancelAnimationFrame(i.current), i.current = requestAnimationFrame(o);
|
|
228
258
|
};
|
|
229
|
-
return
|
|
230
|
-
|
|
259
|
+
return r.addEventListener("scroll", m, { passive: !0 }), o(), () => {
|
|
260
|
+
r.removeEventListener("scroll", m), i.current !== null && cancelAnimationFrame(i.current);
|
|
231
261
|
};
|
|
232
262
|
}, [l, e]), t;
|
|
233
263
|
}
|
|
234
|
-
function
|
|
235
|
-
const { itemCount: e,
|
|
236
|
-
|
|
237
|
-
|
|
264
|
+
function ie(l) {
|
|
265
|
+
const { itemCount: e, firstKey: t, lastKey: n, isAtBottom: i, scrollToIndex: r, mode: o } = l, m = y(e), s = y(t), d = y(n);
|
|
266
|
+
D(() => {
|
|
267
|
+
if (!o) {
|
|
268
|
+
m.current = e, s.current = t, d.current = n;
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const f = m.current, A = s.current, T = d.current;
|
|
272
|
+
e > f && t === A && n !== T && i && e > 0 && r(e - 1, {
|
|
238
273
|
align: "end",
|
|
239
|
-
behavior:
|
|
240
|
-
}),
|
|
241
|
-
}, [e, t, n,
|
|
274
|
+
behavior: o === "smooth" ? "smooth" : "auto"
|
|
275
|
+
}), m.current = e, s.current = t, d.current = n;
|
|
276
|
+
}, [e, t, n, i, r, o]);
|
|
242
277
|
}
|
|
243
|
-
function
|
|
278
|
+
function ce(l) {
|
|
244
279
|
const {
|
|
245
280
|
items: e,
|
|
246
281
|
getKey: t,
|
|
247
282
|
estimatedItemSize: n = 80,
|
|
248
|
-
overscan:
|
|
249
|
-
atBottomThreshold:
|
|
283
|
+
overscan: i = 20,
|
|
284
|
+
atBottomThreshold: r = 200,
|
|
250
285
|
followOutput: o = "auto",
|
|
251
286
|
initialAlignment: m = "bottom",
|
|
252
|
-
onStartReached:
|
|
253
|
-
onEndReached:
|
|
254
|
-
startReachedThreshold:
|
|
255
|
-
endReachedThreshold:
|
|
256
|
-
scrollToMessageKey:
|
|
257
|
-
onScrollToMessageComplete:
|
|
258
|
-
} = l, u =
|
|
287
|
+
onStartReached: s,
|
|
288
|
+
onEndReached: d,
|
|
289
|
+
startReachedThreshold: f = 300,
|
|
290
|
+
endReachedThreshold: A = 300,
|
|
291
|
+
scrollToMessageKey: T,
|
|
292
|
+
onScrollToMessageComplete: R
|
|
293
|
+
} = l, u = G({
|
|
259
294
|
items: e,
|
|
260
295
|
getKey: t,
|
|
261
296
|
estimatedItemSize: n,
|
|
262
|
-
overscan:
|
|
297
|
+
overscan: i,
|
|
263
298
|
initialAlignment: m
|
|
264
|
-
}),
|
|
265
|
-
|
|
299
|
+
}), H = oe(u.scrollerRef, r), { prepareAnchor: v } = se(u.scrollerRef, e.length), K = e.length > 0 ? t(e[0], 0) : null, S = e.length > 0 ? t(e[e.length - 1], e.length - 1) : null;
|
|
300
|
+
ie({
|
|
266
301
|
itemCount: e.length,
|
|
267
|
-
|
|
302
|
+
firstKey: K,
|
|
303
|
+
lastKey: S,
|
|
304
|
+
isAtBottom: H,
|
|
268
305
|
scrollToIndex: u.scrollToIndex,
|
|
269
306
|
mode: o ?? !1
|
|
270
307
|
});
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
const
|
|
274
|
-
if (!
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
308
|
+
const F = y(!1), I = y(m === "top");
|
|
309
|
+
N(() => {
|
|
310
|
+
const p = u.scrollerRef.current;
|
|
311
|
+
if (!p || !s) return;
|
|
312
|
+
const c = () => {
|
|
313
|
+
const g = p.scrollTop;
|
|
314
|
+
!I.current && g > f && (I.current = !0), I.current && g <= f && !F.current && (F.current = !0, Promise.resolve(s()).finally(() => {
|
|
315
|
+
F.current = !1;
|
|
278
316
|
}));
|
|
279
317
|
};
|
|
280
|
-
return
|
|
281
|
-
}, [u.scrollerRef,
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
const
|
|
285
|
-
if (!
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
318
|
+
return p.addEventListener("scroll", c, { passive: !0 }), () => p.removeEventListener("scroll", c);
|
|
319
|
+
}, [u.scrollerRef, s, f, m]);
|
|
320
|
+
const C = y(!1);
|
|
321
|
+
N(() => {
|
|
322
|
+
const p = u.scrollerRef.current;
|
|
323
|
+
if (!p || !d) return;
|
|
324
|
+
const c = () => {
|
|
325
|
+
p.scrollHeight - p.scrollTop - p.clientHeight <= A && !C.current && (C.current = !0, Promise.resolve(d()).finally(() => {
|
|
326
|
+
C.current = !1;
|
|
289
327
|
}));
|
|
290
328
|
};
|
|
291
|
-
return
|
|
292
|
-
}, [u.scrollerRef,
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
if (!
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
}, [
|
|
299
|
-
const
|
|
300
|
-
(
|
|
301
|
-
e.length !== 0 && u.scrollToIndex(e.length - 1, { align: "end", behavior:
|
|
329
|
+
return p.addEventListener("scroll", c, { passive: !0 }), () => p.removeEventListener("scroll", c);
|
|
330
|
+
}, [u.scrollerRef, d, A]);
|
|
331
|
+
const b = y(null);
|
|
332
|
+
N(() => {
|
|
333
|
+
if (!T || b.current === T) return;
|
|
334
|
+
const p = e.findIndex((c, g) => t(c, g) === T);
|
|
335
|
+
p !== -1 && (b.current = T, u.scrollToIndex(p, { align: "center", behavior: "smooth" }), R == null || R());
|
|
336
|
+
}, [T, e, t, u, R]);
|
|
337
|
+
const _ = L(
|
|
338
|
+
(p = "auto") => {
|
|
339
|
+
e.length !== 0 && u.scrollToIndex(e.length - 1, { align: "end", behavior: p });
|
|
302
340
|
},
|
|
303
341
|
[e.length, u]
|
|
304
|
-
),
|
|
305
|
-
(
|
|
306
|
-
const
|
|
307
|
-
|
|
342
|
+
), w = L(
|
|
343
|
+
(p, c) => {
|
|
344
|
+
const g = e.findIndex((x, P) => t(x, P) === p);
|
|
345
|
+
g !== -1 && u.scrollToIndex(g, c);
|
|
308
346
|
},
|
|
309
347
|
[e, t, u]
|
|
310
348
|
);
|
|
311
349
|
return {
|
|
312
350
|
scrollerRef: u.scrollerRef,
|
|
351
|
+
innerRef: u.innerRef,
|
|
313
352
|
virtualItems: u.virtualItems,
|
|
314
353
|
totalSize: u.totalSize,
|
|
315
354
|
measureItem: u.measureItem,
|
|
316
355
|
scrollToIndex: u.scrollToIndex,
|
|
317
|
-
scrollToBottom:
|
|
318
|
-
scrollToKey:
|
|
319
|
-
isAtBottom:
|
|
320
|
-
prepareAnchor:
|
|
356
|
+
scrollToBottom: _,
|
|
357
|
+
scrollToKey: w,
|
|
358
|
+
isAtBottom: H,
|
|
359
|
+
prepareAnchor: v
|
|
321
360
|
};
|
|
322
361
|
}
|
|
323
|
-
function
|
|
362
|
+
function J({
|
|
324
363
|
virtualItem: l,
|
|
325
364
|
measureItem: e,
|
|
326
365
|
children: t
|
|
327
366
|
}) {
|
|
328
|
-
const n =
|
|
329
|
-
return
|
|
330
|
-
const
|
|
331
|
-
if (!
|
|
332
|
-
const
|
|
367
|
+
const n = y(null);
|
|
368
|
+
return N(() => {
|
|
369
|
+
const i = n.current;
|
|
370
|
+
if (!i) return;
|
|
371
|
+
const r = new ResizeObserver(([o]) => {
|
|
333
372
|
o && e(l.key, o.contentRect.height);
|
|
334
373
|
});
|
|
335
|
-
return
|
|
336
|
-
}, [l.key, e]), /* @__PURE__ */
|
|
374
|
+
return r.observe(i), () => r.disconnect();
|
|
375
|
+
}, [l.key, e]), /* @__PURE__ */ B(
|
|
337
376
|
"div",
|
|
338
377
|
{
|
|
339
378
|
ref: n,
|
|
@@ -350,234 +389,237 @@ function Y({
|
|
|
350
389
|
}
|
|
351
390
|
);
|
|
352
391
|
}
|
|
353
|
-
function
|
|
392
|
+
function le(l, e) {
|
|
354
393
|
const {
|
|
355
394
|
data: t,
|
|
356
395
|
itemContent: n,
|
|
357
|
-
computeItemKey:
|
|
358
|
-
estimatedItemSize:
|
|
396
|
+
computeItemKey: i,
|
|
397
|
+
estimatedItemSize: r = 80,
|
|
359
398
|
overscan: o = 20,
|
|
360
399
|
followOutput: m = "auto",
|
|
361
|
-
atBottomThreshold:
|
|
362
|
-
initialAlignment:
|
|
363
|
-
onStartReached:
|
|
364
|
-
onEndReached:
|
|
365
|
-
startReachedThreshold:
|
|
366
|
-
endReachedThreshold:
|
|
400
|
+
atBottomThreshold: s = 200,
|
|
401
|
+
initialAlignment: d = "bottom",
|
|
402
|
+
onStartReached: f,
|
|
403
|
+
onEndReached: A,
|
|
404
|
+
startReachedThreshold: T = 300,
|
|
405
|
+
endReachedThreshold: R = 300,
|
|
367
406
|
scrollToMessageKey: u,
|
|
368
|
-
onScrollToMessageComplete:
|
|
369
|
-
onAtBottomChange:
|
|
370
|
-
components:
|
|
371
|
-
className:
|
|
372
|
-
style:
|
|
407
|
+
onScrollToMessageComplete: H,
|
|
408
|
+
onAtBottomChange: v,
|
|
409
|
+
components: K = {},
|
|
410
|
+
className: S,
|
|
411
|
+
style: F
|
|
373
412
|
} = l, {
|
|
374
|
-
scrollerRef:
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
413
|
+
scrollerRef: I,
|
|
414
|
+
innerRef: C,
|
|
415
|
+
virtualItems: b,
|
|
416
|
+
totalSize: _,
|
|
417
|
+
measureItem: w,
|
|
418
|
+
scrollToIndex: p,
|
|
419
|
+
scrollToBottom: c,
|
|
420
|
+
scrollToKey: g,
|
|
421
|
+
isAtBottom: x,
|
|
422
|
+
prepareAnchor: P
|
|
423
|
+
} = ce({
|
|
384
424
|
items: t,
|
|
385
|
-
getKey: (
|
|
386
|
-
estimatedItemSize:
|
|
425
|
+
getKey: (z, k) => i(k, z),
|
|
426
|
+
estimatedItemSize: r,
|
|
387
427
|
overscan: o,
|
|
388
|
-
atBottomThreshold:
|
|
428
|
+
atBottomThreshold: s,
|
|
389
429
|
followOutput: m,
|
|
390
|
-
initialAlignment:
|
|
391
|
-
onStartReached:
|
|
392
|
-
onEndReached:
|
|
393
|
-
startReachedThreshold:
|
|
394
|
-
endReachedThreshold:
|
|
430
|
+
initialAlignment: d,
|
|
431
|
+
onStartReached: f,
|
|
432
|
+
onEndReached: A,
|
|
433
|
+
startReachedThreshold: T,
|
|
434
|
+
endReachedThreshold: R,
|
|
395
435
|
scrollToMessageKey: u,
|
|
396
|
-
onScrollToMessageComplete:
|
|
397
|
-
}),
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
}, [
|
|
436
|
+
onScrollToMessageComplete: H
|
|
437
|
+
}), j = U.useRef(x);
|
|
438
|
+
U.useEffect(() => {
|
|
439
|
+
j.current !== x && (j.current = x, v == null || v(x));
|
|
440
|
+
}, [x, v]), W(
|
|
401
441
|
e,
|
|
402
442
|
() => ({
|
|
403
|
-
scrollToBottom:
|
|
404
|
-
scrollToIndex:
|
|
405
|
-
scrollToKey:
|
|
443
|
+
scrollToBottom: c,
|
|
444
|
+
scrollToIndex: p,
|
|
445
|
+
scrollToKey: g,
|
|
406
446
|
getScrollTop: () => {
|
|
407
|
-
var
|
|
408
|
-
return ((
|
|
447
|
+
var z;
|
|
448
|
+
return ((z = I.current) == null ? void 0 : z.scrollTop) ?? 0;
|
|
409
449
|
},
|
|
410
|
-
isAtBottom: () =>
|
|
411
|
-
prepareAnchor:
|
|
450
|
+
isAtBottom: () => x,
|
|
451
|
+
prepareAnchor: P
|
|
412
452
|
}),
|
|
413
|
-
[
|
|
453
|
+
[c, p, g, I, x, P]
|
|
414
454
|
);
|
|
415
|
-
const { Header:
|
|
416
|
-
return t.length === 0 &&
|
|
455
|
+
const { Header: q, Footer: a, EmptyPlaceholder: h } = K;
|
|
456
|
+
return t.length === 0 && h ? /* @__PURE__ */ B(h, {}) : /* @__PURE__ */ $(
|
|
417
457
|
"div",
|
|
418
458
|
{
|
|
419
|
-
ref:
|
|
420
|
-
className:
|
|
459
|
+
ref: I,
|
|
460
|
+
className: S,
|
|
421
461
|
style: {
|
|
422
462
|
overflow: "auto",
|
|
423
463
|
height: "100%",
|
|
424
464
|
position: "relative",
|
|
425
|
-
|
|
465
|
+
overscrollBehaviorY: "contain",
|
|
466
|
+
...F
|
|
426
467
|
},
|
|
427
468
|
children: [
|
|
428
|
-
|
|
429
|
-
/* @__PURE__ */
|
|
430
|
-
|
|
469
|
+
q && /* @__PURE__ */ B(q, {}),
|
|
470
|
+
/* @__PURE__ */ B("div", { ref: C, style: { height: _, position: "relative", width: "100%" }, children: b.map((z) => /* @__PURE__ */ B(
|
|
471
|
+
J,
|
|
431
472
|
{
|
|
432
|
-
virtualItem:
|
|
433
|
-
measureItem:
|
|
434
|
-
children: n(
|
|
473
|
+
virtualItem: z,
|
|
474
|
+
measureItem: w,
|
|
475
|
+
children: n(z.index, z.data)
|
|
435
476
|
},
|
|
436
|
-
|
|
477
|
+
z.key
|
|
437
478
|
)) }),
|
|
438
|
-
|
|
479
|
+
a && /* @__PURE__ */ B(a, {})
|
|
439
480
|
]
|
|
440
481
|
}
|
|
441
482
|
);
|
|
442
483
|
}
|
|
443
|
-
const
|
|
444
|
-
function
|
|
484
|
+
const fe = Q(le);
|
|
485
|
+
function he({
|
|
445
486
|
data: l,
|
|
446
487
|
itemContent: e,
|
|
447
488
|
computeItemKey: t,
|
|
448
489
|
estimatedItemSize: n = 60,
|
|
449
|
-
overscan:
|
|
450
|
-
onEndReached:
|
|
490
|
+
overscan: i = 20,
|
|
491
|
+
onEndReached: r,
|
|
451
492
|
endReachedThreshold: o = 300,
|
|
452
493
|
components: m = {},
|
|
453
|
-
className:
|
|
454
|
-
style:
|
|
494
|
+
className: s,
|
|
495
|
+
style: d
|
|
455
496
|
}) {
|
|
456
|
-
const { scrollerRef:
|
|
497
|
+
const { scrollerRef: f, innerRef: A, virtualItems: T, totalSize: R, measureItem: u } = G({
|
|
457
498
|
items: l,
|
|
458
|
-
getKey: (
|
|
499
|
+
getKey: (S, F) => t(F, S),
|
|
459
500
|
estimatedItemSize: n,
|
|
460
|
-
overscan:
|
|
501
|
+
overscan: i,
|
|
461
502
|
initialAlignment: "top"
|
|
462
503
|
});
|
|
463
|
-
|
|
464
|
-
const
|
|
465
|
-
if (!
|
|
466
|
-
let
|
|
467
|
-
const
|
|
468
|
-
|
|
469
|
-
|
|
504
|
+
U.useEffect(() => {
|
|
505
|
+
const S = f.current;
|
|
506
|
+
if (!S || !r) return;
|
|
507
|
+
let F = !1;
|
|
508
|
+
const I = () => {
|
|
509
|
+
S.scrollHeight - S.scrollTop - S.clientHeight <= o && !F && (F = !0, Promise.resolve(r()).finally(() => {
|
|
510
|
+
F = !1;
|
|
470
511
|
}));
|
|
471
512
|
};
|
|
472
|
-
return
|
|
473
|
-
}, [
|
|
474
|
-
const { Header:
|
|
475
|
-
return l.length === 0 &&
|
|
513
|
+
return S.addEventListener("scroll", I, { passive: !0 }), () => S.removeEventListener("scroll", I);
|
|
514
|
+
}, [f, r, o]);
|
|
515
|
+
const { Header: H, Footer: v, EmptyPlaceholder: K } = m;
|
|
516
|
+
return l.length === 0 && K ? /* @__PURE__ */ B(K, {}) : /* @__PURE__ */ $(
|
|
476
517
|
"div",
|
|
477
518
|
{
|
|
478
|
-
ref:
|
|
479
|
-
className:
|
|
519
|
+
ref: f,
|
|
520
|
+
className: s,
|
|
480
521
|
style: {
|
|
481
522
|
overflow: "auto",
|
|
482
523
|
height: "100%",
|
|
483
524
|
position: "relative",
|
|
484
|
-
|
|
525
|
+
overscrollBehaviorY: "contain",
|
|
526
|
+
...d
|
|
485
527
|
},
|
|
486
528
|
children: [
|
|
487
|
-
|
|
488
|
-
/* @__PURE__ */
|
|
489
|
-
|
|
529
|
+
H && /* @__PURE__ */ B(H, {}),
|
|
530
|
+
/* @__PURE__ */ B("div", { ref: A, style: { height: R, position: "relative", width: "100%" }, children: T.map((S) => /* @__PURE__ */ B(
|
|
531
|
+
J,
|
|
490
532
|
{
|
|
491
|
-
virtualItem:
|
|
492
|
-
measureItem:
|
|
493
|
-
children: e(
|
|
533
|
+
virtualItem: S,
|
|
534
|
+
measureItem: u,
|
|
535
|
+
children: e(S.index, S.data)
|
|
494
536
|
},
|
|
495
|
-
|
|
537
|
+
S.key
|
|
496
538
|
)) }),
|
|
497
|
-
|
|
539
|
+
v && /* @__PURE__ */ B(v, {})
|
|
498
540
|
]
|
|
499
541
|
}
|
|
500
542
|
);
|
|
501
543
|
}
|
|
502
|
-
function
|
|
544
|
+
function de(l) {
|
|
503
545
|
const {
|
|
504
546
|
fetcher: e,
|
|
505
547
|
initialPage: t = 1,
|
|
506
548
|
direction: n = "append",
|
|
507
|
-
getKey:
|
|
508
|
-
onPageLoaded:
|
|
549
|
+
getKey: i,
|
|
550
|
+
onPageLoaded: r,
|
|
509
551
|
onError: o
|
|
510
|
-
} = l, [m,
|
|
511
|
-
(
|
|
512
|
-
const
|
|
513
|
-
return
|
|
514
|
-
}) :
|
|
515
|
-
[
|
|
516
|
-
),
|
|
517
|
-
if (!(
|
|
518
|
-
|
|
552
|
+
} = l, [m, s] = V([]), [d, f] = V(t), [A, T] = V(!0), [R, u] = V(!1), [H, v] = V(!1), [K, S] = V(!1), F = y(/* @__PURE__ */ new Set()), I = y(!1), C = L(
|
|
553
|
+
(c) => i ? c.filter((g) => {
|
|
554
|
+
const x = i(g);
|
|
555
|
+
return F.current.has(x) ? !1 : (F.current.add(x), !0);
|
|
556
|
+
}) : c,
|
|
557
|
+
[i]
|
|
558
|
+
), b = L(async () => {
|
|
559
|
+
if (!(I.current || !A)) {
|
|
560
|
+
I.current = !0, S(!0);
|
|
519
561
|
try {
|
|
520
|
-
const
|
|
521
|
-
|
|
522
|
-
(
|
|
523
|
-
),
|
|
524
|
-
} catch (
|
|
525
|
-
o == null || o(
|
|
562
|
+
const c = d + 1, g = await e(c), x = C(g.data);
|
|
563
|
+
s(
|
|
564
|
+
(P) => n === "prepend" ? [...x, ...P] : [...P, ...x]
|
|
565
|
+
), f(c), T(g.hasNextPage), u(g.hasPrevPage), r == null || r(c, x);
|
|
566
|
+
} catch (c) {
|
|
567
|
+
o == null || o(c instanceof Error ? c : new Error(String(c)));
|
|
526
568
|
} finally {
|
|
527
|
-
|
|
569
|
+
S(!1), I.current = !1;
|
|
528
570
|
}
|
|
529
571
|
}
|
|
530
|
-
}, [
|
|
531
|
-
if (!(
|
|
532
|
-
|
|
572
|
+
}, [d, A, e, C, n, r, o]), _ = L(async () => {
|
|
573
|
+
if (!(I.current || !R)) {
|
|
574
|
+
I.current = !0, S(!0);
|
|
533
575
|
try {
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
} catch (
|
|
537
|
-
o == null || o(
|
|
576
|
+
const c = d - 1, g = await e(c), x = C(g.data);
|
|
577
|
+
s((P) => [...x, ...P]), f(c), u(g.hasPrevPage), T(g.hasNextPage), r == null || r(c, x);
|
|
578
|
+
} catch (c) {
|
|
579
|
+
o == null || o(c instanceof Error ? c : new Error(String(c)));
|
|
538
580
|
} finally {
|
|
539
|
-
|
|
581
|
+
S(!1), I.current = !1;
|
|
540
582
|
}
|
|
541
583
|
}
|
|
542
|
-
}, [
|
|
543
|
-
if (!
|
|
544
|
-
|
|
584
|
+
}, [d, R, e, C, r, o]), w = L(async () => {
|
|
585
|
+
if (!I.current) {
|
|
586
|
+
I.current = !0, v(!0);
|
|
545
587
|
try {
|
|
546
|
-
const
|
|
547
|
-
if (
|
|
548
|
-
const
|
|
549
|
-
|
|
550
|
-
const
|
|
551
|
-
return n === "prepend" ? [...
|
|
588
|
+
const c = await e(t), g = c.data;
|
|
589
|
+
if (i) {
|
|
590
|
+
const x = new Set(g.map(i));
|
|
591
|
+
g.forEach((P) => F.current.add(i(P))), s((P) => {
|
|
592
|
+
const j = P.filter((q) => !x.has(i(q)));
|
|
593
|
+
return n === "prepend" ? [...g, ...j] : [...j, ...g];
|
|
552
594
|
});
|
|
553
595
|
} else
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
} catch (
|
|
557
|
-
o == null || o(
|
|
596
|
+
s(g);
|
|
597
|
+
f(t), T(c.hasNextPage), u(c.hasPrevPage), r == null || r(t, g);
|
|
598
|
+
} catch (c) {
|
|
599
|
+
o == null || o(c instanceof Error ? c : new Error(String(c)));
|
|
558
600
|
} finally {
|
|
559
|
-
|
|
601
|
+
v(!1), I.current = !1;
|
|
560
602
|
}
|
|
561
603
|
}
|
|
562
|
-
}, [e, t,
|
|
563
|
-
|
|
604
|
+
}, [e, t, i, n, r, o]), p = L(() => {
|
|
605
|
+
s([]), f(t), T(!0), u(!1), v(!1), S(!1), F.current.clear(), I.current = !1;
|
|
564
606
|
}, [t]);
|
|
565
607
|
return {
|
|
566
608
|
items: m,
|
|
567
|
-
loadNextPage:
|
|
568
|
-
loadPrevPage:
|
|
569
|
-
hasNextPage:
|
|
570
|
-
hasPrevPage:
|
|
571
|
-
loading:
|
|
572
|
-
loadingMore:
|
|
573
|
-
refresh:
|
|
574
|
-
reset:
|
|
575
|
-
currentPage:
|
|
609
|
+
loadNextPage: b,
|
|
610
|
+
loadPrevPage: _,
|
|
611
|
+
hasNextPage: A,
|
|
612
|
+
hasPrevPage: R,
|
|
613
|
+
loading: H,
|
|
614
|
+
loadingMore: K,
|
|
615
|
+
refresh: w,
|
|
616
|
+
reset: p,
|
|
617
|
+
currentPage: d
|
|
576
618
|
};
|
|
577
619
|
}
|
|
578
620
|
export {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
621
|
+
fe as ChatVirtualList,
|
|
622
|
+
he as VirtualList,
|
|
623
|
+
ce as useChatVirtualizer,
|
|
624
|
+
de as usePagination
|
|
583
625
|
};
|