ngx-ui-scroll
Version:
Infinite/virtual scroll for Angular
134 lines (126 loc) • 5.55 kB
JavaScript
/**
* @license ngx-ui-scroll
* MIT license
*/
import { Component, ChangeDetectionStrategy, ChangeDetectorRef, ElementRef, Directive, TemplateRef, ViewContainerRef, ComponentFactoryResolver, Input, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Workflow, makeDatasource, AdapterPropName, EMPTY_ITEM } from 'vscroll';
export { Routines, SizeStrategy } from 'vscroll';
import { Subject, BehaviorSubject } from 'rxjs';
var consumer = {
name: 'ngx-ui-scroll',
version: '2.4.1'
};
var UiScrollComponent = /** @class */ (function () {
function UiScrollComponent(changeDetector, elementRef) {
this.changeDetector = changeDetector;
this.elementRef = elementRef;
// the only template variable
this.items = [];
}
UiScrollComponent.prototype.ngOnInit = function () {
var _this = this;
this.workflow = new Workflow({
consumer: consumer,
element: this.elementRef.nativeElement,
datasource: this.datasource,
run: function (items) {
if (!items.length && !_this.items.length) {
return;
}
_this.items = items;
_this.changeDetector.detectChanges();
}
});
};
UiScrollComponent.prototype.ngOnDestroy = function () {
this.workflow.dispose();
};
UiScrollComponent.decorators = [
{ type: Component, args: [{
selector: '[ui-scroll]',
changeDetection: ChangeDetectionStrategy.OnPush,
template: "\n <div data-padding-backward></div>\n <div\n *ngFor=\"let item of items\"\n [attr.data-sid]=\"item.$index\"\n [style.position]=\"item.invisible ? 'fixed' : null\"\n [style.left]=\"item.invisible ? '-99999px' : null\">\n <ng-template\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"{\n $implicit: item.data,\n index: item.$index,\n odd: item.$index % 2,\n even: !(item.$index % 2)\n }\"></ng-template>\n </div>\n <div data-padding-forward></div>"
},] }
];
UiScrollComponent.ctorParameters = function () { return [
{ type: ChangeDetectorRef },
{ type: ElementRef }
]; };
return UiScrollComponent;
}());
var UiScrollDirective = /** @class */ (function () {
function UiScrollDirective(templateRef, viewContainer, resolver) {
this.templateRef = templateRef;
this.viewContainer = viewContainer;
this.resolver = resolver;
}
Object.defineProperty(UiScrollDirective.prototype, "uiScrollOf", {
set: function (datasource) {
this.datasource = datasource;
},
enumerable: false,
configurable: true
});
UiScrollDirective.prototype.ngOnInit = function () {
var compFactory = this.resolver.resolveComponentFactory(UiScrollComponent);
var componentRef = this.viewContainer.createComponent(compFactory, void 0, this.viewContainer.injector);
componentRef.instance.datasource = this.datasource;
componentRef.instance.template = this.templateRef;
};
UiScrollDirective.decorators = [
{ type: Directive, args: [{ selector: '[uiScroll][uiScrollOf]' },] }
];
UiScrollDirective.ctorParameters = function () { return [
{ type: TemplateRef },
{ type: ViewContainerRef },
{ type: ComponentFactoryResolver }
]; };
UiScrollDirective.propDecorators = {
uiScrollOf: [{ type: Input }]
};
return UiScrollDirective;
}());
var UiScrollModule = /** @class */ (function () {
function UiScrollModule() {
}
UiScrollModule.decorators = [
{ type: NgModule, args: [{
declarations: [
UiScrollComponent,
UiScrollDirective
],
imports: [CommonModule],
entryComponents: [UiScrollComponent],
exports: [UiScrollDirective],
providers: []
},] }
];
return UiScrollModule;
}());
var getBooleanSubjectPropConfig = function () { return ({
source: new Subject(),
emit: function (source, value) { return source.next(value); }
}); };
var getItemBehaviorSubjectPropConfig = function () { return ({
source: new BehaviorSubject(EMPTY_ITEM),
emit: function (source, value) { return source.next(value); }
}); };
var getAdapterConfig = function () {
var _a;
return ({
mock: false,
reactive: (_a = {},
_a[AdapterPropName.init$] = getBooleanSubjectPropConfig(),
_a[AdapterPropName.isLoading$] = getBooleanSubjectPropConfig(),
_a[AdapterPropName.loopPending$] = getBooleanSubjectPropConfig(),
_a[AdapterPropName.firstVisible$] = getItemBehaviorSubjectPropConfig(),
_a[AdapterPropName.lastVisible$] = getItemBehaviorSubjectPropConfig(),
_a[AdapterPropName.bof$] = getBooleanSubjectPropConfig(),
_a[AdapterPropName.eof$] = getBooleanSubjectPropConfig(),
_a)
});
};
var AngularDatasource = makeDatasource(getAdapterConfig);
export { AngularDatasource as Datasource, UiScrollDirective, UiScrollModule, UiScrollComponent as ɵa };
//# sourceMappingURL=ngx-ui-scroll.js.map