{"version":3,"file":"angularity-forms.mjs","sources":["../../../packages/forms/src/value-accessing/accessor-host.ts","../../../packages/forms/src/value-accessing/accessor.ts","../../../packages/forms/src/value-accessing/provide.ts","../../../packages/forms/src/angularity-forms.ts"],"sourcesContent":["import {\n  Directive,\n  EventEmitter,\n  Injectable,\n  Input,\n  Output,\n} from '@angular/core';\nimport { toSignal } from '@angular/core/rxjs-interop';\nimport { merge, Subject, SubjectLike, Subscribable } from 'rxjs';\n\n/**\n * A host component of a custom Angular form control.\n *\n * It exposes several RxJS streams for value, change, disabled, and touched events.\n *\n * @see `SimpleComponentValueAccessorHost` for a generic implementation of this\n * interface that simplifies the process for most use cases.\n *\n * @see `ComponentValueAccessor` for adapting this host into a standard\n * Angular `ControlValueAccessor`.\n */\n@Injectable()\nexport abstract class ComponentValueAccessorHost<T = any> {\n  /**\n   * A stream of value changes from input binding.\n   */\n  abstract readonly valueInput$: SubjectLike<T>;\n  /**\n   * A stream of value changes from DOM events.\n   */\n  abstract readonly valueChange$: Subscribable<T>;\n  /**\n   * A stream of disabled state changes from input binding.\n   */\n  abstract readonly disabled$: SubjectLike<boolean>;\n  /**\n   * A stream of touched events from DOM events.\n   */\n  abstract readonly touched$: Subscribable<void>;\n}\n\n/**\n * A simple implementation of `ComponentValueAccessorHost` that suits most\n * use cases of creating custom Angular form control components.\n *\n * It defines the following input/output bindings:\n * - `value/valueChange`: A two-way binding for `valueInput$/valueChange$`.\n * - `disabled`: An input binding for `disabled$`.\n * - `touched`: An output binding for `touched$`.\n *\n * It also defines the following signals for convenience:\n * - `value`: A signal that emits the current value of the form control.\n * - `disabled`: A signal that emits the current disabled state of the form control.\n */\n@Directive()\nexport class SimpleComponentValueAccessorHost<T>\n  implements ComponentValueAccessorHost<T>\n{\n  // prettier-ignore\n  @Input('value') set valueInput(v: T) { this.valueInput$.next(v) }\n  readonly valueInput$ = new Subject<T>();\n\n  @Output('valueChange')\n  readonly valueChange$ = new EventEmitter<T>();\n\n  // prettier-ignore\n  @Input('disabled') set disabledInput(v: boolean) { this.disabled$.next(v) }\n  readonly disabled$ = new Subject<boolean>();\n\n  @Output('touched')\n  readonly touched$ = new EventEmitter<void>();\n\n  /**\n   * A signal that emits the current value of the form control.\n   */\n  readonly value = toSignal(merge(this.valueInput$, this.valueChange$));\n\n  /**\n   * A signal that emits the current disabled state of the form control.\n   */\n  readonly disabled = toSignal(this.disabled$);\n}\n","import { inject, Injectable } from '@angular/core';\nimport { ControlValueAccessor } from '@angular/forms';\n\nimport { ComponentValueAccessorHost } from './accessor-host';\n\n/**\n * An adapter that adapts a `ComponentValueAccessorHost` into a `ControlValueAccessor`.\n * It uses the `ComponentValueAccessorHost` provided at the `self` level to implement\n * the `ControlValueAccessor` interface.\n */\n@Injectable()\nexport class ComponentValueAccessor implements ControlValueAccessor {\n  protected readonly host = inject(ComponentValueAccessorHost, { self: true });\n  writeValue(value: unknown): void {\n    this.host.valueInput$.next(value);\n  }\n  registerOnChange(fn: (value: unknown) => void): void {\n    this.host.valueChange$.subscribe({ next: fn });\n  }\n  registerOnTouched(fn: () => void): void {\n    this.host.touched$.subscribe({ next: fn });\n  }\n  setDisabledState(disabled: boolean): void {\n    this.host.disabled$.next(disabled);\n  }\n}\n","import { Provider, ProviderToken } from '@angular/core';\nimport { NG_VALUE_ACCESSOR } from '@angular/forms';\nimport { provide, provideMulti } from '@angularity/core';\n\nimport { ComponentValueAccessor } from './accessor';\nimport { ComponentValueAccessorHost } from './accessor-host';\n\n/**\n * Provides the essential providers for a custom Angular form control component\n * that implements `ComponentValueAccessorHost`\n *\n * @param host The provider token to the `ComponentValueAccessorHost` component\n *\n * @example\n * ```ts\n * \\@Component({\n *   providers: [provideComponentValueAccessor(MyFormControlComponent)],\n * })\n * class MyFormControlComponent implements ComponentValueAccessorHost {\n *   // ...\n * }\n * ```\n */\nexport function provideComponentValueAccessor(\n  host: ProviderToken<ComponentValueAccessorHost>,\n): Provider[] {\n  return [\n    provide({\n      token: ComponentValueAccessorHost,\n      useExisting: host,\n    }),\n    provideMulti({\n      token: NG_VALUE_ACCESSOR,\n      useClass: ComponentValueAccessor,\n    }),\n  ];\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;AAUA;;;;;;;;;;AAUG;MAEmB,0BAA0B,CAAA;8GAA1B,0BAA0B,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;kHAA1B,0BAA0B,EAAA,CAAA,CAAA;;2FAA1B,0BAA0B,EAAA,UAAA,EAAA,CAAA;kBAD/C;;AAoBD;;;;;;;;;;;;AAYG;MAEU,gCAAgC,CAAA;AAD7C,IAAA,WAAA,GAAA;AAMW,QAAA,IAAA,CAAA,WAAW,GAAG,IAAI,OAAO,EAAK;AAG9B,QAAA,IAAA,CAAA,YAAY,GAAG,IAAI,YAAY,EAAK;AAIpC,QAAA,IAAA,CAAA,SAAS,GAAG,IAAI,OAAO,EAAW;AAGlC,QAAA,IAAA,CAAA,QAAQ,GAAG,IAAI,YAAY,EAAQ;AAE5C;;AAEG;AACM,QAAA,IAAA,CAAA,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;AAErE;;AAEG;AACM,QAAA,IAAA,CAAA,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC;AAC7C,IAAA;;AAtBC,IAAA,IAAoB,UAAU,CAAC,CAAI,EAAA,EAAI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA,CAAC;;AAOhE,IAAA,IAAuB,aAAa,CAAC,CAAU,EAAA,EAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA,CAAC;8GAX/D,gCAAgC,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,C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