@lwrjs/router 0.19.0-alpha.8 → 0.19.0
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.
- package/build/bundle/prod/lwr/routerContainer/routerContainer.js +1 -1
- package/build/cjs/modules/lwr/domRouterUtils/domRouterUtils.cjs +1 -0
- package/build/cjs/modules/lwr/domRouterUtils/uriUtils.cjs +9 -1
- package/build/cjs/modules/lwr/historyRouter/historyRouter.cjs +6 -1
- package/build/cjs/modules/lwr/routerContainer/routerContainer.cjs +5 -1
- package/build/es/modules/lwr/domRouterUtils/domRouterUtils.d.ts +1 -1
- package/build/es/modules/lwr/domRouterUtils/domRouterUtils.js +1 -1
- package/build/es/modules/lwr/domRouterUtils/uriUtils.d.ts +7 -0
- package/build/es/modules/lwr/domRouterUtils/uriUtils.js +13 -0
- package/build/es/modules/lwr/historyRouter/historyRouter.d.ts +1 -0
- package/build/es/modules/lwr/historyRouter/historyRouter.js +8 -2
- package/build/es/modules/lwr/routerContainer/routerContainer.js +6 -1
- package/build/modules/lwr/domRouterUtils/domRouterUtils.js +1 -1
- package/build/modules/lwr/domRouterUtils/uriUtils.js +14 -0
- package/build/modules/lwr/historyRouter/historyRouter.js +8 -2
- package/build/modules/lwr/routerContainer/routerContainer.js +7 -1
- package/package.json +6 -6
|
@@ -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 $=P(new w(void 0)),A=P(new w(void 0)),O=new w(void 0),U=class extends(P(O)){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(A),V=D?r(U):void 0,G=r($);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},A.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,$),W(void 0,this.target,F,A),W(void 0,this.target,V,U),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)};U.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}connect(){super.connect(),this.historyDisabled||(D&&window.addEventListener("popstate",this.onpopstate.bind(this)),this.onpopstate())}onpopstate(){!this.parent&&D&&this.catchBrowserUpdate(q(window.location.href))}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)),s}catchBrowserUpdate(e){this.process(e,!1,{},!1)}}s(z,{fields:["historyDisabled"]});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)}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=function(e){const t=e.indexOf("#");return-1!==t?e.substring(0,t):e}(q(window.location.href));e!==this.currentUrl&&this.catchBrowserUpdate(e)}}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};
|
|
2
2
|
//# sourceMappingURL=routerContainer.js.map
|
|
@@ -25,6 +25,7 @@ var __toModule = (module2) => {
|
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
27
|
getRelativeUrl: () => import_uriUtils.getRelativeUrl,
|
|
28
|
+
removeFragment: () => import_uriUtils.removeFragment,
|
|
28
29
|
replace: () => import_historyUtils.replace,
|
|
29
30
|
set: () => import_historyUtils.set
|
|
30
31
|
});
|
|
@@ -25,7 +25,8 @@ var __toModule = (module2) => {
|
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
27
|
getRelativeUrl: () => getRelativeUrl,
|
|
28
|
-
getUrlObject: () => getUrlObject
|
|
28
|
+
getUrlObject: () => getUrlObject,
|
|
29
|
+
removeFragment: () => removeFragment
|
|
29
30
|
});
|
|
30
31
|
var import_routerUtils = __toModule(require("lwr/routerUtils"));
|
|
31
32
|
function getUrlObject(url = "") {
|
|
@@ -59,3 +60,10 @@ function getRelativeUrl(url) {
|
|
|
59
60
|
const origin = urlObj.origin.replace(/:\d+/, "");
|
|
60
61
|
return href.replace(origin, "");
|
|
61
62
|
}
|
|
63
|
+
function removeFragment(url) {
|
|
64
|
+
const hashIndex = url.indexOf("#");
|
|
65
|
+
if (hashIndex !== -1) {
|
|
66
|
+
return url.substring(0, hashIndex);
|
|
67
|
+
}
|
|
68
|
+
return url;
|
|
69
|
+
}
|
|
@@ -34,6 +34,7 @@ var HistoryRouter = class extends import_domRouter.DomRouterImpl {
|
|
|
34
34
|
constructor() {
|
|
35
35
|
super(...arguments);
|
|
36
36
|
this.historyDisabled = false;
|
|
37
|
+
this.currentUrl = "";
|
|
37
38
|
}
|
|
38
39
|
connect() {
|
|
39
40
|
super.connect();
|
|
@@ -44,7 +45,10 @@ var HistoryRouter = class extends import_domRouter.DomRouterImpl {
|
|
|
44
45
|
}
|
|
45
46
|
onpopstate() {
|
|
46
47
|
if (!this.parent && import_routerUtils.hasDocument) {
|
|
47
|
-
|
|
48
|
+
const relativeUrl = (0, import_domRouterUtils.removeFragment)((0, import_domRouterUtils.getRelativeUrl)(window.location.href));
|
|
49
|
+
if (relativeUrl !== this.currentUrl) {
|
|
50
|
+
this.catchBrowserUpdate(relativeUrl);
|
|
51
|
+
}
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
disconnect() {
|
|
@@ -59,6 +63,7 @@ var HistoryRouter = class extends import_domRouter.DomRouterImpl {
|
|
|
59
63
|
} else {
|
|
60
64
|
(0, import_domRouterUtils.set)(url);
|
|
61
65
|
}
|
|
66
|
+
this.currentUrl = url;
|
|
62
67
|
}
|
|
63
68
|
return canContinue;
|
|
64
69
|
}
|
|
@@ -82,8 +82,12 @@ var RouterContainer = class extends import_lwc.LightningElement {
|
|
|
82
82
|
document.title = this.currentTitle;
|
|
83
83
|
}
|
|
84
84
|
const a11yTitle = this.refs?.title;
|
|
85
|
-
if (a11yTitle)
|
|
85
|
+
if (a11yTitle) {
|
|
86
86
|
a11yTitle.innerHTML = this.currentTitle;
|
|
87
|
+
setTimeout(() => {
|
|
88
|
+
a11yTitle.innerHTML = "";
|
|
89
|
+
}, 500);
|
|
90
|
+
}
|
|
87
91
|
}
|
|
88
92
|
errorNavigate(error) {
|
|
89
93
|
this.dispatchEvent(this._createEvent("errornavigate", error));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { getRelativeUrl } from './uriUtils.js';
|
|
1
|
+
export { getRelativeUrl, removeFragment } from './uriUtils.js';
|
|
2
2
|
export { set, replace } from './historyUtils.js';
|
|
3
3
|
export type { DomRouterConfig, NavigationHandler, RouteChange } from './types.js';
|
|
4
4
|
//# sourceMappingURL=domRouterUtils.d.ts.map
|
|
@@ -27,4 +27,11 @@ export declare function getUrlObject(url?: string): UrlObject;
|
|
|
27
27
|
* @return {string}
|
|
28
28
|
*/
|
|
29
29
|
export declare function getRelativeUrl(url: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Remove the fragment identifier from a URL.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} url - The URL to remove the fragment identifier from.
|
|
34
|
+
* @returns {string} The URL without the fragment identifier.
|
|
35
|
+
*/
|
|
36
|
+
export declare function removeFragment(url: string): string;
|
|
30
37
|
//# sourceMappingURL=uriUtils.d.ts.map
|
|
@@ -66,4 +66,17 @@ export function getRelativeUrl(url) {
|
|
|
66
66
|
const origin = urlObj.origin.replace(/:\d+/, '');
|
|
67
67
|
return href.replace(origin, '');
|
|
68
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Remove the fragment identifier from a URL.
|
|
71
|
+
*
|
|
72
|
+
* @param {string} url - The URL to remove the fragment identifier from.
|
|
73
|
+
* @returns {string} The URL without the fragment identifier.
|
|
74
|
+
*/
|
|
75
|
+
export function removeFragment(url) {
|
|
76
|
+
const hashIndex = url.indexOf('#');
|
|
77
|
+
if (hashIndex !== -1) {
|
|
78
|
+
return url.substring(0, hashIndex);
|
|
79
|
+
}
|
|
80
|
+
return url;
|
|
81
|
+
}
|
|
69
82
|
//# sourceMappingURL=uriUtils.js.map
|
|
@@ -10,6 +10,7 @@ import type { DomRouterConfig } from 'lwr/domRouterUtils';
|
|
|
10
10
|
import type { NavigateOptions } from '../routerUtils/types.js';
|
|
11
11
|
export declare class HistoryRouter extends DomRouterImpl {
|
|
12
12
|
historyDisabled: boolean;
|
|
13
|
+
currentUrl: string;
|
|
13
14
|
/**
|
|
14
15
|
* Override.
|
|
15
16
|
* Initialize with the current route and listen to the popstate event for future changes.
|
|
@@ -5,13 +5,14 @@
|
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
7
|
import { DomRouterImpl } from 'lwr/domRouter';
|
|
8
|
-
import { getRelativeUrl, replace, set } from 'lwr/domRouterUtils';
|
|
8
|
+
import { getRelativeUrl, removeFragment, replace, set } from 'lwr/domRouterUtils';
|
|
9
9
|
import { hasDocument } from 'lwr/routerUtils';
|
|
10
10
|
/*
|
|
11
11
|
* Provides a Router rooted to the window, which controls the browser history by default.
|
|
12
12
|
*/
|
|
13
13
|
export class HistoryRouter extends DomRouterImpl {
|
|
14
14
|
historyDisabled = false;
|
|
15
|
+
currentUrl = '';
|
|
15
16
|
/**
|
|
16
17
|
* Override.
|
|
17
18
|
* Initialize with the current route and listen to the popstate event for future changes.
|
|
@@ -28,7 +29,11 @@ export class HistoryRouter extends DomRouterImpl {
|
|
|
28
29
|
onpopstate() {
|
|
29
30
|
// Only the root should update the url since it has the full context
|
|
30
31
|
if (!this.parent && hasDocument) {
|
|
31
|
-
|
|
32
|
+
// Remove fragment identifier from URL, we never want to navigate for fragment changes
|
|
33
|
+
const relativeUrl = removeFragment(getRelativeUrl(window.location.href));
|
|
34
|
+
if (relativeUrl !== this.currentUrl) {
|
|
35
|
+
this.catchBrowserUpdate(relativeUrl);
|
|
36
|
+
}
|
|
32
37
|
}
|
|
33
38
|
}
|
|
34
39
|
disconnect() {
|
|
@@ -57,6 +62,7 @@ export class HistoryRouter extends DomRouterImpl {
|
|
|
57
62
|
else {
|
|
58
63
|
set(url);
|
|
59
64
|
}
|
|
65
|
+
this.currentUrl = url;
|
|
60
66
|
}
|
|
61
67
|
return canContinue;
|
|
62
68
|
}
|
|
@@ -89,8 +89,13 @@ export default class RouterContainer extends LightningElement {
|
|
|
89
89
|
// Update the inner HTML of the aria-live region for screen readers
|
|
90
90
|
// This DOM node must be touched for every route change
|
|
91
91
|
const a11yTitle = this.refs?.title;
|
|
92
|
-
if (a11yTitle)
|
|
92
|
+
if (a11yTitle) {
|
|
93
93
|
a11yTitle.innerHTML = this.currentTitle;
|
|
94
|
+
// Clear the aria-live region after 500ms to ensure proper announcement on next navigation
|
|
95
|
+
setTimeout(() => {
|
|
96
|
+
a11yTitle.innerHTML = '';
|
|
97
|
+
}, 500);
|
|
98
|
+
}
|
|
94
99
|
}
|
|
95
100
|
/**
|
|
96
101
|
* The errorNavigate hook surfaced as a CustomEvent.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { getRelativeUrl } from './uriUtils.js';
|
|
1
|
+
export { getRelativeUrl, removeFragment } from './uriUtils.js';
|
|
2
2
|
export { set, replace } from './historyUtils.js';
|
|
@@ -70,4 +70,18 @@ export function getRelativeUrl(url) {
|
|
|
70
70
|
const href = urlObj.href.replace(/:\d+/, '');
|
|
71
71
|
const origin = urlObj.origin.replace(/:\d+/, '');
|
|
72
72
|
return href.replace(origin, '');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Remove the fragment identifier from a URL.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} url - The URL to remove the fragment identifier from.
|
|
79
|
+
* @returns {string} The URL without the fragment identifier.
|
|
80
|
+
*/
|
|
81
|
+
export function removeFragment(url) {
|
|
82
|
+
const hashIndex = url.indexOf('#');
|
|
83
|
+
if (hashIndex !== -1) {
|
|
84
|
+
return url.substring(0, hashIndex);
|
|
85
|
+
}
|
|
86
|
+
return url;
|
|
73
87
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { DomRouterImpl } from 'lwr/domRouter';
|
|
9
|
-
import { getRelativeUrl, replace, set } from 'lwr/domRouterUtils';
|
|
9
|
+
import { getRelativeUrl, removeFragment, replace, set } from 'lwr/domRouterUtils';
|
|
10
10
|
import { hasDocument } from 'lwr/routerUtils';
|
|
11
11
|
/*
|
|
12
12
|
* Provides a Router rooted to the window, which controls the browser history by default.
|
|
@@ -14,6 +14,7 @@ import { hasDocument } from 'lwr/routerUtils';
|
|
|
14
14
|
|
|
15
15
|
export class HistoryRouter extends DomRouterImpl {
|
|
16
16
|
historyDisabled = false;
|
|
17
|
+
currentUrl = '';
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Override.
|
|
@@ -32,7 +33,11 @@ export class HistoryRouter extends DomRouterImpl {
|
|
|
32
33
|
onpopstate() {
|
|
33
34
|
// Only the root should update the url since it has the full context
|
|
34
35
|
if (!this.parent && hasDocument) {
|
|
35
|
-
|
|
36
|
+
// Remove fragment identifier from URL, we never want to navigate for fragment changes
|
|
37
|
+
const relativeUrl = removeFragment(getRelativeUrl(window.location.href));
|
|
38
|
+
if (relativeUrl !== this.currentUrl) {
|
|
39
|
+
this.catchBrowserUpdate(relativeUrl);
|
|
40
|
+
}
|
|
36
41
|
}
|
|
37
42
|
}
|
|
38
43
|
disconnect() {
|
|
@@ -62,6 +67,7 @@ export class HistoryRouter extends DomRouterImpl {
|
|
|
62
67
|
} else {
|
|
63
68
|
set(url);
|
|
64
69
|
}
|
|
70
|
+
this.currentUrl = url;
|
|
65
71
|
}
|
|
66
72
|
return canContinue;
|
|
67
73
|
}
|
|
@@ -89,7 +89,13 @@ export default class RouterContainer extends LightningElement {
|
|
|
89
89
|
// Update the inner HTML of the aria-live region for screen readers
|
|
90
90
|
// This DOM node must be touched for every route change
|
|
91
91
|
const a11yTitle = this.refs?.title;
|
|
92
|
-
if (a11yTitle)
|
|
92
|
+
if (a11yTitle) {
|
|
93
|
+
a11yTitle.innerHTML = this.currentTitle;
|
|
94
|
+
// Clear the aria-live region after 500ms to ensure proper announcement on next navigation
|
|
95
|
+
setTimeout(() => {
|
|
96
|
+
a11yTitle.innerHTML = '';
|
|
97
|
+
}, 500);
|
|
98
|
+
}
|
|
93
99
|
}
|
|
94
100
|
|
|
95
101
|
/**
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.19.0
|
|
8
|
+
"version": "0.19.0",
|
|
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.19.0
|
|
57
|
-
"@lwrjs/diagnostics": "0.19.0
|
|
58
|
-
"@lwrjs/shared-utils": "0.19.0
|
|
56
|
+
"@lwrjs/client-modules": "0.19.0",
|
|
57
|
+
"@lwrjs/diagnostics": "0.19.0",
|
|
58
|
+
"@lwrjs/shared-utils": "0.19.0",
|
|
59
59
|
"ajv": "6.12.6"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@lwc/jest-preset": "^18.1.2",
|
|
63
|
-
"@lwrjs/fs-watch": "0.19.0
|
|
63
|
+
"@lwrjs/fs-watch": "0.19.0",
|
|
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": "78578bcbf94d64439a250ea19048e492c8f45061"
|
|
104
104
|
}
|