/** * @license Angular v12.2.13 * (c) 2010-2021 Google LLC. https://angular.io/ * License: MIT */ import { Directive, Renderer2, ElementRef, InjectionToken, forwardRef, Optional, Inject, ɵisPromise, ɵisObservable, Self, EventEmitter, Input, Host, SkipSelf, Output, NgModule, ɵɵdefineInjectable, Injectable, Injector, Version } from '@angular/core'; import { ɵgetDOM } from '@angular/common'; import { from, forkJoin } from 'rxjs'; import { map } from 'rxjs/operators'; /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * 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); } } BaseControlValueAccessor.decorators = [ { type: Directive } ]; BaseControlValueAccessor.ctorParameters = () => [ { type: Renderer2 }, { type: 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 { } 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('NgValueAccessor'); /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ 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); } } 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] },] } ]; /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ 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('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 `