@pisell/utils 3.0.4 → 3.0.6
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/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +11 -0
- package/es/arrayUtils.d.ts +76 -1
- package/es/arrayUtils.js +103 -24
- package/es/common/stateHelper.d.ts +22 -0
- package/es/common/stateHelper.js +23 -0
- package/es/common/types.d.ts +31 -0
- package/es/componentStorage.d.ts +38 -0
- package/es/componentStorage.js +106 -0
- package/es/constants/index.js +7 -9
- package/es/date.d.ts +6 -3
- package/es/date.js +36 -53
- package/es/document.d.ts +6 -3
- package/es/document.js +43 -67
- package/es/escPosPrinter/EscPosPrinter.js +353 -490
- package/es/escPosPrinter/index.d.ts +9 -9
- package/es/escPosPrinter/index.js +37 -52
- package/es/format.d.ts +29 -0
- package/es/format.js +90 -112
- package/es/image.d.ts +13 -10
- package/es/image.js +48 -60
- package/es/index.d.ts +39 -18
- package/es/index.js +40 -29
- package/es/jsBridge/index.d.ts +14 -106
- package/es/jsBridge/index.js +57 -40
- package/es/jsBridge/regDeviceApi.js +87 -126
- package/es/jsBridge/types.d.ts +129 -0
- package/es/locales.d.ts +11 -11
- package/es/locales.js +79 -69
- package/es/log.d.ts +11 -6
- package/es/log.js +37 -59
- package/es/miniRedux.d.ts +20 -13
- package/es/miniRedux.js +42 -71
- package/es/number-input/hooks/useNumberInputState.d.ts +29 -0
- package/es/number-input/hooks/useNumberInputState.js +72 -0
- package/es/number-input/types.d.ts +96 -0
- package/es/number-input/utils/formatter.d.ts +56 -0
- package/es/number-input/utils/formatter.js +56 -0
- package/es/number-input/utils/validation.d.ts +32 -0
- package/es/number-input/utils/validation.js +52 -0
- package/es/otherUtils.d.ts +12 -9
- package/es/otherUtils.js +71 -120
- package/es/platform.d.ts +12 -9
- package/es/platform.js +61 -85
- package/es/select/hooks/useDebouncedSearch.d.ts +23 -0
- package/es/select/hooks/useDebouncedSearch.js +41 -0
- package/es/select/hooks/useSelectState.d.ts +19 -0
- package/es/select/hooks/useSelectState.js +60 -0
- package/es/select/index.d.ts +7 -0
- package/es/select/types.d.ts +256 -0
- package/es/select/utils/filterOptions.d.ts +23 -0
- package/es/select/utils/filterOptions.js +29 -0
- package/es/select/utils/helpers.d.ts +43 -0
- package/es/select/utils/helpers.js +51 -0
- package/es/select/utils/index.d.ts +4 -0
- package/es/select/utils/sortOptions.d.ts +13 -0
- package/es/select/utils/sortOptions.js +20 -0
- package/es/select/utils/tagAggregation.d.ts +25 -0
- package/es/select/utils/tagAggregation.js +35 -0
- package/es/text-input/hooks/useTextInputState.d.ts +28 -0
- package/es/text-input/hooks/useTextInputState.js +70 -0
- package/es/text-input/types.d.ts +56 -0
- package/es/text-input/utils/validation.d.ts +28 -0
- package/es/text-input/utils/validation.js +51 -0
- package/es/typeUtils.d.ts +11 -8
- package/es/typeUtils.js +61 -84
- package/es/walletValidity.d.ts +57 -0
- package/es/walletValidity.js +404 -460
- package/es/weighing.d.ts +65 -0
- package/es/weighing.js +96 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +16 -0
- package/lib/_virtual/_rolldown/runtime.js +23 -0
- package/lib/arrayUtils.d.ts +76 -1
- package/lib/arrayUtils.js +102 -37
- package/lib/common/stateHelper.d.ts +22 -0
- package/lib/common/stateHelper.js +23 -0
- package/lib/common/types.d.ts +31 -0
- package/lib/componentStorage.d.ts +38 -0
- package/lib/componentStorage.js +114 -0
- package/lib/constants/index.js +7 -36
- package/lib/date.d.ts +6 -3
- package/lib/date.js +43 -65
- package/lib/document.d.ts +6 -3
- package/lib/document.js +46 -62
- package/lib/escPosPrinter/EscPosPrinter.js +327 -403
- package/lib/escPosPrinter/index.d.ts +9 -9
- package/lib/escPosPrinter/index.js +38 -84
- package/lib/format.d.ts +29 -0
- package/lib/format.js +91 -93
- package/lib/image.d.ts +13 -10
- package/lib/image.js +48 -74
- package/lib/index.d.ts +39 -18
- package/lib/index.js +137 -68
- package/lib/jsBridge/index.d.ts +14 -106
- package/lib/jsBridge/index.js +60 -60
- package/lib/jsBridge/regDeviceApi.js +86 -133
- package/lib/jsBridge/types.d.ts +129 -0
- package/lib/locales.d.ts +11 -11
- package/lib/locales.js +79 -63
- package/lib/log.d.ts +11 -6
- package/lib/log.js +37 -61
- package/lib/miniRedux.d.ts +20 -13
- package/lib/miniRedux.js +43 -91
- package/lib/number-input/hooks/useNumberInputState.d.ts +29 -0
- package/lib/number-input/hooks/useNumberInputState.js +73 -0
- package/lib/number-input/types.d.ts +96 -0
- package/lib/number-input/utils/formatter.d.ts +56 -0
- package/lib/number-input/utils/formatter.js +58 -0
- package/lib/number-input/utils/validation.d.ts +32 -0
- package/lib/number-input/utils/validation.js +52 -0
- package/lib/otherUtils.d.ts +12 -9
- package/lib/otherUtils.js +86 -91
- package/lib/platform.d.ts +12 -9
- package/lib/platform.js +68 -123
- package/lib/select/hooks/useDebouncedSearch.d.ts +23 -0
- package/lib/select/hooks/useDebouncedSearch.js +42 -0
- package/lib/select/hooks/useSelectState.d.ts +19 -0
- package/lib/select/hooks/useSelectState.js +62 -0
- package/lib/select/index.d.ts +7 -0
- package/lib/select/types.d.ts +256 -0
- package/lib/select/utils/filterOptions.d.ts +23 -0
- package/lib/select/utils/filterOptions.js +30 -0
- package/lib/select/utils/helpers.d.ts +43 -0
- package/lib/select/utils/helpers.js +55 -0
- package/lib/select/utils/index.d.ts +4 -0
- package/lib/select/utils/sortOptions.d.ts +13 -0
- package/lib/select/utils/sortOptions.js +20 -0
- package/lib/select/utils/tagAggregation.d.ts +25 -0
- package/lib/select/utils/tagAggregation.js +35 -0
- package/lib/text-input/hooks/useTextInputState.d.ts +28 -0
- package/lib/text-input/hooks/useTextInputState.js +71 -0
- package/lib/text-input/types.d.ts +56 -0
- package/lib/text-input/utils/validation.d.ts +28 -0
- package/lib/text-input/utils/validation.js +51 -0
- package/lib/typeUtils.d.ts +11 -8
- package/lib/typeUtils.js +68 -73
- package/lib/walletValidity.d.ts +57 -0
- package/lib/walletValidity.js +420 -323
- package/lib/weighing.d.ts +65 -0
- package/lib/weighing.js +114 -0
- package/package.json +1 -1
- package/es/constants/index.d.ts +0 -7
- package/es/firebase/config/index.d.ts +0 -13
- package/es/firebase/config/index.js +0 -54
- package/es/firebase/index.d.ts +0 -28
- package/es/firebase/index.js +0 -232
- package/lib/constants/index.d.ts +0 -7
- package/lib/firebase/config/index.d.ts +0 -13
- package/lib/firebase/config/index.js +0 -79
- package/lib/firebase/index.d.ts +0 -28
- package/lib/firebase/index.js +0 -180
package/lib/otherUtils.js
CHANGED
|
@@ -1,96 +1,91 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.js");
|
|
2
|
+
const require_asyncToGenerator = require("./_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
|
|
3
|
+
let crypto_js_md5 = require("crypto-js/md5");
|
|
4
|
+
crypto_js_md5 = require_runtime.__toESM(crypto_js_md5);
|
|
5
|
+
let crypto_js_enc_hex = require("crypto-js/enc-hex");
|
|
6
|
+
crypto_js_enc_hex = require_runtime.__toESM(crypto_js_enc_hex);
|
|
7
|
+
let detectincognitojs = require("detectincognitojs");
|
|
8
|
+
//#region src/otherUtils.ts
|
|
9
|
+
/**
|
|
10
|
+
* @title: 判断是否无痕模式
|
|
11
|
+
* @description:
|
|
12
|
+
* @return: *
|
|
13
|
+
* @Author: shengjie.zuo
|
|
14
|
+
* @Date: 2024-09-4 09:58:22
|
|
15
|
+
*/
|
|
16
|
+
const detectIncognito = function() {
|
|
17
|
+
var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
|
|
18
|
+
try {
|
|
19
|
+
if (navigator.userAgent.toLowerCase().includes("honor")) return { isPrivate: false };
|
|
20
|
+
return yield (0, detectincognitojs.detectIncognito)();
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.warn("detectIncognito failed:", error);
|
|
23
|
+
return { isPrivate: false };
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return function detectIncognito() {
|
|
27
|
+
return _ref.apply(this, arguments);
|
|
28
|
+
};
|
|
29
|
+
}();
|
|
30
|
+
/**
|
|
31
|
+
* @Description: 生成唯一id
|
|
32
|
+
* @Author: wzw
|
|
33
|
+
* @Date: 2020-12-01 14:20:29
|
|
34
|
+
* @param {*}
|
|
35
|
+
* @return {*}
|
|
36
|
+
*/
|
|
37
|
+
const getUniqueId = (prefix = "", maxLength = 11) => {
|
|
38
|
+
return prefix + (Math.random() + "").replace(/\D/g, "").substring(0, maxLength);
|
|
10
39
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
40
|
+
/**
|
|
41
|
+
* @title: 对数组进行增|删
|
|
42
|
+
* @description: 用于多选选中和取消选中的处理
|
|
43
|
+
* @param {any} list
|
|
44
|
+
* @param {any} item
|
|
45
|
+
* @param {string} key
|
|
46
|
+
* @return {*}
|
|
47
|
+
* @Author: zhiwei.Wang
|
|
48
|
+
* @Date: 2023-12-19 16:44
|
|
49
|
+
*/
|
|
50
|
+
const changeArray = (list = [], item, key = "this") => {
|
|
51
|
+
let _list = JSON.parse(JSON.stringify(list));
|
|
52
|
+
let isSome = false;
|
|
53
|
+
if (key === "this") isSome = _list.includes(item);
|
|
54
|
+
else isSome = _list.some((d) => d[key] === item[key]);
|
|
55
|
+
if (isSome) _list = _list.filter((d) => {
|
|
56
|
+
if (key === "this") return d !== item;
|
|
57
|
+
return d[key] !== item[key];
|
|
58
|
+
});
|
|
59
|
+
else _list.push(item);
|
|
60
|
+
return _list;
|
|
18
61
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
__export(otherUtils_exports, {
|
|
32
|
-
changeArray: () => changeArray,
|
|
33
|
-
createArray: () => createArray,
|
|
34
|
-
detectIncognito: () => detectIncognito,
|
|
35
|
-
generateUniqueIdByObj: () => generateUniqueIdByObj,
|
|
36
|
-
getItemByArray: () => getItemByArray,
|
|
37
|
-
getUniqueId: () => getUniqueId
|
|
38
|
-
});
|
|
39
|
-
module.exports = __toCommonJS(otherUtils_exports);
|
|
40
|
-
var import_md5 = __toESM(require("crypto-js/md5"));
|
|
41
|
-
var import_enc_hex = __toESM(require("crypto-js/enc-hex"));
|
|
42
|
-
var import_detectincognitojs = require("detectincognitojs");
|
|
43
|
-
var detectIncognito = async () => {
|
|
44
|
-
if (navigator.userAgent.toLowerCase().includes("honor")) {
|
|
45
|
-
return {
|
|
46
|
-
isPrivate: false
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
return await (0, import_detectincognitojs.detectIncognito)();
|
|
62
|
+
/**
|
|
63
|
+
* @title: 判断某个字段是否在列表内
|
|
64
|
+
* @description:
|
|
65
|
+
* @param {*} T
|
|
66
|
+
* @param {boolean} param2
|
|
67
|
+
* @return {*}
|
|
68
|
+
* @Author: zhiwei.Wang
|
|
69
|
+
* @Date: 2023-12-19 16:54
|
|
70
|
+
*/
|
|
71
|
+
const getItemByArray = (list = [], item, key = "this") => {
|
|
72
|
+
if (key === "this") return list.includes(item);
|
|
73
|
+
return list.some((d) => d[key] === item[key]);
|
|
50
74
|
};
|
|
51
|
-
|
|
52
|
-
|
|
75
|
+
const createArray = (length, returnItem) => {
|
|
76
|
+
return Array.from(new Array(length)).map(returnItem);
|
|
53
77
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
isSome = _list.some((d) => d[key] === item[key]);
|
|
61
|
-
}
|
|
62
|
-
if (isSome) {
|
|
63
|
-
_list = _list.filter((d) => {
|
|
64
|
-
if (key === "this") {
|
|
65
|
-
return d !== item;
|
|
66
|
-
}
|
|
67
|
-
return d[key] !== item[key];
|
|
68
|
-
});
|
|
69
|
-
} else {
|
|
70
|
-
_list.push(item);
|
|
71
|
-
}
|
|
72
|
-
return _list;
|
|
78
|
+
/**
|
|
79
|
+
* 根据对象内容生成唯一id
|
|
80
|
+
* @param obj
|
|
81
|
+
*/
|
|
82
|
+
const generateUniqueIdByObj = (obj) => {
|
|
83
|
+
return (0, crypto_js_md5.default)(JSON.stringify(obj)).toString(crypto_js_enc_hex.default.Hex);
|
|
73
84
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return Array.from(new Array(length)).map(returnItem);
|
|
82
|
-
};
|
|
83
|
-
var generateUniqueIdByObj = (obj) => {
|
|
84
|
-
const jsonString = JSON.stringify(obj);
|
|
85
|
-
const hash = (0, import_md5.default)(jsonString);
|
|
86
|
-
return hash.toString(import_enc_hex.default.Hex);
|
|
87
|
-
};
|
|
88
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
-
0 && (module.exports = {
|
|
90
|
-
changeArray,
|
|
91
|
-
createArray,
|
|
92
|
-
detectIncognito,
|
|
93
|
-
generateUniqueIdByObj,
|
|
94
|
-
getItemByArray,
|
|
95
|
-
getUniqueId
|
|
96
|
-
});
|
|
85
|
+
//#endregion
|
|
86
|
+
exports.changeArray = changeArray;
|
|
87
|
+
exports.createArray = createArray;
|
|
88
|
+
exports.detectIncognito = detectIncognito;
|
|
89
|
+
exports.generateUniqueIdByObj = generateUniqueIdByObj;
|
|
90
|
+
exports.getItemByArray = getItemByArray;
|
|
91
|
+
exports.getUniqueId = getUniqueId;
|
package/lib/platform.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
//#region src/platform.d.ts
|
|
2
|
+
declare const isIpad: () => boolean;
|
|
3
|
+
declare const isMobile: () => boolean;
|
|
4
|
+
declare const isAndroid: () => boolean;
|
|
5
|
+
declare const isIos: () => boolean;
|
|
6
|
+
declare const checkEnv: () => number;
|
|
7
|
+
declare const isWx: () => boolean;
|
|
8
|
+
declare const isIOS: () => boolean;
|
|
9
|
+
declare const isWxApp: () => boolean;
|
|
10
|
+
declare const isSafari: () => boolean;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { checkEnv, isAndroid, isIOS, isIos, isIpad, isMobile, isSafari, isWx, isWxApp };
|
package/lib/platform.js
CHANGED
|
@@ -1,132 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
//#region src/platform.ts
|
|
2
|
+
const isBrowser = typeof window != "undefined" && window.document;
|
|
3
|
+
const isIpad = () => {
|
|
4
|
+
var ua = navigator.userAgent;
|
|
5
|
+
var isSafari = ua.indexOf("Safari") != -1 && ua.indexOf("Version") != -1;
|
|
6
|
+
var isIphone = ua.indexOf("iPhone") != -1 && ua.indexOf("Version") != -1;
|
|
7
|
+
var isIPad = isSafari && !isIphone && "ontouchend" in document;
|
|
8
|
+
if (!/iphone|ios|ipad|android|mobile/i.test(navigator.userAgent.toLowerCase()) && !isIPad) return false;
|
|
9
|
+
return true;
|
|
8
10
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
const isMobile = () => {
|
|
12
|
+
let sUserAgent = window.navigator.userAgent.toLowerCase();
|
|
13
|
+
let bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
|
|
14
|
+
let bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
|
|
15
|
+
let bIsMidp = sUserAgent.match(/midp/i) == "midp";
|
|
16
|
+
let bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
|
|
17
|
+
let bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
|
|
18
|
+
let bIsAndroid = sUserAgent.match(/android/i) == "android";
|
|
19
|
+
let bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
|
|
20
|
+
let bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
|
|
21
|
+
if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM || isIpad()) return true;
|
|
22
|
+
else return false;
|
|
16
23
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// src/platform.ts
|
|
20
|
-
var platform_exports = {};
|
|
21
|
-
__export(platform_exports, {
|
|
22
|
-
checkEnv: () => checkEnv,
|
|
23
|
-
isAndroid: () => isAndroid,
|
|
24
|
-
isIOS: () => isIOS,
|
|
25
|
-
isIos: () => isIos,
|
|
26
|
-
isIpad: () => isIpad,
|
|
27
|
-
isMobile: () => isMobile,
|
|
28
|
-
isSafari: () => isSafari,
|
|
29
|
-
isWx: () => isWx,
|
|
30
|
-
isWxApp: () => isWxApp
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(platform_exports);
|
|
33
|
-
var isBrowser = typeof window != "undefined" && window.document;
|
|
34
|
-
var isIpad = () => {
|
|
35
|
-
var ua = navigator.userAgent;
|
|
36
|
-
var isSafari2 = ua.indexOf("Safari") != -1 && ua.indexOf("Version") != -1;
|
|
37
|
-
var isIphone = ua.indexOf("iPhone") != -1 && ua.indexOf("Version") != -1;
|
|
38
|
-
var isIPad = isSafari2 && !isIphone && "ontouchend" in document;
|
|
39
|
-
if (!/iphone|ios|ipad|android|mobile/i.test(
|
|
40
|
-
navigator.userAgent.toLowerCase()
|
|
41
|
-
) && !isIPad) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
return true;
|
|
24
|
+
const isAndroid = () => {
|
|
25
|
+
return navigator.userAgent.toLowerCase().indexOf("android") !== -1;
|
|
45
26
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
let bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
|
|
49
|
-
let bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
|
|
50
|
-
let bIsMidp = sUserAgent.match(/midp/i) == "midp";
|
|
51
|
-
let bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
|
|
52
|
-
let bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
|
|
53
|
-
let bIsAndroid = sUserAgent.match(/android/i) == "android";
|
|
54
|
-
let bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
|
|
55
|
-
let bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
|
|
56
|
-
if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM || isIpad()) {
|
|
57
|
-
return true;
|
|
58
|
-
} else {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
27
|
+
const isIos = () => {
|
|
28
|
+
return /iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase());
|
|
61
29
|
};
|
|
62
|
-
|
|
63
|
-
|
|
30
|
+
const checkEnv = () => {
|
|
31
|
+
let env = 0;
|
|
32
|
+
let userAgent = window.navigator.userAgent;
|
|
33
|
+
let isOpera = userAgent.indexOf("Opera") > -1 || userAgent.indexOf("OPR") > -1;
|
|
34
|
+
let isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
|
|
35
|
+
let isIE11 = userAgent.indexOf("compatible") === -1 && userAgent.indexOf("Trident") > -1;
|
|
36
|
+
let isEdge = userAgent.indexOf("Edge") > -1;
|
|
37
|
+
let isFF = userAgent.indexOf("Firefox") > -1;
|
|
38
|
+
let isSafari = userAgent.indexOf("Safari") > -1 && userAgent.indexOf("Chrome") === -1;
|
|
39
|
+
let isChrome = userAgent.indexOf("Chrome") > -1 && userAgent.indexOf("; Win") > -1 && userAgent.indexOf("Safari") > -1;
|
|
40
|
+
if (isOpera || isIE || isIE11 || isEdge || isFF || isSafari || isChrome) env = 0;
|
|
41
|
+
else env = 1;
|
|
42
|
+
return env;
|
|
64
43
|
};
|
|
65
|
-
|
|
66
|
-
|
|
44
|
+
const isWx = () => {
|
|
45
|
+
if (isBrowser) {
|
|
46
|
+
let ua = "";
|
|
47
|
+
if (isBrowser) ua = window.navigator.userAgent.toLowerCase();
|
|
48
|
+
if (ua.match(/MicroMessenger/i) == "micromessenger") return true;
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
67
52
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
let isOpera = userAgent.indexOf("Opera") > -1 || userAgent.indexOf("OPR") > -1;
|
|
72
|
-
let isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
|
|
73
|
-
let isIE11 = userAgent.indexOf("compatible") === -1 && userAgent.indexOf("Trident") > -1;
|
|
74
|
-
let isEdge = userAgent.indexOf("Edge") > -1;
|
|
75
|
-
let isFF = userAgent.indexOf("Firefox") > -1;
|
|
76
|
-
let isSafari2 = userAgent.indexOf("Safari") > -1 && userAgent.indexOf("Chrome") === -1;
|
|
77
|
-
let isChrome = userAgent.indexOf("Chrome") > -1 && userAgent.indexOf("; Win") > -1 && userAgent.indexOf("Safari") > -1;
|
|
78
|
-
if (isOpera || isIE || isIE11 || isEdge || isFF || isSafari2 || isChrome) {
|
|
79
|
-
env = 0;
|
|
80
|
-
} else {
|
|
81
|
-
env = 1;
|
|
82
|
-
}
|
|
83
|
-
return env;
|
|
53
|
+
const isIOS = () => {
|
|
54
|
+
if (isBrowser) return !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
|
|
55
|
+
return false;
|
|
84
56
|
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (isBrowser) {
|
|
89
|
-
ua = window.navigator.userAgent.toLowerCase();
|
|
90
|
-
}
|
|
91
|
-
if (ua.match(/MicroMessenger/i) == "micromessenger") {
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
return false;
|
|
57
|
+
const isWxApp = () => {
|
|
58
|
+
if (isBrowser) return navigator.userAgent.indexOf("miniProgram") !== -1;
|
|
59
|
+
return false;
|
|
97
60
|
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return false;
|
|
61
|
+
const isSafari = () => {
|
|
62
|
+
if (isBrowser) {
|
|
63
|
+
let userAgent = window.navigator.userAgent;
|
|
64
|
+
return userAgent.indexOf("Safari") > -1 && userAgent.indexOf("Chrome") === -1 && userAgent.indexOf("CriOS") === -1 && userAgent.indexOf("ChannelName/Feishu") === -1;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
105
67
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
let userAgent = window.navigator.userAgent;
|
|
117
|
-
return userAgent.indexOf("Safari") > -1 && userAgent.indexOf("Chrome") === -1 && userAgent.indexOf("CriOS") === -1 && userAgent.indexOf("ChannelName/Feishu") === -1;
|
|
118
|
-
}
|
|
119
|
-
return false;
|
|
120
|
-
};
|
|
121
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
-
0 && (module.exports = {
|
|
123
|
-
checkEnv,
|
|
124
|
-
isAndroid,
|
|
125
|
-
isIOS,
|
|
126
|
-
isIos,
|
|
127
|
-
isIpad,
|
|
128
|
-
isMobile,
|
|
129
|
-
isSafari,
|
|
130
|
-
isWx,
|
|
131
|
-
isWxApp
|
|
132
|
-
});
|
|
68
|
+
//#endregion
|
|
69
|
+
exports.checkEnv = checkEnv;
|
|
70
|
+
exports.isAndroid = isAndroid;
|
|
71
|
+
exports.isIOS = isIOS;
|
|
72
|
+
exports.isIos = isIos;
|
|
73
|
+
exports.isIpad = isIpad;
|
|
74
|
+
exports.isMobile = isMobile;
|
|
75
|
+
exports.isSafari = isSafari;
|
|
76
|
+
exports.isWx = isWx;
|
|
77
|
+
exports.isWxApp = isWxApp;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/select/hooks/useDebouncedSearch.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* 防抖搜索 Hook
|
|
4
|
+
* 对用户输入进行防抖处理,避免频繁触发搜索
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 防抖搜索 Hook
|
|
8
|
+
* @template T 值的类型
|
|
9
|
+
* @param initialValue 初始值
|
|
10
|
+
* @param delay 防抖延迟时间(毫秒)
|
|
11
|
+
* @param callback 防抖后的回调函数
|
|
12
|
+
* @returns [防抖后的值, 设置值函数]
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const [debouncedSearch, setSearchInput] = useDebouncedSearch('', 300, (text) => {
|
|
17
|
+
* console.log('搜索关键词:', text);
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function useDebouncedSearch<T = string>(initialValue: T, delay: number, callback?: (value: T) => void): [T, (value: T) => void];
|
|
22
|
+
//#endregion
|
|
23
|
+
export { useDebouncedSearch };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require("../../_virtual/_rolldown/runtime.js");
|
|
2
|
+
let react = require("react");
|
|
3
|
+
//#region src/select/hooks/useDebouncedSearch.ts
|
|
4
|
+
/**
|
|
5
|
+
* 防抖搜索 Hook
|
|
6
|
+
* 对用户输入进行防抖处理,避免频繁触发搜索
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 防抖搜索 Hook
|
|
10
|
+
* @template T 值的类型
|
|
11
|
+
* @param initialValue 初始值
|
|
12
|
+
* @param delay 防抖延迟时间(毫秒)
|
|
13
|
+
* @param callback 防抖后的回调函数
|
|
14
|
+
* @returns [防抖后的值, 设置值函数]
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* const [debouncedSearch, setSearchInput] = useDebouncedSearch('', 300, (text) => {
|
|
19
|
+
* console.log('搜索关键词:', text);
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function useDebouncedSearch(initialValue, delay, callback) {
|
|
24
|
+
const [value, setValue] = (0, react.useState)(initialValue);
|
|
25
|
+
const [debouncedValue, setDebouncedValue] = (0, react.useState)(initialValue);
|
|
26
|
+
(0, react.useEffect)(() => {
|
|
27
|
+
const timer = setTimeout(() => {
|
|
28
|
+
setDebouncedValue(value);
|
|
29
|
+
callback === null || callback === void 0 || callback(value);
|
|
30
|
+
}, delay);
|
|
31
|
+
return () => {
|
|
32
|
+
clearTimeout(timer);
|
|
33
|
+
};
|
|
34
|
+
}, [
|
|
35
|
+
value,
|
|
36
|
+
delay,
|
|
37
|
+
callback
|
|
38
|
+
]);
|
|
39
|
+
return [debouncedValue, setValue];
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
exports.useDebouncedSearch = useDebouncedSearch;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MultipleSelectState, SelectState, UseMultipleSelectStateOptions, UseSelectStateOptions } from "../types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/select/hooks/useSelectState.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* 单选状态管理 Hook
|
|
6
|
+
* @template T 值的类型
|
|
7
|
+
* @param options Hook 配置选项
|
|
8
|
+
* @returns 状态管理对象
|
|
9
|
+
*/
|
|
10
|
+
declare function useSelectState<T = string | number>(options: UseSelectStateOptions<T>): SelectState<T>;
|
|
11
|
+
/**
|
|
12
|
+
* 多选状态管理 Hook
|
|
13
|
+
* @template T 值的类型
|
|
14
|
+
* @param options Hook 配置选项
|
|
15
|
+
* @returns 状态管理对象
|
|
16
|
+
*/
|
|
17
|
+
declare function useMultipleSelectState<T = string | number>(options: UseMultipleSelectStateOptions<T>): MultipleSelectState<T>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { useMultipleSelectState, useSelectState };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require("../../_virtual/_rolldown/runtime.js");
|
|
2
|
+
let react = require("react");
|
|
3
|
+
//#region src/select/hooks/useSelectState.ts
|
|
4
|
+
/**
|
|
5
|
+
* Select 状态管理 Hook
|
|
6
|
+
* 处理受控/非受控模式,适用于单选和多选
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 单选状态管理 Hook
|
|
10
|
+
* @template T 值的类型
|
|
11
|
+
* @param options Hook 配置选项
|
|
12
|
+
* @returns 状态管理对象
|
|
13
|
+
*/
|
|
14
|
+
function useSelectState(options) {
|
|
15
|
+
const { value: controlledValue, defaultValue, onChange } = options;
|
|
16
|
+
const isControlled = controlledValue !== void 0;
|
|
17
|
+
const [internalValue, setInternalValue] = (0, react.useState)(defaultValue !== null && defaultValue !== void 0 ? defaultValue : null);
|
|
18
|
+
const value = isControlled ? controlledValue : internalValue;
|
|
19
|
+
const setValue = (0, react.useCallback)((newValue) => {
|
|
20
|
+
if (!isControlled) setInternalValue(newValue);
|
|
21
|
+
onChange === null || onChange === void 0 || onChange(newValue, null);
|
|
22
|
+
}, [isControlled, onChange]);
|
|
23
|
+
return {
|
|
24
|
+
value,
|
|
25
|
+
setValue,
|
|
26
|
+
clearValue: (0, react.useCallback)(() => {
|
|
27
|
+
setValue(null);
|
|
28
|
+
}, [setValue])
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 多选状态管理 Hook
|
|
33
|
+
* @template T 值的类型
|
|
34
|
+
* @param options Hook 配置选项
|
|
35
|
+
* @returns 状态管理对象
|
|
36
|
+
*/
|
|
37
|
+
function useMultipleSelectState(options) {
|
|
38
|
+
const { value: controlledValue, defaultValue, onChange } = options;
|
|
39
|
+
const isControlled = controlledValue !== void 0;
|
|
40
|
+
const [internalValue, setInternalValue] = (0, react.useState)(defaultValue !== null && defaultValue !== void 0 ? defaultValue : []);
|
|
41
|
+
const value = isControlled ? controlledValue !== null && controlledValue !== void 0 ? controlledValue : [] : internalValue;
|
|
42
|
+
const setValue = (0, react.useCallback)((newValue) => {
|
|
43
|
+
if (!isControlled) setInternalValue(newValue);
|
|
44
|
+
onChange === null || onChange === void 0 || onChange(newValue, []);
|
|
45
|
+
}, [isControlled, onChange]);
|
|
46
|
+
return {
|
|
47
|
+
value,
|
|
48
|
+
setValue,
|
|
49
|
+
addValue: (0, react.useCallback)((val) => {
|
|
50
|
+
setValue([...value, val]);
|
|
51
|
+
}, [value, setValue]),
|
|
52
|
+
removeValue: (0, react.useCallback)((val) => {
|
|
53
|
+
setValue(value.filter((v) => v !== val));
|
|
54
|
+
}, [value, setValue]),
|
|
55
|
+
clearValue: (0, react.useCallback)(() => {
|
|
56
|
+
setValue([]);
|
|
57
|
+
}, [setValue])
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
exports.useMultipleSelectState = useMultipleSelectState;
|
|
62
|
+
exports.useSelectState = useSelectState;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BaseSelectProps, FilterOptionFunc, MultipleSelectState, SelectOption, SelectState, SortDirection, TagDisplayInfo, UseMultipleSelectStateOptions, UseSelectStateOptions } from "./types.js";
|
|
2
|
+
import { useMultipleSelectState, useSelectState } from "./hooks/useSelectState.js";
|
|
3
|
+
import { useDebouncedSearch } from "./hooks/useDebouncedSearch.js";
|
|
4
|
+
import { calculateTagDisplay } from "./utils/tagAggregation.js";
|
|
5
|
+
import { defaultFilterOption, filterOptions } from "./utils/filterOptions.js";
|
|
6
|
+
import { sortOptions } from "./utils/sortOptions.js";
|
|
7
|
+
import { findOptionByValue, findOptionsByValues, generateId, isOptionSelected, isOptionSelectedInMultiple } from "./utils/helpers.js";
|