/** * @license Angular v17.1.3 * (c) 2010-2022 Google LLC. https://angular.io/ * License: MIT */ import * as i0 from '@angular/core'; import { Directive, InjectionToken, forwardRef, Optional, Inject, ɵisPromise, ɵisSubscribable, ɵRuntimeError, Self, EventEmitter, Input, Host, SkipSelf, booleanAttribute, ChangeDetectorRef, Output, Injectable, inject, NgModule, Version } from '@angular/core'; import { ɵgetDOM } from '@angular/common'; import { from, forkJoin } from 'rxjs'; import { map } from 'rxjs/operators'; /** * Base class for all ControlValueAccessor classes defined in Forms package. * Contains common logic and utility functions. * * Note: this is an *internal-only* class and should not be extended or used directly in * applications code. */ class BaseControlValueAccessor { constructor(_renderer, _elementRef) { this._renderer = _renderer; this._elementRef = _elementRef; /** * The registered callback function called when a change or input event occurs on the input * element. * @nodoc */ this.onChange = (_) => { }; /** * The registered callback function called when a blur event occurs on the input element. * @nodoc */ this.onTouched = () => { }; } /** * Helper method that sets a property on a target element using the current Renderer * implementation. * @nodoc */ setProperty(key, value) { this._renderer.setProperty(this._elementRef.nativeElement, key, value); } /** * Registers a function called when the control is touched. * @nodoc */ registerOnTouched(fn) { this.onTouched = fn; } /** * Registers a function called when the control value changes. * @nodoc */ registerOnChange(fn) { this.onChange = fn; } /** * Sets the "disabled" property on the range input element. * @nodoc */ setDisabledState(isDisabled) { this.setProperty('disabled', isDisabled); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.3", ngImport: i0, type: BaseControlValueAccessor, deps: [{ token: i0.Renderer2 }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.1.3", type: BaseControlValueAccessor, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.3", ngImport: i0, type: BaseControlValueAccessor, decorators: [{ type: Directive }], ctorParameters: () => [{ type: i0.Renderer2 }, { type: i0.ElementRef }] }); /** * Base class for all built-in ControlValueAccessor classes (except DefaultValueAccessor, which is * used in case no other CVAs can be found). We use this class to distinguish between default CVA, * built-in CVAs and custom CVAs, so that Forms logic can recognize built-in CVAs and treat custom * ones with higher priority (when both built-in and custom CVAs are present). * * Note: this is an *internal-only* class and should not be extended or used directly in * applications code. */ class BuiltInControlValueAccessor extends BaseControlValueAccessor { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.3", ngImport: i0, type: BuiltInControlValueAccessor, deps: null, target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.1.3", type: BuiltInControlValueAccessor, usesInheritance: true, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.3", ngImport: i0, type: BuiltInControlValueAccessor, decorators: [{ type: Directive }] }); /** * Used to provide a `ControlValueAccessor` for form controls. * * See `DefaultValueAccessor` for how to implement one. * * @publicApi */ const NG_VALUE_ACCESSOR = new InjectionToken(ngDevMode ? 'NgValueAccessor' : ''); const CHECKBOX_VALUE_ACCESSOR = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => CheckboxControlValueAccessor), multi: true, }; /** * @description * A `ControlValueAccessor` for writing a value and listening to changes on a checkbox input * element. * * @usageNotes * * ### Using a checkbox with a reactive form. * * The following example shows how to use a checkbox with a reactive form. * * ```ts * const rememberLoginControl = new FormControl(); * ``` * * ``` * * ``` * * @ngModule ReactiveFormsModule * @ngModule FormsModule * @publicApi */ class CheckboxControlValueAccessor extends BuiltInControlValueAccessor { /** * Sets the "checked" property on the input element. * @nodoc */ writeValue(value) { this.setProperty('checked', value); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.3", ngImport: i0, type: CheckboxControlValueAccessor, deps: null, target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.1.3", type: CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]", host: { listeners: { "change": "onChange($event.target.checked)", "blur": "onTouched()" } }, providers: [CHECKBOX_VALUE_ACCESSOR], usesInheritance: true, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.3", ngImport: i0, type: CheckboxControlValueAccessor, decorators: [{ type: Directive, args: [{ selector: 'input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]', host: { '(change)': 'onChange($event.target.checked)', '(blur)': 'onTouched()' }, providers: [CHECKBOX_VALUE_ACCESSOR] }] }] }); const DEFAULT_VALUE_ACCESSOR = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => DefaultValueAccessor), multi: true }; /** * We must check whether the agent is Android because composition events * behave differently between iOS and Android. */ function _isAndroid() { const userAgent = ɵgetDOM() ? ɵgetDOM().getUserAgent() : ''; return /android (\d+)/.test(userAgent.toLowerCase()); } /** * @description * Provide this token to control if form directives buffer IME input until * the "compositionend" event occurs. * @publicApi */ const COMPOSITION_BUFFER_MODE = new InjectionToken(ngDevMode ? 'CompositionEventMode' : ''); /** * The default `ControlValueAccessor` for writing a value and listening to changes on input * elements. The accessor is used by the `FormControlDirective`, `FormControlName`, and * `NgModel` directives. * * {@searchKeywords ngDefaultControl} * * @usageNotes * * ### Using the default value accessor * * The following example shows how to use an input element that activates the default value accessor * (in this case, a text field). * * ```ts * const firstNameControl = new FormControl(); * ``` * * ``` * * ``` * * This value accessor is used by default for `` and `