From abfba9e8ba64988b4676387b7bbed3e5b0da7f5b Mon Sep 17 00:00:00 2001 From: Vladimir Potekhin <46284632+vladimirpotekhin@users.noreply.github.com> Date: Mon, 19 Aug 2024 19:42:38 +0300 Subject: [PATCH] fix(kit): improve tree-shakeability of `InputPhoneInternational` (#8603) --- .../src/tests/input-phone-international.cy.ts | 12 ++++++++++-- .../components/input-phone-international/index.ts | 12 ++++++++++-- .../input-phone-international.options.ts | 7 ++----- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/projects/demo-cypress/src/tests/input-phone-international.cy.ts b/projects/demo-cypress/src/tests/input-phone-international.cy.ts index 31fd8dab0ab5..5720bb8c1169 100644 --- a/projects/demo-cypress/src/tests/input-phone-international.cy.ts +++ b/projects/demo-cypress/src/tests/input-phone-international.cy.ts @@ -5,7 +5,10 @@ import {FormControl, ReactiveFormsModule} from '@angular/forms'; import {provideAnimations} from '@angular/platform-browser/animations'; import {TuiRoot} from '@taiga-ui/core'; import type {TuiCountryIsoCode} from '@taiga-ui/i18n'; -import {TuiInputPhoneInternational} from '@taiga-ui/kit'; +import { + TuiInputPhoneInternational, + tuiInputPhoneInternationalOptionsProvider, +} from '@taiga-ui/kit'; import {createOutputSpy} from 'cypress/angular'; @Component({ @@ -20,7 +23,12 @@ import {createOutputSpy} from 'cypress/angular'; > `, - providers: [provideAnimations()], + providers: [ + provideAnimations(), + tuiInputPhoneInternationalOptionsProvider({ + metadata: import('libphonenumber-js/max/metadata').then((m) => m.default), + }), + ], }) export class Test implements OnInit { private readonly destroyRef = inject(DestroyRef); diff --git a/projects/demo/src/modules/components/input-phone-international/index.ts b/projects/demo/src/modules/components/input-phone-international/index.ts index 5460fb153301..a1ae046b9bbd 100644 --- a/projects/demo/src/modules/components/input-phone-international/index.ts +++ b/projects/demo/src/modules/components/input-phone-international/index.ts @@ -5,7 +5,10 @@ import {TuiDemo} from '@demo/utils'; import {tuiProvide} from '@taiga-ui/cdk'; import {TuiDropdown, TuiHint, TuiTextfield} from '@taiga-ui/core'; import type {TuiCountryIsoCode} from '@taiga-ui/i18n'; -import {TuiInputPhoneInternational} from '@taiga-ui/kit'; +import { + TuiInputPhoneInternational, + tuiInputPhoneInternationalOptionsProvider, +} from '@taiga-ui/kit'; import {getCountries} from 'libphonenumber-js'; import {ABSTRACT_PROPS_ACCESSOR} from '../abstract/abstract-props-accessor'; @@ -25,7 +28,12 @@ import {InheritedDocumentation} from '../abstract/inherited-documentation'; ], templateUrl: './index.html', changeDetection, - providers: [tuiProvide(ABSTRACT_PROPS_ACCESSOR, PageComponent)], + providers: [ + tuiProvide(ABSTRACT_PROPS_ACCESSOR, PageComponent), + tuiInputPhoneInternationalOptionsProvider({ + metadata: import('libphonenumber-js/max/metadata').then((m) => m.default), + }), + ], }) export default class PageComponent extends AbstractExampleTuiControl { protected readonly countriesVariants: ReadonlyArray = [ diff --git a/projects/kit/components/input-phone-international/input-phone-international.options.ts b/projects/kit/components/input-phone-international/input-phone-international.options.ts index 27d20fcb3224..ed916e56d23b 100644 --- a/projects/kit/components/input-phone-international/input-phone-international.options.ts +++ b/projects/kit/components/input-phone-international/input-phone-international.options.ts @@ -2,8 +2,7 @@ import type {Provider} from '@angular/core'; import {tuiCreateToken, tuiProvideOptions} from '@taiga-ui/cdk/utils/miscellaneous'; import type {TuiCountryIsoCode} from '@taiga-ui/i18n/types'; import type {MetadataJson} from 'libphonenumber-js/core'; -import type {Observable} from 'rxjs'; -import {defer} from 'rxjs'; +import {type Observable, of} from 'rxjs'; export interface TuiInputPhoneInternationalOptions { readonly countries: readonly TuiCountryIsoCode[]; @@ -15,9 +14,7 @@ export const TUI_INPUT_PHONE_INTERNATIONAL_DEFAULT_OPTIONS: TuiInputPhoneInterna { countries: [], countryIsoCode: 'RU', - metadata: defer(async () => - import('libphonenumber-js/min/metadata').then((m) => m.default), - ), + metadata: of({countries: {}, country_calling_codes: {}}), }; /**