@aiszlab/relax 1.5.12 → 2.0.0

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,2 +1,2 @@
1
1
  import { type UsingDrag } from "./use-drag";
2
- export declare const useDraggable: <T extends HTMLElement = HTMLElement>(using?: UsingDrag) => readonly [import("react").RefObject<T>, import("./use-drag").DragState];
2
+ export declare const useDraggable: <T extends HTMLElement = HTMLElement>(using?: UsingDrag) => readonly [import("react").RefObject<T | null>, import("./use-drag").DragState];
@@ -8,7 +8,7 @@ var useMounted = require('./use-mounted.cjs');
8
8
  * fetch event source
9
9
  */
10
10
  var useEventSource = function useEventSource(url) {
11
- var eventSourceRef = react.useRef();
11
+ var eventSourceRef = react.useRef(null);
12
12
  useMounted.useMounted(function () {
13
13
  var _eventSource = eventSourceRef.current = new EventSource(url);
14
14
  return function () {
@@ -6,7 +6,7 @@ import { useMounted } from './use-mounted.mjs';
6
6
  * fetch event source
7
7
  */
8
8
  var useEventSource = function useEventSource(url) {
9
- var eventSourceRef = useRef();
9
+ var eventSourceRef = useRef(null);
10
10
  useMounted(function () {
11
11
  var _eventSource = eventSourceRef.current = new EventSource(url);
12
12
  return function () {
@@ -15,7 +15,7 @@ var useImageLoader = function useImageLoader(_ref) {
15
15
  crossOrigin = _ref.crossOrigin,
16
16
  _ref$referrerPolicy = _ref.referrerPolicy,
17
17
  referrerPolicy = _ref$referrerPolicy === void 0 ? "no-referrer" : _ref$referrerPolicy;
18
- var loader = react.useRef();
18
+ var loader = react.useRef(null);
19
19
  var _useState = react.useState("none"),
20
20
  _useState2 = _slicedToArray(_useState, 2),
21
21
  status = _useState2[0],
@@ -13,7 +13,7 @@ var useImageLoader = function useImageLoader(_ref) {
13
13
  crossOrigin = _ref.crossOrigin,
14
14
  _ref$referrerPolicy = _ref.referrerPolicy,
15
15
  referrerPolicy = _ref$referrerPolicy === void 0 ? "no-referrer" : _ref$referrerPolicy;
16
- var loader = useRef();
16
+ var loader = useRef(null);
17
17
  var _useState = useState("none"),
18
18
  _useState2 = _slicedToArray(_useState, 2),
19
19
  status = _useState2[0],
@@ -1,4 +1,5 @@
1
1
  import { type RefObject } from "react";
2
+ import type { Nullable } from "../types";
2
3
  type UsingInfiniteScroll = {
3
4
  /**
4
5
  * @description
@@ -16,7 +17,10 @@ type UsingInfiniteScroll = {
16
17
  */
17
18
  onLoadMore?: () => void;
18
19
  };
19
- type UsedInfiniteScroll<S, V> = [sentinelRef: RefObject<S>, viewportRef: RefObject<V>];
20
+ type UsedInfiniteScroll<S, V> = [
21
+ sentinelRef: RefObject<Nullable<S>>,
22
+ viewportRef: RefObject<Nullable<V>>
23
+ ];
20
24
  /**
21
25
  * @description
22
26
  * use infinite scroll
@@ -4,7 +4,7 @@
4
4
  * provider with\height to child
5
5
  */
6
6
  export declare const useParentSize: <T extends HTMLElement = HTMLDivElement>() => {
7
- parentRef: import("react").RefObject<T>;
7
+ parentRef: import("react").RefObject<T | null>;
8
8
  width: number;
9
9
  height: number;
10
10
  };
@@ -8,8 +8,8 @@ interface UseScrollableProps {
8
8
  * scrollable hook
9
9
  */
10
10
  export declare const useScrollable: <P extends HTMLElement, C extends HTMLElement>({ orientation, }?: UseScrollableProps) => {
11
- targetRef: import("react").RefObject<P>;
12
- triggerRefs: import("react").MutableRefObject<Map<Key, C | null>>;
11
+ targetRef: import("react").RefObject<P | null>;
12
+ triggerRefs: import("react").RefObject<Map<Key, C | null>>;
13
13
  scrollTo: (to: number, duration?: number) => void;
14
14
  to: (key: Key) => number;
15
15
  setTrigger: (key: Key, trigger: C) => void;
@@ -1,5 +1,5 @@
1
1
  import { useRef, useEffect } from 'react';
2
- import { Observable, timer } from 'rxjs';
2
+ import { timer, Observable } from 'rxjs';
3
3
  import { useEvent } from './use-event.mjs';
4
4
  import { useMounted } from './use-mounted.mjs';
5
5
 
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ var isString = require('../is/is-string.cjs');
4
+
5
+ function at(value, pos) {
6
+ if (isString.isString(value)) {
7
+ return value.at(pos);
8
+ }
9
+ // check can i use `at`
10
+ if (!!Array.prototype.at) {
11
+ return value.at(pos);
12
+ }
13
+ return value[pos];
14
+ }
15
+
16
+ exports.at = at;
@@ -0,0 +1,7 @@
1
+ import type { Partialable } from "../types";
2
+ /**
3
+ * @description for different browser or browser version, use good api to cover
4
+ */
5
+ declare function at(value: string, pos: number): string;
6
+ declare function at<T>(value: Array<T>, pos: number): Partialable<T>;
7
+ export { at };
@@ -0,0 +1,14 @@
1
+ import { isString } from '../is/is-string.mjs';
2
+
3
+ function at(value, pos) {
4
+ if (isString(value)) {
5
+ return value.at(pos);
6
+ }
7
+ // check can i use `at`
8
+ if (!!Array.prototype.at) {
9
+ return value.at(pos);
10
+ }
11
+ return value[pos];
12
+ }
13
+
14
+ export { at };
@@ -1,15 +1,18 @@
1
1
  'use strict';
2
2
 
3
3
  var toArray = require('./to-array.cjs');
4
+ var at = require('./at.cjs');
5
+ var isString = require('../is/is-string.cjs');
4
6
 
5
7
  /**
6
8
  * @description
7
9
  * first element of array
8
10
  */
9
11
  var first = function first(value) {
10
- return toArray.toArray(value, {
11
- separator: ""
12
- }).at(0);
12
+ if (isString.isString(value)) {
13
+ return value.at(0);
14
+ }
15
+ return at.at(toArray.toArray(value), 0);
13
16
  };
14
17
 
15
18
  exports.first = first;
@@ -1,13 +1,16 @@
1
1
  import { toArray } from './to-array.mjs';
2
+ import { at } from './at.mjs';
3
+ import { isString } from '../is/is-string.mjs';
2
4
 
3
5
  /**
4
6
  * @description
5
7
  * first element of array
6
8
  */
7
9
  var first = function first(value) {
8
- return toArray(value, {
9
- separator: ""
10
- }).at(0);
10
+ if (isString(value)) {
11
+ return value.at(0);
12
+ }
13
+ return at(toArray(value), 0);
11
14
  };
12
15
 
13
16
  export { first };
@@ -1,15 +1,18 @@
1
1
  'use strict';
2
2
 
3
3
  var toArray = require('./to-array.cjs');
4
+ var isString = require('../is/is-string.cjs');
5
+ var at = require('./at.cjs');
4
6
 
5
7
  /**
6
8
  * @description
7
9
  * last element of array
8
10
  */
9
11
  var last = function last(value) {
10
- return toArray.toArray(value, {
11
- separator: ""
12
- }).at(-1);
12
+ if (isString.isString(value)) {
13
+ return value.at(-1);
14
+ }
15
+ return at.at(toArray.toArray(value), -1);
13
16
  };
14
17
 
15
18
  exports.last = last;
@@ -1,13 +1,16 @@
1
1
  import { toArray } from './to-array.mjs';
2
+ import { isString } from '../is/is-string.mjs';
3
+ import { at } from './at.mjs';
2
4
 
3
5
  /**
4
6
  * @description
5
7
  * last element of array
6
8
  */
7
9
  var last = function last(value) {
8
- return toArray(value, {
9
- separator: ""
10
- }).at(-1);
10
+ if (isString(value)) {
11
+ return value.at(-1);
12
+ }
13
+ return at(toArray(value), -1);
11
14
  };
12
15
 
13
16
  export { last };
@@ -1,27 +1,21 @@
1
1
  'use strict';
2
2
 
3
- var _typeof = require('@babel/runtime/helpers/typeof');
4
- var isVoid = require('../is/is-void.cjs');
3
+ var isString = require('../is/is-string.cjs');
4
+ var isUndefined = require('../is/is-undefined.cjs');
5
5
 
6
- /**
7
- * @description
8
- * convert any type data to a array
9
- */
10
- var toArray = function toArray(value) {
11
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
12
- separator = _ref.separator;
6
+ function toArray(value, splitter) {
7
+ // string branch
8
+ if (isString.isString(value)) {
9
+ if (isUndefined.isUndefined(splitter)) {
10
+ return [value];
11
+ }
12
+ return value.split(splitter);
13
+ }
14
+ // array branch
13
15
  if (Array.isArray(value)) {
14
16
  return value;
15
17
  }
16
- switch (_typeof(value)) {
17
- case "string":
18
- if (isVoid.isVoid(separator)) {
19
- return [value];
20
- }
21
- return value.split(separator);
22
- default:
23
- return [value];
24
- }
25
- };
18
+ return [value];
19
+ }
26
20
 
27
21
  exports.toArray = toArray;
@@ -1,18 +1,8 @@
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
- };
1
+ type Splitter = string | RegExp;
13
2
  /**
14
3
  * @description
15
4
  * convert any type data to a array
16
5
  */
17
- export declare const toArray: <T extends unknown = unknown>(value: T | Array<T>, { separator }?: Options) => Array<T>;
18
- export {};
6
+ declare function toArray(value: string, splitter?: Splitter): string[];
7
+ declare function toArray<T = unknown>(value: T): T extends Array<unknown> ? T : T[];
8
+ export { toArray };
@@ -1,25 +1,19 @@
1
- import _typeof from '@babel/runtime/helpers/typeof';
2
- import { isVoid } from '../is/is-void.mjs';
1
+ import { isString } from '../is/is-string.mjs';
2
+ import { isUndefined } from '../is/is-undefined.mjs';
3
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;
4
+ function toArray(value, splitter) {
5
+ // string branch
6
+ if (isString(value)) {
7
+ if (isUndefined(splitter)) {
8
+ return [value];
9
+ }
10
+ return value.split(splitter);
11
+ }
12
+ // array branch
11
13
  if (Array.isArray(value)) {
12
14
  return value;
13
15
  }
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
- };
16
+ return [value];
17
+ }
24
18
 
25
19
  export { toArray };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.5.12",
3
+ "version": "2.0.0",
4
4
  "description": "react utils collection",
5
5
  "exports": {
6
6
  ".": {
@@ -29,30 +29,30 @@
29
29
  "publish:npm": "npm publish"
30
30
  },
31
31
  "dependencies": {
32
- "@babel/runtime": "^7.26.0",
33
- "react-is": "^18.3.1",
32
+ "@babel/runtime": "^7.26.9",
33
+ "react-is": "^19.0.0",
34
34
  "rxjs": "^7.8.1"
35
35
  },
36
36
  "devDependencies": {
37
- "@babel/core": "^7.26.0",
38
- "@babel/plugin-transform-runtime": "^7.25.9",
39
- "@babel/preset-env": "^7.26.0",
40
- "@babel/preset-react": "^7.25.9",
37
+ "@babel/core": "^7.26.9",
38
+ "@babel/plugin-transform-runtime": "^7.26.9",
39
+ "@babel/preset-env": "^7.26.9",
40
+ "@babel/preset-react": "^7.26.3",
41
41
  "@babel/preset-typescript": "^7.26.0",
42
42
  "@jest/globals": "^29.7.0",
43
43
  "@rollup/plugin-babel": "^6.0.4",
44
- "@rollup/plugin-node-resolve": "^15.3.0",
45
- "@rollup/plugin-typescript": "^12.1.1",
46
- "@testing-library/react": "^16.1.0",
44
+ "@rollup/plugin-node-resolve": "^16.0.0",
45
+ "@rollup/plugin-typescript": "^12.1.2",
46
+ "@testing-library/react": "^16.2.0",
47
47
  "@types/babel__core": "^7.20.5",
48
- "@types/react": "^18.3.12",
49
- "@types/react-dom": "^18.3.1",
50
- "@types/react-is": "^18.3.0",
48
+ "@types/react": "^19.0.10",
49
+ "@types/react-dom": "^19.0.4",
50
+ "@types/react-is": "^19.0.0",
51
51
  "jest": "^29.7.0",
52
52
  "jest-environment-jsdom": "^29.7.0",
53
- "react": "^18.3.1",
54
- "react-dom": "^18.3.1",
55
- "rollup": "^4.28.1",
53
+ "react": "^19.0.0",
54
+ "react-dom": "^19.0.0",
55
+ "rollup": "^4.34.8",
56
56
  "typescript": "5.7.3"
57
57
  },
58
58
  "peerDependencies": {