@aiszlab/relax 1.3.13 → 1.3.15
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-refs.cjs +8 -23
- package/dist/hooks/use-refs.d.ts +2 -4
- package/dist/hooks/use-refs.mjs +8 -23
- package/dist/index.cjs +4 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +2 -0
- package/dist/react/index.cjs +9 -0
- package/dist/react/index.d.ts +4 -0
- package/dist/react/index.mjs +2 -0
- package/dist/react/is-class-component.cjs +7 -0
- package/dist/react/is-class-component.d.ts +1 -0
- package/dist/react/is-class-component.mjs +5 -0
- package/dist/react/mount-ref.cjs +19 -0
- package/dist/react/mount-ref.d.ts +3 -0
- package/dist/react/mount-ref.mjs +17 -0
- package/dist/types/first.d.ts +1 -1
- package/dist/types/last.d.ts +1 -1
- package/dist/utils/first.cjs +13 -0
- package/dist/utils/first.d.ts +6 -0
- package/dist/utils/first.mjs +11 -0
- package/dist/utils/last.cjs +13 -0
- package/dist/utils/last.d.ts +6 -0
- package/dist/utils/last.mjs +11 -0
- package/package.json +8 -1
package/dist/hooks/use-refs.cjs
CHANGED
|
@@ -1,33 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var mountRef = require('../react/mount-ref.cjs');
|
|
4
|
+
var useEvent = require('./use-event.cjs');
|
|
5
5
|
|
|
6
|
-
var mount = function mount(ref, trigger) {
|
|
7
|
-
if (isFunction.isFunction(ref)) {
|
|
8
|
-
ref(trigger);
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
// in deprecated react, class component can use string ref
|
|
12
|
-
// but there are many problems, in relax, we just make it not work
|
|
13
|
-
// issue for react: https://github.com/facebook/react/pull/8333#issuecomment-271648615
|
|
14
|
-
if (typeof ref === "string") {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
ref.current = trigger;
|
|
18
|
-
};
|
|
19
6
|
var useRefs = function useRefs() {
|
|
20
7
|
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
21
8
|
refs[_key] = arguments[_key];
|
|
22
9
|
}
|
|
23
|
-
return
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
}, refs);
|
|
10
|
+
return useEvent.useEvent(function (_reference) {
|
|
11
|
+
refs.forEach(function (ref) {
|
|
12
|
+
if (!ref) return;
|
|
13
|
+
mountRef.mountRef(ref, _reference);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
31
16
|
};
|
|
32
17
|
|
|
33
18
|
exports.useRefs = useRefs;
|
package/dist/hooks/use-refs.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { type MutableRefObject, type RefCallback } from "react";
|
|
2
1
|
import type { Nullable, Voidable } from "@aiszlab/relax/types";
|
|
3
|
-
type Refable
|
|
4
|
-
export declare const useRefs: <T>(...refs: Voidable<Refable<Nullable<T>>>[]) => (
|
|
5
|
-
export {};
|
|
2
|
+
import { type Refable } from "@aiszlab/relax/react";
|
|
3
|
+
export declare const useRefs: <T>(...refs: Voidable<Refable<Nullable<T>>>[]) => (_reference: T) => void;
|
package/dist/hooks/use-refs.mjs
CHANGED
|
@@ -1,31 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { mountRef } from '../react/mount-ref.mjs';
|
|
2
|
+
import { useEvent } from './use-event.mjs';
|
|
3
3
|
|
|
4
|
-
var mount = function mount(ref, trigger) {
|
|
5
|
-
if (isFunction(ref)) {
|
|
6
|
-
ref(trigger);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
// in deprecated react, class component can use string ref
|
|
10
|
-
// but there are many problems, in relax, we just make it not work
|
|
11
|
-
// issue for react: https://github.com/facebook/react/pull/8333#issuecomment-271648615
|
|
12
|
-
if (typeof ref === "string") {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
ref.current = trigger;
|
|
16
|
-
};
|
|
17
4
|
var useRefs = function useRefs() {
|
|
18
5
|
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
19
6
|
refs[_key] = arguments[_key];
|
|
20
7
|
}
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
}, refs);
|
|
8
|
+
return useEvent(function (_reference) {
|
|
9
|
+
refs.forEach(function (ref) {
|
|
10
|
+
if (!ref) return;
|
|
11
|
+
mountRef(ref, _reference);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
29
14
|
};
|
|
30
15
|
|
|
31
16
|
export { useRefs };
|
package/dist/index.cjs
CHANGED
|
@@ -65,6 +65,8 @@ var toggle = require('./utils/toggle.cjs');
|
|
|
65
65
|
var taggedTemplateLiterals = require('./utils/tagged-template-literals.cjs');
|
|
66
66
|
var replace = require('./utils/replace.cjs');
|
|
67
67
|
var clsx = require('./utils/clsx.cjs');
|
|
68
|
+
var first = require('./utils/first.cjs');
|
|
69
|
+
var last = require('./utils/last.cjs');
|
|
68
70
|
|
|
69
71
|
|
|
70
72
|
|
|
@@ -134,3 +136,5 @@ exports.toggle = toggle.toggle;
|
|
|
134
136
|
exports.taggedTemplateLiterals = taggedTemplateLiterals.taggedTemplateLiterals;
|
|
135
137
|
exports.replace = replace.replace;
|
|
136
138
|
exports.clsx = clsx.clsx;
|
|
139
|
+
exports.first = first.first;
|
|
140
|
+
exports.last = last.last;
|
package/dist/index.d.ts
CHANGED
|
@@ -75,3 +75,5 @@ export { toggle } from "./utils/toggle";
|
|
|
75
75
|
export { taggedTemplateLiterals } from "./utils/tagged-template-literals";
|
|
76
76
|
export { replace } from "./utils/replace";
|
|
77
77
|
export { clsx } from "./utils/clsx";
|
|
78
|
+
export { first } from "./utils/first";
|
|
79
|
+
export { last } from "./utils/last";
|
package/dist/index.mjs
CHANGED
|
@@ -63,3 +63,5 @@ export { toggle } from './utils/toggle.mjs';
|
|
|
63
63
|
export { taggedTemplateLiterals } from './utils/tagged-template-literals.mjs';
|
|
64
64
|
export { replace } from './utils/replace.mjs';
|
|
65
65
|
export { clsx } from './utils/clsx.mjs';
|
|
66
|
+
export { first } from './utils/first.mjs';
|
|
67
|
+
export { last } from './utils/last.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isClassComponent: () => boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var isFunction = require('../is/is-function.cjs');
|
|
4
|
+
|
|
5
|
+
var mountRef = function mountRef(ref, trigger) {
|
|
6
|
+
if (isFunction.isFunction(ref)) {
|
|
7
|
+
ref(trigger);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
// in deprecated react, class component can use string ref
|
|
11
|
+
// but there are many problems, in relax, we just make it not work
|
|
12
|
+
// issue for react: https://github.com/facebook/react/pull/8333#issuecomment-271648615
|
|
13
|
+
if (typeof ref === "string") {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
ref.current = trigger;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.mountRef = mountRef;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isFunction } from '../is/is-function.mjs';
|
|
2
|
+
|
|
3
|
+
var mountRef = function mountRef(ref, trigger) {
|
|
4
|
+
if (isFunction(ref)) {
|
|
5
|
+
ref(trigger);
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
// in deprecated react, class component can use string ref
|
|
9
|
+
// but there are many problems, in relax, we just make it not work
|
|
10
|
+
// issue for react: https://github.com/facebook/react/pull/8333#issuecomment-271648615
|
|
11
|
+
if (typeof ref === "string") {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
ref.current = trigger;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { mountRef };
|
package/dist/types/first.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type First<T> = T extends [infer D, ...Array<unknown>] ? D :
|
|
1
|
+
export type First<T, R = undefined> = T extends [infer D, ...Array<unknown>] ? D : R;
|
package/dist/types/last.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type Last<T> = T extends [...Array<unknown>, infer D] ? D :
|
|
1
|
+
export type Last<T, R = undefined> = T extends [...Array<unknown>, infer D] ? D : R;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiszlab/relax",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.15",
|
|
4
4
|
"description": "react utils collection",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -17,6 +17,13 @@
|
|
|
17
17
|
"import": "./dist/dom/index.mjs",
|
|
18
18
|
"default": "./dist/dom/index.mjs"
|
|
19
19
|
},
|
|
20
|
+
"./react": {
|
|
21
|
+
"types": "./dist/react/index.d.ts",
|
|
22
|
+
"node": "./dist/react/index.cjs",
|
|
23
|
+
"require": "./dist/react/index.cjs",
|
|
24
|
+
"import": "./dist/react/index.mjs",
|
|
25
|
+
"default": "./dist/react/index.mjs"
|
|
26
|
+
},
|
|
20
27
|
"./types": "./dist/types/index.d.ts"
|
|
21
28
|
},
|
|
22
29
|
"scripts": {
|