@pisell/utils 3.0.5 → 3.0.7
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/arrayUtils.d.ts +72 -0
- package/es/arrayUtils.js +142 -3
- package/es/common/index.d.ts +5 -0
- package/es/common/index.js +5 -0
- package/es/common/stateHelper.d.ts +18 -0
- package/es/common/stateHelper.js +25 -0
- package/es/common/types.d.ts +28 -0
- package/es/common/types.js +1 -0
- package/es/componentStorage.d.ts +36 -0
- package/es/componentStorage.js +142 -0
- package/es/format.d.ts +5 -1
- package/es/format.js +53 -8
- package/es/index.d.ts +6 -0
- package/es/index.js +6 -0
- package/es/jsBridge/index.d.ts +9 -105
- package/es/jsBridge/index.js +28 -12
- package/es/jsBridge/types.d.ts +149 -0
- package/es/jsBridge/types.js +1 -0
- package/es/locales.d.ts +2 -5
- package/es/locales.js +36 -7
- package/es/miniRedux.js +7 -2
- package/es/number-input/hooks/index.d.ts +4 -0
- package/es/number-input/hooks/index.js +5 -0
- package/es/number-input/hooks/useNumberInputState.d.ts +25 -0
- package/es/number-input/hooks/useNumberInputState.js +129 -0
- package/es/number-input/index.d.ts +14 -0
- package/es/number-input/index.js +21 -0
- package/es/number-input/types.d.ts +96 -0
- package/es/number-input/types.js +1 -0
- package/es/number-input/utils/formatter.d.ts +53 -0
- package/es/number-input/utils/formatter.js +82 -0
- package/es/number-input/utils/index.d.ts +7 -0
- package/es/number-input/utils/index.js +8 -0
- package/es/number-input/utils/validation.d.ts +27 -0
- package/es/number-input/utils/validation.js +67 -0
- package/es/otherUtils.d.ts +48 -0
- package/es/select/hooks/index.d.ts +5 -0
- package/es/select/hooks/index.js +6 -0
- package/es/select/hooks/useDebouncedSearch.d.ts +20 -0
- package/es/select/hooks/useDebouncedSearch.js +55 -0
- package/es/select/hooks/useSelectState.d.ts +19 -0
- package/es/select/hooks/useSelectState.js +117 -0
- package/es/select/index.d.ts +8 -0
- package/es/select/index.js +13 -0
- package/es/select/types.d.ts +256 -0
- package/es/select/types.js +1 -0
- package/es/select/utils/filterOptions.d.ts +22 -0
- package/es/select/utils/filterOptions.js +34 -0
- package/es/select/utils/helpers.d.ts +42 -0
- package/es/select/utils/helpers.js +61 -0
- package/es/select/utils/index.d.ts +7 -0
- package/es/select/utils/index.js +8 -0
- package/es/select/utils/sortOptions.d.ts +12 -0
- package/es/select/utils/sortOptions.js +32 -0
- package/es/select/utils/tagAggregation.d.ts +25 -0
- package/es/select/utils/tagAggregation.js +48 -0
- package/es/text-input/hooks/index.d.ts +4 -0
- package/es/text-input/hooks/index.js +5 -0
- package/es/text-input/hooks/useTextInputState.d.ts +24 -0
- package/es/text-input/hooks/useTextInputState.js +127 -0
- package/es/text-input/index.d.ts +14 -0
- package/es/text-input/index.js +20 -0
- package/es/text-input/types.d.ts +56 -0
- package/es/text-input/types.js +1 -0
- package/es/text-input/utils/index.d.ts +5 -0
- package/es/text-input/utils/index.js +7 -0
- package/es/text-input/utils/validation.d.ts +23 -0
- package/es/text-input/utils/validation.js +71 -0
- package/es/walletValidity.d.ts +55 -0
- package/es/walletValidity.js +143 -38
- package/es/weighing.d.ts +62 -0
- package/es/weighing.js +119 -0
- package/lib/arrayUtils.d.ts +72 -0
- package/lib/arrayUtils.js +75 -0
- package/lib/common/index.d.ts +5 -0
- package/lib/common/index.js +29 -0
- package/lib/common/stateHelper.d.ts +18 -0
- package/lib/common/stateHelper.js +34 -0
- package/lib/common/types.d.ts +28 -0
- package/lib/common/types.js +17 -0
- package/lib/componentStorage.d.ts +36 -0
- package/lib/componentStorage.js +144 -0
- package/lib/format.d.ts +5 -1
- package/lib/format.js +45 -5
- package/lib/index.d.ts +6 -0
- package/lib/index.js +13 -1
- package/lib/jsBridge/index.d.ts +9 -105
- package/lib/jsBridge/index.js +20 -1
- package/lib/jsBridge/types.d.ts +149 -0
- package/lib/jsBridge/types.js +17 -0
- package/lib/locales.d.ts +2 -5
- package/lib/locales.js +34 -7
- package/lib/miniRedux.js +5 -7
- package/lib/number-input/hooks/index.d.ts +4 -0
- package/lib/number-input/hooks/index.js +29 -0
- package/lib/number-input/hooks/useNumberInputState.d.ts +25 -0
- package/lib/number-input/hooks/useNumberInputState.js +83 -0
- package/lib/number-input/index.d.ts +14 -0
- package/lib/number-input/index.js +41 -0
- package/lib/number-input/types.d.ts +96 -0
- package/lib/number-input/types.js +17 -0
- package/lib/number-input/utils/formatter.d.ts +53 -0
- package/lib/number-input/utils/formatter.js +55 -0
- package/lib/number-input/utils/index.d.ts +7 -0
- package/lib/number-input/utils/index.js +39 -0
- package/lib/number-input/utils/validation.d.ts +27 -0
- package/lib/number-input/utils/validation.js +54 -0
- package/lib/otherUtils.d.ts +48 -0
- package/lib/select/hooks/index.d.ts +5 -0
- package/lib/select/hooks/index.js +34 -0
- package/lib/select/hooks/useDebouncedSearch.d.ts +20 -0
- package/lib/select/hooks/useDebouncedSearch.js +43 -0
- package/lib/select/hooks/useSelectState.d.ts +19 -0
- package/lib/select/hooks/useSelectState.js +97 -0
- package/lib/select/index.d.ts +8 -0
- package/lib/select/index.js +53 -0
- package/lib/select/types.d.ts +256 -0
- package/lib/select/types.js +17 -0
- package/lib/select/utils/filterOptions.d.ts +22 -0
- package/lib/select/utils/filterOptions.js +41 -0
- package/lib/select/utils/helpers.d.ts +42 -0
- package/lib/select/utils/helpers.js +51 -0
- package/lib/select/utils/index.d.ts +7 -0
- package/lib/select/utils/index.js +48 -0
- package/lib/select/utils/sortOptions.d.ts +12 -0
- package/lib/select/utils/sortOptions.js +41 -0
- package/lib/select/utils/tagAggregation.d.ts +25 -0
- package/lib/select/utils/tagAggregation.js +43 -0
- package/lib/text-input/hooks/index.d.ts +4 -0
- package/lib/text-input/hooks/index.js +29 -0
- package/lib/text-input/hooks/useTextInputState.d.ts +24 -0
- package/lib/text-input/hooks/useTextInputState.js +81 -0
- package/lib/text-input/index.d.ts +14 -0
- package/lib/text-input/index.js +35 -0
- package/lib/text-input/types.d.ts +56 -0
- package/lib/text-input/types.js +17 -0
- package/lib/text-input/utils/index.d.ts +5 -0
- package/lib/text-input/utils/index.js +32 -0
- package/lib/text-input/utils/validation.d.ts +23 -0
- package/lib/text-input/utils/validation.js +60 -0
- package/lib/walletValidity.d.ts +55 -0
- package/lib/walletValidity.js +120 -40
- package/lib/weighing.d.ts +62 -0
- package/lib/weighing.js +159 -0
- package/package.json +1 -1
- package/es/date.d.ts +0 -28
- package/es/document.d.ts +0 -13
- package/es/firebase/config/index.d.ts +0 -13
- package/es/firebase/index.d.ts +0 -28
- package/es/image.d.ts +0 -11
- package/es/typeUtils.d.ts +0 -42
- package/lib/date.d.ts +0 -28
- package/lib/document.d.ts +0 -13
- package/lib/firebase/config/index.d.ts +0 -13
- package/lib/firebase/index.d.ts +0 -28
- package/lib/image.d.ts +0 -11
- package/lib/typeUtils.d.ts +0 -42
package/es/jsBridge/index.d.ts
CHANGED
|
@@ -1,113 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
en: number;
|
|
3
|
-
zh_CN: number;
|
|
4
|
-
zh_HK: number;
|
|
5
|
-
};
|
|
6
|
-
declare type LanguageString = {
|
|
7
|
-
en: string;
|
|
8
|
-
zh_CN: string;
|
|
9
|
-
zh_HK: string;
|
|
10
|
-
} | string;
|
|
11
|
-
/**
|
|
12
|
-
* 打印小票
|
|
13
|
-
*/
|
|
14
|
-
declare type WebPrint0 = {
|
|
15
|
-
/**
|
|
16
|
-
* 打印类型
|
|
17
|
-
* 0: 小票
|
|
18
|
-
* 1:ITS备货单/划菜单
|
|
19
|
-
* 2:手环
|
|
20
|
-
*/
|
|
21
|
-
type: "0";
|
|
22
|
-
data: {
|
|
23
|
-
/** 订单ID */
|
|
24
|
-
order_id: string;
|
|
25
|
-
};
|
|
26
|
-
/** 打印语言对应的数量 */
|
|
27
|
-
language: LanguageNumber;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* 打印ITS备货单/划菜单
|
|
31
|
-
*/
|
|
32
|
-
declare type WebPrint1 = {
|
|
33
|
-
/**
|
|
34
|
-
* 打印类型
|
|
35
|
-
* 0: 小票
|
|
36
|
-
* 1:ITS备货单/划菜单
|
|
37
|
-
* 2:手环
|
|
38
|
-
*/
|
|
39
|
-
type: "1";
|
|
40
|
-
data: {
|
|
41
|
-
/** 0:备货 1:划单 */
|
|
42
|
-
mode: "0" | "1";
|
|
43
|
-
resource: LanguageString;
|
|
44
|
-
/** 订单备注 */
|
|
45
|
-
order_note: string;
|
|
46
|
-
/** 订单时间或商品下单时间 */
|
|
47
|
-
time: string;
|
|
48
|
-
/** 订单编号 */
|
|
49
|
-
order_number?: string;
|
|
50
|
-
/** 商品 */
|
|
51
|
-
products: {
|
|
52
|
-
/** 商品名称 */
|
|
53
|
-
product_title: LanguageString;
|
|
54
|
-
/** 商品规格 */
|
|
55
|
-
product_option_string: LanguageString;
|
|
56
|
-
/** 商品备注 */
|
|
57
|
-
product_note: string;
|
|
58
|
-
/** 商品数量 */
|
|
59
|
-
product_quantity: number;
|
|
60
|
-
/** 加菜标识 待定 */
|
|
61
|
-
is_append?: boolean;
|
|
62
|
-
/** 退菜标识 待定 */
|
|
63
|
-
is_removed?: boolean;
|
|
64
|
-
}[];
|
|
65
|
-
};
|
|
66
|
-
/** 打印语言对应的数量 */
|
|
67
|
-
language: LanguageNumber;
|
|
68
|
-
};
|
|
69
|
-
declare type WebPrint2 = {
|
|
70
|
-
/**
|
|
71
|
-
* 打印类型
|
|
72
|
-
* 0: 小票
|
|
73
|
-
* 1:ITS备货单/划菜单
|
|
74
|
-
* 2:手环
|
|
75
|
-
*/
|
|
76
|
-
type: "2";
|
|
77
|
-
data: {
|
|
78
|
-
/** 0: 普通票 1:成人票 2:免费成人票 */
|
|
79
|
-
type: "0" | "1" | "2";
|
|
80
|
-
/** 发行编码 */
|
|
81
|
-
encoded: string;
|
|
82
|
-
/** 编码 */
|
|
83
|
-
code: string;
|
|
84
|
-
/** 到期时间 */
|
|
85
|
-
expire_date: string;
|
|
86
|
-
areas: {
|
|
87
|
-
/** 区域名字 */
|
|
88
|
-
area_name: string;
|
|
89
|
-
/** 区域代码 */
|
|
90
|
-
area_code: string;
|
|
91
|
-
/** 可用次数 */
|
|
92
|
-
limit_num: number;
|
|
93
|
-
/** 已用次数 */
|
|
94
|
-
used_num: number;
|
|
95
|
-
}[];
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
declare type WebPrintParams = WebPrint0 | WebPrint1 | WebPrint2;
|
|
1
|
+
import { WebPrintParams, DataManagerParams, WebPaymentParams } from './types';
|
|
99
2
|
/**
|
|
100
3
|
* webView页面中调用打印机打印
|
|
101
4
|
* 此api暂时只支持native app平台下ios手机
|
|
102
5
|
* @param params
|
|
103
6
|
* @param callback
|
|
104
7
|
*/
|
|
105
|
-
export declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void): void;
|
|
106
|
-
declare type DataManagerParams = {
|
|
107
|
-
module: "set" | "get";
|
|
108
|
-
key: string;
|
|
109
|
-
data?: any;
|
|
110
|
-
};
|
|
8
|
+
export declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
|
|
111
9
|
/**
|
|
112
10
|
* webView页面中调用APP内的数据
|
|
113
11
|
* 此api暂时只支持native app平台下ios手机
|
|
@@ -115,4 +13,10 @@ declare type DataManagerParams = {
|
|
|
115
13
|
* @param callback
|
|
116
14
|
*/
|
|
117
15
|
export declare function dataManager(params: DataManagerParams, callback: (...arg: any) => void, onError: () => void): void;
|
|
118
|
-
|
|
16
|
+
/**
|
|
17
|
+
* webView页面中调用APP内的支付
|
|
18
|
+
* 此api暂时只支持native app平台下ios
|
|
19
|
+
* @param params
|
|
20
|
+
* @param callback
|
|
21
|
+
*/
|
|
22
|
+
export declare function webPayment(params: WebPaymentParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
|
package/es/jsBridge/index.js
CHANGED
|
@@ -1,30 +1,25 @@
|
|
|
1
1
|
import regDeviceApi from "./regDeviceApi";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 打印小票
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 打印ITS备货单/划菜单
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
2
|
/**
|
|
12
3
|
* webView页面中调用打印机打印
|
|
13
4
|
* 此api暂时只支持native app平台下ios手机
|
|
14
5
|
* @param params
|
|
15
6
|
* @param callback
|
|
16
7
|
*/
|
|
17
|
-
export function webPrint(params, _callback) {
|
|
8
|
+
export function webPrint(params, _callback, onError) {
|
|
18
9
|
regDeviceApi().then(function (jsBridge) {
|
|
19
10
|
jsBridge.callDeviceApi({
|
|
20
|
-
apiName:
|
|
11
|
+
apiName: 'webPrint',
|
|
21
12
|
params: params,
|
|
22
13
|
callback: function callback() {
|
|
23
14
|
_callback && _callback.apply(void 0, arguments);
|
|
24
15
|
}
|
|
25
16
|
});
|
|
17
|
+
}).catch(function (err) {
|
|
18
|
+
onError === null || onError === void 0 || onError(err);
|
|
19
|
+
console.error('webPrint', err);
|
|
26
20
|
});
|
|
27
21
|
}
|
|
22
|
+
|
|
28
23
|
/**
|
|
29
24
|
* webView页面中调用APP内的数据
|
|
30
25
|
* 此api暂时只支持native app平台下ios手机
|
|
@@ -34,11 +29,32 @@ export function webPrint(params, _callback) {
|
|
|
34
29
|
export function dataManager(params, _callback2, onError) {
|
|
35
30
|
regDeviceApi().then(function (jsBridge) {
|
|
36
31
|
jsBridge.callDeviceApi({
|
|
37
|
-
apiName:
|
|
32
|
+
apiName: 'dataManager',
|
|
38
33
|
params: params,
|
|
39
34
|
callback: function callback() {
|
|
40
35
|
_callback2 && _callback2.apply(void 0, arguments);
|
|
41
36
|
}
|
|
42
37
|
});
|
|
43
38
|
}).catch(onError);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* webView页面中调用APP内的支付
|
|
43
|
+
* 此api暂时只支持native app平台下ios
|
|
44
|
+
* @param params
|
|
45
|
+
* @param callback
|
|
46
|
+
*/
|
|
47
|
+
export function webPayment(params, _callback3, onError) {
|
|
48
|
+
regDeviceApi().then(function (jsBridge) {
|
|
49
|
+
jsBridge.callDeviceApi({
|
|
50
|
+
apiName: 'webPayment',
|
|
51
|
+
params: params,
|
|
52
|
+
callback: function callback() {
|
|
53
|
+
_callback3 && _callback3.apply(void 0, arguments);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}).catch(function (err) {
|
|
57
|
+
onError === null || onError === void 0 || onError(err);
|
|
58
|
+
console.error('webPayment', err);
|
|
59
|
+
});
|
|
44
60
|
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
declare type LanguageNumber = {
|
|
2
|
+
en: number;
|
|
3
|
+
zh_CN: number;
|
|
4
|
+
zh_HK: number;
|
|
5
|
+
};
|
|
6
|
+
declare type LanguageString = {
|
|
7
|
+
en: string;
|
|
8
|
+
zh_CN: string;
|
|
9
|
+
zh_HK: string;
|
|
10
|
+
} | string;
|
|
11
|
+
/**
|
|
12
|
+
* 打印小票
|
|
13
|
+
*/
|
|
14
|
+
export declare type WebPrint0 = {
|
|
15
|
+
/**
|
|
16
|
+
* 打印类型
|
|
17
|
+
* 0: 小票
|
|
18
|
+
* 1:ITS备货单/划菜单
|
|
19
|
+
* 2:手环
|
|
20
|
+
*/
|
|
21
|
+
type: '0';
|
|
22
|
+
data: {
|
|
23
|
+
/** 订单ID */
|
|
24
|
+
order_id: string;
|
|
25
|
+
};
|
|
26
|
+
/** 打印语言对应的数量 */
|
|
27
|
+
language: LanguageNumber;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* 打印ITS备货单/划菜单
|
|
31
|
+
*/
|
|
32
|
+
export declare type WebPrint1 = {
|
|
33
|
+
/**
|
|
34
|
+
* 打印类型
|
|
35
|
+
* 0: 小票
|
|
36
|
+
* 1:ITS备货单/划菜单
|
|
37
|
+
* 2:手环
|
|
38
|
+
*/
|
|
39
|
+
type: '1';
|
|
40
|
+
data: {
|
|
41
|
+
/** 0:备货 1:划单 */
|
|
42
|
+
mode: '0' | '1';
|
|
43
|
+
resource: LanguageString;
|
|
44
|
+
/** 订单备注 */
|
|
45
|
+
order_note: string;
|
|
46
|
+
/** 订单时间或商品下单时间 */
|
|
47
|
+
time: string;
|
|
48
|
+
/** 订单编号 */
|
|
49
|
+
order_number?: string;
|
|
50
|
+
/** 商品 */
|
|
51
|
+
products: {
|
|
52
|
+
/** 商品名称 */
|
|
53
|
+
product_title: LanguageString;
|
|
54
|
+
/** 商品规格 */
|
|
55
|
+
product_option_string: LanguageString;
|
|
56
|
+
/** 商品备注 */
|
|
57
|
+
product_note: string;
|
|
58
|
+
/** 商品数量 */
|
|
59
|
+
product_quantity: number;
|
|
60
|
+
/** 加菜标识 待定 */
|
|
61
|
+
is_append?: boolean;
|
|
62
|
+
/** 退菜标识 待定 */
|
|
63
|
+
is_removed?: boolean;
|
|
64
|
+
}[];
|
|
65
|
+
};
|
|
66
|
+
/** 打印语言对应的数量 */
|
|
67
|
+
language: LanguageNumber;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* 打印手环
|
|
71
|
+
*/
|
|
72
|
+
export declare type WebPrint2 = {
|
|
73
|
+
/**
|
|
74
|
+
* 打印类型
|
|
75
|
+
* 0: 小票
|
|
76
|
+
* 1:ITS备货单/划菜单
|
|
77
|
+
* 2:手环
|
|
78
|
+
*/
|
|
79
|
+
type: '2';
|
|
80
|
+
data: {
|
|
81
|
+
/** 0: 普通票 1:成人票 2:免费成人票 */
|
|
82
|
+
type: '0' | '1' | '2';
|
|
83
|
+
/** 发行编码 */
|
|
84
|
+
encoded: string;
|
|
85
|
+
/** 编码 */
|
|
86
|
+
code: string;
|
|
87
|
+
/** 到期时间 */
|
|
88
|
+
expire_date: string;
|
|
89
|
+
areas: {
|
|
90
|
+
/** 区域名字 */
|
|
91
|
+
area_name: string;
|
|
92
|
+
/** 区域代码 */
|
|
93
|
+
area_code: string;
|
|
94
|
+
/** 可用次数 */
|
|
95
|
+
limit_num: number;
|
|
96
|
+
/** 已用次数 */
|
|
97
|
+
used_num: number;
|
|
98
|
+
}[];
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* 打印充值卡
|
|
103
|
+
*/
|
|
104
|
+
export declare type WebPrint4 = {
|
|
105
|
+
type: '4';
|
|
106
|
+
data: {
|
|
107
|
+
order_id: string;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* 打印订单中所有
|
|
112
|
+
*/
|
|
113
|
+
export declare type WebPrint99 = {
|
|
114
|
+
type: '99';
|
|
115
|
+
data: {
|
|
116
|
+
order_id: string;
|
|
117
|
+
machine_code_print_info: {
|
|
118
|
+
[key: string]: any;
|
|
119
|
+
}[];
|
|
120
|
+
small_ticket_data: {
|
|
121
|
+
[key: string]: any;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* 打印
|
|
127
|
+
*/
|
|
128
|
+
export declare type WebPrintParams = WebPrint0 | WebPrint1 | WebPrint2 | WebPrint4 | WebPrint99;
|
|
129
|
+
/**
|
|
130
|
+
* 数据管理
|
|
131
|
+
*/
|
|
132
|
+
export declare type DataManagerParams = {
|
|
133
|
+
module: 'set' | 'get';
|
|
134
|
+
key: string;
|
|
135
|
+
data?: any;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* 支付
|
|
139
|
+
*/
|
|
140
|
+
export declare type WebPaymentParams = {
|
|
141
|
+
module: 'payment' | 'refund' | string;
|
|
142
|
+
key: 'mx51' | string;
|
|
143
|
+
data?: {
|
|
144
|
+
order_id: string | number;
|
|
145
|
+
amount: string | number;
|
|
146
|
+
surcharge?: string | number;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/es/locales.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
export declare const locales: {
|
|
2
2
|
init: (_localeMaps: any, _locale: string) => void;
|
|
3
3
|
getText: (id: string) => any;
|
|
4
|
+
getLocale: () => string;
|
|
4
5
|
locale: string;
|
|
5
6
|
localeMap: any;
|
|
6
|
-
localeMaps:
|
|
7
|
-
en: {};
|
|
8
|
-
'zh-CN': {};
|
|
9
|
-
'zh-HK': {};
|
|
10
|
-
};
|
|
7
|
+
localeMaps: any;
|
|
11
8
|
formatLocale: (_locale: string) => string;
|
|
12
9
|
};
|
package/es/locales.js
CHANGED
|
@@ -8,7 +8,9 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
8
8
|
var localeMaps = {
|
|
9
9
|
en: {},
|
|
10
10
|
'zh-CN': {},
|
|
11
|
-
'zh-HK': {}
|
|
11
|
+
'zh-HK': {},
|
|
12
|
+
'ja': {},
|
|
13
|
+
'pt': {}
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
// 当前语言
|
|
@@ -17,16 +19,37 @@ var locale = 'en';
|
|
|
17
19
|
// 当前语言对应的多语言
|
|
18
20
|
var localeMap = {};
|
|
19
21
|
|
|
20
|
-
//
|
|
22
|
+
// 语言格式化(兼容 BCP 47,如 ja-JP、pt-BR)
|
|
21
23
|
var formatLocale = function formatLocale(_locale) {
|
|
22
24
|
var obj = {
|
|
23
|
-
|
|
25
|
+
en: 'en',
|
|
26
|
+
'en-US': 'en',
|
|
27
|
+
'en-us': 'en',
|
|
24
28
|
'zh-CN': 'zh-CN',
|
|
29
|
+
'zh-cn': 'zh-CN',
|
|
25
30
|
'zh-HK': 'zh-HK',
|
|
31
|
+
'zh-hk': 'zh-HK',
|
|
26
32
|
'zh-TW': 'zh-HK',
|
|
27
|
-
'
|
|
33
|
+
'zh-tw': 'zh-HK',
|
|
34
|
+
ja: 'ja',
|
|
35
|
+
'ja-JP': 'ja',
|
|
36
|
+
'ja-jp': 'ja',
|
|
37
|
+
pt: 'pt',
|
|
38
|
+
'pt-BR': 'pt',
|
|
39
|
+
'pt-br': 'pt',
|
|
40
|
+
'pt-PT': 'pt',
|
|
41
|
+
'pt-pt': 'pt'
|
|
28
42
|
};
|
|
29
|
-
|
|
43
|
+
var direct = obj[_locale];
|
|
44
|
+
if (direct) return direct;
|
|
45
|
+
var norm = String(_locale || '').trim().replace(/_/g, '-').toLowerCase();
|
|
46
|
+
if (obj[norm]) return obj[norm];
|
|
47
|
+
if (norm.startsWith('ja')) return 'ja';
|
|
48
|
+
if (norm.startsWith('pt')) return 'pt';
|
|
49
|
+
if (norm.startsWith('zh-hk') || norm.startsWith('zh-tw')) return 'zh-HK';
|
|
50
|
+
if (norm.startsWith('zh-cn')) return 'zh-CN';
|
|
51
|
+
if (norm.startsWith('en')) return 'en';
|
|
52
|
+
return 'en';
|
|
30
53
|
};
|
|
31
54
|
|
|
32
55
|
/**
|
|
@@ -51,7 +74,6 @@ var init = function init(_localeMaps, _locale) {
|
|
|
51
74
|
|
|
52
75
|
// 更新当前语言对应的多语言
|
|
53
76
|
localeMap = localeMaps[locale];
|
|
54
|
-
console.log('多语言注入成功, 当前语言为:' + locale);
|
|
55
77
|
};
|
|
56
78
|
|
|
57
79
|
/**
|
|
@@ -63,11 +85,18 @@ var init = function init(_localeMaps, _locale) {
|
|
|
63
85
|
* @Date: 2024-01-17 21:39
|
|
64
86
|
*/
|
|
65
87
|
var getText = function getText(id) {
|
|
66
|
-
|
|
88
|
+
var _localeMaps2;
|
|
89
|
+
return localeMap[id] || ((_localeMaps2 = localeMaps) === null || _localeMaps2 === void 0 || (_localeMaps2 = _localeMaps2['en']) === null || _localeMaps2 === void 0 ? void 0 : _localeMaps2[id]) || id;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/** 获取当前语言(与 getText 同源,供 datetime 等组件与 getText 语言一致) */
|
|
93
|
+
var getLocale = function getLocale() {
|
|
94
|
+
return locale;
|
|
67
95
|
};
|
|
68
96
|
export var locales = {
|
|
69
97
|
init: init,
|
|
70
98
|
getText: getText,
|
|
99
|
+
getLocale: getLocale,
|
|
71
100
|
locale: locale,
|
|
72
101
|
localeMap: localeMap,
|
|
73
102
|
localeMaps: localeMaps,
|
package/es/miniRedux.js
CHANGED
|
@@ -10,7 +10,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
10
10
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
11
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
12
12
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
-
import React, { createContext, useCallback, useReducer, forwardRef, useRef } from 'react';
|
|
13
|
+
import React, { createContext, useCallback, useMemo, useReducer, forwardRef, useRef } from 'react';
|
|
14
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
15
|
export var miniRedux = function miniRedux(_ref2) {
|
|
16
16
|
var _ref2$namespace = _ref2.namespace,
|
|
@@ -49,6 +49,11 @@ export var miniRedux = function miniRedux(_ref2) {
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
}, []);
|
|
52
|
+
|
|
53
|
+
// 缓存Context value,避免不必要的重新渲染
|
|
54
|
+
var contextValue = useMemo(function () {
|
|
55
|
+
return _defineProperty(_defineProperty({}, namespace, providerState), "dispatch", _dispatch);
|
|
56
|
+
}, [providerState, _dispatch]);
|
|
52
57
|
var _props = _objectSpread(_objectSpread({}, props), {}, _defineProperty(_defineProperty({}, namespace, providerState), "dispatch", _dispatch));
|
|
53
58
|
var _ref = null;
|
|
54
59
|
if (_props.forwardedRef) {
|
|
@@ -56,7 +61,7 @@ export var miniRedux = function miniRedux(_ref2) {
|
|
|
56
61
|
delete _props.forwardedRef;
|
|
57
62
|
}
|
|
58
63
|
return /*#__PURE__*/_jsx(Context.Provider, {
|
|
59
|
-
value:
|
|
64
|
+
value: contextValue,
|
|
60
65
|
children: /*#__PURE__*/_jsx(ComponentUi, _objectSpread(_objectSpread({}, _props), {}, {
|
|
61
66
|
ref: ref
|
|
62
67
|
}))
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BaseNumberInputProps, NumberInputState } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 数值输入状态管理 Hook
|
|
4
|
+
*
|
|
5
|
+
* 管理组件的内部状态,包括:
|
|
6
|
+
* - 值管理(受控/非受控模式)
|
|
7
|
+
* - 校验状态管理
|
|
8
|
+
* - 事件处理函数封装
|
|
9
|
+
*
|
|
10
|
+
* 支持受控和非受控两种模式:
|
|
11
|
+
* - 受控模式:value 由外部传入,组件不维护内部状态
|
|
12
|
+
* - 非受控模式:使用 defaultValue,组件维护内部状态
|
|
13
|
+
*
|
|
14
|
+
* @param props 组件 Props(包含校验配置)
|
|
15
|
+
* @returns 数值输入状态对象
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // 受控模式
|
|
19
|
+
* const state = useNumberInputState({ value: 10, onChange: (v) => console.log(v) });
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // 非受控模式
|
|
23
|
+
* const state = useNumberInputState({ defaultValue: 10, min: 0, max: 100 });
|
|
24
|
+
*/
|
|
25
|
+
export declare function useNumberInputState(props: BaseNumberInputProps): NumberInputState;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { useState, useCallback } from 'react';
|
|
8
|
+
import { validateValue } from "../utils/validation";
|
|
9
|
+
/**
|
|
10
|
+
* 数值输入状态管理 Hook
|
|
11
|
+
*
|
|
12
|
+
* 管理组件的内部状态,包括:
|
|
13
|
+
* - 值管理(受控/非受控模式)
|
|
14
|
+
* - 校验状态管理
|
|
15
|
+
* - 事件处理函数封装
|
|
16
|
+
*
|
|
17
|
+
* 支持受控和非受控两种模式:
|
|
18
|
+
* - 受控模式:value 由外部传入,组件不维护内部状态
|
|
19
|
+
* - 非受控模式:使用 defaultValue,组件维护内部状态
|
|
20
|
+
*
|
|
21
|
+
* @param props 组件 Props(包含校验配置)
|
|
22
|
+
* @returns 数值输入状态对象
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // 受控模式
|
|
26
|
+
* const state = useNumberInputState({ value: 10, onChange: (v) => console.log(v) });
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // 非受控模式
|
|
30
|
+
* const state = useNumberInputState({ defaultValue: 10, min: 0, max: 100 });
|
|
31
|
+
*/
|
|
32
|
+
export function useNumberInputState(props) {
|
|
33
|
+
var _props$defaultValue;
|
|
34
|
+
// 判断是否为受控组件
|
|
35
|
+
var isControlled = props.value !== undefined;
|
|
36
|
+
|
|
37
|
+
// 内部状态(仅非受控模式使用)
|
|
38
|
+
var _useState = useState((_props$defaultValue = props.defaultValue) !== null && _props$defaultValue !== void 0 ? _props$defaultValue : null),
|
|
39
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
40
|
+
innerValue = _useState2[0],
|
|
41
|
+
setInnerValue = _useState2[1];
|
|
42
|
+
var _useState3 = useState(false),
|
|
43
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
44
|
+
isTouched = _useState4[0],
|
|
45
|
+
setIsTouched = _useState4[1];
|
|
46
|
+
var _useState5 = useState(true),
|
|
47
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
48
|
+
isValid = _useState6[0],
|
|
49
|
+
setIsValid = _useState6[1];
|
|
50
|
+
var _useState7 = useState([]),
|
|
51
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
52
|
+
errors = _useState8[0],
|
|
53
|
+
setErrors = _useState8[1];
|
|
54
|
+
|
|
55
|
+
// 当前值(受控模式优先使用 props.value)
|
|
56
|
+
var currentValue = isControlled ? props.value : innerValue;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 值变更处理函数
|
|
60
|
+
*
|
|
61
|
+
* 1. 更新内部状态(非受控模式)
|
|
62
|
+
* 2. 根据 validateTrigger 决定是否立即校验
|
|
63
|
+
* 3. 触发外部 onChange 回调
|
|
64
|
+
*/
|
|
65
|
+
var handleChange = useCallback(function (newValue) {
|
|
66
|
+
var _props$onChange;
|
|
67
|
+
// 更新内部状态(非受控模式)
|
|
68
|
+
if (!isControlled) {
|
|
69
|
+
setInnerValue(newValue);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 根据配置决定是否立即校验
|
|
73
|
+
var shouldValidate = props.validateTrigger === 'onChange' || props.validateTrigger === 'both';
|
|
74
|
+
if (shouldValidate) {
|
|
75
|
+
var _props$onValidate;
|
|
76
|
+
var validation = validateValue(newValue, props);
|
|
77
|
+
setIsValid(validation.isValid);
|
|
78
|
+
setErrors(validation.errors);
|
|
79
|
+
(_props$onValidate = props.onValidate) === null || _props$onValidate === void 0 || _props$onValidate.call(props, validation.isValid, validation.errors);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 触发外部回调
|
|
83
|
+
(_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, newValue);
|
|
84
|
+
}, [isControlled, props]);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 失焦处理函数
|
|
88
|
+
*
|
|
89
|
+
* 1. 标记为已触摸
|
|
90
|
+
* 2. 执行失焦时的校验(根据 validateTrigger)
|
|
91
|
+
* 3. 触发外部 onBlur 回调
|
|
92
|
+
*/
|
|
93
|
+
var handleBlur = useCallback(function () {
|
|
94
|
+
var _props$onBlur;
|
|
95
|
+
setIsTouched(true);
|
|
96
|
+
|
|
97
|
+
// 失焦时执行校验(如果 validateTrigger 不是 'onChange')
|
|
98
|
+
var shouldValidate = props.validateTrigger !== 'onChange';
|
|
99
|
+
if (shouldValidate) {
|
|
100
|
+
var _props$onValidate2;
|
|
101
|
+
var validation = validateValue(currentValue, props);
|
|
102
|
+
setIsValid(validation.isValid);
|
|
103
|
+
setErrors(validation.errors);
|
|
104
|
+
(_props$onValidate2 = props.onValidate) === null || _props$onValidate2 === void 0 || _props$onValidate2.call(props, validation.isValid, validation.errors);
|
|
105
|
+
}
|
|
106
|
+
(_props$onBlur = props.onBlur) === null || _props$onBlur === void 0 || _props$onBlur.call(props, currentValue !== null && currentValue !== void 0 ? currentValue : null);
|
|
107
|
+
}, [currentValue, props]);
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 聚焦处理函数
|
|
111
|
+
*
|
|
112
|
+
* 1. 标记为已触摸
|
|
113
|
+
* 2. 触发外部 onFocus 回调
|
|
114
|
+
*/
|
|
115
|
+
var handleFocus = useCallback(function () {
|
|
116
|
+
var _props$onFocus;
|
|
117
|
+
setIsTouched(true);
|
|
118
|
+
(_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 || _props$onFocus.call(props);
|
|
119
|
+
}, [props]);
|
|
120
|
+
return {
|
|
121
|
+
value: currentValue,
|
|
122
|
+
isTouched: isTouched,
|
|
123
|
+
isValid: isValid,
|
|
124
|
+
errors: errors,
|
|
125
|
+
handleChange: handleChange,
|
|
126
|
+
handleBlur: handleBlur,
|
|
127
|
+
handleFocus: handleFocus
|
|
128
|
+
};
|
|
129
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数值输入组件公共逻辑导出
|
|
3
|
+
*
|
|
4
|
+
* 供以下组件使用:
|
|
5
|
+
* - PisellNumber
|
|
6
|
+
* - PisellCurrency
|
|
7
|
+
* - PisellPercent
|
|
8
|
+
* - 其他数值输入组件
|
|
9
|
+
*/
|
|
10
|
+
export type { DisplayState, ValidationResult, NumberInputState, BaseNumberInputProps, } from './types';
|
|
11
|
+
export { useNumberInputState } from './hooks';
|
|
12
|
+
export { getDisplayState, formatNumber, addThousandsSeparator, formatPrecision, } from './utils';
|
|
13
|
+
export { validateValue as validateNumberValue } from './utils';
|
|
14
|
+
export type { NumberFormatOptions } from './utils';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数值输入组件公共逻辑导出
|
|
3
|
+
*
|
|
4
|
+
* 供以下组件使用:
|
|
5
|
+
* - PisellNumber
|
|
6
|
+
* - PisellCurrency
|
|
7
|
+
* - PisellPercent
|
|
8
|
+
* - 其他数值输入组件
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// 类型
|
|
12
|
+
|
|
13
|
+
// Hooks
|
|
14
|
+
export { useNumberInputState } from "./hooks";
|
|
15
|
+
|
|
16
|
+
// 工具函数
|
|
17
|
+
export { getDisplayState, formatNumber, addThousandsSeparator, formatPrecision } from "./utils";
|
|
18
|
+
// 使用别名导出避免与 text-input 的 validateValue 重名
|
|
19
|
+
export { validateValue as validateNumberValue } from "./utils";
|
|
20
|
+
|
|
21
|
+
// 格式化相关类型
|