@rpcbase/ui 0.281.0 → 0.283.0
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/dist/components/AddressAutocompleteInput/index.d.ts.map +1 -1
- package/dist/index13.js +0 -1
- package/dist/index13.js.map +1 -1
- package/dist/index14.js +88 -88
- package/dist/index14.js.map +1 -1
- package/dist/index15.js.map +1 -1
- package/dist/index16.js +45 -37
- package/dist/index16.js.map +1 -1
- package/dist/index182.js +162 -145
- package/dist/index182.js.map +1 -1
- package/dist/index294.js +27 -16
- package/dist/index294.js.map +1 -1
- package/dist/index296.js +83 -56
- package/dist/index296.js.map +1 -1
- package/dist/index298.js.map +1 -1
- package/dist/index299.js +18 -12
- package/dist/index299.js.map +1 -1
- package/dist/index300.js +352 -255
- package/dist/index300.js.map +1 -1
- package/dist/index301.js.map +1 -1
- package/dist/index356.js.map +1 -1
- package/dist/index358.js.map +1 -1
- package/dist/index361.js.map +1 -1
- package/dist/index362.js.map +1 -1
- package/dist/index4.js.map +1 -1
- package/dist/index416.js +62 -40
- package/dist/index416.js.map +1 -1
- package/dist/index417.js.map +1 -1
- package/dist/index419.js.map +1 -1
- package/dist/index420.js.map +1 -1
- package/dist/index421.js.map +1 -1
- package/dist/index6.js.map +1 -1
- package/dist/index7.js +133 -91
- package/dist/index7.js.map +1 -1
- package/dist/index8.js.map +1 -1
- package/dist/index9.js +19 -16
- package/dist/index9.js.map +1 -1
- package/package.json +3 -5
package/dist/index7.js
CHANGED
|
@@ -1,76 +1,93 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as e } from "react/compiler-runtime";
|
|
2
|
+
import { useEffect as t, useRef as n, useState as r } from "react";
|
|
2
3
|
//#region src/helpers/useScrollPagination.ts
|
|
3
|
-
var
|
|
4
|
+
var i = () => typeof window > "u" ? !1 : "IntersectionObserver" in window, ee = (e, t, n) => {
|
|
4
5
|
let r = e.getBoundingClientRect(), i = t.getBoundingClientRect();
|
|
5
6
|
return r.bottom >= i.top - n && r.top <= i.bottom;
|
|
6
|
-
},
|
|
7
|
+
}, te = (e, t, n) => {
|
|
7
8
|
let r = e.getBoundingClientRect(), i = t.getBoundingClientRect();
|
|
8
9
|
return r.top <= i.bottom + n && r.bottom >= i.top;
|
|
9
10
|
};
|
|
10
|
-
function
|
|
11
|
-
let [h,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}, [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}, [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}, [u]),
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}, [
|
|
27
|
-
let N
|
|
28
|
-
|
|
29
|
-
|
|
11
|
+
function ne(ne) {
|
|
12
|
+
let a = e(96), { containerRef: o, enabled: ie, hasPreviousPage: ae, hasNextPage: oe, onStartReached: s, onEndReached: c, startReachedOffsetPx: se, endReachedOffsetPx: ce, maintainScrollOnStartFetch: le } = ne, l = ie === void 0 || ie, u = ae !== void 0 && ae, d = oe !== void 0 && oe, f = se === void 0 ? 160 : se, p = ce === void 0 ? 160 : ce, m = le === void 0 || le, [h, ue] = r(null), [g, de] = r(null), [_, fe] = r(!1), [v, pe] = r(!1), y = n(!1), b = n(!1), x = n(!0), S = n(!0), me = n(u), he = n(d), ge = n(u), _e = n(d), C = n(s), ve = n(c), w, T;
|
|
13
|
+
a[0] === _ ? (w = a[1], T = a[2]) : (w = () => {
|
|
14
|
+
y.current = _;
|
|
15
|
+
}, T = [_], a[0] = _, a[1] = w, a[2] = T), t(w, T);
|
|
16
|
+
let E, D;
|
|
17
|
+
a[3] === v ? (E = a[4], D = a[5]) : (D = () => {
|
|
18
|
+
b.current = v;
|
|
19
|
+
}, E = [v], a[3] = v, a[4] = E, a[5] = D), t(D, E);
|
|
20
|
+
let O, k;
|
|
21
|
+
a[6] === u ? (O = a[7], k = a[8]) : (O = () => {
|
|
22
|
+
me.current = u;
|
|
23
|
+
}, k = [u], a[6] = u, a[7] = O, a[8] = k), t(O, k);
|
|
24
|
+
let A, j;
|
|
25
|
+
a[9] === d ? (A = a[10], j = a[11]) : (A = () => {
|
|
26
|
+
he.current = d;
|
|
27
|
+
}, j = [d], a[9] = d, a[10] = A, a[11] = j), t(A, j);
|
|
28
|
+
let M, N;
|
|
29
|
+
a[12] === s ? (M = a[13], N = a[14]) : (M = () => {
|
|
30
|
+
C.current = s;
|
|
31
|
+
}, N = [s], a[12] = s, a[13] = M, a[14] = N), t(M, N);
|
|
32
|
+
let P, F;
|
|
33
|
+
a[15] === c ? (P = a[16], F = a[17]) : (P = () => {
|
|
34
|
+
ve.current = c;
|
|
35
|
+
}, F = [c], a[15] = c, a[16] = P, a[17] = F), t(P, F);
|
|
36
|
+
let I;
|
|
37
|
+
a[18] === Symbol.for("react.memo_cache_sentinel") ? (I = () => {
|
|
38
|
+
x.current = !0, S.current = !0;
|
|
39
|
+
}, a[18] = I) : I = a[18];
|
|
40
|
+
let L;
|
|
41
|
+
a[19] === l ? L = a[20] : (L = [l], a[19] = l, a[20] = L), t(I, L);
|
|
42
|
+
let R;
|
|
43
|
+
a[21] === m ? R = a[22] : (R = (e) => {
|
|
44
|
+
if (!me.current || !C.current || !x.current || y.current || b.current) return;
|
|
45
|
+
x.current = !1, y.current = !0, fe(!0);
|
|
30
46
|
let t = e.scrollTop, n = e.scrollHeight;
|
|
31
|
-
Promise.resolve(
|
|
47
|
+
Promise.resolve(C.current()).then(async () => {
|
|
32
48
|
if (!m || !e.isConnected) return;
|
|
33
|
-
await new Promise(
|
|
34
|
-
window.requestAnimationFrame(() => {
|
|
35
|
-
window.requestAnimationFrame(() => e());
|
|
36
|
-
});
|
|
37
|
-
});
|
|
49
|
+
await new Promise(re);
|
|
38
50
|
let r = e.scrollHeight - n;
|
|
39
51
|
r <= 0 || (e.scrollTop = t + r);
|
|
40
52
|
}).finally(() => {
|
|
41
|
-
|
|
53
|
+
y.current = !1, fe(!1);
|
|
42
54
|
});
|
|
43
|
-
},
|
|
55
|
+
}, a[21] = m, a[22] = R);
|
|
56
|
+
let z = R, B;
|
|
57
|
+
a[23] !== o || a[24] !== p || a[25] !== g ? (B = () => {
|
|
44
58
|
let e = o.current;
|
|
45
|
-
return !e || !
|
|
46
|
-
},
|
|
47
|
-
|
|
59
|
+
return !e || !g ? !1 : te(g, e, Math.max(0, p));
|
|
60
|
+
}, a[23] = o, a[24] = p, a[25] = g, a[26] = B) : B = a[26];
|
|
61
|
+
let V = B, H;
|
|
62
|
+
a[27] !== o || a[28] !== V ? (H = () => {
|
|
63
|
+
if (!he.current || !ve.current || !S.current || b.current || y.current) return;
|
|
48
64
|
let e = o.current?.scrollHeight;
|
|
49
|
-
|
|
65
|
+
S.current = !1, b.current = !0, pe(!0);
|
|
50
66
|
let t;
|
|
51
|
-
Promise.resolve(
|
|
67
|
+
Promise.resolve(ve.current()).then((e) => {
|
|
52
68
|
t = e;
|
|
53
69
|
}).finally(() => {
|
|
54
|
-
|
|
70
|
+
b.current = !1, pe(!1), S.current = !0, t !== !1 && window.requestAnimationFrame(() => {
|
|
55
71
|
window.requestAnimationFrame(() => {
|
|
56
72
|
let t = o.current;
|
|
57
|
-
t && (!(typeof e == "number" && t.scrollHeight > e) || !
|
|
73
|
+
t && (!(typeof e == "number" && t.scrollHeight > e) || !he.current || !V() || H());
|
|
58
74
|
});
|
|
59
75
|
});
|
|
60
76
|
});
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
|
|
77
|
+
}, a[27] = o, a[28] = V, a[29] = H) : H = a[29];
|
|
78
|
+
let U;
|
|
79
|
+
a[30] !== o || a[31] !== l || a[32] !== z || a[33] !== f || a[34] !== h ? (U = () => {
|
|
80
|
+
if (!l || !i()) return;
|
|
64
81
|
let e = o.current;
|
|
65
82
|
if (!e || !h) return;
|
|
66
83
|
let t = new IntersectionObserver((t) => {
|
|
67
84
|
let n = t[0];
|
|
68
85
|
if (n) {
|
|
69
86
|
if (!n.isIntersecting) {
|
|
70
|
-
|
|
87
|
+
x.current = !0;
|
|
71
88
|
return;
|
|
72
89
|
}
|
|
73
|
-
|
|
90
|
+
z(e);
|
|
74
91
|
}
|
|
75
92
|
}, {
|
|
76
93
|
root: e,
|
|
@@ -80,81 +97,97 @@ function o({ containerRef: o, enabled: s = !0, hasPreviousPage: c = !1, hasNextP
|
|
|
80
97
|
return t.observe(h), () => {
|
|
81
98
|
t.disconnect();
|
|
82
99
|
};
|
|
83
|
-
}, [
|
|
100
|
+
}, a[30] = o, a[31] = l, a[32] = z, a[33] = f, a[34] = h, a[35] = U) : U = a[35];
|
|
101
|
+
let W;
|
|
102
|
+
a[36] !== o || a[37] !== l || a[38] !== m || a[39] !== f || a[40] !== h ? (W = [
|
|
84
103
|
o,
|
|
85
|
-
|
|
104
|
+
l,
|
|
86
105
|
m,
|
|
87
106
|
f,
|
|
88
107
|
h
|
|
89
|
-
]),
|
|
90
|
-
|
|
108
|
+
], a[36] = o, a[37] = l, a[38] = m, a[39] = f, a[40] = h, a[41] = W) : W = a[41], t(U, W);
|
|
109
|
+
let G;
|
|
110
|
+
a[42] !== o || a[43] !== l || a[44] !== u || a[45] !== z || a[46] !== f || a[47] !== h ? (G = () => {
|
|
111
|
+
if (!l) return;
|
|
91
112
|
let e = o.current;
|
|
92
113
|
if (!e || !h) return;
|
|
93
|
-
let t =
|
|
94
|
-
if (
|
|
95
|
-
if (!
|
|
96
|
-
|
|
114
|
+
let t = ge.current;
|
|
115
|
+
if (ge.current = u, !(!u || t)) {
|
|
116
|
+
if (!ee(h, e, Math.max(0, f))) {
|
|
117
|
+
x.current = !0;
|
|
97
118
|
return;
|
|
98
119
|
}
|
|
99
|
-
|
|
120
|
+
z(e);
|
|
100
121
|
}
|
|
101
|
-
}, [
|
|
122
|
+
}, a[42] = o, a[43] = l, a[44] = u, a[45] = z, a[46] = f, a[47] = h, a[48] = G) : G = a[48];
|
|
123
|
+
let K;
|
|
124
|
+
a[49] !== o || a[50] !== l || a[51] !== u || a[52] !== m || a[53] !== f || a[54] !== h ? (K = [
|
|
102
125
|
o,
|
|
103
|
-
|
|
104
|
-
|
|
126
|
+
l,
|
|
127
|
+
u,
|
|
105
128
|
m,
|
|
106
129
|
f,
|
|
107
130
|
h
|
|
108
|
-
]),
|
|
109
|
-
|
|
131
|
+
], a[49] = o, a[50] = l, a[51] = u, a[52] = m, a[53] = f, a[54] = h, a[55] = K) : K = a[55], t(G, K);
|
|
132
|
+
let q;
|
|
133
|
+
a[56] !== o || a[57] !== l || a[58] !== p || a[59] !== g || a[60] !== H ? (q = () => {
|
|
134
|
+
if (!l || !i()) return;
|
|
110
135
|
let e = o.current;
|
|
111
|
-
if (!e || !
|
|
136
|
+
if (!e || !g) return;
|
|
112
137
|
let t = new IntersectionObserver((e) => {
|
|
113
138
|
let t = e[0];
|
|
114
139
|
if (t) {
|
|
115
140
|
if (!t.isIntersecting) {
|
|
116
|
-
|
|
141
|
+
S.current = !0;
|
|
117
142
|
return;
|
|
118
143
|
}
|
|
119
|
-
|
|
144
|
+
H();
|
|
120
145
|
}
|
|
121
146
|
}, {
|
|
122
147
|
root: e,
|
|
123
148
|
rootMargin: `0px 0px ${Math.max(0, p)}px 0px`,
|
|
124
149
|
threshold: 0
|
|
125
150
|
});
|
|
126
|
-
return t.observe(
|
|
151
|
+
return t.observe(g), () => {
|
|
127
152
|
t.disconnect();
|
|
128
153
|
};
|
|
129
|
-
}, [
|
|
154
|
+
}, a[56] = o, a[57] = l, a[58] = p, a[59] = g, a[60] = H, a[61] = q) : q = a[61];
|
|
155
|
+
let J;
|
|
156
|
+
a[62] !== o || a[63] !== l || a[64] !== p || a[65] !== g ? (J = [
|
|
130
157
|
o,
|
|
131
|
-
|
|
158
|
+
l,
|
|
132
159
|
p,
|
|
133
|
-
|
|
134
|
-
]),
|
|
135
|
-
|
|
160
|
+
g
|
|
161
|
+
], a[62] = o, a[63] = l, a[64] = p, a[65] = g, a[66] = J) : J = a[66], t(q, J);
|
|
162
|
+
let Y;
|
|
163
|
+
a[67] !== o || a[68] !== l || a[69] !== p || a[70] !== g || a[71] !== d || a[72] !== H ? (Y = () => {
|
|
164
|
+
if (!l) return;
|
|
136
165
|
let e = o.current;
|
|
137
|
-
if (!e || !
|
|
138
|
-
let t =
|
|
139
|
-
if (
|
|
140
|
-
if (!
|
|
141
|
-
|
|
166
|
+
if (!e || !g) return;
|
|
167
|
+
let t = _e.current;
|
|
168
|
+
if (_e.current = d, !(!d || t)) {
|
|
169
|
+
if (!te(g, e, Math.max(0, p))) {
|
|
170
|
+
S.current = !0;
|
|
142
171
|
return;
|
|
143
172
|
}
|
|
144
|
-
|
|
173
|
+
H();
|
|
145
174
|
}
|
|
146
|
-
}, [
|
|
175
|
+
}, a[67] = o, a[68] = l, a[69] = p, a[70] = g, a[71] = d, a[72] = H, a[73] = Y) : Y = a[73];
|
|
176
|
+
let X;
|
|
177
|
+
a[74] !== o || a[75] !== l || a[76] !== p || a[77] !== g || a[78] !== d ? (X = [
|
|
147
178
|
o,
|
|
148
|
-
|
|
179
|
+
l,
|
|
149
180
|
p,
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
]),
|
|
153
|
-
|
|
181
|
+
g,
|
|
182
|
+
d
|
|
183
|
+
], a[74] = o, a[75] = l, a[76] = p, a[77] = g, a[78] = d, a[79] = X) : X = a[79], t(Y, X);
|
|
184
|
+
let Z;
|
|
185
|
+
a[80] !== o || a[81] !== l || a[82] !== g || a[83] !== d || a[84] !== V || a[85] !== H ? (Z = () => {
|
|
186
|
+
if (!l || !d) return;
|
|
154
187
|
let e = o.current;
|
|
155
|
-
if (!e || !
|
|
188
|
+
if (!e || !g) return;
|
|
156
189
|
let t = () => {
|
|
157
|
-
|
|
190
|
+
V() && H();
|
|
158
191
|
}, n = () => {
|
|
159
192
|
t();
|
|
160
193
|
}, r = () => {
|
|
@@ -165,20 +198,29 @@ function o({ containerRef: o, enabled: s = !0, hasPreviousPage: c = !1, hasNextP
|
|
|
165
198
|
return e.addEventListener("scroll", n, { passive: !0 }), window.addEventListener("resize", r), () => {
|
|
166
199
|
e.removeEventListener("scroll", n), window.removeEventListener("resize", r);
|
|
167
200
|
};
|
|
168
|
-
}, [
|
|
201
|
+
}, a[80] = o, a[81] = l, a[82] = g, a[83] = d, a[84] = V, a[85] = H, a[86] = Z) : Z = a[86];
|
|
202
|
+
let Q;
|
|
203
|
+
a[87] !== o || a[88] !== l || a[89] !== p || a[90] !== g || a[91] !== d ? (Q = [
|
|
169
204
|
o,
|
|
170
|
-
|
|
205
|
+
l,
|
|
171
206
|
p,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
]),
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
207
|
+
g,
|
|
208
|
+
d
|
|
209
|
+
], a[87] = o, a[88] = l, a[89] = p, a[90] = g, a[91] = d, a[92] = Q) : Q = a[92], t(Z, Q);
|
|
210
|
+
let $;
|
|
211
|
+
return a[93] !== v || a[94] !== _ ? ($ = {
|
|
212
|
+
startSentinelRef: ue,
|
|
213
|
+
endSentinelRef: de,
|
|
214
|
+
isFetchingPrevious: _,
|
|
215
|
+
isFetchingNext: v
|
|
216
|
+
}, a[93] = v, a[94] = _, a[95] = $) : $ = a[95], $;
|
|
217
|
+
}
|
|
218
|
+
function re(e) {
|
|
219
|
+
window.requestAnimationFrame(() => {
|
|
220
|
+
window.requestAnimationFrame(() => e());
|
|
221
|
+
});
|
|
180
222
|
}
|
|
181
223
|
//#endregion
|
|
182
|
-
export {
|
|
224
|
+
export { ne as useScrollPagination };
|
|
183
225
|
|
|
184
226
|
//# sourceMappingURL=index7.js.map
|
package/dist/index7.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index7.js","names":["root","previousScrollHeight","resolvedOffsetPx","observer","entries","entry"],"sources":["../src/helpers/useScrollPagination.ts"],"sourcesContent":["import { useEffect, useRef, useState, type RefObject } from \"react\"\n\n\ntype MaybePromise<T> = T | Promise<T>\n\ntype ReachCallback = () => MaybePromise<boolean | void>\n\nexport type UseScrollPaginationOptions = {\n containerRef: RefObject<HTMLElement | null>\n enabled?: boolean\n hasPreviousPage?: boolean\n hasNextPage?: boolean\n onStartReached?: ReachCallback\n onEndReached?: ReachCallback\n startReachedOffsetPx?: number\n endReachedOffsetPx?: number\n maintainScrollOnStartFetch?: boolean\n}\n\nexport type UseScrollPaginationResult = {\n startSentinelRef: (node: Element | null) => void\n endSentinelRef: (node: Element | null) => void\n isFetchingPrevious: boolean\n isFetchingNext: boolean\n}\n\nconst supportsIntersectionObserver = () => {\n if (typeof window === \"undefined\") return false\n return \"IntersectionObserver\" in window\n}\n\nconst isWithinStartRange = (target: Element, root: HTMLElement, offsetPx: number) => {\n const targetRect = target.getBoundingClientRect()\n const rootRect = root.getBoundingClientRect()\n return targetRect.bottom >= rootRect.top - offsetPx && targetRect.top <= rootRect.bottom\n}\n\nconst isWithinEndRange = (target: Element, root: HTMLElement, offsetPx: number) => {\n const targetRect = target.getBoundingClientRect()\n const rootRect = root.getBoundingClientRect()\n return targetRect.top <= rootRect.bottom + offsetPx && targetRect.bottom >= rootRect.top\n}\n\nexport function useScrollPagination({\n containerRef,\n enabled = true,\n hasPreviousPage = false,\n hasNextPage = false,\n onStartReached,\n onEndReached,\n startReachedOffsetPx = 160,\n endReachedOffsetPx = 160,\n maintainScrollOnStartFetch = true,\n}: UseScrollPaginationOptions): UseScrollPaginationResult {\n const [startSentinel, setStartSentinel] = useState<Element | null>(null)\n const [endSentinel, setEndSentinel] = useState<Element | null>(null)\n const [isFetchingPrevious, setIsFetchingPrevious] = useState(false)\n const [isFetchingNext, setIsFetchingNext] = useState(false)\n\n const isFetchingPreviousRef = useRef(false)\n const isFetchingNextRef = useRef(false)\n const canTriggerStartRef = useRef(true)\n const canTriggerEndRef = useRef(true)\n const hasPreviousPageRef = useRef(hasPreviousPage)\n const hasNextPageRef = useRef(hasNextPage)\n const previousHasPreviousPageRef = useRef(hasPreviousPage)\n const previousHasNextPageRef = useRef(hasNextPage)\n const onStartReachedRef = useRef<ReachCallback | undefined>(onStartReached)\n const onEndReachedRef = useRef<ReachCallback | undefined>(onEndReached)\n\n useEffect(() => {\n isFetchingPreviousRef.current = isFetchingPrevious\n }, [isFetchingPrevious])\n\n useEffect(() => {\n isFetchingNextRef.current = isFetchingNext\n }, [isFetchingNext])\n\n useEffect(() => {\n hasPreviousPageRef.current = hasPreviousPage\n }, [hasPreviousPage])\n\n useEffect(() => {\n hasNextPageRef.current = hasNextPage\n }, [hasNextPage])\n\n useEffect(() => {\n onStartReachedRef.current = onStartReached\n }, [onStartReached])\n\n useEffect(() => {\n onEndReachedRef.current = onEndReached\n }, [onEndReached])\n\n useEffect(() => {\n canTriggerStartRef.current = true\n canTriggerEndRef.current = true\n }, [enabled])\n\n const runStartFetch = (root: HTMLElement) => {\n if (!hasPreviousPageRef.current) return\n if (!onStartReachedRef.current) return\n if (!canTriggerStartRef.current) return\n if (isFetchingPreviousRef.current || isFetchingNextRef.current) return\n\n canTriggerStartRef.current = false\n isFetchingPreviousRef.current = true\n setIsFetchingPrevious(true)\n\n const previousScrollTop = root.scrollTop\n const previousScrollHeight = root.scrollHeight\n\n void Promise.resolve(onStartReachedRef.current())\n .then(async () => {\n if (!maintainScrollOnStartFetch) return\n if (!root.isConnected) return\n\n await new Promise<void>((resolve) => {\n window.requestAnimationFrame(() => {\n window.requestAnimationFrame(() => resolve())\n })\n })\n\n const scrollHeightDelta = root.scrollHeight - previousScrollHeight\n if (scrollHeightDelta <= 0) return\n root.scrollTop = previousScrollTop + scrollHeightDelta\n })\n .finally(() => {\n isFetchingPreviousRef.current = false\n setIsFetchingPrevious(false)\n })\n }\n\n const isEndSentinelWithinRange = () => {\n const root = containerRef.current\n if (!root || !endSentinel) return false\n const resolvedOffsetPx = Math.max(0, endReachedOffsetPx)\n return isWithinEndRange(endSentinel, root, resolvedOffsetPx)\n }\n\n const runEndFetch = () => {\n if (!hasNextPageRef.current) return\n if (!onEndReachedRef.current) return\n if (!canTriggerEndRef.current) return\n if (isFetchingNextRef.current || isFetchingPreviousRef.current) return\n\n const initialRoot = containerRef.current\n const previousScrollHeight = initialRoot?.scrollHeight\n canTriggerEndRef.current = false\n isFetchingNextRef.current = true\n setIsFetchingNext(true)\n\n let didFetch: boolean | void\n void Promise.resolve(onEndReachedRef.current())\n .then((result) => {\n didFetch = result\n })\n .finally(() => {\n isFetchingNextRef.current = false\n setIsFetchingNext(false)\n canTriggerEndRef.current = true\n\n if (didFetch === false) return\n window.requestAnimationFrame(() => {\n window.requestAnimationFrame(() => {\n const root = containerRef.current\n if (!root) return\n const didGrow = typeof previousScrollHeight === \"number\"\n ? root.scrollHeight > previousScrollHeight\n : false\n if (!didGrow || !hasNextPageRef.current || !isEndSentinelWithinRange()) return\n runEndFetch()\n })\n })\n })\n }\n\n useEffect(() => {\n if (!enabled) return\n if (!supportsIntersectionObserver()) return\n\n const root = containerRef.current\n if (!root || !startSentinel) return\n\n const observer = new IntersectionObserver((entries) => {\n const entry = entries[0]\n if (!entry) return\n\n if (!entry.isIntersecting) {\n canTriggerStartRef.current = true\n return\n }\n\n runStartFetch(root)\n }, {\n root,\n rootMargin: `${Math.max(0, startReachedOffsetPx)}px 0px 0px 0px`,\n threshold: 0,\n })\n\n observer.observe(startSentinel)\n return () => {\n observer.disconnect()\n }\n }, [containerRef, enabled, maintainScrollOnStartFetch, startReachedOffsetPx, startSentinel])\n\n useEffect(() => {\n if (!enabled) return\n\n const root = containerRef.current\n if (!root || !startSentinel) return\n\n const hadPreviousPage = previousHasPreviousPageRef.current\n previousHasPreviousPageRef.current = hasPreviousPage\n if (!hasPreviousPage || hadPreviousPage) return\n\n const resolvedOffsetPx = Math.max(0, startReachedOffsetPx)\n if (!isWithinStartRange(startSentinel, root, resolvedOffsetPx)) {\n canTriggerStartRef.current = true\n return\n }\n\n runStartFetch(root)\n }, [\n containerRef,\n enabled,\n hasPreviousPage,\n maintainScrollOnStartFetch,\n startReachedOffsetPx,\n startSentinel,\n ])\n\n useEffect(() => {\n if (!enabled) return\n if (!supportsIntersectionObserver()) return\n\n const root = containerRef.current\n if (!root || !endSentinel) return\n\n const observer = new IntersectionObserver((entries) => {\n const entry = entries[0]\n if (!entry) return\n\n if (!entry.isIntersecting) {\n canTriggerEndRef.current = true\n return\n }\n\n runEndFetch()\n }, {\n root,\n rootMargin: `0px 0px ${Math.max(0, endReachedOffsetPx)}px 0px`,\n threshold: 0,\n })\n\n observer.observe(endSentinel)\n return () => {\n observer.disconnect()\n }\n }, [containerRef, enabled, endReachedOffsetPx, endSentinel])\n\n useEffect(() => {\n if (!enabled) return\n\n const root = containerRef.current\n if (!root || !endSentinel) return\n\n const hadNextPage = previousHasNextPageRef.current\n previousHasNextPageRef.current = hasNextPage\n if (!hasNextPage || hadNextPage) return\n\n const resolvedOffsetPx = Math.max(0, endReachedOffsetPx)\n if (!isWithinEndRange(endSentinel, root, resolvedOffsetPx)) {\n canTriggerEndRef.current = true\n return\n }\n\n runEndFetch()\n }, [\n containerRef,\n enabled,\n endReachedOffsetPx,\n endSentinel,\n hasNextPage,\n ])\n\n useEffect(() => {\n if (!enabled) return\n if (!hasNextPage) return\n\n const root = containerRef.current\n if (!root || !endSentinel) return\n\n const checkAndFetch = () => {\n if (!isEndSentinelWithinRange()) return\n runEndFetch()\n }\n\n const handleScroll = () => {\n checkAndFetch()\n }\n\n const handleResize = () => {\n window.requestAnimationFrame(() => {\n checkAndFetch()\n })\n }\n\n root.addEventListener(\"scroll\", handleScroll, { passive: true })\n window.addEventListener(\"resize\", handleResize)\n\n return () => {\n root.removeEventListener(\"scroll\", handleScroll)\n window.removeEventListener(\"resize\", handleResize)\n }\n }, [\n containerRef,\n enabled,\n endReachedOffsetPx,\n endSentinel,\n hasNextPage,\n ])\n\n return {\n startSentinelRef: setStartSentinel,\n endSentinelRef: setEndSentinel,\n isFetchingPrevious,\n isFetchingNext,\n }\n}\n"],"mappings":";;AA0BA,IAAM,UACA,OAAO,SAAW,MAAoB,KACnC,0BA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F"}
|
|
1
|
+
{"version":3,"file":"index7.js","names":["{\n containerRef,\n enabled = true,\n hasPreviousPage = false,\n hasNextPage = false,\n onStartReached,\n onEndReached,\n startReachedOffsetPx = 160,\n endReachedOffsetPx = 160,\n maintainScrollOnStartFetch = true,\n}: UseScrollPaginationOptions","enabled = true","hasPreviousPage = false","hasNextPage = false","startReachedOffsetPx = 160","endReachedOffsetPx = 160","maintainScrollOnStartFetch = true","() => {\n isFetchingPreviousRef.current = isFetchingPrevious\n }","[isFetchingPrevious]","[isFetchingNext]","() => {\n isFetchingNextRef.current = isFetchingNext\n }","() => {\n hasPreviousPageRef.current = hasPreviousPage\n }","[hasPreviousPage]","() => {\n hasNextPageRef.current = hasNextPage\n }","[hasNextPage]","() => {\n onStartReachedRef.current = onStartReached\n }","[onStartReached]","() => {\n onEndReachedRef.current = onEndReached\n }","[onEndReached]","() => {\n canTriggerStartRef.current = true\n canTriggerEndRef.current = true\n }","[enabled]","(root: HTMLElement) => {\n if (!hasPreviousPageRef.current) return\n if (!onStartReachedRef.current) return\n if (!canTriggerStartRef.current) return\n if (isFetchingPreviousRef.current || isFetchingNextRef.current) return\n\n canTriggerStartRef.current = false\n isFetchingPreviousRef.current = true\n setIsFetchingPrevious(true)\n\n const previousScrollTop = root.scrollTop\n const previousScrollHeight = root.scrollHeight\n\n void Promise.resolve(onStartReachedRef.current())\n .then(async () => {\n if (!maintainScrollOnStartFetch) return\n if (!root.isConnected) return\n\n await new Promise<void>((resolve) => {\n window.requestAnimationFrame(() => {\n window.requestAnimationFrame(() => resolve())\n })\n })\n\n const scrollHeightDelta = root.scrollHeight - previousScrollHeight\n if (scrollHeightDelta <= 0) return\n root.scrollTop = previousScrollTop + scrollHeightDelta\n })\n .finally(() => {\n isFetchingPreviousRef.current = false\n setIsFetchingPrevious(false)\n })\n }","(resolve) => {\n window.requestAnimationFrame(() => {\n window.requestAnimationFrame(() => resolve())\n })\n }","() => {\n const root = containerRef.current\n if (!root || !endSentinel) return false\n const resolvedOffsetPx = Math.max(0, endReachedOffsetPx)\n return isWithinEndRange(endSentinel, root, resolvedOffsetPx)\n }","containerRef.current","root","previousScrollHeight","() => {\n if (!enabled) return\n if (!supportsIntersectionObserver()) return\n\n const root = containerRef.current\n if (!root || !startSentinel) return\n\n const observer = new IntersectionObserver((entries) => {\n const entry = entries[0]\n if (!entry) return\n\n if (!entry.isIntersecting) {\n canTriggerStartRef.current = true\n return\n }\n\n runStartFetch(root)\n }, {\n root,\n rootMargin: `${Math.max(0, startReachedOffsetPx)}px 0px 0px 0px`,\n threshold: 0,\n })\n\n observer.observe(startSentinel)\n return () => {\n observer.disconnect()\n }\n }","[containerRef, enabled, maintainScrollOnStartFetch, startReachedOffsetPx, startSentinel]","() => {\n if (!enabled) return\n\n const root = containerRef.current\n if (!root || !startSentinel) return\n\n const hadPreviousPage = previousHasPreviousPageRef.current\n previousHasPreviousPageRef.current = hasPreviousPage\n if (!hasPreviousPage || hadPreviousPage) return\n\n const resolvedOffsetPx = Math.max(0, startReachedOffsetPx)\n if (!isWithinStartRange(startSentinel, root, resolvedOffsetPx)) {\n canTriggerStartRef.current = true\n return\n }\n\n runStartFetch(root)\n }","resolvedOffsetPx","[\n containerRef,\n enabled,\n hasPreviousPage,\n maintainScrollOnStartFetch,\n startReachedOffsetPx,\n startSentinel,\n ]","() => {\n if (!enabled) return\n if (!supportsIntersectionObserver()) return\n\n const root = containerRef.current\n if (!root || !endSentinel) return\n\n const observer = new IntersectionObserver((entries) => {\n const entry = entries[0]\n if (!entry) return\n\n if (!entry.isIntersecting) {\n canTriggerEndRef.current = true\n return\n }\n\n runEndFetch()\n }, {\n root,\n rootMargin: `0px 0px ${Math.max(0, endReachedOffsetPx)}px 0px`,\n threshold: 0,\n })\n\n observer.observe(endSentinel)\n return () => {\n observer.disconnect()\n }\n }","observer","entry","entries","[containerRef, enabled, endReachedOffsetPx, endSentinel]","() => {\n if (!enabled) return\n\n const root = containerRef.current\n if (!root || !endSentinel) return\n\n const hadNextPage = previousHasNextPageRef.current\n previousHasNextPageRef.current = hasNextPage\n if (!hasNextPage || hadNextPage) return\n\n const resolvedOffsetPx = Math.max(0, endReachedOffsetPx)\n if (!isWithinEndRange(endSentinel, root, resolvedOffsetPx)) {\n canTriggerEndRef.current = true\n return\n }\n\n runEndFetch()\n }","[\n containerRef,\n enabled,\n endReachedOffsetPx,\n endSentinel,\n hasNextPage,\n ]","() => {\n if (!enabled) return\n if (!hasNextPage) return\n\n const root = containerRef.current\n if (!root || !endSentinel) return\n\n const checkAndFetch = () => {\n if (!isEndSentinelWithinRange()) return\n runEndFetch()\n }\n\n const handleScroll = () => {\n checkAndFetch()\n }\n\n const handleResize = () => {\n window.requestAnimationFrame(() => {\n checkAndFetch()\n })\n }\n\n root.addEventListener(\"scroll\", handleScroll, { passive: true })\n window.addEventListener(\"resize\", handleResize)\n\n return () => {\n root.removeEventListener(\"scroll\", handleScroll)\n window.removeEventListener(\"resize\", handleResize)\n }\n }","{\n startSentinelRef: setStartSentinel,\n endSentinelRef: setEndSentinel,\n isFetchingPrevious,\n isFetchingNext,\n }"],"sources":["../src/helpers/useScrollPagination.ts"],"sourcesContent":["import { useEffect, useRef, useState, type RefObject } from \"react\"\n\n\ntype MaybePromise<T> = T | Promise<T>\n\ntype ReachCallback = () => MaybePromise<boolean | void>\n\nexport type UseScrollPaginationOptions = {\n containerRef: RefObject<HTMLElement | null>\n enabled?: boolean\n hasPreviousPage?: boolean\n hasNextPage?: boolean\n onStartReached?: ReachCallback\n onEndReached?: ReachCallback\n startReachedOffsetPx?: number\n endReachedOffsetPx?: number\n maintainScrollOnStartFetch?: boolean\n}\n\nexport type UseScrollPaginationResult = {\n startSentinelRef: (node: Element | null) => void\n endSentinelRef: (node: Element | null) => void\n isFetchingPrevious: boolean\n isFetchingNext: boolean\n}\n\nconst supportsIntersectionObserver = () => {\n if (typeof window === \"undefined\") return false\n return \"IntersectionObserver\" in window\n}\n\nconst isWithinStartRange = (target: Element, root: HTMLElement, offsetPx: number) => {\n const targetRect = target.getBoundingClientRect()\n const rootRect = root.getBoundingClientRect()\n return targetRect.bottom >= rootRect.top - offsetPx && targetRect.top <= rootRect.bottom\n}\n\nconst isWithinEndRange = (target: Element, root: HTMLElement, offsetPx: number) => {\n const targetRect = target.getBoundingClientRect()\n const rootRect = root.getBoundingClientRect()\n return targetRect.top <= rootRect.bottom + offsetPx && targetRect.bottom >= rootRect.top\n}\n\nexport function useScrollPagination({\n containerRef,\n enabled = true,\n hasPreviousPage = false,\n hasNextPage = false,\n onStartReached,\n onEndReached,\n startReachedOffsetPx = 160,\n endReachedOffsetPx = 160,\n maintainScrollOnStartFetch = true,\n}: UseScrollPaginationOptions): UseScrollPaginationResult {\n const [startSentinel, setStartSentinel] = useState<Element | null>(null)\n const [endSentinel, setEndSentinel] = useState<Element | null>(null)\n const [isFetchingPrevious, setIsFetchingPrevious] = useState(false)\n const [isFetchingNext, setIsFetchingNext] = useState(false)\n\n const isFetchingPreviousRef = useRef(false)\n const isFetchingNextRef = useRef(false)\n const canTriggerStartRef = useRef(true)\n const canTriggerEndRef = useRef(true)\n const hasPreviousPageRef = useRef(hasPreviousPage)\n const hasNextPageRef = useRef(hasNextPage)\n const previousHasPreviousPageRef = useRef(hasPreviousPage)\n const previousHasNextPageRef = useRef(hasNextPage)\n const onStartReachedRef = useRef<ReachCallback | undefined>(onStartReached)\n const onEndReachedRef = useRef<ReachCallback | undefined>(onEndReached)\n\n useEffect(() => {\n isFetchingPreviousRef.current = isFetchingPrevious\n }, [isFetchingPrevious])\n\n useEffect(() => {\n isFetchingNextRef.current = isFetchingNext\n }, [isFetchingNext])\n\n useEffect(() => {\n hasPreviousPageRef.current = hasPreviousPage\n }, [hasPreviousPage])\n\n useEffect(() => {\n hasNextPageRef.current = hasNextPage\n }, [hasNextPage])\n\n useEffect(() => {\n onStartReachedRef.current = onStartReached\n }, [onStartReached])\n\n useEffect(() => {\n onEndReachedRef.current = onEndReached\n }, [onEndReached])\n\n useEffect(() => {\n canTriggerStartRef.current = true\n canTriggerEndRef.current = true\n }, [enabled])\n\n const runStartFetch = (root: HTMLElement) => {\n if (!hasPreviousPageRef.current) return\n if (!onStartReachedRef.current) return\n if (!canTriggerStartRef.current) return\n if (isFetchingPreviousRef.current || isFetchingNextRef.current) return\n\n canTriggerStartRef.current = false\n isFetchingPreviousRef.current = true\n setIsFetchingPrevious(true)\n\n const previousScrollTop = root.scrollTop\n const previousScrollHeight = root.scrollHeight\n\n void Promise.resolve(onStartReachedRef.current())\n .then(async () => {\n if (!maintainScrollOnStartFetch) return\n if (!root.isConnected) return\n\n await new Promise<void>((resolve) => {\n window.requestAnimationFrame(() => {\n window.requestAnimationFrame(() => resolve())\n })\n })\n\n const scrollHeightDelta = root.scrollHeight - previousScrollHeight\n if (scrollHeightDelta <= 0) return\n root.scrollTop = previousScrollTop + scrollHeightDelta\n })\n .finally(() => {\n isFetchingPreviousRef.current = false\n setIsFetchingPrevious(false)\n })\n }\n\n const isEndSentinelWithinRange = () => {\n const root = containerRef.current\n if (!root || !endSentinel) return false\n const resolvedOffsetPx = Math.max(0, endReachedOffsetPx)\n return isWithinEndRange(endSentinel, root, resolvedOffsetPx)\n }\n\n const runEndFetch = () => {\n if (!hasNextPageRef.current) return\n if (!onEndReachedRef.current) return\n if (!canTriggerEndRef.current) return\n if (isFetchingNextRef.current || isFetchingPreviousRef.current) return\n\n const initialRoot = containerRef.current\n const previousScrollHeight = initialRoot?.scrollHeight\n canTriggerEndRef.current = false\n isFetchingNextRef.current = true\n setIsFetchingNext(true)\n\n let didFetch: boolean | void\n void Promise.resolve(onEndReachedRef.current())\n .then((result) => {\n didFetch = result\n })\n .finally(() => {\n isFetchingNextRef.current = false\n setIsFetchingNext(false)\n canTriggerEndRef.current = true\n\n if (didFetch === false) return\n window.requestAnimationFrame(() => {\n window.requestAnimationFrame(() => {\n const root = containerRef.current\n if (!root) return\n const didGrow = typeof previousScrollHeight === \"number\"\n ? root.scrollHeight > previousScrollHeight\n : false\n if (!didGrow || !hasNextPageRef.current || !isEndSentinelWithinRange()) return\n runEndFetch()\n })\n })\n })\n }\n\n useEffect(() => {\n if (!enabled) return\n if (!supportsIntersectionObserver()) return\n\n const root = containerRef.current\n if (!root || !startSentinel) return\n\n const observer = new IntersectionObserver((entries) => {\n const entry = entries[0]\n if (!entry) return\n\n if (!entry.isIntersecting) {\n canTriggerStartRef.current = true\n return\n }\n\n runStartFetch(root)\n }, {\n root,\n rootMargin: `${Math.max(0, startReachedOffsetPx)}px 0px 0px 0px`,\n threshold: 0,\n })\n\n observer.observe(startSentinel)\n return () => {\n observer.disconnect()\n }\n }, [containerRef, enabled, maintainScrollOnStartFetch, startReachedOffsetPx, startSentinel])\n\n useEffect(() => {\n if (!enabled) return\n\n const root = containerRef.current\n if (!root || !startSentinel) return\n\n const hadPreviousPage = previousHasPreviousPageRef.current\n previousHasPreviousPageRef.current = hasPreviousPage\n if (!hasPreviousPage || hadPreviousPage) return\n\n const resolvedOffsetPx = Math.max(0, startReachedOffsetPx)\n if (!isWithinStartRange(startSentinel, root, resolvedOffsetPx)) {\n canTriggerStartRef.current = true\n return\n }\n\n runStartFetch(root)\n }, [\n containerRef,\n enabled,\n hasPreviousPage,\n maintainScrollOnStartFetch,\n startReachedOffsetPx,\n startSentinel,\n ])\n\n useEffect(() => {\n if (!enabled) return\n if (!supportsIntersectionObserver()) return\n\n const root = containerRef.current\n if (!root || !endSentinel) return\n\n const observer = new IntersectionObserver((entries) => {\n const entry = entries[0]\n if (!entry) return\n\n if (!entry.isIntersecting) {\n canTriggerEndRef.current = true\n return\n }\n\n runEndFetch()\n }, {\n root,\n rootMargin: `0px 0px ${Math.max(0, endReachedOffsetPx)}px 0px`,\n threshold: 0,\n })\n\n observer.observe(endSentinel)\n return () => {\n observer.disconnect()\n }\n }, [containerRef, enabled, endReachedOffsetPx, endSentinel])\n\n useEffect(() => {\n if (!enabled) return\n\n const root = containerRef.current\n if (!root || !endSentinel) return\n\n const hadNextPage = previousHasNextPageRef.current\n previousHasNextPageRef.current = hasNextPage\n if (!hasNextPage || hadNextPage) return\n\n const resolvedOffsetPx = Math.max(0, endReachedOffsetPx)\n if (!isWithinEndRange(endSentinel, root, resolvedOffsetPx)) {\n canTriggerEndRef.current = true\n return\n }\n\n runEndFetch()\n }, [\n containerRef,\n enabled,\n endReachedOffsetPx,\n endSentinel,\n hasNextPage,\n ])\n\n useEffect(() => {\n if (!enabled) return\n if (!hasNextPage) return\n\n const root = containerRef.current\n if (!root || !endSentinel) return\n\n const checkAndFetch = () => {\n if (!isEndSentinelWithinRange()) return\n runEndFetch()\n }\n\n const handleScroll = () => {\n checkAndFetch()\n }\n\n const handleResize = () => {\n window.requestAnimationFrame(() => {\n checkAndFetch()\n })\n }\n\n root.addEventListener(\"scroll\", handleScroll, { passive: true })\n window.addEventListener(\"resize\", handleResize)\n\n return () => {\n root.removeEventListener(\"scroll\", handleScroll)\n window.removeEventListener(\"resize\", handleResize)\n }\n }, [\n containerRef,\n enabled,\n endReachedOffsetPx,\n endSentinel,\n hasNextPage,\n ])\n\n return {\n startSentinelRef: setStartSentinel,\n endSentinelRef: setEndSentinel,\n isFetchingPrevious,\n isFetchingNext,\n }\n}\n"],"mappings":";;;AA0BA,IAAM,UACA,OAAO,SAAW,MAAoB,KACnC,0BAA0B,QAG7B,MAAsB,GAAiB,GAAmB,MAAqB;CACnF,IAAM,IAAa,EAAO,sBAAsB,GAC1C,IAAW,EAAK,sBAAsB;CAC5C,OAAO,EAAW,UAAU,EAAS,MAAM,KAAY,EAAW,OAAO,EAAS;AACpF,GAEM,MAAoB,GAAiB,GAAmB,MAAqB;CACjF,IAAM,IAAa,EAAO,sBAAsB,GAC1C,IAAW,EAAK,sBAAsB;CAC5C,OAAO,EAAW,OAAO,EAAS,SAAS,KAAY,EAAW,UAAU,EAAS;AACvF;AAEA,SAAgB,GAAA,IAU0C;gBAVtB,EAClC,iBACA,SAAA,IACA,iBAAA,IACA,aAAA,IACA,mBACA,iBACA,sBAAA,IACA,oBAAA,IACA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AoB,UAAU,CAAY,GAC/C,OAAO,oBAAoB,UAAU,CAAY;EACnD;CACF,GAzBeD,EAAAA,MAAAA,GAHR,EAAA,MAAA,GAIS,EAAA,MAAA,GAHT,EAAA,MAAA,GAME,EAAA,MAAA,GACL,EAAA,MAAA;CAoBDc,IAAAA;CA7BH,AA8BE,EAAA,QAAA,KAAA,EAAA,QACA,KAAA,EAAA,QACA,KAAA,EAAA,QACA,KAAA,EAAA,QACA,KALC,IAAA;EACD;EACA;EACA;EACA;EACA;CACF,GALE,EAAA,MAAA,GACA,EAAA,MAAA,GACA,EAAA,MAAA,GACA,EAAA,MAAA,GACA,EAAA,MAAA,2BAlCF,EAAUC,GA6BPD,CAMF;CAEME,IAAAA;CAAP,OAIE,EAAA,QAAA,KAAA,EAAA,QADA,KAHK,IAAA;EACL,kBAAkB;EAClB,gBAAgB;EAChB;EACA;CACF,GADE,EAAA,MAAA,GADA,EAAA,MAAA,2BAHKA;AAMT;AApNgC,SAAA,GAAC,GAAY;CACnC,OAAO,4BAA4B;EACjC,OAAO,4BAA4B,EAAQ,CAAC;CAC9C,CAAC;AACH"}
|
package/dist/index8.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index8.js","names":[],"sources":["../src/helpers/useUserScrollIntent.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\"\n\n\nconst KEYBOARD_SCROLL_KEYS = new Set([\n \" \",\n \"Spacebar\",\n \"PageUp\",\n \"PageDown\",\n \"Home\",\n \"End\",\n \"ArrowDown\",\n \"ArrowUp\",\n])\n\nexport function useUserScrollIntent(timeoutMs = 1000) {\n const isUserScrollRef = useRef(false)\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)\n\n useEffect(() => {\n if (typeof window === \"undefined\") {\n return\n }\n\n if (timeoutMs <= 0) {\n isUserScrollRef.current = false\n return\n }\n\n const markUserScroll = () => {\n isUserScrollRef.current = true\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current)\n }\n timeoutRef.current = setTimeout(() => {\n isUserScrollRef.current = false\n }, timeoutMs)\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (KEYBOARD_SCROLL_KEYS.has(event.key)) {\n markUserScroll()\n }\n }\n\n window.addEventListener(\"touchmove\", markUserScroll, { passive: true })\n window.addEventListener(\"wheel\", markUserScroll, { passive: true })\n window.addEventListener(\"keydown\", handleKeyDown)\n\n return () => {\n window.removeEventListener(\"touchmove\", markUserScroll)\n window.removeEventListener(\"wheel\", markUserScroll)\n window.removeEventListener(\"keydown\", handleKeyDown)\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current)\n }\n }\n }, [timeoutMs])\n\n return isUserScrollRef\n}\n\n"],"mappings":";;;AAGA,IAAM,oBAAuB,IAAI,IAAI;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;
|
|
1
|
+
{"version":3,"file":"index8.js","names":["timeoutMs = 1000","() => {\n if (typeof window === \"undefined\") {\n return\n }\n\n if (timeoutMs <= 0) {\n isUserScrollRef.current = false\n return\n }\n\n const markUserScroll = () => {\n isUserScrollRef.current = true\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current)\n }\n timeoutRef.current = setTimeout(() => {\n isUserScrollRef.current = false\n }, timeoutMs)\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (KEYBOARD_SCROLL_KEYS.has(event.key)) {\n markUserScroll()\n }\n }\n\n window.addEventListener(\"touchmove\", markUserScroll, { passive: true })\n window.addEventListener(\"wheel\", markUserScroll, { passive: true })\n window.addEventListener(\"keydown\", handleKeyDown)\n\n return () => {\n window.removeEventListener(\"touchmove\", markUserScroll)\n window.removeEventListener(\"wheel\", markUserScroll)\n window.removeEventListener(\"keydown\", handleKeyDown)\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current)\n }\n }\n }","[timeoutMs]"],"sources":["../src/helpers/useUserScrollIntent.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\"\n\n\nconst KEYBOARD_SCROLL_KEYS = new Set([\n \" \",\n \"Spacebar\",\n \"PageUp\",\n \"PageDown\",\n \"Home\",\n \"End\",\n \"ArrowDown\",\n \"ArrowUp\",\n])\n\nexport function useUserScrollIntent(timeoutMs = 1000) {\n const isUserScrollRef = useRef(false)\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)\n\n useEffect(() => {\n if (typeof window === \"undefined\") {\n return\n }\n\n if (timeoutMs <= 0) {\n isUserScrollRef.current = false\n return\n }\n\n const markUserScroll = () => {\n isUserScrollRef.current = true\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current)\n }\n timeoutRef.current = setTimeout(() => {\n isUserScrollRef.current = false\n }, timeoutMs)\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (KEYBOARD_SCROLL_KEYS.has(event.key)) {\n markUserScroll()\n }\n }\n\n window.addEventListener(\"touchmove\", markUserScroll, { passive: true })\n window.addEventListener(\"wheel\", markUserScroll, { passive: true })\n window.addEventListener(\"keydown\", handleKeyDown)\n\n return () => {\n window.removeEventListener(\"touchmove\", markUserScroll)\n window.removeEventListener(\"wheel\", markUserScroll)\n window.removeEventListener(\"keydown\", handleKeyDown)\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current)\n }\n }\n }, [timeoutMs])\n\n return isUserScrollRef\n}\n\n"],"mappings":";;;AAGA,IAAM,oBAAuB,IAAI,IAAI;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAgB,EAAA,GAAsC;eAAlB,IAAA,MAAA,KAAA,IAAY,MAAZA,GAC5B,IAAkB,EAAO,EAAK,GAC9B,IAAa,EAA6C,IAAI,GAE1DC,GAsCPC;CAEH,OAnCM,EAAA,OAAA,4BALI,UAAM;EACd,IAAI,OAAO,SAAW,KACpB;EAGF,IAAI,KAAa,GAAG;GAClB,EAAgB,UAAU;GAC1B;EACF;EAEA,IAAM,UAAuB;GAK3B,AAJA,EAAgB,UAAU,IACtB,EAAW,WACb,aAAa,EAAW,OAAO,GAEjC,EAAW,UAAU,iBAAiB;IACpC,EAAgB,UAAU;GAC5B,GAAG,CAAS;EACd,GAEM,KAAiB,MAAyB;GAC9C,AAAI,EAAqB,IAAI,EAAM,GAAG,KACpC,EAAe;EAEnB;EAMA,OAJA,OAAO,iBAAiB,aAAa,GAAgB,EAAE,SAAS,GAAK,CAAC,GACtE,OAAO,iBAAiB,SAAS,GAAgB,EAAE,SAAS,GAAK,CAAC,GAClE,OAAO,iBAAiB,WAAW,CAAa,SAEnC;GAIX,AAHA,OAAO,oBAAoB,aAAa,CAAc,GACtD,OAAO,oBAAoB,SAAS,CAAc,GAClD,OAAO,oBAAoB,WAAW,CAAa,GAC/C,EAAW,WACb,aAAa,EAAW,OAAO;EAEnC;CACF,GAAG,IAAA,CAAC,CAAS,GAjCP,EAAA,KAAA,wBALN,EAAUD,GAsCPC,CAAW,GAEP;AACT"}
|
package/dist/index9.js
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
import { useUserScrollIntent as e } from "./index8.js";
|
|
2
|
-
import {
|
|
2
|
+
import { c as t } from "react/compiler-runtime";
|
|
3
|
+
import { useEffect as n, useState as r } from "react";
|
|
3
4
|
//#region src/helpers/useScrollHideOnDown.ts
|
|
4
|
-
function
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
function i(i) {
|
|
6
|
+
let a = t(8), o;
|
|
7
|
+
a[0] === i ? o = a[1] : (o = i === void 0 ? {} : i, a[0] = i, a[1] = o);
|
|
8
|
+
let { enabled: s, thresholdPx: c, ignoreProgrammaticScroll: l, userScrollIntentTimeoutMs: u } = o, d = s === void 0 || s, f = c === void 0 ? 0 : c, p = l === void 0 || l, m = e(d && p ? u === void 0 ? 1e3 : u : 0), [h, g] = r(!1), _, v;
|
|
9
|
+
return a[2] !== d || a[3] !== p || a[4] !== m || a[5] !== f ? (_ = () => {
|
|
10
|
+
if (!d || typeof window > "u") {
|
|
11
|
+
g(!1);
|
|
9
12
|
return;
|
|
10
13
|
}
|
|
11
|
-
let e = Math.max(0,
|
|
14
|
+
let e = Math.max(0, f), t = window.scrollY, n = () => {
|
|
12
15
|
let n = window.scrollY;
|
|
13
|
-
if (
|
|
16
|
+
if (p && !m.current) {
|
|
14
17
|
t = n;
|
|
15
18
|
return;
|
|
16
19
|
}
|
|
17
|
-
n > t && n > e ?
|
|
20
|
+
n > t && n > e ? g(!0) : n < t && g(!1), t = n;
|
|
18
21
|
};
|
|
19
22
|
return window.addEventListener("scroll", n, { passive: !0 }), () => window.removeEventListener("scroll", n);
|
|
20
|
-
}, [
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
]),
|
|
23
|
+
}, v = [
|
|
24
|
+
d,
|
|
25
|
+
f,
|
|
26
|
+
p,
|
|
27
|
+
m
|
|
28
|
+
], a[2] = d, a[3] = p, a[4] = m, a[5] = f, a[6] = _, a[7] = v) : (_ = a[6], v = a[7]), n(_, v), h;
|
|
26
29
|
}
|
|
27
30
|
//#endregion
|
|
28
|
-
export {
|
|
31
|
+
export { i as useScrollHideOnDown };
|
|
29
32
|
|
|
30
33
|
//# sourceMappingURL=index9.js.map
|
package/dist/index9.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index9.js","names":[],"sources":["../src/helpers/useScrollHideOnDown.ts"],"sourcesContent":["import { useEffect, useState } from \"react\"\n\nimport { useUserScrollIntent } from \"./useUserScrollIntent\"\n\n\ntype UseScrollHideOnDownOptions = {\n enabled?: boolean\n thresholdPx?: number\n ignoreProgrammaticScroll?: boolean\n userScrollIntentTimeoutMs?: number\n}\n\nexport function useScrollHideOnDown({\n enabled = true,\n thresholdPx = 0,\n ignoreProgrammaticScroll = true,\n userScrollIntentTimeoutMs = 1000,\n}: UseScrollHideOnDownOptions = {}) {\n const isUserScrollRef = useUserScrollIntent(\n enabled && ignoreProgrammaticScroll ? userScrollIntentTimeoutMs : 0,\n )\n\n const [isHidden, setIsHidden] = useState(false)\n\n useEffect(() => {\n if (!enabled || typeof window === \"undefined\") {\n setIsHidden(false)\n return\n }\n\n const resolvedThresholdPx = Math.max(0, thresholdPx)\n let lastScrollY = window.scrollY\n\n const handleScroll = () => {\n const currentScrollY = window.scrollY\n\n if (ignoreProgrammaticScroll && !isUserScrollRef.current) {\n lastScrollY = currentScrollY\n return\n }\n\n if (currentScrollY > lastScrollY && currentScrollY > resolvedThresholdPx) {\n setIsHidden(true)\n } else if (currentScrollY < lastScrollY) {\n setIsHidden(false)\n }\n\n lastScrollY = currentScrollY\n }\n\n window.addEventListener(\"scroll\", handleScroll, { passive: true })\n return () => window.removeEventListener(\"scroll\", handleScroll)\n }, [enabled, thresholdPx, ignoreProgrammaticScroll, isUserScrollRef])\n\n return isHidden\n}\n\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index9.js","names":["{\n enabled = true,\n thresholdPx = 0,\n ignoreProgrammaticScroll = true,\n userScrollIntentTimeoutMs = 1000,\n}: UseScrollHideOnDownOptions = {}","enabled = true","thresholdPx = 0","ignoreProgrammaticScroll = true","userScrollIntentTimeoutMs = 1000","() => {\n if (!enabled || typeof window === \"undefined\") {\n setIsHidden(false)\n return\n }\n\n const resolvedThresholdPx = Math.max(0, thresholdPx)\n let lastScrollY = window.scrollY\n\n const handleScroll = () => {\n const currentScrollY = window.scrollY\n\n if (ignoreProgrammaticScroll && !isUserScrollRef.current) {\n lastScrollY = currentScrollY\n return\n }\n\n if (currentScrollY > lastScrollY && currentScrollY > resolvedThresholdPx) {\n setIsHidden(true)\n } else if (currentScrollY < lastScrollY) {\n setIsHidden(false)\n }\n\n lastScrollY = currentScrollY\n }\n\n window.addEventListener(\"scroll\", handleScroll, { passive: true })\n return () => window.removeEventListener(\"scroll\", handleScroll)\n }","[enabled, thresholdPx, ignoreProgrammaticScroll, isUserScrollRef]","isUserScrollRef.current"],"sources":["../src/helpers/useScrollHideOnDown.ts"],"sourcesContent":["import { useEffect, useState } from \"react\"\n\nimport { useUserScrollIntent } from \"./useUserScrollIntent\"\n\n\ntype UseScrollHideOnDownOptions = {\n enabled?: boolean\n thresholdPx?: number\n ignoreProgrammaticScroll?: boolean\n userScrollIntentTimeoutMs?: number\n}\n\nexport function useScrollHideOnDown({\n enabled = true,\n thresholdPx = 0,\n ignoreProgrammaticScroll = true,\n userScrollIntentTimeoutMs = 1000,\n}: UseScrollHideOnDownOptions = {}) {\n const isUserScrollRef = useUserScrollIntent(\n enabled && ignoreProgrammaticScroll ? userScrollIntentTimeoutMs : 0,\n )\n\n const [isHidden, setIsHidden] = useState(false)\n\n useEffect(() => {\n if (!enabled || typeof window === \"undefined\") {\n setIsHidden(false)\n return\n }\n\n const resolvedThresholdPx = Math.max(0, thresholdPx)\n let lastScrollY = window.scrollY\n\n const handleScroll = () => {\n const currentScrollY = window.scrollY\n\n if (ignoreProgrammaticScroll && !isUserScrollRef.current) {\n lastScrollY = currentScrollY\n return\n }\n\n if (currentScrollY > lastScrollY && currentScrollY > resolvedThresholdPx) {\n setIsHidden(true)\n } else if (currentScrollY < lastScrollY) {\n setIsHidden(false)\n }\n\n lastScrollY = currentScrollY\n }\n\n window.addEventListener(\"scroll\", handleScroll, { passive: true })\n return () => window.removeEventListener(\"scroll\", handleScroll)\n }, [enabled, thresholdPx, ignoreProgrammaticScroll, isUserScrollRef])\n\n return isHidden\n}\n\n"],"mappings":";;;;AAYA,SAAgB,EAAA,GAKoB;eALAA;0BAKJ,IAAA,MAAA,KAAA,IAAA,CAAC,IALGA;CAClC,IAAA,EAAA,SAAA,GACA,aAAA,GACA,0BAAA,GACA,2BAAA,MAJkCA,GAClC,IAAA,MAAA,KAAA,KAAAC,GACA,IAAA,MAAA,KAAA,IAAc,IAAdC,GACA,IAAA,MAAA,KAAA,KAAAC,GAGM,IAAkB,EACtB,KAAW,IAHb,MAAA,KAAA,IAA4B,MAA5BC,IAGoE,CACpE,GAEM,CAAC,GAAU,KAAe,EAAS,EAAK,GAEpCC,GA4BPC;CAEH,OA7BO,EAAA,OAAA,KAAA,EAAA,OAWC,KAAA,EAAA,OAA6BC,KAAAA,EAAAA,OANK,KANhC,UAAM;EACd,IAAI,CAAC,KAAW,OAAO,SAAW,KAAa;GAC7C,EAAY,EAAK;GACjB;EACF;EAEA,IAAM,IAAsB,KAAK,IAAI,GAAG,CAAW,GAC/C,IAAc,OAAO,SAEnB,UAAqB;GACzB,IAAM,IAAiB,OAAO;GAE9B,IAAI,KAA4B,CAAC,EAAgB,SAAS;IACxD,IAAc;IACd;GACF;GAQA,AANI,IAAiB,KAAe,IAAiB,IACnD,EAAY,EAAI,IACP,IAAiB,KAC1B,EAAY,EAAK,GAGnB,IAAc;EAChB;EAGA,OADA,OAAO,iBAAiB,UAAU,GAAc,EAAE,SAAS,GAAK,CAAC,SACpD,OAAO,oBAAoB,UAAU,CAAY;CAChE,GAAG,IAAA;EAAC;EAAS;EAAa;EAA0B;CAAe,GA3B5D,EAAA,KAAA,GAWC,EAAA,KAAA,GAA6BA,EAAAA,KAAAA,GANK,EAAA,KAAA,+CAN1C,EAAUF,GA4BPC,CAAiE,GAE7D;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpcbase/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.283.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -110,16 +110,14 @@
|
|
|
110
110
|
"sonner": "2.0.8"
|
|
111
111
|
},
|
|
112
112
|
"devDependencies": {
|
|
113
|
-
"@babel/core": "8.0.1",
|
|
114
|
-
"@rolldown/plugin-babel": "0.2.3",
|
|
115
113
|
"@rpcbase/test": "0.0.0",
|
|
116
114
|
"@tailwindcss/vite": "4.3.3",
|
|
117
115
|
"@types/google.maps": "3.65.5",
|
|
118
|
-
"@vitejs/plugin-react": "6.1.
|
|
119
|
-
"babel-plugin-react-compiler": "1.0.0",
|
|
116
|
+
"@vitejs/plugin-react": "6.1.1",
|
|
120
117
|
"clsx": "2.1.1",
|
|
121
118
|
"libphonenumber-js": "1.13.11",
|
|
122
119
|
"lucide-react": "1.34.0",
|
|
120
|
+
"oxc-transform-react": "0.145.0",
|
|
123
121
|
"react": "19.2.8",
|
|
124
122
|
"react-dom": "19.2.8",
|
|
125
123
|
"react-router": "8.3.0",
|