@aiszlab/relax 1.2.70 → 1.2.71

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,18 +1,19 @@
1
1
  import { type Dispatch, type SetStateAction } from "react";
2
- import type { State, RequiredTo } from "../types";
3
- type UseControlledStateBy<T> = {
2
+ import type { State } from "../types";
3
+ type UseControlledStateBy<R> = {
4
4
  /**
5
5
  * @description
6
6
  * default value
7
7
  */
8
- defaultState?: State<T>;
8
+ defaultState?: State<R>;
9
9
  };
10
- type UsedControlledState<T, R> = R extends undefined ? [T, Dispatch<SetStateAction<T>>] : [RequiredTo<T>, Dispatch<SetStateAction<RequiredTo<T>>>];
10
+ type UsedControlledState<T> = [T, Dispatch<SetStateAction<T>>];
11
+ type Requirable<T, P> = T extends undefined ? (P extends undefined ? T : Exclude<T, undefined>) : T;
11
12
  /**
12
13
  * @author murukal
13
14
  *
14
15
  * @description
15
16
  * controlled state
16
17
  */
17
- export declare const useControlledState: <T, R extends T>(controlledState: T, { defaultState }?: UseControlledStateBy<R>) => UsedControlledState<T, R>;
18
+ export declare const useControlledState: <T, P extends T = T>(controlledState: T, { defaultState }?: UseControlledStateBy<P>) => UsedControlledState<Requirable<T, P>>;
18
19
  export {};
@@ -1,8 +1,8 @@
1
1
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
2
  import { useState } from 'react';
3
- import { isStateGetter } from '../is/is-state-getter.js';
4
3
  import { isUndefined } from '../is/is-undefined.js';
5
4
  import { useUpdateEffect } from './use-update-effect.js';
5
+ import { isFunction } from '../is/is-function.js';
6
6
 
7
7
  /**
8
8
  * @author murukal
@@ -13,28 +13,30 @@ import { useUpdateEffect } from './use-update-effect.js';
13
13
  var useControlledState = function useControlledState(controlledState) {
14
14
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
15
15
  defaultState = _ref.defaultState;
16
- /// initialize state
16
+ // initialize state
17
17
  var _useState = useState(function () {
18
18
  // default use controlled state
19
19
  if (!isUndefined(controlledState)) {
20
20
  return controlledState;
21
21
  }
22
- // not controlled use default prop
23
- if (isUndefined(defaultState)) return controlledState;
24
- if (isStateGetter(defaultState)) return defaultState();
25
- return defaultState;
22
+ // not controlled use default state
23
+ if (isFunction(defaultState)) {
24
+ return defaultState();
25
+ }
26
+ return defaultState !== null && defaultState !== void 0 ? defaultState : controlledState;
26
27
  }),
27
28
  _useState2 = _slicedToArray(_useState, 2),
28
29
  _state = _useState2[0],
29
30
  _setState = _useState2[1];
30
- /// sync value back to `undefined` when it from control to un-control
31
+ // sync value back to `undefined` when it from control to un-control
31
32
  useUpdateEffect(function () {
32
- if (!isUndefined(controlledState)) return;
33
- _setState(controlledState !== null && controlledState !== void 0 ? controlledState : defaultState);
33
+ if (!isUndefined(controlledState)) {
34
+ return;
35
+ }
36
+ _setState(defaultState !== null && defaultState !== void 0 ? defaultState : controlledState);
34
37
  }, [controlledState]);
35
- /// use controlled
36
- var state = !isUndefined(controlledState) ? controlledState : _state;
37
- // @ts-ignore
38
+ // use controlled
39
+ var state = isUndefined(controlledState) ? _state : controlledState;
38
40
  return [state, _setState];
39
41
  };
40
42
 
@@ -1,5 +1,7 @@
1
+ type UsedIdentity = [string, () => string];
1
2
  /**
2
3
  * @description
3
4
  * extends from react `useId`
4
5
  */
5
- export declare const useIdentity: (signal?: string) => [string, () => string];
6
+ export declare const useIdentity: (signal?: string) => UsedIdentity;
7
+ export {};
@@ -0,0 +1,2 @@
1
+ import { type UseStorageBy } from "./use-storage";
2
+ export declare const useLocalStorage: (key: string, useBy?: UseStorageBy) => import("./use-storage").UsedStorage;
@@ -2,4 +2,4 @@
2
2
  * @description
3
3
  * network
4
4
  */
5
- export declare const useNetwork: () => void;
5
+ export declare const useNetwork: () => boolean;
@@ -0,0 +1,2 @@
1
+ import { type UseStorageBy } from "./use-storage";
2
+ export declare const useSessionStorage: (key: string, useBy?: UseStorageBy) => import("./use-storage").UsedStorage;
@@ -0,0 +1,5 @@
1
+ export type UsedStorage = [string | null, (value: string | null) => void];
2
+ export type UseStorageBy = {
3
+ listen?: boolean;
4
+ };
5
+ export declare const useStorage: (key: string, storage: Storage, { listen }?: UseStorageBy) => UsedStorage;
package/dist/index.d.ts CHANGED
@@ -36,7 +36,6 @@ export { useTimer } from "./hooks/use-timer";
36
36
  */
37
37
  export { isRefable } from "./is/is-refable";
38
38
  export { isUndefined } from "./is/is-undefined";
39
- export { isStateGetter } from "./is/is-state-getter";
40
39
  export { isNull } from "./is/is-null";
41
40
  export { isVoid } from "./is/is-void";
42
41
  export { isArray } from "./is/is-array";
package/dist/index.js CHANGED
@@ -28,7 +28,6 @@ export { useUnmount } from './hooks/use-unmount.js';
28
28
  export { useTimer } from './hooks/use-timer.js';
29
29
  export { isRefable } from './is/is-refable.js';
30
30
  export { isUndefined } from './is/is-undefined.js';
31
- export { isStateGetter } from './is/is-state-getter.js';
32
31
  export { isNull } from './is/is-null.js';
33
32
  export { isVoid } from './is/is-void.js';
34
33
  export { isArray } from './is/is-array.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.2.70",
3
+ "version": "1.2.71",
4
4
  "description": "react utils collection",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,6 +0,0 @@
1
- import type { State, StateGetter } from "../types";
2
- /**
3
- * @description
4
- * is state getter
5
- */
6
- export declare const isStateGetter: <T>(state: State<T>) => state is StateGetter<T>;
@@ -1,9 +0,0 @@
1
- /**
2
- * @description
3
- * is state getter
4
- */
5
- var isStateGetter = function isStateGetter(state) {
6
- return typeof state === "function";
7
- };
8
-
9
- export { isStateGetter };