@mantine/hooks
Advanced tools
Comparing version 1.4.0-alpha.0 to 1.4.0-alpha.1
@@ -23,2 +23,3 @@ 'use strict'; | ||
var useScrollLock = require('./use-scroll-lock/use-scroll-lock.js'); | ||
var useUncontrolled = require('./use-uncontrolled/use-uncontrolled.js'); | ||
var useWindowEvent = require('./use-window-event/use-window-event.js'); | ||
@@ -29,2 +30,3 @@ var randomId = require('./utils/random-id/random-id.js'); | ||
var assignRef = require('./utils/assign-ref/assign-ref.js'); | ||
var clamp = require('./utils/clamp/clamp.js'); | ||
@@ -51,2 +53,3 @@ | ||
exports.useScrollLock = useScrollLock.useScrollLock; | ||
exports.useUncontrolled = useUncontrolled.useUncontrolled; | ||
exports.useWindowEvent = useWindowEvent.useWindowEvent; | ||
@@ -57,2 +60,3 @@ exports.randomId = randomId.randomId; | ||
exports.assignRef = assignRef.assignRef; | ||
exports.clamp = clamp.clamp; | ||
//# sourceMappingURL=index.js.map |
@@ -5,6 +5,6 @@ 'use strict'; | ||
var react = require('react'); | ||
var useIsomorphicEffect = require('../use-isomorphic-effect/use-isomorphic-effect.js'); | ||
function useDocumentTitle(title) { | ||
react.useLayoutEffect(() => { | ||
useIsomorphicEffect.useIsomorphicEffect(() => { | ||
if (typeof title === "string" && title.trim().length > 0) { | ||
@@ -11,0 +11,0 @@ document.title = title.trim(); |
@@ -19,2 +19,3 @@ export { useClickOutside } from './use-click-outside/use-click-outside.js'; | ||
export { useScrollLock } from './use-scroll-lock/use-scroll-lock.js'; | ||
export { useUncontrolled } from './use-uncontrolled/use-uncontrolled.js'; | ||
export { useWindowEvent } from './use-window-event/use-window-event.js'; | ||
@@ -25,2 +26,3 @@ export { randomId } from './utils/random-id/random-id.js'; | ||
export { assignRef } from './utils/assign-ref/assign-ref.js'; | ||
export { clamp } from './utils/clamp/clamp.js'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,5 +0,5 @@ | ||
import { useLayoutEffect } from 'react'; | ||
import { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect.js'; | ||
function useDocumentTitle(title) { | ||
useLayoutEffect(() => { | ||
useIsomorphicEffect(() => { | ||
if (typeof title === "string" && title.trim().length > 0) { | ||
@@ -6,0 +6,0 @@ document.title = title.trim(); |
@@ -20,3 +20,4 @@ export * from './utils'; | ||
export { useScrollLock } from './use-scroll-lock/use-scroll-lock'; | ||
export { useUncontrolled } from './use-uncontrolled/use-uncontrolled'; | ||
export { useWindowEvent } from './use-window-event/use-window-event'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
(function(i,o){typeof exports=="object"&&typeof module!="undefined"?o(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],o):(i=typeof globalThis!="undefined"?globalThis:i||self,o(i["@mantine/hooks"]={},i.React))})(this,function(i,o){"use strict";function T(){return`mantine-${Math.random().toString(36).substr(2,9)}`}function H(e){return typeof e!="string"?"":e.charAt(0).toUpperCase()+e.slice(1)}function Q(e){return typeof e!="string"?"":e.charAt(0).toLowerCase()+e.slice(1)}function I(e,t){typeof e=="function"?e(t):typeof e=="object"&&e!==null&&"current"in e&&(e.current=t)}function B(e,t=["mousedown","touchstart"]){const n=o.useRef();return o.useEffect(()=>{const s=r=>{n.current&&!n.current.contains(r.target)&&e()};return t.forEach(r=>document.addEventListener(r,s)),()=>{t.forEach(r=>document.removeEventListener(r,s))}},[n,e]),n}function U({timeout:e=2e3}={}){const[t,n]=o.useState(null),[s,r]=o.useState(!1),[u,d]=o.useState(null),f=w=>{clearTimeout(u),d(setTimeout(()=>r(!1),e)),r(w)};return{copy:w=>{"clipboard"in navigator?navigator.clipboard.writeText(w).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:s}}function K(e,t){try{return e.addEventListener("change",t),()=>e.removeEventListener("change",t)}catch(n){return e.addListener(t),()=>e.removeListener(t)}}function W(e){return typeof window!="undefined"&&"matchMedia"in window?window.matchMedia(e).matches:!1}function g(e){const[t,n]=o.useState(W(e)),s=o.useRef();return o.useEffect(()=>{if("matchMedia"in window)return s.current=window.matchMedia(e),n(s.current.matches),K(s.current,r=>n(r.matches))},[e]),t}function z(){return g("(prefers-color-scheme: dark)")?"dark":"light"}function G(e,t,n={leading:!1}){const[s,r]=o.useState(e),u=o.useRef(!1),d=o.useRef(null),f=o.useRef(!1),p=()=>window.clearTimeout(d.current);return o.useEffect(()=>{u.current&&(!f.current&&n.leading?(f.current=!0,r(e)):(p(),d.current=window.setTimeout(()=>{f.current=!1,r(e)},t)))},[e,n.leading]),o.useEffect(()=>(u.current=!0,p),[]),[s,p]}function J(e){o.useLayoutEffect(()=>{typeof e=="string"&&e.trim().length>0&&(document.title=e.trim())},[e])}function X(e,t){const n=o.useRef(!1);o.useEffect(()=>{n.current?e():n.current=!0},t)}const Y=/input|select|textarea|button|object/,N="a, input, select, textarea, button, object, [tabindex]";function Z(e){return process.env.NODE_ENV==="test"?!1:e.offsetWidth<=0&&e.offsetHeight<=0||e.style.display==="none"}function x(e){let t=e;for(;t&&t!==document.body;){if(Z(t))return!1;t=t.parentNode}return!0}function P(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(P(e));return(Y.test(t)&&!e.disabled||e instanceof HTMLAnchorElement&&e.href||n)&&x(e)}function F(e){const t=P(e);return(Number.isNaN(t)||t>=0)&&S(e)}function R(e){return Array.from(e.querySelectorAll(N)).filter(F)}const D=[];let v=null,_=!1;function A(){_=!0}function C(){if(_){if(_=!1,!v||!v||v.contains(document.activeElement))return;(R(v)[0]||v).focus()}}function ee(){D.push(document.activeElement)}function te(){let e=null;try{e=D.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 ne(e){v=e,document.addEventListener("focusout",A,!1),document.addEventListener("focusin",C,!0)}function re(){v=null,document.removeEventListener("focusout",A),document.removeEventListener("focusin",C)}function oe(e,t){const n=R(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 se(e,t="body > :not(script)"){const n=Array.from(document.querySelectorAll(t)).map(s=>{if(s.contains(e))return;const r=s.getAttribute("aria-hidden");return(r===null||r==="false")&&s.setAttribute("aria-hidden","true"),{node:s,ariaHidden:r}});return()=>{n.forEach(s=>{!s||(s.ariaHidden===null?s.node.removeAttribute("aria-hidden"):s.node.setAttribute("aria-hidden",s.ariaHidden))})}}function ue(e=!0){const t=o.useRef(),n=o.useRef(null),s=o.useCallback(r=>{if(n.current&&n.current(),t.current&&(te(),re()),e&&r){ne(r),ee();const u=d=>{n.current=se(d);let f=r.querySelector("[data-autofocus]");if(!f){const p=Array.from(r.querySelectorAll(N));f=p.find(F)||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 o.useEffect(()=>{if(!e)return;const r=u=>{u.key==="Tab"&&t.current&&oe(t.current,u)};return document.addEventListener("keydown",r),()=>{document.removeEventListener("keydown",r)}},[e]),s}var ce=Object.defineProperty,ie=Object.defineProperties,ae=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertySymbols,fe=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable,M=(e,t,n)=>t in e?ce(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,O=(e,t)=>{for(var n in t||(t={}))fe.call(t,n)&&M(e,n,t[n]);if(j)for(var n of j(t))le.call(t,n)&&M(e,n,t[n]);return e},L=(e,t)=>ie(e,ae(t));function de({initialValues:e,validationRules:t={}}){const n=Object.keys(e).reduce((c,l)=>(c[l]=!1,c),{}),[s,r]=o.useState(n),[u,d]=o.useState(e),f=()=>r(n),p=()=>{d(e),f()},h=()=>{let c=!0;const l=Object.keys(u).reduce((E,y)=>(t&&typeof t[y]=="function"&&!t[y](u[y])?(E[y]=!0,c=!1):E[y]=!1,E),{});return r(l),c},w=c=>r(l=>L(O({},l),{[c]:typeof t[c]=="function"?!t[c](u[c]):!1})),a=(c,l)=>r(E=>L(O({},E),{[c]:l}));return{values:u,errors:s,validate:h,reset:p,setErrors:r,setValues:d,setFieldValue:(c,l)=>{d(E=>L(O({},E),{[c]:l})),a(c,!1)},setFieldError:a,validateField:w,resetErrors:f,onSubmit:c=>l=>{l&&l.preventDefault(),h()&&c(u)}}}function pe(e,t=T){const n=o.useRef(t());return e||n.current}function me(e,t){const[n,s]=o.useState(!1),r=o.useRef(),u=()=>{s(!0),r.current=window.setInterval(e,t)},d=()=>{s(!1),window.clearInterval(r.current)};return{start:u,stop:d,toggle:()=>{n?d():u()},active:n}}const be=typeof document!="undefined"?o.useLayoutEffect:o.useEffect;var we=Object.defineProperty,he=Object.defineProperties,ve=Object.getOwnPropertyDescriptors,k=Object.getOwnPropertySymbols,Ee=Object.prototype.hasOwnProperty,ye=Object.prototype.propertyIsEnumerable,V=(e,t,n)=>t in e?we(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ge=(e,t)=>{for(var n in t||(t={}))Ee.call(t,n)&&V(e,n,t[n]);if(k)for(var n of k(t))ye.call(t,n)&&V(e,n,t[n]);return e},Se=(e,t)=>he(e,ve(t));function _e(e=[]){const[t,n]=o.useState(e);return[t,{setState:n,append:(...a)=>n(m=>[...m,...a]),prepend:(...a)=>n(m=>[...a,...m]),insert:(a,...m)=>n(b=>[...b.slice(0,a),...m,...b.slice(a)]),apply:a=>n(m=>m.map((b,c)=>a(b,c))),remove:(...a)=>n(m=>m.filter((b,c)=>!a.includes(c))),reorder:({from:a,to:m})=>n(b=>{const c=[...b],l=b[a];return c.splice(a,1),c.splice(m,0,l),c}),setItem:(a,m)=>n(b=>{const c=[...b];return c[a]=m,c}),setItemProp:(a,m,b)=>n(c=>{const l=[...c];return l[a]=Se(ge({},l[a]),{[m]:b}),l})}]}function $(e,t,n){o.useEffect(()=>(window.addEventListener(e,t,n),()=>window.removeEventListener(e,t,n)),[])}function Oe({key:e,defaultValue:t=void 0}){const[n,s]=o.useState(typeof window!="undefined"&&"localStorage"in window?window.localStorage.getItem(e):t!=null?t:""),r=o.useCallback(u=>{typeof u=="function"?s(d=>{const f=u(d);return window.localStorage.setItem(e,f),f}):(window.localStorage.setItem(e,u),s(u))},[e]);return $("storage",u=>{u.storageArea===window.localStorage&&u.key===e&&s(u.newValue)}),o.useEffect(()=>{t&&!n&&r(t)},[t,n,r]),[n,r]}function Le(...e){return t=>{e.forEach(n=>I(n,t))}}function Te({initialValues:e=[],limit:t}){const[{state:n,queue:s},r]=o.useState({state:e.slice(0,t),queue:e.slice(t)});return{state:n,queue:s,add:(...p)=>r(h=>{const w=[...h.state,...h.queue,...p];return{state:w.slice(0,t),queue:w.slice(t)}}),update:p=>r(h=>{const w=p([...h.state,...h.queue]);return{state:w.slice(0,t),queue:w.slice(t)}}),cleanQueue:()=>r(p=>({state:p.state,queue:[]}))}}function Ie(){return g("(prefers-reduced-motion: reduce)")}const q=e=>{e.preventDefault()};function Ne(e,t={disableTouchEvents:!1}){const n=o.useRef(!1),s=o.useRef(null),r=()=>{n.current&&(n.current=!1,document.body.style.overflow=s.current||"",t.disableTouchEvents&&document.body.removeEventListener("touchmove",q))},u=()=>{n.current=!0,s.current=document.body.style.overflow,document.body.style.overflow="hidden",t.disableTouchEvents&&document.body.addEventListener("touchmove",q,{passive:!1})};o.useEffect(()=>(e?u():r(),r),[e])}i.assignRef=I,i.lowerFirst=Q,i.randomId=T,i.upperFirst=H,i.useClickOutside=B,i.useClipboard=U,i.useColorScheme=z,i.useDebouncedValue=G,i.useDidUpdate=X,i.useDocumentTitle=J,i.useFocusTrap=ue,i.useForm=de,i.useId=pe,i.useInterval=me,i.useIsomorphicEffect=be,i.useListState=_e,i.useLocalStorageValue=Oe,i.useMediaQuery=g,i.useMergedRef=Le,i.useQueue=Te,i.useReducedMotion=Ie,i.useScrollLock=Ne,i.useWindowEvent=$,Object.defineProperty(i,"__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 L(){return`mantine-${Math.random().toString(36).substr(2,9)}`}function Q(e){return typeof e!="string"?"":e.charAt(0).toUpperCase()+e.slice(1)}function U(e){return typeof e!="string"?"":e.charAt(0).toLowerCase()+e.slice(1)}function I(e,t){typeof e=="function"?e(t):typeof e=="object"&&e!==null&&"current"in e&&(e.current=t)}function B({value:e,min:t,max:n}){return Math.min(Math.max(e,t),n)}function K(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 W({timeout:e=2e3}={}){const[t,n]=s.useState(null),[o,r]=s.useState(!1),[u,l]=s.useState(null),a=b=>{clearTimeout(u),l(setTimeout(()=>r(!1),e)),r(b)};return{copy:b=>{"clipboard"in navigator?navigator.clipboard.writeText(b).then(()=>a(!0)).catch(f=>n(f)):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 G(e){return typeof window!="undefined"&&"matchMedia"in window?window.matchMedia(e).matches:!1}function g(e){const[t,n]=s.useState(G(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 J(){return g("(prefers-color-scheme: dark)")?"dark":"light"}function X(e,t,n={leading:!1}){const[o,r]=s.useState(e),u=s.useRef(!1),l=s.useRef(null),a=s.useRef(!1),d=()=>window.clearTimeout(l.current);return s.useEffect(()=>{u.current&&(!a.current&&n.leading?(a.current=!0,r(e)):(d(),l.current=window.setTimeout(()=>{a.current=!1,r(e)},t)))},[e,n.leading]),s.useEffect(()=>(u.current=!0,d),[]),[o,d]}const N=typeof document!="undefined"?s.useLayoutEffect:s.useEffect;function Y(e){N(()=>{typeof e=="string"&&e.trim().length>0&&(document.title=e.trim())},[e])}function Z(e,t){const n=s.useRef(!1);s.useEffect(()=>{n.current?e():n.current=!0},t)}const x=/input|select|textarea|button|object/,P="a, input, select, textarea, button, object, [tabindex]";function ee(e){return process.env.NODE_ENV==="test"?!1:e.offsetWidth<=0&&e.offsetHeight<=0||e.style.display==="none"}function te(e){let t=e;for(;t&&t!==document.body;){if(ee(t))return!1;t=t.parentNode}return!0}function F(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(F(e));return(x.test(t)&&!e.disabled||e instanceof HTMLAnchorElement&&e.href||n)&&te(e)}function R(e){const t=F(e);return(Number.isNaN(t)||t>=0)&&S(e)}function D(e){return Array.from(e.querySelectorAll(P)).filter(R)}const A=[];let E=null,_=!1;function C(){_=!0}function M(){if(_){if(_=!1,!E||!E||E.contains(document.activeElement))return;(D(E)[0]||E).focus()}}function ne(){A.push(document.activeElement)}function re(){let e=null;try{e=A.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 oe(e){E=e,document.addEventListener("focusout",C,!1),document.addEventListener("focusin",M,!0)}function se(){E=null,document.removeEventListener("focusout",C),document.removeEventListener("focusin",M)}function ue(e,t){const n=D(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 ce(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 ie(e=!0){const t=s.useRef(),n=s.useRef(null),o=s.useCallback(r=>{if(n.current&&n.current(),t.current&&(re(),se()),e&&r){oe(r),ne();const u=l=>{n.current=ce(l);let a=r.querySelector("[data-autofocus]");if(!a){const d=Array.from(r.querySelectorAll(P));a=d.find(R)||d.find(S)||null,!a&&S(r)&&(a=r)}a?a.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&&ue(t.current,u)};return document.addEventListener("keydown",r),()=>{document.removeEventListener("keydown",r)}},[e]),o}var ae=Object.defineProperty,fe=Object.defineProperties,le=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertySymbols,de=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable,k=(e,t,n)=>t in e?ae(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,O=(e,t)=>{for(var n in t||(t={}))de.call(t,n)&&k(e,n,t[n]);if(j)for(var n of j(t))pe.call(t,n)&&k(e,n,t[n]);return e},T=(e,t)=>fe(e,le(t));function me({initialValues:e,validationRules:t={}}){const n=Object.keys(e).reduce((i,p)=>(i[p]=!1,i),{}),[o,r]=s.useState(n),[u,l]=s.useState(e),a=()=>r(n),d=()=>{l(e),a()},h=()=>{let i=!0;const p=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 r(p),i},b=i=>r(p=>T(O({},p),{[i]:typeof t[i]=="function"?!t[i](u[i]):!1})),f=(i,p)=>r(v=>T(O({},v),{[i]:p}));return{values:u,errors:o,validate:h,reset:d,setErrors:r,setValues:l,setFieldValue:(i,p)=>{l(v=>T(O({},v),{[i]:p})),f(i,!1)},setFieldError:f,validateField:b,resetErrors:a,onSubmit:i=>p=>{p&&p.preventDefault(),h()&&i(u)}}}function be(e,t=L){const n=s.useRef(t());return e||n.current}function we(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 he=Object.defineProperty,Ee=Object.defineProperties,ve=Object.getOwnPropertyDescriptors,V=Object.getOwnPropertySymbols,ye=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,Se=(e,t)=>{for(var n in t||(t={}))ye.call(t,n)&&$(e,n,t[n]);if(V)for(var n of V(t))ge.call(t,n)&&$(e,n,t[n]);return e},_e=(e,t)=>Ee(e,ve(t));function Oe(e=[]){const[t,n]=s.useState(e);return[t,{setState:n,append:(...f)=>n(m=>[...m,...f]),prepend:(...f)=>n(m=>[...f,...m]),insert:(f,...m)=>n(w=>[...w.slice(0,f),...m,...w.slice(f)]),apply:f=>n(m=>m.map((w,i)=>f(w,i))),remove:(...f)=>n(m=>m.filter((w,i)=>!f.includes(i))),reorder:({from:f,to:m})=>n(w=>{const i=[...w],p=w[f];return i.splice(f,1),i.splice(m,0,p),i}),setItem:(f,m)=>n(w=>{const i=[...w];return i[f]=m,i}),setItemProp:(f,m,w)=>n(i=>{const p=[...i];return p[f]=_e(Se({},p[f]),{[m]:w}),p})}]}function q(e,t,n){s.useEffect(()=>(window.addEventListener(e,t,n),()=>window.removeEventListener(e,t,n)),[])}function Te({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 a=u(l);return window.localStorage.setItem(e,a),a}):(window.localStorage.setItem(e,u),o(u))},[e]);return q("storage",u=>{u.storageArea===window.localStorage&&u.key===e&&o(u.newValue)}),s.useEffect(()=>{t&&!n&&r(t)},[t,n,r]),[n,r]}function Le(...e){return t=>{e.forEach(n=>I(n,t))}}function Ie({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:(...d)=>r(h=>{const b=[...h.state,...h.queue,...d];return{state:b.slice(0,t),queue:b.slice(t)}}),update:d=>r(h=>{const b=d([...h.state,...h.queue]);return{state:b.slice(0,t),queue:b.slice(t)}}),cleanQueue:()=>r(d=>({state:d.state,queue:[]}))}}function Ne(){return g("(prefers-reduced-motion: reduce)")}const H=e=>{e.preventDefault()};function Pe(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",H))},u=()=>{n.current=!0,o.current=document.body.style.overflow,document.body.style.overflow="hidden",t.disableTouchEvents&&document.body.addEventListener("touchmove",H,{passive:!1})};s.useEffect(()=>(e?u():r(),r),[e])}function Fe({value:e,defaultValue:t,finalValue:n,rule:o,onChange:r,onValueUpdate:u}){const l=o(e)?e:o(t)?t:n,[a,d]=s.useState(l),h=b=>{typeof r=="function"&&r(b),d(b)};return s.useEffect(()=>{o(e)&&(d(e),typeof u=="function"&&u(e))},[e]),[a,h]}c.assignRef=I,c.clamp=B,c.lowerFirst=U,c.randomId=L,c.upperFirst=Q,c.useClickOutside=K,c.useClipboard=W,c.useColorScheme=J,c.useDebouncedValue=X,c.useDidUpdate=Z,c.useDocumentTitle=Y,c.useFocusTrap=ie,c.useForm=me,c.useId=be,c.useInterval=we,c.useIsomorphicEffect=N,c.useListState=Oe,c.useLocalStorageValue=Te,c.useMediaQuery=g,c.useMergedRef=Le,c.useQueue=Ie,c.useReducedMotion=Ne,c.useScrollLock=Pe,c.useUncontrolled=Fe,c.useWindowEvent=q,Object.defineProperty(c,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -5,2 +5,3 @@ export { randomId } from './random-id/random-id'; | ||
export { assignRef } from './assign-ref/assign-ref'; | ||
export { clamp } from './clamp/clamp'; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@mantine/hooks", | ||
"version": "1.4.0-alpha.0", | ||
"version": "1.4.0-alpha.1", | ||
"main": "cjs/index.js", | ||
@@ -11,2 +11,3 @@ "module": "esm/index.js", | ||
"sideEffects": false, | ||
"homepage": "https://mantine.dev/hooks/getting-started/", | ||
"repository": { | ||
@@ -13,0 +14,0 @@ "url": "https://github.com/mantinedev/mantine.git", |
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
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 website
QualityPackage does not have a website.
Found 1 instance in 1 package
234975
186
1696