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