@mantine/hooks
Advanced tools
Comparing version 2.0.7 to 2.1.0-alpha.0
@@ -28,2 +28,6 @@ 'use strict'; | ||
var useWindowScroll = require('./use-window-scroll/use-window-scroll.js'); | ||
var useIntersection = require('./use-intersection/use-intersection.js'); | ||
var useHash = require('./use-hash/use-hash.js'); | ||
var useHotkeys = require('./use-hotkey/use-hotkeys.js'); | ||
var parseHotkey = require('./use-hotkey/parse-hotkey.js'); | ||
var randomId = require('./utils/random-id/random-id.js'); | ||
@@ -61,2 +65,6 @@ var upperFirst = require('./utils/upper-first/upper-first.js'); | ||
exports.useWindowScroll = useWindowScroll.useWindowScroll; | ||
exports.useIntersection = useIntersection.useIntersection; | ||
exports.useHash = useHash.useHash; | ||
exports.useHotkeys = useHotkeys.useHotkeys; | ||
exports.getHotkeyHandler = parseHotkey.getHotkeyHandler; | ||
exports.randomId = randomId.randomId; | ||
@@ -63,0 +71,0 @@ exports.upperFirst = upperFirst.upperFirst; |
@@ -24,2 +24,6 @@ export { useClickOutside } from './use-click-outside/use-click-outside.js'; | ||
export { useWindowScroll } from './use-window-scroll/use-window-scroll.js'; | ||
export { useIntersection } from './use-intersection/use-intersection.js'; | ||
export { useHash } from './use-hash/use-hash.js'; | ||
export { useHotkeys } from './use-hotkey/use-hotkeys.js'; | ||
export { getHotkeyHandler } from './use-hotkey/parse-hotkey.js'; | ||
export { randomId } from './utils/random-id/random-id.js'; | ||
@@ -26,0 +30,0 @@ export { upperFirst } from './utils/upper-first/upper-first.js'; |
@@ -25,2 +25,5 @@ export * from './utils'; | ||
export { useWindowScroll } from './use-window-scroll/use-window-scroll'; | ||
export { useIntersection } from './use-intersection/use-intersection'; | ||
export { useHash } from './use-hash/use-hash'; | ||
export { useHotkeys, getHotkeyHandler } from './use-hotkey/use-hotkeys'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
(function(c,r){typeof exports=="object"&&typeof module!="undefined"?r(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],r):(c=typeof globalThis!="undefined"?globalThis:c||self,r(c["@mantine/hooks"]={},c.React))})(this,function(c,r){"use strict";function P(){return`mantine-${Math.random().toString(36).substr(2,9)}`}function Q(e){return typeof e!="string"?"":e.charAt(0).toUpperCase()+e.slice(1)}function W(e){return typeof e!="string"?"":e.charAt(0).toLowerCase()+e.slice(1)}function F(e,t){typeof e=="function"?e(t):typeof e=="object"&&e!==null&&"current"in e&&(e.current=t)}function K({value:e,min:t,max:n}){return Math.min(Math.max(e,t),n)}function z(e,t=["mousedown","touchstart"]){const n=r.useRef();return r.useEffect(()=>{const s=o=>{n.current&&!n.current.contains(o.target)&&e()};return t.forEach(o=>document.addEventListener(o,s)),()=>{t.forEach(o=>document.removeEventListener(o,s))}},[n,e]),n}function X({timeout:e=2e3}={}){const[t,n]=r.useState(null),[s,o]=r.useState(!1),[u,l]=r.useState(null),a=w=>{clearTimeout(u),l(setTimeout(()=>o(!1),e)),o(w)};return{copy:w=>{"clipboard"in navigator?navigator.clipboard.writeText(w).then(()=>a(!0)).catch(f=>n(f)):n(new Error("useClipboard: navigator.clipboard is not supported"))},reset:()=>{o(!1),n(null),clearTimeout(u)},error:t,copied:s}}function Y(e,t){try{return e.addEventListener("change",t),()=>e.removeEventListener("change",t)}catch(n){return e.addListener(t),()=>e.removeListener(t)}}function G(e){return typeof window!="undefined"&&"matchMedia"in window?window.matchMedia(e).matches:!1}function S(e){const[t,n]=r.useState(G(e)),s=r.useRef();return r.useEffect(()=>{if("matchMedia"in window)return s.current=window.matchMedia(e),n(s.current.matches),Y(s.current,o=>n(o.matches))},[e]),t}function J(){return S("(prefers-color-scheme: dark)")?"dark":"light"}function Z(e,t,n={leading:!1}){const[s,o]=r.useState(e),u=r.useRef(!1),l=r.useRef(null),a=r.useRef(!1),p=()=>window.clearTimeout(l.current);return r.useEffect(()=>{u.current&&(!a.current&&n.leading?(a.current=!0,o(e)):(p(),l.current=window.setTimeout(()=>{a.current=!1,o(e)},t)))},[e,n.leading]),r.useEffect(()=>(u.current=!0,p),[]),[s,p]}const N=typeof document!="undefined"?r.useLayoutEffect:r.useEffect;function x(e){N(()=>{typeof e=="string"&&e.trim().length>0&&(document.title=e.trim())},[e])}function ee(e,t){const n=r.useRef(!1);r.useEffect(()=>{n.current?e():n.current=!0},t)}const te=/input|select|textarea|button|object/,R="a, input, select, textarea, button, object, [tabindex]";function ne(e){return process.env.NODE_ENV==="test"?!1:e.offsetWidth<=0&&e.offsetHeight<=0||e.style.display==="none"}function oe(e){let t=e;for(;t&&t!==document.body;){if(ne(t))return!1;t=t.parentNode}return!0}function D(e){let t=e.getAttribute("tabindex");return t===null&&(t=void 0),parseInt(t,10)}function _(e){const t=e.nodeName.toLowerCase(),n=!Number.isNaN(D(e));return(te.test(t)&&!e.disabled||e instanceof HTMLAnchorElement&&e.href||n)&&oe(e)}function A(e){const t=D(e);return(Number.isNaN(t)||t>=0)&&_(e)}function C(e){return Array.from(e.querySelectorAll(R)).filter(A)}const M=[];let g=null,O=!1;function j(){O=!0}function k(){if(O){if(O=!1,!g||!g||g.contains(document.activeElement))return;(C(g)[0]||g).focus()}}function re(){M.push(document.activeElement)}function se(){let e=null;try{e=M.pop(),e&&e.focus()}catch(t){console.warn(["[@mantine/hooks/use-focus-trap] Focus was returned to",e,"but dom node does not exist"].join(" "))}}function ue(e){g=e,document.addEventListener("focusout",j,!1),document.addEventListener("focusin",k,!0)}function ce(){g=null,document.removeEventListener("focusout",j),document.removeEventListener("focusin",k)}function ie(e,t){const n=C(e);if(!n.length){t.preventDefault();return}if(!(n[t.shiftKey?0:n.length-1]===document.activeElement||e===document.activeElement))return;t.preventDefault();const u=n[t.shiftKey?n.length-1:0];u&&u.focus()}function fe(e,t="body > :not(script)"){const n=Array.from(document.querySelectorAll(t)).map(s=>{if(s.contains(e))return;const o=s.getAttribute("aria-hidden");return(o===null||o==="false")&&s.setAttribute("aria-hidden","true"),{node:s,ariaHidden:o}});return()=>{n.forEach(s=>{!s||(s.ariaHidden===null?s.node.removeAttribute("aria-hidden"):s.node.setAttribute("aria-hidden",s.ariaHidden))})}}function ae(e=!0){const t=r.useRef(),n=r.useRef(null),s=r.useCallback(o=>{if(n.current&&n.current(),t.current&&(se(),ce()),e&&o){ue(o),re();const u=l=>{n.current=fe(l);let a=o.querySelector("[data-autofocus]");if(!a){const p=Array.from(o.querySelectorAll(R));a=p.find(A)||p.find(_)||null,!a&&_(o)&&(a=o)}a?a.focus():process.env.NODE_ENV==="development"&&console.warn("[@mantine/hooks/use-focus-trap] Failed to find focusable element within provided node",o)};setTimeout(()=>{o.ownerDocument?u(o):process.env.NODE_ENV==="development"&&console.warn("[@mantine/hooks/use-focus-trap] Ref node is not part of the dom",o)}),t.current=o}else t.current=null},[e]);return r.useEffect(()=>{if(!e)return;const o=u=>{u.key==="Tab"&&t.current&&ie(t.current,u)};return document.addEventListener("keydown",o),()=>{document.removeEventListener("keydown",o)}},[e]),s}const le=e=>(e+1)%1e6;function de(){const[,e]=r.useReducer(le,0);return e}var pe=Object.defineProperty,me=Object.defineProperties,we=Object.getOwnPropertyDescriptors,V=Object.getOwnPropertySymbols,be=Object.prototype.hasOwnProperty,he=Object.prototype.propertyIsEnumerable,$=(e,t,n)=>t in e?pe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,T=(e,t)=>{for(var n in t||(t={}))be.call(t,n)&&$(e,n,t[n]);if(V)for(var n of V(t))he.call(t,n)&&$(e,n,t[n]);return e},L=(e,t)=>me(e,we(t));function ge({initialValues:e,validationRules:t={}}){const n=Object.keys(e).reduce((i,m)=>(i[m]=!1,i),{}),[s,o]=r.useState(n),[u,l]=r.useState(e),a=()=>o(n),p=()=>{l(e),a()},h=()=>{let i=!0;const m=Object.keys(u).reduce((v,y)=>(t&&typeof t[y]=="function"&&!t[y](u[y])?(v[y]=!0,i=!1):v[y]=!1,v),{});return o(m),i},w=i=>o(m=>L(T({},m),{[i]:typeof t[i]=="function"?!t[i](u[i]):!1})),f=(i,m)=>o(v=>L(T({},v),{[i]:m}));return{values:u,errors:s,validate:h,reset:p,setErrors:o,setValues:l,setFieldValue:(i,m)=>{l(v=>L(T({},v),{[i]:m})),f(i,!1)},setFieldError:f,validateField:w,resetErrors:a,onSubmit:i=>m=>{m&&m.preventDefault(),h()&&i(u)}}}function ve(e,t=P){const n=r.useRef(t());return e||n.current}function ye(e,t){const[n,s]=r.useState(!1),o=r.useRef(),u=()=>{s(!0),o.current=window.setInterval(e,t)},l=()=>{s(!1),window.clearInterval(o.current)};return{start:u,stop:l,toggle:()=>{n?l():u()},active:n}}var Ee=Object.defineProperty,Se=Object.defineProperties,_e=Object.getOwnPropertyDescriptors,q=Object.getOwnPropertySymbols,Oe=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable,U=(e,t,n)=>t in e?Ee(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Le=(e,t)=>{for(var n in t||(t={}))Oe.call(t,n)&&U(e,n,t[n]);if(q)for(var n of q(t))Te.call(t,n)&&U(e,n,t[n]);return e},Ie=(e,t)=>Se(e,_e(t));function Pe(e=[]){const[t,n]=r.useState(e);return[t,{setState:n,append:(...f)=>n(d=>[...d,...f]),prepend:(...f)=>n(d=>[...f,...d]),insert:(f,...d)=>n(b=>[...b.slice(0,f),...d,...b.slice(f)]),apply:f=>n(d=>d.map((b,i)=>f(b,i))),remove:(...f)=>n(d=>d.filter((b,i)=>!f.includes(i))),reorder:({from:f,to:d})=>n(b=>{const i=[...b],m=b[f];return i.splice(f,1),i.splice(d,0,m),i}),setItem:(f,d)=>n(b=>{const i=[...b];return i[f]=d,i}),setItemProp:(f,d,b)=>n(i=>{const m=[...i];return m[f]=Ie(Le({},m[f]),{[d]:b}),m})}]}function E(e,t,n){r.useEffect(()=>(window.addEventListener(e,t,n),()=>window.removeEventListener(e,t,n)),[])}function Fe({key:e,defaultValue:t=void 0}){const[n,s]=r.useState(typeof window!="undefined"&&"localStorage"in window?window.localStorage.getItem(e):t!=null?t:""),o=r.useCallback(u=>{typeof u=="function"?s(l=>{const a=u(l);return window.localStorage.setItem(e,a),a}):(window.localStorage.setItem(e,u),s(u))},[e]);return E("storage",u=>{u.storageArea===window.localStorage&&u.key===e&&s(u.newValue)}),r.useEffect(()=>{t&&!n&&o(t)},[t,n,o]),[n,o]}function Ne(...e){return t=>{e.forEach(n=>F(n,t))}}function Re({initialValues:e=[],limit:t}){const[{state:n,queue:s},o]=r.useState({state:e.slice(0,t),queue:e.slice(t)});return{state:n,queue:s,add:(...p)=>o(h=>{const w=[...h.state,...h.queue,...p];return{state:w.slice(0,t),queue:w.slice(t)}}),update:p=>o(h=>{const w=p([...h.state,...h.queue]);return{state:w.slice(0,t),queue:w.slice(t)}}),cleanQueue:()=>o(p=>({state:p.state,queue:[]}))}}function De(){return S("(prefers-reduced-motion: reduce)")}const B=e=>{e.preventDefault()};function Ae(e,t={disableTouchEvents:!1}){const n=r.useRef(!1),s=r.useRef(null),o=()=>{n.current&&(n.current=!1,document.body.style.overflow=s.current||"",t.disableTouchEvents&&document.body.removeEventListener("touchmove",B))},u=()=>{n.current=!0,s.current=document.body.style.overflow,document.body.style.overflow="hidden",t.disableTouchEvents&&document.body.addEventListener("touchmove",B,{passive:!1})};r.useEffect(()=>(e?u():o(),o),[e])}function H(e,t){const[n,s]=r.useState(e);return[n,u=>{typeof u!="undefined"?s(u):s(l=>l===t[0]?t[1]:t[0])}]}function Ce(e=!1){return H(e,[!0,!1])}function Me({value:e,defaultValue:t,finalValue:n,rule:s,onChange:o,onValueUpdate:u}){const l=s(e),a=r.useRef("initial"),p=s(t)?t:n,[h,w]=r.useState(p);let f=l?e:h;!l&&a.current==="controlled"&&(f=n),a.current=l?"controlled":"uncontrolled";const d=a.current,b=i=>{typeof o=="function"&&o(i),d==="uncontrolled"&&w(i)};return r.useEffect(()=>{d==="uncontrolled"&&w(f),typeof u=="function"&&u(f)},[d,f]),[f,b,a.current]}function I(){return typeof window!="undefined"?{x:window.pageXOffset,y:window.pageYOffset}:{x:0,y:0}}function je({x:e,y:t}){if(typeof window!="undefined"){const n={behavior:"smooth"};typeof e=="number"&&(n.left=e),typeof t=="number"&&(n.top=t),window.scrollTo(n)}}function ke(){const[e,t]=r.useState(I());return E("scroll",()=>t(I())),E("resize",()=>t(I())),[e,je]}c.assignRef=F,c.clamp=K,c.lowerFirst=W,c.randomId=P,c.upperFirst=Q,c.useBooleanToggle=Ce,c.useClickOutside=z,c.useClipboard=X,c.useColorScheme=J,c.useDebouncedValue=Z,c.useDidUpdate=ee,c.useDocumentTitle=x,c.useFocusTrap=ae,c.useForceUpdate=de,c.useForm=ge,c.useId=ve,c.useInterval=ye,c.useIsomorphicEffect=N,c.useListState=Pe,c.useLocalStorageValue=Fe,c.useMediaQuery=S,c.useMergedRef=Ne,c.useQueue=Re,c.useReducedMotion=De,c.useScrollLock=Ae,c.useToggle=H,c.useUncontrolled=Me,c.useWindowEvent=E,c.useWindowScroll=ke,Object.defineProperty(c,"__esModule",{value:!0})}); | ||
(function(c,s){typeof exports=="object"&&typeof module!="undefined"?s(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],s):(c=typeof globalThis!="undefined"?globalThis:c||self,s(c["@mantine/hooks"]={},c.React))})(this,function(c,s){"use strict";function I(){return`mantine-${Math.random().toString(36).substr(2,9)}`}function z(e){return typeof e!="string"?"":e.charAt(0).toUpperCase()+e.slice(1)}function X(e){return typeof e!="string"?"":e.charAt(0).toLowerCase()+e.slice(1)}function N(e,t){typeof e=="function"?e(t):typeof e=="object"&&e!==null&&"current"in e&&(e.current=t)}function Y({value:e,min:t,max:n}){return Math.min(Math.max(e,t),n)}function G(e,t=["mousedown","touchstart"]){const n=s.useRef();return s.useEffect(()=>{const o=r=>{n.current&&!n.current.contains(r.target)&&e()};return t.forEach(r=>document.addEventListener(r,o)),()=>{t.forEach(r=>document.removeEventListener(r,o))}},[n,e]),n}function J({timeout:e=2e3}={}){const[t,n]=s.useState(null),[o,r]=s.useState(!1),[u,l]=s.useState(null),f=m=>{clearTimeout(u),l(setTimeout(()=>r(!1),e)),r(m)};return{copy:m=>{"clipboard"in navigator?navigator.clipboard.writeText(m).then(()=>f(!0)).catch(a=>n(a)):n(new Error("useClipboard: navigator.clipboard is not supported"))},reset:()=>{r(!1),n(null),clearTimeout(u)},error:t,copied:o}}function Z(e,t){try{return e.addEventListener("change",t),()=>e.removeEventListener("change",t)}catch(n){return e.addListener(t),()=>e.removeListener(t)}}function x(e){return typeof window!="undefined"&&"matchMedia"in window?window.matchMedia(e).matches:!1}function _(e){const[t,n]=s.useState(x(e)),o=s.useRef();return s.useEffect(()=>{if("matchMedia"in window)return o.current=window.matchMedia(e),n(o.current.matches),Z(o.current,r=>n(r.matches))},[e]),t}function ee(){return _("(prefers-color-scheme: dark)")?"dark":"light"}function te(e,t,n={leading:!1}){const[o,r]=s.useState(e),u=s.useRef(!1),l=s.useRef(null),f=s.useRef(!1),p=()=>window.clearTimeout(l.current);return s.useEffect(()=>{u.current&&(!f.current&&n.leading?(f.current=!0,r(e)):(p(),l.current=window.setTimeout(()=>{f.current=!1,r(e)},t)))},[e,n.leading]),s.useEffect(()=>(u.current=!0,p),[]),[o,p]}const R=typeof document!="undefined"?s.useLayoutEffect:s.useEffect;function ne(e){R(()=>{typeof e=="string"&&e.trim().length>0&&(document.title=e.trim())},[e])}function re(e,t){const n=s.useRef(!1);s.useEffect(()=>{n.current?e():n.current=!0},t)}const oe=/input|select|textarea|button|object/,F="a, input, select, textarea, button, object, [tabindex]";function se(e){return process.env.NODE_ENV==="test"?!1:e.offsetWidth<=0&&e.offsetHeight<=0||e.style.display==="none"}function ue(e){let t=e;for(;t&&t!==document.body;){if(se(t))return!1;t=t.parentNode}return!0}function D(e){let t=e.getAttribute("tabindex");return t===null&&(t=void 0),parseInt(t,10)}function S(e){const t=e.nodeName.toLowerCase(),n=!Number.isNaN(D(e));return(oe.test(t)&&!e.disabled||e instanceof HTMLAnchorElement&&e.href||n)&&ue(e)}function C(e){const t=D(e);return(Number.isNaN(t)||t>=0)&&S(e)}function k(e){return Array.from(e.querySelectorAll(F)).filter(C)}const j=[];let b=null,O=!1;function A(){O=!0}function H(){if(O){if(O=!1,!b||!b||b.contains(document.activeElement))return;(k(b)[0]||b).focus()}}function ce(){j.push(document.activeElement)}function ie(){let e=null;try{e=j.pop(),e&&e.focus()}catch(t){console.warn(["[@mantine/hooks/use-focus-trap] Focus was returned to",e,"but dom node does not exist"].join(" "))}}function ae(e){b=e,document.addEventListener("focusout",A,!1),document.addEventListener("focusin",H,!0)}function fe(){b=null,document.removeEventListener("focusout",A),document.removeEventListener("focusin",H)}function le(e,t){const n=k(e);if(!n.length){t.preventDefault();return}if(!(n[t.shiftKey?0:n.length-1]===document.activeElement||e===document.activeElement))return;t.preventDefault();const u=n[t.shiftKey?n.length-1:0];u&&u.focus()}function de(e,t="body > :not(script)"){const n=Array.from(document.querySelectorAll(t)).map(o=>{if(o.contains(e))return;const r=o.getAttribute("aria-hidden");return(r===null||r==="false")&&o.setAttribute("aria-hidden","true"),{node:o,ariaHidden:r}});return()=>{n.forEach(o=>{!o||(o.ariaHidden===null?o.node.removeAttribute("aria-hidden"):o.node.setAttribute("aria-hidden",o.ariaHidden))})}}function pe(e=!0){const t=s.useRef(),n=s.useRef(null),o=s.useCallback(r=>{if(n.current&&n.current(),t.current&&(ie(),fe()),e&&r){ae(r),ce();const u=l=>{n.current=de(l);let f=r.querySelector("[data-autofocus]");if(!f){const p=Array.from(r.querySelectorAll(F));f=p.find(C)||p.find(S)||null,!f&&S(r)&&(f=r)}f?f.focus():process.env.NODE_ENV==="development"&&console.warn("[@mantine/hooks/use-focus-trap] Failed to find focusable element within provided node",r)};setTimeout(()=>{r.ownerDocument?u(r):process.env.NODE_ENV==="development"&&console.warn("[@mantine/hooks/use-focus-trap] Ref node is not part of the dom",r)}),t.current=r}else t.current=null},[e]);return s.useEffect(()=>{if(!e)return;const r=u=>{u.key==="Tab"&&t.current&&le(t.current,u)};return document.addEventListener("keydown",r),()=>{document.removeEventListener("keydown",r)}},[e]),o}const me=e=>(e+1)%1e6;function we(){const[,e]=s.useReducer(me,0);return e}var he=Object.defineProperty,ye=Object.defineProperties,be=Object.getOwnPropertyDescriptors,M=Object.getOwnPropertySymbols,ve=Object.prototype.hasOwnProperty,ge=Object.prototype.propertyIsEnumerable,$=(e,t,n)=>t in e?he(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,P=(e,t)=>{for(var n in t||(t={}))ve.call(t,n)&&$(e,n,t[n]);if(M)for(var n of M(t))ge.call(t,n)&&$(e,n,t[n]);return e},L=(e,t)=>ye(e,be(t));function Ee({initialValues:e,validationRules:t={}}){const n=Object.keys(e).reduce((i,w)=>(i[w]=!1,i),{}),[o,r]=s.useState(n),[u,l]=s.useState(e),f=()=>r(n),p=()=>{l(e),f()},h=()=>{let i=!0;const w=Object.keys(u).reduce((v,E)=>(t&&typeof t[E]=="function"&&!t[E](u[E])?(v[E]=!0,i=!1):v[E]=!1,v),{});return r(w),i},m=i=>r(w=>L(P({},w),{[i]:typeof t[i]=="function"?!t[i](u[i]):!1})),a=(i,w)=>r(v=>L(P({},v),{[i]:w}));return{values:u,errors:o,validate:h,reset:p,setErrors:r,setValues:l,setFieldValue:(i,w)=>{l(v=>L(P({},v),{[i]:w})),a(i,!1)},setFieldError:a,validateField:m,resetErrors:f,onSubmit:i=>w=>{w&&w.preventDefault(),h()&&i(u)}}}function _e(e,t=I){const n=s.useRef(t());return e||n.current}function Se(e,t){const[n,o]=s.useState(!1),r=s.useRef(),u=()=>{o(!0),r.current=window.setInterval(e,t)},l=()=>{o(!1),window.clearInterval(r.current)};return{start:u,stop:l,toggle:()=>{n?l():u()},active:n}}var Oe=Object.defineProperty,Pe=Object.defineProperties,Le=Object.getOwnPropertyDescriptors,V=Object.getOwnPropertySymbols,Te=Object.prototype.hasOwnProperty,Ie=Object.prototype.propertyIsEnumerable,K=(e,t,n)=>t in e?Oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ne=(e,t)=>{for(var n in t||(t={}))Te.call(t,n)&&K(e,n,t[n]);if(V)for(var n of V(t))Ie.call(t,n)&&K(e,n,t[n]);return e},Re=(e,t)=>Pe(e,Le(t));function Fe(e=[]){const[t,n]=s.useState(e);return[t,{setState:n,append:(...a)=>n(d=>[...d,...a]),prepend:(...a)=>n(d=>[...a,...d]),insert:(a,...d)=>n(y=>[...y.slice(0,a),...d,...y.slice(a)]),apply:a=>n(d=>d.map((y,i)=>a(y,i))),remove:(...a)=>n(d=>d.filter((y,i)=>!a.includes(i))),reorder:({from:a,to:d})=>n(y=>{const i=[...y],w=y[a];return i.splice(a,1),i.splice(d,0,w),i}),setItem:(a,d)=>n(y=>{const i=[...y];return i[a]=d,i}),setItemProp:(a,d,y)=>n(i=>{const w=[...i];return w[a]=Re(Ne({},w[a]),{[d]:y}),w})}]}function g(e,t,n){s.useEffect(()=>(window.addEventListener(e,t,n),()=>window.removeEventListener(e,t,n)),[])}function De({key:e,defaultValue:t=void 0}){const[n,o]=s.useState(typeof window!="undefined"&&"localStorage"in window?window.localStorage.getItem(e):t!=null?t:""),r=s.useCallback(u=>{typeof u=="function"?o(l=>{const f=u(l);return window.localStorage.setItem(e,f),f}):(window.localStorage.setItem(e,u),o(u))},[e]);return g("storage",u=>{u.storageArea===window.localStorage&&u.key===e&&o(u.newValue)}),s.useEffect(()=>{t&&!n&&r(t)},[t,n,r]),[n,r]}function Ce(...e){return t=>{e.forEach(n=>N(n,t))}}function ke({initialValues:e=[],limit:t}){const[{state:n,queue:o},r]=s.useState({state:e.slice(0,t),queue:e.slice(t)});return{state:n,queue:o,add:(...p)=>r(h=>{const m=[...h.state,...h.queue,...p];return{state:m.slice(0,t),queue:m.slice(t)}}),update:p=>r(h=>{const m=p([...h.state,...h.queue]);return{state:m.slice(0,t),queue:m.slice(t)}}),cleanQueue:()=>r(p=>({state:p.state,queue:[]}))}}function je(){return _("(prefers-reduced-motion: reduce)")}const q=e=>{e.preventDefault()};function Ae(e,t={disableTouchEvents:!1}){const n=s.useRef(!1),o=s.useRef(null),r=()=>{n.current&&(n.current=!1,document.body.style.overflow=o.current||"",t.disableTouchEvents&&document.body.removeEventListener("touchmove",q))},u=()=>{n.current=!0,o.current=document.body.style.overflow,document.body.style.overflow="hidden",t.disableTouchEvents&&document.body.addEventListener("touchmove",q,{passive:!1})};s.useEffect(()=>(e?u():r(),r),[e])}function U(e,t){const[n,o]=s.useState(e);return[n,u=>{typeof u!="undefined"?o(u):o(l=>l===t[0]?t[1]:t[0])}]}function He(e=!1){return U(e,[!0,!1])}function Me({value:e,defaultValue:t,finalValue:n,rule:o,onChange:r,onValueUpdate:u}){const l=o(e),f=s.useRef("initial"),p=o(t)?t:n,[h,m]=s.useState(p);let a=l?e:h;!l&&f.current==="controlled"&&(a=n),f.current=l?"controlled":"uncontrolled";const d=f.current,y=i=>{typeof r=="function"&&r(i),d==="uncontrolled"&&m(i)};return s.useEffect(()=>{d==="uncontrolled"&&m(a),typeof u=="function"&&u(a)},[d,a]),[a,y,f.current]}function T(){return typeof window!="undefined"?{x:window.pageXOffset,y:window.pageYOffset}:{x:0,y:0}}function $e({x:e,y:t}){if(typeof window!="undefined"){const n={behavior:"smooth"};typeof e=="number"&&(n.left=e),typeof t=="number"&&(n.top=t),window.scrollTo(n)}}function Ve(){const[e,t]=s.useState(T());return g("scroll",()=>t(T())),g("resize",()=>t(T())),[e,$e]}function Ke(e){const[t,n]=s.useState(null),o=s.useRef();return[s.useCallback(u=>{if(o.current&&(o.current.disconnect(),o.current=null),u===null){n(null);return}o.current=new IntersectionObserver(([l])=>{n(l)},e),o.current.observe(u)},[e==null?void 0:e.rootMargin,e==null?void 0:e.root,e==null?void 0:e.threshold]),t]}function qe(){const[e,t]=s.useState(null),n=o=>{window.location.hash=o,t(o)};return g("hashchange",()=>{t(window.location.hash)}),[e,n]}var Ue=Object.defineProperty,Be=Object.defineProperties,Qe=Object.getOwnPropertyDescriptors,B=Object.getOwnPropertySymbols,We=Object.prototype.hasOwnProperty,ze=Object.prototype.propertyIsEnumerable,Q=(e,t,n)=>t in e?Ue(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Xe=(e,t)=>{for(var n in t||(t={}))We.call(t,n)&&Q(e,n,t[n]);if(B)for(var n of B(t))ze.call(t,n)&&Q(e,n,t[n]);return e},Ye=(e,t)=>Be(e,Qe(t));function Ge(e){const t=e.toLowerCase().split("+").map(u=>u.trim()),n={alt:t.includes("alt"),ctrl:t.includes("ctrl"),meta:t.includes("meta"),mod:t.includes("mod"),shift:t.includes("shift")},o=["alt","ctrl","meta","shift","mod"],r=t.find(u=>!o.includes(u));return Ye(Xe({},n),{key:r})}function Je(e,t){const{alt:n,ctrl:o,meta:r,mod:u,shift:l,key:f}=e,{altKey:p,ctrlKey:h,metaKey:m,shiftKey:a,key:d}=t;if(n!==p)return!1;if(u){if(!h&&!m)return!1}else if(o!==h||r!==m)return!1;return l!==a?!1:!!(f&&(d.toLowerCase()===f.toLowerCase()||t.code.replace("Key","").toLowerCase()===f.toLowerCase()))}function W(e){return t=>Je(Ge(e),t)}function Ze(e){return t=>{e.forEach(([n,o])=>{W(n)(t.nativeEvent)&&(t.preventDefault(),o(t))})}}function xe(e){s.useEffect(()=>{const t=n=>{e.forEach(([o,r])=>{W(o)(n)&&(n.preventDefault(),r(n))})};return document.documentElement.addEventListener("keydown",t),()=>document.documentElement.removeEventListener("keydown",t)},[e])}c.assignRef=N,c.clamp=Y,c.getHotkeyHandler=Ze,c.lowerFirst=X,c.randomId=I,c.upperFirst=z,c.useBooleanToggle=He,c.useClickOutside=G,c.useClipboard=J,c.useColorScheme=ee,c.useDebouncedValue=te,c.useDidUpdate=re,c.useDocumentTitle=ne,c.useFocusTrap=pe,c.useForceUpdate=we,c.useForm=Ee,c.useHash=qe,c.useHotkeys=xe,c.useId=_e,c.useIntersection=Ke,c.useInterval=Se,c.useIsomorphicEffect=R,c.useListState=Fe,c.useLocalStorageValue=De,c.useMediaQuery=_,c.useMergedRef=Ce,c.useQueue=ke,c.useReducedMotion=je,c.useScrollLock=Ae,c.useToggle=U,c.useUncontrolled=Me,c.useWindowEvent=g,c.useWindowScroll=Ve,Object.defineProperty(c,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -1,2 +0,2 @@ | ||
export declare function useFocusTrap(active?: boolean): (instance: HTMLElement) => void; | ||
export declare function useFocusTrap(active?: boolean): (instance: HTMLElement | null) => void; | ||
//# sourceMappingURL=use-focus-trap.d.ts.map |
{ | ||
"name": "@mantine/hooks", | ||
"version": "2.0.7", | ||
"version": "2.1.0-alpha.0", | ||
"main": "cjs/index.js", | ||
@@ -5,0 +5,0 @@ "module": "esm/index.js", |
@@ -46,2 +46,3 @@ # Mantine Hooks | ||
- [use-isomorphic-effect](https://mantine.dev/hooks/use-isomorphic-effect/) – switch between useEffect during SSR and useLayoutEffect after hydration | ||
- [use-hash](https://mantine.dev/hooks/use-hash/) – get and set hash value in url | ||
@@ -48,0 +49,0 @@ ## Licence |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
306122
228
2178
51
3