@alessiofrittoli/react-hooks 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser-api/index.js +1 -2
- package/dist/browser-api/index.mjs +1 -2
- package/dist/browser-api/storage/index.js +1 -2
- package/dist/browser-api/storage/index.mjs +1 -2
- package/dist/browser-api/storage/useLocalStorage.js +1 -2
- package/dist/browser-api/storage/useLocalStorage.mjs +1 -2
- package/dist/browser-api/storage/useSessionStorage.js +1 -2
- package/dist/browser-api/storage/useSessionStorage.mjs +1 -2
- package/dist/browser-api/storage/useStorage.js +1 -2
- package/dist/browser-api/storage/useStorage.mjs +1 -2
- package/dist/browser-api/useIsPortrait.js +1 -2
- package/dist/browser-api/useIsPortrait.mjs +1 -2
- package/dist/browser-api/useMediaQuery.js +1 -2
- package/dist/browser-api/useMediaQuery.mjs +1 -2
- package/dist/chunk-26XSIIUK.mjs +1 -0
- package/dist/chunk-2CZNCZFR.mjs +0 -0
- package/dist/chunk-43RVMR6S.mjs +1 -0
- package/dist/chunk-4BGMCO3F.js +1 -0
- package/dist/chunk-65SF33P4.mjs +1 -0
- package/dist/chunk-6BSD56XC.js +1 -0
- package/dist/chunk-6IRIG5HU.mjs +1 -0
- package/dist/chunk-7ILYMOVB.js +1 -0
- package/dist/chunk-AJKPRTOJ.mjs +1 -0
- package/dist/chunk-EFFJB2GR.js +1 -0
- package/dist/chunk-FUCUVFLW.js +1 -0
- package/dist/chunk-G55NP3QG.js +1 -0
- package/dist/chunk-HO57SPST.js +1 -0
- package/dist/chunk-HZLWSH3W.mjs +1 -0
- package/dist/chunk-IDNLFWFO.js +1 -0
- package/dist/chunk-RENUP2VU.mjs +1 -0
- package/dist/chunk-SNMJ53QB.js +1 -0
- package/dist/chunk-SW7BCMZF.js +1 -0
- package/dist/chunk-TA6PCHH4.js +1 -0
- package/dist/chunk-UAJXVBNR.mjs +1 -0
- package/dist/chunk-UXNKH2MC.mjs +1 -0
- package/dist/chunk-VLSP3MAN.js +1 -0
- package/dist/chunk-WLIFJNZA.mjs +0 -0
- package/dist/chunk-WOVEE75M.js +1 -0
- package/dist/chunk-YAZXPL6I.mjs +1 -0
- package/dist/chunk-YLUTFORB.js +1 -0
- package/dist/chunk-YQO25XKN.mjs +0 -0
- package/dist/chunk-ZNAB4TYW.mjs +0 -0
- package/dist/dom-api/index.js +1 -2
- package/dist/dom-api/index.mjs +1 -2
- package/dist/dom-api/useFocusTrap.js +1 -2
- package/dist/dom-api/useFocusTrap.mjs +1 -2
- package/dist/dom-api/useScrollBlock.js +1 -2
- package/dist/dom-api/useScrollBlock.mjs +1 -2
- package/dist/eslint.js +1 -2
- package/dist/eslint.mjs +1 -2
- package/dist/index.js +1 -2
- package/dist/index.mjs +1 -2
- package/dist/misc/index.js +1 -2
- package/dist/misc/index.mjs +1 -2
- package/dist/misc/useIsClient.js +1 -2
- package/dist/misc/useIsClient.mjs +1 -2
- package/dist/misc/useIsFirstRender.js +1 -2
- package/dist/misc/useIsFirstRender.mjs +1 -2
- package/dist/misc/usePagination.js +1 -2
- package/dist/misc/usePagination.mjs +1 -2
- package/dist/misc/useUpdateEffect.js +1 -2
- package/dist/misc/useUpdateEffect.mjs +1 -2
- package/package.json +15 -14
- package/dist/browser-api/index.js.map +0 -1
- package/dist/browser-api/index.mjs.map +0 -1
- package/dist/browser-api/storage/index.js.map +0 -1
- package/dist/browser-api/storage/index.mjs.map +0 -1
- package/dist/browser-api/storage/useLocalStorage.js.map +0 -1
- package/dist/browser-api/storage/useLocalStorage.mjs.map +0 -1
- package/dist/browser-api/storage/useSessionStorage.js.map +0 -1
- package/dist/browser-api/storage/useSessionStorage.mjs.map +0 -1
- package/dist/browser-api/storage/useStorage.js.map +0 -1
- package/dist/browser-api/storage/useStorage.mjs.map +0 -1
- package/dist/browser-api/useIsPortrait.js.map +0 -1
- package/dist/browser-api/useIsPortrait.mjs.map +0 -1
- package/dist/browser-api/useMediaQuery.js.map +0 -1
- package/dist/browser-api/useMediaQuery.mjs.map +0 -1
- package/dist/dom-api/index.js.map +0 -1
- package/dist/dom-api/index.mjs.map +0 -1
- package/dist/dom-api/useFocusTrap.js.map +0 -1
- package/dist/dom-api/useFocusTrap.mjs.map +0 -1
- package/dist/dom-api/useScrollBlock.js.map +0 -1
- package/dist/dom-api/useScrollBlock.mjs.map +0 -1
- package/dist/eslint.js.map +0 -1
- package/dist/eslint.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/misc/index.js.map +0 -1
- package/dist/misc/index.mjs.map +0 -1
- package/dist/misc/useIsClient.js.map +0 -1
- package/dist/misc/useIsClient.mjs.map +0 -1
- package/dist/misc/useIsFirstRender.js.map +0 -1
- package/dist/misc/useIsFirstRender.mjs.map +0 -1
- package/dist/misc/usePagination.js.map +0 -1
- package/dist/misc/usePagination.mjs.map +0 -1
- package/dist/misc/useUpdateEffect.js.map +0 -1
- package/dist/misc/useUpdateEffect.mjs.map +0 -1
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-TA6PCHH4.js');require('../chunk-4BGMCO3F.js');var _chunkIDNLFWFOjs = require('../chunk-IDNLFWFO.js');var _chunkG55NP3QGjs = require('../chunk-G55NP3QG.js');var _chunk7ILYMOVBjs = require('../chunk-7ILYMOVB.js');var _chunkWOVEE75Mjs = require('../chunk-WOVEE75M.js');var _chunkFUCUVFLWjs = require('../chunk-FUCUVFLW.js');exports.useIsPortrait = _chunkWOVEE75Mjs.a; exports.useLocalStorage = _chunkIDNLFWFOjs.a; exports.useMediaQuery = _chunkFUCUVFLWjs.a; exports.useSessionStorage = _chunkG55NP3QGjs.a; exports.useStorage = _chunk7ILYMOVBjs.a;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import"../chunk-YQO25XKN.mjs";import"../chunk-2CZNCZFR.mjs";import{a as b}from"../chunk-YAZXPL6I.mjs";import{a as c}from"../chunk-UXNKH2MC.mjs";import{a}from"../chunk-HZLWSH3W.mjs";import{a as e}from"../chunk-RENUP2VU.mjs";import{a as d}from"../chunk-AJKPRTOJ.mjs";export{e as useIsPortrait,b as useLocalStorage,d as useMediaQuery,c as useSessionStorage,a as useStorage};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../../chunk-4BGMCO3F.js');var _chunkIDNLFWFOjs = require('../../chunk-IDNLFWFO.js');var _chunkG55NP3QGjs = require('../../chunk-G55NP3QG.js');var _chunk7ILYMOVBjs = require('../../chunk-7ILYMOVB.js');exports.useLocalStorage = _chunkIDNLFWFOjs.a; exports.useSessionStorage = _chunkG55NP3QGjs.a; exports.useStorage = _chunk7ILYMOVBjs.a;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import"../../chunk-2CZNCZFR.mjs";import{a as b}from"../../chunk-YAZXPL6I.mjs";import{a as c}from"../../chunk-UXNKH2MC.mjs";import{a}from"../../chunk-HZLWSH3W.mjs";export{b as useLocalStorage,c as useSessionStorage,a as useStorage};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=useLocalStorage.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkIDNLFWFOjs = require('../../chunk-IDNLFWFO.js');require('../../chunk-7ILYMOVB.js');exports.useLocalStorage = _chunkIDNLFWFOjs.a;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//# sourceMappingURL=useLocalStorage.mjs.map
|
|
1
|
+
import{a}from"../../chunk-YAZXPL6I.mjs";import"../../chunk-HZLWSH3W.mjs";export{a as useLocalStorage};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=useSessionStorage.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkG55NP3QGjs = require('../../chunk-G55NP3QG.js');require('../../chunk-7ILYMOVB.js');exports.useSessionStorage = _chunkG55NP3QGjs.a;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//# sourceMappingURL=useSessionStorage.mjs.map
|
|
1
|
+
import{a}from"../../chunk-UXNKH2MC.mjs";import"../../chunk-HZLWSH3W.mjs";export{a as useSessionStorage};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=useStorage.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk7ILYMOVBjs = require('../../chunk-7ILYMOVB.js');exports.useStorage = _chunk7ILYMOVBjs.a;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//# sourceMappingURL=useStorage.mjs.map
|
|
1
|
+
import{a}from"../../chunk-HZLWSH3W.mjs";export{a as useStorage};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=useIsPortrait.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkWOVEE75Mjs = require('../chunk-WOVEE75M.js');require('../chunk-FUCUVFLW.js');exports.useIsPortrait = _chunkWOVEE75Mjs.a;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//# sourceMappingURL=useIsPortrait.mjs.map
|
|
1
|
+
import{a}from"../chunk-RENUP2VU.mjs";import"../chunk-AJKPRTOJ.mjs";export{a as useIsPortrait};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=useMediaQuery.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkFUCUVFLWjs = require('../chunk-FUCUVFLW.js');exports.useMediaQuery = _chunkFUCUVFLWjs.a;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//# sourceMappingURL=useMediaQuery.mjs.map
|
|
1
|
+
import{a}from"../chunk-AJKPRTOJ.mjs";export{a as useMediaQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useRef as e}from"react";var n=()=>{let r=e(!0);return r.current?(r.current=!1,!0):r.current};export{n as a};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useCallback as o}from"react";import{blockScroll as e,restoreScroll as n}from"@alessiofrittoli/web-utils/dom";var d=l=>{let r=o(()=>e(l?.current||void 0),[l]),c=o(()=>n(l?.current||void 0),[l]);return[r,c]};export{d as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useEffect as s,useState as n}from"react";var u=()=>{let[e,t]=n(!1);return s(()=>t(!0),[]),e};export{u as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useCallback as l,useEffect as m,useRef as p,useState as T}from"react";var E=["input","select","textarea","button","[href]",'[tabindex]:not([tabindex="-1"])'].join(", "),y=n=>{let[r,o]=T(!1),s=p(null),f=l(t=>{s.current=document.activeElement;let e=t||n?.current||!1;if(e)return o(e)},[n]),i=l(()=>{s.current?.focus(),o(!1)},[]);return m(()=>{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 a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _react = require('react');var _LocalStorage = require('@alessiofrittoli/web-utils/storage/LocalStorage');var _SessionStorage = require('@alessiofrittoli/web-utils/storage/SessionStorage');var w=(e,o,t="local")=>{let s=_react.useCallback.call(void 0, ()=>_nullishCoalesce((t==="local"?_LocalStorage.LocalStorage:_SessionStorage.SessionStorage).get(e), () => (o)),[t,e,o]),[S,l]=_react.useState.call(void 0, o),T=_react.useCallback.call(void 0, 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.call(void 0, ()=>{l(s())},[s]),[S,T]};exports.a = w;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useCallback as i,useEffect as o,useState as r}from"react";import{getMediaMatches as n}from"@alessiofrittoli/web-utils/browser-api";var g=e=>{let[s,c]=r(n(e)),t=i(()=>c(n(e)),[e]);return o(()=>{let a=window.matchMedia(e);return t(),a.addEventListener("change",t),()=>{a.removeEventListener("change",t)}},[e,t]),s};export{g as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkHO57SPSTjs = require('./chunk-HO57SPST.js');var _react = require('react');var n=(t,r)=>{let s=_chunkHO57SPSTjs.a.call(void 0, );_react.useEffect.call(void 0, ()=>{if(!s)return t()},r)};exports.a = n;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _react = require('react');var _browserapi = require('@alessiofrittoli/web-utils/browser-api');var M=e=>{let[s,c]=_react.useState.call(void 0, _browserapi.getMediaMatches.call(void 0, e)),t=_react.useCallback.call(void 0, ()=>c(_browserapi.getMediaMatches.call(void 0, e)),[e]);return _react.useEffect.call(void 0, ()=>{let a=window.matchMedia(e);return t(),a.addEventListener("change",t),()=>{a.removeEventListener("change",t)}},[e,t]),s};exports.a = M;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk7ILYMOVBjs = require('./chunk-7ILYMOVB.js');var i=(o,e)=>_chunk7ILYMOVBjs.a.call(void 0, o,e,"session");exports.a = i;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _react = require('react');var u=()=>{let r=_react.useRef.call(void 0, !0);return r.current?(r.current=!1,!0):r.current};exports.a = u;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useCallback as r,useEffect as f,useState as d}from"react";import{LocalStorage as u}from"@alessiofrittoli/web-utils/storage/LocalStorage";import{SessionStorage as c}from"@alessiofrittoli/web-utils/storage/SessionStorage";var R=(e,o,t="local")=>{let s=r(()=>(t==="local"?u:c).get(e)??o,[t,e,o]),[S,l]=d(o),T=r(a=>{l(V=>{let n=a instanceof Function?a(V):a;return(typeof window<"u"&&t==="local"?u:c).set(e,n),n})},[t,e]);return f(()=>{l(s())},[s]),[S,T]};export{R as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk7ILYMOVBjs = require('./chunk-7ILYMOVB.js');var a=(r,t)=>_chunk7ILYMOVBjs.a.call(void 0, r,t,"local");exports.a = a;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as r}from"./chunk-AJKPRTOJ.mjs";import{portraitMediaQuery as o}from"@alessiofrittoli/web-utils/device";var m=()=>r(o);export{m as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _react = require('react');var _dom = require('@alessiofrittoli/web-utils/dom');var S=l=>{let r=_react.useCallback.call(void 0, ()=>_dom.blockScroll.call(void 0, _optionalChain([l, 'optionalAccess', _ => _.current])||void 0),[l]),c=_react.useCallback.call(void 0, ()=>_dom.restoreScroll.call(void 0, _optionalChain([l, 'optionalAccess', _2 => _2.current])||void 0),[l]);return[r,c]};exports.a = S;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _react = require('react');var E=["input","select","textarea","button","[href]",'[tabindex]:not([tabindex="-1"])'].join(", "),b= exports.a =n=>{let[r,o]=_react.useState.call(void 0, !1),s=_react.useRef.call(void 0, null),f=_react.useCallback.call(void 0, t=>{s.current=document.activeElement;let e=t||_optionalChain([n, 'optionalAccess', _ => _.current])||!1;if(e)return o(e)},[n]),i=_react.useCallback.call(void 0, ()=>{_optionalChain([s, 'access', _2 => _2.current, 'optionalAccess', _3 => _3.focus, 'call', _4 => _4()]),o(!1)},[]);return _react.useEffect.call(void 0, ()=>{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(),_optionalChain([u, 'optionalAccess', _5 => _5.focus, 'call', _6 => _6()]));return}document.activeElement===u&&(e.preventDefault(),_optionalChain([a, 'optionalAccess', _7 => _7.focus, 'call', _8 => _8()]))};return document.addEventListener("keydown",t),()=>{document.removeEventListener("keydown",t)}},[r]),[f,i]};exports.a = b;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e}from"./chunk-26XSIIUK.mjs";import{useEffect as c}from"react";var a=(t,r)=>{let s=e();c(()=>{if(!s)return t()},r)};export{a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as s}from"./chunk-HZLWSH3W.mjs";var n=(o,e)=>s(o,e,"session");export{n as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _react = require('react');var o=()=>{let[e,t]=_react.useState.call(void 0, !1);return _react.useEffect.call(void 0, ()=>t(!0),[]),e};exports.a = o;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkFUCUVFLWjs = require('./chunk-FUCUVFLW.js');var _device = require('@alessiofrittoli/web-utils/device');var a=()=>_chunkFUCUVFLWjs.a.call(void 0, _device.portraitMediaQuery);exports.a = a;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as o}from"./chunk-HZLWSH3W.mjs";var g=(r,t)=>o(r,t,"local");export{g as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
File without changes
|
package/dist/dom-api/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-6BSD56XC.js');var _chunkSW7BCMZFjs = require('../chunk-SW7BCMZF.js');var _chunkSNMJ53QBjs = require('../chunk-SNMJ53QB.js');exports.useFocusTrap = _chunkSW7BCMZFjs.a; exports.useScrollBlock = _chunkSNMJ53QBjs.a;
|
package/dist/dom-api/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import"../chunk-WLIFJNZA.mjs";import{a}from"../chunk-6IRIG5HU.mjs";import{a as b}from"../chunk-43RVMR6S.mjs";export{a as useFocusTrap,b as useScrollBlock};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=useFocusTrap.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkSW7BCMZFjs = require('../chunk-SW7BCMZF.js');exports.useFocusTrap = _chunkSW7BCMZFjs.a;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//# sourceMappingURL=useFocusTrap.mjs.map
|
|
1
|
+
import{a}from"../chunk-6IRIG5HU.mjs";export{a as useFocusTrap};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=useScrollBlock.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkSNMJ53QBjs = require('../chunk-SNMJ53QB.js');exports.useScrollBlock = _chunkSNMJ53QBjs.a;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//# sourceMappingURL=useScrollBlock.mjs.map
|
|
1
|
+
import{a}from"../chunk-43RVMR6S.mjs";export{a as useScrollBlock};
|
package/dist/eslint.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=eslint.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var n={recommended:[{rules:{"react-hooks/exhaustive-deps":["warn",{additionalHooks:"(useUpdateEffect)"}]}}]};exports.config = n;
|
package/dist/eslint.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
var o={recommended:[{rules:{"react-hooks/exhaustive-deps":["warn",{additionalHooks:"(useUpdateEffect)"}]}}]};export{o as config}
|
|
2
|
-
//# sourceMappingURL=eslint.mjs.map
|
|
1
|
+
var o={recommended:[{rules:{"react-hooks/exhaustive-deps":["warn",{additionalHooks:"(useUpdateEffect)"}]}}]};export{o as config};
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-YLUTFORB.js');var _chunkVLSP3MANjs = require('./chunk-VLSP3MAN.js');var _chunkEFFJB2GRjs = require('./chunk-EFFJB2GR.js');var _chunkHO57SPSTjs = require('./chunk-HO57SPST.js');require('./chunk-TA6PCHH4.js');require('./chunk-4BGMCO3F.js');var _chunkIDNLFWFOjs = require('./chunk-IDNLFWFO.js');var _chunkG55NP3QGjs = require('./chunk-G55NP3QG.js');var _chunk7ILYMOVBjs = require('./chunk-7ILYMOVB.js');var _chunkWOVEE75Mjs = require('./chunk-WOVEE75M.js');var _chunkFUCUVFLWjs = require('./chunk-FUCUVFLW.js');require('./chunk-6BSD56XC.js');var _chunkSW7BCMZFjs = require('./chunk-SW7BCMZF.js');var _chunkSNMJ53QBjs = require('./chunk-SNMJ53QB.js');exports.useFocusTrap = _chunkSW7BCMZFjs.a; exports.useIsClient = _chunkVLSP3MANjs.a; exports.useIsFirstRender = _chunkHO57SPSTjs.a; exports.useIsPortrait = _chunkWOVEE75Mjs.a; exports.useLocalStorage = _chunkIDNLFWFOjs.a; exports.useMediaQuery = _chunkFUCUVFLWjs.a; exports.useScrollBlock = _chunkSNMJ53QBjs.a; exports.useSessionStorage = _chunkG55NP3QGjs.a; exports.useStorage = _chunk7ILYMOVBjs.a; exports.useUpdateEffect = _chunkEFFJB2GRjs.a;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import"./chunk-ZNAB4TYW.mjs";import{a as x}from"./chunk-65SF33P4.mjs";import{a as b}from"./chunk-UAJXVBNR.mjs";import{a}from"./chunk-26XSIIUK.mjs";import"./chunk-YQO25XKN.mjs";import"./chunk-2CZNCZFR.mjs";import{a as r}from"./chunk-YAZXPL6I.mjs";import{a as e}from"./chunk-UXNKH2MC.mjs";import{a as o}from"./chunk-HZLWSH3W.mjs";import{a as m}from"./chunk-RENUP2VU.mjs";import{a as f}from"./chunk-AJKPRTOJ.mjs";import"./chunk-WLIFJNZA.mjs";import{a as p}from"./chunk-6IRIG5HU.mjs";import{a as t}from"./chunk-43RVMR6S.mjs";export{p as useFocusTrap,x as useIsClient,a as useIsFirstRender,m as useIsPortrait,r as useLocalStorage,f as useMediaQuery,t as useScrollBlock,e as useSessionStorage,o as useStorage,b as useUpdateEffect};
|
package/dist/misc/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-YLUTFORB.js');var _chunkVLSP3MANjs = require('../chunk-VLSP3MAN.js');var _chunkEFFJB2GRjs = require('../chunk-EFFJB2GR.js');var _chunkHO57SPSTjs = require('../chunk-HO57SPST.js');exports.useIsClient = _chunkVLSP3MANjs.a; exports.useIsFirstRender = _chunkHO57SPSTjs.a; exports.useUpdateEffect = _chunkEFFJB2GRjs.a;
|
package/dist/misc/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import"../chunk-ZNAB4TYW.mjs";import{a}from"../chunk-65SF33P4.mjs";import{a as c}from"../chunk-UAJXVBNR.mjs";import{a as b}from"../chunk-26XSIIUK.mjs";export{a as useIsClient,b as useIsFirstRender,c as useUpdateEffect};
|
package/dist/misc/useIsClient.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=useIsClient.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkVLSP3MANjs = require('../chunk-VLSP3MAN.js');exports.useIsClient = _chunkVLSP3MANjs.a;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//# sourceMappingURL=useIsClient.mjs.map
|
|
1
|
+
import{a}from"../chunk-65SF33P4.mjs";export{a as useIsClient};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=useIsFirstRender.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkHO57SPSTjs = require('../chunk-HO57SPST.js');exports.useIsFirstRender = _chunkHO57SPSTjs.a;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//# sourceMappingURL=useIsFirstRender.mjs.map
|
|
1
|
+
import{a}from"../chunk-26XSIIUK.mjs";export{a as useIsFirstRender};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=usePagination.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _react = require('react');var _helpers = require('@alessiofrittoli/math-utils/helpers');var p=(t={})=>_react.useMemo.call(void 0, ()=>_helpers.paginate.call(void 0, t),[t]);exports.usePagination = p;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//# sourceMappingURL=usePagination.mjs.map
|
|
1
|
+
import{useMemo as a}from"react";import{paginate as e}from"@alessiofrittoli/math-utils/helpers";var m=(t={})=>a(()=>e(t),[t]);export{m as usePagination};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=useUpdateEffect.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkEFFJB2GRjs = require('../chunk-EFFJB2GR.js');require('../chunk-HO57SPST.js');exports.useUpdateEffect = _chunkEFFJB2GRjs.a;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//# sourceMappingURL=useUpdateEffect.mjs.map
|
|
1
|
+
import{a}from"../chunk-UAJXVBNR.mjs";import"../chunk-26XSIIUK.mjs";export{a as useUpdateEffect};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alessiofrittoli/react-hooks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "TypeScript React utility Hooks",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Alessio Frittoli",
|
|
@@ -68,10 +68,11 @@
|
|
|
68
68
|
"sideEffects": false,
|
|
69
69
|
"scripts": {
|
|
70
70
|
"//1a": "*********************************************************************",
|
|
71
|
-
"//1b": "
|
|
71
|
+
"//1b": "******************** DEV - BUILD - LINT - RELEASE *******************",
|
|
72
72
|
"//1c": "*********************************************************************",
|
|
73
|
-
"
|
|
74
|
-
"build:
|
|
73
|
+
"dev": "NODE_ENV=development tsup --watch",
|
|
74
|
+
"build:prod": "NODE_ENV=production tsup",
|
|
75
|
+
"build": "pnpm lint && pnpm test:ci && pnpm build:prod",
|
|
75
76
|
"lint": "eslint",
|
|
76
77
|
"release": "node scripts/publish.js --verbose --npm",
|
|
77
78
|
"//2a": "*********************************************************************",
|
|
@@ -102,22 +103,22 @@
|
|
|
102
103
|
]
|
|
103
104
|
},
|
|
104
105
|
"devDependencies": {
|
|
105
|
-
"@alessiofrittoli/node-scripts": "^2.
|
|
106
|
-
"@eslint/compat": "^1.2.
|
|
106
|
+
"@alessiofrittoli/node-scripts": "^2.5.0",
|
|
107
|
+
"@eslint/compat": "^1.2.9",
|
|
107
108
|
"@eslint/eslintrc": "^3.3.1",
|
|
108
|
-
"@eslint/js": "^9.
|
|
109
|
+
"@eslint/js": "^9.26.0",
|
|
109
110
|
"@jest/globals": "^29.7.0",
|
|
110
111
|
"@testing-library/dom": "^10.4.0",
|
|
111
112
|
"@testing-library/jest-dom": "^6.6.3",
|
|
112
113
|
"@testing-library/react": "^16.3.0",
|
|
113
114
|
"@testing-library/user-event": "^14.6.1",
|
|
114
115
|
"@types/jest": "^29.5.14",
|
|
115
|
-
"@types/node": "^22.15.
|
|
116
|
+
"@types/node": "^22.15.3",
|
|
116
117
|
"@types/react": "^19.1.2",
|
|
117
|
-
"@types/react-dom": "^19.1.
|
|
118
|
+
"@types/react-dom": "^19.1.3",
|
|
118
119
|
"concurrently": "^9.1.2",
|
|
119
120
|
"dotenv": "^16.5.0",
|
|
120
|
-
"eslint": "^9.
|
|
121
|
+
"eslint": "^9.26.0",
|
|
121
122
|
"eslint-plugin-react": "^7.37.5",
|
|
122
123
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
123
124
|
"globals": "^16.0.0",
|
|
@@ -130,12 +131,12 @@
|
|
|
130
131
|
"ts-node": "^10.9.2",
|
|
131
132
|
"tsup": "^8.4.0",
|
|
132
133
|
"typescript": "^5.8.3",
|
|
133
|
-
"typescript-eslint": "^8.31.
|
|
134
|
+
"typescript-eslint": "^8.31.1"
|
|
134
135
|
},
|
|
135
136
|
"dependencies": {
|
|
136
|
-
"@alessiofrittoli/math-utils": "^1.
|
|
137
|
-
"@alessiofrittoli/type-utils": "^1.
|
|
138
|
-
"@alessiofrittoli/web-utils": "^1.
|
|
137
|
+
"@alessiofrittoli/math-utils": "^1.13.0",
|
|
138
|
+
"@alessiofrittoli/type-utils": "^1.8.0",
|
|
139
|
+
"@alessiofrittoli/web-utils": "^1.10.0"
|
|
139
140
|
},
|
|
140
141
|
"peerDependencies": {
|
|
141
142
|
"@types/react": "^19",
|
|
@@ -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"],"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"],"mappings":"6SAcO,IAAMA,EAAa,CACzBC,CAAAA,CACAC,CACAC,CAAAA,CAAAA,CAA+B,OACO,GAAA,CAEtC,IAAMC,CAAYC,CAAAA,iBAAAA,CAAa,KAC5BF,CAAS,GAAA,OAAA,CAAUG,0BAAeC,6BAClC,EAAA,GAAA,CAAQN,CAAI,CAAA,EAAKC,CACjB,CAAA,CAAEC,EAAMF,CAAKC,CAAAA,CAAa,CAAE,CAQzB,CAAA,CAAEM,EAAaC,CAAe,CAAA,CAAIC,cAAoBR,CAAAA,CAAa,CAQnES,CAAAA,CAAAA,CAAWN,kBAAiCO,CAAS,EAAA,CAE1DH,EAAgBD,CAAe,EAAA,CAC9B,IAAMK,CAAeD,CAAAA,CAAAA,YAAiB,QAAWA,CAAAA,CAAAA,CAAOJ,CAAY,CAAA,CAAII,EAEvE,OACA,CAAA,OAAO,OAAW,GAClBT,EAAAA,CAAAA,GAAS,QAAUG,yBAAeC,CAAAA,6BAAAA,EACjC,GAAKN,CAAAA,CAAAA,CAAKY,CAAa,CAAA,CAElBA,CACR,CAAE,EAGH,EAAG,CAAEV,CAAAA,CAAMF,CAAI,CAAE,CAAA,CAEjB,OAAAa,eAAAA,CAAW,IAAM,CAChBL,EAAgBL,CAAU,EAAE,EAC7B,CAAG,CAAA,CAAEA,CAAU,CAAE,CAAA,CAEV,CAAEI,CAAAA,CAAaG,CAAS,CAChC,ECpDaI,IAAAA,CAAAA,CAAkB,CAC9Bd,CACAC,CAAAA,CAAAA,GACIF,EAAYC,CAAKC,CAAAA,CAAAA,CAAc,OAAQ,ECHrC,IAAMc,EAAoB,CAChCf,CAAAA,CACAC,IACIF,CAAYC,CAAAA,CAAAA,CAAKC,EAAc,SAAU,ECCvC,IAAMe,CAAkBC,CAAAA,CAAAA,EAAmB,CAEjD,GAAM,CAAEC,CAASC,CAAAA,CAAW,EAAIV,cAAUW,CAAAA,0BAAAA,CAAiBH,CAAM,CAAE,CAAA,CAC7DI,CAA0BjB,CAAAA,iBAAAA,CAAa,IAAMe,CAAAA,CAAYC,2BAAiBH,CAAM,CAAE,EAAG,CAAEA,CAAM,CAAE,CAGrG,CAAA,OAAAJ,eAAW,CAAA,IAAM,CAEhB,IAAMS,EAAa,MAAO,CAAA,UAAA,CAAYL,CAAM,CAE5C,CAAA,OAAAI,GAEAC,CAAAA,CAAAA,CAAW,gBAAkB,CAAA,QAAA,CAAUD,CAAwB,CAAA,CAExD,IAAM,CACZC,CAAAA,CAAW,oBAAqB,QAAUD,CAAAA,CAAwB,EACnE,CAED,CAAA,CAAG,CAAEJ,CAAAA,CAAOI,CAAwB,CAAE,EAE/BH,CAER,ECxBaK,IAAAA,CAAAA,CAAgB,IAAMP,CAAAA,CAAeQ,yBAAmB","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 )"]}
|
|
@@ -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"],"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"],"mappings":"qVAcO,IAAMA,EAAa,CACzBC,CAAAA,CACAC,CACAC,CAAAA,CAAAA,CAA+B,OACO,GAAA,CAEtC,IAAMC,CAAYC,CAAAA,WAAAA,CAAa,KAC5BF,CAAS,GAAA,OAAA,CAAUG,aAAeC,cAClC,EAAA,GAAA,CAAQN,CAAI,CAAA,EAAKC,CACjB,CAAA,CAAEC,EAAMF,CAAKC,CAAAA,CAAa,CAAE,CAQzB,CAAA,CAAEM,EAAaC,CAAe,CAAA,CAAIC,QAAoBR,CAAAA,CAAa,CAQnES,CAAAA,CAAAA,CAAWN,YAAiCO,CAAS,EAAA,CAE1DH,EAAgBD,CAAe,EAAA,CAC9B,IAAMK,CAAeD,CAAAA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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 )"]}
|
|
@@ -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"],"names":["useStorage","key","initialValue","type","readValue","useCallback","LocalStorage","SessionStorage","storedValue","setStoredValue","useState","setValue","value","valueToStore","useEffect","useLocalStorage","useSessionStorage"],"mappings":"4LAcaA,IAAAA,CAAAA,CAAa,CACzBC,CAAAA,CACAC,CACAC,CAAAA,CAAAA,CAA+B,OACO,GAAA,CAEtC,IAAMC,CAAAA,CAAYC,iBAAa,CAAA,IAAA,CAC5BF,CAAS,GAAA,OAAA,CAAUG,0BAAeC,6BAClC,EAAA,GAAA,CAAQN,CAAI,CAAA,EAAKC,CACjB,CAAA,CAAEC,CAAMF,CAAAA,CAAAA,CAAKC,CAAa,CAAE,CAQzB,CAAA,CAAEM,CAAaC,CAAAA,CAAe,CAAIC,CAAAA,cAAAA,CAAoBR,CAAa,CAAA,CAQnES,CAAWN,CAAAA,iBAAAA,CAAiCO,CAAS,EAAA,CAE1DH,CAAgBD,CAAAA,CAAAA,EAAe,CAC9B,IAAMK,CAAeD,CAAAA,CAAAA,YAAiB,QAAWA,CAAAA,CAAAA,CAAOJ,CAAY,CAAII,CAAAA,CAAAA,CAEvE,OACA,CAAA,OAAO,MAAW,CAAA,GAAA,EAClBT,CAAS,GAAA,OAAA,CAAUG,yBAAeC,CAAAA,6BAAAA,EACjC,GAAKN,CAAAA,CAAAA,CAAKY,CAAa,CAAA,CAElBA,CACR,CAAE,EAGH,CAAA,CAAG,CAAEV,CAAAA,CAAMF,CAAI,CAAE,CAEjB,CAAA,OAAAa,eAAW,CAAA,IAAM,CAChBL,CAAAA,CAAgBL,CAAU,EAAE,EAC7B,CAAG,CAAA,CAAEA,CAAU,CAAE,CAEV,CAAA,CAAEI,CAAaG,CAAAA,CAAS,CAChC,ECpDaI,IAAAA,CAAAA,CAAkB,CAC9Bd,CAAAA,CACAC,CACIF,GAAAA,CAAAA,CAAYC,CAAKC,CAAAA,CAAAA,CAAc,OAAQ,ECH/Bc,IAAAA,CAAAA,CAAoB,CAChCf,CAAAA,CACAC,CACIF,GAAAA,CAAAA,CAAYC,CAAKC,CAAAA,CAAAA,CAAc,SAAU","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' )"]}
|
|
@@ -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"],"names":["useStorage","key","initialValue","type","readValue","useCallback","LocalStorage","SessionStorage","storedValue","setStoredValue","useState","setValue","value","valueToStore","useEffect","useLocalStorage","useSessionStorage"],"mappings":"6MAcaA,IAAAA,CAAAA,CAAa,CACzBC,CAAAA,CACAC,CACAC,CAAAA,CAAAA,CAA+B,OACO,GAAA,CAEtC,IAAMC,CAAAA,CAAYC,WAAa,CAAA,IAAA,CAC5BF,CAAS,GAAA,OAAA,CAAUG,aAAeC,cAClC,EAAA,GAAA,CAAQN,CAAI,CAAA,EAAKC,CACjB,CAAA,CAAEC,CAAMF,CAAAA,CAAAA,CAAKC,CAAa,CAAE,CAQzB,CAAA,CAAEM,CAAaC,CAAAA,CAAe,CAAIC,CAAAA,QAAAA,CAAoBR,CAAa,CAAA,CAQnES,CAAWN,CAAAA,WAAAA,CAAiCO,CAAS,EAAA,CAE1DH,CAAgBD,CAAAA,CAAAA,EAAe,CAC9B,IAAMK,CAAeD,CAAAA,CAAAA,YAAiB,QAAWA,CAAAA,CAAAA,CAAOJ,CAAY,CAAII,CAAAA,CAAAA,CAEvE,OACA,CAAA,OAAO,MAAW,CAAA,GAAA,EAClBT,CAAS,GAAA,OAAA,CAAUG,YAAeC,CAAAA,cAAAA,EACjC,GAAKN,CAAAA,CAAAA,CAAKY,CAAa,CAAA,CAElBA,CACR,CAAE,EAGH,CAAA,CAAG,CAAEV,CAAAA,CAAMF,CAAI,CAAE,CAEjB,CAAA,OAAAa,SAAW,CAAA,IAAM,CAChBL,CAAAA,CAAgBL,CAAU,EAAE,EAC7B,CAAG,CAAA,CAAEA,CAAU,CAAE,CAEV,CAAA,CAAEI,CAAaG,CAAAA,CAAS,CAChC,ECpDaI,IAAAA,CAAAA,CAAkB,CAC9Bd,CAAAA,CACAC,CACIF,GAAAA,CAAAA,CAAYC,CAAKC,CAAAA,CAAAA,CAAc,OAAQ,ECH/Bc,IAAAA,CAAAA,CAAoB,CAChCf,CAAAA,CACAC,CACIF,GAAAA,CAAAA,CAAYC,CAAKC,CAAAA,CAAAA,CAAc,SAAU","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' )"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/browser-api/storage/useStorage.ts","../../../src/browser-api/storage/useLocalStorage.ts"],"names":["useStorage","key","initialValue","type","readValue","useCallback","LocalStorage","SessionStorage","storedValue","setStoredValue","useState","setValue","value","valueToStore","useEffect","useLocalStorage"],"mappings":"4LAcO,IAAMA,CAAAA,CAAa,CACzBC,CAAAA,CACAC,EACAC,CAA+B,CAAA,OAAA,GACO,CAEtC,IAAMC,CAAYC,CAAAA,iBAAAA,CAAa,KAC5BF,CAAS,GAAA,OAAA,CAAUG,yBAAeC,CAAAA,6BAAAA,EAClC,GAAQN,CAAAA,CAAI,GAAKC,CACjB,CAAA,CAAEC,CAAMF,CAAAA,CAAAA,CAAKC,CAAa,CAAE,EAQzB,CAAEM,CAAAA,CAAaC,CAAe,CAAA,CAAIC,cAAoBR,CAAAA,CAAa,CAQnES,CAAAA,CAAAA,CAAWN,iBAAiCO,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,0BAAeC,6BACjC,EAAA,GAAA,CAAKN,CAAKY,CAAAA,CAAa,CAElBA,CAAAA,CACR,CAAE,EAGH,CAAA,CAAG,CAAEV,CAAAA,CAAMF,CAAI,CAAE,EAEjB,OAAAa,eAAAA,CAAW,IAAM,CAChBL,CAAgBL,CAAAA,CAAAA,EAAY,EAC7B,CAAA,CAAG,CAAEA,CAAU,CAAE,CAAA,CAEV,CAAEI,CAAaG,CAAAA,CAAS,CAChC,CAAA,CCpDaI,IAAAA,CAAAA,CAAkB,CAC9Bd,CAAAA,CACAC,CACIF,GAAAA,CAAAA,CAAYC,CAAKC,CAAAA,CAAAA,CAAc,OAAQ","file":"useLocalStorage.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' )"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/browser-api/storage/useStorage.ts","../../../src/browser-api/storage/useLocalStorage.ts"],"names":["useStorage","key","initialValue","type","readValue","useCallback","LocalStorage","SessionStorage","storedValue","setStoredValue","useState","setValue","value","valueToStore","useEffect","useLocalStorage"],"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,CAAkB,CAC9Bd,CAAAA,CACAC,CACIF,GAAAA,CAAAA,CAAYC,CAAKC,CAAAA,CAAAA,CAAc,OAAQ","file":"useLocalStorage.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' )"]}
|
|
@@ -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":"4LAcO,IAAMA,CAAAA,CAAa,CACzBC,CAAAA,CACAC,EACAC,CAA+B,CAAA,OAAA,GACO,CAEtC,IAAMC,CAAYC,CAAAA,iBAAAA,CAAa,KAC5BF,CAAS,GAAA,OAAA,CAAUG,yBAAeC,CAAAA,6BAAAA,EAClC,GAAQN,CAAAA,CAAI,GAAKC,CACjB,CAAA,CAAEC,CAAMF,CAAAA,CAAAA,CAAKC,CAAa,CAAE,EAQzB,CAAEM,CAAAA,CAAaC,CAAe,CAAA,CAAIC,cAAoBR,CAAAA,CAAa,CAQnES,CAAAA,CAAAA,CAAWN,iBAAiCO,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,0BAAeC,6BACjC,EAAA,GAAA,CAAKN,CAAKY,CAAAA,CAAa,CAElBA,CAAAA,CACR,CAAE,EAGH,CAAA,CAAG,CAAEV,CAAAA,CAAMF,CAAI,CAAE,EAEjB,OAAAa,eAAAA,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.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 * 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 +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 +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 +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 +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 +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 +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 +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 +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,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nB,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 +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 +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":"wC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ACNG,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 +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,CAC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AA,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 +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 +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}"]}
|
package/dist/eslint.js.map
DELETED
|
@@ -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}"]}
|
package/dist/eslint.mjs.map
DELETED
|
@@ -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","useUpdateEffect","effect","deps"],"mappings":"2VAcO,IAAMA,CAAa,CAAA,CACzBC,CACAC,CAAAA,CAAAA,CACAC,CAA+B,CAAA,OAAA,GACO,CAEtC,IAAMC,CAAYC,CAAAA,iBAAAA,C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AA,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}"]}
|
package/dist/index.mjs.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","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,CAAiB,YAAA,QAAA,CAAWA,EAAOJ,CAAY,CAAA,CAAII,CAEvE,CAAA,OAAA,CACA,OAAO,MAAA,CAAW,GAClBT,EAAA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EoC,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}"]}
|
package/dist/misc/index.js.map
DELETED
|
@@ -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}"]}
|
package/dist/misc/index.mjs.map
DELETED
|
@@ -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 +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 +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 +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 +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 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/misc/usePagination.ts"],"names":["usePagination","options","useMemo","paginate"],"mappings":"mGASaA,CAAgB,CAAA,CAAEC,EAA2B,EAAC,GAC1DC,cAAS,IAAMC,gBAAAA,CAAUF,CAAQ,CAAG,CAAA,CAAEA,CAAQ,CAAE","file":"usePagination.js","sourcesContent":["import { useMemo } from 'react'\nimport { paginate, type PaginateOptions } from '@alessiofrittoli/math-utils/helpers'\n\n/**\n * Get pagination informations based on the given options.\n *\n * @param options An object defining pagination input data. See {@link PaginateOptions} for more information.\n * @returns A memoized object containing pagination informations based on the given options.\n */\nexport const usePagination = ( options: PaginateOptions = {} ) => (\n\tuseMemo( () => paginate( options ), [ options ] )\n)"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/misc/usePagination.ts"],"names":["usePagination","options","useMemo","paginate"],"mappings":"2FASaA,CAAgB,CAAA,CAAEC,EAA2B,EAAC,GAC1DC,QAAS,IAAMC,QAAAA,CAAUF,CAAQ,CAAG,CAAA,CAAEA,CAAQ,CAAE","file":"usePagination.mjs","sourcesContent":["import { useMemo } from 'react'\nimport { paginate, type PaginateOptions } from '@alessiofrittoli/math-utils/helpers'\n\n/**\n * Get pagination informations based on the given options.\n *\n * @param options An object defining pagination input data. See {@link PaginateOptions} for more information.\n * @returns A memoized object containing pagination informations based on the given options.\n */\nexport const usePagination = ( options: PaginateOptions = {} ) => (\n\tuseMemo( () => paginate( options ), [ options ] )\n)"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/misc/useIsFirstRender.ts","../../src/misc/useUpdateEffect.ts"],"names":["useIsFirstRender","isFirst","useRef","useUpdateEffect","effect","deps","useEffect"],"mappings":"wCAQO,IAAMA,CAAmB,CAAA,IAAM,CAErC,IAAMC,CAAAA,CAAUC,aAAQ,IAAK,CAAA,CAE7B,OAAKD,CAAQ,CAAA,OAAA,EACZA,CAAQ,CAAA,OAAA,CAAU,KAEX,CAAA,IAAA,EAGDA,EAAQ,OAEhB,CAAA,KCVaE,CAAkB,CAAA,CAC9BC,EACAC,CACI,GAAA,CAEJ,IAAMJ,CAAAA,CAAUD,CAAiB,EAAA,CAEjCM,gBAAW,IAAM,CAChB,GAAK,CAAEL,CAAAA,CAAU,OAAOG,CAAO,EAEhC,CAAGC,CAAAA,CAAK,EAET","file":"useUpdateEffect.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}","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/misc/useIsFirstRender.ts","../../src/misc/useUpdateEffect.ts"],"names":["useIsFirstRender","isFirst","useRef","useUpdateEffect","effect","deps","useEffect"],"mappings":"qCAQO,IAAMA,CAAmB,CAAA,IAAM,CAErC,IAAMC,CAAAA,CAAUC,OAAQ,IAAK,CAAA,CAE7B,OAAKD,CAAQ,CAAA,OAAA,EACZA,CAAQ,CAAA,OAAA,CAAU,KAEX,CAAA,IAAA,EAGDA,EAAQ,OAEhB,CAAA,KCVaE,CAAkB,CAAA,CAC9BC,EACAC,CACI,GAAA,CAEJ,IAAMJ,CAAAA,CAAUD,CAAiB,EAAA,CAEjCM,UAAW,IAAM,CAChB,GAAK,CAAEL,CAAAA,CAAU,OAAOG,CAAO,EAEhC,CAAGC,CAAAA,CAAK,EAET","file":"useUpdateEffect.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}","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}"]}
|