@liquid-js/lyr-extras 22.0.0-alpha.4 → 22.0.0-alpha.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 +1 @@
1
- {"version":3,"file":"liquid-js-lyr-extras-phone-input.mjs","names":["allCountries"],"sources":["../../../packages/extras/phone-input/src/country-names.ts","../../../packages/extras/phone-input/src/texts.ts","../../../packages/extras/phone-input/src/phone-number.validator.ts","../../../packages/extras/phone-input/src/phone-input.component.ts","../../../packages/extras/phone-input/src/phone-input.component.html","../../../packages/extras/phone-input/src/phone-number.directive.ts"],"sourcesContent":["import { InjectionToken, Provider } from '@angular/core'\n\n/**\n * Country names in a language, as the language files of\n * [`i18n-iso-countries`](https://www.npmjs.com/package/i18n-iso-countries) have them, e.g. its `langs/de.json`: the\n * language and the names by ISO 3166-1 code, each a name or a list of names, the first of which is shown.\n */\nexport interface NbCountryNames {\n locale: string\n countries: Record<string, string | string[]>\n}\n\n/** Country names, or a function that loads them, e.g. `() => import('i18n-iso-countries/langs/de.json')`. */\nexport type NbCountryNamesSource = NbCountryNames | (() => Promise<NbCountryNames | { default: NbCountryNames }>)\n\n/** @internal */\nexport const NB_COUNTRY_NAMES = new InjectionToken<NbCountryNamesSource>('Lyra Country Names', {\n factory: () => () => import('i18n-iso-countries/langs/en.json', { with: { type: 'json' } })\n})\n\n/**\n * Sets the language of the country names in the phone input, English by default, for the app or for the components\n * inside the one that provides it:\n *\n * ```ts\n * providers: [provideNbCountryNames(() => import('i18n-iso-countries/langs/de.json'))]\n * ```\n */\nexport function provideNbCountryNames(names: NbCountryNamesSource): Provider[] {\n return [{ provide: NB_COUNTRY_NAMES, useValue: names }]\n}\n\n/** @internal */\nexport async function loadCountryNames(source: NbCountryNamesSource): Promise<NbCountryNames> {\n if (typeof source !== 'function') {\n return source\n }\n const loaded = await source()\n return 'default' in loaded ? loaded.default : loaded\n}\n","import { injectNbTexts, NbLocalize } from '@liquid-js/lyr-core'\n\n/** @internal */\ndeclare const $localize: NbLocalize\n\n/**\n * The texts of the phone input. `provideNbTexts({ phoneInput: { ... } })` changes them, and they're translated with\n * Angular's i18n, as `$localize` messages with ids like `@@nb.phoneInput.invalid`.\n */\nexport interface NbPhoneInputTexts {\n /** Names the number field when it has no `aria-label` or `aria-labelledby`. */\n number: string\n /** Label of the button that picks the country, given the country's name. */\n country: (name: string) => string\n /** Label of the button that picks the country while there's none. */\n noCountry: string\n /** Label and placeholder of the field that searches the countries. */\n search: string\n /** The message of the `nbPhoneNumber` error for a number that isn't valid. */\n invalid: string\n /** The message of the `nbPhoneNumber` error for a number from a country that isn't allowed. */\n otherCountry: string\n}\n\ndeclare module '@liquid-js/lyr-core' {\n interface NbTexts {\n phoneInput: NbPhoneInputTexts\n }\n}\n\n/** The default texts, in the app's language. @internal */\nexport function nbPhoneInputTexts(): NbPhoneInputTexts {\n return {\n number: $localize`:@@nb.phoneInput.number:Phone number`,\n country: (name: string) => $localize`:@@nb.phoneInput.country:Country: ${name}:country:`,\n noCountry: $localize`:@@nb.phoneInput.noCountry:Choose a country`,\n search: $localize`:@@nb.phoneInput.search:Search countries`,\n invalid: $localize`:@@nb.phoneInput.invalid:Enter a valid phone number`,\n otherCountry: $localize`:@@nb.phoneInput.otherCountry:Enter a phone number from one of the allowed countries`\n }\n}\n\n/** @internal */\nexport function injectNbPhoneInputTexts() {\n return injectNbTexts('phoneInput', nbPhoneInputTexts)\n}\n","import { inject, LOCALE_ID } from '@angular/core'\nimport { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms'\nimport { SchemaPath, validate } from '@angular/forms/signals'\nimport { injectNbValidationMessage, NbValidationError, nbValidationParam } from '@liquid-js/lyr-core'\nimport { CountryCode, getCountries, parsePhoneNumberFromString, PhoneNumber } from 'libphonenumber-js'\n\nimport { injectNbPhoneInputTexts, NbPhoneInputTexts, nbPhoneInputTexts } from './texts'\n\n/** The error kind of a phone number that isn't valid or isn't from an allowed country. */\nexport const NB_PHONE_NUMBER_ERROR = 'nbPhoneNumber' as const\n\n/**\n * What's wrong with a phone number: it isn't valid (`invalid`), or it's from a country that isn't allowed (`country`).\n */\nexport type NbPhoneNumberProblem = 'invalid' | 'country'\n\n/**\n * The `nbPhoneNumber` error, the same in signal, reactive and template-driven forms, as Angular gives parse errors:\n * its kind, what's wrong, and its message.\n */\nexport interface NbPhoneNumberError {\n kind: typeof NB_PHONE_NUMBER_ERROR\n problem: NbPhoneNumberProblem\n message: string\n}\n\n/** A value, or a function that gives it, e.g. from another control or a signal. */\nexport type NbPhoneNumberOption<T> = T | (() => T)\n\n/** A message of this validator's errors, or a function that gives it for what's wrong. */\nexport type NbPhoneNumberMessage = string | ((problem: NbPhoneNumberProblem) => string)\n\nexport interface NbPhoneNumberOptions {\n /** The country of numbers without a calling code; the app locale's country by default. */\n country?: NbPhoneNumberOption<CountryCode | undefined>\n /** The countries whose numbers pass, all by default. */\n countries?: NbPhoneNumberOption<ReadonlyArray<CountryCode> | undefined>\n /** The message of its errors, in place of the app's (`provideNbValidation`, `provideNbTexts`). */\n message?: NbPhoneNumberMessage\n}\n\n/** Where the errors take their messages and numbers their country from. @internal */\nexport interface NbPhoneNumberContext {\n texts: () => NbPhoneInputTexts\n /** The message of an error, as `nb-validation-errors` shows it. */\n message: (error: NbValidationError) => string\n country?: CountryCode\n}\n\nconst allCountries = new Set<string>(getCountries())\n\n/** The country of a locale, e.g. `GB` for `en-GB`, or `US` for `en`. @internal */\nexport function localeCountry(locale: string): CountryCode | undefined {\n try {\n const region = new Intl.Locale(locale).maximize().region\n return region && allCountries.has(region) ? (region as CountryCode) : undefined\n } catch {\n return undefined\n }\n}\n\n/** The valid number in a text, in the country unless it has a calling code. @internal */\nexport function parsePhoneNumber(text: string, country?: CountryCode): PhoneNumber | undefined {\n if (!text.trim()) {\n return undefined\n }\n const number = parsePhoneNumberFromString(text, country)\n return number?.isValid() ? number : undefined\n}\n\n/** What's wrong with a value as a phone number, if anything; an empty value is fine. @internal */\nexport function checkPhoneNumber(\n value: unknown,\n country?: CountryCode,\n countries?: ReadonlyArray<CountryCode>\n): NbPhoneNumberProblem | undefined {\n if (value === null || value === undefined || value === '') {\n return undefined\n }\n const number = parsePhoneNumber(String(value), country)\n if (!number) {\n return 'invalid'\n }\n return countries && !(number.country && countries.includes(number.country)) ? 'country' : undefined\n}\n\n/**\n * The error of a problem, with its message: the one given, or the app's, or the phone input's texts'. @internal\n */\nexport function phoneNumberError(\n context: NbPhoneNumberContext,\n problem: NbPhoneNumberProblem,\n message?: NbPhoneNumberMessage\n): NbPhoneNumberError {\n const own = typeof message === 'function' ? message(problem) : message\n if (own !== undefined) {\n return { kind: NB_PHONE_NUMBER_ERROR, problem, message: own }\n }\n const texts = context.texts()\n const error = {\n kind: NB_PHONE_NUMBER_ERROR,\n problem,\n message: problem === 'country' ? texts.otherCountry : texts.invalid\n }\n return { ...error, message: context.message({ kind: NB_PHONE_NUMBER_ERROR, params: error }) }\n}\n\n/** Validates a value with the options, as all the forms do. @internal */\nexport function validatePhoneNumber(\n value: unknown,\n options: NbPhoneNumberOptions,\n context: NbPhoneNumberContext\n): NbPhoneNumberError | undefined {\n const problem = checkPhoneNumber(value, read(options.country) ?? context.country, read(options.countries))\n return problem ? phoneNumberError(context, problem, options.message) : undefined\n}\n\nconst read = <T>(option: NbPhoneNumberOption<T>): T =>\n typeof option === 'function' ? (option as () => T)() : option\n\n/** The texts, the app's messages and the locale's country, from the injection context when there's one. @internal */\nexport function phoneNumberContext(): NbPhoneNumberContext {\n try {\n const texts = injectNbPhoneInputTexts()\n return {\n texts: () => texts(),\n message: injectNbValidationMessage(),\n country: localeCountry(inject(LOCALE_ID))\n }\n } catch {\n const texts = nbPhoneInputTexts()\n return {\n texts: () => texts,\n message: (error) => {\n const message = nbValidationParam(error, 'message')\n return typeof message === 'string' ? message : ''\n }\n }\n }\n}\n\n/**\n * Validates a phone number in reactive forms: an empty value passes, a number that isn't valid or isn't from one of\n * `countries` gets the `nbPhoneNumber` error, with its message. In templates, use the `nbPhoneNumber` attribute.\n *\n * ```ts\n * readonly phone = new FormControl('', nbPhoneNumberValidator({ countries: ['US', 'CA'] }));\n * ```\n *\n * The error's message is `message`, if given, or the one `nb-validation-errors` shows for `nbPhoneNumber`: the app's\n * (`provideNbValidation`, `provideNbTexts({ validation })`), or the phone input's texts, `invalid` or\n * `otherCountry`. Made in an injection context, e.g. in a field initializer, it reads numbers in the app locale's\n * country and has the app's messages; elsewhere, numbers need a calling code unless `country` is given, and the\n * messages are the default ones.\n */\nexport function nbPhoneNumberValidator(options: NbPhoneNumberOptions = {}): ValidatorFn {\n const context = phoneNumberContext()\n return (control: AbstractControl): ValidationErrors | null => {\n const error = validatePhoneNumber(control.value, options, context)\n return error ? { [NB_PHONE_NUMBER_ERROR]: error } : null\n }\n}\n\n/**\n * Validates a phone number in signal forms, as `nbPhoneNumberValidator` does:\n *\n * ```ts\n * readonly form = form(this.model, (path) => {\n * nbPhoneNumber(path.phone, { countries: ['US', 'CA'] });\n * });\n * ```\n */\nexport function nbPhoneNumber(\n path: SchemaPath<string | null | undefined>,\n options: NbPhoneNumberOptions = {}\n): void {\n const context = phoneNumberContext()\n validate(path, ({ value }) => validatePhoneNumber(value(), options, context))\n}\n","import {\n afterNextRender,\n booleanAttribute,\n ChangeDetectionStrategy,\n Component,\n computed,\n effect,\n ElementRef,\n forwardRef,\n inject,\n Injector,\n input,\n linkedSignal,\n LOCALE_ID,\n model,\n OnInit,\n resource,\n signal,\n untracked,\n viewChild,\n ViewEncapsulation\n} from '@angular/core'\nimport {\n ControlValueAccessor,\n NG_VALIDATORS,\n NG_VALUE_ACCESSOR,\n ValidationErrors,\n Validator\n} from '@angular/forms'\nimport {\n injectNbDefaults,\n NbAutocompleteComponent,\n NbAutocompleteDirective,\n NbButtonComponent,\n NbComponentOrCustomStatus,\n NbComponentShape,\n NbComponentSize,\n NbFormFieldComponent,\n NbIconComponent,\n NbInputDirective,\n NbOptionComponent,\n NbPrefixDirective,\n NbValidationDirective\n} from '@liquid-js/lyr-core'\nimport {\n CountryCode,\n getCountries,\n getCountryCallingCode,\n getExampleNumber,\n PhoneNumber\n} from 'libphonenumber-js'\nimport examples from 'libphonenumber-js/mobile/examples'\nimport { FlagComponent, FlagDatabase, FlagDatabaseKey } from 'nxt-flags'\n\nimport { loadCountryNames, NB_COUNTRY_NAMES } from './country-names'\nimport {\n checkPhoneNumber,\n localeCountry,\n NB_PHONE_NUMBER_ERROR,\n parsePhoneNumber,\n phoneNumberContext,\n phoneNumberError\n} from './phone-number.validator'\nimport { injectNbPhoneInputTexts } from './texts'\n\n/** A country in the list. */\ninterface NbPhoneCountry {\n code: CountryCode\n name: string\n callingCode: string\n /** The names, the calling code and the ISO code, as the search compares them. */\n search: string\n}\n\n/**\n * Flags of phone regions that aren't ISO countries: Ascension and Tristan da Cunha are part of Saint Helena, Ascension\n * and Tristan da Cunha (SH), whose flag they show.\n */\nconst flagFallbacks: Partial<Record<CountryCode, FlagDatabaseKey>> = { AC: 'sh', TA: 'sh' }\n\nconst allCountries = new Set<string>(getCountries())\n\n/** Text as the search compares it, without case and accents. */\nconst fold = (text: string) =>\n text\n .normalize('NFD')\n .replace(/\\p{Diacritic}/gu, '')\n .toLocaleLowerCase()\n\n/**\n * A phone number field with the country's flag, which picks the country:\n *\n * ```html\n * <nb-phone-input formControlName=\"phone\" />\n * ```\n *\n * @stacked-example(Showcase, phone-input/phone-input-showcase.component)\n *\n * ### Installation\n *\n * It parses and formats numbers with [`libphonenumber-js`](https://www.npmjs.com/package/libphonenumber-js), names\n * the countries with [`i18n-iso-countries`](https://www.npmjs.com/package/i18n-iso-countries)' language files, and\n * shows flags with [`nxt-flags`](https://www.npmjs.com/package/nxt-flags); install them and import\n * `NbPhoneInputComponent` from `@liquid-js/lyr-extras/phone-input`.\n *\n * ```sh\n * npm install libphonenumber-js i18n-iso-countries nxt-flags\n * ```\n *\n * The flags are images the app serves from `assets/flags`; add them to the assets in `angular.json`:\n *\n * ```json\n * { \"glob\": \"*.svg\", \"input\": \"node_modules/nxt-flags/assets/flags\", \"output\": \"assets/flags\" }\n * ```\n *\n * To serve them from elsewhere, e.g. a CDN, set the path with `provideFlagsPath()` from `nxt-flags`.\n *\n * ### Usage\n *\n * The user types the number in their country's format or with a calling code, e.g. `+44`, which picks the country.\n * The flag button replaces the field with a search of the countries, by name or calling code; Escape goes back.\n * The country is the one of the app's locale (`LOCALE_ID`) until the user or a number picks another, or set it with\n * `country`, which also tells which one is picked. It has the sizes, statuses, shapes and `ghost` look of `nbInput`,\n * and its `placeholder` and `readonly`; the placeholder is an example number of the country by default.\n * @stacked-example(Sizes and statuses, phone-input/phone-input-sizes.component)\n *\n * The value is the number in the `E.164` format, e.g. `+12015550123`, or `null` without one; when the field leaves,\n * it shows the number in its country's format, `(201) 555-0123`. While the text isn't a valid number, the value\n * stays the last valid one, or `null`, and the field has the `nbPhoneNumber` parse error,\n * `{ kind, problem: 'invalid', message }`, as Angular's controls report text they can't parse; so validators never\n * see the text. A number from a country that isn't in `countries`, which the list offers, has the same error with\n * `problem: 'country'`. The errors work in reactive, template-driven and signal forms alike.\n *\n * It works with `formControl`, `formControlName`, `ngModel` and signal forms' `[formField]`.\n * @stacked-example(Validation, phone-input/phone-input-validation.component)\n *\n * ### Validators\n *\n * Phone numbers in other fields, e.g. a text field or data from elsewhere, are checked the same way with validators:\n * `nbPhoneNumberValidator(options)` in reactive forms, the `nbPhoneNumber` attribute in template-driven forms, and\n * `nbPhoneNumber(path, options)` in signal forms. The options are the `country` of numbers without a\n * calling code, the app locale's by default, and the `countries` whose numbers pass, each a value or a function that\n * gives it, and the `message` of the errors, a text or a function of what's wrong, in place of the app's. Their\n * `nbPhoneNumber` error says what's wrong, `invalid` or `country`, with its message.\n *\n * ```ts\n * readonly phone = new FormControl<string | null>(null, nbPhoneNumberValidator({ countries: ['US', 'CA'] }));\n *\n * readonly contactForm = form(this.contact, (path) => {\n * nbPhoneNumber(path.phone, { countries: ['GB'] });\n * });\n * ```\n *\n * ```html\n * <input nbInput type=\"tel\" name=\"support\" ngModel nbPhoneNumber [nbPhoneNumberCountries]=\"['US', 'CA']\" />\n * ```\n *\n * ### Country names\n *\n * The countries are named in English. For other languages, provide the language file of `i18n-iso-countries`, e.g.\n * per locale's build, or loaded by `LOCALE_ID`:\n *\n * ```ts\n * providers: [provideNbCountryNames(() => import('i18n-iso-countries/langs/de.json'))]\n * ```\n *\n * Countries without a name in the file aren't in the list; their numbers are still accepted.\n */\n@Component({\n selector: 'nb-phone-input',\n templateUrl: './phone-input.component.html',\n styleUrl: './phone-input.component.scss',\n encapsulation: ViewEncapsulation.None,\n changeDetection: ChangeDetectionStrategy.OnPush,\n imports: [\n NbFormFieldComponent,\n NbPrefixDirective,\n NbButtonComponent,\n NbIconComponent,\n NbInputDirective,\n NbAutocompleteDirective,\n NbAutocompleteComponent,\n NbOptionComponent,\n FlagComponent\n ],\n providers: [\n { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => NbPhoneInputComponent), multi: true },\n { provide: NG_VALIDATORS, useExisting: forwardRef(() => NbPhoneInputComponent), multi: true }\n ],\n host: {\n 'class': 'nb-phone-input',\n '[class.full-width]': 'fullWidth()'\n }\n})\nexport class NbPhoneInputComponent implements OnInit, ControlValueAccessor, Validator {\n // The app's defaults for fields, which the inputs below start from.\n protected readonly nbDefaults = injectNbDefaults('input')\n\n protected readonly texts = injectNbPhoneInputTexts()\n /** Where its errors take their messages from. */\n protected readonly errorContext = phoneNumberContext()\n protected readonly locale = inject(LOCALE_ID)\n protected readonly injector = inject(Injector)\n protected readonly validation = inject(NbValidationDirective, { self: true, optional: true })\n\n /**\n * The country of the number: the app locale's country at first, unless it's set, then the one the user or the number\n * picks.\n */\n readonly country = model<CountryCode>()\n /** The countries in the list, whose numbers pass, all by default. */\n readonly countries = input<ReadonlyArray<CountryCode>>()\n /** Field size: `tiny`, `small`, `medium` (default), `large` or `giant`. */\n readonly sizeInput = input<NbComponentSize | undefined>(undefined, { alias: 'size' })\n /** The size in use: the input's, the app's default, or 'medium'. */\n readonly size = linkedSignal<NbComponentSize>(() => this.sizeInput() ?? this.nbDefaults().size ?? 'medium')\n /** Field status: `basic` (default), `primary`, `info`, `success`, `warning`, `danger` or `control`. */\n readonly status = input<NbComponentOrCustomStatus>('basic')\n /** Field shape: `rectangle` (default), `semi-round` or `round`. */\n readonly shapeInput = input<NbComponentShape | undefined>(undefined, { alias: 'shape' })\n /** The shape in use: the input's, the app's default, or 'rectangle'. */\n readonly shape = linkedSignal<NbComponentShape>(() => this.shapeInput() ?? this.nbDefaults().shape ?? 'rectangle')\n readonly fullWidth = input(false, { transform: booleanAttribute })\n /** Shows the field without its background and border, as `nbInput`'s `ghost` does. */\n readonly ghost = input(false, { transform: booleanAttribute })\n readonly disabled = input(false, { transform: booleanAttribute })\n /** Lets the user read and select the number, but not change it or its country, as a read-only field. */\n readonly readonly = input(false, { transform: booleanAttribute })\n /** The number field's placeholder; an example number of the country by default. */\n readonly placeholder = input<string>()\n /** The country list's distance from the search field, as other fields' overlays have it. */\n readonly overlayOffset = input(8)\n /** Names the number field when there's no `aria-labelledby`; \"Phone number\" by default. */\n readonly ariaLabel = input<string | undefined>(undefined, { alias: 'aria-label' })\n /** The id of the element that names the number field, e.g. a `label`. */\n readonly ariaLabelledBy = input<string | undefined>(undefined, { alias: 'aria-labelledby' })\n\n /** What labels the field: its own `aria-labelledby` and an `nbLabel` of its `nbValidation`. */\n protected readonly fieldLabelledBy = computed(\n () => [this.ariaLabelledBy(), this.validation?.labelledBy()].filter(Boolean).join(' ') || null\n )\n\n /** The country the number is parsed in, the locale's until `country` has one. */\n readonly selectedCountry = computed(() => this.country() ?? localeCountry(this.locale))\n\n constructor() {\n // The number field is the control: it gets the validation's ARIA, not the host.\n this.validation?.delegateAria()\n // Another list of countries can change whether the number passes.\n effect(() => {\n this.countries()\n untracked(() => this.onValidatorChange())\n })\n }\n\n ngOnInit() {\n // `country` tells the country the field uses from the start, also when the binding gives none.\n if (!this.country()) {\n this.pickCountry(localeCountry(this.locale))\n }\n }\n\n protected readonly isDisabled = linkedSignal(() => this.disabled())\n protected readonly resolvedStatus = computed(() => this.validation?.status() ?? this.status())\n /** The field's buttons are white on colour, with the `control` status, and grey otherwise. */\n protected readonly buttonStatus = computed(() => (this.resolvedStatus() === 'control' ? 'control' : 'basic'))\n /** The number as the field shows it. */\n protected readonly text = signal('')\n /** Whether the text isn't a valid number. */\n protected readonly parseError = signal(false)\n /** Whether the search of the countries replaces the number field. */\n protected readonly picking = signal(false)\n protected readonly query = signal('')\n protected readonly namesSource = inject(NB_COUNTRY_NAMES)\n protected readonly names = resource({ loader: () => loadCountryNames(this.namesSource) })\n\n /** The countries with a name, in the language's order. */\n protected readonly list = computed(() => {\n const names = this.names.hasValue() ? this.names.value().countries : {}\n const only = this.countries()\n const codes = only ? only.filter((code) => allCountries.has(code)) : (getCountries() as CountryCode[])\n const list = new Array<NbPhoneCountry>()\n for (const code of codes) {\n const name = names[code]\n const all = Array.isArray(name) ? name : name ? [name] : []\n if (all.length) {\n const callingCode = getCountryCallingCode(code)\n list.push({ code, name: all[0], callingCode, search: fold(`${all.join(' ')} +${callingCode} ${code}`) })\n }\n }\n const collator = new Intl.Collator(this.locale)\n return list.sort((a, b) => collator.compare(a.name, b.name))\n })\n\n /** The countries the search finds. */\n protected readonly shown = computed(() => {\n const words = fold(this.query()).split(/\\s+/).filter(Boolean)\n return this.list().filter((country) => words.every((word) => country.search.includes(word)))\n })\n\n protected readonly countryName = computed(() => {\n const code = this.selectedCountry()\n return code && (this.list().find((country) => country.code === code)?.name ?? code)\n })\n\n protected readonly countryLabel = computed(() => {\n const name = this.countryName()\n return name ? this.texts().country(name) : this.texts().noCountry\n })\n\n /** An example number of the country, in its format. */\n protected readonly example = computed(() => {\n const code = this.selectedCountry()\n return code ? (getExampleNumber(code, examples)?.formatNational() ?? '') : ''\n })\n\n protected readonly numberField = viewChild.required<ElementRef<HTMLInputElement>>('number')\n protected readonly searchField = viewChild.required<ElementRef<HTMLInputElement>>('search')\n\n /** The value last given to the form, `null` without one. */\n protected value: string | null = null\n protected onChange: (value: string | null) => void = () => {}\n protected onTouched: () => void = () => {}\n protected onValidatorChange: () => void = () => {}\n\n // Untracked, as forms write values from wherever the app sets them, e.g. an effect that mustn't come to depend\n // on the control.\n writeValue(value?: string | null) {\n untracked(() => {\n const text = value ?? ''\n const number = this.parse(text)\n this.pickCountry(number?.country)\n this.text.set(number ? this.display(number) : text)\n this.value = value ?? null\n this.setParseError(false)\n })\n }\n\n registerOnChange(fn: (value: string | null) => void) {\n this.onChange = fn\n }\n\n registerOnTouched(fn: () => void) {\n this.onTouched = fn\n }\n\n registerOnValidatorChange(fn: () => void) {\n this.onValidatorChange = fn\n }\n\n setDisabledState(disabled: boolean) {\n this.isDisabled.set(disabled)\n }\n\n /** The parse error of text that isn't a valid number, or the error of a number from a country not in `countries`. */\n validate(): ValidationErrors | null {\n const problem = this.parseError()\n ? 'invalid'\n : checkPhoneNumber(this.value, this.selectedCountry(), this.countries())\n return problem ? { [NB_PHONE_NUMBER_ERROR]: phoneNumberError(this.errorContext, problem) } : null\n }\n\n /** Moves focus to the number. */\n focus() {\n this.numberField().nativeElement.focus()\n }\n\n /** Sets `country`, when it's another. */\n protected pickCountry(code?: CountryCode) {\n if (code && code !== this.country()) {\n this.country.set(code)\n }\n }\n\n /** The flag of a country, the unknown flag without one. */\n protected flag(code?: CountryCode): FlagDatabaseKey {\n const key = code?.toLowerCase()\n return (code && flagFallbacks[code]) ?? (key && key in FlagDatabase ? (key as FlagDatabaseKey) : 'xx')\n }\n\n protected typed(event: Event) {\n const text = (event.target as HTMLInputElement).value\n this.text.set(text)\n // A number with a calling code picks its country.\n this.pickCountry(this.parse(text)?.country)\n this.update()\n }\n\n protected left() {\n const number = this.parse(this.text())\n if (number) {\n this.text.set(this.display(number))\n }\n this.onTouched()\n }\n\n /** Replaces the number field with the search of the countries, whose list opens. */\n protected pick() {\n if (this.isDisabled() || this.readonly()) {\n return\n }\n const search = this.searchField().nativeElement\n search.value = ''\n this.query.set('')\n this.picking.set(true)\n afterNextRender(() => search.focus(), { injector: this.injector })\n }\n\n protected searched(event: Event) {\n this.query.set((event.target as HTMLInputElement).value)\n }\n\n protected chose(country?: NbPhoneCountry | string) {\n if (country && typeof country !== 'string') {\n this.country.set(country.code)\n // The text is a number of the new country.\n this.update()\n }\n this.stopPicking(true)\n }\n\n /**\n * Escape in the search goes back to the number, the list closing too; it's handled, so nothing else closes, e.g. a\n * dialog around it.\n */\n protected searchEscaped(event: Event) {\n event.preventDefault()\n this.stopPicking(true)\n }\n\n /** Leaving the search touches the control, as leaving an autocomplete's input does. */\n protected searchLeft() {\n this.stopPicking(false)\n this.onTouched()\n }\n\n /**\n * Shows the number field again, and moves focus to it after Escape or picking a country, which can come after the\n * search field lost focus to the list.\n */\n protected stopPicking(focus: boolean) {\n this.picking.set(false)\n if (focus) {\n afterNextRender(() => this.focus(), { injector: this.injector })\n }\n }\n\n /** What the search field shows: the text typed in it, or the name of the country picked. */\n protected readonly displayCountry = (value?: NbPhoneCountry | string) =>\n typeof value === 'string' ? value : (value?.name ?? '')\n\n /** The valid number in the text, in the picked country unless it has a calling code. */\n protected parse(text: string): PhoneNumber | undefined {\n return parsePhoneNumber(text, this.selectedCountry())\n }\n\n /** A number as the field shows it: in its country's format, or international without one. */\n protected display(number: PhoneNumber) {\n return number.country ? number.formatNational() : number.formatInternational()\n }\n\n /**\n * Gives the form the number in the text, when it's another; while the text isn't a valid number, the value stays\n * and the field has the parse error.\n */\n protected update() {\n const text = this.text().trim()\n const number = text ? this.parse(text) : undefined\n this.setParseError(!!text && !number)\n const value = number?.number ?? null\n if ((!text || number) && value !== this.value) {\n this.value = value\n this.onChange(value)\n }\n // Signal forms only check a value accessor's validators again when they're told to, e.g. for a number of a\n // country `countries` leaves out.\n this.onValidatorChange()\n }\n\n protected setParseError(parseError: boolean) {\n if (parseError !== this.parseError()) {\n this.parseError.set(parseError)\n this.onValidatorChange()\n }\n }\n}\n","<nb-form-field class=\"nb-phone-input-number\"\n [style.display]=\"picking() ? 'none' : null\">\n <button nbPrefix\n nbButton\n ghost\n type=\"button\"\n class=\"nb-phone-input-country\"\n [size]=\"size()\"\n [status]=\"buttonStatus()\"\n [disabled]=\"isDisabled() || readonly()\"\n [attr.aria-label]=\"countryLabel()\"\n (click)=\"pick()\">\n <nxt-flag [country]=\"flag(selectedCountry())\"\n size=\"s\" />\n <nb-icon icon=\"chevron-down-outline\"\n pack=\"essentials\"\n aria-hidden=\"true\" />\n </button>\n <input #number\n nbInput\n type=\"tel\"\n autocomplete=\"tel\"\n [fieldSize]=\"size()\"\n [status]=\"resolvedStatus()\"\n [shape]=\"shape()\"\n [fullWidth]=\"fullWidth()\"\n [ghost]=\"ghost()\"\n [disabled]=\"isDisabled()\"\n [readOnly]=\"readonly()\"\n [value]=\"text()\"\n [placeholder]=\"placeholder() ?? example()\"\n [attr.aria-label]=\"fieldLabelledBy() ? null : (ariaLabel() ?? texts().number)\"\n [attr.aria-labelledby]=\"fieldLabelledBy()\"\n [attr.aria-required]=\"validation?.ariaRequired()\"\n [attr.aria-invalid]=\"validation?.ariaInvalid()\"\n [attr.aria-describedby]=\"validation?.describedBy()\"\n (input)=\"typed($event)\"\n (blur)=\"left()\" />\n</nb-form-field>\n\n<!-- Stays in the page while it's hidden, so the list it opens still takes a click after it loses focus. -->\n<nb-form-field class=\"nb-phone-input-search\"\n [style.display]=\"picking() ? null : 'none'\">\n <nb-icon nbPrefix\n icon=\"search-outline\"\n pack=\"essentials\"\n aria-hidden=\"true\" />\n <input #search\n nbInput\n type=\"text\"\n autocomplete=\"off\"\n [fieldSize]=\"size()\"\n [status]=\"resolvedStatus()\"\n [shape]=\"shape()\"\n [fullWidth]=\"fullWidth()\"\n [ghost]=\"ghost()\"\n [placeholder]=\"texts().search\"\n [attr.aria-label]=\"texts().search\"\n [nbAutocomplete]=\"countryList\"\n [overlayOffset]=\"overlayOffset()\"\n (input)=\"searched($event)\"\n (keydown.escape)=\"searchEscaped($event)\"\n (blur)=\"searchLeft()\" />\n</nb-form-field>\n\n<nb-autocomplete #countryList\n [size]=\"size()\"\n [handleDisplayFn]=\"displayCountry\"\n (selectedChange)=\"chose($event)\">\n @for (country of shown(); track country.code) {\n <nb-option class=\"nb-phone-input-option\"\n [value]=\"country\">\n <nxt-flag [country]=\"flag(country.code)\"\n size=\"s\" />\n <span class=\"nb-phone-input-name\">{{ country.name }}</span>\n <span class=\"nb-phone-input-calling-code\">+{{ country.callingCode }}</span>\n </nb-option>\n }\n</nb-autocomplete>\n","import { Directive, effect, ElementRef, forwardRef, inject, input } from '@angular/core'\nimport { AbstractControl, NG_VALIDATORS, ValidationErrors, Validator } from '@angular/forms'\nimport type { CountryCode } from 'libphonenumber-js'\n\nimport {\n NB_PHONE_NUMBER_ERROR,\n NbPhoneNumberMessage,\n phoneNumberContext,\n validatePhoneNumber\n} from './phone-number.validator'\n\n/**\n * Validates a phone number in template-driven forms, as `nbPhoneNumberValidator` does in reactive forms:\n *\n * ```html\n * <input nbInput type=\"tel\" name=\"phone\" ngModel nbPhoneNumber [nbPhoneNumberCountries]=\"['US', 'CA']\" />\n * ```\n */\n@Directive({\n selector: '[nbPhoneNumber][ngModel],[nbPhoneNumber][formControl],[nbPhoneNumber][formControlName]',\n providers: [{ provide: NG_VALIDATORS, useExisting: forwardRef(() => NbPhoneNumberValidatorDirective), multi: true }],\n host: {\n // On a plain text field, the number reads left to right from the left in any page, as a tel field's does.\n '[style.text-align]': \"isInput ? 'left' : null\",\n '[style.unicode-bidi]': \"isInput ? 'plaintext' : null\"\n }\n})\nexport class NbPhoneNumberValidatorDirective implements Validator {\n /** The country of numbers without a calling code; the app locale's country by default. */\n readonly country = input<CountryCode>(undefined, { alias: 'nbPhoneNumberCountry' })\n /** The countries whose numbers pass, all by default. */\n readonly countries = input<ReadonlyArray<CountryCode>>(undefined, { alias: 'nbPhoneNumberCountries' })\n /** The message of its errors, in place of the app's. */\n readonly message = input<NbPhoneNumberMessage>(undefined, { alias: 'nbPhoneNumberMessage' })\n\n // By tag name, which a server's DOM also has.\n protected readonly isInput = inject<ElementRef<Element>>(ElementRef).nativeElement.tagName === 'INPUT'\n protected readonly context = phoneNumberContext()\n protected onValidatorChange: () => void = () => {}\n\n constructor() {\n // Other options can change whether the value passes.\n effect(() => {\n this.country()\n this.countries()\n this.message()\n this.onValidatorChange()\n })\n }\n\n validate(control: AbstractControl): ValidationErrors | null {\n const error = validatePhoneNumber(\n control.value,\n { country: this.country(), countries: this.countries(), message: this.message() },\n this.context\n )\n return error ? { [NB_PHONE_NUMBER_ERROR]: error } : null\n }\n\n registerOnValidatorChange(fn: () => void) {\n this.onValidatorChange = fn\n }\n}\n"],"mappings":";;;;;;;;AAgBA,MAAa,mBAAmB,IAAI,eAAqC,sBAAsB,EAC3F,qBAAqB,OAAO,oCAAoC,EAAE,MAAM,EAAE,MAAM,OAAM,EAAE,GAC3F,CAAA;AAUD,SAAgB,sBAAsB,OAA2B;CAC7D,OAAO,CAAC;EAAE,SAAS;EAAkB,UAAU;CAAK,CAAE;AAC1D;AAGA,eAAsB,iBAAiB,QAA4B;CAC/D,IAAI,OAAO,WAAW,YAClB,OAAO;CAEX,MAAM,SAAS,MAAM,OAAM;CAC3B,OAAO,aAAa,SAAS,OAAO,UAAU;AAClD;ACRA,SAAgB,oBAAiB;CAC7B,OAAO;EACH,QAAQ,SAAS;EACjB,UAAU,SAAiB,SAAS,qCAAqC,KAAI;EAC7E,WAAW,SAAS;EACpB,QAAQ,SAAS;EACjB,SAAS,SAAS;EAClB,cAAc,SAAS;CAC1B;AACL;AAGA,SAAgB,0BAAuB;CACnC,OAAO,cAAc,cAAc,iBAAiB;AACxD;ACpCA,MAAa,wBAAwB;AAwCrC,MAAMA,iBAAe,IAAI,IAAY,aAAY,CAAE;AAGnD,SAAgB,cAAc,QAAc;CACxC,IAAI;EACA,MAAM,SAAS,IAAI,KAAK,OAAO,MAAM,CAAC,CAAC,SAAQ,CAAE,CAAC;EAClD,OAA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AAA;KAAA,YAAA;KAAA,mBAAA;IAAA;IAAA,WAAA;KAAA,mBAAA;KAAA,YAAA;KAAA,UAAA;KAAA,YAAA;KAAA,mBAAA;IAAA;IAAA,SAAA;KAAA,mBAAA;KAAA,YAAA;KAAA,UAAA;KAAA,YAAA;KAAA,mBAAA;IAAA;GAAA;GAAA,MAAA,EAAA,YAAA;IAAA,oBAAA;IAAA,sBAAA;GAAA,EAAA;GAAA,WAP7B,CAAC;IAAE,SAAS;IAAe,aAAa,iBAAiB,+BAA+B;IAAG,OAAO;GAAI,CAAE;GAAC,UAAA;EAAA,CAAA;CAAA;;AAO3G,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAA+B,YAAA,CAAA;EAT3C,MAAA;EAAU,MAAA,CAAA;GACP,UAAU;GACV,WAAW,CAAC;IAAE,SAAS;IAAe,aAAa,iBAAgB,+BAAgC;IAAG,OAAO;GAAI,CAAE;GACnH,MAAM;IAEF,sBAAsB;IACtB,wBAAwB;GAC3B;EACJ,CAAA"}
1
+ {"version":3,"file":"liquid-js-lyr-extras-phone-input.mjs","names":["allCountries"],"sources":["../../../packages/extras/phone-input/src/country-names.ts","../../../packages/extras/phone-input/src/texts.ts","../../../packages/extras/phone-input/src/phone-number.validator.ts","../../../packages/extras/phone-input/src/phone-input.component.ts","../../../packages/extras/phone-input/src/phone-input.component.html","../../../packages/extras/phone-input/src/phone-number.directive.ts"],"sourcesContent":["import { InjectionToken, Provider } from '@angular/core'\n\n/**\n * Country names in a language, as the language files of\n * [`i18n-iso-countries`](https://www.npmjs.com/package/i18n-iso-countries) have them, e.g. its `langs/de.json`: the\n * language and the names by ISO 3166-1 code, each a name or a list of names, the first of which is shown.\n */\nexport interface NbCountryNames {\n locale: string\n countries: Record<string, string | string[]>\n}\n\n/** Country names, or a function that loads them, e.g. `() => import('i18n-iso-countries/langs/de.json')`. */\nexport type NbCountryNamesSource = NbCountryNames | (() => Promise<NbCountryNames | { default: NbCountryNames }>)\n\n/** @internal */\nexport const NB_COUNTRY_NAMES = new InjectionToken<NbCountryNamesSource>('Lyra Country Names', {\n factory: () => () => import('i18n-iso-countries/langs/en.json', { with: { type: 'json' } })\n})\n\n/**\n * Sets the language of the country names in the phone input, English by default, for the app or for the components\n * inside the one that provides it:\n *\n * ```ts\n * providers: [provideNbCountryNames(() => import('i18n-iso-countries/langs/de.json'))]\n * ```\n */\nexport function provideNbCountryNames(names: NbCountryNamesSource): Provider[] {\n return [{ provide: NB_COUNTRY_NAMES, useValue: names }]\n}\n\n/** @internal */\nexport async function loadCountryNames(source: NbCountryNamesSource): Promise<NbCountryNames> {\n if (typeof source !== 'function') {\n return source\n }\n const loaded = await source()\n return 'default' in loaded ? loaded.default : loaded\n}\n","import { injectNbTexts, NbLocalize } from '@liquid-js/lyr-core'\n\n/** @internal */\ndeclare const $localize: NbLocalize\n\n/**\n * The texts of the phone input. `provideNbTexts({ phoneInput: { ... } })` changes them, and they're translated with\n * Angular's i18n, as `$localize` messages with ids like `@@nb.phoneInput.invalid`.\n */\nexport interface NbPhoneInputTexts {\n /** Names the number field when it has no `aria-label` or `aria-labelledby`. */\n number: string\n /** Label of the button that picks the country, given the country's name. */\n country: (name: string) => string\n /** Label of the button that picks the country while there's none. */\n noCountry: string\n /** Label and placeholder of the field that searches the countries. */\n search: string\n /** The message of the `nbPhoneNumber` error for a number that isn't valid. */\n invalid: string\n /** The message of the `nbPhoneNumber` error for a number from a country that isn't allowed. */\n otherCountry: string\n}\n\ndeclare module '@liquid-js/lyr-core' {\n interface NbTexts {\n phoneInput: NbPhoneInputTexts\n }\n}\n\n/** The default texts, in the app's language. @internal */\nexport function nbPhoneInputTexts(): NbPhoneInputTexts {\n return {\n number: $localize`:@@nb.phoneInput.number:Phone number`,\n country: (name: string) => $localize`:@@nb.phoneInput.country:Country: ${name}:country:`,\n noCountry: $localize`:@@nb.phoneInput.noCountry:Choose a country`,\n search: $localize`:@@nb.phoneInput.search:Search countries`,\n invalid: $localize`:@@nb.phoneInput.invalid:Enter a valid phone number`,\n otherCountry: $localize`:@@nb.phoneInput.otherCountry:Enter a phone number from one of the allowed countries`\n }\n}\n\n/** @internal */\nexport function injectNbPhoneInputTexts() {\n return injectNbTexts('phoneInput', nbPhoneInputTexts)\n}\n","import { inject, LOCALE_ID } from '@angular/core'\nimport { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms'\nimport { SchemaPath, validate } from '@angular/forms/signals'\nimport { injectNbValidationMessage, NbValidationError, nbValidationParam } from '@liquid-js/lyr-core'\nimport { CountryCode, getCountries, parsePhoneNumberFromString, PhoneNumber } from 'libphonenumber-js'\n\nimport { injectNbPhoneInputTexts, NbPhoneInputTexts, nbPhoneInputTexts } from './texts'\n\n/** The error kind of a phone number that isn't valid or isn't from an allowed country. */\nexport const NB_PHONE_NUMBER_ERROR = 'nbPhoneNumber' as const\n\n/**\n * What's wrong with a phone number: it isn't valid (`invalid`), or it's from a country that isn't allowed (`country`).\n */\nexport type NbPhoneNumberProblem = 'invalid' | 'country'\n\n/**\n * The `nbPhoneNumber` error, the same in signal, reactive and template-driven forms, as Angular gives parse errors:\n * its kind, what's wrong, and its message.\n */\nexport interface NbPhoneNumberError {\n kind: typeof NB_PHONE_NUMBER_ERROR\n problem: NbPhoneNumberProblem\n message: string\n}\n\n/** A value, or a function that gives it, e.g. from another control or a signal. */\nexport type NbPhoneNumberOption<T> = T | (() => T)\n\n/** A message of this validator's errors, or a function that gives it for what's wrong. */\nexport type NbPhoneNumberMessage = string | ((problem: NbPhoneNumberProblem) => string)\n\nexport interface NbPhoneNumberOptions {\n /** The country of numbers without a calling code; the app locale's country by default. */\n country?: NbPhoneNumberOption<CountryCode | undefined>\n /** The countries whose numbers pass, all by default. */\n countries?: NbPhoneNumberOption<ReadonlyArray<CountryCode> | undefined>\n /** The message of its errors, in place of the app's (`provideNbValidation`, `provideNbTexts`). */\n message?: NbPhoneNumberMessage\n}\n\n/** Where the errors take their messages and numbers their country from. @internal */\nexport interface NbPhoneNumberContext {\n texts: () => NbPhoneInputTexts\n /** The message of an error, as `nb-validation-errors` shows it. */\n message: (error: NbValidationError) => string\n country?: CountryCode\n}\n\nconst allCountries = new Set<string>(getCountries())\n\n/** The country of a locale, e.g. `GB` for `en-GB`, or `US` for `en`. @internal */\nexport function localeCountry(locale: string): CountryCode | undefined {\n try {\n const region = new Intl.Locale(locale).maximize().region\n return region && allCountries.has(region) ? (region as CountryCode) : undefined\n } catch {\n return undefined\n }\n}\n\n/** The valid number in a text, in the country unless it has a calling code. @internal */\nexport function parsePhoneNumber(text: string, country?: CountryCode): PhoneNumber | undefined {\n if (!text.trim()) {\n return undefined\n }\n const number = parsePhoneNumberFromString(text, country)\n return number?.isValid() ? number : undefined\n}\n\n/** What's wrong with a value as a phone number, if anything; an empty value is fine. @internal */\nexport function checkPhoneNumber(\n value: unknown,\n country?: CountryCode,\n countries?: ReadonlyArray<CountryCode>\n): NbPhoneNumberProblem | undefined {\n if (value === null || value === undefined || value === '') {\n return undefined\n }\n const number = parsePhoneNumber(String(value), country)\n if (!number) {\n return 'invalid'\n }\n return countries && !(number.country && countries.includes(number.country)) ? 'country' : undefined\n}\n\n/**\n * The error of a problem, with its message: the one given, or the app's, or the phone input's texts'. @internal\n */\nexport function phoneNumberError(\n context: NbPhoneNumberContext,\n problem: NbPhoneNumberProblem,\n message?: NbPhoneNumberMessage\n): NbPhoneNumberError {\n const own = typeof message === 'function' ? message(problem) : message\n if (own !== undefined) {\n return { kind: NB_PHONE_NUMBER_ERROR, problem, message: own }\n }\n const texts = context.texts()\n const error = {\n kind: NB_PHONE_NUMBER_ERROR,\n problem,\n message: problem === 'country' ? texts.otherCountry : texts.invalid\n }\n return { ...error, message: context.message({ kind: NB_PHONE_NUMBER_ERROR, params: error }) }\n}\n\n/** Validates a value with the options, as all the forms do. @internal */\nexport function validatePhoneNumber(\n value: unknown,\n options: NbPhoneNumberOptions,\n context: NbPhoneNumberContext\n): NbPhoneNumberError | undefined {\n const problem = checkPhoneNumber(value, read(options.country) ?? context.country, read(options.countries))\n return problem ? phoneNumberError(context, problem, options.message) : undefined\n}\n\nconst read = <T>(option: NbPhoneNumberOption<T>): T =>\n typeof option === 'function' ? (option as () => T)() : option\n\n/** The texts, the app's messages and the locale's country, from the injection context when there's one. @internal */\nexport function phoneNumberContext(): NbPhoneNumberContext {\n try {\n const texts = injectNbPhoneInputTexts()\n return {\n texts: () => texts(),\n message: injectNbValidationMessage(),\n country: localeCountry(inject(LOCALE_ID))\n }\n } catch {\n const texts = nbPhoneInputTexts()\n return {\n texts: () => texts,\n message: (error) => {\n const message = nbValidationParam(error, 'message')\n return typeof message === 'string' ? message : ''\n }\n }\n }\n}\n\n/**\n * Validates a phone number in reactive forms: an empty value passes, a number that isn't valid or isn't from one of\n * `countries` gets the `nbPhoneNumber` error, with its message. In templates, use the `nbPhoneNumber` attribute.\n *\n * ```ts\n * readonly phone = new FormControl('', nbPhoneNumberValidator({ countries: ['US', 'CA'] }));\n * ```\n *\n * The error's message is `message`, if given, or the one `nb-validation-errors` shows for `nbPhoneNumber`: the app's\n * (`provideNbValidation`, `provideNbTexts({ validation })`), or the phone input's texts, `invalid` or\n * `otherCountry`. Made in an injection context, e.g. in a field initializer, it reads numbers in the app locale's\n * country and has the app's messages; elsewhere, numbers need a calling code unless `country` is given, and the\n * messages are the default ones.\n */\nexport function nbPhoneNumberValidator(options: NbPhoneNumberOptions = {}): ValidatorFn {\n const context = phoneNumberContext()\n return (control: AbstractControl): ValidationErrors | null => {\n const error = validatePhoneNumber(control.value, options, context)\n return error ? { [NB_PHONE_NUMBER_ERROR]: error } : null\n }\n}\n\n/**\n * Validates a phone number in signal forms, as `nbPhoneNumberValidator` does:\n *\n * ```ts\n * readonly form = form(this.model, (path) => {\n * nbPhoneNumber(path.phone, { countries: ['US', 'CA'] });\n * });\n * ```\n */\nexport function nbPhoneNumber(\n path: SchemaPath<string | null | undefined>,\n options: NbPhoneNumberOptions = {}\n): void {\n const context = phoneNumberContext()\n validate(path, ({ value }) => validatePhoneNumber(value(), options, context))\n}\n","import {\n afterNextRender,\n booleanAttribute,\n ChangeDetectionStrategy,\n Component,\n computed,\n effect,\n ElementRef,\n forwardRef,\n inject,\n Injector,\n input,\n linkedSignal,\n LOCALE_ID,\n model,\n OnInit,\n resource,\n signal,\n untracked,\n viewChild,\n ViewEncapsulation\n} from '@angular/core'\nimport {\n ControlValueAccessor,\n NG_VALIDATORS,\n NG_VALUE_ACCESSOR,\n ValidationErrors,\n Validator\n} from '@angular/forms'\nimport {\n injectNbDefaults,\n NbAutocompleteComponent,\n NbAutocompleteDirective,\n NbButtonComponent,\n NbComponentOrCustomStatus,\n NbComponentShape,\n NbComponentSize,\n NbFormFieldComponent,\n NbIconComponent,\n NbInputDirective,\n NbOptionComponent,\n NbPrefixDirective,\n NbValidationDirective\n} from '@liquid-js/lyr-core'\nimport {\n CountryCode,\n getCountries,\n getCountryCallingCode,\n getExampleNumber,\n PhoneNumber\n} from 'libphonenumber-js'\nimport examples from 'libphonenumber-js/mobile/examples'\nimport { FlagComponent, FlagDatabase, FlagDatabaseKey } from 'nxt-flags'\n\nimport { loadCountryNames, NB_COUNTRY_NAMES } from './country-names'\nimport {\n checkPhoneNumber,\n localeCountry,\n NB_PHONE_NUMBER_ERROR,\n parsePhoneNumber,\n phoneNumberContext,\n phoneNumberError\n} from './phone-number.validator'\nimport { injectNbPhoneInputTexts } from './texts'\n\n/** A country in the list. */\ninterface NbPhoneCountry {\n code: CountryCode\n name: string\n callingCode: string\n /** The names, the calling code and the ISO code, as the search compares them. */\n search: string\n}\n\n/**\n * Flags of phone regions that aren't ISO countries: Ascension and Tristan da Cunha are part of Saint Helena, Ascension\n * and Tristan da Cunha (SH), whose flag they show.\n */\nconst flagFallbacks: Partial<Record<CountryCode, FlagDatabaseKey>> = { AC: 'sh', TA: 'sh' }\n\nconst allCountries = new Set<string>(getCountries())\n\n/** Text as the search compares it, without case and accents. */\nconst fold = (text: string) =>\n text\n .normalize('NFD')\n .replace(/\\p{Diacritic}/gu, '')\n .toLocaleLowerCase()\n\n/**\n * A phone number field with the country's flag, which picks the country:\n *\n * ```html\n * <nb-phone-input formControlName=\"phone\" />\n * ```\n *\n * @stacked-example(Showcase, phone-input/phone-input-showcase.component)\n *\n * ### Installation\n *\n * It parses and formats numbers with [`libphonenumber-js`](https://www.npmjs.com/package/libphonenumber-js), names\n * the countries with [`i18n-iso-countries`](https://www.npmjs.com/package/i18n-iso-countries)' language files, and\n * shows flags with [`nxt-flags`](https://www.npmjs.com/package/nxt-flags); install them and import\n * `NbPhoneInputComponent` from `@liquid-js/lyr-extras/phone-input`.\n *\n * ```sh\n * npm install libphonenumber-js i18n-iso-countries nxt-flags\n * ```\n *\n * The flags are images the app serves from `assets/flags`; add them to the assets in `angular.json`:\n *\n * ```json\n * { \"glob\": \"*.svg\", \"input\": \"node_modules/nxt-flags/assets/flags\", \"output\": \"assets/flags\" }\n * ```\n *\n * To serve them from elsewhere, e.g. a CDN, set the path with `provideFlagsPath()` from `nxt-flags`.\n *\n * ### Usage\n *\n * The user types the number in their country's format or with a calling code, e.g. `+44`, which picks the country.\n * The flag button replaces the field with a search of the countries, by name or calling code; Escape goes back.\n * The country is the one of the app's locale (`LOCALE_ID`) until the user or a number picks another, or set it with\n * `country`, which also tells which one is picked. It has the sizes, statuses, shapes and `ghost` look of `nbInput`,\n * and its `placeholder` and `readonly`; the placeholder is an example number of the country by default.\n * @stacked-example(Sizes and statuses, phone-input/phone-input-sizes.component)\n *\n * The value is the number in the `E.164` format, e.g. `+12015550123`, or `null` without one; when the field leaves,\n * it shows the number in its country's format, `(201) 555-0123`. While the text isn't a valid number, the value\n * stays the last valid one, or `null`, and the field has the `nbPhoneNumber` parse error,\n * `{ kind, problem: 'invalid', message }`, as Angular's controls report text they can't parse; so validators never\n * see the text. A number from a country that isn't in `countries`, which the list offers, has the same error with\n * `problem: 'country'`. The errors work in reactive, template-driven and signal forms alike.\n *\n * It works with `formControl`, `formControlName`, `ngModel` and signal forms' `[formField]`.\n * @stacked-example(Validation, phone-input/phone-input-validation.component)\n *\n * ### Validators\n *\n * Phone numbers in other fields, e.g. a text field or data from elsewhere, are checked the same way with validators:\n * `nbPhoneNumberValidator(options)` in reactive forms, the `nbPhoneNumber` attribute in template-driven forms, and\n * `nbPhoneNumber(path, options)` in signal forms. The options are the `country` of numbers without a\n * calling code, the app locale's by default, and the `countries` whose numbers pass, each a value or a function that\n * gives it, and the `message` of the errors, a text or a function of what's wrong, in place of the app's. Their\n * `nbPhoneNumber` error says what's wrong, `invalid` or `country`, with its message.\n *\n * ```ts\n * readonly phone = new FormControl<string | null>(null, nbPhoneNumberValidator({ countries: ['US', 'CA'] }));\n *\n * readonly contactForm = form(this.contact, (path) => {\n * nbPhoneNumber(path.phone, { countries: ['GB'] });\n * });\n * ```\n *\n * ```html\n * <input nbInput type=\"tel\" name=\"support\" ngModel nbPhoneNumber [nbPhoneNumberCountries]=\"['US', 'CA']\" />\n * ```\n *\n * ### Country names\n *\n * The countries are named in English. For other languages, provide the language file of `i18n-iso-countries`, e.g.\n * per locale's build, or loaded by `LOCALE_ID`:\n *\n * ```ts\n * providers: [provideNbCountryNames(() => import('i18n-iso-countries/langs/de.json'))]\n * ```\n *\n * Countries without a name in the file aren't in the list; their numbers are still accepted.\n */\n@Component({\n selector: 'nb-phone-input',\n templateUrl: './phone-input.component.html',\n styleUrl: './phone-input.component.scss',\n encapsulation: ViewEncapsulation.None,\n changeDetection: ChangeDetectionStrategy.OnPush,\n imports: [\n NbFormFieldComponent,\n NbPrefixDirective,\n NbButtonComponent,\n NbIconComponent,\n NbInputDirective,\n NbAutocompleteDirective,\n NbAutocompleteComponent,\n NbOptionComponent,\n FlagComponent\n ],\n providers: [\n { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => NbPhoneInputComponent), multi: true },\n { provide: NG_VALIDATORS, useExisting: forwardRef(() => NbPhoneInputComponent), multi: true }\n ],\n host: {\n 'class': 'nb-phone-input',\n '[class.full-width]': 'fullWidth()'\n }\n})\nexport class NbPhoneInputComponent implements OnInit, ControlValueAccessor, Validator {\n // The app's defaults for fields, which the inputs below start from.\n protected readonly nbDefaults = injectNbDefaults('input')\n\n protected readonly texts = injectNbPhoneInputTexts()\n /** Where its errors take their messages from. */\n protected readonly errorContext = phoneNumberContext()\n protected readonly locale = inject(LOCALE_ID)\n protected readonly injector = inject(Injector)\n protected readonly validation = inject(NbValidationDirective, { self: true, optional: true })\n\n /**\n * The country of the number: the app locale's country at first, unless it's set, then the one the user or the number\n * picks.\n */\n readonly country = model<CountryCode>()\n /** The countries in the list, whose numbers pass, all by default. */\n readonly countries = input<ReadonlyArray<CountryCode>>()\n /** Field size: `tiny`, `small`, `medium` (default), `large` or `giant`. */\n readonly sizeInput = input<NbComponentSize | undefined>(undefined, { alias: 'size' })\n /** The size in use: the input's, the app's default, or 'medium'. */\n readonly size = linkedSignal<NbComponentSize>(() => this.sizeInput() ?? this.nbDefaults().size ?? 'medium')\n /** Field status: `basic` (default), `primary`, `info`, `success`, `warning`, `danger` or `control`. */\n readonly status = input<NbComponentOrCustomStatus>('basic')\n /** Field shape: `rectangle` (default), `semi-round` or `round`. */\n readonly shapeInput = input<NbComponentShape | undefined>(undefined, { alias: 'shape' })\n /** The shape in use: the input's, the app's default, or 'rectangle'. */\n readonly shape = linkedSignal<NbComponentShape>(() => this.shapeInput() ?? this.nbDefaults().shape ?? 'rectangle')\n readonly fullWidth = input(false, { transform: booleanAttribute })\n /** Shows the field without its background and border, as `nbInput`'s `ghost` does. */\n readonly ghost = input(false, { transform: booleanAttribute })\n readonly disabled = input(false, { transform: booleanAttribute })\n /** Lets the user read and select the number, but not change it or its country, as a read-only field. */\n readonly readonly = input(false, { transform: booleanAttribute })\n /** The number field's placeholder; an example number of the country by default. */\n readonly placeholder = input<string>()\n /** The country list's distance from the search field, as other fields' overlays have it. */\n readonly overlayOffset = input(8)\n /** Names the number field when there's no `aria-labelledby`; \"Phone number\" by default. */\n readonly ariaLabel = input<string | undefined>(undefined, { alias: 'aria-label' })\n /** The id of the element that names the number field, e.g. a `label`. */\n readonly ariaLabelledBy = input<string | undefined>(undefined, { alias: 'aria-labelledby' })\n\n /** What labels the field: its own `aria-labelledby` and an `nbLabel` of its `nbValidation`. */\n protected readonly fieldLabelledBy = computed(\n () => [this.ariaLabelledBy(), this.validation?.labelledBy()].filter(Boolean).join(' ') || null\n )\n\n /** The country the number is parsed in, the locale's until `country` has one. */\n readonly selectedCountry = computed(() => this.country() ?? localeCountry(this.locale))\n\n constructor() {\n // The number field is the control: it gets the validation's ARIA, not the host.\n this.validation?.delegateAria()\n // Another list of countries can change whether the number passes.\n effect(() => {\n this.countries()\n untracked(() => this.onValidatorChange())\n })\n }\n\n ngOnInit() {\n // `country` tells the country the field uses from the start, also when the binding gives none.\n if (!this.country()) {\n this.pickCountry(localeCountry(this.locale))\n }\n }\n\n protected readonly isDisabled = linkedSignal(() => this.disabled())\n protected readonly resolvedStatus = computed(() => this.validation?.status() ?? this.status())\n /** The field's buttons are white on colour, with the `control` status, and grey otherwise. */\n protected readonly buttonStatus = computed(() => (this.resolvedStatus() === 'control' ? 'control' : 'basic'))\n /** The number as the field shows it. */\n protected readonly text = signal('')\n /** Whether the text isn't a valid number. */\n protected readonly parseError = signal(false)\n /** Whether the search of the countries replaces the number field. */\n protected readonly picking = signal(false)\n protected readonly query = signal('')\n protected readonly namesSource = inject(NB_COUNTRY_NAMES)\n protected readonly names = resource({ loader: () => loadCountryNames(this.namesSource) })\n\n /** The countries with a name, in the language's order. */\n protected readonly list = computed(() => {\n const names = this.names.hasValue() ? this.names.value().countries : {}\n const only = this.countries()\n const codes = only ? only.filter((code) => allCountries.has(code)) : (getCountries() as CountryCode[])\n const list = new Array<NbPhoneCountry>()\n for (const code of codes) {\n const name = names[code]\n const all = Array.isArray(name) ? name : name ? [name] : []\n if (all.length) {\n const callingCode = getCountryCallingCode(code)\n list.push({ code, name: all[0], callingCode, search: fold(`${all.join(' ')} +${callingCode} ${code}`) })\n }\n }\n const collator = new Intl.Collator(this.locale)\n return list.sort((a, b) => collator.compare(a.name, b.name))\n })\n\n /** The countries the search finds. */\n protected readonly shown = computed(() => {\n const words = fold(this.query()).split(/\\s+/).filter(Boolean)\n return this.list().filter((country) => words.every((word) => country.search.includes(word)))\n })\n\n protected readonly countryName = computed(() => {\n const code = this.selectedCountry()\n return code && (this.list().find((country) => country.code === code)?.name ?? code)\n })\n\n protected readonly countryLabel = computed(() => {\n const name = this.countryName()\n return name ? this.texts().country(name) : this.texts().noCountry\n })\n\n /** An example number of the country, in its format. */\n protected readonly example = computed(() => {\n const code = this.selectedCountry()\n return code ? (getExampleNumber(code, examples)?.formatNational() ?? '') : ''\n })\n\n protected readonly numberField = viewChild.required<ElementRef<HTMLInputElement>>('number')\n protected readonly searchField = viewChild.required<ElementRef<HTMLInputElement>>('search')\n\n /** The value last given to the form, `null` without one. */\n protected value: string | null = null\n protected onChange: (value: string | null) => void = () => {}\n protected onTouched: () => void = () => {}\n protected onValidatorChange: () => void = () => {}\n\n // Untracked, as forms write values from wherever the app sets them, e.g. an effect that mustn't come to depend\n // on the control.\n writeValue(value?: string | null) {\n untracked(() => {\n const text = value ?? ''\n const number = this.parse(text)\n this.pickCountry(number?.country)\n this.text.set(number ? this.display(number) : text)\n this.value = value ?? null\n this.setParseError(false)\n })\n }\n\n registerOnChange(fn: (value: string | null) => void) {\n this.onChange = fn\n }\n\n registerOnTouched(fn: () => void) {\n this.onTouched = fn\n }\n\n registerOnValidatorChange(fn: () => void) {\n this.onValidatorChange = fn\n }\n\n setDisabledState(disabled: boolean) {\n this.isDisabled.set(disabled)\n }\n\n /** The parse error of text that isn't a valid number, or the error of a number from a country not in `countries`. */\n validate(): ValidationErrors | null {\n const problem = this.parseError()\n ? 'invalid'\n : checkPhoneNumber(this.value, this.selectedCountry(), this.countries())\n return problem ? { [NB_PHONE_NUMBER_ERROR]: phoneNumberError(this.errorContext, problem) } : null\n }\n\n /** Moves focus to the number. */\n focus() {\n this.numberField().nativeElement.focus()\n }\n\n /** Sets `country`, when it's another. */\n protected pickCountry(code?: CountryCode) {\n if (code && code !== this.country()) {\n this.country.set(code)\n }\n }\n\n /** The flag of a country, the unknown flag without one. */\n protected flag(code?: CountryCode): FlagDatabaseKey {\n const key = code?.toLowerCase()\n return (code && flagFallbacks[code]) ?? (key && key in FlagDatabase ? (key as FlagDatabaseKey) : 'xx')\n }\n\n protected typed(event: Event) {\n const text = (event.target as HTMLInputElement).value\n this.text.set(text)\n // A number with a calling code picks its country.\n this.pickCountry(this.parse(text)?.country)\n this.update()\n }\n\n protected left() {\n const number = this.parse(this.text())\n if (number) {\n this.text.set(this.display(number))\n }\n this.onTouched()\n }\n\n /** Replaces the number field with the search of the countries, whose list opens. */\n protected pick() {\n if (this.isDisabled() || this.readonly()) {\n return\n }\n const search = this.searchField().nativeElement\n search.value = ''\n this.query.set('')\n this.picking.set(true)\n afterNextRender(() => search.focus(), { injector: this.injector })\n }\n\n protected searched(event: Event) {\n this.query.set((event.target as HTMLInputElement).value)\n }\n\n protected chose(country?: NbPhoneCountry | string) {\n if (country && typeof country !== 'string') {\n this.country.set(country.code)\n // The text is a number of the new country.\n this.update()\n }\n this.stopPicking(true)\n }\n\n /**\n * Escape in the search goes back to the number, the list closing too; it's handled, so nothing else closes, e.g. a\n * dialog around it.\n */\n protected searchEscaped(event: Event) {\n event.preventDefault()\n this.stopPicking(true)\n }\n\n /** Leaving the search touches the control, as leaving an autocomplete's input does. */\n protected searchLeft() {\n this.stopPicking(false)\n this.onTouched()\n }\n\n /**\n * Shows the number field again, and moves focus to it after Escape or picking a country, which can come after the\n * search field lost focus to the list.\n */\n protected stopPicking(focus: boolean) {\n this.picking.set(false)\n if (focus) {\n afterNextRender(() => this.focus(), { injector: this.injector })\n }\n }\n\n /** What the search field shows: the text typed in it, or the name of the country picked. */\n protected readonly displayCountry = (value?: NbPhoneCountry | string) =>\n typeof value === 'string' ? value : (value?.name ?? '')\n\n /** The valid number in the text, in the picked country unless it has a calling code. */\n protected parse(text: string): PhoneNumber | undefined {\n return parsePhoneNumber(text, this.selectedCountry())\n }\n\n /** A number as the field shows it: in its country's format, or international without one. */\n protected display(number: PhoneNumber) {\n return number.country ? number.formatNational() : number.formatInternational()\n }\n\n /**\n * Gives the form the number in the text, when it's another; while the text isn't a valid number, the value stays\n * and the field has the parse error.\n */\n protected update() {\n const text = this.text().trim()\n const number = text ? this.parse(text) : undefined\n this.setParseError(!!text && !number)\n const value = number?.number ?? null\n if ((!text || number) && value !== this.value) {\n this.value = value\n this.onChange(value)\n }\n // Signal forms only check a value accessor's validators again when they're told to, e.g. for a number of a\n // country `countries` leaves out.\n this.onValidatorChange()\n }\n\n protected setParseError(parseError: boolean) {\n if (parseError !== this.parseError()) {\n this.parseError.set(parseError)\n this.onValidatorChange()\n }\n }\n}\n","<nb-form-field class=\"nb-phone-input-number\"\n [style.display]=\"picking() ? 'none' : null\">\n <button nbPrefix\n nbButton\n ghost\n type=\"button\"\n class=\"nb-phone-input-country\"\n [size]=\"size()\"\n [status]=\"buttonStatus()\"\n [disabled]=\"isDisabled() || readonly()\"\n [attr.aria-label]=\"countryLabel()\"\n (click)=\"pick()\">\n <!-- Together in one element, so the button spaces neither as its icon: the arrow sits close to the flag. -->\n <span class=\"nb-phone-input-country-content\">\n <nxt-flag [country]=\"flag(selectedCountry())\"\n size=\"s\" />\n <nb-icon icon=\"chevron-down-outline\"\n pack=\"essentials\"\n aria-hidden=\"true\" />\n </span>\n </button>\n <input #number\n nbInput\n type=\"tel\"\n autocomplete=\"tel\"\n [fieldSize]=\"size()\"\n [status]=\"resolvedStatus()\"\n [shape]=\"shape()\"\n [fullWidth]=\"fullWidth()\"\n [ghost]=\"ghost()\"\n [disabled]=\"isDisabled()\"\n [readOnly]=\"readonly()\"\n [value]=\"text()\"\n [placeholder]=\"placeholder() ?? example()\"\n [attr.aria-label]=\"fieldLabelledBy() ? null : (ariaLabel() ?? texts().number)\"\n [attr.aria-labelledby]=\"fieldLabelledBy()\"\n [attr.aria-required]=\"validation?.ariaRequired()\"\n [attr.aria-invalid]=\"validation?.ariaInvalid()\"\n [attr.aria-describedby]=\"validation?.describedBy()\"\n (input)=\"typed($event)\"\n (blur)=\"left()\" />\n</nb-form-field>\n\n<!-- Stays in the page while it's hidden, so the list it opens still takes a click after it loses focus. -->\n<nb-form-field class=\"nb-phone-input-search\"\n [style.display]=\"picking() ? null : 'none'\">\n <nb-icon nbPrefix\n icon=\"search-outline\"\n pack=\"essentials\"\n aria-hidden=\"true\" />\n <input #search\n nbInput\n type=\"text\"\n autocomplete=\"off\"\n [fieldSize]=\"size()\"\n [status]=\"resolvedStatus()\"\n [shape]=\"shape()\"\n [fullWidth]=\"fullWidth()\"\n [ghost]=\"ghost()\"\n [placeholder]=\"texts().search\"\n [attr.aria-label]=\"texts().search\"\n [nbAutocomplete]=\"countryList\"\n [overlayOffset]=\"overlayOffset()\"\n (input)=\"searched($event)\"\n (keydown.escape)=\"searchEscaped($event)\"\n (blur)=\"searchLeft()\" />\n</nb-form-field>\n\n<nb-autocomplete #countryList\n [size]=\"size()\"\n [handleDisplayFn]=\"displayCountry\"\n (selectedChange)=\"chose($event)\">\n @for (country of shown(); track country.code) {\n <nb-option class=\"nb-phone-input-option\"\n [value]=\"country\">\n <nxt-flag [country]=\"flag(country.code)\"\n size=\"s\" />\n <span class=\"nb-phone-input-name\">{{ country.name }}</span>\n <span class=\"nb-phone-input-calling-code\">+{{ country.callingCode }}</span>\n </nb-option>\n }\n</nb-autocomplete>\n","import { Directive, effect, ElementRef, forwardRef, inject, input } from '@angular/core'\nimport { AbstractControl, NG_VALIDATORS, ValidationErrors, Validator } from '@angular/forms'\nimport type { CountryCode } from 'libphonenumber-js'\n\nimport {\n NB_PHONE_NUMBER_ERROR,\n NbPhoneNumberMessage,\n phoneNumberContext,\n validatePhoneNumber\n} from './phone-number.validator'\n\n/**\n * Validates a phone number in template-driven forms, as `nbPhoneNumberValidator` does in reactive forms:\n *\n * ```html\n * <input nbInput type=\"tel\" name=\"phone\" ngModel nbPhoneNumber [nbPhoneNumberCountries]=\"['US', 'CA']\" />\n * ```\n */\n@Directive({\n selector: '[nbPhoneNumber][ngModel],[nbPhoneNumber][formControl],[nbPhoneNumber][formControlName]',\n providers: [{ provide: NG_VALIDATORS, useExisting: forwardRef(() => NbPhoneNumberValidatorDirective), multi: true }],\n host: {\n // On a plain text field, the number reads left to right from the left in any page, as a tel field's does.\n '[style.text-align]': \"isInput ? 'left' : null\",\n '[style.unicode-bidi]': \"isInput ? 'plaintext' : null\"\n }\n})\nexport class NbPhoneNumberValidatorDirective implements Validator {\n /** The country of numbers without a calling code; the app locale's country by default. */\n readonly country = input<CountryCode>(undefined, { alias: 'nbPhoneNumberCountry' })\n /** The countries whose numbers pass, all by default. */\n readonly countries = input<ReadonlyArray<CountryCode>>(undefined, { alias: 'nbPhoneNumberCountries' })\n /** The message of its errors, in place of the app's. */\n readonly message = input<NbPhoneNumberMessage>(undefined, { alias: 'nbPhoneNumberMessage' })\n\n // By tag name, which a server's DOM also has.\n protected readonly isInput = inject<ElementRef<Element>>(ElementRef).nativeElement.tagName === 'INPUT'\n protected readonly context = phoneNumberContext()\n protected onValidatorChange: () => void = () => {}\n\n constructor() {\n // Other options can change whether the value passes.\n effect(() => {\n this.country()\n this.countries()\n this.message()\n this.onValidatorChange()\n })\n }\n\n validate(control: AbstractControl): ValidationErrors | null {\n const error = validatePhoneNumber(\n control.value,\n { country: this.country(), countries: this.countries(), message: this.message() },\n this.context\n )\n return error ? { [NB_PHONE_NUMBER_ERROR]: error } : null\n }\n\n registerOnValidatorChange(fn: () => void) {\n this.onValidatorChange = fn\n }\n}\n"],"mappings":";;;;;;;;AAgBA,MAAa,mBAAmB,IAAI,eAAqC,sBAAsB,EAC3F,qBAAqB,OAAO,oCAAoC,EAAE,MAAM,EAAE,MAAM,OAAM,EAAE,GAC3F,CAAA;AAUD,SAAgB,sBAAsB,OAA2B;CAC7D,OAAO,CAAC;EAAE,SAAS;EAAkB,UAA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3B;EACJ,CAAA"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "bugs": {
5
5
  "url": "https://github.com/Liquid-JS/lyra/issues"
6
6
  },
7
- "version": "22.0.0-alpha.4",
7
+ "version": "22.0.0-alpha.6",
8
8
  "license": "MIT",
9
9
  "author": "HitkoDev <development@hitko.si>",
10
10
  "type": "module",
@@ -113,8 +113,6 @@
113
113
  }
114
114
  },
115
115
  "sideEffects": false,
116
- "module": "fesm2022/liquid-js-lyr-extras.mjs",
117
- "typings": "types/liquid-js-lyr-extras.d.ts",
118
116
  "exports": {
119
117
  "./package.json": {
120
118
  "default": "./package.json"
@@ -135,6 +133,10 @@
135
133
  "types": "./types/liquid-js-lyr-extras-markdown-editor.d.ts",
136
134
  "default": "./fesm2022/liquid-js-lyr-extras-markdown-editor.mjs"
137
135
  },
136
+ "./markdown-renderer": {
137
+ "types": "./types/liquid-js-lyr-extras-markdown-renderer.d.ts",
138
+ "default": "./fesm2022/liquid-js-lyr-extras-markdown-renderer.mjs"
139
+ },
138
140
  "./markdown-viewer": {
139
141
  "types": "./types/liquid-js-lyr-extras-markdown-viewer.d.ts",
140
142
  "default": "./fesm2022/liquid-js-lyr-extras-markdown-viewer.mjs"
@@ -156,6 +158,8 @@
156
158
  "default": "./fesm2022/liquid-js-lyr-extras-qr-code.mjs"
157
159
  }
158
160
  },
161
+ "module": "fesm2022/liquid-js-lyr-extras.mjs",
162
+ "typings": "types/liquid-js-lyr-extras.d.ts",
159
163
  "dependencies": {
160
164
  "tslib": "^2.9.1"
161
165
  }
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ import * as i0 from "@angular/core";
5
+ import { ElementRef, TemplateRef } from "@angular/core";
6
+ import { FootnoteDefinition, Node, Parent, Root } from "mdast";
7
+ import { RemarkTemplateDirective } from "ngx-remark";
8
+ /** A unified processor that parses markdown, with its plugins, e.g. `remark().use(remarkGfm)`. */
9
+ export interface NbMarkdownProcessor {
10
+ parse(markdown: string): Node;
11
+ runSync(tree: Node): Node;
12
+ }
13
+ /**
14
+ * What `nb-markdown-renderer` and `nb-markdown-viewer` share: the markdown's syntax tree and the templates that render
15
+ * it. They differ in the processor they parse with and in their styles. Each provides its own `RemarkTemplatesService`,
16
+ * so templates put in it, and the templates' own content, find its templates.
17
+ */
18
+ export declare abstract class NbMarkdownRendering {
19
+ /** The markdown to show. */
20
+ readonly markdown: import("@angular/core").InputSignal<string>;
21
+ /**
22
+ * Gives each block of the document, e.g. a paragraph or a list, the direction of its own text (`dir="auto"`), for
23
+ * text in more than one direction; `false` by default.
24
+ */
25
+ readonly autoDirection: import("@angular/core").InputSignalWithTransform<boolean, unknown>;
26
+ /** The markdown's syntax tree, as its templates render it. */
27
+ readonly tree: import("@angular/core").Signal<Root>;
28
+ protected readonly id: string;
29
+ protected readonly texts: import("@angular/core").Signal<import("@liquid-js/lyr-extras/markdown-renderer").NbMarkdownViewerTexts>;
30
+ protected readonly htmlElements: Set<string>;
31
+ protected readonly blockParents: Set<string>;
32
+ protected readonly element: ElementRef<HTMLElement>;
33
+ /** Whether the app loads highlight.js for code, the same on the server and in the browser. */
34
+ protected readonly highlighting: boolean;
35
+ protected readonly defaultTemplates: import("@angular/core").Signal<readonly RemarkTemplateDirective[]>;
36
+ protected readonly customTemplates: import("@angular/core").Signal<readonly RemarkTemplateDirective[]>;
37
+ protected readonly fallback: import("@angular/core").Signal<TemplateRef<unknown>>;
38
+ constructor();
39
+ /** The processor the markdown is parsed with. */
40
+ protected abstract parser(): NbMarkdownProcessor;
41
+ /** `auto` for a block of the document, with `autoDirection`, which a block in a quote or a list shares. */
42
+ protected direction(parent: Node): "auto" | null;
43
+ protected footnoteId(identifier: string, reference?: boolean): string;
44
+ /** Moves to a footnote in the page, whose address the document's base would otherwise change. */
45
+ protected showFootnote(event: Event, id: string): void;
46
+ static ɵfac: i0.ɵɵFactoryDeclaration<NbMarkdownRendering, never>;
47
+ static ɵdir: i0.ɵɵDirectiveDeclaration<NbMarkdownRendering, never, never, {
48
+ "markdown": {
49
+ "alias": "markdown";
50
+ "required": false;
51
+ "isSignal": true;
52
+ };
53
+ "autoDirection": {
54
+ "alias": "autoDirection";
55
+ "required": false;
56
+ "isSignal": true;
57
+ };
58
+ }, {}, ["customTemplates"], never, true, never>;
59
+ }
60
+ /**
61
+ * Renders markdown with a processor of the app's, and no styles of its own, for an app that styles its content itself:
62
+ *
63
+ * ```html
64
+ * <nb-markdown-renderer [markdown]="text" [processor]="processor" />
65
+ * ```
66
+ *
67
+ * @stacked-example(Renderer, markdown/markdown-renderer.component)
68
+ *
69
+ * It renders as `nb-markdown-viewer` does, with the same templates, which templates of the app's replace the same way,
70
+ * and the same `autoDirection`, footnotes and code highlighting. Unlike the viewer, it doesn't load `remark` or
71
+ * `remark-smartypants` for a default processor, nor the editor's content styles: the processor is the app's, and the
72
+ * content is styled by the app, in the element with class `uf-contents`.
73
+ *
74
+ * ```sh
75
+ * npm install ngx-remark nxt-highlightjs highlight.js
76
+ * ```
77
+ *
78
+ * Import `NbMarkdownRendererComponent` from `@liquid-js/lyr-extras/markdown-renderer`, and give it a processor that
79
+ * parses markdown, e.g. with `unified` and `remark-parse`, which `ngx-remark` uses too:
80
+ *
81
+ * ```ts
82
+ * import { unified } from 'unified';
83
+ * import remarkParse from 'remark-parse';
84
+ * import remarkGfm from 'remark-gfm';
85
+ *
86
+ * readonly processor = unified().use(remarkParse).use(remarkGfm).freeze();
87
+ * ```
88
+ */
89
+ export declare class NbMarkdownRendererComponent extends NbMarkdownRendering {
90
+ /** Parses the markdown, with the plugins the app uses. */
91
+ readonly processor: import("@angular/core").InputSignal<NbMarkdownProcessor>;
92
+ protected parser(): NbMarkdownProcessor;
93
+ static ɵfac: i0.ɵɵFactoryDeclaration<NbMarkdownRendererComponent, never>;
94
+ static ɵcmp: i0.ɵɵComponentDeclaration<NbMarkdownRendererComponent, "nb-markdown-renderer", never, {
95
+ "processor": {
96
+ "alias": "processor";
97
+ "required": true;
98
+ "isSignal": true;
99
+ };
100
+ }, {}, never, never, true, never>;
101
+ }
102
+ /** An inline HTML element of the markdown, e.g. `<kbd>Ctrl</kbd>`, with the markdown between its tags. */
103
+ interface NbMarkdownHtmlElement extends Parent {
104
+ type: 'nbHtmlElement';
105
+ tagName: string;
106
+ }
107
+ /** A link from a footnote back to where the text refers to it, at the end of the footnote. */
108
+ interface NbMarkdownFootnoteBack extends Node {
109
+ type: 'nbFootnoteBack';
110
+ identifier: string;
111
+ }
112
+ /** The footnotes, at the end of the document. */
113
+ interface NbMarkdownFootnotes extends Parent {
114
+ type: 'nbFootnotes';
115
+ children: FootnoteDefinition[];
116
+ }
117
+ declare module 'mdast' {
118
+ interface PhrasingContentMap {
119
+ nbHtmlElement: NbMarkdownHtmlElement;
120
+ nbFootnoteBack: NbMarkdownFootnoteBack;
121
+ }
122
+ interface RootContentMap {
123
+ nbHtmlElement: NbMarkdownHtmlElement;
124
+ nbFootnoteBack: NbMarkdownFootnoteBack;
125
+ nbFootnotes: NbMarkdownFootnotes;
126
+ }
127
+ }
128
+ /**
129
+ * The texts of the markdown viewer. `provideNbTexts({ markdownViewer: { ... } })` changes them, and they're translated
130
+ * with Angular's i18n, as `$localize` messages with ids like `@@nb.markdownViewer.footnotes`.
131
+ */
132
+ interface NbMarkdownViewerTexts {
133
+ /** Names the footnotes at the end of the text. */
134
+ footnotes: string;
135
+ /** Names the link at the end of a footnote back to where the text refers to it. */
136
+ backToText: string;
137
+ }
138
+ declare module '@liquid-js/lyr-core' {
139
+ interface NbTexts {
140
+ markdownViewer: NbMarkdownViewerTexts;
141
+ }
142
+ }
143
+ export type { NbMarkdownFootnoteBack, NbMarkdownFootnotes, NbMarkdownHtmlElement, NbMarkdownViewerTexts };
@@ -1,15 +1,8 @@
1
1
  /**
2
2
  * Generated bundle index. Do not edit.
3
3
  */
4
+ import { NbMarkdownFootnoteBack, NbMarkdownFootnotes, NbMarkdownHtmlElement, NbMarkdownProcessor, NbMarkdownProcessor as NbMarkdownProcessor$1, NbMarkdownRendering, NbMarkdownViewerTexts } from "@liquid-js/lyr-extras/markdown-renderer";
4
5
  import * as i0 from "@angular/core";
5
- import { ElementRef, TemplateRef } from "@angular/core";
6
- import { FootnoteDefinition, Node, Parent, Root } from "mdast";
7
- import { RemarkTemplateDirective } from "ngx-remark";
8
- /** A unified processor that parses markdown, with its plugins, e.g. `remark().use(remarkGfm)`. */
9
- export interface NbMarkdownProcessor {
10
- parse(markdown: string): Node;
11
- runSync(tree: Node): Node;
12
- }
13
6
  /**
14
7
  * Shows markdown, in the theme's text styles:
15
8
  *
@@ -63,6 +56,8 @@ export interface NbMarkdownProcessor {
63
56
  * they need `dir="auto"` themselves.
64
57
  *
65
58
  * `processor` replaces the parser, e.g. to add remark plugins, whose new types of nodes need templates of their own.
59
+ * An app with a processor and content styles of its own can use `nb-markdown-renderer` instead, which renders the same
60
+ * way without loading the default processor's packages or these styles.
66
61
  *
67
62
  * ### Code highlighting
68
63
  *
@@ -83,92 +78,17 @@ export interface NbMarkdownProcessor {
83
78
  * Code in other languages, or without one, shows as plain text. The server waits for highlight.js, so a prerendered
84
79
  * page has highlighted code. `nb-markdown-editor` highlights its preview and WYSIWYG code the same way.
85
80
  */
86
- export declare class NbMarkdownViewerComponent {
87
- /** The markdown to show. */
88
- readonly markdown: import("@angular/core").InputSignal<string>;
81
+ export declare class NbMarkdownViewerComponent extends NbMarkdownRendering {
89
82
  /** Parses the markdown, `remark().use(remarkGfm).use(remarkSmartypants, { dashes: 'oldschool' })` by default. */
90
- readonly processor: import("@angular/core").InputSignal<NbMarkdownProcessor | undefined>;
91
- /**
92
- * Gives each block of the document, e.g. a paragraph or a list, the direction of its own text (`dir="auto"`), for
93
- * text in more than one direction; `false` by default.
94
- */
95
- readonly autoDirection: import("@angular/core").InputSignalWithTransform<boolean, unknown>;
96
- /** The markdown's syntax tree, as its templates render it. */
97
- readonly tree: import("@angular/core").Signal<Root>;
98
- protected readonly id: string;
99
- protected readonly texts: import("@angular/core").Signal<import("@liquid-js/lyr-extras/markdown-viewer").NbMarkdownViewerTexts>;
100
- protected readonly htmlElements: Set<string>;
101
- protected readonly blockParents: Set<string>;
102
- protected readonly element: ElementRef<HTMLElement>;
103
- /** Whether the app loads highlight.js for code, the same on the server and in the browser. */
104
- protected readonly highlighting: boolean;
105
- protected readonly defaultTemplates: import("@angular/core").Signal<readonly RemarkTemplateDirective[]>;
106
- protected readonly customTemplates: import("@angular/core").Signal<readonly RemarkTemplateDirective[]>;
107
- protected readonly fallback: import("@angular/core").Signal<TemplateRef<unknown>>;
108
- constructor();
109
- /** `auto` for a block of the document, with `autoDirection`, which a block in a quote or a list shares. */
110
- protected direction(parent: Node): "auto" | null;
111
- protected footnoteId(identifier: string, reference?: boolean): string;
112
- /** Moves to a footnote in the page, whose address the document's base would otherwise change. */
113
- protected showFootnote(event: Event, id: string): void;
83
+ readonly processor: import("@angular/core").InputSignal<NbMarkdownProcessor$1 | undefined>;
84
+ protected parser(): NbMarkdownProcessor$1;
114
85
  static ɵfac: i0.ɵɵFactoryDeclaration<NbMarkdownViewerComponent, never>;
115
86
  static ɵcmp: i0.ɵɵComponentDeclaration<NbMarkdownViewerComponent, "nb-markdown-viewer", never, {
116
- "markdown": {
117
- "alias": "markdown";
118
- "required": false;
119
- "isSignal": true;
120
- };
121
87
  "processor": {
122
88
  "alias": "processor";
123
89
  "required": false;
124
90
  "isSignal": true;
125
91
  };
126
- "autoDirection": {
127
- "alias": "autoDirection";
128
- "required": false;
129
- "isSignal": true;
130
- };
131
- }, {}, ["customTemplates"], never, true, never>;
132
- }
133
- /** An inline HTML element of the markdown, e.g. `<kbd>Ctrl</kbd>`, with the markdown between its tags. */
134
- interface NbMarkdownHtmlElement extends Parent {
135
- type: 'nbHtmlElement';
136
- tagName: string;
137
- }
138
- /** A link from a footnote back to where the text refers to it, at the end of the footnote. */
139
- interface NbMarkdownFootnoteBack extends Node {
140
- type: 'nbFootnoteBack';
141
- identifier: string;
142
- }
143
- /** The footnotes, at the end of the document. */
144
- interface NbMarkdownFootnotes extends Parent {
145
- type: 'nbFootnotes';
146
- children: FootnoteDefinition[];
147
- }
148
- declare module 'mdast' {
149
- interface PhrasingContentMap {
150
- nbHtmlElement: NbMarkdownHtmlElement;
151
- nbFootnoteBack: NbMarkdownFootnoteBack;
152
- }
153
- interface RootContentMap {
154
- nbHtmlElement: NbMarkdownHtmlElement;
155
- nbFootnoteBack: NbMarkdownFootnoteBack;
156
- nbFootnotes: NbMarkdownFootnotes;
157
- }
158
- }
159
- /**
160
- * The texts of the markdown viewer. `provideNbTexts({ markdownViewer: { ... } })` changes them, and they're translated
161
- * with Angular's i18n, as `$localize` messages with ids like `@@nb.markdownViewer.footnotes`.
162
- */
163
- interface NbMarkdownViewerTexts {
164
- /** Names the footnotes at the end of the text. */
165
- footnotes: string;
166
- /** Names the link at the end of a footnote back to where the text refers to it. */
167
- backToText: string;
168
- }
169
- declare module '@liquid-js/lyr-core' {
170
- interface NbTexts {
171
- markdownViewer: NbMarkdownViewerTexts;
172
- }
92
+ }, {}, never, never, true, never>;
173
93
  }
174
- export type { NbMarkdownFootnoteBack, NbMarkdownFootnotes, NbMarkdownHtmlElement, NbMarkdownViewerTexts };
94
+ export type { NbMarkdownFootnoteBack, NbMarkdownFootnotes, NbMarkdownHtmlElement, NbMarkdownProcessor, NbMarkdownViewerTexts };