@progress/kendo-angular-dateinputs
Version:
Kendo UI for Angular Date Inputs Package - Everything you need to add date selection functionality to apps (DatePicker, TimePicker, DateInput, DateRangePicker, DateTimePicker, Calendar, and MultiViewCalendar).
117 lines (116 loc) • 4.43 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import { Directive, Input, IterableDiffers, TemplateRef, ViewContainerRef } from '@angular/core';
import { isDocumentAvailable } from '@progress/kendo-angular-common';
import * as i0 from "@angular/core";
/**
* @hidden
*/
export class KForOfContext {
$implicit;
kForOf;
index;
count;
constructor($implicit, kForOf, index, count) {
this.$implicit = $implicit;
this.kForOf = kForOf;
this.index = index;
this.count = count;
}
get first() { return this.index === 0; }
get last() { return this.index === this.count - 1; }
get even() { return this.index % 2 === 0; }
get odd() { return !this.even; }
}
/**
* @hidden
*/
// eslint-disable-next-line
export class KForOf {
_viewContainer;
_template;
_differs;
kForOf;
kForTrackBy;
_differ = null;
constructor(_viewContainer, _template, _differs) {
this._viewContainer = _viewContainer;
this._template = _template;
this._differs = _differs;
}
set kForTemplate(value) {
if (value) {
this._template = value;
}
}
ngOnChanges(changes) {
if ('kForOf' in changes) {
const value = changes['kForOf'].currentValue;
if (this._differ || !value) {
return;
}
try {
this._differ = this._differs.find(value).create(this.kForTrackBy);
}
catch (e) {
throw new Error(`Cannot find a differ supporting object '${value}' of type '${getTypeNameForDebugging(value)}'.`);
}
}
}
ngDoCheck() {
if (this._differ) {
const changes = this._differ.diff(this.kForOf);
if (changes) {
this._applyChanges(changes);
}
}
}
_applyChanges(changes) {
if (!isDocumentAvailable()) {
return;
}
const viewContainerLength = this._viewContainer.length;
const dataLength = this.kForOf.length;
const tuples = {};
changes.forEachOperation((record, _, currentIndex) => {
if (currentIndex !== null) {
tuples[currentIndex] = record.item;
}
});
for (let i = viewContainerLength; i < dataLength; i++) {
this._viewContainer.createEmbeddedView(this._template, new KForOfContext(null, this.kForOf, -1, -1), i);
}
for (let i = this._viewContainer.length; i > dataLength; i--) {
this._viewContainer.remove(i - 1);
}
for (let i = 0; i < this._viewContainer.length; i++) {
const view = this._viewContainer.get(i);
view.context.index = i;
view.context.count = length;
view.context.$implicit = tuples[i] || null;
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: KForOf, deps: [{ token: i0.ViewContainerRef }, { token: i0.TemplateRef }, { token: i0.IterableDiffers }], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: KForOf, isStandalone: true, selector: "[kFor][kForOf]", inputs: { kForOf: "kForOf", kForTrackBy: "kForTrackBy", kForTemplate: "kForTemplate" }, usesOnChanges: true, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: KForOf, decorators: [{
type: Directive,
args: [{
selector: '[kFor][kForOf]',
standalone: true
}]
}], ctorParameters: function () { return [{ type: i0.ViewContainerRef }, { type: i0.TemplateRef }, { type: i0.IterableDiffers }]; }, propDecorators: { kForOf: [{
type: Input
}], kForTrackBy: [{
type: Input
}], kForTemplate: [{
type: Input
}] } });
/**
* @hidden
*/
export function getTypeNameForDebugging(type) {
return type.name || typeof type;
}