@mado/hooks 0.4.0 → 0.5.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 +21 -0
- package/LICENSE +1 -1
- package/dist/index.cjs +2 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +2 -10
- package/dist/index.js.map +1 -1
- package/dist/use-debounce.cjs +2 -0
- package/dist/use-debounce.cjs.map +1 -0
- package/dist/use-debounce.js +2 -0
- package/dist/use-debounce.js.map +1 -0
- package/dist/use-event.cjs +2 -0
- package/dist/use-event.cjs.map +1 -0
- package/dist/use-event.js +2 -0
- package/dist/use-event.js.map +1 -0
- package/dist/use-is-mounted.cjs +2 -0
- package/dist/use-is-mounted.cjs.map +1 -0
- package/dist/use-is-mounted.js +2 -0
- package/dist/use-is-mounted.js.map +1 -0
- package/dist/use-isomorphic-layout-effect.cjs +2 -0
- package/dist/use-isomorphic-layout-effect.cjs.map +1 -0
- package/dist/use-isomorphic-layout-effect.js +2 -0
- package/dist/use-isomorphic-layout-effect.js.map +1 -0
- package/dist/use-media-query.cjs +2 -0
- package/dist/use-media-query.cjs.map +1 -0
- package/dist/use-media-query.js +2 -0
- package/dist/use-media-query.js.map +1 -0
- package/dist/use-online.cjs +2 -0
- package/dist/use-online.cjs.map +1 -0
- package/dist/use-online.d.cts +3 -0
- package/dist/use-online.d.ts +3 -0
- package/dist/use-online.js +2 -0
- package/dist/use-online.js.map +1 -0
- package/dist/use-rerender.cjs +2 -0
- package/dist/use-rerender.cjs.map +1 -0
- package/dist/use-rerender.js +2 -0
- package/dist/use-rerender.js.map +1 -0
- package/dist/use-visibility-state.cjs +2 -0
- package/dist/use-visibility-state.cjs.map +1 -0
- package/dist/use-visibility-state.d.cts +3 -0
- package/dist/use-visibility-state.d.ts +3 -0
- package/dist/use-visibility-state.js +2 -0
- package/dist/use-visibility-state.js.map +1 -0
- package/package.json +32 -18
- package/src/index.ts +8 -8
- package/src/{useDebounce.ts → use-debounce.ts} +3 -2
- package/src/use-event.ts +14 -0
- package/src/use-is-mounted.ts +15 -0
- package/src/use-isomorphic-layout-effect.ts +3 -0
- package/src/{useMediaQuery.ts → use-media-query.ts} +2 -6
- package/src/{useOnline.ts → use-online.ts} +3 -9
- package/src/{useRerender.ts → use-rerender.ts} +2 -1
- package/src/use-visibility-state.ts +21 -0
- package/dist/useDebounce.cjs +0 -21
- package/dist/useDebounce.cjs.map +0 -1
- package/dist/useDebounce.js +0 -19
- package/dist/useDebounce.js.map +0 -1
- package/dist/useEvent.cjs +0 -17
- package/dist/useEvent.cjs.map +0 -1
- package/dist/useEvent.js +0 -15
- package/dist/useEvent.js.map +0 -1
- package/dist/useIsMounted.cjs +0 -16
- package/dist/useIsMounted.cjs.map +0 -1
- package/dist/useIsMounted.js +0 -14
- package/dist/useIsMounted.js.map +0 -1
- package/dist/useIsomorphicLayoutEffect.cjs +0 -10
- package/dist/useIsomorphicLayoutEffect.cjs.map +0 -1
- package/dist/useIsomorphicLayoutEffect.js +0 -8
- package/dist/useIsomorphicLayoutEffect.js.map +0 -1
- package/dist/useMediaQuery.cjs +0 -36
- package/dist/useMediaQuery.cjs.map +0 -1
- package/dist/useMediaQuery.js +0 -34
- package/dist/useMediaQuery.js.map +0 -1
- package/dist/useOnline.cjs +0 -31
- package/dist/useOnline.cjs.map +0 -1
- package/dist/useOnline.d.cts +0 -3
- package/dist/useOnline.d.ts +0 -3
- package/dist/useOnline.js +0 -29
- package/dist/useOnline.js.map +0 -1
- package/dist/useRerender.cjs +0 -16
- package/dist/useRerender.cjs.map +0 -1
- package/dist/useRerender.js +0 -14
- package/dist/useRerender.js.map +0 -1
- package/dist/useVisibilityState.cjs +0 -27
- package/dist/useVisibilityState.cjs.map +0 -1
- package/dist/useVisibilityState.d.cts +0 -3
- package/dist/useVisibilityState.d.ts +0 -3
- package/dist/useVisibilityState.js +0 -25
- package/dist/useVisibilityState.js.map +0 -1
- package/src/useEvent.ts +0 -15
- package/src/useIsMounted.ts +0 -11
- package/src/useIsomorphicLayoutEffect.ts +0 -4
- package/src/useVisibilityState.ts +0 -25
- /package/dist/{useDebounce.d.cts → use-debounce.d.cts} +0 -0
- /package/dist/{useDebounce.d.ts → use-debounce.d.ts} +0 -0
- /package/dist/{useEvent.d.cts → use-event.d.cts} +0 -0
- /package/dist/{useEvent.d.ts → use-event.d.ts} +0 -0
- /package/dist/{useIsMounted.d.cts → use-is-mounted.d.cts} +0 -0
- /package/dist/{useIsMounted.d.ts → use-is-mounted.d.ts} +0 -0
- /package/dist/{useIsomorphicLayoutEffect.d.cts → use-isomorphic-layout-effect.d.cts} +0 -0
- /package/dist/{useIsomorphicLayoutEffect.d.ts → use-isomorphic-layout-effect.d.ts} +0 -0
- /package/dist/{useMediaQuery.d.cts → use-media-query.d.cts} +0 -0
- /package/dist/{useMediaQuery.d.ts → use-media-query.d.ts} +0 -0
- /package/dist/{useRerender.d.cts → use-rerender.d.cts} +0 -0
- /package/dist/{useRerender.d.ts → use-rerender.d.ts} +0 -0
package/dist/useDebounce.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { debounce } from '@mado/utils';
|
|
2
|
-
import { useMemo, useEffect } from 'react';
|
|
3
|
-
import { useEvent } from './useEvent.js';
|
|
4
|
-
|
|
5
|
-
// src/useDebounce.ts
|
|
6
|
-
function useDebounce(fn, wait) {
|
|
7
|
-
const callback = useEvent(fn);
|
|
8
|
-
const debounced = useMemo(() => debounce(callback, wait), [callback, wait]);
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
return () => {
|
|
11
|
-
debounced.cancel();
|
|
12
|
-
};
|
|
13
|
-
}, [debounced]);
|
|
14
|
-
return debounced;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { useDebounce };
|
|
18
|
-
//# sourceMappingURL=out.js.map
|
|
19
|
-
//# sourceMappingURL=useDebounce.js.map
|
package/dist/useDebounce.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useDebounce.ts"],"names":[],"mappings":";AAAA,SAA0B,gBAAgB;AAC1C,SAAS,WAAW,eAAe;AAEnC,SAAS,gBAAgB;AAElB,SAAS,YACd,IACA,MACkC;AAClC,QAAM,WAAW,SAAS,EAAE;AAE5B,QAAM,YAAY,QAAQ,MAAM,SAAS,UAAU,IAAI,GAAG,CAAC,UAAU,IAAI,CAAC;AAE1E,YAAU,MAAM;AACd,WAAO,MAAM;AACX,gBAAU,OAAO;AAAA,IACnB;AAAA,EACF,GAAG,CAAC,SAAS,CAAC;AAEd,SAAO;AACT","sourcesContent":["import { type Cancelable, debounce } from '@mado/utils';\nimport { useEffect, useMemo } from 'react';\n\nimport { useEvent } from './useEvent';\n\nexport function useDebounce<T extends any[], U>(\n fn: (...args: T) => U,\n wait?: number,\n): ((...args: T) => U) & Cancelable {\n const callback = useEvent(fn);\n\n const debounced = useMemo(() => debounce(callback, wait), [callback, wait]);\n\n useEffect(() => {\n return () => {\n debounced.cancel();\n };\n }, [debounced]);\n\n return debounced;\n}\n"]}
|
package/dist/useEvent.cjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var react = require('react');
|
|
4
|
-
var useIsomorphicLayoutEffect_cjs = require('./useIsomorphicLayoutEffect.cjs');
|
|
5
|
-
|
|
6
|
-
// src/useEvent.ts
|
|
7
|
-
function useEvent(fn) {
|
|
8
|
-
const ref = react.useRef(fn);
|
|
9
|
-
useIsomorphicLayoutEffect_cjs.useIsomorphicLayoutEffect(() => {
|
|
10
|
-
ref.current = fn;
|
|
11
|
-
});
|
|
12
|
-
return react.useRef((...args) => (0, ref.current)(...args)).current;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
exports.useEvent = useEvent;
|
|
16
|
-
//# sourceMappingURL=out.js.map
|
|
17
|
-
//# sourceMappingURL=useEvent.cjs.map
|
package/dist/useEvent.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useEvent.ts"],"names":[],"mappings":";AAAA,SAAS,cAAc;AAEvB,SAAS,iCAAiC;AAEnC,SAAS,SACd,IACmB;AACnB,QAAM,MAAM,OAAO,EAAE;AAErB,4BAA0B,MAAM;AAC9B,QAAI,UAAU;AAAA,EAChB,CAAC;AAED,SAAO,OAAO,IAAI,UAAa,GAAG,IAAI,SAAS,GAAG,IAAI,CAAC,EAAE;AAC3D","sourcesContent":["import { useRef } from 'react';\n\nimport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';\n\nexport function useEvent<T extends unknown[], U>(\n fn: (...args: T) => U,\n): (...args: T) => U {\n const ref = useRef(fn);\n\n useIsomorphicLayoutEffect(() => {\n ref.current = fn;\n });\n\n return useRef((...args: T) => (0, ref.current)(...args)).current;\n}\n"]}
|
package/dist/useEvent.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useRef } from 'react';
|
|
2
|
-
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect.js';
|
|
3
|
-
|
|
4
|
-
// src/useEvent.ts
|
|
5
|
-
function useEvent(fn) {
|
|
6
|
-
const ref = useRef(fn);
|
|
7
|
-
useIsomorphicLayoutEffect(() => {
|
|
8
|
-
ref.current = fn;
|
|
9
|
-
});
|
|
10
|
-
return useRef((...args) => (0, ref.current)(...args)).current;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { useEvent };
|
|
14
|
-
//# sourceMappingURL=out.js.map
|
|
15
|
-
//# sourceMappingURL=useEvent.js.map
|
package/dist/useEvent.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useEvent.ts"],"names":[],"mappings":";AAAA,SAAS,cAAc;AAEvB,SAAS,iCAAiC;AAEnC,SAAS,SACd,IACmB;AACnB,QAAM,MAAM,OAAO,EAAE;AAErB,4BAA0B,MAAM;AAC9B,QAAI,UAAU;AAAA,EAChB,CAAC;AAED,SAAO,OAAO,IAAI,UAAa,GAAG,IAAI,SAAS,GAAG,IAAI,CAAC,EAAE;AAC3D","sourcesContent":["import { useRef } from 'react';\n\nimport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';\n\nexport function useEvent<T extends unknown[], U>(\n fn: (...args: T) => U,\n): (...args: T) => U {\n const ref = useRef(fn);\n\n useIsomorphicLayoutEffect(() => {\n ref.current = fn;\n });\n\n return useRef((...args: T) => (0, ref.current)(...args)).current;\n}\n"]}
|
package/dist/useIsMounted.cjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var react = require('react');
|
|
4
|
-
|
|
5
|
-
// src/useIsMounted.ts
|
|
6
|
-
function useIsMounted() {
|
|
7
|
-
const [isMounted, setIsMounted] = react.useState(false);
|
|
8
|
-
react.useEffect(() => {
|
|
9
|
-
setIsMounted(true);
|
|
10
|
-
}, []);
|
|
11
|
-
return isMounted;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
exports.useIsMounted = useIsMounted;
|
|
15
|
-
//# sourceMappingURL=out.js.map
|
|
16
|
-
//# sourceMappingURL=useIsMounted.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useIsMounted.ts"],"names":[],"mappings":";AAAA,SAAS,WAAW,gBAAgB;AAE7B,SAAS,eAAwB;AACtC,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAEhD,YAAU,MAAM;AACd,iBAAa,IAAI;AAAA,EACnB,GAAG,CAAC,CAAC;AAEL,SAAO;AACT","sourcesContent":["import { useEffect, useState } from 'react';\n\nexport function useIsMounted(): boolean {\n const [isMounted, setIsMounted] = useState(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n return isMounted;\n}\n"]}
|
package/dist/useIsMounted.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
// src/useIsMounted.ts
|
|
4
|
-
function useIsMounted() {
|
|
5
|
-
const [isMounted, setIsMounted] = useState(false);
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
setIsMounted(true);
|
|
8
|
-
}, []);
|
|
9
|
-
return isMounted;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export { useIsMounted };
|
|
13
|
-
//# sourceMappingURL=out.js.map
|
|
14
|
-
//# sourceMappingURL=useIsMounted.js.map
|
package/dist/useIsMounted.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useIsMounted.ts"],"names":[],"mappings":";AAAA,SAAS,WAAW,gBAAgB;AAE7B,SAAS,eAAwB;AACtC,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAEhD,YAAU,MAAM;AACd,iBAAa,IAAI;AAAA,EACnB,GAAG,CAAC,CAAC;AAEL,SAAO;AACT","sourcesContent":["import { useEffect, useState } from 'react';\n\nexport function useIsMounted(): boolean {\n const [isMounted, setIsMounted] = useState(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n return isMounted;\n}\n"]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var react = require('react');
|
|
4
|
-
|
|
5
|
-
// src/useIsomorphicLayoutEffect.ts
|
|
6
|
-
var useIsomorphicLayoutEffect = typeof window === "undefined" ? react.useEffect : react.useLayoutEffect;
|
|
7
|
-
|
|
8
|
-
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
9
|
-
//# sourceMappingURL=out.js.map
|
|
10
|
-
//# sourceMappingURL=useIsomorphicLayoutEffect.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":";AAAA,SAAS,WAAW,uBAAuB;AAEpC,IAAM,4BACX,OAAO,WAAW,cAAc,YAAY","sourcesContent":["import { useEffect, useLayoutEffect } from 'react';\n\nexport const useIsomorphicLayoutEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n"]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { useEffect, useLayoutEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
// src/useIsomorphicLayoutEffect.ts
|
|
4
|
-
var useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
5
|
-
|
|
6
|
-
export { useIsomorphicLayoutEffect };
|
|
7
|
-
//# sourceMappingURL=out.js.map
|
|
8
|
-
//# sourceMappingURL=useIsomorphicLayoutEffect.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":";AAAA,SAAS,WAAW,uBAAuB;AAEpC,IAAM,4BACX,OAAO,WAAW,cAAc,YAAY","sourcesContent":["import { useEffect, useLayoutEffect } from 'react';\n\nexport const useIsomorphicLayoutEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n"]}
|
package/dist/useMediaQuery.cjs
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var react = require('react');
|
|
4
|
-
var index_js = require('use-sync-external-store/shim/index.js');
|
|
5
|
-
|
|
6
|
-
// src/useMediaQuery.ts
|
|
7
|
-
function useMediaQuery(query, defaultMatches = false) {
|
|
8
|
-
const [subscribe, getSnapshot, getServerSnapshot] = react.useMemo(() => {
|
|
9
|
-
const matchMedia = typeof window !== "undefined" && window.matchMedia;
|
|
10
|
-
const getDefaultSnapshot = () => {
|
|
11
|
-
return defaultMatches;
|
|
12
|
-
};
|
|
13
|
-
if (!matchMedia) {
|
|
14
|
-
return [() => () => {
|
|
15
|
-
}, getDefaultSnapshot, getDefaultSnapshot];
|
|
16
|
-
}
|
|
17
|
-
const mediaQueryList = matchMedia(query);
|
|
18
|
-
return [
|
|
19
|
-
(onStoreChange) => {
|
|
20
|
-
mediaQueryList.addListener(onStoreChange);
|
|
21
|
-
return () => {
|
|
22
|
-
mediaQueryList.removeListener(onStoreChange);
|
|
23
|
-
};
|
|
24
|
-
},
|
|
25
|
-
() => {
|
|
26
|
-
return mediaQueryList.matches;
|
|
27
|
-
},
|
|
28
|
-
getDefaultSnapshot
|
|
29
|
-
];
|
|
30
|
-
}, [defaultMatches, query]);
|
|
31
|
-
return index_js.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
exports.useMediaQuery = useMediaQuery;
|
|
35
|
-
//# sourceMappingURL=out.js.map
|
|
36
|
-
//# sourceMappingURL=useMediaQuery.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useMediaQuery.ts"],"names":[],"mappings":";AAAA,SAAS,eAAe;AAExB,SAAS,4BAA4B;AAE9B,SAAS,cAAc,OAAe,iBAAiB,OAAgB;AAC5E,QAAM,CAAC,WAAW,aAAa,iBAAiB,IAAI,QAAQ,MAAM;AAChE,UAAM,aAAa,OAAO,WAAW,eAAe,OAAO;AAE3D,UAAM,qBAAqB,MAAM;AAC/B,aAAO;AAAA,IACT;AAEA,QAAI,CAAC,YAAY;AACf,aAAO,CAAC,MAAM,MAAM;AAAA,MAAC,GAAG,oBAAoB,kBAAkB;AAAA,IAChE;AAEA,UAAM,iBAAiB,WAAW,KAAK;AAEvC,WAAO;AAAA,MACL,CAAC,kBAAgC;AAC/B,uBAAe,YAAY,aAAa;AAExC,eAAO,MAAM;AACX,yBAAe,eAAe,aAAa;AAAA,QAC7C;AAAA,MACF;AAAA,MACA,MAAM;AACJ,eAAO,eAAe;AAAA,MACxB;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,gBAAgB,KAAK,CAAC;AAE1B,SAAO,qBAAqB,WAAW,aAAa,iBAAiB;AACvE","sourcesContent":["import { useMemo } from 'react';\n// eslint-disable-next-line import/extensions\nimport { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';\n\nexport function useMediaQuery(query: string, defaultMatches = false): boolean {\n const [subscribe, getSnapshot, getServerSnapshot] = useMemo(() => {\n const matchMedia = typeof window !== 'undefined' && window.matchMedia;\n\n const getDefaultSnapshot = () => {\n return defaultMatches;\n };\n\n if (!matchMedia) {\n return [() => () => {}, getDefaultSnapshot, getDefaultSnapshot];\n }\n\n const mediaQueryList = matchMedia(query);\n\n return [\n (onStoreChange: VoidFunction) => {\n mediaQueryList.addListener(onStoreChange);\n\n return () => {\n mediaQueryList.removeListener(onStoreChange);\n };\n },\n () => {\n return mediaQueryList.matches;\n },\n getDefaultSnapshot,\n ];\n }, [defaultMatches, query]);\n\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n}\n"]}
|
package/dist/useMediaQuery.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
|
|
3
|
-
|
|
4
|
-
// src/useMediaQuery.ts
|
|
5
|
-
function useMediaQuery(query, defaultMatches = false) {
|
|
6
|
-
const [subscribe, getSnapshot, getServerSnapshot] = useMemo(() => {
|
|
7
|
-
const matchMedia = typeof window !== "undefined" && window.matchMedia;
|
|
8
|
-
const getDefaultSnapshot = () => {
|
|
9
|
-
return defaultMatches;
|
|
10
|
-
};
|
|
11
|
-
if (!matchMedia) {
|
|
12
|
-
return [() => () => {
|
|
13
|
-
}, getDefaultSnapshot, getDefaultSnapshot];
|
|
14
|
-
}
|
|
15
|
-
const mediaQueryList = matchMedia(query);
|
|
16
|
-
return [
|
|
17
|
-
(onStoreChange) => {
|
|
18
|
-
mediaQueryList.addListener(onStoreChange);
|
|
19
|
-
return () => {
|
|
20
|
-
mediaQueryList.removeListener(onStoreChange);
|
|
21
|
-
};
|
|
22
|
-
},
|
|
23
|
-
() => {
|
|
24
|
-
return mediaQueryList.matches;
|
|
25
|
-
},
|
|
26
|
-
getDefaultSnapshot
|
|
27
|
-
];
|
|
28
|
-
}, [defaultMatches, query]);
|
|
29
|
-
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export { useMediaQuery };
|
|
33
|
-
//# sourceMappingURL=out.js.map
|
|
34
|
-
//# sourceMappingURL=useMediaQuery.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useMediaQuery.ts"],"names":[],"mappings":";AAAA,SAAS,eAAe;AAExB,SAAS,4BAA4B;AAE9B,SAAS,cAAc,OAAe,iBAAiB,OAAgB;AAC5E,QAAM,CAAC,WAAW,aAAa,iBAAiB,IAAI,QAAQ,MAAM;AAChE,UAAM,aAAa,OAAO,WAAW,eAAe,OAAO;AAE3D,UAAM,qBAAqB,MAAM;AAC/B,aAAO;AAAA,IACT;AAEA,QAAI,CAAC,YAAY;AACf,aAAO,CAAC,MAAM,MAAM;AAAA,MAAC,GAAG,oBAAoB,kBAAkB;AAAA,IAChE;AAEA,UAAM,iBAAiB,WAAW,KAAK;AAEvC,WAAO;AAAA,MACL,CAAC,kBAAgC;AAC/B,uBAAe,YAAY,aAAa;AAExC,eAAO,MAAM;AACX,yBAAe,eAAe,aAAa;AAAA,QAC7C;AAAA,MACF;AAAA,MACA,MAAM;AACJ,eAAO,eAAe;AAAA,MACxB;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,gBAAgB,KAAK,CAAC;AAE1B,SAAO,qBAAqB,WAAW,aAAa,iBAAiB;AACvE","sourcesContent":["import { useMemo } from 'react';\n// eslint-disable-next-line import/extensions\nimport { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';\n\nexport function useMediaQuery(query: string, defaultMatches = false): boolean {\n const [subscribe, getSnapshot, getServerSnapshot] = useMemo(() => {\n const matchMedia = typeof window !== 'undefined' && window.matchMedia;\n\n const getDefaultSnapshot = () => {\n return defaultMatches;\n };\n\n if (!matchMedia) {\n return [() => () => {}, getDefaultSnapshot, getDefaultSnapshot];\n }\n\n const mediaQueryList = matchMedia(query);\n\n return [\n (onStoreChange: VoidFunction) => {\n mediaQueryList.addListener(onStoreChange);\n\n return () => {\n mediaQueryList.removeListener(onStoreChange);\n };\n },\n () => {\n return mediaQueryList.matches;\n },\n getDefaultSnapshot,\n ];\n }, [defaultMatches, query]);\n\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n}\n"]}
|
package/dist/useOnline.cjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var index_js = require('use-sync-external-store/shim/index.js');
|
|
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 index_js.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
|
package/dist/useOnline.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useOnline.ts"],"names":[],"mappings":";AACA,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":["// eslint-disable-next-line import/extensions\nimport { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';\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"]}
|
package/dist/useOnline.d.cts
DELETED
package/dist/useOnline.d.ts
DELETED
package/dist/useOnline.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
|
|
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
|
package/dist/useOnline.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useOnline.ts"],"names":[],"mappings":";AACA,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":["// eslint-disable-next-line import/extensions\nimport { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';\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"]}
|
package/dist/useRerender.cjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var react = require('react');
|
|
4
|
-
|
|
5
|
-
// src/useRerender.ts
|
|
6
|
-
var initialState = {};
|
|
7
|
-
function reducer() {
|
|
8
|
-
return {};
|
|
9
|
-
}
|
|
10
|
-
function useRerender() {
|
|
11
|
-
return react.useReducer(reducer, initialState)[1];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
exports.useRerender = useRerender;
|
|
15
|
-
//# sourceMappingURL=out.js.map
|
|
16
|
-
//# sourceMappingURL=useRerender.cjs.map
|
package/dist/useRerender.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useRerender.ts"],"names":[],"mappings":";AAAA,SAAqC,kBAAkB;AAEvD,IAAM,eAAe,CAAC;AAEtB,SAAS,UAAU;AACjB,SAAO,CAAC;AACV;AAEO,SAAS,cAAqC;AACnD,SAAO,WAAW,SAAS,YAAY,EAAE,CAAC;AAC5C","sourcesContent":["import { type DispatchWithoutAction, useReducer } from 'react';\n\nconst initialState = {};\n\nfunction reducer() {\n return {};\n}\n\nexport function useRerender(): DispatchWithoutAction {\n return useReducer(reducer, initialState)[1];\n}\n"]}
|
package/dist/useRerender.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { useReducer } from 'react';
|
|
2
|
-
|
|
3
|
-
// src/useRerender.ts
|
|
4
|
-
var initialState = {};
|
|
5
|
-
function reducer() {
|
|
6
|
-
return {};
|
|
7
|
-
}
|
|
8
|
-
function useRerender() {
|
|
9
|
-
return useReducer(reducer, initialState)[1];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export { useRerender };
|
|
13
|
-
//# sourceMappingURL=out.js.map
|
|
14
|
-
//# sourceMappingURL=useRerender.js.map
|
package/dist/useRerender.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useRerender.ts"],"names":[],"mappings":";AAAA,SAAqC,kBAAkB;AAEvD,IAAM,eAAe,CAAC;AAEtB,SAAS,UAAU;AACjB,SAAO,CAAC;AACV;AAEO,SAAS,cAAqC;AACnD,SAAO,WAAW,SAAS,YAAY,EAAE,CAAC;AAC5C","sourcesContent":["import { type DispatchWithoutAction, useReducer } from 'react';\n\nconst initialState = {};\n\nfunction reducer() {\n return {};\n}\n\nexport function useRerender(): DispatchWithoutAction {\n return useReducer(reducer, initialState)[1];\n}\n"]}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var index_js = require('use-sync-external-store/shim/index.js');
|
|
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 index_js.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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useVisibilityState.ts"],"names":[],"mappings":";AACA,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":["// eslint-disable-next-line import/extensions\nimport { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';\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"]}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useVisibilityState.ts"],"names":[],"mappings":";AACA,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":["// eslint-disable-next-line import/extensions\nimport { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';\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/src/useEvent.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
|
|
4
|
-
|
|
5
|
-
export function useEvent<T extends unknown[], U>(
|
|
6
|
-
fn: (...args: T) => U,
|
|
7
|
-
): (...args: T) => U {
|
|
8
|
-
const ref = useRef(fn);
|
|
9
|
-
|
|
10
|
-
useIsomorphicLayoutEffect(() => {
|
|
11
|
-
ref.current = fn;
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
return useRef((...args: T) => (0, ref.current)(...args)).current;
|
|
15
|
-
}
|
package/src/useIsMounted.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line import/extensions
|
|
2
|
-
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
|
|
3
|
-
|
|
4
|
-
function subscribe(onStoreChange: VoidFunction): VoidFunction {
|
|
5
|
-
document.addEventListener('visibilitychange', onStoreChange, {
|
|
6
|
-
passive: true,
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
return () => {
|
|
10
|
-
document.removeEventListener('visibilitychange', onStoreChange);
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function getSnapshot(): DocumentVisibilityState {
|
|
15
|
-
return document.visibilityState;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/* istanbul ignore next -- @preserve */
|
|
19
|
-
function getServerSnapshot(): DocumentVisibilityState {
|
|
20
|
-
return 'visible';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function useVisibilityState(): DocumentVisibilityState {
|
|
24
|
-
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
25
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|