@brandup/ui-textbox 1.0.18 → 1.0.20
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/package.json +6 -6
- package/source/textbox.less +1 -0
- package/source/textbox.ts +54 -48
package/package.json
CHANGED
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
"email": "it@brandup.online"
|
|
22
22
|
},
|
|
23
23
|
"license": "Apache-2.0",
|
|
24
|
-
"version": "1.0.
|
|
24
|
+
"version": "1.0.20",
|
|
25
25
|
"main": "source/index.ts",
|
|
26
26
|
"types": "source/index.ts",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@brandup/ui": "^1.0.
|
|
29
|
-
"@brandup/ui-dom": "^1.0.
|
|
30
|
-
"@brandup/ui-helpers": "^1.0.
|
|
31
|
-
"@brandup/ui-input": "^1.0.
|
|
32
|
-
"@brandup/ui-kit": "^1.0.
|
|
28
|
+
"@brandup/ui": "^1.0.37",
|
|
29
|
+
"@brandup/ui-dom": "^1.0.37",
|
|
30
|
+
"@brandup/ui-helpers": "^1.0.37",
|
|
31
|
+
"@brandup/ui-input": "^1.0.20",
|
|
32
|
+
"@brandup/ui-kit": "^1.0.20"
|
|
33
33
|
},
|
|
34
34
|
"files": [
|
|
35
35
|
"source",
|
package/source/textbox.less
CHANGED
package/source/textbox.ts
CHANGED
|
@@ -164,7 +164,7 @@ export default class TextBox extends InputControl<HTMLInputElement | HTMLTextAre
|
|
|
164
164
|
this.__carretToEnd(); // пыремещаем курсов в конец, если клик не по строке
|
|
165
165
|
});
|
|
166
166
|
|
|
167
|
-
this.__inputElem.addEventListener("blur", (
|
|
167
|
+
this.__inputElem.addEventListener("blur", () => {
|
|
168
168
|
hasInputClick = false;
|
|
169
169
|
|
|
170
170
|
if (this.disabled)
|
|
@@ -186,71 +186,75 @@ export default class TextBox extends InputControl<HTMLInputElement | HTMLTextAre
|
|
|
186
186
|
this.__selectAll();
|
|
187
187
|
});
|
|
188
188
|
|
|
189
|
-
this.element.addEventListener("paste", (e) => {
|
|
189
|
+
this.element.addEventListener("paste", (e: ClipboardEvent) => {
|
|
190
190
|
e.preventDefault();
|
|
191
191
|
e.stopPropagation();
|
|
192
192
|
|
|
193
|
-
if (this.readonly || this.disabled || !this.element)
|
|
193
|
+
if (this.readonly || this.disabled || !this.element)
|
|
194
|
+
return false;
|
|
194
195
|
|
|
195
196
|
let pastedData = e.clipboardData?.getData("text/plain");
|
|
196
|
-
if (pastedData)
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
197
|
+
if (!pastedData)
|
|
198
|
+
return false;
|
|
199
|
+
|
|
200
|
+
if (this.type == "number") {
|
|
201
|
+
const numberData = /[\d\s]+/.exec(pastedData);
|
|
202
|
+
if (numberData && numberData.length)
|
|
203
|
+
pastedData = numberData[0].replace(' ', '');
|
|
204
|
+
else {
|
|
205
|
+
this.element.classList.add("incorrect");
|
|
206
|
+
window.setTimeout(() => this.element?.classList.remove("incorrect"), 300);
|
|
207
|
+
return false;
|
|
206
208
|
}
|
|
209
|
+
}
|
|
207
210
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
+
const selection = window.getSelection();
|
|
212
|
+
if (!selection)
|
|
213
|
+
return false; // TODO
|
|
211
214
|
|
|
212
|
-
|
|
213
|
-
|
|
215
|
+
if (this.maxlength > 0) {
|
|
216
|
+
// обрезаем вставляемый текст по кол-ву оставшихся символов для ввода
|
|
214
217
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
+
const selectionLength = selection.toString().length;
|
|
219
|
+
const currentTextLength = this.__getTextLenght();
|
|
220
|
+
const leftSymbols = this.maxlength - currentTextLength + selectionLength; // осталось символов для ввода
|
|
218
221
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
+
if (pastedData.length > leftSymbols)
|
|
223
|
+
pastedData = pastedData.substring(0, leftSymbols);
|
|
224
|
+
}
|
|
222
225
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
+
const lines = pastedData.split(/\n/);
|
|
227
|
+
// тримим все строки, кроме начала первой строки, вдруг так нужно
|
|
228
|
+
const output = lines.map((line, index) => index === 0 ? line.trimEnd() : line.trim());
|
|
226
229
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
230
|
+
var fragment = document.createDocumentFragment();
|
|
231
|
+
if (!this.multyline) {
|
|
232
|
+
fragment.appendChild(document.createTextNode(output.join(" ")));
|
|
233
|
+
} else {
|
|
234
|
+
output.forEach((line, index) => {
|
|
235
|
+
if (index > 0) fragment.appendChild(document.createElement("br"));
|
|
233
236
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
+
fragment.appendChild(document.createTextNode(line));
|
|
238
|
+
});
|
|
239
|
+
}
|
|
237
240
|
|
|
238
|
-
|
|
239
|
-
|
|
241
|
+
// Удаляем выделенную область
|
|
242
|
+
selection.getRangeAt(0).deleteContents();
|
|
240
243
|
|
|
241
|
-
|
|
242
|
-
|
|
244
|
+
// Вставляем текст
|
|
245
|
+
selection.getRangeAt(0).insertNode(fragment);
|
|
243
246
|
|
|
244
|
-
|
|
245
|
-
|
|
247
|
+
// Перемещаем курсор в конец вставленной области
|
|
248
|
+
selection.setPosition(selection.focusNode, selection.focusOffset);
|
|
246
249
|
|
|
247
|
-
|
|
248
|
-
|
|
250
|
+
this.__applyValue();
|
|
251
|
+
|
|
252
|
+
return true;
|
|
249
253
|
});
|
|
250
254
|
|
|
251
255
|
this.__inputElem.addEventListener("keydown", (e: KeyboardEvent) => {
|
|
252
256
|
if (!this.element)
|
|
253
|
-
return;
|
|
257
|
+
return false;
|
|
254
258
|
|
|
255
259
|
const isChar = e.key.length === 1;
|
|
256
260
|
|
|
@@ -290,7 +294,7 @@ export default class TextBox extends InputControl<HTMLInputElement | HTMLTextAre
|
|
|
290
294
|
e.stopPropagation();
|
|
291
295
|
|
|
292
296
|
this.__toIncorrect();
|
|
293
|
-
return;
|
|
297
|
+
return false;
|
|
294
298
|
}
|
|
295
299
|
}
|
|
296
300
|
|
|
@@ -300,6 +304,8 @@ export default class TextBox extends InputControl<HTMLInputElement | HTMLTextAre
|
|
|
300
304
|
this.__submitForm();
|
|
301
305
|
return false;
|
|
302
306
|
}
|
|
307
|
+
|
|
308
|
+
return true;
|
|
303
309
|
});
|
|
304
310
|
|
|
305
311
|
this.__inputElem.addEventListener("input", () => {
|
|
@@ -448,7 +454,7 @@ export default class TextBox extends InputControl<HTMLInputElement | HTMLTextAre
|
|
|
448
454
|
this.__onChange();
|
|
449
455
|
}
|
|
450
456
|
|
|
451
|
-
validate(): boolean {
|
|
457
|
+
override validate(): boolean {
|
|
452
458
|
if (!this.element)
|
|
453
459
|
return false;
|
|
454
460
|
|
|
@@ -471,7 +477,7 @@ export default class TextBox extends InputControl<HTMLInputElement | HTMLTextAre
|
|
|
471
477
|
return isValid;
|
|
472
478
|
}
|
|
473
479
|
|
|
474
|
-
destroy(): void {
|
|
480
|
+
override destroy(): void {
|
|
475
481
|
this.__valueElem.tabIndex = this.__inputElem.tabIndex;
|
|
476
482
|
|
|
477
483
|
this.element?.insertAdjacentElement("afterend", this.__valueElem);
|