@kubed/hooks 0.0.18 → 0.2.12
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 -108
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useUnmount/index.ts"],"sourcesContent":["import { useRef, useEffect } from 'react';\n\nexport function useUnmount(fn: () => void) {\n const fnRef = useRef(fn);\n fnRef.current = fn;\n\n useEffect(\n () => () => {\n fnRef.current();\n },\n []\n );\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useUnmount/index.ts"],"sourcesContent":["import { useRef, useEffect } from 'react';\n\nexport function useUnmount(fn: () => void) {\n const fnRef = useRef(fn);\n fnRef.current = fn;\n\n useEffect(\n () => () => {\n fnRef.current();\n },\n []\n );\n}\n"],"names":["r","n"],"mappings":";;;;;;AAAqD,SAAS,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAACA,YAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAACC,eAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,OAAO,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 r=require("react");function i(e,t,n){r.useEffect(()=>(window.addEventListener(e,t,n),()=>window.removeEventListener(e,t,n)),[])}exports.useWindowEvent=i;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useWindowEvent/index.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nexport function useWindowEvent<K extends keyof WindowEventMap>(\n type: K,\n listener: (this: Window, ev: WindowEventMap[K]) => any,\n options?: boolean | AddEventListenerOptions\n) {\n useEffect(() => {\n window.addEventListener(type, listener, options);\n return () => window.removeEventListener(type, listener, options);\n }, []);\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useWindowEvent/index.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nexport function useWindowEvent<K extends keyof WindowEventMap>(\n type: K,\n listener: (this: Window, ev: WindowEventMap[K]) => any,\n options?: boolean | AddEventListenerOptions\n) {\n useEffect(() => {\n window.addEventListener(type, listener, options);\n return () => window.removeEventListener(type, listener, options);\n }, []);\n}\n"],"names":["o"],"mappings":";;;;;;AAAyC,SAAS,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,eAAC,CAAC,KAAK,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,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 o(i,n){const[r,s]=t.useState(n);t.useEffect(()=>{const e=()=>{s(window.innerWidth),i()};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[r])}exports.useWindowResize=o;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useWindowResize/index.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport function useWindowResize(handler: { (): void }, initialWindowSize?: number) {\n const [windowSize, setWindowSize] = useState<undefined | number>(initialWindowSize);\n useEffect(() => {\n const handleResize = () => {\n setWindowSize(window.innerWidth);\n handler();\n };\n window.addEventListener('resize', handleResize);\n\n return () => window.removeEventListener('resize', handleResize);\n }, [windowSize]);\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useWindowResize/index.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport function useWindowResize(handler: { (): void }, initialWindowSize?: number) {\n const [windowSize, setWindowSize] = useState<undefined | number>(initialWindowSize);\n useEffect(() => {\n const handleResize = () => {\n setWindowSize(window.innerWidth);\n handler();\n };\n window.addEventListener('resize', handleResize);\n\n return () => window.removeEventListener('resize', handleResize);\n }, [windowSize]);\n}\n"],"names":["d","r"],"mappings":";;;;;;AAAuD,SAAS,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,cAAC,CAAC,CAAC,CAAC,CAACC,eAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,GAAE,CAAC,CAAC,OAAO,MAAM,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC;;;;"}
|
package/cjs/utils/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});function r(){return`kubed-${Math.random().toString(36).substr(2,9)}`}function u({value:t,min:e,max:n}){return Math.min(Math.max(t,e),n)}function a(t,e){typeof t=="function"?t(e):typeof t=="object"&&t!==null&&"current"in t&&(t.current=e)}exports.assignRef=a,exports.clamp=u,exports.randomId=r;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/cjs/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/utils/index.ts"],"sourcesContent":["import React from 'react';\n\nexport function randomId() {\n return `kubed-${Math.random().toString(36).substr(2, 9)}`;\n}\n\ninterface Clamp {\n value: number;\n min: number;\n max: number;\n}\n\nexport function clamp({ value, min, max }: Clamp) {\n return Math.min(Math.max(value, min), max);\n}\n\nexport function assignRef<T = any>(ref: React.ForwardedRef<T>, value: T | null) {\n if (typeof ref === 'function') {\n ref(value);\n } else if (typeof ref === 'object' && ref !== null && 'current' in ref) {\n // eslint-disable-next-line no-param-reassign\n ref.current = value;\n }\n}\n"],"names":[],"mappings":";;;;AAAO,SAAS,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/utils/index.ts"],"sourcesContent":["import React from 'react';\n\nexport function randomId() {\n return `kubed-${Math.random().toString(36).substr(2, 9)}`;\n}\n\ninterface Clamp {\n value: number;\n min: number;\n max: number;\n}\n\nexport function clamp({ value, min, max }: Clamp) {\n return Math.min(Math.max(value, min), max);\n}\n\nexport function assignRef<T = any>(ref: React.ForwardedRef<T>, value: T | null) {\n if (typeof ref === 'function') {\n ref(value);\n } else if (typeof ref === 'object' && ref !== null && 'current' in ref) {\n // eslint-disable-next-line no-param-reassign\n ref.current = value;\n }\n}\n"],"names":[],"mappings":";;;;AAAO,SAAS,QAAQ,EAAE,CAAC,OAAM,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAQ,SAAS,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAQ,SAAS,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,SAAS,GAAG,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,EAAC;;;;;;"}
|
package/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{assignRef as s,clamp as r,randomId as u}from"./utils/index.js";import{useId as i}from"./useId/index.js";import{useBooleanToggle as n,useToggle as t}from"./useToggle/index.js";import{useUncontrolled as m}from"./useUncontrolled/index.js";import{useMediaQuery as j}from"./useMediaQuery/index.js";import{useReducedMotion as c}from"./useReducedMotion/index.js";import{useWindowEvent as g}from"./useWindowEvent/index.js";import{useLocalStorage as v}from"./useLocalStorage/index.js";import{useForceUpdate as R}from"./useForceUpdate/index.js";import{useClipboard as k}from"./useClipboard/index.js";import{useQueue as w}from"./useQueue/index.js";import{useClickOutside as C}from"./useClickOutside/index.js";import{useMove as L}from"./useMove/index.js";import{useHotkeys as S}from"./useHotkeys/index.js";import{mergeRefs as I,useMergedRef as T}from"./useMergedRef/index.js";import{useDebouncedValue as E}from"./useDebouncedValue/index.js";import{useDidMount as O}from"./useDidMount/index.js";import{useDidUpdate as V}from"./useDidUpdate/index.js";import{useUnmount as h}from"./useUnmount/index.js";import{usePrevious as A}from"./usePrevious/index.js";import{useScrollLock as J}from"./useScrollLock/index.js";import{useHover as N}from"./useHover/index.js";import{useWindowResize as Y}from"./useWindowResize/index.js";import{useDisclosure as _}from"./useDisclosure/index.js";export{s as assignRef,r as clamp,I as mergeRefs,u as randomId,n as useBooleanToggle,C as useClickOutside,k as useClipboard,E as useDebouncedValue,O as useDidMount,V as useDidUpdate,_ as useDisclosure,R as useForceUpdate,S as useHotkeys,N as useHover,i as useId,v as useLocalStorage,j as useMediaQuery,T as useMergedRef,L as useMove,A as usePrevious,w as useQueue,c as useReducedMotion,J as useScrollLock,t as useToggle,m as useUncontrolled,h as useUnmount,g as useWindowEvent,Y as useWindowResize};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useRef as
|
|
1
|
+
import{useRef as a,useEffect as i}from"react";const u=["mousedown","touchstart"];function f(r,o,n){const t=a();return i(()=>{const c=e=>{Array.isArray(n)?n.every(s=>!!s&&!s.contains(e.target))&&r():t.current&&!t.current.contains(e.target)&&r()};return(o||u).forEach(e=>document.addEventListener(e,c)),()=>{(o||u).forEach(e=>document.removeEventListener(e,c))}},[t,r,n]),t}export{f as useClickOutside};
|
|
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":[],"mappings":";;
|
|
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,MAAC,EAAE,CAAC,OAAOC,SAAC,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
|
-
import{useState as
|
|
1
|
+
import{useState as t}from"react";function s({timeout:a=2e3}={}){const[l,e]=t(null),[n,r]=t(!1),[i,c]=t(null),u=o=>{clearTimeout(i),c(setTimeout(()=>r(!1),a)),r(o)};return{copy:o=>{"clipboard"in navigator?navigator.clipboard.writeText(o).then(()=>u(!0)).catch(p=>e(p)):e(new Error("useClipboard: navigator.clipboard is not supported"))},reset:()=>{r(!1),e(null),clearTimeout(i)},error:l,copied:n}}export{s as useClipboard};
|
|
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":[],"mappings":";;
|
|
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,QAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,QAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,QAAC,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
|
-
import{useState as
|
|
1
|
+
import{useState as d,useRef as n,useEffect as l}from"react";function f(e,a,u={leading:!1}){const[s,c]=d(e),o=n(!1),i=n(null),r=n(!1),t=()=>window.clearTimeout(i.current);return l(()=>{o.current&&(!r.current&&u.leading?(r.current=!0,c(e)):(t(),i.current=window.setTimeout(()=>{r.current=!1,c(e)},a)))},[e,u.leading]),l(()=>(o.current=!0,t),[]),[s,t]}export{f as useDebouncedValue};
|
|
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":[],"mappings":";;
|
|
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,QAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACC,MAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,MAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAACA,MAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,OAAOC,SAAC,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,SAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;;;"}
|
package/esm/useDidMount/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useEffect as
|
|
1
|
+
import{useEffect as e}from"react";function f(t){e(()=>{typeof t=="function"&&t()},[])}export{f as useDidMount};
|
|
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":[],"mappings":";;
|
|
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,SAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC,GAAE,CAAC,CAAC,EAAE,EAAC;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useRef as
|
|
1
|
+
import{useRef as c,useEffect as u}from"react";function f(t,r){const e=c(!1);u(()=>{e.current?t():e.current=!0},r)}export{f as useDidUpdate};
|
|
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":[],"mappings":";;
|
|
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,MAAC,CAAC,CAAC,CAAC,CAAC,CAACC,SAAC,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
|
-
import{useState as
|
|
1
|
+
import{useState as u,useCallback as s}from"react";function l(n=!1){const[e,r]=u(n),t=s(()=>r(!0),[]),o=s(()=>r(!1),[]),c=s(()=>e?o():t(),[e,o,t]);return{isOpen:e,open:t,close:o,toggle:c}}export{l as useDisclosure};
|
|
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":[],"mappings":";;
|
|
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,QAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACC,WAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAACA,WAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAACA,WAAC,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
|
-
import{useReducer as
|
|
1
|
+
import{useReducer as t}from"react";const r=e=>(e+1)%1e6;function o(){const[,e]=t(r,0);return e}export{o as useForceUpdate};
|
|
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":[],"mappings":";;
|
|
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,UAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;;;;"}
|
package/esm/useHotkeys/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useEffect as m}from"react";import{getHotkeyMatcher as c}from"./parseHotkey.js";function
|
|
1
|
+
import{useEffect as m}from"react";import{getHotkeyMatcher as c}from"./parseHotkey.js";function u(t){m(()=>{const o=e=>{t.forEach(([n,r])=>{c(n)(e)&&(e.preventDefault(),r(e))})};return document.documentElement.addEventListener("keydown",o),()=>document.documentElement.removeEventListener("keydown",o)},[t])}export{u as useHotkeys};
|
|
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":[],"mappings":";;;
|
|
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,SAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAACC,gBAAC,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
|
-
var
|
|
1
|
+
var b=Object.defineProperty,v=Object.defineProperties,w=Object.getOwnPropertyDescriptors,s=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,h=Object.prototype.propertyIsEnumerable,f=(r,e,t)=>e in r?b(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,j=(r,e)=>{for(var t in e||(e={}))O.call(e,t)&&f(r,t,e[t]);if(s)for(var t of s(e))h.call(e,t)&&f(r,t,e[t]);return r},k=(r,e)=>v(r,w(e));function u(r){const e=r.toLowerCase().split("+").map(o=>o.trim()),t={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 k(j({},t),{key:n})}function K(r,e){const{alt:t,ctrl:a,meta:n,mod:o,shift:y,key:i}=r,{altKey:p,ctrlKey:c,metaKey:l,shiftKey:d,key:m}=e;if(t!==p)return!1;if(o){if(!c&&!l)return!1}else if(a!==c||n!==l)return!1;return y!==d?!1:!!(i&&(m.toLowerCase()===i.toLowerCase()||e.code.replace("Key","").toLowerCase()===i.toLowerCase()))}function C(r){return e=>K(u(r),e)}export{C as getHotkeyMatcher,u as parseHotkey};
|
|
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/esm/useHover/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useState as u,useRef as v,useEffect as
|
|
1
|
+
import{useState as u,useRef as v,useEffect as i}from"react";function m(){const[s,r]=u(!1),t=v(null),n=()=>r(!0),o=()=>r(!1);return i(()=>{const e=t==null?void 0:t.current;if(e)return e.addEventListener("mouseenter",n),e.addEventListener("mouseleave",o),()=>{e.removeEventListener("mouseenter",n),e.removeEventListener("mouseleave",o)}},[]),{ref:t,isHovered:s}}export{m as useHover};
|
|
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":[],"mappings":";;
|
|
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,QAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACC,MAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAOC,SAAC,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/esm/useId/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useRef as
|
|
1
|
+
import{useRef as o}from"react";import{randomId as n}from"../utils/index.js";function u(r,e=n){const t=o(e());return r||t.current}export{u as useId};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/esm/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":[],"mappings":";;;
|
|
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,QAAC,CAAC,CAAC,MAAM,CAAC,CAACC,MAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,OAAO;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useState as
|
|
1
|
+
import{useState as u,useCallback as w,useEffect as s}from"react";import{useWindowEvent as c}from"../useWindowEvent/index.js";function d({key:o,defaultValue:t=void 0}){const[n,a]=u(typeof window!="undefined"&&"localStorage"in window?window.localStorage.getItem(o):t??""),r=w(e=>{typeof e=="function"?a(i=>{const l=e(i);return window.localStorage.setItem(o,l),l}):(window.localStorage.setItem(o,e),a(e))},[o]);return c("storage",e=>{e.storageArea===window.localStorage&&e.key===o&&a(e.newValue)}),s(()=>{t&&!n&&r(t)},[t,n,r]),[n,r]}export{d as useLocalStorage};
|
|
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":[],"mappings":";;;
|
|
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,QAAC,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,WAAC,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,cAAC,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,SAAC,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
|
-
import{useState as
|
|
1
|
+
import{useState as c,useRef as a,useEffect as u}from"react";function d(e,n){try{return e.addEventListener("change",n),()=>e.removeEventListener("change",n)}catch(t){return e.addListener(n),()=>e.removeListener(n)}}function o(e){return typeof window!="undefined"&&"matchMedia"in window?window.matchMedia(e).matches:!1}function s(e){const[n,t]=c(o(e)),r=a();return u(()=>{if("matchMedia"in window)return r.current=window.matchMedia(e),t(r.current.matches),d(r.current,i=>t(i.matches))},[e]),n}export{s as useMediaQuery};
|
|
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":[],"mappings":";;
|
|
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,QAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACC,MAAC,EAAE,CAAC,OAAOC,SAAC,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
|
-
import{useCallback as
|
|
1
|
+
import{useCallback as t}from"react";import{assignRef as o}from"../utils/index.js";function n(...r){return t(e=>{r.forEach(f=>o(f,e))},r)}function i(...r){return e=>{r.forEach(f=>o(f,e))}}export{i as mergeRefs,n as useMergedRef};
|
|
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":[],"mappings":";;;
|
|
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,WAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAEC,SAAC,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,SAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC;;;;"}
|
package/esm/useMove/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useRef as
|
|
1
|
+
import{useRef as i,useState as b,useEffect as E}from"react";import{clamp as L}from"../utils/index.js";function w(p,n){const t=i(),u=i(!1),c=i(!1),s=i(0),[x,v]=b(!1);return E(()=>{u.current=!0},[]),E(()=>{const a=({x:e,y:g})=>{cancelAnimationFrame(s.current),s.current=requestAnimationFrame(()=>{if(u.current&&t.current){t.current.style.userSelect="none";const r=t.current.getBoundingClientRect();r.width&&r.height&&p({x:L({value:(e-r.left)/r.width,min:0,max:1}),y:L({value:(g-r.top)/r.height,min:0,max:1})})}})},S=()=>{document.addEventListener("mousemove",m),document.addEventListener("mouseup",o),document.addEventListener("touchmove",d),document.addEventListener("touchend",o)},y=()=>{document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",o),document.removeEventListener("touchmove",d),document.removeEventListener("touchend",o)},l=()=>{!c.current&&u.current&&(c.current=!0,typeof(n==null?void 0:n.onScrubStart)=="function"&&n.onScrubStart(),v(!0),S())},o=()=>{c.current&&u.current&&(c.current=!1,typeof(n==null?void 0:n.onScrubEnd)=="function"&&n.onScrubEnd(),v(!1),y())},f=e=>{l(),m(e)},m=e=>a({x:e.clientX,y:e.clientY}),h=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",h),()=>{t.current&&(t.current.removeEventListener("mousedown",f),t.current.removeEventListener("touchstart",h))}},[t.current]),{ref:t,active:x}}export{w as useMove};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/esm/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":[],"mappings":";;;
|
|
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":"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"}
|
package/esm/usePrevious/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useRef as t,useEffect as u}from"react";function c(
|
|
1
|
+
import{useRef as t,useEffect as u}from"react";function c(e){const r=t();return u(()=>{r.current=e},[e]),r.current}export{c as usePrevious};
|
|
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":[],"mappings":";;
|
|
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,MAAC,EAAE,CAAC,OAAOC,SAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO;;;;"}
|
package/esm/useQueue/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useState as
|
|
1
|
+
import{useState as l}from"react";function r({initialValues:i=[],limit:e}){const[{state:c,queue:n},a]=l({state:i.slice(0,e),queue:i.slice(e)});return{state:c,queue:n,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:[]}))}}export{r as useQueue};
|
|
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":[],"mappings":";;
|
|
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,QAAC,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 +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":[],"mappings":";;
|
|
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,aAAC,CAAC,kCAAkC,CAAC;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useState as f,useRef as
|
|
1
|
+
import{useState as f,useRef as c,useEffect as n}from"react";function i(o){const[t,e]=f(o||!1),r=c(!1),d=c(null),u=()=>{r.current&&(r.current=!1,document.body.style.overflow=d.current||"")},l=()=>{r.current=!0,d.current=document.body.style.overflow,document.body.style.overflow="hidden"};return n(()=>(t?l():u(),u),[t]),n(()=>{o!==void 0&&e(o)},[o]),n(()=>{o===void 0&&typeof window!="undefined"&&window.document.body.style.overflow==="hidden"&&e(!0)},[e]),[t,e]}export{i as useScrollLock};
|
|
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":[],"mappings":";;
|
|
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,QAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAACC,MAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,MAAC,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,SAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,SAAC,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACA,SAAC,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/esm/useToggle/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useState as
|
|
1
|
+
import{useState as c}from"react";function r(e,o){const[t,u]=c(e);return[t,n=>{u(typeof n!="undefined"?n:f=>f===o[0]?o[1]:o[0])}]}function g(e=!1){return r(e,[!0,!1])}export{g as useBooleanToggle,r as useToggle};
|
|
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":[],"mappings":";;
|
|
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,QAAC,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;;;;"}
|