@reactuses/core 5.0.7 → 5.0.9
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 +58 -3
- package/dist/index.d.cts +55 -1
- package/dist/index.d.mts +55 -1
- package/dist/index.d.ts +55 -1
- package/dist/index.mjs +57 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1601,7 +1601,6 @@ const useScroll = (target, options = defaultOptions$1)=>{
|
|
|
1601
1601
|
onStop(e);
|
|
1602
1602
|
}, throttle + idle);
|
|
1603
1603
|
const onScrollHandler = useEvent((e)=>{
|
|
1604
|
-
console.log("??? scroll");
|
|
1605
1604
|
const eventTarget = e.target === document ? e.target.documentElement : e.target;
|
|
1606
1605
|
const scrollLeft = eventTarget.scrollLeft;
|
|
1607
1606
|
let scrollTop = eventTarget.scrollTop;
|
|
@@ -1627,7 +1626,6 @@ const useScroll = (target, options = defaultOptions$1)=>{
|
|
|
1627
1626
|
});
|
|
1628
1627
|
const { run: throttleOnScroll } = useThrottleFn(onScrollHandler, throttle);
|
|
1629
1628
|
useEventListener("scroll", throttle ? throttleOnScroll : onScrollHandler, target, eventListenerOptions);
|
|
1630
|
-
console.log("123", target);
|
|
1631
1629
|
return [
|
|
1632
1630
|
x,
|
|
1633
1631
|
y,
|
|
@@ -3102,7 +3100,7 @@ const useWindowScroll = ()=>{
|
|
|
3102
3100
|
y: window.scrollY
|
|
3103
3101
|
});
|
|
3104
3102
|
};
|
|
3105
|
-
useEventListener("scroll", handleScroll,
|
|
3103
|
+
useEventListener("scroll", handleScroll, defaultWindow, listenerOptions);
|
|
3106
3104
|
// Set scroll at the first client-side load
|
|
3107
3105
|
useIsomorphicLayoutEffect(()=>{
|
|
3108
3106
|
handleScroll();
|
|
@@ -3204,6 +3202,61 @@ const useClipboard = ()=>{
|
|
|
3204
3202
|
];
|
|
3205
3203
|
};
|
|
3206
3204
|
|
|
3205
|
+
const getPlatform = (userAgent)=>{
|
|
3206
|
+
if (/iPad|iPhone|iPod|ios/i.test(userAgent)) {
|
|
3207
|
+
return "ios";
|
|
3208
|
+
} else if (/android/i.test(userAgent)) {
|
|
3209
|
+
return "android";
|
|
3210
|
+
} else {
|
|
3211
|
+
return "unknown";
|
|
3212
|
+
}
|
|
3213
|
+
};
|
|
3214
|
+
const usePlatform = ({ userAgent } = {
|
|
3215
|
+
userAgent: ""
|
|
3216
|
+
})=>{
|
|
3217
|
+
const [ua, setUa] = React.useState(userAgent || "");
|
|
3218
|
+
const [platform, setPlatform] = React.useState(()=>{
|
|
3219
|
+
if (userAgent) {
|
|
3220
|
+
return getPlatform(userAgent);
|
|
3221
|
+
}
|
|
3222
|
+
return "unknown";
|
|
3223
|
+
});
|
|
3224
|
+
React.useEffect(()=>{
|
|
3225
|
+
setPlatform(getPlatform(navigator.userAgent));
|
|
3226
|
+
setUa(navigator.userAgent);
|
|
3227
|
+
}, []);
|
|
3228
|
+
const isInMiniProgram = React.useCallback(()=>{
|
|
3229
|
+
return /miniprogram/i.test(ua);
|
|
3230
|
+
}, [
|
|
3231
|
+
ua
|
|
3232
|
+
]);
|
|
3233
|
+
const isInWechat = React.useCallback(()=>{
|
|
3234
|
+
return /micromessenger/i.test(ua);
|
|
3235
|
+
}, []);
|
|
3236
|
+
const isiPhoneX = React.useCallback(()=>{
|
|
3237
|
+
return /iPhoneX/i.test(ua);
|
|
3238
|
+
}, []);
|
|
3239
|
+
return {
|
|
3240
|
+
platform,
|
|
3241
|
+
isInMiniProgram,
|
|
3242
|
+
isInWechat,
|
|
3243
|
+
isiPhoneX
|
|
3244
|
+
};
|
|
3245
|
+
};
|
|
3246
|
+
|
|
3247
|
+
const useMobileLandscape = ()=>{
|
|
3248
|
+
const [isMobileLandscape, setIsMobileLandscape] = React.useState(false);
|
|
3249
|
+
const [orientation] = useOrientation();
|
|
3250
|
+
React.useEffect(()=>{
|
|
3251
|
+
const userAgent = window.navigator.userAgent;
|
|
3252
|
+
const isMobile = /Mobi|Android|iphone/i.test(userAgent);
|
|
3253
|
+
setIsMobileLandscape(isMobile && orientation.type === "landscape-primary");
|
|
3254
|
+
}, [
|
|
3255
|
+
orientation.type
|
|
3256
|
+
]);
|
|
3257
|
+
return isMobileLandscape;
|
|
3258
|
+
};
|
|
3259
|
+
|
|
3207
3260
|
exports.defaultOptions = defaultOptions;
|
|
3208
3261
|
exports.useActiveElement = useActiveElement;
|
|
3209
3262
|
exports.useAsyncEffect = useAsyncEffect;
|
|
@@ -3251,6 +3304,7 @@ exports.useLongPress = useLongPress;
|
|
|
3251
3304
|
exports.useMeasure = useMeasure;
|
|
3252
3305
|
exports.useMediaDevices = useMediaDevices;
|
|
3253
3306
|
exports.useMediaQuery = useMediaQuery;
|
|
3307
|
+
exports.useMobileLandscape = useMobileLandscape;
|
|
3254
3308
|
exports.useMount = useMount;
|
|
3255
3309
|
exports.useMountedState = useMountedState;
|
|
3256
3310
|
exports.useMouse = useMouse;
|
|
@@ -3264,6 +3318,7 @@ exports.useOnline = useOnline;
|
|
|
3264
3318
|
exports.useOrientation = useOrientation;
|
|
3265
3319
|
exports.usePageLeave = usePageLeave;
|
|
3266
3320
|
exports.usePermission = usePermission;
|
|
3321
|
+
exports.usePlatform = usePlatform;
|
|
3267
3322
|
exports.usePreferredColorScheme = usePreferredColorScheme;
|
|
3268
3323
|
exports.usePreferredContrast = usePreferredContrast;
|
|
3269
3324
|
exports.usePreferredDark = usePreferredDark;
|
package/dist/index.d.cts
CHANGED
|
@@ -2567,6 +2567,53 @@ type UseClipboard = () => readonly [string, (txt: string) => Promise<void>];
|
|
|
2567
2567
|
|
|
2568
2568
|
declare const useClipboard: UseClipboard;
|
|
2569
2569
|
|
|
2570
|
+
type Platform = "ios" | "android" | "unknown";
|
|
2571
|
+
/**
|
|
2572
|
+
* @title UsePlatformProps
|
|
2573
|
+
*/
|
|
2574
|
+
interface UsePlatformProps {
|
|
2575
|
+
/**
|
|
2576
|
+
* @zh 服务端渲染时,需要传递 `userAgent`
|
|
2577
|
+
* @en When server rendering, you need to pass `userAgent`
|
|
2578
|
+
*/
|
|
2579
|
+
userAgent?: string;
|
|
2580
|
+
}
|
|
2581
|
+
/**
|
|
2582
|
+
* @title usePlatform
|
|
2583
|
+
* @returns 和平台相关的对象
|
|
2584
|
+
* @returns_en object that related to platform
|
|
2585
|
+
*/
|
|
2586
|
+
type UsePlatform = (props?: UsePlatformProps) => UsePlatformReturn;
|
|
2587
|
+
/**
|
|
2588
|
+
* @title UsePlatformReturn
|
|
2589
|
+
*/
|
|
2590
|
+
interface UsePlatformReturn {
|
|
2591
|
+
/**
|
|
2592
|
+
* @zh 平台
|
|
2593
|
+
* @en platform
|
|
2594
|
+
*/
|
|
2595
|
+
platform: Platform;
|
|
2596
|
+
/**
|
|
2597
|
+
* @zh 是否在小程序中
|
|
2598
|
+
* @en Whether in mini program
|
|
2599
|
+
*/
|
|
2600
|
+
isInMiniProgram: () => boolean;
|
|
2601
|
+
/**
|
|
2602
|
+
* @zh 是否在微信中
|
|
2603
|
+
* @en whether in wechat
|
|
2604
|
+
*/
|
|
2605
|
+
isInWechat: () => boolean;
|
|
2606
|
+
/**
|
|
2607
|
+
* @zh 是否是 iPhoneX
|
|
2608
|
+
* @en whether is iPhoneX
|
|
2609
|
+
*/
|
|
2610
|
+
isiPhoneX: () => boolean;
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2613
|
+
declare const usePlatform: UsePlatform;
|
|
2614
|
+
|
|
2615
|
+
declare const useMobileLandscape: () => boolean;
|
|
2616
|
+
|
|
2570
2617
|
/**
|
|
2571
2618
|
* @title useDocumentVisiblity
|
|
2572
2619
|
* @returns_en document visibility
|
|
@@ -2912,4 +2959,11 @@ type UseWindowsFocus = (
|
|
|
2912
2959
|
*/
|
|
2913
2960
|
defauleValue?: boolean) => boolean;
|
|
2914
2961
|
|
|
2915
|
-
|
|
2962
|
+
/**
|
|
2963
|
+
* @title useMobileLandscape
|
|
2964
|
+
* @returns 是否是移动端横屏
|
|
2965
|
+
* @returns_en whether is mobile landscape
|
|
2966
|
+
*/
|
|
2967
|
+
type UseMobileLandscape = () => boolean;
|
|
2968
|
+
|
|
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 };
|
package/dist/index.d.mts
CHANGED
|
@@ -2567,6 +2567,53 @@ type UseClipboard = () => readonly [string, (txt: string) => Promise<void>];
|
|
|
2567
2567
|
|
|
2568
2568
|
declare const useClipboard: UseClipboard;
|
|
2569
2569
|
|
|
2570
|
+
type Platform = "ios" | "android" | "unknown";
|
|
2571
|
+
/**
|
|
2572
|
+
* @title UsePlatformProps
|
|
2573
|
+
*/
|
|
2574
|
+
interface UsePlatformProps {
|
|
2575
|
+
/**
|
|
2576
|
+
* @zh 服务端渲染时,需要传递 `userAgent`
|
|
2577
|
+
* @en When server rendering, you need to pass `userAgent`
|
|
2578
|
+
*/
|
|
2579
|
+
userAgent?: string;
|
|
2580
|
+
}
|
|
2581
|
+
/**
|
|
2582
|
+
* @title usePlatform
|
|
2583
|
+
* @returns 和平台相关的对象
|
|
2584
|
+
* @returns_en object that related to platform
|
|
2585
|
+
*/
|
|
2586
|
+
type UsePlatform = (props?: UsePlatformProps) => UsePlatformReturn;
|
|
2587
|
+
/**
|
|
2588
|
+
* @title UsePlatformReturn
|
|
2589
|
+
*/
|
|
2590
|
+
interface UsePlatformReturn {
|
|
2591
|
+
/**
|
|
2592
|
+
* @zh 平台
|
|
2593
|
+
* @en platform
|
|
2594
|
+
*/
|
|
2595
|
+
platform: Platform;
|
|
2596
|
+
/**
|
|
2597
|
+
* @zh 是否在小程序中
|
|
2598
|
+
* @en Whether in mini program
|
|
2599
|
+
*/
|
|
2600
|
+
isInMiniProgram: () => boolean;
|
|
2601
|
+
/**
|
|
2602
|
+
* @zh 是否在微信中
|
|
2603
|
+
* @en whether in wechat
|
|
2604
|
+
*/
|
|
2605
|
+
isInWechat: () => boolean;
|
|
2606
|
+
/**
|
|
2607
|
+
* @zh 是否是 iPhoneX
|
|
2608
|
+
* @en whether is iPhoneX
|
|
2609
|
+
*/
|
|
2610
|
+
isiPhoneX: () => boolean;
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2613
|
+
declare const usePlatform: UsePlatform;
|
|
2614
|
+
|
|
2615
|
+
declare const useMobileLandscape: () => boolean;
|
|
2616
|
+
|
|
2570
2617
|
/**
|
|
2571
2618
|
* @title useDocumentVisiblity
|
|
2572
2619
|
* @returns_en document visibility
|
|
@@ -2912,4 +2959,11 @@ type UseWindowsFocus = (
|
|
|
2912
2959
|
*/
|
|
2913
2960
|
defauleValue?: boolean) => boolean;
|
|
2914
2961
|
|
|
2915
|
-
|
|
2962
|
+
/**
|
|
2963
|
+
* @title useMobileLandscape
|
|
2964
|
+
* @returns 是否是移动端横屏
|
|
2965
|
+
* @returns_en whether is mobile landscape
|
|
2966
|
+
*/
|
|
2967
|
+
type UseMobileLandscape = () => boolean;
|
|
2968
|
+
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -2567,6 +2567,53 @@ type UseClipboard = () => readonly [string, (txt: string) => Promise<void>];
|
|
|
2567
2567
|
|
|
2568
2568
|
declare const useClipboard: UseClipboard;
|
|
2569
2569
|
|
|
2570
|
+
type Platform = "ios" | "android" | "unknown";
|
|
2571
|
+
/**
|
|
2572
|
+
* @title UsePlatformProps
|
|
2573
|
+
*/
|
|
2574
|
+
interface UsePlatformProps {
|
|
2575
|
+
/**
|
|
2576
|
+
* @zh 服务端渲染时,需要传递 `userAgent`
|
|
2577
|
+
* @en When server rendering, you need to pass `userAgent`
|
|
2578
|
+
*/
|
|
2579
|
+
userAgent?: string;
|
|
2580
|
+
}
|
|
2581
|
+
/**
|
|
2582
|
+
* @title usePlatform
|
|
2583
|
+
* @returns 和平台相关的对象
|
|
2584
|
+
* @returns_en object that related to platform
|
|
2585
|
+
*/
|
|
2586
|
+
type UsePlatform = (props?: UsePlatformProps) => UsePlatformReturn;
|
|
2587
|
+
/**
|
|
2588
|
+
* @title UsePlatformReturn
|
|
2589
|
+
*/
|
|
2590
|
+
interface UsePlatformReturn {
|
|
2591
|
+
/**
|
|
2592
|
+
* @zh 平台
|
|
2593
|
+
* @en platform
|
|
2594
|
+
*/
|
|
2595
|
+
platform: Platform;
|
|
2596
|
+
/**
|
|
2597
|
+
* @zh 是否在小程序中
|
|
2598
|
+
* @en Whether in mini program
|
|
2599
|
+
*/
|
|
2600
|
+
isInMiniProgram: () => boolean;
|
|
2601
|
+
/**
|
|
2602
|
+
* @zh 是否在微信中
|
|
2603
|
+
* @en whether in wechat
|
|
2604
|
+
*/
|
|
2605
|
+
isInWechat: () => boolean;
|
|
2606
|
+
/**
|
|
2607
|
+
* @zh 是否是 iPhoneX
|
|
2608
|
+
* @en whether is iPhoneX
|
|
2609
|
+
*/
|
|
2610
|
+
isiPhoneX: () => boolean;
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2613
|
+
declare const usePlatform: UsePlatform;
|
|
2614
|
+
|
|
2615
|
+
declare const useMobileLandscape: () => boolean;
|
|
2616
|
+
|
|
2570
2617
|
/**
|
|
2571
2618
|
* @title useDocumentVisiblity
|
|
2572
2619
|
* @returns_en document visibility
|
|
@@ -2912,4 +2959,11 @@ type UseWindowsFocus = (
|
|
|
2912
2959
|
*/
|
|
2913
2960
|
defauleValue?: boolean) => boolean;
|
|
2914
2961
|
|
|
2915
|
-
|
|
2962
|
+
/**
|
|
2963
|
+
* @title useMobileLandscape
|
|
2964
|
+
* @returns 是否是移动端横屏
|
|
2965
|
+
* @returns_en whether is mobile landscape
|
|
2966
|
+
*/
|
|
2967
|
+
type UseMobileLandscape = () => boolean;
|
|
2968
|
+
|
|
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -1594,7 +1594,6 @@ const useScroll = (target, options = defaultOptions$1)=>{
|
|
|
1594
1594
|
onStop(e);
|
|
1595
1595
|
}, throttle + idle);
|
|
1596
1596
|
const onScrollHandler = useEvent((e)=>{
|
|
1597
|
-
console.log("??? scroll");
|
|
1598
1597
|
const eventTarget = e.target === document ? e.target.documentElement : e.target;
|
|
1599
1598
|
const scrollLeft = eventTarget.scrollLeft;
|
|
1600
1599
|
let scrollTop = eventTarget.scrollTop;
|
|
@@ -1620,7 +1619,6 @@ const useScroll = (target, options = defaultOptions$1)=>{
|
|
|
1620
1619
|
});
|
|
1621
1620
|
const { run: throttleOnScroll } = useThrottleFn(onScrollHandler, throttle);
|
|
1622
1621
|
useEventListener("scroll", throttle ? throttleOnScroll : onScrollHandler, target, eventListenerOptions);
|
|
1623
|
-
console.log("123", target);
|
|
1624
1622
|
return [
|
|
1625
1623
|
x,
|
|
1626
1624
|
y,
|
|
@@ -3095,7 +3093,7 @@ const useWindowScroll = ()=>{
|
|
|
3095
3093
|
y: window.scrollY
|
|
3096
3094
|
});
|
|
3097
3095
|
};
|
|
3098
|
-
useEventListener("scroll", handleScroll,
|
|
3096
|
+
useEventListener("scroll", handleScroll, defaultWindow, listenerOptions);
|
|
3099
3097
|
// Set scroll at the first client-side load
|
|
3100
3098
|
useIsomorphicLayoutEffect(()=>{
|
|
3101
3099
|
handleScroll();
|
|
@@ -3197,4 +3195,59 @@ const useClipboard = ()=>{
|
|
|
3197
3195
|
];
|
|
3198
3196
|
};
|
|
3199
3197
|
|
|
3200
|
-
|
|
3198
|
+
const getPlatform = (userAgent)=>{
|
|
3199
|
+
if (/iPad|iPhone|iPod|ios/i.test(userAgent)) {
|
|
3200
|
+
return "ios";
|
|
3201
|
+
} else if (/android/i.test(userAgent)) {
|
|
3202
|
+
return "android";
|
|
3203
|
+
} else {
|
|
3204
|
+
return "unknown";
|
|
3205
|
+
}
|
|
3206
|
+
};
|
|
3207
|
+
const usePlatform = ({ userAgent } = {
|
|
3208
|
+
userAgent: ""
|
|
3209
|
+
})=>{
|
|
3210
|
+
const [ua, setUa] = useState(userAgent || "");
|
|
3211
|
+
const [platform, setPlatform] = useState(()=>{
|
|
3212
|
+
if (userAgent) {
|
|
3213
|
+
return getPlatform(userAgent);
|
|
3214
|
+
}
|
|
3215
|
+
return "unknown";
|
|
3216
|
+
});
|
|
3217
|
+
useEffect(()=>{
|
|
3218
|
+
setPlatform(getPlatform(navigator.userAgent));
|
|
3219
|
+
setUa(navigator.userAgent);
|
|
3220
|
+
}, []);
|
|
3221
|
+
const isInMiniProgram = useCallback(()=>{
|
|
3222
|
+
return /miniprogram/i.test(ua);
|
|
3223
|
+
}, [
|
|
3224
|
+
ua
|
|
3225
|
+
]);
|
|
3226
|
+
const isInWechat = useCallback(()=>{
|
|
3227
|
+
return /micromessenger/i.test(ua);
|
|
3228
|
+
}, []);
|
|
3229
|
+
const isiPhoneX = useCallback(()=>{
|
|
3230
|
+
return /iPhoneX/i.test(ua);
|
|
3231
|
+
}, []);
|
|
3232
|
+
return {
|
|
3233
|
+
platform,
|
|
3234
|
+
isInMiniProgram,
|
|
3235
|
+
isInWechat,
|
|
3236
|
+
isiPhoneX
|
|
3237
|
+
};
|
|
3238
|
+
};
|
|
3239
|
+
|
|
3240
|
+
const useMobileLandscape = ()=>{
|
|
3241
|
+
const [isMobileLandscape, setIsMobileLandscape] = useState(false);
|
|
3242
|
+
const [orientation] = useOrientation();
|
|
3243
|
+
useEffect(()=>{
|
|
3244
|
+
const userAgent = window.navigator.userAgent;
|
|
3245
|
+
const isMobile = /Mobi|Android|iphone/i.test(userAgent);
|
|
3246
|
+
setIsMobileLandscape(isMobile && orientation.type === "landscape-primary");
|
|
3247
|
+
}, [
|
|
3248
|
+
orientation.type
|
|
3249
|
+
]);
|
|
3250
|
+
return isMobileLandscape;
|
|
3251
|
+
};
|
|
3252
|
+
|
|
3253
|
+
export { 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 };
|