1 | import { EditableTextBase as EditableTextBaseCommon, autofillTypeProperty, keyboardTypeProperty, returnKeyTypeProperty, autocapitalizationTypeProperty, autocorrectProperty } from './editable-text-base-common';
|
2 | export * from './editable-text-base-common';
|
3 | export class EditableTextBase extends EditableTextBaseCommon {
|
4 | dismissSoftInput() {
|
5 | this.nativeTextViewProtected.resignFirstResponder();
|
6 | this.notify({ eventName: EditableTextBase.blurEvent, object: this });
|
7 | }
|
8 | [keyboardTypeProperty.getDefault]() {
|
9 | const keyboardType = this.nativeTextViewProtected.keyboardType;
|
10 | switch (keyboardType) {
|
11 | case 2 :
|
12 | return 'number';
|
13 | case 5 :
|
14 | return 'phone';
|
15 | case 3 :
|
16 | return 'url';
|
17 | case 7 :
|
18 | return 'email';
|
19 | case 4 :
|
20 | return 'integer';
|
21 | default:
|
22 | return keyboardType.toString();
|
23 | }
|
24 | }
|
25 | [keyboardTypeProperty.setNative](value) {
|
26 | let newKeyboardType;
|
27 | switch (value) {
|
28 | case 'datetime':
|
29 | newKeyboardType = 2 ;
|
30 | break;
|
31 | case 'phone':
|
32 | newKeyboardType = 5 ;
|
33 | break;
|
34 | case 'number':
|
35 | newKeyboardType = 2 ;
|
36 | break;
|
37 | case 'url':
|
38 | newKeyboardType = 3 ;
|
39 | break;
|
40 | case 'email':
|
41 | newKeyboardType = 7 ;
|
42 | break;
|
43 | case 'integer':
|
44 | newKeyboardType = 4 ;
|
45 | break;
|
46 | default: {
|
47 | const kt = +value;
|
48 | if (!isNaN(kt)) {
|
49 | newKeyboardType = kt;
|
50 | }
|
51 | else {
|
52 | newKeyboardType = 0 ;
|
53 | }
|
54 | break;
|
55 | }
|
56 | }
|
57 | this.nativeTextViewProtected.keyboardType = newKeyboardType;
|
58 | }
|
59 | [autofillTypeProperty.setNative](value) {
|
60 | let newTextContentType;
|
61 | switch (value) {
|
62 | case 'phone':
|
63 | newTextContentType = UITextContentTypeTelephoneNumber;
|
64 | break;
|
65 | case 'postalCode':
|
66 | newTextContentType = UITextContentTypePostalCode;
|
67 | break;
|
68 | case 'creditCardNumber':
|
69 | newTextContentType = UITextContentTypeCreditCardNumber;
|
70 | break;
|
71 | case 'email':
|
72 | newTextContentType = UITextContentTypeEmailAddress;
|
73 | break;
|
74 | case 'name':
|
75 | newTextContentType = UITextContentTypeName;
|
76 | break;
|
77 | case 'username':
|
78 | newTextContentType = UITextContentTypeUsername;
|
79 | break;
|
80 | case 'password':
|
81 | newTextContentType = UITextContentTypePassword;
|
82 | break;
|
83 | case 'newPassword':
|
84 | newTextContentType = UITextContentTypeNewPassword;
|
85 | break;
|
86 | case 'oneTimeCode':
|
87 | newTextContentType = UITextContentTypeOneTimeCode;
|
88 | break;
|
89 | case 'none':
|
90 | newTextContentType = null;
|
91 | break;
|
92 | default: {
|
93 | newTextContentType = value;
|
94 | break;
|
95 | }
|
96 | }
|
97 | this.nativeTextViewProtected.textContentType = newTextContentType;
|
98 | }
|
99 | [returnKeyTypeProperty.getDefault]() {
|
100 | const returnKeyType = this.nativeTextViewProtected.returnKeyType;
|
101 | switch (returnKeyType) {
|
102 | case 9 :
|
103 | return 'done';
|
104 | case 1 :
|
105 | return 'go';
|
106 | case 4 :
|
107 | return 'next';
|
108 | case 6 :
|
109 | return 'search';
|
110 | case 7 :
|
111 | return 'send';
|
112 | default:
|
113 | return returnKeyType.toString();
|
114 | }
|
115 | }
|
116 | [returnKeyTypeProperty.setNative](value) {
|
117 | let newValue;
|
118 | switch (value) {
|
119 | case 'done':
|
120 | newValue = 9 ;
|
121 | break;
|
122 | case 'go':
|
123 | newValue = 1 ;
|
124 | break;
|
125 | case 'next':
|
126 | newValue = 4 ;
|
127 | break;
|
128 | case 'search':
|
129 | newValue = 6 ;
|
130 | break;
|
131 | case 'send':
|
132 | newValue = 7 ;
|
133 | break;
|
134 | default: {
|
135 | const rkt = +value;
|
136 | if (!isNaN(rkt)) {
|
137 | newValue = rkt;
|
138 | }
|
139 | else {
|
140 | newValue = 0 ;
|
141 | }
|
142 | break;
|
143 | }
|
144 | }
|
145 | this.nativeTextViewProtected.returnKeyType = newValue;
|
146 | }
|
147 | [autocapitalizationTypeProperty.getDefault]() {
|
148 | const autocapitalizationType = this.nativeTextViewProtected.autocapitalizationType;
|
149 | switch (autocapitalizationType) {
|
150 | case 0 :
|
151 | return 'none';
|
152 | case 1 :
|
153 | return 'words';
|
154 | case 2 :
|
155 | return 'sentences';
|
156 | case 3 :
|
157 | return 'allcharacters';
|
158 | default:
|
159 | throw new Error('Invalid autocapitalizationType value:' + autocapitalizationType);
|
160 | }
|
161 | }
|
162 | [autocapitalizationTypeProperty.setNative](value) {
|
163 | let newValue;
|
164 | switch (value) {
|
165 | case 'none':
|
166 | newValue = 0 ;
|
167 | break;
|
168 | case 'words':
|
169 | newValue = 1 ;
|
170 | break;
|
171 | case 'sentences':
|
172 | newValue = 2 ;
|
173 | break;
|
174 | case 'allcharacters':
|
175 | newValue = 3 ;
|
176 | break;
|
177 | default:
|
178 | newValue = 2 ;
|
179 | break;
|
180 | }
|
181 | this.nativeTextViewProtected.autocapitalizationType = newValue;
|
182 | }
|
183 | [autocorrectProperty.getDefault]() {
|
184 | const autocorrectionType = this.nativeTextViewProtected.autocorrectionType;
|
185 | switch (autocorrectionType) {
|
186 | case 2 :
|
187 | return true;
|
188 | case 1 :
|
189 | return false;
|
190 | case 0 :
|
191 | return autocorrectionType;
|
192 | }
|
193 | }
|
194 | [autocorrectProperty.setNative](value) {
|
195 | let newValue;
|
196 | let spelling;
|
197 | if (typeof value === 'number') {
|
198 | newValue = 0 ;
|
199 | spelling = 0 ;
|
200 | }
|
201 | else if (value) {
|
202 | newValue = 2 ;
|
203 | spelling = 2 ;
|
204 | }
|
205 | else {
|
206 | newValue = 1 ;
|
207 | spelling = 1 ;
|
208 | }
|
209 | this.nativeTextViewProtected.autocorrectionType = newValue;
|
210 | this.nativeTextViewProtected.spellCheckingType = spelling;
|
211 | }
|
212 | setSelection(start, stop) {
|
213 | const view = this.nativeTextViewProtected;
|
214 | if (view) {
|
215 | if (stop !== undefined) {
|
216 | const begin = view.beginningOfDocument;
|
217 | const fromPosition = view.positionFromPositionOffset(begin, start);
|
218 | const toPosition = view.positionFromPositionOffset(begin, stop);
|
219 | view.selectedTextRange = view.textRangeFromPositionToPosition(fromPosition, toPosition);
|
220 | }
|
221 | else {
|
222 | const begin = view.beginningOfDocument;
|
223 | const pos = view.positionFromPositionOffset(begin, start);
|
224 | view.selectedTextRange = view.textRangeFromPositionToPosition(pos, pos);
|
225 | }
|
226 | }
|
227 | }
|
228 | }
|
229 | export function _updateCharactersInRangeReplacementString(formattedText, rangeLocation, rangeLength, replacementString) {
|
230 | const deletingText = !replacementString;
|
231 | let currentLocation = 0;
|
232 | for (let i = 0, length = formattedText.spans.length; i < length; i++) {
|
233 | const span = formattedText.spans.getItem(i);
|
234 | if (currentLocation <= rangeLocation && rangeLocation < currentLocation + span.text.length) {
|
235 | const newText = splice(span.text, rangeLocation - currentLocation, deletingText ? rangeLength : 0, replacementString);
|
236 | span._setTextInternal(newText);
|
237 | return;
|
238 | }
|
239 | currentLocation += span.text.length;
|
240 | }
|
241 | }
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 | function splice(value, start, delCount, newSubStr) {
|
250 | return value.slice(0, start) + newSubStr + value.slice(start + Math.abs(delCount));
|
251 | }
|
252 |
|
\ | No newline at end of file |