@siberiacancode/reactuse 0.2.31 → 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 (37) 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/useControllableState/useControllableState.cjs +2 -0
  9. package/dist/cjs/hooks/useControllableState/useControllableState.cjs.map +1 -0
  10. package/dist/cjs/hooks/useFocusTrap/useFocusTrap.cjs +2 -0
  11. package/dist/cjs/hooks/useFocusTrap/useFocusTrap.cjs.map +1 -0
  12. package/dist/cjs/hooks/useScroll/useScroll.cjs +1 -1
  13. package/dist/cjs/hooks/useScroll/useScroll.cjs.map +1 -1
  14. package/dist/cjs/index.cjs +1 -1
  15. package/dist/esm/helpers/createStore/createStore.mjs +4 -4
  16. package/dist/esm/helpers/createStore/createStore.mjs.map +1 -1
  17. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs +5 -7
  18. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
  19. package/dist/esm/hooks/useAsyncEffect/useAsyncEffect.mjs +10 -0
  20. package/dist/esm/hooks/useAsyncEffect/useAsyncEffect.mjs.map +1 -0
  21. package/dist/esm/hooks/useControllableState/useControllableState.mjs +17 -0
  22. package/dist/esm/hooks/useControllableState/useControllableState.mjs.map +1 -0
  23. package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs +56 -0
  24. package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs.map +1 -0
  25. package/dist/esm/hooks/useScroll/useScroll.mjs +53 -35
  26. package/dist/esm/hooks/useScroll/useScroll.mjs.map +1 -1
  27. package/dist/esm/index.mjs +270 -264
  28. package/dist/esm/index.mjs.map +1 -1
  29. package/dist/types/hooks/elements.d.ts +1 -0
  30. package/dist/types/hooks/lifecycle.d.ts +1 -0
  31. package/dist/types/hooks/state.d.ts +1 -0
  32. package/dist/types/hooks/useActiveElement/useActiveElement.d.ts +5 -3
  33. package/dist/types/hooks/useAsyncEffect/useAsyncEffect.d.ts +14 -0
  34. package/dist/types/hooks/useControllableState/useControllableState.d.ts +34 -0
  35. package/dist/types/hooks/useFocusTrap/useFocusTrap.d.ts +42 -0
  36. package/dist/types/hooks/useScroll/useScroll.d.ts +33 -14
  37. package/package.json +89 -89
@@ -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,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,4 +1,5 @@
1
1
  export * from './useBoolean/useBoolean';
2
+ export * from './useControllableState/useControllableState';
2
3
  export * from './useCookie/useCookie';
3
4
  export * from './useCookies/useCookies';
4
5
  export * from './useCounter/useCounter';
@@ -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,34 @@
1
+ /** The use controllable state options type */
2
+ export interface UseControllableStateOptions<Value> {
3
+ /** The initial value for uncontrolled state */
4
+ initialValue?: Value;
5
+ /** The controlled value */
6
+ value?: Value;
7
+ /** The onChange callback */
8
+ onChange?: (value: Value) => void;
9
+ }
10
+ /** The use controllable state return type */
11
+ export type UseControllableStateReturn<Value> = [
12
+ /** Current value */
13
+ value: Value,
14
+ /** Setter function that works with both controlled and uncontrolled state */
15
+ setValue: (nextValue: ((prevValue: Value) => Value) | Value) => void,
16
+ /** Whether the state is controlled */
17
+ isControlled: boolean
18
+ ];
19
+ /**
20
+ * @name useControllableState
21
+ * @description - Hook that manages both controlled and uncontrolled state patterns
22
+ * @category State
23
+ * @usage medium
24
+ *
25
+ * @template Value The type of the state value
26
+ * @param {Value} [options.value] The controlled value. When provided, the component becomes controlled
27
+ * @param {Value} [options.initialValue] The initial value for uncontrolled state
28
+ * @param {(value: Value) => void} [options.onChange] The callback function called when the state changes
29
+ * @returns {UseControllableStateReturn<Value>} A tuple containing the current value, setter function, and controlled flag
30
+ *
31
+ * @example
32
+ * const [value, setValue, isControlled] = useControllableState({ initialValue: 'initial' });
33
+ */
34
+ export declare function useControllableState<Value>(options: UseControllableStateOptions<Value>): UseControllableStateReturn<Value>;
@@ -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;
@@ -33,16 +33,35 @@ export interface UseScrollCallbackParams {
33
33
  bottom: boolean;
34
34
  };
35
35
  }
36
+ /** The scroll into view params type */
37
+ export interface ScrollIntoViewParams {
38
+ behavior?: ScrollBehavior;
39
+ block?: ScrollLogicalPosition;
40
+ inline?: ScrollLogicalPosition;
41
+ }
42
+ /** The scroll to params type */
43
+ export interface ScrollToParams {
44
+ behavior?: ScrollBehavior;
45
+ x: number;
46
+ y: number;
47
+ }
48
+ /** The use scroll return type */
49
+ export interface UseScrollReturn {
50
+ /** The state of scrolling */
51
+ scrolling: boolean;
52
+ /** Function to scroll element into view */
53
+ scrollIntoView: (params?: ScrollIntoViewParams) => void;
54
+ /** Function to scroll element to a specific position */
55
+ scrollTo: (params?: ScrollToParams) => void;
56
+ }
36
57
  export interface UseScroll {
37
- (target?: HookTarget, callback?: (params: UseScrollCallbackParams, event: Event) => void): boolean;
38
- (target?: HookTarget, options?: UseScrollOptions): boolean;
39
- <Target extends Element>(callback?: (params: UseScrollCallbackParams, event: Event) => void, target?: never): {
58
+ (target?: HookTarget, callback?: (params: UseScrollCallbackParams, event: Event) => void): UseScrollReturn;
59
+ (target?: HookTarget, options?: UseScrollOptions): UseScrollReturn;
60
+ <Target extends Element>(callback?: (params: UseScrollCallbackParams, event: Event) => void, target?: never): UseScrollReturn & {
40
61
  ref: StateRef<Target>;
41
- scrolling: boolean;
42
62
  };
43
- <Target extends Element>(options?: UseScrollOptions, target?: never): {
63
+ <Target extends Element>(options?: UseScrollOptions, target?: never): UseScrollReturn & {
44
64
  ref: StateRef<Target>;
45
- scrolling: boolean;
46
65
  };
47
66
  }
48
67
  /**
@@ -60,18 +79,18 @@ export interface UseScroll {
60
79
  * @param {number} [options.offset.bottom=0] The bottom offset for arrived states
61
80
  * @param {(params: UseScrollCallbackParams, event: Event) => void} [options.onScroll] The callback function to be invoked on scroll
62
81
  * @param {(event: Event) => void} [options.onStop] The callback function to be invoked on scroll end
63
- * @returns {boolean} The state of scrolling
82
+ * @returns {UseScrollReturn} The state of scrolling
64
83
  *
65
84
  * @example
66
- * const scrolling = useScroll(ref, options);
85
+ * const { scrolling, scrollIntoView, scrollTo} = useScroll(ref, options);
67
86
  *
68
87
  * @overload
69
88
  * @template Target The target element
70
89
  * @param {(params: UseScrollCallbackParams, event: Event) => void} [callback] The callback function to be invoked on scroll
71
- * @returns {boolean} The state of scrolling
90
+ * @returns {UseScrollReturn} The state of scrolling
72
91
  *
73
92
  * @example
74
- * const scrolling = useScroll(ref, () => console.log('callback'));
93
+ * const { scrolling, scrollIntoView, scrollTo} = useScroll(ref, () => console.log('callback'));
75
94
  *
76
95
  * @overload
77
96
  * @template Target The target element
@@ -83,18 +102,18 @@ export interface UseScroll {
83
102
  * @param {number} [options.offset.bottom=0] The bottom offset for arrived states
84
103
  * @param {(params: UseScrollCallbackParams, event: Event) => void} [options.onScroll] The callback function to be invoked on scroll
85
104
  * @param {(event: Event) => void} [options.onStop] The callback function to be invoked on scroll end
86
- * @returns {[StateRef<Target>, boolean]} The state of scrolling
105
+ * @returns {UseScrollReturn & { ref: StateRef<Target> }} The state of scrolling
87
106
  *
88
107
  * @example
89
- * const { ref, scrolling } = useScroll(options);
108
+ * const { ref, scrolling, scrollIntoView, scrollTo} = useScroll(options);
90
109
  *
91
110
  * @overload
92
111
  * @template Target The target element
93
112
  * @param {Target} target The target element to scroll
94
113
  * @param {(params: UseScrollCallbackParams, event: Event) => void} [callback] The callback function to be invoked on scroll
95
- * @returns {[StateRef<Target>, boolean]} The state of scrolling
114
+ * @returns {UseScrollReturn & { ref: StateRef<Target> }} The state of scrolling
96
115
  *
97
116
  * @example
98
- * const { ref, scrolling } = useScroll(() => console.log('callback'));
117
+ * const { ref, scrolling, scrollIntoView, scrollTo} = useScroll(() => console.log('callback'));
99
118
  */
100
119
  export declare const useScroll: UseScroll;
package/package.json CHANGED
@@ -1,89 +1,89 @@
1
- {
2
- "name": "@siberiacancode/reactuse",
3
- "version": "0.2.31",
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
+ }