@pisell/utils 3.0.5 → 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 +12 -11
- 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 +51 -0
- package/es/otherUtils.js +71 -129
- 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 +12 -11
- 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 +51 -0
- package/lib/otherUtils.js +86 -98
- 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/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/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/es/locales.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
formatLocale: (_locale: string) => string;
|
|
1
|
+
//#region src/locales.d.ts
|
|
2
|
+
declare const locales: {
|
|
3
|
+
init: (_localeMaps: any, _locale: string) => void;
|
|
4
|
+
getText: (id: string) => any;
|
|
5
|
+
getLocale: () => string;
|
|
6
|
+
locale: string;
|
|
7
|
+
localeMap: any;
|
|
8
|
+
localeMaps: any;
|
|
9
|
+
formatLocale: (_locale: string) => string;
|
|
12
10
|
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { locales };
|
package/es/locales.js
CHANGED
|
@@ -1,75 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
en: {},
|
|
10
|
-
'zh-CN': {},
|
|
11
|
-
'zh-HK': {}
|
|
1
|
+
import { _objectSpread2 } from "./_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
|
|
2
|
+
//#region src/locales.ts
|
|
3
|
+
let localeMaps = {
|
|
4
|
+
en: {},
|
|
5
|
+
"zh-CN": {},
|
|
6
|
+
"zh-HK": {},
|
|
7
|
+
"ja": {},
|
|
8
|
+
"pt": {}
|
|
12
9
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
10
|
+
let locale = "en";
|
|
11
|
+
let localeMap = {};
|
|
12
|
+
const formatLocale = (_locale) => {
|
|
13
|
+
const obj = {
|
|
14
|
+
en: "en",
|
|
15
|
+
"en-US": "en",
|
|
16
|
+
"en-us": "en",
|
|
17
|
+
"zh-CN": "zh-CN",
|
|
18
|
+
"zh-cn": "zh-CN",
|
|
19
|
+
"zh-HK": "zh-HK",
|
|
20
|
+
"zh-hk": "zh-HK",
|
|
21
|
+
"zh-TW": "zh-HK",
|
|
22
|
+
"zh-tw": "zh-HK",
|
|
23
|
+
ja: "ja",
|
|
24
|
+
"ja-JP": "ja",
|
|
25
|
+
"ja-jp": "ja",
|
|
26
|
+
pt: "pt",
|
|
27
|
+
"pt-BR": "pt",
|
|
28
|
+
"pt-br": "pt",
|
|
29
|
+
"pt-PT": "pt",
|
|
30
|
+
"pt-pt": "pt"
|
|
31
|
+
};
|
|
32
|
+
const direct = obj[_locale];
|
|
33
|
+
if (direct) return direct;
|
|
34
|
+
const norm = String(_locale || "").trim().replace(/_/g, "-").toLowerCase();
|
|
35
|
+
if (obj[norm]) return obj[norm];
|
|
36
|
+
if (norm.startsWith("ja")) return "ja";
|
|
37
|
+
if (norm.startsWith("pt")) return "pt";
|
|
38
|
+
if (norm.startsWith("zh-hk") || norm.startsWith("zh-tw")) return "zh-HK";
|
|
39
|
+
if (norm.startsWith("zh-cn")) return "zh-CN";
|
|
40
|
+
if (norm.startsWith("en")) return "en";
|
|
41
|
+
return "en";
|
|
30
42
|
};
|
|
31
|
-
|
|
32
43
|
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// 更新语言
|
|
50
|
-
localeMaps = allLocales;
|
|
51
|
-
|
|
52
|
-
// 更新当前语言对应的多语言
|
|
53
|
-
localeMap = localeMaps[locale];
|
|
54
|
-
console.log('多语言注入成功, 当前语言为:' + locale);
|
|
44
|
+
* @title: 初始化多语言
|
|
45
|
+
* @description:
|
|
46
|
+
* @param {any} _localeMaps
|
|
47
|
+
* @param {string} _locale
|
|
48
|
+
* @return {*}
|
|
49
|
+
* @Author: zhiwei.Wang
|
|
50
|
+
* @Date: 2024-01-17 21:38
|
|
51
|
+
*/
|
|
52
|
+
const init = (_localeMaps, _locale) => {
|
|
53
|
+
locale = formatLocale(_locale);
|
|
54
|
+
let allLocales = {};
|
|
55
|
+
for (let key in localeMaps) allLocales[key] = _objectSpread2(_objectSpread2({}, localeMaps[key]), _localeMaps[key]);
|
|
56
|
+
localeMaps = allLocales;
|
|
57
|
+
localeMap = localeMaps[locale];
|
|
55
58
|
};
|
|
56
|
-
|
|
57
59
|
/**
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
* @title: 获取语言
|
|
61
|
+
* @description:
|
|
62
|
+
* @param {string} id
|
|
63
|
+
* @return {*}
|
|
64
|
+
* @Author: zhiwei.Wang
|
|
65
|
+
* @Date: 2024-01-17 21:39
|
|
66
|
+
*/
|
|
67
|
+
const getText = (id) => {
|
|
68
|
+
var _localeMaps$en;
|
|
69
|
+
return localeMap[id] || (localeMaps === null || localeMaps === void 0 || (_localeMaps$en = localeMaps["en"]) === null || _localeMaps$en === void 0 ? void 0 : _localeMaps$en[id]) || id;
|
|
67
70
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
/** 获取当前语言(与 getText 同源,供 datetime 等组件与 getText 语言一致) */
|
|
72
|
+
const getLocale = () => {
|
|
73
|
+
return locale;
|
|
74
|
+
};
|
|
75
|
+
const locales = {
|
|
76
|
+
init,
|
|
77
|
+
getText,
|
|
78
|
+
getLocale,
|
|
79
|
+
locale,
|
|
80
|
+
localeMap,
|
|
81
|
+
localeMaps,
|
|
82
|
+
formatLocale
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
85
|
+
export { locales };
|
package/es/log.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
//#region src/log.d.ts
|
|
1
2
|
interface contentItem {
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
key: string;
|
|
4
|
+
value: string;
|
|
4
5
|
}
|
|
5
6
|
interface sendWebhookProps {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
title: string;
|
|
8
|
+
content: contentItem[];
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
declare const sendWarningLog: ({
|
|
11
|
+
title,
|
|
12
|
+
content
|
|
13
|
+
}: sendWebhookProps) => Promise<any>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { sendWarningLog };
|
package/es/log.js
CHANGED
|
@@ -1,60 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}];
|
|
16
|
-
}));
|
|
1
|
+
import { _asyncToGenerator } from "./_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
|
|
2
|
+
import { webHookApi } from "./constants/index.js";
|
|
3
|
+
import { getPisellUtilsConfig } from "./index.js";
|
|
4
|
+
//#region src/log.ts
|
|
5
|
+
const createFeishuMessageContent = (contentArr) => {
|
|
6
|
+
return JSON.stringify(contentArr.map((item) => {
|
|
7
|
+
return [{
|
|
8
|
+
tag: "text",
|
|
9
|
+
text: `${item.key}: `
|
|
10
|
+
}, {
|
|
11
|
+
tag: "text",
|
|
12
|
+
text: `${item.value}`
|
|
13
|
+
}];
|
|
14
|
+
}));
|
|
17
15
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
msg_type: 'post',
|
|
42
|
-
content: "{\"post\":{\"zh_cn\":{\"title\":\"".concat(title, "\",\"content\":").concat(contentStr, "}}}")
|
|
43
|
-
})
|
|
44
|
-
});
|
|
45
|
-
case 8:
|
|
46
|
-
response = _context.sent;
|
|
47
|
-
_context.next = 11;
|
|
48
|
-
return response.json();
|
|
49
|
-
case 11:
|
|
50
|
-
return _context.abrupt("return", _context.sent);
|
|
51
|
-
case 12:
|
|
52
|
-
case "end":
|
|
53
|
-
return _context.stop();
|
|
54
|
-
}
|
|
55
|
-
}, _callee);
|
|
56
|
-
}));
|
|
57
|
-
return function sendWarningLog(_x) {
|
|
58
|
-
return _ref2.apply(this, arguments);
|
|
59
|
-
};
|
|
60
|
-
}();
|
|
16
|
+
const sendWarningLog = function() {
|
|
17
|
+
var _ref = _asyncToGenerator(function* ({ title, content }) {
|
|
18
|
+
const contentStr = createFeishuMessageContent(content);
|
|
19
|
+
let apiUrl = "";
|
|
20
|
+
const config = getPisellUtilsConfig();
|
|
21
|
+
console.log("PISELL_UTILS_CONFIG>>>>", config);
|
|
22
|
+
if ((config === null || config === void 0 ? void 0 : config.env) === "dev" || (config === null || config === void 0 ? void 0 : config.env) === "pre" || (config === null || config === void 0 ? void 0 : config.env) === "release") apiUrl = webHookApi.warning_log.test;
|
|
23
|
+
else apiUrl = webHookApi.warning_log.prod;
|
|
24
|
+
return yield (yield fetch(apiUrl, {
|
|
25
|
+
headers: { "Content-Type": "application/json" },
|
|
26
|
+
method: "POST",
|
|
27
|
+
body: JSON.stringify({
|
|
28
|
+
msg_type: "post",
|
|
29
|
+
content: `{"post":{"zh_cn":{"title":"${title}","content":${contentStr}}}}`
|
|
30
|
+
})
|
|
31
|
+
})).json();
|
|
32
|
+
});
|
|
33
|
+
return function sendWarningLog(_x) {
|
|
34
|
+
return _ref.apply(this, arguments);
|
|
35
|
+
};
|
|
36
|
+
}();
|
|
37
|
+
//#endregion
|
|
38
|
+
export { sendWarningLog };
|
package/es/miniRedux.d.ts
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
|
+
//#region src/miniRedux.d.ts
|
|
1
2
|
interface MiniReduxProps<State, Namespace> {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
namespace?: Namespace;
|
|
4
|
+
state?: State;
|
|
5
|
+
reducers?: any;
|
|
6
|
+
effects?: any;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
declare const miniRedux: <State extends Record<string, any>, Namespace extends string>({
|
|
9
|
+
namespace,
|
|
10
|
+
state,
|
|
11
|
+
reducers,
|
|
12
|
+
effects
|
|
13
|
+
}: MiniReduxProps<State, Namespace>) => {
|
|
14
|
+
Context: React.Context<{ [K in Namespace]: State } & {
|
|
15
|
+
dispatch: (params: {
|
|
16
|
+
type: string;
|
|
17
|
+
payload: any;
|
|
18
|
+
}) => void;
|
|
19
|
+
}>;
|
|
20
|
+
Provider: (ComponentUi: any) => any;
|
|
15
21
|
};
|
|
16
|
-
|
|
22
|
+
//#endregion
|
|
23
|
+
export { miniRedux };
|
package/es/miniRedux.js
CHANGED
|
@@ -1,71 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (effects[type]) {
|
|
44
|
-
effects[type].call(null, stateRef.current, payload, dispatch);
|
|
45
|
-
} else if (reducers[type]) {
|
|
46
|
-
dispatch({
|
|
47
|
-
type: type,
|
|
48
|
-
payload: payload
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}, []);
|
|
52
|
-
var _props = _objectSpread(_objectSpread({}, props), {}, _defineProperty(_defineProperty({}, namespace, providerState), "dispatch", _dispatch));
|
|
53
|
-
var _ref = null;
|
|
54
|
-
if (_props.forwardedRef) {
|
|
55
|
-
_ref = _props.forwardedRef;
|
|
56
|
-
delete _props.forwardedRef;
|
|
57
|
-
}
|
|
58
|
-
return /*#__PURE__*/_jsx(Context.Provider, {
|
|
59
|
-
value: _defineProperty(_defineProperty({}, namespace, providerState), "dispatch", _dispatch),
|
|
60
|
-
children: /*#__PURE__*/_jsx(ComponentUi, _objectSpread(_objectSpread({}, _props), {}, {
|
|
61
|
-
ref: ref
|
|
62
|
-
}))
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
return Components;
|
|
66
|
-
};
|
|
67
|
-
return {
|
|
68
|
-
Context: Context,
|
|
69
|
-
Provider: Provider
|
|
70
|
-
};
|
|
71
|
-
};
|
|
1
|
+
import { _objectSpread2 } from "./_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
|
|
2
|
+
import React, { createContext, forwardRef, useCallback, useMemo, useReducer, useRef } from "react";
|
|
3
|
+
//#region src/miniRedux.tsx
|
|
4
|
+
const miniRedux = ({ namespace = "state", state, reducers = {}, effects = {} }) => {
|
|
5
|
+
const Context = createContext({});
|
|
6
|
+
const Provider = (ComponentUi) => {
|
|
7
|
+
return forwardRef((props, ref) => {
|
|
8
|
+
const stateRef = useRef();
|
|
9
|
+
const [providerState, dispatch] = useReducer((state, { type, payload }) => {
|
|
10
|
+
if (reducers[type]) return reducers[type](state, payload) || state;
|
|
11
|
+
else return state;
|
|
12
|
+
}, state);
|
|
13
|
+
stateRef.current = providerState;
|
|
14
|
+
const _dispatch = useCallback(({ type, payload }) => {
|
|
15
|
+
if (effects[type]) effects[type].call(null, stateRef.current, payload, dispatch);
|
|
16
|
+
else if (reducers[type]) dispatch({
|
|
17
|
+
type,
|
|
18
|
+
payload
|
|
19
|
+
});
|
|
20
|
+
}, []);
|
|
21
|
+
const contextValue = useMemo(() => ({
|
|
22
|
+
[namespace]: providerState,
|
|
23
|
+
dispatch: _dispatch
|
|
24
|
+
}), [providerState, _dispatch]);
|
|
25
|
+
let _props = _objectSpread2(_objectSpread2({}, props), {}, {
|
|
26
|
+
[namespace]: providerState,
|
|
27
|
+
dispatch: _dispatch
|
|
28
|
+
});
|
|
29
|
+
if (_props.forwardedRef) {
|
|
30
|
+
_props.forwardedRef;
|
|
31
|
+
delete _props.forwardedRef;
|
|
32
|
+
}
|
|
33
|
+
return /* @__PURE__ */ React.createElement(Context.Provider, { value: contextValue }, /* @__PURE__ */ React.createElement(ComponentUi, _objectSpread2(_objectSpread2({}, _props), {}, { ref })));
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
Context,
|
|
38
|
+
Provider
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
//#endregion
|
|
42
|
+
export { miniRedux };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BaseNumberInputProps, NumberInputState } from "../types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/number-input/hooks/useNumberInputState.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* 数值输入状态管理 Hook
|
|
6
|
+
*
|
|
7
|
+
* 管理组件的内部状态,包括:
|
|
8
|
+
* - 值管理(受控/非受控模式)
|
|
9
|
+
* - 校验状态管理
|
|
10
|
+
* - 事件处理函数封装
|
|
11
|
+
*
|
|
12
|
+
* 支持受控和非受控两种模式:
|
|
13
|
+
* - 受控模式:value 由外部传入,组件不维护内部状态
|
|
14
|
+
* - 非受控模式:使用 defaultValue,组件维护内部状态
|
|
15
|
+
*
|
|
16
|
+
* @param props 组件 Props(包含校验配置)
|
|
17
|
+
* @returns 数值输入状态对象
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // 受控模式
|
|
21
|
+
* const state = useNumberInputState({ value: 10, onChange: (v) => console.log(v) });
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // 非受控模式
|
|
25
|
+
* const state = useNumberInputState({ defaultValue: 10, min: 0, max: 100 });
|
|
26
|
+
*/
|
|
27
|
+
declare function useNumberInputState(props: BaseNumberInputProps): NumberInputState;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { useNumberInputState };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { validateValue } from "../utils/validation.js";
|
|
2
|
+
import { useCallback, useState } from "react";
|
|
3
|
+
//#region src/number-input/hooks/useNumberInputState.ts
|
|
4
|
+
/**
|
|
5
|
+
* 数值输入状态管理 Hook
|
|
6
|
+
*
|
|
7
|
+
* 管理组件的内部状态,包括:
|
|
8
|
+
* - 值管理(受控/非受控模式)
|
|
9
|
+
* - 校验状态管理
|
|
10
|
+
* - 事件处理函数封装
|
|
11
|
+
*
|
|
12
|
+
* 支持受控和非受控两种模式:
|
|
13
|
+
* - 受控模式:value 由外部传入,组件不维护内部状态
|
|
14
|
+
* - 非受控模式:使用 defaultValue,组件维护内部状态
|
|
15
|
+
*
|
|
16
|
+
* @param props 组件 Props(包含校验配置)
|
|
17
|
+
* @returns 数值输入状态对象
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // 受控模式
|
|
21
|
+
* const state = useNumberInputState({ value: 10, onChange: (v) => console.log(v) });
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // 非受控模式
|
|
25
|
+
* const state = useNumberInputState({ defaultValue: 10, min: 0, max: 100 });
|
|
26
|
+
*/
|
|
27
|
+
function useNumberInputState(props) {
|
|
28
|
+
var _props$defaultValue;
|
|
29
|
+
const isControlled = props.value !== void 0;
|
|
30
|
+
const [innerValue, setInnerValue] = useState((_props$defaultValue = props.defaultValue) !== null && _props$defaultValue !== void 0 ? _props$defaultValue : null);
|
|
31
|
+
const [isTouched, setIsTouched] = useState(false);
|
|
32
|
+
const [isValid, setIsValid] = useState(true);
|
|
33
|
+
const [errors, setErrors] = useState([]);
|
|
34
|
+
const currentValue = isControlled ? props.value : innerValue;
|
|
35
|
+
return {
|
|
36
|
+
value: currentValue,
|
|
37
|
+
isTouched,
|
|
38
|
+
isValid,
|
|
39
|
+
errors,
|
|
40
|
+
handleChange: useCallback((newValue) => {
|
|
41
|
+
var _props$onChange;
|
|
42
|
+
if (!isControlled) setInnerValue(newValue);
|
|
43
|
+
if (props.validateTrigger === "onChange" || props.validateTrigger === "both") {
|
|
44
|
+
var _props$onValidate;
|
|
45
|
+
const validation = validateValue(newValue, props);
|
|
46
|
+
setIsValid(validation.isValid);
|
|
47
|
+
setErrors(validation.errors);
|
|
48
|
+
(_props$onValidate = props.onValidate) === null || _props$onValidate === void 0 || _props$onValidate.call(props, validation.isValid, validation.errors);
|
|
49
|
+
}
|
|
50
|
+
(_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, newValue);
|
|
51
|
+
}, [isControlled, props]),
|
|
52
|
+
handleBlur: useCallback(() => {
|
|
53
|
+
var _props$onBlur;
|
|
54
|
+
setIsTouched(true);
|
|
55
|
+
if (props.validateTrigger !== "onChange") {
|
|
56
|
+
var _props$onValidate2;
|
|
57
|
+
const validation = validateValue(currentValue, props);
|
|
58
|
+
setIsValid(validation.isValid);
|
|
59
|
+
setErrors(validation.errors);
|
|
60
|
+
(_props$onValidate2 = props.onValidate) === null || _props$onValidate2 === void 0 || _props$onValidate2.call(props, validation.isValid, validation.errors);
|
|
61
|
+
}
|
|
62
|
+
(_props$onBlur = props.onBlur) === null || _props$onBlur === void 0 || _props$onBlur.call(props, currentValue !== null && currentValue !== void 0 ? currentValue : null);
|
|
63
|
+
}, [currentValue, props]),
|
|
64
|
+
handleFocus: useCallback(() => {
|
|
65
|
+
var _props$onFocus;
|
|
66
|
+
setIsTouched(true);
|
|
67
|
+
(_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 || _props$onFocus.call(props);
|
|
68
|
+
}, [props])
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
export { useNumberInputState };
|