@aiszlab/relax 1.3.11 → 1.3.13
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/clipboard.d.ts +1 -0
- package/dist/dom/contains.cjs +22 -0
- package/dist/dom/index.cjs +9 -0
- package/dist/dom/index.mjs +2 -0
- package/dist/dom/scroll-to.cjs +74 -0
- package/dist/hooks/use-boolean.cjs +36 -0
- package/dist/hooks/use-click-away.cjs +29 -0
- package/dist/hooks/{use-click-away.js → use-click-away.mjs} +3 -3
- package/dist/hooks/use-controlled-state.cjs +39 -0
- package/dist/hooks/{use-controlled-state.js → use-controlled-state.mjs} +3 -3
- package/dist/hooks/use-counter.cjs +61 -0
- package/dist/hooks/{use-counter.js → use-counter.mjs} +2 -2
- package/dist/hooks/use-debounce-callback.cjs +83 -0
- package/dist/hooks/{use-debounce-callback.js → use-debounce-callback.mjs} +4 -4
- package/dist/hooks/use-default.cjs +16 -0
- package/dist/hooks/{use-default.js → use-default.mjs} +1 -1
- package/dist/hooks/use-device-pixel-ratio.cjs +22 -0
- package/dist/hooks/{use-device-pixel-ratio.js → use-device-pixel-ratio.mjs} +1 -1
- package/dist/hooks/use-event.cjs +16 -0
- package/dist/hooks/use-focus.cjs +33 -0
- package/dist/hooks/{use-focus.js → use-focus.mjs} +2 -2
- package/dist/hooks/use-force-update.cjs +23 -0
- package/dist/hooks/use-hover.cjs +27 -0
- package/dist/hooks/{use-hover.js → use-hover.mjs} +3 -3
- package/dist/hooks/use-identity.cjs +22 -0
- package/dist/hooks/use-image-loader.cjs +65 -0
- package/dist/hooks/use-infinite-scroll.cjs +64 -0
- package/dist/hooks/{use-infinite-scroll.js → use-infinite-scroll.mjs} +2 -2
- package/dist/hooks/use-is-mounted.cjs +35 -0
- package/dist/hooks/{use-is-mounted.js → use-is-mounted.mjs} +1 -1
- package/dist/hooks/use-local-storage-state.cjs +9 -0
- package/dist/hooks/{use-local-storage-state.js → use-local-storage-state.mjs} +1 -1
- package/dist/hooks/use-media-query.cjs +55 -0
- package/dist/hooks/{use-media-query.js → use-media-query.mjs} +3 -3
- package/dist/hooks/use-memorable.cjs +16 -0
- package/dist/hooks/use-mount.cjs +18 -0
- package/dist/hooks/{use-mount.js → use-mount.mjs} +1 -1
- package/dist/hooks/use-mounted.cjs +18 -0
- package/dist/hooks/{use-mounted.js → use-mounted.mjs} +1 -1
- package/dist/hooks/use-mutate-observer.cjs +30 -0
- package/dist/hooks/{use-mutate-observer.js → use-mutate-observer.mjs} +3 -3
- package/dist/hooks/use-raf.cjs +28 -0
- package/dist/hooks/{use-raf.js → use-raf.mjs} +1 -1
- package/dist/hooks/use-reactive.cjs +32 -0
- package/dist/hooks/{use-reactive.js → use-reactive.mjs} +1 -1
- package/dist/hooks/use-refs.cjs +33 -0
- package/dist/hooks/{use-refs.js → use-refs.mjs} +1 -1
- package/dist/hooks/use-scroll-locker.cjs +99 -0
- package/dist/hooks/{use-scroll-locker.js → use-scroll-locker.mjs} +2 -2
- package/dist/hooks/use-scrollable.cjs +45 -0
- package/dist/hooks/{use-scrollable.js → use-scrollable.mjs} +1 -1
- package/dist/hooks/use-session-storage-state.cjs +9 -0
- package/dist/hooks/{use-session-storage-state.js → use-session-storage-state.mjs} +1 -1
- package/dist/hooks/use-storage-state.cjs +49 -0
- package/dist/hooks/{use-storage-state.js → use-storage-state.mjs} +1 -1
- package/dist/hooks/use-throttle-callback.cjs +85 -0
- package/dist/hooks/{use-throttle-callback.js → use-throttle-callback.mjs} +4 -4
- package/dist/hooks/use-timeout.cjs +70 -0
- package/dist/hooks/{use-timeout.js → use-timeout.mjs} +2 -2
- package/dist/hooks/use-timer.cjs +34 -0
- package/dist/hooks/{use-timer.js → use-timer.mjs} +1 -1
- package/dist/hooks/use-togglable.cjs +191 -0
- package/dist/hooks/{use-togglable.js → use-togglable.mjs} +2 -2
- package/dist/hooks/use-unmount.cjs +17 -0
- package/dist/hooks/use-update-effect.cjs +15 -0
- package/dist/hooks/{use-update-effect.js → use-update-effect.mjs} +2 -2
- package/dist/index.cjs +136 -0
- package/dist/index.mjs +65 -0
- package/dist/is/is-array.cjs +11 -0
- package/dist/is/is-dom-usable.cjs +12 -0
- package/dist/is/is-empty.cjs +27 -0
- package/dist/is/{is-empty.js → is-empty.mjs} +3 -3
- package/dist/is/is-function.cjs +11 -0
- package/dist/is/is-html-element.cjs +13 -0
- package/dist/is/is-html-input-element.cjs +13 -0
- package/dist/is/{is-html-input-element.js → is-html-input-element.mjs} +1 -1
- package/dist/is/is-mobile.cjs +15 -0
- package/dist/is/is-null.cjs +11 -0
- package/dist/is/is-number.cjs +7 -0
- package/dist/is/is-object.cjs +13 -0
- package/dist/is/is-overflow.cjs +16 -0
- package/dist/is/is-primitive.cjs +11 -0
- package/dist/is/is-refable.cjs +36 -0
- package/dist/is/is-set.cjs +11 -0
- package/dist/is/is-string.cjs +7 -0
- package/dist/is/is-style-element.cjs +11 -0
- package/dist/is/is-thenable.cjs +11 -0
- package/dist/is/is-undefined.cjs +11 -0
- package/dist/is/is-void.cjs +14 -0
- package/dist/is/{is-void.js → is-void.mjs} +2 -2
- package/dist/utils/chain.cjs +17 -0
- package/dist/utils/clamp.cjs +15 -0
- package/dist/utils/clone.cjs +19 -0
- package/dist/utils/{clone.js → clone.mjs} +2 -2
- package/dist/utils/clsx.cjs +34 -0
- package/dist/utils/{clsx.js → clsx.mjs} +4 -4
- package/dist/utils/debounce.cjs +34 -0
- package/dist/utils/{debounce.js → debounce.mjs} +2 -2
- package/dist/utils/effect.cjs +18 -0
- package/dist/utils/{effect.js → effect.mjs} +1 -1
- package/dist/utils/exclude.cjs +20 -0
- package/dist/utils/range.cjs +18 -0
- package/dist/utils/replace.cjs +22 -0
- package/dist/utils/{replace.js → replace.mjs} +1 -1
- package/dist/utils/set-style.cjs +23 -0
- package/dist/utils/tagged-template-literals.cjs +34 -0
- package/dist/utils/throttle.cjs +34 -0
- package/dist/utils/{throttle.js → throttle.mjs} +2 -2
- package/dist/utils/to-array.cjs +27 -0
- package/dist/utils/{to-array.js → to-array.mjs} +1 -1
- package/dist/utils/to-form-data.cjs +29 -0
- package/dist/utils/{to-form-data.js → to-form-data.mjs} +1 -1
- package/dist/utils/to-function.cjs +15 -0
- package/dist/utils/{to-function.js → to-function.mjs} +1 -1
- package/dist/utils/toggle.cjs +32 -0
- package/dist/utils/{toggle.js → toggle.mjs} +1 -1
- package/dist/utils/unique.cjs +19 -0
- package/dist/utils/waitable.cjs +99 -0
- package/dist/utils/{waitable.js → waitable.mjs} +1 -1
- package/package.json +10 -4
- package/dist/dom/index.js +0 -2
- package/dist/index.js +0 -65
- /package/dist/dom/{contains.js → contains.mjs} +0 -0
- /package/dist/dom/{scroll-to.js → scroll-to.mjs} +0 -0
- /package/dist/hooks/{use-boolean.js → use-boolean.mjs} +0 -0
- /package/dist/hooks/{use-event.js → use-event.mjs} +0 -0
- /package/dist/hooks/{use-force-update.js → use-force-update.mjs} +0 -0
- /package/dist/hooks/{use-identity.js → use-identity.mjs} +0 -0
- /package/dist/hooks/{use-image-loader.js → use-image-loader.mjs} +0 -0
- /package/dist/hooks/{use-memorable.js → use-memorable.mjs} +0 -0
- /package/dist/hooks/{use-unmount.js → use-unmount.mjs} +0 -0
- /package/dist/is/{is-array.js → is-array.mjs} +0 -0
- /package/dist/is/{is-dom-usable.js → is-dom-usable.mjs} +0 -0
- /package/dist/is/{is-function.js → is-function.mjs} +0 -0
- /package/dist/is/{is-html-element.js → is-html-element.mjs} +0 -0
- /package/dist/is/{is-mobile.js → is-mobile.mjs} +0 -0
- /package/dist/is/{is-null.js → is-null.mjs} +0 -0
- /package/dist/is/{is-number.js → is-number.mjs} +0 -0
- /package/dist/is/{is-object.js → is-object.mjs} +0 -0
- /package/dist/is/{is-overflow.js → is-overflow.mjs} +0 -0
- /package/dist/is/{is-primitive.js → is-primitive.mjs} +0 -0
- /package/dist/is/{is-refable.js → is-refable.mjs} +0 -0
- /package/dist/is/{is-set.js → is-set.mjs} +0 -0
- /package/dist/is/{is-string.js → is-string.mjs} +0 -0
- /package/dist/is/{is-style-element.js → is-style-element.mjs} +0 -0
- /package/dist/is/{is-thenable.js → is-thenable.mjs} +0 -0
- /package/dist/is/{is-undefined.js → is-undefined.mjs} +0 -0
- /package/dist/utils/{chain.js → chain.mjs} +0 -0
- /package/dist/utils/{clamp.js → clamp.mjs} +0 -0
- /package/dist/utils/{exclude.js → exclude.mjs} +0 -0
- /package/dist/utils/{range.js → range.mjs} +0 -0
- /package/dist/utils/{set-style.js → set-style.mjs} +0 -0
- /package/dist/utils/{tagged-template-literals.js → tagged-template-literals.mjs} +0 -0
- /package/dist/utils/{unique.js → unique.mjs} +0 -0
package/dist/dom/clipboard.d.ts
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var contains = function contains(root, node) {
|
|
4
|
+
if (!root) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
// Use native if support
|
|
8
|
+
if (root.contains) {
|
|
9
|
+
return root.contains(node !== null && node !== void 0 ? node : null);
|
|
10
|
+
}
|
|
11
|
+
// `document.contains` not support with IE11
|
|
12
|
+
var _node = node;
|
|
13
|
+
while (_node) {
|
|
14
|
+
if (_node === root) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
_node = _node.parentNode;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.contains = contains;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
|
|
4
|
+
var _createClass = require('@babel/runtime/helpers/createClass');
|
|
5
|
+
var _classPrivateFieldInitSpec = require('@babel/runtime/helpers/classPrivateFieldInitSpec');
|
|
6
|
+
var _classPrivateFieldGet = require('@babel/runtime/helpers/classPrivateFieldGet2');
|
|
7
|
+
|
|
8
|
+
var _scrolled = /*#__PURE__*/new WeakMap();
|
|
9
|
+
var Scroller = /*#__PURE__*/function () {
|
|
10
|
+
function Scroller() {
|
|
11
|
+
var _scroller$_;
|
|
12
|
+
_classCallCheck(this, Scroller);
|
|
13
|
+
_classPrivateFieldInitSpec(this, _scrolled, new Map());
|
|
14
|
+
return (_scroller$_ = _scroller._) !== null && _scroller$_ !== void 0 ? _scroller$_ : _scroller._ = this;
|
|
15
|
+
}
|
|
16
|
+
return _createClass(Scroller, [{
|
|
17
|
+
key: "scrolled",
|
|
18
|
+
get: function get() {
|
|
19
|
+
return _classPrivateFieldGet(_scrolled, this);
|
|
20
|
+
}
|
|
21
|
+
}, {
|
|
22
|
+
key: "currentAt",
|
|
23
|
+
value: function currentAt(orientation) {
|
|
24
|
+
return orientation === "vertical" ? "scrollTop" : "scrollLeft";
|
|
25
|
+
}
|
|
26
|
+
}]);
|
|
27
|
+
}();
|
|
28
|
+
/**
|
|
29
|
+
* @description
|
|
30
|
+
* scroll to for wrapper element
|
|
31
|
+
*/
|
|
32
|
+
// singleton mode
|
|
33
|
+
var _scroller = {
|
|
34
|
+
_: null
|
|
35
|
+
};
|
|
36
|
+
var _scrollTo = function scrollTo(target, to) {
|
|
37
|
+
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
38
|
+
duration: 0,
|
|
39
|
+
orientation: "vertical"
|
|
40
|
+
},
|
|
41
|
+
_ref$duration = _ref.duration,
|
|
42
|
+
duration = _ref$duration === void 0 ? 0 : _ref$duration,
|
|
43
|
+
_ref$orientation = _ref.orientation,
|
|
44
|
+
orientation = _ref$orientation === void 0 ? "vertical" : _ref$orientation;
|
|
45
|
+
var scroller = new Scroller();
|
|
46
|
+
var scrolled = scroller.scrolled.get(target);
|
|
47
|
+
var currentAtProperty = scroller.currentAt(orientation);
|
|
48
|
+
if (scrolled) {
|
|
49
|
+
cancelAnimationFrame(scrolled);
|
|
50
|
+
scroller.scrolled["delete"](target);
|
|
51
|
+
}
|
|
52
|
+
// if duration <= 0, jump immediately
|
|
53
|
+
if (duration <= 0) {
|
|
54
|
+
scroller.scrolled.set(target, requestAnimationFrame(function () {
|
|
55
|
+
target[currentAtProperty] = to;
|
|
56
|
+
}));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
// animate
|
|
60
|
+
var currentAt = target[currentAtProperty];
|
|
61
|
+
var difference = to - currentAt;
|
|
62
|
+
var step = difference / duration * 10;
|
|
63
|
+
scroller.scrolled.set(target, requestAnimationFrame(function () {
|
|
64
|
+
target[currentAtProperty] = currentAt + step;
|
|
65
|
+
// over end, stop any animation
|
|
66
|
+
if (target[currentAtProperty] === to) return;
|
|
67
|
+
_scrollTo(target, to, {
|
|
68
|
+
duration: duration - 10,
|
|
69
|
+
orientation: orientation
|
|
70
|
+
});
|
|
71
|
+
}));
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
exports.scrollTo = _scrollTo;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @author murukal
|
|
8
|
+
*
|
|
9
|
+
* @description
|
|
10
|
+
* boolean state, in relax, we already create some api to easy use
|
|
11
|
+
*/
|
|
12
|
+
var useBoolean = function useBoolean(initialState) {
|
|
13
|
+
var _useState = react.useState(initialState !== null && initialState !== void 0 ? initialState : false),
|
|
14
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
15
|
+
isOn = _useState2[0],
|
|
16
|
+
setIsOn = _useState2[1];
|
|
17
|
+
var turnOn = react.useCallback(function () {
|
|
18
|
+
return setIsOn(true);
|
|
19
|
+
}, []);
|
|
20
|
+
var turnOff = react.useCallback(function () {
|
|
21
|
+
return setIsOn(false);
|
|
22
|
+
}, []);
|
|
23
|
+
var toggle = react.useCallback(function () {
|
|
24
|
+
return setIsOn(function (_isOn) {
|
|
25
|
+
return !_isOn;
|
|
26
|
+
});
|
|
27
|
+
}, []);
|
|
28
|
+
return [isOn, {
|
|
29
|
+
turnOn: turnOn,
|
|
30
|
+
turnOff: turnOff,
|
|
31
|
+
toggle: toggle,
|
|
32
|
+
setBoolean: setIsOn
|
|
33
|
+
}];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.useBoolean = useBoolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var useEvent = require('./use-event.cjs');
|
|
5
|
+
var toArray = require('../utils/to-array.cjs');
|
|
6
|
+
var contains = require('../dom/contains.cjs');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @description
|
|
10
|
+
* click away
|
|
11
|
+
*/
|
|
12
|
+
var useClickAway = function useClickAway(onClickAway, target) {
|
|
13
|
+
var clickAway = useEvent.useEvent(function (event) {
|
|
14
|
+
var targets = toArray.toArray(target);
|
|
15
|
+
var isContained = targets.some(function (_target) {
|
|
16
|
+
return _target && contains.contains(_target.current, event.target);
|
|
17
|
+
});
|
|
18
|
+
if (isContained) return;
|
|
19
|
+
onClickAway(event);
|
|
20
|
+
});
|
|
21
|
+
react.useEffect(function () {
|
|
22
|
+
document.addEventListener("click", clickAway);
|
|
23
|
+
return function () {
|
|
24
|
+
document.removeEventListener("click", clickAway);
|
|
25
|
+
};
|
|
26
|
+
}, []);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.useClickAway = useClickAway;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
|
-
import { useEvent } from './use-event.
|
|
3
|
-
import { toArray } from '../utils/to-array.
|
|
4
|
-
import { contains } from '../dom/contains.
|
|
2
|
+
import { useEvent } from './use-event.mjs';
|
|
3
|
+
import { toArray } from '../utils/to-array.mjs';
|
|
4
|
+
import { contains } from '../dom/contains.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @description
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var isUndefined = require('../is/is-undefined.cjs');
|
|
6
|
+
var useUpdateEffect = require('./use-update-effect.cjs');
|
|
7
|
+
var isFunction = require('../is/is-function.cjs');
|
|
8
|
+
|
|
9
|
+
function useControlledState(controlledState) {
|
|
10
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
11
|
+
defaultState = _ref.defaultState;
|
|
12
|
+
// initialize state
|
|
13
|
+
var _useState = react.useState(function () {
|
|
14
|
+
// default use controlled state
|
|
15
|
+
if (!isUndefined.isUndefined(controlledState)) {
|
|
16
|
+
return controlledState;
|
|
17
|
+
}
|
|
18
|
+
// not controlled use default state
|
|
19
|
+
if (isFunction.isFunction(defaultState)) {
|
|
20
|
+
return defaultState();
|
|
21
|
+
}
|
|
22
|
+
return defaultState !== null && defaultState !== void 0 ? defaultState : controlledState;
|
|
23
|
+
}),
|
|
24
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
25
|
+
_state = _useState2[0],
|
|
26
|
+
_setState = _useState2[1];
|
|
27
|
+
// sync value back to `undefined` when it from control to un-control
|
|
28
|
+
useUpdateEffect.useUpdateEffect(function () {
|
|
29
|
+
if (!isUndefined.isUndefined(controlledState)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
_setState(defaultState !== null && defaultState !== void 0 ? defaultState : controlledState);
|
|
33
|
+
}, [controlledState]);
|
|
34
|
+
// use controlled
|
|
35
|
+
var state = isUndefined.isUndefined(controlledState) ? _state : controlledState;
|
|
36
|
+
return [state, _setState];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.useControlledState = useControlledState;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
2
|
import { useState } from 'react';
|
|
3
|
-
import { isUndefined } from '../is/is-undefined.
|
|
4
|
-
import { useUpdateEffect } from './use-update-effect.
|
|
5
|
-
import { isFunction } from '../is/is-function.
|
|
3
|
+
import { isUndefined } from '../is/is-undefined.mjs';
|
|
4
|
+
import { useUpdateEffect } from './use-update-effect.mjs';
|
|
5
|
+
import { isFunction } from '../is/is-function.mjs';
|
|
6
6
|
|
|
7
7
|
function useControlledState(controlledState) {
|
|
8
8
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var clamp = require('../utils/clamp.cjs');
|
|
6
|
+
var useDefault = require('./use-default.cjs');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @author murukal
|
|
10
|
+
*
|
|
11
|
+
* @description
|
|
12
|
+
* a number counter with some useful apis
|
|
13
|
+
*/
|
|
14
|
+
var useCounter = function useCounter() {
|
|
15
|
+
var initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
16
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
17
|
+
_ref$max = _ref.max,
|
|
18
|
+
max = _ref$max === void 0 ? Infinity : _ref$max,
|
|
19
|
+
_ref$min = _ref.min,
|
|
20
|
+
min = _ref$min === void 0 ? -Infinity : _ref$min;
|
|
21
|
+
// memorized first time prop value
|
|
22
|
+
var defaultState = useDefault.useDefault(initialState);
|
|
23
|
+
var _useState = react.useState(defaultState),
|
|
24
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
25
|
+
_count = _useState2[0],
|
|
26
|
+
_setCount = _useState2[1];
|
|
27
|
+
var add = react.useCallback(function () {
|
|
28
|
+
var step = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
29
|
+
_setCount(function (prev) {
|
|
30
|
+
return Math.min(max, prev + step);
|
|
31
|
+
});
|
|
32
|
+
}, [max]);
|
|
33
|
+
var subtract = react.useCallback(function () {
|
|
34
|
+
var step = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
35
|
+
_setCount(function (prev) {
|
|
36
|
+
return Math.max(min, prev - step);
|
|
37
|
+
});
|
|
38
|
+
}, [min]);
|
|
39
|
+
var first = react.useCallback(function () {
|
|
40
|
+
_setCount(min);
|
|
41
|
+
}, [min]);
|
|
42
|
+
var last = react.useCallback(function () {
|
|
43
|
+
_setCount(max);
|
|
44
|
+
}, [max]);
|
|
45
|
+
var reset = react.useCallback(function () {
|
|
46
|
+
_setCount(defaultState);
|
|
47
|
+
}, []);
|
|
48
|
+
var count = react.useMemo(function () {
|
|
49
|
+
return clamp.clamp(_count, min, max);
|
|
50
|
+
}, [_count, min, max]);
|
|
51
|
+
return [count, {
|
|
52
|
+
add: add,
|
|
53
|
+
subtract: subtract,
|
|
54
|
+
first: first,
|
|
55
|
+
last: last,
|
|
56
|
+
reset: reset,
|
|
57
|
+
setCount: _setCount
|
|
58
|
+
}];
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
exports.useCounter = useCounter;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
2
|
import { useState, useCallback, useMemo } from 'react';
|
|
3
|
-
import { clamp } from '../utils/clamp.
|
|
4
|
-
import { useDefault } from './use-default.
|
|
3
|
+
import { clamp } from '../utils/clamp.mjs';
|
|
4
|
+
import { useDefault } from './use-default.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @author murukal
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var debounce = require('../utils/debounce.cjs');
|
|
5
|
+
var useEvent = require('./use-event.cjs');
|
|
6
|
+
var isFunction = require('../is/is-function.cjs');
|
|
7
|
+
var useDefault = require('./use-default.cjs');
|
|
8
|
+
|
|
9
|
+
var useDebouncer = function useDebouncer(debouncer) {
|
|
10
|
+
var _debouncer = react.useMemo(function () {
|
|
11
|
+
return isFunction.isFunction(debouncer) ? {
|
|
12
|
+
callback: debouncer,
|
|
13
|
+
pipe: null
|
|
14
|
+
} : debouncer;
|
|
15
|
+
}, [debouncer]);
|
|
16
|
+
return {
|
|
17
|
+
callback: useEvent.useEvent(function () {
|
|
18
|
+
return _debouncer.callback.apply(_debouncer, arguments);
|
|
19
|
+
}),
|
|
20
|
+
pipe: useEvent.useEvent(function () {
|
|
21
|
+
var _debouncer$pipe, _debouncer$pipe2;
|
|
22
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
23
|
+
args[_key] = arguments[_key];
|
|
24
|
+
}
|
|
25
|
+
return (_debouncer$pipe = (_debouncer$pipe2 = _debouncer.pipe) === null || _debouncer$pipe2 === void 0 ? void 0 : _debouncer$pipe2.call.apply(_debouncer$pipe2, [_debouncer].concat(args))) !== null && _debouncer$pipe !== void 0 ? _debouncer$pipe : args;
|
|
26
|
+
})
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* @author murukal
|
|
31
|
+
*
|
|
32
|
+
* @description
|
|
33
|
+
* debounce callback
|
|
34
|
+
*
|
|
35
|
+
* @param callback
|
|
36
|
+
* @param wait number
|
|
37
|
+
* @description
|
|
38
|
+
* The delay time (in milliseconds) until the debounce function is called.
|
|
39
|
+
* default 1000
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* 1000
|
|
43
|
+
*/
|
|
44
|
+
var useDebounceCallback = function useDebounceCallback(debouncer) {
|
|
45
|
+
var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
|
|
46
|
+
var debounced = react.useRef(null);
|
|
47
|
+
var _useDebouncer = useDebouncer(debouncer),
|
|
48
|
+
callback = _useDebouncer.callback,
|
|
49
|
+
pipe = _useDebouncer.pipe;
|
|
50
|
+
react.useEffect(function () {
|
|
51
|
+
var _debounced = debounce.debounce({
|
|
52
|
+
callback: callback,
|
|
53
|
+
pipe: pipe
|
|
54
|
+
}, wait);
|
|
55
|
+
debounced.current = _debounced;
|
|
56
|
+
// dispose
|
|
57
|
+
return function () {
|
|
58
|
+
_debounced.abort();
|
|
59
|
+
debounced.current = null;
|
|
60
|
+
};
|
|
61
|
+
}, [wait]);
|
|
62
|
+
return useDefault.useDefault(function () {
|
|
63
|
+
return {
|
|
64
|
+
next: function next() {
|
|
65
|
+
var _debounced$current;
|
|
66
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
67
|
+
args[_key2] = arguments[_key2];
|
|
68
|
+
}
|
|
69
|
+
return (_debounced$current = debounced.current) === null || _debounced$current === void 0 ? void 0 : _debounced$current.next.apply(_debounced$current, args);
|
|
70
|
+
},
|
|
71
|
+
flush: function flush() {
|
|
72
|
+
var _debounced$current2;
|
|
73
|
+
return (_debounced$current2 = debounced.current) === null || _debounced$current2 === void 0 ? void 0 : _debounced$current2.flush();
|
|
74
|
+
},
|
|
75
|
+
abort: function abort() {
|
|
76
|
+
var _debounced$current3;
|
|
77
|
+
return (_debounced$current3 = debounced.current) === null || _debounced$current3 === void 0 ? void 0 : _debounced$current3.abort();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
exports.useDebounceCallback = useDebounceCallback;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useRef, useEffect, useMemo } from 'react';
|
|
2
|
-
import { debounce } from '../utils/debounce.
|
|
3
|
-
import { useEvent } from './use-event.
|
|
4
|
-
import { isFunction } from '../is/is-function.
|
|
5
|
-
import { useDefault } from './use-default.
|
|
2
|
+
import { debounce } from '../utils/debounce.mjs';
|
|
3
|
+
import { useEvent } from './use-event.mjs';
|
|
4
|
+
import { isFunction } from '../is/is-function.mjs';
|
|
5
|
+
import { useDefault } from './use-default.mjs';
|
|
6
6
|
|
|
7
7
|
var useDebouncer = function useDebouncer(debouncer) {
|
|
8
8
|
var _debouncer = useMemo(function () {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var toFunction = require('../utils/to-function.cjs');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @author murukal
|
|
8
|
+
*
|
|
9
|
+
* @description
|
|
10
|
+
* state always be same after first render
|
|
11
|
+
*/
|
|
12
|
+
var useDefault = function useDefault(initialState) {
|
|
13
|
+
return react.useMemo(toFunction.toFunction(initialState), []);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.useDefault = useDefault;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var isDomUsable = require('../is/is-dom-usable.cjs');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @description
|
|
9
|
+
* devicePixelRatio
|
|
10
|
+
* in different device, ratio
|
|
11
|
+
*/
|
|
12
|
+
var useDevicePixelRatio = function useDevicePixelRatio() {
|
|
13
|
+
var _useState = react.useState(function () {
|
|
14
|
+
if (!isDomUsable.isDomUsable()) return 1;
|
|
15
|
+
return window.devicePixelRatio;
|
|
16
|
+
}),
|
|
17
|
+
_useState2 = _slicedToArray(_useState, 1),
|
|
18
|
+
devicePixelRatio = _useState2[0];
|
|
19
|
+
return devicePixelRatio;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.useDevicePixelRatio = useDevicePixelRatio;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
var useEvent = function useEvent(callback) {
|
|
6
|
+
var ref = react.useRef(callback);
|
|
7
|
+
react.useEffect(function () {
|
|
8
|
+
ref.current = callback;
|
|
9
|
+
});
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
return react.useCallback(function () {
|
|
12
|
+
return ref.current.apply(ref, arguments);
|
|
13
|
+
}, []);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.useEvent = useEvent;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var useBoolean = require('./use-boolean.cjs');
|
|
6
|
+
var chain = require('../utils/chain.cjs');
|
|
7
|
+
|
|
8
|
+
var useFocus = function useFocus(props) {
|
|
9
|
+
var _useBoolean = useBoolean.useBoolean(false),
|
|
10
|
+
_useBoolean2 = _slicedToArray(_useBoolean, 2),
|
|
11
|
+
isFocused = _useBoolean2[0],
|
|
12
|
+
_useBoolean2$ = _useBoolean2[1],
|
|
13
|
+
turnOn = _useBoolean2$.turnOn,
|
|
14
|
+
turnOff = _useBoolean2$.turnOff;
|
|
15
|
+
var onFocus = react.useCallback(function (e) {
|
|
16
|
+
chain.chain(props === null || props === void 0 ? void 0 : props.onFocus, turnOn, function () {
|
|
17
|
+
var _props$onFocusChange;
|
|
18
|
+
return props === null || props === void 0 || (_props$onFocusChange = props.onFocusChange) === null || _props$onFocusChange === void 0 ? void 0 : _props$onFocusChange.call(props, true);
|
|
19
|
+
})(e);
|
|
20
|
+
}, [props === null || props === void 0 ? void 0 : props.onFocus, props === null || props === void 0 ? void 0 : props.onFocusChange]);
|
|
21
|
+
var onBlur = react.useCallback(function (e) {
|
|
22
|
+
chain.chain(props === null || props === void 0 ? void 0 : props.onBlur, turnOff, function () {
|
|
23
|
+
var _props$onFocusChange2;
|
|
24
|
+
return props === null || props === void 0 || (_props$onFocusChange2 = props.onFocusChange) === null || _props$onFocusChange2 === void 0 ? void 0 : _props$onFocusChange2.call(props, false);
|
|
25
|
+
})(e);
|
|
26
|
+
}, [props === null || props === void 0 ? void 0 : props.onBlur, props === null || props === void 0 ? void 0 : props.onFocusChange]);
|
|
27
|
+
return [isFocused, {
|
|
28
|
+
onFocus: onFocus,
|
|
29
|
+
onBlur: onBlur
|
|
30
|
+
}];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
exports.useFocus = useFocus;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
2
|
import { useCallback } from 'react';
|
|
3
|
-
import { useBoolean } from './use-boolean.
|
|
4
|
-
import { chain } from '../utils/chain.
|
|
3
|
+
import { useBoolean } from './use-boolean.mjs';
|
|
4
|
+
import { chain } from '../utils/chain.mjs';
|
|
5
5
|
|
|
6
6
|
var useFocus = function useFocus(props) {
|
|
7
7
|
var _useBoolean = useBoolean(false),
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @description
|
|
8
|
+
* force update
|
|
9
|
+
*/
|
|
10
|
+
var useForceUpdate = function useForceUpdate() {
|
|
11
|
+
var _useState = react.useState(1),
|
|
12
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
13
|
+
times = _useState2[0],
|
|
14
|
+
setTimes = _useState2[1];
|
|
15
|
+
var forceUpdate = react.useCallback(function () {
|
|
16
|
+
setTimes(function (prev) {
|
|
17
|
+
return prev + 1;
|
|
18
|
+
});
|
|
19
|
+
}, []);
|
|
20
|
+
return [times, forceUpdate];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
exports.useForceUpdate = useForceUpdate;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
|
+
var useBoolean = require('./use-boolean.cjs');
|
|
5
|
+
var chain = require('../utils/chain.cjs');
|
|
6
|
+
var useEvent = require('./use-event.cjs');
|
|
7
|
+
|
|
8
|
+
var useHover = function useHover(props) {
|
|
9
|
+
var _useBoolean = useBoolean.useBoolean(false),
|
|
10
|
+
_useBoolean2 = _slicedToArray(_useBoolean, 2),
|
|
11
|
+
isHovered = _useBoolean2[0],
|
|
12
|
+
_useBoolean2$ = _useBoolean2[1],
|
|
13
|
+
turnOn = _useBoolean2$.turnOn,
|
|
14
|
+
turnOff = _useBoolean2$.turnOff;
|
|
15
|
+
var onPointerEnter = useEvent.useEvent(function (event) {
|
|
16
|
+
chain.chain(props === null || props === void 0 ? void 0 : props.onEnter, turnOn)(event);
|
|
17
|
+
});
|
|
18
|
+
var onPointerLeave = useEvent.useEvent(function (event) {
|
|
19
|
+
chain.chain(props === null || props === void 0 ? void 0 : props.onLeave, turnOff)(event);
|
|
20
|
+
});
|
|
21
|
+
return [isHovered, {
|
|
22
|
+
onPointerEnter: onPointerEnter,
|
|
23
|
+
onPointerLeave: onPointerLeave
|
|
24
|
+
}];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
exports.useHover = useHover;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
|
-
import { useBoolean } from './use-boolean.
|
|
3
|
-
import { chain } from '../utils/chain.
|
|
4
|
-
import { useEvent } from './use-event.
|
|
2
|
+
import { useBoolean } from './use-boolean.mjs';
|
|
3
|
+
import { chain } from '../utils/chain.mjs';
|
|
4
|
+
import { useEvent } from './use-event.mjs';
|
|
5
5
|
|
|
6
6
|
var useHover = function useHover(props) {
|
|
7
7
|
var _useBoolean = useBoolean(false),
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* extends from react `useId`
|
|
8
|
+
*/
|
|
9
|
+
var useIdentity = function useIdentity() {
|
|
10
|
+
var signal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
11
|
+
var id = react.useId();
|
|
12
|
+
var count = react.useRef(0);
|
|
13
|
+
var unique = react.useCallback(function () {
|
|
14
|
+
if (!signal) {
|
|
15
|
+
return "".concat(id).concat(count.current++);
|
|
16
|
+
}
|
|
17
|
+
return "".concat(id).concat(signal, ":").concat(count.current++);
|
|
18
|
+
}, []);
|
|
19
|
+
return [id, unique];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.useIdentity = useIdentity;
|