@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.
- package/dist/hooks/use-draggable.d.ts +1 -1
- package/dist/hooks/use-event-source.cjs +1 -1
- package/dist/hooks/use-event-source.mjs +1 -1
- package/dist/hooks/use-image-loader.cjs +1 -1
- package/dist/hooks/use-image-loader.mjs +1 -1
- package/dist/hooks/use-infinite-scroll.d.ts +5 -1
- package/dist/hooks/use-parent-size.d.ts +1 -1
- package/dist/hooks/use-scrollable.d.ts +2 -2
- package/dist/hooks/use-timeout.mjs +1 -1
- package/dist/utils/at.cjs +16 -0
- package/dist/utils/at.d.ts +7 -0
- package/dist/utils/at.mjs +14 -0
- package/dist/utils/first.cjs +6 -3
- package/dist/utils/first.mjs +6 -3
- package/dist/utils/last.cjs +6 -3
- package/dist/utils/last.mjs +6 -3
- package/dist/utils/to-array.cjs +13 -19
- package/dist/utils/to-array.d.ts +4 -14
- package/dist/utils/to-array.mjs +13 -19
- package/package.json +16 -16
|
@@ -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> = [
|
|
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
|
|
@@ -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").
|
|
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;
|
|
@@ -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 };
|
package/dist/utils/first.cjs
CHANGED
|
@@ -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
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
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;
|
package/dist/utils/first.mjs
CHANGED
|
@@ -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
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
10
|
+
if (isString(value)) {
|
|
11
|
+
return value.at(0);
|
|
12
|
+
}
|
|
13
|
+
return at(toArray(value), 0);
|
|
11
14
|
};
|
|
12
15
|
|
|
13
16
|
export { first };
|
package/dist/utils/last.cjs
CHANGED
|
@@ -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
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
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;
|
package/dist/utils/last.mjs
CHANGED
|
@@ -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
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
10
|
+
if (isString(value)) {
|
|
11
|
+
return value.at(-1);
|
|
12
|
+
}
|
|
13
|
+
return at(toArray(value), -1);
|
|
11
14
|
};
|
|
12
15
|
|
|
13
16
|
export { last };
|
package/dist/utils/to-array.cjs
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var isString = require('../is/is-string.cjs');
|
|
4
|
+
var isUndefined = require('../is/is-undefined.cjs');
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
17
|
-
|
|
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;
|
package/dist/utils/to-array.d.ts
CHANGED
|
@@ -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
|
-
|
|
18
|
-
|
|
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 };
|
package/dist/utils/to-array.mjs
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { isString } from '../is/is-string.mjs';
|
|
2
|
+
import { isUndefined } from '../is/is-undefined.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
15
|
-
|
|
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": "
|
|
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.
|
|
33
|
-
"react-is": "^
|
|
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.
|
|
38
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
39
|
-
"@babel/preset-env": "^7.26.
|
|
40
|
-
"@babel/preset-react": "^7.
|
|
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": "^
|
|
45
|
-
"@rollup/plugin-typescript": "^12.1.
|
|
46
|
-
"@testing-library/react": "^16.
|
|
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": "^
|
|
49
|
-
"@types/react-dom": "^
|
|
50
|
-
"@types/react-is": "^
|
|
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": "^
|
|
54
|
-
"react-dom": "^
|
|
55
|
-
"rollup": "^4.
|
|
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": {
|