@siberiacancode/reactuse 0.2.5 → 0.2.7
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 +66 -7
- package/dist/cjs/hooks/useAsync/useAsync.cjs.map +1 -1
- package/dist/cjs/hooks/useDropZone/useDropZone.cjs.map +1 -1
- package/dist/cjs/hooks/useShare/useShare.cjs.map +1 -1
- package/dist/cjs/hooks/useStep/useStep.cjs.map +1 -1
- package/dist/cjs/hooks/useStorage/useStorage.cjs +1 -1
- package/dist/cjs/hooks/useStorage/useStorage.cjs.map +1 -1
- package/dist/esm/hooks/useAsync/useAsync.mjs.map +1 -1
- package/dist/esm/hooks/useDropZone/useDropZone.mjs.map +1 -1
- package/dist/esm/hooks/useShare/useShare.mjs.map +1 -1
- package/dist/esm/hooks/useStep/useStep.mjs.map +1 -1
- package/dist/esm/hooks/useStorage/useStorage.mjs +36 -32
- package/dist/esm/hooks/useStorage/useStorage.mjs.map +1 -1
- package/dist/types/hooks/useAsync/useAsync.d.ts +3 -3
- package/dist/types/hooks/useDropZone/useDropZone.d.ts +4 -4
- package/dist/types/hooks/useLocalStorage/useLocalStorage.d.ts +1 -5
- package/dist/types/hooks/useSessionStorage/useSessionStorage.d.ts +1 -5
- package/dist/types/hooks/useShare/useShare.d.ts +2 -0
- package/dist/types/hooks/useStep/useStep.d.ts +2 -3
- package/dist/types/hooks/useStorage/useStorage.d.ts +9 -5
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,12 +1,71 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://reactuse.dev">
|
|
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>
|
|
2
8
|
|
|
3
|
-
|
|
9
|
+
<a href="https://www.npmjs.com/package/@siberiacancode/reactuse"><img alt="NPM version" src="https://img.shields.io/npm/v/@reactuses/core.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/@reactuses/core.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>
|
|
4
12
|
|
|
5
|
-
|
|
13
|
+
</div>
|
|
6
14
|
|
|
7
|
-
|
|
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.
|
|
8
16
|
|
|
9
|
-
##
|
|
17
|
+
## Documentation
|
|
10
18
|
|
|
11
|
-
|
|
12
|
-
|
|
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 '@reactuses/core';
|
|
29
|
+
|
|
30
|
+
function App() {
|
|
31
|
+
const counter = useCounter(0);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div>
|
|
35
|
+
<h1>Count: {const.value}</h1>
|
|
36
|
+
<button onClick={() => const.inc()}>+1</button>
|
|
37
|
+
<button onClick={() => const.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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAsync.cjs","sources":["../../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/* The use query return type */\nexport interface UseAsyncReturn<Data> {\n /* The state of the query */\n data?: Data;\n /* The error of the query */\n error?: Error;\n /* The error state of the query */\n isError: boolean;\n /* The loading state of the query */\n isLoading: boolean;\n}\n\n/**\n * @name useAsync\n * @description - Hook that provides the state of an async callback\n * @category Utilities\n *\n * @param {() => Promise<Data>} callback
|
|
1
|
+
{"version":3,"file":"useAsync.cjs","sources":["../../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/* The use query return type */\nexport interface UseAsyncReturn<Data> {\n /* The state of the query */\n data?: Data;\n /* The error of the query */\n error?: Error;\n /* The error state of the query */\n isError: boolean;\n /* The loading state of the query */\n isLoading: boolean;\n}\n\n/**\n * @name useAsync\n * @description - Hook that provides the state of an async callback\n * @category Utilities\n *\n * @param {() => Promise<Data>} callback The async callback\n * @param {DependencyList} deps The dependencies of the callback\n * @returns {UseAsyncReturn<Data>} The state of the async callback\n *\n * @example\n * const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);\n */\nexport const useAsync = <Data>(\n callback: () => Promise<Data>,\n deps: DependencyList\n): UseAsyncReturn<Data> => {\n const [isLoading, setIsLoading] = useState(true);\n const [isError, setIsError] = useState(false);\n\n const [error, setError] = useState<Error | undefined>(undefined);\n const [data, setData] = useState<Data | undefined>(undefined);\n\n useEffect(() => {\n setIsLoading(true);\n callback()\n .then((response) => {\n setData(response);\n setError(undefined);\n setIsError(false);\n })\n .catch((error: Error) => {\n setError(error);\n setIsError(true);\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, deps);\n\n return {\n data,\n isLoading,\n isError,\n error\n };\n};\n"],"names":["useAsync","callback","deps","isLoading","setIsLoading","useState","isError","setIsError","error","setError","data","setData","useEffect","response"],"mappings":"yGA4BaA,EAAW,CACtBC,EACAC,IACyB,CACzB,KAAM,CAACC,EAAWC,CAAY,EAAIC,EAAAA,SAAS,EAAI,EACzC,CAACC,EAASC,CAAU,EAAIF,EAAAA,SAAS,EAAK,EAEtC,CAACG,EAAOC,CAAQ,EAAIJ,EAAAA,SAA4B,MAAS,EACzD,CAACK,EAAMC,CAAO,EAAIN,EAAAA,SAA2B,MAAS,EAE5DO,OAAAA,EAAAA,UAAU,IAAM,CACdR,EAAa,EAAI,EACRH,EAAA,EACN,KAAMY,GAAa,CAClBF,EAAQE,CAAQ,EAChBJ,EAAS,MAAS,EAClBF,EAAW,EAAK,CAAA,CACjB,EACA,MAAOC,GAAiB,CACvBC,EAASD,CAAK,EACdD,EAAW,EAAI,CAAA,CAChB,EACA,QAAQ,IAAM,CACbH,EAAa,EAAK,CAAA,CACnB,GACFF,CAAI,EAEA,CACL,KAAAQ,EACA,UAAAP,EACA,QAAAG,EACA,MAAAE,CACF,CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDropZone.cjs","sources":["../../../../src/hooks/useDropZone/useDropZone.ts"],"sourcesContent":["import { useEffect, useRef, 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\nexport type DropZoneDataTypes = ((types: string[]) => boolean) | string[];\n\nexport interface UseDropZoneOptions {\n /** The data types for drop zone */\n dataTypes?: DropZoneDataTypes;\n /** The multiple mode for drop zone */\n multiple?: boolean;\n /** The on drop callback */\n onDrop?: (files: File[] | null, event: DragEvent) => void;\n /** The on enter callback */\n onEnter?: (event: DragEvent) => void;\n /** The on leave callback */\n onLeave?: (event: DragEvent) => void;\n /** The on over callback */\n onOver?: (event: DragEvent) => void;\n}\n\nexport interface UseDropZoneReturn {\n /** The files that was dropped in drop zone */\n files: File[] | null;\n /** The over drop zone status */\n overed: boolean;\n}\n\nexport interface UseDropZone {\n (\n target: HookTarget,\n callback?: (files: File[] | null, event: DragEvent) => void\n ): UseDropZoneReturn;\n\n <Target extends Element>(\n callback?: (files: File[] | null, event: DragEvent) => void,\n target?: never\n ): UseDropZoneReturn & {\n ref: StateRef<Target>;\n };\n\n (target: HookTarget, options?: UseDropZoneOptions): UseDropZoneReturn;\n\n <Target extends Element>(\n options?: UseDropZoneOptions,\n target?: never\n ): UseDropZoneReturn & {\n ref: StateRef<Target>;\n };\n}\n\n/**\n * @name useDropZone\n * @description - Hook that provides drop zone functionality\n * @category Elements\n *\n * @overload\n * @template Target The target element\n * @param {Target} target The target element drop zone's\n * @param {DataTypes} [options.dataTypes] The data types\n * @param {boolean} [options.multiple] The multiple mode\n * @param {(files: File[] | null, event: DragEvent) => void} [options.onDrop] The on drop callback function\n * @param {(event: DragEvent) => void} [options.onEnter] The on enter callback function\n * @param {(event: DragEvent) => void} [options.onLeave] The on leave callback function\n * @param {(event: DragEvent) => void} [options.onOver] The on over callback function\n * @returns {[boolean, File[] | null]} The object with drop zone states\n *\n * @example\n * const { overed, files } = useDropZone(ref, options);\n *\n * @overload\n * @param {Target} target The target element drop zone's\n * @param {(files: File[] | null, event: DragEvent) => void} [callback] The callback function to be invoked on drop\n * @returns {[boolean, File[] | null]} The object with drop zone states\n *\n * @example\n * const { overed, files } = useDropZone(ref, () => console.log('callback'));\n *\n * @overload\n * @param {DataTypes} [options.dataTypes] The data types\n * @param {boolean} [options.multiple] The multiple mode\n * @param {(files: File[] | null, event: DragEvent) => void} [options.onDrop] The on drop callback function\n * @param {(event: DragEvent) => void} [options.onEnter] The on enter callback function\n * @param {(event: DragEvent) => void} [options.onLeave] The on leave callback function\n * @param {(event: DragEvent) => void} [options.onOver] The on over callback function\n * @returns {[StateRef<Target>, boolean, File[] | null]} The object with drop zone states and ref\n *\n * @example\n * const { ref, overed, files } = useDropZone(options);\n *\n * @overload\n * @param {(files: File[] | null, event: DragEvent) => void} [callback] The callback function to be invoked on drop\n * @returns {[StateRef<Target>, boolean, File[] | null]} The object with drop zone states and ref\n *\n * @example\n * const { ref, overed, files } = useDropZone(() => console.log('callback'));\n */\n\nexport const useDropZone = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n\n const options = (\n target\n ? typeof params[1] === 'object'\n ? params[1]\n : { onDrop: params[1] }\n : typeof params[0] === 'object'\n ? params[0]\n : { onDrop: params[0] }\n ) as UseDropZoneOptions;\n\n const internalRef = useRefState<Element>();\n\n const counterRef = useRef(0);\n const [files, setFiles] = useState<File[] | null>(null);\n const [overed, setOvered] = useState(false);\n\n const dataTypes = options.dataTypes;\n\n const getFiles = (event: DragEvent) => {\n if (!event.dataTransfer) return null;\n const list = Array.from(event.dataTransfer.files);\n if (options.multiple) return list;\n if (!list.length) return null;\n return [list[0]];\n };\n\n const checkDataTypes = (types: string[]) => {\n if (!dataTypes) return true;\n if (typeof dataTypes === 'function') return dataTypes(types);\n if (!dataTypes.length) return true;\n if (!types.length) return false;\n\n return types.every((type) => {\n console.log('type', type);\n console.log('dataTypes', dataTypes);\n return dataTypes.some((dataType) => type.includes(dataType));\n });\n };\n\n const checkValidity = (items: DataTransferItemList) => {\n const types = Array.from(items).map((item) => item.type);\n const dataTypesValid = checkDataTypes(types);\n const multipleFilesValid = options.multiple || items.length <= 1;\n\n return dataTypesValid && multipleFilesValid;\n };\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = target ? getElement(target) : internalRef.current;\n\n if (!element) return;\n\n const onEvent = (event: DragEvent, type: 'drop' | 'enter' | 'leave' | 'over') => {\n if (!event.dataTransfer) return;\n\n const isValid = checkValidity(event.dataTransfer.items);\n if (!isValid) {\n event.dataTransfer.dropEffect = 'none';\n return;\n }\n\n event.preventDefault();\n event.dataTransfer.dropEffect = 'copy';\n\n const currentFiles = getFiles(event);\n\n if (type === 'drop') {\n counterRef.current = 0;\n setOvered(false);\n setFiles(currentFiles);\n options.onDrop?.(currentFiles, event);\n return;\n }\n\n if (type === 'enter') {\n counterRef.current += 1;\n setOvered(true);\n options.onEnter?.(event);\n return;\n }\n\n if (type === 'leave') {\n counterRef.current -= 1;\n if (counterRef.current !== 0) return;\n setOvered(false);\n options.onLeave?.(event);\n return;\n }\n\n if (type === 'over') options.onOver?.(event);\n };\n\n const onDrop = ((event: DragEvent) => onEvent(event, 'drop')) as EventListener;\n const onDragOver = ((event: DragEvent) => onEvent(event, 'over')) as EventListener;\n const onDragEnter = ((event: DragEvent) => onEvent(event, 'enter')) as EventListener;\n const onDragLeave = ((event: DragEvent) => onEvent(event, 'leave')) as EventListener;\n\n element.addEventListener('dragenter', onDragEnter);\n element.addEventListener('dragover', onDragOver);\n element.addEventListener('dragleave', onDragLeave);\n element.addEventListener('drop', onDrop);\n\n return () => {\n element.removeEventListener('dragenter', onDragEnter);\n element.removeEventListener('dragover', onDragOver);\n element.removeEventListener('dragleave', onDragLeave);\n element.removeEventListener('drop', onDrop);\n };\n }, [target, internalRef.current]);\n\n if (target) return { overed, files };\n return { ref: internalRef, overed, files };\n}) as UseDropZone;\n"],"names":["useDropZone","params","target","isTarget","options","internalRef","useRefState","counterRef","useRef","files","setFiles","useState","overed","setOvered","dataTypes","getFiles","event","list","checkDataTypes","types","type","dataType","checkValidity","items","item","dataTypesValid","multipleFilesValid","useEffect","element","getElement","onEvent","currentFiles","_a","_b","_c","_d","onDrop","onDragOver","onDragEnter","onDragLeave"],"mappings":"mPAwGaA,EAAe,IAAIC,IAAkB,CAC1C,MAAAC,EAAUC,WAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAE5CG,EACJF,EACI,OAAOD,EAAO,CAAC,GAAM,SACnBA,EAAO,CAAC,EACR,CAAE,OAAQA,EAAO,CAAC,CAAE,EACtB,OAAOA,EAAO,CAAC,GAAM,SACnBA,EAAO,CAAC,EACR,CAAE,OAAQA,EAAO,CAAC,CAAE,EAGtBI,EAAcC,EAAAA,YAAqB,EAEnCC,EAAaC,SAAO,CAAC,EACrB,CAACC,EAAOC,CAAQ,EAAIC,EAAAA,SAAwB,IAAI,EAChD,CAACC,EAAQC,CAAS,EAAIF,EAAAA,SAAS,EAAK,EAEpCG,EAAYV,EAAQ,UAEpBW,EAAYC,GAAqB,CACjC,GAAA,CAACA,EAAM,aAAqB,OAAA,KAChC,MAAMC,EAAO,MAAM,KAAKD,EAAM,aAAa,KAAK,EAC5C,OAAAZ,EAAQ,SAAiBa,EACxBA,EAAK,OACH,CAACA,EAAK,CAAC,CAAC,EADU,IAE3B,EAEMC,EAAkBC,GACjBL,EACD,OAAOA,GAAc,WAAmBA,EAAUK,CAAK,EACtDL,EAAU,OACVK,EAAM,OAEJA,EAAM,MAAOC,IACV,QAAA,IAAI,OAAQA,CAAI,EAChB,QAAA,IAAI,YAAaN,CAAS,EAC3BA,EAAU,KAAMO,GAAaD,EAAK,SAASC,CAAQ,CAAC,EAC5D,EANyB,GADI,GAFP,GAYnBC,EAAiBC,GAAgC,CAC/C,MAAAJ,EAAQ,MAAM,KAAKI,CAAK,EAAE,IAAKC,GAASA,EAAK,IAAI,EACjDC,EAAiB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Y,EAAA,iBAAiB,YAAaU,CAAW,EACzCV,EAAA,iBAAiB,WAAYS,CAAU,EACvCT,EAAA,iBAAiB,YAAaW,CAAW,EACzCX,EAAA,iBAAiB,OAAQQ,CAAM,EAEhC,IAAM,CACHR,EAAA,oBAAoB,YAAaU,CAAW,EAC5CV,EAAA,oBAAoB,WAAYS,CAAU,EAC1CT,EAAA,oBAAoB,YAAaW,CAAW,EAC5CX,EAAA,oBAAoB,OAAQQ,CAAM,CAC5C,CACC,EAAA,CAAClC,EAAQG,EAAY,OAAO,CAAC,EAE5BH,EAAe,CAAE,OAAAU,EAAQ,MAAAH,CAAM,EAC5B,CAAE,IAAKJ,EAAa,OAAAO,EAAQ,MAAAH,CAAM,CAC3C"}
|
|
1
|
+
{"version":3,"file":"useDropZone.cjs","sources":["../../../../src/hooks/useDropZone/useDropZone.ts"],"sourcesContent":["import { useEffect, useRef, 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\nexport type DropZoneDataTypes = ((types: string[]) => boolean) | string[];\n\nexport interface UseDropZoneOptions {\n /** The data types for drop zone */\n dataTypes?: DropZoneDataTypes;\n /** The multiple mode for drop zone */\n multiple?: boolean;\n /** The on drop callback */\n onDrop?: (files: File[] | null, event: DragEvent) => void;\n /** The on enter callback */\n onEnter?: (event: DragEvent) => void;\n /** The on leave callback */\n onLeave?: (event: DragEvent) => void;\n /** The on over callback */\n onOver?: (event: DragEvent) => void;\n}\n\nexport interface UseDropZoneReturn {\n /** The files that was dropped in drop zone */\n files: File[] | null;\n /** The over drop zone status */\n overed: boolean;\n}\n\nexport interface UseDropZone {\n (\n target: HookTarget,\n callback?: (files: File[] | null, event: DragEvent) => void\n ): UseDropZoneReturn;\n\n <Target extends Element>(\n callback?: (files: File[] | null, event: DragEvent) => void,\n target?: never\n ): UseDropZoneReturn & {\n ref: StateRef<Target>;\n };\n\n (target: HookTarget, options?: UseDropZoneOptions): UseDropZoneReturn;\n\n <Target extends Element>(\n options?: UseDropZoneOptions,\n target?: never\n ): UseDropZoneReturn & {\n ref: StateRef<Target>;\n };\n}\n\n/**\n * @name useDropZone\n * @description - Hook that provides drop zone functionality\n * @category Elements\n *\n * @overload\n * @template Target The target element\n * @param {Target} target The target element drop zone's\n * @param {DataTypes} [options.dataTypes] The data types\n * @param {boolean} [options.multiple] The multiple mode\n * @param {(files: File[] | null, event: DragEvent) => void} [options.onDrop] The on drop callback function\n * @param {(event: DragEvent) => void} [options.onEnter] The on enter callback function\n * @param {(event: DragEvent) => void} [options.onLeave] The on leave callback function\n * @param {(event: DragEvent) => void} [options.onOver] The on over callback function\n * @returns {UseDropZoneReturn} The object with drop zone states\n *\n * @example\n * const { overed, files } = useDropZone(ref, options);\n *\n * @overload\n * @param {Target} target The target element drop zone's\n * @param {(files: File[] | null, event: DragEvent) => void} [callback] The callback function to be invoked on drop\n * @returns {UseDropZoneReturn} The object with drop zone states\n *\n * @example\n * const { overed, files } = useDropZone(ref, () => console.log('callback'));\n *\n * @overload\n * @param {DataTypes} [options.dataTypes] The data types\n * @param {boolean} [options.multiple] The multiple mode\n * @param {(files: File[] | null, event: DragEvent) => void} [options.onDrop] The on drop callback function\n * @param {(event: DragEvent) => void} [options.onEnter] The on enter callback function\n * @param {(event: DragEvent) => void} [options.onLeave] The on leave callback function\n * @param {(event: DragEvent) => void} [options.onOver] The on over callback function\n * @returns {UseDropZoneReturn & { ref: StateRef<Target> }} The object with drop zone states and ref\n *\n * @example\n * const { ref, overed, files } = useDropZone(options);\n *\n * @overload\n * @param {(files: File[] | null, event: DragEvent) => void} [callback] The callback function to be invoked on drop\n * @returns {UseDropZoneReturn & { ref: StateRef<Target> }} The object with drop zone states and ref\n *\n * @example\n * const { ref, overed, files } = useDropZone(() => console.log('callback'));\n */\n\nexport const useDropZone = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n\n const options = (\n target\n ? typeof params[1] === 'object'\n ? params[1]\n : { onDrop: params[1] }\n : typeof params[0] === 'object'\n ? params[0]\n : { onDrop: params[0] }\n ) as UseDropZoneOptions;\n\n const internalRef = useRefState<Element>();\n\n const counterRef = useRef(0);\n const [files, setFiles] = useState<File[] | null>(null);\n const [overed, setOvered] = useState(false);\n\n const dataTypes = options.dataTypes;\n\n const getFiles = (event: DragEvent) => {\n if (!event.dataTransfer) return null;\n const list = Array.from(event.dataTransfer.files);\n if (options.multiple) return list;\n if (!list.length) return null;\n return [list[0]];\n };\n\n const checkDataTypes = (types: string[]) => {\n if (!dataTypes) return true;\n if (typeof dataTypes === 'function') return dataTypes(types);\n if (!dataTypes.length) return true;\n if (!types.length) return false;\n\n return types.every((type) => {\n console.log('type', type);\n console.log('dataTypes', dataTypes);\n return dataTypes.some((dataType) => type.includes(dataType));\n });\n };\n\n const checkValidity = (items: DataTransferItemList) => {\n const types = Array.from(items).map((item) => item.type);\n const dataTypesValid = checkDataTypes(types);\n const multipleFilesValid = options.multiple || items.length <= 1;\n\n return dataTypesValid && multipleFilesValid;\n };\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = target ? getElement(target) : internalRef.current;\n\n if (!element) return;\n\n const onEvent = (event: DragEvent, type: 'drop' | 'enter' | 'leave' | 'over') => {\n if (!event.dataTransfer) return;\n\n const isValid = checkValidity(event.dataTransfer.items);\n if (!isValid) {\n event.dataTransfer.dropEffect = 'none';\n return;\n }\n\n event.preventDefault();\n event.dataTransfer.dropEffect = 'copy';\n\n const currentFiles = getFiles(event);\n\n if (type === 'drop') {\n counterRef.current = 0;\n setOvered(false);\n setFiles(currentFiles);\n options.onDrop?.(currentFiles, event);\n return;\n }\n\n if (type === 'enter') {\n counterRef.current += 1;\n setOvered(true);\n options.onEnter?.(event);\n return;\n }\n\n if (type === 'leave') {\n counterRef.current -= 1;\n if (counterRef.current !== 0) return;\n setOvered(false);\n options.onLeave?.(event);\n return;\n }\n\n if (type === 'over') options.onOver?.(event);\n };\n\n const onDrop = ((event: DragEvent) => onEvent(event, 'drop')) as EventListener;\n const onDragOver = ((event: DragEvent) => onEvent(event, 'over')) as EventListener;\n const onDragEnter = ((event: DragEvent) => onEvent(event, 'enter')) as EventListener;\n const onDragLeave = ((event: DragEvent) => onEvent(event, 'leave')) as EventListener;\n\n element.addEventListener('dragenter', onDragEnter);\n element.addEventListener('dragover', onDragOver);\n element.addEventListener('dragleave', onDragLeave);\n element.addEventListener('drop', onDrop);\n\n return () => {\n element.removeEventListener('dragenter', onDragEnter);\n element.removeEventListener('dragover', onDragOver);\n element.removeEventListener('dragleave', onDragLeave);\n element.removeEventListener('drop', onDrop);\n };\n }, [target, internalRef.current]);\n\n if (target) return { overed, files };\n return { ref: internalRef, overed, files };\n}) as UseDropZone;\n"],"names":["useDropZone","params","target","isTarget","options","internalRef","useRefState","counterRef","useRef","files","setFiles","useState","overed","setOvered","dataTypes","getFiles","event","list","checkDataTypes","types","type","dataType","checkValidity","items","item","dataTypesValid","multipleFilesValid","useEffect","element","getElement","onEvent","currentFiles","_a","_b","_c","_d","onDrop","onDragOver","onDragEnter","onDragLeave"],"mappings":"mPAwGaA,EAAe,IAAIC,IAAkB,CAC1C,MAAAC,EAAUC,WAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAE5CG,EACJF,EACI,OAAOD,EAAO,CAAC,GAAM,SACnBA,EAAO,CAAC,EACR,CAAE,OAAQA,EAAO,CAAC,CAAE,EACtB,OAAOA,EAAO,CAAC,GAAM,SACnBA,EAAO,CAAC,EACR,CAAE,OAAQA,EAAO,CAAC,CAAE,EAGtBI,EAAcC,EAAAA,YAAqB,EAEnCC,EAAaC,SAAO,CAAC,EACrB,CAACC,EAAOC,CAAQ,EAAIC,EAAAA,SAAwB,IAAI,EAChD,CAACC,EAAQC,CAAS,EAAIF,EAAAA,SAAS,EAAK,EAEpCG,EAAYV,EAAQ,UAEpBW,EAAYC,GAA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,SAAW,EACtBM,EAAU,EAAI,GACdoB,EAAA7B,EAAQ,UAAR,MAAA6B,EAAA,KAAA7B,EAAkBY,GAClB,MAAA,CAGF,GAAII,IAAS,QAAS,CAEhB,GADJb,EAAW,SAAW,EAClBA,EAAW,UAAY,EAAG,OAC9BM,EAAU,EAAK,GACfqB,EAAA9B,EAAQ,UAAR,MAAA8B,EAAA,KAAA9B,EAAkBY,GAClB,MAAA,CAGEI,IAAS,UAAgBe,EAAA/B,EAAA,SAAA,MAAA+B,EAAA,KAAA/B,EAASY,GACxC,EAEMoB,EAAWpB,GAAqBc,EAAQd,EAAO,MAAM,EACrDqB,EAAerB,GAAqBc,EAAQd,EAAO,MAAM,EACzDsB,EAAgBtB,GAAqBc,EAAQd,EAAO,OAAO,EAC3DuB,EAAgBvB,GAAqBc,EAAQd,EAAO,OAAO,EAEzD,OAAAY,EAAA,iBAAiB,YAAaU,CAAW,EACzCV,EAAA,iBAAiB,WAAYS,CAAU,EACvCT,EAAA,iBAAiB,YAAaW,CAAW,EACzCX,EAAA,iBAAiB,OAAQQ,CAAM,EAEhC,IAAM,CACHR,EAAA,oBAAoB,YAAaU,CAAW,EAC5CV,EAAA,oBAAoB,WAAYS,CAAU,EAC1CT,EAAA,oBAAoB,YAAaW,CAAW,EAC5CX,EAAA,oBAAoB,OAAQQ,CAAM,CAC5C,CACC,EAAA,CAAClC,EAAQG,EAAY,OAAO,CAAC,EAE5BH,EAAe,CAAE,OAAAU,EAAQ,MAAAH,CAAM,EAC5B,CAAE,IAAKJ,EAAa,OAAAO,EAAQ,MAAAH,CAAM,CAC3C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useShare.cjs","sources":["../../../../src/hooks/useShare/useShare.ts"],"sourcesContent":["/** The use share options type */\nexport interface UseShareParams {\n /** Array of files to be shared */\n files?: File[];\n /** Text content to be shared */\n text?: string;\n /** Title of the content being shared */\n title?: string;\n /** URL link to be shared */\n url?: string;\n}\n\n/** The use share return type */\nexport interface UseShareReturn {\n /** Whether the Web Share API is supported in the current environment */\n supported: boolean;\n /** Function to trigger the native share dialog */\n share: (shareParams: ShareData) => Promise<void>;\n}\n\n/**\n * @name useShare\n * @description - Hook that utilizes the share api\n * @category Browser\n *\n * @param {UseShareParams} [params] The use share options\n * @returns {UseShareReturn}\n *\n * @example\n * const { share, supported } = useShare();\n */\nexport const useShare = (params?: UseShareParams) => {\n const supported = typeof navigator !== 'undefined' && 'share' in navigator;\n\n const share = async (shareParams: ShareData) => {\n if (!supported) return;\n\n const data = {\n ...params,\n ...shareParams\n };\n\n if (data.files && navigator.canShare({ files: data.files })) navigator.share(data);\n\n return navigator.share(data);\n };\n\n return { share, supported };\n};\n"],"names":["useShare","params","supported","shareParams","data"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useShare.cjs","sources":["../../../../src/hooks/useShare/useShare.ts"],"sourcesContent":["/** The use share options type */\nexport interface UseShareParams {\n /** Array of files to be shared */\n files?: File[];\n /** Text content to be shared */\n text?: string;\n /** Title of the content being shared */\n title?: string;\n /** URL link to be shared */\n url?: string;\n}\n\n/** The use share return type */\nexport interface UseShareReturn {\n /** Whether the Web Share API is supported in the current environment */\n supported: boolean;\n /** Function to trigger the native share dialog */\n share: (shareParams: ShareData) => Promise<void>;\n}\n\n/**\n * @name useShare\n * @description - Hook that utilizes the share api\n * @category Browser\n *\n * @browserapi share https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share\n *\n * @param {UseShareParams} [params] The use share options\n * @returns {UseShareReturn}\n *\n * @example\n * const { share, supported } = useShare();\n */\nexport const useShare = (params?: UseShareParams) => {\n const supported = typeof navigator !== 'undefined' && 'share' in navigator;\n\n const share = async (shareParams: ShareData) => {\n if (!supported) return;\n\n const data = {\n ...params,\n ...shareParams\n };\n\n if (data.files && navigator.canShare({ files: data.files })) navigator.share(data);\n\n return navigator.share(data);\n };\n\n return { share, supported };\n};\n"],"names":["useShare","params","supported","shareParams","data"],"mappings":"gFAiCa,MAAAA,EAAYC,GAA4B,CACnD,MAAMC,EAAY,OAAO,UAAc,KAAe,UAAW,UAe1D,MAAA,CAAE,MAbK,MAAOC,GAA2B,CAC9C,GAAI,CAACD,EAAW,OAEhB,MAAME,EAAO,CACX,GAAGH,EACH,GAAGE,CACL,EAEA,OAAIC,EAAK,OAAS,UAAU,SAAS,CAAE,MAAOA,EAAK,KAAA,CAAO,GAAa,UAAA,MAAMA,CAAI,EAE1E,UAAU,MAAMA,CAAI,CAC7B,EAEgB,UAAAF,CAAU,CAC5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStep.cjs","sources":["../../../../src/hooks/useStep/useStep.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\n/** The use step params type */\
|
|
1
|
+
{"version":3,"file":"useStep.cjs","sources":["../../../../src/hooks/useStep/useStep.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\n/** The use step params type */\nexport interface UseStepParams {\n /** Initial value for step */\n initial: number;\n /** Maximum value for step */\n max: number;\n}\n\n/** The use step return type */\nexport interface UseStepReturn {\n /** Counts of steps */\n counts: number;\n /** Current value of step */\n currentStep: number;\n /** Boolean value if current step is first */\n isFirst: boolean;\n /** Boolean value if current step is last */\n isLast: boolean;\n /** Go to back step */\n back: () => void;\n /** Go to next step */\n next: () => void;\n /** Reset current step to initial value */\n reset: () => void;\n /** Go to custom step */\n set: (value: number | 'first' | 'last') => void;\n}\n\nconst FIRST_STEP_VALUE = 1;\n\n/**\n * @name useStep\n * @description - Hook that create stepper\n * @category Utilities\n *\n * @overload\n * @param {number} max Maximum number of steps\n * @returns {UseStepReturn} An object contains variables and functions to change the step\n *\n * @example\n * const stepper = useStep(5);\n *\n * @overload\n * @param {number} params.max Maximum number of steps\n * @param {number} params.initial Initial value for step\n * @returns {UseStepReturn} An object contains variables and functions to change the step\n *\n * @example\n * const stepper = useStep({ initial: 2, max: 5 });\n */\nexport const useStep = (params: number | UseStepParams): UseStepReturn => {\n const max = typeof params === 'object' ? params.max : params;\n const initial = typeof params === 'object' ? params.initial : FIRST_STEP_VALUE;\n\n const initialStep = useRef(\n initial > max || initial < FIRST_STEP_VALUE ? FIRST_STEP_VALUE : initial\n );\n const [currentStep, setCurrentStep] = useState(initial);\n\n const isFirst = currentStep === FIRST_STEP_VALUE;\n const isLast = currentStep === max;\n\n const next = () => {\n if (isLast) return;\n setCurrentStep((prevStep) => prevStep + 1);\n };\n\n const back = () => {\n if (isFirst) return;\n setCurrentStep((prevStep) => prevStep - 1);\n };\n\n const reset = () => setCurrentStep(initialStep.current);\n\n const set = (value: number | 'first' | 'last') => {\n if (value === 'first') return setCurrentStep(initialStep.current);\n if (value === 'last') return setCurrentStep(max);\n if (value >= max) return setCurrentStep(max);\n if (value <= FIRST_STEP_VALUE) return setCurrentStep(FIRST_STEP_VALUE);\n setCurrentStep(value);\n };\n\n return {\n counts: max,\n currentStep,\n isFirst,\n isLast,\n next,\n back,\n reset,\n set\n };\n};\n"],"names":["FIRST_STEP_VALUE","useStep","params","max","initial","initialStep","useRef","currentStep","setCurrentStep","useState","isFirst","isLast","prevStep","value"],"mappings":"yGA8BMA,EAAmB,EAsBZC,EAAWC,GAAkD,CACxE,MAAMC,EAAM,OAAOD,GAAW,SAAWA,EAAO,IAAMA,EAChDE,EAAU,OAAOF,GAAW,SAAWA,EAAO,QAAUF,EAExDK,EAAcC,EAAA,OAClBF,EAAUD,GAAOC,EAAUJ,EAAmBA,EAAmBI,CACnE,EACM,CAACG,EAAaC,CAAc,EAAIC,EAAAA,SAASL,CAAO,EAEhDM,EAAUH,IAAgBP,EAC1BW,EAASJ,IAAgBJ,EAsBxB,MAAA,CACL,OAAQA,EACR,YAAAI,EACA,QAAAG,EACA,OAAAC,EACA,KAzBW,IAAM,CACbA,GACWH,EAACI,GAAaA,EAAW,CAAC,CAC3C,EAuBE,KArBW,IAAM,CACbF,GACWF,EAACI,GAAaA,EAAW,CAAC,CAC3C,EAmBE,MAjBY,IAAMJ,EAAeH,EAAY,OAAO,EAkBpD,IAhBWQ,GAAqC,CAChD,GAAIA,IAAU,QAAgB,OAAAL,EAAeH,EAAY,OAAO,EAEhE,GADIQ,IAAU,QACVA,GAASV,EAAY,OAAAK,EAAeL,CAAG,EAC3C,GAAIU,GAASb,EAAyB,OAAAQ,EAAeR,CAAgB,EACrEQ,EAAeK,CAAK,CACtB,CAWA,CACF"}
|
|
@@ -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 g=require("react"),c="reactuse-storage",u=o=>window.dispatchEvent(new StorageEvent(c,o)),f=(o,r,n)=>{const t=o.getItem(r);o.setItem(r,n),u({key:r,oldValue:t,newValue:n,storageArea:o})},V=(o,r)=>{const n=o.getItem(r);o.removeItem(r),u({key:r,oldValue:n,newValue:null,storageArea:o})},v=(o,r)=>{const n=o.getItem(r);if(n)return n},z=(...o)=>{const r=o[0],n=o[1],t=typeof n=="object"&&n&&("serializer"in n||"deserializer"in n||"initialValue"in n||"storage"in n)?n:void 0,i=t?t==null?void 0:t.initialValue:n;if(typeof window>"u")return{value:typeof i=="function"?i():i,set:()=>{},remove:()=>{}};const d=e=>t!=null&&t.serializer?t.serializer(e):typeof e=="string"?e:JSON.stringify(e),s=(t==null?void 0:t.storage)??(window==null?void 0:window.localStorage),S=e=>f(s,r,d(e)),m=()=>V(s,r),l=e=>{if(t!=null&&t.deserializer)return t.deserializer(e);if(e!=="undefined")try{return JSON.parse(e)}catch{return e}},[w,E]=g.useState(()=>{const e=v(s,r);if(e===void 0&&i!==void 0){const a=typeof i=="function"?i():i;return f(s,r,d(a)),a}return e?l(e):void 0});return g.useEffect(()=>{const e=()=>{const a=v(s,r);E(a?l(a):void 0)};return window.addEventListener(c,e),()=>window.removeEventListener(c,e)},[r]),{value:w,set:S,remove:m}};exports.STORAGE_EVENT=c;exports.dispatchStorageEvent=u;exports.useStorage=z;
|
|
2
2
|
//# sourceMappingURL=useStorage.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStorage.cjs","sources":["../../../../src/hooks/useStorage/useStorage.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/* The use storage initial value type */\nexport type UseStorageInitialValue<Value> = (() => Value) | Value;\n\n/* The use storage options type */\nexport interface UseStorageOptions<Value> {\n /* The initial value of the storage */\n initialValue?: UseStorageInitialValue<Value>;\n /* The storage to be used */\n storage?: Storage;\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value;\n /* The serializer function to be invoked */\n serializer?: (value: Value) => string;\n}\n\n/* The use storage return type */\nexport interface UseStorageReturn<Value> {\n /* The value of the storage */\n value: Value;\n /* The error state of the storage */\n remove: () => void;\n /* The loading state of the storage */\n set: (value: Value) => void;\n}\n\nexport const STORAGE_EVENT = 'reactuse-storage';\n\nexport const dispatchStorageEvent = (params: Partial<StorageEvent>) =>\n window.dispatchEvent(new StorageEvent(STORAGE_EVENT, params));\n\nconst setStorageItem = (storage: Storage, key: string, value: string) => {\n const oldValue = storage.getItem(key);\n\n storage.setItem(key, value);\n dispatchStorageEvent({ key, oldValue, newValue: value, storageArea: storage });\n};\n\nconst removeStorageItem = (storage: Storage, key: string) => {\n const oldValue = storage.getItem(key);\n\n storage.removeItem(key);\n dispatchStorageEvent({ key, oldValue, newValue: null, storageArea: storage });\n};\n\nconst getStorageItem = (storage: Storage, key: string) => {\n const value = storage.getItem(key);\n if (!value) return undefined;\n return value;\n};\n\n/**\n * @name useStorage\n * @description - Hook that manages storage value\n * @category Browser\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {(value: Value) => string} [params.serializer] The serializer function\n * @param {(value: string) => Value} [params.deserializer] The deserializer function\n * @param {Storage} [params.storage] The storage\n * @param {UseStorageInitialValue<Value>} [params.initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @example\n * const { value, set, remove } = useStorage('key', 'value');\n */\nexport const useStorage = <Value>(\n key
|
|
1
|
+
{"version":3,"file":"useStorage.cjs","sources":["../../../../src/hooks/useStorage/useStorage.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/* The use storage initial value type */\nexport type UseStorageInitialValue<Value> = (() => Value) | Value;\n\n/* The use storage options type */\nexport interface UseStorageOptions<Value> {\n /* The initial value of the storage */\n initialValue?: UseStorageInitialValue<Value>;\n /* The storage to be used */\n storage?: Storage;\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value;\n /* The serializer function to be invoked */\n serializer?: (value: Value) => string;\n}\n\n/* The use storage return type */\nexport interface UseStorageReturn<Value> {\n /* The value of the storage */\n value: Value;\n /* The error state of the storage */\n remove: () => void;\n /* The loading state of the storage */\n set: (value: Value) => void;\n}\n\nexport interface UseStorage {\n <Value>(\n key: string,\n options: UseStorageOptions<Value> & { initialValue: UseStorageInitialValue<Value> }\n ): UseStorageReturn<Value>;\n\n <Value>(key: string, options?: UseStorageOptions<Value>): UseStorageReturn<Value | undefined>;\n\n <Value>(key: string, initialValue: UseStorageInitialValue<Value>): UseStorageReturn<Value>;\n\n <Value>(key: string): UseStorageReturn<Value | undefined>;\n}\n\nexport const STORAGE_EVENT = 'reactuse-storage';\n\nexport const dispatchStorageEvent = (params: Partial<StorageEvent>) =>\n window.dispatchEvent(new StorageEvent(STORAGE_EVENT, params));\n\nconst setStorageItem = (storage: Storage, key: string, value: string) => {\n const oldValue = storage.getItem(key);\n\n storage.setItem(key, value);\n dispatchStorageEvent({ key, oldValue, newValue: value, storageArea: storage });\n};\n\nconst removeStorageItem = (storage: Storage, key: string) => {\n const oldValue = storage.getItem(key);\n\n storage.removeItem(key);\n dispatchStorageEvent({ key, oldValue, newValue: null, storageArea: storage });\n};\n\nconst getStorageItem = (storage: Storage, key: string) => {\n const value = storage.getItem(key);\n if (!value) return undefined;\n return value;\n};\n\n/**\n * @name useStorage\n * @description - Hook that manages storage value\n * @category Browser\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {(value: Value) => string} [params.serializer] The serializer function\n * @param {(value: string) => Value} [params.deserializer] The deserializer function\n * @param {Storage} [params.storage] The storage\n * @param {UseStorageInitialValue<Value>} [params.initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @example\n * const { value, set, remove } = useStorage('key', 'value');\n */\nexport const useStorage = (<Value>(...params: any[]): UseStorageReturn<Value> => {\n const key = params[0] as string;\n const secondParam = params[1];\n\n const options = (\n typeof secondParam === 'object' &&\n secondParam &&\n ('serializer' in secondParam ||\n 'deserializer' in secondParam ||\n 'initialValue' in secondParam ||\n 'storage' in secondParam)\n ? secondParam\n : undefined\n ) as UseStorageOptions<Value>;\n\n const initialValue = (\n options ? options?.initialValue : secondParam\n ) as UseStorageInitialValue<Value>;\n\n if (typeof window === 'undefined') {\n const value = typeof initialValue === 'function' ? (initialValue as () => any)() : initialValue;\n return {\n value,\n set: () => {},\n remove: () => {}\n };\n }\n\n const serializer = (value: Value) => {\n if (options?.serializer) return options.serializer(value);\n if (typeof value === 'string') return value;\n return JSON.stringify(value);\n };\n\n const storage = options?.storage ?? window?.localStorage;\n\n const set = (value: Value) => setStorageItem(storage, key, serializer(value));\n const remove = () => removeStorageItem(storage, key);\n\n const deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined') return undefined as unknown as Value;\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value;\n }\n };\n\n const [value, setValue] = useState<Value | undefined>(() => {\n const storageValue = getStorageItem(storage, key);\n if (storageValue === undefined && initialValue !== undefined) {\n const value =\n typeof initialValue === 'function' ? (initialValue as () => Value)() : initialValue;\n setStorageItem(storage, key, serializer(value));\n return value;\n }\n return storageValue ? deserializer(storageValue) : undefined;\n });\n\n useEffect(() => {\n const onChange = () => {\n const storageValue = getStorageItem(storage, key);\n setValue(storageValue ? deserializer(storageValue) : undefined);\n };\n window.addEventListener(STORAGE_EVENT, onChange);\n return () => window.removeEventListener(STORAGE_EVENT, onChange);\n }, [key]);\n\n return {\n value: value as Value,\n set,\n remove\n };\n}) as UseStorage;\n"],"names":["STORAGE_EVENT","dispatchStorageEvent","params","setStorageItem","storage","key","value","oldValue","removeStorageItem","getStorageItem","useStorage","secondParam","options","initialValue","serializer","set","remove","deserializer","setValue","useState","storageValue","useEffect","onChange"],"mappings":"yGAwCaA,EAAgB,mBAEhBC,EAAwBC,GACnC,OAAO,cAAc,IAAI,aAAaF,EAAeE,CAAM,CAAC,EAExDC,EAAiB,CAACC,EAAkBC,EAAaC,IAAkB,CACjE,MAAAC,EAAWH,EAAQ,QAAQC,CAAG,EAE5BD,EAAA,QAAQC,EAAKC,CAAK,EAC1BL,EAAqB,CAAE,IAAAI,EAAK,SAAAE,EAAU,SAAUD,EAAO,YAAaF,EAAS,CAC/E,EAEMI,EAAoB,CAACJ,EAAkBC,IAAgB,CACrD,MAAAE,EAAWH,EAAQ,QAAQC,CAAG,EAEpCD,EAAQ,WAAWC,CAAG,EACtBJ,EAAqB,CAAE,IAAAI,EAAK,SAAAE,EAAU,SAAU,KAAM,YAAaH,EAAS,CAC9E,EAEMK,EAAiB,CAACL,EAAkBC,IAAgB,CAClD,MAAAC,EAAQF,EAAQ,QAAQC,CAAG,EAC7B,GAACC,EACE,OAAAA,CACT,EAuBaI,EAAc,IAAWR,IAA2C,CACzE,MAAAG,EAAMH,EAAO,CAAC,EACdS,EAAcT,EAAO,CAAC,EAEtBU,EACJ,OAAOD,GAAgB,UACvBA,IACC,eAAgBA,GACf,iBAAkBA,GAClB,iBAAkBA,GAClB,YAAaA,GACXA,EACA,OAGAE,EACJD,EAAUA,GAAA,YAAAA,EAAS,aAAeD,EAGhC,G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 -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAsync.mjs","sources":["../../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/* The use query return type */\nexport interface UseAsyncReturn<Data> {\n /* The state of the query */\n data?: Data;\n /* The error of the query */\n error?: Error;\n /* The error state of the query */\n isError: boolean;\n /* The loading state of the query */\n isLoading: boolean;\n}\n\n/**\n * @name useAsync\n * @description - Hook that provides the state of an async callback\n * @category Utilities\n *\n * @param {() => Promise<Data>} callback
|
|
1
|
+
{"version":3,"file":"useAsync.mjs","sources":["../../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/* The use query return type */\nexport interface UseAsyncReturn<Data> {\n /* The state of the query */\n data?: Data;\n /* The error of the query */\n error?: Error;\n /* The error state of the query */\n isError: boolean;\n /* The loading state of the query */\n isLoading: boolean;\n}\n\n/**\n * @name useAsync\n * @description - Hook that provides the state of an async callback\n * @category Utilities\n *\n * @param {() => Promise<Data>} callback The async callback\n * @param {DependencyList} deps The dependencies of the callback\n * @returns {UseAsyncReturn<Data>} The state of the async callback\n *\n * @example\n * const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);\n */\nexport const useAsync = <Data>(\n callback: () => Promise<Data>,\n deps: DependencyList\n): UseAsyncReturn<Data> => {\n const [isLoading, setIsLoading] = useState(true);\n const [isError, setIsError] = useState(false);\n\n const [error, setError] = useState<Error | undefined>(undefined);\n const [data, setData] = useState<Data | undefined>(undefined);\n\n useEffect(() => {\n setIsLoading(true);\n callback()\n .then((response) => {\n setData(response);\n setError(undefined);\n setIsError(false);\n })\n .catch((error: Error) => {\n setError(error);\n setIsError(true);\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, deps);\n\n return {\n data,\n isLoading,\n isError,\n error\n };\n};\n"],"names":["useAsync","callback","deps","isLoading","setIsLoading","useState","isError","setIsError","error","setError","data","setData","useEffect","response"],"mappings":";AA4Ba,MAAAA,IAAW,CACtBC,GACAC,MACyB;AACzB,QAAM,CAACC,GAAWC,CAAY,IAAIC,EAAS,EAAI,GACzC,CAACC,GAASC,CAAU,IAAIF,EAAS,EAAK,GAEtC,CAACG,GAAOC,CAAQ,IAAIJ,EAA4B,MAAS,GACzD,CAACK,GAAMC,CAAO,IAAIN,EAA2B,MAAS;AAE5D,SAAAO,EAAU,MAAM;AACd,IAAAR,EAAa,EAAI,GACRH,EAAA,EACN,KAAK,CAACY,MAAa;AAClB,MAAAF,EAAQE,CAAQ,GAChBJ,EAAS,MAAS,GAClBF,EAAW,EAAK;AAAA,IAAA,CACjB,EACA,MAAM,CAACC,MAAiB;AACvB,MAAAC,EAASD,CAAK,GACdD,EAAW,EAAI;AAAA,IAAA,CAChB,EACA,QAAQ,MAAM;AACb,MAAAH,EAAa,EAAK;AAAA,IAAA,CACnB;AAAA,KACFF,CAAI,GAEA;AAAA,IACL,MAAAQ;AAAA,IACA,WAAAP;AAAA,IACA,SAAAG;AAAA,IACA,OAAAE;AAAA,EACF;AACF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDropZone.mjs","sources":["../../../../src/hooks/useDropZone/useDropZone.ts"],"sourcesContent":["import { useEffect, useRef, 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\nexport type DropZoneDataTypes = ((types: string[]) => boolean) | string[];\n\nexport interface UseDropZoneOptions {\n /** The data types for drop zone */\n dataTypes?: DropZoneDataTypes;\n /** The multiple mode for drop zone */\n multiple?: boolean;\n /** The on drop callback */\n onDrop?: (files: File[] | null, event: DragEvent) => void;\n /** The on enter callback */\n onEnter?: (event: DragEvent) => void;\n /** The on leave callback */\n onLeave?: (event: DragEvent) => void;\n /** The on over callback */\n onOver?: (event: DragEvent) => void;\n}\n\nexport interface UseDropZoneReturn {\n /** The files that was dropped in drop zone */\n files: File[] | null;\n /** The over drop zone status */\n overed: boolean;\n}\n\nexport interface UseDropZone {\n (\n target: HookTarget,\n callback?: (files: File[] | null, event: DragEvent) => void\n ): UseDropZoneReturn;\n\n <Target extends Element>(\n callback?: (files: File[] | null, event: DragEvent) => void,\n target?: never\n ): UseDropZoneReturn & {\n ref: StateRef<Target>;\n };\n\n (target: HookTarget, options?: UseDropZoneOptions): UseDropZoneReturn;\n\n <Target extends Element>(\n options?: UseDropZoneOptions,\n target?: never\n ): UseDropZoneReturn & {\n ref: StateRef<Target>;\n };\n}\n\n/**\n * @name useDropZone\n * @description - Hook that provides drop zone functionality\n * @category Elements\n *\n * @overload\n * @template Target The target element\n * @param {Target} target The target element drop zone's\n * @param {DataTypes} [options.dataTypes] The data types\n * @param {boolean} [options.multiple] The multiple mode\n * @param {(files: File[] | null, event: DragEvent) => void} [options.onDrop] The on drop callback function\n * @param {(event: DragEvent) => void} [options.onEnter] The on enter callback function\n * @param {(event: DragEvent) => void} [options.onLeave] The on leave callback function\n * @param {(event: DragEvent) => void} [options.onOver] The on over callback function\n * @returns {[boolean, File[] | null]} The object with drop zone states\n *\n * @example\n * const { overed, files } = useDropZone(ref, options);\n *\n * @overload\n * @param {Target} target The target element drop zone's\n * @param {(files: File[] | null, event: DragEvent) => void} [callback] The callback function to be invoked on drop\n * @returns {[boolean, File[] | null]} The object with drop zone states\n *\n * @example\n * const { overed, files } = useDropZone(ref, () => console.log('callback'));\n *\n * @overload\n * @param {DataTypes} [options.dataTypes] The data types\n * @param {boolean} [options.multiple] The multiple mode\n * @param {(files: File[] | null, event: DragEvent) => void} [options.onDrop] The on drop callback function\n * @param {(event: DragEvent) => void} [options.onEnter] The on enter callback function\n * @param {(event: DragEvent) => void} [options.onLeave] The on leave callback function\n * @param {(event: DragEvent) => void} [options.onOver] The on over callback function\n * @returns {[StateRef<Target>, boolean, File[] | null]} The object with drop zone states and ref\n *\n * @example\n * const { ref, overed, files } = useDropZone(options);\n *\n * @overload\n * @param {(files: File[] | null, event: DragEvent) => void} [callback] The callback function to be invoked on drop\n * @returns {[StateRef<Target>, boolean, File[] | null]} The object with drop zone states and ref\n *\n * @example\n * const { ref, overed, files } = useDropZone(() => console.log('callback'));\n */\n\nexport const useDropZone = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n\n const options = (\n target\n ? typeof params[1] === 'object'\n ? params[1]\n : { onDrop: params[1] }\n : typeof params[0] === 'object'\n ? params[0]\n : { onDrop: params[0] }\n ) as UseDropZoneOptions;\n\n const internalRef = useRefState<Element>();\n\n const counterRef = useRef(0);\n const [files, setFiles] = useState<File[] | null>(null);\n const [overed, setOvered] = useState(false);\n\n const dataTypes = options.dataTypes;\n\n const getFiles = (event: DragEvent) => {\n if (!event.dataTransfer) return null;\n const list = Array.from(event.dataTransfer.files);\n if (options.multiple) return list;\n if (!list.length) return null;\n return [list[0]];\n };\n\n const checkDataTypes = (types: string[]) => {\n if (!dataTypes) return true;\n if (typeof dataTypes === 'function') return dataTypes(types);\n if (!dataTypes.length) return true;\n if (!types.length) return false;\n\n return types.every((type) => {\n console.log('type', type);\n console.log('dataTypes', dataTypes);\n return dataTypes.some((dataType) => type.includes(dataType));\n });\n };\n\n const checkValidity = (items: DataTransferItemList) => {\n const types = Array.from(items).map((item) => item.type);\n const dataTypesValid = checkDataTypes(types);\n const multipleFilesValid = options.multiple || items.length <= 1;\n\n return dataTypesValid && multipleFilesValid;\n };\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = target ? getElement(target) : internalRef.current;\n\n if (!element) return;\n\n const onEvent = (event: DragEvent, type: 'drop' | 'enter' | 'leave' | 'over') => {\n if (!event.dataTransfer) return;\n\n const isValid = checkValidity(event.dataTransfer.items);\n if (!isValid) {\n event.dataTransfer.dropEffect = 'none';\n return;\n }\n\n event.preventDefault();\n event.dataTransfer.dropEffect = 'copy';\n\n const currentFiles = getFiles(event);\n\n if (type === 'drop') {\n counterRef.current = 0;\n setOvered(false);\n setFiles(currentFiles);\n options.onDrop?.(currentFiles, event);\n return;\n }\n\n if (type === 'enter') {\n counterRef.current += 1;\n setOvered(true);\n options.onEnter?.(event);\n return;\n }\n\n if (type === 'leave') {\n counterRef.current -= 1;\n if (counterRef.current !== 0) return;\n setOvered(false);\n options.onLeave?.(event);\n return;\n }\n\n if (type === 'over') options.onOver?.(event);\n };\n\n const onDrop = ((event: DragEvent) => onEvent(event, 'drop')) as EventListener;\n const onDragOver = ((event: DragEvent) => onEvent(event, 'over')) as EventListener;\n const onDragEnter = ((event: DragEvent) => onEvent(event, 'enter')) as EventListener;\n const onDragLeave = ((event: DragEvent) => onEvent(event, 'leave')) as EventListener;\n\n element.addEventListener('dragenter', onDragEnter);\n element.addEventListener('dragover', onDragOver);\n element.addEventListener('dragleave', onDragLeave);\n element.addEventListener('drop', onDrop);\n\n return () => {\n element.removeEventListener('dragenter', onDragEnter);\n element.removeEventListener('dragover', onDragOver);\n element.removeEventListener('dragleave', onDragLeave);\n element.removeEventListener('drop', onDrop);\n };\n }, [target, internalRef.current]);\n\n if (target) return { overed, files };\n return { ref: internalRef, overed, files };\n}) as UseDropZone;\n"],"names":["useDropZone","params","target","isTarget","options","internalRef","useRefState","counterRef","useRef","files","setFiles","useState","overed","setOvered","dataTypes","getFiles","event","list","checkDataTypes","types","type","dataType","checkValidity","items","item","dataTypesValid","multipleFilesValid","useEffect","element","getElement","onEvent","currentFiles","_a","_b","_c","_d","onDrop","onDragOver","onDragEnter","onDragLeave"],"mappings":";;;;AAwGa,MAAAA,IAAe,IAAIC,MAAkB;AAC1C,QAAAC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAE5CG,IACJF,IACI,OAAOD,EAAO,CAAC,KAAM,WACnBA,EAAO,CAAC,IACR,EAAE,QAAQA,EAAO,CAAC,EAAE,IACtB,OAAOA,EAAO,CAAC,KAAM,WACnB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AAO,CAAC,GAE5BH,IAAe,EAAE,QAAAU,GAAQ,OAAAH,EAAM,IAC5B,EAAE,KAAKJ,GAAa,QAAAO,GAAQ,OAAAH,EAAM;AAC3C;"}
|
|
1
|
+
{"version":3,"file":"useDropZone.mjs","sources":["../../../../src/hooks/useDropZone/useDropZone.ts"],"sourcesContent":["import { useEffect, useRef, 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\nexport type DropZoneDataTypes = ((types: string[]) => boolean) | string[];\n\nexport interface UseDropZoneOptions {\n /** The data types for drop zone */\n dataTypes?: DropZoneDataTypes;\n /** The multiple mode for drop zone */\n multiple?: boolean;\n /** The on drop callback */\n onDrop?: (files: File[] | null, event: DragEvent) => void;\n /** The on enter callback */\n onEnter?: (event: DragEvent) => void;\n /** The on leave callback */\n onLeave?: (event: DragEvent) => void;\n /** The on over callback */\n onOver?: (event: DragEvent) => void;\n}\n\nexport interface UseDropZoneReturn {\n /** The files that was dropped in drop zone */\n files: File[] | null;\n /** The over drop zone status */\n overed: boolean;\n}\n\nexport interface UseDropZone {\n (\n target: HookTarget,\n callback?: (files: File[] | null, event: DragEvent) => void\n ): UseDropZoneReturn;\n\n <Target extends Element>(\n callback?: (files: File[] | null, event: DragEvent) => void,\n target?: never\n ): UseDropZoneReturn & {\n ref: StateRef<Target>;\n };\n\n (target: HookTarget, options?: UseDropZoneOptions): UseDropZoneReturn;\n\n <Target extends Element>(\n options?: UseDropZoneOptions,\n target?: never\n ): UseDropZoneReturn & {\n ref: StateRef<Target>;\n };\n}\n\n/**\n * @name useDropZone\n * @description - Hook that provides drop zone functionality\n * @category Elements\n *\n * @overload\n * @template Target The target element\n * @param {Target} target The target element drop zone's\n * @param {DataTypes} [options.dataTypes] The data types\n * @param {boolean} [options.multiple] The multiple mode\n * @param {(files: File[] | null, event: DragEvent) => void} [options.onDrop] The on drop callback function\n * @param {(event: DragEvent) => void} [options.onEnter] The on enter callback function\n * @param {(event: DragEvent) => void} [options.onLeave] The on leave callback function\n * @param {(event: DragEvent) => void} [options.onOver] The on over callback function\n * @returns {UseDropZoneReturn} The object with drop zone states\n *\n * @example\n * const { overed, files } = useDropZone(ref, options);\n *\n * @overload\n * @param {Target} target The target element drop zone's\n * @param {(files: File[] | null, event: DragEvent) => void} [callback] The callback function to be invoked on drop\n * @returns {UseDropZoneReturn} The object with drop zone states\n *\n * @example\n * const { overed, files } = useDropZone(ref, () => console.log('callback'));\n *\n * @overload\n * @param {DataTypes} [options.dataTypes] The data types\n * @param {boolean} [options.multiple] The multiple mode\n * @param {(files: File[] | null, event: DragEvent) => void} [options.onDrop] The on drop callback function\n * @param {(event: DragEvent) => void} [options.onEnter] The on enter callback function\n * @param {(event: DragEvent) => void} [options.onLeave] The on leave callback function\n * @param {(event: DragEvent) => void} [options.onOver] The on over callback function\n * @returns {UseDropZoneReturn & { ref: StateRef<Target> }} The object with drop zone states and ref\n *\n * @example\n * const { ref, overed, files } = useDropZone(options);\n *\n * @overload\n * @param {(files: File[] | null, event: DragEvent) => void} [callback] The callback function to be invoked on drop\n * @returns {UseDropZoneReturn & { ref: StateRef<Target> }} The object with drop zone states and ref\n *\n * @example\n * const { ref, overed, files } = useDropZone(() => console.log('callback'));\n */\n\nexport const useDropZone = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n\n const options = (\n target\n ? typeof params[1] === 'object'\n ? params[1]\n : { onDrop: params[1] }\n : typeof params[0] === 'object'\n ? params[0]\n : { onDrop: params[0] }\n ) as UseDropZoneOptions;\n\n const internalRef = useRefState<Element>();\n\n const counterRef = useRef(0);\n const [files, setFiles] = useState<File[] | null>(null);\n const [overed, setOvered] = useState(false);\n\n const dataTypes = options.dataTypes;\n\n const getFiles = (event: DragEvent) => {\n if (!event.dataTransfer) return null;\n const list = Array.from(event.dataTransfer.files);\n if (options.multiple) return list;\n if (!list.length) return null;\n return [list[0]];\n };\n\n const checkDataTypes = (types: string[]) => {\n if (!dataTypes) return true;\n if (typeof dataTypes === 'function') return dataTypes(types);\n if (!dataTypes.length) return true;\n if (!types.length) return false;\n\n return types.every((type) => {\n console.log('type', type);\n console.log('dataTypes', dataTypes);\n return dataTypes.some((dataType) => type.includes(dataType));\n });\n };\n\n const checkValidity = (items: DataTransferItemList) => {\n const types = Array.from(items).map((item) => item.type);\n const dataTypesValid = checkDataTypes(types);\n const multipleFilesValid = options.multiple || items.length <= 1;\n\n return dataTypesValid && multipleFilesValid;\n };\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = target ? getElement(target) : internalRef.current;\n\n if (!element) return;\n\n const onEvent = (event: DragEvent, type: 'drop' | 'enter' | 'leave' | 'over') => {\n if (!event.dataTransfer) return;\n\n const isValid = checkValidity(event.dataTransfer.items);\n if (!isValid) {\n event.dataTransfer.dropEffect = 'none';\n return;\n }\n\n event.preventDefault();\n event.dataTransfer.dropEffect = 'copy';\n\n const currentFiles = getFiles(event);\n\n if (type === 'drop') {\n counterRef.current = 0;\n setOvered(false);\n setFiles(currentFiles);\n options.onDrop?.(currentFiles, event);\n return;\n }\n\n if (type === 'enter') {\n counterRef.current += 1;\n setOvered(true);\n options.onEnter?.(event);\n return;\n }\n\n if (type === 'leave') {\n counterRef.current -= 1;\n if (counterRef.current !== 0) return;\n setOvered(false);\n options.onLeave?.(event);\n return;\n }\n\n if (type === 'over') options.onOver?.(event);\n };\n\n const onDrop = ((event: DragEvent) => onEvent(event, 'drop')) as EventListener;\n const onDragOver = ((event: DragEvent) => onEvent(event, 'over')) as EventListener;\n const onDragEnter = ((event: DragEvent) => onEvent(event, 'enter')) as EventListener;\n const onDragLeave = ((event: DragEvent) => onEvent(event, 'leave')) as EventListener;\n\n element.addEventListener('dragenter', onDragEnter);\n element.addEventListener('dragover', onDragOver);\n element.addEventListener('dragleave', onDragLeave);\n element.addEventListener('drop', onDrop);\n\n return () => {\n element.removeEventListener('dragenter', onDragEnter);\n element.removeEventListener('dragover', onDragOver);\n element.removeEventListener('dragleave', onDragLeave);\n element.removeEventListener('drop', onDrop);\n };\n }, [target, internalRef.current]);\n\n if (target) return { overed, files };\n return { ref: internalRef, overed, files };\n}) as UseDropZone;\n"],"names":["useDropZone","params","target","isTarget","options","internalRef","useRefState","counterRef","useRef","files","setFiles","useState","overed","setOvered","dataTypes","getFiles","event","list","checkDataTypes","types","type","dataType","checkValidity","items","item","dataTypesValid","multipleFilesValid","useEffect","element","getElement","onEvent","currentFiles","_a","_b","_c","_d","onDrop","onDragOver","onDragEnter","onDragLeave"],"mappings":";;;;AAwGa,MAAAA,IAAe,IAAIC,MAAkB;AAC1C,QAAAC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAE5CG,IACJF,IACI,OAAOD,EAAO,CAAC,KAAM,WACnBA,EAAO,CAAC,IACR,EAAE,QAAQA,EAAO,CAAC,EAAE,IACtB,OAAOA,EAAO,CAAC,KAAM,WACnBA,EAAO,CAAC,IACR,EAAE,QAAQA,EAAO,CAAC,EAAE,GAGtBI,IAAcC,EAAqB,GAEnCC,IAAaC,EAAO,CAAC,GACrB,CAACC,GAAOC,CAAQ,IAAIC,EAAwB,IAAI,GAChD,CAACC,GAAQC,CAAS,IAAIF,EAAS,EAAK,GAEpCG,IAAYV,EAAQ,WAEpBW,IAAW,CAACC,MAAqB;AACjC,QAAA,CAACA,EAAM,aAAqB,QAAA;AAChC,UAAMC,IAAO,MAAM,KAAKD,EAAM,aAAa,KAAK;AAC5C,WAAAZ,EAAQ,WAAiBa,IACxBA,EAAK,SACH,CAACA,EAAK,CAAC,CAAC,IADU;AAAA,EAE3B,GAEMC,IAAiB,CAACC,MACjBL,IACD,OAAOA,KAAc,aAAmBA,EAAUK,CAAK,IACtDL,EAAU,SACVK,EAAM,SAEJA,EAAM,MAAM,CAACC,OACV,QAAA,IAAI,QAAQA,CAAI,GAChB,QA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AAA;AAGF,MAAII,MAAS,YAAgBe,IAAA/B,EAAA,WAAA,QAAA+B,EAAA,KAAA/B,GAASY;AAAA,IACxC,GAEMoB,IAAU,CAACpB,MAAqBc,EAAQd,GAAO,MAAM,GACrDqB,IAAc,CAACrB,MAAqBc,EAAQd,GAAO,MAAM,GACzDsB,IAAe,CAACtB,MAAqBc,EAAQd,GAAO,OAAO,GAC3DuB,IAAe,CAACvB,MAAqBc,EAAQd,GAAO,OAAO;AAEzD,WAAAY,EAAA,iBAAiB,aAAaU,CAAW,GACzCV,EAAA,iBAAiB,YAAYS,CAAU,GACvCT,EAAA,iBAAiB,aAAaW,CAAW,GACzCX,EAAA,iBAAiB,QAAQQ,CAAM,GAEhC,MAAM;AACH,MAAAR,EAAA,oBAAoB,aAAaU,CAAW,GAC5CV,EAAA,oBAAoB,YAAYS,CAAU,GAC1CT,EAAA,oBAAoB,aAAaW,CAAW,GAC5CX,EAAA,oBAAoB,QAAQQ,CAAM;AAAA,IAC5C;AAAA,EACC,GAAA,CAAClC,GAAQG,EAAY,OAAO,CAAC,GAE5BH,IAAe,EAAE,QAAAU,GAAQ,OAAAH,EAAM,IAC5B,EAAE,KAAKJ,GAAa,QAAAO,GAAQ,OAAAH,EAAM;AAC3C;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useShare.mjs","sources":["../../../../src/hooks/useShare/useShare.ts"],"sourcesContent":["/** The use share options type */\nexport interface UseShareParams {\n /** Array of files to be shared */\n files?: File[];\n /** Text content to be shared */\n text?: string;\n /** Title of the content being shared */\n title?: string;\n /** URL link to be shared */\n url?: string;\n}\n\n/** The use share return type */\nexport interface UseShareReturn {\n /** Whether the Web Share API is supported in the current environment */\n supported: boolean;\n /** Function to trigger the native share dialog */\n share: (shareParams: ShareData) => Promise<void>;\n}\n\n/**\n * @name useShare\n * @description - Hook that utilizes the share api\n * @category Browser\n *\n * @param {UseShareParams} [params] The use share options\n * @returns {UseShareReturn}\n *\n * @example\n * const { share, supported } = useShare();\n */\nexport const useShare = (params?: UseShareParams) => {\n const supported = typeof navigator !== 'undefined' && 'share' in navigator;\n\n const share = async (shareParams: ShareData) => {\n if (!supported) return;\n\n const data = {\n ...params,\n ...shareParams\n };\n\n if (data.files && navigator.canShare({ files: data.files })) navigator.share(data);\n\n return navigator.share(data);\n };\n\n return { share, supported };\n};\n"],"names":["useShare","params","supported","shareParams","data"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useShare.mjs","sources":["../../../../src/hooks/useShare/useShare.ts"],"sourcesContent":["/** The use share options type */\nexport interface UseShareParams {\n /** Array of files to be shared */\n files?: File[];\n /** Text content to be shared */\n text?: string;\n /** Title of the content being shared */\n title?: string;\n /** URL link to be shared */\n url?: string;\n}\n\n/** The use share return type */\nexport interface UseShareReturn {\n /** Whether the Web Share API is supported in the current environment */\n supported: boolean;\n /** Function to trigger the native share dialog */\n share: (shareParams: ShareData) => Promise<void>;\n}\n\n/**\n * @name useShare\n * @description - Hook that utilizes the share api\n * @category Browser\n *\n * @browserapi share https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share\n *\n * @param {UseShareParams} [params] The use share options\n * @returns {UseShareReturn}\n *\n * @example\n * const { share, supported } = useShare();\n */\nexport const useShare = (params?: UseShareParams) => {\n const supported = typeof navigator !== 'undefined' && 'share' in navigator;\n\n const share = async (shareParams: ShareData) => {\n if (!supported) return;\n\n const data = {\n ...params,\n ...shareParams\n };\n\n if (data.files && navigator.canShare({ files: data.files })) navigator.share(data);\n\n return navigator.share(data);\n };\n\n return { share, supported };\n};\n"],"names":["useShare","params","supported","shareParams","data"],"mappings":"AAiCa,MAAAA,IAAW,CAACC,MAA4B;AACnD,QAAMC,IAAY,OAAO,YAAc,OAAe,WAAW;AAe1D,SAAA,EAAE,OAbK,OAAOC,MAA2B;AAC9C,QAAI,CAACD,EAAW;AAEhB,UAAME,IAAO;AAAA,MACX,GAAGH;AAAA,MACH,GAAGE;AAAA,IACL;AAEA,WAAIC,EAAK,SAAS,UAAU,SAAS,EAAE,OAAOA,EAAK,MAAA,CAAO,KAAa,UAAA,MAAMA,CAAI,GAE1E,UAAU,MAAMA,CAAI;AAAA,EAC7B,GAEgB,WAAAF,EAAU;AAC5B;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStep.mjs","sources":["../../../../src/hooks/useStep/useStep.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\n/** The use step params type */\
|
|
1
|
+
{"version":3,"file":"useStep.mjs","sources":["../../../../src/hooks/useStep/useStep.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\n/** The use step params type */\nexport interface UseStepParams {\n /** Initial value for step */\n initial: number;\n /** Maximum value for step */\n max: number;\n}\n\n/** The use step return type */\nexport interface UseStepReturn {\n /** Counts of steps */\n counts: number;\n /** Current value of step */\n currentStep: number;\n /** Boolean value if current step is first */\n isFirst: boolean;\n /** Boolean value if current step is last */\n isLast: boolean;\n /** Go to back step */\n back: () => void;\n /** Go to next step */\n next: () => void;\n /** Reset current step to initial value */\n reset: () => void;\n /** Go to custom step */\n set: (value: number | 'first' | 'last') => void;\n}\n\nconst FIRST_STEP_VALUE = 1;\n\n/**\n * @name useStep\n * @description - Hook that create stepper\n * @category Utilities\n *\n * @overload\n * @param {number} max Maximum number of steps\n * @returns {UseStepReturn} An object contains variables and functions to change the step\n *\n * @example\n * const stepper = useStep(5);\n *\n * @overload\n * @param {number} params.max Maximum number of steps\n * @param {number} params.initial Initial value for step\n * @returns {UseStepReturn} An object contains variables and functions to change the step\n *\n * @example\n * const stepper = useStep({ initial: 2, max: 5 });\n */\nexport const useStep = (params: number | UseStepParams): UseStepReturn => {\n const max = typeof params === 'object' ? params.max : params;\n const initial = typeof params === 'object' ? params.initial : FIRST_STEP_VALUE;\n\n const initialStep = useRef(\n initial > max || initial < FIRST_STEP_VALUE ? FIRST_STEP_VALUE : initial\n );\n const [currentStep, setCurrentStep] = useState(initial);\n\n const isFirst = currentStep === FIRST_STEP_VALUE;\n const isLast = currentStep === max;\n\n const next = () => {\n if (isLast) return;\n setCurrentStep((prevStep) => prevStep + 1);\n };\n\n const back = () => {\n if (isFirst) return;\n setCurrentStep((prevStep) => prevStep - 1);\n };\n\n const reset = () => setCurrentStep(initialStep.current);\n\n const set = (value: number | 'first' | 'last') => {\n if (value === 'first') return setCurrentStep(initialStep.current);\n if (value === 'last') return setCurrentStep(max);\n if (value >= max) return setCurrentStep(max);\n if (value <= FIRST_STEP_VALUE) return setCurrentStep(FIRST_STEP_VALUE);\n setCurrentStep(value);\n };\n\n return {\n counts: max,\n currentStep,\n isFirst,\n isLast,\n next,\n back,\n reset,\n set\n };\n};\n"],"names":["FIRST_STEP_VALUE","useStep","params","max","initial","initialStep","useRef","currentStep","setCurrentStep","useState","isFirst","isLast","prevStep","value"],"mappings":";AA8BA,MAAMA,IAAmB,GAsBZC,IAAU,CAACC,MAAkD;AACxE,QAAMC,IAAM,OAAOD,KAAW,WAAWA,EAAO,MAAMA,GAChDE,IAAU,OAAOF,KAAW,WAAWA,EAAO,UAAUF,GAExDK,IAAcC;AAAA,IAClBF,IAAUD,KAAOC,IAAUJ,IAAmBA,IAAmBI;AAAA,EACnE,GACM,CAACG,GAAaC,CAAc,IAAIC,EAASL,CAAO,GAEhDM,IAAUH,MAAgBP,GAC1BW,IAASJ,MAAgBJ;AAsBxB,SAAA;AAAA,IACL,QAAQA;AAAA,IACR,aAAAI;AAAA,IACA,SAAAG;AAAA,IACA,QAAAC;AAAA,IACA,MAzBW,MAAM;AACjB,MAAIA,KACWH,EAAA,CAACI,MAAaA,IAAW,CAAC;AAAA,IAC3C;AAAA,IAuBE,MArBW,MAAM;AACjB,MAAIF,KACWF,EAAA,CAACI,MAAaA,IAAW,CAAC;AAAA,IAC3C;AAAA,IAmBE,OAjBY,MAAMJ,EAAeH,EAAY,OAAO;AAAA,IAkBpD,KAhBU,CAACQ,MAAqC;AAChD,UAAIA,MAAU,QAAgB,QAAAL,EAAeH,EAAY,OAAO;AAEhE,UADIQ,MAAU,UACVA,KAASV,EAAY,QAAAK,EAAeL,CAAG;AAC3C,UAAIU,KAASb,EAAyB,QAAAQ,EAAeR,CAAgB;AACrE,MAAAQ,EAAeK,CAAK;AAAA,IACtB;AAAA,EAWA;AACF;"}
|
|
@@ -1,51 +1,55 @@
|
|
|
1
1
|
import { useState as V, useEffect as E } from "react";
|
|
2
|
-
const c = "reactuse-storage",
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
}, z = (
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
},
|
|
9
|
-
const
|
|
10
|
-
if (
|
|
11
|
-
return
|
|
12
|
-
},
|
|
13
|
-
const
|
|
2
|
+
const c = "reactuse-storage", g = (o) => window.dispatchEvent(new StorageEvent(c, o)), l = (o, r, n) => {
|
|
3
|
+
const t = o.getItem(r);
|
|
4
|
+
o.setItem(r, n), g({ key: r, oldValue: t, newValue: n, storageArea: o });
|
|
5
|
+
}, z = (o, r) => {
|
|
6
|
+
const n = o.getItem(r);
|
|
7
|
+
o.removeItem(r), g({ key: r, oldValue: n, newValue: null, storageArea: o });
|
|
8
|
+
}, f = (o, r) => {
|
|
9
|
+
const n = o.getItem(r);
|
|
10
|
+
if (n)
|
|
11
|
+
return n;
|
|
12
|
+
}, h = (...o) => {
|
|
13
|
+
const r = o[0], n = o[1], t = typeof n == "object" && n && ("serializer" in n || "deserializer" in n || "initialValue" in n || "storage" in n) ? n : void 0, i = t ? t == null ? void 0 : t.initialValue : n;
|
|
14
14
|
if (typeof window > "u")
|
|
15
15
|
return {
|
|
16
|
-
value: typeof i == "function" ? i() : i
|
|
16
|
+
value: typeof i == "function" ? i() : i,
|
|
17
|
+
set: () => {
|
|
18
|
+
},
|
|
19
|
+
remove: () => {
|
|
20
|
+
}
|
|
17
21
|
};
|
|
18
|
-
const u = (
|
|
19
|
-
if (
|
|
20
|
-
if (
|
|
22
|
+
const u = (e) => t != null && t.serializer ? t.serializer(e) : typeof e == "string" ? e : JSON.stringify(e), s = (t == null ? void 0 : t.storage) ?? (window == null ? void 0 : window.localStorage), v = (e) => l(s, r, u(e)), m = () => z(s, r), d = (e) => {
|
|
23
|
+
if (t != null && t.deserializer) return t.deserializer(e);
|
|
24
|
+
if (e !== "undefined")
|
|
21
25
|
try {
|
|
22
|
-
return JSON.parse(
|
|
26
|
+
return JSON.parse(e);
|
|
23
27
|
} catch {
|
|
24
|
-
return
|
|
28
|
+
return e;
|
|
25
29
|
}
|
|
26
30
|
}, [w, S] = V(() => {
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
const
|
|
30
|
-
return
|
|
31
|
+
const e = f(s, r);
|
|
32
|
+
if (e === void 0 && i !== void 0) {
|
|
33
|
+
const a = typeof i == "function" ? i() : i;
|
|
34
|
+
return l(s, r, u(a)), a;
|
|
31
35
|
}
|
|
32
|
-
return
|
|
36
|
+
return e ? d(e) : void 0;
|
|
33
37
|
});
|
|
34
38
|
return E(() => {
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
S(
|
|
39
|
+
const e = () => {
|
|
40
|
+
const a = f(s, r);
|
|
41
|
+
S(a ? d(a) : void 0);
|
|
38
42
|
};
|
|
39
|
-
return window.addEventListener(c,
|
|
40
|
-
}, [
|
|
43
|
+
return window.addEventListener(c, e), () => window.removeEventListener(c, e);
|
|
44
|
+
}, [r]), {
|
|
41
45
|
value: w,
|
|
42
|
-
set:
|
|
43
|
-
remove:
|
|
46
|
+
set: v,
|
|
47
|
+
remove: m
|
|
44
48
|
};
|
|
45
49
|
};
|
|
46
50
|
export {
|
|
47
51
|
c as STORAGE_EVENT,
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
g as dispatchStorageEvent,
|
|
53
|
+
h as useStorage
|
|
50
54
|
};
|
|
51
55
|
//# sourceMappingURL=useStorage.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStorage.mjs","sources":["../../../../src/hooks/useStorage/useStorage.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/* The use storage initial value type */\nexport type UseStorageInitialValue<Value> = (() => Value) | Value;\n\n/* The use storage options type */\nexport interface UseStorageOptions<Value> {\n /* The initial value of the storage */\n initialValue?: UseStorageInitialValue<Value>;\n /* The storage to be used */\n storage?: Storage;\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value;\n /* The serializer function to be invoked */\n serializer?: (value: Value) => string;\n}\n\n/* The use storage return type */\nexport interface UseStorageReturn<Value> {\n /* The value of the storage */\n value: Value;\n /* The error state of the storage */\n remove: () => void;\n /* The loading state of the storage */\n set: (value: Value) => void;\n}\n\nexport const STORAGE_EVENT = 'reactuse-storage';\n\nexport const dispatchStorageEvent = (params: Partial<StorageEvent>) =>\n window.dispatchEvent(new StorageEvent(STORAGE_EVENT, params));\n\nconst setStorageItem = (storage: Storage, key: string, value: string) => {\n const oldValue = storage.getItem(key);\n\n storage.setItem(key, value);\n dispatchStorageEvent({ key, oldValue, newValue: value, storageArea: storage });\n};\n\nconst removeStorageItem = (storage: Storage, key: string) => {\n const oldValue = storage.getItem(key);\n\n storage.removeItem(key);\n dispatchStorageEvent({ key, oldValue, newValue: null, storageArea: storage });\n};\n\nconst getStorageItem = (storage: Storage, key: string) => {\n const value = storage.getItem(key);\n if (!value) return undefined;\n return value;\n};\n\n/**\n * @name useStorage\n * @description - Hook that manages storage value\n * @category Browser\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {(value: Value) => string} [params.serializer] The serializer function\n * @param {(value: string) => Value} [params.deserializer] The deserializer function\n * @param {Storage} [params.storage] The storage\n * @param {UseStorageInitialValue<Value>} [params.initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @example\n * const { value, set, remove } = useStorage('key', 'value');\n */\nexport const useStorage = <Value>(\n key
|
|
1
|
+
{"version":3,"file":"useStorage.mjs","sources":["../../../../src/hooks/useStorage/useStorage.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/* The use storage initial value type */\nexport type UseStorageInitialValue<Value> = (() => Value) | Value;\n\n/* The use storage options type */\nexport interface UseStorageOptions<Value> {\n /* The initial value of the storage */\n initialValue?: UseStorageInitialValue<Value>;\n /* The storage to be used */\n storage?: Storage;\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value;\n /* The serializer function to be invoked */\n serializer?: (value: Value) => string;\n}\n\n/* The use storage return type */\nexport interface UseStorageReturn<Value> {\n /* The value of the storage */\n value: Value;\n /* The error state of the storage */\n remove: () => void;\n /* The loading state of the storage */\n set: (value: Value) => void;\n}\n\nexport interface UseStorage {\n <Value>(\n key: string,\n options: UseStorageOptions<Value> & { initialValue: UseStorageInitialValue<Value> }\n ): UseStorageReturn<Value>;\n\n <Value>(key: string, options?: UseStorageOptions<Value>): UseStorageReturn<Value | undefined>;\n\n <Value>(key: string, initialValue: UseStorageInitialValue<Value>): UseStorageReturn<Value>;\n\n <Value>(key: string): UseStorageReturn<Value | undefined>;\n}\n\nexport const STORAGE_EVENT = 'reactuse-storage';\n\nexport const dispatchStorageEvent = (params: Partial<StorageEvent>) =>\n window.dispatchEvent(new StorageEvent(STORAGE_EVENT, params));\n\nconst setStorageItem = (storage: Storage, key: string, value: string) => {\n const oldValue = storage.getItem(key);\n\n storage.setItem(key, value);\n dispatchStorageEvent({ key, oldValue, newValue: value, storageArea: storage });\n};\n\nconst removeStorageItem = (storage: Storage, key: string) => {\n const oldValue = storage.getItem(key);\n\n storage.removeItem(key);\n dispatchStorageEvent({ key, oldValue, newValue: null, storageArea: storage });\n};\n\nconst getStorageItem = (storage: Storage, key: string) => {\n const value = storage.getItem(key);\n if (!value) return undefined;\n return value;\n};\n\n/**\n * @name useStorage\n * @description - Hook that manages storage value\n * @category Browser\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {(value: Value) => string} [params.serializer] The serializer function\n * @param {(value: string) => Value} [params.deserializer] The deserializer function\n * @param {Storage} [params.storage] The storage\n * @param {UseStorageInitialValue<Value>} [params.initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @example\n * const { value, set, remove } = useStorage('key', 'value');\n */\nexport const useStorage = (<Value>(...params: any[]): UseStorageReturn<Value> => {\n const key = params[0] as string;\n const secondParam = params[1];\n\n const options = (\n typeof secondParam === 'object' &&\n secondParam &&\n ('serializer' in secondParam ||\n 'deserializer' in secondParam ||\n 'initialValue' in secondParam ||\n 'storage' in secondParam)\n ? secondParam\n : undefined\n ) as UseStorageOptions<Value>;\n\n const initialValue = (\n options ? options?.initialValue : secondParam\n ) as UseStorageInitialValue<Value>;\n\n if (typeof window === 'undefined') {\n const value = typeof initialValue === 'function' ? (initialValue as () => any)() : initialValue;\n return {\n value,\n set: () => {},\n remove: () => {}\n };\n }\n\n const serializer = (value: Value) => {\n if (options?.serializer) return options.serializer(value);\n if (typeof value === 'string') return value;\n return JSON.stringify(value);\n };\n\n const storage = options?.storage ?? window?.localStorage;\n\n const set = (value: Value) => setStorageItem(storage, key, serializer(value));\n const remove = () => removeStorageItem(storage, key);\n\n const deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined') return undefined as unknown as Value;\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value;\n }\n };\n\n const [value, setValue] = useState<Value | undefined>(() => {\n const storageValue = getStorageItem(storage, key);\n if (storageValue === undefined && initialValue !== undefined) {\n const value =\n typeof initialValue === 'function' ? (initialValue as () => Value)() : initialValue;\n setStorageItem(storage, key, serializer(value));\n return value;\n }\n return storageValue ? deserializer(storageValue) : undefined;\n });\n\n useEffect(() => {\n const onChange = () => {\n const storageValue = getStorageItem(storage, key);\n setValue(storageValue ? deserializer(storageValue) : undefined);\n };\n window.addEventListener(STORAGE_EVENT, onChange);\n return () => window.removeEventListener(STORAGE_EVENT, onChange);\n }, [key]);\n\n return {\n value: value as Value,\n set,\n remove\n };\n}) as UseStorage;\n"],"names":["STORAGE_EVENT","dispatchStorageEvent","params","setStorageItem","storage","key","value","oldValue","removeStorageItem","getStorageItem","useStorage","secondParam","options","initialValue","serializer","set","remove","deserializer","setValue","useState","storageValue","useEffect","onChange"],"mappings":";AAwCO,MAAMA,IAAgB,oBAEhBC,IAAuB,CAACC,MACnC,OAAO,cAAc,IAAI,aAAaF,GAAeE,CAAM,CAAC,GAExDC,IAAiB,CAACC,GAAkBC,GAAaC,MAAkB;AACjE,QAAAC,IAAWH,EAAQ,QAAQC,CAAG;AAE5B,EAAAD,EAAA,QAAQC,GAAKC,CAAK,GAC1BL,EAAqB,EAAE,KAAAI,GAAK,UAAAE,GAAU,UAAUD,GAAO,aAAaF,GAAS;AAC/E,GAEMI,IAAoB,CAACJ,GAAkBC,MAAgB;AACrD,QAAAE,IAAWH,EAAQ,QAAQC,CAAG;AAEpC,EAAAD,EAAQ,WAAWC,CAAG,GACtBJ,EAAqB,EAAE,KAAAI,GAAK,UAAAE,GAAU,UAAU,MAAM,aAAaH,GAAS;AAC9E,GAEMK,IAAiB,CAACL,GAAkBC,MAAgB;AAClD,QAAAC,IAAQF,EAAQ,QAAQC,CAAG;AAC7B,MAACC;AACE,WAAAA;AACT,GAuBaI,IAAc,IAAWR,MAA2C;AACzE,QAAAG,IAAMH,EAAO,CAAC,GACdS,IAAcT,EAAO,CAAC,GAEtBU,IACJ,OAAOD,KAAgB,YACvBA,MACC,gBAAgBA,KACf,kBAAkBA,KAClB,kBAAkBA,KAClB,aAAaA,KACXA,IACA,QAGAE,IACJD,IAAUA,KAAA,gBAAAA,EAAS,eAAeD;AAGhC,MAAA,OAAO,SAAW;AAEb,WAAA;AAAA,MACL,OAFY,OAAOE,KAAiB,aAAcA,EAA+B,IAAAA;AAAA,MAGjF,KAAK,MAAM;AAAA,MAAC;AAAA,M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10,9 @@ export interface UseAsyncReturn<Data> {
|
|
|
10
10
|
* @description - Hook that provides the state of an async callback
|
|
11
11
|
* @category Utilities
|
|
12
12
|
*
|
|
13
|
-
* @param {() => Promise<Data>} callback
|
|
14
|
-
* @param {DependencyList} deps
|
|
15
|
-
* @returns {UseAsyncReturn<Data>}
|
|
13
|
+
* @param {() => Promise<Data>} callback The async callback
|
|
14
|
+
* @param {DependencyList} deps The dependencies of the callback
|
|
15
|
+
* @returns {UseAsyncReturn<Data>} The state of the async callback
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);
|
|
@@ -45,7 +45,7 @@ export interface UseDropZone {
|
|
|
45
45
|
* @param {(event: DragEvent) => void} [options.onEnter] The on enter callback function
|
|
46
46
|
* @param {(event: DragEvent) => void} [options.onLeave] The on leave callback function
|
|
47
47
|
* @param {(event: DragEvent) => void} [options.onOver] The on over callback function
|
|
48
|
-
* @returns {
|
|
48
|
+
* @returns {UseDropZoneReturn} The object with drop zone states
|
|
49
49
|
*
|
|
50
50
|
* @example
|
|
51
51
|
* const { overed, files } = useDropZone(ref, options);
|
|
@@ -53,7 +53,7 @@ export interface UseDropZone {
|
|
|
53
53
|
* @overload
|
|
54
54
|
* @param {Target} target The target element drop zone's
|
|
55
55
|
* @param {(files: File[] | null, event: DragEvent) => void} [callback] The callback function to be invoked on drop
|
|
56
|
-
* @returns {
|
|
56
|
+
* @returns {UseDropZoneReturn} The object with drop zone states
|
|
57
57
|
*
|
|
58
58
|
* @example
|
|
59
59
|
* const { overed, files } = useDropZone(ref, () => console.log('callback'));
|
|
@@ -65,14 +65,14 @@ export interface UseDropZone {
|
|
|
65
65
|
* @param {(event: DragEvent) => void} [options.onEnter] The on enter callback function
|
|
66
66
|
* @param {(event: DragEvent) => void} [options.onLeave] The on leave callback function
|
|
67
67
|
* @param {(event: DragEvent) => void} [options.onOver] The on over callback function
|
|
68
|
-
* @returns {
|
|
68
|
+
* @returns {UseDropZoneReturn & { ref: StateRef<Target> }} The object with drop zone states and ref
|
|
69
69
|
*
|
|
70
70
|
* @example
|
|
71
71
|
* const { ref, overed, files } = useDropZone(options);
|
|
72
72
|
*
|
|
73
73
|
* @overload
|
|
74
74
|
* @param {(files: File[] | null, event: DragEvent) => void} [callback] The callback function to be invoked on drop
|
|
75
|
-
* @returns {
|
|
75
|
+
* @returns {UseDropZoneReturn & { ref: StateRef<Target> }} The object with drop zone states and ref
|
|
76
76
|
*
|
|
77
77
|
* @example
|
|
78
78
|
* const { ref, overed, files } = useDropZone(() => console.log('callback'));
|
|
@@ -14,8 +14,4 @@ import { UseStorageInitialValue, UseStorageOptions } from '../useStorage/useStor
|
|
|
14
14
|
* @example
|
|
15
15
|
* const { value, set, remove } = useLocalStorage('key', 'value');
|
|
16
16
|
*/
|
|
17
|
-
export declare const useLocalStorage: <Value>(key: string, initialValue?: UseStorageInitialValue<Value>, options?: Omit<UseStorageOptions<Value>, "initialValue" | "storage">) =>
|
|
18
|
-
value: Value | undefined;
|
|
19
|
-
set: (value: Value) => void;
|
|
20
|
-
remove: () => void;
|
|
21
|
-
};
|
|
17
|
+
export declare const useLocalStorage: <Value>(key: string, initialValue?: UseStorageInitialValue<Value>, options?: Omit<UseStorageOptions<Value>, "initialValue" | "storage">) => import('..').UseStorageReturn<Value | undefined>;
|
|
@@ -14,8 +14,4 @@ import { UseStorageInitialValue, UseStorageOptions } from '../useStorage/useStor
|
|
|
14
14
|
* @example
|
|
15
15
|
* const { value, set, remove } = useSessionStorage('key', 'value');
|
|
16
16
|
*/
|
|
17
|
-
export declare const useSessionStorage: <Value>(key: string, initialValue?: UseStorageInitialValue<Value>, options?: Omit<UseStorageOptions<Value>, "initialValue" | "storage">) =>
|
|
18
|
-
value: Value | undefined;
|
|
19
|
-
set: (value: Value) => void;
|
|
20
|
-
remove: () => void;
|
|
21
|
-
};
|
|
17
|
+
export declare const useSessionStorage: <Value>(key: string, initialValue?: UseStorageInitialValue<Value>, options?: Omit<UseStorageOptions<Value>, "initialValue" | "storage">) => import('..').UseStorageReturn<Value | undefined>;
|
|
@@ -21,6 +21,8 @@ export interface UseShareReturn {
|
|
|
21
21
|
* @description - Hook that utilizes the share api
|
|
22
22
|
* @category Browser
|
|
23
23
|
*
|
|
24
|
+
* @browserapi share https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share
|
|
25
|
+
*
|
|
24
26
|
* @param {UseShareParams} [params] The use share options
|
|
25
27
|
* @returns {UseShareReturn}
|
|
26
28
|
*
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/** The use step params type */
|
|
2
|
-
interface UseStepParams {
|
|
2
|
+
export interface UseStepParams {
|
|
3
3
|
/** Initial value for step */
|
|
4
4
|
initial: number;
|
|
5
5
|
/** Maximum value for step */
|
|
6
6
|
max: number;
|
|
7
7
|
}
|
|
8
8
|
/** The use step return type */
|
|
9
|
-
interface UseStepReturn {
|
|
9
|
+
export interface UseStepReturn {
|
|
10
10
|
/** Counts of steps */
|
|
11
11
|
counts: number;
|
|
12
12
|
/** Current value of step */
|
|
@@ -45,4 +45,3 @@ interface UseStepReturn {
|
|
|
45
45
|
* const stepper = useStep({ initial: 2, max: 5 });
|
|
46
46
|
*/
|
|
47
47
|
export declare const useStep: (params: number | UseStepParams) => UseStepReturn;
|
|
48
|
-
export {};
|
|
@@ -10,6 +10,14 @@ export interface UseStorageReturn<Value> {
|
|
|
10
10
|
remove: () => void;
|
|
11
11
|
set: (value: Value) => void;
|
|
12
12
|
}
|
|
13
|
+
export interface UseStorage {
|
|
14
|
+
<Value>(key: string, options: UseStorageOptions<Value> & {
|
|
15
|
+
initialValue: UseStorageInitialValue<Value>;
|
|
16
|
+
}): UseStorageReturn<Value>;
|
|
17
|
+
<Value>(key: string, options?: UseStorageOptions<Value>): UseStorageReturn<Value | undefined>;
|
|
18
|
+
<Value>(key: string, initialValue: UseStorageInitialValue<Value>): UseStorageReturn<Value>;
|
|
19
|
+
<Value>(key: string): UseStorageReturn<Value | undefined>;
|
|
20
|
+
}
|
|
13
21
|
export declare const STORAGE_EVENT = "reactuse-storage";
|
|
14
22
|
export declare const dispatchStorageEvent: (params: Partial<StorageEvent>) => boolean;
|
|
15
23
|
/**
|
|
@@ -33,8 +41,4 @@ export declare const dispatchStorageEvent: (params: Partial<StorageEvent>) => bo
|
|
|
33
41
|
* @example
|
|
34
42
|
* const { value, set, remove } = useStorage('key', 'value');
|
|
35
43
|
*/
|
|
36
|
-
export declare const useStorage:
|
|
37
|
-
value: Value | undefined;
|
|
38
|
-
set: (value: Value) => void;
|
|
39
|
-
remove: () => void;
|
|
40
|
-
};
|
|
44
|
+
export declare const useStorage: UseStorage;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@siberiacancode/reactuse",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "The ultimate collection of react hooks",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "SIBERIA CAN CODE 🧊",
|
|
@@ -68,17 +68,17 @@
|
|
|
68
68
|
"@testing-library/dom": "^10.4.0",
|
|
69
69
|
"@testing-library/react": "^16.3.0",
|
|
70
70
|
"@types/dom-speech-recognition": "^0.0.6",
|
|
71
|
-
"@types/react": "^19.1.
|
|
72
|
-
"@types/react-dom": "^19.1.
|
|
71
|
+
"@types/react": "^19.1.7",
|
|
72
|
+
"@types/react-dom": "^19.1.6",
|
|
73
73
|
"@types/web-bluetooth": "^0.0.21",
|
|
74
|
-
"@vitejs/plugin-react": "^4.5.
|
|
75
|
-
"core-js": "^3.
|
|
74
|
+
"@vitejs/plugin-react": "^4.5.2",
|
|
75
|
+
"core-js": "^3.43.0",
|
|
76
76
|
"react": "^19.1.0",
|
|
77
77
|
"react-dom": "^19.1.0",
|
|
78
78
|
"shx": "^0.4.0",
|
|
79
79
|
"vite": "^6.3.5",
|
|
80
80
|
"vite-plugin-dts": "^4.5.4",
|
|
81
|
-
"vitest": "^3.2.
|
|
81
|
+
"vitest": "^3.2.3"
|
|
82
82
|
},
|
|
83
83
|
"lint-staged": {
|
|
84
84
|
"*.{js,ts,tsx}": [
|