@mado/hooks 0.6.1 → 0.7.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
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @mado/hooks
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`d1145bc`](https://github.com/doinki/mado/commit/d1145bc2f8958602297c64bf1347e9afbbe770eb) Thanks [@doinki](https://github.com/doinki)! - The functions returned by `debounce` and `useDebounce` now have a `void` return type. Calling them schedules the callback for later. If you need the callback's result, consume it inside the callback.
|
|
8
|
+
|
|
9
|
+
`@mado/utils` now exports `Debounced<T>` for a debounced function with a `cancel()` method. For an overloaded callback, `debounce` infers the parameters of its last overload.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`d1145bc`](https://github.com/doinki/mado/commit/d1145bc2f8958602297c64bf1347e9afbbe770eb)]:
|
|
14
|
+
- @mado/utils@0.5.0
|
|
15
|
+
|
|
3
16
|
## 0.6.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-debounce.cjs","sources":["../src/use-debounce.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"use-debounce.cjs","sources":["../src/use-debounce.ts"],"sourcesContent":["import type { Debounced } from '@mado/utils';\nimport { debounce } from '@mado/utils';\nimport { useEffect, useMemo } from 'react';\n\nimport { useEvent } from './use-event';\n\nexport function useDebounce<T extends unknown[], U>(\n fn: (...args: T) => U,\n wait?: number,\n): Debounced<(...args: T) => U> {\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"],"names":["useDebounce","fn","wait","$","_c","callback","useEvent","t0","debounce","debounced","t1","t2","cancel","useEffect"],"mappings":"4KAMO,SAAAA,YAAAC,GAAAC,MAAA,MAAAC,EAAAC,qBAAAA,EAAA,GAIL,MAAAC,SAAiBC,SAAAA,SAASL,IAAI,IAAAM,GAAA,GAAAJ,EAAA,KAAAE,UAAAF,OAAAD,KAAA,CAEEK,GAAAC,MAAAA,SAASH,SAAUH,MAAKC,KAAAE,SAAAF,KAAAD,KAAAC,KAAAI,EAAA,KAAA,CAAAA,GAAAJ,EAAA,EAAA,CAAxD,MAAAM,UAAgCF,GAA4C,IAAAG,GAAA,IAAAC,GAAA,GAAAR,OAAAM,UAAA,CAElEC,GAAAA,IACD,KACLD,UAASG,UAEVD,GAAA,CAACF,WAAUN,KAAAM,UAAAN,KAAAO,GAAAP,KAAAQ,EAAA,KAAA,CAAAD,GAAAP,EAAA,GAAAQ,GAAAR,EAAA,EAAA,CAJdU,MAAAA,UAAUH,GAIPC,IAAY,OAERF,SAAS"}
|
package/dist/use-debounce.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Debounced } from '@mado/utils';
|
|
2
2
|
|
|
3
|
-
declare function useDebounce<T extends
|
|
3
|
+
declare function useDebounce<T extends unknown[], U>(fn: (...args: T) => U, wait?: number): Debounced<(...args: T) => U>;
|
|
4
4
|
|
|
5
5
|
export { useDebounce };
|
package/dist/use-debounce.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Debounced } from '@mado/utils';
|
|
2
2
|
|
|
3
|
-
declare function useDebounce<T extends
|
|
3
|
+
declare function useDebounce<T extends unknown[], U>(fn: (...args: T) => U, wait?: number): Debounced<(...args: T) => U>;
|
|
4
4
|
|
|
5
5
|
export { useDebounce };
|
package/dist/use-debounce.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-debounce.js","sources":["../src/use-debounce.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"use-debounce.js","sources":["../src/use-debounce.ts"],"sourcesContent":["import type { Debounced } from '@mado/utils';\nimport { debounce } from '@mado/utils';\nimport { useEffect, useMemo } from 'react';\n\nimport { useEvent } from './use-event';\n\nexport function useDebounce<T extends unknown[], U>(\n fn: (...args: T) => U,\n wait?: number,\n): Debounced<(...args: T) => U> {\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"],"names":["useDebounce","fn","wait","$","_c","callback","useEvent","t0","debounce","debounced","t1","t2","cancel","useEffect"],"mappings":"0IAMO,SAAAA,YAAAC,GAAAC,MAAA,MAAAC,EAAAC,EAAA,GAIL,MAAAC,SAAiBC,SAASL,IAAI,IAAAM,GAAA,GAAAJ,EAAA,KAAAE,UAAAF,OAAAD,KAAA,CAEEK,GAAAC,SAASH,SAAUH,MAAKC,KAAAE,SAAAF,KAAAD,KAAAC,KAAAI,EAAA,KAAA,CAAAA,GAAAJ,EAAA,EAAA,CAAxD,MAAAM,UAAgCF,GAA4C,IAAAG,GAAA,IAAAC,GAAA,GAAAR,OAAAM,UAAA,CAElEC,GAAAA,IACD,KACLD,UAASG,UAEVD,GAAA,CAACF,WAAUN,KAAAM,UAAAN,KAAAO,GAAAP,KAAAQ,EAAA,KAAA,CAAAD,GAAAP,EAAA,GAAAQ,GAAAR,EAAA,EAAA,CAJdU,UAAUH,GAIPC,IAAY,OAERF,SAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-media-query.cjs","sources":["../src/use-media-query.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"use-media-query.cjs","sources":["../src/use-media-query.ts"],"sourcesContent":["/* oxlint-disable typescript/prefer-optional-chain -- SSR can run without a window binding. */\nimport { useMemo, useSyncExternalStore } from 'react';\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 () => mediaQueryList.matches,\n getDefaultSnapshot,\n ];\n }, [defaultMatches, query]);\n\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n}\n"],"names":["useMediaQuery","query","t0","$","_c","defaultMatches","undefined","t1","bb0","matchMedia","window","t2","getDefaultSnapshot","t3","_temp2","mediaQueryList","t4","t5","onStoreChange","addListener","removeListener","matches","t6","subscribe","getSnapshot","getServerSnapshot","useSyncExternalStore","_temp"],"mappings":"mGAGO,SAAAA,cAAAC,MAAAC,IAAA,MAAAC,EAAAC,qBAAAA,EAAA,IAAsC,MAAAC,eAAAH,KAAAI,UAAA,MAAAJ,GAAsB,IAAAK,GAAAC,IAAA,CAE/D,MAAAC,kBAA0BC,SAAW,aAAeA,OAAMD,WAAY,IAAAE,GAAA,GAAAR,OAAAE,eAAA,CAE3CM,GAAAA,IAClBN,eACRF,KAAAE,eAAAF,KAAAQ,EAAA,KAAA,CAAAA,GAAAR,EAAA,EAAA,CAFD,MAAAS,mBAA2BD,GAI3B,IAAKF,WAAU,CAAA,IAAAI,GAAA,GAAAV,OAAAS,mBAAA,CACNC,IAACC,OAAgBF,mBAAoBA,oBAAmBT,KAAAS,mBAAAT,KAAAU,EAAA,KAAA,CAAAA,GAAAV,EAAA,EAAA,CAA/DI,GAAOM,GAAP,MAAAL,GAAgE,CACjE,IAAAK,GAAA,GAAAV,OAAAF,MAAA,CAEsBY,GAAAJ,WAAWR,OAAME,KAAAF,MAAAE,KAAAU,EAAA,KAAA,CAAAA,GAAAV,EAAA,EAAA,CAAxC,MAAAY,eAAuBF,GAAkB,IAAAG,GAAA,IAAAC,GAAA,GAAAd,OAAAY,eAAA,CAGvCC,GAAAE,gBACEH,eAAcI,YAAaD,eAAc,MAElC,KACLH,eAAcK,eAAgBF,iBAGlCD,GAAAA,IAAMF,eAAcM,QAAQlB,KAAAY,eAAAZ,KAAAa,GAAAb,KAAAc,EAAA,KAAA,CAAAD,GAAAb,EAAA,GAAAc,GAAAd,EAAA,EAAA,CAAA,IAAAmB,GAAA,GAAAnB,EAAA,KAAAS,oBAAAT,QAAAa,IAAAb,EAAA,MAAAc,GAAA,CARvBK,IACLN,GAOAC,GACAL,oBACDT,KAAAS,mBAAAT,MAAAa,GAAAb,MAAAc,GAAAd,MAAAmB,EAAA,KAAA,CAAAA,GAAAnB,EAAA,GAAA,CAVDI,GAAOe,EAUL,CAvBJ,MAAAC,UAAAC,YAAAC,mBAAoDlB,GAwBxB,OAErBmB,2BAAqBH,UAAWC,YAAaC,kBAAkB,CA3BjE,SAAAX,SAAA,OASaa,KAAQ,CATrB,SAAAA,QAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-media-query.js","sources":["../src/use-media-query.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"use-media-query.js","sources":["../src/use-media-query.ts"],"sourcesContent":["/* oxlint-disable typescript/prefer-optional-chain -- SSR can run without a window binding. */\nimport { useMemo, useSyncExternalStore } from 'react';\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 () => mediaQueryList.matches,\n getDefaultSnapshot,\n ];\n }, [defaultMatches, query]);\n\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n}\n"],"names":["useMediaQuery","query","t0","$","_c","defaultMatches","undefined","t1","bb0","matchMedia","window","t2","getDefaultSnapshot","t3","_temp2","mediaQueryList","t4","t5","onStoreChange","addListener","removeListener","matches","t6","subscribe","getSnapshot","getServerSnapshot","useSyncExternalStore","_temp"],"mappings":"8EAGO,SAAAA,cAAAC,MAAAC,IAAA,MAAAC,EAAAC,EAAA,IAAsC,MAAAC,eAAAH,KAAAI,UAAA,MAAAJ,GAAsB,IAAAK,GAAAC,IAAA,CAE/D,MAAAC,kBAA0BC,SAAW,aAAeA,OAAMD,WAAY,IAAAE,GAAA,GAAAR,OAAAE,eAAA,CAE3CM,GAAAA,IAClBN,eACRF,KAAAE,eAAAF,KAAAQ,EAAA,KAAA,CAAAA,GAAAR,EAAA,EAAA,CAFD,MAAAS,mBAA2BD,GAI3B,IAAKF,WAAU,CAAA,IAAAI,GAAA,GAAAV,OAAAS,mBAAA,CACNC,IAACC,OAAgBF,mBAAoBA,oBAAmBT,KAAAS,mBAAAT,KAAAU,EAAA,KAAA,CAAAA,GAAAV,EAAA,EAAA,CAA/DI,GAAOM,GAAP,MAAAL,GAAgE,CACjE,IAAAK,GAAA,GAAAV,OAAAF,MAAA,CAEsBY,GAAAJ,WAAWR,OAAME,KAAAF,MAAAE,KAAAU,EAAA,KAAA,CAAAA,GAAAV,EAAA,EAAA,CAAxC,MAAAY,eAAuBF,GAAkB,IAAAG,GAAA,IAAAC,GAAA,GAAAd,OAAAY,eAAA,CAGvCC,GAAAE,gBACEH,eAAcI,YAAaD,eAAc,MAElC,KACLH,eAAcK,eAAgBF,iBAGlCD,GAAAA,IAAMF,eAAcM,QAAQlB,KAAAY,eAAAZ,KAAAa,GAAAb,KAAAc,EAAA,KAAA,CAAAD,GAAAb,EAAA,GAAAc,GAAAd,EAAA,EAAA,CAAA,IAAAmB,GAAA,GAAAnB,EAAA,KAAAS,oBAAAT,QAAAa,IAAAb,EAAA,MAAAc,GAAA,CARvBK,IACLN,GAOAC,GACAL,oBACDT,KAAAS,mBAAAT,MAAAa,GAAAb,MAAAc,GAAAd,MAAAmB,EAAA,KAAA,CAAAA,GAAAnB,EAAA,GAAA,CAVDI,GAAOe,EAUL,CAvBJ,MAAAC,UAAAC,YAAAC,mBAAoDlB,GAwBxB,OAErBmB,qBAAqBH,UAAWC,YAAaC,kBAAkB,CA3BjE,SAAAX,SAAA,OASaa,KAAQ,CATrB,SAAAA,QAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mado/hooks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "React hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hooks",
|
|
@@ -45,18 +45,17 @@
|
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@babel/runtime": "^7.29.
|
|
49
|
-
"@mado/utils": "^0.
|
|
48
|
+
"@babel/runtime": "^7.29.15",
|
|
49
|
+
"@mado/utils": "^0.5.0",
|
|
50
50
|
"react-compiler-runtime": "^1.0.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@babel/preset-react": "^7.29.7",
|
|
54
|
-
"@rollup/plugin-terser": "^1.0.0",
|
|
55
54
|
"@testing-library/jest-dom": "^7.0.1",
|
|
56
55
|
"@testing-library/react": "^16.3.3",
|
|
57
|
-
"@vitest/coverage-istanbul": "^5.
|
|
56
|
+
"@vitest/coverage-istanbul": "^5.1.1",
|
|
58
57
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
59
|
-
"happy-dom": "^21.0.
|
|
58
|
+
"happy-dom": "^21.0.4",
|
|
60
59
|
"react": "^19.3.1",
|
|
61
60
|
"react-dom": "^19.3.1"
|
|
62
61
|
},
|