@siberiacancode/reactuse 0.2.32 → 0.2.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -71
- package/dist/cjs/helpers/createStore/createStore.cjs +1 -1
- package/dist/cjs/helpers/createStore/createStore.cjs.map +1 -1
- package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs +1 -1
- package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs.map +1 -1
- package/dist/cjs/hooks/useAsyncEffect/useAsyncEffect.cjs +2 -0
- package/dist/cjs/hooks/useAsyncEffect/useAsyncEffect.cjs.map +1 -0
- package/dist/cjs/hooks/useFocusTrap/useFocusTrap.cjs +2 -0
- package/dist/cjs/hooks/useFocusTrap/useFocusTrap.cjs.map +1 -0
- package/dist/cjs/index.cjs +1 -1
- package/dist/esm/helpers/createStore/createStore.mjs +4 -4
- package/dist/esm/helpers/createStore/createStore.mjs.map +1 -1
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs +5 -7
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
- package/dist/esm/hooks/useAsyncEffect/useAsyncEffect.mjs +10 -0
- package/dist/esm/hooks/useAsyncEffect/useAsyncEffect.mjs.map +1 -0
- package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs +56 -0
- package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs.map +1 -0
- package/dist/esm/index.mjs +262 -258
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/hooks/elements.d.ts +1 -0
- package/dist/types/hooks/lifecycle.d.ts +1 -0
- package/dist/types/hooks/useActiveElement/useActiveElement.d.ts +5 -3
- package/dist/types/hooks/useAsyncEffect/useAsyncEffect.d.ts +14 -0
- package/dist/types/hooks/useFocusTrap/useFocusTrap.d.ts +42 -0
- package/package.json +89 -89
package/README.md
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
<a href="https://siberiacancode.github.io/reactuse/">
|
|
3
|
-
<picture>
|
|
4
|
-
<img alt="React Use logo" src="https://siberiacancode.github.io/reactuse/logo.svg" height="128">
|
|
5
|
-
</picture>
|
|
6
|
-
</a>
|
|
7
|
-
<h1>React Use</h1>
|
|
8
|
-
|
|
9
|
-
<a href="https://www.npmjs.com/package/@siberiacancode/reactuse"><img alt="NPM version" src="https://img.shields.io/npm/v/@siberiacancode/reactuse.svg?style=for-the-badge&labelColor=000000"></a>
|
|
10
|
-
<a href="https://github.com/siberiacancode/reactuse/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/npm/l/@siberiacancode/reactuse.svg?style=for-the-badge&labelColor=000000"></a>
|
|
11
|
-
<a href="https://github.com/siberiacancode/reactuse/discussions"><img alt="Join the community on GitHub" src="https://img.shields.io/badge/Join%20the%20community-blueviolet.svg?style=for-the-badge&logo=React&labelColor=000000&logoWidth=20"></a>
|
|
12
|
-
|
|
13
|
-
</div>
|
|
14
|
-
|
|
15
|
-
React Use delivers **production-ready hooks** that solve real-world problems. Built with **TypeScript-first** approach, **SSR compatibility**, and **tree-shaking optimization** - everything you need to build modern React applications. Improve your react applications with our library 📦 designed for comfort and speed.
|
|
16
|
-
|
|
17
|
-
## Documentation
|
|
18
|
-
|
|
19
|
-
Visit https://siberiacancode.github.io/reactuse to view the full documentation.
|
|
20
|
-
|
|
21
|
-
## Getting Started
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
npm install @siberiacancode/reactuse
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
```tsx
|
|
28
|
-
import { useCounter } from
|
|
29
|
-
|
|
30
|
-
const App = () => {
|
|
31
|
-
const counter = useCounter(0);
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<div>
|
|
35
|
-
<h1>Count: {counter.value}</h1>
|
|
36
|
-
<button onClick={() => counter.inc()}>+1</button>
|
|
37
|
-
<button onClick={() => counter.dec()}>-1</button>
|
|
38
|
-
</div>
|
|
39
|
-
);
|
|
40
|
-
};
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## CLI installation
|
|
44
|
-
|
|
45
|
-
Use the CLI to add hooks to your project with [useverse](https://www.npmjs.com/package/useverse).
|
|
46
|
-
|
|
47
|
-
```bash
|
|
48
|
-
npx useverse@latest init
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
npx useverse@latest add [hook]
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
You will be presented with a list of hooks to choose from:
|
|
56
|
-
|
|
57
|
-
```bash
|
|
58
|
-
Which hooks would you like to add? › Space to select. A to toggle all.
|
|
59
|
-
Enter to submit.
|
|
60
|
-
|
|
61
|
-
◯ useActiveElement
|
|
62
|
-
◯ useAsync
|
|
63
|
-
◯ useBattery
|
|
64
|
-
◯ useBluetooth
|
|
65
|
-
◯ useBoolean
|
|
66
|
-
◯ useBreakpoints
|
|
67
|
-
◯ useBrowserLanguage
|
|
68
|
-
◯ useClickOutside
|
|
69
|
-
◯ useClipboard
|
|
70
|
-
◯ useConst
|
|
71
|
-
```
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://siberiacancode.github.io/reactuse/">
|
|
3
|
+
<picture>
|
|
4
|
+
<img alt="React Use logo" src="https://siberiacancode.github.io/reactuse/logo.svg" height="128">
|
|
5
|
+
</picture>
|
|
6
|
+
</a>
|
|
7
|
+
<h1>React Use</h1>
|
|
8
|
+
|
|
9
|
+
<a href="https://www.npmjs.com/package/@siberiacancode/reactuse"><img alt="NPM version" src="https://img.shields.io/npm/v/@siberiacancode/reactuse.svg?style=for-the-badge&labelColor=000000"></a>
|
|
10
|
+
<a href="https://github.com/siberiacancode/reactuse/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/npm/l/@siberiacancode/reactuse.svg?style=for-the-badge&labelColor=000000"></a>
|
|
11
|
+
<a href="https://github.com/siberiacancode/reactuse/discussions"><img alt="Join the community on GitHub" src="https://img.shields.io/badge/Join%20the%20community-blueviolet.svg?style=for-the-badge&logo=React&labelColor=000000&logoWidth=20"></a>
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
React Use delivers **production-ready hooks** that solve real-world problems. Built with **TypeScript-first** approach, **SSR compatibility**, and **tree-shaking optimization** - everything you need to build modern React applications. Improve your react applications with our library 📦 designed for comfort and speed.
|
|
16
|
+
|
|
17
|
+
## Documentation
|
|
18
|
+
|
|
19
|
+
Visit https://siberiacancode.github.io/reactuse to view the full documentation.
|
|
20
|
+
|
|
21
|
+
## Getting Started
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @siberiacancode/reactuse
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { useCounter } from '@siberiacancode/reactuse';
|
|
29
|
+
|
|
30
|
+
const App = () => {
|
|
31
|
+
const counter = useCounter(0);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div>
|
|
35
|
+
<h1>Count: {counter.value}</h1>
|
|
36
|
+
<button onClick={() => counter.inc()}>+1</button>
|
|
37
|
+
<button onClick={() => counter.dec()}>-1</button>
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## CLI installation
|
|
44
|
+
|
|
45
|
+
Use the CLI to add hooks to your project with [useverse](https://www.npmjs.com/package/useverse).
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npx useverse@latest init
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npx useverse@latest add [hook]
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
You will be presented with a list of hooks to choose from:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
Which hooks would you like to add? › Space to select. A to toggle all.
|
|
59
|
+
Enter to submit.
|
|
60
|
+
|
|
61
|
+
◯ useActiveElement
|
|
62
|
+
◯ useAsync
|
|
63
|
+
◯ useBattery
|
|
64
|
+
◯ useBluetooth
|
|
65
|
+
◯ useBoolean
|
|
66
|
+
◯ useBreakpoints
|
|
67
|
+
◯ useBrowserLanguage
|
|
68
|
+
◯ useClickOutside
|
|
69
|
+
◯ useClipboard
|
|
70
|
+
◯ useConst
|
|
71
|
+
```
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react"),b=s=>{let e;const o=new Set,c=t=>{const n=typeof t=="function"?t(e):t;if(!Object.is(n,e)){const S=e;e=typeof n!="object"||n===null||Array.isArray(n)?n:Object.assign({},e,n),o.forEach(f=>f(e,S))}},u=t=>(o.add(t),()=>o.delete(t)),r=()=>e,i=()=>e;typeof s=="function"?e=s(c,r):e=s;function a(t){return y.useSyncExternalStore(u,()=>t?t(r()):r(),()=>t?t(i()):i())}return{set:c,get:r,use:a,subscribe:u}};exports.createStore=b;
|
|
2
2
|
//# sourceMappingURL=createStore.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createStore.cjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype StoreSetAction<Value> = ((prev: Value) => Partial<Value>) | Partial<Value>;\n\ntype StoreListener<Value> = (state: Value, prevState: Value) => void;\n\ntype StoreCreator<Value> = (\n set: (action: StoreSetAction<Value>) => void,\n get: () => Value\n) => Value;\n\nexport interface StoreApi<Value> {\n getInitialState: () => Value;\n getState: () => Value;\n setState: (action: StoreSetAction<Value>) => void;\n subscribe: (listener: StoreListener<Value>) => () => void;\n}\n\n/**\n * @name createStore\n * @description - Creates a store with state management capabilities\n * @category Helpers\n * @usage medium\n *\n * @template Value - The type of the store state\n * @param {StateCreator<Value>} createState - Function that initializes the store state\n * @returns {StoreApi<Value>} - Object containing store methods and hook for accessing state\n *\n * @example\n * const { set, get, use, subscribe } = createStore((set) => ({\n * count: 0,\n * increment: () => set(state => ({ count: state.count + 1 }))\n * }));\n */\nexport const createStore = <Value>(createState: StoreCreator<Value> | Value) => {\n let state: Value;\n const listeners: Set<StoreListener<Value>> = new Set();\n\n const setState: StoreApi<Value>['setState'] = (action: StoreSetAction<Value>) => {\n const nextState = typeof action === 'function' ? action(state) : action;\n\n if (!Object.is(nextState, state)) {\n const prevState = state;\n state
|
|
1
|
+
{"version":3,"file":"createStore.cjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype StoreSetAction<Value> = ((prev: Value) => Partial<Value>) | Partial<Value>;\n\ntype StoreListener<Value> = (state: Value, prevState: Value) => void;\n\ntype StoreCreator<Value> = (\n set: (action: StoreSetAction<Value>) => void,\n get: () => Value\n) => Value;\n\nexport interface StoreApi<Value> {\n getInitialState: () => Value;\n getState: () => Value;\n setState: (action: StoreSetAction<Value>) => void;\n subscribe: (listener: StoreListener<Value>) => () => void;\n}\n\n/**\n * @name createStore\n * @description - Creates a store with state management capabilities\n * @category Helpers\n * @usage medium\n *\n * @template Value - The type of the store state\n * @param {StateCreator<Value>} createState - Function that initializes the store state\n * @returns {StoreApi<Value>} - Object containing store methods and hook for accessing state\n *\n * @example\n * const { set, get, use, subscribe } = createStore((set) => ({\n * count: 0,\n * increment: () => set(state => ({ count: state.count + 1 }))\n * }));\n */\nexport const createStore = <Value>(createState: StoreCreator<Value> | Value) => {\n let state: Value;\n const listeners: Set<StoreListener<Value>> = new Set();\n\n const setState: StoreApi<Value>['setState'] = (action: StoreSetAction<Value>) => {\n const nextState = typeof action === 'function' ? action(state) : action;\n\n if (!Object.is(nextState, state)) {\n const prevState = state;\n state = (\n typeof nextState !== 'object' || nextState === null || Array.isArray(nextState)\n ? nextState\n : Object.assign({}, state, nextState)\n ) as Value;\n\n listeners.forEach((listener) => listener(state, prevState));\n }\n };\n\n const subscribe = (listener: StoreListener<Value>) => {\n listeners.add(listener);\n\n return () => listeners.delete(listener);\n };\n\n const getState = () => state;\n const getInitialState = () => state;\n\n if (typeof createState === 'function') {\n state = (createState as StoreCreator<Value>)(setState, getState);\n } else {\n state = createState;\n }\n\n function useStore(): Value;\n function useStore<Selected>(selector: (state: Value) => Selected): Selected;\n function useStore<Selected>(selector?: (state: Value) => Selected): Selected | Value {\n return useSyncExternalStore(\n subscribe,\n () => (selector ? selector(getState()) : getState()),\n () => (selector ? selector(getInitialState()) : getInitialState())\n );\n }\n\n return {\n set: setState,\n get: getState,\n use: useStore,\n subscribe\n };\n};\n"],"names":["createStore","createState","state","listeners","setState","action","nextState","prevState","listener","subscribe","getState","getInitialState","useStore","selector","useSyncExternalStore"],"mappings":"yGAkCaA,EAAsBC,GAA6C,CAC9E,IAAIC,EACJ,MAAMC,MAA2C,IAE3CC,EAAyCC,GAAkC,CAC/E,MAAMC,EAAY,OAAOD,GAAW,WAAaA,EAAOH,CAAK,EAAIG,EAEjE,GAAI,CAAC,OAAO,GAAGC,EAAWJ,CAAK,EAAG,CAChC,MAAMK,EAAYL,EAClBA,EACE,OAAOI,GAAc,UAAYA,IAAc,MAAQ,MAAM,QAAQA,CAAS,EAC1EA,EACA,OAAO,OAAO,CAAA,EAAIJ,EAAOI,CAAS,EAGxCH,EAAU,QAASK,GAAaA,EAASN,EAAOK,CAAS,CAAC,CAAA,CAC5D,EAGIE,EAAaD,IACjBL,EAAU,IAAIK,CAAQ,EAEf,IAAML,EAAU,OAAOK,CAAQ,GAGlCE,EAAW,IAAMR,EACjBS,EAAkB,IAAMT,EAE1B,OAAOD,GAAgB,WACzBC,EAASD,EAAoCG,EAAUM,CAAQ,EAE/DR,EAAQD,EAKV,SAASW,EAAmBC,EAAyD,CACnF,OAAOC,EAAAA,qBACLL,EACA,IAAOI,EAAWA,EAASH,EAAA,CAAU,EAAIA,EAAA,EACzC,IAAOG,EAAWA,EAASF,EAAA,CAAiB,EAAIA,EAAA,CAAgB,CAClE,CAGF,MAAO,CACL,IAAKP,EACL,IAAKM,EACL,IAAKE,EACL,UAAAH,CAAA,CAEJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react"),d=require("../useRefState/useRefState.cjs"),f=require("../../utils/helpers/isTarget.cjs"),m=require("../../utils/helpers/getElement.cjs"),E=(...
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react"),d=require("../useRefState/useRefState.cjs"),f=require("../../utils/helpers/isTarget.cjs"),m=require("../../utils/helpers/getElement.cjs"),E=(...u)=>{const r=f.isTarget(u[0])?u[0]:void 0,[o,c]=l.useState(null),s=d.useRefState();return l.useEffect(()=>{const e=(r?m.getElement(r):s.current)??window,i=new MutationObserver(v=>{v.filter(t=>t.removedNodes.length).map(t=>Array.from(t.removedNodes)).flat().forEach(t=>{c(a=>t===a?document.activeElement:a)})});i.observe(e,{childList:!0,subtree:!0});const n=()=>c(document?.activeElement);return e.addEventListener("focus",n,!0),e.addEventListener("blur",n,!0),()=>{i.disconnect(),e.removeEventListener("focus",n,!0),e.removeEventListener("blur",n,!0)}},[r,s.state]),r?o:{ref:s,value:o}};exports.useActiveElement=E;
|
|
2
2
|
//# sourceMappingURL=useActiveElement.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActiveElement.cjs","sources":["../../../../src/hooks/useActiveElement/useActiveElement.ts"],"sourcesContent":["import { useEffect, useState } from
|
|
1
|
+
{"version":3,"file":"useActiveElement.cjs","sources":["../../../../src/hooks/useActiveElement/useActiveElement.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\n\nimport type { HookTarget } from \"@/utils/helpers\";\n\nimport { getElement, isTarget } from \"@/utils/helpers\";\n\nimport type { StateRef } from \"../useRefState/useRefState\";\n\nimport { useRefState } from \"../useRefState/useRefState\";\n\n/** The use active element return type */\nexport type UseActiveElementReturn<\n ActiveElement extends HTMLElement = HTMLElement\n> = ActiveElement | null;\n\nexport interface UseActiveElement {\n (): UseActiveElementReturn;\n\n <Target extends Element, ActiveElement extends HTMLElement = HTMLElement>(\n target?: never\n ): {\n ref: StateRef<Target>;\n value: UseActiveElementReturn<ActiveElement>;\n };\n\n <ActiveElement extends HTMLElement = HTMLElement>(\n target: HookTarget\n ): UseActiveElementReturn<ActiveElement>;\n}\n\n/**\n * @name useActiveElement\n * @description - Hook that returns the active element\n * @category Elements\n * @usage low\n *\n * @overload\n * @param {HookTarget} [target=window] The target element to observe active element changes\n * @returns {ActiveElement | null} The active element\n *\n * @example\n * const activeElement = useActiveElement(ref);\n *\n * @overload\n * @template ActiveElement The active element type\n * @returns {{ ref: StateRef<Element>; activeElement: ActiveElement | null }} An object containing the ref and active element\n *\n * @example\n * const { ref, value } = useActiveElement();\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useActiveElement.html}\n */\nexport const useActiveElement = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as\n | HookTarget\n | undefined;\n\n const [value, setValue] = useState<HTMLElement | null>(null);\n const internalRef = useRefState();\n\n useEffect(() => {\n const element = ((target ? getElement(target) : internalRef.current) ??\n window) as Element;\n\n const observer = new MutationObserver((mutations) => {\n mutations\n .filter((mutation) => mutation.removedNodes.length)\n .map((mutation) => Array.from(mutation.removedNodes))\n .flat()\n .forEach((node) => {\n setValue((prevActiveElement) => {\n if (node === prevActiveElement)\n return document.activeElement as HTMLElement | null;\n return prevActiveElement;\n });\n });\n });\n\n observer.observe(element, {\n childList: true,\n subtree: true,\n });\n\n const onActiveElementChange = () =>\n setValue(document?.activeElement as HTMLElement | null);\n\n element.addEventListener(\"focus\", onActiveElementChange, true);\n element.addEventListener(\"blur\", onActiveElementChange, true);\n\n return () => {\n observer.disconnect();\n element.removeEventListener(\"focus\", onActiveElementChange, true);\n element.removeEventListener(\"blur\", onActiveElementChange, true);\n };\n }, [target, internalRef.state]);\n\n if (target) return value;\n return {\n ref: internalRef,\n value,\n };\n}) as UseActiveElement;\n"],"names":["useActiveElement","params","target","isTarget","value","setValue","useState","internalRef","useRefState","useEffect","element","getElement","observer","mutations","mutation","node","prevActiveElement","onActiveElementChange"],"mappings":"mPAoDaA,EAAoB,IAAIC,IAAkB,CACrD,MAAMC,EAAUC,EAAAA,SAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAI5C,CAACG,EAAOC,CAAQ,EAAIC,EAAAA,SAA6B,IAAI,EACrDC,EAAcC,EAAAA,YAAA,EAsCpB,OApCAC,EAAAA,UAAU,IAAM,CACd,MAAMC,GAAYR,EAASS,EAAAA,WAAWT,CAAM,EAAIK,EAAY,UAC1D,OAEIK,EAAW,IAAI,iBAAkBC,GAAc,CACnDA,EACG,OAAQC,GAAaA,EAAS,aAAa,MAAM,EACjD,IAAKA,GAAa,MAAM,KAAKA,EAAS,YAAY,CAAC,EACnD,OACA,QAASC,GAAS,CACjBV,EAAUW,GACJD,IAASC,EACJ,SAAS,cACXA,CACR,CAAA,CACF,CAAA,CACJ,EAEDJ,EAAS,QAAQF,EAAS,CACxB,UAAW,GACX,QAAS,EAAA,CACV,EAED,MAAMO,EAAwB,IAC5BZ,EAAS,UAAU,aAAmC,EAExD,OAAAK,EAAQ,iBAAiB,QAASO,EAAuB,EAAI,EAC7DP,EAAQ,iBAAiB,OAAQO,EAAuB,EAAI,EAErD,IAAM,CACXL,EAAS,WAAA,EACTF,EAAQ,oBAAoB,QAASO,EAAuB,EAAI,EAChEP,EAAQ,oBAAoB,OAAQO,EAAuB,EAAI,CAAA,CACjE,EACC,CAACf,EAAQK,EAAY,KAAK,CAAC,EAE1BL,EAAeE,EACZ,CACL,IAAKG,EACL,MAAAH,CAAA,CAEJ"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs"),o=(e,t)=>{c.useIsomorphicLayoutEffect(()=>{e()},t)};exports.useAsyncEffect=o;
|
|
2
|
+
//# sourceMappingURL=useAsyncEffect.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAsyncEffect.cjs","sources":["../../../../src/hooks/useAsyncEffect/useAsyncEffect.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\n\n/**\n * @name useAsyncEffect\n * @description – Hook that triggers the effect callback on updates\n * @category Lifecycle\n * @usage medium\n\n * @param {EffectCallback} effect The effect callback\n * @param {DependencyList} [deps] The dependencies list for the effect\n *\n * @example\n * useAsyncEffect(async () => console.log(\"effect runs on updates\"), deps);\n */\nexport const useAsyncEffect = (сallback: () => Promise<any>, deps?: DependencyList): void => {\n useIsomorphicLayoutEffect(() => {\n сallback();\n }, deps);\n};\n"],"names":["useAsyncEffect","сallback","deps","useIsomorphicLayoutEffect"],"mappings":"8JAgBaA,EAAiB,CAACC,EAA8BC,IAAgC,CAC3FC,EAAAA,0BAA0B,IAAM,CAC9BF,EAAA,CAAS,EACRC,CAAI,CACT"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react"),h=require("../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs"),v=require("../useRefState/useRefState.cjs"),S=require("../../utils/helpers/isTarget.cjs"),T=require("../../utils/helpers/getElement.cjs"),q=["input:not([disabled])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","a[href]","area[href]","summary","iframe","object","embed","audio[controls]","video[controls]","[contenteditable]",'[tabindex]:not([tabindex^="-"])'].join(","),y=e=>Array.from(e.querySelectorAll(q)).filter(o=>{const n=o;return n.tabIndex!==-1&&!n.hidden&&n.style.display!=="none"}),L=e=>{const t=e.querySelector("[data-autofocus]");if(t)return t.focus();const o=y(e);o.length>0&&o[0].focus()},p=(...e)=>{const t=S.isTarget(e[0])?e[0]:void 0,o=t?e[1]:e[0],[n,c]=g.useState(o),u=v.useRefState(),i=()=>c(!0),l=()=>c(!1),a=()=>c(s=>!s);return h.useIsomorphicLayoutEffect(()=>{if(!n)return;const s=t?T.getElement(t):u.current;if(!s)return;const f=s;L(f);const d=r=>{if(r.key!=="Tab")return;const[m,...E]=y(f);if(!E.length)return;const b=E.at(-1);r.shiftKey&&document.activeElement===m&&(r.preventDefault(),b.focus()),document.activeElement===b&&(r.preventDefault(),m.focus())};return document.addEventListener("keydown",d),()=>{document.removeEventListener("keydown",d)}},[n,t,u.state]),t?{active:n,enable:i,disable:l,toggle:a}:{active:n,enable:i,disable:l,toggle:a,ref:u}};exports.useFocusTrap=p;
|
|
2
|
+
//# sourceMappingURL=useFocusTrap.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFocusTrap.cjs","sources":["../../../../src/hooks/useFocusTrap/useFocusTrap.ts"],"sourcesContent":["import { useState } from \"react\";\n\nimport type { HookTarget } from \"@/utils/helpers\";\n\nimport { getElement, isTarget } from \"@/utils/helpers\";\n\nimport type { StateRef } from \"../useRefState/useRefState\";\n\nimport { useIsomorphicLayoutEffect } from \"../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect\";\nimport { useRefState } from \"../useRefState/useRefState\";\n\nconst FOCUSABLE_ELEMENTS_SELECTOR = [\n \"input:not([disabled])\",\n \"select:not([disabled])\",\n \"textarea:not([disabled])\",\n \"button:not([disabled])\",\n \"a[href]\",\n \"area[href]\",\n \"summary\",\n \"iframe\",\n \"object\",\n \"embed\",\n \"audio[controls]\",\n \"video[controls]\",\n \"[contenteditable]\",\n '[tabindex]:not([tabindex^=\"-\"])',\n].join(\",\");\n\nconst getFocusableElements = (element: HTMLElement): HTMLElement[] => {\n const elements = Array.from(\n element.querySelectorAll(FOCUSABLE_ELEMENTS_SELECTOR)\n );\n return elements.filter((el) => {\n const htmlEl = el as HTMLElement;\n return (\n htmlEl.tabIndex !== -1 &&\n !htmlEl.hidden &&\n htmlEl.style.display !== \"none\"\n );\n }) as HTMLElement[];\n};\n\nconst focusElement = (element: HTMLElement) => {\n const autofocusElement = element.querySelector(\n \"[data-autofocus]\"\n ) as HTMLElement;\n if (autofocusElement) return autofocusElement.focus();\n\n const focusableElements = getFocusableElements(element);\n if (focusableElements.length > 0) {\n focusableElements[0].focus();\n }\n};\n\n/** The use focus trap return type */\nexport interface UseFocusTrapReturn {\n /** Whether focus trap is active */\n active: boolean;\n /** Disable focus trap */\n disable: () => void;\n /** Enable focus trap */\n enable: () => void;\n /** Toggle focus trap */\n toggle: () => void;\n}\n\nexport interface UseFocusTrap {\n (target: HookTarget, active?: boolean): UseFocusTrapReturn;\n\n <Target extends HTMLElement>(\n active?: boolean,\n target?: never\n ): UseFocusTrapReturn & {\n ref: StateRef<Target>;\n };\n}\n\n/**\n * @name useFocusTrap\n * @description - Hook that traps focus within a given element\n * @category Elements\n * @usage medium\n *\n * @overload\n * @param {HookTarget} target The target element for focus trap\n * @param {boolean} [active=true] Whether focus trap is active\n * @returns {UseFocusTrapReturn} Object with control methods and state\n *\n * @example\n * const { active, disable, toggle, enable } = useFocusTrap(ref, true);\n *\n * @overload\n * @template Target The target element type\n * @param {boolean} [active=true] Whether focus trap is active\n * @returns {UseFocusTrapReturn & { ref: StateRef<Target> }} Object with ref and controls\n *\n * @example\n * const { ref, active, disable, toggle, enable } = useFocusTrap(true);\n */\nexport const useFocusTrap = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as\n | HookTarget\n | undefined;\n const initialActive = target ? params[1] : params[0];\n\n const [active, setActive] = useState(initialActive);\n const internalRef = useRefState<HTMLElement>();\n\n const enable = () => setActive(true);\n const disable = () => setActive(false);\n const toggle = () => setActive((prevActive: boolean) => !prevActive);\n\n useIsomorphicLayoutEffect(() => {\n if (!active) return;\n\n const element = target ? getElement(target) : internalRef.current;\n if (!element) return;\n\n const htmlElement = element as HTMLElement;\n focusElement(htmlElement);\n\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key !== \"Tab\") return;\n\n const [firstElement, ...restElements] = getFocusableElements(htmlElement);\n if (!restElements.length) return;\n\n const lastElement = restElements.at(-1)!;\n\n if (event.shiftKey && document.activeElement === firstElement) {\n event.preventDefault();\n lastElement.focus();\n }\n\n if (document.activeElement === lastElement) {\n event.preventDefault();\n firstElement.focus();\n }\n };\n\n document.addEventListener(\"keydown\", onKeyDown);\n\n return () => {\n document.removeEventListener(\"keydown\", onKeyDown);\n };\n }, [active, target, internalRef.state]);\n\n if (target) return { active, enable, disable, toggle };\n return { active, enable, disable, toggle, ref: internalRef };\n}) as UseFocusTrap;\n"],"names":["FOCUSABLE_ELEMENTS_SELECTOR","getFocusableElements","element","el","htmlEl","focusElement","autofocusElement","focusableElements","useFocusTrap","params","target","isTarget","initialActive","active","setActive","useState","internalRef","useRefState","enable","disable","toggle","prevActive","useIsomorphicLayoutEffect","getElement","htmlElement","onKeyDown","event","firstElement","restElements","lastElement"],"mappings":"2TAWMA,EAA8B,CAClC,wBACA,yBACA,2BACA,yBACA,UACA,aACA,UACA,SACA,SACA,QACA,kBACA,kBACA,oBACA,iCACF,EAAE,KAAK,GAAG,EAEJC,EAAwBC,GACX,MAAM,KACrBA,EAAQ,iBAAiBF,CAA2B,CAAA,EAEtC,OAAQG,GAAO,CAC7B,MAAMC,EAASD,EACf,OACEC,EAAO,WAAa,IACpB,CAACA,EAAO,QACRA,EAAO,MAAM,UAAY,MAAA,CAE5B,EAGGC,EAAgBH,GAAyB,CAC7C,MAAMI,EAAmBJ,EAAQ,cAC/B,kBAAA,EAEF,GAAII,EAAkB,OAAOA,EAAiB,MAAA,EAE9C,MAAMC,EAAoBN,EAAqBC,CAAO,EAClDK,EAAkB,OAAS,GAC7BA,EAAkB,CAAC,EAAE,MAAA,CAEzB,EA+CaC,EAAgB,IAAIC,IAAkB,CACjD,MAAMC,EAAUC,EAAAA,SAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAG5CG,EAAgBF,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,EAE7C,CAACI,EAAQC,CAAS,EAAIC,EAAAA,SAASH,CAAa,EAC5CI,EAAcC,EAAAA,YAAA,EAEdC,EAAS,IAAMJ,EAAU,EAAI,EAC7BK,EAAU,IAAML,EAAU,EAAK,EAC/BM,EAAS,IAAMN,EAAWO,GAAwB,CAACA,CAAU,EAqCnE,OAnCAC,EAAAA,0BAA0B,IAAM,CAC9B,GAAI,CAACT,EAAQ,OAEb,MAAMX,EAAUQ,EAASa,EAAAA,WAAWb,CAAM,EAAIM,EAAY,QAC1D,GAAI,CAACd,EAAS,OAEd,MAAMsB,EAActB,EACpBG,EAAamB,CAAW,EAExB,MAAMC,EAAaC,GAAyB,CAC1C,GAAIA,EAAM,MAAQ,MAAO,OAEzB,KAAM,CAACC,EAAc,GAAGC,CAAY,EAAI3B,EAAqBuB,CAAW,EACxE,GAAI,CAACI,EAAa,OAAQ,OAE1B,MAAMC,EAAcD,EAAa,GAAG,EAAE,EAElCF,EAAM,UAAY,SAAS,gBAAkBC,IAC/CD,EAAM,eAAA,EACNG,EAAY,MAAA,GAGV,SAAS,gBAAkBA,IAC7BH,EAAM,eAAA,EACNC,EAAa,MAAA,EACf,EAGF,gBAAS,iBAAiB,UAAWF,CAAS,EAEvC,IAAM,CACX,SAAS,oBAAoB,UAAWA,CAAS,CAAA,CACnD,EACC,CAACZ,EAAQH,EAAQM,EAAY,KAAK,CAAC,EAElCN,EAAe,CAAE,OAAAG,EAAQ,OAAAK,EAAQ,QAAAC,EAAS,OAAAC,CAAA,EACvC,CAAE,OAAAP,EAAQ,OAAAK,EAAQ,QAAAC,EAAS,OAAAC,EAAQ,IAAKJ,CAAA,CACjD"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("./helpers/createContext/createContext.cjs"),I=require("./helpers/createEventEmitter/createEventEmitter.cjs"),k=require("./helpers/createReactiveContext/createReactiveContext.cjs"),v=require("./helpers/createStore/createStore.cjs"),O=require("./hooks/useAsync/useAsync.cjs"),h=require("./hooks/useLockCallback/useLockCallback.cjs"),A=require("./hooks/useMutation/useMutation.cjs"),D=require("./hooks/useOptimistic/useOptimistic.cjs"),b=require("./hooks/useQuery/useQuery.cjs"),f=require("./hooks/useAudio/useAudio.cjs"),M=require("./hooks/useBattery/useBattery.cjs"),L=require("./hooks/useBluetooth/useBluetooth.cjs"),_=require("./hooks/useBroadcastChannel/useBroadcastChannel.cjs"),N=require("./hooks/useClipboard/useClipboard.cjs"),B=require("./hooks/useCopy/useCopy.cjs"),K=require("./hooks/useCssVar/useCssVar.cjs"),F=require("./hooks/useDisplayMedia/useDisplayMedia.cjs"),V=require("./hooks/useDocumentTitle/useDocumentTitle.cjs"),U=require("./hooks/useEventSource/useEventSource.cjs"),w=require("./hooks/useEyeDropper/useEyeDropper.cjs"),W=require("./hooks/useFavicon/useFavicon.cjs"),H=require("./hooks/useFps/useFps.cjs"),x=require("./hooks/useFullscreen/useFullscreen.cjs"),n=require("./hooks/useGamepad/useGamepad.cjs"),Q=require("./hooks/useGeolocation/useGeolocation.cjs"),c=require("./hooks/useMediaControls/useMediaControls.cjs"),z=require("./hooks/useMemory/useMemory.cjs"),a=require("./hooks/useNetwork/useNetwork.cjs"),G=require("./hooks/useOnline/useOnline.cjs"),X=require("./hooks/useOtpCredential/useOtpCredential.cjs"),Z=require("./hooks/usePermission/usePermission.cjs"),j=require("./hooks/usePictureInPicture/usePictureInPicture.cjs"),J=require("./hooks/usePointerLock/usePointerLock.cjs"),Y=require("./hooks/usePostMessage/usePostMessage.cjs"),$=require("./hooks/useRaf/useRaf.cjs"),ee=require("./hooks/useShare/useShare.cjs"),l=require("./hooks/useSpeechRecognition/useSpeechRecognition.cjs"),se=require("./hooks/useSpeechSynthesis/useSpeechSynthesis.cjs"),ue=require("./hooks/useVibrate/useVibrate.cjs"),re=require("./hooks/useVirtualKeyboard/useVirtualKeyboard.cjs"),te=require("./hooks/useWakeLock/useWakeLock.cjs"),oe=require("./hooks/useWebSocket/useWebSocket.cjs"),ie=require("./hooks/useLogger/useLogger.cjs"),ne=require("./hooks/useRenderCount/useRenderCount.cjs"),ce=require("./hooks/useRenderInfo/useRenderInfo.cjs"),ae=require("./hooks/useRerender/useRerender.cjs"),le=require("./hooks/useActiveElement/useActiveElement.cjs"),Se=require("./hooks/useAutoScroll/useAutoScroll.cjs"),qe=require("./hooks/useClickOutside/useClickOutside.cjs"),S=require("./hooks/useDoubleClick/useDoubleClick.cjs"),de=require("./hooks/useDropZone/useDropZone.cjs"),ge=require("./hooks/useFileDialog/useFileDialog.cjs"),Ee=require("./hooks/useFocus/useFocus.cjs"),Te=require("./hooks/useHover/useHover.cjs"),Pe=require("./hooks/useImage/useImage.cjs"),Ce=require("./hooks/useLongPress/useLongPress.cjs"),r=require("./hooks/usePaint/usePaint.cjs"),Re=require("./hooks/useRightClick/useRightClick.cjs"),q=require("./hooks/useScript/useScript.cjs"),me=require("./hooks/useSticky/useSticky.cjs"),pe=require("./hooks/useTextDirection/useTextDirection.cjs"),ye=require("./hooks/useFul/useFul.cjs"),Ie=require("./hooks/useLess/useLess.cjs"),ke=require("./hooks/useOnce/useOnce.cjs"),ve=require("./hooks/useDidUpdate/useDidUpdate.cjs"),Oe=require("./hooks/useIsFirstRender/useIsFirstRender.cjs"),he=require("./hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs"),Ae=require("./hooks/useMount/useMount.cjs"),d=require("./hooks/useShallowEffect/useShallowEffect.cjs"),De=require("./hooks/useUnmount/useUnmount.cjs"),e=require("./hooks/useBreakpoints/useBreakpoints.cjs"),be=require("./hooks/useDeviceMotion/useDeviceMotion.cjs"),fe=require("./hooks/useDeviceOrientation/useDeviceOrientation.cjs"),Me=require("./hooks/useDevicePixelRatio/useDevicePixelRatio.cjs"),Le=require("./hooks/useDocumentEvent/useDocumentEvent.cjs"),_e=require("./hooks/useDocumentVisibility/useDocumentVisibility.cjs"),Ne=require("./hooks/useElementSize/useElementSize.cjs"),Be=require("./hooks/useEventListener/useEventListener.cjs"),g=require("./hooks/useHotkeys/useHotkeys.cjs"),Ke=require("./hooks/useIdle/useIdle.cjs"),Fe=require("./hooks/useInfiniteScroll/useInfiniteScroll.cjs"),Ve=require("./hooks/useIntersectionObserver/useIntersectionObserver.cjs"),Ue=require("./hooks/useKeyboard/useKeyboard.cjs"),we=require("./hooks/useKeyPress/useKeyPress.cjs"),We=require("./hooks/useKeyPressEvent/useKeyPressEvent.cjs"),He=require("./hooks/useKeysPressed/useKeysPressed.cjs"),xe=require("./hooks/useLockScroll/useLockScroll.cjs"),Qe=require("./hooks/useMeasure/useMeasure.cjs"),ze=require("./hooks/useMediaQuery/useMediaQuery.cjs"),Ge=require("./hooks/useMouse/useMouse.cjs"),Xe=require("./hooks/useMutationObserver/useMutationObserver.cjs"),Ze=require("./hooks/useOrientation/useOrientation.cjs"),je=require("./hooks/usePageLeave/usePageLeave.cjs"),Je=require("./hooks/useParallax/useParallax.cjs"),Ye=require("./hooks/usePerformanceObserver/usePerformanceObserver.cjs"),$e=require("./hooks/useResizeObserver/useResizeObserver.cjs"),es=require("./hooks/useScroll/useScroll.cjs"),ss=require("./hooks/useScrollIntoView/useScrollIntoView.cjs"),us=require("./hooks/useScrollTo/useScrollTo.cjs"),E=require("./hooks/useTextSelection/useTextSelection.cjs"),rs=require("./hooks/useWindowEvent/useWindowEvent.cjs"),ts=require("./hooks/useWindowFocus/useWindowFocus.cjs"),T=require("./hooks/useWindowScroll/useWindowScroll.cjs"),os=require("./hooks/useWindowSize/useWindowSize.cjs"),is=require("./hooks/useBoolean/useBoolean.cjs"),ns=require("./hooks/useControllableState/useControllableState.cjs"),s=require("./hooks/useCookie/useCookie.cjs"),P=require("./hooks/useCookies/useCookies.cjs"),cs=require("./hooks/useCounter/useCounter.cjs"),as=require("./hooks/useDefault/useDefault.cjs"),ls=require("./hooks/useDisclosure/useDisclosure.cjs"),Ss=require("./hooks/useField/useField.cjs"),qs=require("./hooks/useHash/useHash.cjs"),ds=require("./hooks/useList/useList.cjs"),gs=require("./hooks/useLocalStorage/useLocalStorage.cjs"),Es=require("./hooks/useMap/useMap.cjs"),t=require("./hooks/useMergedRef/useMergedRef.cjs"),Ts=require("./hooks/useOffsetPagination/useOffsetPagination.cjs"),Ps=require("./hooks/useQueue/useQueue.cjs"),Cs=require("./hooks/useRafState/useRafState.cjs"),Rs=require("./hooks/useRefState/useRefState.cjs"),ms=require("./hooks/useSessionStorage/useSessionStorage.cjs"),ps=require("./hooks/useSet/useSet.cjs"),C=require("./hooks/useStateHistory/useStateHistory.cjs"),ys=require("./hooks/useStep/useStep.cjs"),o=require("./hooks/useStorage/useStorage.cjs"),Is=require("./hooks/useToggle/useToggle.cjs"),u=require("./hooks/useUrlSearchParam/useUrlSearchParam.cjs"),ks=require("./hooks/useUrlSearchParams/useUrlSearchParams.cjs"),vs=require("./hooks/useWizard/useWizard.cjs"),Os=require("./hooks/useInterval/useInterval.cjs"),hs=require("./hooks/useStopwatch/useStopwatch.cjs"),As=require("./hooks/useTime/useTime.cjs"),Ds=require("./hooks/useTimeout/useTimeout.cjs"),R=require("./hooks/useTimer/useTimer.cjs"),bs=require("./hooks/useBrowserLanguage/useBrowserLanguage.cjs"),m=require("./hooks/useOperatingSystem/useOperatingSystem.cjs"),fs=require("./hooks/usePreferredColorScheme/usePreferredColorScheme.cjs"),Ms=require("./hooks/usePreferredContrast/usePreferredContrast.cjs"),Ls=require("./hooks/usePreferredDark/usePreferredDark.cjs"),_s=require("./hooks/usePreferredLanguages/usePreferredLanguages.cjs"),Ns=require("./hooks/usePreferredReducedMotion/usePreferredReducedMotion.cjs"),Bs=require("./hooks/useConst/useConst.cjs"),Ks=require("./hooks/useDebounceCallback/useDebounceCallback.cjs"),Fs=require("./hooks/useDebounceState/useDebounceState.cjs"),Vs=require("./hooks/useDebounceValue/useDebounceValue.cjs"),Us=require("./hooks/useEvent/useEvent.cjs"),ws=require("./hooks/useLastChanged/useLastChanged.cjs"),Ws=require("./hooks/useLatest/useLatest.cjs"),Hs=require("./hooks/usePrevious/usePrevious.cjs"),xs=require("./hooks/useThrottleCallback/useThrottleCallback.cjs"),Qs=require("./hooks/useThrottleState/useThrottleState.cjs"),zs=require("./hooks/useThrottleValue/useThrottleValue.cjs"),p=require("./utils/helpers/copy.cjs"),Gs=require("./utils/helpers/debounce.cjs"),Xs=require("./utils/helpers/getDate.cjs"),i=require("./utils/helpers/getElement.cjs"),Zs=require("./utils/helpers/getRetry.cjs"),js=require("./utils/helpers/isTarget.cjs"),Js=require("./utils/helpers/throttle.cjs");exports.createContext=y.createContext;exports.createEventEmitter=I.createEventEmitter;exports.createReactiveContext=k.createReactiveContext;exports.createStore=v.createStore;exports.useAsync=O.useAsync;exports.useLockCallback=h.useLockCallback;exports.useMutation=A.useMutation;exports.useOptimistic=D.useOptimistic;exports.useQuery=b.useQuery;exports.useAudio=f.useAudio;exports.useBattery=M.useBattery;exports.useBluetooth=L.useBluetooth;exports.useBroadcastChannel=_.useBroadcastChannel;exports.useClipboard=N.useClipboard;exports.useCopy=B.useCopy;exports.useCssVar=K.useCssVar;exports.useDisplayMedia=F.useDisplayMedia;exports.useDocumentTitle=V.useDocumentTitle;exports.useEventSource=U.useEventSource;exports.useEyeDropper=w.useEyeDropper;exports.useFavicon=W.useFavicon;exports.useFps=H.useFps;exports.useFullscreen=x.useFullscreen;exports.mapGamepadToXbox360Controller=n.mapGamepadToXbox360Controller;exports.useGamepad=n.useGamepad;exports.useGeolocation=Q.useGeolocation;exports.timeRangeToArray=c.timeRangeToArray;exports.useMediaControls=c.useMediaControls;exports.useMemory=z.useMemory;exports.getConnection=a.getConnection;exports.useNetwork=a.useNetwork;exports.useOnline=G.useOnline;exports.useOtpCredential=X.useOtpCredential;exports.usePermission=Z.usePermission;exports.usePictureInPicture=j.usePictureInPicture;exports.usePointerLock=J.usePointerLock;exports.usePostMessage=Y.usePostMessage;exports.useRaf=$.useRaf;exports.useShare=ee.useShare;exports.getSpeechRecognition=l.getSpeechRecognition;exports.useSpeechRecognition=l.useSpeechRecognition;exports.useSpeechSynthesis=se.useSpeechSynthesis;exports.useVibrate=ue.useVibrate;exports.useVirtualKeyboard=re.useVirtualKeyboard;exports.useWakeLock=te.useWakeLock;exports.useWebSocket=oe.useWebSocket;exports.useLogger=ie.useLogger;exports.useRenderCount=ne.useRenderCount;exports.useRenderInfo=ce.useRenderInfo;exports.useRerender=ae.useRerender;exports.useActiveElement=le.useActiveElement;exports.useAutoScroll=Se.useAutoScroll;exports.useClickOutside=qe.useClickOutside;exports.DEFAULT_THRESHOLD_TIME=S.DEFAULT_THRESHOLD_TIME;exports.useDoubleClick=S.useDoubleClick;exports.useDropZone=de.useDropZone;exports.useFileDialog=ge.useFileDialog;exports.useFocus=Ee.useFocus;exports.useHover=Te.useHover;exports.useImage=Pe.useImage;exports.useLongPress=Ce.useLongPress;exports.Paint=r.Paint;exports.Pointer=r.Pointer;exports.usePaint=r.usePaint;exports.useRightClick=Re.useRightClick;exports.SCRIPT_STATUS_ATTRIBUTE_NAME=q.SCRIPT_STATUS_ATTRIBUTE_NAME;exports.useScript=q.useScript;exports.useSticky=me.useSticky;exports.useTextDirection=pe.useTextDirection;exports.useFul=ye.useFul;exports.useLess=Ie.useLess;exports.useOnce=ke.useOnce;exports.useDidUpdate=ve.useDidUpdate;exports.useIsFirstRender=Oe.useIsFirstRender;exports.useIsomorphicLayoutEffect=he.useIsomorphicLayoutEffect;exports.useMount=Ae.useMount;exports.deepEqual=d.deepEqual;exports.useShallowEffect=d.useShallowEffect;exports.useUnmount=De.useUnmount;exports.BREAKPOINTS_ANT_DESIGN=e.BREAKPOINTS_ANT_DESIGN;exports.BREAKPOINTS_BOOTSTRAP_V5=e.BREAKPOINTS_BOOTSTRAP_V5;exports.BREAKPOINTS_MANTINE=e.BREAKPOINTS_MANTINE;exports.BREAKPOINTS_MASTER_CSS=e.BREAKPOINTS_MASTER_CSS;exports.BREAKPOINTS_MATERIAL_UI=e.BREAKPOINTS_MATERIAL_UI;exports.BREAKPOINTS_PRIME_FLEX=e.BREAKPOINTS_PRIME_FLEX;exports.BREAKPOINTS_QUASAR_V2=e.BREAKPOINTS_QUASAR_V2;exports.BREAKPOINTS_SEMANTIC=e.BREAKPOINTS_SEMANTIC;exports.BREAKPOINTS_TAILWIND=e.BREAKPOINTS_TAILWIND;exports.useBreakpoints=e.useBreakpoints;exports.useDeviceMotion=be.useDeviceMotion;exports.useDeviceOrientation=fe.useDeviceOrientation;exports.useDevicePixelRatio=Me.useDevicePixelRatio;exports.useDocumentEvent=Le.useDocumentEvent;exports.useDocumentVisibility=_e.useDocumentVisibility;exports.useElementSize=Ne.useElementSize;exports.useEventListener=Be.useEventListener;exports.isHotkeyMatch=g.isHotkeyMatch;exports.useHotkeys=g.useHotkeys;exports.useIdle=Ke.useIdle;exports.useInfiniteScroll=Fe.useInfiniteScroll;exports.useIntersectionObserver=Ve.useIntersectionObserver;exports.useKeyboard=Ue.useKeyboard;exports.useKeyPress=we.useKeyPress;exports.useKeyPressEvent=We.useKeyPressEvent;exports.useKeysPressed=He.useKeysPressed;exports.useLockScroll=xe.useLockScroll;exports.useMeasure=Qe.useMeasure;exports.useMediaQuery=ze.useMediaQuery;exports.useMouse=Ge.useMouse;exports.useMutationObserver=Xe.useMutationObserver;exports.useOrientation=Ze.useOrientation;exports.usePageLeave=je.usePageLeave;exports.useParallax=Je.useParallax;exports.usePerformanceObserver=Ye.usePerformanceObserver;exports.useResizeObserver=$e.useResizeObserver;exports.useScroll=es.useScroll;exports.useScrollIntoView=ss.useScrollIntoView;exports.useScrollTo=us.useScrollTo;exports.getRangesSelection=E.getRangesSelection;exports.useTextSelection=E.useTextSelection;exports.useWindowEvent=rs.useWindowEvent;exports.useWindowFocus=ts.useWindowFocus;exports.scrollTo=T.scrollTo;exports.useWindowScroll=T.useWindowScroll;exports.useWindowSize=os.useWindowSize;exports.useBoolean=is.useBoolean;exports.useControllableState=ns.useControllableState;exports.COOKIE_EVENT=s.COOKIE_EVENT;exports.dispatchCookieEvent=s.dispatchCookieEvent;exports.getCookie=s.getCookie;exports.getCookies=s.getCookies;exports.removeCookie=s.removeCookie;exports.removeCookieItem=s.removeCookieItem;exports.setCookie=s.setCookie;exports.setCookieItem=s.setCookieItem;exports.useCookie=s.useCookie;exports.clearCookies=P.clearCookies;exports.useCookies=P.useCookies;exports.useCounter=cs.useCounter;exports.useDefault=as.useDefault;exports.useDisclosure=ls.useDisclosure;exports.useField=Ss.useField;exports.useHash=qs.useHash;exports.useList=ds.useList;exports.useLocalStorage=gs.useLocalStorage;exports.useMap=Es.useMap;exports.assignRef=t.assignRef;exports.mergeRefs=t.mergeRefs;exports.useMergedRef=t.useMergedRef;exports.useOffsetPagination=Ts.useOffsetPagination;exports.useQueue=Ps.useQueue;exports.useRafState=Cs.useRafState;exports.useRefState=Rs.useRefState;exports.useSessionStorage=ms.useSessionStorage;exports.useSet=ps.useSet;exports.stateHistoryReducer=C.stateHistoryReducer;exports.useStateHistory=C.useStateHistory;exports.useStep=ys.useStep;exports.STORAGE_EVENT=o.STORAGE_EVENT;exports.dispatchStorageEvent=o.dispatchStorageEvent;exports.useStorage=o.useStorage;exports.useToggle=Is.useToggle;exports.URL_SEARCH_PARAMS_EVENT=u.URL_SEARCH_PARAMS_EVENT;exports.createQueryString=u.createQueryString;exports.dispatchUrlSearchParamsEvent=u.dispatchUrlSearchParamsEvent;exports.getUrlSearchParams=u.getUrlSearchParams;exports.useUrlSearchParam=u.useUrlSearchParam;exports.useUrlSearchParams=ks.useUrlSearchParams;exports.useWizard=vs.useWizard;exports.useInterval=Os.useInterval;exports.useStopwatch=hs.useStopwatch;exports.useTime=As.useTime;exports.useTimeout=Ds.useTimeout;exports.getTimeFromSeconds=R.getTimeFromSeconds;exports.useTimer=R.useTimer;exports.useBrowserLanguage=bs.useBrowserLanguage;exports.getOperatingSystem=m.getOperatingSystem;exports.useOperatingSystem=m.useOperatingSystem;exports.usePreferredColorScheme=fs.usePreferredColorScheme;exports.usePreferredContrast=Ms.usePreferredContrast;exports.usePreferredDark=Ls.usePreferredDark;exports.usePreferredLanguages=_s.usePreferredLanguages;exports.usePreferredReducedMotion=Ns.usePreferredReducedMotion;exports.useConst=Bs.useConst;exports.useDebounceCallback=Ks.useDebounceCallback;exports.useDebounceState=Fs.useDebounceState;exports.useDebounceValue=Vs.useDebounceValue;exports.useEvent=Us.useEvent;exports.useLastChanged=ws.useLastChanged;exports.useLatest=Ws.useLatest;exports.usePrevious=Hs.usePrevious;exports.useThrottleCallback=xs.useThrottleCallback;exports.useThrottleState=Qs.useThrottleState;exports.useThrottleValue=zs.useThrottleValue;exports.copy=p.copy;exports.legacyCopyToClipboard=p.legacyCopyToClipboard;exports.debounce=Gs.debounce;exports.getDate=Xs.getDate;exports.getElement=i.getElement;exports.target=i.target;exports.targetSymbol=i.targetSymbol;exports.getRetry=Zs.getRetry;exports.isTarget=js.isTarget;exports.throttle=Js.throttle;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("./helpers/createContext/createContext.cjs"),I=require("./helpers/createEventEmitter/createEventEmitter.cjs"),k=require("./helpers/createReactiveContext/createReactiveContext.cjs"),v=require("./helpers/createStore/createStore.cjs"),O=require("./hooks/useAsync/useAsync.cjs"),h=require("./hooks/useLockCallback/useLockCallback.cjs"),A=require("./hooks/useMutation/useMutation.cjs"),f=require("./hooks/useOptimistic/useOptimistic.cjs"),D=require("./hooks/useQuery/useQuery.cjs"),b=require("./hooks/useAudio/useAudio.cjs"),M=require("./hooks/useBattery/useBattery.cjs"),L=require("./hooks/useBluetooth/useBluetooth.cjs"),_=require("./hooks/useBroadcastChannel/useBroadcastChannel.cjs"),N=require("./hooks/useClipboard/useClipboard.cjs"),B=require("./hooks/useCopy/useCopy.cjs"),F=require("./hooks/useCssVar/useCssVar.cjs"),K=require("./hooks/useDisplayMedia/useDisplayMedia.cjs"),V=require("./hooks/useDocumentTitle/useDocumentTitle.cjs"),U=require("./hooks/useEventSource/useEventSource.cjs"),w=require("./hooks/useEyeDropper/useEyeDropper.cjs"),W=require("./hooks/useFavicon/useFavicon.cjs"),H=require("./hooks/useFps/useFps.cjs"),x=require("./hooks/useFullscreen/useFullscreen.cjs"),n=require("./hooks/useGamepad/useGamepad.cjs"),Q=require("./hooks/useGeolocation/useGeolocation.cjs"),c=require("./hooks/useMediaControls/useMediaControls.cjs"),z=require("./hooks/useMemory/useMemory.cjs"),a=require("./hooks/useNetwork/useNetwork.cjs"),G=require("./hooks/useOnline/useOnline.cjs"),X=require("./hooks/useOtpCredential/useOtpCredential.cjs"),Z=require("./hooks/usePermission/usePermission.cjs"),j=require("./hooks/usePictureInPicture/usePictureInPicture.cjs"),J=require("./hooks/usePointerLock/usePointerLock.cjs"),Y=require("./hooks/usePostMessage/usePostMessage.cjs"),$=require("./hooks/useRaf/useRaf.cjs"),ee=require("./hooks/useShare/useShare.cjs"),l=require("./hooks/useSpeechRecognition/useSpeechRecognition.cjs"),se=require("./hooks/useSpeechSynthesis/useSpeechSynthesis.cjs"),ue=require("./hooks/useVibrate/useVibrate.cjs"),re=require("./hooks/useVirtualKeyboard/useVirtualKeyboard.cjs"),te=require("./hooks/useWakeLock/useWakeLock.cjs"),oe=require("./hooks/useWebSocket/useWebSocket.cjs"),ie=require("./hooks/useLogger/useLogger.cjs"),ne=require("./hooks/useRenderCount/useRenderCount.cjs"),ce=require("./hooks/useRenderInfo/useRenderInfo.cjs"),ae=require("./hooks/useRerender/useRerender.cjs"),le=require("./hooks/useActiveElement/useActiveElement.cjs"),Se=require("./hooks/useAutoScroll/useAutoScroll.cjs"),qe=require("./hooks/useClickOutside/useClickOutside.cjs"),S=require("./hooks/useDoubleClick/useDoubleClick.cjs"),de=require("./hooks/useDropZone/useDropZone.cjs"),ge=require("./hooks/useFileDialog/useFileDialog.cjs"),Ee=require("./hooks/useFocus/useFocus.cjs"),Te=require("./hooks/useFocusTrap/useFocusTrap.cjs"),Pe=require("./hooks/useHover/useHover.cjs"),Ce=require("./hooks/useImage/useImage.cjs"),Re=require("./hooks/useLongPress/useLongPress.cjs"),r=require("./hooks/usePaint/usePaint.cjs"),me=require("./hooks/useRightClick/useRightClick.cjs"),q=require("./hooks/useScript/useScript.cjs"),pe=require("./hooks/useSticky/useSticky.cjs"),ye=require("./hooks/useTextDirection/useTextDirection.cjs"),Ie=require("./hooks/useFul/useFul.cjs"),ke=require("./hooks/useLess/useLess.cjs"),ve=require("./hooks/useOnce/useOnce.cjs"),Oe=require("./hooks/useAsyncEffect/useAsyncEffect.cjs"),he=require("./hooks/useDidUpdate/useDidUpdate.cjs"),Ae=require("./hooks/useIsFirstRender/useIsFirstRender.cjs"),fe=require("./hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs"),De=require("./hooks/useMount/useMount.cjs"),d=require("./hooks/useShallowEffect/useShallowEffect.cjs"),be=require("./hooks/useUnmount/useUnmount.cjs"),e=require("./hooks/useBreakpoints/useBreakpoints.cjs"),Me=require("./hooks/useDeviceMotion/useDeviceMotion.cjs"),Le=require("./hooks/useDeviceOrientation/useDeviceOrientation.cjs"),_e=require("./hooks/useDevicePixelRatio/useDevicePixelRatio.cjs"),Ne=require("./hooks/useDocumentEvent/useDocumentEvent.cjs"),Be=require("./hooks/useDocumentVisibility/useDocumentVisibility.cjs"),Fe=require("./hooks/useElementSize/useElementSize.cjs"),Ke=require("./hooks/useEventListener/useEventListener.cjs"),g=require("./hooks/useHotkeys/useHotkeys.cjs"),Ve=require("./hooks/useIdle/useIdle.cjs"),Ue=require("./hooks/useInfiniteScroll/useInfiniteScroll.cjs"),we=require("./hooks/useIntersectionObserver/useIntersectionObserver.cjs"),We=require("./hooks/useKeyboard/useKeyboard.cjs"),He=require("./hooks/useKeyPress/useKeyPress.cjs"),xe=require("./hooks/useKeyPressEvent/useKeyPressEvent.cjs"),Qe=require("./hooks/useKeysPressed/useKeysPressed.cjs"),ze=require("./hooks/useLockScroll/useLockScroll.cjs"),Ge=require("./hooks/useMeasure/useMeasure.cjs"),Xe=require("./hooks/useMediaQuery/useMediaQuery.cjs"),Ze=require("./hooks/useMouse/useMouse.cjs"),je=require("./hooks/useMutationObserver/useMutationObserver.cjs"),Je=require("./hooks/useOrientation/useOrientation.cjs"),Ye=require("./hooks/usePageLeave/usePageLeave.cjs"),$e=require("./hooks/useParallax/useParallax.cjs"),es=require("./hooks/usePerformanceObserver/usePerformanceObserver.cjs"),ss=require("./hooks/useResizeObserver/useResizeObserver.cjs"),us=require("./hooks/useScroll/useScroll.cjs"),rs=require("./hooks/useScrollIntoView/useScrollIntoView.cjs"),ts=require("./hooks/useScrollTo/useScrollTo.cjs"),E=require("./hooks/useTextSelection/useTextSelection.cjs"),os=require("./hooks/useWindowEvent/useWindowEvent.cjs"),is=require("./hooks/useWindowFocus/useWindowFocus.cjs"),T=require("./hooks/useWindowScroll/useWindowScroll.cjs"),ns=require("./hooks/useWindowSize/useWindowSize.cjs"),cs=require("./hooks/useBoolean/useBoolean.cjs"),as=require("./hooks/useControllableState/useControllableState.cjs"),s=require("./hooks/useCookie/useCookie.cjs"),P=require("./hooks/useCookies/useCookies.cjs"),ls=require("./hooks/useCounter/useCounter.cjs"),Ss=require("./hooks/useDefault/useDefault.cjs"),qs=require("./hooks/useDisclosure/useDisclosure.cjs"),ds=require("./hooks/useField/useField.cjs"),gs=require("./hooks/useHash/useHash.cjs"),Es=require("./hooks/useList/useList.cjs"),Ts=require("./hooks/useLocalStorage/useLocalStorage.cjs"),Ps=require("./hooks/useMap/useMap.cjs"),t=require("./hooks/useMergedRef/useMergedRef.cjs"),Cs=require("./hooks/useOffsetPagination/useOffsetPagination.cjs"),Rs=require("./hooks/useQueue/useQueue.cjs"),ms=require("./hooks/useRafState/useRafState.cjs"),ps=require("./hooks/useRefState/useRefState.cjs"),ys=require("./hooks/useSessionStorage/useSessionStorage.cjs"),Is=require("./hooks/useSet/useSet.cjs"),C=require("./hooks/useStateHistory/useStateHistory.cjs"),ks=require("./hooks/useStep/useStep.cjs"),o=require("./hooks/useStorage/useStorage.cjs"),vs=require("./hooks/useToggle/useToggle.cjs"),u=require("./hooks/useUrlSearchParam/useUrlSearchParam.cjs"),Os=require("./hooks/useUrlSearchParams/useUrlSearchParams.cjs"),hs=require("./hooks/useWizard/useWizard.cjs"),As=require("./hooks/useInterval/useInterval.cjs"),fs=require("./hooks/useStopwatch/useStopwatch.cjs"),Ds=require("./hooks/useTime/useTime.cjs"),bs=require("./hooks/useTimeout/useTimeout.cjs"),R=require("./hooks/useTimer/useTimer.cjs"),Ms=require("./hooks/useBrowserLanguage/useBrowserLanguage.cjs"),m=require("./hooks/useOperatingSystem/useOperatingSystem.cjs"),Ls=require("./hooks/usePreferredColorScheme/usePreferredColorScheme.cjs"),_s=require("./hooks/usePreferredContrast/usePreferredContrast.cjs"),Ns=require("./hooks/usePreferredDark/usePreferredDark.cjs"),Bs=require("./hooks/usePreferredLanguages/usePreferredLanguages.cjs"),Fs=require("./hooks/usePreferredReducedMotion/usePreferredReducedMotion.cjs"),Ks=require("./hooks/useConst/useConst.cjs"),Vs=require("./hooks/useDebounceCallback/useDebounceCallback.cjs"),Us=require("./hooks/useDebounceState/useDebounceState.cjs"),ws=require("./hooks/useDebounceValue/useDebounceValue.cjs"),Ws=require("./hooks/useEvent/useEvent.cjs"),Hs=require("./hooks/useLastChanged/useLastChanged.cjs"),xs=require("./hooks/useLatest/useLatest.cjs"),Qs=require("./hooks/usePrevious/usePrevious.cjs"),zs=require("./hooks/useThrottleCallback/useThrottleCallback.cjs"),Gs=require("./hooks/useThrottleState/useThrottleState.cjs"),Xs=require("./hooks/useThrottleValue/useThrottleValue.cjs"),p=require("./utils/helpers/copy.cjs"),Zs=require("./utils/helpers/debounce.cjs"),js=require("./utils/helpers/getDate.cjs"),i=require("./utils/helpers/getElement.cjs"),Js=require("./utils/helpers/getRetry.cjs"),Ys=require("./utils/helpers/isTarget.cjs"),$s=require("./utils/helpers/throttle.cjs");exports.createContext=y.createContext;exports.createEventEmitter=I.createEventEmitter;exports.createReactiveContext=k.createReactiveContext;exports.createStore=v.createStore;exports.useAsync=O.useAsync;exports.useLockCallback=h.useLockCallback;exports.useMutation=A.useMutation;exports.useOptimistic=f.useOptimistic;exports.useQuery=D.useQuery;exports.useAudio=b.useAudio;exports.useBattery=M.useBattery;exports.useBluetooth=L.useBluetooth;exports.useBroadcastChannel=_.useBroadcastChannel;exports.useClipboard=N.useClipboard;exports.useCopy=B.useCopy;exports.useCssVar=F.useCssVar;exports.useDisplayMedia=K.useDisplayMedia;exports.useDocumentTitle=V.useDocumentTitle;exports.useEventSource=U.useEventSource;exports.useEyeDropper=w.useEyeDropper;exports.useFavicon=W.useFavicon;exports.useFps=H.useFps;exports.useFullscreen=x.useFullscreen;exports.mapGamepadToXbox360Controller=n.mapGamepadToXbox360Controller;exports.useGamepad=n.useGamepad;exports.useGeolocation=Q.useGeolocation;exports.timeRangeToArray=c.timeRangeToArray;exports.useMediaControls=c.useMediaControls;exports.useMemory=z.useMemory;exports.getConnection=a.getConnection;exports.useNetwork=a.useNetwork;exports.useOnline=G.useOnline;exports.useOtpCredential=X.useOtpCredential;exports.usePermission=Z.usePermission;exports.usePictureInPicture=j.usePictureInPicture;exports.usePointerLock=J.usePointerLock;exports.usePostMessage=Y.usePostMessage;exports.useRaf=$.useRaf;exports.useShare=ee.useShare;exports.getSpeechRecognition=l.getSpeechRecognition;exports.useSpeechRecognition=l.useSpeechRecognition;exports.useSpeechSynthesis=se.useSpeechSynthesis;exports.useVibrate=ue.useVibrate;exports.useVirtualKeyboard=re.useVirtualKeyboard;exports.useWakeLock=te.useWakeLock;exports.useWebSocket=oe.useWebSocket;exports.useLogger=ie.useLogger;exports.useRenderCount=ne.useRenderCount;exports.useRenderInfo=ce.useRenderInfo;exports.useRerender=ae.useRerender;exports.useActiveElement=le.useActiveElement;exports.useAutoScroll=Se.useAutoScroll;exports.useClickOutside=qe.useClickOutside;exports.DEFAULT_THRESHOLD_TIME=S.DEFAULT_THRESHOLD_TIME;exports.useDoubleClick=S.useDoubleClick;exports.useDropZone=de.useDropZone;exports.useFileDialog=ge.useFileDialog;exports.useFocus=Ee.useFocus;exports.useFocusTrap=Te.useFocusTrap;exports.useHover=Pe.useHover;exports.useImage=Ce.useImage;exports.useLongPress=Re.useLongPress;exports.Paint=r.Paint;exports.Pointer=r.Pointer;exports.usePaint=r.usePaint;exports.useRightClick=me.useRightClick;exports.SCRIPT_STATUS_ATTRIBUTE_NAME=q.SCRIPT_STATUS_ATTRIBUTE_NAME;exports.useScript=q.useScript;exports.useSticky=pe.useSticky;exports.useTextDirection=ye.useTextDirection;exports.useFul=Ie.useFul;exports.useLess=ke.useLess;exports.useOnce=ve.useOnce;exports.useAsyncEffect=Oe.useAsyncEffect;exports.useDidUpdate=he.useDidUpdate;exports.useIsFirstRender=Ae.useIsFirstRender;exports.useIsomorphicLayoutEffect=fe.useIsomorphicLayoutEffect;exports.useMount=De.useMount;exports.deepEqual=d.deepEqual;exports.useShallowEffect=d.useShallowEffect;exports.useUnmount=be.useUnmount;exports.BREAKPOINTS_ANT_DESIGN=e.BREAKPOINTS_ANT_DESIGN;exports.BREAKPOINTS_BOOTSTRAP_V5=e.BREAKPOINTS_BOOTSTRAP_V5;exports.BREAKPOINTS_MANTINE=e.BREAKPOINTS_MANTINE;exports.BREAKPOINTS_MASTER_CSS=e.BREAKPOINTS_MASTER_CSS;exports.BREAKPOINTS_MATERIAL_UI=e.BREAKPOINTS_MATERIAL_UI;exports.BREAKPOINTS_PRIME_FLEX=e.BREAKPOINTS_PRIME_FLEX;exports.BREAKPOINTS_QUASAR_V2=e.BREAKPOINTS_QUASAR_V2;exports.BREAKPOINTS_SEMANTIC=e.BREAKPOINTS_SEMANTIC;exports.BREAKPOINTS_TAILWIND=e.BREAKPOINTS_TAILWIND;exports.useBreakpoints=e.useBreakpoints;exports.useDeviceMotion=Me.useDeviceMotion;exports.useDeviceOrientation=Le.useDeviceOrientation;exports.useDevicePixelRatio=_e.useDevicePixelRatio;exports.useDocumentEvent=Ne.useDocumentEvent;exports.useDocumentVisibility=Be.useDocumentVisibility;exports.useElementSize=Fe.useElementSize;exports.useEventListener=Ke.useEventListener;exports.isHotkeyMatch=g.isHotkeyMatch;exports.useHotkeys=g.useHotkeys;exports.useIdle=Ve.useIdle;exports.useInfiniteScroll=Ue.useInfiniteScroll;exports.useIntersectionObserver=we.useIntersectionObserver;exports.useKeyboard=We.useKeyboard;exports.useKeyPress=He.useKeyPress;exports.useKeyPressEvent=xe.useKeyPressEvent;exports.useKeysPressed=Qe.useKeysPressed;exports.useLockScroll=ze.useLockScroll;exports.useMeasure=Ge.useMeasure;exports.useMediaQuery=Xe.useMediaQuery;exports.useMouse=Ze.useMouse;exports.useMutationObserver=je.useMutationObserver;exports.useOrientation=Je.useOrientation;exports.usePageLeave=Ye.usePageLeave;exports.useParallax=$e.useParallax;exports.usePerformanceObserver=es.usePerformanceObserver;exports.useResizeObserver=ss.useResizeObserver;exports.useScroll=us.useScroll;exports.useScrollIntoView=rs.useScrollIntoView;exports.useScrollTo=ts.useScrollTo;exports.getRangesSelection=E.getRangesSelection;exports.useTextSelection=E.useTextSelection;exports.useWindowEvent=os.useWindowEvent;exports.useWindowFocus=is.useWindowFocus;exports.scrollTo=T.scrollTo;exports.useWindowScroll=T.useWindowScroll;exports.useWindowSize=ns.useWindowSize;exports.useBoolean=cs.useBoolean;exports.useControllableState=as.useControllableState;exports.COOKIE_EVENT=s.COOKIE_EVENT;exports.dispatchCookieEvent=s.dispatchCookieEvent;exports.getCookie=s.getCookie;exports.getCookies=s.getCookies;exports.removeCookie=s.removeCookie;exports.removeCookieItem=s.removeCookieItem;exports.setCookie=s.setCookie;exports.setCookieItem=s.setCookieItem;exports.useCookie=s.useCookie;exports.clearCookies=P.clearCookies;exports.useCookies=P.useCookies;exports.useCounter=ls.useCounter;exports.useDefault=Ss.useDefault;exports.useDisclosure=qs.useDisclosure;exports.useField=ds.useField;exports.useHash=gs.useHash;exports.useList=Es.useList;exports.useLocalStorage=Ts.useLocalStorage;exports.useMap=Ps.useMap;exports.assignRef=t.assignRef;exports.mergeRefs=t.mergeRefs;exports.useMergedRef=t.useMergedRef;exports.useOffsetPagination=Cs.useOffsetPagination;exports.useQueue=Rs.useQueue;exports.useRafState=ms.useRafState;exports.useRefState=ps.useRefState;exports.useSessionStorage=ys.useSessionStorage;exports.useSet=Is.useSet;exports.stateHistoryReducer=C.stateHistoryReducer;exports.useStateHistory=C.useStateHistory;exports.useStep=ks.useStep;exports.STORAGE_EVENT=o.STORAGE_EVENT;exports.dispatchStorageEvent=o.dispatchStorageEvent;exports.useStorage=o.useStorage;exports.useToggle=vs.useToggle;exports.URL_SEARCH_PARAMS_EVENT=u.URL_SEARCH_PARAMS_EVENT;exports.createQueryString=u.createQueryString;exports.dispatchUrlSearchParamsEvent=u.dispatchUrlSearchParamsEvent;exports.getUrlSearchParams=u.getUrlSearchParams;exports.useUrlSearchParam=u.useUrlSearchParam;exports.useUrlSearchParams=Os.useUrlSearchParams;exports.useWizard=hs.useWizard;exports.useInterval=As.useInterval;exports.useStopwatch=fs.useStopwatch;exports.useTime=Ds.useTime;exports.useTimeout=bs.useTimeout;exports.getTimeFromSeconds=R.getTimeFromSeconds;exports.useTimer=R.useTimer;exports.useBrowserLanguage=Ms.useBrowserLanguage;exports.getOperatingSystem=m.getOperatingSystem;exports.useOperatingSystem=m.useOperatingSystem;exports.usePreferredColorScheme=Ls.usePreferredColorScheme;exports.usePreferredContrast=_s.usePreferredContrast;exports.usePreferredDark=Ns.usePreferredDark;exports.usePreferredLanguages=Bs.usePreferredLanguages;exports.usePreferredReducedMotion=Fs.usePreferredReducedMotion;exports.useConst=Ks.useConst;exports.useDebounceCallback=Vs.useDebounceCallback;exports.useDebounceState=Us.useDebounceState;exports.useDebounceValue=ws.useDebounceValue;exports.useEvent=Ws.useEvent;exports.useLastChanged=Hs.useLastChanged;exports.useLatest=xs.useLatest;exports.usePrevious=Qs.usePrevious;exports.useThrottleCallback=zs.useThrottleCallback;exports.useThrottleState=Gs.useThrottleState;exports.useThrottleValue=Xs.useThrottleValue;exports.copy=p.copy;exports.legacyCopyToClipboard=p.legacyCopyToClipboard;exports.debounce=Zs.debounce;exports.getDate=js.getDate;exports.getElement=i.getElement;exports.target=i.target;exports.targetSymbol=i.targetSymbol;exports.getRetry=Js.getRetry;exports.isTarget=Ys.isTarget;exports.throttle=$s.throttle;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useSyncExternalStore as p } from "react";
|
|
2
|
-
const
|
|
2
|
+
const b = (o) => {
|
|
3
3
|
let e;
|
|
4
4
|
const r = /* @__PURE__ */ new Set(), c = (t) => {
|
|
5
5
|
const n = typeof t == "function" ? t(e) : t;
|
|
6
6
|
if (!Object.is(n, e)) {
|
|
7
|
-
const
|
|
8
|
-
e = typeof n != "object" || n === null ? n : Object.assign({}, e, n), r.forEach((
|
|
7
|
+
const a = e;
|
|
8
|
+
e = typeof n != "object" || n === null || Array.isArray(n) ? n : Object.assign({}, e, n), r.forEach((S) => S(e, a));
|
|
9
9
|
}
|
|
10
10
|
}, u = (t) => (r.add(t), () => r.delete(t)), s = () => e, f = () => e;
|
|
11
11
|
typeof o == "function" ? e = o(c, s) : e = o;
|
|
@@ -24,6 +24,6 @@ const g = (o) => {
|
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
export {
|
|
27
|
-
|
|
27
|
+
b as createStore
|
|
28
28
|
};
|
|
29
29
|
//# sourceMappingURL=createStore.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createStore.mjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype StoreSetAction<Value> = ((prev: Value) => Partial<Value>) | Partial<Value>;\n\ntype StoreListener<Value> = (state: Value, prevState: Value) => void;\n\ntype StoreCreator<Value> = (\n set: (action: StoreSetAction<Value>) => void,\n get: () => Value\n) => Value;\n\nexport interface StoreApi<Value> {\n getInitialState: () => Value;\n getState: () => Value;\n setState: (action: StoreSetAction<Value>) => void;\n subscribe: (listener: StoreListener<Value>) => () => void;\n}\n\n/**\n * @name createStore\n * @description - Creates a store with state management capabilities\n * @category Helpers\n * @usage medium\n *\n * @template Value - The type of the store state\n * @param {StateCreator<Value>} createState - Function that initializes the store state\n * @returns {StoreApi<Value>} - Object containing store methods and hook for accessing state\n *\n * @example\n * const { set, get, use, subscribe } = createStore((set) => ({\n * count: 0,\n * increment: () => set(state => ({ count: state.count + 1 }))\n * }));\n */\nexport const createStore = <Value>(createState: StoreCreator<Value> | Value) => {\n let state: Value;\n const listeners: Set<StoreListener<Value>> = new Set();\n\n const setState: StoreApi<Value>['setState'] = (action: StoreSetAction<Value>) => {\n const nextState = typeof action === 'function' ? action(state) : action;\n\n if (!Object.is(nextState, state)) {\n const prevState = state;\n state
|
|
1
|
+
{"version":3,"file":"createStore.mjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype StoreSetAction<Value> = ((prev: Value) => Partial<Value>) | Partial<Value>;\n\ntype StoreListener<Value> = (state: Value, prevState: Value) => void;\n\ntype StoreCreator<Value> = (\n set: (action: StoreSetAction<Value>) => void,\n get: () => Value\n) => Value;\n\nexport interface StoreApi<Value> {\n getInitialState: () => Value;\n getState: () => Value;\n setState: (action: StoreSetAction<Value>) => void;\n subscribe: (listener: StoreListener<Value>) => () => void;\n}\n\n/**\n * @name createStore\n * @description - Creates a store with state management capabilities\n * @category Helpers\n * @usage medium\n *\n * @template Value - The type of the store state\n * @param {StateCreator<Value>} createState - Function that initializes the store state\n * @returns {StoreApi<Value>} - Object containing store methods and hook for accessing state\n *\n * @example\n * const { set, get, use, subscribe } = createStore((set) => ({\n * count: 0,\n * increment: () => set(state => ({ count: state.count + 1 }))\n * }));\n */\nexport const createStore = <Value>(createState: StoreCreator<Value> | Value) => {\n let state: Value;\n const listeners: Set<StoreListener<Value>> = new Set();\n\n const setState: StoreApi<Value>['setState'] = (action: StoreSetAction<Value>) => {\n const nextState = typeof action === 'function' ? action(state) : action;\n\n if (!Object.is(nextState, state)) {\n const prevState = state;\n state = (\n typeof nextState !== 'object' || nextState === null || Array.isArray(nextState)\n ? nextState\n : Object.assign({}, state, nextState)\n ) as Value;\n\n listeners.forEach((listener) => listener(state, prevState));\n }\n };\n\n const subscribe = (listener: StoreListener<Value>) => {\n listeners.add(listener);\n\n return () => listeners.delete(listener);\n };\n\n const getState = () => state;\n const getInitialState = () => state;\n\n if (typeof createState === 'function') {\n state = (createState as StoreCreator<Value>)(setState, getState);\n } else {\n state = createState;\n }\n\n function useStore(): Value;\n function useStore<Selected>(selector: (state: Value) => Selected): Selected;\n function useStore<Selected>(selector?: (state: Value) => Selected): Selected | Value {\n return useSyncExternalStore(\n subscribe,\n () => (selector ? selector(getState()) : getState()),\n () => (selector ? selector(getInitialState()) : getInitialState())\n );\n }\n\n return {\n set: setState,\n get: getState,\n use: useStore,\n subscribe\n };\n};\n"],"names":["createStore","createState","state","listeners","setState","action","nextState","prevState","listener","subscribe","getState","getInitialState","useStore","selector","useSyncExternalStore"],"mappings":";AAkCO,MAAMA,IAAc,CAAQC,MAA6C;AAC9E,MAAIC;AACJ,QAAMC,wBAA2C,IAAA,GAE3CC,IAAwC,CAACC,MAAkC;AAC/E,UAAMC,IAAY,OAAOD,KAAW,aAAaA,EAAOH,CAAK,IAAIG;AAEjE,QAAI,CAAC,OAAO,GAAGC,GAAWJ,CAAK,GAAG;AAChC,YAAMK,IAAYL;AAClB,MAAAA,IACE,OAAOI,KAAc,YAAYA,MAAc,QAAQ,MAAM,QAAQA,CAAS,IAC1EA,IACA,OAAO,OAAO,CAAA,GAAIJ,GAAOI,CAAS,GAGxCH,EAAU,QAAQ,CAACK,MAAaA,EAASN,GAAOK,CAAS,CAAC;AAAA,IAAA;AAAA,EAC5D,GAGIE,IAAY,CAACD,OACjBL,EAAU,IAAIK,CAAQ,GAEf,MAAML,EAAU,OAAOK,CAAQ,IAGlCE,IAAW,MAAMR,GACjBS,IAAkB,MAAMT;AAE9B,EAAI,OAAOD,KAAgB,aACzBC,IAASD,EAAoCG,GAAUM,CAAQ,IAE/DR,IAAQD;AAKV,WAASW,EAAmBC,GAAyD;AACnF,WAAOC;AAAA,MACLL;AAAA,MACA,MAAOI,IAAWA,EAASH,EAAA,CAAU,IAAIA,EAAA;AAAA,MACzC,MAAOG,IAAWA,EAASF,EAAA,CAAiB,IAAIA,EAAA;AAAA,IAAgB;AAAA,EAClE;AAGF,SAAO;AAAA,IACL,KAAKP;AAAA,IACL,KAAKM;AAAA,IACL,KAAKE;AAAA,IACL,WAAAH;AAAA,EAAA;AAEJ;"}
|
|
@@ -2,12 +2,10 @@ import { useState as a, useEffect as l } from "react";
|
|
|
2
2
|
import { useRefState as v } from "../useRefState/useRefState.mjs";
|
|
3
3
|
import { isTarget as d } from "../../utils/helpers/isTarget.mjs";
|
|
4
4
|
import { getElement as E } from "../../utils/helpers/getElement.mjs";
|
|
5
|
-
const p = (...
|
|
6
|
-
const r = d(
|
|
5
|
+
const p = (...s) => {
|
|
6
|
+
const r = d(s[0]) ? s[0] : void 0, [u, i] = a(null), o = v();
|
|
7
7
|
return l(() => {
|
|
8
|
-
const e = r ? E(r) : o.current
|
|
9
|
-
if (!e) return;
|
|
10
|
-
const c = new MutationObserver((f) => {
|
|
8
|
+
const e = (r ? E(r) : o.current) ?? window, c = new MutationObserver((f) => {
|
|
11
9
|
f.filter((t) => t.removedNodes.length).map((t) => Array.from(t.removedNodes)).flat().forEach((t) => {
|
|
12
10
|
i((m) => t === m ? document.activeElement : m);
|
|
13
11
|
});
|
|
@@ -20,9 +18,9 @@ const p = (...u) => {
|
|
|
20
18
|
return e.addEventListener("focus", n, !0), e.addEventListener("blur", n, !0), () => {
|
|
21
19
|
c.disconnect(), e.removeEventListener("focus", n, !0), e.removeEventListener("blur", n, !0);
|
|
22
20
|
};
|
|
23
|
-
}, [r, o.state]), r ?
|
|
21
|
+
}, [r, o.state]), r ? u : {
|
|
24
22
|
ref: o,
|
|
25
|
-
value:
|
|
23
|
+
value: u
|
|
26
24
|
};
|
|
27
25
|
};
|
|
28
26
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActiveElement.mjs","sources":["../../../../src/hooks/useActiveElement/useActiveElement.ts"],"sourcesContent":["import { useEffect, useState } from
|
|
1
|
+
{"version":3,"file":"useActiveElement.mjs","sources":["../../../../src/hooks/useActiveElement/useActiveElement.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\n\nimport type { HookTarget } from \"@/utils/helpers\";\n\nimport { getElement, isTarget } from \"@/utils/helpers\";\n\nimport type { StateRef } from \"../useRefState/useRefState\";\n\nimport { useRefState } from \"../useRefState/useRefState\";\n\n/** The use active element return type */\nexport type UseActiveElementReturn<\n ActiveElement extends HTMLElement = HTMLElement\n> = ActiveElement | null;\n\nexport interface UseActiveElement {\n (): UseActiveElementReturn;\n\n <Target extends Element, ActiveElement extends HTMLElement = HTMLElement>(\n target?: never\n ): {\n ref: StateRef<Target>;\n value: UseActiveElementReturn<ActiveElement>;\n };\n\n <ActiveElement extends HTMLElement = HTMLElement>(\n target: HookTarget\n ): UseActiveElementReturn<ActiveElement>;\n}\n\n/**\n * @name useActiveElement\n * @description - Hook that returns the active element\n * @category Elements\n * @usage low\n *\n * @overload\n * @param {HookTarget} [target=window] The target element to observe active element changes\n * @returns {ActiveElement | null} The active element\n *\n * @example\n * const activeElement = useActiveElement(ref);\n *\n * @overload\n * @template ActiveElement The active element type\n * @returns {{ ref: StateRef<Element>; activeElement: ActiveElement | null }} An object containing the ref and active element\n *\n * @example\n * const { ref, value } = useActiveElement();\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useActiveElement.html}\n */\nexport const useActiveElement = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as\n | HookTarget\n | undefined;\n\n const [value, setValue] = useState<HTMLElement | null>(null);\n const internalRef = useRefState();\n\n useEffect(() => {\n const element = ((target ? getElement(target) : internalRef.current) ??\n window) as Element;\n\n const observer = new MutationObserver((mutations) => {\n mutations\n .filter((mutation) => mutation.removedNodes.length)\n .map((mutation) => Array.from(mutation.removedNodes))\n .flat()\n .forEach((node) => {\n setValue((prevActiveElement) => {\n if (node === prevActiveElement)\n return document.activeElement as HTMLElement | null;\n return prevActiveElement;\n });\n });\n });\n\n observer.observe(element, {\n childList: true,\n subtree: true,\n });\n\n const onActiveElementChange = () =>\n setValue(document?.activeElement as HTMLElement | null);\n\n element.addEventListener(\"focus\", onActiveElementChange, true);\n element.addEventListener(\"blur\", onActiveElementChange, true);\n\n return () => {\n observer.disconnect();\n element.removeEventListener(\"focus\", onActiveElementChange, true);\n element.removeEventListener(\"blur\", onActiveElementChange, true);\n };\n }, [target, internalRef.state]);\n\n if (target) return value;\n return {\n ref: internalRef,\n value,\n };\n}) as UseActiveElement;\n"],"names":["useActiveElement","params","target","isTarget","value","setValue","useState","internalRef","useRefState","useEffect","element","getElement","observer","mutations","mutation","node","prevActiveElement","onActiveElementChange"],"mappings":";;;;AAoDO,MAAMA,IAAoB,IAAIC,MAAkB;AACrD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAI5C,CAACG,GAAOC,CAAQ,IAAIC,EAA6B,IAAI,GACrDC,IAAcC,EAAA;AAsCpB,SApCAC,EAAU,MAAM;AACd,UAAMC,KAAYR,IAASS,EAAWT,CAAM,IAAIK,EAAY,YAC1D,QAEIK,IAAW,IAAI,iBAAiB,CAACC,MAAc;AACnD,MAAAA,EACG,OAAO,CAACC,MAAaA,EAAS,aAAa,MAAM,EACjD,IAAI,CAACA,MAAa,MAAM,KAAKA,EAAS,YAAY,CAAC,EACnD,OACA,QAAQ,CAACC,MAAS;AACjB,QAAAV,EAAS,CAACW,MACJD,MAASC,IACJ,SAAS,gBACXA,CACR;AAAA,MAAA,CACF;AAAA,IAAA,CACJ;AAED,IAAAJ,EAAS,QAAQF,GAAS;AAAA,MACxB,WAAW;AAAA,MACX,SAAS;AAAA,IAAA,CACV;AAED,UAAMO,IAAwB,MAC5BZ,EAAS,UAAU,aAAmC;AAExD,WAAAK,EAAQ,iBAAiB,SAASO,GAAuB,EAAI,GAC7DP,EAAQ,iBAAiB,QAAQO,GAAuB,EAAI,GAErD,MAAM;AACX,MAAAL,EAAS,WAAA,GACTF,EAAQ,oBAAoB,SAASO,GAAuB,EAAI,GAChEP,EAAQ,oBAAoB,QAAQO,GAAuB,EAAI;AAAA,IAAA;AAAA,EACjE,GACC,CAACf,GAAQK,EAAY,KAAK,CAAC,GAE1BL,IAAeE,IACZ;AAAA,IACL,KAAKG;AAAA,IACL,OAAAH;AAAA,EAAA;AAEJ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAsyncEffect.mjs","sources":["../../../../src/hooks/useAsyncEffect/useAsyncEffect.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\n\n/**\n * @name useAsyncEffect\n * @description – Hook that triggers the effect callback on updates\n * @category Lifecycle\n * @usage medium\n\n * @param {EffectCallback} effect The effect callback\n * @param {DependencyList} [deps] The dependencies list for the effect\n *\n * @example\n * useAsyncEffect(async () => console.log(\"effect runs on updates\"), deps);\n */\nexport const useAsyncEffect = (сallback: () => Promise<any>, deps?: DependencyList): void => {\n useIsomorphicLayoutEffect(() => {\n сallback();\n }, deps);\n};\n"],"names":["useAsyncEffect","сallback","deps","useIsomorphicLayoutEffect"],"mappings":";AAgBO,MAAMA,IAAiB,CAACC,GAA8BC,MAAgC;AAC3F,EAAAC,EAA0B,MAAM;AAC9B,IAAAF,EAAA;AAAA,EAAS,GACRC,CAAI;AACT;"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useState as h } from "react";
|
|
2
|
+
import { useIsomorphicLayoutEffect as p } from "../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
|
|
3
|
+
import { useRefState as v } from "../useRefState/useRefState.mjs";
|
|
4
|
+
import { isTarget as g } from "../../utils/helpers/isTarget.mjs";
|
|
5
|
+
import { getElement as S } from "../../utils/helpers/getElement.mjs";
|
|
6
|
+
const L = [
|
|
7
|
+
"input:not([disabled])",
|
|
8
|
+
"select:not([disabled])",
|
|
9
|
+
"textarea:not([disabled])",
|
|
10
|
+
"button:not([disabled])",
|
|
11
|
+
"a[href]",
|
|
12
|
+
"area[href]",
|
|
13
|
+
"summary",
|
|
14
|
+
"iframe",
|
|
15
|
+
"object",
|
|
16
|
+
"embed",
|
|
17
|
+
"audio[controls]",
|
|
18
|
+
"video[controls]",
|
|
19
|
+
"[contenteditable]",
|
|
20
|
+
'[tabindex]:not([tabindex^="-"])'
|
|
21
|
+
].join(","), y = (e) => Array.from(
|
|
22
|
+
e.querySelectorAll(L)
|
|
23
|
+
).filter((o) => {
|
|
24
|
+
const n = o;
|
|
25
|
+
return n.tabIndex !== -1 && !n.hidden && n.style.display !== "none";
|
|
26
|
+
}), x = (e) => {
|
|
27
|
+
const t = e.querySelector(
|
|
28
|
+
"[data-autofocus]"
|
|
29
|
+
);
|
|
30
|
+
if (t) return t.focus();
|
|
31
|
+
const o = y(e);
|
|
32
|
+
o.length > 0 && o[0].focus();
|
|
33
|
+
}, F = (...e) => {
|
|
34
|
+
const t = g(e[0]) ? e[0] : void 0, o = t ? e[1] : e[0], [n, c] = h(o), i = v(), l = () => c(!0), u = () => c(!1), a = () => c((r) => !r);
|
|
35
|
+
return p(() => {
|
|
36
|
+
if (!n) return;
|
|
37
|
+
const r = t ? S(t) : i.current;
|
|
38
|
+
if (!r) return;
|
|
39
|
+
const f = r;
|
|
40
|
+
x(f);
|
|
41
|
+
const m = (s) => {
|
|
42
|
+
if (s.key !== "Tab") return;
|
|
43
|
+
const [d, ...E] = y(f);
|
|
44
|
+
if (!E.length) return;
|
|
45
|
+
const b = E.at(-1);
|
|
46
|
+
s.shiftKey && document.activeElement === d && (s.preventDefault(), b.focus()), document.activeElement === b && (s.preventDefault(), d.focus());
|
|
47
|
+
};
|
|
48
|
+
return document.addEventListener("keydown", m), () => {
|
|
49
|
+
document.removeEventListener("keydown", m);
|
|
50
|
+
};
|
|
51
|
+
}, [n, t, i.state]), t ? { active: n, enable: l, disable: u, toggle: a } : { active: n, enable: l, disable: u, toggle: a, ref: i };
|
|
52
|
+
};
|
|
53
|
+
export {
|
|
54
|
+
F as useFocusTrap
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=useFocusTrap.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFocusTrap.mjs","sources":["../../../../src/hooks/useFocusTrap/useFocusTrap.ts"],"sourcesContent":["import { useState } from \"react\";\n\nimport type { HookTarget } from \"@/utils/helpers\";\n\nimport { getElement, isTarget } from \"@/utils/helpers\";\n\nimport type { StateRef } from \"../useRefState/useRefState\";\n\nimport { useIsomorphicLayoutEffect } from \"../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect\";\nimport { useRefState } from \"../useRefState/useRefState\";\n\nconst FOCUSABLE_ELEMENTS_SELECTOR = [\n \"input:not([disabled])\",\n \"select:not([disabled])\",\n \"textarea:not([disabled])\",\n \"button:not([disabled])\",\n \"a[href]\",\n \"area[href]\",\n \"summary\",\n \"iframe\",\n \"object\",\n \"embed\",\n \"audio[controls]\",\n \"video[controls]\",\n \"[contenteditable]\",\n '[tabindex]:not([tabindex^=\"-\"])',\n].join(\",\");\n\nconst getFocusableElements = (element: HTMLElement): HTMLElement[] => {\n const elements = Array.from(\n element.querySelectorAll(FOCUSABLE_ELEMENTS_SELECTOR)\n );\n return elements.filter((el) => {\n const htmlEl = el as HTMLElement;\n return (\n htmlEl.tabIndex !== -1 &&\n !htmlEl.hidden &&\n htmlEl.style.display !== \"none\"\n );\n }) as HTMLElement[];\n};\n\nconst focusElement = (element: HTMLElement) => {\n const autofocusElement = element.querySelector(\n \"[data-autofocus]\"\n ) as HTMLElement;\n if (autofocusElement) return autofocusElement.focus();\n\n const focusableElements = getFocusableElements(element);\n if (focusableElements.length > 0) {\n focusableElements[0].focus();\n }\n};\n\n/** The use focus trap return type */\nexport interface UseFocusTrapReturn {\n /** Whether focus trap is active */\n active: boolean;\n /** Disable focus trap */\n disable: () => void;\n /** Enable focus trap */\n enable: () => void;\n /** Toggle focus trap */\n toggle: () => void;\n}\n\nexport interface UseFocusTrap {\n (target: HookTarget, active?: boolean): UseFocusTrapReturn;\n\n <Target extends HTMLElement>(\n active?: boolean,\n target?: never\n ): UseFocusTrapReturn & {\n ref: StateRef<Target>;\n };\n}\n\n/**\n * @name useFocusTrap\n * @description - Hook that traps focus within a given element\n * @category Elements\n * @usage medium\n *\n * @overload\n * @param {HookTarget} target The target element for focus trap\n * @param {boolean} [active=true] Whether focus trap is active\n * @returns {UseFocusTrapReturn} Object with control methods and state\n *\n * @example\n * const { active, disable, toggle, enable } = useFocusTrap(ref, true);\n *\n * @overload\n * @template Target The target element type\n * @param {boolean} [active=true] Whether focus trap is active\n * @returns {UseFocusTrapReturn & { ref: StateRef<Target> }} Object with ref and controls\n *\n * @example\n * const { ref, active, disable, toggle, enable } = useFocusTrap(true);\n */\nexport const useFocusTrap = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as\n | HookTarget\n | undefined;\n const initialActive = target ? params[1] : params[0];\n\n const [active, setActive] = useState(initialActive);\n const internalRef = useRefState<HTMLElement>();\n\n const enable = () => setActive(true);\n const disable = () => setActive(false);\n const toggle = () => setActive((prevActive: boolean) => !prevActive);\n\n useIsomorphicLayoutEffect(() => {\n if (!active) return;\n\n const element = target ? getElement(target) : internalRef.current;\n if (!element) return;\n\n const htmlElement = element as HTMLElement;\n focusElement(htmlElement);\n\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key !== \"Tab\") return;\n\n const [firstElement, ...restElements] = getFocusableElements(htmlElement);\n if (!restElements.length) return;\n\n const lastElement = restElements.at(-1)!;\n\n if (event.shiftKey && document.activeElement === firstElement) {\n event.preventDefault();\n lastElement.focus();\n }\n\n if (document.activeElement === lastElement) {\n event.preventDefault();\n firstElement.focus();\n }\n };\n\n document.addEventListener(\"keydown\", onKeyDown);\n\n return () => {\n document.removeEventListener(\"keydown\", onKeyDown);\n };\n }, [active, target, internalRef.state]);\n\n if (target) return { active, enable, disable, toggle };\n return { active, enable, disable, toggle, ref: internalRef };\n}) as UseFocusTrap;\n"],"names":["FOCUSABLE_ELEMENTS_SELECTOR","getFocusableElements","element","el","htmlEl","focusElement","autofocusElement","focusableElements","useFocusTrap","params","target","isTarget","initialActive","active","setActive","useState","internalRef","useRefState","enable","disable","toggle","prevActive","useIsomorphicLayoutEffect","getElement","htmlElement","onKeyDown","event","firstElement","restElements","lastElement"],"mappings":";;;;;AAWA,MAAMA,IAA8B;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,EAAE,KAAK,GAAG,GAEJC,IAAuB,CAACC,MACX,MAAM;AAAA,EACrBA,EAAQ,iBAAiBF,CAA2B;AAAA,EAEtC,OAAO,CAACG,MAAO;AAC7B,QAAMC,IAASD;AACf,SACEC,EAAO,aAAa,MACpB,CAACA,EAAO,UACRA,EAAO,MAAM,YAAY;AAAA,CAE5B,GAGGC,IAAe,CAACH,MAAyB;AAC7C,QAAMI,IAAmBJ,EAAQ;AAAA,IAC/B;AAAA,EAAA;AAEF,MAAII,EAAkB,QAAOA,EAAiB,MAAA;AAE9C,QAAMC,IAAoBN,EAAqBC,CAAO;AACtD,EAAIK,EAAkB,SAAS,KAC7BA,EAAkB,CAAC,EAAE,MAAA;AAEzB,GA+CaC,IAAgB,IAAIC,MAAkB;AACjD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAG5CG,IAAgBF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GAE7C,CAACI,GAAQC,CAAS,IAAIC,EAASH,CAAa,GAC5CI,IAAcC,EAAA,GAEdC,IAAS,MAAMJ,EAAU,EAAI,GAC7BK,IAAU,MAAML,EAAU,EAAK,GAC/BM,IAAS,MAAMN,EAAU,CAACO,MAAwB,CAACA,CAAU;AAqCnE,SAnCAC,EAA0B,MAAM;AAC9B,QAAI,CAACT,EAAQ;AAEb,UAAMX,IAAUQ,IAASa,EAAWb,CAAM,IAAIM,EAAY;AAC1D,QAAI,CAACd,EAAS;AAEd,UAAMsB,IAActB;AACpB,IAAAG,EAAamB,CAAW;AAExB,UAAMC,IAAY,CAACC,MAAyB;AAC1C,UAAIA,EAAM,QAAQ,MAAO;AAEzB,YAAM,CAACC,GAAc,GAAGC,CAAY,IAAI3B,EAAqBuB,CAAW;AACxE,UAAI,CAACI,EAAa,OAAQ;AAE1B,YAAMC,IAAcD,EAAa,GAAG,EAAE;AAEtC,MAAIF,EAAM,YAAY,SAAS,kBAAkBC,MAC/CD,EAAM,eAAA,GACNG,EAAY,MAAA,IAGV,SAAS,kBAAkBA,MAC7BH,EAAM,eAAA,GACNC,EAAa,MAAA;AAAA,IACf;AAGF,oBAAS,iBAAiB,WAAWF,CAAS,GAEvC,MAAM;AACX,eAAS,oBAAoB,WAAWA,CAAS;AAAA,IAAA;AAAA,EACnD,GACC,CAACZ,GAAQH,GAAQM,EAAY,KAAK,CAAC,GAElCN,IAAe,EAAE,QAAAG,GAAQ,QAAAK,GAAQ,SAAAC,GAAS,QAAAC,EAAA,IACvC,EAAE,QAAAP,GAAQ,QAAAK,GAAQ,SAAAC,GAAS,QAAAC,GAAQ,KAAKJ,EAAA;AACjD;"}
|