@ngrdt/router 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as t from"@angular/core";import{InjectionToken as e,inject as r,EnvironmentInjector as a,runInInjectionContext as s,makeEnvironmentProviders as i,Injectable as n,DestroyRef as o,Renderer2 as h,ElementRef as l,Input as u,Directive as c,afterNextRender as p,input as d,linkedSignal as m,booleanAttribute as g,computed as v,effect as f}from"@angular/core";import{Location as y,PlatformLocation as b}from"@angular/common";import*as R from"@angular/router";import{Router as _,NavigationEnd as P,RouterModule as A,RouterLink as C,GuardsCheckStart as w}from"@angular/router";import{RdtViewStateService as D}from"@ngrdt/core";import{RdtStringUtils as E}from"@ngrdt/utils";import{filter as M,take as k,fromEvent as q}from"rxjs";import{takeUntilDestroyed as x}from"@angular/core/rxjs-interop";import{RDT_BUTTON_BASE_PROVIDER as U}from"@ngrdt/button";const B=new e("RDT_CANNOT_BE_ENTERED",{factory:()=>{},providedIn:"root"});class I{params;constructor(t={}){this.params=t}get(t){return this.params[t.absolutePath]??null}set(t,e){return this.params[t.absolutePath]=e,this}append(t,e){const r=this.get(t)??{};return this.params[t.absolutePath]={...r,...e},this}setAll(t){return this.params={...this.params,...t.params},this}*[Symbol.iterator](){const t=Object.keys(this.params);t.sort((t,e)=>t.length-e.length);for(const e of t)yield[e,this.params[e]]}}function L(){return!0}var N;!function(t){t.BREADCRUMB="breadcrumb"}(N||(N={}));class S{route;children=[];loadComponent;loadChildren;component;providers=[];providersForChildren=[];resolvers={};canActivate=[];canActivateChild=[];canDeactivate=[];runGuardsAndResolvers;data;constructor(t){this.route=t}provide(...t){return this.providers.push(...t),this}provideToChildren(...t){return this.providersForChildren.push(...t),this.providers.push(...t),this}withLazyComponent(t){return this.loadComponent=t,this}withModule(t){return this.loadChildren=t,this}setModule(t){return this.loadChildren=t,this}withComponent(t){return this.component=t,this}setComponent(t){return this.withComponent(t)}withChildren(...t){return this.children=t,this}setChildren(...t){return this.withChildren(...t)}addResolve(t,e){return this.resolvers[t]=e,this}addCanActivate(...t){return this.canActivate.push(...t),this}addCanDeactivate(...t){return this.canDeactivate.push(...t),this}addCanActivateChild(...t){return this.canActivateChild.push(...t),this}withRunGuardsAndResolvers(t){return this.runGuardsAndResolvers=t,this}setRunGuardsAndResolvers(t){return this.withRunGuardsAndResolvers(t)}build(){this.checkChildrenMatch();let t={path:this.route.path,providers:this.providers,title:this.route.name,canMatch:this.getCanMatch()};if(this.component?t.component=this.component:this.loadChildren?t.loadChildren=this.loadChildren:this.loadComponent&&(t.loadComponent=this.loadComponent),t.data=this.data??{breadcrumb:{label:this.route.name,disable:this.route.entryDisabled,staticStateParams:{src:N.BREADCRUMB}},...this.route.data},this.canActivate.push((t,e)=>{const i=r(a),n=r(T).parseAbsoluteUrl(e.url),o=n?.params??{params:{},query:{},state:{},route:new I};if(o.query=t.queryParams,s(i,()=>this.route.canBeEnteredFn(n?.route??this.route,o)))return!0;{const t=r(_),a=r(y);let o=r(B);return"function"==typeof o&&(o=s(i,o.bind(o,a.path(),e.url,n?.route??this.route))),"string"==typeof o&&t.parseUrl(o)}}),t.canActivate=this.canActivate,t.canDeactivate=this.canDeactivate,this.providersForChildren.length>0&&this.children.forEach(t=>this.provideToChildrenRec(t)),this.children.length>0)if(this.loadChildren||this.component||this.loadComponent){const e=t.path;t.path="",t.pathMatch="full",t.canMatch=void 0,t={path:e,pathMatch:"prefix",children:[t,...this.children],canActivateChild:this.canActivateChild,canMatch:this.getCanMatch(),data:t.data,providers:t.providers,canActivate:t.canActivate,canDeactivate:t.canDeactivate}}else t.children=this.children;return Object.keys(this.resolvers).length>0&&(t.resolve=this.resolvers),this.runGuardsAndResolvers&&(t.runGuardsAndResolvers=this.runGuardsAndResolvers),t}getCanMatch(){const t=this.route.paramMap;if(!Object.keys(t).some(e=>"number"===t[e]||Array.isArray(t[e])))return;const e=this.route.path.split("/").length,r=this.route.regex?new RegExp(`^${this.route.regex.source}$`):this.route.absoluteRegex;return[(t,a)=>{const s=a.slice(0,e).map(t=>t.path).join("/");return r.test(s)}]}provideToChildrenRec(t){t.providers||(t.providers=[]),this.providersForChildren.forEach(e=>{"object"==typeof e&&"provide"in e&&t.providers.some(t=>"object"==typeof t&&"provide"in t&&t.provide===e.provide)||t.providers.unshift(e)}),t.children&&t.children.forEach(t=>this.provideToChildrenRec(t))}checkChildrenMatch(){if(!this.loadChildren&&(this.route.children.length>0||this.children.length>0)){if(this.children.length<this.route.children.length)throw new Error(`RdtRoute ${this.route.name} has ${this.route.children.length} children, but RdtAngularRoute has ${this.children.length}. These numbers must match. Did you forget to call .setChildren() method in global routes definition? Routes with following names should be present: ${this.route.children.map(t=>t.name).join(", ")}`);if(this.children.length>this.route.children.length)throw new Error(`RdtRoute ${this.route.name} has ${this.route.children.length} children, but RdtAngularRoute has ${this.children.length}. These numbers must match. Did you forget to call .setChildren() method in feature shell routes definition? Routes with following paths should be present: ${this.children.map(t=>t.path).join(", ")}`);const t=this.children.map(t=>t.path),e=this.route.children.map(t=>t.path);t.sort(),e.sort();for(let r=0;r<t.length;r++)if(t[r]!==e[r])throw new Error(`Paths of children provided in RdtRoute and\n RdtAngularRoute do not match. ${t[r]} != ${e[r]}`)}}}class ${_orderedParams=[];_paramMap={};_regex=null;_paramMappings=[];_name;_path;_parent=null;_children=[];_entryDisabled=!1;_canBeEntered=L;_data={};get data(){return this._data}get regex(){return this._regex}get entryDisabled(){return this._entryDisabled}get paramMap(){return this._paramMap}get name(){return this._name}get path(){return this._path}get parent(){return this._parent}get children(){return this._children}}class j extends ${_absoluteRegex;_staticParams={};_queryParams={};_stateParams={};get basePath(){return this._parent?this._parent.absolutePath:"/"}get absolutePath(){return E.joinPaths(this.basePath,this._path)}get absoluteRegex(){if(this._absoluteRegex)return this._absoluteRegex;if(this._regex)if(this._parent){const t=this._parent.absoluteRegex.source.slice(1,-1);this._absoluteRegex=new RegExp("^"+E.joinPaths(t,this._regex.source)+"$")}else this._absoluteRegex=new RegExp("^"+E.joinPaths("/",this._regex.source)+"$");else if(this._absoluteRegex=new RegExp("^/$"),this._parent)throw new Error("Nested route with empty path is not allowed.");return this._absoluteRegex}get stateParams(){return this._stateParams}get queryParams(){return this._queryParams}testUrl(t){return this.absoluteRegex.test(t)}get staticParams(){return{...this._staticParams}}get hasCanBeEnteredGuard(){return this._canBeEntered!==L}canBeEntered(t,e={}){const r=this.getStaticParams();let a=this._queryParams,i=this._stateParams;e.params&&r.set(this,e.params),e.route&&r.setAll(e.route),e.query&&(a={...a,...e.query}),e.state&&(i={...i,...e.state});let n=this;for(;n;){const e={params:r.get(n)??{},route:r,query:a,state:i};if(t){const r=n;if(!s(t,()=>r._canBeEntered(r,e)))return!1}else if(!n._canBeEntered(n,e))return!1;n=n._parent}return!0}get canBeEnteredFn(){return this._canBeEntered}parseAbsoluteUrl(t){const e=E.stripQueryParams(t),r=this.absoluteRegex.exec(e);if(r){const e=E.parseQueryParams(t),a=r.slice(1).reverse(),s=this.fill(a),i=new I(s);return{params:i.get(this)??{},route:i,query:e,state:{}}}return null}fill(t,e={}){const r={},a=this._orderedParams.slice().reverse();for(let e=0;e<a.length&&e<t.length;e++){const s=a[e],i=this._paramMappings.find(t=>t.urlName===s)?.tableName??s;let n=decodeURIComponent(t[e]);"number"===this._paramMap[s]&&(n=parseInt(n)),r[i]=n}return e[this.absolutePath]=r,t.length>a.length&&this._parent&&this._parent.fill(t.slice(a.length),e),e}createAbsoluteUrl(t=this._staticParams){return this._parent?E.joinPaths(this._parent.createAbsoluteUrl(),this.createRelativeUrl(t)):this.createUrl(this.absolutePath,t)}createRelativeUrl(t=this._staticParams){return this.createUrl(this.path,t)}createUrl(t,e){const r=Object.keys(this._paramMap);r.sort((t,e)=>e.length-t.length);const a={...e};return this._paramMappings.forEach(t=>{t.tableName in e&&(a[t.urlName]=e[t.tableName])}),r.forEach(e=>{if(!(e in a))throw new Error(`Param ${e} is missing for route ${this.absolutePath}. Please pass object with required parameters.`);const r=a[e],s=this._paramMap[e];if(Array.isArray(s)&&!s.includes(`${r}`))throw new Error(`Value "${r}" is not allowed for enum param "${e}" in route ${this.absolutePath}. Allowed values: ${s.join(", ")}`);t=t.replace(`:${e}`,encodeURIComponent(`${r}`))}),t}toAngularRoute(){return new S(this)}withParamMappings(t){const e=this.clone();return e._paramMappings=t,e}withStaticParams(t,e){const r=this.clone();if(e){const a=t.absolutePath;let s=r;for(;s;)s.absolutePath===a&&(s._staticParams=e),s=s._parent}else r._staticParams=t;return r}withQueryParams(t){const e=this.clone();return e._queryParams={...t},e}withStateParams(t){const e=this.clone();return e._stateParams={...t},e}extractRouteParams(t){const e={};return this._orderedParams.forEach(r=>{const a=this._paramMappings.find(t=>t.urlName===r),s=a?.tableName??r;s in t&&(e[s]=t[s])}),e}getStaticParams(){const t=new I;let e=this;for(;e;)t.set(e,e._staticParams),e=e._parent;return t}clone(){const t=new j;return t._name=this._name,t._parent=this._parent?.clone()??null,t._path=this.path,t._entryDisabled=this._entryDisabled,t._orderedParams=[...this._orderedParams],t._paramMap={...this._paramMap},t._regex=this._regex?new RegExp(this._regex):null,t._paramMappings=this._paramMappings,t._staticParams={...this._staticParams},t._stateParams={...this._stateParams},t._canBeEntered=this._canBeEntered,t._queryParams={...this._queryParams},t}static getGroup(t){return Array.isArray(t)?"("+t.map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|")+")":j.groups[t]}setRegex(){const t=Object.keys(this._paramMap);t.sort((t,e)=>e.length-t.length);let e=this.path;t.forEach(t=>{const r=this._paramMap[t];if(!r)throw new Error("Params is not set i");e=e.replace(`:${t}`,j.getGroup(r))}),this._regex=""===e?null:new RegExp(e)}static fromBuilder(t){const e=new j;return e._name=t.name,e._path=t.path,e._entryDisabled=t.entryDisabled,e._orderedParams=t.orderedParams,e._canBeEntered=t.canBeEntered,e._paramMap=t.paramMap,e._regex=t.regex?new RegExp(t.regex):null,e._paramMappings=t.paramMappings,e._children=t.children,e._data=t.data,e._children.forEach(t=>t._parent=e),e.setRegex(),e}static groups={string:"([^/]+)",number:"(-?\\d+)"}}const O=new e("RDT_ROUTES_PROVIDER");function F(t){const e=Array.isArray(t)?t:Object.values(t).filter(t=>t instanceof j);return i([{provide:O,useValue:e}])}const V="RdtStateParams";class T{allRoutes=r(O,{optional:!0});baseHref=r(b).getBaseHrefFromDOM();location=r(y);router=r(_);viewStateService=r(D,{optional:!0});_previousUrl=null;_currentUrl=null;get previousUrl(){return this._previousUrl}get currentUrl(){return this._currentUrl}parsePreviousUrl(){return this._previousUrl?this.parseAbsoluteUrl(this._previousUrl):null}parseCurrentUrl(){return this._currentUrl?this.parseAbsoluteUrl(this._currentUrl):null}navigationEnd$=this.router.events.pipe(M(t=>t instanceof P));nextNavigationEnd$=this.navigationEnd$.pipe(k(1));constructor(){null===this.allRoutes&&(console.warn("All routes not provided. Make sure to provide RDT_ROUTES_PROVIDER with RdtRoute[]."),this.allRoutes=[]),this.navigationEnd$.subscribe(t=>{this._previousUrl=this._currentUrl,this._currentUrl=t.url})}getHistoryState(){return"RdtStateParams"in window&&"object"==typeof window[V]?{...window[V],...history.state??{}}:history.state??{}}navigate(t,e,r){let a;if(e instanceof I){let r=t;for(let t=r;null!==t;t=t.parent){const a=e.get(t);a&&(r=r.withStaticParams(t,a))}a=r.createAbsoluteUrl()}else a=e?t.createAbsoluteUrl(e):t.createAbsoluteUrl();const s=r?.target??"_self",i=r?.query??t.queryParams,n=r?.state??t.stateParams;if("_self"===s)return this.router.navigate([a],{queryParams:i,state:n,replaceUrl:r?.replaceUrl});const o=E.createAbsoluteUrl(a,this.baseHref),h=E.appendQueryParams(o,i),l=window.open(h,s);return l&&(l[V]=n),Promise.resolve(!0)}navigateHome(t){return this.router.navigateByUrl(E.appendQueryParams("/",t?.query??{}),{state:t?.state,replaceUrl:t?.replaceUrl})}navigateBack(t){const e=this.parseAbsoluteUrl();if(e){let r=e.route.withStaticParams(e.params);do{r=r.parent}while(r&&r.entryDisabled);return r?(t&&(t.query&&(r=r.withQueryParams(t.query)),t.state&&(r=r.withStateParams(t.state))),this.viewStateService?.markNextAsRestore(),this.navigate(r,t)):this.navigateHome(t)}return console.warn(`Cannot go back from ${this.location.path()} because no route matches current url`),null}parseAbsoluteUrl(t=this.location.path()){const e=E.stripQueryParams(t);if(this.allRoutes)for(const t of this.allRoutes){const r=t.parseAbsoluteUrl(e);if(r)return{route:t,params:r}}return null}extractAllParams(t){if(!t){const e=this.parseAbsoluteUrl();if(!e)return console.warn("No route matches current url."),null;t=e.route}const e=this.location.path();return t.parseAbsoluteUrl(e)}isParentOfCurrentLocation(t){return!0}removeQueryParams(...t){const e=new RegExp(`[?&](${t.join("|")})=[^&]*`,"g");return history.replaceState(history.state,"",location.pathname+location.search.replace(e,"").replace(/^&/,"?"))}static"ɵfac"=t.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"21.1.2",ngImport:t,type:T,deps:[],target:t.ɵɵFactoryTarget.Injectable});static"ɵprov"=t.ɵɵngDeclareInjectable({minVersion:"12.0.0",version:"21.1.2",ngImport:t,type:T,providedIn:"root"})}t.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"21.1.2",ngImport:t,type:T,decorators:[{type:n,args:[{providedIn:"root"}]}],ctorParameters:()=>[]});class G extends ${get canBeEntered(){return this._canBeEntered}get orderedParams(){return this._orderedParams}get paramMappings(){return this._paramMappings}withCanBeEntered(t){return this._canBeEntered=t,this}setCanBeEntered(t){return this.withCanBeEntered(t)}withEntryDisabled(t=!0){return this._entryDisabled=t,this}setEntryDisabled(t=!0){return this.withEntryDisabled(t)}withPath(t){this._path=t;const e=t.split("/"),r=[];return e.forEach(t=>{if(t.includes(":")){const e=t.split(":")[1];e&&(r.push(e),this._paramMap[e]||(this._paramMap[e]="number"))}}),this._orderedParams=r,this}setPath(t){return this.withPath(t)}withData(t){return this._data=t,this}setData(t){return this.withData(t)}withParam(t,e){return this._paramMap[t]=e,this}setParam(t,e){return this.withParam(t,e)}withName(t){return this._name=t,this}setName(t){return this.withName(t)}withChildren(...t){return this._children=t,this}setChildren(...t){return this.withChildren(...t)}build(){if("string"!=typeof this._path)throw new Error("Please provide path for route. Empty string is acceptable.");return j.fromBuilder(this)}}const H={paths:"exact",queryParams:"exact",fragment:"ignored",matrixParams:"ignored"},Q={paths:"subset",queryParams:"subset",fragment:"ignored",matrixParams:"ignored"};class W{destroyRef=r(o);router=r(_);renderer=r(h);elRef=r(l);set anyRouteActive(t){this.classes=this.parseClasses(t)}watchedRoutes=[];set anyRouteActiveOptions(t){this._anyRouteActiveOptions=this.parseOptions(t)}_anyRouteActiveOptions=Q;ariaCurrentWhenActive;get isActive(){return this._isActive}_isActive=!1;classes=[];ngOnInit(){this.update(),this.listenRouterEvents()}ngOnChanges(t){t.anyRouteActive?.previousValue&&this.parseClasses(t.anyRouteActive.previousValue).forEach(t=>this.removeClass(t)),this.update()}update(){this._isActive=this.watchedRoutes.some(t=>{const e="string"==typeof t?t:this.router.createUrlTree(t);return this.router.isActive(e,this._anyRouteActiveOptions)}),this.setClasses(),this.setAriaCurrent()}setAriaCurrent(){const t=this.elRef.nativeElement;if(this._isActive&&void 0!==this.ariaCurrentWhenActive){const e=this.ariaCurrentWhenActive.toString();this.renderer.setAttribute(t,"aria-current",e)}else this.renderer.removeAttribute(t,"aria-current")}setClasses(){this._isActive?this.classes.forEach(t=>this.addClass(t)):this.classes.forEach(t=>this.removeClass(t))}addClass(t){this.renderer.addClass(this.elRef.nativeElement,t)}removeClass(t){this.renderer.removeClass(this.elRef.nativeElement,t)}listenRouterEvents(){this.router.events.pipe(M(t=>t instanceof P),x(this.destroyRef)).subscribe(()=>this.update())}parseClasses(t){return(Array.isArray(t)?t:t.split(" ")).filter(t=>!!t)}parseOptions(t){return"exact"in t?t.exact?H:Q:t}static"ɵfac"=t.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"21.1.2",ngImport:t,type:W,deps:[],target:t.ɵɵFactoryTarget.Directive});static"ɵdir"=t.ɵɵngDeclareDirective({minVersion:"14.0.0",version:"21.1.2",type:W,isStandalone:!0,selector:"[rdtAnyRouteActive]",inputs:{anyRouteActive:["rdtAnyRouteActive","anyRouteActive"],watchedRoutes:"watchedRoutes",anyRouteActiveOptions:"anyRouteActiveOptions",ariaCurrentWhenActive:"ariaCurrentWhenActive"},providers:[A],usesOnChanges:!0,ngImport:t})}t.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"21.1.2",ngImport:t,type:W,decorators:[{type:c,args:[{selector:"[rdtAnyRouteActive]",standalone:!0,providers:[A]}]}],propDecorators:{anyRouteActive:[{type:u,args:[{required:!0,alias:"rdtAnyRouteActive"}]}],watchedRoutes:[{type:u,args:[{required:!0}]}],anyRouteActiveOptions:[{type:u}],ariaCurrentWhenActive:[{type:u}]}});class z{destroyRef=r(o);location=r(y);elRef=r(l);buttonClass=r(U);buttonRef=r(this.buttonClass,{optional:!0,host:!0});constructor(){p(()=>{this.buttonRef?this.buttonRef.click.subscribe(()=>this.location.back()):q(this.elRef.nativeElement,"click").pipe(x(this.destroyRef)).subscribe(()=>this.location.back())})}static"ɵfac"=t.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"21.1.2",ngImport:t,type:z,deps:[],target:t.ɵɵFactoryTarget.Directive});static"ɵdir"=t.ɵɵngDeclareDirective({minVersion:"14.0.0",version:"21.1.2",type:z,isStandalone:!0,selector:"[rdtBackLink]",ngImport:t})}t.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"21.1.2",ngImport:t,type:z,decorators:[{type:c,args:[{selector:"[rdtBackLink]"}]}],ctorParameters:()=>[]});const J=Symbol();class K{buttonClass=r(U);buttonRef=r(this.buttonClass,{host:!0,optional:!0});routerLinkRef=r(C,{self:!0});envInjector=r(a);routeInput=d.required({...ngDevMode?{debugName:"routeInput"}:{},alias:"rdtRouterLink"});route=m(()=>this.routeInput(),...ngDevMode?[{debugName:"route"}]:[]);target=d("_self",...ngDevMode?[{debugName:"target"}]:[]);params=d(...ngDevMode?[void 0,{debugName:"params"}]:[]);queryParams=d(...ngDevMode?[void 0,{debugName:"queryParams"}]:[]);stateParams=d(...ngDevMode?[void 0,{debugName:"stateParams"}]:[]);disabled=d(!1,{...ngDevMode?{debugName:"disabled"}:{},alias:"rdtDisabled",transform:g});canBeEntered=v(()=>{const t=this.route(),e=this.disabled();if(!t||e)return!1;const r={params:this.params(),query:this.queryParams(),state:this.stateParams()};return t.canBeEntered(this.envInjector,r)},...ngDevMode?[{debugName:"canBeEntered"}]:[]);updateEffect=f(()=>{this.buttonRef?this.updateButton():this.updateRouterLink()},...ngDevMode?[{debugName:"updateEffect"}]:[]);updateButton(){const t=this.route();t?this.canBeEntered()?this.setButtonLink(t):this.disableButtonLink():this.clearButtonLink()}setButtonLink(t){const e=this.buttonRef;try{const r=this.getNgHref(t);e.ngHref.set(r),e.stateParams.set(this.stateParams()??t.stateParams),e.queryParams.set(this.queryParams()??t.queryParams),e.setDisabledState(!1,J)}catch(t){console.error(t),this.disableButtonLink()}}disableButtonLink(){const t=this.buttonRef;t.ngHref.set(null),t.setDisabledState(!0,J)}clearButtonLink(){const t=this.buttonRef;t.ngHref.set(null),t.stateParams.set(void 0),t.queryParams.set(void 0),t.setDisabledState(!1,J)}updateRouterLink(){const t=this.route();t?this.canBeEntered()?this.setRouterLink(t):this.disableRouterLink():this.clearRouterLink()}setRouterLink(t){try{const e=this.getNgHref(t);this.routerLinkRef.routerLink=e,this.routerLinkRef.state=this.stateParams()??t.stateParams,this.routerLinkRef.queryParams=this.queryParams()??t.queryParams,this.routerLinkRef.ngOnChanges({})}catch(t){console.error(t),this.disableRouterLink()}}disableRouterLink(){this.routerLinkRef.routerLink=null,this.routerLinkRef.ngOnChanges({})}clearRouterLink(){this.routerLinkRef.routerLink=null,this.routerLinkRef.state=void 0,this.routerLinkRef.queryParams=void 0,this.routerLinkRef.ngOnChanges({})}getNgHref(t){return t.createAbsoluteUrl(this.params())}static"ɵfac"=t.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"21.1.2",ngImport:t,type:K,deps:[],target:t.ɵɵFactoryTarget.Directive});static"ɵdir"=t.ɵɵngDeclareDirective({minVersion:"17.1.0",version:"21.1.2",type:K,isStandalone:!0,selector:"[rdtRouterLink]",inputs:{routeInput:{classPropertyName:"routeInput",publicName:"rdtRouterLink",isSignal:!0,isRequired:!0,transformFunction:null},target:{classPropertyName:"target",publicName:"target",isSignal:!0,isRequired:!1,transformFunction:null},params:{classPropertyName:"params",publicName:"params",isSignal:!0,isRequired:!1,transformFunction:null},queryParams:{classPropertyName:"queryParams",publicName:"queryParams",isSignal:!0,isRequired:!1,transformFunction:null},stateParams:{classPropertyName:"stateParams",publicName:"stateParams",isSignal:!0,isRequired:!1,transformFunction:null},disabled:{classPropertyName:"disabled",publicName:"rdtDisabled",isSignal:!0,isRequired:!1,transformFunction:null}},hostDirectives:[{directive:R.RouterLink,inputs:["target","target","replaceUrl","replaceUrl"]}],ngImport:t})}t.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"21.1.2",ngImport:t,type:K,decorators:[{type:c,args:[{selector:"[rdtRouterLink]",standalone:!0,hostDirectives:[{directive:C,inputs:["target","replaceUrl"]}]}]}],propDecorators:{routeInput:[{type:t.Input,args:[{isSignal:!0,alias:"rdtRouterLink",required:!0}]}],target:[{type:t.Input,args:[{isSignal:!0,alias:"target",required:!1}]}],params:[{type:t.Input,args:[{isSignal:!0,alias:"params",required:!1}]}],queryParams:[{type:t.Input,args:[{isSignal:!0,alias:"queryParams",required:!1}]}],stateParams:[{type:t.Input,args:[{isSignal:!0,alias:"stateParams",required:!1}]}],disabled:[{type:t.Input,args:[{isSignal:!0,alias:"rdtDisabled",required:!1}]}]}});const X=t=>!t.guardRegistry.hasLeaveBlockers()||t.guardRegistry.canLeaveAll();class Y{router=r(_);ensureGlobalGuards(){let t="";this.router.events.subscribe(e=>{if(e instanceof P&&(t=location.href),e instanceof w){let r=e.state.root;for(;r?.firstChild;)r=r.firstChild;history.replaceState(window.history.state,"",t),r?.routeConfig&&this.ensureCanDeactivateGuards(r.routeConfig)}})}ensureCanDeactivateGuards(t){t.canDeactivate||(t.canDeactivate=[]);const e=t.canDeactivate;e.find(t=>t==X)||e.push(X)}static"ɵfac"=t.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"21.1.2",ngImport:t,type:Y,deps:[],target:t.ɵɵFactoryTarget.Injectable});static"ɵprov"=t.ɵɵngDeclareInjectable({minVersion:"12.0.0",version:"21.1.2",ngImport:t,type:Y,providedIn:"root"})}t.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"21.1.2",ngImport:t,type:Y,decorators:[{type:n,args:[{providedIn:"root"}]}]});export{Y as GlobalRouteGuardService,J as PERMISSION_DISABLED_KEY,B as RDT_CANNOT_BE_ENTERED_PROVIDER,O as RDT_ROUTES_PROVIDER,S as RdtAngularRoute,W as RdtAnyRouteActiveDirective,z as RdtBackLinkDirective,N as RdtNavigationSource,I as RdtParameters,j as RdtRoute,G as RdtRouteBuilder,K as RdtRouterLinkDirective,T as RdtRouterService,X as preventDataLossGuardFn,F as provideRdtRoutes};
|
|
1
|
+
import*as t from"@angular/core";import{InjectionToken as e,inject as r,EnvironmentInjector as a,runInInjectionContext as s,makeEnvironmentProviders as i,Injectable as n,DestroyRef as o,Renderer2 as h,ElementRef as l,Input as u,Directive as c,afterNextRender as p,input as d,linkedSignal as m,booleanAttribute as g,computed as v,effect as f}from"@angular/core";import{Location as y,PlatformLocation as b}from"@angular/common";import*as R from"@angular/router";import{Router as _,NavigationEnd as P,RouterModule as A,RouterLink as C,GuardsCheckStart as w}from"@angular/router";import{RdtViewStateService as D}from"@ngrdt/core";import{RdtStringUtils as E}from"@ngrdt/utils";import{filter as M,take as k,fromEvent as q}from"rxjs";import{takeUntilDestroyed as x}from"@angular/core/rxjs-interop";import{RDT_BUTTON_BASE_PROVIDER as U}from"@ngrdt/button";const B=new e("RDT_CANNOT_BE_ENTERED",{factory:()=>{},providedIn:"root"});class I{params;constructor(t={}){this.params=t}get(t){return this.params[t.absolutePath]??null}set(t,e){return this.params[t.absolutePath]=e,this}append(t,e){const r=this.get(t)??{};return this.params[t.absolutePath]={...r,...e},this}setAll(t){return this.params={...this.params,...t.params},this}*[Symbol.iterator](){const t=Object.keys(this.params);t.sort((t,e)=>t.length-e.length);for(const e of t)yield[e,this.params[e]]}}function L(){return!0}var N;!function(t){t.BREADCRUMB="breadcrumb"}(N||(N={}));class S{route;children=[];loadComponent;loadChildren;component;providers=[];providersForChildren=[];resolvers={};canActivate=[];canActivateChild=[];canDeactivate=[];runGuardsAndResolvers;data;constructor(t){this.route=t}provide(...t){return this.providers.push(...t),this}provideToChildren(...t){return this.providersForChildren.push(...t),this.providers.push(...t),this}withLazyComponent(t){return this.loadComponent=t,this}withModule(t){return this.loadChildren=t,this}setModule(t){return this.loadChildren=t,this}withComponent(t){return this.component=t,this}setComponent(t){return this.withComponent(t)}withChildren(...t){return this.children=t,this}setChildren(...t){return this.withChildren(...t)}addResolve(t,e){return this.resolvers[t]=e,this}addCanActivate(...t){return this.canActivate.push(...t),this}addCanDeactivate(...t){return this.canDeactivate.push(...t),this}addCanActivateChild(...t){return this.canActivateChild.push(...t),this}withRunGuardsAndResolvers(t){return this.runGuardsAndResolvers=t,this}setRunGuardsAndResolvers(t){return this.withRunGuardsAndResolvers(t)}build(){this.checkChildrenMatch();let t={path:this.route.path,providers:this.providers,title:this.route.name,canMatch:this.getCanMatch()};if(this.component?t.component=this.component:this.loadChildren?t.loadChildren=this.loadChildren:this.loadComponent&&(t.loadComponent=this.loadComponent),t.data=this.data??{breadcrumb:{label:this.route.name,disable:this.route.entryDisabled,staticStateParams:{src:N.BREADCRUMB}},...this.route.data},this.canActivate.push((t,e)=>{const i=r(a),n=r(T).parseAbsoluteUrl(e.url),o=n?.params??{params:{},query:{},state:{},route:new I};if(o.query=t.queryParams,s(i,()=>this.route.canBeEnteredFn(n?.route??this.route,o)))return!0;{const t=r(_),a=r(y);let o=r(B);return"function"==typeof o&&(o=s(i,o.bind(o,a.path(),e.url,n?.route??this.route))),"string"==typeof o&&t.parseUrl(o)}}),t.canActivate=this.canActivate,t.canDeactivate=this.canDeactivate,this.providersForChildren.length>0&&this.children.forEach(t=>this.provideToChildrenRec(t)),this.children.length>0)if(this.loadChildren||this.component||this.loadComponent){const e=t.path;t.path="",t.pathMatch="full",t.canMatch=void 0,t={path:e,pathMatch:"prefix",children:[t,...this.children],canActivateChild:this.canActivateChild,canMatch:this.getCanMatch(),data:t.data,providers:t.providers,canActivate:t.canActivate,canDeactivate:t.canDeactivate}}else t.children=this.children;return Object.keys(this.resolvers).length>0&&(t.resolve=this.resolvers),this.runGuardsAndResolvers&&(t.runGuardsAndResolvers=this.runGuardsAndResolvers),t}getCanMatch(){const t=this.route.paramMap;if(!Object.keys(t).some(e=>"number"===t[e]||Array.isArray(t[e])))return;const e=this.route.path.split("/").length,r=this.route.regex?new RegExp(`^${this.route.regex.source}$`):this.route.absoluteRegex;return[(t,a)=>{const s=a.slice(0,e).map(t=>t.path).join("/");return r.test(s)}]}provideToChildrenRec(t){t.providers||(t.providers=[]),this.providersForChildren.forEach(e=>{"object"==typeof e&&"provide"in e&&t.providers.some(t=>"object"==typeof t&&"provide"in t&&t.provide===e.provide)||t.providers.unshift(e)}),t.children&&t.children.forEach(t=>this.provideToChildrenRec(t))}checkChildrenMatch(){if(!this.loadChildren&&(this.route.children.length>0||this.children.length>0)){if(this.children.length<this.route.children.length)throw new Error(`RdtRoute ${this.route.name} has ${this.route.children.length} children, but RdtAngularRoute has ${this.children.length}. These numbers must match. Did you forget to call .setChildren() method in global routes definition? Routes with following names should be present: ${this.route.children.map(t=>t.name).join(", ")}`);if(this.children.length>this.route.children.length)throw new Error(`RdtRoute ${this.route.name} has ${this.route.children.length} children, but RdtAngularRoute has ${this.children.length}. These numbers must match. Did you forget to call .setChildren() method in feature shell routes definition? Routes with following paths should be present: ${this.children.map(t=>t.path).join(", ")}`);const t=this.children.map(t=>t.path),e=this.route.children.map(t=>t.path);t.sort(),e.sort();for(let r=0;r<t.length;r++)if(t[r]!==e[r])throw new Error(`Paths of children provided in RdtRoute and\n RdtAngularRoute do not match. ${t[r]} != ${e[r]}`)}}}class ${_orderedParams=[];_paramMap={};_regex=null;_paramMappings=[];_name;_path;_parent=null;_children=[];_entryDisabled=!1;_canBeEntered=L;_data={};get data(){return this._data}get regex(){return this._regex}get entryDisabled(){return this._entryDisabled}get paramMap(){return this._paramMap}get name(){return this._name}get path(){return this._path}get parent(){return this._parent}get children(){return this._children}}class j extends ${_absoluteRegex;_staticParams={};_queryParams={};_stateParams={};get basePath(){return this._parent?this._parent.absolutePath:"/"}get absolutePath(){return E.joinPaths(this.basePath,this._path)}get absoluteRegex(){if(this._absoluteRegex)return this._absoluteRegex;if(this._regex)if(this._parent){const t=this._parent.absoluteRegex.source.slice(1,-1);this._absoluteRegex=new RegExp("^"+E.joinPaths(t,this._regex.source)+"$")}else this._absoluteRegex=new RegExp("^"+E.joinPaths("/",this._regex.source)+"$");else if(this._absoluteRegex=new RegExp("^/$"),this._parent)throw new Error("Nested route with empty path is not allowed.");return this._absoluteRegex}get stateParams(){return this._stateParams}get queryParams(){return this._queryParams}testUrl(t){return this.absoluteRegex.test(t)}get staticParams(){return{...this._staticParams}}get hasCanBeEnteredGuard(){return this._canBeEntered!==L}canBeEntered(t,e={}){const r=this.getStaticParams();let a=this._queryParams,i=this._stateParams;e.params&&r.set(this,e.params),e.route&&r.setAll(e.route),e.query&&(a={...a,...e.query}),e.state&&(i={...i,...e.state});let n=this;for(;n;){const e={params:r.get(n)??{},route:r,query:a,state:i};if(t){const r=n;if(!s(t,()=>r._canBeEntered(r,e)))return!1}else if(!n._canBeEntered(n,e))return!1;n=n._parent}return!0}get canBeEnteredFn(){return this._canBeEntered}parseAbsoluteUrl(t){const e=E.stripQueryParams(t),r=this.absoluteRegex.exec(e);if(r){const e=E.parseQueryParams(t),a=r.slice(1).reverse(),s=this.fill(a),i=new I(s);return{params:i.get(this)??{},route:i,query:e,state:{}}}return null}fill(t,e={}){const r={},a=this._orderedParams.slice().reverse();for(let e=0;e<a.length&&e<t.length;e++){const s=a[e],i=this._paramMappings.find(t=>t.urlName===s)?.tableName??s;let n=decodeURIComponent(t[e]);"number"===this._paramMap[s]&&(n=parseInt(n)),r[i]=n}return e[this.absolutePath]=r,t.length>a.length&&this._parent&&this._parent.fill(t.slice(a.length),e),e}createAbsoluteUrl(t=this._staticParams){return this._parent?E.joinPaths(this._parent.createAbsoluteUrl(),this.createRelativeUrl(t)):this.createUrl(this.absolutePath,t)}createRelativeUrl(t=this._staticParams){return this.createUrl(this.path,t)}createUrl(t,e){const r=Object.keys(this._paramMap);r.sort((t,e)=>e.length-t.length);const a={...e};return this._paramMappings.forEach(t=>{t.tableName in e&&(a[t.urlName]=e[t.tableName])}),r.forEach(e=>{if(!(e in a))throw new Error(`Param ${e} is missing for route ${this.absolutePath}. Please pass object with required parameters.`);const r=a[e],s=this._paramMap[e];if(Array.isArray(s)&&!s.includes(`${r}`))throw new Error(`Value "${r}" is not allowed for enum param "${e}" in route ${this.absolutePath}. Allowed values: ${s.join(", ")}`);t=t.replace(`:${e}`,encodeURIComponent(`${r}`))}),t}toAngularRoute(){return new S(this)}withParamMappings(t){const e=this.clone();return e._paramMappings=t,e}withStaticParams(t,e){const r=this.clone();if(e){const a=t.absolutePath;let s=r;for(;s;)s.absolutePath===a&&(s._staticParams=e),s=s._parent}else r._staticParams=t;return r}withQueryParams(t){const e=this.clone();return e._queryParams={...t},e}withStateParams(t){const e=this.clone();return e._stateParams={...t},e}extractRouteParams(t){const e={};return this._orderedParams.forEach(r=>{const a=this._paramMappings.find(t=>t.urlName===r),s=a?.tableName??r;s in t&&(e[s]=t[s])}),e}getStaticParams(){const t=new I;let e=this;for(;e;)t.set(e,e._staticParams),e=e._parent;return t}clone(){const t=new j;return t._name=this._name,t._parent=this._parent?.clone()??null,t._path=this.path,t._entryDisabled=this._entryDisabled,t._orderedParams=[...this._orderedParams],t._paramMap={...this._paramMap},t._regex=this._regex?new RegExp(this._regex):null,t._paramMappings=this._paramMappings,t._staticParams={...this._staticParams},t._stateParams={...this._stateParams},t._canBeEntered=this._canBeEntered,t._queryParams={...this._queryParams},t}static getGroup(t){return Array.isArray(t)?"("+t.map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|")+")":j.groups[t]}setRegex(){const t=Object.keys(this._paramMap);t.sort((t,e)=>e.length-t.length);let e=this.path;t.forEach(t=>{const r=this._paramMap[t];if(!r)throw new Error("Params is not set i");e=e.replace(`:${t}`,j.getGroup(r))}),this._regex=""===e?null:new RegExp(e)}static fromBuilder(t){const e=new j;return e._name=t.name,e._path=t.path,e._entryDisabled=t.entryDisabled,e._orderedParams=t.orderedParams,e._canBeEntered=t.canBeEntered,e._paramMap=t.paramMap,e._regex=t.regex?new RegExp(t.regex):null,e._paramMappings=t.paramMappings,e._children=t.children,e._data=t.data,e._children.forEach(t=>t._parent=e),e.setRegex(),e}static groups={string:"([^/]+)",number:"(-?\\d+)"}}const O=new e("RDT_ROUTES_PROVIDER");function F(t){const e=Array.isArray(t)?t:Object.values(t).filter(t=>t instanceof j);return i([{provide:O,useValue:e}])}const V="RdtStateParams";class T{allRoutes=r(O,{optional:!0});baseHref=r(b).getBaseHrefFromDOM();location=r(y);router=r(_);viewStateService=r(D,{optional:!0});_previousUrl=null;_currentUrl=null;get previousUrl(){return this._previousUrl}get currentUrl(){return this._currentUrl}parsePreviousUrl(){return this._previousUrl?this.parseAbsoluteUrl(this._previousUrl):null}parseCurrentUrl(){return this._currentUrl?this.parseAbsoluteUrl(this._currentUrl):null}navigationEnd$=this.router.events.pipe(M(t=>t instanceof P));nextNavigationEnd$=this.navigationEnd$.pipe(k(1));constructor(){null===this.allRoutes&&(console.warn("All routes not provided. Make sure to provide RDT_ROUTES_PROVIDER with RdtRoute[]."),this.allRoutes=[]),this.navigationEnd$.subscribe(t=>{this._previousUrl=this._currentUrl,this._currentUrl=t.url})}getHistoryState(){return"RdtStateParams"in window&&"object"==typeof window[V]?{...window[V],...history.state??{}}:history.state??{}}navigate(t,e,r){let a;if(e instanceof I){let r=t;for(let t=r;null!==t;t=t.parent){const a=e.get(t);a&&(r=r.withStaticParams(t,a))}a=r.createAbsoluteUrl()}else a=e?t.createAbsoluteUrl(e):t.createAbsoluteUrl();const s=r?.target??"_self",i=r?.query??t.queryParams,n=r?.state??t.stateParams;if("_self"===s)return this.router.navigate([a],{queryParams:i,state:n,replaceUrl:r?.replaceUrl});const o=E.createAbsoluteUrl(a,this.baseHref),h=E.appendQueryParams(o,i),l=window.open(h,s);return l&&(l[V]=n),Promise.resolve(!0)}navigateHome(t){return this.router.navigateByUrl(E.appendQueryParams("/",t?.query??{}),{state:t?.state,replaceUrl:t?.replaceUrl})}navigateBack(t){const e=this.parseAbsoluteUrl();if(e){let r=e.route.withStaticParams(e.params);do{r=r.parent}while(r&&r.entryDisabled);return r?(t&&(t.query&&(r=r.withQueryParams(t.query)),t.state&&(r=r.withStateParams(t.state))),this.viewStateService?.markNextAsRestore(),this.navigate(r,t)):this.navigateHome(t)}return console.warn(`Cannot go back from ${this.location.path()} because no route matches current url`),null}parseAbsoluteUrl(t=this.location.path()){const e=E.stripQueryParams(t);if(this.allRoutes)for(const t of this.allRoutes){const r=t.parseAbsoluteUrl(e);if(r)return{route:t,params:r}}return null}extractAllParams(t){if(!t){const e=this.parseAbsoluteUrl();if(!e)return console.warn("No route matches current url."),null;t=e.route}const e=this.location.path();return t.parseAbsoluteUrl(e)}isParentOfCurrentLocation(t){return!0}removeQueryParams(...t){const e=new RegExp(`[?&](${t.join("|")})=[^&]*`,"g");return history.replaceState(history.state,"",location.pathname+location.search.replace(e,"").replace(/^&/,"?"))}static"ɵfac"=t.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"21.2.15",ngImport:t,type:T,deps:[],target:t.ɵɵFactoryTarget.Injectable});static"ɵprov"=t.ɵɵngDeclareInjectable({minVersion:"12.0.0",version:"21.2.15",ngImport:t,type:T,providedIn:"root"})}t.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"21.2.15",ngImport:t,type:T,decorators:[{type:n,args:[{providedIn:"root"}]}],ctorParameters:()=>[]});class G extends ${get canBeEntered(){return this._canBeEntered}get orderedParams(){return this._orderedParams}get paramMappings(){return this._paramMappings}withCanBeEntered(t){return this._canBeEntered=t,this}setCanBeEntered(t){return this.withCanBeEntered(t)}withEntryDisabled(t=!0){return this._entryDisabled=t,this}setEntryDisabled(t=!0){return this.withEntryDisabled(t)}withPath(t){this._path=t;const e=t.split("/"),r=[];return e.forEach(t=>{if(t.includes(":")){const e=t.split(":")[1];e&&(r.push(e),this._paramMap[e]||(this._paramMap[e]="number"))}}),this._orderedParams=r,this}setPath(t){return this.withPath(t)}withData(t){return this._data=t,this}setData(t){return this.withData(t)}withParam(t,e){return this._paramMap[t]=e,this}setParam(t,e){return this.withParam(t,e)}withName(t){return this._name=t,this}setName(t){return this.withName(t)}withChildren(...t){return this._children=t,this}setChildren(...t){return this.withChildren(...t)}build(){if("string"!=typeof this._path)throw new Error("Please provide path for route. Empty string is acceptable.");return j.fromBuilder(this)}}const H={paths:"exact",queryParams:"exact",fragment:"ignored",matrixParams:"ignored"},Q={paths:"subset",queryParams:"subset",fragment:"ignored",matrixParams:"ignored"};class W{destroyRef=r(o);router=r(_);renderer=r(h);elRef=r(l);set anyRouteActive(t){this.classes=this.parseClasses(t)}watchedRoutes=[];set anyRouteActiveOptions(t){this._anyRouteActiveOptions=this.parseOptions(t)}_anyRouteActiveOptions=Q;ariaCurrentWhenActive;get isActive(){return this._isActive}_isActive=!1;classes=[];ngOnInit(){this.update(),this.listenRouterEvents()}ngOnChanges(t){t.anyRouteActive?.previousValue&&this.parseClasses(t.anyRouteActive.previousValue).forEach(t=>this.removeClass(t)),this.update()}update(){this._isActive=this.watchedRoutes.some(t=>{const e="string"==typeof t?t:this.router.createUrlTree(t);return this.router.isActive(e,this._anyRouteActiveOptions)}),this.setClasses(),this.setAriaCurrent()}setAriaCurrent(){const t=this.elRef.nativeElement;if(this._isActive&&void 0!==this.ariaCurrentWhenActive){const e=this.ariaCurrentWhenActive.toString();this.renderer.setAttribute(t,"aria-current",e)}else this.renderer.removeAttribute(t,"aria-current")}setClasses(){this._isActive?this.classes.forEach(t=>this.addClass(t)):this.classes.forEach(t=>this.removeClass(t))}addClass(t){this.renderer.addClass(this.elRef.nativeElement,t)}removeClass(t){this.renderer.removeClass(this.elRef.nativeElement,t)}listenRouterEvents(){this.router.events.pipe(M(t=>t instanceof P),x(this.destroyRef)).subscribe(()=>this.update())}parseClasses(t){return(Array.isArray(t)?t:t.split(" ")).filter(t=>!!t)}parseOptions(t){return"exact"in t?t.exact?H:Q:t}static"ɵfac"=t.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"21.2.15",ngImport:t,type:W,deps:[],target:t.ɵɵFactoryTarget.Directive});static"ɵdir"=t.ɵɵngDeclareDirective({minVersion:"14.0.0",version:"21.2.15",type:W,isStandalone:!0,selector:"[rdtAnyRouteActive]",inputs:{anyRouteActive:["rdtAnyRouteActive","anyRouteActive"],watchedRoutes:"watchedRoutes",anyRouteActiveOptions:"anyRouteActiveOptions",ariaCurrentWhenActive:"ariaCurrentWhenActive"},providers:[A],usesOnChanges:!0,ngImport:t})}t.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"21.2.15",ngImport:t,type:W,decorators:[{type:c,args:[{selector:"[rdtAnyRouteActive]",standalone:!0,providers:[A]}]}],propDecorators:{anyRouteActive:[{type:u,args:[{required:!0,alias:"rdtAnyRouteActive"}]}],watchedRoutes:[{type:u,args:[{required:!0}]}],anyRouteActiveOptions:[{type:u}],ariaCurrentWhenActive:[{type:u}]}});class z{destroyRef=r(o);location=r(y);elRef=r(l);buttonClass=r(U);buttonRef=r(this.buttonClass,{optional:!0,host:!0});constructor(){p(()=>{this.buttonRef?this.buttonRef.click.subscribe(()=>this.location.back()):q(this.elRef.nativeElement,"click").pipe(x(this.destroyRef)).subscribe(()=>this.location.back())})}static"ɵfac"=t.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"21.2.15",ngImport:t,type:z,deps:[],target:t.ɵɵFactoryTarget.Directive});static"ɵdir"=t.ɵɵngDeclareDirective({minVersion:"14.0.0",version:"21.2.15",type:z,isStandalone:!0,selector:"[rdtBackLink]",ngImport:t})}t.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"21.2.15",ngImport:t,type:z,decorators:[{type:c,args:[{selector:"[rdtBackLink]"}]}],ctorParameters:()=>[]});const J=Symbol();class K{buttonClass=r(U);buttonRef=r(this.buttonClass,{host:!0,optional:!0});routerLinkRef=r(C,{self:!0});envInjector=r(a);routeInput=d.required({...ngDevMode?{debugName:"routeInput"}:{},alias:"rdtRouterLink"});route=m(()=>this.routeInput(),...ngDevMode?[{debugName:"route"}]:[]);target=d("_self",...ngDevMode?[{debugName:"target"}]:[]);params=d(...ngDevMode?[void 0,{debugName:"params"}]:[]);queryParams=d(...ngDevMode?[void 0,{debugName:"queryParams"}]:[]);stateParams=d(...ngDevMode?[void 0,{debugName:"stateParams"}]:[]);disabled=d(!1,{...ngDevMode?{debugName:"disabled"}:{},alias:"rdtDisabled",transform:g});canBeEntered=v(()=>{const t=this.route(),e=this.disabled();if(!t||e)return!1;const r={params:this.params(),query:this.queryParams(),state:this.stateParams()};return t.canBeEntered(this.envInjector,r)},...ngDevMode?[{debugName:"canBeEntered"}]:[]);updateEffect=f(()=>{this.buttonRef?this.updateButton():this.updateRouterLink()},...ngDevMode?[{debugName:"updateEffect"}]:[]);updateButton(){const t=this.route();t?this.canBeEntered()?this.setButtonLink(t):this.disableButtonLink():this.clearButtonLink()}setButtonLink(t){const e=this.buttonRef;try{const r=this.getNgHref(t);e.ngHref.set(r),e.stateParams.set(this.stateParams()??t.stateParams),e.queryParams.set(this.queryParams()??t.queryParams),e.setDisabledState(!1,J)}catch(t){console.error(t),this.disableButtonLink()}}disableButtonLink(){const t=this.buttonRef;t.ngHref.set(null),t.setDisabledState(!0,J)}clearButtonLink(){const t=this.buttonRef;t.ngHref.set(null),t.stateParams.set(void 0),t.queryParams.set(void 0),t.setDisabledState(!1,J)}updateRouterLink(){const t=this.route();t?this.canBeEntered()?this.setRouterLink(t):this.disableRouterLink():this.clearRouterLink()}setRouterLink(t){try{const e=this.getNgHref(t);this.routerLinkRef.routerLink=e,this.routerLinkRef.state=this.stateParams()??t.stateParams,this.routerLinkRef.queryParams=this.queryParams()??t.queryParams,this.routerLinkRef.ngOnChanges({})}catch(t){console.error(t),this.disableRouterLink()}}disableRouterLink(){this.routerLinkRef.routerLink=null,this.routerLinkRef.ngOnChanges({})}clearRouterLink(){this.routerLinkRef.routerLink=null,this.routerLinkRef.state=void 0,this.routerLinkRef.queryParams=void 0,this.routerLinkRef.ngOnChanges({})}getNgHref(t){return t.createAbsoluteUrl(this.params())}static"ɵfac"=t.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"21.2.15",ngImport:t,type:K,deps:[],target:t.ɵɵFactoryTarget.Directive});static"ɵdir"=t.ɵɵngDeclareDirective({minVersion:"17.1.0",version:"21.2.15",type:K,isStandalone:!0,selector:"[rdtRouterLink]",inputs:{routeInput:{classPropertyName:"routeInput",publicName:"rdtRouterLink",isSignal:!0,isRequired:!0,transformFunction:null},target:{classPropertyName:"target",publicName:"target",isSignal:!0,isRequired:!1,transformFunction:null},params:{classPropertyName:"params",publicName:"params",isSignal:!0,isRequired:!1,transformFunction:null},queryParams:{classPropertyName:"queryParams",publicName:"queryParams",isSignal:!0,isRequired:!1,transformFunction:null},stateParams:{classPropertyName:"stateParams",publicName:"stateParams",isSignal:!0,isRequired:!1,transformFunction:null},disabled:{classPropertyName:"disabled",publicName:"rdtDisabled",isSignal:!0,isRequired:!1,transformFunction:null}},hostDirectives:[{directive:R.RouterLink,inputs:["target","target","replaceUrl","replaceUrl"]}],ngImport:t})}t.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"21.2.15",ngImport:t,type:K,decorators:[{type:c,args:[{selector:"[rdtRouterLink]",standalone:!0,hostDirectives:[{directive:C,inputs:["target","replaceUrl"]}]}]}],propDecorators:{routeInput:[{type:t.Input,args:[{isSignal:!0,alias:"rdtRouterLink",required:!0}]}],target:[{type:t.Input,args:[{isSignal:!0,alias:"target",required:!1}]}],params:[{type:t.Input,args:[{isSignal:!0,alias:"params",required:!1}]}],queryParams:[{type:t.Input,args:[{isSignal:!0,alias:"queryParams",required:!1}]}],stateParams:[{type:t.Input,args:[{isSignal:!0,alias:"stateParams",required:!1}]}],disabled:[{type:t.Input,args:[{isSignal:!0,alias:"rdtDisabled",required:!1}]}]}});const X=t=>!t.guardRegistry.hasLeaveBlockers()||t.guardRegistry.canLeaveAll();class Y{router=r(_);ensureGlobalGuards(){let t="";this.router.events.subscribe(e=>{if(e instanceof P&&(t=location.href),e instanceof w){let r=e.state.root;for(;r?.firstChild;)r=r.firstChild;history.replaceState(window.history.state,"",t),r?.routeConfig&&this.ensureCanDeactivateGuards(r.routeConfig)}})}ensureCanDeactivateGuards(t){t.canDeactivate||(t.canDeactivate=[]);const e=t.canDeactivate;e.find(t=>t==X)||e.push(X)}static"ɵfac"=t.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"21.2.15",ngImport:t,type:Y,deps:[],target:t.ɵɵFactoryTarget.Injectable});static"ɵprov"=t.ɵɵngDeclareInjectable({minVersion:"12.0.0",version:"21.2.15",ngImport:t,type:Y,providedIn:"root"})}t.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"21.2.15",ngImport:t,type:Y,decorators:[{type:n,args:[{providedIn:"root"}]}]});export{Y as GlobalRouteGuardService,J as PERMISSION_DISABLED_KEY,B as RDT_CANNOT_BE_ENTERED_PROVIDER,O as RDT_ROUTES_PROVIDER,S as RdtAngularRoute,W as RdtAnyRouteActiveDirective,z as RdtBackLinkDirective,N as RdtNavigationSource,I as RdtParameters,j as RdtRoute,G as RdtRouteBuilder,K as RdtRouterLinkDirective,T as RdtRouterService,X as preventDataLossGuardFn,F as provideRdtRoutes};
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngrdt/router",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@angular/common": ">=21.0.0",
|
|
6
6
|
"@angular/core": ">=21.0.0",
|
|
7
7
|
"@angular/router": ">=21.0.0",
|
|
8
8
|
"rxjs": ">=7.0.0",
|
|
9
|
-
"@ngrdt/utils": "^0.1.
|
|
10
|
-
"@ngrdt/core": "^0.1.
|
|
11
|
-
"@ngrdt/button": "^0.1.
|
|
9
|
+
"@ngrdt/utils": "^0.1.3",
|
|
10
|
+
"@ngrdt/core": "^0.1.3",
|
|
11
|
+
"@ngrdt/button": "^0.1.3"
|
|
12
12
|
},
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"module": "fesm2022/ngrdt-router.mjs",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"default": "./fesm2022/ngrdt-router.mjs"
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
|
+
"type": "module",
|
|
25
26
|
"dependencies": {
|
|
26
27
|
"tslib": "^2.3.0"
|
|
27
28
|
}
|