@kubed/hooks 0.0.2 → 0.0.6

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.
Files changed (76) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/cjs/index.js +1 -30
  3. package/cjs/index.js.map +1 -1
  4. package/cjs/useClickOutside/index.js +2 -0
  5. package/cjs/useClickOutside/index.js.map +1 -0
  6. package/cjs/useClipboard/index.js +1 -31
  7. package/cjs/useDebouncedValue/index.js +2 -0
  8. package/cjs/useDebouncedValue/index.js.map +1 -0
  9. package/cjs/useDidMount/index.js +2 -0
  10. package/cjs/useDidMount/index.js.map +1 -0
  11. package/cjs/useDidUpdate/index.js +2 -0
  12. package/cjs/useDidUpdate/index.js.map +1 -0
  13. package/cjs/useForceUpdate/index.js +1 -13
  14. package/cjs/useHotkeys/index.js +2 -0
  15. package/cjs/useHotkeys/index.js.map +1 -0
  16. package/cjs/useHotkeys/parseHotkey.js +2 -0
  17. package/cjs/useHotkeys/parseHotkey.js.map +1 -0
  18. package/cjs/useId/index.js +1 -13
  19. package/cjs/useLocalStorage/index.js +1 -38
  20. package/cjs/useMediaQuery/index.js +1 -35
  21. package/cjs/useMove/index.js +2 -0
  22. package/cjs/useMove/index.js.map +1 -0
  23. package/cjs/useQueue/index.js +1 -36
  24. package/cjs/useReducedMotion/index.js +1 -11
  25. package/cjs/useToggle/index.js +1 -28
  26. package/cjs/useUncontrolled/index.js +1 -40
  27. package/cjs/useWindowEvent/index.js +1 -14
  28. package/cjs/utils/index.js +1 -9
  29. package/cjs/utils/index.js.map +1 -1
  30. package/esm/index.js +1 -11
  31. package/esm/index.js.map +1 -1
  32. package/esm/useClickOutside/index.js +2 -0
  33. package/esm/useClickOutside/index.js.map +1 -0
  34. package/esm/useClipboard/index.js +1 -27
  35. package/esm/useDebouncedValue/index.js +2 -0
  36. package/esm/useDebouncedValue/index.js.map +1 -0
  37. package/esm/useDidMount/index.js +2 -0
  38. package/esm/useDidMount/index.js.map +1 -0
  39. package/esm/useDidUpdate/index.js +2 -0
  40. package/esm/useDidUpdate/index.js.map +1 -0
  41. package/esm/useForceUpdate/index.js +1 -9
  42. package/esm/useHotkeys/index.js +2 -0
  43. package/esm/useHotkeys/index.js.map +1 -0
  44. package/esm/useHotkeys/parseHotkey.js +2 -0
  45. package/esm/useHotkeys/parseHotkey.js.map +1 -0
  46. package/esm/useId/index.js +1 -9
  47. package/esm/useLocalStorage/index.js +1 -34
  48. package/esm/useMediaQuery/index.js +1 -31
  49. package/esm/useMove/index.js +2 -0
  50. package/esm/useMove/index.js.map +1 -0
  51. package/esm/useQueue/index.js +1 -32
  52. package/esm/useReducedMotion/index.js +1 -7
  53. package/esm/useToggle/index.js +1 -23
  54. package/esm/useUncontrolled/index.js +1 -36
  55. package/esm/useWindowEvent/index.js +1 -10
  56. package/esm/utils/index.js +1 -5
  57. package/esm/utils/index.js.map +1 -1
  58. package/lib/index.d.ts +6 -0
  59. package/lib/index.d.ts.map +1 -1
  60. package/lib/useClickOutside/index.d.ts +3 -0
  61. package/lib/useClickOutside/index.d.ts.map +1 -0
  62. package/lib/useDebouncedValue/index.d.ts +4 -0
  63. package/lib/useDebouncedValue/index.d.ts.map +1 -0
  64. package/lib/useDidUpdate/index.d.ts +2 -0
  65. package/lib/useDidUpdate/index.d.ts.map +1 -0
  66. package/lib/useHotkeys/index.d.ts +5 -0
  67. package/lib/useHotkeys/index.d.ts.map +1 -0
  68. package/lib/useHotkeys/parseHotkey.d.ts +18 -0
  69. package/lib/useHotkeys/parseHotkey.d.ts.map +1 -0
  70. package/lib/useMove/index.d.ts +19 -0
  71. package/lib/useMove/index.d.ts.map +1 -0
  72. package/lib/utils/index.d.ts +7 -0
  73. package/lib/utils/index.d.ts.map +1 -1
  74. package/package.json +1 -2
  75. package/lib/index.umd.js +0 -2
  76. package/lib/index.umd.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,8 +1,35 @@
1
1
  # @kubed/hooks
2
2
 
3
- ## 0.0.2
3
+ ## 0.0.6
4
+
4
5
  ### Patch Changes
5
6
 
7
+ - [`db858ee`](https://github.com/kubesphere/kube-design/commit/db858ee70bc841176d9dd8cf3d52ce6a3927fc2c) Thanks [@chenz24](https://github.com/chenz24)! - 1. add useDidUpdate hook.
8
+
9
+ ## 0.0.5
10
+
11
+ ### Patch Changes
12
+
13
+ - [`f39c7e8`](https://github.com/kubesphere/kube-design/commit/f39c7e8d9550ddd329dc057bf6a737835b738d33) Thanks [@chenz24](https://github.com/chenz24)! - 1. Completely Refactor Empty component.
14
+ 2. Add useDebouncedValue hook.
15
+ 3. Reset default props for LoadingOverlay.
16
+
17
+ ## 0.0.4
18
+
19
+ ### Patch Changes
6
20
 
21
+ - [`bf37ccc`](https://github.com/kubesphere/kube-design/commit/bf37cccbf64598b67b6e599b61c9d4ed33ec8504) Thanks [@chenz24](https://github.com/chenz24)! - 1. Add hotkey hook.
22
+ 2. Fix Banner cannot set className
23
+
24
+ ## 0.0.3
25
+
26
+ ### Patch Changes
27
+
28
+ - [`de74de1`](https://github.com/kubesphere/kube-design/commit/de74de1786e2dcef25f7fea435d24dc146527b78) Thanks [@chenz24](https://github.com/chenz24)! - 1. Remove umd build and browser field in package.json.
29
+ 2. Remove useless export in Select.
30
+
31
+ ## 0.0.2
32
+
33
+ ### Patch Changes
7
34
 
8
35
  - [`df0624c`](https://github.com/kubesphere/kube-design/commit/df0624c146781210b3eb8849bdb7ceea65c064e5) Thanks [@chenz24](https://github.com/chenz24)! - add useScrollLock hook
package/cjs/index.js CHANGED
@@ -1,31 +1,2 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var index$a = require('./utils/index.js');
6
- var index = require('./useId/index.js');
7
- var index$1 = require('./useToggle/index.js');
8
- var index$2 = require('./useUncontrolled/index.js');
9
- var index$3 = require('./useMediaQuery/index.js');
10
- var index$4 = require('./useReducedMotion/index.js');
11
- var index$5 = require('./useWindowEvent/index.js');
12
- var index$6 = require('./useLocalStorage/index.js');
13
- var index$7 = require('./useForceUpdate/index.js');
14
- var index$8 = require('./useClipboard/index.js');
15
- var index$9 = require('./useQueue/index.js');
16
-
17
-
18
-
19
- exports.randomId = index$a.randomId;
20
- exports.useId = index.useId;
21
- exports.useBooleanToggle = index$1.useBooleanToggle;
22
- exports.useToggle = index$1.useToggle;
23
- exports.useUncontrolled = index$2.useUncontrolled;
24
- exports.useMediaQuery = index$3.useMediaQuery;
25
- exports.useReducedMotion = index$4.useReducedMotion;
26
- exports.useWindowEvent = index$5.useWindowEvent;
27
- exports.useLocalStorage = index$6.useLocalStorage;
28
- exports.useForceUpdate = index$7.useForceUpdate;
29
- exports.useClipboard = index$8.useClipboard;
30
- exports.useQueue = index$9.useQueue;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var index$g=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");exports.clamp=index$g.clamp,exports.randomId=index$g.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;
31
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");const DEFAULT_EVENTS=["mousedown","touchstart"];function useClickOutside(t,u,s){const r=react.useRef();return react.useEffect(()=>{const c=e=>{Array.isArray(s)?s.every(i=>!!i&&!i.contains(e.target))&&t():r.current&&!r.current.contains(e.target)&&t()};return(u||DEFAULT_EVENTS).forEach(e=>document.addEventListener(e,c)),()=>{(u||DEFAULT_EVENTS).forEach(e=>document.removeEventListener(e,c))}},[r,t,s]),r}exports.useClickOutside=useClickOutside;
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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));\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
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var react = require('react');
6
-
7
- function useClipboard({ timeout = 2e3 } = {}) {
8
- const [error, setError] = react.useState(null);
9
- const [copied, setCopied] = react.useState(false);
10
- const [copyTimeout, setCopyTimeout] = react.useState(null);
11
- const handleCopyResult = (value) => {
12
- clearTimeout(copyTimeout);
13
- setCopyTimeout(setTimeout(() => setCopied(false), timeout));
14
- setCopied(value);
15
- };
16
- const copy = (valueToCopy) => {
17
- if ("clipboard" in navigator) {
18
- navigator.clipboard.writeText(valueToCopy).then(() => handleCopyResult(true)).catch((err) => setError(err));
19
- } else {
20
- setError(new Error("useClipboard: navigator.clipboard is not supported"));
21
- }
22
- };
23
- const reset = () => {
24
- setCopied(false);
25
- setError(null);
26
- clearTimeout(copyTimeout);
27
- };
28
- return { copy, reset, error, copied };
29
- }
30
-
31
- exports.useClipboard = useClipboard;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react");function useClipboard({timeout:s=2e3}={}){const[a,e]=react.useState(null),[i,t]=react.useState(!1),[o,u]=react.useState(null),c=r=>{clearTimeout(o),u(setTimeout(()=>t(!1),s)),t(r)};return{copy:r=>{"clipboard"in navigator?navigator.clipboard.writeText(r).then(()=>c(!0)).catch(l=>e(l)):e(new Error("useClipboard: navigator.clipboard is not supported"))},reset:()=>{t(!1),e(null),clearTimeout(o)},error:a,copied:i}}exports.useClipboard=useClipboard;
32
2
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react");function useDebouncedValue(e,o,r={leading:!1}){const[f,n]=react.useState(e),c=react.useRef(!1),s=react.useRef(null),t=react.useRef(!1),u=()=>window.clearTimeout(s.current);return react.useEffect(()=>{c.current&&(!t.current&&r.leading?(t.current=!0,n(e)):(u(),s.current=window.setTimeout(()=>{t.current=!1,n(e)},o)))},[e,r.leading]),react.useEffect(()=>(c.current=!0,u),[]),[f,u]}exports.useDebouncedValue=useDebouncedValue;
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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":["useState","useRef","useEffect"],"mappings":";;;;;;AACO,SAAS,iBAAiB,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;AAC7E,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAGA,cAAQ,CAAC,KAAK,CAAC,CAAC;AAC7C,EAAE,MAAM,UAAU,GAAGC,YAAM,CAAC,KAAK,CAAC,CAAC;AACnC,EAAE,MAAM,UAAU,GAAGA,YAAM,CAAC,IAAI,CAAC,CAAC;AAClC,EAAE,MAAM,WAAW,GAAGA,YAAM,CAAC,KAAK,CAAC,CAAC;AACpC,EAAE,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAC/D,EAAEC,eAAS,CAAC,MAAM;AAClB,IAAI,IAAI,UAAU,CAAC,OAAO,EAAE;AAC5B,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE;AACnD,QAAQ,WAAW,CAAC,OAAO,GAAG,IAAI,CAAC;AACnC,QAAQ,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxB,OAAO,MAAM;AACb,QAAQ,MAAM,EAAE,CAAC;AACjB,QAAQ,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM;AACrD,UAAU,WAAW,CAAC,OAAO,GAAG,KAAK,CAAC;AACtC,UAAU,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC1B,SAAS,EAAE,IAAI,CAAC,CAAC;AACjB,OAAO;AACP,KAAK;AACL,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;AAC/B,EAAEA,eAAS,CAAC,MAAM;AAClB,IAAI,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;AAC9B,IAAI,OAAO,MAAM,CAAC;AAClB,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC1B;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react");function useDidMount(e){react.useEffect(()=>{typeof e=="function"&&e()},[])}exports.useDidMount=useDidMount;
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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":["useEffect"],"mappings":";;;;;;AACO,SAAS,WAAW,CAAC,QAAQ,EAAE;AACtC,EAAEA,eAAS,CAAC,MAAM;AAClB,IAAI,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;AACxC,MAAM,QAAQ,EAAE,CAAC;AACjB,KAAK;AACL,GAAG,EAAE,EAAE,CAAC,CAAC;AACT;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react");function useDidUpdate(t,r){const e=react.useRef(!1);react.useEffect(()=>{e.current?t():e.current=!0},r)}exports.useDidUpdate=useDidUpdate;
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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":["useRef","useEffect"],"mappings":";;;;;;AACO,SAAS,YAAY,CAAC,EAAE,EAAE,YAAY,EAAE;AAC/C,EAAE,MAAM,OAAO,GAAGA,YAAM,CAAC,KAAK,CAAC,CAAC;AAChC,EAAEC,eAAS,CAAC,MAAM;AAClB,IAAI,IAAI,OAAO,CAAC,OAAO,EAAE;AACzB,MAAM,EAAE,EAAE,CAAC;AACX,KAAK,MAAM;AACX,MAAM,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;AAC7B,KAAK;AACL,GAAG,EAAE,YAAY,CAAC,CAAC;AACnB;;;;"}
@@ -1,14 +1,2 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var react = require('react');
6
-
7
- const reducer = (value) => (value + 1) % 1e6;
8
- function useForceUpdate() {
9
- const [, update] = react.useReducer(reducer, 0);
10
- return update;
11
- }
12
-
13
- exports.useForceUpdate = useForceUpdate;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react");const reducer=e=>(e+1)%1e6;function useForceUpdate(){const[,e]=react.useReducer(reducer,0);return e}exports.useForceUpdate=useForceUpdate;
14
2
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react"),parseHotkey=require("./parseHotkey.js");function useHotkeys(t){react.useEffect(()=>{const r=e=>{t.forEach(([o,n])=>{parseHotkey.getHotkeyMatcher(o)(e)&&(e.preventDefault(),n(e))})};return document.documentElement.addEventListener("keydown",r),()=>document.documentElement.removeEventListener("keydown",r)},[t])}exports.useHotkeys=useHotkeys;
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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":["useEffect","getHotkeyMatcher"],"mappings":";;;;;;;AAGO,SAAS,UAAU,CAAC,OAAO,EAAE;AACpC,EAAEA,eAAS,CAAC,MAAM;AAClB,IAAI,MAAM,eAAe,GAAG,CAAC,KAAK,KAAK;AACvC,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK;AAC7C,QAAQ,IAAIC,4BAAgB,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,EAAE;AAC7C,UAAU,KAAK,CAAC,cAAc,EAAE,CAAC;AACjC,UAAU,OAAO,CAAC,KAAK,CAAC,CAAC;AACzB,SAAS;AACT,OAAO,CAAC,CAAC;AACT,KAAK,CAAC;AACN,IAAI,QAAQ,CAAC,eAAe,CAAC,gBAAgB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;AAC1E,IAAI,OAAO,MAAM,QAAQ,CAAC,eAAe,CAAC,mBAAmB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;AAC1F,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAChB;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var __defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,e,t)=>e in r?__defProp(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,__spreadValues=(r,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(r,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(r,t,e[t]);return r},__spreadProps=(r,e)=>__defProps(r,__getOwnPropDescs(e));function parseHotkey(r){const e=r.toLowerCase().split("+").map(s=>s.trim()),t={alt:e.includes("alt"),ctrl:e.includes("ctrl"),meta:e.includes("meta"),mod:e.includes("mod"),shift:e.includes("shift")},o=["alt","ctrl","meta","shift","mod"],a=e.find(s=>!o.includes(s));return __spreadProps(__spreadValues({},t),{key:a})}function isExactHotkey(r,e){const{alt:t,ctrl:o,meta:a,mod:s,shift:l,key:n}=r,{altKey:f,ctrlKey:i,metaKey:c,shiftKey:p,key:u}=e;if(t!==f)return!1;if(s){if(!i&&!c)return!1}else if(o!==i||a!==c)return!1;return l!==p?!1:!!(n&&(u.toLowerCase()===n.toLowerCase()||e.code.replace("Key","").toLowerCase()===n.toLowerCase()))}function getHotkeyMatcher(r){return e=>isExactHotkey(parseHotkey(r),e)}exports.getHotkeyMatcher=getHotkeyMatcher,exports.parseHotkey=parseHotkey;
2
+ //# sourceMappingURL=parseHotkey.js.map
@@ -0,0 +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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E,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;AACxE,EAAE,IAAI,GAAG,KAAK,MAAM,EAAE;AACtB,IAAI,OAAO,KAAK,CAAC;AACjB,GAAG;AACH,EAAE,IAAI,GAAG,EAAE;AACX,IAAI,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE;AAC9B,MAAM,OAAO,KAAK,CAAC;AACnB,KAAK;AACL,GAAG,MAAM;AACT,IAAI,IAAI,IAAI,KAAK,OAAO,EAAE;AAC1B,MAAM,OAAO,KAAK,CAAC;AACnB,KAAK;AACL,IAAI,IAAI,IAAI,KAAK,OAAO,EAAE;AAC1B,MAAM,OAAO,KAAK,CAAC;AACnB,KAAK;AACL,GAAG;AACH,EAAE,IAAI,KAAK,KAAK,QAAQ,EAAE;AAC1B,IAAI,OAAO,KAAK,CAAC;AACjB,GAAG;AACH,EAAE,IAAI,GAAG,KAAK,UAAU,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC,WAAW,EAAE,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC,WAAW,EAAE,CAAC,EAAE;AACpI,IAAI,OAAO,IAAI,CAAC;AAChB,GAAG;AACH,EAAE,OAAO,KAAK,CAAC;AACf,CAAC;AACM,SAAS,gBAAgB,CAAC,MAAM,EAAE;AACzC,EAAE,OAAO,CAAC,KAAK,KAAK,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;AAC9D;;;;;"}
@@ -1,14 +1,2 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var react = require('react');
6
- var index = require('../utils/index.js');
7
-
8
- function useId(id, generateId = index.randomId) {
9
- const generatedId = react.useRef(generateId());
10
- return id || generatedId.current;
11
- }
12
-
13
- exports.useId = useId;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react"),index=require("../utils/index.js");function useId(e,r=index.randomId){const t=react.useRef(r());return e||t.current}exports.useId=useId;
14
2
  //# sourceMappingURL=index.js.map
@@ -1,39 +1,2 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var react = require('react');
6
- var index = require('../useWindowEvent/index.js');
7
-
8
- function useLocalStorage({
9
- key,
10
- defaultValue = void 0
11
- }) {
12
- const [value, setValue] = react.useState(typeof window !== "undefined" && "localStorage" in window ? window.localStorage.getItem(key) : defaultValue != null ? defaultValue : "");
13
- const setLocalStorageValue = react.useCallback((val) => {
14
- if (typeof val === "function") {
15
- setValue((current) => {
16
- const result = val(current);
17
- window.localStorage.setItem(key, result);
18
- return result;
19
- });
20
- } else {
21
- window.localStorage.setItem(key, val);
22
- setValue(val);
23
- }
24
- }, [key]);
25
- index.useWindowEvent("storage", (event) => {
26
- if (event.storageArea === window.localStorage && event.key === key) {
27
- setValue(event.newValue);
28
- }
29
- });
30
- react.useEffect(() => {
31
- if (defaultValue && !value) {
32
- setLocalStorageValue(defaultValue);
33
- }
34
- }, [defaultValue, value, setLocalStorageValue]);
35
- return [value, setLocalStorageValue];
36
- }
37
-
38
- exports.useLocalStorage = useLocalStorage;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react"),index=require("../useWindowEvent/index.js");function useLocalStorage({key:o,defaultValue:t=void 0}){const[r,n]=react.useState(typeof window!="undefined"&&"localStorage"in window?window.localStorage.getItem(o):t!=null?t:""),s=react.useCallback(e=>{typeof e=="function"?n(a=>{const i=e(a);return window.localStorage.setItem(o,i),i}):(window.localStorage.setItem(o,e),n(e))},[o]);return index.useWindowEvent("storage",e=>{e.storageArea===window.localStorage&&e.key===o&&n(e.newValue)}),react.useEffect(()=>{t&&!r&&s(t)},[t,r,s]),[r,s]}exports.useLocalStorage=useLocalStorage;
39
2
  //# sourceMappingURL=index.js.map
@@ -1,36 +1,2 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var react = require('react');
6
-
7
- function attachMediaListener(query, callback) {
8
- try {
9
- query.addEventListener("change", callback);
10
- return () => query.removeEventListener("change", callback);
11
- } catch (e) {
12
- query.addListener(callback);
13
- return () => query.removeListener(callback);
14
- }
15
- }
16
- function getInitialValue(query) {
17
- if (typeof window !== "undefined" && "matchMedia" in window) {
18
- return window.matchMedia(query).matches;
19
- }
20
- return false;
21
- }
22
- function useMediaQuery(query) {
23
- const [matches, setMatches] = react.useState(getInitialValue(query));
24
- const queryRef = react.useRef();
25
- react.useEffect(() => {
26
- if ("matchMedia" in window) {
27
- queryRef.current = window.matchMedia(query);
28
- setMatches(queryRef.current.matches);
29
- return attachMediaListener(queryRef.current, (event) => setMatches(event.matches));
30
- }
31
- }, [query]);
32
- return matches;
33
- }
34
-
35
- exports.useMediaQuery = useMediaQuery;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react");function attachMediaListener(e,t){try{return e.addEventListener("change",t),()=>e.removeEventListener("change",t)}catch(n){return e.addListener(t),()=>e.removeListener(t)}}function getInitialValue(e){return typeof window!="undefined"&&"matchMedia"in window?window.matchMedia(e).matches:!1}function useMediaQuery(e){const[t,n]=react.useState(getInitialValue(e)),r=react.useRef();return react.useEffect(()=>{if("matchMedia"in window)return r.current=window.matchMedia(e),n(r.current.matches),attachMediaListener(r.current,i=>n(i.matches))},[e]),t}exports.useMediaQuery=useMediaQuery;
36
2
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react"),index=require("../utils/index.js");function useMove(E,n){const t=react.useRef(),u=react.useRef(!1),o=react.useRef(!1),d=react.useRef(0),[h,m]=react.useState(!1);return react.useEffect(()=>{u.current=!0},[]),react.useEffect(()=>{const a=({x:e,y:b})=>{cancelAnimationFrame(d.current),d.current=requestAnimationFrame(()=>{if(u.current&&t.current){t.current.style.userSelect="none";const r=t.current.getBoundingClientRect();r.width&&r.height&&E({x:index.clamp({value:(e-r.left)/r.width,min:0,max:1}),y:index.clamp({value:(b-r.top)/r.height,min:0,max:1})})}})},p=()=>{document.addEventListener("mousemove",s),document.addEventListener("mouseup",c),document.addEventListener("touchmove",i),document.addEventListener("touchend",c)},S=()=>{document.removeEventListener("mousemove",s),document.removeEventListener("mouseup",c),document.removeEventListener("touchmove",i),document.removeEventListener("touchend",c)},v=()=>{!o.current&&u.current&&(o.current=!0,typeof(n==null?void 0:n.onScrubStart)=="function"&&n.onScrubStart(),m(!0),p())},c=()=>{o.current&&u.current&&(o.current=!1,typeof(n==null?void 0:n.onScrubEnd)=="function"&&n.onScrubEnd(),m(!1),S())},f=e=>{v(),s(e)},s=e=>a({x:e.clientX,y:e.clientY}),l=e=>{v(),e==null||e.preventDefault(),i(e)},i=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",l),()=>{t.current&&(t.current.removeEventListener("mousedown",f),t.current.removeEventListener("touchstart",l))}},[t.current]),{ref:t,active:h}}exports.useMove=useMove;
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,EAAE,MAAM,SAAS,GAAGA,YAAM,CAAC,KAAK,CAAC,CAAC;AAClC,EAAE,MAAM,KAAK,GAAGA,YAAM,CAAC,CAAC,CAAC,CAAC;AAC1B,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAGC,cAAQ,CAAC,KAAK,CAAC,CAAC;AAC9C,EAAEC,eAAS,CAAC,MAAM;AAClB,IAAI,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;AAC3B,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAEA,eAAS,CAAC,MAAM;AAClB,IAAI,MAAM,OAAO,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK;AAClC,MAAM,oBAAoB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAC1C,MAAM,KAAK,CAAC,OAAO,GAAG,qBAAqB,CAAC,MAAM;AAClD,QAAQ,IAAI,OAAO,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,EAAE;AAC5C,UAAU,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,GAAG,MAAM,CAAC;AAChD,UAAU,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC;AAC3D,UAAU,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;AACzC,YAAY,QAAQ,CAAC;AACrB,cAAc,CAAC,EAAEC,WAAK,CA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,KAAK,CAAC,GAAG,KAAK,CAAC,cAAc,EAAE,CAAC;AACtD,MAAM,OAAO,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;AAC1F,KAAK,CAAC;AACN,IAAI,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAC3D,IAAI,GAAG,CAAC,OAAO,CAAC,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,37 +1,2 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var react = require('react');
6
-
7
- function useQueue({ initialValues = [], limit }) {
8
- const [{ state, queue }, setState] = react.useState({
9
- state: initialValues.slice(0, limit),
10
- queue: initialValues.slice(limit)
11
- });
12
- const add = (...items) => setState((current) => {
13
- const results = [...current.state, ...current.queue, ...items];
14
- return {
15
- state: results.slice(0, limit),
16
- queue: results.slice(limit)
17
- };
18
- });
19
- const update = (fn) => setState((current) => {
20
- const results = fn([...current.state, ...current.queue]);
21
- return {
22
- state: results.slice(0, limit),
23
- queue: results.slice(limit)
24
- };
25
- });
26
- const cleanQueue = () => setState((current) => ({ state: current.state, queue: [] }));
27
- return {
28
- state,
29
- queue,
30
- add,
31
- update,
32
- cleanQueue
33
- };
34
- }
35
-
36
- exports.useQueue = useQueue;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react");function useQueue({initialValues:c=[],limit:e}){const[{state:r,queue:n},a]=react.useState({state:c.slice(0,e),queue:c.slice(e)});return{state:r,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:[]}))}}exports.useQueue=useQueue;
37
2
  //# sourceMappingURL=index.js.map
@@ -1,12 +1,2 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var index = require('../useMediaQuery/index.js');
6
-
7
- function useReducedMotion() {
8
- return index.useMediaQuery("(prefers-reduced-motion: reduce)");
9
- }
10
-
11
- exports.useReducedMotion = useReducedMotion;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var index=require("../useMediaQuery/index.js");function useReducedMotion(){return index.useMediaQuery("(prefers-reduced-motion: reduce)")}exports.useReducedMotion=useReducedMotion;
12
2
  //# sourceMappingURL=index.js.map
@@ -1,29 +1,2 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var react = require('react');
6
-
7
- function useToggle(initialValue, options) {
8
- const [state, setState] = react.useState(initialValue);
9
- const toggle = (value) => {
10
- if (typeof value !== "undefined") {
11
- setState(value);
12
- } else {
13
- setState((current) => {
14
- if (current === options[0]) {
15
- return options[1];
16
- }
17
- return options[0];
18
- });
19
- }
20
- };
21
- return [state, toggle];
22
- }
23
- function useBooleanToggle(initialValue = false) {
24
- return useToggle(initialValue, [true, false]);
25
- }
26
-
27
- exports.useBooleanToggle = useBooleanToggle;
28
- exports.useToggle = useToggle;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react");function useToggle(e,t){const[o,r]=react.useState(e);return[o,u=>{typeof u!="undefined"?r(u):r(s=>s===t[0]?t[1]:t[0])}]}function useBooleanToggle(e=!1){return useToggle(e,[!0,!1])}exports.useBooleanToggle=useBooleanToggle,exports.useToggle=useToggle;
29
2
  //# sourceMappingURL=index.js.map
@@ -1,41 +1,2 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var react = require('react');
6
-
7
- function useUncontrolled({
8
- value,
9
- defaultValue,
10
- finalValue,
11
- rule,
12
- onChange,
13
- onValueUpdate
14
- }) {
15
- const shouldBeControlled = rule(value);
16
- const modeRef = react.useRef("initial");
17
- const initialValue = rule(defaultValue) ? defaultValue : finalValue;
18
- const [uncontrolledValue, setUncontrolledValue] = react.useState(initialValue);
19
- let effectiveValue = shouldBeControlled ? value : uncontrolledValue;
20
- if (!shouldBeControlled && modeRef.current === "controlled") {
21
- effectiveValue = finalValue;
22
- }
23
- modeRef.current = shouldBeControlled ? "controlled" : "uncontrolled";
24
- const mode = modeRef.current;
25
- const handleChange = (nextValue) => {
26
- typeof onChange === "function" && onChange(nextValue);
27
- if (mode === "uncontrolled") {
28
- setUncontrolledValue(nextValue);
29
- }
30
- };
31
- react.useEffect(() => {
32
- if (mode === "uncontrolled") {
33
- setUncontrolledValue(effectiveValue);
34
- }
35
- typeof onValueUpdate === "function" && onValueUpdate(effectiveValue);
36
- }, [mode, effectiveValue]);
37
- return [effectiveValue, handleChange, modeRef.current];
38
- }
39
-
40
- exports.useUncontrolled = useUncontrolled;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react");function useUncontrolled({value:r,defaultValue:c,finalValue:l,rule:u,onChange:s,onValueUpdate:i}){const o=u(r),t=react.useRef("initial"),a=u(c)?c:l,[p,d]=react.useState(a);let e=o?r:p;!o&&t.current==="controlled"&&(e=l),t.current=o?"controlled":"uncontrolled";const n=t.current,y=f=>{typeof s=="function"&&s(f),n==="uncontrolled"&&d(f)};return react.useEffect(()=>{n==="uncontrolled"&&d(e),typeof i=="function"&&i(e)},[n,e]),[e,y,t.current]}exports.useUncontrolled=useUncontrolled;
41
2
  //# sourceMappingURL=index.js.map
@@ -1,15 +1,2 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var react = require('react');
6
-
7
- function useWindowEvent(type, listener, options) {
8
- react.useEffect(() => {
9
- window.addEventListener(type, listener, options);
10
- return () => window.removeEventListener(type, listener, options);
11
- }, []);
12
- }
13
-
14
- exports.useWindowEvent = useWindowEvent;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react");function useWindowEvent(e,r,t){react.useEffect(()=>(window.addEventListener(e,r,t),()=>window.removeEventListener(e,r,t)),[])}exports.useWindowEvent=useWindowEvent;
15
2
  //# sourceMappingURL=index.js.map
@@ -1,10 +1,2 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function randomId() {
6
- return `kubed-${Math.random().toString(36).substr(2, 9)}`;
7
- }
8
-
9
- 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:r,max:e}){return Math.min(Math.max(t,r),e)}exports.clamp=clamp,exports.randomId=randomId;
10
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"],"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;;;;"}
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;;;;;"}
package/esm/index.js CHANGED
@@ -1,12 +1,2 @@
1
- export { randomId } from './utils/index.js';
2
- export { useId } from './useId/index.js';
3
- export { useBooleanToggle, useToggle } from './useToggle/index.js';
4
- export { useUncontrolled } from './useUncontrolled/index.js';
5
- export { useMediaQuery } from './useMediaQuery/index.js';
6
- export { useReducedMotion } from './useReducedMotion/index.js';
7
- export { useWindowEvent } from './useWindowEvent/index.js';
8
- export { useLocalStorage } from './useLocalStorage/index.js';
9
- export { useForceUpdate } from './useForceUpdate/index.js';
10
- export { useClipboard } from './useClipboard/index.js';
11
- export { useQueue } from './useQueue/index.js';
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";
12
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{useRef as i,useEffect as f}from"react";const u=["mousedown","touchstart"];function a(e,o,c){const t=i();return f(()=>{const s=r=>{Array.isArray(c)?c.every(n=>!!n&&!n.contains(r.target))&&e():t.current&&!t.current.contains(r.target)&&e()};return(o||u).forEach(r=>document.addEventListener(r,s)),()=>{(o||u).forEach(r=>document.removeEventListener(r,s))}},[t,e,c]),t}export{a as useClickOutside};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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;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error, setError] = useState(null);
5
- const [copied, setCopied] = useState(false);
6
- const [copyTimeout, setCopyTimeout] = useState(null);
7
- const handleCopyResult = (value) => {
8
- clearTimeout(copyTimeout);
9
- setCopyTimeout(setTimeout(() => setCopied(false), timeout));
10
- setCopied(value);
11
- };
12
- const copy = (valueToCopy) => {
13
- if ("clipboard" in navigator) {
14
- navigator.clipboard.writeText(valueToCopy).then(() => handleCopyResult(true)).catch((err) => setError(err));
15
- } else {
16
- setError(new Error("useClipboard: navigator.clipboard is not supported"));
17
- }
18
- };
19
- const reset = () => {
20
- setCopied(false);
21
- setError(null);
22
- clearTimeout(copyTimeout);
23
- };
24
- return { copy, reset, error, copied };
25
- }
26
-
27
- export { useClipboard };
1
+ import{useState as r}from"react";function u({timeout:i=2e3}={}){const[a,e]=r(null),[n,o]=r(!1),[s,c]=r(null),l=t=>{clearTimeout(s),c(setTimeout(()=>o(!1),i)),o(t)};return{copy:t=>{"clipboard"in navigator?navigator.clipboard.writeText(t).then(()=>l(!0)).catch(p=>e(p)):e(new Error("useClipboard: navigator.clipboard is not supported"))},reset:()=>{o(!1),e(null),clearTimeout(s)},error:a,copied:n}}export{u as useClipboard};
28
2
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ import{useState as i,useRef as r,useEffect as f}from"react";function d(e,l,u={leading:!1}){const[a,c]=i(e),o=r(!1),s=r(null),t=r(!1),n=()=>window.clearTimeout(s.current);return f(()=>{o.current&&(!t.current&&u.leading?(t.current=!0,c(e)):(n(),s.current=window.setTimeout(()=>{t.current=!1,c(e)},l)))},[e,u.leading]),f(()=>(o.current=!0,n),[]),[a,n]}export{d as useDebouncedValue};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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":";;AACO,SAAS,iBAAiB,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;AAC7E,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC7C,EAAE,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AACnC,EAAE,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AAClC,EAAE,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AACpC,EAAE,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAC/D,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,UAAU,CAAC,OAAO,EAAE;AAC5B,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE;AACnD,QAAQ,WAAW,CAAC,OAAO,GAAG,IAAI,CAAC;AACnC,QAAQ,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxB,OAAO,MAAM;AACb,QAAQ,MAAM,EAAE,CAAC;AACjB,QAAQ,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM;AACrD,UAAU,WAAW,CAAC,OAAO,GAAG,KAAK,CAAC;AACtC,UAAU,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC1B,SAAS,EAAE,IAAI,CAAC,CAAC;AACjB,OAAO;AACP,KAAK;AACL,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;AAC/B,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;AAC9B,IAAI,OAAO,MAAM,CAAC;AAClB,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC1B;;;;"}
@@ -0,0 +1,2 @@
1
+ import{useEffect as f}from"react";function o(t){f(()=>{typeof t=="function"&&t()},[])}export{o as useDidMount};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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":";;AACO,SAAS,WAAW,CAAC,QAAQ,EAAE;AACtC,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;AACxC,MAAM,QAAQ,EAAE,CAAC;AACjB,KAAK;AACL,GAAG,EAAE,EAAE,CAAC,CAAC;AACT;;;;"}
@@ -0,0 +1,2 @@
1
+ import{useRef as u,useEffect as f}from"react";function c(t,r){const e=u(!1);f(()=>{e.current?t():e.current=!0},r)}export{c as useDidUpdate};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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":";;AACO,SAAS,YAAY,CAAC,EAAE,EAAE,YAAY,EAAE;AAC/C,EAAE,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAChC,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,OAAO,CAAC,OAAO,EAAE;AACzB,MAAM,EAAE,EAAE,CAAC;AACX,KAAK,MAAM;AACX,MAAM,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;AAC7B,KAAK;AACL,GAAG,EAAE,YAAY,CAAC,CAAC;AACnB;;;;"}
@@ -1,10 +1,2 @@
1
- import { useReducer } from 'react';
2
-
3
- const reducer = (value) => (value + 1) % 1e6;
4
- function useForceUpdate() {
5
- const [, update] = useReducer(reducer, 0);
6
- return update;
7
- }
8
-
9
- export { useForceUpdate };
1
+ import{useReducer as r}from"react";const t=e=>(e+1)%1e6;function c(){const[,e]=r(t,0);return e}export{c as useForceUpdate};
10
2
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ import{useEffect as m}from"react";import{getHotkeyMatcher as c}from"./parseHotkey.js";function d(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{d as useHotkeys};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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":";;;AAGO,SAAS,UAAU,CAAC,OAAO,EAAE;AACpC,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,MAAM,eAAe,GAAG,CAAC,KAAK,KAAK;AACvC,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK;AAC7C,QAAQ,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,EAAE;AAC7C,UAAU,KAAK,CAAC,cAAc,EAAE,CAAC;AACjC,UAAU,OAAO,CAAC,KAAK,CAAC,CAAC;AACzB,SAAS;AACT,OAAO,CAAC,CAAC;AACT,KAAK,CAAC;AACN,IAAI,QAAQ,CAAC,eAAe,CAAC,gBAAgB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;AAC1E,IAAI,OAAO,MAAM,QAAQ,CAAC,eAAe,CAAC,mBAAmB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;AAC1F,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAChB;;;;"}
@@ -0,0 +1,2 @@
1
+ var _=Object.defineProperty,w=Object.defineProperties,O=Object.getOwnPropertyDescriptors,l=Object.getOwnPropertySymbols,P=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable,c=(r,e,t)=>e in r?_(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,h=(r,e)=>{for(var t in e||(e={}))P.call(e,t)&&c(r,t,e[t]);if(l)for(var t of l(e))v.call(e,t)&&c(r,t,e[t]);return r},K=(r,e)=>w(r,O(e));function p(r){const e=r.toLowerCase().split("+").map(s=>s.trim()),t={alt:e.includes("alt"),ctrl:e.includes("ctrl"),meta:e.includes("meta"),mod:e.includes("mod"),shift:e.includes("shift")},o=["alt","ctrl","meta","shift","mod"],a=e.find(s=>!o.includes(s));return K(h({},t),{key:a})}function g(r,e){const{alt:t,ctrl:o,meta:a,mod:s,shift:u,key:n}=r,{altKey:d,ctrlKey:i,metaKey:f,shiftKey:y,key:m}=e;if(t!==d)return!1;if(s){if(!i&&!f)return!1}else if(o!==i||a!==f)return!1;return u!==y?!1:!!(n&&(m.toLowerCase()===n.toLowerCase()||e.code.replace("Key","").toLowerCase()===n.toLowerCase()))}function k(r){return e=>g(p(r),e)}export{k as getHotkeyMatcher,p as parseHotkey};
2
+ //# sourceMappingURL=parseHotkey.js.map
@@ -0,0 +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,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAI,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;AAC/B,EAAE,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAChC,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC;AAClC,MA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AAC;AACf,CAAC;AACM,SAAS,gBAAgB,CAAC,MAAM,EAAE;AACzC,EAAE,OAAO,CAAC,KAAK,KAAK,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;AAC9D;;;;"}
@@ -1,10 +1,2 @@
1
- import { useRef } from 'react';
2
- import { randomId } from '../utils/index.js';
3
-
4
- function useId(id, generateId = randomId) {
5
- const generatedId = useRef(generateId());
6
- return id || generatedId.current;
7
- }
8
-
9
- export { useId };
1
+ import{useRef as n}from"react";import{randomId as o}from"../utils/index.js";function d(r,e=o){const t=n(e());return r||t.current}export{d as useId};
10
2
  //# sourceMappingURL=index.js.map
@@ -1,35 +1,2 @@
1
- import { useState, useCallback, useEffect } from 'react';
2
- import { useWindowEvent } from '../useWindowEvent/index.js';
3
-
4
- function useLocalStorage({
5
- key,
6
- defaultValue = void 0
7
- }) {
8
- const [value, setValue] = useState(typeof window !== "undefined" && "localStorage" in window ? window.localStorage.getItem(key) : defaultValue != null ? defaultValue : "");
9
- const setLocalStorageValue = useCallback((val) => {
10
- if (typeof val === "function") {
11
- setValue((current) => {
12
- const result = val(current);
13
- window.localStorage.setItem(key, result);
14
- return result;
15
- });
16
- } else {
17
- window.localStorage.setItem(key, val);
18
- setValue(val);
19
- }
20
- }, [key]);
21
- useWindowEvent("storage", (event) => {
22
- if (event.storageArea === window.localStorage && event.key === key) {
23
- setValue(event.newValue);
24
- }
25
- });
26
- useEffect(() => {
27
- if (defaultValue && !value) {
28
- setLocalStorageValue(defaultValue);
29
- }
30
- }, [defaultValue, value, setLocalStorageValue]);
31
- return [value, setLocalStorageValue];
32
- }
33
-
34
- export { useLocalStorage };
1
+ import{useState as w,useCallback as a,useEffect as l}from"react";import{useWindowEvent as g}from"../useWindowEvent/index.js";function u({key:e,defaultValue:t=void 0}){const[n,r]=w(typeof window!="undefined"&&"localStorage"in window?window.localStorage.getItem(e):t!=null?t:""),i=a(o=>{typeof o=="function"?r(c=>{const s=o(c);return window.localStorage.setItem(e,s),s}):(window.localStorage.setItem(e,o),r(o))},[e]);return g("storage",o=>{o.storageArea===window.localStorage&&o.key===e&&r(o.newValue)}),l(()=>{t&&!n&&i(t)},[t,n,i]),[n,i]}export{u as useLocalStorage};
35
2
  //# sourceMappingURL=index.js.map
@@ -1,32 +1,2 @@
1
- import { useState, useRef, useEffect } from 'react';
2
-
3
- function attachMediaListener(query, callback) {
4
- try {
5
- query.addEventListener("change", callback);
6
- return () => query.removeEventListener("change", callback);
7
- } catch (e) {
8
- query.addListener(callback);
9
- return () => query.removeListener(callback);
10
- }
11
- }
12
- function getInitialValue(query) {
13
- if (typeof window !== "undefined" && "matchMedia" in window) {
14
- return window.matchMedia(query).matches;
15
- }
16
- return false;
17
- }
18
- function useMediaQuery(query) {
19
- const [matches, setMatches] = useState(getInitialValue(query));
20
- const queryRef = useRef();
21
- useEffect(() => {
22
- if ("matchMedia" in window) {
23
- queryRef.current = window.matchMedia(query);
24
- setMatches(queryRef.current.matches);
25
- return attachMediaListener(queryRef.current, (event) => setMatches(event.matches));
26
- }
27
- }, [query]);
28
- return matches;
29
- }
30
-
31
- export { useMediaQuery };
1
+ import{useState as a,useRef as c,useEffect as s}from"react";function d(e,t){try{return e.addEventListener("change",t),()=>e.removeEventListener("change",t)}catch(n){return e.addListener(t),()=>e.removeListener(t)}}function o(e){return typeof window!="undefined"&&"matchMedia"in window?window.matchMedia(e).matches:!1}function u(e){const[t,n]=a(o(e)),i=c();return s(()=>{if("matchMedia"in window)return i.current=window.matchMedia(e),n(i.current.matches),d(i.current,r=>n(r.matches))},[e]),t}export{u as useMediaQuery};
32
2
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ import{useRef as s,useState as y,useEffect as h}from"react";import{clamp as S}from"../utils/index.js";function w(p,n){const t=s(),r=s(!1),u=s(!1),d=s(0),[L,v]=y(!1);return h(()=>{r.current=!0},[]),h(()=>{const a=({x:e,y:x})=>{cancelAnimationFrame(d.current),d.current=requestAnimationFrame(()=>{if(r.current&&t.current){t.current.style.userSelect="none";const o=t.current.getBoundingClientRect();o.width&&o.height&&p({x:S({value:(e-o.left)/o.width,min:0,max:1}),y:S({value:(x-o.top)/o.height,min:0,max:1})})}})},b=()=>{document.addEventListener("mousemove",i),document.addEventListener("mouseup",c),document.addEventListener("touchmove",m),document.addEventListener("touchend",c)},g=()=>{document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",c),document.removeEventListener("touchmove",m),document.removeEventListener("touchend",c)},f=()=>{!u.current&&r.current&&(u.current=!0,typeof(n==null?void 0:n.onScrubStart)=="function"&&n.onScrubStart(),v(!0),b())},c=()=>{u.current&&r.current&&(u.current=!1,typeof(n==null?void 0:n.onScrubEnd)=="function"&&n.onScrubEnd(),v(!1),g())},l=e=>{f(),i(e)},i=e=>a({x:e.clientX,y:e.clientY}),E=e=>{f(),e==null||e.preventDefault(),m(e)},m=e=>{e==null||e.preventDefault(),a({x:e.changedTouches[0].clientX,y:e.changedTouches[0].clientY})};return t.current.addEventListener("mousedown",l),t.current.addEventListener("touchstart",E),()=>{t.current&&(t.current.removeEventListener("mousedown",l),t.current.removeEventListener("touchstart",E))}},[t.current]),{ref:t,active:L}}export{w as useMove};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC9C,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;AAC3B,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,MAAM,OAAO,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK;AAClC,MAAM,oBAAoB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAC1C,MAAM,KAAK,CAAC,OAAO,GAAG,qBAAqB,CAAC,MAAM;AAClD,QAAQ,IAAI,OAAO,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,EAAE;AAC5C,UAAU,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,GAAG,MAAM,CAAC;AAChD,UAAU,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC;AAC3D,UAAU,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;AACzC,YAAY,QAAQ,CAAC;AACrB,cAAc,CAAC,EAAE,KAAK,CA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KAAK,CAAC,GAAG,KAAK,CAAC,cAAc,EAAE,CAAC;AACtD,MAAM,OAAO,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;AAC1F,KAAK,CAAC;AACN,IAAI,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAC3D,IAAI,GAAG,CAAC,OAAO,CAAC,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,33 +1,2 @@
1
- import { useState } from 'react';
2
-
3
- function useQueue({ initialValues = [], limit }) {
4
- const [{ state, queue }, setState] = useState({
5
- state: initialValues.slice(0, limit),
6
- queue: initialValues.slice(limit)
7
- });
8
- const add = (...items) => setState((current) => {
9
- const results = [...current.state, ...current.queue, ...items];
10
- return {
11
- state: results.slice(0, limit),
12
- queue: results.slice(limit)
13
- };
14
- });
15
- const update = (fn) => setState((current) => {
16
- const results = fn([...current.state, ...current.queue]);
17
- return {
18
- state: results.slice(0, limit),
19
- queue: results.slice(limit)
20
- };
21
- });
22
- const cleanQueue = () => setState((current) => ({ state: current.state, queue: [] }));
23
- return {
24
- state,
25
- queue,
26
- add,
27
- update,
28
- cleanQueue
29
- };
30
- }
31
-
32
- export { useQueue };
1
+ import{useState as r}from"react";function q({initialValues:c=[],limit:e}){const[{state:n,queue:o},a]=r({state:c.slice(0,e),queue:c.slice(e)});return{state:n,queue:o,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{q as useQueue};
33
2
  //# sourceMappingURL=index.js.map
@@ -1,8 +1,2 @@
1
- import { useMediaQuery } from '../useMediaQuery/index.js';
2
-
3
- function useReducedMotion() {
4
- return useMediaQuery("(prefers-reduced-motion: reduce)");
5
- }
6
-
7
- export { useReducedMotion };
1
+ import{useMediaQuery as e}from"../useMediaQuery/index.js";function r(){return e("(prefers-reduced-motion: reduce)")}export{r as useReducedMotion};
8
2
  //# sourceMappingURL=index.js.map
@@ -1,24 +1,2 @@
1
- import { useState } from 'react';
2
-
3
- function useToggle(initialValue, options) {
4
- const [state, setState] = useState(initialValue);
5
- const toggle = (value) => {
6
- if (typeof value !== "undefined") {
7
- setState(value);
8
- } else {
9
- setState((current) => {
10
- if (current === options[0]) {
11
- return options[1];
12
- }
13
- return options[0];
14
- });
15
- }
16
- };
17
- return [state, toggle];
18
- }
19
- function useBooleanToggle(initialValue = false) {
20
- return useToggle(initialValue, [true, false]);
21
- }
22
-
23
- export { useBooleanToggle, useToggle };
1
+ import{useState as g}from"react";function o(e,t){const[u,r]=g(e);return[u,n=>{typeof n!="undefined"?r(n):r(f=>f===t[0]?t[1]:t[0])}]}function s(e=!1){return o(e,[!0,!1])}export{s as useBooleanToggle,o as useToggle};
24
2
  //# sourceMappingURL=index.js.map
@@ -1,37 +1,2 @@
1
- import { useRef, useState, useEffect } from 'react';
2
-
3
- function useUncontrolled({
4
- value,
5
- defaultValue,
6
- finalValue,
7
- rule,
8
- onChange,
9
- onValueUpdate
10
- }) {
11
- const shouldBeControlled = rule(value);
12
- const modeRef = useRef("initial");
13
- const initialValue = rule(defaultValue) ? defaultValue : finalValue;
14
- const [uncontrolledValue, setUncontrolledValue] = useState(initialValue);
15
- let effectiveValue = shouldBeControlled ? value : uncontrolledValue;
16
- if (!shouldBeControlled && modeRef.current === "controlled") {
17
- effectiveValue = finalValue;
18
- }
19
- modeRef.current = shouldBeControlled ? "controlled" : "uncontrolled";
20
- const mode = modeRef.current;
21
- const handleChange = (nextValue) => {
22
- typeof onChange === "function" && onChange(nextValue);
23
- if (mode === "uncontrolled") {
24
- setUncontrolledValue(nextValue);
25
- }
26
- };
27
- useEffect(() => {
28
- if (mode === "uncontrolled") {
29
- setUncontrolledValue(effectiveValue);
30
- }
31
- typeof onValueUpdate === "function" && onValueUpdate(effectiveValue);
32
- }, [mode, effectiveValue]);
33
- return [effectiveValue, handleChange, modeRef.current];
34
- }
35
-
36
- export { useUncontrolled };
1
+ import{useRef as y,useState as R,useEffect as a}from"react";function B({value:c,defaultValue:r,finalValue:l,rule:u,onChange:f,onValueUpdate:i}){const n=u(c),t=y("initial"),m=u(r)?r:l,[p,s]=R(m);let o=n?c:p;!n&&t.current==="controlled"&&(o=l),t.current=n?"controlled":"uncontrolled";const e=t.current,h=d=>{typeof f=="function"&&f(d),e==="uncontrolled"&&s(d)};return a(()=>{e==="uncontrolled"&&s(o),typeof i=="function"&&i(o)},[e,o]),[o,h,t.current]}export{B as useUncontrolled};
37
2
  //# sourceMappingURL=index.js.map
@@ -1,11 +1,2 @@
1
- import { useEffect } from 'react';
2
-
3
- function useWindowEvent(type, listener, options) {
4
- useEffect(() => {
5
- window.addEventListener(type, listener, options);
6
- return () => window.removeEventListener(type, listener, options);
7
- }, []);
8
- }
9
-
10
- export { useWindowEvent };
1
+ import{useEffect as t}from"react";function o(e,n,r){t(()=>(window.addEventListener(e,n,r),()=>window.removeEventListener(e,n,r)),[])}export{o as useWindowEvent};
11
2
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,2 @@
1
- function randomId() {
2
- return `kubed-${Math.random().toString(36).substr(2, 9)}`;
3
- }
4
-
5
- export { randomId };
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};
6
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"],"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;;;;"}
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;;;;"}
package/lib/index.d.ts CHANGED
@@ -9,4 +9,10 @@ export { useLocalStorage } from './useLocalStorage';
9
9
  export { useForceUpdate } from './useForceUpdate';
10
10
  export { useClipboard } from './useClipboard';
11
11
  export { useQueue } from './useQueue';
12
+ export { useClickOutside } from './useClickOutside';
13
+ export { useMove } from './useMove';
14
+ export { useHotkeys } from './useHotkeys';
15
+ export { useDebouncedValue } from './useDebouncedValue';
16
+ export { useDidMount } from './useDidMount';
17
+ export { useDidUpdate } from './useDidUpdate';
12
18
  //# 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"}
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,CAAC"}
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ export declare function useClickOutside<T extends HTMLElement = any>(handler: () => void, events?: string[] | null, nodes?: HTMLElement[]): import("react").MutableRefObject<T>;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useClickOutside/index.ts"],"names":[],"mappings":";AAIA,wBAAgB,eAAe,CAAC,CAAC,SAAS,WAAW,GAAG,GAAG,EACzD,OAAO,EAAE,MAAM,IAAI,EACnB,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EACxB,KAAK,CAAC,EAAE,WAAW,EAAE,uCAsBtB"}
@@ -0,0 +1,4 @@
1
+ export declare function useDebouncedValue<T = any>(value: T, wait: number, options?: {
2
+ leading: boolean;
3
+ }): readonly [T, () => void];
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useDebouncedValue/index.ts"],"names":[],"mappings":"AAGA,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO;;CAAqB,4BA6B9F"}
@@ -0,0 +1,2 @@
1
+ export declare function useDidUpdate(fn: () => void, dependencies?: any[]): void;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useDidUpdate/index.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,YAAY,CAAC,EAAE,GAAG,EAAE,QAUhE"}
@@ -0,0 +1,5 @@
1
+ import { getHotkeyHandler } from './parseHotkey';
2
+ export { getHotkeyHandler };
3
+ declare type HokeyItem = [string, (event: KeyboardEvent) => void];
4
+ export declare function useHotkeys(hotkeys: HokeyItem[]): void;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useHotkeys/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEnE,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,aAAK,SAAS,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC,CAAC;AAE1D,wBAAgB,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,QAc9C"}
@@ -0,0 +1,18 @@
1
+ /// <reference types="react" />
2
+ export declare type KeyboardModifiers = {
3
+ alt: boolean;
4
+ ctrl: boolean;
5
+ meta: boolean;
6
+ mod: boolean;
7
+ shift: boolean;
8
+ };
9
+ export declare type Hotkey = KeyboardModifiers & {
10
+ key?: string;
11
+ };
12
+ declare type CheckHotkeyMatch = (event: KeyboardEvent) => boolean;
13
+ export declare function parseHotkey(hotkey: string): Hotkey;
14
+ export declare function getHotkeyMatcher(hotkey: string): CheckHotkeyMatch;
15
+ declare type HotkeyItem = [string, (event: React.KeyboardEvent<HTMLElement>) => void];
16
+ export declare function getHotkeyHandler(hotkeys: HotkeyItem[]): (event: React.KeyboardEvent<HTMLElement>) => void;
17
+ export {};
18
+ //# sourceMappingURL=parseHotkey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseHotkey.d.ts","sourceRoot":"","sources":["../../src/useHotkeys/parseHotkey.ts"],"names":[],"mappings":";AAAA,oBAAY,iBAAiB,GAAG;IAC9B,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;IACd,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,oBAAY,MAAM,GAAG,iBAAiB,GAAG;IACvC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,aAAK,gBAAgB,GAAG,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC;AAE1D,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAsBlD;AAqCD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAEjE;AAED,aAAK,UAAU,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC,CAAC;AAE9E,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,UAAU,EAAE,WACrC,mBAAmB,CAAC,WAAW,CAAC,UAQhD"}
@@ -0,0 +1,19 @@
1
+ /// <reference types="react" />
2
+ export interface UseMovePosition {
3
+ x: number;
4
+ y: number;
5
+ }
6
+ export declare const clampUseMovePosition: (position: UseMovePosition) => {
7
+ x: number;
8
+ y: number;
9
+ };
10
+ interface useMoveHandlers {
11
+ onScrubStart?(): void;
12
+ onScrubEnd?(): void;
13
+ }
14
+ export declare function useMove<T extends HTMLElement = HTMLDivElement>(onChange: (value: UseMovePosition) => void, handlers?: useMoveHandlers): {
15
+ ref: import("react").MutableRefObject<T>;
16
+ active: boolean;
17
+ };
18
+ export {};
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,2 +1,9 @@
1
1
  export declare function randomId(): string;
2
+ interface Clamp {
3
+ value: number;
4
+ min: number;
5
+ max: number;
6
+ }
7
+ export declare function clamp({ value, min, max }: Clamp): number;
8
+ export {};
2
9
  //# 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"}
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"}
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "@kubed/hooks",
3
- "version": "0.0.2",
3
+ "version": "0.0.6",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
- "browser": "lib/index.umd.js",
7
6
  "types": "lib/index.d.ts",
8
7
  "license": "MIT",
9
8
  "sideEffects": false,
package/lib/index.umd.js DELETED
@@ -1,2 +0,0 @@
1
- (function(u,o){typeof exports=="object"&&typeof module!="undefined"?o(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],o):(u=typeof globalThis!="undefined"?globalThis:u||self,o(u["@kubed/hooks"]={},u.React))})(this,function(u,o){"use strict";function h(){return`kubed-${Math.random().toString(36).substr(2,9)}`}function M(e,t=h){const n=o.useRef(t());return e||n.current}function m(e,t){const[n,r]=o.useState(e);return[n,s=>{typeof s!="undefined"?r(s):r(d=>d===t[0]?t[1]:t[0])}]}function T(e=!1){return m(e,[!0,!1])}function L({value:e,defaultValue:t,finalValue:n,rule:r,onChange:c,onValueUpdate:s}){const d=r(e),a=o.useRef("initial"),f=r(t)?t:n,[l,i]=o.useState(f);let w=d?e:l;!d&&a.current==="controlled"&&(w=n),a.current=d?"controlled":"uncontrolled";const g=a.current,U=E=>{typeof c=="function"&&c(E),g==="uncontrolled"&&i(E)};return o.useEffect(()=>{g==="uncontrolled"&&i(w),typeof s=="function"&&s(w)},[g,w]),[w,U,a.current]}function R(e,t){try{return e.addEventListener("change",t),()=>e.removeEventListener("change",t)}catch(n){return e.addListener(t),()=>e.removeListener(t)}}function v(e){return typeof window!="undefined"&&"matchMedia"in window?window.matchMedia(e).matches:!1}function S(e){const[t,n]=o.useState(v(e)),r=o.useRef();return o.useEffect(()=>{if("matchMedia"in window)return r.current=window.matchMedia(e),n(r.current.matches),R(r.current,c=>n(c.matches))},[e]),t}function y(){return S("(prefers-reduced-motion: reduce)")}function p(e,t,n){o.useEffect(()=>(window.addEventListener(e,t,n),()=>window.removeEventListener(e,t,n)),[])}function I({key:e,defaultValue:t=void 0}){const[n,r]=o.useState(typeof window!="undefined"&&"localStorage"in window?window.localStorage.getItem(e):t!=null?t:""),c=o.useCallback(s=>{typeof s=="function"?r(d=>{const a=s(d);return window.localStorage.setItem(e,a),a}):(window.localStorage.setItem(e,s),r(s))},[e]);return p("storage",s=>{s.storageArea===window.localStorage&&s.key===e&&r(s.newValue)}),o.useEffect(()=>{t&&!n&&c(t)},[t,n,c]),[n,c]}const b=e=>(e+1)%1e6;function C(){const[,e]=o.useReducer(b,0);return e}function Q({timeout:e=2e3}={}){const[t,n]=o.useState(null),[r,c]=o.useState(!1),[s,d]=o.useState(null),a=i=>{clearTimeout(s),d(setTimeout(()=>c(!1),e)),c(i)};return{copy:i=>{"clipboard"in navigator?navigator.clipboard.writeText(i).then(()=>a(!0)).catch(w=>n(w)):n(new Error("useClipboard: navigator.clipboard is not supported"))},reset:()=>{c(!1),n(null),clearTimeout(s)},error:t,copied:r}}function q({initialValues:e=[],limit:t}){const[{state:n,queue:r},c]=o.useState({state:e.slice(0,t),queue:e.slice(t)});return{state:n,queue:r,add:(...f)=>c(l=>{const i=[...l.state,...l.queue,...f];return{state:i.slice(0,t),queue:i.slice(t)}}),update:f=>c(l=>{const i=f([...l.state,...l.queue]);return{state:i.slice(0,t),queue:i.slice(t)}}),cleanQueue:()=>c(f=>({state:f.state,queue:[]}))}}u.randomId=h,u.useBooleanToggle=T,u.useClipboard=Q,u.useForceUpdate=C,u.useId=M,u.useLocalStorage=I,u.useMediaQuery=S,u.useQueue=q,u.useReducedMotion=y,u.useToggle=m,u.useUncontrolled=L,u.useWindowEvent=p,Object.defineProperty(u,"__esModule",{value:!0})});
2
- //# sourceMappingURL=index.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/utils/index.ts","../src/useId/index.ts","../src/useToggle/index.ts","../src/useUncontrolled/index.ts","../src/useMediaQuery/index.ts","../src/useReducedMotion/index.ts","../src/useWindowEvent/index.ts","../src/useLocalStorage/index.ts","../src/useForceUpdate/index.ts","../src/useClipboard/index.ts","../src/useQueue/index.ts"],"sourcesContent":["export function randomId() {\n return `kubed-${Math.random().toString(36).substr(2, 9)}`;\n}\n","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","// 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","// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-uncontrolled/use-uncontrolled.ts\nimport { useEffect, useRef, useState } from 'react';\n\nexport type UncontrolledMode = 'initial' | 'controlled' | 'uncontrolled';\n\nexport interface UncontrolledOptions<T> {\n value: T | null | undefined;\n defaultValue: T | null | undefined;\n finalValue: T | null;\n onChange(value: T | null): void;\n onValueUpdate?(value: T | null): void;\n rule: (value: T | null | undefined) => boolean;\n}\n\nexport function useUncontrolled<T>({\n value,\n defaultValue,\n finalValue,\n rule,\n onChange,\n onValueUpdate,\n}: UncontrolledOptions<T>): readonly [T | null, (nextValue: T | null) => void, UncontrolledMode] {\n // determine, whether new props indicate controlled state\n const shouldBeControlled = rule(value);\n\n // initialize state\n const modeRef = useRef<UncontrolledMode>('initial');\n const initialValue = rule(defaultValue) ? defaultValue : finalValue;\n const [uncontrolledValue, setUncontrolledValue] = useState(initialValue);\n\n // compute effective value\n let effectiveValue = shouldBeControlled ? value : uncontrolledValue;\n\n if (!shouldBeControlled && modeRef.current === 'controlled') {\n // We are transitioning from controlled to uncontrolled\n // this transition is special as it happens when clearing out\n // the input using \"invalid\" value (typically null or undefined).\n //\n // Since the value is invalid, doing nothing would mean just\n // transitioning to uncontrolled state and using whatever value\n // it currently holds which is likely not the bavior\n // user expects, so lets change the state to finalValue.\n //\n // The value will be propagated to internal state by useEffect below.\n\n effectiveValue = finalValue;\n }\n modeRef.current = shouldBeControlled ? 'controlled' : 'uncontrolled';\n const mode = modeRef.current;\n\n const handleChange = (nextValue: T | null) => {\n typeof onChange === 'function' && onChange(nextValue);\n\n // Controlled input only triggers onChange event and expects\n // the controller to propagate new value back.\n if (mode === 'uncontrolled') {\n setUncontrolledValue(nextValue);\n }\n };\n\n useEffect(() => {\n if (mode === 'uncontrolled') {\n setUncontrolledValue(effectiveValue);\n }\n typeof onValueUpdate === 'function' && onValueUpdate(effectiveValue);\n }, [mode, effectiveValue]);\n\n return [effectiveValue, handleChange, modeRef.current] as const;\n}\n","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","import { useMediaQuery } from '../useMediaQuery';\n\nexport function useReducedMotion() {\n return useMediaQuery('(prefers-reduced-motion: reduce)');\n}\n","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","// 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","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","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","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":["useRef","useState","useEffect","useCallback","useReducer"],"mappings":";;;;;;EAAO,SAAS,QAAQ,GAAG;EAC3B,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;EAC5D;;ECAO,SAAS,KAAK,CAAC,EAAE,EAAE,UAAU,GAAG,QAAQ,EAAE;EACjD,EAAE,MAAM,WAAW,GAAGA,YAAM,CAAC,UAAU,EAAE,CAAC,CAAC;EAC3C,EAAE,OAAO,EAAE,IAAI,WAAW,CAAC,OAAO,CAAC;EACnC;;ECJO,SAAS,SAAS,CAAC,YAAY,EAAE,OAAO,EAAE;EACjD,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGC,cAAQ,CAAC,YAAY,CAAC,CAAC;EACnD,EAAE,M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