@kubed/hooks 0.0.17 → 0.2.11
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/cjs/index.js +1 -1
- package/cjs/useClickOutside/index.js +1 -1
- package/cjs/useClickOutside/index.js.map +1 -1
- package/cjs/useClipboard/index.js +1 -1
- package/cjs/useClipboard/index.js.map +1 -1
- package/cjs/useDebouncedValue/index.js +1 -1
- package/cjs/useDebouncedValue/index.js.map +1 -1
- package/cjs/useDidMount/index.js +1 -1
- package/cjs/useDidMount/index.js.map +1 -1
- package/cjs/useDidUpdate/index.js +1 -1
- package/cjs/useDidUpdate/index.js.map +1 -1
- package/cjs/useDisclosure/index.js +1 -1
- package/cjs/useDisclosure/index.js.map +1 -1
- package/cjs/useForceUpdate/index.js +1 -1
- package/cjs/useForceUpdate/index.js.map +1 -1
- package/cjs/useHotkeys/index.js +1 -1
- package/cjs/useHotkeys/index.js.map +1 -1
- package/cjs/useHotkeys/parseHotkey.js +1 -1
- package/cjs/useHotkeys/parseHotkey.js.map +1 -1
- package/cjs/useHover/index.js +1 -1
- package/cjs/useHover/index.js.map +1 -1
- package/cjs/useId/index.js +1 -1
- package/cjs/useId/index.js.map +1 -1
- package/cjs/useLocalStorage/index.js +1 -1
- package/cjs/useLocalStorage/index.js.map +1 -1
- package/cjs/useMediaQuery/index.js +1 -1
- package/cjs/useMediaQuery/index.js.map +1 -1
- package/cjs/useMergedRef/index.js +1 -1
- package/cjs/useMergedRef/index.js.map +1 -1
- package/cjs/useMove/index.js +1 -1
- package/cjs/useMove/index.js.map +1 -1
- package/cjs/usePrevious/index.js +1 -1
- package/cjs/usePrevious/index.js.map +1 -1
- package/cjs/useQueue/index.js +1 -1
- package/cjs/useQueue/index.js.map +1 -1
- package/cjs/useReducedMotion/index.js +1 -1
- package/cjs/useReducedMotion/index.js.map +1 -1
- package/cjs/useScrollLock/index.js +1 -1
- package/cjs/useScrollLock/index.js.map +1 -1
- package/cjs/useToggle/index.js +1 -1
- package/cjs/useToggle/index.js.map +1 -1
- package/cjs/useUncontrolled/index.js +1 -1
- package/cjs/useUncontrolled/index.js.map +1 -1
- package/cjs/useUnmount/index.js +1 -1
- package/cjs/useUnmount/index.js.map +1 -1
- package/cjs/useWindowEvent/index.js +1 -1
- package/cjs/useWindowEvent/index.js.map +1 -1
- package/cjs/useWindowResize/index.js +1 -1
- package/cjs/useWindowResize/index.js.map +1 -1
- package/cjs/utils/index.js +1 -1
- package/cjs/utils/index.js.map +1 -1
- package/esm/index.js +1 -1
- package/esm/useClickOutside/index.js +1 -1
- package/esm/useClickOutside/index.js.map +1 -1
- package/esm/useClipboard/index.js +1 -1
- package/esm/useClipboard/index.js.map +1 -1
- package/esm/useDebouncedValue/index.js +1 -1
- package/esm/useDebouncedValue/index.js.map +1 -1
- package/esm/useDidMount/index.js +1 -1
- package/esm/useDidMount/index.js.map +1 -1
- package/esm/useDidUpdate/index.js +1 -1
- package/esm/useDidUpdate/index.js.map +1 -1
- package/esm/useDisclosure/index.js +1 -1
- package/esm/useDisclosure/index.js.map +1 -1
- package/esm/useForceUpdate/index.js +1 -1
- package/esm/useForceUpdate/index.js.map +1 -1
- package/esm/useHotkeys/index.js +1 -1
- package/esm/useHotkeys/index.js.map +1 -1
- package/esm/useHotkeys/parseHotkey.js +1 -1
- package/esm/useHotkeys/parseHotkey.js.map +1 -1
- package/esm/useHover/index.js +1 -1
- package/esm/useHover/index.js.map +1 -1
- package/esm/useId/index.js +1 -1
- package/esm/useId/index.js.map +1 -1
- package/esm/useLocalStorage/index.js +1 -1
- package/esm/useLocalStorage/index.js.map +1 -1
- package/esm/useMediaQuery/index.js +1 -1
- package/esm/useMediaQuery/index.js.map +1 -1
- package/esm/useMergedRef/index.js +1 -1
- package/esm/useMergedRef/index.js.map +1 -1
- package/esm/useMove/index.js +1 -1
- package/esm/useMove/index.js.map +1 -1
- package/esm/usePrevious/index.js +1 -1
- package/esm/usePrevious/index.js.map +1 -1
- package/esm/useQueue/index.js +1 -1
- package/esm/useQueue/index.js.map +1 -1
- package/esm/useReducedMotion/index.js.map +1 -1
- package/esm/useScrollLock/index.js +1 -1
- package/esm/useScrollLock/index.js.map +1 -1
- package/esm/useToggle/index.js +1 -1
- package/esm/useToggle/index.js.map +1 -1
- package/esm/useUncontrolled/index.js +1 -1
- package/esm/useUncontrolled/index.js.map +1 -1
- package/esm/useUnmount/index.js +1 -1
- package/esm/useUnmount/index.js.map +1 -1
- package/esm/useWindowEvent/index.js +1 -1
- package/esm/useWindowEvent/index.js.map +1 -1
- package/esm/useWindowResize/index.js +1 -1
- package/esm/useWindowResize/index.js.map +1 -1
- package/esm/utils/index.js +1 -1
- package/esm/utils/index.js.map +1 -1
- package/lib/useHover/index.d.ts +0 -1
- package/lib/useHover/index.d.ts.map +1 -1
- package/lib/useMove/index.d.ts +0 -1
- package/lib/useMove/index.d.ts.map +1 -1
- package/package.json +10 -12
- package/CHANGELOG.md +0 -102
package/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./utils/index.js"),i=require("./useId/index.js"),u=require("./useToggle/index.js"),r=require("./useUncontrolled/index.js"),d=require("./useMediaQuery/index.js"),n=require("./useReducedMotion/index.js"),o=require("./useWindowEvent/index.js"),a=require("./useLocalStorage/index.js"),x=require("./useForceUpdate/index.js"),l=require("./useClipboard/index.js"),v=require("./useQueue/index.js"),t=require("./useClickOutside/index.js"),c=require("./useMove/index.js"),j=require("./useHotkeys/index.js"),s=require("./useMergedRef/index.js"),q=require("./useDebouncedValue/index.js"),$=require("./useDidMount/index.js"),g=require("./useDidUpdate/index.js"),M=require("./useUnmount/index.js"),R=require("./usePrevious/index.js"),p=require("./useScrollLock/index.js"),D=require("./useHover/index.js"),U=require("./useWindowResize/index.js"),k=require("./useDisclosure/index.js");exports.assignRef=e.assignRef,exports.clamp=e.clamp,exports.randomId=e.randomId,exports.useId=i.useId,exports.useBooleanToggle=u.useBooleanToggle,exports.useToggle=u.useToggle,exports.useUncontrolled=r.useUncontrolled,exports.useMediaQuery=d.useMediaQuery,exports.useReducedMotion=n.useReducedMotion,exports.useWindowEvent=o.useWindowEvent,exports.useLocalStorage=a.useLocalStorage,exports.useForceUpdate=x.useForceUpdate,exports.useClipboard=l.useClipboard,exports.useQueue=v.useQueue,exports.useClickOutside=t.useClickOutside,exports.useMove=c.useMove,exports.useHotkeys=j.useHotkeys,exports.mergeRefs=s.mergeRefs,exports.useMergedRef=s.useMergedRef,exports.useDebouncedValue=q.useDebouncedValue,exports.useDidMount=$.useDidMount,exports.useDidUpdate=g.useDidUpdate,exports.useUnmount=M.useUnmount,exports.usePrevious=R.usePrevious,exports.useScrollLock=p.useScrollLock,exports.useHover=D.useHover,exports.useWindowResize=U.useWindowResize,exports.useDisclosure=k.useDisclosure;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var o=require("react");const a=["mousedown","touchstart"];function i(r,u,s){const t=o.useRef();return o.useEffect(()=>{const c=e=>{Array.isArray(s)?s.every(n=>!!n&&!n.contains(e.target))&&r():t.current&&!t.current.contains(e.target)&&r()};return(u||a).forEach(e=>document.addEventListener(e,c)),()=>{(u||a).forEach(e=>document.removeEventListener(e,c))}},[t,r,s]),t}exports.useClickOutside=i;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useClickOutside/index.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nconst DEFAULT_EVENTS = ['mousedown', 'touchstart'];\n\nexport function useClickOutside<T extends HTMLElement = any>(\n handler: () => void,\n events?: string[] | null,\n nodes?: HTMLElement[]\n) {\n const ref = useRef<T>();\n\n useEffect(() => {\n const listener = (event: any) => {\n if (Array.isArray(nodes)) {\n const shouldTrigger = nodes.every((node) => !!node && !node.contains(event.target));\n shouldTrigger && handler();\n } else if (ref.current && !ref.current.contains(event.target)) {\n handler();\n }\n };\n\n (events || DEFAULT_EVENTS).forEach((fn) => document.addEventListener(fn, listener));\n\n return () => {\n (events || DEFAULT_EVENTS).forEach((fn) => document.removeEventListener(fn, listener));\n };\n }, [ref, handler, nodes]);\n\n return ref;\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useClickOutside/index.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nconst DEFAULT_EVENTS = ['mousedown', 'touchstart'];\n\nexport function useClickOutside<T extends HTMLElement = any>(\n handler: () => void,\n events?: string[] | null,\n nodes?: HTMLElement[]\n) {\n const ref = useRef<T>();\n\n useEffect(() => {\n const listener = (event: any) => {\n if (Array.isArray(nodes)) {\n const shouldTrigger = nodes.every((node) => !!node && !node.contains(event.target));\n shouldTrigger && handler();\n } else if (ref.current && !ref.current.contains(event.target)) {\n handler();\n }\n };\n\n (events || DEFAULT_EVENTS).forEach((fn) => document.addEventListener(fn, listener));\n\n return () => {\n (events || DEFAULT_EVENTS).forEach((fn) => document.removeEventListener(fn, listener));\n };\n }, [ref, handler, nodes]);\n\n return ref;\n}\n"],"names":["a","u"],"mappings":";;;;;;AAA8C,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,YAAY,CAAC,CAAQ,SAAS,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAACA,YAAC,EAAE,CAAC,OAAOC,eAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,GAAE,CAAC,CAAC,OAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var o=require("react");function p({timeout:i=2e3}={}){const[u,e]=o.useState(null),[l,t]=o.useState(!1),[a,c]=o.useState(null),n=r=>{clearTimeout(a),c(setTimeout(()=>t(!1),i)),t(r)};return{copy:r=>{"clipboard"in navigator?navigator.clipboard.writeText(r).then(()=>n(!0)).catch(s=>e(s)):e(new Error("useClipboard: navigator.clipboard is not supported"))},reset:()=>{t(!1),e(null),clearTimeout(a)},error:u,copied:l}}exports.useClipboard=p;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useClipboard/index.ts"],"sourcesContent":["import { useState } from 'react';\n\nexport function useClipboard({ timeout = 2000 } = {}) {\n const [error, setError] = useState<Error>(null);\n const [copied, setCopied] = useState(false);\n const [copyTimeout, setCopyTimeout] = useState(null);\n\n const handleCopyResult = (value: boolean) => {\n clearTimeout(copyTimeout);\n setCopyTimeout(setTimeout(() => setCopied(false), timeout));\n setCopied(value);\n };\n\n const copy = (valueToCopy: any) => {\n if ('clipboard' in navigator) {\n navigator.clipboard\n .writeText(valueToCopy)\n .then(() => handleCopyResult(true))\n .catch((err) => setError(err));\n } else {\n setError(new Error('useClipboard: navigator.clipboard is not supported'));\n }\n };\n\n const reset = () => {\n setCopied(false);\n setError(null);\n clearTimeout(copyTimeout);\n };\n\n return { copy, reset, error, copied };\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useClipboard/index.ts"],"sourcesContent":["import { useState } from 'react';\n\nexport function useClipboard({ timeout = 2000 } = {}) {\n const [error, setError] = useState<Error>(null);\n const [copied, setCopied] = useState(false);\n const [copyTimeout, setCopyTimeout] = useState(null);\n\n const handleCopyResult = (value: boolean) => {\n clearTimeout(copyTimeout);\n setCopyTimeout(setTimeout(() => setCopied(false), timeout));\n setCopied(value);\n };\n\n const copy = (valueToCopy: any) => {\n if ('clipboard' in navigator) {\n navigator.clipboard\n .writeText(valueToCopy)\n .then(() => handleCopyResult(true))\n .catch((err) => setError(err));\n } else {\n setError(new Error('useClipboard: navigator.clipboard is not supported'));\n }\n };\n\n const reset = () => {\n setCopied(false);\n setError(null);\n clearTimeout(copyTimeout);\n };\n\n return { copy, reset, error, copied };\n}\n"],"names":["r"],"mappings":";;;;;;AAAwC,SAAS,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,cAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,cAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,cAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,OAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,WAAW,GAAG,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,oDAAoD,CAAC,EAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,EAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function o(u,i,n={leading:!1}){const[l,c]=e.useState(u),s=e.useRef(!1),a=e.useRef(null),r=e.useRef(!1),t=()=>window.clearTimeout(a.current);return e.useEffect(()=>{s.current&&(!r.current&&n.leading?(r.current=!0,c(u)):(t(),a.current=window.setTimeout(()=>{r.current=!1,c(u)},i)))},[u,n.leading]),e.useEffect(()=>(s.current=!0,t),[]),[l,t]}exports.useDebouncedValue=o;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useDebouncedValue/index.ts"],"sourcesContent":["// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-debounced-value/use-debounced-value.ts\nimport { useEffect, useState, useRef } from 'react';\n\nexport function useDebouncedValue<T = any>(value: T, wait: number, options = { leading: false }) {\n const [_value, setValue] = useState(value);\n const mountedRef = useRef(false);\n const timeoutRef = useRef<number>(null);\n const cooldownRef = useRef(false);\n\n const cancel = () => window.clearTimeout(timeoutRef.current);\n\n useEffect(() => {\n if (mountedRef.current) {\n if (!cooldownRef.current && options.leading) {\n cooldownRef.current = true;\n setValue(value);\n } else {\n cancel();\n timeoutRef.current = window.setTimeout(() => {\n cooldownRef.current = false;\n setValue(value);\n }, wait);\n }\n }\n }, [value, options.leading]);\n\n useEffect(() => {\n mountedRef.current = true;\n return cancel;\n }, []);\n\n return [_value, cancel] as const;\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useDebouncedValue/index.ts"],"sourcesContent":["// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-debounced-value/use-debounced-value.ts\nimport { useEffect, useState, useRef } from 'react';\n\nexport function useDebouncedValue<T = any>(value: T, wait: number, options = { leading: false }) {\n const [_value, setValue] = useState(value);\n const mountedRef = useRef(false);\n const timeoutRef = useRef<number>(null);\n const cooldownRef = useRef(false);\n\n const cancel = () => window.clearTimeout(timeoutRef.current);\n\n useEffect(() => {\n if (mountedRef.current) {\n if (!cooldownRef.current && options.leading) {\n cooldownRef.current = true;\n setValue(value);\n } else {\n cancel();\n timeoutRef.current = window.setTimeout(() => {\n cooldownRef.current = false;\n setValue(value);\n }, wait);\n }\n }\n }, [value, options.leading]);\n\n useEffect(() => {\n mountedRef.current = true;\n return cancel;\n }, []);\n\n return [_value, cancel] as const;\n}\n"],"names":["i","r","f"],"mappings":";;;;;;AAAmE,SAAS,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,cAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACC,YAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,YAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAACA,YAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,OAAOC,eAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAACA,eAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;;;"}
|
package/cjs/useDidMount/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react");function u(e){t.useEffect(()=>{typeof e=="function"&&e()},[])}exports.useDidMount=u;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useDidMount/index.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nexport function useDidMount(callback: () => any): void {\n useEffect(() => {\n if (typeof callback === 'function') {\n callback();\n }\n }, []);\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useDidMount/index.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nexport function useDidMount(callback: () => any): void {\n useEffect(() => {\n if (typeof callback === 'function') {\n callback();\n }\n }, []);\n}\n"],"names":["t"],"mappings":";;;;;;AAAyC,SAAS,WAAW,CAAC,CAAC,CAAC,CAACA,eAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC,GAAE,CAAC,CAAC,EAAE,EAAC;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react");function c(r,u){const e=t.useRef(!1);t.useEffect(()=>{e.current?r():e.current=!0},u)}exports.useDidUpdate=c;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useDidUpdate/index.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nexport function useDidUpdate(fn: () => void, dependencies?: any[]) {\n const mounted = useRef(false);\n\n useEffect(() => {\n if (mounted.current) {\n fn();\n } else {\n mounted.current = true;\n }\n }, dependencies);\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useDidUpdate/index.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nexport function useDidUpdate(fn: () => void, dependencies?: any[]) {\n const mounted = useRef(false);\n\n useEffect(() => {\n if (mounted.current) {\n fn();\n } else {\n mounted.current = true;\n }\n }, dependencies);\n}\n"],"names":["f","u"],"mappings":";;;;;;AAAqD,SAAS,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAACA,YAAC,CAAC,CAAC,CAAC,CAAC,CAACC,eAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,EAAC;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function a(c=!1){const[s,t]=e.useState(c),u=e.useCallback(()=>t(!0),[]),r=e.useCallback(()=>t(!1),[]),l=e.useCallback(()=>s?r():u(),[s,r,u]);return{isOpen:s,open:u,close:r,toggle:l}}exports.useDisclosure=a;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useDisclosure/index.ts"],"sourcesContent":["import { useCallback, useState } from 'react';\n\nexport function useDisclosure(initialIsOpen = false) {\n const [isOpen, setIsOpen] = useState(initialIsOpen);\n\n const open = useCallback(() => setIsOpen(true), []);\n\n const close = useCallback(() => setIsOpen(false), []);\n\n const toggle = useCallback(() => (isOpen ? close() : open()), [isOpen, close, open]);\n\n return { isOpen, open, close, toggle };\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useDisclosure/index.ts"],"sourcesContent":["import { useCallback, useState } from 'react';\n\nexport function useDisclosure(initialIsOpen = false) {\n const [isOpen, setIsOpen] = useState(initialIsOpen);\n\n const open = useCallback(() => setIsOpen(true), []);\n\n const close = useCallback(() => setIsOpen(false), []);\n\n const toggle = useCallback(() => (isOpen ? close() : open()), [isOpen, close, open]);\n\n return { isOpen, open, close, toggle };\n}\n"],"names":["l","o"],"mappings":";;;;;;AAAyD,SAAS,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,cAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACC,iBAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAACA,iBAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAACA,iBAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("react");const t=e=>(e+1)%1e6;function u(){const[,e]=r.useReducer(t,0);return e}exports.useForceUpdate=u;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useForceUpdate/index.ts"],"sourcesContent":["import { useReducer } from 'react';\n\nconst reducer = (value: number) => (value + 1) % 1000000;\n\nexport function useForceUpdate(): () => void {\n const [, update] = useReducer(reducer, 0);\n return update;\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useForceUpdate/index.ts"],"sourcesContent":["import { useReducer } from 'react';\n\nconst reducer = (value: number) => (value + 1) % 1000000;\n\nexport function useForceUpdate(): () => void {\n const [, update] = useReducer(reducer, 0);\n return update;\n}\n"],"names":["r"],"mappings":";;;;;;AAAmC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAQ,SAAS,cAAc,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAACA,gBAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;;;;"}
|
package/cjs/useHotkeys/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var u=require("react"),s=require("./parseHotkey.js");function c(t){u.useEffect(()=>{const r=e=>{t.forEach(([n,o])=>{s.getHotkeyMatcher(n)(e)&&(e.preventDefault(),o(e))})};return document.documentElement.addEventListener("keydown",r),()=>document.documentElement.removeEventListener("keydown",r)},[t])}exports.useHotkeys=c;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useHotkeys/index.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { getHotkeyMatcher, getHotkeyHandler } from './parseHotkey';\n\nexport { getHotkeyHandler };\n\ntype HokeyItem = [string, (event: KeyboardEvent) => void];\n\nexport function useHotkeys(hotkeys: HokeyItem[]) {\n useEffect(() => {\n const keydownListener = (event: KeyboardEvent) => {\n hotkeys.forEach(([hotkey, handler]) => {\n if (getHotkeyMatcher(hotkey)(event)) {\n event.preventDefault();\n handler(event);\n }\n });\n };\n\n document.documentElement.addEventListener('keydown', keydownListener);\n return () => document.documentElement.removeEventListener('keydown', keydownListener);\n }, [hotkeys]);\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useHotkeys/index.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { getHotkeyMatcher, getHotkeyHandler } from './parseHotkey';\n\nexport { getHotkeyHandler };\n\ntype HokeyItem = [string, (event: KeyboardEvent) => void];\n\nexport function useHotkeys(hotkeys: HokeyItem[]) {\n useEffect(() => {\n const keydownListener = (event: KeyboardEvent) => {\n hotkeys.forEach(([hotkey, handler]) => {\n if (getHotkeyMatcher(hotkey)(event)) {\n event.preventDefault();\n handler(event);\n }\n });\n };\n\n document.documentElement.addEventListener('keydown', keydownListener);\n return () => document.documentElement.removeEventListener('keydown', keydownListener);\n }, [hotkeys]);\n}\n"],"names":["d","m"],"mappings":";;;;;;;AAA8I,SAAS,UAAU,CAAC,CAAC,CAAC,CAACA,eAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAACC,4BAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC,EAAC,CAAC,CAAC,OAAO,QAAQ,CAAC,eAAe,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,eAAe,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var b=Object.defineProperty,v=Object.defineProperties,O=Object.getOwnPropertyDescriptors,s=Object.getOwnPropertySymbols,h=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable,u=(t,e,r)=>e in t?b(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,k=(t,e)=>{for(var r in e||(e={}))h.call(e,r)&&u(t,r,e[r]);if(s)for(var r of s(e))w.call(e,r)&&u(t,r,e[r]);return t},j=(t,e)=>v(t,O(e));function f(t){const e=t.toLowerCase().split("+").map(o=>o.trim()),r={alt:e.includes("alt"),ctrl:e.includes("ctrl"),meta:e.includes("meta"),mod:e.includes("mod"),shift:e.includes("shift")},a=["alt","ctrl","meta","shift","mod"],n=e.find(o=>!a.includes(o));return j(k({},r),{key:n})}function K(t,e){const{alt:r,ctrl:a,meta:n,mod:o,shift:y,key:c}=t,{altKey:p,ctrlKey:i,metaKey:l,shiftKey:d,key:m}=e;if(r!==p)return!1;if(o){if(!i&&!l)return!1}else if(a!==i||n!==l)return!1;return y!==d?!1:!!(c&&(m.toLowerCase()===c.toLowerCase()||e.code.replace("Key","").toLowerCase()===c.toLowerCase()))}function P(t){return e=>K(f(t),e)}exports.getHotkeyMatcher=P,exports.parseHotkey=f;
|
|
2
2
|
//# sourceMappingURL=parseHotkey.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseHotkey.js","sources":["../../src/useHotkeys/parseHotkey.ts"],"sourcesContent":["export type KeyboardModifiers = {\n alt: boolean;\n ctrl: boolean;\n meta: boolean;\n mod: boolean;\n shift: boolean;\n};\n\nexport type Hotkey = KeyboardModifiers & {\n key?: string;\n};\n\ntype CheckHotkeyMatch = (event: KeyboardEvent) => boolean;\n\nexport function parseHotkey(hotkey: string): Hotkey {\n const keys = hotkey\n .toLowerCase()\n .split('+')\n .map((part) => part.trim());\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\n ctrl: keys.includes('ctrl'),\n meta: keys.includes('meta'),\n mod: keys.includes('mod'),\n shift: keys.includes('shift'),\n };\n\n const reservedKeys = ['alt', 'ctrl', 'meta', 'shift', 'mod'];\n\n const freeKey = keys.find((key) => !reservedKeys.includes(key));\n\n return {\n ...modifiers,\n key: freeKey,\n };\n}\n\nfunction isExactHotkey(hotkey: Hotkey, event: KeyboardEvent): boolean {\n const { alt, ctrl, meta, mod, shift, key } = hotkey;\n const { altKey, ctrlKey, metaKey, shiftKey, key: pressedKey } = event;\n\n if (alt !== altKey) {\n return false;\n }\n\n if (mod) {\n if (!ctrlKey && !metaKey) {\n return false;\n }\n } else {\n if (ctrl !== ctrlKey) {\n return false;\n }\n if (meta !== metaKey) {\n return false;\n }\n }\n if (shift !== shiftKey) {\n return false;\n }\n\n if (\n key &&\n (pressedKey.toLowerCase() === key.toLowerCase() ||\n event.code.replace('Key', '').toLowerCase() === key.toLowerCase())\n ) {\n return true;\n }\n\n return false;\n}\n\nexport function getHotkeyMatcher(hotkey: string): CheckHotkeyMatch {\n return (event) => isExactHotkey(parseHotkey(hotkey), event);\n}\n\ntype HotkeyItem = [string, (event: React.KeyboardEvent<HTMLElement>) => void];\n\nexport function getHotkeyHandler(hotkeys: HotkeyItem[]) {\n return (event: React.KeyboardEvent<HTMLElement>) => {\n hotkeys.forEach(([hotkey, handler]) => {\n if (getHotkeyMatcher(hotkey)(event.nativeEvent)) {\n event.preventDefault();\n handler(event);\n }\n });\n };\n}\n"],"names":[],"mappings":";;;;AAAA,IAAI,
|
|
1
|
+
{"version":3,"file":"parseHotkey.js","sources":["../../src/useHotkeys/parseHotkey.ts"],"sourcesContent":["export type KeyboardModifiers = {\n alt: boolean;\n ctrl: boolean;\n meta: boolean;\n mod: boolean;\n shift: boolean;\n};\n\nexport type Hotkey = KeyboardModifiers & {\n key?: string;\n};\n\ntype CheckHotkeyMatch = (event: KeyboardEvent) => boolean;\n\nexport function parseHotkey(hotkey: string): Hotkey {\n const keys = hotkey\n .toLowerCase()\n .split('+')\n .map((part) => part.trim());\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\n ctrl: keys.includes('ctrl'),\n meta: keys.includes('meta'),\n mod: keys.includes('mod'),\n shift: keys.includes('shift'),\n };\n\n const reservedKeys = ['alt', 'ctrl', 'meta', 'shift', 'mod'];\n\n const freeKey = keys.find((key) => !reservedKeys.includes(key));\n\n return {\n ...modifiers,\n key: freeKey,\n };\n}\n\nfunction isExactHotkey(hotkey: Hotkey, event: KeyboardEvent): boolean {\n const { alt, ctrl, meta, mod, shift, key } = hotkey;\n const { altKey, ctrlKey, metaKey, shiftKey, key: pressedKey } = event;\n\n if (alt !== altKey) {\n return false;\n }\n\n if (mod) {\n if (!ctrlKey && !metaKey) {\n return false;\n }\n } else {\n if (ctrl !== ctrlKey) {\n return false;\n }\n if (meta !== metaKey) {\n return false;\n }\n }\n if (shift !== shiftKey) {\n return false;\n }\n\n if (\n key &&\n (pressedKey.toLowerCase() === key.toLowerCase() ||\n event.code.replace('Key', '').toLowerCase() === key.toLowerCase())\n ) {\n return true;\n }\n\n return false;\n}\n\nexport function getHotkeyMatcher(hotkey: string): CheckHotkeyMatch {\n return (event) => isExactHotkey(parseHotkey(hotkey), event);\n}\n\ntype HotkeyItem = [string, (event: React.KeyboardEvent<HTMLElement>) => void];\n\nexport function getHotkeyHandler(hotkeys: HotkeyItem[]) {\n return (event: React.KeyboardEvent<HTMLElement>) => {\n hotkeys.forEach(([hotkey, handler]) => {\n if (getHotkeyMatcher(hotkey)(event.nativeEvent)) {\n event.preventDefault();\n handler(event);\n }\n });\n };\n}\n"],"names":[],"mappings":"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"}
|
package/cjs/useHover/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react");function v(){const[o,n]=t.useState(!1),r=t.useRef(null),s=()=>n(!0),u=()=>n(!1);return t.useEffect(()=>{const e=r==null?void 0:r.current;if(e)return e.addEventListener("mouseenter",s),e.addEventListener("mouseleave",u),()=>{e.removeEventListener("mouseenter",s),e.removeEventListener("mouseleave",u)}},[]),{ref:r,isHovered:o}}exports.useHover=v;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useHover/index.ts"],"sourcesContent":["import { useState, useRef, useEffect } from 'react';\n\nexport function useHover<T extends HTMLElement = HTMLElement>() {\n const [isHovered, setIsHovered] = useState<boolean>(false);\n const ref = useRef<T>(null);\n\n const handleMouseEnter = () => setIsHovered(true);\n const handleMouseLeave = () => setIsHovered(false);\n\n useEffect(() => {\n const element = ref?.current;\n\n if (element) {\n element.addEventListener('mouseenter', handleMouseEnter);\n element.addEventListener('mouseleave', handleMouseLeave);\n\n return () => {\n element.removeEventListener('mouseenter', handleMouseEnter);\n element.removeEventListener('mouseleave', handleMouseLeave);\n };\n }\n\n return undefined;\n }, []);\n\n return { ref, isHovered };\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useHover/index.ts"],"sourcesContent":["import { useState, useRef, useEffect } from 'react';\n\nexport function useHover<T extends HTMLElement = HTMLElement>() {\n const [isHovered, setIsHovered] = useState<boolean>(false);\n const ref = useRef<T>(null);\n\n const handleMouseEnter = () => setIsHovered(true);\n const handleMouseLeave = () => setIsHovered(false);\n\n useEffect(() => {\n const element = ref?.current;\n\n if (element) {\n element.addEventListener('mouseenter', handleMouseEnter);\n element.addEventListener('mouseleave', handleMouseLeave);\n\n return () => {\n element.removeEventListener('mouseenter', handleMouseEnter);\n element.removeEventListener('mouseleave', handleMouseLeave);\n };\n }\n\n return undefined;\n }, []);\n\n return { ref, isHovered };\n}\n"],"names":["u","a","l"],"mappings":";;;;;;AAAmE,SAAS,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,cAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACC,YAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAOC,eAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;;;;"}
|
package/cjs/useId/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),n=require("../utils/index.js");function s(e,r=n.randomId){const u=t.useRef(r());return e||u.current}exports.useId=s;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/cjs/useId/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useId/index.ts"],"sourcesContent":["import { useRef } from 'react';\nimport { randomId } from '../utils';\n\nexport function useId(id?: string, generateId: () => string = randomId) {\n const generatedId = useRef(generateId());\n return id || generatedId.current;\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useId/index.ts"],"sourcesContent":["import { useRef } from 'react';\nimport { randomId } from '../utils';\n\nexport function useId(id?: string, generateId: () => string = randomId) {\n const generatedId = useRef(generateId());\n return id || generatedId.current;\n}\n"],"names":["o","n"],"mappings":";;;;;;;AAA0E,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,CAACA,cAAC,CAAC,CAAC,MAAM,CAAC,CAACC,YAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,OAAO;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var u=require("react"),s=require("../useWindowEvent/index.js");function c({key:t,defaultValue:a=void 0}){const[o,n]=u.useState(typeof window!="undefined"&&"localStorage"in window?window.localStorage.getItem(t):a??""),r=u.useCallback(e=>{typeof e=="function"?n(i=>{const l=e(i);return window.localStorage.setItem(t,l),l}):(window.localStorage.setItem(t,e),n(e))},[t]);return s.useWindowEvent("storage",e=>{e.storageArea===window.localStorage&&e.key===t&&n(e.newValue)}),u.useEffect(()=>{a&&!o&&r(a)},[a,o,r]),[o,r]}exports.useLocalStorage=c;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useLocalStorage/index.ts"],"sourcesContent":["// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-local-storage-value/use-local-storage-value.ts\nimport { useState, useCallback, useEffect } from 'react';\nimport { useWindowEvent } from '../useWindowEvent';\n\nexport function useLocalStorage<T extends string>({\n key,\n defaultValue = undefined,\n}: {\n key: string;\n defaultValue?: T;\n}) {\n const [value, setValue] = useState<T>(\n typeof window !== 'undefined' && 'localStorage' in window\n ? (window.localStorage.getItem(key) as T)\n : ((defaultValue ?? '') as T)\n );\n\n const setLocalStorageValue = useCallback(\n (val: T | ((prevState: T) => T)) => {\n if (typeof val === 'function') {\n setValue((current) => {\n const result = val(current);\n window.localStorage.setItem(key, result);\n return result;\n });\n } else {\n window.localStorage.setItem(key, val);\n setValue(val);\n }\n },\n [key]\n );\n\n useWindowEvent('storage', (event) => {\n if (event.storageArea === window.localStorage && event.key === key) {\n setValue(event.newValue as T);\n }\n });\n\n useEffect(() => {\n if (defaultValue && !value) {\n setLocalStorageValue(defaultValue);\n }\n }, [defaultValue, value, setLocalStorageValue]);\n\n return [value, setLocalStorageValue] as const;\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useLocalStorage/index.ts"],"sourcesContent":["// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-local-storage-value/use-local-storage-value.ts\nimport { useState, useCallback, useEffect } from 'react';\nimport { useWindowEvent } from '../useWindowEvent';\n\nexport function useLocalStorage<T extends string>({\n key,\n defaultValue = undefined,\n}: {\n key: string;\n defaultValue?: T;\n}) {\n const [value, setValue] = useState<T>(\n typeof window !== 'undefined' && 'localStorage' in window\n ? (window.localStorage.getItem(key) as T)\n : ((defaultValue ?? '') as T)\n );\n\n const setLocalStorageValue = useCallback(\n (val: T | ((prevState: T) => T)) => {\n if (typeof val === 'function') {\n setValue((current) => {\n const result = val(current);\n window.localStorage.setItem(key, result);\n return result;\n });\n } else {\n window.localStorage.setItem(key, val);\n setValue(val);\n }\n },\n [key]\n );\n\n useWindowEvent('storage', (event) => {\n if (event.storageArea === window.localStorage && event.key === key) {\n setValue(event.newValue as T);\n }\n });\n\n useEffect(() => {\n if (defaultValue && !value) {\n setLocalStorageValue(defaultValue);\n }\n }, [defaultValue, value, setLocalStorageValue]);\n\n return [value, setLocalStorageValue] as const;\n}\n"],"names":["a","w","S","g"],"mappings":";;;;;;;AAA2H,SAAS,eAAe,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,cAAC,CAAC,OAAO,MAAM,EAAE,WAAW,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAACC,iBAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAOC,oBAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAC,CAAC,CAAC,CAACC,eAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var i=require("react");function u(e,t){try{return e.addEventListener("change",t),()=>e.removeEventListener("change",t)}catch(n){return e.addListener(t),()=>e.removeListener(t)}}function a(e){return typeof window!="undefined"&&"matchMedia"in window?window.matchMedia(e).matches:!1}function d(e){const[t,n]=i.useState(a(e)),r=i.useRef();return i.useEffect(()=>{if("matchMedia"in window)return r.current=window.matchMedia(e),n(r.current.matches),u(r.current,c=>n(c.matches))},[e]),t}exports.useMediaQuery=d;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useMediaQuery/index.ts"],"sourcesContent":["import { useState, useEffect, useRef } from 'react';\n\ntype MediaQueryCallback = (event: { matches: boolean; media: string }) => void;\n\n/**\n * Older versions of Safari (shipped withCatalina and before) do not support addEventListener on matchMedia\n * https://stackoverflow.com/questions/56466261/matchmedia-addlistener-marked-as-deprecated-addeventlistener-equivalent\n * */\nfunction attachMediaListener(query: MediaQueryList, callback: MediaQueryCallback) {\n try {\n query.addEventListener('change', callback);\n return () => query.removeEventListener('change', callback);\n } catch (e) {\n query.addListener(callback);\n return () => query.removeListener(callback);\n }\n}\n\nfunction getInitialValue(query: string) {\n if (typeof window !== 'undefined' && 'matchMedia' in window) {\n return window.matchMedia(query).matches;\n }\n return false;\n}\n\nexport function useMediaQuery(query: string) {\n const [matches, setMatches] = useState(getInitialValue(query));\n const queryRef = useRef<MediaQueryList>();\n\n // eslint-disable-next-line consistent-return\n useEffect(() => {\n if ('matchMedia' in window) {\n queryRef.current = window.matchMedia(query);\n setMatches(queryRef.current.matches);\n return attachMediaListener(queryRef.current, (event) => setMatches(event.matches));\n }\n }, [query]);\n\n return matches;\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useMediaQuery/index.ts"],"sourcesContent":["import { useState, useEffect, useRef } from 'react';\n\ntype MediaQueryCallback = (event: { matches: boolean; media: string }) => void;\n\n/**\n * Older versions of Safari (shipped withCatalina and before) do not support addEventListener on matchMedia\n * https://stackoverflow.com/questions/56466261/matchmedia-addlistener-marked-as-deprecated-addeventlistener-equivalent\n * */\nfunction attachMediaListener(query: MediaQueryList, callback: MediaQueryCallback) {\n try {\n query.addEventListener('change', callback);\n return () => query.removeEventListener('change', callback);\n } catch (e) {\n query.addListener(callback);\n return () => query.removeListener(callback);\n }\n}\n\nfunction getInitialValue(query: string) {\n if (typeof window !== 'undefined' && 'matchMedia' in window) {\n return window.matchMedia(query).matches;\n }\n return false;\n}\n\nexport function useMediaQuery(query: string) {\n const [matches, setMatches] = useState(getInitialValue(query));\n const queryRef = useRef<MediaQueryList>();\n\n // eslint-disable-next-line consistent-return\n useEffect(() => {\n if ('matchMedia' in window) {\n queryRef.current = window.matchMedia(query);\n setMatches(queryRef.current.matches);\n return attachMediaListener(queryRef.current, (event) => setMatches(event.matches));\n }\n }, [query]);\n\n return matches;\n}\n"],"names":["a","d","s"],"mappings":";;;;;;AAA4D,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,OAAO,MAAM,EAAE,WAAW,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAQ,SAAS,aAAa,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,cAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACC,YAAC,EAAE,CAAC,OAAOC,eAAC,CAAC,IAAI,CAAC,GAAG,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),u=require("../utils/index.js");function a(...e){return t.useCallback(r=>{e.forEach(s=>u.assignRef(s,r))},e)}function f(...e){return r=>{e.forEach(s=>u.assignRef(s,r))}}exports.mergeRefs=f,exports.useMergedRef=a;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useMergedRef/index.ts"],"sourcesContent":["import React, { useCallback } from 'react';\nimport { assignRef } from '../utils';\n\ntype Ref<T> = React.Dispatch<React.SetStateAction<T>> | React.ForwardedRef<T>;\n\nexport function useMergedRef<T = any>(...refs: Ref<T>[]) {\n return useCallback((node: T | null) => {\n refs.forEach((ref) => assignRef(ref, node));\n }, refs);\n}\n\nexport function mergeRefs<T = any>(...refs: Ref<T>[]) {\n return (node: T | null) => {\n refs.forEach((ref) => assignRef(ref, node));\n };\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useMergedRef/index.ts"],"sourcesContent":["import React, { useCallback } from 'react';\nimport { assignRef } from '../utils';\n\ntype Ref<T> = React.Dispatch<React.SetStateAction<T>> | React.ForwardedRef<T>;\n\nexport function useMergedRef<T = any>(...refs: Ref<T>[]) {\n return useCallback((node: T | null) => {\n refs.forEach((ref) => assignRef(ref, node));\n }, refs);\n}\n\nexport function mergeRefs<T = any>(...refs: Ref<T>[]) {\n return (node: T | null) => {\n refs.forEach((ref) => assignRef(ref, node));\n };\n}\n"],"names":["c","a"],"mappings":";;;;;;;AAAgF,SAAS,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,OAAOA,iBAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAEC,eAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,CAAQ,SAAS,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAEA,eAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC;;;;;"}
|
package/cjs/useMove/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("react"),h=require("../utils/index.js");function b(L,r){const t=n.useRef(),c=n.useRef(!1),o=n.useRef(!1),v=n.useRef(0),[p,m]=n.useState(!1);return n.useEffect(()=>{c.current=!0},[]),n.useEffect(()=>{const a=({x:e,y:S})=>{cancelAnimationFrame(v.current),v.current=requestAnimationFrame(()=>{if(c.current&&t.current){t.current.style.userSelect="none";const u=t.current.getBoundingClientRect();u.width&&u.height&&L({x:h.clamp({value:(e-u.left)/u.width,min:0,max:1}),y:h.clamp({value:(S-u.top)/u.height,min:0,max:1})})}})},x=()=>{document.addEventListener("mousemove",s),document.addEventListener("mouseup",i),document.addEventListener("touchmove",d),document.addEventListener("touchend",i)},y=()=>{document.removeEventListener("mousemove",s),document.removeEventListener("mouseup",i),document.removeEventListener("touchmove",d),document.removeEventListener("touchend",i)},l=()=>{!o.current&&c.current&&(o.current=!0,typeof(r==null?void 0:r.onScrubStart)=="function"&&r.onScrubStart(),m(!0),x())},i=()=>{o.current&&c.current&&(o.current=!1,typeof(r==null?void 0:r.onScrubEnd)=="function"&&r.onScrubEnd(),m(!1),y())},f=e=>{l(),s(e)},s=e=>a({x:e.clientX,y:e.clientY}),E=e=>{l(),e==null||e.preventDefault(),d(e)},d=e=>{e==null||e.preventDefault(),a({x:e.changedTouches[0].clientX,y:e.changedTouches[0].clientY})};return t.current.addEventListener("mousedown",f),t.current.addEventListener("touchstart",E),()=>{t.current&&(t.current.removeEventListener("mousedown",f),t.current.removeEventListener("touchstart",E))}},[t.current]),{ref:t,active:p}}exports.useMove=b;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/cjs/useMove/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useMove/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\nimport { useEffect, useState, useRef } from 'react';\nimport { clamp } from '../utils';\n\nexport interface UseMovePosition {\n x: number;\n y: number;\n}\n\nexport const clampUseMovePosition = (position: UseMovePosition) => ({\n x: clamp({ min: 0, max: 1, value: position.x }),\n y: clamp({ min: 0, max: 1, value: position.y }),\n});\n\ninterface useMoveHandlers {\n onScrubStart?(): void;\n onScrubEnd?(): void;\n}\n\nexport function useMove<T extends HTMLElement = HTMLDivElement>(\n onChange: (value: UseMovePosition) => void,\n handlers?: useMoveHandlers\n) {\n const ref = useRef<T>();\n const mounted = useRef<boolean>(false);\n const isSliding = useRef(false);\n const frame = useRef(0);\n const [active, setActive] = useState(false);\n\n useEffect(() => {\n mounted.current = true;\n }, []);\n\n useEffect(() => {\n const onScrub = ({ x, y }: UseMovePosition) => {\n cancelAnimationFrame(frame.current);\n\n frame.current = requestAnimationFrame(() => {\n if (mounted.current && ref.current) {\n ref.current.style.userSelect = 'none';\n const rect = ref.current.getBoundingClientRect();\n\n if (rect.width && rect.height) {\n onChange({\n x: clamp({ value: (x - rect.left) / rect.width, min: 0, max: 1 }),\n y: clamp({ value: (y - rect.top) / rect.height, min: 0, max: 1 }),\n });\n }\n }\n });\n };\n\n const bindEvents = () => {\n document.addEventListener('mousemove', onMouseMove);\n document.addEventListener('mouseup', stopScrubbing);\n document.addEventListener('touchmove', onTouchMove);\n document.addEventListener('touchend', stopScrubbing);\n };\n\n const unbindEvents = () => {\n document.removeEventListener('mousemove', onMouseMove);\n document.removeEventListener('mouseup', stopScrubbing);\n document.removeEventListener('touchmove', onTouchMove);\n document.removeEventListener('touchend', stopScrubbing);\n };\n\n const startScrubbing = () => {\n if (!isSliding.current && mounted.current) {\n isSliding.current = true;\n typeof handlers?.onScrubStart === 'function' && handlers.onScrubStart();\n setActive(true);\n bindEvents();\n }\n };\n\n const stopScrubbing = () => {\n if (isSliding.current && mounted.current) {\n isSliding.current = false;\n typeof handlers?.onScrubEnd === 'function' && handlers.onScrubEnd();\n setActive(false);\n unbindEvents();\n }\n };\n\n const onMouseDown = (event: MouseEvent) => {\n startScrubbing();\n onMouseMove(event);\n };\n\n const onMouseMove = (event: MouseEvent) => onScrub({ x: event.clientX, y: event.clientY });\n\n const onTouchStart = (event: TouchEvent) => {\n startScrubbing();\n event?.preventDefault();\n onTouchMove(event);\n };\n\n const onTouchMove = (event: TouchEvent) => {\n event?.preventDefault();\n onScrub({ x: event.changedTouches[0].clientX, y: event.changedTouches[0].clientY });\n };\n\n ref.current.addEventListener('mousedown', onMouseDown);\n ref.current.addEventListener('touchstart', onTouchStart);\n\n return () => {\n if (ref.current) {\n ref.current.removeEventListener('mousedown', onMouseDown);\n ref.current.removeEventListener('touchstart', onTouchStart);\n }\n };\n }, [ref.current]);\n\n return { ref, active };\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useMove/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\nimport { useEffect, useState, useRef } from 'react';\nimport { clamp } from '../utils';\n\nexport interface UseMovePosition {\n x: number;\n y: number;\n}\n\nexport const clampUseMovePosition = (position: UseMovePosition) => ({\n x: clamp({ min: 0, max: 1, value: position.x }),\n y: clamp({ min: 0, max: 1, value: position.y }),\n});\n\ninterface useMoveHandlers {\n onScrubStart?(): void;\n onScrubEnd?(): void;\n}\n\nexport function useMove<T extends HTMLElement = HTMLDivElement>(\n onChange: (value: UseMovePosition) => void,\n handlers?: useMoveHandlers\n) {\n const ref = useRef<T>();\n const mounted = useRef<boolean>(false);\n const isSliding = useRef(false);\n const frame = useRef(0);\n const [active, setActive] = useState(false);\n\n useEffect(() => {\n mounted.current = true;\n }, []);\n\n useEffect(() => {\n const onScrub = ({ x, y }: UseMovePosition) => {\n cancelAnimationFrame(frame.current);\n\n frame.current = requestAnimationFrame(() => {\n if (mounted.current && ref.current) {\n ref.current.style.userSelect = 'none';\n const rect = ref.current.getBoundingClientRect();\n\n if (rect.width && rect.height) {\n onChange({\n x: clamp({ value: (x - rect.left) / rect.width, min: 0, max: 1 }),\n y: clamp({ value: (y - rect.top) / rect.height, min: 0, max: 1 }),\n });\n }\n }\n });\n };\n\n const bindEvents = () => {\n document.addEventListener('mousemove', onMouseMove);\n document.addEventListener('mouseup', stopScrubbing);\n document.addEventListener('touchmove', onTouchMove);\n document.addEventListener('touchend', stopScrubbing);\n };\n\n const unbindEvents = () => {\n document.removeEventListener('mousemove', onMouseMove);\n document.removeEventListener('mouseup', stopScrubbing);\n document.removeEventListener('touchmove', onTouchMove);\n document.removeEventListener('touchend', stopScrubbing);\n };\n\n const startScrubbing = () => {\n if (!isSliding.current && mounted.current) {\n isSliding.current = true;\n typeof handlers?.onScrubStart === 'function' && handlers.onScrubStart();\n setActive(true);\n bindEvents();\n }\n };\n\n const stopScrubbing = () => {\n if (isSliding.current && mounted.current) {\n isSliding.current = false;\n typeof handlers?.onScrubEnd === 'function' && handlers.onScrubEnd();\n setActive(false);\n unbindEvents();\n }\n };\n\n const onMouseDown = (event: MouseEvent) => {\n startScrubbing();\n onMouseMove(event);\n };\n\n const onMouseMove = (event: MouseEvent) => onScrub({ x: event.clientX, y: event.clientY });\n\n const onTouchStart = (event: TouchEvent) => {\n startScrubbing();\n event?.preventDefault();\n onTouchMove(event);\n };\n\n const onTouchMove = (event: TouchEvent) => {\n event?.preventDefault();\n onScrub({ x: event.changedTouches[0].clientX, y: event.changedTouches[0].clientY });\n };\n\n ref.current.addEventListener('mousedown', onMouseDown);\n ref.current.addEventListener('touchstart', onTouchStart);\n\n return () => {\n if (ref.current) {\n ref.current.removeEventListener('mousedown', onMouseDown);\n ref.current.removeEventListener('touchstart', onTouchStart);\n }\n };\n }, [ref.current]);\n\n return { ref, active };\n}\n"],"names":["s","g","S","m"],"mappings":";;;;;;;AAAuM,SAAS,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAACA,YAAC,EAAE,CAAC,CAAC,CAACA,YAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,YAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,YAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACC,cAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAOC,eAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAC,CAAC,CAAC,EAAE,CAAC,CAACA,eAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAACC,WAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,WAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAC,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;;;;"}
|
package/cjs/usePrevious/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var u=require("react");function t(e){const r=u.useRef();return u.useEffect(()=>{r.current=e},[e]),r.current}exports.usePrevious=t;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/usePrevious/index.ts"],"sourcesContent":["import { useRef, useEffect } from 'react';\n\nexport function usePrevious<T>(value: T): T {\n const ref: any = useRef<T>();\n // Store current value in ref\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref.current;\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/usePrevious/index.ts"],"sourcesContent":["import { useRef, useEffect } from 'react';\n\nexport function usePrevious<T>(value: T): T {\n const ref: any = useRef<T>();\n // Store current value in ref\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref.current;\n}\n"],"names":["t","n"],"mappings":";;;;;;AAAqD,SAAS,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAACA,YAAC,EAAE,CAAC,OAAOC,eAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO;;;;"}
|
package/cjs/useQueue/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var l=require("react");function n({initialValues:i=[],limit:e}){const[{state:r,queue:c},a]=l.useState({state:i.slice(0,e),queue:i.slice(e)});return{state:r,queue:c,add:(...t)=>a(u=>{const s=[...u.state,...u.queue,...t];return{state:s.slice(0,e),queue:s.slice(e)}}),update:t=>a(u=>{const s=t([...u.state,...u.queue]);return{state:s.slice(0,e),queue:s.slice(e)}}),cleanQueue:()=>a(t=>({state:t.state,queue:[]}))}}exports.useQueue=n;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useQueue/index.ts"],"sourcesContent":["import { useState } from 'react';\n\nexport function useQueue<T>({ initialValues = [], limit }: { initialValues?: T[]; limit: number }) {\n const [{ state, queue }, setState] = useState({\n state: initialValues.slice(0, limit),\n queue: initialValues.slice(limit),\n });\n\n const add = (...items: T[]) =>\n setState((current) => {\n const results = [...current.state, ...current.queue, ...items];\n\n return {\n state: results.slice(0, limit),\n queue: results.slice(limit),\n };\n });\n\n const update = (fn: (state: T[]) => T[]) =>\n setState((current) => {\n const results = fn([...current.state, ...current.queue]);\n\n return {\n state: results.slice(0, limit),\n queue: results.slice(limit),\n };\n });\n\n const cleanQueue = () => setState((current) => ({ state: current.state, queue: [] }));\n\n return {\n state,\n queue,\n add,\n update,\n cleanQueue,\n };\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useQueue/index.ts"],"sourcesContent":["import { useState } from 'react';\n\nexport function useQueue<T>({ initialValues = [], limit }: { initialValues?: T[]; limit: number }) {\n const [{ state, queue }, setState] = useState({\n state: initialValues.slice(0, limit),\n queue: initialValues.slice(limit),\n });\n\n const add = (...items: T[]) =>\n setState((current) => {\n const results = [...current.state, ...current.queue, ...items];\n\n return {\n state: results.slice(0, limit),\n queue: results.slice(limit),\n };\n });\n\n const update = (fn: (state: T[]) => T[]) =>\n setState((current) => {\n const results = fn([...current.state, ...current.queue]);\n\n return {\n state: results.slice(0, limit),\n queue: results.slice(limit),\n };\n });\n\n const cleanQueue = () => setState((current) => ({ state: current.state, queue: [] }));\n\n return {\n state,\n queue,\n add,\n update,\n cleanQueue,\n };\n}\n"],"names":["r"],"mappings":";;;;;;AAAwC,SAAS,QAAQ,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,cAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,OAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../useMediaQuery/index.js");function u(){return e.useMediaQuery("(prefers-reduced-motion: reduce)")}exports.useReducedMotion=u;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useReducedMotion/index.ts"],"sourcesContent":["import { useMediaQuery } from '../useMediaQuery';\n\nexport function useReducedMotion() {\n return useMediaQuery('(prefers-reduced-motion: reduce)');\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useReducedMotion/index.ts"],"sourcesContent":["import { useMediaQuery } from '../useMediaQuery';\n\nexport function useReducedMotion() {\n return useMediaQuery('(prefers-reduced-motion: reduce)');\n}\n"],"names":["e"],"mappings":";;;;;;AAAwD,SAAS,gBAAgB,EAAE,CAAC,OAAOA,mBAAC,CAAC,kCAAkC,CAAC;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function l(o){const[r,t]=e.useState(o||!1),u=e.useRef(!1),c=e.useRef(null),n=()=>{u.current&&(u.current=!1,document.body.style.overflow=c.current||"")},d=()=>{u.current=!0,c.current=document.body.style.overflow,document.body.style.overflow="hidden"};return e.useEffect(()=>(r?d():n(),n),[r]),e.useEffect(()=>{o!==void 0&&t(o)},[o]),e.useEffect(()=>{o===void 0&&typeof window!="undefined"&&window.document.body.style.overflow==="hidden"&&t(!0)},[t]),[r,t]}exports.useScrollLock=l;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useScrollLock/index.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\n\nexport function useScrollLock(lock?: boolean) {\n const [scrollLocked, setScrollLocked] = useState(lock || false);\n\n // value is stored to prevent body overflow styles override with initial useScrollLock(false)\n const locked = useRef(false);\n\n // after scroll is unlocked body overflow style returns to the previous known value\n const bodyOverflow = useRef<React.CSSProperties[\"overflow\"]>(null);\n\n const unlockScroll = () => {\n if (locked.current) {\n locked.current = false;\n document.body.style.overflow = bodyOverflow.current || \"\";\n }\n };\n\n const lockScroll = () => {\n locked.current = true;\n bodyOverflow.current = document.body.style.overflow;\n document.body.style.overflow = \"hidden\";\n };\n\n useEffect(() => {\n if (scrollLocked) {\n lockScroll();\n } else {\n unlockScroll();\n }\n\n return unlockScroll;\n }, [scrollLocked]);\n\n useEffect(() => {\n if (lock !== undefined) {\n setScrollLocked(lock);\n }\n }, [lock]);\n\n useEffect(() => {\n if (lock === undefined && typeof window !== \"undefined\") {\n window.document.body.style.overflow === \"hidden\" && setScrollLocked(true);\n }\n }, [setScrollLocked]);\n\n return [scrollLocked, setScrollLocked] as const;\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useScrollLock/index.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\n\nexport function useScrollLock(lock?: boolean) {\n const [scrollLocked, setScrollLocked] = useState(lock || false);\n\n // value is stored to prevent body overflow styles override with initial useScrollLock(false)\n const locked = useRef(false);\n\n // after scroll is unlocked body overflow style returns to the previous known value\n const bodyOverflow = useRef<React.CSSProperties[\"overflow\"]>(null);\n\n const unlockScroll = () => {\n if (locked.current) {\n locked.current = false;\n document.body.style.overflow = bodyOverflow.current || \"\";\n }\n };\n\n const lockScroll = () => {\n locked.current = true;\n bodyOverflow.current = document.body.style.overflow;\n document.body.style.overflow = \"hidden\";\n };\n\n useEffect(() => {\n if (scrollLocked) {\n lockScroll();\n } else {\n unlockScroll();\n }\n\n return unlockScroll;\n }, [scrollLocked]);\n\n useEffect(() => {\n if (lock !== undefined) {\n setScrollLocked(lock);\n }\n }, [lock]);\n\n useEffect(() => {\n if (lock === undefined && typeof window !== \"undefined\") {\n window.document.body.style.overflow === \"hidden\" && setScrollLocked(true);\n }\n }, [setScrollLocked]);\n\n return [scrollLocked, setScrollLocked] as const;\n}\n"],"names":["f","d","n"],"mappings":";;;;;;AAAmE,SAAS,aAAa,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,cAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAACC,YAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,YAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,EAAE,EAAE,EAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAQ,CAAC,CAAC,OAAOC,eAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,eAAC,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,eAAC,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,EAAE,OAAO,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;;;"}
|
package/cjs/useToggle/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var g=require("react");function r(e,o){const[t,n]=g.useState(e);return[t,u=>{n(typeof u!="undefined"?u:s=>s===o[0]?o[1]:o[0])}]}function l(e=!1){return r(e,[!0,!1])}exports.useBooleanToggle=l,exports.useToggle=r;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useToggle/index.ts"],"sourcesContent":["// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-toggle/use-toggle.ts\nimport React, { useState } from 'react';\n\nexport function useToggle<T>(initialValue: T, options: [T, T]) {\n const [state, setState] = useState(initialValue);\n\n const toggle = (value?: React.SetStateAction<T>) => {\n if (typeof value !== 'undefined') {\n setState(value);\n } else {\n setState((current) => {\n if (current === options[0]) {\n return options[1];\n }\n\n return options[0];\n });\n }\n };\n\n return [state, toggle] as const;\n}\n\nexport function useBooleanToggle(initialValue = false) {\n return useToggle(initialValue, [true, false]);\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useToggle/index.ts"],"sourcesContent":["// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-toggle/use-toggle.ts\nimport React, { useState } from 'react';\n\nexport function useToggle<T>(initialValue: T, options: [T, T]) {\n const [state, setState] = useState(initialValue);\n\n const toggle = (value?: React.SetStateAction<T>) => {\n if (typeof value !== 'undefined') {\n setState(value);\n } else {\n setState((current) => {\n if (current === options[0]) {\n return options[1];\n }\n\n return options[0];\n });\n }\n };\n\n return [state, toggle] as const;\n}\n\nexport function useBooleanToggle(initialValue = false) {\n return useToggle(initialValue, [true, false]);\n}\n"],"names":["s"],"mappings":";;;;;;AAAwC,SAAS,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,cAAC,CAAC,CAAC,CAAC,CAAC,OAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAQ,SAAS,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var o=require("react");function U({value:r,defaultValue:u,finalValue:c,rule:a,onChange:f,onValueUpdate:s}){const t=a(r),n=o.useRef("initial"),p=a(u)?u:c,[v,d]=o.useState(p);let e=t?r:v;!t&&n.current==="controlled"&&(e=c),n.current=t?"controlled":"uncontrolled";const l=n.current,y=i=>{typeof f=="function"&&f(i),l==="uncontrolled"&&d(i)};return o.useEffect(()=>{l==="uncontrolled"&&d(e),typeof s=="function"&&s(e)},[l,e]),[e,y,n.current]}exports.useUncontrolled=U;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useUncontrolled/index.ts"],"sourcesContent":["// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-uncontrolled/use-uncontrolled.ts\nimport { useEffect, useRef, useState } from 'react';\n\nexport type UncontrolledMode = 'initial' | 'controlled' | 'uncontrolled';\n\nexport interface UncontrolledOptions<T> {\n value: T | null | undefined;\n defaultValue: T | null | undefined;\n finalValue: T | null;\n onChange(value: T | null): void;\n onValueUpdate?(value: T | null): void;\n rule: (value: T | null | undefined) => boolean;\n}\n\nexport function useUncontrolled<T>({\n value,\n defaultValue,\n finalValue,\n rule,\n onChange,\n onValueUpdate,\n}: UncontrolledOptions<T>): readonly [T | null, (nextValue: T | null) => void, UncontrolledMode] {\n // determine, whether new props indicate controlled state\n const shouldBeControlled = rule(value);\n\n // initialize state\n const modeRef = useRef<UncontrolledMode>('initial');\n const initialValue = rule(defaultValue) ? defaultValue : finalValue;\n const [uncontrolledValue, setUncontrolledValue] = useState(initialValue);\n\n // compute effective value\n let effectiveValue = shouldBeControlled ? value : uncontrolledValue;\n\n if (!shouldBeControlled && modeRef.current === 'controlled') {\n // We are transitioning from controlled to uncontrolled\n // this transition is special as it happens when clearing out\n // the input using \"invalid\" value (typically null or undefined).\n //\n // Since the value is invalid, doing nothing would mean just\n // transitioning to uncontrolled state and using whatever value\n // it currently holds which is likely not the bavior\n // user expects, so lets change the state to finalValue.\n //\n // The value will be propagated to internal state by useEffect below.\n\n effectiveValue = finalValue;\n }\n modeRef.current = shouldBeControlled ? 'controlled' : 'uncontrolled';\n const mode = modeRef.current;\n\n const handleChange = (nextValue: T | null) => {\n typeof onChange === 'function' && onChange(nextValue);\n\n // Controlled input only triggers onChange event and expects\n // the controller to propagate new value back.\n if (mode === 'uncontrolled') {\n setUncontrolledValue(nextValue);\n }\n };\n\n useEffect(() => {\n if (mode === 'uncontrolled') {\n setUncontrolledValue(effectiveValue);\n }\n typeof onValueUpdate === 'function' && onValueUpdate(effectiveValue);\n }, [mode, effectiveValue]);\n\n return [effectiveValue, handleChange, modeRef.current] as const;\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useUncontrolled/index.ts"],"sourcesContent":["// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-uncontrolled/use-uncontrolled.ts\nimport { useEffect, useRef, useState } from 'react';\n\nexport type UncontrolledMode = 'initial' | 'controlled' | 'uncontrolled';\n\nexport interface UncontrolledOptions<T> {\n value: T | null | undefined;\n defaultValue: T | null | undefined;\n finalValue: T | null;\n onChange(value: T | null): void;\n onValueUpdate?(value: T | null): void;\n rule: (value: T | null | undefined) => boolean;\n}\n\nexport function useUncontrolled<T>({\n value,\n defaultValue,\n finalValue,\n rule,\n onChange,\n onValueUpdate,\n}: UncontrolledOptions<T>): readonly [T | null, (nextValue: T | null) => void, UncontrolledMode] {\n // determine, whether new props indicate controlled state\n const shouldBeControlled = rule(value);\n\n // initialize state\n const modeRef = useRef<UncontrolledMode>('initial');\n const initialValue = rule(defaultValue) ? defaultValue : finalValue;\n const [uncontrolledValue, setUncontrolledValue] = useState(initialValue);\n\n // compute effective value\n let effectiveValue = shouldBeControlled ? value : uncontrolledValue;\n\n if (!shouldBeControlled && modeRef.current === 'controlled') {\n // We are transitioning from controlled to uncontrolled\n // this transition is special as it happens when clearing out\n // the input using \"invalid\" value (typically null or undefined).\n //\n // Since the value is invalid, doing nothing would mean just\n // transitioning to uncontrolled state and using whatever value\n // it currently holds which is likely not the bavior\n // user expects, so lets change the state to finalValue.\n //\n // The value will be propagated to internal state by useEffect below.\n\n effectiveValue = finalValue;\n }\n modeRef.current = shouldBeControlled ? 'controlled' : 'uncontrolled';\n const mode = modeRef.current;\n\n const handleChange = (nextValue: T | null) => {\n typeof onChange === 'function' && onChange(nextValue);\n\n // Controlled input only triggers onChange event and expects\n // the controller to propagate new value back.\n if (mode === 'uncontrolled') {\n setUncontrolledValue(nextValue);\n }\n };\n\n useEffect(() => {\n if (mode === 'uncontrolled') {\n setUncontrolledValue(effectiveValue);\n }\n typeof onValueUpdate === 'function' && onValueUpdate(effectiveValue);\n }, [mode, effectiveValue]);\n\n return [effectiveValue, handleChange, modeRef.current] as const;\n}\n"],"names":["U","m","v"],"mappings":";;;;;;AAAmE,SAAS,eAAe,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,YAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACC,cAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,GAAG,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,cAAc,EAAE,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,OAAOC,eAAC,CAAC,IAAI,CAAC,CAAC,GAAG,cAAc,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;;;;"}
|
package/cjs/useUnmount/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var u=require("react");function r(e){const t=u.useRef(e);t.current=e,u.useEffect(()=>()=>{t.current()},[])}exports.useUnmount=r;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|