@zayne-labs/toolkit-react 0.9.47 → 0.9.48
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.
@@ -1,2 +1,2 @@
|
|
1
|
-
import { ContextError
|
1
|
+
import { 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 } from "../index-DasjkKek.js";
|
2
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 };
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { AnyFunction, CallbackFn, NonEmptyArray, Prettify, SelectorFn } from "@zayne-labs/toolkit-type-helpers";
|
2
2
|
import * as react5 from "react";
|
3
|
-
import * as
|
4
|
-
import * as
|
3
|
+
import * as react16 from "react";
|
4
|
+
import * as react7 from "react";
|
5
5
|
import { RefCallback, useEffect } from "react";
|
6
|
-
import * as
|
7
|
-
import * as
|
6
|
+
import * as _zayne_labs_toolkit_core9 from "@zayne-labs/toolkit-core";
|
7
|
+
import * as _zayne_labs_toolkit_core14 from "@zayne-labs/toolkit-core";
|
8
8
|
import * as _zayne_labs_toolkit_core21 from "@zayne-labs/toolkit-core";
|
9
9
|
import { AnimationIntervalOptions, LocationInfo, LocationStoreApi, LocationStoreOptions, ScrollObserverOptions, StorageOptions, StorageStoreApi, StoreApi, URLSearchParamsInit } from "@zayne-labs/toolkit-core";
|
10
10
|
|
@@ -27,19 +27,15 @@ type UseCustomContextResult<TContextValue, TStrict extends boolean> = TStrict ex
|
|
27
27
|
declare const createCustomContext: <TContextValue, TStrict extends boolean = true>(options?: CustomContextOptions<TContextValue, TStrict>) => [react5.Context<TContextValue | null>, () => UseCustomContextResult<TContextValue, TStrict>] & {
|
28
28
|
"~inferredUnion": react5.Context<TContextValue | null> | (() => UseCustomContextResult<TContextValue, TStrict>);
|
29
29
|
};
|
30
|
-
|
31
30
|
//#endregion
|
32
31
|
//#region src/hooks/effects/useAfterMountEffect.d.ts
|
33
32
|
declare const useAfterMountEffect: typeof useEffect;
|
34
|
-
|
35
33
|
//#endregion
|
36
34
|
//#region src/hooks/effects/useAsyncEffect.d.ts
|
37
35
|
declare function useAsyncEffect(effect: () => Promise<ReturnType<React.EffectCallback>>, deps?: React.DependencyList): void;
|
38
|
-
|
39
36
|
//#endregion
|
40
37
|
//#region src/hooks/effects/useEffectOnce.d.ts
|
41
38
|
declare const useEffectOnce: (callBackFn: React.EffectCallback) => void;
|
42
|
-
|
43
39
|
//#endregion
|
44
40
|
//#region src/hooks/effects/useLifeCycle.d.ts
|
45
41
|
type Destructor = ReturnType<React.EffectCallback>;
|
@@ -51,15 +47,12 @@ declare const useLifeCycle: ({
|
|
51
47
|
onMount,
|
52
48
|
onUnmount
|
53
49
|
}: LifeCycleOptions) => void;
|
54
|
-
|
55
50
|
//#endregion
|
56
51
|
//#region src/hooks/effects/useMountEffect.d.ts
|
57
52
|
declare const useMountEffect: (callBackFn: () => void) => void;
|
58
|
-
|
59
53
|
//#endregion
|
60
54
|
//#region src/hooks/effects/useUnMountEffect.d.ts
|
61
55
|
declare const useUnmountEffect: (cleanUpFn: Destructor) => void;
|
62
|
-
|
63
56
|
//#endregion
|
64
57
|
//#region src/hooks/useAnimateElementRefs.d.ts
|
65
58
|
type ElementsInfoArray<TTargetElement extends string> = NonEmptyArray<{
|
@@ -75,7 +68,6 @@ declare const useAnimateElementRefs: <TTargetElement extends string>(elementsInf
|
|
75
68
|
animatedElements: Record<TTargetElement, HTMLElement | null>;
|
76
69
|
handleElementsAnimation: () => void;
|
77
70
|
};
|
78
|
-
|
79
71
|
//#endregion
|
80
72
|
//#region src/hooks/useAnimationInterval.d.ts
|
81
73
|
type AnimationOptions = Prettify<AnimationIntervalOptions & {
|
@@ -86,7 +78,6 @@ declare const useAnimationInterval: (options: AnimationOptions) => {
|
|
86
78
|
start: () => void;
|
87
79
|
stop: () => void;
|
88
80
|
};
|
89
|
-
|
90
81
|
//#endregion
|
91
82
|
//#region src/hooks/useCallbackRef.d.ts
|
92
83
|
/**
|
@@ -95,25 +86,21 @@ declare const useAnimationInterval: (options: AnimationOptions) => {
|
|
95
86
|
* @returns a stable function that always points to the latest version of the callback function
|
96
87
|
*/
|
97
88
|
declare const useCallbackRef: <TCallback = AnyFunction>(callbackFn: TCallback | undefined) => TCallback;
|
98
|
-
|
99
89
|
//#endregion
|
100
90
|
//#region src/hooks/useClickOutside.d.ts
|
101
91
|
type UseClickOutsideOptions = {
|
102
92
|
enabled?: boolean;
|
103
93
|
};
|
104
94
|
declare const useClickOutside: <TElement extends HTMLElement>(refOrRefArray: Array<React.RefObject<TElement>> | React.RefObject<TElement>, callback: (event: MouseEvent | TouchEvent) => void, options?: UseClickOutsideOptions) => void;
|
105
|
-
|
106
95
|
//#endregion
|
107
96
|
//#region src/hooks/useConstant.d.ts
|
108
97
|
declare const useConstant: <TResult>(initCallbackFn: () => TResult) => TResult;
|
109
|
-
|
110
98
|
//#endregion
|
111
99
|
//#region src/hooks/useCopyToClipboard.d.ts
|
112
100
|
declare const useCopyToClipboard: () => {
|
113
101
|
copiedValue: string;
|
114
102
|
handleCopy: (value: string) => void;
|
115
103
|
};
|
116
|
-
|
117
104
|
//#endregion
|
118
105
|
//#region src/hooks/useDebounce.d.ts
|
119
106
|
declare const useDebouncedFn: <TParams>(callBackFn: CallbackFn<TParams>, delay: number | undefined) => {
|
@@ -125,14 +112,13 @@ declare const useDebouncedFn: <TParams>(callBackFn: CallbackFn<TParams>, delay:
|
|
125
112
|
cancelMaxWait(): void;
|
126
113
|
};
|
127
114
|
declare const useDebouncedState: <TValue>(defaultValue: TValue, delay: number | undefined) => readonly [TValue, {
|
128
|
-
(...params:
|
129
|
-
(params:
|
115
|
+
(...params: react16.SetStateAction<TValue>[]): void;
|
116
|
+
(params: react16.SetStateAction<TValue> | react16.SetStateAction<TValue>[], overrideOptions: {
|
130
117
|
$delay: number;
|
131
118
|
}): void;
|
132
119
|
cancel: () => void;
|
133
120
|
cancelMaxWait(): void;
|
134
|
-
},
|
135
|
-
|
121
|
+
}, react16.Dispatch<react16.SetStateAction<TValue>>];
|
136
122
|
//#endregion
|
137
123
|
//#region src/hooks/useDisclosure.d.ts
|
138
124
|
type DisclosureOptions = {
|
@@ -145,7 +131,6 @@ declare const useDisclosure: (options?: DisclosureOptions) => {
|
|
145
131
|
onOpen: () => void;
|
146
132
|
onToggle: <TValue>(value?: TValue) => void;
|
147
133
|
};
|
148
|
-
|
149
134
|
//#endregion
|
150
135
|
//#region src/hooks/useIsServer.d.ts
|
151
136
|
/**
|
@@ -154,24 +139,21 @@ declare const useDisclosure: (options?: DisclosureOptions) => {
|
|
154
139
|
* until after hydration.
|
155
140
|
*/
|
156
141
|
declare const useIsServer: () => boolean;
|
157
|
-
|
158
142
|
//#endregion
|
159
143
|
//#region src/hooks/useLocationState.d.ts
|
160
144
|
type UseLocationResult<TSlice> = [state: TSlice, actions: LocationStoreApi];
|
161
|
-
declare const createUseLocationState: (options?: LocationStoreOptions) => Omit<
|
162
|
-
push: (url: string |
|
163
|
-
state?:
|
145
|
+
declare const createUseLocationState: (options?: LocationStoreOptions) => Omit<_zayne_labs_toolkit_core9.StoreApi<_zayne_labs_toolkit_core9.URLInfoObject>, "setState" | "resetState"> & {
|
146
|
+
push: (url: string | _zayne_labs_toolkit_core9.PartialURLInfo, options?: {
|
147
|
+
state?: _zayne_labs_toolkit_core9.PartialURLInfo["state"];
|
164
148
|
}) => void;
|
165
149
|
replace: LocationStoreApi["push"];
|
166
150
|
triggerPopstateEvent: (nextLocationState?: LocationInfo["state"]) => void;
|
167
|
-
} & (<TSlice =
|
151
|
+
} & (<TSlice = _zayne_labs_toolkit_core9.URLInfoObject>(selector?: SelectorFn<LocationInfo, TSlice>) => UseLocationResult<TSlice>);
|
168
152
|
declare const useLocationState: <TSlice = LocationInfo>(selector?: SelectorFn<LocationInfo, TSlice>, options?: LocationStoreOptions) => UseLocationResult<TSlice>;
|
169
|
-
|
170
153
|
//#endregion
|
171
154
|
//#region src/hooks/useToggle.d.ts
|
172
155
|
type InitialState = boolean | (() => boolean);
|
173
156
|
declare const useToggle: (initialValue?: InitialState) => readonly [boolean, <TValue>(newValue?: TValue) => void];
|
174
|
-
|
175
157
|
//#endregion
|
176
158
|
//#region src/hooks/usePresence/types.d.ts
|
177
159
|
type UsePresenceOptions<TDuration extends number | undefined> = {
|
@@ -200,7 +182,6 @@ type TypeOption = {
|
|
200
182
|
type?: "animation" | "transition";
|
201
183
|
};
|
202
184
|
type UsePresence = <TElement extends HTMLElement, TDuration extends number | undefined = undefined>(options?: Prettify<TypeOption & UsePresenceOptions<TDuration>>) => UsePresenceResult<TElement, TDuration>;
|
203
|
-
|
204
185
|
//#endregion
|
205
186
|
//#region src/hooks/usePresence/usePresence.d.ts
|
206
187
|
/**
|
@@ -210,23 +191,20 @@ type UsePresence = <TElement extends HTMLElement, TDuration extends number | und
|
|
210
191
|
* @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.
|
211
192
|
*/
|
212
193
|
declare const usePresence: UsePresence;
|
213
|
-
|
214
194
|
//#endregion
|
215
195
|
//#region src/hooks/useScrollObserver.d.ts
|
216
196
|
declare const useScrollObserver: <TElement extends HTMLElement>(options?: ScrollObserverOptions) => {
|
217
197
|
isScrolled: boolean;
|
218
198
|
observedElementRef: RefCallback<TElement>;
|
219
199
|
};
|
220
|
-
|
221
200
|
//#endregion
|
222
201
|
//#region src/hooks/useSearch.d.ts
|
223
202
|
declare const useSearch: <TData>(initialData: TData[], delay?: number) => {
|
224
203
|
data: TData[];
|
225
204
|
isLoading: boolean;
|
226
205
|
query: string;
|
227
|
-
setQuery:
|
206
|
+
setQuery: react7.Dispatch<react7.SetStateAction<string>>;
|
228
207
|
};
|
229
|
-
|
230
208
|
//#endregion
|
231
209
|
//#region src/hooks/useSearchParams.d.ts
|
232
210
|
type UseSearchParamsOptions = LocationStoreOptions & {
|
@@ -234,13 +212,12 @@ type UseSearchParamsOptions = LocationStoreOptions & {
|
|
234
212
|
};
|
235
213
|
declare const useSearchParams: <TSearchParams extends URLSearchParamsInit>(options?: UseSearchParamsOptions) => readonly [URLSearchParams, {
|
236
214
|
(newQueryParams: TSearchParams | ((prev: URLSearchParams) => TSearchParams)): void;
|
237
|
-
triggerPopstateEvent: (nextLocationState?:
|
215
|
+
triggerPopstateEvent: (nextLocationState?: _zayne_labs_toolkit_core14.LocationInfo["state"]) => void;
|
238
216
|
}];
|
239
217
|
declare const useSearchParamsObject: <TSearchParams extends Record<string, string>>(options?: UseSearchParamsOptions) => readonly [TSearchParams, {
|
240
218
|
(newQueryParams: TSearchParams | ((prev: TSearchParams) => TSearchParams)): void;
|
241
|
-
triggerPopstateEvent: (nextLocationState?:
|
219
|
+
triggerPopstateEvent: (nextLocationState?: _zayne_labs_toolkit_core14.LocationInfo["state"]) => void;
|
242
220
|
}];
|
243
|
-
|
244
221
|
//#endregion
|
245
222
|
//#region src/hooks/useStorageState.d.ts
|
246
223
|
type UseStorageResult<TState, TSlice = TState> = [state: TSlice, actions: StorageStoreApi<TState>];
|
@@ -255,11 +232,9 @@ type UseStorageStateOptions<TValue> = Omit<StorageOptions<TValue>, "initialValue
|
|
255
232
|
declare const useStorageState: <TValue, TSlice = TValue>(key: string, initialValue?: TValue, options?: UseStorageStateOptions<TValue> & {
|
256
233
|
select?: SelectorFn<TValue, TSlice>;
|
257
234
|
}) => UseStorageResult<TValue, TSlice>;
|
258
|
-
|
259
235
|
//#endregion
|
260
236
|
//#region src/hooks/useStore.d.ts
|
261
237
|
declare const useStore: <TState, TSlice>(store: StoreApi<TState>, selector?: SelectorFn<TState, TSlice>) => TSlice;
|
262
|
-
|
263
238
|
//#endregion
|
264
239
|
//#region src/hooks/useThrottle.d.ts
|
265
240
|
declare const useThrottleBySetTimeout: <TParams>(callbackFn: CallbackFn<TParams>, delay: number) => {
|
@@ -271,7 +246,6 @@ declare const useThrottleByFrame: <TParams>(callbackFn: CallbackFn<TParams>) =>
|
|
271
246
|
(...params: TParams[]): void;
|
272
247
|
cancelAnimation(): void;
|
273
248
|
};
|
274
|
-
|
275
249
|
//#endregion
|
276
|
-
export { ContextError
|
277
|
-
//# sourceMappingURL=index-
|
250
|
+
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 };
|
251
|
+
//# sourceMappingURL=index-DasjkKek.d.ts.map
|
@@ -14,12 +14,10 @@ declare const setRef: <TRef extends HTMLElement>(ref: PossibleRef<TRef>, node: T
|
|
14
14
|
*/
|
15
15
|
declare const composeRefs: <TRef extends HTMLElement>(...refs: Array<PossibleRef<TRef>>) => RefCallback<TRef>;
|
16
16
|
declare const useComposeRefs: <TRef extends HTMLElement>(...refs: Array<PossibleRef<TRef>>) => () => RefCallback<TRef>;
|
17
|
-
|
18
17
|
//#endregion
|
19
18
|
//#region src/utils/composeEventHandlers.d.ts
|
20
19
|
declare const composeTwoEventHandlers: (formerHandler: AnyFunction | undefined, latterHandler: AnyFunction | undefined) => (event: unknown) => unknown;
|
21
20
|
declare const composeEventHandlers: (...eventHandlerArray: Array<AnyFunction | undefined>) => (event: unknown) => unknown;
|
22
|
-
|
23
21
|
//#endregion
|
24
22
|
//#region src/utils/mergeProps.d.ts
|
25
23
|
type UnionToIntersection<TUnion> = (TUnion extends unknown ? (param: TUnion) => void : "") extends ((param: infer TParam) => void) ? TParam : "";
|
@@ -38,11 +36,9 @@ type UnionToIntersection<TUnion> = (TUnion extends unknown ? (param: TUnion) =>
|
|
38
36
|
* @returns the merged props.
|
39
37
|
*/
|
40
38
|
declare const mergeProps: <TProps extends Record<never, never>>(...propsObjectArray: Array<TProps | undefined>) => UnionToIntersection<TProps>;
|
41
|
-
|
42
39
|
//#endregion
|
43
40
|
//#region src/utils/mergeTwoProps.d.ts
|
44
41
|
declare const mergeTwoProps: <TProps extends Record<never, never>>(formerProps: TProps | undefined, latterProps: TProps | undefined) => TProps;
|
45
|
-
|
46
42
|
//#endregion
|
47
43
|
//#region src/utils/types/common.d.ts
|
48
44
|
type ForwardedRefType<TComponent extends HTMLElement | React.ElementType> = TComponent extends React.ElementType ? React.ForwardedRef<React.Ref<TComponent>> : React.ForwardedRef<TComponent>;
|
@@ -64,7 +60,6 @@ type DiscriminatedRenderProps<TRenderPropType, TErrorMessages extends Record<"ch
|
|
64
60
|
}, {
|
65
61
|
render: TRenderPropType;
|
66
62
|
}], TErrorMessages>;
|
67
|
-
|
68
63
|
//#endregion
|
69
64
|
//#region src/utils/types/polymorphism.d.ts
|
70
65
|
type AsProp<TElement extends React.ElementType> = {
|
@@ -73,7 +68,6 @@ type AsProp<TElement extends React.ElementType> = {
|
|
73
68
|
type InferRemainingProps<TElement extends React.ElementType, TProps> = Omit<InferProps<TElement>, keyof TProps>;
|
74
69
|
type MergedGivenPropsWithAs<TElement extends React.ElementType, TProps> = Prettify<Omit<AsProp<TElement>, keyof TProps> & TProps>;
|
75
70
|
type PolymorphicProps<TElement extends React.ElementType, TProps extends AnyObject = NonNullable<unknown>> = MergedGivenPropsWithAs<TElement, TProps> & InferRemainingProps<TElement, TProps>;
|
76
|
-
|
77
71
|
//#endregion
|
78
72
|
export { AsProp, CssWithCustomProperties, DiscriminatedRenderProps, ForwardedRefType, InferProps, PolymorphicProps, StateSetter, composeEventHandlers, composeRefs, composeTwoEventHandlers, mergeProps, mergeTwoProps, setRef, useComposeRefs };
|
79
73
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import { CustomContextOptions } from "../index-
|
1
|
+
import { CustomContextOptions } from "../index-DasjkKek.js";
|
2
2
|
import { AnyObject, Prettify, SelectorFn } from "@zayne-labs/toolkit-type-helpers";
|
3
3
|
import * as react0 from "react";
|
4
4
|
import { StoreApi } from "@zayne-labs/toolkit-core";
|
5
5
|
import * as zustand2 from "zustand";
|
6
|
-
import { Mutate, StateCreator, StoreApi as StoreApi$1, StoreMutatorIdentifier, UseBoundStore } from "zustand";
|
6
|
+
import { Mutate, StateCreator as StateCreator$1, StoreApi as StoreApi$1, StoreMutatorIdentifier, UseBoundStore } from "zustand";
|
7
7
|
|
8
8
|
//#region src/zustand/createZustandContext.d.ts
|
9
9
|
declare const createZustandContext: <TState extends Record<string, unknown>, TUseBoundStore extends UseBoundStore<StoreApi$1<TState>> = UseBoundStore<StoreApi$1<TState>>, TStore extends StoreApi$1<TState> = StoreApi$1<TState>>(options?: CustomContextOptions<TUseBoundStore, true>) => [ZustandProvider: (props: ({
|
@@ -21,31 +21,28 @@ declare const createZustandContext: <TState extends Record<string, unknown>, TUs
|
|
21
21
|
}) & {
|
22
22
|
children: React.ReactNode;
|
23
23
|
}) => react0.DetailedReactHTMLElement<react0.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, useBoundStore: <TResult = TState>(selector?: SelectorFn<TState, TResult>) => TResult];
|
24
|
-
|
25
24
|
//#endregion
|
26
25
|
//#region src/zustand/createZustandStoreWithCombine.d.ts
|
27
26
|
type Write<TInitialState, TExtraState> = Prettify<Omit<TInitialState, keyof TExtraState> & TExtraState>;
|
28
|
-
declare const combine: <TInitialState extends AnyObject, TExtraState extends AnyObject, Mps extends Array<[StoreMutatorIdentifier, unknown]> = [], Mcs extends Array<[StoreMutatorIdentifier, unknown]> = []>(initialState: TInitialState, storeCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>) => StateCreator<Write<TInitialState, TExtraState>, Mps, Mcs>;
|
27
|
+
declare const combine: <TInitialState extends AnyObject, TExtraState extends AnyObject, Mps extends Array<[StoreMutatorIdentifier, unknown]> = [], Mcs extends Array<[StoreMutatorIdentifier, unknown]> = []>(initialState: TInitialState, storeCreator: StateCreator$1<TInitialState, Mps, Mcs, TExtraState>) => StateCreator$1<Write<TInitialState, TExtraState>, Mps, Mcs>;
|
29
28
|
declare const createStoreWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) => zustand2.StoreApi<Omit<TInitialState, keyof TExtraState> & TExtraState extends infer T ? { [Key in keyof T]: (Omit<TInitialState, keyof TExtraState> & TExtraState)[Key] } : never>;
|
30
29
|
declare const createWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) => zustand2.UseBoundStore<zustand2.StoreApi<Omit<TInitialState, keyof TExtraState> & TExtraState extends infer T ? { [Key in keyof T]: (Omit<TInitialState, keyof TExtraState> & TExtraState)[Key] } : never>>;
|
31
|
-
|
32
30
|
//#endregion
|
33
31
|
//#region src/zustand/createZustandStoreWithSubscribe.d.ts
|
34
32
|
type Get<T, K, F> = K extends keyof T ? T[K] : F;
|
35
|
-
type StateCreator
|
33
|
+
type StateCreator<T, Mis extends Array<[StoreMutatorIdentifier, unknown]> = [], Mos extends Array<[StoreMutatorIdentifier, unknown]> = [], U = T> = {
|
36
34
|
$$storeMutators?: Mos;
|
37
35
|
} & ((setState: Get<Mutate<StoreApi<T>, Mis>, "setState", never>, getState: Get<Mutate<StoreApi<T>, Mis>, "getState", never>, store: Mutate<StoreApi<T>, Mis>) => U);
|
38
36
|
type CreateStoreWithSubscribe = {
|
39
|
-
<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator
|
40
|
-
<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator
|
37
|
+
<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>): Mutate<StoreApi<T>, Mos>;
|
38
|
+
<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>) => Mutate<StoreApi<T>, Mos>;
|
41
39
|
};
|
42
40
|
declare const createStoreWithSubscribe: CreateStoreWithSubscribe;
|
43
41
|
type CreateWithSubscribe = {
|
44
|
-
<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator
|
45
|
-
<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator
|
42
|
+
<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>): UseBoundStore<Mutate<StoreApi<T>, Mos>>;
|
43
|
+
<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>) => UseBoundStore<Mutate<StoreApi<T>, Mos>>;
|
46
44
|
};
|
47
45
|
declare const createWithSubscribe: CreateWithSubscribe;
|
48
|
-
|
49
46
|
//#endregion
|
50
|
-
export { combine, createStoreWithCombine, createStoreWithSubscribe, createWithCombine, createWithSubscribe, createZustandContext };
|
47
|
+
export { StateCreator, combine, createStoreWithCombine, createStoreWithSubscribe, createWithCombine, createWithSubscribe, createZustandContext };
|
51
48
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","names":["options?: CustomContextOptions<TUseBoundStore, true>","props: ZustandProviderProps","useBoundStore","selector: SelectorFn<TState, unknown>","selector?: SelectorFn<TState, TResult>","initialState: TInitialState","storeCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>","stateInitializer: StateCreator<TState> | undefined","createState: StateCreator<TState>","selector?: SelectorFn<TState, unknown>"],"sources":["../../../src/zustand/createZustandContext.ts","../../../src/zustand/createZustandStoreWithCombine.ts","../../../src/zustand/createZustandStoreWithSubscribe.ts"],"sourcesContent":["import type { SelectorFn, UnionDiscriminator } from \"@zayne-labs/toolkit-type-helpers\";\nimport { createElement } from \"react\";\nimport { type StoreApi, type UseBoundStore, useStore } from \"zustand\";\nimport { type CustomContextOptions, createCustomContext, useConstant } from \"../hooks\";\n\nconst createZustandContext = <\n\tTState extends Record<string, unknown>,\n\tTUseBoundStore extends UseBoundStore<StoreApi<TState>> = UseBoundStore<StoreApi<TState>>,\n\tTStore extends StoreApi<TState> = StoreApi<TState>,\n>(\n\toptions?: CustomContextOptions<TUseBoundStore, true>\n) => {\n\tconst [Provider, useCustomContext] = createCustomContext(options);\n\n\ttype ZustandProviderProps = UnionDiscriminator<\n\t\t[{ store: TStore }, { storeCreator: () => TUseBoundStore }, { value: TUseBoundStore }]\n\t> & { children: React.ReactNode };\n\n\tfunction ZustandProvider(props: ZustandProviderProps) {\n\t\tconst { children, store, storeCreator, value } = props;\n\n\t\tconst useZustandStore = useConstant(() => {\n\t\t\tswitch (true) {\n\t\t\t\tcase Boolean(storeCreator): {\n\t\t\t\t\treturn storeCreator();\n\t\t\t\t}\n\t\t\t\tcase Boolean(value): {\n\t\t\t\t\treturn value;\n\t\t\t\t}\n\t\t\t\tcase Boolean(store): {\n\t\t\t\t\tconst useBoundStore = (selector: SelectorFn<TState, unknown>) => useStore(store, selector);\n\t\t\t\t\tObject.assign(useBoundStore, store);\n\t\t\t\t\treturn useBoundStore as TUseBoundStore;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new Error(\"No store provided\");\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\treturn createElement(Provider, { value: useZustandStore }, children);\n\t}\n\n\tconst useBoundStore = <TResult = TState>(selector?: SelectorFn<TState, TResult>): TResult => {\n\t\tconst useZustandStore = useCustomContext();\n\n\t\treturn useZustandStore(selector as never);\n\t};\n\n\treturn [ZustandProvider, useBoundStore] as [\n\t\tZustandProvider: typeof ZustandProvider,\n\t\tuseBoundStore: typeof useBoundStore,\n\t];\n};\n\nexport { createZustandContext };\n","import type { AnyFunction, AnyObject, Prettify } from \"@zayne-labs/toolkit-type-helpers\";\nimport { type StateCreator, type StoreMutatorIdentifier, create, createStore } from \"zustand\";\n\ntype Write<TInitialState, TExtraState> = Prettify<Omit<TInitialState, keyof TExtraState> & TExtraState>;\n\nexport const combine =\n\t<\n\t\tTInitialState extends AnyObject,\n\t\tTExtraState extends AnyObject,\n\t\tMps extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\t\tMcs extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\t>(\n\t\tinitialState: TInitialState,\n\t\tstoreCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>\n\t): StateCreator<Write<TInitialState, TExtraState>, Mps, Mcs> =>\n\t// eslint-disable-next-line ts-eslint/no-unsafe-return -- We don't know what the storeCreator will return\n\t(...params) => ({\n\t\t...initialState,\n\t\t...(storeCreator as AnyFunction)(...params),\n\t});\n\nexport const createStoreWithCombine = <TInitialState extends AnyObject, TExtraState extends AnyObject>(\n\t...params: Parameters<typeof combine<TInitialState, TExtraState>>\n) => createStore(combine(...params));\n\nexport const createWithCombine = <TInitialState extends AnyObject, TExtraState extends AnyObject>(\n\t...params: Parameters<typeof combine<TInitialState, TExtraState>>\n) => create(combine(...params));\n","import { useStore } from \"@/hooks\";\nimport { type StoreApi, createStore } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport type { Mutate, StoreMutatorIdentifier, UseBoundStore } from \"zustand\";\n\ntype Get<T, K, F> = K extends keyof T ? T[K] : F;\n\
|
1
|
+
{"version":3,"file":"index.js","names":["options?: CustomContextOptions<TUseBoundStore, true>","props: ZustandProviderProps","useBoundStore","selector: SelectorFn<TState, unknown>","selector?: SelectorFn<TState, TResult>","initialState: TInitialState","storeCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>","stateInitializer: StateCreator<TState> | undefined","createState: StateCreator<TState>","selector?: SelectorFn<TState, unknown>"],"sources":["../../../src/zustand/createZustandContext.ts","../../../src/zustand/createZustandStoreWithCombine.ts","../../../src/zustand/createZustandStoreWithSubscribe.ts"],"sourcesContent":["import type { SelectorFn, UnionDiscriminator } from \"@zayne-labs/toolkit-type-helpers\";\nimport { createElement } from \"react\";\nimport { type StoreApi, type UseBoundStore, useStore } from \"zustand\";\nimport { type CustomContextOptions, createCustomContext, useConstant } from \"../hooks\";\n\nconst createZustandContext = <\n\tTState extends Record<string, unknown>,\n\tTUseBoundStore extends UseBoundStore<StoreApi<TState>> = UseBoundStore<StoreApi<TState>>,\n\tTStore extends StoreApi<TState> = StoreApi<TState>,\n>(\n\toptions?: CustomContextOptions<TUseBoundStore, true>\n) => {\n\tconst [Provider, useCustomContext] = createCustomContext(options);\n\n\ttype ZustandProviderProps = UnionDiscriminator<\n\t\t[{ store: TStore }, { storeCreator: () => TUseBoundStore }, { value: TUseBoundStore }]\n\t> & { children: React.ReactNode };\n\n\tfunction ZustandProvider(props: ZustandProviderProps) {\n\t\tconst { children, store, storeCreator, value } = props;\n\n\t\tconst useZustandStore = useConstant(() => {\n\t\t\tswitch (true) {\n\t\t\t\tcase Boolean(storeCreator): {\n\t\t\t\t\treturn storeCreator();\n\t\t\t\t}\n\t\t\t\tcase Boolean(value): {\n\t\t\t\t\treturn value;\n\t\t\t\t}\n\t\t\t\tcase Boolean(store): {\n\t\t\t\t\tconst useBoundStore = (selector: SelectorFn<TState, unknown>) => useStore(store, selector);\n\t\t\t\t\tObject.assign(useBoundStore, store);\n\t\t\t\t\treturn useBoundStore as TUseBoundStore;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new Error(\"No store provided\");\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\treturn createElement(Provider, { value: useZustandStore }, children);\n\t}\n\n\tconst useBoundStore = <TResult = TState>(selector?: SelectorFn<TState, TResult>): TResult => {\n\t\tconst useZustandStore = useCustomContext();\n\n\t\treturn useZustandStore(selector as never);\n\t};\n\n\treturn [ZustandProvider, useBoundStore] as [\n\t\tZustandProvider: typeof ZustandProvider,\n\t\tuseBoundStore: typeof useBoundStore,\n\t];\n};\n\nexport { createZustandContext };\n","import type { AnyFunction, AnyObject, Prettify } from \"@zayne-labs/toolkit-type-helpers\";\nimport { type StateCreator, type StoreMutatorIdentifier, create, createStore } from \"zustand\";\n\ntype Write<TInitialState, TExtraState> = Prettify<Omit<TInitialState, keyof TExtraState> & TExtraState>;\n\nexport const combine =\n\t<\n\t\tTInitialState extends AnyObject,\n\t\tTExtraState extends AnyObject,\n\t\tMps extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\t\tMcs extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\t>(\n\t\tinitialState: TInitialState,\n\t\tstoreCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>\n\t): StateCreator<Write<TInitialState, TExtraState>, Mps, Mcs> =>\n\t// eslint-disable-next-line ts-eslint/no-unsafe-return -- We don't know what the storeCreator will return\n\t(...params) => ({\n\t\t...initialState,\n\t\t...(storeCreator as AnyFunction)(...params),\n\t});\n\nexport const createStoreWithCombine = <TInitialState extends AnyObject, TExtraState extends AnyObject>(\n\t...params: Parameters<typeof combine<TInitialState, TExtraState>>\n) => createStore(combine(...params));\n\nexport const createWithCombine = <TInitialState extends AnyObject, TExtraState extends AnyObject>(\n\t...params: Parameters<typeof combine<TInitialState, TExtraState>>\n) => create(combine(...params));\n","import { useStore } from \"@/hooks\";\nimport { type StoreApi, createStore } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport type { Mutate, StoreMutatorIdentifier, UseBoundStore } from \"zustand\";\n\ntype Get<T, K, F> = K extends keyof T ? T[K] : F;\n\nexport type StateCreator<\n\tT,\n\tMis extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\tMos extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\tU = T,\n> = { $$storeMutators?: Mos } & ((\n\tsetState: Get<Mutate<StoreApi<T>, Mis>, \"setState\", never>,\n\tgetState: Get<Mutate<StoreApi<T>, Mis>, \"getState\", never>,\n\tstore: Mutate<StoreApi<T>, Mis>\n) => U);\n\ntype CreateStoreWithSubscribe = {\n\t<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(\n\t\tinitializer: StateCreator<T, [], Mos>\n\t): Mutate<StoreApi<T>, Mos>;\n\n\t<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(\n\t\tinitializer: StateCreator<T, [], Mos>\n\t) => Mutate<StoreApi<T>, Mos>;\n};\n\nexport const createStoreWithSubscribe = (<TState>(stateInitializer: StateCreator<TState> | undefined) =>\n\tstateInitializer ? createStore(stateInitializer) : createStore) as CreateStoreWithSubscribe;\n\ntype CreateWithSubscribe = {\n\t<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(\n\t\tinitializer: StateCreator<T, [], Mos>\n\t): UseBoundStore<Mutate<StoreApi<T>, Mos>>;\n\t<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(\n\t\tinitializer: StateCreator<T, [], Mos>\n\t) => UseBoundStore<Mutate<StoreApi<T>, Mos>>;\n};\n\nconst createWithSubscribeImpl = <TState>(createState: StateCreator<TState>) => {\n\tconst store = createStore(createState);\n\n\tconst useBoundStore = (selector?: SelectorFn<TState, unknown>) => useStore(store, selector);\n\n\tObject.assign(useBoundStore, store);\n\n\treturn useBoundStore;\n};\n\nexport const createWithSubscribe = (<TState>(stateInitializer: StateCreator<TState> | undefined) =>\n\tstateInitializer\n\t\t? createWithSubscribeImpl(stateInitializer)\n\t\t: createWithSubscribeImpl) as CreateWithSubscribe;\n"],"mappings":";;;;;;AAKA,MAAM,uBAAuB,CAK5BA,YACI;CACJ,MAAM,CAAC,UAAU,iBAAiB,GAAG,oBAAoB,QAAQ;CAMjE,SAAS,gBAAgBC,OAA6B;EACrD,MAAM,EAAE,UAAU,OAAO,cAAc,OAAO,GAAG;EAEjD,MAAM,kBAAkB,YAAY,MAAM;AACzC,WAAQ,MAAR;IACC,KAAK,QAAQ,aAAa,CACzB,QAAO,cAAc;IAEtB,KAAK,QAAQ,MAAM,CAClB,QAAO;IAER,KAAK,QAAQ,MAAM,EAAE;KACpB,MAAMC,kBAAgB,CAACC,aAA0C,WAAS,OAAO,SAAS;AAC1F,YAAO,OAAOD,iBAAe,MAAM;AACnC,YAAOA;IACP;IACD,QACC,OAAM,IAAI,MAAM;GAEjB;EACD,EAAC;AAEF,SAAO,cAAc,UAAU,EAAE,OAAO,gBAAiB,GAAE,SAAS;CACpE;CAED,MAAM,gBAAgB,CAAmBE,aAAoD;EAC5F,MAAM,kBAAkB,kBAAkB;AAE1C,SAAO,gBAAgB,SAAkB;CACzC;AAED,QAAO,CAAC,iBAAiB,aAAc;AAIvC;;;;AChDD,MAAa,UACZ,CAMCC,cACAC,iBAGD,CAAC,GAAG,YAAY;CACf,GAAG;CACH,GAAG,AAAC,aAA6B,GAAG,OAAO;AAC3C;AAEF,MAAa,yBAAyB,CACrC,GAAG,WACC,cAAY,QAAQ,GAAG,OAAO,CAAC;AAEpC,MAAa,oBAAoB,CAChC,GAAG,WACC,OAAO,QAAQ,GAAG,OAAO,CAAC;;;;ACC/B,MAAa,2BAA4B,CAASC,qBACjD,mBAAmB,YAAY,iBAAiB,GAAG;AAWpD,MAAM,0BAA0B,CAASC,gBAAsC;CAC9E,MAAM,QAAQ,YAAY,YAAY;CAEtC,MAAM,gBAAgB,CAACC,aAA2C,SAAS,OAAO,SAAS;AAE3F,QAAO,OAAO,eAAe,MAAM;AAEnC,QAAO;AACP;AAED,MAAa,sBAAuB,CAASF,qBAC5C,mBACG,wBAAwB,iBAAiB,GACzC"}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@zayne-labs/toolkit-react",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.9.
|
4
|
+
"version": "0.9.48",
|
5
5
|
"description": "A collection of utility functions, types and composables used by my other projects. Nothing too fancy but can be useful.",
|
6
6
|
"author": "Ryan Zayne",
|
7
7
|
"license": "MIT",
|
@@ -47,8 +47,8 @@
|
|
47
47
|
}
|
48
48
|
},
|
49
49
|
"dependencies": {
|
50
|
-
"@zayne-labs/toolkit-core": "0.9.
|
51
|
-
"@zayne-labs/toolkit-type-helpers": "0.9.
|
50
|
+
"@zayne-labs/toolkit-core": "0.9.48",
|
51
|
+
"@zayne-labs/toolkit-type-helpers": "0.9.48"
|
52
52
|
},
|
53
53
|
"devDependencies": {
|
54
54
|
"@arethetypeswrong/cli": "^0.18.1",
|
@@ -56,17 +56,17 @@
|
|
56
56
|
"@size-limit/esbuild-why": "^11.2.0",
|
57
57
|
"@size-limit/preset-small-lib": "^11.2.0",
|
58
58
|
"@total-typescript/ts-reset": "^0.6.1",
|
59
|
-
"@types/node": "^22.15.
|
60
|
-
"@types/react": "^19.1.
|
61
|
-
"@zayne-labs/tsconfig": "0.
|
59
|
+
"@types/node": "^22.15.30",
|
60
|
+
"@types/react": "^19.1.6",
|
61
|
+
"@zayne-labs/tsconfig": "0.9.1",
|
62
62
|
"concurrently": "^9.1.2",
|
63
63
|
"cross-env": "^7.0.3",
|
64
64
|
"publint": "^0.3.12",
|
65
65
|
"react": "^19.1.0",
|
66
66
|
"size-limit": "^11.2.0",
|
67
|
-
"tsdown": "^0.12.
|
67
|
+
"tsdown": "^0.12.7",
|
68
68
|
"typescript": "5.8.3",
|
69
|
-
"zustand": "^5.0.
|
69
|
+
"zustand": "^5.0.5"
|
70
70
|
},
|
71
71
|
"publishConfig": {
|
72
72
|
"access": "public",
|