@reactuses/core 1.0.2 → 1.0.3
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/LICENSE +24 -24
- package/README.md +81 -73
- package/index.cjs +76 -0
- package/index.d.ts +543 -505
- package/index.mjs +76 -1
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
This is free and unencumbered software released into the public domain.
|
|
2
|
-
|
|
3
|
-
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
4
|
-
distribute this software, either in source code form or as a compiled
|
|
5
|
-
binary, for any purpose, commercial or non-commercial, and by any
|
|
6
|
-
means.
|
|
7
|
-
|
|
8
|
-
In jurisdictions that recognize copyright laws, the author or authors
|
|
9
|
-
of this software dedicate any and all copyright interest in the
|
|
10
|
-
software to the public domain. We make this dedication for the benefit
|
|
11
|
-
of the public at large and to the detriment of our heirs and
|
|
12
|
-
successors. We intend this dedication to be an overt act of
|
|
13
|
-
relinquishment in perpetuity of all present and future rights to this
|
|
14
|
-
software under copyright law.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
-
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
20
|
-
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
|
-
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
-
|
|
24
|
-
For more information, please refer to <http://unlicense.org/>
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
|
2
|
+
|
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
4
|
+
distribute this software, either in source code form or as a compiled
|
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
|
6
|
+
means.
|
|
7
|
+
|
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
|
9
|
+
of this software dedicate any and all copyright interest in the
|
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
|
11
|
+
of the public at large and to the detriment of our heirs and
|
|
12
|
+
successors. We intend this dedication to be an overt act of
|
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
|
14
|
+
software under copyright law.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
For more information, please refer to <http://unlicense.org/>
|
package/README.md
CHANGED
|
@@ -1,73 +1,81 @@
|
|
|
1
|
-
<div align = "center">
|
|
2
|
-
<h1 align = "center">
|
|
3
|
-
reactuse
|
|
4
|
-
</h1>
|
|
5
|
-
</div>
|
|
6
|
-
|
|
7
|
-
<p align="center">
|
|
8
|
-
<a href="https://bundlephobia.com/result?p=@reactuses/core">
|
|
9
|
-
<img alt="Bundlephobia" src="https://img.shields.io/bundlephobia/minzip/@reactuses/core?style=for-the-badge&labelColor=24292e">
|
|
10
|
-
</a>
|
|
11
|
-
<a aria-label="Types" href="https://www.npmjs.com/package/@reactuses/core">
|
|
12
|
-
<img alt="Types" src="https://img.shields.io/npm/types/react-use-system-color-mode?style=for-the-badge&labelColor=24292e">
|
|
13
|
-
</a>
|
|
14
|
-
<a aria-label="NPM version" href="https://www.npmjs.com/package/@reactuses/core">
|
|
15
|
-
<img alt="NPM Version" src="https://img.shields.io/npm/v/@reactuses/core?style=for-the-badge&labelColor=24292e">
|
|
16
|
-
</a>
|
|
17
|
-
<a aria-label="License" href="https://jaredlunde.mit-license.org/">
|
|
18
|
-
<img alt="UnLicense" src="https://img.shields.io/npm/l/@reactuses/core?style=for-the-badge&labelColor=24292e">
|
|
19
|
-
</a>
|
|
20
|
-
</p>
|
|
21
|
-
|
|
22
|
-
<pre align="center">npm i @reactuses/core</pre>
|
|
23
|
-
|
|
24
|
-
<p align="center">
|
|
25
|
-
Collection of essential React Hooks Utilities.
|
|
26
|
-
</p>
|
|
27
|
-
|
|
28
|
-
<hr>
|
|
29
|
-
|
|
30
|
-
## QuickStart
|
|
31
|
-
|
|
32
|
-
```tsx harmony
|
|
33
|
-
import { useToggle } from "@reactuses/core";
|
|
34
|
-
|
|
35
|
-
const Demo = () => {
|
|
36
|
-
const [on, toggle] = useToggle(true);
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
<div>
|
|
40
|
-
<div>{on ? "ON" : "OFF"}</div>
|
|
41
|
-
<button onClick={toggle}>Toggle</button>
|
|
42
|
-
<button onClick={() => toggle(true)}>set ON</button>
|
|
43
|
-
<button onClick={() => toggle(false)}>set OFF</button>
|
|
44
|
-
</div>
|
|
45
|
-
);
|
|
46
|
-
};
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Refer to [documentations](https://reactuse.com/) for more details.
|
|
50
|
-
|
|
51
|
-
<hr>
|
|
52
|
-
|
|
53
|
-
## Documentation & Live Examples
|
|
54
|
-
|
|
55
|
-
* [Documentation](https://reactuse.com/)
|
|
56
|
-
|
|
57
|
-
<hr/>
|
|
58
|
-
|
|
59
|
-
## Contribute
|
|
60
|
-
|
|
61
|
-
See the [**Contributing Guide**](CONTRIBUTING.md)
|
|
62
|
-
|
|
63
|
-
<hr/>
|
|
64
|
-
|
|
65
|
-
##
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
* [
|
|
70
|
-
|
|
71
|
-
* [
|
|
72
|
-
|
|
73
|
-
|
|
1
|
+
<div align = "center">
|
|
2
|
+
<h1 align = "center">
|
|
3
|
+
reactuse
|
|
4
|
+
</h1>
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://bundlephobia.com/result?p=@reactuses/core">
|
|
9
|
+
<img alt="Bundlephobia" src="https://img.shields.io/bundlephobia/minzip/@reactuses/core?style=for-the-badge&labelColor=24292e">
|
|
10
|
+
</a>
|
|
11
|
+
<a aria-label="Types" href="https://www.npmjs.com/package/@reactuses/core">
|
|
12
|
+
<img alt="Types" src="https://img.shields.io/npm/types/react-use-system-color-mode?style=for-the-badge&labelColor=24292e">
|
|
13
|
+
</a>
|
|
14
|
+
<a aria-label="NPM version" href="https://www.npmjs.com/package/@reactuses/core">
|
|
15
|
+
<img alt="NPM Version" src="https://img.shields.io/npm/v/@reactuses/core?style=for-the-badge&labelColor=24292e">
|
|
16
|
+
</a>
|
|
17
|
+
<a aria-label="License" href="https://jaredlunde.mit-license.org/">
|
|
18
|
+
<img alt="UnLicense" src="https://img.shields.io/npm/l/@reactuses/core?style=for-the-badge&labelColor=24292e">
|
|
19
|
+
</a>
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
<pre align="center">npm i @reactuses/core</pre>
|
|
23
|
+
|
|
24
|
+
<p align="center">
|
|
25
|
+
Collection of essential React Hooks Utilities.
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
<hr>
|
|
29
|
+
|
|
30
|
+
## QuickStart
|
|
31
|
+
|
|
32
|
+
```tsx harmony
|
|
33
|
+
import { useToggle } from "@reactuses/core";
|
|
34
|
+
|
|
35
|
+
const Demo = () => {
|
|
36
|
+
const [on, toggle] = useToggle(true);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<div>
|
|
40
|
+
<div>{on ? "ON" : "OFF"}</div>
|
|
41
|
+
<button onClick={toggle}>Toggle</button>
|
|
42
|
+
<button onClick={() => toggle(true)}>set ON</button>
|
|
43
|
+
<button onClick={() => toggle(false)}>set OFF</button>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Refer to [documentations](https://reactuse.com/) for more details.
|
|
50
|
+
|
|
51
|
+
<hr>
|
|
52
|
+
|
|
53
|
+
## Documentation & Live Examples
|
|
54
|
+
|
|
55
|
+
* [Documentation](https://reactuse.com/)
|
|
56
|
+
|
|
57
|
+
<hr/>
|
|
58
|
+
|
|
59
|
+
## Contribute
|
|
60
|
+
|
|
61
|
+
See the [**Contributing Guide**](CONTRIBUTING.md)
|
|
62
|
+
|
|
63
|
+
<hr/>
|
|
64
|
+
|
|
65
|
+
## Idea
|
|
66
|
+
|
|
67
|
+
We want to keep a single hook function as simple as possible.
|
|
68
|
+
|
|
69
|
+
* For data fetch, we recommend use [swr](https://www.npmjs.com/package/swr)
|
|
70
|
+
|
|
71
|
+
* For keyboard shortcuts, we recommend use [react-hotkeys-hook](https://www.npmjs.com/package/react-hotkeys-hook)
|
|
72
|
+
|
|
73
|
+
## Thanks
|
|
74
|
+
|
|
75
|
+
This project is heavily inspired by the following awesome projects.
|
|
76
|
+
|
|
77
|
+
* [streamich/react-use](https://github.com/streamich/react-use)
|
|
78
|
+
* [ahooks](https://github.com/alibaba/hooks)
|
|
79
|
+
* [vueuse](https://github.com/vueuse/vueuse)
|
|
80
|
+
|
|
81
|
+
<hr/>
|
package/index.cjs
CHANGED
|
@@ -2223,6 +2223,81 @@ function useDraggable(target, options = {}) {
|
|
|
2223
2223
|
return [position.x, position.y, !!pressedDelta];
|
|
2224
2224
|
}
|
|
2225
2225
|
|
|
2226
|
+
function useElementBounding(target, options = {}) {
|
|
2227
|
+
const {
|
|
2228
|
+
reset = true,
|
|
2229
|
+
windowResize = true,
|
|
2230
|
+
windowScroll = true,
|
|
2231
|
+
immediate = true
|
|
2232
|
+
} = options;
|
|
2233
|
+
const [height, setHeight] = react.useState(0);
|
|
2234
|
+
const [bottom, setBottom] = react.useState(0);
|
|
2235
|
+
const [left, setLeft] = react.useState(0);
|
|
2236
|
+
const [right, setRight] = react.useState(0);
|
|
2237
|
+
const [top, setTop] = react.useState(0);
|
|
2238
|
+
const [width, setWidth] = react.useState(0);
|
|
2239
|
+
const [x, setX] = react.useState(0);
|
|
2240
|
+
const [y, setY] = react.useState(0);
|
|
2241
|
+
const update = useEvent(() => {
|
|
2242
|
+
const element = getTargetElement(target);
|
|
2243
|
+
if (!element) {
|
|
2244
|
+
if (reset) {
|
|
2245
|
+
setHeight(0);
|
|
2246
|
+
setBottom(0);
|
|
2247
|
+
setLeft(0);
|
|
2248
|
+
setRight(0);
|
|
2249
|
+
setTop(0);
|
|
2250
|
+
setWidth(0);
|
|
2251
|
+
setX(0);
|
|
2252
|
+
setY(0);
|
|
2253
|
+
}
|
|
2254
|
+
return;
|
|
2255
|
+
}
|
|
2256
|
+
const rect = element.getBoundingClientRect();
|
|
2257
|
+
setHeight(rect.height);
|
|
2258
|
+
setBottom(rect.bottom);
|
|
2259
|
+
setLeft(rect.left);
|
|
2260
|
+
setRight(rect.right);
|
|
2261
|
+
setTop(rect.top);
|
|
2262
|
+
setWidth(rect.width);
|
|
2263
|
+
setX(rect.x);
|
|
2264
|
+
setY(rect.y);
|
|
2265
|
+
});
|
|
2266
|
+
useResizeObserver(target, update);
|
|
2267
|
+
react.useEffect(() => {
|
|
2268
|
+
if (immediate) {
|
|
2269
|
+
update();
|
|
2270
|
+
}
|
|
2271
|
+
}, [immediate, update]);
|
|
2272
|
+
react.useEffect(() => {
|
|
2273
|
+
if (windowScroll) {
|
|
2274
|
+
window.addEventListener("scroll", update, { passive: true });
|
|
2275
|
+
}
|
|
2276
|
+
if (windowResize) {
|
|
2277
|
+
window.addEventListener("resize", update, { passive: true });
|
|
2278
|
+
}
|
|
2279
|
+
return () => {
|
|
2280
|
+
if (windowScroll) {
|
|
2281
|
+
window.removeEventListener("scroll", update);
|
|
2282
|
+
}
|
|
2283
|
+
if (windowResize) {
|
|
2284
|
+
window.removeEventListener("resize", update);
|
|
2285
|
+
}
|
|
2286
|
+
};
|
|
2287
|
+
}, [update, windowResize, windowScroll]);
|
|
2288
|
+
return {
|
|
2289
|
+
height,
|
|
2290
|
+
bottom,
|
|
2291
|
+
left,
|
|
2292
|
+
right,
|
|
2293
|
+
top,
|
|
2294
|
+
width,
|
|
2295
|
+
x,
|
|
2296
|
+
y,
|
|
2297
|
+
update
|
|
2298
|
+
};
|
|
2299
|
+
}
|
|
2300
|
+
|
|
2226
2301
|
exports.useActiveElement = useActiveElement;
|
|
2227
2302
|
exports.useCounter = useCounter;
|
|
2228
2303
|
exports.useCustomCompareEffect = useCustomCompareEffect;
|
|
@@ -2233,6 +2308,7 @@ exports.useDeepCompareEffect = useDeepCompareEffect;
|
|
|
2233
2308
|
exports.useDocumentVisibility = useDocumentVisibility;
|
|
2234
2309
|
exports.useDraggable = useDraggable;
|
|
2235
2310
|
exports.useDropZone = useDropZone;
|
|
2311
|
+
exports.useElementBounding = useElementBounding;
|
|
2236
2312
|
exports.useElementSize = useElementSize;
|
|
2237
2313
|
exports.useEvent = useEvent;
|
|
2238
2314
|
exports.useEventEmitter = useEventEmitter;
|