@taiga-ui/kit
Version:
Taiga UI Angular main components kit
114 lines (108 loc) • 16.6 kB
JavaScript
import { NgForOf, NgIf } from '@angular/common';
import * as i0 from '@angular/core';
import { signal, inject, EventEmitter, computed, isSignal, Component, ChangeDetectionStrategy, ViewChildren, forwardRef, Input, Output, ViewChild } from '@angular/core';
import { TuiElement } from '@taiga-ui/cdk/directives/element';
import * as i1 from '@taiga-ui/core/components/data-list';
import { tuiInjectDataListSize, tuiAsDataListAccessor, TuiDataListComponent, TuiOption, TuiOptionWithValue, TuiDataList, TuiDataListDirective } from '@taiga-ui/core/components/data-list';
import { TuiLoader } from '@taiga-ui/core/components/loader';
import { PolymorpheusOutlet } from '@taiga-ui/polymorpheus';
import { EMPTY_QUERY } from '@taiga-ui/cdk/constants';
import { tuiInjectElement } from '@taiga-ui/cdk/utils/dom';
import { tuiIsNativeFocused } from '@taiga-ui/cdk/utils/focus';
import { tuiIsPresent } from '@taiga-ui/cdk/utils/miscellaneous';
import { TUI_ITEMS_HANDLERS } from '@taiga-ui/core/directives/items-handlers';
import { TUI_ITEMS_HANDLERS as TUI_ITEMS_HANDLERS$1 } from '@taiga-ui/kit/tokens';
class TuiDataListWrapperComponent {
constructor() {
this.datalist = signal(null);
this.itemsHandlers = inject(TUI_ITEMS_HANDLERS);
// TODO(v5): delete
this.itemsHandlersLegacy = inject(TUI_ITEMS_HANDLERS$1);
// TODO(v5): delete
this.legacyOptionsQuery = EMPTY_QUERY;
// TODO(v5): delete
this.optionsQuery = EMPTY_QUERY;
this.newOptionMode = tuiInjectElement().hasAttribute('new');
this.items = [];
this.disabledItemHandler = this.newOptionMode
? this.itemsHandlers?.disabledItemHandler()
: this.itemsHandlersLegacy.disabledItemHandler;
this.size = tuiInjectDataListSize();
this.itemClick = new EventEmitter();
this.options = computed(() => this.datalist()?.options() ?? []);
this.itemContent = ({ $implicit }) => this.newOptionMode
? this.itemsHandlers.stringify()($implicit)
: this.itemsHandlersLegacy.stringify($implicit);
}
getContext($implicit, { nativeElement }) {
return { $implicit, active: tuiIsNativeFocused(nativeElement) };
}
// TODO(v5): delete
getOptions(includeDisabled = false) {
return [
...this.legacyOptionsQuery,
...this.optionsQuery,
]
.filter(({ disabled }) => includeDisabled || !disabled)
.map(({ value }) => (isSignal(value) ? value() : value))
.filter(tuiIsPresent);
}
// TODO(v5): use signal `viewChild`
set datalistSetter(x) {
this.datalist.set(x);
}
$cast(items) {
return items;
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiDataListWrapperComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: TuiDataListWrapperComponent, isStandalone: true, selector: "tui-data-list-wrapper:not([labels]), tui-data-list-wrapper:not([labels])[new]", inputs: { items: "items", disabledItemHandler: "disabledItemHandler", emptyContent: "emptyContent", size: "size", itemContent: "itemContent" }, outputs: { itemClick: "itemClick" }, providers: [tuiAsDataListAccessor(TuiDataListWrapperComponent)], viewQueries: [{ propertyName: "datalistSetter", first: true, predicate: TuiDataListComponent, descendants: true }, { propertyName: "legacyOptionsQuery", predicate: i0.forwardRef(function () { return TuiOption; }), descendants: true }, { propertyName: "optionsQuery", predicate: i0.forwardRef(function () { return TuiOptionWithValue; }), descendants: true }], ngImport: i0, template: "<tui-data-list\n *ngIf=\"items; else loading\"\n [emptyContent]=\"emptyContent\"\n [size]=\"size\"\n>\n <ng-container *ngIf=\"newOptionMode; else legacyOptionFallback\">\n <button\n *ngFor=\"let item of $cast(items)\"\n #elementRef=\"elementRef\"\n new\n tuiElement\n tuiOption\n type=\"button\"\n [disabled]=\"disabledItemHandler(item)\"\n [value]=\"item\"\n (click.capture)=\"itemClick.emit(item)\"\n >\n <ng-container *polymorpheusOutlet=\"itemContent as text; context: getContext(item, elementRef)\">\n {{ text }}\n </ng-container>\n </button>\n </ng-container>\n\n <!-- TODO(v5): delete fallback -->\n <ng-template #legacyOptionFallback>\n <button\n *ngFor=\"let item of $cast(items)\"\n #elementRef=\"elementRef\"\n automation-id=\"tui-data-list-wrapper__option\"\n tuiElement\n tuiOption\n type=\"button\"\n [disabled]=\"disabledItemHandler(item)\"\n [value]=\"item\"\n (click)=\"itemClick.emit(item)\"\n >\n <span class=\"t-content\">\n <ng-container *polymorpheusOutlet=\"itemContent as text; context: getContext(item, elementRef)\">\n {{ text }}\n </ng-container>\n </span>\n </button>\n </ng-template>\n</tui-data-list>\n<ng-template #loading>\n <tui-loader\n automation-id=\"tui-data-list-wrapper__loader\"\n class=\"t-loader\"\n />\n</ng-template>\n", styles: [":host{display:block}.t-content{flex:1;min-inline-size:0}.t-loader{margin:.75rem 0}\n"], dependencies: [{ kind: "directive", type: NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: PolymorpheusOutlet, selector: "[polymorpheusOutlet]", inputs: ["polymorpheusOutlet", "polymorpheusOutletContext"] }, { kind: "component", type: i1.TuiDataListComponent, selector: "tui-data-list", inputs: ["emptyContent", "size"] }, { kind: "component", type: i1.TuiOption, selector: "button[tuiOption]:not([new]), a[tuiOption]:not([new]), label[tuiOption]:not([new])", inputs: ["disabled", "value"] }, { kind: "directive", type: i1.TuiOptionNew, selector: "button[tuiOption][new], a[tuiOption][new], label[tuiOption][new]", inputs: ["disabled"] }, { kind: "directive", type: i1.TuiOptionWithValue, selector: "button[tuiOption][value][new], a[tuiOption][value][new], label[tuiOption][value][new]", inputs: ["disabled", "value"] }, { kind: "directive", type: TuiElement, selector: "[tuiElement]", exportAs: ["elementRef"] }, { kind: "component", type: TuiLoader, selector: "tui-loader", inputs: ["size", "inheritColor", "overlay", "textContent", "showLoader"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiDataListWrapperComponent, decorators: [{
type: Component,
args: [{ standalone: true, selector: 'tui-data-list-wrapper:not([labels]), tui-data-list-wrapper:not([labels])[new]', imports: [NgForOf, NgIf, PolymorpheusOutlet, TuiDataList, TuiElement, TuiLoader], changeDetection: ChangeDetectionStrategy.OnPush, providers: [tuiAsDataListAccessor(TuiDataListWrapperComponent)], template: "<tui-data-list\n *ngIf=\"items; else loading\"\n [emptyContent]=\"emptyContent\"\n [size]=\"size\"\n>\n <ng-container *ngIf=\"newOptionMode; else legacyOptionFallback\">\n <button\n *ngFor=\"let item of $cast(items)\"\n #elementRef=\"elementRef\"\n new\n tuiElement\n tuiOption\n type=\"button\"\n [disabled]=\"disabledItemHandler(item)\"\n [value]=\"item\"\n (click.capture)=\"itemClick.emit(item)\"\n >\n <ng-container *polymorpheusOutlet=\"itemContent as text; context: getContext(item, elementRef)\">\n {{ text }}\n </ng-container>\n </button>\n </ng-container>\n\n <!-- TODO(v5): delete fallback -->\n <ng-template #legacyOptionFallback>\n <button\n *ngFor=\"let item of $cast(items)\"\n #elementRef=\"elementRef\"\n automation-id=\"tui-data-list-wrapper__option\"\n tuiElement\n tuiOption\n type=\"button\"\n [disabled]=\"disabledItemHandler(item)\"\n [value]=\"item\"\n (click)=\"itemClick.emit(item)\"\n >\n <span class=\"t-content\">\n <ng-container *polymorpheusOutlet=\"itemContent as text; context: getContext(item, elementRef)\">\n {{ text }}\n </ng-container>\n </span>\n </button>\n </ng-template>\n</tui-data-list>\n<ng-template #loading>\n <tui-loader\n automation-id=\"tui-data-list-wrapper__loader\"\n class=\"t-loader\"\n />\n</ng-template>\n", styles: [":host{display:block}.t-content{flex:1;min-inline-size:0}.t-loader{margin:.75rem 0}\n"] }]
}], propDecorators: { legacyOptionsQuery: [{
type: ViewChildren,
args: [forwardRef(() => TuiOption)]
}], optionsQuery: [{
type: ViewChildren,
args: [forwardRef(() => TuiOptionWithValue)]
}], items: [{
type: Input
}], disabledItemHandler: [{
type: Input
}], emptyContent: [{
type: Input
}], size: [{
type: Input
}], itemClick: [{
type: Output
}], itemContent: [{
type: Input
}], datalistSetter: [{
type: ViewChild,
args: [TuiDataListComponent]
}] } });
class TuiDataListGroupWrapperComponent extends TuiDataListWrapperComponent {
constructor() {
super(...arguments);
this.labels = [];
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiDataListGroupWrapperComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: TuiDataListGroupWrapperComponent, isStandalone: true, selector: "tui-data-list-wrapper[labels]", inputs: { labels: "labels" }, providers: [tuiAsDataListAccessor(TuiDataListGroupWrapperComponent)], usesInheritance: true, ngImport: i0, template: "<tui-data-list\n *ngIf=\"items; else loading\"\n [emptyContent]=\"emptyContent\"\n [size]=\"size\"\n>\n <tui-opt-group\n *ngFor=\"let group of items; let index = index\"\n [label]=\"labels[index]\"\n >\n <ng-container *ngIf=\"newOptionMode; else legacyOptionFallback\">\n <button\n *ngFor=\"let item of group\"\n #elementRef=\"elementRef\"\n new\n tuiElement\n tuiOption\n type=\"button\"\n [disabled]=\"disabledItemHandler(item)\"\n [value]=\"item\"\n (click.capture)=\"itemClick.emit(item)\"\n >\n <ng-container *polymorpheusOutlet=\"itemContent as text; context: getContext(item, elementRef)\">\n {{ text }}\n </ng-container>\n </button>\n </ng-container>\n\n <!-- TODO(v5): delete fallback -->\n <ng-template #legacyOptionFallback>\n <button\n *ngFor=\"let item of group\"\n #elementRef=\"elementRef\"\n automation-id=\"tui-data-list-wrapper__option\"\n tuiElement\n tuiOption\n type=\"button\"\n [disabled]=\"disabledItemHandler(item)\"\n [value]=\"item\"\n (click)=\"itemClick.emit(item)\"\n >\n <ng-container *polymorpheusOutlet=\"itemContent as text; context: getContext(item, elementRef)\">\n {{ text }}\n </ng-container>\n </button>\n </ng-template>\n </tui-opt-group>\n</tui-data-list>\n<ng-template #loading>\n <tui-loader class=\"t-loader\" />\n</ng-template>\n", styles: [":host{display:block}.t-content{flex:1;min-inline-size:0}.t-loader{margin:.75rem 0}\n"], dependencies: [{ kind: "directive", type: NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: PolymorpheusOutlet, selector: "[polymorpheusOutlet]", inputs: ["polymorpheusOutlet", "polymorpheusOutletContext"] }, { kind: "component", type: i1.TuiDataListComponent, selector: "tui-data-list", inputs: ["emptyContent", "size"] }, { kind: "component", type: i1.TuiOption, selector: "button[tuiOption]:not([new]), a[tuiOption]:not([new]), label[tuiOption]:not([new])", inputs: ["disabled", "value"] }, { kind: "directive", type: i1.TuiOptionNew, selector: "button[tuiOption][new], a[tuiOption][new], label[tuiOption][new]", inputs: ["disabled"] }, { kind: "directive", type: i1.TuiOptionWithValue, selector: "button[tuiOption][value][new], a[tuiOption][value][new], label[tuiOption][value][new]", inputs: ["disabled", "value"] }, { kind: "directive", type: i1.TuiOptGroup, selector: "tui-opt-group", inputs: ["label"] }, { kind: "directive", type: TuiElement, selector: "[tuiElement]", exportAs: ["elementRef"] }, { kind: "component", type: TuiLoader, selector: "tui-loader", inputs: ["size", "inheritColor", "overlay", "textContent", "showLoader"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiDataListGroupWrapperComponent, decorators: [{
type: Component,
args: [{ standalone: true, selector: 'tui-data-list-wrapper[labels]', imports: [NgForOf, NgIf, PolymorpheusOutlet, TuiDataList, TuiElement, TuiLoader], changeDetection: ChangeDetectionStrategy.OnPush, providers: [tuiAsDataListAccessor(TuiDataListGroupWrapperComponent)], template: "<tui-data-list\n *ngIf=\"items; else loading\"\n [emptyContent]=\"emptyContent\"\n [size]=\"size\"\n>\n <tui-opt-group\n *ngFor=\"let group of items; let index = index\"\n [label]=\"labels[index]\"\n >\n <ng-container *ngIf=\"newOptionMode; else legacyOptionFallback\">\n <button\n *ngFor=\"let item of group\"\n #elementRef=\"elementRef\"\n new\n tuiElement\n tuiOption\n type=\"button\"\n [disabled]=\"disabledItemHandler(item)\"\n [value]=\"item\"\n (click.capture)=\"itemClick.emit(item)\"\n >\n <ng-container *polymorpheusOutlet=\"itemContent as text; context: getContext(item, elementRef)\">\n {{ text }}\n </ng-container>\n </button>\n </ng-container>\n\n <!-- TODO(v5): delete fallback -->\n <ng-template #legacyOptionFallback>\n <button\n *ngFor=\"let item of group\"\n #elementRef=\"elementRef\"\n automation-id=\"tui-data-list-wrapper__option\"\n tuiElement\n tuiOption\n type=\"button\"\n [disabled]=\"disabledItemHandler(item)\"\n [value]=\"item\"\n (click)=\"itemClick.emit(item)\"\n >\n <ng-container *polymorpheusOutlet=\"itemContent as text; context: getContext(item, elementRef)\">\n {{ text }}\n </ng-container>\n </button>\n </ng-template>\n </tui-opt-group>\n</tui-data-list>\n<ng-template #loading>\n <tui-loader class=\"t-loader\" />\n</ng-template>\n", styles: [":host{display:block}.t-content{flex:1;min-inline-size:0}.t-loader{margin:.75rem 0}\n"] }]
}], propDecorators: { labels: [{
type: Input
}] } });
const TuiDataListWrapper = [
TuiDataListWrapperComponent,
TuiDataListGroupWrapperComponent,
TuiDataListDirective,
];
/**
* Generated bundle index. Do not edit.
*/
export { TuiDataListGroupWrapperComponent, TuiDataListWrapper, TuiDataListWrapperComponent };
//# sourceMappingURL=taiga-ui-kit-components-data-list-wrapper.mjs.map