monkey-style-guide-v2 0.0.66 → 0.0.68
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.
|
@@ -16,8 +16,9 @@ import { HttpClient } from '@angular/common/http';
|
|
|
16
16
|
import { format, parseISO, addYears, subYears, subMonths, addMonths, getMonth, getYear, startOfWeek, startOfMonth, endOfWeek, endOfMonth, isSameMonth, isBefore, isAfter, isToday, addDays, isWithinInterval, subDays } from 'date-fns';
|
|
17
17
|
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
|
18
18
|
import { getSupportedInputTypes } from '@angular/cdk/platform';
|
|
19
|
-
import parsePhoneNumberFromString, { getCountries, getCountryCallingCode, getExampleNumber, AsYouType
|
|
19
|
+
import parsePhoneNumberFromString, { getCountries, getCountryCallingCode, getExampleNumber, AsYouType } from 'libphonenumber-js';
|
|
20
20
|
import examples from 'libphonenumber-js/examples.mobile.json';
|
|
21
|
+
import { isValidPhoneNumber } from 'libphonenumber-js/max';
|
|
21
22
|
import { hasModifierKey } from '@angular/cdk/keycodes';
|
|
22
23
|
|
|
23
24
|
const counters = {};
|
|
@@ -2660,6 +2661,9 @@ class MonkeyAutocompleteAddressComponent {
|
|
|
2660
2661
|
set value(value) {
|
|
2661
2662
|
if (this._value !== value && value !== undefined) {
|
|
2662
2663
|
this._value = value;
|
|
2664
|
+
if (!this.searchData) {
|
|
2665
|
+
this.searchData = value;
|
|
2666
|
+
}
|
|
2663
2667
|
this._onChange(value);
|
|
2664
2668
|
this._onTouched(value);
|
|
2665
2669
|
}
|
|
@@ -5649,7 +5653,7 @@ class MonkeyInputPhoneComponent {
|
|
|
5649
5653
|
getCountryByCallingCode(code) {
|
|
5650
5654
|
const cleanCode = code.replace('+', '');
|
|
5651
5655
|
return (getCountries().find((country) => {
|
|
5652
|
-
return
|
|
5656
|
+
return country === cleanCode;
|
|
5653
5657
|
}) || null);
|
|
5654
5658
|
}
|
|
5655
5659
|
isoToFlagEmoji(isoCode) {
|
|
@@ -5671,18 +5675,21 @@ class MonkeyInputPhoneComponent {
|
|
|
5671
5675
|
return this.selectedCallingCode;
|
|
5672
5676
|
}
|
|
5673
5677
|
performValue(value) {
|
|
5674
|
-
|
|
5678
|
+
const countryCode = `+${getCountryCallingCode(this.selectedCallingCode)}`;
|
|
5679
|
+
this._value = `${countryCode}${value}`;
|
|
5675
5680
|
this._onChange(this._value);
|
|
5676
5681
|
this._onTouched(this._value);
|
|
5677
5682
|
}
|
|
5678
5683
|
validateValue() {
|
|
5679
5684
|
const { phoneValid } = this;
|
|
5680
5685
|
if (!phoneValid) {
|
|
5681
|
-
const countryCode = this.
|
|
5686
|
+
const countryCode = this.selectedCallingCode;
|
|
5682
5687
|
const example = getExampleNumber(countryCode, examples);
|
|
5688
|
+
const formatter = new AsYouType(countryCode);
|
|
5689
|
+
const phoneAllowed = formatter.input(example.nationalNumber);
|
|
5683
5690
|
this.ngControl?.control?.setErrors({
|
|
5684
5691
|
phone: true,
|
|
5685
|
-
phoneAllowed
|
|
5692
|
+
phoneAllowed
|
|
5686
5693
|
});
|
|
5687
5694
|
}
|
|
5688
5695
|
}
|
|
@@ -5698,18 +5705,19 @@ class MonkeyInputPhoneComponent {
|
|
|
5698
5705
|
if (isCountryChanged && detectedCallingCode) {
|
|
5699
5706
|
this.selectedCallingCode = detectedCallingCode;
|
|
5700
5707
|
}
|
|
5701
|
-
const countryCode =
|
|
5708
|
+
const countryCode = `+${getCountryCallingCode(this.selectedCallingCode)}`;
|
|
5702
5709
|
if (!countryCode) {
|
|
5703
5710
|
this.phoneFormatted = value;
|
|
5704
5711
|
this.phoneValid = false;
|
|
5705
5712
|
this.validateValue();
|
|
5706
5713
|
return;
|
|
5707
5714
|
}
|
|
5708
|
-
|
|
5709
|
-
|
|
5715
|
+
let nationalPart = value.replace(this.selectedCallingCode, '').replace(/[^\d+]/g, '');
|
|
5716
|
+
nationalPart = nationalPart.replace(countryCode, '');
|
|
5717
|
+
const formatter = new AsYouType(this.selectedCallingCode);
|
|
5710
5718
|
this.phoneFormatted = formatter.input(nationalPart);
|
|
5711
5719
|
this.performValue(nationalPart);
|
|
5712
|
-
this.phoneValid = isValidPhoneNumber(nationalPart,
|
|
5720
|
+
this.phoneValid = isValidPhoneNumber(nationalPart, this.selectedCallingCode);
|
|
5713
5721
|
this.validateValue();
|
|
5714
5722
|
}
|
|
5715
5723
|
ngAfterContentInit() { }
|