@aiszlab/relax 1.2.37 → 1.2.39

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 (122) hide show
  1. package/dist/_virtual/_rollupPluginBabelHelpers.js +153 -0
  2. package/dist/dom/contains.js +20 -0
  3. package/dist/dom/index.js +2 -0
  4. package/dist/dom/scroll-to.js +69 -0
  5. package/dist/hooks/use-boolean.js +34 -0
  6. package/dist/hooks/use-controlled-state.js +40 -0
  7. package/dist/hooks/use-counter.js +60 -0
  8. package/dist/hooks/use-debounce-callback.js +81 -0
  9. package/dist/hooks/use-default.js +14 -0
  10. package/dist/hooks/use-event.js +12 -0
  11. package/dist/hooks/use-focus.js +31 -0
  12. package/dist/hooks/use-force-update.js +21 -0
  13. package/dist/hooks/use-hover.js +25 -0
  14. package/dist/hooks/use-image-loader.js +54 -0
  15. package/dist/hooks/use-memorable.js +14 -0
  16. package/dist/hooks/use-mount.js +16 -0
  17. package/dist/hooks/use-mounted.js +16 -0
  18. package/dist/hooks/use-refs.js +25 -0
  19. package/dist/hooks/use-scroll-locker.js +92 -0
  20. package/dist/hooks/use-scrollable.js +43 -0
  21. package/dist/hooks/use-throttle-callback.d.ts +3 -3
  22. package/dist/hooks/use-throttle-callback.js +83 -0
  23. package/dist/hooks/use-timeout.js +19 -0
  24. package/dist/hooks/use-toggleable.js +186 -0
  25. package/dist/hooks/use-update-effect.js +19 -0
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.js +43 -0
  28. package/dist/is/is-array.js +9 -0
  29. package/dist/is/is-complex.js +11 -0
  30. package/dist/is/is-dom-usable.js +9 -0
  31. package/dist/is/is-empty.js +25 -0
  32. package/dist/is/is-function.js +9 -0
  33. package/dist/is/is-mobile.js +13 -0
  34. package/dist/is/is-null.js +9 -0
  35. package/dist/is/is-overflow.js +14 -0
  36. package/dist/is/is-refable.js +34 -0
  37. package/dist/is/is-state-getter.js +9 -0
  38. package/dist/is/is-style-element.js +9 -0
  39. package/dist/is/is-thenable/index.js +9 -0
  40. package/dist/is/is-thenable/index.test.d.ts +1 -0
  41. package/dist/is/is-undefined.js +9 -0
  42. package/dist/is/is-void.js +12 -0
  43. package/dist/utils/{chain.d.ts → chain/index.d.ts} +1 -1
  44. package/dist/utils/chain/index.js +15 -0
  45. package/dist/utils/chain/index.test.d.ts +1 -0
  46. package/dist/utils/{clamp.mjs → clamp/index.js} +2 -2
  47. package/dist/utils/clamp/index.test.d.ts +1 -0
  48. package/dist/utils/clone/index.test.d.ts +1 -0
  49. package/dist/utils/debounce/index.d.ts +23 -0
  50. package/dist/utils/debounce/index.js +32 -0
  51. package/dist/utils/debounce/index.test.d.ts +1 -0
  52. package/dist/utils/{effect.d.ts → effect/index.d.ts} +1 -1
  53. package/dist/utils/effect/index.js +16 -0
  54. package/dist/utils/effect/index.test.d.ts +1 -0
  55. package/dist/utils/exclude/index.d.ts +7 -0
  56. package/dist/utils/exclude/index.js +14 -0
  57. package/dist/utils/exclude/index.test.d.ts +1 -0
  58. package/dist/utils/range.js +16 -0
  59. package/dist/utils/set-style.js +21 -0
  60. package/dist/utils/{throttle.d.ts → throttle/index.d.ts} +3 -3
  61. package/dist/utils/throttle/index.js +32 -0
  62. package/dist/utils/throttle/index.test.d.ts +1 -0
  63. package/dist/utils/to-array/index.d.ts +18 -0
  64. package/dist/utils/to-array/index.js +25 -0
  65. package/dist/utils/to-array/index.test.d.ts +1 -0
  66. package/dist/utils/to-function.js +13 -0
  67. package/dist/utils/unique.js +16 -0
  68. package/dist/utils/waitable/index.d.ts +36 -0
  69. package/dist/utils/waitable/index.js +90 -0
  70. package/package.json +9 -6
  71. package/dist/dom/contains.mjs +0 -20
  72. package/dist/dom/index.mjs +0 -2
  73. package/dist/dom/scroll-to.mjs +0 -53
  74. package/dist/hooks/use-boolean.mjs +0 -22
  75. package/dist/hooks/use-controlled-state.mjs +0 -37
  76. package/dist/hooks/use-counter.mjs +0 -33
  77. package/dist/hooks/use-debounce-callback.mjs +0 -57
  78. package/dist/hooks/use-default.mjs +0 -14
  79. package/dist/hooks/use-event.mjs +0 -10
  80. package/dist/hooks/use-focus.mjs +0 -16
  81. package/dist/hooks/use-force-update.mjs +0 -15
  82. package/dist/hooks/use-hover.mjs +0 -16
  83. package/dist/hooks/use-image-loader.mjs +0 -41
  84. package/dist/hooks/use-memorable.mjs +0 -14
  85. package/dist/hooks/use-mount.mjs +0 -16
  86. package/dist/hooks/use-mounted.mjs +0 -16
  87. package/dist/hooks/use-refs.mjs +0 -23
  88. package/dist/hooks/use-scroll-locker.mjs +0 -79
  89. package/dist/hooks/use-scrollable.mjs +0 -41
  90. package/dist/hooks/use-throttle-callback.mjs +0 -57
  91. package/dist/hooks/use-timeout.mjs +0 -20
  92. package/dist/hooks/use-toggleable.mjs +0 -145
  93. package/dist/hooks/use-update-effect.mjs +0 -20
  94. package/dist/index.mjs +0 -42
  95. package/dist/is/is-array.mjs +0 -9
  96. package/dist/is/is-complex.mjs +0 -9
  97. package/dist/is/is-dom-usable.mjs +0 -9
  98. package/dist/is/is-empty.mjs +0 -25
  99. package/dist/is/is-function.mjs +0 -9
  100. package/dist/is/is-mobile.mjs +0 -16
  101. package/dist/is/is-null.mjs +0 -9
  102. package/dist/is/is-overflow.mjs +0 -14
  103. package/dist/is/is-refable.mjs +0 -33
  104. package/dist/is/is-state-getter.mjs +0 -9
  105. package/dist/is/is-style-element.mjs +0 -9
  106. package/dist/is/is-thenable.mjs +0 -9
  107. package/dist/is/is-undefined.mjs +0 -9
  108. package/dist/is/is-void.mjs +0 -12
  109. package/dist/utils/chain.mjs +0 -9
  110. package/dist/utils/debounce.d.ts +0 -56
  111. package/dist/utils/debounce.mjs +0 -77
  112. package/dist/utils/effect.mjs +0 -18
  113. package/dist/utils/range.mjs +0 -12
  114. package/dist/utils/set-style.mjs +0 -17
  115. package/dist/utils/throttle.mjs +0 -17
  116. package/dist/utils/to-array.d.ts +0 -5
  117. package/dist/utils/to-array.mjs +0 -12
  118. package/dist/utils/to-function.mjs +0 -11
  119. package/dist/utils/unique.mjs +0 -16
  120. /package/dist/is/{is-thenable.d.ts → is-thenable/index.d.ts} +0 -0
  121. /package/dist/utils/{clamp.d.ts → clamp/index.d.ts} +0 -0
  122. /package/dist/utils/{clone.d.ts → clone/index.d.ts} +0 -0
@@ -0,0 +1,34 @@
1
+ import { isValidElement } from 'react';
2
+ import { isFragment, isMemo } from 'react-is';
3
+
4
+ /**
5
+ * @description
6
+ */
7
+ var isRefable = function isRefable(node) {
8
+ if (!isValidElement(node)) {
9
+ return false;
10
+ }
11
+ if (isFragment(node)) {
12
+ return false;
13
+ }
14
+ return _RefableElement(node);
15
+ };
16
+ /**
17
+ * @description
18
+ * refable element
19
+ */
20
+ var _RefableElement = function _RefableElement(element) {
21
+ var _type$prototype, _element$prototype;
22
+ var type = isMemo(element) ? element.type.type : element.type;
23
+ // Function component node
24
+ if (typeof type === 'function' && !((_type$prototype = type.prototype) !== null && _type$prototype !== void 0 && _type$prototype.render)) {
25
+ return false;
26
+ }
27
+ // Class component
28
+ if (typeof element === 'function' && !((_element$prototype = element.prototype) !== null && _element$prototype !== void 0 && _element$prototype.render)) {
29
+ return false;
30
+ }
31
+ return true;
32
+ };
33
+
34
+ export { isRefable };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * is state getter
4
+ */
5
+ var isStateGetter = function isStateGetter(state) {
6
+ return typeof state === 'function';
7
+ };
8
+
9
+ export { isStateGetter };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * style element
4
+ */
5
+ var isStyleElement = function isStyleElement(element) {
6
+ return element.tagName === 'STYLE';
7
+ };
8
+
9
+ export { isStyleElement };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * is thenable
4
+ */
5
+ var isThenable = function isThenable(value) {
6
+ return value instanceof Promise || !!value.then;
7
+ };
8
+
9
+ export { isThenable };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * is undefined
4
+ */
5
+ var isUndefined = function isUndefined(value) {
6
+ return value === void 0;
7
+ };
8
+
9
+ export { isUndefined };
@@ -0,0 +1,12 @@
1
+ import { isUndefined } from './is-undefined.js';
2
+ import { isNull } from './is-null.js';
3
+
4
+ /**
5
+ * @description
6
+ * is null or undefined
7
+ */
8
+ var isVoid = function isVoid(value) {
9
+ return isNull(value) || isUndefined(value);
10
+ };
11
+
12
+ export { isVoid };
@@ -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;
@@ -0,0 +1,15 @@
1
+ var chain = function chain() {
2
+ for (var _len = arguments.length, callbacks = new Array(_len), _key = 0; _key < _len; _key++) {
3
+ callbacks[_key] = arguments[_key];
4
+ }
5
+ return function () {
6
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
7
+ args[_key2] = arguments[_key2];
8
+ }
9
+ callbacks.forEach(function (callback) {
10
+ callback === null || callback === void 0 || callback.apply(void 0, args);
11
+ });
12
+ };
13
+ };
14
+
15
+ export { chain };
@@ -0,0 +1 @@
1
+ export {};
@@ -6,8 +6,8 @@
6
6
  * @param max number
7
7
  * @returns number
8
8
  */
9
- const clamp = (value, min, max) => {
10
- return Math.min(Math.max(value, min), max);
9
+ var clamp = function clamp(value, min, max) {
10
+ return Math.min(Math.max(value, min), max);
11
11
  };
12
12
 
13
13
  export { clamp };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import { type Callable } from '../../hooks/use-event';
2
+ export interface Debounced<T extends Callable> {
3
+ /**
4
+ * @description
5
+ * value trigger
6
+ */
7
+ next: (...args: Parameters<T>) => void;
8
+ /**
9
+ * @description
10
+ * complete current debounce/throttle function
11
+ */
12
+ flush: () => void;
13
+ /**
14
+ * @description
15
+ * ignore any value after call cancel
16
+ */
17
+ abort: () => void;
18
+ }
19
+ export type Debouncer<T extends Callable, R extends Array<unknown> = Parameters<T>> = {
20
+ callback: (...args: R) => ReturnType<T>;
21
+ pipe: (...args: Parameters<T>) => R | Promise<R>;
22
+ };
23
+ export declare const debounce: <T extends Callable, R extends unknown[] = Parameters<T>>(debouncer: T | Debouncer<T, R>, wait: number) => Debounced<T>;
@@ -0,0 +1,32 @@
1
+ import { debounceTime } from 'rxjs';
2
+ import { isFunction } from '../../is/is-function.js';
3
+ import { Waitable } from '../waitable/index.js';
4
+
5
+ var debounce = function debounce(debouncer, wait) {
6
+ var isCallable = isFunction(debouncer);
7
+ var callback = isCallable ? debouncer : debouncer.callback;
8
+ var pipe = isCallable ? function () {
9
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
10
+ args[_key] = arguments[_key];
11
+ }
12
+ return args;
13
+ } : debouncer.pipe;
14
+ var waiter = new Waitable({
15
+ callback: callback,
16
+ pipe: pipe,
17
+ timer: debounceTime(wait)
18
+ });
19
+ return {
20
+ next: function next() {
21
+ return waiter.next.apply(waiter, arguments);
22
+ },
23
+ flush: function flush() {
24
+ return waiter.flush();
25
+ },
26
+ abort: function abort() {
27
+ return waiter.abort();
28
+ }
29
+ };
30
+ };
31
+
32
+ export { debounce };
@@ -0,0 +1 @@
1
+ export {};
@@ -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
@@ -0,0 +1,16 @@
1
+ import { isThenable } from '../../is/is-thenable/index.js';
2
+
3
+ /**
4
+ * @description
5
+ * call thenable effect
6
+ */
7
+ var effect = function effect(callable) {
8
+ var called = callable();
9
+ // if result is void
10
+ if (!called) return void 0;
11
+ // if result is promise like, return void
12
+ if (isThenable(called)) return void 0;
13
+ return called;
14
+ };
15
+
16
+ export { effect };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @description
3
+ * exclude any value from array
4
+ *
5
+ * for performance, avoid using `Array.includes`, replace with `Set`
6
+ */
7
+ export declare const exclude: (value: Array<unknown>, _excludeBy: Array<unknown>) => unknown[];
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @description
3
+ * exclude any value from array
4
+ *
5
+ * for performance, avoid using `Array.includes`, replace with `Set`
6
+ */
7
+ var exclude = function exclude(value, _excludeBy) {
8
+ var excludeBy = new Set(_excludeBy);
9
+ return value.filter(function (item) {
10
+ return !excludeBy.has(item);
11
+ });
12
+ };
13
+
14
+ export { exclude };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Returns an array of numbers, starting at `from` and ending at `to`.
3
+ * @param from number
4
+ * @param to number
5
+ * @returns number[]
6
+ */
7
+ var range = function range(from, to) {
8
+ var length = to - from + 1;
9
+ return Array.from({
10
+ length: length
11
+ }, function (_, index) {
12
+ return index + from;
13
+ });
14
+ };
15
+
16
+ export { range };
@@ -0,0 +1,21 @@
1
+ import { slicedToArray as _slicedToArray } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+
3
+ /**
4
+ * @description
5
+ * set inline style util
6
+ */
7
+ var setStyle = function setStyle(target, styles) {
8
+ if (!styles) return {};
9
+ return Object.entries(styles).reduce(function (prev, _ref) {
10
+ var _ref2 = _slicedToArray(_ref, 2),
11
+ key = _ref2[0],
12
+ value = _ref2[1];
13
+ // @ts-ignore
14
+ prev[key] = target.style[key];
15
+ // @ts-ignore
16
+ target.style[key] = value;
17
+ return prev;
18
+ }, {});
19
+ };
20
+
21
+ export { setStyle };
@@ -1,5 +1,5 @@
1
- import { type Debounced, type 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
- export declare const throttle: <T extends Callable, R extends unknown[] = Parameters<T>>(throttler: T | Throttler<T, R>, duration: number) => Throttled<T>;
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,32 @@
1
+ import { Waitable } from '../waitable/index.js';
2
+ import { isFunction } from '../../is/is-function.js';
3
+ import { throttleTime } from 'rxjs';
4
+
5
+ var throttle = function throttle(throttler, wait) {
6
+ var isCallable = isFunction(throttler);
7
+ var callback = isCallable ? throttler : throttler.callback;
8
+ var pipe = isCallable ? function () {
9
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
10
+ args[_key] = arguments[_key];
11
+ }
12
+ return args;
13
+ } : throttler.pipe;
14
+ var waiter = new Waitable({
15
+ callback: callback,
16
+ pipe: pipe,
17
+ timer: throttleTime(wait)
18
+ });
19
+ return {
20
+ next: function next() {
21
+ return waiter.next.apply(waiter, arguments);
22
+ },
23
+ flush: function flush() {
24
+ return waiter.flush();
25
+ },
26
+ abort: function abort() {
27
+ return waiter.abort();
28
+ }
29
+ };
30
+ };
31
+
32
+ export { throttle };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @description
3
+ * options
4
+ */
5
+ type Options = {
6
+ /**
7
+ * @description
8
+ * separator
9
+ * only effect in `value is string`, value would be split by separator
10
+ */
11
+ separator?: string;
12
+ };
13
+ /**
14
+ * @description
15
+ * convert any type data to a array
16
+ */
17
+ export declare const toArray: <T extends unknown = unknown>(value: T | T[], { separator }?: Options) => T[];
18
+ export {};
@@ -0,0 +1,25 @@
1
+ import { typeof as _typeof } from '../../_virtual/_rollupPluginBabelHelpers.js';
2
+ import { isVoid } from '../../is/is-void.js';
3
+
4
+ /**
5
+ * @description
6
+ * convert any type data to a array
7
+ */
8
+ var toArray = function toArray(value) {
9
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
10
+ separator = _ref.separator;
11
+ if (Array.isArray(value)) {
12
+ return value;
13
+ }
14
+ switch (_typeof(value)) {
15
+ case 'string':
16
+ if (isVoid(separator)) {
17
+ return [value];
18
+ }
19
+ return value.split(separator);
20
+ default:
21
+ return [value];
22
+ }
23
+ };
24
+
25
+ export { toArray };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import { isFunction } from '../is/is-function.js';
2
+
3
+ var toFunction = function toFunction(value) {
4
+ var _isFunction = isFunction(value);
5
+ if (_isFunction) {
6
+ return value;
7
+ }
8
+ return function () {
9
+ return value;
10
+ };
11
+ };
12
+
13
+ export { toFunction };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @description
3
+ * unique
4
+ */
5
+ var unique = function unique(value) {
6
+ return Array.from(new Set(value));
7
+ };
8
+ /**
9
+ * @description
10
+ * unique by
11
+ */
12
+ var uniqueBy = function uniqueBy(value, callback) {
13
+ return Array.from(new Set(Array.from(value).map(callback)));
14
+ };
15
+
16
+ export { unique, uniqueBy };
@@ -0,0 +1,36 @@
1
+ import { type MonoTypeOperatorFunction } from 'rxjs';
2
+ interface Props<T extends Array<unknown> = Array<unknown>, R extends Array<unknown> = T> {
3
+ callback: (...args: T) => unknown;
4
+ pipe: (...args: R) => T | Promise<T>;
5
+ timer: MonoTypeOperatorFunction<R>;
6
+ }
7
+ /**
8
+ * @description
9
+ * waitable instance
10
+ * for debounce...
11
+ */
12
+ export declare class Waitable<T extends Array<unknown>, R extends Array<unknown> = T> {
13
+ #private;
14
+ constructor(props: Props<T, R>);
15
+ /**
16
+ * @description
17
+ * flush
18
+ * complete all handlers
19
+ * in relax, we will create a new observable for next debounce/throttle handler
20
+ * so it will make some async problems, pls attention
21
+ */
22
+ flush(): void;
23
+ /**
24
+ * @description
25
+ * abort
26
+ * cancel all handlers
27
+ * in relax, we will create a new observable for next debounce/throttle handler
28
+ */
29
+ abort(): void;
30
+ /**
31
+ * @description
32
+ * trigger value
33
+ */
34
+ next(...args: R): void;
35
+ }
36
+ export {};
@@ -0,0 +1,90 @@
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
+ import { Observable, switchMap, from, of } from 'rxjs';
3
+ import { isThenable } from '../../is/is-thenable/index.js';
4
+
5
+ /**
6
+ * @description
7
+ * waitable instance
8
+ * for debounce...
9
+ */
10
+ var _cook$ = /*#__PURE__*/new WeakMap();
11
+ var _waiter$ = /*#__PURE__*/new WeakMap();
12
+ var _timer = /*#__PURE__*/new WeakMap();
13
+ var _pipe = /*#__PURE__*/new WeakMap();
14
+ var _callback = /*#__PURE__*/new WeakMap();
15
+ var _Waitable_brand = /*#__PURE__*/new WeakSet();
16
+ var Waitable = /*#__PURE__*/function () {
17
+ function Waitable(props) {
18
+ _classCallCheck(this, Waitable);
19
+ _classPrivateMethodInitSpec(this, _Waitable_brand);
20
+ _classPrivateFieldInitSpec(this, _cook$, void 0);
21
+ _classPrivateFieldInitSpec(this, _waiter$, void 0);
22
+ _classPrivateFieldInitSpec(this, _timer, void 0);
23
+ _classPrivateFieldInitSpec(this, _pipe, void 0);
24
+ _classPrivateFieldInitSpec(this, _callback, void 0);
25
+ _classPrivateFieldSet2(_cook$, this, null);
26
+ _classPrivateFieldSet2(_waiter$, this, null);
27
+ _classPrivateFieldSet2(_pipe, this, props.pipe);
28
+ _classPrivateFieldSet2(_timer, this, props.timer);
29
+ _classPrivateFieldSet2(_callback, this, props.callback);
30
+ _assertClassBrand(_Waitable_brand, this, _use).call(this);
31
+ }
32
+ return _createClass(Waitable, [{
33
+ key: "flush",
34
+ value:
35
+ /**
36
+ * @description
37
+ * flush
38
+ * complete all handlers
39
+ * in relax, we will create a new observable for next debounce/throttle handler
40
+ * so it will make some async problems, pls attention
41
+ */
42
+ function flush() {
43
+ var _classPrivateFieldGet2$1;
44
+ (_classPrivateFieldGet2$1 = _classPrivateFieldGet2(_waiter$, this)) === null || _classPrivateFieldGet2$1 === void 0 || _classPrivateFieldGet2$1.complete();
45
+ _assertClassBrand(_Waitable_brand, this, _use).call(this);
46
+ }
47
+ /**
48
+ * @description
49
+ * abort
50
+ * cancel all handlers
51
+ * in relax, we will create a new observable for next debounce/throttle handler
52
+ */
53
+ }, {
54
+ key: "abort",
55
+ value: function abort() {
56
+ var _classPrivateFieldGet3, _classPrivateFieldGet4;
57
+ (_classPrivateFieldGet3 = _classPrivateFieldGet2(_cook$, this)) === null || _classPrivateFieldGet3 === void 0 || _classPrivateFieldGet3.unsubscribe();
58
+ (_classPrivateFieldGet4 = _classPrivateFieldGet2(_waiter$, this)) === null || _classPrivateFieldGet4 === void 0 || _classPrivateFieldGet4.error();
59
+ _assertClassBrand(_Waitable_brand, this, _use).call(this);
60
+ }
61
+ /**
62
+ * @description
63
+ * trigger value
64
+ */
65
+ }, {
66
+ key: "next",
67
+ value: function next() {
68
+ var _classPrivateFieldGet5;
69
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
70
+ args[_key] = arguments[_key];
71
+ }
72
+ (_classPrivateFieldGet5 = _classPrivateFieldGet2(_waiter$, this)) === null || _classPrivateFieldGet5 === void 0 || _classPrivateFieldGet5.next(args);
73
+ }
74
+ }]);
75
+ }();
76
+ function _use() {
77
+ var _this = this;
78
+ _classPrivateFieldSet2(_cook$, this, new Observable(function (subscriber) {
79
+ _classPrivateFieldSet2(_waiter$, _this, subscriber);
80
+ }).pipe(_classPrivateFieldGet2(_timer, this), switchMap(function (args) {
81
+ var _classPrivateFieldGet6;
82
+ var piped = (_classPrivateFieldGet6 = _classPrivateFieldGet2(_pipe, _this)).call.apply(_classPrivateFieldGet6, [_this].concat(_toConsumableArray(args)));
83
+ return isThenable(piped) ? from(piped) : of(piped);
84
+ })).subscribe(function (args) {
85
+ var _classPrivateFieldGet7;
86
+ (_classPrivateFieldGet7 = _classPrivateFieldGet2(_callback, _this)) === null || _classPrivateFieldGet7 === void 0 || _classPrivateFieldGet7.call.apply(_classPrivateFieldGet7, [_this].concat(_toConsumableArray(args)));
87
+ }));
88
+ }
89
+
90
+ export { Waitable };
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.2.37",
3
+ "version": "1.2.39",
4
4
  "description": "react utils collection",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
8
  "types": "./dist/index.d.ts",
9
- "default": "./dist/index.mjs"
9
+ "default": "./dist/index.js"
10
10
  },
11
11
  "./dom": {
12
12
  "types": "./dist/dom/index.d.ts",
13
- "default": "./dist/dom/index.mjs"
13
+ "default": "./dist/dom/index.js"
14
14
  },
15
15
  "./types": "./dist/types/index.d.ts"
16
16
  },
@@ -18,7 +18,8 @@
18
18
  "dev": "rollup -c -w",
19
19
  "build": "rollup -c",
20
20
  "clean:build": "rm -rf dist",
21
- "pub": "npm run clean:build && npm run build && npm publish"
21
+ "pub": "npm run clean:build && npm run build && npm publish",
22
+ "test": "jest"
22
23
  },
23
24
  "dependencies": {
24
25
  "react-is": "^18.2.0",
@@ -28,13 +29,15 @@
28
29
  "@babel/core": "^7.24.0",
29
30
  "@babel/preset-env": "^7.24.0",
30
31
  "@babel/preset-typescript": "^7.24.1",
31
- "@rollup/plugin-babel": "^6.0.3",
32
+ "@rollup/plugin-babel": "^6.0.4",
32
33
  "@rollup/plugin-node-resolve": "^15.1.0",
33
34
  "@rollup/plugin-typescript": "^11.1.6",
35
+ "@types/jest": "^29.5.12",
34
36
  "@types/react": "^18",
35
37
  "@types/react-dom": "^18",
36
38
  "@types/react-is": "^18",
37
- "rollup": "^4.13.0",
39
+ "jest": "^29.7.0",
40
+ "rollup": "^4.17.2",
38
41
  "typescript": "5.3.3"
39
42
  },
40
43
  "peerDependencies": {
@@ -1,20 +0,0 @@
1
- const contains = (root, n) => {
2
- if (!root) {
3
- return false;
4
- }
5
- // Use native if support
6
- if (root.contains) {
7
- return root.contains(n ?? null);
8
- }
9
- // `document.contains` not support with IE11
10
- let node = n;
11
- while (node) {
12
- if (node === root) {
13
- return true;
14
- }
15
- node = node.parentNode;
16
- }
17
- return false;
18
- };
19
-
20
- export { contains };
@@ -1,2 +0,0 @@
1
- export { scrollTo } from './scroll-to.mjs';
2
- export { contains } from './contains.mjs';