@kubed/hooks 0.0.9 → 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,11 @@
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
+
3
9
  ## 0.0.9
4
10
 
5
11
  ### Patch Changes
package/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var index$j=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");exports.assignRef=index$j.assignRef,exports.clamp=index$j.clamp,exports.randomId=index$j.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;
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");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;;;;"}
package/esm/index.js CHANGED
@@ -1,2 +1,2 @@
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";
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{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);\n }\n }, [setScrollLocked]);\n\n return [scrollLocked, setScrollLocked] as const;\n}\n"],"names":[],"mappings":";;AACO,SAAS,aAAa,CAAC,IAAI,EAAE;AACpC,EAAE,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC;AAClE,EAAE,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAC/B,EAAE,MAAM,YAAY,GAAG,MAAM,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,EAAE,SAAS,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,EAAE,SAAS,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,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;;;;"}
package/lib/index.d.ts CHANGED
@@ -18,4 +18,5 @@ export { useDidMount } from './useDidMount';
18
18
  export { useDidUpdate } from './useDidUpdate';
19
19
  export { useUnmount } from './useUnmount';
20
20
  export { usePrevious } from './usePrevious';
21
+ export { useScrollLock } from './useScrollLock';
21
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,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
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,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubed/hooks",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "types": "lib/index.d.ts",