@mado/hooks 0.2.0 → 0.3.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/CHANGELOG.md +6 -0
- package/dist/index.cjs +14 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/useOnline.cjs +31 -0
- package/dist/useOnline.cjs.map +1 -0
- package/dist/useOnline.d.cts +3 -0
- package/dist/useOnline.d.ts +3 -0
- package/dist/useOnline.js +29 -0
- package/dist/useOnline.js.map +1 -0
- package/dist/useVisibilityState.cjs +27 -0
- package/dist/useVisibilityState.cjs.map +1 -0
- package/dist/useVisibilityState.d.cts +3 -0
- package/dist/useVisibilityState.d.ts +3 -0
- package/dist/useVisibilityState.js +25 -0
- package/dist/useVisibilityState.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/useOnline.ts +28 -0
- package/src/useVisibilityState.ts +24 -0
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,9 @@ var useDebounce_cjs = require('./useDebounce.cjs');
|
|
|
4
4
|
var useEvent_cjs = require('./useEvent.cjs');
|
|
5
5
|
var useIsMounted_cjs = require('./useIsMounted.cjs');
|
|
6
6
|
var useIsomorphicLayoutEffect_cjs = require('./useIsomorphicLayoutEffect.cjs');
|
|
7
|
+
var useOnline_cjs = require('./useOnline.cjs');
|
|
7
8
|
var useRerender_cjs = require('./useRerender.cjs');
|
|
9
|
+
var useVisibilityState_cjs = require('./useVisibilityState.cjs');
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
|
|
@@ -32,11 +34,23 @@ Object.keys(useIsomorphicLayoutEffect_cjs).forEach(function (k) {
|
|
|
32
34
|
get: function () { return useIsomorphicLayoutEffect_cjs[k]; }
|
|
33
35
|
});
|
|
34
36
|
});
|
|
37
|
+
Object.keys(useOnline_cjs).forEach(function (k) {
|
|
38
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () { return useOnline_cjs[k]; }
|
|
41
|
+
});
|
|
42
|
+
});
|
|
35
43
|
Object.keys(useRerender_cjs).forEach(function (k) {
|
|
36
44
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
37
45
|
enumerable: true,
|
|
38
46
|
get: function () { return useRerender_cjs[k]; }
|
|
39
47
|
});
|
|
40
48
|
});
|
|
49
|
+
Object.keys(useVisibilityState_cjs).forEach(function (k) {
|
|
50
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
get: function () { return useVisibilityState_cjs[k]; }
|
|
53
|
+
});
|
|
54
|
+
});
|
|
41
55
|
//# sourceMappingURL=out.js.map
|
|
42
56
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc","sourcesContent":["export * from './useDebounce';\nexport * from './useEvent';\nexport * from './useIsMounted';\nexport * from './useIsomorphicLayoutEffect';\nexport * from './useRerender';\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc","sourcesContent":["export * from './useDebounce';\nexport * from './useEvent';\nexport * from './useIsMounted';\nexport * from './useIsomorphicLayoutEffect';\nexport * from './useOnline';\nexport * from './useRerender';\nexport * from './useVisibilityState';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -2,6 +2,8 @@ export { useDebounce } from './useDebounce.cjs';
|
|
|
2
2
|
export { useEvent } from './useEvent.cjs';
|
|
3
3
|
export { useIsMounted } from './useIsMounted.cjs';
|
|
4
4
|
export { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect.cjs';
|
|
5
|
+
export { useOnline } from './useOnline.cjs';
|
|
5
6
|
export { useRerender } from './useRerender.cjs';
|
|
7
|
+
export { useVisibilityState } from './useVisibilityState.cjs';
|
|
6
8
|
import '@mado/utils';
|
|
7
9
|
import 'react';
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export { useDebounce } from './useDebounce.js';
|
|
|
2
2
|
export { useEvent } from './useEvent.js';
|
|
3
3
|
export { useIsMounted } from './useIsMounted.js';
|
|
4
4
|
export { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect.js';
|
|
5
|
+
export { useOnline } from './useOnline.js';
|
|
5
6
|
export { useRerender } from './useRerender.js';
|
|
7
|
+
export { useVisibilityState } from './useVisibilityState.js';
|
|
6
8
|
import '@mado/utils';
|
|
7
9
|
import 'react';
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,8 @@ export * from './useDebounce.js';
|
|
|
2
2
|
export * from './useEvent.js';
|
|
3
3
|
export * from './useIsMounted.js';
|
|
4
4
|
export * from './useIsomorphicLayoutEffect.js';
|
|
5
|
+
export * from './useOnline.js';
|
|
5
6
|
export * from './useRerender.js';
|
|
7
|
+
export * from './useVisibilityState.js';
|
|
6
8
|
//# sourceMappingURL=out.js.map
|
|
7
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc","sourcesContent":["export * from './useDebounce';\nexport * from './useEvent';\nexport * from './useIsMounted';\nexport * from './useIsomorphicLayoutEffect';\nexport * from './useRerender';\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc","sourcesContent":["export * from './useDebounce';\nexport * from './useEvent';\nexport * from './useIsMounted';\nexport * from './useIsomorphicLayoutEffect';\nexport * from './useOnline';\nexport * from './useRerender';\nexport * from './useVisibilityState';\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
// src/useOnline.ts
|
|
6
|
+
function subscribe(onStoreChange) {
|
|
7
|
+
window.addEventListener("online", onStoreChange, {
|
|
8
|
+
passive: true
|
|
9
|
+
});
|
|
10
|
+
window.addEventListener("offline", onStoreChange, {
|
|
11
|
+
passive: true
|
|
12
|
+
});
|
|
13
|
+
return () => {
|
|
14
|
+
window.removeEventListener("online", onStoreChange);
|
|
15
|
+
window.removeEventListener("offline", onStoreChange);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function getSnapshot() {
|
|
19
|
+
return navigator.onLine;
|
|
20
|
+
}
|
|
21
|
+
function getServerSnapshot() {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
function useOnline() {
|
|
25
|
+
return react.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
26
|
+
}
|
|
27
|
+
/* istanbul ignore next -- @preserve */
|
|
28
|
+
|
|
29
|
+
exports.useOnline = useOnline;
|
|
30
|
+
//# sourceMappingURL=out.js.map
|
|
31
|
+
//# sourceMappingURL=useOnline.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useOnline.ts"],"names":[],"mappings":";AAAA,SAAS,4BAA4B;AAErC,SAAS,UAAU,eAA2C;AAC5D,SAAO,iBAAiB,UAAU,eAAe;AAAA,IAC/C,SAAS;AAAA,EACX,CAAC;AACD,SAAO,iBAAiB,WAAW,eAAe;AAAA,IAChD,SAAS;AAAA,EACX,CAAC;AAED,SAAO,MAAM;AACX,WAAO,oBAAoB,UAAU,aAAa;AAClD,WAAO,oBAAoB,WAAW,aAAa;AAAA,EACrD;AACF;AAEA,SAAS,cAAuB;AAC9B,SAAO,UAAU;AACnB;AAGA,SAAS,oBAA6B;AACpC,SAAO;AACT;AAEO,SAAS,YAAqB;AACnC,SAAO,qBAAqB,WAAW,aAAa,iBAAiB;AACvE","sourcesContent":["import { useSyncExternalStore } from 'react';\n\nfunction subscribe(onStoreChange: VoidFunction): VoidFunction {\n window.addEventListener('online', onStoreChange, {\n passive: true,\n });\n window.addEventListener('offline', onStoreChange, {\n passive: true,\n });\n\n return () => {\n window.removeEventListener('online', onStoreChange);\n window.removeEventListener('offline', onStoreChange);\n };\n}\n\nfunction getSnapshot(): boolean {\n return navigator.onLine;\n}\n\n/* istanbul ignore next -- @preserve */\nfunction getServerSnapshot(): boolean {\n return true;\n}\n\nexport function useOnline(): boolean {\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useSyncExternalStore } from 'react';
|
|
2
|
+
|
|
3
|
+
// src/useOnline.ts
|
|
4
|
+
function subscribe(onStoreChange) {
|
|
5
|
+
window.addEventListener("online", onStoreChange, {
|
|
6
|
+
passive: true
|
|
7
|
+
});
|
|
8
|
+
window.addEventListener("offline", onStoreChange, {
|
|
9
|
+
passive: true
|
|
10
|
+
});
|
|
11
|
+
return () => {
|
|
12
|
+
window.removeEventListener("online", onStoreChange);
|
|
13
|
+
window.removeEventListener("offline", onStoreChange);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function getSnapshot() {
|
|
17
|
+
return navigator.onLine;
|
|
18
|
+
}
|
|
19
|
+
function getServerSnapshot() {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
function useOnline() {
|
|
23
|
+
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
24
|
+
}
|
|
25
|
+
/* istanbul ignore next -- @preserve */
|
|
26
|
+
|
|
27
|
+
export { useOnline };
|
|
28
|
+
//# sourceMappingURL=out.js.map
|
|
29
|
+
//# sourceMappingURL=useOnline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useOnline.ts"],"names":[],"mappings":";AAAA,SAAS,4BAA4B;AAErC,SAAS,UAAU,eAA2C;AAC5D,SAAO,iBAAiB,UAAU,eAAe;AAAA,IAC/C,SAAS;AAAA,EACX,CAAC;AACD,SAAO,iBAAiB,WAAW,eAAe;AAAA,IAChD,SAAS;AAAA,EACX,CAAC;AAED,SAAO,MAAM;AACX,WAAO,oBAAoB,UAAU,aAAa;AAClD,WAAO,oBAAoB,WAAW,aAAa;AAAA,EACrD;AACF;AAEA,SAAS,cAAuB;AAC9B,SAAO,UAAU;AACnB;AAGA,SAAS,oBAA6B;AACpC,SAAO;AACT;AAEO,SAAS,YAAqB;AACnC,SAAO,qBAAqB,WAAW,aAAa,iBAAiB;AACvE","sourcesContent":["import { useSyncExternalStore } from 'react';\n\nfunction subscribe(onStoreChange: VoidFunction): VoidFunction {\n window.addEventListener('online', onStoreChange, {\n passive: true,\n });\n window.addEventListener('offline', onStoreChange, {\n passive: true,\n });\n\n return () => {\n window.removeEventListener('online', onStoreChange);\n window.removeEventListener('offline', onStoreChange);\n };\n}\n\nfunction getSnapshot(): boolean {\n return navigator.onLine;\n}\n\n/* istanbul ignore next -- @preserve */\nfunction getServerSnapshot(): boolean {\n return true;\n}\n\nexport function useOnline(): boolean {\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
// src/useVisibilityState.ts
|
|
6
|
+
function subscribe(onStoreChange) {
|
|
7
|
+
document.addEventListener("visibilitychange", onStoreChange, {
|
|
8
|
+
passive: true
|
|
9
|
+
});
|
|
10
|
+
return () => {
|
|
11
|
+
document.removeEventListener("visibilitychange", onStoreChange);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function getSnapshot() {
|
|
15
|
+
return document.visibilityState;
|
|
16
|
+
}
|
|
17
|
+
function getServerSnapshot() {
|
|
18
|
+
return "visible";
|
|
19
|
+
}
|
|
20
|
+
function useVisibilityState() {
|
|
21
|
+
return react.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
22
|
+
}
|
|
23
|
+
/* istanbul ignore next -- @preserve */
|
|
24
|
+
|
|
25
|
+
exports.useVisibilityState = useVisibilityState;
|
|
26
|
+
//# sourceMappingURL=out.js.map
|
|
27
|
+
//# sourceMappingURL=useVisibilityState.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useVisibilityState.ts"],"names":[],"mappings":";AAAA,SAAS,4BAA4B;AAErC,SAAS,UAAU,eAA2C;AAC5D,WAAS,iBAAiB,oBAAoB,eAAe;AAAA,IAC3D,SAAS;AAAA,EACX,CAAC;AAED,SAAO,MAAM;AACX,aAAS,oBAAoB,oBAAoB,aAAa;AAAA,EAChE;AACF;AAEA,SAAS,cAAuC;AAC9C,SAAO,SAAS;AAClB;AAGA,SAAS,oBAA6C;AACpD,SAAO;AACT;AAEO,SAAS,qBAA8C;AAC5D,SAAO,qBAAqB,WAAW,aAAa,iBAAiB;AACvE","sourcesContent":["import { useSyncExternalStore } from 'react';\n\nfunction subscribe(onStoreChange: VoidFunction): VoidFunction {\n document.addEventListener('visibilitychange', onStoreChange, {\n passive: true,\n });\n\n return () => {\n document.removeEventListener('visibilitychange', onStoreChange);\n };\n}\n\nfunction getSnapshot(): DocumentVisibilityState {\n return document.visibilityState;\n}\n\n/* istanbul ignore next -- @preserve */\nfunction getServerSnapshot(): DocumentVisibilityState {\n return 'visible';\n}\n\nexport function useVisibilityState(): DocumentVisibilityState {\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useSyncExternalStore } from 'react';
|
|
2
|
+
|
|
3
|
+
// src/useVisibilityState.ts
|
|
4
|
+
function subscribe(onStoreChange) {
|
|
5
|
+
document.addEventListener("visibilitychange", onStoreChange, {
|
|
6
|
+
passive: true
|
|
7
|
+
});
|
|
8
|
+
return () => {
|
|
9
|
+
document.removeEventListener("visibilitychange", onStoreChange);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function getSnapshot() {
|
|
13
|
+
return document.visibilityState;
|
|
14
|
+
}
|
|
15
|
+
function getServerSnapshot() {
|
|
16
|
+
return "visible";
|
|
17
|
+
}
|
|
18
|
+
function useVisibilityState() {
|
|
19
|
+
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
20
|
+
}
|
|
21
|
+
/* istanbul ignore next -- @preserve */
|
|
22
|
+
|
|
23
|
+
export { useVisibilityState };
|
|
24
|
+
//# sourceMappingURL=out.js.map
|
|
25
|
+
//# sourceMappingURL=useVisibilityState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useVisibilityState.ts"],"names":[],"mappings":";AAAA,SAAS,4BAA4B;AAErC,SAAS,UAAU,eAA2C;AAC5D,WAAS,iBAAiB,oBAAoB,eAAe;AAAA,IAC3D,SAAS;AAAA,EACX,CAAC;AAED,SAAO,MAAM;AACX,aAAS,oBAAoB,oBAAoB,aAAa;AAAA,EAChE;AACF;AAEA,SAAS,cAAuC;AAC9C,SAAO,SAAS;AAClB;AAGA,SAAS,oBAA6C;AACpD,SAAO;AACT;AAEO,SAAS,qBAA8C;AAC5D,SAAO,qBAAqB,WAAW,aAAa,iBAAiB;AACvE","sourcesContent":["import { useSyncExternalStore } from 'react';\n\nfunction subscribe(onStoreChange: VoidFunction): VoidFunction {\n document.addEventListener('visibilitychange', onStoreChange, {\n passive: true,\n });\n\n return () => {\n document.removeEventListener('visibilitychange', onStoreChange);\n };\n}\n\nfunction getSnapshot(): DocumentVisibilityState {\n return document.visibilityState;\n}\n\n/* istanbul ignore next -- @preserve */\nfunction getServerSnapshot(): DocumentVisibilityState {\n return 'visible';\n}\n\nexport function useVisibilityState(): DocumentVisibilityState {\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n}\n"]}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/useOnline.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useSyncExternalStore } from 'react';
|
|
2
|
+
|
|
3
|
+
function subscribe(onStoreChange: VoidFunction): VoidFunction {
|
|
4
|
+
window.addEventListener('online', onStoreChange, {
|
|
5
|
+
passive: true,
|
|
6
|
+
});
|
|
7
|
+
window.addEventListener('offline', onStoreChange, {
|
|
8
|
+
passive: true,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
return () => {
|
|
12
|
+
window.removeEventListener('online', onStoreChange);
|
|
13
|
+
window.removeEventListener('offline', onStoreChange);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getSnapshot(): boolean {
|
|
18
|
+
return navigator.onLine;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/* istanbul ignore next -- @preserve */
|
|
22
|
+
function getServerSnapshot(): boolean {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function useOnline(): boolean {
|
|
27
|
+
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useSyncExternalStore } from 'react';
|
|
2
|
+
|
|
3
|
+
function subscribe(onStoreChange: VoidFunction): VoidFunction {
|
|
4
|
+
document.addEventListener('visibilitychange', onStoreChange, {
|
|
5
|
+
passive: true,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
return () => {
|
|
9
|
+
document.removeEventListener('visibilitychange', onStoreChange);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getSnapshot(): DocumentVisibilityState {
|
|
14
|
+
return document.visibilityState;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* istanbul ignore next -- @preserve */
|
|
18
|
+
function getServerSnapshot(): DocumentVisibilityState {
|
|
19
|
+
return 'visible';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function useVisibilityState(): DocumentVisibilityState {
|
|
23
|
+
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
24
|
+
}
|