@zayne-labs/toolkit-react 0.9.30 → 0.9.32
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,8 +1,9 @@
|
|
1
1
|
import * as react from 'react';
|
2
2
|
import { SelectorFn, AnyObject, Prettify } from '@zayne-labs/toolkit-type-helpers';
|
3
3
|
import * as zustand from 'zustand';
|
4
|
-
import { UseBoundStore, StoreApi, StoreMutatorIdentifier, StateCreator } from 'zustand';
|
4
|
+
import { UseBoundStore, StoreApi, StoreMutatorIdentifier, StateCreator as StateCreator$1, Mutate } from 'zustand';
|
5
5
|
import { a as CustomContextOptions } from '../createCustomContext-x3pCDou7.js';
|
6
|
+
import { StoreApi as StoreApi$1 } from '@zayne-labs/toolkit-core';
|
6
7
|
|
7
8
|
declare const createZustandContext: <TState extends Record<string, unknown>, TUseBoundStore extends UseBoundStore<StoreApi<TState>> = UseBoundStore<StoreApi<TState>>, TStore extends StoreApi<TState> = StoreApi<TState>>(options?: CustomContextOptions<TUseBoundStore, true>) => [ZustandProvider: (props: ({
|
8
9
|
store: TStore;
|
@@ -21,8 +22,23 @@ declare const createZustandContext: <TState extends Record<string, unknown>, TUs
|
|
21
22
|
}) => react.FunctionComponentElement<react.ProviderProps<TUseBoundStore | null>>, useBoundStore: <TResult = TState>(selector?: SelectorFn<TState, TResult>) => TResult];
|
22
23
|
|
23
24
|
type Write<TInitialState, TExtraState> = Prettify<Omit<TInitialState, keyof TExtraState> & TExtraState>;
|
24
|
-
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>;
|
25
|
+
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>;
|
25
26
|
declare const createStoreWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) => zustand.StoreApi<Omit<TInitialState, keyof TExtraState> & TExtraState extends infer T ? { [Key in keyof T]: (Omit<TInitialState, keyof TExtraState> & TExtraState)[Key]; } : never>;
|
26
27
|
declare const createWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) => zustand.UseBoundStore<zustand.StoreApi<Omit<TInitialState, keyof TExtraState> & TExtraState extends infer T ? { [Key in keyof T]: (Omit<TInitialState, keyof TExtraState> & TExtraState)[Key]; } : never>>;
|
27
28
|
|
28
|
-
|
29
|
+
type Get<T, K, F> = K extends keyof T ? T[K] : F;
|
30
|
+
type StateCreator<T, Mis extends Array<[StoreMutatorIdentifier, unknown]> = [], Mos extends Array<[StoreMutatorIdentifier, unknown]> = [], U = T> = {
|
31
|
+
$$storeMutators?: Mos;
|
32
|
+
} & ((setState: Get<Mutate<StoreApi$1<T>, Mis>, "setState", never>, getState: Get<Mutate<StoreApi$1<T>, Mis>, "getState", never>, store: Mutate<StoreApi$1<T>, Mis>) => U);
|
33
|
+
type CreateStoreWithSubscribe = {
|
34
|
+
<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>): Mutate<StoreApi$1<T>, Mos>;
|
35
|
+
<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>) => Mutate<StoreApi$1<T>, Mos>;
|
36
|
+
};
|
37
|
+
declare const createStoreWithSubscribe: CreateStoreWithSubscribe;
|
38
|
+
type CreateWithSubscribe = {
|
39
|
+
<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>): UseBoundStore<Mutate<StoreApi$1<T>, Mos>>;
|
40
|
+
<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>) => UseBoundStore<Mutate<StoreApi$1<T>, Mos>>;
|
41
|
+
};
|
42
|
+
declare const createWithSubscribe: CreateWithSubscribe;
|
43
|
+
|
44
|
+
export { combine, createStoreWithCombine, createStoreWithSubscribe, createWithCombine, createWithSubscribe, createZustandContext };
|
@@ -1,6 +1,7 @@
|
|
1
|
-
import { createCustomContext, useConstant } from '../chunk-F46ZNZPZ.js';
|
1
|
+
import { createCustomContext, useStore, useConstant } from '../chunk-F46ZNZPZ.js';
|
2
2
|
import { createElement } from 'react';
|
3
|
-
import { createStore, create, useStore } from 'zustand';
|
3
|
+
import { createStore, create, useStore as useStore$1 } from 'zustand';
|
4
|
+
import { createStore as createStore$1 } from '@zayne-labs/toolkit-core';
|
4
5
|
|
5
6
|
var createZustandContext = (options) => {
|
6
7
|
const [Provider, useCustomContext] = createCustomContext(options);
|
@@ -15,7 +16,7 @@ var createZustandContext = (options) => {
|
|
15
16
|
return value;
|
16
17
|
}
|
17
18
|
case Boolean(store): {
|
18
|
-
const useBoundStore2 = (selector) => useStore(store, selector);
|
19
|
+
const useBoundStore2 = (selector) => useStore$1(store, selector);
|
19
20
|
Object.assign(useBoundStore2, store);
|
20
21
|
return useBoundStore2;
|
21
22
|
}
|
@@ -41,7 +42,15 @@ var combine = (initialState, storeCreator) => (
|
|
41
42
|
);
|
42
43
|
var createStoreWithCombine = (...params) => createStore(combine(...params));
|
43
44
|
var createWithCombine = (...params) => create(combine(...params));
|
45
|
+
var createStoreWithSubscribe = (stateInitializer) => stateInitializer ? createStore$1(stateInitializer) : createStore$1;
|
46
|
+
var createWithSubscribeImpl = (createState) => {
|
47
|
+
const store = createStore$1(createState);
|
48
|
+
const useBoundStore = (selector) => useStore(store, selector);
|
49
|
+
Object.assign(useBoundStore, store);
|
50
|
+
return useBoundStore;
|
51
|
+
};
|
52
|
+
var createWithSubscribe = (stateInitializer) => stateInitializer ? createWithSubscribeImpl(stateInitializer) : createWithSubscribeImpl;
|
44
53
|
|
45
|
-
export { combine, createStoreWithCombine, createWithCombine, createZustandContext };
|
54
|
+
export { combine, createStoreWithCombine, createStoreWithSubscribe, createWithCombine, createWithSubscribe, createZustandContext };
|
46
55
|
//# sourceMappingURL=index.js.map
|
47
56
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/zustand/createZustandContext.ts","../../../src/zustand/createZustandStoreWithCombine.ts"],"names":["useBoundStore"],"mappings":"
|
1
|
+
{"version":3,"sources":["../../../src/zustand/createZustandContext.ts","../../../src/zustand/createZustandStoreWithCombine.ts","../../../src/zustand/createZustandStoreWithSubscribe.ts"],"names":["useBoundStore","useStore","createStore"],"mappings":";;;;;AAKM,IAAA,oBAAA,GAAuB,CAK5B,OACI,KAAA;AACJ,EAAA,MAAM,CAAC,QAAA,EAAU,gBAAgB,CAAA,GAAI,oBAAoB,OAAO,CAAA;AAMhE,EAAA,SAAS,gBAAgB,KAA6B,EAAA;AACrD,IAAA,MAAM,EAAE,QAAA,EAAU,KAAO,EAAA,YAAA,EAAc,OAAU,GAAA,KAAA;AAEjD,IAAM,MAAA,eAAA,GAAkB,YAAY,MAAM;AACzC,MAAA,QAAQ,IAAM;AAAA,QACb,KAAK,OAAQ,CAAA,YAAY,CAAG,EAAA;AAC3B,UAAA,OAAO,YAAa,EAAA;AAAA;AACrB,QACA,KAAK,OAAQ,CAAA,KAAK,CAAG,EAAA;AACpB,UAAO,OAAA,KAAA;AAAA;AACR,QACA,KAAK,OAAQ,CAAA,KAAK,CAAG,EAAA;AACpB,UAAA,MAAMA,cAAgB,GAAA,CAAC,QAA0CC,KAAAA,UAAAA,CAAS,OAAO,QAAQ,CAAA;AACzF,UAAO,MAAA,CAAA,MAAA,CAAOD,gBAAe,KAA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scriminator } 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\ntype 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"]}
|
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.32",
|
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-
|
51
|
-
"@zayne-labs/toolkit-
|
50
|
+
"@zayne-labs/toolkit-core": "0.9.32",
|
51
|
+
"@zayne-labs/toolkit-type-helpers": "0.9.32"
|
52
52
|
},
|
53
53
|
"devDependencies": {
|
54
54
|
"@arethetypeswrong/cli": "^0.17.4",
|
@@ -85,7 +85,7 @@
|
|
85
85
|
},
|
86
86
|
{
|
87
87
|
"path": "./src/zustand/index.ts",
|
88
|
-
"limit": "
|
88
|
+
"limit": "2 kb"
|
89
89
|
}
|
90
90
|
],
|
91
91
|
"scripts": {
|