@reactuses/core 6.1.11 → 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 +162 -45
- 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 +162 -46
- 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
|
}
|
|
@@ -1351,12 +1351,16 @@ function useSupported(callback, sync = false) {
|
|
|
1351
1351
|
const [supported, setSupported] = React.useState(false);
|
|
1352
1352
|
const effect = sync ? useIsomorphicLayoutEffect : React.useEffect;
|
|
1353
1353
|
effect(()=>{
|
|
1354
|
-
|
|
1354
|
+
try {
|
|
1355
|
+
setSupported(Boolean(callback()));
|
|
1356
|
+
} catch (e) {
|
|
1357
|
+
setSupported(false);
|
|
1358
|
+
}
|
|
1355
1359
|
}, []);
|
|
1356
1360
|
return supported;
|
|
1357
1361
|
}
|
|
1358
1362
|
|
|
1359
|
-
function asyncGeneratorStep$
|
|
1363
|
+
function asyncGeneratorStep$7(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1360
1364
|
try {
|
|
1361
1365
|
var info = gen[key](arg);
|
|
1362
1366
|
var value = info.value;
|
|
@@ -1370,16 +1374,16 @@ function asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
1370
1374
|
Promise.resolve(value).then(_next, _throw);
|
|
1371
1375
|
}
|
|
1372
1376
|
}
|
|
1373
|
-
function _async_to_generator$
|
|
1377
|
+
function _async_to_generator$7(fn) {
|
|
1374
1378
|
return function() {
|
|
1375
1379
|
var self = this, args = arguments;
|
|
1376
1380
|
return new Promise(function(resolve, reject) {
|
|
1377
1381
|
var gen = fn.apply(self, args);
|
|
1378
1382
|
function _next(value) {
|
|
1379
|
-
asyncGeneratorStep$
|
|
1383
|
+
asyncGeneratorStep$7(gen, resolve, reject, _next, _throw, "next", value);
|
|
1380
1384
|
}
|
|
1381
1385
|
function _throw(err) {
|
|
1382
|
-
asyncGeneratorStep$
|
|
1386
|
+
asyncGeneratorStep$7(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1383
1387
|
}
|
|
1384
1388
|
_next(undefined);
|
|
1385
1389
|
});
|
|
@@ -1387,7 +1391,7 @@ function _async_to_generator$6(fn) {
|
|
|
1387
1391
|
}
|
|
1388
1392
|
const useEyeDropper = ()=>{
|
|
1389
1393
|
const isSupported = useSupported(()=>typeof window !== 'undefined' && 'EyeDropper' in window, true);
|
|
1390
|
-
const open = React.useCallback((options = {})=>_async_to_generator$
|
|
1394
|
+
const open = React.useCallback((options = {})=>_async_to_generator$7(function*() {
|
|
1391
1395
|
if (!isSupported) {
|
|
1392
1396
|
return {
|
|
1393
1397
|
sRGBHex: ''
|
|
@@ -1422,7 +1426,7 @@ function useFavicon(href, baseUrl = '', rel = 'icon') {
|
|
|
1422
1426
|
]);
|
|
1423
1427
|
}
|
|
1424
1428
|
|
|
1425
|
-
function asyncGeneratorStep$
|
|
1429
|
+
function asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1426
1430
|
try {
|
|
1427
1431
|
var info = gen[key](arg);
|
|
1428
1432
|
var value = info.value;
|
|
@@ -1436,16 +1440,16 @@ function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
1436
1440
|
Promise.resolve(value).then(_next, _throw);
|
|
1437
1441
|
}
|
|
1438
1442
|
}
|
|
1439
|
-
function _async_to_generator$
|
|
1443
|
+
function _async_to_generator$6(fn) {
|
|
1440
1444
|
return function() {
|
|
1441
1445
|
var self = this, args = arguments;
|
|
1442
1446
|
return new Promise(function(resolve, reject) {
|
|
1443
1447
|
var gen = fn.apply(self, args);
|
|
1444
1448
|
function _next(value) {
|
|
1445
|
-
asyncGeneratorStep$
|
|
1449
|
+
asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, "next", value);
|
|
1446
1450
|
}
|
|
1447
1451
|
function _throw(err) {
|
|
1448
|
-
asyncGeneratorStep$
|
|
1452
|
+
asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1449
1453
|
}
|
|
1450
1454
|
_next(undefined);
|
|
1451
1455
|
});
|
|
@@ -1488,7 +1492,7 @@ const useFileDialog = (options = defaultOptions$1)=>{
|
|
|
1488
1492
|
return input;
|
|
1489
1493
|
}, []);
|
|
1490
1494
|
inputRef.current = initFn();
|
|
1491
|
-
const open = (localOptions)=>_async_to_generator$
|
|
1495
|
+
const open = (localOptions)=>_async_to_generator$6(function*() {
|
|
1492
1496
|
if (!inputRef.current) {
|
|
1493
1497
|
return;
|
|
1494
1498
|
}
|
|
@@ -1682,7 +1686,7 @@ const initCoord = {
|
|
|
1682
1686
|
};
|
|
1683
1687
|
const useGeolocation = (options = defaultOptions$1)=>{
|
|
1684
1688
|
const { enableHighAccuracy = true, maximumAge = 30000, timeout = 27000 } = options;
|
|
1685
|
-
const isSupported = useSupported(()=>navigator && 'geolocation'
|
|
1689
|
+
const isSupported = useSupported(()=>typeof navigator !== 'undefined' && !!navigator.geolocation && typeof navigator.geolocation.getCurrentPosition === 'function' && typeof navigator.geolocation.watchPosition === 'function' && typeof navigator.geolocation.clearWatch === 'function');
|
|
1686
1690
|
const [coordinates, setCoordinates] = React.useState(initCoord);
|
|
1687
1691
|
const [locatedAt, setLocatedAt] = React.useState(null);
|
|
1688
1692
|
const [error, setError] = React.useState(null);
|
|
@@ -1901,7 +1905,7 @@ const createUpdateEffect = (hook)=>(effect, deps)=>{
|
|
|
1901
1905
|
|
|
1902
1906
|
const useUpdateEffect = createUpdateEffect(React.useEffect);
|
|
1903
1907
|
|
|
1904
|
-
function asyncGeneratorStep$
|
|
1908
|
+
function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1905
1909
|
try {
|
|
1906
1910
|
var info = gen[key](arg);
|
|
1907
1911
|
var value = info.value;
|
|
@@ -1915,16 +1919,16 @@ function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
1915
1919
|
Promise.resolve(value).then(_next, _throw);
|
|
1916
1920
|
}
|
|
1917
1921
|
}
|
|
1918
|
-
function _async_to_generator$
|
|
1922
|
+
function _async_to_generator$5(fn) {
|
|
1919
1923
|
return function() {
|
|
1920
1924
|
var self = this, args = arguments;
|
|
1921
1925
|
return new Promise(function(resolve, reject) {
|
|
1922
1926
|
var gen = fn.apply(self, args);
|
|
1923
1927
|
function _next(value) {
|
|
1924
|
-
asyncGeneratorStep$
|
|
1928
|
+
asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "next", value);
|
|
1925
1929
|
}
|
|
1926
1930
|
function _throw(err) {
|
|
1927
|
-
asyncGeneratorStep$
|
|
1931
|
+
asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1928
1932
|
}
|
|
1929
1933
|
_next(undefined);
|
|
1930
1934
|
});
|
|
@@ -1957,7 +1961,7 @@ const useInfiniteScroll = (target, onLoadMore, options = defaultOptions$1)=>{
|
|
|
1957
1961
|
const di = state[3][direction];
|
|
1958
1962
|
useUpdateEffect(()=>{
|
|
1959
1963
|
const element = getTargetElement(target);
|
|
1960
|
-
const fn = ()=>_async_to_generator$
|
|
1964
|
+
const fn = ()=>_async_to_generator$5(function*() {
|
|
1961
1965
|
var _element_scrollHeight, _element_scrollWidth;
|
|
1962
1966
|
const previous = {
|
|
1963
1967
|
height: (_element_scrollHeight = element == null ? void 0 : element.scrollHeight) != null ? _element_scrollHeight : 0,
|
|
@@ -2107,7 +2111,7 @@ const useMeasure = (target, options = defaultOptions$1)=>{
|
|
|
2107
2111
|
];
|
|
2108
2112
|
};
|
|
2109
2113
|
|
|
2110
|
-
function asyncGeneratorStep$
|
|
2114
|
+
function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2111
2115
|
try {
|
|
2112
2116
|
var info = gen[key](arg);
|
|
2113
2117
|
var value = info.value;
|
|
@@ -2121,16 +2125,16 @@ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
2121
2125
|
Promise.resolve(value).then(_next, _throw);
|
|
2122
2126
|
}
|
|
2123
2127
|
}
|
|
2124
|
-
function _async_to_generator$
|
|
2128
|
+
function _async_to_generator$4(fn) {
|
|
2125
2129
|
return function() {
|
|
2126
2130
|
var self = this, args = arguments;
|
|
2127
2131
|
return new Promise(function(resolve, reject) {
|
|
2128
2132
|
var gen = fn.apply(self, args);
|
|
2129
2133
|
function _next(value) {
|
|
2130
|
-
asyncGeneratorStep$
|
|
2134
|
+
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "next", value);
|
|
2131
2135
|
}
|
|
2132
2136
|
function _throw(err) {
|
|
2133
|
-
asyncGeneratorStep$
|
|
2137
|
+
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "throw", err);
|
|
2134
2138
|
}
|
|
2135
2139
|
_next(undefined);
|
|
2136
2140
|
});
|
|
@@ -2164,7 +2168,7 @@ const useMediaDevices = (options = {})=>{
|
|
|
2164
2168
|
});
|
|
2165
2169
|
}).catch(noop$1);
|
|
2166
2170
|
}, []);
|
|
2167
|
-
const ensurePermissions = React.useCallback(()=>_async_to_generator$
|
|
2171
|
+
const ensurePermissions = React.useCallback(()=>_async_to_generator$4(function*() {
|
|
2168
2172
|
if (!isSupported) {
|
|
2169
2173
|
return false;
|
|
2170
2174
|
}
|
|
@@ -3253,7 +3257,10 @@ function useSticky(targetElement, { axis = 'y', nav = 0 }, scrollElement) {
|
|
|
3253
3257
|
}, [
|
|
3254
3258
|
targetKey,
|
|
3255
3259
|
scrollKey,
|
|
3256
|
-
scrollHandler
|
|
3260
|
+
scrollHandler,
|
|
3261
|
+
targetRef,
|
|
3262
|
+
scrollRef,
|
|
3263
|
+
axisRef
|
|
3257
3264
|
]);
|
|
3258
3265
|
return [
|
|
3259
3266
|
isSticky,
|
|
@@ -3403,7 +3410,7 @@ const useToggle = (initialValue)=>{
|
|
|
3403
3410
|
|
|
3404
3411
|
const useUpdateLayoutEffect = createUpdateEffect(React.useLayoutEffect);
|
|
3405
3412
|
|
|
3406
|
-
function asyncGeneratorStep$
|
|
3413
|
+
function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
|
|
3407
3414
|
try {
|
|
3408
3415
|
var info = gen[key](arg);
|
|
3409
3416
|
var value = info.value;
|
|
@@ -3417,16 +3424,16 @@ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
3417
3424
|
Promise.resolve(value).then(_next, _throw);
|
|
3418
3425
|
}
|
|
3419
3426
|
}
|
|
3420
|
-
function _async_to_generator$
|
|
3427
|
+
function _async_to_generator$3(fn) {
|
|
3421
3428
|
return function() {
|
|
3422
3429
|
var self = this, args = arguments;
|
|
3423
3430
|
return new Promise(function(resolve, reject) {
|
|
3424
3431
|
var gen = fn.apply(self, args);
|
|
3425
3432
|
function _next(value) {
|
|
3426
|
-
asyncGeneratorStep$
|
|
3433
|
+
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
|
|
3427
3434
|
}
|
|
3428
3435
|
function _throw(err) {
|
|
3429
|
-
asyncGeneratorStep$
|
|
3436
|
+
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
|
|
3430
3437
|
}
|
|
3431
3438
|
_next(undefined);
|
|
3432
3439
|
});
|
|
@@ -3456,7 +3463,7 @@ const useWebNotification = (requestPermissions = false)=>{
|
|
|
3456
3463
|
}, [
|
|
3457
3464
|
isSupported
|
|
3458
3465
|
]);
|
|
3459
|
-
const ensurePermissions = React.useCallback(()=>_async_to_generator$
|
|
3466
|
+
const ensurePermissions = React.useCallback(()=>_async_to_generator$3(function*() {
|
|
3460
3467
|
if (!isSupported) return;
|
|
3461
3468
|
if (!permissionGranted.current && Notification.permission !== 'denied') {
|
|
3462
3469
|
const result = yield Notification.requestPermission();
|
|
@@ -3567,7 +3574,7 @@ const useWindowSize = ()=>{
|
|
|
3567
3574
|
};
|
|
3568
3575
|
};
|
|
3569
3576
|
|
|
3570
|
-
function asyncGeneratorStep$
|
|
3577
|
+
function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
|
|
3571
3578
|
try {
|
|
3572
3579
|
var info = gen[key](arg);
|
|
3573
3580
|
var value = info.value;
|
|
@@ -3581,16 +3588,16 @@ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
3581
3588
|
Promise.resolve(value).then(_next, _throw);
|
|
3582
3589
|
}
|
|
3583
3590
|
}
|
|
3584
|
-
function _async_to_generator$
|
|
3591
|
+
function _async_to_generator$2(fn) {
|
|
3585
3592
|
return function() {
|
|
3586
3593
|
var self = this, args = arguments;
|
|
3587
3594
|
return new Promise(function(resolve, reject) {
|
|
3588
3595
|
var gen = fn.apply(self, args);
|
|
3589
3596
|
function _next(value) {
|
|
3590
|
-
asyncGeneratorStep$
|
|
3597
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
|
|
3591
3598
|
}
|
|
3592
3599
|
function _throw(err) {
|
|
3593
|
-
asyncGeneratorStep$
|
|
3600
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
|
|
3594
3601
|
}
|
|
3595
3602
|
_next(undefined);
|
|
3596
3603
|
});
|
|
@@ -3598,7 +3605,7 @@ function _async_to_generator$1(fn) {
|
|
|
3598
3605
|
}
|
|
3599
3606
|
const useClipboard = ()=>{
|
|
3600
3607
|
const [text, setText] = React.useState('');
|
|
3601
|
-
const updateText = React.useCallback(()=>_async_to_generator$
|
|
3608
|
+
const updateText = React.useCallback(()=>_async_to_generator$2(function*() {
|
|
3602
3609
|
// Check if document is focused before attempting to read clipboard
|
|
3603
3610
|
if (!document.hasFocus()) {
|
|
3604
3611
|
return;
|
|
@@ -3615,7 +3622,7 @@ const useClipboard = ()=>{
|
|
|
3615
3622
|
useEventListener('cut', updateText);
|
|
3616
3623
|
// Also listen for focus events to update clipboard when window regains focus
|
|
3617
3624
|
useEventListener('focus', updateText, window);
|
|
3618
|
-
const copy = React.useCallback((txt)=>_async_to_generator$
|
|
3625
|
+
const copy = React.useCallback((txt)=>_async_to_generator$2(function*() {
|
|
3619
3626
|
setText(txt);
|
|
3620
3627
|
try {
|
|
3621
3628
|
yield window.navigator.clipboard.writeText(txt);
|
|
@@ -4143,7 +4150,7 @@ const useElementByPoint = (options)=>{
|
|
|
4143
4150
|
};
|
|
4144
4151
|
};
|
|
4145
4152
|
|
|
4146
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
4153
|
+
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
4147
4154
|
try {
|
|
4148
4155
|
var info = gen[key](arg);
|
|
4149
4156
|
var value = info.value;
|
|
@@ -4157,16 +4164,16 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
4157
4164
|
Promise.resolve(value).then(_next, _throw);
|
|
4158
4165
|
}
|
|
4159
4166
|
}
|
|
4160
|
-
function _async_to_generator(fn) {
|
|
4167
|
+
function _async_to_generator$1(fn) {
|
|
4161
4168
|
return function() {
|
|
4162
4169
|
var self = this, args = arguments;
|
|
4163
4170
|
return new Promise(function(resolve, reject) {
|
|
4164
4171
|
var gen = fn.apply(self, args);
|
|
4165
4172
|
function _next(value) {
|
|
4166
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
4173
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
|
|
4167
4174
|
}
|
|
4168
4175
|
function _throw(err) {
|
|
4169
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
4176
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
|
|
4170
4177
|
}
|
|
4171
4178
|
_next(undefined);
|
|
4172
4179
|
});
|
|
@@ -4217,7 +4224,7 @@ const useFetchEventSource = (url, options = {})=>{
|
|
|
4217
4224
|
options.onClose == null ? void 0 : options.onClose.call(options);
|
|
4218
4225
|
}
|
|
4219
4226
|
});
|
|
4220
|
-
const open = useEvent(()=>_async_to_generator(function*() {
|
|
4227
|
+
const open = useEvent(()=>_async_to_generator$1(function*() {
|
|
4221
4228
|
close();
|
|
4222
4229
|
setStatus('CONNECTING');
|
|
4223
4230
|
explicitlyClosed.current = false;
|
|
@@ -4256,7 +4263,7 @@ const useFetchEventSource = (url, options = {})=>{
|
|
|
4256
4263
|
}
|
|
4257
4264
|
yield fetchEventSource.fetchEventSource(url.toString(), _extends({}, finalOptions, {
|
|
4258
4265
|
onopen (response) {
|
|
4259
|
-
return _async_to_generator(function*() {
|
|
4266
|
+
return _async_to_generator$1(function*() {
|
|
4260
4267
|
if (response.ok) {
|
|
4261
4268
|
setStatus('CONNECTED');
|
|
4262
4269
|
setError(null);
|
|
@@ -4505,6 +4512,115 @@ const useSpeechRecognition = (options = {})=>{
|
|
|
4505
4512
|
};
|
|
4506
4513
|
};
|
|
4507
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
|
+
|
|
4508
4624
|
exports.assignRef = assignRef;
|
|
4509
4625
|
exports.defaultOptions = defaultOptions;
|
|
4510
4626
|
exports.mergeRefs = mergeRefs;
|
|
@@ -4615,6 +4731,7 @@ exports.useUnmount = useUnmount;
|
|
|
4615
4731
|
exports.useUpdate = useUpdate;
|
|
4616
4732
|
exports.useUpdateEffect = useUpdateEffect;
|
|
4617
4733
|
exports.useUpdateLayoutEffect = useUpdateLayoutEffect;
|
|
4734
|
+
exports.useWakeLock = useWakeLock;
|
|
4618
4735
|
exports.useWebNotification = useWebNotification;
|
|
4619
4736
|
exports.useWindowScroll = useWindowScroll;
|
|
4620
4737
|
exports.useWindowSize = useWindowSize;
|