@zayne-labs/toolkit-react 0.11.21 → 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.
@@ -1,4 +1,4 @@
1
- import * as react0 from "react";
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: react0.Context<TContextValue>, useCustomContext: UseCustomContext<TContextValue, TStrict>];
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,4 +1,4 @@
1
- import * as react1 from "react";
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: react1.RefObject<TElement | null>;
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 react0 from "react";
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>>) => react0.RefCallback<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,4 +1,4 @@
1
- import * as react2 from "react";
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: react2.Dispatch<react2.SetStateAction<AllowedClipboardItems>>;
10
+ setValue: react4.Dispatch<react4.SetStateAction<AllowedClipboardItems>>;
11
11
  value: AllowedClipboardItems;
12
12
  };
13
13
  //#endregion
@@ -1,4 +1,4 @@
1
- import * as react4 from "react";
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: react4.SetStateAction<TValue>[]): void;
15
- (params: react4.SetStateAction<TValue> | react4.SetStateAction<TValue>[], overrideOptions: {
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
- }, react4.Dispatch<react4.SetStateAction<TValue>>];
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 _zayne_labs_toolkit_core0 from "@zayne-labs/toolkit-core";
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<_zayne_labs_toolkit_core0.StoreApi<_zayne_labs_toolkit_core0.URLInfoObject>, "resetState" | "setState"> & {
8
- push: (url: string | _zayne_labs_toolkit_core0.PartialURLInfo, options?: {
9
- state?: _zayne_labs_toolkit_core0.PartialURLInfo["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 = _zayne_labs_toolkit_core0.URLInfoObject>(selector?: SelectorFn<LocationInfo, TSlice>) => UseLocationResult<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 react9 from "react";
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: react9.Dispatch<react9.SetStateAction<string>>;
8
+ setQuery: react11.Dispatch<react11.SetStateAction<string>>;
9
9
  };
10
10
  //#endregion
11
11
  export { useSearch };
@@ -1,12 +1,12 @@
1
- import * as _zayne_labs_toolkit_core5 from "@zayne-labs/toolkit-core";
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) => [searchParams: URLSearchParams, setSearchParams: (newQueryParams: TSearchParams | ((prev: URLSearchParams) => TSearchParams)) => void, triggerPopstateEvent: (nextLocationState?: _zayne_labs_toolkit_core5.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_core5.LocationInfo["state"]) => void];
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];
10
10
  //#endregion
11
11
  export { useSearchParams, useSearchParamsObject };
12
12
  //# sourceMappingURL=useSearchParams.d.ts.map
@@ -1,4 +1,4 @@
1
- import * as _zayne_labs_toolkit_core4 from "@zayne-labs/toolkit-core";
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>) => _zayne_labs_toolkit_core4.StoreApi<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 slice = useSyncExternalStore(store.subscribe, useCallback(() => selector(store.getState()), [store, selector]), useCallback(() => selector(store.getInitialState()), [store, selector]));
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 slice = useSyncExternalStore(\n\t\tstore.subscribe,\n\t\tuseCallback(() => selector(store.getState()), [store, selector]),\n\t\tuseCallback(() => selector(store.getInitialState()), [store, selector])\n\t);\n\n\tuseDebugValue(slice);\n\n\treturn slice;\n};\n\nexport { useStore };\n"],"mappings":";;;AAIA,MAAM,YAAoB,UAAkB;AAE5C,MAAM,YACL,OACA,WAAuC,aACnC;CACJ,MAAM,QAAQ,qBACb,MAAM,WACN,kBAAkB,SAAS,MAAM,UAAU,CAAC,EAAE,CAAC,OAAO,SAAS,CAAC,EAChE,kBAAkB,SAAS,MAAM,iBAAiB,CAAC,EAAE,CAAC,OAAO,SAAS,CAAC,CACvE;AAED,eAAc,MAAM;AAEpB,QAAO"}
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,5 +1,5 @@
1
1
  import { CustomContextOptions } from "../hooks/createCustomContext.js";
2
- import * as react11 from "react";
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
- }) => react11.FunctionComponentElement<react11.ProviderProps<TStore>>, useZustandStoreContext: <TResult = TState>(selector?: SelectorFn<TState, TResult>) => TResult];
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,12 +1,12 @@
1
1
  import { StateCreator, StoreMutatorIdentifier, UseBoundStore } from "./types.js";
2
- import * as _zayne_labs_toolkit_core7 from "@zayne-labs/toolkit-core";
2
+ import * as _zayne_labs_toolkit_core0 from "@zayne-labs/toolkit-core";
3
3
  import { AnyObject, Prettify } from "@zayne-labs/toolkit-type-helpers";
4
4
 
5
5
  //#region src/zustand/createZustandStoreWithCombine.d.ts
6
6
  type Write<TInitialState, TExtraState> = Prettify<Omit<TInitialState, keyof TExtraState> & TExtraState>;
7
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>;
8
- declare const createStoreWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) => _zayne_labs_toolkit_core7.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_core7.StoreApi<Omit<TInitialState, keyof TExtraState> & TExtraState extends infer T ? { [Key in keyof T]: T[Key] } : never>>;
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>>;
10
10
  //#endregion
11
11
  export { combine, createStoreWithCombine, createWithCombine };
12
12
  //# sourceMappingURL=createZustandStoreWithCombine.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.11.21",
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",
@@ -43,8 +43,8 @@
43
43
  }
44
44
  },
45
45
  "dependencies": {
46
- "@zayne-labs/toolkit-core": "0.11.21",
47
- "@zayne-labs/toolkit-type-helpers": "0.11.21"
46
+ "@zayne-labs/toolkit-core": "0.12.0",
47
+ "@zayne-labs/toolkit-type-helpers": "0.12.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@arethetypeswrong/cli": "^0.18.2",