@bgord/ui 0.8.1 → 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.
@@ -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";
@@ -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,5 @@
1
+ export declare enum OnlineStatus {
2
+ online = "online",
3
+ offline = "offline"
4
+ }
5
+ export declare function useOnlineStatus(): OnlineStatus;
@@ -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
+ }
@@ -0,0 +1 @@
1
+ export declare function absoluteUrl(path: string, request: Request | null): string | URL;
@@ -0,0 +1,15 @@
1
+ export function absoluteUrl(path, request) {
2
+ if (!request)
3
+ return path;
4
+ const incoming = new URL(request.url);
5
+ // Respect reverse-proxy TLS
6
+ const xfproto = request.headers.get("x-forwarded-proto");
7
+ const forwarded = request.headers.get("forwarded");
8
+ const isHttps = xfproto === "https" || (forwarded && /proto=https/i.test(forwarded));
9
+ // Build a clean origin (protocol + host), no path/search/hash
10
+ const origin = `${isHttps ? "https:" : incoming.protocol}//${incoming.host}`;
11
+ // Let WHATWG URL do the right thing:
12
+ // - if `path` is relative with "?...", it becomes pathname + search (NO %3F)
13
+ // - if `path` is absolute, it’s used as-is
14
+ return new URL(path, origin);
15
+ }
@@ -1,3 +1,4 @@
1
+ export * from "./absolute-url";
1
2
  export * from "./autocomplete";
2
3
  export * from "./clipboard";
3
4
  export * from "./cookies";
@@ -1,3 +1,4 @@
1
+ export * from "./absolute-url";
1
2
  export * from "./autocomplete";
2
3
  export * from "./clipboard";
3
4
  export * from "./cookies";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/ui",
3
- "version": "0.8.1",
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.2",
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.66.4",
39
+ "knip": "5.67.1",
40
40
  "lefthook": "2.0.2",
41
41
  "only-allow": "1.2.1",
42
42
  "shellcheck": "4.1.0"
package/readme.md CHANGED
@@ -36,11 +36,13 @@ src/
36
36
  │   ├── use-meta-enter-submit.ts
37
37
  │   ├── use-mutation.ts
38
38
  │   ├── use-number-field.ts
39
+ │   ├── use-online-status.ts
39
40
  │   ├── use-scroll-lock.ts
40
41
  │   ├── use-shortcuts.ts
41
42
  │   ├── use-text-field.ts
42
43
  │   └── use-toggle.ts
43
44
  └── services
45
+ ├── absolute-url.ts
44
46
  ├── autocomplete.ts
45
47
  ├── clipboard.ts
46
48
  ├── cookies.ts