pp-breadcrumbs
Version:
PP-Breadcrumbs is an Angular 10 library generating breadcrumbs based on the routing state.
2 lines • 4.08 kB
JavaScript
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/router"),require("rxjs"),require("lodash"),require("rxjs/operators"),require("@angular/common")):"function"==typeof define&&define.amd?define("pp-breadcrumbs",["exports","@angular/core","@angular/router","rxjs","lodash","rxjs/operators","@angular/common"],e):e((r=r||self)["pp-breadcrumbs"]={},r.ng.core,r.ng.router,r.rxjs,r.lodash,r.rxjs.operators,r.ng.common)}(this,(function(r,e,t,o,n,s,u){"use strict";var i=function(){function r(){}return r.prototype.resolve=function(r,e){var t=r.routeConfig.data,n=this.getFullPath(r),s="string"==typeof t.breadcrumbs?t.breadcrumbs:t.breadcrumbs.text||t.text||n;return o.of([{path:n,text:this.stringFormat(s,r.data)}])},r.prototype.getFullPath=function(r){return r.pathFromRoot.reduce((function(r,e){return r+e.url.reduce((function(r,e){return r+"/"+e.path}),"")}),"")},r.prototype.stringFormat=function(r,e){return n.template(r,{interpolate:/{{(.+?)}}/g})(e)},r}();i.decorators=[{type:e.Injectable}];var a=function(){function r(r,e){var n=this;this.router=r,this.injector=e,this.breadcrumbs=new o.BehaviorSubject([]),this.defaultResolver=new i,this.subscription=this.router.events.pipe(s.filter((function(r){return r instanceof t.NavigationEnd})),s.concatMap((function(){return n.onNavigationEnd()}))).subscribe(),this.onNavigationEnd().subscribe()}return Object.defineProperty(r.prototype,"crumbs$",{get:function(){return this.breadcrumbs.asObservable()},enumerable:!1,configurable:!0}),r.prototype.ngOnDestroy=function(){var r;null===(r=this.subscription)||void 0===r||r.unsubscribe(),this.breadcrumbs.complete()},r.prototype.onNavigationEnd=function(){var r=this;return this.resolveCrumbs(this.router.routerState.snapshot.root).pipe(s.mergeMap((function(r){return r})),s.distinct((function(r){return r.text})),s.toArray(),s.mergeMap((function(e){return r.postProcess?r.wrapIntoObservable(r.postProcess(e)).pipe(s.first()):o.of(e)})),s.tap((function(e){return r.breadcrumbs.next(e)})))},r.prototype.resolveCrumbs=function(r){var e,t=o.of([]),n=null===(e=r.routeConfig)||void 0===e?void 0:e.data;if(null==n?void 0:n.breadcrumbs){var u=this.getBreadcrumbResolver(n.breadcrumbs).resolve(r,this.router.routerState.snapshot);t=this.wrapIntoObservable(u).pipe(s.first())}return r.firstChild?o.concat(t,this.resolveCrumbs(r.firstChild)):t},r.prototype.getBreadcrumbResolver=function(r){return"function"==typeof r&&r.prototype instanceof i?this.injector.get(r):this.defaultResolver},r.prototype.wrapIntoObservable=function(r){return o.isObservable(r)?r:o.from(Promise.resolve(r))},r}();a.ɵprov=e.ɵɵdefineInjectable({factory:function(){return new a(e.ɵɵinject(t.Router),e.ɵɵinject(e.INJECTOR))},token:a,providedIn:"root"}),a.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}],a.ctorParameters=function(){return[{type:t.Router},{type:e.Injector}]};var c=function(){function r(r){this.service=r}return r.prototype.ngOnInit=function(){var r=this;this.subscription=this.service.crumbs$.subscribe((function(e){r.crumbs=e}))},r.prototype.ngOnDestroy=function(){var r;null===(r=this.subscription)||void 0===r||r.unsubscribe()},r}();c.decorators=[{type:e.Component,args:[{selector:"pp-breadcrumbs",template:'<ol *ngIf="crumbs.length" class="breadcrumb">\r\n <li *ngFor="let crumb of crumbs; let first = first; let last = last" [ngClass]="{ \'active\': last }" class="breadcrumb-item">\r\n <a *ngIf="!last; else lastBreadcrumb" [routerLink]="crumb.path" [innerHTML]="crumb.text"></a>\r\n <ng-template #lastBreadcrumb>\r\n <span [innerHTML]="crumb.text"></span>\r\n </ng-template>\r\n </li>\r\n</ol>\r\n',styles:[""]}]}],c.ctorParameters=function(){return[{type:a}]};var p=function(){};p.decorators=[{type:e.NgModule,args:[{declarations:[c],imports:[u.CommonModule,t.RouterModule],exports:[c]}]}],r.PpBreadcrumbsComponent=c,r.PpBreadcrumbsModule=p,r.PpBreadcrumbsResolver=i,r.PpBreadcrumbsService=a,Object.defineProperty(r,"__esModule",{value:!0})}));
//# sourceMappingURL=pp-breadcrumbs.umd.min.js.map