@zayne-labs/toolkit-react 0.9.52 → 0.9.54
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,32 +1,26 @@
|
|
1
1
|
import { CustomContextOptions } from "../index-DSea1K0S.js";
|
2
2
|
import { AnyObject, Prettify, SelectorFn } from "@zayne-labs/toolkit-type-helpers";
|
3
|
-
import * as
|
3
|
+
import * as react3 from "react";
|
4
4
|
import { StoreApi } from "@zayne-labs/toolkit-core";
|
5
|
-
import * as
|
5
|
+
import * as zustand0 from "zustand";
|
6
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
|
-
declare const createZustandContext: <TState extends Record<string, unknown>,
|
9
|
+
declare const createZustandContext: <TState extends Record<string, unknown>, TStore extends StoreApi$1<TState> = StoreApi$1<TState>>(options?: CustomContextOptions<TStore, true>) => [ZustandStoreContextProvider: (props: ({
|
10
10
|
store: TStore;
|
11
11
|
storeCreator?: undefined;
|
12
|
-
value?: undefined;
|
13
12
|
} | {
|
14
|
-
storeCreator: () =>
|
13
|
+
storeCreator: () => TStore;
|
15
14
|
store?: undefined;
|
16
|
-
value?: undefined;
|
17
|
-
} | {
|
18
|
-
value: TUseBoundStore;
|
19
|
-
store?: undefined;
|
20
|
-
storeCreator?: undefined;
|
21
15
|
}) & {
|
22
16
|
children: React.ReactNode;
|
23
|
-
}) =>
|
17
|
+
}) => react3.DetailedReactHTMLElement<react3.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, useZustandStoreContext: <TResult = TState>(selector?: SelectorFn<TState, TResult>) => TResult];
|
24
18
|
//#endregion
|
25
19
|
//#region src/zustand/createZustandStoreWithCombine.d.ts
|
26
20
|
type Write<TInitialState, TExtraState> = Prettify<Omit<TInitialState, keyof TExtraState> & TExtraState>;
|
27
21
|
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>;
|
28
|
-
declare const createStoreWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) =>
|
29
|
-
declare const createWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) =>
|
22
|
+
declare const createStoreWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) => zustand0.StoreApi<Omit<TInitialState, keyof TExtraState> & TExtraState extends infer T ? { [Key in keyof T]: (Omit<TInitialState, keyof TExtraState> & TExtraState)[Key] } : never>;
|
23
|
+
declare const createWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) => zustand0.UseBoundStore<zustand0.StoreApi<Omit<TInitialState, keyof TExtraState> & TExtraState extends infer T ? { [Key in keyof T]: (Omit<TInitialState, keyof TExtraState> & TExtraState)[Key] } : never>>;
|
30
24
|
//#endregion
|
31
25
|
//#region src/zustand/createZustandStoreWithSubscribe.d.ts
|
32
26
|
type Get<T, K, F> = K extends keyof T ? T[K] : F;
|
@@ -6,27 +6,22 @@ import { create, createStore as createStore$1, useStore as useStore$1 } from "zu
|
|
6
6
|
//#region src/zustand/createZustandContext.ts
|
7
7
|
const createZustandContext = (options) => {
|
8
8
|
const [Provider, useCustomContext] = createCustomContext(options);
|
9
|
-
function
|
10
|
-
const { children, store, storeCreator
|
9
|
+
function ZustandStoreContextProvider(props) {
|
10
|
+
const { children, store, storeCreator } = props;
|
11
11
|
const useZustandStore = useConstant(() => {
|
12
12
|
switch (true) {
|
13
13
|
case Boolean(storeCreator): return storeCreator();
|
14
|
-
case Boolean(
|
15
|
-
case Boolean(store): {
|
16
|
-
const useBoundStore$1 = (selector) => useStore$1(store, selector);
|
17
|
-
Object.assign(useBoundStore$1, store);
|
18
|
-
return useBoundStore$1;
|
19
|
-
}
|
14
|
+
case Boolean(store): return store;
|
20
15
|
default: throw new Error("No store provided");
|
21
16
|
}
|
22
17
|
});
|
23
18
|
return createElement(Provider, { value: useZustandStore }, children);
|
24
19
|
}
|
25
|
-
const
|
26
|
-
const
|
27
|
-
return
|
20
|
+
const useZustandStoreContext = (selector) => {
|
21
|
+
const zustandStore = useCustomContext();
|
22
|
+
return useStore$1(zustandStore, selector);
|
28
23
|
};
|
29
|
-
return [
|
24
|
+
return [ZustandStoreContextProvider, useZustandStoreContext];
|
30
25
|
};
|
31
26
|
|
32
27
|
//#endregion
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","names":["options?: CustomContextOptions<
|
1
|
+
{"version":3,"file":"index.js","names":["options?: CustomContextOptions<TStore, true>","props: ZustandStoreContextProviderProps","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, useStore } from \"zustand\";\nimport { type CustomContextOptions, createCustomContext, useConstant } 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 = UnionDiscriminator<\n\t\t[{ store: TStore }, { storeCreator: () => TStore }]\n\t> & { children: React.ReactNode };\n\n\tfunction ZustandStoreContextProvider(props: ZustandStoreContextProviderProps) {\n\t\tconst { children, store, storeCreator } = 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(store): {\n\t\t\t\t\treturn store;\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 useZustandStoreContext = <TResult = TState>(selector?: SelectorFn<TState, TResult>): TResult => {\n\t\tconst zustandStore = useCustomContext();\n\n\t\treturn useStore(zustandStore, selector as never);\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","import type { AnyFunction, AnyObject, Prettify } from \"@zayne-labs/toolkit-type-helpers\";\nimport { create, createStore, type StateCreator, type StoreMutatorIdentifier } 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 { createStore, type StoreApi } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport type { Mutate, StoreMutatorIdentifier, UseBoundStore } from \"zustand\";\nimport { useStore } from \"@/hooks\";\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\tcreateWithSubscribeImpl(stateInitializer)\n\t:\tcreateWithSubscribeImpl) as CreateWithSubscribe;\n"],"mappings":";;;;;;AAKA,MAAM,uBAAuB,CAI5BA,YACI;CACJ,MAAM,CAAC,UAAU,iBAAiB,GAAG,oBAAoB,QAAQ;CAMjE,SAAS,4BAA4BC,OAAyC;EAC7E,MAAM,EAAE,UAAU,OAAO,cAAc,GAAG;EAE1C,MAAM,kBAAkB,YAAY,MAAM;AACzC,WAAQ,MAAR;IACC,KAAK,QAAQ,aAAa,CACzB,QAAO,cAAc;IAEtB,KAAK,QAAQ,MAAM,CAClB,QAAO;IAER,QACC,OAAM,IAAI,MAAM;GAEjB;EACD,EAAC;AAEF,SAAO,cAAc,UAAU,EAAE,OAAO,gBAAiB,GAAE,SAAS;CACpE;CAED,MAAM,yBAAyB,CAAmBC,aAAoD;EACrG,MAAM,eAAe,kBAAkB;AAEvC,SAAO,WAAS,cAAc,SAAkB;CAChD;AAED,QAAO,CAAC,6BAA6B,sBAAuB;AAI5D;;;;AC1CD,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,mBACC,wBAAwB,iBAAiB,GACxC"}
|
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.54",
|
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.54",
|
51
|
+
"@zayne-labs/toolkit-type-helpers": "0.9.54"
|
52
52
|
},
|
53
53
|
"devDependencies": {
|
54
54
|
"@arethetypeswrong/cli": "^0.18.2",
|