@aliexme/react-utils 3.0.1 → 3.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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),p=require("./useValueRef.cjs"),d=e=>({width:(e==null?void 0:e.offsetWidth)??0,height:(e==null?void 0:e.offsetHeight)??0}),R=(e={})=>{const{ref:h,enabled:o=!0,manual:i=!1,onResize:z}=e,S=r.useRef(null),n=h??S,t=p.useValueRef(z),[u,a]=r.useState(()=>d(n.current)),c=r.useCallback(s=>{var l;const b=s[0],f=d(n.current);i||a(f),(l=t.current)==null||l.call(t,f,b)},[n,i,t]);return r.useEffect(()=>{if(typeof window>"u"||!o||!n.current)return;const s=new ResizeObserver(c);return s.observe(n.current),()=>{s.disconnect()}},[o,n,c]),{ref:n,width:u.width,height:u.height}};exports.useComponentSize=R;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),g=require("./useValueRef.cjs"),a=t=>({width:t?.offsetWidth??0,height:t?.offsetHeight??0}),S=(t={})=>{const{ref:l,enabled:s=!0,manual:o=!1,onResize:d}=t,h=r.useRef(null),e=l??h,i=g.useValueRef(d),[u,z]=r.useState(()=>a(e.current)),c=r.useCallback(n=>{const R=n[0],f=a(e.current);o||z(f),i.current?.(f,R)},[e,o,i]);return r.useEffect(()=>{if(typeof window>"u"||!s||!e.current)return;const n=new ResizeObserver(c);return n.observe(e.current),()=>{n.disconnect()}},[s,e,c]),{ref:e,width:u.width,height:u.height}};exports.useComponentSize=S;
@@ -1,30 +1,29 @@
1
- import { useRef as w, useState as R, useCallback as b, useEffect as S } from "react";
2
- import { useValueRef as a } from "./useValueRef.js";
3
- const h = (e) => ({
4
- width: (e == null ? void 0 : e.offsetWidth) ?? 0,
5
- height: (e == null ? void 0 : e.offsetHeight) ?? 0
6
- }), C = (e = {}) => {
7
- const { ref: d, enabled: s = !0, manual: o = !1, onResize: l } = e, p = w(null), n = d ?? p, t = a(l), [i, z] = R(() => h(n.current)), c = b(
8
- (r) => {
9
- var f;
10
- const m = r[0], u = h(n.current);
11
- o || z(u), (f = t.current) == null || f.call(t, u, m);
1
+ import { useRef as l, useState as p, useCallback as g, useEffect as m } from "react";
2
+ import { useValueRef as w } from "./useValueRef.js";
3
+ const u = (t) => ({
4
+ width: t?.offsetWidth ?? 0,
5
+ height: t?.offsetHeight ?? 0
6
+ }), v = (t = {}) => {
7
+ const { ref: h, enabled: r = !0, manual: s = !1, onResize: a } = t, d = l(null), e = h ?? d, o = w(a), [i, z] = p(() => u(e.current)), f = g(
8
+ (n) => {
9
+ const R = n[0], c = u(e.current);
10
+ s || z(c), o.current?.(c, R);
12
11
  },
13
- [n, o, t]
12
+ [e, s, o]
14
13
  );
15
- return S(() => {
16
- if (typeof window > "u" || !s || !n.current)
14
+ return m(() => {
15
+ if (typeof window > "u" || !r || !e.current)
17
16
  return;
18
- const r = new ResizeObserver(c);
19
- return r.observe(n.current), () => {
20
- r.disconnect();
17
+ const n = new ResizeObserver(f);
18
+ return n.observe(e.current), () => {
19
+ n.disconnect();
21
20
  };
22
- }, [s, n, c]), {
23
- ref: n,
21
+ }, [r, e, f]), {
22
+ ref: e,
24
23
  width: i.width,
25
24
  height: i.height
26
25
  };
27
26
  };
28
27
  export {
29
- C as useComponentSize
28
+ v as useComponentSize
30
29
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),S=require("./useValueRef.cjs"),d=n=>{const{value:e,initialValue:o,onChange:r}=n,[c,l]=s.useState(e??o),t=S.useValueRef(r),i=e!==void 0?e:c,v=s.useCallback(a=>{var u;(u=t.current)==null||u.call(t,a),l(a)},[]);return[i,v]};exports.useDerivedState=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),p=require("./useValueRef.cjs"),g=n=>{const{value:e,initialValue:u,onChange:o}=n,[r,s]=a.useState(e??u),c=p.useValueRef(o),l=e!==void 0?e:r,i=a.useCallback(t=>{c.current?.(t),s(t)},[]);return[l,i]};exports.useDerivedState=g;
@@ -1,12 +1,11 @@
1
- import { useState as p, useCallback as m } from "react";
2
- import { useValueRef as v } from "./useValueRef.js";
3
- const S = (n) => {
4
- const { value: e, initialValue: s, onChange: u } = n, [r, l] = p(e ?? s), t = v(u), c = e !== void 0 ? e : r, i = m((a) => {
5
- var o;
6
- (o = t.current) == null || o.call(t, a), l(a);
1
+ import { useState as c, useCallback as i } from "react";
2
+ import { useValueRef as C } from "./useValueRef.js";
3
+ const h = (a) => {
4
+ const { value: e, initialValue: o, onChange: n } = a, [r, s] = c(e ?? o), u = C(n), l = e !== void 0 ? e : r, p = i((t) => {
5
+ u.current?.(t), s(t);
7
6
  }, []);
8
- return [c, i];
7
+ return [l, p];
9
8
  };
10
9
  export {
11
- S as useDerivedState
10
+ h as useDerivedState
12
11
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aliexme/react-utils",
3
- "version": "3.0.1",
3
+ "version": "3.2.0",
4
4
  "private": false,
5
5
  "description": "React utilities",
6
6
  "homepage": "https://github.com/aliexme/web-shared/tree/main/packages/react-utils",
@@ -30,12 +30,12 @@
30
30
  "ts:check": "tsc --noEmit"
31
31
  },
32
32
  "dependencies": {
33
- "@aliexme/js-utils": "^2.3.1"
33
+ "@aliexme/js-utils": "^2.4.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@types/react": "19.1.8",
37
- "@vitejs/plugin-react": "4.5.2",
38
- "react": "19.1.0"
36
+ "@types/react": "19.2.7",
37
+ "@vitejs/plugin-react": "5.1.1",
38
+ "react": "19.2.1"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "react": "^19.0.0"
@@ -43,5 +43,5 @@
43
43
  "publishConfig": {
44
44
  "access": "public"
45
45
  },
46
- "gitHead": "b0b64c6bea3f7d5a2dcf2db3372b4ba29025d0bc"
46
+ "gitHead": "4ccd2ac23c307f3099bacdba050ea5591d9b2643"
47
47
  }