@zayne-labs/toolkit-react 0.11.21 → 0.12.1
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/useClickOutside.d.ts +2 -2
- package/dist/esm/hooks/useComposeRefs.d.ts +2 -2
- package/dist/esm/hooks/useSearchParams.d.ts +3 -3
- 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/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react0 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: react0.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 react1 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>>) => react1.RefCallback<TRef>;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { useComposeRefs };
|
|
8
8
|
//# sourceMappingURL=useComposeRefs.d.ts.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _zayne_labs_toolkit_core4 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?:
|
|
9
|
-
declare const useSearchParamsObject: <TSearchParams extends Record<string, string>>(options?: UseSearchParamsOptions) => [searchParamsObject: TSearchParams, setSearchParamsObject: (newQueryParams: TSearchParams | ((prev: TSearchParams) => TSearchParams)) => void, triggerPopstateEvent: (nextLocationState?:
|
|
8
|
+
declare const useSearchParams: <TSearchParams extends URLSearchParamsInit>(options?: UseSearchParamsOptions) => [searchParams: URLSearchParams, setSearchParams: (newQueryParams: TSearchParams | ((prev: URLSearchParams) => TSearchParams)) => void, triggerPopstateEvent: (nextLocationState?: _zayne_labs_toolkit_core4.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_core4.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
|
|
1
|
+
import * as _zayne_labs_toolkit_core6 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_core6.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"}
|
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.1",
|
|
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.
|
|
47
|
-
"@zayne-labs/toolkit-type-helpers": "0.
|
|
46
|
+
"@zayne-labs/toolkit-core": "0.12.1",
|
|
47
|
+
"@zayne-labs/toolkit-type-helpers": "0.12.1"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@arethetypeswrong/cli": "^0.18.2",
|