{"version":3,"file":"ngx-t-forms-input-custom.component-s1ryJQy4.mjs","sources":["../../../projects/ngx-t-forms/src/lib/components/t-form-input/elements/basic-input-input-element/core/input-custom/input-custom.component.ts","../../../projects/ngx-t-forms/src/lib/components/t-form-input/elements/basic-input-input-element/core/input-custom/input-custom.component.html"],"sourcesContent":["import {\r\n  AfterViewInit,\r\n  ChangeDetectionStrategy,\r\n  Component,\r\n  DestroyRef,\r\n  ElementRef,\r\n  Input,\r\n  OnInit,\r\n  Optional,\r\n  Self,\r\n  ViewEncapsulation,\r\n  forwardRef,\r\n  inject,\r\n  viewChild,\r\n} from '@angular/core';\r\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\r\nimport { NgControl } from '@angular/forms';\r\nimport { MatFormFieldControl } from '@angular/material/form-field';\r\nimport { MatInputModule } from '@angular/material/input';\r\nimport { ITowerStepColumn } from 'ngx-t-forms-types';\r\nimport { Subject, debounceTime } from 'rxjs';\r\n\r\nimport {\r\n  BaseCustomInput,\r\n  BaseCustomInputConfig,\r\n} from '../../../../../../services/core/t-input-controller/functions/baseCustomInput';\r\n\r\nconst customInputConfig: BaseCustomInputConfig = {\r\n  controlType: 'lib-input-custom',\r\n  nextId: 0,\r\n};\r\n\r\n@Component({\r\n  selector: 'lib-input-custom',\r\n  imports: [MatInputModule],\r\n  templateUrl: './input-custom.component.html',\r\n  styleUrl: './input-custom.component.css',\r\n  changeDetection: ChangeDetectionStrategy.OnPush,\r\n  encapsulation: ViewEncapsulation.Emulated,\r\n  host: {\r\n    '[class.floating]': 'shouldLabelFloat',\r\n    '[id]': 'id',\r\n  },\r\n  providers: [\r\n    {\r\n      provide: MatFormFieldControl,\r\n      //:Note\r\n      useExisting: forwardRef(() => InputCustomComponent),\r\n    },\r\n  ],\r\n})\r\nexport class InputCustomComponent\r\n  extends BaseCustomInput<string | number | Date>\r\n  implements OnInit, AfterViewInit\r\n{\r\n  // Kept as @Input() because BaseCustomInput exposes `required`/`disabled`/`placeholder`\r\n  // as setter-backed @Input()s tied to MatFormFieldControl `stateChanges`. Keeping\r\n  // `inputConfig` as a classic @Input keeps the imperative-setter ergonomic consistent\r\n  // with the base class and avoids mixing signal + setter inputs on one component.\r\n  @Input() inputConfig!: ITowerStepColumn;\r\n\r\n  readonly #destroyRef = inject(DestroyRef);\r\n  readonly #debounceTimeMs = 300;\r\n  readonly #valueSubject = new Subject<string>();\r\n\r\n  // The native input is left uncontrolled while the user types: binding the\r\n  // (debounced, therefore lagging) model to `[value]` made Angular overwrite the\r\n  // DOM mid-keystroke and drop characters during fast typing. We instead push the\r\n  // model to the DOM only on external writes (writeValue) — never while typing.\r\n  // TS `private` (not ES `#private`): Angular signal queries cannot sit on an ES-private field.\r\n  private readonly inputEl = viewChild<ElementRef<HTMLInputElement>>('inputEl');\r\n\r\n  constructor(\r\n    @Optional() @Self() ngControl: NgControl,\r\n    elementRef: ElementRef<HTMLElement>,\r\n  ) {\r\n    super(ngControl, elementRef, customInputConfig);\r\n  }\r\n\r\n  override get empty(): boolean {\r\n    const n = this.value;\r\n    // Check for null, undefined, or empty string, but allow 0\r\n    return n === null || n === undefined || n === '';\r\n  }\r\n\r\n  override get shouldLabelFloat(): boolean {\r\n    return true;\r\n  }\r\n\r\n  ngOnInit(): void {\r\n    this.#valueSubject\r\n      .pipe(debounceTime(this.#debounceTimeMs), takeUntilDestroyed(this.#destroyRef))\r\n      .subscribe((next) => {\r\n        // The base `value` setter guards on equality and fires onChange + stateChanges.\r\n        // Only the (heavier) form propagation + validation is debounced — never the display.\r\n        this.value = next;\r\n      });\r\n  }\r\n\r\n  ngAfterViewInit(): void {\r\n    // Reflect any value the form set before the view existed (initial bind / patch).\r\n    this.#syncInputFromModel();\r\n  }\r\n\r\n  override writeValue(value: string | number | Date): void {\r\n    super.writeValue(value);\r\n    // External model change (patchValue / reset) — push it to the DOM. This never\r\n    // runs in response to the user's own typing, so it can't clobber the cursor.\r\n    this.#syncInputFromModel();\r\n  }\r\n\r\n  protected onInputChange($event: Event): void {\r\n    const next = ($event.target as HTMLInputElement | null)?.value ?? '';\r\n    this.#valueSubject.next(next);\r\n  }\r\n\r\n  #syncInputFromModel(): void {\r\n    const el = this.inputEl()?.nativeElement;\r\n    if (!el) {\r\n      return;\r\n    }\r\n    const v = this.value;\r\n    el.value = v === null || v === undefined ? '' : String(v);\r\n  }\r\n\r\n  protected onInputBlur($event: FocusEvent): void {\r\n    this.touched = true; // Mark as touched on blur\r\n    this.onTouched();\r\n    this.blur.emit($event);\r\n  }\r\n}\r\n","@if (inputConfig) {\r\n  <input matInput\r\n    #inputEl\r\n    [readonly]=\"inputConfig.readonly || inputConfig.disabled\"\r\n    (blur)=\"onInputBlur($event)\"\r\n    [pattern]=\"inputConfig.pattern || ''\"\r\n    [required]=\"inputConfig.required\"\r\n    [attr.maxlength]=\"inputConfig.maxLength\"\r\n    [type]=\"inputConfig.type || 'text'\"\r\n    (input)=\"onInputChange($event)\"\r\n    [attr.minlength]=\"inputConfig.minLength\"\r\n    [autocomplete]=\"inputConfig.autocomplete\"\r\n    [min]=\"inputConfig.min\"\r\n    [max]=\"inputConfig.max\" />\r\n}\r\n"],"names":[],"mappings":";;;;;;;;;;AA2BA,MAAM,iBAAiB,GAA0B;AAC/C,IAAA,WAAW,EAAE,kBAAkB;AAC/B,IAAA,MAAM,EAAE,CAAC;CACV;AAqBK,MAAO,oBACX,SAAQ,eAAuC,CAAA;AAStC,IAAA,WAAW;AACX,IAAA,eAAe;AACf,IAAA,aAAa;IAStB,WAAA,CACsB,SAAoB,EACxC,UAAmC,EAAA;AAEnC,QAAA,KAAK,CAAC,SAAS,EAAE,UAAU,EAAE,iBAAiB,CAAC;AAfxC,QAAA,IAAA,CAAA,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;QAChC,IAAA,CAAA,eAAe,GAAG,GAAG;AACrB,QAAA,IAAA,CAAA,aAAa,GAAG,IAAI,OAAO,EAAU;;;;;;AAO7B,QAAA,IAAA,CAAA,OAAO,GAAG,SAAS,CAA+B,SA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