@rescui/use-resize-observer 0.3.4-RUI-297-Add-react-compiler-to-the-packages-build-ccd086200.40 → 0.3.5-RUI-308-Fix-select-issues-405b9fa40.12
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.
- package/lib/use-resize-observer.js +56 -96
- package/package.json +4 -5
|
@@ -1,117 +1,77 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { c } from 'react-compiler-runtime';
|
|
3
2
|
import { useRef, useEffect, useLayoutEffect } from 'react';
|
|
4
3
|
const useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
|
|
5
4
|
|
|
6
|
-
const useResizeObserver = (target, callback
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if ($[0] !== t0) {
|
|
11
|
-
t1 = t0 === undefined ? {
|
|
12
|
-
ignoreFirstCall: false
|
|
13
|
-
} : t0;
|
|
14
|
-
$[0] = t0;
|
|
15
|
-
$[1] = t1;
|
|
16
|
-
} else {
|
|
17
|
-
t1 = $[1];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const options = t1;
|
|
5
|
+
const useResizeObserver = function (target, callback) {
|
|
6
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
7
|
+
ignoreFirstCall: false
|
|
8
|
+
};
|
|
21
9
|
const cb = useRef(null);
|
|
22
10
|
const {
|
|
23
11
|
ignoreFirstCall
|
|
24
|
-
} = options;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
12
|
+
} = options; // using useLayoutEffect here so the ref has only committed to the DOM callback
|
|
13
|
+
|
|
14
|
+
useIsomorphicLayoutEffect(() => {
|
|
15
|
+
cb.current = callback;
|
|
16
|
+
}, [callback]);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (!target) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let targetEl;
|
|
23
|
+
|
|
24
|
+
if ('current' in target) {
|
|
25
|
+
targetEl = target.current;
|
|
26
|
+
} else {
|
|
27
|
+
targetEl = target;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!targetEl) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const ownerWindow = targetEl.ownerDocument.defaultView;
|
|
35
|
+
const ResizeObserver = ownerWindow?.ResizeObserver;
|
|
36
|
+
|
|
37
|
+
if (!ResizeObserver) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let firstCall = true;
|
|
42
|
+
let abort = false; // eslint-disable-next-line complexity
|
|
43
|
+
|
|
44
|
+
const onResize = entries => {
|
|
45
|
+
// on the first call, delay it by a frame, see https://stackoverflow.com/a/58701523
|
|
46
|
+
if (firstCall) {
|
|
47
|
+
firstCall = false;
|
|
48
|
+
|
|
49
|
+
if (!ignoreFirstCall) {
|
|
50
|
+
ownerWindow.requestAnimationFrame(() => {
|
|
51
|
+
onResize(entries);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
32
54
|
|
|
33
|
-
t3 = [callback];
|
|
34
|
-
$[2] = callback;
|
|
35
|
-
$[3] = t2;
|
|
36
|
-
$[4] = t3;
|
|
37
|
-
} else {
|
|
38
|
-
t2 = $[3];
|
|
39
|
-
t3 = $[4];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
useIsomorphicLayoutEffect(t2, t3);
|
|
43
|
-
let t4;
|
|
44
|
-
let t5;
|
|
45
|
-
|
|
46
|
-
if ($[5] !== ignoreFirstCall || $[6] !== target) {
|
|
47
|
-
t4 = () => {
|
|
48
|
-
if (!target) {
|
|
49
55
|
return;
|
|
50
56
|
}
|
|
51
57
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if ("current" in target) {
|
|
55
|
-
targetEl = target.current;
|
|
56
|
-
} else {
|
|
57
|
-
targetEl = target;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (!targetEl) {
|
|
58
|
+
if (!Array.isArray(entries) || !entries.length || abort) {
|
|
61
59
|
return;
|
|
62
60
|
}
|
|
63
61
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (!ResizeObserver) {
|
|
68
|
-
return;
|
|
62
|
+
if (cb.current && typeof cb.current === 'function') {
|
|
63
|
+
cb.current(entries[0]);
|
|
69
64
|
}
|
|
65
|
+
};
|
|
70
66
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const onResize = entries => {
|
|
75
|
-
if (firstCall) {
|
|
76
|
-
firstCall = false;
|
|
77
|
-
|
|
78
|
-
if (!ignoreFirstCall) {
|
|
79
|
-
ownerWindow.requestAnimationFrame(() => {
|
|
80
|
-
onResize(entries);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (!Array.isArray(entries) || !entries.length || abort) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
67
|
+
const resizeObserver = new ResizeObserver(onResize);
|
|
68
|
+
resizeObserver.observe(targetEl); // eslint-disable-next-line consistent-return
|
|
90
69
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const resizeObserver = new ResizeObserver(onResize);
|
|
97
|
-
resizeObserver.observe(targetEl);
|
|
98
|
-
return () => {
|
|
99
|
-
abort = true;
|
|
100
|
-
resizeObserver.disconnect();
|
|
101
|
-
};
|
|
70
|
+
return () => {
|
|
71
|
+
abort = true;
|
|
72
|
+
resizeObserver.disconnect();
|
|
102
73
|
};
|
|
103
|
-
|
|
104
|
-
t5 = [target, ignoreFirstCall];
|
|
105
|
-
$[5] = ignoreFirstCall;
|
|
106
|
-
$[6] = target;
|
|
107
|
-
$[7] = t4;
|
|
108
|
-
$[8] = t5;
|
|
109
|
-
} else {
|
|
110
|
-
t4 = $[7];
|
|
111
|
-
t5 = $[8];
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
useEffect(t4, t5);
|
|
74
|
+
}, [target, ignoreFirstCall]);
|
|
115
75
|
};
|
|
116
76
|
|
|
117
77
|
export { useResizeObserver };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rescui/use-resize-observer",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5-RUI-308-Fix-select-issues-405b9fa40.12+405b9fa40",
|
|
4
4
|
"description": "ResizeObserver hook",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "JetBrains",
|
|
@@ -16,11 +16,10 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@babel/runtime-corejs3": "^7.26.0"
|
|
20
|
-
"react-compiler-runtime": "^1.0.0"
|
|
19
|
+
"@babel/runtime-corejs3": "^7.26.0"
|
|
21
20
|
},
|
|
22
21
|
"peerDependencies": {
|
|
23
|
-
"react": ">=
|
|
22
|
+
"react": ">=16.8.0 <20"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
26
25
|
"@rescui/scripts": "0.5.2"
|
|
@@ -29,5 +28,5 @@
|
|
|
29
28
|
"build": "rescui-scripts build"
|
|
30
29
|
},
|
|
31
30
|
"nx": {},
|
|
32
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "405b9fa40886b0ab6709c9185e8214599d2d792e"
|
|
33
32
|
}
|