{"version":3,"file":"tableau-ui-angular-form-field.mjs","sources":["../../../projects/component-library/form-field/src/form-field.component.ts","../../../projects/component-library/form-field/src/form-field.component.html","../../../projects/component-library/form-field/src/tableau-ui-form-field.module.ts","../../../projects/component-library/form-field/src/tableau-ui-angular-form-field.ts"],"sourcesContent":["import type { AfterContentInit, AfterViewInit, OnDestroy, Signal } from '@angular/core';\nimport { ChangeDetectionStrategy, Component, contentChild, ElementRef, inject, input, Renderer2, signal, viewChild } from '@angular/core';\nimport { ErrorComponent, HintComponent, LabelComponent, PrefixComponent, SuffixComponent } from 'tableau-ui-angular/common';\nimport { generateRandomString } from 'tableau-ui-angular/utils';\n\n@Component({\n  selector: 'tab-form-field',\n  standalone: false,\n  templateUrl: './form-field.component.html',\n  styleUrl: './form-field.component.scss',\n  changeDetection: ChangeDetectionStrategy.OnPush,\n  host: {\n    '[class.disabled]': '$inputDisabled()',\n    '[attr.aria-disabled]': '$inputDisabled()',\n    'style.display': 'grid',\n  },\n})\nexport class FormFieldComponent implements AfterContentInit, AfterViewInit, OnDestroy {\n  private readonly inputContainerSelector = 'input,textarea,tab-single-select,tab-multi-select,tab-list-single-select,tab-list-multi-select';\n  protected readonly id = generateRandomString(16);\n  readonly $style = input<string>(undefined, {\n    alias: 'style',\n  });\n  // nullable Signal type needs to be set explicitly -> ng-packagr strips nullability\n  protected readonly $hintElement: Signal<HintComponent | undefined> = contentChild(HintComponent);\n  // nullable Signal type needs to be set explicitly -> ng-packagr strips nullability\n  protected readonly $errorElement: Signal<ErrorComponent | undefined> = contentChild(ErrorComponent);\n  // nullable Signal type needs to be set explicitly -> ng-packagr strips nullability\n  protected readonly $labelElement: Signal<LabelComponent | undefined> = contentChild(LabelComponent);\n  // nullable Signal type needs to be set explicitly -> ng-packagr strips nullability\n  protected readonly $prefixElement: Signal<PrefixComponent | undefined> = contentChild(PrefixComponent);\n  // nullable Signal type needs to be set explicitly -> ng-packagr strips nullability\n  protected readonly $suffixElement: Signal<SuffixComponent | undefined> = contentChild(SuffixComponent);\n  private readonly $prefixContainer = viewChild.required<ElementRef<HTMLElement>>('prefixContainer');\n  private readonly $suffixContainer = viewChild.required<ElementRef<HTMLElement>>('suffixContainer');\n  private readonly $inputContainer = viewChild.required<ElementRef<HTMLElement>>('inputContainer');\n  private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);\n\n  private readonly renderer = inject(Renderer2);\n\n  private readonly $inputDisabled = signal(false);\n\n  private resizeObserver?: ResizeObserver;\n  private intersectionObserver?: IntersectionObserver;\n  private inputObserver?: MutationObserver;\n\n  ngAfterContentInit(): void {\n    this.updatePrefixSuffixWidths();\n\n    const inputElement: HTMLElement | null = this.$inputContainer().nativeElement.querySelector(this.inputContainerSelector);\n\n    if (inputElement) {\n      inputElement.id = this.id;\n      this.updateInputAttributes(inputElement);\n\n      this.inputObserver = new MutationObserver(() => {\n        this.updateInputAttributes(inputElement);\n      });\n      this.inputObserver.observe(inputElement, {\n        attributes: true,\n        attributeFilter: ['disabled', 'placeholder', 'required'],\n      });\n    }\n  }\n\n  private updateInputAttributes(inputElement: HTMLElement) {\n    this.$inputDisabled.set(inputElement.getAttribute('disabled') != null);\n    const required = inputElement.getAttribute('required') != null && inputElement.getAttribute('required') !== 'false';\n    const placeholder = inputElement.getAttribute('placeholder');\n    if (placeholder !== null) {\n      if (required && !placeholder.endsWith('*')) {\n        inputElement.setAttribute('placeholder', `${placeholder}*`);\n      }\n      if (!required && placeholder.endsWith('*')) {\n        inputElement.setAttribute('placeholder', placeholder.slice(0, -1));\n      }\n    }\n  }\n  ngAfterViewInit(): void {\n    // Recalculate when view initializes\n    setTimeout(() => {\n      this.updatePrefixSuffixWidths();\n    });\n\n    // whenever the formFieldWrapper is in view, update the prefix/suffix widths\n    this.intersectionObserver = new IntersectionObserver(\n      entries => {\n        entries.forEach(entry => {\n          if (entry.isIntersecting) {\n            this.updatePrefixSuffixWidths();\n          }\n        });\n      },\n      { threshold: 0.1 },\n    );\n    this.intersectionObserver.observe(this.host.nativeElement);\n\n    // Observe size changes in prefix and suffix elements to adjust padding dynamically\n    this.resizeObserver = new ResizeObserver(() => {\n      this.updatePrefixSuffixWidths();\n    });\n    this.resizeObserver.observe(this.host.nativeElement);\n    if (this.$prefixElement()) {\n      this.resizeObserver.observe(this.$prefixContainer().nativeElement);\n    }\n    if (this.$suffixElement()) {\n      this.resizeObserver.observe(this.$suffixContainer().nativeElement);\n    }\n  }\n  ngOnDestroy(): void {\n    if (this.resizeObserver) {\n      this.resizeObserver.disconnect();\n    }\n    if (this.intersectionObserver) {\n      this.intersectionObserver.disconnect();\n    }\n    if (this.inputObserver) {\n      this.inputObserver.disconnect();\n    }\n  }\n\n  private updatePrefixSuffixWidths(): void {\n    const prefixElement = this.$prefixElement();\n    if (prefixElement) {\n      const prefixWidth = prefixElement.elementRef.nativeElement.offsetWidth;\n      this.renderer.setStyle(\n        this.$inputContainer().nativeElement.querySelector(this.inputContainerSelector),\n        'padding-left',\n        `${prefixWidth + 12}px`, // Adds a small margin for spacing\n      );\n    }\n    const suffixElement = this.$suffixElement();\n    if (suffixElement) {\n      const suffixWidth = suffixElement.elementRef.nativeElement.offsetWidth;\n      this.renderer.setStyle(\n        this.$inputContainer().nativeElement.querySelector(this.inputContainerSelector),\n        'padding-right',\n        `${suffixWidth + 8}px`, // Adds a small margin for spacing\n      );\n    }\n  }\n}\n","@if ($labelElement()) {\n  <div class=\"form-label\">\n    <label [for]=\"id\"><ng-content select=\"tab-label\" /></label>\n  </div>\n}\n\n<div class=\"form-input-wrapper\">\n  @if ($prefixElement()) {\n    <div #prefixContainer class=\"prefix\">\n      <ng-content select=\"tab-prefix\" />\n    </div>\n  }\n  <div #inputContainer class=\"input-container\">\n    <ng-content />\n  </div>\n  @if ($suffixElement()) {\n    <div #suffixContainer class=\"suffix\">\n      <ng-content select=\"tab-suffix\" />\n    </div>\n  }\n</div>\n@if ($hintElement() || $errorElement()) {\n  <div class=\"form-extra-info\">\n    @if ($hintElement() && (!$errorElement() || $hintElement()!.$showOnError())) {\n      <ng-content select=\"tab-hint\" />\n    }\n    @if ($errorElement()) {\n      <ng-content select=\"tab-error\" />\n    }\n  </div>\n}\n","import { CommonModule } from '@angular/common';\nimport { NgModule } from '@angular/core';\nimport { ReactiveFormsModule } from '@angular/forms';\nimport { FormFieldComponent } from './form-field.component';\nimport { TableauUiCommonModule } from 'tableau-ui-angular/common';\n\n@NgModule({\n  imports: [CommonModule, TableauUiCommonModule, ReactiveFormsModule],\n  declarations: [FormFieldComponent],\n  exports: [FormFieldComponent, ReactiveFormsModule, CommonModule],\n})\nexport class TableauUiFormFieldModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;;MAiBa,kBAAkB,CAAA;IACZ,sBAAsB,GAAG,gGAAgG;AACvH,IAAA,EAAE,GAAG,oBAAoB,CAAC,EAAE,CAAC;AACvC,IAAA,MAAM,GAAG,KAAK,CAAS,SAAS,EAAE;AACzC,QAAA,KAAK,EAAE,OAAO;AACf,KAAA,CAAC;;AAEiB,IAAA,YAAY,GAAsC,YAAY,CAAC,aAAa,CAAC;;AAE7E,IAAA,aAAa,GAAuC,YAAY,CAAC,cAAc,CAAC;;AAEhF,IAAA,aAAa,GAAuC,YAAY,CAAC,cAAc,CAAC;;AAEhF,IAAA,cAAc,GAAwC,YAAY,CAAC,eAAe,CAAC;;AAEnF,IAAA,cAAc,GAAwC,YAAY,CAAC,eAAe,CAAC;AACrF,IAAA,gBAAgB,GAAG,SAAS,CAAC,QAAQ,CAA0B,iBAAiB,CAAC;AACjF,IAAA,gBAAgB,GAAG,SAAS,CAAC,QAAQ,CAA0B,iBAAiB,CAAC;AACjF,IAAA,eAAe,GAAG,SAAS,CAAC,QAAQ,CAA0B,gBAAgB,CAAC;AAC/E,IAAA,IAAI,GAAG,MAAM,CAA0B,UAAU,CAAC;AAElD,IAAA,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC;AAE5B,IAAA,cAAc,GAAG,MAAM,CAA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