@bouko/react 3.0.5 → 3.0.7
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.
|
@@ -29,7 +29,8 @@ const row = tv({
|
|
|
29
29
|
variants: {
|
|
30
30
|
centerX: { true: "justify-center" },
|
|
31
31
|
centerY: { true: "items-center" },
|
|
32
|
-
center: { true: "items-center justify-center" }
|
|
32
|
+
center: { true: "items-center justify-center" },
|
|
33
|
+
equal: { true: "[&>*]:flex-1" }
|
|
33
34
|
}
|
|
34
35
|
});
|
|
35
36
|
const column = tv({
|
|
@@ -37,6 +38,7 @@ const column = tv({
|
|
|
37
38
|
variants: {
|
|
38
39
|
centerX: { true: "items-center" },
|
|
39
40
|
centerY: { true: "justify-center" },
|
|
40
|
-
center: { true: "items-center justify-center" }
|
|
41
|
+
center: { true: "items-center justify-center" },
|
|
42
|
+
equal: { true: "[&>*]:flex-1" }
|
|
41
43
|
}
|
|
42
44
|
});
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -6,3 +6,12 @@ export { default as useSound } from "./audio/sound";
|
|
|
6
6
|
export { withAudio, type DivRef, type AudioRef } from "./element/with-audio";
|
|
7
7
|
export * from "./router/params";
|
|
8
8
|
export * from "./auth";
|
|
9
|
+
export declare function useObjectUrl(): {
|
|
10
|
+
setFromBlob: (blob: Blob) => string;
|
|
11
|
+
revoke: () => void;
|
|
12
|
+
current: import("react").RefObject<string | null>;
|
|
13
|
+
};
|
|
14
|
+
export declare function useRequestGate(): {
|
|
15
|
+
next: () => number;
|
|
16
|
+
isLatest: (id: number) => boolean;
|
|
17
|
+
};
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useRef, useCallback, useEffect } from "react";
|
|
1
2
|
export { default as useElement } from "./element";
|
|
2
3
|
export { default as useContainer } from "./element/container";
|
|
3
4
|
export { default as useResize } from "./element/resize";
|
|
@@ -6,3 +7,26 @@ export { default as useSound } from "./audio/sound";
|
|
|
6
7
|
export { withAudio } from "./element/with-audio";
|
|
7
8
|
export * from "./router/params";
|
|
8
9
|
export * from "./auth";
|
|
10
|
+
export function useObjectUrl() {
|
|
11
|
+
const urlRef = useRef(null);
|
|
12
|
+
const revoke = useCallback(() => {
|
|
13
|
+
if (!urlRef.current)
|
|
14
|
+
return;
|
|
15
|
+
URL.revokeObjectURL(urlRef.current);
|
|
16
|
+
urlRef.current = null;
|
|
17
|
+
}, []);
|
|
18
|
+
const setFromBlob = useCallback((blob) => {
|
|
19
|
+
revoke();
|
|
20
|
+
const url = URL.createObjectURL(blob);
|
|
21
|
+
urlRef.current = url;
|
|
22
|
+
return url;
|
|
23
|
+
}, [revoke]);
|
|
24
|
+
useEffect(() => revoke, [revoke]);
|
|
25
|
+
return { setFromBlob, revoke, current: urlRef };
|
|
26
|
+
}
|
|
27
|
+
export function useRequestGate() {
|
|
28
|
+
const idRef = useRef(0);
|
|
29
|
+
const next = useCallback(() => ++idRef.current, []);
|
|
30
|
+
const isLatest = useCallback((id) => id === idRef.current, []);
|
|
31
|
+
return { next, isLatest };
|
|
32
|
+
}
|
|
@@ -8,6 +8,7 @@ export function usePagination({ fetcher, pageSize }) {
|
|
|
8
8
|
const [params, setParams] = useSearchParams();
|
|
9
9
|
const [items, setItems] = useState([]);
|
|
10
10
|
const [loading, setLoading] = useState(false);
|
|
11
|
+
const [fetchedAt, setFetchedAt] = useState(null);
|
|
11
12
|
const raw = params.get("page");
|
|
12
13
|
const page = Math.max(1, Number(raw) || 1);
|
|
13
14
|
const setPage = (nextPage) => {
|
|
@@ -16,9 +17,14 @@ export function usePagination({ fetcher, pageSize }) {
|
|
|
16
17
|
};
|
|
17
18
|
const fetchPage = useCallback(async (refresh = false) => {
|
|
18
19
|
setLoading(true);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const result = await fetcher({
|
|
21
|
+
page,
|
|
22
|
+
pageSize,
|
|
23
|
+
refresh
|
|
24
|
+
});
|
|
25
|
+
setItems(result);
|
|
26
|
+
setFetchedAt(new Date());
|
|
27
|
+
setLoading(false);
|
|
22
28
|
}, [page, pageSize]);
|
|
23
29
|
useEffect(() => {
|
|
24
30
|
fetchPage(false);
|
|
@@ -29,6 +35,7 @@ export function usePagination({ fetcher, pageSize }) {
|
|
|
29
35
|
page,
|
|
30
36
|
prev: () => page > 1 ? setPage(page - 1) : undefined,
|
|
31
37
|
next: () => !(page > 1 && items.length === 0) ? setPage(page + 1) : undefined,
|
|
32
|
-
refresh: () => fetchPage(true)
|
|
38
|
+
refresh: () => fetchPage(true),
|
|
39
|
+
fetchedAt
|
|
33
40
|
};
|
|
34
41
|
}
|