@siberiacancode/reactuse 0.2.23 → 0.2.25

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 (57) hide show
  1. package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs +1 -1
  2. package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs.map +1 -1
  3. package/dist/cjs/hooks/useAudio/useAudio.cjs.map +1 -1
  4. package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs +2 -0
  5. package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs.map +1 -0
  6. package/dist/cjs/hooks/useBattery/useBattery.cjs.map +1 -1
  7. package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs +1 -1
  8. package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs.map +1 -1
  9. package/dist/cjs/hooks/useEvent/useEvent.cjs +1 -1
  10. package/dist/cjs/hooks/useEvent/useEvent.cjs.map +1 -1
  11. package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs +1 -1
  12. package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs.map +1 -1
  13. package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs +1 -1
  14. package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs.map +1 -1
  15. package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs.map +1 -1
  16. package/dist/cjs/hooks/useLockCallback/useLockCallback.cjs +1 -1
  17. package/dist/cjs/hooks/useLockCallback/useLockCallback.cjs.map +1 -1
  18. package/dist/cjs/hooks/useMemory/useMemory.cjs.map +1 -1
  19. package/dist/cjs/hooks/useScroll/useScroll.cjs.map +1 -1
  20. package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs +1 -1
  21. package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs.map +1 -1
  22. package/dist/cjs/hooks/useWindowEvent/useWindowEvent.cjs.map +1 -1
  23. package/dist/cjs/hooks/useWindowScroll/useWindowScroll.cjs.map +1 -1
  24. package/dist/cjs/index.cjs +1 -1
  25. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs +23 -17
  26. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
  27. package/dist/esm/hooks/useAudio/useAudio.mjs.map +1 -1
  28. package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs +48 -0
  29. package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs.map +1 -0
  30. package/dist/esm/hooks/useBattery/useBattery.mjs.map +1 -1
  31. package/dist/esm/hooks/useClickOutside/useClickOutside.mjs +12 -12
  32. package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
  33. package/dist/esm/hooks/useEvent/useEvent.mjs +6 -6
  34. package/dist/esm/hooks/useEvent/useEvent.mjs.map +1 -1
  35. package/dist/esm/hooks/useKeyPress/useKeyPress.mjs.map +1 -1
  36. package/dist/esm/hooks/useKeyboard/useKeyboard.mjs +15 -15
  37. package/dist/esm/hooks/useKeyboard/useKeyboard.mjs.map +1 -1
  38. package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs.map +1 -1
  39. package/dist/esm/hooks/useLockCallback/useLockCallback.mjs.map +1 -1
  40. package/dist/esm/hooks/useMemory/useMemory.mjs.map +1 -1
  41. package/dist/esm/hooks/useScroll/useScroll.mjs.map +1 -1
  42. package/dist/esm/hooks/useStopwatch/useStopwatch.mjs +18 -18
  43. package/dist/esm/hooks/useStopwatch/useStopwatch.mjs.map +1 -1
  44. package/dist/esm/hooks/useWindowEvent/useWindowEvent.mjs.map +1 -1
  45. package/dist/esm/hooks/useWindowScroll/useWindowScroll.mjs.map +1 -1
  46. package/dist/esm/index.mjs +336 -334
  47. package/dist/esm/index.mjs.map +1 -1
  48. package/dist/types/hooks/index.d.ts +1 -0
  49. package/dist/types/hooks/useActiveElement/useActiveElement.d.ts +21 -2
  50. package/dist/types/hooks/useAutoScroll/useAutoScroll.d.ts +35 -0
  51. package/dist/types/hooks/useKeyPress/useKeyPress.d.ts +1 -1
  52. package/dist/types/hooks/useKeyboard/useKeyboard.d.ts +28 -8
  53. package/dist/types/hooks/useStopwatch/useStopwatch.d.ts +2 -2
  54. package/dist/types/hooks/useWindowEvent/useWindowEvent.d.ts +1 -1
  55. package/dist/types/hooks/useWindowScroll/useWindowScroll.d.ts +1 -1
  56. package/dist/types/utils/helpers/getElement.d.ts +1 -1
  57. 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,6 +1,7 @@
1
1
  export * from './useActiveElement/useActiveElement';
2
2
  export * from './useAsync/useAsync';
3
3
  export * from './useAudio/useAudio';
4
+ export * from './useAutoScroll/useAutoScroll';
4
5
  export * from './useBattery/useBattery';
5
6
  export * from './useBluetooth/useBluetooth';
6
7
  export * from './useBoolean/useBoolean';
@@ -1,13 +1,32 @@
1
+ import { HookTarget } from '../../utils/helpers';
2
+ import { StateRef } from '../useRefState/useRefState';
3
+ export interface UseActiveElement {
4
+ (): HTMLElement | null;
5
+ <Target extends Element, ActiveElement extends HTMLElement = HTMLElement>(target?: never): {
6
+ ref: StateRef<Target>;
7
+ value: ActiveElement | null;
8
+ };
9
+ <ActiveElement extends HTMLElement = HTMLElement>(target: HookTarget): ActiveElement | null;
10
+ }
1
11
  /**
2
12
  * @name useActiveElement
3
13
  * @description - Hook that returns the active element
4
14
  * @category Elements
5
15
  *
16
+ * @overload
17
+ * @param {HookTarget} [target=window] The target element to observe active element changes
6
18
  * @returns {ActiveElement | null} The active element
7
19
  *
8
20
  * @example
9
- * const activeElement = useActiveElement();
21
+ * const activeElement = useActiveElement(ref);
22
+ *
23
+ * @overload
24
+ * @template ActiveElement The active element type
25
+ * @returns {{ ref: StateRef<Element>; activeElement: ActiveElement | null }} An object containing the ref and active element
26
+ *
27
+ * @example
28
+ * const { ref, value } = useActiveElement();
10
29
  *
11
30
  * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useActiveElement.html}
12
31
  */
13
- export declare const useActiveElement: <ActiveElement extends HTMLElement>() => ActiveElement | null;
32
+ export declare const useActiveElement: UseActiveElement;
@@ -0,0 +1,35 @@
1
+ import { HookTarget } from '../../utils/helpers';
2
+ import { StateRef } from '../useRefState/useRefState';
3
+ /** The use auto scroll options type */
4
+ export interface UseAutoScrollOptions {
5
+ /** Whether auto-scrolling is enabled */
6
+ enabled?: boolean;
7
+ /** Whether to force auto-scrolling regardless of user interactions */
8
+ force?: boolean;
9
+ }
10
+ export interface UseAutoScroll {
11
+ (target: HookTarget, options?: UseAutoScrollOptions): void;
12
+ <Target extends HTMLElement>(options?: UseAutoScrollOptions): StateRef<Target>;
13
+ }
14
+ /**
15
+ * @name useAutoScroll
16
+ * @description - Hook that automatically scrolls a list element to the bottom
17
+ * @category Sensors
18
+ *
19
+ * @overload
20
+ * @param {HookTarget} target The target element to auto-scroll
21
+ * @param {boolean} [options.enabled] Whether auto-scrolling is enabled
22
+ * @returns {void}
23
+ *
24
+ * @example
25
+ * useAutoScroll(ref);
26
+ *
27
+ * @overload
28
+ * @template Target
29
+ * @param {boolean} [options.enabled] Whether auto-scrolling is enabled
30
+ * @returns {StateRef<Target>} A React ref to attach to the list element
31
+ *
32
+ * @example
33
+ * const ref = useAutoScroll();
34
+ */
35
+ export declare const useAutoScroll: UseAutoScroll;
@@ -23,7 +23,7 @@ export interface UseKeyPress {
23
23
  * @returns {boolean} The pressed state of the key
24
24
  *
25
25
  * @example
26
- * const isKeyPressed = useKeyPress('a', window);
26
+ * const isKeyPressed = useKeyPress(ref, 'a');
27
27
  *
28
28
  * @overload
29
29
  * @template Target The target element type
@@ -1,17 +1,21 @@
1
1
  import { HookTarget } from '../../utils/helpers';
2
2
  import { StateRef } from '../useRefState/useRefState';
3
- /** The keyboard event handler type */
3
+ /** The use keyboard event handler type */
4
4
  export type KeyboardEventHandler = (event: KeyboardEvent) => void;
5
- /** The use keyboard options type */
6
- export interface UseKeyboardOptions {
5
+ /** The use keyboard event options type */
6
+ export interface UseKeyboardEventOptions {
7
7
  /** The callback function to be invoked on key down */
8
8
  onKeyDown?: KeyboardEventHandler;
9
9
  /** The callback function to be invoked on key up */
10
10
  onKeyUp?: KeyboardEventHandler;
11
11
  }
12
12
  export interface UseKeyboard {
13
- (target: HookTarget | Window, options: UseKeyboardOptions): void;
14
- <Target extends Element>(options: UseKeyboardOptions, target?: never): {
13
+ (target: HookTarget, callback: KeyboardEventHandler): void;
14
+ (target: HookTarget, options: UseKeyboardEventOptions): void;
15
+ <Target extends HTMLElement>(callback: KeyboardEventHandler, target?: never): {
16
+ ref: StateRef<Target>;
17
+ };
18
+ <Target extends HTMLElement>(options: UseKeyboardEventOptions, target?: never): {
15
19
  ref: StateRef<Target>;
16
20
  };
17
21
  }
@@ -21,8 +25,16 @@ export interface UseKeyboard {
21
25
  * @category Sensors
22
26
  *
23
27
  * @overload
24
- * @param {HookTarget | Window} target The target to attach the event listeners to
25
- * @param {UseKeyboardOptions} [options] The keyboard event options
28
+ * @param {HookTarget} target The target to attach the event listeners to
29
+ * @param {KeyboardEventHandler} callback The callback function to be invoked on key down
30
+ * @returns {void}
31
+ *
32
+ * @example
33
+ * useKeyboard(ref, (event) => console.log('key down'));
34
+ *
35
+ * @overload
36
+ * @param {HookTarget} target The target to attach the event listeners to
37
+ * @param {UseKeyboardEventOptions} [options] The keyboard event options
26
38
  * @returns {void}
27
39
  *
28
40
  * @example
@@ -30,7 +42,15 @@ export interface UseKeyboard {
30
42
  *
31
43
  * @overload
32
44
  * @template Target The target element type
33
- * @param {UseKeyboardOptions} [options] The keyboard event options
45
+ * @param {KeyboardEventHandler} callback The callback function to be invoked on key down
46
+ * @returns {{ ref: StateRef<Target> }} An object containing the ref
47
+ *
48
+ * @example
49
+ * const ref = useKeyboard((event) => console.log('key down'));
50
+ *
51
+ * @overload
52
+ * @template Target The target element type
53
+ * @param {UseKeyboardEventOptions} [options] The keyboard event options
34
54
  * @returns {{ ref: StateRef<Target> }} An object containing the ref
35
55
  *
36
56
  * @example
@@ -25,8 +25,8 @@ export interface UseStopwatchReturn {
25
25
  }
26
26
  /** The use stopwatch options */
27
27
  export interface UseStopwatchOptions {
28
- /** The enabled state of the timer */
29
- enabled?: boolean;
28
+ /** The immediately state of the timer */
29
+ immediately?: boolean;
30
30
  }
31
31
  interface UseStopwatch {
32
32
  (initialTime?: number, options?: UseStopwatchOptions): UseStopwatchReturn;
@@ -2,7 +2,7 @@ import { UseEventListenerOptions } from '../useEventListener/useEventListener';
2
2
  /**
3
3
  * @name useWindowEvent
4
4
  * @description - Hook attaches an event listener to the window object for the specified event
5
- * @category Browser
5
+ * @category Sensors
6
6
  *
7
7
  * @template Event Key of window event map.
8
8
  * @param {Event} event The event to listen for.
@@ -6,7 +6,7 @@ export declare const scrollTo: ({ x, y, behavior }: Partial<ScrollPosition & Scr
6
6
  /**
7
7
  * @name useWindowScroll
8
8
  * @description - Hook that manages the window scroll position
9
- * @category Browser
9
+ * @category Sensors
10
10
  *
11
11
  * @returns {UseWindowScrollReturn} An object containing the current window scroll position
12
12
  *
@@ -9,4 +9,4 @@ export declare const target: (target: Target) => {
9
9
  value: Target;
10
10
  type: symbol;
11
11
  };
12
- export declare const getElement: (target: HookTarget) => Element | Window | Document | null | undefined;
12
+ export declare const getElement: (target: HookTarget) => Document | Element | Window | null | undefined;
package/package.json CHANGED
@@ -1,89 +1,89 @@
1
- {
2
- "name": "@siberiacancode/reactuse",
3
- "version": "0.2.23",
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.0",
69
- "@testing-library/react": "^16.3.0",
70
- "@types/dom-speech-recognition": "^0.0.6",
71
- "@types/react": "^19.1.8",
72
- "@types/react-dom": "^19.1.6",
73
- "@types/web-bluetooth": "^0.0.21",
74
- "@vitejs/plugin-react": "^4.6.0",
75
- "core-js": "^3.44.0",
76
- "react": "^19.1.0",
77
- "react-dom": "^19.1.0",
78
- "shx": "^0.4.0",
79
- "vite": "^7.0.4",
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.25",
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.0",
69
+ "@testing-library/react": "^16.3.0",
70
+ "@types/dom-speech-recognition": "^0.0.6",
71
+ "@types/react": "^19.1.8",
72
+ "@types/react-dom": "^19.1.6",
73
+ "@types/web-bluetooth": "^0.0.21",
74
+ "@vitejs/plugin-react": "^4.6.0",
75
+ "core-js": "^3.44.0",
76
+ "react": "^19.1.0",
77
+ "react-dom": "^19.1.0",
78
+ "shx": "^0.4.0",
79
+ "vite": "^7.0.4",
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
+ }