@reactuses/core 6.0.5 → 6.0.6
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 +21 -0
- package/dist/index.cjs +199 -190
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.mjs +199 -190
- package/dist/useQRCode.cjs +8 -8
- package/dist/useQRCode.mjs +8 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,6 +27,20 @@ Collection of essential React Hooks Utilities.
|
|
|
27
27
|
|
|
28
28
|
<hr>
|
|
29
29
|
|
|
30
|
+
## MCP Support
|
|
31
|
+
|
|
32
|
+
If you want to use the MCP (Meta Command 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.
|
|
33
|
+
|
|
34
|
+
Add the following to your configuration:
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
"@reactuses/mcp": {
|
|
38
|
+
"command": "npx",
|
|
39
|
+
"args": ["-y", "@reactuses/mcp@latest"],
|
|
40
|
+
"type": "stdio"
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
30
44
|
## QuickStart
|
|
31
45
|
|
|
32
46
|
```tsx harmony
|
|
@@ -50,6 +64,13 @@ Refer to [documentations](https://reactuse.com/) for more details.
|
|
|
50
64
|
|
|
51
65
|
<hr>
|
|
52
66
|
|
|
67
|
+
## Who's Using This
|
|
68
|
+
|
|
69
|
+
[](https://www.pinduoduo.com/)
|
|
70
|
+
[](https://www.ctrip.com/)
|
|
71
|
+
|
|
72
|
+
<hr>
|
|
73
|
+
|
|
53
74
|
## Documentation & Live Examples
|
|
54
75
|
|
|
55
76
|
- [Documentation](https://reactuse.com/)
|
package/dist/index.cjs
CHANGED
|
@@ -206,12 +206,12 @@ function _async_to_generator$7(fn) {
|
|
|
206
206
|
const useAsyncEffect = (effect, cleanup = noop, deps)=>{
|
|
207
207
|
const mounted = useMountedState();
|
|
208
208
|
React.useEffect(()=>{
|
|
209
|
-
const execute =
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
209
|
+
const execute = ()=>_async_to_generator$7(function*() {
|
|
210
|
+
if (!mounted()) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
yield effect();
|
|
214
|
+
})();
|
|
215
215
|
execute();
|
|
216
216
|
return ()=>{
|
|
217
217
|
cleanup();
|
|
@@ -1254,15 +1254,15 @@ function _async_to_generator$6(fn) {
|
|
|
1254
1254
|
}
|
|
1255
1255
|
const useEyeDropper = ()=>{
|
|
1256
1256
|
const isSupported = useSupported(()=>typeof window !== 'undefined' && 'EyeDropper' in window, true);
|
|
1257
|
-
const open = React.useCallback(
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1257
|
+
const open = React.useCallback((options = {})=>_async_to_generator$6(function*() {
|
|
1258
|
+
if (!isSupported) {
|
|
1259
|
+
return {
|
|
1260
|
+
sRGBHex: ''
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1263
|
+
const eyeDropper = new window.EyeDropper();
|
|
1264
|
+
return eyeDropper.open(options);
|
|
1265
|
+
})(), [
|
|
1266
1266
|
isSupported
|
|
1267
1267
|
]);
|
|
1268
1268
|
return [
|
|
@@ -1355,20 +1355,20 @@ const useFileDialog = (options = defaultOptions$1)=>{
|
|
|
1355
1355
|
return input;
|
|
1356
1356
|
}, []);
|
|
1357
1357
|
inputRef.current = initFn();
|
|
1358
|
-
const open =
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1358
|
+
const open = (localOptions)=>_async_to_generator$5(function*() {
|
|
1359
|
+
if (!inputRef.current) {
|
|
1360
|
+
return;
|
|
1361
|
+
}
|
|
1362
|
+
const _options = _extends$3({}, DEFAULT_OPTIONS, options, localOptions);
|
|
1363
|
+
inputRef.current.multiple = _options.multiple;
|
|
1364
|
+
inputRef.current.accept = _options.accept;
|
|
1365
|
+
inputRef.current.capture = _options.capture;
|
|
1366
|
+
fileOpenPromiseRef.current = new Promise((resolve)=>{
|
|
1367
|
+
resolveFileOpenPromiseRef.current = resolve;
|
|
1368
|
+
});
|
|
1369
|
+
inputRef.current.click();
|
|
1370
|
+
return fileOpenPromiseRef.current;
|
|
1371
|
+
})();
|
|
1372
1372
|
const reset = ()=>{
|
|
1373
1373
|
setFiles(null);
|
|
1374
1374
|
resolveFileOpenPromiseRef.current == null ? void 0 : resolveFileOpenPromiseRef.current.call(resolveFileOpenPromiseRef, null);
|
|
@@ -1821,20 +1821,20 @@ const useInfiniteScroll = (target, onLoadMore, options = defaultOptions$1)=>{
|
|
|
1821
1821
|
const di = state[3][direction];
|
|
1822
1822
|
useUpdateEffect(()=>{
|
|
1823
1823
|
const element = getTargetElement(target);
|
|
1824
|
-
const fn =
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1824
|
+
const fn = ()=>_async_to_generator$4(function*() {
|
|
1825
|
+
var _element_scrollHeight, _element_scrollWidth;
|
|
1826
|
+
const previous = {
|
|
1827
|
+
height: (_element_scrollHeight = element == null ? void 0 : element.scrollHeight) != null ? _element_scrollHeight : 0,
|
|
1828
|
+
width: (_element_scrollWidth = element == null ? void 0 : element.scrollWidth) != null ? _element_scrollWidth : 0
|
|
1829
|
+
};
|
|
1830
|
+
yield savedLoadMore.current(state);
|
|
1831
|
+
if (options.preserveScrollPosition && element) {
|
|
1832
|
+
element.scrollTo({
|
|
1833
|
+
top: element.scrollHeight - previous.height,
|
|
1834
|
+
left: element.scrollWidth - previous.width
|
|
1835
|
+
});
|
|
1836
|
+
}
|
|
1837
|
+
})();
|
|
1838
1838
|
fn();
|
|
1839
1839
|
}, [
|
|
1840
1840
|
di,
|
|
@@ -2028,30 +2028,30 @@ const useMediaDevices = (options = {})=>{
|
|
|
2028
2028
|
});
|
|
2029
2029
|
}).catch(noop);
|
|
2030
2030
|
}, []);
|
|
2031
|
-
const ensurePermissions = React.useCallback(
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2031
|
+
const ensurePermissions = React.useCallback(()=>_async_to_generator$3(function*() {
|
|
2032
|
+
if (!isSupported) {
|
|
2033
|
+
return false;
|
|
2034
|
+
}
|
|
2035
|
+
if (permissionGranted.current) {
|
|
2036
|
+
return true;
|
|
2037
|
+
}
|
|
2038
|
+
let state;
|
|
2039
|
+
try {
|
|
2040
|
+
state = (yield navigator.permissions.query({
|
|
2041
|
+
name: 'camera'
|
|
2042
|
+
})).state;
|
|
2043
|
+
} catch (error) {
|
|
2044
|
+
state = 'prompt';
|
|
2045
|
+
}
|
|
2046
|
+
if (state !== 'granted') {
|
|
2047
|
+
stream.current = yield navigator.mediaDevices.getUserMedia(constraints);
|
|
2048
|
+
onChange();
|
|
2049
|
+
permissionGranted.current = true;
|
|
2050
|
+
} else {
|
|
2051
|
+
permissionGranted.current = false;
|
|
2052
|
+
}
|
|
2053
|
+
return permissionGranted.current;
|
|
2054
|
+
})(), [
|
|
2055
2055
|
onChange,
|
|
2056
2056
|
isSupported,
|
|
2057
2057
|
constraints
|
|
@@ -2845,15 +2845,24 @@ const useScrollIntoView = (targetElement, { duration = 1250, axis = 'y', onScrol
|
|
|
2845
2845
|
};
|
|
2846
2846
|
};
|
|
2847
2847
|
|
|
2848
|
+
function checkOverflowScroll(ele) {
|
|
2849
|
+
const style = window.getComputedStyle(ele);
|
|
2850
|
+
if (style.overflowX === 'scroll' || style.overflowY === 'scroll' || style.overflowX === 'auto' && ele.clientWidth < ele.scrollWidth || style.overflowY === 'auto' && ele.clientHeight < ele.scrollHeight) {
|
|
2851
|
+
return true;
|
|
2852
|
+
} else {
|
|
2853
|
+
const parent = ele.parentNode;
|
|
2854
|
+
if (!parent || parent.tagName === 'BODY') return false;
|
|
2855
|
+
return checkOverflowScroll(parent);
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2848
2858
|
function preventDefault(rawEvent) {
|
|
2849
2859
|
const e = rawEvent || window.event;
|
|
2860
|
+
const _target = e.target;
|
|
2861
|
+
// Do not prevent if element or parentNodes have overflow: scroll set.
|
|
2862
|
+
if (checkOverflowScroll(_target)) return false;
|
|
2850
2863
|
// Do not prevent if the event has more than one touch (usually meaning this is a multi touch gesture like pinch to zoom).
|
|
2851
|
-
if (e.touches.length > 1)
|
|
2852
|
-
|
|
2853
|
-
}
|
|
2854
|
-
if (e.preventDefault) {
|
|
2855
|
-
e.preventDefault();
|
|
2856
|
-
}
|
|
2864
|
+
if (e.touches.length > 1) return true;
|
|
2865
|
+
if (e.preventDefault) e.preventDefault();
|
|
2857
2866
|
return false;
|
|
2858
2867
|
}
|
|
2859
2868
|
const useScrollLock = (target, initialState = false)=>{
|
|
@@ -3166,14 +3175,14 @@ const useWebNotification = (requestPermissions = false)=>{
|
|
|
3166
3175
|
}, [
|
|
3167
3176
|
isSupported
|
|
3168
3177
|
]);
|
|
3169
|
-
const ensurePermissions = React.useCallback(
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3178
|
+
const ensurePermissions = React.useCallback(()=>_async_to_generator$2(function*() {
|
|
3179
|
+
if (!isSupported) return;
|
|
3180
|
+
if (!permissionGranted.current && Notification.permission !== 'denied') {
|
|
3181
|
+
const result = yield Notification.requestPermission();
|
|
3182
|
+
if (result === 'granted') permissionGranted.current = true;
|
|
3183
|
+
}
|
|
3184
|
+
return permissionGranted.current;
|
|
3185
|
+
})(), [
|
|
3177
3186
|
isSupported
|
|
3178
3187
|
]);
|
|
3179
3188
|
React.useEffect(()=>{
|
|
@@ -3308,33 +3317,33 @@ function _async_to_generator$1(fn) {
|
|
|
3308
3317
|
}
|
|
3309
3318
|
const useClipboard = ()=>{
|
|
3310
3319
|
const [text, setText] = React.useState('');
|
|
3311
|
-
const updateText = React.useCallback(
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3320
|
+
const updateText = React.useCallback(()=>_async_to_generator$1(function*() {
|
|
3321
|
+
// Check if document is focused before attempting to read clipboard
|
|
3322
|
+
if (!document.hasFocus()) {
|
|
3323
|
+
return;
|
|
3324
|
+
}
|
|
3325
|
+
try {
|
|
3326
|
+
const value = yield window.navigator.clipboard.readText();
|
|
3327
|
+
setText(value);
|
|
3328
|
+
} catch (error) {
|
|
3329
|
+
// Handle cases where clipboard access is denied or unavailable
|
|
3330
|
+
console.warn('Failed to read clipboard:', error);
|
|
3331
|
+
}
|
|
3332
|
+
})(), []);
|
|
3324
3333
|
useEventListener('copy', updateText);
|
|
3325
3334
|
useEventListener('cut', updateText);
|
|
3326
3335
|
// Also listen for focus events to update clipboard when window regains focus
|
|
3327
3336
|
useEventListener('focus', updateText, window);
|
|
3328
|
-
const copy = React.useCallback(
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3337
|
+
const copy = React.useCallback((txt)=>_async_to_generator$1(function*() {
|
|
3338
|
+
setText(txt);
|
|
3339
|
+
try {
|
|
3340
|
+
yield window.navigator.clipboard.writeText(txt);
|
|
3341
|
+
} catch (error) {
|
|
3342
|
+
console.warn('Failed to write to clipboard:', error);
|
|
3343
|
+
throw error // Re-throw so caller can handle it
|
|
3344
|
+
;
|
|
3345
|
+
}
|
|
3346
|
+
})(), []);
|
|
3338
3347
|
React.useEffect(()=>{
|
|
3339
3348
|
updateText();
|
|
3340
3349
|
}, [
|
|
@@ -3904,98 +3913,98 @@ const useFetchEventSource = (url, options = {})=>{
|
|
|
3904
3913
|
options.onClose == null ? void 0 : options.onClose.call(options);
|
|
3905
3914
|
}
|
|
3906
3915
|
});
|
|
3907
|
-
const open = useEvent(
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3916
|
+
const open = useEvent(()=>_async_to_generator(function*() {
|
|
3917
|
+
close();
|
|
3918
|
+
setStatus('CONNECTING');
|
|
3919
|
+
explicitlyClosed.current = false;
|
|
3920
|
+
retries.current = 0;
|
|
3921
|
+
// 创建新的 AbortController
|
|
3922
|
+
abortController.current = new AbortController();
|
|
3923
|
+
try {
|
|
3924
|
+
// 从选项中提取 FetchEventSourceInit 相关的选项
|
|
3925
|
+
const { immediate, autoReconnect, onOpen, onMessage, onError, onClose, withCredentials, body } = options, fetchOptions = _object_without_properties_loose(options, [
|
|
3926
|
+
"immediate",
|
|
3927
|
+
"autoReconnect",
|
|
3928
|
+
"onOpen",
|
|
3929
|
+
"onMessage",
|
|
3930
|
+
"onError",
|
|
3931
|
+
"onClose",
|
|
3932
|
+
"withCredentials",
|
|
3933
|
+
"body"
|
|
3934
|
+
]);
|
|
3935
|
+
// 构建请求配置
|
|
3936
|
+
const finalOptions = _extends({
|
|
3937
|
+
method: options.method || 'GET',
|
|
3938
|
+
headers: _extends({
|
|
3939
|
+
'Accept': 'text/event-stream',
|
|
3940
|
+
'Cache-Control': 'no-cache',
|
|
3941
|
+
'Connection': 'keep-alive'
|
|
3942
|
+
}, options.headers),
|
|
3943
|
+
signal: abortController.current.signal,
|
|
3944
|
+
credentials: withCredentials ? 'include' : 'same-origin'
|
|
3945
|
+
}, fetchOptions);
|
|
3946
|
+
// 只在 POST 请求时添加 body
|
|
3947
|
+
if (options.method === 'POST' && body) {
|
|
3948
|
+
finalOptions.body = body;
|
|
3949
|
+
finalOptions.headers = _extends({}, finalOptions.headers, {
|
|
3950
|
+
'Content-Type': 'application/json'
|
|
3951
|
+
});
|
|
3952
|
+
}
|
|
3953
|
+
yield fetchEventSource.fetchEventSource(url.toString(), _extends({}, finalOptions, {
|
|
3954
|
+
onopen (response) {
|
|
3955
|
+
return _async_to_generator(function*() {
|
|
3956
|
+
if (response.ok) {
|
|
3957
|
+
setStatus('CONNECTED');
|
|
3958
|
+
setError(null);
|
|
3959
|
+
options.onOpen == null ? void 0 : options.onOpen.call(options);
|
|
3960
|
+
} else {
|
|
3961
|
+
const error = new Error(`Failed to connect: ${response.status} ${response.statusText}`);
|
|
3962
|
+
setError(error);
|
|
3963
|
+
throw error;
|
|
3964
|
+
}
|
|
3965
|
+
})();
|
|
3966
|
+
},
|
|
3967
|
+
onmessage (msg) {
|
|
3968
|
+
if (!explicitlyClosed.current) {
|
|
3969
|
+
setData(msg.data);
|
|
3970
|
+
var _msg_id;
|
|
3971
|
+
setLastEventId((_msg_id = msg.id) != null ? _msg_id : null);
|
|
3972
|
+
setEvent(msg.event || null);
|
|
3973
|
+
options.onMessage == null ? void 0 : options.onMessage.call(options, msg);
|
|
3974
|
+
}
|
|
3975
|
+
},
|
|
3976
|
+
onerror (err) {
|
|
3977
|
+
setError(err);
|
|
3978
|
+
setStatus('DISCONNECTED');
|
|
3979
|
+
const retryDelay = options.onError == null ? void 0 : options.onError.call(options, err);
|
|
3980
|
+
if (options.autoReconnect && !explicitlyClosed.current) {
|
|
3981
|
+
const { retries: maxRetries = -1, delay = 1000, onFailed } = options.autoReconnect;
|
|
3982
|
+
retries.current += 1;
|
|
3983
|
+
if (typeof maxRetries === 'number' && (maxRetries < 0 || retries.current < maxRetries) || typeof maxRetries === 'function' && maxRetries()) {
|
|
3984
|
+
return retryDelay != null ? retryDelay : delay;
|
|
3985
|
+
} else {
|
|
3986
|
+
onFailed == null ? void 0 : onFailed();
|
|
3987
|
+
throw err;
|
|
3988
|
+
}
|
|
3989
|
+
}
|
|
3990
|
+
throw err;
|
|
3991
|
+
},
|
|
3992
|
+
onclose () {
|
|
3993
|
+
if (!explicitlyClosed.current) {
|
|
3994
|
+
setStatus('DISCONNECTED');
|
|
3995
|
+
options.onClose == null ? void 0 : options.onClose.call(options);
|
|
3955
3996
|
}
|
|
3956
|
-
})();
|
|
3957
|
-
},
|
|
3958
|
-
onmessage (msg) {
|
|
3959
|
-
if (!explicitlyClosed.current) {
|
|
3960
|
-
setData(msg.data);
|
|
3961
|
-
var _msg_id;
|
|
3962
|
-
setLastEventId((_msg_id = msg.id) != null ? _msg_id : null);
|
|
3963
|
-
setEvent(msg.event || null);
|
|
3964
|
-
options.onMessage == null ? void 0 : options.onMessage.call(options, msg);
|
|
3965
3997
|
}
|
|
3966
|
-
}
|
|
3967
|
-
|
|
3998
|
+
}));
|
|
3999
|
+
} catch (err) {
|
|
4000
|
+
// 只处理非主动关闭导致的错误
|
|
4001
|
+
if (!explicitlyClosed.current) {
|
|
4002
|
+
console.error('EventSource Error:', err);
|
|
3968
4003
|
setError(err);
|
|
3969
4004
|
setStatus('DISCONNECTED');
|
|
3970
|
-
const retryDelay = options.onError == null ? void 0 : options.onError.call(options, err);
|
|
3971
|
-
if (options.autoReconnect && !explicitlyClosed.current) {
|
|
3972
|
-
const { retries: maxRetries = -1, delay = 1000, onFailed } = options.autoReconnect;
|
|
3973
|
-
retries.current += 1;
|
|
3974
|
-
if (typeof maxRetries === 'number' && (maxRetries < 0 || retries.current < maxRetries) || typeof maxRetries === 'function' && maxRetries()) {
|
|
3975
|
-
return retryDelay != null ? retryDelay : delay;
|
|
3976
|
-
} else {
|
|
3977
|
-
onFailed == null ? void 0 : onFailed();
|
|
3978
|
-
throw err;
|
|
3979
|
-
}
|
|
3980
|
-
}
|
|
3981
|
-
throw err;
|
|
3982
|
-
},
|
|
3983
|
-
onclose () {
|
|
3984
|
-
if (!explicitlyClosed.current) {
|
|
3985
|
-
setStatus('DISCONNECTED');
|
|
3986
|
-
options.onClose == null ? void 0 : options.onClose.call(options);
|
|
3987
|
-
}
|
|
3988
4005
|
}
|
|
3989
|
-
}));
|
|
3990
|
-
} catch (err) {
|
|
3991
|
-
// 只处理非主动关闭导致的错误
|
|
3992
|
-
if (!explicitlyClosed.current) {
|
|
3993
|
-
console.error('EventSource Error:', err);
|
|
3994
|
-
setError(err);
|
|
3995
|
-
setStatus('DISCONNECTED');
|
|
3996
4006
|
}
|
|
3997
|
-
}
|
|
3998
|
-
}));
|
|
4007
|
+
})());
|
|
3999
4008
|
React.useEffect(()=>{
|
|
4000
4009
|
if (options.immediate !== false) {
|
|
4001
4010
|
open();
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import react__default, { DependencyList, MutableRefObject, EffectCallback, Dispatch, SetStateAction,
|
|
2
|
+
import react__default, { DependencyList, MutableRefObject, EffectCallback, RefObject, Dispatch, SetStateAction, useEffect, useLayoutEffect, Ref, Context } from 'react';
|
|
3
3
|
import Cookies from 'js-cookie';
|
|
4
4
|
import { DebounceSettings, ThrottleSettings, DebouncedFunc as DebouncedFunc$1 } from 'lodash-es';
|
|
5
5
|
import * as lodash from 'lodash';
|
|
@@ -3596,4 +3596,5 @@ type Use = <T>(
|
|
|
3596
3596
|
*/
|
|
3597
3597
|
usable: Usable<T>) => T;
|
|
3598
3598
|
|
|
3599
|
-
export {
|
|
3599
|
+
export { assignRef, defaultOptions, mergeRefs, use, useActiveElement, useAsyncEffect, useBroadcastChannel, useClickOutside, useClipboard, useControlled, useCookie, useCountDown, useCounter, useCssVar, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDevicePixelRatio, useDisclosure, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementByPoint, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEventSource, useEyeDropper, useFavicon, useFetchEventSource, useFileDialog, useFirstMountState, useFocus, useFps, useFullscreen, useGeolocation, useHover, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLocationSelector, useLongPress, useMeasure, useMediaDevices, useMediaQuery, useMergedRefs, useMobileLandscape, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnceEffect, useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePlatform, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePreferredLanguages, usePrevious, useRafFn, useRafState, useReducedMotion, useResizeObserver, useScreenSafeArea, useScriptTag, useScroll, useScrollIntoView, useScrollLock, useSessionStorage, useSetState, useSticky, useSupported, useTextDirection, useTextSelection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, useUpdateEffect, useUpdateLayoutEffect, useWebNotification, useWindowScroll, useWindowSize, useWindowsFocus };
|
|
3600
|
+
export type { ColorScheme, Contrast, DepsEqualFnType, EventSourceStatus, EventType, INetworkInformation, IUseNetworkState, KeyModifier, Pausable, Platform, PossibleRef, Use, UseActiveElement, UseAsyncEffect, UseBroadcastChannel, UseBroadcastChannelOptions, UseBroadcastChannelReturn, UseClickOutside, UseClipboard, UseControlled, UseCookie, UseCookieState, UseCountDown, UseCounter, UseCssVar, UseCssVarOptions, UseCustomCompareEffect, UseCycleList, UseDarkMode, UseDarkOptions, UseDebounce, UseDebounceFn, UseDeepCompareEffect, UseDevicePixelRatio, UseDevicePixelRatioReturn, UseDisclosure, UseDisclosureProps, UseDocumentVisibility, UseDoubleClick, UseDoubleClickProps, UseDraggable, UseDraggableOptions, UseDropZone, UseElementBounding, UseElementBoundingOptions, UseElementBoundingReturn, UseElementByPoint, UseElementByPointOptions, UseElementByPointReturn, UseElementSize, UseElementVisibility, UseEvent, UseEventEmitter, UseEventEmitterDisposable, UseEventEmitterEvent, UseEventEmitterEventOnce, UseEventEmitterListener, UseEventEmitterReturn, UseEventListener, UseEventSource, UseEventSourceAutoReconnectOptions, UseEventSourceOptions, UseEventSourceReturn, UseEyeDropper, UseEyeDropperOpenOptions, UseEyeDropperOpenReturnType, UseFavicon, UseFetchEventSource, UseFetchEventSourceAutoReconnectOptions, UseFetchEventSourceMessage, UseFetchEventSourceOptions, UseFetchEventSourceReturn, UseFetchEventSourceStatus, UseFileDialog, UseFileDialogOptions, UseFirstMountState, UseFocus, UseFps, UseFpsOptions, UseFullScreenOptions, UseFullscreen, UseGeolocation, UseHover, UseIdle, UseInfiniteScroll, UseInfiniteScrollArrivedState, UseInfiniteScrollDirection, UseInfiniteScrollLoadMore, UseInfiniteScrollOptions, UseIntersectionObserver, UseInterval, UseIntervalOptions, UseKeyModifier, UseLatest, UseLocalStorage, UseLocalStorageOptions, UseLocalStorageSerializer, UseLocationSelector, UseLongPress, UseLongPressOptions, UseMeasure, UseMeasureRect, UseMediaDeviceOptions, UseMediaDevices, UseMediaQuery, UseMergedRef, UseMobileLandscape, UseModifierOptions, UseMount, UseMountedState, UseMouse, UseMouseCursorState, UseMousePressed, UseMousePressedOptions, UseMousePressedSourceType, UseMutationObserver, UseNetwork, UseObjectUrl, UseOnline, UseOrientation, UseOrientationLockType, UseOrientationState, UseOrientationType, UsePageLeave, UsePermission, UsePermissionDescriptorNamePolyfill, UsePermissionGeneralPermissionDescriptor, UsePermissionState, UsePlatform, UsePlatformProps, UsePlatformReturn, UsePreferredColorScheme, UsePreferredContrast, UsePreferredDark, UsePreferredLanguages, UsePrevious, UseRafFn, UseRafState, UseReducedMotion, UseResizeObserver, UseScreenSafeArea, UseScriptTag, UseScriptTagOptions, UseScriptTagStatus, UseScroll, UseScrollArrivedState, UseScrollDirection, UseScrollIntoView, UseScrollIntoViewAnimation, UseScrollIntoViewParams, UseScrollLock, UseScrollOffset, UseScrollOptions, UseSessionStorage, UseSessionStorageOptions, UseSessionStorageSerializer, UseSetState, UseSticky, UseStickyParams, UseSupported, UseTextDirection, UseTextDirectionOptions, UseTextDirectionValue, UseTextSelection, UseThrottle, UseThrottleFn, UseTimeout, UseTimeoutFn, UseTimeoutFnOptions, UseTimeoutOptions, UseTitle, UseToggle, UseUnmount, UseUpdate, UseWebNotification, UseWebNotificationReturn, UseWebNotificationShow, UseWindowScroll, UseWindowScrollState, UseWindowSize, UseWindowsFocus };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import react__default, { DependencyList, MutableRefObject, EffectCallback, Dispatch, SetStateAction,
|
|
2
|
+
import react__default, { DependencyList, MutableRefObject, EffectCallback, RefObject, Dispatch, SetStateAction, useEffect, useLayoutEffect, Ref, Context } from 'react';
|
|
3
3
|
import Cookies from 'js-cookie';
|
|
4
4
|
import { DebounceSettings, ThrottleSettings, DebouncedFunc as DebouncedFunc$1 } from 'lodash-es';
|
|
5
5
|
import * as lodash from 'lodash';
|
|
@@ -3596,4 +3596,5 @@ type Use = <T>(
|
|
|
3596
3596
|
*/
|
|
3597
3597
|
usable: Usable<T>) => T;
|
|
3598
3598
|
|
|
3599
|
-
export {
|
|
3599
|
+
export { assignRef, defaultOptions, mergeRefs, use, useActiveElement, useAsyncEffect, useBroadcastChannel, useClickOutside, useClipboard, useControlled, useCookie, useCountDown, useCounter, useCssVar, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDevicePixelRatio, useDisclosure, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementByPoint, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEventSource, useEyeDropper, useFavicon, useFetchEventSource, useFileDialog, useFirstMountState, useFocus, useFps, useFullscreen, useGeolocation, useHover, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLocationSelector, useLongPress, useMeasure, useMediaDevices, useMediaQuery, useMergedRefs, useMobileLandscape, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnceEffect, useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePlatform, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePreferredLanguages, usePrevious, useRafFn, useRafState, useReducedMotion, useResizeObserver, useScreenSafeArea, useScriptTag, useScroll, useScrollIntoView, useScrollLock, useSessionStorage, useSetState, useSticky, useSupported, useTextDirection, useTextSelection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, useUpdateEffect, useUpdateLayoutEffect, useWebNotification, useWindowScroll, useWindowSize, useWindowsFocus };
|
|
3600
|
+
export type { ColorScheme, Contrast, DepsEqualFnType, EventSourceStatus, EventType, INetworkInformation, IUseNetworkState, KeyModifier, Pausable, Platform, PossibleRef, Use, UseActiveElement, UseAsyncEffect, UseBroadcastChannel, UseBroadcastChannelOptions, UseBroadcastChannelReturn, UseClickOutside, UseClipboard, UseControlled, UseCookie, UseCookieState, UseCountDown, UseCounter, UseCssVar, UseCssVarOptions, UseCustomCompareEffect, UseCycleList, UseDarkMode, UseDarkOptions, UseDebounce, UseDebounceFn, UseDeepCompareEffect, UseDevicePixelRatio, UseDevicePixelRatioReturn, UseDisclosure, UseDisclosureProps, UseDocumentVisibility, UseDoubleClick, UseDoubleClickProps, UseDraggable, UseDraggableOptions, UseDropZone, UseElementBounding, UseElementBoundingOptions, UseElementBoundingReturn, UseElementByPoint, UseElementByPointOptions, UseElementByPointReturn, UseElementSize, UseElementVisibility, UseEvent, UseEventEmitter, UseEventEmitterDisposable, UseEventEmitterEvent, UseEventEmitterEventOnce, UseEventEmitterListener, UseEventEmitterReturn, UseEventListener, UseEventSource, UseEventSourceAutoReconnectOptions, UseEventSourceOptions, UseEventSourceReturn, UseEyeDropper, UseEyeDropperOpenOptions, UseEyeDropperOpenReturnType, UseFavicon, UseFetchEventSource, UseFetchEventSourceAutoReconnectOptions, UseFetchEventSourceMessage, UseFetchEventSourceOptions, UseFetchEventSourceReturn, UseFetchEventSourceStatus, UseFileDialog, UseFileDialogOptions, UseFirstMountState, UseFocus, UseFps, UseFpsOptions, UseFullScreenOptions, UseFullscreen, UseGeolocation, UseHover, UseIdle, UseInfiniteScroll, UseInfiniteScrollArrivedState, UseInfiniteScrollDirection, UseInfiniteScrollLoadMore, UseInfiniteScrollOptions, UseIntersectionObserver, UseInterval, UseIntervalOptions, UseKeyModifier, UseLatest, UseLocalStorage, UseLocalStorageOptions, UseLocalStorageSerializer, UseLocationSelector, UseLongPress, UseLongPressOptions, UseMeasure, UseMeasureRect, UseMediaDeviceOptions, UseMediaDevices, UseMediaQuery, UseMergedRef, UseMobileLandscape, UseModifierOptions, UseMount, UseMountedState, UseMouse, UseMouseCursorState, UseMousePressed, UseMousePressedOptions, UseMousePressedSourceType, UseMutationObserver, UseNetwork, UseObjectUrl, UseOnline, UseOrientation, UseOrientationLockType, UseOrientationState, UseOrientationType, UsePageLeave, UsePermission, UsePermissionDescriptorNamePolyfill, UsePermissionGeneralPermissionDescriptor, UsePermissionState, UsePlatform, UsePlatformProps, UsePlatformReturn, UsePreferredColorScheme, UsePreferredContrast, UsePreferredDark, UsePreferredLanguages, UsePrevious, UseRafFn, UseRafState, UseReducedMotion, UseResizeObserver, UseScreenSafeArea, UseScriptTag, UseScriptTagOptions, UseScriptTagStatus, UseScroll, UseScrollArrivedState, UseScrollDirection, UseScrollIntoView, UseScrollIntoViewAnimation, UseScrollIntoViewParams, UseScrollLock, UseScrollOffset, UseScrollOptions, UseSessionStorage, UseSessionStorageOptions, UseSessionStorageSerializer, UseSetState, UseSticky, UseStickyParams, UseSupported, UseTextDirection, UseTextDirectionOptions, UseTextDirectionValue, UseTextSelection, UseThrottle, UseThrottleFn, UseTimeout, UseTimeoutFn, UseTimeoutFnOptions, UseTimeoutOptions, UseTitle, UseToggle, UseUnmount, UseUpdate, UseWebNotification, UseWebNotificationReturn, UseWebNotificationShow, UseWindowScroll, UseWindowScrollState, UseWindowSize, UseWindowsFocus };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import react__default, { DependencyList, MutableRefObject, EffectCallback, Dispatch, SetStateAction,
|
|
2
|
+
import react__default, { DependencyList, MutableRefObject, EffectCallback, RefObject, Dispatch, SetStateAction, useEffect, useLayoutEffect, Ref, Context } from 'react';
|
|
3
3
|
import Cookies from 'js-cookie';
|
|
4
4
|
import { DebounceSettings, ThrottleSettings, DebouncedFunc as DebouncedFunc$1 } from 'lodash-es';
|
|
5
5
|
import * as lodash from 'lodash';
|
|
@@ -3596,4 +3596,5 @@ type Use = <T>(
|
|
|
3596
3596
|
*/
|
|
3597
3597
|
usable: Usable<T>) => T;
|
|
3598
3598
|
|
|
3599
|
-
export {
|
|
3599
|
+
export { assignRef, defaultOptions, mergeRefs, use, useActiveElement, useAsyncEffect, useBroadcastChannel, useClickOutside, useClipboard, useControlled, useCookie, useCountDown, useCounter, useCssVar, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDevicePixelRatio, useDisclosure, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementByPoint, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEventSource, useEyeDropper, useFavicon, useFetchEventSource, useFileDialog, useFirstMountState, useFocus, useFps, useFullscreen, useGeolocation, useHover, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLocationSelector, useLongPress, useMeasure, useMediaDevices, useMediaQuery, useMergedRefs, useMobileLandscape, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnceEffect, useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePlatform, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePreferredLanguages, usePrevious, useRafFn, useRafState, useReducedMotion, useResizeObserver, useScreenSafeArea, useScriptTag, useScroll, useScrollIntoView, useScrollLock, useSessionStorage, useSetState, useSticky, useSupported, useTextDirection, useTextSelection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, useUpdateEffect, useUpdateLayoutEffect, useWebNotification, useWindowScroll, useWindowSize, useWindowsFocus };
|
|
3600
|
+
export type { ColorScheme, Contrast, DepsEqualFnType, EventSourceStatus, EventType, INetworkInformation, IUseNetworkState, KeyModifier, Pausable, Platform, PossibleRef, Use, UseActiveElement, UseAsyncEffect, UseBroadcastChannel, UseBroadcastChannelOptions, UseBroadcastChannelReturn, UseClickOutside, UseClipboard, UseControlled, UseCookie, UseCookieState, UseCountDown, UseCounter, UseCssVar, UseCssVarOptions, UseCustomCompareEffect, UseCycleList, UseDarkMode, UseDarkOptions, UseDebounce, UseDebounceFn, UseDeepCompareEffect, UseDevicePixelRatio, UseDevicePixelRatioReturn, UseDisclosure, UseDisclosureProps, UseDocumentVisibility, UseDoubleClick, UseDoubleClickProps, UseDraggable, UseDraggableOptions, UseDropZone, UseElementBounding, UseElementBoundingOptions, UseElementBoundingReturn, UseElementByPoint, UseElementByPointOptions, UseElementByPointReturn, UseElementSize, UseElementVisibility, UseEvent, UseEventEmitter, UseEventEmitterDisposable, UseEventEmitterEvent, UseEventEmitterEventOnce, UseEventEmitterListener, UseEventEmitterReturn, UseEventListener, UseEventSource, UseEventSourceAutoReconnectOptions, UseEventSourceOptions, UseEventSourceReturn, UseEyeDropper, UseEyeDropperOpenOptions, UseEyeDropperOpenReturnType, UseFavicon, UseFetchEventSource, UseFetchEventSourceAutoReconnectOptions, UseFetchEventSourceMessage, UseFetchEventSourceOptions, UseFetchEventSourceReturn, UseFetchEventSourceStatus, UseFileDialog, UseFileDialogOptions, UseFirstMountState, UseFocus, UseFps, UseFpsOptions, UseFullScreenOptions, UseFullscreen, UseGeolocation, UseHover, UseIdle, UseInfiniteScroll, UseInfiniteScrollArrivedState, UseInfiniteScrollDirection, UseInfiniteScrollLoadMore, UseInfiniteScrollOptions, UseIntersectionObserver, UseInterval, UseIntervalOptions, UseKeyModifier, UseLatest, UseLocalStorage, UseLocalStorageOptions, UseLocalStorageSerializer, UseLocationSelector, UseLongPress, UseLongPressOptions, UseMeasure, UseMeasureRect, UseMediaDeviceOptions, UseMediaDevices, UseMediaQuery, UseMergedRef, UseMobileLandscape, UseModifierOptions, UseMount, UseMountedState, UseMouse, UseMouseCursorState, UseMousePressed, UseMousePressedOptions, UseMousePressedSourceType, UseMutationObserver, UseNetwork, UseObjectUrl, UseOnline, UseOrientation, UseOrientationLockType, UseOrientationState, UseOrientationType, UsePageLeave, UsePermission, UsePermissionDescriptorNamePolyfill, UsePermissionGeneralPermissionDescriptor, UsePermissionState, UsePlatform, UsePlatformProps, UsePlatformReturn, UsePreferredColorScheme, UsePreferredContrast, UsePreferredDark, UsePreferredLanguages, UsePrevious, UseRafFn, UseRafState, UseReducedMotion, UseResizeObserver, UseScreenSafeArea, UseScriptTag, UseScriptTagOptions, UseScriptTagStatus, UseScroll, UseScrollArrivedState, UseScrollDirection, UseScrollIntoView, UseScrollIntoViewAnimation, UseScrollIntoViewParams, UseScrollLock, UseScrollOffset, UseScrollOptions, UseSessionStorage, UseSessionStorageOptions, UseSessionStorageSerializer, UseSetState, UseSticky, UseStickyParams, UseSupported, UseTextDirection, UseTextDirectionOptions, UseTextDirectionValue, UseTextSelection, UseThrottle, UseThrottleFn, UseTimeout, UseTimeoutFn, UseTimeoutFnOptions, UseTimeoutOptions, UseTitle, UseToggle, UseUnmount, UseUpdate, UseWebNotification, UseWebNotificationReturn, UseWebNotificationShow, UseWindowScroll, UseWindowScrollState, UseWindowSize, UseWindowsFocus };
|
package/dist/index.mjs
CHANGED
|
@@ -198,12 +198,12 @@ function _async_to_generator$7(fn) {
|
|
|
198
198
|
const useAsyncEffect = (effect, cleanup = noop, deps)=>{
|
|
199
199
|
const mounted = useMountedState();
|
|
200
200
|
useEffect(()=>{
|
|
201
|
-
const execute =
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
201
|
+
const execute = ()=>_async_to_generator$7(function*() {
|
|
202
|
+
if (!mounted()) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
yield effect();
|
|
206
|
+
})();
|
|
207
207
|
execute();
|
|
208
208
|
return ()=>{
|
|
209
209
|
cleanup();
|
|
@@ -1246,15 +1246,15 @@ function _async_to_generator$6(fn) {
|
|
|
1246
1246
|
}
|
|
1247
1247
|
const useEyeDropper = ()=>{
|
|
1248
1248
|
const isSupported = useSupported(()=>typeof window !== 'undefined' && 'EyeDropper' in window, true);
|
|
1249
|
-
const open = useCallback(
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1249
|
+
const open = useCallback((options = {})=>_async_to_generator$6(function*() {
|
|
1250
|
+
if (!isSupported) {
|
|
1251
|
+
return {
|
|
1252
|
+
sRGBHex: ''
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
const eyeDropper = new window.EyeDropper();
|
|
1256
|
+
return eyeDropper.open(options);
|
|
1257
|
+
})(), [
|
|
1258
1258
|
isSupported
|
|
1259
1259
|
]);
|
|
1260
1260
|
return [
|
|
@@ -1347,20 +1347,20 @@ const useFileDialog = (options = defaultOptions$1)=>{
|
|
|
1347
1347
|
return input;
|
|
1348
1348
|
}, []);
|
|
1349
1349
|
inputRef.current = initFn();
|
|
1350
|
-
const open =
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1350
|
+
const open = (localOptions)=>_async_to_generator$5(function*() {
|
|
1351
|
+
if (!inputRef.current) {
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1354
|
+
const _options = _extends$3({}, DEFAULT_OPTIONS, options, localOptions);
|
|
1355
|
+
inputRef.current.multiple = _options.multiple;
|
|
1356
|
+
inputRef.current.accept = _options.accept;
|
|
1357
|
+
inputRef.current.capture = _options.capture;
|
|
1358
|
+
fileOpenPromiseRef.current = new Promise((resolve)=>{
|
|
1359
|
+
resolveFileOpenPromiseRef.current = resolve;
|
|
1360
|
+
});
|
|
1361
|
+
inputRef.current.click();
|
|
1362
|
+
return fileOpenPromiseRef.current;
|
|
1363
|
+
})();
|
|
1364
1364
|
const reset = ()=>{
|
|
1365
1365
|
setFiles(null);
|
|
1366
1366
|
resolveFileOpenPromiseRef.current == null ? void 0 : resolveFileOpenPromiseRef.current.call(resolveFileOpenPromiseRef, null);
|
|
@@ -1813,20 +1813,20 @@ const useInfiniteScroll = (target, onLoadMore, options = defaultOptions$1)=>{
|
|
|
1813
1813
|
const di = state[3][direction];
|
|
1814
1814
|
useUpdateEffect(()=>{
|
|
1815
1815
|
const element = getTargetElement(target);
|
|
1816
|
-
const fn =
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1816
|
+
const fn = ()=>_async_to_generator$4(function*() {
|
|
1817
|
+
var _element_scrollHeight, _element_scrollWidth;
|
|
1818
|
+
const previous = {
|
|
1819
|
+
height: (_element_scrollHeight = element == null ? void 0 : element.scrollHeight) != null ? _element_scrollHeight : 0,
|
|
1820
|
+
width: (_element_scrollWidth = element == null ? void 0 : element.scrollWidth) != null ? _element_scrollWidth : 0
|
|
1821
|
+
};
|
|
1822
|
+
yield savedLoadMore.current(state);
|
|
1823
|
+
if (options.preserveScrollPosition && element) {
|
|
1824
|
+
element.scrollTo({
|
|
1825
|
+
top: element.scrollHeight - previous.height,
|
|
1826
|
+
left: element.scrollWidth - previous.width
|
|
1827
|
+
});
|
|
1828
|
+
}
|
|
1829
|
+
})();
|
|
1830
1830
|
fn();
|
|
1831
1831
|
}, [
|
|
1832
1832
|
di,
|
|
@@ -2020,30 +2020,30 @@ const useMediaDevices = (options = {})=>{
|
|
|
2020
2020
|
});
|
|
2021
2021
|
}).catch(noop);
|
|
2022
2022
|
}, []);
|
|
2023
|
-
const ensurePermissions = useCallback(
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2023
|
+
const ensurePermissions = useCallback(()=>_async_to_generator$3(function*() {
|
|
2024
|
+
if (!isSupported) {
|
|
2025
|
+
return false;
|
|
2026
|
+
}
|
|
2027
|
+
if (permissionGranted.current) {
|
|
2028
|
+
return true;
|
|
2029
|
+
}
|
|
2030
|
+
let state;
|
|
2031
|
+
try {
|
|
2032
|
+
state = (yield navigator.permissions.query({
|
|
2033
|
+
name: 'camera'
|
|
2034
|
+
})).state;
|
|
2035
|
+
} catch (error) {
|
|
2036
|
+
state = 'prompt';
|
|
2037
|
+
}
|
|
2038
|
+
if (state !== 'granted') {
|
|
2039
|
+
stream.current = yield navigator.mediaDevices.getUserMedia(constraints);
|
|
2040
|
+
onChange();
|
|
2041
|
+
permissionGranted.current = true;
|
|
2042
|
+
} else {
|
|
2043
|
+
permissionGranted.current = false;
|
|
2044
|
+
}
|
|
2045
|
+
return permissionGranted.current;
|
|
2046
|
+
})(), [
|
|
2047
2047
|
onChange,
|
|
2048
2048
|
isSupported,
|
|
2049
2049
|
constraints
|
|
@@ -2837,15 +2837,24 @@ const useScrollIntoView = (targetElement, { duration = 1250, axis = 'y', onScrol
|
|
|
2837
2837
|
};
|
|
2838
2838
|
};
|
|
2839
2839
|
|
|
2840
|
+
function checkOverflowScroll(ele) {
|
|
2841
|
+
const style = window.getComputedStyle(ele);
|
|
2842
|
+
if (style.overflowX === 'scroll' || style.overflowY === 'scroll' || style.overflowX === 'auto' && ele.clientWidth < ele.scrollWidth || style.overflowY === 'auto' && ele.clientHeight < ele.scrollHeight) {
|
|
2843
|
+
return true;
|
|
2844
|
+
} else {
|
|
2845
|
+
const parent = ele.parentNode;
|
|
2846
|
+
if (!parent || parent.tagName === 'BODY') return false;
|
|
2847
|
+
return checkOverflowScroll(parent);
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2840
2850
|
function preventDefault(rawEvent) {
|
|
2841
2851
|
const e = rawEvent || window.event;
|
|
2852
|
+
const _target = e.target;
|
|
2853
|
+
// Do not prevent if element or parentNodes have overflow: scroll set.
|
|
2854
|
+
if (checkOverflowScroll(_target)) return false;
|
|
2842
2855
|
// Do not prevent if the event has more than one touch (usually meaning this is a multi touch gesture like pinch to zoom).
|
|
2843
|
-
if (e.touches.length > 1)
|
|
2844
|
-
|
|
2845
|
-
}
|
|
2846
|
-
if (e.preventDefault) {
|
|
2847
|
-
e.preventDefault();
|
|
2848
|
-
}
|
|
2856
|
+
if (e.touches.length > 1) return true;
|
|
2857
|
+
if (e.preventDefault) e.preventDefault();
|
|
2849
2858
|
return false;
|
|
2850
2859
|
}
|
|
2851
2860
|
const useScrollLock = (target, initialState = false)=>{
|
|
@@ -3158,14 +3167,14 @@ const useWebNotification = (requestPermissions = false)=>{
|
|
|
3158
3167
|
}, [
|
|
3159
3168
|
isSupported
|
|
3160
3169
|
]);
|
|
3161
|
-
const ensurePermissions = useCallback(
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3170
|
+
const ensurePermissions = useCallback(()=>_async_to_generator$2(function*() {
|
|
3171
|
+
if (!isSupported) return;
|
|
3172
|
+
if (!permissionGranted.current && Notification.permission !== 'denied') {
|
|
3173
|
+
const result = yield Notification.requestPermission();
|
|
3174
|
+
if (result === 'granted') permissionGranted.current = true;
|
|
3175
|
+
}
|
|
3176
|
+
return permissionGranted.current;
|
|
3177
|
+
})(), [
|
|
3169
3178
|
isSupported
|
|
3170
3179
|
]);
|
|
3171
3180
|
useEffect(()=>{
|
|
@@ -3300,33 +3309,33 @@ function _async_to_generator$1(fn) {
|
|
|
3300
3309
|
}
|
|
3301
3310
|
const useClipboard = ()=>{
|
|
3302
3311
|
const [text, setText] = useState('');
|
|
3303
|
-
const updateText = useCallback(
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3312
|
+
const updateText = useCallback(()=>_async_to_generator$1(function*() {
|
|
3313
|
+
// Check if document is focused before attempting to read clipboard
|
|
3314
|
+
if (!document.hasFocus()) {
|
|
3315
|
+
return;
|
|
3316
|
+
}
|
|
3317
|
+
try {
|
|
3318
|
+
const value = yield window.navigator.clipboard.readText();
|
|
3319
|
+
setText(value);
|
|
3320
|
+
} catch (error) {
|
|
3321
|
+
// Handle cases where clipboard access is denied or unavailable
|
|
3322
|
+
console.warn('Failed to read clipboard:', error);
|
|
3323
|
+
}
|
|
3324
|
+
})(), []);
|
|
3316
3325
|
useEventListener('copy', updateText);
|
|
3317
3326
|
useEventListener('cut', updateText);
|
|
3318
3327
|
// Also listen for focus events to update clipboard when window regains focus
|
|
3319
3328
|
useEventListener('focus', updateText, window);
|
|
3320
|
-
const copy = useCallback(
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3329
|
+
const copy = useCallback((txt)=>_async_to_generator$1(function*() {
|
|
3330
|
+
setText(txt);
|
|
3331
|
+
try {
|
|
3332
|
+
yield window.navigator.clipboard.writeText(txt);
|
|
3333
|
+
} catch (error) {
|
|
3334
|
+
console.warn('Failed to write to clipboard:', error);
|
|
3335
|
+
throw error // Re-throw so caller can handle it
|
|
3336
|
+
;
|
|
3337
|
+
}
|
|
3338
|
+
})(), []);
|
|
3330
3339
|
useEffect(()=>{
|
|
3331
3340
|
updateText();
|
|
3332
3341
|
}, [
|
|
@@ -3896,98 +3905,98 @@ const useFetchEventSource = (url, options = {})=>{
|
|
|
3896
3905
|
options.onClose == null ? void 0 : options.onClose.call(options);
|
|
3897
3906
|
}
|
|
3898
3907
|
});
|
|
3899
|
-
const open = useEvent(
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3908
|
+
const open = useEvent(()=>_async_to_generator(function*() {
|
|
3909
|
+
close();
|
|
3910
|
+
setStatus('CONNECTING');
|
|
3911
|
+
explicitlyClosed.current = false;
|
|
3912
|
+
retries.current = 0;
|
|
3913
|
+
// 创建新的 AbortController
|
|
3914
|
+
abortController.current = new AbortController();
|
|
3915
|
+
try {
|
|
3916
|
+
// 从选项中提取 FetchEventSourceInit 相关的选项
|
|
3917
|
+
const { immediate, autoReconnect, onOpen, onMessage, onError, onClose, withCredentials, body } = options, fetchOptions = _object_without_properties_loose(options, [
|
|
3918
|
+
"immediate",
|
|
3919
|
+
"autoReconnect",
|
|
3920
|
+
"onOpen",
|
|
3921
|
+
"onMessage",
|
|
3922
|
+
"onError",
|
|
3923
|
+
"onClose",
|
|
3924
|
+
"withCredentials",
|
|
3925
|
+
"body"
|
|
3926
|
+
]);
|
|
3927
|
+
// 构建请求配置
|
|
3928
|
+
const finalOptions = _extends({
|
|
3929
|
+
method: options.method || 'GET',
|
|
3930
|
+
headers: _extends({
|
|
3931
|
+
'Accept': 'text/event-stream',
|
|
3932
|
+
'Cache-Control': 'no-cache',
|
|
3933
|
+
'Connection': 'keep-alive'
|
|
3934
|
+
}, options.headers),
|
|
3935
|
+
signal: abortController.current.signal,
|
|
3936
|
+
credentials: withCredentials ? 'include' : 'same-origin'
|
|
3937
|
+
}, fetchOptions);
|
|
3938
|
+
// 只在 POST 请求时添加 body
|
|
3939
|
+
if (options.method === 'POST' && body) {
|
|
3940
|
+
finalOptions.body = body;
|
|
3941
|
+
finalOptions.headers = _extends({}, finalOptions.headers, {
|
|
3942
|
+
'Content-Type': 'application/json'
|
|
3943
|
+
});
|
|
3944
|
+
}
|
|
3945
|
+
yield fetchEventSource(url.toString(), _extends({}, finalOptions, {
|
|
3946
|
+
onopen (response) {
|
|
3947
|
+
return _async_to_generator(function*() {
|
|
3948
|
+
if (response.ok) {
|
|
3949
|
+
setStatus('CONNECTED');
|
|
3950
|
+
setError(null);
|
|
3951
|
+
options.onOpen == null ? void 0 : options.onOpen.call(options);
|
|
3952
|
+
} else {
|
|
3953
|
+
const error = new Error(`Failed to connect: ${response.status} ${response.statusText}`);
|
|
3954
|
+
setError(error);
|
|
3955
|
+
throw error;
|
|
3956
|
+
}
|
|
3957
|
+
})();
|
|
3958
|
+
},
|
|
3959
|
+
onmessage (msg) {
|
|
3960
|
+
if (!explicitlyClosed.current) {
|
|
3961
|
+
setData(msg.data);
|
|
3962
|
+
var _msg_id;
|
|
3963
|
+
setLastEventId((_msg_id = msg.id) != null ? _msg_id : null);
|
|
3964
|
+
setEvent(msg.event || null);
|
|
3965
|
+
options.onMessage == null ? void 0 : options.onMessage.call(options, msg);
|
|
3966
|
+
}
|
|
3967
|
+
},
|
|
3968
|
+
onerror (err) {
|
|
3969
|
+
setError(err);
|
|
3970
|
+
setStatus('DISCONNECTED');
|
|
3971
|
+
const retryDelay = options.onError == null ? void 0 : options.onError.call(options, err);
|
|
3972
|
+
if (options.autoReconnect && !explicitlyClosed.current) {
|
|
3973
|
+
const { retries: maxRetries = -1, delay = 1000, onFailed } = options.autoReconnect;
|
|
3974
|
+
retries.current += 1;
|
|
3975
|
+
if (typeof maxRetries === 'number' && (maxRetries < 0 || retries.current < maxRetries) || typeof maxRetries === 'function' && maxRetries()) {
|
|
3976
|
+
return retryDelay != null ? retryDelay : delay;
|
|
3977
|
+
} else {
|
|
3978
|
+
onFailed == null ? void 0 : onFailed();
|
|
3979
|
+
throw err;
|
|
3980
|
+
}
|
|
3981
|
+
}
|
|
3982
|
+
throw err;
|
|
3983
|
+
},
|
|
3984
|
+
onclose () {
|
|
3985
|
+
if (!explicitlyClosed.current) {
|
|
3986
|
+
setStatus('DISCONNECTED');
|
|
3987
|
+
options.onClose == null ? void 0 : options.onClose.call(options);
|
|
3947
3988
|
}
|
|
3948
|
-
})();
|
|
3949
|
-
},
|
|
3950
|
-
onmessage (msg) {
|
|
3951
|
-
if (!explicitlyClosed.current) {
|
|
3952
|
-
setData(msg.data);
|
|
3953
|
-
var _msg_id;
|
|
3954
|
-
setLastEventId((_msg_id = msg.id) != null ? _msg_id : null);
|
|
3955
|
-
setEvent(msg.event || null);
|
|
3956
|
-
options.onMessage == null ? void 0 : options.onMessage.call(options, msg);
|
|
3957
3989
|
}
|
|
3958
|
-
}
|
|
3959
|
-
|
|
3990
|
+
}));
|
|
3991
|
+
} catch (err) {
|
|
3992
|
+
// 只处理非主动关闭导致的错误
|
|
3993
|
+
if (!explicitlyClosed.current) {
|
|
3994
|
+
console.error('EventSource Error:', err);
|
|
3960
3995
|
setError(err);
|
|
3961
3996
|
setStatus('DISCONNECTED');
|
|
3962
|
-
const retryDelay = options.onError == null ? void 0 : options.onError.call(options, err);
|
|
3963
|
-
if (options.autoReconnect && !explicitlyClosed.current) {
|
|
3964
|
-
const { retries: maxRetries = -1, delay = 1000, onFailed } = options.autoReconnect;
|
|
3965
|
-
retries.current += 1;
|
|
3966
|
-
if (typeof maxRetries === 'number' && (maxRetries < 0 || retries.current < maxRetries) || typeof maxRetries === 'function' && maxRetries()) {
|
|
3967
|
-
return retryDelay != null ? retryDelay : delay;
|
|
3968
|
-
} else {
|
|
3969
|
-
onFailed == null ? void 0 : onFailed();
|
|
3970
|
-
throw err;
|
|
3971
|
-
}
|
|
3972
|
-
}
|
|
3973
|
-
throw err;
|
|
3974
|
-
},
|
|
3975
|
-
onclose () {
|
|
3976
|
-
if (!explicitlyClosed.current) {
|
|
3977
|
-
setStatus('DISCONNECTED');
|
|
3978
|
-
options.onClose == null ? void 0 : options.onClose.call(options);
|
|
3979
|
-
}
|
|
3980
3997
|
}
|
|
3981
|
-
}));
|
|
3982
|
-
} catch (err) {
|
|
3983
|
-
// 只处理非主动关闭导致的错误
|
|
3984
|
-
if (!explicitlyClosed.current) {
|
|
3985
|
-
console.error('EventSource Error:', err);
|
|
3986
|
-
setError(err);
|
|
3987
|
-
setStatus('DISCONNECTED');
|
|
3988
3998
|
}
|
|
3989
|
-
}
|
|
3990
|
-
}));
|
|
3999
|
+
})());
|
|
3991
4000
|
useEffect(()=>{
|
|
3992
4001
|
if (options.immediate !== false) {
|
|
3993
4002
|
open();
|
package/dist/useQRCode.cjs
CHANGED
|
@@ -90,14 +90,14 @@ const useQRCode = (text, options = defaultOptions)=>{
|
|
|
90
90
|
const [qrCode, setQRCode] = React.useState('');
|
|
91
91
|
const [error, setError] = React.useState(null);
|
|
92
92
|
useDeepCompareEffect(()=>{
|
|
93
|
-
const generate =
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
93
|
+
const generate = ()=>_async_to_generator(function*() {
|
|
94
|
+
try {
|
|
95
|
+
const qrCode = yield generateQRCode(text, options);
|
|
96
|
+
setQRCode(qrCode);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
setError(error);
|
|
99
|
+
}
|
|
100
|
+
})();
|
|
101
101
|
generate();
|
|
102
102
|
}, [
|
|
103
103
|
text,
|
package/dist/useQRCode.mjs
CHANGED
|
@@ -84,14 +84,14 @@ const useQRCode = (text, options = defaultOptions)=>{
|
|
|
84
84
|
const [qrCode, setQRCode] = useState('');
|
|
85
85
|
const [error, setError] = useState(null);
|
|
86
86
|
useDeepCompareEffect(()=>{
|
|
87
|
-
const generate =
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
const generate = ()=>_async_to_generator(function*() {
|
|
88
|
+
try {
|
|
89
|
+
const qrCode = yield generateQRCode(text, options);
|
|
90
|
+
setQRCode(qrCode);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
setError(error);
|
|
93
|
+
}
|
|
94
|
+
})();
|
|
95
95
|
generate();
|
|
96
96
|
}, [
|
|
97
97
|
text,
|