@alessiofrittoli/react-hooks 1.1.0 → 2.0.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.
Files changed (102) hide show
  1. package/README.md +387 -73
  2. package/dist/eslint.js +1 -2
  3. package/dist/eslint.mjs +1 -2
  4. package/dist/index.d.mts +940 -11
  5. package/dist/index.d.ts +940 -11
  6. package/dist/index.js +1 -2
  7. package/dist/index.mjs +1 -2
  8. package/package.json +132 -145
  9. package/dist/browser-api/index.d.mts +0 -6
  10. package/dist/browser-api/index.d.ts +0 -6
  11. package/dist/browser-api/index.js +0 -2
  12. package/dist/browser-api/index.js.map +0 -1
  13. package/dist/browser-api/index.mjs +0 -2
  14. package/dist/browser-api/index.mjs.map +0 -1
  15. package/dist/browser-api/storage/index.d.mts +0 -4
  16. package/dist/browser-api/storage/index.d.ts +0 -4
  17. package/dist/browser-api/storage/index.js +0 -2
  18. package/dist/browser-api/storage/index.js.map +0 -1
  19. package/dist/browser-api/storage/index.mjs +0 -2
  20. package/dist/browser-api/storage/index.mjs.map +0 -1
  21. package/dist/browser-api/storage/useLocalStorage.d.mts +0 -11
  22. package/dist/browser-api/storage/useLocalStorage.d.ts +0 -11
  23. package/dist/browser-api/storage/useLocalStorage.js +0 -2
  24. package/dist/browser-api/storage/useLocalStorage.js.map +0 -1
  25. package/dist/browser-api/storage/useLocalStorage.mjs +0 -2
  26. package/dist/browser-api/storage/useLocalStorage.mjs.map +0 -1
  27. package/dist/browser-api/storage/useSessionStorage.d.mts +0 -11
  28. package/dist/browser-api/storage/useSessionStorage.d.ts +0 -11
  29. package/dist/browser-api/storage/useSessionStorage.js +0 -2
  30. package/dist/browser-api/storage/useSessionStorage.js.map +0 -1
  31. package/dist/browser-api/storage/useSessionStorage.mjs +0 -2
  32. package/dist/browser-api/storage/useSessionStorage.mjs.map +0 -1
  33. package/dist/browser-api/storage/useStorage.d.mts +0 -12
  34. package/dist/browser-api/storage/useStorage.d.ts +0 -12
  35. package/dist/browser-api/storage/useStorage.js +0 -2
  36. package/dist/browser-api/storage/useStorage.js.map +0 -1
  37. package/dist/browser-api/storage/useStorage.mjs +0 -2
  38. package/dist/browser-api/storage/useStorage.mjs.map +0 -1
  39. package/dist/browser-api/useIsPortrait.d.mts +0 -10
  40. package/dist/browser-api/useIsPortrait.d.ts +0 -10
  41. package/dist/browser-api/useIsPortrait.js +0 -2
  42. package/dist/browser-api/useIsPortrait.js.map +0 -1
  43. package/dist/browser-api/useIsPortrait.mjs +0 -2
  44. package/dist/browser-api/useIsPortrait.mjs.map +0 -1
  45. package/dist/browser-api/useMediaQuery.d.mts +0 -11
  46. package/dist/browser-api/useMediaQuery.d.ts +0 -11
  47. package/dist/browser-api/useMediaQuery.js +0 -2
  48. package/dist/browser-api/useMediaQuery.js.map +0 -1
  49. package/dist/browser-api/useMediaQuery.mjs +0 -2
  50. package/dist/browser-api/useMediaQuery.mjs.map +0 -1
  51. package/dist/dom-api/index.d.mts +0 -2
  52. package/dist/dom-api/index.d.ts +0 -2
  53. package/dist/dom-api/index.js +0 -2
  54. package/dist/dom-api/index.js.map +0 -1
  55. package/dist/dom-api/index.mjs +0 -2
  56. package/dist/dom-api/index.mjs.map +0 -1
  57. package/dist/dom-api/useFocusTrap.d.mts +0 -15
  58. package/dist/dom-api/useFocusTrap.d.ts +0 -15
  59. package/dist/dom-api/useFocusTrap.js +0 -2
  60. package/dist/dom-api/useFocusTrap.js.map +0 -1
  61. package/dist/dom-api/useFocusTrap.mjs +0 -2
  62. package/dist/dom-api/useFocusTrap.mjs.map +0 -1
  63. package/dist/dom-api/useScrollBlock.d.mts +0 -8
  64. package/dist/dom-api/useScrollBlock.d.ts +0 -8
  65. package/dist/dom-api/useScrollBlock.js +0 -2
  66. package/dist/dom-api/useScrollBlock.js.map +0 -1
  67. package/dist/dom-api/useScrollBlock.mjs +0 -2
  68. package/dist/dom-api/useScrollBlock.mjs.map +0 -1
  69. package/dist/eslint.js.map +0 -1
  70. package/dist/eslint.mjs.map +0 -1
  71. package/dist/index.js.map +0 -1
  72. package/dist/index.mjs.map +0 -1
  73. package/dist/misc/index.d.mts +0 -3
  74. package/dist/misc/index.d.ts +0 -3
  75. package/dist/misc/index.js +0 -2
  76. package/dist/misc/index.js.map +0 -1
  77. package/dist/misc/index.mjs +0 -2
  78. package/dist/misc/index.mjs.map +0 -1
  79. package/dist/misc/useIsClient.d.mts +0 -8
  80. package/dist/misc/useIsClient.d.ts +0 -8
  81. package/dist/misc/useIsClient.js +0 -2
  82. package/dist/misc/useIsClient.js.map +0 -1
  83. package/dist/misc/useIsClient.mjs +0 -2
  84. package/dist/misc/useIsClient.mjs.map +0 -1
  85. package/dist/misc/useIsFirstRender.d.mts +0 -9
  86. package/dist/misc/useIsFirstRender.d.ts +0 -9
  87. package/dist/misc/useIsFirstRender.js +0 -2
  88. package/dist/misc/useIsFirstRender.js.map +0 -1
  89. package/dist/misc/useIsFirstRender.mjs +0 -2
  90. package/dist/misc/useIsFirstRender.mjs.map +0 -1
  91. package/dist/misc/usePagination.d.mts +0 -12
  92. package/dist/misc/usePagination.d.ts +0 -12
  93. package/dist/misc/usePagination.js +0 -2
  94. package/dist/misc/usePagination.js.map +0 -1
  95. package/dist/misc/usePagination.mjs +0 -2
  96. package/dist/misc/usePagination.mjs.map +0 -1
  97. package/dist/misc/useUpdateEffect.d.mts +0 -9
  98. package/dist/misc/useUpdateEffect.d.ts +0 -9
  99. package/dist/misc/useUpdateEffect.js +0 -2
  100. package/dist/misc/useUpdateEffect.js.map +0 -1
  101. package/dist/misc/useUpdateEffect.mjs +0 -2
  102. package/dist/misc/useUpdateEffect.mjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/browser-api/storage/useStorage.ts","../../../src/browser-api/storage/useSessionStorage.ts"],"names":["useStorage","key","initialValue","type","readValue","useCallback","LocalStorage","SessionStorage","storedValue","setStoredValue","useState","setValue","value","valueToStore","useEffect","useSessionStorage"],"mappings":"6MAcO,IAAMA,CAAAA,CAAa,CACzBC,CAAAA,CACAC,EACAC,CAA+B,CAAA,OAAA,GACO,CAEtC,IAAMC,CAAYC,CAAAA,WAAAA,CAAa,KAC5BF,CAAS,GAAA,OAAA,CAAUG,YAAeC,CAAAA,cAAAA,EAClC,GAAQN,CAAAA,CAAI,GAAKC,CACjB,CAAA,CAAEC,CAAMF,CAAAA,CAAAA,CAAKC,CAAa,CAAE,EAQzB,CAAEM,CAAAA,CAAaC,CAAe,CAAA,CAAIC,QAAoBR,CAAAA,CAAa,CAQnES,CAAAA,CAAAA,CAAWN,WAAiCO,CAAAA,CAAAA,EAAS,CAE1DH,CAAAA,CAAgBD,CAAe,EAAA,CAC9B,IAAMK,CAAeD,CAAAA,CAAAA,YAAiB,QAAWA,CAAAA,CAAAA,CAAOJ,CAAY,CAAA,CAAII,EAEvE,OACA,CAAA,OAAO,MAAW,CAAA,GAAA,EAClBT,CAAS,GAAA,OAAA,CAAUG,aAAeC,cACjC,EAAA,GAAA,CAAKN,CAAKY,CAAAA,CAAa,CAElBA,CAAAA,CACR,CAAE,EAGH,CAAA,CAAG,CAAEV,CAAAA,CAAMF,CAAI,CAAE,EAEjB,OAAAa,SAAAA,CAAW,IAAM,CAChBL,CAAgBL,CAAAA,CAAAA,EAAY,EAC7B,CAAA,CAAG,CAAEA,CAAU,CAAE,CAAA,CAEV,CAAEI,CAAaG,CAAAA,CAAS,CAChC,CAAA,CCpDaI,IAAAA,CAAAA,CAAoB,CAChCd,CAAAA,CACAC,CACIF,GAAAA,CAAAA,CAAYC,CAAKC,CAAAA,CAAAA,CAAc,SAAU","file":"useSessionStorage.mjs","sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { LocalStorage } from '@alessiofrittoli/web-utils/storage/LocalStorage'\nimport { SessionStorage } from '@alessiofrittoli/web-utils/storage/SessionStorage'\n\ntype Value<T>\t\t= T | undefined | null\ntype SetValue<T>\t= React.Dispatch<React.SetStateAction<T>>\n\n/**\n * Easly handle Local or Session Storage State.\n * \n * @param\tkey\t\t\t\tThe storage item key.\n * @param\tinitialValue\tThe storage item initial value.\n * @param\ttype\t\t\t( Optional ) The storage API to use. Default: `local`.\n */\nexport const useStorage = <T = string>(\n\tkey\t\t\t\t: string,\n\tinitialValue?\t: T,\n\ttype\t\t\t: 'local' | 'session' = 'local'\n): [ Value<T>, SetValue<Value<T>> ] => {\n\n\tconst readValue = useCallback( () => (\n\t\t( type === 'local' ? LocalStorage : SessionStorage )\n\t\t\t.get<T>( key ) ?? initialValue\n\t), [ type, key, initialValue ] )\n\n\n\t/**\n\t * State to store our value.\n\t * Pass initial state function to useState so logic is only executed once.\n\t * \n\t */\n\tconst [ storedValue, setStoredValue ] = useState<Value<T>>( initialValue )\n\n\t/**\n\t * Return a wrapped version of useState's setter function that\n\t * persists the new value to localStorage | sessionStorage.\n\t * \n\t * @param value The SetStateAction value.\n\t */\n\tconst setValue = useCallback<SetValue<Value<T>>>( value => {\n\n\t\tsetStoredValue( storedValue => {\n\t\t\tconst valueToStore = value instanceof Function ? value( storedValue ) : value\n\t\n\t\t\t;(\n\t\t\t\ttypeof window !== 'undefined' &&\n\t\t\t\ttype === 'local' ? LocalStorage : SessionStorage\n\t\t\t).set( key, valueToStore )\n\n\t\t\treturn valueToStore\n\t\t} )\n\n\n\t}, [ type, key ] )\n\n\tuseEffect( () => {\n\t\tsetStoredValue( readValue() )\n\t}, [ readValue ] )\n\n\treturn [ storedValue, setValue ]\n}","import { useStorage } from './useStorage'\n\n/**\n * useSessionStorage hook.\n * \n * @param\tkey\t\t\t\tThe session item key.\n * @param\tinitialValue\tThe session item initial value.\n */\nexport const useSessionStorage = <T = string>(\n\tkey\t\t\t\t: string,\n\tinitialValue?\t: T\n) => useStorage( key, initialValue, 'session' )"]}
@@ -1,12 +0,0 @@
1
- type Value<T> = T | undefined | null;
2
- type SetValue<T> = React.Dispatch<React.SetStateAction<T>>;
3
- /**
4
- * Easly handle Local or Session Storage State.
5
- *
6
- * @param key The storage item key.
7
- * @param initialValue The storage item initial value.
8
- * @param type ( Optional ) The storage API to use. Default: `local`.
9
- */
10
- declare const useStorage: <T = string>(key: string, initialValue?: T, type?: "local" | "session") => [Value<T>, SetValue<Value<T>>];
11
-
12
- export { useStorage };
@@ -1,12 +0,0 @@
1
- type Value<T> = T | undefined | null;
2
- type SetValue<T> = React.Dispatch<React.SetStateAction<T>>;
3
- /**
4
- * Easly handle Local or Session Storage State.
5
- *
6
- * @param key The storage item key.
7
- * @param initialValue The storage item initial value.
8
- * @param type ( Optional ) The storage API to use. Default: `local`.
9
- */
10
- declare const useStorage: <T = string>(key: string, initialValue?: T, type?: "local" | "session") => [Value<T>, SetValue<Value<T>>];
11
-
12
- export { useStorage };
@@ -1,2 +0,0 @@
1
- 'use strict';var react=require('react'),LocalStorage=require('@alessiofrittoli/web-utils/storage/LocalStorage'),SessionStorage=require('@alessiofrittoli/web-utils/storage/SessionStorage');var w=(e,o,t="local")=>{let s=react.useCallback(()=>(t==="local"?LocalStorage.LocalStorage:SessionStorage.SessionStorage).get(e)??o,[t,e,o]),[S,l]=react.useState(o),T=react.useCallback(a=>{l(V=>{let n=a instanceof Function?a(V):a;return (typeof window<"u"&&t==="local"?LocalStorage.LocalStorage:SessionStorage.SessionStorage).set(e,n),n});},[t,e]);return react.useEffect(()=>{l(s());},[s]),[S,T]};exports.useStorage=w;//# sourceMappingURL=useStorage.js.map
2
- //# sourceMappingURL=useStorage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/browser-api/storage/useStorage.ts"],"names":["useStorage","key","initialValue","type","readValue","useCallback","LocalStorage","SessionStorage","storedValue","setStoredValue","useState","setValue","value","valueToStore","useEffect"],"mappings":"4LAcaA,IAAAA,CAAAA,CAAa,CACzBC,CACAC,CAAAA,CAAAA,CACAC,CAA+B,CAAA,OAAA,GACO,CAEtC,IAAMC,EAAYC,iBAAa,CAAA,IAAA,CAC5BF,IAAS,OAAUG,CAAAA,yBAAAA,CAAeC,+BAClC,GAAQN,CAAAA,CAAI,CAAKC,EAAAA,CAAAA,CACjB,CAAEC,CAAAA,CAAMF,EAAKC,CAAa,CAAE,EAQzB,CAAEM,CAAAA,CAAaC,CAAe,CAAIC,CAAAA,cAAAA,CAAoBR,CAAa,CAAA,CAQnES,CAAWN,CAAAA,iBAAAA,CAAiCO,GAAS,CAE1DH,CAAAA,CAAgBD,GAAe,CAC9B,IAAMK,EAAeD,CAAiB,YAAA,QAAA,CAAWA,CAAOJ,CAAAA,CAAY,CAAII,CAAAA,CAAAA,CAEvE,QACA,OAAO,MAAA,CAAW,KAClBT,CAAS,GAAA,OAAA,CAAUG,0BAAeC,6BACjC,EAAA,GAAA,CAAKN,CAAKY,CAAAA,CAAa,CAElBA,CAAAA,CACR,CAAE,EAGH,CAAA,CAAG,CAAEV,CAAMF,CAAAA,CAAI,CAAE,CAEjB,CAAA,OAAAa,eAAW,CAAA,IAAM,CAChBL,CAAAA,CAAgBL,GAAY,EAC7B,EAAG,CAAEA,CAAU,CAAE,CAEV,CAAA,CAAEI,CAAaG,CAAAA,CAAS,CAChC","file":"useStorage.js","sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { LocalStorage } from '@alessiofrittoli/web-utils/storage/LocalStorage'\nimport { SessionStorage } from '@alessiofrittoli/web-utils/storage/SessionStorage'\n\ntype Value<T>\t\t= T | undefined | null\ntype SetValue<T>\t= React.Dispatch<React.SetStateAction<T>>\n\n/**\n * Easly handle Local or Session Storage State.\n * \n * @param\tkey\t\t\t\tThe storage item key.\n * @param\tinitialValue\tThe storage item initial value.\n * @param\ttype\t\t\t( Optional ) The storage API to use. Default: `local`.\n */\nexport const useStorage = <T = string>(\n\tkey\t\t\t\t: string,\n\tinitialValue?\t: T,\n\ttype\t\t\t: 'local' | 'session' = 'local'\n): [ Value<T>, SetValue<Value<T>> ] => {\n\n\tconst readValue = useCallback( () => (\n\t\t( type === 'local' ? LocalStorage : SessionStorage )\n\t\t\t.get<T>( key ) ?? initialValue\n\t), [ type, key, initialValue ] )\n\n\n\t/**\n\t * State to store our value.\n\t * Pass initial state function to useState so logic is only executed once.\n\t * \n\t */\n\tconst [ storedValue, setStoredValue ] = useState<Value<T>>( initialValue )\n\n\t/**\n\t * Return a wrapped version of useState's setter function that\n\t * persists the new value to localStorage | sessionStorage.\n\t * \n\t * @param value The SetStateAction value.\n\t */\n\tconst setValue = useCallback<SetValue<Value<T>>>( value => {\n\n\t\tsetStoredValue( storedValue => {\n\t\t\tconst valueToStore = value instanceof Function ? value( storedValue ) : value\n\t\n\t\t\t;(\n\t\t\t\ttypeof window !== 'undefined' &&\n\t\t\t\ttype === 'local' ? LocalStorage : SessionStorage\n\t\t\t).set( key, valueToStore )\n\n\t\t\treturn valueToStore\n\t\t} )\n\n\n\t}, [ type, key ] )\n\n\tuseEffect( () => {\n\t\tsetStoredValue( readValue() )\n\t}, [ readValue ] )\n\n\treturn [ storedValue, setValue ]\n}"]}
@@ -1,2 +0,0 @@
1
- import {useCallback,useState,useEffect}from'react';import {LocalStorage}from'@alessiofrittoli/web-utils/storage/LocalStorage';import {SessionStorage}from'@alessiofrittoli/web-utils/storage/SessionStorage';var R=(e,o,t="local")=>{let s=useCallback(()=>(t==="local"?LocalStorage:SessionStorage).get(e)??o,[t,e,o]),[S,l]=useState(o),T=useCallback(a=>{l(V=>{let n=a instanceof Function?a(V):a;return (typeof window<"u"&&t==="local"?LocalStorage:SessionStorage).set(e,n),n});},[t,e]);return useEffect(()=>{l(s());},[s]),[S,T]};export{R as useStorage};//# sourceMappingURL=useStorage.mjs.map
2
- //# sourceMappingURL=useStorage.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/browser-api/storage/useStorage.ts"],"names":["useStorage","key","initialValue","type","readValue","useCallback","LocalStorage","SessionStorage","storedValue","setStoredValue","useState","setValue","value","valueToStore","useEffect"],"mappings":"6MAcaA,IAAAA,CAAAA,CAAa,CACzBC,CACAC,CAAAA,CAAAA,CACAC,CAA+B,CAAA,OAAA,GACO,CAEtC,IAAMC,EAAYC,WAAa,CAAA,IAAA,CAC5BF,IAAS,OAAUG,CAAAA,YAAAA,CAAeC,gBAClC,GAAQN,CAAAA,CAAI,CAAKC,EAAAA,CAAAA,CACjB,CAAEC,CAAAA,CAAMF,EAAKC,CAAa,CAAE,EAQzB,CAAEM,CAAAA,CAAaC,CAAe,CAAIC,CAAAA,QAAAA,CAAoBR,CAAa,CAAA,CAQnES,CAAWN,CAAAA,WAAAA,CAAiCO,GAAS,CAE1DH,CAAAA,CAAgBD,GAAe,CAC9B,IAAMK,EAAeD,CAAiB,YAAA,QAAA,CAAWA,CAAOJ,CAAAA,CAAY,CAAII,CAAAA,CAAAA,CAEvE,QACA,OAAO,MAAA,CAAW,KAClBT,CAAS,GAAA,OAAA,CAAUG,aAAeC,cACjC,EAAA,GAAA,CAAKN,CAAKY,CAAAA,CAAa,CAElBA,CAAAA,CACR,CAAE,EAGH,CAAA,CAAG,CAAEV,CAAMF,CAAAA,CAAI,CAAE,CAEjB,CAAA,OAAAa,SAAW,CAAA,IAAM,CAChBL,CAAAA,CAAgBL,GAAY,EAC7B,EAAG,CAAEA,CAAU,CAAE,CAEV,CAAA,CAAEI,CAAaG,CAAAA,CAAS,CAChC","file":"useStorage.mjs","sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { LocalStorage } from '@alessiofrittoli/web-utils/storage/LocalStorage'\nimport { SessionStorage } from '@alessiofrittoli/web-utils/storage/SessionStorage'\n\ntype Value<T>\t\t= T | undefined | null\ntype SetValue<T>\t= React.Dispatch<React.SetStateAction<T>>\n\n/**\n * Easly handle Local or Session Storage State.\n * \n * @param\tkey\t\t\t\tThe storage item key.\n * @param\tinitialValue\tThe storage item initial value.\n * @param\ttype\t\t\t( Optional ) The storage API to use. Default: `local`.\n */\nexport const useStorage = <T = string>(\n\tkey\t\t\t\t: string,\n\tinitialValue?\t: T,\n\ttype\t\t\t: 'local' | 'session' = 'local'\n): [ Value<T>, SetValue<Value<T>> ] => {\n\n\tconst readValue = useCallback( () => (\n\t\t( type === 'local' ? LocalStorage : SessionStorage )\n\t\t\t.get<T>( key ) ?? initialValue\n\t), [ type, key, initialValue ] )\n\n\n\t/**\n\t * State to store our value.\n\t * Pass initial state function to useState so logic is only executed once.\n\t * \n\t */\n\tconst [ storedValue, setStoredValue ] = useState<Value<T>>( initialValue )\n\n\t/**\n\t * Return a wrapped version of useState's setter function that\n\t * persists the new value to localStorage | sessionStorage.\n\t * \n\t * @param value The SetStateAction value.\n\t */\n\tconst setValue = useCallback<SetValue<Value<T>>>( value => {\n\n\t\tsetStoredValue( storedValue => {\n\t\t\tconst valueToStore = value instanceof Function ? value( storedValue ) : value\n\t\n\t\t\t;(\n\t\t\t\ttypeof window !== 'undefined' &&\n\t\t\t\ttype === 'local' ? LocalStorage : SessionStorage\n\t\t\t).set( key, valueToStore )\n\n\t\t\treturn valueToStore\n\t\t} )\n\n\n\t}, [ type, key ] )\n\n\tuseEffect( () => {\n\t\tsetStoredValue( readValue() )\n\t}, [ readValue ] )\n\n\treturn [ storedValue, setValue ]\n}"]}
@@ -1,10 +0,0 @@
1
- /**
2
- * Check if device is portrait oriented.
3
- *
4
- * State get updated when device orientation changes.
5
- *
6
- * @returns `true` if the device is portrait oriented, `false` otherwise.
7
- */
8
- declare const useIsPortrait: () => boolean;
9
-
10
- export { useIsPortrait };
@@ -1,10 +0,0 @@
1
- /**
2
- * Check if device is portrait oriented.
3
- *
4
- * State get updated when device orientation changes.
5
- *
6
- * @returns `true` if the device is portrait oriented, `false` otherwise.
7
- */
8
- declare const useIsPortrait: () => boolean;
9
-
10
- export { useIsPortrait };
@@ -1,2 +0,0 @@
1
- 'use strict';var react=require('react'),browserApi=require('@alessiofrittoli/web-utils/browser-api'),device=require('@alessiofrittoli/web-utils/device');var o=e=>{let[s,i]=react.useState(browserApi.getMediaMatches(e)),t=react.useCallback(()=>i(browserApi.getMediaMatches(e)),[e]);return react.useEffect(()=>{let a=window.matchMedia(e);return t(),a.addEventListener("change",t),()=>{a.removeEventListener("change",t);}},[e,t]),s};var v=()=>o(device.portraitMediaQuery);exports.useIsPortrait=v;//# sourceMappingURL=useIsPortrait.js.map
2
- //# sourceMappingURL=useIsPortrait.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/browser-api/useMediaQuery.ts","../../src/browser-api/useIsPortrait.ts"],"names":["useMediaQuery","query","matches","setMatches","useState","getMediaMatches","matchMediaChangeHandler","useCallback","useEffect","matchMedia","useIsPortrait","portraitMediaQuery"],"mappings":"yJAYO,IAAMA,CAAAA,CAAkBC,CAAmB,EAAA,CAEjD,GAAM,CAAEC,CAAAA,CAASC,CAAW,CAAA,CAAIC,eAAUC,0BAAiBJ,CAAAA,CAAM,CAAE,CAAA,CAC7DK,EAA0BC,iBAAa,CAAA,IAAMJ,CAAYE,CAAAA,0BAAAA,CAAiBJ,CAAM,CAAE,CAAA,CAAG,CAAEA,CAAM,CAAE,EAGrG,OAAAO,eAAAA,CAAW,IAAM,CAEhB,IAAMC,CAAa,CAAA,MAAA,CAAO,UAAYR,CAAAA,CAAM,EAE5C,OAAAK,CAAAA,EAEAG,CAAAA,CAAAA,CAAW,iBAAkB,QAAUH,CAAAA,CAAwB,EAExD,IAAM,CACZG,EAAW,mBAAqB,CAAA,QAAA,CAAUH,CAAwB,EACnE,CAED,CAAG,CAAA,CAAEL,CAAOK,CAAAA,CAAwB,CAAE,CAE/BJ,CAAAA,CAER,CCjCA,KASaQ,CAAgB,CAAA,IAAMV,EAAeW,yBAAmB","file":"useIsPortrait.js","sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { getMediaMatches } from '@alessiofrittoli/web-utils/browser-api'\n\n\n/**\n * Get Document Media matches and listen for changes.\n *\n * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia)\n *\n * @param\tquery A string specifying the media query to parse into a `MediaQueryList`.\n * @returns\tA boolean value that returns `true` if the document currently matches the media query list, or `false` if not.\n */\nexport const useMediaQuery = ( query: string ) => {\n\n\tconst [ matches, setMatches ]\t= useState( getMediaMatches( query ) )\n\tconst matchMediaChangeHandler\t= useCallback( () => setMatches( getMediaMatches( query ) ), [ query ] )\n\n\n\tuseEffect( () => {\n\n\t\tconst matchMedia = window.matchMedia( query )\n\t\t// Triggered at the first client-side load\n\t\tmatchMediaChangeHandler()\n\t\t// Listen matchMedia\n\t\tmatchMedia.addEventListener( 'change', matchMediaChangeHandler )\n\n\t\treturn () => {\n\t\t\tmatchMedia.removeEventListener( 'change', matchMediaChangeHandler )\n\t\t}\n\n\t}, [ query, matchMediaChangeHandler ] )\n\n\treturn matches\n\t\n}","import { useMediaQuery } from './useMediaQuery'\nimport { portraitMediaQuery } from '@alessiofrittoli/web-utils/device'\n\n/**\n * Check if device is portrait oriented.\n * \n * State get updated when device orientation changes.\n *\n * @returns\t`true` if the device is portrait oriented, `false` otherwise.\n */\nexport const useIsPortrait = () => useMediaQuery( portraitMediaQuery )"]}
@@ -1,2 +0,0 @@
1
- import {useState,useCallback,useEffect}from'react';import {getMediaMatches}from'@alessiofrittoli/web-utils/browser-api';import {portraitMediaQuery}from'@alessiofrittoli/web-utils/device';var o=e=>{let[s,i]=useState(getMediaMatches(e)),t=useCallback(()=>i(getMediaMatches(e)),[e]);return useEffect(()=>{let a=window.matchMedia(e);return t(),a.addEventListener("change",t),()=>{a.removeEventListener("change",t);}},[e,t]),s};var E=()=>o(portraitMediaQuery);export{E as useIsPortrait};//# sourceMappingURL=useIsPortrait.mjs.map
2
- //# sourceMappingURL=useIsPortrait.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/browser-api/useMediaQuery.ts","../../src/browser-api/useIsPortrait.ts"],"names":["useMediaQuery","query","matches","setMatches","useState","getMediaMatches","matchMediaChangeHandler","useCallback","useEffect","matchMedia","useIsPortrait","portraitMediaQuery"],"mappings":"2LAYO,IAAMA,CAAAA,CAAkBC,CAAmB,EAAA,CAEjD,GAAM,CAAEC,CAAAA,CAASC,CAAW,CAAA,CAAIC,SAAUC,eAAiBJ,CAAAA,CAAM,CAAE,CAAA,CAC7DK,EAA0BC,WAAa,CAAA,IAAMJ,CAAYE,CAAAA,eAAAA,CAAiBJ,CAAM,CAAE,CAAA,CAAG,CAAEA,CAAM,CAAE,EAGrG,OAAAO,SAAAA,CAAW,IAAM,CAEhB,IAAMC,CAAa,CAAA,MAAA,CAAO,UAAYR,CAAAA,CAAM,EAE5C,OAAAK,CAAAA,EAEAG,CAAAA,CAAAA,CAAW,iBAAkB,QAAUH,CAAAA,CAAwB,EAExD,IAAM,CACZG,EAAW,mBAAqB,CAAA,QAAA,CAAUH,CAAwB,EACnE,CAED,CAAG,CAAA,CAAEL,CAAOK,CAAAA,CAAwB,CAAE,CAE/BJ,CAAAA,CAER,CCjCA,KASaQ,CAAgB,CAAA,IAAMV,EAAeW,kBAAmB","file":"useIsPortrait.mjs","sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { getMediaMatches } from '@alessiofrittoli/web-utils/browser-api'\n\n\n/**\n * Get Document Media matches and listen for changes.\n *\n * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia)\n *\n * @param\tquery A string specifying the media query to parse into a `MediaQueryList`.\n * @returns\tA boolean value that returns `true` if the document currently matches the media query list, or `false` if not.\n */\nexport const useMediaQuery = ( query: string ) => {\n\n\tconst [ matches, setMatches ]\t= useState( getMediaMatches( query ) )\n\tconst matchMediaChangeHandler\t= useCallback( () => setMatches( getMediaMatches( query ) ), [ query ] )\n\n\n\tuseEffect( () => {\n\n\t\tconst matchMedia = window.matchMedia( query )\n\t\t// Triggered at the first client-side load\n\t\tmatchMediaChangeHandler()\n\t\t// Listen matchMedia\n\t\tmatchMedia.addEventListener( 'change', matchMediaChangeHandler )\n\n\t\treturn () => {\n\t\t\tmatchMedia.removeEventListener( 'change', matchMediaChangeHandler )\n\t\t}\n\n\t}, [ query, matchMediaChangeHandler ] )\n\n\treturn matches\n\t\n}","import { useMediaQuery } from './useMediaQuery'\nimport { portraitMediaQuery } from '@alessiofrittoli/web-utils/device'\n\n/**\n * Check if device is portrait oriented.\n * \n * State get updated when device orientation changes.\n *\n * @returns\t`true` if the device is portrait oriented, `false` otherwise.\n */\nexport const useIsPortrait = () => useMediaQuery( portraitMediaQuery )"]}
@@ -1,11 +0,0 @@
1
- /**
2
- * Get Document Media matches and listen for changes.
3
- *
4
- * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia)
5
- *
6
- * @param query A string specifying the media query to parse into a `MediaQueryList`.
7
- * @returns A boolean value that returns `true` if the document currently matches the media query list, or `false` if not.
8
- */
9
- declare const useMediaQuery: (query: string) => boolean;
10
-
11
- export { useMediaQuery };
@@ -1,11 +0,0 @@
1
- /**
2
- * Get Document Media matches and listen for changes.
3
- *
4
- * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia)
5
- *
6
- * @param query A string specifying the media query to parse into a `MediaQueryList`.
7
- * @returns A boolean value that returns `true` if the document currently matches the media query list, or `false` if not.
8
- */
9
- declare const useMediaQuery: (query: string) => boolean;
10
-
11
- export { useMediaQuery };
@@ -1,2 +0,0 @@
1
- 'use strict';var react=require('react'),browserApi=require('@alessiofrittoli/web-utils/browser-api');var M=e=>{let[s,c]=react.useState(browserApi.getMediaMatches(e)),t=react.useCallback(()=>c(browserApi.getMediaMatches(e)),[e]);return react.useEffect(()=>{let a=window.matchMedia(e);return t(),a.addEventListener("change",t),()=>{a.removeEventListener("change",t);}},[e,t]),s};exports.useMediaQuery=M;//# sourceMappingURL=useMediaQuery.js.map
2
- //# sourceMappingURL=useMediaQuery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/browser-api/useMediaQuery.ts"],"names":["useMediaQuery","query","matches","setMatches","useState","getMediaMatches","matchMediaChangeHandler","useCallback","useEffect","matchMedia"],"mappings":"qGAYaA,IAAAA,CAAAA,CAAkBC,GAAmB,CAEjD,GAAM,CAAEC,CAAAA,CAASC,CAAW,CAAA,CAAIC,cAAUC,CAAAA,0BAAAA,CAAiBJ,CAAM,CAAE,CAAA,CAC7DK,CAA0BC,CAAAA,iBAAAA,CAAa,IAAMJ,CAAAA,CAAYE,0BAAiBJ,CAAAA,CAAM,CAAE,CAAG,CAAA,CAAEA,CAAM,CAAE,CAGrG,CAAA,OAAAO,eAAW,CAAA,IAAM,CAEhB,IAAMC,CAAAA,CAAa,MAAO,CAAA,UAAA,CAAYR,CAAM,CAAA,CAE5C,OAAAK,CAAAA,GAEAG,CAAW,CAAA,gBAAA,CAAkB,QAAUH,CAAAA,CAAwB,CAExD,CAAA,IAAM,CACZG,CAAAA,CAAW,oBAAqB,QAAUH,CAAAA,CAAwB,EACnE,CAED,EAAG,CAAEL,CAAAA,CAAOK,CAAwB,CAAE,EAE/BJ,CAER","file":"useMediaQuery.js","sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { getMediaMatches } from '@alessiofrittoli/web-utils/browser-api'\n\n\n/**\n * Get Document Media matches and listen for changes.\n *\n * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia)\n *\n * @param\tquery A string specifying the media query to parse into a `MediaQueryList`.\n * @returns\tA boolean value that returns `true` if the document currently matches the media query list, or `false` if not.\n */\nexport const useMediaQuery = ( query: string ) => {\n\n\tconst [ matches, setMatches ]\t= useState( getMediaMatches( query ) )\n\tconst matchMediaChangeHandler\t= useCallback( () => setMatches( getMediaMatches( query ) ), [ query ] )\n\n\n\tuseEffect( () => {\n\n\t\tconst matchMedia = window.matchMedia( query )\n\t\t// Triggered at the first client-side load\n\t\tmatchMediaChangeHandler()\n\t\t// Listen matchMedia\n\t\tmatchMedia.addEventListener( 'change', matchMediaChangeHandler )\n\n\t\treturn () => {\n\t\t\tmatchMedia.removeEventListener( 'change', matchMediaChangeHandler )\n\t\t}\n\n\t}, [ query, matchMediaChangeHandler ] )\n\n\treturn matches\n\t\n}"]}
@@ -1,2 +0,0 @@
1
- import {useState,useCallback,useEffect}from'react';import {getMediaMatches}from'@alessiofrittoli/web-utils/browser-api';var g=e=>{let[s,c]=useState(getMediaMatches(e)),t=useCallback(()=>c(getMediaMatches(e)),[e]);return useEffect(()=>{let a=window.matchMedia(e);return t(),a.addEventListener("change",t),()=>{a.removeEventListener("change",t);}},[e,t]),s};export{g as useMediaQuery};//# sourceMappingURL=useMediaQuery.mjs.map
2
- //# sourceMappingURL=useMediaQuery.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/browser-api/useMediaQuery.ts"],"names":["useMediaQuery","query","matches","setMatches","useState","getMediaMatches","matchMediaChangeHandler","useCallback","useEffect","matchMedia"],"mappings":"wHAYaA,IAAAA,CAAAA,CAAkBC,GAAmB,CAEjD,GAAM,CAAEC,CAAAA,CAASC,CAAW,CAAA,CAAIC,QAAUC,CAAAA,eAAAA,CAAiBJ,CAAM,CAAE,CAAA,CAC7DK,CAA0BC,CAAAA,WAAAA,CAAa,IAAMJ,CAAAA,CAAYE,eAAiBJ,CAAAA,CAAM,CAAE,CAAG,CAAA,CAAEA,CAAM,CAAE,CAGrG,CAAA,OAAAO,SAAW,CAAA,IAAM,CAEhB,IAAMC,CAAAA,CAAa,MAAO,CAAA,UAAA,CAAYR,CAAM,CAAA,CAE5C,OAAAK,CAAAA,GAEAG,CAAW,CAAA,gBAAA,CAAkB,QAAUH,CAAAA,CAAwB,CAExD,CAAA,IAAM,CACZG,CAAAA,CAAW,oBAAqB,QAAUH,CAAAA,CAAwB,EACnE,CAED,EAAG,CAAEL,CAAAA,CAAOK,CAAwB,CAAE,EAE/BJ,CAER","file":"useMediaQuery.mjs","sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { getMediaMatches } from '@alessiofrittoli/web-utils/browser-api'\n\n\n/**\n * Get Document Media matches and listen for changes.\n *\n * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia)\n *\n * @param\tquery A string specifying the media query to parse into a `MediaQueryList`.\n * @returns\tA boolean value that returns `true` if the document currently matches the media query list, or `false` if not.\n */\nexport const useMediaQuery = ( query: string ) => {\n\n\tconst [ matches, setMatches ]\t= useState( getMediaMatches( query ) )\n\tconst matchMediaChangeHandler\t= useCallback( () => setMatches( getMediaMatches( query ) ), [ query ] )\n\n\n\tuseEffect( () => {\n\n\t\tconst matchMedia = window.matchMedia( query )\n\t\t// Triggered at the first client-side load\n\t\tmatchMediaChangeHandler()\n\t\t// Listen matchMedia\n\t\tmatchMedia.addEventListener( 'change', matchMediaChangeHandler )\n\n\t\treturn () => {\n\t\t\tmatchMedia.removeEventListener( 'change', matchMediaChangeHandler )\n\t\t}\n\n\t}, [ query, matchMediaChangeHandler ] )\n\n\treturn matches\n\t\n}"]}
@@ -1,2 +0,0 @@
1
- export { useFocusTrap } from './useFocusTrap.mjs';
2
- export { useScrollBlock } from './useScrollBlock.mjs';
@@ -1,2 +0,0 @@
1
- export { useFocusTrap } from './useFocusTrap.js';
2
- export { useScrollBlock } from './useScrollBlock.js';
@@ -1,2 +0,0 @@
1
- 'use strict';var react=require('react'),dom=require('@alessiofrittoli/web-utils/dom');var b=["input","select","textarea","button","[href]",'[tabindex]:not([tabindex="-1"])'].join(", "),k=e=>{let[r,o]=react.useState(false),c=react.useRef(null),i=react.useCallback(n=>{c.current=document.activeElement;let t=n||e?.current||false;if(t)return o(t)},[e]),p=react.useCallback(()=>{c.current?.focus(),o(false);},[]);return react.useEffect(()=>{if(!r)return;let n=t=>{if(t.key!=="Tab")return;let s=Array.from(r.querySelectorAll(b)),l=s.at(0),u=s.at(-1);if(!t.shiftKey){document.activeElement===u&&(t.preventDefault(),l?.focus());return}document.activeElement===l&&(t.preventDefault(),u?.focus());};return document.addEventListener("keydown",n),()=>{document.removeEventListener("keydown",n);}},[r]),[i,p]};var x=e=>{let r=react.useCallback(()=>dom.blockScroll(e?.current||void 0),[e]),o=react.useCallback(()=>dom.restoreScroll(e?.current||void 0),[e]);return [r,o]};exports.useFocusTrap=k;exports.useScrollBlock=x;//# sourceMappingURL=index.js.map
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/dom-api/useFocusTrap.ts","../../src/dom-api/useScrollBlock.ts"],"names":["focusableSelector","useFocusTrap","target","focusTrap","setFocusTrapDispatch","useState","lastActiveElement","useRef","setFocusTrap","useCallback","onDemandTarget","restoreFocusTrap","useEffect","keyDownHandler","event","focusableElements","firstFocusableElement","lastFocusableElement","useScrollBlock","blockScroll","blockScrollHandler","restoreScroll","restoreScrollHandler"],"mappings":"sFAKMA,IAAAA,CAAAA,CAAoB,CACzB,OAAS,CAAA,QAAA,CAAU,WACnB,QAAU,CAAA,QAAA,CAAU,iCACrB,CAAE,CAAA,IAAA,CAAM,IAAK,CAAA,CAaAC,CACZC,CAAAA,CAAAA,EACiD,CAEjD,GAAM,CAAEC,EAAWC,CAAqB,CAAA,CACvCC,eAA+B,KAAM,CAAA,CAGhCC,CAAoBC,CAAAA,YAAAA,CAAqB,IAAK,CAAA,CAM9CC,EAAeC,iBAA2BC,CAAAA,CAAAA,EAAkB,CAEjEJ,CAAkB,CAAA,OAAA,CAAU,SAAS,aACrC,CAAA,IAAMH,CAAeO,CAAAA,CAAAA,EAAkBR,CAAQ,EAAA,OAAA,EAAW,MAE1D,GAAOC,CAAAA,CAEP,OAAOC,CAAsBD,CAAAA,CAAU,CAExC,CAAG,CAAA,CAAED,CAAO,CAAE,CAMRS,CAAAA,CAAAA,CAAmBF,kBAA+B,IAAM,CAE7DH,EAAkB,OAAS,EAAA,KAAA,GAC3BF,CAAsB,CAAA,KAAM,EAE7B,CAAA,CAAG,EAAG,EAGN,OAAAQ,eAAAA,CAAW,IAAM,CAEhB,GAAK,CAAET,CAAY,CAAA,OAEnB,IAAMU,CAAAA,CAAmBC,CAA0B,EAAA,CAElD,GAAKA,CAAM,CAAA,GAAA,GAAQ,MAAQ,OAE3B,IAAMC,EAAqB,KAAM,CAAA,IAAA,CAAMZ,CAAU,CAAA,gBAAA,CAA+BH,CAAkB,CAAE,EACnGgB,CAAwBD,CAAAA,CAAAA,CAAkB,GAAI,CAAE,CAAA,CAChDE,EAAuBF,CAAkB,CAAA,EAAA,CAAI,EAAG,CAAA,CAEjD,GAAK,CAAED,EAAM,QAAW,CAAA,CAKlB,SAAS,aAAkBG,GAAAA,CAAAA,GAC/BH,EAAM,cAAe,EAAA,CACrBE,CAAuB,EAAA,KAAA,EAExB,CAAA,CAAA,MACD,CAQK,QAAS,CAAA,aAAA,GAAkBA,IAC/BF,CAAM,CAAA,cAAA,GACNG,CAAsB,EAAA,KAAA,EAGxB,EAAA,CAAA,CAEA,OAAS,QAAA,CAAA,gBAAA,CAAkB,UAAWJ,CAAe,CAAA,CAE9C,IAAM,CACZ,QAAA,CAAS,oBAAqB,SAAWA,CAAAA,CAAe,EACzD,CAED,CAAG,CAAA,CAAEV,CAAU,CAAE,CAAA,CAEV,CAAEK,CAAcG,CAAAA,CAAiB,CAEzC,EC7FO,IAAMO,EAAmBhB,CAAkD,EAAA,CAMjF,IAAMiB,CAAAA,CAAcV,iBACnB,CAAA,IAAMW,gBAAoBlB,CAAQ,EAAA,OAAA,EAAW,MAAU,CAAG,CAAA,CAAEA,CAAO,CACpE,CAAA,CAOMmB,CAAgBZ,CAAAA,iBAAAA,CACrB,IAAMa,iBAAAA,CAAsBpB,GAAQ,OAAW,EAAA,MAAU,CAAG,CAAA,CAAEA,CAAO,CACtE,EAGA,OAAO,CAAEiB,CAAaE,CAAAA,CAAc,CAErC","file":"index.js","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\ntype SetFocusTrap = ( target?: HTMLElement ) => void\ntype RestoreFocusTrap = () => void\n\nconst focusableSelector = [\n\t'input', 'select', 'textarea',\n\t'button', '[href]', '[tabindex]:not([tabindex=\"-1\"])',\n].join( ', ' )\n\n\n/**\n * Trap focus inside the given HTML Element.\n * \n * @param target (Optional) The target HTMLElement React RefObject to trap focus within.\n * \t\t\t\t\tIf no target is given, you must provide the target HTMLElement when calling `setFocusTrap`.\n * \n * @returns A tuple containing:\n * - `setFocusTrap`: A function to enable the focus trap. Optionally accept an HTMLElement as target.\n * - `restoreFocusTrap`: A function to restore the previous focus state.\n */\nexport const useFocusTrap = (\n\ttarget?: React.RefObject<HTMLElement | null>\n): readonly [ SetFocusTrap, RestoreFocusTrap ] => {\n\n\tconst [ focusTrap, setFocusTrapDispatch ] = (\n\t\tuseState<HTMLElement | false>( false )\n\t)\n\n\tconst lastActiveElement = useRef<HTMLElement>( null )\n\t\n\t/**\n\t * Enable the focus trap.\n\t * \n\t */\n\tconst setFocusTrap = useCallback<SetFocusTrap>( onDemandTarget => {\n\n\t\tlastActiveElement.current\t= document.activeElement as HTMLElement\n\t\tconst focusTrap\t\t\t\t= onDemandTarget || target?.current || false\n\t\t\n\t\tif ( ! focusTrap ) return\n\n\t\treturn setFocusTrapDispatch( focusTrap )\n\t\n\t}, [ target ] )\n\n\n\t/**\n\t * Restore the focus to the latest Document active Element.\n\t */\n\tconst restoreFocusTrap = useCallback<RestoreFocusTrap>( () => {\n\n\t\tlastActiveElement.current?.focus()\n\t\tsetFocusTrapDispatch( false )\n\t\n\t}, [] )\n\n\t\n\tuseEffect( () => {\n\n\t\tif ( ! focusTrap ) return\n\n\t\tconst keyDownHandler = ( event: KeyboardEvent ) => {\n\n\t\t\tif ( event.key !== 'Tab' ) return\n\n\t\t\tconst focusableElements\t\t= Array.from( focusTrap.querySelectorAll<HTMLElement>( focusableSelector ) ),\n\t\t\t\tfirstFocusableElement\t= focusableElements.at( 0 ),\n\t\t\t\tlastFocusableElement\t= focusableElements.at( -1 );\n\n\t\t\tif ( ! event.shiftKey ) {\n\t\t\t\t/**\n\t\t\t\t * Focust the firs element if\n\t\t\t\t * focusing forward and the current focused element is the last one.\n\t\t\t\t */\n\t\t\t\tif ( document.activeElement === lastFocusableElement ) {\n\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\tfirstFocusableElement?.focus()\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\n\n\t\t\t/**\n\t\t\t * Focus the last focusable element if\n\t\t\t * focusing backward and the current focused element is the first one.\n\t\t\t * \n\t\t\t */\n\t\t\tif ( document.activeElement === firstFocusableElement ) {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tlastFocusableElement?.focus()\n\t\t\t}\n\n\t\t}\n\n\t\tdocument.addEventListener( 'keydown', keyDownHandler );\n\t\n\t\treturn () => {\n\t\t\tdocument.removeEventListener( 'keydown', keyDownHandler );\n\t\t}\n\n\t}, [ focusTrap ] )\n\n\treturn [ setFocusTrap, restoreFocusTrap ]\n\n}","import { useCallback } from 'react'\nimport {\n\tblockScroll as blockScrollHandler,\n\trestoreScroll as restoreScrollHandler\n} from '@alessiofrittoli/web-utils/dom'\n\n\n/**\n * Prevent Element overflow.\n * \n * @param target (Optional) The React RefObject target HTMLElement. Default: `Document.documentElement`.\n */\nexport const useScrollBlock = ( target?: React.RefObject<HTMLElement | null> ) => {\n\t\n\t/**\n\t * Block scroll.\n\t * \n\t */\n\tconst blockScroll = useCallback(\n\t\t() => blockScrollHandler( target?.current || undefined ), [ target ]\n\t)\n\n\n\t/**\n\t * Restore scroll.\n\t * \n\t */\n\tconst restoreScroll = useCallback(\n\t\t() => restoreScrollHandler( target?.current || undefined ), [ target ]\n\t)\n\n\t\n\treturn [ blockScroll, restoreScroll ] as const\n\n}"]}
@@ -1,2 +0,0 @@
1
- import {useState,useRef,useCallback,useEffect}from'react';import {blockScroll,restoreScroll}from'@alessiofrittoli/web-utils/dom';var S=["input","select","textarea","button","[href]",'[tabindex]:not([tabindex="-1"])'].join(", "),H=e=>{let[r,o]=useState(false),c=useRef(null),p=useCallback(n=>{c.current=document.activeElement;let t=n||e?.current||false;if(t)return o(t)},[e]),d=useCallback(()=>{c.current?.focus(),o(false);},[]);return useEffect(()=>{if(!r)return;let n=t=>{if(t.key!=="Tab")return;let s=Array.from(r.querySelectorAll(S)),l=s.at(0),u=s.at(-1);if(!t.shiftKey){document.activeElement===u&&(t.preventDefault(),l?.focus());return}document.activeElement===l&&(t.preventDefault(),u?.focus());};return document.addEventListener("keydown",n),()=>{document.removeEventListener("keydown",n);}},[r]),[p,d]};var M=e=>{let r=useCallback(()=>blockScroll(e?.current||void 0),[e]),o=useCallback(()=>restoreScroll(e?.current||void 0),[e]);return [r,o]};export{H as useFocusTrap,M as useScrollBlock};//# sourceMappingURL=index.mjs.map
2
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/dom-api/useFocusTrap.ts","../../src/dom-api/useScrollBlock.ts"],"names":["focusableSelector","useFocusTrap","target","focusTrap","setFocusTrapDispatch","useState","lastActiveElement","useRef","setFocusTrap","useCallback","onDemandTarget","restoreFocusTrap","useEffect","keyDownHandler","event","focusableElements","firstFocusableElement","lastFocusableElement","useScrollBlock","blockScroll","blockScrollHandler","restoreScroll","restoreScrollHandler"],"mappings":"iIAKMA,IAAAA,CAAAA,CAAoB,CACzB,OAAS,CAAA,QAAA,CAAU,WACnB,QAAU,CAAA,QAAA,CAAU,iCACrB,CAAE,CAAA,IAAA,CAAM,IAAK,CAAA,CAaAC,CACZC,CAAAA,CAAAA,EACiD,CAEjD,GAAM,CAAEC,EAAWC,CAAqB,CAAA,CACvCC,SAA+B,KAAM,CAAA,CAGhCC,CAAoBC,CAAAA,MAAAA,CAAqB,IAAK,CAAA,CAM9CC,EAAeC,WAA2BC,CAAAA,CAAAA,EAAkB,CAEjEJ,CAAkB,CAAA,OAAA,CAAU,SAAS,aACrC,CAAA,IAAMH,CAAeO,CAAAA,CAAAA,EAAkBR,CAAQ,EAAA,OAAA,EAAW,MAE1D,GAAOC,CAAAA,CAEP,OAAOC,CAAsBD,CAAAA,CAAU,CAExC,CAAG,CAAA,CAAED,CAAO,CAAE,CAMRS,CAAAA,CAAAA,CAAmBF,YAA+B,IAAM,CAE7DH,EAAkB,OAAS,EAAA,KAAA,GAC3BF,CAAsB,CAAA,KAAM,EAE7B,CAAA,CAAG,EAAG,EAGN,OAAAQ,SAAAA,CAAW,IAAM,CAEhB,GAAK,CAAET,CAAY,CAAA,OAEnB,IAAMU,CAAAA,CAAmBC,CAA0B,EAAA,CAElD,GAAKA,CAAM,CAAA,GAAA,GAAQ,MAAQ,OAE3B,IAAMC,EAAqB,KAAM,CAAA,IAAA,CAAMZ,CAAU,CAAA,gBAAA,CAA+BH,CAAkB,CAAE,EACnGgB,CAAwBD,CAAAA,CAAAA,CAAkB,GAAI,CAAE,CAAA,CAChDE,EAAuBF,CAAkB,CAAA,EAAA,CAAI,EAAG,CAAA,CAEjD,GAAK,CAAED,EAAM,QAAW,CAAA,CAKlB,SAAS,aAAkBG,GAAAA,CAAAA,GAC/BH,EAAM,cAAe,EAAA,CACrBE,CAAuB,EAAA,KAAA,EAExB,CAAA,CAAA,MACD,CAQK,QAAS,CAAA,aAAA,GAAkBA,IAC/BF,CAAM,CAAA,cAAA,GACNG,CAAsB,EAAA,KAAA,EAGxB,EAAA,CAAA,CAEA,OAAS,QAAA,CAAA,gBAAA,CAAkB,UAAWJ,CAAe,CAAA,CAE9C,IAAM,CACZ,QAAA,CAAS,oBAAqB,SAAWA,CAAAA,CAAe,EACzD,CAED,CAAG,CAAA,CAAEV,CAAU,CAAE,CAAA,CAEV,CAAEK,CAAcG,CAAAA,CAAiB,CAEzC,EC7FO,IAAMO,EAAmBhB,CAAkD,EAAA,CAMjF,IAAMiB,CAAAA,CAAcV,WACnB,CAAA,IAAMW,YAAoBlB,CAAQ,EAAA,OAAA,EAAW,MAAU,CAAG,CAAA,CAAEA,CAAO,CACpE,CAAA,CAOMmB,CAAgBZ,CAAAA,WAAAA,CACrB,IAAMa,aAAAA,CAAsBpB,GAAQ,OAAW,EAAA,MAAU,CAAG,CAAA,CAAEA,CAAO,CACtE,EAGA,OAAO,CAAEiB,CAAaE,CAAAA,CAAc,CAErC","file":"index.mjs","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\ntype SetFocusTrap = ( target?: HTMLElement ) => void\ntype RestoreFocusTrap = () => void\n\nconst focusableSelector = [\n\t'input', 'select', 'textarea',\n\t'button', '[href]', '[tabindex]:not([tabindex=\"-1\"])',\n].join( ', ' )\n\n\n/**\n * Trap focus inside the given HTML Element.\n * \n * @param target (Optional) The target HTMLElement React RefObject to trap focus within.\n * \t\t\t\t\tIf no target is given, you must provide the target HTMLElement when calling `setFocusTrap`.\n * \n * @returns A tuple containing:\n * - `setFocusTrap`: A function to enable the focus trap. Optionally accept an HTMLElement as target.\n * - `restoreFocusTrap`: A function to restore the previous focus state.\n */\nexport const useFocusTrap = (\n\ttarget?: React.RefObject<HTMLElement | null>\n): readonly [ SetFocusTrap, RestoreFocusTrap ] => {\n\n\tconst [ focusTrap, setFocusTrapDispatch ] = (\n\t\tuseState<HTMLElement | false>( false )\n\t)\n\n\tconst lastActiveElement = useRef<HTMLElement>( null )\n\t\n\t/**\n\t * Enable the focus trap.\n\t * \n\t */\n\tconst setFocusTrap = useCallback<SetFocusTrap>( onDemandTarget => {\n\n\t\tlastActiveElement.current\t= document.activeElement as HTMLElement\n\t\tconst focusTrap\t\t\t\t= onDemandTarget || target?.current || false\n\t\t\n\t\tif ( ! focusTrap ) return\n\n\t\treturn setFocusTrapDispatch( focusTrap )\n\t\n\t}, [ target ] )\n\n\n\t/**\n\t * Restore the focus to the latest Document active Element.\n\t */\n\tconst restoreFocusTrap = useCallback<RestoreFocusTrap>( () => {\n\n\t\tlastActiveElement.current?.focus()\n\t\tsetFocusTrapDispatch( false )\n\t\n\t}, [] )\n\n\t\n\tuseEffect( () => {\n\n\t\tif ( ! focusTrap ) return\n\n\t\tconst keyDownHandler = ( event: KeyboardEvent ) => {\n\n\t\t\tif ( event.key !== 'Tab' ) return\n\n\t\t\tconst focusableElements\t\t= Array.from( focusTrap.querySelectorAll<HTMLElement>( focusableSelector ) ),\n\t\t\t\tfirstFocusableElement\t= focusableElements.at( 0 ),\n\t\t\t\tlastFocusableElement\t= focusableElements.at( -1 );\n\n\t\t\tif ( ! event.shiftKey ) {\n\t\t\t\t/**\n\t\t\t\t * Focust the firs element if\n\t\t\t\t * focusing forward and the current focused element is the last one.\n\t\t\t\t */\n\t\t\t\tif ( document.activeElement === lastFocusableElement ) {\n\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\tfirstFocusableElement?.focus()\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\n\n\t\t\t/**\n\t\t\t * Focus the last focusable element if\n\t\t\t * focusing backward and the current focused element is the first one.\n\t\t\t * \n\t\t\t */\n\t\t\tif ( document.activeElement === firstFocusableElement ) {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tlastFocusableElement?.focus()\n\t\t\t}\n\n\t\t}\n\n\t\tdocument.addEventListener( 'keydown', keyDownHandler );\n\t\n\t\treturn () => {\n\t\t\tdocument.removeEventListener( 'keydown', keyDownHandler );\n\t\t}\n\n\t}, [ focusTrap ] )\n\n\treturn [ setFocusTrap, restoreFocusTrap ]\n\n}","import { useCallback } from 'react'\nimport {\n\tblockScroll as blockScrollHandler,\n\trestoreScroll as restoreScrollHandler\n} from '@alessiofrittoli/web-utils/dom'\n\n\n/**\n * Prevent Element overflow.\n * \n * @param target (Optional) The React RefObject target HTMLElement. Default: `Document.documentElement`.\n */\nexport const useScrollBlock = ( target?: React.RefObject<HTMLElement | null> ) => {\n\t\n\t/**\n\t * Block scroll.\n\t * \n\t */\n\tconst blockScroll = useCallback(\n\t\t() => blockScrollHandler( target?.current || undefined ), [ target ]\n\t)\n\n\n\t/**\n\t * Restore scroll.\n\t * \n\t */\n\tconst restoreScroll = useCallback(\n\t\t() => restoreScrollHandler( target?.current || undefined ), [ target ]\n\t)\n\n\t\n\treturn [ blockScroll, restoreScroll ] as const\n\n}"]}
@@ -1,15 +0,0 @@
1
- type SetFocusTrap = (target?: HTMLElement) => void;
2
- type RestoreFocusTrap = () => void;
3
- /**
4
- * Trap focus inside the given HTML Element.
5
- *
6
- * @param target (Optional) The target HTMLElement React RefObject to trap focus within.
7
- * If no target is given, you must provide the target HTMLElement when calling `setFocusTrap`.
8
- *
9
- * @returns A tuple containing:
10
- * - `setFocusTrap`: A function to enable the focus trap. Optionally accept an HTMLElement as target.
11
- * - `restoreFocusTrap`: A function to restore the previous focus state.
12
- */
13
- declare const useFocusTrap: (target?: React.RefObject<HTMLElement | null>) => readonly [SetFocusTrap, RestoreFocusTrap];
14
-
15
- export { useFocusTrap };
@@ -1,15 +0,0 @@
1
- type SetFocusTrap = (target?: HTMLElement) => void;
2
- type RestoreFocusTrap = () => void;
3
- /**
4
- * Trap focus inside the given HTML Element.
5
- *
6
- * @param target (Optional) The target HTMLElement React RefObject to trap focus within.
7
- * If no target is given, you must provide the target HTMLElement when calling `setFocusTrap`.
8
- *
9
- * @returns A tuple containing:
10
- * - `setFocusTrap`: A function to enable the focus trap. Optionally accept an HTMLElement as target.
11
- * - `restoreFocusTrap`: A function to restore the previous focus state.
12
- */
13
- declare const useFocusTrap: (target?: React.RefObject<HTMLElement | null>) => readonly [SetFocusTrap, RestoreFocusTrap];
14
-
15
- export { useFocusTrap };
@@ -1,2 +0,0 @@
1
- 'use strict';var react=require('react');var E=["input","select","textarea","button","[href]",'[tabindex]:not([tabindex="-1"])'].join(", "),b=n=>{let[r,o]=react.useState(false),s=react.useRef(null),f=react.useCallback(t=>{s.current=document.activeElement;let e=t||n?.current||false;if(e)return o(e)},[n]),i=react.useCallback(()=>{s.current?.focus(),o(false);},[]);return react.useEffect(()=>{if(!r)return;let t=e=>{if(e.key!=="Tab")return;let c=Array.from(r.querySelectorAll(E)),u=c.at(0),a=c.at(-1);if(!e.shiftKey){document.activeElement===a&&(e.preventDefault(),u?.focus());return}document.activeElement===u&&(e.preventDefault(),a?.focus());};return document.addEventListener("keydown",t),()=>{document.removeEventListener("keydown",t);}},[r]),[f,i]};exports.useFocusTrap=b;//# sourceMappingURL=useFocusTrap.js.map
2
- //# sourceMappingURL=useFocusTrap.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/dom-api/useFocusTrap.ts"],"names":["focusableSelector","useFocusTrap","target","focusTrap","setFocusTrapDispatch","useState","lastActiveElement","useRef","setFocusTrap","useCallback","onDemandTarget","restoreFocusTrap","useEffect","keyDownHandler","event","focusableElements","firstFocusableElement","lastFocusableElement"],"mappings":"wCAKA,IAAMA,EAAoB,CACzB,OAAA,CAAS,QAAU,CAAA,UAAA,CACnB,SAAU,QAAU,CAAA,iCACrB,CAAE,CAAA,IAAA,CAAM,IAAK,CAaAC,CAAAA,CAAAA,CACZC,CACiD,EAAA,CAEjD,GAAM,CAAEC,CAAAA,CAAWC,CAAqB,CAAA,CACvCC,eAA+B,KAAM,CAAA,CAGhCC,EAAoBC,YAAqB,CAAA,IAAK,EAM9CC,CAAeC,CAAAA,iBAAAA,CAA2BC,CAAkB,EAAA,CAEjEJ,EAAkB,OAAU,CAAA,QAAA,CAAS,aACrC,CAAA,IAAMH,EAAeO,CAAkBR,EAAAA,CAAAA,EAAQ,OAAW,EAAA,KAAA,CAE1D,GAAOC,CAEP,CAAA,OAAOC,CAAsBD,CAAAA,CAAU,CAExC,CAAG,CAAA,CAAED,CAAO,CAAE,EAMRS,CAAmBF,CAAAA,iBAAAA,CAA+B,IAAM,CAE7DH,EAAkB,OAAS,EAAA,KAAA,EAC3BF,CAAAA,CAAAA,CAAsB,KAAM,EAE7B,CAAA,CAAG,EAAG,CAAA,CAGN,OAAAQ,eAAW,CAAA,IAAM,CAEhB,GAAK,CAAET,CAAY,CAAA,OAEnB,IAAMU,CAAAA,CAAmBC,GAA0B,CAElD,GAAKA,CAAM,CAAA,GAAA,GAAQ,MAAQ,OAE3B,IAAMC,CAAqB,CAAA,KAAA,CAAM,KAAMZ,CAAU,CAAA,gBAAA,CAA+BH,CAAkB,CAAE,EACnGgB,CAAwBD,CAAAA,CAAAA,CAAkB,EAAI,CAAA,CAAE,EAChDE,CAAuBF,CAAAA,CAAAA,CAAkB,EAAI,CAAA,EAAG,EAEjD,GAAK,CAAED,EAAM,QAAW,CAAA,CAKlB,SAAS,aAAkBG,GAAAA,CAAAA,GAC/BH,CAAM,CAAA,cAAA,GACNE,CAAuB,EAAA,KAAA,EAExB,CAAA,CAAA,MACD,CAQK,QAAS,CAAA,aAAA,GAAkBA,CAC/BF,GAAAA,CAAAA,CAAM,gBACNG,CAAAA,CAAAA,EAAsB,KAAM,EAAA,EAG9B,EAEA,OAAS,QAAA,CAAA,gBAAA,CAAkB,SAAWJ,CAAAA,CAAe,EAE9C,IAAM,CACZ,QAAS,CAAA,mBAAA,CAAqB,UAAWA,CAAe,EACzD,CAED,CAAA,CAAG,CAAEV,CAAU,CAAE,EAEV,CAAEK,CAAAA,CAAcG,CAAiB,CAEzC","file":"useFocusTrap.js","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\ntype SetFocusTrap = ( target?: HTMLElement ) => void\ntype RestoreFocusTrap = () => void\n\nconst focusableSelector = [\n\t'input', 'select', 'textarea',\n\t'button', '[href]', '[tabindex]:not([tabindex=\"-1\"])',\n].join( ', ' )\n\n\n/**\n * Trap focus inside the given HTML Element.\n * \n * @param target (Optional) The target HTMLElement React RefObject to trap focus within.\n * \t\t\t\t\tIf no target is given, you must provide the target HTMLElement when calling `setFocusTrap`.\n * \n * @returns A tuple containing:\n * - `setFocusTrap`: A function to enable the focus trap. Optionally accept an HTMLElement as target.\n * - `restoreFocusTrap`: A function to restore the previous focus state.\n */\nexport const useFocusTrap = (\n\ttarget?: React.RefObject<HTMLElement | null>\n): readonly [ SetFocusTrap, RestoreFocusTrap ] => {\n\n\tconst [ focusTrap, setFocusTrapDispatch ] = (\n\t\tuseState<HTMLElement | false>( false )\n\t)\n\n\tconst lastActiveElement = useRef<HTMLElement>( null )\n\t\n\t/**\n\t * Enable the focus trap.\n\t * \n\t */\n\tconst setFocusTrap = useCallback<SetFocusTrap>( onDemandTarget => {\n\n\t\tlastActiveElement.current\t= document.activeElement as HTMLElement\n\t\tconst focusTrap\t\t\t\t= onDemandTarget || target?.current || false\n\t\t\n\t\tif ( ! focusTrap ) return\n\n\t\treturn setFocusTrapDispatch( focusTrap )\n\t\n\t}, [ target ] )\n\n\n\t/**\n\t * Restore the focus to the latest Document active Element.\n\t */\n\tconst restoreFocusTrap = useCallback<RestoreFocusTrap>( () => {\n\n\t\tlastActiveElement.current?.focus()\n\t\tsetFocusTrapDispatch( false )\n\t\n\t}, [] )\n\n\t\n\tuseEffect( () => {\n\n\t\tif ( ! focusTrap ) return\n\n\t\tconst keyDownHandler = ( event: KeyboardEvent ) => {\n\n\t\t\tif ( event.key !== 'Tab' ) return\n\n\t\t\tconst focusableElements\t\t= Array.from( focusTrap.querySelectorAll<HTMLElement>( focusableSelector ) ),\n\t\t\t\tfirstFocusableElement\t= focusableElements.at( 0 ),\n\t\t\t\tlastFocusableElement\t= focusableElements.at( -1 );\n\n\t\t\tif ( ! event.shiftKey ) {\n\t\t\t\t/**\n\t\t\t\t * Focust the firs element if\n\t\t\t\t * focusing forward and the current focused element is the last one.\n\t\t\t\t */\n\t\t\t\tif ( document.activeElement === lastFocusableElement ) {\n\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\tfirstFocusableElement?.focus()\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\n\n\t\t\t/**\n\t\t\t * Focus the last focusable element if\n\t\t\t * focusing backward and the current focused element is the first one.\n\t\t\t * \n\t\t\t */\n\t\t\tif ( document.activeElement === firstFocusableElement ) {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tlastFocusableElement?.focus()\n\t\t\t}\n\n\t\t}\n\n\t\tdocument.addEventListener( 'keydown', keyDownHandler );\n\t\n\t\treturn () => {\n\t\t\tdocument.removeEventListener( 'keydown', keyDownHandler );\n\t\t}\n\n\t}, [ focusTrap ] )\n\n\treturn [ setFocusTrap, restoreFocusTrap ]\n\n}"]}
@@ -1,2 +0,0 @@
1
- import {useState,useRef,useCallback,useEffect}from'react';var E=["input","select","textarea","button","[href]",'[tabindex]:not([tabindex="-1"])'].join(", "),y=n=>{let[r,o]=useState(false),s=useRef(null),f=useCallback(t=>{s.current=document.activeElement;let e=t||n?.current||false;if(e)return o(e)},[n]),i=useCallback(()=>{s.current?.focus(),o(false);},[]);return useEffect(()=>{if(!r)return;let t=e=>{if(e.key!=="Tab")return;let c=Array.from(r.querySelectorAll(E)),u=c.at(0),a=c.at(-1);if(!e.shiftKey){document.activeElement===a&&(e.preventDefault(),u?.focus());return}document.activeElement===u&&(e.preventDefault(),a?.focus());};return document.addEventListener("keydown",t),()=>{document.removeEventListener("keydown",t);}},[r]),[f,i]};export{y as useFocusTrap};//# sourceMappingURL=useFocusTrap.mjs.map
2
- //# sourceMappingURL=useFocusTrap.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/dom-api/useFocusTrap.ts"],"names":["focusableSelector","useFocusTrap","target","focusTrap","setFocusTrapDispatch","useState","lastActiveElement","useRef","setFocusTrap","useCallback","onDemandTarget","restoreFocusTrap","useEffect","keyDownHandler","event","focusableElements","firstFocusableElement","lastFocusableElement"],"mappings":"0DAKA,IAAMA,EAAoB,CACzB,OAAA,CAAS,QAAU,CAAA,UAAA,CACnB,SAAU,QAAU,CAAA,iCACrB,CAAE,CAAA,IAAA,CAAM,IAAK,CAaAC,CAAAA,CAAAA,CACZC,CACiD,EAAA,CAEjD,GAAM,CAAEC,CAAAA,CAAWC,CAAqB,CAAA,CACvCC,SAA+B,KAAM,CAAA,CAGhCC,EAAoBC,MAAqB,CAAA,IAAK,EAM9CC,CAAeC,CAAAA,WAAAA,CAA2BC,CAAkB,EAAA,CAEjEJ,EAAkB,OAAU,CAAA,QAAA,CAAS,aACrC,CAAA,IAAMH,EAAeO,CAAkBR,EAAAA,CAAAA,EAAQ,OAAW,EAAA,KAAA,CAE1D,GAAOC,CAEP,CAAA,OAAOC,CAAsBD,CAAAA,CAAU,CAExC,CAAG,CAAA,CAAED,CAAO,CAAE,EAMRS,CAAmBF,CAAAA,WAAAA,CAA+B,IAAM,CAE7DH,EAAkB,OAAS,EAAA,KAAA,EAC3BF,CAAAA,CAAAA,CAAsB,KAAM,EAE7B,CAAA,CAAG,EAAG,CAAA,CAGN,OAAAQ,SAAW,CAAA,IAAM,CAEhB,GAAK,CAAET,CAAY,CAAA,OAEnB,IAAMU,CAAAA,CAAmBC,GAA0B,CAElD,GAAKA,CAAM,CAAA,GAAA,GAAQ,MAAQ,OAE3B,IAAMC,CAAqB,CAAA,KAAA,CAAM,KAAMZ,CAAU,CAAA,gBAAA,CAA+BH,CAAkB,CAAE,EACnGgB,CAAwBD,CAAAA,CAAAA,CAAkB,EAAI,CAAA,CAAE,EAChDE,CAAuBF,CAAAA,CAAAA,CAAkB,EAAI,CAAA,EAAG,EAEjD,GAAK,CAAED,EAAM,QAAW,CAAA,CAKlB,SAAS,aAAkBG,GAAAA,CAAAA,GAC/BH,CAAM,CAAA,cAAA,GACNE,CAAuB,EAAA,KAAA,EAExB,CAAA,CAAA,MACD,CAQK,QAAS,CAAA,aAAA,GAAkBA,CAC/BF,GAAAA,CAAAA,CAAM,gBACNG,CAAAA,CAAAA,EAAsB,KAAM,EAAA,EAG9B,EAEA,OAAS,QAAA,CAAA,gBAAA,CAAkB,SAAWJ,CAAAA,CAAe,EAE9C,IAAM,CACZ,QAAS,CAAA,mBAAA,CAAqB,UAAWA,CAAe,EACzD,CAED,CAAA,CAAG,CAAEV,CAAU,CAAE,EAEV,CAAEK,CAAAA,CAAcG,CAAiB,CAEzC","file":"useFocusTrap.mjs","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\ntype SetFocusTrap = ( target?: HTMLElement ) => void\ntype RestoreFocusTrap = () => void\n\nconst focusableSelector = [\n\t'input', 'select', 'textarea',\n\t'button', '[href]', '[tabindex]:not([tabindex=\"-1\"])',\n].join( ', ' )\n\n\n/**\n * Trap focus inside the given HTML Element.\n * \n * @param target (Optional) The target HTMLElement React RefObject to trap focus within.\n * \t\t\t\t\tIf no target is given, you must provide the target HTMLElement when calling `setFocusTrap`.\n * \n * @returns A tuple containing:\n * - `setFocusTrap`: A function to enable the focus trap. Optionally accept an HTMLElement as target.\n * - `restoreFocusTrap`: A function to restore the previous focus state.\n */\nexport const useFocusTrap = (\n\ttarget?: React.RefObject<HTMLElement | null>\n): readonly [ SetFocusTrap, RestoreFocusTrap ] => {\n\n\tconst [ focusTrap, setFocusTrapDispatch ] = (\n\t\tuseState<HTMLElement | false>( false )\n\t)\n\n\tconst lastActiveElement = useRef<HTMLElement>( null )\n\t\n\t/**\n\t * Enable the focus trap.\n\t * \n\t */\n\tconst setFocusTrap = useCallback<SetFocusTrap>( onDemandTarget => {\n\n\t\tlastActiveElement.current\t= document.activeElement as HTMLElement\n\t\tconst focusTrap\t\t\t\t= onDemandTarget || target?.current || false\n\t\t\n\t\tif ( ! focusTrap ) return\n\n\t\treturn setFocusTrapDispatch( focusTrap )\n\t\n\t}, [ target ] )\n\n\n\t/**\n\t * Restore the focus to the latest Document active Element.\n\t */\n\tconst restoreFocusTrap = useCallback<RestoreFocusTrap>( () => {\n\n\t\tlastActiveElement.current?.focus()\n\t\tsetFocusTrapDispatch( false )\n\t\n\t}, [] )\n\n\t\n\tuseEffect( () => {\n\n\t\tif ( ! focusTrap ) return\n\n\t\tconst keyDownHandler = ( event: KeyboardEvent ) => {\n\n\t\t\tif ( event.key !== 'Tab' ) return\n\n\t\t\tconst focusableElements\t\t= Array.from( focusTrap.querySelectorAll<HTMLElement>( focusableSelector ) ),\n\t\t\t\tfirstFocusableElement\t= focusableElements.at( 0 ),\n\t\t\t\tlastFocusableElement\t= focusableElements.at( -1 );\n\n\t\t\tif ( ! event.shiftKey ) {\n\t\t\t\t/**\n\t\t\t\t * Focust the firs element if\n\t\t\t\t * focusing forward and the current focused element is the last one.\n\t\t\t\t */\n\t\t\t\tif ( document.activeElement === lastFocusableElement ) {\n\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\tfirstFocusableElement?.focus()\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\n\n\t\t\t/**\n\t\t\t * Focus the last focusable element if\n\t\t\t * focusing backward and the current focused element is the first one.\n\t\t\t * \n\t\t\t */\n\t\t\tif ( document.activeElement === firstFocusableElement ) {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tlastFocusableElement?.focus()\n\t\t\t}\n\n\t\t}\n\n\t\tdocument.addEventListener( 'keydown', keyDownHandler );\n\t\n\t\treturn () => {\n\t\t\tdocument.removeEventListener( 'keydown', keyDownHandler );\n\t\t}\n\n\t}, [ focusTrap ] )\n\n\treturn [ setFocusTrap, restoreFocusTrap ]\n\n}"]}
@@ -1,8 +0,0 @@
1
- /**
2
- * Prevent Element overflow.
3
- *
4
- * @param target (Optional) The React RefObject target HTMLElement. Default: `Document.documentElement`.
5
- */
6
- declare const useScrollBlock: (target?: React.RefObject<HTMLElement | null>) => readonly [() => void, () => void];
7
-
8
- export { useScrollBlock };
@@ -1,8 +0,0 @@
1
- /**
2
- * Prevent Element overflow.
3
- *
4
- * @param target (Optional) The React RefObject target HTMLElement. Default: `Document.documentElement`.
5
- */
6
- declare const useScrollBlock: (target?: React.RefObject<HTMLElement | null>) => readonly [() => void, () => void];
7
-
8
- export { useScrollBlock };
@@ -1,2 +0,0 @@
1
- 'use strict';var react=require('react'),dom=require('@alessiofrittoli/web-utils/dom');var S=l=>{let r=react.useCallback(()=>dom.blockScroll(l?.current||void 0),[l]),c=react.useCallback(()=>dom.restoreScroll(l?.current||void 0),[l]);return [r,c]};exports.useScrollBlock=S;//# sourceMappingURL=useScrollBlock.js.map
2
- //# sourceMappingURL=useScrollBlock.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/dom-api/useScrollBlock.ts"],"names":["useScrollBlock","target","blockScroll","useCallback","blockScrollHandler","restoreScroll","restoreScrollHandler"],"mappings":"0FAYaA,CAAmBC,CAAAA,CAAAA,EAAkD,CAMjF,IAAMC,CAAAA,CAAcC,kBACnB,IAAMC,eAAAA,CAAoBH,GAAQ,OAAW,EAAA,MAAU,CAAG,CAAA,CAAEA,CAAO,CACpE,CAAA,CAOMI,EAAgBF,iBACrB,CAAA,IAAMG,kBAAsBL,CAAQ,EAAA,OAAA,EAAW,MAAU,CAAG,CAAA,CAAEA,CAAO,CACtE,CAAA,CAGA,OAAO,CAAEC,CAAAA,CAAaG,CAAc,CAErC","file":"useScrollBlock.js","sourcesContent":["import { useCallback } from 'react'\nimport {\n\tblockScroll as blockScrollHandler,\n\trestoreScroll as restoreScrollHandler\n} from '@alessiofrittoli/web-utils/dom'\n\n\n/**\n * Prevent Element overflow.\n * \n * @param target (Optional) The React RefObject target HTMLElement. Default: `Document.documentElement`.\n */\nexport const useScrollBlock = ( target?: React.RefObject<HTMLElement | null> ) => {\n\t\n\t/**\n\t * Block scroll.\n\t * \n\t */\n\tconst blockScroll = useCallback(\n\t\t() => blockScrollHandler( target?.current || undefined ), [ target ]\n\t)\n\n\n\t/**\n\t * Restore scroll.\n\t * \n\t */\n\tconst restoreScroll = useCallback(\n\t\t() => restoreScrollHandler( target?.current || undefined ), [ target ]\n\t)\n\n\t\n\treturn [ blockScroll, restoreScroll ] as const\n\n}"]}
@@ -1,2 +0,0 @@
1
- import {useCallback}from'react';import {blockScroll,restoreScroll}from'@alessiofrittoli/web-utils/dom';var d=l=>{let r=useCallback(()=>blockScroll(l?.current||void 0),[l]),c=useCallback(()=>restoreScroll(l?.current||void 0),[l]);return [r,c]};export{d as useScrollBlock};//# sourceMappingURL=useScrollBlock.mjs.map
2
- //# sourceMappingURL=useScrollBlock.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/dom-api/useScrollBlock.ts"],"names":["useScrollBlock","target","blockScroll","useCallback","blockScrollHandler","restoreScroll","restoreScrollHandler"],"mappings":"2GAYaA,CAAmBC,CAAAA,CAAAA,EAAkD,CAMjF,IAAMC,CAAAA,CAAcC,YACnB,IAAMC,WAAAA,CAAoBH,GAAQ,OAAW,EAAA,MAAU,CAAG,CAAA,CAAEA,CAAO,CACpE,CAAA,CAOMI,EAAgBF,WACrB,CAAA,IAAMG,cAAsBL,CAAQ,EAAA,OAAA,EAAW,MAAU,CAAG,CAAA,CAAEA,CAAO,CACtE,CAAA,CAGA,OAAO,CAAEC,CAAAA,CAAaG,CAAc,CAErC","file":"useScrollBlock.mjs","sourcesContent":["import { useCallback } from 'react'\nimport {\n\tblockScroll as blockScrollHandler,\n\trestoreScroll as restoreScrollHandler\n} from '@alessiofrittoli/web-utils/dom'\n\n\n/**\n * Prevent Element overflow.\n * \n * @param target (Optional) The React RefObject target HTMLElement. Default: `Document.documentElement`.\n */\nexport const useScrollBlock = ( target?: React.RefObject<HTMLElement | null> ) => {\n\t\n\t/**\n\t * Block scroll.\n\t * \n\t */\n\tconst blockScroll = useCallback(\n\t\t() => blockScrollHandler( target?.current || undefined ), [ target ]\n\t)\n\n\n\t/**\n\t * Restore scroll.\n\t * \n\t */\n\tconst restoreScroll = useCallback(\n\t\t() => restoreScrollHandler( target?.current || undefined ), [ target ]\n\t)\n\n\t\n\treturn [ blockScroll, restoreScroll ] as const\n\n}"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/eslint.ts"],"names":["config"],"mappings":"aAWO,IAAMA,EAA8B,CAC1C,WAAA,CAAa,CACZ,CACC,MAAO,CACN,6BAAA,CAA+B,CAC9B,MAAA,CACA,CACC,eAAiB,CAAA,mBAClB,CACD,CACD,CACD,CACD,CACD","file":"eslint.js","sourcesContent":["import type { Linter } from 'eslint'\n\ninterface ESLintConfiguration\n{\n\trecommended: Linter.Config[]\n}\n\n\n/**\n * [`@alessiofrittoli/react-hooks`](https://npmjs.com/package/@alessiofrittoli/react-hooks) Recommended ESLint configurations.\n */\nexport const config: ESLintConfiguration = {\n\trecommended: [\n\t\t{\n\t\t\trules: {\n\t\t\t\t'react-hooks/exhaustive-deps': [\n\t\t\t\t\t'warn',\n\t\t\t\t\t{\n\t\t\t\t\t\tadditionalHooks: '(useUpdateEffect)',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t}\n\t\t}\n\t]\n}"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/eslint.ts"],"names":["config"],"mappings":"AAWO,IAAMA,EAA8B,CAC1C,WAAA,CAAa,CACZ,CACC,MAAO,CACN,6BAAA,CAA+B,CAC9B,MAAA,CACA,CACC,eAAiB,CAAA,mBAClB,CACD,CACD,CACD,CACD,CACD","file":"eslint.mjs","sourcesContent":["import type { Linter } from 'eslint'\n\ninterface ESLintConfiguration\n{\n\trecommended: Linter.Config[]\n}\n\n\n/**\n * [`@alessiofrittoli/react-hooks`](https://npmjs.com/package/@alessiofrittoli/react-hooks) Recommended ESLint configurations.\n */\nexport const config: ESLintConfiguration = {\n\trecommended: [\n\t\t{\n\t\t\trules: {\n\t\t\t\t'react-hooks/exhaustive-deps': [\n\t\t\t\t\t'warn',\n\t\t\t\t\t{\n\t\t\t\t\t\tadditionalHooks: '(useUpdateEffect)',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t}\n\t\t}\n\t]\n}"]}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/browser-api/storage/useStorage.ts","../src/browser-api/storage/useLocalStorage.ts","../src/browser-api/storage/useSessionStorage.ts","../src/browser-api/useMediaQuery.ts","../src/browser-api/useIsPortrait.ts","../src/dom-api/useFocusTrap.ts","../src/dom-api/useScrollBlock.ts","../src/misc/useIsClient.ts","../src/misc/useIsFirstRender.ts","../src/misc/useUpdateEffect.ts"],"names":["useStorage","key","initialValue","type","readValue","useCallback","LocalStorage","SessionStorage","storedValue","setStoredValue","useState","setValue","value","valueToStore","useEffect","useLocalStorage","useSessionStorage","useMediaQuery","query","matches","setMatches","getMediaMatches","matchMediaChangeHandler","matchMedia","useIsPortrait","portraitMediaQuery","focusableSelector","useFocusTrap","target","focusTrap","setFocusTrapDispatch","lastActiveElement","useRef","setFocusTrap","onDemandTarget","restoreFocusTrap","keyDownHandler","event","focusableElements","firstFocusableElement","lastFocusableElement","useScrollBlock","blockScroll","blockScrollHandler","restoreScroll","restoreScrollHandler","useIsClient","isClient","setClient","useIsFirstRender","isFirst","useUpdateEff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U,CAAG,CAAA,CAAEA,CAAO,CACtE,CAGA,CAAA,OAAO,CAAEc,CAAAA,CAAaE,CAAc,CAErC,EC3BO,IAAME,EAAc,CAAA,IAAM,CAEhC,GAAM,CAAEC,CAAAA,CAAUC,CAAU,CAAA,CAAItC,cAAU,CAAA,KAAM,EAEhD,OAAAI,eAAAA,CAAW,IAAMkC,CAAAA,CAAW,IAAK,CAAA,CAAG,EAAG,CAEhCD,CAAAA,CAER,ECPO,IAAME,CAAmB,CAAA,IAAM,CAErC,IAAMC,CAAUlB,CAAAA,YAAAA,CAAQ,IAAK,CAAA,CAE7B,OAAKkB,CAAAA,CAAQ,OACZA,EAAAA,CAAAA,CAAQ,OAAU,CAAA,KAAA,CAEX,MAGDA,CAAQ,CAAA,OAEhB,ECVO,IAAMC,EAAkB,CAAA,CAC9BC,CACAC,CAAAA,CAAAA,GACI,CAEJ,IAAMH,CAAUD,CAAAA,CAAAA,EAEhBnC,CAAAA,eAAAA,CAAW,IAAM,CAChB,GAAK,CAAEoC,CAAU,CAAA,OAAOE,CAAO,EAEhC,CAAGC,CAAAA,CAAK,EAET","file":"index.js","sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { LocalStorage } from '@alessiofrittoli/web-utils/storage/LocalStorage'\nimport { SessionStorage } from '@alessiofrittoli/web-utils/storage/SessionStorage'\n\ntype Value<T>\t\t= T | undefined | null\ntype SetValue<T>\t= React.Dispatch<React.SetStateAction<T>>\n\n/**\n * Easly handle Local or Session Storage State.\n * \n * @param\tkey\t\t\t\tThe storage item key.\n * @param\tinitialValue\tThe storage item initial value.\n * @param\ttype\t\t\t( Optional ) The storage API to use. Default: `local`.\n */\nexport const useStorage = <T = string>(\n\tkey\t\t\t\t: string,\n\tinitialValue?\t: T,\n\ttype\t\t\t: 'local' | 'session' = 'local'\n): [ Value<T>, SetValue<Value<T>> ] => {\n\n\tconst readValue = useCallback( () => (\n\t\t( type === 'local' ? LocalStorage : SessionStorage )\n\t\t\t.get<T>( key ) ?? initialValue\n\t), [ type, key, initialValue ] )\n\n\n\t/**\n\t * State to store our value.\n\t * Pass initial state function to useState so logic is only executed once.\n\t * \n\t */\n\tconst [ storedValue, setStoredValue ] = useState<Value<T>>( initialValue )\n\n\t/**\n\t * Return a wrapped version of useState's setter function that\n\t * persists the new value to localStorage | sessionStorage.\n\t * \n\t * @param value The SetStateAction value.\n\t */\n\tconst setValue = useCallback<SetValue<Value<T>>>( value => {\n\n\t\tsetStoredValue( storedValue => {\n\t\t\tconst valueToStore = value instanceof Function ? value( storedValue ) : value\n\t\n\t\t\t;(\n\t\t\t\ttypeof window !== 'undefined' &&\n\t\t\t\ttype === 'local' ? LocalStorage : SessionStorage\n\t\t\t).set( key, valueToStore )\n\n\t\t\treturn valueToStore\n\t\t} )\n\n\n\t}, [ type, key ] )\n\n\tuseEffect( () => {\n\t\tsetStoredValue( readValue() )\n\t}, [ readValue ] )\n\n\treturn [ storedValue, setValue ]\n}","import { useStorage } from './useStorage'\n\n/**\n * useLocalStorage hook.\n * \n * @param\tkey\t\t\t\tThe local storage item key.\n * @param\tinitialValue\tThe local storage item initial value.\n */\nexport const useLocalStorage = <T = string>(\n\tkey\t\t\t\t: string,\n\tinitialValue?\t: T\n) => useStorage( key, initialValue, 'local' )","import { useStorage } from './useStorage'\n\n/**\n * useSessionStorage hook.\n * \n * @param\tkey\t\t\t\tThe session item key.\n * @param\tinitialValue\tThe session item initial value.\n */\nexport const useSessionStorage = <T = string>(\n\tkey\t\t\t\t: string,\n\tinitialValue?\t: T\n) => useStorage( key, initialValue, 'session' )","import { useCallback, useEffect, useState } from 'react'\nimport { getMediaMatches } from '@alessiofrittoli/web-utils/browser-api'\n\n\n/**\n * Get Document Media matches and listen for changes.\n *\n * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia)\n *\n * @param\tquery A string specifying the media query to parse into a `MediaQueryList`.\n * @returns\tA boolean value that returns `true` if the document currently matches the media query list, or `false` if not.\n */\nexport const useMediaQuery = ( query: string ) => {\n\n\tconst [ matches, setMatches ]\t= useState( getMediaMatches( query ) )\n\tconst matchMediaChangeHandler\t= useCallback( () => setMatches( getMediaMatches( query ) ), [ query ] )\n\n\n\tuseEffect( () => {\n\n\t\tconst matchMedia = window.matchMedia( query )\n\t\t// Triggered at the first client-side load\n\t\tmatchMediaChangeHandler()\n\t\t// Listen matchMedia\n\t\tmatchMedia.addEventListener( 'change', matchMediaChangeHandler )\n\n\t\treturn () => {\n\t\t\tmatchMedia.removeEventListener( 'change', matchMediaChangeHandler )\n\t\t}\n\n\t}, [ query, matchMediaChangeHandler ] )\n\n\treturn matches\n\t\n}","import { useMediaQuery } from './useMediaQuery'\nimport { portraitMediaQuery } from '@alessiofrittoli/web-utils/device'\n\n/**\n * Check if device is portrait oriented.\n * \n * State get updated when device orientation changes.\n *\n * @returns\t`true` if the device is portrait oriented, `false` otherwise.\n */\nexport const useIsPortrait = () => useMediaQuery( portraitMediaQuery )","import { useCallback, useEffect, useRef, useState } from 'react'\n\ntype SetFocusTrap = ( target?: HTMLElement ) => void\ntype RestoreFocusTrap = () => void\n\nconst focusableSelector = [\n\t'input', 'select', 'textarea',\n\t'button', '[href]', '[tabindex]:not([tabindex=\"-1\"])',\n].join( ', ' )\n\n\n/**\n * Trap focus inside the given HTML Element.\n * \n * @param target (Optional) The target HTMLElement React RefObject to trap focus within.\n * \t\t\t\t\tIf no target is given, you must provide the target HTMLElement when calling `setFocusTrap`.\n * \n * @returns A tuple containing:\n * - `setFocusTrap`: A function to enable the focus trap. Optionally accept an HTMLElement as target.\n * - `restoreFocusTrap`: A function to restore the previous focus state.\n */\nexport const useFocusTrap = (\n\ttarget?: React.RefObject<HTMLElement | null>\n): readonly [ SetFocusTrap, RestoreFocusTrap ] => {\n\n\tconst [ focusTrap, setFocusTrapDispatch ] = (\n\t\tuseState<HTMLElement | false>( false )\n\t)\n\n\tconst lastActiveElement = useRef<HTMLElement>( null )\n\t\n\t/**\n\t * Enable the focus trap.\n\t * \n\t */\n\tconst setFocusTrap = useCallback<SetFocusTrap>( onDemandTarget => {\n\n\t\tlastActiveElement.current\t= document.activeElement as HTMLElement\n\t\tconst focusTrap\t\t\t\t= onDemandTarget || target?.current || false\n\t\t\n\t\tif ( ! focusTrap ) return\n\n\t\treturn setFocusTrapDispatch( focusTrap )\n\t\n\t}, [ target ] )\n\n\n\t/**\n\t * Restore the focus to the latest Document active Element.\n\t */\n\tconst restoreFocusTrap = useCallback<RestoreFocusTrap>( () => {\n\n\t\tlastActiveElement.current?.focus()\n\t\tsetFocusTrapDispatch( false )\n\t\n\t}, [] )\n\n\t\n\tuseEffect( () => {\n\n\t\tif ( ! focusTrap ) return\n\n\t\tconst keyDownHandler = ( event: KeyboardEvent ) => {\n\n\t\t\tif ( event.key !== 'Tab' ) return\n\n\t\t\tconst focusableElements\t\t= Array.from( focusTrap.querySelectorAll<HTMLElement>( focusableSelector ) ),\n\t\t\t\tfirstFocusableElement\t= focusableElements.at( 0 ),\n\t\t\t\tlastFocusableElement\t= focusableElements.at( -1 );\n\n\t\t\tif ( ! event.shiftKey ) {\n\t\t\t\t/**\n\t\t\t\t * Focust the firs element if\n\t\t\t\t * focusing forward and the current focused element is the last one.\n\t\t\t\t */\n\t\t\t\tif ( document.activeElement === lastFocusableElement ) {\n\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\tfirstFocusableElement?.focus()\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\n\n\t\t\t/**\n\t\t\t * Focus the last focusable element if\n\t\t\t * focusing backward and the current focused element is the first one.\n\t\t\t * \n\t\t\t */\n\t\t\tif ( document.activeElement === firstFocusableElement ) {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tlastFocusableElement?.focus()\n\t\t\t}\n\n\t\t}\n\n\t\tdocument.addEventListener( 'keydown', keyDownHandler );\n\t\n\t\treturn () => {\n\t\t\tdocument.removeEventListener( 'keydown', keyDownHandler );\n\t\t}\n\n\t}, [ focusTrap ] )\n\n\treturn [ setFocusTrap, restoreFocusTrap ]\n\n}","import { useCallback } from 'react'\nimport {\n\tblockScroll as blockScrollHandler,\n\trestoreScroll as restoreScrollHandler\n} from '@alessiofrittoli/web-utils/dom'\n\n\n/**\n * Prevent Element overflow.\n * \n * @param target (Optional) The React RefObject target HTMLElement. Default: `Document.documentElement`.\n */\nexport const useScrollBlock = ( target?: React.RefObject<HTMLElement | null> ) => {\n\t\n\t/**\n\t * Block scroll.\n\t * \n\t */\n\tconst blockScroll = useCallback(\n\t\t() => blockScrollHandler( target?.current || undefined ), [ target ]\n\t)\n\n\n\t/**\n\t * Restore scroll.\n\t * \n\t */\n\tconst restoreScroll = useCallback(\n\t\t() => restoreScrollHandler( target?.current || undefined ), [ target ]\n\t)\n\n\t\n\treturn [ blockScroll, restoreScroll ] as const\n\n}","import { useEffect, useState } from 'react'\n\n/**\n * Check if the React Hook or Component where this hook is executed is running in a browser environment.\n * \n * @returns `true` if the React Hook or Component is running in a browser environment, `false` otherwise.\n */\nexport const useIsClient = () => {\n\n\tconst [ isClient, setClient ] = useState( false )\n\n\tuseEffect( () => setClient( true ), [] )\n\n\treturn isClient\n\n}","import { useRef } from 'react'\n\n/**\n * Check if is first React Hook/Component render.\n * \n * @returns `true` at the mount time, then always `false`.\n * - Note that if the React Hook/Component has no state updates, `useIsFirstRender` will always return `true`.\n */\nexport const useIsFirstRender = () => {\n\n\tconst isFirst = useRef( true )\n\n\tif ( isFirst.current ) {\n\t\tisFirst.current = false\n\n\t\treturn true\n\t}\n\n\treturn isFirst.current\n\t\n}","import { useEffect } from 'react'\nimport { useIsFirstRender } from './useIsFirstRender'\n\n\n/**\n * Modified version of `useEffect` that skips the first render.\n *\n * @param\teffect\tImperative function that can return a cleanup function.\n * @param\tdeps\tIf present, effect will only activate if the values in the list change.\n */\nexport const useUpdateEffect = (\n\teffect\t: React.EffectCallback,\n\tdeps?\t: React.DependencyList,\n) => {\n\n\tconst isFirst = useIsFirstRender()\n\n\tuseEffect( () => {\n\t\tif ( ! isFirst ) return effect()\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, deps )\n\t\n}"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/browser-api/storage/useStorage.ts","../src/browser-api/storage/useLocalStorage.ts","../src/browser-api/storage/useSessionStorage.ts","../src/browser-api/useMediaQuery.ts","../src/browser-api/useIsPortrait.ts","../src/dom-api/useFocusTrap.ts","../src/dom-api/useScrollBlock.ts","../src/misc/useIsClient.ts","../src/misc/useIsFirstRender.ts","../src/misc/useUpdateEffect.ts"],"names":["useStorage","key","initialValue","type","readValue","useCallback","LocalStorage","SessionStorage","storedValue","setStoredValue","useState","setValue","value","valueToStore","useEffect","useLocalStorage","useSessionStorage","useMediaQuery","query","matches","setMatches","getMediaMatches","matchMediaChangeHandler","matchMedia","useIsPortrait","portraitMediaQuery","focusableSelector","useFocusTrap","target","focusTrap","setFocusTrapDispatch","lastActiveElement","useRef","setFocusTrap","onDemandTarget","restoreFocusTrap","keyDownHandler","event","focusableElements","firstFocusableElement","lastFocusableElement","useScrollBlock","blockScroll","blockScrollHandler","restoreScroll","restoreScrollHandler","useIsClient","isClient","setClient","useIsFirstRender","isFirst","useUpdateEffect","effect","deps"],"mappings":"maAcO,IAAMA,CAAa,CAAA,CACzBC,CACAC,CAAAA,CAAAA,CACAC,CAA+B,CAAA,OAAA,GACO,CAEtC,IAAMC,CAAYC,CAAAA,WAAAA,CAAa,IAC5BF,CAAAA,CAAAA,GAAS,QAAUG,YAAeC,CAAAA,cAAAA,EAClC,GAAQN,CAAAA,CAAI,CAAKC,EAAAA,CAAAA,CACjB,CAAEC,CAAAA,CAAMF,CAAKC,CAAAA,CAAa,CAAE,CAAA,CAQzB,CAAEM,CAAAA,CAAaC,CAAe,CAAA,CAAIC,QAAoBR,CAAAA,CAAa,CAQnES,CAAAA,CAAAA,CAAWN,WAAiCO,CAAAA,CAAAA,EAAS,CAE1DH,CAAAA,CAAgBD,CAAe,EAAA,CAC9B,IAAMK,CAAAA,CAAeD,CAA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AA,CAAAA,GACI,CAEJ,IAAMH,CAAUD,CAAAA,CAAAA,EAEhBnC,CAAAA,SAAAA,CAAW,IAAM,CAChB,GAAK,CAAEoC,CAAU,CAAA,OAAOE,CAAO,EAEhC,CAAGC,CAAAA,CAAK,EAET","file":"index.mjs","sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { LocalStorage } from '@alessiofrittoli/web-utils/storage/LocalStorage'\nimport { SessionStorage } from '@alessiofrittoli/web-utils/storage/SessionStorage'\n\ntype Value<T>\t\t= T | undefined | null\ntype SetValue<T>\t= React.Dispatch<React.SetStateAction<T>>\n\n/**\n * Easly handle Local or Session Storage State.\n * \n * @param\tkey\t\t\t\tThe storage item key.\n * @param\tinitialValue\tThe storage item initial value.\n * @param\ttype\t\t\t( Optional ) The storage API to use. Default: `local`.\n */\nexport const useStorage = <T = string>(\n\tkey\t\t\t\t: string,\n\tinitialValue?\t: T,\n\ttype\t\t\t: 'local' | 'session' = 'local'\n): [ Value<T>, SetValue<Value<T>> ] => {\n\n\tconst readValue = useCallback( () => (\n\t\t( type === 'local' ? LocalStorage : SessionStorage )\n\t\t\t.get<T>( key ) ?? initialValue\n\t), [ type, key, initialValue ] )\n\n\n\t/**\n\t * State to store our value.\n\t * Pass initial state function to useState so logic is only executed once.\n\t * \n\t */\n\tconst [ storedValue, setStoredValue ] = useState<Value<T>>( initialValue )\n\n\t/**\n\t * Return a wrapped version of useState's setter function that\n\t * persists the new value to localStorage | sessionStorage.\n\t * \n\t * @param value The SetStateAction value.\n\t */\n\tconst setValue = useCallback<SetValue<Value<T>>>( value => {\n\n\t\tsetStoredValue( storedValue => {\n\t\t\tconst valueToStore = value instanceof Function ? value( storedValue ) : value\n\t\n\t\t\t;(\n\t\t\t\ttypeof window !== 'undefined' &&\n\t\t\t\ttype === 'local' ? LocalStorage : SessionStorage\n\t\t\t).set( key, valueToStore )\n\n\t\t\treturn valueToStore\n\t\t} )\n\n\n\t}, [ type, key ] )\n\n\tuseEffect( () => {\n\t\tsetStoredValue( readValue() )\n\t}, [ readValue ] )\n\n\treturn [ storedValue, setValue ]\n}","import { useStorage } from './useStorage'\n\n/**\n * useLocalStorage hook.\n * \n * @param\tkey\t\t\t\tThe local storage item key.\n * @param\tinitialValue\tThe local storage item initial value.\n */\nexport const useLocalStorage = <T = string>(\n\tkey\t\t\t\t: string,\n\tinitialValue?\t: T\n) => useStorage( key, initialValue, 'local' )","import { useStorage } from './useStorage'\n\n/**\n * useSessionStorage hook.\n * \n * @param\tkey\t\t\t\tThe session item key.\n * @param\tinitialValue\tThe session item initial value.\n */\nexport const useSessionStorage = <T = string>(\n\tkey\t\t\t\t: string,\n\tinitialValue?\t: T\n) => useStorage( key, initialValue, 'session' )","import { useCallback, useEffect, useState } from 'react'\nimport { getMediaMatches } from '@alessiofrittoli/web-utils/browser-api'\n\n\n/**\n * Get Document Media matches and listen for changes.\n *\n * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia)\n *\n * @param\tquery A string specifying the media query to parse into a `MediaQueryList`.\n * @returns\tA boolean value that returns `true` if the document currently matches the media query list, or `false` if not.\n */\nexport const useMediaQuery = ( query: string ) => {\n\n\tconst [ matches, setMatches ]\t= useState( getMediaMatches( query ) )\n\tconst matchMediaChangeHandler\t= useCallback( () => setMatches( getMediaMatches( query ) ), [ query ] )\n\n\n\tuseEffect( () => {\n\n\t\tconst matchMedia = window.matchMedia( query )\n\t\t// Triggered at the first client-side load\n\t\tmatchMediaChangeHandler()\n\t\t// Listen matchMedia\n\t\tmatchMedia.addEventListener( 'change', matchMediaChangeHandler )\n\n\t\treturn () => {\n\t\t\tmatchMedia.removeEventListener( 'change', matchMediaChangeHandler )\n\t\t}\n\n\t}, [ query, matchMediaChangeHandler ] )\n\n\treturn matches\n\t\n}","import { useMediaQuery } from './useMediaQuery'\nimport { portraitMediaQuery } from '@alessiofrittoli/web-utils/device'\n\n/**\n * Check if device is portrait oriented.\n * \n * State get updated when device orientation changes.\n *\n * @returns\t`true` if the device is portrait oriented, `false` otherwise.\n */\nexport const useIsPortrait = () => useMediaQuery( portraitMediaQuery )","import { useCallback, useEffect, useRef, useState } from 'react'\n\ntype SetFocusTrap = ( target?: HTMLElement ) => void\ntype RestoreFocusTrap = () => void\n\nconst focusableSelector = [\n\t'input', 'select', 'textarea',\n\t'button', '[href]', '[tabindex]:not([tabindex=\"-1\"])',\n].join( ', ' )\n\n\n/**\n * Trap focus inside the given HTML Element.\n * \n * @param target (Optional) The target HTMLElement React RefObject to trap focus within.\n * \t\t\t\t\tIf no target is given, you must provide the target HTMLElement when calling `setFocusTrap`.\n * \n * @returns A tuple containing:\n * - `setFocusTrap`: A function to enable the focus trap. Optionally accept an HTMLElement as target.\n * - `restoreFocusTrap`: A function to restore the previous focus state.\n */\nexport const useFocusTrap = (\n\ttarget?: React.RefObject<HTMLElement | null>\n): readonly [ SetFocusTrap, RestoreFocusTrap ] => {\n\n\tconst [ focusTrap, setFocusTrapDispatch ] = (\n\t\tuseState<HTMLElement | false>( false )\n\t)\n\n\tconst lastActiveElement = useRef<HTMLElement>( null )\n\t\n\t/**\n\t * Enable the focus trap.\n\t * \n\t */\n\tconst setFocusTrap = useCallback<SetFocusTrap>( onDemandTarget => {\n\n\t\tlastActiveElement.current\t= document.activeElement as HTMLElement\n\t\tconst focusTrap\t\t\t\t= onDemandTarget || target?.current || false\n\t\t\n\t\tif ( ! focusTrap ) return\n\n\t\treturn setFocusTrapDispatch( focusTrap )\n\t\n\t}, [ target ] )\n\n\n\t/**\n\t * Restore the focus to the latest Document active Element.\n\t */\n\tconst restoreFocusTrap = useCallback<RestoreFocusTrap>( () => {\n\n\t\tlastActiveElement.current?.focus()\n\t\tsetFocusTrapDispatch( false )\n\t\n\t}, [] )\n\n\t\n\tuseEffect( () => {\n\n\t\tif ( ! focusTrap ) return\n\n\t\tconst keyDownHandler = ( event: KeyboardEvent ) => {\n\n\t\t\tif ( event.key !== 'Tab' ) return\n\n\t\t\tconst focusableElements\t\t= Array.from( focusTrap.querySelectorAll<HTMLElement>( focusableSelector ) ),\n\t\t\t\tfirstFocusableElement\t= focusableElements.at( 0 ),\n\t\t\t\tlastFocusableElement\t= focusableElements.at( -1 );\n\n\t\t\tif ( ! event.shiftKey ) {\n\t\t\t\t/**\n\t\t\t\t * Focust the firs element if\n\t\t\t\t * focusing forward and the current focused element is the last one.\n\t\t\t\t */\n\t\t\t\tif ( document.activeElement === lastFocusableElement ) {\n\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\tfirstFocusableElement?.focus()\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\n\n\t\t\t/**\n\t\t\t * Focus the last focusable element if\n\t\t\t * focusing backward and the current focused element is the first one.\n\t\t\t * \n\t\t\t */\n\t\t\tif ( document.activeElement === firstFocusableElement ) {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tlastFocusableElement?.focus()\n\t\t\t}\n\n\t\t}\n\n\t\tdocument.addEventListener( 'keydown', keyDownHandler );\n\t\n\t\treturn () => {\n\t\t\tdocument.removeEventListener( 'keydown', keyDownHandler );\n\t\t}\n\n\t}, [ focusTrap ] )\n\n\treturn [ setFocusTrap, restoreFocusTrap ]\n\n}","import { useCallback } from 'react'\nimport {\n\tblockScroll as blockScrollHandler,\n\trestoreScroll as restoreScrollHandler\n} from '@alessiofrittoli/web-utils/dom'\n\n\n/**\n * Prevent Element overflow.\n * \n * @param target (Optional) The React RefObject target HTMLElement. Default: `Document.documentElement`.\n */\nexport const useScrollBlock = ( target?: React.RefObject<HTMLElement | null> ) => {\n\t\n\t/**\n\t * Block scroll.\n\t * \n\t */\n\tconst blockScroll = useCallback(\n\t\t() => blockScrollHandler( target?.current || undefined ), [ target ]\n\t)\n\n\n\t/**\n\t * Restore scroll.\n\t * \n\t */\n\tconst restoreScroll = useCallback(\n\t\t() => restoreScrollHandler( target?.current || undefined ), [ target ]\n\t)\n\n\t\n\treturn [ blockScroll, restoreScroll ] as const\n\n}","import { useEffect, useState } from 'react'\n\n/**\n * Check if the React Hook or Component where this hook is executed is running in a browser environment.\n * \n * @returns `true` if the React Hook or Component is running in a browser environment, `false` otherwise.\n */\nexport const useIsClient = () => {\n\n\tconst [ isClient, setClient ] = useState( false )\n\n\tuseEffect( () => setClient( true ), [] )\n\n\treturn isClient\n\n}","import { useRef } from 'react'\n\n/**\n * Check if is first React Hook/Component render.\n * \n * @returns `true` at the mount time, then always `false`.\n * - Note that if the React Hook/Component has no state updates, `useIsFirstRender` will always return `true`.\n */\nexport const useIsFirstRender = () => {\n\n\tconst isFirst = useRef( true )\n\n\tif ( isFirst.current ) {\n\t\tisFirst.current = false\n\n\t\treturn true\n\t}\n\n\treturn isFirst.current\n\t\n}","import { useEffect } from 'react'\nimport { useIsFirstRender } from './useIsFirstRender'\n\n\n/**\n * Modified version of `useEffect` that skips the first render.\n *\n * @param\teffect\tImperative function that can return a cleanup function.\n * @param\tdeps\tIf present, effect will only activate if the values in the list change.\n */\nexport const useUpdateEffect = (\n\teffect\t: React.EffectCallback,\n\tdeps?\t: React.DependencyList,\n) => {\n\n\tconst isFirst = useIsFirstRender()\n\n\tuseEffect( () => {\n\t\tif ( ! isFirst ) return effect()\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, deps )\n\t\n}"]}
@@ -1,3 +0,0 @@
1
- export { useIsClient } from './useIsClient.mjs';
2
- export { useIsFirstRender } from './useIsFirstRender.mjs';
3
- export { useUpdateEffect } from './useUpdateEffect.mjs';
@@ -1,3 +0,0 @@
1
- export { useIsClient } from './useIsClient.js';
2
- export { useIsFirstRender } from './useIsFirstRender.js';
3
- export { useUpdateEffect } from './useUpdateEffect.js';
@@ -1,2 +0,0 @@
1
- 'use strict';var react=require('react');var p=()=>{let[e,t]=react.useState(false);return react.useEffect(()=>t(true),[]),e};var s=()=>{let e=react.useRef(true);return e.current?(e.current=false,true):e.current};var E=(e,t)=>{let o=s();react.useEffect(()=>{if(!o)return e()},t);};exports.useIsClient=p;exports.useIsFirstRender=s;exports.useUpdateEffect=E;//# sourceMappingURL=index.js.map
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/misc/useIsClient.ts","../../src/misc/useIsFirstRender.ts","../../src/misc/useUpdateEffect.ts"],"names":["useIsClient","isClient","setClient","useState","useEffect","useIsFirstRender","isFirst","useRef","useUpdateEffect","effect","deps"],"mappings":"4CAOaA,CAAc,CAAA,IAAM,CAEhC,GAAM,CAAEC,CAAUC,CAAAA,CAAU,CAAIC,CAAAA,cAAAA,CAAU,KAAM,CAEhD,CAAA,OAAAC,eAAW,CAAA,IAAMF,EAAW,IAAK,CAAA,CAAG,EAAG,EAEhCD,CAER,ECPO,IAAMI,CAAmB,CAAA,IAAM,CAErC,IAAMC,CAAAA,CAAUC,YAAQ,CAAA,IAAK,EAE7B,OAAKD,CAAAA,CAAQ,OACZA,EAAAA,CAAAA,CAAQ,QAAU,KAEX,CAAA,IAAA,EAGDA,CAAQ,CAAA,OAEhB,MCVaE,CAAkB,CAAA,CAC9BC,CACAC,CAAAA,CAAAA,GACI,CAEJ,IAAMJ,CAAAA,CAAUD,CAAiB,EAAA,CAEjCD,gBAAW,IAAM,CAChB,GAAK,CAAEE,EAAU,OAAOG,CAAAA,EAEzB,CAAA,CAAGC,CAAK,EAET","file":"index.js","sourcesContent":["import { useEffect, useState } from 'react'\n\n/**\n * Check if the React Hook or Component where this hook is executed is running in a browser environment.\n * \n * @returns `true` if the React Hook or Component is running in a browser environment, `false` otherwise.\n */\nexport const useIsClient = () => {\n\n\tconst [ isClient, setClient ] = useState( false )\n\n\tuseEffect( () => setClient( true ), [] )\n\n\treturn isClient\n\n}","import { useRef } from 'react'\n\n/**\n * Check if is first React Hook/Component render.\n * \n * @returns `true` at the mount time, then always `false`.\n * - Note that if the React Hook/Component has no state updates, `useIsFirstRender` will always return `true`.\n */\nexport const useIsFirstRender = () => {\n\n\tconst isFirst = useRef( true )\n\n\tif ( isFirst.current ) {\n\t\tisFirst.current = false\n\n\t\treturn true\n\t}\n\n\treturn isFirst.current\n\t\n}","import { useEffect } from 'react'\nimport { useIsFirstRender } from './useIsFirstRender'\n\n\n/**\n * Modified version of `useEffect` that skips the first render.\n *\n * @param\teffect\tImperative function that can return a cleanup function.\n * @param\tdeps\tIf present, effect will only activate if the values in the list change.\n */\nexport const useUpdateEffect = (\n\teffect\t: React.EffectCallback,\n\tdeps?\t: React.DependencyList,\n) => {\n\n\tconst isFirst = useIsFirstRender()\n\n\tuseEffect( () => {\n\t\tif ( ! isFirst ) return effect()\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, deps )\n\t\n}"]}
@@ -1,2 +0,0 @@
1
- import {useState,useEffect,useRef}from'react';var m=()=>{let[e,t]=useState(false);return useEffect(()=>t(true),[]),e};var o=()=>{let e=useRef(true);return e.current?(e.current=false,true):e.current};var F=(e,t)=>{let f=o();useEffect(()=>{if(!f)return e()},t);};export{m as useIsClient,o as useIsFirstRender,F as useUpdateEffect};//# sourceMappingURL=index.mjs.map
2
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/misc/useIsClient.ts","../../src/misc/useIsFirstRender.ts","../../src/misc/useUpdateEffect.ts"],"names":["useIsClient","isClient","setClient","useState","useEffect","useIsFirstRender","isFirst","useRef","useUpdateEffect","effect","deps"],"mappings":"kDAOaA,CAAc,CAAA,IAAM,CAEhC,GAAM,CAAEC,CAAUC,CAAAA,CAAU,CAAIC,CAAAA,QAAAA,CAAU,KAAM,CAEhD,CAAA,OAAAC,SAAW,CAAA,IAAMF,EAAW,IAAK,CAAA,CAAG,EAAG,EAEhCD,CAER,ECPO,IAAMI,CAAmB,CAAA,IAAM,CAErC,IAAMC,CAAAA,CAAUC,MAAQ,CAAA,IAAK,EAE7B,OAAKD,CAAAA,CAAQ,OACZA,EAAAA,CAAAA,CAAQ,QAAU,KAEX,CAAA,IAAA,EAGDA,CAAQ,CAAA,OAEhB,MCVaE,CAAkB,CAAA,CAC9BC,CACAC,CAAAA,CAAAA,GACI,CAEJ,IAAMJ,CAAAA,CAAUD,CAAiB,EAAA,CAEjCD,UAAW,IAAM,CAChB,GAAK,CAAEE,EAAU,OAAOG,CAAAA,EAEzB,CAAA,CAAGC,CAAK,EAET","file":"index.mjs","sourcesContent":["import { useEffect, useState } from 'react'\n\n/**\n * Check if the React Hook or Component where this hook is executed is running in a browser environment.\n * \n * @returns `true` if the React Hook or Component is running in a browser environment, `false` otherwise.\n */\nexport const useIsClient = () => {\n\n\tconst [ isClient, setClient ] = useState( false )\n\n\tuseEffect( () => setClient( true ), [] )\n\n\treturn isClient\n\n}","import { useRef } from 'react'\n\n/**\n * Check if is first React Hook/Component render.\n * \n * @returns `true` at the mount time, then always `false`.\n * - Note that if the React Hook/Component has no state updates, `useIsFirstRender` will always return `true`.\n */\nexport const useIsFirstRender = () => {\n\n\tconst isFirst = useRef( true )\n\n\tif ( isFirst.current ) {\n\t\tisFirst.current = false\n\n\t\treturn true\n\t}\n\n\treturn isFirst.current\n\t\n}","import { useEffect } from 'react'\nimport { useIsFirstRender } from './useIsFirstRender'\n\n\n/**\n * Modified version of `useEffect` that skips the first render.\n *\n * @param\teffect\tImperative function that can return a cleanup function.\n * @param\tdeps\tIf present, effect will only activate if the values in the list change.\n */\nexport const useUpdateEffect = (\n\teffect\t: React.EffectCallback,\n\tdeps?\t: React.DependencyList,\n) => {\n\n\tconst isFirst = useIsFirstRender()\n\n\tuseEffect( () => {\n\t\tif ( ! isFirst ) return effect()\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, deps )\n\t\n}"]}
@@ -1,8 +0,0 @@
1
- /**
2
- * Check if the React Hook or Component where this hook is executed is running in a browser environment.
3
- *
4
- * @returns `true` if the React Hook or Component is running in a browser environment, `false` otherwise.
5
- */
6
- declare const useIsClient: () => boolean;
7
-
8
- export { useIsClient };
@@ -1,8 +0,0 @@
1
- /**
2
- * Check if the React Hook or Component where this hook is executed is running in a browser environment.
3
- *
4
- * @returns `true` if the React Hook or Component is running in a browser environment, `false` otherwise.
5
- */
6
- declare const useIsClient: () => boolean;
7
-
8
- export { useIsClient };
@@ -1,2 +0,0 @@
1
- 'use strict';var react=require('react');var o=()=>{let[e,t]=react.useState(false);return react.useEffect(()=>t(true),[]),e};exports.useIsClient=o;//# sourceMappingURL=useIsClient.js.map
2
- //# sourceMappingURL=useIsClient.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/misc/useIsClient.ts"],"names":["useIsClient","isClient","setClient","useState","useEffect"],"mappings":"wCAOaA,IAAAA,CAAAA,CAAc,IAAM,CAEhC,GAAM,CAAEC,CAAUC,CAAAA,CAAU,EAAIC,cAAU,CAAA,KAAM,CAEhD,CAAA,OAAAC,eAAW,CAAA,IAAMF,CAAW,CAAA,IAAK,CAAG,CAAA,EAAG,CAAA,CAEhCD,CAER","file":"useIsClient.js","sourcesContent":["import { useEffect, useState } from 'react'\n\n/**\n * Check if the React Hook or Component where this hook is executed is running in a browser environment.\n * \n * @returns `true` if the React Hook or Component is running in a browser environment, `false` otherwise.\n */\nexport const useIsClient = () => {\n\n\tconst [ isClient, setClient ] = useState( false )\n\n\tuseEffect( () => setClient( true ), [] )\n\n\treturn isClient\n\n}"]}
@@ -1,2 +0,0 @@
1
- import {useState,useEffect}from'react';var u=()=>{let[e,t]=useState(false);return useEffect(()=>t(true),[]),e};export{u as useIsClient};//# sourceMappingURL=useIsClient.mjs.map
2
- //# sourceMappingURL=useIsClient.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/misc/useIsClient.ts"],"names":["useIsClient","isClient","setClient","useState","useEffect"],"mappings":"uCAOaA,IAAAA,CAAAA,CAAc,IAAM,CAEhC,GAAM,CAAEC,CAAUC,CAAAA,CAAU,EAAIC,QAAU,CAAA,KAAM,CAEhD,CAAA,OAAAC,SAAW,CAAA,IAAMF,CAAW,CAAA,IAAK,CAAG,CAAA,EAAG,CAAA,CAEhCD,CAER","file":"useIsClient.mjs","sourcesContent":["import { useEffect, useState } from 'react'\n\n/**\n * Check if the React Hook or Component where this hook is executed is running in a browser environment.\n * \n * @returns `true` if the React Hook or Component is running in a browser environment, `false` otherwise.\n */\nexport const useIsClient = () => {\n\n\tconst [ isClient, setClient ] = useState( false )\n\n\tuseEffect( () => setClient( true ), [] )\n\n\treturn isClient\n\n}"]}
@@ -1,9 +0,0 @@
1
- /**
2
- * Check if is first React Hook/Component render.
3
- *
4
- * @returns `true` at the mount time, then always `false`.
5
- * - Note that if the React Hook/Component has no state updates, `useIsFirstRender` will always return `true`.
6
- */
7
- declare const useIsFirstRender: () => boolean;
8
-
9
- export { useIsFirstRender };
@@ -1,9 +0,0 @@
1
- /**
2
- * Check if is first React Hook/Component render.
3
- *
4
- * @returns `true` at the mount time, then always `false`.
5
- * - Note that if the React Hook/Component has no state updates, `useIsFirstRender` will always return `true`.
6
- */
7
- declare const useIsFirstRender: () => boolean;
8
-
9
- export { useIsFirstRender };
@@ -1,2 +0,0 @@
1
- 'use strict';var react=require('react');var u=()=>{let r=react.useRef(true);return r.current?(r.current=false,true):r.current};exports.useIsFirstRender=u;//# sourceMappingURL=useIsFirstRender.js.map
2
- //# sourceMappingURL=useIsFirstRender.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/misc/useIsFirstRender.ts"],"names":["useIsFirstRender","isFirst","useRef"],"mappings":"wCAQO,IAAMA,EAAmB,IAAM,CAErC,IAAMC,CAAUC,CAAAA,YAAAA,CAAQ,IAAK,CAE7B,CAAA,OAAKD,EAAQ,OACZA,EAAAA,CAAAA,CAAQ,QAAU,KAEX,CAAA,IAAA,EAGDA,EAAQ,OAEhB","file":"useIsFirstRender.js","sourcesContent":["import { useRef } from 'react'\n\n/**\n * Check if is first React Hook/Component render.\n * \n * @returns `true` at the mount time, then always `false`.\n * - Note that if the React Hook/Component has no state updates, `useIsFirstRender` will always return `true`.\n */\nexport const useIsFirstRender = () => {\n\n\tconst isFirst = useRef( true )\n\n\tif ( isFirst.current ) {\n\t\tisFirst.current = false\n\n\t\treturn true\n\t}\n\n\treturn isFirst.current\n\t\n}"]}
@@ -1,2 +0,0 @@
1
- import {useRef}from'react';var n=()=>{let r=useRef(true);return r.current?(r.current=false,true):r.current};export{n as useIsFirstRender};//# sourceMappingURL=useIsFirstRender.mjs.map
2
- //# sourceMappingURL=useIsFirstRender.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/misc/useIsFirstRender.ts"],"names":["useIsFirstRender","isFirst","useRef"],"mappings":"2BAQO,IAAMA,EAAmB,IAAM,CAErC,IAAMC,CAAUC,CAAAA,MAAAA,CAAQ,IAAK,CAE7B,CAAA,OAAKD,EAAQ,OACZA,EAAAA,CAAAA,CAAQ,QAAU,KAEX,CAAA,IAAA,EAGDA,EAAQ,OAEhB","file":"useIsFirstRender.mjs","sourcesContent":["import { useRef } from 'react'\n\n/**\n * Check if is first React Hook/Component render.\n * \n * @returns `true` at the mount time, then always `false`.\n * - Note that if the React Hook/Component has no state updates, `useIsFirstRender` will always return `true`.\n */\nexport const useIsFirstRender = () => {\n\n\tconst isFirst = useRef( true )\n\n\tif ( isFirst.current ) {\n\t\tisFirst.current = false\n\n\t\treturn true\n\t}\n\n\treturn isFirst.current\n\t\n}"]}
@@ -1,12 +0,0 @@
1
- import * as _alessiofrittoli_math_utils_helpers from '@alessiofrittoli/math-utils/helpers';
2
- import { PaginateOptions } from '@alessiofrittoli/math-utils/helpers';
3
-
4
- /**
5
- * Get pagination informations based on the given options.
6
- *
7
- * @param options An object defining pagination input data. See {@link PaginateOptions} for more information.
8
- * @returns A memoized object containing pagination informations based on the given options.
9
- */
10
- declare const usePagination: (options?: PaginateOptions) => _alessiofrittoli_math_utils_helpers.Pagination;
11
-
12
- export { usePagination };
@@ -1,12 +0,0 @@
1
- import * as _alessiofrittoli_math_utils_helpers from '@alessiofrittoli/math-utils/helpers';
2
- import { PaginateOptions } from '@alessiofrittoli/math-utils/helpers';
3
-
4
- /**
5
- * Get pagination informations based on the given options.
6
- *
7
- * @param options An object defining pagination input data. See {@link PaginateOptions} for more information.
8
- * @returns A memoized object containing pagination informations based on the given options.
9
- */
10
- declare const usePagination: (options?: PaginateOptions) => _alessiofrittoli_math_utils_helpers.Pagination;
11
-
12
- export { usePagination };