@reactuses/core 2.2.6 → 2.2.8
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 +2659 -30
- package/dist/index.d.ts +43 -25
- package/dist/index.mjs +2658 -30
- package/package.json +6 -20
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import react__default, { MutableRefObject, useEffect, useLayoutEffect, Dispatch, SetStateAction, DependencyList, EffectCallback, RefObject, CSSProperties } from 'react';
|
|
3
|
-
import lodash from 'lodash';
|
|
3
|
+
import * as lodash from 'lodash';
|
|
4
|
+
import Cookies from 'js-cookie';
|
|
4
5
|
|
|
5
6
|
declare function usePrevious<T>(state: T): T | undefined;
|
|
6
7
|
|
|
@@ -45,9 +46,9 @@ declare function useSessionStorage(key: string, defaults: boolean, options?: Use
|
|
|
45
46
|
declare function useSessionStorage<T>(key: string, defaults: T, options?: UseStorageOptions<T>): readonly [T | null, Dispatch<SetStateAction<T | null>>];
|
|
46
47
|
declare function useSessionStorage<T = unknown>(key: string, defaults: null, options?: UseStorageOptions<T>): readonly [T | null, Dispatch<SetStateAction<T | null>>];
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
type Fn = (this: any, ...args: any[]) => any;
|
|
50
|
+
type Stoppable = [boolean, Fn, Fn];
|
|
51
|
+
type PointerType = "mouse" | "touch" | "pen";
|
|
51
52
|
interface Position {
|
|
52
53
|
x: number;
|
|
53
54
|
y: number;
|
|
@@ -166,11 +167,11 @@ declare function useTimeout(ms?: number, options?: UseTimeoutFnOptions): Stoppab
|
|
|
166
167
|
|
|
167
168
|
declare function useMountedState(): () => boolean;
|
|
168
169
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
type TargetValue<T> = T | undefined | null;
|
|
171
|
+
type TargetType = HTMLElement | Element | Window | Document | EventTarget;
|
|
172
|
+
type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>;
|
|
172
173
|
|
|
173
|
-
|
|
174
|
+
type Target = BasicTarget<HTMLElement | Element | Window | Document | EventTarget>;
|
|
174
175
|
declare function useEventListener<K extends keyof WindowEventMap>(eventName: K, handler: (event: WindowEventMap[K]) => void, element?: Window, options?: boolean | AddEventListenerOptions): void;
|
|
175
176
|
declare function useEventListener<K extends keyof DocumentEventMap>(eventName: K, handler: (event: DocumentEventMap[K]) => void, element: Document, options?: boolean | AddEventListenerOptions): void;
|
|
176
177
|
declare function useEventListener<K extends keyof HTMLElementEventMap, T extends HTMLElement = HTMLDivElement>(eventName: K, handler: (event: HTMLElementEventMap[K]) => void, element: T, options?: boolean | AddEventListenerOptions): void;
|
|
@@ -180,7 +181,7 @@ declare function useEventListener(eventName: string, handler: (...p: any) => voi
|
|
|
180
181
|
|
|
181
182
|
declare function useCounter(initialValue?: number | (() => number), max?: number | null, min?: number | null): readonly [number, (newState: number | ((prev: number) => number) | (() => number)) => void, (delta?: number) => void, (delta?: number) => void, () => void];
|
|
182
183
|
|
|
183
|
-
|
|
184
|
+
type RafLoopReturns = readonly [() => void, () => void, () => boolean];
|
|
184
185
|
declare function useRafFn(callback: FrameRequestCallback, initiallyActive?: boolean): RafLoopReturns;
|
|
185
186
|
|
|
186
187
|
interface IListener<T, U = void> {
|
|
@@ -218,7 +219,7 @@ declare function useFavicon(href: string, baseUrl?: string, rel?: string): void;
|
|
|
218
219
|
|
|
219
220
|
declare function useMutationObserver(callback: MutationCallback, target: BasicTarget, options?: MutationObserverInit): () => void;
|
|
220
221
|
|
|
221
|
-
|
|
222
|
+
type DepsEqualFnType<TDeps extends DependencyList> = (prevDeps: TDeps, nextDeps: TDeps) => boolean;
|
|
222
223
|
declare function useCustomCompareEffect<TDeps extends DependencyList>(effect: EffectCallback, deps: TDeps, depsEqual: DepsEqualFnType<TDeps>): void;
|
|
223
224
|
|
|
224
225
|
declare function useDeepCompareEffect(effect: EffectCallback, deps: DependencyList): void;
|
|
@@ -260,12 +261,12 @@ interface UseScriptTagOptions {
|
|
|
260
261
|
*/
|
|
261
262
|
attrs?: Record<string, string>;
|
|
262
263
|
}
|
|
263
|
-
|
|
264
|
+
type Status = "idle" | "loading" | "ready" | "error";
|
|
264
265
|
declare function useScriptTag(src: string, onLoaded?: (el: HTMLScriptElement) => void, options?: UseScriptTagOptions): readonly [HTMLScriptElement | null, Status, (waitForScriptLoad?: boolean) => Promise<HTMLScriptElement | boolean>, () => void];
|
|
265
266
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
type IState = PermissionState | "";
|
|
268
|
+
type DescriptorNamePolyfill = "accelerometer" | "accessibility-events" | "ambient-light-sensor" | "background-sync" | "camera" | "clipboard-read" | "clipboard-write" | "gyroscope" | "magnetometer" | "microphone" | "notifications" | "payment-handler" | "persistent-storage" | "push" | "speaker";
|
|
269
|
+
type GeneralPermissionDescriptor = PermissionDescriptor | {
|
|
269
270
|
name: DescriptorNamePolyfill;
|
|
270
271
|
};
|
|
271
272
|
declare function usePermission(permissionDesc: GeneralPermissionDescriptor | GeneralPermissionDescriptor["name"]): IState;
|
|
@@ -296,7 +297,7 @@ declare function useMediaDevices(): {
|
|
|
296
297
|
};
|
|
297
298
|
declare const _default$3: typeof useMediaDevices;
|
|
298
299
|
|
|
299
|
-
|
|
300
|
+
type UseTextDirectionValue = "ltr" | "rtl" | "auto";
|
|
300
301
|
interface UseTextDirectionOptions {
|
|
301
302
|
/**
|
|
302
303
|
* CSS Selector for the target element applying to
|
|
@@ -539,7 +540,7 @@ interface UseInfiniteScrollOptions extends UseScrollOptions {
|
|
|
539
540
|
}
|
|
540
541
|
declare function useInfiniteScroll(target: BasicTarget<HTMLElement | SVGElement>, onLoadMore: (state: ReturnType<typeof useScroll>) => void | Promise<void>, options?: UseInfiniteScrollOptions): void;
|
|
541
542
|
|
|
542
|
-
|
|
543
|
+
type KeyModifier = "Alt" | "AltGraph" | "CapsLock" | "Control" | "Fn" | "FnLock" | "Meta" | "NumLock" | "ScrollLock" | "Shift" | "Symbol" | "SymbolLock";
|
|
543
544
|
interface UseModifierOptions {
|
|
544
545
|
/**
|
|
545
546
|
* Event names that will prompt update to modifier states
|
|
@@ -556,8 +557,8 @@ interface UseModifierOptions {
|
|
|
556
557
|
}
|
|
557
558
|
declare function useKeyModifier(modifier: KeyModifier, options?: UseModifierOptions): boolean;
|
|
558
559
|
|
|
559
|
-
|
|
560
|
-
|
|
560
|
+
type IHookStateInitialSetter<S> = () => S;
|
|
561
|
+
type IHookStateInitAction<S> = S | IHookStateInitialSetter<S>;
|
|
561
562
|
|
|
562
563
|
interface MousePressedOptions {
|
|
563
564
|
/**
|
|
@@ -579,7 +580,7 @@ interface MousePressedOptions {
|
|
|
579
580
|
*/
|
|
580
581
|
initialValue?: IHookStateInitAction<boolean>;
|
|
581
582
|
}
|
|
582
|
-
|
|
583
|
+
type MouseSourceType = "mouse" | "touch" | null;
|
|
583
584
|
declare function useMousePressed(target?: BasicTarget, options?: MousePressedOptions): readonly [boolean, MouseSourceType];
|
|
584
585
|
|
|
585
586
|
declare function useScrollLock(target: BasicTarget<HTMLElement>, initialState?: boolean): readonly [boolean, (flag: boolean) => void];
|
|
@@ -626,10 +627,10 @@ interface UseVirtualListReturn<T> {
|
|
|
626
627
|
}
|
|
627
628
|
declare function useVirtualList<T = any>(list: T[] | undefined, options: UseVirtualListOptions): UseVirtualListReturn<T>;
|
|
628
629
|
|
|
629
|
-
|
|
630
|
+
type ColorScheme = "dark" | "light" | "no-preference";
|
|
630
631
|
declare function usePreferredColorScheme(defaultState?: ColorScheme): ColorScheme;
|
|
631
632
|
|
|
632
|
-
|
|
633
|
+
type Contrast = "more" | "less" | "custom" | "no-preference";
|
|
633
634
|
declare function usePreferredContrast(defaultState?: Contrast): Contrast;
|
|
634
635
|
|
|
635
636
|
declare function useActiveElement<T extends Element>(): T | null;
|
|
@@ -751,7 +752,7 @@ declare function useClipBorad(): readonly [
|
|
|
751
752
|
(txt: string) => Promise<void>
|
|
752
753
|
];
|
|
753
754
|
|
|
754
|
-
|
|
755
|
+
type EventType = MouseEvent | TouchEvent;
|
|
755
756
|
declare function useClickOutSide(target: BasicTarget, handler: (evt: EventType) => void): void;
|
|
756
757
|
|
|
757
758
|
declare function useCycleList<T>(list: T[], i?: number): readonly [T, (i?: number) => void, (i?: number) => void];
|
|
@@ -814,7 +815,7 @@ declare const useSticky: ({ targetElement, scrollElement, axis, nav, }: UseStick
|
|
|
814
815
|
declare function useAsyncEffect<T extends void>(effect: () => Promise<T> | T, cleanup?: typeof effect, deps?: DependencyList): void;
|
|
815
816
|
|
|
816
817
|
declare const getHMSTime: (timeDiff: number) => [string, string, string];
|
|
817
|
-
declare const useCountDown: (time: number, format?: (
|
|
818
|
+
declare const useCountDown: (time: number, format?: (num: number) => [string, string, string], callback?: () => void) => readonly [string, string, string];
|
|
818
819
|
|
|
819
820
|
declare function useSupported(callback: () => unknown, sync?: boolean): boolean;
|
|
820
821
|
|
|
@@ -827,6 +828,23 @@ interface EyeDropperOpenReturnType {
|
|
|
827
828
|
sRGBHex: string;
|
|
828
829
|
}
|
|
829
830
|
declare function useEyeDropper(): readonly [boolean, (options?: EyeDropperOpenOptions) => Promise<EyeDropperOpenReturnType>];
|
|
830
|
-
|
|
831
|
+
type UseEyeDropperReturn = ReturnType<typeof useEyeDropper>;
|
|
831
832
|
|
|
832
|
-
|
|
833
|
+
type CookieState = string | undefined;
|
|
834
|
+
interface CookieOptions extends Cookies.CookieAttributes {
|
|
835
|
+
defaultValue?: string | (() => string);
|
|
836
|
+
/**
|
|
837
|
+
* set to storage when nodata in effect, fallback to defaultValue
|
|
838
|
+
*/
|
|
839
|
+
csrData?: CookieState | (() => CookieState);
|
|
840
|
+
}
|
|
841
|
+
declare function useCookie(key: string, options?: CookieOptions): readonly [CookieState, (newValue: CookieState | ((prevState: CookieState) => CookieState)) => void, () => void];
|
|
842
|
+
|
|
843
|
+
declare function useDoubleClick({ target, latency, onSingleClick, onDoubleClick, }: {
|
|
844
|
+
target: BasicTarget;
|
|
845
|
+
latency?: number;
|
|
846
|
+
onSingleClick?: (e?: MouseEvent | TouchEvent) => void;
|
|
847
|
+
onDoubleClick?: (e?: MouseEvent | TouchEvent) => void;
|
|
848
|
+
}): void;
|
|
849
|
+
|
|
850
|
+
export { ColorScheme, Contrast, CookieOptions, CookieState, CursorState, EyeDropperOpenReturnType, GeneralPermissionDescriptor, IDisposable, IEvent, IEventOnce, IListener, INetworkInformation, IState, IUseNetworkState, KeyModifier, MousePressedOptions, MouseSourceType, OrientationState, RafLoopReturns, ScrollIntoViewAnimation, ScrollIntoViewParams, State, Status, Target, UseDarkOptions, UseDraggableOptions, UseElementBoundingOptions, UseEventEmitterReturn, UseEyeDropperReturn, UseFileDialogOptions, UseFpsOptions, UseFullScreenOptions, UseInfiniteScrollOptions, UseLongPressOptions, UseModifierOptions, UseScriptTagOptions, UseScrollOptions, UseStickyParams, UseTextDirectionOptions, UseTextDirectionValue, UseTimeoutFnOptions, UseVirtualListItem, UseVirtualListOptions, UseVirtualListReturn, WindowSize, getHMSTime, useActiveElement, useAsyncEffect, useClickOutSide as useClickOutside, useClipBorad as useClipboard, useControlled, useCookie, useCountDown, useCounter, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEyeDropper, useFavicon, useFileDialog, useFirstMountState, useFocus, _default$2 as useFps, useFullscreen, useGeolocation, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLongPress, _default$3 as useMediaDevices, useMediaQuery, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, _default$1 as useOnceEffect, _default as useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePrevious, useRafFn, useRafState, useReducedMotion, useResizeObserver, useScriptTag, useScroll, useScrollIntoView, useScrollLock, useSessionStorage, useSticky, useSupported, useTextDirection, useTextSelection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, _default$5 as useUpdateEffect, _default$4 as useUpdateLayoutEffect, useVirtualList, useWindowScroll, useWindowSize, useWindowsFocus };
|