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