@aiszlab/relax 1.2.56 → 1.2.58
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/dom/index.d.ts +2 -2
- package/dist/dom/scroll-to.d.ts +1 -1
- package/dist/dom/scroll-to.js +3 -3
- package/dist/hooks/use-boolean.d.ts +2 -2
- package/dist/hooks/use-controlled-state.d.ts +2 -2
- package/dist/hooks/use-counter.d.ts +2 -2
- package/dist/hooks/use-debounce-callback.d.ts +2 -2
- package/dist/hooks/use-default.d.ts +1 -1
- package/dist/hooks/use-focus.d.ts +3 -3
- package/dist/hooks/use-hover.d.ts +4 -4
- package/dist/hooks/use-identity.js +1 -1
- package/dist/hooks/use-image-loader.d.ts +1 -1
- package/dist/hooks/use-image-loader.js +7 -7
- package/dist/hooks/use-mount.d.ts +1 -1
- package/dist/hooks/use-mounted.d.ts +1 -1
- package/dist/hooks/use-mutate-observer.js +1 -1
- package/dist/hooks/use-raf.d.ts +1 -1
- package/dist/hooks/use-reactive.d.ts +1 -1
- package/dist/hooks/use-refs.d.ts +2 -2
- package/dist/hooks/use-refs.js +1 -1
- package/dist/hooks/use-scroll-locker.js +8 -8
- package/dist/hooks/use-scrollable.d.ts +3 -3
- package/dist/hooks/use-scrollable.js +2 -2
- package/dist/hooks/use-throttle-callback.d.ts +2 -2
- package/dist/hooks/use-togglable.d.ts +1 -1
- package/dist/hooks/use-update-effect.d.ts +2 -2
- package/dist/index.d.ts +52 -49
- package/dist/index.js +3 -0
- package/dist/is/is-complex.js +1 -1
- package/dist/is/is-dom-usable.js +1 -1
- package/dist/is/is-empty.js +1 -1
- package/dist/is/is-function.js +1 -1
- package/dist/is/is-map.d.ts +5 -0
- package/dist/is/is-mobile.js +1 -1
- package/dist/is/is-primitive.js +9 -0
- package/dist/is/is-refable.d.ts +1 -1
- package/dist/is/is-refable.js +2 -2
- package/dist/is/is-set.d.ts +5 -0
- package/dist/is/is-set.js +9 -0
- package/dist/is/is-state-getter.js +1 -1
- package/dist/is/is-style-element.js +1 -1
- package/dist/types/index.d.ts +8 -8
- package/dist/types/thenable-effect-callback.d.ts +1 -1
- package/dist/types/voidable.d.ts +2 -2
- package/dist/utils/chain.d.ts +1 -1
- package/dist/utils/clone.js +17 -0
- package/dist/utils/debounce.d.ts +1 -1
- package/dist/utils/effect.d.ts +2 -2
- package/dist/utils/range.js +1 -1
- package/dist/utils/set-style.d.ts +1 -1
- package/dist/utils/throttle.d.ts +2 -2
- package/dist/utils/to-array.js +1 -1
- package/dist/utils/toggle.d.ts +8 -0
- package/dist/utils/toggle.js +30 -0
- package/dist/utils/waitable.d.ts +1 -1
- package/package.json +5 -5
- package/dist/__test__/hooks/use-boolean.test.d.ts +0 -4
- package/dist/__test__/hooks/use-identity.test.d.ts +0 -4
- package/dist/__test__/hooks/use-mount.test.d.ts +0 -4
- package/dist/__test__/hooks/use-mounted.test.d.ts +0 -4
- package/dist/__test__/hooks/use-timeout.test.d.ts +0 -4
- package/dist/__test__/hooks/use-togglable.test.d.ts +0 -4
- package/dist/__test__/is/is-null.test.d.ts +0 -1
- package/dist/__test__/is/is-thenable.test.d.ts +0 -1
- package/dist/__test__/utils/chain.test.d.ts +0 -1
- package/dist/__test__/utils/clamp.test.d.ts +0 -1
- package/dist/__test__/utils/clone.test.d.ts +0 -1
- package/dist/__test__/utils/debounce.test.d.ts +0 -1
- package/dist/__test__/utils/effect.test.d.ts +0 -1
- package/dist/__test__/utils/exclude.test.d.ts +0 -1
- package/dist/__test__/utils/throttle.test.d.ts +0 -1
- package/dist/__test__/utils/to-array.test.d.ts +0 -1
- package/dist/__test__/utils/to-form-data.test.d.ts +0 -1
- package/dist/hooks/use-toggleable.d.ts +0 -48
- package/dist/hooks/use-toggleable.js +0 -187
package/dist/dom/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { scrollTo } from
|
|
2
|
-
import { contains } from
|
|
1
|
+
import { scrollTo } from "./scroll-to";
|
|
2
|
+
import { contains } from "./contains";
|
|
3
3
|
export { scrollTo, contains };
|
package/dist/dom/scroll-to.d.ts
CHANGED
package/dist/dom/scroll-to.js
CHANGED
|
@@ -16,7 +16,7 @@ var Scroller = /*#__PURE__*/function () {
|
|
|
16
16
|
}, {
|
|
17
17
|
key: "currentAt",
|
|
18
18
|
value: function currentAt(direction) {
|
|
19
|
-
return direction ===
|
|
19
|
+
return direction === "vertical" ? "scrollTop" : "scrollLeft";
|
|
20
20
|
}
|
|
21
21
|
}]);
|
|
22
22
|
}();
|
|
@@ -31,12 +31,12 @@ var _scroller = {
|
|
|
31
31
|
var scrollTo = function scrollTo(target, to) {
|
|
32
32
|
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
33
33
|
duration: 0,
|
|
34
|
-
direction:
|
|
34
|
+
direction: "vertical"
|
|
35
35
|
},
|
|
36
36
|
_ref$duration = _ref.duration,
|
|
37
37
|
duration = _ref$duration === void 0 ? 0 : _ref$duration,
|
|
38
38
|
_ref$direction = _ref.direction,
|
|
39
|
-
direction = _ref$direction === void 0 ?
|
|
39
|
+
direction = _ref$direction === void 0 ? "vertical" : _ref$direction;
|
|
40
40
|
var scroller = new Scroller();
|
|
41
41
|
var scrolled = scroller.scrolled.get(target);
|
|
42
42
|
var currentAtProperty = scroller.currentAt(direction);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { type DOMAttributes } from
|
|
1
|
+
import { type DOMAttributes } from "react";
|
|
2
2
|
/**
|
|
3
3
|
* @description
|
|
4
4
|
* hooks for focus
|
|
5
5
|
*/
|
|
6
|
-
type Props<T> = Pick<DOMAttributes<T>,
|
|
6
|
+
type Props<T> = Pick<DOMAttributes<T>, "onFocus" | "onBlur"> & {
|
|
7
7
|
onFocusChange?: (isFocused: boolean) => void;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* @description
|
|
11
11
|
* dom attributes
|
|
12
12
|
*/
|
|
13
|
-
type UsedFocus<T> = [boolean, Required<Pick<DOMAttributes<T>,
|
|
13
|
+
type UsedFocus<T> = [boolean, Required<Pick<DOMAttributes<T>, "onFocus" | "onBlur">>];
|
|
14
14
|
export declare const useFocus: <T extends Element = Element>(props?: Props<T>) => UsedFocus<T>;
|
|
15
15
|
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type DOMAttributes } from
|
|
1
|
+
import { type DOMAttributes } from "react";
|
|
2
2
|
type UseHoverBy<T> = {
|
|
3
|
-
onEnter?: DOMAttributes<T>[
|
|
4
|
-
onLeave?: DOMAttributes<T>[
|
|
3
|
+
onEnter?: DOMAttributes<T>["onPointerEnter"];
|
|
4
|
+
onLeave?: DOMAttributes<T>["onPointerLeave"];
|
|
5
5
|
};
|
|
6
|
-
type UsedHover<T> = [boolean, Required<Pick<DOMAttributes<T>,
|
|
6
|
+
type UsedHover<T> = [boolean, Required<Pick<DOMAttributes<T>, "onPointerEnter" | "onPointerLeave">>];
|
|
7
7
|
export declare const useHover: <T extends Element = Element>(props?: UseHoverBy<T>) => UsedHover<T>;
|
|
8
8
|
export {};
|
|
@@ -5,7 +5,7 @@ import { useId, useRef, useCallback } from 'react';
|
|
|
5
5
|
* extends from react `useId`
|
|
6
6
|
*/
|
|
7
7
|
var useIdentity = function useIdentity() {
|
|
8
|
-
var signal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] :
|
|
8
|
+
var signal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
9
9
|
var id = useId();
|
|
10
10
|
var count = useRef(0);
|
|
11
11
|
var unique = useCallback(function () {
|
|
@@ -11,13 +11,13 @@ import { Observable } from 'rxjs';
|
|
|
11
11
|
var useImageLoader = function useImageLoader(_ref) {
|
|
12
12
|
var src = _ref.src;
|
|
13
13
|
var loader = useRef();
|
|
14
|
-
var _useState = useState(
|
|
14
|
+
var _useState = useState("none"),
|
|
15
15
|
_useState2 = _slicedToArray(_useState, 2),
|
|
16
16
|
status = _useState2[0],
|
|
17
17
|
setStatus = _useState2[1];
|
|
18
18
|
useEffect(function () {
|
|
19
19
|
if (!src) {
|
|
20
|
-
return setStatus(
|
|
20
|
+
return setStatus("none");
|
|
21
21
|
}
|
|
22
22
|
// create observable to listen img status
|
|
23
23
|
new Observable(function (subscriber) {
|
|
@@ -25,21 +25,21 @@ var useImageLoader = function useImageLoader(_ref) {
|
|
|
25
25
|
subscriber.next();
|
|
26
26
|
}).subscribe({
|
|
27
27
|
next: function next() {
|
|
28
|
-
return setStatus(
|
|
28
|
+
return setStatus("loading");
|
|
29
29
|
},
|
|
30
30
|
complete: function complete() {
|
|
31
|
-
return setStatus(
|
|
31
|
+
return setStatus("loaded");
|
|
32
32
|
},
|
|
33
33
|
error: function error() {
|
|
34
|
-
return setStatus(
|
|
34
|
+
return setStatus("error");
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
var image = new Image();
|
|
38
|
-
image.addEventListener(
|
|
38
|
+
image.addEventListener("load", function () {
|
|
39
39
|
var _loader$current;
|
|
40
40
|
(_loader$current = loader.current) === null || _loader$current === void 0 || _loader$current.complete();
|
|
41
41
|
});
|
|
42
|
-
image.addEventListener(
|
|
42
|
+
image.addEventListener("error", function () {
|
|
43
43
|
var _loader$current2;
|
|
44
44
|
(_loader$current2 = loader.current) === null || _loader$current2 === void 0 || _loader$current2.error(null);
|
|
45
45
|
});
|
package/dist/hooks/use-raf.d.ts
CHANGED
package/dist/hooks/use-refs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type MutableRefObject, type RefCallback } from
|
|
2
|
-
import type { Nullable, Voidable } from
|
|
1
|
+
import { type MutableRefObject, type RefCallback } from "react";
|
|
2
|
+
import type { Nullable, Voidable } from "../types";
|
|
3
3
|
type Refable<T> = RefCallback<T> | MutableRefObject<T> | string;
|
|
4
4
|
export declare const useRefs: <T>(...refs: Voidable<Refable<Nullable<T>>>[]) => (trigger: T) => void;
|
|
5
5
|
export {};
|
package/dist/hooks/use-refs.js
CHANGED
|
@@ -9,7 +9,7 @@ var mount = function mount(ref, trigger) {
|
|
|
9
9
|
// in deprecated react, class component can use string ref
|
|
10
10
|
// but there are many problems, in relax, we just make it not work
|
|
11
11
|
// issue for react: https://github.com/facebook/react/pull/8333#issuecomment-271648615
|
|
12
|
-
if (typeof ref ===
|
|
12
|
+
if (typeof ref === "string") {
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
ref.current = trigger;
|
|
@@ -21,13 +21,13 @@ var ScrollLocker = /*#__PURE__*/function () {
|
|
|
21
21
|
if (_classPrivateFieldGet2(_barSize, this)) return _classPrivateFieldGet2(_barSize, this);
|
|
22
22
|
// how to calculate dom scroll bar size
|
|
23
23
|
// create a backend dom element, set force scrollable
|
|
24
|
-
var _target = document.createElement(
|
|
25
|
-
_target.attributeStyleMap.set(
|
|
26
|
-
_target.attributeStyleMap.set(
|
|
27
|
-
_target.attributeStyleMap.set(
|
|
28
|
-
_target.attributeStyleMap.set(
|
|
29
|
-
_target.attributeStyleMap.set(
|
|
30
|
-
_target.attributeStyleMap.set(
|
|
24
|
+
var _target = document.createElement("div");
|
|
25
|
+
_target.attributeStyleMap.set("position", "absolute");
|
|
26
|
+
_target.attributeStyleMap.set("left", "0");
|
|
27
|
+
_target.attributeStyleMap.set("top", "0");
|
|
28
|
+
_target.attributeStyleMap.set("width", "100vw");
|
|
29
|
+
_target.attributeStyleMap.set("height", "100vh");
|
|
30
|
+
_target.attributeStyleMap.set("overflow", "scroll");
|
|
31
31
|
// calculate, then clear
|
|
32
32
|
document.body.appendChild(_target);
|
|
33
33
|
_classPrivateFieldSet2(_barSize, this, {
|
|
@@ -51,7 +51,7 @@ var ScrollLocker = /*#__PURE__*/function () {
|
|
|
51
51
|
// if target is not scrollable, do not lock
|
|
52
52
|
if (!isOverflow(element)) return;
|
|
53
53
|
_classPrivateFieldGet2(_locked, this).set(element, setStyle(element, {
|
|
54
|
-
overflow:
|
|
54
|
+
overflow: "hidden",
|
|
55
55
|
width: "calc(100% - ".concat(this.barSize.width, "px)")
|
|
56
56
|
}));
|
|
57
57
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type Key } from
|
|
2
|
-
import { type Direction } from
|
|
1
|
+
import { type Key } from "react";
|
|
2
|
+
import { type Direction } from "../dom/scroll-to";
|
|
3
3
|
interface Dependencies {
|
|
4
4
|
direction?: Direction;
|
|
5
5
|
}
|
|
@@ -7,7 +7,7 @@ interface Dependencies {
|
|
|
7
7
|
* @description
|
|
8
8
|
* scrollable hook
|
|
9
9
|
*/
|
|
10
|
-
export declare const useScrollable: <P extends HTMLElement, C extends HTMLElement>({ direction }?: Dependencies) => {
|
|
10
|
+
export declare const useScrollable: <P extends HTMLElement, C extends HTMLElement>({ direction, }?: Dependencies) => {
|
|
11
11
|
targetRef: import("react").RefObject<P>;
|
|
12
12
|
triggerRefs: import("react").MutableRefObject<Map<Key, C | null>>;
|
|
13
13
|
scrollTo: (to: number, duration?: number) => void;
|
|
@@ -8,7 +8,7 @@ import { scrollTo } from '../dom/scroll-to.js';
|
|
|
8
8
|
var useScrollable = function useScrollable() {
|
|
9
9
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
10
10
|
_ref$direction = _ref.direction,
|
|
11
|
-
direction = _ref$direction === void 0 ?
|
|
11
|
+
direction = _ref$direction === void 0 ? "vertical" : _ref$direction;
|
|
12
12
|
var targetRef = useRef(null);
|
|
13
13
|
var triggerRefs = useRef(new Map());
|
|
14
14
|
var scrollTo$1 = useCallback(function (to) {
|
|
@@ -25,7 +25,7 @@ var useScrollable = function useScrollable() {
|
|
|
25
25
|
var trigger = triggerRefs.current.get(key);
|
|
26
26
|
if (!trigger) return 0;
|
|
27
27
|
// different direction, use different property
|
|
28
|
-
return direction ===
|
|
28
|
+
return direction === "vertical" ? trigger.offsetTop : trigger.offsetLeft;
|
|
29
29
|
}, [direction]);
|
|
30
30
|
/// set trigger
|
|
31
31
|
var setTrigger = useCallback(function (key, trigger) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type DependencyList } from
|
|
2
|
-
import type { ThenableEffectCallback } from
|
|
1
|
+
import { type DependencyList } from "react";
|
|
2
|
+
import type { ThenableEffectCallback } from "../types";
|
|
3
3
|
export declare const useUpdateEffect: (callback: ThenableEffectCallback, deps?: DependencyList) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,60 +2,63 @@
|
|
|
2
2
|
* @description
|
|
3
3
|
* hooks
|
|
4
4
|
*/
|
|
5
|
-
export { useBoolean } from
|
|
6
|
-
export { useDebounceCallback } from
|
|
7
|
-
export { useThrottleCallback } from
|
|
8
|
-
export { useImageLoader } from
|
|
9
|
-
export { useMount } from
|
|
10
|
-
export { useMounted } from
|
|
11
|
-
export { useTimeout } from
|
|
12
|
-
export { useControlledState } from
|
|
13
|
-
export { useDefault } from
|
|
14
|
-
export { useScrollLocker } from
|
|
15
|
-
export { useForceUpdate } from
|
|
16
|
-
export { useScrollable } from
|
|
17
|
-
export { useRefs } from
|
|
18
|
-
export { useTogglable } from
|
|
19
|
-
export { useEvent } from
|
|
20
|
-
export { useUpdateEffect } from
|
|
21
|
-
export { useCounter } from
|
|
22
|
-
export { useHover } from
|
|
23
|
-
export { useFocus } from
|
|
24
|
-
export { useMemorable } from
|
|
25
|
-
export { useMutateObserver } from
|
|
26
|
-
export { useRaf } from
|
|
27
|
-
export { useDevicePixelRatio } from
|
|
28
|
-
export { useIdentity } from
|
|
5
|
+
export { useBoolean } from "./hooks/use-boolean";
|
|
6
|
+
export { useDebounceCallback } from "./hooks/use-debounce-callback";
|
|
7
|
+
export { useThrottleCallback } from "./hooks/use-throttle-callback";
|
|
8
|
+
export { useImageLoader } from "./hooks/use-image-loader";
|
|
9
|
+
export { useMount } from "./hooks/use-mount";
|
|
10
|
+
export { useMounted } from "./hooks/use-mounted";
|
|
11
|
+
export { useTimeout } from "./hooks/use-timeout";
|
|
12
|
+
export { useControlledState } from "./hooks/use-controlled-state";
|
|
13
|
+
export { useDefault } from "./hooks/use-default";
|
|
14
|
+
export { useScrollLocker } from "./hooks/use-scroll-locker";
|
|
15
|
+
export { useForceUpdate } from "./hooks/use-force-update";
|
|
16
|
+
export { useScrollable } from "./hooks/use-scrollable";
|
|
17
|
+
export { useRefs } from "./hooks/use-refs";
|
|
18
|
+
export { useTogglable } from "./hooks/use-togglable";
|
|
19
|
+
export { useEvent } from "./hooks/use-event";
|
|
20
|
+
export { useUpdateEffect } from "./hooks/use-update-effect";
|
|
21
|
+
export { useCounter } from "./hooks/use-counter";
|
|
22
|
+
export { useHover } from "./hooks/use-hover";
|
|
23
|
+
export { useFocus } from "./hooks/use-focus";
|
|
24
|
+
export { useMemorable } from "./hooks/use-memorable";
|
|
25
|
+
export { useMutateObserver } from "./hooks/use-mutate-observer";
|
|
26
|
+
export { useRaf } from "./hooks/use-raf";
|
|
27
|
+
export { useDevicePixelRatio } from "./hooks/use-device-pixel-ratio";
|
|
28
|
+
export { useIdentity } from "./hooks/use-identity";
|
|
29
29
|
/**
|
|
30
30
|
* @description
|
|
31
31
|
* is
|
|
32
32
|
*/
|
|
33
|
-
export { isRefable } from
|
|
34
|
-
export { isUndefined } from
|
|
35
|
-
export { isStateGetter } from
|
|
36
|
-
export { isNull } from
|
|
37
|
-
export { isVoid } from
|
|
38
|
-
export { isArray } from
|
|
39
|
-
export { isComplex } from
|
|
40
|
-
export { isEmpty } from
|
|
41
|
-
export { isDomUsable } from
|
|
42
|
-
export { isMobile } from
|
|
43
|
-
export { isOverflow } from
|
|
44
|
-
export { isStyleElement } from
|
|
45
|
-
export { isFunction } from
|
|
46
|
-
export { isThenable } from
|
|
33
|
+
export { isRefable } from "./is/is-refable";
|
|
34
|
+
export { isUndefined } from "./is/is-undefined";
|
|
35
|
+
export { isStateGetter } from "./is/is-state-getter";
|
|
36
|
+
export { isNull } from "./is/is-null";
|
|
37
|
+
export { isVoid } from "./is/is-void";
|
|
38
|
+
export { isArray } from "./is/is-array";
|
|
39
|
+
export { isComplex } from "./is/is-complex";
|
|
40
|
+
export { isEmpty } from "./is/is-empty";
|
|
41
|
+
export { isDomUsable } from "./is/is-dom-usable";
|
|
42
|
+
export { isMobile } from "./is/is-mobile";
|
|
43
|
+
export { isOverflow } from "./is/is-overflow";
|
|
44
|
+
export { isStyleElement } from "./is/is-style-element";
|
|
45
|
+
export { isFunction } from "./is/is-function";
|
|
46
|
+
export { isThenable } from "./is/is-thenable";
|
|
47
47
|
/**
|
|
48
48
|
* @description
|
|
49
49
|
* utils
|
|
50
50
|
*/
|
|
51
|
-
export { effect } from
|
|
52
|
-
export { unique, uniqueBy } from
|
|
53
|
-
export { range } from
|
|
54
|
-
export { clamp } from
|
|
55
|
-
export { chain } from
|
|
56
|
-
export { debounce } from
|
|
57
|
-
export { toArray } from
|
|
58
|
-
export { toFunction } from
|
|
59
|
-
export { exclude } from
|
|
60
|
-
export { toFormData } from
|
|
61
|
-
export { setStyle } from
|
|
51
|
+
export { effect } from "./utils/effect";
|
|
52
|
+
export { unique, uniqueBy } from "./utils/unique";
|
|
53
|
+
export { range } from "./utils/range";
|
|
54
|
+
export { clamp } from "./utils/clamp";
|
|
55
|
+
export { chain } from "./utils/chain";
|
|
56
|
+
export { debounce } from "./utils/debounce";
|
|
57
|
+
export { toArray } from "./utils/to-array";
|
|
58
|
+
export { toFunction } from "./utils/to-function";
|
|
59
|
+
export { exclude } from "./utils/exclude";
|
|
60
|
+
export { toFormData } from "./utils/to-form-data";
|
|
61
|
+
export { setStyle } from "./utils/set-style";
|
|
62
|
+
export { throttle } from "./utils/throttle";
|
|
63
|
+
export { clone } from "./utils/clone";
|
|
64
|
+
export { toggle } from "./utils/toggle";
|
package/dist/index.js
CHANGED
|
@@ -47,3 +47,6 @@ export { toFunction } from './utils/to-function.js';
|
|
|
47
47
|
export { exclude } from './utils/exclude.js';
|
|
48
48
|
export { toFormData } from './utils/to-form-data.js';
|
|
49
49
|
export { setStyle } from './utils/set-style.js';
|
|
50
|
+
export { throttle } from './utils/throttle.js';
|
|
51
|
+
export { clone } from './utils/clone.js';
|
|
52
|
+
export { toggle } from './utils/toggle.js';
|
package/dist/is/is-complex.js
CHANGED
|
@@ -5,7 +5,7 @@ import { typeof as _typeof } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
|
5
5
|
* complex
|
|
6
6
|
*/
|
|
7
7
|
var isComplex = function isComplex(value) {
|
|
8
|
-
return _typeof(value) ===
|
|
8
|
+
return _typeof(value) === "object" || typeof value === "function";
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export { isComplex };
|
package/dist/is/is-dom-usable.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* if there is dom
|
|
4
4
|
*/
|
|
5
5
|
var isDomUsable = function isDomUsable() {
|
|
6
|
-
return !!(typeof window !==
|
|
6
|
+
return !!(typeof window !== "undefined" && window.document && window.document.createElement);
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
export { isDomUsable };
|
package/dist/is/is-empty.js
CHANGED
package/dist/is/is-function.js
CHANGED
package/dist/is/is-mobile.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* is mobile
|
|
4
4
|
*/
|
|
5
5
|
var isMobile = function isMobile() {
|
|
6
|
-
if (typeof navigator ===
|
|
6
|
+
if (typeof navigator === "undefined" || typeof window === "undefined") {
|
|
7
7
|
return false;
|
|
8
8
|
}
|
|
9
9
|
var agent = navigator.userAgent || navigator.vendor || window.opera;
|
package/dist/is/is-refable.d.ts
CHANGED
package/dist/is/is-refable.js
CHANGED
|
@@ -21,11 +21,11 @@ var _RefableElement = function _RefableElement(element) {
|
|
|
21
21
|
var _type$prototype, _element$prototype;
|
|
22
22
|
var type = isMemo(element) ? element.type.type : element.type;
|
|
23
23
|
// Function component node
|
|
24
|
-
if (typeof type ===
|
|
24
|
+
if (typeof type === "function" && !((_type$prototype = type.prototype) !== null && _type$prototype !== void 0 && _type$prototype.render)) {
|
|
25
25
|
return false;
|
|
26
26
|
}
|
|
27
27
|
// Class component
|
|
28
|
-
if (typeof element ===
|
|
28
|
+
if (typeof element === "function" && !((_element$prototype = element.prototype) !== null && _element$prototype !== void 0 && _element$prototype.render)) {
|
|
29
29
|
return false;
|
|
30
30
|
}
|
|
31
31
|
return true;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export type { Nullable } from
|
|
2
|
-
export type { Partialable } from
|
|
3
|
-
export type { Voidable } from
|
|
4
|
-
export type { RequiredIn } from
|
|
5
|
-
export type { ThenableEffectCallback } from
|
|
6
|
-
export type { First } from
|
|
7
|
-
export type { Last } from
|
|
8
|
-
export type { State, StateGetter } from
|
|
1
|
+
export type { Nullable } from "./nullable";
|
|
2
|
+
export type { Partialable } from "./partialable";
|
|
3
|
+
export type { Voidable } from "./voidable";
|
|
4
|
+
export type { RequiredIn } from "./required-in";
|
|
5
|
+
export type { ThenableEffectCallback } from "./thenable-effect-callback";
|
|
6
|
+
export type { First } from "./first";
|
|
7
|
+
export type { Last } from "./last";
|
|
8
|
+
export type { State, StateGetter } from "./state";
|
package/dist/types/voidable.d.ts
CHANGED
package/dist/utils/chain.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Voidable } from
|
|
1
|
+
import type { Voidable } from "../types";
|
|
2
2
|
export declare const chain: <T extends Function>(...callbacks: Voidable<T>[]) => T;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isArray } from '../is/is-array.js';
|
|
2
|
+
import { isPrimitive } from '../is/is-primitive.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @description
|
|
6
|
+
* in develop, there are many cases to clone a string/number/object/array
|
|
7
|
+
* this util is planning to resolve it
|
|
8
|
+
*/
|
|
9
|
+
var clone = function clone(value) {
|
|
10
|
+
if (isPrimitive(value)) return value;
|
|
11
|
+
if (value instanceof Map) return new Map(value);
|
|
12
|
+
if (value instanceof Set) return new Set(value);
|
|
13
|
+
if (isArray(value)) return Array.from(value);
|
|
14
|
+
return Object(value);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { clone };
|
package/dist/utils/debounce.d.ts
CHANGED
package/dist/utils/effect.d.ts
CHANGED
package/dist/utils/range.js
CHANGED
package/dist/utils/throttle.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Debounced, Debouncer } from
|
|
2
|
-
import { type Callable } from
|
|
1
|
+
import type { Debounced, Debouncer } from "./debounce";
|
|
2
|
+
import { type Callable } from "../hooks/use-event";
|
|
3
3
|
export type Throttled<T extends Callable> = Debounced<T>;
|
|
4
4
|
export type Throttler<T extends Callable, R extends Array<unknown> = Parameters<T>> = Debouncer<T, R>;
|
|
5
5
|
export declare const throttle: <T extends Callable, R extends Array<unknown> = Parameters<T>>(throttler: Throttler<T, R> | T, wait: number) => Throttled<T>;
|
package/dist/utils/to-array.js
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { isSet } from '../is/is-set.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* toggle api
|
|
5
|
+
* @description
|
|
6
|
+
* when list has current key, remove it, otherwise add it
|
|
7
|
+
*
|
|
8
|
+
* return a copy of list
|
|
9
|
+
*/
|
|
10
|
+
var toggle = function toggle(value, key) {
|
|
11
|
+
if (isSet(value)) {
|
|
12
|
+
var _copied = new Set(value);
|
|
13
|
+
if (_copied.has(key)) {
|
|
14
|
+
_copied["delete"](key);
|
|
15
|
+
} else {
|
|
16
|
+
_copied.add(key);
|
|
17
|
+
}
|
|
18
|
+
return _copied;
|
|
19
|
+
}
|
|
20
|
+
var copied = Array.from(value);
|
|
21
|
+
var index = copied.indexOf(key);
|
|
22
|
+
if (index === -1) {
|
|
23
|
+
copied.push(key);
|
|
24
|
+
} else {
|
|
25
|
+
copied.splice(index, 1);
|
|
26
|
+
}
|
|
27
|
+
return copied;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { toggle };
|
package/dist/utils/waitable.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type MonoTypeOperatorFunction } from
|
|
1
|
+
import { type MonoTypeOperatorFunction } from "rxjs";
|
|
2
2
|
interface Props<T extends Array<unknown> = Array<unknown>, R extends Array<unknown> = T> {
|
|
3
3
|
callback: (...args: T) => unknown;
|
|
4
4
|
pipe: (...args: R) => T | Promise<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiszlab/relax",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.58",
|
|
4
4
|
"description": "react utils collection",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"@babel/core": "^7.24.7",
|
|
30
30
|
"@babel/preset-env": "^7.24.7",
|
|
31
31
|
"@babel/preset-typescript": "^7.24.7",
|
|
32
|
+
"@jest/globals": "^29.7.0",
|
|
32
33
|
"@rollup/plugin-babel": "^6.0.4",
|
|
33
34
|
"@rollup/plugin-node-resolve": "^15.1.0",
|
|
34
35
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
35
|
-
"@testing-library/react": "^
|
|
36
|
-
"@types/jest": "^29.5.12",
|
|
36
|
+
"@testing-library/react": "^16.0.0",
|
|
37
37
|
"@types/react": "^18",
|
|
38
38
|
"@types/react-dom": "^18",
|
|
39
39
|
"@types/react-is": "^18",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"jest-environment-jsdom": "^29.7.0",
|
|
42
42
|
"react": "18",
|
|
43
43
|
"react-dom": "18",
|
|
44
|
-
"rollup": "^4.
|
|
45
|
-
"typescript": "5.5.
|
|
44
|
+
"rollup": "^4.18.1",
|
|
45
|
+
"typescript": "5.5.3"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"react": "18",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { type Key } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* @description
|
|
4
|
-
* togglable key
|
|
5
|
-
*/
|
|
6
|
-
type TogglableKey = {
|
|
7
|
-
/**
|
|
8
|
-
* @description
|
|
9
|
-
* unique key
|
|
10
|
-
*/
|
|
11
|
-
key: Key;
|
|
12
|
-
/**
|
|
13
|
-
* @description
|
|
14
|
-
* children
|
|
15
|
-
*/
|
|
16
|
-
children?: TogglableKey[];
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* @description
|
|
20
|
-
* extra options
|
|
21
|
-
*/
|
|
22
|
-
type Options = {
|
|
23
|
-
/**
|
|
24
|
-
* @description
|
|
25
|
-
* default toggled
|
|
26
|
-
*/
|
|
27
|
-
isDefaultToggled?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* @description
|
|
30
|
-
* toggled keys
|
|
31
|
-
*/
|
|
32
|
-
toggledKeys?: Key[];
|
|
33
|
-
/**
|
|
34
|
-
* @description
|
|
35
|
-
* on toggle callback
|
|
36
|
-
*/
|
|
37
|
-
onToggle?: (keys: Key[]) => void;
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* @description
|
|
41
|
-
* toggle able
|
|
42
|
-
*/
|
|
43
|
-
export declare const useTogglable: (togglableKeys: TogglableKey[], { onToggle, ...options }?: Options) => {
|
|
44
|
-
toggledKeys: Set<Key>;
|
|
45
|
-
isToggled: (key: Key) => boolean;
|
|
46
|
-
toggle: (key: Key) => void;
|
|
47
|
-
};
|
|
48
|
-
export {};
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, createClass as _createClass, classPrivateFieldGet2 as _classPrivateFieldGet2, classCallCheck as _classCallCheck, classPrivateFieldInitSpec as _classPrivateFieldInitSpec, classPrivateFieldSet2 as _classPrivateFieldSet2 } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
-
import { useMemo, useCallback } from 'react';
|
|
3
|
-
import { useControlledState } from './use-controlled-state.js';
|
|
4
|
-
import { useEvent } from './use-event.js';
|
|
5
|
-
|
|
6
|
-
var _excluded = ["onToggle"];
|
|
7
|
-
var _groupedLeaves = /*#__PURE__*/new WeakMap();
|
|
8
|
-
var Tree = /*#__PURE__*/function () {
|
|
9
|
-
function Tree() {
|
|
10
|
-
_classCallCheck(this, Tree);
|
|
11
|
-
_classPrivateFieldInitSpec(this, _groupedLeaves, void 0);
|
|
12
|
-
_classPrivateFieldSet2(_groupedLeaves, this, new Map());
|
|
13
|
-
}
|
|
14
|
-
return _createClass(Tree, [{
|
|
15
|
-
key: "groupedLeaves",
|
|
16
|
-
get: function get() {
|
|
17
|
-
return _classPrivateFieldGet2(_groupedLeaves, this);
|
|
18
|
-
}
|
|
19
|
-
}, {
|
|
20
|
-
key: "grow",
|
|
21
|
-
value: function grow(togglableKey) {
|
|
22
|
-
// create leaf, leaf will auto trigger tree collect callback
|
|
23
|
-
new Leaf({
|
|
24
|
-
key: togglableKey.key,
|
|
25
|
-
parent: null,
|
|
26
|
-
belongTo: this
|
|
27
|
-
}).grow(togglableKey.children);
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
}, {
|
|
31
|
-
key: "collect",
|
|
32
|
-
value: function collect(leaf) {
|
|
33
|
-
_classPrivateFieldGet2(_groupedLeaves, this).has(leaf.key) ? _classPrivateFieldGet2(_groupedLeaves, this).get(leaf.key).add(leaf) : _classPrivateFieldGet2(_groupedLeaves, this).set(leaf.key, new Set([leaf]));
|
|
34
|
-
}
|
|
35
|
-
}, {
|
|
36
|
-
key: "toggle",
|
|
37
|
-
value: function toggle(key, toggledKeys) {
|
|
38
|
-
var hasToggled = toggledKeys.has(key);
|
|
39
|
-
var isToggled = !hasToggled;
|
|
40
|
-
return this.toggleBy(key, isToggled, toggledKeys);
|
|
41
|
-
}
|
|
42
|
-
}, {
|
|
43
|
-
key: "toggleBy",
|
|
44
|
-
value: function toggleBy(key, isToggled, toggledKeys) {
|
|
45
|
-
var _classPrivateFieldGet2$1;
|
|
46
|
-
debugger;
|
|
47
|
-
return Array.from((_classPrivateFieldGet2$1 = _classPrivateFieldGet2(_groupedLeaves, this).get(key)) !== null && _classPrivateFieldGet2$1 !== void 0 ? _classPrivateFieldGet2$1 : []).reduce(function (prev, leaf) {
|
|
48
|
-
// deep fall, add or remove child key
|
|
49
|
-
var fell = leaf.fall(isToggled, prev);
|
|
50
|
-
// deep rise, add or remove parent key
|
|
51
|
-
var rised = leaf.rise(fell);
|
|
52
|
-
return rised;
|
|
53
|
-
}, new Set(toggledKeys));
|
|
54
|
-
}
|
|
55
|
-
}]);
|
|
56
|
-
}();
|
|
57
|
-
var _key = /*#__PURE__*/new WeakMap();
|
|
58
|
-
var _belongTo = /*#__PURE__*/new WeakMap();
|
|
59
|
-
var _parent = /*#__PURE__*/new WeakMap();
|
|
60
|
-
var _children = /*#__PURE__*/new WeakMap();
|
|
61
|
-
var Leaf = /*#__PURE__*/function () {
|
|
62
|
-
function Leaf(props) {
|
|
63
|
-
_classCallCheck(this, Leaf);
|
|
64
|
-
_classPrivateFieldInitSpec(this, _key, void 0);
|
|
65
|
-
_classPrivateFieldInitSpec(this, _belongTo, void 0);
|
|
66
|
-
_classPrivateFieldInitSpec(this, _parent, void 0);
|
|
67
|
-
_classPrivateFieldInitSpec(this, _children, void 0);
|
|
68
|
-
_classPrivateFieldSet2(_key, this, props.key);
|
|
69
|
-
_classPrivateFieldSet2(_parent, this, props.parent);
|
|
70
|
-
_classPrivateFieldSet2(_belongTo, this, props.belongTo);
|
|
71
|
-
_classPrivateFieldSet2(_children, this, []);
|
|
72
|
-
// when leaf has grew, let tree collect leaf
|
|
73
|
-
_classPrivateFieldGet2(_belongTo, this).collect(this);
|
|
74
|
-
}
|
|
75
|
-
return _createClass(Leaf, [{
|
|
76
|
-
key: "key",
|
|
77
|
-
get: function get() {
|
|
78
|
-
return _classPrivateFieldGet2(_key, this);
|
|
79
|
-
}
|
|
80
|
-
}, {
|
|
81
|
-
key: "grow",
|
|
82
|
-
value: function grow() {
|
|
83
|
-
var _this = this;
|
|
84
|
-
var children = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
85
|
-
if (children.length === 0) return this;
|
|
86
|
-
children.forEach(function (node) {
|
|
87
|
-
var child = new Leaf({
|
|
88
|
-
key: node.key,
|
|
89
|
-
parent: _this,
|
|
90
|
-
belongTo: _classPrivateFieldGet2(_belongTo, _this)
|
|
91
|
-
}).grow(node.children);
|
|
92
|
-
_classPrivateFieldGet2(_children, _this).push(child);
|
|
93
|
-
});
|
|
94
|
-
return this;
|
|
95
|
-
}
|
|
96
|
-
}, {
|
|
97
|
-
key: "rise",
|
|
98
|
-
value: function rise(toggledKeys) {
|
|
99
|
-
// if current key is toggled or children is all toggled
|
|
100
|
-
// just add current key into toggled keys
|
|
101
|
-
// else remove current key
|
|
102
|
-
var isToggled = toggledKeys.has(_classPrivateFieldGet2(_key, this)) || _classPrivateFieldGet2(_children, this).every(function (child) {
|
|
103
|
-
return toggledKeys.has(child.key);
|
|
104
|
-
});
|
|
105
|
-
var rised = new Set(toggledKeys);
|
|
106
|
-
if (isToggled) {
|
|
107
|
-
rised.add(_classPrivateFieldGet2(_key, this));
|
|
108
|
-
} else {
|
|
109
|
-
rised["delete"](_classPrivateFieldGet2(_key, this));
|
|
110
|
-
}
|
|
111
|
-
if (_classPrivateFieldGet2(_parent, this)) {
|
|
112
|
-
return _classPrivateFieldGet2(_parent, this).rise(rised);
|
|
113
|
-
}
|
|
114
|
-
return rised;
|
|
115
|
-
}
|
|
116
|
-
}, {
|
|
117
|
-
key: "fall",
|
|
118
|
-
value: function fall(isToggled, toggledKeys) {
|
|
119
|
-
var _this2 = this;
|
|
120
|
-
return _classPrivateFieldGet2(_children, this).reduce(function (prev, leaf) {
|
|
121
|
-
// deep loop, remove or add key
|
|
122
|
-
var fell = leaf.fall(isToggled, prev);
|
|
123
|
-
// toggle true, add key
|
|
124
|
-
// toggle false, remove key
|
|
125
|
-
if (isToggled) {
|
|
126
|
-
fell.add(_classPrivateFieldGet2(_key, _this2));
|
|
127
|
-
} else {
|
|
128
|
-
fell["delete"](_classPrivateFieldGet2(_key, _this2));
|
|
129
|
-
}
|
|
130
|
-
return fell;
|
|
131
|
-
}, new Set(toggledKeys));
|
|
132
|
-
}
|
|
133
|
-
}]);
|
|
134
|
-
}();
|
|
135
|
-
/**
|
|
136
|
-
* @description
|
|
137
|
-
* toggle able
|
|
138
|
-
*/
|
|
139
|
-
var useTogglable = function useTogglable(togglableKeys) {
|
|
140
|
-
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
141
|
-
onToggle = _ref.onToggle,
|
|
142
|
-
options = _objectWithoutProperties(_ref, _excluded);
|
|
143
|
-
/// re-create tree when togglable keys changed
|
|
144
|
-
var tree = useMemo(function () {
|
|
145
|
-
return togglableKeys.reduce(function (_tree, togglable) {
|
|
146
|
-
return _tree.grow(togglable);
|
|
147
|
-
}, new Tree());
|
|
148
|
-
}, [togglableKeys]);
|
|
149
|
-
/// use controlled state to record toggled keys
|
|
150
|
-
var _useControlledState = useControlledState(options.toggledKeys, {
|
|
151
|
-
defaultState: function defaultState() {
|
|
152
|
-
return options.isDefaultToggled ? Array.from(Array.from(tree.groupedLeaves.values()).reduce(function (prev, leaves) {
|
|
153
|
-
leaves.forEach(function (leaf) {
|
|
154
|
-
return prev.add(leaf.key);
|
|
155
|
-
});
|
|
156
|
-
return prev;
|
|
157
|
-
}, new Set())) : [];
|
|
158
|
-
}
|
|
159
|
-
}),
|
|
160
|
-
_useControlledState2 = _slicedToArray(_useControlledState, 2),
|
|
161
|
-
_toggledKeys = _useControlledState2[0],
|
|
162
|
-
_setToggledKeys = _useControlledState2[1];
|
|
163
|
-
/// use set for toggled keys to make it read-only
|
|
164
|
-
var readableToggledKeys = useMemo(function () {
|
|
165
|
-
return new Set(_toggledKeys);
|
|
166
|
-
}, [_toggledKeys]);
|
|
167
|
-
/// check current key is toggled
|
|
168
|
-
var isToggled = useCallback(function (key) {
|
|
169
|
-
return !readableToggledKeys || readableToggledKeys.has(key);
|
|
170
|
-
}, [readableToggledKeys]);
|
|
171
|
-
/// toggle one key
|
|
172
|
-
var toggle = useEvent(function (key) {
|
|
173
|
-
// get new toggled keys by toggle current key
|
|
174
|
-
var _toggledKeys = Array.from(tree.toggle(key, readableToggledKeys));
|
|
175
|
-
// set state
|
|
176
|
-
_setToggledKeys(_toggledKeys);
|
|
177
|
-
// trigger on toggle callback
|
|
178
|
-
onToggle === null || onToggle === void 0 || onToggle(_toggledKeys);
|
|
179
|
-
});
|
|
180
|
-
return {
|
|
181
|
-
toggledKeys: readableToggledKeys,
|
|
182
|
-
isToggled: isToggled,
|
|
183
|
-
toggle: toggle
|
|
184
|
-
};
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
export { useTogglable };
|