@reactuses/core 5.0.11 → 5.0.13
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/dist/index.cjs +97 -37
- package/dist/index.d.cts +28 -3
- package/dist/index.d.mts +28 -3
- package/dist/index.d.ts +28 -3
- package/dist/index.mjs +97 -37
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -132,7 +132,7 @@ const useMountedState = ()=>{
|
|
|
132
132
|
return get;
|
|
133
133
|
};
|
|
134
134
|
|
|
135
|
-
function asyncGeneratorStep$
|
|
135
|
+
function asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, key, arg) {
|
|
136
136
|
try {
|
|
137
137
|
var info = gen[key](arg);
|
|
138
138
|
var value = info.value;
|
|
@@ -146,16 +146,16 @@ function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
146
146
|
Promise.resolve(value).then(_next, _throw);
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
function _async_to_generator$
|
|
149
|
+
function _async_to_generator$6(fn) {
|
|
150
150
|
return function() {
|
|
151
151
|
var self = this, args = arguments;
|
|
152
152
|
return new Promise(function(resolve, reject) {
|
|
153
153
|
var gen = fn.apply(self, args);
|
|
154
154
|
function _next(value) {
|
|
155
|
-
asyncGeneratorStep$
|
|
155
|
+
asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, "next", value);
|
|
156
156
|
}
|
|
157
157
|
function _throw(err) {
|
|
158
|
-
asyncGeneratorStep$
|
|
158
|
+
asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, "throw", err);
|
|
159
159
|
}
|
|
160
160
|
_next(undefined);
|
|
161
161
|
});
|
|
@@ -164,7 +164,7 @@ function _async_to_generator$5(fn) {
|
|
|
164
164
|
const useAsyncEffect = (effect, cleanup = noop, deps)=>{
|
|
165
165
|
const mounted = useMountedState();
|
|
166
166
|
React.useEffect(()=>{
|
|
167
|
-
const execute = /*#__PURE__*/ _async_to_generator$
|
|
167
|
+
const execute = /*#__PURE__*/ _async_to_generator$6(function*() {
|
|
168
168
|
if (!mounted()) {
|
|
169
169
|
return;
|
|
170
170
|
}
|
|
@@ -266,16 +266,56 @@ const useCookie = (key, options = defaultOptions$1, defaultValue)=>{
|
|
|
266
266
|
];
|
|
267
267
|
};
|
|
268
268
|
|
|
269
|
+
const useIsomorphicLayoutEffect = isBrowser ? React.useLayoutEffect : React.useEffect;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* keep function reference immutable
|
|
273
|
+
*/ const useEvent = (fn)=>{
|
|
274
|
+
if (isDev) {
|
|
275
|
+
if (!isFunction(fn)) {
|
|
276
|
+
console.error(`useEvent expected parameter is a function, got ${typeof fn}`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const handlerRef = React.useRef(fn);
|
|
280
|
+
useIsomorphicLayoutEffect(()=>{
|
|
281
|
+
handlerRef.current = fn;
|
|
282
|
+
}, [
|
|
283
|
+
fn
|
|
284
|
+
]);
|
|
285
|
+
return React.useCallback((...args)=>{
|
|
286
|
+
const fn = handlerRef.current;
|
|
287
|
+
return fn(...args);
|
|
288
|
+
}, []);
|
|
289
|
+
};
|
|
290
|
+
|
|
269
291
|
const useInterval = (callback, delay, options = defaultOptions$1)=>{
|
|
270
|
-
const immediate = options
|
|
292
|
+
const { immediate, controls } = options;
|
|
271
293
|
const savedCallback = useLatest(callback);
|
|
294
|
+
const isActive = React.useRef(false);
|
|
295
|
+
const timer = React.useRef(null);
|
|
296
|
+
const clean = ()=>{
|
|
297
|
+
timer.current && clearInterval(timer.current);
|
|
298
|
+
};
|
|
299
|
+
const resume = useEvent(()=>{
|
|
300
|
+
isActive.current = true;
|
|
301
|
+
timer.current = setInterval(()=>savedCallback.current(), delay || 0);
|
|
302
|
+
});
|
|
303
|
+
const pause = useEvent(()=>{
|
|
304
|
+
isActive.current = false;
|
|
305
|
+
clean();
|
|
306
|
+
});
|
|
272
307
|
React.useEffect(()=>{
|
|
273
308
|
if (immediate) {
|
|
274
309
|
savedCallback.current();
|
|
275
310
|
}
|
|
311
|
+
if (controls) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
276
314
|
if (delay !== null) {
|
|
277
|
-
|
|
278
|
-
return ()=>
|
|
315
|
+
resume();
|
|
316
|
+
return ()=>{
|
|
317
|
+
clean();
|
|
318
|
+
};
|
|
279
319
|
}
|
|
280
320
|
return undefined;
|
|
281
321
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -283,6 +323,11 @@ const useInterval = (callback, delay, options = defaultOptions$1)=>{
|
|
|
283
323
|
delay,
|
|
284
324
|
immediate
|
|
285
325
|
]);
|
|
326
|
+
return {
|
|
327
|
+
isActive,
|
|
328
|
+
pause,
|
|
329
|
+
resume
|
|
330
|
+
};
|
|
286
331
|
};
|
|
287
332
|
|
|
288
333
|
const padZero = (time)=>{
|
|
@@ -339,28 +384,6 @@ const useCountDown = (time, format = getHMSTime, callback)=>{
|
|
|
339
384
|
];
|
|
340
385
|
};
|
|
341
386
|
|
|
342
|
-
const useIsomorphicLayoutEffect = isBrowser ? React.useLayoutEffect : React.useEffect;
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* keep function reference immutable
|
|
346
|
-
*/ const useEvent = (fn)=>{
|
|
347
|
-
if (isDev) {
|
|
348
|
-
if (!isFunction(fn)) {
|
|
349
|
-
console.error(`useEvent expected parameter is a function, got ${typeof fn}`);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
const handlerRef = React.useRef(fn);
|
|
353
|
-
useIsomorphicLayoutEffect(()=>{
|
|
354
|
-
handlerRef.current = fn;
|
|
355
|
-
}, [
|
|
356
|
-
fn
|
|
357
|
-
]);
|
|
358
|
-
return React.useCallback((...args)=>{
|
|
359
|
-
const fn = handlerRef.current;
|
|
360
|
-
return fn(...args);
|
|
361
|
-
}, []);
|
|
362
|
-
};
|
|
363
|
-
|
|
364
387
|
const useCounter = (initialValue = 0, max = null, min = null)=>{
|
|
365
388
|
// avoid exec init code every render
|
|
366
389
|
const initFunc = ()=>{
|
|
@@ -1135,7 +1158,7 @@ const useSupported = (callback, sync = false)=>{
|
|
|
1135
1158
|
return supported;
|
|
1136
1159
|
};
|
|
1137
1160
|
|
|
1138
|
-
function asyncGeneratorStep$
|
|
1161
|
+
function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1139
1162
|
try {
|
|
1140
1163
|
var info = gen[key](arg);
|
|
1141
1164
|
var value = info.value;
|
|
@@ -1149,16 +1172,16 @@ function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
1149
1172
|
Promise.resolve(value).then(_next, _throw);
|
|
1150
1173
|
}
|
|
1151
1174
|
}
|
|
1152
|
-
function _async_to_generator$
|
|
1175
|
+
function _async_to_generator$5(fn) {
|
|
1153
1176
|
return function() {
|
|
1154
1177
|
var self = this, args = arguments;
|
|
1155
1178
|
return new Promise(function(resolve, reject) {
|
|
1156
1179
|
var gen = fn.apply(self, args);
|
|
1157
1180
|
function _next(value) {
|
|
1158
|
-
asyncGeneratorStep$
|
|
1181
|
+
asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "next", value);
|
|
1159
1182
|
}
|
|
1160
1183
|
function _throw(err) {
|
|
1161
|
-
asyncGeneratorStep$
|
|
1184
|
+
asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1162
1185
|
}
|
|
1163
1186
|
_next(undefined);
|
|
1164
1187
|
});
|
|
@@ -1166,7 +1189,7 @@ function _async_to_generator$4(fn) {
|
|
|
1166
1189
|
}
|
|
1167
1190
|
const useEyeDropper = ()=>{
|
|
1168
1191
|
const isSupported = useSupported(()=>typeof window !== "undefined" && "EyeDropper" in window, true);
|
|
1169
|
-
const open = React.useCallback(/*#__PURE__*/ _async_to_generator$
|
|
1192
|
+
const open = React.useCallback(/*#__PURE__*/ _async_to_generator$5(function*(options = {}) {
|
|
1170
1193
|
if (!isSupported) {
|
|
1171
1194
|
return {
|
|
1172
1195
|
sRGBHex: ""
|
|
@@ -1201,6 +1224,35 @@ const useFavicon = (href, baseUrl = "", rel = "icon")=>{
|
|
|
1201
1224
|
]);
|
|
1202
1225
|
};
|
|
1203
1226
|
|
|
1227
|
+
function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1228
|
+
try {
|
|
1229
|
+
var info = gen[key](arg);
|
|
1230
|
+
var value = info.value;
|
|
1231
|
+
} catch (error) {
|
|
1232
|
+
reject(error);
|
|
1233
|
+
return;
|
|
1234
|
+
}
|
|
1235
|
+
if (info.done) {
|
|
1236
|
+
resolve(value);
|
|
1237
|
+
} else {
|
|
1238
|
+
Promise.resolve(value).then(_next, _throw);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
function _async_to_generator$4(fn) {
|
|
1242
|
+
return function() {
|
|
1243
|
+
var self = this, args = arguments;
|
|
1244
|
+
return new Promise(function(resolve, reject) {
|
|
1245
|
+
var gen = fn.apply(self, args);
|
|
1246
|
+
function _next(value) {
|
|
1247
|
+
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "next", value);
|
|
1248
|
+
}
|
|
1249
|
+
function _throw(err) {
|
|
1250
|
+
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1251
|
+
}
|
|
1252
|
+
_next(undefined);
|
|
1253
|
+
});
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1204
1256
|
function _extends$2() {
|
|
1205
1257
|
_extends$2 = Object.assign || function(target) {
|
|
1206
1258
|
for(var i = 1; i < arguments.length; i++){
|
|
@@ -1222,6 +1274,8 @@ const DEFAULT_OPTIONS = {
|
|
|
1222
1274
|
const useFileDialog = (options = defaultOptions$1)=>{
|
|
1223
1275
|
const [files, setFiles] = React.useState(null);
|
|
1224
1276
|
const inputRef = React.useRef();
|
|
1277
|
+
const fileOpenPromiseRef = React.useRef(null);
|
|
1278
|
+
const resolveFileOpenPromiseRef = React.useRef();
|
|
1225
1279
|
const initFn = React.useCallback(()=>{
|
|
1226
1280
|
if (typeof document === "undefined") {
|
|
1227
1281
|
return undefined;
|
|
@@ -1231,11 +1285,12 @@ const useFileDialog = (options = defaultOptions$1)=>{
|
|
|
1231
1285
|
input.onchange = (event)=>{
|
|
1232
1286
|
const result = event.target;
|
|
1233
1287
|
setFiles(result.files);
|
|
1288
|
+
resolveFileOpenPromiseRef.current == null ? void 0 : resolveFileOpenPromiseRef.current.call(resolveFileOpenPromiseRef, result.files);
|
|
1234
1289
|
};
|
|
1235
1290
|
return input;
|
|
1236
1291
|
}, []);
|
|
1237
1292
|
inputRef.current = initFn();
|
|
1238
|
-
const open = (localOptions)
|
|
1293
|
+
const open = /*#__PURE__*/ _async_to_generator$4(function*(localOptions) {
|
|
1239
1294
|
if (!inputRef.current) {
|
|
1240
1295
|
return;
|
|
1241
1296
|
}
|
|
@@ -1243,10 +1298,15 @@ const useFileDialog = (options = defaultOptions$1)=>{
|
|
|
1243
1298
|
inputRef.current.multiple = _options.multiple;
|
|
1244
1299
|
inputRef.current.accept = _options.accept;
|
|
1245
1300
|
inputRef.current.capture = _options.capture;
|
|
1301
|
+
fileOpenPromiseRef.current = new Promise((resolve)=>{
|
|
1302
|
+
resolveFileOpenPromiseRef.current = resolve;
|
|
1303
|
+
});
|
|
1246
1304
|
inputRef.current.click();
|
|
1247
|
-
|
|
1305
|
+
return fileOpenPromiseRef.current;
|
|
1306
|
+
});
|
|
1248
1307
|
const reset = ()=>{
|
|
1249
1308
|
setFiles(null);
|
|
1309
|
+
resolveFileOpenPromiseRef.current == null ? void 0 : resolveFileOpenPromiseRef.current.call(resolveFileOpenPromiseRef, null);
|
|
1250
1310
|
if (inputRef.current) {
|
|
1251
1311
|
inputRef.current.value = "";
|
|
1252
1312
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -825,7 +825,7 @@ declare const useFavicon: (href: string, baseUrl?: string, rel?: string) => void
|
|
|
825
825
|
*/
|
|
826
826
|
type UseFileDialog = (options?: UseFileDialogOptions) => readonly [
|
|
827
827
|
FileList | null,
|
|
828
|
-
(localOptions?: Partial<UseFileDialogOptions>) =>
|
|
828
|
+
(localOptions?: Partial<UseFileDialogOptions>) => Promise<FileList | null | undefined>,
|
|
829
829
|
() => void
|
|
830
830
|
];
|
|
831
831
|
/**
|
|
@@ -1323,7 +1323,7 @@ delay?: number | null,
|
|
|
1323
1323
|
* @zh 可选参数
|
|
1324
1324
|
* @en optional params
|
|
1325
1325
|
*/
|
|
1326
|
-
options?: UseIntervalOptions) =>
|
|
1326
|
+
options?: UseIntervalOptions) => Pausable;
|
|
1327
1327
|
/**
|
|
1328
1328
|
* @title UseIntervalOptions
|
|
1329
1329
|
*/
|
|
@@ -1333,6 +1333,31 @@ interface UseIntervalOptions {
|
|
|
1333
1333
|
* @en Whether to execute immediately.
|
|
1334
1334
|
*/
|
|
1335
1335
|
immediate?: boolean;
|
|
1336
|
+
/**
|
|
1337
|
+
* @zh 是否控制执行。
|
|
1338
|
+
* @en Whether to control execution.
|
|
1339
|
+
*/
|
|
1340
|
+
controls?: boolean;
|
|
1341
|
+
}
|
|
1342
|
+
/**
|
|
1343
|
+
* @title Pausable
|
|
1344
|
+
*/
|
|
1345
|
+
interface Pausable {
|
|
1346
|
+
/**
|
|
1347
|
+
* @en A ref indicate whether a pausable instance is active
|
|
1348
|
+
* @zh 一个 ref,指示一个 pausable 实例是否处于激活状态
|
|
1349
|
+
*/
|
|
1350
|
+
isActive: RefObject<boolean>;
|
|
1351
|
+
/**
|
|
1352
|
+
* @en Temporary pause the effect from executing
|
|
1353
|
+
* @zh 暂时暂停执行效果
|
|
1354
|
+
*/
|
|
1355
|
+
pause: () => void;
|
|
1356
|
+
/**
|
|
1357
|
+
* @en Resume the effects
|
|
1358
|
+
* @zh 恢复效果
|
|
1359
|
+
*/
|
|
1360
|
+
resume: () => void;
|
|
1336
1361
|
}
|
|
1337
1362
|
|
|
1338
1363
|
declare const useInterval: UseInterval;
|
|
@@ -2966,4 +2991,4 @@ defauleValue?: boolean) => boolean;
|
|
|
2966
2991
|
*/
|
|
2967
2992
|
type UseMobileLandscape = () => boolean;
|
|
2968
2993
|
|
|
2969
|
-
export { type ColorScheme, type Contrast, type DepsEqualFnType, type EventType, type INetworkInformation, type IUseNetworkState, type KeyModifier, type Platform, type UseActiveElement, type UseAsyncEffect, type UseClickOutside, type UseClipboard, 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 UseDocumentVisibility, type UseDoubleClick, type UseDoubleClickProps, type UseDraggable, type UseDraggableOptions, type UseDropZone, type UseElementBounding, type UseElementBoundingOptions, type UseElementBoundingReturn, type UseElementSize, type UseElementVisibility, type UseEvent, type UseEventEmitter, type UseEventEmitterDisposable, type UseEventEmitterEvent, type UseEventEmitterEventOnce, type UseEventEmitterListener, type UseEventEmitterReturn, type UseEventListener, type UseEyeDropper, type UseEyeDropperOpenOptions, type UseEyeDropperOpenReturnType, type UseFavicon, 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 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 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, defaultOptions, useActiveElement, useAsyncEffect, useClickOutside, useClipboard, useCookie, useCountDown, useCounter, useCssVar, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEyeDropper, useFavicon, useFileDialog, useFirstMountState, useFocus, useFps, useFullscreen, useGeolocation, useHover, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLocationSelector, useLongPress, useMeasure, useMediaDevices, useMediaQuery, useMobileLandscape, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnceEffect, useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePlatform, usePreferredColorScheme, usePreferredContrast, usePreferredDark, 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 };
|
|
2994
|
+
export { type ColorScheme, type Contrast, type DepsEqualFnType, type EventType, type INetworkInformation, type IUseNetworkState, type KeyModifier, type Pausable, type Platform, type UseActiveElement, type UseAsyncEffect, type UseClickOutside, type UseClipboard, 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 UseDocumentVisibility, type UseDoubleClick, type UseDoubleClickProps, type UseDraggable, type UseDraggableOptions, type UseDropZone, type UseElementBounding, type UseElementBoundingOptions, type UseElementBoundingReturn, type UseElementSize, type UseElementVisibility, type UseEvent, type UseEventEmitter, type UseEventEmitterDisposable, type UseEventEmitterEvent, type UseEventEmitterEventOnce, type UseEventEmitterListener, type UseEventEmitterReturn, type UseEventListener, type UseEyeDropper, type UseEyeDropperOpenOptions, type UseEyeDropperOpenReturnType, type UseFavicon, 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 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 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, defaultOptions, useActiveElement, useAsyncEffect, useClickOutside, useClipboard, useCookie, useCountDown, useCounter, useCssVar, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEyeDropper, useFavicon, useFileDialog, useFirstMountState, useFocus, useFps, useFullscreen, useGeolocation, useHover, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLocationSelector, useLongPress, useMeasure, useMediaDevices, useMediaQuery, useMobileLandscape, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnceEffect, useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePlatform, usePreferredColorScheme, usePreferredContrast, usePreferredDark, 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 };
|
package/dist/index.d.mts
CHANGED
|
@@ -825,7 +825,7 @@ declare const useFavicon: (href: string, baseUrl?: string, rel?: string) => void
|
|
|
825
825
|
*/
|
|
826
826
|
type UseFileDialog = (options?: UseFileDialogOptions) => readonly [
|
|
827
827
|
FileList | null,
|
|
828
|
-
(localOptions?: Partial<UseFileDialogOptions>) =>
|
|
828
|
+
(localOptions?: Partial<UseFileDialogOptions>) => Promise<FileList | null | undefined>,
|
|
829
829
|
() => void
|
|
830
830
|
];
|
|
831
831
|
/**
|
|
@@ -1323,7 +1323,7 @@ delay?: number | null,
|
|
|
1323
1323
|
* @zh 可选参数
|
|
1324
1324
|
* @en optional params
|
|
1325
1325
|
*/
|
|
1326
|
-
options?: UseIntervalOptions) =>
|
|
1326
|
+
options?: UseIntervalOptions) => Pausable;
|
|
1327
1327
|
/**
|
|
1328
1328
|
* @title UseIntervalOptions
|
|
1329
1329
|
*/
|
|
@@ -1333,6 +1333,31 @@ interface UseIntervalOptions {
|
|
|
1333
1333
|
* @en Whether to execute immediately.
|
|
1334
1334
|
*/
|
|
1335
1335
|
immediate?: boolean;
|
|
1336
|
+
/**
|
|
1337
|
+
* @zh 是否控制执行。
|
|
1338
|
+
* @en Whether to control execution.
|
|
1339
|
+
*/
|
|
1340
|
+
controls?: boolean;
|
|
1341
|
+
}
|
|
1342
|
+
/**
|
|
1343
|
+
* @title Pausable
|
|
1344
|
+
*/
|
|
1345
|
+
interface Pausable {
|
|
1346
|
+
/**
|
|
1347
|
+
* @en A ref indicate whether a pausable instance is active
|
|
1348
|
+
* @zh 一个 ref,指示一个 pausable 实例是否处于激活状态
|
|
1349
|
+
*/
|
|
1350
|
+
isActive: RefObject<boolean>;
|
|
1351
|
+
/**
|
|
1352
|
+
* @en Temporary pause the effect from executing
|
|
1353
|
+
* @zh 暂时暂停执行效果
|
|
1354
|
+
*/
|
|
1355
|
+
pause: () => void;
|
|
1356
|
+
/**
|
|
1357
|
+
* @en Resume the effects
|
|
1358
|
+
* @zh 恢复效果
|
|
1359
|
+
*/
|
|
1360
|
+
resume: () => void;
|
|
1336
1361
|
}
|
|
1337
1362
|
|
|
1338
1363
|
declare const useInterval: UseInterval;
|
|
@@ -2966,4 +2991,4 @@ defauleValue?: boolean) => boolean;
|
|
|
2966
2991
|
*/
|
|
2967
2992
|
type UseMobileLandscape = () => boolean;
|
|
2968
2993
|
|
|
2969
|
-
export { type ColorScheme, type Contrast, type DepsEqualFnType, type EventType, type INetworkInformation, type IUseNetworkState, type KeyModifier, type Platform, type UseActiveElement, type UseAsyncEffect, type UseClickOutside, type UseClipboard, 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 UseDocumentVisibility, type UseDoubleClick, type UseDoubleClickProps, type UseDraggable, type UseDraggableOptions, type UseDropZone, type UseElementBounding, type UseElementBoundingOptions, type UseElementBoundingReturn, type UseElementSize, type UseElementVisibility, type UseEvent, type UseEventEmitter, type UseEventEmitterDisposable, type UseEventEmitterEvent, type UseEventEmitterEventOnce, type UseEventEmitterListener, type UseEventEmitterReturn, type UseEventListener, type UseEyeDropper, type UseEyeDropperOpenOptions, type UseEyeDropperOpenReturnType, type UseFavicon, 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 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 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, defaultOptions, useActiveElement, useAsyncEffect, useClickOutside, useClipboard, useCookie, useCountDown, useCounter, useCssVar, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEyeDropper, useFavicon, useFileDialog, useFirstMountState, useFocus, useFps, useFullscreen, useGeolocation, useHover, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLocationSelector, useLongPress, useMeasure, useMediaDevices, useMediaQuery, useMobileLandscape, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnceEffect, useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePlatform, usePreferredColorScheme, usePreferredContrast, usePreferredDark, 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 };
|
|
2994
|
+
export { type ColorScheme, type Contrast, type DepsEqualFnType, type EventType, type INetworkInformation, type IUseNetworkState, type KeyModifier, type Pausable, type Platform, type UseActiveElement, type UseAsyncEffect, type UseClickOutside, type UseClipboard, 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 UseDocumentVisibility, type UseDoubleClick, type UseDoubleClickProps, type UseDraggable, type UseDraggableOptions, type UseDropZone, type UseElementBounding, type UseElementBoundingOptions, type UseElementBoundingReturn, type UseElementSize, type UseElementVisibility, type UseEvent, type UseEventEmitter, type UseEventEmitterDisposable, type UseEventEmitterEvent, type UseEventEmitterEventOnce, type UseEventEmitterListener, type UseEventEmitterReturn, type UseEventListener, type UseEyeDropper, type UseEyeDropperOpenOptions, type UseEyeDropperOpenReturnType, type UseFavicon, 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 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 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, defaultOptions, useActiveElement, useAsyncEffect, useClickOutside, useClipboard, useCookie, useCountDown, useCounter, useCssVar, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEyeDropper, useFavicon, useFileDialog, useFirstMountState, useFocus, useFps, useFullscreen, useGeolocation, useHover, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLocationSelector, useLongPress, useMeasure, useMediaDevices, useMediaQuery, useMobileLandscape, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnceEffect, useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePlatform, usePreferredColorScheme, usePreferredContrast, usePreferredDark, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -825,7 +825,7 @@ declare const useFavicon: (href: string, baseUrl?: string, rel?: string) => void
|
|
|
825
825
|
*/
|
|
826
826
|
type UseFileDialog = (options?: UseFileDialogOptions) => readonly [
|
|
827
827
|
FileList | null,
|
|
828
|
-
(localOptions?: Partial<UseFileDialogOptions>) =>
|
|
828
|
+
(localOptions?: Partial<UseFileDialogOptions>) => Promise<FileList | null | undefined>,
|
|
829
829
|
() => void
|
|
830
830
|
];
|
|
831
831
|
/**
|
|
@@ -1323,7 +1323,7 @@ delay?: number | null,
|
|
|
1323
1323
|
* @zh 可选参数
|
|
1324
1324
|
* @en optional params
|
|
1325
1325
|
*/
|
|
1326
|
-
options?: UseIntervalOptions) =>
|
|
1326
|
+
options?: UseIntervalOptions) => Pausable;
|
|
1327
1327
|
/**
|
|
1328
1328
|
* @title UseIntervalOptions
|
|
1329
1329
|
*/
|
|
@@ -1333,6 +1333,31 @@ interface UseIntervalOptions {
|
|
|
1333
1333
|
* @en Whether to execute immediately.
|
|
1334
1334
|
*/
|
|
1335
1335
|
immediate?: boolean;
|
|
1336
|
+
/**
|
|
1337
|
+
* @zh 是否控制执行。
|
|
1338
|
+
* @en Whether to control execution.
|
|
1339
|
+
*/
|
|
1340
|
+
controls?: boolean;
|
|
1341
|
+
}
|
|
1342
|
+
/**
|
|
1343
|
+
* @title Pausable
|
|
1344
|
+
*/
|
|
1345
|
+
interface Pausable {
|
|
1346
|
+
/**
|
|
1347
|
+
* @en A ref indicate whether a pausable instance is active
|
|
1348
|
+
* @zh 一个 ref,指示一个 pausable 实例是否处于激活状态
|
|
1349
|
+
*/
|
|
1350
|
+
isActive: RefObject<boolean>;
|
|
1351
|
+
/**
|
|
1352
|
+
* @en Temporary pause the effect from executing
|
|
1353
|
+
* @zh 暂时暂停执行效果
|
|
1354
|
+
*/
|
|
1355
|
+
pause: () => void;
|
|
1356
|
+
/**
|
|
1357
|
+
* @en Resume the effects
|
|
1358
|
+
* @zh 恢复效果
|
|
1359
|
+
*/
|
|
1360
|
+
resume: () => void;
|
|
1336
1361
|
}
|
|
1337
1362
|
|
|
1338
1363
|
declare const useInterval: UseInterval;
|
|
@@ -2966,4 +2991,4 @@ defauleValue?: boolean) => boolean;
|
|
|
2966
2991
|
*/
|
|
2967
2992
|
type UseMobileLandscape = () => boolean;
|
|
2968
2993
|
|
|
2969
|
-
export { type ColorScheme, type Contrast, type DepsEqualFnType, type EventType, type INetworkInformation, type IUseNetworkState, type KeyModifier, type Platform, type UseActiveElement, type UseAsyncEffect, type UseClickOutside, type UseClipboard, 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 UseDocumentVisibility, type UseDoubleClick, type UseDoubleClickProps, type UseDraggable, type UseDraggableOptions, type UseDropZone, type UseElementBounding, type UseElementBoundingOptions, type UseElementBoundingReturn, type UseElementSize, type UseElementVisibility, type UseEvent, type UseEventEmitter, type UseEventEmitterDisposable, type UseEventEmitterEvent, type UseEventEmitterEventOnce, type UseEventEmitterListener, type UseEventEmitterReturn, type UseEventListener, type UseEyeDropper, type UseEyeDropperOpenOptions, type UseEyeDropperOpenReturnType, type UseFavicon, 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 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 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, defaultOptions, useActiveElement, useAsyncEffect, useClickOutside, useClipboard, useCookie, useCountDown, useCounter, useCssVar, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEyeDropper, useFavicon, useFileDialog, useFirstMountState, useFocus, useFps, useFullscreen, useGeolocation, useHover, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLocationSelector, useLongPress, useMeasure, useMediaDevices, useMediaQuery, useMobileLandscape, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnceEffect, useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePlatform, usePreferredColorScheme, usePreferredContrast, usePreferredDark, 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 };
|
|
2994
|
+
export { type ColorScheme, type Contrast, type DepsEqualFnType, type EventType, type INetworkInformation, type IUseNetworkState, type KeyModifier, type Pausable, type Platform, type UseActiveElement, type UseAsyncEffect, type UseClickOutside, type UseClipboard, 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 UseDocumentVisibility, type UseDoubleClick, type UseDoubleClickProps, type UseDraggable, type UseDraggableOptions, type UseDropZone, type UseElementBounding, type UseElementBoundingOptions, type UseElementBoundingReturn, type UseElementSize, type UseElementVisibility, type UseEvent, type UseEventEmitter, type UseEventEmitterDisposable, type UseEventEmitterEvent, type UseEventEmitterEventOnce, type UseEventEmitterListener, type UseEventEmitterReturn, type UseEventListener, type UseEyeDropper, type UseEyeDropperOpenOptions, type UseEyeDropperOpenReturnType, type UseFavicon, 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 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 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, defaultOptions, useActiveElement, useAsyncEffect, useClickOutside, useClipboard, useCookie, useCountDown, useCounter, useCssVar, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEyeDropper, useFavicon, useFileDialog, useFirstMountState, useFocus, useFps, useFullscreen, useGeolocation, useHover, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLocationSelector, useLongPress, useMeasure, useMediaDevices, useMediaQuery, useMobileLandscape, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnceEffect, useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePlatform, usePreferredColorScheme, usePreferredContrast, usePreferredDark, 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 };
|
package/dist/index.mjs
CHANGED
|
@@ -125,7 +125,7 @@ const useMountedState = ()=>{
|
|
|
125
125
|
return get;
|
|
126
126
|
};
|
|
127
127
|
|
|
128
|
-
function asyncGeneratorStep$
|
|
128
|
+
function asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, key, arg) {
|
|
129
129
|
try {
|
|
130
130
|
var info = gen[key](arg);
|
|
131
131
|
var value = info.value;
|
|
@@ -139,16 +139,16 @@ function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
139
139
|
Promise.resolve(value).then(_next, _throw);
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
function _async_to_generator$
|
|
142
|
+
function _async_to_generator$6(fn) {
|
|
143
143
|
return function() {
|
|
144
144
|
var self = this, args = arguments;
|
|
145
145
|
return new Promise(function(resolve, reject) {
|
|
146
146
|
var gen = fn.apply(self, args);
|
|
147
147
|
function _next(value) {
|
|
148
|
-
asyncGeneratorStep$
|
|
148
|
+
asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, "next", value);
|
|
149
149
|
}
|
|
150
150
|
function _throw(err) {
|
|
151
|
-
asyncGeneratorStep$
|
|
151
|
+
asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, "throw", err);
|
|
152
152
|
}
|
|
153
153
|
_next(undefined);
|
|
154
154
|
});
|
|
@@ -157,7 +157,7 @@ function _async_to_generator$5(fn) {
|
|
|
157
157
|
const useAsyncEffect = (effect, cleanup = noop, deps)=>{
|
|
158
158
|
const mounted = useMountedState();
|
|
159
159
|
useEffect(()=>{
|
|
160
|
-
const execute = /*#__PURE__*/ _async_to_generator$
|
|
160
|
+
const execute = /*#__PURE__*/ _async_to_generator$6(function*() {
|
|
161
161
|
if (!mounted()) {
|
|
162
162
|
return;
|
|
163
163
|
}
|
|
@@ -259,16 +259,56 @@ const useCookie = (key, options = defaultOptions$1, defaultValue)=>{
|
|
|
259
259
|
];
|
|
260
260
|
};
|
|
261
261
|
|
|
262
|
+
const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : useEffect;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* keep function reference immutable
|
|
266
|
+
*/ const useEvent = (fn)=>{
|
|
267
|
+
if (isDev) {
|
|
268
|
+
if (!isFunction(fn)) {
|
|
269
|
+
console.error(`useEvent expected parameter is a function, got ${typeof fn}`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
const handlerRef = useRef(fn);
|
|
273
|
+
useIsomorphicLayoutEffect(()=>{
|
|
274
|
+
handlerRef.current = fn;
|
|
275
|
+
}, [
|
|
276
|
+
fn
|
|
277
|
+
]);
|
|
278
|
+
return useCallback((...args)=>{
|
|
279
|
+
const fn = handlerRef.current;
|
|
280
|
+
return fn(...args);
|
|
281
|
+
}, []);
|
|
282
|
+
};
|
|
283
|
+
|
|
262
284
|
const useInterval = (callback, delay, options = defaultOptions$1)=>{
|
|
263
|
-
const immediate = options
|
|
285
|
+
const { immediate, controls } = options;
|
|
264
286
|
const savedCallback = useLatest(callback);
|
|
287
|
+
const isActive = useRef(false);
|
|
288
|
+
const timer = useRef(null);
|
|
289
|
+
const clean = ()=>{
|
|
290
|
+
timer.current && clearInterval(timer.current);
|
|
291
|
+
};
|
|
292
|
+
const resume = useEvent(()=>{
|
|
293
|
+
isActive.current = true;
|
|
294
|
+
timer.current = setInterval(()=>savedCallback.current(), delay || 0);
|
|
295
|
+
});
|
|
296
|
+
const pause = useEvent(()=>{
|
|
297
|
+
isActive.current = false;
|
|
298
|
+
clean();
|
|
299
|
+
});
|
|
265
300
|
useEffect(()=>{
|
|
266
301
|
if (immediate) {
|
|
267
302
|
savedCallback.current();
|
|
268
303
|
}
|
|
304
|
+
if (controls) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
269
307
|
if (delay !== null) {
|
|
270
|
-
|
|
271
|
-
return ()=>
|
|
308
|
+
resume();
|
|
309
|
+
return ()=>{
|
|
310
|
+
clean();
|
|
311
|
+
};
|
|
272
312
|
}
|
|
273
313
|
return undefined;
|
|
274
314
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -276,6 +316,11 @@ const useInterval = (callback, delay, options = defaultOptions$1)=>{
|
|
|
276
316
|
delay,
|
|
277
317
|
immediate
|
|
278
318
|
]);
|
|
319
|
+
return {
|
|
320
|
+
isActive,
|
|
321
|
+
pause,
|
|
322
|
+
resume
|
|
323
|
+
};
|
|
279
324
|
};
|
|
280
325
|
|
|
281
326
|
const padZero = (time)=>{
|
|
@@ -332,28 +377,6 @@ const useCountDown = (time, format = getHMSTime, callback)=>{
|
|
|
332
377
|
];
|
|
333
378
|
};
|
|
334
379
|
|
|
335
|
-
const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : useEffect;
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* keep function reference immutable
|
|
339
|
-
*/ const useEvent = (fn)=>{
|
|
340
|
-
if (isDev) {
|
|
341
|
-
if (!isFunction(fn)) {
|
|
342
|
-
console.error(`useEvent expected parameter is a function, got ${typeof fn}`);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
const handlerRef = useRef(fn);
|
|
346
|
-
useIsomorphicLayoutEffect(()=>{
|
|
347
|
-
handlerRef.current = fn;
|
|
348
|
-
}, [
|
|
349
|
-
fn
|
|
350
|
-
]);
|
|
351
|
-
return useCallback((...args)=>{
|
|
352
|
-
const fn = handlerRef.current;
|
|
353
|
-
return fn(...args);
|
|
354
|
-
}, []);
|
|
355
|
-
};
|
|
356
|
-
|
|
357
380
|
const useCounter = (initialValue = 0, max = null, min = null)=>{
|
|
358
381
|
// avoid exec init code every render
|
|
359
382
|
const initFunc = ()=>{
|
|
@@ -1128,7 +1151,7 @@ const useSupported = (callback, sync = false)=>{
|
|
|
1128
1151
|
return supported;
|
|
1129
1152
|
};
|
|
1130
1153
|
|
|
1131
|
-
function asyncGeneratorStep$
|
|
1154
|
+
function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1132
1155
|
try {
|
|
1133
1156
|
var info = gen[key](arg);
|
|
1134
1157
|
var value = info.value;
|
|
@@ -1142,16 +1165,16 @@ function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
1142
1165
|
Promise.resolve(value).then(_next, _throw);
|
|
1143
1166
|
}
|
|
1144
1167
|
}
|
|
1145
|
-
function _async_to_generator$
|
|
1168
|
+
function _async_to_generator$5(fn) {
|
|
1146
1169
|
return function() {
|
|
1147
1170
|
var self = this, args = arguments;
|
|
1148
1171
|
return new Promise(function(resolve, reject) {
|
|
1149
1172
|
var gen = fn.apply(self, args);
|
|
1150
1173
|
function _next(value) {
|
|
1151
|
-
asyncGeneratorStep$
|
|
1174
|
+
asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "next", value);
|
|
1152
1175
|
}
|
|
1153
1176
|
function _throw(err) {
|
|
1154
|
-
asyncGeneratorStep$
|
|
1177
|
+
asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1155
1178
|
}
|
|
1156
1179
|
_next(undefined);
|
|
1157
1180
|
});
|
|
@@ -1159,7 +1182,7 @@ function _async_to_generator$4(fn) {
|
|
|
1159
1182
|
}
|
|
1160
1183
|
const useEyeDropper = ()=>{
|
|
1161
1184
|
const isSupported = useSupported(()=>typeof window !== "undefined" && "EyeDropper" in window, true);
|
|
1162
|
-
const open = useCallback(/*#__PURE__*/ _async_to_generator$
|
|
1185
|
+
const open = useCallback(/*#__PURE__*/ _async_to_generator$5(function*(options = {}) {
|
|
1163
1186
|
if (!isSupported) {
|
|
1164
1187
|
return {
|
|
1165
1188
|
sRGBHex: ""
|
|
@@ -1194,6 +1217,35 @@ const useFavicon = (href, baseUrl = "", rel = "icon")=>{
|
|
|
1194
1217
|
]);
|
|
1195
1218
|
};
|
|
1196
1219
|
|
|
1220
|
+
function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1221
|
+
try {
|
|
1222
|
+
var info = gen[key](arg);
|
|
1223
|
+
var value = info.value;
|
|
1224
|
+
} catch (error) {
|
|
1225
|
+
reject(error);
|
|
1226
|
+
return;
|
|
1227
|
+
}
|
|
1228
|
+
if (info.done) {
|
|
1229
|
+
resolve(value);
|
|
1230
|
+
} else {
|
|
1231
|
+
Promise.resolve(value).then(_next, _throw);
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
function _async_to_generator$4(fn) {
|
|
1235
|
+
return function() {
|
|
1236
|
+
var self = this, args = arguments;
|
|
1237
|
+
return new Promise(function(resolve, reject) {
|
|
1238
|
+
var gen = fn.apply(self, args);
|
|
1239
|
+
function _next(value) {
|
|
1240
|
+
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "next", value);
|
|
1241
|
+
}
|
|
1242
|
+
function _throw(err) {
|
|
1243
|
+
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1244
|
+
}
|
|
1245
|
+
_next(undefined);
|
|
1246
|
+
});
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1197
1249
|
function _extends$2() {
|
|
1198
1250
|
_extends$2 = Object.assign || function(target) {
|
|
1199
1251
|
for(var i = 1; i < arguments.length; i++){
|
|
@@ -1215,6 +1267,8 @@ const DEFAULT_OPTIONS = {
|
|
|
1215
1267
|
const useFileDialog = (options = defaultOptions$1)=>{
|
|
1216
1268
|
const [files, setFiles] = useState(null);
|
|
1217
1269
|
const inputRef = useRef();
|
|
1270
|
+
const fileOpenPromiseRef = useRef(null);
|
|
1271
|
+
const resolveFileOpenPromiseRef = useRef();
|
|
1218
1272
|
const initFn = useCallback(()=>{
|
|
1219
1273
|
if (typeof document === "undefined") {
|
|
1220
1274
|
return undefined;
|
|
@@ -1224,11 +1278,12 @@ const useFileDialog = (options = defaultOptions$1)=>{
|
|
|
1224
1278
|
input.onchange = (event)=>{
|
|
1225
1279
|
const result = event.target;
|
|
1226
1280
|
setFiles(result.files);
|
|
1281
|
+
resolveFileOpenPromiseRef.current == null ? void 0 : resolveFileOpenPromiseRef.current.call(resolveFileOpenPromiseRef, result.files);
|
|
1227
1282
|
};
|
|
1228
1283
|
return input;
|
|
1229
1284
|
}, []);
|
|
1230
1285
|
inputRef.current = initFn();
|
|
1231
|
-
const open = (localOptions)
|
|
1286
|
+
const open = /*#__PURE__*/ _async_to_generator$4(function*(localOptions) {
|
|
1232
1287
|
if (!inputRef.current) {
|
|
1233
1288
|
return;
|
|
1234
1289
|
}
|
|
@@ -1236,10 +1291,15 @@ const useFileDialog = (options = defaultOptions$1)=>{
|
|
|
1236
1291
|
inputRef.current.multiple = _options.multiple;
|
|
1237
1292
|
inputRef.current.accept = _options.accept;
|
|
1238
1293
|
inputRef.current.capture = _options.capture;
|
|
1294
|
+
fileOpenPromiseRef.current = new Promise((resolve)=>{
|
|
1295
|
+
resolveFileOpenPromiseRef.current = resolve;
|
|
1296
|
+
});
|
|
1239
1297
|
inputRef.current.click();
|
|
1240
|
-
|
|
1298
|
+
return fileOpenPromiseRef.current;
|
|
1299
|
+
});
|
|
1241
1300
|
const reset = ()=>{
|
|
1242
1301
|
setFiles(null);
|
|
1302
|
+
resolveFileOpenPromiseRef.current == null ? void 0 : resolveFileOpenPromiseRef.current.call(resolveFileOpenPromiseRef, null);
|
|
1243
1303
|
if (inputRef.current) {
|
|
1244
1304
|
inputRef.current.value = "";
|
|
1245
1305
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactuses/core",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.13",
|
|
4
4
|
"license": "Unlicense",
|
|
5
5
|
"homepage": "https://www.reactuse.com/",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/childrentime/reactuse",
|
|
8
|
+
"url": "git+https://github.com/childrentime/reactuse.git",
|
|
9
9
|
"directory": "packages/core"
|
|
10
10
|
},
|
|
11
11
|
"bugs": {
|
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
"esbuild-register": "^3.4.1",
|
|
79
79
|
"jest": "^29.0.2",
|
|
80
80
|
"jest-environment-jsdom": "^29.0.2",
|
|
81
|
+
"jest-environment-node": "^29.7.0",
|
|
81
82
|
"lodash": "^4.17.21",
|
|
82
83
|
"react": "^18.2.0",
|
|
83
84
|
"react-dom": "^18.2.0",
|