@versini/ui-hooks 4.3.0 → 4.4.0

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.
@@ -0,0 +1,13 @@
1
+ import { useRef as f, useState as u, useCallback as l } from "react";
2
+ function b() {
3
+ const e = f(null), [i, t] = u(!1);
4
+ return { ref: l((r) => {
5
+ var n, s;
6
+ typeof IntersectionObserver < "u" && (r && !e.current ? e.current = new IntersectionObserver(
7
+ (o) => t(o.some((c) => c.isIntersecting))
8
+ ) : (n = e.current) == null || n.disconnect(), r ? (s = e.current) == null || s.observe(r) : t(!1));
9
+ }, []), inViewport: i };
10
+ }
11
+ export {
12
+ b as useInViewport
13
+ };
package/dist/index.d.ts CHANGED
@@ -11,8 +11,20 @@ type HotkeyItem = [
11
11
  (event: KeyboardEvent) => void,
12
12
  HotkeyItemOptions?
13
13
  ];
14
+ declare function shouldFireEvent(event: KeyboardEvent, tagsToIgnore: string[], triggerOnContentEditable?: boolean): boolean;
14
15
  declare function useHotkeys(hotkeys: HotkeyItem[], tagsToIgnore?: string[], triggerOnContentEditable?: boolean): void;
15
16
 
17
+ /**
18
+ * Hook that checks if an element is visible in the viewport.
19
+ * @returns
20
+ * ref: React ref object to attach to the element you want to monitor.
21
+ * inViewport: Boolean indicating if the element is in the viewport.
22
+ */
23
+ declare function useInViewport<T extends HTMLElement = any>(): {
24
+ ref: (node: T | null) => void;
25
+ inViewport: boolean;
26
+ };
27
+
16
28
  /**
17
29
  * Custom hook that returns a function indicating whether the component
18
30
  * is mounted or not.
@@ -142,4 +154,4 @@ type UseUniqueIdOptions = string | number | {
142
154
  };
143
155
  declare function useUniqueId(options?: UseUniqueIdOptions): string | undefined;
144
156
 
145
- export { getHotkeyHandler, useHotkeys, useIsMounted, useLocalStorage, useMergeRefs, useResizeObserver, useUncontrolled, useUniqueId };
157
+ export { type HotkeyItem, type HotkeyItemOptions, type StorageProperties, type UseUniqueIdOptions, getHotkeyHandler, shouldFireEvent, useHotkeys, useInViewport, useIsMounted, useLocalStorage, useMergeRefs, useResizeObserver, useUncontrolled, useUniqueId };
package/dist/index.js CHANGED
@@ -1,21 +1,24 @@
1
- import { getHotkeyHandler as r, useHotkeys as t } from "./hooks/useHotkeys.js";
2
- import { useIsMounted as u } from "./hooks/useIsMounted.js";
3
- import { useLocalStorage as m } from "./hooks/useLocalStorage.js";
4
- import { useMergeRefs as x } from "./hooks/useMergeRefs.js";
5
- import { useResizeObserver as d } from "./hooks/useResizeObserver.js";
6
- import { useUncontrolled as a } from "./hooks/useUncontrolled.js";
7
- import { useUniqueId as H } from "./hooks/useUniqueId.js";
1
+ import { getHotkeyHandler as r, shouldFireEvent as t, useHotkeys as s } from "./hooks/useHotkeys.js";
2
+ import { useInViewport as f } from "./hooks/useInViewport.js";
3
+ import { useIsMounted as m } from "./hooks/useIsMounted.js";
4
+ import { useLocalStorage as n } from "./hooks/useLocalStorage.js";
5
+ import { useMergeRefs as l } from "./hooks/useMergeRefs.js";
6
+ import { useResizeObserver as a } from "./hooks/useResizeObserver.js";
7
+ import { useUncontrolled as H } from "./hooks/useUncontrolled.js";
8
+ import { useUniqueId as c } from "./hooks/useUniqueId.js";
8
9
  /*!
9
- @versini/ui-hooks v4.3.0
10
- © 2024 gizmette.com
10
+ @versini/ui-hooks v4.4.0
11
+ © 2025 gizmette.com
11
12
  */
12
13
  export {
13
14
  r as getHotkeyHandler,
14
- t as useHotkeys,
15
- u as useIsMounted,
16
- m as useLocalStorage,
17
- x as useMergeRefs,
18
- d as useResizeObserver,
19
- a as useUncontrolled,
20
- H as useUniqueId
15
+ t as shouldFireEvent,
16
+ s as useHotkeys,
17
+ f as useInViewport,
18
+ m as useIsMounted,
19
+ n as useLocalStorage,
20
+ l as useMergeRefs,
21
+ a as useResizeObserver,
22
+ H as useUncontrolled,
23
+ c as useUniqueId
21
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/ui-hooks",
3
- "version": "4.3.0",
3
+ "version": "4.4.0",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -37,5 +37,5 @@
37
37
  "react": "^18.3.1 || ^19.0.0",
38
38
  "react-dom": "^18.3.1 || ^19.0.0"
39
39
  },
40
- "gitHead": "413e5c7cd8228d2f135f54fa897101401207229b"
40
+ "gitHead": "bc91b8aaa11a672d219b6f32da04f001f33e38d7"
41
41
  }