@aiszlab/relax 1.2.32 → 1.2.33
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/contains.mjs +1 -1
- package/dist/dom/scroll-to.mjs +5 -13
- package/dist/hooks/use-boolean.mjs +1 -1
- package/dist/hooks/use-controlled-state.mjs +1 -1
- package/dist/hooks/use-counter.mjs +1 -1
- package/dist/hooks/use-debounce-callback.mjs +4 -5
- package/dist/hooks/use-focus.mjs +4 -4
- package/dist/hooks/use-hover.mjs +4 -4
- package/dist/hooks/use-image-loader.mjs +2 -4
- package/dist/hooks/use-scroll-locker.d.ts +4 -0
- package/dist/hooks/use-scroll-locker.mjs +49 -56
- package/dist/hooks/use-throttle-callback.mjs +4 -5
- package/dist/hooks/use-toggleable.mjs +29 -35
- package/dist/is/is-mobile.mjs +1 -1
- package/dist/is/is-refable.mjs +2 -3
- package/dist/utils/chain.mjs +1 -1
- package/dist/utils/debounce.mjs +21 -29
- package/dist/utils/set-style.d.ts +6 -0
- package/dist/utils/set-style.mjs +17 -0
- package/package.json +1 -1
- package/dist/node_modules/tslib/tslib.es6.mjs +0 -25
package/dist/dom/contains.mjs
CHANGED
package/dist/dom/scroll-to.mjs
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
|
-
import { __classPrivateFieldSet, __classPrivateFieldGet } from '../node_modules/tslib/tslib.es6.mjs';
|
|
2
|
-
|
|
3
|
-
var _a, _Scroller_scrolled, _Scroller_scroller;
|
|
4
1
|
class Scroller {
|
|
2
|
+
#scrolled = new Map();
|
|
3
|
+
// singleton mode
|
|
4
|
+
static #scroller = null;
|
|
5
5
|
constructor() {
|
|
6
|
-
|
|
7
|
-
var _c;
|
|
8
|
-
_Scroller_scrolled.set(this, new Map()
|
|
9
|
-
// singleton mode
|
|
10
|
-
);
|
|
11
|
-
return (__classPrivateFieldSet(_c = _a, _a, (_b = __classPrivateFieldGet(_c, _a, "f", _Scroller_scroller)) !== null && _b !== void 0 ? _b : this, "f", _Scroller_scroller));
|
|
6
|
+
return (Scroller.#scroller ??= this);
|
|
12
7
|
}
|
|
13
8
|
get scrolled() {
|
|
14
|
-
return
|
|
9
|
+
return this.#scrolled;
|
|
15
10
|
}
|
|
16
11
|
currentAt(direction) {
|
|
17
12
|
return direction === 'vertical' ? 'scrollTop' : 'scrollLeft';
|
|
18
13
|
}
|
|
19
14
|
}
|
|
20
|
-
_a = Scroller, _Scroller_scrolled = new WeakMap();
|
|
21
|
-
// singleton mode
|
|
22
|
-
_Scroller_scroller = { value: null };
|
|
23
15
|
/**
|
|
24
16
|
* @description
|
|
25
17
|
* scroll to for wrapper element
|
|
@@ -7,7 +7,7 @@ import { useState, useCallback } from 'react';
|
|
|
7
7
|
* boolean state, in relax, we already create some api to easy use
|
|
8
8
|
*/
|
|
9
9
|
const useBoolean = (initialState) => {
|
|
10
|
-
const [isOn, setIsOn] = useState(initialState
|
|
10
|
+
const [isOn, setIsOn] = useState(initialState ?? false);
|
|
11
11
|
const turnOn = useCallback(() => setIsOn(true), []);
|
|
12
12
|
const turnOff = useCallback(() => setIsOn(false), []);
|
|
13
13
|
const toggle = useCallback(() => setIsOn((_isOn) => !_isOn), []);
|
|
@@ -27,7 +27,7 @@ const useControlledState = (controlledState, { defaultState } = {}) => {
|
|
|
27
27
|
useUpdateEffect(() => {
|
|
28
28
|
if (!isUndefined(controlledState))
|
|
29
29
|
return;
|
|
30
|
-
_setState(controlledState
|
|
30
|
+
_setState(controlledState ?? defaultState);
|
|
31
31
|
}, [controlledState]);
|
|
32
32
|
/// use controlled
|
|
33
33
|
const state = !isUndefined(controlledState) ? controlledState : _state;
|
|
@@ -9,7 +9,7 @@ import { useDefault } from './use-default.mjs';
|
|
|
9
9
|
* a number counter with some useful apis
|
|
10
10
|
*/
|
|
11
11
|
const useCounter = (initialState, { max = Infinity, min = -Infinity } = { max: Infinity, min: -Infinity }) => {
|
|
12
|
-
const defaultState = useDefault(initialState
|
|
12
|
+
const defaultState = useDefault(initialState ?? 0);
|
|
13
13
|
const [_count, _setCount] = useState(defaultState);
|
|
14
14
|
const add = useCallback((step = 1) => {
|
|
15
15
|
_setCount((prev) => Math.min(max, prev + step));
|
|
@@ -13,8 +13,7 @@ const useDebouncer = (debouncer) => {
|
|
|
13
13
|
return _debouncer.callback(...args);
|
|
14
14
|
}),
|
|
15
15
|
pipeable: useEvent((...args) => {
|
|
16
|
-
|
|
17
|
-
return (_b = (_a = _debouncer.pipeable) === null || _a === void 0 ? void 0 : _a.call(_debouncer, ...args)) !== null && _b !== void 0 ? _b : args;
|
|
16
|
+
return _debouncer.pipeable?.(...args) ?? args;
|
|
18
17
|
})
|
|
19
18
|
};
|
|
20
19
|
};
|
|
@@ -49,9 +48,9 @@ const useDebounceCallback = (debouncer, wait = 1000) => {
|
|
|
49
48
|
};
|
|
50
49
|
}, [wait]);
|
|
51
50
|
return useDefault(() => ({
|
|
52
|
-
next: (...args) =>
|
|
53
|
-
flush: () =>
|
|
54
|
-
abort: () =>
|
|
51
|
+
next: (...args) => debounced.current?.next(...args),
|
|
52
|
+
flush: () => debounced.current?.flush(),
|
|
53
|
+
abort: () => debounced.current?.abort()
|
|
55
54
|
}));
|
|
56
55
|
};
|
|
57
56
|
|
package/dist/hooks/use-focus.mjs
CHANGED
|
@@ -5,11 +5,11 @@ import { chain } from '../utils/chain.mjs';
|
|
|
5
5
|
const useFocus = (props) => {
|
|
6
6
|
const [isFocused, { turnOn, turnOff }] = useBoolean(false);
|
|
7
7
|
const onFocus = useCallback((e) => {
|
|
8
|
-
chain(props
|
|
9
|
-
}, [props
|
|
8
|
+
chain(props?.onFocus, turnOn, () => props?.onFocusChange?.(true))(e);
|
|
9
|
+
}, [props?.onFocus, props?.onFocusChange]);
|
|
10
10
|
const onBlur = useCallback((e) => {
|
|
11
|
-
chain(props
|
|
12
|
-
}, [props
|
|
11
|
+
chain(props?.onBlur, turnOff, () => props?.onFocusChange?.(false))(e);
|
|
12
|
+
}, [props?.onBlur, props?.onFocusChange]);
|
|
13
13
|
return [isFocused, { onFocus, onBlur }];
|
|
14
14
|
};
|
|
15
15
|
|
package/dist/hooks/use-hover.mjs
CHANGED
|
@@ -5,11 +5,11 @@ import { chain } from '../utils/chain.mjs';
|
|
|
5
5
|
const useHover = (props) => {
|
|
6
6
|
const [isHovered, { turnOn, turnOff }] = useBoolean(false);
|
|
7
7
|
const onPointerEnter = useCallback((e) => {
|
|
8
|
-
chain(props
|
|
9
|
-
}, [props
|
|
8
|
+
chain(props?.onEnter, turnOn)(e);
|
|
9
|
+
}, [props?.onEnter]);
|
|
10
10
|
const onPointerLeave = useCallback((e) => {
|
|
11
|
-
chain(props
|
|
12
|
-
}, [props
|
|
11
|
+
chain(props?.onEnter, turnOff)(e);
|
|
12
|
+
}, [props?.onLeave]);
|
|
13
13
|
return [isHovered, { onPointerEnter, onPointerLeave }];
|
|
14
14
|
};
|
|
15
15
|
|
|
@@ -25,12 +25,10 @@ const useImageLoader = ({ src }) => {
|
|
|
25
25
|
});
|
|
26
26
|
const image = new Image();
|
|
27
27
|
image.addEventListener('load', () => {
|
|
28
|
-
|
|
29
|
-
(_a = loader.current) === null || _a === void 0 ? void 0 : _a.complete();
|
|
28
|
+
loader.current?.complete();
|
|
30
29
|
});
|
|
31
30
|
image.addEventListener('error', () => {
|
|
32
|
-
|
|
33
|
-
(_a = loader.current) === null || _a === void 0 ? void 0 : _a.error(null);
|
|
31
|
+
loader.current?.error(null);
|
|
34
32
|
});
|
|
35
33
|
image.src = src;
|
|
36
34
|
return () => {
|
|
@@ -1,83 +1,76 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useId, useLayoutEffect } from 'react';
|
|
1
|
+
import { useLayoutEffect } from 'react';
|
|
3
2
|
import { isOverflow } from '../is/is-overflow.mjs';
|
|
4
|
-
import {
|
|
3
|
+
import { setStyle } from '../utils/set-style.mjs';
|
|
5
4
|
|
|
6
|
-
var _a, _ScrollLocker_scrollLocker, _ScrollLocker_barSize;
|
|
7
|
-
const isComputable = (value) => /^(.*)px$/.test(value);
|
|
8
5
|
class ScrollLocker {
|
|
6
|
+
// singleton mode
|
|
7
|
+
static #scrollLocker = null;
|
|
8
|
+
// bar size
|
|
9
|
+
#barSize = null;
|
|
10
|
+
// locked elements, with previous styles
|
|
11
|
+
#locked = new Map();
|
|
9
12
|
constructor() {
|
|
10
|
-
|
|
11
|
-
var _c;
|
|
12
|
-
// bar size
|
|
13
|
-
_ScrollLocker_barSize.set(this, null);
|
|
14
|
-
return (__classPrivateFieldSet(_c = _a, _a, (_b = __classPrivateFieldGet(_c, _a, "f", _ScrollLocker_scrollLocker)) !== null && _b !== void 0 ? _b : this, "f", _ScrollLocker_scrollLocker));
|
|
13
|
+
return (ScrollLocker.#scrollLocker ??= this);
|
|
15
14
|
}
|
|
16
15
|
get barSize() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
if (this.#barSize)
|
|
17
|
+
return this.#barSize;
|
|
18
|
+
// how to calculate dom scroll bar size
|
|
19
|
+
// create a backend dom element, set force scrollable
|
|
20
|
+
const _target = document.createElement('div');
|
|
21
|
+
_target.attributeStyleMap.set('position', 'absolute');
|
|
22
|
+
_target.attributeStyleMap.set('left', '0');
|
|
23
|
+
_target.attributeStyleMap.set('top', '0');
|
|
24
|
+
_target.attributeStyleMap.set('width', '100vw');
|
|
25
|
+
_target.attributeStyleMap.set('height', '100vh');
|
|
26
|
+
_target.attributeStyleMap.set('overflow', 'scroll');
|
|
27
|
+
// calculate, then clear
|
|
28
|
+
document.body.appendChild(_target);
|
|
29
|
+
this.#barSize = {
|
|
30
|
+
width: _target.offsetWidth - _target.clientWidth,
|
|
31
|
+
height: _target.offsetHeight - _target.clientHeight
|
|
32
|
+
};
|
|
33
|
+
document.body.removeChild(_target);
|
|
34
|
+
return this.#barSize;
|
|
25
35
|
}
|
|
26
36
|
get isOverflow() {
|
|
27
37
|
return isOverflow();
|
|
28
38
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
${this.isOverflow ? `width: calc(100% - ${this.barSize.width});` : ''}
|
|
33
|
-
}`;
|
|
34
|
-
}
|
|
35
|
-
get container() {
|
|
36
|
-
return document.head || document.body;
|
|
37
|
-
}
|
|
38
|
-
getLocked(id) {
|
|
39
|
-
return Array.from(this.container.children).filter((element) => isStyleElement(element)).find((element) => element.id === id);
|
|
40
|
-
}
|
|
41
|
-
lock(id) {
|
|
42
|
-
if (!this.container)
|
|
39
|
+
lock(element = document.body) {
|
|
40
|
+
// if locked, do not lock again
|
|
41
|
+
if (this.#locked.has(element))
|
|
43
42
|
return;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
return locked;
|
|
50
|
-
}
|
|
51
|
-
const locker = document.createElement('style');
|
|
52
|
-
locker.id = id;
|
|
53
|
-
locker.innerHTML = this.locker;
|
|
54
|
-
this.container.appendChild(locker);
|
|
55
|
-
return locker;
|
|
43
|
+
this.#locked.set(element, setStyle(element, {
|
|
44
|
+
overflow: 'hidden',
|
|
45
|
+
width: `calc(100% - ${this.barSize.width}px)`
|
|
46
|
+
}));
|
|
56
47
|
}
|
|
57
|
-
unlock(
|
|
58
|
-
|
|
59
|
-
if (!locked)
|
|
48
|
+
unlock(element = document.body) {
|
|
49
|
+
// not locked, no need to unlock
|
|
50
|
+
if (!this.#locked.has(element))
|
|
60
51
|
return;
|
|
61
|
-
|
|
52
|
+
// reset style, in lock, some styled are setted
|
|
53
|
+
setStyle(element, this.#locked.get(element));
|
|
54
|
+
this.#locked.delete(element);
|
|
62
55
|
}
|
|
63
56
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
57
|
+
/**
|
|
58
|
+
* @description
|
|
59
|
+
* hooks
|
|
60
|
+
*/
|
|
67
61
|
const useScrollLocker = (isLock) => {
|
|
68
|
-
const id = useId();
|
|
69
62
|
useLayoutEffect(() => {
|
|
70
63
|
const scrollLocker = new ScrollLocker();
|
|
71
64
|
if (!!isLock) {
|
|
72
|
-
scrollLocker.lock(
|
|
65
|
+
scrollLocker.lock(document.body);
|
|
73
66
|
}
|
|
74
67
|
else {
|
|
75
|
-
scrollLocker.unlock(
|
|
68
|
+
scrollLocker.unlock(document.body);
|
|
76
69
|
}
|
|
77
70
|
return () => {
|
|
78
|
-
scrollLocker.unlock(
|
|
71
|
+
scrollLocker.unlock(document.body);
|
|
79
72
|
};
|
|
80
|
-
}, [!!isLock
|
|
73
|
+
}, [!!isLock]);
|
|
81
74
|
};
|
|
82
75
|
|
|
83
76
|
export { useScrollLocker };
|
|
@@ -13,8 +13,7 @@ const useThrottler = (debouncer) => {
|
|
|
13
13
|
return _debouncer.callback(...args);
|
|
14
14
|
}),
|
|
15
15
|
pipeable: useEvent((...args) => {
|
|
16
|
-
|
|
17
|
-
return (_b = (_a = _debouncer.pipeable) === null || _a === void 0 ? void 0 : _a.call(_debouncer, ...args)) !== null && _b !== void 0 ? _b : args;
|
|
16
|
+
return _debouncer.pipeable?.(...args) ?? args;
|
|
18
17
|
})
|
|
19
18
|
};
|
|
20
19
|
};
|
|
@@ -49,9 +48,9 @@ const useThrottleCallback = (throttler, duration = 1000) => {
|
|
|
49
48
|
};
|
|
50
49
|
}, [duration]);
|
|
51
50
|
return useDefault(() => ({
|
|
52
|
-
next: (...args) =>
|
|
53
|
-
flush: () =>
|
|
54
|
-
abort: () =>
|
|
51
|
+
next: (...args) => throttled.current?.next(...args),
|
|
52
|
+
flush: () => throttled.current?.flush(),
|
|
53
|
+
abort: () => throttled.current?.abort()
|
|
55
54
|
}));
|
|
56
55
|
};
|
|
57
56
|
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { __rest, __classPrivateFieldSet, __classPrivateFieldGet } from '../node_modules/tslib/tslib.es6.mjs';
|
|
2
1
|
import { useMemo, useCallback } from 'react';
|
|
3
2
|
import { useControlledState } from './use-controlled-state.mjs';
|
|
4
3
|
|
|
5
|
-
var _Tree_groupedLeaves, _Leaf_key, _Leaf_belongTo, _Leaf_parent, _Leaf_children;
|
|
6
4
|
class Tree {
|
|
5
|
+
#groupedLeaves;
|
|
7
6
|
constructor() {
|
|
8
|
-
|
|
9
|
-
__classPrivateFieldSet(this, _Tree_groupedLeaves, new Map(), "f");
|
|
7
|
+
this.#groupedLeaves = new Map();
|
|
10
8
|
}
|
|
11
9
|
get groupedLeaves() {
|
|
12
|
-
return
|
|
10
|
+
return this.#groupedLeaves;
|
|
13
11
|
}
|
|
14
12
|
grow(toggleableKey) {
|
|
15
13
|
// create leaf, leaf will auto trigger tree collect callback
|
|
@@ -21,9 +19,9 @@ class Tree {
|
|
|
21
19
|
return this;
|
|
22
20
|
}
|
|
23
21
|
collect(leaf) {
|
|
24
|
-
|
|
25
|
-
?
|
|
26
|
-
:
|
|
22
|
+
this.#groupedLeaves.has(leaf.key)
|
|
23
|
+
? this.#groupedLeaves.get(leaf.key).add(leaf)
|
|
24
|
+
: this.#groupedLeaves.set(leaf.key, new Set([leaf]));
|
|
27
25
|
}
|
|
28
26
|
toggle(key, toggledKeys) {
|
|
29
27
|
const hasToggled = toggledKeys.has(key);
|
|
@@ -31,8 +29,7 @@ class Tree {
|
|
|
31
29
|
return this.toggleBy(key, _isToggled, toggledKeys);
|
|
32
30
|
}
|
|
33
31
|
toggleBy(key, isToggled, toggledKeys) {
|
|
34
|
-
|
|
35
|
-
return Array.from((_a = __classPrivateFieldGet(this, _Tree_groupedLeaves, "f").get(key)) !== null && _a !== void 0 ? _a : []).reduce((prev, leaf) => {
|
|
32
|
+
return Array.from(this.#groupedLeaves.get(key) ?? []).reduce((prev, leaf) => {
|
|
36
33
|
// deep fall, add or remove child key
|
|
37
34
|
const fell = leaf.fall(isToggled, prev);
|
|
38
35
|
// deep rise, add or remove parent key
|
|
@@ -41,22 +38,21 @@ class Tree {
|
|
|
41
38
|
}, new Set(toggledKeys));
|
|
42
39
|
}
|
|
43
40
|
}
|
|
44
|
-
_Tree_groupedLeaves = new WeakMap();
|
|
45
41
|
class Leaf {
|
|
42
|
+
#key;
|
|
43
|
+
#belongTo;
|
|
44
|
+
#parent;
|
|
45
|
+
#children;
|
|
46
46
|
constructor(props) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
__classPrivateFieldSet(this, _Leaf_key, props.key, "f");
|
|
52
|
-
__classPrivateFieldSet(this, _Leaf_parent, props.parent, "f");
|
|
53
|
-
__classPrivateFieldSet(this, _Leaf_belongTo, props.belongTo, "f");
|
|
54
|
-
__classPrivateFieldSet(this, _Leaf_children, [], "f");
|
|
47
|
+
this.#key = props.key;
|
|
48
|
+
this.#parent = props.parent;
|
|
49
|
+
this.#belongTo = props.belongTo;
|
|
50
|
+
this.#children = [];
|
|
55
51
|
// when leaf has grew, let tree collect leaf
|
|
56
|
-
|
|
52
|
+
this.#belongTo.collect(this);
|
|
57
53
|
}
|
|
58
54
|
get key() {
|
|
59
|
-
return
|
|
55
|
+
return this.#key;
|
|
60
56
|
}
|
|
61
57
|
grow(toggleableKeys = []) {
|
|
62
58
|
if (toggleableKeys.length > 0) {
|
|
@@ -64,9 +60,9 @@ class Leaf {
|
|
|
64
60
|
const child = new Leaf({
|
|
65
61
|
key: _toggleableKey.key,
|
|
66
62
|
parent: this,
|
|
67
|
-
belongTo:
|
|
63
|
+
belongTo: this.#belongTo
|
|
68
64
|
}).grow(_toggleableKey.children);
|
|
69
|
-
|
|
65
|
+
this.#children.push(child);
|
|
70
66
|
});
|
|
71
67
|
}
|
|
72
68
|
return this;
|
|
@@ -75,42 +71,40 @@ class Leaf {
|
|
|
75
71
|
// if current key is toggled or children is all toggled
|
|
76
72
|
// just add current key into toggled keys
|
|
77
73
|
// else remove current key
|
|
78
|
-
const isToggled = toggledKeys.has(
|
|
74
|
+
const isToggled = toggledKeys.has(this.#key) || this.#children.every((child) => toggledKeys.has(child.key));
|
|
79
75
|
const rised = new Set(toggledKeys);
|
|
80
76
|
if (isToggled) {
|
|
81
|
-
rised.add(
|
|
77
|
+
rised.add(this.#key);
|
|
82
78
|
}
|
|
83
79
|
else {
|
|
84
|
-
rised.delete(
|
|
80
|
+
rised.delete(this.#key);
|
|
85
81
|
}
|
|
86
|
-
if (
|
|
87
|
-
return
|
|
82
|
+
if (this.#parent) {
|
|
83
|
+
return this.#parent.rise(rised);
|
|
88
84
|
}
|
|
89
85
|
return rised;
|
|
90
86
|
}
|
|
91
87
|
fall(isToggled, toggledKeys) {
|
|
92
|
-
return
|
|
88
|
+
return this.#children.reduce((prev, leaf) => {
|
|
93
89
|
// deep loop, remove or add key
|
|
94
90
|
const fell = leaf.fall(isToggled, prev);
|
|
95
91
|
// toggle true, add key
|
|
96
92
|
// toggle false, remove key
|
|
97
93
|
if (isToggled) {
|
|
98
|
-
fell.add(
|
|
94
|
+
fell.add(this.#key);
|
|
99
95
|
}
|
|
100
96
|
else {
|
|
101
|
-
fell.delete(
|
|
97
|
+
fell.delete(this.#key);
|
|
102
98
|
}
|
|
103
99
|
return fell;
|
|
104
100
|
}, new Set(toggledKeys));
|
|
105
101
|
}
|
|
106
102
|
}
|
|
107
|
-
_Leaf_key = new WeakMap(), _Leaf_belongTo = new WeakMap(), _Leaf_parent = new WeakMap(), _Leaf_children = new WeakMap();
|
|
108
103
|
/**
|
|
109
104
|
* @description
|
|
110
105
|
* toggle able
|
|
111
106
|
*/
|
|
112
|
-
const useToggleable = (toggleableKeys,
|
|
113
|
-
var { onToggle } = _a, options = __rest(_a, ["onToggle"]);
|
|
107
|
+
const useToggleable = (toggleableKeys, { onToggle, ...options } = {}) => {
|
|
114
108
|
/// re-create tree when toggleable keys changed
|
|
115
109
|
const tree = useMemo(() => {
|
|
116
110
|
return toggleableKeys.reduce((_tree, toggleable) => {
|
|
@@ -139,7 +133,7 @@ const useToggleable = (toggleableKeys, _a = {}) => {
|
|
|
139
133
|
// set state
|
|
140
134
|
_setToggledKeys(_toggledKeys);
|
|
141
135
|
// trigger on toggle callback
|
|
142
|
-
onToggle
|
|
136
|
+
onToggle?.(_toggledKeys);
|
|
143
137
|
}, [tree, readableToggledKeys, _setToggledKeys, onToggle]);
|
|
144
138
|
return {
|
|
145
139
|
toggledKeys: readableToggledKeys,
|
package/dist/is/is-mobile.mjs
CHANGED
|
@@ -10,7 +10,7 @@ const isMobile = () => {
|
|
|
10
10
|
navigator.vendor ||
|
|
11
11
|
window.opera;
|
|
12
12
|
return (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(agent) ||
|
|
13
|
-
/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(agent
|
|
13
|
+
/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(agent?.substring(0, 4)));
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export { isMobile };
|
package/dist/is/is-refable.mjs
CHANGED
|
@@ -18,14 +18,13 @@ const isRefable = (node) => {
|
|
|
18
18
|
* refable element
|
|
19
19
|
*/
|
|
20
20
|
const _RefableElement = (element) => {
|
|
21
|
-
var _a, _b;
|
|
22
21
|
const type = isMemo(element) ? element.type.type : element.type;
|
|
23
22
|
// Function component node
|
|
24
|
-
if (typeof type === 'function' && !
|
|
23
|
+
if (typeof type === 'function' && !type.prototype?.render) {
|
|
25
24
|
return false;
|
|
26
25
|
}
|
|
27
26
|
// Class component
|
|
28
|
-
if (typeof element === 'function' && !
|
|
27
|
+
if (typeof element === 'function' && !element.prototype?.render) {
|
|
29
28
|
return false;
|
|
30
29
|
}
|
|
31
30
|
return true;
|
package/dist/utils/chain.mjs
CHANGED
package/dist/utils/debounce.mjs
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import { __classPrivateFieldSet, __classPrivateFieldGet } from '../node_modules/tslib/tslib.es6.mjs';
|
|
2
1
|
import { Observable, debounceTime, throttleTime, concatMap, from } from 'rxjs';
|
|
3
2
|
import { isFunction } from '../is/is-function.mjs';
|
|
4
3
|
|
|
5
|
-
var _Trigger_subscriber, _Trigger_subscription, _Trigger_callback, _Trigger_pipeable, _Trigger_wait, _Trigger_type;
|
|
6
4
|
class Trigger {
|
|
5
|
+
#subscriber;
|
|
6
|
+
#subscription;
|
|
7
|
+
#callback;
|
|
8
|
+
#pipeable;
|
|
9
|
+
#wait;
|
|
10
|
+
#type;
|
|
7
11
|
constructor(debouncer, wait, type = 'debounce') {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
_Trigger_type.set(this, void 0);
|
|
15
|
-
__classPrivateFieldSet(this, _Trigger_subscriber, null, "f");
|
|
16
|
-
__classPrivateFieldSet(this, _Trigger_subscription, null, "f");
|
|
17
|
-
__classPrivateFieldSet(this, _Trigger_callback, debouncer.callback, "f");
|
|
18
|
-
__classPrivateFieldSet(this, _Trigger_pipeable, (_a = debouncer.pipeable) !== null && _a !== void 0 ? _a : ((...args) => args), "f");
|
|
19
|
-
__classPrivateFieldSet(this, _Trigger_wait, wait, "f");
|
|
20
|
-
__classPrivateFieldSet(this, _Trigger_type, type, "f");
|
|
12
|
+
this.#subscriber = null;
|
|
13
|
+
this.#subscription = null;
|
|
14
|
+
this.#callback = debouncer.callback;
|
|
15
|
+
this.#pipeable = debouncer.pipeable ?? ((...args) => args);
|
|
16
|
+
this.#wait = wait;
|
|
17
|
+
this.#type = type;
|
|
21
18
|
}
|
|
22
19
|
/**
|
|
23
20
|
* @description
|
|
@@ -25,14 +22,13 @@ class Trigger {
|
|
|
25
22
|
* used for debounce/throttle handler
|
|
26
23
|
*/
|
|
27
24
|
use() {
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
this.#subscription = new Observable((subscriber) => {
|
|
26
|
+
this.#subscriber = subscriber;
|
|
30
27
|
})
|
|
31
|
-
.pipe(
|
|
28
|
+
.pipe(this.#type === 'debounce' ? debounceTime(this.#wait) : throttleTime(this.#wait), concatMap((args) => from(Promise.resolve(this.#pipeable(...args)))))
|
|
32
29
|
.subscribe((args) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}), "f");
|
|
30
|
+
this.#callback?.(...args);
|
|
31
|
+
});
|
|
36
32
|
return this;
|
|
37
33
|
}
|
|
38
34
|
/**
|
|
@@ -43,8 +39,7 @@ class Trigger {
|
|
|
43
39
|
* so it will make some async problems, pls attention
|
|
44
40
|
*/
|
|
45
41
|
flush() {
|
|
46
|
-
|
|
47
|
-
(_a = __classPrivateFieldGet(this, _Trigger_subscriber, "f")) === null || _a === void 0 ? void 0 : _a.complete();
|
|
42
|
+
this.#subscriber?.complete();
|
|
48
43
|
this.use();
|
|
49
44
|
}
|
|
50
45
|
/**
|
|
@@ -54,9 +49,8 @@ class Trigger {
|
|
|
54
49
|
* in relax, we will create a new observable for next debounce/throttle handler
|
|
55
50
|
*/
|
|
56
51
|
abort() {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
(_b = __classPrivateFieldGet(this, _Trigger_subscriber, "f")) === null || _b === void 0 ? void 0 : _b.error();
|
|
52
|
+
this.#subscription?.unsubscribe();
|
|
53
|
+
this.#subscriber?.error();
|
|
60
54
|
this.use();
|
|
61
55
|
}
|
|
62
56
|
/**
|
|
@@ -64,11 +58,9 @@ class Trigger {
|
|
|
64
58
|
* trigger value
|
|
65
59
|
*/
|
|
66
60
|
next(...args) {
|
|
67
|
-
|
|
68
|
-
(_a = __classPrivateFieldGet(this, _Trigger_subscriber, "f")) === null || _a === void 0 ? void 0 : _a.next(args);
|
|
61
|
+
this.#subscriber?.next(args);
|
|
69
62
|
}
|
|
70
63
|
}
|
|
71
|
-
_Trigger_subscriber = new WeakMap(), _Trigger_subscription = new WeakMap(), _Trigger_callback = new WeakMap(), _Trigger_pipeable = new WeakMap(), _Trigger_wait = new WeakMap(), _Trigger_type = new WeakMap();
|
|
72
64
|
const debounce = (debouncer, wait) => {
|
|
73
65
|
const _isFunction = isFunction(debouncer);
|
|
74
66
|
const trigger = new Trigger({
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* set inline style util
|
|
4
|
+
*/
|
|
5
|
+
const setStyle = (target, styles) => {
|
|
6
|
+
if (!styles)
|
|
7
|
+
return {};
|
|
8
|
+
return Object.entries(styles).reduce((prev, [key, value]) => {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
prev[key] = target.style[key];
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
target.style[key] = value;
|
|
13
|
+
return prev;
|
|
14
|
+
}, {});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { setStyle };
|
package/package.json
CHANGED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
function __rest(s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
4
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
5
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
6
|
-
}
|
|
7
|
-
return t;
|
|
8
|
-
}
|
|
9
|
-
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
10
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
11
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
12
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
13
|
-
}
|
|
14
|
-
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
15
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
16
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
17
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
18
|
-
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
19
|
-
}
|
|
20
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
21
|
-
var e = new Error(message);
|
|
22
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export { __classPrivateFieldGet, __classPrivateFieldSet, __rest };
|