source: trip-planner-front/node_modules/primeng/fesm2020/primeng-inputnumber.mjs@ 571e0df

Last change on this file since 571e0df was 59329aa, checked in by Ema <ema_spirova@…>, 3 years ago

adding photos

  • Property mode set to 100644
File size: 46.7 KB
RevLine 
[59329aa]1import * as i0 from '@angular/core';
2import { forwardRef, EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, ViewChild, Output, NgModule } from '@angular/core';
3import * as i1 from '@angular/common';
4import { CommonModule } from '@angular/common';
5import * as i2 from 'primeng/inputtext';
6import { InputTextModule } from 'primeng/inputtext';
7import * as i3 from 'primeng/button';
8import { ButtonModule } from 'primeng/button';
9import { NG_VALUE_ACCESSOR } from '@angular/forms';
10
11const INPUTNUMBER_VALUE_ACCESSOR = {
12 provide: NG_VALUE_ACCESSOR,
13 useExisting: forwardRef(() => InputNumber),
14 multi: true
15};
16class InputNumber {
17 constructor(el, cd) {
18 this.el = el;
19 this.cd = cd;
20 this.showButtons = false;
21 this.format = true;
22 this.buttonLayout = "stacked";
23 this.incrementButtonIcon = 'pi pi-angle-up';
24 this.decrementButtonIcon = 'pi pi-angle-down';
25 this.readonly = false;
26 this.step = 1;
27 this.allowEmpty = true;
28 this.mode = "decimal";
29 this.useGrouping = true;
30 this.onInput = new EventEmitter();
31 this.onFocus = new EventEmitter();
32 this.onBlur = new EventEmitter();
33 this.onKeyDown = new EventEmitter();
34 this.onModelChange = () => { };
35 this.onModelTouched = () => { };
36 this.groupChar = '';
37 this.prefixChar = '';
38 this.suffixChar = '';
39 }
40 get disabled() {
41 return this._disabled;
42 }
43 set disabled(disabled) {
44 if (disabled)
45 this.focused = false;
46 this._disabled = disabled;
47 if (this.timer)
48 this.clearTimer();
49 }
50 ngOnChanges(simpleChange) {
51 const props = ['locale', 'localeMatcher', 'mode', 'currency', 'currencyDisplay', 'useGrouping', 'minFractionDigits', 'maxFractionDigits', 'prefix', 'suffix'];
52 if (props.some(p => !!simpleChange[p])) {
53 this.updateConstructParser();
54 }
55 }
56 ngOnInit() {
57 this.constructParser();
58 this.initialized = true;
59 }
60 getOptions() {
61 return {
62 localeMatcher: this.localeMatcher,
63 style: this.mode,
64 currency: this.currency,
65 currencyDisplay: this.currencyDisplay,
66 useGrouping: this.useGrouping,
67 minimumFractionDigits: this.minFractionDigits,
68 maximumFractionDigits: this.maxFractionDigits
69 };
70 }
71 constructParser() {
72 this.numberFormat = new Intl.NumberFormat(this.locale, this.getOptions());
73 const numerals = [...new Intl.NumberFormat(this.locale, { useGrouping: false }).format(9876543210)].reverse();
74 const index = new Map(numerals.map((d, i) => [d, i]));
75 this._numeral = new RegExp(`[${numerals.join('')}]`, 'g');
76 this._group = this.getGroupingExpression();
77 this._minusSign = this.getMinusSignExpression();
78 this._currency = this.getCurrencyExpression();
79 this._decimal = this.getDecimalExpression();
80 this._suffix = this.getSuffixExpression();
81 this._prefix = this.getPrefixExpression();
82 this._index = d => index.get(d);
83 }
84 updateConstructParser() {
85 if (this.initialized) {
86 this.constructParser();
87 }
88 }
89 escapeRegExp(text) {
90 return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
91 }
92 getDecimalExpression() {
93 const formatter = new Intl.NumberFormat(this.locale, { ...this.getOptions(), useGrouping: false });
94 return new RegExp(`[${formatter.format(1.1).replace(this._currency, '').trim().replace(this._numeral, '')}]`, 'g');
95 }
96 getGroupingExpression() {
97 const formatter = new Intl.NumberFormat(this.locale, { useGrouping: true });
98 this.groupChar = formatter.format(1000000).trim().replace(this._numeral, '').charAt(0);
99 return new RegExp(`[${this.groupChar}]`, 'g');
100 }
101 getMinusSignExpression() {
102 const formatter = new Intl.NumberFormat(this.locale, { useGrouping: false });
103 return new RegExp(`[${formatter.format(-1).trim().replace(this._numeral, '')}]`, 'g');
104 }
105 getCurrencyExpression() {
106 if (this.currency) {
107 const formatter = new Intl.NumberFormat(this.locale, { style: 'currency', currency: this.currency, currencyDisplay: this.currencyDisplay,
108 minimumFractionDigits: 0, maximumFractionDigits: 0 });
109 return new RegExp(`[${formatter.format(1).replace(/\s/g, '').replace(this._numeral, '').replace(this._group, '')}]`, 'g');
110 }
111 return new RegExp(`[]`, 'g');
112 }
113 getPrefixExpression() {
114 if (this.prefix) {
115 this.prefixChar = this.prefix;
116 }
117 else {
118 const formatter = new Intl.NumberFormat(this.locale, { style: this.mode, currency: this.currency, currencyDisplay: this.currencyDisplay });
119 this.prefixChar = formatter.format(1).split('1')[0];
120 }
121 return new RegExp(`${this.escapeRegExp(this.prefixChar || '')}`, 'g');
122 }
123 getSuffixExpression() {
124 if (this.suffix) {
125 this.suffixChar = this.suffix;
126 }
127 else {
128 const formatter = new Intl.NumberFormat(this.locale, { style: this.mode, currency: this.currency, currencyDisplay: this.currencyDisplay,
129 minimumFractionDigits: 0, maximumFractionDigits: 0 });
130 this.suffixChar = formatter.format(1).split('1')[1];
131 }
132 return new RegExp(`${this.escapeRegExp(this.suffixChar || '')}`, 'g');
133 }
134 formatValue(value) {
135 if (value != null) {
136 if (value === '-') { // Minus sign
137 return value;
138 }
139 if (this.format) {
140 let formatter = new Intl.NumberFormat(this.locale, this.getOptions());
141 let formattedValue = formatter.format(value);
142 if (this.prefix) {
143 formattedValue = this.prefix + formattedValue;
144 }
145 if (this.suffix) {
146 formattedValue = formattedValue + this.suffix;
147 }
148 return formattedValue;
149 }
150 return value.toString();
151 }
152 return '';
153 }
154 parseValue(text) {
155 let filteredText = text
156 .replace(this._suffix, '')
157 .replace(this._prefix, '')
158 .trim()
159 .replace(/\s/g, '')
160 .replace(this._currency, '')
161 .replace(this._group, '')
162 .replace(this._minusSign, '-')
163 .replace(this._decimal, '.')
164 .replace(this._numeral, this._index);
165 if (filteredText) {
166 if (filteredText === '-') // Minus sign
167 return filteredText;
168 let parsedValue = +filteredText;
169 return isNaN(parsedValue) ? null : parsedValue;
170 }
171 return null;
172 }
173 repeat(event, interval, dir) {
174 if (this.readonly) {
175 return;
176 }
177 let i = interval || 500;
178 this.clearTimer();
179 this.timer = setTimeout(() => {
180 this.repeat(event, 40, dir);
181 }, i);
182 this.spin(event, dir);
183 }
184 spin(event, dir) {
185 let step = this.step * dir;
186 let currentValue = this.parseValue(this.input.nativeElement.value) || 0;
187 let newValue = this.validateValue(currentValue + step);
188 if (this.maxlength && this.maxlength < this.formatValue(newValue).length) {
189 return;
190 }
191 this.updateInput(newValue, null, 'spin', null);
192 this.updateModel(event, newValue);
193 this.handleOnInput(event, currentValue, newValue);
194 }
195 onUpButtonMouseDown(event) {
196 this.input.nativeElement.focus();
197 this.repeat(event, null, 1);
198 event.preventDefault();
199 }
200 onUpButtonMouseUp() {
201 this.clearTimer();
202 }
203 onUpButtonMouseLeave() {
204 this.clearTimer();
205 }
206 onUpButtonKeyDown(event) {
207 if (event.keyCode === 32 || event.keyCode === 13) {
208 this.repeat(event, null, 1);
209 }
210 }
211 onUpButtonKeyUp() {
212 this.clearTimer();
213 }
214 onDownButtonMouseDown(event) {
215 this.input.nativeElement.focus();
216 this.repeat(event, null, -1);
217 event.preventDefault();
218 }
219 onDownButtonMouseUp() {
220 this.clearTimer();
221 }
222 onDownButtonMouseLeave() {
223 this.clearTimer();
224 }
225 onDownButtonKeyUp() {
226 this.clearTimer();
227 }
228 onDownButtonKeyDown(event) {
229 if (event.keyCode === 32 || event.keyCode === 13) {
230 this.repeat(event, null, -1);
231 }
232 }
233 onUserInput(event) {
234 if (this.isSpecialChar) {
235 event.target.value = this.lastValue;
236 }
237 this.isSpecialChar = false;
238 }
239 onInputKeyDown(event) {
240 this.lastValue = event.target.value;
241 if (event.shiftKey || event.altKey) {
242 this.isSpecialChar = true;
243 return;
244 }
245 let selectionStart = event.target.selectionStart;
246 let selectionEnd = event.target.selectionEnd;
247 let inputValue = event.target.value;
248 let newValueStr = null;
249 if (event.altKey) {
250 event.preventDefault();
251 }
252 switch (event.which) {
253 //up
254 case 38:
255 this.spin(event, 1);
256 event.preventDefault();
257 break;
258 //down
259 case 40:
260 this.spin(event, -1);
261 event.preventDefault();
262 break;
263 //left
264 case 37:
265 if (!this.isNumeralChar(inputValue.charAt(selectionStart - 1))) {
266 event.preventDefault();
267 }
268 break;
269 //right
270 case 39:
271 if (!this.isNumeralChar(inputValue.charAt(selectionStart))) {
272 event.preventDefault();
273 }
274 break;
275 //enter
276 case 13:
277 newValueStr = this.validateValue(this.parseValue(this.input.nativeElement.value));
278 this.input.nativeElement.value = this.formatValue(newValueStr);
279 this.input.nativeElement.setAttribute('aria-valuenow', newValueStr);
280 this.updateModel(event, newValueStr);
281 break;
282 //backspace
283 case 8: {
284 event.preventDefault();
285 if (selectionStart === selectionEnd) {
286 const deleteChar = inputValue.charAt(selectionStart - 1);
287 const { decimalCharIndex, decimalCharIndexWithoutPrefix } = this.getDecimalCharIndexes(inputValue);
288 if (this.isNumeralChar(deleteChar)) {
289 const decimalLength = this.getDecimalLength(inputValue);
290 if (this._group.test(deleteChar)) {
291 this._group.lastIndex = 0;
292 newValueStr = inputValue.slice(0, selectionStart - 2) + inputValue.slice(selectionStart - 1);
293 }
294 else if (this._decimal.test(deleteChar)) {
295 this._decimal.lastIndex = 0;
296 if (decimalLength) {
297 this.input.nativeElement.setSelectionRange(selectionStart - 1, selectionStart - 1);
298 }
299 else {
300 newValueStr = inputValue.slice(0, selectionStart - 1) + inputValue.slice(selectionStart);
301 }
302 }
303 else if (decimalCharIndex > 0 && selectionStart > decimalCharIndex) {
304 const insertedText = this.isDecimalMode() && (this.minFractionDigits || 0) < decimalLength ? '' : '0';
305 newValueStr = inputValue.slice(0, selectionStart - 1) + insertedText + inputValue.slice(selectionStart);
306 }
307 else if (decimalCharIndexWithoutPrefix === 1) {
308 newValueStr = inputValue.slice(0, selectionStart - 1) + '0' + inputValue.slice(selectionStart);
309 newValueStr = this.parseValue(newValueStr) > 0 ? newValueStr : '';
310 }
311 else {
312 newValueStr = inputValue.slice(0, selectionStart - 1) + inputValue.slice(selectionStart);
313 }
314 }
315 this.updateValue(event, newValueStr, null, 'delete-single');
316 }
317 else {
318 newValueStr = this.deleteRange(inputValue, selectionStart, selectionEnd);
319 this.updateValue(event, newValueStr, null, 'delete-range');
320 }
321 break;
322 }
323 // del
324 case 46:
325 event.preventDefault();
326 if (selectionStart === selectionEnd) {
327 const deleteChar = inputValue.charAt(selectionStart);
328 const { decimalCharIndex, decimalCharIndexWithoutPrefix } = this.getDecimalCharIndexes(inputValue);
329 if (this.isNumeralChar(deleteChar)) {
330 const decimalLength = this.getDecimalLength(inputValue);
331 if (this._group.test(deleteChar)) {
332 this._group.lastIndex = 0;
333 newValueStr = inputValue.slice(0, selectionStart) + inputValue.slice(selectionStart + 2);
334 }
335 else if (this._decimal.test(deleteChar)) {
336 this._decimal.lastIndex = 0;
337 if (decimalLength) {
338 this.input.nativeElement.setSelectionRange(selectionStart + 1, selectionStart + 1);
339 }
340 else {
341 newValueStr = inputValue.slice(0, selectionStart) + inputValue.slice(selectionStart + 1);
342 }
343 }
344 else if (decimalCharIndex > 0 && selectionStart > decimalCharIndex) {
345 const insertedText = this.isDecimalMode() && (this.minFractionDigits || 0) < decimalLength ? '' : '0';
346 newValueStr = inputValue.slice(0, selectionStart) + insertedText + inputValue.slice(selectionStart + 1);
347 }
348 else if (decimalCharIndexWithoutPrefix === 1) {
349 newValueStr = inputValue.slice(0, selectionStart) + '0' + inputValue.slice(selectionStart + 1);
350 newValueStr = this.parseValue(newValueStr) > 0 ? newValueStr : '';
351 }
352 else {
353 newValueStr = inputValue.slice(0, selectionStart) + inputValue.slice(selectionStart + 1);
354 }
355 }
356 this.updateValue(event, newValueStr, null, 'delete-back-single');
357 }
358 else {
359 newValueStr = this.deleteRange(inputValue, selectionStart, selectionEnd);
360 this.updateValue(event, newValueStr, null, 'delete-range');
361 }
362 break;
363 default:
364 break;
365 }
366 this.onKeyDown.emit(event);
367 }
368 onInputKeyPress(event) {
369 event.preventDefault();
370 let code = event.which || event.keyCode;
371 let char = String.fromCharCode(code);
372 const isDecimalSign = this.isDecimalSign(char);
373 const isMinusSign = this.isMinusSign(char);
374 if ((48 <= code && code <= 57) || isMinusSign || isDecimalSign) {
375 this.insert(event, char, { isDecimalSign, isMinusSign });
376 }
377 }
378 onPaste(event) {
379 if (!this.disabled) {
380 event.preventDefault();
381 let data = (event.clipboardData || window['clipboardData']).getData('Text');
382 if (data) {
383 let filteredData = this.parseValue(data);
384 if (filteredData != null) {
385 this.insert(event, filteredData.toString());
386 }
387 }
388 }
389 }
390 allowMinusSign() {
391 return this.min == null || this.min < 0;
392 }
393 isMinusSign(char) {
394 if (this._minusSign.test(char) || char === '-') {
395 this._minusSign.lastIndex = 0;
396 return true;
397 }
398 return false;
399 }
400 isDecimalSign(char) {
401 if (this._decimal.test(char)) {
402 this._decimal.lastIndex = 0;
403 return true;
404 }
405 return false;
406 }
407 isDecimalMode() {
408 return this.mode === 'decimal';
409 }
410 getDecimalCharIndexes(val) {
411 let decimalCharIndex = val.search(this._decimal);
412 this._decimal.lastIndex = 0;
413 const filteredVal = val.replace(this._prefix, '').trim().replace(/\s/g, '').replace(this._currency, '');
414 const decimalCharIndexWithoutPrefix = filteredVal.search(this._decimal);
415 this._decimal.lastIndex = 0;
416 return { decimalCharIndex, decimalCharIndexWithoutPrefix };
417 }
418 getCharIndexes(val) {
419 const decimalCharIndex = val.search(this._decimal);
420 this._decimal.lastIndex = 0;
421 const minusCharIndex = val.search(this._minusSign);
422 this._minusSign.lastIndex = 0;
423 const suffixCharIndex = val.search(this._suffix);
424 this._suffix.lastIndex = 0;
425 const currencyCharIndex = val.search(this._currency);
426 this._currency.lastIndex = 0;
427 return { decimalCharIndex, minusCharIndex, suffixCharIndex, currencyCharIndex };
428 }
429 insert(event, text, sign = { isDecimalSign: false, isMinusSign: false }) {
430 const minusCharIndexOnText = text.search(this._minusSign);
431 this._minusSign.lastIndex = 0;
432 if (!this.allowMinusSign() && minusCharIndexOnText !== -1) {
433 return;
434 }
435 let selectionStart = this.input.nativeElement.selectionStart;
436 let selectionEnd = this.input.nativeElement.selectionEnd;
437 let inputValue = this.input.nativeElement.value.trim();
438 const { decimalCharIndex, minusCharIndex, suffixCharIndex, currencyCharIndex } = this.getCharIndexes(inputValue);
439 let newValueStr;
440 if (sign.isMinusSign) {
441 if (selectionStart === 0) {
442 newValueStr = inputValue;
443 if (minusCharIndex === -1 || selectionEnd !== 0) {
444 newValueStr = this.insertText(inputValue, text, 0, selectionEnd);
445 }
446 this.updateValue(event, newValueStr, text, 'insert');
447 }
448 }
449 else if (sign.isDecimalSign) {
450 if (decimalCharIndex > 0 && selectionStart === decimalCharIndex) {
451 this.updateValue(event, inputValue, text, 'insert');
452 }
453 else if (decimalCharIndex > selectionStart && decimalCharIndex < selectionEnd) {
454 newValueStr = this.insertText(inputValue, text, selectionStart, selectionEnd);
455 this.updateValue(event, newValueStr, text, 'insert');
456 }
457 else if (decimalCharIndex === -1 && this.maxFractionDigits) {
458 newValueStr = this.insertText(inputValue, text, selectionStart, selectionEnd);
459 this.updateValue(event, newValueStr, text, 'insert');
460 }
461 }
462 else {
463 const maxFractionDigits = this.numberFormat.resolvedOptions().maximumFractionDigits;
464 const operation = selectionStart !== selectionEnd ? 'range-insert' : 'insert';
465 if (decimalCharIndex > 0 && selectionStart > decimalCharIndex) {
466 if ((selectionStart + text.length - (decimalCharIndex + 1)) <= maxFractionDigits) {
467 const charIndex = currencyCharIndex >= selectionStart ? currencyCharIndex - 1 : (suffixCharIndex >= selectionStart ? suffixCharIndex : inputValue.length);
468 newValueStr = inputValue.slice(0, selectionStart) + text + inputValue.slice(selectionStart + text.length, charIndex) + inputValue.slice(charIndex);
469 this.updateValue(event, newValueStr, text, operation);
470 }
471 }
472 else {
473 newValueStr = this.insertText(inputValue, text, selectionStart, selectionEnd);
474 this.updateValue(event, newValueStr, text, operation);
475 }
476 }
477 }
478 insertText(value, text, start, end) {
479 let textSplit = text === '.' ? text : text.split('.');
480 if (textSplit.length === 2) {
481 const decimalCharIndex = value.slice(start, end).search(this._decimal);
482 this._decimal.lastIndex = 0;
483 return (decimalCharIndex > 0) ? value.slice(0, start) + this.formatValue(text) + value.slice(end) : (value || this.formatValue(text));
484 }
485 else if ((end - start) === value.length) {
486 return this.formatValue(text);
487 }
488 else if (start === 0) {
489 return text + value.slice(end);
490 }
491 else if (end === value.length) {
492 return value.slice(0, start) + text;
493 }
494 else {
495 return value.slice(0, start) + text + value.slice(end);
496 }
497 }
498 deleteRange(value, start, end) {
499 let newValueStr;
500 if ((end - start) === value.length)
501 newValueStr = '';
502 else if (start === 0)
503 newValueStr = value.slice(end);
504 else if (end === value.length)
505 newValueStr = value.slice(0, start);
506 else
507 newValueStr = value.slice(0, start) + value.slice(end);
508 return newValueStr;
509 }
510 initCursor() {
511 let selectionStart = this.input.nativeElement.selectionStart;
512 let inputValue = this.input.nativeElement.value;
513 let valueLength = inputValue.length;
514 let index = null;
515 // remove prefix
516 let prefixLength = (this.prefixChar || '').length;
517 inputValue = inputValue.replace(this._prefix, '');
518 selectionStart = selectionStart - prefixLength;
519 let char = inputValue.charAt(selectionStart);
520 if (this.isNumeralChar(char)) {
521 return selectionStart + prefixLength;
522 }
523 //left
524 let i = selectionStart - 1;
525 while (i >= 0) {
526 char = inputValue.charAt(i);
527 if (this.isNumeralChar(char)) {
528 index = i + prefixLength;
529 break;
530 }
531 else {
532 i--;
533 }
534 }
535 if (index !== null) {
536 this.input.nativeElement.setSelectionRange(index + 1, index + 1);
537 }
538 else {
539 i = selectionStart;
540 while (i < valueLength) {
541 char = inputValue.charAt(i);
542 if (this.isNumeralChar(char)) {
543 index = i + prefixLength;
544 break;
545 }
546 else {
547 i++;
548 }
549 }
550 if (index !== null) {
551 this.input.nativeElement.setSelectionRange(index, index);
552 }
553 }
554 return index || 0;
555 }
556 onInputClick() {
557 this.initCursor();
558 }
559 isNumeralChar(char) {
560 if (char.length === 1 && (this._numeral.test(char) || this._decimal.test(char) || this._group.test(char) || this._minusSign.test(char))) {
561 this.resetRegex();
562 return true;
563 }
564 return false;
565 }
566 resetRegex() {
567 this._numeral.lastIndex = 0;
568 this._decimal.lastIndex = 0;
569 this._group.lastIndex = 0;
570 this._minusSign.lastIndex = 0;
571 }
572 updateValue(event, valueStr, insertedValueStr, operation) {
573 let currentValue = this.input.nativeElement.value;
574 let newValue = null;
575 if (valueStr != null) {
576 newValue = this.parseValue(valueStr);
577 newValue = !newValue && !this.allowEmpty ? 0 : newValue;
578 this.updateInput(newValue, insertedValueStr, operation, valueStr);
579 this.handleOnInput(event, currentValue, newValue);
580 }
581 }
582 handleOnInput(event, currentValue, newValue) {
583 if (this.isValueChanged(currentValue, newValue)) {
584 this.onInput.emit({ originalEvent: event, value: newValue });
585 }
586 }
587 isValueChanged(currentValue, newValue) {
588 if (newValue === null && currentValue !== null) {
589 return true;
590 }
591 if (newValue != null) {
592 let parsedCurrentValue = (typeof currentValue === 'string') ? this.parseValue(currentValue) : currentValue;
593 return newValue !== parsedCurrentValue;
594 }
595 return false;
596 }
597 validateValue(value) {
598 if (value === '-' || value == null) {
599 return null;
600 }
601 if (this.min != null && value < this.min) {
602 return this.min;
603 }
604 if (this.max != null && value > this.max) {
605 return this.max;
606 }
607 return value;
608 }
609 updateInput(value, insertedValueStr, operation, valueStr) {
610 insertedValueStr = insertedValueStr || '';
611 let inputValue = this.input.nativeElement.value;
612 let newValue = this.formatValue(value);
613 let currentLength = inputValue.length;
614 if (newValue !== valueStr) {
615 newValue = this.concatValues(newValue, valueStr);
616 }
617 if (currentLength === 0) {
618 this.input.nativeElement.value = newValue;
619 this.input.nativeElement.setSelectionRange(0, 0);
620 const index = this.initCursor();
621 const selectionEnd = index + insertedValueStr.length;
622 this.input.nativeElement.setSelectionRange(selectionEnd, selectionEnd);
623 }
624 else {
625 let selectionStart = this.input.nativeElement.selectionStart;
626 let selectionEnd = this.input.nativeElement.selectionEnd;
627 if (this.maxlength && this.maxlength < newValue.length) {
628 return;
629 }
630 this.input.nativeElement.value = newValue;
631 let newLength = newValue.length;
632 if (operation === 'range-insert') {
633 const startValue = this.parseValue((inputValue || '').slice(0, selectionStart));
634 const startValueStr = startValue !== null ? startValue.toString() : '';
635 const startExpr = startValueStr.split('').join(`(${this.groupChar})?`);
636 const sRegex = new RegExp(startExpr, 'g');
637 sRegex.test(newValue);
638 const tExpr = insertedValueStr.split('').join(`(${this.groupChar})?`);
639 const tRegex = new RegExp(tExpr, 'g');
640 tRegex.test(newValue.slice(sRegex.lastIndex));
641 selectionEnd = sRegex.lastIndex + tRegex.lastIndex;
642 this.input.nativeElement.setSelectionRange(selectionEnd, selectionEnd);
643 }
644 else if (newLength === currentLength) {
645 if (operation === 'insert' || operation === 'delete-back-single')
646 this.input.nativeElement.setSelectionRange(selectionEnd + 1, selectionEnd + 1);
647 else if (operation === 'delete-single')
648 this.input.nativeElement.setSelectionRange(selectionEnd - 1, selectionEnd - 1);
649 else if (operation === 'delete-range' || operation === 'spin')
650 this.input.nativeElement.setSelectionRange(selectionEnd, selectionEnd);
651 }
652 else if (operation === 'delete-back-single') {
653 let prevChar = inputValue.charAt(selectionEnd - 1);
654 let nextChar = inputValue.charAt(selectionEnd);
655 let diff = currentLength - newLength;
656 let isGroupChar = this._group.test(nextChar);
657 if (isGroupChar && diff === 1) {
658 selectionEnd += 1;
659 }
660 else if (!isGroupChar && this.isNumeralChar(prevChar)) {
661 selectionEnd += (-1 * diff) + 1;
662 }
663 this._group.lastIndex = 0;
664 this.input.nativeElement.setSelectionRange(selectionEnd, selectionEnd);
665 }
666 else if (inputValue === '-' && operation === 'insert') {
667 this.input.nativeElement.setSelectionRange(0, 0);
668 const index = this.initCursor();
669 const selectionEnd = index + insertedValueStr.length + 1;
670 this.input.nativeElement.setSelectionRange(selectionEnd, selectionEnd);
671 }
672 else {
673 selectionEnd = selectionEnd + (newLength - currentLength);
674 this.input.nativeElement.setSelectionRange(selectionEnd, selectionEnd);
675 }
676 }
677 this.input.nativeElement.setAttribute('aria-valuenow', value);
678 }
679 concatValues(val1, val2) {
680 if (val1 && val2) {
681 let decimalCharIndex = val2.search(this._decimal);
682 this._decimal.lastIndex = 0;
683 return decimalCharIndex !== -1 ? (val1.split(this._decimal)[0] + val2.slice(decimalCharIndex)) : val1;
684 }
685 return val1;
686 }
687 getDecimalLength(value) {
688 if (value) {
689 const valueSplit = value.split(this._decimal);
690 if (valueSplit.length === 2) {
691 return valueSplit[1].replace(this._suffix, '')
692 .trim()
693 .replace(/\s/g, '')
694 .replace(this._currency, '').length;
695 }
696 }
697 return 0;
698 }
699 onInputFocus(event) {
700 this.focused = true;
701 this.onFocus.emit(event);
702 }
703 onInputBlur(event) {
704 this.focused = false;
705 let newValue = this.validateValue(this.parseValue(this.input.nativeElement.value));
706 this.input.nativeElement.value = this.formatValue(newValue);
707 this.input.nativeElement.setAttribute('aria-valuenow', newValue);
708 this.updateModel(event, newValue);
709 this.onBlur.emit(event);
710 }
711 formattedValue() {
712 const val = !this.value && !this.allowEmpty ? 0 : this.value;
713 return this.formatValue(val);
714 }
715 updateModel(event, value) {
716 if (this.value !== value) {
717 this.value = value;
718 this.onModelChange(value);
719 }
720 this.onModelTouched();
721 }
722 writeValue(value) {
723 this.value = value;
724 this.cd.markForCheck();
725 }
726 registerOnChange(fn) {
727 this.onModelChange = fn;
728 }
729 registerOnTouched(fn) {
730 this.onModelTouched = fn;
731 }
732 setDisabledState(val) {
733 this.disabled = val;
734 this.cd.markForCheck();
735 }
736 get filled() {
737 return (this.value != null && this.value.toString().length > 0);
738 }
739 clearTimer() {
740 if (this.timer) {
741 clearInterval(this.timer);
742 }
743 }
744 getFormatter() {
745 return this.numberFormat;
746 }
747}
748InputNumber.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputNumber, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
749InputNumber.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.0", type: InputNumber, selector: "p-inputNumber", inputs: { showButtons: "showButtons", format: "format", buttonLayout: "buttonLayout", inputId: "inputId", styleClass: "styleClass", style: "style", placeholder: "placeholder", size: "size", maxlength: "maxlength", tabindex: "tabindex", title: "title", ariaLabel: "ariaLabel", ariaRequired: "ariaRequired", name: "name", required: "required", autocomplete: "autocomplete", min: "min", max: "max", incrementButtonClass: "incrementButtonClass", decrementButtonClass: "decrementButtonClass", incrementButtonIcon: "incrementButtonIcon", decrementButtonIcon: "decrementButtonIcon", readonly: "readonly", step: "step", allowEmpty: "allowEmpty", locale: "locale", localeMatcher: "localeMatcher", mode: "mode", currency: "currency", currencyDisplay: "currencyDisplay", useGrouping: "useGrouping", minFractionDigits: "minFractionDigits", maxFractionDigits: "maxFractionDigits", prefix: "prefix", suffix: "suffix", inputStyle: "inputStyle", inputStyleClass: "inputStyleClass", disabled: "disabled" }, outputs: { onInput: "onInput", onFocus: "onFocus", onBlur: "onBlur", onKeyDown: "onKeyDown" }, host: { properties: { "class.p-inputwrapper-filled": "filled", "class.p-inputwrapper-focus": "focused" }, classAttribute: "p-element p-inputwrapper" }, providers: [INPUTNUMBER_VALUE_ACCESSOR], viewQueries: [{ propertyName: "input", first: true, predicate: ["input"], descendants: true }], usesOnChanges: true, ngImport: i0, template: `
750 <span [ngClass]="{'p-inputnumber p-component': true,'p-inputnumber-buttons-stacked': this.showButtons && this.buttonLayout === 'stacked',
751 'p-inputnumber-buttons-horizontal': this.showButtons && this.buttonLayout === 'horizontal', 'p-inputnumber-buttons-vertical': this.showButtons && this.buttonLayout === 'vertical'}"
752 [ngStyle]="style" [class]="styleClass">
753 <input #input [ngClass]="'p-inputnumber-input'" [ngStyle]="inputStyle" [class]="inputStyleClass" pInputText [value]="formattedValue()" [attr.placeholder]="placeholder" [attr.title]="title" [attr.id]="inputId"
754 [attr.size]="size" [attr.name]="name" [attr.autocomplete]="autocomplete" [attr.maxlength]="maxlength" [attr.tabindex]="tabindex" [attr.aria-label]="ariaLabel"
755 [attr.aria-required]="ariaRequired" [disabled]="disabled" [attr.required]="required" [attr.aria-valuemin]="min" [attr.aria-valuemax]="max" [readonly]="readonly" inputmode="decimal"
756 (input)="onUserInput($event)" (keydown)="onInputKeyDown($event)" (keypress)="onInputKeyPress($event)" (paste)="onPaste($event)" (click)="onInputClick()"
757 (focus)="onInputFocus($event)" (blur)="onInputBlur($event)">
758 <span class="p-inputnumber-button-group" *ngIf="showButtons && buttonLayout === 'stacked'">
759 <button type="button" pButton [ngClass]="{'p-inputnumber-button p-inputnumber-button-up': true}" [class]="incrementButtonClass" [icon]="incrementButtonIcon" [disabled]="disabled"
760 (mousedown)="this.onUpButtonMouseDown($event)" (mouseup)="onUpButtonMouseUp()" (mouseleave)="onUpButtonMouseLeave()" (keydown)="onUpButtonKeyDown($event)" (keyup)="onUpButtonKeyUp()"></button>
761 <button type="button" pButton [ngClass]="{'p-inputnumber-button p-inputnumber-button-down': true}" [class]="decrementButtonClass" [icon]="decrementButtonIcon" [disabled]="disabled"
762 (mousedown)="this.onDownButtonMouseDown($event)" (mouseup)="onDownButtonMouseUp()" (mouseleave)="onDownButtonMouseLeave()" (keydown)="onDownButtonKeyDown($event)" (keyup)="onDownButtonKeyUp()"></button>
763 </span>
764 <button type="button" pButton [ngClass]="{'p-inputnumber-button p-inputnumber-button-up': true}" [class]="incrementButtonClass" [icon]="incrementButtonIcon" *ngIf="showButtons && buttonLayout !== 'stacked'" [disabled]="disabled"
765 (mousedown)="this.onUpButtonMouseDown($event)" (mouseup)="onUpButtonMouseUp()" (mouseleave)="onUpButtonMouseLeave()" (keydown)="onUpButtonKeyDown($event)" (keyup)="onUpButtonKeyUp()"></button>
766 <button type="button" pButton [ngClass]="{'p-inputnumber-button p-inputnumber-button-down': true}" [class]="decrementButtonClass" [icon]="decrementButtonIcon" *ngIf="showButtons && buttonLayout !== 'stacked'" [disabled]="disabled"
767 (mousedown)="this.onDownButtonMouseDown($event)" (mouseup)="onDownButtonMouseUp()" (mouseleave)="onDownButtonMouseLeave()" (keydown)="onDownButtonKeyDown($event)" (keyup)="onDownButtonKeyUp()"></button>
768 </span>
769 `, isInline: true, styles: ["p-inputnumber,.p-inputnumber{display:inline-flex}.p-inputnumber-button{display:flex;align-items:center;justify-content:center;flex:0 0 auto}.p-inputnumber-buttons-stacked .p-button.p-inputnumber-button .p-button-label,.p-inputnumber-buttons-horizontal .p-button.p-inputnumber-button .p-button-label{display:none}.p-inputnumber-buttons-stacked .p-button.p-inputnumber-button-up{border-top-left-radius:0;border-bottom-left-radius:0;border-bottom-right-radius:0;padding:0}.p-inputnumber-buttons-stacked .p-inputnumber-input{border-top-right-radius:0;border-bottom-right-radius:0}.p-inputnumber-buttons-stacked .p-button.p-inputnumber-button-down{border-top-left-radius:0;border-top-right-radius:0;border-bottom-left-radius:0;padding:0}.p-inputnumber-buttons-stacked .p-inputnumber-button-group{display:flex;flex-direction:column}.p-inputnumber-buttons-stacked .p-inputnumber-button-group .p-button.p-inputnumber-button{flex:1 1 auto}.p-inputnumber-buttons-horizontal .p-button.p-inputnumber-button-up{order:3;border-top-left-radius:0;border-bottom-left-radius:0}.p-inputnumber-buttons-horizontal .p-inputnumber-input{order:2;border-radius:0}.p-inputnumber-buttons-horizontal .p-button.p-inputnumber-button-down{order:1;border-top-right-radius:0;border-bottom-right-radius:0}.p-inputnumber-buttons-vertical{flex-direction:column}.p-inputnumber-buttons-vertical .p-button.p-inputnumber-button-up{order:1;border-bottom-left-radius:0;border-bottom-right-radius:0;width:100%}.p-inputnumber-buttons-vertical .p-inputnumber-input{order:2;border-radius:0;text-align:center}.p-inputnumber-buttons-vertical .p-button.p-inputnumber-button-down{order:3;border-top-left-radius:0;border-top-right-radius:0;width:100%}.p-inputnumber-input{flex:1 1 auto}.p-fluid p-inputnumber,.p-fluid .p-inputnumber{width:100%}.p-fluid .p-inputnumber .p-inputnumber-input{width:1%}.p-fluid .p-inputnumber-buttons-vertical .p-inputnumber-input{width:100%}\n"], directives: [{ type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { type: i2.InputText, selector: "[pInputText]" }, { type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i3.ButtonDirective, selector: "[pButton]", inputs: ["iconPos", "loadingIcon", "label", "icon", "loading"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
770i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputNumber, decorators: [{
771 type: Component,
772 args: [{ selector: 'p-inputNumber', template: `
773 <span [ngClass]="{'p-inputnumber p-component': true,'p-inputnumber-buttons-stacked': this.showButtons && this.buttonLayout === 'stacked',
774 'p-inputnumber-buttons-horizontal': this.showButtons && this.buttonLayout === 'horizontal', 'p-inputnumber-buttons-vertical': this.showButtons && this.buttonLayout === 'vertical'}"
775 [ngStyle]="style" [class]="styleClass">
776 <input #input [ngClass]="'p-inputnumber-input'" [ngStyle]="inputStyle" [class]="inputStyleClass" pInputText [value]="formattedValue()" [attr.placeholder]="placeholder" [attr.title]="title" [attr.id]="inputId"
777 [attr.size]="size" [attr.name]="name" [attr.autocomplete]="autocomplete" [attr.maxlength]="maxlength" [attr.tabindex]="tabindex" [attr.aria-label]="ariaLabel"
778 [attr.aria-required]="ariaRequired" [disabled]="disabled" [attr.required]="required" [attr.aria-valuemin]="min" [attr.aria-valuemax]="max" [readonly]="readonly" inputmode="decimal"
779 (input)="onUserInput($event)" (keydown)="onInputKeyDown($event)" (keypress)="onInputKeyPress($event)" (paste)="onPaste($event)" (click)="onInputClick()"
780 (focus)="onInputFocus($event)" (blur)="onInputBlur($event)">
781 <span class="p-inputnumber-button-group" *ngIf="showButtons && buttonLayout === 'stacked'">
782 <button type="button" pButton [ngClass]="{'p-inputnumber-button p-inputnumber-button-up': true}" [class]="incrementButtonClass" [icon]="incrementButtonIcon" [disabled]="disabled"
783 (mousedown)="this.onUpButtonMouseDown($event)" (mouseup)="onUpButtonMouseUp()" (mouseleave)="onUpButtonMouseLeave()" (keydown)="onUpButtonKeyDown($event)" (keyup)="onUpButtonKeyUp()"></button>
784 <button type="button" pButton [ngClass]="{'p-inputnumber-button p-inputnumber-button-down': true}" [class]="decrementButtonClass" [icon]="decrementButtonIcon" [disabled]="disabled"
785 (mousedown)="this.onDownButtonMouseDown($event)" (mouseup)="onDownButtonMouseUp()" (mouseleave)="onDownButtonMouseLeave()" (keydown)="onDownButtonKeyDown($event)" (keyup)="onDownButtonKeyUp()"></button>
786 </span>
787 <button type="button" pButton [ngClass]="{'p-inputnumber-button p-inputnumber-button-up': true}" [class]="incrementButtonClass" [icon]="incrementButtonIcon" *ngIf="showButtons && buttonLayout !== 'stacked'" [disabled]="disabled"
788 (mousedown)="this.onUpButtonMouseDown($event)" (mouseup)="onUpButtonMouseUp()" (mouseleave)="onUpButtonMouseLeave()" (keydown)="onUpButtonKeyDown($event)" (keyup)="onUpButtonKeyUp()"></button>
789 <button type="button" pButton [ngClass]="{'p-inputnumber-button p-inputnumber-button-down': true}" [class]="decrementButtonClass" [icon]="decrementButtonIcon" *ngIf="showButtons && buttonLayout !== 'stacked'" [disabled]="disabled"
790 (mousedown)="this.onDownButtonMouseDown($event)" (mouseup)="onDownButtonMouseUp()" (mouseleave)="onDownButtonMouseLeave()" (keydown)="onDownButtonKeyDown($event)" (keyup)="onDownButtonKeyUp()"></button>
791 </span>
792 `, changeDetection: ChangeDetectionStrategy.OnPush, providers: [INPUTNUMBER_VALUE_ACCESSOR], encapsulation: ViewEncapsulation.None, host: {
793 'class': 'p-element p-inputwrapper',
794 '[class.p-inputwrapper-filled]': 'filled',
795 '[class.p-inputwrapper-focus]': 'focused'
796 }, styles: ["p-inputnumber,.p-inputnumber{display:inline-flex}.p-inputnumber-button{display:flex;align-items:center;justify-content:center;flex:0 0 auto}.p-inputnumber-buttons-stacked .p-button.p-inputnumber-button .p-button-label,.p-inputnumber-buttons-horizontal .p-button.p-inputnumber-button .p-button-label{display:none}.p-inputnumber-buttons-stacked .p-button.p-inputnumber-button-up{border-top-left-radius:0;border-bottom-left-radius:0;border-bottom-right-radius:0;padding:0}.p-inputnumber-buttons-stacked .p-inputnumber-input{border-top-right-radius:0;border-bottom-right-radius:0}.p-inputnumber-buttons-stacked .p-button.p-inputnumber-button-down{border-top-left-radius:0;border-top-right-radius:0;border-bottom-left-radius:0;padding:0}.p-inputnumber-buttons-stacked .p-inputnumber-button-group{display:flex;flex-direction:column}.p-inputnumber-buttons-stacked .p-inputnumber-button-group .p-button.p-inputnumber-button{flex:1 1 auto}.p-inputnumber-buttons-horizontal .p-button.p-inputnumber-button-up{order:3;border-top-left-radius:0;border-bottom-left-radius:0}.p-inputnumber-buttons-horizontal .p-inputnumber-input{order:2;border-radius:0}.p-inputnumber-buttons-horizontal .p-button.p-inputnumber-button-down{order:1;border-top-right-radius:0;border-bottom-right-radius:0}.p-inputnumber-buttons-vertical{flex-direction:column}.p-inputnumber-buttons-vertical .p-button.p-inputnumber-button-up{order:1;border-bottom-left-radius:0;border-bottom-right-radius:0;width:100%}.p-inputnumber-buttons-vertical .p-inputnumber-input{order:2;border-radius:0;text-align:center}.p-inputnumber-buttons-vertical .p-button.p-inputnumber-button-down{order:3;border-top-left-radius:0;border-top-right-radius:0;width:100%}.p-inputnumber-input{flex:1 1 auto}.p-fluid p-inputnumber,.p-fluid .p-inputnumber{width:100%}.p-fluid .p-inputnumber .p-inputnumber-input{width:1%}.p-fluid .p-inputnumber-buttons-vertical .p-inputnumber-input{width:100%}\n"] }]
797 }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { showButtons: [{
798 type: Input
799 }], format: [{
800 type: Input
801 }], buttonLayout: [{
802 type: Input
803 }], inputId: [{
804 type: Input
805 }], styleClass: [{
806 type: Input
807 }], style: [{
808 type: Input
809 }], placeholder: [{
810 type: Input
811 }], size: [{
812 type: Input
813 }], maxlength: [{
814 type: Input
815 }], tabindex: [{
816 type: Input
817 }], title: [{
818 type: Input
819 }], ariaLabel: [{
820 type: Input
821 }], ariaRequired: [{
822 type: Input
823 }], name: [{
824 type: Input
825 }], required: [{
826 type: Input
827 }], autocomplete: [{
828 type: Input
829 }], min: [{
830 type: Input
831 }], max: [{
832 type: Input
833 }], incrementButtonClass: [{
834 type: Input
835 }], decrementButtonClass: [{
836 type: Input
837 }], incrementButtonIcon: [{
838 type: Input
839 }], decrementButtonIcon: [{
840 type: Input
841 }], readonly: [{
842 type: Input
843 }], step: [{
844 type: Input
845 }], allowEmpty: [{
846 type: Input
847 }], locale: [{
848 type: Input
849 }], localeMatcher: [{
850 type: Input
851 }], mode: [{
852 type: Input
853 }], currency: [{
854 type: Input
855 }], currencyDisplay: [{
856 type: Input
857 }], useGrouping: [{
858 type: Input
859 }], minFractionDigits: [{
860 type: Input
861 }], maxFractionDigits: [{
862 type: Input
863 }], prefix: [{
864 type: Input
865 }], suffix: [{
866 type: Input
867 }], inputStyle: [{
868 type: Input
869 }], inputStyleClass: [{
870 type: Input
871 }], input: [{
872 type: ViewChild,
873 args: ['input']
874 }], onInput: [{
875 type: Output
876 }], onFocus: [{
877 type: Output
878 }], onBlur: [{
879 type: Output
880 }], onKeyDown: [{
881 type: Output
882 }], disabled: [{
883 type: Input
884 }] } });
885class InputNumberModule {
886}
887InputNumberModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputNumberModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
888InputNumberModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputNumberModule, declarations: [InputNumber], imports: [CommonModule, InputTextModule, ButtonModule], exports: [InputNumber] });
889InputNumberModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputNumberModule, imports: [[CommonModule, InputTextModule, ButtonModule]] });
890i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputNumberModule, decorators: [{
891 type: NgModule,
892 args: [{
893 imports: [CommonModule, InputTextModule, ButtonModule],
894 exports: [InputNumber],
895 declarations: [InputNumber]
896 }]
897 }] });
898
899/**
900 * Generated bundle index. Do not edit.
901 */
902
903export { INPUTNUMBER_VALUE_ACCESSOR, InputNumber, InputNumberModule };
Note: See TracBrowser for help on using the repository browser.