@mantine/hooks 4.2.0 → 4.2.1
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.
|
@@ -33,11 +33,14 @@ function getConnection() {
|
|
|
33
33
|
}
|
|
34
34
|
const _navigator = navigator;
|
|
35
35
|
const connection = _navigator.connection || _navigator.mozConnection || _navigator.webkitConnection;
|
|
36
|
+
if (!connection) {
|
|
37
|
+
return defaultValue;
|
|
38
|
+
}
|
|
36
39
|
return {
|
|
37
|
-
downlink: connection.downlink,
|
|
38
|
-
effectiveType: connection.effectiveType,
|
|
39
|
-
saveData: connection.saveData,
|
|
40
|
-
rtt: connection.rtt
|
|
40
|
+
downlink: connection == null ? void 0 : connection.downlink,
|
|
41
|
+
effectiveType: connection == null ? void 0 : connection.effectiveType,
|
|
42
|
+
saveData: connection == null ? void 0 : connection.saveData,
|
|
43
|
+
rtt: connection == null ? void 0 : connection.rtt
|
|
41
44
|
};
|
|
42
45
|
}
|
|
43
46
|
function useNetwork() {
|
|
@@ -46,8 +49,11 @@ function useNetwork() {
|
|
|
46
49
|
useWindowEvent.useWindowEvent("online", () => setStatus(__spreadValues({ online: true }, getConnection())));
|
|
47
50
|
useWindowEvent.useWindowEvent("offline", () => setStatus(__spreadValues({ online: false }, getConnection())));
|
|
48
51
|
react.useEffect(() => {
|
|
49
|
-
navigator.connection
|
|
50
|
-
|
|
52
|
+
if (navigator.connection) {
|
|
53
|
+
navigator.connection.addEventListener("change", handleConnectionChange);
|
|
54
|
+
return () => navigator.connection.removeEventListener("change", handleConnectionChange);
|
|
55
|
+
}
|
|
56
|
+
return void 0;
|
|
51
57
|
}, []);
|
|
52
58
|
return status;
|
|
53
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-network.js","sources":["../../src/use-network/use-network.ts"],"sourcesContent":["import { useState, useEffect, useCallback } from 'react';\nimport { useWindowEvent } from '../use-window-event/use-window-event';\n\ninterface NetworkStatus {\n downlink: number;\n effectiveType: 'slow-2g' | '2g' | '3g' | '4g';\n saveData: boolean;\n rtt: number;\n}\n\nconst defaultValue: NetworkStatus = {\n downlink: 10,\n effectiveType: '4g',\n saveData: false,\n rtt: 50,\n};\n\nfunction getConnection(): NetworkStatus {\n if (typeof navigator === 'undefined') {\n return defaultValue;\n }\n\n const _navigator = navigator as any;\n const connection: any =\n _navigator.connection || _navigator.mozConnection || _navigator.webkitConnection;\n\n return {\n downlink: connection
|
|
1
|
+
{"version":3,"file":"use-network.js","sources":["../../src/use-network/use-network.ts"],"sourcesContent":["import { useState, useEffect, useCallback } from 'react';\nimport { useWindowEvent } from '../use-window-event/use-window-event';\n\ninterface NetworkStatus {\n downlink: number;\n effectiveType: 'slow-2g' | '2g' | '3g' | '4g';\n saveData: boolean;\n rtt: number;\n}\n\nconst defaultValue: NetworkStatus = {\n downlink: 10,\n effectiveType: '4g',\n saveData: false,\n rtt: 50,\n};\n\nfunction getConnection(): NetworkStatus {\n if (typeof navigator === 'undefined') {\n return defaultValue;\n }\n\n const _navigator = navigator as any;\n const connection: any =\n _navigator.connection || _navigator.mozConnection || _navigator.webkitConnection;\n\n if (!connection) {\n return defaultValue;\n }\n\n return {\n downlink: connection?.downlink,\n effectiveType: connection?.effectiveType,\n saveData: connection?.saveData,\n rtt: connection?.rtt,\n };\n}\n\nexport function useNetwork() {\n const [status, setStatus] = useState({ online: true, ...getConnection() });\n const handleConnectionChange = useCallback(\n () => setStatus((current) => ({ ...current, ...getConnection() })),\n []\n );\n\n useWindowEvent('online', () => setStatus({ online: true, ...getConnection() }));\n useWindowEvent('offline', () => setStatus({ online: false, ...getConnection() }));\n\n useEffect(() => {\n if (navigator.connection) {\n navigator.connection.addEventListener('change', handleConnectionChange);\n return () => navigator.connection.removeEventListener('change', handleConnectionChange);\n }\n\n return undefined;\n }, []);\n\n return status;\n}\n"],"names":["useState","useCallback","useWindowEvent","useEffect"],"mappings":";;;;;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC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SAAS,EAAE,MAAM,SAAS,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC;AACjG,EAAEC,eAAS,CAAC,MAAM;AAClB,IAAI,IAAI,SAAS,CAAC,UAAU,EAAE;AAC9B,MAAM,SAAS,CAAC,UAAU,CAAC,gBAAgB,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;AAC9E,MAAM,OAAO,MAAM,SAAS,CAAC,UAAU,CAAC,mBAAmB,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;AAC9F,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,CAAC;AAClB,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,MAAM,CAAC;AAChB;;;;"}
|
|
@@ -29,11 +29,14 @@ function getConnection() {
|
|
|
29
29
|
}
|
|
30
30
|
const _navigator = navigator;
|
|
31
31
|
const connection = _navigator.connection || _navigator.mozConnection || _navigator.webkitConnection;
|
|
32
|
+
if (!connection) {
|
|
33
|
+
return defaultValue;
|
|
34
|
+
}
|
|
32
35
|
return {
|
|
33
|
-
downlink: connection.downlink,
|
|
34
|
-
effectiveType: connection.effectiveType,
|
|
35
|
-
saveData: connection.saveData,
|
|
36
|
-
rtt: connection.rtt
|
|
36
|
+
downlink: connection == null ? void 0 : connection.downlink,
|
|
37
|
+
effectiveType: connection == null ? void 0 : connection.effectiveType,
|
|
38
|
+
saveData: connection == null ? void 0 : connection.saveData,
|
|
39
|
+
rtt: connection == null ? void 0 : connection.rtt
|
|
37
40
|
};
|
|
38
41
|
}
|
|
39
42
|
function useNetwork() {
|
|
@@ -42,8 +45,11 @@ function useNetwork() {
|
|
|
42
45
|
useWindowEvent("online", () => setStatus(__spreadValues({ online: true }, getConnection())));
|
|
43
46
|
useWindowEvent("offline", () => setStatus(__spreadValues({ online: false }, getConnection())));
|
|
44
47
|
useEffect(() => {
|
|
45
|
-
navigator.connection
|
|
46
|
-
|
|
48
|
+
if (navigator.connection) {
|
|
49
|
+
navigator.connection.addEventListener("change", handleConnectionChange);
|
|
50
|
+
return () => navigator.connection.removeEventListener("change", handleConnectionChange);
|
|
51
|
+
}
|
|
52
|
+
return void 0;
|
|
47
53
|
}, []);
|
|
48
54
|
return status;
|
|
49
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-network.js","sources":["../../src/use-network/use-network.ts"],"sourcesContent":["import { useState, useEffect, useCallback } from 'react';\nimport { useWindowEvent } from '../use-window-event/use-window-event';\n\ninterface NetworkStatus {\n downlink: number;\n effectiveType: 'slow-2g' | '2g' | '3g' | '4g';\n saveData: boolean;\n rtt: number;\n}\n\nconst defaultValue: NetworkStatus = {\n downlink: 10,\n effectiveType: '4g',\n saveData: false,\n rtt: 50,\n};\n\nfunction getConnection(): NetworkStatus {\n if (typeof navigator === 'undefined') {\n return defaultValue;\n }\n\n const _navigator = navigator as any;\n const connection: any =\n _navigator.connection || _navigator.mozConnection || _navigator.webkitConnection;\n\n return {\n downlink: connection
|
|
1
|
+
{"version":3,"file":"use-network.js","sources":["../../src/use-network/use-network.ts"],"sourcesContent":["import { useState, useEffect, useCallback } from 'react';\nimport { useWindowEvent } from '../use-window-event/use-window-event';\n\ninterface NetworkStatus {\n downlink: number;\n effectiveType: 'slow-2g' | '2g' | '3g' | '4g';\n saveData: boolean;\n rtt: number;\n}\n\nconst defaultValue: NetworkStatus = {\n downlink: 10,\n effectiveType: '4g',\n saveData: false,\n rtt: 50,\n};\n\nfunction getConnection(): NetworkStatus {\n if (typeof navigator === 'undefined') {\n return defaultValue;\n }\n\n const _navigator = navigator as any;\n const connection: any =\n _navigator.connection || _navigator.mozConnection || _navigator.webkitConnection;\n\n if (!connection) {\n return defaultValue;\n }\n\n return {\n downlink: connection?.downlink,\n effectiveType: connection?.effectiveType,\n saveData: connection?.saveData,\n rtt: connection?.rtt,\n };\n}\n\nexport function useNetwork() {\n const [status, setStatus] = useState({ online: true, ...getConnection() });\n const handleConnectionChange = useCallback(\n () => setStatus((current) => ({ ...current, ...getConnection() })),\n []\n );\n\n useWindowEvent('online', () => setStatus({ online: true, ...getConnection() }));\n useWindowEvent('offline', () => setStatus({ online: false, ...getConnection() }));\n\n useEffect(() => {\n if (navigator.connection) {\n navigator.connection.addEventListener('change', handleConnectionChange);\n return () => navigator.connection.removeEventListener('change', handleConnectionChange);\n }\n\n return undefined;\n }, []);\n\n return status;\n}\n"],"names":[],"mappings":";;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAI,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;AAC/B,EAAE,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAChC,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC;AAClC,MAAM,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACxC,EAAE,IAAI,mBAAmB;AACzB,IAAI,KAAK,IAAI,IAAI,IAAI,mBAAmB,CAAC,CAAC,CAAC,EAAE;AAC7C,MAAM,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,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AAsB,GAAG,WAAW,CAAC,MAAM,SAAS,CAAC,CAAC,OAAO,KAAK,cAAc,CAAC,cAAc,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC7I,EAAE,cAAc,CAAC,QAAQ,EAAE,MAAM,SAAS,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC;AAC/F,EAAE,cAAc,CAAC,SAAS,EAAE,MAAM,SAAS,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC;AACjG,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,SAAS,CAAC,UAAU,EAAE;AAC9B,MAAM,SAAS,CAAC,UAAU,CAAC,gBAAgB,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;AAC9E,MAAM,OAAO,MAAM,SAAS,CAAC,UAAU,CAAC,mBAAmB,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;AAC9F,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,CAAC;AAClB,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,MAAM,CAAC;AAChB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-network.d.ts","sourceRoot":"","sources":["../../src/use-network/use-network.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-network.d.ts","sourceRoot":"","sources":["../../src/use-network/use-network.ts"],"names":[],"mappings":"AAsCA,wBAAgB,UAAU;;;;;;EAoBzB"}
|