@siberiacancode/reactuse 0.2.32 → 0.2.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/README.md +71 -71
  2. package/dist/cjs/helpers/createStore/createStore.cjs +1 -1
  3. package/dist/cjs/helpers/createStore/createStore.cjs.map +1 -1
  4. package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs +1 -1
  5. package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs.map +1 -1
  6. package/dist/cjs/hooks/useAsyncEffect/useAsyncEffect.cjs +2 -0
  7. package/dist/cjs/hooks/useAsyncEffect/useAsyncEffect.cjs.map +1 -0
  8. package/dist/cjs/hooks/useFocusTrap/useFocusTrap.cjs +2 -0
  9. package/dist/cjs/hooks/useFocusTrap/useFocusTrap.cjs.map +1 -0
  10. package/dist/cjs/index.cjs +1 -1
  11. package/dist/esm/helpers/createStore/createStore.mjs +4 -4
  12. package/dist/esm/helpers/createStore/createStore.mjs.map +1 -1
  13. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs +5 -7
  14. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
  15. package/dist/esm/hooks/useAsyncEffect/useAsyncEffect.mjs +10 -0
  16. package/dist/esm/hooks/useAsyncEffect/useAsyncEffect.mjs.map +1 -0
  17. package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs +56 -0
  18. package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs.map +1 -0
  19. package/dist/esm/index.mjs +262 -258
  20. package/dist/esm/index.mjs.map +1 -1
  21. package/dist/types/hooks/elements.d.ts +1 -0
  22. package/dist/types/hooks/lifecycle.d.ts +1 -0
  23. package/dist/types/hooks/useActiveElement/useActiveElement.d.ts +5 -3
  24. package/dist/types/hooks/useAsyncEffect/useAsyncEffect.d.ts +14 -0
  25. package/dist/types/hooks/useFocusTrap/useFocusTrap.d.ts +42 -0
  26. package/package.json +89 -89
@@ -1,3 +1,4 @@
1
+ export * from './useAsyncEffect/useAsyncEffect';
1
2
  export * from './useDidUpdate/useDidUpdate';
2
3
  export * from './useIsFirstRender/useIsFirstRender';
3
4
  export * from './useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';
@@ -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
- (): HTMLElement | null;
6
+ (): UseActiveElementReturn;
5
7
  <Target extends Element, ActiveElement extends HTMLElement = HTMLElement>(target?: never): {
6
8
  ref: StateRef<Target>;
7
- value: ActiveElement | null;
9
+ value: UseActiveElementReturn<ActiveElement>;
8
10
  };
9
- <ActiveElement extends HTMLElement = HTMLElement>(target: HookTarget): ActiveElement | null;
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;
package/package.json CHANGED
@@ -1,89 +1,89 @@
1
- {
2
- "name": "@siberiacancode/reactuse",
3
- "version": "0.2.32",
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.33",
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
+ }