@siberiacancode/reactuse 0.3.9 → 0.3.12

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 (74) 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/useAutoScroll/useAutoScroll.cjs +1 -1
  4. package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs.map +1 -1
  5. package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs +1 -1
  6. package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs.map +1 -1
  7. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs +1 -1
  8. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs.map +1 -1
  9. package/dist/cjs/hooks/useFocusTrap/useFocusTrap.cjs.map +1 -1
  10. package/dist/cjs/hooks/useHash/useHash.cjs +1 -1
  11. package/dist/cjs/hooks/useHash/useHash.cjs.map +1 -1
  12. package/dist/cjs/hooks/useHover/useHover.cjs +1 -1
  13. package/dist/cjs/hooks/useHover/useHover.cjs.map +1 -1
  14. package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs +1 -1
  15. package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs.map +1 -1
  16. package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs +1 -1
  17. package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs.map +1 -1
  18. package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs +1 -1
  19. package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs.map +1 -1
  20. package/dist/cjs/hooks/useLongPress/useLongPress.cjs +1 -1
  21. package/dist/cjs/hooks/useLongPress/useLongPress.cjs.map +1 -1
  22. package/dist/cjs/hooks/useMediaControls/useMediaControls.cjs.map +1 -1
  23. package/dist/cjs/hooks/usePostMessage/usePostMessage.cjs +1 -1
  24. package/dist/cjs/hooks/usePostMessage/usePostMessage.cjs.map +1 -1
  25. package/dist/cjs/hooks/useSticky/useSticky.cjs +1 -1
  26. package/dist/cjs/hooks/useSticky/useSticky.cjs.map +1 -1
  27. package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs +1 -1
  28. package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs.map +1 -1
  29. package/dist/cjs/hooks/useWindowScroll/useWindowScroll.cjs +1 -1
  30. package/dist/cjs/hooks/useWindowScroll/useWindowScroll.cjs.map +1 -1
  31. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs +1 -1
  32. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
  33. package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs +11 -11
  34. package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs.map +1 -1
  35. package/dist/esm/hooks/useClickOutside/useClickOutside.mjs +9 -9
  36. package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
  37. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs +3 -1
  38. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -1
  39. package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs.map +1 -1
  40. package/dist/esm/hooks/useHash/useHash.mjs +6 -3
  41. package/dist/esm/hooks/useHash/useHash.mjs.map +1 -1
  42. package/dist/esm/hooks/useHover/useHover.mjs +4 -4
  43. package/dist/esm/hooks/useHover/useHover.mjs.map +1 -1
  44. package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs +1 -1
  45. package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs.map +1 -1
  46. package/dist/esm/hooks/useKeyPress/useKeyPress.mjs +1 -1
  47. package/dist/esm/hooks/useKeyPress/useKeyPress.mjs.map +1 -1
  48. package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs +1 -1
  49. package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs.map +1 -1
  50. package/dist/esm/hooks/useLongPress/useLongPress.mjs +1 -4
  51. package/dist/esm/hooks/useLongPress/useLongPress.mjs.map +1 -1
  52. package/dist/esm/hooks/useMediaControls/useMediaControls.mjs.map +1 -1
  53. package/dist/esm/hooks/usePostMessage/usePostMessage.mjs +18 -14
  54. package/dist/esm/hooks/usePostMessage/usePostMessage.mjs.map +1 -1
  55. package/dist/esm/hooks/useSticky/useSticky.mjs +1 -1
  56. package/dist/esm/hooks/useSticky/useSticky.mjs.map +1 -1
  57. package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs +6 -6
  58. package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs.map +1 -1
  59. package/dist/esm/hooks/useWindowScroll/useWindowScroll.mjs +1 -4
  60. package/dist/esm/hooks/useWindowScroll/useWindowScroll.mjs.map +1 -1
  61. package/dist/types/hooks/useActiveElement/useActiveElement.d.ts +4 -3
  62. package/dist/types/hooks/useAutoScroll/useAutoScroll.d.ts +5 -3
  63. package/dist/types/hooks/useClickOutside/useClickOutside.d.ts +5 -3
  64. package/dist/types/hooks/useDoubleClick/useDoubleClick.d.ts +7 -5
  65. package/dist/types/hooks/useFocusTrap/useFocusTrap.d.ts +2 -2
  66. package/dist/types/hooks/useHash/useHash.d.ts +10 -5
  67. package/dist/types/hooks/useHover/useHover.d.ts +8 -6
  68. package/dist/types/hooks/useInfiniteScroll/useInfiniteScroll.d.ts +12 -6
  69. package/dist/types/hooks/useKeyPress/useKeyPress.d.ts +10 -4
  70. package/dist/types/hooks/useKeysPressed/useKeysPressed.d.ts +10 -10
  71. package/dist/types/hooks/useLongPress/useLongPress.d.ts +9 -3
  72. package/dist/types/hooks/usePostMessage/usePostMessage.d.ts +5 -2
  73. package/dist/types/hooks/useSticky/useSticky.d.ts +5 -5
  74. package/package.json +89 -89
@@ -7,11 +7,17 @@ export interface UseInfiniteScrollOptions {
7
7
  /** The distance in pixels to trigger the callback */
8
8
  distance?: number;
9
9
  }
10
+ /** The use infinite scroll return type */
11
+ export interface UseInfiniteScrollReturn {
12
+ /** The loading state of the infinite scroll */
13
+ loading: boolean;
14
+ /** The ref to attach to the element */
15
+ ref: StateRef<Element>;
16
+ }
10
17
  export interface UseInfiniteScroll {
11
- (target: HookTarget, callback: (event: Event) => void, options?: UseInfiniteScrollOptions): boolean;
12
- <Target extends Element>(callback: (event: Event) => void, options?: UseInfiniteScrollOptions, target?: never): {
18
+ (target: HookTarget, callback: (event: Event) => void, options?: UseInfiniteScrollOptions): UseInfiniteScrollReturn;
19
+ <Target extends Element>(callback: (event: Event) => void, options?: UseInfiniteScrollOptions, target?: never): UseInfiniteScrollReturn & {
13
20
  ref: StateRef<Target>;
14
- loading: boolean;
15
21
  };
16
22
  }
17
23
  /**
@@ -25,7 +31,7 @@ export interface UseInfiniteScroll {
25
31
  * @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected
26
32
  * @param {number} [options.distance=10] The distance in pixels to trigger the callback
27
33
  * @param {string} [options.direction='bottom'] The direction to trigger the callback
28
- * @returns {{ ref: StateRef<Target>, loading: boolean }} An object containing the ref and loading
34
+ * @returns {UseInfiniteScrollReturn & { ref: StateRef<Target> }} An object containing the ref and loading
29
35
  *
30
36
  * @example
31
37
  * const { ref, loading } = useInfiniteScroll(() => console.log('infinite scroll'));
@@ -35,9 +41,9 @@ export interface UseInfiniteScroll {
35
41
  * @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected
36
42
  * @param {number} [options.distance=10] The distance in pixels to trigger the callback
37
43
  * @param {string} [options.direction='bottom'] The direction to trigger the callback
38
- * @returns {boolean} A loading indicator of the infinite scroll
44
+ * @returns {UseInfiniteScrollReturn} An object containing the ref and loading
39
45
  *
40
46
  * @example
41
- * const loading = useInfiniteScroll(ref, () => console.log('infinite scroll'));
47
+ * const { loading } = useInfiniteScroll(ref, () => console.log('infinite scroll'));
42
48
  */
43
49
  export declare const useInfiniteScroll: UseInfiniteScroll;
@@ -4,10 +4,16 @@ import { StateRef } from '../useRefState/useRefState';
4
4
  export type UseKeyPressKey = string | string[];
5
5
  /** The callback function to be invoked when key is pressed */
6
6
  export type UseKeyPressCallback = (pressed: boolean, event: KeyboardEvent) => void;
7
+ /** The use key press return type */
8
+ export interface UseKeyPressReturn {
9
+ /** The pressed state of the key */
10
+ pressed: boolean;
11
+ /** The ref to attach to the element */
12
+ ref: StateRef<Element>;
13
+ }
7
14
  export interface UseKeyPress {
8
- (target: HookTarget | Window, key: UseKeyPressKey, callback?: UseKeyPressCallback): boolean;
9
- <Target extends Element>(key: UseKeyPressKey, callback?: UseKeyPressCallback, target?: never): {
10
- pressed: boolean;
15
+ (target: HookTarget | Window, key: UseKeyPressKey, callback?: UseKeyPressCallback): UseKeyPressReturn;
16
+ <Target extends Element>(key: UseKeyPressKey, callback?: UseKeyPressCallback, target?: never): UseKeyPressReturn & {
11
17
  ref: StateRef<Target>;
12
18
  };
13
19
  }
@@ -21,7 +27,7 @@ export interface UseKeyPress {
21
27
  * @param {HookTarget} [target=window] The target to attach the event listeners to
22
28
  * @param {UseKeyPressKey} key The key or keys to listen for
23
29
  * @param {(pressed: boolean, event: KeyboardEvent) => void} [callback] Callback function invoked when key is pressed
24
- * @returns {boolean} The pressed state of the key
30
+ * @returns {UseKeyPressReturn} An object containing the pressed state and ref
25
31
  *
26
32
  * @example
27
33
  * const isKeyPressed = useKeyPress(ref, 'a');
@@ -5,16 +5,16 @@ export interface UseKeysPressedOptions {
5
5
  /** Enable or disable the event listeners */
6
6
  enabled?: boolean;
7
7
  }
8
- export interface UseKeysPressed {
9
- (target: HookTarget | Window, options?: UseKeysPressedOptions): Array<{
8
+ export interface UseKeysPressedReturn {
9
+ /** The array of currently pressed keys */
10
+ value: Array<{
10
11
  key: string;
11
12
  code: string;
12
13
  }>;
13
- <Target extends Element>(options?: UseKeysPressedOptions): {
14
- value: Array<{
15
- key: string;
16
- code: string;
17
- }>;
14
+ }
15
+ export interface UseKeysPressed {
16
+ (target: HookTarget | Window, options?: UseKeysPressedOptions): UseKeysPressedReturn;
17
+ <Target extends Element>(options?: UseKeysPressedOptions): UseKeysPressedReturn & {
18
18
  ref: StateRef<Target>;
19
19
  };
20
20
  }
@@ -27,15 +27,15 @@ export interface UseKeysPressed {
27
27
  * @overload
28
28
  * @param {HookTarget | Window} target DOM element or ref to attach keyboard listeners to
29
29
  * @param {UseKeysPressedOptions} [options.enabled=true] Enable or disable the event listeners
30
- * @returns {Array<{ key: string; code: string }>} Array of currently pressed keys with their key and code values
30
+ * @returns {UseKeysPressedReturn} Object containing the array of currently pressed keys
31
31
  *
32
32
  * @example
33
- * const pressedKeys = useKeysPressed(ref);
33
+ * const { value } = useKeysPressed(ref);
34
34
  *
35
35
  * @overload
36
36
  * @template Target - Type of the target DOM element
37
37
  * @param {UseKeysPressedOptions} [options] - Optional configuration options
38
- * @returns {{ keys: Array<{ key: string; code: string }>; ref: StateRef<Target> }} Object containing pressed keys array and ref to attach to a DOM element
38
+ * @returns {UseKeysPressedReturn & { ref: StateRef<Target> }} Object containing the array of currently pressed keys and ref to attach to the element
39
39
  *
40
40
  * @example
41
41
  * const { value, ref } = useKeysPressed();
@@ -7,12 +7,18 @@ export interface UseLongPressOptions {
7
7
  onFinish?: (event: LongPressEvents) => void;
8
8
  onStart?: (event: LongPressEvents) => void;
9
9
  }
10
+ /** The use long press return type */
11
+ export interface UseLongPressReturn {
12
+ /** The long pressing state */
13
+ pressed: boolean;
14
+ /** The ref to attach to the element */
15
+ ref: StateRef<Element>;
16
+ }
10
17
  export interface UseLongPress {
11
- (target: HookTarget, callback: (event: LongPressEvents) => void, options?: UseLongPressOptions): boolean;
18
+ (target: HookTarget, callback: (event: LongPressEvents) => void, options?: UseLongPressOptions): UseLongPressReturn;
12
19
  <Target extends Element>(callback: (event: LongPressEvents) => void, options?: UseLongPressOptions, target?: never): {
13
20
  ref: StateRef<Target>;
14
- pressed: boolean;
15
- };
21
+ } & UseLongPressReturn;
16
22
  }
17
23
  /**
18
24
  * @name useLongPress
@@ -1,3 +1,6 @@
1
+ /** The origin of the message */
2
+ export type UsePostMessageOrigin = string | '*' | string[];
3
+ /** The return type of the usePostMessage hook */
1
4
  export type UsePostMessageReturn<Message> = (message: Message) => void;
2
5
  /**
3
6
  * @name usePostMessage
@@ -7,11 +10,11 @@ export type UsePostMessageReturn<Message> = (message: Message) => void;
7
10
  *
8
11
  * @overload
9
12
  * @template Message The message data type
10
- * @param {string | string[]} origin The origin of the message
13
+ * @param {UsePostMessageOrigin} origin The origin of the message
11
14
  * @param {(message: Message) => Message} callback callback to get received message
12
15
  * @returns {(message: Message) => void} An object containing the current message
13
16
  *
14
17
  * @example
15
18
  * const postMessage = usePostMessage();
16
19
  */
17
- export declare const usePostMessage: <Message>(origin: string | "*" | string[], callback: (message: Message, event: MessageEvent<Message>) => void) => UsePostMessageReturn<Message>;
20
+ export declare const usePostMessage: <Message>(origin: UsePostMessageOrigin, callback: (message: Message, event: MessageEvent<Message>) => void) => UsePostMessageReturn<Message>;
@@ -12,10 +12,10 @@ export interface UseStickyOptions {
12
12
  root?: HookTarget;
13
13
  }
14
14
  export interface UseSticky {
15
- (target: HookTarget, options?: UseStickyOptions): boolean;
16
- <Target extends Element>(options?: UseStickyOptions, target?: never): {
15
+ (target: HookTarget, options?: UseStickyOptions): UseStickyReturn;
16
+ <Target extends Element>(options?: UseStickyOptions, target?: never): UseStickyReturn & {
17
17
  ref: StateRef<Target>;
18
- } & UseStickyReturn;
18
+ };
19
19
  }
20
20
  /**
21
21
  * @name UseSticky
@@ -30,12 +30,12 @@ export interface UseSticky {
30
30
  * @returns {UseStickyReturn} The state of the sticky
31
31
  *
32
32
  * @example
33
- * const stuck = useSticky(ref);
33
+ * const { stuck } = useSticky(ref);
34
34
  *
35
35
  * @overload
36
36
  * @param {UseStickyAxis} [options.axis='vertical'] The axis of motion of the sticky component
37
37
  * @param {UseStickyRoot} [options.root=document] The element that contains your sticky component
38
- * @returns {{ stickyRef: StateRef<Target> } & UseStickyReturn} The state of the sticky
38
+ * @returns {{ ref: StateRef<Target> } & UseStickyReturn} The state of the sticky
39
39
  *
40
40
  * @example
41
41
  * const { stuck, ref } = useSticky();
package/package.json CHANGED
@@ -1,89 +1,89 @@
1
- {
2
- "name": "@siberiacancode/reactuse",
3
- "version": "0.3.9",
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.3.0",
68
- "@testing-library/dom": "^10.4.1",
69
- "@testing-library/react": "^16.3.1",
70
- "@types/dom-speech-recognition": "^0.0.7",
71
- "@types/react": "^19.2.7",
72
- "@types/react-dom": "^19.2.3",
73
- "@types/web-bluetooth": "^0.0.21",
74
- "@vitejs/plugin-react": "^5.1.2",
75
- "core-js": "^3.47.0",
76
- "react": "^19.2.3",
77
- "react-dom": "^19.2.3",
78
- "shx": "^0.4.0",
79
- "vite": "^7.3.0",
80
- "vite-plugin-dts": "^4.5.4",
81
- "vitest": "^4.0.16"
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.3.12",
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.3.0",
68
+ "@testing-library/dom": "^10.4.1",
69
+ "@testing-library/react": "^16.3.2",
70
+ "@types/dom-speech-recognition": "^0.0.7",
71
+ "@types/react": "^19.2.13",
72
+ "@types/react-dom": "^19.2.3",
73
+ "@types/web-bluetooth": "^0.0.21",
74
+ "@vitejs/plugin-react": "^5.1.3",
75
+ "core-js": "^3.48.0",
76
+ "react": "^19.2.4",
77
+ "react-dom": "^19.2.4",
78
+ "shx": "^0.4.0",
79
+ "vite": "^7.3.1",
80
+ "vite-plugin-dts": "^4.5.4",
81
+ "vitest": "^4.0.18"
82
+ },
83
+ "lint-staged": {
84
+ "*.{js,ts,tsx}": [
85
+ "eslint --fix",
86
+ "prettier --write"
87
+ ]
88
+ }
89
+ }