@versini/ui-hooks 4.5.0 → 4.6.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.
@@ -1,25 +1,25 @@
1
1
  import { useRef as f, useEffect as d } from "react";
2
2
  const i = ["mousedown", "touchstart"];
3
- function E(r, o, e) {
3
+ function E(r, e, o) {
4
4
  const c = f(null);
5
5
  return d(() => {
6
- const n = (t) => {
7
- const s = t ? t.target : void 0;
8
- if (Array.isArray(e)) {
9
- const a = !document.body.contains(s) && s.tagName !== "HTML";
10
- e.every(
6
+ const s = (t) => {
7
+ const n = t ? t.target : void 0;
8
+ if (Array.isArray(o)) {
9
+ const a = !document.body.contains(n) && n.tagName !== "HTML";
10
+ o.every(
11
11
  (u) => !!u && !t.composedPath().includes(u)
12
12
  ) && !a && r();
13
- } else c.current && !c.current.contains(s) && r();
13
+ } else c.current && !c.current.contains(n) && r();
14
14
  };
15
- return (o || i).forEach(
16
- (t) => document.addEventListener(t, n)
15
+ return (e || i).forEach(
16
+ (t) => document.addEventListener(t, s)
17
17
  ), () => {
18
- (o || i).forEach(
19
- (t) => document.removeEventListener(t, n)
18
+ (e || i).forEach(
19
+ (t) => document.removeEventListener(t, s)
20
20
  );
21
21
  };
22
- }, [r, e, o]), c;
22
+ }, [r, o, e]), c;
23
23
  }
24
24
  export {
25
25
  E as useClickOutside
@@ -1,4 +1,4 @@
1
- import { useSyncExternalStore as w, useCallback as a, useEffect as d } from "react";
1
+ import { useSyncExternalStore as d, useCallback as a, useEffect as w } from "react";
2
2
  function S(t, e) {
3
3
  window.dispatchEvent(new StorageEvent("storage", { key: t, newValue: e }));
4
4
  }
@@ -14,7 +14,7 @@ function E({
14
14
  key: t,
15
15
  initialValue: e
16
16
  }) {
17
- const s = w(m, () => l(t)), o = a(
17
+ const s = d(m, () => l(t)), o = a(
18
18
  (n) => {
19
19
  try {
20
20
  const r = typeof n == "function" ? n(JSON.parse(s)) : n;
@@ -29,7 +29,7 @@ function E({
29
29
  }, [e, o]), f = a(() => {
30
30
  o(null);
31
31
  }, [o]);
32
- return d(() => {
32
+ return w(() => {
33
33
  try {
34
34
  l(t) === null && typeof e < "u" && g(t, e);
35
35
  } catch (n) {
@@ -1,22 +1,22 @@
1
- import { useState as f, useEffect as U } from "react";
1
+ import { useState as u, useEffect as U } from "react";
2
2
  function w({
3
- value: e,
4
- defaultValue: o,
5
- finalValue: u,
6
- onChange: t = () => {
3
+ value: t,
4
+ defaultValue: n,
5
+ finalValue: c,
6
+ onChange: e = () => {
7
7
  },
8
8
  initialControlledDelay: r = 0
9
9
  }) {
10
- const [c, i] = f(!1), [n, d] = f(
11
- o !== void 0 ? o : u
10
+ const [f, i] = u(!1), [d, o] = u(
11
+ n !== void 0 ? n : c
12
12
  ), m = (s) => {
13
- d(s), t == null || t(s);
13
+ o(s), e == null || e(s);
14
14
  };
15
15
  return U(() => {
16
- (async () => e !== void 0 && !c && r > 0 && (await new Promise(
16
+ (async () => t !== void 0 && !f && r > 0 && (await new Promise(
17
17
  (s) => setTimeout(s, r)
18
18
  ), i(!0)))();
19
- }, [e, r, c]), e !== void 0 ? !c && r > 0 ? ["", t, !0] : [e, t, !0] : [n, m, !1];
19
+ }, [t, r, f]), t !== void 0 ? !f && r > 0 ? ["", e, !0] : [t, e, !0] : [d, m, !1];
20
20
  }
21
21
  export {
22
22
  w as useUncontrolled
@@ -0,0 +1,21 @@
1
+ import { useState as w, useCallback as r, useEffect as o } from "react";
2
+ function t(e, i) {
3
+ o(() => (window.addEventListener(e, i, {
4
+ passive: !0
5
+ }), () => window.removeEventListener(e, i)), [e, i]);
6
+ }
7
+ function s() {
8
+ const [e, i] = w({
9
+ width: 0,
10
+ height: 0
11
+ }), n = r(() => {
12
+ i({
13
+ width: window.innerWidth || 0,
14
+ height: window.innerHeight || 0
15
+ });
16
+ }, []);
17
+ return t("resize", n), t("orientationchange", n), o(n, []), e;
18
+ }
19
+ export {
20
+ s as useViewportSize
21
+ };
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import { useResizeObserver as k } from "./hooks/useResizeObserver.js";
9
9
  import { useUncontrolled as H } from "./hooks/useUncontrolled.js";
10
10
  import { useUniqueId as M } from "./hooks/useUniqueId.js";
11
11
  /*!
12
- @versini/ui-hooks v4.5.0
12
+ @versini/ui-hooks v4.6.0
13
13
  © 2025 gizmette.com
14
14
  */
15
15
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/ui-hooks",
3
- "version": "4.5.0",
3
+ "version": "4.6.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": "9fe85d906eb117bb22c3b576f104b6f0203429d7"
40
+ "gitHead": "1199c5a06253a95c103981005f5a1131c841bb00"
41
41
  }