@skyux/phone-field 5.7.2 → 6.0.0-beta.2

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.
Files changed (53) hide show
  1. package/esm2020/index.mjs +8 -0
  2. package/esm2020/lib/modules/phone-field/phone-field-adapter.service.mjs +64 -0
  3. package/esm2020/lib/modules/phone-field/phone-field-input.directive.mjs +280 -0
  4. package/esm2020/lib/modules/phone-field/phone-field.component.mjs +332 -0
  5. package/esm2020/lib/modules/phone-field/phone-field.module.mjs +50 -0
  6. package/esm2020/lib/modules/phone-field/types/country.mjs +2 -0
  7. package/esm2020/lib/modules/phone-field/types/number-return-format.mjs +2 -0
  8. package/esm2020/lib/modules/shared/sky-phone-field-resources.module.mjs +60 -0
  9. package/esm2020/skyux-phone-field.mjs +5 -0
  10. package/esm2020/testing/phonefield/phone-field-fixture.mjs +160 -0
  11. package/esm2020/testing/phonefield/phone-field-testing.module.mjs +27 -0
  12. package/esm2020/testing/public-api.mjs +3 -0
  13. package/esm2020/testing/skyux-phone-field-testing.mjs +5 -0
  14. package/fesm2015/{skyux-phone-field-testing.js → skyux-phone-field-testing.mjs} +5 -5
  15. package/fesm2015/skyux-phone-field-testing.mjs.map +1 -0
  16. package/fesm2015/skyux-phone-field.mjs +771 -0
  17. package/fesm2015/skyux-phone-field.mjs.map +1 -0
  18. package/fesm2020/skyux-phone-field-testing.mjs +194 -0
  19. package/fesm2020/skyux-phone-field-testing.mjs.map +1 -0
  20. package/{fesm2015/skyux-phone-field.js → fesm2020/skyux-phone-field.mjs} +22 -30
  21. package/fesm2020/skyux-phone-field.mjs.map +1 -0
  22. package/package.json +42 -18
  23. package/testing/package.json +5 -5
  24. package/bundles/skyux-phone-field-testing.umd.js +0 -658
  25. package/bundles/skyux-phone-field.umd.js +0 -1162
  26. package/esm2015/index.js +0 -8
  27. package/esm2015/index.js.map +0 -1
  28. package/esm2015/lib/modules/phone-field/phone-field-adapter.service.js +0 -64
  29. package/esm2015/lib/modules/phone-field/phone-field-adapter.service.js.map +0 -1
  30. package/esm2015/lib/modules/phone-field/phone-field-input.directive.js +0 -280
  31. package/esm2015/lib/modules/phone-field/phone-field-input.directive.js.map +0 -1
  32. package/esm2015/lib/modules/phone-field/phone-field.component.js +0 -340
  33. package/esm2015/lib/modules/phone-field/phone-field.component.js.map +0 -1
  34. package/esm2015/lib/modules/phone-field/phone-field.module.js +0 -50
  35. package/esm2015/lib/modules/phone-field/phone-field.module.js.map +0 -1
  36. package/esm2015/lib/modules/phone-field/types/country.js +0 -2
  37. package/esm2015/lib/modules/phone-field/types/country.js.map +0 -1
  38. package/esm2015/lib/modules/phone-field/types/number-return-format.js +0 -2
  39. package/esm2015/lib/modules/phone-field/types/number-return-format.js.map +0 -1
  40. package/esm2015/lib/modules/shared/sky-phone-field-resources.module.js +0 -60
  41. package/esm2015/lib/modules/shared/sky-phone-field-resources.module.js.map +0 -1
  42. package/esm2015/skyux-phone-field.js +0 -5
  43. package/esm2015/skyux-phone-field.js.map +0 -1
  44. package/esm2015/testing/phonefield/phone-field-fixture.js +0 -185
  45. package/esm2015/testing/phonefield/phone-field-fixture.js.map +0 -1
  46. package/esm2015/testing/phonefield/phone-field-testing.module.js +0 -27
  47. package/esm2015/testing/phonefield/phone-field-testing.module.js.map +0 -1
  48. package/esm2015/testing/public-api.js +0 -3
  49. package/esm2015/testing/public-api.js.map +0 -1
  50. package/esm2015/testing/skyux-phone-field-testing.js +0 -5
  51. package/esm2015/testing/skyux-phone-field-testing.js.map +0 -1
  52. package/fesm2015/skyux-phone-field-testing.js.map +0 -1
  53. package/fesm2015/skyux-phone-field.js.map +0 -1
package/esm2015/index.js DELETED
@@ -1,8 +0,0 @@
1
- export * from './lib/modules/phone-field/phone-field.module';
2
- export * from './lib/modules/phone-field/types/country';
3
- export * from './lib/modules/phone-field/types/number-return-format';
4
- // Components and directives must be exported to support Angular's "partial" Ivy compiler.
5
- // Obscure names are used to indicate types are not part of the public API.
6
- export { SkyPhoneFieldComponent as λ1 } from './lib/modules/phone-field/phone-field.component';
7
- export { SkyPhoneFieldInputDirective as λ2 } from './lib/modules/phone-field/phone-field-input.directive';
8
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/components/phone-field/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8CAA8C,CAAC;AAC7D,cAAc,yCAAyC,CAAC;AACxD,cAAc,sDAAsD,CAAC;AAErE,0FAA0F;AAC1F,2EAA2E;AAC3E,OAAO,EAAE,sBAAsB,IAAI,EAAE,EAAE,MAAM,iDAAiD,CAAC;AAC/F,OAAO,EAAE,2BAA2B,IAAI,EAAE,EAAE,MAAM,uDAAuD,CAAC","sourcesContent":["export * from './lib/modules/phone-field/phone-field.module';\nexport * from './lib/modules/phone-field/types/country';\nexport * from './lib/modules/phone-field/types/number-return-format';\n\n// Components and directives must be exported to support Angular's \"partial\" Ivy compiler.\n// Obscure names are used to indicate types are not part of the public API.\nexport { SkyPhoneFieldComponent as λ1 } from './lib/modules/phone-field/phone-field.component';\nexport { SkyPhoneFieldInputDirective as λ2 } from './lib/modules/phone-field/phone-field-input.directive';\n"]}
@@ -1,64 +0,0 @@
1
- import { Injectable, Renderer2 } from '@angular/core';
2
- import { SkyLibResourcesService } from '@skyux/i18n';
3
- import { Subject } from 'rxjs';
4
- import { takeUntil } from 'rxjs/operators';
5
- import * as i0 from "@angular/core";
6
- import * as i1 from "@skyux/i18n";
7
- /**
8
- * Service for interacting with the DOM elements of the phone field.
9
- * @internal
10
- */
11
- export class SkyPhoneFieldAdapterService {
12
- constructor(renderer, resourcesService) {
13
- this.renderer = renderer;
14
- this.resourcesService = resourcesService;
15
- this.ngUnsubscribe = new Subject();
16
- }
17
- ngOnDestroy() {
18
- this.ngUnsubscribe.next();
19
- this.ngUnsubscribe.complete();
20
- }
21
- addElementClass(elementRef, className) {
22
- this.renderer.addClass(elementRef.nativeElement, className);
23
- }
24
- setElementDisabledState(elementRef, disabled) {
25
- this.renderer.setProperty(elementRef.nativeElement, 'disabled', disabled);
26
- }
27
- setElementPlaceholder(elementRef, placeholder) {
28
- this.renderer.setAttribute(elementRef.nativeElement, 'placeholder', placeholder);
29
- }
30
- setElementType(elementRef) {
31
- this.renderer.setAttribute(elementRef.nativeElement, 'type', 'tel');
32
- }
33
- setElementValue(elementRef, value) {
34
- if (value) {
35
- this.renderer.setProperty(elementRef.nativeElement, 'value', value);
36
- }
37
- }
38
- setAriaLabel(element) {
39
- /* Sanity check */
40
- /* istanbul ignore else */
41
- if (!element.nativeElement.getAttribute('aria-label')) {
42
- this.resourcesService
43
- .getString('skyux_phone_field_default_label')
44
- .pipe(takeUntil(this.ngUnsubscribe))
45
- .subscribe((value) => {
46
- this.renderer.setAttribute(element.nativeElement, 'aria-label', value);
47
- });
48
- }
49
- }
50
- focusCountrySearchElement(el) {
51
- const input = el.querySelector('textarea');
52
- input.focus();
53
- }
54
- focusPhoneInput(el) {
55
- const input = el.querySelector('.sky-phone-field-container input');
56
- input.focus();
57
- }
58
- }
59
- SkyPhoneFieldAdapterService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyPhoneFieldAdapterService, deps: [{ token: i0.Renderer2 }, { token: i1.SkyLibResourcesService }], target: i0.ɵɵFactoryTarget.Injectable });
60
- SkyPhoneFieldAdapterService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyPhoneFieldAdapterService });
61
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyPhoneFieldAdapterService, decorators: [{
62
- type: Injectable
63
- }], ctorParameters: function () { return [{ type: i0.Renderer2 }, { type: i1.SkyLibResourcesService }]; } });
64
- //# sourceMappingURL=phone-field-adapter.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"phone-field-adapter.service.js","sourceRoot":"","sources":["../../../../../../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AI,KAAK,EAAE;YACT,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,aAAa,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;SACrE;IACH,CAAC;IAEM,YAAY,CAAC,OAAmB;QACrC,kBAAkB;QAClB,0BAA0B;QAC1B,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE;YACrD,IAAI,CAAC,gBAAgB;iBAClB,SAAS,CAAC,iCAAiC,CAAC;iBAC5C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;iBACnC,SAAS,CAAC,CAAC,KAAa,EAAE,EAAE;gBAC3B,IAAI,CAAC,QAAQ,CAAC,YAAY,CACxB,OAAO,CAAC,aAAa,EACrB,YAAY,EACZ,KAAK,CACN,CAAC;YACJ,CAAC,CAAC,CAAC;SACN;IACH,CAAC;IAEM,yBAAyB,CAAC,EAAW;QAC1C,MAAM,KAAK,GAAgB,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QACxD,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;IAEM,eAAe,CAAC,EAAW;QAChC,MAAM,KAAK,GAAgB,EAAE,CAAC,aAAa,CACzC,kCAAkC,CACnC,CAAC;QACF,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;;yHAxEU,2BAA2B;6HAA3B,2BAA2B;4FAA3B,2BAA2B;kBADvC,UAAU","sourcesContent":["import { ElementRef, Injectable, OnDestroy, Renderer2 } from '@angular/core';\nimport { SkyLibResourcesService } from '@skyux/i18n';\n\nimport { Subject } from 'rxjs';\nimport { takeUntil } from 'rxjs/operators';\n\n/**\n * Service for interacting with the DOM elements of the phone field.\n * @internal\n */\n@Injectable()\nexport class SkyPhoneFieldAdapterService implements OnDestroy {\n private ngUnsubscribe = new Subject();\n\n constructor(\n private renderer: Renderer2,\n private resourcesService: SkyLibResourcesService\n ) {}\n\n public ngOnDestroy(): void {\n this.ngUnsubscribe.next();\n this.ngUnsubscribe.complete();\n }\n\n public addElementClass(elementRef: ElementRef, className: string): void {\n this.renderer.addClass(elementRef.nativeElement, className);\n }\n\n public setElementDisabledState(\n elementRef: ElementRef,\n disabled: boolean\n ): void {\n this.renderer.setProperty(elementRef.nativeElement, 'disabled', disabled);\n }\n\n public setElementPlaceholder(\n elementRef: ElementRef,\n placeholder: string\n ): void {\n this.renderer.setAttribute(\n elementRef.nativeElement,\n 'placeholder',\n placeholder\n );\n }\n\n public setElementType(elementRef: ElementRef): void {\n this.renderer.setAttribute(elementRef.nativeElement, 'type', 'tel');\n }\n\n public setElementValue(elementRef: ElementRef, value: string): void {\n if (value) {\n this.renderer.setProperty(elementRef.nativeElement, 'value', value);\n }\n }\n\n public setAriaLabel(element: ElementRef): void {\n /* Sanity check */\n /* istanbul ignore else */\n if (!element.nativeElement.getAttribute('aria-label')) {\n this.resourcesService\n .getString('skyux_phone_field_default_label')\n .pipe(takeUntil(this.ngUnsubscribe))\n .subscribe((value: string) => {\n this.renderer.setAttribute(\n element.nativeElement,\n 'aria-label',\n value\n );\n });\n }\n }\n\n public focusCountrySearchElement(el: Element): void {\n const input: HTMLElement = el.querySelector('textarea');\n input.focus();\n }\n\n public focusPhoneInput(el: Element): void {\n const input: HTMLElement = el.querySelector(\n '.sky-phone-field-container input'\n );\n input.focus();\n }\n}\n"]}
@@ -1,280 +0,0 @@
1
- import { ChangeDetectorRef, Directive, ElementRef, HostListener, Input, Optional, forwardRef, } from '@angular/core';
2
- import { NG_VALIDATORS, NG_VALUE_ACCESSOR, } from '@angular/forms';
3
- import { PhoneNumberFormat, PhoneNumberUtil } from 'google-libphonenumber';
4
- import { BehaviorSubject, Subject } from 'rxjs';
5
- import { debounceTime, takeUntil } from 'rxjs/operators';
6
- import { SkyPhoneFieldAdapterService } from './phone-field-adapter.service';
7
- import { SkyPhoneFieldComponent } from './phone-field.component';
8
- import * as i0 from "@angular/core";
9
- import * as i1 from "./phone-field-adapter.service";
10
- import * as i2 from "./phone-field.component";
11
- // tslint:disable:no-forward-ref no-use-before-declare
12
- const SKY_PHONE_FIELD_VALUE_ACCESSOR = {
13
- provide: NG_VALUE_ACCESSOR,
14
- useExisting: forwardRef(() => SkyPhoneFieldInputDirective),
15
- multi: true,
16
- };
17
- const SKY_PHONE_FIELD_VALIDATOR = {
18
- provide: NG_VALIDATORS,
19
- useExisting: forwardRef(() => SkyPhoneFieldInputDirective),
20
- multi: true,
21
- };
22
- // tslint:enable
23
- /**
24
- * Creates a button, search input, and text input for entering and validating
25
- * international phone numbers. Place this attribute on an `input` element, and wrap
26
- * that element in a `sky-phone-field` component. By default, the country selector
27
- * button displays a flag icon for the default country, and the phone number input
28
- * displays a sample of the correct phone number format. When users select the country
29
- * selector button, they expose the country search input, which is
30
- * [an autocomplete input](https://developer.blackbaud.com/skyux/components/autocomplete)
31
- * that allows them to select different countries. When users enter `+` followed by an
32
- * international dial code in the phone number input, the country automatically switches
33
- * to the country associated with the dial code.
34
- * @required
35
- */
36
- export class SkyPhoneFieldInputDirective {
37
- constructor(changeDetector, elRef, adapterService, phoneFieldComponent) {
38
- this.changeDetector = changeDetector;
39
- this.elRef = elRef;
40
- this.adapterService = adapterService;
41
- this.phoneFieldComponent = phoneFieldComponent;
42
- /**
43
- * Indicates whether to prevent validation on the phone number input. For validation,
44
- * phone numbers are driven through the `ngModel` attribute that you specify on an
45
- * `input` element or on a `FormControl` in a reactive form. To prevent validation,
46
- * set this property to `true`.
47
- * @default false
48
- */
49
- this.skyPhoneFieldNoValidate = false;
50
- this.ngUnsubscribe = new Subject();
51
- this.phoneUtils = PhoneNumberUtil.getInstance();
52
- // eslint-disable-next-line @typescript-eslint/no-empty-function
53
- this.onChange = (_) => { };
54
- // eslint-disable-next-line @typescript-eslint/no-empty-function
55
- this.onTouched = () => { };
56
- // eslint-disable-next-line @typescript-eslint/no-empty-function
57
- this.validatorChange = () => { };
58
- }
59
- /**
60
- * Indicates whether to disable the phone field.
61
- * @default false
62
- */
63
- set disabled(value) {
64
- this.phoneFieldComponent.countrySelectDisabled = value;
65
- this.adapterService.setElementDisabledState(this.elRef, value);
66
- this._disabled = value;
67
- }
68
- get disabled() {
69
- return this._disabled || false;
70
- }
71
- set modelValue(value) {
72
- this._modelValue = value;
73
- this.adapterService.setElementValue(this.elRef, value);
74
- if (value) {
75
- const formattedValue = this.formatNumber(value.toString());
76
- this.onChange(formattedValue);
77
- }
78
- else {
79
- this.onChange(value);
80
- }
81
- this.validatorChange();
82
- }
83
- get modelValue() {
84
- return this._modelValue;
85
- }
86
- ngOnInit() {
87
- if (!this.phoneFieldComponent) {
88
- throw new Error('You must wrap the `skyPhoneFieldInput` directive within a ' +
89
- '`<sky-phone-field>` component!');
90
- }
91
- this.adapterService.setElementType(this.elRef);
92
- this.adapterService.addElementClass(this.elRef, 'sky-form-control');
93
- if (this.phoneFieldComponent.selectedCountry) {
94
- this.adapterService.setElementPlaceholder(this.elRef, this.phoneFieldComponent.selectedCountry.exampleNumber);
95
- }
96
- this.adapterService.setAriaLabel(this.elRef);
97
- }
98
- ngAfterViewInit() {
99
- this.phoneFieldComponent.selectedCountryChange
100
- .pipe(takeUntil(this.ngUnsubscribe))
101
- .subscribe((country) => {
102
- this.modelValue = this.elRef.nativeElement.value;
103
- this.adapterService.setElementPlaceholder(this.elRef, country.exampleNumber);
104
- });
105
- // This is needed to address a bug in Angular 4, where the value is not changed on the view.
106
- // See: https://github.com/angular/angular/issues/13792
107
- /* istanbul ignore else */
108
- if (this.control && this.modelValue) {
109
- this.control.setValue(this.modelValue, { emitEvent: false });
110
- this.changeDetector.detectChanges();
111
- }
112
- }
113
- ngOnDestroy() {
114
- this.ngUnsubscribe.next();
115
- this.ngUnsubscribe.complete();
116
- }
117
- /**
118
- * Writes the new value for reactive forms on change events on the input element
119
- * @param event The change event that was received
120
- */
121
- onInputChange(event) {
122
- if (!this.textChanges) {
123
- this.setupTextChangeSubscription(event.target.value);
124
- }
125
- else {
126
- this.textChanges.next(event.target.value);
127
- }
128
- }
129
- /**
130
- * Marks reactive form controls as touched on input blur events
131
- */
132
- onInputBlur() {
133
- this.onTouched();
134
- }
135
- onInputTyping(event) {
136
- if (!this.textChanges) {
137
- this.setupTextChangeSubscription(event.target.value);
138
- }
139
- else {
140
- this.textChanges.next(event.target.value);
141
- }
142
- }
143
- /**
144
- * Writes the new value for reactive forms
145
- * @param value The new value for the input
146
- */
147
- writeValue(value) {
148
- this.phoneFieldComponent.setCountryByDialCode(value);
149
- this.modelValue = value;
150
- }
151
- registerOnChange(fn) {
152
- this.onChange = fn;
153
- }
154
- registerOnTouched(fn) {
155
- this.onTouched = fn;
156
- }
157
- registerOnValidatorChange(fn) {
158
- this.validatorChange = fn;
159
- }
160
- /**
161
- * Sets the disabled state on the input
162
- * @param isDisabled the new value of the input's disabled state
163
- */
164
- setDisabledState(isDisabled) {
165
- this.disabled = isDisabled;
166
- }
167
- /**
168
- * Validate's the form control's current value
169
- * @param control the form control for the input
170
- */
171
- validate(control) {
172
- if (!this.control) {
173
- this.control = control;
174
- }
175
- if (this.skyPhoneFieldNoValidate) {
176
- return;
177
- }
178
- const value = control.value;
179
- if (!value) {
180
- return;
181
- }
182
- if (this.phoneFieldComponent.selectedCountry &&
183
- !this.validateNumber(value)) {
184
- if (!this.textChanges) {
185
- // Mark the invalid control as touched so that the input's invalid CSS styles appear.
186
- // (This is only required when the invalid value is set by the FormControl constructor.)
187
- // We don't do this if the input is the active element so that we don't show validation
188
- // errors unless it is invalid on initialization or the input has been blurred.
189
- control.markAsTouched();
190
- }
191
- return {
192
- skyPhoneField: {
193
- invalid: value,
194
- },
195
- };
196
- }
197
- }
198
- setupTextChangeSubscription(text) {
199
- this.textChanges = new BehaviorSubject(text);
200
- this.textChanges
201
- .pipe(debounceTime(500), takeUntil(this.ngUnsubscribe))
202
- .subscribe((newValue) => {
203
- this.writeValue(newValue);
204
- });
205
- }
206
- validateNumber(phoneNumber) {
207
- try {
208
- const numberObj = this.phoneUtils.parseAndKeepRawInput(phoneNumber, this.phoneFieldComponent.selectedCountry.iso2);
209
- if (!this.phoneFieldComponent.allowExtensions &&
210
- numberObj.getExtension()) {
211
- return false;
212
- }
213
- return this.phoneUtils.isValidNumber(numberObj);
214
- }
215
- catch (e) {
216
- return false;
217
- }
218
- }
219
- /**
220
- * Format's the given phone number based on the currently selected country.
221
- * @param phoneNumber The number to format
222
- */
223
- formatNumber(phoneNumber) {
224
- try {
225
- const numberObj = this.phoneUtils.parseAndKeepRawInput(phoneNumber, this.phoneFieldComponent.selectedCountry.iso2);
226
- if (this.phoneUtils.isPossibleNumber(numberObj)) {
227
- switch (this.phoneFieldComponent.returnFormat) {
228
- case 'international':
229
- return this.phoneUtils.format(numberObj, PhoneNumberFormat.INTERNATIONAL);
230
- case 'national':
231
- return this.phoneUtils.format(numberObj, PhoneNumberFormat.NATIONAL);
232
- case 'default':
233
- default:
234
- if (this.phoneFieldComponent.selectedCountry.iso2 !==
235
- this.phoneFieldComponent.defaultCountry) {
236
- return this.phoneUtils.format(numberObj, PhoneNumberFormat.INTERNATIONAL);
237
- }
238
- else {
239
- return this.phoneUtils.format(numberObj, PhoneNumberFormat.NATIONAL);
240
- }
241
- }
242
- }
243
- else {
244
- return phoneNumber;
245
- }
246
- }
247
- catch (e) {
248
- /* sanity check */
249
- /* istanbul ignore next */
250
- return phoneNumber;
251
- }
252
- }
253
- }
254
- SkyPhoneFieldInputDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyPhoneFieldInputDirective, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i1.SkyPhoneFieldAdapterService, optional: true }, { token: i2.SkyPhoneFieldComponent, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
255
- SkyPhoneFieldInputDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: SkyPhoneFieldInputDirective, selector: "[skyPhoneFieldInput]", inputs: { disabled: "disabled", skyPhoneFieldNoValidate: "skyPhoneFieldNoValidate" }, host: { listeners: { "change": "onInputChange($event)", "blur": "onInputBlur()", "input": "onInputTyping($event)" } }, providers: [SKY_PHONE_FIELD_VALUE_ACCESSOR, SKY_PHONE_FIELD_VALIDATOR], ngImport: i0 });
256
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyPhoneFieldInputDirective, decorators: [{
257
- type: Directive,
258
- args: [{
259
- selector: '[skyPhoneFieldInput]',
260
- providers: [SKY_PHONE_FIELD_VALUE_ACCESSOR, SKY_PHONE_FIELD_VALIDATOR],
261
- }]
262
- }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i1.SkyPhoneFieldAdapterService, decorators: [{
263
- type: Optional
264
- }] }, { type: i2.SkyPhoneFieldComponent, decorators: [{
265
- type: Optional
266
- }] }]; }, propDecorators: { disabled: [{
267
- type: Input
268
- }], skyPhoneFieldNoValidate: [{
269
- type: Input
270
- }], onInputChange: [{
271
- type: HostListener,
272
- args: ['change', ['$event']]
273
- }], onInputBlur: [{
274
- type: HostListener,
275
- args: ['blur']
276
- }], onInputTyping: [{
277
- type: HostListener,
278
- args: ['input', ['$event']]
279
- }] } });
280
- //# sourceMappingURL=phone-field-input.directive.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"phone-field-input.directive.js","sourceRoot":"","sources":["../../../../../../../../libs/components/phone-field/src/lib/modules/phone-field/phone-field-input.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EACjB,SAAS,EACT,UAAU,EACV,YAAY,EACZ,KAAK,EAGL,QAAQ,EACR,UAAU,GACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAGL,aAAa,EACb,iBAAiB,GAGlB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,OAAO,E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BACJ,KAAK,UAAU;wBACb,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAC3B,SAAS,EACT,iBAAiB,CAAC,QAAQ,CAC3B,CAAC;oBACJ,KAAK,SAAS,CAAC;oBACf;wBACE,IACE,IAAI,CAAC,mBAAmB,CAAC,eAAe,CAAC,IAAI;4BAC7C,IAAI,CAAC,mBAAmB,CAAC,cAAc,EACvC;4BACA,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAC3B,SAAS,EACT,iBAAiB,CAAC,aAAa,CAChC,CAAC;yBACH;6BAAM;4BACL,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAC3B,SAAS,EACT,iBAAiB,CAAC,QAAQ,CAC3B,CAAC;yBACH;iBACJ;aACF;iBAAM;gBACL,OAAO,WAAW,CAAC;aACpB;SACF;QAAC,OAAO,CAAC,EAAE;YACV,kBAAkB;YAClB,0BAA0B;YAC1B,OAAO,WAAW,CAAC;SACpB;IACH,CAAC;;yHA/RU,2BAA2B;6GAA3B,2BAA2B,4PAF3B,CAAC,8BAA8B,EAAE,yBAAyB,CAAC;4FAE3D,2BAA2B;kBAJvC,SAAS;mBAAC;oBACT,QAAQ,EAAE,sBAAsB;oBAChC,SAAS,EAAE,CAAC,8BAA8B,EAAE,yBAAyB,CAAC;iBACvE;;0BA+DI,QAAQ;;0BACR,QAAQ;4CAvDA,QAAQ;sBADlB,KAAK;gBAmBC,uBAAuB;sBAD7B,KAAK;gBA2FC,aAAa;sBADnB,YAAY;uBAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC;gBAa3B,WAAW;sBADjB,YAAY;uBAAC,MAAM;gBAMb,aAAa;sBADnB,YAAY;uBAAC,OAAO,EAAE,CAAC,QAAQ,CAAC","sourcesContent":["import {\n AfterViewInit,\n ChangeDetectorRef,\n Directive,\n ElementRef,\n HostListener,\n Input,\n OnDestroy,\n OnInit,\n Optional,\n forwardRef,\n} from '@angular/core';\nimport {\n AbstractControl,\n ControlValueAccessor,\n NG_VALIDATORS,\n NG_VALUE_ACCESSOR,\n ValidationErrors,\n Validator,\n} from '@angular/forms';\n\nimport { PhoneNumberFormat, PhoneNumberUtil } from 'google-libphonenumber';\nimport { BehaviorSubject, Subject } from 'rxjs';\nimport { debounceTime, takeUntil } from 'rxjs/operators';\n\nimport { SkyPhoneFieldAdapterService } from './phone-field-adapter.service';\nimport { SkyPhoneFieldComponent } from './phone-field.component';\nimport { SkyPhoneFieldCountry } from './types/country';\n\n// tslint:disable:no-forward-ref no-use-before-declare\nconst SKY_PHONE_FIELD_VALUE_ACCESSOR = {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => SkyPhoneFieldInputDirective),\n multi: true,\n};\n\nconst SKY_PHONE_FIELD_VALIDATOR = {\n provide: NG_VALIDATORS,\n useExisting: forwardRef(() => SkyPhoneFieldInputDirective),\n multi: true,\n};\n// tslint:enable\n\n/**\n * Creates a button, search input, and text input for entering and validating\n * international phone numbers. Place this attribute on an `input` element, and wrap\n * that element in a `sky-phone-field` component. By default, the country selector\n * button displays a flag icon for the default country, and the phone number input\n * displays a sample of the correct phone number format. When users select the country\n * selector button, they expose the country search input, which is\n * [an autocomplete input](https://developer.blackbaud.com/skyux/components/autocomplete)\n * that allows them to select different countries. When users enter `+` followed by an\n * international dial code in the phone number input, the country automatically switches\n * to the country associated with the dial code.\n * @required\n */\n@Directive({\n selector: '[skyPhoneFieldInput]',\n providers: [SKY_PHONE_FIELD_VALUE_ACCESSOR, SKY_PHONE_FIELD_VALIDATOR],\n})\nexport class SkyPhoneFieldInputDirective\n implements OnInit, OnDestroy, AfterViewInit, ControlValueAccessor, Validator\n{\n /**\n * Indicates whether to disable the phone field.\n * @default false\n */\n @Input()\n public set disabled(value: boolean) {\n this.phoneFieldComponent.countrySelectDisabled = value;\n this.adapterService.setElementDisabledState(this.elRef, value);\n this._disabled = value;\n }\n\n public get disabled(): boolean {\n return this._disabled || false;\n }\n\n /**\n * Indicates whether to prevent validation on the phone number input. For validation,\n * phone numbers are driven through the `ngModel` attribute that you specify on an\n * `input` element or on a `FormControl` in a reactive form. To prevent validation,\n * set this property to `true`.\n * @default false\n */\n @Input()\n public skyPhoneFieldNoValidate = false;\n\n private set modelValue(value: string) {\n this._modelValue = value;\n\n this.adapterService.setElementValue(this.elRef, value);\n\n if (value) {\n const formattedValue = this.formatNumber(value.toString());\n\n this.onChange(formattedValue);\n } else {\n this.onChange(value);\n }\n this.validatorChange();\n }\n\n private get modelValue(): string {\n return this._modelValue;\n }\n\n private control: AbstractControl;\n\n private textChanges: BehaviorSubject<string>;\n\n private ngUnsubscribe = new Subject();\n\n private phoneUtils = PhoneNumberUtil.getInstance();\n\n private _disabled: boolean;\n\n private _modelValue: string;\n\n public constructor(\n private changeDetector: ChangeDetectorRef,\n private elRef: ElementRef,\n @Optional() private adapterService: SkyPhoneFieldAdapterService,\n @Optional() private phoneFieldComponent: SkyPhoneFieldComponent\n ) {}\n\n public ngOnInit(): void {\n if (!this.phoneFieldComponent) {\n throw new Error(\n 'You must wrap the `skyPhoneFieldInput` directive within a ' +\n '`<sky-phone-field>` component!'\n );\n }\n\n this.adapterService.setElementType(this.elRef);\n this.adapterService.addElementClass(this.elRef, 'sky-form-control');\n if (this.phoneFieldComponent.selectedCountry) {\n this.adapterService.setElementPlaceholder(\n this.elRef,\n this.phoneFieldComponent.selectedCountry.exampleNumber\n );\n }\n\n this.adapterService.setAriaLabel(this.elRef);\n }\n\n public ngAfterViewInit(): void {\n this.phoneFieldComponent.selectedCountryChange\n .pipe(takeUntil(this.ngUnsubscribe))\n .subscribe((country: SkyPhoneFieldCountry) => {\n this.modelValue = this.elRef.nativeElement.value;\n this.adapterService.setElementPlaceholder(\n this.elRef,\n country.exampleNumber\n );\n });\n\n // This is needed to address a bug in Angular 4, where the value is not changed on the view.\n // See: https://github.com/angular/angular/issues/13792\n /* istanbul ignore else */\n if (this.control && this.modelValue) {\n this.control.setValue(this.modelValue, { emitEvent: false });\n this.changeDetector.detectChanges();\n }\n }\n\n public ngOnDestroy(): void {\n this.ngUnsubscribe.next();\n this.ngUnsubscribe.complete();\n }\n\n /**\n * Writes the new value for reactive forms on change events on the input element\n * @param event The change event that was received\n */\n @HostListener('change', ['$event'])\n public onInputChange(event: any): void {\n if (!this.textChanges) {\n this.setupTextChangeSubscription(event.target.value);\n } else {\n this.textChanges.next(event.target.value);\n }\n }\n\n /**\n * Marks reactive form controls as touched on input blur events\n */\n @HostListener('blur')\n public onInputBlur(): void {\n this.onTouched();\n }\n\n @HostListener('input', ['$event'])\n public onInputTyping(event: any): void {\n if (!this.textChanges) {\n this.setupTextChangeSubscription(event.target.value);\n } else {\n this.textChanges.next(event.target.value);\n }\n }\n\n /**\n * Writes the new value for reactive forms\n * @param value The new value for the input\n */\n public writeValue(value: string): void {\n this.phoneFieldComponent.setCountryByDialCode(value);\n\n this.modelValue = value;\n }\n\n public registerOnChange(fn: (value: any) => any): void {\n this.onChange = fn;\n }\n\n public registerOnTouched(fn: () => any): void {\n this.onTouched = fn;\n }\n\n public registerOnValidatorChange(fn: () => void): void {\n this.validatorChange = fn;\n }\n\n /**\n * Sets the disabled state on the input\n * @param isDisabled the new value of the input's disabled state\n */\n public setDisabledState(isDisabled: boolean): void {\n this.disabled = isDisabled;\n }\n\n /**\n * Validate's the form control's current value\n * @param control the form control for the input\n */\n public validate(control: AbstractControl): ValidationErrors {\n if (!this.control) {\n this.control = control;\n }\n\n if (this.skyPhoneFieldNoValidate) {\n return;\n }\n\n const value = control.value;\n\n if (!value) {\n return;\n }\n\n if (\n this.phoneFieldComponent.selectedCountry &&\n !this.validateNumber(value)\n ) {\n if (!this.textChanges) {\n // Mark the invalid control as touched so that the input's invalid CSS styles appear.\n // (This is only required when the invalid value is set by the FormControl constructor.)\n // We don't do this if the input is the active element so that we don't show validation\n // errors unless it is invalid on initialization or the input has been blurred.\n control.markAsTouched();\n }\n\n return {\n skyPhoneField: {\n invalid: value,\n },\n };\n }\n }\n\n private setupTextChangeSubscription(text: string) {\n this.textChanges = new BehaviorSubject(text);\n\n this.textChanges\n .pipe(debounceTime(500), takeUntil(this.ngUnsubscribe))\n .subscribe((newValue) => {\n this.writeValue(newValue);\n });\n }\n\n private validateNumber(phoneNumber: string): boolean {\n try {\n const numberObj = this.phoneUtils.parseAndKeepRawInput(\n phoneNumber,\n this.phoneFieldComponent.selectedCountry.iso2\n );\n\n if (\n !this.phoneFieldComponent.allowExtensions &&\n numberObj.getExtension()\n ) {\n return false;\n }\n\n return this.phoneUtils.isValidNumber(numberObj);\n } catch (e) {\n return false;\n }\n }\n\n /**\n * Format's the given phone number based on the currently selected country.\n * @param phoneNumber The number to format\n */\n private formatNumber(phoneNumber: string): string {\n try {\n const numberObj = this.phoneUtils.parseAndKeepRawInput(\n phoneNumber,\n this.phoneFieldComponent.selectedCountry.iso2\n );\n if (this.phoneUtils.isPossibleNumber(numberObj)) {\n switch (this.phoneFieldComponent.returnFormat) {\n case 'international':\n return this.phoneUtils.format(\n numberObj,\n PhoneNumberFormat.INTERNATIONAL\n );\n case 'national':\n return this.phoneUtils.format(\n numberObj,\n PhoneNumberFormat.NATIONAL\n );\n case 'default':\n default:\n if (\n this.phoneFieldComponent.selectedCountry.iso2 !==\n this.phoneFieldComponent.defaultCountry\n ) {\n return this.phoneUtils.format(\n numberObj,\n PhoneNumberFormat.INTERNATIONAL\n );\n } else {\n return this.phoneUtils.format(\n numberObj,\n PhoneNumberFormat.NATIONAL\n );\n }\n }\n } else {\n return phoneNumber;\n }\n } catch (e) {\n /* sanity check */\n /* istanbul ignore next */\n return phoneNumber;\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n private onChange = (_: any) => {};\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n private onTouched = () => {};\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n private validatorChange = () => {};\n}\n"]}