@zayne-labs/toolkit-react 0.12.9 → 0.12.12
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/{createZustandContext-BWbr75p1.js → createReactStoreContext-Dbu--nQR.js} +4 -4
- package/dist/esm/createReactStoreContext-Dbu--nQR.js.map +1 -0
- package/dist/esm/hooks/index.d.ts +1 -1
- package/dist/esm/{index-BuczfOir.d.ts → index-Dlu-KFem.d.ts} +10 -10
- package/dist/esm/{types-DHraAX02.d.ts → types-DSkt-5Az.d.ts} +7 -7
- package/dist/esm/zustand/compatible/index.d.ts +5 -10
- package/dist/esm/zustand/compatible/index.js +2 -3
- package/dist/esm/zustand/compatible/index.js.map +1 -1
- package/dist/esm/zustand/index.d.ts +17 -0
- package/dist/esm/zustand/index.js +17 -0
- package/dist/esm/zustand/index.js.map +1 -0
- package/package.json +7 -7
- package/dist/esm/createZustandContext-BWbr75p1.js.map +0 -1
- package/dist/esm/zustand/new-implementation/index.d.ts +0 -22
- package/dist/esm/zustand/new-implementation/index.js +0 -18
- package/dist/esm/zustand/new-implementation/index.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { L as createCustomContext, m as useStore } from "./hooks-DtugZjSs.js";
|
|
2
2
|
import { createElement } from "react";
|
|
3
3
|
|
|
4
|
-
//#region src/zustand/
|
|
5
|
-
const
|
|
4
|
+
//#region src/zustand/createReactStoreContext.ts
|
|
5
|
+
const createReactStoreContext = (options) => {
|
|
6
6
|
const [Provider, useCustomContext] = createCustomContext(options);
|
|
7
7
|
function ZustandStoreContextProvider(props) {
|
|
8
8
|
const { children, store } = props;
|
|
@@ -15,5 +15,5 @@ const createZustandContext = (options) => {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
//#endregion
|
|
18
|
-
export {
|
|
19
|
-
//# sourceMappingURL=
|
|
18
|
+
export { createReactStoreContext as t };
|
|
19
|
+
//# sourceMappingURL=createReactStoreContext-Dbu--nQR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createReactStoreContext-Dbu--nQR.js","names":[],"sources":["../../src/zustand/createReactStoreContext.ts"],"sourcesContent":["import type { StoreApi } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { createElement } from \"react\";\nimport { type CustomContextOptions, createCustomContext, useStore } from \"../hooks\";\n\nconst createReactStoreContext = <\n\tTState extends Record<string, unknown>,\n\tTStore extends StoreApi<TState> = StoreApi<TState>,\n>(\n\toptions?: CustomContextOptions<TStore, true>\n) => {\n\tconst [Provider, useCustomContext] = createCustomContext(options);\n\n\ttype ZustandStoreContextProviderProps = {\n\t\tchildren: React.ReactNode;\n\t\tstore: TStore;\n\t};\n\n\tfunction ZustandStoreContextProvider(props: ZustandStoreContextProviderProps) {\n\t\tconst { children, store } = props;\n\n\t\treturn createElement(Provider, { value: store }, children);\n\t}\n\n\tconst useZustandStoreContext = <TResult = TState>(selector?: SelectorFn<TState, TResult>): TResult => {\n\t\tconst zustandStore = useCustomContext();\n\n\t\treturn useStore(zustandStore, selector);\n\t};\n\n\treturn [ZustandStoreContextProvider, useZustandStoreContext] as [\n\t\tZustandStoreContextProvider: typeof ZustandStoreContextProvider,\n\t\tuseZustandStoreContext: typeof useZustandStoreContext,\n\t];\n};\n\nexport { createReactStoreContext };\n"],"mappings":";;;;AAKA,MAAM,2BAIL,YACI;CACJ,MAAM,CAAC,UAAU,oBAAoB,oBAAoB,QAAQ;CAOjE,SAAS,4BAA4B,OAAyC;EAC7E,MAAM,EAAE,UAAU,UAAU;AAE5B,SAAO,cAAc,UAAU,EAAE,OAAO,OAAO,EAAE,SAAS;;CAG3D,MAAM,0BAA4C,aAAoD;AAGrG,SAAO,SAFc,kBAAkB,EAET,SAAS;;AAGxC,QAAO,CAAC,6BAA6B,uBAAuB"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { A as useUnmountEffect, B as getErrorMessage, C as useConstant, D as useCallbackRef, E as useClickOutside, F as useAfterMountEffect, I as ContextError, L as CustomContextOptions, M as useLifeCycle, N as useEffectOnce, O as useAnimationInterval, P as useAsyncEffect, R as UseCustomContext, S as useControllableState, T as useComposeRefs, _ as useDisclosure, a as useStore, b as useCopyToClipboard, c as useShallowCompSelector, d as useSearchParamsObject, f as useSearch, g as useIsHydrated, h as useLocationState, i as useThrottleByTimer, j as useMountEffect, k as useAnimateElementRefs, l as useShallowCompValue, m as createUseLocationState, n as useThrottleByFrame, o as createUseStorageState, p as useScrollObserver, r as useThrottleBySetTimeout, s as useStorageState, t as useToggle, u as useSearchParams, v as useDebouncedFn, w as useLazyRef, x as useControllableProp, y as useDebouncedState, z as createCustomContext } from "../index-
|
|
1
|
+
import { A as useUnmountEffect, B as getErrorMessage, C as useConstant, D as useCallbackRef, E as useClickOutside, F as useAfterMountEffect, I as ContextError, L as CustomContextOptions, M as useLifeCycle, N as useEffectOnce, O as useAnimationInterval, P as useAsyncEffect, R as UseCustomContext, S as useControllableState, T as useComposeRefs, _ as useDisclosure, a as useStore, b as useCopyToClipboard, c as useShallowCompSelector, d as useSearchParamsObject, f as useSearch, g as useIsHydrated, h as useLocationState, i as useThrottleByTimer, j as useMountEffect, k as useAnimateElementRefs, l as useShallowCompValue, m as createUseLocationState, n as useThrottleByFrame, o as createUseStorageState, p as useScrollObserver, r as useThrottleBySetTimeout, s as useStorageState, t as useToggle, u as useSearchParams, v as useDebouncedFn, w as useLazyRef, x as useControllableProp, y as useDebouncedState, z as createCustomContext } from "../index-Dlu-KFem.js";
|
|
2
2
|
import "../index--n6VOfXE.js";
|
|
3
3
|
export { ContextError, CustomContextOptions, UseCustomContext, createCustomContext, createUseLocationState, createUseStorageState, getErrorMessage, useAfterMountEffect, useAnimateElementRefs, useAnimationInterval, useAsyncEffect, useCallbackRef, useClickOutside, useComposeRefs, useConstant, useControllableProp, useControllableState, useCopyToClipboard, useDebouncedFn, useDebouncedState, useDisclosure, useEffectOnce, useIsHydrated, useLazyRef, useLifeCycle, useLocationState, useMountEffect, useScrollObserver, useSearch, useSearchParams, useSearchParamsObject, useShallowCompSelector, useShallowCompValue, useStorageState, useStore, useThrottleByFrame, useThrottleBySetTimeout, useThrottleByTimer, useToggle, useUnmountEffect };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { D as PossibleRef, f as StateSetter } from "./index--n6VOfXE.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react1 from "react";
|
|
3
3
|
import { RefCallback, useEffect } from "react";
|
|
4
4
|
import * as _zayne_labs_toolkit_core0 from "@zayne-labs/toolkit-core";
|
|
5
5
|
import { AllowedClipboardItems, AnimationIntervalOptions, CopyToClipboardOptions, LocationInfo, LocationStoreApi, LocationStoreOptions, ScrollObserverOptions, StorageOptions, StorageStoreApi, StoreApi, URLSearchParamsInit } from "@zayne-labs/toolkit-core";
|
|
@@ -16,7 +16,7 @@ type CustomContextOptions<TContextValue, TStrict extends boolean> = {
|
|
|
16
16
|
strict?: TStrict;
|
|
17
17
|
};
|
|
18
18
|
type UseCustomContext<TContextValue, TStrict extends boolean> = () => TStrict extends true ? TContextValue : TContextValue | null;
|
|
19
|
-
declare const createCustomContext: <TContextValue = null, TStrict extends boolean = true>(options?: CustomContextOptions<TContextValue, TStrict>) => [Provider:
|
|
19
|
+
declare const createCustomContext: <TContextValue = null, TStrict extends boolean = true>(options?: CustomContextOptions<TContextValue, TStrict>) => [Provider: react1.Context<TContextValue>, useCustomContext: UseCustomContext<TContextValue, TStrict>];
|
|
20
20
|
declare class ContextError extends Error {
|
|
21
21
|
name: string;
|
|
22
22
|
}
|
|
@@ -88,11 +88,11 @@ type UseClickOutsideOptions<TElement extends HTMLElement> = {
|
|
|
88
88
|
ref?: Array<React.RefObject<TElement>> | React.RefObject<TElement>;
|
|
89
89
|
};
|
|
90
90
|
declare const useClickOutside: <TElement extends HTMLElement>(options: UseClickOutsideOptions<TElement>) => {
|
|
91
|
-
ref:
|
|
91
|
+
ref: react1.RefObject<TElement | null>;
|
|
92
92
|
};
|
|
93
93
|
//#endregion
|
|
94
94
|
//#region src/hooks/useComposeRefs.d.ts
|
|
95
|
-
declare const useComposeRefs: <TRef extends HTMLElement>(...refs: Array<PossibleRef<TRef>>) =>
|
|
95
|
+
declare const useComposeRefs: <TRef extends HTMLElement>(...refs: Array<PossibleRef<TRef>>) => react1.RefCallback<TRef>;
|
|
96
96
|
//#endregion
|
|
97
97
|
//#region src/hooks/useConstant.d.ts
|
|
98
98
|
declare const useConstant: <TResult>(initFn: () => TResult) => TResult;
|
|
@@ -155,7 +155,7 @@ declare const useCopyToClipboard: (options?: CopyToClipboardOptions & {
|
|
|
155
155
|
}) => {
|
|
156
156
|
handleCopy: (valueToCopy: AllowedClipboardItems) => void;
|
|
157
157
|
hasCopied: boolean;
|
|
158
|
-
setValue:
|
|
158
|
+
setValue: react1.Dispatch<react1.SetStateAction<AllowedClipboardItems>>;
|
|
159
159
|
value: AllowedClipboardItems;
|
|
160
160
|
};
|
|
161
161
|
//#endregion
|
|
@@ -169,13 +169,13 @@ declare const useDebouncedFn: <TParams>(callBackFn: CallbackFn<TParams>, delay:
|
|
|
169
169
|
cancelMaxWait(): void;
|
|
170
170
|
};
|
|
171
171
|
declare const useDebouncedState: <TValue>(defaultValue: TValue, delay: number | undefined) => readonly [TValue, {
|
|
172
|
-
(...params:
|
|
173
|
-
(params:
|
|
172
|
+
(...params: react1.SetStateAction<TValue>[]): void;
|
|
173
|
+
(params: react1.SetStateAction<TValue> | react1.SetStateAction<TValue>[], overrideOptions: {
|
|
174
174
|
$delay: number;
|
|
175
175
|
}): void;
|
|
176
176
|
cancel: () => void;
|
|
177
177
|
cancelMaxWait(): void;
|
|
178
|
-
},
|
|
178
|
+
}, react1.Dispatch<react1.SetStateAction<TValue>>];
|
|
179
179
|
//#endregion
|
|
180
180
|
//#region src/hooks/useDisclosure.d.ts
|
|
181
181
|
type DisclosureOptions = {
|
|
@@ -237,7 +237,7 @@ declare const useSearch: <TData>(initialData: TData[], delay?: number) => {
|
|
|
237
237
|
data: TData[];
|
|
238
238
|
isLoading: boolean;
|
|
239
239
|
query: string;
|
|
240
|
-
setQuery:
|
|
240
|
+
setQuery: react1.Dispatch<react1.SetStateAction<string>>;
|
|
241
241
|
};
|
|
242
242
|
//#endregion
|
|
243
243
|
//#region src/hooks/useSearchParams.d.ts
|
|
@@ -284,4 +284,4 @@ type InitialState = boolean | (() => boolean);
|
|
|
284
284
|
declare const useToggle: (initialValue?: InitialState) => [value: boolean, toggleValue: <TValue>(newValue?: TValue) => void];
|
|
285
285
|
//#endregion
|
|
286
286
|
export { useUnmountEffect as A, getErrorMessage as B, useConstant as C, useCallbackRef as D, useClickOutside as E, useAfterMountEffect as F, ContextError as I, CustomContextOptions as L, useLifeCycle as M, useEffectOnce as N, useAnimationInterval as O, useAsyncEffect as P, UseCustomContext as R, useControllableState as S, useComposeRefs as T, useDisclosure as _, useStore as a, useCopyToClipboard as b, useShallowCompSelector as c, useSearchParamsObject as d, useSearch as f, useIsHydrated as g, useLocationState as h, useThrottleByTimer as i, useMountEffect as j, useAnimateElementRefs as k, useShallowCompValue as l, createUseLocationState as m, useThrottleByFrame as n, createUseStorageState as o, useScrollObserver as p, useThrottleBySetTimeout as r, useStorageState as s, useToggle as t, useSearchParams as u, useDebouncedFn as v, useLazyRef as w, useControllableProp as x, useDebouncedState as y, createCustomContext as z };
|
|
287
|
-
//# sourceMappingURL=index-
|
|
287
|
+
//# sourceMappingURL=index-Dlu-KFem.d.ts.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { L as CustomContextOptions } from "./index-
|
|
2
|
-
import * as
|
|
1
|
+
import { L as CustomContextOptions } from "./index-Dlu-KFem.js";
|
|
2
|
+
import * as react0 from "react";
|
|
3
3
|
import { StoreApi } from "@zayne-labs/toolkit-core";
|
|
4
4
|
import { SelectorFn } from "@zayne-labs/toolkit-type-helpers";
|
|
5
5
|
|
|
6
|
-
//#region src/zustand/
|
|
7
|
-
declare const
|
|
6
|
+
//#region src/zustand/createReactStoreContext.d.ts
|
|
7
|
+
declare const createReactStoreContext: <TState extends Record<string, unknown>, TStore extends StoreApi<TState> = StoreApi<TState>>(options?: CustomContextOptions<TStore, true>) => [ZustandStoreContextProvider: (props: {
|
|
8
8
|
children: React.ReactNode;
|
|
9
9
|
store: TStore;
|
|
10
|
-
}) =>
|
|
10
|
+
}) => react0.FunctionComponentElement<react0.ProviderProps<TStore>>, useZustandStoreContext: <TResult = TState>(selector?: SelectorFn<TState, TResult>) => TResult];
|
|
11
11
|
//#endregion
|
|
12
12
|
//#region src/zustand/types.d.ts
|
|
13
13
|
type Get<T$1, K, F> = K extends keyof T$1 ? T$1[K] : F;
|
|
@@ -23,5 +23,5 @@ type ReadonlyStoreApi<T$1> = Pick<StoreApi<T$1>, "getInitialState" | "getState"
|
|
|
23
23
|
interface StoreMutators<S, A> {}
|
|
24
24
|
type StoreMutatorIdentifier = keyof StoreMutators<unknown, unknown>;
|
|
25
25
|
//#endregion
|
|
26
|
-
export {
|
|
27
|
-
//# sourceMappingURL=types-
|
|
26
|
+
export { createReactStoreContext as a, UseBoundStore as i, Mutate as n, StoreMutatorIdentifier as r, Get as t };
|
|
27
|
+
//# sourceMappingURL=types-DSkt-5Az.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "../../index-
|
|
1
|
+
import "../../index-Dlu-KFem.js";
|
|
2
2
|
import "../../index--n6VOfXE.js";
|
|
3
|
-
import { a as
|
|
3
|
+
import { a as createReactStoreContext, i as UseBoundStore, t as Get } from "../../types-DSkt-5Az.js";
|
|
4
4
|
import { StoreApi } from "@zayne-labs/toolkit-core";
|
|
5
5
|
import { Mutate, StoreMutatorIdentifier } from "zustand";
|
|
6
6
|
|
|
@@ -8,16 +8,11 @@ import { Mutate, StoreMutatorIdentifier } from "zustand";
|
|
|
8
8
|
type StateCreator<T, Mis extends Array<[StoreMutatorIdentifier, unknown]> = [], Mos extends Array<[StoreMutatorIdentifier, unknown]> = [], U = T> = {
|
|
9
9
|
$$storeMutators?: Mos;
|
|
10
10
|
} & ((setState: Get<Mutate<StoreApi<T>, Mis>, "setState", never>, getState: Get<Mutate<StoreApi<T>, Mis>, "getState", never>, store: Mutate<StoreApi<T>, Mis>) => U);
|
|
11
|
-
type
|
|
12
|
-
<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>): Mutate<StoreApi<T>, Mos>;
|
|
13
|
-
<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>) => Mutate<StoreApi<T>, Mos>;
|
|
14
|
-
};
|
|
15
|
-
declare const createVanillaStore: CreateStoreWithSubscribe;
|
|
16
|
-
type CreateWithSubscribe = {
|
|
11
|
+
type CreateReactStore = {
|
|
17
12
|
<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>): UseBoundStore<Mutate<StoreApi<T>, Mos>>;
|
|
18
13
|
<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>) => UseBoundStore<Mutate<StoreApi<T>, Mos>>;
|
|
19
14
|
};
|
|
20
|
-
declare const createReactStore:
|
|
15
|
+
declare const createReactStore: CreateReactStore;
|
|
21
16
|
//#endregion
|
|
22
|
-
export { StateCreator, createReactStore,
|
|
17
|
+
export { StateCreator, createReactStore, createReactStoreContext };
|
|
23
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { m as useStore } from "../../hooks-DtugZjSs.js";
|
|
2
2
|
import "../../utils--Ucc0oql.js";
|
|
3
|
-
import { t as
|
|
3
|
+
import { t as createReactStoreContext } from "../../createReactStoreContext-Dbu--nQR.js";
|
|
4
4
|
import { createStore } from "@zayne-labs/toolkit-core";
|
|
5
5
|
|
|
6
6
|
//#region src/zustand/compatible/createReactStore.ts
|
|
7
|
-
const createVanillaStore = ((stateInitializer) => stateInitializer ? createStore(stateInitializer) : createStore);
|
|
8
7
|
const createReactStoreImpl = (createState) => {
|
|
9
8
|
const store = createStore(createState);
|
|
10
9
|
const useBoundStore = (selector) => useStore(store, selector);
|
|
@@ -14,5 +13,5 @@ const createReactStoreImpl = (createState) => {
|
|
|
14
13
|
const createReactStore = ((stateInitializer) => stateInitializer ? createReactStoreImpl(stateInitializer) : createReactStoreImpl);
|
|
15
14
|
|
|
16
15
|
//#endregion
|
|
17
|
-
export { createReactStore,
|
|
16
|
+
export { createReactStore, createReactStoreContext };
|
|
18
17
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/zustand/compatible/createReactStore.ts"],"sourcesContent":["import { createStore, type StoreApi } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport type { Mutate, StoreMutatorIdentifier } from \"zustand\";\nimport { useStore } from \"../../hooks\";\nimport type { Get, UseBoundStore } from \"../types\";\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
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/zustand/compatible/createReactStore.ts"],"sourcesContent":["import { createStore, type StoreApi } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport type { Mutate, StoreMutatorIdentifier } from \"zustand\";\nimport { useStore } from \"../../hooks\";\nimport type { Get, UseBoundStore } from \"../types\";\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 CreateReactStore = {\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 createReactStoreImpl = <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 createReactStore = (<TState>(stateInitializer: StateCreator<TState> | undefined) =>\n\tstateInitializer ? createReactStoreImpl(stateInitializer) : createReactStoreImpl) as CreateReactStore;\n"],"mappings":";;;;;;AA0BA,MAAM,wBAAgC,gBAAsC;CAC3E,MAAM,QAAQ,YAAY,YAAY;CAEtC,MAAM,iBAAiB,aAA2C,SAAS,OAAO,SAAS;AAE3F,QAAO,OAAO,eAAe,MAAM;AAEnC,QAAO;;AAGR,MAAa,qBAA6B,qBACzC,mBAAmB,qBAAqB,iBAAiB,GAAG"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import "../index-Dlu-KFem.js";
|
|
2
|
+
import "../index--n6VOfXE.js";
|
|
3
|
+
import { a as createReactStoreContext, i as UseBoundStore, n as Mutate, r as StoreMutatorIdentifier, t as Get } from "../types-DSkt-5Az.js";
|
|
4
|
+
import { StoreApi } from "@zayne-labs/toolkit-core";
|
|
5
|
+
|
|
6
|
+
//#region src/zustand/createReactStore.d.ts
|
|
7
|
+
type StateCreator<T, Mis extends Array<[StoreMutatorIdentifier, unknown]> = [], Mos extends Array<[StoreMutatorIdentifier, unknown]> = [], U = T> = {
|
|
8
|
+
$$storeMutators?: Mos;
|
|
9
|
+
} & ((setState: Get<Mutate<StoreApi<T>, Mis>, "setState", never>, getState: Get<Mutate<StoreApi<T>, Mis>, "getState", never>, store: Mutate<StoreApi<T>, Mis>) => U);
|
|
10
|
+
type CreateReactStore = {
|
|
11
|
+
<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>): UseBoundStore<Mutate<StoreApi<T>, Mos>>;
|
|
12
|
+
<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>) => UseBoundStore<Mutate<StoreApi<T>, Mos>>;
|
|
13
|
+
};
|
|
14
|
+
declare const createReactStore: CreateReactStore;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { StateCreator, createReactStore, createReactStoreContext };
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { m as useStore } from "../hooks-DtugZjSs.js";
|
|
2
|
+
import "../utils--Ucc0oql.js";
|
|
3
|
+
import { t as createReactStoreContext } from "../createReactStoreContext-Dbu--nQR.js";
|
|
4
|
+
import { createStore } from "@zayne-labs/toolkit-core";
|
|
5
|
+
|
|
6
|
+
//#region src/zustand/createReactStore.ts
|
|
7
|
+
const createReactStoreImpl = (createState) => {
|
|
8
|
+
const store = createStore(createState);
|
|
9
|
+
const useBoundStore = (selector) => useStore(store, selector);
|
|
10
|
+
Object.assign(useBoundStore, store);
|
|
11
|
+
return useBoundStore;
|
|
12
|
+
};
|
|
13
|
+
const createReactStore = ((stateInitializer) => stateInitializer ? createReactStoreImpl(stateInitializer) : createReactStoreImpl);
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { createReactStore, createReactStoreContext };
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/zustand/createReactStore.ts"],"sourcesContent":["import { createStore, type StoreApi } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useStore } from \"../hooks\";\nimport type { Get, Mutate, StoreMutatorIdentifier, UseBoundStore } from \"./types\";\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 CreateReactStore = {\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 createReactStoreImpl = <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 createReactStore = (<TState>(stateInitializer: StateCreator<TState> | undefined) =>\n\tstateInitializer ? createReactStoreImpl(stateInitializer) : createReactStoreImpl) as CreateReactStore;\n"],"mappings":";;;;;;AAyBA,MAAM,wBAAgC,gBAAsC;CAC3E,MAAM,QAAQ,YAAY,YAAY;CAEtC,MAAM,iBAAiB,aAA2C,SAAS,OAAO,SAAS;AAE3F,QAAO,OAAO,eAAe,MAAM;AAEnC,QAAO;;AAGR,MAAa,qBAA6B,qBACzC,mBAAmB,qBAAqB,iBAAiB,GAAG"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zayne-labs/toolkit-react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.12.
|
|
4
|
+
"version": "0.12.12",
|
|
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",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"exports": {
|
|
23
23
|
".": "./dist/esm/hooks/index.js",
|
|
24
24
|
"./utils": "./dist/esm/utils/index.js",
|
|
25
|
-
"./zustand": "./dist/esm/zustand/
|
|
25
|
+
"./zustand": "./dist/esm/zustand/index.js",
|
|
26
26
|
"./zustand-compat": "./dist/esm/zustand/compatible/index.js"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@zayne-labs/toolkit-
|
|
53
|
-
"@zayne-labs/toolkit-
|
|
52
|
+
"@zayne-labs/toolkit-type-helpers": "0.12.12",
|
|
53
|
+
"@zayne-labs/toolkit-core": "0.12.12"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"@size-limit/esbuild-why": "^11.2.0",
|
|
59
59
|
"@size-limit/preset-small-lib": "^11.2.0",
|
|
60
60
|
"@total-typescript/ts-reset": "^0.6.1",
|
|
61
|
-
"@types/node": "^24.9.
|
|
61
|
+
"@types/node": "^24.9.2",
|
|
62
62
|
"@types/react": "^19.2.2",
|
|
63
63
|
"@zayne-labs/tsconfig": "0.11.4",
|
|
64
64
|
"concurrently": "^9.2.1",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"react": "^19.2.0",
|
|
68
68
|
"size-limit": "^11.2.0",
|
|
69
69
|
"tailwind-merge": "3.3.1",
|
|
70
|
-
"tsdown": "^0.15.
|
|
70
|
+
"tsdown": "^0.15.12",
|
|
71
71
|
"typescript": "5.9.3",
|
|
72
72
|
"zustand": "^5.0.8"
|
|
73
73
|
},
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"limit": "2 kb"
|
|
87
87
|
},
|
|
88
88
|
{
|
|
89
|
-
"path": "./src/zustand/
|
|
89
|
+
"path": "./src/zustand/index.ts",
|
|
90
90
|
"limit": "2 kb"
|
|
91
91
|
}
|
|
92
92
|
],
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createZustandContext-BWbr75p1.js","names":[],"sources":["../../src/zustand/new-implementation/createZustandContext.ts"],"sourcesContent":["import type { StoreApi } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { createElement } from \"react\";\nimport { type CustomContextOptions, createCustomContext, useStore } from \"../../hooks\";\n\nconst createZustandContext = <\n\tTState extends Record<string, unknown>,\n\tTStore extends StoreApi<TState> = StoreApi<TState>,\n>(\n\toptions?: CustomContextOptions<TStore, true>\n) => {\n\tconst [Provider, useCustomContext] = createCustomContext(options);\n\n\ttype ZustandStoreContextProviderProps = {\n\t\tchildren: React.ReactNode;\n\t\tstore: TStore;\n\t};\n\n\tfunction ZustandStoreContextProvider(props: ZustandStoreContextProviderProps) {\n\t\tconst { children, store } = props;\n\n\t\treturn createElement(Provider, { value: store }, children);\n\t}\n\n\tconst useZustandStoreContext = <TResult = TState>(selector?: SelectorFn<TState, TResult>): TResult => {\n\t\tconst zustandStore = useCustomContext();\n\n\t\treturn useStore(zustandStore, selector);\n\t};\n\n\treturn [ZustandStoreContextProvider, useZustandStoreContext] as [\n\t\tZustandStoreContextProvider: typeof ZustandStoreContextProvider,\n\t\tuseZustandStoreContext: typeof useZustandStoreContext,\n\t];\n};\n\nexport { createZustandContext };\n"],"mappings":";;;;AAKA,MAAM,wBAIL,YACI;CACJ,MAAM,CAAC,UAAU,oBAAoB,oBAAoB,QAAQ;CAOjE,SAAS,4BAA4B,OAAyC;EAC7E,MAAM,EAAE,UAAU,UAAU;AAE5B,SAAO,cAAc,UAAU,EAAE,OAAO,OAAO,EAAE,SAAS;;CAG3D,MAAM,0BAA4C,aAAoD;AAGrG,SAAO,SAFc,kBAAkB,EAET,SAAS;;AAGxC,QAAO,CAAC,6BAA6B,uBAAuB"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import "../../index-BuczfOir.js";
|
|
2
|
-
import "../../index--n6VOfXE.js";
|
|
3
|
-
import { a as createZustandContext, i as UseBoundStore, n as Mutate, r as StoreMutatorIdentifier, t as Get } from "../../types-DHraAX02.js";
|
|
4
|
-
import { StoreApi } from "@zayne-labs/toolkit-core";
|
|
5
|
-
|
|
6
|
-
//#region src/zustand/new-implementation/createReactStore.d.ts
|
|
7
|
-
type StateCreator<T, Mis extends Array<[StoreMutatorIdentifier, unknown]> = [], Mos extends Array<[StoreMutatorIdentifier, unknown]> = [], U = T> = {
|
|
8
|
-
$$storeMutators?: Mos;
|
|
9
|
-
} & ((setState: Get<Mutate<StoreApi<T>, Mis>, "setState", never>, getState: Get<Mutate<StoreApi<T>, Mis>, "getState", never>, store: Mutate<StoreApi<T>, Mis>) => U);
|
|
10
|
-
type CreateStoreWithSubscribe = {
|
|
11
|
-
<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>): Mutate<StoreApi<T>, Mos>;
|
|
12
|
-
<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>) => Mutate<StoreApi<T>, Mos>;
|
|
13
|
-
};
|
|
14
|
-
declare const createVanillaStore: CreateStoreWithSubscribe;
|
|
15
|
-
type CreateWithSubscribe = {
|
|
16
|
-
<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>): UseBoundStore<Mutate<StoreApi<T>, Mos>>;
|
|
17
|
-
<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>) => UseBoundStore<Mutate<StoreApi<T>, Mos>>;
|
|
18
|
-
};
|
|
19
|
-
declare const createReactStore: CreateWithSubscribe;
|
|
20
|
-
//#endregion
|
|
21
|
-
export { StateCreator, createReactStore, createVanillaStore, createZustandContext };
|
|
22
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { m as useStore } from "../../hooks-DtugZjSs.js";
|
|
2
|
-
import "../../utils--Ucc0oql.js";
|
|
3
|
-
import { t as createZustandContext } from "../../createZustandContext-BWbr75p1.js";
|
|
4
|
-
import { createStore } from "@zayne-labs/toolkit-core";
|
|
5
|
-
|
|
6
|
-
//#region src/zustand/new-implementation/createReactStore.ts
|
|
7
|
-
const createVanillaStore = ((stateInitializer) => stateInitializer ? createStore(stateInitializer) : createStore);
|
|
8
|
-
const createReactStoreImpl = (createState) => {
|
|
9
|
-
const store = createStore(createState);
|
|
10
|
-
const useBoundStore = (selector) => useStore(store, selector);
|
|
11
|
-
Object.assign(useBoundStore, store);
|
|
12
|
-
return useBoundStore;
|
|
13
|
-
};
|
|
14
|
-
const createReactStore = ((stateInitializer) => stateInitializer ? createReactStoreImpl(stateInitializer) : createReactStoreImpl);
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
export { createReactStore, createVanillaStore, createZustandContext };
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/zustand/new-implementation/createReactStore.ts"],"sourcesContent":["import { createStore, type StoreApi } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useStore } from \"../../hooks\";\nimport type { Get, Mutate, StoreMutatorIdentifier, UseBoundStore } from \"../types\";\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 createVanillaStore = (<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 createReactStoreImpl = <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 createReactStore = (<TState>(stateInitializer: StateCreator<TState> | undefined) =>\n\tstateInitializer ?\n\t\tcreateReactStoreImpl(stateInitializer)\n\t:\tcreateReactStoreImpl) as CreateWithSubscribe;\n"],"mappings":";;;;;;AA0BA,MAAa,uBAA+B,qBAC3C,mBAAmB,YAAY,iBAAiB,GAAG;AAWpD,MAAM,wBAAgC,gBAAsC;CAC3E,MAAM,QAAQ,YAAY,YAAY;CAEtC,MAAM,iBAAiB,aAA2C,SAAS,OAAO,SAAS;AAE3F,QAAO,OAAO,eAAe,MAAM;AAEnC,QAAO;;AAGR,MAAa,qBAA6B,qBACzC,mBACC,qBAAqB,iBAAiB,GACrC"}
|