@siberiacancode/reactuse 0.2.32 → 0.2.34
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/hooks/useHash/useHash.cjs +1 -1
- package/dist/cjs/hooks/useHash/useHash.cjs.map +1 -1
- package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs.map +1 -1
- 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/hooks/useHash/useHash.mjs +16 -9
- package/dist/esm/hooks/useHash/useHash.mjs.map +1 -1
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs +8 -1
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
- package/dist/esm/index.mjs +267 -262
- 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/dist/types/hooks/useHash/useHash.d.ts +33 -2
- package/dist/types/hooks/useIntersectionObserver/useIntersectionObserver.d.ts +1 -1
- package/package.json +89 -89
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -5,6 +5,7 @@ export * from './useDoubleClick/useDoubleClick';
|
|
|
5
5
|
export * from './useDropZone/useDropZone';
|
|
6
6
|
export * from './useFileDialog/useFileDialog';
|
|
7
7
|
export * from './useFocus/useFocus';
|
|
8
|
+
export * from './useFocusTrap/useFocusTrap';
|
|
8
9
|
export * from './useHover/useHover';
|
|
9
10
|
export * from './useImage/useImage';
|
|
10
11
|
export * from './useLongPress/useLongPress';
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { HookTarget } from '../../utils/helpers';
|
|
2
2
|
import { StateRef } from '../useRefState/useRefState';
|
|
3
|
+
/** The use active element return type */
|
|
4
|
+
export type UseActiveElementReturn<ActiveElement extends HTMLElement = HTMLElement> = ActiveElement | null;
|
|
3
5
|
export interface UseActiveElement {
|
|
4
|
-
():
|
|
6
|
+
(): UseActiveElementReturn;
|
|
5
7
|
<Target extends Element, ActiveElement extends HTMLElement = HTMLElement>(target?: never): {
|
|
6
8
|
ref: StateRef<Target>;
|
|
7
|
-
value: ActiveElement
|
|
9
|
+
value: UseActiveElementReturn<ActiveElement>;
|
|
8
10
|
};
|
|
9
|
-
<ActiveElement extends HTMLElement = HTMLElement>(target: HookTarget): ActiveElement
|
|
11
|
+
<ActiveElement extends HTMLElement = HTMLElement>(target: HookTarget): UseActiveElementReturn<ActiveElement>;
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
12
14
|
* @name useActiveElement
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DependencyList } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* @name useAsyncEffect
|
|
4
|
+
* @description – Hook that triggers the effect callback on updates
|
|
5
|
+
* @category Lifecycle
|
|
6
|
+
* @usage medium
|
|
7
|
+
|
|
8
|
+
* @param {EffectCallback} effect The effect callback
|
|
9
|
+
* @param {DependencyList} [deps] The dependencies list for the effect
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* useAsyncEffect(async () => console.log("effect runs on updates"), deps);
|
|
13
|
+
*/
|
|
14
|
+
export declare const useAsyncEffect: (сallback: () => Promise<any>, deps?: DependencyList) => void;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { HookTarget } from '../../utils/helpers';
|
|
2
|
+
import { StateRef } from '../useRefState/useRefState';
|
|
3
|
+
/** The use focus trap return type */
|
|
4
|
+
export interface UseFocusTrapReturn {
|
|
5
|
+
/** Whether focus trap is active */
|
|
6
|
+
active: boolean;
|
|
7
|
+
/** Disable focus trap */
|
|
8
|
+
disable: () => void;
|
|
9
|
+
/** Enable focus trap */
|
|
10
|
+
enable: () => void;
|
|
11
|
+
/** Toggle focus trap */
|
|
12
|
+
toggle: () => void;
|
|
13
|
+
}
|
|
14
|
+
export interface UseFocusTrap {
|
|
15
|
+
(target: HookTarget, active?: boolean): UseFocusTrapReturn;
|
|
16
|
+
<Target extends HTMLElement>(active?: boolean, target?: never): UseFocusTrapReturn & {
|
|
17
|
+
ref: StateRef<Target>;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @name useFocusTrap
|
|
22
|
+
* @description - Hook that traps focus within a given element
|
|
23
|
+
* @category Elements
|
|
24
|
+
* @usage medium
|
|
25
|
+
*
|
|
26
|
+
* @overload
|
|
27
|
+
* @param {HookTarget} target The target element for focus trap
|
|
28
|
+
* @param {boolean} [active=true] Whether focus trap is active
|
|
29
|
+
* @returns {UseFocusTrapReturn} Object with control methods and state
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const { active, disable, toggle, enable } = useFocusTrap(ref, true);
|
|
33
|
+
*
|
|
34
|
+
* @overload
|
|
35
|
+
* @template Target The target element type
|
|
36
|
+
* @param {boolean} [active=true] Whether focus trap is active
|
|
37
|
+
* @returns {UseFocusTrapReturn & { ref: StateRef<Target> }} Object with ref and controls
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* const { ref, active, disable, toggle, enable } = useFocusTrap(true);
|
|
41
|
+
*/
|
|
42
|
+
export declare const useFocusTrap: UseFocusTrap;
|
|
@@ -1,16 +1,47 @@
|
|
|
1
|
+
export declare const getHash: () => string;
|
|
2
|
+
/** The use hash options type */
|
|
3
|
+
export interface UseHashOptions {
|
|
4
|
+
/** The enabled state of the hook */
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
/** The mode of hash setting */
|
|
7
|
+
mode?: 'initial' | 'replace';
|
|
8
|
+
/** Callback function called when hash changes */
|
|
9
|
+
onChange?: (hash: string) => void;
|
|
10
|
+
}
|
|
1
11
|
/** The use hash return type */
|
|
2
12
|
type UseHashReturn = [string, (value: string) => void];
|
|
13
|
+
export interface UseHash {
|
|
14
|
+
(initialValue?: string, options?: UseHashOptions): UseHashReturn;
|
|
15
|
+
(initialValue?: string, callback?: (hash: string) => void): UseHashReturn;
|
|
16
|
+
}
|
|
3
17
|
/**
|
|
4
18
|
* @name useHash
|
|
5
19
|
* @description - Hook that manages the hash value
|
|
6
20
|
* @category State
|
|
7
21
|
* @usage low
|
|
8
22
|
*
|
|
23
|
+
* @overload
|
|
9
24
|
* @param {string} [initialValue] The initial hash value if no hash exists
|
|
25
|
+
* @param {UseHashOptions} [options] Configuration options
|
|
26
|
+
* @param {boolean} [options.enabled] The enabled state of the hook
|
|
27
|
+
* @param {'initial' | 'replace'} [options.mode] The mode of hash setting
|
|
28
|
+
* @param {(hash: string) => void} [options.onChange] Callback function called when hash changes
|
|
10
29
|
* @returns {UseHashReturn} An array containing the hash value and a function to set the hash value
|
|
11
30
|
*
|
|
12
31
|
* @example
|
|
13
|
-
* const [hash, setHash] = useHash("initial"
|
|
32
|
+
* const [hash, setHash] = useHash("initial", {
|
|
33
|
+
* enabled: true,
|
|
34
|
+
* mode: "replace",
|
|
35
|
+
* onChange: (newHash) => console.log('Hash changed:', newHash)
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* @overload
|
|
39
|
+
* @param {string} [initialValue] The initial hash value if no hash exists
|
|
40
|
+
* @param {(hash: string) => void} [callback] Callback function called when hash changes
|
|
41
|
+
* @returns {UseHashReturn} An array containing the hash value and a function to set the hash value
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* const [hash, setHash] = useHash("initial", (newHash) => console.log('Hash changed:', newHash));
|
|
14
45
|
*/
|
|
15
|
-
export declare const useHash:
|
|
46
|
+
export declare const useHash: UseHash;
|
|
16
47
|
export {};
|
|
@@ -3,7 +3,7 @@ import { StateRef } from '../useRefState/useRefState';
|
|
|
3
3
|
/** The intersection observer callback type */
|
|
4
4
|
export type UseIntersectionObserverCallback = (entry: IntersectionObserverEntry, observer: IntersectionObserver) => void;
|
|
5
5
|
/** The intersection observer options type */
|
|
6
|
-
export interface UseIntersectionObserverOptions extends Omit<IntersectionObserverInit,
|
|
6
|
+
export interface UseIntersectionObserverOptions extends Omit<IntersectionObserverInit, "root"> {
|
|
7
7
|
/** The enabled state of the intersection observer */
|
|
8
8
|
enabled?: boolean;
|
|
9
9
|
/** The callback to execute when intersection is detected */
|
package/package.json
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@siberiacancode/reactuse",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "The ultimate collection of react hooks",
|
|
5
|
-
"author": {
|
|
6
|
-
"name": "SIBERIA CAN CODE 🧊",
|
|
7
|
-
"url": "https://github.com/siberiacancode"
|
|
8
|
-
},
|
|
9
|
-
"license": "MIT",
|
|
10
|
-
"homepage": "https://siberiacancode.github.io/reactuse/",
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/siberiacancode/reactuse.git",
|
|
14
|
-
"directory": "packages/core"
|
|
15
|
-
},
|
|
16
|
-
"bugs": "https://github.com/siberiacancode/reactuse/issues",
|
|
17
|
-
"keywords": [
|
|
18
|
-
"react",
|
|
19
|
-
"react hooks",
|
|
20
|
-
"react use",
|
|
21
|
-
"use",
|
|
22
|
-
"hooks"
|
|
23
|
-
],
|
|
24
|
-
"sideEffects": false,
|
|
25
|
-
"exports": {
|
|
26
|
-
"types": "./dist/types/index.d.ts",
|
|
27
|
-
"import": "./dist/esm/index.mjs",
|
|
28
|
-
"require": "./dist/cjs/index.cjs"
|
|
29
|
-
},
|
|
30
|
-
"main": "dist/cjs/index.cjs",
|
|
31
|
-
"module": "dist/esm/index.mjs",
|
|
32
|
-
"types": "dist/types/index.d.ts",
|
|
33
|
-
"files": [
|
|
34
|
-
"dist"
|
|
35
|
-
],
|
|
36
|
-
"engines": {
|
|
37
|
-
"node": ">=14"
|
|
38
|
-
},
|
|
39
|
-
"publishConfig": {
|
|
40
|
-
"access": "public"
|
|
41
|
-
},
|
|
42
|
-
"scripts": {
|
|
43
|
-
"prepublishOnly": "pnpm unit-test run && pnpm build",
|
|
44
|
-
"build": "shx rm -rf dist && vite build",
|
|
45
|
-
"build:js": "tsc --project tsconfig.build.json && prettier --write src/bundle",
|
|
46
|
-
"lint": "eslint . --fix",
|
|
47
|
-
"lint-inspector": "npx @eslint/config-inspector@latest",
|
|
48
|
-
"format": "prettier --write .",
|
|
49
|
-
"pretty": "pnpm lint && pnpm format",
|
|
50
|
-
"unit-test": "vitest",
|
|
51
|
-
"lint-staged": "lint-staged"
|
|
52
|
-
},
|
|
53
|
-
"peerDependencies": {
|
|
54
|
-
"@types/react": "^18 || ^19",
|
|
55
|
-
"react": "^18 || ^19",
|
|
56
|
-
"react-dom": "^18 || ^19"
|
|
57
|
-
},
|
|
58
|
-
"peerDependenciesMeta": {
|
|
59
|
-
"@types/react": {
|
|
60
|
-
"optional": true
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
"dependencies": {
|
|
64
|
-
"screenfull": "^6.0.2"
|
|
65
|
-
},
|
|
66
|
-
"devDependencies": {
|
|
67
|
-
"@siberiacancode/vitest": "^2.1.0",
|
|
68
|
-
"@testing-library/dom": "^10.4.1",
|
|
69
|
-
"@testing-library/react": "^16.3.0",
|
|
70
|
-
"@types/dom-speech-recognition": "^0.0.6",
|
|
71
|
-
"@types/react": "^19.1.10",
|
|
72
|
-
"@types/react-dom": "^19.1.7",
|
|
73
|
-
"@types/web-bluetooth": "^0.0.21",
|
|
74
|
-
"@vitejs/plugin-react": "^5.0.1",
|
|
75
|
-
"core-js": "^3.45.0",
|
|
76
|
-
"react": "^19.1.1",
|
|
77
|
-
"react-dom": "^19.1.1",
|
|
78
|
-
"shx": "^0.4.0",
|
|
79
|
-
"vite": "^7.1.3",
|
|
80
|
-
"vite-plugin-dts": "^4.5.4",
|
|
81
|
-
"vitest": "^3.2.4"
|
|
82
|
-
},
|
|
83
|
-
"lint-staged": {
|
|
84
|
-
"*.{js,ts,tsx}": [
|
|
85
|
-
"eslint --fix",
|
|
86
|
-
"prettier --write"
|
|
87
|
-
]
|
|
88
|
-
}
|
|
89
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@siberiacancode/reactuse",
|
|
3
|
+
"version": "0.2.34",
|
|
4
|
+
"description": "The ultimate collection of react hooks",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "SIBERIA CAN CODE 🧊",
|
|
7
|
+
"url": "https://github.com/siberiacancode"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"homepage": "https://siberiacancode.github.io/reactuse/",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/siberiacancode/reactuse.git",
|
|
14
|
+
"directory": "packages/core"
|
|
15
|
+
},
|
|
16
|
+
"bugs": "https://github.com/siberiacancode/reactuse/issues",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"react",
|
|
19
|
+
"react hooks",
|
|
20
|
+
"react use",
|
|
21
|
+
"use",
|
|
22
|
+
"hooks"
|
|
23
|
+
],
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"exports": {
|
|
26
|
+
"types": "./dist/types/index.d.ts",
|
|
27
|
+
"import": "./dist/esm/index.mjs",
|
|
28
|
+
"require": "./dist/cjs/index.cjs"
|
|
29
|
+
},
|
|
30
|
+
"main": "dist/cjs/index.cjs",
|
|
31
|
+
"module": "dist/esm/index.mjs",
|
|
32
|
+
"types": "dist/types/index.d.ts",
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=14"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"prepublishOnly": "pnpm unit-test run && pnpm build",
|
|
44
|
+
"build": "shx rm -rf dist && vite build",
|
|
45
|
+
"build:js": "tsc --project tsconfig.build.json && prettier --write src/bundle",
|
|
46
|
+
"lint": "eslint . --fix",
|
|
47
|
+
"lint-inspector": "npx @eslint/config-inspector@latest",
|
|
48
|
+
"format": "prettier --write .",
|
|
49
|
+
"pretty": "pnpm lint && pnpm format",
|
|
50
|
+
"unit-test": "vitest",
|
|
51
|
+
"lint-staged": "lint-staged"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@types/react": "^18 || ^19",
|
|
55
|
+
"react": "^18 || ^19",
|
|
56
|
+
"react-dom": "^18 || ^19"
|
|
57
|
+
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"@types/react": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"screenfull": "^6.0.2"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@siberiacancode/vitest": "^2.1.0",
|
|
68
|
+
"@testing-library/dom": "^10.4.1",
|
|
69
|
+
"@testing-library/react": "^16.3.0",
|
|
70
|
+
"@types/dom-speech-recognition": "^0.0.6",
|
|
71
|
+
"@types/react": "^19.1.10",
|
|
72
|
+
"@types/react-dom": "^19.1.7",
|
|
73
|
+
"@types/web-bluetooth": "^0.0.21",
|
|
74
|
+
"@vitejs/plugin-react": "^5.0.1",
|
|
75
|
+
"core-js": "^3.45.0",
|
|
76
|
+
"react": "^19.1.1",
|
|
77
|
+
"react-dom": "^19.1.1",
|
|
78
|
+
"shx": "^0.4.0",
|
|
79
|
+
"vite": "^7.1.3",
|
|
80
|
+
"vite-plugin-dts": "^4.5.4",
|
|
81
|
+
"vitest": "^3.2.4"
|
|
82
|
+
},
|
|
83
|
+
"lint-staged": {
|
|
84
|
+
"*.{js,ts,tsx}": [
|
|
85
|
+
"eslint --fix",
|
|
86
|
+
"prettier --write"
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
}
|