@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.
@@ -1,33 +1,18 @@
1
1
  'use strict';
2
2
 
3
- var react = require('react');
4
- var isFunction = require('../is/is-function.cjs');
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 react.useMemo(function () {
24
- return function (trigger) {
25
- refs.forEach(function (ref) {
26
- if (!ref) return;
27
- mount(ref, trigger);
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;
@@ -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<T> = RefCallback<T> | MutableRefObject<T> | string;
4
- export declare const useRefs: <T>(...refs: Voidable<Refable<Nullable<T>>>[]) => (trigger: T) => void;
5
- export {};
2
+ import { type Refable } from "@aiszlab/relax/react";
3
+ export declare const useRefs: <T>(...refs: Voidable<Refable<Nullable<T>>>[]) => (_reference: T) => void;
@@ -1,31 +1,16 @@
1
- import { useMemo } from 'react';
2
- import { isFunction } from '../is/is-function.mjs';
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 useMemo(function () {
22
- return function (trigger) {
23
- refs.forEach(function (ref) {
24
- if (!ref) return;
25
- mount(ref, trigger);
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,9 @@
1
+ 'use strict';
2
+
3
+ var mountRef = require('./mount-ref.cjs');
4
+ var isClassComponent = require('./is-class-component.cjs');
5
+
6
+
7
+
8
+ exports.mountRef = mountRef.mountRef;
9
+ exports.isClassComponent = isClassComponent.isClassComponent;
@@ -0,0 +1,4 @@
1
+ import { mountRef, type Refable } from "./mount-ref";
2
+ import { isClassComponent } from "./is-class-component";
3
+ export { mountRef, isClassComponent };
4
+ export type { Refable };
@@ -0,0 +1,2 @@
1
+ export { mountRef } from './mount-ref.mjs';
2
+ export { isClassComponent } from './is-class-component.mjs';
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ var isClassComponent = function isClassComponent() {
4
+ return false;
5
+ };
6
+
7
+ exports.isClassComponent = isClassComponent;
@@ -0,0 +1 @@
1
+ export declare const isClassComponent: () => boolean;
@@ -0,0 +1,5 @@
1
+ var isClassComponent = function isClassComponent() {
2
+ return false;
3
+ };
4
+
5
+ export { isClassComponent };
@@ -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,3 @@
1
+ import type { MutableRefObject, RefCallback } from "react";
2
+ export type Refable<T> = RefCallback<T> | MutableRefObject<T> | string;
3
+ export declare const mountRef: <T>(ref: Refable<T>, trigger: T) => void;
@@ -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 };
@@ -1 +1 @@
1
- export type First<T> = T extends [infer D, ...Array<unknown>] ? D : undefined;
1
+ export type First<T, R = undefined> = T extends [infer D, ...Array<unknown>] ? D : R;
@@ -1 +1 @@
1
- export type Last<T> = T extends [...Array<unknown>, infer D] ? D : undefined;
1
+ export type Last<T, R = undefined> = T extends [...Array<unknown>, infer D] ? D : R;
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var toArray = require('./to-array.cjs');
4
+
5
+ /**
6
+ * @description
7
+ * first element of array
8
+ */
9
+ var first = function first(value) {
10
+ return toArray.toArray(value).at(0);
11
+ };
12
+
13
+ exports.first = first;
@@ -0,0 +1,6 @@
1
+ import { type First } from "../types";
2
+ /**
3
+ * @description
4
+ * first element of array
5
+ */
6
+ export declare const first: <T = unknown>(value: T) => First<T, T>;
@@ -0,0 +1,11 @@
1
+ import { toArray } from './to-array.mjs';
2
+
3
+ /**
4
+ * @description
5
+ * first element of array
6
+ */
7
+ var first = function first(value) {
8
+ return toArray(value).at(0);
9
+ };
10
+
11
+ export { first };
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var toArray = require('./to-array.cjs');
4
+
5
+ /**
6
+ * @description
7
+ * last element of array
8
+ */
9
+ var last = function last(value) {
10
+ return toArray.toArray(value).at(-1);
11
+ };
12
+
13
+ exports.last = last;
@@ -0,0 +1,6 @@
1
+ import { type Last } from "../types";
2
+ /**
3
+ * @description
4
+ * last element of array
5
+ */
6
+ export declare const last: <T = unknown>(value: T) => Last<T, T>;
@@ -0,0 +1,11 @@
1
+ import { toArray } from './to-array.mjs';
2
+
3
+ /**
4
+ * @description
5
+ * last element of array
6
+ */
7
+ var last = function last(value) {
8
+ return toArray(value).at(-1);
9
+ };
10
+
11
+ export { last };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.3.13",
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": {