@reactuses/core 6.1.12 → 6.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.
- package/README.md +64 -37
- package/dist/index.cjs +156 -43
- package/dist/index.d.cts +91 -2
- package/dist/index.d.mts +91 -2
- package/dist/index.d.ts +91 -2
- package/dist/index.mjs +156 -44
- package/package.json +35 -5
package/README.md
CHANGED
|
@@ -12,40 +12,67 @@
|
|
|
12
12
|
<img alt="TypeScript Support" src="https://img.shields.io/badge/TypeScript-Support-blue?style=for-the-badge&labelColor=24292e">
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Introduction
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
**ReactUse** is a comprehensive collection of **100+ essential React Hooks** for building modern React applications. Inspired by [VueUse](https://vueuse.org/), it provides production-ready hooks for browser APIs, state management, sensors, animations, DOM elements, and more.
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
### Features
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
```
|
|
21
|
+
- 🎯 **100+ Hooks** — The most comprehensive React hooks collection
|
|
22
|
+
- 📦 **Tree-Shakable** — Import only what you need
|
|
23
|
+
- 🔷 **TypeScript** — Full type definitions for every hook
|
|
24
|
+
- 🖥️ **SSR Compatible** — Works with Next.js, Remix, and more
|
|
25
|
+
- 📚 **Well Documented** — Interactive demos for every hook
|
|
26
|
+
- 🤖 **MCP Support** — AI-powered hook discovery
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
### Installation
|
|
30
29
|
|
|
31
|
-
```
|
|
32
|
-
|
|
30
|
+
```bash
|
|
31
|
+
npm i @reactuses/core
|
|
32
|
+
```
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
const [on, toggle] = useToggle(true)
|
|
34
|
+
### Quick Start
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
)
|
|
45
|
-
}
|
|
36
|
+
```tsx
|
|
37
|
+
import { useToggle } from "@reactuses/core";
|
|
38
|
+
|
|
39
|
+
const Demo = () => {
|
|
40
|
+
const [on, toggle] = useToggle(true);
|
|
41
|
+
return <button onClick={toggle}>{on ? "ON" : "OFF"}</button>;
|
|
42
|
+
};
|
|
46
43
|
```
|
|
47
44
|
|
|
48
|
-
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Hook Categories
|
|
48
|
+
|
|
49
|
+
<details>
|
|
50
|
+
<summary><strong>Browser (48 hooks)</strong></summary>
|
|
51
|
+
|
|
52
|
+
useClipboard, useColorMode, useCookie, useDarkMode, useDocumentVisibility, useEyeDropper, useFavicon, useFileDialog, useFullscreen, useMediaDevices, useMediaQuery, useOnline, usePermission, usePlatform, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePreferredLanguages, useScreenSafeArea, useScriptTag, useTextDirection, useTitle, useWebNotification, useBroadcastChannel, useEventSource, useFetchEventSource, useGeolocation, useIdle, useKeyModifier, useMobileLandscape, useNetwork, useOrientation, usePageLeave, useSpeechRecognition, useWindowFocus, useWindowScroll, useWindowSize, and more...
|
|
53
|
+
|
|
54
|
+
</details>
|
|
55
|
+
|
|
56
|
+
<details>
|
|
57
|
+
<summary><strong>State (24 hooks)</strong></summary>
|
|
58
|
+
|
|
59
|
+
useBoolean, useControlled, useCounter, useCycleList, useDebounce, useDebounceFn, useDisclosure, useLocalStorage, useMap, usePrevious, useSessionStorage, useSetState, useThrottle, useThrottleFn, useToggle, and more...
|
|
60
|
+
|
|
61
|
+
</details>
|
|
62
|
+
|
|
63
|
+
<details>
|
|
64
|
+
<summary><strong>Element (19 hooks)</strong></summary>
|
|
65
|
+
|
|
66
|
+
useClickOutside, useDraggable, useDropZone, useElementBounding, useElementByPoint, useElementSize, useElementVisibility, useFocus, useHover, useInfiniteScroll, useIntersectionObserver, useLongPress, useMeasure, useMouse, useMousePressed, useMutationObserver, useResizeObserver, useScroll, useScrollIntoView, and more...
|
|
67
|
+
|
|
68
|
+
</details>
|
|
69
|
+
|
|
70
|
+
<details>
|
|
71
|
+
<summary><strong>Effect (20 hooks)</strong></summary>
|
|
72
|
+
|
|
73
|
+
useAsyncEffect, useCustomCompareEffect, useDeepCompareEffect, useEventListener, useInterval, useMount, useRafFn, useTimeout, useTimeoutFn, useUnmount, useUpdate, and more...
|
|
74
|
+
|
|
75
|
+
</details>
|
|
49
76
|
|
|
50
77
|
---
|
|
51
78
|
|
|
@@ -58,25 +85,25 @@ Refer to [documentations](https://reactuse.com/) for more details.
|
|
|
58
85
|
|
|
59
86
|
---
|
|
60
87
|
|
|
61
|
-
##
|
|
62
|
-
|
|
63
|
-
- [Documentation](https://reactuse.com/)
|
|
88
|
+
## MCP Support
|
|
64
89
|
|
|
65
|
-
|
|
90
|
+
If you want to use the MCP (Model Context Protocol) integration with reactuse, you can easily set it up with the following configuration. This allows you to run the `@reactuses/mcp` utility via `npx` for enhanced command-line support and automation.
|
|
66
91
|
|
|
67
|
-
|
|
92
|
+
Add the following to your configuration:
|
|
68
93
|
|
|
69
|
-
|
|
94
|
+
```json
|
|
95
|
+
"@reactuses/mcp": {
|
|
96
|
+
"command": "npx",
|
|
97
|
+
"args": ["-y", "@reactuses/mcp@latest"],
|
|
98
|
+
"type": "stdio"
|
|
99
|
+
}
|
|
100
|
+
```
|
|
70
101
|
|
|
71
102
|
---
|
|
72
103
|
|
|
73
|
-
##
|
|
74
|
-
|
|
75
|
-
See the [**Contributing Guide**](https://github.com/childrentime/reactuse/blob/main/CONTRIBUTING.md)
|
|
76
|
-
|
|
77
|
-
## ChangeLog
|
|
104
|
+
## Documentation
|
|
78
105
|
|
|
79
|
-
|
|
106
|
+
📖 [Full Documentation](https://reactuse.com) | 💬 [Discord](https://discord.gg/VEMFdByJ) | 🐛 [Issues](https://github.com/childrentime/reactuse/issues)
|
|
80
107
|
|
|
81
108
|
---
|
|
82
109
|
|
package/dist/index.cjs
CHANGED
|
@@ -223,7 +223,7 @@ function useMountedState() {
|
|
|
223
223
|
return get;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
function asyncGeneratorStep$
|
|
226
|
+
function asyncGeneratorStep$8(gen, resolve, reject, _next, _throw, key, arg) {
|
|
227
227
|
try {
|
|
228
228
|
var info = gen[key](arg);
|
|
229
229
|
var value = info.value;
|
|
@@ -237,16 +237,16 @@ function asyncGeneratorStep$7(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
237
237
|
Promise.resolve(value).then(_next, _throw);
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
function _async_to_generator$
|
|
240
|
+
function _async_to_generator$8(fn) {
|
|
241
241
|
return function() {
|
|
242
242
|
var self = this, args = arguments;
|
|
243
243
|
return new Promise(function(resolve, reject) {
|
|
244
244
|
var gen = fn.apply(self, args);
|
|
245
245
|
function _next(value) {
|
|
246
|
-
asyncGeneratorStep$
|
|
246
|
+
asyncGeneratorStep$8(gen, resolve, reject, _next, _throw, "next", value);
|
|
247
247
|
}
|
|
248
248
|
function _throw(err) {
|
|
249
|
-
asyncGeneratorStep$
|
|
249
|
+
asyncGeneratorStep$8(gen, resolve, reject, _next, _throw, "throw", err);
|
|
250
250
|
}
|
|
251
251
|
_next(undefined);
|
|
252
252
|
});
|
|
@@ -255,7 +255,7 @@ function _async_to_generator$7(fn) {
|
|
|
255
255
|
const useAsyncEffect = (effect, cleanup = noop$1, deps)=>{
|
|
256
256
|
const mounted = useMountedState();
|
|
257
257
|
React.useEffect(()=>{
|
|
258
|
-
const execute = ()=>_async_to_generator$
|
|
258
|
+
const execute = ()=>_async_to_generator$8(function*() {
|
|
259
259
|
if (!mounted()) {
|
|
260
260
|
return;
|
|
261
261
|
}
|
|
@@ -1360,7 +1360,7 @@ function useSupported(callback, sync = false) {
|
|
|
1360
1360
|
return supported;
|
|
1361
1361
|
}
|
|
1362
1362
|
|
|
1363
|
-
function asyncGeneratorStep$
|
|
1363
|
+
function asyncGeneratorStep$7(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1364
1364
|
try {
|
|
1365
1365
|
var info = gen[key](arg);
|
|
1366
1366
|
var value = info.value;
|
|
@@ -1374,16 +1374,16 @@ function asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
1374
1374
|
Promise.resolve(value).then(_next, _throw);
|
|
1375
1375
|
}
|
|
1376
1376
|
}
|
|
1377
|
-
function _async_to_generator$
|
|
1377
|
+
function _async_to_generator$7(fn) {
|
|
1378
1378
|
return function() {
|
|
1379
1379
|
var self = this, args = arguments;
|
|
1380
1380
|
return new Promise(function(resolve, reject) {
|
|
1381
1381
|
var gen = fn.apply(self, args);
|
|
1382
1382
|
function _next(value) {
|
|
1383
|
-
asyncGeneratorStep$
|
|
1383
|
+
asyncGeneratorStep$7(gen, resolve, reject, _next, _throw, "next", value);
|
|
1384
1384
|
}
|
|
1385
1385
|
function _throw(err) {
|
|
1386
|
-
asyncGeneratorStep$
|
|
1386
|
+
asyncGeneratorStep$7(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1387
1387
|
}
|
|
1388
1388
|
_next(undefined);
|
|
1389
1389
|
});
|
|
@@ -1391,7 +1391,7 @@ function _async_to_generator$6(fn) {
|
|
|
1391
1391
|
}
|
|
1392
1392
|
const useEyeDropper = ()=>{
|
|
1393
1393
|
const isSupported = useSupported(()=>typeof window !== 'undefined' && 'EyeDropper' in window, true);
|
|
1394
|
-
const open = React.useCallback((options = {})=>_async_to_generator$
|
|
1394
|
+
const open = React.useCallback((options = {})=>_async_to_generator$7(function*() {
|
|
1395
1395
|
if (!isSupported) {
|
|
1396
1396
|
return {
|
|
1397
1397
|
sRGBHex: ''
|
|
@@ -1426,7 +1426,7 @@ function useFavicon(href, baseUrl = '', rel = 'icon') {
|
|
|
1426
1426
|
]);
|
|
1427
1427
|
}
|
|
1428
1428
|
|
|
1429
|
-
function asyncGeneratorStep$
|
|
1429
|
+
function asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1430
1430
|
try {
|
|
1431
1431
|
var info = gen[key](arg);
|
|
1432
1432
|
var value = info.value;
|
|
@@ -1440,16 +1440,16 @@ function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
1440
1440
|
Promise.resolve(value).then(_next, _throw);
|
|
1441
1441
|
}
|
|
1442
1442
|
}
|
|
1443
|
-
function _async_to_generator$
|
|
1443
|
+
function _async_to_generator$6(fn) {
|
|
1444
1444
|
return function() {
|
|
1445
1445
|
var self = this, args = arguments;
|
|
1446
1446
|
return new Promise(function(resolve, reject) {
|
|
1447
1447
|
var gen = fn.apply(self, args);
|
|
1448
1448
|
function _next(value) {
|
|
1449
|
-
asyncGeneratorStep$
|
|
1449
|
+
asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, "next", value);
|
|
1450
1450
|
}
|
|
1451
1451
|
function _throw(err) {
|
|
1452
|
-
asyncGeneratorStep$
|
|
1452
|
+
asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1453
1453
|
}
|
|
1454
1454
|
_next(undefined);
|
|
1455
1455
|
});
|
|
@@ -1492,7 +1492,7 @@ const useFileDialog = (options = defaultOptions$1)=>{
|
|
|
1492
1492
|
return input;
|
|
1493
1493
|
}, []);
|
|
1494
1494
|
inputRef.current = initFn();
|
|
1495
|
-
const open = (localOptions)=>_async_to_generator$
|
|
1495
|
+
const open = (localOptions)=>_async_to_generator$6(function*() {
|
|
1496
1496
|
if (!inputRef.current) {
|
|
1497
1497
|
return;
|
|
1498
1498
|
}
|
|
@@ -1905,7 +1905,7 @@ const createUpdateEffect = (hook)=>(effect, deps)=>{
|
|
|
1905
1905
|
|
|
1906
1906
|
const useUpdateEffect = createUpdateEffect(React.useEffect);
|
|
1907
1907
|
|
|
1908
|
-
function asyncGeneratorStep$
|
|
1908
|
+
function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1909
1909
|
try {
|
|
1910
1910
|
var info = gen[key](arg);
|
|
1911
1911
|
var value = info.value;
|
|
@@ -1919,16 +1919,16 @@ function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
1919
1919
|
Promise.resolve(value).then(_next, _throw);
|
|
1920
1920
|
}
|
|
1921
1921
|
}
|
|
1922
|
-
function _async_to_generator$
|
|
1922
|
+
function _async_to_generator$5(fn) {
|
|
1923
1923
|
return function() {
|
|
1924
1924
|
var self = this, args = arguments;
|
|
1925
1925
|
return new Promise(function(resolve, reject) {
|
|
1926
1926
|
var gen = fn.apply(self, args);
|
|
1927
1927
|
function _next(value) {
|
|
1928
|
-
asyncGeneratorStep$
|
|
1928
|
+
asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "next", value);
|
|
1929
1929
|
}
|
|
1930
1930
|
function _throw(err) {
|
|
1931
|
-
asyncGeneratorStep$
|
|
1931
|
+
asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1932
1932
|
}
|
|
1933
1933
|
_next(undefined);
|
|
1934
1934
|
});
|
|
@@ -1961,7 +1961,7 @@ const useInfiniteScroll = (target, onLoadMore, options = defaultOptions$1)=>{
|
|
|
1961
1961
|
const di = state[3][direction];
|
|
1962
1962
|
useUpdateEffect(()=>{
|
|
1963
1963
|
const element = getTargetElement(target);
|
|
1964
|
-
const fn = ()=>_async_to_generator$
|
|
1964
|
+
const fn = ()=>_async_to_generator$5(function*() {
|
|
1965
1965
|
var _element_scrollHeight, _element_scrollWidth;
|
|
1966
1966
|
const previous = {
|
|
1967
1967
|
height: (_element_scrollHeight = element == null ? void 0 : element.scrollHeight) != null ? _element_scrollHeight : 0,
|
|
@@ -2111,7 +2111,7 @@ const useMeasure = (target, options = defaultOptions$1)=>{
|
|
|
2111
2111
|
];
|
|
2112
2112
|
};
|
|
2113
2113
|
|
|
2114
|
-
function asyncGeneratorStep$
|
|
2114
|
+
function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2115
2115
|
try {
|
|
2116
2116
|
var info = gen[key](arg);
|
|
2117
2117
|
var value = info.value;
|
|
@@ -2125,16 +2125,16 @@ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
2125
2125
|
Promise.resolve(value).then(_next, _throw);
|
|
2126
2126
|
}
|
|
2127
2127
|
}
|
|
2128
|
-
function _async_to_generator$
|
|
2128
|
+
function _async_to_generator$4(fn) {
|
|
2129
2129
|
return function() {
|
|
2130
2130
|
var self = this, args = arguments;
|
|
2131
2131
|
return new Promise(function(resolve, reject) {
|
|
2132
2132
|
var gen = fn.apply(self, args);
|
|
2133
2133
|
function _next(value) {
|
|
2134
|
-
asyncGeneratorStep$
|
|
2134
|
+
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "next", value);
|
|
2135
2135
|
}
|
|
2136
2136
|
function _throw(err) {
|
|
2137
|
-
asyncGeneratorStep$
|
|
2137
|
+
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "throw", err);
|
|
2138
2138
|
}
|
|
2139
2139
|
_next(undefined);
|
|
2140
2140
|
});
|
|
@@ -2168,7 +2168,7 @@ const useMediaDevices = (options = {})=>{
|
|
|
2168
2168
|
});
|
|
2169
2169
|
}).catch(noop$1);
|
|
2170
2170
|
}, []);
|
|
2171
|
-
const ensurePermissions = React.useCallback(()=>_async_to_generator$
|
|
2171
|
+
const ensurePermissions = React.useCallback(()=>_async_to_generator$4(function*() {
|
|
2172
2172
|
if (!isSupported) {
|
|
2173
2173
|
return false;
|
|
2174
2174
|
}
|
|
@@ -3257,7 +3257,10 @@ function useSticky(targetElement, { axis = 'y', nav = 0 }, scrollElement) {
|
|
|
3257
3257
|
}, [
|
|
3258
3258
|
targetKey,
|
|
3259
3259
|
scrollKey,
|
|
3260
|
-
scrollHandler
|
|
3260
|
+
scrollHandler,
|
|
3261
|
+
targetRef,
|
|
3262
|
+
scrollRef,
|
|
3263
|
+
axisRef
|
|
3261
3264
|
]);
|
|
3262
3265
|
return [
|
|
3263
3266
|
isSticky,
|
|
@@ -3407,7 +3410,7 @@ const useToggle = (initialValue)=>{
|
|
|
3407
3410
|
|
|
3408
3411
|
const useUpdateLayoutEffect = createUpdateEffect(React.useLayoutEffect);
|
|
3409
3412
|
|
|
3410
|
-
function asyncGeneratorStep$
|
|
3413
|
+
function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
|
|
3411
3414
|
try {
|
|
3412
3415
|
var info = gen[key](arg);
|
|
3413
3416
|
var value = info.value;
|
|
@@ -3421,16 +3424,16 @@ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
3421
3424
|
Promise.resolve(value).then(_next, _throw);
|
|
3422
3425
|
}
|
|
3423
3426
|
}
|
|
3424
|
-
function _async_to_generator$
|
|
3427
|
+
function _async_to_generator$3(fn) {
|
|
3425
3428
|
return function() {
|
|
3426
3429
|
var self = this, args = arguments;
|
|
3427
3430
|
return new Promise(function(resolve, reject) {
|
|
3428
3431
|
var gen = fn.apply(self, args);
|
|
3429
3432
|
function _next(value) {
|
|
3430
|
-
asyncGeneratorStep$
|
|
3433
|
+
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
|
|
3431
3434
|
}
|
|
3432
3435
|
function _throw(err) {
|
|
3433
|
-
asyncGeneratorStep$
|
|
3436
|
+
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
|
|
3434
3437
|
}
|
|
3435
3438
|
_next(undefined);
|
|
3436
3439
|
});
|
|
@@ -3460,7 +3463,7 @@ const useWebNotification = (requestPermissions = false)=>{
|
|
|
3460
3463
|
}, [
|
|
3461
3464
|
isSupported
|
|
3462
3465
|
]);
|
|
3463
|
-
const ensurePermissions = React.useCallback(()=>_async_to_generator$
|
|
3466
|
+
const ensurePermissions = React.useCallback(()=>_async_to_generator$3(function*() {
|
|
3464
3467
|
if (!isSupported) return;
|
|
3465
3468
|
if (!permissionGranted.current && Notification.permission !== 'denied') {
|
|
3466
3469
|
const result = yield Notification.requestPermission();
|
|
@@ -3571,7 +3574,7 @@ const useWindowSize = ()=>{
|
|
|
3571
3574
|
};
|
|
3572
3575
|
};
|
|
3573
3576
|
|
|
3574
|
-
function asyncGeneratorStep$
|
|
3577
|
+
function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
|
|
3575
3578
|
try {
|
|
3576
3579
|
var info = gen[key](arg);
|
|
3577
3580
|
var value = info.value;
|
|
@@ -3585,16 +3588,16 @@ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
3585
3588
|
Promise.resolve(value).then(_next, _throw);
|
|
3586
3589
|
}
|
|
3587
3590
|
}
|
|
3588
|
-
function _async_to_generator$
|
|
3591
|
+
function _async_to_generator$2(fn) {
|
|
3589
3592
|
return function() {
|
|
3590
3593
|
var self = this, args = arguments;
|
|
3591
3594
|
return new Promise(function(resolve, reject) {
|
|
3592
3595
|
var gen = fn.apply(self, args);
|
|
3593
3596
|
function _next(value) {
|
|
3594
|
-
asyncGeneratorStep$
|
|
3597
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
|
|
3595
3598
|
}
|
|
3596
3599
|
function _throw(err) {
|
|
3597
|
-
asyncGeneratorStep$
|
|
3600
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
|
|
3598
3601
|
}
|
|
3599
3602
|
_next(undefined);
|
|
3600
3603
|
});
|
|
@@ -3602,7 +3605,7 @@ function _async_to_generator$1(fn) {
|
|
|
3602
3605
|
}
|
|
3603
3606
|
const useClipboard = ()=>{
|
|
3604
3607
|
const [text, setText] = React.useState('');
|
|
3605
|
-
const updateText = React.useCallback(()=>_async_to_generator$
|
|
3608
|
+
const updateText = React.useCallback(()=>_async_to_generator$2(function*() {
|
|
3606
3609
|
// Check if document is focused before attempting to read clipboard
|
|
3607
3610
|
if (!document.hasFocus()) {
|
|
3608
3611
|
return;
|
|
@@ -3619,7 +3622,7 @@ const useClipboard = ()=>{
|
|
|
3619
3622
|
useEventListener('cut', updateText);
|
|
3620
3623
|
// Also listen for focus events to update clipboard when window regains focus
|
|
3621
3624
|
useEventListener('focus', updateText, window);
|
|
3622
|
-
const copy = React.useCallback((txt)=>_async_to_generator$
|
|
3625
|
+
const copy = React.useCallback((txt)=>_async_to_generator$2(function*() {
|
|
3623
3626
|
setText(txt);
|
|
3624
3627
|
try {
|
|
3625
3628
|
yield window.navigator.clipboard.writeText(txt);
|
|
@@ -4147,7 +4150,7 @@ const useElementByPoint = (options)=>{
|
|
|
4147
4150
|
};
|
|
4148
4151
|
};
|
|
4149
4152
|
|
|
4150
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
4153
|
+
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
4151
4154
|
try {
|
|
4152
4155
|
var info = gen[key](arg);
|
|
4153
4156
|
var value = info.value;
|
|
@@ -4161,16 +4164,16 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
4161
4164
|
Promise.resolve(value).then(_next, _throw);
|
|
4162
4165
|
}
|
|
4163
4166
|
}
|
|
4164
|
-
function _async_to_generator(fn) {
|
|
4167
|
+
function _async_to_generator$1(fn) {
|
|
4165
4168
|
return function() {
|
|
4166
4169
|
var self = this, args = arguments;
|
|
4167
4170
|
return new Promise(function(resolve, reject) {
|
|
4168
4171
|
var gen = fn.apply(self, args);
|
|
4169
4172
|
function _next(value) {
|
|
4170
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
4173
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
|
|
4171
4174
|
}
|
|
4172
4175
|
function _throw(err) {
|
|
4173
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
4176
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
|
|
4174
4177
|
}
|
|
4175
4178
|
_next(undefined);
|
|
4176
4179
|
});
|
|
@@ -4221,7 +4224,7 @@ const useFetchEventSource = (url, options = {})=>{
|
|
|
4221
4224
|
options.onClose == null ? void 0 : options.onClose.call(options);
|
|
4222
4225
|
}
|
|
4223
4226
|
});
|
|
4224
|
-
const open = useEvent(()=>_async_to_generator(function*() {
|
|
4227
|
+
const open = useEvent(()=>_async_to_generator$1(function*() {
|
|
4225
4228
|
close();
|
|
4226
4229
|
setStatus('CONNECTING');
|
|
4227
4230
|
explicitlyClosed.current = false;
|
|
@@ -4260,7 +4263,7 @@ const useFetchEventSource = (url, options = {})=>{
|
|
|
4260
4263
|
}
|
|
4261
4264
|
yield fetchEventSource.fetchEventSource(url.toString(), _extends({}, finalOptions, {
|
|
4262
4265
|
onopen (response) {
|
|
4263
|
-
return _async_to_generator(function*() {
|
|
4266
|
+
return _async_to_generator$1(function*() {
|
|
4264
4267
|
if (response.ok) {
|
|
4265
4268
|
setStatus('CONNECTED');
|
|
4266
4269
|
setError(null);
|
|
@@ -4509,6 +4512,115 @@ const useSpeechRecognition = (options = {})=>{
|
|
|
4509
4512
|
};
|
|
4510
4513
|
};
|
|
4511
4514
|
|
|
4515
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
4516
|
+
try {
|
|
4517
|
+
var info = gen[key](arg);
|
|
4518
|
+
var value = info.value;
|
|
4519
|
+
} catch (error) {
|
|
4520
|
+
reject(error);
|
|
4521
|
+
return;
|
|
4522
|
+
}
|
|
4523
|
+
if (info.done) {
|
|
4524
|
+
resolve(value);
|
|
4525
|
+
} else {
|
|
4526
|
+
Promise.resolve(value).then(_next, _throw);
|
|
4527
|
+
}
|
|
4528
|
+
}
|
|
4529
|
+
function _async_to_generator(fn) {
|
|
4530
|
+
return function() {
|
|
4531
|
+
var self = this, args = arguments;
|
|
4532
|
+
return new Promise(function(resolve, reject) {
|
|
4533
|
+
var gen = fn.apply(self, args);
|
|
4534
|
+
function _next(value) {
|
|
4535
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
4536
|
+
}
|
|
4537
|
+
function _throw(err) {
|
|
4538
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
4539
|
+
}
|
|
4540
|
+
_next(undefined);
|
|
4541
|
+
});
|
|
4542
|
+
};
|
|
4543
|
+
}
|
|
4544
|
+
const useWakeLock = (options = {})=>{
|
|
4545
|
+
const { onRequest, onRelease, onError } = options;
|
|
4546
|
+
const isSupported = useSupported(()=>'wakeLock' in navigator);
|
|
4547
|
+
const [isActive, setIsActive] = React.useState(false);
|
|
4548
|
+
const sentinelRef = React.useRef(null);
|
|
4549
|
+
const requestedTypeRef = React.useRef(false);
|
|
4550
|
+
const forceRequest = useEvent(()=>_async_to_generator(function*() {
|
|
4551
|
+
if (!isSupported) return;
|
|
4552
|
+
try {
|
|
4553
|
+
var _sentinelRef_current;
|
|
4554
|
+
yield (_sentinelRef_current = sentinelRef.current) == null ? void 0 : _sentinelRef_current.release();
|
|
4555
|
+
const sentinel = yield navigator.wakeLock.request('screen');
|
|
4556
|
+
sentinelRef.current = sentinel;
|
|
4557
|
+
setIsActive(true);
|
|
4558
|
+
sentinel.addEventListener('release', ()=>{
|
|
4559
|
+
var _sentinelRef_current;
|
|
4560
|
+
var _sentinelRef_current_type;
|
|
4561
|
+
requestedTypeRef.current = (_sentinelRef_current_type = (_sentinelRef_current = sentinelRef.current) == null ? void 0 : _sentinelRef_current.type) != null ? _sentinelRef_current_type : false;
|
|
4562
|
+
sentinelRef.current = null;
|
|
4563
|
+
setIsActive(false);
|
|
4564
|
+
onRelease == null ? void 0 : onRelease();
|
|
4565
|
+
}, {
|
|
4566
|
+
once: true
|
|
4567
|
+
});
|
|
4568
|
+
onRequest == null ? void 0 : onRequest();
|
|
4569
|
+
} catch (error) {
|
|
4570
|
+
onError == null ? void 0 : onError(error);
|
|
4571
|
+
}
|
|
4572
|
+
})());
|
|
4573
|
+
const request = useEvent(()=>_async_to_generator(function*() {
|
|
4574
|
+
if (!isSupported) return;
|
|
4575
|
+
if (document.visibilityState === 'visible') {
|
|
4576
|
+
yield forceRequest();
|
|
4577
|
+
} else {
|
|
4578
|
+
requestedTypeRef.current = 'screen';
|
|
4579
|
+
}
|
|
4580
|
+
})());
|
|
4581
|
+
const release = useEvent(()=>_async_to_generator(function*() {
|
|
4582
|
+
requestedTypeRef.current = false;
|
|
4583
|
+
const s = sentinelRef.current;
|
|
4584
|
+
sentinelRef.current = null;
|
|
4585
|
+
setIsActive(false);
|
|
4586
|
+
try {
|
|
4587
|
+
yield s == null ? void 0 : s.release();
|
|
4588
|
+
} catch (error) {
|
|
4589
|
+
onError == null ? void 0 : onError(error);
|
|
4590
|
+
}
|
|
4591
|
+
})());
|
|
4592
|
+
React.useEffect(()=>{
|
|
4593
|
+
const handleVisibilityChange = ()=>{
|
|
4594
|
+
if (document.visibilityState === 'visible' && requestedTypeRef.current) {
|
|
4595
|
+
requestedTypeRef.current = false;
|
|
4596
|
+
forceRequest();
|
|
4597
|
+
}
|
|
4598
|
+
};
|
|
4599
|
+
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
4600
|
+
return ()=>{
|
|
4601
|
+
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
4602
|
+
};
|
|
4603
|
+
}, [
|
|
4604
|
+
forceRequest
|
|
4605
|
+
]);
|
|
4606
|
+
React.useEffect(()=>{
|
|
4607
|
+
return ()=>{
|
|
4608
|
+
requestedTypeRef.current = false;
|
|
4609
|
+
if (sentinelRef.current) {
|
|
4610
|
+
sentinelRef.current.release();
|
|
4611
|
+
sentinelRef.current = null;
|
|
4612
|
+
}
|
|
4613
|
+
};
|
|
4614
|
+
}, []);
|
|
4615
|
+
return {
|
|
4616
|
+
isSupported,
|
|
4617
|
+
isActive,
|
|
4618
|
+
request,
|
|
4619
|
+
release,
|
|
4620
|
+
forceRequest
|
|
4621
|
+
};
|
|
4622
|
+
};
|
|
4623
|
+
|
|
4512
4624
|
exports.assignRef = assignRef;
|
|
4513
4625
|
exports.defaultOptions = defaultOptions;
|
|
4514
4626
|
exports.mergeRefs = mergeRefs;
|
|
@@ -4619,6 +4731,7 @@ exports.useUnmount = useUnmount;
|
|
|
4619
4731
|
exports.useUpdate = useUpdate;
|
|
4620
4732
|
exports.useUpdateEffect = useUpdateEffect;
|
|
4621
4733
|
exports.useUpdateLayoutEffect = useUpdateLayoutEffect;
|
|
4734
|
+
exports.useWakeLock = useWakeLock;
|
|
4622
4735
|
exports.useWebNotification = useWebNotification;
|
|
4623
4736
|
exports.useWindowScroll = useWindowScroll;
|
|
4624
4737
|
exports.useWindowSize = useWindowSize;
|