@aiszlab/relax 1.2.59 → 1.2.60
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/_virtual/_rollupPluginBabelHelpers.js +16 -1
- package/dist/hooks/use-click-away.d.ts +6 -0
- package/dist/hooks/use-click-away.js +22 -0
- package/dist/hooks/use-media-query.d.ts +1 -7
- package/dist/hooks/use-media-query.js +53 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/utils/replace.d.ts +16 -0
- package/dist/utils/replace.js +20 -0
- package/dist/utils/tagged-template-literals.d.ts +6 -0
- package/dist/utils/tagged-template-literals.js +30 -0
- package/package.json +2 -2
|
@@ -31,6 +31,13 @@ function _classPrivateFieldSet2(s, a, r) {
|
|
|
31
31
|
function _classPrivateMethodInitSpec(e, a) {
|
|
32
32
|
_checkPrivateRedeclaration(e, a), a.add(e);
|
|
33
33
|
}
|
|
34
|
+
function _construct(t, e, r) {
|
|
35
|
+
if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
|
|
36
|
+
var o = [null];
|
|
37
|
+
o.push.apply(o, e);
|
|
38
|
+
var p = new (t.bind.apply(t, o))();
|
|
39
|
+
return p;
|
|
40
|
+
}
|
|
34
41
|
function _defineProperties(e, r) {
|
|
35
42
|
for (var t = 0; t < r.length; t++) {
|
|
36
43
|
var o = r[t];
|
|
@@ -42,6 +49,14 @@ function _createClass(e, r, t) {
|
|
|
42
49
|
writable: !1
|
|
43
50
|
}), e;
|
|
44
51
|
}
|
|
52
|
+
function _isNativeReflectConstruct() {
|
|
53
|
+
try {
|
|
54
|
+
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
55
|
+
} catch (t) {}
|
|
56
|
+
return (_isNativeReflectConstruct = function () {
|
|
57
|
+
return !!t;
|
|
58
|
+
})();
|
|
59
|
+
}
|
|
45
60
|
function _iterableToArray(r) {
|
|
46
61
|
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
47
62
|
}
|
|
@@ -135,4 +150,4 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
135
150
|
}
|
|
136
151
|
}
|
|
137
152
|
|
|
138
|
-
export { _arrayLikeToArray as arrayLikeToArray, _arrayWithHoles as arrayWithHoles, _arrayWithoutHoles as arrayWithoutHoles, _assertClassBrand as assertClassBrand, _checkPrivateRedeclaration as checkPrivateRedeclaration, _classCallCheck as classCallCheck, _classPrivateFieldGet2 as classPrivateFieldGet2, _classPrivateFieldInitSpec as classPrivateFieldInitSpec, _classPrivateFieldSet2 as classPrivateFieldSet2, _classPrivateMethodInitSpec as classPrivateMethodInitSpec, _createClass as createClass, _iterableToArray as iterableToArray, _iterableToArrayLimit as iterableToArrayLimit, _nonIterableRest as nonIterableRest, _nonIterableSpread as nonIterableSpread, _objectWithoutProperties as objectWithoutProperties, _objectWithoutPropertiesLoose as objectWithoutPropertiesLoose, _slicedToArray as slicedToArray, _toConsumableArray as toConsumableArray, _toPrimitive as toPrimitive, _toPropertyKey as toPropertyKey, _typeof as typeof, _unsupportedIterableToArray as unsupportedIterableToArray };
|
|
153
|
+
export { _arrayLikeToArray as arrayLikeToArray, _arrayWithHoles as arrayWithHoles, _arrayWithoutHoles as arrayWithoutHoles, _assertClassBrand as assertClassBrand, _checkPrivateRedeclaration as checkPrivateRedeclaration, _classCallCheck as classCallCheck, _classPrivateFieldGet2 as classPrivateFieldGet2, _classPrivateFieldInitSpec as classPrivateFieldInitSpec, _classPrivateFieldSet2 as classPrivateFieldSet2, _classPrivateMethodInitSpec as classPrivateMethodInitSpec, _construct as construct, _createClass as createClass, _isNativeReflectConstruct as isNativeReflectConstruct, _iterableToArray as iterableToArray, _iterableToArrayLimit as iterableToArrayLimit, _nonIterableRest as nonIterableRest, _nonIterableSpread as nonIterableSpread, _objectWithoutProperties as objectWithoutProperties, _objectWithoutPropertiesLoose as objectWithoutPropertiesLoose, _slicedToArray as slicedToArray, _toConsumableArray as toConsumableArray, _toPrimitive as toPrimitive, _toPropertyKey as toPropertyKey, _typeof as typeof, _unsupportedIterableToArray as unsupportedIterableToArray };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useEvent } from './use-event.js';
|
|
3
|
+
import { contains } from '../dom/contains.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* click away
|
|
8
|
+
*/
|
|
9
|
+
var useClickAway = function useClickAway(onClickAway, target) {
|
|
10
|
+
var clickAway = useEvent(function (event) {
|
|
11
|
+
if (contains(target.current, event.target)) return;
|
|
12
|
+
onClickAway(event);
|
|
13
|
+
});
|
|
14
|
+
useEffect(function () {
|
|
15
|
+
document.addEventListener("click", clickAway);
|
|
16
|
+
return function () {
|
|
17
|
+
document.removeEventListener("click", clickAway);
|
|
18
|
+
};
|
|
19
|
+
}, []);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { useClickAway };
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @author murukal
|
|
3
|
-
* @description 监听浏览器 media 变化,控制状态
|
|
4
|
-
*
|
|
5
|
-
* media 规则 @media not|only mediatype and (mediafeature and|or|not mediafeature)
|
|
6
|
-
*/
|
|
7
|
-
export declare const useMediaQuery: () => void;
|
|
1
|
+
export declare const useMediaQuery: (query: string[] | string) => boolean[];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { slicedToArray as _slicedToArray } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import { useMemo, useState, useEffect } from 'react';
|
|
3
|
+
import { toArray } from '../utils/to-array.js';
|
|
4
|
+
import { useEvent } from './use-event.js';
|
|
5
|
+
import { replace } from '../utils/replace.js';
|
|
6
|
+
|
|
7
|
+
var useMediaQuery = function useMediaQuery(query) {
|
|
8
|
+
var _query = useMemo(function () {
|
|
9
|
+
return query.toString();
|
|
10
|
+
}, [query]);
|
|
11
|
+
var queries = toArray(query);
|
|
12
|
+
var _useState = useState(function () {
|
|
13
|
+
return queries.map(function (query) {
|
|
14
|
+
var _window$matchMedia, _window;
|
|
15
|
+
return !!((_window$matchMedia = (_window = window).matchMedia) !== null && _window$matchMedia !== void 0 && (_window$matchMedia = _window$matchMedia.call(_window, query)) !== null && _window$matchMedia !== void 0 && _window$matchMedia.matches);
|
|
16
|
+
});
|
|
17
|
+
}),
|
|
18
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
19
|
+
value = _useState2[0],
|
|
20
|
+
setValue = _useState2[1];
|
|
21
|
+
var onMediaQueryChange = useEvent(function (event, index) {
|
|
22
|
+
setValue(function (prev) {
|
|
23
|
+
return replace(prev, {
|
|
24
|
+
index: index,
|
|
25
|
+
replaceValue: event.matches
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
useEffect(function () {
|
|
30
|
+
var mediaQueries = queries.map(function (query) {
|
|
31
|
+
return window.matchMedia(query);
|
|
32
|
+
});
|
|
33
|
+
// listen media query change
|
|
34
|
+
var cleaners = mediaQueries.map(function (mediaQuery, index) {
|
|
35
|
+
var listener = function listener(event) {
|
|
36
|
+
return onMediaQueryChange(event, index);
|
|
37
|
+
};
|
|
38
|
+
mediaQuery.addEventListener("change", listener);
|
|
39
|
+
return function () {
|
|
40
|
+
return mediaQuery.removeEventListener("change", listener);
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
// clean up all listeners
|
|
44
|
+
return function () {
|
|
45
|
+
return cleaners.forEach(function (cleaner) {
|
|
46
|
+
return cleaner();
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
}, [_query]);
|
|
50
|
+
return value;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { useMediaQuery };
|
package/dist/index.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export { useMutateObserver } from "./hooks/use-mutate-observer";
|
|
|
26
26
|
export { useRaf } from "./hooks/use-raf";
|
|
27
27
|
export { useDevicePixelRatio } from "./hooks/use-device-pixel-ratio";
|
|
28
28
|
export { useIdentity } from "./hooks/use-identity";
|
|
29
|
+
export { useMediaQuery } from "./hooks/use-media-query";
|
|
30
|
+
export { useClickAway } from "./hooks/use-click-away";
|
|
29
31
|
/**
|
|
30
32
|
* @description
|
|
31
33
|
* is
|
|
@@ -62,3 +64,5 @@ export { setStyle } from "./utils/set-style";
|
|
|
62
64
|
export { throttle } from "./utils/throttle";
|
|
63
65
|
export { clone } from "./utils/clone";
|
|
64
66
|
export { toggle } from "./utils/toggle";
|
|
67
|
+
export { taggedTemplateLiterals } from "./utils/tagged-template-literals";
|
|
68
|
+
export { replace } from "./utils/replace";
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,8 @@ export { useMutateObserver } from './hooks/use-mutate-observer.js';
|
|
|
22
22
|
export { useRaf } from './hooks/use-raf.js';
|
|
23
23
|
export { useDevicePixelRatio } from './hooks/use-device-pixel-ratio.js';
|
|
24
24
|
export { useIdentity } from './hooks/use-identity.js';
|
|
25
|
+
export { useMediaQuery } from './hooks/use-media-query.js';
|
|
26
|
+
export { useClickAway } from './hooks/use-click-away.js';
|
|
25
27
|
export { isRefable } from './is/is-refable.js';
|
|
26
28
|
export { isUndefined } from './is/is-undefined.js';
|
|
27
29
|
export { isStateGetter } from './is/is-state-getter.js';
|
|
@@ -50,3 +52,5 @@ export { setStyle } from './utils/set-style.js';
|
|
|
50
52
|
export { throttle } from './utils/throttle.js';
|
|
51
53
|
export { clone } from './utils/clone.js';
|
|
52
54
|
export { toggle } from './utils/toggle.js';
|
|
55
|
+
export { taggedTemplateLiterals } from './utils/tagged-template-literals.js';
|
|
56
|
+
export { replace } from './utils/replace.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type ReplaceArrayOptions<R> = {
|
|
2
|
+
index: number;
|
|
3
|
+
replaceValue: R;
|
|
4
|
+
};
|
|
5
|
+
type ReplaceStringOptions = {
|
|
6
|
+
searchValue: string;
|
|
7
|
+
replaceValue: string;
|
|
8
|
+
};
|
|
9
|
+
type ReplaceOptions<T> = T extends string ? ReplaceStringOptions : T extends Array<infer R> ? ReplaceArrayOptions<R> : never;
|
|
10
|
+
/**
|
|
11
|
+
* @description
|
|
12
|
+
* comman replace
|
|
13
|
+
* usable for `string`, `array`
|
|
14
|
+
*/
|
|
15
|
+
export declare const replace: <T extends string | R[], R>(value: T, options: ReplaceOptions<T>) => T;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { toConsumableArray as _toConsumableArray } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import { isArray } from '../is/is-array.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @description
|
|
6
|
+
* comman replace
|
|
7
|
+
* usable for `string`, `array`
|
|
8
|
+
*/
|
|
9
|
+
var replace = function replace(value, options) {
|
|
10
|
+
if (isArray(value)) {
|
|
11
|
+
var index = options.index,
|
|
12
|
+
_replaceValue = options.replaceValue;
|
|
13
|
+
return [].concat(_toConsumableArray(value.slice(0, index)), [_replaceValue], _toConsumableArray(value.slice(index + 1)));
|
|
14
|
+
}
|
|
15
|
+
var replaceValue = options.replaceValue,
|
|
16
|
+
searchValue = options.searchValue;
|
|
17
|
+
return value.replace(searchValue, replaceValue);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { replace };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { slicedToArray as _slicedToArray, construct as _construct, toConsumableArray as _toConsumableArray } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* create tagged template literals
|
|
6
|
+
*/
|
|
7
|
+
var taggedTemplateLiterals = function taggedTemplateLiterals(template, variables) {
|
|
8
|
+
if (!variables) return template;
|
|
9
|
+
var entries = Object.entries(variables);
|
|
10
|
+
if (entries.length === 0) return template;
|
|
11
|
+
var _entries$reduce = entries.reduce(function (prev, _ref) {
|
|
12
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
13
|
+
key = _ref2[0],
|
|
14
|
+
value = _ref2[1];
|
|
15
|
+
prev[0].push(key);
|
|
16
|
+
prev[1].push(value !== null && value !== void 0 ? value : "");
|
|
17
|
+
return prev;
|
|
18
|
+
}, [[], []]),
|
|
19
|
+
_entries$reduce2 = _slicedToArray(_entries$reduce, 2),
|
|
20
|
+
keys = _entries$reduce2[0],
|
|
21
|
+
values = _entries$reduce2[1];
|
|
22
|
+
try {
|
|
23
|
+
var render = _construct(Function, _toConsumableArray(keys).concat(["return `".concat(template, "`")]));
|
|
24
|
+
return render.apply(void 0, _toConsumableArray(values));
|
|
25
|
+
} catch (error) {
|
|
26
|
+
return template;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { taggedTemplateLiterals };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiszlab/relax",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.60",
|
|
4
4
|
"description": "react utils collection",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@babel/core": "^7.24.7",
|
|
30
|
-
"@babel/preset-env": "^7.24.
|
|
30
|
+
"@babel/preset-env": "^7.24.8",
|
|
31
31
|
"@babel/preset-typescript": "^7.24.7",
|
|
32
32
|
"@jest/globals": "^29.7.0",
|
|
33
33
|
"@rollup/plugin-babel": "^6.0.4",
|