@reactuses/core 1.0.3 → 1.0.5
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 -81
- package/index.cjs +68 -0
- package/index.d.ts +557 -541
- package/index.mjs +65 -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,81 +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
|
-
## 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/>
|
|
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
|
@@ -2298,6 +2298,70 @@ function useElementBounding(target, options = {}) {
|
|
|
2298
2298
|
};
|
|
2299
2299
|
}
|
|
2300
2300
|
|
|
2301
|
+
function useElementVisibility(target, options = {}) {
|
|
2302
|
+
const [visible, setVisible] = react.useState(false);
|
|
2303
|
+
const callback = react.useCallback((entries) => {
|
|
2304
|
+
const rect = entries[0].boundingClientRect;
|
|
2305
|
+
setVisible(
|
|
2306
|
+
rect.top <= (window.innerHeight || document.documentElement.clientHeight) && rect.left <= (window.innerWidth || document.documentElement.clientWidth) && rect.bottom >= 0 && rect.right >= 0
|
|
2307
|
+
);
|
|
2308
|
+
}, []);
|
|
2309
|
+
const stop = useIntersectionObserver(target, callback, options);
|
|
2310
|
+
return [visible, stop];
|
|
2311
|
+
}
|
|
2312
|
+
|
|
2313
|
+
function useWindowsFocus() {
|
|
2314
|
+
const [focused, setFocused] = react.useState(() => {
|
|
2315
|
+
if (!window) {
|
|
2316
|
+
return false;
|
|
2317
|
+
}
|
|
2318
|
+
return window.document.hasFocus();
|
|
2319
|
+
});
|
|
2320
|
+
useEventListener("blur", () => {
|
|
2321
|
+
setFocused(false);
|
|
2322
|
+
});
|
|
2323
|
+
useEventListener("focus", () => {
|
|
2324
|
+
setFocused(true);
|
|
2325
|
+
});
|
|
2326
|
+
return focused;
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
function useWindowSize() {
|
|
2330
|
+
const [windowSize, setWindowSize] = react.useState({
|
|
2331
|
+
width: 0,
|
|
2332
|
+
height: 0
|
|
2333
|
+
});
|
|
2334
|
+
const handleSize = () => {
|
|
2335
|
+
setWindowSize({
|
|
2336
|
+
width: window.innerWidth,
|
|
2337
|
+
height: window.innerHeight
|
|
2338
|
+
});
|
|
2339
|
+
};
|
|
2340
|
+
useEventListener("resize", handleSize);
|
|
2341
|
+
useIsomorphicLayoutEffect(() => {
|
|
2342
|
+
handleSize();
|
|
2343
|
+
}, []);
|
|
2344
|
+
return windowSize;
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2347
|
+
function useWindowScroll() {
|
|
2348
|
+
const [state, setState] = useRafState(() => ({
|
|
2349
|
+
x: 0,
|
|
2350
|
+
y: 0
|
|
2351
|
+
}));
|
|
2352
|
+
const handleScroll = () => {
|
|
2353
|
+
setState({ x: window.scrollX, y: window.screenY });
|
|
2354
|
+
};
|
|
2355
|
+
useEventListener("scroll", handleScroll, window, {
|
|
2356
|
+
capture: false,
|
|
2357
|
+
passive: true
|
|
2358
|
+
});
|
|
2359
|
+
useIsomorphicLayoutEffect(() => {
|
|
2360
|
+
handleScroll();
|
|
2361
|
+
}, []);
|
|
2362
|
+
return state;
|
|
2363
|
+
}
|
|
2364
|
+
|
|
2301
2365
|
exports.useActiveElement = useActiveElement;
|
|
2302
2366
|
exports.useCounter = useCounter;
|
|
2303
2367
|
exports.useCustomCompareEffect = useCustomCompareEffect;
|
|
@@ -2310,6 +2374,7 @@ exports.useDraggable = useDraggable;
|
|
|
2310
2374
|
exports.useDropZone = useDropZone;
|
|
2311
2375
|
exports.useElementBounding = useElementBounding;
|
|
2312
2376
|
exports.useElementSize = useElementSize;
|
|
2377
|
+
exports.useElementVisibility = useElementVisibility;
|
|
2313
2378
|
exports.useEvent = useEvent;
|
|
2314
2379
|
exports.useEventEmitter = useEventEmitter;
|
|
2315
2380
|
exports.useEventListener = useEventListener;
|
|
@@ -2365,3 +2430,6 @@ exports.useUpdate = useUpdate;
|
|
|
2365
2430
|
exports.useUpdateEffect = useUpdateEffect;
|
|
2366
2431
|
exports.useUpdateLayoutEffect = useUpdateLayoutEffect;
|
|
2367
2432
|
exports.useVirtualList = useVirtualList;
|
|
2433
|
+
exports.useWindowScroll = useWindowScroll;
|
|
2434
|
+
exports.useWindowSize = useWindowSize;
|
|
2435
|
+
exports.useWindowsFocus = useWindowsFocus;
|