@kubed/hooks 0.0.8 → 0.0.10

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @kubed/hooks
2
2
 
3
+ ## 0.0.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [`7bdb130`](https://github.com/kubesphere/kube-design/commit/7bdb130dcbbe3f65870b564f811556462fd727d4) Thanks [@chenz24](https://github.com/chenz24)! - 1. export useScreenLock hook
8
+
9
+ ## 0.0.9
10
+
11
+ ### Patch Changes
12
+
13
+ - [`d589bc9`](https://github.com/kubesphere/kube-design/commit/d589bc9b5a8d42390fc1a2f494ccb4b5bda34bd9) Thanks [@chenz24](https://github.com/chenz24)! - 1. fix: Fix AutoComplete 'omit' import bug.
14
+ 2. refactor: Improve Slider.
15
+
3
16
  ## 0.0.8
4
17
 
5
18
  ### Patch Changes
package/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var index$i=require("./utils/index.js"),index=require("./useId/index.js"),index$1=require("./useToggle/index.js"),index$2=require("./useUncontrolled/index.js"),index$3=require("./useMediaQuery/index.js"),index$4=require("./useReducedMotion/index.js"),index$5=require("./useWindowEvent/index.js"),index$6=require("./useLocalStorage/index.js"),index$7=require("./useForceUpdate/index.js"),index$8=require("./useClipboard/index.js"),index$9=require("./useQueue/index.js"),index$a=require("./useClickOutside/index.js"),index$b=require("./useMove/index.js"),index$c=require("./useHotkeys/index.js"),index$d=require("./useDebouncedValue/index.js"),index$e=require("./useDidMount/index.js"),index$f=require("./useDidUpdate/index.js"),index$g=require("./useUnmount/index.js"),index$h=require("./usePrevious/index.js");exports.clamp=index$i.clamp,exports.randomId=index$i.randomId,exports.useId=index.useId,exports.useBooleanToggle=index$1.useBooleanToggle,exports.useToggle=index$1.useToggle,exports.useUncontrolled=index$2.useUncontrolled,exports.useMediaQuery=index$3.useMediaQuery,exports.useReducedMotion=index$4.useReducedMotion,exports.useWindowEvent=index$5.useWindowEvent,exports.useLocalStorage=index$6.useLocalStorage,exports.useForceUpdate=index$7.useForceUpdate,exports.useClipboard=index$8.useClipboard,exports.useQueue=index$9.useQueue,exports.useClickOutside=index$a.useClickOutside,exports.useMove=index$b.useMove,exports.useHotkeys=index$c.useHotkeys,exports.useDebouncedValue=index$d.useDebouncedValue,exports.useDidMount=index$e.useDidMount,exports.useDidUpdate=index$f.useDidUpdate,exports.useUnmount=index$g.useUnmount,exports.usePrevious=index$h.usePrevious;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var index$k=require("./utils/index.js"),index=require("./useId/index.js"),index$1=require("./useToggle/index.js"),index$2=require("./useUncontrolled/index.js"),index$3=require("./useMediaQuery/index.js"),index$4=require("./useReducedMotion/index.js"),index$5=require("./useWindowEvent/index.js"),index$6=require("./useLocalStorage/index.js"),index$7=require("./useForceUpdate/index.js"),index$8=require("./useClipboard/index.js"),index$9=require("./useQueue/index.js"),index$a=require("./useClickOutside/index.js"),index$b=require("./useMove/index.js"),index$c=require("./useHotkeys/index.js"),index$d=require("./useMergedRef/index.js"),index$e=require("./useDebouncedValue/index.js"),index$f=require("./useDidMount/index.js"),index$g=require("./useDidUpdate/index.js"),index$h=require("./useUnmount/index.js"),index$i=require("./usePrevious/index.js"),index$j=require("./useScrollLock/index.js");exports.assignRef=index$k.assignRef,exports.clamp=index$k.clamp,exports.randomId=index$k.randomId,exports.useId=index.useId,exports.useBooleanToggle=index$1.useBooleanToggle,exports.useToggle=index$1.useToggle,exports.useUncontrolled=index$2.useUncontrolled,exports.useMediaQuery=index$3.useMediaQuery,exports.useReducedMotion=index$4.useReducedMotion,exports.useWindowEvent=index$5.useWindowEvent,exports.useLocalStorage=index$6.useLocalStorage,exports.useForceUpdate=index$7.useForceUpdate,exports.useClipboard=index$8.useClipboard,exports.useQueue=index$9.useQueue,exports.useClickOutside=index$a.useClickOutside,exports.useMove=index$b.useMove,exports.useHotkeys=index$c.useHotkeys,exports.mergeRefs=index$d.mergeRefs,exports.useMergedRef=index$d.useMergedRef,exports.useDebouncedValue=index$e.useDebouncedValue,exports.useDidMount=index$f.useDidMount,exports.useDidUpdate=index$g.useDidUpdate,exports.useUnmount=index$h.useUnmount,exports.usePrevious=index$i.usePrevious,exports.useScrollLock=index$j.useScrollLock;
2
2
  //# sourceMappingURL=index.js.map
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react"),index=require("../utils/index.js");function useMergedRef(...e){return react.useCallback(r=>{e.forEach(s=>index.assignRef(s,r))},e)}function mergeRefs(...e){return r=>{e.forEach(s=>index.assignRef(s,r))}}exports.mergeRefs=mergeRefs,exports.useMergedRef=useMergedRef;
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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":["useCallback","assignRef"],"mappings":";;;;;;;AAEO,SAAS,YAAY,CAAC,GAAG,IAAI,EAAE;AACtC,EAAE,OAAOA,iBAAW,CAAC,CAAC,IAAI,KAAK;AAC/B,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,KAAKC,eAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;AAChD,GAAG,EAAE,IAAI,CAAC,CAAC;AACX,CAAC;AACM,SAAS,SAAS,CAAC,GAAG,IAAI,EAAE;AACnC,EAAE,OAAO,CAAC,IAAI,KAAK;AACnB,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,KAAKA,eAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;AAChD,GAAG,CAAC;AACJ;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/useMove/index.tsx"],"sourcesContent":["// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-move/use-move.ts\n/* 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":["useRef","useState","useEffect","clamp"],"mappings":";;;;;;;AAMO,SAAS,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE;AAC5C,EAAE,MAAM,GAAG,GAAGA,YAAM,EAAE,CAAC;AACvB,EAAE,MAAM,OAAO,GAAGA,YAAM,CAAC,KAAK,CAAC,CAAC;AAChC,EAA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AAC,gBAAgB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;AAC7D,IAAI,OAAO,MAAM;AACjB,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE;AACvB,QAAQ,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAClE,QAAQ,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;AACpE,OAAO;AACP,KAAK,CAAC;AACN,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;AACpB,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;AACzB;;;;"}
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":["useRef","useState","useEffect","clamp"],"mappings":";;;;;;;AAMO,SAAS,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE;AAC5C,EAAE,MAAM,GAAG,GAAGA,YAAM,EAAE,CAAC;AACvB,EAAE,MAAM,OAAO,GAAGA,YAAM,CAAC,KAAK,CAAC,CAAC;AAChC,EAAE,MAAM,SAAS,GAAGA,Y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Y,EAAE,YAAY,CAAC,CAAC;AAC7D,IAAI,OAAO,MAAM;AACjB,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE;AACvB,QAAQ,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAClE,QAAQ,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;AACpE,OAAO;AACP,KAAK,CAAC;AACN,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;AACpB,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;AACzB;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react");function useScrollLock(e){const[t,o]=react.useState(e||!1),r=react.useRef(!1),c=react.useRef(null),u=()=>{r.current&&(r.current=!1,document.body.style.overflow=c.current||"")},l=()=>{r.current=!0,c.current=document.body.style.overflow,document.body.style.overflow="hidden"};return react.useEffect(()=>(t?l():u(),u),[t]),react.useEffect(()=>{e!==void 0&&o(e)},[e]),react.useEffect(()=>{e===void 0&&typeof window!="undefined"&&window.document.body.style.overflow==="hidden"&&o(!0)},[o]),[t,o]}exports.useScrollLock=useScrollLock;
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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":["useState","useRef","useEffect"],"mappings":";;;;;;AACO,SAAS,aAAa,CAAC,IAAI,EAAE;AACpC,EAAE,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAGA,cAAQ,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC;AAClE,EAAE,MAAM,MAAM,GAAGC,YAAM,CAAC,KAAK,CAAC,CAAC;AAC/B,EAAE,MAAM,YAAY,GAAGA,YAAM,CAAC,IAAI,CAAC,CAAC;AACpC,EAAE,MAAM,YAAY,GAAG,MAAM;AAC7B,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE;AACxB,MAAM,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC;AAC7B,MAAM,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,YAAY,CAAC,OAAO,IAAI,EAAE,CAAC;AAChE,KAAK;AACL,GAAG,CAAC;AACJ,EAAE,MAAM,UAAU,GAAG,MAAM;AAC3B,IAAI,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;AAC1B,IAAI,YAAY,CAAC,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;AACxD,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC5C,GAAG,CAAC;AACJ,EAAEC,eAAS,CAAC,MAAM;AAClB,IAAI,IAAI,YAAY,EAAE;AACtB,MAAM,UAAU,EAAE,CAAC;AACnB,KAAK,MAAM;AACX,MAAM,YAAY,EAAE,CAAC;AACrB,KAAK;AACL,IAAI,OAAO,YAAY,CAAC;AACxB,GAAG,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;AACrB,EAAEA,eAAS,CAAC,MAAM;AAClB,IAAI,IAAI,IAAI,KAAK,KAAK,CAAC,EAAE;AACzB,MAAM,eAAe,CAAC,IAAI,CAAC,CAAC;AAC5B,KAAK;AACL,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;AACb,EAAEA,eAAS,CAAC,MAAM;AAClB,IAAI,IAAI,IAAI,KAAK,KAAK,CAAC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AAC1D,MAAM,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,KAAK,QAAQ,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;AAChF,KAAK;AACL,GAAG,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;AACxB,EAAE,OAAO,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;AACzC;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});function randomId(){return`kubed-${Math.random().toString(36).substr(2,9)}`}function clamp({value:t,min:r,max:e}){return Math.min(Math.max(t,r),e)}exports.clamp=clamp,exports.randomId=randomId;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});function randomId(){return`kubed-${Math.random().toString(36).substr(2,9)}`}function clamp({value:t,min:n,max:e}){return Math.min(Math.max(t,n),e)}function assignRef(t,n){typeof t=="function"?t(n):typeof t=="object"&&t!==null&&"current"in t&&(t.current=n)}exports.assignRef=assignRef,exports.clamp=clamp,exports.randomId=randomId;
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/utils/index.ts"],"sourcesContent":["export 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"],"names":[],"mappings":";;;;AAAO,SAAS,QAAQ,GAAG;AAC3B,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AACM,SAAS,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;AAC3C,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;AAC7C;;;;;"}
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,GAAG;AAC3B,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AACM,SAAS,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;AAC3C,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;AAC7C,CAAC;AACM,SAAS,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE;AACtC,EAAE,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;AACjC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;AACf,GAAG,MAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,SAAS,IAAI,GAAG,EAAE;AAC1E,IAAI,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;AACxB,GAAG;AACH;;;;;;"}
package/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export{clamp,randomId}from"./utils/index.js";export{useId}from"./useId/index.js";export{useBooleanToggle,useToggle}from"./useToggle/index.js";export{useUncontrolled}from"./useUncontrolled/index.js";export{useMediaQuery}from"./useMediaQuery/index.js";export{useReducedMotion}from"./useReducedMotion/index.js";export{useWindowEvent}from"./useWindowEvent/index.js";export{useLocalStorage}from"./useLocalStorage/index.js";export{useForceUpdate}from"./useForceUpdate/index.js";export{useClipboard}from"./useClipboard/index.js";export{useQueue}from"./useQueue/index.js";export{useClickOutside}from"./useClickOutside/index.js";export{useMove}from"./useMove/index.js";export{useHotkeys}from"./useHotkeys/index.js";export{useDebouncedValue}from"./useDebouncedValue/index.js";export{useDidMount}from"./useDidMount/index.js";export{useDidUpdate}from"./useDidUpdate/index.js";export{useUnmount}from"./useUnmount/index.js";export{usePrevious}from"./usePrevious/index.js";
1
+ export{assignRef,clamp,randomId}from"./utils/index.js";export{useId}from"./useId/index.js";export{useBooleanToggle,useToggle}from"./useToggle/index.js";export{useUncontrolled}from"./useUncontrolled/index.js";export{useMediaQuery}from"./useMediaQuery/index.js";export{useReducedMotion}from"./useReducedMotion/index.js";export{useWindowEvent}from"./useWindowEvent/index.js";export{useLocalStorage}from"./useLocalStorage/index.js";export{useForceUpdate}from"./useForceUpdate/index.js";export{useClipboard}from"./useClipboard/index.js";export{useQueue}from"./useQueue/index.js";export{useClickOutside}from"./useClickOutside/index.js";export{useMove}from"./useMove/index.js";export{useHotkeys}from"./useHotkeys/index.js";export{mergeRefs,useMergedRef}from"./useMergedRef/index.js";export{useDebouncedValue}from"./useDebouncedValue/index.js";export{useDidMount}from"./useDidMount/index.js";export{useDidUpdate}from"./useDidUpdate/index.js";export{useUnmount}from"./useUnmount/index.js";export{usePrevious}from"./usePrevious/index.js";export{useScrollLock}from"./useScrollLock/index.js";
2
2
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ import{useCallback as f}from"react";import{assignRef as t}from"../utils/index.js";function n(...e){return f(r=>{e.forEach(o=>t(o,r))},e)}function i(...e){return r=>{e.forEach(o=>t(o,r))}}export{i as mergeRefs,n as useMergedRef};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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":";;;AAEO,SAAS,YAAY,CAAC,GAAG,IAAI,EAAE;AACtC,EAAE,OAAO,WAAW,CAAC,CAAC,IAAI,KAAK;AAC/B,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;AAChD,GAAG,EAAE,IAAI,CAAC,CAAC;AACX,CAAC;AACM,SAAS,SAAS,CAAC,GAAG,IAAI,EAAE;AACnC,EAAE,OAAO,CAAC,IAAI,KAAK;AACnB,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;AAChD,GAAG,CAAC;AACJ;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/useMove/index.tsx"],"sourcesContent":["// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-move/use-move.ts\n/* 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":";;;AAMO,SAAS,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE;AAC5C,EAAE,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;AACvB,EAAE,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAChC,EAAE,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAClC,EAAE,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAC1B,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,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CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAClE,QAAQ,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;AACpE,OAAO;AACP,KAAK,CAAC;AACN,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;AACpB,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;AACzB;;;;"}
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":";;;AAMO,SAAS,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE;AAC5C,EAAE,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;AACvB,EAAE,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAChC,EAAE,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAClC,EAAE,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAC1B,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC9C,EAAE,S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AC,OAAO,CAAC,mBAAmB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;AACpE,OAAO;AACP,KAAK,CAAC;AACN,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;AACpB,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;AACzB;;;;"}
@@ -0,0 +1,2 @@
1
+ import{useState as f,useRef as d,useEffect as n}from"react";function s(e){const[t,o]=f(e||!1),r=d(!1),c=d(null),l=()=>{r.current&&(r.current=!1,document.body.style.overflow=c.current||"")},u=()=>{r.current=!0,c.current=document.body.style.overflow,document.body.style.overflow="hidden"};return n(()=>(t?u():l(),l),[t]),n(()=>{e!==void 0&&o(e)},[e]),n(()=>{e===void 0&&typeof window!="undefined"&&window.document.body.style.overflow==="hidden"&&o(!0)},[o]),[t,o]}export{s as useScrollLock};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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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C,IAAI,CAAC,CAAC,CAAC;AACb,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,IAAI,KAAK,KAAK,CAAC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AAC1D,MAAM,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,KAAK,QAAQ,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;AAChF,KAAK;AACL,GAAG,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;AACxB,EAAE,OAAO,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;AACzC;;;;"}
@@ -1,2 +1,2 @@
1
- function a(){return`kubed-${Math.random().toString(36).substr(2,9)}`}function o({value:t,min:n,max:r}){return Math.min(Math.max(t,n),r)}export{o as clamp,a as randomId};
1
+ function i(){return`kubed-${Math.random().toString(36).substr(2,9)}`}function u({value:n,min:t,max:o}){return Math.min(Math.max(n,t),o)}function c(n,t){typeof n=="function"?n(t):typeof n=="object"&&n!==null&&"current"in n&&(n.current=t)}export{c as assignRef,u as clamp,i as randomId};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/utils/index.ts"],"sourcesContent":["export 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"],"names":[],"mappings":"AAAO,SAAS,QAAQ,GAAG;AAC3B,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AACM,SAAS,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;AAC3C,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;AAC7C;;;;"}
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,GAAG;AAC3B,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AACM,SAAS,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;AAC3C,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;AAC7C,CAAC;AACM,SAAS,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE;AACtC,EAAE,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;AACjC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;AACf,GAAG,MAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,SAAS,IAAI,GAAG,EAAE;AAC1E,IAAI,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;AACxB,GAAG;AACH;;;;"}
package/lib/index.d.ts CHANGED
@@ -12,9 +12,11 @@ export { useQueue } from './useQueue';
12
12
  export { useClickOutside } from './useClickOutside';
13
13
  export { useMove } from './useMove';
14
14
  export { useHotkeys } from './useHotkeys';
15
+ export { useMergedRef, mergeRefs } from './useMergedRef';
15
16
  export { useDebouncedValue } from './useDebouncedValue';
16
17
  export { useDidMount } from './useDidMount';
17
18
  export { useDidUpdate } from './useDidUpdate';
18
19
  export { useUnmount } from './useUnmount';
19
20
  export { usePrevious } from './usePrevious';
21
+ export { useScrollLock } from './useScrollLock';
20
22
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,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@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ declare type Ref<T> = React.Dispatch<React.SetStateAction<T>> | React.ForwardedRef<T>;
3
+ export declare function useMergedRef<T = any>(...refs: Ref<T>[]): (node: T | null) => void;
4
+ export declare function mergeRefs<T = any>(...refs: Ref<T>[]): (node: T | null) => void;
5
+ export {};
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useMergedRef/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAsB,MAAM,OAAO,CAAC;AAG3C,aAAK,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;AAE9E,wBAAgB,YAAY,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,UAC3B,CAAC,GAAG,IAAI,UAGnC;AAED,wBAAgB,SAAS,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,UACpC,CAAC,GAAG,IAAI,UAGvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useMove/index.tsx"],"names":[],"mappings":";AAKA,MAAM,WAAW,eAAe;IAC9B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,eAAO,MAAM,oBAAoB,aAAc,eAAe;;;CAG5D,CAAC;AAEH,UAAU,eAAe;IACvB,YAAY,CAAC,IAAI,IAAI,CAAC;IACtB,UAAU,CAAC,IAAI,IAAI,CAAC;CACrB;AAED,wBAAgB,OAAO,CAAC,CAAC,SAAS,WAAW,GAAG,cAAc,EAC5D,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,EAC1C,QAAQ,CAAC,EAAE,eAAe;;;EA6F3B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useMove/index.ts"],"names":[],"mappings":";AAIA,MAAM,WAAW,eAAe;IAC9B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,eAAO,MAAM,oBAAoB,aAAc,eAAe;;;CAG5D,CAAC;AAEH,UAAU,eAAe;IACvB,YAAY,CAAC,IAAI,IAAI,CAAC;IACtB,UAAU,CAAC,IAAI,IAAI,CAAC;CACrB;AAED,wBAAgB,OAAO,CAAC,CAAC,SAAS,WAAW,GAAG,cAAc,EAC5D,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,EAC1C,QAAQ,CAAC,EAAE,eAAe;;;EA6F3B"}
@@ -1,3 +1,4 @@
1
+ import React from 'react';
1
2
  export declare function randomId(): string;
2
3
  interface Clamp {
3
4
  value: number;
@@ -5,5 +6,6 @@ interface Clamp {
5
6
  max: number;
6
7
  }
7
8
  export declare function clamp({ value, min, max }: Clamp): number;
9
+ export declare function assignRef<T = any>(ref: React.ForwardedRef<T>, value: T | null): void;
8
10
  export {};
9
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,WAEvB;AAED,UAAU,KAAK;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAED,wBAAgB,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,KAAK,UAE/C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,wBAAgB,QAAQ,WAEvB;AAED,UAAU,KAAK;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAED,wBAAgB,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,KAAK,UAE/C;AAED,wBAAgB,SAAS,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,QAO7E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubed/hooks",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "types": "lib/index.d.ts",