@zayne-labs/toolkit-react 0.9.56 → 0.9.57
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, 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-
|
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-5O_BGhd_.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,7 +1,7 @@
|
|
1
1
|
import { AnyFunction, CallbackFn, NonEmptyArray, Prettify, SelectorFn } from "@zayne-labs/toolkit-type-helpers";
|
2
2
|
import * as react5 from "react";
|
3
3
|
import { RefCallback, useEffect } from "react";
|
4
|
-
import * as
|
4
|
+
import * as _zayne_labs_toolkit_core15 from "@zayne-labs/toolkit-core";
|
5
5
|
import { AnimationIntervalOptions, LocationInfo, LocationStoreApi, LocationStoreOptions, ScrollObserverOptions, StorageOptions, StorageStoreApi, StoreApi, URLSearchParamsInit } from "@zayne-labs/toolkit-core";
|
6
6
|
|
7
7
|
//#region src/hooks/createCustomContext.d.ts
|
@@ -138,13 +138,13 @@ declare const useIsServer: () => boolean;
|
|
138
138
|
//#endregion
|
139
139
|
//#region src/hooks/useLocationState.d.ts
|
140
140
|
type UseLocationResult<TSlice> = [state: TSlice, actions: LocationStoreApi];
|
141
|
-
declare const createUseLocationState: (options?: LocationStoreOptions) => Omit<
|
142
|
-
push: (url: string |
|
143
|
-
state?:
|
141
|
+
declare const createUseLocationState: (options?: LocationStoreOptions) => Omit<_zayne_labs_toolkit_core15.StoreApi<_zayne_labs_toolkit_core15.URLInfoObject>, "setState" | "resetState"> & {
|
142
|
+
push: (url: string | _zayne_labs_toolkit_core15.PartialURLInfo, options?: {
|
143
|
+
state?: _zayne_labs_toolkit_core15.PartialURLInfo["state"];
|
144
144
|
}) => void;
|
145
145
|
replace: LocationStoreApi["push"];
|
146
146
|
triggerPopstateEvent: (nextLocationState?: LocationInfo["state"]) => void;
|
147
|
-
} & (<TSlice =
|
147
|
+
} & (<TSlice = _zayne_labs_toolkit_core15.URLInfoObject>(selector?: SelectorFn<LocationInfo, TSlice>) => UseLocationResult<TSlice>);
|
148
148
|
declare const useLocationState: <TSlice = LocationInfo>(selector?: SelectorFn<LocationInfo, TSlice>, options?: LocationStoreOptions) => UseLocationResult<TSlice>;
|
149
149
|
//#endregion
|
150
150
|
//#region src/hooks/useToggle.d.ts
|
@@ -208,11 +208,11 @@ type UseSearchParamsOptions = LocationStoreOptions & {
|
|
208
208
|
};
|
209
209
|
declare const useSearchParams: <TSearchParams extends URLSearchParamsInit>(options?: UseSearchParamsOptions) => readonly [URLSearchParams, {
|
210
210
|
(newQueryParams: TSearchParams | ((prev: URLSearchParams) => TSearchParams)): void;
|
211
|
-
triggerPopstateEvent: (nextLocationState?:
|
211
|
+
triggerPopstateEvent: (nextLocationState?: _zayne_labs_toolkit_core15.LocationInfo["state"]) => void;
|
212
212
|
}];
|
213
213
|
declare const useSearchParamsObject: <TSearchParams extends Record<string, string>>(options?: UseSearchParamsOptions) => readonly [TSearchParams, {
|
214
214
|
(newQueryParams: TSearchParams | ((prev: TSearchParams) => TSearchParams)): void;
|
215
|
-
triggerPopstateEvent: (nextLocationState?:
|
215
|
+
triggerPopstateEvent: (nextLocationState?: _zayne_labs_toolkit_core15.LocationInfo["state"]) => void;
|
216
216
|
}];
|
217
217
|
//#endregion
|
218
218
|
//#region src/hooks/useStorageState.d.ts
|
@@ -221,7 +221,7 @@ type UseStorageResult<TState, TSlice = TState> = [state: TSlice, actions: Storag
|
|
221
221
|
* @description Creates a custom hook that returns a storage state and actions to modify it. You can use this if you need shared options.
|
222
222
|
* @note You must use this if you want to be able to prevent syncing state across tabs.
|
223
223
|
*/
|
224
|
-
declare const createUseStorageState: <TState>(baseOptions: StorageOptions<TState>) =>
|
224
|
+
declare const createUseStorageState: <TState>(baseOptions: StorageOptions<TState>) => _zayne_labs_toolkit_core15.StoreApi<TState> & {
|
225
225
|
removeState: () => void;
|
226
226
|
} & (<TSlice = TState>(selector?: SelectorFn<TState, TSlice>) => UseStorageResult<TState, TSlice>);
|
227
227
|
type UseStorageStateOptions<TValue> = Omit<StorageOptions<TValue>, "initialValue" | "key">;
|
@@ -244,4 +244,4 @@ declare const useThrottleByFrame: <TParams>(callbackFn: CallbackFn<TParams>) =>
|
|
244
244
|
};
|
245
245
|
//#endregion
|
246
246
|
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 };
|
247
|
-
//# sourceMappingURL=index-
|
247
|
+
//# sourceMappingURL=index-5O_BGhd_.d.ts.map
|
@@ -1,20 +1,15 @@
|
|
1
|
-
import { CustomContextOptions } from "../index-
|
1
|
+
import { CustomContextOptions } from "../index-5O_BGhd_.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 as StateCreator$1,
|
6
|
+
import { Mutate, StateCreator as StateCreator$1, StoreMutatorIdentifier, UseBoundStore } from "zustand";
|
7
7
|
|
8
8
|
//#region src/zustand/createZustandContext.d.ts
|
9
|
-
declare const createZustandContext: <TState extends Record<string, unknown>, TStore extends StoreApi
|
10
|
-
store: TStore;
|
11
|
-
storeCreator?: undefined;
|
12
|
-
} | {
|
13
|
-
storeCreator: () => TStore;
|
14
|
-
store?: undefined;
|
15
|
-
}) & {
|
9
|
+
declare const createZustandContext: <TState extends Record<string, unknown>, TStore extends StoreApi<TState> = StoreApi<TState>>(options?: CustomContextOptions<TStore, true>) => [ZustandStoreContextProvider: (props: {
|
16
10
|
children: React.ReactNode;
|
17
|
-
|
11
|
+
store: TStore;
|
12
|
+
}) => react0.FunctionComponentElement<react0.ProviderProps<TStore | null>>, useZustandStoreContext: <TResult = TState>(selector?: SelectorFn<TState, TResult>) => TResult];
|
18
13
|
//#endregion
|
19
14
|
//#region src/zustand/createZustandStoreWithCombine.d.ts
|
20
15
|
type Write<TInitialState, TExtraState> = Prettify<Omit<TInitialState, keyof TExtraState> & TExtraState>;
|
@@ -1,25 +1,19 @@
|
|
1
1
|
import { createCustomContext, useConstant, useStore } from "../hooks-DjqgsmLX.js";
|
2
2
|
import { createElement } from "react";
|
3
3
|
import { createStore } from "@zayne-labs/toolkit-core";
|
4
|
-
import { create, createStore as createStore$1
|
4
|
+
import { create, createStore as createStore$1 } from "zustand";
|
5
5
|
|
6
6
|
//#region src/zustand/createZustandContext.ts
|
7
7
|
const createZustandContext = (options) => {
|
8
8
|
const [Provider, useCustomContext] = createCustomContext(options);
|
9
9
|
function ZustandStoreContextProvider(props) {
|
10
|
-
const { children, store
|
11
|
-
const
|
12
|
-
|
13
|
-
case Boolean(storeCreator): return storeCreator();
|
14
|
-
case Boolean(store): return store;
|
15
|
-
default: throw new Error("No store provided");
|
16
|
-
}
|
17
|
-
});
|
18
|
-
return createElement(Provider, { value: useZustandStore }, children);
|
10
|
+
const { children, store } = props;
|
11
|
+
const zustandStore = useConstant(() => store);
|
12
|
+
return createElement(Provider, { value: zustandStore }, children);
|
19
13
|
}
|
20
14
|
const useZustandStoreContext = (selector) => {
|
21
15
|
const zustandStore = useCustomContext();
|
22
|
-
return useStore
|
16
|
+
return useStore(zustandStore, selector);
|
23
17
|
};
|
24
18
|
return [ZustandStoreContextProvider, useZustandStoreContext];
|
25
19
|
};
|
@@ -1 +1 @@
|
|
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
|
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 } from \"@zayne-labs/toolkit-type-helpers\";\nimport { createElement } from \"react\";\nimport { type CustomContextOptions, createCustomContext, useConstant, useStore } from \"../hooks\";\nimport type { StoreApi } from \"@zayne-labs/toolkit-core\";\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\tconst zustandStore = useConstant(() => store);\n\n\t\treturn createElement(Provider, { value: zustandStore }, 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","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;CAOjE,SAAS,4BAA4BC,OAAyC;EAC7E,MAAM,EAAE,UAAU,OAAO,GAAG;EAE5B,MAAM,eAAe,YAAY,MAAM,MAAM;AAE7C,SAAO,cAAc,UAAU,EAAE,OAAO,aAAc,GAAE,SAAS;CACjE;CAED,MAAM,yBAAyB,CAAmBC,aAAoD;EACrG,MAAM,eAAe,kBAAkB;AAEvC,SAAO,SAAS,cAAc,SAAS;CACvC;AAED,QAAO,CAAC,6BAA6B,sBAAuB;AAI5D;;;;AC/BD,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.57",
|
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.57",
|
51
|
+
"@zayne-labs/toolkit-type-helpers": "0.9.57"
|
52
52
|
},
|
53
53
|
"devDependencies": {
|
54
54
|
"@arethetypeswrong/cli": "^0.18.2",
|