@angular/material
Version:
Angular Material
1 lines • 4.23 kB
Source Map (JSON)
{"version":3,"file":"_error-state-chunk.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/material/core/common-behaviors/error-state.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {AbstractControl, FormGroupDirective, NgControl, NgForm} from '@angular/forms';\nimport {Subject} from 'rxjs';\nimport {ErrorStateMatcher as _ErrorStateMatcher} from '../error/error-options';\nimport {FormField} from '@angular/forms/signals';\nimport {isSignal} from '@angular/core';\n\n// Declare ErrorStateMatcher as an interface to have compatibility with Closure Compiler.\ninterface ErrorStateMatcher extends _ErrorStateMatcher {}\n\n/**\n * Class that tracks the error state of a component.\n * @docs-private\n */\nexport class _ErrorStateTracker {\n /** Whether the tracker is currently in an error state. */\n errorState = false;\n\n /** User-defined matcher for the error state. */\n matcher!: ErrorStateMatcher;\n\n /** Reactive or template-based control directive. */\n ngControl: NgControl | null;\n\n /** Signal-based form field directive. */\n formField: FormField<unknown> | null;\n\n constructor(\n private _defaultMatcher: ErrorStateMatcher | null,\n directive: NgControl | FormField<unknown> | null,\n private _parentFormGroup: FormGroupDirective | null,\n private _parentForm: NgForm | null,\n private _stateChanges: Subject<void>,\n ) {\n if (!directive) {\n this.ngControl = this.formField = null;\n } else if (\n isSignal((directive as {field?: unknown}).field) &&\n // Avoid false positives for interop controls.\n !(directive as {updateValueAndValidity?: unknown}).updateValueAndValidity\n ) {\n this.formField = directive as FormField<unknown>;\n this.ngControl = null;\n } else {\n this.formField = null;\n this.ngControl = directive as NgControl;\n }\n }\n\n /** Updates the error state based on the provided error state matcher. */\n updateErrorState() {\n const oldState = this.errorState;\n const newState = this._getCurrentErrorState(this.matcher || this._defaultMatcher);\n\n if (newState !== oldState) {\n this.errorState = newState;\n this._stateChanges.next();\n }\n }\n\n private _getCurrentErrorState(matcher: ErrorStateMatcher | undefined): boolean {\n if (this.formField && matcher?.isSignalErrorState) {\n return matcher.isSignalErrorState(this.formField.field()) ?? false;\n }\n\n const parent = this._parentFormGroup || this._parentForm;\n const control = this.ngControl ? (this.ngControl.control as AbstractControl) : null;\n return matcher?.isErrorState(control, parent) ?? false;\n }\n}\n"],"names":[],"mappings":";;MAqBa,kBAAkB,CAAA;EAcnB,eAAA;EAEA,gBAAA;EACA,WAAA;EACA,aAAA;AAhBV,EAAA,UAAU,GAAG,KAAK;EAGlB,OAAO;EAGP,SAAS;EAGT,SAAS;EAET,WAAA,CACU,eAAyC,EACjD,SAAgD,EACxC,gBAA2C,EAC3C,WAA0B,EAC1B,aAA4B,EAAA;IAJ5B,IAAA,CAAA,eAAe,GAAf,eAAe;IAEf,IAAA,CAAA,gBAAgB,GAAhB,gBAAgB;IAChB,IAAA,CAAA,WAAW,GAAX,WAAW;IACX,IAAA,CAAA,aAAa,GAAb,aAAa;IAErB,IAAI,CAAC,SAAS,EAAE;AACd,MAAA,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI;AACxC,IAAA,CAAA,MAAO,IACL,QAAQ,CAAE,SAA+B,CAAC,KAAK,CAAC,IAEhD,CAAE,SAAgD,CAAC,sBAAsB,EACzE;MACA,IAAI,CAAC,SAAS,GAAG,SAA+B;MAChD,IAAI,CAAC,SAAS,GAAG,IAAI;AACvB,IAAA,CAAA,MAAO;MACL,IAAI,CAAC,SAAS,GAAG,IAAI;MACrB,IAAI,CAAC,SAAS,GAAG,SAAsB;AACzC,IAAA;AACF,EAAA;AAGA,EAAA,gBAAgB,GAAA;AACd,IAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU;AAChC,IAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,eAAe,CAAC;IAEjF,IAAI,QAAQ,KAAK,QAAQ,EAAE;MACzB,IAAI,CAAC,UAAU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