@bgord/ui 0.8.2 → 0.8.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/dist/hooks/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./use-hover";
|
|
|
7
7
|
export * from "./use-meta-enter-submit";
|
|
8
8
|
export * from "./use-mutation";
|
|
9
9
|
export * from "./use-number-field";
|
|
10
|
+
export * from "./use-online-status";
|
|
10
11
|
export * from "./use-scroll-lock";
|
|
11
12
|
export * from "./use-shortcuts";
|
|
12
13
|
export * from "./use-text-field";
|
package/dist/hooks/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./use-hover";
|
|
|
7
7
|
export * from "./use-meta-enter-submit";
|
|
8
8
|
export * from "./use-mutation";
|
|
9
9
|
export * from "./use-number-field";
|
|
10
|
+
export * from "./use-online-status";
|
|
10
11
|
export * from "./use-scroll-lock";
|
|
11
12
|
export * from "./use-shortcuts";
|
|
12
13
|
export * from "./use-text-field";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
export var OnlineStatus;
|
|
3
|
+
(function (OnlineStatus) {
|
|
4
|
+
OnlineStatus["online"] = "online";
|
|
5
|
+
OnlineStatus["offline"] = "offline";
|
|
6
|
+
})(OnlineStatus || (OnlineStatus = {}));
|
|
7
|
+
const OnlineStatusStore = {
|
|
8
|
+
subscribe: (callback) => {
|
|
9
|
+
if (typeof window === "undefined")
|
|
10
|
+
return () => { };
|
|
11
|
+
window.addEventListener("online", callback);
|
|
12
|
+
window.addEventListener("offline", callback);
|
|
13
|
+
return () => {
|
|
14
|
+
window.removeEventListener("online", callback);
|
|
15
|
+
window.removeEventListener("offline", callback);
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
getSnapshot: () => {
|
|
19
|
+
if (typeof navigator === "undefined")
|
|
20
|
+
return OnlineStatus.online;
|
|
21
|
+
return navigator.onLine ? OnlineStatus.online : OnlineStatus.offline;
|
|
22
|
+
},
|
|
23
|
+
getServerSnapshot: () => OnlineStatus.online,
|
|
24
|
+
};
|
|
25
|
+
export function useOnlineStatus() {
|
|
26
|
+
const status = useSyncExternalStore(OnlineStatusStore.subscribe, OnlineStatusStore.getSnapshot, OnlineStatusStore.getServerSnapshot);
|
|
27
|
+
return status;
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bgord/ui",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@biomejs/biome": "2.3.
|
|
26
|
+
"@biomejs/biome": "2.3.3",
|
|
27
27
|
"@commitlint/cli": "20.1.0",
|
|
28
28
|
"@commitlint/config-conventional": "20.0.0",
|
|
29
29
|
"@happy-dom/global-registrator": "20.0.10",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@types/react": "19.2.2",
|
|
37
37
|
"@types/react-dom": "19.2.2",
|
|
38
38
|
"cspell": "9.2.2",
|
|
39
|
-
"knip": "5.
|
|
39
|
+
"knip": "5.67.1",
|
|
40
40
|
"lefthook": "2.0.2",
|
|
41
41
|
"only-allow": "1.2.1",
|
|
42
42
|
"shellcheck": "4.1.0"
|