@aiszlab/relax 1.2.41 → 1.2.43

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.
Files changed (103) hide show
  1. package/dist/__test__/hooks/use-boolean.test.d.ts +4 -0
  2. package/dist/__test__/hooks/use-mount.test.d.ts +4 -0
  3. package/dist/__test__/hooks/use-mounted.test.d.ts +4 -0
  4. package/dist/__test__/hooks/use-timeout.test.d.ts +4 -0
  5. package/dist/__test__/utils/to-form-data.test.d.ts +1 -0
  6. package/dist/_virtual/_rollupPluginBabelHelpers.js +74 -92
  7. package/dist/hooks/use-counter.js +1 -1
  8. package/dist/hooks/use-debounce-callback.js +1 -1
  9. package/dist/hooks/use-focus.js +1 -1
  10. package/dist/hooks/use-hover.js +1 -1
  11. package/dist/hooks/use-mount.js +1 -1
  12. package/dist/hooks/use-mounted.js +1 -1
  13. package/dist/hooks/use-throttle-callback.js +1 -1
  14. package/dist/hooks/use-timeout.js +30 -19
  15. package/dist/hooks/use-update-effect.js +1 -1
  16. package/dist/index.js +8 -7
  17. package/dist/{hooks → src/hooks}/use-boolean.d.ts +1 -1
  18. package/dist/src/hooks/use-event.d.ts +2 -0
  19. package/dist/{hooks → src/hooks}/use-timeout.d.ts +1 -1
  20. package/dist/{index.d.ts → src/index.d.ts} +1 -0
  21. package/dist/{utils/chain/index.d.ts → src/utils/chain.d.ts} +1 -1
  22. package/dist/{utils/debounce/index.d.ts → src/utils/debounce.d.ts} +1 -1
  23. package/dist/{utils/effect/index.d.ts → src/utils/effect.d.ts} +1 -1
  24. package/dist/{utils/throttle/index.d.ts → src/utils/throttle.d.ts} +2 -2
  25. package/dist/src/utils/to-form-data.d.ts +5 -0
  26. package/dist/utils/{debounce/index.js → debounce.js} +2 -2
  27. package/dist/utils/{effect/index.js → effect.js} +1 -1
  28. package/dist/utils/{throttle/index.js → throttle.js} +2 -2
  29. package/dist/utils/{to-array/index.js → to-array.js} +2 -2
  30. package/dist/utils/to-form-data.js +27 -0
  31. package/dist/utils/{waitable/index.js → waitable.js} +2 -2
  32. package/package.json +7 -3
  33. package/dist/hooks/use-event.d.ts +0 -2
  34. package/dist/utils/to-form-data/index.d.ts +0 -5
  35. /package/dist/{is/is-thenable/index.test.d.ts → __test__/is/is-thenable.test.d.ts} +0 -0
  36. /package/dist/{utils/chain/index.test.d.ts → __test__/utils/chain.test.d.ts} +0 -0
  37. /package/dist/{utils/clamp/index.test.d.ts → __test__/utils/clamp.test.d.ts} +0 -0
  38. /package/dist/{utils/clone/index.test.d.ts → __test__/utils/clone.test.d.ts} +0 -0
  39. /package/dist/{utils/debounce/index.test.d.ts → __test__/utils/debounce.test.d.ts} +0 -0
  40. /package/dist/{utils/effect/index.test.d.ts → __test__/utils/effect.test.d.ts} +0 -0
  41. /package/dist/{utils/exclude/index.test.d.ts → __test__/utils/exclude.test.d.ts} +0 -0
  42. /package/dist/{utils/throttle/index.test.d.ts → __test__/utils/throttle.test.d.ts} +0 -0
  43. /package/dist/{utils/to-array/index.test.d.ts → __test__/utils/to-array.test.d.ts} +0 -0
  44. /package/dist/is/{is-thenable/index.js → is-thenable.js} +0 -0
  45. /package/dist/{dom → src/dom}/contains.d.ts +0 -0
  46. /package/dist/{dom → src/dom}/index.d.ts +0 -0
  47. /package/dist/{dom → src/dom}/scroll-to.d.ts +0 -0
  48. /package/dist/{hooks → src/hooks}/use-controlled-state.d.ts +0 -0
  49. /package/dist/{hooks → src/hooks}/use-counter.d.ts +0 -0
  50. /package/dist/{hooks → src/hooks}/use-debounce-callback.d.ts +0 -0
  51. /package/dist/{hooks → src/hooks}/use-default.d.ts +0 -0
  52. /package/dist/{hooks → src/hooks}/use-focus.d.ts +0 -0
  53. /package/dist/{hooks → src/hooks}/use-force-update.d.ts +0 -0
  54. /package/dist/{hooks → src/hooks}/use-hover.d.ts +0 -0
  55. /package/dist/{hooks → src/hooks}/use-image-loader.d.ts +0 -0
  56. /package/dist/{hooks → src/hooks}/use-media-query.d.ts +0 -0
  57. /package/dist/{hooks → src/hooks}/use-memorable.d.ts +0 -0
  58. /package/dist/{hooks → src/hooks}/use-mount.d.ts +0 -0
  59. /package/dist/{hooks → src/hooks}/use-mounted.d.ts +0 -0
  60. /package/dist/{hooks → src/hooks}/use-reactive.d.ts +0 -0
  61. /package/dist/{hooks → src/hooks}/use-refs.d.ts +0 -0
  62. /package/dist/{hooks → src/hooks}/use-scroll-locker.d.ts +0 -0
  63. /package/dist/{hooks → src/hooks}/use-scrollable.d.ts +0 -0
  64. /package/dist/{hooks → src/hooks}/use-throttle-callback.d.ts +0 -0
  65. /package/dist/{hooks → src/hooks}/use-toggleable.d.ts +0 -0
  66. /package/dist/{hooks → src/hooks}/use-update-effect.d.ts +0 -0
  67. /package/dist/{is → src/is}/is-array.d.ts +0 -0
  68. /package/dist/{is → src/is}/is-complex.d.ts +0 -0
  69. /package/dist/{is → src/is}/is-dom-usable.d.ts +0 -0
  70. /package/dist/{is → src/is}/is-empty.d.ts +0 -0
  71. /package/dist/{is → src/is}/is-function.d.ts +0 -0
  72. /package/dist/{is → src/is}/is-mobile.d.ts +0 -0
  73. /package/dist/{is → src/is}/is-null.d.ts +0 -0
  74. /package/dist/{is → src/is}/is-overflow.d.ts +0 -0
  75. /package/dist/{is → src/is}/is-pointer-usable.d.ts +0 -0
  76. /package/dist/{is → src/is}/is-primitive.d.ts +0 -0
  77. /package/dist/{is → src/is}/is-refable.d.ts +0 -0
  78. /package/dist/{is → src/is}/is-state-getter.d.ts +0 -0
  79. /package/dist/{is → src/is}/is-style-element.d.ts +0 -0
  80. /package/dist/{is/is-thenable/index.d.ts → src/is/is-thenable.d.ts} +0 -0
  81. /package/dist/{is → src/is}/is-undefined.d.ts +0 -0
  82. /package/dist/{is → src/is}/is-void.d.ts +0 -0
  83. /package/dist/{types → src/types}/first.d.ts +0 -0
  84. /package/dist/{types → src/types}/index.d.ts +0 -0
  85. /package/dist/{types → src/types}/last.d.ts +0 -0
  86. /package/dist/{types → src/types}/nullable.d.ts +0 -0
  87. /package/dist/{types → src/types}/partialable.d.ts +0 -0
  88. /package/dist/{types → src/types}/required-in.d.ts +0 -0
  89. /package/dist/{types → src/types}/state.d.ts +0 -0
  90. /package/dist/{types → src/types}/thenable-effect-callback.d.ts +0 -0
  91. /package/dist/{types → src/types}/voidable.d.ts +0 -0
  92. /package/dist/{utils/clamp/index.d.ts → src/utils/clamp.d.ts} +0 -0
  93. /package/dist/{utils/clone/index.d.ts → src/utils/clone.d.ts} +0 -0
  94. /package/dist/{utils/exclude/index.d.ts → src/utils/exclude.d.ts} +0 -0
  95. /package/dist/{utils → src/utils}/range.d.ts +0 -0
  96. /package/dist/{utils → src/utils}/set-style.d.ts +0 -0
  97. /package/dist/{utils/to-array/index.d.ts → src/utils/to-array.d.ts} +0 -0
  98. /package/dist/{utils → src/utils}/to-function.d.ts +0 -0
  99. /package/dist/{utils → src/utils}/unique.d.ts +0 -0
  100. /package/dist/{utils/waitable/index.d.ts → src/utils/waitable.d.ts} +0 -0
  101. /package/dist/utils/{chain/index.js → chain.js} +0 -0
  102. /package/dist/utils/{clamp/index.js → clamp.js} +0 -0
  103. /package/dist/utils/{exclude/index.js → exclude.js} +0 -0
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,13 +1,50 @@
1
+ function _arrayLikeToArray(r, a) {
2
+ (null == a || a > r.length) && (a = r.length);
3
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
4
+ return n;
5
+ }
6
+ function _arrayWithHoles(r) {
7
+ if (Array.isArray(r)) return r;
8
+ }
9
+ function _arrayWithoutHoles(r) {
10
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
11
+ }
1
12
  function _assertClassBrand(e, t, n) {
2
13
  if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
3
14
  throw new TypeError("Private element is not present on this object");
4
15
  }
16
+ function _checkPrivateRedeclaration(e, t) {
17
+ if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
18
+ }
19
+ function _classCallCheck(a, n) {
20
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
21
+ }
5
22
  function _classPrivateFieldGet2(s, a) {
6
23
  return s.get(_assertClassBrand(s, a));
7
24
  }
25
+ function _classPrivateFieldInitSpec(e, t, a) {
26
+ _checkPrivateRedeclaration(e, t), t.set(e, a);
27
+ }
8
28
  function _classPrivateFieldSet2(s, a, r) {
9
29
  return s.set(_assertClassBrand(s, a), r), r;
10
30
  }
31
+ function _classPrivateMethodInitSpec(e, a) {
32
+ _checkPrivateRedeclaration(e, a), a.add(e);
33
+ }
34
+ function _defineProperties(e, r) {
35
+ for (var t = 0; t < r.length; t++) {
36
+ var o = r[t];
37
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
38
+ }
39
+ }
40
+ function _createClass(e, r, t) {
41
+ return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
42
+ writable: !1
43
+ }), e;
44
+ }
45
+ function _iterableToArray(r) {
46
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
47
+ }
11
48
  function _iterableToArrayLimit(r, l) {
12
49
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
13
50
  if (null != t) {
@@ -32,6 +69,38 @@ function _iterableToArrayLimit(r, l) {
32
69
  return a;
33
70
  }
34
71
  }
72
+ function _nonIterableRest() {
73
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
74
+ }
75
+ function _nonIterableSpread() {
76
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
77
+ }
78
+ function _objectWithoutProperties(e, t) {
79
+ if (null == e) return {};
80
+ var o,
81
+ r,
82
+ i = _objectWithoutPropertiesLoose(e, t);
83
+ if (Object.getOwnPropertySymbols) {
84
+ var n = Object.getOwnPropertySymbols(e);
85
+ for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
86
+ }
87
+ return i;
88
+ }
89
+ function _objectWithoutPropertiesLoose(r, e) {
90
+ if (null == r) return {};
91
+ var t = {};
92
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
93
+ if (e.indexOf(n) >= 0) continue;
94
+ t[n] = r[n];
95
+ }
96
+ return t;
97
+ }
98
+ function _slicedToArray(r, e) {
99
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
100
+ }
101
+ function _toConsumableArray(r) {
102
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
103
+ }
35
104
  function _toPrimitive(t, r) {
36
105
  if ("object" != typeof t || !t) return t;
37
106
  var e = t[Symbol.toPrimitive];
@@ -55,99 +124,12 @@ function _typeof(o) {
55
124
  return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
56
125
  }, _typeof(o);
57
126
  }
58
- function _classCallCheck(instance, Constructor) {
59
- if (!(instance instanceof Constructor)) {
60
- throw new TypeError("Cannot call a class as a function");
61
- }
62
- }
63
- function _defineProperties(target, props) {
64
- for (var i = 0; i < props.length; i++) {
65
- var descriptor = props[i];
66
- descriptor.enumerable = descriptor.enumerable || false;
67
- descriptor.configurable = true;
68
- if ("value" in descriptor) descriptor.writable = true;
69
- Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
127
+ function _unsupportedIterableToArray(r, a) {
128
+ if (r) {
129
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
130
+ var t = {}.toString.call(r).slice(8, -1);
131
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
70
132
  }
71
133
  }
72
- function _createClass(Constructor, protoProps, staticProps) {
73
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
74
- Object.defineProperty(Constructor, "prototype", {
75
- writable: false
76
- });
77
- return Constructor;
78
- }
79
- function _objectWithoutPropertiesLoose(source, excluded) {
80
- if (source == null) return {};
81
- var target = {};
82
- for (var key in source) {
83
- if (Object.prototype.hasOwnProperty.call(source, key)) {
84
- if (excluded.indexOf(key) >= 0) continue;
85
- target[key] = source[key];
86
- }
87
- }
88
- return target;
89
- }
90
- function _objectWithoutProperties(source, excluded) {
91
- if (source == null) return {};
92
- var target = _objectWithoutPropertiesLoose(source, excluded);
93
- var key, i;
94
- if (Object.getOwnPropertySymbols) {
95
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
96
- for (i = 0; i < sourceSymbolKeys.length; i++) {
97
- key = sourceSymbolKeys[i];
98
- if (excluded.indexOf(key) >= 0) continue;
99
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
100
- target[key] = source[key];
101
- }
102
- }
103
- return target;
104
- }
105
- function _slicedToArray(arr, i) {
106
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
107
- }
108
- function _toConsumableArray(arr) {
109
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
110
- }
111
- function _arrayWithoutHoles(arr) {
112
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
113
- }
114
- function _arrayWithHoles(arr) {
115
- if (Array.isArray(arr)) return arr;
116
- }
117
- function _iterableToArray(iter) {
118
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
119
- }
120
- function _unsupportedIterableToArray(o, minLen) {
121
- if (!o) return;
122
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
123
- var n = Object.prototype.toString.call(o).slice(8, -1);
124
- if (n === "Object" && o.constructor) n = o.constructor.name;
125
- if (n === "Map" || n === "Set") return Array.from(o);
126
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
127
- }
128
- function _arrayLikeToArray(arr, len) {
129
- if (len == null || len > arr.length) len = arr.length;
130
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
131
- return arr2;
132
- }
133
- function _nonIterableSpread() {
134
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
135
- }
136
- function _nonIterableRest() {
137
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
138
- }
139
- function _checkPrivateRedeclaration(obj, privateCollection) {
140
- if (privateCollection.has(obj)) {
141
- throw new TypeError("Cannot initialize the same private elements twice on an object");
142
- }
143
- }
144
- function _classPrivateFieldInitSpec(obj, privateMap, value) {
145
- _checkPrivateRedeclaration(obj, privateMap);
146
- privateMap.set(obj, value);
147
- }
148
- function _classPrivateMethodInitSpec(obj, privateSet) {
149
- _checkPrivateRedeclaration(obj, privateSet);
150
- privateSet.add(obj);
151
- }
152
134
 
153
135
  export { _arrayLikeToArray as arrayLikeToArray, _arrayWithHoles as arrayWithHoles, _arrayWithoutHoles as arrayWithoutHoles, _assertClassBrand as assertClassBrand, _checkPrivateRedeclaration as checkPrivateRedeclaration, _classCallCheck as classCallCheck, _classPrivateFieldGet2 as classPrivateFieldGet2, _classPrivateFieldInitSpec as classPrivateFieldInitSpec, _classPrivateFieldSet2 as classPrivateFieldSet2, _classPrivateMethodInitSpec as classPrivateMethodInitSpec, _createClass as createClass, _iterableToArray as iterableToArray, _iterableToArrayLimit as iterableToArrayLimit, _nonIterableRest as nonIterableRest, _nonIterableSpread as nonIterableSpread, _objectWithoutProperties as objectWithoutProperties, _objectWithoutPropertiesLoose as objectWithoutPropertiesLoose, _slicedToArray as slicedToArray, _toConsumableArray as toConsumableArray, _toPrimitive as toPrimitive, _toPropertyKey as toPropertyKey, _typeof as typeof, _unsupportedIterableToArray as unsupportedIterableToArray };
@@ -1,6 +1,6 @@
1
1
  import { slicedToArray as _slicedToArray } from '../_virtual/_rollupPluginBabelHelpers.js';
2
2
  import { useState, useCallback, useMemo } from 'react';
3
- import { clamp } from '../utils/clamp/index.js';
3
+ import { clamp } from '../utils/clamp.js';
4
4
  import { useDefault } from './use-default.js';
5
5
 
6
6
  /**
@@ -1,5 +1,5 @@
1
1
  import { useRef, useEffect, useMemo } from 'react';
2
- import { debounce } from '../utils/debounce/index.js';
2
+ import { debounce } from '../utils/debounce.js';
3
3
  import { useEvent } from './use-event.js';
4
4
  import { isFunction } from '../is/is-function.js';
5
5
  import { useDefault } from './use-default.js';
@@ -1,7 +1,7 @@
1
1
  import { slicedToArray as _slicedToArray } from '../_virtual/_rollupPluginBabelHelpers.js';
2
2
  import { useCallback } from 'react';
3
3
  import { useBoolean } from './use-boolean.js';
4
- import { chain } from '../utils/chain/index.js';
4
+ import { chain } from '../utils/chain.js';
5
5
 
6
6
  var useFocus = function useFocus(props) {
7
7
  var _useBoolean = useBoolean(false),
@@ -1,7 +1,7 @@
1
1
  import { slicedToArray as _slicedToArray } from '../_virtual/_rollupPluginBabelHelpers.js';
2
2
  import { useCallback } from 'react';
3
3
  import { useBoolean } from './use-boolean.js';
4
- import { chain } from '../utils/chain/index.js';
4
+ import { chain } from '../utils/chain.js';
5
5
 
6
6
  var useHover = function useHover(props) {
7
7
  var _useBoolean = useBoolean(false),
@@ -1,5 +1,5 @@
1
1
  import { useLayoutEffect } from 'react';
2
- import { effect } from '../utils/effect/index.js';
2
+ import { effect } from '../utils/effect.js';
3
3
 
4
4
  /**
5
5
  * @author murukal
@@ -1,5 +1,5 @@
1
1
  import { useEffect } from 'react';
2
- import { effect } from '../utils/effect/index.js';
2
+ import { effect } from '../utils/effect.js';
3
3
 
4
4
  /**
5
5
  * @author murukal
@@ -1,5 +1,5 @@
1
1
  import { useRef, useEffect, useMemo } from 'react';
2
- import { throttle } from '../utils/throttle/index.js';
2
+ import { throttle } from '../utils/throttle.js';
3
3
  import { useEvent } from './use-event.js';
4
4
  import { isFunction } from '../is/is-function.js';
5
5
  import { useDefault } from './use-default.js';
@@ -1,6 +1,7 @@
1
1
  import { useRef, useEffect } from 'react';
2
- import { Observable, delay } from 'rxjs';
2
+ import { Observable, timer } from 'rxjs';
3
3
  import { useEvent } from './use-event.js';
4
+ import { useMounted } from './use-mounted.js';
4
5
 
5
6
  /**
6
7
  * @author murukal
@@ -8,45 +9,55 @@ import { useEvent } from './use-event.js';
8
9
  * @description
9
10
  * timeout effect
10
11
  */
11
- var useTimeout = function useTimeout(handler, wait) {
12
- var timer = useRef(null);
12
+ var useTimeout = function useTimeout(callback, wait) {
13
13
  var trigger = useRef(null);
14
+ var timed = useRef(null);
15
+ var callable = useEvent(callback);
16
+ useMounted(function () {
17
+ new Observable(function (_) {
18
+ trigger.current = _;
19
+ }).subscribe({
20
+ complete: function complete() {
21
+ return callable();
22
+ }
23
+ });
24
+ });
14
25
  // when user what to flush timeout handler
15
26
  // if trigger already registed, just complete trigger
16
27
  // not registed, call `handler` manaully
17
28
  var flush = useEvent(function () {
29
+ var _timed$current;
18
30
  if (trigger.current) {
19
- var _timer$current;
20
31
  trigger.current.complete();
21
- (_timer$current = timer.current) === null || _timer$current === void 0 || _timer$current.unsubscribe();
22
32
  } else {
23
- handler();
33
+ callback();
24
34
  }
35
+ (_timed$current = timed.current) === null || _timed$current === void 0 || _timed$current.unsubscribe();
36
+ timed.current = null;
25
37
  trigger.current = null;
26
- timer.current = null;
27
38
  });
28
39
  // cancel
29
40
  var cancel = useEvent(function () {
30
- var _trigger$current, _timer$current2;
41
+ var _trigger$current, _timed$current2;
31
42
  (_trigger$current = trigger.current) === null || _trigger$current === void 0 || _trigger$current.error();
32
- (_timer$current2 = timer.current) === null || _timer$current2 === void 0 || _timer$current2.unsubscribe();
33
- trigger.current = null;
34
- timer.current = null;
43
+ (_timed$current2 = timed.current) === null || _timed$current2 === void 0 || _timed$current2.unsubscribe();
44
+ timed.current = null;
35
45
  });
46
+ // add timer for `wait`
36
47
  useEffect(function () {
37
48
  // if 0, always mean not need to set timeout
38
49
  if (wait <= 0) {
39
50
  return;
40
51
  }
41
- var _timer = new Observable(function (_trigger) {
42
- trigger.current = _trigger;
43
- _trigger.next();
44
- }).pipe(delay(wait)).subscribe(function () {
45
- handler();
52
+ var _timed = timer(wait).subscribe(function () {
53
+ var _trigger$current2;
54
+ (_trigger$current2 = trigger.current) === null || _trigger$current2 === void 0 || _trigger$current2.complete();
46
55
  });
47
- timer.current = _timer;
48
- // unmount callback
49
- return cancel;
56
+ timed.current = _timed;
57
+ return function () {
58
+ _timed.unsubscribe();
59
+ timed.current = null;
60
+ };
50
61
  }, [wait]);
51
62
  return {
52
63
  flush: flush,
@@ -1,6 +1,6 @@
1
1
  import { useRef, useEffect } from 'react';
2
2
  import { useMounted } from './use-mounted.js';
3
- import { effect } from '../utils/effect/index.js';
3
+ import { effect } from '../utils/effect.js';
4
4
 
5
5
  var useUpdateEffect = function useUpdateEffect(callback, deps) {
6
6
  var isMounted = useRef(false);
package/dist/index.js CHANGED
@@ -31,13 +31,14 @@ export { isMobile } from './is/is-mobile.js';
31
31
  export { isOverflow } from './is/is-overflow.js';
32
32
  export { isStyleElement } from './is/is-style-element.js';
33
33
  export { isFunction } from './is/is-function.js';
34
- export { isThenable } from './is/is-thenable/index.js';
35
- export { effect } from './utils/effect/index.js';
34
+ export { isThenable } from './is/is-thenable.js';
35
+ export { effect } from './utils/effect.js';
36
36
  export { unique, uniqueBy } from './utils/unique.js';
37
37
  export { range } from './utils/range.js';
38
- export { clamp } from './utils/clamp/index.js';
39
- export { chain } from './utils/chain/index.js';
40
- export { debounce } from './utils/debounce/index.js';
41
- export { toArray } from './utils/to-array/index.js';
38
+ export { clamp } from './utils/clamp.js';
39
+ export { chain } from './utils/chain.js';
40
+ export { debounce } from './utils/debounce.js';
41
+ export { toArray } from './utils/to-array.js';
42
42
  export { toFunction } from './utils/to-function.js';
43
- export { exclude } from './utils/exclude/index.js';
43
+ export { exclude } from './utils/exclude.js';
44
+ export { toFormData } from './utils/to-form-data.js';
@@ -1,5 +1,5 @@
1
1
  import { type Dispatch, type SetStateAction } from 'react';
2
- import type { State } from "../types";
2
+ import type { State } from '../types';
3
3
  type UsedBoolean = [
4
4
  boolean,
5
5
  {
@@ -0,0 +1,2 @@
1
+ export type Callable = (...args: any) => any;
2
+ export declare const useEvent: <T extends Function | Callable>(callback: T) => T;
@@ -4,7 +4,7 @@
4
4
  * @description
5
5
  * timeout effect
6
6
  */
7
- export declare const useTimeout: (handler: Function, wait: number) => {
7
+ export declare const useTimeout: (callback: Function, wait: number) => {
8
8
  flush: () => void;
9
9
  cancel: () => void;
10
10
  };
@@ -53,3 +53,4 @@ export { debounce } from './utils/debounce';
53
53
  export { toArray } from './utils/to-array';
54
54
  export { toFunction } from './utils/to-function';
55
55
  export { exclude } from './utils/exclude';
56
+ export { toFormData } from './utils/to-form-data';
@@ -1,2 +1,2 @@
1
- import type { Voidable } from '../../types';
1
+ import type { Voidable } from '../types';
2
2
  export declare const chain: <T extends Function>(...callbacks: Voidable<T>[]) => T;
@@ -1,4 +1,4 @@
1
- import { type Callable } from '../../hooks/use-event';
1
+ import { type Callable } from '../hooks/use-event';
2
2
  export interface Debounced<T extends Callable> {
3
3
  /**
4
4
  * @description
@@ -1,5 +1,5 @@
1
1
  import type { EffectCallback } from 'react';
2
- import type { ThenableEffectCallback } from '../../types';
2
+ import type { ThenableEffectCallback } from '../types';
3
3
  /**
4
4
  * @description
5
5
  * call thenable effect
@@ -1,5 +1,5 @@
1
- import type { Debounced, Debouncer } from '../debounce';
2
- import { type Callable } from '../../hooks/use-event';
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 unknown[] = Parameters<T>>(throttler: T | Throttler<T, R>, wait: number) => Throttled<T>;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * convert to formData
4
+ */
5
+ export declare const toFormData: (data: unknown) => FormData;
@@ -1,6 +1,6 @@
1
1
  import { debounceTime } from 'rxjs';
2
- import { isFunction } from '../../is/is-function.js';
3
- import { Waitable } from '../waitable/index.js';
2
+ import { isFunction } from '../is/is-function.js';
3
+ import { Waitable } from './waitable.js';
4
4
 
5
5
  var debounce = function debounce(debouncer, wait) {
6
6
  var isCallable = isFunction(debouncer);
@@ -1,4 +1,4 @@
1
- import { isThenable } from '../../is/is-thenable/index.js';
1
+ import { isThenable } from '../is/is-thenable.js';
2
2
 
3
3
  /**
4
4
  * @description
@@ -1,5 +1,5 @@
1
- import { Waitable } from '../waitable/index.js';
2
- import { isFunction } from '../../is/is-function.js';
1
+ import { Waitable } from './waitable.js';
2
+ import { isFunction } from '../is/is-function.js';
3
3
  import { throttleTime } from 'rxjs';
4
4
 
5
5
  var throttle = function throttle(throttler, wait) {
@@ -1,5 +1,5 @@
1
- import { typeof as _typeof } from '../../_virtual/_rollupPluginBabelHelpers.js';
2
- import { isVoid } from '../../is/is-void.js';
1
+ import { typeof as _typeof } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+ import { isVoid } from '../is/is-void.js';
3
3
 
4
4
  /**
5
5
  * @description
@@ -0,0 +1,27 @@
1
+ import { slicedToArray as _slicedToArray } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+ import { isArray } from '../is/is-array.js';
3
+
4
+ /**
5
+ * @description
6
+ * convert to formData
7
+ */
8
+ var toFormData = function toFormData(data) {
9
+ return Object.entries(data !== null && data !== void 0 ? data : {}).reduce(function (prev, _ref) {
10
+ var _ref2 = _slicedToArray(_ref, 2),
11
+ key = _ref2[0],
12
+ value = _ref2[1];
13
+ // support key-value array data
14
+ // if value is { list: [ 11, 22 ] }
15
+ // like prev.append('list[]', 11);
16
+ if (isArray(value)) {
17
+ value.forEach(function (item) {
18
+ prev.append("".concat(key, "[]"), item);
19
+ });
20
+ return prev;
21
+ }
22
+ prev.append(key, value);
23
+ return prev;
24
+ }, new FormData());
25
+ };
26
+
27
+ export { toFormData };
@@ -1,6 +1,6 @@
1
- import { createClass as _createClass, classPrivateFieldGet2 as _classPrivateFieldGet2, assertClassBrand as _assertClassBrand, classCallCheck as _classCallCheck, classPrivateMethodInitSpec as _classPrivateMethodInitSpec, classPrivateFieldInitSpec as _classPrivateFieldInitSpec, classPrivateFieldSet2 as _classPrivateFieldSet2, toConsumableArray as _toConsumableArray } from '../../_virtual/_rollupPluginBabelHelpers.js';
1
+ import { createClass as _createClass, classPrivateFieldGet2 as _classPrivateFieldGet2, assertClassBrand as _assertClassBrand, classCallCheck as _classCallCheck, classPrivateMethodInitSpec as _classPrivateMethodInitSpec, classPrivateFieldInitSpec as _classPrivateFieldInitSpec, classPrivateFieldSet2 as _classPrivateFieldSet2, toConsumableArray as _toConsumableArray } from '../_virtual/_rollupPluginBabelHelpers.js';
2
2
  import { Observable, switchMap, from, of } from 'rxjs';
3
- import { isThenable } from '../../is/is-thenable/index.js';
3
+ import { isThenable } from '../is/is-thenable.js';
4
4
 
5
5
  /**
6
6
  * @description
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.2.41",
3
+ "version": "1.2.43",
4
4
  "description": "react utils collection",
5
5
  "type": "module",
6
6
  "exports": {
@@ -32,17 +32,21 @@
32
32
  "@rollup/plugin-babel": "^6.0.4",
33
33
  "@rollup/plugin-node-resolve": "^15.1.0",
34
34
  "@rollup/plugin-typescript": "^11.1.6",
35
+ "@testing-library/react": "^15.0.7",
35
36
  "@types/jest": "^29.5.12",
36
37
  "@types/react": "^18",
37
38
  "@types/react-dom": "^18",
38
39
  "@types/react-is": "^18",
39
40
  "jest": "^29.7.0",
41
+ "jest-environment-jsdom": "^29.7.0",
42
+ "react": "18",
43
+ "react-dom": "18",
40
44
  "rollup": "^4.17.2",
41
45
  "typescript": "5.3.3"
42
46
  },
43
47
  "peerDependencies": {
44
- "react": "^18",
45
- "react-dom": "^18"
48
+ "react": "18",
49
+ "react-dom": "18"
46
50
  },
47
51
  "files": [
48
52
  "dist/"
@@ -1,2 +0,0 @@
1
- export type Callable = (...args: any) => any;
2
- export declare const useEvent: <T extends Callable>(callback: T) => T;
@@ -1,5 +0,0 @@
1
- /**
2
- * @description
3
- * convert to formData
4
- */
5
- export declare const toFormData: (data: Record<string, unknown>) => FormData;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes