@aliexme/react-utils 3.0.1 → 3.1.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"),
|
|
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
|
|
2
|
-
import { useValueRef as
|
|
3
|
-
const
|
|
4
|
-
width:
|
|
5
|
-
height:
|
|
6
|
-
}),
|
|
7
|
-
const { ref:
|
|
8
|
-
(
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
[
|
|
12
|
+
[e, s, o]
|
|
14
13
|
);
|
|
15
|
-
return
|
|
16
|
-
if (typeof window > "u" || !
|
|
14
|
+
return m(() => {
|
|
15
|
+
if (typeof window > "u" || !r || !e.current)
|
|
17
16
|
return;
|
|
18
|
-
const
|
|
19
|
-
return
|
|
20
|
-
|
|
17
|
+
const n = new ResizeObserver(f);
|
|
18
|
+
return n.observe(e.current), () => {
|
|
19
|
+
n.disconnect();
|
|
21
20
|
};
|
|
22
|
-
}, [
|
|
23
|
-
ref:
|
|
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
|
-
|
|
28
|
+
v as useComponentSize
|
|
30
29
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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
|
|
2
|
-
import { useValueRef as
|
|
3
|
-
const
|
|
4
|
-
const { value: e, initialValue:
|
|
5
|
-
|
|
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 [
|
|
7
|
+
return [l, p];
|
|
9
8
|
};
|
|
10
9
|
export {
|
|
11
|
-
|
|
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
|
|
3
|
+
"version": "3.1.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.
|
|
33
|
+
"@aliexme/js-utils": "^2.4.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/react": "19.1.
|
|
37
|
-
"@vitejs/plugin-react": "
|
|
38
|
-
"react": "19.1.
|
|
36
|
+
"@types/react": "19.1.12",
|
|
37
|
+
"@vitejs/plugin-react": "5.0.2",
|
|
38
|
+
"react": "19.1.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": "
|
|
46
|
+
"gitHead": "73fd109626f172b3682864fabf470f5367ecaaee"
|
|
47
47
|
}
|