This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { | |
| AbstractDataSourceProvider, | |
| DataSource, | |
| DataSourceParser, | |
| isDataSource, | |
| } from '@host-directives-app/data-source'; | |
| import { Nullable } from '@host-directives-app/shared'; | |
| import { isObservable, Observable, of } from 'rxjs'; | |
| export interface ComboboxItem { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Nullable } from '@host-directives-app/shared'; | |
| import { Observable } from 'rxjs'; | |
| /** | |
| * Acceptable data source types. | |
| */ | |
| export type DataSource<T = unknown> = | |
| | AbstractDataSourceProvider<T> | |
| | Observable<T[]> | |
| | T[]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component({ | |
| selector: 'app-combobox', | |
| template: ` | |
| <input | |
| #comboboxInput | |
| class="combobox-input" | |
| type="text" | |
| [attr.list]="'inputOptions' + uniqueId" | |
| [attr.placeholder]="placeholder" | |
| autocomplete="off" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class ComboboxDataProvider extends AbstractDataProvider<AcceptableComboboxItem> { | |
| constructor(private _values: Observable<AcceptableComboboxItem[]> | AcceptableComboboxItem[]) { | |
| super(); | |
| } | |
| fetch(): Observable<AcceptableComboboxItem[]> { | |
| return isObservable(this._values) ? this._values : of(this._values); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Acceptable data source types. | |
| */ | |
| export type DataSource<T = unknown> = | |
| | AbstractDataSourceProvider<T> | |
| | Observable<T[]> | |
| | T[]; | |
| export interface DataSourceParser< | |
| T = unknown, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const DATA_SOURCE_TRANSFORMER = new InjectionToken<DataSourceParser>('DataSourceTransformerClass'); | |
| @Directive({ | |
| selector: '[appDataSource]', | |
| standalone: true, | |
| providers: [ | |
| // Small helper service to unsubscribe from streams when component destroys. | |
| DestroyedService | |
| ], | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export type ProviderParams = ReadonlyMap<string, unknown>; | |
| export abstract class AbstractDataProvider<T> { | |
| /** | |
| * Method responsible for retrieving the data. | |
| * @param params Set of parameters used for search query. | |
| * @param start Start index of the items array. | |
| * @param end End index of the items array. | |
| */ | |
| abstract fetch(params?: ProviderParams, start?: number, end?: number): Observable<T[]> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export abstract class AbstractDataProvider<T> { | |
| abstract fetch(params?: ProviderParams, start?: number, end?: number): Observable<T[]> | |
| } | |
| export class AbstractDataSourceProvider<T = unknown> { | |
| /** @hidden */ | |
| protected readonly _dataChanges$: BehaviorSubject<T[]> = new BehaviorSubject< | |
| T[] | |
| >([]); | |
| /** @hidden */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component({ | |
| selector: 'app-combobox', | |
| template: ` | |
| <input | |
| #comboboxInput | |
| class="combobox-input" | |
| type="text" | |
| [attr.list]="'inputOptions' + uniqueId" | |
| [attr.placeholder]="placeholder" | |
| autocomplete="off" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Directive({ | |
| selector: '[appCva]', | |
| standalone: true, | |
| providers: [ | |
| // Small helper service to unsubscribe from streams when component destroys. | |
| DestroyedService | |
| ], | |
| }) | |
| export class CvaDirective<T = unknown> implements ControlValueAccessor, OnDestroy, AfterViewInit, DoCheck { | |
| /** |
NewerOlder