@zayne-labs/toolkit-react 0.11.20 → 0.12.0
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/hooks/createCustomContext.d.ts +2 -2
- package/dist/esm/hooks/useAnimateElementRefs.js.map +1 -1
- package/dist/esm/hooks/useClickOutside.d.ts +2 -2
- package/dist/esm/hooks/useComposeRefs.d.ts +2 -2
- package/dist/esm/hooks/useConstant.js.map +1 -1
- package/dist/esm/hooks/useCopyToClipboard.d.ts +2 -2
- package/dist/esm/hooks/useDebounce.d.ts +4 -4
- package/dist/esm/hooks/useLocationState.d.ts +5 -5
- package/dist/esm/hooks/useSearch.d.ts +2 -2
- package/dist/esm/hooks/useSearchParams.d.ts +3 -9
- package/dist/esm/hooks/useSearchParams.js +11 -5
- package/dist/esm/hooks/useSearchParams.js.map +1 -1
- package/dist/esm/hooks/useShallowCompare.js +6 -3
- package/dist/esm/hooks/useShallowCompare.js.map +1 -1
- package/dist/esm/hooks/useStorageState.d.ts +2 -2
- package/dist/esm/hooks/useStore.js +5 -1
- package/dist/esm/hooks/useStore.js.map +1 -1
- package/dist/esm/zustand/createReactZustandStore.js.map +1 -1
- package/dist/esm/zustand/createZustandContext.d.ts +2 -2
- package/dist/esm/zustand/createZustandStoreWithCombine.d.ts +4 -5
- package/dist/esm/zustand/createZustandStoreWithCombine.js.map +1 -1
- package/dist/esm/zustand/createZustandStoreWithSubscribe.d.ts +6 -10
- package/dist/esm/zustand/createZustandStoreWithSubscribe.js.map +1 -1
- package/dist/esm/zustand/index.d.ts +2 -2
- package/dist/esm/zustand/types.d.ts +20 -0
- package/package.json +11 -16
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react1 from "react";
|
|
2
2
|
|
|
3
3
|
//#region src/hooks/createCustomContext.d.ts
|
|
4
4
|
type CustomContextOptions<TContextValue, TStrict extends boolean> = {
|
|
@@ -11,7 +11,7 @@ type CustomContextOptions<TContextValue, TStrict extends boolean> = {
|
|
|
11
11
|
strict?: TStrict;
|
|
12
12
|
};
|
|
13
13
|
type UseCustomContext<TContextValue, TStrict extends boolean> = () => TStrict extends true ? TContextValue : TContextValue | null;
|
|
14
|
-
declare const createCustomContext: <TContextValue = null, TStrict extends boolean = true>(options?: CustomContextOptions<TContextValue, TStrict>) => [Provider:
|
|
14
|
+
declare const createCustomContext: <TContextValue = null, TStrict extends boolean = true>(options?: CustomContextOptions<TContextValue, TStrict>) => [Provider: react1.Context<TContextValue>, useCustomContext: UseCustomContext<TContextValue, TStrict>];
|
|
15
15
|
declare class ContextError extends Error {
|
|
16
16
|
name: string;
|
|
17
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAnimateElementRefs.js","names":[],"sources":["../../../src/hooks/useAnimateElementRefs.ts"],"sourcesContent":["import { on } from \"@zayne-labs/toolkit-core\";\nimport { type NonEmptyArray
|
|
1
|
+
{"version":3,"file":"useAnimateElementRefs.js","names":[],"sources":["../../../src/hooks/useAnimateElementRefs.ts"],"sourcesContent":["import { on } from \"@zayne-labs/toolkit-core\";\nimport { isArray, type NonEmptyArray } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useCallback, useRef } from \"react\";\nimport { useCallbackRef } from \"./useCallbackRef\";\n\ntype ElementsInfoArray<TTargetElement extends string> = NonEmptyArray<{\n\tanimationClass: string;\n\ttargetElement: TTargetElement;\n}>;\n\nconst removeClass = (target: HTMLElement, className: string) => () => target.classList.remove(className);\n\n/**\n * This is a custom React hook that adds and removes animation classes to specified HTML elements.\n * @param elementsInfoArray - An array of objects that contain information about the animation class and the target HTML element.\n * @returns - An object containing the refs of the animated elements and a function to handle the initiation and removal animation.\n */\n\nconst useAnimateElementRefs = <TTargetElement extends string>(\n\telementsInfoArray: ElementsInfoArray<TTargetElement>\n) => {\n\tconst elementsRef = useRef<Record<TTargetElement, HTMLElement | null>>({} as never);\n\n\tconst addAnimationClasses = useCallbackRef(() => {\n\t\tif (!isArray(elementsInfoArray)) {\n\t\t\tconsole.error(\"elementsInfo is not an Array\");\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const { animationClass, targetElement } of elementsInfoArray) {\n\t\t\tif (!elementsRef.current[targetElement]) {\n\t\t\t\tconsole.error(\"ElementError\", `\"${targetElement}\" element does not exist`);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\telementsRef.current[targetElement].classList.add(animationClass);\n\t\t}\n\t});\n\n\tconst removeAnimationClasses = useCallbackRef(() => {\n\t\tif (!isArray(elementsInfoArray)) {\n\t\t\tconsole.error(\"elementsInfo is not an Array\");\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const { animationClass, targetElement } of elementsInfoArray) {\n\t\t\tif (!elementsRef.current[targetElement]) {\n\t\t\t\tconsole.error(\"ElementError\", `\"${targetElement}\" element does not exist`);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\ton(\n\t\t\t\t\"transitionend\",\n\t\t\t\telementsRef.current[targetElement],\n\t\t\t\tremoveClass(elementsRef.current[targetElement], animationClass)\n\t\t\t);\n\n\t\t\ton(\n\t\t\t\t\"animationend\",\n\t\t\t\telementsRef.current[targetElement],\n\t\t\t\tremoveClass(elementsRef.current[targetElement], animationClass)\n\t\t\t);\n\t\t}\n\t});\n\n\t// Add animation classes to elements and remove them after the animation ends\n\tconst handleElementsAnimation = useCallback(() => {\n\t\taddAnimationClasses();\n\n\t\tremoveAnimationClasses();\n\t}, [addAnimationClasses, removeAnimationClasses]);\n\n\t// eslint-disable-next-line react-hooks/refs -- Allow this for convenience\n\treturn { animatedElements: elementsRef.current, handleElementsAnimation };\n};\n\nexport { useAnimateElementRefs };\n"],"mappings":";;;;;;AAUA,MAAM,eAAe,QAAqB,oBAA4B,OAAO,UAAU,OAAO,UAAU;;;;;;AAQxG,MAAM,yBACL,sBACI;CACJ,MAAM,cAAc,OAAmD,EAAE,CAAU;CAEnF,MAAM,sBAAsB,qBAAqB;AAChD,MAAI,CAAC,QAAQ,kBAAkB,EAAE;AAChC,WAAQ,MAAM,+BAA+B;AAC7C;;AAGD,OAAK,MAAM,EAAE,gBAAgB,mBAAmB,mBAAmB;AAClE,OAAI,CAAC,YAAY,QAAQ,gBAAgB;AACxC,YAAQ,MAAM,gBAAgB,IAAI,cAAc,0BAA0B;AAC1E;;AAGD,eAAY,QAAQ,eAAe,UAAU,IAAI,eAAe;;GAEhE;CAEF,MAAM,yBAAyB,qBAAqB;AACnD,MAAI,CAAC,QAAQ,kBAAkB,EAAE;AAChC,WAAQ,MAAM,+BAA+B;AAC7C;;AAGD,OAAK,MAAM,EAAE,gBAAgB,mBAAmB,mBAAmB;AAClE,OAAI,CAAC,YAAY,QAAQ,gBAAgB;AACxC,YAAQ,MAAM,gBAAgB,IAAI,cAAc,0BAA0B;AAC1E;;AAGD,MACC,iBACA,YAAY,QAAQ,gBACpB,YAAY,YAAY,QAAQ,gBAAgB,eAAe,CAC/D;AAED,MACC,gBACA,YAAY,QAAQ,gBACpB,YAAY,YAAY,QAAQ,gBAAgB,eAAe,CAC/D;;GAED;CAGF,MAAM,0BAA0B,kBAAkB;AACjD,uBAAqB;AAErB,0BAAwB;IACtB,CAAC,qBAAqB,uBAAuB,CAAC;AAGjD,QAAO;EAAE,kBAAkB,YAAY;EAAS;EAAyB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react3 from "react";
|
|
2
2
|
|
|
3
3
|
//#region src/hooks/useClickOutside.d.ts
|
|
4
4
|
type UseClickOutsideOptions<TElement extends HTMLElement> = {
|
|
@@ -7,7 +7,7 @@ type UseClickOutsideOptions<TElement extends HTMLElement> = {
|
|
|
7
7
|
ref?: Array<React.RefObject<TElement>> | React.RefObject<TElement>;
|
|
8
8
|
};
|
|
9
9
|
declare const useClickOutside: <TElement extends HTMLElement>(options: UseClickOutsideOptions<TElement>) => {
|
|
10
|
-
ref:
|
|
10
|
+
ref: react3.RefObject<TElement | null>;
|
|
11
11
|
};
|
|
12
12
|
//#endregion
|
|
13
13
|
export { useClickOutside };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { PossibleRef } from "../utils/composeRefs.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react2 from "react";
|
|
3
3
|
|
|
4
4
|
//#region src/hooks/useComposeRefs.d.ts
|
|
5
|
-
declare const useComposeRefs: <TRef extends HTMLElement>(...refs: Array<PossibleRef<TRef>>) =>
|
|
5
|
+
declare const useComposeRefs: <TRef extends HTMLElement>(...refs: Array<PossibleRef<TRef>>) => react2.RefCallback<TRef>;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { useComposeRefs };
|
|
8
8
|
//# sourceMappingURL=useComposeRefs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConstant.js","names":[],"sources":["../../../src/hooks/useConstant.ts"],"sourcesContent":["import { useRef } from \"react\";\n\nexport const useConstant = <TResult>(initFn: () => TResult): TResult => {\n\tconst resultRef = useRef<TResult | null>(null);\n\n\t// eslint-disable-next-line ts-eslint/prefer-nullish-coalescing -- The current case is justified since it's optimizable by the react compiler\n\tif (resultRef.current === null) {\n\t\tresultRef.current = initFn();\n\t}\n\n\treturn resultRef.current;\n};\n\nexport const useLazyRef = <TResult>(initFn: () => TResult): React.RefObject<TResult> => {\n\tconst resultRef = useRef<TResult>(null as never);\n\n\t// eslint-disable-next-line ts-eslint/prefer-nullish-coalescing -- The current case is justified since it's optimizable by the react compiler\n\tif (resultRef.current === null) {\n\t\tresultRef.current = initFn();\n\t}\n\n\treturn resultRef;\n};\n"],"mappings":";;;AAEA,MAAa,eAAwB,WAAmC;CACvE,MAAM,YAAY,OAAuB,KAAK;AAG9C,KAAI,UAAU,YAAY,KACzB,WAAU,UAAU,QAAQ;
|
|
1
|
+
{"version":3,"file":"useConstant.js","names":[],"sources":["../../../src/hooks/useConstant.ts"],"sourcesContent":["import { useRef } from \"react\";\n\nexport const useConstant = <TResult>(initFn: () => TResult): TResult => {\n\tconst resultRef = useRef<TResult | null>(null);\n\n\t// eslint-disable-next-line ts-eslint/prefer-nullish-coalescing -- The current case is justified since it's optimizable by the react compiler\n\tif (resultRef.current === null) {\n\t\tresultRef.current = initFn();\n\t}\n\n\t// eslint-disable-next-line react-hooks/refs -- Allow this for convenience\n\treturn resultRef.current;\n};\n\nexport const useLazyRef = <TResult>(initFn: () => TResult): React.RefObject<TResult> => {\n\tconst resultRef = useRef<TResult>(null as never);\n\n\t// eslint-disable-next-line ts-eslint/prefer-nullish-coalescing -- The current case is justified since it's optimizable by the react compiler\n\tif (resultRef.current === null) {\n\t\tresultRef.current = initFn();\n\t}\n\n\treturn resultRef;\n};\n"],"mappings":";;;AAEA,MAAa,eAAwB,WAAmC;CACvE,MAAM,YAAY,OAAuB,KAAK;AAG9C,KAAI,UAAU,YAAY,KACzB,WAAU,UAAU,QAAQ;AAI7B,QAAO,UAAU;;AAGlB,MAAa,cAAuB,WAAoD;CACvF,MAAM,YAAY,OAAgB,KAAc;AAGhD,KAAI,UAAU,YAAY,KACzB,WAAU,UAAU,QAAQ;AAG7B,QAAO"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react4 from "react";
|
|
2
2
|
import { AllowedClipboardItems, CopyToClipboardOptions } from "@zayne-labs/toolkit-core";
|
|
3
3
|
|
|
4
4
|
//#region src/hooks/useCopyToClipboard.d.ts
|
|
@@ -7,7 +7,7 @@ declare const useCopyToClipboard: (options?: CopyToClipboardOptions & {
|
|
|
7
7
|
}) => {
|
|
8
8
|
handleCopy: (valueToCopy: AllowedClipboardItems) => void;
|
|
9
9
|
hasCopied: boolean;
|
|
10
|
-
setValue:
|
|
10
|
+
setValue: react4.Dispatch<react4.SetStateAction<AllowedClipboardItems>>;
|
|
11
11
|
value: AllowedClipboardItems;
|
|
12
12
|
};
|
|
13
13
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react6 from "react";
|
|
2
2
|
import { CallbackFn } from "@zayne-labs/toolkit-type-helpers";
|
|
3
3
|
|
|
4
4
|
//#region src/hooks/useDebounce.d.ts
|
|
@@ -11,13 +11,13 @@ declare const useDebouncedFn: <TParams>(callBackFn: CallbackFn<TParams>, delay:
|
|
|
11
11
|
cancelMaxWait(): void;
|
|
12
12
|
};
|
|
13
13
|
declare const useDebouncedState: <TValue>(defaultValue: TValue, delay: number | undefined) => readonly [TValue, {
|
|
14
|
-
(...params:
|
|
15
|
-
(params:
|
|
14
|
+
(...params: react6.SetStateAction<TValue>[]): void;
|
|
15
|
+
(params: react6.SetStateAction<TValue> | react6.SetStateAction<TValue>[], overrideOptions: {
|
|
16
16
|
$delay: number;
|
|
17
17
|
}): void;
|
|
18
18
|
cancel: () => void;
|
|
19
19
|
cancelMaxWait(): void;
|
|
20
|
-
},
|
|
20
|
+
}, react6.Dispatch<react6.SetStateAction<TValue>>];
|
|
21
21
|
//#endregion
|
|
22
22
|
export { useDebouncedFn, useDebouncedState };
|
|
23
23
|
//# sourceMappingURL=useDebounce.d.ts.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _zayne_labs_toolkit_core1 from "@zayne-labs/toolkit-core";
|
|
2
2
|
import { LocationInfo, LocationStoreApi, LocationStoreOptions } from "@zayne-labs/toolkit-core";
|
|
3
3
|
import { SelectorFn } from "@zayne-labs/toolkit-type-helpers";
|
|
4
4
|
|
|
5
5
|
//#region src/hooks/useLocationState.d.ts
|
|
6
6
|
type UseLocationResult<TSlice> = [state: TSlice, actions: LocationStoreApi];
|
|
7
|
-
declare const createUseLocationState: (options?: LocationStoreOptions) => Omit<
|
|
8
|
-
push: (url: string |
|
|
9
|
-
state?:
|
|
7
|
+
declare const createUseLocationState: (options?: LocationStoreOptions) => Omit<_zayne_labs_toolkit_core1.StoreApi<_zayne_labs_toolkit_core1.URLInfoObject>, "setState" | "resetState"> & {
|
|
8
|
+
push: (url: string | _zayne_labs_toolkit_core1.PartialURLInfo, options?: {
|
|
9
|
+
state?: _zayne_labs_toolkit_core1.PartialURLInfo["state"];
|
|
10
10
|
}) => void;
|
|
11
11
|
replace: LocationStoreApi["push"];
|
|
12
12
|
triggerPopstateEvent: (nextLocationState?: LocationInfo["state"]) => void;
|
|
13
|
-
} & (<TSlice =
|
|
13
|
+
} & (<TSlice = _zayne_labs_toolkit_core1.URLInfoObject>(selector?: SelectorFn<LocationInfo, TSlice>) => UseLocationResult<TSlice>);
|
|
14
14
|
declare const useLocationState: <TSlice = LocationInfo>(selector?: SelectorFn<LocationInfo, TSlice>, options?: LocationStoreOptions) => UseLocationResult<TSlice>;
|
|
15
15
|
//#endregion
|
|
16
16
|
export { createUseLocationState, useLocationState };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react11 from "react";
|
|
2
2
|
|
|
3
3
|
//#region src/hooks/useSearch.d.ts
|
|
4
4
|
declare const useSearch: <TData>(initialData: TData[], delay?: number) => {
|
|
5
5
|
data: TData[];
|
|
6
6
|
isLoading: boolean;
|
|
7
7
|
query: string;
|
|
8
|
-
setQuery:
|
|
8
|
+
setQuery: react11.Dispatch<react11.SetStateAction<string>>;
|
|
9
9
|
};
|
|
10
10
|
//#endregion
|
|
11
11
|
export { useSearch };
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _zayne_labs_toolkit_core6 from "@zayne-labs/toolkit-core";
|
|
2
2
|
import { LocationStoreOptions, URLSearchParamsInit } from "@zayne-labs/toolkit-core";
|
|
3
3
|
|
|
4
4
|
//#region src/hooks/useSearchParams.d.ts
|
|
5
5
|
type UseSearchParamsOptions = LocationStoreOptions & {
|
|
6
6
|
action?: "push" | "replace";
|
|
7
7
|
};
|
|
8
|
-
declare const useSearchParams: <TSearchParams extends URLSearchParamsInit>(options?: UseSearchParamsOptions) =>
|
|
9
|
-
|
|
10
|
-
triggerPopstateEvent: (nextLocationState?: _zayne_labs_toolkit_core5.LocationInfo["state"]) => void;
|
|
11
|
-
}];
|
|
12
|
-
declare const useSearchParamsObject: <TSearchParams extends Record<string, string>>(options?: UseSearchParamsOptions) => readonly [TSearchParams, {
|
|
13
|
-
(newQueryParams: TSearchParams | ((prev: TSearchParams) => TSearchParams)): void;
|
|
14
|
-
triggerPopstateEvent: (nextLocationState?: _zayne_labs_toolkit_core5.LocationInfo["state"]) => void;
|
|
15
|
-
}];
|
|
8
|
+
declare const useSearchParams: <TSearchParams extends URLSearchParamsInit>(options?: UseSearchParamsOptions) => [searchParams: URLSearchParams, setSearchParams: (newQueryParams: TSearchParams | ((prev: URLSearchParams) => TSearchParams)) => void, triggerPopstateEvent: (nextLocationState?: _zayne_labs_toolkit_core6.LocationInfo["state"]) => void];
|
|
9
|
+
declare const useSearchParamsObject: <TSearchParams extends Record<string, string>>(options?: UseSearchParamsOptions) => [searchParamsObject: TSearchParams, setSearchParamsObject: (newQueryParams: TSearchParams | ((prev: TSearchParams) => TSearchParams)) => void, triggerPopstateEvent: (nextLocationState?: _zayne_labs_toolkit_core6.LocationInfo["state"]) => void];
|
|
16
10
|
//#endregion
|
|
17
11
|
export { useSearchParams, useSearchParamsObject };
|
|
18
12
|
//# sourceMappingURL=useSearchParams.d.ts.map
|
|
@@ -11,18 +11,24 @@ const useSearchParams = (options) => {
|
|
|
11
11
|
const nextSearchParams = createSearchParams(params);
|
|
12
12
|
actions[action]({ search: nextSearchParams });
|
|
13
13
|
};
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
return [
|
|
15
|
+
searchParams,
|
|
16
|
+
setSearchParams,
|
|
17
|
+
actions.triggerPopstateEvent
|
|
18
|
+
];
|
|
16
19
|
};
|
|
17
20
|
const useSearchParamsObject = (options) => {
|
|
18
|
-
const [searchParams, setSearchParams] = useSearchParams(options);
|
|
21
|
+
const [searchParams, setSearchParams, triggerPopstateEvent] = useSearchParams(options);
|
|
19
22
|
const searchParamsObject = Object.fromEntries(searchParams);
|
|
20
23
|
const setSearchParamsObject = (newQueryParams) => {
|
|
21
24
|
const params = isFunction(newQueryParams) ? newQueryParams(searchParamsObject) : newQueryParams;
|
|
22
25
|
setSearchParams(params);
|
|
23
26
|
};
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
return [
|
|
28
|
+
searchParamsObject,
|
|
29
|
+
setSearchParamsObject,
|
|
30
|
+
triggerPopstateEvent
|
|
31
|
+
];
|
|
26
32
|
};
|
|
27
33
|
|
|
28
34
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSearchParams.js","names":[],"sources":["../../../src/hooks/useSearchParams.ts"],"sourcesContent":["import {\n\ttype LocationStoreOptions,\n\ttype URLSearchParamsInit,\n
|
|
1
|
+
{"version":3,"file":"useSearchParams.js","names":[],"sources":["../../../src/hooks/useSearchParams.ts"],"sourcesContent":["import {\n\tcreateSearchParams,\n\ttype LocationStoreOptions,\n\ttype URLSearchParamsInit,\n} from \"@zayne-labs/toolkit-core\";\nimport { isFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useLocationState } from \"./useLocationState\";\n\ntype UseSearchParamsOptions = LocationStoreOptions & {\n\taction?: \"push\" | \"replace\";\n};\n\nexport const useSearchParams = <TSearchParams extends URLSearchParamsInit>(\n\toptions?: UseSearchParamsOptions\n) => {\n\tconst { action = \"push\", ...restOfOptions } = options ?? {};\n\n\tconst [searchParams, actions] = useLocationState((state) => state.search, restOfOptions);\n\n\tconst setSearchParams = (\n\t\tnewQueryParams: TSearchParams | ((prev: URLSearchParams) => TSearchParams)\n\t) => {\n\t\tconst params = isFunction(newQueryParams) ? newQueryParams(searchParams) : newQueryParams;\n\n\t\tconst nextSearchParams = createSearchParams(params);\n\n\t\tactions[action]({ search: nextSearchParams });\n\t};\n\n\treturn [searchParams, setSearchParams, actions.triggerPopstateEvent] as [\n\t\tsearchParams: typeof searchParams,\n\t\tsetSearchParams: typeof setSearchParams,\n\t\ttriggerPopstateEvent: typeof actions.triggerPopstateEvent,\n\t];\n};\n\nexport const useSearchParamsObject = <TSearchParams extends Record<string, string>>(\n\toptions?: UseSearchParamsOptions\n) => {\n\tconst [searchParams, setSearchParams, triggerPopstateEvent] = useSearchParams(options);\n\n\tconst searchParamsObject = Object.fromEntries(searchParams) as TSearchParams;\n\n\tconst setSearchParamsObject = (\n\t\tnewQueryParams: TSearchParams | ((prev: TSearchParams) => TSearchParams)\n\t) => {\n\t\tconst params = isFunction(newQueryParams) ? newQueryParams(searchParamsObject) : newQueryParams;\n\n\t\tsetSearchParams(params);\n\t};\n\n\treturn [searchParamsObject, setSearchParamsObject, triggerPopstateEvent] as [\n\t\tsearchParamsObject: typeof searchParamsObject,\n\t\tsetSearchParamsObject: typeof setSearchParamsObject,\n\t\ttriggerPopstateEvent: typeof triggerPopstateEvent,\n\t];\n};\n"],"mappings":";;;;;AAYA,MAAa,mBACZ,YACI;CACJ,MAAM,EAAE,SAAS,OAAQ,GAAG,kBAAkB,WAAW,EAAE;CAE3D,MAAM,CAAC,cAAc,WAAW,kBAAkB,UAAU,MAAM,QAAQ,cAAc;CAExF,MAAM,mBACL,mBACI;EACJ,MAAM,SAAS,WAAW,eAAe,GAAG,eAAe,aAAa,GAAG;EAE3E,MAAM,mBAAmB,mBAAmB,OAAO;AAEnD,UAAQ,QAAQ,EAAE,QAAQ,kBAAkB,CAAC;;AAG9C,QAAO;EAAC;EAAc;EAAiB,QAAQ;EAAqB;;AAOrE,MAAa,yBACZ,YACI;CACJ,MAAM,CAAC,cAAc,iBAAiB,wBAAwB,gBAAgB,QAAQ;CAEtF,MAAM,qBAAqB,OAAO,YAAY,aAAa;CAE3D,MAAM,yBACL,mBACI;EACJ,MAAM,SAAS,WAAW,eAAe,GAAG,eAAe,mBAAmB,GAAG;AAEjF,kBAAgB,OAAO;;AAGxB,QAAO;EAAC;EAAoB;EAAuB;EAAqB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useCallbackRef } from "./useCallbackRef.js";
|
|
2
|
-
import { useRef } from "react";
|
|
2
|
+
import { useInsertionEffect, useRef } from "react";
|
|
3
3
|
import { shallowCompare } from "@zayne-labs/toolkit-core";
|
|
4
4
|
|
|
5
5
|
//#region src/hooks/useShallowCompare.ts
|
|
@@ -14,8 +14,11 @@ const useShallowCompSelector = (selector) => {
|
|
|
14
14
|
};
|
|
15
15
|
const useShallowCompValue = (value) => {
|
|
16
16
|
const prevValueRef = useRef(value);
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
useInsertionEffect(() => {
|
|
18
|
+
if (shallowCompare(prevValueRef.current, value)) return;
|
|
19
|
+
prevValueRef.current = value;
|
|
20
|
+
});
|
|
21
|
+
return prevValueRef.current;
|
|
19
22
|
};
|
|
20
23
|
|
|
21
24
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useShallowCompare.js","names":[],"sources":["../../../src/hooks/useShallowCompare.ts"],"sourcesContent":["import { shallowCompare } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useRef } from \"react\";\nimport { useCallbackRef } from \"./useCallbackRef\";\n\nexport const useShallowCompSelector = <TState, TResult>(\n\tselector: SelectorFn<TState, TResult> | undefined\n) => {\n\tconst prevStateRef = useRef<TResult>(undefined as never);\n\n\tconst shallowSelector = useCallbackRef((state: TState) => {\n\t\tconst nextState = selector?.(state);\n\n\t\tif (!nextState) {\n\t\t\treturn prevStateRef.current;\n\t\t}\n\n\t\tif (shallowCompare(prevStateRef.current, nextState)) {\n\t\t\treturn prevStateRef.current;\n\t\t}\n\n\t\treturn (prevStateRef.current = nextState);\n\t});\n\n\treturn shallowSelector;\n};\n\nexport const useShallowCompValue = <TValue>(value: TValue) => {\n\tconst prevValueRef = useRef<TValue>(value);\n\n\tif (shallowCompare(prevValueRef.current, value))
|
|
1
|
+
{"version":3,"file":"useShallowCompare.js","names":[],"sources":["../../../src/hooks/useShallowCompare.ts"],"sourcesContent":["import { shallowCompare } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useInsertionEffect, useRef } from \"react\";\nimport { useCallbackRef } from \"./useCallbackRef\";\n\nexport const useShallowCompSelector = <TState, TResult>(\n\tselector: SelectorFn<TState, TResult> | undefined\n) => {\n\tconst prevStateRef = useRef<TResult>(undefined as never);\n\n\tconst shallowSelector = useCallbackRef((state: TState) => {\n\t\tconst nextState = selector?.(state);\n\n\t\tif (!nextState) {\n\t\t\treturn prevStateRef.current;\n\t\t}\n\n\t\tif (shallowCompare(prevStateRef.current, nextState)) {\n\t\t\treturn prevStateRef.current;\n\t\t}\n\n\t\treturn (prevStateRef.current = nextState);\n\t});\n\n\treturn shallowSelector;\n};\n\nexport const useShallowCompValue = <TValue>(value: TValue) => {\n\tconst prevValueRef = useRef<TValue>(value);\n\n\tuseInsertionEffect(() => {\n\t\tif (shallowCompare(prevValueRef.current, value)) return;\n\n\t\tprevValueRef.current = value;\n\t});\n\n\t// eslint-disable-next-line react-hooks/refs -- Allow this for convenience\n\treturn prevValueRef.current;\n};\n"],"mappings":";;;;;AAKA,MAAa,0BACZ,aACI;CACJ,MAAM,eAAe,OAAgB,OAAmB;AAgBxD,QAdwB,gBAAgB,UAAkB;EACzD,MAAM,YAAY,WAAW,MAAM;AAEnC,MAAI,CAAC,UACJ,QAAO,aAAa;AAGrB,MAAI,eAAe,aAAa,SAAS,UAAU,CAClD,QAAO,aAAa;AAGrB,SAAQ,aAAa,UAAU;GAC9B;;AAKH,MAAa,uBAA+B,UAAkB;CAC7D,MAAM,eAAe,OAAe,MAAM;AAE1C,0BAAyB;AACxB,MAAI,eAAe,aAAa,SAAS,MAAM,CAAE;AAEjD,eAAa,UAAU;GACtB;AAGF,QAAO,aAAa"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _zayne_labs_toolkit_core8 from "@zayne-labs/toolkit-core";
|
|
2
2
|
import { StorageOptions, StorageStoreApi } from "@zayne-labs/toolkit-core";
|
|
3
3
|
import { SelectorFn } from "@zayne-labs/toolkit-type-helpers";
|
|
4
4
|
|
|
@@ -8,7 +8,7 @@ type UseStorageResult<TState, TSlice = TState> = [state: TSlice, actions: Storag
|
|
|
8
8
|
* @description Creates a custom hook that returns a storage state and actions to modify it. You can use this if you need shared options.
|
|
9
9
|
* @note You must use this if you want to be able to prevent syncing state across tabs.
|
|
10
10
|
*/
|
|
11
|
-
declare const createUseStorageState: <TState>(baseOptions: StorageOptions<TState>) =>
|
|
11
|
+
declare const createUseStorageState: <TState>(baseOptions: StorageOptions<TState>) => _zayne_labs_toolkit_core8.StoreApi<TState> & {
|
|
12
12
|
removeState: () => void;
|
|
13
13
|
} & (<TSlice = TState>(selector?: SelectorFn<TState, TSlice>) => UseStorageResult<TState, TSlice>);
|
|
14
14
|
type UseStorageStateOptions<TValue> = Omit<StorageOptions<TValue>, "initialValue" | "key">;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { useCallbackRef } from "./useCallbackRef.js";
|
|
1
2
|
import { useCallback, useDebugValue, useSyncExternalStore } from "react";
|
|
2
3
|
|
|
3
4
|
//#region src/hooks/useStore.ts
|
|
4
5
|
const identity = (value) => value;
|
|
5
6
|
const useStore = (store, selector = identity) => {
|
|
6
|
-
const
|
|
7
|
+
const stableSelector = useCallbackRef(selector);
|
|
8
|
+
const getState = useCallback(() => stableSelector(store.getState()), [stableSelector, store]);
|
|
9
|
+
const getInitialState = useCallback(() => stableSelector(store.getInitialState()), [stableSelector, store]);
|
|
10
|
+
const slice = useSyncExternalStore(store.subscribe, getState, getInitialState);
|
|
7
11
|
useDebugValue(slice);
|
|
8
12
|
return slice;
|
|
9
13
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStore.js","names":[],"sources":["../../../src/hooks/useStore.ts"],"sourcesContent":["import type { StoreApi } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useCallback, useDebugValue, useSyncExternalStore } from \"react\";\n\nconst identity = <TState>(value: TState) => value;\n\nconst useStore = <TState, TSlice = TState>(\n\tstore: StoreApi<TState>,\n\tselector: SelectorFn<TState, TSlice> = identity as never\n) => {\n\tconst
|
|
1
|
+
{"version":3,"file":"useStore.js","names":[],"sources":["../../../src/hooks/useStore.ts"],"sourcesContent":["import type { StoreApi } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useCallback, useDebugValue, useSyncExternalStore } from \"react\";\nimport { useCallbackRef } from \"./useCallbackRef\";\n\nconst identity = <TState>(value: TState) => value;\n\nconst useStore = <TState, TSlice = TState>(\n\tstore: StoreApi<TState>,\n\tselector: SelectorFn<TState, TSlice> = identity as never\n) => {\n\tconst stableSelector = useCallbackRef(selector);\n\n\tconst getState = useCallback(() => stableSelector(store.getState()), [stableSelector, store]);\n\n\tconst getInitialState = useCallback(\n\t\t() => stableSelector(store.getInitialState()),\n\t\t[stableSelector, store]\n\t);\n\n\tconst slice = useSyncExternalStore(store.subscribe, getState, getInitialState);\n\n\tuseDebugValue(slice);\n\n\treturn slice;\n};\n\nexport { useStore };\n"],"mappings":";;;;AAKA,MAAM,YAAoB,UAAkB;AAE5C,MAAM,YACL,OACA,WAAuC,aACnC;CACJ,MAAM,iBAAiB,eAAe,SAAS;CAE/C,MAAM,WAAW,kBAAkB,eAAe,MAAM,UAAU,CAAC,EAAE,CAAC,gBAAgB,MAAM,CAAC;CAE7F,MAAM,kBAAkB,kBACjB,eAAe,MAAM,iBAAiB,CAAC,EAC7C,CAAC,gBAAgB,MAAM,CACvB;CAED,MAAM,QAAQ,qBAAqB,MAAM,WAAW,UAAU,gBAAgB;AAE9E,eAAc,MAAM;AAEpB,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createReactZustandStore.js","names":[],"sources":["../../../src/zustand/createReactZustandStore.ts"],"sourcesContent":["import { createStore } from \"@zayne-labs/toolkit-core\";\nimport type { Mutate, StateCreator,
|
|
1
|
+
{"version":3,"file":"createReactZustandStore.js","names":[],"sources":["../../../src/zustand/createReactZustandStore.ts"],"sourcesContent":["import { createStore, type StoreApi } from \"@zayne-labs/toolkit-core\";\nimport type { Mutate, StateCreator, StoreMutatorIdentifier, UseBoundStore } from \"./types\";\n\ntype Create = {\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\nexport const createReactZustandStore = (<TState>(stateInitializer: StateCreator<TState> | undefined) =>\n\tstateInitializer ? createStore(stateInitializer) : createStore) as Create;\n"],"mappings":";;;AAYA,MAAa,4BAAoC,qBAChD,mBAAmB,YAAY,iBAAiB,GAAG"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomContextOptions } from "../hooks/createCustomContext.js";
|
|
2
|
-
import * as
|
|
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
|
|
|
@@ -7,7 +7,7 @@ import { SelectorFn } from "@zayne-labs/toolkit-type-helpers";
|
|
|
7
7
|
declare const createZustandContext: <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
|
export { createZustandContext };
|
|
13
13
|
//# sourceMappingURL=createZustandContext.d.ts.map
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { StateCreator, StoreMutatorIdentifier, UseBoundStore } from "./types.js";
|
|
2
|
+
import * as _zayne_labs_toolkit_core0 from "@zayne-labs/toolkit-core";
|
|
2
3
|
import { AnyObject, Prettify } from "@zayne-labs/toolkit-type-helpers";
|
|
3
|
-
import * as zustand0 from "zustand";
|
|
4
|
-
import { StateCreator, StoreMutatorIdentifier } from "zustand";
|
|
5
4
|
|
|
6
5
|
//#region src/zustand/createZustandStoreWithCombine.d.ts
|
|
7
6
|
type Write<TInitialState, TExtraState> = Prettify<Omit<TInitialState, keyof TExtraState> & TExtraState>;
|
|
8
7
|
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>;
|
|
9
|
-
declare const createStoreWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) =>
|
|
10
|
-
declare const createWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) =>
|
|
8
|
+
declare const createStoreWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) => _zayne_labs_toolkit_core0.StoreApi<Omit<TInitialState, keyof TExtraState> & TExtraState extends infer T ? { [Key in keyof T]: T[Key] } : never>;
|
|
9
|
+
declare const createWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) => UseBoundStore<_zayne_labs_toolkit_core0.StoreApi<Omit<TInitialState, keyof TExtraState> & TExtraState extends infer T ? { [Key in keyof T]: T[Key] } : never>>;
|
|
11
10
|
//#endregion
|
|
12
11
|
export { combine, createStoreWithCombine, createWithCombine };
|
|
13
12
|
//# sourceMappingURL=createZustandStoreWithCombine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createZustandStoreWithCombine.js","names":[],"sources":["../../../src/zustand/createZustandStoreWithCombine.ts"],"sourcesContent":["import { createStore } from \"@zayne-labs/toolkit-core\";\nimport type { AnyFunction, AnyObject, Prettify } from \"@zayne-labs/toolkit-type-helpers\";\nimport
|
|
1
|
+
{"version":3,"file":"createZustandStoreWithCombine.js","names":[],"sources":["../../../src/zustand/createZustandStoreWithCombine.ts"],"sourcesContent":["import { createStore } from \"@zayne-labs/toolkit-core\";\nimport type { AnyFunction, AnyObject, Prettify } from \"@zayne-labs/toolkit-type-helpers\";\nimport { createReactZustandStore } from \"./createReactZustandStore\";\nimport type { StateCreator, StoreMutatorIdentifier } from \"./types\";\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) => createReactZustandStore(combine(...params));\n"],"mappings":";;;;AAOA,MAAa,WAOX,cACA,kBAGA,GAAG,YAAY;CACf,GAAG;CACH,GAAI,aAA6B,GAAG,OAAO;CAC3C;AAEF,MAAa,0BACZ,GAAG,WACC,YAAY,QAAQ,GAAG,OAAO,CAAC;AAEpC,MAAa,qBACZ,GAAG,WACC,wBAAwB,QAAQ,GAAG,OAAO,CAAC"}
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
+
import { Mutate, StateCreator, StoreMutatorIdentifier, UseBoundStore } from "./types.js";
|
|
1
2
|
import { StoreApi } from "@zayne-labs/toolkit-core";
|
|
2
|
-
import { Mutate, StoreMutatorIdentifier, UseBoundStore } from "zustand";
|
|
3
3
|
|
|
4
4
|
//#region src/zustand/createZustandStoreWithSubscribe.d.ts
|
|
5
|
-
type Get<T, K, F> = K extends keyof T ? T[K] : F;
|
|
6
|
-
type StateCreator$1<T, Mis extends Array<[StoreMutatorIdentifier, unknown]> = [], Mos extends Array<[StoreMutatorIdentifier, unknown]> = [], U = T> = {
|
|
7
|
-
$$storeMutators?: Mos;
|
|
8
|
-
} & ((setState: Get<Mutate<StoreApi<T>, Mis>, "setState", never>, getState: Get<Mutate<StoreApi<T>, Mis>, "getState", never>, store: Mutate<StoreApi<T>, Mis>) => U);
|
|
9
5
|
type CreateStoreWithSubscribe = {
|
|
10
|
-
<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator
|
|
11
|
-
<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator
|
|
6
|
+
<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>): Mutate<StoreApi<T>, Mos>;
|
|
7
|
+
<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>) => Mutate<StoreApi<T>, Mos>;
|
|
12
8
|
};
|
|
13
9
|
declare const createStoreWithSubscribe: CreateStoreWithSubscribe;
|
|
14
10
|
type CreateWithSubscribe = {
|
|
15
|
-
<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator
|
|
16
|
-
<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator
|
|
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>>;
|
|
17
13
|
};
|
|
18
14
|
declare const createWithSubscribe: CreateWithSubscribe;
|
|
19
15
|
//#endregion
|
|
20
|
-
export {
|
|
16
|
+
export { createStoreWithSubscribe, createWithSubscribe };
|
|
21
17
|
//# sourceMappingURL=createZustandStoreWithSubscribe.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createZustandStoreWithSubscribe.js","names":[],"sources":["../../../src/zustand/createZustandStoreWithSubscribe.ts"],"sourcesContent":["import { createStore, type StoreApi } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport
|
|
1
|
+
{"version":3,"file":"createZustandStoreWithSubscribe.js","names":[],"sources":["../../../src/zustand/createZustandStoreWithSubscribe.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 { Mutate, StateCreator, StoreMutatorIdentifier, UseBoundStore } from \"./types\";\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":";;;;AAeA,MAAa,6BAAqC,qBACjD,mBAAmB,YAAY,iBAAiB,GAAG;AAWpD,MAAM,2BAAmC,gBAAsC;CAC9E,MAAM,QAAQ,YAAY,YAAY;CAEtC,MAAM,iBAAiB,aAA2C,SAAS,OAAO,SAAS;AAE3F,QAAO,OAAO,eAAe,MAAM;AAEnC,QAAO;;AAGR,MAAa,wBAAgC,qBAC5C,mBACC,wBAAwB,iBAAiB,GACxC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createZustandContext } from "./createZustandContext.js";
|
|
2
2
|
import { combine, createStoreWithCombine, createWithCombine } from "./createZustandStoreWithCombine.js";
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
3
|
+
import { createStoreWithSubscribe, createWithSubscribe } from "./createZustandStoreWithSubscribe.js";
|
|
4
|
+
export { combine, createStoreWithCombine, createStoreWithSubscribe, createWithCombine, createWithSubscribe, createZustandContext };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { StoreApi } from "@zayne-labs/toolkit-core";
|
|
2
|
+
|
|
3
|
+
//#region src/zustand/types.d.ts
|
|
4
|
+
type StoreMutatorIdentifier = never;
|
|
5
|
+
type Get<T, K, F> = K extends keyof T ? T[K] : F;
|
|
6
|
+
type Mutate<S, Ms> = number extends Ms["length" & keyof Ms] ? S : Ms extends [] ? S : Ms extends [[infer IgnoredMi, infer IgnoredMa], ...infer Mrs] ? Mutate<never, Mrs> : never;
|
|
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 ExtractState<S> = S extends ({
|
|
11
|
+
getState: () => infer T;
|
|
12
|
+
}) ? T : never;
|
|
13
|
+
type UseBoundStore<S extends ReadonlyStoreApi<unknown>> = S & {
|
|
14
|
+
(): ExtractState<S>;
|
|
15
|
+
<U>(selector: (state: ExtractState<S>) => U): U;
|
|
16
|
+
};
|
|
17
|
+
type ReadonlyStoreApi<T> = Pick<StoreApi<T>, "getInitialState" | "getState" | "subscribe">;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { Mutate, StateCreator, StoreMutatorIdentifier, UseBoundStore };
|
|
20
|
+
//# sourceMappingURL=types.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zayne-labs/toolkit-react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.0",
|
|
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",
|
|
@@ -32,8 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@types/react": ">=19.0.0",
|
|
35
|
-
"react": ">=19.0.0"
|
|
36
|
-
"zustand": ">=5.0.0"
|
|
35
|
+
"react": ">=19.0.0"
|
|
37
36
|
},
|
|
38
37
|
"peerDependenciesMeta": {
|
|
39
38
|
"@types/react": {
|
|
@@ -41,14 +40,11 @@
|
|
|
41
40
|
},
|
|
42
41
|
"react": {
|
|
43
42
|
"optional": true
|
|
44
|
-
},
|
|
45
|
-
"zustand": {
|
|
46
|
-
"optional": true
|
|
47
43
|
}
|
|
48
44
|
},
|
|
49
45
|
"dependencies": {
|
|
50
|
-
"@zayne-labs/toolkit-core": "0.
|
|
51
|
-
"@zayne-labs/toolkit-type-helpers": "0.
|
|
46
|
+
"@zayne-labs/toolkit-core": "0.12.0",
|
|
47
|
+
"@zayne-labs/toolkit-type-helpers": "0.12.0"
|
|
52
48
|
},
|
|
53
49
|
"devDependencies": {
|
|
54
50
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
@@ -56,17 +52,16 @@
|
|
|
56
52
|
"@size-limit/esbuild-why": "^11.2.0",
|
|
57
53
|
"@size-limit/preset-small-lib": "^11.2.0",
|
|
58
54
|
"@total-typescript/ts-reset": "^0.6.1",
|
|
59
|
-
"@types/node": "^24.
|
|
60
|
-
"@types/react": "^19.
|
|
61
|
-
"@zayne-labs/tsconfig": "0.10.
|
|
55
|
+
"@types/node": "^24.6.1",
|
|
56
|
+
"@types/react": "^19.2.0",
|
|
57
|
+
"@zayne-labs/tsconfig": "0.10.4",
|
|
62
58
|
"concurrently": "^9.2.1",
|
|
63
|
-
"cross-env": "^10.
|
|
59
|
+
"cross-env": "^10.1.0",
|
|
64
60
|
"publint": "^0.3.13",
|
|
65
|
-
"react": "^19.
|
|
61
|
+
"react": "^19.2.0",
|
|
66
62
|
"size-limit": "^11.2.0",
|
|
67
|
-
"tsdown": "^0.15.
|
|
68
|
-
"typescript": "5.9.
|
|
69
|
-
"zustand": "^5.0.8"
|
|
63
|
+
"tsdown": "^0.15.6",
|
|
64
|
+
"typescript": "5.9.3"
|
|
70
65
|
},
|
|
71
66
|
"publishConfig": {
|
|
72
67
|
"access": "public",
|