Comparing version 3.7.4 to 3.7.5
import type { useEffect, useLayoutEffect } from 'react'; | ||
declare type EffectHookType = typeof useEffect | typeof useLayoutEffect; | ||
declare type CreateUpdateEffect = (hook: EffectHookType) => EffectHookType; | ||
type EffectHookType = typeof useEffect | typeof useLayoutEffect; | ||
type CreateUpdateEffect = (hook: EffectHookType) => EffectHookType; | ||
export declare const createDeepCompareEffect: CreateUpdateEffect; | ||
export {}; |
import type { useEffect, useLayoutEffect } from 'react'; | ||
declare type EffectHookType = typeof useEffect | typeof useLayoutEffect; | ||
type EffectHookType = typeof useEffect | typeof useLayoutEffect; | ||
export declare const createUpdateEffect: (hook: EffectHookType) => EffectHookType; | ||
export default createUpdateEffect; |
import type { PaginationOptions, PaginationResult } from '../usePagination/types'; | ||
export declare type Data = { | ||
export type Data = { | ||
total: number; | ||
list: any[]; | ||
}; | ||
export declare type Params = [ | ||
export type Params = [ | ||
{ | ||
@@ -17,5 +17,5 @@ current: number; | ||
]; | ||
export declare type Service<TData extends Data, TParams extends Params> = (...args: TParams) => Promise<TData>; | ||
export declare type Antd3ValidateFields = (fieldNames: string[], callback: (errors: any, values: Record<string, any>) => void) => void; | ||
export declare type Antd4ValidateFields = (fieldNames?: string[]) => Promise<Record<string, any>>; | ||
export type Service<TData extends Data, TParams extends Params> = (...args: TParams) => Promise<TData>; | ||
export type Antd3ValidateFields = (fieldNames: string[], callback: (errors: any, values: Record<string, any>) => void) => void; | ||
export type Antd4ValidateFields = (fieldNames?: string[]) => Promise<Record<string, any>>; | ||
export interface AntdFormUtils { | ||
@@ -22,0 +22,0 @@ getFieldInstance?: (name: string) => Record<string, any>; |
@@ -8,3 +8,3 @@ import type { SetStateAction } from 'react'; | ||
} | ||
export declare type Props = Record<string, any>; | ||
export type Props = Record<string, any>; | ||
export interface StandardProps<T> { | ||
@@ -11,0 +11,0 @@ value: T; |
import Cookies from 'js-cookie'; | ||
export declare type State = string | undefined; | ||
export type State = string | undefined; | ||
export interface Options extends Cookies.CookieAttributes { | ||
@@ -4,0 +4,0 @@ defaultValue?: State | (() => State); |
@@ -21,11 +21,9 @@ import { __rest } from "tslib"; | ||
restOptions = __rest(_a, ["defaultValue"]); | ||
setState(prevState => { | ||
const value = isFunction(newValue) ? newValue(prevState) : newValue; | ||
if (value === undefined) { | ||
Cookies.remove(cookieKey); | ||
} else { | ||
Cookies.set(cookieKey, value, restOptions); | ||
} | ||
return value; | ||
}); | ||
const value = isFunction(newValue) ? newValue(state) : newValue; | ||
setState(value); | ||
if (value === undefined) { | ||
Cookies.remove(cookieKey); | ||
} else { | ||
Cookies.set(cookieKey, value, restOptions); | ||
} | ||
}); | ||
@@ -32,0 +30,0 @@ return [state, updateState]; |
import dayjs from 'dayjs'; | ||
export declare type TDate = dayjs.ConfigType; | ||
export type TDate = dayjs.ConfigType; | ||
export interface Options { | ||
@@ -4,0 +4,0 @@ leftTime?: number; |
@@ -11,3 +11,3 @@ export interface Options { | ||
} | ||
export declare type ValueParam = number | ((c: number) => number); | ||
export type ValueParam = number | ((c: number) => number); | ||
declare function useCounter(initialValue?: number, options?: Options): readonly [number, { | ||
@@ -14,0 +14,0 @@ readonly inc: (delta?: number) => void; |
import type { DebounceOptions } from '../useDebounce/debounceOptions'; | ||
declare type noop = (...args: any[]) => any; | ||
type noop = (...args: any[]) => any; | ||
declare function useDebounceFn<T extends noop>(fn: T, options?: DebounceOptions): { | ||
@@ -4,0 +4,0 @@ run: import("lodash").DebouncedFunc<(...args: Parameters<T>) => ReturnType<T>>; |
@@ -1,3 +0,3 @@ | ||
declare type VisibilityState = 'hidden' | 'visible' | 'prerender' | undefined; | ||
type VisibilityState = 'hidden' | 'visible' | 'prerender' | undefined; | ||
declare function useDocumentVisibility(): VisibilityState; | ||
export default useDocumentVisibility; |
@@ -1,2 +0,2 @@ | ||
declare type Subscription<T> = (val: T) => void; | ||
type Subscription<T> = (val: T) => void; | ||
export declare class EventEmitter<T> { | ||
@@ -3,0 +3,0 @@ private subscriptions; |
import type { BasicTarget } from '../utils/domTarget'; | ||
declare type noop = (...p: any) => void; | ||
export declare type Target = BasicTarget<HTMLElement | Element | Window | Document>; | ||
declare type Options<T extends Target = Target> = { | ||
type noop = (...p: any) => void; | ||
export type Target = BasicTarget<HTMLElement | Element | Window | Document>; | ||
type Options<T extends Target = Target> = { | ||
target?: T; | ||
@@ -6,0 +6,0 @@ capture?: boolean; |
@@ -1,8 +0,17 @@ | ||
export interface Options { | ||
type?: 'js' | 'css'; | ||
type JsOptions = { | ||
type: 'js'; | ||
js?: Partial<HTMLScriptElement>; | ||
}; | ||
type CssOptions = { | ||
type: 'css'; | ||
css?: Partial<HTMLStyleElement>; | ||
} | ||
export declare type Status = 'unset' | 'loading' | 'ready' | 'error'; | ||
}; | ||
type DefaultOptions = { | ||
type?: never; | ||
js?: Partial<HTMLScriptElement>; | ||
css?: Partial<HTMLStyleElement>; | ||
}; | ||
export type Options = JsOptions | CssOptions | DefaultOptions; | ||
export type Status = 'unset' | 'loading' | 'ready' | 'error'; | ||
declare const useExternal: (path?: string, options?: Options) => Status; | ||
export default useExternal; |
import type { Dispatch, SetStateAction } from 'react'; | ||
declare type GetStateAction<S> = () => S; | ||
type GetStateAction<S> = () => S; | ||
declare function useGetState<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>, GetStateAction<S>]; | ||
@@ -4,0 +4,0 @@ declare function useGetState<S = undefined>(): [ |
import type { DependencyList } from 'react'; | ||
import type { BasicTarget } from '../utils/domTarget'; | ||
export declare type Data = { | ||
export type Data = { | ||
list: any[]; | ||
[key: string]: any; | ||
}; | ||
export declare type Service<TData extends Data> = (currentData?: Data) => Promise<TData>; | ||
export type Service<TData extends Data> = (currentData?: Data) => Promise<TData>; | ||
export interface InfiniteScrollResult<TData extends Data> { | ||
@@ -9,0 +9,0 @@ data: TData; |
import type { BasicTarget } from '../utils/domTarget'; | ||
export declare type KeyPredicate = (event: KeyboardEvent) => boolean; | ||
export declare type keyType = number | string; | ||
export declare type KeyFilter = keyType | keyType[] | ((event: KeyboardEvent) => boolean); | ||
export declare type EventHandler = (event: KeyboardEvent) => void; | ||
export declare type KeyEvent = 'keydown' | 'keyup'; | ||
export declare type Target = BasicTarget<HTMLElement | Document | Window>; | ||
export declare type Options = { | ||
export type KeyPredicate = (event: KeyboardEvent) => boolean; | ||
export type keyType = number | string; | ||
export type KeyFilter = keyType | keyType[] | ((event: KeyboardEvent) => boolean); | ||
export type EventHandler = (event: KeyboardEvent) => void; | ||
export type KeyEvent = 'keydown' | 'keyup'; | ||
export type Target = BasicTarget<HTMLElement | Document | Window>; | ||
export type Options = { | ||
events?: KeyEvent[]; | ||
@@ -10,0 +10,0 @@ target?: Target; |
import type { BasicTarget } from '../utils/domTarget'; | ||
declare type EventType = MouseEvent | TouchEvent; | ||
type EventType = MouseEvent | TouchEvent; | ||
export interface Options { | ||
@@ -4,0 +4,0 @@ delay?: number; |
@@ -1,3 +0,3 @@ | ||
declare type noop = (this: any, ...args: any[]) => any; | ||
type noop = (this: any, ...args: any[]) => any; | ||
declare function useMemoizedFn<T extends noop>(fn: T): T; | ||
export default useMemoizedFn; |
import type { Options, Result } from '../useRequest/src/types'; | ||
export declare type Data = { | ||
export type Data = { | ||
total: number; | ||
list: any[]; | ||
}; | ||
export declare type Params = [{ | ||
export type Params = [{ | ||
current: number; | ||
@@ -11,3 +11,3 @@ pageSize: number; | ||
}, ...any[]]; | ||
export declare type Service<TData extends Data, TParams extends Params> = (...args: TParams) => Promise<TData>; | ||
export type Service<TData extends Data, TParams extends Params> = (...args: TParams) => Promise<TData>; | ||
export interface PaginationResult<TData extends Data, TParams extends Params> extends Result<TData, TParams> { | ||
@@ -14,0 +14,0 @@ pagination: { |
@@ -1,3 +0,3 @@ | ||
export declare type ShouldUpdateFunc<T> = (prev: T | undefined, next: T) => boolean; | ||
export type ShouldUpdateFunc<T> = (prev: T | undefined, next: T) => boolean; | ||
declare function usePrevious<T>(state: T, shouldUpdate?: ShouldUpdateFunc<T>): T | undefined; | ||
export default usePrevious; |
import { useRef } from 'react'; | ||
const useLoadingDelayPlugin = (fetchInstance, { | ||
loadingDelay | ||
loadingDelay, | ||
ready | ||
}) => { | ||
@@ -17,7 +18,12 @@ const timerRef = useRef(); | ||
cancelTimeout(); | ||
timerRef.current = setTimeout(() => { | ||
fetchInstance.setState({ | ||
loading: true | ||
}); | ||
}, loadingDelay); | ||
// Two cases: | ||
// 1. ready === undefined | ||
// 2. ready === true | ||
if (ready !== false) { | ||
timerRef.current = setTimeout(() => { | ||
fetchInstance.setState({ | ||
loading: true | ||
}); | ||
}, loadingDelay); | ||
} | ||
return { | ||
@@ -24,0 +30,0 @@ loading: false |
import type { DependencyList } from 'react'; | ||
import type Fetch from './Fetch'; | ||
import type { CachedData } from './utils/cache'; | ||
export declare type Service<TData, TParams extends any[]> = (...args: TParams) => Promise<TData>; | ||
export declare type Subscribe = () => void; | ||
export type Service<TData, TParams extends any[]> = (...args: TParams) => Promise<TData>; | ||
export type Subscribe = () => void; | ||
export interface FetchState<TData, TParams extends any[]> { | ||
@@ -57,3 +57,3 @@ loading: boolean; | ||
} | ||
export declare type Plugin<TData, TParams extends any[]> = { | ||
export type Plugin<TData, TParams extends any[]> = { | ||
(fetchInstance: Fetch<TData, TParams>, options: Options<TData, TParams>): PluginReturn<TData, TParams>; | ||
@@ -74,2 +74,2 @@ onInit?: (options: Options<TData, TParams>) => Partial<FetchState<TData, TParams>>; | ||
} | ||
export declare type Timeout = ReturnType<typeof setTimeout>; | ||
export type Timeout = ReturnType<typeof setTimeout>; |
@@ -1,3 +0,3 @@ | ||
declare type Timer = ReturnType<typeof setTimeout>; | ||
declare type CachedKey = string | number; | ||
type Timer = ReturnType<typeof setTimeout>; | ||
type CachedKey = string | number; | ||
export interface CachedData<TData = any, TParams = any> { | ||
@@ -4,0 +4,0 @@ data: TData; |
@@ -1,4 +0,4 @@ | ||
declare type CachedKey = string | number; | ||
type CachedKey = string | number; | ||
declare const getCachePromise: (cacheKey: CachedKey) => Promise<any> | undefined; | ||
declare const setCachePromise: (cacheKey: CachedKey, promise: Promise<any>) => void; | ||
export { getCachePromise, setCachePromise }; |
@@ -1,4 +0,4 @@ | ||
declare type Listener = (data: any) => void; | ||
type Listener = (data: any) => void; | ||
declare const trigger: (key: string, data: any) => void; | ||
declare const subscribe: (key: string, listener: Listener) => () => void; | ||
export { trigger, subscribe }; |
@@ -1,3 +0,3 @@ | ||
declare type Listener = () => void; | ||
type Listener = () => void; | ||
declare function subscribe(listener: Listener): () => void; | ||
export default subscribe; |
@@ -1,3 +0,3 @@ | ||
declare type Listener = () => void; | ||
type Listener = () => void; | ||
declare function subscribe(listener: Listener): () => void; | ||
export default subscribe; |
import type { Dispatch, SetStateAction } from 'react'; | ||
declare type ResetState = () => void; | ||
type ResetState = () => void; | ||
declare const useResetState: <S>(initialState: S | (() => S)) => [S, Dispatch<SetStateAction<S>>, ResetState]; | ||
export default useResetState; |
@@ -1,5 +0,5 @@ | ||
declare type ResponsiveConfig = Record<string, number>; | ||
declare type ResponsiveInfo = Record<string, boolean>; | ||
type ResponsiveConfig = Record<string, number>; | ||
type ResponsiveInfo = Record<string, boolean>; | ||
export declare function configResponsive(config: ResponsiveConfig): void; | ||
export declare function useResponsive(): ResponsiveInfo; | ||
export {}; |
import type { BasicTarget } from '../utils/domTarget'; | ||
declare type Position = { | ||
type Position = { | ||
left: number; | ||
top: number; | ||
}; | ||
export declare type Target = BasicTarget<Element | Document>; | ||
export declare type ScrollListenController = (val: Position) => boolean; | ||
export type Target = BasicTarget<Element | Document>; | ||
export type ScrollListenController = (val: Position) => boolean; | ||
declare function useScroll(target?: Target, shouldUpdate?: ScrollListenController): Position | undefined; | ||
export default useScroll; |
@@ -1,3 +0,3 @@ | ||
export declare type SetState<S extends Record<string, any>> = <K extends keyof S>(state: Pick<S, K> | null | ((prevState: Readonly<S>) => Pick<S, K> | S | null)) => void; | ||
export type SetState<S extends Record<string, any>> = <K extends keyof S>(state: Pick<S, K> | null | ((prevState: Readonly<S>) => Pick<S, K> | S | null)) => void; | ||
declare const useSetState: <S extends Record<string, any>>(initialState: S | (() => S)) => [S, SetState<S>]; | ||
export default useSetState; |
import type { BasicTarget } from '../utils/domTarget'; | ||
declare type Size = { | ||
type Size = { | ||
width: number; | ||
@@ -4,0 +4,0 @@ height: number; |
@@ -6,3 +6,9 @@ import ResizeObserver from 'resize-observer-polyfill'; | ||
function useSize(target) { | ||
const [state, setState] = useRafState(); | ||
const [state, setState] = useRafState(() => { | ||
const el = getTargetElement(target); | ||
return el ? { | ||
width: el.clientWidth, | ||
height: el.clientHeight | ||
} : undefined; | ||
}); | ||
useIsomorphicLayoutEffectWithTarget(() => { | ||
@@ -9,0 +15,0 @@ const el = getTargetElement(target); |
import type { ThrottleOptions } from '../useThrottle/throttleOptions'; | ||
declare type noop = (...args: any[]) => any; | ||
type noop = (...args: any[]) => any; | ||
declare function useThrottleFn<T extends noop>(fn: T, options?: ThrottleOptions): { | ||
@@ -4,0 +4,0 @@ run: import("lodash").DebouncedFunc<(...args: Parameters<T>) => ReturnType<T>>; |
import type { DependencyList } from 'react'; | ||
declare type Effect = (changes?: number[], previousDeps?: DependencyList, currentDeps?: DependencyList) => void | (() => void); | ||
type Effect = (changes?: number[], previousDeps?: DependencyList, currentDeps?: DependencyList) => void | (() => void); | ||
declare const useTrackedEffect: (effect: Effect, deps?: DependencyList) => void; | ||
export default useTrackedEffect; |
import type { BasicTarget } from '../utils/domTarget'; | ||
declare type ItemHeight<T> = (index: number, data: T) => number; | ||
type ItemHeight<T> = (index: number, data: T) => number; | ||
export interface Options<T> { | ||
@@ -4,0 +4,0 @@ containerTarget: BasicTarget; |
@@ -8,2 +8,3 @@ import { useEffect, useMemo, useState, useRef } from 'react'; | ||
import { isNumber } from '../utils'; | ||
import useUpdateEffect from '../useUpdateEffect'; | ||
const useVirtualList = (list, options) => { | ||
@@ -20,2 +21,3 @@ const { | ||
const [targetList, setTargetList] = useState([]); | ||
const [wrapperStyle, setWrapperStyle] = useState({}); | ||
const getVisibleCount = (containerHeight, fromIndex) => { | ||
@@ -70,4 +72,3 @@ if (isNumber(itemHeightRef.current)) { | ||
const container = getTargetElement(containerTarget); | ||
const wrapper = getTargetElement(wrapperTarget); | ||
if (container && wrapper) { | ||
if (container) { | ||
const { | ||
@@ -82,4 +83,6 @@ scrollTop, | ||
const offsetTop = getDistanceTop(start); | ||
wrapper.style.height = totalHeight - offsetTop + 'px'; | ||
wrapper.style.marginTop = offsetTop + 'px'; | ||
setWrapperStyle({ | ||
height: totalHeight - offsetTop + 'px', | ||
marginTop: offsetTop + 'px' | ||
}); | ||
setTargetList(list.slice(start, end).map((ele, index) => ({ | ||
@@ -91,2 +94,8 @@ data: ele, | ||
}; | ||
useUpdateEffect(() => { | ||
const wrapper = getTargetElement(wrapperTarget); | ||
if (wrapper) { | ||
Object.keys(wrapperStyle).forEach(key => wrapper.style[key] = wrapperStyle[key]); | ||
} | ||
}, [wrapperStyle]); | ||
useEffect(() => { | ||
@@ -93,0 +102,0 @@ if (!(size === null || size === void 0 ? void 0 : size.width) || !(size === null || size === void 0 ? void 0 : size.height)) { |
@@ -1,2 +0,2 @@ | ||
export declare type IProps = Record<string, any>; | ||
export type IProps = Record<string, any>; | ||
export default function useWhyDidYouUpdate(componentName: string, props: IProps): void; |
import type { MutableRefObject } from 'react'; | ||
declare type TargetValue<T> = T | undefined | null; | ||
declare type TargetType = HTMLElement | Element | Window | Document; | ||
export declare type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>; | ||
type TargetValue<T> = T | undefined | null; | ||
type TargetType = HTMLElement | Element | Window | Document; | ||
export type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>; | ||
export declare function getTargetElement<T extends TargetType>(target: BasicTarget<T>, defaultElement?: T): TargetValue<T>; | ||
export {}; |
import type { useEffect, useLayoutEffect } from 'react'; | ||
declare type EffectHookType = typeof useEffect | typeof useLayoutEffect; | ||
declare type CreateUpdateEffect = (hook: EffectHookType) => EffectHookType; | ||
type EffectHookType = typeof useEffect | typeof useLayoutEffect; | ||
type CreateUpdateEffect = (hook: EffectHookType) => EffectHookType; | ||
export declare const createDeepCompareEffect: CreateUpdateEffect; | ||
export {}; |
import type { useEffect, useLayoutEffect } from 'react'; | ||
declare type EffectHookType = typeof useEffect | typeof useLayoutEffect; | ||
type EffectHookType = typeof useEffect | typeof useLayoutEffect; | ||
export declare const createUpdateEffect: (hook: EffectHookType) => EffectHookType; | ||
export default createUpdateEffect; |
import type { PaginationOptions, PaginationResult } from '../usePagination/types'; | ||
export declare type Data = { | ||
export type Data = { | ||
total: number; | ||
list: any[]; | ||
}; | ||
export declare type Params = [ | ||
export type Params = [ | ||
{ | ||
@@ -17,5 +17,5 @@ current: number; | ||
]; | ||
export declare type Service<TData extends Data, TParams extends Params> = (...args: TParams) => Promise<TData>; | ||
export declare type Antd3ValidateFields = (fieldNames: string[], callback: (errors: any, values: Record<string, any>) => void) => void; | ||
export declare type Antd4ValidateFields = (fieldNames?: string[]) => Promise<Record<string, any>>; | ||
export type Service<TData extends Data, TParams extends Params> = (...args: TParams) => Promise<TData>; | ||
export type Antd3ValidateFields = (fieldNames: string[], callback: (errors: any, values: Record<string, any>) => void) => void; | ||
export type Antd4ValidateFields = (fieldNames?: string[]) => Promise<Record<string, any>>; | ||
export interface AntdFormUtils { | ||
@@ -22,0 +22,0 @@ getFieldInstance?: (name: string) => Record<string, any>; |
@@ -23,36 +23,34 @@ "use strict"; | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!isAsyncGenerator(e)) { | ||
_context.next = 11; | ||
break; | ||
} | ||
case 1: | ||
if (!true) { | ||
_context.next = 9; | ||
break; | ||
} | ||
_context.next = 4; | ||
return e.next(); | ||
case 4: | ||
result = _context.sent; | ||
if (!(result.done || cancelled)) { | ||
_context.next = 7; | ||
break; | ||
} | ||
return _context.abrupt("break", 9); | ||
case 7: | ||
_context.next = 1; | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!isAsyncGenerator(e)) { | ||
_context.next = 11; | ||
break; | ||
case 9: | ||
_context.next = 13; | ||
} | ||
case 1: | ||
if (!true) { | ||
_context.next = 9; | ||
break; | ||
case 11: | ||
_context.next = 13; | ||
return e; | ||
case 13: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
_context.next = 4; | ||
return e.next(); | ||
case 4: | ||
result = _context.sent; | ||
if (!(result.done || cancelled)) { | ||
_context.next = 7; | ||
break; | ||
} | ||
return _context.abrupt("break", 9); | ||
case 7: | ||
_context.next = 1; | ||
break; | ||
case 9: | ||
_context.next = 13; | ||
break; | ||
case 11: | ||
_context.next = 13; | ||
return e; | ||
case 13: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
@@ -59,0 +57,0 @@ }, _callee); |
@@ -8,3 +8,3 @@ import type { SetStateAction } from 'react'; | ||
} | ||
export declare type Props = Record<string, any>; | ||
export type Props = Record<string, any>; | ||
export interface StandardProps<T> { | ||
@@ -11,0 +11,0 @@ value: T; |
import Cookies from 'js-cookie'; | ||
export declare type State = string | undefined; | ||
export type State = string | undefined; | ||
export interface Options extends Cookies.CookieAttributes { | ||
@@ -4,0 +4,0 @@ defaultValue?: State | (() => State); |
@@ -32,11 +32,9 @@ "use strict"; | ||
restOptions = (0, _tslib.__rest)(_a, ["defaultValue"]); | ||
setState(function (prevState) { | ||
var value = (0, _utils.isFunction)(newValue) ? newValue(prevState) : newValue; | ||
if (value === undefined) { | ||
_jsCookie["default"].remove(cookieKey); | ||
} else { | ||
_jsCookie["default"].set(cookieKey, value, restOptions); | ||
} | ||
return value; | ||
}); | ||
var value = (0, _utils.isFunction)(newValue) ? newValue(state) : newValue; | ||
setState(value); | ||
if (value === undefined) { | ||
_jsCookie["default"].remove(cookieKey); | ||
} else { | ||
_jsCookie["default"].set(cookieKey, value, restOptions); | ||
} | ||
}); | ||
@@ -43,0 +41,0 @@ return [state, updateState]; |
import dayjs from 'dayjs'; | ||
export declare type TDate = dayjs.ConfigType; | ||
export type TDate = dayjs.ConfigType; | ||
export interface Options { | ||
@@ -4,0 +4,0 @@ leftTime?: number; |
@@ -11,3 +11,3 @@ export interface Options { | ||
} | ||
export declare type ValueParam = number | ((c: number) => number); | ||
export type ValueParam = number | ((c: number) => number); | ||
declare function useCounter(initialValue?: number, options?: Options): readonly [number, { | ||
@@ -14,0 +14,0 @@ readonly inc: (delta?: number) => void; |
import type { DebounceOptions } from '../useDebounce/debounceOptions'; | ||
declare type noop = (...args: any[]) => any; | ||
type noop = (...args: any[]) => any; | ||
declare function useDebounceFn<T extends noop>(fn: T, options?: DebounceOptions): { | ||
@@ -4,0 +4,0 @@ run: import("lodash").DebouncedFunc<(...args: Parameters<T>) => ReturnType<T>>; |
@@ -1,3 +0,3 @@ | ||
declare type VisibilityState = 'hidden' | 'visible' | 'prerender' | undefined; | ||
type VisibilityState = 'hidden' | 'visible' | 'prerender' | undefined; | ||
declare function useDocumentVisibility(): VisibilityState; | ||
export default useDocumentVisibility; |
@@ -1,2 +0,2 @@ | ||
declare type Subscription<T> = (val: T) => void; | ||
type Subscription<T> = (val: T) => void; | ||
export declare class EventEmitter<T> { | ||
@@ -3,0 +3,0 @@ private subscriptions; |
@@ -14,3 +14,3 @@ "use strict"; | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } | ||
var EventEmitter = /*#__PURE__*/(0, _createClass2["default"])(function EventEmitter() { | ||
@@ -17,0 +17,0 @@ var _this = this; |
import type { BasicTarget } from '../utils/domTarget'; | ||
declare type noop = (...p: any) => void; | ||
export declare type Target = BasicTarget<HTMLElement | Element | Window | Document>; | ||
declare type Options<T extends Target = Target> = { | ||
type noop = (...p: any) => void; | ||
export type Target = BasicTarget<HTMLElement | Element | Window | Document>; | ||
type Options<T extends Target = Target> = { | ||
target?: T; | ||
@@ -6,0 +6,0 @@ capture?: boolean; |
@@ -1,8 +0,17 @@ | ||
export interface Options { | ||
type?: 'js' | 'css'; | ||
type JsOptions = { | ||
type: 'js'; | ||
js?: Partial<HTMLScriptElement>; | ||
}; | ||
type CssOptions = { | ||
type: 'css'; | ||
css?: Partial<HTMLStyleElement>; | ||
} | ||
export declare type Status = 'unset' | 'loading' | 'ready' | 'error'; | ||
}; | ||
type DefaultOptions = { | ||
type?: never; | ||
js?: Partial<HTMLScriptElement>; | ||
css?: Partial<HTMLStyleElement>; | ||
}; | ||
export type Options = JsOptions | CssOptions | DefaultOptions; | ||
export type Status = 'unset' | 'loading' | 'ready' | 'error'; | ||
declare const useExternal: (path?: string, options?: Options) => Status; | ||
export default useExternal; |
import type { Dispatch, SetStateAction } from 'react'; | ||
declare type GetStateAction<S> = () => S; | ||
type GetStateAction<S> = () => S; | ||
declare function useGetState<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>, GetStateAction<S>]; | ||
@@ -4,0 +4,0 @@ declare function useGetState<S = undefined>(): [ |
@@ -48,22 +48,20 @@ "use strict"; | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return service(lastData); | ||
case 2: | ||
currentData = _context.sent; | ||
if (!lastData) { | ||
setFinalData(currentData); | ||
} else { | ||
setFinalData(Object.assign(Object.assign({}, currentData), { | ||
// @ts-ignore | ||
list: [].concat((0, _toConsumableArray2["default"])(lastData.list), (0, _toConsumableArray2["default"])(currentData.list)) | ||
})); | ||
} | ||
return _context.abrupt("return", currentData); | ||
case 5: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return service(lastData); | ||
case 2: | ||
currentData = _context.sent; | ||
if (!lastData) { | ||
setFinalData(currentData); | ||
} else { | ||
setFinalData(Object.assign(Object.assign({}, currentData), { | ||
// @ts-ignore | ||
list: [].concat((0, _toConsumableArray2["default"])(lastData.list), (0, _toConsumableArray2["default"])(currentData.list)) | ||
})); | ||
} | ||
return _context.abrupt("return", currentData); | ||
case 5: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
@@ -70,0 +68,0 @@ }, _callee); |
import type { DependencyList } from 'react'; | ||
import type { BasicTarget } from '../utils/domTarget'; | ||
export declare type Data = { | ||
export type Data = { | ||
list: any[]; | ||
[key: string]: any; | ||
}; | ||
export declare type Service<TData extends Data> = (currentData?: Data) => Promise<TData>; | ||
export type Service<TData extends Data> = (currentData?: Data) => Promise<TData>; | ||
export interface InfiniteScrollResult<TData extends Data> { | ||
@@ -9,0 +9,0 @@ data: TData; |
@@ -15,3 +15,3 @@ "use strict"; | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } | ||
function useInViewport(target, options) { | ||
@@ -18,0 +18,0 @@ var _useState = (0, _react.useState)(), |
import type { BasicTarget } from '../utils/domTarget'; | ||
export declare type KeyPredicate = (event: KeyboardEvent) => boolean; | ||
export declare type keyType = number | string; | ||
export declare type KeyFilter = keyType | keyType[] | ((event: KeyboardEvent) => boolean); | ||
export declare type EventHandler = (event: KeyboardEvent) => void; | ||
export declare type KeyEvent = 'keydown' | 'keyup'; | ||
export declare type Target = BasicTarget<HTMLElement | Document | Window>; | ||
export declare type Options = { | ||
export type KeyPredicate = (event: KeyboardEvent) => boolean; | ||
export type keyType = number | string; | ||
export type KeyFilter = keyType | keyType[] | ((event: KeyboardEvent) => boolean); | ||
export type EventHandler = (event: KeyboardEvent) => void; | ||
export type KeyEvent = 'keydown' | 'keyup'; | ||
export type Target = BasicTarget<HTMLElement | Document | Window>; | ||
export type Options = { | ||
events?: KeyEvent[]; | ||
@@ -10,0 +10,0 @@ target?: Target; |
@@ -15,3 +15,3 @@ "use strict"; | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } | ||
// 键盘事件 keyCode 别名 | ||
@@ -18,0 +18,0 @@ var aliasKeyCodeMap = { |
@@ -21,28 +21,26 @@ "use strict"; | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!lockRef.current) { | ||
_context.next = 2; | ||
break; | ||
} | ||
return _context.abrupt("return"); | ||
case 2: | ||
lockRef.current = true; | ||
_context.prev = 3; | ||
_context.next = 6; | ||
return fn.apply(void 0, args); | ||
case 6: | ||
ret = _context.sent; | ||
lockRef.current = false; | ||
return _context.abrupt("return", ret); | ||
case 11: | ||
_context.prev = 11; | ||
_context.t0 = _context["catch"](3); | ||
lockRef.current = false; | ||
throw _context.t0; | ||
case 15: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!lockRef.current) { | ||
_context.next = 2; | ||
break; | ||
} | ||
return _context.abrupt("return"); | ||
case 2: | ||
lockRef.current = true; | ||
_context.prev = 3; | ||
_context.next = 6; | ||
return fn.apply(void 0, args); | ||
case 6: | ||
ret = _context.sent; | ||
lockRef.current = false; | ||
return _context.abrupt("return", ret); | ||
case 11: | ||
_context.prev = 11; | ||
_context.t0 = _context["catch"](3); | ||
lockRef.current = false; | ||
throw _context.t0; | ||
case 15: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
@@ -49,0 +47,0 @@ }, _callee, null, [[3, 11]]); |
import type { BasicTarget } from '../utils/domTarget'; | ||
declare type EventType = MouseEvent | TouchEvent; | ||
type EventType = MouseEvent | TouchEvent; | ||
export interface Options { | ||
@@ -4,0 +4,0 @@ delay?: number; |
@@ -1,3 +0,3 @@ | ||
declare type noop = (this: any, ...args: any[]) => any; | ||
type noop = (this: any, ...args: any[]) => any; | ||
declare function useMemoizedFn<T extends noop>(fn: T): T; | ||
export default useMemoizedFn; |
import type { Options, Result } from '../useRequest/src/types'; | ||
export declare type Data = { | ||
export type Data = { | ||
total: number; | ||
list: any[]; | ||
}; | ||
export declare type Params = [{ | ||
export type Params = [{ | ||
current: number; | ||
@@ -11,3 +11,3 @@ pageSize: number; | ||
}, ...any[]]; | ||
export declare type Service<TData extends Data, TParams extends Params> = (...args: TParams) => Promise<TData>; | ||
export type Service<TData extends Data, TParams extends Params> = (...args: TParams) => Promise<TData>; | ||
export interface PaginationResult<TData extends Data, TParams extends Params> extends Result<TData, TParams> { | ||
@@ -14,0 +14,0 @@ pagination: { |
@@ -1,3 +0,3 @@ | ||
export declare type ShouldUpdateFunc<T> = (prev: T | undefined, next: T) => boolean; | ||
export type ShouldUpdateFunc<T> = (prev: T | undefined, next: T) => boolean; | ||
declare function usePrevious<T>(state: T, shouldUpdate?: ShouldUpdateFunc<T>): T | undefined; | ||
export default usePrevious; |
@@ -14,3 +14,4 @@ "use strict"; | ||
var _utils = require("../../utils"); | ||
/* eslint-disable @typescript-eslint/no-parameter-properties */var Fetch = /*#__PURE__*/function () { | ||
/* eslint-disable @typescript-eslint/no-parameter-properties */ | ||
var Fetch = /*#__PURE__*/function () { | ||
function Fetch(serviceRef, options, subscribe) { | ||
@@ -65,79 +66,77 @@ var initState = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
this.count += 1; | ||
currentCount = this.count; | ||
_l = this.runPluginHandler('onBefore', params), _l$stopNow = _l.stopNow, stopNow = _l$stopNow === void 0 ? false : _l$stopNow, _l$returnNow = _l.returnNow, returnNow = _l$returnNow === void 0 ? false : _l$returnNow, state = (0, _tslib.__rest)(_l, ["stopNow", "returnNow"]); // stop request | ||
if (!stopNow) { | ||
_context.next = 5; | ||
break; | ||
} | ||
return _context.abrupt("return", new Promise(function () {})); | ||
case 5: | ||
this.setState(Object.assign({ | ||
loading: true, | ||
params: params | ||
}, state)); | ||
// return now | ||
if (!returnNow) { | ||
_context.next = 8; | ||
break; | ||
} | ||
return _context.abrupt("return", Promise.resolve(state.data)); | ||
case 8: | ||
(_b = (_a = this.options).onBefore) === null || _b === void 0 ? void 0 : _b.call(_a, params); | ||
_context.prev = 9; | ||
// replace service | ||
_this$runPluginHandle = this.runPluginHandler('onRequest', this.serviceRef.current, params), servicePromise = _this$runPluginHandle.servicePromise; | ||
if (!servicePromise) { | ||
servicePromise = (_this$serviceRef = this.serviceRef).current.apply(_this$serviceRef, params); | ||
} | ||
_context.next = 14; | ||
return servicePromise; | ||
case 14: | ||
res = _context.sent; | ||
if (!(currentCount !== this.count)) { | ||
_context.next = 17; | ||
break; | ||
} | ||
return _context.abrupt("return", new Promise(function () {})); | ||
case 17: | ||
// const formattedResult = this.options.formatResultRef.current ? this.options.formatResultRef.current(res) : res; | ||
this.setState({ | ||
data: res, | ||
error: undefined, | ||
loading: false | ||
}); | ||
(_d = (_c = this.options).onSuccess) === null || _d === void 0 ? void 0 : _d.call(_c, res, params); | ||
this.runPluginHandler('onSuccess', res, params); | ||
(_f = (_e = this.options).onFinally) === null || _f === void 0 ? void 0 : _f.call(_e, params, res, undefined); | ||
if (currentCount === this.count) { | ||
this.runPluginHandler('onFinally', params, res, undefined); | ||
} | ||
return _context.abrupt("return", res); | ||
case 25: | ||
_context.prev = 25; | ||
_context.t0 = _context["catch"](9); | ||
if (!(currentCount !== this.count)) { | ||
_context.next = 29; | ||
break; | ||
} | ||
return _context.abrupt("return", new Promise(function () {})); | ||
case 29: | ||
this.setState({ | ||
error: _context.t0, | ||
loading: false | ||
}); | ||
(_h = (_g = this.options).onError) === null || _h === void 0 ? void 0 : _h.call(_g, _context.t0, params); | ||
this.runPluginHandler('onError', _context.t0, params); | ||
(_k = (_j = this.options).onFinally) === null || _k === void 0 ? void 0 : _k.call(_j, params, undefined, _context.t0); | ||
if (currentCount === this.count) { | ||
this.runPluginHandler('onFinally', params, undefined, _context.t0); | ||
} | ||
throw _context.t0; | ||
case 35: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
this.count += 1; | ||
currentCount = this.count; | ||
_l = this.runPluginHandler('onBefore', params), _l$stopNow = _l.stopNow, stopNow = _l$stopNow === void 0 ? false : _l$stopNow, _l$returnNow = _l.returnNow, returnNow = _l$returnNow === void 0 ? false : _l$returnNow, state = (0, _tslib.__rest)(_l, ["stopNow", "returnNow"]); // stop request | ||
if (!stopNow) { | ||
_context.next = 5; | ||
break; | ||
} | ||
return _context.abrupt("return", new Promise(function () {})); | ||
case 5: | ||
this.setState(Object.assign({ | ||
loading: true, | ||
params: params | ||
}, state)); | ||
// return now | ||
if (!returnNow) { | ||
_context.next = 8; | ||
break; | ||
} | ||
return _context.abrupt("return", Promise.resolve(state.data)); | ||
case 8: | ||
(_b = (_a = this.options).onBefore) === null || _b === void 0 ? void 0 : _b.call(_a, params); | ||
_context.prev = 9; | ||
// replace service | ||
_this$runPluginHandle = this.runPluginHandler('onRequest', this.serviceRef.current, params), servicePromise = _this$runPluginHandle.servicePromise; | ||
if (!servicePromise) { | ||
servicePromise = (_this$serviceRef = this.serviceRef).current.apply(_this$serviceRef, params); | ||
} | ||
_context.next = 14; | ||
return servicePromise; | ||
case 14: | ||
res = _context.sent; | ||
if (!(currentCount !== this.count)) { | ||
_context.next = 17; | ||
break; | ||
} | ||
return _context.abrupt("return", new Promise(function () {})); | ||
case 17: | ||
// const formattedResult = this.options.formatResultRef.current ? this.options.formatResultRef.current(res) : res; | ||
this.setState({ | ||
data: res, | ||
error: undefined, | ||
loading: false | ||
}); | ||
(_d = (_c = this.options).onSuccess) === null || _d === void 0 ? void 0 : _d.call(_c, res, params); | ||
this.runPluginHandler('onSuccess', res, params); | ||
(_f = (_e = this.options).onFinally) === null || _f === void 0 ? void 0 : _f.call(_e, params, res, undefined); | ||
if (currentCount === this.count) { | ||
this.runPluginHandler('onFinally', params, res, undefined); | ||
} | ||
return _context.abrupt("return", res); | ||
case 25: | ||
_context.prev = 25; | ||
_context.t0 = _context["catch"](9); | ||
if (!(currentCount !== this.count)) { | ||
_context.next = 29; | ||
break; | ||
} | ||
return _context.abrupt("return", new Promise(function () {})); | ||
case 29: | ||
this.setState({ | ||
error: _context.t0, | ||
loading: false | ||
}); | ||
(_h = (_g = this.options).onError) === null || _h === void 0 ? void 0 : _h.call(_g, _context.t0, params); | ||
this.runPluginHandler('onError', _context.t0, params); | ||
(_k = (_j = this.options).onFinally) === null || _k === void 0 ? void 0 : _k.call(_j, params, undefined, _context.t0); | ||
if (currentCount === this.count) { | ||
this.runPluginHandler('onFinally', params, undefined, _context.t0); | ||
} | ||
throw _context.t0; | ||
case 35: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
@@ -144,0 +143,0 @@ }, _callee, this, [[9, 25]]); |
@@ -9,3 +9,4 @@ "use strict"; | ||
var useLoadingDelayPlugin = function useLoadingDelayPlugin(fetchInstance, _ref) { | ||
var loadingDelay = _ref.loadingDelay; | ||
var loadingDelay = _ref.loadingDelay, | ||
ready = _ref.ready; | ||
var timerRef = (0, _react.useRef)(); | ||
@@ -23,7 +24,12 @@ if (!loadingDelay) { | ||
cancelTimeout(); | ||
timerRef.current = setTimeout(function () { | ||
fetchInstance.setState({ | ||
loading: true | ||
}); | ||
}, loadingDelay); | ||
// Two cases: | ||
// 1. ready === undefined | ||
// 2. ready === true | ||
if (ready !== false) { | ||
timerRef.current = setTimeout(function () { | ||
fetchInstance.setState({ | ||
loading: true | ||
}); | ||
}, loadingDelay); | ||
} | ||
return { | ||
@@ -30,0 +36,0 @@ loading: false |
import type { DependencyList } from 'react'; | ||
import type Fetch from './Fetch'; | ||
import type { CachedData } from './utils/cache'; | ||
export declare type Service<TData, TParams extends any[]> = (...args: TParams) => Promise<TData>; | ||
export declare type Subscribe = () => void; | ||
export type Service<TData, TParams extends any[]> = (...args: TParams) => Promise<TData>; | ||
export type Subscribe = () => void; | ||
export interface FetchState<TData, TParams extends any[]> { | ||
@@ -57,3 +57,3 @@ loading: boolean; | ||
} | ||
export declare type Plugin<TData, TParams extends any[]> = { | ||
export type Plugin<TData, TParams extends any[]> = { | ||
(fetchInstance: Fetch<TData, TParams>, options: Options<TData, TParams>): PluginReturn<TData, TParams>; | ||
@@ -74,2 +74,2 @@ onInit?: (options: Options<TData, TParams>) => Partial<FetchState<TData, TParams>>; | ||
} | ||
export declare type Timeout = ReturnType<typeof setTimeout>; | ||
export type Timeout = ReturnType<typeof setTimeout>; |
@@ -1,3 +0,3 @@ | ||
declare type Timer = ReturnType<typeof setTimeout>; | ||
declare type CachedKey = string | number; | ||
type Timer = ReturnType<typeof setTimeout>; | ||
type CachedKey = string | number; | ||
export interface CachedData<TData = any, TParams = any> { | ||
@@ -4,0 +4,0 @@ data: TData; |
@@ -1,4 +0,4 @@ | ||
declare type CachedKey = string | number; | ||
type CachedKey = string | number; | ||
declare const getCachePromise: (cacheKey: CachedKey) => Promise<any> | undefined; | ||
declare const setCachePromise: (cacheKey: CachedKey, promise: Promise<any>) => void; | ||
export { getCachePromise, setCachePromise }; |
@@ -1,4 +0,4 @@ | ||
declare type Listener = (data: any) => void; | ||
type Listener = (data: any) => void; | ||
declare const trigger: (key: string, data: any) => void; | ||
declare const subscribe: (key: string, listener: Listener) => () => void; | ||
export { trigger, subscribe }; |
@@ -1,3 +0,3 @@ | ||
declare type Listener = () => void; | ||
type Listener = () => void; | ||
declare function subscribe(listener: Listener): () => void; | ||
export default subscribe; |
@@ -1,3 +0,3 @@ | ||
declare type Listener = () => void; | ||
type Listener = () => void; | ||
declare function subscribe(listener: Listener): () => void; | ||
export default subscribe; |
import type { Dispatch, SetStateAction } from 'react'; | ||
declare type ResetState = () => void; | ||
type ResetState = () => void; | ||
declare const useResetState: <S>(initialState: S | (() => S)) => [S, Dispatch<SetStateAction<S>>, ResetState]; | ||
export default useResetState; |
@@ -1,5 +0,5 @@ | ||
declare type ResponsiveConfig = Record<string, number>; | ||
declare type ResponsiveInfo = Record<string, boolean>; | ||
type ResponsiveConfig = Record<string, number>; | ||
type ResponsiveInfo = Record<string, boolean>; | ||
export declare function configResponsive(config: ResponsiveConfig): void; | ||
export declare function useResponsive(): ResponsiveInfo; | ||
export {}; |
@@ -14,3 +14,3 @@ "use strict"; | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } | ||
var subscribers = new Set(); | ||
@@ -17,0 +17,0 @@ var info; |
import type { BasicTarget } from '../utils/domTarget'; | ||
declare type Position = { | ||
type Position = { | ||
left: number; | ||
top: number; | ||
}; | ||
export declare type Target = BasicTarget<Element | Document>; | ||
export declare type ScrollListenController = (val: Position) => boolean; | ||
export type Target = BasicTarget<Element | Document>; | ||
export type ScrollListenController = (val: Position) => boolean; | ||
declare function useScroll(target?: Target, shouldUpdate?: ScrollListenController): Position | undefined; | ||
export default useScroll; |
@@ -1,3 +0,3 @@ | ||
export declare type SetState<S extends Record<string, any>> = <K extends keyof S>(state: Pick<S, K> | null | ((prevState: Readonly<S>) => Pick<S, K> | S | null)) => void; | ||
export type SetState<S extends Record<string, any>> = <K extends keyof S>(state: Pick<S, K> | null | ((prevState: Readonly<S>) => Pick<S, K> | S | null)) => void; | ||
declare const useSetState: <S extends Record<string, any>>(initialState: S | (() => S)) => [S, SetState<S>]; | ||
export default useSetState; |
import type { BasicTarget } from '../utils/domTarget'; | ||
declare type Size = { | ||
type Size = { | ||
width: number; | ||
@@ -4,0 +4,0 @@ height: number; |
@@ -14,3 +14,9 @@ "use strict"; | ||
function useSize(target) { | ||
var _useRafState = (0, _useRafState3["default"])(), | ||
var _useRafState = (0, _useRafState3["default"])(function () { | ||
var el = (0, _domTarget.getTargetElement)(target); | ||
return el ? { | ||
width: el.clientWidth, | ||
height: el.clientHeight | ||
} : undefined; | ||
}), | ||
_useRafState2 = (0, _slicedToArray2["default"])(_useRafState, 2), | ||
@@ -17,0 +23,0 @@ state = _useRafState2[0], |
import type { ThrottleOptions } from '../useThrottle/throttleOptions'; | ||
declare type noop = (...args: any[]) => any; | ||
type noop = (...args: any[]) => any; | ||
declare function useThrottleFn<T extends noop>(fn: T, options?: ThrottleOptions): { | ||
@@ -4,0 +4,0 @@ run: import("lodash").DebouncedFunc<(...args: Parameters<T>) => ReturnType<T>>; |
import type { DependencyList } from 'react'; | ||
declare type Effect = (changes?: number[], previousDeps?: DependencyList, currentDeps?: DependencyList) => void | (() => void); | ||
type Effect = (changes?: number[], previousDeps?: DependencyList, currentDeps?: DependencyList) => void | (() => void); | ||
declare const useTrackedEffect: (effect: Effect, deps?: DependencyList) => void; | ||
export default useTrackedEffect; |
import type { BasicTarget } from '../utils/domTarget'; | ||
declare type ItemHeight<T> = (index: number, data: T) => number; | ||
type ItemHeight<T> = (index: number, data: T) => number; | ||
export interface Options<T> { | ||
@@ -4,0 +4,0 @@ containerTarget: BasicTarget; |
@@ -16,2 +16,3 @@ "use strict"; | ||
var _utils = require("../utils"); | ||
var _useUpdateEffect = _interopRequireDefault(require("../useUpdateEffect")); | ||
var useVirtualList = function useVirtualList(list, options) { | ||
@@ -30,2 +31,6 @@ var containerTarget = options.containerTarget, | ||
setTargetList = _useState2[1]; | ||
var _useState3 = (0, _react.useState)({}), | ||
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2), | ||
wrapperStyle = _useState4[0], | ||
setWrapperStyle = _useState4[1]; | ||
var getVisibleCount = function getVisibleCount(containerHeight, fromIndex) { | ||
@@ -84,4 +89,3 @@ if ((0, _utils.isNumber)(itemHeightRef.current)) { | ||
var container = (0, _domTarget.getTargetElement)(containerTarget); | ||
var wrapper = (0, _domTarget.getTargetElement)(wrapperTarget); | ||
if (container && wrapper) { | ||
if (container) { | ||
var scrollTop = container.scrollTop, | ||
@@ -94,4 +98,6 @@ clientHeight = container.clientHeight; | ||
var offsetTop = getDistanceTop(start); | ||
wrapper.style.height = totalHeight - offsetTop + 'px'; | ||
wrapper.style.marginTop = offsetTop + 'px'; | ||
setWrapperStyle({ | ||
height: totalHeight - offsetTop + 'px', | ||
marginTop: offsetTop + 'px' | ||
}); | ||
setTargetList(list.slice(start, end).map(function (ele, index) { | ||
@@ -105,2 +111,10 @@ return { | ||
}; | ||
(0, _useUpdateEffect["default"])(function () { | ||
var wrapper = (0, _domTarget.getTargetElement)(wrapperTarget); | ||
if (wrapper) { | ||
Object.keys(wrapperStyle).forEach(function (key) { | ||
return wrapper.style[key] = wrapperStyle[key]; | ||
}); | ||
} | ||
}, [wrapperStyle]); | ||
(0, _react.useEffect)(function () { | ||
@@ -107,0 +121,0 @@ if (!(size === null || size === void 0 ? void 0 : size.width) || !(size === null || size === void 0 ? void 0 : size.height)) { |
@@ -1,2 +0,2 @@ | ||
export declare type IProps = Record<string, any>; | ||
export type IProps = Record<string, any>; | ||
export default function useWhyDidYouUpdate(componentName: string, props: IProps): void; |
import type { MutableRefObject } from 'react'; | ||
declare type TargetValue<T> = T | undefined | null; | ||
declare type TargetType = HTMLElement | Element | Window | Document; | ||
export declare type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>; | ||
type TargetValue<T> = T | undefined | null; | ||
type TargetType = HTMLElement | Element | Window | Document; | ||
export type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>; | ||
export declare function getTargetElement<T extends TargetType>(target: BasicTarget<T>, defaultElement?: T): TargetValue<T>; | ||
export {}; |
{ | ||
"name": "ahooks", | ||
"version": "3.7.4", | ||
"version": "3.7.5", | ||
"description": "react hooks library", | ||
@@ -24,5 +24,2 @@ "keywords": [ | ||
"homepage": "https://github.com/alibaba/hooks", | ||
"scripts": { | ||
"build": "gulp && webpack-cli" | ||
}, | ||
"files": [ | ||
@@ -52,5 +49,5 @@ "dist", | ||
"@alifd/next": "^1.20.6", | ||
"@ant-design/icons": "^4.6.2", | ||
"@ant-design/icons": "^5.0.1", | ||
"@types/enzyme": "^3.10.5", | ||
"antd": "^4.16.9", | ||
"antd": "^5.2.1", | ||
"enzyme-adapter-react-16": "^1.15.4", | ||
@@ -66,3 +63,6 @@ "jest-websocket-mock": "^2.1.0", | ||
"license": "MIT", | ||
"gitHead": "11f6ad571bd365c95ecb9409ca3050cbbfc9b34a" | ||
} | ||
"gitHead": "11f6ad571bd365c95ecb9409ca3050cbbfc9b34a", | ||
"scripts": { | ||
"build": "gulp && webpack-cli" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
562883
493
12716