@reactuses/core 6.0.5 → 6.0.7

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 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
+ [![PDD](https://img.shields.io/badge/PDD-E_Commerce-orange?style=for-the-badge)](https://www.pinduoduo.com/)
70
+ [![Ctrip](https://img.shields.io/badge/Ctrip-Travel-blue?style=for-the-badge)](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 = /*#__PURE__*/ _async_to_generator$7(function*() {
210
- if (!mounted()) {
211
- return;
212
- }
213
- yield effect();
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(/*#__PURE__*/ _async_to_generator$6(function*(options = {}) {
1258
- if (!isSupported) {
1259
- return {
1260
- sRGBHex: ''
1261
- };
1262
- }
1263
- const eyeDropper = new window.EyeDropper();
1264
- return eyeDropper.open(options);
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,23 @@ const useFileDialog = (options = defaultOptions$1)=>{
1355
1355
  return input;
1356
1356
  }, []);
1357
1357
  inputRef.current = initFn();
1358
- const open = /*#__PURE__*/ _async_to_generator$5(function*(localOptions) {
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
- });
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
+ // Only set capture attribute if it's explicitly provided
1366
+ if (_options.capture !== undefined) {
1367
+ inputRef.current.capture = _options.capture;
1368
+ }
1369
+ fileOpenPromiseRef.current = new Promise((resolve)=>{
1370
+ resolveFileOpenPromiseRef.current = resolve;
1371
+ });
1372
+ inputRef.current.click();
1373
+ return fileOpenPromiseRef.current;
1374
+ })();
1372
1375
  const reset = ()=>{
1373
1376
  setFiles(null);
1374
1377
  resolveFileOpenPromiseRef.current == null ? void 0 : resolveFileOpenPromiseRef.current.call(resolveFileOpenPromiseRef, null);
@@ -1821,20 +1824,20 @@ const useInfiniteScroll = (target, onLoadMore, options = defaultOptions$1)=>{
1821
1824
  const di = state[3][direction];
1822
1825
  useUpdateEffect(()=>{
1823
1826
  const element = getTargetElement(target);
1824
- const fn = /*#__PURE__*/ _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
- });
1827
+ const fn = ()=>_async_to_generator$4(function*() {
1828
+ var _element_scrollHeight, _element_scrollWidth;
1829
+ const previous = {
1830
+ height: (_element_scrollHeight = element == null ? void 0 : element.scrollHeight) != null ? _element_scrollHeight : 0,
1831
+ width: (_element_scrollWidth = element == null ? void 0 : element.scrollWidth) != null ? _element_scrollWidth : 0
1832
+ };
1833
+ yield savedLoadMore.current(state);
1834
+ if (options.preserveScrollPosition && element) {
1835
+ element.scrollTo({
1836
+ top: element.scrollHeight - previous.height,
1837
+ left: element.scrollWidth - previous.width
1838
+ });
1839
+ }
1840
+ })();
1838
1841
  fn();
1839
1842
  }, [
1840
1843
  di,
@@ -2028,30 +2031,30 @@ const useMediaDevices = (options = {})=>{
2028
2031
  });
2029
2032
  }).catch(noop);
2030
2033
  }, []);
2031
- const ensurePermissions = React.useCallback(/*#__PURE__*/ _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
- }), [
2034
+ const ensurePermissions = React.useCallback(()=>_async_to_generator$3(function*() {
2035
+ if (!isSupported) {
2036
+ return false;
2037
+ }
2038
+ if (permissionGranted.current) {
2039
+ return true;
2040
+ }
2041
+ let state;
2042
+ try {
2043
+ state = (yield navigator.permissions.query({
2044
+ name: 'camera'
2045
+ })).state;
2046
+ } catch (error) {
2047
+ state = 'prompt';
2048
+ }
2049
+ if (state !== 'granted') {
2050
+ stream.current = yield navigator.mediaDevices.getUserMedia(constraints);
2051
+ onChange();
2052
+ permissionGranted.current = true;
2053
+ } else {
2054
+ permissionGranted.current = false;
2055
+ }
2056
+ return permissionGranted.current;
2057
+ })(), [
2055
2058
  onChange,
2056
2059
  isSupported,
2057
2060
  constraints
@@ -2845,15 +2848,24 @@ const useScrollIntoView = (targetElement, { duration = 1250, axis = 'y', onScrol
2845
2848
  };
2846
2849
  };
2847
2850
 
2851
+ function checkOverflowScroll(ele) {
2852
+ const style = window.getComputedStyle(ele);
2853
+ if (style.overflowX === 'scroll' || style.overflowY === 'scroll' || style.overflowX === 'auto' && ele.clientWidth < ele.scrollWidth || style.overflowY === 'auto' && ele.clientHeight < ele.scrollHeight) {
2854
+ return true;
2855
+ } else {
2856
+ const parent = ele.parentNode;
2857
+ if (!parent || parent.tagName === 'BODY') return false;
2858
+ return checkOverflowScroll(parent);
2859
+ }
2860
+ }
2848
2861
  function preventDefault(rawEvent) {
2849
2862
  const e = rawEvent || window.event;
2863
+ const _target = e.target;
2864
+ // Do not prevent if element or parentNodes have overflow: scroll set.
2865
+ if (checkOverflowScroll(_target)) return false;
2850
2866
  // 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
- return true;
2853
- }
2854
- if (e.preventDefault) {
2855
- e.preventDefault();
2856
- }
2867
+ if (e.touches.length > 1) return true;
2868
+ if (e.preventDefault) e.preventDefault();
2857
2869
  return false;
2858
2870
  }
2859
2871
  const useScrollLock = (target, initialState = false)=>{
@@ -3166,14 +3178,14 @@ const useWebNotification = (requestPermissions = false)=>{
3166
3178
  }, [
3167
3179
  isSupported
3168
3180
  ]);
3169
- const ensurePermissions = React.useCallback(/*#__PURE__*/ _async_to_generator$2(function*() {
3170
- if (!isSupported) return;
3171
- if (!permissionGranted.current && Notification.permission !== 'denied') {
3172
- const result = yield Notification.requestPermission();
3173
- if (result === 'granted') permissionGranted.current = true;
3174
- }
3175
- return permissionGranted.current;
3176
- }), [
3181
+ const ensurePermissions = React.useCallback(()=>_async_to_generator$2(function*() {
3182
+ if (!isSupported) return;
3183
+ if (!permissionGranted.current && Notification.permission !== 'denied') {
3184
+ const result = yield Notification.requestPermission();
3185
+ if (result === 'granted') permissionGranted.current = true;
3186
+ }
3187
+ return permissionGranted.current;
3188
+ })(), [
3177
3189
  isSupported
3178
3190
  ]);
3179
3191
  React.useEffect(()=>{
@@ -3308,33 +3320,33 @@ function _async_to_generator$1(fn) {
3308
3320
  }
3309
3321
  const useClipboard = ()=>{
3310
3322
  const [text, setText] = React.useState('');
3311
- const updateText = React.useCallback(/*#__PURE__*/ _async_to_generator$1(function*() {
3312
- // Check if document is focused before attempting to read clipboard
3313
- if (!document.hasFocus()) {
3314
- return;
3315
- }
3316
- try {
3317
- const value = yield window.navigator.clipboard.readText();
3318
- setText(value);
3319
- } catch (error) {
3320
- // Handle cases where clipboard access is denied or unavailable
3321
- console.warn('Failed to read clipboard:', error);
3322
- }
3323
- }), []);
3323
+ const updateText = React.useCallback(()=>_async_to_generator$1(function*() {
3324
+ // Check if document is focused before attempting to read clipboard
3325
+ if (!document.hasFocus()) {
3326
+ return;
3327
+ }
3328
+ try {
3329
+ const value = yield window.navigator.clipboard.readText();
3330
+ setText(value);
3331
+ } catch (error) {
3332
+ // Handle cases where clipboard access is denied or unavailable
3333
+ console.warn('Failed to read clipboard:', error);
3334
+ }
3335
+ })(), []);
3324
3336
  useEventListener('copy', updateText);
3325
3337
  useEventListener('cut', updateText);
3326
3338
  // Also listen for focus events to update clipboard when window regains focus
3327
3339
  useEventListener('focus', updateText, window);
3328
- const copy = React.useCallback(/*#__PURE__*/ _async_to_generator$1(function*(txt) {
3329
- setText(txt);
3330
- try {
3331
- yield window.navigator.clipboard.writeText(txt);
3332
- } catch (error) {
3333
- console.warn('Failed to write to clipboard:', error);
3334
- throw error // Re-throw so caller can handle it
3335
- ;
3336
- }
3337
- }), []);
3340
+ const copy = React.useCallback((txt)=>_async_to_generator$1(function*() {
3341
+ setText(txt);
3342
+ try {
3343
+ yield window.navigator.clipboard.writeText(txt);
3344
+ } catch (error) {
3345
+ console.warn('Failed to write to clipboard:', error);
3346
+ throw error // Re-throw so caller can handle it
3347
+ ;
3348
+ }
3349
+ })(), []);
3338
3350
  React.useEffect(()=>{
3339
3351
  updateText();
3340
3352
  }, [
@@ -3904,98 +3916,98 @@ const useFetchEventSource = (url, options = {})=>{
3904
3916
  options.onClose == null ? void 0 : options.onClose.call(options);
3905
3917
  }
3906
3918
  });
3907
- const open = useEvent(/*#__PURE__*/ _async_to_generator(function*() {
3908
- close();
3909
- setStatus('CONNECTING');
3910
- explicitlyClosed.current = false;
3911
- retries.current = 0;
3912
- // 创建新的 AbortController
3913
- abortController.current = new AbortController();
3914
- try {
3915
- // 从选项中提取 FetchEventSourceInit 相关的选项
3916
- const { immediate, autoReconnect, onOpen, onMessage, onError, onClose, withCredentials, body } = options, fetchOptions = _object_without_properties_loose(options, [
3917
- "immediate",
3918
- "autoReconnect",
3919
- "onOpen",
3920
- "onMessage",
3921
- "onError",
3922
- "onClose",
3923
- "withCredentials",
3924
- "body"
3925
- ]);
3926
- // 构建请求配置
3927
- const finalOptions = _extends({
3928
- method: options.method || 'GET',
3929
- headers: _extends({
3930
- 'Accept': 'text/event-stream',
3931
- 'Cache-Control': 'no-cache',
3932
- 'Connection': 'keep-alive'
3933
- }, options.headers),
3934
- signal: abortController.current.signal,
3935
- credentials: withCredentials ? 'include' : 'same-origin'
3936
- }, fetchOptions);
3937
- // 只在 POST 请求时添加 body
3938
- if (options.method === 'POST' && body) {
3939
- finalOptions.body = body;
3940
- finalOptions.headers = _extends({}, finalOptions.headers, {
3941
- 'Content-Type': 'application/json'
3942
- });
3943
- }
3944
- yield fetchEventSource.fetchEventSource(url.toString(), _extends({}, finalOptions, {
3945
- onopen (response) {
3946
- return _async_to_generator(function*() {
3947
- if (response.ok) {
3948
- setStatus('CONNECTED');
3949
- setError(null);
3950
- options.onOpen == null ? void 0 : options.onOpen.call(options);
3951
- } else {
3952
- const error = new Error(`Failed to connect: ${response.status} ${response.statusText}`);
3953
- setError(error);
3954
- throw error;
3919
+ const open = useEvent(()=>_async_to_generator(function*() {
3920
+ close();
3921
+ setStatus('CONNECTING');
3922
+ explicitlyClosed.current = false;
3923
+ retries.current = 0;
3924
+ // 创建新的 AbortController
3925
+ abortController.current = new AbortController();
3926
+ try {
3927
+ // 从选项中提取 FetchEventSourceInit 相关的选项
3928
+ const { immediate, autoReconnect, onOpen, onMessage, onError, onClose, withCredentials, body } = options, fetchOptions = _object_without_properties_loose(options, [
3929
+ "immediate",
3930
+ "autoReconnect",
3931
+ "onOpen",
3932
+ "onMessage",
3933
+ "onError",
3934
+ "onClose",
3935
+ "withCredentials",
3936
+ "body"
3937
+ ]);
3938
+ // 构建请求配置
3939
+ const finalOptions = _extends({
3940
+ method: options.method || 'GET',
3941
+ headers: _extends({
3942
+ 'Accept': 'text/event-stream',
3943
+ 'Cache-Control': 'no-cache',
3944
+ 'Connection': 'keep-alive'
3945
+ }, options.headers),
3946
+ signal: abortController.current.signal,
3947
+ credentials: withCredentials ? 'include' : 'same-origin'
3948
+ }, fetchOptions);
3949
+ // 只在 POST 请求时添加 body
3950
+ if (options.method === 'POST' && body) {
3951
+ finalOptions.body = body;
3952
+ finalOptions.headers = _extends({}, finalOptions.headers, {
3953
+ 'Content-Type': 'application/json'
3954
+ });
3955
+ }
3956
+ yield fetchEventSource.fetchEventSource(url.toString(), _extends({}, finalOptions, {
3957
+ onopen (response) {
3958
+ return _async_to_generator(function*() {
3959
+ if (response.ok) {
3960
+ setStatus('CONNECTED');
3961
+ setError(null);
3962
+ options.onOpen == null ? void 0 : options.onOpen.call(options);
3963
+ } else {
3964
+ const error = new Error(`Failed to connect: ${response.status} ${response.statusText}`);
3965
+ setError(error);
3966
+ throw error;
3967
+ }
3968
+ })();
3969
+ },
3970
+ onmessage (msg) {
3971
+ if (!explicitlyClosed.current) {
3972
+ setData(msg.data);
3973
+ var _msg_id;
3974
+ setLastEventId((_msg_id = msg.id) != null ? _msg_id : null);
3975
+ setEvent(msg.event || null);
3976
+ options.onMessage == null ? void 0 : options.onMessage.call(options, msg);
3977
+ }
3978
+ },
3979
+ onerror (err) {
3980
+ setError(err);
3981
+ setStatus('DISCONNECTED');
3982
+ const retryDelay = options.onError == null ? void 0 : options.onError.call(options, err);
3983
+ if (options.autoReconnect && !explicitlyClosed.current) {
3984
+ const { retries: maxRetries = -1, delay = 1000, onFailed } = options.autoReconnect;
3985
+ retries.current += 1;
3986
+ if (typeof maxRetries === 'number' && (maxRetries < 0 || retries.current < maxRetries) || typeof maxRetries === 'function' && maxRetries()) {
3987
+ return retryDelay != null ? retryDelay : delay;
3988
+ } else {
3989
+ onFailed == null ? void 0 : onFailed();
3990
+ throw err;
3991
+ }
3992
+ }
3993
+ throw err;
3994
+ },
3995
+ onclose () {
3996
+ if (!explicitlyClosed.current) {
3997
+ setStatus('DISCONNECTED');
3998
+ options.onClose == null ? void 0 : options.onClose.call(options);
3955
3999
  }
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
4000
  }
3966
- },
3967
- onerror (err) {
4001
+ }));
4002
+ } catch (err) {
4003
+ // 只处理非主动关闭导致的错误
4004
+ if (!explicitlyClosed.current) {
4005
+ console.error('EventSource Error:', err);
3968
4006
  setError(err);
3969
4007
  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
4008
  }
3989
- }));
3990
- } catch (err) {
3991
- // 只处理非主动关闭导致的错误
3992
- if (!explicitlyClosed.current) {
3993
- console.error('EventSource Error:', err);
3994
- setError(err);
3995
- setStatus('DISCONNECTED');
3996
4009
  }
3997
- }
3998
- }));
4010
+ })());
3999
4011
  React.useEffect(()=>{
4000
4012
  if (options.immediate !== false) {
4001
4013
  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, RefObject, useEffect, useLayoutEffect, Ref, Context } from 'react';
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';
@@ -2402,9 +2402,9 @@ options?: ThrottleSettings) => T;
2402
2402
  declare const useThrottle: UseThrottle;
2403
2403
 
2404
2404
  declare function useThrottleFn<T extends (...args: any) => any>(fn: T, wait?: number, options?: ThrottleSettings): {
2405
- run: lodash.DebouncedFunc<(...args_0: Parameters<T>) => ReturnType<T>>;
2405
+ run: lodash.DebouncedFuncLeading<(...args_0: Parameters<T>) => ReturnType<T>>;
2406
2406
  cancel: () => void;
2407
- flush: () => ReturnType<T> | undefined;
2407
+ flush: () => ReturnType<T>;
2408
2408
  };
2409
2409
 
2410
2410
  /**
@@ -3596,4 +3596,5 @@ type Use = <T>(
3596
3596
  */
3597
3597
  usable: Usable<T>) => T;
3598
3598
 
3599
- export { type ColorScheme, type Contrast, type DepsEqualFnType, type EventSourceStatus, type EventType, type INetworkInformation, type IUseNetworkState, type KeyModifier, type Pausable, type Platform, type PossibleRef, type Use, type UseActiveElement, type UseAsyncEffect, type UseBroadcastChannel, type UseBroadcastChannelOptions, type UseBroadcastChannelReturn, type UseClickOutside, type UseClipboard, type UseControlled, type UseCookie, type UseCookieState, type UseCountDown, type UseCounter, type UseCssVar, type UseCssVarOptions, type UseCustomCompareEffect, type UseCycleList, type UseDarkMode, type UseDarkOptions, type UseDebounce, type UseDebounceFn, type UseDeepCompareEffect, type UseDevicePixelRatio, type UseDevicePixelRatioReturn, type UseDisclosure, type UseDisclosureProps, type UseDocumentVisibility, type UseDoubleClick, type UseDoubleClickProps, type UseDraggable, type UseDraggableOptions, type UseDropZone, type UseElementBounding, type UseElementBoundingOptions, type UseElementBoundingReturn, type UseElementByPoint, type UseElementByPointOptions, type UseElementByPointReturn, type UseElementSize, type UseElementVisibility, type UseEvent, type UseEventEmitter, type UseEventEmitterDisposable, type UseEventEmitterEvent, type UseEventEmitterEventOnce, type UseEventEmitterListener, type UseEventEmitterReturn, type UseEventListener, type UseEventSource, type UseEventSourceAutoReconnectOptions, type UseEventSourceOptions, type UseEventSourceReturn, type UseEyeDropper, type UseEyeDropperOpenOptions, type UseEyeDropperOpenReturnType, type UseFavicon, type UseFetchEventSource, type UseFetchEventSourceAutoReconnectOptions, type UseFetchEventSourceMessage, type UseFetchEventSourceOptions, type UseFetchEventSourceReturn, type UseFetchEventSourceStatus, type UseFileDialog, type UseFileDialogOptions, type UseFirstMountState, type UseFocus, type UseFps, type UseFpsOptions, type UseFullScreenOptions, type UseFullscreen, type UseGeolocation, type UseHover, type UseIdle, type UseInfiniteScroll, type UseInfiniteScrollArrivedState, type UseInfiniteScrollDirection, type UseInfiniteScrollLoadMore, type UseInfiniteScrollOptions, type UseIntersectionObserver, type UseInterval, type UseIntervalOptions, type UseKeyModifier, type UseLatest, type UseLocalStorage, type UseLocalStorageOptions, type UseLocalStorageSerializer, type UseLocationSelector, type UseLongPress, type UseLongPressOptions, type UseMeasure, type UseMeasureRect, type UseMediaDeviceOptions, type UseMediaDevices, type UseMediaQuery, type UseMergedRef, type UseMobileLandscape, type UseModifierOptions, type UseMount, type UseMountedState, type UseMouse, type UseMouseCursorState, type UseMousePressed, type UseMousePressedOptions, type UseMousePressedSourceType, type UseMutationObserver, type UseNetwork, type UseObjectUrl, type UseOnline, type UseOrientation, type UseOrientationLockType, type UseOrientationState, type UseOrientationType, type UsePageLeave, type UsePermission, type UsePermissionDescriptorNamePolyfill, type UsePermissionGeneralPermissionDescriptor, type UsePermissionState, type UsePlatform, type UsePlatformProps, type UsePlatformReturn, type UsePreferredColorScheme, type UsePreferredContrast, type UsePreferredDark, type UsePreferredLanguages, type UsePrevious, type UseRafFn, type UseRafState, type UseReducedMotion, type UseResizeObserver, type UseScreenSafeArea, type UseScriptTag, type UseScriptTagOptions, type UseScriptTagStatus, type UseScroll, type UseScrollArrivedState, type UseScrollDirection, type UseScrollIntoView, type UseScrollIntoViewAnimation, type UseScrollIntoViewParams, type UseScrollLock, type UseScrollOffset, type UseScrollOptions, type UseSessionStorage, type UseSessionStorageOptions, type UseSessionStorageSerializer, type UseSetState, type UseSticky, type UseStickyParams, type UseSupported, type UseTextDirection, type UseTextDirectionOptions, type UseTextDirectionValue, type UseTextSelection, type UseThrottle, type UseThrottleFn, type UseTimeout, type UseTimeoutFn, type UseTimeoutFnOptions, type UseTimeoutOptions, type UseTitle, type UseToggle, type UseUnmount, type UseUpdate, type UseWebNotification, type UseWebNotificationReturn, type UseWebNotificationShow, type UseWindowScroll, type UseWindowScrollState, type UseWindowSize, type UseWindowsFocus, 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 };
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, RefObject, useEffect, useLayoutEffect, Ref, Context } from 'react';
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';
@@ -2402,9 +2402,9 @@ options?: ThrottleSettings) => T;
2402
2402
  declare const useThrottle: UseThrottle;
2403
2403
 
2404
2404
  declare function useThrottleFn<T extends (...args: any) => any>(fn: T, wait?: number, options?: ThrottleSettings): {
2405
- run: lodash.DebouncedFunc<(...args_0: Parameters<T>) => ReturnType<T>>;
2405
+ run: lodash.DebouncedFuncLeading<(...args_0: Parameters<T>) => ReturnType<T>>;
2406
2406
  cancel: () => void;
2407
- flush: () => ReturnType<T> | undefined;
2407
+ flush: () => ReturnType<T>;
2408
2408
  };
2409
2409
 
2410
2410
  /**
@@ -3596,4 +3596,5 @@ type Use = <T>(
3596
3596
  */
3597
3597
  usable: Usable<T>) => T;
3598
3598
 
3599
- export { type ColorScheme, type Contrast, type DepsEqualFnType, type EventSourceStatus, type EventType, type INetworkInformation, type IUseNetworkState, type KeyModifier, type Pausable, type Platform, type PossibleRef, type Use, type UseActiveElement, type UseAsyncEffect, type UseBroadcastChannel, type UseBroadcastChannelOptions, type UseBroadcastChannelReturn, type UseClickOutside, type UseClipboard, type UseControlled, type UseCookie, type UseCookieState, type UseCountDown, type UseCounter, type UseCssVar, type UseCssVarOptions, type UseCustomCompareEffect, type UseCycleList, type UseDarkMode, type UseDarkOptions, type UseDebounce, type UseDebounceFn, type UseDeepCompareEffect, type UseDevicePixelRatio, type UseDevicePixelRatioReturn, type UseDisclosure, type UseDisclosureProps, type UseDocumentVisibility, type UseDoubleClick, type UseDoubleClickProps, type UseDraggable, type UseDraggableOptions, type UseDropZone, type UseElementBounding, type UseElementBoundingOptions, type UseElementBoundingReturn, type UseElementByPoint, type UseElementByPointOptions, type UseElementByPointReturn, type UseElementSize, type UseElementVisibility, type UseEvent, type UseEventEmitter, type UseEventEmitterDisposable, type UseEventEmitterEvent, type UseEventEmitterEventOnce, type UseEventEmitterListener, type UseEventEmitterReturn, type UseEventListener, type UseEventSource, type UseEventSourceAutoReconnectOptions, type UseEventSourceOptions, type UseEventSourceReturn, type UseEyeDropper, type UseEyeDropperOpenOptions, type UseEyeDropperOpenReturnType, type UseFavicon, type UseFetchEventSource, type UseFetchEventSourceAutoReconnectOptions, type UseFetchEventSourceMessage, type UseFetchEventSourceOptions, type UseFetchEventSourceReturn, type UseFetchEventSourceStatus, type UseFileDialog, type UseFileDialogOptions, type UseFirstMountState, type UseFocus, type UseFps, type UseFpsOptions, type UseFullScreenOptions, type UseFullscreen, type UseGeolocation, type UseHover, type UseIdle, type UseInfiniteScroll, type UseInfiniteScrollArrivedState, type UseInfiniteScrollDirection, type UseInfiniteScrollLoadMore, type UseInfiniteScrollOptions, type UseIntersectionObserver, type UseInterval, type UseIntervalOptions, type UseKeyModifier, type UseLatest, type UseLocalStorage, type UseLocalStorageOptions, type UseLocalStorageSerializer, type UseLocationSelector, type UseLongPress, type UseLongPressOptions, type UseMeasure, type UseMeasureRect, type UseMediaDeviceOptions, type UseMediaDevices, type UseMediaQuery, type UseMergedRef, type UseMobileLandscape, type UseModifierOptions, type UseMount, type UseMountedState, type UseMouse, type UseMouseCursorState, type UseMousePressed, type UseMousePressedOptions, type UseMousePressedSourceType, type UseMutationObserver, type UseNetwork, type UseObjectUrl, type UseOnline, type UseOrientation, type UseOrientationLockType, type UseOrientationState, type UseOrientationType, type UsePageLeave, type UsePermission, type UsePermissionDescriptorNamePolyfill, type UsePermissionGeneralPermissionDescriptor, type UsePermissionState, type UsePlatform, type UsePlatformProps, type UsePlatformReturn, type UsePreferredColorScheme, type UsePreferredContrast, type UsePreferredDark, type UsePreferredLanguages, type UsePrevious, type UseRafFn, type UseRafState, type UseReducedMotion, type UseResizeObserver, type UseScreenSafeArea, type UseScriptTag, type UseScriptTagOptions, type UseScriptTagStatus, type UseScroll, type UseScrollArrivedState, type UseScrollDirection, type UseScrollIntoView, type UseScrollIntoViewAnimation, type UseScrollIntoViewParams, type UseScrollLock, type UseScrollOffset, type UseScrollOptions, type UseSessionStorage, type UseSessionStorageOptions, type UseSessionStorageSerializer, type UseSetState, type UseSticky, type UseStickyParams, type UseSupported, type UseTextDirection, type UseTextDirectionOptions, type UseTextDirectionValue, type UseTextSelection, type UseThrottle, type UseThrottleFn, type UseTimeout, type UseTimeoutFn, type UseTimeoutFnOptions, type UseTimeoutOptions, type UseTitle, type UseToggle, type UseUnmount, type UseUpdate, type UseWebNotification, type UseWebNotificationReturn, type UseWebNotificationShow, type UseWindowScroll, type UseWindowScrollState, type UseWindowSize, type UseWindowsFocus, 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 };
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, RefObject, useEffect, useLayoutEffect, Ref, Context } from 'react';
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';
@@ -2402,9 +2402,9 @@ options?: ThrottleSettings) => T;
2402
2402
  declare const useThrottle: UseThrottle;
2403
2403
 
2404
2404
  declare function useThrottleFn<T extends (...args: any) => any>(fn: T, wait?: number, options?: ThrottleSettings): {
2405
- run: lodash.DebouncedFunc<(...args_0: Parameters<T>) => ReturnType<T>>;
2405
+ run: lodash.DebouncedFuncLeading<(...args_0: Parameters<T>) => ReturnType<T>>;
2406
2406
  cancel: () => void;
2407
- flush: () => ReturnType<T> | undefined;
2407
+ flush: () => ReturnType<T>;
2408
2408
  };
2409
2409
 
2410
2410
  /**
@@ -3596,4 +3596,5 @@ type Use = <T>(
3596
3596
  */
3597
3597
  usable: Usable<T>) => T;
3598
3598
 
3599
- export { type ColorScheme, type Contrast, type DepsEqualFnType, type EventSourceStatus, type EventType, type INetworkInformation, type IUseNetworkState, type KeyModifier, type Pausable, type Platform, type PossibleRef, type Use, type UseActiveElement, type UseAsyncEffect, type UseBroadcastChannel, type UseBroadcastChannelOptions, type UseBroadcastChannelReturn, type UseClickOutside, type UseClipboard, type UseControlled, type UseCookie, type UseCookieState, type UseCountDown, type UseCounter, type UseCssVar, type UseCssVarOptions, type UseCustomCompareEffect, type UseCycleList, type UseDarkMode, type UseDarkOptions, type UseDebounce, type UseDebounceFn, type UseDeepCompareEffect, type UseDevicePixelRatio, type UseDevicePixelRatioReturn, type UseDisclosure, type UseDisclosureProps, type UseDocumentVisibility, type UseDoubleClick, type UseDoubleClickProps, type UseDraggable, type UseDraggableOptions, type UseDropZone, type UseElementBounding, type UseElementBoundingOptions, type UseElementBoundingReturn, type UseElementByPoint, type UseElementByPointOptions, type UseElementByPointReturn, type UseElementSize, type UseElementVisibility, type UseEvent, type UseEventEmitter, type UseEventEmitterDisposable, type UseEventEmitterEvent, type UseEventEmitterEventOnce, type UseEventEmitterListener, type UseEventEmitterReturn, type UseEventListener, type UseEventSource, type UseEventSourceAutoReconnectOptions, type UseEventSourceOptions, type UseEventSourceReturn, type UseEyeDropper, type UseEyeDropperOpenOptions, type UseEyeDropperOpenReturnType, type UseFavicon, type UseFetchEventSource, type UseFetchEventSourceAutoReconnectOptions, type UseFetchEventSourceMessage, type UseFetchEventSourceOptions, type UseFetchEventSourceReturn, type UseFetchEventSourceStatus, type UseFileDialog, type UseFileDialogOptions, type UseFirstMountState, type UseFocus, type UseFps, type UseFpsOptions, type UseFullScreenOptions, type UseFullscreen, type UseGeolocation, type UseHover, type UseIdle, type UseInfiniteScroll, type UseInfiniteScrollArrivedState, type UseInfiniteScrollDirection, type UseInfiniteScrollLoadMore, type UseInfiniteScrollOptions, type UseIntersectionObserver, type UseInterval, type UseIntervalOptions, type UseKeyModifier, type UseLatest, type UseLocalStorage, type UseLocalStorageOptions, type UseLocalStorageSerializer, type UseLocationSelector, type UseLongPress, type UseLongPressOptions, type UseMeasure, type UseMeasureRect, type UseMediaDeviceOptions, type UseMediaDevices, type UseMediaQuery, type UseMergedRef, type UseMobileLandscape, type UseModifierOptions, type UseMount, type UseMountedState, type UseMouse, type UseMouseCursorState, type UseMousePressed, type UseMousePressedOptions, type UseMousePressedSourceType, type UseMutationObserver, type UseNetwork, type UseObjectUrl, type UseOnline, type UseOrientation, type UseOrientationLockType, type UseOrientationState, type UseOrientationType, type UsePageLeave, type UsePermission, type UsePermissionDescriptorNamePolyfill, type UsePermissionGeneralPermissionDescriptor, type UsePermissionState, type UsePlatform, type UsePlatformProps, type UsePlatformReturn, type UsePreferredColorScheme, type UsePreferredContrast, type UsePreferredDark, type UsePreferredLanguages, type UsePrevious, type UseRafFn, type UseRafState, type UseReducedMotion, type UseResizeObserver, type UseScreenSafeArea, type UseScriptTag, type UseScriptTagOptions, type UseScriptTagStatus, type UseScroll, type UseScrollArrivedState, type UseScrollDirection, type UseScrollIntoView, type UseScrollIntoViewAnimation, type UseScrollIntoViewParams, type UseScrollLock, type UseScrollOffset, type UseScrollOptions, type UseSessionStorage, type UseSessionStorageOptions, type UseSessionStorageSerializer, type UseSetState, type UseSticky, type UseStickyParams, type UseSupported, type UseTextDirection, type UseTextDirectionOptions, type UseTextDirectionValue, type UseTextSelection, type UseThrottle, type UseThrottleFn, type UseTimeout, type UseTimeoutFn, type UseTimeoutFnOptions, type UseTimeoutOptions, type UseTitle, type UseToggle, type UseUnmount, type UseUpdate, type UseWebNotification, type UseWebNotificationReturn, type UseWebNotificationShow, type UseWindowScroll, type UseWindowScrollState, type UseWindowSize, type UseWindowsFocus, 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 };
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 = /*#__PURE__*/ _async_to_generator$7(function*() {
202
- if (!mounted()) {
203
- return;
204
- }
205
- yield effect();
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(/*#__PURE__*/ _async_to_generator$6(function*(options = {}) {
1250
- if (!isSupported) {
1251
- return {
1252
- sRGBHex: ''
1253
- };
1254
- }
1255
- const eyeDropper = new window.EyeDropper();
1256
- return eyeDropper.open(options);
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,23 @@ const useFileDialog = (options = defaultOptions$1)=>{
1347
1347
  return input;
1348
1348
  }, []);
1349
1349
  inputRef.current = initFn();
1350
- const open = /*#__PURE__*/ _async_to_generator$5(function*(localOptions) {
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
- });
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
+ // Only set capture attribute if it's explicitly provided
1358
+ if (_options.capture !== undefined) {
1359
+ inputRef.current.capture = _options.capture;
1360
+ }
1361
+ fileOpenPromiseRef.current = new Promise((resolve)=>{
1362
+ resolveFileOpenPromiseRef.current = resolve;
1363
+ });
1364
+ inputRef.current.click();
1365
+ return fileOpenPromiseRef.current;
1366
+ })();
1364
1367
  const reset = ()=>{
1365
1368
  setFiles(null);
1366
1369
  resolveFileOpenPromiseRef.current == null ? void 0 : resolveFileOpenPromiseRef.current.call(resolveFileOpenPromiseRef, null);
@@ -1813,20 +1816,20 @@ const useInfiniteScroll = (target, onLoadMore, options = defaultOptions$1)=>{
1813
1816
  const di = state[3][direction];
1814
1817
  useUpdateEffect(()=>{
1815
1818
  const element = getTargetElement(target);
1816
- const fn = /*#__PURE__*/ _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
- });
1819
+ const fn = ()=>_async_to_generator$4(function*() {
1820
+ var _element_scrollHeight, _element_scrollWidth;
1821
+ const previous = {
1822
+ height: (_element_scrollHeight = element == null ? void 0 : element.scrollHeight) != null ? _element_scrollHeight : 0,
1823
+ width: (_element_scrollWidth = element == null ? void 0 : element.scrollWidth) != null ? _element_scrollWidth : 0
1824
+ };
1825
+ yield savedLoadMore.current(state);
1826
+ if (options.preserveScrollPosition && element) {
1827
+ element.scrollTo({
1828
+ top: element.scrollHeight - previous.height,
1829
+ left: element.scrollWidth - previous.width
1830
+ });
1831
+ }
1832
+ })();
1830
1833
  fn();
1831
1834
  }, [
1832
1835
  di,
@@ -2020,30 +2023,30 @@ const useMediaDevices = (options = {})=>{
2020
2023
  });
2021
2024
  }).catch(noop);
2022
2025
  }, []);
2023
- const ensurePermissions = useCallback(/*#__PURE__*/ _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
- }), [
2026
+ const ensurePermissions = useCallback(()=>_async_to_generator$3(function*() {
2027
+ if (!isSupported) {
2028
+ return false;
2029
+ }
2030
+ if (permissionGranted.current) {
2031
+ return true;
2032
+ }
2033
+ let state;
2034
+ try {
2035
+ state = (yield navigator.permissions.query({
2036
+ name: 'camera'
2037
+ })).state;
2038
+ } catch (error) {
2039
+ state = 'prompt';
2040
+ }
2041
+ if (state !== 'granted') {
2042
+ stream.current = yield navigator.mediaDevices.getUserMedia(constraints);
2043
+ onChange();
2044
+ permissionGranted.current = true;
2045
+ } else {
2046
+ permissionGranted.current = false;
2047
+ }
2048
+ return permissionGranted.current;
2049
+ })(), [
2047
2050
  onChange,
2048
2051
  isSupported,
2049
2052
  constraints
@@ -2837,15 +2840,24 @@ const useScrollIntoView = (targetElement, { duration = 1250, axis = 'y', onScrol
2837
2840
  };
2838
2841
  };
2839
2842
 
2843
+ function checkOverflowScroll(ele) {
2844
+ const style = window.getComputedStyle(ele);
2845
+ if (style.overflowX === 'scroll' || style.overflowY === 'scroll' || style.overflowX === 'auto' && ele.clientWidth < ele.scrollWidth || style.overflowY === 'auto' && ele.clientHeight < ele.scrollHeight) {
2846
+ return true;
2847
+ } else {
2848
+ const parent = ele.parentNode;
2849
+ if (!parent || parent.tagName === 'BODY') return false;
2850
+ return checkOverflowScroll(parent);
2851
+ }
2852
+ }
2840
2853
  function preventDefault(rawEvent) {
2841
2854
  const e = rawEvent || window.event;
2855
+ const _target = e.target;
2856
+ // Do not prevent if element or parentNodes have overflow: scroll set.
2857
+ if (checkOverflowScroll(_target)) return false;
2842
2858
  // 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
- return true;
2845
- }
2846
- if (e.preventDefault) {
2847
- e.preventDefault();
2848
- }
2859
+ if (e.touches.length > 1) return true;
2860
+ if (e.preventDefault) e.preventDefault();
2849
2861
  return false;
2850
2862
  }
2851
2863
  const useScrollLock = (target, initialState = false)=>{
@@ -3158,14 +3170,14 @@ const useWebNotification = (requestPermissions = false)=>{
3158
3170
  }, [
3159
3171
  isSupported
3160
3172
  ]);
3161
- const ensurePermissions = useCallback(/*#__PURE__*/ _async_to_generator$2(function*() {
3162
- if (!isSupported) return;
3163
- if (!permissionGranted.current && Notification.permission !== 'denied') {
3164
- const result = yield Notification.requestPermission();
3165
- if (result === 'granted') permissionGranted.current = true;
3166
- }
3167
- return permissionGranted.current;
3168
- }), [
3173
+ const ensurePermissions = useCallback(()=>_async_to_generator$2(function*() {
3174
+ if (!isSupported) return;
3175
+ if (!permissionGranted.current && Notification.permission !== 'denied') {
3176
+ const result = yield Notification.requestPermission();
3177
+ if (result === 'granted') permissionGranted.current = true;
3178
+ }
3179
+ return permissionGranted.current;
3180
+ })(), [
3169
3181
  isSupported
3170
3182
  ]);
3171
3183
  useEffect(()=>{
@@ -3300,33 +3312,33 @@ function _async_to_generator$1(fn) {
3300
3312
  }
3301
3313
  const useClipboard = ()=>{
3302
3314
  const [text, setText] = useState('');
3303
- const updateText = useCallback(/*#__PURE__*/ _async_to_generator$1(function*() {
3304
- // Check if document is focused before attempting to read clipboard
3305
- if (!document.hasFocus()) {
3306
- return;
3307
- }
3308
- try {
3309
- const value = yield window.navigator.clipboard.readText();
3310
- setText(value);
3311
- } catch (error) {
3312
- // Handle cases where clipboard access is denied or unavailable
3313
- console.warn('Failed to read clipboard:', error);
3314
- }
3315
- }), []);
3315
+ const updateText = useCallback(()=>_async_to_generator$1(function*() {
3316
+ // Check if document is focused before attempting to read clipboard
3317
+ if (!document.hasFocus()) {
3318
+ return;
3319
+ }
3320
+ try {
3321
+ const value = yield window.navigator.clipboard.readText();
3322
+ setText(value);
3323
+ } catch (error) {
3324
+ // Handle cases where clipboard access is denied or unavailable
3325
+ console.warn('Failed to read clipboard:', error);
3326
+ }
3327
+ })(), []);
3316
3328
  useEventListener('copy', updateText);
3317
3329
  useEventListener('cut', updateText);
3318
3330
  // Also listen for focus events to update clipboard when window regains focus
3319
3331
  useEventListener('focus', updateText, window);
3320
- const copy = useCallback(/*#__PURE__*/ _async_to_generator$1(function*(txt) {
3321
- setText(txt);
3322
- try {
3323
- yield window.navigator.clipboard.writeText(txt);
3324
- } catch (error) {
3325
- console.warn('Failed to write to clipboard:', error);
3326
- throw error // Re-throw so caller can handle it
3327
- ;
3328
- }
3329
- }), []);
3332
+ const copy = useCallback((txt)=>_async_to_generator$1(function*() {
3333
+ setText(txt);
3334
+ try {
3335
+ yield window.navigator.clipboard.writeText(txt);
3336
+ } catch (error) {
3337
+ console.warn('Failed to write to clipboard:', error);
3338
+ throw error // Re-throw so caller can handle it
3339
+ ;
3340
+ }
3341
+ })(), []);
3330
3342
  useEffect(()=>{
3331
3343
  updateText();
3332
3344
  }, [
@@ -3896,98 +3908,98 @@ const useFetchEventSource = (url, options = {})=>{
3896
3908
  options.onClose == null ? void 0 : options.onClose.call(options);
3897
3909
  }
3898
3910
  });
3899
- const open = useEvent(/*#__PURE__*/ _async_to_generator(function*() {
3900
- close();
3901
- setStatus('CONNECTING');
3902
- explicitlyClosed.current = false;
3903
- retries.current = 0;
3904
- // 创建新的 AbortController
3905
- abortController.current = new AbortController();
3906
- try {
3907
- // 从选项中提取 FetchEventSourceInit 相关的选项
3908
- const { immediate, autoReconnect, onOpen, onMessage, onError, onClose, withCredentials, body } = options, fetchOptions = _object_without_properties_loose(options, [
3909
- "immediate",
3910
- "autoReconnect",
3911
- "onOpen",
3912
- "onMessage",
3913
- "onError",
3914
- "onClose",
3915
- "withCredentials",
3916
- "body"
3917
- ]);
3918
- // 构建请求配置
3919
- const finalOptions = _extends({
3920
- method: options.method || 'GET',
3921
- headers: _extends({
3922
- 'Accept': 'text/event-stream',
3923
- 'Cache-Control': 'no-cache',
3924
- 'Connection': 'keep-alive'
3925
- }, options.headers),
3926
- signal: abortController.current.signal,
3927
- credentials: withCredentials ? 'include' : 'same-origin'
3928
- }, fetchOptions);
3929
- // 只在 POST 请求时添加 body
3930
- if (options.method === 'POST' && body) {
3931
- finalOptions.body = body;
3932
- finalOptions.headers = _extends({}, finalOptions.headers, {
3933
- 'Content-Type': 'application/json'
3934
- });
3935
- }
3936
- yield fetchEventSource(url.toString(), _extends({}, finalOptions, {
3937
- onopen (response) {
3938
- return _async_to_generator(function*() {
3939
- if (response.ok) {
3940
- setStatus('CONNECTED');
3941
- setError(null);
3942
- options.onOpen == null ? void 0 : options.onOpen.call(options);
3943
- } else {
3944
- const error = new Error(`Failed to connect: ${response.status} ${response.statusText}`);
3945
- setError(error);
3946
- throw error;
3911
+ const open = useEvent(()=>_async_to_generator(function*() {
3912
+ close();
3913
+ setStatus('CONNECTING');
3914
+ explicitlyClosed.current = false;
3915
+ retries.current = 0;
3916
+ // 创建新的 AbortController
3917
+ abortController.current = new AbortController();
3918
+ try {
3919
+ // 从选项中提取 FetchEventSourceInit 相关的选项
3920
+ const { immediate, autoReconnect, onOpen, onMessage, onError, onClose, withCredentials, body } = options, fetchOptions = _object_without_properties_loose(options, [
3921
+ "immediate",
3922
+ "autoReconnect",
3923
+ "onOpen",
3924
+ "onMessage",
3925
+ "onError",
3926
+ "onClose",
3927
+ "withCredentials",
3928
+ "body"
3929
+ ]);
3930
+ // 构建请求配置
3931
+ const finalOptions = _extends({
3932
+ method: options.method || 'GET',
3933
+ headers: _extends({
3934
+ 'Accept': 'text/event-stream',
3935
+ 'Cache-Control': 'no-cache',
3936
+ 'Connection': 'keep-alive'
3937
+ }, options.headers),
3938
+ signal: abortController.current.signal,
3939
+ credentials: withCredentials ? 'include' : 'same-origin'
3940
+ }, fetchOptions);
3941
+ // 只在 POST 请求时添加 body
3942
+ if (options.method === 'POST' && body) {
3943
+ finalOptions.body = body;
3944
+ finalOptions.headers = _extends({}, finalOptions.headers, {
3945
+ 'Content-Type': 'application/json'
3946
+ });
3947
+ }
3948
+ yield fetchEventSource(url.toString(), _extends({}, finalOptions, {
3949
+ onopen (response) {
3950
+ return _async_to_generator(function*() {
3951
+ if (response.ok) {
3952
+ setStatus('CONNECTED');
3953
+ setError(null);
3954
+ options.onOpen == null ? void 0 : options.onOpen.call(options);
3955
+ } else {
3956
+ const error = new Error(`Failed to connect: ${response.status} ${response.statusText}`);
3957
+ setError(error);
3958
+ throw error;
3959
+ }
3960
+ })();
3961
+ },
3962
+ onmessage (msg) {
3963
+ if (!explicitlyClosed.current) {
3964
+ setData(msg.data);
3965
+ var _msg_id;
3966
+ setLastEventId((_msg_id = msg.id) != null ? _msg_id : null);
3967
+ setEvent(msg.event || null);
3968
+ options.onMessage == null ? void 0 : options.onMessage.call(options, msg);
3969
+ }
3970
+ },
3971
+ onerror (err) {
3972
+ setError(err);
3973
+ setStatus('DISCONNECTED');
3974
+ const retryDelay = options.onError == null ? void 0 : options.onError.call(options, err);
3975
+ if (options.autoReconnect && !explicitlyClosed.current) {
3976
+ const { retries: maxRetries = -1, delay = 1000, onFailed } = options.autoReconnect;
3977
+ retries.current += 1;
3978
+ if (typeof maxRetries === 'number' && (maxRetries < 0 || retries.current < maxRetries) || typeof maxRetries === 'function' && maxRetries()) {
3979
+ return retryDelay != null ? retryDelay : delay;
3980
+ } else {
3981
+ onFailed == null ? void 0 : onFailed();
3982
+ throw err;
3983
+ }
3984
+ }
3985
+ throw err;
3986
+ },
3987
+ onclose () {
3988
+ if (!explicitlyClosed.current) {
3989
+ setStatus('DISCONNECTED');
3990
+ options.onClose == null ? void 0 : options.onClose.call(options);
3947
3991
  }
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
3992
  }
3958
- },
3959
- onerror (err) {
3993
+ }));
3994
+ } catch (err) {
3995
+ // 只处理非主动关闭导致的错误
3996
+ if (!explicitlyClosed.current) {
3997
+ console.error('EventSource Error:', err);
3960
3998
  setError(err);
3961
3999
  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
4000
  }
3981
- }));
3982
- } catch (err) {
3983
- // 只处理非主动关闭导致的错误
3984
- if (!explicitlyClosed.current) {
3985
- console.error('EventSource Error:', err);
3986
- setError(err);
3987
- setStatus('DISCONNECTED');
3988
4001
  }
3989
- }
3990
- }));
4002
+ })());
3991
4003
  useEffect(()=>{
3992
4004
  if (options.immediate !== false) {
3993
4005
  open();
@@ -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 = /*#__PURE__*/ _async_to_generator(function*() {
94
- try {
95
- const qrCode = yield generateQRCode(text, options);
96
- setQRCode(qrCode);
97
- } catch (error) {
98
- setError(error);
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,
@@ -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 = /*#__PURE__*/ _async_to_generator(function*() {
88
- try {
89
- const qrCode = yield generateQRCode(text, options);
90
- setQRCode(qrCode);
91
- } catch (error) {
92
- setError(error);
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactuses/core",
3
- "version": "6.0.5",
3
+ "version": "6.0.7",
4
4
  "license": "Unlicense",
5
5
  "homepage": "https://www.reactuse.com/",
6
6
  "repository": {