@seniorsistemas/angular-components 16.10.5 → 16.10.6

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.
@@ -1,5 +1,5 @@
1
1
  import { __decorate, __rest, __awaiter, __param } from 'tslib';
2
- import { EventEmitter, Input, Output, HostListener, Component, NgModule, HostBinding, ViewChild, Renderer2, Directive, Injectable, ElementRef, Pipe, forwardRef, ViewEncapsulation, ɵɵdefineInjectable, InjectionToken, Inject, ApplicationRef, ComponentFactoryResolver, Injector, TemplateRef, ViewContainerRef, ChangeDetectorRef, Optional, ContentChild, ContentChildren } from '@angular/core';
2
+ import { EventEmitter, Input, Output, HostListener, Component, NgModule, HostBinding, ViewChild, Renderer2, Directive, Injectable, ElementRef, forwardRef, Pipe, ViewEncapsulation, ɵɵdefineInjectable, InjectionToken, Inject, ApplicationRef, ComponentFactoryResolver, Injector, TemplateRef, ViewContainerRef, ChangeDetectorRef, Optional, ContentChild, ContentChildren } from '@angular/core';
3
3
  import { CommonModule } from '@angular/common';
4
4
  import { RouterModule, NavigationEnd, PRIMARY_OUTLET, ActivatedRoute, Router } from '@angular/router';
5
5
  import { BreadcrumbModule as BreadcrumbModule$1 } from 'primeng/breadcrumb';
@@ -1334,18 +1334,34 @@ let CountryPhonePickerComponent = CountryPhonePickerComponent_1 = class CountryP
1334
1334
  this.tabindex = 0;
1335
1335
  this._filterCountries = (value) => {
1336
1336
  if (!value) {
1337
- this.filteredCountriesList = this.countriesList;
1337
+ this.filteredCountriesList = this._countriesList;
1338
1338
  }
1339
1339
  else {
1340
- this.filteredCountriesList = this.countriesList.filter((country) => {
1340
+ this.filteredCountriesList = this._countriesList.filter((country) => {
1341
1341
  const countryName = this.translate.instant(`platform.angular_components.country_name_${country.id}`);
1342
1342
  return countryName.toLowerCase().includes(value.toLowerCase());
1343
1343
  });
1344
1344
  }
1345
1345
  };
1346
1346
  }
1347
+ get value() {
1348
+ return this._value;
1349
+ }
1350
+ set value(value) {
1351
+ this._value = value;
1352
+ this.mask = this.getMask();
1353
+ }
1347
1354
  writeValue(value) {
1348
1355
  this.value = value;
1356
+ if (value === null || value === void 0 ? void 0 : value.id) {
1357
+ const country = this._countriesList.filter(({ id }) => id == value.id);
1358
+ if (country.length) {
1359
+ this.onSelectItem(country[0]);
1360
+ }
1361
+ }
1362
+ if (value === null || value === void 0 ? void 0 : value.rawValue) {
1363
+ this.phone.setValue(value.rawValue);
1364
+ }
1349
1365
  }
1350
1366
  registerOnChange(onChange) {
1351
1367
  this._onChange = onChange;
@@ -1365,28 +1381,30 @@ let CountryPhonePickerComponent = CountryPhonePickerComponent_1 = class CountryP
1365
1381
  const countries = this.countryPhonePickerService.getCountries(this.ordination);
1366
1382
  this.filter.valueChanges.subscribe(this._filterCountries);
1367
1383
  if ((_a = this.countries) === null || _a === void 0 ? void 0 : _a.length) {
1368
- this.countriesList = countries.filter((country) => this.countries.includes(country.id));
1384
+ this._countriesList = countries.filter((country) => this.countries.includes(country.id));
1369
1385
  }
1370
1386
  else {
1371
- this.countriesList = countries;
1387
+ this._countriesList = countries;
1372
1388
  }
1373
- this.filteredCountriesList = this.countriesList;
1389
+ this.filteredCountriesList = this._countriesList;
1374
1390
  this.selectedItem = this._getSelectedCountryDefault();
1391
+ this.mask = this.getMask();
1375
1392
  this.phone.valueChanges.subscribe((value) => {
1376
- var _a;
1377
1393
  this.value = {
1378
1394
  id: this.selectedItem.id,
1379
1395
  ddi: this.selectedItem.ddi,
1380
1396
  rawValue: value !== null && value !== void 0 ? value : "",
1381
1397
  value: value ? `${this._applyMask(value)}` : "",
1382
1398
  };
1383
- (_a = this._onChange) === null || _a === void 0 ? void 0 : _a.call(this.value);
1399
+ if (this._onChange) {
1400
+ this._onChange(this.value);
1401
+ }
1384
1402
  });
1385
1403
  }
1386
1404
  onKeydown(event) {
1387
1405
  if (event.key === "Enter" || event.key === " ") {
1388
1406
  if (this.open) {
1389
- this.selectedItem = this.countriesList[this.currentItemIndex];
1407
+ this.selectedItem = this._countriesList[this.currentItemIndex];
1390
1408
  this.selected.emit(this.selectedItem);
1391
1409
  }
1392
1410
  this.open = !this.open;
@@ -1412,13 +1430,13 @@ let CountryPhonePickerComponent = CountryPhonePickerComponent_1 = class CountryP
1412
1430
  }
1413
1431
  onBlur() {
1414
1432
  this.open = false;
1415
- this.currentItemIndex = this.countriesList.indexOf(this.selectedItem);
1433
+ this.currentItemIndex = this._countriesList.indexOf(this.selectedItem);
1416
1434
  }
1417
1435
  onSelectItem(country) {
1418
1436
  this.open = false;
1419
1437
  this.selectedItem = country;
1420
1438
  this.phone.setValue("");
1421
- this.currentItemIndex = this.countriesList.indexOf(this.selectedItem);
1439
+ this.currentItemIndex = this._countriesList.indexOf(this.selectedItem);
1422
1440
  this.selected.emit(this.selectedItem);
1423
1441
  }
1424
1442
  onCleanFilter() {
@@ -1428,9 +1446,10 @@ let CountryPhonePickerComponent = CountryPhonePickerComponent_1 = class CountryP
1428
1446
  this.open = false;
1429
1447
  }
1430
1448
  getMask() {
1449
+ var _a;
1431
1450
  const mask = this.selectedItem.mask;
1432
1451
  if (Array.isArray(mask)) {
1433
- return !this.value || this.value.value.length <= mask[0].length - 1
1452
+ return !((_a = this.value) === null || _a === void 0 ? void 0 : _a.rawValue) || this.value.rawValue.length <= mask[0].replace(/[^0]/g, "").length
1434
1453
  ? mask[0] // fixo
1435
1454
  : mask[1]; // celular
1436
1455
  }
@@ -1439,14 +1458,14 @@ let CountryPhonePickerComponent = CountryPhonePickerComponent_1 = class CountryP
1439
1458
  }
1440
1459
  }
1441
1460
  getPlaceholder() {
1442
- return this.getMask().replace(/9/g, "");
1461
+ return this.mask.replace(/9/g, "");
1443
1462
  }
1444
1463
  _getSelectedCountryDefault() {
1445
- if (!this.countriesList.length) {
1464
+ if (!this._countriesList.length) {
1446
1465
  throw new Error("No country loaded");
1447
1466
  }
1448
- const filteredByBr = this.countriesList.filter((country) => country.id === "br");
1449
- return filteredByBr.length ? filteredByBr[0] : this.countriesList[0];
1467
+ const filteredByBr = this._countriesList.filter((country) => country.id === "br");
1468
+ return filteredByBr.length ? filteredByBr[0] : this._countriesList[0];
1450
1469
  }
1451
1470
  _moveToUp() {
1452
1471
  if (this.currentItemIndex == 0) {
@@ -1461,7 +1480,7 @@ let CountryPhonePickerComponent = CountryPhonePickerComponent_1 = class CountryP
1461
1480
  }
1462
1481
  }
1463
1482
  _moveToDown() {
1464
- if (this.currentItemIndex >= this.countriesList.length - 1) {
1483
+ if (this.currentItemIndex >= this._countriesList.length - 1) {
1465
1484
  return;
1466
1485
  }
1467
1486
  this.currentItemIndex++;
@@ -1481,7 +1500,7 @@ let CountryPhonePickerComponent = CountryPhonePickerComponent_1 = class CountryP
1481
1500
  : this.selectedItem.mask[1] + "\0";
1482
1501
  }
1483
1502
  else {
1484
- mask = this.selectedItem.mask;
1503
+ mask = this.selectedItem.mask + "\0";
1485
1504
  }
1486
1505
  let tokens = "";
1487
1506
  let replace = "";
@@ -1535,10 +1554,10 @@ __decorate([
1535
1554
  CountryPhonePickerComponent = CountryPhonePickerComponent_1 = __decorate([
1536
1555
  Component({
1537
1556
  selector: "s-country-phone-picker",
1538
- template: "<div class=\"country-phone-picker\">\n <div class=\"phone-input\">\n <div class=\"drop\" (click)=\"open = !open\">\n <span class=\"drop-flag\" [ngClass]=\"'fi fi-' + selectedItem.id\">\n </span>\n <span class=\"drop-icon fas fa-caret-down\"></span>\n </div>\n <p class=\"phone-ddi\">{{ selectedItem.ddi }}</p>\n <input\n #phoneInput\n type=\"tel\"\n autofocus\n [mask]=\"getMask()\" \n [placeholder]=\"getPlaceholder()\"\n [formControl]=\"phone\"\n (focus)=\"onPhoneInputFocus()\" />\n </div>\n <div *ngIf=\"open\" class=\"dropdown\">\n <div class=\"search\">\n <input\n class=\"search-field\"\n type=\"text\"\n [formControl]=\"filter\">\n <span class=\"search-icon fas fa-search\"></span>\n <span\n class=\"search-clear fa fa-times\"\n (click)=\"onCleanFilter()\"></span>\n </div>\n <ul class=\"select-list\">\n <li\n *ngFor=\"let country of filteredCountriesList; let i = index;\"\n class=\"select-option\"\n [ngClass]=\"{ 'select-option--focused': i == currentItemIndex }\"\n (click)=\"onSelectItem(country)\">\n <span\n class=\"select-option__flag\"\n [ngClass]=\"'fi fi-' + country.id\">\n </span>\n <span class=\"select-option__name\">\n {{ \"platform.angular_components.country_name_\" + country.id | translate }}\n </span>\n <span class=\"select-option__ddi\">\n {{ country.ddi }}\n </span>\n </li>\n </ul>\n </div>\n</div>",
1557
+ template: "<div class=\"country-phone-picker\">\n <div class=\"phone-input\">\n <div class=\"drop\" (click)=\"open = !open\">\n <span class=\"drop-flag\" [ngClass]=\"'fi fi-' + selectedItem.id\">\n </span>\n <span class=\"drop-icon fas fa-caret-down\"></span>\n </div>\n <p class=\"phone-ddi\">{{ selectedItem.ddi }}</p>\n <input\n #phoneInput\n type=\"tel\"\n autofocus\n [mask]=\"mask\" \n [placeholder]=\"getPlaceholder()\"\n [formControl]=\"phone\"\n (focus)=\"onPhoneInputFocus()\" />\n </div>\n <div *ngIf=\"open\" class=\"dropdown\">\n <div class=\"search\">\n <input\n class=\"search-field\"\n type=\"text\"\n [formControl]=\"filter\">\n <span class=\"search-icon fas fa-search\"></span>\n <span\n class=\"search-clear fa fa-times\"\n (click)=\"onCleanFilter()\"></span>\n </div>\n <ul class=\"select-list\">\n <li\n *ngFor=\"let country of filteredCountriesList; let i = index;\"\n class=\"select-option\"\n [ngClass]=\"{ 'select-option--focused': i == currentItemIndex }\"\n (click)=\"onSelectItem(country)\">\n <span\n class=\"select-option__flag\"\n [ngClass]=\"'fi fi-' + country.id\">\n </span>\n <span class=\"select-option__name\">\n {{ \"platform.angular_components.country_name_\" + country.id | translate }}\n </span>\n <span class=\"select-option__ddi\">\n {{ country.ddi }}\n </span>\n </li>\n </ul>\n </div>\n</div>",
1539
1558
  providers: [{
1540
1559
  provide: NG_VALUE_ACCESSOR,
1541
- useExisting: CountryPhonePickerComponent_1,
1560
+ useExisting: forwardRef(() => CountryPhonePickerComponent_1),
1542
1561
  multi: true,
1543
1562
  }],
1544
1563
  styles: [".country-phone-picker .phone-input{background-color:#fff;border:1px solid #d8d8d8;border-radius:4px;display:-ms-flexbox;display:flex;line-height:normal}.country-phone-picker .phone-input .drop{-ms-flex-align:center;align-items:center;cursor:pointer;display:-ms-flexbox;display:flex}.country-phone-picker .phone-input .drop .drop-flag{margin-left:12px}.country-phone-picker .phone-input .drop .drop-icon{font-size:12px;margin:0 8px}.country-phone-picker .phone-input .phone-ddi{margin:8px 0}.country-phone-picker .phone-input input{border:none;-ms-flex-positive:1;flex-grow:1;font-family:\"Open Sans\",sans-serif;font-size:14px;font-weight:400;line-height:150%;margin-left:8px}.country-phone-picker .phone-input input:focus{color:#697882;outline:0}.country-phone-picker .dropdown{background-color:#fff;border-radius:4px;box-shadow:0 4px 5px #00000033;padding:4px 0;position:absolute;margin:2px 0;z-index:999999}.country-phone-picker .dropdown .search{-ms-flex-align:center;align-items:center;display:-ms-flexbox;display:flex;padding:8px 12px}.country-phone-picker .dropdown .search .search-field{border:1px solid #d8d8d8;border-radius:4px;-ms-flex-positive:1;flex-grow:1;font-family:\"Open Sans\",sans-serif;font-size:14px;font-weight:400;height:36px;line-height:150%;padding:0 32px 0 8px}.country-phone-picker .dropdown .search .search-icon{color:#333;font-size:12px;position:relative;right:24px}.country-phone-picker .dropdown .search .search-clear{color:#333;cursor:pointer;font-size:1rem}.country-phone-picker .dropdown .select-list{list-style:none;max-height:234px;min-width:360px;max-width:100vw;overflow:scroll;padding:0}.country-phone-picker .dropdown .select-list .select-option{cursor:pointer;display:-ms-flexbox;display:flex;padding:12px;-webkit-user-select:none;-ms-user-select:none;user-select:none}.country-phone-picker .dropdown .select-list .select-option .select-option__flag{margin-right:12px}.country-phone-picker .dropdown .select-list .select-option .select-option__name{margin-right:.5rem;max-width:100%;overflow:hidden;text-overflow:ellipsis}.country-phone-picker .dropdown .select-list .select-option .select-option__ddi{color:#697882;font-size:14px;font-family:\"Open Sans\",sans-serif;font-weight:400;line-height:150%}.country-phone-picker .dropdown .select-list .select-option--focused,.country-phone-picker .dropdown .select-list .select-option:hover{background-color:#e5eaea}"]