@zayne-labs/toolkit-react 0.9.45 → 0.9.47
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/esm/hooks/index.d.ts +2 -199
- package/dist/esm/hooks/index.js +3 -3
- package/dist/esm/hooks-cJL0eNIo.js +575 -0
- package/dist/esm/hooks-cJL0eNIo.js.map +1 -0
- package/dist/esm/index-DeDvIi3X.d.ts +277 -0
- package/dist/esm/utils/index.d.ts +22 -9
- package/dist/esm/utils/index.js +115 -108
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/zustand/index.d.ts +35 -28
- package/dist/esm/zustand/index.js +48 -50
- package/dist/esm/zustand/index.js.map +1 -1
- package/package.json +6 -6
- package/dist/esm/chunk-KFK5FGDY.js +0 -495
- package/dist/esm/chunk-KFK5FGDY.js.map +0 -1
- package/dist/esm/createCustomContext-BTQFrzrp.d.ts +0 -20
- package/dist/esm/hooks/index.js.map +0 -1
@@ -1,199 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
import { useEffect, RefCallback } from 'react';
|
4
|
-
import { NonEmptyArray, Prettify, AnyFunction, CallbackFn, SelectorFn } from '@zayne-labs/toolkit-type-helpers';
|
5
|
-
import * as _zayne_labs_toolkit_core from '@zayne-labs/toolkit-core';
|
6
|
-
import { AnimationIntervalOptions, LocationStoreOptions, LocationStoreApi, LocationInfo, ScrollObserverOptions, URLSearchParamsInit, StorageOptions, StorageStoreApi, StoreApi } from '@zayne-labs/toolkit-core';
|
7
|
-
|
8
|
-
declare const useAfterMountEffect: typeof useEffect;
|
9
|
-
|
10
|
-
declare function useAsyncEffect(effect: () => Promise<ReturnType<React.EffectCallback>>, deps?: React.DependencyList): void;
|
11
|
-
|
12
|
-
declare const useEffectOnce: (callBackFn: React.EffectCallback) => void;
|
13
|
-
|
14
|
-
type Destructor = ReturnType<React.EffectCallback>;
|
15
|
-
type LifeCycleOptions = {
|
16
|
-
onMount?: () => void;
|
17
|
-
onUnmount?: Destructor;
|
18
|
-
};
|
19
|
-
declare const useLifeCycle: ({ onMount, onUnmount }: LifeCycleOptions) => void;
|
20
|
-
|
21
|
-
declare const useMountEffect: (callBackFn: () => void) => void;
|
22
|
-
|
23
|
-
declare const useUnmountEffect: (cleanUpFn: Destructor) => void;
|
24
|
-
|
25
|
-
type ElementsInfoArray<TTargetElement extends string> = NonEmptyArray<{
|
26
|
-
animationClass: string;
|
27
|
-
targetElement: TTargetElement;
|
28
|
-
}>;
|
29
|
-
/**
|
30
|
-
* This is a custom React hook that adds and removes animation classes to specified HTML elements.
|
31
|
-
* @param elementsInfoArray - An array of objects that contain information about the animation class and the target HTML element.
|
32
|
-
* @returns - An object containing the refs of the animated elements and a function to handle the initiation and removal animation.
|
33
|
-
*/
|
34
|
-
declare const useAnimateElementRefs: <TTargetElement extends string>(elementsInfoArray: ElementsInfoArray<TTargetElement>) => {
|
35
|
-
animatedElements: Record<TTargetElement, HTMLElement | null>;
|
36
|
-
handleElementsAnimation: () => void;
|
37
|
-
};
|
38
|
-
|
39
|
-
type AnimationOptions = Prettify<AnimationIntervalOptions & {
|
40
|
-
intervalDuration: number | null;
|
41
|
-
onAnimation: () => void;
|
42
|
-
}>;
|
43
|
-
declare const useAnimationInterval: (options: AnimationOptions) => {
|
44
|
-
start: () => void;
|
45
|
-
stop: () => void;
|
46
|
-
};
|
47
|
-
|
48
|
-
/**
|
49
|
-
* Returns a stable function that always points to the latest version of the callback function.
|
50
|
-
* @param callbackFn - The function to reference
|
51
|
-
* @returns a stable function that always points to the latest version of the callback function
|
52
|
-
*/
|
53
|
-
declare const useCallbackRef: <TCallback = AnyFunction>(callbackFn: TCallback | undefined) => TCallback;
|
54
|
-
|
55
|
-
type UseClickOutsideOptions = {
|
56
|
-
enabled?: boolean;
|
57
|
-
};
|
58
|
-
declare const useClickOutside: <TElement extends HTMLElement>(refOrRefArray: Array<React.RefObject<TElement>> | React.RefObject<TElement>, callback: (event: MouseEvent | TouchEvent) => void, options?: UseClickOutsideOptions) => void;
|
59
|
-
|
60
|
-
declare const useConstant: <TResult>(initCallbackFn: () => TResult) => TResult;
|
61
|
-
|
62
|
-
declare const useCopyToClipboard: () => {
|
63
|
-
copiedValue: string;
|
64
|
-
handleCopy: (value: string) => void;
|
65
|
-
};
|
66
|
-
|
67
|
-
declare const useDebouncedFn: <TParams>(callBackFn: CallbackFn<TParams>, delay: number | undefined) => {
|
68
|
-
(...params: TParams[]): void;
|
69
|
-
(params: TParams | TParams[], overrideOptions: {
|
70
|
-
$delay: number;
|
71
|
-
}): void;
|
72
|
-
cancel: () => void;
|
73
|
-
cancelMaxWait(): void;
|
74
|
-
};
|
75
|
-
declare const useDebouncedState: <TValue>(defaultValue: TValue, delay: number | undefined) => readonly [TValue, {
|
76
|
-
(...params: react.SetStateAction<TValue>[]): void;
|
77
|
-
(params: react.SetStateAction<TValue> | react.SetStateAction<TValue>[], overrideOptions: {
|
78
|
-
$delay: number;
|
79
|
-
}): void;
|
80
|
-
cancel: () => void;
|
81
|
-
cancelMaxWait(): void;
|
82
|
-
}, react.Dispatch<react.SetStateAction<TValue>>];
|
83
|
-
|
84
|
-
type DisclosureOptions = {
|
85
|
-
hasScrollControl?: boolean;
|
86
|
-
initialState?: boolean | (() => boolean);
|
87
|
-
};
|
88
|
-
declare const useDisclosure: (options?: DisclosureOptions) => {
|
89
|
-
isOpen: boolean;
|
90
|
-
onClose: () => void;
|
91
|
-
onOpen: () => void;
|
92
|
-
onToggle: <TValue>(value?: TValue) => void;
|
93
|
-
};
|
94
|
-
|
95
|
-
/**
|
96
|
-
* @description Returns whether the component is currently being server side rendered or
|
97
|
-
* hydrated on the client. Can be used to delay browser-specific rendering
|
98
|
-
* until after hydration.
|
99
|
-
*/
|
100
|
-
declare const useIsServer: () => boolean;
|
101
|
-
|
102
|
-
type UseLocationResult<TSlice> = [state: TSlice, actions: LocationStoreApi];
|
103
|
-
declare const createUseLocationState: (options?: LocationStoreOptions) => Omit<_zayne_labs_toolkit_core.StoreApi<_zayne_labs_toolkit_core.URLInfoObject>, "setState" | "resetState"> & {
|
104
|
-
push: (url: string | _zayne_labs_toolkit_core.PartialURLInfo, options?: {
|
105
|
-
state?: _zayne_labs_toolkit_core.PartialURLInfo["state"];
|
106
|
-
}) => void;
|
107
|
-
replace: LocationStoreApi["push"];
|
108
|
-
triggerPopstateEvent: (nextLocationState?: LocationInfo["state"]) => void;
|
109
|
-
} & (<TSlice = _zayne_labs_toolkit_core.URLInfoObject>(selector?: SelectorFn<LocationInfo, TSlice>) => UseLocationResult<TSlice>);
|
110
|
-
declare const useLocationState: <TSlice = LocationInfo>(selector?: SelectorFn<LocationInfo, TSlice>, options?: LocationStoreOptions) => UseLocationResult<TSlice>;
|
111
|
-
|
112
|
-
type InitialState = boolean | (() => boolean);
|
113
|
-
declare const useToggle: (initialValue?: InitialState) => readonly [boolean, <TValue>(newValue?: TValue) => void];
|
114
|
-
|
115
|
-
type UsePresenceOptions<TDuration extends number | undefined> = {
|
116
|
-
defaultValue?: boolean;
|
117
|
-
/**
|
118
|
-
* @description The duration of the animation or transition
|
119
|
-
*/
|
120
|
-
duration?: TDuration;
|
121
|
-
/**
|
122
|
-
* @description A callback function that will be called when the animation or transition ends
|
123
|
-
*/
|
124
|
-
onExitComplete?: () => void;
|
125
|
-
};
|
126
|
-
type UsePresenceResult<TElement, TDuration> = Prettify<(TDuration extends undefined ? {
|
127
|
-
elementRef: React.RefObject<TElement>;
|
128
|
-
} : unknown) & {
|
129
|
-
isPresent: boolean;
|
130
|
-
isVisible: boolean;
|
131
|
-
toggleVisibility: ReturnType<typeof useToggle>[1];
|
132
|
-
}>;
|
133
|
-
type TypeOption = {
|
134
|
-
/**
|
135
|
-
* @description The type of animation, whether animation or transition
|
136
|
-
* @default "transition"
|
137
|
-
*/
|
138
|
-
type?: "animation" | "transition";
|
139
|
-
};
|
140
|
-
type UsePresence = <TElement extends HTMLElement, TDuration extends number | undefined = undefined>(options?: Prettify<TypeOption & UsePresenceOptions<TDuration>>) => UsePresenceResult<TElement, TDuration>;
|
141
|
-
|
142
|
-
/**
|
143
|
-
* usePresence hook provides a way to animate an element, before removing it from the DOM.
|
144
|
-
* @param defaultValue - The default value for the presence state. Defaults to `true`.
|
145
|
-
* @param options - The options for the usePresence hook.
|
146
|
-
* @returns A object containing the boolean that should be used to conditionally render the element (isPresent), another boolean used to toggle the animation classes, and a function to toggle the state.
|
147
|
-
*/
|
148
|
-
declare const usePresence: UsePresence;
|
149
|
-
|
150
|
-
declare const useScrollObserver: <TElement extends HTMLElement>(options?: ScrollObserverOptions) => {
|
151
|
-
isScrolled: boolean;
|
152
|
-
observedElementRef: RefCallback<TElement>;
|
153
|
-
};
|
154
|
-
|
155
|
-
declare const useSearch: <TData>(initialData: TData[], delay?: number) => {
|
156
|
-
data: TData[];
|
157
|
-
isLoading: boolean;
|
158
|
-
query: string;
|
159
|
-
setQuery: react.Dispatch<react.SetStateAction<string>>;
|
160
|
-
};
|
161
|
-
|
162
|
-
type UseSearchParamsOptions = LocationStoreOptions & {
|
163
|
-
action?: "push" | "replace";
|
164
|
-
};
|
165
|
-
declare const useSearchParams: <TSearchParams extends URLSearchParamsInit>(options?: UseSearchParamsOptions) => readonly [URLSearchParams, {
|
166
|
-
(newQueryParams: TSearchParams | ((prev: URLSearchParams) => TSearchParams)): void;
|
167
|
-
triggerPopstateEvent: (nextLocationState?: _zayne_labs_toolkit_core.LocationInfo["state"]) => void;
|
168
|
-
}];
|
169
|
-
declare const useSearchParamsObject: <TSearchParams extends Record<string, string>>(options?: UseSearchParamsOptions) => readonly [TSearchParams, {
|
170
|
-
(newQueryParams: TSearchParams | ((prev: TSearchParams) => TSearchParams)): void;
|
171
|
-
triggerPopstateEvent: (nextLocationState?: _zayne_labs_toolkit_core.LocationInfo["state"]) => void;
|
172
|
-
}];
|
173
|
-
|
174
|
-
type UseStorageResult<TState, TSlice = TState> = [state: TSlice, actions: StorageStoreApi<TState>];
|
175
|
-
/**
|
176
|
-
* @description Creates a custom hook that returns a storage state and actions to modify it. You can use this if you need shared options.
|
177
|
-
* @note You must use this if you want to be able to prevent syncing state across tabs.
|
178
|
-
*/
|
179
|
-
declare const createUseStorageState: <TState>(baseOptions: StorageOptions<TState>) => _zayne_labs_toolkit_core.StoreApi<TState> & {
|
180
|
-
removeState: () => void;
|
181
|
-
} & (<TSlice = TState>(selector?: SelectorFn<TState, TSlice>) => UseStorageResult<TState, TSlice>);
|
182
|
-
type UseStorageStateOptions<TValue> = Omit<StorageOptions<TValue>, "initialValue" | "key">;
|
183
|
-
declare const useStorageState: <TValue, TSlice = TValue>(key: string, initialValue?: TValue, options?: UseStorageStateOptions<TValue> & {
|
184
|
-
select?: SelectorFn<TValue, TSlice>;
|
185
|
-
}) => UseStorageResult<TValue, TSlice>;
|
186
|
-
|
187
|
-
declare const useStore: <TState, TSlice>(store: StoreApi<TState>, selector?: SelectorFn<TState, TSlice>) => TSlice;
|
188
|
-
|
189
|
-
declare const useThrottleBySetTimeout: <TParams>(callbackFn: CallbackFn<TParams>, delay: number) => {
|
190
|
-
(...params: TParams[]): void;
|
191
|
-
cancelTimeout(): void;
|
192
|
-
};
|
193
|
-
declare const useThrottleByTimer: <TParams>(callbackFn: CallbackFn<TParams>, delay: number) => (...params: TParams[]) => void;
|
194
|
-
declare const useThrottleByFrame: <TParams>(callbackFn: CallbackFn<TParams>) => {
|
195
|
-
(...params: TParams[]): void;
|
196
|
-
cancelAnimation(): void;
|
197
|
-
};
|
198
|
-
|
199
|
-
export { createUseLocationState, createUseStorageState, useAfterMountEffect, useAnimateElementRefs, useAnimationInterval, useAsyncEffect, useCallbackRef, useClickOutside, useConstant, useCopyToClipboard, useDebouncedFn, useDebouncedState, useDisclosure, useEffectOnce, useIsServer, useLifeCycle, useLocationState, useMountEffect, usePresence, useScrollObserver, useSearch, useSearchParams, useSearchParamsObject, useStorageState, useStore, useThrottleByFrame, useThrottleBySetTimeout, useThrottleByTimer, useToggle, useUnmountEffect };
|
1
|
+
import { ContextError$1 as ContextError, CustomContextOptions, createCustomContext$1 as createCustomContext, createUseLocationState$1 as createUseLocationState, createUseStorageState$1 as createUseStorageState, getErrorMessage$1 as getErrorMessage, useAfterMountEffect$1 as useAfterMountEffect, useAnimateElementRefs$1 as useAnimateElementRefs, useAnimationInterval$1 as useAnimationInterval, useAsyncEffect$1 as useAsyncEffect, useCallbackRef$1 as useCallbackRef, useClickOutside$1 as useClickOutside, useConstant$1 as useConstant, useCopyToClipboard$1 as useCopyToClipboard, useDebouncedFn$1 as useDebouncedFn, useDebouncedState$1 as useDebouncedState, useDisclosure$1 as useDisclosure, useEffectOnce$1 as useEffectOnce, useIsServer$1 as useIsServer, useLifeCycle$1 as useLifeCycle, useLocationState$1 as useLocationState, useMountEffect$1 as useMountEffect, usePresence$1 as usePresence, useScrollObserver$1 as useScrollObserver, useSearch$1 as useSearch, useSearchParams$1 as useSearchParams, useSearchParamsObject$1 as useSearchParamsObject, useStorageState$1 as useStorageState, useStore$1 as useStore, useThrottleByFrame$1 as useThrottleByFrame, useThrottleBySetTimeout$1 as useThrottleBySetTimeout, useThrottleByTimer$1 as useThrottleByTimer, useToggle$1 as useToggle, useUnmountEffect$1 as useUnmountEffect } from "../index-DeDvIi3X.js";
|
2
|
+
export { ContextError, CustomContextOptions, createCustomContext, createUseLocationState, createUseStorageState, getErrorMessage, useAfterMountEffect, useAnimateElementRefs, useAnimationInterval, useAsyncEffect, useCallbackRef, useClickOutside, useConstant, useCopyToClipboard, useDebouncedFn, useDebouncedState, useDisclosure, useEffectOnce, useIsServer, useLifeCycle, useLocationState, useMountEffect, usePresence, useScrollObserver, useSearch, useSearchParams, useSearchParamsObject, useStorageState, useStore, useThrottleByFrame, useThrottleBySetTimeout, useThrottleByTimer, useToggle, useUnmountEffect };
|
package/dist/esm/hooks/index.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
import { ContextError, createCustomContext, createUseLocationState, createUseStorageState, getErrorMessage, useAfterMountEffect, useAnimateElementRefs, useAnimationInterval, useAsyncEffect, useCallbackRef, useClickOutside, useConstant, useCopyToClipboard, useDebouncedFn, useDebouncedState, useDisclosure, useEffectOnce, useIsServer, useLifeCycle, useLocationState, useMountEffect, usePresence, useScrollObserver, useSearch, useSearchParams, useSearchParamsObject, useStorageState, useStore, useThrottleByFrame, useThrottleBySetTimeout, useThrottleByTimer, useToggle, useUnmountEffect } from "../hooks-cJL0eNIo.js";
|
2
|
+
|
3
|
+
export { ContextError, createCustomContext, createUseLocationState, createUseStorageState, getErrorMessage, useAfterMountEffect, useAnimateElementRefs, useAnimationInterval, useAsyncEffect, useCallbackRef, useClickOutside, useConstant, useCopyToClipboard, useDebouncedFn, useDebouncedState, useDisclosure, useEffectOnce, useIsServer, useLifeCycle, useLocationState, useMountEffect, usePresence, useScrollObserver, useSearch, useSearchParams, useSearchParamsObject, useStorageState, useStore, useThrottleByFrame, useThrottleBySetTimeout, useThrottleByTimer, useToggle, useUnmountEffect };
|