@aiszlab/relax 2.0.6-beta.3 → 2.0.6-beta.5
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/LICENSE +21 -21
- package/README.md +4 -4
- package/dist/dom/clipboard.cjs +4 -4
- package/dist/dom/clipboard.mjs +4 -4
- package/dist/fetch-event-source/fetch.cjs +18 -18
- package/dist/fetch-event-source/fetch.mjs +18 -18
- package/dist/fetch-event-source/parse.cjs +9 -9
- package/dist/fetch-event-source/parse.mjs +9 -9
- package/dist/hooks/use-counter.cjs +12 -11
- package/dist/hooks/use-counter.mjs +12 -11
- package/dist/hooks/use-parent-size.cjs +3 -1
- package/dist/hooks/use-parent-size.mjs +3 -1
- package/dist/hooks/use-screen-size.cjs +6 -4
- package/dist/hooks/use-screen-size.mjs +6 -4
- package/dist/types/at.d.ts +2 -2
- package/dist/types/first.d.ts +1 -1
- package/dist/types/last.d.ts +1 -1
- package/dist/utils/at.d.ts +1 -1
- package/dist/utils/first.d.ts +2 -2
- package/dist/utils/last.d.ts +2 -2
- package/package.json +10 -11
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 aiszlab
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 aiszlab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
# relax
|
|
2
|
-
favorite and easy hooks for react
|
|
3
|
-
|
|
4
|
-
## i alaways like writting many hooks for mine project
|
|
1
|
+
# relax
|
|
2
|
+
favorite and easy hooks for react
|
|
3
|
+
|
|
4
|
+
## i alaways like writting many hooks for mine project
|
|
5
5
|
## so i need a hooks project to support me
|
package/dist/dom/clipboard.cjs
CHANGED
|
@@ -5,14 +5,14 @@ var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
|
5
5
|
|
|
6
6
|
var clipboard = /*#__PURE__*/function () {
|
|
7
7
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(value) {
|
|
8
|
-
return _regeneratorRuntime().wrap(function
|
|
8
|
+
return _regeneratorRuntime().wrap(function (_context) {
|
|
9
9
|
while (1) switch (_context.prev = _context.next) {
|
|
10
10
|
case 0:
|
|
11
|
-
_context.next =
|
|
11
|
+
_context.next = 1;
|
|
12
12
|
return navigator.clipboard.writeText(value);
|
|
13
|
-
case
|
|
13
|
+
case 1:
|
|
14
14
|
return _context.abrupt("return", _context.sent);
|
|
15
|
-
case
|
|
15
|
+
case 2:
|
|
16
16
|
case "end":
|
|
17
17
|
return _context.stop();
|
|
18
18
|
}
|
package/dist/dom/clipboard.mjs
CHANGED
|
@@ -3,14 +3,14 @@ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
|
3
3
|
|
|
4
4
|
var clipboard = /*#__PURE__*/function () {
|
|
5
5
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(value) {
|
|
6
|
-
return _regeneratorRuntime().wrap(function
|
|
6
|
+
return _regeneratorRuntime().wrap(function (_context) {
|
|
7
7
|
while (1) switch (_context.prev = _context.next) {
|
|
8
8
|
case 0:
|
|
9
|
-
_context.next =
|
|
9
|
+
_context.next = 1;
|
|
10
10
|
return navigator.clipboard.writeText(value);
|
|
11
|
-
case
|
|
11
|
+
case 1:
|
|
12
12
|
return _context.abrupt("return", _context.sent);
|
|
13
|
-
case
|
|
13
|
+
case 2:
|
|
14
14
|
case "end":
|
|
15
15
|
return _context.stop();
|
|
16
16
|
}
|
|
@@ -53,23 +53,23 @@ function fetchEventSource(input, _ref) {
|
|
|
53
53
|
}
|
|
54
54
|
function _create() {
|
|
55
55
|
_create = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
56
|
-
var response, _onerror, interval;
|
|
57
|
-
return _regeneratorRuntime().wrap(function
|
|
56
|
+
var response, _onerror, interval, _t;
|
|
57
|
+
return _regeneratorRuntime().wrap(function (_context) {
|
|
58
58
|
while (1) switch (_context.prev = _context.next) {
|
|
59
59
|
case 0:
|
|
60
60
|
curRequestController = new AbortController();
|
|
61
61
|
_context.prev = 1;
|
|
62
|
-
_context.next =
|
|
62
|
+
_context.next = 2;
|
|
63
63
|
return fetch(input, _objectSpread(_objectSpread({}, rest), {}, {
|
|
64
64
|
headers: headers,
|
|
65
65
|
signal: curRequestController.signal
|
|
66
66
|
}));
|
|
67
|
-
case
|
|
67
|
+
case 2:
|
|
68
68
|
response = _context.sent;
|
|
69
|
-
_context.next =
|
|
69
|
+
_context.next = 3;
|
|
70
70
|
return onopen(response);
|
|
71
|
-
case
|
|
72
|
-
_context.next =
|
|
71
|
+
case 3:
|
|
72
|
+
_context.next = 4;
|
|
73
73
|
return parse.getBytes(response.body, parse.getLines(parse.getMessages(function (id) {
|
|
74
74
|
if (id) {
|
|
75
75
|
// store the id and send it back on the next retry:
|
|
@@ -81,20 +81,20 @@ function fetchEventSource(input, _ref) {
|
|
|
81
81
|
}, function (retry) {
|
|
82
82
|
retryInterval = retry;
|
|
83
83
|
}, onmessage)));
|
|
84
|
-
case
|
|
84
|
+
case 4:
|
|
85
85
|
onclose === null || onclose === void 0 || onclose();
|
|
86
86
|
dispose();
|
|
87
87
|
resolve();
|
|
88
|
-
_context.next =
|
|
88
|
+
_context.next = 6;
|
|
89
89
|
break;
|
|
90
|
-
case
|
|
91
|
-
_context.prev =
|
|
92
|
-
|
|
90
|
+
case 5:
|
|
91
|
+
_context.prev = 5;
|
|
92
|
+
_t = _context["catch"](1);
|
|
93
93
|
if (!curRequestController.signal.aborted) {
|
|
94
94
|
// if we haven't aborted the request ourselves:
|
|
95
95
|
try {
|
|
96
96
|
// check if we need to retry:
|
|
97
|
-
interval = (_onerror = onerror === null || onerror === void 0 ? void 0 : onerror(
|
|
97
|
+
interval = (_onerror = onerror === null || onerror === void 0 ? void 0 : onerror(_t)) !== null && _onerror !== void 0 ? _onerror : retryInterval;
|
|
98
98
|
window.clearTimeout(retryTimer);
|
|
99
99
|
retryTimer = window.setTimeout(create, interval);
|
|
100
100
|
} catch (innerErr) {
|
|
@@ -103,11 +103,11 @@ function fetchEventSource(input, _ref) {
|
|
|
103
103
|
reject(innerErr);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
case
|
|
106
|
+
case 6:
|
|
107
107
|
case "end":
|
|
108
108
|
return _context.stop();
|
|
109
109
|
}
|
|
110
|
-
}, _callee, null, [[1,
|
|
110
|
+
}, _callee, null, [[1, 5]]);
|
|
111
111
|
}));
|
|
112
112
|
return _create.apply(this, arguments);
|
|
113
113
|
}
|
|
@@ -120,16 +120,16 @@ function defaultOnOpen(_x) {
|
|
|
120
120
|
function _defaultOnOpen() {
|
|
121
121
|
_defaultOnOpen = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(response) {
|
|
122
122
|
var contentType;
|
|
123
|
-
return _regeneratorRuntime().wrap(function
|
|
123
|
+
return _regeneratorRuntime().wrap(function (_context2) {
|
|
124
124
|
while (1) switch (_context2.prev = _context2.next) {
|
|
125
125
|
case 0:
|
|
126
126
|
contentType = response.headers.get("content-type");
|
|
127
127
|
if (contentType !== null && contentType !== void 0 && contentType.startsWith(EventStreamContentType)) {
|
|
128
|
-
_context2.next =
|
|
128
|
+
_context2.next = 1;
|
|
129
129
|
break;
|
|
130
130
|
}
|
|
131
131
|
throw new Error("Expected content-type to be ".concat(EventStreamContentType, ", Actual: ").concat(contentType));
|
|
132
|
-
case
|
|
132
|
+
case 1:
|
|
133
133
|
case "end":
|
|
134
134
|
return _context2.stop();
|
|
135
135
|
}
|
|
@@ -51,23 +51,23 @@ function fetchEventSource(input, _ref) {
|
|
|
51
51
|
}
|
|
52
52
|
function _create() {
|
|
53
53
|
_create = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
54
|
-
var response, _onerror, interval;
|
|
55
|
-
return _regeneratorRuntime().wrap(function
|
|
54
|
+
var response, _onerror, interval, _t;
|
|
55
|
+
return _regeneratorRuntime().wrap(function (_context) {
|
|
56
56
|
while (1) switch (_context.prev = _context.next) {
|
|
57
57
|
case 0:
|
|
58
58
|
curRequestController = new AbortController();
|
|
59
59
|
_context.prev = 1;
|
|
60
|
-
_context.next =
|
|
60
|
+
_context.next = 2;
|
|
61
61
|
return fetch(input, _objectSpread(_objectSpread({}, rest), {}, {
|
|
62
62
|
headers: headers,
|
|
63
63
|
signal: curRequestController.signal
|
|
64
64
|
}));
|
|
65
|
-
case
|
|
65
|
+
case 2:
|
|
66
66
|
response = _context.sent;
|
|
67
|
-
_context.next =
|
|
67
|
+
_context.next = 3;
|
|
68
68
|
return onopen(response);
|
|
69
|
-
case
|
|
70
|
-
_context.next =
|
|
69
|
+
case 3:
|
|
70
|
+
_context.next = 4;
|
|
71
71
|
return getBytes(response.body, getLines(getMessages(function (id) {
|
|
72
72
|
if (id) {
|
|
73
73
|
// store the id and send it back on the next retry:
|
|
@@ -79,20 +79,20 @@ function fetchEventSource(input, _ref) {
|
|
|
79
79
|
}, function (retry) {
|
|
80
80
|
retryInterval = retry;
|
|
81
81
|
}, onmessage)));
|
|
82
|
-
case
|
|
82
|
+
case 4:
|
|
83
83
|
onclose === null || onclose === void 0 || onclose();
|
|
84
84
|
dispose();
|
|
85
85
|
resolve();
|
|
86
|
-
_context.next =
|
|
86
|
+
_context.next = 6;
|
|
87
87
|
break;
|
|
88
|
-
case
|
|
89
|
-
_context.prev =
|
|
90
|
-
|
|
88
|
+
case 5:
|
|
89
|
+
_context.prev = 5;
|
|
90
|
+
_t = _context["catch"](1);
|
|
91
91
|
if (!curRequestController.signal.aborted) {
|
|
92
92
|
// if we haven't aborted the request ourselves:
|
|
93
93
|
try {
|
|
94
94
|
// check if we need to retry:
|
|
95
|
-
interval = (_onerror = onerror === null || onerror === void 0 ? void 0 : onerror(
|
|
95
|
+
interval = (_onerror = onerror === null || onerror === void 0 ? void 0 : onerror(_t)) !== null && _onerror !== void 0 ? _onerror : retryInterval;
|
|
96
96
|
window.clearTimeout(retryTimer);
|
|
97
97
|
retryTimer = window.setTimeout(create, interval);
|
|
98
98
|
} catch (innerErr) {
|
|
@@ -101,11 +101,11 @@ function fetchEventSource(input, _ref) {
|
|
|
101
101
|
reject(innerErr);
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
case
|
|
104
|
+
case 6:
|
|
105
105
|
case "end":
|
|
106
106
|
return _context.stop();
|
|
107
107
|
}
|
|
108
|
-
}, _callee, null, [[1,
|
|
108
|
+
}, _callee, null, [[1, 5]]);
|
|
109
109
|
}));
|
|
110
110
|
return _create.apply(this, arguments);
|
|
111
111
|
}
|
|
@@ -118,16 +118,16 @@ function defaultOnOpen(_x) {
|
|
|
118
118
|
function _defaultOnOpen() {
|
|
119
119
|
_defaultOnOpen = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(response) {
|
|
120
120
|
var contentType;
|
|
121
|
-
return _regeneratorRuntime().wrap(function
|
|
121
|
+
return _regeneratorRuntime().wrap(function (_context2) {
|
|
122
122
|
while (1) switch (_context2.prev = _context2.next) {
|
|
123
123
|
case 0:
|
|
124
124
|
contentType = response.headers.get("content-type");
|
|
125
125
|
if (contentType !== null && contentType !== void 0 && contentType.startsWith(EventStreamContentType)) {
|
|
126
|
-
_context2.next =
|
|
126
|
+
_context2.next = 1;
|
|
127
127
|
break;
|
|
128
128
|
}
|
|
129
129
|
throw new Error("Expected content-type to be ".concat(EventStreamContentType, ", Actual: ").concat(contentType));
|
|
130
|
-
case
|
|
130
|
+
case 1:
|
|
131
131
|
case "end":
|
|
132
132
|
return _context2.stop();
|
|
133
133
|
}
|
|
@@ -21,28 +21,28 @@ function getBytes(_x, _x2) {
|
|
|
21
21
|
function _getBytes() {
|
|
22
22
|
_getBytes = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(stream, onChunk) {
|
|
23
23
|
var reader, result;
|
|
24
|
-
return _regeneratorRuntime().wrap(function
|
|
24
|
+
return _regeneratorRuntime().wrap(function (_context) {
|
|
25
25
|
while (1) switch (_context.prev = _context.next) {
|
|
26
26
|
case 0:
|
|
27
27
|
if (stream) {
|
|
28
|
-
_context.next =
|
|
28
|
+
_context.next = 1;
|
|
29
29
|
break;
|
|
30
30
|
}
|
|
31
31
|
return _context.abrupt("return");
|
|
32
|
-
case
|
|
32
|
+
case 1:
|
|
33
33
|
reader = stream.getReader();
|
|
34
|
-
case
|
|
35
|
-
_context.next =
|
|
34
|
+
case 2:
|
|
35
|
+
_context.next = 3;
|
|
36
36
|
return reader.read();
|
|
37
|
-
case
|
|
37
|
+
case 3:
|
|
38
38
|
if ((result = _context.sent).done) {
|
|
39
|
-
_context.next =
|
|
39
|
+
_context.next = 4;
|
|
40
40
|
break;
|
|
41
41
|
}
|
|
42
42
|
onChunk(result.value);
|
|
43
|
-
_context.next =
|
|
43
|
+
_context.next = 2;
|
|
44
44
|
break;
|
|
45
|
-
case
|
|
45
|
+
case 4:
|
|
46
46
|
case "end":
|
|
47
47
|
return _context.stop();
|
|
48
48
|
}
|
|
@@ -19,28 +19,28 @@ function getBytes(_x, _x2) {
|
|
|
19
19
|
function _getBytes() {
|
|
20
20
|
_getBytes = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(stream, onChunk) {
|
|
21
21
|
var reader, result;
|
|
22
|
-
return _regeneratorRuntime().wrap(function
|
|
22
|
+
return _regeneratorRuntime().wrap(function (_context) {
|
|
23
23
|
while (1) switch (_context.prev = _context.next) {
|
|
24
24
|
case 0:
|
|
25
25
|
if (stream) {
|
|
26
|
-
_context.next =
|
|
26
|
+
_context.next = 1;
|
|
27
27
|
break;
|
|
28
28
|
}
|
|
29
29
|
return _context.abrupt("return");
|
|
30
|
-
case
|
|
30
|
+
case 1:
|
|
31
31
|
reader = stream.getReader();
|
|
32
|
-
case
|
|
33
|
-
_context.next =
|
|
32
|
+
case 2:
|
|
33
|
+
_context.next = 3;
|
|
34
34
|
return reader.read();
|
|
35
|
-
case
|
|
35
|
+
case 3:
|
|
36
36
|
if ((result = _context.sent).done) {
|
|
37
|
-
_context.next =
|
|
37
|
+
_context.next = 4;
|
|
38
38
|
break;
|
|
39
39
|
}
|
|
40
40
|
onChunk(result.value);
|
|
41
|
-
_context.next =
|
|
41
|
+
_context.next = 2;
|
|
42
42
|
break;
|
|
43
|
-
case
|
|
43
|
+
case 4:
|
|
44
44
|
case "end":
|
|
45
45
|
return _context.stop();
|
|
46
46
|
}
|
|
@@ -4,6 +4,7 @@ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
|
4
4
|
var react = require('react');
|
|
5
5
|
var clamp = require('../utils/clamp.cjs');
|
|
6
6
|
var useDefault = require('./use-default.cjs');
|
|
7
|
+
var useEvent = require('./use-event.cjs');
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @author murukal
|
|
@@ -18,30 +19,30 @@ var useCounter = function useCounter() {
|
|
|
18
19
|
max = _ref$max === void 0 ? Infinity : _ref$max,
|
|
19
20
|
_ref$min = _ref.min,
|
|
20
21
|
min = _ref$min === void 0 ? -Infinity : _ref$min;
|
|
21
|
-
|
|
22
|
-
var defaultState = useDefault.useDefault(initialState);
|
|
23
|
-
var _useState = react.useState(defaultState),
|
|
22
|
+
var _useState = react.useState(initialState),
|
|
24
23
|
_useState2 = _slicedToArray(_useState, 2),
|
|
25
24
|
_count = _useState2[0],
|
|
26
25
|
_setCount = _useState2[1];
|
|
27
|
-
|
|
26
|
+
// memorized first time prop value
|
|
27
|
+
var defaultState = useDefault.useDefault(initialState);
|
|
28
|
+
var add = useEvent.useEvent(function () {
|
|
28
29
|
var step = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
29
30
|
_setCount(function (prev) {
|
|
30
31
|
return Math.min(max, prev + step);
|
|
31
32
|
});
|
|
32
|
-
}
|
|
33
|
-
var subtract =
|
|
33
|
+
});
|
|
34
|
+
var subtract = useEvent.useEvent(function () {
|
|
34
35
|
var step = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
35
36
|
_setCount(function (prev) {
|
|
36
37
|
return Math.max(min, prev - step);
|
|
37
38
|
});
|
|
38
|
-
}
|
|
39
|
-
var first =
|
|
39
|
+
});
|
|
40
|
+
var first = useEvent.useEvent(function () {
|
|
40
41
|
_setCount(min);
|
|
41
|
-
}
|
|
42
|
-
var last =
|
|
42
|
+
});
|
|
43
|
+
var last = useEvent.useEvent(function () {
|
|
43
44
|
_setCount(max);
|
|
44
|
-
}
|
|
45
|
+
});
|
|
45
46
|
var reset = react.useCallback(function () {
|
|
46
47
|
_setCount(defaultState);
|
|
47
48
|
}, []);
|
|
@@ -2,6 +2,7 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
|
2
2
|
import { useState, useCallback, useMemo } from 'react';
|
|
3
3
|
import { clamp } from '../utils/clamp.mjs';
|
|
4
4
|
import { useDefault } from './use-default.mjs';
|
|
5
|
+
import { useEvent } from './use-event.mjs';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @author murukal
|
|
@@ -16,30 +17,30 @@ var useCounter = function useCounter() {
|
|
|
16
17
|
max = _ref$max === void 0 ? Infinity : _ref$max,
|
|
17
18
|
_ref$min = _ref.min,
|
|
18
19
|
min = _ref$min === void 0 ? -Infinity : _ref$min;
|
|
19
|
-
|
|
20
|
-
var defaultState = useDefault(initialState);
|
|
21
|
-
var _useState = useState(defaultState),
|
|
20
|
+
var _useState = useState(initialState),
|
|
22
21
|
_useState2 = _slicedToArray(_useState, 2),
|
|
23
22
|
_count = _useState2[0],
|
|
24
23
|
_setCount = _useState2[1];
|
|
25
|
-
|
|
24
|
+
// memorized first time prop value
|
|
25
|
+
var defaultState = useDefault(initialState);
|
|
26
|
+
var add = useEvent(function () {
|
|
26
27
|
var step = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
27
28
|
_setCount(function (prev) {
|
|
28
29
|
return Math.min(max, prev + step);
|
|
29
30
|
});
|
|
30
|
-
}
|
|
31
|
-
var subtract =
|
|
31
|
+
});
|
|
32
|
+
var subtract = useEvent(function () {
|
|
32
33
|
var step = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
33
34
|
_setCount(function (prev) {
|
|
34
35
|
return Math.max(min, prev - step);
|
|
35
36
|
});
|
|
36
|
-
}
|
|
37
|
-
var first =
|
|
37
|
+
});
|
|
38
|
+
var first = useEvent(function () {
|
|
38
39
|
_setCount(min);
|
|
39
|
-
}
|
|
40
|
-
var last =
|
|
40
|
+
});
|
|
41
|
+
var last = useEvent(function () {
|
|
41
42
|
_setCount(max);
|
|
42
|
-
}
|
|
43
|
+
});
|
|
43
44
|
var reset = useCallback(function () {
|
|
44
45
|
_setCount(defaultState);
|
|
45
46
|
}, []);
|
|
@@ -48,8 +48,10 @@ var useParentSize = function useParentSize() {
|
|
|
48
48
|
resizer.observe(parentRef.current);
|
|
49
49
|
}
|
|
50
50
|
return function () {
|
|
51
|
+
var _resizer;
|
|
51
52
|
cancelAnimationFrame(_animation.current);
|
|
52
|
-
resizer.disconnect();
|
|
53
|
+
(_resizer = resizer) === null || _resizer === void 0 || _resizer.disconnect();
|
|
54
|
+
resizer = null;
|
|
53
55
|
abort();
|
|
54
56
|
};
|
|
55
57
|
});
|
|
@@ -46,8 +46,10 @@ var useParentSize = function useParentSize() {
|
|
|
46
46
|
resizer.observe(parentRef.current);
|
|
47
47
|
}
|
|
48
48
|
return function () {
|
|
49
|
+
var _resizer;
|
|
49
50
|
cancelAnimationFrame(_animation.current);
|
|
50
|
-
resizer.disconnect();
|
|
51
|
+
(_resizer = resizer) === null || _resizer === void 0 || _resizer.disconnect();
|
|
52
|
+
resizer = null;
|
|
51
53
|
abort();
|
|
52
54
|
};
|
|
53
55
|
});
|
|
@@ -12,10 +12,12 @@ var useMounted = require('./use-mounted.cjs');
|
|
|
12
12
|
*/
|
|
13
13
|
var useScreenSize = function useScreenSize() {
|
|
14
14
|
var _useState = react.useState(function () {
|
|
15
|
-
if (!isDomUsable.isDomUsable())
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
if (!isDomUsable.isDomUsable()) {
|
|
16
|
+
return {
|
|
17
|
+
width: 0,
|
|
18
|
+
height: 0
|
|
19
|
+
};
|
|
20
|
+
}
|
|
19
21
|
return {
|
|
20
22
|
width: window.innerWidth,
|
|
21
23
|
height: window.innerHeight
|
|
@@ -10,10 +10,12 @@ import { useMounted } from './use-mounted.mjs';
|
|
|
10
10
|
*/
|
|
11
11
|
var useScreenSize = function useScreenSize() {
|
|
12
12
|
var _useState = useState(function () {
|
|
13
|
-
if (!isDomUsable())
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
if (!isDomUsable()) {
|
|
14
|
+
return {
|
|
15
|
+
width: 0,
|
|
16
|
+
height: 0
|
|
17
|
+
};
|
|
18
|
+
}
|
|
17
19
|
return {
|
|
18
20
|
width: window.innerWidth,
|
|
19
21
|
height: window.innerHeight
|
package/dist/types/at.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Partialable } from "./partialable";
|
|
2
2
|
/**
|
|
3
|
-
* At
|
|
3
|
+
* `At` types
|
|
4
4
|
*/
|
|
5
|
-
export type At<T> = T extends string ? Partialable<string> : T extends
|
|
5
|
+
export type At<T> = T extends string ? Partialable<string> : T extends ReadonlyArray<infer R> ? R : never;
|
package/dist/types/first.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type First<T> = T extends null | undefined ? undefined : T extends string ? string : T extends [infer D, ...Array<any>] ? D : T extends
|
|
1
|
+
export type First<T> = T extends null | undefined ? undefined : T extends string ? string : T extends [infer D, ...Array<any>] ? D : T extends ReadonlyArray<infer I> ? I | undefined : T;
|
package/dist/types/last.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type Last<T> = T extends null | undefined ? undefined : T extends string ? string : T extends [...Array<unknown>, infer D] ? D : T extends
|
|
1
|
+
export type Last<T> = T extends null | undefined ? undefined : T extends string ? string : T extends [...Array<unknown>, infer D] ? D : T extends ReadonlyArray<infer I> ? I | undefined : T;
|
package/dist/utils/at.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import type { At } from "../types/at";
|
|
|
2
2
|
/**
|
|
3
3
|
* @description for different browser or browser version, use good api to cover
|
|
4
4
|
*/
|
|
5
|
-
declare function at<T>(value: string |
|
|
5
|
+
declare function at<T>(value: string | ReadonlyArray<T>, index: number): At<T>;
|
|
6
6
|
export { at };
|
package/dist/utils/first.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Voidable, First } from "@aiszlab/relax/types";
|
|
2
2
|
/**
|
|
3
3
|
* @description
|
|
4
4
|
* first element
|
|
5
5
|
*/
|
|
6
|
-
declare function first<T extends
|
|
6
|
+
declare function first<T extends ReadonlyArray<unknown>>(value: Voidable<string | T>): First<T>;
|
|
7
7
|
export { first };
|
package/dist/utils/last.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Voidable, Last } from "@aiszlab/relax/types";
|
|
2
2
|
/**
|
|
3
3
|
* @description
|
|
4
4
|
* last element
|
|
5
5
|
*/
|
|
6
|
-
declare function last<T extends
|
|
6
|
+
declare function last<T extends ReadonlyArray<unknown>>(value: Voidable<string | T>): Last<T>;
|
|
7
7
|
export { last };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiszlab/relax",
|
|
3
|
-
"version": "2.0.6-beta.
|
|
3
|
+
"version": "2.0.6-beta.5",
|
|
4
4
|
"description": "react utils collection",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -19,14 +19,6 @@
|
|
|
19
19
|
},
|
|
20
20
|
"./types": "./dist/types/index.d.ts"
|
|
21
21
|
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"dev": "rollup -c -w",
|
|
24
|
-
"build": "rollup -c",
|
|
25
|
-
"clean:build": "z rm dist",
|
|
26
|
-
"prepublishOnly": "npm run clean:build && npm run build",
|
|
27
|
-
"test": "jest",
|
|
28
|
-
"test:coverage": "jest --coverage"
|
|
29
|
-
},
|
|
30
22
|
"dependencies": {
|
|
31
23
|
"@babel/runtime": "^7.27.1",
|
|
32
24
|
"react-is": "^19.1.0",
|
|
@@ -71,5 +63,12 @@
|
|
|
71
63
|
"access": "public",
|
|
72
64
|
"registry": "https://registry.npmjs.org/"
|
|
73
65
|
},
|
|
74
|
-
"homepage": "https://aisz.dev/hooks"
|
|
75
|
-
|
|
66
|
+
"homepage": "https://aisz.dev/hooks",
|
|
67
|
+
"scripts": {
|
|
68
|
+
"dev": "rollup -c -w",
|
|
69
|
+
"build": "rollup -c",
|
|
70
|
+
"clean:build": "z rm dist",
|
|
71
|
+
"test": "jest",
|
|
72
|
+
"test:coverage": "jest --coverage"
|
|
73
|
+
}
|
|
74
|
+
}
|