@versini/ui-hooks 4.1.3 → 4.2.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,56 @@
1
+ import { useEffect as y } from "react";
2
+ function E(t) {
3
+ const e = t.toLowerCase().split("+").map((s) => s.trim()), r = {
4
+ alt: e.includes("alt"),
5
+ ctrl: e.includes("ctrl"),
6
+ meta: e.includes("meta"),
7
+ mod: e.includes("mod"),
8
+ shift: e.includes("shift")
9
+ }, a = ["alt", "ctrl", "meta", "shift", "mod"], n = e.find((s) => !a.includes(s));
10
+ return {
11
+ ...r,
12
+ key: n
13
+ };
14
+ }
15
+ function p(t, e) {
16
+ const { alt: r, ctrl: a, meta: n, mod: s, shift: i, key: f } = t, { altKey: c, ctrlKey: o, metaKey: u, shiftKey: d, key: m } = e;
17
+ if (r !== c)
18
+ return !1;
19
+ if (s) {
20
+ if (!o && !u)
21
+ return !1;
22
+ } else if (a !== o || n !== u)
23
+ return !1;
24
+ return i !== d ? !1 : !!(f && (m.toLowerCase() === f.toLowerCase() || e.code.replace("Key", "").toLowerCase() === f.toLowerCase()));
25
+ }
26
+ function l(t) {
27
+ return (e) => p(E(t), e);
28
+ }
29
+ function h(t) {
30
+ return (e) => {
31
+ const r = "nativeEvent" in e ? e.nativeEvent : e;
32
+ t.forEach(([a, n, s = { preventDefault: !0 }]) => {
33
+ l(a)(r) && (s.preventDefault && e.preventDefault(), n(r));
34
+ });
35
+ };
36
+ }
37
+ function k(t, e, r = !1) {
38
+ return t.target instanceof HTMLElement ? (r || !t.target.isContentEditable) && !e.includes(t.target.tagName) : !0;
39
+ }
40
+ function w(t, e = ["INPUT", "TEXTAREA", "SELECT"], r = !1) {
41
+ y(() => {
42
+ const a = (n) => {
43
+ t.forEach(
44
+ ([s, i, f = { preventDefault: !0 }]) => {
45
+ l(s)(n) && k(n, e, r) && (f.preventDefault && n.preventDefault(), i(n));
46
+ }
47
+ );
48
+ };
49
+ return document.documentElement.addEventListener("keydown", a), () => document.documentElement.removeEventListener("keydown", a);
50
+ }, [t, e, r]);
51
+ }
52
+ export {
53
+ h as getHotkeyHandler,
54
+ k as shouldFireEvent,
55
+ w as useHotkeys
56
+ };
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import { useResizeObserver as p } from "./hooks/useResizeObserver.js";
5
5
  import { useUncontrolled as n } from "./hooks/useUncontrolled.js";
6
6
  import { useUniqueId as l } from "./hooks/useUniqueId.js";
7
7
  /*!
8
- @versini/ui-hooks v4.1.3
8
+ @versini/ui-hooks v4.2.0
9
9
  © 2024 gizmette.com
10
10
  */
11
11
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/ui-hooks",
3
- "version": "4.1.3",
3
+ "version": "4.2.0",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -41,5 +41,5 @@
41
41
  "react": "18.3.1",
42
42
  "react-dom": "18.3.1"
43
43
  },
44
- "gitHead": "5398941244aa5c6642426325c804d7cb9529b688"
44
+ "gitHead": "6a6a35ebe0703c747695dd047bd90c48a059bea4"
45
45
  }