[59329aa] | 1 | import * as i0 from '@angular/core';
|
---|
| 2 | import { forwardRef, EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, ViewChild, Output, NgModule } from '@angular/core';
|
---|
| 3 | import * as i2 from '@angular/common';
|
---|
| 4 | import { CommonModule } from '@angular/common';
|
---|
| 5 | import { DomHandler } from 'primeng/dom';
|
---|
| 6 | import * as i1 from 'primeng/inputtext';
|
---|
| 7 | import { InputTextModule } from 'primeng/inputtext';
|
---|
| 8 | import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
---|
| 9 |
|
---|
| 10 | /*
|
---|
| 11 | Port of jQuery MaskedInput by DigitalBush as a Native Angular2 Component in Typescript without jQuery
|
---|
| 12 | https://github.com/digitalBush/jquery.maskedinput/
|
---|
| 13 |
|
---|
| 14 | Copyright (c) 2007-2014 Josh Bush (digitalbush.com)
|
---|
| 15 |
|
---|
| 16 | Permission is hereby granted, free of charge, to any person
|
---|
| 17 | obtaining a copy of this software and associated documentation
|
---|
| 18 | files (the "Software"), to deal in the Software without
|
---|
| 19 | restriction, including without limitation the rights to use,
|
---|
| 20 | copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
| 21 | copies of the Software, and to permit persons to whom the
|
---|
| 22 | Software is furnished to do so, subject to the following
|
---|
| 23 | conditions:
|
---|
| 24 |
|
---|
| 25 | The above copyright notice and this permission notice shall be
|
---|
| 26 | included in all copies or substantial portions of the Software.
|
---|
| 27 |
|
---|
| 28 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
---|
| 29 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
---|
| 30 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
---|
| 31 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
---|
| 32 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
| 33 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
| 34 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
| 35 | OTHER DEALINGS IN THE SOFTWARE.
|
---|
| 36 | */
|
---|
| 37 | const INPUTMASK_VALUE_ACCESSOR = {
|
---|
| 38 | provide: NG_VALUE_ACCESSOR,
|
---|
| 39 | useExisting: forwardRef(() => InputMask),
|
---|
| 40 | multi: true
|
---|
| 41 | };
|
---|
| 42 | class InputMask {
|
---|
| 43 | constructor(el, cd) {
|
---|
| 44 | this.el = el;
|
---|
| 45 | this.cd = cd;
|
---|
| 46 | this.type = 'text';
|
---|
| 47 | this.slotChar = '_';
|
---|
| 48 | this.autoClear = true;
|
---|
| 49 | this.characterPattern = '[A-Za-z]';
|
---|
| 50 | this.onComplete = new EventEmitter();
|
---|
| 51 | this.onFocus = new EventEmitter();
|
---|
| 52 | this.onBlur = new EventEmitter();
|
---|
| 53 | this.onInput = new EventEmitter();
|
---|
| 54 | this.onKeydown = new EventEmitter();
|
---|
| 55 | this.onModelChange = () => { };
|
---|
| 56 | this.onModelTouched = () => { };
|
---|
| 57 | }
|
---|
| 58 | ngOnInit() {
|
---|
| 59 | let ua = DomHandler.getUserAgent();
|
---|
| 60 | this.androidChrome = /chrome/i.test(ua) && /android/i.test(ua);
|
---|
| 61 | this.initMask();
|
---|
| 62 | }
|
---|
| 63 | get mask() {
|
---|
| 64 | return this._mask;
|
---|
| 65 | }
|
---|
| 66 | set mask(val) {
|
---|
| 67 | this._mask = val;
|
---|
| 68 | this.initMask();
|
---|
| 69 | this.writeValue('');
|
---|
| 70 | this.onModelChange(this.value);
|
---|
| 71 | }
|
---|
| 72 | initMask() {
|
---|
| 73 | this.tests = [];
|
---|
| 74 | this.partialPosition = this.mask.length;
|
---|
| 75 | this.len = this.mask.length;
|
---|
| 76 | this.firstNonMaskPos = null;
|
---|
| 77 | this.defs = {
|
---|
| 78 | '9': '[0-9]',
|
---|
| 79 | 'a': this.characterPattern,
|
---|
| 80 | '*': `${this.characterPattern}|[0-9]`
|
---|
| 81 | };
|
---|
| 82 | let maskTokens = this.mask.split('');
|
---|
| 83 | for (let i = 0; i < maskTokens.length; i++) {
|
---|
| 84 | let c = maskTokens[i];
|
---|
| 85 | if (c == '?') {
|
---|
| 86 | this.len--;
|
---|
| 87 | this.partialPosition = i;
|
---|
| 88 | }
|
---|
| 89 | else if (this.defs[c]) {
|
---|
| 90 | this.tests.push(new RegExp(this.defs[c]));
|
---|
| 91 | if (this.firstNonMaskPos === null) {
|
---|
| 92 | this.firstNonMaskPos = this.tests.length - 1;
|
---|
| 93 | }
|
---|
| 94 | if (i < this.partialPosition) {
|
---|
| 95 | this.lastRequiredNonMaskPos = this.tests.length - 1;
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 | else {
|
---|
| 99 | this.tests.push(null);
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 | this.buffer = [];
|
---|
| 103 | for (let i = 0; i < maskTokens.length; i++) {
|
---|
| 104 | let c = maskTokens[i];
|
---|
| 105 | if (c != '?') {
|
---|
| 106 | if (this.defs[c])
|
---|
| 107 | this.buffer.push(this.getPlaceholder(i));
|
---|
| 108 | else
|
---|
| 109 | this.buffer.push(c);
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 | this.defaultBuffer = this.buffer.join('');
|
---|
| 113 | }
|
---|
| 114 | writeValue(value) {
|
---|
| 115 | this.value = value;
|
---|
| 116 | if (this.inputViewChild && this.inputViewChild.nativeElement) {
|
---|
| 117 | if (this.value == undefined || this.value == null)
|
---|
| 118 | this.inputViewChild.nativeElement.value = '';
|
---|
| 119 | else
|
---|
| 120 | this.inputViewChild.nativeElement.value = this.value;
|
---|
| 121 | this.checkVal();
|
---|
| 122 | this.focusText = this.inputViewChild.nativeElement.value;
|
---|
| 123 | this.updateFilledState();
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
| 126 | registerOnChange(fn) {
|
---|
| 127 | this.onModelChange = fn;
|
---|
| 128 | }
|
---|
| 129 | registerOnTouched(fn) {
|
---|
| 130 | this.onModelTouched = fn;
|
---|
| 131 | }
|
---|
| 132 | setDisabledState(val) {
|
---|
| 133 | this.disabled = val;
|
---|
| 134 | this.cd.markForCheck();
|
---|
| 135 | }
|
---|
| 136 | caret(first, last) {
|
---|
| 137 | let range, begin, end;
|
---|
| 138 | if (!this.inputViewChild.nativeElement.offsetParent || this.inputViewChild.nativeElement !== this.inputViewChild.nativeElement.ownerDocument.activeElement) {
|
---|
| 139 | return;
|
---|
| 140 | }
|
---|
| 141 | if (typeof first == 'number') {
|
---|
| 142 | begin = first;
|
---|
| 143 | end = (typeof last === 'number') ? last : begin;
|
---|
| 144 | if (this.inputViewChild.nativeElement.setSelectionRange) {
|
---|
| 145 | this.inputViewChild.nativeElement.setSelectionRange(begin, end);
|
---|
| 146 | }
|
---|
| 147 | else if (this.inputViewChild.nativeElement['createTextRange']) {
|
---|
| 148 | range = this.inputViewChild.nativeElement['createTextRange']();
|
---|
| 149 | range.collapse(true);
|
---|
| 150 | range.moveEnd('character', end);
|
---|
| 151 | range.moveStart('character', begin);
|
---|
| 152 | range.select();
|
---|
| 153 | }
|
---|
| 154 | }
|
---|
| 155 | else {
|
---|
| 156 | if (this.inputViewChild.nativeElement.setSelectionRange) {
|
---|
| 157 | begin = this.inputViewChild.nativeElement.selectionStart;
|
---|
| 158 | end = this.inputViewChild.nativeElement.selectionEnd;
|
---|
| 159 | }
|
---|
| 160 | else if (document['selection'] && document['selection'].createRange) {
|
---|
| 161 | range = document['selection'].createRange();
|
---|
| 162 | begin = 0 - range.duplicate().moveStart('character', -100000);
|
---|
| 163 | end = begin + range.text.length;
|
---|
| 164 | }
|
---|
| 165 | return { begin: begin, end: end };
|
---|
| 166 | }
|
---|
| 167 | }
|
---|
| 168 | isCompleted() {
|
---|
| 169 | let completed;
|
---|
| 170 | for (let i = this.firstNonMaskPos; i <= this.lastRequiredNonMaskPos; i++) {
|
---|
| 171 | if (this.tests[i] && this.buffer[i] === this.getPlaceholder(i)) {
|
---|
| 172 | return false;
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 | return true;
|
---|
| 176 | }
|
---|
| 177 | getPlaceholder(i) {
|
---|
| 178 | if (i < this.slotChar.length) {
|
---|
| 179 | return this.slotChar.charAt(i);
|
---|
| 180 | }
|
---|
| 181 | return this.slotChar.charAt(0);
|
---|
| 182 | }
|
---|
| 183 | seekNext(pos) {
|
---|
| 184 | while (++pos < this.len && !this.tests[pos])
|
---|
| 185 | ;
|
---|
| 186 | return pos;
|
---|
| 187 | }
|
---|
| 188 | seekPrev(pos) {
|
---|
| 189 | while (--pos >= 0 && !this.tests[pos])
|
---|
| 190 | ;
|
---|
| 191 | return pos;
|
---|
| 192 | }
|
---|
| 193 | shiftL(begin, end) {
|
---|
| 194 | let i, j;
|
---|
| 195 | if (begin < 0) {
|
---|
| 196 | return;
|
---|
| 197 | }
|
---|
| 198 | for (i = begin, j = this.seekNext(end); i < this.len; i++) {
|
---|
| 199 | if (this.tests[i]) {
|
---|
| 200 | if (j < this.len && this.tests[i].test(this.buffer[j])) {
|
---|
| 201 | this.buffer[i] = this.buffer[j];
|
---|
| 202 | this.buffer[j] = this.getPlaceholder(j);
|
---|
| 203 | }
|
---|
| 204 | else {
|
---|
| 205 | break;
|
---|
| 206 | }
|
---|
| 207 | j = this.seekNext(j);
|
---|
| 208 | }
|
---|
| 209 | }
|
---|
| 210 | this.writeBuffer();
|
---|
| 211 | this.caret(Math.max(this.firstNonMaskPos, begin));
|
---|
| 212 | }
|
---|
| 213 | shiftR(pos) {
|
---|
| 214 | let i, c, j, t;
|
---|
| 215 | for (i = pos, c = this.getPlaceholder(pos); i < this.len; i++) {
|
---|
| 216 | if (this.tests[i]) {
|
---|
| 217 | j = this.seekNext(i);
|
---|
| 218 | t = this.buffer[i];
|
---|
| 219 | this.buffer[i] = c;
|
---|
| 220 | if (j < this.len && this.tests[j].test(t)) {
|
---|
| 221 | c = t;
|
---|
| 222 | }
|
---|
| 223 | else {
|
---|
| 224 | break;
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 | }
|
---|
| 228 | }
|
---|
| 229 | handleAndroidInput(e) {
|
---|
| 230 | var curVal = this.inputViewChild.nativeElement.value;
|
---|
| 231 | var pos = this.caret();
|
---|
| 232 | if (this.oldVal && this.oldVal.length && this.oldVal.length > curVal.length) {
|
---|
| 233 | // a deletion or backspace happened
|
---|
| 234 | this.checkVal(true);
|
---|
| 235 | while (pos.begin > 0 && !this.tests[pos.begin - 1])
|
---|
| 236 | pos.begin--;
|
---|
| 237 | if (pos.begin === 0) {
|
---|
| 238 | while (pos.begin < this.firstNonMaskPos && !this.tests[pos.begin])
|
---|
| 239 | pos.begin++;
|
---|
| 240 | }
|
---|
| 241 | setTimeout(() => {
|
---|
| 242 | this.caret(pos.begin, pos.begin);
|
---|
| 243 | this.updateModel(e);
|
---|
| 244 | if (this.isCompleted()) {
|
---|
| 245 | this.onComplete.emit();
|
---|
| 246 | }
|
---|
| 247 | }, 0);
|
---|
| 248 | }
|
---|
| 249 | else {
|
---|
| 250 | this.checkVal(true);
|
---|
| 251 | while (pos.begin < this.len && !this.tests[pos.begin])
|
---|
| 252 | pos.begin++;
|
---|
| 253 | setTimeout(() => {
|
---|
| 254 | this.caret(pos.begin, pos.begin);
|
---|
| 255 | this.updateModel(e);
|
---|
| 256 | if (this.isCompleted()) {
|
---|
| 257 | this.onComplete.emit();
|
---|
| 258 | }
|
---|
| 259 | }, 0);
|
---|
| 260 | }
|
---|
| 261 | }
|
---|
| 262 | onInputBlur(e) {
|
---|
| 263 | this.focused = false;
|
---|
| 264 | this.onModelTouched();
|
---|
| 265 | this.checkVal();
|
---|
| 266 | this.updateFilledState();
|
---|
| 267 | this.onBlur.emit(e);
|
---|
| 268 | if (this.inputViewChild.nativeElement.value != this.focusText || this.inputViewChild.nativeElement.value != this.value) {
|
---|
| 269 | this.updateModel(e);
|
---|
| 270 | let event = document.createEvent('HTMLEvents');
|
---|
| 271 | event.initEvent('change', true, false);
|
---|
| 272 | this.inputViewChild.nativeElement.dispatchEvent(event);
|
---|
| 273 | }
|
---|
| 274 | }
|
---|
| 275 | onInputKeydown(e) {
|
---|
| 276 | if (this.readonly) {
|
---|
| 277 | return;
|
---|
| 278 | }
|
---|
| 279 | let k = e.which || e.keyCode, pos, begin, end;
|
---|
| 280 | let iPhone = /iphone/i.test(DomHandler.getUserAgent());
|
---|
| 281 | this.oldVal = this.inputViewChild.nativeElement.value;
|
---|
| 282 | this.onKeydown.emit(e);
|
---|
| 283 | //backspace, delete, and escape get special treatment
|
---|
| 284 | if (k === 8 || k === 46 || (iPhone && k === 127)) {
|
---|
| 285 | pos = this.caret();
|
---|
| 286 | begin = pos.begin;
|
---|
| 287 | end = pos.end;
|
---|
| 288 | if (end - begin === 0) {
|
---|
| 289 | begin = k !== 46 ? this.seekPrev(begin) : (end = this.seekNext(begin - 1));
|
---|
| 290 | end = k === 46 ? this.seekNext(end) : end;
|
---|
| 291 | }
|
---|
| 292 | this.clearBuffer(begin, end);
|
---|
| 293 | this.shiftL(begin, end - 1);
|
---|
| 294 | this.updateModel(e);
|
---|
| 295 | this.onInput.emit(e);
|
---|
| 296 | e.preventDefault();
|
---|
| 297 | }
|
---|
| 298 | else if (k === 13) { // enter
|
---|
| 299 | this.onInputBlur(e);
|
---|
| 300 | this.updateModel(e);
|
---|
| 301 | }
|
---|
| 302 | else if (k === 27) { // escape
|
---|
| 303 | this.inputViewChild.nativeElement.value = this.focusText;
|
---|
| 304 | this.caret(0, this.checkVal());
|
---|
| 305 | this.updateModel(e);
|
---|
| 306 | e.preventDefault();
|
---|
| 307 | }
|
---|
| 308 | }
|
---|
| 309 | onKeyPress(e) {
|
---|
| 310 | if (this.readonly) {
|
---|
| 311 | return;
|
---|
| 312 | }
|
---|
| 313 | var k = e.which || e.keyCode, pos = this.caret(), p, c, next, completed;
|
---|
| 314 | if (e.ctrlKey || e.altKey || e.metaKey || k < 32 || (k > 34 && k < 41)) { //Ignore
|
---|
| 315 | return;
|
---|
| 316 | }
|
---|
| 317 | else if (k && k !== 13) {
|
---|
| 318 | if (pos.end - pos.begin !== 0) {
|
---|
| 319 | this.clearBuffer(pos.begin, pos.end);
|
---|
| 320 | this.shiftL(pos.begin, pos.end - 1);
|
---|
| 321 | }
|
---|
| 322 | p = this.seekNext(pos.begin - 1);
|
---|
| 323 | if (p < this.len) {
|
---|
| 324 | c = String.fromCharCode(k);
|
---|
| 325 | if (this.tests[p].test(c)) {
|
---|
| 326 | this.shiftR(p);
|
---|
| 327 | this.buffer[p] = c;
|
---|
| 328 | this.writeBuffer();
|
---|
| 329 | next = this.seekNext(p);
|
---|
| 330 | if (/android/i.test(DomHandler.getUserAgent())) {
|
---|
| 331 | //Path for CSP Violation on FireFox OS 1.1
|
---|
| 332 | let proxy = () => {
|
---|
| 333 | this.caret(next);
|
---|
| 334 | };
|
---|
| 335 | setTimeout(proxy, 0);
|
---|
| 336 | }
|
---|
| 337 | else {
|
---|
| 338 | this.caret(next);
|
---|
| 339 | }
|
---|
| 340 | if (pos.begin <= this.lastRequiredNonMaskPos) {
|
---|
| 341 | completed = this.isCompleted();
|
---|
| 342 | }
|
---|
| 343 | this.onInput.emit(e);
|
---|
| 344 | }
|
---|
| 345 | }
|
---|
| 346 | e.preventDefault();
|
---|
| 347 | }
|
---|
| 348 | this.updateModel(e);
|
---|
| 349 | this.updateFilledState();
|
---|
| 350 | if (completed) {
|
---|
| 351 | this.onComplete.emit();
|
---|
| 352 | }
|
---|
| 353 | }
|
---|
| 354 | clearBuffer(start, end) {
|
---|
| 355 | let i;
|
---|
| 356 | for (i = start; i < end && i < this.len; i++) {
|
---|
| 357 | if (this.tests[i]) {
|
---|
| 358 | this.buffer[i] = this.getPlaceholder(i);
|
---|
| 359 | }
|
---|
| 360 | }
|
---|
| 361 | }
|
---|
| 362 | writeBuffer() {
|
---|
| 363 | this.inputViewChild.nativeElement.value = this.buffer.join('');
|
---|
| 364 | }
|
---|
| 365 | checkVal(allow) {
|
---|
| 366 | //try to place characters where they belong
|
---|
| 367 | let test = this.inputViewChild.nativeElement.value, lastMatch = -1, i, c, pos;
|
---|
| 368 | for (i = 0, pos = 0; i < this.len; i++) {
|
---|
| 369 | if (this.tests[i]) {
|
---|
| 370 | this.buffer[i] = this.getPlaceholder(i);
|
---|
| 371 | while (pos++ < test.length) {
|
---|
| 372 | c = test.charAt(pos - 1);
|
---|
| 373 | if (this.tests[i].test(c)) {
|
---|
| 374 | this.buffer[i] = c;
|
---|
| 375 | lastMatch = i;
|
---|
| 376 | break;
|
---|
| 377 | }
|
---|
| 378 | }
|
---|
| 379 | if (pos > test.length) {
|
---|
| 380 | this.clearBuffer(i + 1, this.len);
|
---|
| 381 | break;
|
---|
| 382 | }
|
---|
| 383 | }
|
---|
| 384 | else {
|
---|
| 385 | if (this.buffer[i] === test.charAt(pos)) {
|
---|
| 386 | pos++;
|
---|
| 387 | }
|
---|
| 388 | if (i < this.partialPosition) {
|
---|
| 389 | lastMatch = i;
|
---|
| 390 | }
|
---|
| 391 | }
|
---|
| 392 | }
|
---|
| 393 | if (allow) {
|
---|
| 394 | this.writeBuffer();
|
---|
| 395 | }
|
---|
| 396 | else if (lastMatch + 1 < this.partialPosition) {
|
---|
| 397 | if (this.autoClear || this.buffer.join('') === this.defaultBuffer) {
|
---|
| 398 | // Invalid value. Remove it and replace it with the
|
---|
| 399 | // mask, which is the default behavior.
|
---|
| 400 | if (this.inputViewChild.nativeElement.value)
|
---|
| 401 | this.inputViewChild.nativeElement.value = '';
|
---|
| 402 | this.clearBuffer(0, this.len);
|
---|
| 403 | }
|
---|
| 404 | else {
|
---|
| 405 | // Invalid value, but we opt to show the value to the
|
---|
| 406 | // user and allow them to correct their mistake.
|
---|
| 407 | this.writeBuffer();
|
---|
| 408 | }
|
---|
| 409 | }
|
---|
| 410 | else {
|
---|
| 411 | this.writeBuffer();
|
---|
| 412 | this.inputViewChild.nativeElement.value = this.inputViewChild.nativeElement.value.substring(0, lastMatch + 1);
|
---|
| 413 | }
|
---|
| 414 | return (this.partialPosition ? i : this.firstNonMaskPos);
|
---|
| 415 | }
|
---|
| 416 | onInputFocus(event) {
|
---|
| 417 | if (this.readonly) {
|
---|
| 418 | return;
|
---|
| 419 | }
|
---|
| 420 | this.focused = true;
|
---|
| 421 | clearTimeout(this.caretTimeoutId);
|
---|
| 422 | let pos;
|
---|
| 423 | this.focusText = this.inputViewChild.nativeElement.value;
|
---|
| 424 | pos = this.checkVal();
|
---|
| 425 | this.caretTimeoutId = setTimeout(() => {
|
---|
| 426 | if (this.inputViewChild.nativeElement !== this.inputViewChild.nativeElement.ownerDocument.activeElement) {
|
---|
| 427 | return;
|
---|
| 428 | }
|
---|
| 429 | this.writeBuffer();
|
---|
| 430 | if (pos == this.mask.replace("?", "").length) {
|
---|
| 431 | this.caret(0, pos);
|
---|
| 432 | }
|
---|
| 433 | else {
|
---|
| 434 | this.caret(pos);
|
---|
| 435 | }
|
---|
| 436 | }, 10);
|
---|
| 437 | this.onFocus.emit(event);
|
---|
| 438 | }
|
---|
| 439 | onInputChange(event) {
|
---|
| 440 | if (this.androidChrome)
|
---|
| 441 | this.handleAndroidInput(event);
|
---|
| 442 | else
|
---|
| 443 | this.handleInputChange(event);
|
---|
| 444 | this.onInput.emit(event);
|
---|
| 445 | }
|
---|
| 446 | handleInputChange(event) {
|
---|
| 447 | if (this.readonly) {
|
---|
| 448 | return;
|
---|
| 449 | }
|
---|
| 450 | setTimeout(() => {
|
---|
| 451 | var pos = this.checkVal(true);
|
---|
| 452 | this.caret(pos);
|
---|
| 453 | this.updateModel(event);
|
---|
| 454 | if (this.isCompleted()) {
|
---|
| 455 | this.onComplete.emit();
|
---|
| 456 | }
|
---|
| 457 | }, 0);
|
---|
| 458 | }
|
---|
| 459 | getUnmaskedValue() {
|
---|
| 460 | let unmaskedBuffer = [];
|
---|
| 461 | for (let i = 0; i < this.buffer.length; i++) {
|
---|
| 462 | let c = this.buffer[i];
|
---|
| 463 | if (this.tests[i] && c != this.getPlaceholder(i)) {
|
---|
| 464 | unmaskedBuffer.push(c);
|
---|
| 465 | }
|
---|
| 466 | }
|
---|
| 467 | return unmaskedBuffer.join('');
|
---|
| 468 | }
|
---|
| 469 | updateModel(e) {
|
---|
| 470 | const updatedValue = this.unmask ? this.getUnmaskedValue() : e.target.value;
|
---|
| 471 | if (updatedValue !== null || updatedValue !== undefined) {
|
---|
| 472 | this.value = updatedValue;
|
---|
| 473 | this.onModelChange(this.value);
|
---|
| 474 | }
|
---|
| 475 | }
|
---|
| 476 | updateFilledState() {
|
---|
| 477 | this.filled = this.inputViewChild.nativeElement && this.inputViewChild.nativeElement.value != '';
|
---|
| 478 | }
|
---|
| 479 | focus() {
|
---|
| 480 | this.inputViewChild.nativeElement.focus();
|
---|
| 481 | }
|
---|
| 482 | ngOnDestroy() {
|
---|
| 483 | }
|
---|
| 484 | }
|
---|
| 485 | InputMask.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputMask, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
|
---|
| 486 | InputMask.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.0", type: InputMask, selector: "p-inputMask", inputs: { type: "type", slotChar: "slotChar", autoClear: "autoClear", style: "style", inputId: "inputId", styleClass: "styleClass", placeholder: "placeholder", size: "size", maxlength: "maxlength", tabindex: "tabindex", title: "title", ariaLabel: "ariaLabel", ariaRequired: "ariaRequired", disabled: "disabled", readonly: "readonly", unmask: "unmask", name: "name", required: "required", characterPattern: "characterPattern", autoFocus: "autoFocus", autocomplete: "autocomplete", mask: "mask" }, outputs: { onComplete: "onComplete", onFocus: "onFocus", onBlur: "onBlur", onInput: "onInput", onKeydown: "onKeydown" }, host: { properties: { "class.p-inputwrapper-filled": "filled", "class.p-inputwrapper-focus": "focused" }, classAttribute: "p-element" }, providers: [INPUTMASK_VALUE_ACCESSOR], viewQueries: [{ propertyName: "inputViewChild", first: true, predicate: ["input"], descendants: true, static: true }], ngImport: i0, template: `<input #input pInputText class="p-inputmask" [attr.id]="inputId" [attr.type]="type" [attr.name]="name" [ngStyle]="style" [ngClass]="styleClass" [attr.placeholder]="placeholder" [attr.title]="title"
|
---|
| 487 | [attr.size]="size" [attr.autocomplete]="autocomplete" [attr.maxlength]="maxlength" [attr.tabindex]="tabindex" [attr.aria-label]="ariaLabel" [attr.aria-required]="ariaRequired" [disabled]="disabled" [readonly]="readonly" [attr.required]="required"
|
---|
| 488 | (focus)="onInputFocus($event)" (blur)="onInputBlur($event)" (keydown)="onInputKeydown($event)" (keypress)="onKeyPress($event)" [attr.autofocus]="autoFocus"
|
---|
| 489 | (input)="onInputChange($event)" (paste)="handleInputChange($event)">`, isInline: true, directives: [{ type: i1.InputText, selector: "[pInputText]" }, { type: i2.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
---|
| 490 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputMask, decorators: [{
|
---|
| 491 | type: Component,
|
---|
| 492 | args: [{
|
---|
| 493 | selector: 'p-inputMask',
|
---|
| 494 | template: `<input #input pInputText class="p-inputmask" [attr.id]="inputId" [attr.type]="type" [attr.name]="name" [ngStyle]="style" [ngClass]="styleClass" [attr.placeholder]="placeholder" [attr.title]="title"
|
---|
| 495 | [attr.size]="size" [attr.autocomplete]="autocomplete" [attr.maxlength]="maxlength" [attr.tabindex]="tabindex" [attr.aria-label]="ariaLabel" [attr.aria-required]="ariaRequired" [disabled]="disabled" [readonly]="readonly" [attr.required]="required"
|
---|
| 496 | (focus)="onInputFocus($event)" (blur)="onInputBlur($event)" (keydown)="onInputKeydown($event)" (keypress)="onKeyPress($event)" [attr.autofocus]="autoFocus"
|
---|
| 497 | (input)="onInputChange($event)" (paste)="handleInputChange($event)">`,
|
---|
| 498 | host: {
|
---|
| 499 | 'class': 'p-element',
|
---|
| 500 | '[class.p-inputwrapper-filled]': 'filled',
|
---|
| 501 | '[class.p-inputwrapper-focus]': 'focused'
|
---|
| 502 | },
|
---|
| 503 | providers: [INPUTMASK_VALUE_ACCESSOR],
|
---|
| 504 | changeDetection: ChangeDetectionStrategy.OnPush,
|
---|
| 505 | encapsulation: ViewEncapsulation.None
|
---|
| 506 | }]
|
---|
| 507 | }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { type: [{
|
---|
| 508 | type: Input
|
---|
| 509 | }], slotChar: [{
|
---|
| 510 | type: Input
|
---|
| 511 | }], autoClear: [{
|
---|
| 512 | type: Input
|
---|
| 513 | }], style: [{
|
---|
| 514 | type: Input
|
---|
| 515 | }], inputId: [{
|
---|
| 516 | type: Input
|
---|
| 517 | }], styleClass: [{
|
---|
| 518 | type: Input
|
---|
| 519 | }], placeholder: [{
|
---|
| 520 | type: Input
|
---|
| 521 | }], size: [{
|
---|
| 522 | type: Input
|
---|
| 523 | }], maxlength: [{
|
---|
| 524 | type: Input
|
---|
| 525 | }], tabindex: [{
|
---|
| 526 | type: Input
|
---|
| 527 | }], title: [{
|
---|
| 528 | type: Input
|
---|
| 529 | }], ariaLabel: [{
|
---|
| 530 | type: Input
|
---|
| 531 | }], ariaRequired: [{
|
---|
| 532 | type: Input
|
---|
| 533 | }], disabled: [{
|
---|
| 534 | type: Input
|
---|
| 535 | }], readonly: [{
|
---|
| 536 | type: Input
|
---|
| 537 | }], unmask: [{
|
---|
| 538 | type: Input
|
---|
| 539 | }], name: [{
|
---|
| 540 | type: Input
|
---|
| 541 | }], required: [{
|
---|
| 542 | type: Input
|
---|
| 543 | }], characterPattern: [{
|
---|
| 544 | type: Input
|
---|
| 545 | }], autoFocus: [{
|
---|
| 546 | type: Input
|
---|
| 547 | }], autocomplete: [{
|
---|
| 548 | type: Input
|
---|
| 549 | }], inputViewChild: [{
|
---|
| 550 | type: ViewChild,
|
---|
| 551 | args: ['input', { static: true }]
|
---|
| 552 | }], onComplete: [{
|
---|
| 553 | type: Output
|
---|
| 554 | }], onFocus: [{
|
---|
| 555 | type: Output
|
---|
| 556 | }], onBlur: [{
|
---|
| 557 | type: Output
|
---|
| 558 | }], onInput: [{
|
---|
| 559 | type: Output
|
---|
| 560 | }], onKeydown: [{
|
---|
| 561 | type: Output
|
---|
| 562 | }], mask: [{
|
---|
| 563 | type: Input
|
---|
| 564 | }] } });
|
---|
| 565 | class InputMaskModule {
|
---|
| 566 | }
|
---|
| 567 | InputMaskModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputMaskModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
---|
| 568 | InputMaskModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputMaskModule, declarations: [InputMask], imports: [CommonModule, InputTextModule], exports: [InputMask] });
|
---|
| 569 | InputMaskModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputMaskModule, imports: [[CommonModule, InputTextModule]] });
|
---|
| 570 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputMaskModule, decorators: [{
|
---|
| 571 | type: NgModule,
|
---|
| 572 | args: [{
|
---|
| 573 | imports: [CommonModule, InputTextModule],
|
---|
| 574 | exports: [InputMask],
|
---|
| 575 | declarations: [InputMask]
|
---|
| 576 | }]
|
---|
| 577 | }] });
|
---|
| 578 |
|
---|
| 579 | /**
|
---|
| 580 | * Generated bundle index. Do not edit.
|
---|
| 581 | */
|
---|
| 582 |
|
---|
| 583 | export { INPUTMASK_VALUE_ACCESSOR, InputMask, InputMaskModule };
|
---|