@lwrjs/router 0.20.6 → 0.20.7
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,2 +1,2 @@
|
|
|
1
|
-
import{parseFragment as e,registerTemplate as t,freezeTemplate as i,createContextProvider as r,registerDecorators as s,registerComponent as n,LightningElement as o}from"lwc";import{ROUTER_VIEW as a,ROUTER_NAV as c,ROUTER_ERROR as d}from"lwr/metrics";import{logOperationEnd as h,logOperationStart as l}from"lwr/profiler";function u(e,t,i){return"span.router-title"+(e?"."+e:"")+" {position: absolute;margin: -1px;border: 0;padding: 0;width: 1px;height: 1px;overflow: hidden;clip: rect(0 0 0 0);text-transform: none;white-space: nowrap;}"}u.$scoped$=!0;var p=[u];const v=e`<span class="router-title${0}" aria-live="polite" aria-atomic="true"${2}></span>`,g={key:0},m=[],f={ref:"title"};function E(e,t,i,r){const{s:s,sp:n,st:o}=e;return[s("",g,m,i),o(v,2,[n(0,f,null)])]}var I=t(E);function b(e){if(null==e)throw new TypeError("Provider must be defined.")}E.slots=[""],E.renderMode="light",E.hasRefs=!0,E.stylesheets=[],E.stylesheetToken="lwc-7bis3qj4jjc",E.legacyStylesheetToken="lwr-routerContainer_routerContainer",p&&E.stylesheets.push.apply(E.stylesheets,p),i(E);class w{constructor(e){this.infoMap=new WeakMap,this.defaultValue=void 0,this.defaultValue=e}getInfo(e){let t=this.infoMap.get(e);return void 0===t&&(t={consumers:new Set},this.infoMap.set(e,t)),t}setContext(e,t){b(e);const i=t,r=this.getInfo(e);r.contextValue=t,r.consumers.forEach((e=>e.provide(i))),0===r.consumers.size&&i?.onComplete&&i.onComplete()}getContext(e){b(e);const{contextValue:t}=this.getInfo(e);return void 0!==t?t:this.defaultValue}clearContext(e){b(e),this.infoMap.delete(e)}subscribeContext(e,t){b(e);const{consumers:i,contextValue:r}=this.getInfo(e);i.has(t)||(i.add(t),t.provide(r))}unsubscribeContext(e,t){b(e),this.getInfo(e).consumers.delete(t)}}const N="LWR",_=1;function R(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,i)=>t[i])):e}function x(e,t){const i={...e,message:R(e.message,t)};return e.address&&(i.address=R(e.address,t)),e.stack&&(i.stack=R(e.stack,t)),i}function C(e,t,i){if(!e)throw new Error(function(e,t){return`${e.code}: ${R(e.message,t)}`}(t,i))}const T={INVALID_MIXIN_CMP:{code:`${N}4001`,message:"{0} must be an Element type",level:_},MISSING_CONTEXT:{code:`${N}4002`,message:"Could not find context to perform navigation action.",level:_},INVALID_CONTEXT:{code:`${N}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:_},MULTIPLE_ROOTS:{code:`${N}4004`,message:"Router connection failed. There can only be one root router.",level:_},MULTIPLE_CHILDREN:{code:`${N}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:_},MISSING_ROUTE:{code:`${N}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:_,address:"{0}"},MISSING_URL:{code:`${N}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:_,address:"{0}"},PRENAV_FAILED:{code:`${N}4008`,message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:`${N}4009`,message:'Route definition with id "{0}" is missing a "uri" property.',level:_,address:"{0}"},MISSING_ROUTE_CMP:{code:`${N}4016`,message:"Expected a route view component with a default export.",level:_},MISSING_DATA_CONTEXT:{code:`${N}4018`,message:"Could not find context to retrieve navigation data.",level:_},INVALID_ROUTE_QUERY:{code:`${N}4019`,message:"Invalid query param in route definition.",level:_},MISSING_PAGE_BINDING:{code:`${N}4020`,message:'Route definition with id "{0}" is missing a "page" binding.',level:_,address:"{0}"},INVALID_PAGE_BINDING:{code:`${N}4021`,message:'Route definition with id "{0}" has an invalid "page" binding.',level:_,address:"{0}"},INVALID_URI_SYNTAX:{code:`${N}4022`,message:'Route definition with id "{0}" has invalid "uri" syntax. URI cannot contain *, +, (, ), ',level:_,address:"{0}"},VIEW_IMPORT_FAILED:{code:`${N}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:_,stack:"{2}"},VIEW_MISSING:{code:`${N}4024`,message:'Expected a view with name "{0}" in the viewset',level:_},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${N}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:_,stack:"{3}"},NO_ROUTE_MATCH:{code:`${N}4026`,message:"A routing match cannot be found for: {0}",level:_},INVALID_ROUTE_HANDLER:{code:`${N}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:_},DESTINATION_NOT_FOUND:{code:`${N}4028`,message:"Route handler returned 404: Not Found",level:_},DESTINATION_ERROR:{code:`${N}4029`,message:"Route handler returned error status {0}: {1}",level:_,stack:"{2}"},NO_INIT_URL:{code:`${N}4030`,message:'Cannot initialize a server router without a "url"',level:_}},y=new WeakMap;function P(e){var t;return(t=class{constructor(e){this._callback=void 0,this._callback=e}connect(){}disconnect(){}update(e,t){t&&this._callback(t)}static setContext(t,i){e.setContext(t,i)}static getContext(t){return e.getContext(t)}static clearContext(t){e.clearContext(t)}static subscribeContext(t,i){e.subscribeContext(t,i)}static unsubscribeContext(t,i){e.unsubscribeContext(t,i)}}).contextSchema={value:"required"},t}const U=P(new w(void 0)),$=P(new w(void 0)),A=new w(void 0),O=class extends(P(A)){async update(e,t){if(t){const i=e&&e.viewName?e.viewName:"default",r=t.viewset[i],s=r,n=s&&s.module||r;let o;if(n)try{const e=await n(),t=e&&e.default;if(!t||void 0===t.constructor)throw new Error("error occurred with view import");this._callback(t)}catch(e){const t=e;o=s.specifier?x(T.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[s.specifier,i,t.message,t.stack||""]):x(T.VIEW_IMPORT_FAILED,[i,t.message,t.stack||""])}else o=x(T.VIEW_MISSING,[i]);t.onComplete&&t.onComplete(o)}}};function M(){const e=[],t=t=>{"function"==typeof t&&e.push(t)};return{add:(e=[])=>{Array.isArray(e)?e.forEach((e=>t(e))):t(e)},compile:t=>0===e.length?Promise.resolve(!0):e.reduce(((e,i)=>e.then((e=>!1===e?Promise.reject():Promise.resolve(i(t))))),Promise.resolve(!0)).then((e=>!1!==e)).catch((e=>{if(e instanceof Error)throw e;return!1})),empty:()=>0===e.length}}function S(e=""){return e=e||"",decodeURIComponent(e)}function L(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const D="undefined"!=typeof document,k=`universalcontainergetnavigationcontext${L()}`,F=r($),V=D?r(O):void 0,G=r(U);function W(e,t,i,r){i&&r&&(r.setContext(t,e),i(t,{consumerConnectedCallback:r.subscribeContext.bind(r,t),consumerDisconnectedCallback:r.unsubscribeContext.bind(r,t)}))}function j(){let e,t,i=[];const r=r=>{i.filter((e=>null!==e)).forEach((e=>e.error&&e.error(r))),e=void 0,t=r};return{next:r=>{i.filter((e=>null!==e)).forEach((e=>e.next&&e.next(r))),e=r,t=void 0},error:r,complete:()=>{i.filter((e=>null!==e)).forEach((e=>e.complete&&e.complete())),i=[],e=void 0,t=void 0},subscribe:(s,n=!0)=>{(e=>{i.push(e)})(s),e&&n&&s.next(e),t&&r(t);const o=i.length-1;return{unsubscribe:()=>(e=>{i=[...i.slice(0,e),...i.slice(e+1)]})(o)}}}}const H=`universalcontainernavigationevent${L()}`,B=`universalcontainerparentevent${L()}`;class X{constructor(e,t,i){this.config=void 0,this.target=void 0,this.router=void 0,this.pendingRoute=null,this.committedRoute=null,this.routeObservable=void 0,this.eventId=void 0,this.contextId=Object.freeze((()=>{})),this.connected=!1,this.parent=void 0,this.child=void 0,this.preNavFilters=M(),this.errorNavFilters=M(),this._handleNavigationEvent=e=>{const t=e;if(t.detail&&"object"==typeof t.detail){const{url:e,replace:i,address:r}=t.detail;this.config.handleNavigation(r,i)?this.root&&!e?this.root.processError(x(T.MISSING_URL,[JSON.stringify(r)])):this.parent||this.process(e,i):t.stopPropagation()}},this._handleParentEvent=e=>{e.stopImmediatePropagation();const t=e;t&&t.detail&&"function"==typeof t.detail&&t.detail(this)},this.config={handleNavigation:e.handleNavigation||(()=>!0)},this.target=i||window,this.router=t,this.router.contextId=this.contextId,this.routeObservable=j()}get root(){if(!this.parent)return this;let e=this.parent;for(;e;){if(!e.parent)return e;e=e.parent}throw new Error("No root router could be found")}updateWires(e,t,i){if(i)this.processError(i);else{if(this.committedRoute&&e.route===this.committedRoute.route)return;h({id:a,specifier:this.eventId}),this.pendingRoute=this.pendingRoute||{...e,url:t},this.committedRoute={...this.pendingRoute,...e},$.setContext(this.target,e.route.pageReference),this.routeObservable.next({...this.committedRoute,viewset:e.viewset}),h({id:c,specifier:this.eventId}),this.child&&this.child.process(this._stripUrlForChild(this.committedRoute.url))}}connect(){this._sendEvent(B,(e=>{this.parent=e,e.addChild(this)}));const e={navigate:(e,t)=>this.navigate(e,t),generateUrl:(e,t)=>this.generateUrl(e,t),generateUrlAsync:(e,t)=>this.generateUrlAsync(e,t),subscribe:(e,t)=>this.subscribe(e,t)};!function(e,t){const i={id:e,value:t,update:e=>{i.value=e}};y.set(i.id,i)}(this.contextId,e),W(this.contextId,this.target,G,U),W(void 0,this.target,F,$),W(void 0,this.target,V,O),this.router.subscribe((e=>{if(404===e.status)return void this.processError(x(T.DESTINATION_NOT_FOUND));if(e.status&&e.status>=400){const t=e.error||new Error;return void this.processError(x(T.DESTINATION_ERROR,[e.status.toString(),t.message,t.stack||""]))}const t=e.route.pageReference||{},i=this.router.generateUrl(t)||"";if(l({id:a,specifier:this.eventId}),e.viewset){const t={viewset:e.viewset,onComplete:this.updateWires.bind(this,e,i)};O.setContext(this.target,t)}else e.route.pageReference&&this.updateWires(e,i)}),!0),D&&(this.target.addEventListener(H,this._handleNavigationEvent),this.target.addEventListener(B,this._handleParentEvent),this.target.addEventListener(k,(e=>{const t=e;t.detail.callback&&t.detail.callback(this.contextId)}))),this.connected=!0}disconnect(){this.target.removeEventListener(H,this._handleNavigationEvent),this.target.removeEventListener(B,this._handleParentEvent),this.parent&&(this.parent.child=void 0),this.parent=void 0,this.child&&(this.child.parent=void 0),this.child=void 0,this.connected=!1}addPreNavigate(e){this.preNavFilters.add(e)}addErrorNavigate(e){this.errorNavFilters.add(e)}async addChild(e){if(await new Promise((t=>{setTimeout((()=>{C(!this.child,T.MULTIPLE_CHILDREN),this.child=e,t()}),0)})),this.child&&this.committedRoute){const e=this._stripUrlForChild(this.committedRoute.url);await this.child.preProcess(e)&&this.child.process(e)}}async process(e,t,i,r){this.eventId=(new Date).getTime().toString(),l({id:c,specifier:this.eventId});try{this.parent||await this.preProcess(e,i)}catch(e){if(e.code)return this.processError(e),!1;throw e}const s=this.router.parseUrl(e);return s&&this.router.navigate(s,i),!0}preProcess(e,t){const i=this.router.parseUrl(e),r=i&&this.router.matchRoute(i,t);if(!r)return Promise.reject(x(T.MISSING_ROUTE,[e]));this.pendingRoute={url:e,...r};return(this.preNavFilters.empty()?Promise.resolve(!0):this.preNavFilters.compile({current:this.committedRoute||void 0,next:this.pendingRoute})).then((t=>t&&this.child?this.child.preProcess(this._stripUrlForChild(e)):t)).then((t=>t||Promise.reject(x(T.PRENAV_FAILED,[e]))))}processError(e){l({id:d}),this.errorNavFilters.compile(e),this.child&&this.child.processError(e)}navigate(e,t,i){const r=this.filterNavigateOptions(i);let s=this.router.generateUrl(e,r);if(s){s=(this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||"").concat(s)}this._sendEvent(H,{url:s,replace:t,address:e})}generateUrl(e,t){const i=this.filterNavigateOptions(t),r=this.router.generateUrl(e,i);if(!r)return null;return`${this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||""}${r}`}async generateUrlAsync(e,t){const i=this.filterNavigateOptions(t),r=await this.router.generateUrlAsync(e,i);if(!r)return null;return`${this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||""}${r}`}subscribe(e,t){return this.routeObservable.subscribe({next:e,error:()=>{},complete:()=>{}},Boolean(t))}_sendEvent(e,t){D&&this.target.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t}))}_stripUrlForChild(e){return this.pendingRoute&&0===e.indexOf(this.pendingRoute.pathMatch)?e.replace(this.pendingRoute.pathMatch,""):e}filterNavigateOptions(e){const t=!this.parent;return{...e,locale:t?e?.locale:void 0}}}function q(e){const t=function(e=""){if((e=e||"").indexOf("://")<0){const t=window.location.port?`:${window.location.port}`:"",i=`${window.location.protocol}//${window.location.hostname}${t}`,r="/"===e.charAt(0)?"":"/";e=i+r+e}const t={},i=document.createElement("a");i.href=e;const r=i.search.substring(1);return r&&r.split("&").forEach((e=>{const[i,r=""]=e.split("=");t[S(i)]=S(r)})),{href:i.href,origin:`${i.protocol}//${i.hostname}${i.port?`:${i.port}`:""}`,pathname:i.pathname.replace(/(\/)?/,"/"),searchParams:t}}(e),i=t.href.replace(/:\d+/,""),r=t.origin.replace(/:\d+/,"");return i.replace(r,"")}class z extends X{constructor(...e){super(...e),this.historyDisabled=!1,this.currentUrl=""}connect(){super.connect(),this.historyDisabled||(D&&window.addEventListener("popstate",this.onpopstate.bind(this)),this.onpopstate())}onpopstate(){if(!this.parent&&D){const e=q(window.location.href),t=this.router.basePath.includes("#")?e:function(e){const t=e.indexOf("#");return-1!==t?e.substring(0,t):e}(e);t!==this.currentUrl&&this.catchBrowserUpdate(t)}}disconnect(){super.disconnect(),D&&window.removeEventListener("popstate",this.onpopstate)}async process(e,t,i,r=!0){const s=await super.process(e,t,i,r);return s&&!this.historyDisabled&&r&&this.connected&&!this.parent&&(t?function(e,t){const i=t||{};window.history.replaceState(i,"",e)}(e):function(e,t){const i=t||{};window.history.pushState(i,"",e)}(e),this.currentUrl=e),s}catchBrowserUpdate(e){this.process(e,!1,{},!1)}}s(z,{fields:["historyDisabled","currentUrl"]});let Y=!1;class J extends o{constructor(){super(),this.router=void 0,this.historyDisabled=!1,this.currentTitle=D?document.title:""}connectedCallback(){const e={historyDisabled:this.historyDisabled,handleNavigation:this.handleNavigation.bind(this)};D&&this.router&&(this.routerApi=function(e,t={},i){const r=t.historyDisabled?new X(t,i,e):new z(t,i,e),s={addPreNavigate:e=>(r.addPreNavigate(e),s),addPostNavigate:e=>(r.subscribe(e),s),addErrorNavigate:e=>(r.addErrorNavigate(e),s),connect:()=>{r.connect(),C(!Y||!!r.parent,T.MULTIPLE_ROOTS),Y=Y||!r.parent,s.id=r.contextId},disconnect:()=>{Y=Y&&!!r.parent,r.disconnect()}};return s}(this,e,this.router),this.routerApi.addPreNavigate(this.preNavigate.bind(this)).addPostNavigate(this.postNavigate.bind(this)).addErrorNavigate(this.errorNavigate.bind(this)).connect())}preNavigate(e){const t=this._createEvent("prenavigate",e,!0);return this.dispatchEvent(t),!t.defaultPrevented}postNavigate(e){this.dispatchEvent(this._createEvent("postnavigate",e));const t=e.routeDefinition.metadata&&e.routeDefinition.metadata.title;t&&(this.currentTitle=t.replace(/[<>&"']/g,(e=>{switch(e){case"<":return"<";case">":return">";case"&":return"&";case'"':return""";case"'":return"'";default:return e}})),document.title=this.currentTitle);const i=this.refs?.title;i&&(i.innerHTML=this.currentTitle,setTimeout((()=>{i.innerHTML=""}),500))}errorNavigate(e){return this.dispatchEvent(this._createEvent("errornavigate",e)),!0}handleNavigation(e,t){const i=this._createEvent("handlenavigation",{address:e,replace:t},!0);return this.dispatchEvent(i),!i.defaultPrevented}disconnectedCallback(){this.routerApi&&this.routerApi.disconnect()}_createEvent(e,t,i){return new CustomEvent(e,{detail:t,bubbles:!1,composed:!1,cancelable:i})}}J.renderMode="light",s(J,{publicProps:{router:{config:0},historyDisabled:{config:0}}});const Q=n(J,{tmpl:I,sel:"lwr-router-container",apiVersion:63});export{Q as default};
|
|
1
|
+
import{parseFragment as e,registerTemplate as t,freezeTemplate as i,createContextProvider as r,registerDecorators as s,registerComponent as n,LightningElement as o}from"lwc";import{ROUTER_VIEW as a,ROUTER_NAV as c,ROUTER_ERROR as d}from"lwr/metrics";import{logOperationEnd as h,logOperationStart as l}from"lwr/profiler";function u(e,t,i){return"span.router-title"+(e?"."+e:"")+" {position: absolute;margin: -1px;border: 0;padding: 0;width: 1px;height: 1px;overflow: hidden;clip: rect(0 0 0 0);text-transform: none;white-space: nowrap;}"}u.$scoped$=!0;var p=[u];const v=e`<span class="router-title${0}" aria-live="polite" aria-atomic="true"${2}></span>`,g={key:0},m=[],f={ref:"title"};function E(e,t,i,r){const{s:s,sp:n,st:o}=e;return[s("",g,m,i),o(v,2,[n(0,f,null)])]}var I=t(E);function b(e){if(null==e)throw new TypeError("Provider must be defined.")}E.slots=[""],E.renderMode="light",E.hasRefs=!0,E.stylesheets=[],E.stylesheetToken="lwc-7bis3qj4jjc",E.legacyStylesheetToken="lwr-routerContainer_routerContainer",p&&E.stylesheets.push.apply(E.stylesheets,p),i(E);class w{constructor(e){this.infoMap=new WeakMap,this.defaultValue=void 0,this.defaultValue=e}getInfo(e){let t=this.infoMap.get(e);return void 0===t&&(t={consumers:new Set},this.infoMap.set(e,t)),t}setContext(e,t){b(e);const i=t,r=this.getInfo(e);r.contextValue=t,r.consumers.forEach((e=>e.provide(i))),0===r.consumers.size&&i?.onComplete&&i.onComplete()}getContext(e){b(e);const{contextValue:t}=this.getInfo(e);return void 0!==t?t:this.defaultValue}clearContext(e){b(e),this.infoMap.delete(e)}subscribeContext(e,t){b(e);const{consumers:i,contextValue:r}=this.getInfo(e);i.has(t)||(i.add(t),t.provide(r))}unsubscribeContext(e,t){b(e),this.getInfo(e).consumers.delete(t)}}const N="LWR",_=1;function R(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,i)=>t[i])):e}function x(e,t){const i={...e,message:R(e.message,t)};return e.address&&(i.address=R(e.address,t)),e.stack&&(i.stack=R(e.stack,t)),i}function C(e,t,i){if(!e)throw new Error(function(e,t){return`${e.code}: ${R(e.message,t)}`}(t,i))}const T={INVALID_MIXIN_CMP:{code:`${N}4001`,message:"{0} must be an Element type",level:_},MISSING_CONTEXT:{code:`${N}4002`,message:"Could not find context to perform navigation action.",level:_},INVALID_CONTEXT:{code:`${N}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:_},MULTIPLE_ROOTS:{code:`${N}4004`,message:"Router connection failed. There can only be one root router.",level:_},MULTIPLE_CHILDREN:{code:`${N}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:_},MISSING_ROUTE:{code:`${N}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:_,address:"{0}"},MISSING_URL:{code:`${N}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:_,address:"{0}"},PRENAV_FAILED:{code:`${N}4008`,message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:`${N}4009`,message:'Route definition with id "{0}" is missing a "uri" property.',level:_,address:"{0}"},MISSING_ROUTE_CMP:{code:`${N}4016`,message:"Expected a route view component with a default export.",level:_},MISSING_DATA_CONTEXT:{code:`${N}4018`,message:"Could not find context to retrieve navigation data.",level:_},INVALID_ROUTE_QUERY:{code:`${N}4019`,message:"Invalid query param in route definition.",level:_},MISSING_PAGE_BINDING:{code:`${N}4020`,message:'Route definition with id "{0}" is missing a "page" binding.',level:_,address:"{0}"},INVALID_PAGE_BINDING:{code:`${N}4021`,message:'Route definition with id "{0}" has an invalid "page" binding.',level:_,address:"{0}"},INVALID_URI_SYNTAX:{code:`${N}4022`,message:'Route definition with id "{0}" has invalid "uri" syntax. URI cannot contain *, +, (, ), ',level:_,address:"{0}"},VIEW_IMPORT_FAILED:{code:`${N}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:_,stack:"{2}"},VIEW_MISSING:{code:`${N}4024`,message:'Expected a view with name "{0}" in the viewset',level:_},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${N}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:_,stack:"{3}"},NO_ROUTE_MATCH:{code:`${N}4026`,message:"A routing match cannot be found for: {0}",level:_},INVALID_ROUTE_HANDLER:{code:`${N}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:_},DESTINATION_NOT_FOUND:{code:`${N}4028`,message:"Route handler returned 404: Not Found",level:_},DESTINATION_ERROR:{code:`${N}4029`,message:"Route handler returned error status {0}: {1}",level:_,stack:"{2}"},NO_INIT_URL:{code:`${N}4030`,message:'Cannot initialize a server router without a "url"',level:_}},y=new WeakMap;function P(e){var t;return(t=class{constructor(e){this._callback=void 0,this._callback=e}connect(){}disconnect(){}update(e,t){t&&this._callback(t)}static setContext(t,i){e.setContext(t,i)}static getContext(t){return e.getContext(t)}static clearContext(t){e.clearContext(t)}static subscribeContext(t,i){e.subscribeContext(t,i)}static unsubscribeContext(t,i){e.unsubscribeContext(t,i)}}).contextSchema={value:"required"},t}const U=P(new w(void 0)),$=P(new w(void 0)),A=new w(void 0),O=class extends(P(A)){async update(e,t){if(t){const i=e&&e.viewName?e.viewName:"default",r=t.viewset[i],s=r,n=s&&s.module||r;let o;if(n)try{const e=await n(),t=e&&e.default;if(!t||void 0===t.constructor)throw new Error("error occurred with view import");this._callback(t)}catch(e){const t=e;o=s.specifier?x(T.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[s.specifier,i,t.message,t.stack||""]):x(T.VIEW_IMPORT_FAILED,[i,t.message,t.stack||""])}else o=x(T.VIEW_MISSING,[i]);t.onComplete&&t.onComplete(o)}}};function M(){const e=[],t=t=>{"function"==typeof t&&e.push(t)};return{add:(e=[])=>{Array.isArray(e)?e.forEach((e=>t(e))):t(e)},compile:t=>0===e.length?Promise.resolve(!0):e.reduce(((e,i)=>e.then((e=>!1===e?Promise.reject():Promise.resolve(i(t))))),Promise.resolve(!0)).then((e=>!1!==e)).catch((e=>{if(e instanceof Error)throw e;return!1})),empty:()=>0===e.length}}function S(e=""){return e=e||"",decodeURIComponent(e)}function L(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const D="undefined"!=typeof document,k=`universalcontainergetnavigationcontext${L()}`,F=r($),V=D?r(O):void 0,G=r(U);function W(e,t,i,r){i&&r&&(r.setContext(t,e),i(t,{consumerConnectedCallback:r.subscribeContext.bind(r,t),consumerDisconnectedCallback:r.unsubscribeContext.bind(r,t)}))}function j(){let e,t,i=[];const r=r=>{i.filter((e=>null!==e)).forEach((e=>e.error&&e.error(r))),e=void 0,t=r};return{next:r=>{i.filter((e=>null!==e)).forEach((e=>e.next&&e.next(r))),e=r,t=void 0},error:r,complete:()=>{i.filter((e=>null!==e)).forEach((e=>e.complete&&e.complete())),i=[],e=void 0,t=void 0},subscribe:(s,n=!0)=>{(e=>{i.push(e)})(s),e&&n&&s.next(e),t&&r(t);const o=i.length-1;return{unsubscribe:()=>(e=>{i=[...i.slice(0,e),...i.slice(e+1)]})(o)}}}}const H=`universalcontainernavigationevent${L()}`,B=`universalcontainerparentevent${L()}`;class X{constructor(e,t,i){this.config=void 0,this.target=void 0,this.router=void 0,this.pendingRoute=null,this.committedRoute=null,this.routeObservable=void 0,this.eventId=void 0,this.contextId=Object.freeze((()=>{})),this.connected=!1,this.parent=void 0,this.child=void 0,this.preNavFilters=M(),this.errorNavFilters=M(),this._handleNavigationEvent=e=>{const t=e;if(t.detail&&"object"==typeof t.detail){const{url:e,replace:i,address:r}=t.detail;this.config.handleNavigation(r,i)?this.root&&!e?this.root.processError(x(T.MISSING_URL,[JSON.stringify(r)])):this.parent||this.process(e,i):t.stopPropagation()}},this._handleParentEvent=e=>{e.stopImmediatePropagation();const t=e;t&&t.detail&&"function"==typeof t.detail&&t.detail(this)},this.config={handleNavigation:e.handleNavigation||(()=>!0)},this.target=i||window,this.router=t,this.router.contextId=this.contextId,this.routeObservable=j()}get root(){if(!this.parent)return this;let e=this.parent;for(;e;){if(!e.parent)return e;e=e.parent}throw new Error("No root router could be found")}updateWires(e,t,i){if(i)this.processError(i);else{if(this.committedRoute&&e.route===this.committedRoute.route)return;h({id:a,specifier:this.eventId}),this.pendingRoute=this.pendingRoute||{...e,url:t},this.committedRoute={...this.pendingRoute,...e},$.setContext(this.target,e.route.pageReference),this.routeObservable.next({...this.committedRoute,viewset:e.viewset}),h({id:c,specifier:this.eventId}),this.child&&this.child.process(this._stripUrlForChild(this.committedRoute.url))}}connect(){this._sendEvent(B,(e=>{this.parent=e,e.addChild(this)}));const e={navigate:(e,t)=>this.navigate(e,t),generateUrl:(e,t)=>this.generateUrl(e,t),generateUrlAsync:(e,t)=>this.generateUrlAsync(e,t),subscribe:(e,t)=>this.subscribe(e,t)};!function(e,t){const i={id:e,value:t,update:e=>{i.value=e}};y.set(i.id,i)}(this.contextId,e),W(this.contextId,this.target,G,U),W(void 0,this.target,F,$),W(void 0,this.target,V,O),this.router.subscribe((e=>{if(404===e.status)return void this.processError(x(T.DESTINATION_NOT_FOUND));if(e.status&&e.status>=400){const t=e.error||new Error;return void this.processError(x(T.DESTINATION_ERROR,[e.status.toString(),t.message,t.stack||""]))}const t=e.route.pageReference||{},i=this.router.generateUrl(t)||"";if(l({id:a,specifier:this.eventId}),e.viewset){const t={viewset:e.viewset,onComplete:this.updateWires.bind(this,e,i)};O.setContext(this.target,t)}else e.route.pageReference&&this.updateWires(e,i)}),!0),D&&(this.target.addEventListener(H,this._handleNavigationEvent),this.target.addEventListener(B,this._handleParentEvent),this.target.addEventListener(k,(e=>{const t=e;t.detail.callback&&t.detail.callback(this.contextId)}))),this.connected=!0}disconnect(){this.target.removeEventListener(H,this._handleNavigationEvent),this.target.removeEventListener(B,this._handleParentEvent),this.parent&&(this.parent.child=void 0),this.parent=void 0,this.child&&(this.child.parent=void 0),this.child=void 0,this.connected=!1}addPreNavigate(e){this.preNavFilters.add(e)}addErrorNavigate(e){this.errorNavFilters.add(e)}async addChild(e){if(await new Promise((t=>{setTimeout((()=>{C(!this.child,T.MULTIPLE_CHILDREN),this.child=e,t()}),0)})),this.child&&this.committedRoute){const e=this._stripUrlForChild(this.committedRoute.url);await this.child.preProcess(e)&&this.child.process(e)}}async process(e,t,i,r){this.eventId=(new Date).getTime().toString(),l({id:c,specifier:this.eventId});try{this.parent||await this.preProcess(e,i)}catch(e){if(e.code)return this.processError(e),!1;throw e}const s=this.router.parseUrl(e);return s&&this.router.navigate(s,i),!0}preProcess(e,t){const i=this.router.parseUrl(e),r=i&&this.router.matchRoute(i,t);if(!r)return Promise.reject(x(T.MISSING_ROUTE,[e]));this.pendingRoute={url:e,...r};return(this.preNavFilters.empty()?Promise.resolve(!0):this.preNavFilters.compile({current:this.committedRoute||void 0,next:this.pendingRoute})).then((t=>t&&this.child?this.child.preProcess(this._stripUrlForChild(e)):t)).then((t=>t||Promise.reject(x(T.PRENAV_FAILED,[e]))))}processError(e){l({id:d}),this.errorNavFilters.compile(e),this.child&&this.child.processError(e)}navigate(e,t,i){const r=this.filterNavigateOptions(i);let s=this.router.generateUrl(e,r);if(s){s=(this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||"").concat(s)}this._sendEvent(H,{url:s,replace:t,address:e})}generateUrl(e,t){const i=this.filterNavigateOptions(t),r=this.router.generateUrl(e,i);if(!r)return null;return`${this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||""}${r}`}async generateUrlAsync(e,t){const i=this.filterNavigateOptions(t),r=await this.router.generateUrlAsync(e,i);if(!r)return null;return`${this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||""}${r}`}subscribe(e,t){return this.routeObservable.subscribe({next:e,error:()=>{},complete:()=>{}},Boolean(t))}_sendEvent(e,t){D&&this.target.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t}))}_stripUrlForChild(e){return this.pendingRoute&&0===e.indexOf(this.pendingRoute.pathMatch)?e.replace(this.pendingRoute.pathMatch,""):e}filterNavigateOptions(e){const t=!this.parent;return{...e,locale:t?e?.locale:void 0}}}function q(e){const t=function(e=""){if((e=e||"").indexOf("://")<0){const t=window.location.port?`:${window.location.port}`:"",i=`${window.location.protocol}//${window.location.hostname}${t}`,r="/"===e.charAt(0)?"":"/";e=i+r+e}const t={},i=document.createElement("a");i.href=e;const r=i.search.substring(1);return r&&r.split("&").forEach((e=>{const[i,r=""]=e.split("=");t[S(i)]=S(r)})),{href:i.href,origin:`${i.protocol}//${i.hostname}${i.port?`:${i.port}`:""}`,pathname:i.pathname.replace(/(\/)?/,"/"),searchParams:t}}(e),i=t.href.replace(/:\d+/,""),r=t.origin.replace(/:\d+/,"");return i.replace(r,"")}class z extends X{constructor(...e){super(...e),this.historyDisabled=!1,this.currentUrl=""}connect(){super.connect(),this.historyDisabled||(D&&window.addEventListener("popstate",this.onpopstate.bind(this)),this.onpopstate())}onpopstate(){if(!this.parent&&D){const e=q(window.location.href),t=this.router.basePath.includes("#")?e:function(e){const t=e.indexOf("#");return-1!==t?e.substring(0,t):e}(e);t!==this.currentUrl&&this.catchBrowserUpdate(t)}}disconnect(){super.disconnect(),D&&window.removeEventListener("popstate",this.onpopstate)}async process(e,t,i,r=!0){const s=await super.process(e,t,i,r);return s&&this.connected&&!this.parent&&(this.currentUrl=e,!this.historyDisabled&&r&&(t?function(e,t){const i=t||{};window.history.replaceState(i,"",e)}(e):function(e,t){const i=t||{};window.history.pushState(i,"",e)}(e))),s}catchBrowserUpdate(e){this.process(e,!1,{},!1)}}s(z,{fields:["historyDisabled","currentUrl"]});let Y=!1;class J extends o{constructor(){super(),this.router=void 0,this.historyDisabled=!1,this.currentTitle=D?document.title:""}connectedCallback(){const e={historyDisabled:this.historyDisabled,handleNavigation:this.handleNavigation.bind(this)};D&&this.router&&(this.routerApi=function(e,t={},i){const r=t.historyDisabled?new X(t,i,e):new z(t,i,e),s={addPreNavigate:e=>(r.addPreNavigate(e),s),addPostNavigate:e=>(r.subscribe(e),s),addErrorNavigate:e=>(r.addErrorNavigate(e),s),connect:()=>{r.connect(),C(!Y||!!r.parent,T.MULTIPLE_ROOTS),Y=Y||!r.parent,s.id=r.contextId},disconnect:()=>{Y=Y&&!!r.parent,r.disconnect()}};return s}(this,e,this.router),this.routerApi.addPreNavigate(this.preNavigate.bind(this)).addPostNavigate(this.postNavigate.bind(this)).addErrorNavigate(this.errorNavigate.bind(this)).connect())}preNavigate(e){const t=this._createEvent("prenavigate",e,!0);return this.dispatchEvent(t),!t.defaultPrevented}postNavigate(e){this.dispatchEvent(this._createEvent("postnavigate",e));const t=e.routeDefinition.metadata&&e.routeDefinition.metadata.title;t&&(this.currentTitle=t.replace(/[<>&"']/g,(e=>{switch(e){case"<":return"<";case">":return">";case"&":return"&";case'"':return""";case"'":return"'";default:return e}})),document.title=this.currentTitle);const i=this.refs?.title;i&&(i.innerHTML=this.currentTitle,setTimeout((()=>{i.innerHTML=""}),500))}errorNavigate(e){return this.dispatchEvent(this._createEvent("errornavigate",e)),!0}handleNavigation(e,t){const i=this._createEvent("handlenavigation",{address:e,replace:t},!0);return this.dispatchEvent(i),!i.defaultPrevented}disconnectedCallback(){this.routerApi&&this.routerApi.disconnect()}_createEvent(e,t,i){return new CustomEvent(e,{detail:t,bubbles:!1,composed:!1,cancelable:i})}}J.renderMode="light",s(J,{publicProps:{router:{config:0},historyDisabled:{config:0}}});const Q=n(J,{tmpl:I,sel:"lwr-router-container",apiVersion:63});export{Q as default};
|
|
2
2
|
//# sourceMappingURL=routerContainer.js.map
|
|
@@ -58,13 +58,15 @@ var HistoryRouter = class extends import_domRouter.DomRouterImpl {
|
|
|
58
58
|
}
|
|
59
59
|
async process(url, shouldReplace, options, updateHistory = true) {
|
|
60
60
|
const canContinue = await super.process(url, shouldReplace, options, updateHistory);
|
|
61
|
-
if (canContinue &&
|
|
62
|
-
if (shouldReplace) {
|
|
63
|
-
(0, import_domRouterUtils.replace)(url);
|
|
64
|
-
} else {
|
|
65
|
-
(0, import_domRouterUtils.set)(url);
|
|
66
|
-
}
|
|
61
|
+
if (canContinue && this.connected && !this.parent) {
|
|
67
62
|
this.currentUrl = url;
|
|
63
|
+
if (!this.historyDisabled && updateHistory) {
|
|
64
|
+
if (shouldReplace) {
|
|
65
|
+
(0, import_domRouterUtils.replace)(url);
|
|
66
|
+
} else {
|
|
67
|
+
(0, import_domRouterUtils.set)(url);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
68
70
|
}
|
|
69
71
|
return canContinue;
|
|
70
72
|
}
|
|
@@ -57,16 +57,22 @@ export class HistoryRouter extends DomRouterImpl {
|
|
|
57
57
|
async process(url, shouldReplace, options, updateHistory = true) {
|
|
58
58
|
// Run the preNavigate hooks to check if this event should be processed.
|
|
59
59
|
const canContinue = await super.process(url, shouldReplace, options, updateHistory);
|
|
60
|
-
//
|
|
61
|
-
if (canContinue &&
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
else {
|
|
67
|
-
set(url);
|
|
68
|
-
}
|
|
60
|
+
// Only the root router handles history and currentUrl tracking
|
|
61
|
+
if (canContinue && this.connected && !this.parent) {
|
|
62
|
+
// Always track the current URL for popstate comparison.
|
|
63
|
+
// This must be updated for both programmatic navigation (updateHistory=true)
|
|
64
|
+
// and browser-initiated navigation (updateHistory=false) to ensure
|
|
65
|
+
// subsequent popstate events are correctly detected.
|
|
69
66
|
this.currentUrl = url;
|
|
67
|
+
// Only modify browser history for programmatic navigation
|
|
68
|
+
if (!this.historyDisabled && updateHistory) {
|
|
69
|
+
if (shouldReplace) {
|
|
70
|
+
replace(url);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
set(url);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
70
76
|
}
|
|
71
77
|
return canContinue;
|
|
72
78
|
}
|
|
@@ -61,15 +61,22 @@ export class HistoryRouter extends DomRouterImpl {
|
|
|
61
61
|
// Run the preNavigate hooks to check if this event should be processed.
|
|
62
62
|
const canContinue = await super.process(url, shouldReplace, options, updateHistory);
|
|
63
63
|
|
|
64
|
-
//
|
|
65
|
-
if (canContinue &&
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
set(url);
|
|
71
|
-
}
|
|
64
|
+
// Only the root router handles history and currentUrl tracking
|
|
65
|
+
if (canContinue && this.connected && !this.parent) {
|
|
66
|
+
// Always track the current URL for popstate comparison.
|
|
67
|
+
// This must be updated for both programmatic navigation (updateHistory=true)
|
|
68
|
+
// and browser-initiated navigation (updateHistory=false) to ensure
|
|
69
|
+
// subsequent popstate events are correctly detected.
|
|
72
70
|
this.currentUrl = url;
|
|
71
|
+
|
|
72
|
+
// Only modify browser history for programmatic navigation
|
|
73
|
+
if (!this.historyDisabled && updateHistory) {
|
|
74
|
+
if (shouldReplace) {
|
|
75
|
+
replace(url);
|
|
76
|
+
} else {
|
|
77
|
+
set(url);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
73
80
|
}
|
|
74
81
|
return canContinue;
|
|
75
82
|
}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.20.
|
|
8
|
+
"version": "0.20.7",
|
|
9
9
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -53,14 +53,14 @@
|
|
|
53
53
|
"test:server": "jest --config ./jest.server.config.cjs"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@lwrjs/client-modules": "0.20.
|
|
57
|
-
"@lwrjs/diagnostics": "0.20.
|
|
58
|
-
"@lwrjs/shared-utils": "0.20.
|
|
56
|
+
"@lwrjs/client-modules": "0.20.7",
|
|
57
|
+
"@lwrjs/diagnostics": "0.20.7",
|
|
58
|
+
"@lwrjs/shared-utils": "0.20.7",
|
|
59
59
|
"ajv": "6.12.6"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@lwc/jest-preset": "^18.1.2",
|
|
63
|
-
"@lwrjs/fs-watch": "0.20.
|
|
63
|
+
"@lwrjs/fs-watch": "0.20.7",
|
|
64
64
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
65
65
|
"jest": "29.7.0",
|
|
66
66
|
"memfs": "^4.13.0",
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"volta": {
|
|
101
101
|
"extends": "../../../package.json"
|
|
102
102
|
},
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "8b1c3ff25c653681c7dfa2553c9974cb70567d8d"
|
|
104
104
|
}
|