@react-native-ohos/react-native-text-input-mask 3.1.6-rc.1 → 3.1.6-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.OpenSource +10 -10
- package/README.md +15 -134
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/harmony/text_input_mask/BuildProfile.ets +16 -16
- package/harmony/text_input_mask/Index.ets +7 -7
- package/harmony/text_input_mask/build-profile.json5 +31 -31
- package/harmony/text_input_mask/hvigorfile.ts +6 -6
- package/harmony/text_input_mask/obfuscation-rules.txt +22 -22
- package/harmony/text_input_mask/oh-package.json5 +11 -11
- package/harmony/text_input_mask/src/main/cpp/CMakeLists.txt +9 -9
- package/harmony/text_input_mask/src/main/cpp/RNTextInputMask.cpp +421 -415
- package/harmony/text_input_mask/src/main/cpp/RNTextInputMask.h +93 -93
- package/harmony/text_input_mask/src/main/cpp/RNTextInputMaskPackage.h +31 -31
- package/harmony/text_input_mask/src/main/cpp/common/Compiler.h +174 -174
- package/harmony/text_input_mask/src/main/cpp/common/FormatError.h +22 -22
- package/harmony/text_input_mask/src/main/cpp/common/FormatSanitizer.h +230 -230
- package/harmony/text_input_mask/src/main/cpp/common/Mask.h +377 -377
- package/harmony/text_input_mask/src/main/cpp/common/RTLMask.h +78 -78
- package/harmony/text_input_mask/src/main/cpp/common/model/AffinityCalculationStrategy.h +57 -57
- package/harmony/text_input_mask/src/main/cpp/common/model/CaretString.h +75 -75
- package/harmony/text_input_mask/src/main/cpp/common/model/CaretStringIterator.h +58 -58
- package/harmony/text_input_mask/src/main/cpp/common/model/Next.h +24 -24
- package/harmony/text_input_mask/src/main/cpp/common/model/Notation.h +24 -24
- package/harmony/text_input_mask/src/main/cpp/common/model/RTLCaretStringIterator.h +22 -22
- package/harmony/text_input_mask/src/main/cpp/common/model/State.h +302 -302
- package/harmony/text_input_mask/src/main/cpp/common/model/common.h +94 -94
- package/harmony/text_input_mask/src/main/ets/RNTextInputMaskPackage.ts +28 -28
- package/harmony/text_input_mask/src/main/ets/RNTextInputMaskTurboModle.ts +32 -32
- package/harmony/text_input_mask/src/main/module.json5 +11 -11
- package/harmony/text_input_mask/src/main/resources/base/element/string.json +8 -8
- package/harmony/text_input_mask/src/main/resources/en_US/element/string.json +8 -8
- package/harmony/text_input_mask/src/main/resources/zh_CN/element/string.json +8 -8
- package/harmony/text_input_mask/ts.ts +8 -8
- package/harmony/text_input_mask.har +0 -0
- package/index.tsx +258 -258
- package/package.json +48 -50
- package/src/RNNativeTextInputMask.ts +142 -142
- package/src/index.harmony.ts +147 -147
- package/src/index.ts +36 -36
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
-
* Use of this source code is governed by a MIT license that can be
|
|
4
|
-
* found in the LICENSE file.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { TurboModule } from "react-native/Libraries/TurboModule/RCTExport";
|
|
8
|
-
import { TurboModuleRegistry} from "react-native";
|
|
9
|
-
|
|
10
|
-
export interface MaskOptions {
|
|
11
|
-
affineFormats?: string[]
|
|
12
|
-
customNotations?: Notation[]
|
|
13
|
-
affinityCalculationStrategy?: AffinityCalculationStrategy
|
|
14
|
-
/**
|
|
15
|
-
* autocomplete pattern while editing text
|
|
16
|
-
*/
|
|
17
|
-
autocomplete?: boolean
|
|
18
|
-
/**
|
|
19
|
-
* automatically remove mask characters on backspace
|
|
20
|
-
*/
|
|
21
|
-
autoskip?: boolean
|
|
22
|
-
rightToLeft?: boolean
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type AffinityCalculationStrategy =
|
|
26
|
-
/**
|
|
27
|
-
* Default strategy.
|
|
28
|
-
*
|
|
29
|
-
* Uses ```Mask``` built-in mechanism to calculate total affinity between the text and the mask format.
|
|
30
|
-
*
|
|
31
|
-
* For example:
|
|
32
|
-
* ```
|
|
33
|
-
* format: [00].[00]
|
|
34
|
-
*
|
|
35
|
-
* input1: 1234
|
|
36
|
-
* input2: 12.34
|
|
37
|
-
* input3: 1.234
|
|
38
|
-
*
|
|
39
|
-
* affinity1 = 4 (symbols) - 1 (missed dot) = 3
|
|
40
|
-
* affinity2 = 5 (symbols) = 5
|
|
41
|
-
* affinity3 = 5 (symbols) - 1 (superfluous dot) - 1 (missed dot) = 3
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
'WHOLE_STRING' |
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Finds the longest common prefix between the original text and the same text after applying the mask.
|
|
48
|
-
*
|
|
49
|
-
* For example:
|
|
50
|
-
* ```
|
|
51
|
-
* format1: +7 [000] [000]
|
|
52
|
-
* format2: 8 [000] [000]
|
|
53
|
-
*
|
|
54
|
-
* input: +7 12 345
|
|
55
|
-
* affinity1 = 5
|
|
56
|
-
* affinity2 = 0
|
|
57
|
-
*
|
|
58
|
-
* input: 8 12 345
|
|
59
|
-
* affinity1 = 0
|
|
60
|
-
* affinity2 = 4
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
'PREFIX' |
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Affinity is tolerance between the length of the input and the total amount of text current mask can accommodate.
|
|
67
|
-
*
|
|
68
|
-
* If current mask can't accommodate all the text, the affinity equals `Int.min`.
|
|
69
|
-
*
|
|
70
|
-
* For example:
|
|
71
|
-
* ```
|
|
72
|
-
* format1: [00]-[0]
|
|
73
|
-
* format2: [00]-[000]
|
|
74
|
-
* format3: [00]-[00000]
|
|
75
|
-
*
|
|
76
|
-
* input affinity1 affinity2 affinity3
|
|
77
|
-
* 1 -3 -5 -7
|
|
78
|
-
* 12 -2 -4 -6
|
|
79
|
-
* 123 -1 -3 -5
|
|
80
|
-
* 12-3 0 -2 -4
|
|
81
|
-
* 1234 0 -2 -4
|
|
82
|
-
* 12345 Int.MIN_VALUE -1 -3
|
|
83
|
-
* 123456 Int.MIN_VALUE 0 -2
|
|
84
|
-
* ```
|
|
85
|
-
*
|
|
86
|
-
* This affinity calculation strategy comes in handy when the mask format radically changes depending on the input
|
|
87
|
-
* length.
|
|
88
|
-
*
|
|
89
|
-
* N.B.: Make sure the widest mask format is the primary mask format.
|
|
90
|
-
*/
|
|
91
|
-
'CAPACITY' |
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Affinity is tolerance between the length of the extracted value and the total extracted value length current mask can accommodate.
|
|
95
|
-
*
|
|
96
|
-
* If current mask can't accommodate all the text, the affinity equals `Int.min`.
|
|
97
|
-
*
|
|
98
|
-
* For example:
|
|
99
|
-
* ```
|
|
100
|
-
* format1: [00]-[0]
|
|
101
|
-
* format2: [00]-[000]
|
|
102
|
-
* format3: [00]-[00000]
|
|
103
|
-
*
|
|
104
|
-
* input affinity1 affinity2 affinity3
|
|
105
|
-
* 1 -2 -4 -6
|
|
106
|
-
* 12 -1 -3 -5
|
|
107
|
-
* 123 0 -2 -4
|
|
108
|
-
* 12-3 0 -2 -4
|
|
109
|
-
* 1234 Int.MIN_VALUE -1 -3
|
|
110
|
-
* 12345 Int.MIN_VALUE 0 -2
|
|
111
|
-
* 123456 Int.MIN_VALUE Int.MIN_VALUE -1
|
|
112
|
-
* ```
|
|
113
|
-
*
|
|
114
|
-
* This affinity calculation strategy comes in handy when the mask format radically changes depending on the value
|
|
115
|
-
* length.
|
|
116
|
-
*
|
|
117
|
-
* N.B.: Make sure the widest mask format is the primary mask format.
|
|
118
|
-
*/
|
|
119
|
-
'EXTRACTED_VALUE_CAPACITY'
|
|
120
|
-
|
|
121
|
-
interface Notation {
|
|
122
|
-
/**
|
|
123
|
-
* A symbol in format string.
|
|
124
|
-
*/
|
|
125
|
-
character: string,
|
|
126
|
-
/**
|
|
127
|
-
* An associated character set of acceptable input characters.
|
|
128
|
-
*/
|
|
129
|
-
characterSet: string,
|
|
130
|
-
/**
|
|
131
|
-
* Is it an optional symbol or mandatory?
|
|
132
|
-
*/
|
|
133
|
-
isOptional: boolean
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export interface Spec extends TurboModule {
|
|
137
|
-
mask (mask: string, value: string, autocomplete: boolean) :Promise<string>,
|
|
138
|
-
unmask (mask: string, value: string, autocomplete: boolean): Promise<string>,
|
|
139
|
-
setMask (reactNode: number, primaryFormat: string, options?: MaskOptions): void;
|
|
140
|
-
unmaskWithRightToLeft (mask: string, value: string, autocomplete: boolean, rightToLeft: boolean): Promise<string>;
|
|
141
|
-
}
|
|
142
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { TurboModule } from "react-native/Libraries/TurboModule/RCTExport";
|
|
8
|
+
import { TurboModuleRegistry} from "react-native";
|
|
9
|
+
|
|
10
|
+
export interface MaskOptions {
|
|
11
|
+
affineFormats?: string[]
|
|
12
|
+
customNotations?: Notation[]
|
|
13
|
+
affinityCalculationStrategy?: AffinityCalculationStrategy
|
|
14
|
+
/**
|
|
15
|
+
* autocomplete pattern while editing text
|
|
16
|
+
*/
|
|
17
|
+
autocomplete?: boolean
|
|
18
|
+
/**
|
|
19
|
+
* automatically remove mask characters on backspace
|
|
20
|
+
*/
|
|
21
|
+
autoskip?: boolean
|
|
22
|
+
rightToLeft?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type AffinityCalculationStrategy =
|
|
26
|
+
/**
|
|
27
|
+
* Default strategy.
|
|
28
|
+
*
|
|
29
|
+
* Uses ```Mask``` built-in mechanism to calculate total affinity between the text and the mask format.
|
|
30
|
+
*
|
|
31
|
+
* For example:
|
|
32
|
+
* ```
|
|
33
|
+
* format: [00].[00]
|
|
34
|
+
*
|
|
35
|
+
* input1: 1234
|
|
36
|
+
* input2: 12.34
|
|
37
|
+
* input3: 1.234
|
|
38
|
+
*
|
|
39
|
+
* affinity1 = 4 (symbols) - 1 (missed dot) = 3
|
|
40
|
+
* affinity2 = 5 (symbols) = 5
|
|
41
|
+
* affinity3 = 5 (symbols) - 1 (superfluous dot) - 1 (missed dot) = 3
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
'WHOLE_STRING' |
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Finds the longest common prefix between the original text and the same text after applying the mask.
|
|
48
|
+
*
|
|
49
|
+
* For example:
|
|
50
|
+
* ```
|
|
51
|
+
* format1: +7 [000] [000]
|
|
52
|
+
* format2: 8 [000] [000]
|
|
53
|
+
*
|
|
54
|
+
* input: +7 12 345
|
|
55
|
+
* affinity1 = 5
|
|
56
|
+
* affinity2 = 0
|
|
57
|
+
*
|
|
58
|
+
* input: 8 12 345
|
|
59
|
+
* affinity1 = 0
|
|
60
|
+
* affinity2 = 4
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
'PREFIX' |
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Affinity is tolerance between the length of the input and the total amount of text current mask can accommodate.
|
|
67
|
+
*
|
|
68
|
+
* If current mask can't accommodate all the text, the affinity equals `Int.min`.
|
|
69
|
+
*
|
|
70
|
+
* For example:
|
|
71
|
+
* ```
|
|
72
|
+
* format1: [00]-[0]
|
|
73
|
+
* format2: [00]-[000]
|
|
74
|
+
* format3: [00]-[00000]
|
|
75
|
+
*
|
|
76
|
+
* input affinity1 affinity2 affinity3
|
|
77
|
+
* 1 -3 -5 -7
|
|
78
|
+
* 12 -2 -4 -6
|
|
79
|
+
* 123 -1 -3 -5
|
|
80
|
+
* 12-3 0 -2 -4
|
|
81
|
+
* 1234 0 -2 -4
|
|
82
|
+
* 12345 Int.MIN_VALUE -1 -3
|
|
83
|
+
* 123456 Int.MIN_VALUE 0 -2
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* This affinity calculation strategy comes in handy when the mask format radically changes depending on the input
|
|
87
|
+
* length.
|
|
88
|
+
*
|
|
89
|
+
* N.B.: Make sure the widest mask format is the primary mask format.
|
|
90
|
+
*/
|
|
91
|
+
'CAPACITY' |
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Affinity is tolerance between the length of the extracted value and the total extracted value length current mask can accommodate.
|
|
95
|
+
*
|
|
96
|
+
* If current mask can't accommodate all the text, the affinity equals `Int.min`.
|
|
97
|
+
*
|
|
98
|
+
* For example:
|
|
99
|
+
* ```
|
|
100
|
+
* format1: [00]-[0]
|
|
101
|
+
* format2: [00]-[000]
|
|
102
|
+
* format3: [00]-[00000]
|
|
103
|
+
*
|
|
104
|
+
* input affinity1 affinity2 affinity3
|
|
105
|
+
* 1 -2 -4 -6
|
|
106
|
+
* 12 -1 -3 -5
|
|
107
|
+
* 123 0 -2 -4
|
|
108
|
+
* 12-3 0 -2 -4
|
|
109
|
+
* 1234 Int.MIN_VALUE -1 -3
|
|
110
|
+
* 12345 Int.MIN_VALUE 0 -2
|
|
111
|
+
* 123456 Int.MIN_VALUE Int.MIN_VALUE -1
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* This affinity calculation strategy comes in handy when the mask format radically changes depending on the value
|
|
115
|
+
* length.
|
|
116
|
+
*
|
|
117
|
+
* N.B.: Make sure the widest mask format is the primary mask format.
|
|
118
|
+
*/
|
|
119
|
+
'EXTRACTED_VALUE_CAPACITY'
|
|
120
|
+
|
|
121
|
+
interface Notation {
|
|
122
|
+
/**
|
|
123
|
+
* A symbol in format string.
|
|
124
|
+
*/
|
|
125
|
+
character: string,
|
|
126
|
+
/**
|
|
127
|
+
* An associated character set of acceptable input characters.
|
|
128
|
+
*/
|
|
129
|
+
characterSet: string,
|
|
130
|
+
/**
|
|
131
|
+
* Is it an optional symbol or mandatory?
|
|
132
|
+
*/
|
|
133
|
+
isOptional: boolean
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface Spec extends TurboModule {
|
|
137
|
+
mask (mask: string, value: string, autocomplete: boolean) :Promise<string>,
|
|
138
|
+
unmask (mask: string, value: string, autocomplete: boolean): Promise<string>,
|
|
139
|
+
setMask (reactNode: number, primaryFormat: string, options?: MaskOptions): void;
|
|
140
|
+
unmaskWithRightToLeft (mask: string, value: string, autocomplete: boolean, rightToLeft: boolean): Promise<string>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
143
|
export default TurboModuleRegistry.get<Spec>('RNTextInputMask') as Spec ;
|
package/src/index.harmony.ts
CHANGED
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
-
* Use of this source code is governed by a MIT license that can be
|
|
4
|
-
* found in the LICENSE file.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import RNNativeTextInputMask from './RNNativeTextInputMask';
|
|
8
|
-
export interface MaskOptions {
|
|
9
|
-
affineFormats?: string[];
|
|
10
|
-
customNotations?: Notation[];
|
|
11
|
-
affinityCalculationStrategy?: AffinityCalculationStrategy;
|
|
12
|
-
/**
|
|
13
|
-
* autocomplete pattern while editing text
|
|
14
|
-
*/
|
|
15
|
-
autocomplete?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* automatically remove mask characters on backspace
|
|
18
|
-
*/
|
|
19
|
-
autoskip?: boolean;
|
|
20
|
-
rightToLeft?: boolean;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type AffinityCalculationStrategy =
|
|
24
|
-
/**
|
|
25
|
-
* Default strategy.
|
|
26
|
-
*
|
|
27
|
-
* Uses ```Mask``` built-in mechanism to calculate total affinity between the text and the mask format.
|
|
28
|
-
*
|
|
29
|
-
* For example:
|
|
30
|
-
* ```
|
|
31
|
-
* format: [00].[00]
|
|
32
|
-
*
|
|
33
|
-
* input1: 1234
|
|
34
|
-
* input2: 12.34
|
|
35
|
-
* input3: 1.234
|
|
36
|
-
*
|
|
37
|
-
* affinity1 = 4 (symbols) - 1 (missed dot) = 3
|
|
38
|
-
* affinity2 = 5 (symbols) = 5
|
|
39
|
-
* affinity3 = 5 (symbols) - 1 (superfluous dot) - 1 (missed dot) = 3
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
'WHOLE_STRING' |
|
|
43
|
-
/**
|
|
44
|
-
* Finds the longest common prefix between the original text and the same text after applying the mask.
|
|
45
|
-
*
|
|
46
|
-
* For example:
|
|
47
|
-
* ```
|
|
48
|
-
* format1: +7 [000] [000]
|
|
49
|
-
* format2: 8 [000] [000]
|
|
50
|
-
*
|
|
51
|
-
* input: +7 12 345
|
|
52
|
-
* affinity1 = 5
|
|
53
|
-
* affinity2 = 0
|
|
54
|
-
*
|
|
55
|
-
* input: 8 12 345
|
|
56
|
-
* affinity1 = 0
|
|
57
|
-
* affinity2 = 4
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
'PREFIX' |
|
|
61
|
-
/**
|
|
62
|
-
* Affinity is tolerance between the length of the input and the total amount of text current mask can accommodate.
|
|
63
|
-
*
|
|
64
|
-
* If current mask can't accommodate all the text, the affinity equals `Int.min`.
|
|
65
|
-
*
|
|
66
|
-
* For example:
|
|
67
|
-
* ```
|
|
68
|
-
* format1: [00]-[0]
|
|
69
|
-
* format2: [00]-[000]
|
|
70
|
-
* format3: [00]-[00000]
|
|
71
|
-
*
|
|
72
|
-
* input affinity1 affinity2 affinity3
|
|
73
|
-
* 1 -3 -5 -7
|
|
74
|
-
* 12 -2 -4 -6
|
|
75
|
-
* 123 -1 -3 -5
|
|
76
|
-
* 12-3 0 -2 -4
|
|
77
|
-
* 1234 0 -2 -4
|
|
78
|
-
* 12345 Int.MIN_VALUE -1 -3
|
|
79
|
-
* 123456 Int.MIN_VALUE 0 -2
|
|
80
|
-
* ```
|
|
81
|
-
*
|
|
82
|
-
* This affinity calculation strategy comes in handy when the mask format radically changes depending on the input
|
|
83
|
-
* length.
|
|
84
|
-
*
|
|
85
|
-
* N.B.: Make sure the widest mask format is the primary mask format.
|
|
86
|
-
*/
|
|
87
|
-
'CAPACITY' |
|
|
88
|
-
/**
|
|
89
|
-
* Affinity is tolerance between the length of the extracted value and the total extracted value length current mask can accommodate.
|
|
90
|
-
*
|
|
91
|
-
* If current mask can't accommodate all the text, the affinity equals `Int.min`.
|
|
92
|
-
*
|
|
93
|
-
* For example:
|
|
94
|
-
* ```
|
|
95
|
-
* format1: [00]-[0]
|
|
96
|
-
* format2: [00]-[000]
|
|
97
|
-
* format3: [00]-[00000]
|
|
98
|
-
*
|
|
99
|
-
* input affinity1 affinity2 affinity3
|
|
100
|
-
* 1 -2 -4 -6
|
|
101
|
-
* 12 -1 -3 -5
|
|
102
|
-
* 123 0 -2 -4
|
|
103
|
-
* 12-3 0 -2 -4
|
|
104
|
-
* 1234 Int.MIN_VALUE -1 -3
|
|
105
|
-
* 12345 Int.MIN_VALUE 0 -2
|
|
106
|
-
* 123456 Int.MIN_VALUE Int.MIN_VALUE -1
|
|
107
|
-
* ```
|
|
108
|
-
*
|
|
109
|
-
* This affinity calculation strategy comes in handy when the mask format radically changes depending on the value
|
|
110
|
-
* length.
|
|
111
|
-
*
|
|
112
|
-
* N.B.: Make sure the widest mask format is the primary mask format.
|
|
113
|
-
*/
|
|
114
|
-
'EXTRACTED_VALUE_CAPACITY';
|
|
115
|
-
interface Notation {
|
|
116
|
-
/**
|
|
117
|
-
* A symbol in format string.
|
|
118
|
-
*/
|
|
119
|
-
character: string;
|
|
120
|
-
/**
|
|
121
|
-
* An associated character set of acceptable input characters.
|
|
122
|
-
*/
|
|
123
|
-
characterSet: string;
|
|
124
|
-
/**
|
|
125
|
-
* Is it an optional symbol or mandatory?
|
|
126
|
-
*/
|
|
127
|
-
isOptional: boolean;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
class HarmonyTextInputMask {
|
|
132
|
-
static mask(mask: string, value: string, autocomplete: boolean): Promise<string> {
|
|
133
|
-
return RNNativeTextInputMask.mask(mask, value, autocomplete);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
static unmask(mask: string, value: string, autocomplete: boolean): Promise<string> {
|
|
137
|
-
return RNNativeTextInputMask.unmask(mask, value, autocomplete);
|
|
138
|
-
}
|
|
139
|
-
static setMask(reactNode: number, primaryFormat: string, options?: MaskOptions): void {
|
|
140
|
-
RNNativeTextInputMask.setMask(reactNode, primaryFormat, options)
|
|
141
|
-
}
|
|
142
|
-
static unmaskWithRightToLeft(mask: string, value: string, autocomplete: boolean, rightToLeft: boolean): Promise<string> {
|
|
143
|
-
return RNNativeTextInputMask.unmaskWithRightToLeft(mask, value, autocomplete, rightToLeft);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
console.log("======HarmonyTextInputMask=",HarmonyTextInputMask)
|
|
147
|
-
export default HarmonyTextInputMask;
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import RNNativeTextInputMask from './RNNativeTextInputMask';
|
|
8
|
+
export interface MaskOptions {
|
|
9
|
+
affineFormats?: string[];
|
|
10
|
+
customNotations?: Notation[];
|
|
11
|
+
affinityCalculationStrategy?: AffinityCalculationStrategy;
|
|
12
|
+
/**
|
|
13
|
+
* autocomplete pattern while editing text
|
|
14
|
+
*/
|
|
15
|
+
autocomplete?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* automatically remove mask characters on backspace
|
|
18
|
+
*/
|
|
19
|
+
autoskip?: boolean;
|
|
20
|
+
rightToLeft?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type AffinityCalculationStrategy =
|
|
24
|
+
/**
|
|
25
|
+
* Default strategy.
|
|
26
|
+
*
|
|
27
|
+
* Uses ```Mask``` built-in mechanism to calculate total affinity between the text and the mask format.
|
|
28
|
+
*
|
|
29
|
+
* For example:
|
|
30
|
+
* ```
|
|
31
|
+
* format: [00].[00]
|
|
32
|
+
*
|
|
33
|
+
* input1: 1234
|
|
34
|
+
* input2: 12.34
|
|
35
|
+
* input3: 1.234
|
|
36
|
+
*
|
|
37
|
+
* affinity1 = 4 (symbols) - 1 (missed dot) = 3
|
|
38
|
+
* affinity2 = 5 (symbols) = 5
|
|
39
|
+
* affinity3 = 5 (symbols) - 1 (superfluous dot) - 1 (missed dot) = 3
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
'WHOLE_STRING' |
|
|
43
|
+
/**
|
|
44
|
+
* Finds the longest common prefix between the original text and the same text after applying the mask.
|
|
45
|
+
*
|
|
46
|
+
* For example:
|
|
47
|
+
* ```
|
|
48
|
+
* format1: +7 [000] [000]
|
|
49
|
+
* format2: 8 [000] [000]
|
|
50
|
+
*
|
|
51
|
+
* input: +7 12 345
|
|
52
|
+
* affinity1 = 5
|
|
53
|
+
* affinity2 = 0
|
|
54
|
+
*
|
|
55
|
+
* input: 8 12 345
|
|
56
|
+
* affinity1 = 0
|
|
57
|
+
* affinity2 = 4
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
'PREFIX' |
|
|
61
|
+
/**
|
|
62
|
+
* Affinity is tolerance between the length of the input and the total amount of text current mask can accommodate.
|
|
63
|
+
*
|
|
64
|
+
* If current mask can't accommodate all the text, the affinity equals `Int.min`.
|
|
65
|
+
*
|
|
66
|
+
* For example:
|
|
67
|
+
* ```
|
|
68
|
+
* format1: [00]-[0]
|
|
69
|
+
* format2: [00]-[000]
|
|
70
|
+
* format3: [00]-[00000]
|
|
71
|
+
*
|
|
72
|
+
* input affinity1 affinity2 affinity3
|
|
73
|
+
* 1 -3 -5 -7
|
|
74
|
+
* 12 -2 -4 -6
|
|
75
|
+
* 123 -1 -3 -5
|
|
76
|
+
* 12-3 0 -2 -4
|
|
77
|
+
* 1234 0 -2 -4
|
|
78
|
+
* 12345 Int.MIN_VALUE -1 -3
|
|
79
|
+
* 123456 Int.MIN_VALUE 0 -2
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* This affinity calculation strategy comes in handy when the mask format radically changes depending on the input
|
|
83
|
+
* length.
|
|
84
|
+
*
|
|
85
|
+
* N.B.: Make sure the widest mask format is the primary mask format.
|
|
86
|
+
*/
|
|
87
|
+
'CAPACITY' |
|
|
88
|
+
/**
|
|
89
|
+
* Affinity is tolerance between the length of the extracted value and the total extracted value length current mask can accommodate.
|
|
90
|
+
*
|
|
91
|
+
* If current mask can't accommodate all the text, the affinity equals `Int.min`.
|
|
92
|
+
*
|
|
93
|
+
* For example:
|
|
94
|
+
* ```
|
|
95
|
+
* format1: [00]-[0]
|
|
96
|
+
* format2: [00]-[000]
|
|
97
|
+
* format3: [00]-[00000]
|
|
98
|
+
*
|
|
99
|
+
* input affinity1 affinity2 affinity3
|
|
100
|
+
* 1 -2 -4 -6
|
|
101
|
+
* 12 -1 -3 -5
|
|
102
|
+
* 123 0 -2 -4
|
|
103
|
+
* 12-3 0 -2 -4
|
|
104
|
+
* 1234 Int.MIN_VALUE -1 -3
|
|
105
|
+
* 12345 Int.MIN_VALUE 0 -2
|
|
106
|
+
* 123456 Int.MIN_VALUE Int.MIN_VALUE -1
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* This affinity calculation strategy comes in handy when the mask format radically changes depending on the value
|
|
110
|
+
* length.
|
|
111
|
+
*
|
|
112
|
+
* N.B.: Make sure the widest mask format is the primary mask format.
|
|
113
|
+
*/
|
|
114
|
+
'EXTRACTED_VALUE_CAPACITY';
|
|
115
|
+
interface Notation {
|
|
116
|
+
/**
|
|
117
|
+
* A symbol in format string.
|
|
118
|
+
*/
|
|
119
|
+
character: string;
|
|
120
|
+
/**
|
|
121
|
+
* An associated character set of acceptable input characters.
|
|
122
|
+
*/
|
|
123
|
+
characterSet: string;
|
|
124
|
+
/**
|
|
125
|
+
* Is it an optional symbol or mandatory?
|
|
126
|
+
*/
|
|
127
|
+
isOptional: boolean;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class HarmonyTextInputMask {
|
|
132
|
+
static mask(mask: string, value: string, autocomplete: boolean): Promise<string> {
|
|
133
|
+
return RNNativeTextInputMask.mask(mask, value, autocomplete);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
static unmask(mask: string, value: string, autocomplete: boolean): Promise<string> {
|
|
137
|
+
return RNNativeTextInputMask.unmask(mask, value, autocomplete);
|
|
138
|
+
}
|
|
139
|
+
static setMask(reactNode: number, primaryFormat: string, options?: MaskOptions): void {
|
|
140
|
+
RNNativeTextInputMask.setMask(reactNode, primaryFormat, options)
|
|
141
|
+
}
|
|
142
|
+
static unmaskWithRightToLeft(mask: string, value: string, autocomplete: boolean, rightToLeft: boolean): Promise<string> {
|
|
143
|
+
return RNNativeTextInputMask.unmaskWithRightToLeft(mask, value, autocomplete, rightToLeft);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
console.log("======HarmonyTextInputMask=",HarmonyTextInputMask)
|
|
147
|
+
export default HarmonyTextInputMask;
|
package/src/index.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
-
* Use of this source code is governed by a MIT license that can be
|
|
4
|
-
* found in the LICENSE file.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import HarmonyTextInputMask ,{MaskOptions}from './index.harmony'
|
|
8
|
-
import {mask as maskA, unmask as unmaskA, setMask as setMaskA } from 'react-native-text-input-mask';
|
|
9
|
-
import { Platform } from 'react-native';
|
|
10
|
-
|
|
11
|
-
interface MaskOperations {
|
|
12
|
-
mask(mask: string, value: string, autocomplete: boolean): Promise<string> ;
|
|
13
|
-
unmask(mask: string, value: string, autocomplete: boolean): Promise<string>
|
|
14
|
-
setMask(reactNode: number, primaryFormat: string, options?: MaskOptions): void
|
|
15
|
-
}
|
|
16
|
-
const isIosAndroid = Platform.OS === 'ios' || Platform.OS === 'android';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class RNTextInputMask {
|
|
20
|
-
constructor(){}
|
|
21
|
-
static mask(mask: string, value: string, autocomplete: boolean): Promise<string> {
|
|
22
|
-
return maskA(mask, value, autocomplete);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
static unmask(mask: string, value: string, autocomplete: boolean): Promise<string> {
|
|
26
|
-
return unmaskA(mask, value, autocomplete);
|
|
27
|
-
}
|
|
28
|
-
static setMask(reactNode: number, primaryFormat: string, options?: MaskOptions): void {
|
|
29
|
-
setMaskA(reactNode, primaryFormat, options)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
console.log("======isIosAndroid=",isIosAndroid)
|
|
33
|
-
console.log("======RNTextInputMask=",RNTextInputMask)
|
|
34
|
-
export const exportMasker:MaskOperations= isIosAndroid ? RNTextInputMask : HarmonyTextInputMask
|
|
35
|
-
console.log("======exportMasker=",exportMasker)
|
|
36
|
-
export default exportMasker;
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import HarmonyTextInputMask ,{MaskOptions}from './index.harmony'
|
|
8
|
+
import {mask as maskA, unmask as unmaskA, setMask as setMaskA } from 'react-native-text-input-mask';
|
|
9
|
+
import { Platform } from 'react-native';
|
|
10
|
+
|
|
11
|
+
interface MaskOperations {
|
|
12
|
+
mask(mask: string, value: string, autocomplete: boolean): Promise<string> ;
|
|
13
|
+
unmask(mask: string, value: string, autocomplete: boolean): Promise<string>
|
|
14
|
+
setMask(reactNode: number, primaryFormat: string, options?: MaskOptions): void
|
|
15
|
+
}
|
|
16
|
+
const isIosAndroid = Platform.OS === 'ios' || Platform.OS === 'android';
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class RNTextInputMask {
|
|
20
|
+
constructor(){}
|
|
21
|
+
static mask(mask: string, value: string, autocomplete: boolean): Promise<string> {
|
|
22
|
+
return maskA(mask, value, autocomplete);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static unmask(mask: string, value: string, autocomplete: boolean): Promise<string> {
|
|
26
|
+
return unmaskA(mask, value, autocomplete);
|
|
27
|
+
}
|
|
28
|
+
static setMask(reactNode: number, primaryFormat: string, options?: MaskOptions): void {
|
|
29
|
+
setMaskA(reactNode, primaryFormat, options)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
console.log("======isIosAndroid=",isIosAndroid)
|
|
33
|
+
console.log("======RNTextInputMask=",RNTextInputMask)
|
|
34
|
+
export const exportMasker:MaskOperations= isIosAndroid ? RNTextInputMask : HarmonyTextInputMask
|
|
35
|
+
console.log("======exportMasker=",exportMasker)
|
|
36
|
+
export default exportMasker;
|