@aiszlab/relax 1.2.73 → 1.2.75

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.
@@ -1 +1,16 @@
1
- export declare const contains: (root: Node | null | undefined, n?: Node | null) => boolean;
1
+ import type { Nullable, Voidable } from "@aiszlab/relax/types";
2
+ /**
3
+ * @description
4
+ * in musae, we add this function to replace `root.contains(n)`
5
+ * and we use simple type declaration
6
+ *
7
+ * support `HTMLElement` interface
8
+ */
9
+ export type Containable = {
10
+ /**
11
+ * @description
12
+ * native `contains` api
13
+ */
14
+ contains?: (node: Nullable<Node>) => boolean;
15
+ };
16
+ export declare const contains: (root: Voidable<Containable>, node: Voidable<Node>) => boolean;
@@ -1,18 +1,18 @@
1
- var contains = function contains(root, n) {
1
+ var contains = function contains(root, node) {
2
2
  if (!root) {
3
3
  return false;
4
4
  }
5
5
  // Use native if support
6
6
  if (root.contains) {
7
- return root.contains(n !== null && n !== void 0 ? n : null);
7
+ return root.contains(node !== null && node !== void 0 ? node : null);
8
8
  }
9
9
  // `document.contains` not support with IE11
10
- var node = n;
11
- while (node) {
12
- if (node === root) {
10
+ var _node = node;
11
+ while (_node) {
12
+ if (_node === root) {
13
13
  return true;
14
14
  }
15
- node = node.parentNode;
15
+ _node = _node.parentNode;
16
16
  }
17
17
  return false;
18
18
  };
@@ -1,3 +1,4 @@
1
- import { scrollTo } from "./scroll-to";
2
- import { contains } from "./contains";
1
+ import { scrollTo, type Orientation } from "./scroll-to";
2
+ import { contains, type Containable } from "./contains";
3
3
  export { scrollTo, contains };
4
+ export type { Containable, Orientation };
@@ -1,5 +1,5 @@
1
1
  import { type Dispatch, type SetStateAction } from "react";
2
- import type { State } from "../types";
2
+ import type { State } from "@aiszlab/relax/types";
3
3
  type UsedBoolean = [
4
4
  boolean,
5
5
  {
@@ -1,7 +1,8 @@
1
1
  import { type MutableRefObject } from "react";
2
- import type { Arrayable } from "../types/arrayable";
2
+ import { type Containable } from "@aiszlab/relax/dom";
3
+ import type { Nullable, Arrayable } from "@aiszlab/relax/types";
3
4
  /**
4
5
  * @description
5
6
  * click away
6
7
  */
7
- export declare const useClickAway: (onClickAway: (event: MouseEvent) => void, target: Arrayable<MutableRefObject<HTMLElement | null>>) => void;
8
+ export declare const useClickAway: (onClickAway: (event: MouseEvent) => void, target: Arrayable<MutableRefObject<Nullable<Containable>> | false>) => void;
@@ -1,7 +1,7 @@
1
1
  import { useEffect } from 'react';
2
2
  import { useEvent } from './use-event.js';
3
- import { contains } from '../dom/contains.js';
4
3
  import { toArray } from '../utils/to-array.js';
4
+ import { contains } from '@aiszlab/relax/dom';
5
5
 
6
6
  /**
7
7
  * @description
@@ -11,7 +11,7 @@ var useClickAway = function useClickAway(onClickAway, target) {
11
11
  var clickAway = useEvent(function (event) {
12
12
  var targets = toArray(target);
13
13
  var isContained = targets.some(function (_target) {
14
- return contains(_target.current, event.target);
14
+ return _target && contains(_target.current, event.target);
15
15
  });
16
16
  if (isContained) return;
17
17
  onClickAway(event);
@@ -1,5 +1,5 @@
1
1
  import { type Dispatch, type SetStateAction } from "react";
2
- import type { State } from "../types";
2
+ import type { State } from "@aiszlab/relax/types";
3
3
  type UseControlledStateBy<R> = {
4
4
  /**
5
5
  * @description
@@ -1,5 +1,5 @@
1
1
  import { type Dispatch, type SetStateAction } from "react";
2
- import type { State } from "../types";
2
+ import type { State } from "@aiszlab/relax/types";
3
3
  type Props = {
4
4
  /**
5
5
  * @description
@@ -1,4 +1,4 @@
1
- import type { State } from "../types";
1
+ import type { State } from "@aiszlab/relax/types";
2
2
  /**
3
3
  * @author murukal
4
4
  *
@@ -1,4 +1,4 @@
1
- import type { ThenableEffectCallback } from "../types";
1
+ import type { ThenableEffectCallback } from "@aiszlab/relax/types";
2
2
  /**
3
3
  * @author murukal
4
4
  *
@@ -1,4 +1,4 @@
1
- import type { ThenableEffectCallback } from "../types";
1
+ import type { ThenableEffectCallback } from "@aiszlab/relax/types";
2
2
  /**
3
3
  * @author murukal
4
4
  *
@@ -1,4 +1,4 @@
1
- import type { State } from "../types";
1
+ import type { State } from "@aiszlab/relax/types";
2
2
  /**
3
3
  * @description
4
4
  * use reactive
@@ -1,5 +1,5 @@
1
1
  import { type MutableRefObject, type RefCallback } from "react";
2
- import type { Nullable, Voidable } from "../types";
2
+ import type { Nullable, Voidable } from "@aiszlab/relax/types";
3
3
  type Refable<T> = RefCallback<T> | MutableRefObject<T> | string;
4
4
  export declare const useRefs: <T>(...refs: Voidable<Refable<Nullable<T>>>[]) => (trigger: T) => void;
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  import { type Key } from "react";
2
- import { type Orientation } from "../dom/scroll-to";
2
+ import { type Orientation } from "@aiszlab/relax/dom";
3
3
  interface UseScrollableProps {
4
4
  orientation?: Orientation;
5
5
  }
@@ -1,5 +1,5 @@
1
1
  import { useRef, useCallback } from 'react';
2
- import { scrollTo as _scrollTo } from '../dom/scroll-to.js';
2
+ import { scrollTo } from '@aiszlab/relax/dom';
3
3
 
4
4
  /**
5
5
  * @description
@@ -11,12 +11,12 @@ var useScrollable = function useScrollable() {
11
11
  orientation = _ref$orientation === void 0 ? "vertical" : _ref$orientation;
12
12
  var targetRef = useRef(null);
13
13
  var triggerRefs = useRef(new Map());
14
- var scrollTo = useCallback(function (to) {
14
+ var scrollTo$1 = useCallback(function (to) {
15
15
  var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
16
16
  var target = targetRef.current;
17
17
  if (!target) return;
18
18
  // use animated scroll
19
- _scrollTo(target, to, {
19
+ scrollTo(target, to, {
20
20
  duration: duration,
21
21
  orientation: orientation
22
22
  });
@@ -34,7 +34,7 @@ var useScrollable = function useScrollable() {
34
34
  return {
35
35
  targetRef: targetRef,
36
36
  triggerRefs: triggerRefs,
37
- scrollTo: scrollTo,
37
+ scrollTo: scrollTo$1,
38
38
  to: to,
39
39
  setTrigger: setTrigger
40
40
  };
@@ -1,3 +1,3 @@
1
1
  import { type DependencyList } from "react";
2
- import type { ThenableEffectCallback } from "../types";
2
+ import type { ThenableEffectCallback } from "@aiszlab/relax/types";
3
3
  export declare const useUpdateEffect: (callback: ThenableEffectCallback, deps?: DependencyList) => void;
package/dist/index.d.ts CHANGED
@@ -51,6 +51,8 @@ export { isOverflow } from "./is/is-overflow";
51
51
  export { isStyleElement } from "./is/is-style-element";
52
52
  export { isFunction } from "./is/is-function";
53
53
  export { isThenable } from "./is/is-thenable";
54
+ export { isHTMLElement } from "./is/is-html-element";
55
+ export { isHTMLInputElement } from "./is/is-html-input-element";
54
56
  /**
55
57
  * @description
56
58
  * utils
package/dist/index.js CHANGED
@@ -43,6 +43,8 @@ export { isOverflow } from './is/is-overflow.js';
43
43
  export { isStyleElement } from './is/is-style-element.js';
44
44
  export { isFunction } from './is/is-function.js';
45
45
  export { isThenable } from './is/is-thenable.js';
46
+ export { isHTMLElement } from './is/is-html-element.js';
47
+ export { isHTMLInputElement } from './is/is-html-input-element.js';
46
48
  export { effect } from './utils/effect.js';
47
49
  export { unique, uniqueBy } from './utils/unique.js';
48
50
  export { range } from './utils/range.js';
@@ -0,0 +1,9 @@
1
+ import type { Voidable } from "../types";
2
+ export type Node = {
3
+ nodeType?: number;
4
+ };
5
+ /**
6
+ * @description
7
+ * is html element
8
+ */
9
+ export declare const isHTMLElement: (value: Voidable<Node>) => value is HTMLElement;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @description
3
+ * is html element
4
+ */
5
+ var isHTMLElement = function isHTMLElement(value) {
6
+ if (!value) return false;
7
+ return value.nodeType === 1;
8
+ };
9
+
10
+ export { isHTMLElement };
@@ -0,0 +1,7 @@
1
+ import type { Voidable } from "../types";
2
+ import { type Node } from "./is-html-element";
3
+ /**
4
+ * @param value - The element being tested
5
+ * @returns Returns true if x is an HTML input tag, false otherwise
6
+ */
7
+ export declare const isHTMLInputElement: (value: Voidable<Node>) => value is HTMLInputElement;
@@ -0,0 +1,11 @@
1
+ import { isHTMLElement } from './is-html-element.js';
2
+
3
+ /**
4
+ * @param value - The element being tested
5
+ * @returns Returns true if x is an HTML input tag, false otherwise
6
+ */
7
+ var isHTMLInputElement = function isHTMLInputElement(value) {
8
+ return isHTMLElement(value) && value.tagName === "INPUT";
9
+ };
10
+
11
+ export { isHTMLInputElement };
@@ -1,2 +1,2 @@
1
- import type { Voidable } from "../types";
1
+ import type { Voidable } from "@aiszlab/relax/types";
2
2
  export declare const chain: <T extends Function>(...callbacks: Voidable<T>[]) => T;
@@ -1,5 +1,5 @@
1
1
  import type { EffectCallback } from "react";
2
- import type { ThenableEffectCallback } from "../types";
2
+ import type { ThenableEffectCallback } from "@aiszlab/relax/types";
3
3
  /**
4
4
  * @description
5
5
  * call thenable effect
@@ -1,4 +1,4 @@
1
- import type { Voidable } from "../types";
1
+ import type { Voidable } from "@aiszlab/relax/types";
2
2
  /**
3
3
  * @description
4
4
  * set inline style util
@@ -1,4 +1,4 @@
1
- import { Voidable } from "../types";
1
+ import type { Voidable } from "@aiszlab/relax/types";
2
2
  /**
3
3
  * @description
4
4
  * create tagged template literals
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.2.73",
3
+ "version": "1.2.75",
4
4
  "description": "react utils collection",
5
5
  "type": "module",
6
6
  "exports": {
@@ -19,17 +19,18 @@
19
19
  "build": "rollup -c",
20
20
  "clean:build": "rm -rf dist",
21
21
  "prepublishOnly": "npm run clean:build && npm run build",
22
- "test": "jest"
22
+ "test": "jest",
23
+ "publish:npm": "npm publish"
23
24
  },
24
25
  "dependencies": {
25
- "@babel/runtime": "^7.25.0",
26
+ "@babel/runtime": "^7.25.4",
26
27
  "react-is": "^18.3.1",
27
28
  "rxjs": "^7.8.1"
28
29
  },
29
30
  "devDependencies": {
30
31
  "@babel/core": "^7.25.2",
31
- "@babel/plugin-transform-runtime": "^7.24.7",
32
- "@babel/preset-env": "^7.25.3",
32
+ "@babel/plugin-transform-runtime": "^7.25.4",
33
+ "@babel/preset-env": "^7.25.4",
33
34
  "@babel/preset-react": "^7.24.7",
34
35
  "@babel/preset-typescript": "^7.24.7",
35
36
  "@jest/globals": "^29.7.0",
@@ -37,14 +38,14 @@
37
38
  "@rollup/plugin-node-resolve": "^15.2.3",
38
39
  "@rollup/plugin-typescript": "^11.1.6",
39
40
  "@testing-library/react": "^16.0.0",
40
- "@types/react": "^18.3.3",
41
+ "@types/react": "^18.3.4",
41
42
  "@types/react-dom": "^18.3.0",
42
43
  "@types/react-is": "^18.3.0",
43
44
  "jest": "^29.7.0",
44
45
  "jest-environment-jsdom": "^29.7.0",
45
46
  "react": "^18.3.1",
46
47
  "react-dom": "^18.3.1",
47
- "rollup": "^4.20.0",
48
+ "rollup": "^4.21.0",
48
49
  "typescript": "5.5.4"
49
50
  },
50
51
  "peerDependencies": {