@aiszlab/relax 1.2.19 → 1.2.20
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/hooks/use-counter.d.ts +23 -3
- package/dist/hooks/use-counter.mjs +23 -11
- package/dist/hooks/use-refs.d.ts +2 -1
- package/dist/hooks/use-refs.mjs +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +2 -0
- package/dist/is/is-pointer-usable.d.ts +5 -0
- package/dist/utils/chain.d.ts +4 -0
- package/dist/utils/chain.mjs +9 -0
- package/dist/utils/clamp.d.ts +9 -0
- package/dist/utils/clamp.mjs +13 -0
- package/package.json +1 -1
|
@@ -1,14 +1,34 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
interface Props {
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* initial value
|
|
6
|
+
*/
|
|
7
|
+
initialValue?: number;
|
|
8
|
+
/**
|
|
9
|
+
* @description
|
|
10
|
+
* max
|
|
11
|
+
*/
|
|
12
|
+
max?: number;
|
|
13
|
+
/**
|
|
14
|
+
* @description
|
|
15
|
+
* min
|
|
16
|
+
*/
|
|
17
|
+
min?: number;
|
|
18
|
+
}
|
|
2
19
|
/**
|
|
3
20
|
* @author murukal
|
|
4
21
|
*
|
|
5
22
|
* @description
|
|
6
23
|
* a number counter with some useful apis
|
|
7
24
|
*/
|
|
8
|
-
export declare const useCounter: () => {
|
|
25
|
+
export declare const useCounter: ({ max, min, ...props }?: Props) => {
|
|
9
26
|
count: number;
|
|
10
|
-
next: () => void;
|
|
11
|
-
prev: () => void;
|
|
27
|
+
next: (step?: number) => void;
|
|
28
|
+
prev: (step?: number) => void;
|
|
12
29
|
first: () => void;
|
|
30
|
+
last: () => void;
|
|
31
|
+
reset: () => void;
|
|
13
32
|
setCount: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
14
33
|
};
|
|
34
|
+
export {};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __rest } from '../node_modules/tslib/tslib.es6.mjs';
|
|
2
|
+
import { useMemo, useState, useCallback } from 'react';
|
|
3
|
+
import { clamp } from '../utils/clamp.mjs';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* @author murukal
|
|
@@ -6,22 +8,32 @@ import { useState, useCallback } from 'react';
|
|
|
6
8
|
* @description
|
|
7
9
|
* a number counter with some useful apis
|
|
8
10
|
*/
|
|
9
|
-
const useCounter = () => {
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
const useCounter = (_a = { initialValue: 0, max: Infinity, min: 0 }) => {
|
|
12
|
+
var { max = Infinity, min = 0 } = _a, props = __rest(_a, ["max", "min"]);
|
|
13
|
+
const initialValue = useMemo(() => { var _a; return clamp((_a = props.initialValue) !== null && _a !== void 0 ? _a : 0, min, max); }, [max, min, props.initialValue]);
|
|
14
|
+
const [count, setCount] = useState(initialValue);
|
|
15
|
+
const next = useCallback((step = 1) => {
|
|
16
|
+
setCount((prev) => Math.min(max, prev + step));
|
|
17
|
+
}, [max]);
|
|
18
|
+
const prev = useCallback((step = 1) => {
|
|
19
|
+
setCount((prev) => Math.max(prev - step));
|
|
20
|
+
}, [min]);
|
|
17
21
|
const first = useCallback(() => {
|
|
18
|
-
setCount(
|
|
19
|
-
}, []);
|
|
22
|
+
setCount(min);
|
|
23
|
+
}, [min]);
|
|
24
|
+
const last = useCallback(() => {
|
|
25
|
+
setCount(max);
|
|
26
|
+
}, [max]);
|
|
27
|
+
const reset = useCallback(() => {
|
|
28
|
+
setCount(initialValue);
|
|
29
|
+
}, [initialValue]);
|
|
20
30
|
return {
|
|
21
31
|
count,
|
|
22
32
|
next,
|
|
23
33
|
prev,
|
|
24
34
|
first,
|
|
35
|
+
last,
|
|
36
|
+
reset,
|
|
25
37
|
setCount
|
|
26
38
|
};
|
|
27
39
|
};
|
package/dist/hooks/use-refs.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type MutableRefObject, type RefCallback } from 'react';
|
|
2
|
+
import type { Nullable } from '../utils/null-able';
|
|
2
3
|
type Refable<T> = RefCallback<T> | MutableRefObject<T>;
|
|
3
|
-
export declare const useRefs: <T>(...refs: Refable<T
|
|
4
|
+
export declare const useRefs: <T>(...refs: Nullable<Refable<Nullable<T>>>[]) => (trigger: T) => void;
|
|
4
5
|
export {};
|
package/dist/hooks/use-refs.mjs
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -47,3 +47,5 @@ export { type RequiredIn } from './utils/required-in';
|
|
|
47
47
|
export { type ThenableEffectCallback, callAsEffect } from './utils/thenable-effect-callback';
|
|
48
48
|
export { unique, uniqueBy } from './utils/unique';
|
|
49
49
|
export { range } from './utils/range';
|
|
50
|
+
export { clamp } from './utils/clamp';
|
|
51
|
+
export { chain } from './utils/chain';
|
package/dist/index.mjs
CHANGED
|
@@ -32,3 +32,5 @@ export { isThenable } from './is/is-thenable.mjs';
|
|
|
32
32
|
export { callAsEffect } from './utils/thenable-effect-callback.mjs';
|
|
33
33
|
export { unique, uniqueBy } from './utils/unique.mjs';
|
|
34
34
|
export { range } from './utils/range.mjs';
|
|
35
|
+
export { clamp } from './utils/clamp.mjs';
|
|
36
|
+
export { chain } from './utils/chain.mjs';
|