{"version":3,"file":"ngx-t-forms-chip-options-creator-editor.component-CO_3EQ_v.mjs","sources":["../../../projects/ngx-t-forms/src/lib/components/t-dynamic-data-edit/elements/chip-options-creator-editor/chip-options-creator-editor.component.ts","../../../projects/ngx-t-forms/src/lib/components/t-dynamic-data-edit/elements/chip-options-creator-editor/chip-options-creator-editor.component.html"],"sourcesContent":["import {\r\n  ChangeDetectionStrategy,\r\n  Component,\r\n  ViewEncapsulation,\r\n  computed,\r\n  effect,\r\n  inject,\r\n  input,\r\n  output,\r\n  signal,\r\n} from '@angular/core';\r\nimport { LiveAnnouncer } from '@angular/cdk/a11y';\r\nimport { COMMA, ENTER } from '@angular/cdk/keycodes';\r\nimport { MatChipEditedEvent, MatChipInputEvent, MatChipsModule } from '@angular/material/chips';\r\nimport { MatIconModule } from '@angular/material/icon';\r\nimport type { IConfigElementError } from '../../t-dynamic-data-edit.component';\r\nimport { EmptyStateComponent } from '../_shared/empty-state/empty-state.component';\r\n\r\n/**\r\n * Internal chip-options creator editor: the user types free-text tokens that\r\n * become removable, editable chips; the resulting `string[]` is emitted.\r\n *\r\n * Rendered by `t-dynamic-data-edit`'s non-control branch (it is NOT a\r\n * MatFormFieldControl), which already supplies the field label, hint, and\r\n * validation errors — so this component owns only the chip grid and its empty\r\n * state.\r\n */\r\n@Component({\r\n  selector: 'lib-chip-options-creator-editor',\r\n  imports: [MatChipsModule, MatIconModule, EmptyStateComponent],\r\n  templateUrl: './chip-options-creator-editor.component.html',\r\n  styleUrl: './chip-options-creator-editor.component.scss',\r\n  changeDetection: ChangeDetectionStrategy.OnPush,\r\n  encapsulation: ViewEncapsulation.Emulated,\r\n  host: {\r\n    'class': 'lib-chip-options-creator-editor',\r\n    '[attr.id]': 'id()',\r\n  },\r\n})\r\nexport class ChipOptionsCreatorEditorComponent {\r\n  /** Optional id attribute supplied by the parent editor. */\r\n  readonly id = input<string | undefined>(undefined);\r\n  /** Disables chip entry/edit/remove. */\r\n  readonly disabled = input<boolean>(false);\r\n  /** Whether a non-empty value is required (kept on the contract). */\r\n  readonly required = input<boolean>(false);\r\n  /** External validation errors (surfaced by the parent). */\r\n  readonly errors = input<IConfigElementError[] | undefined>([]);\r\n  /** The chip values to render. */\r\n  readonly value = input<string[] | undefined>(undefined);\r\n  /** Placeholder for the new-chip input. */\r\n  readonly placeholder = input<string>('');\r\n\r\n  /** Emits the full chip list whenever it changes. */\r\n  readonly valueChange = output<string[] | undefined>();\r\n\r\n  protected readonly separatorKeysCodes = [ENTER, COMMA] as const;\r\n\r\n  /** Local working copy of the chip list; mirrors the `value` input. */\r\n  readonly #internalValue = signal<readonly string[]>([]);\r\n  /** Read-only accessor used by the template. */\r\n  protected readonly currentValue = this.#internalValue.asReadonly();\r\n  protected readonly isEmpty = computed(() => this.#internalValue().length === 0);\r\n\r\n  readonly #announcer = inject(LiveAnnouncer);\r\n\r\n  constructor() {\r\n    // The parent drives the value declaratively via [value].\r\n    effect(() => {\r\n      this.#internalValue.set(this.value() ?? []);\r\n    });\r\n  }\r\n\r\n  protected add(event: MatChipInputEvent): void {\r\n    const value = (event.value || '').trim();\r\n    event.chipInput?.clear();\r\n    if (!value) {\r\n      return;\r\n    }\r\n    const current = this.#internalValue();\r\n    if (current.includes(value)) {\r\n      this.#announcer.announce(`value ${value} already exists`);\r\n      return;\r\n    }\r\n    this.#commit([...current, value]);\r\n  }\r\n\r\n  protected edit(segment: string, event: MatChipEditedEvent): void {\r\n    const newValue = event.value.trim();\r\n    if (!newValue) {\r\n      this.remove(segment);\r\n      return;\r\n    }\r\n    this.#commit(this.#internalValue().map((s) => (s === segment ? newValue : s)));\r\n  }\r\n\r\n  protected remove(segment: string): void {\r\n    const current = this.#internalValue();\r\n    if (!current.includes(segment)) {\r\n      return;\r\n    }\r\n    this.#announcer.announce(`Removed ${segment}`);\r\n    this.#commit(current.filter((s) => s !== segment));\r\n  }\r\n\r\n  #commit(next: readonly string[]): void {\r\n    const snapshot = [...next];\r\n    this.#internalValue.set(snapshot);\r\n    this.valueChange.emit(snapshot);\r\n  }\r\n}\r\n","@if (isEmpty()) {\r\n<lib-empty-state icon=\"label_off\" message=\"No options yet — type below to add one\" />\r\n}\r\n\r\n<mat-chip-grid\r\n  #chipGrid\r\n  class=\"lib-chip-options-creator-editor__grid\"\r\n  [disabled]=\"disabled()\"\r\n  aria-label=\"Chip options\">\r\n  @for (segment of currentValue(); track $index) {\r\n  <mat-chip-row\r\n    class=\"lib-chip-options-creator-editor__chip\"\r\n    [editable]=\"true\"\r\n    [aria-description]=\"'press enter to edit ' + segment\"\r\n    (edited)=\"edit(segment, $event)\"\r\n    (removed)=\"remove(segment)\">\r\n    {{ segment }}\r\n    <button matChipRemove [attr.aria-label]=\"'remove ' + segment\">\r\n      <mat-icon>cancel</mat-icon>\r\n    </button>\r\n  </mat-chip-row>\r\n  }\r\n  <input\r\n    class=\"lib-chip-options-creator-editor__input\"\r\n    [placeholder]=\"placeholder() || 'New selection...'\"\r\n    [matChipInputFor]=\"chipGrid\"\r\n    [matChipInputSeparatorKeyCodes]=\"separatorKeysCodes\"\r\n    [matChipInputAddOnBlur]=\"true\"\r\n    (matChipInputTokenEnd)=\"add($event)\" />\r\n</mat-chip-grid>\r\n"],"names":["i1"],"mappings":";;;;;;;;;;AAkBA;;;;;;;;AAQG;MAaU,iCAAiC,CAAA;;AAoBnC,IAAA,cAAc;AAKd,IAAA,UAAU;AAEnB,IAAA,WAAA,GAAA;;AAzBS,QAAA,IAAA,CAAA,EAAE,GAAG,KAAK,CAAqB,SAAS,yEAAC;;AAEzC,QAAA,IAAA,CAAA,QAAQ,GAAG,KAAK,CAAU,KAAK,+EAAC;;AAEhC,QAAA,IAAA,CAAA,QAAQ,GAAG,KAAK,CAAU,KAAK,+EAAC;;AAEhC,QAAA,IAAA,CAAA,MAAM,GAAG,KAAK,CAAoC,EAAE,6EAAC;;AAErD,QAAA,IAAA,CAAA,KAAK,GAAG,KAAK,CAAuB,SAAS,4EAAC;;AAE9C,QAAA,IAAA,CAAA,WAAW,G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