UNPKG

@jaspero/ng-helpers

Version:

[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) [![CircleCI](https://circleci.com/gh/Jaspero/ng-helpers.svg?style=svg)](https://circleci.

861 lines (831 loc) 39.1 kB
import { take, filter, debounceTime, finalize } from 'rxjs/operators'; import * as i1 from '@angular/common'; import { CommonModule } from '@angular/common'; import * as i0 from '@angular/core'; import { EventEmitter, Directive, Input, Output, NgModule, HostListener, InjectionToken, Inject, Host, Pipe } from '@angular/core'; import { fromEvent } from 'rxjs'; import * as i1$1 from '@angular/platform-browser'; function OnChange(callback) { const cachedValueKey = Symbol(); const isFirstChangeKey = Symbol(); return (target, key) => { Object.defineProperty(target, key, { set: function (value) { /** * Change status of "isFirstChange" */ this[isFirstChangeKey] = this[isFirstChangeKey] === undefined; /** * No operation if new value is same as old value */ if (!this[isFirstChangeKey] && this[cachedValueKey] === value) { return; } const oldValue = this[cachedValueKey]; this[cachedValueKey] = value; const simpleChange = { firstChange: this[isFirstChangeKey], previousValue: oldValue, currentValue: this[cachedValueKey], isFirstChange: () => this[isFirstChangeKey] }; callback.call(this, this[cachedValueKey], simpleChange); }, get: function () { return this[cachedValueKey]; } }); }; } /** * @param options * take: Number passed to take operator (0 skips operator) */ const JpFunction = (options = {}) => { return (target, propertyKey, descriptor) => { target[propertyKey] = function (...args) { const caller = /(\w+)@|at (\w+) \(/g.exec(Error().stack); const callerName = caller[1] || caller[2]; const pipeline = []; if (options.take !== 0) { pipeline.push(take(options.take || 1)); } return callerName === 'callHook' || callerName === 'invokeTask' ? descriptor.value .apply(this, args) .pipe(...pipeline) .subscribe() : () => descriptor.value.apply(this, args); }; return target; }; }; /** * Emits an event when a click action occurs that does not target the element * * @example * <div (jpClickOutside)="doSomething()"></div> */ class ClickOutsideDirective { _el; _ngZone; constructor(_el, _ngZone) { this._el = _el; this._ngZone = _ngZone; } /** * Any valid html event */ clickOutsideEventType = 'click'; /** * if true jpClickOutside doesn't emit */ clickOutsideBlock = false; /** * Emits when triggered event doesn't contain this e */ jpClickOutside = new EventEmitter(); subscription; ngAfterViewInit() { this._ngZone.runOutsideAngular(() => { this.subscription = fromEvent(window, this.clickOutsideEventType) .pipe(filter(event => !this.clickOutsideBlock && !this._el.nativeElement.contains(event.target))) .subscribe(event => { this._ngZone.run(() => { this.jpClickOutside.emit(event); }); }); }); } ngOnDestroy() { if (this.subscription) { this.subscription.unsubscribe(); } } /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ClickOutsideDirective, deps: [{ token: i0.ElementRef }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive }); /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.13", type: ClickOutsideDirective, selector: "[jpClickOutside]", inputs: { clickOutsideEventType: "clickOutsideEventType", clickOutsideBlock: "clickOutsideBlock" }, outputs: { jpClickOutside: "jpClickOutside" }, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ClickOutsideDirective, decorators: [{ type: Directive, args: [{ selector: '[jpClickOutside]' }] }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.NgZone }], propDecorators: { clickOutsideEventType: [{ type: Input }], clickOutsideBlock: [{ type: Input }], jpClickOutside: [{ type: Output }] } }); class ClickOutsideModule { /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ClickOutsideModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); /** @nocollapse */ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: ClickOutsideModule, declarations: [ClickOutsideDirective], imports: [CommonModule], exports: [ClickOutsideDirective] }); /** @nocollapse */ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ClickOutsideModule, imports: [CommonModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ClickOutsideModule, decorators: [{ type: NgModule, args: [{ imports: [ CommonModule ], declarations: [ ClickOutsideDirective ], exports: [ ClickOutsideDirective ] }] }] }); /** * Used for preventing propagation on event calls event.stopPropagation()) * * @example * <div (jpStopPropagation)="doSomething()"></div> */ class StopPropagationDirective { _renderer; _el; constructor(_renderer, _el) { this._renderer = _renderer; this._el = _el; } /** * Any valid html event */ stopPropagationEventType = 'click'; /** * Should preventDefault also be called */ preventDefault = false; condition; /** * Outputs the input event */ jpStopPropagation = new EventEmitter(); ngOnInit() { this._renderer.listen(this._el.nativeElement, this.stopPropagationEventType, event => { if (this.preventDefault) { event.preventDefault(); } if (this.condition !== undefined) { if (typeof this.condition === 'boolean') { if (this.condition) { this.sp(event); } } else if (this.condition(event)) { this.sp(event); } } else { this.sp(event); } }); } sp(event) { event.stopPropagation(); this.jpStopPropagation.emit(event); } /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: StopPropagationDirective, deps: [{ token: i0.Renderer2 }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.13", type: StopPropagationDirective, selector: "[jpStopPropagation]", inputs: { stopPropagationEventType: "stopPropagationEventType", preventDefault: "preventDefault", condition: "condition" }, outputs: { jpStopPropagation: "jpStopPropagation" }, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: StopPropagationDirective, decorators: [{ type: Directive, args: [{ selector: '[jpStopPropagation]' }] }], ctorParameters: () => [{ type: i0.Renderer2 }, { type: i0.ElementRef }], propDecorators: { stopPropagationEventType: [{ type: Input }], preventDefault: [{ type: Input }], condition: [{ type: Input }], jpStopPropagation: [{ type: Output }] } }); class StopPropagationModule { /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: StopPropagationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); /** @nocollapse */ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: StopPropagationModule, declarations: [StopPropagationDirective], imports: [CommonModule], exports: [StopPropagationDirective] }); /** @nocollapse */ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: StopPropagationModule, imports: [CommonModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: StopPropagationModule, decorators: [{ type: NgModule, args: [{ imports: [ CommonModule ], declarations: [ StopPropagationDirective ], exports: [ StopPropagationDirective ] }] }] }); class FormTouchOnHoverDirective { jpFormTouchOnHover; jpFormTouched = new EventEmitter(); enter() { if (Array.isArray(this.jpFormTouchOnHover)) { this.jpFormTouchOnHover.forEach(form => form.markAllAsTouched()); } else { this.jpFormTouchOnHover.markAllAsTouched(); } this.jpFormTouched.emit(); } /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormTouchOnHoverDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.13", type: FormTouchOnHoverDirective, selector: "[jpFormTouchOnHover]", inputs: { jpFormTouchOnHover: "jpFormTouchOnHover" }, outputs: { jpFormTouched: "jpFormTouched" }, host: { listeners: { "mouseenter": "enter()" } }, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormTouchOnHoverDirective, decorators: [{ type: Directive, args: [{ selector: '[jpFormTouchOnHover]' }] }], propDecorators: { jpFormTouchOnHover: [{ type: Input }], jpFormTouched: [{ type: Output }], enter: [{ type: HostListener, args: ['mouseenter'] }] } }); class FormTouchOnHoverModule { /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormTouchOnHoverModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); /** @nocollapse */ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: FormTouchOnHoverModule, declarations: [FormTouchOnHoverDirective], imports: [CommonModule], exports: [FormTouchOnHoverDirective] }); /** @nocollapse */ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormTouchOnHoverModule, imports: [CommonModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormTouchOnHoverModule, decorators: [{ type: NgModule, args: [{ imports: [ CommonModule ], declarations: [ FormTouchOnHoverDirective ], exports: [ FormTouchOnHoverDirective ] }] }] }); const DEBOUNCE_TIME = new InjectionToken('DEBOUNCE_TIME'); class DebounceChangeDirective { _el; _ngZone; _defaultDebounceTime; constructor(_el, _ngZone, _defaultDebounceTime) { this._el = _el; this._ngZone = _ngZone; this._defaultDebounceTime = _defaultDebounceTime; } /** * time to forward to the debounceTime pipe */ debounceTime; /** * Any valid html event */ debounceChangeEventType = 'keyup'; /** * If true and the event has a 'target.value' * we listen for it and only emit if the value changed */ emitOnlyOnChange = false; /** * Emits original event after debounce */ jpDebounceChange = new EventEmitter(); subscription; ngAfterViewInit() { this._ngZone.runOutsideAngular(() => { let prev = this._el.nativeElement.value; this.subscription = fromEvent(this._el.nativeElement, this.debounceChangeEventType) .pipe(debounceTime(this.debounceTime || this._defaultDebounceTime), filter(event => { return event.target && event.target.value !== undefined && this.emitOnlyOnChange ? event.target.value !== prev : true; })) .subscribe(event => { this._ngZone.run(() => { if (event.target) { prev = event.target.value; } this.jpDebounceChange.emit(event.target.value); }); }); }); } ngOnDestroy() { if (this.subscription) { this.subscription.unsubscribe(); } } /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DebounceChangeDirective, deps: [{ token: i0.ElementRef }, { token: i0.NgZone }, { token: DEBOUNCE_TIME }], target: i0.ɵɵFactoryTarget.Directive }); /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.13", type: DebounceChangeDirective, selector: "[jpDebounceChange]", inputs: { debounceTime: "debounceTime", debounceChangeEventType: "debounceChangeEventType", emitOnlyOnChange: "emitOnlyOnChange" }, outputs: { jpDebounceChange: "jpDebounceChange" }, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DebounceChangeDirective, decorators: [{ type: Directive, args: [{ selector: '[jpDebounceChange]' }] }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.NgZone }, { type: undefined, decorators: [{ type: Inject, args: [DEBOUNCE_TIME] }] }], propDecorators: { debounceTime: [{ type: Input }], debounceChangeEventType: [{ type: Input }], emitOnlyOnChange: [{ type: Input }], jpDebounceChange: [{ type: Output }] } }); class DebounceChangeModule { static defaultDebounceTime(value) { return { ngModule: DebounceChangeModule, providers: [ { provide: DEBOUNCE_TIME, useValue: value } ] }; } /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DebounceChangeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); /** @nocollapse */ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: DebounceChangeModule, declarations: [DebounceChangeDirective], imports: [CommonModule], exports: [DebounceChangeDirective] }); /** @nocollapse */ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DebounceChangeModule, providers: [ { provide: DEBOUNCE_TIME, useValue: 500 } ], imports: [CommonModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DebounceChangeModule, decorators: [{ type: NgModule, args: [{ imports: [ CommonModule ], declarations: [ DebounceChangeDirective ], exports: [ DebounceChangeDirective ], providers: [ { provide: DEBOUNCE_TIME, useValue: 500 } ] }] }] }); class TrackByFieldDirective { ngFor; defaultKey; ngForJpTrackByField; constructor(ngFor, defaultKey) { this.ngFor = ngFor; this.defaultKey = defaultKey; this.ngFor.ngForTrackBy = (index, item) => item[this.ngForJpTrackByField || this.defaultKey]; } /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TrackByFieldDirective, deps: [{ token: i1.NgForOf, host: true }, { token: 'defaultKey' }], target: i0.ɵɵFactoryTarget.Directive }); /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.13", type: TrackByFieldDirective, selector: "[ngForJpTrackByField]", inputs: { ngForJpTrackByField: "ngForJpTrackByField" }, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TrackByFieldDirective, decorators: [{ type: Directive, args: [{ // tslint:disable-next-line selector: '[ngForJpTrackByField]', }] }], ctorParameters: () => [{ type: i1.NgForOf, decorators: [{ type: Host }] }, { type: undefined, decorators: [{ type: Inject, args: ['defaultKey'] }] }], propDecorators: { ngForJpTrackByField: [{ type: Input }] } }); class TrackByFieldModule { static defaultKey(value = 'id') { return { ngModule: TrackByFieldModule, providers: [ { provide: 'defaultKey', useValue: value } ] }; } /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TrackByFieldModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); /** @nocollapse */ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: TrackByFieldModule, declarations: [TrackByFieldDirective], imports: [CommonModule], exports: [TrackByFieldDirective] }); /** @nocollapse */ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TrackByFieldModule, imports: [CommonModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TrackByFieldModule, decorators: [{ type: NgModule, args: [{ imports: [ CommonModule ], declarations: [ TrackByFieldDirective ], exports: [ TrackByFieldDirective ], }] }] }); const LOAD_CLICK_CLASS = new InjectionToken('LOAD_CLICK_CLASS'); /** * Directive will add loading class to the host element on click event * Usage: [jpLoadClick]="save()" * Function save() should return observable */ class LoadClickDirective { _el; _renderer; _defaultLoadClickClass; constructor(_el, _renderer, _defaultLoadClickClass) { this._el = _el; this._renderer = _renderer; this._defaultLoadClickClass = _defaultLoadClickClass; } jpLoadClick; loadClickEventType = 'click'; loadClickStopPropagation = false; loadClickPreventDefault = false; loadClickClass; disableAttribute = true; subscription; ngOnInit() { this._renderer.listen(this._el.nativeElement, this.loadClickEventType, event => { const defaultClass = this.loadClickClass || this._defaultLoadClickClass; if (this.loadClickStopPropagation) { event.stopPropagation(); } if (this.loadClickPreventDefault) { event.preventDefault(); } this._renderer.addClass(this._el.nativeElement, defaultClass); if (this.disableAttribute) { this._renderer.setAttribute(this._el.nativeElement, 'disabled', ''); } this.subscription = this.jpLoadClick() .pipe(finalize(() => { this._renderer.removeClass(this._el.nativeElement, defaultClass); if (this.disableAttribute) { this._renderer.removeAttribute(this._el.nativeElement, 'disabled'); } })) .subscribe(); }); } ngOnDestroy() { if (this.subscription) { this.subscription.unsubscribe(); } } /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: LoadClickDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: LOAD_CLICK_CLASS }], target: i0.ɵɵFactoryTarget.Directive }); /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.13", type: LoadClickDirective, selector: "[jpLoadClick]", inputs: { jpLoadClick: "jpLoadClick", loadClickEventType: "loadClickEventType", loadClickStopPropagation: "loadClickStopPropagation", loadClickPreventDefault: "loadClickPreventDefault", loadClickClass: "loadClickClass", disableAttribute: "disableAttribute" }, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: LoadClickDirective, decorators: [{ type: Directive, args: [{ selector: '[jpLoadClick]' }] }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: undefined, decorators: [{ type: Inject, args: [LOAD_CLICK_CLASS] }] }], propDecorators: { jpLoadClick: [{ type: Input }], loadClickEventType: [{ type: Input }], loadClickStopPropagation: [{ type: Input }], loadClickPreventDefault: [{ type: Input }], loadClickClass: [{ type: Input }], disableAttribute: [{ type: Input }] } }); class LoadClickModule { static defaultLoadingClass(value) { return { ngModule: LoadClickModule, providers: [ { provide: LOAD_CLICK_CLASS, useValue: value } ] }; } /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: LoadClickModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); /** @nocollapse */ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: LoadClickModule, declarations: [LoadClickDirective], imports: [CommonModule], exports: [LoadClickDirective] }); /** @nocollapse */ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: LoadClickModule, providers: [ { provide: LOAD_CLICK_CLASS, useValue: 'loading' } ], imports: [CommonModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: LoadClickModule, decorators: [{ type: NgModule, args: [{ imports: [ CommonModule ], declarations: [ LoadClickDirective ], exports: [ LoadClickDirective ], providers: [ { provide: LOAD_CLICK_CLASS, useValue: 'loading' } ] }] }] }); class DropZoneDirective { el; renderer; constructor(el, renderer) { this.el = el; this.renderer = renderer; } hoverClass = 'active'; dropped = new EventEmitter(); hovered = new EventEmitter(); onDrop($event) { $event.preventDefault(); this.dropped.emit($event.dataTransfer.files); if (this.hoverClass) { this.renderer.removeClass(this.el.nativeElement, this.hoverClass); } this.hovered.emit(false); } onDragOver($event) { $event.preventDefault(); if (this.hoverClass) { this.renderer.addClass(this.el.nativeElement, this.hoverClass); } this.hovered.emit($event); } onDragLeave($event) { $event.preventDefault(); // @ts-ignore if ($event.currentTarget.contains($event.relatedTarget)) { return; } this.renderer.removeClass(this.el.nativeElement, this.hoverClass); this.hovered.emit(false); } /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DropZoneDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive }); /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.13", type: DropZoneDirective, selector: "[jpDropZone]", inputs: { hoverClass: "hoverClass" }, outputs: { dropped: "dropped", hovered: "hovered" }, host: { listeners: { "drop": "onDrop($event)", "dragover": "onDragOver($event)", "dragleave": "onDragLeave($event)" } }, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DropZoneDirective, decorators: [{ type: Directive, args: [{ selector: '[jpDropZone]' }] }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.Renderer2 }], propDecorators: { hoverClass: [{ type: Input }], dropped: [{ type: Output }], hovered: [{ type: Output }], onDrop: [{ type: HostListener, args: ['drop', ['$event']] }], onDragOver: [{ type: HostListener, args: ['dragover', ['$event']] }], onDragLeave: [{ type: HostListener, args: ['dragleave', ['$event']] }] } }); class DropZoneModule { /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DropZoneModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); /** @nocollapse */ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: DropZoneModule, declarations: [DropZoneDirective], imports: [CommonModule], exports: [DropZoneDirective] }); /** @nocollapse */ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DropZoneModule, imports: [CommonModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DropZoneModule, decorators: [{ type: NgModule, args: [{ declarations: [DropZoneDirective], exports: [DropZoneDirective], imports: [CommonModule] }] }] }); /** * Returns an array of {key: number, value: string} objects. * Most useful in *ngFor iterations * * @example * <div *ngFor="let item of someEnum | enum></div> * */ class EnumPipe { transform(value) { const keys = []; for (const enumMember in value) { if (value[enumMember]) { const val = parseInt(enumMember, 10); if (!isNaN(val)) { keys.push({ key: val, value: value[enumMember] }); } } } return keys; } /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: EnumPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); /** @nocollapse */ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: EnumPipe, name: "jpEnum" }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: EnumPipe, decorators: [{ type: Pipe, args: [{ name: 'jpEnum' }] }] }); class EnumModule { /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: EnumModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); /** @nocollapse */ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: EnumModule, declarations: [EnumPipe], imports: [CommonModule], exports: [EnumPipe] }); /** @nocollapse */ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: EnumModule, imports: [CommonModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: EnumModule, decorators: [{ type: NgModule, args: [{ imports: [ CommonModule ], declarations: [ EnumPipe ], exports: [ EnumPipe ] }] }] }); /** * Applies the appropriate DomSanitizer method * to inputted value. * * @example * <div [innerHtml]="someHtmlValue | sanitize"></div> */ class SanitizePipe { _sanitizer; constructor(_sanitizer) { this._sanitizer = _sanitizer; } transform(value, type = 'html') { const sanitizeMap = { html: 'bypassSecurityTrustHtml', style: 'bypassSecurityTrustStyle', script: 'bypassSecurityTrustScript', url: 'bypassSecurityTrustUrl', resourceUrl: 'bypassSecurityTrustResourceUrl' }; return this._sanitizer[sanitizeMap[type]](value); } /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SanitizePipe, deps: [{ token: i1$1.DomSanitizer }], target: i0.ɵɵFactoryTarget.Pipe }); /** @nocollapse */ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: SanitizePipe, name: "jpSanitize" }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SanitizePipe, decorators: [{ type: Pipe, args: [{ name: 'jpSanitize' }] }], ctorParameters: () => [{ type: i1$1.DomSanitizer }] }); class SanitizeModule { /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SanitizeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); /** @nocollapse */ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: SanitizeModule, declarations: [SanitizePipe], imports: [CommonModule], exports: [SanitizePipe] }); /** @nocollapse */ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SanitizeModule, imports: [CommonModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SanitizeModule, decorators: [{ type: NgModule, args: [{ imports: [ CommonModule ], declarations: [ SanitizePipe ], exports: [ SanitizePipe ] }] }] }); var TimePassedType; (function (TimePassedType) { TimePassedType[TimePassedType["Millisecond"] = 0] = "Millisecond"; TimePassedType[TimePassedType["Second"] = 1] = "Second"; TimePassedType[TimePassedType["Minute"] = 2] = "Minute"; TimePassedType[TimePassedType["Hour"] = 3] = "Hour"; TimePassedType[TimePassedType["Day"] = 4] = "Day"; TimePassedType[TimePassedType["Month"] = 5] = "Month"; TimePassedType[TimePassedType["Year"] = 6] = "Year"; })(TimePassedType || (TimePassedType = {})); class TimePassedPipe { static timeDiff(dateOne, dateTwo = new Date(), type = TimePassedType.Day) { const oneDay = 24 * 60 * 60 * 1000; const minute = 60 * 1000; const hour = 60 * minute; const day = hour * 24; const durationMap = { [TimePassedType.Millisecond]: 1, [TimePassedType.Second]: 1000, [TimePassedType.Minute]: minute, [TimePassedType.Hour]: hour, [TimePassedType.Day]: day, [TimePassedType.Month]: day * 30, [TimePassedType.Year]: day * 365 }; return Math.round(Math.abs((dateOne.getTime() - dateTwo.getTime()) / durationMap[type])); } transform(dateOne, dateTwo, type) { if (!dateTwo) { dateTwo = new Date(); } return TimePassedPipe.timeDiff(dateOne, dateTwo, type !== undefined ? type : TimePassedType.Minute); } /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TimePassedPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); /** @nocollapse */ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: TimePassedPipe, name: "jpTimePassed" }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TimePassedPipe, decorators: [{ type: Pipe, args: [{ name: 'jpTimePassed' }] }] }); class TimePassedModule { /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TimePassedModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); /** @nocollapse */ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: TimePassedModule, declarations: [TimePassedPipe], imports: [CommonModule], exports: [TimePassedPipe] }); /** @nocollapse */ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TimePassedModule, imports: [CommonModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TimePassedModule, decorators: [{ type: NgModule, args: [{ imports: [CommonModule], declarations: [TimePassedPipe], exports: [TimePassedPipe] }] }] }); class EnumKeyFormatPipe { static defaultFormat(value) { return value .split(new RegExp('(?=[A-Z])')) .join(' '); } transform(value, enumValue, formatFunction = EnumKeyFormatPipe.defaultFormat) { return enumValue[value] ? formatFunction(enumValue[value]) : value; } /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: EnumKeyFormatPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); /** @nocollapse */ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: EnumKeyFormatPipe, name: "jpEnumKeyFormat" }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: EnumKeyFormatPipe, decorators: [{ type: Pipe, args: [{ name: 'jpEnumKeyFormat' }] }] }); class EnumKeyFormatModule { /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: EnumKeyFormatModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); /** @nocollapse */ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: EnumKeyFormatModule, declarations: [EnumKeyFormatPipe], imports: [CommonModule], exports: [EnumKeyFormatPipe] }); /** @nocollapse */ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: EnumKeyFormatModule, imports: [CommonModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: EnumKeyFormatModule, decorators: [{ type: NgModule, args: [{ imports: [ CommonModule ], declarations: [ EnumKeyFormatPipe ], exports: [ EnumKeyFormatPipe ] }] }] }); /* * Public API Surface of ng-helpers */ /** * Decorators */ /** * Generated bundle index. Do not edit. */ export { ClickOutsideDirective, ClickOutsideModule, DEBOUNCE_TIME, DebounceChangeDirective, DebounceChangeModule, DropZoneDirective, DropZoneModule, EnumKeyFormatModule, EnumKeyFormatPipe, EnumModule, EnumPipe, FormTouchOnHoverDirective, FormTouchOnHoverModule, JpFunction, LOAD_CLICK_CLASS, LoadClickDirective, LoadClickModule, OnChange, SanitizeModule, SanitizePipe, StopPropagationDirective, StopPropagationModule, TimePassedModule, TimePassedPipe, TimePassedType, TrackByFieldDirective, TrackByFieldModule }; //# sourceMappingURL=jaspero-ng-helpers.mjs.map